:root {
  --bg: #10141c;
  --card: #1a2130;
  --card-2: #212a3d;
  --text: #e8ecf4;
  --muted: #93a0b8;
  --accent: #6ea8fe;
  --good: #46b28a;
  --bad: #d9705f;
  --border: #2c3750;
  --radius: 14px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f2f4f8;
    --card: #ffffff;
    --card-2: #eef1f7;
    --text: #1a2130;
    --muted: #5b6880;
    --accent: #2f6fd0;
    --good: #1f8f66;
    --bad: #c14f3d;
    --border: #d7dde8;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 17px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.top {
  padding: calc(env(safe-area-inset-top) + 14px) 16px 10px;
  max-width: 640px;
  margin: 0 auto;
}

.top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.top-row.sub { margin-top: 10px; flex-wrap: wrap; }
.top-row.sub select { flex: 1 1 140px; max-width: none; min-width: 0; }

h1 {
  font-size: 1.15rem;
  margin: 0;
  letter-spacing: 0.02em;
}

select {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.9rem;
  max-width: 60vw;
}

#topic-select { flex: 1; max-width: none; }

button {
  font-family: inherit;
  font-size: 0.95rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  cursor: pointer;
  padding: 10px 14px;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #0c1220;
  font-weight: 600;
  width: 100%;
  padding: 13px;
  margin-top: 14px;
}

button.ghost {
  background: transparent;
  color: var(--muted);
}

button.ghost.danger { color: var(--bad); width: 100%; margin-top: 10px; }

main {
  max-width: 640px;
  margin: 0 auto;
  padding: 6px 16px 90px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-top: 8px;
}

.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.tag {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  background: var(--card-2);
  border-radius: 999px;
  padding: 3px 10px;
}

.tag.type { color: var(--accent); }

.question {
  font-size: 1.08rem;
  font-weight: 550;
  white-space: pre-line;
}

.options { margin-top: 14px; display: grid; gap: 8px; }

.options button {
  background: var(--card-2);
  color: var(--text);
  text-align: left;
  padding: 12px 14px;
  width: 100%;
  line-height: 1.4;
}

.options button.correct {
  border-color: var(--good);
  background: color-mix(in srgb, var(--good) 18%, var(--card-2));
}

.options button.wrong {
  border-color: var(--bad);
  background: color-mix(in srgb, var(--bad) 18%, var(--card-2));
}

.options button:disabled { cursor: default; opacity: 1; }
.options button:disabled:not(.correct):not(.wrong) { opacity: 0.55; }

.verdict { margin-top: 12px; font-weight: 650; }
.verdict.good { color: var(--good); }
.verdict.bad { color: var(--bad); }

.answer {
  margin-top: 14px;
  padding: 13px 14px;
  background: var(--card-2);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  white-space: pre-line;
  font-size: 0.98rem;
}

.rate-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 16px;
}

.rate { padding: 13px; font-weight: 600; }
.rate.again { background: var(--card-2); color: var(--text); }
.rate.known {
  background: var(--good);
  border-color: var(--good);
  color: #0c1220;
}

.empty { color: var(--muted); text-align: center; margin-top: 40px; }

.foot {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 10px 16px calc(env(safe-area-inset-bottom) + 10px);
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
}

.tabs { display: flex; gap: 6px; }

.tab {
  background: var(--card);
  color: var(--muted);
  padding: 7px 14px;
  font-size: 0.88rem;
}

.tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #0c1220;
  font-weight: 600;
}

#game-menu { display: grid; gap: 10px; margin-top: 8px; }

.game-tile {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: left;
  color: var(--text);
  display: grid;
  gap: 4px;
}

.game-tile strong { font-size: 1.02rem; }
.game-tile span { color: var(--muted); font-size: 0.88rem; }
.game-tile .best { color: var(--accent); font-size: 0.8rem; }

.disclaimer {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.45;
  margin: 4px 2px 0;
}

.back-btn { margin-bottom: 10px; padding: 6px 10px; }

.game-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 10px;
}

.big-num { font-size: 1.9rem; font-weight: 700; color: var(--text); }

.big-problem {
  font-size: 2.2rem;
  font-weight: 700;
  text-align: center;
  padding: 22px 0;
  font-variant-numeric: tabular-nums;
}

#kr-input {
  width: 100%;
  background: var(--card-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 13px;
  font-size: 1.3rem;
  text-align: center;
}

.game-hint { color: var(--muted); font-size: 0.88rem; margin: 0 0 12px; }

.nb-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  aspect-ratio: 1;
  max-width: 320px;
  margin: 0 auto 4px;
}

.nb-cell {
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  transition: background 0.15s;
}

.nb-cell.on { background: var(--accent); border-color: var(--accent); }

.game-result {
  text-align: center;
  padding: 24px 0;
  line-height: 1.8;
  color: var(--muted);
}

#stats h2 { margin: 0 0 12px; font-size: 1.05rem; }

.stat-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
}

.stat-row:last-of-type { border-bottom: none; }
.stat-row .val { color: var(--muted); white-space: nowrap; }
