/* ═══════════════════════════════════════════════════════════════
   tufte.css — Tufte 网格 + 右侧 gutter sidenote
   ported from ~/Desktop/pdrk_agent/webpage.css
   palette aligned with poole.css / dark-mode.css (this blog)
   ═══════════════════════════════════════════════════════════════ */

:root {
  /* 严格对齐 poole.css / lanyon.css 的字体栈 */
  --body-font: "Palatino Linotype", "Spectral", "Palatino LT STD", "Book Antiqua", Georgia, serif;
  --heading-font: "Palatino Linotype", "Spectral", "Palatino LT STD", "Book Antiqua", Georgia, serif;
  --code-font: "JetBrains Mono", Menlo, Monaco, "Courier New", monospace;

  --text: #313131;        /* poole.css heading colour */
  --body: #515151;        /* poole.css body */
  --muted: #717171;
  --faint: #9a9a9a;
  --accent: #268bd2;      /* solarized blue link */
  --accent-bg: #f4faff;
  --warn: #bf616a;        /* poole inline code red — repurposed for warn */
  --warn-bg: #fdf3f4;
  --rule: #e5e5e5;
  --rule-light: #eee;
  --bg: #FFFEF0;          /* signature cream */
  --code-bg: #f9f9f9;
  --code-text: #bf616a;
  --table-rule: #303030;
  --sidenote-width: 240px;
  --gutter-width: 280px;
}

/* Dark mode — mirrors dark-mode.css; activates when blog toggles `data-theme="dark"`. */
[data-theme="dark"] {
  --text: #F0EAD6;
  --body: #dddddd;
  --muted: #bbbbbb;
  --faint: #888;
  --accent: #ccccf0;
  --accent-bg: #2b2b3a;
  --warn: #e09a9a;
  --warn-bg: #3a2c2c;
  --rule: #444444;
  --rule-light: #3a3a3a;
  --bg: #333333;
  --code-bg: #444444;
  --code-text: #ddddad;
  --table-rule: #888;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
body {
  counter-reset: sec;
  font-family: var(--body-font);
  color: var(--body);
  background: var(--bg);
  line-height: 1.55;
  font-feature-settings: "halt";
  text-spacing-trim: trim-start;
}

/* ── Tufte grid ── */
.grid {
  display: grid;
  grid-template-columns: 1fr var(--gutter-width);
  gap: 48px;
  max-width: 1100px;
  margin: 0 auto;
  padding: 40px 40px 120px;
}

/* ── Frontmatter (spans both columns) ── */
.frontmatter {
  grid-column: 1 / -1;
  margin-bottom: 40px;
  padding-bottom: 28px;
  border-bottom: 1px solid var(--rule);
}
.frontmatter h1 {
  font-family: var(--heading-font);
  font-size: 2em;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: 0.01em;
  color: var(--text);
  margin-bottom: 6px;
}
.frontmatter .meta {
  font-size: .8em;
  color: var(--muted);
  font-feature-settings: "c2sc", "smcp";
  letter-spacing: .04em;
  text-transform: lowercase;
  margin-bottom: 18px;
}
.frontmatter .abstract {
  font-size: .92em;
  color: var(--muted);
  max-width: 64ch;
  line-height: 1.6;
}

/* ── Main column ── */
.main-col { min-width: 0; }

/* ── Right gutter ── */
.gutter {
  font-size: .85em;
  line-height: 1.5;
  color: var(--muted);
}
.gutter.sticky {
  position: sticky;
  top: 28px;
  align-self: start;
  max-height: calc(100vh - 56px);
  overflow-y: auto;
}
.gutter h2,
.gutter .gutter-title {
  font-family: var(--heading-font);
  font-size: .85em;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--faint);
  margin: 0 0 10px;
  padding: 0;
  border: none;
}
.gutter h2::before { content: none; }
.gutter ol,
.gutter ul {
  list-style: none;
  padding-left: 0;
  margin: 0;
}
.gutter ol ol,
.gutter ul ul {
  padding-left: 14px;
  margin-top: 2px;
}
.gutter li {
  margin: 4px 0;
  line-height: 1.4;
}
.gutter a {
  color: var(--muted);
  text-decoration: none;
}
.gutter a:hover { color: var(--accent); }

.gutter figure { margin-bottom: 28px; }
.gutter figure img,
.gutter figure svg { max-width: 100%; height: auto; }
.gutter figcaption {
  font-size: .9em;
  font-style: italic;
  margin-top: 4px;
  color: var(--muted);
}
.gutter dl { margin-bottom: 22px; }
.gutter dt {
  font-weight: 700;
  color: var(--text);
  margin-top: 10px;
  font-size: .95em;
}
.gutter dd {
  margin-left: 0;
  margin-top: 2px;
  color: var(--muted);
}

/* ── Sections ── */
section { margin-bottom: 36px; }
section:target { scroll-margin-top: 28px; }

h2 {
  font-family: var(--heading-font);
  font-size: 1.35em;
  font-weight: 600;
  margin: 2em 0 .5em;
  padding-bottom: .3em;
  border-bottom: 1px solid var(--rule);
  counter-increment: sec;
  clear: both;
  color: var(--text);
}
h2::before { content: "§ " counter(sec) " · "; color: var(--faint); }

h3 {
  font-family: var(--heading-font);
  font-size: 1.05em;
  font-weight: 600;
  margin: 1.5em 0 .4em;
  color: var(--text);
}
h4 {
  font-family: var(--heading-font);
  font-size: .95em;
  font-weight: 600;
  font-style: italic;
  margin: 1.2em 0 .3em;
  color: var(--text);
}

