/* The decorations fly out past the screen edge; without this a phone zooms the page out to fit them. */

/* --chrome: the page height around the board except the machine's top (--top-room), so the
   whole machine fits on the screen. Measured, and tightened on short screens below. */
.app {
  --chrome: 340px;
  max-width: 470px;
  margin: 0 auto;
  padding: 14px 16px 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

/* Top bar: back, score panel, restart. */
.topbar { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.scorebox {
  flex: 1;
  min-width: 0;
  max-width: 290px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  column-gap: 10px;
  padding: 6px 14px 8px;
}
.scorebox .crown { grid-column: 1; grid-row: 1 / 3; font-size: 1.7rem; filter: drop-shadow(0 2px 0 rgba(0, 0, 0, 0.12)); }
.scorebox .value { grid-column: 2; grid-row: 1; text-align: center; font-size: 2rem; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.scorebox .sub { grid-column: 2; grid-row: 2; text-align: center; font-size: 0.95rem; color: var(--muted); font-weight: 600; white-space: nowrap; }
.scorebox .sub b { color: var(--ink); font-variant-numeric: tabular-nums; }
.level {
  grid-column: 3;
  grid-row: 1 / 3;
  position: relative;
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  color: #fff;
  text-align: center;
  line-height: 0.95;
  font-weight: 700;
}
.level svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.level > span { position: relative; font-size: 0.82rem; }
.level b { display: block; font-size: 1.35rem; }
.level.bump svg { animation: badge 0.7s ease; }

/* For screen readers only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}


/* Tray: hold, current, next, rising row. */
.tray { width: 100%; padding: 10px 14px 12px; display: flex; flex-direction: column; gap: 8px; }
.tray-slots { display: grid; grid-template-columns: 1fr 1.2fr 1fr; gap: 10px; align-items: end; }
.slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
}
.slot-die { position: relative; width: 56px; height: 56px; display: block; }
.slot-die.small { width: 42px; height: 42px; margin: 7px 0; }
.slot-well {
  display: grid;
  place-items: center;
  width: 100%;
  padding: 8px;
  border-radius: 16px;
  background: var(--cream-2);
  box-shadow: inset 0 3px 6px rgba(120, 80, 40, 0.18);
}
.slot--current .slot-well { background: #e9d3b4; }
.slot--current .slot-die { width: 66px; height: 66px; }
.slot--hold { cursor: pointer; transition: transform 0.1s ease, opacity 0.15s ease; }
.slot--hold:active { transform: translateY(3px); }
.slot--hold.used { opacity: 0.55; }
.slot-die:empty::before {
  content: "";
  position: absolute;
  inset: 5px;
  border: 3px dashed var(--purple-soft);
  border-radius: 24%;
}
.slot--rise { flex-direction: row; gap: 10px; }
.slot--rise .label { white-space: nowrap; }
.rise-bar { flex: 1; height: 16px; border-radius: 999px; background: var(--cream-2); box-shadow: inset 0 2px 4px rgba(120, 80, 40, 0.2); overflow: hidden; }
.rise-bar i { display: block; height: 100%; border-radius: 999px; background: linear-gradient(180deg, #86e85e, var(--green)); box-shadow: inset 0 -3px 0 var(--green-dark); transition: width 0.3s ease; }
.rise-bar.danger i { background: linear-gradient(180deg, #ff8a90, var(--red)); box-shadow: inset 0 -3px 0 #c9303a; animation: blink 0.8s ease-in-out infinite alternate; }
.rise-count { min-width: 1.5ch; text-align: right; font-weight: 700; font-size: 1.15rem; line-height: 1; font-variant-numeric: tabular-nums; }

/* The drawer: Bewaar, Nu and Straks hang on the machine, in its colours and with the same chrome rim
   (decor.js puts the frame's colours on the whole .app). */
.tray.panel {
  position: relative;
  background: linear-gradient(180deg, color-mix(in srgb, var(--machine-1, #a56ff0) 55%, #fff), color-mix(in srgb, var(--machine-2, #8d4fe0) 70%, #fff));
  box-shadow:
    inset 0 0 0 3px rgba(255, 255, 255, 0.55),
    inset 0 0 0 5px #b4bfd2,
    0 0 0 2px #8995ab,
    0 6px 0 var(--machine-dark, #5a2aa0),
    0 18px 26px -14px rgba(60, 20, 120, 0.5);
}
.tray .label { color: var(--machine-dark, #5a2aa0); font-weight: 700; text-shadow: 0 1px 0 rgba(255, 255, 255, 0.6); }
.tray .slot-well {
  background: color-mix(in srgb, var(--board, #9d84ea) 84%, #fff);
  box-shadow: inset 0 0 0 3px var(--board-edge, #6e3fc4), inset 0 5px 9px rgba(20, 10, 60, 0.35), 0 0 0 2px #eef2f8, 0 0 0 3.5px #9aa7bd;
}
.tray .slot--current .slot-well { background: color-mix(in srgb, var(--board, #9d84ea) 70%, #fff); }
.tray .slot-die:empty::before { border-color: rgba(255, 255, 255, 0.55); }
.tray .rise-count { color: var(--machine-dark, #5a2aa0); text-shadow: 0 1px 0 rgba(255, 255, 255, 0.6); }
.tray .rise-bar { background: color-mix(in srgb, var(--board, #9d84ea) 84%, #fff); box-shadow: inset 0 0 0 2px var(--board-edge, #6e3fc4), inset 0 3px 5px rgba(20, 10, 60, 0.35); }
/* the handle on the front of the drawer */
.tray.panel::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -4px;
  width: 56px;
  height: 8px;
  margin-left: -28px;
  border-radius: 0 0 8px 8px;
  background: linear-gradient(180deg, #eef2f8, #9aa7bd);
  box-shadow: 0 2px 0 rgba(60, 70, 100, 0.35);
}

/* The candy machine around the board: icing on top, striped pillars with bulbs, purple body. */
.machine {
  --top-room: 16px;
  position: relative;
  margin-top: var(--top-room);
  padding: 24px 10px 14px;
  display: grid;
  grid-template-columns: 22px auto 22px;
  gap: 8px;
  border-radius: 30px;
  /* a light front in the machine's colours (the theme's own, or ArcadeSkins' frame), with a chrome rim */
  --front-1: color-mix(in srgb, var(--machine-1, #a56ff0) 62%, #fff);
  --front-2: color-mix(in srgb, var(--machine-2, #8d4fe0) 74%, #fff);
  --front-3: color-mix(in srgb, var(--machine-3, #7b3bd0) 84%, #fff);
  background: linear-gradient(180deg, var(--front-1), var(--front-2) 40%, var(--front-3));
  box-shadow:
    inset 0 0 0 3px rgba(255, 255, 255, 0.55),
    inset 0 0 0 5px #b4bfd2,
    inset 0 7px 0 rgba(255, 255, 255, 0.35),
    inset 0 -6px 0 rgba(0, 0, 0, 0.1),
    0 0 0 2px #8995ab,
    0 9px 0 var(--machine-dark, #5a2aa0),
    0 30px 44px -18px rgba(60, 20, 120, 0.55);
}
/* Feet */
.machine::before, .machine::after {
  content: "";
  position: absolute;
  bottom: -18px;
  width: 54px;
  height: 22px;
  border-radius: 10px;
  background: var(--feet, #a98ad9);
  box-shadow: inset 0 3px 0 rgba(255, 255, 255, 0.4), 0 4px 0 color-mix(in srgb, var(--feet, #a98ad9) 70%, #000);
}
.machine::before { left: 18px; }
.machine::after { right: 18px; }

.icing {
  position: absolute;
  left: -8px;
  top: -16px;
  width: calc(100% + 16px);
  height: 58px;
  z-index: 3;
  pointer-events: none;
  filter: drop-shadow(0 5px 0 var(--icing-dark, #d8347f));
}
.icing path { fill: var(--icing, #ff6fb3); }
.icing-gloss { position: absolute; left: 10px; right: 10px; top: -8px; height: 10px; z-index: 4; border-radius: 999px; background: rgba(255, 255, 255, 0.5); pointer-events: none; }
.icing-sprinkles { position: absolute; left: 0; right: 0; top: -12px; height: 34px; z-index: 4; pointer-events: none; }
.icing-sprinkles i { position: absolute; width: 14px; height: 6px; border-radius: 3px; background: var(--c); box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.12); }

.pillar {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  align-items: center;
  border-radius: 12px;
  background: repeating-linear-gradient(155deg, var(--pillar-a, #fff) 0 10px, var(--pillar-b, var(--icing, #ff6fb3)) 10px 20px);
  box-shadow: inset 4px 0 0 rgba(255, 255, 255, 0.5), inset -4px 0 6px rgba(160, 30, 90, 0.25), 0 3px 0 rgba(90, 42, 160, 0.5);
}
.pillar i {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff 0 22%, #fff3a6 40%, #ffd23a);
  box-shadow: 0 0 10px 3px rgba(255, 230, 120, 0.9);
  animation: bulb 1.6s ease-in-out infinite alternate;
}
.pillar i:nth-child(even) { animation-delay: -0.8s; }
.machine.party .pillar i { animation: bulb-party 0.24s steps(2, jump-none) infinite; }
.machine.party .pillar i:nth-child(even) { animation-delay: -0.12s; }

/* The marquee: a row of lamps across the top of the machine. Off by day, softly on in the evening (body.night,
   world.js); on a combo they light up one by one, on a level up the light runs along them. */
.marquee {
  position: absolute;
  left: 40px;
  right: 40px;
  top: 7px;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
}
.marquee i {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff 0 25%, color-mix(in srgb, var(--bulb, #ffd23a) 40%, #fff));
  box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.18), 0 1px 0 rgba(255, 255, 255, 0.6);
}
body.night .marquee i { background: radial-gradient(circle at 35% 35%, #fff 0 22%, var(--bulb, #ffd23a) 62%); box-shadow: 0 0 8px 2px color-mix(in srgb, var(--bulb, #ffd23a) 70%, transparent); }
body.night .marquee i { opacity: 0.8; }
.marquee.lit-up i { animation: mq-on 1.3s ease-out calc(var(--k) * 55ms) both; }
.marquee.running i { animation: mq-run 0.36s steps(1, end) 5; }
.marquee.running i:nth-child(3n + 1) { animation-delay: 0s; }
.marquee.running i:nth-child(3n + 2) { animation-delay: -0.12s; }
.marquee.running i:nth-child(3n) { animation-delay: -0.24s; }
@keyframes mq-on {
  0% { background: radial-gradient(circle at 35% 35%, #fff 0 25%, color-mix(in srgb, var(--bulb, #ffd23a) 40%, #fff)); box-shadow: none; transform: scale(1); }
  12%, 70% { background: radial-gradient(circle at 35% 35%, #fff 0 22%, var(--bulb, #ffd23a) 62%); box-shadow: 0 0 10px 3px color-mix(in srgb, var(--bulb, #ffd23a) 80%, transparent); transform: scale(1.25); opacity: 1; }
  100% { transform: scale(1); }
}
@keyframes mq-run {
  0% { background: radial-gradient(circle at 35% 35%, #fff 0 22%, var(--bulb, #ffd23a) 62%); box-shadow: 0 0 10px 3px color-mix(in srgb, var(--bulb, #ffd23a) 80%, transparent); opacity: 1; }
  33% { background: radial-gradient(circle at 35% 35%, #fff 0 25%, color-mix(in srgb, var(--bulb, #ffd23a) 40%, #fff)); box-shadow: none; opacity: 0.7; }
}
/* at night the round top's sign glows a little too */
body.night .arch span { color: #fff; text-shadow: 0 0 8px color-mix(in srgb, var(--icing) 60%, #fff), 0 0 18px var(--icing); }

/* Board: --cols and --rows must match COLS and ROWS in game.js */
.board {
  --cols: 5;
  --rows: 8;
  position: relative;
  width: min(calc(100vw - 112px), max(var(--board-min, 200px), calc((100vh - var(--chrome) - var(--top-room)) * var(--cols) / var(--rows))));
  width: min(calc(100vw - 112px), max(var(--board-min, 200px), calc((100dvh - var(--chrome) - var(--top-room)) * var(--cols) / var(--rows))));
  aspect-ratio: var(--cols) / var(--rows);
  border-radius: 20px;
  background: color-mix(in srgb, var(--board, #9d84ea) 74%, #fff);
  /* the board sits in a chrome bezel */
  box-shadow: inset 0 0 0 4px var(--board-edge, #6e3fc4), inset 0 6px 14px rgba(40, 10, 110, 0.35), 0 0 0 3px #eef2f8, 0 0 0 5px #9aa7bd, 0 2px 0 5px rgba(60, 70, 100, 0.3);
  overflow: hidden;
  touch-action: none; /* a finger slides over the columns to aim */
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.board:focus-visible { outline: 4px solid #fff; outline-offset: 3px; }
.board.shake { animation: shake 0.35s ease; }

.cells, .layer { position: absolute; inset: 8px; }
.cells { display: grid; grid-template-columns: repeat(var(--cols), 1fr); grid-template-rows: repeat(var(--rows), 1fr); }
.cells span {
  margin: 3px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--cell, #b4a0f3) 80%, #fff);
  box-shadow: inset 0 2px 4px rgba(50, 20, 120, 0.25), inset 0 -2px 0 rgba(255, 255, 255, 0.18);
}
/* Candy-cane stripes on the top row: don't stack up to here. */
.cells span:nth-child(-n + 5) {
  background: repeating-linear-gradient(135deg, var(--danger-1, #ff8fc6) 0 9px, var(--danger-2, #ffd9ea) 9px 18px);
  box-shadow: inset 0 2px 4px rgba(120, 20, 80, 0.25);
  transition: background 0.3s ease;
}
/* A die up here: the danger zone turns red, and flashes when one arrives. */
.cells.danger span:nth-child(-n + 5) { background: repeating-linear-gradient(135deg, #ff4b55 0 9px, #ffb3b8 9px 18px); }
.cells.flash span:nth-child(-n + 5) { animation: danger 0.42s ease-in-out 3; }

.layer > * { position: absolute; top: 0; left: 0; width: calc(100% / var(--cols)); height: calc(100% / var(--rows)); }

.column-hl {
  height: 100% !important;
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0.06));
  transition: transform 0.09s ease, background 0.2s ease, opacity 0.15s ease;
}
.column-hl.off { opacity: 0; }
.column-hl.deny { opacity: 1; background: rgba(255, 75, 85, 0.35); }

/* Dice motion (looks live in assets/dice.css). */
.layer .die { transition: transform 0.18s cubic-bezier(0.3, 0.75, 0.4, 1), opacity 0.2s ease; }
.die.ghost { opacity: 0.4; transition: transform 0.09s ease; pointer-events: none; }
.die.absorbed { opacity: 0; }
.die.absorbed .face { transform: scale(0.55); }
.layer .die.fresh .face { animation: land 0.3s ease-out 0.15s; }
.layer .die.pop .face { animation: pop 0.38s ease; }
.layer .die.boom .face { animation: boom 0.32s ease forwards; }

/* Effects */
.popup {
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 1.15rem;
  color: #fff;
  text-shadow: 0 2px 0 var(--purple-dark), 0 0 8px rgba(106, 51, 184, 0.7);
  pointer-events: none;
  z-index: 5;
  animation: float 0.9s ease-out forwards;
}
.blast {
  width: 60% !important;
  height: calc(300% / var(--rows)) !important;
  border-radius: 50%;
  background: radial-gradient(circle, #fff 0 18%, var(--lemon) 19% 34%, rgba(255, 95, 162, 0.55) 35% 48%, transparent 50%);
  pointer-events: none;
  z-index: 4;
  animation: blast 0.55s ease-out forwards;
}
.sprinkle {
  width: 7px !important;
  height: 16px !important;
  margin: -8px 0 0 -3px;
  border-radius: 4px;
  background: var(--c);
  pointer-events: none;
  z-index: 6;
  animation: sprinkle 0.8s cubic-bezier(0.2, 0.7, 0.4, 1) forwards;
}
/* Messages over the board: combo, level up, the danger warning. */
.banner {
  position: absolute;
  left: 50%;
  top: 38%;
  padding: 6px 20px;
  border: 4px solid #fff;
  border-radius: 999px;
  font-size: 1.6rem;
  font-weight: 700;
  white-space: nowrap;
  color: #fff;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.18);
  box-shadow: 0 5px 0 rgba(58, 31, 74, 0.25);
  pointer-events: none;
  z-index: 7;
}
.combo {
  background: linear-gradient(90deg, var(--pink), var(--orange), var(--lemon), var(--green), var(--blue), var(--purple));
  animation: combo 0.9s ease-out forwards;
}
.levelup {
  top: 30%;
  padding: 8px 26px;
  font-size: 2.1rem;
  background: linear-gradient(180deg, #ffe066, #ffb703 60%, #f08c00);
  text-shadow: 0 2px 0 #b86a00;
  box-shadow: 0 6px 0 #b86a00, 0 0 0 6px rgba(255, 224, 102, 0.35), 0 12px 30px rgba(255, 190, 40, 0.6);
  animation: levelup 1.6s ease-out forwards;
}
.toast {
  top: calc(100% / var(--rows) + 12px);
  padding: 5px 16px;
  font-size: 1.15rem;
  background: linear-gradient(180deg, #ff7a82, #e5303b);
  animation: toast 1.8s ease forwards;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--machine-3, #6e3fc4) 80%, transparent);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  cursor: default;
}
.overlay { padding: 10px; }
.overlay .end-card { width: min(300px, 100%); padding: 14px 14px 16px; gap: 6px; }
.overlay .over-icon .die { width: 58px; height: 58px; padding: 0; rotate: -10deg; }
.overlay .over-title { font-size: 1.3rem; }
.overlay .over-stars span { width: 32px; height: 32px; }
.overlay .over-stars span:nth-child(2) { width: 40px; height: 40px; margin-top: -6px; }
.over-score { margin: 0; font-size: 3rem; font-weight: 700; line-height: 1; color: var(--purple); font-variant-numeric: tabular-nums; }
.overlay .over-actions { flex-direction: column; gap: 12px; }
.overlay .over-actions .btn { flex: none; }

/* Help on the start screen: cream pill that opens a card. */
.help { margin-top: 10px; width: min(420px, 100%); text-align: left; display: flex; flex-direction: column; align-items: center; gap: 10px; color: var(--muted); font-size: 0.98rem; line-height: 1.5; }
.help summary { list-style: none; min-height: 44px; display: inline-flex; align-items: center; gap: 6px; padding: 8px 18px; border-radius: 999px; cursor: pointer; color: var(--ink); font-weight: 600; }
.help summary::-webkit-details-marker { display: none; }
.help ul { margin: 0; padding: 12px 18px 12px 34px; width: 100%; }
.help strong { color: var(--ink); }
/* the stickers earned in this game, again on the end card */
.new-stickers { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 2px 10px; margin: 0; padding: 5px 10px; border-radius: 16px; background: #fff7cc; box-shadow: inset 0 0 0 3px var(--lemon); color: var(--ink); font-weight: 700; line-height: 1.2; animation: sticker-row 0.4s ease 0.3s backwards; }
.new-stickers > span { display: inline-flex; align-items: center; gap: 6px; }
.new-stickers .art { width: 34px; height: 34px; }
@keyframes sticker-row { from { transform: scale(0.85); opacity: 0; } }

kbd {
  font: inherit;
  font-size: 0.85em;
  padding: 0 7px;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 2px 0 var(--cream-dark);
  color: var(--ink);
}

/* Start screen */
.start {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  overflow-y: auto; /* the help can open below the buttons */
  background: var(--theme-sky, #bfe2ff) var(--theme-bg, url("../../assets/candy-bg.svg")) center bottom / cover no-repeat;
}
.start-card {
  flex: 1 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px 16px 12px;
  text-align: center;
  z-index: 2;
}
.start-logo { position: relative; }
.start-logo h1 { margin: 0; font-size: clamp(3.2rem, 15vw, 5rem); }
.start-mascot { position: absolute; right: -22px; top: -42px; width: 62px; height: 62px; rotate: 12deg; animation: bob 2.4s ease-in-out infinite; }
/* now and then the die tumbles over once, slowly, and lands back on its six */
.start-mascot .die { animation: tumble 4.8s ease-in-out 1s infinite; }
@keyframes tumble {
  0%, 58% { transform: translateY(0) rotate(0deg); }
  70% { transform: translateY(-14px) rotate(160deg) scale(1.08); }
  84% { transform: translateY(0) rotate(360deg) scale(0.94, 1.06); }
  90% { transform: translateY(0) rotate(360deg) scale(1.06, 0.92); }
  100% { transform: translateY(0) rotate(360deg); }
}
.start-best { margin: 0; padding: 6px 18px; border-radius: 999px; font-size: 1.15rem; font-weight: 700; }
.start-best .art { vertical-align: -0.15em; }
/* the one choice: Makkelijk or Klassiek */
.start-form { width: min(360px, 100%); padding: 10px 14px 14px; display: flex; flex-direction: column; gap: 8px; }
.start-form .label { margin: 0; }
.targets { display: flex; justify-content: center; gap: 8px; }
.targets button {
  flex: 1;
  min-height: 52px;
  padding: 4px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 16px;
  font: inherit;
  font-size: 1.1rem;
  font-weight: 700;
  line-height: 1.15;
  color: var(--ink);
  background: #fff;
  box-shadow: 0 4px 0 var(--cream-dark);
  cursor: pointer;
}
.targets button:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--cream-dark); }
.targets button small { font-size: 0.82rem; font-weight: 600; color: var(--muted); }
/* darker towards the bottom and a text shadow: white stays readable on a light theme colour (gold) */
.targets button.on { color: #fff; background: linear-gradient(180deg, var(--purple), color-mix(in srgb, var(--purple-dark) 70%, var(--purple))); box-shadow: 0 4px 0 var(--purple-dark); text-shadow: 0 1px 0 rgba(0, 0, 0, 0.28); }
.targets button.on small { color: rgba(255, 255, 255, 0.88); }
.start-actions { display: flex; flex-direction: column; align-items: center; gap: 16px; width: min(280px, 80vw); }
.start-actions #start-btn { width: 100%; text-align: center; }
.start-actions a { text-decoration: none; }

/* The bottom of the start screen: a stack of dice on the candy ground; falling dice stay inside this zone. */
.start-ground {
  position: relative;
  flex: 0 1 clamp(190px, 34vh, 340px); /* gives way to the start card on short screens */
  min-height: calc(2 * var(--s) + 30px);
  overflow: hidden;
  --s: min(12vw, 60px);
}
.start-stack {
  position: absolute;
  left: 50%;
  bottom: 18px;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(7, var(--s));
  gap: 4px;
  transform: translateX(-50%);
}
.start-stack .die, .start-fall .die { width: var(--s); height: var(--s); padding: 0; }
.start-fall {
  position: absolute;
  bottom: calc(18px + 2 * var(--s) + 8px);
  z-index: 1;
  width: var(--s);
  animation: fall 2.8s ease-in infinite;
}

/* ---- Theme decoration (decor.js) ---- */
.machine.themed .icing-sprinkles { display: none; }
.machine.themed .pillar i { background: radial-gradient(circle at 35% 35%, #fff 0 22%, var(--bulb) 60%); box-shadow: 0 0 10px 3px color-mix(in srgb, var(--bulb) 75%, transparent); }
.machine.multi .pillar i:nth-child(4n + 1) { --bulb: #ff3b30; }
.machine.multi .pillar i:nth-child(4n + 2) { --bulb: #34c759; }
.machine.multi .pillar i:nth-child(4n + 3) { --bulb: #2d8dff; }
.machine.stone .pillar {
  background: repeating-linear-gradient(0deg, var(--pillar-a) 0 22px, var(--pillar-b) 22px 25px);
  box-shadow: inset 3px 0 0 rgba(255, 255, 255, 0.25), inset -3px 0 4px rgba(0, 0, 0, 0.25), 0 3px 0 rgba(0, 0, 0, 0.3);
}
.machine.stone { background-image: linear-gradient(180deg, var(--front-1), var(--front-2) 40%, var(--front-3)), radial-gradient(rgba(0, 0, 0, 0.08) 1.5px, transparent 2px); background-size: auto, 9px 9px; }

/* Round top (haunted cabinet, desert arch, space dome) */
.machine.top-arch { --top-room: 64px; }
.machine.top-arch .icing, .machine.top-arch .icing-gloss { display: none; }
.arch {
  position: absolute;
  left: 0;
  right: 0;
  top: -62px;
  height: 92px;
  z-index: -1;
  display: grid;
  place-items: start center;
  padding-top: 18px;
  border-radius: 50% 50% 0 0 / 100% 100% 0 0;
  background: linear-gradient(180deg, color-mix(in srgb, var(--icing) 80%, #fff), var(--icing));
  box-shadow: inset 0 4px 0 rgba(255, 255, 255, 0.35), 0 -2px 0 var(--icing-dark);
}
.arch span {
  font-weight: 700;
  font-size: 1.5rem;
  letter-spacing: 0.12em;
  color: var(--icing-dark);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.45), 0 -1px 0 rgba(0, 0, 0, 0.25);
}
.arch .crack { position: absolute; left: 18%; top: 16px; width: 44px; stroke: var(--icing-dark); opacity: 0.7; }

/* Chequered flag top */
.machine.top-checker .icing, .machine.top-checker .icing-gloss { display: none; }
.checker {
  position: absolute;
  left: -4px;
  right: -4px;
  top: -10px;
  height: 30px;
  z-index: 3;
  border-radius: 14px 14px 6px 6px;
  background: repeating-conic-gradient(var(--icing-dark) 0 25%, var(--icing) 0 50%) 0 0 / 20px 20px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.35);
}

/* Cobwebs, a dangling spider */
.web { position: absolute; top: 18px; z-index: 4; width: 92px; height: 92px; pointer-events: none; }
.web svg { width: 100%; height: 100%; }
.web.left { left: 36px; }
.web.right { right: 36px; transform: scaleX(-1); }
.spider { position: absolute; z-index: 4; top: 20px; right: 30%; display: flex; flex-direction: column; align-items: center; pointer-events: none; animation: spider 5s ease-in-out infinite; }
.spider i { width: 1.5px; height: 46px; background: rgba(255, 255, 255, 0.75); }
.spider span { font-size: 2.6rem; line-height: 0; margin-top: -10px; }

/* Decoration standing at the foot of the machine */
.corner { position: absolute; bottom: -22px; z-index: 5; font-size: 2.8rem; line-height: 1; filter: drop-shadow(0 4px 0 rgba(0, 0, 0, 0.2)); pointer-events: none; }
.corner.left { left: -30px; rotate: -8deg; }
.corner.right { right: -30px; rotate: 8deg; }

/* Bats, snowflakes, butterflies... flying around the machine */
.flyers { position: absolute; inset: -70px -70px 0; z-index: -2; pointer-events: none; } /* not below the feet: that would scroll the page */
.flyers span {
  position: absolute;
  /* alternate sides so they peek out left and right of the machine */
  left: calc(var(--k) * 37% - var(--k) * var(--k) * 6%);
  top: calc(4% + var(--k) * 21%);
  font-size: 1.6rem;
  animation: fly calc(7s + var(--k) * 1.3s) ease-in-out infinite;
  animation-delay: calc(var(--k) * -1.7s);
}

@keyframes fly {
  0%, 100% { transform: translate(0, 0) scale(1); }
  20% { transform: translate(60px, -30px) scale(1.15, 0.85); }
  40% { transform: translate(120px, 10px) scale(1); }
  60% { transform: translate(40px, 50px) scale(0.9, 1.1); }
  80% { transform: translate(-40px, 10px) scale(1.1, 0.9); }
}
@keyframes spider { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(26px); } }

@keyframes pop { 0% { transform: scale(0.7); } 55% { transform: scale(1.22) rotate(-6deg); } 100% { transform: scale(1); } }
@keyframes land { 0% { transform: scale(1, 1); } 40% { transform: scale(1.1, 0.88); } 100% { transform: scale(1, 1); } }
@keyframes boom { to { transform: scale(1.5) rotate(20deg); opacity: 0; } }
@keyframes float { from { transform: translateY(0) scale(0.8); opacity: 1; } to { transform: translateY(-130%) scale(1.1); opacity: 0; } }
@keyframes blast { from { transform: scale(0.3); opacity: 1; } to { transform: scale(1.5); opacity: 0; } }
@keyframes sprinkle {
  from { transform: translate(0, 0) rotate(0deg); opacity: 1; }
  to { transform: translate(var(--dx), var(--dy)) rotate(var(--rot)); opacity: 0; }
}
@keyframes combo {
  0% { transform: translate(-50%, 10px) scale(0.5) rotate(-6deg); opacity: 0; }
  20% { transform: translate(-50%, 0) scale(1.1) rotate(2deg); opacity: 1; }
  100% { transform: translate(-50%, -30px) scale(1); opacity: 0; }
}
@keyframes shake {
  20% { transform: translateX(-6px) rotate(-1deg); } 40% { transform: translateX(5px) rotate(1deg); }
  60% { transform: translateX(-3px); } 80% { transform: translateX(2px); }
}
@keyframes levelup {
  0% { transform: translate(-50%, 0) scale(0.3) rotate(-8deg); opacity: 0; }
  15% { transform: translate(-50%, 0) scale(1.15) rotate(3deg); opacity: 1; }
  25% { transform: translate(-50%, 0) scale(1) rotate(0deg); }
  80% { transform: translate(-50%, 0) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -24px) scale(0.95); opacity: 0; }
}
@keyframes toast {
  0% { transform: translate(-50%, -8px) scale(0.8); opacity: 0; }
  12% { transform: translate(-50%, 0) scale(1.05); opacity: 1; }
  20% { transform: translate(-50%, 0) scale(1); }
  82% { opacity: 1; }
  100% { transform: translate(-50%, 0); opacity: 0; }
}
@keyframes danger { 50% { background: #ff2d3a; box-shadow: 0 0 12px 2px rgba(255, 45, 58, 0.8); } }
@keyframes badge { 30% { transform: scale(1.3) rotate(25deg); } 60% { transform: scale(0.95) rotate(-8deg); } }
@keyframes blink { to { opacity: 0.35; } }
@keyframes bulb { to { opacity: 0.45; box-shadow: 0 0 2px rgba(255, 214, 58, 0.4); } }
@keyframes bulb-party { 50% { opacity: 0.25; } }
@keyframes bob { 50% { translate: 0 -8px; } }
@keyframes fall {
  0% { transform: translateY(-34vh); opacity: 0; }
  30% { opacity: 1; }
  70% { transform: translateY(0); opacity: 1; }
  100% { transform: translateY(0); opacity: 0; }
}

/* ---- Small screens: the whole machine stays on screen ---- */
@media (max-height: 720px) {
  .app { --chrome: 262px; padding-top: 8px; gap: 8px; }
  .scorebox { padding-top: 4px; padding-bottom: 5px; }
  .scorebox .value { font-size: 1.7rem; }
  .level { width: 50px; height: 50px; }
  .tray { padding: 6px 12px 8px; gap: 5px; }
  .tray-slots { gap: 8px; }
  .slot { gap: 3px; }
  .slot-well { padding: 4px; border-radius: 14px; }
  .slot-die { width: 42px; height: 42px; }
  .slot-die.small { width: 32px; height: 32px; margin: 5px 0; }
  .slot--current .slot-die { width: 50px; height: 50px; }
  .rise-bar { height: 14px; }
  .machine { padding-top: 20px; }
  .machine.top-arch { --top-room: 40px; }
  .arch { top: -38px; height: 68px; padding-top: 7px; }
  .arch span { font-size: 1.15rem; }
  .arch .crack { top: 8px; width: 34px; }
}
@media (max-height: 600px) {
  .app { --chrome: 236px; }
  .slot .label { font-size: 0.85rem; }
  .slot-die { width: 36px; height: 36px; }
  .slot-die.small { width: 28px; height: 28px; margin: 4px 0; }
  .slot--current .slot-die { width: 42px; height: 42px; }
  .machine { padding-top: 18px; }
  .machine.top-arch { --top-room: 34px; }
  .arch { top: -32px; height: 60px; padding-top: 5px; }
  .arch span { font-size: 1rem; }
  /* the board is too small for the game-over card here: it covers the whole screen instead */
  .overlay { position: fixed; z-index: 40; }
}
/* Phones: no room for the crown next to a five-digit score, "Best:" says it already. */
@media (max-width: 400px), (orientation: landscape) and (max-height: 500px) {
  .scorebox { grid-template-columns: 1fr auto; column-gap: 6px; padding-left: 10px; padding-right: 10px; }
  .scorebox .crown { display: none; }
  .scorebox .value, .scorebox .sub { grid-column: 1; }
  .level { grid-column: 2; }
}
@media (max-width: 360px) {
  .topbar { gap: 6px; }
  .scorebox { column-gap: 4px; padding: 5px 6px 6px; }
  .scorebox .value { font-size: 1.4rem; }
  .scorebox .sub { font-size: 0.85rem; }
  .level { width: 46px; height: 46px; }
  .level > span { font-size: 0.82rem; }
  .level b { font-size: 1.05rem; }
}
/* Tablets upright: the machine as tall as the screen allows (about three quarters of it). */
@media (orientation: portrait) and (min-width: 561px) {
  .app { max-width: 720px; padding-top: max(14px, env(safe-area-inset-top)); }
  .board { width: min(calc(100vw - 112px), max(var(--board-min, 200px), calc((100dvh - var(--chrome) - var(--top-room)) * var(--cols) / var(--rows)))); }
}
/* Landscape: the top bar falls apart into side columns. Back, score and the tray on the left, the machine
   in the middle at the full height, the round buttons in a column on the right edge. */
@media (orientation: landscape) {
  .app {
    --chrome: 76px;
    --board-min: 140px;
    max-width: none;
    display: grid;
    grid-template-columns: auto minmax(0, 300px) minmax(0, 1fr) auto;
    grid-template-areas: "back score machine actions" "tray tray machine actions" ". . machine actions";
    grid-template-rows: auto auto 1fr;
    align-items: start;
    --cgap: 14px;
    column-gap: var(--cgap);
    row-gap: 10px;
    padding: max(8px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left));
  }
  .topbar { display: contents; }
  .topbar .back-link { grid-area: back; align-self: center; }
  .scorebox { grid-area: score; width: 100%; max-width: none; min-width: 0; }
  .top-actions { grid-area: actions; flex-direction: column; }
  /* the drawer slides out of the machine's left side: it reaches over the gap and the machine's rim covers the seam */
  .tray { grid-area: tray; min-width: 0; margin-right: calc(-1 * var(--cgap, 14px)); border-radius: 24px 0 0 24px; }
  .tray.panel::after { left: 12px; top: 50%; bottom: auto; width: 8px; height: 56px; margin: -28px 0 0; border-radius: 8px 0 0 8px; background: linear-gradient(90deg, #9aa7bd, #eef2f8); }
  .machine { grid-area: machine; justify-self: start; }
  .board { width: min(calc(100vw - 500px), max(var(--board-min, 200px), calc((100dvh - var(--chrome) - var(--top-room)) * var(--cols) / var(--rows)))); }
}
@media (orientation: landscape) and (max-height: 500px) {
  .topbar .icon-btn, .topbar .back-link { width: 44px; height: 44px; font-size: 1.2rem; }
  .top-actions { gap: 8px; }
}
@media (orientation: landscape) and (min-height: 501px) {
  .app { --chrome: 84px; --cgap: 18px; grid-template-columns: auto minmax(0, 330px) minmax(0, 1fr) auto; column-gap: var(--cgap); row-gap: 14px; padding-top: max(16px, env(safe-area-inset-top)); }
  .top-actions { gap: 12px; }
}

/* Start screen in landscape: the choice left, the big button right, so "Spelen!" needs no scrolling. */
@media (orientation: landscape) and (min-width: 600px) and (max-height: 820px) {
  .start-card {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 300px);
    grid-template-areas: "logo actions" "best actions" "form actions";
    align-content: center;
    justify-items: center;
    align-items: center;
    gap: 10px 32px;
    width: min(780px, 100%);
    margin: 0 auto;
    padding-top: max(16px, env(safe-area-inset-top));
  }
  .start-logo { grid-area: logo; }
  .start-logo h1 { font-size: clamp(2.6rem, 11vh, 4.6rem); }
  .start-best { grid-area: best; }
  .start-form { grid-area: form; }
  .start-actions { grid-area: actions; gap: 12px; width: 100%; }
  .start-actions #start-btn { padding-top: 20px; padding-bottom: 20px; font-size: 1.5rem; }
  .help, .start-card .start-utils { grid-column: 1 / -1; margin-top: 0; }
  .start-ground { flex-basis: clamp(80px, 22vh, 200px); --s: min(7vh, 48px); }
}
/* the game-over card in two columns where the screen is low, so both buttons are on screen */
@media (orientation: landscape) and (max-height: 600px) {
  .overlay .end-card {
    width: min(580px, 100%);
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas: "icon text" "title text" "stars text" "score actions" "stickers actions";
    align-items: center;
    gap: 6px 20px;
  }
  .overlay .over-icon { grid-area: icon; }
  .overlay .over-title { grid-area: title; }
  .overlay .over-stars { grid-area: stars; }
  .overlay .over-score { grid-area: score; }
  .overlay .over-text { grid-area: text; }
  .overlay .new-stickers { grid-area: stickers; }
  .overlay .over-actions { grid-area: actions; margin-top: 0; }
}
@media (orientation: landscape) and (max-height: 500px) {
  .start-mascot { width: 48px; height: 48px; top: -30px; }
}

@media (prefers-reduced-motion: reduce) {
  .pillar i, .start-mascot, .start-mascot .die, .start-fall, .flyers span, .spider, .new-stickers, .marquee i { animation: none !important; }
  .banner { animation-name: fade !important; }
  .cells.flash span:nth-child(-n + 5), .level.bump svg { animation: none; }
}
@keyframes fade { 0% { opacity: 0; transform: translateX(-50%); } 10%, 80% { opacity: 1; transform: translateX(-50%); } 100% { opacity: 0; transform: translateX(-50%); } }

/* ---- Phones upright: one compact strip above the machine, so the dice get the room ----
   Bewaar, Nu, Straks and the rise counter sit side by side; the machine's pillars, padding and
   arch shrink. --chrome is measured for this layout (see tools in the README: smoke test). */
@media (orientation: portrait) and (max-width: 560px) {
  .app { --chrome: 226px; padding: 10px 10px 24px; gap: 10px; }
  .tray { flex-direction: row; align-items: stretch; gap: 8px; padding: 6px 8px 8px; }
  .tray-slots { flex: 3; grid-template-columns: 1fr 1.15fr 1fr; gap: 6px; align-items: end; }
  .slot { gap: 2px; }
  .slot .label { font-size: 0.82rem; line-height: 1.1; }
  .slot-well { padding: 4px; border-radius: 12px; }
  .slot-die { width: 38px; height: 38px; }
  .slot-die.small { width: 30px; height: 30px; margin: 4px 0; }
  .slot--current .slot-die { width: 46px; height: 46px; }
  .slot--rise { flex: 1.05; flex-direction: column; justify-content: flex-end; align-items: stretch; gap: 4px; min-width: 0; }
  .slot--rise .label { text-align: center; }
  .slot--rise .label .art { display: none; }
  .rise-count { order: -1; text-align: center; font-size: 1.5rem; }
  .rise-bar { flex: none; height: 10px; }
  .machine { padding: 18px 6px 10px; grid-template-columns: 14px auto 14px; gap: 6px; border-radius: 24px; }
  .pillar i { width: 9px; height: 9px; }
  .board { width: min(calc(100vw - 76px), 380px, max(var(--board-min, 200px), calc((100vh - var(--chrome) - var(--top-room)) * var(--cols) / var(--rows)))); }
  .board { width: min(calc(100vw - 76px), 380px, max(var(--board-min, 200px), calc((100dvh - var(--chrome) - var(--top-room)) * var(--cols) / var(--rows)))); }
  .machine.top-arch { --top-room: 36px; }
  .arch { top: -34px; height: 60px; padding-top: 6px; }
  .arch span { font-size: 1.05rem; }
}
@media (orientation: portrait) and (max-width: 560px) and (max-height: 720px) {
  .app { --chrome: 218px; padding-top: 6px; gap: 8px; }
}
@media (orientation: portrait) and (max-width: 560px) and (max-height: 600px) {
  .app { --chrome: 212px; }
  .slot-die { width: 32px; height: 32px; }
  .slot--current .slot-die { width: 40px; height: 40px; }
  .slot-die.small { width: 26px; height: 26px; }
}

/* ---- Desktop: a big screen (the same test as html.desktop in assets/arcade.js) ----
   Three columns over the hall: on the left the back button, the score card and the drawer (Bewaar, Nu, Straks and
   the rising row) standing against the machine; the machine in the middle at the full height; on the right the
   round buttons and, with a mouse (html.mouse), the keys. A big tablet on its side gets the same layout without the
   keys. Everything scales with --ui (assets/style.css). The start screen is two columns at any height, the
   game-over card covers the screen in two columns. */
.start-hero, .key-card { display: none; }
@media (hover: hover) and (pointer: fine) {
  .slot--hold:not(.used):hover .slot-well { filter: brightness(1.08); }
  .slot--hold:focus-visible { outline: 4px solid #fff; outline-offset: 3px; border-radius: 18px; }
}
@media (min-width: 1100px) and (min-height: 650px) {
  html.mouse .help .keys-line { display: none; }
  /* the pill's buttons as assets/style.css means them on desktop (its 44px base rule comes later in that file and wins) */
  :is(#start, body) .app .topbar .top-actions > .icon-btn { width: calc(52px * var(--ui)); height: calc(52px * var(--ui)); font-size: calc(1.4rem * var(--ui)); }
  .app {
    --pad-y: calc(14px * var(--ui));
    --side-in: min(100%, calc(290px * var(--ui)));
    --die: clamp(56px, 7.2vh, 104px);
    --cgap: calc(30px * var(--ui));
    /* around the board: the padding, the machine's padding and rim, the feet under it */
    --chrome: calc(2 * var(--pad-y) + 76px);
    height: 100vh;
    height: 100dvh;
    max-width: none;
    grid-template-columns: minmax(calc(230px * var(--ui)), 1fr) auto minmax(calc(230px * var(--ui)), 1fr);
    grid-template-rows: auto auto minmax(0, 1fr);
    grid-template-areas: "back machine actions" "score machine keys" "tray machine keys";
    align-items: start;
    column-gap: var(--cgap);
    row-gap: calc(16px * var(--ui));
    padding: var(--pad-y) max(calc(20px * var(--ui)), env(safe-area-inset-right)) var(--pad-y) max(calc(20px * var(--ui)), env(safe-area-inset-left));
    overflow: hidden;
  }
  :is(#start, body) .app .topbar .top-actions { grid-area: actions; flex-direction: row; justify-self: end; }

  /* the score card: score, best and level, big */
  .scorebox {
    grid-area: score;
    justify-self: end;
    width: var(--side-in);
    grid-template-columns: auto 1fr auto;
    column-gap: calc(12px * var(--ui));
    padding: calc(12px * var(--ui)) calc(16px * var(--ui)) calc(14px * var(--ui));
  }
  .scorebox .crown { display: block; font-size: calc(2.1rem * var(--ui)); }
  .scorebox .value, .scorebox .sub { grid-column: 2; }
  .scorebox .value { font-size: calc(2.9rem * var(--ui)); }
  .scorebox .sub { font-size: calc(18px * var(--ui)); margin-top: calc(4px * var(--ui)); }
  .level { grid-column: 3; width: calc(84px * var(--ui)); height: calc(84px * var(--ui)); }
  .level > span { font-size: calc(18px * var(--ui)); }
  .level b { font-size: calc(30px * var(--ui)); }

  /* the drawer: Bewaar, Nu and Straks with big dice and the rising row under them; it slides out of the
     machine's side (over the gap, under the machine's rim) */
  .tray {
    grid-area: tray;
    justify-self: end;
    align-self: start;
    width: calc(var(--side-in) + var(--cgap));
    margin-right: calc(-1 * var(--cgap));
    padding: calc(14px * var(--ui)) calc(14px + var(--cgap)) calc(18px * var(--ui)) calc(16px * var(--ui));
    gap: calc(14px * var(--ui));
    border-radius: 26px 0 0 26px;
  }
  .tray.panel::after { left: 12px; top: 50%; bottom: auto; width: 8px; height: 64px; margin: -32px 0 0; border-radius: 8px 0 0 8px; background: linear-gradient(90deg, #9aa7bd, #eef2f8); }
  .tray-slots { gap: calc(10px * var(--ui)); }
  .slot { gap: calc(6px * var(--ui)); }
  .slot .label { font-size: calc(18px * var(--ui)); }
  .slot-well { padding: calc(8px * var(--ui)); border-radius: calc(18px * var(--ui)); }
  .slot-die { width: var(--die); height: var(--die); }
  .slot--current .slot-die { width: calc(var(--die) * 1.16); height: calc(var(--die) * 1.16); }
  .slot-die.small { width: calc(var(--die) * 0.78); height: calc(var(--die) * 0.78); margin: calc(var(--die) * 0.11) 0; }
  .slot--rise { gap: calc(10px * var(--ui)); }
  .rise-count { font-size: calc(1.6rem * var(--ui)); }
  .rise-bar { height: calc(18px * var(--ui)); }

  /* the machine at the full height, in the middle */
  .machine { grid-area: machine; grid-row: 1 / -1; justify-self: center; align-self: center; grid-template-columns: calc(22px * var(--ui)) auto calc(22px * var(--ui)); }
  .pillar i { width: calc(14px * var(--ui)); height: calc(14px * var(--ui)); }
  .board {
    width: min(calc(100vw - 2 * (230px * var(--ui) + var(--cgap)) - 120px), max(var(--board-min, 200px), calc((100dvh - var(--chrome) - var(--top-room)) * var(--cols) / var(--rows))));
    border-radius: calc(20px * var(--ui));
  }
  .cells, .layer { inset: calc(8px * var(--ui)); }
  .cells span { margin: calc(3px * var(--ui)); border-radius: calc(12px * var(--ui)); }
  .popup { font-size: calc(1.15rem * var(--ui)); }
  .banner { font-size: calc(1.6rem * var(--ui)); }
  .levelup { font-size: calc(2.1rem * var(--ui)); }
  .toast { font-size: calc(1.15rem * var(--ui)); }
  .corner { font-size: calc(2.8rem * var(--ui)); }
  .flyers span { font-size: calc(1.6rem * var(--ui)); }

  /* the keys, next to the machine on the right */
  .key-card {
    grid-area: keys;
    justify-self: start;
    align-self: start;
    width: var(--side-in);
    display: flex;
    flex-direction: column;
    gap: calc(10px * var(--ui));
    padding: calc(14px * var(--ui)) calc(18px * var(--ui)) calc(16px * var(--ui));
    font-size: calc(18px * var(--ui));
    color: var(--muted);
    font-weight: 600;
    line-height: 1.3;
  }
  .key-title { margin: 0; color: var(--ink); font-weight: 700; font-size: calc(20px * var(--ui)); }
  .key-card ul { margin: 0; padding: 0; list-style: none; display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: calc(9px * var(--ui)) calc(12px * var(--ui)); }
  .key-card li { display: contents; }
  .key-card .keys { display: inline-flex; gap: calc(4px * var(--ui)); }
  .key-card kbd { display: inline-grid; place-items: center; min-width: 1.9em; height: 1.75em; padding: 0 0.4em; font-size: 0.95em; font-weight: 700; }
  .key-mouse { margin: 0; padding-top: calc(8px * var(--ui)); border-top: 2px dashed var(--cream-2); }
  /* a touch screen has no keys to show */
  html:not(.mouse) .key-card { display: none; }

  /* game over: the whole screen, a wide card in two columns */
  .overlay { position: fixed; z-index: 40; padding: calc(24px * var(--ui)); }
  .overlay .end-card {
    width: min(100%, calc(660px * var(--ui)));
    max-height: calc(100dvh - 48px);
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
    grid-template-areas: "icon text" "title text" "stars text" "score actions" "stickers actions";
    align-items: center;
    gap: calc(10px * var(--ui)) calc(28px * var(--ui));
    padding: calc(24px * var(--ui)) calc(28px * var(--ui));
  }
  .overlay .over-icon { grid-area: icon; }
  .overlay .over-icon .die { width: calc(84px * var(--ui)); height: calc(84px * var(--ui)); }
  .overlay .over-icon .art { width: calc(84px * var(--ui)); height: calc(84px * var(--ui)); }
  .overlay .over-title { grid-area: title; font-size: calc(1.8rem * var(--ui)); }
  .overlay .over-stars { grid-area: stars; }
  .overlay .over-stars span { width: calc(46px * var(--ui)); height: calc(46px * var(--ui)); }
  .overlay .over-stars span:nth-child(2) { width: calc(58px * var(--ui)); height: calc(58px * var(--ui)); margin-top: calc(-8px * var(--ui)); }
  .overlay .over-score { grid-area: score; font-size: calc(4rem * var(--ui)); }
  .overlay .over-text { grid-area: text; font-size: calc(19px * var(--ui)); text-align: left; }
  .overlay .new-stickers { grid-area: stickers; font-size: calc(18px * var(--ui)); }
  .overlay .new-stickers .art { width: calc(40px * var(--ui)); height: calc(40px * var(--ui)); }
  .overlay .over-actions { grid-area: actions; margin-top: 0; padding: 0; position: static; background: none; gap: calc(14px * var(--ui)); }
  .overlay .over-actions .btn { min-height: calc(60px * var(--ui)); font-size: calc(1.25rem * var(--ui)); border-radius: calc(20px * var(--ui)); }

  /* the start screen: the title, the record and the choice left; the dice tower and the big button right */
  .start-card {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, calc(320px * var(--ui)));
    grid-template-areas: "logo hero" "best hero" "form actions";
    align-content: center;
    justify-items: center;
    align-items: center;
    gap: calc(16px * var(--ui)) calc(48px * var(--ui));
    width: min(94vw, calc(880px * var(--ui)));
    margin: 0 auto;
    padding: calc(28px * var(--ui)) 16px calc(12px * var(--ui));
  }
  .start-logo { grid-area: logo; }
  .start-logo h1 { font-size: calc(5.2rem * var(--ui)); }
  .start-mascot { width: calc(66px * var(--ui)); height: calc(66px * var(--ui)); right: calc(-26px * var(--ui)); top: calc(-46px * var(--ui)); }
  .start-best { grid-area: best; font-size: calc(1.3rem * var(--ui)); padding: calc(8px * var(--ui)) calc(22px * var(--ui)); }
  .start-form { grid-area: form; width: 100%; padding: calc(14px * var(--ui)) calc(18px * var(--ui)) calc(18px * var(--ui)); gap: calc(12px * var(--ui)); }
  .start-form .label { font-size: calc(19px * var(--ui)); }
  .targets { gap: calc(12px * var(--ui)); }
  .targets button { min-height: calc(76px * var(--ui)); font-size: calc(23px * var(--ui)); border-radius: calc(18px * var(--ui)); }
  .targets button small { font-size: calc(18px * var(--ui)); }
  .start-actions { grid-area: actions; width: 100%; gap: calc(12px * var(--ui)); }
  .start-actions #start-btn { padding: calc(24px * var(--ui)) 20px; font-size: calc(1.8rem * var(--ui)); border-radius: calc(24px * var(--ui)); }
  .help, .start-card .start-utils { grid-column: 1 / -1; margin-top: calc(6px * var(--ui)); }
  .start-hero {
    --hs: calc(86px * var(--ui));
    grid-area: hero;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: calc(6px * var(--ui));
    filter: drop-shadow(0 calc(10px * var(--ui)) calc(10px * var(--ui)) rgba(60, 30, 110, 0.22));
  }
  .start-hero > div { display: flex; gap: calc(6px * var(--ui)); }
  .start-hero .die { width: var(--hs); height: var(--hs); padding: 0; }
  .start-hero > div:first-child .die { animation: tumble 4.8s ease-in-out 1.6s infinite; }
  .start-ground { flex: 0 1 clamp(90px, 18vh, 260px); --s: min(7vh, calc(54px * var(--ui))); }
}
@media (min-width: 1100px) and (min-height: 650px) and (prefers-reduced-motion: reduce) {
  .start-hero > div:first-child .die { animation: none; }
}
