/* Smart Worksheet — childplay's colours on a light, airy page. */

:root {
  --teal: #27847B; --teal-hi: #2E9A8F; --teal-lo: #1E6B63;
  --navy: #243447; --coral: #E9785E; --sun: #F6C344; --sky: #7CCBDD;
  --cream: #FFF8EE; --paper: #FFFFFF; --muted: #6A7686; --line: #EDE6DA;
  --teal-soft: #E3F3F1; --coral-soft: #FDEBE6; --sun-soft: #FEF4D8; --sky-soft: #E4F4F8;
  --radius: 26px;
  --shadow: 0 6px 20px rgba(36, 52, 71, .08), 0 1px 3px rgba(36, 52, 71, .06);
  --head: Fredoka, Nunito, system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; touch-action: manipulation; }
body {
  margin: 0; min-height: 100dvh; color: var(--navy);
  font-family: Nunito, system-ui, -apple-system, sans-serif;
  background:
    radial-gradient(420px 320px at 0% 0%, var(--teal-soft), transparent 70%),
    radial-gradient(380px 300px at 100% 12%, var(--sun-soft), transparent 70%),
    radial-gradient(460px 360px at 50% 110%, var(--coral-soft), transparent 70%),
    var(--cream);
  background-attachment: fixed;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
button:focus-visible, a:focus-visible { outline: 3px solid var(--sun); outline-offset: 2px; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, .btn, .chip, .choice b, .number, .question { font-family: var(--head); }

main { max-width: 980px; margin: 0 auto; padding: max(12px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom)); }
.loading { text-align: center; padding-top: 38vh; margin: 0; }
.loading img { animation: bob 1.6s ease-in-out infinite; }
.fatal { text-align: center; padding: 40vh 24px 0; }
.grow { flex: 1; }
.note { color: var(--muted); font-size: 14px; }
@keyframes bob { 50% { transform: translateY(-6px); } }

/* ── Buttons ──────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 999px; padding: 12px 22px; font-size: 18px; font-weight: 600;
  background: var(--teal); color: #fff; box-shadow: 0 4px 0 var(--teal-lo);
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--teal-lo); }
.btn.ghost { background: var(--paper); color: var(--navy); box-shadow: 0 4px 0 var(--line); border: 2px solid var(--line); }
.btn.big { font-size: 24px; padding: 16px 34px; }
.chip { border: 2px solid var(--line); border-radius: 999px; padding: 8px 16px; background: var(--paper); font-weight: 600; font-size: 15px; }
.chip.on { border-color: var(--teal); background: var(--teal-soft); color: var(--teal-lo); }
.pill { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; padding: 8px 14px; border-radius: 999px; background: var(--paper); box-shadow: var(--shadow); font-weight: 900; }
.round {
  display: inline-grid; place-items: center; width: 46px; height: 46px; border-radius: 50%; border: 0;
  background: var(--paper); box-shadow: var(--shadow); font-size: 22px; font-weight: 900; overflow: hidden;
}
.round img { width: 100%; height: 100%; object-fit: cover; }
.row { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin: 16px 0; }

/* ── Top bar ──────────────────────────────────────────────────────────── */
.top { display: flex; align-items: center; gap: 10px; padding: 4px 0 8px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand img { width: 46px; height: 46px; }
.brand span { display: grid; line-height: 1.05; }
.brand b { font-family: var(--head); font-size: 22px; font-weight: 700; }
.brand small { color: var(--coral); font-weight: 800; font-size: 13px; }

/* ── Home ─────────────────────────────────────────────────────────────── */
.hero h1 { margin: 14px 0 4px; font-size: clamp(26px, 5vw, 38px); font-weight: 700; }
.hero p { margin: 0 0 18px; color: var(--muted); font-weight: 700; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(156px, 1fr)); gap: 14px; }
.card {
  display: grid; gap: 4px; padding: 16px 14px 14px; border-radius: var(--radius);
  background: var(--paper); box-shadow: var(--shadow); border: 3px solid transparent;
  transition: transform .15s;
}
.card:active { transform: scale(.97); }
.card-art { display: grid; place-items: center; height: 92px; border-radius: 20px; font-size: 56px; margin-bottom: 6px; background: var(--tint-soft); }
.card b { font-family: var(--head); font-size: 19px; font-weight: 600; }
.card small { color: var(--muted); font-weight: 700; font-size: 13px; line-height: 1.3; }
.card-stars { margin-top: 4px; letter-spacing: 2px; color: var(--line); font-size: 18px; }
.card-stars .on { color: var(--sun); }
.tint-teal { --tint: var(--teal); --tint-soft: var(--teal-soft); }
.tint-coral { --tint: var(--coral); --tint-soft: var(--coral-soft); }
.tint-sun { --tint: #D9A21B; --tint-soft: var(--sun-soft); }
.tint-sky { --tint: #3E9DB4; --tint-soft: var(--sky-soft); }
.card:hover { border-color: var(--tint-soft); }
.foot { text-align: center; margin-top: 30px; color: var(--muted); font-size: 12px; font-weight: 700; }
.foot img { width: min(240px, 60vw); display: block; margin: 0 auto 6px; }

/* ── Worksheet ────────────────────────────────────────────────────────── */
.sheet-head { display: flex; align-items: center; gap: 14px; margin: 6px 0 14px; padding: 12px 16px; border-radius: var(--radius); background: var(--tint-soft); }
.sheet-emoji { font-size: 44px; }
.sheet-head h1 { margin: 0; font-size: clamp(22px, 4.5vw, 30px); font-weight: 700; color: var(--tint); }
.sheet-head p { margin: 2px 0 0; font-weight: 800; }
.play { min-height: 50vh; }
.emoji { font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif; line-height: 1; }
.question { text-align: center; font-size: clamp(20px, 4vw, 28px); font-weight: 600; margin: 6px 0 14px; }
.caption { text-align: center; font-family: var(--head); font-size: 24px; font-weight: 600; min-height: 32px; margin: 8px 0; }

/* Drag and drop */
.drag { touch-action: none; user-select: none; -webkit-user-select: none; cursor: grab; }
.dragging { z-index: 50; cursor: grabbing; position: relative; box-shadow: 0 16px 30px rgba(36, 52, 71, .25); }
.homing { transition: transform .28s cubic-bezier(.3, 1.4, .6, 1); }
.board { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; }
.tray { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; margin-top: 18px; padding: 14px; min-height: 120px; border-radius: var(--radius); background: rgba(255,255,255,.7); border: 3px dashed var(--line); }
.slot {
  display: grid; place-items: center; gap: 4px; padding: 12px 8px; min-height: 150px;
  border-radius: var(--radius); background: var(--paper); box-shadow: var(--shadow);
  border: 3px dashed var(--line); transition: border-color .15s, background .15s, transform .15s;
}
.slot small { font-family: var(--head); font-size: 17px; font-weight: 600; color: var(--muted); }
.slot.over { border-color: var(--tint); background: var(--tint-soft); transform: scale(1.03); }
.slot.filled { border-style: solid; border-color: var(--tint-soft); }
.slot.nope { animation: nope .35s; }
@keyframes nope { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.slot > .emoji { font-size: 64px; }
.silhouette { filter: brightness(0); opacity: .22; }
.plate { font-size: 44px; opacity: .5; }
.piece {
  display: grid; place-items: center; width: 96px; height: 96px; border-radius: 24px;
  background: var(--paper); box-shadow: var(--shadow); border: 3px solid var(--tint-soft);
}
.piece .emoji { font-size: 58px; pointer-events: none; }
.piece.small { width: 76px; height: 76px; }
.piece.small .emoji { font-size: 44px; }
.piece.placed { box-shadow: none; border-color: transparent; background: transparent; animation: pop .35s; }
@keyframes pop { 50% { transform: scale(1.18); } }

/* Baskets */
.baskets { grid-template-columns: repeat(3, 1fr); }
.basket { align-content: start; min-height: 190px; }
.basket b { font-family: var(--head); font-size: 18px; font-weight: 600; }
.basket-in { display: flex; flex-wrap: wrap; justify-content: center; gap: 2px; }
.basket-in .piece { width: 54px; height: 54px; }
.basket-in .piece .emoji { font-size: 36px; }

/* Puzzle */
.levels { display: flex; justify-content: center; gap: 8px; margin-bottom: 12px; }
.puzzle {
  --size: min(88vw, 420px);
  display: grid; grid-template-columns: repeat(var(--n), 1fr); width: var(--size); height: var(--size);
  margin: 0 auto; border-radius: 18px; overflow: hidden; box-shadow: var(--shadow); position: relative;
  background: var(--paper);
}
.puzzle::before { content: ''; position: absolute; inset: 0; background: var(--guide) center / cover; opacity: .18; pointer-events: none; }
.cell { min-height: 0; padding: 0; border-radius: 0; border: 1px dashed rgba(36,52,71,.15); box-shadow: none; background: transparent; }
.cell.over { transform: none; }
.cell .piece { width: 100%; height: 100%; border-radius: 0; border: 0; }
.puzzle.complete .cell { border-color: transparent; }
.puzzle.complete { animation: pop .5s; }
.tray.tiles { gap: 8px; }
.tray.tiles .piece { width: calc(min(88vw, 420px) / var(--n) * .62); height: calc(min(88vw, 420px) / var(--n) * .62); border-radius: 10px; border: 0; }

/* Sounds, counting */
.start { text-align: center; padding: 40px 0; font-weight: 800; font-size: 18px; }
.progress-dots { display: flex; justify-content: center; gap: 8px; margin: 0 0 12px; }
.progress-dots i { width: 14px; height: 14px; border-radius: 50%; background: var(--line); }
.progress-dots i.on { background: var(--tint); }
.progress-dots i.now { background: var(--sun); transform: scale(1.25); }
.listen {
  display: grid; place-items: center; width: 140px; height: 140px; margin: 0 auto 20px; border-radius: 50%; border: 0;
  background: var(--sun); font-size: 56px; box-shadow: 0 8px 0 #D9A21B; animation: breathe 2s ease-in-out infinite;
}
.listen small { font-size: 13px; font-weight: 900; margin-top: -18px; }
.listen:active { transform: translateY(4px); box-shadow: 0 3px 0 #D9A21B; }
@keyframes breathe { 50% { transform: scale(1.05); } }
.choices { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.choice { display: grid; place-items: center; gap: 6px; padding: 18px 8px; border: 3px solid var(--line); border-radius: var(--radius); background: var(--paper); box-shadow: var(--shadow); }
.choice .emoji { font-size: clamp(48px, 12vw, 72px); }
.choice b { font-size: 18px; font-weight: 600; }
.choice.right, .number.right { border-color: var(--teal); background: var(--teal-soft); animation: pop .4s; }
.choice.wrong, .number.wrong { opacity: .45; animation: nope .35s; }
.count-box { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; max-width: 520px; margin: 0 auto 18px; padding: 18px; border-radius: var(--radius); background: var(--paper); box-shadow: var(--shadow); }
.count-box .emoji { font-size: clamp(40px, 10vw, 58px); }
.numbers { display: flex; justify-content: center; gap: 14px; }
.number { width: 92px; height: 92px; border-radius: 26px; border: 3px solid var(--line); background: var(--paper); font-size: 42px; font-weight: 700; box-shadow: var(--shadow); }

/* Memory */
.memory { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; max-width: 560px; margin: 0 auto; }
.memo { position: relative; aspect-ratio: 3 / 4; border: 0; padding: 0; background: none; perspective: 600px; }
.memo span { position: absolute; inset: 0; display: grid; place-items: center; border-radius: 18px; backface-visibility: hidden; transition: transform .35s; box-shadow: var(--shadow); }
.memo .back { background: var(--tint); color: #fff; font-size: 30px; }
.memo .front { background: var(--paper); font-size: clamp(36px, 9vw, 54px); transform: rotateY(180deg); }
.memo.flip .back { transform: rotateY(180deg); }
.memo.flip .front { transform: rotateY(0); }
.memo.match .front { background: var(--teal-soft); }

/* Drawing */
.stage { position: relative; width: min(100%, 560px); aspect-ratio: 1; margin: 0 auto; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.paint { touch-action: none; cursor: crosshair; }
.swatches { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 14px 0 8px; }
.swatch { width: 40px; height: 40px; border-radius: 50%; border: 3px solid #fff; background: var(--c); box-shadow: 0 0 0 2px var(--line); }
.swatch.on { box-shadow: 0 0 0 3px var(--navy); transform: scale(1.12); }
.swatch.erase { background: var(--paper); font-size: 20px; }
.sizes { display: flex; justify-content: center; gap: 8px; }

/* Done */
.done { position: relative; text-align: center; padding: 30px 12px; overflow: hidden; }
.done h2 { font-size: 32px; margin: 10px 0 4px; }
.done p { font-weight: 800; color: var(--muted); }
.done-stars { font-size: 72px; letter-spacing: 6px; color: var(--line); }
.done-stars .on { color: var(--sun); display: inline-block; animation: starpop .5s backwards; animation-delay: calc(var(--n) * .22s); }
@keyframes starpop { from { transform: scale(0) rotate(-40deg); } 70% { transform: scale(1.3); } }
.confetti i { position: absolute; top: -12px; left: calc(var(--i) * 4.2%); width: 10px; height: 14px; border-radius: 3px; background: var(--coral); animation: fall 2.4s ease-in calc(var(--i) * .07s) forwards; }
.confetti i:nth-child(3n) { background: var(--sun); }
.confetti i:nth-child(3n+1) { background: var(--sky); }
.confetti i:nth-child(4n) { background: var(--teal); }
@keyframes fall { to { transform: translateY(460px) rotate(540deg); opacity: 0; } }

.legal-links { text-align: center; font-size: 13px; font-weight: 800; color: var(--muted); padding: 4px 16px max(18px, env(safe-area-inset-bottom)); }
.legal-links a { color: var(--teal-lo); text-decoration: underline; }
.btn.danger { background: var(--coral); box-shadow: 0 4px 0 #C25A44; }
.link-btn { border: 0; background: none; color: var(--muted); text-decoration: underline; font-weight: 800; font-size: 14px; padding: 6px; }
.note a { color: var(--teal-lo); text-decoration: underline; }

/* Dialog */
dialog.sheet { border: 0; border-radius: 28px; padding: 0; width: min(92vw, 420px); box-shadow: 0 20px 60px rgba(36,52,71,.25); color: var(--navy); }
dialog.sheet::backdrop { background: rgba(36, 52, 71, .35); }
.sheet-body { display: grid; gap: 10px; justify-items: center; text-align: center; padding: 26px 22px 20px; }
.sheet-body h2 { margin: 0; font-size: 24px; }
.sheet-body p { margin: 0; line-height: 1.45; }
.big-emoji { font-size: 52px; }
.gsi { min-height: 44px; display: grid; justify-items: center; gap: 6px; }

/* Bigger screens: iPads and laptops get roomier pieces. */
@media (min-width: 760px) {
  .piece { width: 116px; height: 116px; }
  .piece .emoji { font-size: 70px; }
  .slot { min-height: 180px; }
  .slot > .emoji { font-size: 80px; }
  .puzzle { --size: min(60vw, 480px); }
  .tray.tiles .piece { width: calc(min(60vw, 480px) / var(--n) * .62); height: calc(min(60vw, 480px) / var(--n) * .62); }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
