/* pid1 Labs — the lab site.
 *
 * Monospace throughout, terminal palette. What this deliberately does NOT do
 * is dress up as a terminal: no fake window chrome, no `$` prompt that accepts
 * no input. Those assert the identity instead of having it. What is kept is
 * the part that carries information — fixed columns, tabular figures, and
 * section labels named like directories.
 *
 * Light is a light *terminal* (Terminal.app / solarized-light lineage), not an
 * inversion: the accents are re-derived, since #7fd88f on white is invisible.
 */

:root {
  /* Neutral near-black, not #000. Pure black under light text produces
     halation — the letterforms bloom, badly for anyone with astigmatism —
     and these pages are long-form prose, so it is the wrong place to spend
     contrast. #0d0d0d reads as terminal black without the bleed. Switch this
     one value to #000 if you want the OLED-true version. */
  --bg: #0d0d0d;
  --bg-raised: #161616;
  --ink: #e9e9e9;
  --ink-dim: #b4b4b4;
  /* #808080 rather than something dimmer: this carries dates, tags, nav and
     status at small sizes, and the previous value sat at 3.5:1 — under AA. */
  --ink-faint: #808080;
  --rule: #262626;
  --rule-soft: #1a1a1a;
  --accent: #7fd88f;
  --accent-quiet: #9ae3a7;

  /* Product accents, mapped onto terminal colours. */
  --lyra: #79b8ff;
  --aquila: #e0b872;
  --agentfs: #7fd88f;

  --code-bg: #131313;

  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --page: 60rem;
  --column: 44rem;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #fbfbf9;
    --bg-raised: #f2f2ee;
    --ink: #14181e;
    --ink-dim: #3b414a;
    --ink-faint: #6b7179;  /* 4.75:1 on --bg; #7c828d was 3.73 and failed AA */
    --rule: #e0e1de;
    --rule-soft: #ebebe8;
    --accent: #2f7d4a;
    --accent-quiet: #266740;

    --lyra: #2a5db0;
    --aquila: #8a6100;
    --agentfs: #2f7d4a;

    --code-bg: #f4f4f0;
  }
}

* { box-sizing: border-box; }

/* The type scale lives here, not on body. Nearly every rule below is sized in
   rem, which is root-relative — so scaling the root moves the whole scale
   together, and scaling body would only move the text that inherits from it.
   A percentage rather than px so a reader who has raised their browser's
   default font size keeps that preference; px would silently override it. */
html {
  font-size: 106.25%;          /* 17px at a default 16px preference */
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink-dim);
  font-family: var(--mono);
  font-size: 0.9rem;
  line-height: 1.8;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-variant-ligatures: none;
}

a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: var(--accent-quiet); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

/* Masthead ----------------------------------------------------------------- */

.masthead {
  max-width: var(--page);
  margin: 0 auto;
  padding: 1.5rem 1.4rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem 1.4rem;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--rule);
}

.brand { display: flex; align-items: center; gap: 0.6rem; text-decoration: none; color: var(--ink); }
.brand-mark { width: 24px; height: 24px; overflow: visible; color: var(--ink); flex: none; }
.brand-mark line { stroke: var(--ink-faint); stroke-width: 1.2; }
.brand-name { font-size: 0.95rem; font-weight: 700; letter-spacing: -0.01em; }

.masthead-nav { display: flex; gap: 1.3rem; flex-wrap: wrap; }
.masthead-nav a { font-size: 0.8rem; color: var(--ink-faint); text-decoration: none; }
.masthead-nav a:hover { color: var(--ink); }
/* Where you are, marked once. The underline carries it — colour alone would be
   the only signal for anyone who cannot separate these two greys. */
.masthead-nav a[aria-current="page"] {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-underline-offset: 5px;
}

main { max-width: var(--page); margin: 0 auto; padding: 0 1.4rem; }

/* Section labels, named like directories ----------------------------------- */

.rubric {
  font-size: 0.76rem;
  font-weight: 500;
  color: var(--ink-faint);
  margin: 0;
  letter-spacing: 0.02em;
}
/* A rubric sitting directly in main labels the block beneath it and needs its
   own air; one nested inside a section inherits that section's spacing. */
main > .rubric { margin-top: 2.4rem; }

/* Homepage standfirst ------------------------------------------------------ */

.standfirst { max-width: var(--column); padding: 2.4rem 0 0; }
.standfirst p { font-size: 0.9rem; margin: 0; color: var(--ink-dim); }
.standfirst code { color: var(--ink); }

/* The notes listing -------------------------------------------------------- */
/* This is the part the terminal treatment genuinely improves: date, kind and
   title lock into fixed columns, so six entries scan in one pass. */

.feed { margin: 1.6rem 0 0; border-top: 1px solid var(--rule); }

.entry {
  display: grid;
  grid-template-columns: 11ch 8ch 1fr;
  gap: 0 1.4ch;
  padding: 0.9rem 0;
  border-bottom: 1px solid var(--rule-soft);
}

