/* write-up.css: the shared style for the HTML supports in docs/exploratory-modeling/.
   Every page links this file. A change here changes every page, so propose it in a page plan.
   It follows the 1cf.energy blog (Manrope, its warm grey-beige, navy and bright-blue accents), tuned for long
   technical reading: a lighter reading surface, darker body text, normal weight and spacing. The rail keeps the
   blog's exact background. Light theme only. */

@import url("https://fonts.googleapis.com/css2?family=Fira+Code:wght@400;500&family=Manrope:wght@300..700&display=swap");

/* === Tokens === */

:root {
  color-scheme: light;

  --paper: #f1eee9;
  --rail: #dfdcd7;
  --band: #e5e1db;
  --surface: #f9f8f6;
  --surface-2: #eae6e0;
  --ink: #2e2b28;
  --ink-strong: #191919;
  --muted: #5f5f5f;
  --faint: #6e6961;
  --rule: #d3cdc4;
  --accent: #1b5f99;
  --accent-soft: #d5e6f3;
  --brand-blue: #55b7f9;
  --code-bg: #e6e2dc;
  --plate: #fbfaf8;
  --note-ink: #8a5200;
  --skim: #f2cf8c;       /* the key-sentence band: amber, so it never reads as a link */

  /* Diagram roles */
  --role-calc: #1b5f99;
  --role-data: #0b6f6a;
  --role-check: #95520f;

  --font-sans: "Manrope", "Helvetica Neue", Arial, sans-serif;
  --font-mono: "Fira Code", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;

  --rail-width: 17.5rem;
  --measure: 50rem;
  --wide: 64rem;
}

/* === Base === */

html {
  scroll-padding-top: 1.5rem;
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 1.0625rem;
  line-height: 1.65;
}

a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}

a:hover { text-decoration-thickness: 2px; }

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

strong {
  font-weight: 600;
  color: var(--ink-strong);
}

/* === Layout: fixed contents rail on the left, centred article === */

.rail {
  position: fixed;
  inset: 0 auto 0 0;
  box-sizing: border-box;
  width: var(--rail-width);
  overflow-y: auto;
  padding: 2.25rem 1.25rem 2rem 1.5rem;
  background: var(--rail);
  border-right: 1px solid var(--rule);
}

.page {
  margin-left: var(--rail-width);
  padding-block: 3.5rem 6rem;
  padding-inline: clamp(1rem, 4vw, 3rem);
}

/* Prose sits in the centre track at a reading measure. Section headings, figures and anything marked
   .wide use all three tracks. Sections are subgrids, so nesting keeps the same columns. */
.article {
  display: grid;
  grid-template-columns:
    [wide-start] minmax(0, 1fr)
    [text-start] minmax(0, var(--measure))
    [text-end] minmax(0, 1fr)
    [wide-end];
  max-width: var(--wide);
  margin-inline: auto;
}

:where(.article, .article section) > * { grid-column: text; }

.article section {
  grid-column: wide;
  display: grid;
  grid-template-columns: subgrid;
}

.article h2,
.article .wide { grid-column: wide; }

/* === Rail contents === */

.rail-eyebrow {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--faint);
}

.rail-title {
  margin: 0.5rem 0 1.75rem;
  font-size: 1.125rem;
  font-weight: 600;
  line-height: 1.3;
  color: var(--ink-strong);
  text-wrap: balance;
}

.toc ol {
  list-style: none;
  margin: 0;
  padding: 0;
}

.toc a {
  display: grid;
  grid-template-columns: 2.1rem 1fr;
  gap: 0.2rem;
  padding: 0.3rem 0.5rem;
  border-radius: 3px;
  color: var(--muted);
  font-size: 0.875rem;
  line-height: 1.35;
  text-decoration: none;
}

.toc .n {
  padding-top: 0.1rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--faint);
}

/* Top level: the numbered parts. */
.toc > ol > li { margin-top: 0.9rem; }
.toc > ol > li:first-child { margin-top: 0; }

.toc > ol > li > a {
  font-weight: 600;
  color: var(--ink-strong);
}

/* Second level hangs off a guide line under its part. */
.toc ol ol {
  margin: 0.2rem 0 0 0.95rem;
  padding-left: 0.35rem;
  border-left: 1px solid var(--rule);
}

.toc a:hover {
  background: var(--accent-soft);
  color: var(--ink-strong);
}

.toc a[aria-current] {
  background: var(--accent-soft);
  color: var(--ink-strong);
}

.toc a[aria-current] .n { color: var(--accent); }

