:root {
  --bg: #0f172a;
  --bg-elev: #1a2540;
  --bg-elev-2: #22304f;
  --border: #2c3a5c;
  --text: #e8ecf6;
  --text-dim: #a4b0cc;
  --accent: #f59e0b;
  --accent-dark: #b47305;
  --good: #34d399;
  --bad: #f87171;
  --radius: 14px;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6fb;
    --bg-elev: #ffffff;
    --bg-elev-2: #eef1f9;
    --border: #dbe1ee;
    --text: #16213e;
    --text-dim: #5b6785;
    --accent: #b4720a;
    --accent-dark: #8a5806;
    --good: #0f9d63;
    --bad: #d1414a;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

#app {
  max-width: 640px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) 16px calc(env(safe-area-inset-bottom) + 16px);
  display: flex;
  flex-direction: column;
}

a { color: var(--accent); }

button {
  font-family: inherit;
  cursor: pointer;
}

.btn {
  display: block;
  width: 100%;
  padding: 14px 18px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  text-align: left;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
.btn:active { transform: scale(0.98); }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #1a1206;
  text-align: center;
}
.btn.secondary {
  text-align: center;
}
.btn.ghost {
  background: transparent;
  text-align: center;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-row {
  display: flex;
  gap: 10px;
}
.btn-row .btn { flex: 1; }

header.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 2px 10px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 5;
}
header.topbar h1 {
  font-size: 18px;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}
header.topbar .back {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 15px;
  padding: 8px 4px;
}

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
}

.stack { display: flex; flex-direction: column; gap: 12px; }

.hero {
  text-align: center;
  padding: 22px 8px 6px;
}
.hero .logo {
  width: 64px; height: 64px;
  border-radius: 18px;
  margin: 0 auto 12px;
  display: block;
}
.hero h1 { font-size: 22px; margin: 0 0 4px; }
.hero p { color: var(--text-dim); margin: 0; font-size: 14px; }

.domain-list { display: flex; flex-direction: column; gap: 10px; }
.domain-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-elev);
}
.domain-row .meta { font-size: 12px; color: var(--text-dim); }
.domain-row .name { font-weight: 600; font-size: 15px; }
.domain-row .acc { font-variant-numeric: tabular-nums; font-weight: 700; }
.acc-good { color: var(--good); }
.acc-bad { color: var(--bad); }
.acc-mid { color: var(--accent); }

.progress-bar {
  height: 6px;
  border-radius: 4px;
  background: var(--bg-elev-2);
  overflow: hidden;
  margin-top: 6px;
}
.progress-bar > div {
  height: 100%;
  background: var(--accent);
}

.qmeta {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 8px;
}
.qtext {
  font-size: 17px;
  font-weight: 600;
  line-height: 1.4;
  margin: 4px 0 16px;
}
.options { display: flex; flex-direction: column; gap: 10px; }
.option {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 13px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  font-size: 15px;
  line-height: 1.4;
  text-align: left;
}
.option .letter {
  flex: 0 0 auto;
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-dim);
}
.option.selectable:active { transform: scale(0.99); }
.option.correct { border-color: var(--good); background: color-mix(in srgb, var(--good) 14%, var(--bg-elev)); }
.option.correct .letter { border-color: var(--good); color: var(--good); }
.option.incorrect { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 14%, var(--bg-elev)); }
.option.incorrect .letter { border-color: var(--bad); color: var(--bad); }
.option.dim { opacity: 0.55; }

.explanation {
  margin-top: 16px;
  padding: 14px;
  border-radius: 12px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
}
.explanation .tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 6px;
  padding: 3px 8px;
  border-radius: 6px;
}
.tag.correct-tag { background: color-mix(in srgb, var(--good) 25%, transparent); color: var(--good); }
.tag.incorrect-tag { background: color-mix(in srgb, var(--bad) 25%, transparent); color: var(--bad); }

footer.actions {
  margin-top: auto;
  padding-top: 14px;
  position: sticky;
  bottom: 0;
  background: linear-gradient(to top, var(--bg) 60%, transparent);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 14px 0;
}
.stat-tile {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 10px;
  text-align: center;
}
.stat-tile .val { font-size: 20px; font-weight: 700; }
.stat-tile .lbl { font-size: 11px; color: var(--text-dim); margin-top: 2px; }

.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  font-size: 13px;
  color: var(--text-dim);
}
.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #1a1206;
  font-weight: 600;
}

.timer {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 13px;
  color: var(--text-dim);
}
.timer.low { color: var(--bad); }

.review-item { border-left: 3px solid var(--border); padding-left: 12px; margin-bottom: 18px; }
.review-item.wrong { border-left-color: var(--bad); }
.review-item.right { border-left-color: var(--good); }

.empty-note { color: var(--text-dim); font-size: 13px; text-align: center; padding: 20px 0; }

.install-banner {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  font-size: 13px;
  margin-bottom: 14px;
}
.install-banner button {
  background: var(--accent);
  color: #1a1206;
  border: none;
  border-radius: 8px;
  padding: 8px 12px;
  font-weight: 700;
  font-size: 13px;
  white-space: nowrap;
}
.install-banner.show { display: flex; }

.section-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  margin: 22px 0 10px;
}
.section-title:first-child { margin-top: 0; }
