/* Little Words, Big Village — one bright kid look (deliberately single-theme).
   Layout: full-screen app; one focal card per screen, plain colored worlds behind it. */
:root {
  --ink: #2B2A4C;
  --ink-soft: #6B6A8E;
  --paper: #FFFFFF;
  --sky: #E9F4FF;
  --sun: #FFD84D;
  --tang: #FF8A3D;
  --vowel: #E5304F;
  --mark: #FFE45C;
  --ok: #22B573;
  --close: #F5A524;
  --again: #8C8FB8;
  --line: #E3E6F2;
  --world: #DFEDFF;
  --accent: #4C9BFF;
  --ui: "Fredoka", "Trebuchet MS", system-ui, sans-serif;
  --word: "Andika", "Fredoka", system-ui, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--world); color: var(--ink);
  font-family: var(--ui); font-size: 18px; overflow: hidden;
  user-select: none; -webkit-user-select: none; touch-action: manipulation;
  transition: background-color .5s ease;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
button:focus-visible { outline: 4px solid var(--tang); outline-offset: 3px; }
.screen { position: absolute; inset: 0; display: flex; flex-direction: column; padding: env(safe-area-inset-top, 0px) 0 env(safe-area-inset-bottom, 0px); }
.screen[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.bar { display: flex; align-items: center; gap: 12px; padding: 14px 18px; min-height: 76px; }
.bar .title { font-weight: 600; font-size: clamp(1.1rem, 2.6vw, 1.6rem); flex: 1; min-width: 0; text-wrap: balance; }
.pill-btn { background: var(--paper); border-radius: 999px; padding: 10px 18px; font-weight: 600; font-size: 1rem; box-shadow: 0 3px 0 rgba(43,42,76,.12); min-height: 52px; display: inline-flex; align-items: center; gap: 8px; }
.icon-btn { width: 56px; height: 56px; border-radius: 50%; background: var(--paper); font-size: 1.6rem; display: grid; place-items: center; box-shadow: 0 3px 0 rgba(43,42,76,.12); flex: none; }
.hold { position: relative; overflow: hidden; }
.hold .fill { position: absolute; inset: 0; background: var(--sun); transform-origin: left; transform: scaleX(0); z-index: 0; }
.hold span { position: relative; z-index: 1; }

/* ---------- gate (tap to start) ---------- */
#gate { align-items: center; justify-content: center; gap: 26px; padding: 24px; text-align: center; background: linear-gradient(180deg, #CFE6FF 0%, #E9F4FF 60%, #FFF6D8 100%); }
.gate-title { font-size: clamp(1.8rem, 5vw, 3rem); font-weight: 600; line-height: 1; }
.gate-title b { color: var(--tang); }
.ticket { display: flex; align-items: stretch; border-radius: 22px; overflow: visible; filter: drop-shadow(0 10px 0 #C35A1E); max-width: 94vw; }
.tk-main { background: var(--tang); color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 26px clamp(22px, 5vw, 56px); border-radius: 22px 0 0 22px; position: relative; }
.tk-main::before { content: ""; position: absolute; inset: 10px; border: 3px solid rgba(255,255,255,.55); border-radius: 14px; pointer-events: none; }
.tk-top { font-size: clamp(.8rem, 1.8vw, 1.05rem); letter-spacing: .12em; text-transform: uppercase; font-weight: 600; opacity: .95; }
.tk-title { font-size: clamp(2.2rem, 7vw, 4.4rem); font-weight: 700; letter-spacing: .06em; line-height: 1; text-shadow: 0 3px 0 rgba(0,0,0,.12); }
.tk-sub { font-size: clamp(1.2rem, 3vw, 1.7rem); font-weight: 600; background: #fff; color: var(--tang); border-radius: 999px; padding: 4px 18px; margin-top: 4px; }
.tk-stub { background: #FFB547; color: #7A3B10; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 18px clamp(14px, 3vw, 26px); border-radius: 0 22px 22px 0; border-left: 4px dashed rgba(122,59,16,.45); position: relative; font-weight: 700; }
.tk-stub::before, .tk-stub::after { content: ""; position: absolute; left: -16px; width: 28px; height: 28px; border-radius: 50%; background: #E3EFFB; }
.tk-stub::before { top: -14px; } .tk-stub::after { bottom: -14px; }
.tk-admit { font-size: clamp(.8rem, 1.8vw, 1rem); letter-spacing: .14em; }
.tk-one { font-size: clamp(2rem, 6vw, 3.4rem); line-height: 1; }
.tk-no { font-size: clamp(.7rem, 1.5vw, .85rem); letter-spacing: .06em; opacity: .8; }
.gate-note { margin: 0; color: var(--ink-soft); font-size: 1.05rem; }

/* ---------- start ---------- */
#start { align-items: center; justify-content: safe center; overflow-y: auto; overflow-x: hidden; gap: 18px; padding: 24px; text-align: center; background: linear-gradient(180deg, #CFE6FF 0%, #E9F4FF 60%, #FFF6D8 100%); }
#start .village { width: 100%; display: flex; justify-content: center; overflow: visible; flex-shrink: 0; padding-top: 4vh; }
#start .train-btn { padding: 0; width: min(92vw, 860px, 120vh); }
#start .train-wrap { position: relative; display: block; width: 100%; aspect-ratio: 1470 / 630; mix-blend-mode: multiply; }
/* Both the picture and the wave clip sit on white; "multiply" lets the sky show through the white. */
#start .train-wrap img, #start .train-wrap video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; filter: brightness(1.05); }
#start .train-wrap video { opacity: 0; }
#start .train-wrap.waving video { opacity: 1; }
/* Steam puffs live outside the blended train layer so they stay bright white. */
#start .train-btn { position: relative; }
#start .puffs { position: absolute; inset: 0; pointer-events: none; mix-blend-mode: multiply; }
/* Copies of the cloud drawn in the picture (img/b/smoke.webp), so the puffs match its style exactly. */
#start .puff { position: absolute; left: 13.605%; top: 9.365%; width: 8.707%; height: auto; filter: brightness(1.05); opacity: 0; transform-origin: 6% 96%; }
/* A white cloud-shaped "eraser" inside the blended train layer hides the drawn cloud while the puffs play. */
#start .train-wrap img.smoke-eraser { inset: auto; left: 13.197%; top: 8.413%; width: 9.524%; height: auto; filter: none; opacity: 0; }
#start h1 { font-size: clamp(2.2rem, 6vw, 3.6rem); margin: 0; line-height: 1; letter-spacing: .01em; }
#start h1 b { color: var(--tang); }
#start .hi { font-size: 1.3rem; color: var(--ink-soft); margin: 0; }
.big-go { background: var(--ok); color: #fff; border-radius: 28px; padding: 22px 36px; font-size: clamp(1.3rem, 3vw, 1.8rem); font-weight: 600; box-shadow: 0 6px 0 #178A57; min-width: min(420px, 90vw); }
.big-go small { display: block; font-size: .65em; font-weight: 500; opacity: .9; margin-top: 2px; }
.link-btn { color: var(--ink-soft); font-weight: 600; text-decoration: underline; text-underline-offset: 4px; padding: 12px; }

/* ---------- kid home ---------- */
#home .grid { flex: 1; display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 18px; padding: 8px 22px 22px; align-content: center; max-width: 1100px; width: 100%; margin: 0 auto; min-height: 0; }
.buddy-card { border-radius: 32px; padding: 18px; display: flex; flex-direction: column; align-items: center; gap: 6px; box-shadow: 0 8px 0 rgba(43,42,76,.14); min-height: 220px; justify-content: center; }
.buddy-card img { width: min(150px, 60%); aspect-ratio: 1; object-fit: contain; }
.buddy-card .nm { font-size: 1.4rem; font-weight: 600; }
.buddy-card .snd { font-size: 1rem; color: var(--ink-soft); }
.game-card { background: #fff; }
.guide { display: flex; align-items: center; gap: 12px; }
.guide img { width: 76px; height: 76px; object-fit: contain; }
.bubble { background: var(--paper); border-radius: 22px; padding: 10px 16px; font-size: 1.15rem; font-weight: 500; position: relative; box-shadow: 0 3px 0 rgba(43,42,76,.1); }

/* ---------- practice ---------- */
#practice .stage { flex: 1; display: grid; grid-template-columns: 1fr minmax(150px, 22%); gap: 14px; padding: 0 18px; min-height: 0; width: 100%; max-width: 1400px; margin: 0 auto; }
#practice .coach { width: 100%; max-width: 1400px; margin: 0 auto; }
.keys { font-size: .85rem; color: var(--ink-soft); }
@media (hover: none) { .keys { display: none; } }
.card { background: var(--paper); border-radius: 36px; box-shadow: 0 10px 0 rgba(43,42,76,.12); display: flex; align-items: center; justify-content: center; gap: clamp(12px, 3vw, 40px); padding: clamp(14px, 3vw, 34px); min-height: 0; position: relative; overflow: auto; }
.card .pic { height: min(100%, 52vh); max-height: 420px; aspect-ratio: 1; object-fit: contain; flex: none; max-width: 48%; }
.card .side { display: flex; flex-direction: column; gap: 18px; align-items: flex-start; min-width: 0; }
.word { font-family: var(--word); font-weight: 700; font-size: clamp(3rem, 9vw, 6.4rem); line-height: 1.05; letter-spacing: .02em; color: var(--ink); overflow-wrap: anywhere; }
.word.phrase { font-size: clamp(2rem, 5.4vw, 4rem); }
.word .v, .lab .v { color: var(--vowel); }
.word .t { background: linear-gradient(to top, transparent 0 18%, var(--mark) 18% 62%, transparent 62%); padding: 0 .05em; border-radius: .1em; }
.cue { font-size: 1.1rem; color: var(--ink-soft); max-width: 30ch; }
.say-row { display: flex; gap: 12px; flex-wrap: wrap; }
.say-btn { background: var(--accent); color: #fff; border-radius: 22px; padding: 14px 24px; font-size: 1.3rem; font-weight: 600; box-shadow: 0 5px 0 rgba(0,0,0,.18); min-height: 64px; }
.say-btn.slow { background: var(--paper); color: var(--ink); box-shadow: 0 5px 0 rgba(43,42,76,.15); border: 3px solid var(--line); }
.say-btn.rec { background: #E5304F; }
.say-btn.rec.on { animation: recpulse 1s ease-in-out infinite; }
@keyframes recpulse { 50% { transform: scale(1.05); box-shadow: 0 0 0 10px rgba(229,48,79,.25); } }
.selfcheck { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; background: var(--sky); border-radius: 22px; padding: 10px 14px; font-size: 1.15rem; font-weight: 600; }
.selfcheck[hidden] { display: none; }
.selfcheck img { width: 52px; height: 52px; object-fit: contain; }
.selfcheck button { border-radius: 16px; padding: 10px 16px; font-weight: 600; min-height: 52px; background: #fff; box-shadow: 0 3px 0 rgba(43,42,76,.15); }
.selfcheck .sc-yes { background: var(--ok); color: #fff; }
.sound-alone { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; }
.sound-alone img { width: min(260px, 40vh); }
.sound-alone .letter { font-family: var(--word); font-size: clamp(5rem, 14vw, 9rem); font-weight: 700; line-height: 1; background: var(--mark); border-radius: 24px; padding: 0 24px; box-shadow: 0 8px 0 #E8C400; }

/* orange tower */
.tower { position: relative; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; min-height: 0; }
.tower .stack { display: flex; flex-direction: column-reverse; align-items: center; margin-bottom: -28px; z-index: 2; }
.tower .stack img { width: 64px; height: 64px; margin-top: -18px; }
.tower .cappy { width: 100%; max-width: 220px; z-index: 1; }

/* grown-up scoring strip */
.coach { display: flex; align-items: center; gap: 10px; padding: 12px 18px 16px; flex-wrap: wrap; }
.coach .lbl { font-size: .95rem; color: var(--ink-soft); font-weight: 500; margin-right: 4px; }
.score { border-radius: 18px; padding: 10px 20px; font-weight: 600; font-size: 1.1rem; color: #fff; min-height: 60px; min-width: 120px; box-shadow: 0 4px 0 rgba(0,0,0,.18); }
.score.ok { background: var(--ok); } .score.close { background: var(--close); } .score.again { background: var(--again); }
.dots { display: flex; gap: 6px; margin-left: auto; }
.dots i { width: 14px; height: 14px; border-radius: 50%; background: rgba(43,42,76,.15); display: block; }
.dots i.ok { background: var(--ok); } .dots i.close { background: var(--close); } .dots i.again { background: var(--again); }
.tries { font-size: .95rem; color: var(--ink-soft); font-weight: 500; }

/* ---------- caboose ---------- */
.train { display: flex; align-items: flex-end; gap: 8px; flex-wrap: nowrap; }
.card.col { flex-direction: column; gap: 14px; }
.card.col .pic { height: min(34vh, 300px); max-width: 100%; }
.card.col .side { align-items: center; text-align: center; }
.car { font-family: var(--word); font-weight: 700; font-size: clamp(1.8rem, 5vw, 3.6rem); line-height: 1; background: #fff; border: 5px solid var(--ink); border-radius: 18px 18px 8px 8px; padding: 10px 14px 16px; position: relative; min-width: 1.6em; text-align: center; }
.car::after { content: ""; position: absolute; left: 18%; right: 18%; bottom: -16px; height: 18px; background: radial-gradient(circle at 25% 50%, var(--ink) 7px, transparent 8px), radial-gradient(circle at 75% 50%, var(--ink) 7px, transparent 8px); }
.car.engine { background: #4C9BFF; color: #fff; }
.car.v { color: var(--vowel); }
.car.cab { background: var(--tang); color: #fff; border-color: #C35A1E; }
.car.cab.loose { margin-left: 40px; }
.pairs { display: flex; gap: clamp(12px, 3vw, 36px); align-items: center; justify-content: center; width: 100%; }
.pair-pic { background: #fff; border: 6px solid var(--line); border-radius: 30px; padding: 10px; display: flex; flex-direction: column; align-items: center; gap: 4px; width: min(36vw, 300px); }
.pair-pic img { width: 100%; aspect-ratio: 1; object-fit: contain; }
.pair-pic .lab { font-family: var(--word); font-weight: 700; font-size: clamp(1.5rem, 3.6vw, 2.4rem); }
.pair-pic.yes { border-color: var(--ok); }
.feed-cappy { width: min(200px, 22vw); }

/* ---------- bubble judge ---------- */
#judge { background: linear-gradient(180deg, #E4F3FF, #F3E9FF); }
.judge-stage { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; padding: 0 18px 22px; min-height: 0; }
.bubble-wrap { position: relative; width: min(52vh, 380px, 80vw); aspect-ratio: 1; }
.bubble-img { position: absolute; inset: 0; width: 100%; height: 100%; }
.bubble-pic { position: absolute; left: 22%; top: 16%; width: 56%; height: 56%; object-fit: contain; border-radius: 50%; }
.bubble-word { position: absolute; left: 0; right: 0; bottom: 14%; text-align: center; font-family: var(--word); font-weight: 700; font-size: clamp(1.6rem, 4vw, 2.4rem); }
.bubble-word .v { color: var(--vowel); }
.judge-btns { display: flex; gap: 18px; flex-wrap: wrap; justify-content: center; }
.judge-btn { border-radius: 28px; padding: 18px 34px; font-size: clamp(1.3rem, 3vw, 1.8rem); font-weight: 600; color: #fff; min-width: 190px; min-height: 76px; box-shadow: 0 6px 0 rgba(0,0,0,.18); }
.judge-btn.yes { background: var(--ok); } .judge-btn.no { background: var(--tang); }
.pop-burst { position: absolute; inset: 0; border-radius: 50%; border: 8px solid rgba(255,255,255,.9); pointer-events: none; }

/* ---------- overlays ---------- */
.overlay { position: fixed; inset: 0; background: rgba(43,42,76,.45); display: grid; place-items: center; z-index: 50; padding: 20px; }
.overlay[hidden] { display: none !important; }
.panel { background: #fff; border-radius: 36px; padding: 28px; max-width: 640px; width: 100%; text-align: center; display: flex; flex-direction: column; gap: 14px; align-items: center; box-shadow: 0 12px 0 rgba(43,42,76,.2); max-height: 92vh; overflow: auto; }
.panel h2 { margin: 0; font-size: clamp(1.6rem, 4vw, 2.4rem); }
.panel img.hero { width: min(220px, 26vh); }
.buddy-card img.wide { width: min(230px, 92%); }
.panel .grown { background: var(--sky); border-radius: 18px; padding: 12px 16px; font-size: 1rem; color: var(--ink); width: 100%; text-align: left; }
.panel .row { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.btn { border-radius: 20px; padding: 14px 24px; font-weight: 600; font-size: 1.15rem; min-height: 60px; box-shadow: 0 4px 0 rgba(0,0,0,.15); }
.btn.go { background: var(--ok); color: #fff; } .btn.alt { background: var(--sky); } .btn.warm { background: var(--tang); color: #fff; }

/* hot spring */
#spring { background: linear-gradient(180deg, #BFE7FF, #E8F7FF); align-items: center; justify-content: center; gap: 10px; text-align: center; }
#spring .breath { width: min(56vh, 380px); aspect-ratio: 1; border-radius: 50%; background: radial-gradient(circle, #FFFFFF 0%, #DDF3FF 60%, #B7E2FF 100%); display: grid; place-items: center; position: relative; }
#spring .breath img { width: 74%; }
#spring .say { font-size: clamp(1.6rem, 4vw, 2.4rem); font-weight: 600; min-height: 1.4em; }

/* ---------- grown-up area ---------- */
#grown { background: #F6F7FB; overflow: auto; }
#grown .wrap { max-width: 980px; margin: 0 auto; width: 100%; padding: 0 20px 40px; display: flex; flex-direction: column; gap: 18px; }
.tabs { display: flex; gap: 8px; flex-wrap: wrap; }
.tab { padding: 10px 18px; border-radius: 999px; background: #fff; font-weight: 600; border: 2px solid var(--line); min-height: 48px; }
.tab[aria-selected="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }
.box { background: #fff; border-radius: 22px; padding: 18px; border: 2px solid var(--line); }
.box h3 { margin: 0 0 10px; font-size: 1.25rem; }
.box p { margin: 0 0 8px; line-height: 1.45; font-family: system-ui, -apple-system, "Segoe UI", sans-serif; font-size: 1rem; }
.muted { color: var(--ink-soft); }
.chips { display: flex; flex-wrap: wrap; gap: 10px; }
.chip { display: flex; align-items: center; gap: 10px; padding: 8px 16px 8px 8px; border-radius: 20px; border: 3px solid var(--line); background: #fff; font-weight: 600; min-height: 64px; }
.chip img { width: 46px; height: 46px; object-fit: contain; }
.chip[aria-pressed="true"] { border-color: var(--accent); background: #EAF3FF; }
.seg { display: inline-flex; border: 2px solid var(--line); border-radius: 14px; overflow: hidden; flex-wrap: wrap; }
.seg button { padding: 10px 16px; font-weight: 600; min-height: 48px; background: #fff; }
.seg button[aria-pressed="true"] { background: var(--ink); color: #fff; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-weight: 600; }
.field input { font: inherit; padding: 12px 14px; border-radius: 14px; border: 2px solid var(--line); min-height: 52px; max-width: 360px; }
.tablewrap { overflow-x: auto; }
table.prog { border-collapse: collapse; width: 100%; min-width: 460px; font-variant-numeric: tabular-nums; }
table.prog th, table.prog td { padding: 10px 12px; text-align: center; border-bottom: 1px solid var(--line); }
table.prog th:first-child, table.prog td:first-child { text-align: left; }
.pct { display: inline-block; min-width: 64px; padding: 4px 10px; border-radius: 10px; font-weight: 600; color: #fff; }
.pct.g { background: var(--ok); } .pct.y { background: var(--close); } .pct.r { background: #E5566B; } .pct.n { background: var(--line); color: var(--ink-soft); }
.days { display: grid; grid-template-columns: repeat(14, 1fr); gap: 6px; }
.days div { aspect-ratio: 1; border-radius: 10px; background: var(--line); display: grid; place-items: center; font-size: .8rem; color: var(--ink-soft); }
.days div.on { background: var(--sun); color: var(--ink); font-weight: 700; }
.stat-row { display: flex; gap: 12px; flex-wrap: wrap; }
.stat { flex: 1; min-width: 150px; background: var(--sky); border-radius: 18px; padding: 14px; }
.stat b { display: block; font-size: 2rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.wins { display: flex; gap: 12px; flex-wrap: wrap; }
.win-btn { flex: 1; min-width: 220px; border-radius: 20px; padding: 16px; font-weight: 600; font-size: 1.1rem; background: var(--sun); box-shadow: 0 4px 0 #E0B400; min-height: 64px; }
.win-btn.b { background: #BFF0D6; box-shadow: 0 4px 0 #7FD3A8; }
.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 22px; border-radius: 999px; font-weight: 600; z-index: 80; }
.toast[hidden] { display: none; }

@media (max-width: 760px) {
  #practice .stage { grid-template-columns: 1fr; }
  .tower { display: none; }
  .card { flex-direction: column; }
  .card .pic { height: auto; width: min(60vw, 280px); max-width: 100%; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
