/* ==================================================================
   高等概率论逐页精讲 · 全站样式
   - 正文与卡片：Times New Roman（西文）+ 宋体（中文）
   - 公式：KaTeX（构建时已排版，这里只调大小与溢出）
   - 性能：不用 backdrop-filter / 大面积阴影动画；全页只有一个滚动条
   ================================================================== */

:root {
  --font-scale: 1;
  --font-serif: "Times New Roman", Times, "Nimbus Roman", "Nimbus Roman No9 L", "TeX Gyre Termes",
    "Liberation Serif", Tinos, SimSun, "宋体", "Songti SC", STSong, "Noto Serif CJK SC",
    "Source Han Serif SC", "Noto Serif SC", serif;
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Noto Sans CJK SC", "Source Han Sans SC", sans-serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;

  --paper: #f5f3ee;
  --surface: #fffefb;
  --ink: #1d2126;
  --ink-soft: #3d434b;
  --muted: #6a7078;
  --line: #e4dfd5;
  --line-strong: #d3ccbf;
  --accent: #2f3b9c;
  --accent-deep: #232d7a;
  --accent-soft: #eceefb;

  --topbar-height: 56px;
  --radius: 10px;
}

*, *::before, *::after { box-sizing: border-box; }

html {
  font-size: calc(17.5px * var(--font-scale));
  -webkit-text-size-adjust: 100%;
  scroll-padding-top: calc(var(--topbar-height) + 16px);
}
@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-serif);
  line-height: 1.8;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

img { max-width: 100%; }
a { color: var(--accent); text-underline-offset: 0.18em; }
a:hover { color: var(--accent-deep); }
kbd {
  font-family: var(--font-ui); font-size: 0.78em; padding: 0.05em 0.45em;
  border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 5px; background: #fff;
}

.skip-link { position: absolute; left: -9999px; }
.skip-link:focus { left: 12px; top: 12px; z-index: 100; background: #fff; padding: 6px 12px; border-radius: 6px; }

@view-transition { navigation: auto; }

/* ------------------------------------------------------------------ */
/* 顶栏                                                                */
/* ------------------------------------------------------------------ */

.topbar {
  position: sticky; top: 0; z-index: 50;
  height: var(--topbar-height);
  background: #fff;
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  height: 100%;
  display: flex; align-items: center; gap: 18px;
  padding: 0 18px;
  font-family: var(--font-ui);
}
.brand {
  font-family: var(--font-serif); font-weight: 700; font-size: 1.12rem;
  color: var(--ink); text-decoration: none; white-space: nowrap; flex: none;
}
@media (max-width: 1100px) {
  .tool-btn span, .brand span { display: none; }
  .topbar-inner { gap: 10px; }
}
.brand span { color: var(--accent); margin-left: 0.4em; }
.topnav { display: flex; gap: 4px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; min-width: 0; flex: 1 1 auto; }
.topnav::-webkit-scrollbar { display: none; }
.topnav a {
  color: var(--ink-soft); text-decoration: none; font-size: 0.86rem;
  padding: 6px 10px; border-radius: 8px; white-space: nowrap;
}
.topnav a:hover { background: var(--accent-soft); color: var(--accent); }
.topnav a[aria-current="page"] { color: var(--accent); font-weight: 700; background: var(--accent-soft); }
.tools { margin-left: auto; display: flex; align-items: center; gap: 6px; flex: none; }
.font-tools { display: flex; gap: 2px; }
.tool-btn {
  display: inline-flex; align-items: center; gap: 6px; flex: none; white-space: nowrap;
  font-family: var(--font-ui); font-size: 0.82rem; color: var(--ink-soft);
  background: #fff; border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 10px; cursor: pointer; line-height: 1;
}
.tool-btn:hover { border-color: var(--accent); color: var(--accent); }
.tool-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.tool-btn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }

.read-progress { position: absolute; left: 0; right: 0; bottom: -1px; height: 3px; pointer-events: none; }
.read-progress span {
  display: block; height: 100%; background: var(--accent);
  transform-origin: 0 50%; transform: scaleX(0); will-change: transform;
}

/* ------------------------------------------------------------------ */
/* 逐页阅读：目录 + 课件原页 + 讲义                                     */
/* ------------------------------------------------------------------ */

.reader { display: grid; grid-template-columns: minmax(0, 1fr); }

