:root {
  --bg: #fdf6e9;
  --bg2: #f6e7cc;
  --card: #ffffff;
  --ink: #1d1b3a;
  --muted: #6b6785;
  --line: #e6d8bd;
  --accent: #3a86ff;
  --accent-soft: #cfe0ff;
  --good: #1fa463;
  --bad: #e63946;
  --gold: #f4b400;
  --radius: 20px;
  --shadow: 0 4px 0 rgba(29, 27, 58, 0.15), 0 10px 24px rgba(29, 27, 58, 0.08);
  font-family: "Baloo 2", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background:
    radial-gradient(circle at 15% 10%, rgba(255, 255, 255, 0.7) 0 18%, transparent 19%),
    radial-gradient(circle at 85% 0%, rgba(255, 210, 160, 0.35) 0 22%, transparent 23%),
    linear-gradient(var(--bg), var(--bg2));
  background-attachment: fixed;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
input, select { font: inherit; }
h1, h2, h3 { margin: 0 0 8px; line-height: 1.1; }
h1 { font-size: clamp(30px, 6vw, 48px); font-weight: 800; }
h2 { font-size: clamp(24px, 4.5vw, 34px); font-weight: 800; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

#app { max-width: 1040px; margin: 0 auto; padding: 16px 16px 48px; }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
.topbar .spacer { flex: 1; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; background: var(--card); border: 2px solid var(--line);
  border-radius: 999px; padding: 4px 14px 4px 6px; font-weight: 700; box-shadow: var(--shadow); text-decoration: none; color: var(--ink);
}
.chip .av { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font-size: 22px; }
.icon-btn {
  min-width: 48px; height: 48px; border-radius: 16px; border: 2px solid var(--line); background: var(--card);
  font-size: 22px; box-shadow: var(--shadow); display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 0 12px; font-weight: 700; text-decoration: none; color: var(--ink);
}
.icon-btn:active, .btn:active, .choice:active { transform: translateY(2px); box-shadow: none; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: none; border-radius: 16px;
  padding: 12px 22px; font-size: 20px; font-weight: 800; background: var(--accent); color: #fff;
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.22); text-decoration: none; min-height: 52px;
}
.btn.secondary { background: var(--card); color: var(--ink); border: 2px solid var(--line); box-shadow: var(--shadow); }
.btn.good { background: var(--good); }
.btn.danger { background: var(--bad); }
.btn.small { font-size: 16px; padding: 8px 14px; min-height: 40px; }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.center { text-align: center; }
.stack > * + * { margin-top: 12px; }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; border: 2px solid var(--line); }

