/* 数值分析复习 · 纸墨版式 */
:root {
  --paper: #f6f2e8;
  --paper-2: #efe9db;
  --ink: #1d1b17;
  --ink-2: #3f3a32;
  --muted: #6d6558;
  --rule: #d8d0bf;
  --rule-soft: #e5ddcc;
  --accent: #9a3b2a;
  --accent-2: #7d2f22;
  --serif: "Noto Serif SC", "Source Han Serif SC", "Songti SC", "SimSun", Georgia, serif;
  --mono: "SFMono-Regular", "JetBrains Mono", Menlo, Consolas, monospace;
  --col: 44rem;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.95;
  font-kerning: normal;
  text-rendering: optimizeLegibility;
}

::selection { background: #e8d3c6; }

a { color: var(--ink); text-decoration-color: var(--rule); text-underline-offset: .22em; }
a:hover { color: var(--accent); text-decoration-color: var(--accent); }

.skip {
  position: absolute; left: -999px; top: 0; padding: .6rem 1rem;
  background: var(--ink); color: var(--paper); z-index: 20;
}
.skip:focus { left: .5rem; top: .5rem; }

/* ---------- head ---------- */
.site-head {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: baseline; justify-content: space-between; gap: 1.5rem;
  padding: .85rem clamp(1.1rem, 4vw, 2.6rem);
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
}
.brand {
  font-size: .98rem; letter-spacing: .08em; text-decoration: none; white-space: nowrap;
}
.brand span { margin: 0 .35em; color: var(--accent); }
.site-nav { display: flex; flex-wrap: wrap; gap: 1.15rem; }
.site-nav a {
  font-family: var(--mono); font-size: .74rem; letter-spacing: .04em;
  color: var(--muted); text-decoration: none;
}
.site-nav a:hover { color: var(--ink); }
.site-nav a[aria-current="page"] { color: var(--accent); }

/* ---------- shell ---------- */
.shell {
  display: grid; grid-template-columns: minmax(0, 1fr);
  gap: clamp(1.5rem, 5vw, 4rem);
  max-width: 66rem; margin: 0 auto;
  padding: clamp(2rem, 6vw, 4.5rem) clamp(1.1rem, 4vw, 2.6rem) 4rem;
}
main { min-width: 0; max-width: var(--col); }
.layout-index main { max-width: 52rem; }

.kicker {
  font-family: var(--mono); font-size: .72rem; letter-spacing: .22em;
  color: var(--accent); margin: 0 0 .7rem; text-transform: uppercase;
}
h1 {
  font-size: clamp(1.9rem, 4.4vw, 2.55rem);
  line-height: 1.28; font-weight: 600; letter-spacing: .015em;
  margin: 0 0 1rem;
}
.lede {
  font-size: 1.06rem; color: var(--ink-2); margin: 0 0 2.6rem;
  padding-bottom: 1.5rem; border-bottom: 1px solid var(--rule);
  max-width: 38rem;
}

h2 {
  font-size: 1.34rem; font-weight: 600; line-height: 1.5;
  margin: 3.4rem 0 1.1rem; padding-top: .85rem;
  border-top: 1px solid var(--rule);
  scroll-margin-top: 5rem;
}
h3 {
  font-size: 1.06rem; font-weight: 700; line-height: 1.6;
  margin: 2rem 0 .5rem; scroll-margin-top: 5rem;
}
h2 + h3 { margin-top: 1.2rem; }

p { margin: 0 0 1.05rem; text-wrap: pretty; }
ul, ol { padding-left: 1.35em; margin: 0 0 1.15rem; }
li { margin-bottom: .38rem; }
li::marker { color: var(--muted); }
hr { border: 0; border-top: 1px solid var(--rule); margin: 2.6rem 0; }

strong { font-weight: 700; }
em { font-style: normal; border-bottom: 1px dotted var(--muted); }
small { font-size: .86em; color: var(--muted); }

code, .mono { font-family: var(--mono); font-size: .86em; letter-spacing: 0; }
code { background: var(--paper-2); padding: .1em .32em; }

/* ---------- toc ---------- */
.toc {
  display: none; position: sticky; top: 5.2rem; align-self: start;
  max-height: calc(100vh - 7rem); overflow: auto;
  padding-right: .5rem; font-size: .83rem; line-height: 1.7;
}
.toc-label {
  font-family: var(--mono); font-size: .68rem; letter-spacing: .18em;
  color: var(--muted); margin: 0 0 .8rem;
}
.toc ul { list-style: none; margin: 0; padding: 0; }
.toc li { margin: 0 0 .55rem; }
.toc a { color: var(--muted); text-decoration: none; display: block; }
.toc a:hover { color: var(--accent); }
.toc .lv3 { padding-left: .9rem; font-size: .95em; }
.toc-mobile {
  margin: 0 0 2rem; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule);
  padding: .55rem 0; font-size: .9rem;
}
.toc-mobile summary {
  cursor: pointer; font-family: var(--mono); font-size: .74rem;
  letter-spacing: .12em; color: var(--muted);
}
.toc-mobile ul { list-style: none; margin: .7rem 0 .3rem; padding: 0; line-height: 1.8; }
.toc-mobile .lv3 { padding-left: 1rem; }

