/* 杂志式排版:标题衬线、正文无衬线、暖白底、中性灰激活、两侧虚线导引、右侧嵌套 TOC。 */
:root {
  --bg: #fdfdfc;
  --fg: #1c1c1c;
  --muted: #565654;
  --faint: #8a8a86;
  --line: #e7e6e2;
  --line-dash: #dcdbd6;
  --active-bg: #ececeb;          /* 中性灰,非暖选中态 */
  --hover-bg: #f3f2ef;
  --code-bg: #f0efeb;
  --code-fg: #37363270;
  --link: #1a1a1a;
  --blue: #2563eb;
  --serif: Charter, "Bitstream Charter", "Sitka Text", "Iowan Old Style", Cambria, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", "PingFang SC", "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
  --mono: "SF Mono", ui-monospace, Menlo, Consolas, "Liberation Mono", monospace;
  --top-h: 58px; --side-w: 288px; --toc-w: 256px; --page-max: 1680px; --content-max: 720px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--sans); color: var(--fg); background: var(--bg);
  font-size: 15.5px; line-height: 1.7; -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
a { color: var(--link); text-decoration: none; }

/* ── 顶栏 ── */
#topbar {
  height: var(--top-h); display: flex; align-items: center; justify-content: space-between;
  max-width: var(--page-max); margin: 0 auto; padding: 0 28px;
  border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--bg); z-index: 20;
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand .logo { font-weight: 700; font-size: 18px; letter-spacing: -.02em; color: var(--fg); }
.brand #repo-name { font-weight: 400; color: var(--muted); font-size: 15px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
#search { border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px; font-size: 13px; width: 200px; outline: none; background: #fff; color: var(--fg); font-family: var(--sans); }
#search:focus { border-color: var(--faint); }
#lang-toggle { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 7px 14px; cursor: pointer; font-size: 13px; font-weight: 500; color: var(--fg); font-family: var(--sans); }
#lang-toggle:hover { background: var(--hover-bg); }