.entry-meta {
  display: contents;
  font-variant-numeric: tabular-nums;
}
.entry-meta time { color: var(--ink-faint); font-size: 0.8rem; font-variant-numeric: tabular-nums; }

.kind { font-size: 0.8rem; }
/* The kind is not decoration — it tells you the shape of what you are about to
   read, which is what a mixed-length listing most needs to signal. */
.kind-note { color: var(--lyra); }
.kind-finding { color: var(--agentfs); }
.kind-method { color: var(--aquila); }

/* Pinned to column 3 rather than auto-placed. .entry-meta is display:contents,
   so its children are the grid items — and an entry without a `kind` (the feed
   page renders from Atom, which carries none) would otherwise slide the body
   into the 8ch kind column. Explicit placement leaves a gap instead. */
.entry-body { grid-column: 3; }
.entry-body h3 { font-size: 0.9rem; font-weight: 500; line-height: 1.5; margin: 0; }
.entry-body h3 a { color: var(--ink); text-decoration: none; }
.entry-body h3 a:hover { color: var(--accent); text-decoration: underline; }

.dek { color: var(--ink-dim); opacity: 0.82; font-size: 0.85rem; line-height: 1.7; margin: 0.15rem 0 0; }

.tags { margin: 0.25rem 0 0; display: flex; flex-wrap: wrap; gap: 1.1ch; }
.tags span { font-size: 0.76rem; color: var(--ink-faint); }
.tags span::before { content: "#"; opacity: 0.55; }

/* The feed, seen in a browser ---------------------------------------------- */
/* Only ever rendered through static/feed.xsl. */

.feed-banner { max-width: var(--column); padding: 2.4rem 0 1.2rem; }
.feed-banner h1 { font-size: 1.25rem; font-weight: 700; line-height: 1.35; margin: 0.4rem 0 0.9rem; color: var(--ink); }
.feed-url code {
  display: block;
  font-size: 0.82rem;
  color: var(--ink);
  background: var(--bg-raised);
  border: 1px solid var(--rule);
  padding: 0.55rem 0.75rem;
  overflow-x: auto;
  white-space: nowrap;
}

/* work/ -------------------------------------------------------------------- */

.products { margin: 2.8rem 0 0; }
.product-list { list-style: none; margin: 0.8rem 0 0; padding: 0; border-top: 1px solid var(--rule); }
.product-list li { border-bottom: 1px solid var(--rule-soft); }
.product-list a {
  display: grid;
  grid-template-columns: 11ch 1fr 10ch;
  gap: 0.1rem 1.4ch;
  align-items: baseline;
  padding: 0.75rem 0;
  text-decoration: none;
}
.product-name { font-size: 0.9rem; font-weight: 500; color: var(--c); }
.product-list a:hover .product-name { text-decoration: underline; }
.product-what { color: var(--ink-dim); opacity: 0.82; font-size: 0.85rem; }
.product-status { color: var(--ink-faint); font-size: 0.78rem; text-align: right; }

/* Page / taxonomy heads ---------------------------------------------------- */

.page-head { padding: 2.6rem 0 0; max-width: var(--column); }
.page-head h1 { font-size: 1.4rem; font-weight: 700; line-height: 1.35; margin: 0.3rem 0 0; color: var(--ink); }
.standfirst-prose { margin-top: 0.9rem; }
.standfirst-prose p { color: var(--ink-dim); margin: 0 0 0.9rem; }

.tag-index { list-style: none; padding: 0; margin: 1.6rem 0 3rem; max-width: var(--column); border-top: 1px solid var(--rule); }
.tag-index li { display: flex; justify-content: space-between; gap: 1rem; padding: 0.55rem 0; border-bottom: 1px solid var(--rule-soft); }
.tag-index a { font-size: 0.86rem; text-decoration: none; }
.tag-index a:hover { text-decoration: underline; }
.tag-index .count { color: var(--ink-faint); font-size: 0.78rem; font-variant-numeric: tabular-nums; }

/* A note ------------------------------------------------------------------- */
/* 80 columns, the width every terminal inherited from a punch card. It is the
   top of the comfortable range rather than the middle, but the even rhythm of
   a fixed-width face makes lines easier to track than the same count set
   proportionally — and tables get the extra room they need. */

.note { max-width: 80ch; padding: 2.6rem 0 0; }

.note-meta {
  font-size: 0.8rem;
  color: var(--ink-faint);
  margin: 0 0 0.8rem;
  display: flex;
  align-items: center;
  gap: 1.4ch;
  flex-wrap: wrap;
  font-variant-numeric: tabular-nums;
}

.note-head h1 { font-size: 1.4rem; font-weight: 700; line-height: 1.4; margin: 0; color: var(--ink); }
.note-head .dek { font-size: 0.88rem; line-height: 1.75; margin: 0.9rem 0 0; max-width: none; opacity: 1; }
.note-head { padding-bottom: 1.4rem; border-bottom: 1px solid var(--rule); margin-bottom: 1.8rem; }

/* Prose -------------------------------------------------------------------- */

.prose > *:first-child { margin-top: 0; }
.prose p { margin: 0 0 1.3rem; }

