:root {
  color-scheme: light;
  --bg-start: #eef3ea;
  --bg: #edf1e8;
  --bg-end: #e8eee4;
  --surface: #fbfaf2;
  --surface-2: #eef1e6;
  --surface-elevated: #fffdf6;
  --text: #21302a;
  --heading: #182820;
  --muted: #6b766d;
  --line: #d7ddcf;
  --primary: #2f6f5e;
  --primary-strong: #24584b;
  --primary-text: #fff;
  --primary-soft: #ddece4;
  --danger: #9d3d35;
  --danger-soft: #f5e3de;
  --ok: #2f6a45;
  --ok-soft: #e2efe4;
  --warn: #725d20;
  --warn-soft: #f5edcf;
  --header-bg: rgba(237, 241, 232, 0.96);
  --note-text: #3f2b00;
  --body-size: 16px;
  --question-size: 22px;
  --option-size: 16px;
  --shadow: 0 10px 24px rgba(54, 68, 52, 0.09);
}

body[data-theme="warm"] {
  color-scheme: dark;
  --bg-start: #242820;
  --bg: #20251f;
  --bg-end: #1b211c;
  --surface: #2c3129;
  --surface-2: #363d32;
  --surface-elevated: #30362d;
  --text: #f0eadb;
  --heading: #fff7e6;
  --muted: #c9c1ac;
  --line: #535b49;
  --primary: #d2a14f;
  --primary-strong: #bd8a37;
  --primary-text: #23190d;
  --primary-soft: #4b442f;
  --danger: #ffb1a7;
  --danger-soft: #4e2e2b;
  --ok: #a8d9ac;
  --ok-soft: #2f4734;
  --warn: #ffe3a3;
  --warn-soft: #4d4025;
  --header-bg: rgba(32, 37, 31, 0.96);
  --note-text: #ffe3a3;
  --shadow: 0 10px 24px rgba(0, 0, 0, 0.22);
}

body[data-theme="contrast"] {
  --bg-start: #f4f0d9;
  --bg: #f6f3df;
  --bg-end: #eee8c9;
  --surface: #fffbe9;
  --surface-2: #eee6bd;
  --surface-elevated: #fffdf0;
  --text: #101610;
  --heading: #09130d;
  --muted: #4d564d;
  --line: #9f9467;
  --primary: #1d6757;
  --primary-strong: #124b3e;
  --primary-soft: #cce5d9;
  --danger: #8b1f18;
  --danger-soft: #f3d1cb;
  --ok: #17572f;
  --ok-soft: #d5ead7;
  --warn: #594500;
  --warn-soft: #f2e4a9;
  --header-bg: rgba(246, 243, 223, 0.97);
  --shadow: none;
}

body[data-font="normal"] {
  --body-size: 16px;
  --question-size: 20px;
  --option-size: 16px;
}

body[data-font="large"] {
  --body-size: 17px;
  --question-size: 22px;
  --option-size: 17px;
}

body[data-font="xlarge"] {
  --body-size: 18.5px;
  --question-size: 24px;
  --option-size: 18.5px;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: linear-gradient(180deg, var(--bg-start) 0%, var(--bg) 46%, var(--bg-end) 100%);
  color: var(--text);
  font-size: var(--body-size);
  font-family:
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    "Microsoft YaHei",
    sans-serif;
  letter-spacing: 0;
  line-height: 1.55;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.app-shell {
  width: min(980px, 100%);
  margin: 0 auto;
  padding: 18px 14px 30px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.title-block h1 {
  margin: 0;
  font-size: 34px;
  font-weight: 760;
  color: var(--heading);
}

.title-block p {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.meta-pill,
.type-pill,
.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.status-pill.pass {
  background: var(--ok-soft);
  color: var(--ok);
}

.status-pill.fail {
  background: var(--danger-soft);
  color: var(--danger);
}

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

.grid.stats {
  grid-template-columns: repeat(4, 1fr);
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 16px;
}

.stat {
  min-height: 86px;
}

.stat strong {
  display: block;
  font-size: 26px;
  line-height: 1.1;
}

.stat span {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 16px 0;
}

.actions.compact {
  margin: 10px 0 0;
}

.comfort-panel {
  display: grid;
  gap: 14px;
  margin-bottom: 14px;
}

.comfort-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.comfort-title .section-title {
  margin: 0;
}

.comfort-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.comfort-group {
  display: grid;
  gap: 8px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.choice-btn {
  min-height: 36px;
  border-radius: 6px;
  padding: 7px 10px;
  background: transparent;
  color: var(--text);
  font-weight: 680;
}

.choice-btn.active {
  background: var(--primary);
  color: var(--primary-text);
}

.btn {
  min-height: 44px;
  border-radius: 8px;
  padding: 10px 16px;
  background: var(--surface-2);
  color: var(--text);
  font-weight: 680;
}

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

.btn.primary:hover {
  background: var(--primary-strong);
}

.btn.ghost {
  background: transparent;
  border: 1px solid var(--line);
}

.btn.danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.sync-panel {
  margin-bottom: 16px;
}

.sync-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.sync-input {
  min-height: 44px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--surface-elevated);
  color: var(--text);
}

.gate-shell {
  min-height: calc(100vh - 48px);
  display: grid;
  place-items: center;
}

.gate-card {
  width: min(560px, 100%);
  display: grid;
  gap: 18px;
}

.section-title {
  margin: 0 0 10px;
  font-size: 17px;
}

.history-list,
.wrong-list {
  display: grid;
  gap: 10px;
}

.date-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.date-card {
  display: grid;
  gap: 12px;
}

.date-card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.date-card-foot strong {
  font-size: 28px;
}

.history-item,
.wrong-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface-elevated);
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.history-item strong {
  display: block;
}

.history-item span,
.muted {
  color: var(--muted);
}

.exam-header {
  position: sticky;
  top: 0;
  z-index: 5;
  margin: -18px -14px 14px;
  padding: 12px 14px;
  background: var(--header-bg);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.exam-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.progress {
  height: 9px;
  margin-top: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-2);
}

.progress > span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--primary);
  transition: width 180ms ease;
}

