/* Hallmark · genre: editorial · macrostructure: Long Document · theme: Almanac · enrichment: Tier-B hand-SVG teaching diagrams
 * nav: N3 Side-rail (side=left · width=12ch · indicator=text-only) · footer: Ft4 Dense colophon (mono · single block · date+attribution)
 * section heads: genuinely ordinal (§ numbering inside the heading, stacked single column — Long Document exception)
 * pre-emit critique: P4 H5 E4 S5 R4 V4
 */

/* —— N3 侧栏(目录轨) —— */
.rail {
  position: fixed;
  inset-block: 0;
  left: 0;
  width: 13rem;
  padding: var(--space-lg) var(--space-md);
  border-right: var(--rule-hair) solid var(--color-rule);
  overflow-y: auto;
  z-index: var(--z-sticky);
  background: var(--color-paper);
  scrollbar-width: thin;
}
.rail-home {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--text-sm);
  letter-spacing: 0.08em;
  text-decoration: none;
  color: var(--color-ink);
}
.rail-home:hover { color: var(--color-accent); }
.rail-paper {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--color-neutral);
  margin: var(--space-sm) 0 var(--space-lg);
  line-height: 1.5;
}
.rail nav ul {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: var(--rule-hair) solid var(--color-rule);
}
.rail nav a {
  display: block;
  padding: 0.4rem 0.4rem 0.4rem 0.6rem;
  font-size: var(--text-xs);
  line-height: 1.45;
  color: var(--color-neutral);
  text-decoration: none;
  border-bottom: var(--rule-hair) solid var(--color-rule);
  transition: color var(--dur-short) var(--ease-out);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rail nav a:hover { color: var(--color-ink); }
.rail nav a[aria-current="true"] {
  color: var(--color-accent);
  border-left: 2px solid var(--color-accent);
  padding-left: calc(0.6rem - 2px);
}

/* —— 移动端顶条(<60rem 时 rail 收起) —— */
.topbar {
  display: none;
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  background: var(--color-paper);
  border-bottom: var(--rule-hair) solid var(--color-rule);
  padding: var(--space-sm) var(--space-md);
}
.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
}
.topbar a.home {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--text-sm);
  color: var(--color-ink);
  text-decoration: none;
  white-space: nowrap;
}
.topbar details { position: relative; }
.topbar summary {
  cursor: pointer;
  list-style: none;
  font-size: var(--text-sm);
  color: var(--color-neutral);
  padding: var(--space-2xs) var(--space-sm);
  border: var(--rule-hair) solid var(--color-rule);
  border-radius: var(--radius-sm);
  white-space: nowrap;
  min-height: 2rem;
  display: grid;
  align-items: center;
}
.topbar summary::-webkit-details-marker { display: none; }
.topbar details[open] summary { background: var(--color-paper-2); }
.topbar .toc-pop {
  position: absolute;
  right: 0;
  top: calc(100% + var(--space-xs));
  min-width: 16rem;
  max-height: 70dvh;
  overflow-y: auto;
  background: var(--color-paper);
  border: var(--rule-hair) solid var(--color-rule);
  box-shadow: 0 1px 2px oklch(20% 0.01 60 / 0.08);
  padding: var(--space-xs);
}
.topbar .toc-pop a {
  display: block;
  padding: var(--space-xs) var(--space-sm);
  font-size: var(--text-sm);
  color: var(--color-ink);
  text-decoration: none;
}
.topbar .toc-pop a:hover { background: var(--color-paper-2); }

/* —— 版心 —— */
.page {
  margin-left: 13rem;
  padding: var(--space-2xl) var(--space-lg) var(--space-xl);
}
.doc {
  max-width: 44rem;
  margin-inline: auto;
}

/* —— 文头 —— */
.doc-head { margin-bottom: var(--space-3xl); }
.doc-kicker {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.08em;
  color: var(--color-neutral);
  margin: 0 0 var(--space-md);
}
.doc-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--text-display);
  line-height: 1.15;
  letter-spacing: -0.01em;
  margin: 0 0 var(--space-md);
  overflow-wrap: anywhere;
  min-width: 0;
}
.doc-subtitle {
  font-size: var(--text-md);
  color: var(--color-muted);
  margin: 0 0 var(--space-lg);
  line-height: 1.55;
}
.doc-meta {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--color-neutral);
  line-height: 2;
  border-top: var(--rule-hair) solid var(--color-rule);
  border-bottom: var(--rule-hair) solid var(--color-rule);
  padding: var(--space-sm) 0;
  margin: 0;
}
.doc-meta a { color: var(--color-accent); text-decoration-thickness: 1px; }
.doc-meta a:hover { text-decoration-thickness: 2px; }

