:root {
  --bg: #fdf4ff;
  --bg2: #ede9fe;
  --card: #ffffff;
  --ink: #2e1065;
  --muted: #6b5b8a;
  --primary: #7c3aed;
  --primary-ink: #ffffff;
  --accent: #ec4899;
  --good: #16a34a;
  --good-bg: #dcfce7;
  --warn: #d97706;
  --warn-bg: #fef3c7;
  --bad: #dc2626;
  --bad-bg: #fee2e2;
  --line: #e9d5ff;
  --shadow: 0 6px 20px rgba(76, 29, 149, 0.10);
  --radius: 18px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1030;
    --bg2: #120a24;
    --card: #261a44;
    --ink: #f5f0ff;
    --muted: #b8a9d9;
    --primary: #a78bfa;
    --primary-ink: #1a1030;
    --accent: #f472b6;
    --good: #4ade80;
    --good-bg: #14532d;
    --warn: #fbbf24;
    --warn-bg: #4a3405;
    --bad: #f87171;
    --bad-bg: #4c1414;
    --line: #3b2a63;
    --shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: linear-gradient(160deg, var(--bg), var(--bg2)) fixed;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}
.app {
  max-width: 680px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}
h1, h2, h3 { margin: 0 0 8px; line-height: 1.15; }
h3 { font-size: 1.05rem; }
.muted { color: var(--muted); }
.hidden { display: none !important; }
.grow { flex: 1; margin: 0; }

