:root {
  color-scheme: light dark;
  --bg: #f3f5fb; --surface: #fff; --soft: #f8f9fd;
  --ink: #222a42; --muted: #626d83; --line: #e0e5ef;
  --accent: #4d57c8; --tint: #eef0ff; --solid: #4d57c8;
  --good: #236b67; --good-bg: #edf7f3; --bad: #8b521f; --bad-bg: #fff3e6;
  --shadow: 0 4px 24px rgb(30 43 89 / 4%); --radius: 22px;
  font-family: "Noto Sans TC", system-ui, sans-serif; font-synthesis: none;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121725; --surface: #1c2333; --soft: #20293b;
    --ink: #e6eaf4; --muted: #adb7cb; --line: #354057;
    --accent: #b1b7ff; --tint: #2a3155;
    --good: #a0dcca; --good-bg: #203c38; --bad: #f2c295; --bad-bg: #413122;
    --shadow: 0 4px 24px rgb(0 0 0 / 10%);
  }
}
[data-chapter="ch1"] { --chapter: #365e47; --chapter-bg: #e5eddf; }
[data-chapter="ch2"] { --chapter: #65508d; --chapter-bg: #ece8f5; }
[data-chapter="dw"] { --chapter: #876018; --chapter-bg: #f6efd9; }
[data-chapter="teacher"] { --chapter: #97443c; --chapter-bg: #fbece8; }
[data-chapter="supp"] { --chapter: #626d83; --chapter-bg: #edf0f5; }
@media (prefers-color-scheme: dark) {
  [data-chapter="ch1"] { --chapter: #b5d2a8; --chapter-bg: #2d3e2f; }
  [data-chapter="ch2"] { --chapter: #d3bff3; --chapter-bg: #332d43; }
  [data-chapter="dw"] { --chapter: #e5c37f; --chapter-bg: #3d3525; }
  [data-chapter="teacher"] { --chapter: #ffb9a9; --chapter-bg: #432d2c; }
  [data-chapter="supp"] { --chapter: #adb7cb; --chapter-bg: #293245; }
}
* { box-sizing: border-box; }
html { scroll-padding-top: 106px; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 16px; line-height: 1.8; -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }
button, a, summary { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--accent); text-underline-offset: 4px; }
button, a { transition: background-color .18s, border-color .18s, color .18s, box-shadow .18s; }
button:disabled { cursor: default; opacity: .5; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 4px; }
h1, h2, h3, h4, p { margin: 0; }
h1, h2, h3, h4 { line-height: 1.5; }
h1 { font-size: clamp(21px, 3vw, 30px); letter-spacing: .025em; }
h2 { font-size: 25px; }
h3 { font-size: 21px; }
.app { max-width: 1184px; margin-inline: auto; padding-inline: 32px; }
.page-header { display: flex; justify-content: space-between; align-items: center; gap: 20px; padding: 30px 0 26px; }
.eyebrow { font-size: 12px; letter-spacing: .12em; color: var(--muted); margin-bottom: 5px; }
.muted, .system-note, .page-footer { color: var(--muted); font-size: 14px; }
.system-note { font-size: 12px; }
.tabs { position: sticky; top: 12px; z-index: 20; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; padding: 7px; background: var(--surface); border: 1px solid var(--line); border-radius: 17px; box-shadow: var(--shadow); }
.tabs a { display: flex; align-items: center; justify-content: center; gap: 10px; min-height: 51px; border-radius: 11px; color: var(--muted); font-weight: 500; text-decoration: none; }
.tabs a:hover { background: var(--tint); color: var(--accent); }
.tabs a[aria-current="page"] { color: #fff; background: var(--solid); }
.icon { width: 22px; height: 22px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
main { min-height: 58vh; padding-top: 30px; }
main:focus { outline: none; }
.screen-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.screen-head .muted { margin-top: 8px; }
.button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 9px 17px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--ink); font-size: 14px; font-weight: 500; text-decoration: none; text-align: center; }
.button:hover:not(:disabled) { background: var(--tint); border-color: var(--accent); color: var(--accent); }
button:active:not(:disabled), .button:active { box-shadow: inset 0 0 0 2px var(--accent); }
.button.primary { background: var(--solid); color: white; border-color: var(--solid); }
.button.primary:hover:not(:disabled) { background: #3f49b4; color: white; }
.button.quiet { background: transparent; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 24px; }
.chip { min-height: 44px; padding: 8px 17px; border: 1px solid var(--line); border-radius: 24px; background: var(--surface); color: var(--chapter, var(--muted)); font-size: 14px; }
.chip:hover, .chip[aria-pressed="true"] { border-color: var(--chapter, var(--accent)); background: var(--chapter-bg, var(--tint)); color: var(--chapter, var(--accent)); }
.chip[aria-pressed="true"] { font-weight: 700; box-shadow: inset 0 0 0 1px var(--chapter, var(--accent)); }
.toolbar, .actions { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.toolbar { justify-content: space-between; margin-bottom: 24px; }
.toolbar .chips { margin: 0; }
.card { min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.reading-layout { display: grid; grid-template-columns: minmax(0, 1fr) 252px; gap: 24px; align-items: start; }
.reading-layout > *, [data-content] { min-width: 0; }
.reading { padding: 30px; font-size: 16px; line-height: 1.95; overflow-wrap: anywhere; }
.reading h2 { margin-bottom: 20px; }
.reading h3 { margin: 28px 0 12px; }
.reading h4 { margin: 20px 0 10px; font-size: 18px; }
.reading p + p, .reading ul, .reading ol, .reading blockquote { margin-top: 14px; }
.reading ul, .reading ol { padding-left: 1.5em; margin-bottom: 18px; }
.reading li + li { margin-top: 8px; }
.reading blockquote { margin-inline: 0; padding: 14px 20px; border-left: 3px solid var(--chapter, var(--accent)); background: var(--chapter-bg, var(--tint)); border-radius: 0 12px 12px 0; }
.reading hr { border: 0; border-top: 1px solid var(--line); margin: 28px 0; }
.reading img, .reading svg { max-width: 100%; }
.reading pre { white-space: pre-wrap; overflow-wrap: anywhere; padding: 16px; border-radius: 12px; background: var(--soft); font-size: 14px; }
.reading :not(pre) > code { font-size: .92em; background: var(--soft); border-radius: 4px; padding: 2px 4px; }
.table-wrap { overflow-x: auto; max-width: 100%; margin: 20px 0; border: 1px solid var(--line); border-radius: 12px; }
table { border-collapse: collapse; width: 100%; font-size: 15px; line-height: 1.85; }
th, td { padding: 12px 14px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); min-width: 90px; }
th { background: var(--soft); font-weight: 500; }
tr:last-child td { border-bottom: 0; }
td + td, th + th { border-left: 1px solid var(--line); }
.katex { font-size: 1.06em; }
/* Scroll within long formulas, never the page. Do not shrink mathematical text. */
.katex-display { max-width: 100%; overflow-x: auto; overflow-y: hidden; padding: 12px 4px; margin: 18px 0; }
.katex-display > .katex { text-align: left; }
:not(.katex-display) > .katex { display: inline-block; max-width: 100%; overflow-x: auto; overflow-y: hidden; vertical-align: middle; padding-block: 3px; }
.reading-section, [data-ex], .question-title { scroll-margin-top: 106px; }
.reading-section + .reading-section { border-top: 1px solid var(--line); padding-top: 30px; margin-top: 34px; }
.chapter-heading { border-left: 4px solid var(--chapter, var(--accent)); padding-left: 18px; margin-bottom: 28px; }
.chapter-heading h2, .section-title { color: var(--chapter, var(--ink)); }
.section-title { font-size: 22px; }
.tag { display: inline-block; border-radius: 7px; padding: 4px 10px; background: var(--chapter-bg, var(--tint)); color: var(--chapter, var(--accent)); font-size: 12px; line-height: 1.6; font-weight: 500; }
.tags { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.toc-panel { position: sticky; top: 102px; padding: 20px 14px; max-height: calc(100dvh - 126px); overflow-y: auto; scrollbar-width: thin; }
.toc-panel h2 { font-size: 14px; padding: 0 10px 12px; color: var(--muted); }
.toc-link { display: flex; align-items: center; min-height: 44px; padding: 10px 12px; margin: 3px 0; border-left: 2px solid transparent; border-radius: 0 9px 9px 0; font-size: 14px; text-decoration: none; line-height: 1.7; color: var(--muted); overflow-wrap: anywhere; }
.toc-link:hover, .toc-link[aria-current="location"] { background: var(--chapter-bg, var(--tint)); color: var(--chapter, var(--accent)); border-left-color: var(--chapter, var(--accent)); }
.toc-group { font-size: 14px; margin: 18px 12px 8px; color: var(--chapter, var(--accent)); }
dialog { width: min(580px, calc(100% - 32px)); max-height: calc(100dvh - 40px); padding: 0 18px 20px; background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 22px; }
dialog::backdrop { background: rgb(16 23 42 / 60%); }
.dialog-head { position: sticky; top: 0; display: flex; justify-content: space-between; align-items: center; gap: 16px; background: var(--surface); padding: 18px 0; border-bottom: 1px solid var(--line); z-index: 1; }
.dialog-head h2 { font-size: 21px; }
body.menu-open { overflow: hidden; }
.exam-info { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 22px; padding: 16px 20px; background: var(--tint); border: 1px solid var(--line); border-radius: 15px; font-size: 14px; margin-bottom: 12px; }
.exam-info strong { color: var(--accent); }
.shortcuts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 30px; }
.exercise-list { display: grid; gap: 24px; }
.exercise-title { font-size: 23px; margin-bottom: 20px; }
.answer-controls { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--line); }
.answer { margin-top: 24px; padding-top: 22px; border-top: 1px solid var(--line); }
.answer > h4 { color: var(--good); margin-top: 0; }
.answer.explanation > h4 { color: var(--accent); }
.notice, [data-empty] { padding: 24px; background: var(--soft); border: 1px dashed var(--line); border-radius: 16px; overflow-wrap: anywhere; }
[data-empty] h3 { margin-bottom: 10px; }
[data-empty] .button { margin-top: 16px; }
.notice { margin: 16px 0; }
.score-panel { padding: 18px 22px; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 16px; align-items: center; }
[data-score] { font-variant-numeric: tabular-nums; font-weight: 500; }
.storage-note { font-size: 12px; margin: 12px 0 24px; }
.practice-wrap { max-width: 800px; margin-inline: auto; }
.question-title { font-size: 18px; margin-bottom: 12px; }
.question-stem { font-size: 19px; margin-bottom: 22px; }
.options { display: grid; gap: 12px; }
.option { display: flex; width: 100%; align-items: center; gap: 12px; text-align: left; min-height: 64px; padding: 12px 16px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface); overflow-wrap: anywhere; }
.option:not(:disabled):hover { background: var(--tint); border-color: var(--accent); }
.option-letter { flex-shrink: 0; display: grid; place-items: center; width: 32px; height: 32px; background: var(--soft); border: 1px solid var(--line); border-radius: 9px; font: 14px ui-monospace, monospace; }
.option-copy { flex: 1; min-width: 0; }
.option-copy > :first-child { margin-top: 0; }
.option-copy > :last-child { margin-bottom: 0; }
.option-state { font-size: 12px; flex-shrink: 0; }
.option:disabled { opacity: 1; color: var(--muted); background: var(--soft); }
.option.correct { color: var(--good); background: var(--good-bg); border-color: var(--good); }
.option.incorrect { color: var(--bad); background: var(--bad-bg); border-color: var(--bad); }
.feedback { margin-top: 22px; padding: 20px; border-radius: 14px; background: var(--good-bg); }
.feedback h4 { color: var(--good); margin-top: 0; }
.feedback.wrong { background: var(--bad-bg); }
.feedback.wrong h4 { color: var(--bad); }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 24px; }
.position { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; text-align: center; }
.flash-wrap { max-width: 742px; margin: 0 auto; }
.flash-card { min-height: 350px; width: 100%; display: flex; flex-direction: column; justify-content: space-between; gap: 24px; padding: 28px 36px; border: 1px solid var(--line); border-radius: 26px; background-color: var(--surface); background-image: radial-gradient(var(--line) .7px, transparent .7px); background-size: 16px 16px; box-shadow: 0 6px 0 -1px var(--soft), 0 7px 0 0 var(--line), var(--shadow); cursor: pointer; touch-action: pan-y pinch-zoom; transition: background-color .18s, border-color .18s; }
.flash-card:hover { border-color: var(--chapter, var(--accent)); }
.flash-card[aria-pressed="true"] { background-color: var(--chapter-bg, var(--tint)); background-image: none; border-color: var(--chapter, var(--accent)); }
.flash-text { padding: 0; font-size: 24px; font-weight: 700; text-align: center; }
.flash-card[aria-pressed="true"] .flash-text { font-size: 17px; font-weight: 400; text-align: left; }
.flash-side { align-self: center; color: var(--chapter, var(--accent)); background: var(--surface); font-size: 13px; padding: 4px 12px; border-radius: 24px; border: 1px solid var(--line); }
.flash-hint { font-size: 12px; color: var(--muted); text-align: center; }
.flash-toolbar { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 16px; align-items: center; }
.flash-toolbar .tags { margin: 0; }
.sheet { max-width: 900px; margin-inline: auto; }
.sheet > h2 { color: var(--accent); padding-top: 24px; margin-top: 28px; border-top: 1px solid var(--line); }
.sheet > h2:first-child { margin-top: 0; padding-top: 0; border: 0; }
.mermaid[data-rendered="true"] { padding: 16px 0; background: transparent; text-align: center; overflow-x: auto; max-width: 100%; }
.mermaid svg { height: auto; max-width: none; display: block; margin-inline: auto; }
.diagram-hint { color: var(--muted); font-size: 12px; margin-top: 16px; }
.diagram-zoom { display: block; margin: 4px auto 16px; }
.chart-frame { position: relative; width: 100%; height: 300px; }
.chart-source { font-size: 12px; }
.chart-data { color: var(--muted); font-size: 13px; margin-top: 10px; }
.page-footer { padding: 32px 0; font-size: 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.skip-link { position: fixed; top: -100px; left: 16px; z-index: 50; background: var(--surface); padding: 12px 20px; border-radius: 10px; }
.skip-link:focus { top: 12px; }
@media (max-width: 900px) {
  .reading-layout { grid-template-columns: minmax(0, 1fr); }
  .toc-panel { display: none; }
  .app { padding-inline: 24px; }
}
@media (max-width: 600px) {
  html { scroll-padding-top: 20px; }
  .app { padding-inline: 16px; }
  .page-header { padding: 22px 0; }
  .page-header .eyebrow { font-size: 10px; }
  .system-note { display: none; }
  .tabs { position: fixed; inset: auto 0 0; z-index: 30; border-radius: 20px 20px 0 0; border-width: 1px 0 0; padding: 7px 8px calc(7px + env(safe-area-inset-bottom)); gap: 3px; box-shadow: 0 -4px 24px rgb(25 35 70 / 6%); }
  .tabs a { flex-direction: column; gap: 3px; font-size: 11px; min-height: 58px; padding: 6px 2px; }
  .tabs a[aria-current="page"] { background: var(--tint); color: var(--accent); }
  main { padding-top: 4px; }
  .screen-head { flex-wrap: wrap; gap: 12px; margin-bottom: 20px; }
  h2 { font-size: 22px; }
  .card { border-radius: 18px; }
  .reading { padding: 24px 16px; }
  .reading h3, .section-title { font-size: 20px; }
  .chips { gap: 8px; }
  .chip { padding: 8px 13px; font-size: 13px; }
  .button { padding: 9px 13px; }
  .exam-info { padding: 14px 16px; gap: 4px 16px; }
  .exam-info strong { width: 100%; }
  .shortcuts { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .shortcuts .button { font-size: 13px; padding-inline: 8px; }
  .exercise-title { font-size: 21px; }
  .answer-controls .button { flex: 1 1 130px; }
  .reading-section, [data-ex], .question-title { scroll-margin-top: 20px; }
  .score-panel { padding: 16px; }
  .question-stem { font-size: 18px; }
  .option { padding: 12px; gap: 10px; flex-wrap: wrap; }
  .option-state { margin-left: auto; }
  .flash-card { padding: 24px 20px; min-height: 330px; border-radius: 22px; }
  .flash-text { font-size: 22px; }
  .flash-card[aria-pressed="true"] .flash-text { font-size: 16px; }
  .pager { gap: 8px; flex-wrap: wrap; }
  .pager .button { flex-shrink: 0; }
  .position { font-size: 13px; }
  .page-footer { padding-bottom: calc(106px + env(safe-area-inset-bottom)); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
@media print {
  .tabs, .page-header, .page-footer, .chips, .toolbar, .shortcuts, [data-open-toc], .toc-panel { display: none; }
  body { background: #fff; color: #000; }
  .app, .reading { max-width: none; padding: 0; }
  .card { box-shadow: none; border: 0; }
  .table-wrap, .katex-display { overflow: visible; }
}
