:root {
  --bg: #fef9f1;
  --ink: #33415c;
  --muted: #7b8aa3;
  --card: #ffffff;
  --line: #ece4d6;
  --good: #22c55e;
  --good-bg: #dcfce7;
  --hint-bg: #fff7d6;
  --accent: #f59e0b;
  --go: #34d399;
  --c: #c7d2fe;
  --radius: 26px;
  --shadow: 0 4px 0 rgba(51, 65, 92, .10), 0 8px 24px rgba(51, 65, 92, .08);
  --emoji: clamp(44px, 11vw, 72px);
  --font: 'Nunito', ui-rounded, 'Segoe UI', system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--ink); font-family: var(--font); font-weight: 700;
  -webkit-user-select: none; user-select: none; overscroll-behavior: none;
  background-image: radial-gradient(circle at 10% 0%, #fff1d6 0, transparent 40%), radial-gradient(circle at 100% 100%, #e0f2fe 0, transparent 45%);
  background-attachment: fixed;
}
button { font: inherit; color: inherit; border: 0; cursor: pointer; touch-action: manipulation; background: none; }
button:focus-visible { outline: 4px solid #93c5fd; outline-offset: 3px; }
h1, h2 { margin: .2em 0; font-weight: 900; line-height: 1.15; }
.muted { color: var(--muted); }

.screen { max-width: 980px; margin: 0 auto; min-height: 100%; padding: max(12px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 14px; }

/* ---------- topbar ---------- */
.topbar { display: flex; align-items: center; gap: 10px; }
.top-mid { flex: 1; display: flex; align-items: center; justify-content: center; gap: 10px; min-width: 0; }
.icon-btn, .round-btn, .lvl-badge {
  width: 56px; height: 56px; border-radius: 50%; background: var(--card); box-shadow: var(--shadow); font-size: 26px;
  display: inline-grid; place-items: center; flex: none; transition: transform .12s;
}
.icon-btn:active, .round-btn:active, .opt:active, .tile:active, .age-btn:active, .big-btn:active { transform: scale(.94); }
.lvl-badge { width: 46px; height: 46px; font-size: 22px; font-weight: 900; background: var(--c); }
.pill { background: var(--card); box-shadow: var(--shadow); border-radius: 999px; padding: 10px 16px; font-size: 20px; white-space: nowrap; flex: none; }
.pill.bump { animation: bump .4s; }
.dots { display: flex; gap: 6px; }
.dots i, .lvl-dots i, .story-dots i { width: 12px; height: 12px; border-radius: 50%; background: #e5ded0; display: block; }
.dots i.on, .lvl-dots i.on, .story-dots i.on { background: var(--accent); }
.dots i.cur, .lvl-dots i.cur { background: #fff; box-shadow: inset 0 0 0 3px var(--accent); }
.game-icon, .age-chip { font-size: 30px; }

/* ---------- home ---------- */
.home-head { display: flex; justify-content: space-between; align-items: center; }
.langs { display: flex; gap: 8px; }
.lang-btn { background: var(--card); border-radius: 18px; padding: 6px 10px; box-shadow: var(--shadow); display: flex; flex-direction: column; align-items: center; opacity: .55; }
.lang-btn.on { opacity: 1; box-shadow: 0 0 0 3px var(--accent), var(--shadow); }
.lang-btn .flag { font-size: 30px; line-height: 1; }
.lang-btn small { font-size: 12px; }
.hero { text-align: center; display: flex; flex-direction: column; align-items: center; }
.hero h1 { font-size: clamp(28px, 7vw, 44px); color: #3b4a6b; }
.continue-btn {
  align-self: center; display: flex; align-items: center; gap: 14px; padding: 12px 30px; border-radius: 999px;
  background: var(--go); color: #fff; box-shadow: 0 6px 0 #059669, 0 10px 24px rgba(16, 185, 129, .3); font-size: 40px;
  animation: breathe 2.4s ease-in-out infinite;
}
.continue-btn .tile-icon { background: #fff; border-radius: 50%; width: 60px; height: 60px; display: grid; place-items: center; font-size: 36px; }
.ages { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.age-btn {
  background: var(--c); border-radius: var(--radius); padding: 18px 8px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center; gap: 4px; transition: transform .12s;
}
.age-btn.on { box-shadow: 0 0 0 4px #fff, 0 0 0 7px var(--accent), var(--shadow); }
.age-icon { font-size: clamp(48px, 13vw, 80px); line-height: 1.1; }
.age-num { font-size: clamp(20px, 5vw, 28px); font-weight: 900; }
.foot { display: flex; justify-content: center; gap: 18px; margin-top: auto; padding-top: 8px; }
.round-btn { width: 66px; height: 66px; font-size: 32px; position: relative; }
.round-btn small { position: absolute; right: -4px; top: -4px; background: var(--accent); color: #fff; font-size: 13px; border-radius: 999px; min-width: 24px; height: 24px; display: grid; place-items: center; }
.gear { opacity: .7; }
.gear.holding { animation: hold 1.2s linear forwards; }
.lang-pick { justify-content: center; }
.lang-pick .ages { grid-template-columns: repeat(2, 1fr); max-width: 520px; width: 100%; margin: 0 auto; }

/* ---------- pet ---------- */
.pet { position: relative; display: inline-block; line-height: 1; cursor: pointer; font-size: 90px; filter: drop-shadow(0 8px 6px rgba(51, 65, 92, .15)); }
.pet-l { font-size: 90px; }
.pet-xl { font-size: clamp(100px, 26vw, 140px); }
.pet-xxl { font-size: clamp(130px, 40vw, 200px); }
.pet.glow .pet-body { filter: drop-shadow(0 0 18px #fde047) drop-shadow(0 0 6px #fbbf24); }
.acc { position: absolute; font-size: .42em; }
.acc-head { top: -.22em; left: 50%; transform: translateX(-50%) rotate(-8deg); }
.acc-face { top: .3em; left: 50%; transform: translateX(-50%); font-size: .36em; }
.acc-hand { bottom: 0; right: -.25em; transform: rotate(12deg); }
.pet-stage { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 10px; padding-top: 10px; }
.grow-bar { display: flex; align-items: center; gap: 4px; font-size: 28px; }
.grow-bar span { opacity: .25; filter: grayscale(1); }
.grow-bar span.on { opacity: 1; filter: none; }
.grow-bar i { width: 14px; height: 3px; background: var(--line); }
.bar { height: 14px; background: #eee7da; border-radius: 999px; overflow: hidden; width: 100%; }
.bar.big { max-width: 360px; height: 20px; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, #fbbf24, #f59e0b); border-radius: 999px; transition: width .6s; }
.items { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 12px; }
.item { aspect-ratio: 1; background: var(--card); border-radius: 22px; box-shadow: var(--shadow); font-size: 44px; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.item.on { box-shadow: 0 0 0 4px var(--go), var(--shadow); background: #ecfdf5; }
.item.locked { background: #f3efe7; }
.item .lock { font-size: 26px; opacity: .6; }
.item small { font-size: 14px; color: var(--muted); }

/* ---------- hubs ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(46%, 200px), 1fr)); gap: 16px; }
.tile {
  position: relative; background: var(--c); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 10px 14px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; min-height: 150px; transition: transform .12s, filter .6s;
}
@media (min-width: 700px) { .tiles .tile { min-height: 200px; } .tiles { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); } }
.tile-icon { font-size: clamp(54px, 14vw, 80px); line-height: 1; }
.tile-name { font-size: 18px; font-weight: 900; text-align: center; }
.lvl-dots { display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; max-width: 160px; }
.lvl-dots i { width: 10px; height: 10px; background: rgba(255, 255, 255, .7); }
.crown { position: absolute; top: 6px; right: 10px; font-size: 28px; }
.island-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; justify-content: space-between; }
.island-head h2 { font-size: 26px; }
.clues { flex: 1; min-width: 200px; display: flex; flex-direction: column; gap: 6px; font-size: 16px; }
.chip-btn { background: var(--card); box-shadow: var(--shadow); border-radius: 999px; padding: 10px 16px; font-size: 17px; font-weight: 800; }
.island {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(min(46%, 210px), 1fr)); gap: 16px; padding: 18px;
  border-radius: 40px; background: radial-gradient(ellipse at center, #a7f3d0 0, #bae6fd 70%); box-shadow: inset 0 0 0 8px #fde68a, var(--shadow);
}
.island .tile { filter: grayscale(calc(var(--gray, 1) * .8)); }

/* ---------- game ---------- */
.game { gap: 10px; }
.game:not(.age-school) .topbar .speak { display: none; }
.prompt { text-align: center; min-height: 20px; display: flex; justify-content: center; }
.prompt h2 { font-size: clamp(22px, 5.5vw, 34px); background: var(--card); padding: 10px 22px; border-radius: 20px; box-shadow: var(--shadow); }
.speak-big { width: 84px; height: 84px; border-radius: 50%; background: var(--c); box-shadow: var(--shadow); font-size: 40px; animation: breathe 2.6s ease-in-out infinite; }
.stage { display: flex; flex-direction: column; align-items: center; gap: 16px; flex: 1; justify-content: center; }
.scene { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; max-width: 100%; text-align: center; font-size: 22px; }
.scene:empty { display: none; }
.options { display: grid; gap: 14px; width: 100%; max-width: 760px; }
.options.n2 { grid-template-columns: repeat(2, 1fr); max-width: 560px; }
.options.n3 { grid-template-columns: repeat(3, 1fr); }
.options.n4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 600px) { .options.n4 { grid-template-columns: repeat(2, 1fr); } .options.n3 { gap: 10px; } }
.opt {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); min-height: 120px; padding: 12px 8px;
  display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 4px;
  font-size: var(--emoji); font-weight: 900; line-height: 1.1; transition: transform .12s, opacity .3s, background .3s; overflow: hidden; word-break: break-word;
}
.opt .shape { max-width: 100%; height: auto; }
.age-school .opt { font-size: clamp(28px, 7vw, 46px); min-height: 100px; }
.opt.right { background: var(--good-bg); box-shadow: 0 0 0 5px var(--good), var(--shadow); animation: pop .5s; }
.opt.nope { animation: shake .45s; opacity: .45; }
.opt.pulse { animation: pulse 1s ease-in-out infinite; box-shadow: 0 0 0 5px #fbbf24, var(--shadow); }
.fb { min-height: 64px; display: flex; justify-content: center; }
.bubble { border-radius: 22px; padding: 12px 18px; display: flex; gap: 12px; align-items: center; max-width: 720px; font-size: 19px; animation: rise .3s ease-out; }
.bubble p { margin: 0; line-height: 1.35; }
.bubble.good { background: var(--good-bg); color: #166534; font-size: 24px; }
.bubble.hint { background: var(--hint-bg); box-shadow: 0 0 0 2px #fde68a; }
.hint-ico { font-size: 34px; }
.hint-scene { margin-top: 8px; font-size: 26px; }

/* scene helpers for game modules */
.row { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 6px 10px; font-size: var(--emoji); line-height: 1.15; }
.big { font-size: clamp(70px, 20vw, 120px); line-height: 1.1; }
.mid { font-size: clamp(24px, 6vw, 34px); }
.box { background: #fff; border-radius: 18px; box-shadow: var(--shadow); padding: 10px 14px; display: inline-block; }
.q { display: inline-grid; place-items: center; min-width: 1.2em; min-height: 1.2em; border-radius: 16px; border: 4px dashed #f59e0b; color: #f59e0b; background: #fffbeb; font-weight: 900; }
.q::before { content: '?'; font-size: .7em; }
.q:not(:empty)::before { content: none; }
.grid-dots { display: inline-flex; flex-wrap: wrap; gap: 4px; max-width: 70px; justify-content: center; }
.grid-dots i, .grid-dots span { width: 12px; height: 12px; border-radius: 50%; background: var(--accent); display: block; }
.numline { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; font-size: 18px; }
.numline span { min-width: 34px; height: 34px; border-radius: 10px; background: #f1ece2; display: grid; place-items: center; padding: 0 4px; }
.numline span.hl { background: #fbbf24; color: #fff; font-weight: 900; transform: scale(1.08); }

/* memory */
.memory { display: grid; grid-template-columns: repeat(var(--cols), 1fr); gap: 10px; width: 100%; max-width: 680px; }
.card { aspect-ratio: 3/4; perspective: 600px; position: relative; border-radius: 18px; }
.card span { position: absolute; inset: 0; border-radius: 18px; display: grid; place-items: center; backface-visibility: hidden; transition: transform .35s; box-shadow: var(--shadow); }
.card .back { background: linear-gradient(135deg, #c4b5fd, #93c5fd); color: #fff; font-size: clamp(28px, 7vw, 44px); font-weight: 900; }
.card .front { background: #fff; transform: rotateY(180deg); font-size: clamp(32px, 9vw, 60px); }
.card.up .back { transform: rotateY(180deg); }
.card.up .front { transform: rotateY(360deg); }
.card.done .front { background: var(--good-bg); box-shadow: 0 0 0 4px var(--good); animation: pop .5s; }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(40, 50, 70, .45); display: grid; place-items: center; padding: 16px; z-index: 50; animation: fade .2s; }
.sheet { background: var(--bg); border-radius: 32px; padding: 24px 20px; width: min(560px, 100%); max-height: calc(100% - 20px); overflow: auto; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); animation: rise .3s ease-out; }
.center { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.center h2 { font-size: 28px; }
.lead { font-size: 22px; margin: 0; }
.row-btns { display: flex; gap: 14px; justify-content: center; align-items: center; margin-top: 10px; flex-wrap: wrap; }
.big-btn { min-width: 96px; height: 76px; border-radius: 999px; background: var(--card); box-shadow: var(--shadow); font-size: 36px; padding: 0 24px; }
.big-btn.go { background: var(--go); color: #fff; box-shadow: 0 6px 0 #059669, 0 10px 24px rgba(16, 185, 129, .3); }
.rating { font-size: 56px; display: flex; gap: 6px; }
.rating span { filter: grayscale(1) opacity(.3); transform: scale(.6); animation: starIn .5s forwards; }
.rating span.on { filter: none; }
.plus { font-size: 26px; color: var(--accent); margin: 0; }
.beat { background: #fff; border-radius: 20px; padding: 12px 16px; box-shadow: var(--shadow); font-size: 18px; }
.beat p { margin: 6px 0 0; }
.clue-line { color: var(--muted); }
.reward-big { font-size: 110px; line-height: 1.1; }
.level-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 10px; width: 100%; }
.lvl-pick { height: 64px; border-radius: 18px; background: var(--card); box-shadow: var(--shadow); font-size: 26px; font-weight: 900; }
.lvl-pick.done { background: #fef3c7; }
.lvl-pick.on { box-shadow: 0 0 0 4px var(--accent), var(--shadow); }
.lvl-pick:disabled { opacity: .45; cursor: default; }

/* story */
.story { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.story-art { font-size: clamp(70px, 20vw, 110px); line-height: 1.1; animation: bounce 2.5s ease-in-out infinite; }
.story-text { font-size: 21px; line-height: 1.45; margin: 0; }
.story-dots { display: flex; gap: 6px; }

/* badges */
.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 14px; }
.badge { background: #f3efe7; border-radius: 24px; padding: 14px 8px; display: flex; flex-direction: column; align-items: center; gap: 6px; min-height: 130px; justify-content: center; }
.badge.on { background: var(--card); box-shadow: var(--shadow); }
.b-ico { font-size: 52px; }
.badge:not(.on) .b-ico { opacity: .35; }
.b-name { font-size: 15px; text-align: center; }

/* settings */
.settings { display: flex; flex-direction: column; gap: 12px; font-weight: 600; }
.set-row { display: flex; justify-content: space-between; align-items: center; background: #fff; border-radius: 16px; padding: 12px 16px; font-size: 18px; }
.set-row input { width: 26px; height: 26px; accent-color: var(--go); }
.stats { background: #fff; border-radius: 16px; padding: 10px 16px; font-size: 15px; display: grid; gap: 4px; }
.stats div { display: flex; justify-content: space-between; }
.note { font-size: 14px; color: var(--muted); margin: 0; line-height: 1.4; }
.text-btn { background: #fff; border-radius: 999px; padding: 12px 20px; font-size: 16px; font-weight: 800; box-shadow: var(--shadow); }
.text-btn.danger { color: #b91c1c; }

/* parent gate + captions */
.gate-q { font-size: 40px; font-weight: 900; margin: 4px 0 8px; }
.level-grid.gate { grid-template-columns: repeat(2, 1fr); max-width: 320px; margin-bottom: 8px; }
.caption {
  position: fixed; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translate(-50%, 140%);
  width: min(640px, calc(100% - 32px)); background: #33415c; color: #fff; border-radius: 20px; padding: 12px 18px;
  display: flex; gap: 10px; align-items: center; font-size: 19px; line-height: 1.35; z-index: 120;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .25); transition: transform .3s ease-out; pointer-events: none;
}
.caption.show { transform: translate(-50%, 0); pointer-events: auto; }
.cap-ico { font-size: 26px; }

/* effects */
.confetti { position: fixed; width: 10px; height: 14px; border-radius: 3px; z-index: 99; pointer-events: none; animation: confetti 1s ease-out forwards; }
.fly-star { position: fixed; z-index: 98; font-size: 40px; pointer-events: none; transition: left .6s cubic-bezier(.5, -.3, .6, 1), top .6s cubic-bezier(.5, -.3, .6, 1), transform .6s; translate: -50% -50%; }
.bounce { animation: bounce 2s ease-in-out infinite; }
.wiggle { animation: wiggle .6s; }
.badge-pop { animation: popIn .6s cubic-bezier(.3, 1.6, .5, 1); }

@keyframes pop { 50% { transform: scale(1.08); } }
@keyframes popIn { from { transform: scale(0) rotate(-30deg); } to { transform: scale(1); } }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
@keyframes pulse { 50% { transform: scale(1.06); } }
@keyframes breathe { 50% { transform: scale(1.05); } }
@keyframes bump { 50% { transform: scale(1.25); } }
@keyframes bounce { 50% { transform: translateY(-10px); } }
@keyframes wiggle { 25% { transform: rotate(-12deg); } 75% { transform: rotate(12deg); } }
@keyframes rise { from { transform: translateY(14px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
@keyframes starIn { to { transform: scale(1); } }
@keyframes confetti { to { transform: translate(var(--dx), var(--dy)) rotate(540deg); opacity: 0; } }
@keyframes hold { to { box-shadow: 0 0 0 8px var(--accent), var(--shadow); opacity: 1; transform: rotate(180deg); } }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; } }

/* voice settings */
.voice-box { background: #fff; border-radius: 16px; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.voice-box h3 { margin: 0; font-size: 18px; }
.set-row.radio { justify-content: flex-start; gap: 12px; background: #faf7f1; padding: 10px 12px; cursor: pointer; }
.set-row.radio input { flex: none; }
.set-row.radio span { display: flex; flex-direction: column; }
.set-row.radio small { font-size: 13px; color: var(--muted); font-weight: 600; }
.voice-pick { display: flex; gap: 8px; flex-wrap: wrap; }
.voice-pick .chip-btn.on { box-shadow: 0 0 0 3px var(--accent), var(--shadow); }
.dl-status { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.text-btn.go { background: var(--go); color: #fff; }
.text-btn:disabled { opacity: .6; }
