/* Game styles, scoped under #game-root so they do not leak into the site.
   Token values are copied from the site's styles.css :root.
   No invented hex. No :root or body rules. Cyber theme. */
#game-root {
  --cyber: #0057b8;
  --money: #0e7a5a;
  --ai: #8a2d70;
  --navy: #001c3b;
  --ink: #1f2a33;
  --muted: #55626d;
  --line: #cfd4da;
  --line-strong: #6b7882;
  --bg: #e4e7eb;
  --paper: #ffffff;
  --critical: #b3261e;
  --warn: #7a5a1e;
  --cyber-mid: #006fea;
  --money-mid: #0f8361;
  --ai-mid: #a93789;
  --flag-fam: #46398f;
  --flag-acct: #008a96;
  --cyber-soft: #e8f0f9;
  --money-soft: #ecf4f2;
  --ai-soft: #f3eaf1;
  --neutral-soft: #ebeced;
  --neutral: #2c3842;
  --money-on-grey: #107256;
  --money-dark: #0a5c44;
  --navy-hover: #002b5a;
  --critical-soft: #f8ebeb;
  --warn-soft: #f6f3ef;
  --on-color: var(--paper);
  --ai-on-grey: var(--ai);
  --shadow-1: 0 6px 20px rgb(31 42 51 / 0.08);
  --shadow-2: 0 10px 24px rgb(31 42 51 / 0.12), 0 2px 6px rgb(31 42 51 / 0.06);
  --shadow-3: 0 14px 44px rgb(0 28 59 / 0.35);
  --overlay: rgb(0 28 59 / 0.6);
  --sans: "Atkinson Hyperlegible Next", "AHN Fallback", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --fs-xs: 0.8125rem;
  --fs-sm: 0.9375rem;
  --fs-ui: 1rem;
  --fs-md: 1.0625rem;
  --fs-lg: 1.1875rem;
  --fs-xl: 1.4375rem;
  --fs-2xl: 2rem;
  --fs-2xl-sm: 1.625rem;
  --sp-1: 0.25rem;
  --sp-2: 0.5rem;
  --sp-3: 0.75rem;
  --sp-4: 1rem;
  --sp-5: 1.25rem;
  --sp-6: 1.5rem;
  --sp-7: 2rem;
  --sp-8: 2.5rem;
  --sp-9: 3rem;
  --r-sm: 4px;
  --r-md: 8px;
  --r-lg: 12px;
  --r-pill: 999px;
  --max: 46rem;
  /* Motion tokens (DESIGN.md 5b). */
  --dur-1: 150ms;
  --dur-2: 250ms;
  --dur-3: 400ms;
  --ease: cubic-bezier(.2, 0, 0, 1);
  --accent: var(--cyber);
  --accent-ink: var(--on-color);
  --soft: var(--cyber-soft);
  --brand1: var(--cyber);
  --brand2: var(--ink);
  --link: var(--accent);
  box-sizing: border-box;
  display: block;
  width: 100%;
  max-width: 100%;
  color: var(--ink);
  background: var(--bg);
  font: var(--fs-md) / 1.65 var(--sans);
}

#game-root *,
#game-root *::before,
#game-root *::after { box-sizing: border-box; }

#game-root .skip {
  position: absolute;
  left: -999px;
}
#game-root .skip:focus {
  left: var(--sp-4);
  top: var(--sp-4);
  background: var(--paper);
  padding: var(--sp-2) var(--sp-4);
  z-index: 9;
}

#game-root .game-header {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
  overflow: hidden;
  margin: 0 0 var(--sp-5);
}

#game-root .brand-line {
  display: flex;
  height: 4px;
}
#game-root .brand-line span:nth-child(1) { flex: 1; background: var(--cyber); }
#game-root .brand-line span:nth-child(2) { flex: 1; background: var(--money); }
#game-root .brand-line span:nth-child(3) { flex: 1; background: var(--ai); }

#game-root .header-inner { padding: var(--sp-4) var(--sp-5); }

#game-root .header-row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex-wrap: wrap;
}

#game-root h1 {
  margin: 0;
  font: 600 var(--fs-lg) / 1.2 var(--sans);
  color: var(--ink);
}

#game-root .badge {
  display: inline-block;
  font: 600 var(--fs-xs) / 1 var(--sans);
  padding: 0.35rem var(--sp-2);
  border-radius: var(--r-pill);
  background: var(--warn-soft);
  color: var(--warn);
}

#game-root .muted { color: var(--muted); font-size: var(--fs-sm); margin: var(--sp-2) 0 0; }
/* ==== Round 8: one fixed play frame, full bleed, MystrS on the right ====
   Scott, Nov 12 2026: "make sure i'm facing the box", "i don't want the screen resizing
   based on the text box", "i don't like that my head is cut off or that i have to scroll",
   "can we utilze this area". The play area is sized from the viewport (game.js fitFrame
   sets --play-h and --vw with el.style.setProperty), never from its content. Inside it,
   every row has a fixed size: the chat scrolls in its own box, and the lesson, hints,
   tracker and Trick Book live in the side panel (a column on wide screens, an overlay
   inside the frame on narrow ones). MystrS stands right of the chat on every size, because
   Scott's poses turn to the viewer's left (tools/facing-audit.py). */

/* Pending the site's metal tokens: the approved metal colours (Option B, Nov 12).
   Game-local until src/styles.css :root has them. Decoration only, never text. */
#game-root {
  --metal-gold: #e0b43a;
  --metal-silver: #b4bec8;
  --metal-bronze: #b46a3c;
  --lift: -3px;
  --rise: 12px;
}

/* Full bleed: break out of the site's centred .wrap to the viewport width (--vw is the
   viewport without a scrollbar, so there is never a horizontal scroll). */
#game-root {
  width: min(var(--vw, 100vw), 100vw);
  max-width: none;
  margin-left: calc(50% - min(var(--vw, 100vw), 100vw) / 2);
  margin-right: 0;
  padding: var(--sp-3) clamp(var(--sp-3), 2vw, var(--sp-7)) var(--sp-3);
}
#game-root .play-area {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  height: calc(100vh - 9rem);
  height: var(--play-h, calc(100svh - 9rem));
  min-height: 0;
}
#game-root.is-complete .play-area { height: var(--play-h, calc(100svh - 9rem)); }

/* Header: one compact block of fixed height; long titles and the score never wrap into it. */
#game-root .game-header { margin: 0; flex: none; }
#game-root .header-inner { padding: var(--sp-2) var(--sp-4) var(--sp-2); }
#game-root .header-row { flex-wrap: nowrap; min-width: 0; gap: var(--sp-2) var(--sp-3); }
#game-root .header-row h1 { flex: none; }
#game-root .header-row .badge { flex: none; }
#game-root #level-header { flex: 1 1 auto; min-width: 0; margin: 0; font: 600 var(--fs-sm) / 1.3 var(--sans); white-space: nowrap; }
/* Fixed height (one line; two on phones), so a longer score never resizes the frame. */
#game-root #score-line { margin: var(--sp-1) 0 0; text-align: left; font-size: var(--fs-xs); line-height: 1.3; height: 1.3em; overflow: hidden; color: var(--muted); }
#game-root #score-line .sc { white-space: nowrap; }
#game-root #score-line .sep { padding: 0 var(--sp-1); }
#game-root .codes-note { margin: var(--sp-1) 0 0; line-height: 1.3; }
@media (max-width: 24rem) {
  #game-root #level-header { font-size: var(--fs-xs); }
}
@media (max-width: 39.99rem) {
  #game-root .header-row { flex-wrap: wrap; }
  #game-root #level-header { flex: 1 1 100%; }
  #game-root #score-line { height: 2.6em; }
  #game-root .codes-note { font-size: var(--fs-xs); }
}

