/*
  The white design.
  Committed to a single light world on purpose: the palette, the paper ground
  and the ink are all painted explicitly, so the page holds the same look
  whatever theme the reader's device is set to.
*/

:root {
  --paper:     #F3F5F0;
  --card:      #FFFFFF;
  --ink:       #16211C;
  --muted:     #66756B;
  --green:     #3D6B4F;
  --green-tint: rgba(61,107,79,.14);
  --loss:      #B4451F;
  --water:     #4E7B96;
  --water-tint: rgba(78,123,150,.16);
  --rule:      #D6DCD4;
  --rule-soft: #E6EAE3;
  --grid:      rgba(61,107,79,.10);
  --tint:      rgba(61,107,79,.05);
  --map-ground:#E7EBE2;
  --halo:      #F6F8F3;

  /* Era shading for time-coloured data maps. These live here rather than in a
     post because a colour that is only defined in one post's <style> resolves
     to black the moment the post is copied, reused, or its style block is
     trimmed - which is exactly what happened the first time.

     Sequential, light to dark with time. The first version of this ramp ran
     #77543F / #B4451F / #E2732E, whose first two steps sit 11.5 apart in
     normal vision - under the 15 below which two classes stop being tellable
     apart, and 4.4 for a protanopic reader. These three are 20.1 apart at
     their closest, and monotonic in lightness so the order reads without the
     legend. They must stay in step with scripts/maps_story.py in the
     analysis repo, which paints the same classes into the map images. */
  --era1:      #F0B36A;
  --era2:      #C9651F;
  --era3:      #7C2A12;

  --display: "Bricolage Grotesque", "Helvetica Neue", Arial, sans-serif;
  --body:    "Source Serif 4", Georgia, "Times New Roman", serif;
  --mono:    "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --measure: 62ch;
  --pad: clamp(1.15rem, 4vw, 2rem);
}

* { box-sizing: border-box; }

html { color-scheme: light; }

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--body);
  font-size: 18px;
  line-height: 1.68;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 46rem; margin: 0 auto; padding: 0 var(--pad); }

a { color: var(--ink); text-decoration-color: var(--green); text-underline-offset: .18em; }
a:hover { color: var(--green); }
a:focus-visible { outline: 2px solid var(--green); outline-offset: 3px; }

.eyebrow {
  font-family: var(--mono); font-size: .705rem; letter-spacing: .13em;
  text-transform: uppercase; color: var(--muted); margin: 0;
}

/* ---------- site header ---------- */

.masthead {
  border-bottom: 1px solid var(--rule);
  background:
    repeating-linear-gradient(to right,  var(--grid) 0 1px, transparent 1px 64px),
    repeating-linear-gradient(to bottom, var(--grid) 0 1px, transparent 1px 64px),
    var(--card);
}
.masthead .wrap {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 1rem 2rem; flex-wrap: wrap;
  padding-top: 1.5rem; padding-bottom: 1.5rem;
}
.masthead .brand {
  font-family: var(--display); font-weight: 800; font-size: 1.15rem;
  letter-spacing: -.015em; text-decoration: none; color: var(--ink);
}
.masthead .brand:hover { color: var(--green); }
.masthead nav { display: flex; gap: 1.35rem; }
.masthead nav a {
  font-family: var(--mono); font-size: .74rem; letter-spacing: .07em;
  text-transform: uppercase; color: var(--muted); text-decoration: none;
}
.masthead nav a:hover { color: var(--green); }

/* ---------- index ---------- */

.intro { border-bottom: 1px solid var(--rule); background: var(--card); }
.intro .wrap {
  display: flex; flex-direction: column; gap: 1rem;
  padding-top: clamp(2.5rem, 7vw, 4rem);
  padding-bottom: clamp(2rem, 5vw, 3rem);
}
.intro h1 {
  font-family: var(--display); font-weight: 800;
  font-size: clamp(2rem, 6.5vw, 3rem); line-height: 1.05;
  letter-spacing: -.022em; text-wrap: balance; margin: 0;
}
.intro p { max-width: var(--measure); margin: 0; font-size: clamp(1.04rem, 2.5vw, 1.15rem); }

