/* Leer & Speel
   Layout: one phone-width column. Every kid control is a chunky cut-out with an ink outline and a
   solid drop shadow, to match the colouring-book pictures from the Pack Factory. Grown-up screens
   use plain system text instead. */
:root {
  --bg: #E4F1FA;          /* sky */
  --paper: #FFFFFF;       /* cards and bubbles */
  --text: #26303F;        /* text on the page */
  --muted: #5D6C80;
  --line: #C9D7E4;
  --edge: #26303F;        /* outlines and drop shadows */
  --ink: #26303F;         /* text and outlines on the pastel tiles (same in both themes) */
  --sheet: #FFFFFF;       /* white inside tile drawings (same in both themes) */
  --accent: #2D78C8;
  --on-accent: #FFFFFF;
  --good: #3E9F4C;
  --on-good: #FFFFFF;
  --try: #E46A3B;
  --scrim: rgba(23, 32, 51, 0.55);
  --trace-fill: #DCEBF7;
  --trace-line: #7C9BB8;
  --crayon: #F28A1E;
  --land: #CFEBB9;
  --land-sky: #D9EEFB;
  --sea: #9ED3EF;
  --sea-deep: #6FB5DD;
  --screen: #10151F;

  --t-count: #FFE08A;
  --t-trace: #FFC4AF;
  --t-line: #BFE8CB;
  --t-add: #C5DBFF;
  --t-words: #E4CEFF;
  --t-stickers: #FFD2E7;
  --t-stories: #FFE3BF;
  --t-watch: #C8EFF4;

  --font: ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", "Nunito", "Segoe UI", Roboto, system-ui, sans-serif;
  --font-adult: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --r: 22px;
  --drop: 5px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #162034; --paper: #222E47; --text: #EAF0FA; --muted: #A8B6CC; --line: #34425E;
    --edge: #0A0F1C; --accent: #6FB0F2; --on-accent: #0E1626; --good: #5CC06A; --on-good: #0E1626;
    --try: #F08A60; --scrim: rgba(5, 8, 16, 0.7); --trace-fill: #2C3A57; --trace-line: #8FA8C8;
    --crayon: #FFA640; --land: #9CCB86; --land-sky: #A9CDE6; --sea: #4E8FBD; --sea-deep: #3A78A6;
    --t-count: #F4D57A; --t-trace: #F2B39E; --t-line: #A9DABA; --t-add: #B0CBF5; --t-words: #D3BBF2;
    --t-stickers: #F1BFD6; --t-stories: #F2D3AC; --t-watch: #B3E0E6;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #162034; --paper: #222E47; --text: #EAF0FA; --muted: #A8B6CC; --line: #34425E;
  --edge: #0A0F1C; --accent: #6FB0F2; --on-accent: #0E1626; --good: #5CC06A; --on-good: #0E1626;
  --try: #F08A60; --scrim: rgba(5, 8, 16, 0.7); --trace-fill: #2C3A57; --trace-line: #8FA8C8;
  --crayon: #FFA640; --land: #9CCB86; --land-sky: #A9CDE6; --sea: #4E8FBD; --sea-deep: #3A78A6;
  --t-count: #F4D57A; --t-trace: #F2B39E; --t-line: #A9DABA; --t-add: #B0CBF5; --t-words: #D3BBF2;
  --t-stickers: #F1BFD6; --t-stories: #F2D3AC; --t-watch: #B3E0E6;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
:root { padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
img { max-width: 100%; -webkit-user-drag: none; }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 4px solid var(--accent); outline-offset: 3px; }

#app {
  max-width: 560px;
  min-height: 100%;
  margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 12px 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.boot { margin: 40vh 0 0; text-align: center; font: 800 1.6rem var(--font); color: var(--muted); }

/* ---------- shared kid controls */
.press {
  border: 3px solid var(--edge);
  border-radius: var(--r);
  box-shadow: 0 var(--drop) 0 var(--edge);
  transition: transform .08s ease, box-shadow .08s ease;
}
.press:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 1px 0 var(--edge); }

