/* Allen CMOS 读书笔记 — 共享样式（所有章节页共用） */
:root {
  --paper: #F2F4F1;
  --plate: #FFFFFF;
  --ink: #1C2430;
  --ink-2: #4A5562;
  --ink-3: #6E7884;
  --rule: #CCD3CE;
  --rule-2: #E1E6E2;
  --node: #8A5300;      /* 节点电压标注（与电路图一致） */
  --current: #1F5F8B;   /* 电流 */
  --errata: #A3245C;    /* 原书勘误 */
  --modern: #2E6B4E;    /* 现代工艺对照 */
  --supp: #5B6270;      /* 笔记补充（非原书） */
  --focus: #1F5F8B;
  --serif: "Noto Serif SC", "Source Han Serif SC", "Songti SC", "STSong", "SimSun", serif;
  --sans: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 24px; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font-family: var(--sans); font-size: 16px; line-height: 1.8;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--current); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 2px; }

/* ---------- 版面 ---------- */
.layout { display: grid; grid-template-columns: 264px minmax(0, 1fr); max-width: 1180px; margin: 0 auto; }
.toc {
  position: sticky; top: 0; align-self: start; height: 100vh; overflow-y: auto;
  padding: 36px 20px 40px 28px; border-right: 1px solid var(--rule);
  font-size: 14px; line-height: 1.55;
}
.toc .book { font-family: var(--serif); font-size: 15px; color: var(--ink-2); text-decoration: none; display: block; margin-bottom: 18px; }
.toc .book:hover { color: var(--ink); }
.toc ol { list-style: none; margin: 0; padding: 0; }
.toc li { margin: 0; }
.toc a.sec { display: flex; gap: 8px; align-items: baseline; padding: 5px 8px; margin: 1px 0; border-radius: 4px; color: var(--ink); text-decoration: none; }
.toc a.sec .n { font-variant-numeric: tabular-nums; color: var(--ink-3); min-width: 2.2em; }
.toc a.sec:hover { background: var(--rule-2); }
.toc a.sec.pending { color: var(--ink-3); }
.toc a.sec.pending::after { content: "待整理"; margin-left: auto; font-size: 11px; color: var(--ink-3); border: 1px solid var(--rule); border-radius: 3px; padding: 0 4px; white-space: nowrap; }
.toc a.sec.active { background: var(--ink); color: #fff; }
.toc a.sec.active .n { color: #C9D3DC; }
.toc ol.sub { margin: 2px 0 8px 2.6em; border-left: 1px solid var(--rule); }
.toc ol.sub a { display: block; padding: 3px 0 3px 12px; color: var(--ink-2); text-decoration: none; font-size: 13px; }
.toc ol.sub a:hover { color: var(--ink); }
.toc ol.sub a.active { color: var(--ink); font-weight: 600; box-shadow: inset 2px 0 0 var(--ink); }
.toc .group { margin-top: 18px; padding-top: 12px; border-top: 1px solid var(--rule); }

main { padding: 48px 56px 120px; min-width: 0; }
.col { max-width: 760px; }

/* ---------- 章首 ---------- */
.chapter-head { margin-bottom: 40px; }
.chapter-head .kicker { color: var(--ink-3); font-size: 14px; margin: 0 0 6px; }
.chapter-head h1 { font-family: var(--serif); font-weight: 700; font-size: 44px; line-height: 1.2; margin: 0 0 6px; letter-spacing: 0.01em; }
.chapter-head .en { font-family: var(--serif); font-style: italic; color: var(--ink-2); font-size: 20px; margin: 0 0 20px; }
.chapter-head .meta { display: flex; flex-wrap: wrap; gap: 8px 22px; font-size: 14px; color: var(--ink-2); padding: 12px 0; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); }
.chapter-head .meta b { color: var(--ink); font-weight: 600; }

/* ---------- 标题层级 ---------- */
section.sec { padding-top: 12px; margin-top: 56px; }
h2 { font-family: var(--serif); font-size: 30px; line-height: 1.3; margin: 0 0 6px; display: flex; gap: 14px; align-items: baseline; }
h2 .n { font-variant-numeric: tabular-nums; color: var(--ink-3); font-weight: 400; }
h2 + .pages { margin: 0 0 18px; color: var(--ink-3); font-size: 14px; }
h3 { font-family: var(--serif); font-size: 21px; line-height: 1.4; margin: 40px 0 10px; }
h4 { font-size: 16px; margin: 24px 0 6px; }
p { margin: 0 0 14px; }
.gist { font-family: var(--serif); font-size: 19px; line-height: 1.7; margin: 0 0 22px; padding-left: 16px; border-left: 3px solid var(--ink); }
.pg { font-size: 12px; color: var(--ink-3); white-space: nowrap; border: 1px solid var(--rule); border-radius: 3px; padding: 0 4px; margin-left: 4px; font-variant-numeric: tabular-nums; vertical-align: 1px; }
ul, ol.body { padding-left: 1.3em; margin: 0 0 14px; }
li { margin: 3px 0; }
.v-node { color: var(--node); }
.v-cur { color: var(--current); }

/* ---------- 公式 ---------- */
.eq { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 16px; margin: 14px 0 18px; padding: 6px 0; }
.eq .tex { overflow-x: auto; overflow-y: hidden; }
.eq .tag { font-size: 13px; color: var(--ink-3); font-variant-numeric: tabular-nums; white-space: nowrap; }
.eq.key { background: var(--plate); border: 1px solid var(--rule); border-radius: 6px; padding: 12px 18px; }

/* ---------- 图 ---------- */
figure { margin: 22px 0 26px; }
.plate { background: var(--plate); border: 1px solid var(--rule); border-radius: 6px; padding: 20px; }
.plate svg { display: block; max-width: 100%; height: auto; margin: 0 auto; }
.plates { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.plates .plate { display: flex; flex-direction: column; justify-content: space-between; }
.plates .plate .cap { margin-top: 10px; font-size: 13px; color: var(--ink-2); text-align: center; }
figcaption { font-size: 13px; color: var(--ink-2); margin-top: 8px; line-height: 1.6; }
figcaption b { color: var(--ink); }
.sch text { font-family: var(--sans); }

/* ---------- 注释框（语义：勘误 / 现代工艺 / 笔记补充） ---------- */
.note { margin: 20px 0; padding: 12px 16px 12px 18px; background: var(--plate); border: 1px solid var(--rule); border-left-width: 4px; border-radius: 4px; font-size: 15px; line-height: 1.75; }
.note > :last-child { margin-bottom: 0; }
.note .h { font-weight: 700; margin-right: 6px; }
.note.errata { border-left-color: var(--errata); }
.note.errata .h { color: var(--errata); }
.note.modern { border-left-color: var(--modern); }
.note.modern .h { color: var(--modern); }
.note.supp { border-left-color: var(--supp); border-left-style: dashed; }
.note.supp .h { color: var(--supp); }
.note.link { border-left-color: var(--current); }
.note.link .h { color: var(--current); }

/* ---------- 例题 ---------- */
details.ex { margin: 18px 0; border: 1px solid var(--rule); border-radius: 6px; background: var(--plate); }
details.ex > summary { cursor: pointer; list-style: none; padding: 10px 16px; display: flex; gap: 10px; align-items: baseline; }
details.ex > summary::-webkit-details-marker { display: none; }
details.ex > summary::before { content: "+"; font-weight: 700; color: var(--ink-3); width: 1em; }
details.ex[open] > summary::before { content: "−"; }
details.ex > summary .t { font-weight: 600; }
details.ex > summary .pg { margin-left: auto; }
details.ex .body { padding: 2px 18px 14px 42px; font-size: 15px; }

/* ---------- 表格 ---------- */
table.t { width: 100%; border-collapse: collapse; font-size: 14.5px; margin: 14px 0 20px; background: var(--plate); }
table.t th, table.t td { border-bottom: 1px solid var(--rule-2); padding: 8px 10px; text-align: left; vertical-align: top; }
table.t th { font-weight: 600; color: var(--ink-2); border-bottom: 1px solid var(--rule); background: #F7F8F6; }
table.t td.num, table.t th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- 交互 ---------- */
.widget { background: var(--plate); border: 1px solid var(--rule); border-radius: 6px; padding: 18px 20px; margin: 22px 0; }
.widget .wtitle { font-weight: 700; margin: 0 0 4px; }
.widget .wsub { font-size: 13.5px; color: var(--ink-2); margin: 0 0 14px; }
.controls { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px 22px; margin-bottom: 16px; }
.ctl label { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 13.5px; color: var(--ink-2); margin-bottom: 4px; }
.ctl label output { color: var(--ink); font-variant-numeric: tabular-nums; font-weight: 600; }
.ctl input[type=range] { width: 100%; accent-color: var(--ink); }
.seg { display: inline-flex; border: 1px solid var(--rule); border-radius: 5px; overflow: hidden; }
.seg button { font: inherit; font-size: 13px; padding: 4px 10px; border: 0; background: var(--plate); color: var(--ink-2); cursor: pointer; }
.seg button[aria-pressed=true] { background: var(--ink); color: #fff; }
.readout { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; }
@media (max-width: 700px) { .readout { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.readout .r { border-top: 2px solid var(--rule); padding-top: 6px; }
.readout .r .k { font-size: 12.5px; color: var(--ink-2); }
.readout .r .v { font-size: 20px; font-variant-numeric: tabular-nums; font-weight: 600; }
.readout .r.total { border-top-color: var(--ink); }

/* 图表 */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid line { stroke: var(--rule-2); }
.chart .axis text, .chart .lbl { font-size: 11px; fill: var(--ink-2); font-family: var(--sans); }
.chart .axis line, .chart .axis path { stroke: var(--rule); }
.chart .atitle { font-size: 11.5px; fill: var(--ink-2); }
.chart .tip { position: absolute; pointer-events: none; background: var(--ink); color: #fff; font-size: 12px; line-height: 1.5; padding: 6px 9px; border-radius: 4px; white-space: nowrap; transform: translate(12px, -50%); display: none; z-index: 2; }
.chart .tip .sw { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12.5px; color: var(--ink-2); margin: 0 0 6px; }
.legend span::before { content: ""; display: inline-block; width: 14px; height: 2px; background: var(--c); vertical-align: middle; margin-right: 6px; }

/* 族谱对比 */
.family { width: 100%; border-collapse: collapse; font-size: 14px; }
.family th { text-align: left; font-weight: 600; color: var(--ink-2); font-size: 12.5px; padding: 6px 8px; border-bottom: 1px solid var(--rule); }
.family td { padding: 9px 8px; border-bottom: 1px solid var(--rule-2); vertical-align: middle; }
.family td.name { font-weight: 600; white-space: nowrap; }
.family td.name small { display: block; font-weight: 400; color: var(--ink-3); font-size: 12px; }
.family .bar { position: relative; height: 18px; background: #F3F5F3; border-radius: 3px; min-width: 120px; }
.family .bar i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 0 4px 4px 0; background: var(--current); }
.family .bar.v i { background: var(--node); }
.family .bar b { position: absolute; left: 6px; top: 0; font-size: 12px; line-height: 18px; color: #fff; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; mix-blend-mode: normal; }
.family .bar b.out { color: var(--ink); }

/* 待整理占位 */
.pending-box { border: 1px dashed var(--rule); border-radius: 6px; padding: 14px 18px; color: var(--ink-2); font-size: 15px; background: transparent; }

/* 勘误汇总 */
ol.errata-list { padding-left: 1.4em; }
ol.errata-list li { margin: 10px 0; }
.tagk { font-size: 11.5px; border-radius: 3px; padding: 1px 6px; margin-right: 6px; color: #fff; vertical-align: 1px; }
.tagk.e { background: var(--errata); }
.tagk.q { background: var(--ink-3); }

/* 首页 */
.index-wrap { max-width: 900px; margin: 0 auto; padding: 64px 32px 120px; }
.part { margin-top: 40px; }
.part h2 { font-size: 24px; }
.part .desc { color: var(--ink-2); margin: 0 0 12px; }
.chlist { list-style: none; padding: 0; margin: 0; border-top: 1px solid var(--rule); }
.chlist li { display: grid; grid-template-columns: 3.5em 1fr auto; gap: 12px; align-items: baseline; padding: 12px 4px; border-bottom: 1px solid var(--rule); margin: 0; }
.chlist .n { font-family: var(--serif); font-size: 22px; color: var(--ink-3); }
.chlist .t a, .chlist .t span.title { font-family: var(--serif); font-size: 19px; color: var(--ink); text-decoration: none; }
.chlist .t a:hover { text-decoration: underline; }
.chlist .t .sub { display: block; font-size: 13.5px; color: var(--ink-3); }
.chlist .st { font-size: 13px; color: var(--ink-2); white-space: nowrap; }
.chlist .st.done { color: var(--modern); font-weight: 600; }

/* ---------- 响应式 ---------- */
.toc-toggle { display: none; }
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .toc { position: fixed; inset: 0 auto 0 0; width: 290px; z-index: 20; background: var(--paper); transform: translateX(-100%); transition: transform .2s ease; box-shadow: 4px 0 18px rgba(28,36,48,.12); }
  .toc.open { transform: none; }
  .toc-toggle { display: block; position: fixed; top: 12px; left: 12px; z-index: 21; font: inherit; font-size: 14px; padding: 6px 12px; border-radius: 5px; border: 1px solid var(--rule); background: var(--plate); color: var(--ink); }
  main { padding: 64px 20px 80px; }
  .chapter-head h1 { font-size: 34px; }
  h2 { font-size: 25px; }
}
@media print {
  .toc, .toc-toggle { display: none; }
  .layout { display: block; }
  details.ex { break-inside: avoid; }
  details.ex:not([open]) > .body { display: block; }
}