.postlist { padding: clamp(2rem, 5vw, 3rem) 0 1rem; }
.postlist ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 0; }
.postlist li { border-top: 1px solid var(--rule-soft); }
.postlist li:first-child { border-top: 0; }
.postlist article { padding: clamp(1.5rem, 4vw, 2.15rem) 0; display: grid; gap: .55rem; }
.postlist h2 {
  font-family: var(--display); font-weight: 700;
  font-size: clamp(1.3rem, 3.6vw, 1.65rem); line-height: 1.15;
  letter-spacing: -.015em; margin: 0; text-wrap: balance; max-width: 30ch;
}
.postlist h2 a { text-decoration: none; }
.postlist h2 a:hover { text-decoration: underline; text-decoration-color: var(--green); }
.postlist .meta {
  font-family: var(--mono); font-size: .72rem; letter-spacing: .06em;
  text-transform: uppercase; color: var(--muted);
  display: flex; gap: .55rem; flex-wrap: wrap;
}
.postlist .meta span::after { content: "·"; margin-left: .55rem; color: var(--rule); }
.postlist .meta span:last-child::after { content: ""; margin: 0; }
.postlist p.dek { margin: 0; max-width: var(--measure); color: var(--ink); }

/* ---------- post ---------- */

.posthead { border-bottom: 1px solid var(--rule); background: var(--card); }
.posthead .wrap {
  display: flex; flex-direction: column; gap: 1.1rem;
  padding-top: clamp(2.5rem, 7vw, 4.25rem);
  padding-bottom: clamp(2rem, 5vw, 3rem);
}
.posthead h1 {
  font-family: var(--display); font-weight: 800;
  font-size: clamp(2.1rem, 7vw, 3.4rem); line-height: 1.03;
  letter-spacing: -.024em; text-wrap: balance; margin: 0;
}
.posthead .dek {
  font-size: clamp(1.06rem, 2.6vw, 1.22rem); line-height: 1.55;
  max-width: var(--measure); margin: 0;
}

article.post { padding: clamp(2rem, 5vw, 3rem) 0 1rem; }
article.post > .wrap > * { max-width: var(--measure); }
article.post > .wrap > figure { max-width: none; }

/* A `full: true` post supplies its own .wrap containers, so constrain the
   measure inside those rather than on the article's direct children. */
article.post.full { padding-top: 0; }
article.post.full .wrap > * { max-width: var(--measure); }
article.post.full .wrap > figure { max-width: none; }

article.post h2 {
  font-family: var(--display); font-weight: 700;
  font-size: clamp(1.45rem, 4.2vw, 1.95rem); line-height: 1.14;
  letter-spacing: -.016em; text-wrap: balance;
  margin: clamp(2.2rem, 5.5vw, 3rem) 0 0; max-width: 27ch;
}
article.post h3 {
  font-family: var(--display); font-weight: 700; font-size: 1.15rem;
  margin: 2rem 0 0; letter-spacing: -.008em;
}
article.post p { margin: 1.05rem 0 0; }
article.post ul, article.post ol { margin: 1.05rem 0 0; padding-left: 1.3rem; }
article.post li { margin-top: .4rem; }
article.post blockquote {
  margin: 1.5rem 0 0; padding-left: 1.1rem;
  border-left: 3px solid var(--green); font-weight: 600;
  font-size: clamp(1.06rem, 2.5vw, 1.18rem); line-height: 1.5;
}
article.post blockquote p { margin: 0; }
article.post blockquote p + p { margin-top: .7rem; }
article.post hr { border: 0; border-top: 1px solid var(--rule); margin: 2.5rem 0 0; }

article.post code {
  font-family: var(--mono); font-size: .86em;
  background: var(--tint); padding: .12em .35em; border-radius: 2px;
}
article.post pre {
  margin: 1.4rem 0 0; padding: 1rem 1.15rem; overflow-x: auto;
  background: var(--card); border: 1px solid var(--rule);
}
article.post pre code { background: none; padding: 0; font-size: .82rem; line-height: 1.6; }

article.post img { max-width: 100%; height: auto; display: block; }

/* figures, shared with anything a post embeds */
figure {
  margin: 1.6rem 0 0; background: var(--card);
  border: 1px solid var(--rule); padding: 1rem 1rem 1.1rem;
}
figcaption {
  font-family: var(--mono); font-size: .73rem; line-height: 1.6;
  color: var(--muted); margin-top: .8rem; max-width: var(--measure);
}
figure svg { display: block; width: 100%; height: auto; }

.legend {
  display: flex; flex-wrap: wrap; gap: .5rem 1.15rem;
  margin-top: .75rem; font-family: var(--mono); font-size: .72rem; color: var(--muted);
}
.legend span { display: inline-flex; align-items: center; gap: .45rem; }
.legend i { width: .8rem; height: .8rem; display: inline-block; }
.legend i.line { height: 0; border-top: 2px solid var(--green); }
/* a line swatch whose colour is set inline, for legends that name several
   boundaries; .dash matches an outline drawn dashed on the map */
