/* 13fragments site styles: ruled header, numbered sections, Ledger palette.
   One type family in three roles: IBM Plex Serif for reading, IBM Plex Sans for structure,
   IBM Plex Mono for labels, numbers, and code.
   Rules and reasons: docs/style-guide.md. Page <style> blocks hold page-specific components only.
   After you change this file, increase ?v= in every page's stylesheet link. */

/* ------------------------------------------------------------------ tokens */
:root {
  /* Ledger palette. */
  --paper: #f3f4ef;            /* page background */
  --surface: #fdfdfb;          /* cards, figures, tables, header */
  --surface-alt: #e9ebe3;      /* table heads, code, quotes */
  --rule: #dde0d6;             /* hairlines inside components */
  --frame: #cdd1c5;            /* outer lines of the header, cards, and footer */
  --ink: #141815;              /* text */
  --ink-soft: #39403a;         /* deks, secondary text */
  --muted: #5b635c;            /* captions, labels, footers */
  --faint: #8a918a;            /* inactive numbers, separators */
  --accent: #25604c;           /* bookcloth green: section numbers, rules, active states */
  --accent-text: #1d4d3d;      /* the accent on text */
  --accent-tint: #e4ede7;      /* claim boxes, chips */
  --accent-line: rgba(29, 77, 61, .3);
  --accent-line-soft: rgba(29, 77, 61, .15);
  --mark: #f1ecb8;             /* highlighter for one marked phrase */
  --link: #1d4d3d;
  --link-hover: #25604c;
  --link-line: rgba(37, 96, 76, .38);
  --chip-line: #c2d6cb;
  /* Data colors for figures. Keep them inside figures. */
  --data-truth: #25604c;       /* ground truth, human keys, sealed items */
  --data-truth-soft: #e1ebe4;
  --data-model: #2c5d8a;       /* fine-tuned models */
  --data-slate: #2f3e4c;       /* other engines and neutral marks */

  /* Earlier names, kept so page components keep working. */
  --bg: var(--paper);
  --tint: var(--surface-alt);
  --soft: var(--ink-soft);

  --serif: "IBM Plex Serif", Georgia, "Times New Roman", serif;
  --sans: "IBM Plex Sans", "Helvetica Neue", Arial, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;
  --measure: 660px;            /* reading width */
  --wide: 940px;               /* figures and tables in articles */
  --rail: 200px;               /* contents rail in articles */
  --gutter: 40px;
}

/* ------------------------------------------------------------------ base */
* { box-sizing: border-box; }
html { background: var(--paper); -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { margin: 0; color: var(--ink); background: var(--paper); font-family: var(--serif); font-size: 18px; line-height: 1.7;
  -webkit-font-smoothing: antialiased; font-kerning: normal; }
p { margin: 0; text-wrap: pretty; }
strong { font-weight: 600; }
code { font-family: var(--mono); font-size: .8em; background: var(--surface-alt); color: var(--ink-soft); padding: 1px 5px;
  border-radius: 4px; overflow-wrap: anywhere; }
[id] { scroll-margin-top: 24px; }

/* ------------------------------------------------------------------ links */
a { color: var(--link); text-decoration: underline; text-decoration-thickness: 1px; text-decoration-color: var(--link-line);
  text-underline-offset: 3px; }
a:hover { color: var(--link-hover); text-decoration-color: currentColor; }
a:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 2px; }
a.primary { font-family: var(--sans); font-weight: 600; text-decoration-thickness: 2px; text-decoration-color: var(--accent); }
.links { display: flex; flex-wrap: wrap; gap: 6px 18px; font-family: var(--sans); font-size: 15px; font-weight: 500; }

/* ------------------------------------------------------------------ page frame */
main { max-width: 720px; margin: 0 auto; padding: 40px 20px calc(48px + env(safe-area-inset-bottom)); display: flex;
  flex-direction: column; gap: 40px; min-height: 100svh; }

.doc-header { border: 1px solid var(--frame); background: var(--surface); display: flex; }
.doc-header > div { flex: 1 1 0; padding: 10px 14px; display: flex; flex-direction: column; gap: 2px; min-width: 0;
  font-family: var(--sans); font-size: 14px; line-height: 1.45; }