/* Level map: fixed height, one dot per level. Done = filled, now = big ring, next = small
   hollow, The Vault = a square; never colour alone, and each dot has its name for readers. */
#game-root .level-map { margin: var(--sp-2) 0 0; height: 16px; overflow: hidden; }
#game-root .level-map ol { list-style: none; margin: 0; padding: 0; display: flex; align-items: center; gap: 3px; height: 16px; }
#game-root .level-map .dot { position: relative; flex: 0 1 12px; min-width: 6px; height: 8px; border-radius: var(--r-pill); border: 1px solid var(--line-strong); background: var(--paper); }
#game-root .level-map .dot.done { background: var(--money); border-color: var(--money-dark); height: 10px; }
/* Round 8c: "you are here" is a filled diamond, so it never reads as a 0 (done = filled pill, next = small ring). */
#game-root .level-map .dot.now { flex: 0 0 10px; min-width: 10px; width: 10px; height: 10px; margin: 0 3px; border-radius: 1px; border: 2px solid var(--navy); background: var(--cyber); transform: rotate(45deg); }
#game-root .level-map .dot.vault { flex: 0 0 12px; height: 12px; border-radius: 2px; border-color: var(--ai); background: var(--ai-soft); }
#game-root .level-map .dot.vault.now { flex: 0 0 10px; width: 10px; height: 10px; border: 2px solid var(--navy); background: var(--ai); transform: rotate(45deg); }

/* The stage: a fixed grid. Container queries size MystrS from the frame, not from content. */
#game-root .stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  gap: var(--sp-3);
  container-type: size;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas: "tools fig" "chat fig" "dock fig";
}
@media (min-width: 60rem) {
  /* Wide (round 8b): the notes get more room (up to 30rem on big screens) and the chat runs from
     the top of the stage; the tools (Hint) sit over MystrS's head, so no empty strip above the chat. */
  #game-root .stage {
    grid-template-columns: clamp(17rem, 24vw, 30rem) minmax(0, 1fr) auto;
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas: "side chat tools" "side chat fig" "side dock fig";
  }
  #game-root .tools { justify-content: center; }
  /* The Vault always has its bar of three buttons: it keeps the row over the chat. */
  #game-root.is-vault .stage { grid-template-areas: "side tools fig" "side chat fig" "side dock fig"; }
  #game-root.is-vault .tools { justify-content: flex-start; }
}
@media (max-width: 39.99rem) {
  #game-root .stage {
    gap: var(--sp-2);
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: minmax(0, 1fr) auto auto;
    grid-template-areas: "chat fig" "tools fig" "dock dock";
  }
  #game-root .tools { align-self: end; flex-wrap: wrap; overflow: visible; }
  #game-root .tools button { font-size: var(--fs-sm); padding: var(--sp-2); }
  #game-root .side-toggle .label-long { display: none; }
}
@media (min-width: 40rem) { #game-root .side-toggle .label-short { display: none; } }
#game-root .tools { grid-area: tools; display: flex; flex-wrap: nowrap; gap: var(--sp-2); align-items: center; min-height: 2.75rem; overflow: hidden; }
#game-root .tools button { padding: var(--sp-2) var(--sp-3); min-height: 2.75rem; }
#game-root .tools .vault-bar { margin: 0; flex-wrap: nowrap; }
@media (min-width: 60rem) {
  #game-root .side-toggle, #game-root .side-head button { display: none; }
}

/* The chat: the panel is fixed; its log scrolls inside and follows the newest line. */
#game-root .panel.chat {
  grid-area: chat;
  position: relative;
  min-height: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#game-root .chat-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--sp-3) var(--sp-4);
  scroll-padding-bottom: var(--sp-3);
}
#game-root .chat-log { list-style: none; margin: 0; padding: 0; font-size: var(--fs-sm); max-height: none; overflow: visible; }
#game-root .chat-log li { margin: 0 0 var(--sp-2); max-width: 92%; overflow-wrap: anywhere; }
#game-root .chat-log li.you { color: var(--muted); margin-right: auto; }
/* Every MystrS line keeps the same box (padding, border, font), so when a newer line arrives the
   older one only changes colour, never size: nothing below it moves. The newest is the speech bubble. */
#game-root .chat-log li.bot {
  position: relative;
  margin-left: auto;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--fs-md);
  line-height: 1.5;
}
#game-root .chat-log li.note { margin-left: auto; margin-right: auto; text-align: center; }
/* Round 8b: a readable line length on big screens (about 70 characters), the log hugging MystrS. */
#game-root .chat-log { max-width: 48rem; margin-left: auto; }
@media (max-width: 39.99rem) {
  /* Phones: tighter padding and the small font, so a line holds more words (after the base rule). */
  #game-root .chat-scroll { padding: var(--sp-2); }
  #game-root .chat-log li { max-width: 100%; }
  #game-root .chat-log li.bot { font-size: var(--fs-sm); line-height: 1.45; padding: var(--sp-2) var(--sp-3); }
  #game-root .chat-log li.you, #game-root .chat-log li.note { font-size: var(--fs-xs); }
}
/* MystrS's newest line: the speech bubble, with a tail toward him (he stands to the right). */
#game-root .chat-log li.bot.is-latest { background: var(--soft); }
#game-root .chat-log li.bot.is-latest::after {
  content: "";
  position: absolute;
  right: -8px;
  top: var(--sp-4);
  width: 14px;
  height: 14px;
  background: var(--soft);
  border-top: 1px solid var(--line);
  border-right: 1px solid var(--line);
  transform: rotate(45deg);
}
#game-root .notice { margin: 0 0 var(--sp-3); }

/* "MystrS is thinking": one-shot dots, then still. */
/* Out of the flow (pinned to the panel's foot), so showing or hiding it moves no chat line. */
#game-root.is-thinking .chat-scroll { padding-bottom: 3.25rem; }
#game-root .think { position: absolute; right: var(--sp-4); bottom: var(--sp-2); z-index: 1; display: flex; align-items: center; gap: var(--sp-2); margin: 0; width: min(24rem, calc(100% - 2 * var(--sp-4))); box-sizing: border-box; padding: var(--sp-2) var(--sp-3); border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--soft); color: var(--muted); font-size: var(--fs-sm); }
#game-root .think[hidden] { display: none !important; }
/* One line, fixed height: a longer status never grows the box (it is pinned at its foot). */
#game-root .think { height: 2.5rem; }
#game-root #think-text { flex: 1 1 auto; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#game-root .think progress { flex: none; }
#game-root .think progress { width: 6rem; height: 0.5rem; accent-color: var(--accent); }
#game-root .dots { display: inline-flex; gap: 4px; }
#game-root .dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--cyber); }