/* ── 三栏 + 两侧虚线导引 ── */
#layout { display: flex; height: calc(100vh - var(--top-h)); max-width: var(--page-max); margin: 0 auto; border-left: 1px dashed var(--line-dash); border-right: 1px dashed var(--line-dash); }
#sidebar { width: var(--side-w); flex: 0 0 var(--side-w); overflow-y: auto; padding: 24px 12px 80px 26px; border-right: 1px solid var(--line); }
#content { flex: 1; overflow-y: auto; padding: 30px 56px 160px; min-width: 0; }
#content-inner { max-width: var(--content-max); }
#toc { width: var(--toc-w); flex: 0 0 var(--toc-w); overflow-y: auto; padding: 32px 26px 80px 8px; border-left: 1px solid var(--line); }
@media (max-width: 1180px) { #toc { display: none; } }
@media (max-width: 900px) { #sidebar { display: none; } }

/* ── 左 nav ── */
.side-head { font-size: 12px; color: var(--faint); margin-bottom: 18px; line-height: 1.4; }
#nav-list { list-style: none; margin: 0; padding: 0; }
#nav-list li.top { font-size: 14px; font-weight: 600; color: var(--fg); padding: 9px 8px 5px; cursor: default; letter-spacing: -.005em; }
#nav-list li.top.clickable { cursor: pointer; border-radius: 7px; }
#nav-list li.top.clickable:hover { background: var(--hover-bg); }
#nav-list li.top.domain { margin-top: 6px; }
#nav-list li.page, #nav-list li.subanchor { padding: 6px 8px 6px 20px; cursor: pointer; font-size: 13.5px; font-weight: 400; color: var(--muted); line-height: 1.45; border-radius: 7px; }
#nav-list li.page:hover, #nav-list li.subanchor:hover { color: var(--fg); background: var(--hover-bg); }
#nav-list li.page.active, #nav-list li.top.active { color: var(--fg); font-weight: 500; background: var(--active-bg); }
#nav-list li.hidden { display: none; }
#nav-list li .cx { display: inline-block; width: 12px; color: var(--faint); font-size: 10px; }
#nav-list li .num { color: var(--faint); font-variant-numeric: tabular-nums; margin-right: 6px; font-size: 12px; }

/* ── 内容 ── */
.placeholder { color: var(--muted); padding-top: 40px; }
#content h1.chapter-title { font-family: var(--serif); font-size: 30px; font-weight: 600; margin: 0 0 8px; letter-spacing: -.01em; line-height: 1.25; color: var(--fg); }
.chapter-sub { color: var(--faint); font-size: 13px; margin: 0 0 24px; }

/* Relevant source files 折叠盒 */
.srcbox { border: 1px solid var(--line); border-radius: 10px; background: #fff; margin: 4px 0 28px; overflow: hidden; }
.srcbox > summary { cursor: pointer; padding: 13px 16px; font-size: 14px; color: var(--fg); list-style: none; display: flex; align-items: center; gap: 10px; }
.srcbox > summary::-webkit-details-marker { display: none; }
.srcbox > summary::before { content: "›"; font-size: 17px; color: var(--muted); transition: transform .15s; display: inline-block; }
.srcbox[open] > summary::before { transform: rotate(90deg); }
.srcbox .files { padding: 2px 16px 14px; display: flex; flex-wrap: wrap; gap: 6px; }
.srcbox .files .f { font-family: var(--mono); font-size: 11.5px; background: var(--code-bg); border-radius: 6px; padding: 2px 8px; color: var(--muted); }

#content h2 { font-family: var(--serif); font-size: 22px; font-weight: 600; margin: 40px 0 14px; padding-top: 22px; border-top: 1px solid var(--line); scroll-margin-top: 74px; letter-spacing: -.005em; }
#content h2:first-of-type { border-top: none; padding-top: 4px; margin-top: 20px; }
#content h3 { font-family: var(--serif); font-size: 17.5px; font-weight: 600; margin: 28px 0 8px; scroll-margin-top: 74px; }
#content p { margin: 14px 0; color: #232322; }
#content a { text-decoration: underline; text-underline-offset: 2px; text-decoration-color: #c7c5be; text-decoration-thickness: 1px; }
#content a:hover { text-decoration-color: var(--fg); }
#content ul, #content ol { padding-left: 24px; margin: 12px 0; }
#content li { margin: 5px 0; }
#content strong { font-weight: 600; color: var(--fg); }
#content code { background: var(--code-bg); padding: 1.5px 6px; border-radius: 5px; font-size: 13px; font-family: var(--mono); color: #4a4844; }
#content pre { background: #1e2230; color: #e5e9f0; padding: 15px 17px; border-radius: 9px; overflow-x: auto; font-size: 13px; }
#content pre code { background: none; padding: 0; color: inherit; }
#content table { border-collapse: collapse; width: 100%; margin: 18px 0; font-size: 13.5px; }
#content th, #content td { border: 1px solid var(--line); padding: 8px 12px; text-align: left; vertical-align: top; }
#content th { background: #f6f5f2; font-weight: 600; }
#content hr { border: none; border-top: 1px solid var(--line); margin: 30px 0; }

/* 引用药丸 */
.cite { display: inline-flex; align-items: center; gap: 0; background: var(--code-bg); border-radius: 6px; font-family: var(--mono); font-size: 12px; overflow: hidden; vertical-align: baseline; margin: 0 1px; }
.cite .gh { padding: 1px 5px 1px 7px; color: var(--muted); }
.cite .path { padding: 2px 6px; color: var(--muted); }
.cite .ln { padding: 2px 7px; background: #e0ded7; color: #55534d; }
a.cite { text-decoration: none; cursor: pointer; transition: filter .12s; }
#content a.cite { text-decoration: none; }
a.cite:hover { filter: brightness(0.94); }
a.cite:hover .ln { background: var(--blue); color: #fff; }
.sources-line { display: block; font-size: 12.5px; color: var(--muted); margin: 10px 0; }
.sources-line .lbl { font-weight: 600; margin-right: 6px; }

/* 图 */
.diagram-block { border: 1px solid var(--line); border-radius: 11px; padding: 20px; margin: 22px 0; background: #faf9f6; overflow-x: auto; text-align: center; }
.diagram-block .dia-cap { font-size: 11px; color: var(--faint); margin-bottom: 10px; text-align: left; text-transform: uppercase; letter-spacing: .06em; }
.diagram-block svg { max-width: 100%; height: auto; }

/* ── 右 On this page(3 级嵌套) ── */
.toc-title { font-size: 15px; font-weight: 600; color: var(--fg); margin-bottom: 16px; }
#toc-list { list-style: none; margin: 0; padding: 0; }
#toc-list li { font-size: 13px; padding: 5px 0 5px 12px; color: var(--muted); cursor: pointer; line-height: 1.45; border-left: 2px solid transparent; }
#toc-list li.page-title { font-weight: 600; color: var(--fg); padding-left: 10px; margin-bottom: 4px; }
#toc-list li.h3 { padding-left: 26px; font-size: 12.5px; color: var(--faint); }
#toc-list li:hover { color: var(--fg); border-left-color: var(--line-dash); }
#toc-list li.active { color: var(--fg); border-left-color: var(--fg); }

/* ── Prose 层:Purpose and Scope 总述 + 每节叙事(文字优先) ── */
.page-summary { font-size: 16px; color: #232322; margin: 6px 0 8px; }
.page-summary p:first-child { margin-top: 4px; }
.section-narrative { color: #232322; margin: 8px 0 6px; }
.section-narrative p { margin: 8px 0; }
:root[data-theme="dark"] .page-summary, :root[data-theme="dark"] .section-narrative { color: #d0cfc8; }

/* 主题切换按钮(月亮/太阳) */
#theme-toggle { border: 1px solid var(--line); background: #fff; border-radius: 8px; width: 34px; height: 32px; cursor: pointer; font-size: 15px; line-height: 1; color: var(--fg); display: inline-flex; align-items: center; justify-content: center; }
#theme-toggle:hover { background: var(--hover-bg); }

/* ── 深色模式 ── */
:root[data-theme="dark"] {
  --bg: #121213; --fg: #e8e7e3; --muted: #a8a69f; --faint: #77766f;
  --line: #2b2b28; --line-dash: #35342f; --active-bg: #2d2c27; --hover-bg: #1e1e1c; --code-bg: #26261f; --link: #e8e7e3;
}
:root[data-theme="dark"] #topbar, :root[data-theme="dark"] #search,
:root[data-theme="dark"] #lang-toggle, :root[data-theme="dark"] #theme-toggle,
:root[data-theme="dark"] .srcbox { background: #17171a; }
:root[data-theme="dark"] #content p { color: #d0cfc8; }
:root[data-theme="dark"] #content strong { color: var(--fg); }
:root[data-theme="dark"] #content code { color: #d6d4cb; }
:root[data-theme="dark"] #content th { background: #1f1f22; }
:root[data-theme="dark"] #content pre { background: #0c0c0d; }
:root[data-theme="dark"] .diagram-block { background: #161618; }
:root[data-theme="dark"] .cite .ln { background: #3a3934; color: #cbc9c1; }
