/* Prior-Informed Flow Matching: the page's shared styles.
   Hand-written; no framework, no build step. A reading column of 680 px, centred below 1240 px;
   from 1240 px up the contents menu takes a column at its left and the pair is centred instead.
   Figures of class "wide" run to 940 px from 1000 px up: centred on the column below 1240 px,
   left-aligned with it (extending right only) from 1240 px up. One sans family from the
   system stack, one text colour and one muted colour, thin rules, no motion.

   Every colour is a custom property. Light values on bare :root; dark values under
   prefers-color-scheme (unless data-theme="light" is set on <html>) and again under
   data-theme="dark". Figures never write a literal colour: they use these tokens
   through PIFM.color / PIFM.mix (assets/kit.js) or the classes at the end of this file.

   Colour meaning, the same in every figure:
     --c-ink         an observed edge, and the truth
     --c-masked      a masked pair that is truly an edge (strong red)
     --c-masked-non  a masked pair that is truly a non-edge (pale red)
     --c-prior       anything the prior produced (blue)
     --c-flow        anything the flow produced (green)
     --c-ref         reference marks and baselines (grey)
     --c-empty       an empty matrix cell, and the zero end of every fill scale
     --c-grid        gridlines;  --c-axis  axis lines and ticks
     --c-hatch       the lines of the hatch (PIFM.hatch): a masked pair, unknown; an invalid outcome
   Prior, masked and flow were checked with the dataviz validator (all pairs, both themes):
   light  prior #2456bd L 0.48 6.7:1 | masked #c4392f L 0.55 5.3:1 | flow #33a362 L 0.64 3.2:1
          worst colour-blind pair flow/masked dE 8.5 (deutan; tritan worst 14.9), normal-vision floor 29.5
   dark   masked #d33b38 L 0.58 3.9:1 | prior #4a7fe0 L 0.61 4.7:1 | flow #46b475 L 0.69 7.0:1
          worst colour-blind pair flow/masked dE 10.8 (deutan; tritan worst prior/flow 8.8), normal-vision floor 25.1
   (L is OKLCH lightness; ratios are WCAG contrast on --bg; dE is OKLab x100, Machado 2009 simulation.)
   The three also differ in lightness in both themes (in dark, red and blue only by 0.03).
   The masked-pair marks, measured 2026-11-30 (F3), each against what it must stand apart from:
   light  pale red #efb9b3 on --c-empty 1.45:1 (dE 12.8) | strong/pale 3.1:1 (protan dE 34.9)
          hatch line #7d7e85 on --c-empty 3.4:1; a hatched cell (1.4 px lines every 4 px) vs an empty one 1.33:1
   dark   pale red #883136 on --c-empty 1.82:1 (dE 20.9) | strong/pale 1.75:1 (dE 15.7, protan 10.7)
          hatch line #9d9ea6 on --c-empty 5.7:1; a hatched cell vs an empty one 2.64:1
   Colour is still never the only signal: dashes, hatching and labels go with it. */

:root {
  --bg: #ffffff;
  --fg: #1a1b1e;          /* 17:1 on --bg */
  --muted: #64656c;       /* 5.6:1 on --bg: captions, labels, keys */
  --rule: #dcdce1;        /* hairlines */
  --focus: #2456bd;       /* focus ring */
  --control-bg: #ffffff;
  --control-on: #1a1b1e;  /* a chosen segment: --control-on ground, --bg text */
  --on-accent: #ffffff;   /* text on a --c-prior ground (selected text) */

  --c-ink: #1a1b1e;
  --c-masked: #c4392f;
  --c-masked-non: #efb9b3;
  --c-prior: #2456bd;
  --c-flow: #33a362;
  --c-ref: #8e8f96;       /* 3.2:1 on --bg */
  --c-empty: #ececef;
  --c-grid: #e6e6ea;
  --c-axis: #a4a5ac;
  --c-hatch: #7d7e85;     /* hatch lines of a masked pair, unknown: 3.4:1 on --c-empty */

  --sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --col: 680px;
  --wide: 940px;
  --radius: 4px;
  --fig-text: 13.5px;     /* SVG labels */
  --fig-text-sm: 11.5px;  /* SVG small labels: ticks, cell numbers */
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141518;
    --fg: #e8e9ec;
    --muted: #9d9ea6;
    --rule: #2c2d33;
    --focus: #7aa2f0;
    --control-bg: #141518;
    --control-on: #e8e9ec;
    --on-accent: #ffffff;
    --c-ink: #e8e9ec;
    --c-masked: #d33b38;
    --c-masked-non: #883136;
    --c-prior: #4a7fe0;
    --c-flow: #46b475;
    --c-ref: #74757d;
    --c-empty: #25262c;
    --c-grid: #26272d;
    --c-axis: #55565e;
    --c-hatch: #9d9ea6;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141518;
  --fg: #e8e9ec;
  --muted: #9d9ea6;
  --rule: #2c2d33;
  --focus: #7aa2f0;
  --control-bg: #141518;
  --control-on: #e8e9ec;
  --on-accent: #ffffff;
  --c-ink: #e8e9ec;
  --c-masked: #d33b38;
  --c-masked-non: #883136;
  --c-prior: #4a7fe0;
  --c-flow: #46b475;
  --c-ref: #74757d;
  --c-empty: #25262c;
  --c-grid: #26272d;
  --c-axis: #55565e;
  --c-hatch: #9d9ea6;
  color-scheme: dark;
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 18px/1.6 var(--sans); -webkit-font-smoothing: antialiased; overflow-wrap: break-word; }
@media (max-width: 600px) { body { font-size: 16px; } }