.prose h2 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--ink);
  margin: 2.4rem 0 0.9rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--rule-soft);
}
.prose h3 { font-size: 0.9rem; font-weight: 700; color: var(--ink); margin: 1.9rem 0 0.7rem; }

.prose ul, .prose ol { margin: 0 0 1.3rem; padding-left: 2.5ch; }
.prose li { margin: 0 0 0.6rem; }
.prose li::marker { color: var(--ink-faint); }

.prose strong { font-weight: 700; color: var(--ink); }
.prose em { font-style: normal; color: var(--ink); }

.prose blockquote { margin: 1.5rem 0; padding-left: 2ch; border-left: 1px solid var(--rule); color: var(--ink-faint); }
.prose hr { border: 0; border-top: 1px solid var(--rule); margin: 2.4rem 0; }

.prose code { font-size: 0.95em; color: var(--ink); background: var(--bg-raised); padding: 0.05em 0.4ch; }

.prose pre {
  font-size: 0.82rem;
  line-height: 1.7;
  padding: 0.85rem 1ch;
  border: 1px solid var(--rule);
  overflow-x: auto;
  margin: 0 0 1.4rem;
}
.prose pre code { background: none; padding: 0; font-size: inherit; }
/* giallo supplies the token colours and its own ground; override the ground so
   a code block sits in the page rather than on top of it. */
.prose pre.giallo { background: var(--code-bg); }

/* Tables carry most of the evidence here, and mono is the reason they line up:
   figures are already fixed-width, so no tabular-nums fallback is needed. */
.prose table {
  display: block;
  overflow-x: auto;
  border-collapse: collapse;
  font-size: 0.82rem;
  margin: 0 0 1.4rem;
  max-width: 100%;
}
.prose thead th {
  text-align: left;
  font-weight: 500;
  color: var(--ink-faint);
  border-bottom: 1px solid var(--rule);
  padding: 0 2ch 0.45rem 0;
  white-space: nowrap;
}
.prose tbody td { border-bottom: 1px solid var(--rule-soft); padding: 0.4rem 2ch 0.4rem 0; vertical-align: top; }
.prose tbody tr:last-child td { border-bottom: 0; }
.prose td strong { color: var(--ink); }
.prose td code, .prose th code { background: none; padding: 0; }
/* The renderer emits style="text-align: right", not an align attribute; this
   only reclaims the trailing gutter so the last column ends flush. */
.prose th[style*="right"], .prose td[style*="right"] { padding-right: 0; }

.prose img { max-width: 100%; height: auto; }
.prose figure { margin: 1.6rem 0; }
.prose figcaption { font-size: 0.78rem; color: var(--ink-faint); margin-top: 0.5rem; }

.prose .footnote-definition { font-size: 0.84rem; color: var(--ink-faint); display: flex; gap: 1.2ch; }
.prose .footnote-definition p { margin: 0 0 0.4rem; }

/* Note footer -------------------------------------------------------------- */

.note-foot { margin: 2.6rem 0 0; padding-top: 1.2rem; border-top: 1px solid var(--rule); }
.note-foot .source { font-size: 0.78rem; color: var(--ink-faint); margin: 0.7rem 0 0; }
.note-foot .back { margin: 1rem 0 0; }
.note-foot .back a { font-size: 0.82rem; text-decoration: none; }
.note-foot .back a:hover { text-decoration: underline; }

/* Colophon ----------------------------------------------------------------- */

.colophon { max-width: var(--page); margin: 4rem auto 0; padding: 1.4rem 1.4rem 2.6rem; border-top: 1px solid var(--rule); }
.colophon-row { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; font-size: 0.78rem; color: var(--ink-faint); }
.colophon-links { display: flex; gap: 2ch; flex-wrap: wrap; }
.colophon-links a { color: var(--ink-faint); text-decoration: none; }
.colophon-links a:hover { color: var(--ink); }
.colophon-note { font-size: 0.76rem; color: var(--ink-faint); margin: 0.9rem 0 0; }

/* Narrow ------------------------------------------------------------------- */

@media (max-width: 46rem) {
  body { font-size: 0.85rem; }

  /* Date and kind ride on one line, the note drops beneath them. Targets
     .entry-body, not its children — the children are not grid items. */
  .entry { grid-template-columns: 11ch 1fr; gap: 0.15rem 1.4ch; }
  .entry-body { grid-column: 1 / -1; }

  .product-list a { grid-template-columns: 1fr auto; }
  .product-what { grid-column: 1 / -1; }
  .product-status { text-align: left; }

  .standfirst { padding-top: 1.8rem; }
  .note, .page-head { padding-top: 2rem; }
}

/* Wide viewports ----------------------------------------------------------- */
/* The measure is pinned in characters, so a bigger screen cannot buy more of
   them without hurting line-tracking. Scale the type instead: same 80 columns,
   physically wider column, less squinting. */

@media (min-width: 80rem) {
  html { font-size: 112.5%; }  /* 18px — the whole scale, not just body */
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
