/* ---------- Design tokens ---------- */
:root {
  /* Palette */
  --ink: #333;
  --accent: #ff7a59;       /* theme orange — the "=" anchor, CTAs */
  --sun: #ffd166;          /* highlights, banner */
  --go: #06d6a0;           /* success green */
  --part-a: #ef476f;       /* coral — first part of a whole */
  --part-b: #118ab2;       /* teal  — second part of a whole */
  --paper: #fff7e6;        /* page background */
  --card: #fff;

  /* Type scale */
  --fs-1: 16px;   /* meta text */
  --fs-2: 22px;   /* buttons, labels */
  --fs-3: 28px;   /* mode titles */
  --fs-4: 44px;   /* inline equations */
  --fs-5: 64px;   /* large equations, counters */
  --fs-6: 110px;  /* celebration numerals */

  /* Shape */
  --radius-sm: 12px;
  --radius-md: 18px;
  --radius-lg: 24px;
  --border: 4px solid var(--ink);
  --lift: 0 4px 0 var(--ink);   /* the chunky "pressable" shadow */
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: "Comic Sans MS", "Chalkboard SE", "Marker Felt", system-ui, sans-serif;
  background: #fff7e6;
  color: #333;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}
#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}
#confetti-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 999;
}

/* ---------- Top bar (shared across modes) ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: #fff;
  border-bottom: 4px solid #ffd166;
  flex: 0 0 auto;
  z-index: 5;
}
.topbar-left, .topbar-right { display: flex; gap: 12px; }
.btn {
  font: inherit;
  font-size: 22px;
  font-weight: bold;
  padding: 14px 22px;
  min-height: 60px;
  min-width: 60px;
  border-radius: 16px;
  border: 4px solid #333;
  background: #fff;
  color: #333;
  cursor: pointer;
  box-shadow: 0 4px 0 #333;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #333; }
.btn-primary { background: #ff7a59; color: #fff; }
.btn-zoo     { background: #ffd166; }
.btn-newgame { background: #06d6a0; color: #fff; }

/* ---------- Home screen ---------- */
/* Everything on the home screen scales with the viewport so all cards
   always fit — no scrolling, no cut-off buttons, on any tablet size. */
