/*
 * Design tokens. Most visual changes should only need edits here.
 */
:root {
  --font-body: "Iowan Old Style", "Palatino Linotype", Charter, "Bitstream Charter", "Sitka Text", Cambria, Georgia, serif;
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --text-xs: 0.8125rem;
  --text-sm: 0.9375rem;
  --text-base: 1.125rem;
  --text-lg: 1.375rem;
  --text-xl: 1.75rem;
  --text-2xl: 2.25rem;
  --leading: 1.6;
  --leading-tight: 1.25;

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 1rem;
  --space-4: 1.5rem;
  --space-5: 2.5rem;
  --space-6: 4rem;

  --measure: 40rem;

  --bg: #fcfbf8;
  --text: #1f1d1a;
  --muted: #6d6860;
  --rule: #e6e2da;
  --accent: #4b2a9a;
  --accent-soft: #ece8f7;
  --code-bg: #f3f1ec;

  --attention: #8a6d1f;
  --danger: #9a3b2f;
  --pip-off: #d9d4cb;

  /* One-hue ramp for charts, low to high. Validated as an ordinal ramp
     against --bg in both schemes; keep that true when changing it. */
  --ramp-1: #a596e3;
  --ramp-2: #7d68d0;
  --ramp-3: #5a40b6;
  --ramp-4: #3a1f8c;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17161b;
    --text: #e9e6e0;
    --muted: #9c978e;
    --rule: #2d2b33;
    --accent: #b3a6f2;
    --accent-soft: #2a2540;
    --code-bg: #212026;

    --attention: #d8bd6a;
    --danger: #e08c7f;
    --pip-off: #4a4752;

    --ramp-1: #5a4aab;
    --ramp-2: #7765cf;
    --ramp-3: #9a8aec;
    --ramp-4: #c6bcfb;
  }
}

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

html {
  font-size: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0 auto;
  max-width: calc(var(--measure) + 2 * var(--space-4));
  padding: 0 var(--space-4);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--leading);
}

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

h1, h2, h3 { line-height: var(--leading-tight); font-weight: 600; }
h1 { font-size: var(--text-2xl); margin: 0 0 var(--space-2); }
h2 { font-size: var(--text-lg); margin: var(--space-5) 0 var(--space-3); }
h3 { font-size: var(--text-base); margin: var(--space-4) 0 var(--space-2); }

time, .count, .kind, .eyebrow, .byline, .more, .tags, .site-header, .site-footer, .facts {
  font-family: var(--font-ui);
}

.skip { position: absolute; left: -999px; }
.skip:focus { left: var(--space-3); top: var(--space-3); }

/*
 * Site chrome
 */
.site-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-2) var(--space-4);
  padding: var(--space-4) 0;
  margin-bottom: var(--space-5);
  border-bottom: 1px solid var(--rule);
}
.site-name { font-weight: 700; font-size: var(--text-lg); color: var(--text); text-decoration: none; }
.site-nav { display: flex; gap: var(--space-4); font-size: var(--text-sm); }
.site-nav a { color: var(--muted); text-decoration: none; }
.site-nav a:hover, .site-nav a.here { color: var(--text); }
.site-nav a.here { box-shadow: 0 2px 0 var(--accent); }

.site-footer {
  display: flex;
  gap: var(--space-4);
  margin-top: var(--space-6);
  padding: var(--space-4) 0 var(--space-5);
  border-top: 1px solid var(--rule);
  font-size: var(--text-sm);
}
.site-footer a { color: var(--muted); }

/*
 * Shared bits
 */
