/* ==========================================================================
   Wonder Lab — shared design system
   Big touch targets (min 56px), rounded "toy" shapes, candy palette.
   ========================================================================== */
:root {
  --ink: #2b2150;
  --ink-soft: #5d5486;
  --paper: #fffaf3;
  --sun: #ffc93c;
  --tangerine: #ff8a3d;
  --berry: #ff5d8f;
  --bubblegum: #ff9ecf;
  --mint: #3ddcb0;
  --sky: #4cc3ff;
  --ocean: #2f7bff;
  --grape: #9b6bff;
  --leaf: #58c95b;
  --panel: rgba(255, 255, 255, 0.78);
  --panel-strong: rgba(255, 255, 255, 0.92);
  --shadow-toy: 0 6px 0 rgba(43, 33, 80, 0.14), 0 18px 40px -12px rgba(43, 33, 80, 0.35);
  --shadow-soft: 0 10px 30px -10px rgba(43, 33, 80, 0.35);
  --radius-l: 28px;
  --radius-m: 20px;
  --font-display: "Fredoka", "Baloo 2", "Comic Sans MS", system-ui, sans-serif;
  --font-body: "Nunito", "Fredoka", system-ui, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
button:focus-visible, a:focus-visible { outline: 3px solid var(--ocean); outline-offset: 3px; }
img { display: block; max-width: 100%; }

/* ---------- Game page shell ---------- */
.game-body { overflow: hidden; background: #1b1740; }
.stage { position: fixed; inset: 0; }
.stage canvas { display: block; width: 100%; height: 100%; touch-action: none; }

.topbar {
  position: fixed; z-index: 10;
  top: calc(14px + var(--safe-top)); left: 14px; right: 14px;
  display: flex; align-items: center; gap: 12px; pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.chip-btn {
  height: 56px; min-width: 56px; padding: 0 18px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: 999px; background: var(--panel-strong);
  font-family: var(--font-display); font-weight: 600; font-size: 19px; letter-spacing: 0.01em;
  box-shadow: var(--shadow-toy); color: var(--ink); text-decoration: none;
  transition: transform .18s cubic-bezier(.3,1.6,.5,1), background .2s;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.chip-btn:hover { transform: translateY(-2px) scale(1.04); }
.chip-btn:active { transform: translateY(2px) scale(.97); }
.chip-btn .ico { font-size: 24px; line-height: 1; }
.title-pill {
  flex: 1; min-width: 0; text-align: center;
  font-family: var(--font-display); font-weight: 700; font-size: clamp(18px, 2.6vw, 28px);
  letter-spacing: 0.02em; color: #fff; text-shadow: 0 3px 0 rgba(0,0,0,.18), 0 8px 24px rgba(0,0,0,.35);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.stars-pill { background: linear-gradient(180deg, #fff6d6, #ffe38a); }

/* ---------- Mode tabs (top) ---------- */
.modes {
  position: fixed; z-index: 10; left: 50%; transform: translateX(-50%);
  top: calc(84px + var(--safe-top));
  display: flex; gap: 6px; padding: 6px; border-radius: 999px;
  background: rgba(255,255,255,.55); box-shadow: var(--shadow-soft);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  max-width: calc(100vw - 20px); overflow-x: auto; scrollbar-width: none;
}
.modes button {
  height: 48px; padding: 0 18px; border-radius: 999px; white-space: nowrap;
  font-family: var(--font-display); font-weight: 600; font-size: 17px; color: var(--ink-soft);
  transition: background .2s, color .2s, transform .2s;
}
.modes button:hover { background: rgba(255,255,255,.7); }
.modes button.on { background: #fff; color: var(--ink); box-shadow: 0 4px 0 rgba(43,33,80,.12); transform: translateY(-1px); }

/* ---------- Bottom tray (swatches etc.) ---------- */
.tray {
  position: fixed; z-index: 10; left: 50%; transform: translateX(-50%);
  bottom: calc(14px + var(--safe-bottom));
  width: min(980px, calc(100vw - 20px));
  border-radius: var(--radius-l); background: var(--panel);
  box-shadow: var(--shadow-toy); padding: 12px 14px 14px;
  backdrop-filter: blur(16px) saturate(1.3); -webkit-backdrop-filter: blur(16px) saturate(1.3);
}
.tray-tabs { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 10px; }
.tray-tabs button {
  flex: none; height: 50px; padding: 0 16px; border-radius: 16px;
  font-family: var(--font-display); font-weight: 600; font-size: 17px; color: var(--ink-soft);
  display: inline-flex; align-items: center; gap: 8px; background: rgba(255,255,255,.5);
  transition: background .2s, color .2s, transform .2s;
}
.tray-tabs button .ico { font-size: 22px; }
.tray-tabs button.on { background: var(--ink); color: #fff; transform: translateY(-2px); }
.tray-row { display: flex; gap: 10px; overflow-x: auto; scrollbar-width: none; padding: 4px 2px 2px; align-items: center; min-height: 72px; }
.tray-label {
  flex: none; font-family: var(--font-display); font-weight: 600; font-size: 14px; color: var(--ink-soft);
  text-transform: uppercase; letter-spacing: .08em; padding-right: 4px;
}

.swatch {
  flex: none; width: 60px; height: 60px; border-radius: 50%;
  box-shadow: inset 0 -6px 0 rgba(0,0,0,.14), inset 0 6px 10px rgba(255,255,255,.55), 0 4px 10px -2px rgba(43,33,80,.35);
  transition: transform .2s cubic-bezier(.3,1.6,.5,1);
  position: relative;
}
.swatch:hover { transform: scale(1.1) translateY(-2px); }
.swatch.on { transform: scale(1.14) translateY(-4px); }
.swatch.on::after {
  content: ""; position: absolute; inset: -7px; border-radius: 50%;
  border: 4px solid #fff; box-shadow: 0 0 0 3px var(--ink);
}
.opt {
  flex: none; min-width: 86px; height: 64px; padding: 0 14px; border-radius: 18px;
  background: #fff; display: inline-flex; flex-direction: column; align-items: center; justify-content: center;
  font-family: var(--font-display); font-weight: 600; font-size: 14px; color: var(--ink-soft);
  box-shadow: 0 4px 0 rgba(43,33,80,.12);
  transition: transform .2s cubic-bezier(.3,1.6,.5,1), background .2s, color .2s;
}
.opt .ico { font-size: 26px; line-height: 1.1; }
.opt:hover { transform: translateY(-2px); }
.opt.on { background: var(--ink); color: #fff; transform: translateY(-3px); }

/* ---------- Info card (left) ---------- */
.card {
  position: fixed; z-index: 9; left: 14px; top: calc(150px + var(--safe-top));
  width: min(340px, calc(100vw - 28px));
  border-radius: var(--radius-m); background: var(--panel);
  box-shadow: var(--shadow-toy); padding: 16px 18px;
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
}
.card { cursor: pointer; transition: width .3s, padding .3s; }
.card.mini { width: auto; max-width: 340px; padding: 10px 16px; }
.card.mini > :not(h2) { display: none; }
.card.mini h2 { margin: 0; font-size: 18px; }
.card.mini h2::after { content: ' · tap to learn 📖'; font-weight: 500; font-size: 14px; color: var(--ink-soft); }
.card h2 { margin: 0 0 6px; font-family: var(--font-display); font-weight: 700; font-size: 22px; letter-spacing: .01em; }
.card p { margin: 0 0 8px; font-size: 16px; line-height: 1.45; color: var(--ink-soft); }
.card .big {
  font-family: var(--font-display); font-weight: 700; font-size: 30px; letter-spacing: .01em; color: var(--ink);
}
.stat-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.stat {
  flex: 1; min-width: 88px; background: #fff; border-radius: 16px; padding: 8px 10px;
  box-shadow: 0 3px 0 rgba(43,33,80,.1);
}
.stat i { display: block; font-style: normal; font-size: 12px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-soft); }
.stat b { display: block; font-family: var(--font-display); font-size: 24px; font-weight: 700; }
.formula {
  margin-top: 8px; padding: 10px 12px; border-radius: 14px; background: #fff7d6;
  font-family: var(--font-display); font-size: 17px; line-height: 1.4; color: #6b4a00;
}

/* ---------- Big slider (kid sized) ---------- */
.slider-wrap { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 220px; }
.slider-wrap .emo { font-size: 32px; flex: none; }
input[type=range].kid {
  -webkit-appearance: none; appearance: none; flex: 1; height: 22px; border-radius: 999px;
  background: linear-gradient(90deg, var(--tangerine), var(--sun), var(--sky));
  box-shadow: inset 0 3px 6px rgba(0,0,0,.18);
}
input[type=range].kid::-webkit-slider-thumb {
  -webkit-appearance: none; width: 46px; height: 46px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff, #ffe38a 45%, #ffb300);
  box-shadow: 0 5px 0 rgba(0,0,0,.18), 0 8px 18px rgba(0,0,0,.25); cursor: grab;
}
input[type=range].kid::-moz-range-thumb {
  width: 46px; height: 46px; border-radius: 50%; border: 0;
  background: radial-gradient(circle at 35% 30%, #fff, #ffe38a 45%, #ffb300);
  box-shadow: 0 5px 0 rgba(0,0,0,.18), 0 8px 18px rgba(0,0,0,.25);
}

/* ---------- Toast / speech bubble ---------- */
.bubble {
  position: fixed; z-index: 20; left: 50%; top: 42%; transform: translate(-50%, -50%) scale(.6);
  padding: 22px 30px; border-radius: 30px; background: #fff; box-shadow: var(--shadow-toy);
  font-family: var(--font-display); font-weight: 700; font-size: clamp(24px, 4vw, 40px); letter-spacing: .01em;
  text-align: center; opacity: 0; pointer-events: none;
  transition: opacity .25s, transform .45s cubic-bezier(.3,1.7,.5,1);
}
.bubble.on { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.bubble small { display: block; font-size: .5em; color: var(--ink-soft); font-weight: 600; margin-top: 4px; }

.hint {
  position: fixed; z-index: 9; left: 50%; transform: translateX(-50%);
  bottom: calc(190px + var(--safe-bottom)); padding: 10px 18px; border-radius: 999px;
  background: rgba(43,33,80,.72); color: #fff; font-weight: 700; font-size: 16px; white-space: nowrap;
  pointer-events: none; transition: opacity .4s;
}

#confetti { position: fixed; inset: 0; z-index: 30; pointer-events: none; }

.loading {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  background: radial-gradient(circle at 50% 40%, #3b2f7a, #1b1740);
  color: #fff; font-family: var(--font-display); font-size: 26px; font-weight: 600; transition: opacity .6s;
}
.loading .spin { font-size: 64px; animation: bob 1s ease-in-out infinite alternate; text-align: center; }
@keyframes bob { from { transform: translateY(-6px) rotate(-8deg); } to { transform: translateY(6px) rotate(8deg); } }

@media (max-width: 760px) {
  .card { top: auto; bottom: calc(200px + var(--safe-bottom)); left: 10px; right: 10px; width: auto; padding: 12px 14px; }
  .card p { display: none; }
  .card .formula { display: none; }
  .modes { top: calc(78px + var(--safe-top)); }
  .modes button { height: 44px; padding: 0 12px; font-size: 15px; }
  .chip-btn { height: 50px; min-width: 50px; font-size: 16px; padding: 0 14px; }
  .chip-btn .lbl { display: none; }
  .swatch { width: 52px; height: 52px; }
  .hint { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
