:root {
  --bg: #0c1220;
  --bg-elev: #141c2e;
  --bg-card: #1a2438;
  --border: #2a3a55;
  --text: #e8eef8;
  --muted: #8b9bb4;
  --primary: #5b8cff;
  --primary-hover: #7aa3ff;
  --accent: #34d399;
  --danger: #f87171;
  --warn: #fbbf24;
  --flag: #fbbf24;
  --radius: 14px;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.4);
  --font: "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
    "Noto Sans SC", system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  background:
    radial-gradient(1100px 520px at 8% -8%, #1e3a7a55, transparent),
    radial-gradient(800px 480px at 100% 0%, #0a4a5540, transparent),
    var(--bg);
  color: var(--text);
  line-height: 1.55;
}

#app {
  max-width: 760px;
  margin: 0 auto;
  padding: 20px 16px 56px;
}

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

.hero { text-align: center; margin: 12px 0 24px; }
.hero.compact { margin-bottom: 16px; }
.hero-badge {
  display: inline-block;
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--accent);
  background: rgba(52, 211, 153, 0.12);
  border: 1px solid rgba(52, 211, 153, 0.35);
  padding: 4px 10px;
  border-radius: 999px;
  margin-bottom: 10px;
}
.hero h1 { margin: 0 0 8px; font-size: 1.75rem; font-weight: 700; }
.hero-sub { margin: 0; color: var(--muted); font-size: 0.95rem; }

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.card-title {
  margin: 0 0 12px;
  font-size: 0.95rem;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.02em;
}
.info-card .muted { margin: 0; }

.mode-list { display: flex; flex-direction: column; gap: 10px; }
.mode-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 14px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.mode-btn:hover { border-color: var(--primary); }
.mode-btn.selected {
  border-color: var(--primary);
  background: rgba(91, 140, 255, 0.12);
}
.mode-icon { font-size: 1.4rem; width: 2rem; text-align: center; }
.mode-text { display: flex; flex-direction: column; gap: 2px; }
.mode-text strong { font-size: 1rem; }
.mode-text small { color: var(--muted); font-size: 0.82rem; }

.section-pick {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
}
.section-pick.hidden { display: none; }
.section-pick label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.92rem;
  cursor: pointer;
  color: var(--text);
}

.btn {
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 0.95rem;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}
.btn:hover { border-color: var(--primary-hover); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary {
  background: linear-gradient(135deg, #4a7fff, #3b6ef5);
  border-color: transparent;
  color: #fff;
  font-weight: 600;
}
.btn.primary:hover { filter: brightness(1.08); }
.btn.accent {
  background: linear-gradient(135deg, #2dd4a0, #10b981);
  border-color: transparent;
  color: #062218;
  font-weight: 700;
}
.btn.ghost { background: transparent; }
.btn.sm { padding: 6px 10px; font-size: 0.85rem; }
.btn-lg {
  display: block;
  width: 100%;
  padding: 14px 18px;
  font-size: 1.05rem;
  margin-top: 8px;
}
.btn.hidden { display: none; }

.footnote {
  text-align: center;
  color: var(--muted);
  font-size: 0.78rem;
  margin: 18px 0 0;
  line-height: 1.45;
}
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

/* Exam */
.exam-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}
.exam-meta {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  flex: 1;
  min-width: 0;
}
#exam-label { font-size: 0.88rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.timer {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--warn);
  font-size: 1.05rem;
}
.timer.urgent { color: var(--danger); animation: pulse 1s infinite; }
@keyframes pulse {
  50% { opacity: 0.65; }
}
.timer.hidden { display: none; }
.progress-text { font-size: 0.88rem; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 3.5rem; text-align: right; }

.progress-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin-bottom: 12px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  transition: width 0.25s ease;
}

