/* ============================================================
   《纠缠理论的数学基础》阅读版样式
   设计：克制的学术排版 —— 白纸、细线、单一强调色
   ============================================================ */

:root {
  --ink: #1b1b1f;
  --ink-2: #3d3d45;
  --ink-3: #6b6b76;
  --muted: #8e8e99;
  --line: #e7e6e1;
  --line-2: #f0efeb;
  --bg: #fbfaf7;
  --paper: #ffffff;
  --accent: #1d4e6f;
  --accent-soft: #eef4f8;
  --thm: #2f6b4f;
  --thm-bg: #f4f8f5;
  --proof: #6a6a74;
  --warn: #a8562b;
  --radius: 8px;
  --sidebar-w: 272px;
  --serif: "Source Han Serif SC", "Noto Serif SC", "Songti SC", "SimSun", Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 16.5px;
  line-height: 1.78;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }

/* ---------------------------------------------------------- 顶栏 */
.topbar {
  position: sticky; top: 0; z-index: 40;
  background: rgba(251, 250, 247, .88);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1180px; margin: 0 auto; padding: 0 28px;
  height: 56px; display: flex; align-items: center; justify-content: space-between;
  font-family: var(--sans);
}
.brand {
  font-size: 15px; font-weight: 600; letter-spacing: .12em;
  color: var(--ink); text-decoration: none;
}
.brand:hover { text-decoration: none; color: var(--accent); }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a {
  font-size: 13.5px; color: var(--ink-3); padding: 6px 12px; border-radius: 999px;
  transition: background .16s, color .16s;
}
.topbar nav a:hover { background: var(--line-2); color: var(--ink); text-decoration: none; }
.topbar nav a.on { color: var(--ink); background: var(--line-2); }

/* ---------------------------------------------------------- 布局 */
.layout {
  max-width: 1180px; margin: 0 auto; padding: 0 28px;
  display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); gap: 48px;
}

