/* ── 知识库：阅读页 + 首页 ─────────────────────────────────── */
:root {
  --paper: #f5f4ee;
  --surface: #fffdf8;
  --surface-2: #f0efe6;
  --ink: #1b211d;
  --muted: #6d746c;
  --line: #e0dfd4;
  --line-strong: #bcbcae;
  --accent: #2f5d8a;
  --accent-soft: #e2ebf3;
  --gold: #b5842f;
  --serif: "Noto Serif SC", "Songti SC", "STSong", serif;
  --sans: "Noto Sans SC", -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #121614;
    --surface: #191f1b;
    --surface-2: #1d2420;
    --ink: #e9eeea;
    --muted: #95a099;
    --line: #2a322c;
    --line-strong: #48544c;
    --accent: #6fa6d6;
    --accent-soft: #1a2a38;
    --gold: #d3a55b;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 20px; }
body.lib-index, body.note-page {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-bottom: 40px;
}
a { color: var(--accent); }

/* ── 阅读页骨架 ─────────────────────────────────────────────── */
.lib-layout {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr) 200px;
  gap: 34px;
  max-width: 1200px;
  margin: 0 auto;
  padding: 26px 0 90px;
  align-items: start;
}
.lib-side {
  position: sticky;
  top: calc(var(--sb-h, 48px) + 16px);
  max-height: calc(100vh - var(--sb-h, 48px) - 32px);
  overflow: auto;
  padding-right: 8px;
  font-size: 13px;
  scrollbar-width: thin;
}
.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 8px;
}
.side-head > a {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 14px;
  color: var(--ink);
  text-decoration: none;
}
.side-toggle {
  display: none;
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--ink);
  border-radius: 5px;
  padding: 3px 8px;
  font: inherit;
}
.side-tree summary {
  cursor: pointer;
  padding: 3px 0;
  color: var(--ink);
  font-weight: 600;
  list-style: none;
}
.side-tree summary::-webkit-details-marker { display: none; }
.side-tree summary::before {
  content: "▸";
  display: inline-block;
  width: 14px;
  color: var(--muted);
  transition: transform .15s;
}
.side-tree details[open] > summary::before { transform: rotate(90deg); }
.side-tree ul { list-style: none; margin: 0; padding-left: 14px; }
.side-tree .leaf { display: block; padding: 2.5px 0 2.5px 14px; color: var(--muted); text-decoration: none; border-left: 2px solid transparent; }
.side-tree .leaf:hover { color: var(--ink); }
.side-tree .leaf.on { color: var(--accent); font-weight: 600; border-left-color: var(--accent); }
.side-group > .leaf { color: var(--ink); }

.note-main { min-width: 0; }
.crumbs { font-size: 12.5px; color: var(--muted); margin-bottom: 14px; }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--accent); }
.crumbs .sep { margin: 0 6px; opacity: .6; }

.note-head { border-bottom: 1px solid var(--line); padding-bottom: 16px; margin-bottom: 22px; }
.note-head h1 {
  font-family: var(--serif);
  font-size: clamp(24px, 4vw, 31px);
  line-height: 1.35;
  margin: 8px 0 10px;
  letter-spacing: .01em;
}
.badge {
  display: inline-block;
  font-size: 11px;
  line-height: 1.6;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  letter-spacing: .04em;
  white-space: nowrap;
}
.note-meta { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; font-size: 12.5px; color: var(--muted); }
.note-meta .tag { margin-right: 2px; }
.aliases { color: var(--muted); }

