@font-face {
  font-family: "Bungee";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/bungee-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Bungee";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/bungee-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
* { box-sizing: border-box; }
:root {
  --ink: #140d1e;
  --bg: #0f0a18;
  --panel: #1b1436e6;
  --line: #ffffff2e;
  --text: #f3ecff;
  --muted: #b9a9cf;
  --gold: #ffd23f;
  --ember: #e0663f;
  --mine: #c58cff;
  /* drawn UI icons, one source each: chunky ink outline + highlight, same family as the game art */
  --lock: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 22'%3E%3Cpath d='M6 11V7.5a4 4 0 0 1 8 0V11' fill='none' stroke='%23140d1e' stroke-width='5' stroke-linecap='round'/%3E%3Cpath d='M6 11V7.5a4 4 0 0 1 8 0V11' fill='none' stroke='%23ddd2f2' stroke-width='2' stroke-linecap='round'/%3E%3Crect x='2' y='11' width='16' height='11' rx='3' fill='%23140d1e' opacity='.6'/%3E%3Crect x='2' y='9' width='16' height='11' rx='3' fill='%23a993d1' stroke='%23140d1e' stroke-width='1.6'/%3E%3Cpath d='M3.6 16.4h12.8v.8a1.9 1.9 0 0 1-1.9 1.9H5.5a1.9 1.9 0 0 1-1.9-1.9z' fill='%237a64a8'/%3E%3Crect x='4.2' y='10.6' width='11.6' height='2' rx='1' fill='%23f3edff' opacity='.8'/%3E%3Ccircle cx='10' cy='14.4' r='1.7' fill='%23140d1e'/%3E%3Crect x='9.25' y='14.8' width='1.5' height='2.9' rx='.6' fill='%23140d1e'/%3E%3C/svg%3E");
  --check: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.4 6.4l2.4 2.4 4.8-5.2' fill='none' stroke='%23140d1e' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 18 18'%3E%3Ccircle cx='9' cy='9' r='7.6' fill='%23ffd23f' stroke='%23140d1e' stroke-width='1.8'/%3E%3Cpath d='M4.6 6.2a5 5 0 0 1 3-2.4' fill='none' stroke='%23fff6c0' stroke-width='1.4' stroke-linecap='round'/%3E%3Cpath d='M7.6 5.6L11 9l-3.4 3.4' fill='none' stroke='%23140d1e' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  --spark: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 14'%3E%3Cpath d='M7 .8l1.6 4.6L13.2 7 8.6 8.6 7 13.2 5.4 8.6.8 7l4.6-1.6z' fill='%23ffd23f' stroke='%23140d1e' stroke-width='1.2' stroke-linejoin='round'/%3E%3C/svg%3E");
}
/* palette for every native scrollbar the menus can show (still native scrolling) */
#start, #over, .start-grid > .card { scrollbar-color: #c58cffa0 #ffffff0d; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(120% 80% at 50% 100%, #2a1a3f 0%, var(--bg) 70%);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  overscroll-behavior: none;
}
h1, .display, #hud, #pause, #over-score, button { font-family: "Bungee", "Impact", system-ui, sans-serif; }

body { display: grid; place-items: center; }
#wrap {
  position: relative;
  /* fit 16:9 into the viewport, whichever side limits */
  width: min(100vw, calc(100vh * 16 / 9));
  aspect-ratio: 16 / 9;
  box-shadow: 0 30px 80px #000a;
}
canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #1b1436;
  touch-action: none;
}