.screen { display: none; animation: fade .25s ease; }
.screen.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* Hero */
.hero { text-align: center; padding: 12px 0 18px; }
.hero h1 { font-size: clamp(2rem, 8vw, 3rem); letter-spacing: -0.02em; }
.hero h1 span {
  display: block;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.tagline { margin: 4px 0 0; color: var(--muted); font-size: 1.1rem; }

/* Cards */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.card.center { text-align: center; }
.field-label { display: block; font-weight: 700; margin-bottom: 8px; }
.section-title { font-size: 1.2rem; margin: 18px 4px 10px; }

input[type=text] {
  width: 100%;
  font: inherit;
  font-size: 1.15rem;
  padding: 14px 16px;
  border-radius: 14px;
  border: 2px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  outline: none;
  transition: border-color .15s;
}
input[type=text]:focus { border-color: var(--primary); }

/* Buttons */
.btn {
  font: inherit;
  font-weight: 700;
  font-size: 1.05rem;
  border: 0;
  border-radius: 14px;
  padding: 14px 18px;
  cursor: pointer;
  background: var(--bg2);
  color: var(--ink);
  transition: transform .08s, filter .15s;
  min-height: 48px;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: linear-gradient(135deg, var(--primary), var(--accent)); color: #fff; }
.btn.ghost { background: transparent; border: 2px solid var(--line); }
.btn.danger { background: transparent; color: var(--bad); border: 2px solid var(--bad-bg); }
.btn.small { padding: 8px 12px; min-height: 38px; font-size: .95rem; }
.btn.wide { width: 100%; margin-top: 12px; }
.row { display: flex; gap: 10px; margin-top: 12px; }
.row .btn { flex: 1; }
.icon-btn {
  font: inherit; font-size: 1.2rem; width: 44px; height: 44px; border-radius: 50%;
  border: 0; background: var(--card); color: var(--ink); cursor: pointer; box-shadow: var(--shadow);
  flex: none;
}

/* Segmented control */
.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.seg button {
  font: inherit; font-weight: 700; padding: 10px 4px; border-radius: 12px;
  border: 2px solid var(--line); background: transparent; color: var(--ink); cursor: pointer;
  min-height: 44px;
}
.seg button.on { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }

/* Chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chips:empty { display: none; }
.chip {
  font: inherit; font-size: .95rem; padding: 7px 12px; border-radius: 999px;
  background: var(--bg2); color: var(--ink); border: 2px solid transparent; cursor: pointer;
}
.chip.on { border-color: var(--primary); background: var(--primary); color: var(--primary-ink); }
.chips.static .chip { cursor: default; }
.chip.extra { background: var(--warn-bg); }

/* Category grid */
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 520px) { .grid { grid-template-columns: repeat(3, 1fr); } }
.cat {
  font: inherit; color: var(--ink); background: var(--card); border: 0; cursor: pointer;
  border-radius: var(--radius); padding: 16px 10px 14px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  transition: transform .1s;
}
.cat:hover { transform: translateY(-2px); }
.cat:active { transform: scale(.97); }
.cat .emoji { font-size: 2.2rem; line-height: 1; }
.cat .name { font-weight: 800; font-size: 1.05rem; text-align: center; }
.cat .best { font-size: .8rem; color: var(--muted); }

/* Play */
.play-top { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.play-cat { flex: 1; font-weight: 800; font-size: 1.2rem; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.timer {
  min-width: 64px; text-align: center; font-weight: 800; font-size: 1.2rem;
  background: var(--card); border-radius: 999px; padding: 10px 12px; box-shadow: var(--shadow);
  font-variant-numeric: tabular-nums;
}
.timer.low { color: #fff; background: var(--bad); animation: pulse 1s infinite; }
@keyframes pulse { 50% { transform: scale(1.08); } }

.score-bubble { text-align: center; margin: 4px 0 10px; }
.score-num {
  font-size: clamp(3.5rem, 16vw, 5rem); font-weight: 900; line-height: 1;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  display: inline-block;
}
.score-num.bump { animation: bump .3s ease; }
@keyframes bump { 40% { transform: scale(1.25); } }
.score-label { color: var(--muted); font-weight: 700; }

.toast { min-height: 1.6em; text-align: center; font-weight: 700; margin-bottom: 8px; }
.toast.good { color: var(--good); }
.toast.warn { color: var(--warn); }
.toast.bad { color: var(--bad); }

.entry { display: flex; gap: 8px; position: sticky; top: 8px; z-index: 5; }
.entry input { flex: 1; min-width: 0; font-size: 1.25rem; background: var(--card); box-shadow: var(--shadow); }
.entry.shake { animation: shake .35s; }
@keyframes shake { 20%,60% { transform: translateX(-8px); } 40%,80% { transform: translateX(8px); } }

.unknown {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  background: var(--warn-bg); border-radius: 14px; padding: 10px 12px; margin-top: 10px;
}
.unknown span { flex: 1 1 100%; font-weight: 600; }
@media (min-width: 480px) { .unknown span { flex: 1; } }

.answers { list-style: none; padding: 0; margin: 14px 0 0; display: flex; flex-wrap: wrap; gap: 8px; }
.answers li {
  background: var(--good-bg); color: var(--ink); padding: 8px 12px; border-radius: 999px;
  font-weight: 600; animation: pop .25s ease;
}
.answers li.extra { background: var(--warn-bg); }
@keyframes pop { from { transform: scale(.5); opacity: 0; } }

/* Results */
.badge { font-size: 3.5rem; }
.big-score { font-size: 4rem; font-weight: 900; color: var(--primary); line-height: 1.1; }

/* Scores */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
td.num { text-align: right; font-weight: 800; font-variant-numeric: tabular-nums; }
.recent { list-style: none; margin: 0; padding: 0; }
.recent li { display: flex; justify-content: space-between; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.recent li:last-child { border-bottom: 0; }
.recent .when { color: var(--muted); font-size: .85rem; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.stats b { display: block; font-size: 1.6rem; color: var(--primary); }
.stats span { color: var(--muted); font-size: .85rem; }

/* Confetti */
#confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 50; }
.confetto {
  position: absolute; top: -20px; width: 10px; height: 14px; border-radius: 2px;
  animation: fall linear forwards;
}
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