/* === Headings === */

.eyebrow {
  margin: 0 0 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--faint);
}

h1, h2, h3, h4 {
  font-family: var(--font-sans);
  font-weight: 600;
  color: var(--ink-strong);
  text-wrap: balance;
}

h1 {
  margin: 0 0 1rem;
  font-size: clamp(2rem, 1.6rem + 1.5vw, 2.7rem);
  line-height: 1.1;
  letter-spacing: -0.015em;
}

/* A numbered part opens with a band across the wide column. */
h2 {
  position: relative;
  margin: 4.5rem 0 2rem;
  padding: 1.15rem 1.25rem 1.25rem;
  background: var(--band);
  border-top: 3px solid var(--ink-strong);
  font-size: 1.75rem;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

h1 + section > h2:first-child { margin-top: 2.5rem; }

h3 {
  position: relative;
  margin: 3rem 0 0.9rem;
  font-size: 1.3125rem;
  line-height: 1.3;
}

h4 {
  margin: 2rem 0 0.5rem;
  font-size: 1.0625rem;
  line-height: 1.35;
}

/* The section number the markdown heading carries. */
.num {
  margin-right: 0.6em;
  font-family: var(--font-mono);
  font-size: 0.82em;
  font-weight: 500;
  color: var(--accent);
}

/* With room beside the text column, numbers hang in the margin and the titles line up with the prose. */
@media (min-width: 84rem) {
  h2 { padding-left: calc((100% - var(--measure)) / 2); }

  h2 .num,
  h3 .num {
    position: absolute;
    right: calc(100% + 1.1rem);
    margin: 0;
  }

  h2 .num {
    right: auto;
    left: 1.25rem;
    top: 1.35rem;
  }

  h3 .num { top: 0.2em; }
}

/* === Prose === */

p { margin: 0 0 1.1rem; }

ul, ol {
  margin: 0 0 1.25rem;
  padding-left: 1.3rem;
}

li { margin-bottom: 0.45rem; }
li::marker { color: var(--faint); }

code,
pre { font-variant-ligatures: none; }

code {
  padding: 0.08em 0.3em;
  border-radius: 3px;
  background: var(--code-bg);
  font-family: var(--font-mono);
  font-size: 0.87em;
}

/* A repository path that replaces a link: shown, not clickable. */
code.path {
  padding: 0;
  background: none;
  border-bottom: 1px dotted var(--faint);
  border-radius: 0;
  color: var(--muted);
  font-size: 0.82em;
  overflow-wrap: anywhere;
}

/* A qualification the reader must not miss. */
.note {
  margin: 0.4rem 0 1.6rem;
  padding: 0.85rem 0;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
}

.note p:last-child { margin-bottom: 0; }

.note-label {
  display: block;
  margin-bottom: 0.3rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--note-ink);
}

/* A key sentence for a skimming reader: a highlighter band under the lower part of the text, repeated on each
   line when the sentence wraps. Amber, so it never reads as a link (links carry a blue underline). Mark it up
   as <mark class="skim">. */
.skim {
  padding: 0 0.06em;
  background: linear-gradient(to bottom, transparent 52%, var(--skim) 52%, var(--skim) 94%, transparent 94%);
  color: inherit;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}

/* === Figures === */

.figure { margin: 1.75rem 0 2.25rem; }

/* Images and SVG figures sit on a white plate in both themes. */
.plate {
  display: flex;
  justify-content: center;
  padding: 1.25rem;
  background: var(--plate);
  border: 1px solid var(--rule);
  border-radius: 4px;
}

.plate img,
.plate svg {
  display: block;
  max-width: 100%;
  height: auto;
}

/* Diagrams built in HTML use the theme's colors instead of a plate. */
.frame {
  padding: 1.25rem;
  background: var(--surface-2);
  border: 1px solid var(--rule);
  border-radius: 4px;
}

.figure figcaption {
  max-width: var(--measure);
  margin: 0.8rem auto 0;
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--muted);
}

.fig-label {
  margin-right: 0.5em;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-strong);
}

/* === Diagram parts (layouts that belong to one figure go in that page's own style block) === */

.diagram-scroll { overflow-x: auto; }

.diagram {
  min-width: 36rem;
  font-size: 0.9375rem;
  line-height: 1.45;
}

.dg-head { margin-bottom: 1rem; }

.dg-title {
  font-size: 1.0625rem;
  font-weight: 600;
  color: var(--ink-strong);
}

.dg-sub {
  font-size: 0.875rem;
  color: var(--muted);
}

