:root {
  --bg: #f6f3ff;
  --surface: #ffffff;
  --text: #1f1a33;
  --muted: #6b6485;
  --primary: #7c4dff;
  --primary-ink: #ffffff;
  --good: #22a861;
  --good-bg: #e2f7eb;
  --warn: #f2a91d;
  --bad: #e5484d;
  --bad-bg: #fde8e8;
  --key: #ffffff;
  --key-fn: #ece7fb;
  --line: #ddd6f3;
  --slot: #f1edff;
  --shadow: 0 2px 0 rgba(60, 40, 120, .12);
  --skin: #ffd7b0;
  --skin-line: #c98d5c;
  --brain: #f7a8c8;
  --brain-line: #d0648f;
  --shirt: #7c4dff;
  --pants: #3d3a5c;
  --font: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15121f;
    --surface: #221d33;
    --text: #f1edff;
    --muted: #a49cc2;
    --primary: #9b78ff;
    --good-bg: #173527;
    --bad-bg: #3a1c20;
    --key: #2a2440;
    --key-fn: #352d52;
    --line: #3a3257;
    --slot: #2f2848;
    --shadow: 0 2px 0 rgba(0, 0, 0, .4);
    --pants: #8e88b8;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; touch-action: manipulation; cursor: pointer; }

.screen {
  display: none;
  min-height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
}
.screen.active { display: flex; flex-direction: column; }

/* ---------- start ---------- */
.home-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.home-head h1 { font-size: 1.5rem; margin: 4px 0; letter-spacing: -.01em; }
.link { background: none; border: 0; color: var(--primary); font-weight: 600; padding: 8px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 0;
  background: var(--key-fn); font-size: 1.1rem;
}

.figure-wrap { display: flex; justify-content: center; margin-top: 4px; }
.figure { width: 100%; height: 34dvh; min-height: 200px; max-height: 340px; overflow: visible; }

.score-block { text-align: center; margin: 4px 0 10px; position: relative; }
.gain {
  position: absolute; left: calc(50% + 64px); top: 4px; transform: translate(0, 0);
  font-size: 1.6rem; font-weight: 800; color: var(--good); opacity: 0; pointer-events: none;
}
.gain.show { animation: gain 2.2s ease-out forwards; }
@keyframes gain {
  0% { opacity: 0; transform: translate(0, 20px) scale(.6); }
  15% { opacity: 1; transform: translate(0, 0) scale(1.15); }
  70% { opacity: 1; transform: translate(0, -14px) scale(1); }
  100% { opacity: 0; transform: translate(0, -30px) scale(1); }
}
.score.bump { animation: bump .5s ease; }
@keyframes bump { 40% { transform: scale(1.25); } }
.figure.cheer { animation: cheer .7s ease; transform-origin: 50% 100%; }
@keyframes cheer { 25% { transform: scaleY(1.06) translateY(-6px); } 50% { transform: scaleY(.97); } 75% { transform: translateY(-3px); } }
.unlock { margin-top: 8px; font-weight: 700; color: var(--primary); min-height: 0; }
.unlock:empty { display: none; }
.unlock.show { animation: bump .6s ease; }
.score { font-size: 3rem; font-weight: 800; line-height: 1; color: var(--primary); font-variant-numeric: tabular-nums; }
.score-label { color: var(--muted); font-weight: 600; }
.rank { margin-top: 6px; font-weight: 700; }
.next { color: var(--muted); font-size: .9rem; margin-top: 2px; }

.pick-title { font-size: 1rem; margin: 10px 0 8px; color: var(--muted); font-weight: 600; }
.sections { display: grid; gap: 8px; }
.section-btn {
  display: flex; align-items: center; gap: 12px;
  text-align: left; padding: 14px 16px; border-radius: 16px;
  border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow);
}
.section-btn:active { transform: translateY(1px); box-shadow: none; }
.section-btn .num {
  min-width: 44px; height: 32px; border-radius: 10px; display: grid; place-items: center;
  background: var(--slot); color: var(--primary); font-weight: 800; font-size: .95rem;
}
.section-btn .t { font-weight: 600; flex: 1; }
.section-btn .pct { color: var(--muted); font-size: .85rem; font-variant-numeric: tabular-nums; }
.section-btn { width: 100%; }
.section-btn .chev { color: var(--muted); transition: transform .2s; }
.section.open .section-btn { border-radius: 16px 16px 0 0; box-shadow: none; }
.section.open .chev { transform: rotate(180deg); }
.groups {
  display: grid; background: var(--surface); border: 1px solid var(--line); border-top: 0;
  border-radius: 0 0 16px 16px; overflow: hidden; box-shadow: var(--shadow);
}
.group-btn {
  display: flex; align-items: center; gap: 10px; text-align: left;
  padding: 14px 16px 14px 72px; min-height: 52px; background: none; border: 0; border-top: 1px solid var(--line);
}
.group-btn:active { background: var(--slot); }
.group-btn .t { flex: 1; font-weight: 600; }
.group-btn .pct { color: var(--muted); font-size: .85rem; font-variant-numeric: tabular-nums; }
.group-btn .go { color: var(--primary); font-size: .8rem; }
.stat-row.grp { padding-left: 0; font-size: .9rem; }
.stat-row.grp b { display: none; }
.stat-row.grp > div { grid-column: 2; }