p { margin: .8em 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
strong { font-weight: 700; color: var(--text); }
em { font-style: italic; }

blockquote {
  border-left: 2px solid var(--rule);
  padding: .3em 0 .3em 18px;
  margin: 1em 0;
  color: var(--muted);
  font-style: italic;
  font-size: .95em;
}

/* ── Inline code ── */
:not(pre) > code {
  font-family: var(--code-font);
  font-size: .88em;
  background: var(--code-bg);
  color: var(--code-text);
  padding: 1px 5px;
  border-radius: 3px;
}
pre {
  font-family: var(--code-font);
  font-size: .85em;
  line-height: 1.5;
  background: var(--code-bg);
  border-radius: 3px;
  padding: 14px 18px;
  margin: 1em 0;
  overflow-x: auto;
}
pre code { color: var(--body); background: none; padding: 0; }

/* ── Callout ── */
.callout {
  border-left: 2px solid var(--rule);
  padding: 8px 16px;
  margin: 1em 0;
  font-size: .92em;
  color: var(--muted);
}
.callout.accent {
  border-left-color: var(--accent);
  background: var(--accent-bg);
  color: var(--text);
  font-style: italic;
}
.callout.warn {
  border-left-color: var(--warn);
  background: var(--warn-bg);
}

/* ── Sidenote (floats into the gutter) ── */
.sidenote {
  float: right;
  clear: right;
  margin-right: calc(-1 * var(--gutter-width) - 48px);
  width: var(--sidenote-width);
  font-size: .75em;
  line-height: 1.4;
  color: var(--muted);
  margin-top: 3px;
}

/* ── Margin figure ── */
.margin-fig {
  float: right;
  clear: right;
  margin-right: calc(-1 * var(--gutter-width) - 48px);
  width: var(--gutter-width);
  margin-bottom: 20px;
  margin-top: 6px;
}
.margin-fig img,
.margin-fig svg { max-width: 100%; height: auto; }
.margin-fig .fig-cap {
  font-size: .8em;
  font-style: italic;
  color: var(--muted);
  margin-top: 4px;
}

/* ── Inline figure (in main column) ── */
.inline-fig,
figure {
  margin: 1.4em 0;
  text-align: center;
}
.inline-fig svg,
figure svg { max-width: 100%; height: auto; }
.inline-fig .fig-cap,
figure figcaption {
  font-size: .85em;
  font-style: italic;
  color: var(--muted);
  margin-top: 6px;
  text-align: left;
}

/* ── Tables (booktabs) ── */
.table-wrap {
  margin: 1.2em 0;
  overflow-x: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9em;
  margin: 1em 0;
}
thead { border-top: 2px solid var(--table-rule); border-bottom: 1.5px solid var(--table-rule); }
thead th {
  font-feature-settings: "c2sc", "smcp";
  letter-spacing: .04em;
  text-align: left;
  padding: 6px 10px;
  font-weight: 600;
  color: var(--text);
}
tbody td {
  padding: 5px 10px;
  border-bottom: .5px solid var(--rule-light);
  vertical-align: top;
}
tbody tr:last-child { border-bottom: 1.5px solid var(--table-rule); }
.highlight-row { background: var(--code-bg); }
.highlight-row td { font-weight: 600; }

/* ── Tag labels ── */
.tag {
  display: inline-block;
  font-size: .72em;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--faint);
}

/* ── Branch list ── */
.branch-list { margin: 1em 0; }
.branch {
  margin-bottom: 8px;
  padding-left: 14px;
  border-left: 2px solid transparent;
}
.branch.a { border-left-color: #4a7c5c; }
.branch.b { border-left-color: #b08a3c; }
.branch.c { border-left-color: #3c5a7c; }
.branch.d { border-left-color: #6b6b6b; }
.branch.e { border-left-color: var(--warn); }
.branch .br-label { font-size: .8em; font-weight: 600; color: var(--muted); }
.branch h4 { margin: 2px 0; font-style: normal; }

/* ── Two-col card grid ── */
.card-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 1em 0; }

/* ── Misc ── */
hr { border: none; border-top: 1px solid var(--rule); max-width: 30%; margin: 2em auto; }
ol, ul { padding-left: 22px; margin: .6em 0; }
li { margin: .2em 0; }
sup { font-size: .8em; }
dl { margin: 1em 0; }
dt { font-weight: 700; margin-top: .8em; color: var(--text); }
dd { margin-left: 1.5em; color: var(--muted); }

/* ── Axiom list (Ω numbered) — booktabs-rule style, no colour block ── */
dl.axioms {
  margin: 1.6em 0;
  padding: 12px 0;
  border-top: 1.5px solid var(--table-rule);
  border-bottom: 1.5px solid var(--table-rule);
  display: grid;
  grid-template-columns: max-content 1fr;
  column-gap: 28px;
  row-gap: 6px;
  align-items: baseline;
  font-size: .95em;
}
dl.axioms dt {
  font-family: var(--heading-font);
  font-weight: 600;
  color: var(--muted);
  margin: 0;
  white-space: nowrap;
  letter-spacing: .02em;
}
dl.axioms dt sub {
  font-size: .7em;
  vertical-align: -.15em;
  color: var(--text);
  font-weight: 700;
  margin-left: -.05em;
}
dl.axioms dd {
  margin: 0;
  color: var(--body);
  line-height: 1.55;
}

/* ── Narrow screen ── */
@media (max-width: 900px) {
  .grid { grid-template-columns: 1fr; padding: 24px 20px 80px; }
  .sidenote, .margin-fig { float: none; margin: .8em 0; width: auto; clear: both; }
  .frontmatter h1 { font-size: 1.5em; }
  .gutter { font-size: .85em; }
  .gutter.sticky { position: static; max-height: none; }
  .card-grid { grid-template-columns: 1fr; }
}
