/* ============================================
   snsnegi.com design system — Distill
   Cool white paper, serif prose / sans chrome, teal ink.
   Light ("paper") is the default theme; [data-theme="dark"] is the override.
   ============================================ */

/* --- Tokens (Light / paper, default) --- */
:root {
  --paper: #ffffff;
  --paper-dim: #f7f9fa;
  --ink: #1b1f23;
  --ink-soft: #4a5259;
  --ink-faint: #8a929a;
  --rule: #e2e6e9;
  --rule-dark: #c9cfd4;
  --accent: #0b7285;
  --accent-soft: #e6f2f5;
  --warn: #b0871f;
  --bad: #b03a2e;
  --good: #2b7a3d;
  --serif: Charter, "Iowan Old Style", Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --mono: "SF Mono", "Fira Code", Menlo, Consolas, monospace;

  /* Legacy aliases — older classes and rich post content reference these;
     they inherit the active theme automatically. */
  --bg: var(--paper);
  --bg-alt: var(--paper-dim);
  --surface: var(--paper-dim);
  --text: var(--ink);
  --text-muted: var(--ink-soft);
  --border: var(--rule);
  --accent-dim: var(--accent-soft);
  --on-accent: #ffffff;
  --radius: 6px;
  --font: var(--sans);
  --font-mono: var(--mono);
}

/* --- Tokens (Dark override) --- */
[data-theme="dark"] {
  --paper: #14181c;
  --paper-dim: #1b2126;
  --ink: #d8dee3;
  --ink-soft: #a0a9b1;
  --ink-faint: #6e7880;
  --rule: #262e34;
  --rule-dark: #3a444c;
  --accent: #5bc0d4;
  --accent-soft: rgba(91, 192, 212, 0.10);
  --warn: #d9a53f;
  --bad: #e07b6e;
  --good: #5fb376;
}

html { color-scheme: light; }
[data-theme="dark"] { color-scheme: dark; }

/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; }

body {
  font-family: var(--serif);
  background: var(--paper);
  color: var(--ink);
  font-size: 1rem;
  line-height: 1.55;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  transition: background-color 160ms ease, color 160ms ease;
}

