/* Pryzmio Arcade — global stylesheet.
 *
 * Token layer ported from Digibeat / spell DESIGN_SYSTEM.md §1 (the anti-drift rule,
 * invariant 1: every colour, radius, and size comes from :root; components read tokens,
 * never literals). Chunk 0 carries the tokens and the shared chrome; pack skins, the
 * session shell, and the return layer add their own layers on top in later chunks.
 */

:root {
  /* Praise tiers — same meaning everywhere (gold=perfect, cyan=amazing, emerald=great,
     amethyst=good, slate=gentle try-again; never an error red). */
  --gold: #ffd23f;
  --cyan: #36f1cd;
  --emerald: #7ae582;
  --amethyst: #9d8df1;
  --slate: #6c7a89;
  /* Surfaces */
  --bg-0: #070a1c;
  --bg-1: #0e1430;
  --bg-2: #161d44;
  --panel: rgba(255, 255, 255, 0.06);
  --panel-border: rgba(150, 180, 255, 0.18);
  --ink: #eaf0ff;
  --ink-dim: #9fb0d8;
  --accent: #7aa2ff;
  --danger: #ff9aa2;
  /* Sizing */
  --radius: 22px;
  --tap-min: 64px;
  /* Ambient animation period (the music bed's visual counterpart). Not a gameplay
     clock: nothing under 12 is timed, and no per-response deadline reads from this. */
  --beat: 833ms;
}