/* —— 章节 —— */
section.chap { margin-top: var(--space-3xl); }
.chap h2 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--text-xl);
  line-height: 1.25;
  margin: 0 0 var(--space-lg);
  letter-spacing: -0.01em;
}
.chap h2 .no {
  color: var(--color-accent);
  font-variant-numeric: tabular-nums;
  margin-right: 0.35em;
}
.chap h3 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--text-md);
  margin: var(--space-xl) 0 var(--space-sm);
}
p { margin: 0 0 var(--space-md); }
.doc a { color: var(--color-accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
.doc a:hover { text-decoration-thickness: 2px; }
strong { font-weight: 600; }
mark {
  background: var(--color-accent-soft);
  color: inherit;
  padding: 0 0.15em;
}

/* —— 「从 LLM 视角看」旁注带 —— */
.llm-note {
  background: var(--color-paper-2);
  padding: var(--space-md) var(--space-lg);
  margin: var(--space-lg) 0;
}
.llm-note .tag {
  display: block;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.1em;
  color: var(--color-accent);
  margin-bottom: var(--space-xs);
}
.llm-note p:last-child { margin-bottom: 0; }

/* —— 图 —— */
figure {
  margin: var(--space-xl) 0;
}
figure.wide {
  width: min(100%, 58rem);
  margin-inline: calc((100% - min(100%, 58rem)) / 2);
}
figure img {
  display: block;
  max-width: 100%;
  height: auto;
  border: var(--rule-hair) solid var(--color-rule);
}
figcaption {
  font-size: var(--text-sm);
  color: var(--color-neutral);
  margin-top: var(--space-sm);
  line-height: 1.55;
}
figcaption .fig-no {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--color-accent);
  margin-right: 0.5em;
}

/* —— 公式 —— */
.eq {
  margin: var(--space-lg) 0;
  overflow-x: auto;
  overflow-y: clip;
  padding: var(--space-2xs) 0;
}
.katex { font-size: 1.06em; }

/* —— 代码 —— */
pre {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: 1.65;
  background: var(--color-paper-2);
  padding: var(--space-md) var(--space-lg);
  overflow-x: auto;
  margin: var(--space-lg) 0;
  border-top: 2px solid var(--color-ink);
  border-bottom: var(--rule-hair) solid var(--color-rule);
}
code {
  font-family: var(--font-mono);
  font-size: 0.92em;
  background: var(--color-paper-2);
  padding: 0.1em 0.3em;
}
pre code { background: none; padding: 0; font-size: 1em; }
.codewrap { position: relative; }
.copy-btn {
  position: absolute;
  top: var(--space-xs);
  right: var(--space-xs);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--color-neutral);
  background: var(--color-paper);
  border: var(--rule-hair) solid var(--color-rule);
  border-radius: var(--radius-sm);
  padding: 0.2rem 0.55rem;
  cursor: pointer;
  transition: color var(--dur-short) var(--ease-out), background-color var(--dur-short) var(--ease-out);
  white-space: nowrap;
  min-height: 1.8rem;
}
.copy-btn:hover { color: var(--color-ink); background: var(--color-paper-2); }
.copy-btn:active { transform: translateY(1px); }
.copy-btn[data-state="copied"] { color: var(--color-accent); }

/* —— 表格 —— */
.table-scroll { overflow-x: auto; margin: var(--space-lg) 0; }
table {
  border-collapse: collapse;
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
  min-width: 100%;
}
caption {
  text-align: left;
  font-size: var(--text-sm);
  color: var(--color-neutral);
  padding-bottom: var(--space-xs);
}
th, td {
  text-align: left;
  padding: var(--space-xs) var(--space-md) var(--space-xs) 0;
  border-bottom: var(--rule-hair) solid var(--color-rule);
  white-space: nowrap;
}
thead th {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 400;
  letter-spacing: 0.05em;
  color: var(--color-neutral);
  border-bottom: 2px solid var(--color-ink);
}
td.best { color: var(--color-accent); font-weight: 600; }
td.num, th.num { text-align: right; }

