/* R0 安静阅读基准（重写版）
   气质对标：坂本龙一 biography 的克制左栏 + 王振宇文章版式的安静正文。
   原则：统一无衬线阅读体系、不用字号戏剧、不在正文插大图、目录常驻左侧、控件退到边栏。 */

:root {
  color-scheme: dark;
  --paper: #0d0e0d;
  --paper-2: #141613;
  --ink: #e8e9e3;
  --ink-strong: #f6f6f0;
  --muted: #989b93;
  --faint: #656861;
  --line: #292b27;
  --line-soft: #1b1d1a;
  /* 阅读页走克制简约的黑体系；宋体等中式衬线整套留给后续古文板块，不在统一阅读页使用。 */
  --reading: "PingFang SC", "Hiragino Sans GB", "Source Han Sans SC", "Microsoft YaHei", sans-serif;
  --interface: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, "SFMono-Regular", "Menlo", monospace;
  --measure: 44em;
  --body-size: 17px;
  --body-leading: 1.9;
}

html[data-theme="light"] {
  color-scheme: light;
  --paper: #f2f1ec;
  --paper-2: #e8e7e0;
  --ink: #23241f;
  --ink-strong: #101109;
  --muted: #5f635b;
  --faint: #8a8e84;
  --line: #ccccc3;
  --line-soft: #deddd5;
}

* { box-sizing: border-box; }
html { background: var(--paper); scroll-behavior: smooth; scroll-padding-top: 40px; }
body {
  margin: 0;
  min-width: 320px;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--interface);
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; background: none; border: 0; }
::selection { background: var(--ink-strong); color: var(--paper); }
a:focus-visible, button:focus-visible, [tabindex="-1"]:focus-visible {
  outline: 2px solid var(--ink-strong);
  outline-offset: 4px;
  border-radius: 1px;
}

.skip-link {
  position: fixed;
  z-index: 200;
  top: 12px;
  left: 12px;
  padding: 12px 16px;
  min-height: 44px;
  background: var(--ink-strong);
  color: var(--paper);
  transform: translateY(-180%);
}
.skip-link:focus { transform: none; }

.reading-progress { position: fixed; z-index: 120; inset: 0 0 auto; height: 2px; background: transparent; }
.reading-progress span {
  display: block; height: 100%;
  background: var(--muted);
  transform: scaleX(0); transform-origin: left center;
}

/* ---------- 布局：正文对视口居中，目录浮在左缘不挤占版面 ---------- */
.reader { display: block; }

.rail {
  position: fixed;
  z-index: 90;
  inset: 0 auto 0 0;
  width: 228px;
  display: flex;
  flex-direction: column;
  padding: clamp(28px, 4vh, 44px) 24px 24px 28px;
}

.rail-brand { display: flex; align-items: baseline; gap: 9px; min-width: 44px; min-height: 44px; }
.rail-brand strong { font-size: 1rem; letter-spacing: .01em; color: var(--ink-strong); }
.rail-brand span { font-family: var(--mono); font-size: .62rem; letter-spacing: .12em; color: var(--faint); text-transform: uppercase; }

.rail-toc { flex: 1; display: flex; flex-direction: column; justify-content: center; margin: 0; }
.rail-toc-label {
  margin: 0 0 18px;
  font-family: var(--mono); font-size: .58rem; letter-spacing: .2em;
  text-transform: uppercase; color: var(--faint);
}
.rail-toc ol { margin: 0; padding: 0; list-style: none; display: grid; gap: 2px; }
.rail-toc a { display: grid; gap: 9px; padding: 9px 0; color: var(--muted); }
.rail-toc .toc-row { display: grid; grid-template-columns: 18px 1fr; gap: 10px; align-items: baseline; }
.rail-toc .toc-num { font-family: var(--mono); font-size: .58rem; color: var(--faint); transition: color .25s ease; }
.rail-toc .toc-text { font-size: .84rem; line-height: 1.4; color: var(--muted); transition: color .25s ease; }
.rail-toc .toc-track { display: block; height: 1px; background: var(--line-soft); overflow: hidden; }
.rail-toc .toc-track i { display: block; height: 100%; width: var(--seg, 0%); background: var(--faint); transition: width .18s ease, background .25s ease; }
.rail-toc a:hover .toc-text { color: var(--ink); }
.rail-toc a[aria-current="true"] .toc-text { color: var(--ink); }
.rail-toc a[aria-current="true"] .toc-num { color: var(--muted); }
.rail-toc a[aria-current="true"] .toc-track i { background: var(--muted); }

