:root {
  --star: #f6a609;
  --heart: #e8453c;
  --triangle: #2c7be5;
  --circle: #8e44ad;
  --book: #2ba84a;
  --find: #00897b;
  --section: var(--star); /* set per-section by JS */

  --bg: #fbf7ee;
  --card: #ffffff;
  --ink: #2a2a33;
  --muted: #cfc6b4;

  --content-font: "Andika", system-ui, sans-serif;
  --ui-font: "Baloo 2", system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; } /* beat .screen's display:flex */

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--ui-font);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* ---------- Start & finish ---------- */
.mascot { font-size: clamp(4rem, 18vw, 10rem); line-height: 1; animation: bob 2.6s ease-in-out infinite; }
.start-title, .finish-title {
  font-family: var(--ui-font);
  font-weight: 800;
  font-size: clamp(2rem, 9vw, 4.5rem);
  color: var(--star);
  margin: 0.2em 0 0.4em;
}
.finish-title { color: var(--heart); }
.finish-date { font-size: clamp(1rem, 4vw, 1.6rem); color: #8a8170; margin-bottom: 1em; }

.big-play {
  width: clamp(120px, 34vw, 220px);
  height: clamp(120px, 34vw, 220px);
  border: none;
  border-radius: 50%;
  background: var(--star);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 12px 0 rgba(0,0,0,0.12), 0 18px 30px rgba(0,0,0,0.18);
  display: grid;
  place-items: center;
  animation: pulse 1.8s ease-in-out infinite;
  transition: transform 0.08s;
}
.big-play.again { background: var(--heart); animation: none; }
.big-play:active { transform: translateY(6px) scale(0.97); box-shadow: 0 6px 0 rgba(0,0,0,0.12); }
.big-play svg { width: 46%; height: 46%; fill: #fff; stroke: #fff; }

/* ---------- Name (honor-code account) ---------- */
.name-input {
  font-family: var(--ui-font);
  font-weight: 700;
  font-size: clamp(1.6rem, 7vw, 3rem);
  text-align: center;
  width: min(90vw, 520px);
  padding: 0.35em 0.5em;
  margin-bottom: 0.6em;
  border: 4px solid var(--star);
  border-radius: 22px;
  background: var(--card);
  color: var(--ink);
  outline: none;
}

/* ---------- Lesson map ---------- */
#map { justify-content: flex-start; padding: clamp(20px, 6vh, 60px) 16px; overflow-y: auto; }
#map-title { color: var(--triangle); }
#lesson-map {
  display: flex;
  flex-wrap: wrap;
  gap: clamp(12px, 3vw, 24px);
  justify-content: center;
  max-width: 900px;
}
.maptile {
  width: clamp(96px, 24vw, 150px);
  height: clamp(96px, 24vw, 150px);
  border-radius: 28px;
  border: 5px solid var(--triangle);
  background: var(--card);
  color: var(--triangle);
  cursor: pointer;
  position: relative;
  display: grid;
  place-items: center;
  box-shadow: 0 9px 0 color-mix(in srgb, var(--triangle) 30%, #d9cfbb);
  transition: transform 0.1s;
}
.maptile:active { transform: translateY(5px); }
.maptile-num { font-family: var(--ui-font); font-weight: 800; font-size: clamp(2.4rem, 9vw, 4rem); }
.maptile-badge { position: absolute; top: -10px; right: -8px; font-size: clamp(1.4rem, 5vw, 2.2rem); }
.maptile.done { border-color: var(--book); color: var(--book); box-shadow: 0 9px 0 color-mix(in srgb, var(--book) 30%, #d9cfbb); }
.maptile.locked { border-color: var(--muted); color: var(--muted); background: #f1ece0; box-shadow: none; cursor: not-allowed; }

/* ---------- Progress strip ---------- */
#progress {
  display: flex;
  gap: clamp(6px, 2vw, 18px);
  padding: clamp(10px, 3vh, 22px) 12px;
  flex-wrap: wrap; /* many-section lessons / narrow screens: chips wrap, never clipped */
  justify-content: center;
}
.chip {
  width: clamp(46px, 11vw, 68px);
  height: clamp(46px, 11vw, 68px);
  border-radius: 22%;
  background: var(--card);
  border: 3px solid var(--muted);
  display: grid;
  place-items: center;
  cursor: pointer;
  position: relative;
  transition: transform 0.12s, border-color 0.2s;
  opacity: 0.55;
}
.chip svg { width: 58%; height: 58%; }
.chip.current { opacity: 1; transform: scale(1.12); border-color: var(--chip); box-shadow: 0 6px 16px rgba(0,0,0,0.14); }
.chip.current { animation: chipPulse 1.6s ease-in-out infinite; }
.chip.done { opacity: 1; }
.chip.done::after {
  content: "✓";
  position: absolute;
  right: -4px; top: -8px;
  font-size: clamp(0.8rem, 3vw, 1.2rem);
  font-weight: 800;
  color: #fff;
  background: var(--book);
  border-radius: 50%;
  width: 1.5em; height: 1.5em;
  display: grid; place-items: center;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

/* ---------- Stage ---------- */
#stage {
  flex: 1;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: safe center; /* keep top reachable when content overflows */
  gap: clamp(12px, 3vh, 28px);
  padding: clamp(10px, 2vh, 24px) clamp(12px, 4vw, 40px);
  overflow-y: auto;
  overflow-x: hidden;
  font-family: var(--content-font);
}

.tilegrid {
  display: flex;
  flex-wrap: wrap;
  gap: clamp(12px, 3vw, 28px);
  align-items: center;
  justify-content: center;
  max-width: 1100px;
}
.tile {
  font-family: var(--content-font);
  font-weight: 700;
  font-size: clamp(2rem, 9vw, 5.5rem);
  line-height: 1;
  color: var(--ink);
  background: var(--card);
  border: 4px solid var(--section);
  border-radius: 24px;
  padding: clamp(12px, 3vw, 32px) clamp(18px, 5vw, 48px);
  min-width: clamp(80px, 18vw, 150px);
  min-height: 88px;
  text-align: center;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.28em;
  box-shadow: 0 8px 0 color-mix(in srgb, var(--section) 28%, #d9cfbb);
  transition: transform 0.1s, box-shadow 0.1s, background 0.2s;
}
.tile .label { line-height: 1; }

/* star: three dots that fill as the child says + taps each sound three times */
.dots { display: flex; gap: 0.4em; }
.dot {
  width: clamp(12px, 2.4vw, 18px);
  height: clamp(12px, 2.4vw, 18px);
  border-radius: 50%;
  background: color-mix(in srgb, var(--section) 22%, #ded4c0);
  transition: background 0.15s, transform 0.15s;
}
.dot.on { background: var(--section); transform: scale(1.12); }
.tile.pop { animation: pop 0.26s ease; }
@keyframes pop { 0%, 100% { transform: scale(1); } 45% { transform: scale(1.1); } }

/* sounds section: focus the current sound; the others become small faded chips, out of the way */
.tile.focus { transform: scale(1.06); }
.tile.dim {
  font-size: clamp(0.9rem, 3vw, 1.5rem);
  min-width: 0;
  min-height: 0;
  padding: 0.4em 0.7em;
  opacity: 0.3;
  pointer-events: none;
  border-width: 3px;
  box-shadow: 0 3px 0 color-mix(in srgb, var(--section) 18%, #ded4c0);
}
.tile.dim .dots { display: none; }
.tile.focus.awaiting { animation: invite 1.5s ease-in-out infinite; } /* nudge: now tap to say it */
@keyframes invite { 0%, 100% { transform: scale(1.06); } 50% { transform: scale(1.13); } }

/* Listen & Find game */
.game {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(16px, 4vh, 36px);
}
.game-pips { display: flex; gap: clamp(8px, 2vw, 14px); }
.game-pip {
  width: clamp(16px, 4vw, 26px);
  height: clamp(16px, 4vw, 26px);
  border-radius: 50%;
  background: color-mix(in srgb, var(--section) 22%, #ded4c0);
  transition: background 0.2s, transform 0.2s;
}
.game-pip.on { background: var(--section); transform: scale(1.15); }
/* quiz score strip (10): green = right, red = wrong */
.quiz-pips { flex-wrap: wrap; max-width: 460px; justify-content: center; gap: clamp(6px, 1.6vw, 10px); }
.quiz-pips .game-pip { width: clamp(14px, 3.2vw, 20px); height: clamp(14px, 3.2vw, 20px); }
.game-pip.ok { background: var(--book); transform: scale(1.1); }
.game-pip.no { background: var(--heart); transform: scale(1.1); }
/* the word shown for a "which sound is in this word?" question */
.quiz-prompt:empty { display: none; }
.quiz-prompt {
  font-family: var(--content-font);
  font-weight: 700;
  font-size: clamp(2.4rem, 11vw, 5rem);
  color: var(--ink);
}

/* blend: parts -> word (the early-lesson triangle) */
.blendlist { display: flex; flex-direction: column; gap: clamp(12px, 3vh, 26px); align-items: center; }
.blend { display: flex; align-items: center; gap: clamp(8px, 2vw, 18px); flex-wrap: wrap; justify-content: center; }
.blend-arrow { font-size: clamp(2rem, 7vw, 3.4rem); color: var(--section); font-weight: 800; }
.game-listen {
  width: clamp(84px, 20vw, 130px);
  height: clamp(84px, 20vw, 130px);
  border-radius: 50%;
  border: none;
  background: var(--section);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow: 0 8px 0 color-mix(in srgb, var(--section) 32%, #000), 0 12px 22px rgba(0, 0, 0, 0.16);
  animation: pulse 1.8s ease-in-out infinite; /* tap me to hear it */
}
.game-listen:active { transform: translateY(5px); }
.game-listen svg { width: 48%; height: 48%; fill: #fff; stroke: #fff; }
.tile.correct { background: var(--book); color: #fff; border-color: var(--book); }
.tile.locked { pointer-events: none; }
.tile.wrong { animation: shake 0.4s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-9px); }
  40%, 80% { transform: translateX(9px); }
}

/* the moving "pointer" highlight a learner leaves as they read (no audio) */
.tile.pointing { background: color-mix(in srgb, var(--section) 16%, #fff); transform: translateY(-4px); }

/* sound-help: the lesson's new sounds, available while reading the heart/triangle sections */
.soundhelp {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: clamp(8px, 2vw, 16px);
  margin-top: clamp(14px, 4vh, 36px);
}
.soundhelp-icon { font-size: clamp(1.3rem, 4vw, 2rem); }
.tile.mini {
  font-size: clamp(1.1rem, 4vw, 2.2rem);
  padding: clamp(8px, 1.8vw, 14px) clamp(12px, 3vw, 22px);
  min-width: clamp(60px, 13vw, 100px);
  min-height: 56px;
  border-width: 3px;
  box-shadow: 0 5px 0 color-mix(in srgb, var(--section) 28%, #d9cfbb);
}
.tile.sound { letter-spacing: 0.04em; }

/* many tiles (long word lists, the alphabet): shrink so they fit without clipping */
.tilegrid.dense { gap: clamp(8px, 2vw, 16px); }
.tilegrid.dense .tile {
  font-size: clamp(1.1rem, 4.2vw, 2.3rem);
  padding: clamp(8px, 2vw, 18px) clamp(12px, 3.2vw, 26px);
  min-width: clamp(64px, 15vw, 120px);
  min-height: 64px;
  border-width: 3px;
}
.tile:active { transform: translateY(5px); box-shadow: 0 3px 0 color-mix(in srgb, var(--section) 28%, #d9cfbb); }
.tile.speaking { background: color-mix(in srgb, var(--section) 16%, #fff); transform: translateY(-6px) scale(1.05); box-shadow: 0 14px 0 color-mix(in srgb, var(--section) 30%, #d9cfbb); }
.tile.done { border-color: color-mix(in srgb, var(--section) 55%, #d9cfbb); }

/* sentences */
.sentence {
  font-family: var(--content-font);
  font-weight: 700;
  font-size: clamp(1.4rem, 5vw, 2.9rem);
  line-height: 1.38;
  text-align: center;
  max-width: 1000px;
}
.word {
  display: inline-block;
  min-width: 1.1em;
  padding: 0.14em 0.3em;
  margin: 0.05em 0.04em;
  border-radius: 14px;
  cursor: pointer;
  text-align: center;
  transition: transform 0.1s, background 0.15s, color 0.15s;
}
.word:active { transform: scale(0.94); }
.word.speaking,
.word.pointing { background: var(--section); color: #fff; transform: scale(1.12); }

/* read-aloud */
.readaloud { text-align: center; display: flex; flex-direction: column; align-items: center; gap: clamp(14px, 4vh, 36px); }
.readaloud .book { font-size: clamp(5rem, 22vw, 12rem); animation: bob 2.6s ease-in-out infinite; }

/* ---------- Controls ---------- */
#controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(20px, 8vw, 70px);
  padding: clamp(12px, 3vh, 26px) 12px calc(clamp(12px, 3vh, 26px) + env(safe-area-inset-bottom));
}
.ctrl {
  width: clamp(64px, 16vw, 96px);
  height: clamp(64px, 16vw, 96px);
  border-radius: 50%;
  border: none;
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow: 0 7px 0 rgba(0,0,0,0.1), 0 10px 20px rgba(0,0,0,0.12);
  transition: transform 0.08s, box-shadow 0.08s, opacity 0.2s;
}
.ctrl:active { transform: translateY(4px); box-shadow: 0 3px 0 rgba(0,0,0,0.1); }
.ctrl svg { width: 46%; height: 46%; fill: currentColor; }
.ctrl-replay { background: var(--section); color: #fff; width: clamp(76px, 19vw, 120px); height: clamp(76px, 19vw, 120px); }
.ctrl-next { background: var(--book); color: #fff; }
.ctrl-next.ready { animation: pulse 1.4s ease-in-out infinite; }
.ctrl[disabled] { opacity: 0.25; pointer-events: none; box-shadow: none; }

/* ---------- Confetti ---------- */
#confetti { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.confetti-bit { position: absolute; top: -10vh; font-size: clamp(1.2rem, 4vw, 2.2rem); animation: fall linear forwards; }

/* ---------- Animations ---------- */
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.06); } }
@keyframes chipPulse { 0%,100% { transform: scale(1.12); } 50% { transform: scale(1.22); } }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-12px); } }
@keyframes fall { to { transform: translateY(115vh) rotate(540deg); } }

/* ---------- Entry: who's reading ---------- */
.entry-title { color: var(--triangle); }
.learner-row, .avatar-grid {
  display: flex;
  flex-wrap: wrap;
  gap: clamp(12px, 3vw, 24px);
  justify-content: center;
  align-items: center;
  max-width: 900px;
  padding: 0 12px;
}
.learner-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15em;
  border: 5px solid var(--triangle);
  background: var(--card);
  border-radius: 28px;
  padding: clamp(10px, 3vw, 22px) clamp(14px, 4vw, 30px);
  cursor: pointer;
  box-shadow: 0 8px 0 color-mix(in srgb, var(--triangle) 30%, #d9cfbb);
  transition: transform 0.1s;
}
.learner-chip:active { transform: translateY(5px); }
.learner-chip.add { border-style: dashed; color: var(--triangle); }
.learner-av { font-size: clamp(3rem, 12vw, 6rem); line-height: 1; }
.learner-name { font-family: var(--ui-font); font-weight: 800; font-size: clamp(1.2rem, 4vw, 2rem); color: var(--ink); }
.avatar-btn {
  font-size: clamp(3rem, 13vw, 6rem);
  line-height: 1;
  background: var(--card);
  border: 5px solid var(--star);
  border-radius: 26px;
  padding: clamp(6px, 2vw, 14px);
  cursor: pointer;
  box-shadow: 0 7px 0 color-mix(in srgb, var(--star) 30%, #d9cfbb);
  transition: transform 0.1s;
}
.avatar-btn:active { transform: translateY(5px); }
.name-btns { display: flex; align-items: center; gap: clamp(18px, 6vw, 44px); margin-top: 0.4em; }
.name-go { width: clamp(96px, 26vw, 150px); height: clamp(96px, 26vw, 150px); animation: none; }
.skip-btn {
  font-family: var(--ui-font);
  font-weight: 800;
  font-size: clamp(1.4rem, 6vw, 2.4rem);
  color: #fff;
  background: var(--triangle);
  border: none;
  border-radius: 22px;
  padding: 0.4em 1.1em;
  cursor: pointer;
  box-shadow: 0 8px 0 color-mix(in srgb, var(--triangle) 32%, #000);
}
.skip-btn:active { transform: translateY(4px); }

/* ---------- Map head + grown-up ---------- */
#map-head {
  display: flex;
  align-items: center;
  gap: clamp(12px, 3vw, 24px);
  width: min(900px, 94vw);
  margin-bottom: clamp(16px, 4vh, 32px);
}
.map-av { font-size: clamp(2.6rem, 9vw, 4.5rem); line-height: 1; }
.map-info { flex: 1; }
.map-name { font-family: var(--ui-font); font-weight: 800; font-size: clamp(1.4rem, 5vw, 2.4rem); color: var(--triangle); }
.map-bar { height: clamp(12px, 2.4vh, 18px); border-radius: 999px; background: #e8e0d0; overflow: hidden; margin: 0.3em 0; }
.map-bar-fill { height: 100%; background: var(--book); border-radius: 999px; transition: width 0.4s; }
.map-count { font-family: var(--ui-font); font-weight: 700; font-size: clamp(1rem, 3.5vw, 1.5rem); color: #8a8170; }
.maptile.current { border-color: var(--star); color: var(--star); box-shadow: 0 9px 0 color-mix(in srgb, var(--star) 30%, #d9cfbb); animation: pulse 1.6s ease-in-out infinite; }
.maptile-score { position: absolute; bottom: 6px; font-family: var(--ui-font); font-weight: 700; font-size: clamp(0.7rem, 2.4vw, 1rem); color: var(--book); }
.grownup-btn {
  position: fixed;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  width: clamp(52px, 13vw, 74px);
  height: clamp(52px, 13vw, 74px);
  border-radius: 50%;
  border: 3px solid var(--muted);
  background: var(--card);
  font-size: clamp(1.4rem, 5vw, 2rem);
  cursor: pointer;
  box-shadow: 0 5px 12px rgba(0,0,0,0.14);
  opacity: 0.55;
  overflow: hidden;
}
.grownup-btn.on { opacity: 1; border-color: var(--circle); }
.grownup-btn.holding::after {
  content: "";
  position: absolute;
  inset: 0;
  background: color-mix(in srgb, var(--circle) 40%, transparent);
  animation: gate 2s linear forwards;
}
@keyframes gate { from { clip-path: inset(100% 0 0 0); } to { clip-path: inset(0 0 0 0); } }

/* practice-word help marks (subtle dot) */
.tile.helped::after,
.word.helped::after {
  content: "•";
  position: absolute;
  top: -2px; right: 6px;
  color: var(--section);
  font-size: 1.4em;
  line-height: 1;
}
.tile { position: relative; }
.word.helped { position: relative; }

/* grown-up check strip */
.grownup-strip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(10px, 3vh, 20px);
  margin-top: clamp(16px, 4vh, 32px);
  padding: clamp(12px, 3vh, 22px);
  border: 3px dashed var(--circle);
  border-radius: 24px;
  width: min(1000px, 94vw);
}
.grownup-hint { font-size: clamp(1.6rem, 6vw, 2.6rem); }
.grownup-words { display: flex; flex-wrap: wrap; gap: clamp(8px, 2vw, 14px); justify-content: center; }
.grownup-words .tile { border-color: var(--circle); box-shadow: 0 5px 0 color-mix(in srgb, var(--circle) 28%, #d9cfbb); }
.grownup-words .tile.marked { background: var(--circle); color: #fff; }
.done-btn {
  width: clamp(64px, 16vw, 90px);
  height: clamp(64px, 16vw, 90px);
  border-radius: 50%;
  border: none;
  background: var(--book);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow: 0 6px 0 color-mix(in srgb, var(--book) 32%, #000);
}
.done-btn:active { transform: translateY(4px); }
.done-btn svg { width: 52%; height: 52%; }

/* decode quiz: three big colored speaker tiles, no text */
.speaker-tile { min-width: clamp(96px, 26vw, 170px); }
.speaker-tile .spk { font-size: clamp(2.6rem, 11vw, 5rem); line-height: 1; }
.game-choices .speaker-tile:nth-child(1) { border-color: var(--triangle); box-shadow: 0 8px 0 color-mix(in srgb, var(--triangle) 30%, #d9cfbb); border-radius: 28px; }
.game-choices .speaker-tile:nth-child(2) { border-color: var(--heart); box-shadow: 0 8px 0 color-mix(in srgb, var(--heart) 30%, #d9cfbb); border-radius: 50%; }
.game-choices .speaker-tile:nth-child(3) { border-color: var(--star); box-shadow: 0 8px 0 color-mix(in srgb, var(--star) 30%, #d9cfbb); border-radius: 14px; }
.speaker-tile.correct { background: var(--book); border-color: var(--book); }

/* finish extras */
.finish-helped { font-family: var(--ui-font); font-weight: 700; font-size: clamp(0.95rem, 3.4vw, 1.4rem); color: #8a8170; margin-bottom: 0.8em; }
.finish-btns { display: flex; align-items: center; gap: clamp(20px, 8vw, 60px); }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; }
}