/* --- Typography --- */
h1, h2, h3, h4 {
  font-family: var(--sans);
  line-height: 1.3;
  margin-bottom: 0.4em;
  scroll-margin-top: 4.5rem;
  letter-spacing: -0.01em;
}
h1 { font-size: 1.75rem; font-weight: 800; }
h2 { font-size: 1.35rem; margin-top: 1.5em; font-weight: 700; }
h3 { font-size: 1.1rem; font-weight: 700; }
h4 { font-size: 1rem; font-weight: 600; }
p { margin-bottom: 0.75em; color: var(--ink); }
hr { border: none; border-top: 1px solid var(--rule); margin: 1.75rem 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
ul, ol { padding-left: 1.5em; margin-bottom: 0.75em; }
li { margin-bottom: 0.15em; }
small { color: var(--ink-soft); }
.text-muted { color: var(--ink-soft); }

/* --- Layout scaffold --- */
.page { flex: 1; display: flex; flex-direction: column; width: 100%; }
.container { max-width: 720px; margin: 0 auto; padding: 2rem 1.5rem; }
.state-page { text-align: center; padding-top: 6rem; }
.state-page h1 { font-size: 2.25rem; }

/* ==================== masthead ==================== */
/* Sticky wrapper-less masthead: the header itself sticks so the
   detail page's scroll-title (appended into #nav-brand) stays visible. */
.masthead {
  font-family: var(--sans);
  display: flex; align-items: baseline; justify-content: space-between;
  padding: 0.8rem max(2rem, calc((100% - 1180px) / 2 + 2rem));
  border-bottom: 1px solid var(--rule);
  background: var(--paper);
  position: sticky;
  top: 0;
  z-index: 100;
}
.masthead .brand { font-weight: 700; font-size: 0.95rem; color: var(--ink); letter-spacing: -0.01em; }
.masthead .brand:hover { text-decoration: none; color: var(--accent); }
.masthead .nav-links { display: flex; align-items: center; gap: 1.4rem; font-size: 0.8rem; }
.masthead .nav-links a { color: var(--ink-soft); }
.masthead .nav-links a:hover { color: var(--accent); text-decoration: none; }
.masthead .toggle {
  font-family: var(--sans); font-size: 0.72rem; color: var(--ink-faint);
  background: none; border: 1px solid var(--rule); border-radius: 4px;
  padding: 0.2rem 0.55rem; cursor: pointer;
}
.masthead .toggle:hover { color: var(--ink); }
/* scroll-title, filled in by the detail-page JS */
.masthead .brand .nav-title {
  font-family: var(--sans); font-weight: 400; font-size: 0.8rem; color: var(--ink-faint);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40vw; display: none;
}
.masthead .brand.show-title .nav-title { display: inline; }
.masthead .brand .nav-title-sep { color: var(--rule-dark); margin: 0 0.5rem; font-weight: 300; display: none; }
.masthead .brand.show-title .nav-title-sep { display: inline; }

/* ==================== page scaffold ==================== */
.sheet { max-width: 1180px; margin: 0 auto; padding: 0 2rem 4rem; }
.narrow { max-width: 720px; }

/* ==================== home / index ==================== */
.bio { max-width: 720px; padding: 2.25rem 0 0.5rem; }
.bio h1 { font-family: var(--sans); font-size: 1.5rem; font-weight: 800; letter-spacing: -0.02em; }
.bio p { color: var(--ink-soft); font-size: 0.98rem; margin-top: 0.4rem; max-width: 58ch; }

.series-head {
  font-family: var(--sans); display: flex; align-items: baseline; gap: 0.7rem;
  border-bottom: 1px solid var(--ink); padding-bottom: 0.3rem; margin: 2.2rem 0 0.6rem;
}
.series-head h2 { font-size: 0.82rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.1em; margin: 0; }
.series-head .count { font-size: 0.72rem; color: var(--ink-faint); }
.series-head .all { margin-left: auto; font-size: 0.72rem; }

/* index as table — date / title+desc / tags */
.index-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.index-table td { padding: 0.42rem 0.75rem 0.42rem 0; border-bottom: 1px solid var(--rule); vertical-align: baseline; }
.index-table .d { font-family: var(--mono); font-size: 0.72rem; color: var(--ink-faint); white-space: nowrap; width: 6.5rem; }
.index-table .t a { color: var(--ink); font-weight: 600; }
.index-table .t a:hover { color: var(--accent); text-decoration: none; }
.index-table .desc { color: var(--ink-soft); font-size: 0.82rem; }
.index-table .tags { text-align: right; white-space: nowrap; font-family: var(--sans); font-size: 0.7rem; }
.index-table .tags a { color: var(--ink-faint); margin-left: 0.5rem; }
.index-table .tags a:hover { color: var(--accent); }

/* index as two-line dense rows */
.index-rows { display: flex; flex-direction: column; }
.index-rows .row { display: grid; grid-template-columns: 6.5rem 1fr; gap: 0 1rem; padding: 0.5rem 0; border-bottom: 1px solid var(--rule); }
.index-rows .d { font-family: var(--mono); font-size: 0.72rem; color: var(--ink-faint); padding-top: 0.22rem; }
.index-rows .t { font-weight: 650; font-size: 0.95rem; }
.index-rows .t a { color: var(--ink); }
.index-rows .t a:hover { color: var(--accent); text-decoration: none; }
.index-rows .sub { grid-column: 2; color: var(--ink-soft); font-size: 0.82rem; }
.index-rows .sub .tag { font-family: var(--sans); font-size: 0.68rem; color: var(--accent); margin-left: 0.45rem; }

/* index as three-column card-less grid */
.index-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 2.5rem; }
.index-grid .col h3 {
  font-family: var(--sans); font-size: 0.72rem; font-weight: 800; text-transform: uppercase;
  letter-spacing: 0.1em; color: var(--accent); border-bottom: 2px solid var(--accent);
  padding-bottom: 0.3rem; margin-bottom: 0.5rem;
}
.index-grid ul { list-style: none; padding-left: 0; margin-bottom: 0; }
.index-grid li { padding: 0.4rem 0; border-bottom: 1px solid var(--rule); font-size: 0.88rem; line-height: 1.35; margin-bottom: 0; }
.index-grid li a { color: var(--ink); font-weight: 600; }
.index-grid li a:hover { color: var(--accent); text-decoration: none; }
.index-grid li .d { display: block; font-family: var(--mono); font-size: 0.66rem; color: var(--ink-faint); margin-top: 0.15rem; }

