/* 由 build_split.py 从源文件 <style> 原样抽出，请勿手工编辑 */
:root {
  --fg: #24292f;
  --fg-muted: #57606a;
  --bg: #ffffff;
  --bg-soft: #f6f8fa;
  --border: #d0d7de;
  --border-soft: #eaecef;
  --link: #0969da;
  --sidebar-w: 280px;
  --content-w: 780px;
  --gap: 48px;
}

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; scroll-padding-top: 1em; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Segoe UI", "Microsoft YaHei",
               "Helvetica Neue", Arial, sans-serif;
  line-height: 1.75;
  color: var(--fg);
  margin: 0;
  background: var(--bg);
  font-size: 16px;
}

/* ===== 整体布局 ===== */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, var(--content-w));
  column-gap: var(--gap);
  max-width: calc(var(--sidebar-w) + var(--content-w) + var(--gap) + 80px);
  margin: 0 auto;
  padding: 40px 24px 80px 24px;
}

/* ===== 左侧目录 (desktop) ===== */
.toc-sidebar {
  position: sticky;
  top: 24px;
  align-self: start;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  font-size: 14px;
  padding-right: 8px;
  border-right: 1px solid var(--border-soft);
}
.toc-sidebar h2 {
  margin: 0 0 12px 0;
  padding: 0;
  border: 0;
  font-size: 14px;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.toc-sidebar ul { list-style: none; padding: 0; margin: 0; }
.toc-sidebar li { margin: 0; line-height: 1.5; }
.toc-sidebar a {
  display: block;
  padding: 5px 10px;
  margin: 1px 0;
  color: var(--fg-muted);
  border-left: 2px solid transparent;
  text-decoration: none;
  word-break: break-word;
  border-radius: 0 4px 4px 0;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}
.toc-sidebar a:hover { color: var(--link); background: var(--bg-soft); }
.toc-sidebar .toc-h3 { padding-left: 24px; font-size: 13px; }
.toc-sidebar a.active {
  color: var(--link);
  border-left-color: var(--link);
  background: var(--bg-soft);
  font-weight: 600;
}

/* Sidebar 美化滚动条 */
.toc-sidebar::-webkit-scrollbar { width: 6px; }
.toc-sidebar::-webkit-scrollbar-track { background: transparent; }
.toc-sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ===== 移动端：顶部折叠目录 ===== */
.toc-mobile {
  display: none;
  margin: 0 0 24px 0;
  padding: 10px 14px;
  background: var(--bg-soft);
  border: 1px solid var(--border-soft);
  border-radius: 8px;
}
.toc-mobile summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--fg-muted);
  user-select: none;
  list-style: none;
  padding: 4px 0;
}
.toc-mobile summary::before { content: "▸ "; display: inline-block; transition: transform 0.2s; }
.toc-mobile[open] summary::before { transform: rotate(90deg); }
.toc-mobile ul { list-style: none; padding: 0; margin: 8px 0 0 0; }
.toc-mobile li { margin: 2px 0; }
.toc-mobile a { display: block; padding: 4px 8px; color: var(--fg); text-decoration: none; border-radius: 4px; }
.toc-mobile a:hover { background: var(--bg); }
.toc-mobile .toc-h3 { padding-left: 24px; font-size: 14px; color: var(--fg-muted); }

/* ===== 内容区排版 ===== */
.content { min-width: 0; }
.content h1, .content h2, .content h3, .content h4 {
  margin-top: 2em;
  margin-bottom: 0.5em;
  line-height: 1.3;
}
.content h1 { font-size: 2em; margin-top: 0; }
.content h2 { font-size: 1.5em; }
.content h3 { font-size: 1.2em; }
.content h4 { font-size: 1.05em; color: var(--fg-muted); }
.content p { margin: 0.6em 0; }
.content a { color: var(--link); text-decoration: none; }
.content a:hover { text-decoration: underline; }

blockquote {
  border-left: 4px solid var(--border);
  padding: 0.25em 1em;
  color: var(--fg-muted);
  margin: 1em 0;
  background: var(--bg-soft);
  border-radius: 0 6px 6px 0;
}
code {
  font-family: "SF Mono", Menlo, Consolas, monospace;
  background: rgba(175,184,193,0.2);
  padding: 0.2em 0.4em;
  border-radius: 4px;
  font-size: 0.88em;
}
pre { background: var(--bg-soft); padding: 16px; border-radius: 6px; overflow-x: auto; }
pre code { background: transparent; padding: 0; font-size: 0.88em; line-height: 1.5; }