.eyebrow {
  margin: 0 0 var(--space-2);
  font-size: var(--text-xs);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.eyebrow a { color: inherit; text-decoration: none; }
.byline { margin: 0; color: var(--muted); font-size: var(--text-sm); }
.count, .kind { color: var(--muted); font-size: var(--text-xs); font-weight: 400; }
.kind { text-transform: uppercase; letter-spacing: 0.06em; }
.more { font-size: var(--text-sm); margin: var(--space-3) 0 0; }

/* Ratings are a count of filled pips, so they read without color. */
.rating { display: inline-flex; align-items: center; gap: var(--space-2); font-family: var(--font-ui); font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.pips { display: inline-flex; gap: 2px; }
.pips i { width: 7px; height: 7px; border-radius: 2px; background: var(--pip-off); }
.pips i.on { background: var(--text); }

.tags { display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-3); list-style: none; padding: 0; margin: var(--space-3) 0 0; font-size: var(--text-sm); }
.tags a { color: var(--muted); text-decoration: none; }
.tags a:hover { color: var(--accent); }

/*
 * Lists
 */
.book-list, .post-list, .mixed-list { list-style: none; padding: 0; margin: 0; }

/* Book rows share their list's columns (or a whole table of lists), so
   the right side is only as wide as its widest entry and lines up down the
   list: pips in one column, the rating word and date right-aligned. */
.book-list, .book-table { display: grid; grid-template-columns: 1fr auto auto; column-gap: var(--space-2); }
.book-table > * { grid-column: 1 / -1; }
.book-table > .book-list { grid-template-columns: subgrid; }
/* Grid items keep their margins, so drop the first heading's top margin. */
.book-table > :first-child { margin-top: 0; }
.book-row {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: subgrid;
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--rule);
}
.book-row .title { grid-column: 1; margin-right: var(--space-2); text-decoration: none; color: var(--text); }
.book-row .title:hover { color: var(--accent); }
.book-row .author { grid-column: 1; margin-right: var(--space-2); font-size: var(--text-sm); color: var(--muted); }
.book-row .rating { display: contents; }
.book-row .pips { grid-column: 2; grid-row: 1; align-self: center; }
.book-row .rating-word { grid-column: 3; grid-row: 1; justify-self: end; align-self: center; }
.book-row time { grid-column: 2 / 4; grid-row: 2; justify-self: end; white-space: nowrap; font-size: var(--text-xs); color: var(--muted); }

.post-row { padding: var(--space-3) 0; border-bottom: 1px solid var(--rule); }
.post-row .title { font-size: var(--text-lg); text-decoration: none; color: var(--text); }
.post-row .title:hover { color: var(--accent); }
.post-row time { display: block; font-size: var(--text-xs); color: var(--muted); }
.post-row .excerpt { margin: var(--space-2) 0 0; color: var(--muted); font-size: var(--text-sm); }

.mixed-list li { display: flex; gap: var(--space-3); align-items: baseline; padding: var(--space-2) 0; border-bottom: 1px solid var(--rule); }
.mixed-list .kind { width: 3.5rem; flex: none; }
.mixed-list time { margin-left: auto; font-size: var(--text-xs); color: var(--muted); }

.tag-cloud { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-4); }

.year h2, .year h3, h3.year { display: flex; align-items: baseline; gap: var(--space-2); }

/*
 * Index and home pages
 */
.index-header { margin-bottom: var(--space-5); }
.lede { margin: 0; color: var(--muted); }
.home-section h2 a, .index-section h2 a { color: inherit; text-decoration: none; }
.intro { font-size: var(--text-lg); }
.intro p:first-child { margin-top: 0; }

.atom { padding: var(--space-3) 0; border-bottom: 1px solid var(--rule); }
.atom .prose > :first-child { margin-top: 0; }
.atom .prose > :last-child { margin-bottom: var(--space-2); }
.atom-title { margin: 0 0 var(--space-2); font-size: var(--text-base); }
.atom-title a { color: inherit; text-decoration: none; }
.atom-title a:hover { color: var(--accent); }
.atom footer { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--space-3); font-size: var(--text-xs); color: var(--muted); }
.atom footer .tags { margin: 0; font-size: var(--text-xs); }

/*
 * Entries
 */
.entry-header { margin-bottom: var(--space-5); }
.entry-header h1 cite { font-style: italic; }