/* ==================== article scaffold ==================== */
.article-grid {
  display: grid;
  grid-template-columns: 180px minmax(0, 680px) 240px;
  gap: 0 3rem;
  max-width: 1180px; margin: 0 auto; padding: 0 2rem;
}
.toc-margin { font-family: var(--sans); font-size: 0.75rem; padding-top: 3.2rem; }
.toc-margin .toc-inner { position: sticky; top: 1.5rem; }
.toc-margin h4 { font-size: 0.62rem; text-transform: uppercase; letter-spacing: 0.12em; color: var(--ink-faint); margin-bottom: 0.5rem; }
.toc-margin ol { list-style: none; border-left: 1px solid var(--rule); padding-left: 0; margin-bottom: 0; }
.toc-margin li { margin-bottom: 0; }
.toc-margin li a { display: block; color: var(--ink-soft); padding: 0.22rem 0 0.22rem 0.8rem; border-left: 2px solid transparent; margin-left: -1px; line-height: 1.3; }
.toc-margin li a:hover { color: var(--ink); text-decoration: none; }
.toc-margin li a.active { color: var(--accent); border-left-color: var(--accent); font-weight: 600; }
.margin-col { font-family: var(--sans); font-size: 0.74rem; color: var(--ink-soft); }

/* post header — kicker + standfirst + byline */
.post-head { padding-top: 2.5rem; }
.post-kicker { font-family: var(--sans); font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.12em; color: var(--accent); }
.post-head h1 { font-family: var(--sans); font-size: 1.9rem; font-weight: 800; letter-spacing: -0.025em; line-height: 1.15; margin: 0.35rem 0 0.5rem; }
.post-standfirst { font-size: 1.02rem; color: var(--ink-soft); max-width: 56ch; margin-bottom: 0; }
.post-byline {
  font-family: var(--sans); font-size: 0.75rem; color: var(--ink-faint);
  display: flex; gap: 0.9rem; flex-wrap: wrap; margin-top: 0.8rem; padding: 0.55rem 0;
  border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule);
}
.post-byline b { color: var(--ink-soft); font-weight: 600; }

/* post header, alternate — metadata table (distill-style); kept available */
.post-head-b h1 { font-family: var(--sans); font-size: 2rem; font-weight: 800; letter-spacing: -0.025em; line-height: 1.15; padding-top: 2.5rem; }
.meta-table { font-family: var(--sans); display: grid; grid-template-columns: repeat(4, auto); gap: 0 2.5rem; justify-content: start; margin-top: 0.9rem; padding: 0.6rem 0; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); }
.meta-table div { font-size: 0.78rem; }
.meta-table .k { display: block; font-size: 0.6rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-faint); }
.meta-table .v { color: var(--ink); font-weight: 600; }

/* prose */
.prose { padding: 1.6rem 0 3rem; font-size: 0.98rem; }
.prose p { margin-bottom: 0.85em; }
.prose h2 { font-family: var(--sans); font-size: 1.15rem; font-weight: 750; letter-spacing: -0.01em; margin: 1.9em 0 0.5em; }
.prose h2 .secno { color: var(--ink-faint); font-weight: 500; margin-right: 0.5em; }
.prose h3 { font-family: var(--sans); font-size: 0.95rem; font-weight: 700; margin: 1.5em 0 0.4em; }
.prose ul, .prose ol { padding-left: 1.4em; margin-bottom: 0.85em; }
.prose li { margin-bottom: 0.2em; }
.prose code { font-family: var(--mono); font-size: 0.82em; background: var(--paper-dim); border: 1px solid var(--rule); border-radius: 3px; padding: 0.08em 0.3em; }
.fnref { font-family: var(--sans); font-size: 0.68em; vertical-align: super; color: var(--accent); font-weight: 700; }

/* epigraph */
.epigraph { border: none; margin: 1.5rem 0 1.5rem 2rem; max-width: 46ch; }
.epigraph p { font-style: italic; color: var(--ink-soft); font-size: 0.95rem; margin-bottom: 0.2em; }
.epigraph cite { font-family: var(--sans); font-style: normal; font-size: 0.72rem; color: var(--ink-faint); }