/* The dock (round 8b): two fixed rows, the message box and under it the code box with its
   three tries. Both are always there, so nothing ever shows, hides or moves in the frame. */
#game-root .stage { --dock-h: 6.25rem; }
@media (max-width: 39.99rem) { #game-root .stage { --dock-h: 6rem; } }
#game-root .dock { grid-area: dock; position: relative; min-width: 0; height: var(--dock-h); align-self: end; display: grid; grid-template-rows: 1fr 1fr; gap: var(--sp-2); }
#game-root .dock form { margin: 0; padding: 0; border: 0; min-width: 0; display: grid; grid-template-columns: 4.75rem minmax(0, 1fr); align-items: center; gap: 0 var(--sp-2); }
#game-root .dock label { margin: 0; white-space: nowrap; }
#game-root .dock .input-row { height: 2.75rem; align-items: stretch; }
#game-root .dock .input-row input[type="text"] { padding: var(--sp-2) var(--sp-3); }
#game-root .dock .input-row button { padding: var(--sp-2) var(--sp-4); min-width: 5rem; }
#game-root .code-form .input-row input[type="text"]::placeholder { text-transform: none; letter-spacing: normal; }
#game-root.is-gated .dock .code-form { box-shadow: 0 0 0 2px var(--money); border-radius: var(--r-md); background: var(--money-soft); }
#game-root .gate-note { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
/* Tries: three pips, lit = a try left (filled), used = an empty ring. Shape, not colour alone,
   and the live note says it in words. */
#game-root .pips { flex: none; display: inline-flex; align-items: center; gap: 5px; padding: 0 var(--sp-1); }
#game-root .pips[hidden] { display: none; }
#game-root .pip { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--line-strong); background: transparent; box-sizing: border-box; }
#game-root .pip.on { border-color: var(--money-dark); background: var(--money); }
#game-root .tries-note { position: absolute; right: 0; bottom: calc(100% + 2px); margin: 0; font-size: var(--fs-xs); line-height: 1.2; color: var(--muted); white-space: nowrap; pointer-events: none; }
#game-root .dock .code-form { position: relative; }
#game-root .dock .code-form.is-free .tries-note { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
@media (min-width: 40rem) {
  /* Wide: "Code" over "3 tries left" in the label column, beside the box; the row keeps its height. */
  #game-root .dock .code-form { grid-template-rows: 1fr 1fr; }
  #game-root .dock .code-form label { grid-column: 1; grid-row: 1; align-self: end; line-height: 1.15; }
  #game-root .dock .code-form .input-row { grid-column: 2; grid-row: 1 / 3; }
  #game-root .tries-note { position: static; grid-column: 1; grid-row: 2; align-self: start; }
}
@media (max-width: 39.99rem) {
  /* Phones: the labels and the tries words stay for screen readers; the boxes show placeholders. */
  #game-root .dock form { grid-template-columns: minmax(0, 1fr); }
  #game-root .dock label, #game-root .tries-note { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
  #game-root .dock .input-row button { padding: var(--sp-2) var(--sp-3); min-width: 4.25rem; }
}

/* MystrS: one stack, one foot line, one figure height; centred in his area, never cut off.
   The height comes from the frame (container query units), so he always fits head to feet. */
#game-root .portrait {
  grid-area: fig;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  --fig-h: min(calc(100cqh - var(--sp-2)), 36rem);
  --fig-w: calc(var(--fig-h) * 0.548);
}
@media (min-width: 60rem) {
  /* Wide: MystrS shares his column with the tools row above him. */
  #game-root .portrait { --fig-h: min(calc(100cqh - 2.75rem - var(--sp-3) - var(--sp-2)), 36rem); }
  #game-root.is-vault .portrait { --fig-h: min(calc(100cqh - var(--sp-2)), 36rem); }
}
@media (max-width: 39.99rem) {
  /* Phones: MystrS beside the chat, full figure, as tall as the chat and tools rows. */
  /* Round 8b: capped lower so the chat beside him gets more words per line. */
  #game-root .portrait { --fig-h: clamp(8rem, calc(100cqh - var(--dock-h) - var(--sp-2) * 2), 12.5rem); align-self: end; }
}
#game-root .fig-stack { position: relative; height: var(--fig-h); width: var(--fig-w); flex: none; }
#game-root .fig-stack .fig { position: absolute; bottom: 0; height: 100%; width: auto; max-width: none; opacity: 0; }
#game-root .fig-stack .fig.is-on { opacity: 1; }
/* Offsets from tools/build-art.py (dev/art-r8.json): every body centre on one line. */
#game-root .fig-idle { left: calc(var(--fig-h) * 0.1854); }
#game-root .fig-talk { left: calc(var(--fig-h) * 0); }
#game-root .fig-tricked { left: calc(var(--fig-h) * 0.1687); }
#game-root .fig-defended { left: calc(var(--fig-h) * 0.1712); }
#game-root .fig-win { left: calc(var(--fig-h) * 0.133); }
#game-root .fig-calm { left: calc(var(--fig-h) * 0.1673); }
#game-root .fig-vault { left: calc(var(--fig-h) * 0.1704); }
#game-root .fig-finale { left: calc(var(--fig-h) * 0.0895); }

/* The side panel: lesson, hints, tracker, Trick Book, badges. It scrolls inside itself. */
#game-root .side {
  grid-area: side;
  position: relative;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  contain: size;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
  padding: var(--sp-3) var(--sp-4);
}
#game-root .side-body { position: relative; flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
#game-root .side-body > * + * { margin-top: var(--sp-3); }
#game-root .side-head, #game-root .side .game-footer { flex: none; }
#game-root .side-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); }
#game-root .side-head h2 { margin: 0; font-size: var(--fs-md); color: var(--navy); }
@media (max-width: 39.99rem) {
  /* Phones: the notes overlay covers the chat and tools, never MystrS or the message box. */
  /* Round 8b: it also reaches up over the game header (never over MystrS or the two boxes),
     so the notes and the lesson get the frame's full height. Close puts the header back. */
  #game-root .side { grid-row: 1 / 3; grid-column: 1 / 2; padding: var(--sp-2) var(--sp-3); margin-top: calc(-1 * var(--head-h, 0px)); }
  #game-root .side { gap: var(--sp-2); }
  #game-root .side-head button { min-height: 2.25rem; padding: var(--sp-1) var(--sp-3); }
  /* While the lesson shows, its Next is what matters: Start over waits until the next level. */
  #game-root.is-won .side .game-footer { display: none; }
  #game-root .side .lesson { padding: var(--sp-2) var(--sp-3); }
}
@media (max-width: 59.99rem) {
  /* Narrow: the side panel is an overlay over the tools and chat, inside the frame. */
  #game-root .side { z-index: 5; box-shadow: var(--shadow-2); display: none; }
  #game-root.side-open .side { display: flex; }
}
@media (min-width: 40rem) and (max-width: 59.99rem) {
  #game-root .side { grid-row: 1 / 3; grid-column: 1 / 2; }
}
#game-root .side .lesson { margin: 0; }
/* Next stays in view at the foot of the notes while the lesson is showing. */
#game-root .side .lesson .actions { position: sticky; bottom: 0; margin-top: var(--sp-2); padding: var(--sp-2) 0 0; background: inherit; }
#game-root .side .tracker { margin: 0; grid-template-columns: 1fr; }
#game-root .side .tracker h2 { grid-column: auto; }
#game-root .side .trick-book { margin: 0; }
#game-root .game-footer .is-pending { visibility: hidden; }
#game-root .side .game-footer { margin: 0; padding-top: var(--sp-2); border-top: 1px solid var(--line); display: grid; gap: var(--sp-2); justify-items: start; }