@font-face {
  font-family: 'Atkinson Hyperlegible';
  src: url('/fonts/atkinson-hyperlegible-400.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'Atkinson Hyperlegible';
  src: url('/fonts/atkinson-hyperlegible-700.woff2') format('woff2');
  font-weight: 700;
  font-display: swap;
}

* {
  box-sizing: border-box;
}

html {
  font-size: 18px;
}

body {
  margin: 0;
  min-height: 100dvh;
  color: var(--ink);
  font-family: 'Atkinson Hyperlegible', 'Quicksand', 'Segoe UI Rounded', 'Nunito',
    system-ui, -apple-system, sans-serif;
  background:
    radial-gradient(1200px 800px at 50% -10%, #21306e 0%, transparent 60%),
    radial-gradient(900px 700px at 90% 110%, #2a1b54 0%, transparent 55%),
    linear-gradient(160deg, var(--bg-1), var(--bg-0));
  background-attachment: fixed;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

/* Ambient glow that breathes slowly. Purely decorative; stilled entirely under
   prefers-reduced-motion. */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(900px 600px at 50% 85%, var(--accent) 0%, transparent 60%);
  opacity: 0.05;
  animation: ambient-pulse calc(var(--beat) * 2) ease-in-out infinite;
  z-index: 0;
}

@keyframes ambient-pulse {
  0%, 100% { opacity: 0.04; }
  50% { opacity: 0.09; }
}

#app {
  position: relative;
  z-index: 1;
  max-width: 640px;
  margin: 0 auto;
  padding: 16px;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

h1, h2, h3 {
  margin: 0 0 12px;
}

/* ---------- shared components ---------- */

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}

.btn {
  min-height: var(--tap-min);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45em;
  border-radius: var(--radius);
  padding: 16px 26px;
  font-size: 1.2rem;
  font-weight: 700;
  font-family: inherit;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  cursor: pointer;
  transition: transform 0.1s ease;
}
.btn:active {
  transform: scale(0.96);
}
.btn.primary {
  background: linear-gradient(150deg, #5f7bff, #8a5cff);
  border-color: transparent;
  box-shadow: 0 10px 30px -8px #5f7bff88;
}
.btn.ghost {
  min-height: 52px;
  padding: 10px 22px;
  font-size: 1.05rem;
  opacity: 0.92;
}
.btn[disabled] {
  opacity: 0.4;
  pointer-events: none;
}

.seg {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.seg button {
  min-height: var(--tap-min);
  border-radius: 16px;
  font-weight: 800;
  font-size: 1.1rem;
  font-family: inherit;
  color: var(--ink);
  background: var(--panel);
  border: 2px solid var(--panel-border);
  cursor: pointer;
}
.seg button.on {
  background: linear-gradient(150deg, #5f7bff, #8a5cff);
  border-color: transparent;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 8%;
  transform: translateX(-50%) translateY(20px);
  background: #11183c;
  border: 1px solid var(--panel-border);
  color: var(--ink);
  padding: 14px 22px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 1.1rem;
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.3s ease;
  z-index: 50;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Overlay anatomy (z-index ladder: 40 particles / 50 toast / 60 content overlays /
   100 pause / 120 brain break / 200 adult gate — reserve the same rungs). */
.gate-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(4, 6, 20, 0.7);
  backdrop-filter: blur(6px);
}
.gate-box {
  width: min(440px, 100%);
  border-radius: 20px;
  padding: 22px;
  background: linear-gradient(160deg, #1a2350, #11183c);
  border: 1px solid var(--panel-border);
  box-shadow: 0 24px 60px -20px #000d;
}
.gate-err {
  color: var(--danger);
  min-height: 1.4em;
}

/* ---------- app chrome ---------- */

.app-header {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  margin-bottom: 10px;
}
.app-header .header-title {
  font-weight: 700;
  font-size: 1.15rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.btn-icon {
  min-width: 48px;
  min-height: 48px;
  border-radius: 16px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--ink);
  font-size: 1.5rem;
  cursor: pointer;
}
.app-header .header-right {
  margin-left: auto;
}

/* ---------- home ---------- */

.home {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
  gap: 8px;
}
.home-title {
  font-size: clamp(2rem, 9vw, 3.2rem);
  font-weight: 700;
  letter-spacing: 0.02em;
  margin: 0;
}
.home-tag {
  color: var(--ink-dim);
  font-size: 1.05rem;
  margin: 0 0 26px;
}
.home .btn.primary {
  min-height: 96px;
  font-size: 1.5rem;
  align-self: center;
  width: min(340px, 100%);
}

/* ---------- session shell (chunk 2) ---------- */

.session {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.done-card {
  text-align: center;
}

.session-start {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
}
.session-sub {
  color: var(--ink-dim);
  margin: 0 0 8px;
}
.session-go,
.block-continue,
.done-home {
  width: min(320px, 100%);
}

/* A block: plain wayfinding, the skin-themed stage, the input surface. */
.session-block {
  flex: 1;
  display: flex;
  flex-direction: column;
}
.block-nav {
  color: var(--ink-dim);
  font-weight: 700;
  text-align: center;
  margin-bottom: 10px;
}

.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  border-radius: var(--radius);
  padding: 24px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
}
.stub-prompt {
  font-size: clamp(3rem, 16vw, 5rem);
  font-weight: 700;
}
.stub-consequence {
  font-size: 1.4rem;
  color: var(--accent);
  min-height: 1.5em;
}
.feedback-slot {
  min-height: 2.2em;
  display: flex;
  align-items: center;
}
.feedback.praise {
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}
.feedback.praise.gold { color: var(--gold); }
.feedback.praise.cyan { color: var(--cyan); }
.feedback.praise.emerald { color: var(--emerald); }
.feedback.praise.amethyst { color: var(--amethyst); }
.feedback.praise.slate { color: var(--slate); }

.input-surface {
  display: flex;
  justify-content: center;
  padding: 18px 0 6px;
}
.stub-answer {
  width: min(320px, 100%);
  min-height: 84px;
  font-size: 1.5rem;
}

/* Two stub skins — distinct ambient themes, nothing at the answer moment. */
.stage.skin-glow {
  background: radial-gradient(120% 90% at 50% 0%, #22306e33, transparent 70%), var(--panel);
  border-color: color-mix(in srgb, var(--cyan) 40%, var(--panel-border));
}
.stage.skin-dash {
  background: linear-gradient(160deg, #2a1b5433, transparent), var(--panel);
  border-color: color-mix(in srgb, var(--amethyst) 40%, var(--panel-border));
}

/* Between blocks — no countdown, one tap to continue. The outer wrapper is a
   plain top-to-bottom column (same shape as .session/.session-block) so the
   header stays pinned top-left (fix F1, finding 4); .handoff-body carries the
   centering, same split renderStart already uses for .session-start. */
.block-handoff {
  flex: 1;
  display: flex;
  flex-direction: column;
}
.handoff-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
}
.handoff-card {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(150deg, #5f7bff, #8a5cff);
  margin-bottom: 8px;
}
.handoff-check {
  font-size: 2.6rem;
  font-weight: 800;
}

/* The done-for-today card: a bounded celebration slot, the come-back line.
   Same header-stays-pinned split as .block-handoff (fix F1, finding 4):
   .done-card is a plain column, .done-body carries the centering. */
.done-card {
  flex: 1;
  display: flex;
  flex-direction: column;
}
.done-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.celebration-slot {
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.done-burst {
  font-size: 4rem;
  color: var(--gold);
  animation: done-pop calc(var(--beat)) ease-out;
}
@keyframes done-pop {
  0% { transform: scale(0.4); opacity: 0; }
  60% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}
.done-title {
  font-size: clamp(1.8rem, 7vw, 2.6rem);
  margin: 0;
}
.done-line {
  color: var(--ink);
  margin: 0;
}
.done-comeback {
  color: var(--ink-dim);
  margin: 4px 0 18px;
}

.home-auth {
  position: absolute;
  top: 16px;
  right: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink-dim);
  font-weight: 700;
}

.home-links {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 18px;
}

/* ---------- signed-in identity + dashboard (chunk 5) ---------- */

/* The signed-in student's small family line: joined class(es) + their own
   stable link code, the thing a parent types into the dashboard to link up. */
.home-family {
  margin-top: 4px;
  font-size: 0.95rem;
}
.home-family-code {
  font-size: 0.85rem;
  margin-top: 2px;
}

.signin {
  display: flex;
  flex-direction: column;
}
.signin-box {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
}
.signin-role {
  width: min(320px, 100%);
}
.signin-name {
  width: min(320px, 100%);
  min-height: 56px;
  border-radius: var(--radius);
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--ink);
  padding: 0 16px;
  font-size: 1.1rem;
  font-family: inherit;
}
.signin-note {
  color: var(--ink-dim);
  min-height: 1.4em;
}

/* ---------- return layer (chunk 3) ---------- */

/* The 5-7 character-continuity greeting on the start card. */
.greeting {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--cyan);
  margin: 0 0 6px;
}

/* Stars per block (8+): three pips, earned ones lit. */
.block-stars {
  display: flex;
  gap: 6px;
  font-size: 2rem;
  line-height: 1;
}
.block-stars .star {
  color: var(--slate);
}
.block-stars .star.on {
  color: var(--gold);
}
.handoff-cheer {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--cyan);
}
.block-replay {
  width: min(320px, 100%);
}

/* End-of-session celebration on the done card. */
.celebration-stars {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--gold);
  margin-top: 6px;
}
.celebration-bonus {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--cyan);
  margin-top: 4px;
}
/* The burst grows a little with the effort tier (never a countdown, no distance). */
.celebration-slot[data-tier='good'] .done-burst {
  font-size: 4.6rem;
}
.celebration-slot[data-tier='big'] .done-burst {
  font-size: 5.4rem;
}

/* Collectibles — quiet chips, never the lead mechanic. */
.collectibles {
  margin: 6px 0 10px;
}
.collectibles-label {
  color: var(--ink-dim);
  margin: 0 0 8px;
}
.collectible-row,
.gallery-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}
.collectible {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 16px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  font-weight: 700;
}
.collectible[data-kind='badge'] {
  border-color: color-mix(in srgb, var(--gold) 45%, var(--panel-border));
}
.collectible-icon {
  font-size: 1.4rem;
}
.done-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

/* The map: stations as a track, position marked, no filling bar. One pack's
   spine shows at a time (fix F1); this tab row is the "kid-obvious" switcher
   to the other registered pack(s). */
.map-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.map-tab {
  flex: 1;
}
.map-tab-current {
  background: linear-gradient(150deg, #5f7bff, #8a5cff);
  border-color: transparent;
  opacity: 1;
}
.map-pack {
  margin-bottom: 22px;
}
.map-pack-name {
  margin-bottom: 4px;
}
.map-where {
  color: var(--ink-dim);
  margin: 0 0 12px;
}
.map-lessons {
  width: 100%;
  margin: 0 0 12px;
}
.lesson-pick-row {
  width: 100%;
  justify-content: flex-start;
  margin-bottom: 8px;
}
.map-track {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.map-station {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 16px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
}
.map-station.current {
  border-color: color-mix(in srgb, var(--cyan) 50%, var(--panel-border));
  background: radial-gradient(120% 120% at 0% 50%, #22306e44, transparent 70%), var(--panel);
}
.map-station.upcoming {
  opacity: 0.55;
}
.map-dot {
  font-size: 1.3rem;
  width: 1.6rem;
  text-align: center;
  color: var(--accent);
}
.map-station.done .map-dot {
  color: var(--emerald);
}
.map-name {
  font-weight: 700;
}

.gallery-empty {
  text-align: center;
  margin-top: 30px;
}

/* ---------- streak + XP (chunk 4) ---------- */

.home-streak,
.home-xp {
  font-weight: 700;
  margin-top: 4px;
}
.home-goal {
  color: var(--ink-dim);
  font-weight: 400;
}
.home-xp {
  color: var(--accent);
}

.done-streak {
  font-size: 1.15rem;
  font-weight: 800;
  margin-top: 6px;
}
.done-streak-note {
  color: var(--ink-dim);
  font-weight: 400;
  font-size: 0.95rem;
  margin: 2px 0 0;
}
.done-xp {
  color: var(--accent);
  font-weight: 700;
  margin-top: 4px;
}

/* ---------- math pack (M3): numpad, answer slots, prompt, lesson, placement ---------- */

.math-prompt,
.math-fact {
  text-align: center;
  font-size: clamp(2.1rem, 8.5vw, 3.2rem);
  font-weight: 700;
  letter-spacing: 0.03em;
}
.math-prompt-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.math-prompt-box .tag {
  font-weight: 800;
  font-size: 0.8rem;
  letter-spacing: 0.14em;
  color: var(--gold);
}
.math-input {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding-top: 10px;
}

.answer-slots {
  display: flex;
  justify-content: center;
  gap: 12px;
  min-height: 68px;
}
.answer-slot {
  width: 52px;
  height: 68px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.1rem;
  font-weight: 700;
  border-bottom: 4px solid var(--panel-border);
  border-radius: 8px 8px 0 0;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.answer-slot.filled {
  border-bottom-color: var(--accent);
  background: rgba(122, 162, 255, 0.08);
}
/* The grey correct answer (invariant 3): shown dim, never a wrong value; typed
   digits cover it slot by slot. */
.answer-slot.ghost {
  color: var(--ink-dim);
  opacity: 0.75;
}
/* Hint-2's reveal pulse — highlight, never a countdown or an error red. */
.answer-slots.reveal .answer-slot {
  animation: reveal-pulse var(--beat) ease-in-out 2;
}
@keyframes reveal-pulse {
  0%, 100% { background: transparent; }
  50% { background: rgba(157, 141, 241, 0.25); border-bottom-color: var(--amethyst); }
}
.answer-slots.flash .answer-slot {
  animation: slot-flash var(--beat) ease-out 1;
}
@keyframes slot-flash {
  0% { background: var(--flash, rgba(255, 210, 63, 0.35)); border-bottom-color: var(--flash-border, var(--gold)); }
  100% { background: transparent; }
}

.numpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  width: min(380px, 100%);
  margin: 0 auto;
}
.numpad button {
  min-height: max(var(--tap-min), 11dvh);
  border-radius: 16px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--ink);
  font-family: inherit;
  font-size: 1.7rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.08s ease;
}
.numpad button:active,
.numpad button.pressed {
  transform: scale(0.94);
  background: rgba(122, 162, 255, 0.22);
}
.numpad .pad-back {
  font-size: 1.4rem;
  color: var(--ink-dim);
}
/* Locked (a wrong entry waits out the window): unmistakably off, never red. */
.numpad.locked button {
  opacity: 0.35;
  transform: none;
  background: var(--panel);
  transition: opacity 0.15s ease;
}
.numpad .pad-blank {
  visibility: hidden;
  pointer-events: none;
}

/* Four skins (MATHPACK §9): the answer act as the game move. Two launch
   (runner, friend) plus two second-per-band (builder, garden, M5). */
.stage.skin-runner {
  background: linear-gradient(160deg, #16224a55, transparent), var(--panel);
  border-color: color-mix(in srgb, var(--cyan) 40%, var(--panel-border));
}
.runner-track {
  font-size: 2.6rem;
  min-height: 2.6rem;
}
.runner-figure {
  display: inline-block;
  animation: runner-hop var(--beat) ease-out 1;
}
.runner-track[data-strength='2'] .runner-figure,
.runner-track[data-strength='3'] .runner-figure {
  animation-duration: calc(var(--beat) * 0.7);
}
@keyframes runner-hop {
  0% { transform: translateX(-10px); opacity: 0.4; }
  60% { transform: translateX(6px); opacity: 1; }
  100% { transform: translateX(0); }
}
.stage.skin-friend {
  background: linear-gradient(160deg, #2a1b5433, transparent), var(--panel);
  border-color: color-mix(in srgb, var(--amethyst) 40%, var(--panel-border));
}
.friend-scene {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.friend-face {
  font-size: 2.6rem;
  animation: friend-bob var(--beat) ease-in-out 1;
}
@keyframes friend-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}
.friend-line {
  color: var(--ink-dim);
  font-size: 1rem;
}

/* Builder (8-11, second skin, M5): a tower rises instead of the runner's dash
   down a track — a distinct consequence mechanic, same move-strength ladder. */
.stage.skin-builder {
  background: linear-gradient(160deg, #4a3a1655, transparent), var(--panel);
  border-color: color-mix(in srgb, var(--gold) 40%, var(--panel-border));
}
.builder-site {
  font-size: 2.6rem;
  min-height: 2.6rem;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.builder-tower {
  display: inline-block;
  animation: builder-rise var(--beat) ease-out 1;
}
.builder-site[data-strength='2'] .builder-tower,
.builder-site[data-strength='3'] .builder-tower {
  animation-duration: calc(var(--beat) * 0.7);
}
@keyframes builder-rise {
  0% { transform: translateY(14px) scale(0.7); opacity: 0.4; }
  60% { transform: translateY(-4px) scale(1.05); opacity: 1; }
  100% { transform: translateY(0) scale(1); }
}

/* Garden (5-7, second skin, M5): a plant blooms instead of the fox's step —
   no fail states here either, a slow answer still tends the garden. */
.stage.skin-garden {
  background: linear-gradient(160deg, #1b3a1e40, transparent), var(--panel);
  border-color: color-mix(in srgb, var(--emerald) 40%, var(--panel-border));
}
.garden-scene {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.garden-plant {
  font-size: 2.6rem;
  animation: garden-grow var(--beat) ease-out 1;
}
@keyframes garden-grow {
  0% { transform: scale(0.6); opacity: 0.4; }
  60% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); }
}
.garden-line {
  color: var(--ink-dim);
  font-size: 1rem;
}

/* Placement (MATHPACK §5): plain prompts and praise, no score, no test face. */
.place-intro {
  text-align: center;
  color: var(--ink-dim);
  margin: 0 0 10px;
}
.place-stage {
  gap: 20px;
}
/* The next-op offer (MATHPACK §6): a one-line celebration, not a decision
   screen — placement itself is the entry point, this is just naming it. */
.op-mastered-banner {
  text-align: center;
  font-weight: 600;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 10px 14px;
  margin: 0 0 8px;
}

/* The lesson wall (MATHPACK §8): the group's facts, each with its strategy
   line, one continue button — no chain, no worked line. */
.lesson-stage {
  align-items: stretch;
  text-align: center;
}
.lesson-wall {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.lesson-title {
  margin: 0;
}
.lesson-caption {
  color: var(--ink-dim);
  margin: 0;
}
.lesson-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.lesson-fact {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 16px;
  border-radius: 16px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
}
.lesson-eq {
  font-size: 1.3rem;
  font-weight: 700;
}
.lesson-strategy {
  color: var(--ink-dim);
  font-size: 0.95rem;
  transition: opacity 0.2s ease;
}
/* A fact whose strategy is a genuine substitution (MATHPACK §8): a tap-to-
   toggle chip, `6 + 7` <-> `6 + 6 + 1`. Reset the button defaults so it reads
   exactly like the plain (non-swap) fact cards beside it. */
button.lesson-fact {
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
  width: 100%;
  min-height: var(--tap-min);
}
button.lesson-fact.lesson-fact-swap {
  border-color: color-mix(in srgb, var(--cyan) 45%, var(--panel-border));
}
button.lesson-fact.lesson-fact-swap .lesson-eq::after {
  content: ' ⇄';
  color: var(--cyan);
  font-weight: 400;
}
button.lesson-fact.swapped .lesson-eq {
  color: var(--cyan);
}
.lesson-go {
  width: min(320px, 100%);
  align-self: center;
}

/* ---------- spelling pack (S4): keypad, tiles, dictation, compare, reteach ---------- */

.spell-prompt-box {
  min-height: 1.6rem;
  text-align: center;
}
.spell-prompt-box .tag {
  font-weight: 800;
  font-size: 0.8rem;
  letter-spacing: 0.14em;
  color: var(--gold);
}
.spell-listen {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin: 4px 0 10px;
}
.spell-listen-label {
  font-weight: 700;
  color: var(--ink-dim);
}
.spell-model {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--ink-dim);
}

/* The typed attempt: grows one box per keystroke, never pre-sized to the
   (hidden) target length — a fixed-length row would both leak the answer's
   length and structurally forbid a genuine wrong-length guess. */
.spell-attempt-row {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 56px;
  margin-bottom: 8px;
}
.spell-slot {
  width: 42px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  font-weight: 700;
  border-bottom: 4px solid var(--panel-border);
  border-radius: 8px 8px 0 0;
  background: rgba(122, 162, 255, 0.06);
}
.spell-slot.filled {
  border-bottom-color: var(--accent);
}
.spell-slot.ghost {
  color: var(--ink-dim);
  opacity: 0.75;
  border-bottom-color: var(--panel-border);
}

.spell-input {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.spell-keypad-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
}
.spell-actions {
  display: flex;
  gap: 10px;
  width: min(380px, 100%);
}
.spell-actions .btn {
  flex: 1;
  min-height: var(--tap-min);
}
.spell-replay {
  min-height: var(--tap-min);
}

/* The app-drawn keypad (ported from spellcavern, SPELLPACK §7). */
.keypad {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(460px, 100%);
  margin: 0 auto;
}
.keypad-toolbar {
  display: flex;
  justify-content: flex-end;
}
.keypad-toggle {
  min-height: 40px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--ink);
  font-weight: 700;
  cursor: pointer;
}
.keypad-rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.keypad-row {
  display: flex;
  justify-content: center;
  gap: 6px;
}
.keypad-key {
  flex: 1;
  max-width: 46px;
  min-height: var(--tap-min);
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--ink);
  font-family: inherit;
  font-size: 1.15rem;
  font-weight: 700;
  text-transform: uppercase;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.08s ease;
}
.keypad-key.apostrophe {
  font-size: 1.4rem;
}
.keypad-key.pressed {
  transform: scale(0.92);
  background: rgba(122, 162, 255, 0.22);
}
/* A key rejected by copy mode (the reteach highlight) — a gentle wobble,
   never a buzzer, never red (invariant 3-style rendering). */
.keypad-key.wobble {
  animation: keypad-wobble 0.34s ease;
}
@keyframes keypad-wobble {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}
/* Locked (a wrong submit waits out its brief pause): dim, never red. */
.keypad.locked .keypad-key,
.keypad.locked .keypad-toggle {
  opacity: 0.35;
  pointer-events: none;
}

/* Fix F3, finding 5: the alpha layout (the 5-7 default, invent + ordinary
   dictation) measured ~28px per key at 3 rows of 9 — the shared .keypad-key
   rule above flexes evenly across however many keys share a row, so a wide
   row makes a narrow key. keypad-logic.js's alpha rows are now <=6 keys; a
   FIXED width (not flex-stretch) keeps every row's keys the same size even
   though the last row is shorter, so the short last row centers rather than
   ballooning. Scoped to data-layout='alpha' (the .keypad node's own dataset,
   set by components/keypad.js on every layout switch) so the 8+ QWERTY
   layout's own ~30px, named/accepted tradeoff is untouched. */
.keypad[data-layout='alpha'] .keypad-key {
  flex: 0 0 auto;
  width: 46px;
  max-width: 46px;
}

/* The tile bank (supported first exposure, ported from spellcavern). */
.tile-bank {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: 100%;
}
.tile-slots {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
}
.tile-slot {
  width: 40px;
  height: 48px;
  border-radius: 8px;
  border: 1px dashed var(--panel-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  font-weight: 700;
}
.tile-slot.filled {
  border-style: solid;
  border-color: var(--accent);
  background: rgba(122, 162, 255, 0.1);
}
.tile-tray {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
}
.tile {
  min-width: var(--tap-min);
  min-height: var(--tap-min);
  padding: 0 10px;
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--ink);
  font-family: inherit;
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
}
.tile.fused {
  border-color: color-mix(in srgb, var(--cyan) 45%, var(--panel-border));
  color: var(--cyan);
}
.tile.used {
  opacity: 0.3;
  pointer-events: none;
}
.tile.shake {
  animation: keypad-wobble 0.34s ease;
}

/* The aligned compare (the teaching moment, SPELLPACK §2 step 6): the
   child's own attempt shown, never a violation of the math-only
   never-show-wrong rule. */
.spell-compare {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
}
.spell-compare-label {
  color: var(--ink-dim);
  margin: 6px 0 0;
}
.spell-compare-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}
.spell-compare-letter {
  min-width: 38px;
  height: 46px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  font-size: 1.2rem;
  font-weight: 700;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  font-family: inherit;
  color: var(--ink);
}
.spell-compare-attempt .spell-compare-letter {
  color: var(--ink-dim);
}
/* A differing letter: tappable, never rendered as an error red — amber
   invites a tap, cyan confirms it was marked. */
button.spell-compare-letter.diff {
  cursor: pointer;
  border-color: color-mix(in srgb, var(--gold) 55%, var(--panel-border));
}
button.spell-compare-letter.diff.tapped {
  border-color: color-mix(in srgb, var(--cyan) 55%, var(--panel-border));
  color: var(--cyan);
}

/* The rule reteach card (SPELLPACK §2 step 7, §4): same content the pattern
   lesson shows, the wrong grapheme highlighted on the target. */
.spell-reteach {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 16px;
  border-radius: 16px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  text-align: center;
  width: 100%;
}
.spell-reteach-word {
  font-size: 1.4rem;
  font-weight: 700;
  margin: 0;
}
.spell-grapheme-glow {
  color: var(--gold);
  text-decoration: underline;
  text-decoration-thickness: 3px;
  text-underline-offset: 3px;
}
.spell-reteach-rule {
  color: var(--ink);
  margin: 0;
}
.spell-reteach-watch,
.spell-reteach-exemplars {
  color: var(--ink-dim);
  font-size: 0.92rem;
  margin: 0;
}
.spell-continue {
  width: min(280px, 100%);
  margin-top: 6px;
}
.spell-continue:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.feedback.compare {
  text-align: center;
  color: var(--ink-dim);
  font-weight: 600;
}

/* The pattern lesson wall reuses math's .lesson-wall/.lesson-grid/.lesson-fact
   layout (shared, generic classes); spelling only adds its own word-list tag. */
.spell-exemplar {
  text-align: center;
  font-weight: 700;
}

/* Two launch skins (SPELLPACK §8): the answer act as the game move, never a
   speed flourish (invariant 4). */
.stage.skin-bridge {
  background: linear-gradient(160deg, #2a3a1655, transparent), var(--panel);
  border-color: color-mix(in srgb, var(--cyan) 40%, var(--panel-border));
}
.bridge-scene {
  display: flex;
  justify-content: center;
  min-height: 2.6rem;
}
.bridge-piece {
  font-size: 2.4rem;
  display: inline-block;
  animation: bridge-land var(--beat) ease-out 1;
}
@keyframes bridge-land {
  0% { transform: translateY(-14px) rotate(-8deg); opacity: 0.4; }
  60% { transform: translateY(4px) rotate(2deg); opacity: 1; }
  100% { transform: translateY(0) rotate(0); }
}
.stage.skin-creature {
  background: linear-gradient(160deg, #1b2f3a40, transparent), var(--panel);
  border-color: color-mix(in srgb, var(--emerald) 40%, var(--panel-border));
}
.creature-scene {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.creature-face {
  font-size: 2.4rem;
  animation: creature-bob var(--beat) ease-in-out 1;
}
@keyframes creature-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}
.creature-line {
  color: var(--ink-dim);
  font-size: 1rem;
}

/* Second-per-band skins (S6): distinct completion mechanics from the launch
   pair, unlocked by map progress (SPELLPACK §8). Same reduced-motion rule
   above covers these animations too — no per-skin override needed. */
.stage.skin-door {
  background: linear-gradient(160deg, #3a1e4a55, transparent), var(--panel);
  border-color: color-mix(in srgb, var(--amethyst) 40%, var(--panel-border));
}
.door-scene {
  display: flex;
  justify-content: center;
  min-height: 2.6rem;
}
.door-rune {
  font-size: 2.4rem;
  display: inline-block;
  animation: door-glow var(--beat) ease-out 1;
}
@keyframes door-glow {
  0% { transform: scale(0.7); opacity: 0.4; }
  60% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); }
}
.stage.skin-kite {
  background: linear-gradient(160deg, #1a3a4a40, transparent), var(--panel);
  border-color: color-mix(in srgb, var(--gold) 40%, var(--panel-border));
}
.kite-scene {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.kite-face {
  font-size: 2.4rem;
  animation: kite-rise var(--beat) ease-out 1;
}
@keyframes kite-rise {
  0% { transform: translateY(10px) rotate(-6deg); opacity: 0.5; }
  100% { transform: translateY(0) rotate(0); opacity: 1; }
}
.kite-line {
  color: var(--ink-dim);
  font-size: 1rem;
}

/* ---------- the K-1 invented-spelling activity (SPELLPACK §6) ----------
   Errorless UX at 5-7: no red, no fail framing, no scoring surface. All
   tokens off :root (invariant 1). */

/* Fix F1, finding 3: a tighter .stage just for the invent block — scoped by
   session.js's own data-interaction attribute so math's and spelling's
   dictation .stage (both unflagged, both already fit) are untouched. Invent
   stacks the most content of any block (cue + reveal/trace + a growing
   attempt row + the keypad), so it gets less padding/gap than the shared
   default. */
.session-block[data-interaction='invent'] .stage {
  padding: 16px;
  gap: 8px;
}
.invent-cue {
  text-align: center;
  margin-bottom: 8px;
}
.invent-listen {
  font-weight: 700;
  color: var(--accent);
}
.invent-ask {
  font-size: 1.15rem;
  margin: 6px 0 0;
}
.invent-sound {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  margin: 8px 0 4px;
}
.invent-boxes {
  display: flex;
  justify-content: center;
  gap: 8px;
}
.invent-box {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  border: 2px solid var(--panel-border);
  background: rgba(122, 162, 255, 0.06);
}
.invent-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
}
.invent-input {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
/* Phoneme / letter-sound options: big taps, a wrong one wobbles (never red). */
.invent-options {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
}
.invent-option {
  min-width: 64px;
  min-height: var(--tap-min);
  padding: 0 14px;
  border-radius: 14px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--ink);
  font-family: inherit;
  font-size: 1.5rem;
  font-weight: 700;
  text-transform: lowercase;
  cursor: pointer;
}
.invent-option.wobble {
  animation: keypad-wobble 0.34s ease;
}
/* The reveal + its tracing surface, side by side (fix F1, finding 3) — wraps
   to stacked on a narrow viewport, same as the reveal row's own letters do. */
.invent-reveal-row {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
  width: 100%;
}
/* The one-letter-beyond reveal: the correct letters so far, newest glowing. */
.invent-reveal {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}
.invent-reveal-label {
  color: var(--ink-dim);
  margin-right: 4px;
}
.invent-reveal-letter {
  min-width: 34px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 700;
  border-radius: 8px;
  background: rgba(122, 162, 255, 0.1);
}
.invent-reveal-letter.new {
  color: var(--cyan);
  background: color-mix(in srgb, var(--cyan) 18%, transparent);
  animation: creature-bob var(--beat) ease-in-out 1;
}
/* The tracing surface (D14) — a support, never a gate. */
.invent-trace {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.invent-trace-label {
  color: var(--ink-dim);
  font-size: 0.85rem;
}
.invent-trace-surface {
  /* Fix F1, finding 3: a real support-tool size (not a --tap-min tap target,
     so it can shrink) trimmed to help the keypad + Check button stay
     reachable below it. */
  width: 76px;
  height: 76px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 16px;
  border: 2px dashed var(--panel-border);
  touch-action: none;
  cursor: crosshair;
}
.invent-trace.traced .invent-trace-surface {
  border-style: solid;
  border-color: var(--emerald);
}
.invent-trace-glyph {
  font-size: 2.7rem;
  font-weight: 700;
  color: var(--ink-dim);
  text-transform: lowercase;
}
.invent-attempt {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 56px;
}
.invent-keypad-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
}
.invent-actions {
  display: flex;
  gap: 10px;
  width: min(380px, 100%);
}
.invent-actions .btn {
  flex: 1;
  min-height: var(--tap-min);
}
.invent-replay {
  min-height: var(--tap-min);
}
.invent-whole-word {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--cyan);
  margin: 6px 0;
}

/* ---------- responsive ---------- */

@media (max-width: 480px) {
  #app {
    padding: 12px;
  }
}

@media (min-width: 1025px) and (pointer: fine) {
  #app {
    max-width: 900px;
  }
}

/* Compact layout at short viewport heights (fix F4, finding 4, QA round 3) —
   a landscape phone (844x390) leaves ~390px of vertical room. The lesson
   wall's continue button sat 4+ screens of scroll down (every fact in the
   group stacked in one column) — this fix caps the fact list's own height
   and lets IT scroll internally, rather than the whole page, so the continue
   button stays at a fixed, reachable position (re-measured, Playwright,
   844x390, the worst-case 57-fact group: continue button now at
   y=351.8-384.6, fully inside the viewport, was y=1693). Scoped to
   .lesson-stage; .place-stage keeps the same trims (a real, if partial,
   improvement — see the placement note in HANDOFF, this fix is bounded and
   does not fully close that gap) but the drill's own plain .stage is
   untouched either way. */
@media (max-height: 480px) {
  .place-stage,
  .lesson-stage {
    padding: 12px;
    gap: 8px;
  }
  .place-intro {
    margin: 0 0 4px;
  }
  .op-mastered-banner {
    padding: 6px 10px;
    margin: 0 0 4px;
  }
  .lesson-wall {
    gap: 8px;
  }
  .lesson-grid {
    max-height: 24vh;
    overflow-y: auto;
    gap: 6px;
  }
  .lesson-fact {
    padding: 8px 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}
