:root {
  --bg: #f7f4ee;
  --surface: #fffdf9;
  --text: #1f1d1a;
  --muted: #5d584f;
  --rule: #ddd6ca;
  --accent: #2f5d8a;
  --accent-soft: rgba(47, 93, 138, 0.12);
  --tint: #efe9de;
  --dg-edge: #8a8276;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: ui-serif, "New York", Georgia, Cambria, "Times New Roman", serif;
  --measure: 42rem;
  --gutter: 16px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171a;
    --surface: #1d2024;
    --text: #ebe7df;
    --muted: #a8a297;
    --rule: #34383e;
    --accent: #8fb6e3;
    --accent-soft: rgba(143, 182, 227, 0.14);
    --tint: #1e2226;
    --dg-edge: #7d8590;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15171a;
  --surface: #1d2024;
  --text: #ebe7df;
  --muted: #a8a297;
  --rule: #34383e;
  --accent: #8fb6e3;
  --accent-soft: rgba(143, 182, 227, 0.14);
  --tint: #1e2226;
  --dg-edge: #7d8590;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: clamp(1.0625rem, 0.98rem + 0.4vw, 1.1875rem);
  line-height: 1.65;
  overflow-wrap: break-word;
}

a { color: var(--accent); text-underline-offset: 0.18em; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }
a:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 3px; }

.skip {
  position: absolute;
  left: var(--gutter);
  top: -4rem;
  padding: 0.5rem 0.9rem;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 6px;
  z-index: 10;
}
.skip:focus { top: var(--gutter); }

.layout {
  max-width: calc(var(--measure) + 2 * var(--gutter));
  margin: 0 auto;
  padding: 0 var(--gutter) 6rem;
}

/* Masthead */
.masthead { padding: clamp(2.5rem, 8vw, 5rem) 0 1.5rem; }
h1, h2, h3 {
  font-family: var(--serif);
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.01em;
  text-wrap: balance;
}
h1 { font-size: clamp(2.25rem, 1.5rem + 3.2vw, 3.4rem); margin: 0 0 0.75rem; }
.byline { margin: 0; color: var(--muted); font-size: 0.95em; }

/* Contents */
.toc {
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  padding: 1rem 0 1.1rem;
  margin-bottom: 1rem;
  font-size: 0.95em;
  scroll-margin-top: 1rem;
}
.toc-title {
  margin: 0 0 0.4rem;
  font-size: 0.75em;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.toc ol { margin: 0; padding-left: 1.4em; }
.toc li { padding: 0.15rem 0; }
.toc li::marker { color: var(--muted); font-variant-numeric: tabular-nums; }
.toc a { text-decoration: none; display: inline-block; padding: 0.2rem 0; }
.toc a:hover { text-decoration: underline; }

/* Story */
main > p:first-child { font-size: 1.12em; }
h2 {
  font-size: clamp(1.6rem, 1.3rem + 1.2vw, 2rem);
  margin: 3.25rem 0 1rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--rule);
  scroll-margin-top: 1rem;
}
h3 { font-size: 1.25em; margin: 2.25rem 0 0.75rem; scroll-margin-top: 1rem; }
p, ul, ol { margin: 0 0 1.1em; }
ul, ol { padding-left: 1.3em; }
li + li { margin-top: 0.45em; }
li::marker { color: var(--muted); }
strong { font-weight: 650; }

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.25rem 0 1.75rem;
  font-size: 0.93em;
  line-height: 1.5;
}
th {
  text-align: left;
  font-size: 0.8em;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0 0.9rem 0.5rem 0;
  border-bottom: 2px solid var(--rule);
}
td {
  vertical-align: top;
  padding: 0.7rem 0.9rem 0.7rem 0;
  border-bottom: 1px solid var(--rule);
}
th:last-child, td:last-child { padding-right: 0; }
.cols-3 td:first-child { white-space: nowrap; }

@media (max-width: 599px) {
  table, tbody, tr, td { display: block; }
  thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }
  table { border-top: 2px solid var(--rule); }
  tr { padding: 0.8rem 0; border-bottom: 1px solid var(--rule); }
  td { padding: 0; border: 0; }
  .cols-3 td:first-child { white-space: normal; }
  td:first-child { font-size: 1.05em; margin-bottom: 0.2rem; }
  td + td {
    display: grid;
    grid-template-columns: 6.75rem minmax(0, 1fr);
    gap: 0.75rem;
    margin-top: 0.3rem;
  }
  td + td::before {
    content: attr(data-label);
    font-size: 0.72em;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
    padding-top: 0.25em;
  }
  /* Two-column tables read fine as heading plus paragraph, no label needed. */
  .cols-2 td + td { display: block; }
  .cols-2 td + td::before { content: none; }
}

/* Diagram */
.diagram {
  --fig-w: min(760px, calc(100vw - 2 * var(--gutter)));
  width: var(--fig-w);
  margin: 2rem 0 2.25rem calc((100% - var(--fig-w)) / 2);
  padding: 0;
}
.dg { display: block; width: 100%; height: auto; }
.dg text { font-family: var(--sans); }
.dg-tall { display: none; max-width: 26rem; margin: 0 auto; }
.dg-edge { fill: none; stroke: var(--dg-edge); stroke-width: 1.25; }
.dg-head { fill: var(--dg-edge); }
.dg-box { fill: none; stroke: var(--dg-edge); stroke-width: 1.25; }
.dg-main { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 2; }
.dg-team { fill: var(--tint); stroke: var(--dg-edge); stroke-width: 1; }
.dg-ink { fill: var(--text); }
.dg-quiet { fill: var(--muted); }
.diagram figcaption {
  margin-top: 0.75rem;
  text-align: center;
  font-size: 0.85em;
  color: var(--muted);
}
@media (max-width: 640px) {
  .dg-wide { display: none; }
  .dg-tall { display: block; }
}

/* Wide screens: contents become a sticky sidebar */
@media (min-width: 1180px) {
  .layout {
    max-width: calc(14rem + 4rem + var(--measure) + 2 * var(--gutter));
    display: grid;
    grid-template-columns: 14rem minmax(0, var(--measure));
    grid-template-areas: ". head" "toc main";
    column-gap: 4rem;
  }
  .masthead { grid-area: head; }
  main { grid-area: main; }
  .toc {
    grid-area: toc;
    align-self: start;
    position: sticky;
    top: 2rem;
    margin-top: 0.4rem;
    border-bottom: 0;
    font-size: 0.88em;
  }
}