/* Badges shelf: every badge keeps its name (the metal colours are never the only cue). */
#game-root .badge-shelf h2 { margin: 0 0 var(--sp-2); font-size: var(--fs-md); color: var(--navy); }
#game-root .badge-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(5.5rem, 1fr)); gap: var(--sp-2); }
#game-root .badge-item { display: grid; justify-items: center; gap: 2px; text-align: center; font-size: var(--fs-xs); line-height: 1.25; color: var(--muted); }
#game-root .badge-item.on { color: var(--ink); font-weight: 600; }
#game-root .badge-item img { width: 48px; height: 48px; }

/* Win screen: inside the frame, in the chat's place; it scrolls inside itself. */
/* The grid never changes, so MystrS keeps his size: the win block takes the chat and dock cells. */
#game-root .win-block { grid-column: chat; grid-row: chat-start / dock-end; min-height: 0; overflow-y: auto; }
#game-root.is-complete .dock { visibility: hidden; }

/* ---- Effects (engagement starting set). Static by default; motion only when allowed. ---- */
/* Above the notes overlay (z 5) and the card (z 7): on phones the unlock moment shows over the lesson, then fades. */
#game-root .fx { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 8; }
#game-root .burst { position: absolute; left: 50%; top: 5.5rem; width: 0; height: 0; }
#game-root .burst .shape { position: absolute; left: -5px; top: -5px; width: 10px; height: 10px; border-radius: 2px; opacity: 0; }
#game-root .burst .s0 { background: var(--cyber); }
#game-root .burst .s1 { background: var(--money); border-radius: 50%; }
#game-root .burst .s2 { background: var(--ai); }
#game-root .burst .s3 { background: var(--cyber-mid); border-radius: 50%; }
#game-root .burst .s4 { background: var(--money-mid); }
#game-root .celebrate {
  position: absolute;
  left: var(--sp-3);
  right: var(--sp-3);
  top: var(--sp-3);
  z-index: 7;
  pointer-events: none; /* a passing moment: never in the way of Next or the boxes */
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
  padding: var(--sp-4) var(--sp-4) var(--sp-3);
  overflow: hidden;
}
#game-root .celebrate::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 6px; background: linear-gradient(90deg,var(--cyber) 0 33.333%,var(--money) 33.333% 66.666%,var(--ai) 66.666% 100%); }
#game-root .celebrate.metal-gold::before { background: var(--metal-gold); }
#game-root .celebrate.metal-silver::before { background: var(--metal-silver); }
#game-root .celebrate.metal-bronze::before { background: var(--metal-bronze); }
#game-root .celebrate p { margin: 0; }
#game-root .celebrate .kicker { font: 700 var(--fs-xs) / 1.2 var(--sans); text-transform: uppercase; letter-spacing: .06em; color: var(--money-dark); }
#game-root .celebrate .card-title { font: 700 var(--fs-lg) / 1.3 var(--sans); color: var(--navy); }
#game-root .celebrate .card-sub { font-size: var(--fs-sm); color: var(--muted); }
#game-root .celebrate.badge { display: flex; align-items: center; gap: var(--sp-3); }
#game-root .badge-swap { position: relative; width: 96px; height: 96px; flex: none; }
#game-root .badge-swap img { position: absolute; inset: 0; width: 96px; height: 96px; }
#game-root .badge-swap .b-locked { opacity: 0; }
#game-root .celebrate .badge-text { min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 39.99rem) {
  /* Phones: the card is as wide as the chat, so the badge sits above its name. */
  #game-root .celebrate.badge { flex-direction: column; align-items: flex-start; gap: var(--sp-2); }
  #game-root .badge-swap, #game-root .badge-swap img { width: 72px; height: 72px; }
  #game-root .celebrate .card-title { font-size: var(--fs-md); }
}
#game-root .reveal-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: var(--sp-2) !important; }
#game-root .tile-r { min-width: 2.25rem; height: 2.75rem; padding: 0 var(--sp-1); display: inline-flex; align-items: center; justify-content: center; border-radius: var(--r-sm); font: 800 var(--fs-lg) / 1 var(--sans); background: var(--paper); color: var(--navy); border: 2px solid var(--navy); }

@media (prefers-reduced-motion: no-preference) {
  /* Burst: about 10 shapes fly out once (400 ms, eased) and fade; nothing is left on screen. */
  #game-root .burst .shape { animation: r8-burst calc(var(--dur-3) + 250ms) var(--ease) var(--d, 0ms) 1 both; }
  @keyframes r8-burst {
    0% { opacity: 0; transform: rotate(var(--a)) translateX(0) scale(.4); }
    25% { opacity: 1; }
    100% { opacity: 0; transform: rotate(var(--a)) translateX(5.5rem) scale(1); }
  }
  /* Cards rise 12 px into place (--rise) and fade in; leaving is a fade. */
  #game-root .celebrate:not([hidden]) { animation: r8-rise var(--dur-2) var(--ease) 1 both; }
  #game-root .celebrate.is-leaving { opacity: 0; transition: opacity var(--dur-2) var(--ease); }
  @keyframes r8-rise { from { opacity: 0; transform: translateY(var(--rise)); } to { opacity: 1; transform: none; } }
  /* Code reveal: the tiles rise in turn, 40 ms apart. */
  #game-root .tile-r { animation: r8-tile var(--dur-2) var(--ease) calc(120ms + var(--i, 0) * 40ms) 1 both; }
  @keyframes r8-tile { from { opacity: 0; transform: translateY(var(--rise)); } to { opacity: 1; transform: none; } }
  /* Badge unlock: the locked art crossfades to the unlocked art (250 ms). */
  #game-root .badge-swap .b-locked { animation: r8-out var(--dur-2) var(--ease) 300ms 1 backwards; }
  #game-root .badge-swap .b-unlocked { animation: r8-in var(--dur-2) var(--ease) 300ms 1 backwards; }
  @keyframes r8-out { from { opacity: 1; } to { opacity: 0; } }
  @keyframes r8-in { from { opacity: 0; } to { opacity: 1; } }
  /* Thinking dots: appear once, in turn, then hold still (no loop, no pulse). */
  #game-root .dots i { animation: r8-in var(--dur-1) var(--ease) 1 backwards; }
  #game-root .dots i:nth-child(2) { animation-delay: 150ms; }
  #game-root .dots i:nth-child(3) { animation-delay: 300ms; }
  /* The newest bubble fades in (opacity only). */
  #game-root .chat-log li.bot.is-latest { animation: r8-in var(--dur-2) var(--ease) 1 both; }
  /* Side panel buttons: lift on hover and focus only (--shadow-2 there, --shadow-1 at rest). */
  #game-root .side-toggle:hover, #game-root .side-toggle:focus-visible { box-shadow: var(--shadow-2); transform: translateY(var(--lift)); transition: transform var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease); }
}