.ico { display: inline-grid; place-items: center; }
.ico svg { width: 28px; height: 28px; }
.round {
  width: 60px; height: 60px; flex: none;
  border-radius: 50%;
  background: var(--paper);
  color: var(--text);
  display: grid; place-items: center;
  padding: 0;
}
.round.ghost { visibility: hidden; border: 0; box-shadow: none; }

.bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 66px; }
.bar-title { margin: 0; font: 800 1.45rem var(--font); text-align: center; flex: 1; min-width: 0; text-wrap: balance; }

.dots { display: flex; gap: 8px; }
.dots span { width: 20px; height: 20px; border-radius: 50%; border: 3px solid var(--edge); background: var(--paper); transition: background .25s; }
.dots span.on { background: var(--good); }

.bubble {
  margin: 0;
  background: var(--paper);
  color: var(--text);
  border: 3px solid var(--edge);
  border-radius: var(--r);
  padding: 12px 18px;
  font: 800 1.3rem/1.35 var(--font);
  text-align: center;
  min-height: 3.3em;
  display: grid; place-items: center;
  text-wrap: balance;
}

.stage { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; min-height: 220px; }
.answers { display: flex; justify-content: center; gap: 14px; flex-wrap: wrap; min-height: 92px; }
.choice {
  min-width: 88px; height: 88px; padding: 0 14px;
  background: var(--paper);
  color: var(--text);
  font: 800 2.5rem/1 var(--font);
  font-variant-numeric: tabular-nums;
}
.choice.letter { font-size: 2.8rem; min-width: 92px; }
.choice.right, .pic.right { background: var(--good); color: var(--on-good); }
.wrong { animation: shake .4s; opacity: .4; }
.hint { animation: pulse 1s ease-in-out infinite; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 64px; padding: 0 22px;
  background: var(--accent); color: var(--on-accent);
  font: 800 1.25rem var(--font);
}
.btn.quiet { background: var(--paper); color: var(--text); }
.btn > img, .btn > svg { width: 34px; height: 30px; display: block; }
.row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

/* ---------- home */
.home-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand img { width: 58px; height: 58px; }
.brand h1 { margin: 0; font: 800 1.7rem/1.05 var(--font); letter-spacing: -.01em; }
.brand p { margin: 2px 0 0; color: var(--muted); font: 700 1rem var(--font); }

.lock-wrap { position: relative; }
.lock { background: conic-gradient(var(--accent) calc(var(--p, 0) * 1turn), var(--paper) 0); }
.lock .ico { width: 42px; height: 42px; border-radius: 50%; background: var(--paper); }
.lock .ico svg { width: 22px; height: 22px; }
.lock-tip {
  position: absolute; right: 0; top: calc(100% + 10px); z-index: 5;
  width: 210px; padding: 10px 12px;
  background: var(--paper); color: var(--text);
  border: 2px solid var(--edge); border-radius: 14px;
  font: 600 .95rem/1.35 var(--font-adult);
}

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.tile {
  aspect-ratio: 1 / .9;
  min-height: 128px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 8px;
  background: var(--tile);
  color: var(--ink);
  font: 800 1.2rem/1.1 var(--font);
  text-align: center;
}
.tile-art { height: 62%; width: 100%; display: flex; align-items: center; justify-content: center; gap: 2px; }
.tile-art img { height: 100%; max-height: 82px; width: auto; }
.tile-art svg { height: 100%; max-height: 84px; width: auto; }
.tile-count { --tile: var(--t-count); }
.tile-trace { --tile: var(--t-trace); }
.tile-line { --tile: var(--t-line); }
.tile-add { --tile: var(--t-add); }
.tile-words { --tile: var(--t-words); }
.tile-stickers { --tile: var(--t-stickers); }
.tile-stories { --tile: var(--t-stories); }
.tile-watch { --tile: var(--t-watch); }
.art-count img:nth-child(2) { transform: translateY(-10px) rotate(8deg); }
.art-count img:nth-child(1) { transform: rotate(-10deg); }
.art-count img { max-height: 58px !important; }
.art-line { flex-direction: column; gap: 4px; }
.art-line img { height: 58% !important; }
.mini-stones { display: flex; gap: 5px; }
.mini-stones span { width: 28px; height: 28px; border-radius: 50%; background: var(--sheet); border: 2.5px solid var(--ink); display: grid; place-items: center; font: 800 .95rem var(--font); }
.mini-stones span.q { border-style: dashed; }
.art-add { font: 800 2.2rem var(--font); }
.art-add img { max-height: 54px !important; }
.art-words { font: 800 3.3rem/1 var(--font); gap: 6px; }
.art-words img { max-height: 50px !important; }