.legend i.ln { height: 0; border-top: 2px solid currentColor; align-self: center; }
.legend i.ln.dash { border-top-style: dashed; }

.tablewrap { margin: 1.5rem 0 0; overflow-x: auto; border: 1px solid var(--rule); background: var(--card); }
article.post table { border-collapse: collapse; width: 100%; font-size: .9rem; }
article.post th, article.post td {
  padding: .5rem 1rem; text-align: left; border-top: 1px solid var(--rule-soft);
}
article.post th {
  font-family: var(--mono); font-weight: 500; font-size: .69rem;
  letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
}
.num, article.post td.n, article.post th.n {
  font-family: var(--mono); font-variant-numeric: tabular-nums; font-weight: 600;
}
article.post td.n, article.post th.n { text-align: right; }

.callout {
  background: var(--card); border: 1px solid var(--rule);
  border-left: 3px solid var(--loss);
  padding: 1.15rem 1.25rem 1.3rem; margin: 1.5rem 0 0; max-width: var(--measure);
}
.callout h3 { font-family: var(--display); font-weight: 700; font-size: 1.05rem; margin: 0 0 .55rem; }
.callout p { margin: .65rem 0 0; font-size: .97rem; }
.callout p:first-of-type { margin-top: 0; }

.note { border-top: 1px solid var(--rule); margin-top: clamp(2.2rem, 6vw, 3.25rem); background: var(--tint); }
.note .wrap { padding-top: clamp(1.9rem, 5vw, 2.6rem); padding-bottom: 1.4rem; }
.note h2 { font-family: var(--display); font-weight: 700; font-size: clamp(1.25rem, 3.5vw, 1.55rem); margin: .45rem 0 0; }
.note p { max-width: var(--measure); margin: .95rem 0 0; font-size: .98rem; }
.note dl { margin: 1.5rem 0 0; border-top: 1px solid var(--rule); max-width: var(--measure); }
.note dt {
  font-family: var(--mono); font-size: .69rem; letter-spacing: .1em;
  text-transform: uppercase; color: var(--muted); padding-top: .95rem;
}
.note dd { margin: .35rem 0 0; padding-bottom: .95rem; border-bottom: 1px solid var(--rule); font-size: .95rem; }

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

footer.site { border-top: 1px solid var(--rule); margin-top: clamp(2.5rem, 6vw, 3.5rem); padding: 1.6rem 0 3rem; }
footer.site .wrap { display: flex; justify-content: space-between; gap: 1rem 2rem; flex-wrap: wrap; }
footer.site p {
  font-family: var(--mono); font-size: .71rem; line-height: 1.7;
  color: var(--muted); margin: 0; max-width: var(--measure);
}
footer.site a { color: var(--muted); }

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

/* ---------- long-form extras ---------- */

::selection { background: var(--green-tint); }
article.post p { text-wrap: pretty; }
.part { scroll-margin-top: 1.5rem; }

/* figure numbers */
figcaption .fig { color: var(--ink); font-weight: 600; }

/* contents strip at the top of a long piece: one flowing line of links
   between hairlines. The earlier version was a two-column card of mono
   titles - it ate half a screen and wrapped raggedly. */
.toc {
  margin-top: clamp(2rem, 5vw, 2.75rem);
  padding: 1rem 0 1.1rem; max-width: var(--measure);
  border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule);
}
.toc-label {
  display: block; font-family: var(--mono); font-size: .67rem;
  letter-spacing: .14em; text-transform: uppercase; color: var(--muted);
  margin-bottom: .45rem;
}
.toc p { margin: 0; font-size: .95rem; line-height: 1.95; }
.toc a { text-decoration: none; color: var(--ink); }
.toc a:hover { color: var(--green); text-decoration: underline; text-decoration-color: var(--green); }
.toc a b {
  font-family: var(--mono); font-weight: 600; font-size: .74em;
  color: var(--green); margin-right: .1rem;
}
.toc .s { color: var(--rule); margin: 0 .5rem; user-select: none; }