#game-root .panel,
#game-root .win-block,
#game-root #result-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--sp-5) var(--sp-6);
  box-shadow: var(--shadow-1);
  min-width: 0;
  width: 100%;
}

#game-root label {
  display: block;
  font: 600 var(--fs-sm) / 1.3 var(--sans);
  margin-bottom: var(--sp-2);
}

#game-root .input-row {
  display: flex;
  flex-wrap: nowrap;
  align-items: stretch;
  gap: var(--sp-2);
  width: 100%;
}

#game-root .input-row input[type="text"] {
  flex: 1 1 auto;
  min-width: 0;
  width: auto;
  padding: var(--sp-3);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  font: inherit;
  background: var(--paper);
  color: var(--ink);
}

#game-root button,
#game-root .btn {
  display: inline-block;
  padding: var(--sp-3) var(--sp-4);
  border: 0;
  border-radius: var(--r-md);
  background: var(--accent);
  color: var(--accent-ink);
  font: 600 var(--fs-ui) / 1.2 var(--sans);
  text-decoration: none;
  cursor: pointer;
  flex: 0 0 auto;
  white-space: nowrap;
}

#game-root button.secondary {
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--line-strong);
}

#game-root button:disabled {
  color: var(--muted);
  background: var(--neutral-soft);
  cursor: not-allowed;
}

#game-root :focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}


#game-root .hint {
  margin: var(--sp-3) 0 0;
  background: var(--warn-soft);
  border-left: 4px solid var(--warn);
  border-radius: var(--r-md);
  padding: var(--sp-3) var(--sp-4);
}

#game-root .hint p { margin: 0 0 var(--sp-2); }
#game-root .hint p:last-child { margin-bottom: 0; }

#game-root .lesson {
  margin-top: 0;
  background: var(--soft);
  border-left: 4px solid var(--accent);
  border-radius: var(--r-md);
  padding: var(--sp-4);
}

#game-root .lesson p { margin: 0 0 var(--sp-4); }
#game-root .lesson p:last-child { margin-bottom: 0; }
#game-root .lesson .actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; }

#game-root #win-screen,
#game-root #win-screen .lesson,
#game-root #result-card {
  opacity: 1;
  animation: none;
}

#game-root #win-screen-text,
#game-root #result-heading,
#game-root #result-text {
  margin: 0;
  color: var(--ink);
  opacity: 1;
}

#game-root #result-card {
  margin-top: var(--sp-5);
  box-shadow: none;
}

#game-root #result-text {
  white-space: pre-wrap;
  margin: 0 0 var(--sp-4);
  font: var(--fs-sm) / 1.5 var(--sans);
}

#game-root #result-heading {
  margin: 0 0 var(--sp-4);
  font: 600 var(--fs-xl) / 1.25 var(--sans);
  color: var(--ink);
}

#game-root #result-canvas {
  display: block;
  width: auto;
  max-width: 100%;
  max-height: 15rem;
  height: auto;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--bg);
  margin: 0 auto var(--sp-4);
}

#game-root .result-actions {
  display: flex;
  gap: var(--sp-2);
  flex-wrap: wrap;
}

#game-root .game-footer {
  margin-top: var(--sp-6);
  padding-top: var(--sp-5);
  border-top: 1px solid var(--line);
}

#game-root [hidden] { display: none !important; }

}
#game-root .debug {
  margin: var(--sp-4) 0 0;
  padding: var(--sp-3);
  background: var(--paper);
  color: var(--ink);
  border: 1px dashed var(--line-strong);
  border-radius: var(--r-sm);
  font-size: var(--fs-sm);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
#game-root .optin { display: inline-flex; align-items: center; gap: var(--sp-2); color: var(--ink); font-size: var(--fs-sm); }

/* ---- Levels 25 to 30 and The Vault (tokens only) ---- */
#game-root .sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
#game-root .codes-note { margin: var(--sp-2) 0 0; color: var(--muted); font-size: var(--fs-xs); }
#game-root .notice {
  margin: var(--sp-4) 0 0; padding: var(--sp-3) var(--sp-4);
  background: var(--cyber-soft); border-left: 4px solid var(--cyber); border-radius: var(--r-md); color: var(--ink);
}
#game-root .code-form input[type="text"] { text-transform: uppercase; letter-spacing: 0.08em; }
#game-root .code-form .muted:empty { display: none; }
#game-root .vault-bar { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-top: var(--sp-4); }
#game-root .vault-entry {
  margin-top: var(--sp-6); padding: var(--sp-4) var(--sp-5);
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--r-lg);
}
#game-root .vault-entry h2 { margin: 0 0 var(--sp-2); font-size: var(--fs-lg); color: var(--navy); }
#game-root .vault-entry p { margin: 0 0 var(--sp-3); }

#game-root .tracker {
  margin-top: 0; padding: var(--sp-3);
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--r-lg);
  display: grid; grid-template-columns: 1fr; gap: var(--sp-4);
}
@media (min-width: 40rem) {
  #game-root .tracker { grid-template-columns: 3fr 2fr; }
  #game-root .tracker h2 { grid-column: 1 / -1; }
}
#game-root .tracker h2 { margin: 0; font-size: var(--fs-md); color: var(--navy); }
#game-root .tracker h3 { margin: 0 0 var(--sp-2); font-size: var(--fs-sm); color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
#game-root .tracker h4 { margin: var(--sp-3) 0 var(--sp-2); font-size: var(--fs-sm); }
#game-root .tracker p { margin: 0 0 var(--sp-2); }
#game-root .facts, #game-root .doors { margin: 0; padding-left: var(--sp-5); }
#game-root .facts li, #game-root .doors li { margin: 0 0 var(--sp-1); }
#game-root .door.patched { color: var(--muted); text-decoration: line-through; }
#game-root .door.leaking { color: var(--money-dark); font-weight: 600; }

#game-root .board, #game-root .slots, #game-root .keys, #game-root .rows { list-style: none; margin: 0 0 var(--sp-3); padding: 0; }
#game-root .board { display: grid; grid-template-columns: repeat(auto-fill, minmax(6.5rem, 1fr)); gap: var(--sp-2); }
#game-root .board .cell {
  padding: var(--sp-2); text-align: center; font: 600 var(--fs-sm) / 1.2 var(--sans); letter-spacing: 0.04em;
  border: 1px solid var(--line-strong); border-radius: var(--r-md); color: var(--ink); background: var(--paper);
}
#game-root .board .cell.out { color: var(--muted); background: var(--neutral-soft); border-style: dashed; text-decoration: line-through; }

