/* Shared stylesheet for every post under blog/. Each post loads this first, then its own
   style.css for anything specific to that post. Research notes use the same voice as the
   home page (mono chrome, violet accent) with a serif body for long reading. */
:root {
  --bg: #ffffff;
  --text: #1a1a1a;
  --muted: #6f6f6f;
  --rule: #e4e4e4;
  --soft: #f4f4f2;
  --accent: #6d4bd6;
  --blue: #2a6ebb;
  --green: #3a8f5c;
  --red: #c8453d;
  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --sans: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --disp: "Martian Mono", "IBM Plex Mono", ui-monospace, monospace;
  --col: 700px;
  --wide: 980px;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--serif); font-size: 18px; line-height: 1.7;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
a { color: inherit; text-decoration: underline; text-decoration-color: #c9bdf0; text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: var(--accent); text-decoration-color: var(--accent); }

/* ---------- top bar: same voice as the home page ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; background: rgba(255,255,255,.94); backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--rule); font-family: var(--mono); font-size: 12px; color: var(--muted);
}
.topbar .in { max-width: var(--wide); margin: 0 auto; padding: 14px 24px; display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.topbar .brand { text-decoration: none; color: var(--text); white-space: nowrap; }
.topbar .brand:hover { color: var(--accent); }
.topbar nav { display: flex; gap: 18px; flex-wrap: wrap; justify-content: flex-end; }
.topbar nav a { text-decoration: none; color: var(--muted); text-transform: lowercase; }
.topbar nav a::before { content: "./"; opacity: .5; }
.topbar nav a:hover { color: var(--accent); }
.progress { position: absolute; left: 0; bottom: -1px; height: 2px; background: var(--accent); width: 0; }

/* ---------- layout: article, with the contents on the right on wide screens ---------- */
.page { display: grid; grid-template-columns: minmax(0, 1fr); max-width: var(--wide); margin: 0 auto; padding: 0 24px; }
.toc { display: none; }
@media (min-width: 1260px) {
  .page { grid-template-columns: minmax(0, 1fr) 200px; column-gap: 48px; max-width: 1300px; }
  .toc { display: block; order: 2; position: sticky; top: 64px; align-self: start; padding-top: 72px; max-height: calc(100vh - 72px); overflow-y: auto; font-family: var(--mono); font-size: 12px; line-height: 1.45; color: var(--muted); }
  .toc .h { color: var(--text); margin-bottom: 10px; text-transform: lowercase; font-weight: 500; }
  .toc .h::before { content: "## "; color: var(--accent); }
  .toc a { position: relative; display: block; text-decoration: none; padding: 3px 0 3px 14px; color: var(--muted); }
  .toc a.sub { padding-left: 28px; font-size: 11.5px; }
  .toc a:hover { color: var(--text); }
  .toc a.active { color: var(--text); }
  .toc a.active::before { content: "›"; position: absolute; left: 2px; color: var(--accent); }
  .toc a.sub.active::before { left: 16px; }
  .outline { display: none; }
}
article { width: 100%; max-width: var(--col); min-width: 0; margin: 0 auto; padding: 64px 0 120px; }
article > .wide { width: min(var(--wide), calc(100vw - 48px)); margin-left: 50%; transform: translateX(-50%); }
@media (min-width: 1260px) { article > .wide { width: var(--wide); } }

/* ---------- header ---------- */
h1.title {
  font-family: var(--disp); font-variation-settings: "wdth" 92; font-weight: 650;
  font-size: clamp(28px, 4.6vw, 42px); line-height: 1.12; letter-spacing: -.025em;
  margin: 0 0 16px; text-align: left; text-wrap: balance;
}
h1.title::before { content: "research note"; display: block; font-family: var(--mono); font-size: 12px; font-weight: 400; letter-spacing: 0; color: var(--accent); margin-bottom: 18px; }
h1.title::after { content: ""; display: inline-block; width: .42em; height: .78em; background: var(--accent); margin-left: .16em; vertical-align: -.04em; }
.subtitle { font-family: var(--serif); font-style: italic; font-size: clamp(18px, 2.2vw, 21px); line-height: 1.45; color: var(--muted); margin: 0 0 24px; }
.byline, .meta { font-family: var(--mono); font-size: 12.5px; line-height: 1.6; color: var(--muted); }
.byline { margin: 0 0 2px; }
.byline b { color: var(--text); font-weight: 500; }
.meta { margin: 0 0 40px; padding-bottom: 28px; border-bottom: 1px solid var(--rule); }
/* a short note right under the header, e.g. which paper the post accompanies */
.companion { font-size: 16.5px; line-height: 1.6; color: var(--muted); margin: -12px 0 36px; padding-left: 16px; border-left: 2px solid var(--accent); }
.companion em { color: var(--text); }

/* ---------- typography ---------- */
h2 {
  font-family: var(--disp); font-variation-settings: "wdth" 88; font-weight: 500;
  font-size: 22px; line-height: 1.3; letter-spacing: -.02em;
  margin: 72px 0 18px; padding-top: 22px; border-top: 1px solid var(--rule);
}
h3 { font-family: var(--mono); font-weight: 500; font-size: 16.5px; line-height: 1.4; margin: 40px 0 10px; }
h4 { font-family: var(--mono); font-size: 12px; font-weight: 500; text-transform: lowercase; color: var(--muted); margin: 28px 0 8px; }
p { margin: 0 0 18px; }
ul, ol { padding-left: 24px; margin: 0 0 18px; }
li { margin-bottom: 6px; }
strong { font-weight: 600; }
.num { font-family: var(--mono); font-weight: 500; font-size: 13px; letter-spacing: 0; color: var(--accent); margin-right: 12px; vertical-align: .2em; }
.num::before { content: "§"; }
hr { border: 0; border-top: 1px solid var(--rule); margin: 56px 0; }
.katex { font-size: 1.02em; }
.katex-display { position: relative; margin: 14px 0 22px; overflow-x: auto; overflow-y: hidden; padding: 2px 0; }
sup.fn a { text-decoration: none; color: var(--accent); font-family: var(--mono); font-size: 11.5px; }

/* ---------- boxes ---------- */
.tldr { position: relative; border: 1px solid #cfcfcf; padding: 24px 24px 8px; margin: 12px 0 40px; background: var(--bg); }
.tldr h4 { position: absolute; top: -10px; left: 16px; margin: 0; padding: 0 8px; background: var(--bg); color: var(--accent); line-height: 20px; }
.tldr ul { list-style: none; padding-left: 0; }
.tldr li { position: relative; padding-left: 24px; margin-bottom: 12px; font-size: 16.5px; line-height: 1.6; }
.tldr li::before { content: "→"; position: absolute; left: 0; top: .1em; color: var(--accent); font-family: var(--mono); font-size: 14px; }
.outline { font-family: var(--mono); font-size: 13px; margin-bottom: 8px; }
.outline h4 { margin: 0 0 8px; }
.outline ol { list-style: none; padding-left: 0; counter-reset: o; columns: 2; column-gap: 32px; }
.outline li { counter-increment: o; margin-bottom: 4px; break-inside: avoid; }
.outline li::before { content: "§" counter(o) " "; color: var(--accent); }
.outline a { text-decoration: none; color: var(--muted); }
.outline a:hover { color: var(--accent); }
.callout { border: 1px dashed #cfcfcf; padding: 16px 20px 4px; margin: 22px 0 26px; background: var(--bg); }
.callout.q { border: 0; border-left: 2px solid var(--accent); padding: 4px 0 2px 20px; }
.callout.q p { font-size: 19px; font-style: italic; }
.callout .lbl { font-family: var(--mono); font-size: 12px; font-weight: 500; text-transform: lowercase; color: var(--accent); margin-bottom: 6px; }
.twocol { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin: 20px 0 26px; }
@media (max-width: 640px) { .twocol { grid-template-columns: 1fr; } }
.twocol .callout { margin: 0; }
.theorem { border-left: 2px solid var(--blue); padding: 6px 18px; margin: 20px 0 24px; }
.theorem .lbl { font-family: var(--mono); font-weight: 500; color: var(--blue); font-size: 12px; text-transform: lowercase; }
details { margin: 12px 0 22px; border: 1px solid var(--rule); padding: 10px 18px; }
details summary { cursor: pointer; font-family: var(--mono); font-size: 13px; color: var(--muted); }
details[open] summary { margin-bottom: 8px; }

/* ---------- algorithm ---------- */
.algo { position: relative; font-family: var(--mono); font-size: 13px; line-height: 1.65; background: var(--soft); border: 1px solid var(--rule); padding: 16px 18px; margin: 22px 0 28px; overflow-x: auto; }
.algo .t { font-weight: 500; font-size: 12.5px; color: var(--muted); margin-bottom: 10px; }
.algo .ln { display: flex; gap: 12px; white-space: nowrap; }
.algo .n { color: #a8a8a8; width: 20px; flex: none; text-align: right; }
.algo .c { color: var(--muted); }
.algo .k { color: var(--accent); font-weight: 500; }
.algo .i1 { padding-left: 22px; } .algo .i2 { padding-left: 44px; } .algo .i3 { padding-left: 66px; }
.algo .katex { font-size: 1em; }

/* ---------- figures ---------- */
figure { margin: 34px 0 40px; }
.fig { border: 1px solid var(--rule); padding: 14px 14px 8px; background: #fff; }
.controls { display: flex; flex-wrap: wrap; gap: 10px 22px; align-items: center; padding: 4px 6px 10px; font-family: var(--mono); font-size: 12px; color: var(--muted); }
.controls .grp { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.controls .grp > .lbl { font-weight: 500; color: var(--text); font-size: 11.5px; text-transform: lowercase; }
.controls .grp > .lbl::after { content: ":"; color: var(--muted); }
.pills { display: inline-flex; flex-wrap: wrap; gap: 2px; background: #fff; border: 1px solid var(--rule); border-radius: 3px; padding: 2px; }
.pills button { border: 0; background: transparent; color: var(--muted); font: 400 12px var(--mono); padding: 4px 9px; border-radius: 2px; cursor: pointer; }
.pills button.on { background: var(--text); color: #fff; }
.pills button:hover:not(.on) { color: var(--text); background: var(--soft); }
.slider { display: inline-flex; align-items: center; gap: 8px; }
.slider input[type=range] { width: 150px; accent-color: var(--accent); }
.slider .val { font-family: var(--mono); font-size: 12px; color: var(--text); min-width: 52px; }
.btn { border: 1px solid var(--rule); background: #fff; border-radius: 3px; padding: 4px 10px; font: 400 12px var(--mono); cursor: pointer; color: var(--text); }
.btn:hover { border-color: var(--accent); color: var(--accent); }
.chk { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.chk input { accent-color: var(--accent); }
.plot { width: 100%; }
figcaption { font-family: var(--sans); font-size: 13.5px; line-height: 1.55; color: var(--muted); margin-top: 12px; padding: 0 2px; }
figcaption b { color: var(--text); font-weight: 600; }
.fig .mini { font-size: 12px; color: var(--muted); padding: 2px 6px 4px; font-family: var(--mono); }
.fig .mini b { color: var(--text); font-weight: 500; }

/* ---------- tables ---------- */
table.tbl { border-collapse: collapse; width: 100%; font-family: var(--mono); font-size: 12.5px; margin: 14px 0 6px; font-variant-numeric: tabular-nums; }
table.tbl th, table.tbl td { padding: 7px 10px; text-align: right; border-bottom: 1px solid var(--rule); white-space: nowrap; }
table.tbl th { font-weight: 500; color: var(--muted); font-size: 11.5px; border-bottom: 1px solid var(--text); }
table.tbl td:first-child, table.tbl th:first-child { text-align: left; }
table.tbl tr.grp td { background: var(--soft); font-weight: 500; }
table.tbl .hi { color: var(--accent); font-weight: 500; }
.tcap { font-family: var(--sans); font-size: 13.5px; line-height: 1.55; color: var(--muted); margin: 0 0 26px; }
.tcap b { color: var(--text); }

/* ---------- SVG diagrams ---------- */
.diagram { margin: 22px 0 30px; text-align: center; }
.diagram svg { max-width: 100%; height: auto; font-family: var(--sans); }
.diagram .cap { font-family: var(--sans); font-size: 13.5px; color: var(--muted); margin-top: 8px; }

/* ---------- footnotes ---------- */
.footnotes { font-size: 15px; color: var(--muted); }
.footnotes ol { padding-left: 20px; }
.footnotes li { margin-bottom: 8px; }
.refs li { margin-bottom: 8px; font-size: 15.5px; line-height: 1.55; }
.nw { white-space: nowrap; }  /* keeps punctuation on the same line as inline math */
.refs li::marker { font-family: var(--mono); font-size: 12px; color: var(--accent); }

/* citation boxes; blog/cite.js fills the paper entry and wires the copy buttons */
.bib { position: relative; margin: 8px 0 20px; border: 1px solid var(--rule); background: var(--soft); }
.bib pre { margin: 0; padding: 12px 70px 12px 14px; font: 12px/1.55 var(--mono); color: var(--text); overflow-x: auto; }
.bib .cp { position: absolute; top: 8px; right: 8px; font: 11.5px var(--mono); color: var(--accent); background: var(--bg); border: 1px solid var(--rule); padding: 2px 8px; cursor: pointer; }
.bib .cp:hover { border-color: var(--accent); }
footer { font-family: var(--mono); color: var(--muted); font-size: 12px; padding: 30px 0 60px; margin-top: 40px; border-top: 1px solid var(--rule); }

/* ---------- small screens ---------- */
@media (max-width: 760px) {
  body { font-size: 17px; }
  .page { padding: 0 16px; }
  article { padding-top: 44px; }
  article > .wide { width: calc(100vw - 32px); }
  h2 { font-size: 20px; margin-top: 56px; }
  .topbar .in { padding: 12px 16px; }
  .topbar nav { gap: 12px; }
  .controls .slider input[type=range] { width: 110px; }
}
@media (max-width: 640px) { .outline ol { columns: 1; } }

/* ---------- live algorithm panel ---------- */
.fig .split { display: grid; grid-template-columns: minmax(300px, 0.95fr) 1.05fr; gap: 14px; align-items: start; }
@media (max-width: 900px) { .fig .split { grid-template-columns: 1fr; } }
.algo.live { margin: 0; font-size: 12.5px; padding: 14px 16px; }
.algo.live .ln { padding: 1px 4px; }
.algo.live .ln.hl { background: #ebe5fa; }
.algo.live .ln.tap { background: #f3effc; box-shadow: inset 2px 0 0 var(--accent); }
.algo .v { color: var(--accent); font-weight: 500; }
.algo .dim { color: #a8a8a8; }
.algo .cnt { margin-top: 10px; font-size: 12px; color: var(--muted); }
.algo .cnt b { color: var(--text); font-weight: 500; }

/* tables share the figures' width and centring */
.wide.tables { overflow-x: auto; }
.wide.tables table.tbl { width: 100%; }
.wide.tables .tcap { padding: 0 4px; }