/* vertical timeline */
.timeline { display: grid; margin-top: .3rem; }
.timeline .ev {
  display: grid; grid-template-columns: 4.6rem 1fr; gap: 1.3rem;
  position: relative; padding: .5rem 0;
}
.timeline .ev::before {
  content: ""; position: absolute; left: 5.25rem; top: 0; bottom: 0;
  width: 2px; background: var(--rule);
}
.timeline .ev:first-child::before { top: .95rem; }
.timeline .ev:last-child::before { bottom: auto; height: .95rem; }
.timeline .ev::after {
  content: ""; position: absolute; left: 5.25rem; top: .82rem;
  width: 9px; height: 9px; transform: translateX(-3.5px);
  background: var(--green); border-radius: 50%;
}
.timeline .ev.loss::after { background: var(--loss); }
.timeline .y {
  font-family: var(--mono); font-size: .8rem; font-weight: 600;
  text-align: right; padding-top: .1rem;
}
.timeline .t { font-size: .95rem; line-height: 1.55; padding-left: .55rem; }

/* one square of ground through the years (the four-year rule) */
.trace-wrap { display: grid; gap: 1.5rem; margin-top: .3rem; }
.trace-lab {
  font-family: var(--mono); font-size: .71rem; letter-spacing: .09em;
  text-transform: uppercase; color: var(--muted); margin: 0 0 .5rem;
}
.trace { display: flex; gap: 3px; }
.trace i {
  flex: 1; aspect-ratio: 1;
  background: var(--green-tint);
  border: 1px solid color-mix(in srgb, var(--green) 35%, transparent);
}
.trace i.b { background: var(--loss); border-color: var(--loss); }
.trace-yrs {
  display: flex; justify-content: space-between;
  font-family: var(--mono); font-size: .68rem; color: var(--muted);
  margin-top: .35rem;
}
.trace-verdict { margin: .55rem 0 0; font-size: .93rem; font-weight: 600; }
.trace-verdict.ok { color: var(--green); }
.trace-verdict.no { color: var(--loss); }

/* three big numbers in a row */
.stats3 {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 12rem), 1fr));
  border: 1px solid var(--rule); background: var(--card);
  margin-top: 1.5rem; overflow: hidden;
}
/* separators as per-cell borders, not grid gaps: with a gap-and-background
   grid, an uneven wrap (three cells in a 2x2 grid) paints the empty cell in
   the separator colour, a grey block that looks like a broken tile */
.stats3 > div {
  padding: 1rem 1.1rem 1.1rem;
  border-top: 1px solid var(--rule-soft);
  border-left: 1px solid var(--rule-soft);
  margin: -1px 0 0 -1px;
}
.stats3 .n {
  font-family: var(--mono); font-weight: 600; font-variant-numeric: tabular-nums;
  font-size: clamp(1.35rem, 4vw, 1.7rem); line-height: 1.15;
  color: var(--loss); display: block;
}
.stats3 .u {
  font-family: var(--mono); font-size: .69rem; letter-spacing: .06em;
  text-transform: uppercase; color: var(--muted); display: block; margin-top: .45rem;
}

/* wider value column, for bars labelled with signed percentages */
.roads.wide .r { grid-template-columns: minmax(7.5rem, 11rem) 1fr 4.3rem; }

/* north arrow on data maps */
.m-north path { fill: var(--ink); }
.m-north line { stroke: var(--ink); stroke-width: .7; }
.m-north text { font: 600 5.2px var(--mono); fill: var(--ink); }

/* a .note directly after a .note reads as one block */
.note + .note { margin-top: 0; border-top: 0; }
.note + .note .wrap { padding-top: 0; }
.note + .note p {
  font-family: var(--mono); font-size: .72rem; line-height: 1.7;
  color: var(--muted); border-top: 1px solid var(--rule);
  padding-top: 1.1rem; margin-top: .4rem;
}

/* collapsible technical notes: the main text stays a story; the
   instruments, rule parameters and exact figures behind a claim are one
   tap away for the reader who wants them */
details.tech {
  margin: 1.5rem 0 0; max-width: var(--measure);
  border: 1px solid var(--rule); background: var(--card);
}
details.tech summary {
  cursor: pointer; list-style: none;
  display: flex; align-items: baseline; gap: .6rem;
  padding: .78rem 1.05rem .82rem;
  font-family: var(--mono); font-size: .71rem; letter-spacing: .09em;
  text-transform: uppercase; color: var(--muted);
}
details.tech summary::-webkit-details-marker { display: none; }
details.tech summary::before {
  content: "+"; font-weight: 600; font-size: .95rem; line-height: 1;
  color: var(--green); flex: none;
}
details.tech[open] summary::before { content: "\2212"; }
details.tech summary:hover { color: var(--green); }
details.tech .inner { padding: 0 1.05rem 1.1rem; border-top: 1px solid var(--rule-soft); }
details.tech .inner p { margin: .85rem 0 0; font-size: .92rem; line-height: 1.62; }