#game-root .slots { display: flex; flex-wrap: wrap; gap: var(--sp-1); }
#game-root .slot {
  min-width: 2.25rem; height: 2.5rem; display: inline-flex; align-items: center; justify-content: center;
  border: 2px dashed var(--line-strong); border-radius: var(--r-sm); font: 700 var(--fs-lg) / 1 var(--sans); color: var(--muted);
}
#game-root .slot.known { border: 2px solid var(--navy); color: var(--navy); background: var(--cyber-soft); }

#game-root .keys { display: grid; grid-template-columns: repeat(auto-fill, minmax(2.25rem, 1fr)); gap: var(--sp-1); }
#game-root .key, #game-root .tile {
  display: inline-flex; align-items: center; justify-content: center; gap: 2px;
  min-height: 2.25rem; border-radius: var(--r-sm); font: 700 var(--fs-sm) / 1 var(--sans);
  border: 1px solid var(--line-strong); background: var(--paper); color: var(--ink);
}
#game-root .key .glyph { font-size: var(--fs-xs); }
#game-root .key.right, #game-root .tile.right { background: var(--money-dark); border-color: var(--money-dark); color: var(--on-color); }
#game-root .key.present, #game-root .tile.present { background: var(--warn-soft); border: 2px solid var(--warn); color: var(--warn); }
#game-root .key.absent, #game-root .tile.absent { background: var(--neutral-soft); color: var(--muted); text-decoration: line-through; }
#game-root .legend { font-size: var(--fs-xs); }
#game-root .rows .row { display: flex; gap: var(--sp-1); margin: 0 0 var(--sp-1); flex-wrap: wrap; }
#game-root .tile { min-width: 2.25rem; padding: 0 var(--sp-1); }
#game-root .transform { margin: 0 0 var(--sp-3); }
#game-root .mono { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; overflow-wrap: anywhere; }
#game-root .tier { font-weight: 700; color: var(--money-dark); }
#game-root #vault-share { white-space: pre-wrap; }

@media (max-width: 30rem) {
  #game-root .vault-bar button { flex: 1 1 auto; padding: var(--sp-2); }
}
@media (prefers-reduced-motion: reduce) {
  #game-root .tracker *, #game-root .notice { transition: none !important; animation: none !important; }
}

/* Trick Book (disguised leaks) and Reply Director notes. Tokens only. */
#game-root .chat-log li.note { color: var(--money-dark); font-weight: 600; }
#game-root .disguises { list-style: none; margin: 0; padding: 0; }
#game-root .trick-name { font-weight: 600; color: var(--navy); margin: 0 0 var(--sp-1); }
#game-root .teach { margin: var(--sp-2) 0 0; padding: var(--sp-2) var(--sp-3); background: var(--money-soft); border-left: 4px solid var(--money); border-radius: var(--r-sm); }
#game-root .trick-book { margin: var(--sp-4) 0 0; padding: var(--sp-3) var(--sp-4); border: 1px solid var(--line); border-radius: var(--r-md); background: var(--paper); }
#game-root .trick-book summary { cursor: pointer; font-weight: 600; color: var(--navy); min-height: 44px; display: flex; align-items: center; }
#game-root .trick-book summary:focus-visible { outline: 3px solid var(--cyber-mid); outline-offset: 2px; }
#game-root .stamps { list-style: none; margin: var(--sp-2) 0; padding: 0; display: flex; flex-wrap: wrap; gap: var(--sp-2); }
#game-root .stamp { display: inline-flex; align-items: center; gap: var(--sp-1); padding: var(--sp-1) var(--sp-3); border: 1px dashed var(--line-strong); border-radius: var(--r-pill); color: var(--muted); font-size: var(--fs-sm); }
#game-root .stamp.found { border-style: solid; border-color: var(--money); background: var(--money-soft); color: var(--money-dark); }
#game-root .stamp-level { font-size: var(--fs-xs); font-weight: 600; }

/* Round 8b: code pieces in the notes (encoded only). Fixed slots: nothing moves when one fills. */
#game-root .pieces-sum { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#game-root .pieces-sum { margin: 0 0 var(--sp-2); }
#game-root .piece-slots { list-style: none; margin: 0 0 var(--sp-2); padding: 0; display: grid; gap: var(--sp-2); }
#game-root .piece { padding: var(--sp-2) var(--sp-3); border: 2px dashed var(--line-strong); border-radius: var(--r-md); background: var(--paper); }
#game-root .piece.got { border: 2px solid var(--money); background: var(--money-soft); }
#game-root .piece p { margin: 0 0 var(--sp-1); }
#game-root .piece .mono { font-size: var(--fs-sm); line-height: 1.35; color: var(--navy); }
/* Round 8b: binary decoder. The notes card has one fixed height on every level (level 1 holds
   the table and scrolls inside), so Next never moves the notes. The big table is a fixed overlay. */