/* --- HUD --- */
#hud {
  position: absolute;
  top: 12px;
  left: 16px;
  font-size: 30px;
  line-height: 1;
  color: var(--gold);
  -webkit-text-stroke: 1px var(--ink);
  text-shadow: 0 3px 0 var(--ink), 0 6px 16px #0008;
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 12px;
}
.badge.starmulti { border-color: #7cf0ff; color: #c9f7ff; background: #7cf0ff33; }
.badge.multi { border-color: #ff5fd2; color: #ffb3ea; background: #ff5fd233; }
#hud .score { display: flex; flex-direction: column; gap: 4px; }
#hud .score b { font-weight: inherit; }
#hud .score small { font-size: 13px; letter-spacing: .06em; color: var(--text); -webkit-text-stroke: 0; text-shadow: 0 2px 0 var(--ink); }
.badge.magnet { border-color: #ff9de2; color: #ffd6f3; background: #ff9de233; }
.badge.wings { border-color: #f4f6ff; color: #ffffff; background: #f4f6ff33; }
.badge {
  font: 700 12px/1 system-ui, sans-serif;
  letter-spacing: .08em;
  text-transform: uppercase;
  padding: 5px 9px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  -webkit-text-stroke: 0;
  text-shadow: none;
}

/* --- corner panel --- */
#corner {
  position: absolute;
  top: 12px;
  right: 16px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  font-size: 13px;
}
#corner button { min-height: 30px; padding: 0 12px; font-size: 12px; }
#board {
  list-style: decimal;
  margin: 0;
  padding: 6px 10px 6px 2em;
  min-width: 160px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  backdrop-filter: blur(4px);
}
#board:empty { display: none; }
#board li { display: flex; justify-content: space-between; gap: 12px; }
#board li:first-child { color: var(--gold); }
#board b { color: var(--text); font-variant-numeric: tabular-nums; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; box-shadow: 0 0 6px currentColor; }
.dot.mine { background: var(--mine); color: var(--mine); }
.dot.ghost { background: var(--gold); color: var(--gold); }
#ghost-nick[hidden] { display: none; }
.pill.static { cursor: default; color: var(--text); border-color: #ffd23f88; }
.pill.static .dot { opacity: 1; }
.ghosts { display: flex; align-items: center; gap: 8px; }
.pill {
  display: inline-flex; align-items: center;
  font: 700 12.5px/1.25 system-ui, sans-serif;
  letter-spacing: .06em; text-transform: uppercase;
  padding: 7px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--panel);
  color: var(--muted); cursor: pointer; user-select: none;
  transition: background .12s, color .12s, border-color .12s;
}
.pill input { position: absolute; opacity: 0; width: 0; height: 0; }
.pill .dot { opacity: .35; box-shadow: none; }
.pill:has(input:checked) { background: #c58cff33; border-color: var(--mine); color: var(--text); }
.pill:has(input:checked) .dot { opacity: 1; box-shadow: 0 0 6px currentColor; }
.pill:has(input:focus-visible) { outline: 2px solid var(--gold); outline-offset: 2px; }
/* room ghost's name: an informational tag, deliberately not shaped like a control */
.pill.static { border-color: transparent; background: #0f0a18b3; box-shadow: none; text-transform: none; letter-spacing: .03em; }
/* own-ghost toggle: a tactile squared-round key with a drawn checkbox, pressed like the arcade buttons */
.pill.toggle {
  gap: 7px;
  border: 2px solid var(--ink);
  border-radius: 9px;
  background: linear-gradient(#ffffff14, #ffffff00), var(--panel);
  box-shadow: inset 0 1px 0 #ffffff1f, 0 3px 0 var(--ink);
  transition: transform .08s, box-shadow .08s, background .12s, color .12s;
}
.pill.toggle::before {
  content: '';
  flex: none;
  width: 14px; height: 14px;
  border: 2px solid var(--ink);
  border-radius: 4px;
  background: #ffffff1f;
  box-shadow: inset 0 1px 0 #ffffff2e;
}
.pill.toggle:hover { color: var(--text); }
.pill.toggle:active { transform: translateY(2px); box-shadow: inset 0 1px 0 #ffffff1f, 0 1px 0 var(--ink); }
.pill.toggle:has(input:checked) { background: linear-gradient(#ffffff1a, #ffffff00), #4a2f72; border-color: var(--ink); color: var(--text); box-shadow: inset 0 0 0 1px var(--mine), 0 3px 0 var(--ink); }
.pill.toggle:has(input:checked)::before { background: var(--check) center / 11px no-repeat, var(--mine); }

/* --- overlays --- */
/* overlays are designed at 960×540; --ui (set from JS) scales them with the wrap.
   Menus use --ui-menu, additionally capped by height so tall cards fit on screen. */
#pause, #hud, #corner { zoom: var(--ui, 1); }
#start, #over { zoom: var(--ui-menu, 1); }
#over, #pause, #start {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
  text-align: center;
  background: #0f0a18cc;
  backdrop-filter: blur(3px);
}
#over[hidden], #pause[hidden], #start[hidden] { display: none; }

#over-score { font-size: 28px; color: var(--gold); text-shadow: 0 3px 0 var(--ink); }
#top {
  list-style: decimal;
  padding: 8px 12px 8px 2.2em;
  margin: 0;
  max-width: 340px;
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}
#top li { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; border-bottom: 1px dashed var(--line); }
#top li:last-child { border-bottom: 0; }
#top li:first-child { color: var(--gold); }

#pause { font-size: 48px; color: var(--text); letter-spacing: .05em; }
#pause .btns { margin-top: 8px; }
#pause small { font: 14px system-ui, sans-serif; color: var(--muted); }

#start h1 {
  margin: 0;
  font-size: clamp(44px, 9vw, 84px);
  line-height: 1;
  color: var(--gold);
  letter-spacing: .04em;
  -webkit-text-stroke: 2px var(--ink);
  text-shadow: 0 6px 0 var(--ink), 0 10px 0 var(--ember), 0 20px 40px #000a;
  animation: drop .5s cubic-bezier(.2,1.4,.4,1) both;
}
/* centered while it fits, scrolls from the top edge when it doesn't */
#start { overflow-y: auto; justify-content: flex-start; }
.start-grid { margin: auto; }
#start p { margin: 0; color: var(--muted); }
/* the #start p reset wins on specificity — restore section-label spacing */
#start .skin-label { margin: 10px 0 6px; }
#start .card h2 + .skin-label { margin-top: 2px; }
#start .card .hint { margin: 8px 0 10px; }
#start .tag { font-size: 18px; color: var(--text); margin-bottom: 8px; }
#start .keys { display: flex; gap: 8px; align-items: center; font-size: 13px; margin-top: 6px; }
#start .keys .hint-fine { display: contents; }
.hint-touch { display: none; }
#start .room { margin-top: 2px; }
#start .room { font-size: 13px; }
#start .room b { color: var(--gold); font-weight: 700; }
#start .lang { display: flex; gap: 6px; margin-top: 10px; }
#start .lang button { min-height: 0; padding: 3px 10px; font-size: 11px; background: transparent; color: var(--muted); border-color: var(--line); box-shadow: none; }
#start .lang button[aria-pressed="true"] { color: var(--gold); border-color: var(--gold); }
#start kbd {
  padding: 1px 7px;
  border: 1px solid var(--line);
  border-bottom-width: 3px;
  border-radius: 4px;
  font-size: 13px;
  color: var(--text);
  background: #ffffff10;
}
#start label { color: var(--muted); }
#start input {
  margin-top: 8px;
  padding: 10px 12px;
  width: 240px;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff12;
  color: var(--text);
  font: inherit;
}
#start input:focus { outline: 2px solid var(--gold); outline-offset: 1px; }
.k-block { color: #e06b72; } .k-spike { color: #ffb347; } .k-double { color: #52d98e; } .k-shield { color: #6fd6ff; }

/* --- start layout: side cards + central hero --- */
.start-grid {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 256px;
  gap: 20px;
  align-items: center;
  width: 100%;
  max-width: 940px;
}
.hero { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 18px 20px;
  text-align: left;
  font-size: 13px;
  line-height: 1.55;
  color: var(--muted);
  backdrop-filter: blur(4px);
}
.card h2 {
  margin: 0 0 16px;
  font: 700 12px/1 system-ui, sans-serif;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--gold);
}
.card .hint { margin: 8px 0 10px; font-size: 11px; }
#rooms[hidden] { display: none; }
.side { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; margin: 0; }
.stat-grid dt { font-size: 11px; letter-spacing: .06em; text-transform: uppercase; }
.stat-grid dd { margin: 2px 0 0; font: 700 22px/1 "Bungee", "Impact", system-ui, sans-serif; color: var(--text); font-variant-numeric: tabular-nums; }
.room-list { display: flex; flex-direction: column; gap: 8px; }
.room-list:not(:last-child) { margin-bottom: 4px; }
.room-pill {
  min-height: 0;
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  font: 700 12.5px/1.25 system-ui, sans-serif;
  letter-spacing: .03em;
  text-transform: none;
  text-align: left;
  background: #ffffff0a;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: none;
}
.room-pill b { color: var(--text); }
.room-pill span { font-variant-numeric: tabular-nums; white-space: nowrap; }
.room-pill:hover { color: var(--text); border-color: var(--gold); filter: none; }
.room-pill:active { transform: none; box-shadow: none; }
.room-pill.current { border-color: var(--gold); cursor: default; }
.room-pill.current b { color: var(--gold); }

/* --- cosmetics --- */
#cosmetics { margin-top: 16px; border-top: 1px dashed var(--line); padding-top: 12px; }
#cosmetics summary {
  cursor: pointer;
  font: 700 12px/1.3 system-ui, sans-serif;
  letter-spacing: .08em;
  text-transform: uppercase;
  padding: 2px 0;
  /* drawn palette chevron instead of the native disclosure triangle */
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  border-radius: 6px;
}
#cosmetics summary::-webkit-details-marker { display: none; }
#cosmetics summary::before {
  content: '';
  flex: none;
  width: 18px; height: 18px;
  background: var(--chevron) center / contain no-repeat;
  filter: drop-shadow(0 2px 0 var(--ink));
  transition: transform .15s;
}
#cosmetics[open] summary::before { transform: rotate(90deg); filter: drop-shadow(2px 0 0 var(--ink)); }
#cosmetics summary:hover { color: var(--text); }
#cosmetics summary:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }
/* section labels: separation comes from generous whitespace, not lines */
.skin-label {
  margin: 28px 0 14px;
  font-size: 13px;
  line-height: 1.4;
  text-transform: uppercase;
  letter-spacing: .1em;
  opacity: .75;
}
.card h2 + .skin-label { margin-top: 2px; }
/* fewer, wider columns: long cs/en names and rules get room; rows stretch to one height */
.skin-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 10px 8px; align-items: stretch; }
/* cosmetic tile, a little collectible card: live art in an inset window, name, and the unlock rule
   when locked. Chunky ink outline + drop like the arcade buttons. */
