/*
 * Long-form post layout (pages with "layout": "post"), modelled on the Thinking Machines blog:
 * a sticky table of contents in the left rail, a 660px serif reading column, numbered margin notes in the
 * right rail, and figures that break out to the right. Everything is scoped to body.layout-post and draws its
 * colours from the site's own tokens (styles.css) so posts read as part of clark.saben.org.
 * The TOC and margin-note numbers are generated by /post.js from the article itself, so editing headings or
 * adding notes in the editor updates them automatically.
 */
body.layout-post {
  --p-bg: var(--bg);
  --p-fg: #e4e2dc;          /* reading text, a step brighter than --text for long serif runs */
  --p-fg2: var(--text);
  --p-fg3: var(--dim);
  --p-fg5: #4d4c48;
  --p-rule: var(--rule);
  --p-codebg: var(--panel);
  --p-card: var(--panel);
  --p-accent: var(--accent);
  --p-glue: #b48ead;
  --p-head: var(--draft);
  --p-dense: #6d6c67;
  --p-serif: "Iowan Old Style", "Iowan Old Style BT", "Source Serif 4", Georgia, serif;
  --p-sans: var(--sans);
  --p-mono: var(--mono);
  --toc-width: 192px; --toc-gap: clamp(30px, calc(50vw - 330px - 192px - 32px), 150px); --sn-width: 200px; --sn-gap: 48px; --caption: 13px;
}
.layout-post .post-page { max-width: 1160px; margin: 0 auto; padding: 8px 20px 80px; }
.layout-post .post-heading { max-width: 710px; margin: 2.2rem auto 0; }
.layout-post .post-heading h1 { font: 600 1.875rem/1.4 var(--p-serif); color: var(--heading); margin: 0; text-wrap: balance; }
.layout-post .post-meta { font: 400 15px/1.5 var(--p-sans); color: var(--p-fg3); margin-top: .6rem; display: flex; gap: 14px; flex-wrap: wrap; }
.layout-post .post-meta a { color: var(--p-fg2); }
.layout-post .post-shell { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,660px) minmax(0,1fr); align-items: start; margin-top: 2rem; }
.layout-post .post-toc { grid-column: 1; justify-self: end; position: sticky; top: 2rem; width: var(--toc-width); margin-right: var(--toc-gap);
  max-height: calc(100vh - 3rem); overflow-y: auto; scrollbar-width: none; font: 400 var(--caption)/1.4 var(--p-sans); }
.layout-post .post-toc ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 9px; }
.layout-post .post-toc li.sub { padding-left: 12px; }
.layout-post .post-toc a { color: var(--p-fg3); text-decoration: none; transition: color .2s ease-in-out; }
.layout-post .post-toc a:hover { color: var(--p-fg); text-decoration: underline; text-underline-offset: 2px; }
.layout-post .post-toc a.is-active { color: var(--p-fg); font-weight: 500; }

/* the editable article (main#doc keeps its id/data attributes for the editor) */
.layout-post .post-body { grid-column: 2; min-width: 0; max-width: none; margin: 0; padding: 0;
  font: 17px/1.62 var(--p-serif); color: var(--p-fg); }