.question-panel {
  min-height: 420px;
}

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

.question-title {
  margin: 0 0 16px;
  font-size: var(--question-size);
  line-height: 1.65;
  font-weight: 720;
}

.options {
  display: grid;
  gap: 10px;
}

.option {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 10px;
  align-items: center;
  width: 100%;
  min-height: 54px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-elevated);
  color: var(--text);
  font-size: var(--option-size);
  text-align: left;
}

.option:hover {
  border-color: var(--primary);
}

.option.selected {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.option-letter {
  display: inline-grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 999px;
  background: var(--surface-2);
  font-weight: 760;
}

.option.selected .option-letter {
  background: var(--primary);
  color: var(--primary-text);
}

.answer-line {
  overflow-wrap: anywhere;
}

.question-actions {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 16px;
}

.submit-panel {
  text-align: center;
}

.submit-panel h2,
.result-head h2 {
  margin: 0 0 8px;
  font-size: clamp(24px, 6vw, 42px);
}

.score {
  font-size: clamp(46px, 15vw, 82px);
  line-height: 1;
  font-weight: 820;
}

.score small {
  font-size: 22px;
  color: var(--muted);
}

.result-head {
  display: grid;
  gap: 12px;
  align-items: center;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin: 14px 0;
}

.wrong-item h3 {
  margin: 0 0 8px;
  font-size: 16px;
  line-height: 1.35;
}

.wrong-stem {
  margin: 0;
  font-weight: 720;
  line-height: 1.55;
}

.review-body {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  color: var(--text);
}

.review-row {
  padding: 10px;
  border-radius: 8px;
  background: var(--surface-2);
  line-height: 1.55;
}

.review-row.bad {
  background: var(--danger-soft);
}

.review-row.good {
  background: var(--ok-soft);
}

.review-row.note {
  background: var(--warn-soft);
  color: var(--note-text);
}

.empty {
  padding: 28px 16px;
  color: var(--muted);
  text-align: center;
}

.footer-note {
  margin-top: 14px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

@media (max-width: 760px) {
  .app-shell {
    padding-top: 14px;
  }

  .topbar,
  .history-item,
  .exam-header-row,
  .question-meta {
    align-items: stretch;
    flex-direction: column;
  }

  .grid.stats,
  .result-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .actions,
  .question-actions,
  .sync-row {
    display: grid;
    grid-template-columns: 1fr;
  }

  .comfort-title,
  .comfort-grid {
    display: grid;
    grid-template-columns: 1fr;
  }

  .date-grid {
    grid-template-columns: 1fr;
  }

  .btn {
    width: 100%;
  }

  .panel {
    padding: 14px;
  }

  .title-block h1 {
    font-size: 28px;
  }

  .question-panel {
    min-height: 360px;
  }
}

@media (max-width: 420px) {
  .grid.stats,
  .result-grid {
    grid-template-columns: 1fr;
  }

  .option {
    grid-template-columns: 30px 1fr;
  }

  .option-letter {
    width: 30px;
    height: 30px;
  }
}
