/* Graph-paper page, sticky navigation rail on wide screens, one reading column */
:root {
  --bg: #f3f5f1;
  --surface: #ffffff;
  --fg: #1c2320;
  --muted: #5a6560;
  --rule: #d5dcd5;
  --grid: rgba(42, 127, 98, 0.07);
  --accent: #b02f63;
  --accent-2: #24795c;
  --code-bg: #e8ece6;
  --display: "Unbounded", "Arial Black", system-ui, sans-serif;
  --body: "PT Serif", Georgia, "Times New Roman", serif;
  --mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111513; --surface: #181d1a; --fg: #e3e8e4; --muted: #9aa69f; --rule: #2c3530;
    --grid: rgba(92, 197, 155, 0.06); --accent: #ef6c9f; --accent-2: #5cc59b; --code-bg: #1f2622;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111513; --surface: #181d1a; --fg: #e3e8e4; --muted: #9aa69f; --rule: #2c3530;
  --grid: rgba(92, 197, 155, 0.06); --accent: #ef6c9f; --accent-2: #5cc59b; --code-bg: #1f2622;
  color-scheme: dark;
}

* { 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-color: var(--bg);
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 24px 24px;
  color: var(--fg);
  font: 17px/1.62 var(--body);
  padding: 32px max(16px, env(safe-area-inset-right, 0px)) 80px max(16px, env(safe-area-inset-left, 0px));
}
a { color: var(--accent); text-underline-offset: 2px; }
a:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.skip { position: absolute; left: -9999px; }
.skip:focus { left: 16px; top: 8px; background: var(--surface); padding: 6px 10px; z-index: 10; }

.page { max-width: 1180px; margin: 0 auto; display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 56px; }

/* ---------- rail ---------- */
.rail { position: sticky; top: 24px; align-self: start; max-height: calc(100vh - 48px); overflow-y: auto; font: 13px/1.5 var(--mono); scrollbar-width: thin; }
.brand { display: inline-flex; align-items: baseline; gap: 8px; font: 700 20px/1 var(--display); color: var(--fg); text-decoration: none; letter-spacing: -0.01em; }
.brand span { font: 600 11px/1 var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--accent-2); }
.menu-btn { display: none; }
.grp { font: 600 11px/1 var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin: 28px 0 12px; }
.sitenav ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; border-left: 1px solid var(--rule); }
.sitenav a { display: block; padding: 2px 0 2px 14px; margin-left: -1px; border-left: 1px solid transparent; color: var(--muted); text-decoration: none; }
.sitenav a:hover { color: var(--accent); }
.sitenav li.current > a { color: var(--fg); font-weight: 600; border-left-color: var(--accent); }
.sitenav ol.toc { border-left: 0; margin: 4px 0 8px 14px; gap: 2px; font-size: 12px; }
.sitenav ol.toc:empty { display: none; }
.sitenav ol.toc a { padding-left: 10px; border-left: 1px solid var(--rule); }
.sitenav ol.toc a.active { color: var(--accent); border-left-color: var(--accent); }
.rail-foot { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 28px; padding-top: 16px; border-top: 1px solid var(--rule); }
.rail-foot a, .theme-btn { display: inline; padding: 0; margin: 0; border: 0; color: var(--muted); text-decoration: none; font: inherit; }
.rail-foot a:hover, .theme-btn:hover { color: var(--accent); }
.theme-btn { background: none; border: 0; padding: 0; cursor: pointer; }

@media (max-width: 960px) {
  body { padding-top: 16px; }
  .page { grid-template-columns: minmax(0, 1fr); gap: 24px; }
  .rail { position: static; max-height: none; overflow: visible; border-bottom: 1px solid var(--rule); padding-bottom: 14px; }
  .rail-top { display: flex; align-items: center; justify-content: space-between; }
  .menu-btn { display: inline-block; font: 600 12px/1 var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--fg); background: var(--surface); border: 1px solid var(--rule); border-radius: 3px; padding: 9px 12px; cursor: pointer; }
  .menu-btn[aria-expanded="true"] { border-color: var(--accent); color: var(--accent); }
  .js .sitenav { display: none; }
  .js .sitenav.open { display: block; }
  .sitenav ol.toc { display: none; }
}

/* ---------- main column ---------- */
main { min-width: 0; max-width: 760px; }
.hero { padding-bottom: 28px; border-bottom: 1px solid var(--rule); margin-bottom: 8px; }
.eyebrow { font: 600 12px/1 var(--mono); letter-spacing: .14em; text-transform: uppercase; color: var(--accent-2); margin: 0 0 18px; }
h1 { font: 700 clamp(30px, 5vw, 48px)/1.08 var(--display); letter-spacing: -0.01em; margin: 0 0 18px; text-wrap: balance; overflow-wrap: anywhere; }
h1 em { font-style: normal; color: var(--accent); }
.lede { font-size: 19px; color: var(--muted); margin: 0; max-width: 62ch; }
.hero-media { margin: 28px 0 0; }
.hero-media video { display: block; width: 100%; height: auto; aspect-ratio: 16 / 9; border-radius: 4px; border: 1px solid var(--rule); background: var(--code-bg); }