/* ---------- count */
.count-grid { display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); gap: 6px; width: 100%; max-width: 440px; }
.thing { position: relative; aspect-ratio: 1; padding: 6px; border: 0; background: transparent; border-radius: 16px; max-width: 120px; justify-self: center; width: 100%; }
.thing img { width: 100%; height: 100%; transform: rotate(var(--rot, 0deg)); transition: transform .15s; }
.thing.counted { background: color-mix(in srgb, var(--good) 22%, transparent); }
.thing.counted img { transform: rotate(var(--rot, 0deg)) scale(.86); }
.badge {
  position: absolute; top: -4px; right: -4px;
  min-width: 30px; height: 30px; padding: 0 6px;
  border-radius: 15px; border: 2px solid var(--edge);
  background: var(--accent); color: var(--on-accent);
  font: 800 1.05rem/26px var(--font); font-variant-numeric: tabular-nums;
  animation: pop .35s cubic-bezier(.2, 1.6, .4, 1);
}

/* ---------- trace */
.trace-wrap { position: relative; width: 100%; display: flex; justify-content: center; }
canvas.trace { background: var(--paper); border: 3px solid var(--edge); border-radius: var(--r); touch-action: none; display: block; }
.trace-wrap .round { position: absolute; right: 6px; bottom: 6px; }
.trace-word { margin: 0; font: 800 2rem var(--font); }

/* ---------- before & after */
.track { position: relative; display: flex; gap: 12px; justify-content: center; padding-top: 84px; }
.stone {
  position: relative;
  width: 92px; height: 92px; border-radius: 50%;
  background: var(--t-line); color: var(--ink);
  display: grid; place-items: center;
  font: 800 2.6rem var(--font); font-variant-numeric: tabular-nums;
}
.stone.gap { background: var(--paper); color: var(--muted); border-style: dashed; }
.stone.filled { background: var(--t-count); color: var(--ink); border-style: solid; animation: pop .45s cubic-bezier(.2, 1.6, .4, 1); }
.hop { position: absolute; left: 50%; bottom: calc(100% - 6px); width: 82px; max-width: none; transform: translateX(-50%); animation: bob 1.6s ease-in-out infinite; }
.stone.filled .hop { animation: jump .6s ease-out; }

/* ---------- add and make */
.sum { display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; }
.group { display: grid; grid-template-columns: repeat(var(--cols), var(--size, 54px)); gap: 4px; padding: 10px; background: var(--paper); }
.group img { width: 100%; }
.op { font: 800 2.8rem var(--font); }
.frame { display: grid; grid-template-columns: repeat(5, minmax(0, 56px)); gap: 6px; padding: 10px; background: var(--paper); }
.cell { aspect-ratio: 1; border: 3px dashed var(--muted); border-radius: 14px; display: grid; place-items: center; }
.cell.full { border: 3px solid var(--edge); }
.cell img { width: 86%; }
.cell.ghost img { opacity: .5; animation: pop .4s cubic-bezier(.2, 1.6, .4, 1); }
.eq { margin: 0; font: 800 2.2rem var(--font); font-variant-numeric: tabular-nums; animation: pop .4s cubic-bezier(.2, 1.6, .4, 1); }