#game-root .dec-card { box-sizing: border-box; padding: var(--sp-2) var(--sp-3); border: 1px solid var(--line); border-radius: var(--r-md); background: var(--cyber-soft); }
#game-root .dec-card-head, #game-root .decoder-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); margin: 0 0 var(--sp-2); }
#game-root .dec-card-head .trick-name, #game-root .decoder-head h2 { margin: 0; }
#game-root .dec-card-head button { min-height: 2.75rem; padding: var(--sp-1) var(--sp-3); font-size: var(--fs-sm); }
#game-root .dec-ex { font-size: var(--fs-xs); margin: 0 0 var(--sp-2); }
#game-root .dec-places { list-style: none; margin: 0 0 var(--sp-1); padding: 0; display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 2px; }
#game-root .dec-places li { text-align: center; padding: 2px 0; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--paper); color: var(--navy); font: 700 var(--fs-xs) / 1.4 ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; }
#game-root .dec-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(9.25rem, 1fr)); gap: var(--sp-1); }
#game-root .dec-grid li { display: flex; align-items: baseline; gap: var(--sp-2); padding: 2px var(--sp-2); border-radius: var(--r-sm); background: var(--paper); border: 1px solid var(--line); }
#game-root .dec-grid b { min-width: 1.1em; color: var(--cyber); }
#game-root .dec-grid code { font: var(--fs-sm) / 1.4 ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; color: var(--navy); }
#game-root .dec-grid .num { margin-left: auto; font-size: var(--fs-xs); color: var(--muted); }
#game-root .decoder { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: var(--sp-3); background: var(--overlay); }
#game-root .decoder[hidden] { display: none; }
#game-root .decoder-box { box-sizing: border-box; width: min(36rem, 100%); max-height: 100%; overflow-y: auto; padding: var(--sp-3) var(--sp-4) var(--sp-4); border-radius: var(--r-lg); background: var(--paper); color: var(--ink); box-shadow: var(--shadow-2); }
#game-root .decoder-box:focus-visible { outline: 3px solid var(--cyber); outline-offset: 2px; }
#game-root .decoder-yours .mono { margin: 0 0 var(--sp-1); font: var(--fs-sm) / 1.4 ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; color: var(--navy); overflow-wrap: anywhere; }
/* In the notes the table is denser: two columns, no numbers (the big table has them). */
#game-root .dec-card { min-width: 0; }
#game-root .dec-card-head { flex-wrap: wrap; }
#game-root .dec-card-head .trick-name { white-space: nowrap; }
#game-root .dec-card .dec-places { gap: 1px; }
#game-root .dec-card .dec-places li { font-size: 0.75rem; letter-spacing: -0.03em; }
#game-root .dec-card .dec-grid { grid-template-columns: repeat(auto-fill, minmax(5.75rem, 1fr)); gap: 2px; }
#game-root .dec-card .dec-grid li { gap: var(--sp-1); padding: 0 var(--sp-1); }
#game-root .dec-card .dec-grid code { font-size: var(--fs-xs); }
#game-root .dec-card .dec-grid .num { display: none; }
@media (max-width: 39.99rem) {
  #game-root .decoder { padding: var(--sp-2); }
  #game-root .decoder-box { padding: var(--sp-2) var(--sp-3) var(--sp-3); }
  #game-root .dec-grid { grid-template-columns: repeat(auto-fill, minmax(8.5rem, 1fr)); }
  /* The phone notes are narrow: place values in two rows of four, so 128 never squeezes. */
  #game-root .dec-card { padding: var(--sp-2); }
  #game-root .dec-card .dec-places { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  #game-root .dec-card .dec-grid { grid-template-columns: minmax(0, 1fr); }
}
#game-root .slots.bin .slot { min-width: 5.5rem; font: 700 var(--fs-sm) / 1 ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; }
#game-root .celebrate.rotated::before { background: var(--cyber); }
#game-root .celebrate.rotated .kicker { color: var(--cyber); }
@media (max-width: 39.99rem) {
  /* Phones: a compact header gives the stage more height (nothing in it wraps differently). */
  #game-root .header-inner { padding: var(--sp-2) var(--sp-3); }
  #game-root .level-map { margin-top: var(--sp-1); }
  #game-root .codes-note { margin-top: 2px; }
  /* Notes overlay: a smaller head and Start over, so the notes themselves get the room. */
  #game-root .side-head h2 { font-size: var(--fs-sm); }
  #game-root .side .game-footer { padding-top: var(--sp-1); }
  #game-root .side .game-footer button { min-height: 2.25rem; padding: var(--sp-1) var(--sp-3); font-size: var(--fs-sm); }
  /* After the right code: the lesson is all the notes show, the code and message boxes stay in view. */
  #game-root.is-won .side-body > :not(.lesson) { display: none; }
  #game-root .piece { height: 5.25rem; }
  /* The header under the open notes is hidden, so no half-covered title peeks out beside them. */
  #game-root.side-open .game-header { visibility: hidden; }
  #game-root .side .tracker { padding: var(--sp-2); gap: var(--sp-2); }
  #game-root .side .tracker h2 { font-size: var(--fs-sm); }
  #game-root .side .tracker h3 { font-size: var(--fs-xs); margin-bottom: var(--sp-1); }
}

/* ==== Round 8c (Nov 13): load CLS 0, one scroll in the notes, focus, phone header ==== */
/* Before the game mounts, #game-root is empty: it holds the frame's final height, so the site
   footer never jumps. --game-top is where the frame starts on the page (set by the site's
   main.main-game; without it the reserve is a full screen, which still keeps the footer below
   the fold). Same formula as fitFrame in game.js: viewport minus the top minus 4px. */
#game-root:empty { min-height: calc(100vh - var(--game-top, 0px) - 4px); min-height: calc(100svh - var(--game-top, 0px) - 4px); }
/* The header is one fixed size from the first paint: the level line and the codes note keep
   their line while the data loads, and nothing in the header row is taller than the title. */
#game-root #level-header { min-height: 1.3em; color: var(--ink); letter-spacing: normal; }
#game-root #level-header:focus { outline: none; }
#game-root #level-header:focus-visible { outline: 3px solid var(--cyber); outline-offset: 2px; border-radius: var(--r-sm); }
#game-root .codes-note { min-height: 1.3em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#game-root .codes-note.is-empty { visibility: hidden; }
#game-root .header-row .badge { padding-top: 0.25rem; padding-bottom: 0.25rem; }
#game-root .side-head h2:focus { outline: none; }
#game-root .side-head h2:focus-visible { outline: 3px solid var(--cyber); outline-offset: 2px; border-radius: var(--r-sm); }
/* Code piece slots: three fixed rows (name, up to 3 lines of the encoding, one note line), so a
   slot is one height empty or full and never scrolls. The Decoder lists every piece in full. */
#game-root .piece { display: grid; grid-template-rows: auto calc(3 * 1.35 * var(--fs-sm)) calc(1.4 * var(--fs-xs)); row-gap: var(--sp-1); min-width: 0; }
#game-root .piece p { margin: 0; min-width: 0; }
#game-root .piece .trick-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#game-root .piece .mono, #game-root .piece > .muted:not(.piece-note) { overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; line-clamp: 3; line-height: 1.35; font-size: var(--fs-sm); }
#game-root .piece .piece-note { font-size: var(--fs-xs); line-height: 1.4; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* Decoder card: the first rows (level 1) or one line (later), in a box of one fixed height. */
#game-root .dec-more { height: calc(3 * 1.5rem + 2 * 2px); overflow: hidden; margin: 0 0 var(--sp-1); }
#game-root .pieces > .dec-card:first-child { margin: 0 0 var(--sp-2); }
#game-root .dec-more .dec-ex { margin: 0; }
#game-root .dec-card .dec-grid.dec-sample { grid-template-columns: repeat(2, minmax(0, 1fr)); }
#game-root .dec-card .dec-sample li { box-sizing: border-box; height: 1.5rem; align-items: center; line-height: 1.2; }
#game-root .dec-card .dec-sample b, #game-root .dec-card .dec-sample code { line-height: 1.2; }
/* The title has its own line and the button the next, on every level and width, so the head is one height. */
#game-root .dec-card-head { flex-wrap: wrap; justify-content: flex-start; }
@media (max-width: 39.99rem) {
  /* Phones: the notes are narrow, so the first rows are one column (A to C), same box height. */
  #game-root .dec-card .dec-grid.dec-sample { grid-template-columns: minmax(0, 1fr); }
  #game-root .dec-card .dec-sample li:nth-child(n+4) { display: none; }
}
#game-root .dec-card-head > .trick-name { flex: 1 0 100%; }
/* Narrow screens: the unlock moment sits in the lesson, above its text (never over it). */
#game-root .lesson-cracked { margin: 0 0 var(--sp-3); }
#game-root .lesson-cracked .kicker { margin: 0; font: 700 var(--fs-xs) / 1.2 var(--sans); text-transform: uppercase; letter-spacing: .06em; color: var(--money-dark); }
#game-root .lesson-cracked .reveal-row { margin: var(--sp-1) 0 0 !important; gap: 3px; }
#game-root .lesson-cracked .tile-r { min-width: 1.5rem; height: 2rem; padding: 0 2px; border-width: 2px; font-size: var(--fs-md); }
#game-root .lesson .lesson-cracked p { margin: 0; }
#game-root .lesson .lesson-cracked .lesson-badge { margin-top: var(--sp-1); }
#game-root .lesson .lesson-badge { margin: var(--sp-2) 0 0; font-size: var(--fs-sm); font-weight: 600; color: var(--navy); }
@media (prefers-reduced-motion: no-preference) {
  #game-root .lesson-cracked .tile-r { animation: r8-tile var(--dur-2) var(--ease) calc(120ms + var(--i, 0) * 40ms) 1 both; }
}