/* callouts (prose notes) */
.note {
  font-family: var(--sans); font-size: 0.83rem; background: var(--accent-soft);
  border-left: 3px solid var(--accent); border-radius: 0 4px 4px 0;
  padding: 0.65rem 0.9rem; margin: 1.1rem 0; color: var(--ink);
}
.note b:first-child { color: var(--accent); text-transform: uppercase; font-size: 0.68rem; letter-spacing: 0.08em; display: block; margin-bottom: 0.15rem; }
.note-warn { background: color-mix(in srgb, var(--warn) 12%, var(--paper)); border-left-color: var(--warn); }
.note-warn b:first-child { color: var(--warn); }
.note-dead { background: color-mix(in srgb, var(--bad) 12%, var(--paper)); border-left-color: var(--bad); }
.note-dead b:first-child { color: var(--bad); }

/* ==================== code ==================== */
pre.code {
  font-family: var(--mono); font-size: 0.78rem; line-height: 1.55;
  background: var(--paper-dim); border: 1px solid var(--rule); border-radius: 6px;
  padding: 0.9rem 1.1rem; overflow-x: auto; margin: 1.1rem 0;
}
pre.code .c { color: var(--ink-faint); font-style: italic; }
pre.code .k { color: #a33ea1; }
pre.code .s { color: var(--good); }
pre.code .n { color: #1c6fb8; }
.code-caption { font-family: var(--sans); font-size: 0.72rem; color: var(--ink-faint); margin: -0.7rem 0 1.1rem; padding-left: 0.2rem; }

/* notebook cells */
.nb { margin: 1.2rem 0; font-size: 0.78rem; }
.nb .cell { display: grid; grid-template-columns: 4.2rem 1fr; }
.nb .gut { font-family: var(--mono); font-size: 0.68rem; text-align: right; padding: 0.85rem 0.6rem 0 0; color: var(--accent); user-select: none; }
.nb .gut.out { color: var(--bad); }
.nb .in pre { font-family: var(--mono); background: var(--paper-dim); border: 1px solid var(--rule); border-left: 3px solid var(--accent); border-radius: 0 6px 6px 0; padding: 0.75rem 1rem; line-height: 1.55; overflow-x: auto; margin: 0; }
.nb .outp pre { font-family: var(--mono); background: none; border: none; padding: 0.55rem 1rem; color: var(--ink-soft); line-height: 1.5; overflow-x: auto; margin: 0; }

/* ==================== figures ==================== */
figure { margin: 1.6rem 0; }
figure.wide { width: 138%; }
figure svg { display: block; width: 100%; height: auto; background: var(--paper); }
figcaption { font-family: var(--sans); font-size: 0.76rem; color: var(--ink-soft); margin-top: 0.5rem; line-height: 1.45; max-width: 64ch; }
figcaption b { color: var(--ink); }
.fig-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; margin: 1.6rem 0; }
.fig-row figure { margin: 0; }
.fig-frame { border: 1px solid var(--rule); border-radius: 6px; padding: 0.6rem; }

/* margin note (sidenote) */
.sidenote {
  float: right; clear: right; width: 240px; margin-right: -290px;
  font-family: var(--sans); font-size: 0.72rem; line-height: 1.45; color: var(--ink-soft);
  border-top: 1px solid var(--rule); padding-top: 0.3rem; margin-top: 0.2rem;
}
.sidenote .sn-no { color: var(--accent); font-weight: 700; }

/* ==================== tables ==================== */
table.results { width: 100%; border-collapse: collapse; font-size: 0.8rem; margin: 1.2rem 0; font-variant-numeric: tabular-nums; }
table.results caption { font-family: var(--sans); font-size: 0.72rem; color: var(--ink-faint); text-align: left; padding-bottom: 0.4rem; }
table.results th { font-family: var(--sans); font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--ink-soft); text-align: left; border-top: 2px solid var(--ink); border-bottom: 1px solid var(--rule-dark); padding: 0.4rem 0.6rem; }
table.results td { padding: 0.34rem 0.6rem; border-bottom: 1px solid var(--rule); }
table.results tr:last-child td { border-bottom: 2px solid var(--ink); }
table.results td.num { font-family: var(--mono); font-size: 0.74rem; text-align: right; }
table.results .best { font-weight: 700; color: var(--good); }
table.results .hl td { background: var(--accent-soft); }