.rail-readpct {
  margin: 18px 0 0;
  font-family: var(--mono); font-size: .62rem; letter-spacing: .08em; color: var(--faint);
}
.rail-readpct span { color: var(--muted); }

.rail-controls {
  padding-top: 24px;
  display: flex;
  align-items: center;
}
.theme-toggle {
  min-width: 44px; min-height: 44px; padding: 0 8px;
  font-family: var(--mono); font-size: .62rem; letter-spacing: .12em;
  color: var(--muted); text-transform: uppercase;
}
.theme-toggle:hover { color: var(--ink-strong); }

/* ---------- 正文 ---------- */
/* ≥1260px：左右各留出目录宽度以上的空间，正文相对视口真居中 */
.reading { min-width: 0; padding: 0 48px 168px; }
.doc { max-width: var(--measure); margin: 0 auto; }

@media (max-width: 1259.98px) and (min-width: 1001px) {
  /* 视口不够宽时避让固定目录，不与正文重叠 */
  .reading { padding-left: 252px; padding-right: 36px; }
}

.doc-head { padding: clamp(60px, 9vh, 104px) 0 clamp(40px, 5vw, 60px); border-bottom: 1px solid var(--line); }
.doc-kicker { margin: 0 0 26px; font-family: var(--mono); font-size: .64rem; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.doc-title {
  margin: 0;
  font-family: var(--reading);
  font-size: clamp(1.95rem, 3.3vw, 2.65rem);
  font-weight: 600;
  line-height: 1.28;
  letter-spacing: .005em;
  color: var(--ink-strong);
  text-wrap: balance;
}
.doc-lead {
  max-width: 34em;
  margin: 24px 0 0;
  font-family: var(--reading);
  font-size: 1.06rem;
  line-height: 1.85;
  color: var(--muted);
}
.doc-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 20px 40px; margin-top: 36px; }
.doc-meta dl { display: flex; flex-wrap: wrap; gap: 26px; margin: 0; }
.doc-meta div { display: flex; align-items: baseline; gap: 9px; }
.doc-meta dt { margin: 0; font-family: var(--mono); font-size: .58rem; letter-spacing: .12em; text-transform: uppercase; color: var(--faint); }
.doc-meta dd { margin: 0; font-size: .82rem; color: var(--ink); }
.doc-tags { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; list-style: none; }
.doc-tags span {
  display: inline-flex; align-items: center; min-height: 44px; padding: 4px 14px;
  border: 1px solid var(--line); border-radius: 999px;
  font-size: .74rem; color: var(--muted);
}
.doc-tags span::before { content: "#"; margin-right: 3px; color: var(--faint); }

.doc-body { outline: none; }
.doc-body section { padding-top: clamp(52px, 7vw, 84px); }
.sec-head {
  display: flex; align-items: baseline; gap: 14px;
  margin: 0 0 26px;
  font-family: var(--reading);
  font-size: clamp(1.3rem, 1.9vw, 1.55rem);
  font-weight: 600;
  line-height: 1.4;
  color: var(--ink-strong);
  letter-spacing: .01em;
}
.sec-num { font-family: var(--mono); font-size: .74rem; font-weight: 400; color: var(--faint); }