.nav-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}
.nav-dot {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  font-family: inherit;
}
.nav-dot.current { border-color: var(--primary); color: #fff; background: rgba(91,140,255,0.25); }
.nav-dot.answered { background: rgba(52,211,153,0.15); border-color: rgba(52,211,153,0.45); color: var(--accent); }
.nav-dot.flagged { box-shadow: inset 0 -3px 0 var(--flag); }

.q-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.tag {
  font-size: 0.75rem;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(91,140,255,0.15);
  color: var(--primary-hover);
  border: 1px solid rgba(91,140,255,0.3);
}
.flag-btn.flagged { color: var(--flag); border-color: var(--flag); }

.q-stem {
  font-size: 1.05rem;
  margin-bottom: 16px;
  line-height: 1.65;
  word-break: break-word;
}
.q-stem .katex { font-size: 1.05em; }

.choices { display: flex; flex-direction: column; gap: 8px; }
.choice {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.98rem;
  transition: border-color 0.15s, background 0.15s;
}
.choice:hover { border-color: var(--primary); }
.choice.selected {
  border-color: var(--primary);
  background: rgba(91, 140, 255, 0.14);
}
.choice-letter {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border);
}
.choice.selected .choice-letter {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.choice-body { flex: 1; padding-top: 2px; min-width: 0; }

.exam-actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}
.exam-actions .btn { flex: 1; }

/* Answer sheet */
.sheet-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
  gap: 8px;
}
.sheet-cell {
  aspect-ratio: 1;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  font-family: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 4px;
}
.sheet-cell .ans { font-size: 0.7rem; color: var(--accent); }
.sheet-cell.answered { border-color: rgba(52,211,153,0.5); background: rgba(52,211,153,0.1); }
.sheet-cell.flagged { box-shadow: inset 0 -3px 0 var(--flag); }
.sheet-legend { display: flex; gap: 14px; align-items: center; margin: 14px 0 0; flex-wrap: wrap; }
.dot {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 3px;
  margin-right: 4px;
  vertical-align: middle;
}
.dot.answered { background: var(--accent); }
.dot.flagged { background: var(--flag); }
.dot.blank { background: var(--border); }

/* Result */
.score-card { text-align: center; }
.score-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}
.score-item {
  padding: 12px 8px;
  border-radius: 12px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
}
.score-item .num { display: block; font-size: 1.6rem; font-weight: 800; }
.score-item .lbl { font-size: 0.8rem; color: var(--muted); }
.score-item.ok .num { color: var(--accent); }
.score-item.bad .num { color: var(--danger); }
.score-item.blank .num { color: var(--warn); }
.approx-score {
  font-size: 1.15rem;
  margin-bottom: 8px;
}
.approx-score strong {
  font-size: 1.8rem;
  margin: 0 6px;
  color: var(--primary-hover);
}

.review-list { display: flex; flex-direction: column; gap: 12px; }
.review-item {
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
}
.review-item.correct { border-color: rgba(52,211,153,0.4); }
.review-item.wrong { border-color: rgba(248,113,113,0.4); }
.review-item.blank-item { border-color: rgba(251,191,36,0.35); }
.review-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-size: 0.85rem;
  color: var(--muted);
}
.review-stem { margin-bottom: 8px; font-size: 0.95rem; }
.review-ans { font-size: 0.88rem; margin-bottom: 6px; }
.review-ans .ok { color: var(--accent); }
.review-ans .bad { color: var(--danger); }
/* review-explain redefined below */

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  background: #243049;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.9rem;
  z-index: 100;
  box-shadow: var(--shadow);
  max-width: 90vw;
}
.toast.hidden { display: none; }

@media (max-width: 480px) {
  .hero h1 { font-size: 1.45rem; }
  .nav-dot { width: 26px; height: 26px; }
  .choice { padding: 10px 12px; }
}

.pick-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: center;
  margin-bottom: 10px;
}
.pick-row:last-child { margin-bottom: 0; }
.pick-label {
  font-size: 0.8rem;
  color: var(--muted);
  min-width: 2.5em;
}
.review-explain {
  font-size: 0.9rem;
  color: var(--text);
  padding-top: 10px;
  border-top: 1px dashed var(--border);
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
}
.explain-label {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--accent);
  margin-bottom: 6px;
  text-transform: none;
}
.explain-body {
  color: #c5d0e2;
}