/* ---------------------------------------------------------- 侧边栏 */
.sidebar {
  position: sticky; top: 56px; align-self: start;
  max-height: calc(100vh - 56px); overflow-y: auto;
  padding: 30px 0 60px;
  font-family: var(--sans);
  scrollbar-width: thin;
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: #ddd; border-radius: 3px; }

.sb-home {
  display: inline-block; margin-bottom: 18px;
  font-size: 12.5px; color: var(--muted); letter-spacing: .04em;
}
.sb-book {
  display: block; margin-bottom: 22px; padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
  font-size: 14.5px; font-weight: 600; color: var(--ink); line-height: 1.5;
}
.sb-book:hover { color: var(--accent); text-decoration: none; }

.sb-part { margin-bottom: 16px; }
.sb-part-title {
  font-size: 11px; letter-spacing: .1em; color: var(--muted);
  text-transform: uppercase; margin-bottom: 6px;
}
.sb-ch {
  display: flex; gap: 8px; align-items: baseline;
  padding: 4px 10px 4px 8px; border-radius: 6px;
  font-size: 13.2px; color: var(--ink-2); line-height: 1.55;
  border-left: 2px solid transparent;
}
.sb-ch:hover { background: var(--line-2); text-decoration: none; color: var(--ink); }
.sb-ch.active {
  background: var(--accent-soft); color: var(--accent);
  border-left-color: var(--accent); font-weight: 600;
}
.sb-num {
  flex: 0 0 auto; min-width: 14px; font-size: 11px; color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.sb-ch.active .sb-num { color: var(--accent); }

.sb-toc { margin-top: 26px; padding-top: 18px; border-top: 1px solid var(--line); }
.sb-toc-title { font-size: 11px; letter-spacing: .1em; color: var(--muted); text-transform: uppercase; margin-bottom: 8px; }
.sb-sec {
  display: flex; gap: 7px; align-items: baseline;
  padding: 3px 8px; border-radius: 5px;
  font-size: 12.8px; color: var(--ink-3); line-height: 1.5;
}
.sb-sec .sb-num { font-size: 10.5px; }
.sb-sec:hover { background: var(--line-2); color: var(--ink); text-decoration: none; }

/* ---------------------------------------------------------- 正文 */
.content { min-width: 0; padding: 34px 0 90px; max-width: 780px; }

.crumb {
  font-family: var(--sans); font-size: 12.5px; color: var(--muted);
  display: flex; gap: 8px; align-items: center; margin-bottom: 18px;
}
.crumb a { color: var(--muted); }
.crumb a:hover { color: var(--accent); }
.crumb span { color: #cfcec9; }

.chapter-title {
  font-size: 30px; line-height: 1.35; font-weight: 600; letter-spacing: .01em;
  margin: 0 0 8px; color: var(--ink);
}
.chapter-meta {
  font-family: var(--sans); font-size: 12.5px; color: var(--muted);
  letter-spacing: .04em; margin-bottom: 34px;
  padding-bottom: 18px; border-bottom: 1px solid var(--line);
}

.note { font-size: 16.5px; }
.note p { margin: 0 0 1.05em; }
.note > p:first-of-type { margin-top: 0; }

/* 中文段落首行不缩进，靠段距分隔；但连续正文保持舒适行宽 */
.note p, .note li { text-align: justify; text-justify: inter-ideograph; }

.section-title {
  font-size: 21px; font-weight: 600; line-height: 1.4;
  margin: 2.4em 0 .9em; padding-top: .2em;
  display: flex; align-items: baseline; gap: 10px;
  scroll-margin-top: 76px;
}
.sec-num {
  font-family: var(--sans); font-size: 12px; font-weight: 600;
  color: var(--accent); background: var(--accent-soft);
  border-radius: 4px; padding: 2px 7px; line-height: 1.6;
  flex: 0 0 auto; transform: translateY(-2px);
}
.subsection-title {
  font-size: 17.5px; font-weight: 600; color: var(--ink-2);
  margin: 1.9em 0 .7em; scroll-margin-top: 76px;
}
.subsubsection-title {
  font-size: 15.5px; font-weight: 600; color: var(--ink-2);
  margin: 1.6em 0 .5em; scroll-margin-top: 76px;
}

/* ---------------------------------------------------------- 定理环境 */
.thm {
  margin: 1.35em 0; padding: 0;
  border-radius: var(--radius);
  background: var(--paper);
  border: 1px solid var(--line);
  border-left: 3px solid var(--thm);
  overflow: hidden;
  scroll-margin-top: 76px;
}
.thm-head {
  display: flex; align-items: baseline; gap: 7px; flex-wrap: wrap;
  padding: 9px 16px 9px 15px;
  background: var(--thm-bg);
  border-bottom: 1px solid var(--line-2);
  font-family: var(--sans);
}
.thm-name { font-size: 13.5px; font-weight: 700; color: var(--thm); letter-spacing: .04em; }
.thm-num { font-size: 12.5px; font-weight: 600; color: var(--thm); font-variant-numeric: tabular-nums; }
.thm-title { font-size: 13px; color: var(--ink-3); }
.thm-body { padding: 13px 18px 4px; font-size: 16px; }
.thm-body > p:last-child { margin-bottom: .85em; }
.thm-body .thm { margin: 1em 0; }

/* 各类环境配色 */
.thm-definition { border-left-color: #1d4e6f; }
.thm-definition .thm-head { background: var(--accent-soft); }
.thm-definition .thm-name, .thm-definition .thm-num { color: var(--accent); }

.thm-theorem, .thm-proposition, .thm-lemma, .thm-corollary { border-left-color: var(--thm); }
.thm-axiom { border-left-color: #7a5c1e; }
.thm-axiom .thm-head { background: #faf6ec; }
.thm-axiom .thm-name, .thm-axiom .thm-num { color: #7a5c1e; }

.thm-example { border-left-color: #8a5a9a; background: #fdfbfe; }
.thm-example .thm-head { background: #f8f2fb; }
.thm-example .thm-name, .thm-example .thm-num { color: #8a5a9a; }

.thm-remark {
  border-left-color: #b8b7b0; background: #fcfcfa;
}
.thm-remark .thm-head { background: #f7f7f4; }
.thm-remark .thm-name { color: var(--ink-3); }

/* 证明 */
.thm-proof {
  margin: 1.2em 0; padding: 0 0 0 16px;
  border-left: 2px solid #dcdcd6;
  font-size: 15.8px; color: #2c2c33;
}
.thm-proof .thm-head {
  background: none; border: 0; padding: 0 0 4px;
}
.thm-proof .thm-name {
  font-size: 13px; font-weight: 700; color: var(--proof); letter-spacing: .18em;
}
.thm-proof .thm-body { padding: 0; }
.thm-proof .thm-body > p:last-child { margin-bottom: .8em; }

/* ---------------------------------------------------------- 公式 */
.eq {
  display: grid; grid-template-columns: minmax(0, 1fr) auto;
  align-items: center; column-gap: 12px;
  margin: 1.15em 0; position: relative;
  scroll-margin-top: 80px;
}
.eq-body { min-width: 0; overflow-x: auto; overflow-y: hidden; padding: 2px 0; }
.eq-body .katex-display { margin: .2em 0; }
.eq-num {
  font-family: var(--sans); font-size: 12.5px; color: var(--ink-3);
  font-variant-numeric: tabular-nums; letter-spacing: .02em;
  white-space: nowrap; user-select: none;
}
.eq-group { margin: 1.2em 0; }
.eq-group .eq { margin: .25em 0; }
.eq:target { background: #fffdf0; }

.katex { font-size: 1.03em; }
.katex-display > .katex { font-size: 1.06em; }

/* 行内公式容器 */
.m { white-space: nowrap; }

math-err, .math-err {
  font-family: var(--mono); font-size: 12.5px; color: var(--warn);
  background: #fdf3ec; border: 1px dashed #e5b79a; border-radius: 4px;
  padding: 1px 6px; white-space: pre-wrap; word-break: break-all;
}

/* ---------------------------------------------------------- 列表 */
.list { margin: .7em 0 1.1em; padding-left: 1.55em; }
.list li { margin: .3em 0; }
.list li > p { margin-bottom: .35em; }
ul.bullet { list-style: none; padding-left: 1.3em; }
ul.bullet > li { position: relative; }
ul.bullet > li::before {
  content: ""; position: absolute; left: -1em; top: .72em;
  width: 5px; height: 5px; border-radius: 50%; background: #c3c2ba;
}
ol.list { list-style: none; counter-reset: item; padding-left: 1.9em; }
ol.list > li { position: relative; counter-increment: item; }
ol.list > li::before {
  content: "(" counter(item) ")"; position: absolute; left: -1.9em; top: 0;
  font-family: var(--sans); font-size: .82em; color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.list.depth-0 { padding-left: 1.55em; }
.list.depth-0 > li::before { font-size: .86em; }

/* ---------------------------------------------------------- 引用/脚注/文献 */
.ref { border-bottom: 1px solid rgba(29, 78, 111, .28); }
.ref:hover { text-decoration: none; border-bottom-color: var(--accent); }
.ref.dangling {
  color: var(--warn); border-bottom: 1px dashed #d9b49b; cursor: help;
  background: #fdf6f1; padding: 0 3px; border-radius: 3px;
}
.cite { font-family: var(--sans); font-size: .78em; }
.cite a { color: var(--accent); }
sup.fn { font-family: var(--sans); font-size: .72em; line-height: 0; }
sup.fn a {
  padding: 1px 4px; border-radius: 4px; background: var(--line-2); color: var(--ink-3);
}
sup.fn a:hover { background: var(--accent-soft); color: var(--accent); text-decoration: none; }

.footnotes {
  margin-top: 46px; padding-top: 18px; border-top: 1px solid var(--line);
  font-size: 13.6px; color: var(--ink-3); font-family: var(--sans);
}
.footnotes ol { padding-left: 1.6em; margin: 0; }
.footnotes li { margin: .45em 0; line-height: 1.65; }
.footnotes li:target { background: #fffdf0; }

.center { text-align: center; margin: 1.1em 0; }

/* ---------------------------------------------------------- 翻页 */
.pager {
  display: grid; grid-template-columns: 1fr 1fr; gap: 14px;
  margin-top: 64px; font-family: var(--sans);
}
.pager a {
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 13px 16px; background: var(--paper);
  transition: border-color .16s, transform .16s, box-shadow .16s;
  min-width: 0;
}
.pager a:hover {
  text-decoration: none; border-color: #cfcec6;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .04);
}
.pager-label { display: block; font-size: 11px; color: var(--muted); letter-spacing: .08em; margin-bottom: 3px; }
.pager-title {
  display: block; font-size: 14.5px; color: var(--ink); font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.pager-next { text-align: right; }

.page-foot {
  margin-top: 40px; padding-top: 18px; border-top: 1px solid var(--line);
  font-family: var(--sans); font-size: 12px; color: var(--muted); letter-spacing: .03em;
}

/* ---------------------------------------------------------- 资料大纲页 */
.outline {
  max-width: 880px; margin: 0 auto; padding: 46px 28px 100px;
}
.outline-hero {
  display: grid; grid-template-columns: 1fr 190px; gap: 40px; align-items: center;
  padding-bottom: 34px; border-bottom: 1px solid var(--line); margin-bottom: 14px;
}
.oh-text h1 {
  font-size: 32px; line-height: 1.32; margin: 0 0 8px; font-weight: 600; letter-spacing: .01em;
}
.oh-sub {
  font-family: var(--sans); font-size: 12.5px; letter-spacing: .1em;
  color: var(--muted); text-transform: uppercase; margin: 0 0 16px;
}
.oh-desc { font-size: 15px; line-height: 1.85; color: var(--ink-2); margin: 0 0 18px; max-width: 46em; }
.oh-desc em { font-style: normal; font-family: var(--sans); font-weight: 600; }
.oh-stats { display: flex; gap: 10px; flex-wrap: wrap; font-family: var(--sans); margin-bottom: 22px; }
.oh-stats span {
  font-size: 12px; color: var(--ink-3); background: var(--paper);
  border: 1px solid var(--line); border-radius: 999px; padding: 4px 13px;
}
.oh-actions { display: flex; gap: 24px; margin: 0; flex-wrap: wrap; }
.oh-actions a {
  font-family: var(--sans); font-size: 13.5px; font-weight: 500; color: var(--accent);
  display: inline-flex; align-items: center; gap: 6px;
}
.oh-actions a:hover .arrow { transform: translateX(4px); }
.oh-actions .arrow { transition: transform .2s; }
.oh-cover {
  width: 190px; border-radius: var(--radius); display: block;
  box-shadow: 0 6px 26px rgba(30, 40, 60, .16);
  border: 1px solid rgba(0, 0, 0, .06);
}

.parts { margin-top: 8px; }
.part { padding: 30px 0 10px; border-bottom: 1px solid var(--line-2); }
.part:last-child { border-bottom: 0; }
.part-pre { padding-top: 22px; }
.part-head {
  display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap;
  margin-bottom: 18px;
}
.part-cn {
  font-family: var(--sans); font-size: 11px; letter-spacing: .12em;
  color: var(--accent); background: var(--accent-soft);
  border-radius: 4px; padding: 3px 8px; text-transform: uppercase;
}
.part-head h2 { font-size: 21px; font-weight: 600; margin: 0; letter-spacing: .01em; }
.part-sub {
  font-family: var(--sans); font-size: 11.5px; color: var(--muted);
  letter-spacing: .08em; text-transform: uppercase;
}

.ch-list { display: flex; flex-direction: column; }
.ch-card {
  padding: 12px 0 13px 14px; border-left: 2px solid var(--line-2);
  transition: border-color .16s, background .16s;
}
.ch-card:hover { border-left-color: var(--accent); background: rgba(29, 78, 111, .022); }
.ch-line { display: flex; align-items: baseline; gap: 12px; text-decoration: none; }
.ch-line:hover { text-decoration: none; }
.ch-num {
  font-family: var(--sans); font-size: 12px; font-weight: 600; color: var(--muted);
  min-width: 18px; font-variant-numeric: tabular-nums;
}
.ch-title { font-size: 16.5px; color: var(--ink); font-weight: 600; flex: 1 1 auto; }
.ch-line:hover .ch-title { color: var(--accent); }
.ch-secs {
  font-family: var(--sans); font-size: 11.5px; color: var(--muted);
  flex: 0 0 auto; letter-spacing: .04em;
}
.ch-toc {
  display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 7px 0 0 30px;
  font-family: var(--sans);
}
.ch-toc a {
  font-size: 12.6px; color: var(--ink-3); padding: 1px 0;
  border-bottom: 1px solid transparent;
}
.ch-toc a:hover { color: var(--accent); border-bottom-color: rgba(29, 78, 111, .3); text-decoration: none; }

/* ---------------------------------------------------------- 杂项 */
.tex-cmd {
  font-family: var(--mono); font-size: .88em; color: var(--warn);
  background: #fdf6f1; border-radius: 3px; padding: 0 3px;
}
.unknown-env {
  border: 1px dashed #d9b49b; border-radius: 6px; padding: 10px 12px;
  background: #fdf6f1; font-family: var(--sans); font-size: 13px; color: var(--warn);
}
.nobreak { white-space: nowrap; }
.op-symbol, .text, .mathrm, .mathcal, .mathbb, .mathscr, .mathfrak { font-style: normal; }

/* 标题锚点 */
.anchor-link {
  opacity: 0; margin-left: 8px; font-family: var(--sans); font-size: .68em;
  color: var(--muted); text-decoration: none; transition: opacity .16s;
}
.section-title:hover .anchor-link,
.subsection-title:hover .anchor-link,
.anchor-link:focus { opacity: 1; }
.anchor-link:hover { color: var(--accent); text-decoration: none; }

.sb-sec.cur {
  background: var(--accent-soft); color: var(--accent);
  font-weight: 600;
}

.to-top {
  position: fixed; right: 26px; bottom: 26px; z-index: 50;
  width: 38px; height: 38px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--paper); color: var(--ink-3);
  font-size: 15px; line-height: 1; cursor: pointer;
  font-family: var(--sans);
  opacity: 0; transform: translateY(8px); pointer-events: none;
  transition: opacity .2s, transform .2s, border-color .2s, color .2s;
  box-shadow: 0 2px 12px rgba(0, 0, 0, .06);
}
.to-top.show { opacity: 1; transform: none; pointer-events: auto; }
.to-top:hover { border-color: #cfcec6; color: var(--accent); }

/* ---------------------------------------------------------- 响应式 */

/* 窄屏下允许超长行内公式折行，避免整页横向溢出 */
@media (max-width: 1100px) {
  .m,
  .m .katex,
  .m .katex-html,
  .m .katex-base { white-space: normal; }
}

@media (max-width: 1000px) {
  .layout { grid-template-columns: 1fr; gap: 0; padding: 0 22px; }
  .sidebar {
    position: static; max-height: none; overflow: visible;
    padding: 22px 0 6px; border-bottom: 1px solid var(--line);
  }
  .sb-chapters { display: none; }
  .sb-toc { display: none; }
  .sb-book { margin-bottom: 10px; padding-bottom: 10px; border-bottom: 0; }
  .content { padding-top: 24px; max-width: none; }
}
@media (max-width: 720px) {
  body { font-size: 16px; }
  .topbar-inner { padding: 0 18px; height: 52px; }
  .layout { padding: 0 18px; }
  .outline { padding: 30px 18px 80px; }
  .outline-hero { grid-template-columns: 1fr; gap: 22px; }
  .oh-cover { width: 148px; order: -1; }
  .oh-text h1 { font-size: 25px; }
  .chapter-title { font-size: 24px; }
  .section-title { font-size: 19px; }
  .thm-body { padding: 12px 14px 2px; }
  .thm-head { padding: 8px 14px; }
  .pager { grid-template-columns: 1fr; }
  .pager-next { text-align: left; }
  .ch-toc { margin-left: 0; }
  .ch-card { padding-left: 10px; }
}

@media print {
  .topbar, .sidebar, .pager, .page-foot { display: none; }
  .layout { display: block; padding: 0; }
  .content { max-width: none; padding: 0; }
  body { background: #fff; font-size: 11pt; }
  .thm { break-inside: avoid; }
}
