:root {
  color-scheme: light;
  --ink: #18202f;
  --muted: #697386;
  --paper: #f6f7f9;
  --surface: #ffffff;
  --line: #dce3ee;
  --primary: #245d5f;
  --primary-ink: #ffffff;
  --accent: #b84a2f;
  --blue: #315f9e;
  --ok: #237a45;
  --warn-bg: #fff3ea;
  --ok-bg: #eef8f1;
  --select-bg: #e9f2f2;
  --shadow: 0 18px 42px rgba(24, 32, 47, 0.11);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  background: var(--paper);
  color: var(--ink);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(circle at top left, rgba(36, 93, 95, 0.16), transparent 28rem),
    linear-gradient(180deg, #fdfefe 0%, var(--paper) 28rem);
}

button { font: inherit; }

svg {
  width: 1.05rem;
  height: 1.05rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: 0 0 auto;
}

.shell {
  width: min(100%, 780px);
  margin: 0 auto;
  padding: 18px 14px 34px;
}

.hero {
  min-height: 132px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 0 16px;
}

h1, h2, p { margin: 0; }

h1 {
  font-size: 2.55rem;
  line-height: 1.05;
  letter-spacing: 0;
}

h2 {
  font-size: 1.08rem;
  line-height: 1.35;
  letter-spacing: 0;
}

.eyebrow {
  color: var(--primary);
  font-size: 0.86rem;
  font-weight: 800;
  margin-bottom: 8px;
}

.score-pill {
  min-width: 92px;
  min-height: 72px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  display: grid;
  place-items: center;
  box-shadow: var(--shadow);
}

.score-pill span {
  font-size: 1.8rem;
  font-weight: 850;
}

.score-pill small {
  color: var(--muted);
  margin-top: -14px;
}

.notice {
  display: grid;
  gap: 4px;
  padding: 12px 14px;
  margin-bottom: 14px;
  border: 1px solid rgba(184, 74, 47, 0.26);
  border-radius: 8px;
  background: var(--warn-bg);
  color: #5b392c;
  line-height: 1.55;
}

.notice span { color: #765345; }

.quick-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.primary, .secondary, .ghost, .icon-text, .clear-button {
  min-height: 48px;
  border-radius: 8px;
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  font-weight: 780;
  text-decoration: none;
}

.primary {
  color: var(--primary-ink);
  background: var(--primary);
}

.secondary, .ghost, .icon-text {
  color: var(--ink);
  background: var(--surface);
  border-color: var(--line);
}

.secondary b { color: var(--accent); }
button:disabled { opacity: 0.45; }

.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin: 12px 0 18px;
}

.stats-row div {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 10px;
}

.stats-row strong, .stats-row span { display: block; }
.stats-row strong { font-size: 1.32rem; }

.stats-row span, .chapter-card p, .last-attempt, .complete p {
  color: var(--muted);
  font-size: 0.94rem;
  line-height: 1.55;
}

.chapter-list { display: grid; gap: 10px; }

.chapter-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
}

.chapter-card .progress { grid-column: 1 / -1; }

.progress {
  height: 8px;
  border-radius: 999px;
  overflow: hidden;
  background: #e7ecf3;
}

.progress span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--blue));
}

.clear-button {
  width: 100%;
  margin-top: 18px;
  color: var(--muted);
  background: transparent;
  border-color: var(--line);
}

.quiz-shell {
  min-height: 100vh;
  display: grid;
  align-content: start;
  gap: 14px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px 0;
  background: rgba(246, 247, 249, 0.92);
  backdrop-filter: blur(12px);
}

.topbar span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 850;
  text-align: center;
}

.topbar small {
  color: var(--muted);
  font-weight: 750;
}

.question-card, .result, .complete, .loading, .error {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  box-shadow: 0 12px 30px rgba(24, 32, 47, 0.08);
}

.question-meta {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.type-chip, .confidence {
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 0.78rem;
  font-weight: 850;
  white-space: nowrap;
}

.type-chip {
  color: var(--blue);
  background: #edf3ff;
}

.stem {
  font-size: 1.05rem;
  line-height: 1.75;
  white-space: normal;
  overflow-wrap: anywhere;
}

.options {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.option {
  width: 100%;
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
  color: var(--ink);
  padding: 12px;
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 10px;
  text-align: left;
  align-items: start;
}

.option span {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #e9f2f2;
  color: var(--primary);
  font-weight: 900;
}

.option p {
  font-size: 1rem;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.option.selected {
  border-color: rgba(49, 95, 158, 0.48);
  background: #f0f5ff;
}

.option.selected span {
  color: #ffffff;
  background: var(--blue);
}

.option.correct {
  border-color: rgba(35, 122, 69, 0.45);
  background: var(--ok-bg);
}

.option.correct span {
  color: #ffffff;
  background: var(--ok);
}

.option.wrong {
  border-color: rgba(184, 74, 47, 0.45);
  background: var(--warn-bg);
}

.option.wrong span {
  color: #ffffff;
  background: var(--accent);
}

.submit { width: 100%; margin-top: 14px; }

.result {
  display: grid;
  gap: 12px;
}

.result h2 {
  display: flex;
  align-items: center;
  gap: 8px;
}

.result.right h2 { color: var(--ok); }
.result.miss h2 { color: var(--accent); }

.explanation {
  padding: 14px;
  border-radius: 8px;
  background: #f5f7fa;
  color: #2f3848;
  line-height: 1.75;
  overflow-wrap: anywhere;
}

.explanation small {
  display: block;
  margin-top: 10px;
  color: var(--muted);
}

.confidence {
  display: inline-block;
  margin-bottom: 10px;
}

.confidence.high {
  color: #1f6139;
  background: #e7f6ed;
}

.confidence.medium, .confidence.review {
  color: #7a3e20;
  background: #fff0df;
}

.last-attempt { padding: 0 4px; }

.complete {
  margin-top: 24px;
  display: grid;
  gap: 12px;
}

.loading, .error { margin-top: 24px; }

@media (max-width: 430px) {
  .shell { padding: 14px 12px 28px; }
  h1 { font-size: 2.2rem; }
  .quick-grid { grid-template-columns: 1fr; }
  .chapter-card { grid-template-columns: 1fr; }
  .chapter-card .ghost { width: 100%; }
  .stats-row { gap: 8px; }
  .stats-row div { padding: 12px 7px; }
  .stats-row strong { font-size: 1.15rem; }
  .stats-row span { font-size: 0.82rem; }
  .topbar { grid-template-columns: 44px 1fr 42px; }
  .icon-text { min-width: 44px; padding: 0; }
  .icon-text svg + * { display: none; }
  .question-card, .result, .complete, .loading, .error { padding: 16px; }
}