.layout-post .post-body h2 { font: 600 1.45rem/1.4 var(--p-serif); color: var(--heading); margin: 3.1rem 0 1.2rem; text-wrap: balance; }
.layout-post .post-body h3 { font: italic 400 1.35rem/1.4 var(--p-serif); color: var(--heading); margin: 2.2rem 0 .8rem; }
.layout-post .post-body p, .layout-post .post-body ul, .layout-post .post-body ol { margin: 0 0 1.45rem; }
.layout-post .post-body ul, .layout-post .post-body ol { padding-left: 1.3rem; }
.layout-post .post-body li { margin-bottom: .45rem; }
.layout-post .post-body a { color: var(--p-fg); text-decoration: underline; text-decoration-color: var(--p-fg5); text-underline-offset: 3px; text-decoration-thickness: 1px; }
.layout-post .post-body a:hover { text-decoration-color: var(--p-accent); color: var(--p-fg); }
.layout-post .post-body strong { color: var(--heading); font-weight: 600; }
.layout-post .post-body code { font: .84em var(--p-mono); background: var(--p-codebg); padding: 1px 4px; border-radius: 3px; }
.layout-post .post-body pre { font: 13.5px/1.55 var(--p-mono); background: var(--p-codebg); border-radius: 6px; padding: 14px 16px; overflow-x: auto; margin: 0 0 .5rem; color: var(--p-fg2); }
.layout-post .post-body pre code { background: none; padding: 0; font-size: 1em; }
.layout-post .post-body .src { font: 400 var(--caption)/1.4 var(--p-sans); color: var(--p-fg3); margin: 0 0 1.45rem; }
.layout-post .post-body .src a { color: var(--p-fg3); }
.layout-post .post-body .eq { font: 14.5px/1.65 var(--p-mono); background: var(--p-codebg); border-radius: 6px; padding: 12px 16px; margin: 0 0 1.45rem; overflow-x: auto; white-space: pre; color: var(--p-fg2); }
.layout-post .post-body blockquote, .layout-post .post-body .aside { margin: 1.6rem 0; padding: 2px 0 2px 18px; border-left: 2px solid var(--p-accent); color: var(--p-fg2); }
.layout-post .post-body hr { border: 0; border-top: 1px solid var(--p-rule); margin: 2.4rem 0; }

/* margin notes: <span class="snref"></span><span class="sn">note</span>; numbers are filled in by post.js */
.layout-post .snref { font: 600 .68em/0 var(--p-sans); vertical-align: super; color: var(--p-accent); margin-left: 1px; }
.layout-post .sn { float: right; clear: right; width: var(--sn-width); margin-right: calc(-1 * var(--sn-width) - var(--sn-gap)); margin-top: .3rem; margin-bottom: 18px;
  font: .9rem/1.4 var(--p-serif); color: var(--p-fg2); }
.layout-post .sn .n { font: 600 .75rem var(--p-sans); color: var(--p-accent); margin-right: 4px; }

/* figures: <figure class="wide"> breaks out to the right rail; SVG charts colour themselves from these tokens */
.layout-post figure { margin: 2rem 0 2.2rem; }
.layout-post figure.wide { clear: both; margin-left: calc(-1 * (var(--sn-width) + var(--sn-gap))); margin-right: calc(-1 * (var(--sn-width) + var(--sn-gap))); }
/* wide figures are centered on the page and overlap the TOC rail; post.js fades the TOC while one is in view */
.layout-post .post-toc { transition: opacity .3s ease; }
.layout-post .post-toc.is-faded { opacity: 0; pointer-events: none; }
.layout-post figure .scroll { overflow-x: auto; }
.layout-post figure svg { display: block; width: 100%; min-width: 600px; height: auto; }
.layout-post figure img { display: block; max-width: 100%; height: auto; border-radius: 4px; }
.layout-post figcaption, .layout-post .cover p { margin-top: 13px; font: 400 var(--caption)/1.4 var(--p-sans); color: var(--p-fg3); }
.layout-post svg text { font-family: var(--p-sans); }
.layout-post .fcap { font-size: 15px; fill: var(--p-fg); } .layout-post .flab { font-size: 14px; font-weight: 600; fill: var(--p-fg); }
.layout-post .flab-in { font-size: 14px; font-weight: 600; fill: var(--p-bg); } .layout-post .fnote { font-size: 12.5px; fill: var(--p-fg3); }
.layout-post .fnum { font-size: 12px; font-weight: 600; fill: var(--p-fg); font-variant-numeric: tabular-nums; }
.layout-post .b-pre { fill: var(--p-dense); } .layout-post .b-core { fill: var(--p-accent); } .layout-post .b-core2 { fill: var(--p-accent); fill-opacity: .55; } .layout-post .b-post { fill: var(--p-head); }
.layout-post .b-pre + text, .layout-post .b-core + text, .layout-post .b-core2 + text, .layout-post .b-post + text { fill: var(--p-bg); }
.layout-post .tick { stroke: var(--p-bg); stroke-width: 1; opacity: .7; } .layout-post .arc { fill: none; stroke: var(--p-fg3); stroke-width: 1.4; stroke-dasharray: 4 4; }
.layout-post .s-exp { fill: var(--p-accent); } .layout-post .s-glue { fill: var(--p-glue); } .layout-post .s-head { fill: var(--p-head); } .layout-post .s-dense { fill: var(--p-dense); }
.layout-post .grid { stroke: var(--p-rule); stroke-width: 1; } .layout-post .floor { stroke: var(--p-fg); stroke-width: 1.5; stroke-dasharray: 6 4; } .layout-post .goal { stroke: var(--p-head); stroke-width: 1.5; stroke-dasharray: 2 4; }
.layout-post figure.cover { max-width: none; margin: 0 -120px 2rem; } /* 900px, centered on the text column */