/* Round 9: lip sync. While MystrS speaks, a hard cut to his talking pose (Scott's s31g mouth
   rig, dev/art-speak.json) and one mouth frame at a time. Opacity only: no motion. */
#game-root .fig-stack .mouth-frame { position: absolute; bottom: 0; height: 100%; width: auto; max-width: none; opacity: 0; left: calc(var(--fig-h) * -0.0095); }
#game-root.is-speaking .fig-stack .fig { opacity: 0; }
#game-root.is-speaking .fig-stack .mouth-frame.is-on { opacity: 1; }

/* Round 9: sound and voice toggles (aria-pressed). */
#game-root .av-toggles { display: flex; gap: var(--sp-2); margin-left: auto; flex: none; }
/* Desktop: no taller than the title line (24 px targets), so the header keeps its height. */
#game-root .av-btn { display: inline-flex; align-items: center; gap: var(--sp-1); padding: 0 var(--sp-2); min-height: 0; height: 1.5rem; font-size: var(--fs-xs); }
#game-root .av-icon { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
#game-root .av-btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
#game-root .link-btn { flex: none; padding: var(--sp-1) var(--sp-2); min-height: 2rem; background: transparent; color: var(--link); border: 1px solid var(--line); font-size: var(--fs-xs); }

/* Round 9: the defenses on this level (fixed size on every level: four slots, one status line). */
#game-root .defense-card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--sp-2) var(--sp-3); }
#game-root .defense-card h2 { margin: 0 0 var(--sp-1); font: 600 var(--fs-sm) / 1.3 var(--sans); }
#game-root .defense-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1.5rem 1.5rem; gap: var(--sp-1); }
#game-root .def-chip { margin: 0; display: flex; align-items: center; justify-content: center; border-radius: var(--r-pill); border: 1px solid var(--line-strong); background: var(--soft); font: 600 var(--fs-xs) / 1 var(--sans); white-space: nowrap; overflow: hidden; }
#game-root .def-chip.is-hit { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); }
#game-root .defense-last { margin: var(--sp-1) 0 0; height: 1.4em; font-size: var(--fs-xs); line-height: 1.4; color: var(--muted); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

/* Round 9: splash and directions. They cover the game frame exactly (absolute, inside the
   shell), so showing or hiding them never moves anything. */
#game-root .game-shell { position: relative; }
#game-root .intro, #game-root .howto { position: absolute; inset: 0; z-index: 15; box-sizing: border-box; border-radius: var(--r-lg); }
#game-root .intro[hidden], #game-root .howto[hidden] { display: none; }
#game-root .intro { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: center; gap: var(--sp-5); padding: var(--sp-5); background: var(--navy); color: var(--on-color); overflow: hidden; }
#game-root .intro-art { height: 100%; min-height: 0; display: flex; align-items: flex-end; justify-content: flex-start; }
#game-root .intro-text { justify-self: end; max-width: 26rem; }
#game-root .intro-art img { height: min(100%, 44rem); width: auto; max-width: 100%; object-fit: contain; object-position: bottom; }
#game-root .intro-text h2 { margin: 0; font: 700 var(--fs-2xl) / 1.1 var(--sans); color: var(--on-color); }
#game-root .intro-sub { margin: var(--sp-2) 0 var(--sp-5); font-size: var(--fs-md); color: var(--on-color); }
#game-root .intro-actions { display: flex; flex-wrap: wrap; gap: var(--sp-3); }
#game-root .intro-actions button { min-height: 2.75rem; min-width: 8rem; }
#game-root .intro #intro-start { background: var(--cyber); color: var(--on-color); outline-color: var(--paper); }
#game-root .intro :focus-visible { outline-color: var(--paper); }
#game-root .howto { display: grid; place-items: center; padding: var(--sp-3); background: var(--overlay); }
#game-root .howto-card { box-sizing: border-box; width: min(34rem, 100%); max-height: 100%; overflow-y: auto; padding: var(--sp-4) var(--sp-5); border-radius: var(--r-lg); background: var(--paper); color: var(--ink); box-shadow: var(--shadow-2); }
#game-root .howto-card h2 { margin: 0 0 var(--sp-3); font: 700 var(--fs-xl) / 1.2 var(--sans); }
#game-root .howto-list { margin: 0 0 var(--sp-4); padding-left: 1.4em; font-size: var(--fs-md); line-height: 1.45; }
#game-root .howto-list li + li { margin-top: var(--sp-2); }
#game-root .howto-actions { display: flex; justify-content: flex-end; }
#game-root .howto-actions button { min-width: 8rem; min-height: 2.75rem; }
@media (max-width: 40rem) {
  #game-root .intro-text { justify-self: center; }
  #game-root .intro { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); gap: var(--sp-3); padding: var(--sp-4); text-align: center; }
  #game-root .intro-art { justify-content: center; }
  #game-root .intro-actions { justify-content: center; }
  #game-root .intro-text h2 { font-size: var(--fs-2xl-sm); }
  #game-root .howto-card { padding: var(--sp-3) var(--sp-4); }
  #game-root .howto-list { font-size: var(--fs-sm); }
}
#game-root #howto-btn { margin-left: 0; min-height: 0; height: 1.5rem; padding: 0 var(--sp-2); }
#game-root #howto-btn .howto-short { display: none; }
/* Phones: "How to play" sits on the title row (right), above the level name, so the header keeps
   its rows. */
@media (max-width: 39.99rem) {
  #game-root #howto-btn { order: 2; margin-left: auto; width: 1.75rem; height: 1.75rem; min-height: 0; padding: 0; border-radius: var(--r-pill); font-size: var(--fs-sm); text-align: center; }
  #game-root #howto-btn .howto-long { display: none; }
  #game-root #howto-btn .howto-short { display: inline; }
  #game-root #level-header { order: 3; }
  /* Phones: the toggles sit in the tools row (moved there by game.js), icons only (the word is still read). */
  #game-root .tools .av-toggles { margin-left: 0; flex: none; }
  #game-root .tools .av-btn { width: 2.75rem; height: 2.75rem; min-height: 2.75rem; padding: 0; justify-content: center; }
  #game-root .av-word { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
}