.dg-box {
  --role: var(--role-calc);
  min-width: 0;
  padding: 0.75rem 0.95rem 0.85rem;
  background: var(--surface);
  border: 1.5px solid var(--role);
  border-radius: 6px;
}

.dg-box.data { --role: var(--role-data); }
.dg-box.check { --role: var(--role-check); }

.dg-label {
  margin-bottom: 0.45rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--role);
}

.dg-label .what {
  font-family: var(--font-sans);
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
}

.dg-box pre {
  margin: 0;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  line-height: 1.5;
  color: var(--ink);
}

.dg-box ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.dg-box li { margin: 0.1rem 0; }

.dg-box p,
.dg-note {
  margin: 0.55rem 0 0;
  font-size: 0.8125rem;
  color: var(--muted);
}

.dg-arrow {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 1.25rem;
  line-height: 1;
  color: var(--faint);
}

/* === Code blocks === */

.code {
  margin: 1.25rem 0 1.6rem;
  overflow: hidden;
  background: var(--code-bg);
  border: 1px solid var(--rule);
  border-radius: 4px;
}

.code-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.25rem 1rem;
  padding: 0.45rem 0.9rem;
  border-bottom: 1px solid var(--rule);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--muted);
}

.code-head .file { overflow-wrap: anywhere; }

.code-head .lang {
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--faint);
}

.code pre {
  margin: 0;
  padding: 0.9rem 1rem;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  line-height: 1.6;
  color: var(--ink);
}

.code pre code {
  padding: 0;
  background: none;
  font-size: inherit;
}

/* === Collapsible detail: part of the section's structure, closed by default ===
   For material not every reader wants, such as implementation steps. The summary carries the heading. */

details.detail {
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
}

details.detail + details.detail { margin-top: -1px; }

details.detail > summary {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.8rem 0.25rem;
  cursor: pointer;
  list-style: none;
}

details.detail > summary::-webkit-details-marker { display: none; }

details.detail > summary::before {
  content: "";
  flex: none;
  width: 0.45rem;
  height: 0.45rem;
  margin: 0 0.15rem 0 0.1rem;
  border-right: 2px solid var(--accent);
  border-bottom: 2px solid var(--accent);
  transform: rotate(-45deg);
  transition: transform 0.15s ease;
}

details.detail[open] > summary::before { transform: rotate(45deg); }

details.detail > summary::after {
  content: "Show";
  flex: none;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--faint);
}

details.detail[open] > summary::after { content: "Hide"; }

details.detail > summary:hover { background: var(--accent-soft); }

details.detail > summary > :is(h3, h4, span) {
  flex: 1;
  margin: 0;
  font-size: 1.0625rem;
}

details.detail > summary .num { font-size: 0.8em; }

.detail-body {
  margin: 0 0 1rem 0.45rem;
  padding: 0.35rem 0 0.1rem 1.35rem;
  border-left: 2px solid var(--accent-soft);
}

@media (prefers-reduced-motion: reduce) {
  details.detail > summary::before { transition: none; }
}

/* Prose that follows a closed detail section keeps a gap below the section's rule. */
details.detail + p,
details.detail + ul { margin-top: 1.25rem; }

/* === Evidence panel: the information a repository reference points to, closed by default === */

details.evidence {
  margin: 0.4rem 0 1.75rem;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 4px;
}

details.evidence > summary {
  display: flex;
  align-items: baseline;
  gap: 0.7rem;
  padding: 0.65rem 1rem;
  cursor: pointer;
  list-style: none;
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--ink-strong);
}

details.evidence > summary::-webkit-details-marker { display: none; }

details.evidence > summary::before {
  content: "+";
  flex: none;
  width: 1ch;
  font-family: var(--font-mono);
  color: var(--accent);
}

details.evidence[open] > summary::before { content: "\2212"; }

details.evidence > summary:hover { background: var(--accent-soft); }

.evidence-kind {
  flex: none;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--faint);
}

.evidence-body {
  padding: 0.9rem 1rem 0.2rem;
  border-top: 1px solid var(--rule);
  font-size: 0.9375rem;
}

.evidence-body .code { margin-top: 0.4rem; }

/* === Explore panels: a live part the page's script wakes, hidden until it runs, so the page reads without it ===
   A panel holds a lead, a row of chip buttons and a readout. A figure it explores marks its parts with
   data-part; the script adds .explorable to the figure, and .exploring while a part is chosen. */

[hidden] { display: none !important; }