/* ==================== experiment log ==================== */
.exp {
  border: 1px solid var(--rule-dark); border-radius: 6px; margin: 1.3rem 0;
  font-family: var(--sans);
}
.exp-head { display: flex; align-items: center; gap: 0.7rem; padding: 0.55rem 0.9rem; border-bottom: 1px solid var(--rule); background: var(--paper-dim); border-radius: 6px 6px 0 0; }
.exp-head .id { font-family: var(--mono); font-size: 0.72rem; color: var(--ink-faint); }
.exp-head .name { font-weight: 700; font-size: 0.85rem; }
.exp-status { margin-left: auto; font-size: 0.62rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; padding: 0.14rem 0.5rem; border-radius: 999px; }
.exp-status.ok { background: color-mix(in srgb, var(--good) 12%, var(--paper)); color: var(--good); }
.exp-status.fail { background: color-mix(in srgb, var(--bad) 12%, var(--paper)); color: var(--bad); }
.exp-status.run { background: color-mix(in srgb, var(--warn) 12%, var(--paper)); color: var(--warn); }
.exp-body { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1.5rem; padding: 0.7rem 0.9rem; font-size: 0.78rem; }
.exp-body dl { display: grid; grid-template-columns: auto 1fr; gap: 0.15rem 0.8rem; }
.exp-body dt { color: var(--ink-faint); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em; padding-top: 0.1rem; }
.exp-body dd { font-family: var(--mono); font-size: 0.74rem; }
.exp-note { grid-column: 1 / -1; font-family: var(--serif); font-size: 0.85rem; color: var(--ink-soft); border-top: 1px dashed var(--rule); margin-top: 0.5rem; padding-top: 0.5rem; }

/* stat strip */
.stats { display: flex; border-top: 2px solid var(--ink); border-bottom: 1px solid var(--rule-dark); margin: 1.3rem 0; font-family: var(--sans); }
.stats .stat { flex: 1; padding: 0.6rem 0.9rem; border-right: 1px solid var(--rule); }
.stats .stat:last-child { border-right: none; }
.stats .v { font-family: var(--mono); font-size: 1.15rem; font-weight: 600; }
.stats .v.up { color: var(--good); }
.stats .v.down { color: var(--bad); }
.stats .k { font-size: 0.64rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-faint); margin-top: 0.1rem; }

/* ==================== math ==================== */
.math-block { margin: 1.2rem 0; padding: 0.4rem 0; overflow-x: auto; }

/* ==================== connections ==================== */
.connected { border-top: 2px solid var(--ink); margin-top: 2.5rem; padding-top: 1rem; font-family: var(--sans); }
.connected h3 { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.12em; color: var(--ink-faint); margin-bottom: 0.6rem; }
.connected .cols { display: grid; grid-template-columns: 1fr 1fr; gap: 0 2.5rem; }
.connected ul { list-style: none; font-size: 0.82rem; padding-left: 0; margin-bottom: 0; }
.connected li { padding: 0.3rem 0; border-bottom: 1px solid var(--rule); margin-bottom: 0; }
.connected li .rel { font-size: 0.62rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-faint); margin-right: 0.5rem; }
.prevnext { display: flex; justify-content: space-between; gap: 2rem; margin-top: 1.5rem; font-family: var(--sans); font-size: 0.82rem; }
.prevnext a { display: block; max-width: 45%; }
.prevnext .dir { display: block; font-size: 0.62rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-faint); }
.prevnext .next { text-align: right; }

/* footnotes */
.footnotes { border-top: 1px solid var(--rule-dark); margin-top: 2.5rem; padding-top: 0.8rem; font-size: 0.8rem; color: var(--ink-soft); }
.footnotes h3 { font-family: var(--sans); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.12em; color: var(--ink-faint); margin-bottom: 0.5rem; }
.footnotes ol { padding-left: 1.2em; }
.footnotes li { margin-bottom: 0.35em; }

/* footer */
.site-footer { font-family: var(--sans); max-width: 1180px; margin: 3rem auto 0; padding: 1rem 2rem 2.5rem; border-top: 1px solid var(--rule); font-size: 0.72rem; color: var(--ink-faint); display: flex; justify-content: space-between; }


/* ============================================
   Legacy components
   Older classes referenced by existing rich-HTML posts and templates.
   Restyled to the Distill language: flat paper surfaces, hairline rules,
   sans chrome at small sizes, no pill-heavy look.
   ============================================ */

