:root {
  --bg: #0d1220;
  --bg-2: #141c30;
  --line: #222e4a;
  --text: #e8eefc;
  --muted: #8fa0c4;
  --accent: #4cc9f0;
  --good: #35d07f;
  --bad: #ff6b6b;
  --gold: #ffc857;
  --radius: 14px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100dvh;
  background:
    radial-gradient(1100px 600px at 50% -10%, #17223d 0%, transparent 60%),
    var(--bg);
}

#app {
  max-width: 640px;
  margin: 0 auto;
  padding: clamp(16px, 4vw, 32px) clamp(14px, 4vw, 24px) 48px;
}

.screen { animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ------------------------------------------------------------- name --- */
.brand {
  font-size: clamp(38px, 11vw, 60px);
  line-height: 1;
  margin: 8vh 0 6px;
  letter-spacing: -.02em;
  text-align: center;
  font-weight: 800;
}
.brand span { color: var(--accent); }
.tagline {
  text-align: center;
  color: var(--muted);
  margin: 0 0 36px;
  font-size: 16px;
}

#name-form { display: flex; flex-direction: column; gap: 12px; }
#name-form label { color: var(--muted); font-size: 14px; }

input[type=text], #name-input {
  background: var(--bg-2);
  border: 2px solid var(--line);
  color: var(--text);
  border-radius: var(--radius);
  padding: 16px;
  font-size: 20px;
  width: 100%;
  outline: none;
}
input:focus { border-color: var(--accent); }