.tile {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 5px 3px 7px;
  border-radius: 10px;
  border: 2px solid var(--ink);
  background: linear-gradient(#ffffff14, #ffffff03 60%), #22183d;
  box-shadow: inset 0 1px 0 #ffffff1f, 0 3px 0 var(--ink);
  color: var(--text); cursor: pointer; user-select: none;
  text-align: center;
  transition: background .12s, color .12s, box-shadow .12s, transform .08s;
}
.tile input { position: absolute; opacity: 0; width: 0; height: 0; }
.tile-art { display: block; width: 52px; height: 32px; border-radius: 6px; box-shadow: 0 0 0 2px var(--ink), 0 0 0 3px #ffffff1a; }
.tile b { font: 700 10.5px/1.15 system-ui, sans-serif; letter-spacing: .02em; margin-top: 2px; color: var(--text); }
.tile.locked b { color: #d3c7e8; }
.tile small { font: 600 10px/1.25 system-ui, sans-serif; color: var(--muted); text-wrap: balance; }
.tile:has(input:checked) { background: linear-gradient(#ffffff1a, #ffffff00 60%), #4a2f72; box-shadow: inset 0 0 0 2px var(--mine), inset 0 3px 0 #ffffff26, 0 3px 0 var(--ink); }
.tile:has(input:checked) b { color: var(--gold); }
.tile:has(input:focus-visible) { outline: 2px solid var(--gold); outline-offset: 2px; }
.tile:hover:not(.locked) { box-shadow: inset 0 0 0 2px #c58cff88, 0 3px 0 var(--ink); }
.tile:not(.locked):active { transform: translateY(2px); box-shadow: inset 0 0 0 2px var(--mine), 0 1px 0 var(--ink); }
.tile.locked { cursor: default; background: linear-gradient(#ffffff0a, #ffffff00 60%), #1a1230; color: var(--muted); }
.tile.locked .tile-art { filter: saturate(.3) brightness(.75); transition: filter .15s; }
.tile.locked.peek .tile-art { filter: none; }
.tile.locked.peek { box-shadow: inset 0 0 0 2px #c58cff88, 0 3px 0 var(--ink); }
/* the lock: one drawn badge pinned to the tile's top-right corner, outside the text flow */
.tile.locked::after {
  content: '';
  position: absolute;
  top: -7px; right: -7px;
  width: 18px; height: 20px;
  background: var(--lock) center / contain no-repeat;
  pointer-events: none;
  transition: transform .15s;
}
.tile.locked.peek::after { transform: rotate(-12deg) scale(1.08); }
.pill.locked { opacity: .45; cursor: default; }
.pill.locked .dot { opacity: .6; }
.hint.warn { color: var(--ember); margin: 6px 0 0; font-size: 11px; }
.progress-code { display: flex; gap: 6px; align-items: center; }
.progress-code code {
  font-size: 11px;
  line-height: 1.4;
  padding: 4px 6px;
  background: #ffffff10;
  border: 1px solid var(--line);
  border-radius: 4px;
  min-width: 0;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.progress-code button { min-height: 26px; padding: 0 10px; font-size: 11px; background: #ffffff10; color: var(--text); border-color: var(--line); box-shadow: 0 2px 0 #0008; }
#start #prog-restore { margin-top: 8px; width: 100%; font-size: 12px; padding: 8px 10px; text-align: left; }

/* reward announcement: a small prize card — sparkly heading, then each unlock as a mini card with its
   own art, name and rule. The visible part is aria-hidden; .sr-only keeps the full sentence. */
.unlock {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  max-width: min(100%, 560px);
  padding: 8px 12px 12px;
  font: 700 13px/1.25 system-ui, sans-serif;
  color: var(--text);
  background: linear-gradient(#ffd23f2b, #ffd23f08 70%), #1d1438;
  border: 2px solid var(--ink);
  border-radius: 14px;
  box-shadow: inset 0 0 0 2px #ffd23f8c, 0 4px 0 var(--ink), 0 10px 26px #0008;
}
.unlock[hidden] { display: none; }
.reward-head {
  display: flex; align-items: center; gap: 7px;
  font: 400 15px/1 "Bungee", "Impact", system-ui, sans-serif;
  letter-spacing: .05em;
  color: var(--gold);
  text-shadow: 0 2px 0 var(--ink);
}
.reward-head::before, .reward-head::after { content: ''; width: 13px; height: 13px; background: var(--spark) center / contain no-repeat; }
.reward-head::after { width: 10px; height: 10px; }
.reward-list { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; max-width: 100%; }
.reward {
  display: flex; align-items: center; gap: 8px;
  max-width: 100%;
  padding: 5px 10px 5px 5px;
  text-align: left;
  border: 2px solid var(--ink);
  border-radius: 10px;
  background: linear-gradient(#ffffff17, #ffffff00 70%), #2e2052;
  box-shadow: inset 0 1px 0 #ffffff24, 0 3px 0 var(--ink);
}
.reward-art { display: block; flex: none; width: 52px; height: 32px; border-radius: 6px; box-shadow: 0 0 0 2px var(--ink); }
.reward span { min-width: 0; }
.reward b { display: block; font: 700 12.5px/1.2 system-ui, sans-serif; color: var(--text); }
.reward small { display: block; font: 600 11px/1.25 system-ui, sans-serif; color: var(--muted); }
#start-unlock { padding: 7px 10px 10px; }

/* #start .queue-badge (not just .queue-badge): `#start p { color: var(--muted) }`
   otherwise wins on id specificity and the badge loses its gold accent */
#start .queue-badge { font-size: 12px; color: var(--gold); }
.queue-badge[hidden] { display: none; }
/* record banner: three tiers, the room record pulses gold */
#record {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 18px; border-radius: 12px;
  border: 1px solid var(--line); background: #ffffff10;
  animation: pop .45s cubic-bezier(.2,1.3,.4,1) both;
}
#record b { font-family: "Bungee", "Impact", system-ui, sans-serif; font-weight: 400; font-size: 18px; letter-spacing: .04em; color: var(--text); }
#record small { font-size: 12px; color: var(--muted); }
#record.personal { border-color: #52d98e88; background: #52d98e22; }
#record.personal b { color: #52d98e; }
#record.room { border-color: var(--gold); background: #ffd23f22; animation: pop .45s cubic-bezier(.2,1.3,.4,1) both, glow 1.6s .45s ease-in-out infinite; }
#record.room b { color: var(--gold); }
#record[hidden] { display: none; }
@keyframes glow { 0%, 100% { box-shadow: 0 0 0 #ffd23f00; } 50% { box-shadow: 0 0 18px #ffd23f88; } }

.btns { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
button {
  min-height: 42px;
  padding: 0 18px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--gold);
  color: var(--ink);
  font-size: 14px;
  letter-spacing: .03em;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--ink);
  transition: transform .08s, box-shadow .08s;
}
button:hover { filter: brightness(1.08); }
button:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
button:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
/* secondary actions: Menu sits behind Again/Resume, which stay the gold primary */
#newroom, #copy, #menu, #pause-btn, #pause-menu { background: var(--panel); color: var(--text); border-color: var(--line); box-shadow: 0 4px 0 #0008; }


/* --- motion --- */
@keyframes drop { from { transform: translateY(-30px) scale(1.1); opacity: 0; } }
@keyframes rise { from { transform: translateY(14px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { 0% { transform: scale(.6); opacity: 0; } 70% { transform: scale(1.12); } 100% { transform: scale(1); opacity: 1; } }
@keyframes shake {
  10%, 90% { transform: translate(-2px, 1px); } 20%, 80% { transform: translate(4px, -2px); }
  30%, 50%, 70% { transform: translate(-6px, 3px); } 40%, 60% { transform: translate(6px, -3px); }
}
@keyframes leave { to { opacity: 0; transform: scale(1.06); } }
@keyframes flash { from { opacity: .9; } to { opacity: 0; } }
@keyframes twirl { from { transform: scale(0) rotate(-120deg); opacity: 0; } }

.hero > * { animation: rise .45s cubic-bezier(.2,.9,.3,1) both; }
.hero > :nth-child(2) { animation-delay: .12s; }
.hero > :nth-child(3) { animation-delay: .2s; }
.hero > :nth-child(4) { animation-delay: .28s; }
.hero > :nth-child(5) { animation-delay: .36s; }
.hero > :nth-child(6) { animation-delay: .44s; }
.hero > :nth-child(7) { animation-delay: .52s; }
/* #queue-badge and #start-unlock (8th/9th): unlike every other .hero child
   they also get toggled from [hidden] well after page load (a flush minutes
   into a session) — display:none->block restarts this animation from its
   delay, so a long delay here would make a live reveal visibly lag behind
   the JS state change. Just enough to land after the Play button (4th,
   .28s) on the rare page load where one is already visible; short enough
   not to noticeably delay a later reveal. */
.hero > :nth-child(8) { animation-delay: .32s; }
.hero > :nth-child(9) { animation-delay: .32s; }
/* reward card springs in once (same short delay as above on the menu), then each prize pops in turn;
   nothing loops, and prefers-reduced-motion switches all of it off */
.hero > .unlock { animation: pop .45s cubic-bezier(.2,1.3,.4,1) .32s both; }
#over > .unlock { animation: pop .45s cubic-bezier(.2,1.3,.4,1) .1s both; }
.reward { animation: pop .4s cubic-bezier(.2,1.4,.4,1) both; animation-delay: calc(.4s + var(--i, 0) * 90ms); }
.reward-head::before { animation: twirl .7s .35s cubic-bezier(.2,1.3,.4,1) both; }
.reward-head::after { animation: twirl .7s .5s cubic-bezier(.2,1.3,.4,1) both; }
.start-grid .card { animation: fade .5s .35s both; }
/* desktop: the skins card scrolls inside the frame instead of being cut off; on phones the whole start screen scrolls */
@media (min-width: 601px) {
  .start-grid { max-height: 100%; }
  .start-grid > .card { max-height: 100%; overflow-y: auto; box-sizing: border-box; scrollbar-width: thin; padding: 14px 16px; }
}
#start.leaving { animation: leave .3s ease-in both; pointer-events: none; }

#over { animation: fade .25s both; }
#over > * { animation: pop .4s cubic-bezier(.2,1.3,.4,1) both; }
#over-score { animation-delay: .15s; }
#top { animation-delay: .3s; }
#over .btns { animation-delay: .45s; }
#top li { animation: rise .35s both; }
#top li:nth-child(1) { animation-delay: .4s; } #top li:nth-child(2) { animation-delay: .46s; } #top li:nth-child(3) { animation-delay: .52s; }
#top li:nth-child(4) { animation-delay: .58s; } #top li:nth-child(5) { animation-delay: .64s; } #top li:nth-child(n+6) { animation-delay: .7s; }

#pause { animation: fade .2s both; }
#pause > * { animation: pop .3s both; }
.badge.starmulti { border-color: #7cf0ff; color: #c9f7ff; background: #7cf0ff33; }
.badge.multi { border-color: #ff5fd2; color: #ffb3ea; background: #ff5fd233; }
.badge { animation: pop .3s cubic-bezier(.2,1.3,.4,1) both; }
#wrap.shake { animation: shake .45s both; }
#flash { position: absolute; inset: 0; background: #ff6a3a; opacity: 0; pointer-events: none; }
#flash.on { animation: flash .35s ease-out both; }
#hud { animation: rise .4s .1s both; }
#corner { animation: fade .4s .2s both; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media (max-width: 600px) {
  #hud { font-size: 22px; }
  #corner { font-size: 12px; }
  #board { min-width: 120px; }
}
/* phones, and any short/narrow window (touch or mouse): menus leave the 16:9 letterbox and take
   the whole screen. #wrap is min(100vw, 100vh*16/9) — the three-column start grid needs that wrap
   width, not raw viewport width, to be at least 960px (measured in a real browser by bisecting
   viewport width/height: the hero column holding "ROLLA" stops overlapping the skins/stats cards
   at wrap width 960px exactly, overlaps at 959px — a hard cutover, not a gradual squeeze, because
   the h1 font-size clamp(44px, 9vw, 84px) hits its 84px ceiling at vw 933px while the grid's two
   fixed side columns (300px + 256px + 40px gaps = 596px) leave the hero only vw-596px). Below
   960px the grid collapses to one column regardless of which dimension (width or height) is the
   one constraining #wrap — hence two conditions, 964px of width or (964 * 9/16 ≈) 542px of height,
   either one meaning #wrap cannot reach 960px; ~4px over the measured 960px breakpoint as margin
   (small on purpose: the cutover is a hard pixel boundary, not a range, so a wide margin would
   just force more ordinary desktop windows into the one-column layout for no reason). */
@media (max-width: 964px), (max-height: 542px) {
  #start, #over { position: fixed; inset: 0; zoom: 1; overflow-y: auto; }
  #start { justify-content: flex-start; padding: max(20px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom)); }
  /* results: centred while they fit, but a taller card (score + record + rewards + board + buttons on a
     landscape phone) must overflow downwards only — justify-content:center would push the score above
     the scroll origin, where no scrolling reaches it. Auto margins centre without that. */
  #over { justify-content: flex-start; padding-top: max(12px, env(safe-area-inset-top)); padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  #over > :first-child { margin-top: auto; }
  #over > :last-child { margin-bottom: auto; }
  .start-grid { grid-template-columns: 1fr; max-width: 460px; gap: 16px; }
  .hero { order: -1; }
  #start h1 { font-size: clamp(44px, 16vw, 64px); }
}
/* same condition as above: once the grid is one column, the per-card internal scroll below (for
   wide #wrap) would squeeze the stacked cards to the screen height; scroll the whole start screen
   instead, as on phones */
@media (max-width: 964px), (max-height: 542px) {
  .start-grid { max-height: none; }
  .start-grid > .card { max-height: none; overflow-y: visible; box-sizing: content-box; padding: 18px 20px; }
}
/* touch: bigger targets and type */
@media (pointer: coarse) {
  .pill { font-size: 14px; padding: 10px 14px; }
  .room-pill { font-size: 14px; padding: 12px 14px; }
  .card { font-size: 14px; }
  .skin-label { font-size: 12.5px; }
  #start button, #over button, #pause button { min-height: 48px; }
  #start input { padding: 12px; font-size: 16px; } /* 16px stops iOS zoom-on-focus */
  /* a touch device has no Space/P keys to name: show the tap wording instead */
  #start .keys .hint-fine, #pause .hint-fine { display: none; }
  #start .keys .hint-touch, #pause .hint-touch { display: inline; }
}
#wrap:has(#start:not([hidden])) :is(#hud, #corner) { visibility: hidden; }