/* --- Nav (aliased to masthead language) --- */
.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 2rem;
  border-bottom: 1px solid var(--rule);
  background: var(--paper);
  font-family: var(--sans);
  position: sticky;
  top: 0;
  z-index: 100;
}
.nav-brand {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--ink);
  text-decoration: none;
  letter-spacing: -0.01em;
}
.nav-brand:hover { text-decoration: none; color: var(--accent); }
.nav-brand-glyph { font-size: 1rem; filter: saturate(0.7); }
.nav-title {
  font-family: var(--sans);
  font-weight: 400;
  font-size: 0.8rem;
  color: var(--ink-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 40vw;
  display: none;
}
.nav-brand.show-title .nav-title { display: inline; }
.nav-title-sep { color: var(--rule-dark); margin: 0 0.5rem; font-weight: 300; display: none; }
.nav-brand.show-title .nav-title-sep { display: inline; }
.nav-links { display: flex; align-items: center; gap: 1.4rem; }
.nav-links a { color: var(--ink-soft); font-size: 0.8rem; }
.nav-links a:hover { color: var(--accent); text-decoration: none; }
.theme-toggle {
  font-family: var(--sans);
  background: none;
  border: 1px solid var(--rule);
  color: var(--ink-faint);
  padding: 0.2rem 0.55rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.72rem;
}
.theme-toggle:hover { color: var(--ink); }

/* --- Footer (legacy) --- */
.footer {
  border-top: 1px solid var(--rule);
  padding: 1.5rem;
  text-align: center;
  color: var(--ink-faint);
  font-size: 0.85rem;
  font-family: var(--sans);
  padding-bottom: 3.5rem;
}
.footer span { color: var(--accent); }

/* --- Home hero (legacy — kept functional, quiet styling) --- */
.home-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  width: 100%;
  max-width: 40rem;
  margin: 0 auto;
  padding: 5rem 1.5rem 4rem;
}
.home-glyph { font-size: 1.75rem; margin-bottom: 2.5rem; filter: saturate(0.7); }
.home-main h1 { font-family: var(--sans); font-size: clamp(2rem, 6vw, 2.75rem); font-weight: 800; letter-spacing: -0.03em; line-height: 1.15; }
.home-subtitle { margin-top: 0.75rem; font-size: 1.05rem; color: var(--ink-soft); font-weight: 400; font-family: var(--sans); }
.home-subtitle .accent { color: var(--accent); }
.home-sections { margin-top: 4rem; display: flex; flex-direction: column; border-top: 1px solid var(--rule); font-family: var(--sans); }
.home-sections a {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.15rem 0.25rem;
  border-bottom: 1px solid var(--rule);
  text-decoration: none;
  color: var(--ink);
  transition: color 160ms ease, padding-left 160ms ease;
}
.home-sections a:hover, .home-sections a:focus-visible {
  color: var(--accent);
  padding-left: 0.75rem;
  outline: none;
  text-decoration: none;
}
.home-sections a .label { font-size: 1.05rem; font-weight: 600; }
.home-sections a .hint { font-size: 0.85rem; color: var(--ink-soft); text-align: right; }

/* --- Section card --- */
.section {
  background: var(--paper-dim);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}
.section h3 { margin-bottom: 0.75rem; }

/* --- Callout --- */
.callout {
  font-family: var(--sans);
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
  padding: 0.6rem 0.85rem;
  margin-bottom: 1rem;
  border-radius: 0 4px 4px 0;
  color: var(--ink);
  font-size: 0.85rem;
}
.callout-warn {
  font-family: var(--sans);
  background: color-mix(in srgb, var(--warn) 12%, var(--paper));
  border-left: 3px solid var(--warn);
  padding: 0.6rem 0.85rem;
  margin-bottom: 1rem;
  border-radius: 0 4px 4px 0;
  font-size: 0.85rem;
  color: var(--ink);
}
.callout-warn strong { color: var(--warn); }
.callout-success {
  font-family: var(--sans);
  background: color-mix(in srgb, var(--good) 12%, var(--paper));
  border-left: 3px solid var(--good);
  padding: 0.6rem 0.85rem;
  margin-bottom: 1rem;
  border-radius: 0 4px 4px 0;
  font-size: 0.85rem;
  color: var(--ink);
}
.callout-success strong { color: var(--good); }