.facts {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-5);
  margin: var(--space-4) 0 0;
  padding: var(--space-3) 0;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
}
.facts dt { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.facts dd { margin: 0; font-size: var(--text-sm); }

.entry-footer { margin-top: var(--space-5); }

.backlinks { margin-top: var(--space-5); padding: var(--space-3) var(--space-4); background: var(--accent-soft); border-radius: 6px; }
.backlinks h2 { margin: 0 0 var(--space-2); font-size: var(--text-xs); font-family: var(--font-ui); text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.backlinks ul { list-style: none; margin: 0; padding: 0; }
.backlinks li { padding: var(--space-1) 0; }

/*
 * Prose: rendered markdown
 */
.prose img { max-width: 100%; height: auto; }
.prose blockquote { margin: var(--space-4) 0; padding-left: var(--space-3); border-left: 3px solid var(--rule); color: var(--muted); }
.prose code { font-family: var(--font-mono); font-size: 0.875em; background: var(--code-bg); padding: 0.1em 0.3em; border-radius: 3px; }
.prose pre { overflow-x: auto; padding: var(--space-3); background: var(--code-bg); border-radius: 6px; line-height: 1.45; }
.prose pre code { background: none; padding: 0; font-size: var(--text-xs); }
.prose table { border-collapse: collapse; width: 100%; font-size: var(--text-sm); }
.prose th, .prose td { text-align: left; padding: var(--space-1) var(--space-2); border-bottom: 1px solid var(--rule); }
.prose hr { border: none; border-top: 1px solid var(--rule); margin: var(--space-5) 0; }
.broken-ref { color: var(--danger); text-decoration: wavy underline; }

.draft { font-family: var(--font-ui); font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.06em; color: var(--attention); border: 1px solid currentColor; border-radius: 3px; padding: 0 0.3em; vertical-align: middle; }

.provenance { margin-top: var(--space-4); font-family: var(--font-ui); font-size: var(--text-xs); color: var(--muted); }
.provenance a { color: inherit; }
.revisions { list-style: none; padding: 0; margin: 0; }
.revisions li { display: grid; grid-template-columns: 7rem 1fr auto; gap: var(--space-3); align-items: baseline; padding: var(--space-2) 0; border-bottom: 1px solid var(--rule); font-size: var(--text-sm); }
.revisions time, .revisions .links { font-family: var(--font-ui); font-size: var(--text-xs); color: var(--muted); }
.revisions .links { display: flex; gap: var(--space-3); }
@media (max-width: 34rem) { .revisions li { grid-template-columns: 1fr auto; } .revisions .subject { grid-column: 1 / -1; grid-row: 2; } }

/*
 * Reading stats
 */
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.table-scroll { overflow-x: auto; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); gap: var(--space-3); margin: var(--space-5) 0; }
.kpi { display: flex; flex-direction: column; gap: var(--space-1); padding: var(--space-3) 0; border-top: 2px solid var(--text); font-family: var(--font-ui); }
.kpi-label { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.kpi-value { font-size: var(--text-2xl); font-weight: 600; line-height: 1.1; }
.kpi-note { font-size: var(--text-xs); color: var(--muted); }

.ledger, .heatmap { border-collapse: collapse; font-family: var(--font-ui); font-size: var(--text-sm); font-variant-numeric: tabular-nums; }
.ledger { width: 100%; }
.ledger th, .ledger td { padding: var(--space-1) var(--space-2); border-bottom: 1px solid var(--rule); text-align: left; vertical-align: middle; }
.ledger thead th { font-size: var(--text-xs); font-weight: 400; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.ledger tbody th { font-weight: 600; }
.ledger tbody th a { color: inherit; }
.ledger .num { text-align: right; white-space: nowrap; }
.ledger tr.empty td, .ledger tr.empty th { color: var(--muted); }
.ledger .bar-col { width: 24%; }
.ledger .rating-col { width: 20%; }
.bar-cell { display: flex; align-items: center; gap: var(--space-2); }
.bar-value { flex: none; min-width: 3.5rem; text-align: right; }
.bar-track { flex: 1; }
.bar { display: block; height: 10px; width: calc(var(--v) * 100%); border-radius: 0 4px 4px 0; background: var(--ramp-3); }

.stack { display: flex; gap: 2px; height: 10px; }
.seg { min-width: 2px; }
.seg:first-child { border-radius: 0; }
.seg:last-child { border-radius: 0 4px 4px 0; }
.r0 { background: var(--ramp-1); }
.r1 { background: var(--ramp-2); }
.r2 { background: var(--ramp-3); }
.r3 { background: var(--ramp-4); }

.heatmap th { font-weight: 400; color: var(--muted); font-size: var(--text-xs); padding: 0 var(--space-2) 0 0; text-align: right; }
.heatmap thead th { text-align: center; padding: 0 0 var(--space-1); }
.heatmap abbr { text-decoration: none; }
.heatmap { width: 100%; table-layout: fixed; }
.heatmap th:first-child { width: 3rem; }
.heatmap td { height: 1.5rem; padding: 0; border: 2px solid var(--bg); border-radius: 4px; }
.heatmap .q0 { background: var(--rule); }
.heatmap .q1, .legend .q1 { background: var(--ramp-1); }
.heatmap .q2, .legend .q2 { background: var(--ramp-2); }
.heatmap .q3, .legend .q3 { background: var(--ramp-3); }
.heatmap .q4, .legend .q4 { background: var(--ramp-4); }
.legend .q0 { background: var(--rule); }
.heatmap .future { background: transparent; }

.legend { display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-3); list-style: none; padding: 0; margin: var(--space-2) 0 0; font-family: var(--font-ui); font-size: var(--text-xs); color: var(--muted); }
.legend li { display: flex; align-items: center; gap: var(--space-1); }
.swatch { display: inline-block; width: 0.75rem; height: 0.75rem; border-radius: 3px; }

.columns { display: grid; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); gap: 0 var(--space-5); }
.ranked { padding-left: 1.5em; margin: 0; }
.ranked li { padding: var(--space-1) 0; }
.ranked-value { font-family: var(--font-ui); font-size: var(--text-xs); color: var(--muted); white-space: nowrap; }