/* —— 步骤序列(F4:方法四组件)—— */
.steps { margin: var(--space-xl) 0; padding: 0; list-style: none; }
.steps li {
  position: relative;
  padding: 0 0 var(--space-xl) 2.6rem;
}
.steps li:last-child { padding-bottom: 0; }
.steps li::before {
  content: attr(data-no);
  position: absolute;
  left: 0;
  top: 0.1rem;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--color-accent);
}
.steps li::after {
  content: "";
  position: absolute;
  left: 0.55rem;
  top: 1.7rem;
  bottom: 0.4rem;
  width: var(--rule-hair);
  background: var(--color-rule);
}
.steps li:last-child::after { display: none; }
.steps .step-name { font-weight: 600; }
.steps p { margin: var(--space-2xs) 0 0; font-size: var(--text-sm); color: var(--color-muted); }

/* —— 交互小实验 —— */
.widget {
  border: var(--rule-hair) solid var(--color-rule);
  padding: var(--space-lg);
  margin: var(--space-xl) 0;
}
.widget-title {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.1em;
  color: var(--color-accent);
  margin: 0 0 var(--space-md);
}
.widget-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-md);
  align-items: center;
}
.widget label { font-size: var(--text-sm); color: var(--color-muted); white-space: nowrap; }
.widget input[type="range"] {
  flex: 1 1 12rem;
  accent-color: var(--color-accent);
  min-height: 1.6rem;
}
.widget output {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
  color: var(--color-ink);
  white-space: nowrap;
}
.widget .readout {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--color-neutral);
  margin-top: var(--space-sm);
  line-height: 1.8;
}
.widget canvas, .widget svg.viz {
  display: block;
  max-width: 100%;
  height: auto;
  margin-top: var(--space-md);
}
.widget-note { font-size: var(--text-sm); color: var(--color-neutral); margin: var(--space-sm) 0 0; }

/* —— 折叠推导 —— */
details.derive {
  margin: var(--space-lg) 0;
  border-top: var(--rule-hair) solid var(--color-rule);
  border-bottom: var(--rule-hair) solid var(--color-rule);
}
details.derive summary {
  cursor: pointer;
  padding: var(--space-sm) 0;
  font-size: var(--text-sm);
  color: var(--color-muted);
  list-style: none;
}
details.derive summary::-webkit-details-marker { display: none; }
details.derive summary::before {
  content: "+";
  font-family: var(--font-mono);
  color: var(--color-accent);
  margin-right: 0.6em;
}
details.derive[open] summary::before { content: "−"; }
details.derive .derive-body { padding: 0 0 var(--space-md) 1.4rem; }

/* —— 术语表 —— */
dl.gloss { margin: var(--space-lg) 0 0; }
dl.gloss dt {
  font-weight: 600;
  margin-top: var(--space-md);
}
dl.gloss dt code { background: none; padding: 0; }
dl.gloss dd {
  margin: var(--space-2xs) 0 0 0;
  font-size: var(--text-sm);
  color: var(--color-muted);
}

/* —— 分隔花饰 —— */
.fleuron {
  text-align: center;
  color: var(--color-neutral);
  font-size: var(--text-md);
  margin: var(--space-3xl) 0 calc(-1 * var(--space-md));
  user-select: none;
}

/* —— Ft4 колophon 页脚 —— */
.colophon {
  margin-top: var(--space-3xl);
  border-top: 2px solid var(--color-ink);
  padding-top: var(--space-lg);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  line-height: 2;
  color: var(--color-neutral);
}
.colophon a { color: var(--color-accent); }

/* —— 响应式 —— */
@media (max-width: 60rem) {
  .rail { display: none; }
  .topbar { display: block; }
  .page { margin-left: 0; padding: var(--space-xl) var(--space-md); }
  figure.wide { width: 100%; margin-inline: 0; }
}
@media (max-width: 40rem) {
  .doc-title { font-size: clamp(1.7rem, 7vw, 2.25rem); }
  .chap h2 { font-size: var(--text-lg); }
  .steps li { padding-left: 2rem; }
  th, td { white-space: normal; }
}