/* ---------- sounds and words */
.pics { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.pic { width: 104px; height: 104px; padding: 10px; background: var(--paper); }
.pic img { width: 100%; height: 100%; }
.word-card { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.word-card img { width: 150px; height: 150px; }
.word { margin: 0; font: 800 3.2rem/1.1 var(--font); letter-spacing: .05em; }
.blank { display: inline-block; min-width: .8em; border-bottom: 6px solid var(--accent); color: var(--accent); text-align: center; }

/* ---------- done and stickers */
.done-body { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px; }
.sticker { aspect-ratio: 1; border-radius: 50%; background: var(--sc, var(--t-stickers)); border: 3px solid var(--edge); box-shadow: 0 4px 0 var(--edge); display: grid; place-items: center; }
.sticker img { width: 68%; }
.sticker.big { width: min(190px, 52vw); }
.pop { animation: pop .7s cubic-bezier(.2, 1.6, .4, 1); }
.sticker-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.slot { aspect-ratio: 1; border-radius: 50%; border: 3px dashed var(--line); }
.count-note { margin: 0; text-align: center; color: var(--muted); font: 800 1.1rem var(--font); }

/* ---------- stories */
.shelf { display: grid; gap: 14px; }
.story-card { display: flex; align-items: center; gap: 14px; padding: 12px; background: var(--t-stories); color: var(--ink); text-align: left; font: 800 1.3rem/1.2 var(--font); }
.cover { width: 96px; height: 96px; flex: none; border-radius: 16px; border: 3px solid var(--ink); display: grid; place-items: center; }
.cover img { width: 72%; }
.scene-land { background: linear-gradient(var(--land-sky) 0 58%, var(--land) 58%); }
.scene-sea { background: linear-gradient(var(--sea) 0 70%, var(--sea-deep) 70%); }
.story { flex: 1; display: flex; flex-direction: column; gap: 14px; }
.story-art {
  min-height: 230px; padding: 22px 14px;
  border: 3px solid var(--edge); border-radius: var(--r);
  display: flex; align-items: center; justify-content: center; gap: 22px; flex-wrap: wrap;
}
.story-art .group { background: transparent; padding: 0; gap: 6px; border: 0; box-shadow: none; }
.story-art .cover-pic { width: 150px; height: 150px; }
.story-art .group img { animation: pop .5s cubic-bezier(.2, 1.6, .4, 1) backwards; }
.story-title { margin: 0; font: 800 2rem/1.15 var(--font); text-align: center; text-wrap: balance; }
.story-text { margin: 0; padding: 16px 18px; background: var(--paper); border: 3px solid var(--edge); border-radius: var(--r); font: 700 1.45rem/1.45 var(--font); text-wrap: pretty; }
.story-nav { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.page-of { font: 800 1.1rem var(--font); color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- watch */
.empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; text-align: center; }
.empty svg { width: 150px; height: auto; }
.empty h2 { margin: 0; font: 800 1.7rem var(--font); }
.empty p { margin: 0; max-width: 30ch; color: var(--muted); font: 700 1.15rem/1.4 var(--font); }
.video-card { display: flex; align-items: center; gap: 14px; padding: 12px; background: var(--t-watch); color: var(--ink); text-align: left; font: 800 1.25rem/1.2 var(--font); }
.thumb { width: 120px; aspect-ratio: 16 / 9; flex: none; border-radius: 12px; border: 3px solid var(--ink); background: var(--screen) center / cover no-repeat; display: grid; place-items: center; color: var(--sheet); }
video { width: 100%; max-width: 100%; border-radius: var(--r); border: 3px solid var(--edge); background: var(--screen); }

/* ---------- rest */
.rest { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; text-align: center; }
.sleeper { position: relative; width: 190px; }
.sleeper img { width: 100%; animation: breathe 3.6s ease-in-out infinite; transform-origin: 50% 100%; }
.zz { position: absolute; top: -6px; right: -18px; font: 800 2rem var(--font); color: var(--accent); animation: float 3s ease-in-out infinite; }
.rest h2 { margin: 0; font: 800 2rem var(--font); }
.rest p { margin: 0; max-width: 28ch; color: var(--muted); font: 700 1.15rem/1.4 var(--font); }

/* ---------- grown-ups and gate (plain, adult text) */
.grown { font-family: var(--font-adult); -webkit-user-select: text; user-select: text; }
.grown .bar-title { font-family: var(--font-adult); font-weight: 700; }
.grown .intro { margin: 0; color: var(--muted); font-size: 1rem; line-height: 1.45; }
.p-sec { background: var(--paper); border: 1px solid var(--line); border-radius: 16px; padding: 16px; display: grid; gap: 10px; }
.p-sec h2 { margin: 0; font-size: 1.1rem; }
.p-sec p, .p-sec li { margin: 0; font-size: 1rem; line-height: 1.5; color: var(--text); max-width: 65ch; }
.p-sec .note { color: var(--muted); font-size: .95rem; }
.p-sec ul { margin: 0; padding-left: 1.2em; display: grid; gap: 4px; }
.seg { display: flex; flex-wrap: wrap; gap: 8px; }
.seg button, .p-btn {
  min-height: 48px; padding: 0 16px;
  border-radius: 12px; border: 2px solid var(--line);
  background: var(--bg); color: var(--text);
  font: 600 1rem var(--font-adult);
}
.seg button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.p-btn.danger { border-color: var(--try); color: var(--try); }
.p-btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); width: 100%; min-height: 56px; font-size: 1.1rem; }
.p-table { width: 100%; border-collapse: collapse; font-size: 1rem; }
.p-table th, .p-table td { padding: 8px 4px; border-bottom: 1px solid var(--line); text-align: left; }
.p-table td.num, .p-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.teacher { padding: 12px 14px; border-radius: 12px; background: color-mix(in srgb, var(--t-count) 55%, var(--paper)); color: var(--text); font-size: .98rem; line-height: 1.45; margin: 0; }

.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: var(--scrim);
  display: grid; place-items: center;
  padding: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) max(16px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
}
.gate {
  width: min(100%, 360px);
  background: var(--paper); color: var(--text);
  border-radius: 18px; padding: 22px;
  display: grid; gap: 12px;
  font-family: var(--font-adult);
  -webkit-user-select: text; user-select: text;
}
.gate h2 { margin: 0; font-size: 1.3rem; }
.gate-q { margin: 0; font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.gate input {
  width: 100%; min-height: 56px; padding: 0 14px;
  border-radius: 12px; border: 2px solid var(--line);
  background: var(--bg); color: var(--text);
  font: 700 1.6rem var(--font-adult);
}
.gate-msg { margin: 0; min-height: 1.4em; color: var(--try); font-size: .98rem; }
.gate .row { justify-content: flex-end; }

/* ---------- motion */
.spark { position: fixed; z-index: 60; width: 30px; pointer-events: none; animation: spark .85s ease-out forwards; }
@keyframes spark {
  from { transform: translate(-50%, -50%) scale(.3); opacity: 1; }
  to { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(1) rotate(var(--rot)); opacity: 0; }
}
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-9px); } 75% { transform: translateX(9px); } }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.08); } }
@keyframes pop { from { transform: scale(.4); } to { transform: scale(1); } }
@keyframes bob { 0%, 100% { transform: translateX(-50%) translateY(0); } 50% { transform: translateX(-50%) translateY(-7px); } }
@keyframes jump { 0% { transform: translateX(-50%) translateY(0); } 45% { transform: translateX(-50%) translateY(-34px); } 100% { transform: translateX(-50%) translateY(0); } }
@keyframes breathe { 0%, 100% { transform: scale(1, 1); } 50% { transform: scale(1.03, .97); } }
@keyframes float { 0%, 100% { transform: translateY(0); opacity: .6; } 50% { transform: translateY(-10px); opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