/* tables */
.layout-post .tbl { overflow-x: auto; margin: .4rem 0 1.6rem; }
.layout-post .post-body table { border-collapse: collapse; width: 100%; font: 400 14px/1.45 var(--p-sans); font-variant-numeric: tabular-nums; }
.layout-post .post-body th { font-weight: 600; text-align: left; border-bottom: 1px solid var(--p-fg2); padding: 7px 12px 7px 0; color: var(--heading); }
.layout-post .post-body td { border-bottom: 1px solid var(--p-rule); padding: 8px 12px 8px 0; vertical-align: top; color: var(--p-fg2); }
.layout-post .post-body .r { text-align: right; }
.layout-post .post-body tr.hl td { color: var(--heading); font-weight: 600; background: var(--p-codebg); }
.layout-post .post-body tr.tot td { font-weight: 600; color: var(--heading); border-top: 1px solid var(--p-fg2); }
.layout-post .post-body .np { color: var(--p-fg3); font-style: italic; }

/* summary numbers, dev log, reproduce box, references */
.layout-post .kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 16px 22px; margin: 0 0 2rem; padding: 14px 0; border-top: 1px solid var(--p-fg2); border-bottom: 1px solid var(--p-rule); }
.layout-post .kv > div { min-width: 0; } .layout-post .kv .v { font: 600 1.5rem/1.2 var(--p-sans); color: var(--heading); font-variant-numeric: tabular-nums; }
.layout-post .kv .l { font: 400 var(--caption)/1.35 var(--p-sans); color: var(--p-fg3); margin-top: 4px; }
.layout-post .status { font: 500 11px var(--p-sans); letter-spacing: .1em; text-transform: uppercase; color: var(--p-head); font-style: normal; margin-left: 6px; }
.layout-post .log { list-style: none; padding: 0; margin: 0 0 2rem; border-left: 1px solid var(--p-rule); }
.layout-post .log li { position: relative; padding: 0 0 1.1rem 20px; margin: 0; }
.layout-post .log li::before { content: ""; position: absolute; left: -4px; top: .55em; width: 7px; height: 7px; border-radius: 50%; background: var(--p-fg5); }
.layout-post .log li.now::before { background: var(--p-head); }
.layout-post .log .when { font: 500 12.5px var(--p-sans); color: var(--p-fg3); display: block; }
.layout-post .repro { border: 1px solid var(--p-rule); border-radius: 8px; padding: 18px 18px 6px; margin: 0 0 1.8rem; background: var(--p-card); }
.layout-post .repro h4 { font: 600 15px/1.3 var(--p-sans); margin: 0 0 6px; color: var(--heading); }
.layout-post .prompt { position: relative; } .layout-post .prompt pre { white-space: pre-wrap; padding-right: 74px; }
.layout-post .copy { position: absolute; top: 8px; right: 8px; font: 500 12px var(--p-sans); color: var(--p-fg); background: var(--p-bg); border: 1px solid var(--p-rule); border-radius: 5px; padding: 5px 10px; cursor: pointer; }
.layout-post .copy:hover { border-color: var(--p-accent); }
.layout-post ul.refs { font-size: .95rem; } .layout-post ul.refs li { overflow-wrap: anywhere; }
.layout-post .codemap td:first-child { font-family: var(--p-mono); font-size: 12.5px; white-space: nowrap; }
.layout-post .bib pre { font-size: 12.5px; }
.layout-post .post-foot { max-width: 660px; margin: 4rem auto 0; padding-top: 16px; border-top: 1px solid var(--p-rule); font: 400 var(--caption)/1.5 var(--p-sans); color: var(--p-fg3); }