.btn {
  border: 0;
  border-radius: var(--radius);
  padding: 16px 20px;
  font-size: 18px;
  font-weight: 650;
  cursor: pointer;
  font-family: inherit;
}
.btn.primary { background: var(--accent); color: #06263a; }
.btn.primary:active { transform: translateY(1px); }
.btn.ghost { background: transparent; color: var(--muted); border: 2px solid var(--line); }
.btn.small { padding: 8px 14px; font-size: 14px; }

.error { color: var(--bad); font-size: 14px; margin: 0; }

.recent { margin-top: 28px; }
.recent-label { color: var(--muted); font-size: 13px; text-align: center; margin: 0 0 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip {
  background: var(--bg-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 15px;
  cursor: pointer;
  font-family: inherit;
}

/* ------------------------------------------------------------- menu --- */
.topbar { display: flex; justify-content: space-between; align-items: center; margin: 8px 0 26px; }
.who { color: var(--muted); font-size: 16px; }
.who strong { color: var(--text); }
.pick-title { font-size: 22px; margin: 0 0 14px; }

.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.mode {
  background: var(--bg-2);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-family: inherit;
}
.mode:active { border-color: var(--accent); }
.mode.wide { grid-column: 1 / -1; flex-direction: row; justify-content: center; gap: 14px; }
.mode .sign { font-size: 34px; line-height: 1; color: var(--accent); font-weight: 700; }
.mode .mode-name { font-size: 15px; font-weight: 600; }

.fine { color: var(--muted); font-size: 13px; text-align: center; margin: 16px 0 0; }

.panel {
  margin-top: 26px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.panel h3 { margin: 0 0 12px; font-size: 15px; color: var(--muted); font-weight: 600; }

.history { width: 100%; border-collapse: collapse; font-size: 15px; }
.history td { padding: 7px 0; border-bottom: 1px solid var(--line); }
.history tr:last-child td { border-bottom: 0; }
.history td:last-child { text-align: right; font-family: var(--mono); }
.history .rank { color: var(--muted); width: 26px; }
.history .me { color: var(--accent); font-weight: 700; }

.facts { display: flex; flex-wrap: wrap; gap: 8px; }
.fact {
  background: #101828;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 15px;
  font-family: var(--mono);
}
.fact b { font-weight: 700; }
.fact small { color: var(--muted); font-family: system-ui, sans-serif; margin-left: 6px; font-size: 12px; }
.fact.miss { border-color: #5a2530; background: #2a1520; }
.fact.miss small { color: var(--bad); }

/* ------------------------------------------------------------- test --- */
.test { display: flex; flex-direction: column; min-height: 88dvh; }
.hud { display: flex; justify-content: space-between; align-items: baseline; margin-top: 4px; }
.hud-item { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.hud-item small { color: var(--muted); font-size: 13px; font-weight: 500; margin-left: 4px; }
.hud .clock { font-family: var(--mono); color: var(--accent); font-size: 24px; }

.bar { height: 6px; background: var(--bg-2); border-radius: 99px; margin: 12px 0 0; overflow: hidden; }
#bar-fill { height: 100%; width: 0%; background: var(--accent); transition: width .12s linear; }

.question-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(20px, 5vh, 40px);
}
.question {
  font-size: clamp(56px, 18vw, 104px);
  font-weight: 800;
  letter-spacing: .02em;
  font-variant-numeric: tabular-nums;
  display: flex;
  gap: .18em;
  align-items: center;
  line-height: 1;
}
#q-op { color: var(--accent); }

.answer {
  width: clamp(180px, 55vw, 240px);
  text-align: center;
  font-size: clamp(40px, 12vw, 56px);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  padding: 14px;
  border-width: 3px;
  caret-color: var(--accent);
}
.answer.flash-good { border-color: var(--good); background: #0f2c1e; }
.answer.flash-bad { border-color: var(--bad); background: #2c1216; }

.miss-note {
  height: 30px;
  font-size: 22px;
  font-weight: 700;
  color: var(--bad);
  font-variant-numeric: tabular-nums;
  opacity: 0;
  transition: opacity .25s ease;
  pointer-events: none;
}
.miss-note.on { opacity: 1; transition: none; }

.quit { align-self: center; margin-top: 8px; opacity: .6; }

/* ---------------------------------------------------------- results --- */
#results-title { font-size: 30px; margin: 16px 0 20px; }
.score-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.score {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.score.big { grid-column: 1 / -1; }
.score span { font-size: 30px; font-weight: 800; font-family: var(--mono); }
.score.big span { font-size: 46px; color: var(--accent); }
.score small { color: var(--muted); font-size: 13px; }

.pb {
  margin: 14px 0 0;
  padding: 12px 16px;
  border-radius: var(--radius);
  background: #2a2210;
  border: 1px solid #5a4718;
  color: var(--gold);
  font-weight: 650;
  text-align: center;
}

.actions { display: flex; flex-direction: column; gap: 10px; margin-top: 28px; }

@media (max-width: 380px) {
  .modes { grid-template-columns: 1fr; }
}

/* -------------------------------------------------------- leaderboard --- */
.board {
  margin-top: 34px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 16px 14px;
}
.board-title {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  margin: 0 0 14px;
  font-weight: 600;
}
.board-tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.board-tab {
  flex: 1;
  background: #101828;
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 9px;
  padding: 8px 0;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  line-height: 1;
}
.board-tab.wide { flex: 1.6; font-size: 13px; }
.board-tab.is-on { border-color: var(--accent); color: var(--accent); background: #0f2233; }

.board-table { width: 100%; border-collapse: collapse; font-size: 15px; }
.board-table td { padding: 9px 0; border-bottom: 1px solid var(--line); vertical-align: baseline; }
.board-table tr:last-child td { border-bottom: 0; }
.board-rank {
  width: 30px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 13px;
}
.board-rank.medal { color: var(--gold); font-weight: 700; }
.board-name { font-weight: 600; }
.board-score { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.board-score small { display: block; color: var(--muted); font-size: 11px; font-family: system-ui, sans-serif; }
.board-empty { color: var(--muted); font-size: 14px; text-align: center; margin: 10px 0; }
.board-note { color: var(--muted); font-size: 12px; text-align: center; margin: 12px 0 0; }
.board-name.board-me { color: var(--accent); }