/* ---------- welcome / forms ---------- */
.hero { text-align: center; padding: 24px 0 8px; }
.hero .logo { font-size: 84px; line-height: 1; animation: bob 2.6s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-8px) rotate(-4deg); } }
.auth { max-width: 440px; margin: 16px auto; }
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-weight: 700; margin-bottom: 4px; }
.field input, .field select {
  width: 100%; padding: 12px 14px; border-radius: 14px; border: 2px solid var(--line); background: #fffdf8; font-size: 18px; color: var(--ink);
}
.field input:focus, .field select:focus { outline: 3px solid var(--accent-soft); border-color: var(--accent); }
.error { color: var(--bad); font-weight: 700; min-height: 1.2em; }
.tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.tabs button { flex: 1; border: 2px solid var(--line); border-radius: 14px; background: #fffdf8; padding: 10px; font-weight: 800; }
.tabs button.on { background: var(--ink); color: #fff; border-color: var(--ink); }

/* ---------- profile picker ---------- */
.ninjas { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 16px; margin-top: 16px; }
.ninja-card {
  background: var(--card); border: 3px solid var(--line); border-radius: 24px; padding: 18px 10px; text-align: center;
  box-shadow: var(--shadow); font-weight: 800; font-size: 20px;
}
.ninja-card .big-av { width: 96px; height: 96px; border-radius: 50%; margin: 0 auto 8px; display: grid; place-items: center; font-size: 58px; border: 4px solid var(--ink); }
.ninja-card .belt-line { font-size: 14px; color: var(--muted); font-weight: 700; }
.ninja-card.add { border-style: dashed; color: var(--muted); }
.picker { display: flex; flex-wrap: wrap; gap: 8px; }
.picker button { width: 54px; height: 54px; border-radius: 14px; border: 3px solid var(--line); background: #fffdf8; font-size: 30px; }
.picker button.on { border-color: var(--ink); background: var(--accent-soft); }
.picker.colors button { width: 44px; height: 44px; border-radius: 50%; }

/* ---------- hub ---------- */
.dojos { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 18px; }
.dojo-card {
  position: relative; border-radius: 26px; padding: 20px; color: #fff; text-decoration: none; min-height: 190px;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.2), 0 14px 30px rgba(0, 0, 0, 0.12); display: flex; flex-direction: column; overflow: hidden;
}
.dojo-card::after { content: ""; position: absolute; right: -30px; bottom: -30px; width: 140px; height: 140px; border-radius: 50%; background: rgba(255, 255, 255, 0.14); }
.dojo-card .d-icon { font-size: 48px; line-height: 1; }
.dojo-card h3 { font-size: 26px; margin: 8px 0 2px; }
.dojo-card .sub { opacity: 0.9; font-weight: 600; font-size: 15px; }
.dojo-card .meta { margin-top: auto; display: flex; gap: 8px; align-items: center; font-weight: 700; font-size: 15px; padding-top: 10px; z-index: 1; }
.dojo-card.locked { background: #bdb6a6 !important; filter: grayscale(0.4); }
.dojo-card.locked .soon { position: absolute; top: 14px; right: 14px; background: rgba(0, 0, 0, 0.3); border-radius: 999px; padding: 2px 10px; font-size: 13px; font-weight: 800; }
.belt { display: inline-block; width: 34px; height: 12px; border-radius: 4px; border: 2px solid rgba(0, 0, 0, 0.35); vertical-align: middle; }
.belt-tag { display: inline-flex; align-items: center; gap: 6px; background: rgba(0, 0, 0, 0.18); border-radius: 999px; padding: 2px 10px 2px 6px; }

.welcome-band { display: flex; gap: 16px; align-items: center; margin-bottom: 20px; flex-wrap: wrap; }
.welcome-band .big-av { width: 72px; height: 72px; border-radius: 50%; display: grid; place-items: center; font-size: 44px; border: 4px solid var(--ink); }
.stat-pills { display: flex; gap: 8px; flex-wrap: wrap; }
.pill { background: var(--card); border: 2px solid var(--line); border-radius: 999px; padding: 4px 12px; font-weight: 800; }

/* ---------- dojo / game list ---------- */
.games { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.game-card { background: var(--card); border: 3px solid var(--line); border-radius: 22px; padding: 16px; text-decoration: none; color: var(--ink); box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 4px; }
.game-card .g-icon { font-size: 40px; }
.game-card h3 { font-size: 22px; margin: 0; }
.game-card .stars-total { margin-top: auto; font-weight: 800; color: var(--gold); }
.kind-tag { display: inline-block; font-size: 12px; font-weight: 800; background: var(--bg2); border-radius: 999px; padding: 0 8px; color: var(--muted); }

.levels { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.level-btn { background: var(--card); border: 3px solid var(--line); border-radius: 20px; padding: 14px 10px; text-align: center; box-shadow: var(--shadow); }
.level-btn .belt { width: 64px; height: 16px; display: block; margin: 0 auto 6px; }
.level-btn .lv-name { font-weight: 800; font-size: 18px; }
.level-btn .lv-skill { font-size: 13px; color: var(--muted); line-height: 1.2; min-height: 2.4em; }
.level-btn .lv-stars { font-size: 20px; letter-spacing: 2px; }
.level-btn.locked { opacity: 0.5; }
.level-btn.suggested { border-color: var(--accent); }
.arenas { display: flex; gap: 10px; flex-wrap: wrap; margin: 10px 0 18px; }
.arena-btn { border: 3px solid var(--line); background: var(--card); border-radius: 16px; padding: 8px 16px; font-weight: 800; }
.arena-btn.on { border-color: var(--ink); background: var(--accent-soft); }

/* ---------- play ---------- */
.play-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.progress { flex: 1; height: 18px; background: var(--card); border: 2px solid var(--line); border-radius: 999px; overflow: hidden; }
.progress > div { height: 100%; background: linear-gradient(90deg, var(--accent), #7ab0ff); transition: width 0.3s; }
.qcard { background: var(--card); border: 3px solid var(--line); border-radius: 28px; box-shadow: var(--shadow); padding: 20px 16px; text-align: center; position: relative; }
.qtext { font-size: clamp(22px, 4.6vw, 34px); font-weight: 800; line-height: 1.2; margin: 6px 40px 12px; }
.qtext sup { font-size: 0.6em; }
.say-btn { position: absolute; top: 12px; right: 12px; width: 46px; height: 46px; border-radius: 50%; border: 2px solid var(--line); background: #fffdf8; font-size: 22px; }
.visual { margin: 6px 0 14px; display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; align-items: center; }
.visual svg { max-width: 100%; height: auto; }
.emoji-group { font-size: 38px; line-height: 1.2; }
.emoji-group span { display: inline-block; margin: 2px; }
.big-text { font-size: 54px; line-height: 1; }
.sentence { font-size: 22px; background: var(--bg); border-radius: 14px; padding: 10px 16px; max-width: 560px; }
.emoji-choice { font-size: 40px; line-height: 1; }
.len-bar { height: 22px; border-radius: 11px; margin: 10px auto; border: 2px solid var(--ink); }
.train { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.train .car { min-width: 54px; padding: 6px 10px; border-radius: 10px; background: var(--accent-soft); border: 3px solid var(--ink); font-weight: 800; font-size: 22px; }
.train .car.q { background: #fff3c4; }
table.io { border-collapse: collapse; font-size: 22px; font-weight: 800; }
table.io th, table.io td { border: 3px solid var(--ink); padding: 4px 18px; }
table.io th { background: var(--accent-soft); }
.base-ten { display: flex; flex-wrap: wrap; gap: 6px; align-items: flex-end; justify-content: center; max-width: 520px; }
.base-ten .flat { width: 60px; height: 60px; background: repeating-linear-gradient(0deg, #ffd166 0 5px, #e0b040 5px 6px), #ffd166; border: 2px solid var(--ink); }
.base-ten .rod { width: 10px; height: 60px; background: repeating-linear-gradient(0deg, #06d6a0 0 5px, #059c74 5px 6px); border: 2px solid var(--ink); }
.base-ten .unit { width: 10px; height: 10px; background: #ef476f; border: 2px solid var(--ink); }

.choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 14px; }
.choices.wide { grid-template-columns: 1fr; }
.choice {
  min-height: 70px; border-radius: 20px; border: 3px solid var(--line); background: #fffdf8; font-size: clamp(20px, 4vw, 28px); font-weight: 800;
  box-shadow: 0 5px 0 var(--line); padding: 8px 10px; display: flex; align-items: center; justify-content: center; gap: 6px;
}
.choice.right { background: #c8f5dc; border-color: var(--good); box-shadow: 0 5px 0 var(--good); }
.choice.wrong { background: #ffd6d9; border-color: var(--bad); box-shadow: 0 5px 0 var(--bad); animation: shake 0.35s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

.feedback { margin-top: 14px; font-size: 22px; font-weight: 800; min-height: 1.4em; }
.feedback.good { color: var(--good); }
.feedback.bad { color: var(--bad); }
.explain { background: #fff3c4; border-radius: 14px; padding: 10px 14px; margin-top: 10px; font-weight: 600; }

/* keypad */
.answer-box { font-size: 40px; font-weight: 800; min-height: 64px; min-width: 180px; display: inline-block; padding: 4px 18px; border-radius: 16px; border: 3px solid var(--ink); background: #fffdf8; margin: 4px auto 12px; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; max-width: 340px; margin: 0 auto; }
.keypad button { height: 62px; border-radius: 16px; border: 3px solid var(--line); background: #fffdf8; font-size: 28px; font-weight: 800; box-shadow: 0 4px 0 var(--line); }
.keypad button.go { background: var(--good); color: #fff; border-color: var(--good); box-shadow: 0 4px 0 #157a49; }

/* tiles */
.slots { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; min-height: 70px; padding: 10px; border-radius: 18px; background: var(--bg); border: 3px dashed var(--line); margin-bottom: 14px; }
.tile-pool { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.tile { min-width: 56px; height: 56px; padding: 0 12px; border-radius: 14px; border: 3px solid var(--ink); background: #ffe8a3; font-size: 28px; font-weight: 800; box-shadow: 0 4px 0 var(--ink); }
.tile.word { font-size: 22px; background: #d9ecff; }
.tile.used { visibility: hidden; }

/* clock set */
.clock-set { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.steppers { display: flex; gap: 22px; flex-wrap: wrap; justify-content: center; }
.stepper { display: flex; align-items: center; gap: 8px; font-weight: 800; }
.stepper button { width: 56px; height: 56px; border-radius: 50%; border: 3px solid var(--ink); background: #fffdf8; font-size: 28px; font-weight: 800; }
.digital { font-size: 32px; font-weight: 800; background: var(--ink); color: #7dffb0; border-radius: 12px; padding: 2px 14px; font-variant-numeric: tabular-nums; }

/* coins */
.coin-row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.coin { display: inline-grid; place-items: center; border-radius: 50%; font-weight: 800; border: 3px solid rgba(0, 0, 0, 0.35); box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.15); }
.coin.penny { width: 52px; height: 52px; background: #d98a4e; color: #4a2208; font-size: 16px; }
.coin.nickel { width: 60px; height: 60px; background: #c9ccd1; color: #333; font-size: 17px; }
.coin.dime { width: 46px; height: 46px; background: #dfe2e6; color: #333; font-size: 14px; }
.coin.quarter { width: 68px; height: 68px; background: #b9bec5; color: #222; font-size: 19px; }
.coin.bill { width: 96px; height: 50px; border-radius: 8px; background: #a8d5a2; color: #1f4d1a; font-size: 20px; }
.purse { min-height: 90px; display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; align-items: center; padding: 10px; border-radius: 18px; background: var(--bg); border: 3px dashed var(--line); margin-bottom: 12px; }
.coin-tray { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; align-items: center; }
.coin-tray button, .purse button { background: none; border: none; padding: 0; }

/* robot */
.grid { display: grid; gap: 4px; margin: 0 auto 12px; width: min(100%, 360px); }
.cell { aspect-ratio: 1; border-radius: 10px; background: #e9f3ff; border: 2px solid #c9dcf5; display: grid; place-items: center; font-size: clamp(20px, 6vw, 34px); position: relative; }
.cell.wall { background: #6b5b4b; border-color: #4a3f34; }
.cell.trail { background: #c8f5dc; }
.program { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; min-height: 52px; padding: 8px; border-radius: 14px; background: var(--bg); border: 3px dashed var(--line); margin-bottom: 10px; }
.program span { width: 40px; height: 40px; border-radius: 10px; background: var(--ink); color: #fff; display: grid; place-items: center; font-size: 22px; }
.arrows { display: grid; grid-template-columns: repeat(3, 64px); gap: 8px; justify-content: center; margin-bottom: 10px; }
.arrows button { height: 64px; border-radius: 16px; border: 3px solid var(--ink); background: #fffdf8; font-size: 28px; }

/* balloon arena */
.sky { position: relative; height: 380px; border-radius: 24px; overflow: hidden; background: linear-gradient(#bfe3ff, #eef8ff); border: 3px solid var(--line); margin-top: 14px; }
.balloon {
  position: absolute; bottom: -140px; width: 120px; min-height: 120px; border-radius: 50% 50% 46% 46%; border: none; color: #fff;
  font-size: 22px; font-weight: 800; display: grid; place-items: center; padding: 10px; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.25);
  animation: rise linear infinite; box-shadow: inset -10px -12px 0 rgba(0, 0, 0, 0.12);
}
.balloon::after { content: ""; position: absolute; bottom: -38px; left: 50%; width: 2px; height: 38px; background: rgba(0, 0, 0, 0.35); }
.balloon .emoji-choice { font-size: 36px; }
@keyframes rise { from { transform: translateY(0); } to { transform: translateY(-560px); } }
.balloon.popped { animation: pop 0.25s forwards !important; }
@keyframes pop { to { transform: scale(1.6); opacity: 0; } }
.balloon.wrong { filter: grayscale(1); opacity: 0.5; }

/* race arena */
.race { position: relative; height: 70px; background: repeating-linear-gradient(90deg, #f1e3c6 0 30px, #ead7b2 30px 60px); border-radius: 18px; border: 3px solid var(--line); margin-bottom: 12px; overflow: hidden; }
.race .lane { position: absolute; left: 0; right: 0; height: 50%; }
.race .lane.b { top: 50%; border-top: 2px dashed rgba(0, 0, 0, 0.15); }
.race .runner { position: absolute; top: 2px; font-size: 26px; transition: left 0.4s; transform: translateX(-50%); }
.race .finish { position: absolute; right: 8px; top: 0; bottom: 0; width: 10px; background: repeating-linear-gradient(0deg, #000 0 8px, #fff 8px 16px); }
.race .shadow { filter: grayscale(1) brightness(0.3); }

/* memory */
.mem-grid { display: grid; gap: 10px; margin: 0 auto; max-width: 640px; }
.mem-card { aspect-ratio: 3 / 4; perspective: 600px; border: none; background: none; padding: 0; }
.mem-inner { position: relative; width: 100%; height: 100%; transition: transform 0.35s; transform-style: preserve-3d; }
.mem-card.flip .mem-inner, .mem-card.done .mem-inner { transform: rotateY(180deg); }
.mem-face { position: absolute; inset: 0; border-radius: 14px; backface-visibility: hidden; display: grid; place-items: center; border: 3px solid var(--ink); padding: 4px; overflow: hidden; }
.mem-back { background: linear-gradient(135deg, var(--accent), #1d1b3a); color: #fff; font-size: 32px; }
.mem-front { background: #fffdf8; transform: rotateY(180deg); font-weight: 800; font-size: clamp(14px, 3.4vw, 22px); text-align: center; line-height: 1.1; }
.mem-front svg { width: 100%; height: auto; }
.mem-front .coin { transform: scale(0.75); margin: -6px; }
.mem-front .emoji-group { font-size: 22px; }
.mem-card.done .mem-front { background: #c8f5dc; }

/* results */
.results { text-align: center; }
.big-stars { font-size: 64px; letter-spacing: 6px; margin: 6px 0; }
.big-stars .off { filter: grayscale(1); opacity: 0.3; }
.star-pop { display: inline-block; animation: starpop 0.5s backwards; }
@keyframes starpop { from { transform: scale(0) rotate(-90deg); } }
.new-trophies { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin: 14px 0; }

/* trophies */
.shelf { margin-bottom: 26px; }
.shelf h3 { font-size: 22px; }
.shelf-row {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 10px; padding: 14px 12px 22px;
  background: linear-gradient(#8a5a33, #6d4426) bottom / 100% 14px no-repeat, linear-gradient(#fff8ea, #f3e2c2);
  border-radius: 18px; border: 3px solid #6d4426;
}
.trophy { text-align: center; padding: 6px; }
.trophy .t-icon { font-size: 46px; line-height: 1.1; display: block; }
.trophy .t-name { font-weight: 800; font-size: 15px; line-height: 1.1; }
.trophy .t-desc { font-size: 12px; color: var(--muted); line-height: 1.15; }
.trophy.locked .t-icon { filter: grayscale(1) brightness(0.2); opacity: 0.35; }
.trophy.locked .t-name { color: var(--muted); }
.trophy-card { background: var(--card); border: 3px solid var(--gold); border-radius: 18px; padding: 10px 14px; box-shadow: var(--shadow); min-width: 140px; animation: starpop 0.5s backwards; }

/* parents */
.kid-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 2px solid var(--line); flex-wrap: wrap; }
.kid-row .big-av { width: 52px; height: 52px; font-size: 30px; border-radius: 50%; display: grid; place-items: center; border: 3px solid var(--ink); }
.dojo-progress { display: flex; gap: 10px; flex-wrap: wrap; font-size: 14px; }
.dojo-progress span { background: var(--bg); border-radius: 10px; padding: 2px 8px; font-weight: 700; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 16px; font-weight: 800; z-index: 50; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3); max-width: calc(100% - 32px); }
.confetti { position: fixed; top: -20px; font-size: 26px; pointer-events: none; animation: fall linear forwards; z-index: 40; }
@keyframes fall { to { transform: translateY(110vh) rotate(540deg); } }

@media (max-width: 520px) {
  .choices { gap: 10px; }
  .choice { min-height: 62px; }
  .sky { height: 340px; }
  .balloon { width: 96px; min-height: 96px; font-size: 18px; }
  .qtext { margin: 6px 44px 10px 0; text-align: left; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
  .balloon { animation: none !important; position: relative; bottom: auto; display: inline-grid; margin: 8px; }
  .sky { height: auto; padding: 12px; text-align: center; }
}