.live {
  margin: 0.4rem 0 1.75rem;
  padding: 0.85rem 1rem 0.9rem;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 4px;
  font-size: 0.9375rem;
}

.live-head {
  display: flex;
  align-items: baseline;
  gap: 0.7rem;
  margin-bottom: 0.4rem;
  font-weight: 500;
  color: var(--ink-strong);
}

.live-kind {
  flex: none;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}

.live p { margin: 0 0 0.6rem; }
.live p:last-child { margin-bottom: 0; }
.live .muted { color: var(--muted); font-size: 0.875rem; }

.chips { display: flex; flex-wrap: wrap; gap: 0.35rem; margin: 0.5rem 0 0.8rem; }

.chip {
  padding: 0.2rem 0.6rem;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--plate);
  color: var(--ink);
  font: inherit;
  font-size: 0.8125rem;
  line-height: 1.3;
  cursor: pointer;
}

.chip:hover { border-color: var(--accent); }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }

.readout { font-size: 0.9375rem; }
.readout > :last-child { margin-bottom: 0; }
.readout .readout-title { font-weight: 600; color: var(--ink-strong); }
.readout ul { margin: 0 0 0.6rem; padding-left: 1.3rem; }
.readout dl { display: grid; grid-template-columns: auto 1fr; gap: 0.25rem 0.9rem; margin: 0.4rem 0 0; }
.readout dt { color: var(--muted); font-size: 0.875rem; }
.readout dd { margin: 0; }

.explorable [data-part] { cursor: pointer; }
.exploring [data-part] { transition: opacity 0.15s ease; }
.exploring [data-part]:not(.picked):not(.holds-pick) { opacity: 0.4; }
.exploring [data-part].picked { opacity: 1; box-shadow: 0 0 0 3px var(--brand-blue); }

@media (prefers-reduced-motion: reduce) {
  .exploring [data-part] { transition: none; }
}

/* === Tables === */

/* A table set as a figure keeps its caption above the table. */
.table-figure figcaption { margin: 0 auto 0.6rem; }

.table-wrap {
  margin: 0.75rem 0 1.25rem;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
}

th {
  padding: 0.45rem 0.9rem 0.45rem 0;
  border-bottom: 1px solid var(--ink-strong);
  font-weight: 600;
  text-align: left;
  color: var(--ink-strong);
}

td {
  padding: 0.4rem 0.9rem 0.4rem 0;
  border-bottom: 1px solid var(--rule);
  vertical-align: top;
}

td code {
  font-size: 0.85em;
  overflow-wrap: break-word;
}

th.r, td.r { text-align: right; }

/* === Narrow screens: the rail becomes a contents block at the top === */

@media (max-width: 56rem) {
  body { font-size: 1rem; }

  .rail {
    position: static;
    width: auto;
    padding: 1.5rem 1rem 1.25rem;
    border-right: 0;
    border-bottom: 1px solid var(--rule);
  }

  .rail-title { margin-bottom: 1rem; }
  .toc ol ol { display: none; }

  .page {
    margin-left: 0;
    padding-block: 2rem 4rem;
    padding-inline: 1rem;
  }

  h2 {
    margin-inline: -1rem;
    padding-inline: 1rem;
    font-size: 1.5rem;
  }
}

@media print {
  .rail { display: none; }
  .page { margin-left: 0; }
}


/* === The blog's identity, tuned for long technical reading === */

body {
  font-size: 1.125rem;
  font-weight: 400;
  line-height: 1.72;
  letter-spacing: 0;
  word-spacing: 0.02em;
}

h1 {
  font-weight: 400;
  line-height: 1.125;
  letter-spacing: -0.01em;
}

h2 { font-weight: 500; }
h3, h4, details.detail > summary > :is(h3, h4, span) { font-weight: 600; }

strong { font-weight: 700; }

a {
  color: var(--ink-strong);
  text-decoration-color: var(--brand-blue);
  text-decoration-thickness: 2px;
}

a:hover { text-decoration-color: var(--accent); }

.rail { border-right-color: #cfcac2; }
.rail-title { font-weight: 600; }
.toc a { font-weight: 450; color: #4d4a46; }
.toc > ol > li > a { font-weight: 650; }
.toc a[aria-current] { box-shadow: inset 2px 0 0 var(--brand-blue); }

/* Secondary text stays in the blog's grey, but at a size and weight that holds up. */
.figure figcaption,
.dg-sub,
.dg-box p,
.dg-note { font-weight: 450; }

.code pre,
.dg-box pre { font-size: 0.84rem; }