/* a map image that can be opened at full size: the picture is reduced to
   about a third of its pixels in the column, so a reader who wants to find
   their own street needs the original */
.zoom { display: block; text-decoration: none; }
.zoom:focus-visible { outline: 2px solid var(--green); outline-offset: 3px; }

/* the figure lightbox (static/lightbox.js). Without the script the .zoom
   link still opens the image on its own page, so none of this is required
   for a figure to work - it is the in-page version. */
html.lb-open { overflow: hidden; }

dialog.lightbox {
  /* fit-content, not auto: a dialog sized to its max-width leaves white
     bands either side of a picture that is height-constrained */
  margin: auto; padding: 0; border: 0; width: fit-content;
  max-width: 96vw; max-height: 94vh;
  background: var(--card); color: var(--ink);
  box-shadow: 0 18px 60px rgba(22, 33, 28, .28);
}
/* ::backdrop cannot be relied on to see the custom properties on :root in
   every engine, so this one colour is written out: it is --ink at 82%. */
dialog.lightbox::backdrop { background: rgba(22, 33, 28, .82); }
/* The picture is sized by height, not width, and the frame scrolls. On a
   desktop that fits and nothing scrolls; on a phone, where fitting the
   width would show the map at the size it already is in the column, the
   reader gets a genuinely bigger picture to pan and pinch instead. */
dialog.lightbox .lb-frame {
  overflow: auto; max-width: 96vw; touch-action: pinch-zoom pan-x pan-y;
  overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
}
dialog.lightbox .lb-frame:focus-visible { outline: 2px solid var(--green); outline-offset: -2px; }
dialog.lightbox img {
  display: block; max-width: none; max-height: 78vh;
  height: 78vh; width: auto; margin: 0 auto;
}
dialog.lightbox .lb-cap {
  font-family: var(--mono); font-size: .73rem; line-height: 1.6;
  color: var(--muted); margin: 0; padding: .85rem 1rem 1rem;
  max-width: 68ch; border-top: 1px solid var(--rule-soft);
}
.lb-close {
  position: absolute; top: .5rem; right: .5rem; z-index: 2;
  width: 2rem; height: 2rem; padding: 0; cursor: pointer;
  display: grid; place-items: center;
  font-family: var(--mono); font-size: 1.15rem; line-height: 1;
  color: var(--ink); background: var(--card);
  border: 1px solid var(--rule);
}
.lb-close:hover { background: var(--paper); color: var(--green); }
.lb-close:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

/* a boxed pointer to something that lives elsewhere - a repository, a dataset */
.linkcard {
  margin: 1.7rem 0 0; max-width: var(--measure);
  border: 1px solid var(--rule); border-left: 3px solid var(--green);
  background: var(--card); padding: 1.2rem 1.3rem 1.35rem;
}
.linkcard h3 { font-family: var(--display); font-weight: 700; font-size: 1.12rem; margin: .5rem 0 0; }
.linkcard p { margin: .7rem 0 0; font-size: .95rem; }
.linkcard .go {
  display: inline-block; margin-top: 1rem; padding: .55rem .9rem;
  font-family: var(--mono); font-size: .76rem; font-weight: 600; letter-spacing: .05em;
  color: var(--card); background: var(--green); text-decoration: none;
}
.linkcard .go:hover, .linkcard .go:focus-visible { background: var(--ink); color: var(--card); }

/* reading progress along the top edge. CSS scroll timelines only - a
   browser without them simply never shows the bar, and the global
   reduced-motion rule above disables it with everything else. */
@supports (animation-timeline: scroll()) {
  .readbar {
    position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 20;
    background: var(--green); transform-origin: 0 50%; transform: scaleX(0);
    animation: readgrow linear both; animation-timeline: scroll(root);
  }
  @keyframes readgrow { to { transform: scaleX(1); } }
}

@media (prefers-reduced-motion: no-preference) { html { scroll-behavior: smooth; } }

/* print: the article, not the chrome */
@media print {
  .masthead nav, footer.site, .toc, .readbar, details.tech,
  dialog.lightbox { display: none; }
  figure { break-inside: avoid; }
  body { background: #fff; }
}