.doc-body p {
  margin: 0;
  font-family: var(--reading);
  font-size: var(--body-size);
  line-height: var(--body-leading);
  letter-spacing: .012em;
  color: var(--ink);
  text-align: justify;
  text-justify: inter-ideograph;
  text-wrap: pretty;
}
.doc-body p + p { margin-top: 1.4em; }
.doc-body sup { line-height: 0; }
.doc-body sup a {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 24px; min-height: 24px;
  font-family: var(--mono); font-size: .62rem; color: var(--muted);
  vertical-align: .38em;
}
.doc-body sup a:hover { color: var(--ink-strong); }

.pull {
  max-width: 26em;
  margin: clamp(48px, 6vw, 78px) 0;
  padding: 4px 0 4px 26px;
  border-left: 2px solid var(--ink-strong);
}
.pull p {
  margin: 0;
  font-family: var(--reading);
  font-size: clamp(1.24rem, 1.9vw, 1.5rem);
  line-height: 1.66;
  color: var(--ink-strong);
  letter-spacing: .01em;
}

.doc-notes { margin-top: clamp(80px, 10vw, 128px); padding-top: 26px; border-top: 1px solid var(--line); color: var(--muted); }
.notes-label { margin: 0 0 16px; font-family: var(--mono); font-size: .6rem; letter-spacing: .2em; text-transform: uppercase; color: var(--faint); }
.doc-notes ol { margin: 0; padding-left: 1.5em; }
.doc-notes li { font-family: var(--reading); font-size: .88rem; line-height: 1.85; }
.doc-notes a { margin-left: 8px; color: var(--ink); text-decoration: underline; text-underline-offset: 4px; }
.doc-notes a:hover { color: var(--ink-strong); }

/* ---------- 响应式 ---------- */
@media (max-width: 1000px) {
  html { scroll-padding-top: 82px; }
  .reader { display: block; }
  .rail {
    position: sticky; top: 0; z-index: 90;
    inset: auto; width: auto;
    flex-direction: row; align-items: center;
    height: auto; padding: 10px clamp(16px, 4vw, 28px);
    gap: 16px;
    border-bottom: 1px solid var(--line);
    background: color-mix(in srgb, var(--paper) 92%, transparent);
    backdrop-filter: blur(14px);
  }
  .rail-brand { min-height: 44px; }
  .rail-toc { flex: 1; min-width: 0; margin: 0; }
  .rail-toc-label, .rail-readpct { display: none; }
  .rail-toc ol { grid-auto-flow: column; justify-content: flex-start; gap: 2px; overflow-x: auto; scrollbar-width: none; }
  .rail-toc ol::-webkit-scrollbar { display: none; }
  .rail-toc a { gap: 0; min-height: 44px; padding: 4px 12px; white-space: nowrap; }
  .rail-toc .toc-track { display: none; }
  .rail-toc .toc-row { grid-template-columns: auto; }
  .rail-toc .toc-num { display: none; }
  .rail-toc a[aria-current="true"] .toc-text { text-decoration: underline; text-underline-offset: 6px; }
  .rail-controls { margin: 0; padding: 0; border: 0; gap: 8px; }
  .reading { padding: 0 clamp(20px, 6vw, 56px) 120px; }
  .doc-title { font-size: clamp(1.85rem, 6.4vw, 2.4rem); }
}

@media (max-width: 620px) {
  .rail { gap: 10px; padding-inline: 16px; }
  .rail-brand span { display: none; }
  .reading { padding: 0 20px 96px; }
  .doc-body p { text-align: left; }
  .doc-meta { gap: 16px 28px; margin-top: 28px; }
}

@media print {
  .rail, .reading-progress, .skip-link { display: none !important; }
  :root { --paper: #fff; --ink: #111; --ink-strong: #000; --muted: #555; --line: #bbb; }
  .reader { display: block; }
  .reading { padding: 0; }
  .doc { max-width: 42em; }
  .doc-head { padding-top: 0; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
