:root {
  color-scheme: light;
  --bg: #f6f7fb;
  --text: #182033;
  --muted: #667085;
  --line: #d9dee8;
  --panel: #ffffff;
  --accent: #1769e0;
  --accent-2: #0f9f88;
  --danger: #d33f49;
  --warn: #a66b00;
  --shadow: 0 18px 45px rgba(26, 37, 61, 0.1);
}

body.theme-night .toolbar select,
body.theme-night .toolbar input,
body.theme-night .self-answer,
body.theme-night button {
  background: #111821;
  color: var(--text);
}

body.theme-night .segmented {
  background: #101720;
}

body.theme-night .segmented .is-active,
body.theme-night .filter-toggle.is-active {
  background: #233047;
}

body.theme-night .option strong {
  background: #233047;
}

body.theme-night .option.is-right {
  background: #12352f;
}

body.theme-night .option.is-wrong {
  background: #3b1d23;
}

body.theme-night .answer-box {
  background: #102b28;
}

body.theme-night .image-strip figure {
  background: #111821;
}

body.theme-night .list-item.is-active {
  background: #17263a;
}

body.theme-night {
  color-scheme: dark;
  --bg: #0f141b;
  --text: #e6edf7;
  --muted: #9aa7ba;
  --line: #2d3848;
  --panel: #171e28;
  --accent: #7aa7ff;
  --accent-2: #55d6bd;
  --danger: #ff7681;
  --warn: #ffd166;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.26);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
}

.app-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 20px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0 18px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent-2);
  font-weight: 700;
}

h1 {
  margin: 0;
  font-size: clamp(26px, 4vw, 42px);
  letter-spacing: 0;
}

.score-panel {
  display: grid;
  min-width: 94px;
  padding: 14px;
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  text-align: center;
}

.score-panel span {
  font-size: 26px;
  font-weight: 800;
  color: var(--accent);
}

.theme-switch {
  display: inline-grid;
  grid-template-columns: 48px auto;
  gap: 8px;
  align-items: center;
  min-height: 42px;
  border-color: var(--line);
  padding: 6px 10px;
  font-weight: 800;
}

.switch-track {
  position: relative;
  width: 48px;
  height: 26px;
  border-radius: 999px;
  background: #d8e0ec;
  transition: background 0.2s ease;
}

.switch-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 2px 8px rgba(18, 28, 45, 0.24);
  transition: transform 0.2s ease;
}

.switch-hint {
  white-space: nowrap;
  color: var(--muted);
  font-size: 13px;
}

.theme-switch.is-night .switch-track {
  background: var(--accent);
}

.theme-switch.is-night .switch-thumb {
  transform: translateX(22px);
}

.toolbar {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: end;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.filter-toggle {
  display: none;
  font-weight: 800;
}

.filter-toggle.is-active {
  border-color: var(--accent);
  color: var(--accent);
  background: #eef6ff;
}

.filter-panel {
  display: grid;
  grid-template-columns: 160px 140px minmax(220px, 1fr);
  gap: 12px;
  align-items: end;
}

.toolbar label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.toolbar select,
.toolbar input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #fff;
  color: var(--text);
}

.segmented {
  display: grid;
  grid-auto-flow: column;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef2f8;
}

.segmented button {
  min-width: 70px;
  border: 0;
  background: transparent;
  font-weight: 700;
}

.segmented .is-active {
  background: #fff;
  color: var(--accent);
  box-shadow: 0 5px 16px rgba(23, 105, 224, 0.14);
}

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

.stats-grid article {
  display: grid;
  gap: 3px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.stats-grid strong {
  font-size: 25px;
}

.stats-grid span {
  color: var(--muted);
}

.quiz-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 14px;
}

.question-card,
.side-list,
.raw-view {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.question-card {
  min-height: 520px;
  padding: 22px;
}

.question-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-weight: 700;
}

.question-card h2 {
  margin: 18px 0;
  font-size: 22px;
  line-height: 1.65;
  letter-spacing: 0;
  white-space: pre-line;
}

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

.image-strip {
  display: grid;
  gap: 12px;
  margin: 12px 0 16px;
}

.image-strip[hidden] {
  display: none;
}

.image-strip figure {
  margin: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcff;
  padding: 10px;
}

.image-strip img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0 auto;
}

.option {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 10px;
  align-items: center;
  min-height: 54px;
  padding: 10px 12px;
  text-align: left;
}

.option strong {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #eaf2ff;
  color: var(--accent);
}

.option.is-right {
  border-color: var(--accent-2);
  background: #effbf8;
}

.option.is-wrong {
  border-color: var(--danger);
  background: #fff2f3;
}

.self-answer {
  display: none;
  width: 100%;
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  resize: vertical;
}

.self-answer.is-visible {
  display: block;
}

.answer-box {
  margin-top: 14px;
  padding: 14px;
  border-left: 4px solid var(--accent-2);
  border-radius: 8px;
  background: #f1fbf8;
  line-height: 1.7;
  white-space: pre-wrap;
}

.actions {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 18px;
}

.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.side-list {
  overflow: hidden;
}

.side-title {
  display: flex;
  justify-content: space-between;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

#questionList {
  display: grid;
  max-height: 620px;
  overflow: auto;
}

.list-item {
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  padding: 11px 14px;
  text-align: left;
  line-height: 1.45;
}

.list-item.is-active {
  background: #eef6ff;
  color: var(--accent);
  font-weight: 700;
}

.raw-view {
  padding: 18px;
}

.raw-chapter {
  margin-bottom: 22px;
}

.raw-chapter h2 {
  margin: 0 0 10px;
  font-size: 20px;
}

.raw-item {
  padding: 10px 0;
  border-bottom: 1px dashed var(--line);
  line-height: 1.7;
}

.raw-item p {
  margin: 0;
}

.raw-images {
  margin-bottom: 0;
}

.raw-item.section {
  color: var(--accent);
  font-weight: 800;
}

@media (max-width: 860px) {
  .app-shell {
    display: flex;
    flex-direction: column;
    padding: 12px;
  }

  .topbar {
    order: 1;
    align-items: center;
    padding: 4px 0 8px;
  }

  .eyebrow {
    margin-bottom: 2px;
    font-size: 12px;
  }

  h1 {
    font-size: 22px;
  }

  .score-panel {
    min-width: 72px;
    padding: 8px 10px;
    box-shadow: none;
  }

  .score-panel span {
    font-size: 20px;
  }

  .score-panel small {
    font-size: 12px;
  }

  .toolbar {
    order: 2;
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 10px;
  }

  .quiz-layout {
    order: 3;
    grid-template-columns: 1fr;
  }

  .stats-grid {
    order: 4;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
    margin: 10px 0 0;
  }

  .stats-grid article {
    padding: 8px 6px;
    text-align: center;
  }

  .stats-grid strong {
    font-size: 18px;
  }

  .stats-grid span {
    font-size: 12px;
  }

  .search-box {
    grid-column: 1 / -1;
  }

  .segmented {
    grid-column: 1 / -1;
    grid-template-columns: repeat(4, 1fr);
    grid-auto-flow: unset;
  }

  .filter-toggle {
    display: block;
    grid-column: 1 / -1;
    min-height: 38px;
  }

  .filter-panel {
    display: none;
    grid-column: 1 / -1;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .filter-panel.is-open {
    display: grid;
  }

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

  .side-list {
    box-shadow: none;
  }

  .question-card {
    min-height: auto;
    padding: 14px;
  }

  .question-card h2 {
    margin: 12px 0;
    font-size: 18px;
  }
}