/* editing affordances (editor only): make the generated/meta parts visibly non-editable */
.layout-post [contenteditable="true"] .sn { outline: 1px dashed var(--p-fg5); outline-offset: 3px; }

@media (max-width: 1179px) {
  .layout-post .post-shell { display: block; max-width: 660px; margin: 2rem auto 0; }
  .layout-post .post-toc { display: none; }
  .layout-post .sn { float: none; display: block; width: auto; margin: 0 0 1.2rem; padding-left: 14px; border-left: 2px solid var(--p-rule); }
  .layout-post figure.wide, .layout-post figure.cover, .layout-post figure.wide.demo-video { margin-left: 0; margin-right: 0; }
}
@media (max-width: 560px) { .layout-post .post-body { font-size: 16.5px; } .layout-post .post-heading h1 { font-size: 1.6rem; } }
@media (prefers-reduced-motion: reduce) { .layout-post .post-toc a, .layout-post .post-toc { transition: none; } }

/* the post toolbar row stacks under the editor's main toolbar (both are sticky) */
.layout-post .toolbar.post-tools { top: 45px; z-index: 24; border-top: 0; padding-top: 6px; padding-bottom: 6px; }
.layout-post .toolbar .tb-label { font: 600 11px var(--p-sans); letter-spacing: .1em; text-transform: uppercase; color: var(--p-fg3); margin-right: 6px; }

.layout-post .post-meta-links { display: inline-flex; gap: 8px; align-items: baseline; }
.layout-post .post-meta-links a { color: var(--p-fg2); text-decoration: underline; text-decoration-color: var(--p-fg5); text-underline-offset: 3px; }
.layout-post .post-meta-links a:hover { color: var(--p-accent); }
.layout-post .post-meta-sep { color: var(--p-fg5); }

/* light theme (sun/moon toggle) */
html[data-theme="light"] body.layout-post { --p-fg: #1c1c1c; --p-fg5: #cccccc; --p-dense: #a8a8a8; --p-glue: #8e6a89; }

/* demo video figure */
.layout-post figure.wide.demo-video { margin-left: -120px; margin-right: -120px; } /* centered like the cover; the TOC stays visible beside it */
.layout-post figure.demo-video video { display: block; width: 100%; height: auto; border-radius: 6px; background: #000; }

/* artifact embed (tabs: play / video); the iframe is created on click by post.js */
.layout-post .artifact { margin: 2rem -120px 2.2rem; }
.layout-post .artifact-tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.layout-post .artifact-tabs button { font: 500 13px var(--p-sans); color: var(--p-fg3); background: transparent; border: 1px solid var(--p-rule); border-radius: 999px; padding: 5px 14px; cursor: pointer; }
.layout-post .artifact-tabs button.on { color: var(--p-fg); border-color: var(--p-fg3); background: var(--p-rule); }
.layout-post .artifact-stage, .layout-post .artifact-video { aspect-ratio: 16 / 9; border-radius: 8px; overflow: hidden; background: #0b1520; }
.layout-post .artifact[data-show="play"] .artifact-video, .layout-post .artifact[data-show="video"] .artifact-stage { display: none; }
.layout-post .artifact-video video { display: block; width: 100%; height: 100%; object-fit: contain; background: #000; }
.layout-post .artifact-stage iframe { display: block; width: 100%; height: 100%; border: 0; }
.layout-post .artifact-cover { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; text-align: center; padding: 0 24px;
  background: radial-gradient(ellipse at 50% 40%, #2a4a66 0%, #0b1520 70%); }
.layout-post .artifact-cover p { margin: 0; color: #b9c6d2; font: 400 14px/1.5 var(--p-sans); max-width: 460px; }
.layout-post .artifact-play { font: 600 15px var(--p-sans); color: #0b1520; background: #e8eef3; border: 0; border-radius: 999px; padding: 11px 22px; cursor: pointer; }
.layout-post .artifact-play:hover { background: #fff; }
.layout-post .artifact figcaption { margin-top: 12px; }
@media (max-width: 1179px) { .layout-post .artifact { margin-left: 0; margin-right: 0; } }
.layout-post .artifact-caption { margin: 12px 0 0; font: 400 var(--caption)/1.4 var(--p-sans); color: var(--p-fg3); }