img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 1.2em auto 0.3em auto;
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
img + em, p > em:only-child {
  display: block;
  text-align: center;
  color: var(--fg-muted);
  font-size: 0.9em;
  margin: 0 auto 1.5em auto;
  max-width: 720px;
  line-height: 1.6;
}
/* 参考文献：悬挂缩进 + 清晰的段间距，让每条独立成行 */
p.ref {
  margin: 0.75em 0;
  padding-left: 2.5em;
  text-indent: -2.5em;
  line-height: 1.65;
  font-size: 0.95em;
  text-align: left;  /* 避免被 p > em:only-child 的居中规则影响 */
}
/* 覆盖前面"图注 em"的 display:block 规则 —— 参考文献里的 em 是行内标题 */
p.ref em {
  display: inline;
  text-align: inherit;
  color: inherit;
  font-size: inherit;
  margin: 0;
  max-width: none;
  line-height: inherit;
}

table { border-collapse: collapse; margin: 1em 0; }
th, td { border: 1px solid var(--border); padding: 6px 13px; }
th { background: var(--bg-soft); font-weight: 600; }
.dchip { display: inline-block; padding: 0 7px; margin: 1px 1px; border-radius: 10px;
  font-size: 12px; line-height: 1.65; color: #fff; white-space: nowrap; vertical-align: middle; }
.dnote { font-size: 0.9em; color: var(--fg-muted); margin: 0.4em 0 0.8em 0; }
.playbook { margin: 0.6em 0 0.2em 0; padding-left: 1.4em; }
.playbook li { margin: 0.35em 0; line-height: 1.6; }
hr { border: 0; height: 1px; background: var(--border); margin: 2em 0; }
ul, ol { padding-left: 2em; }
li { margin: 0.25em 0; }

/* 内联 SVG 的外框容器（导览图等） */
.figbox {
  margin: 1.2em auto 0.3em auto;
  max-width: 900px;
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  background: #fff;
  padding: 8px;
}

.mermaid {
  text-align: center;
  margin: 1.5em 0;
  background: #fafbfc;
  padding: 1em;
  border-radius: 6px;
  border: 1px solid var(--border-soft);
}
.mermaid svg { max-width: 100%; height: auto !important; }
.katex-display { overflow-x: auto; overflow-y: hidden; padding: 0.2em 0; }

/* ===== 响应式 ===== */
@media (max-width: 1199px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    max-width: 860px;
  }
  .toc-sidebar { display: none; }
  .toc-mobile { display: block; }
}

/* ===== 暗黑模式 ===== */
@media (prefers-color-scheme: dark) {
  :root {
    --fg: #c9d1d9;
    --fg-muted: #8b949e;
    --bg: #0d1117;
    --bg-soft: #161b22;
    --border: #30363d;
    --border-soft: #30363d;
    --link: #58a6ff;
  }
  body { background: var(--bg); color: var(--fg); }
  code { background: rgba(110,118,129,0.4); }
  .mermaid { background: #161b22; }

  /* 图片与内联 SVG 都是浅色底稿（满幅白底 + 深色文字）。这里只做温和降亮 + 加边框，
     把"深色页面上的白色亮块"压成一张可接受的浅色图卡；刻意不做 invert，
     否则图内的深色文字与配色会失真、反而更难读。 */
  .content img,
  .content > svg,
  .content .figbox {
    filter: brightness(0.84) contrast(0.94);
  }
  .content > svg {
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fff;
  }
  .content .figbox { background: #fff; box-shadow: none; }
  /* 需要看清细节时，悬停恢复原亮度 */
  .content img:hover,
  .content > svg:hover,
  .content .figbox:hover { filter: none; }
}

/* 默认折叠的注释块（如"第 6 章证据与口径注"）；注角标跳转时由页尾脚本自动展开 */
details.notes-fold {
  margin: 0.8em 0 1.4em 0;
  padding: 0 14px;
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  background: var(--bg-soft);
}
details.notes-fold > summary {
  cursor: pointer;
  padding: 10px 0;
  color: var(--link);
  font-weight: 600;
  font-size: 0.95em;
  user-select: none;
}
details.notes-fold > summary:hover { text-decoration: underline; }
details.notes-fold[open] { padding-bottom: 6px; }
details.notes-fold[open] > summary { border-bottom: 1px solid var(--border-soft); margin-bottom: 0.4em; }
details.notes-fold .dnote:target { background: var(--bg); outline: 2px solid var(--link); outline-offset: 3px; border-radius: 4px; }