/* ---------- runda ---------- */
#screen-round { padding-bottom: 0; }
.round-head { display: flex; align-items: center; gap: 12px; }
.dots { display: flex; gap: 6px; flex: 1; justify-content: center; }
.dot { width: 14px; height: 14px; border-radius: 50%; background: var(--line); transition: background .2s, transform .2s; }
.dot.current { background: var(--primary); transform: scale(1.25); }
.dot.good { background: var(--good); }
.dot.meh { background: var(--warn); }
.dots.big .dot { width: 22px; height: 22px; }
.head-spacer { width: 40px; }

.round-body { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 14px; padding: 12px 0; }
.q-section { text-align: center; color: var(--muted); font-size: .85rem; font-weight: 600; }
.q-card {
  background: var(--surface); border-radius: 20px; padding: 20px 16px;
  text-align: center; box-shadow: var(--shadow); border: 1px solid var(--line);
}
.question { font-size: 1.45rem; font-weight: 700; line-height: 1.5; overflow-wrap: anywhere; }
.question small { font-size: .9rem; color: var(--muted); font-weight: 600; }
.question sup, .answer sup { font-size: .62em; vertical-align: .9em; line-height: 0; }
.hint { color: var(--muted); font-size: .9rem; margin-top: 6px; }
.hint:empty { display: none; }

.frac { display: inline-flex; flex-direction: column; vertical-align: middle; text-align: center; margin: 0 .15em; }
.frac > span { padding: 0 .25em; line-height: 1.35; }
.frac > span:first-child { border-bottom: 2px solid currentColor; }

.answer {
  display: flex; align-items: center; justify-content: center; flex-wrap: wrap;
  gap: 6px; font-size: 1.6rem; font-weight: 700; min-height: 64px;
}
.answer .eq { color: var(--muted); margin-right: 2px; }
.slot {
  min-width: 64px; height: 56px; padding: 0 12px; border-radius: 14px;
  background: var(--slot); border: 2px solid var(--line);
  display: inline-flex; align-items: center; justify-content: center;
  font-variant-numeric: tabular-nums; font-weight: 700; font-size: 1.6rem;
}
.slot.sup { min-width: 46px; height: 40px; font-size: 1.15rem; align-self: flex-start; margin-top: -14px; border-radius: 10px; padding: 0 8px; }
.slot.active { border-color: var(--primary); }
.slot.active::after { content: ""; width: 2px; height: 1.1em; background: var(--primary); margin-left: 2px; animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.answer.shake { animation: shake .4s ease; }
.answer.correct .slot { background: var(--good-bg); border-color: var(--good); }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }

.feedback { text-align: center; min-height: 2.8em; font-weight: 700; font-size: 1.05rem; }
.feedback.good { color: var(--good); }
.feedback.bad { color: var(--bad); }
.feedback .reveal { display: block; margin-top: 4px; color: var(--text); font-weight: 600; font-size: .95rem; }

.keypad {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
  padding: 10px 0 max(12px, env(safe-area-inset-bottom));
  position: sticky; bottom: 0; background: var(--bg);
}
.keypad button {
  height: 58px; border-radius: 14px; border: 0; background: var(--key);
  font-size: 1.5rem; font-weight: 700; box-shadow: var(--shadow);
  user-select: none; -webkit-user-select: none;
}
.keypad button:active { transform: translateY(2px); box-shadow: none; }
.keypad .k-fn { background: var(--key-fn); }
.keypad .k-switch { font-size: .95rem; }
.keypad .k-switch[disabled] { visibility: hidden; }
.keypad .k-ok { grid-column: span 2; background: var(--primary); color: var(--primary-ink); }

/* ---------- resultat ---------- */
#screen-result { justify-content: center; }
.result { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.result-emoji { font-size: 4rem; }
.result h2 { margin: 0; font-size: 1.8rem; }
.result p { color: var(--muted); margin: 0; font-size: 1.05rem; }
.result-actions { display: grid; gap: 10px; width: 100%; margin-top: 16px; }
.btn {
  height: 56px; border-radius: 16px; border: 1px solid var(--line);
  background: var(--surface); font-weight: 700; font-size: 1.05rem; box-shadow: var(--shadow);
}
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: transparent; }

/* ---------- statistik ---------- */
.stats { display: grid; gap: 16px; margin-top: 12px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 14px 16px; }
.card h3 { margin: 0 0 8px; font-size: 1rem; }
.kv { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.kv b { display: block; font-size: 1.4rem; color: var(--primary); }
.kv span { font-size: .8rem; color: var(--muted); }
.stat-row { display: grid; grid-template-columns: 48px 1fr auto; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
.stat-row:first-of-type { border-top: 0; }
.bar { height: 8px; border-radius: 4px; background: var(--slot); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--good); }
.stat-row small { color: var(--muted); font-variant-numeric: tabular-nums; }
.wrong { padding: 8px 0; border-top: 1px solid var(--line); font-size: .9rem; }
.wrong:first-of-type { border-top: 0; }
.wrong .q { font-weight: 600; }
.wrong .meta { color: var(--muted); }
.wrong .meta .g { color: var(--bad); font-weight: 600; }
.wrong .meta .c { color: var(--good); font-weight: 600; }
.wrong sup { font-size: .7em; }
.muted { color: var(--muted); }
.danger { color: var(--bad); background: none; border: 0; padding: 8px 0; font-weight: 600; }
