:root {
  --paper: #f3f5ef;
  --surface: #ffffff;
  --ink: #17221d;
  --muted: #68736d;
  --line: #d9dfd8;
  --green: #176b4d;
  --green-soft: #e4f0e9;
  --coral: #c8513d;
  --coral-soft: #f9e8e3;
  --gold: #b67a18;
  --gold-soft: #f7efd9;
  --shadow: 0 18px 50px rgba(30, 47, 38, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(rgba(23, 107, 77, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(23, 107, 77, 0.035) 1px, transparent 1px),
    var(--paper);
  background-size: 28px 28px;
  font-family: "Songti SC", "STSong", "Noto Serif SC", serif;
  min-height: 100vh;
}

button, input { font: inherit; }
button { color: inherit; }

.site-header {
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 max(24px, calc((100vw - 1180px) / 2));
  background: rgba(243, 245, 239, 0.94);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(14px);
}

.brand {
  border: 0;
  background: transparent;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0;
  cursor: pointer;
  text-align: left;
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  color: white;
  background: var(--green);
  font-size: 20px;
  font-weight: 800;
}

.brand strong, .brand small { display: block; }
.brand strong { font-size: 18px; }
.brand small { color: var(--muted); margin-top: 1px; font-size: 11px; }

.header-actions { display: flex; gap: 8px; }
.nav-button {
  border: 1px solid var(--line);
  background: var(--surface);
  min-height: 38px;
  padding: 7px 13px;
  cursor: pointer;
}
.nav-button b {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  margin-left: 4px;
  color: var(--coral);
  background: var(--coral-soft);
  font-size: 12px;
}

#app { min-height: calc(100vh - 72px); }
.page { max-width: 1180px; margin: 0 auto; padding: 42px 24px 72px; }

.page-heading { margin-bottom: 30px; }
.eyebrow { color: var(--green); font-weight: 700; font-size: 13px; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: clamp(30px, 5vw, 48px); margin: 8px 0 10px; line-height: 1.12; }
h2 { font-size: 23px; }
h3 { font-size: 17px; }
.page-heading p, .section-note { color: var(--muted); line-height: 1.7; }

.home-grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 28px; align-items: start; }
.builder, .side-panel, .question-shell, .result-summary, .wrong-toolbar {
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.builder { padding: 30px; }
.side-panel { padding: 24px; position: sticky; top: 96px; }

.field-group + .field-group { margin-top: 30px; padding-top: 26px; border-top: 1px solid var(--line); }
.field-title { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 14px; }
.field-title h2 { margin: 0; font-size: 18px; }
.field-title span { color: var(--muted); font-size: 13px; }

.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; border: 1px solid var(--line); }
.segment { border: 0; border-right: 1px solid var(--line); padding: 12px 10px; background: #fafbf8; cursor: pointer; }
.segment:last-child { border-right: 0; }
.segment.active { color: white; background: var(--green); }

.chapter-actions { display: flex; gap: 8px; margin-bottom: 11px; }
.text-button { border: 0; background: transparent; color: var(--green); padding: 2px; cursor: pointer; font-weight: 700; }
.chapter-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.check-tile {
  min-height: 50px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: #fbfcfa;
  cursor: pointer;
}
.check-tile:has(input:checked) { border-color: var(--green); background: var(--green-soft); }
.check-tile input { accent-color: var(--green); width: 17px; height: 17px; }
.check-tile span { min-width: 0; line-height: 1.35; }
.check-tile small { display: block; color: var(--muted); margin-top: 3px; }

.mode-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.mode-tile { display: block; border: 1px solid var(--line); padding: 15px; cursor: pointer; min-height: 112px; }
.mode-tile:has(input:checked) { border-color: var(--green); background: var(--green-soft); }
.mode-tile input { position: absolute; opacity: 0; }
.mode-tile strong, .mode-tile small { display: block; }
.mode-tile strong { margin-bottom: 7px; }
.mode-tile small { color: var(--muted); line-height: 1.55; }

.start-row { margin-top: 28px; display: flex; align-items: center; gap: 16px; }
.form-message { color: var(--coral); font-size: 13px; margin: 0; }
.button {
  border: 1px solid var(--line);
  background: var(--surface);
  min-height: 44px;
  padding: 10px 18px;
  cursor: pointer;
  font-weight: 700;
}
.button.primary { border-color: var(--green); color: white; background: var(--green); }
.button.danger { border-color: #e1b8ae; color: var(--coral); background: var(--coral-soft); }
.button:disabled { opacity: 0.45; cursor: not-allowed; }
.button.wide { min-width: 160px; }

.resume-box { border-left: 4px solid var(--gold); background: var(--gold-soft); padding: 16px; margin-bottom: 24px; }
.resume-box strong { display: block; margin-bottom: 6px; }
.resume-box p { color: #775817; font-size: 13px; line-height: 1.5; }
.resume-actions { display: flex; gap: 8px; }

.stat-line { display: flex; justify-content: space-between; padding: 13px 0; border-bottom: 1px solid var(--line); }
.stat-line span { color: var(--muted); }
.stat-line strong { font-size: 20px; }
.history-list { margin-top: 22px; }
.history-item { padding: 12px 0; border-bottom: 1px solid var(--line); }
.history-item strong, .history-item small { display: block; }
.history-item small { color: var(--muted); margin-top: 5px; }

.quiz-page { max-width: 900px; }
.quiz-bar { margin-bottom: 18px; }
.quiz-meta { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 10px; }
.quiz-meta span { color: var(--muted); font-size: 14px; }
.mode-label { color: var(--green) !important; font-weight: 700; }
.progress-track { height: 5px; background: #dfe5de; }
.progress-fill { height: 100%; background: var(--green); transition: width 220ms ease; }

.question-shell { padding: 34px; }
.question-kicker { display: flex; gap: 8px; color: var(--muted); font-size: 13px; margin-bottom: 16px; }
.type-tag { color: var(--green); background: var(--green-soft); padding: 2px 7px; font-weight: 700; }
.question-title { font-size: 22px; line-height: 1.7; margin-bottom: 24px; overflow-wrap: anywhere; }
.options { display: grid; gap: 11px; }
.option {
  display: grid;
  grid-template-columns: 18px 24px minmax(0, 1fr);
  align-items: start;
  gap: 10px;
  border: 1px solid var(--line);
  padding: 14px 16px;
  background: #fcfdfb;
  cursor: pointer;
  line-height: 1.65;
}
.option:hover { border-color: #9eaea4; }
.option:has(input:checked) { border-color: var(--green); background: var(--green-soft); }
.option input { margin: 5px 0 0; accent-color: var(--green); }
.option-letter { font-weight: 800; }
.option.correct { border-color: var(--green); background: var(--green-soft); }
.option.wrong { border-color: var(--coral); background: var(--coral-soft); }

.feedback { margin-top: 22px; padding: 20px; border-left: 4px solid var(--green); background: var(--green-soft); }
.feedback.incorrect { border-color: var(--coral); background: var(--coral-soft); }
.feedback h3 { margin-bottom: 8px; }
.feedback p { margin-bottom: 6px; line-height: 1.65; }
.feedback p:last-child { margin-bottom: 0; }

.quiz-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 18px; }
.action-group { display: flex; gap: 10px; }
.inline-error { color: var(--coral); font-size: 13px; min-height: 20px; margin-top: 12px; }

.result-page { max-width: 1000px; }
.result-summary { display: grid; grid-template-columns: 1fr repeat(3, 150px); margin-bottom: 22px; }
.score-lead { padding: 28px; }
.score-lead h1 { font-size: 32px; }
.score-stat { border-left: 1px solid var(--line); display: grid; place-items: center; text-align: center; padding: 20px 10px; }
.score-stat strong { display: block; font-size: 30px; }
.score-stat span { color: var(--muted); font-size: 13px; }
.result-toolbar { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.result-list { display: grid; gap: 12px; }
.result-item { background: var(--surface); border: 1px solid var(--line); padding: 22px; }
.result-item.correct { border-left: 4px solid var(--green); }
.result-item.wrong { border-left: 4px solid var(--coral); }
.result-item.unanswered { border-left: 4px solid var(--gold); }
.result-item h3 { line-height: 1.55; }
.result-item p { line-height: 1.6; color: var(--muted); }
.result-item p:last-child { margin-bottom: 0; }

.wrong-page { max-width: 1080px; }
.wrong-toolbar { padding: 20px; margin-bottom: 20px; display: flex; align-items: end; gap: 14px; flex-wrap: wrap; }
.filter-field { min-width: 170px; flex: 1; }
.filter-field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
select { width: 100%; height: 42px; border: 1px solid var(--line); background: white; padding: 0 10px; color: var(--ink); }
.wrong-list { display: grid; gap: 10px; }
.wrong-item { display: grid; grid-template-columns: 1fr auto; gap: 16px; background: white; border: 1px solid var(--line); padding: 18px; }
.wrong-item h3 { font-size: 16px; line-height: 1.55; margin-bottom: 7px; }
.wrong-item p { color: var(--muted); margin: 0; font-size: 13px; }

.stats-page { max-width: 1080px; }
.data-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin-bottom: 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.data-summary div { padding: 22px; border-right: 1px solid var(--line); }
.data-summary div:last-child { border-right: 0; }
.data-summary span, .data-summary strong { display: block; }
.data-summary span { color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.data-summary strong { font-size: 28px; }
.stats-list { display: grid; gap: 9px; }
.stats-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  gap: 18px;
  align-items: center;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--line);
}
.stats-question span { color: var(--muted); font-size: 12px; }
.stats-question h3 { margin: 6px 0 0; line-height: 1.55; }
.stats-numbers { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; text-align: center; }
.stats-numbers span { color: var(--muted); font-size: 12px; }
.stats-numbers b { display: block; color: var(--ink); font-size: 20px; margin-bottom: 3px; }

.empty-state { max-width: 620px; margin: 80px auto; text-align: center; padding: 40px; }
.empty-symbol { display: block; font-size: 56px; color: var(--green); margin-bottom: 14px; }
.empty-state p { color: var(--muted); line-height: 1.7; }

@media (max-width: 820px) {
  .home-grid { grid-template-columns: 1fr; }
  .side-panel { position: static; }
  .mode-grid { grid-template-columns: 1fr; }
  .mode-tile { min-height: auto; }
  .result-summary { grid-template-columns: repeat(3, 1fr); }
  .score-lead { grid-column: 1 / -1; }
  .score-stat { border-left: 0; border-top: 1px solid var(--line); }
}

@media (max-width: 560px) {
  .site-header { height: 62px; padding: 0 15px; }
  .brand small { display: none; }
  .nav-button { padding: 6px 9px; }
  .nav-button span { display: none; }
  #app { min-height: calc(100vh - 62px); }
  .page { padding: 28px 15px 54px; }
  h1 { font-size: 31px; }
  .builder, .question-shell { padding: 21px 17px; }
  .chapter-grid { grid-template-columns: 1fr; }
  .segmented { grid-auto-flow: row; grid-template-columns: repeat(2, 1fr); }
  .segment { border-bottom: 1px solid var(--line); }
  .start-row, .quiz-actions { align-items: stretch; flex-direction: column; }
  .button.wide { width: 100%; }
  .action-group { display: grid; grid-template-columns: 1fr 1fr; width: 100%; }
  .question-title { font-size: 19px; }
  .question-shell { box-shadow: none; }
  .result-summary { grid-template-columns: 1fr; }
  .score-lead { grid-column: auto; }
  .score-stat { display: flex; justify-content: space-between; text-align: left; padding: 14px 18px; }
  .score-stat strong { font-size: 22px; }
  .result-toolbar .button { flex: 1; }
  .wrong-toolbar { align-items: stretch; }
  .wrong-item { grid-template-columns: 1fr; }
  .data-summary { grid-template-columns: 1fr; }
  .data-summary div { display: flex; align-items: center; justify-content: space-between; border-right: 0; border-bottom: 1px solid var(--line); padding: 15px 17px; }
  .data-summary div:last-child { border-bottom: 0; }
  .data-summary span { margin: 0; }
  .data-summary strong { font-size: 22px; }
  .stats-item { grid-template-columns: 1fr; padding: 16px; }
  .stats-numbers { text-align: left; }
}