.content > :first-child { margin-top: 32px; }
.content h2 { font: 700 26px/1.2 var(--display); margin: 48px 0 14px; padding-top: 36px; border-top: 1px solid var(--rule); text-wrap: balance; }
.content > h2:first-child { border-top: 0; padding-top: 0; }
.content h3 { font: 600 13px/1.3 var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin: 32px 0 12px; }
.content h3 code { text-transform: none; letter-spacing: 0; }
.content h2, .content h3 { position: relative; }
.anchor { position: absolute; left: -1.1em; padding-right: .3em; color: var(--rule); text-decoration: none; opacity: 0; transition: opacity .15s; }
h2:hover .anchor, h3:hover .anchor, .anchor:focus { opacity: 1; }
.anchor:hover { color: var(--accent); }
.content p { margin: 0 0 14px; max-width: 66ch; }
.content ul, .content ol { margin: 0 0 16px; padding-left: 1.4em; max-width: 66ch; }
.content li { margin-bottom: 4px; }
.content li::marker { color: var(--muted); font-family: var(--mono); font-size: .85em; }
.content strong { font-weight: 700; }

code { font-family: var(--mono); font-size: .86em; background: var(--code-bg); padding: 1px 5px; border-radius: 3px; overflow-wrap: anywhere; }
pre { margin: 0; padding: 14px 16px; overflow-x: auto; font: 13.5px/1.55 var(--mono); }
pre code { background: none; padding: 0; font-size: inherit; overflow-wrap: normal; }
.highlighter-rouge { position: relative; margin: 0 0 16px; background: var(--code-bg); border: 1px solid var(--rule); border-radius: 4px; }
p > .highlighter-rouge, li > .highlighter-rouge, td > .highlighter-rouge { display: inline; margin: 0; border: 0; background: none; }
.highlight { margin: 0; }
.copy { position: absolute; top: 8px; right: 8px; font: 600 11px/1 var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); background: var(--surface); border: 1px solid var(--rule); border-radius: 3px; padding: 6px 8px; cursor: pointer; opacity: 0; transition: opacity .15s; }
.highlighter-rouge:hover .copy, .copy:focus-visible { opacity: 1; }
.copy:hover { color: var(--accent); border-color: var(--accent); }
@media (hover: none) { .copy { opacity: 1; } }

/* Rouge tokens: two accents only, the rest stays body color */
.highlight .c, .highlight .c1, .highlight .cm, .highlight .cs, .highlight .cp { color: var(--muted); }
.highlight .k, .highlight .kd, .highlight .kn, .highlight .kr, .highlight .kt, .highlight .kc, .highlight .na, .highlight .nt, .highlight .nd { color: var(--accent-2); }
.highlight .s, .highlight .s1, .highlight .s2, .highlight .sb, .highlight .sc, .highlight .se, .highlight .si, .highlight .sr { color: var(--accent); }
.highlight .err { color: inherit; background: none; }

blockquote { margin: 0 0 16px; border: 1px solid var(--accent); background: var(--surface); padding: 14px 18px; border-radius: 4px; }
blockquote p { margin: 0 0 8px; }
blockquote > :last-child { margin-bottom: 0; }

.tablewrap { overflow-x: auto; margin: 0 0 16px; border: 1px solid var(--rule); border-radius: 4px; background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: 15px; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--rule); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
th { font: 600 11px/1.3 var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); background: var(--code-bg); }
td:first-child { font-size: 14px; }
td:first-child code { color: var(--accent-2); background: none; padding: 0; font-size: 13.5px; }
td code { overflow-wrap: normal; }

figure { margin: 4px 0 22px; }
img { max-width: 100%; height: auto; }

/* ---------- footer ---------- */
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 56px; padding-top: 28px; border-top: 1px solid var(--rule); }
.pager a { display: block; padding: 14px 16px; border: 1px solid var(--rule); border-radius: 4px; background: var(--surface); text-decoration: none; color: var(--fg); font: 600 15px/1.3 var(--display); }
.pager a:hover { border-color: var(--accent); color: var(--accent); }
.pager a span { display: block; font: 600 11px/1 var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }
.pager .next { grid-column: 2; text-align: right; }
.edit { margin: 20px 0 0; font: 12px/1.4 var(--mono); }
.edit a { color: var(--muted); }
.edit a:hover { color: var(--accent); }
@media (max-width: 560px) {
  table { min-width: 600px; }
  .pager { grid-template-columns: minmax(0, 1fr); }
  .pager .next { grid-column: 1; }
}