@media (min-width: 1080px) {
  .shell { grid-template-columns: 12.5rem minmax(0, 1fr); }
  .toc { display: block; }
  .toc-mobile { display: none; }
}

/* ---------- formulas ---------- */
.formula {
  margin: 1.35rem 0 1.5rem; padding: .35rem 0 .35rem .1rem;
  overflow-x: auto; overflow-y: hidden;
}
.katex { font-size: 1.03em; }
.katex-display { margin: .2rem 0; }
.formula .katex-display { margin: 0; }

/* numbered formula block */
.eq {
  display: grid; grid-template-columns: minmax(0, 1fr) auto;
  align-items: center; gap: 1rem;
  margin: 1.35rem 0; padding: .55rem 0;
  border-top: 1px solid var(--rule-soft);
}
.eq:last-child { border-bottom: 1px solid var(--rule-soft); }
.eq .tag { font-family: var(--mono); font-size: .72rem; color: var(--muted); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; margin: 1.3rem 0 1.7rem; }
table {
  width: 100%; border-collapse: collapse; font-size: .94rem; line-height: 1.7;
}
th {
  text-align: left; font-weight: 700; white-space: nowrap;
  border-bottom: 1.5px solid var(--ink); padding: .5rem .65rem .5rem 0;
}
td {
  border-bottom: 1px solid var(--rule-soft); padding: .5rem .65rem .5rem 0;
  vertical-align: top;
}
tr:last-child td { border-bottom: 1px solid var(--rule); }
td:first-child, th:first-child { padding-left: 0; }
table.compact { font-size: .88rem; }