.home {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(8px, 1.6vh, 20px);
  padding: clamp(8px, 1.6vh, 20px) 24px;
  position: relative;  /* anchors the grown-ups corner button */
  overflow: hidden;
}
.home h1 {
  font-size: clamp(28px, 5.5vh, 56px);
  margin: 0;
  color: #ff7a59;
  text-shadow: 3px 3px 0 #ffd166;
}
.home-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-auto-rows: minmax(0, 1fr);
  gap: clamp(8px, 1.5vh, 16px);
  width: min(960px, 95vw);
}
@media (max-width: 720px) {
  .home-grid { grid-template-columns: repeat(3, 1fr); }
}
.home-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(2px, 0.8vh, 10px);
  min-height: 0;
  padding: 4px 8px;
  border-radius: var(--radius-lg);
  border: 4px solid #333;
  background: #fff;
  box-shadow: 0 5px 0 #333;
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}
.home-card:active { transform: translateY(3px); box-shadow: 0 2px 0 #333; }
.home-card .emoji { font-size: clamp(30px, 6.5vh, 58px); line-height: 1; }
.home-card .label { font-size: clamp(13px, 2.4vh, 23px); font-weight: bold; text-align: center; }
.card-flip   { background: #ffe5d9; }
.card-build  { background: #d9f0ff; }
.card-balance{ background: #e5ffd9; }
.card-zoo    { background: #fff3b0; }

/* ---------- Game screen ---------- */
.game {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 16px;
  overflow: hidden;
}

/* ---------- Number tiles ---------- */
.num-tile {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 110px;
  height: 110px;
  border-radius: 22px;
  font-size: 70px;
  font-weight: bold;
  border: 5px solid #333;
  background: #fff;
  box-shadow: 0 5px 0 #333;
  color: #fff;
  text-shadow: 2px 2px 0 rgba(0,0,0,0.2);
  flex: 0 0 auto;
}
.num-tile.draggable { cursor: grab; touch-action: none; }
.num-tile.dragging  { cursor: grabbing; z-index: 50; }
.op-tile {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 70px;
  height: 110px;
  font-size: 60px;
  font-weight: bold;
  color: #555;
  flex: 0 0 auto;
}
/* Equals sign in the theme orange so the symmetry "a+b = b+a" pops.
   Plain "+" stays grey. */
.op-tile.op-eq { color: #ff7a59; }

/* Per-digit colors so each number is a distinct visual */
.num-0  { background: #999; }
.num-1  { background: #ef476f; }
.num-2  { background: #f78c6b; }
.num-3  { background: #ffd166; color: #333; text-shadow: none; }
.num-4  { background: #06d6a0; }
.num-5  { background: #118ab2; }
.num-6  { background: #073b4c; }
.num-7  { background: #9b5de5; }
.num-8  { background: #00bbf9; }
.num-9  { background: #00f5d4; color: #333; text-shadow: none; }
/* Two-digit results / distractors (pool tiles, result slot) */
.num-10 { background: #ff9f1c; }
.num-11 { background: #22577a; }
.num-12 { background: #e76f51; }
.num-13 { background: #b298dc; color: #333; text-shadow: none; }
.num-14 { background: #2a9d8f; }
.num-15 { background: #ff6b6b; }
.num-16 { background: #4a4e69; }
.num-17 { background: #ffafcc; color: #333; text-shadow: none; }
.num-18 { background: #1d3557; }

/* Abstract level — strip the colored chrome so the numeral stands on its
   own. Used by Flip It's Level 2 to push the child from the colour cue
   to the symbol itself. Wins over the per-digit .num-N rules via !important. */
.num-tile.abstract {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  color: #333 !important;
  text-shadow: none !important;
  width: auto;
  min-width: 80px;
}
.slot.abstract {
  border: 3px dashed #ccc;
  background: transparent;
}

/* Level picker chips, pinned to the top of the game area so they don't
   crowd the vertically-centered math content. The mode's .game wrapper
   sets position: relative, so absolute here anchors to that. */
.level-picker {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  z-index: 10;
}
.level-chip {
  font: inherit;
  font-size: 18px;
  font-weight: bold;
  padding: 8px 18px;
  border-radius: 999px;
  border: 3px solid #333;
  background: #fff;
  color: #333;
  cursor: pointer;
  box-shadow: 0 3px 0 #333;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}
.level-chip:active { transform: translateY(2px); box-shadow: 0 1px 0 #333; }
.level-chip.active {
  background: #ff7a59;
  color: #fff;
}

/* ---------- Equation rows ---------- */
.equation-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  flex-wrap: nowrap;
}
.equation-half {
  display: flex;
  align-items: center;
  gap: 14px;
}

/* ---------- Dots under number tiles ---------- */
.dots-row {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin-top: 10px;
  min-height: 26px;
  flex-wrap: wrap;
  max-width: 240px;
}
.dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid #333;
}

/* ---------- Build It: drop slots & pool ---------- */
.slots-row {
  display: flex;
  gap: 14px;
  margin-left: 14px;
}
.slot {
  width: 110px;
  height: 110px;
  border: 5px dashed #aaa;
  border-radius: 22px;
  background: rgba(255,255,255,0.6);
}
.slot.op-slot { width: 70px; }
.slot.filled { border-style: solid; border-color: #333; background: transparent; }
.slot.hover  { border-color: #06d6a0; background: rgba(6,214,160,0.15); }

.tile-pool {
  margin-top: 40px;
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
  padding: 20px;
  background: rgba(0,0,0,0.04);
  border-radius: 20px;
}

/* ---------- Balance It ---------- */
.balance-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  height: 100%;
}
.scale {
  position: relative;
  width: min(700px, 90vw);
  height: 280px;
}
.scale-pivot {
  position: absolute;
  left: 50%;
  bottom: 20px;
  width: 20px;
  height: 200px;
  background: #333;
  transform: translateX(-50%);
  border-radius: 6px;
}
.scale-beam {
  position: absolute;
  left: 50%;
  top: 60px;
  width: 100%;
  height: 14px;
  background: #333;
  border-radius: 8px;
  transform-origin: 50% 50%;
  transform: translateX(-50%) rotate(0deg);
  transition: transform 0.5s ease;
}
.scale-beam.tilt-left  { transform: translateX(-50%) rotate(-10deg); }
.scale-beam.tilt-right { transform: translateX(-50%) rotate(10deg); }
.tray {
  position: absolute;
  top: 80px;
  width: 220px;
  min-height: 140px;
  border: 5px solid #333;
  border-top: none;
  border-radius: 0 0 24px 24px;
  background: rgba(255,255,255,0.85);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px;
  align-content: flex-start;
  justify-content: center;
  transition: top 0.5s ease;
}
.tray.left  { left: calc(50% - 230px); }
.tray.right { right: calc(50% - 230px); }
.tray-count {
  position: absolute;
  top: -50px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 36px;
  font-weight: bold;
  background: #fff;
  border: 4px solid #333;
  border-radius: 50%;
  width: 64px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 0 #333;
}
.block {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 3px solid #333;
  flex: 0 0 auto;
  box-shadow: 0 2px 0 #333;
}
.block.red  { background: #ef476f; }
.block.blue { background: #118ab2; }
.block.draggable { cursor: grab; touch-action: none; }
.block-pool {
  margin-top: 20px;
  padding: 16px;
  background: rgba(0,0,0,0.04);
  border-radius: 18px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 90vw;
}

/* ---------- Try-again chip ---------- */
.try-again-chip {
  position: absolute;
  top: 30%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.5);
  background: #ffd166;
  border: 4px solid #333;
  border-radius: 30px;
  padding: 14px 26px;
  font-size: 28px;
  font-weight: bold;
  box-shadow: 0 4px 0 #333;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.3s cubic-bezier(.34,1.56,.64,1);
  z-index: 30;
}
.try-again-chip.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

/* ---------- Animal pop reward ---------- */
.animal-pop {
  position: fixed;
  font-size: 140px;
  z-index: 100;
  pointer-events: none;
  transition: transform 0.9s cubic-bezier(.34,1.56,.64,1), opacity 0.9s ease;
}

/* ---------- Zoo screen ---------- */
.zoo {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 20px;
  overflow: hidden;
}
.zoo h2 {
  margin: 0 0 6px;
  font-size: 40px;
  color: #ff7a59;
  text-shadow: 2px 2px 0 #ffd166;
  text-align: center;
}
.zoo-hint {
  text-align: center;
  font-size: 18px;
  font-weight: bold;
  color: #888;
  margin-bottom: 8px;
}
/* Free-roam canvas: animals are placed anywhere, not in a grid. */
.zoo-canvas {
  flex: 1;
  position: relative;
  overflow: hidden;
  border: 4px dashed #ffd166;
  border-radius: 24px;
  /* a soft meadow-and-sky so it reads as a PLACE, not a list */
  background: linear-gradient(#eaf6ff 0%, #eaf6ff 58%, #e3f7df 58%, #e3f7df 100%);
}
.zoo-pet {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  width: clamp(64px, 12vmin, 104px);
  height: clamp(64px, 12vmin, 104px);
  font-size: clamp(48px, 9vmin, 84px);
  line-height: 1;
  cursor: grab;
  touch-action: none;
  user-select: none;
  transition: filter 0.12s ease;
  z-index: 1;
}
.zoo-pet:active { cursor: grabbing; }
.zoo-pet.dragging {
  z-index: 50;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.3));
}
/* 🧹 Tidy / shuffle button, floating in the canvas corner */
.zoo-tidy {
  position: absolute;
  top: 10px;
  right: 12px;
  z-index: 60;
  font-size: 26px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 3px solid var(--ink);
  background: #fff;
  box-shadow: 0 3px 0 var(--ink);
  cursor: pointer;
}
.zoo-tidy:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.zoo-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: bold;
  color: #888;
  text-align: center;
  padding: 24px;
}
.zoo-count {
  text-align: center;
  font-size: 22px;
  margin-top: 12px;
  font-weight: bold;
  color: #555;
}

/* ---------- Drag transform helper ----------
   While being dragged, an element gets its inline `transform` rewritten on
   every pointermove. Any CSS animation or transition on the same element
   would clobber that on the next animation frame, so kill both here. */
.dragging {
  transform-origin: center;
  transition: none !important;
  animation: none !important;
  z-index: 100;
}

/* ---------- Mode title strip ---------- */
.mode-title {
  font-size: 28px;
  font-weight: bold;
  text-align: center;
  margin: 0 0 16px;
  color: #555;
}

/* ---------- Shared equation component (src/ui.js equation()) ---------- */
.eq {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 2px;
}
.eq-num {
  font-weight: bold;
  color: var(--ink);
  margin: 0 8px;
}
.eq-op {
  font-weight: bold;
  color: #777;
  margin: 0 5px;
}
.eq-op.eq-equals { color: var(--accent); }
.eq-lg .eq-num { font-size: 64px; }
.eq-lg .eq-op  { font-size: 52px; }
.eq-md .eq-num { font-size: var(--fs-4); }
.eq-md .eq-op  { font-size: 36px; }

/* ---------- Big celebration numeral (src/ui.js bigNumeral()) ---------- */
.big-numeral {
  font-size: var(--fs-6);
  font-weight: bold;
  line-height: 1;
  text-shadow: 3px 3px 0 rgba(0, 0, 0, 0.15);
}

/* ---------- Shared answer buttons (src/ui.js answerButtons()) ---------- */
.answer-row {
  display: flex;
  gap: 22px;
  margin-top: 16px;
}
.answer-btn {
  width: 110px;
  height: 110px;
  font-size: 56px;
  border-radius: 22px;
  color: #fff;
  text-shadow: 2px 2px 0 rgba(0,0,0,0.2);
}
.answer-btn.num-3, .answer-btn.num-9 { color: var(--ink); text-shadow: none; }
.answer-btn:disabled { opacity: 0.45; cursor: default; }

/* ---------- Topbar voice + mute buttons ---------- */
.btn-voice { background: #fff; font-size: 26px; }
.btn-mute  { background: #fff; font-size: 26px; }
.home-mute {
  position: absolute;
  top: 14px;
  right: 16px;
  font-size: 26px;
  background: var(--card);
  border: 3px solid var(--ink);
  border-radius: 50%;
  width: 54px;
  height: 54px;
  cursor: pointer;
  box-shadow: 0 3px 0 var(--ink);
}

/* ---------- Wiggle / attention animation ---------- */
@keyframes wiggle {
  0%, 100% { transform: rotate(0deg); }
  25%      { transform: rotate(-8deg); }
  75%      { transform: rotate(8deg); }
}

/* ---------- Home cards for Stack It, Quiz It & Show Me ---------- */
.card-stack  { background: #d9e8ff; }
.card-quiz   { background: #ffe8d9; }
.card-showme { background: #e8d9ff; }
.card-flash  { background: #fff9d9; }
.card-hop    { background: #d9ffe8; }
.card-frame  { background: #ffd9ec; }
.card-story  { background: #e0f7e9; }
.card-feed   { background: #fff0d9; }
.card-howfar { background: #e6f2d9; }

/* ---------- How Far? mode ---------- */
.hf-game {
  align-items: center;
  justify-content: center;
  padding-top: 70px; /* clear the absolute level picker */
}
.hf-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: min(820px, 95vw);
}
.hf-track {
  position: relative;
  width: 100%;
  height: 120px;
}
.hf-rail {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 28px;
  height: 8px;
  background: #c9b88a;
  border-radius: 4px;
}
.hf-start {
  position: absolute;
  bottom: 36px;
  font-size: 34px;
  line-height: 1;
  transform: translateX(-50%);
}
.hf-animal {
  position: absolute;
  bottom: 32px;
  font-size: 44px;
  line-height: 1;
  transform: translateX(-50%);
  touch-action: none;
  z-index: 4;
}
/* The draggable mover gets a measuring pin: a needle under its centre
   touching the rail — the exact point that counts. */
.hf-mover { bottom: 46px; cursor: grab; }
.hf-pin {
  position: absolute;
  left: 50%;
  top: 100%;
  transform: translateX(-50%);
  width: 3px;
  height: 16px;
  background: var(--ink);
  border-radius: 2px;
}
.hf-pin::after {
  content: "";
  position: absolute;
  bottom: -5px;
  left: 50%;
  transform: translateX(-50%);
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--ink);
}
.hf-ribbon-label {
  position: absolute;
  bottom: 4px;
  font-size: 26px;
  font-weight: bold;
  color: var(--ink);
  z-index: 5;
}
.hf-tappable { cursor: pointer; }
.hf-trail {
  position: absolute;
  bottom: 26px;
  height: 12px;
  border-radius: 6px;
  opacity: 0;
  transition: opacity 0.2s ease, width 0.2s ease, background 0.2s ease;
  z-index: 2;
}
.hf-trail.show { opacity: 0.95; }
.hf-ribbon {
  position: absolute;
  bottom: 10px;
  height: 14px;
  border-radius: 7px;
  border: 2px solid #333;
  opacity: 0.95;
  z-index: 3;
}
.hf-ribbon .hf-tick {
  position: absolute;
  top: -8px;
  bottom: -8px;
  width: 3px;
  background: #333;
  border-radius: 2px;
}
.hf-ribbon.blinking { animation: hf-blink 0.5s ease 2; }
.hf-ribbon.fading { opacity: 0; transition: opacity 0.5s ease; }
@keyframes hf-blink {
  0%, 100% { opacity: 0.95; }
  50%      { opacity: 0.35; }
}
.hf-fence-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  align-self: flex-start;
  margin-left: 30px;
}
.hf-fence {
  height: 18px;
  border-left: 4px solid #8a6d3b;
  border-right: 4px solid #8a6d3b;
  background: repeating-linear-gradient(90deg, transparent 0 6px, #8a6d3b 6px 10px);
  background-position: center;
  background-size: 100% 6px;
  background-repeat: no-repeat;
}
.hf-fence-label {
  font-size: 15px;
  font-weight: bold;
  color: #8a6d3b;
}
.hf-meters-word {
  font-size: 40px;
  font-weight: bold;
  color: var(--accent);
}

/* Meter sticks */
.hf-stick-pool {
  display: flex;
  gap: 14px;
  padding: 12px 18px;
  background: rgba(0, 0, 0, 0.04);
  border-radius: var(--radius-md);
}
.hf-stick {
  height: 22px;
  background: #d9a05b;
  border: 3px solid #333;
  border-radius: 6px;
  cursor: grab;
  touch-action: none;
  position: relative;
  flex: 0 0 auto;
}
.hf-stick.placed {
  position: absolute;
  bottom: 24px;
  cursor: default;
  z-index: 2;
}
.hf-stick-num {
  position: absolute;
  top: -26px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 20px;
  font-weight: bold;
  color: var(--ink);
}

/* Two-lane comparison */
.hf-lanes {
  display: flex;
  flex-direction: column;
  width: 100%;
}
.hf-lane { height: 100px; }

/* Trek progress bar */
.hf-trek-bar {
  position: absolute;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  width: min(680px, 90vw);
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 5;
}
.hf-trek-dots {
  position: relative;
  flex: 1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #fff;
  border: 3px solid #333;
  border-radius: 999px;
  padding: 6px 12px;
  height: 30px;
}
.hf-trek-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #ddd;
}
.hf-trek-dot.done { background: var(--go); }
.hf-trek-walker {
  position: absolute;
  top: -16px;
  font-size: 26px;
  line-height: 1;
  transition: left 0.5s ease;
}
.hf-trek-picnic { font-size: 28px; }
.hf-trek-berries {
  font-size: 18px;
  font-weight: bold;
  background: #fff;
  border: 3px solid #333;
  border-radius: 999px;
  padding: 3px 10px;
}

/* SVG paths (short-way + trails) */
.hf-svg {
  width: 100%;
  height: auto;
}
.hf-path {
  fill: none;
  stroke: #c9b88a;
  stroke-width: 8;
  stroke-linecap: round;
}
.hf-path-hit {
  fill: none;
  stroke: transparent;
  stroke-width: 40;
  cursor: pointer;
  pointer-events: stroke;
}
.hf-path.measured.hf-path-straight { stroke: var(--go); }
.hf-path.measured.hf-path-bent     { stroke: var(--accent); }
.hf-path-label {
  font-size: 34px;
  font-weight: bold;
  fill: var(--ink);
  paint-order: stroke;
  stroke: #fff;
  stroke-width: 6;
}
.hf-portion-label {
  font-size: 24px;
  font-weight: bold;
  fill: #8a6d3b;
  paint-order: stroke;
  stroke: #fff7e6;
  stroke-width: 5;
}
.hf-path.choosable {
  stroke: var(--sun);
  animation: hf-choosable 1.2s ease-in-out infinite;
}
@keyframes hf-choosable {
  0%, 100% { stroke-width: 8; }
  50%      { stroke-width: 14; }
}
.hf-trail-progress {
  fill: none;
  stroke: #ffd166;
  stroke-width: 8;
  stroke-linecap: round;
  stroke-dasharray: 0 99999;
}
.hf-trails-frame {
  position: relative;
  width: 100%;
  touch-action: none;
}
.hf-trails-walker {
  position: absolute;
  font-size: 44px;
  line-height: 1;
  transform: translate(-50%, -70%);
  pointer-events: none;
  z-index: 5;
}

/* ---------- Feeding Time mode ---------- */
.feed-game {
  align-items: center;
  justify-content: center;
}
.feed-scene {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin: 10px 0;
}
.feed-bubble {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  border: 4px solid #333;
  border-radius: 24px;
  padding: 8px 22px;
  box-shadow: 0 4px 0 #333;
  position: relative;
}
.feed-bubble::after {
  content: "";
  position: absolute;
  bottom: -14px;
  left: 50%;
  transform: translateX(-50%);
  border: 8px solid transparent;
  border-top-color: #333;
}
.feed-bubble-n {
  font-size: 52px;
  font-weight: bold;
  line-height: 1;
}
.feed-bubble-treat { font-size: 42px; line-height: 1; }
.feed-bubble.granted { background: #e8fff5; border-color: var(--go); }
.feed-animal {
  font-size: 130px;
  line-height: 1;
  margin-top: 14px;
  touch-action: none;
}
.feed-animal.chomp { animation: feed-chomp 0.3s ease; }
.feed-animal.happy { animation: feed-happy 0.6s ease infinite alternate; }
@keyframes feed-chomp {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.12) rotate(-4deg); }
}
@keyframes feed-happy {
  from { transform: translateY(0); }
  to   { transform: translateY(-14px); }
}
.feed-plate {
  min-width: 280px;
  max-width: 420px;
  min-height: 86px;
  margin-top: 10px;
  padding: 12px 18px;
  background: #fff;
  border: 4px solid var(--ink);
  border-radius: 50% / 38%;   /* a plate! */
  box-shadow: 0 4px 0 var(--ink);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: center;
}
.feed-treat.counting {
  transform: scale(1.45);
  filter: drop-shadow(0 0 10px var(--sun));
  transition: transform 0.2s ease;
}
.feed-bubble.blink { animation: hf-blink 0.5s ease 2; }
.feed-btn { margin-top: 14px; }
.feed-pool {
  display: flex;
  gap: 16px;
  padding: 14px 22px;
  background: rgba(0, 0, 0, 0.04);
  border-radius: var(--radius-md);
  margin-top: 8px;
}
.feed-treat {
  font-size: 52px;
  line-height: 1;
  cursor: grab;
  touch-action: none;
}

/* ---------- Daily quest banner (home) ---------- */
.quest-banner {
  display: flex;
  align-items: center;
  gap: 16px;
  width: min(640px, 92vw);
  padding: clamp(8px, 1.6vh, 16px) 24px;
  border-radius: var(--radius-lg);
  border: 4px solid #333;
  background: linear-gradient(105deg, #ffd166, #ff9f1c);
  box-shadow: 0 5px 0 #333;
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
  flex: 0 0 auto;
}
.quest-banner:active { transform: translateY(3px); box-shadow: 0 2px 0 #333; }
.quest-banner-star { font-size: clamp(28px, 4.5vh, 46px); line-height: 1; }
.quest-banner-title {
  font-size: clamp(18px, 3vh, 28px);
  font-weight: bold;
  color: #333;
}
.quest-banner-sub {
  font-size: clamp(12px, 2vh, 17px);
  font-weight: bold;
  color: #6b4f00;
}

/* ---------- Quest progress pill ---------- */
.quest-pill {
  position: fixed;
  top: 96px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fff;
  border: 4px solid #333;
  border-radius: 999px;
  padding: 6px 16px;
  font-size: 24px;
  font-weight: bold;
  box-shadow: 0 4px 0 #333;
  z-index: 500;
}
.quest-pill-close {
  font: inherit;
  font-size: 16px;
  border: none;
  background: #eee;
  border-radius: 50%;
  width: 28px;
  height: 28px;
  cursor: pointer;
  color: #777;
}

/* ---------- Grown-ups page ---------- */
.grownups {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 20px;
  overflow: hidden;
}
.grownups h2 {
  margin: 0 0 4px;
  font-size: 34px;
  color: #ff7a59;
  text-shadow: 2px 2px 0 #ffd166;
  text-align: center;
}
.grownups-sub {
  text-align: center;
  font-size: 18px;
  color: #777;
  font-weight: bold;
  margin-bottom: 16px;
}
.grownups-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 700px;
  width: 100%;
  margin: 0 auto;
}
.grownups-row {
  display: flex;
  align-items: center;
  gap: 14px;
  background: #fff;
  border: 3px solid #333;
  border-radius: 16px;
  padding: 10px 16px;
}
.grownups-emoji { font-size: 30px; flex: 0 0 auto; }
.grownups-main { flex: 1; min-width: 0; }
.grownups-name { font-size: 18px; font-weight: bold; color: #333; }
.grownups-bar {
  height: 12px;
  background: #eee;
  border-radius: 6px;
  margin-top: 5px;
  overflow: hidden;
}
.grownups-bar.untried { background: repeating-linear-gradient(45deg, #f3f3f3 0 8px, #e9e9e9 8px 16px); }
.grownups-bar-fill {
  height: 100%;
  border-radius: 6px;
  transition: width 0.4s ease;
}
.grownups-meta {
  font-size: 14px;
  color: #999;
  font-weight: bold;
  flex: 0 0 auto;
  text-align: right;
  min-width: 90px;
}

/* ---------- Grown-ups corner button on home ---------- */
.grownups-btn {
  position: absolute;
  bottom: 14px;
  right: 16px;
  font-size: 24px;
  background: transparent;
  border: none;
  cursor: pointer;
  opacity: 0.55;
  padding: 8px;
}
.grownups-btn:hover { opacity: 1; }

/* ---------- Story Time mode ---------- */
.story-game {
  align-items: center;
  justify-content: center;
}
.story-cards {
  display: flex;
  gap: 30px;
  margin: 10px 0;
}
.story-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 22px 30px;
  background: #fff;
  border: 4px solid #333;
  border-radius: 24px;
  box-shadow: 0 5px 0 #333;
  min-width: 200px;
}
.story-animal {
  font-size: 80px;
  line-height: 1;
}
.story-treats {
  display: flex;
  gap: 6px;
  font-size: 38px;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 240px;
}
.story-replay {
  font-size: 30px;
  padding: 10px 26px;
  margin: 12px 0 4px;
  background: #fff;
}

/* ---------- Frame It mode ---------- */
.frame-game {
  align-items: center;
  justify-content: center;
  padding-top: 70px; /* clear the absolute level picker */
}
.frame-prompt {
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.frame-numeral {
  font-size: 80px;
  font-weight: bold;
  line-height: 1;
  text-shadow: 3px 3px 0 rgba(0, 0, 0, 0.12);
}
.frame-grid {
  display: grid;
  grid-template-columns: repeat(5, 76px);
  grid-auto-rows: 76px;
  border: 4px solid #333;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 5px 0 #333;
  overflow: hidden;
  margin-top: 8px;
}
.frame-cell {
  border: 2px solid #999;
  display: flex;
  align-items: center;
  justify-content: center;
}
.frame-counter {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 3px solid #333;
  box-shadow: 0 2px 0 #333;
  flex: 0 0 auto;
  cursor: grab;
  touch-action: none;
}
.frame-counter.fixed { cursor: default; }
.frame-pool {
  display: flex;
  gap: 14px;
  margin-top: 26px;
  padding: 14px 22px;
  background: rgba(0, 0, 0, 0.04);
  border-radius: 18px;
}

/* ---------- Hop It mode ---------- */
.hop-game {
  align-items: center;
  justify-content: center;
  padding-top: 70px; /* clear the absolute level picker */
}
.hop-line-wrap {
  width: min(900px, 94vw);
  padding: 90px 40px 30px; /* headroom for the hopping animal */
}
.hop-line {
  position: relative;
  height: 90px;
}
.hop-line.estimating { cursor: pointer; }
.hop-rail {
  position: absolute;
  left: 0;
  right: 0;
  top: 40px;
  height: 10px;
  background: #333;
  border-radius: 6px;
}
.hop-tick {
  position: absolute;
  top: 28px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.hop-tick.tappable {
  cursor: pointer;
  /* generous touch target */
  padding: 14px 16px;
  margin: -14px -16px;
}
.hop-tick-mark {
  width: 6px;
  height: 34px;
  background: #333;
  border-radius: 3px;
}
.hop-tick-label {
  font-size: 26px;
  font-weight: bold;
  color: #333;
  transition: opacity 0.4s ease;
}
.hop-tick-label.hidden { opacity: 0; }
.hop-tick.hop-correct .hop-tick-label { color: #06d6a0; transform: scale(1.3); }
.hop-animal {
  position: absolute;
  top: -52px;
  transform: translateX(-50%);
  z-index: 5;
  pointer-events: none;
}
.hop-animal-inner {
  font-size: 64px;
  line-height: 1;
}
.hop-animal-inner.hopping {
  animation: hop-arc 0.42s ease;
}
@keyframes hop-arc {
  0%   { transform: translateY(0); }
  50%  { transform: translateY(-46px); }
  100% { transform: translateY(0); }
}
.hop-carrot {
  position: absolute;
  top: -46px;
  transform: translateX(-50%);
  font-size: 50px;
  line-height: 1;
  z-index: 4;
  animation: wiggle 1.4s ease-in-out infinite;
}
.hop-carrot.eaten { animation: none; opacity: 0; transition: opacity 0.4s ease; }
.hop-controls {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-top: 10px;
}
.hop-btn {
  background: #06d6a0;
  color: #fff;
  font-size: 28px;
  padding: 16px 36px;
}
.hop-btn:disabled { opacity: 0.6; cursor: default; }
.hop-counter {
  font-size: 54px;
  font-weight: bold;
  color: #333;
  min-width: 50px;
  text-align: center;
}

/* ---------- Flash It mode ---------- */
.flash-game {
  align-items: center;
  justify-content: center;
  padding-top: 70px; /* clear the absolute level picker */
}
.flash-stage-wrap {
  position: relative;
  width: min(520px, 90vw);
  height: 240px;
  border: 4px solid #333;
  border-radius: 24px;
  background: #fff;
  box-shadow: 0 5px 0 #333;
  overflow: hidden;
}
.flash-stage {
  position: absolute;
  inset: 0;
}
.flash-dot {
  position: absolute;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 3px solid #333;
  transform: translate(-50%, -50%);
}
.flash-curtain {
  position: absolute;
  inset: 0;
  background: #ffd166;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 84px;
  transition: transform 0.25s ease;
  transform: translateY(0);
  z-index: 2;
}
.flash-curtain.open { transform: translateY(-101%); }
.flash-peek {
  margin-top: 12px;
  font-size: 28px;
  padding: 8px 24px;
  background: #fff;
}
.flash-answers {
  display: flex;
  gap: 22px;
  margin-top: 16px;
}
.flash-answer {
  width: 110px;
  height: 110px;
  font-size: 56px;
  border-radius: 22px;
  color: #fff;
  text-shadow: 2px 2px 0 rgba(0,0,0,0.2);
}
.flash-answer.num-3, .flash-answer.num-9 { color: #333; text-shadow: none; }
.flash-answer:disabled { opacity: 0.45; cursor: default; }

/* ---------- Show Me mode ---------- */
.showme-game {
  align-items: center;
  justify-content: flex-start;
  padding-top: 70px; /* clear the absolute level picker */
}
.showme-prompt {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 26px;
  min-height: 110px;
  position: relative;
}
.showme-numeral {
  font-size: 96px;
  font-weight: bold;
  line-height: 1;
  text-shadow: 3px 3px 0 rgba(0, 0, 0, 0.12);
}
.showme-curtain {
  font-size: 80px;
  line-height: 1;
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.showme-zone {
  position: relative;
  flex: 1;
  width: min(900px, 94vw);
  margin-top: 14px;
  border: 4px dashed #ffd166;
  border-radius: 26px;
  background: rgba(255, 255, 255, 0.55);
  overflow: hidden;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  min-height: 220px;
}
.showme-hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
  font-weight: bold;
  color: #bba86f;
  pointer-events: none;
}
.showme-count {
  position: absolute;
  top: 10px;
  right: 18px;
  font-size: 64px;
  font-weight: bold;
  color: #333;
  pointer-events: none;
  line-height: 1;
}
.showme-ripple {
  position: absolute;
  width: 86px;
  height: 86px;
  border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, 0.9);
  transform: translate(-50%, -50%);
  pointer-events: none;
  opacity: 0.85;
  box-shadow: 0 0 24px rgba(0, 0, 0, 0.18);
  animation: ripple-in 0.25s cubic-bezier(.34,1.56,.64,1);
}
.showme-ripple.stamp { pointer-events: auto; cursor: pointer; }
.showme-ripple.won { animation: ripple-win 0.6s ease infinite alternate; }
@keyframes ripple-in {
  from { transform: translate(-50%, -50%) scale(0.3); opacity: 0; }
  to   { transform: translate(-50%, -50%) scale(1);   opacity: 0.85; }
}
@keyframes ripple-win {
  from { transform: translate(-50%, -50%) scale(1); }
  to   { transform: translate(-50%, -50%) scale(1.18); }
}

/* ---------- Quiz It mode ---------- */
.quiz-game {
  /* 2 columns × 5 rows must fit without scrolling, so the slot size
     scales with viewport height */
  --quiz-slot: clamp(44px, 7.2vh, 64px);
  align-items: center;
  justify-content: center;
}
.quiz-grid {
  display: grid;
  grid-template-columns: repeat(2, auto);
  gap: clamp(6px, 1.4vh, 14px) 60px;
  margin: 4px 0 12px;
}
.quiz-problem {
  display: flex;
  align-items: center;
  gap: 6px;
}
.quiz-num {
  font-size: 30px;
  font-weight: bold;
  color: #333;
  min-width: 30px;
  text-align: center;
}
.quiz-op {
  font-size: 26px;
  font-weight: bold;
  color: #777;
  margin: 0 2px;
}
.quiz-op.quiz-eq { color: #ff7a59; }

.quiz-slot {
  position: relative;
  width: var(--quiz-slot);
  height: var(--quiz-slot);
  border: 3px dashed #aaa;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  box-sizing: border-box;
}
.quiz-slot.filled { border-style: solid; border-color: #333; background: transparent; }
.quiz-slot.hover  { border-color: #06d6a0; background: rgba(6, 214, 160, 0.15); }
.quiz-slot.correct {
  border-color: #06d6a0;
  background: rgba(6, 214, 160, 0.18);
}
.quiz-slot.incorrect {
  border-color: #ff7a59;
  background: rgba(255, 122, 89, 0.18);
}
/* Quiz tiles (in pool and dropped into slots) override num-tile sizes */
.quiz-tile {
  width: var(--quiz-slot) !important;
  height: var(--quiz-slot) !important;
  font-size: 32px !important;
  border-width: 3px !important;
  border-radius: 12px !important;
  box-shadow: 0 3px 0 #333;
  text-shadow: 1px 1px 0 rgba(0,0,0,0.2);
}
.quiz-slot .quiz-tile {
  box-shadow: none;
}
/* ✓ / ✗ badge in the slot corner */
.quiz-marker {
  position: absolute;
  top: -10px;
  right: -10px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: bold;
  color: #fff;
  z-index: 5;
}
.quiz-marker.correct   { background: #06d6a0; }
.quiz-marker.incorrect { background: #ff7a59; }

.quiz-pool {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  padding: 14px 18px;
  background: rgba(0, 0, 0, 0.04);
  border-radius: 18px;
  max-width: 95vw;
}
.quiz-buttons {
  display: flex;
  gap: 14px;
  margin-top: 14px;
}
.quiz-redo {
  background: #ffd166;
  color: #333;
}

/* ---------- Rectangle Stack mode ---------- */
.rect-game {
  --unit: 22px;     /* 1 number-unit = this many px of height */
  --rect-w: 70px;   /* width of every rectangle */
}
.rect-progress-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 32px;
  margin-bottom: 8px;
  flex-wrap: wrap;
  justify-content: center;
}
.rect-progress-text {
  font-size: 18px;
  font-weight: bold;
  color: #555;
}
.rect-found-chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.rect-found-chip {
  font-size: 16px;
  font-weight: bold;
  padding: 4px 10px;
  border-radius: 999px;
  background: #06d6a0;
  color: #fff;
  border: 2px solid #333;
}

.rect-play {
  display: flex;
  gap: 12px;        /* target & stack almost touching for direct comparison */
  justify-content: center;
  align-items: flex-end;
  margin: 8px 0;
}
.rect-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.rect-col-label {
  font-size: 16px;
  font-weight: bold;
  color: #777;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.rect-col-body {
  display: flex;
  align-items: flex-end;
  /* Slight border around to read as a "container" */
}

/* The stacking area — same height as target, dashed outline so she sees
   the goal even when the stack is empty/short. */
.rect-stack {
  width: var(--rect-w);
  height: calc(var(--rect-h, 1) * var(--unit));
  border: 3px dashed #aaa;
  border-radius: 8px;
  display: flex;
  flex-direction: column-reverse; /* first child = bottom of the stack */
  background: rgba(255, 255, 255, 0.5);
  box-sizing: content-box;
}
/* Slot states for L2/L3 "fill them all, then evaluate" UI */
.rect-stack.slot-empty   { border-color: #ccc; opacity: 0.6; }
.rect-stack.has-pieces   { border-color: #06d6a0; opacity: 1; }
.rect-stack.slot-filled  {
  border-style: solid;
  border-color: #06d6a0;
  background: rgba(6, 214, 160, 0.10);
  opacity: 1;
}

/* A single rectangle — height proportional to value, made of N unit
   cells separated by hairline dividers so a "5" piece visually IS five
   unit-cells, equal in height to five "1" pieces stacked. */
.rect {
  width: var(--rect-w);
  height: calc(var(--rect-h, 1) * var(--unit));
  border: 3px solid #333;
  border-radius: 6px;
  box-shadow: 0 2px 0 #333;
  display: flex;
  flex-direction: column;
  position: relative;
  flex: 0 0 auto;
  box-sizing: border-box;
  overflow: hidden;
}
.rect-unit {
  flex: 1 1 0;
  border-top: 1px solid rgba(0, 0, 0, 0.28);
}
.rect-unit:first-child { border-top: none; }
.rect-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  color: #fff;
  font-weight: bold;
  font-size: 22px;
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.4);
}
/* Rectangles inside a stack: borderless top so adjacent pieces look fused */
.rect-stack .rect {
  border-radius: 0;
  border-width: 2px;
  box-shadow: none;
  margin: 0;
}
.rect-stack .rect:first-child { /* bottom piece in DOM = first appended */
  border-bottom-left-radius: 6px;
  border-bottom-right-radius: 6px;
}
.rect-stack .rect:last-child {  /* top of the stack visually */
  border-top-left-radius: 6px;
  border-top-right-radius: 6px;
}

/* Pool — horizontal row of pieces, aligned at the bottom so heights read */
.rect-pool {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  justify-content: center;
  padding: 14px 20px;
  background: rgba(0,0,0,0.04);
  border-radius: 16px;
  margin-top: 12px;
  flex-wrap: wrap;
  max-width: 95vw;
}
.rect.pool-piece  { cursor: grab; touch-action: none; }
.rect.placed-piece { cursor: grab; touch-action: none; }
.rect-pool .rect { box-shadow: 0 2px 0 #333; }

/* Evaluate button */
.rect-evaluate {
  margin-top: 14px;
  background: #ff7a59;
  color: #fff;
  font-size: 22px;
  padding: 12px 28px;
}
.rect-evaluate:disabled {
  background: #ccc;
  color: #888;
  cursor: not-allowed;
  box-shadow: 0 4px 0 #999;
  border-color: #999;
}

/* Found-combo chip: a tiny rendered stack instead of plain text */
.rect-mini-stack {
  --rect-w: 26px;
  --unit: 8px;
  display: flex;
  flex-direction: column-reverse;
  padding: 5px;
  border: 2px solid #06d6a0;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.7);
  flex: 0 0 auto;
}
.rect-mini-stack .rect-label { font-size: 11px; }
.rect-mini-stack .rect-unit  { border-top-width: 0.5px; }
.rect-mini-stack .rect       { border-width: 1.5px; box-shadow: none; }

/* ---------- Result overlay (Flip It / Stack It celebration) ---------- */
.result-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255, 247, 230, 0.45);
  backdrop-filter: blur(8px) saturate(140%);
  -webkit-backdrop-filter: blur(8px) saturate(140%);
  z-index: 9998;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  opacity: 1;
  transition: opacity 0.3s ease;
  animation: result-overlay-fade-in 0.3s ease;
}
.result-overlay-inner {
  background: #fff;
  border: 6px solid #333;
  border-radius: 28px;
  box-shadow: 0 6px 0 #333;
  padding: 30px 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: result-pop 0.45s cubic-bezier(.34, 1.56, .64, 1);
  max-width: 92vw;
  flex-wrap: wrap;
  gap: 4px;
}
@keyframes result-overlay-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes result-pop {
  0%   { transform: scale(0.5); }
  60%  { transform: scale(1.08); }
  100% { transform: scale(1); }
}

/* ======================================================================
   ECD shell (gallery, screens, top bar additions, parent mode)
   ====================================================================== */

/* A screen = top bar + one body, filling #app */
.screen {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
/* Where a piece mounts (was the mode's game container) */
.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Top bar buttons: icon + label; labels drop on narrow screens */
.topbar .btn { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.btn-home { font-size: 26px; padding: 10px 14px; }
@media (max-width: 900px) {
  .topbar { padding: 10px 12px; }
  .topbar-left, .topbar-right { gap: 8px; }
  .topbar .btn { padding: 10px 14px; }
  .topbar .btn-label { display: none; }
}

/* Language switch */
.lang-pill {
  display: flex;
  gap: 4px;
  padding: 4px;
  border: 4px solid var(--ink);
  border-radius: 999px;
  background: var(--card);
  box-shadow: 0 4px 0 var(--ink);
  align-self: center;
}
.lang-btn {
  font: inherit;
  font-size: 18px;
  font-weight: bold;
  min-width: 44px;
  height: 44px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}
.lang-btn.on { background: var(--sun); }
.lang-pill-lg { align-self: flex-start; }
.lang-pill-lg .lang-btn { min-width: 64px; height: 52px; font-size: 22px; }

/* Gallery: fewer, bigger cards than a topic home */
.gallery-grid {
  grid-template-columns: repeat(3, 1fr);
  width: min(900px, 92vw);
  max-height: 60vh;
}
.gallery .home-card .emoji { font-size: clamp(44px, 12vh, 110px); }
.gallery .home-card .label { font-size: clamp(18px, 3.6vh, 34px); }
.card-topic-math { background: #ffe5d9; }

/* Parent-mode corner: long press fills the ring, then opens */
.grownups-btn { touch-action: none; -webkit-touch-callout: none; }
.grownups-btn .hold-ring {
  position: absolute;
  inset: -2px;
  border-radius: 50%;
  border: 4px solid var(--accent);
  opacity: 0;
  transform: scale(0.6);
  pointer-events: none;
}
.grownups-btn.holding { opacity: 1; }
.grownups-btn.holding .hold-ring {
  opacity: 1;
  transform: scale(1.15);
  transition: transform 1.5s linear, opacity 0.2s ease;
}

/* Parent mode */
.parent-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-width: 700px;
  width: 100%;
  margin: 0 auto;
  padding-bottom: 24px;
  touch-action: pan-y;
}
.parent-section h3 { margin: 0 0 10px; font-size: 22px; color: var(--ink); }
.parent-body .grownups-list { flex: none; overflow: visible; }
.parent-line { font-size: 17px; font-weight: bold; color: #555; padding: 4px 0; }

/* Topic home: chapter numbers (linear topics) and done stars */
.home-card { position: relative; }
.card-num, .card-done {
  position: absolute;
  top: 6px;
  font-size: clamp(12px, 2vh, 18px);
  font-weight: bold;
  line-height: 1;
}
.card-num {
  left: 8px;
  min-width: 1.6em;
  padding: 3px 5px;
  border-radius: 999px;
  background: #fff;
  border: 2px solid var(--ink);
  text-align: center;
}
.card-done { right: 8px; }
.card-topic-electricity { background: #fff3b0; }
.card-elec { background: #e3f1fa; }