/* --- Grid --- */
.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

/* --- Info box --- */
.info-box {
  background: var(--paper-dim);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 0.75rem;
}
.info-box h4 { margin-bottom: 0.3rem; }
.info-box p { margin-bottom: 0; color: var(--ink-soft); font-size: 0.85rem; }

/* --- Tables (legacy) --- */
.table, article table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1.5rem;
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}
.table th, .table td,
article table th, article table td {
  text-align: left;
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--rule);
}
.table th, article table th {
  font-family: var(--sans);
  font-weight: 600;
  color: var(--ink-soft);
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  border-top: 2px solid var(--ink);
  border-bottom: 1px solid var(--rule-dark);
}
.table tr:last-child td, article table tr:last-child td { border-bottom: 2px solid var(--ink); }

/* --- Badges (smaller, squarer) --- */
.badge {
  display: inline-block;
  font-family: var(--sans);
  padding: 0.12rem 0.4rem;
  border-radius: 3px;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.badge-good { background: color-mix(in srgb, var(--good) 14%, var(--paper)); color: var(--good); }
.badge-bad { background: color-mix(in srgb, var(--bad) 14%, var(--paper)); color: var(--bad); }
.badge-neutral { background: var(--paper-dim); color: var(--ink-soft); border: 1px solid var(--rule); }
.badge-warn { background: color-mix(in srgb, var(--warn) 14%, var(--paper)); color: var(--warn); }

/* --- Helper box --- */
.helper-box {
  background: var(--paper-dim);
  border: 1px dashed var(--rule-dark);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1.5rem;
  font-size: 0.9rem;
  color: var(--ink-soft);
}
.helper-box strong { color: var(--ink); }

/* --- Code blocks (legacy bare pre/code) --- */
pre {
  font-family: var(--mono);
  background: var(--paper-dim);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 1rem;
  overflow-x: auto;
  margin-bottom: 1.5rem;
  font-size: 0.85rem;
  line-height: 1.5;
}
code {
  font-family: var(--font-mono);
  font-size: 0.85em;
}
:not(pre) > code {
  background: var(--paper-dim);
  border: 1px solid var(--rule);
  padding: 0.1rem 0.35rem;
  border-radius: 3px;
}

/* --- Tabs --- */
.tabs { margin-bottom: 1.5rem; }
.tab-btns {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 1rem;
  font-family: var(--sans);
}
.tab-btn {
  background: none;
  border: none;
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  color: var(--ink-soft);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  font-family: var(--sans);
  transition: color 0.15s, border-color 0.15s;
}
.tab-btn:hover { color: var(--ink); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* --- Caveat / warning box --- */
.caveat-box {
  background: color-mix(in srgb, var(--bad) 6%, var(--paper));
  border: 1px solid color-mix(in srgb, var(--bad) 25%, var(--rule));
  border-left: 3px solid var(--bad);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
  font-size: 0.85rem;
  color: var(--ink);
}
.caveat-box h4 { color: var(--bad); margin-bottom: 0.4rem; }
.caveat-box strong { color: var(--bad); }

/* --- Collapsible groups --- */
.theme-group { margin-bottom: 1rem; }
.theme-group > summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 0.75rem;
}
.theme-group > summary::-webkit-details-marker { display: none; }
.theme-group > summary::before {
  content: "▸";
  font-size: 0.75rem;
  color: var(--ink-faint);
  transition: transform 0.15s;
}
.theme-group[open] > summary::before { transform: rotate(90deg); }
.theme-group > summary h3 { margin: 0; }

/* --- Section nav (floating bottom TOC, shown under 1100px) --- */
.section-nav-wrap {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 199;
  display: none;
}
.section-nav {
  display: flex;
  align-items: center;
  gap: 0;
  background: var(--paper);
  border-top: 1px solid var(--rule);
  padding: 0.5rem 1.5rem;
  overflow-x: auto;
  scrollbar-width: none;
  font-family: var(--sans);
}
.section-nav::-webkit-scrollbar { display: none; }
.section-nav a {
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 0.7rem;
  font-weight: 500;
  padding: 0.25rem 0.6rem;
  border-radius: 4px;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
  flex-shrink: 0;
}
.section-nav a:hover {
  color: var(--ink);
  background: var(--paper-dim);
  text-decoration: none;
}
.section-nav a.active {
  color: var(--accent);
  background: var(--accent-soft);
}

/* --- Stat row --- */
.stat-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.stat-item {
  text-align: center;
  padding: 0.75rem 0.5rem;
  background: var(--paper-dim);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
}
.stat-value {
  font-family: var(--sans);
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.2;
}
.stat-label {
  font-family: var(--sans);
  font-size: 0.7rem;
  color: var(--ink-soft);
  margin-top: 0.2rem;
}

/* --- Reference list --- */
.ref-list {
  font-size: 0.8rem;
  color: var(--ink-soft);
  line-height: 1.6;
}
.ref-list li { margin-bottom: 0.4rem; }
.ref-list em { color: var(--ink-soft); }
.ref-list a { word-break: break-all; }

/* --- Post list (blog index) --- */
.post-list { display: flex; flex-direction: column; gap: 1rem; }
.post-card {
  background: var(--paper-dim);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 1.25rem;
  transition: border-color 160ms ease;
}
.post-card:hover { border-color: color-mix(in srgb, var(--accent) 35%, var(--rule)); }
.post-card h2 { margin-bottom: 0.4rem; font-size: 1.2rem; margin-top: 0; }
.post-card h2 a { color: var(--ink); }
.post-card h2 a:hover { color: var(--accent); text-decoration: none; }
.post-card-desc { color: var(--ink-soft); margin-bottom: 0.6rem; font-family: var(--serif); }
.post-card-meta { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; font-size: 0.85rem; color: var(--ink-soft); font-family: var(--sans); }

/* --- Post article header (legacy) --- */
#post-body > h1:first-child { margin-bottom: 0.5rem; }
.post-meta { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 1.25rem; font-family: var(--sans); }

/* --- Unlock card --- */
.unlock-wrap { display: flex; justify-content: center; padding-top: 5rem; }
.unlock-card {
  width: 100%;
  max-width: 22rem;
  background: var(--paper-dim);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
}
.unlock-card h1 { font-size: 1.4rem; }
.unlock-card p { color: var(--ink-soft); }
.unlock-error {
  color: var(--bad);
  font-size: 0.85rem;
  background: color-mix(in srgb, var(--bad) 10%, var(--paper));
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
  margin-top: 0.75rem;
  font-family: var(--sans);
}
.unlock-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 1.25rem;
}
.unlock-form input[type="password"] {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 0.6rem 0.75rem;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 0.95rem;
}
.unlock-form input[type="password"]:focus { outline: 1px solid var(--accent); }
.unlock-form button {
  background: var(--accent);
  color: var(--on-accent);
  border: none;
  border-radius: var(--radius);
  padding: 0.65rem 0.75rem;
  font-weight: 600;
  font-family: var(--sans);
  cursor: pointer;
}
.unlock-form button:hover { opacity: 0.9; }