/* ── 正文排版 ─────────────────────────────────────────────── */
.prose { font-size: 15.5px; line-height: 1.85; overflow-wrap: break-word; }
.prose > *:first-child { margin-top: 0; }
.prose h1, .prose h2, .prose h3, .prose h4, .prose h5, .prose h6 {
  font-family: var(--serif);
  line-height: 1.4;
  margin: 1.6em 0 .6em;
  scroll-margin-top: calc(var(--sb-h, 48px) + 16px);
}
.prose h1 { font-size: 24px; }
.prose h2 { font-size: 21px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.prose h3 { font-size: 17.5px; }
.prose h4 { font-size: 16px; }
.prose p { margin: .72em 0; }
.prose ul, .prose ol { padding-left: 1.5em; margin: .6em 0; }
.prose li { margin: .2em 0; }
.prose blockquote {
  margin: 1em 0;
  padding: .2em 0 .2em 1em;
  border-left: 3px solid var(--line-strong);
  color: var(--muted);
}
.prose table { border-collapse: collapse; width: 100%; margin: 1em 0; font-size: 14px; display: block; overflow-x: auto; }
.prose th, .prose td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; vertical-align: top; }
.prose th { background: var(--surface-2); font-weight: 600; white-space: nowrap; }
.prose code {
  font-family: var(--mono);
  font-size: .88em;
  background: var(--surface-2);
  padding: .1em .35em;
  border-radius: 4px;
}
.prose pre.code {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px 14px;
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.6;
}
.prose pre.code code { background: none; padding: 0; }
.prose img { max-width: 100%; height: auto; border-radius: 4px; }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 2em 0; }
.prose mark { background: #f4e6a8; color: inherit; padding: 0 .1em; border-radius: 2px; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .prose mark { background: #5c5122; }
}
.prose .math-display {
  overflow-x: auto;
  overflow-y: hidden;
  padding: 4px 0;
  margin: .5em 0;
  scrollbar-width: thin;
}
/* 长公式（三对角矩阵、长和式）会横向超出：给条可见的细滚动条，免得看起来像被截断 */
.prose .math-display::-webkit-scrollbar,
.prose table::-webkit-scrollbar { height: 6px; }
.prose .math-display::-webkit-scrollbar-thumb,
.prose table::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 3px; }
.prose .math-display::-webkit-scrollbar-track,
.prose table::-webkit-scrollbar-track { background: transparent; }
.prose .katex { font-size: 1.05em; }
.prose .katex-display { margin: .6em 0; }
/* KaTeX 渲染失败时的兜底：直接显示原始 LaTeX，标红虚线框，不影响其它内容 */
.prose .math-error {
  font-family: var(--mono);
  font-size: .86em;
  line-height: 1.5;
  color: #a33a2c;
  background: #fbeeea;
  border: 1px dashed currentColor;
  border-radius: 3px;
  padding: .05em .35em;
  white-space: pre-wrap;
  word-break: break-word;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .prose .math-error { color: #d98a7c; background: #3a2622; }
}
.prose .mm-h {
  font-family: var(--serif);
  font-weight: 700;
  color: var(--accent);
  font-size: 1.02em;
}
.prose .mm-h2 { display: block; font-size: 1.18em; margin: .55em 0 .25em; }
.prose .mm-h3 { font-size: 1.06em; }
.prose .mm-h4, .prose .mm-h5, .prose .mm-h6 { color: var(--ink); font-weight: 600; font-size: .97em; }
.bid { display: inline-block; width: 0; height: 0; overflow: hidden; }
.prose .tpl {
  color: var(--muted);
  background: var(--surface-2);
  border: 1px dashed var(--line-strong);
  border-radius: 4px;
  padding: 0 .3em;
  font-size: .9em;
}
.tag {
  display: inline-block;
  font-size: 12px;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 8px;
  line-height: 1.75;
  font-family: var(--sans);
}
.deadlink {
  color: var(--muted);
  text-decoration: line-through;
  text-decoration-style: dashed;
  text-decoration-color: var(--line-strong);
  cursor: help;
}
.wl { text-decoration-color: color-mix(in srgb, var(--accent) 40%, transparent); text-underline-offset: 2px; }

/* 嵌入 */
.embed {
  border-left: 3px solid var(--accent-soft);
  background: color-mix(in srgb, var(--accent-soft) 35%, transparent);
  padding: 2px 14px 6px;
  margin: .9em 0;
  border-radius: 0 6px 6px 0;
}
.embed-src {
  font-size: 11.5px;
  color: var(--muted);
  margin: 4px 0 2px;
  letter-spacing: .02em;
}
.embed-src a { color: var(--muted); }
.embed .embed { background: transparent; }
.note-fig { margin: 1em 0; }
.note-fig figcaption { font-size: 12px; color: var(--muted); text-align: center; margin-top: 4px; }
.missing-img {
  border: 1px dashed var(--line-strong);
  border-radius: 6px;
  padding: 18px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  background: var(--surface-2);
  margin: 1em 0;
}

/* Callout */
.callout {
  --cc: #6d746c;
  --cb: #f0efe6;
  border-left: 3px solid var(--cc);
  background: var(--cb);
  border-radius: 0 6px 6px 0;
  padding: 10px 14px;
  margin: 1em 0;
}
.callout-title { color: var(--cc); font-weight: 700; font-size: 14px; margin-bottom: 2px; }
.callout-body > :first-child { margin-top: .2em; }
.callout-body > :last-child { margin-bottom: .2em; }
.callout summary { cursor: pointer; color: var(--cc); font-weight: 700; font-size: 14px; }
.callout-tip { --cc: #2e6b52; --cb: #e9f0eb; }
.callout-success { --cc: #2e6b52; --cb: #e9f0eb; }
.callout-note { --cc: #2f5d8a; --cb: #e8eff5; }
.callout-info { --cc: #2f5d8a; --cb: #e8eff5; }
.callout-abstract { --cc: #2f6f6a; --cb: #e4f0ee; }
.callout-summary { --cc: #2f6f6a; --cb: #e4f0ee; }
.callout-quote { --cc: #6d746c; --cb: #efeee6; }
.callout-example { --cc: #6d4c7d; --cb: #f0e9f3; }
.callout-help { --cc: #8a5a2f; --cb: #f4ece2; }
.callout-question { --cc: #a06a1f; --cb: #f6edd9; }
.callout-warning, .callout-caution, .callout-attention { --cc: #a33a2c; --cb: #f6e6e2; }
.callout-danger, .callout-failure, .callout-bug { --cc: #a33a2c; --cb: #f6e6e2; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .callout-tip,
  :root:not([data-theme="light"]) .callout-success { --cc: #67b98f; --cb: #16281f; }
  :root:not([data-theme="light"]) .callout-note,
  :root:not([data-theme="light"]) .callout-info { --cc: #6fa6d6; --cb: #18242f; }
  :root:not([data-theme="light"]) .callout-abstract,
  :root:not([data-theme="light"]) .callout-summary { --cc: #74c0b8; --cb: #142825; }
  :root:not([data-theme="light"]) .callout-quote { --cc: #95a099; --cb: #1c221e; }
  :root:not([data-theme="light"]) .callout-example { --cc: #c4a3d4; --cb: #241c28; }
  :root:not([data-theme="light"]) .callout-help,
  :root:not([data-theme="light"]) .callout-question { --cc: #d7a45b; --cb: #2a2114; }
  :root:not([data-theme="light"]) .callout-warning,
  :root:not([data-theme="light"]) .callout-caution,
  :root:not([data-theme="light"]) .callout-attention,
  :root:not([data-theme="light"]) .callout-danger,
  :root:not([data-theme="light"]) .callout-failure,
  :root:not([data-theme="light"]) .callout-bug { --cc: #e0735f; --cb: #2d1916; }
}

/* Dataview 占位 */
.dataview {
  border: 1px dashed var(--line-strong);
  border-radius: 6px;
  padding: 10px 14px;
  margin: 1em 0;
  background: var(--surface-2);
  font-size: 13.5px;
}
.dv-head { font-weight: 700; color: var(--muted); font-size: 13px; }
.dv-note { margin: 2px 0 6px; color: var(--muted); }
.dataview summary { cursor: pointer; color: var(--muted); font-size: 12.5px; }
.dataview pre { overflow-x: auto; font-size: 12px; }

/* 反链 / 翻页 */
.backlinks, .pager { margin-top: 34px; }
.backlinks h2 { font-family: var(--serif); font-size: 16px; margin-bottom: 8px; }
.backlinks ul { margin: 0; padding-left: 18px; color: var(--muted); }
.backlinks li { margin: 3px 0; }
.pager {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  border-top: 1px solid var(--line);
  padding-top: 16px;
  font-size: 13px;
}
.pager .pg { max-width: 46%; text-decoration: none; color: var(--ink); }
.pager .pg span { display: block; font-size: 11px; color: var(--muted); letter-spacing: .08em; }
.pager .next { text-align: right; margin-left: auto; }

/* 右侧本篇目录 */
.note-toc {
  position: sticky;
  top: calc(var(--sb-h, 48px) + 16px);
  max-height: calc(100vh - var(--sb-h, 48px) - 32px);
  overflow: auto;
  font-size: 12.5px;
  color: var(--muted);
}
.toc-title { font-weight: 700; color: var(--ink); font-size: 12px; letter-spacing: .08em; margin-bottom: 8px; }
.note-toc a { display: block; color: var(--muted); text-decoration: none; padding: 2.5px 0 2.5px 10px; border-left: 2px solid transparent; }
.note-toc a:hover { color: var(--ink); }
.note-toc a.h3 { padding-left: 22px; font-size: 12px; }
.note-toc a.on { color: var(--accent); border-left-color: var(--accent); }

/* ── 知识库首页 ───────────────────────────────────────────── */
.lib-wrap { max-width: 1000px; margin: 0 auto; padding: 34px 0 70px; }
/* 科目切换 */
.lib-tabs { display: flex; flex-wrap: wrap; gap: 7px; margin: 16px 0 4px; }
.lib-tab {
  appearance: none; cursor: pointer;
  font-family: var(--sans); font-size: 13px; line-height: 1;
  padding: 8px 16px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--muted);
  transition: color .15s, border-color .15s, background .15s;
}
.lib-tab:hover { color: var(--ink); border-color: var(--ink); }
.lib-tab.on { background: var(--ink); border-color: var(--ink); color: var(--paper); font-weight: 500; }
.lib-col[hidden] { display: none; }
/* 首页内容宽 1000，顶栏跟着收窄，品牌字与刊头左对齐 */
body.lib-index > .sitebar { max-width: 1000px; }
.lib-mast { display: flex; align-items: center; gap: 16px; padding-bottom: 22px; }
.lib-seal {
  width: 54px; height: 54px;
  display: grid; place-items: center;
  border: 2px solid var(--gold);
  border-radius: 6px;
  color: var(--gold);
  font-family: var(--serif);
  font-size: 28px;
  font-weight: 700;
  transform: rotate(-2deg);
  flex: none;
}
.lib-kicker { margin: 0; font-family: var(--mono); font-size: 10.5px; letter-spacing: .16em; color: var(--muted); }
.lib-mast h1 { margin: 2px 0 4px; font-family: var(--serif); font-size: clamp(26px, 4.4vw, 34px); letter-spacing: .02em; }
.lib-sub { margin: 0; font-size: 13px; color: var(--muted); }
.lib-search { position: sticky; top: var(--sb-h, 48px); z-index: 5; background: var(--paper); padding: 12px 0 10px; border-bottom: 1px solid var(--line); }
.lib-search input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  outline: none;
}
.lib-search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chips button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  border-radius: 999px;
  padding: 2px 10px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.chips button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .chips button.on { color: #0b1319; }
}
.results { margin-top: 18px; }
.result {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 9px 2px;
  border-bottom: 1px solid var(--line);
  text-decoration: none;
  color: var(--ink);
}
.result:hover { color: var(--accent); }
.result .r-title { font-weight: 600; }
.result .r-path { margin-left: auto; font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.result mark { background: #f4e6a8; color: inherit; }
.result-empty { color: var(--muted); padding: 20px 2px; }

.lib-col { margin-top: 34px; }
.lib-col > h2 {
  font-family: var(--serif);
  font-size: 20px;
  margin: 0 0 10px;
  padding-bottom: 7px;
  border-bottom: 1px solid var(--line-strong);
}
.lib-col > h2 small { margin-left: 8px; font-size: 12px; color: var(--muted); font-weight: 400; font-family: var(--sans); }
.chapter { border-bottom: 1px solid var(--line); }
.chapter > summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 2px;
  cursor: pointer;
  list-style: none;
  font-weight: 600;
}
.chapter > summary::-webkit-details-marker { display: none; }
.chapter > summary::before { content: "▸"; color: var(--muted); font-weight: 400; transition: transform .15s; }
.chapter[open] > summary::before { transform: rotate(90deg); }
.ch-name { flex: 1; }
.ch-count { font-size: 11.5px; color: var(--muted); background: var(--surface-2); border-radius: 999px; padding: 0 8px; font-weight: 400; }
.chapter ul { list-style: none; margin: 0 0 10px; padding: 0 0 0 20px; }
.chapter li { border-top: 1px dashed var(--line); }
.chapter li a {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 7px 2px;
  text-decoration: none;
  color: var(--ink);
  font-size: 14px;
}
.chapter li a:hover { color: var(--accent); }
.li-title { flex: 1; }
.chapter li .badge { font-size: 10px; opacity: .9; }
/* 只有一章的分组（英语一 / 模板）不套折叠框，直接铺开 */
.lib-col ul.plain { list-style: none; margin: 0; padding: 0 0 0 20px; border-bottom: 1px solid var(--line); }
.lib-col ul.plain li { border-top: 1px dashed var(--line); }
.lib-col ul.plain li:first-child { border-top: 0; }
.lib-col ul.plain li a {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 7px 2px;
  text-decoration: none;
  color: var(--ink);
  font-size: 14px;
}
.lib-col ul.plain li a:hover { color: var(--accent); }
.lib-col ul.plain li .badge { font-size: 10px; opacity: .9; }
.lib-foot { margin-top: 46px; padding-top: 16px; border-top: 1px solid var(--line); font-size: 12.5px; color: var(--muted); }
.lib-foot p { margin: 3px 0; }
.empty { color: var(--muted); }

/* ── 响应式 ───────────────────────────────────────────────── */
@media (max-width: 1120px) {
  .lib-layout { grid-template-columns: 220px minmax(0, 1fr); }
  .note-toc { display: none; }
}
@media (max-width: 820px) {
  .lib-layout { grid-template-columns: minmax(0, 1fr); padding-top: 14px; }
  .lib-side {
    position: fixed;
    inset: 0 auto 0 0;
    width: 280px;
    max-height: none;
    background: var(--surface);
    border-right: 1px solid var(--line);
    padding: 16px;
    transform: translateX(-102%);
    transition: transform .2s ease;
    z-index: 30;
    box-shadow: 0 0 40px rgba(0, 0, 0, .18);
  }
  .lib-side.open { transform: none; }
  .side-toggle { display: inline-block; }
  .lib-mast { gap: 12px; }
  .lib-seal { width: 46px; height: 46px; font-size: 24px; }
  .pager { flex-direction: column; }
  .pager .pg, .pager .next { max-width: none; text-align: left; }
}
@media print {
  .sitebar, .lib-side, .note-toc, .pager, .backlinks { display: none; }
  .lib-layout { display: block; }
}

/* 侧栏常驻搜索 */
.side-search {
  position: relative;
  margin: 0 0 10px;
}
.side-search input {
  width: 100%;
  box-sizing: border-box;
  appearance: none;
  font-family: var(--sans);
  font-size: 13px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--paper);
  color: var(--ink);
}
.side-search input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
}
.side-search input::placeholder { color: var(--muted); }
.side-results {
  position: absolute;
  z-index: 20;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  max-height: 320px;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 18px 40px -22px rgba(20, 30, 25, .5);
  padding: 4px;
}
.side-results[hidden] { display: none; }
.side-results a {
  display: block;
  padding: 6px 8px;
  border-radius: 4px;
  text-decoration: none;
  color: var(--ink);
}
.side-results a:hover { background: var(--paper); }
.side-results a b {
  display: block;
  font-weight: 600;
  font-size: 12.5px;
  line-height: 1.4;
}
.side-results a span {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-top: 1px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.side-results .sr-empty {
  margin: 0;
  padding: 10px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}
