/* Shared stylesheet for every post published with blogkit. Copied into each post folder. */
:root {
  --bg: #fff; --surface: #f5f5f3; --text: #1f1e1c; --muted: #6d6b65; --rule: #e5e5e2;
  --accent: #b4532a; --code-bg: #f5f5f3;
  --fail: #9b2c1f; --fail-bg: #fbe4df;
  --serif: Charter, "Bitstream Charter", "Sitka Text", Cambria, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --measure: 43rem;
  /* Chart series colours, in fixed order; 0 is the neutral used when a row is not a series. */
  --series-0: #6d6b65; --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #1a1917; --surface: #252421; --text: #eceae4; --muted: #a3a099; --rule: #3a3833;
          --accent: #e08a62; --code-bg: #252421;
          --fail: #f2a99a; --fail-bg: #43231d;
          --series-0: #a3a099; --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body { margin: 0; background: var(--bg); color: var(--text); font: 18px/1.7 var(--serif); }
a { color: inherit; text-decoration: underline; text-decoration-color: var(--accent);
    text-decoration-thickness: 1px; text-underline-offset: .18em; }
a:hover { color: var(--accent); }

/* Post header */
.post-head { max-width: calc(var(--measure) + 2.5rem); margin: 0 auto; padding: 4.5rem 1.25rem 2.5rem; }
h1 { font: 600 clamp(2rem, 5vw, 2.9rem)/1.12 var(--sans); letter-spacing: -.025em; margin: 0; text-wrap: balance; }
.meta { font: 14px/1.5 var(--sans); color: var(--muted); margin: 1.8rem 0 0; padding-top: 1.1rem;
        border-top: 1px solid var(--rule); display: flex; flex-wrap: wrap; gap: .2rem 0; }
.meta > * + *::before { content: "·"; margin: 0 .6em; }

/* Body: one reading column, with the contents list beside it on wide screens */
.layout { display: grid; grid-template-columns: minmax(0, 1fr); padding: 0 1.25rem 6rem; }
.prose, #TOC { width: 100%; max-width: var(--measure); margin: 0 auto; }
#TOC { font: 14px/1.45 var(--sans); background: var(--surface); border-radius: 8px;
       padding: 1rem 1.2rem; margin-bottom: 2rem; }
#TOC .toc-title { font-weight: 600; margin: 0 0 .5rem; padding-left: .8rem; }
#TOC ul { list-style: none; margin: 0; padding: 0; }
#TOC ul ul { padding-left: 1rem; }
#TOC li { margin: .35rem 0; }
#TOC a { display: block; text-decoration: none; color: var(--muted); padding-left: .8rem; border-left: 2px solid transparent; }
#TOC a:hover { color: var(--text); }
#TOC a.active { color: var(--text); border-left-color: var(--accent); }
@media (min-width: 1180px) {
  .layout { grid-template-columns: 1fr minmax(0, var(--measure)) 1fr; column-gap: 2.5rem; }
  #TOC { grid-column: 1; justify-self: end; align-self: start; position: sticky; top: 2rem;
         max-width: 14rem; max-height: calc(100vh - 4rem); overflow-y: auto;
         background: none; padding: .3rem 0 0; margin: 0; }
  .prose { grid-column: 2; }
}

/* Prose */
.prose > :first-child { margin-top: 0; }
.prose h2, .prose h3, .prose h4 { font-family: var(--sans); letter-spacing: -.015em; line-height: 1.25; scroll-margin-top: 1.5rem; }
.prose h2 { font-size: 1.6rem; font-weight: 600; margin: 3.2rem 0 1rem; }
.prose h3 { font-size: 1.2rem; font-weight: 600; margin: 2.3rem 0 .7rem; }
.prose h4 { font-size: 1rem; font-weight: 600; margin: 1.8rem 0 .5rem; }
.prose p, .prose ul, .prose ol { margin: 0 0 1.25rem; }
.prose li { margin: .35rem 0; }
.prose hr { border: 0; border-top: 1px solid var(--rule); margin: 3rem 0; }
.prose blockquote { margin: 1.6rem 0; padding: .1rem 0 .1rem 1.2rem; border-left: 3px solid var(--accent); font-size: 1.08rem; }
.prose blockquote p:last-child { margin-bottom: 0; }