.page { max-width: calc(var(--col) + 2 * 16px); margin-inline: auto; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
a { color: inherit; text-decoration-color: var(--muted); text-underline-offset: 3px; }
a:hover { text-decoration-color: var(--fg); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
::selection { background: var(--c-prior); color: var(--on-accent); }
p { margin: 0 0 1.1em; }
h1, h2, h3 { font-weight: 600; margin: 0; text-wrap: balance; }
small, .small { font-size: 0.875em; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

/* ---------- header ---------- */
.masthead { padding-block: 72px 40px; border-bottom: 1px solid var(--rule); }
h1 { font-size: clamp(30px, 4.6vw, 44px); line-height: 1.12; letter-spacing: -0.02em; }
.standfirst { font-size: 1.11em; margin: 20px 0 0; }
.byline { margin: 24px 0 0; color: var(--muted); }
.byline .authors { color: var(--fg); }   /* each name links to a homepage: the page's normal link underline, in --fg */
.byline p { margin: 0; }
.links { display: flex; flex-wrap: wrap; gap: 8px 24px; margin: 20px 0 0; padding: 0; list-style: none; }
.links a { font-weight: 600; }

/* ---------- sections ---------- */
main { padding-block: 8px 96px; min-width: 0; }
section { scroll-margin-top: 16px; }
h2 { font-size: clamp(23px, 3vw, 28px); line-height: 1.2; letter-spacing: -0.01em; margin: 64px 0 16px; }

/* ---------- prose lists and the key block ---------- */
/* Numbered lists in the prose ("1. " lines in draft/essay.md; tools/fill_essay.py writes them as direct
   children of <main> in the lead, or of a <section>): spaced like paragraphs, the numbers inside the column. */
main > ol, section > ol { max-width: var(--col); margin: 0 0 1.1em; padding-left: 1.3em; }
main > ol > li + li, section > ol > li + li { margin-top: 6px; }
/* The key block ([[KEY: label]] + a numbered list): set off by a 2 px rule in the text colour at the left,
   a small muted label and a tight numbered list, after the Occupation Translator's "questions" block. */
.key { max-width: var(--col); margin: 28px 0; padding-left: 16px; border-left: 2px solid var(--fg); }
.key-label { margin: 0 0 6px; font-size: 0.875em; color: var(--muted); }
.key ol { margin: 0; padding-left: 1.3em; }
.key li + li { margin-top: 6px; }
.key strong { font-weight: 600; }

/* ---------- contents menu and theme switch ---------- */
/* Markup: .side > .side-inner > nav.toc (a <details> with the section links, written by
   tools/fill_essay.py) + #theme-switch (filled by assets/theme.js; hidden while empty).
   Collapsed (below 1240 px): the contents are a closed <details> at the top of the article, with
   the theme switch on the same line as its summary (its buttons 32 px tall, like the other controls
   and the touch-target minimum). Wide (1240 px and up): see the media block below.
   assets/toc.js reads --toc-wide to know which layout is showing, so the breakpoint lives here only. */
.side { margin: 24px 0 16px; }   /* 16 + main's 8 px top padding: 24 px to the first paragraph, as from the rule above */
.side-inner { display: flex; align-items: flex-start; gap: 12px; }
.toc { --toc-wide: 0; flex: 1 1 auto; min-width: 0; font-size: 0.8125em; }
.toc-title { display: none; }
.toc details { border: 1px solid var(--rule); border-radius: var(--radius); padding: 0 12px; }
.toc summary { display: flex; justify-content: space-between; align-items: center; min-height: 34px; color: var(--muted); cursor: pointer; list-style: none; }
.toc summary::-webkit-details-marker { display: none; }
.toc summary::after { content: "Show"; }
.toc details[open] summary::after { content: "Hide"; }
.toc summary:hover { color: var(--fg); }
.toc ol { list-style: none; margin: 4px 0 12px; padding: 0; border-left: 1px solid var(--rule); }
.toc li + li { margin-top: 2px; }
/* the current section: --fg text and a 2 px bar over the 1 px rail (toc.js sets aria-current) */
.toc a { display: block; margin-left: -1px; padding: 3px 0 3px 12px; border-left: 2px solid transparent; color: var(--muted); text-decoration: none; line-height: 1.4; }
.toc a:hover { color: var(--fg); }
.toc a[aria-current] { color: var(--fg); border-left-color: var(--fg); }
/* theme switch: the kit's segmented control (.seg), smaller and muted */
.theme-switch { flex: none; display: flex; align-items: center; min-height: 36px; }
.theme-switch:empty { display: none; }
.theme-switch .seg button { padding: 2px 9px; font-size: 0.75em; color: var(--muted); }
.theme-switch .seg button:hover { color: var(--fg); }
.theme-switch .seg button[aria-checked="true"] { color: var(--bg); }
@media (max-width: 1239.98px) { .theme-switch .seg button { min-height: 32px; } }
@media (max-width: 600px) { .theme-switch .seg button { min-height: 36px; } }   /* phone: as tall as the Contents box beside it */

/* Wide: the menu is a 200 px column at the left, sticky, with the theme switch above it (so the
   switch is on the first screen even of a 1280 x 720 window, and stays in view while scrolling). The
   text, the masthead, every figure, the table and the captions share one width here, --desk, so the
   page has one left edge and one right edge: --col and --wide are both set to it. That column is
   centred in the window and the menu sits to its left (so the menu is off-centre, the text is not).
   1240 px is where the menu fits beside it (200 menu + 48 gap + 840 + 2 x 16 gutter = 1120). Between 1000 and 1239 px
   the menu is collapsed, the column is 680 px and wide figures (940 px) stay centred on it (the
   .fig.wide rule under "figures"). */
@media (min-width: 1240px) {
  .page {
    --desk: 840px; --col: var(--desk); --wide: var(--desk);
    --toc: 200px; --toc-gap: 48px;
    /* The reading column is centred in the window and the menu hangs to its left. The two side
       tracks share the free space equally; when the window is too narrow for that, the left one
       keeps the room the menu needs and the column sits as near the centre as it can. */
    max-width: none;
    display: grid; column-gap: 0;
    grid-template-columns: minmax(calc(var(--toc) + var(--toc-gap)), 1fr) minmax(0, var(--col)) minmax(0, 1fr);
    grid-template-areas: ". head ." "side main .";
  }
  .masthead { grid-area: head; }
  .side { grid-area: side; justify-self: end; width: var(--toc); margin: 0 var(--toc-gap) 0 0; padding-top: 12px; }
  main { grid-area: main; }
  .side-inner { display: flex; flex-direction: column; align-items: stretch; gap: 0; position: sticky; top: 28px; max-height: calc(100vh - 56px); overflow-y: auto; margin: -4px; padding: 4px; }
  .toc { --toc-wide: 1; }
  .toc-title { display: block; margin: 0 0 10px; color: var(--muted); }
  .toc details { border: 0; border-radius: 0; padding: 0; }
  .toc summary { display: none; }
  .toc ol { margin: 0; }
  .theme-switch { order: -1; margin: 0 0 28px; min-height: 0; }   /* shown first; it stays second in the tab order */
}

/* ---------- maths ---------- */
.katex { font-size: 1.05em; white-space: nowrap; }   /* inline maths never breaks across lines */
.katex-display { overflow-x: auto; overflow-y: hidden; margin: 4px 0 1.2em; padding-block: 4px; }
.katex-display > .katex { white-space: nowrap; }

/* ---------- figures ---------- */
/* Markup:  <figure class="fig [wide]" id="fig-x">
              <div class="fig-controls"></div>   controls, built once in init()
              <div class="fig-stage"></div>      the drawing; emptied and redrawn at its measured width
              <div class="fig-legend"></div>     swatch + label rows (PIFM.legend)
              <figcaption>...</figcaption>
            </figure> */
.fig { margin: 36px 0 44px; min-width: 0; }
@media (min-width: 1000px) { .fig.wide { margin-inline: calc((var(--col) - var(--wide)) / 2); } }
@media (min-width: 1240px) { .fig.wide { margin-inline: 0; } }   /* menu shown: one shared width, see .page */
.fig-stage { position: relative; min-width: 0; }
.fig-stage svg { display: block; overflow: visible; max-width: 100%; }
.fig-controls { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 28px; margin: 0 0 16px; }
.fig-controls:empty, .fig-legend:empty { display: none; }
.fig figcaption { margin-top: 16px; font-size: 0.875em; color: var(--muted); }
.fig.wide figcaption { max-width: var(--col); }   /* left-aligned with the legend and readout above it */
.fig-placeholder { display: flex; align-items: center; justify-content: center; min-height: 220px; border: 1px dashed var(--rule); color: var(--muted); font: var(--fig-text) var(--sans); }
.fig-error { margin: 0; padding: 8px 0; font-size: 0.875em; color: var(--muted); }
.fig-readout { font-size: 0.875em; color: var(--muted); font-variant-numeric: tabular-nums; margin: 10px 0 0; min-height: 1.6em; }
.fig-readout strong { color: var(--fg); font-weight: 600; }

/* ---------- tables ---------- */
/* Markup:  <figure class="tbl" id="tab-x">
              <div class="tbl-scroll"><table>...</table></div>   filled by a script; dashed box while empty
              <figcaption>...</figcaption>
            </figure>
   The box scrolls sideways on its own when the table is wider than the column. */
.tbl { margin: 36px 0 28px; min-width: 0; }
.tbl-scroll { max-width: 100%; overflow-x: auto; }
.tbl-scroll:empty { min-height: 120px; border: 1px dashed var(--rule); }
.tbl table { border-collapse: collapse; font-size: 0.875em; font-variant-numeric: tabular-nums; }
.tbl th, .tbl td { padding: 6px 12px; border-bottom: 1px solid var(--rule); text-align: right; white-space: nowrap; }
/* the row-label column: the first cell of every body row, and the corner cell of the first header row
   (a later header row starts with a number column, so it is left alone) */
.tbl :is(tbody, tfoot) > tr > :first-child, .tbl thead > tr:first-child > :first-child { padding-left: 0; text-align: left; }
.tbl th { font-weight: 600; }
.tbl figcaption { margin-top: 12px; font-size: 0.875em; color: var(--muted); }
/* an optional <caption> is the table's title line: at the top, a small muted label in line with the
   row-label column (the figcaption under the table stays the longer note) */
.tbl caption { caption-side: top; padding: 0 0 10px; text-align: left; color: var(--muted); }

/* legend: HTML rows under the stage */
.fig-legend { display: flex; flex-wrap: wrap; gap: 6px 22px; margin: 12px 0 0; padding: 0; list-style: none; font-size: 0.875em; color: var(--muted); }
.fig-legend li { display: inline-flex; align-items: center; gap: 8px; }
.fig-legend svg { display: block; flex: none; }

/* ---------- controls ---------- */
button, input, select { font: inherit; color: inherit; }
.ctl { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.ctl-label { font-size: 0.875em; color: var(--muted); }

/* segmented control: a radio group of joined buttons */
.seg { display: inline-flex; flex-wrap: wrap; }
.seg button { border: 1px solid var(--muted); background: var(--control-bg); padding: 5px 12px; font-size: 0.875em; line-height: 1.4; cursor: pointer; margin-left: -1px; border-radius: 0; }
.seg button:first-child { margin-left: 0; border-radius: var(--radius) 0 0 var(--radius); }
.seg button:last-child { border-radius: 0 var(--radius) var(--radius) 0; }
.seg button:hover { border-color: var(--fg); position: relative; }
.seg button[aria-checked="true"] { background: var(--control-on); border-color: var(--control-on); color: var(--bg); position: relative; }
.seg button:focus-visible { position: relative; z-index: 1; }

/* stepped slider: a range input over equally spaced stops, tick labels under it */
.step { width: min(100%, 360px); }
.step-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.step-value { font-size: 0.875em; font-variant-numeric: tabular-nums; font-weight: 600; }
.step input[type="range"] { width: 100%; margin: 4px 0 0; accent-color: var(--fg); cursor: pointer; }
.step-ticks { position: relative; height: 1.4em; margin: 0 8px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.step-ticks span { position: absolute; top: 0; transform: translateX(-50%); white-space: nowrap; }
.step-ticks span.on { color: var(--fg); font-weight: 600; }
/* the end labels line up with the ends of the track instead of hanging past them */
.step-ticks span:first-child { transform: translateX(-8px); }
.step-ticks span:last-child { transform: translateX(calc(-100% + 8px)); }

/* plain button */
.btn { border: 1px solid var(--muted); border-radius: var(--radius); background: var(--control-bg); padding: 5px 14px; font-size: 0.875em; line-height: 1.4; cursor: pointer; }
.btn:hover { border-color: var(--fg); }
.btn:disabled { opacity: 0.5; cursor: default; }

/* ---------- cite: BibTeX ---------- */
.cite { margin: 0 0 1.2em; }
/* label, status, Copy button. The status sits just left of the button on wider screens; on a phone it
   takes its own line under them, so a long message (clipboard blocked) never moves the button. */
.cite-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 12px; margin: 0 0 8px; }
.cite-head .btn { margin-left: auto; }
.cite-head .cite-status { order: 3; flex: 1 0 100%; text-align: right; }
@media (min-width: 601px) {
  .cite-head .cite-status { order: 0; flex: 0 1 auto; margin-left: auto; }
  .cite-head .cite-status + .btn { margin-left: 0; }
}
.cite pre { margin: 0; padding: 14px 16px; overflow-x: auto; border: 1px solid var(--rule); border-radius: var(--radius); font: 13.5px/1.5 var(--mono); }
.cite-status { font-size: 0.875em; color: var(--muted); }
@media (max-width: 600px) { .cite pre { white-space: pre-wrap; font-size: 12px; } }

/* ---------- SVG drawing classes (figures use these; colours come from the tokens above) ---------- */
.pf-svg { font-family: var(--sans); font-variant-numeric: tabular-nums; }
.pf-text { font-size: var(--fig-text); fill: var(--fg); }
.pf-text-sm { font-size: var(--fig-text-sm); fill: var(--muted); }
.pf-text-muted { fill: var(--muted); }
.pf-bold { font-weight: 600; }

/* node-link: edges by meaning (stroke) plus a dash pattern, so colour is never alone */
.pf-edge { fill: none; stroke-linecap: round; }
.pf-edge.observed { stroke: var(--c-ink); stroke-width: 1.6; }
.pf-edge.masked-edge { stroke: var(--c-masked); stroke-width: 2; stroke-dasharray: 5 3.5; }
.pf-edge.masked-non { stroke: var(--c-masked-non); stroke-width: 1.4; stroke-dasharray: 1 3.5; }
.pf-edge.prior { stroke: var(--c-prior); }
.pf-edge.flow { stroke: var(--c-flow); }
.pf-edge.ref { stroke: var(--c-ref); stroke-dasharray: 3 3; }
.pf-node { fill: var(--bg); stroke: var(--c-ink); stroke-width: 1.5; }
.pf-node-label { font-size: var(--fig-text-sm); fill: var(--fg); text-anchor: middle; dominant-baseline: central; }

/* matrix */
.pf-cell { shape-rendering: crispEdges; }
.pf-cell-outline { fill: none; stroke: var(--fg); stroke-width: 1.5; pointer-events: none; }
.pf-cell-hi { fill: none; stroke: var(--fg); stroke-width: 2; pointer-events: none; }
.pf-matrix-frame { fill: none; stroke: var(--rule); stroke-width: 1; }

/* axes */
.pf-axis line, .pf-axis path { stroke: var(--c-axis); stroke-width: 1; fill: none; shape-rendering: crispEdges; }
.pf-grid line { stroke: var(--c-grid); stroke-width: 1; shape-rendering: crispEdges; }
.pf-axis text { font-size: var(--fig-text-sm); fill: var(--muted); }
.pf-axis-title { font-size: var(--fig-text-sm); fill: var(--muted); }

/* marks by meaning */
.pf-prior { fill: var(--c-prior); stroke: var(--c-prior); }
.pf-flow { fill: var(--c-flow); stroke: var(--c-flow); }
.pf-ref { fill: var(--c-ref); stroke: var(--c-ref); }
.pf-ink { fill: var(--c-ink); stroke: var(--c-ink); }
.pf-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.pf-dot { stroke: var(--bg); stroke-width: 2; }
/* hatching (PIFM.hatch): thin --c-hatch lines on a --c-empty ground (a masked pair, unknown; an invalid outcome) */
.pf-hatch-line { stroke: var(--c-hatch); stroke-width: 1.4; }
.pf-hatch-bg { fill: var(--c-empty); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