.doc-header > div + div { border-left: 1px solid var(--frame); }
.doc-header strong { font-weight: 600; }
.doc-header a { color: var(--ink); }
.doc-mark { flex: 0 0 58px; display: flex; align-items: center; justify-content: center; border-right: 1px solid var(--frame);
  color: var(--ink); text-decoration: none; }
.doc-mark svg { display: block; width: 26px; height: 26px; }
.doc-mark:focus-visible { outline-offset: -4px; }

footer { margin-top: auto; display: grid; grid-template-columns: 1fr auto 1fr; gap: 12px; padding-top: 12px;
  border-top: 1px solid var(--frame); font-family: var(--mono); font-size: 12px; line-height: 1.6; color: var(--muted); }
footer a { color: inherit; }
footer > :last-child { justify-self: end; }
footer > * { white-space: nowrap; }

/* ------------------------------------------------------------------ text roles */
.label { font-family: var(--mono); font-size: 10.5px; font-weight: 500; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); }
.kicker { font-family: var(--mono); font-size: 12px; font-weight: 500; letter-spacing: .1em; text-transform: uppercase; color: var(--accent-text); }
.soft { color: var(--ink-soft); }
.muted { color: var(--muted); }
.note { font-family: var(--sans); font-size: 14px; line-height: 1.6; color: var(--muted); }
mark { background: linear-gradient(transparent 12%, var(--mark) 12%, var(--mark) 92%, transparent 92%); color: inherit; padding: 0 2px; }
.todo { background: #fff3c4; padding: 0 3px; }

/* A claim box marks the one statement or summary a reader must not miss. .status is the same box. */
.claim, .status { background: var(--accent-tint); border-left: 3px solid var(--accent); border-radius: 0 12px 12px 0;
  padding: 14px 18px; color: var(--ink-soft); }
.status { font-size: 16px; line-height: 1.6; }

/* ------------------------------------------------------------------ headings and numbering */
h1, h2 { margin: 0; font-family: var(--sans); font-weight: 600; font-size: 26px; line-height: 1.25; letter-spacing: -.012em; }
h3 { margin: 0; font-family: var(--sans); font-weight: 600; font-size: 19px; line-height: 1.35; }
.num { font-family: var(--mono); font-weight: 500; font-size: .8em; color: var(--accent-text); font-variant-numeric: tabular-nums; }
:is(h1, h2) > .num { font-size: 13px; letter-spacing: .04em; vertical-align: .3em; margin-right: .15em; }
.section { display: flex; flex-direction: column; gap: 14px; }
.refs { display: grid; grid-template-columns: max-content 1fr; column-gap: 20px; row-gap: 8px; }
.refs > :nth-child(odd) { font-family: var(--mono); font-size: 13px; color: var(--accent-text); padding-top: 3px; }
.refs > :nth-child(even) { min-width: 0; overflow-wrap: anywhere; }
.refs > span:target, .refs > span:target + span { background: var(--accent-tint); }

/* ------------------------------------------------------------------ catalog lists: models, datasets */
.models { border: 1px solid var(--frame); background: var(--surface); border-radius: 12px; overflow: hidden; }
.model { padding: 16px 18px 14px; display: grid; grid-template-columns: 34px 1fr; column-gap: 12px; row-gap: 6px; }
.model + .model { border-top: 1px solid var(--rule); }
.model > .num { grid-row: span 4; font-size: 13px; padding-top: 4px; }
.model-name { font-family: var(--sans); font-weight: 600; font-size: 19px; line-height: 1.35; overflow-wrap: anywhere; }
.model .links { font-size: 14px; }

/* ------------------------------------------------------------------ articles */
/* An article page widens to a contents rail, a reading column, and wide figures. */
main:has(> .post) { max-width: calc(var(--rail) + var(--gutter) + var(--wide) + 40px); }
.post { display: grid; grid-template-columns: minmax(0, 1fr); align-items: start; }
.post > * + * { margin-top: 40px; }
.post > *, .section > *, .appendix > * { max-width: var(--measure); width: 100%; }
.post > :is(.section, .appendix, figure, .hero, .keystats), .section > figure, .appendix > .section { max-width: none; }
.post > .title { max-width: 780px; }
:where(.post) .section { gap: 20px; }
:where(.post) h2 { margin-top: 24px; }
:where(.post :is(ul, ol):not([class])) { margin: 0; padding-left: 22px; display: flex; flex-direction: column; gap: 8px; }

.title { display: flex; flex-direction: column; gap: 18px; }
.title h1 { font-family: var(--serif); font-weight: 600; font-size: 50px; line-height: 1.08; letter-spacing: -.02em; }
.title .dek { font-size: 21px; line-height: 1.55; color: var(--ink-soft); }

/* Key numbers under the title: three or four values, each linked to its section. */
.keystats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); border-top: 2px solid var(--ink); }
.keystats .stat { display: flex; flex-direction: column; gap: 6px; padding: 16px 18px 2px; color: inherit; text-decoration: none; }
.keystats .stat:first-child { padding-left: 0; }
.keystats .stat + .stat { border-left: 1px solid var(--rule); }
.keystats .v { font-family: var(--serif); font-weight: 600; font-size: 40px; line-height: 1; letter-spacing: -.02em;
  font-variant-numeric: lining-nums tabular-nums; }