/* Figures: write ![caption](figures/x.png); add {.wide} to let one extend past the text column */
figure { margin: 2.2rem 0; }
figure img, .prose > p > img { display: block; max-width: 100%; height: auto; margin: 0 auto; border-radius: 6px; background: #fff; }
figure a { display: block; }
figcaption { font: 14px/1.5 var(--sans); color: var(--muted); margin-top: .8rem; text-wrap: pretty; }
@media (min-width: 900px) {
  figure:has(img.wide) { width: min(60rem, 100vw - 2.5rem); margin-left: 50%; transform: translateX(-50%); }
  figure:has(img.wide) figcaption { max-width: var(--measure); margin-left: auto; margin-right: auto; }
}

/* Interactive charts: a fenced div, "::: {.chart spec="data/x.json"}" ... ":::"; drawn by chart.js */
figure.chart { font-family: var(--sans); }
.chart-plot { min-height: 3rem; }
.chart-plot svg { display: block; overflow: visible; touch-action: pan-y; }
.chart-plot text { font: 12px var(--sans); fill: var(--muted); }
.chart-plot text.chart-label { font-size: 13px; fill: var(--text); }
.chart-plot text.chart-group { font-weight: 600; fill: var(--text); }
.chart-axis-label { font: 12px/1.4 var(--sans); color: var(--muted); fill: var(--muted); text-align: center; margin-top: .2rem; text-wrap: balance; }
.chart-grid { stroke: var(--rule); stroke-width: 1; }
.chart-ref { stroke: var(--muted); stroke-width: 1; }
.chart-band { fill: var(--surface); }
.chart-span { stroke: var(--rule); stroke-width: 2; }
.chart-median { stroke: var(--text); stroke-width: 2; stroke-linecap: round; }
.chart-cursor { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.chart-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-line.dashed { stroke-width: 1.5; stroke-dasharray: 5 4; }
.chart-trace { fill: none; stroke-width: 1; stroke-opacity: .2; stroke-linejoin: round; }
.chart-bar { stroke: none; }
.chart-plot text.chart-bar-value { font-size: 12px; fill: #fff; font-weight: 600; }
.chart-plot text.chart-bar-value.light { fill: var(--text); font-weight: 500; }
.chart-parts { margin-bottom: 6px; }
.chart-parts span { display: inline-flex; align-items: center; gap: 6px; margin-right: 14px; font-size: 13px; }
.chart-dot { stroke: var(--bg); stroke-width: 1.5; fill-opacity: .9; transition: opacity .12s; }
.chart-dot.faded { fill-opacity: .1; stroke: currentColor; stroke-opacity: .6; stroke-width: 1.2; }
.has-focus .chart-dot { opacity: .22; }
.has-focus .chart-dot.on { opacity: 1; fill-opacity: 1; stroke: var(--text); stroke-opacity: 1; stroke-width: 2; }
.chart-ghost { opacity: .2; }
.chart-trail { stroke-width: 1.5; opacity: .55; }
.chart-head { stroke: var(--bg); stroke-width: 2.5; }
.chart-frame { fill: var(--surface); stroke: none; }
.chart-plot text.chart-halo { paint-order: stroke; stroke: var(--surface); stroke-width: 4px; stroke-linejoin: round; font-weight: 600; }
.chart-step { font: 13px/1.4 var(--sans); color: var(--muted); margin: 1.5rem 0 .6rem; padding-top: .9rem; border-top: 1px solid var(--rule); }
.chart-step:first-child { margin-top: 0; padding-top: 0; border-top: 0; }
.chart-step strong { color: var(--text); font-size: 15px; margin-right: .35em; }
.chart-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(6rem, 1fr)); gap: .6rem; }
.chart-stat { background: var(--surface); border-radius: 8px; padding: .7rem .9rem; }
.chart-stat-label { display: flex; align-items: center; gap: .45em; font: 13px/1.3 var(--sans); color: var(--muted); }
.chart-stat-value { font: 600 1.9rem/1.2 var(--sans); letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.chart-controls { display: flex; align-items: center; gap: .8rem; flex-wrap: wrap; margin-bottom: .7rem; font: 13px/1 var(--sans); color: var(--muted); }
.chart-controls button { font: 600 13px/1 var(--sans); color: var(--bg); background: var(--text); border: 0; border-radius: 999px; padding: .55em 1em; cursor: pointer; min-width: 5.2em; }
.chart-controls input { flex: 1 1 8rem; accent-color: var(--accent); }
.chart-controls span { font-variant-numeric: tabular-nums; min-width: 9.5em; }
.chart-perf .chart-dot:not(.chart-head) { stroke: var(--muted); stroke-width: .6; }
.chart-perf .chart-trail { stroke: var(--muted) !important; opacity: .28; }
.chart-modes { margin: 0; flex-basis: 100%; }
.chart-controls .chart-modes button { min-width: 0; font-weight: 400; color: var(--text); background: none; border: 1px solid var(--rule); }
.chart-controls .chart-modes button[aria-pressed="true"] { border-color: var(--text); font-weight: 600; }
.chart-controls .chart-modes button[aria-pressed="false"] { text-decoration: none; color: var(--muted); }
.chart-ramp { display: flex; align-items: center; justify-content: center; gap: .6rem; font: 12px/1.4 var(--sans); color: var(--muted); margin-top: .4rem; }
.chart-ramp[hidden] { display: none; }
.chart-ramp i { width: 9rem; height: .6rem; border-radius: 999px; }
.chart-hit { fill: transparent; }
.chart-hit:hover { fill: var(--text); fill-opacity: .05; }
.chart-legend { display: flex; flex-wrap: wrap; gap: .3rem .5rem; margin-bottom: .7rem; }
.chart-legend button { display: inline-flex; align-items: center; gap: .45em; font: 13px/1 var(--sans); color: var(--text);
                       background: none; border: 1px solid var(--rule); border-radius: 999px; padding: .4em .8em; cursor: pointer; }
.chart-legend button[aria-pressed="false"] { color: var(--muted); text-decoration: line-through; }
.chart-legend button[aria-pressed="false"] .chart-tip-key { opacity: .25; }
.chart-tip-key { display: inline-block; width: .7em; height: .7em; border-radius: 50%; flex: none; }
.chart-tip { position: fixed; z-index: 10; pointer-events: none; max-width: 20rem; background: var(--bg); color: var(--text);
             border: 1px solid var(--rule); border-radius: 8px; padding: .55rem .7rem; font: 13px/1.45 var(--sans);
             box-shadow: 0 4px 16px rgb(0 0 0 / .14); }
.chart-tip-title { font-weight: 600; margin-bottom: .25rem; }
.chart-tip-row { display: flex; align-items: baseline; gap: .45em; flex-wrap: wrap; }
.chart-tip-row .chart-tip-key { align-self: center; }
.chart-tip-label { color: var(--muted); }
.chart-tip-note { color: var(--muted); font-size: 12px; }
.chart-table { margin-top: .6rem; font: 13px/1.45 var(--sans); color: var(--muted); }
.chart-table summary { cursor: pointer; width: fit-content; }
.chart-table .table-wrap { max-height: 22rem; overflow: auto; margin: .6rem 0; }
.chart-table table { font-size: 13px; color: var(--text); }
.chart-table tbody th { font-weight: 400; }
@media (min-width: 900px) {
  figure.chart.wide { width: min(60rem, 100vw - 2.5rem); margin-left: 50%; transform: translateX(-50%); }
  figure.chart.wide figcaption, figure.chart.wide .chart-table { max-width: var(--measure); margin-left: auto; margin-right: auto; }
}

/* Tables scroll inside their own box on narrow screens */
.table-wrap { overflow-x: auto; margin: 1.8rem 0; }
table { border-collapse: collapse; width: 100%; font: 14px/1.45 var(--sans); font-variant-numeric: tabular-nums; }
/* A row whose first cell is only italic text and whose other cells are empty is a group header. */
tr:has(> td:first-child > em:only-child):not(:has(> td:not(:first-child):not(:empty))) > td { background: var(--surface); }
th, td { padding: .55rem .7rem; vertical-align: top; border-bottom: 1px solid var(--rule); text-align: left; }
/* [value]{.fail} marks a result that did not pass, e.g. a table cell; the tinted box keeps it
   distinguishable without relying on colour alone. */
.fail { color: var(--fail); background: var(--fail-bg); padding: .05em .4em; border-radius: 3px; white-space: nowrap; }
th { font-weight: 600; border-bottom-color: var(--text); }
th:first-child, td:first-child { padding-left: 0; }
th:last-child, td:last-child { padding-right: 0; }
caption { caption-side: bottom; color: var(--muted); padding-top: .7rem; text-align: left; }

/* Code */
code { font: .86em var(--mono); background: var(--code-bg); padding: .12em .35em; border-radius: 4px; }
pre { background: var(--code-bg); padding: 1rem 1.2rem; border-radius: 8px; overflow-x: auto; font-size: 14px; line-height: 1.55; margin: 1.6rem 0; }
pre code { background: none; padding: 0; font-size: inherit; }

/* Callouts: a fenced div, "::: note" ... ":::" */
.note { background: var(--surface); border-radius: 8px; padding: 1rem 1.2rem; margin: 1.8rem 0; font: 16px/1.6 var(--sans); }
.note > :last-child { margin-bottom: 0; }

/* Footnotes */
.footnotes { font-size: .88rem; color: var(--muted); margin-top: 3.5rem; }
.footnotes hr { margin: 0 0 1.5rem; }
sup { line-height: 0; }

@media (max-width: 600px) {
  body { font-size: 17px; }
  .post-head { padding-top: 2.8rem; }
}
@media print {
  #TOC { display: none; }
  body { background: #fff; font-size: 11pt; }
}