/* ============================================
   Responsive (desktop-first)
   ============================================ */
@media (max-width: 1100px) {
  .article-grid {
    grid-template-columns: minmax(0, 680px);
    max-width: 680px;
    justify-content: center;
  }
  .toc-margin, .margin-col { display: none; }
  .sidenote {
    float: none;
    width: auto;
    margin: 0.8rem 0;
    padding: 0.6rem 0.9rem;
    background: var(--paper-dim);
    border-top: none;
    border-left: 2px solid var(--rule-dark);
    font-family: var(--sans);
    font-size: 0.75rem;
  }
  figure.wide { width: 100%; }
  .section-nav-wrap { display: block; }
}

@media (max-width: 700px) {
  .index-table .tags { display: none; }
  .index-grid { grid-template-columns: 1fr; }
  .fig-row { grid-template-columns: 1fr; }
  .exp-body { grid-template-columns: 1fr; }
  .grid { grid-template-columns: 1fr; }
  .stats { flex-wrap: wrap; }
  .sheet, .masthead { padding-left: 1rem; padding-right: 1rem; }
  .stat-row { grid-template-columns: repeat(2, 1fr); }
  .container { max-width: 100%; padding: 1.5rem 1rem; }
  h1 { font-size: 1.6rem; }
}

@media (prefers-reduced-motion: reduce) {
  .home-sections a, body, .theme-group > summary::before, .post-card, .tab-btn, .section-nav a {
    transition: none;
  }
}