/* ---------- notes ---------- */
.note, .warn, .exam {
  margin: 1.6rem 0; padding: .85rem 1.05rem .9rem;
  background: var(--paper-2); font-size: .95rem; line-height: 1.85;
}
.note > :last-child, .warn > :last-child, .exam > :last-child { margin-bottom: 0; }
.note::before, .warn::before, .exam::before {
  display: block; font-family: var(--mono); font-size: .68rem;
  letter-spacing: .16em; margin-bottom: .45rem;
}
.note::before { content: "NOTE"; color: var(--muted); }
.warn::before { content: "易错"; color: var(--accent); }
.exam::before { content: "怎么考"; color: var(--muted); }
.warn { background: #f1e4dc; }

details.ans {
  margin: .8rem 0 1.4rem; font-size: .95rem;
}
details.ans summary {
  cursor: pointer; display: inline-block;
  font-family: var(--mono); font-size: .74rem; letter-spacing: .12em;
  color: var(--muted); border-bottom: 1px dotted var(--rule);
  list-style: none; padding-bottom: .1rem;
}
details.ans summary::-webkit-details-marker { display: none; }
details.ans summary::before { content: "▸ "; color: var(--accent); }
details.ans[open] summary::before { content: "▾ "; }
details.ans p { margin: .6rem 0 0; }

/* ---------- figures ---------- */
figure.fig {
  margin: 2.2rem 0 2.4rem; padding-top: .8rem;
  border-top: 1px solid var(--ink);
}
figure.fig canvas { display: block; width: 100%; height: auto; }
figure.fig figcaption {
  font-family: var(--mono); font-size: .72rem; line-height: 1.75;
  color: var(--muted); margin-top: .7rem; letter-spacing: .02em;
}
figure.fig figcaption b { color: var(--ink-2); font-weight: 600; }

/* ---------- index ---------- */
.lead-grid { display: grid; gap: 0; margin: 2.4rem 0; border-top: 1px solid var(--rule); }
.entry { display: block; padding: 1.35rem 0 1.25rem; border-bottom: 1px solid var(--rule); text-decoration: none; }
.entry:hover h2 { color: var(--accent); }
.entry h2 {
  border: 0; margin: 0 0 .35rem; padding: 0; font-size: 1.2rem;
}
.entry p { margin: 0; color: var(--ink-2); font-size: .95rem; max-width: 34rem; }
.entry .no {
  font-family: var(--mono); font-size: .7rem; letter-spacing: .16em;
  color: var(--accent); display: block; margin-bottom: .35rem;
}
.entry .meta { font-family: var(--mono); font-size: .7rem; color: var(--muted); margin-top: .5rem; }

.route { counter-reset: step; list-style: none; padding: 0; margin: 1.2rem 0 1.6rem; }
.route li {
  counter-increment: step; position: relative; padding-left: 2.4rem;
  margin-bottom: .8rem; font-size: .96rem;
}
.route li::before {
  content: counter(step); position: absolute; left: 0; top: .18rem;
  font-family: var(--mono); font-size: .72rem; color: var(--accent);
  width: 1.5rem; text-align: right;
}

/* ---------- quiz ---------- */
.quiz-bar {
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: .8rem 1.5rem;
  border-top: 1px solid var(--ink); border-bottom: 1px solid var(--rule);
  padding: .8rem 0; margin: 0 0 2rem; font-size: .9rem;
}
.quiz-bar p { margin: 0; color: var(--ink-2); max-width: 30rem; }
.quiz-bar .tally { font-family: var(--mono); font-size: .78rem; color: var(--muted); white-space: nowrap; }
.quiz-sec h2 { margin-top: 2.6rem; }
.sec-note { font-size: .9rem; color: var(--muted); margin-top: -.4rem; }
.q { padding: 1.4rem 0 1rem; border-bottom: 1px solid var(--rule-soft); }
.q-stem { font-size: 1rem; margin-bottom: .85rem; }
.q-no {
  font-family: var(--mono); font-size: .72rem; color: var(--accent);
  margin-right: .7rem; vertical-align: .1em;
}
.opts { display: grid; gap: .45rem; }
.opt {
  display: flex; gap: .7rem; align-items: baseline; text-align: left;
  font-family: inherit; font-size: .95rem; color: var(--ink);
  background: transparent; border: 1px solid var(--rule);
  padding: .55rem .8rem; cursor: pointer; line-height: 1.7;
}
.opt b { font-family: var(--mono); font-size: .76rem; color: var(--muted); font-weight: 500; }
.opt:hover { border-color: var(--ink-2); background: var(--paper-2); }
.opt.correct { border-color: #4d6b4a; background: #e6ecdf; }
.opt.correct b { color: #3c5a39; }
.opt.wrong { border-color: var(--accent); background: #f1e4dc; }
.opt.wrong b { color: var(--accent); }
.q.solved .opt { cursor: default; }
.q.solved .opt:hover { background: transparent; }
.quiz-reset { margin-top: 2rem; }
.quiz-reset button {
  font-family: inherit; font-size: .9rem; background: transparent;
  border: 1px solid var(--rule); padding: .5rem 1rem; cursor: pointer; color: var(--ink-2);
}
.quiz-reset button:hover { border-color: var(--ink); }

/* ---------- pager ---------- */
.pager {
  display: flex; justify-content: space-between; gap: 1rem;
  margin: 4rem 0 0; padding-top: 1.2rem; border-top: 1px solid var(--rule);
  font-size: .9rem;
}
.pager a { text-decoration: none; max-width: 48%; }
.pager a span {
  display: block; font-family: var(--mono); font-size: .68rem;
  letter-spacing: .12em; color: var(--muted); margin-bottom: .2rem;
}
.pager .next { text-align: right; margin-left: auto; }

/* ---------- foot ---------- */
.site-foot {
  border-top: 1px solid var(--rule);
  padding: 1.6rem clamp(1.1rem, 4vw, 2.6rem) 2.6rem;
  max-width: 66rem; margin: 0 auto;
  font-size: .82rem; color: var(--muted);
}
.site-foot p { margin: 0 0 .4rem; max-width: 42rem; }
.site-foot .mono { font-size: .7rem; letter-spacing: .08em; }

/* ---------- formula sheet ---------- */
.layout-sheet main { max-width: 54rem; }
.sheet-cols { columns: 2; column-gap: 2.6rem; }
.sheet-cols h2, .sheet-cols h3 { break-after: avoid; }
.sheet-cols .formula, .sheet-cols table, .sheet-cols .note { break-inside: avoid; }
.sheet-cols h2 { font-size: 1.06rem; margin-top: 1.8rem; padding-top: .5rem; }
.sheet-cols p, .sheet-cols li { font-size: .88rem; line-height: 1.75; }
.sheet-cols .formula { margin: .5rem 0 .7rem; }
.sheet-cols .katex { font-size: .92em; }

@media (max-width: 700px) {
  body { font-size: 16.5px; line-height: 1.9; }
  .site-head { position: static; align-items: flex-start; flex-direction: column; gap: .6rem; }
  .site-nav { gap: .9rem; }
  .sheet-cols { columns: 1; }
  .opt { font-size: .93rem; }
}

@media print {
  :root { --paper: #fff; --paper-2: #f2f0ea; --ink: #000; --ink-2: #222; --muted: #555; --rule: #bbb; --rule-soft: #ddd; }
  body { font-size: 10.5pt; line-height: 1.6; }
  .site-head, .site-nav, .toc, .toc-mobile, .pager, .site-foot, .quiz-reset, .quiz-bar, .skip { display: none !important; }
  .shell { display: block; padding: 0; max-width: none; }
  main { max-width: none; }
  h1 { font-size: 20pt; }
  h2 { font-size: 12pt; margin-top: 1.4em; page-break-after: avoid; }
  h3 { font-size: 11pt; page-break-after: avoid; }
  .formula, .eq, figure.fig, table, .note, .warn { page-break-inside: avoid; }
  a { text-decoration: none; }
  .sheet-cols { columns: 2; column-gap: 8mm; }
}
