@media screen {
  :root[data-theme] {
    --theme-focus: #1c6550;
  }

  :root[data-theme="dark"] {
    color-scheme: dark;
    --forest: #263e36;
    --green: #acd5b6;
    --lime: #cce1a4;
    --ink: #e1e9e3;
    --muted: #adbfb5;
    --bg: #151f1b;
    --line: #41564b;
    --surface: #202d27;
    --soft: #2a3a32;
    --theme-selected: #31483b;
    --theme-action: #305844;
    --theme-focus: #acd5b6;
    --white: var(--surface);
    --red: #f3b7b7;
    --blue: #a9c8dc;
  }

  body > header .theme-toggle {
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
    gap: .45rem;
    margin-inline-start: auto;
    min-height: 42px;
    padding: .36rem .68rem;
    border: 1px solid var(--line);
    border-radius: 9px;
    color: var(--ink);
    background: var(--surface);
    font-size: .82rem;
    font-weight: 650;
  }
  .theme-symbol::before { content: '☾'; font-size: 1.18rem; }
  .theme-toggle[aria-pressed="true"] .theme-symbol::before { content: '☀'; }
  body > header .theme-toggle:is(:hover, [aria-pressed="true"]) { background: var(--soft); }
  :root[data-theme] :is(button, a, summary, select, textarea):focus-visible {
    outline: 3px solid var(--theme-focus);
    outline-offset: 3px;
  }
  @media (max-width: 610px) {
    body > header .pill { display: none; }
    body > header .brand { font-size: clamp(17px, 5vw, 21px); }
  }

  :root[data-theme="dark"] :is(.welcome, .exam-heading) {
    background: linear-gradient(128deg, #20342d, #294537);
  }
  :root[data-theme="dark"] .welcome h1 { color: var(--ink); }
  :root[data-theme="dark"] body > .main-nav :is(a, button):is(:hover, .active, [aria-current="page"]) {
    background: var(--theme-selected);
    color: var(--ink);
  }
  :root[data-theme="dark"] body > .main-nav button span {
    background: var(--theme-selected);
    color: var(--green);
  }
  :root[data-theme="dark"] #na-history-demo {
    --ink: #e1e9e3;
    --sub: var(--muted);
    --panel: var(--surface);
    --paper: var(--bg);
    --line: #41564b;
    --soft: #2a3a32;
    --forest: #263e36;
  }
  :root[data-theme="dark"] :is(.clock, .test-card, .study-panel, .question-card, .map-card, .launch-card,
    .review-card, .mistake-row, .history-row, .empty-state, .source-card, .stat, .report-dialog, dialog,
    .system-notice, .map-button, .archive-filters select, dialog select, dialog textarea,
    .study-card, .dashboard-strip, .filters, .resume-card) {
    background: var(--surface);
    color: var(--ink);
    border-color: var(--line);
  }
  :root[data-theme="dark"] :is(.pill, .intro-tag, .option, .answer-pair > div, .study-metrics > div,
    .study-empty, .notice, .archive-notice, .study-row, .resume-row, .explanation, .question-top .topic,
    .source-year, .secondary, .review-launch, .section-head .lesson-tag, .study-step, .progress) {
    background: var(--soft);
    color: var(--ink);
    border-color: var(--line);
  }
  :root[data-theme="dark"] .dashboard-strip > div { background: transparent; }
  :root[data-theme="dark"] :is(.dashboard-strip b, .notice b, .seo-guide, .site-about) { color: var(--ink); }
  :root[data-theme="dark"] :is(.study-card-heading span, .study-step i, .archive-notice p, .question-total,
    #report-question, .test-card.mix p, .test-card.mix .card-meta, .test-card .card-index) { color: var(--muted); }
  :root[data-theme="dark"] :is(.study-step span, .study-card-heading b, .test-card .subject-icon) {
    background: var(--theme-selected);
    color: var(--green);
  }
  :root[data-theme="dark"] :is(footer a, footer .link-button, .seo-links a, .document-page a) {
    color: var(--green);
  }
  :root[data-theme="dark"] :is(.seo-guide, .site-about) { border-color: var(--line); }
  :root[data-theme="dark"] .system-notice.error { background: #4a3631; color: #f3c7b8; }
  :root[data-theme="dark"] .mark.active { color: #e8c780; }
  :root[data-theme="dark"] .map-legend i { background: var(--theme-selected); border: 1px solid #89ae99; }
  :root[data-theme="dark"] .map-legend .blank { background: var(--surface); }
  :root[data-theme="dark"] .map-legend .flag { background: #e8c780; border-color: #e8c780; }
  :root[data-theme="dark"] :is(.option.selected, .option:hover, .map-button.answered) {
    color: var(--ink);
    background: var(--theme-selected);
    border-color: #89ae99;
  }
  :root[data-theme="dark"] :is(.option.selected .letter, .primary, .lesson-library .start) {
    background: var(--theme-action);
    color: #f0f6ef;
  }
  :root[data-theme="dark"] :is(.primary:not(:disabled):hover, .lesson-library .start:hover) { background: #3b654f; }
  :root[data-theme="dark"] #na-history-demo :is(.subject.selected, .topic a.primary, .topic a.primary:hover) {
    color: #edf4ed;
    background: var(--theme-selected);
    border-color: #658675;
  }
  :root[data-theme="dark"] #na-history-demo .topic .num { color: var(--green); }
  :root[data-theme="dark"] :is(.good, .status.right, .correct-answer, .good strong) { color: #c2e4c5; }
  :root[data-theme="dark"] :is(.bad, .status.wrong, .wrong-answer, .bad strong, .mistake) { color: #f3b7b7; }
  :root[data-theme="dark"] .status.right { background: #304938; }
  :root[data-theme="dark"] .status.wrong { background: #4a353b; }
  :root[data-theme="dark"] .status.empty { background: #39493f; color: var(--ink); }
  :root[data-theme="dark"] :is(.filters button, .answer-pair small, .card-index, .map-legend) { color: var(--muted); }
  :root[data-theme="dark"] :is(.filters button.active, .filters button:hover) { background: var(--theme-selected); color: var(--ink); }

  .pilot-test-list { display: grid; gap: .7rem; margin: 1rem 0; max-width: 30rem; }
  .pilot-test-button {
    display: grid;
    gap: .2rem;
    padding: .85rem 1rem;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--soft);
    color: var(--ink);
    text-align: start;
  }
  .pilot-test-button:hover { border-color: var(--green); }
  .pilot-test-button span { color: var(--muted); font-size: .88rem; }
  .pilot-test-list + .primary { margin-bottom: .65rem; }
  .question-passage {
    margin: 0 0 1rem;
    padding: 1rem 1.15rem;
    border-inline-start: 3px solid var(--theme-focus);
    border-radius: 0 8px 8px 0;
    background: var(--soft);
    color: var(--ink);
    line-height: 1.7;
  }
  .question-figure { margin: 0 0 1rem; }
  .question-figure img { display: block; max-width: 100%; height: auto; border: 1px solid var(--line); border-radius: 12px; }
  :root[data-theme="dark"] .question-figure img { filter: brightness(.84) saturate(.85); }
  .question-figure a { display: inline-block; margin-block-start: .45rem; color: var(--green); font-size: .88rem; }
  .question-figure + .question-text, .question-passage + .question-text { min-height: 0; }
}