.keystats .v.data-truth { color: var(--data-truth); }
.keystats .v.data-model { color: var(--data-model); }
.keystats .k { font-family: var(--sans); font-size: 14px; line-height: 1.4; color: var(--muted); }
.keystats .stat:hover .k { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }

.hero { gap: 12px; }

/* Contents: inline after the summary on narrow screens, a sticky rail on wide screens. */
.contents { display: flex; flex-direction: column; gap: 10px; font-family: var(--sans); font-size: 14px; line-height: 1.4;
  background: var(--surface); border: 1px solid var(--rule); border-radius: 12px; padding: 16px 18px; }
.contents ol { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.contents a { display: grid; grid-template-columns: 34px 1fr; padding: 4px 0; color: var(--ink-soft); text-decoration: none; }
.contents a:hover { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }
.contents .num { font-size: 12px; color: var(--faint); padding-top: 1px; }

.cite { font-family: var(--sans); font-size: .62em; vertical-align: .55em; line-height: 0; white-space: nowrap; color: var(--link); }
.cite a { text-decoration: none; }
.cite a:hover { text-decoration: underline; }
.section p > strong:first-child { font-family: var(--sans); font-size: .93em; }
.appendix { border-top: 1px solid var(--frame); padding-top: 32px; display: flex; flex-direction: column; gap: 40px; }
.appendix h2 { font-size: 22px; }
.appendix .refs { font-family: var(--sans); font-size: 14px; line-height: 1.55; color: var(--ink-soft); }
blockquote { margin: 0; padding: 14px 18px; border-left: 3px solid var(--accent); background: var(--surface-alt);
  border-radius: 0 12px 12px 0; font-style: italic; font-size: 17px; }
details { font-family: var(--sans); font-size: 14px; }
summary { cursor: pointer; color: var(--ink-soft); }
details .table-wrap { margin-top: 8px; }

/* ------------------------------------------------------------------ figures and tables */
figure { margin: 0; display: flex; flex-direction: column; gap: 12px; }
figure img { display: block; width: 100%; height: auto; border: 1px solid var(--rule); background: var(--surface-alt); }
figure svg { display: block; width: 100%; height: auto; }
figcaption { font-family: var(--sans); font-size: 14px; line-height: 1.6; color: var(--muted); max-width: var(--measure); }
.figlabel { color: var(--ink); font-weight: 600; }
/* In articles, a figure or table is a plate on the surface color. */
.post figure { background: var(--surface); border: 1px solid var(--rule); border-radius: 12px; padding: 18px 22px 16px; }
.post figure img { border: 0; }
.post figure.claim { background: var(--accent-tint); border: 0; border-left: 3px solid var(--accent); border-radius: 0 12px 12px 0; }
.post figure.claim > figcaption { font-family: var(--serif); font-size: 17px; font-weight: 600; color: var(--ink); max-width: none; }
.post figure.claim .figlabel { font-family: var(--mono); font-size: 11px; font-weight: 500; letter-spacing: .08em;
  text-transform: uppercase; color: var(--accent-text); margin-right: 6px; }
.post figure.claim .data td:first-child { font-family: var(--sans); font-weight: 600; color: var(--ink); }
.claim .data td strong { font-family: var(--serif); font-size: 1.12em; }
.plate-label { display: flex; align-items: center; gap: 12px; font-family: var(--sans); font-size: 12px; font-weight: 600;
  letter-spacing: .09em; text-transform: uppercase; color: var(--muted); }
.chip { font-family: var(--mono); font-size: 11px; font-weight: 500; letter-spacing: .04em; text-transform: none; color: var(--accent-text);
  background: var(--accent-tint); border: 1px solid var(--chip-line); border-radius: 4px; padding: 1px 7px; white-space: nowrap; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.data { width: 100%; border-collapse: collapse; font-family: var(--sans); font-size: 14px; line-height: 1.45; font-variant-numeric: tabular-nums; }
.data th { text-align: left; vertical-align: bottom; font-family: var(--mono); font-weight: 500; font-size: 10.5px; letter-spacing: .07em;
  text-transform: uppercase; color: var(--muted); background: var(--surface-alt); padding: 8px 12px; border-bottom: 1px solid var(--rule); }
.data td { vertical-align: top; padding: 9px 12px; border-top: 1px solid var(--rule); }
.data tbody tr:first-child td { border-top: 0; }
.data .r { text-align: right; }
.data td.r { white-space: nowrap; }
.data a { overflow-wrap: anywhere; }
.data tr:last-child td { font-weight: 600; }
.data.slices tr:last-child td { font-weight: 400; }
.data tbody tr:hover td { background: #f6f7f2; }
.claim .data th { background: transparent; border-bottom-color: var(--accent-line); }
.claim .data td { border-top-color: var(--accent-line-soft); }

/* An article without a contents block is one centered column; figures still use the wide width. */
.post:not(:has(> .contents)) { justify-items: center; }
.post:not(:has(> .contents)) > .title { max-width: var(--measure); }
.post:not(:has(> .contents)) .section > :not(figure) { margin-left: auto; margin-right: auto; }

/* ------------------------------------------------------------------ wide screens: contents rail */
@media (min-width: 1240px) {
  .post { grid-template-columns: var(--rail) minmax(0, var(--wide)); column-gap: var(--gutter); }
  .post > * { grid-column: 2; }
  .post > .contents { grid-column: 1; grid-row: 1 / span 99; margin-top: 0; position: sticky; top: 24px; background: none;
    border: 0; padding: 6px 0 0; font-size: 13px; }
  .post > .contents ol { border-left: 1px solid var(--rule); }
  .post > .contents a { padding: 5px 0 5px 12px; margin-left: -1px; border-left: 2px solid transparent; color: var(--muted); }
  .post > .contents a[aria-current="true"] { color: var(--ink); font-weight: 600; border-left-color: var(--accent); }
  .post > .contents a[aria-current="true"] .num { color: var(--accent-text); }
  /* An article without a contents block has no rail: center it. */
  .post:not(:has(> .contents)) { grid-template-columns: minmax(0, var(--wide)); justify-content: center; }
  .post:not(:has(> .contents)) > * { grid-column: 1; }
}

/* ------------------------------------------------------------------ phones */
@media (max-width: 640px) {
  body { font-size: 17px; }
  main { padding-top: 24px; gap: 32px; }
  .post > * + * { margin-top: 32px; }
  .doc-header { flex-wrap: wrap; }
  .doc-header > div { padding: 10px 10px; font-size: 13px; }
  .doc-mark { flex-basis: 100%; justify-content: flex-start; padding: 10px; border-right: 0; border-bottom: 1px solid var(--frame); }
  .doc-mark svg { width: 22px; height: 22px; }
  h1, h2 { font-size: 22px; }
  .title h1 { font-size: 34px; }
  .title .dek { font-size: 18px; }
  .model { padding: 14px 12px 12px; grid-template-columns: 28px 1fr; column-gap: 8px; }
  .post figure { padding: 12px; border-radius: 10px; margin-left: -8px; margin-right: -8px; }
  .keystats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .keystats .stat { padding: 14px 12px 10px; }
  .keystats .stat:nth-child(odd) { padding-left: 0; border-left: 0; }
  .keystats .stat:nth-child(n+3) { border-top: 1px solid var(--rule); }
  .keystats .v { font-size: 32px; }
  footer { grid-template-columns: 1fr auto; row-gap: 4px; }
  footer > :first-child { grid-column: 1 / -1; }
}