.toc {
  position: fixed; z-index: 45; top: var(--topbar-height); bottom: 0; left: 0;
  width: 300px; max-width: 86vw;
  background: #fff; border-right: 1px solid var(--line);
  overflow-y: auto; overscroll-behavior: contain;
  transform: translateX(-102%); transition: transform 0.2s ease;
  padding: 14px 10px 40px;
}
.toc-open .toc { transform: none; box-shadow: 8px 0 30px rgba(20, 24, 40, 0.12); }
.toc-scrim { position: fixed; inset: var(--topbar-height) 0 0 0; z-index: 44; background: rgba(20, 22, 30, 0.28); }
.toc-head { padding: 4px 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 8px; }
.toc-head a { font-weight: 700; color: var(--ink); text-decoration: none; font-size: 0.95rem; }
.toc-progress { font-family: var(--font-ui); font-size: 0.78rem; color: var(--muted); margin: 4px 0 0; }
.toc-progress b { color: var(--accent); }
.toc-section h2 {
  font-family: var(--font-ui); font-size: 0.74rem; font-weight: 700; letter-spacing: 0.04em;
  color: var(--muted); margin: 14px 10px 4px;
}
.toc ol { list-style: none; margin: 0; padding: 0; }
.toc li a {
  display: flex; gap: 0.6em; align-items: baseline;
  padding: 0.38em 0.7em; border-radius: 8px;
  color: var(--ink-soft); text-decoration: none; font-size: 0.84rem; line-height: 1.45;
}
.toc li a:hover { background: #f4f3ef; }
.toc-num { flex: 0 0 1.9em; font-family: var(--font-ui); font-size: 0.78em; color: var(--muted); font-variant-numeric: tabular-nums; }
.toc li.current a { background: var(--accent-soft); color: var(--accent-deep); font-weight: 700; }
.toc li.pending a { color: #a2a6ab; }
.toc li.done .toc-num { color: #1f8a4c; }
.toc li.done .toc-num::after { content: " ✓"; }

@media (min-width: 1560px) {
  .reader { grid-template-columns: 280px minmax(0, 1fr); }
  .toc {
    position: sticky; top: var(--topbar-height); height: calc(100vh - var(--topbar-height));
    width: auto; max-width: none; transform: none; transition: none; box-shadow: none;
  }
  .toc-open .toc { box-shadow: none; }
  .toc-scrim { display: none; }
  #toc-toggle { display: none; }
}

.reader-main { min-width: 0; padding: 22px 28px 70px; max-width: 1560px; width: 100%; margin: 0 auto; }

.page-head { margin: 0 0 22px; }
.crumbs { font-family: var(--font-ui); font-size: 0.8rem; color: var(--muted); margin: 0 0 8px; }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--accent); }
.crumbs span { margin: 0 0.5em; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.badge {
  font-family: var(--font-ui); font-size: 0.74rem; color: var(--ink-soft);
  border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 2px 10px;
}
.badge-kind { background: var(--accent); border-color: var(--accent); color: #fff; }
.page-head h1 { font-size: 1.95rem; line-height: 1.35; margin: 0.1em 0 0.15em; letter-spacing: 0.01em; }
.title-en { font-style: italic; color: var(--muted); font-size: 1.05rem; margin: 0; }
.chips { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 14px; }
.chips-label { font-family: var(--font-ui); font-size: 0.74rem; color: var(--muted); margin-right: 4px; }
.chips a {
  font-family: var(--font-ui); font-size: 0.8rem; color: var(--ink-soft); text-decoration: none;
  background: #fff; border: 1px solid var(--line); border-radius: 999px; padding: 3px 12px;
}
.chips a:hover { border-color: var(--accent); color: var(--accent); }

.split {
  display: grid;
  grid-template-columns: minmax(0, 45fr) minmax(0, 55fr);
  gap: 30px;
  align-items: start;
}
.slide-pane { position: sticky; top: calc(var(--topbar-height) + 16px); margin: 0; }
.slide-zoom { display: block; width: 100%; padding: 0; border: 0; background: none; cursor: zoom-in; }
.slide-zoom img {
  display: block; width: 100%; height: auto; background: #fff;
  border-radius: var(--radius); border: 1px solid var(--line);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05), 0 10px 26px rgba(30, 30, 60, 0.07);
}
.slide-pane figcaption { font-family: var(--font-ui); font-size: 0.76rem; color: var(--muted); margin-top: 8px; text-align: center; }

.notes {
  min-width: 0; max-width: 820px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 10px 34px 34px;
}

/* 专注阅读：课件缩到讲义上方，讲义居中 */
.focus-mode .split { grid-template-columns: minmax(0, 1fr); }
.focus-mode .slide-pane { position: static; max-width: 460px; margin: 0 auto; }
.focus-mode .notes { margin: 0 auto; width: 100%; }

@media (max-width: 1180px) {
  .split { grid-template-columns: minmax(0, 1fr); gap: 20px; }
  .slide-pane { position: static; max-width: 760px; margin: 0 auto; width: 100%; }
  .notes { margin: 0 auto; width: 100%; }
  #layout-toggle { display: none; }
}
@media (max-width: 640px) {
  .topbar-inner { gap: 10px; padding: 0 10px; }
  .brand span, .tool-btn span, .topnav { display: none; }
  .reader-main { padding: 14px 10px 50px; }
  .notes { padding: 4px 16px 24px; border-radius: 10px; }
  .page-head h1 { font-size: 1.5rem; }
}
/* 窄手机：按钮收紧，让「目录、标题、搜索、符号、夜间、A− A+」一行放得下 */
@media (max-width: 420px) {
  .topbar-inner { gap: 6px; }
  .tools { gap: 3px; }
  .tool-btn { padding: 6px 7px; }
}
@media (max-width: 350px) {
  .topbar-inner { padding: 0 6px; }
  .brand { font-size: 1rem; }
}

.page-foot { max-width: 1400px; margin: 34px auto 0; }
.done-toggle {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  font-family: var(--font-ui); font-size: 0.95rem; color: var(--ink-soft);
  background: #fff; border: 1px dashed var(--line-strong); border-radius: 12px; padding: 14px; cursor: pointer;
}
.done-toggle input { width: 20px; height: 20px; accent-color: #1f8a4c; }
.done-toggle:has(input:checked) { border-style: solid; border-color: #9ed3b3; background: #f0faf4; color: #17663a; }
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 14px; }
.pager a {
  display: flex; flex-direction: column; gap: 2px; text-decoration: none; color: var(--ink);
  background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px;
}
.pager a:hover { border-color: var(--accent); }
.pager small { font-family: var(--font-ui); color: var(--muted); font-size: 0.76rem; }
.pager-next { text-align: right; }

.pending-note { margin: 28px 0; padding: 22px; border: 1px dashed var(--line-strong); border-radius: 12px; background: #fbfaf7; }
.pending-title { font-weight: 700; font-size: 1.15rem; margin-top: 0; }

/* ------------------------------------------------------------------ */
/* 讲义正文排版                                                        */
/* ------------------------------------------------------------------ */

.prose { font-size: 1rem; line-height: 1.85; overflow-wrap: break-word; }
.prose > :first-child { margin-top: 0.8em; }
.prose h2 {
  position: relative;
  font-size: 1.36rem; line-height: 1.4; margin: 2.1em 0 0.8em; padding: 0 0 0.35em 0.75em;
  border-bottom: 1px solid var(--line); color: var(--ink);
}
.prose h2::before {
  content: ""; position: absolute; left: 0; top: 0.22em; bottom: 0.55em; width: 4px;
  border-radius: 2px; background: var(--accent);
}
.prose h3 { font-size: 1.12rem; line-height: 1.5; margin: 1.7em 0 0.55em; color: var(--accent-deep); }
.prose h4 { font-size: 1rem; margin: 1.3em 0 0.4em; }
.prose p { margin: 0.72em 0; }
.prose ul, .prose ol { padding-left: 1.5em; margin: 0.6em 0; }
.prose li { margin: 0.32em 0; }
.prose li > p { margin: 0.3em 0; }
.prose strong { font-weight: 700; color: #111418; }
.prose em { font-style: italic; }
.prose code { font-family: var(--font-mono); font-size: 0.86em; background: #f1efe9; padding: 0.08em 0.35em; border-radius: 4px; }
.prose blockquote { margin: 1em 0; padding: 0.2em 1em; border-left: 3px solid var(--line-strong); color: var(--ink-soft); background: #faf9f6; }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 2em 0; }

.table-wrap { overflow-x: auto; margin: 1em 0; -webkit-overflow-scrolling: touch; }
.prose table { border-collapse: collapse; width: 100%; font-size: 0.95em; background: #fff; }
.prose th, .prose td { border: 1px solid var(--line); padding: 0.5em 0.75em; vertical-align: top; text-align: left; }
.prose th { background: #f3f3f8; font-weight: 700; }
/* 速查表在窄屏上每行排成一张小卡片（列名由脚本写进 data-label） */
@media (max-width: 640px) {
  .stack-table thead { display: none; }
  .stack-table, .stack-table tbody, .stack-table tr, .stack-table td { display: block; width: auto; }
  .stack-table tr { padding: 8px 2px 10px; border-bottom: 1px solid var(--line); }
  .stack-table tr[hidden] { display: none; }
  .prose .stack-table td { border: 0; padding: 1px 0; }
  .stack-table td:first-child { font-size: 1.1em; padding-bottom: 4px; }
  .stack-table td[data-label]::before { content: attr(data-label) "："; font-family: var(--font-ui); font-size: 0.78em; color: var(--muted); }
}

.page-link { text-decoration-style: dotted; }
.term { border-bottom: 1.5px dotted var(--accent); cursor: help; text-decoration: none; }
.term:focus { outline: 2px solid var(--accent-soft); border-radius: 2px; }

/* 公式 */
.katex { font-size: 1.06em; text-rendering: auto; }
.math-display { overflow-x: auto; overflow-y: hidden; margin: 0.9em 0; padding: 0.25em 0.1em; -webkit-overflow-scrolling: touch; }
.math-display .katex-display { margin: 0; }
.cjk-punct { font-family: var(--font-serif); }
.math-error { color: #b42318; background: #fff1f0; border: 1px dashed #f5a19a; padding: 0 0.3em; border-radius: 4px; }

/* ------------------------------------------------------------------ */
/* 彩色卡片                                                            */
/* ------------------------------------------------------------------ */

.box {
  --box-accent: #6b7280;
  --box-bg: #fafaf8;
  --box-line: #e7e3da;
  margin: 1.2em 0;
  background: var(--box-bg);
  border: 1px solid var(--box-line);
  border-left: 4px solid var(--box-accent);
  border-radius: var(--radius);
  padding: 0.85em 1.15em 0.95em;
  font-family: var(--font-serif);
}
.box-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.35em 0.65em; margin-bottom: 0.4em; }
.box-kind {
  font-family: var(--font-ui); font-size: 0.7rem; font-weight: 700; letter-spacing: 0.06em;
  color: #fff; background: var(--box-accent); border-radius: 999px; padding: 0.2em 0.7em; line-height: 1.5;
  white-space: nowrap;
}
.box-title { font-weight: 700; font-size: 1.02em; color: var(--ink); }
.box-body > :first-child { margin-top: 0; }
.box-body > :last-child { margin-bottom: 0; }
.box .box { margin: 0.9em 0; }

.box-original { --box-accent: #5b6472; --box-bg: #f6f6f4; --box-line: #e2e1dc; }
.box-original .box-body { font-size: 1.02em; line-height: 1.72; }
.box-zh { --box-accent: #8a91b4; --box-bg: #fbfbfe; --box-line: #e4e5f1; }
.box-original + .box-zh { margin-top: -0.75em; border-top-left-radius: 0; border-top-right-radius: 0; border-top-style: dashed; }
.box-original:has(+ .box-zh) { border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.box-board { --box-accent: #1d4ed8; --box-bg: #f2f6ff; --box-line: #d6e0fb; }
.box-board .box-body { color: #1c3b8f; }
.box-board .box-body strong { color: #142c6e; }
.box-def { --box-accent: #1f6feb; --box-bg: #eff5ff; --box-line: #d3e3fb; }
.box-thm { --box-accent: #6d3fd1; --box-bg: #f5f1ff; --box-line: #e1d7fa; }
.box-idea { --box-accent: #d97706; --box-bg: #fff8ea; --box-line: #f6e2b8; }
.box-ex { --box-accent: #15803d; --box-bg: #effaf2; --box-line: #cfeedb; }
.box-proof { --box-accent: #475569; --box-bg: #ffffff; --box-line: #d9dde3; border-style: dashed; border-left-style: solid; }
.box-warn { --box-accent: #d9344f; --box-bg: #fff3f4; --box-line: #f8d4da; }
.box-basics { --box-accent: #0f8f86; --box-bg: #effbf9; --box-line: #cdeee9; }
.box-fig { --box-accent: #0b6aa8; --box-bg: #f3f8fc; --box-line: #d5e6f3; }
.box-sum { --box-accent: #0e7490; --box-bg: #eefaff; --box-line: #cdebf5; }
.box-quiz { --box-accent: #8b3fd9; --box-bg: #faf5ff; --box-line: #eadcfb; }
.box-note { --box-accent: #7c6f64; --box-bg: #faf9f7; --box-line: #e7e1da; }
.box-demo { --box-accent: #c2410c; --box-bg: #fffaf5; --box-line: #f5dcc8; }
.box-vocab { --box-accent: #4b5563; --box-bg: #fbfbfa; --box-line: #e5e3de; margin-top: 2.2em; }
.box-vocab table { font-size: 0.9em; }
.box-vocab td:first-child { white-space: nowrap; font-weight: 700; }
.box-vocab td:first-child a { text-decoration: none; }

details.box { padding: 0; }
details.box > summary {
  list-style: none; cursor: pointer; user-select: none;
  display: flex; align-items: center; gap: 0.5em;
  padding: 0.6em 1.1em; font-family: var(--font-ui); font-size: 0.86rem; font-weight: 700; color: var(--box-accent);
}
details.box > summary::-webkit-details-marker { display: none; }
details.box > summary::before { content: "▸"; display: inline-block; transition: transform 0.15s ease; }
details.box[open] > summary::before { transform: rotate(90deg); }
details.box > .box-body { padding: 0 1.15em 0.95em; }
.box-answer { --box-accent: #7c3aed; --box-bg: #ffffff; --box-line: #e6dcfa; border-left-width: 3px; }
.box-more { --box-accent: #475569; --box-bg: #ffffff; --box-line: #dde1e6; border-left-width: 3px; }

/* 裁出的课件局部 */
/* 必须是 content-box：aspect-ratio 和图片的 top 百分比都要以内框为准，
   否则 1px 边框会让窗口按 from/(to−from) 倍放大地向上偏，切掉半行字 */
.crop {
  position: relative; overflow: hidden; margin: 0.35em 0 0.85em; box-sizing: content-box;
  border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
.crop img { position: absolute; max-width: none; height: auto; display: block; }

/* 练习页左栏：本题在解答原页中的几段上下拼接；比屏幕高时在左栏内部滚动 */
.source-pane { max-height: calc(100vh - var(--topbar-height) - 32px); overflow-y: auto; padding-right: 4px; scrollbar-width: thin; }
.source-pane .crop { margin: 0 0 10px; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05), 0 10px 26px rgba(30, 30, 60, 0.07); }
.focus-mode .source-pane { max-height: none; overflow: visible; }
@media (max-width: 1180px) {
  .source-pane { max-height: none; overflow: visible; }
  /* 窄屏：原页在讲解上方，太长时先收起，免得要滑好几屏才看到讲解 */
  .source-pane.is-collapsible:not(.is-expanded) { max-height: 58vh; overflow: hidden; position: relative; top: auto; }
  .source-pane.is-collapsible:not(.is-expanded)::after {
    content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 90px; pointer-events: none;
    background: linear-gradient(to bottom, transparent, var(--paper));
  }
}
.source-toggle {
  position: relative; z-index: 1; display: block; margin: 8px auto 0; font-family: var(--font-ui); font-size: 0.86rem; cursor: pointer;
  color: var(--accent); background: var(--surface); border: 1px solid var(--line-strong); border-radius: 999px; padding: 7px 16px;
}
.source-toggle:hover { border-color: var(--accent); }
@media (max-width: 640px) {
  .chips { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; padding-bottom: 2px; }
  .chips::-webkit-scrollbar { display: none; }
  .chips a, .chips-label { flex: none; }
}

/* 首页：作业与小测 */
.exercise-home { margin: 34px 0 0; }
.exercise-home h2 { font-size: 1.25rem; margin: 0 0 6px; }
.exercise-home .section-lede { color: var(--muted); margin: 0 0 14px; max-width: 60em; }

/* ------------------------------------------------------------------ */
/* 交互演示                                                            */
/* ------------------------------------------------------------------ */

.demo-ui { font-family: var(--font-ui); font-size: 0.86rem; }
.demo-ui canvas, .demo-ui svg { display: block; width: 100%; height: auto; background: #fff; border: 1px solid var(--line); border-radius: 8px; }
.demo-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin: 10px 0 4px; }
.demo-controls label { display: inline-flex; align-items: center; gap: 8px; }
.demo-controls input[type="range"] { width: 180px; accent-color: #c2410c; }
.demo-controls button {
  font-family: var(--font-ui); font-size: 0.82rem; border: 1px solid var(--line-strong); background: #fff;
  border-radius: 7px; padding: 5px 10px; cursor: pointer;
}
.demo-controls button:hover { border-color: #c2410c; color: #c2410c; }
.demo-readout { font-family: var(--font-serif); font-size: 0.98rem; margin: 6px 0 0; color: var(--ink-soft); }
.demo-readout b { color: #9a3412; }
.demo-controls select { font-family: var(--font-ui); font-size: 0.82rem; padding: 4px 6px; border: 1px solid var(--line-strong); border-radius: 7px; background: #fff; max-width: 100%; }
.demo-ui + * { margin-top: 0.8em; }
.sigma-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 6px 0; }
.sigma-label { font-family: var(--font-serif); min-width: 7.5em; }
.sigma-chip { width: 2.2em; height: 2.2em; border-radius: 50%; border: 1px solid var(--line-strong); background: #fff; cursor: pointer; font-family: var(--font-serif); font-size: 1rem; }
.sigma-chip.on { background: #c2410c; border-color: #c2410c; color: #fff; }
.sigma-set { font-family: var(--font-serif); color: var(--ink-soft); margin-left: 6px; }
.sigma-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.sigma-member { font-family: var(--font-serif); background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 2px 8px; }

/* ------------------------------------------------------------------ */
/* 浮层：术语提示、放大图、搜索                                         */
/* ------------------------------------------------------------------ */

.term-pop {
  position: fixed; z-index: 70; max-width: 340px;
  background: #fff; border: 1px solid var(--line-strong); border-radius: 12px;
  box-shadow: 0 12px 34px rgba(20, 24, 40, 0.16);
  padding: 12px 14px; font-size: 0.92rem; line-height: 1.65;
}
.term-pop strong { font-size: 1.02rem; }
.term-pop .pop-en { font-style: italic; color: var(--muted); margin-left: 0.5em; }
.term-pop p { margin: 6px 0 0; }
.term-pop a { font-family: var(--font-ui); font-size: 0.78rem; }

.lightbox { position: fixed; inset: 0; z-index: 90; background: rgba(18, 20, 26, 0.9); display: flex; flex-direction: column; }
.lightbox[hidden] { display: none; }
.lightbox-stage { flex: 1; overflow: auto; display: flex; align-items: center; justify-content: center; padding: 20px; }
.lightbox-stage img { max-width: 100%; max-height: 100%; background: #fff; border-radius: 6px; cursor: zoom-in; }
.lightbox.zoomed .lightbox-stage { align-items: flex-start; justify-content: flex-start; }
.lightbox.zoomed .lightbox-stage img { max-width: none; max-height: none; width: 220%; cursor: zoom-out; }
.lightbox-close {
  position: absolute; top: 12px; right: 14px; z-index: 2;
  font-family: var(--font-ui); background: #fff; border: 0; border-radius: 8px; padding: 7px 12px; cursor: pointer;
}
.lightbox-hint { font-family: var(--font-ui); color: #d8dbe2; font-size: 0.8rem; text-align: center; margin: 0 0 12px; }

.search-panel { position: fixed; inset: 0; z-index: 80; background: rgba(20, 22, 30, 0.35); display: flex; justify-content: center; align-items: flex-start; padding-top: 9vh; }
.search-panel[hidden] { display: none; }
.search-box { width: min(720px, 94vw); background: #fff; border-radius: 14px; box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2); overflow: hidden; }
.search-box input { width: 100%; border: 0; border-bottom: 1px solid var(--line); padding: 16px 18px; font-size: 1.05rem; font-family: var(--font-serif); outline: none; }
.search-results { list-style: none; margin: 0; padding: 6px; max-height: 60vh; overflow-y: auto; }
.search-results li a { display: block; padding: 10px 12px; border-radius: 10px; text-decoration: none; color: var(--ink); }
.search-results li.active a, .search-results li a:hover { background: var(--accent-soft); }
.search-results .r-kicker { font-family: var(--font-ui); font-size: 0.72rem; color: var(--muted); }
.search-results .r-title { font-weight: 700; display: block; }
.search-results .r-snippet { font-size: 0.86rem; color: var(--ink-soft); display: block; }
.search-results mark { background: #fff1a8; color: inherit; border-radius: 2px; }
.search-hint { font-family: var(--font-ui); font-size: 0.75rem; color: var(--muted); margin: 0; padding: 8px 16px 12px; border-top: 1px solid var(--line); }

/* 符号速查面板：遮罩和对话框沿用搜索面板 */
.symbol-box { width: min(960px, 96vw); max-height: 86vh; display: flex; flex-direction: column; }
.symbol-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px 8px; font-family: var(--font-ui); }
.symbol-head strong { font-size: 1rem; }
.symbol-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 12px 14px 2px; }
.symbol-body .box { margin: 0 0 14px; }
.symbol-body [hidden] { display: none !important; }
.symbol-status { font-family: var(--font-ui); font-size: 0.9rem; color: var(--muted); margin: 8px 4px 14px; }

/* ------------------------------------------------------------------ */
/* 首页 / 目录页 / 术语表 / 基础补课                                    */
/* ------------------------------------------------------------------ */

.home-main, .index-main, .basics-main { max-width: 1080px; margin: 0 auto; padding: 44px 22px 90px; }
.eyebrow { font-family: var(--font-ui); font-size: 0.78rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--accent); margin: 0 0 6px; }
.hero h1, .index-head h1 { font-size: 2.3rem; line-height: 1.3; margin: 0 0 10px; }
.lede { font-size: 1.1rem; color: var(--ink-soft); max-width: 46em; }
.index-actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 20px 0 8px; }
.button {
  display: inline-block; font-family: var(--font-ui); font-size: 0.92rem; text-decoration: none;
  border: 1px solid var(--line-strong); background: #fff; color: var(--ink); border-radius: 10px; padding: 10px 18px;
}
.button:hover { border-color: var(--accent); color: var(--accent); }
.button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.button.primary:hover { background: var(--accent-deep); color: #fff; }

.how { margin: 34px 0; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 6px 26px 14px; }
.how h2 { font-size: 1.25rem; }
.how-steps { padding-left: 1.3em; }
.how-steps li { margin: 0.55em 0; }

.topic-cards { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); gap: 16px; }
.topic-card a {
  display: flex; flex-direction: column; gap: 6px; height: 100%;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 18px 20px;
  text-decoration: none; color: var(--ink);
}
.topic-card a:hover { border-color: var(--accent); }
.card-num { font-family: var(--font-ui); font-size: 0.78rem; font-weight: 700; color: var(--accent); }
.topic-card strong { font-size: 1.25rem; }
.topic-card em { color: var(--muted); font-size: 0.95rem; }
.topic-card p { margin: 4px 0; color: var(--ink-soft); font-size: 0.95rem; flex: 1; }
.card-meta, .card-progress { font-family: var(--font-ui); font-size: 0.78rem; color: var(--muted); }
.meter { display: block; height: 6px; border-radius: 99px; background: #eceae4; overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.extra-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); gap: 16px; margin-top: 16px; }
.extra-card { display: flex; flex-direction: column; gap: 4px; background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 16px 20px; text-decoration: none; color: var(--ink); }
.extra-card:hover { border-color: var(--accent); }
.extra-card span { color: var(--ink-soft); font-size: 0.95rem; }

.index-head { margin-bottom: 26px; }
.index-stats { font-family: var(--font-ui); font-size: 0.86rem; color: var(--muted); }
.index-stats b { color: var(--accent); }
.index-section { margin: 26px 0; }
.index-section h2 { font-size: 1.2rem; margin: 0 0 10px; display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.3em 0.8em; }
.index-section h2 small { font-size: 0.8rem; font-style: italic; font-weight: 400; color: var(--muted); }
.page-rows { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.page-row + .page-row { border-top: 1px solid var(--line); }
.page-row a { display: grid; grid-template-columns: 3em minmax(0, 1fr) auto; gap: 14px; align-items: center; padding: 11px 18px; text-decoration: none; color: var(--ink); }
.page-row a:hover { background: #faf9f5; }
.row-num { font-family: var(--font-ui); font-size: 0.82rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.row-main { display: flex; flex-direction: column; min-width: 0; }
.row-title { font-weight: 700; }
.row-en { font-size: 0.86rem; font-style: italic; color: var(--muted); }
.row-meta { font-family: var(--font-ui); font-size: 0.74rem; color: var(--muted); white-space: nowrap; }
.page-row.pending .row-title { color: #8d9298; font-weight: 400; }
.page-row.done .row-num { color: #1f8a4c; }
.page-row.done .row-num::after { content: " ✓"; }
@media (max-width: 640px) { .row-meta { display: none; } .page-row a { grid-template-columns: 2.4em minmax(0, 1fr); } }

.glossary-filter { width: 100%; max-width: 520px; font-size: 1rem; padding: 10px 14px; border: 1px solid var(--line-strong); border-radius: 10px; font-family: var(--font-serif); }
.glossary-list { list-style: none; padding: 0; margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
.glossary-row { display: grid; grid-template-columns: minmax(170px, 0.9fr) minmax(0, 2.2fr) auto; gap: 16px; padding: 14px 20px; }
.glossary-row + .glossary-row { border-top: 1px solid var(--line); }
.glossary-row:target { background: #fffbe6; }
.g-term strong { display: block; font-size: 1.05rem; }
.g-term span { font-style: italic; color: var(--muted); font-size: 0.92rem; }
.g-plain { margin: 0; }
.g-page { margin: 0; font-family: var(--font-ui); font-size: 0.78rem; white-space: nowrap; }
@media (max-width: 720px) { .glossary-row { grid-template-columns: 1fr; gap: 4px; } }

.basics-prose { margin-top: 10px; max-width: none; }

/* ------------------------------------------------------------------ */
/* 相关练习、原解答问题速览、搜索高亮                                    */
/* ------------------------------------------------------------------ */

.box-related { --box-accent: #4338ca; --box-bg: #f5f6ff; --box-line: #dcdffa; }
.related-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.related-list a { display: flex; flex-wrap: wrap; gap: 0.2em 0.8em; align-items: baseline; text-decoration: none; color: var(--ink); padding: 6px 10px; border-radius: 8px; background: var(--surface); border: 1px solid var(--box-line); }
.related-list a:hover { border-color: var(--box-accent); }
.rel-label { font-family: var(--font-ui); font-size: 0.78rem; font-weight: 700; color: var(--box-accent); white-space: nowrap; }
.rel-title { font-size: 0.95rem; }

.issues-overview .section-lede { color: var(--muted); margin: 0 0 12px; max-width: 60em; }
.issue-list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.issue-item { padding: 12px 18px 14px; }
.issue-item + .issue-item { border-top: 1px solid var(--line); }
.issue-item > a { display: flex; gap: 14px; align-items: baseline; text-decoration: none; color: var(--ink); font-weight: 700; }
.issue-item > a:hover .issue-title { color: var(--accent); }
.issue-item ul { list-style: none; margin: 6px 0 0 calc(2.2em + 14px); padding: 0; }
.issue-item li { margin: 0.25em 0; font-size: 0.94rem; color: var(--ink-soft); }
.issue-tag {
  display: inline-block; margin-right: 0.6em; padding: 0 0.6em; border-radius: 999px; line-height: 1.7;
  font-family: var(--font-ui); font-size: 0.7rem; font-weight: 700; color: #fff; background: #d9344f; vertical-align: 0.1em;
}
.issue-tag-minor { background: #e08a2c; }
.issue-tag-problem { background: #6d3fd1; }
@media (max-width: 640px) { .issue-item ul { margin-left: 0; } }

mark.search-hit { background: #ffe58a; color: inherit; border-radius: 3px; padding: 0 1px; box-shadow: 0 0 0 2px #ffe58a; }

/* ------------------------------------------------------------------ */
/* 页脚与「回到顶部」                                                   */
/* ------------------------------------------------------------------ */

.site-foot { border-top: 1px solid var(--line); background: var(--surface); margin-top: 40px; }
.site-foot-inner { max-width: 1080px; margin: 0 auto; padding: 18px 22px 26px; font-family: var(--font-ui); font-size: 0.82rem; color: var(--muted); display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 22px; }
.foot-brand { font-family: var(--font-serif); font-weight: 700; color: var(--ink); text-decoration: none; }
.foot-links { display: flex; flex-wrap: wrap; gap: 4px 16px; }
.foot-links a { color: var(--ink-soft); text-decoration: none; }
.foot-links a:hover { color: var(--accent); }
.foot-note { margin: 0; flex-basis: 100%; }

.to-top {
  position: fixed; right: 18px; bottom: 22px; z-index: 40;
  font-family: var(--font-ui); font-size: 0.82rem; color: var(--ink-soft); cursor: pointer;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: 999px; padding: 8px 14px;
  box-shadow: 0 6px 18px rgba(20, 24, 40, 0.12);
}
.to-top:hover { border-color: var(--accent); color: var(--accent); }
.to-top[hidden] { display: none; }

/* ------------------------------------------------------------------ */
/* 夜间模式：深色背景 + 柔和的卡片底色；课件原页保持白底、稍微调暗           */
/* ------------------------------------------------------------------ */

@media screen {
html.theme-dark {
  color-scheme: dark;
  --paper: #14161b;
  --surface: #1c1f26;
  --ink: #e4e5e8;
  --ink-soft: #c3c7ce;
  --muted: #959ba5;
  --line: #2d313a;
  --line-strong: #3d424d;
  --accent: #9daeff;
  --accent-deep: #c4cdff;
  --accent-soft: #262c48;
}
.theme-dark .topbar, .theme-dark .toc, .theme-dark .tool-btn, .theme-dark .badge, .theme-dark .chips a,
.theme-dark .done-toggle, .theme-dark .pager a, .theme-dark .button, .theme-dark .extra-card,
.theme-dark .search-box, .theme-dark .term-pop, .theme-dark kbd, .theme-dark .glossary-filter,
.theme-dark .search-box input, .theme-dark .demo-controls button, .theme-dark .demo-controls select,
.theme-dark .sigma-chip, .theme-dark .sigma-member, .theme-dark .lightbox-close, .theme-dark .skip-link:focus {
  background: var(--surface); color: var(--ink-soft); border-color: var(--line-strong);
}
.theme-dark .button.primary { background: #3d4bb8; border-color: #3d4bb8; color: #fff; }
.theme-dark .badge-kind, .theme-dark .tool-btn[aria-pressed="true"] { background: #3d4bb8; border-color: #3d4bb8; color: #fff; }
.theme-dark .prose strong { color: #f4f5f7; }
.theme-dark .prose table, .theme-dark .prose th { background: transparent; }
.theme-dark .prose th { background: #232733; }
.theme-dark .prose code { background: #262a33; }
.theme-dark .prose blockquote { background: #1a1d23; }
.theme-dark .toc li a:hover, .theme-dark .page-row a:hover { background: #232733; }
.theme-dark .glossary-row:target { background: #2e2a1a; }
.theme-dark .pending-note { background: #1a1d23; }
.theme-dark .meter { background: #2b2f39; }
.theme-dark .done-toggle:has(input:checked) { background: #16291f; border-color: #2f6b47; color: #8fdcae; }
.theme-dark .box {
  --box-bg: color-mix(in srgb, var(--box-accent) 11%, #1c1f26);
  --box-line: color-mix(in srgb, var(--box-accent) 32%, #1c1f26);
}
.theme-dark .box-kind { background: color-mix(in srgb, var(--box-accent) 78%, #000); }
.theme-dark details.box > summary { color: color-mix(in srgb, var(--box-accent) 55%, #fff); }
.theme-dark .box-board .box-body, .theme-dark .box-board .box-body strong { color: #c6d4ff; }
.theme-dark .rel-label { color: color-mix(in srgb, var(--box-accent) 55%, #fff); }
.theme-dark .slide-zoom img, .theme-dark .crop, .theme-dark .lightbox-stage img { filter: brightness(0.86) contrast(1.04); }
.theme-dark .demo-ui canvas, .theme-dark .demo-ui svg { filter: brightness(0.9); }
.theme-dark mark, .theme-dark mark.search-hit { background: #6b5a12; box-shadow: 0 0 0 2px #6b5a12; color: #fff6cf; }
.theme-dark .to-top { box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45); }
}

@media print {
  .topbar, .toc, .toc-scrim, .page-foot, .chips, .slide-pane, .site-foot, .to-top, .lightbox, .search-panel { display: none !important; }
  .split { display: block; }
  .notes { border: 0; padding: 0; max-width: none; }
  body { background: #fff; }
  .box { break-inside: avoid; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
