/* One stylesheet, hand-written, no framework.
   Light and dark are the same design with the ink and paper swapped. */

:root {
  --paper: #fdfdfc;
  --ink: #1a1a18;
  --muted: #6a6a64;
  --rule: #e2e1dc;
  --slab: #f4f3ef;
  --link: #1c5d99;
  --accent: #9c4221;
  --measure: 34rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #16171a;
    --ink: #e6e5e0;
    --muted: #9a998f;
    --rule: #2c2e33;
    --slab: #1e2024;
    --link: #7fb2e0;
    --accent: #e08a5c;
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  display: grid;
  grid-template-columns: 17rem minmax(0, 1fr);
  align-items: start;
}

.skip {
  position: absolute;
  left: -9999px;
}
.skip:focus {
  left: 1rem;
  top: 1rem;
  background: var(--paper);
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--rule);
  z-index: 2;
}

/* ---- sidebar ---- */

#sidebar {
  position: sticky;
  top: 0;
  max-height: 100vh;
  overflow-y: auto;
  padding: 2rem 1.25rem 3rem 1.75rem;
  border-right: 1px solid var(--rule);
  font-size: 0.9rem;
}

.brand {
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
  text-decoration: none;
}

.tagline {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
  margin: 0.4rem 0 1.75rem;
}

#sidebar h2 {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted);
  font-weight: 600;
  margin: 1.5rem 0 0.5rem;
}

#sidebar ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

#sidebar li { margin: 0.1rem 0; }

#sidebar li a {
  display: block;
  padding: 0.2rem 0.5rem;
  margin-left: -0.5rem;
  border-radius: 4px;
  color: var(--ink);
  text-decoration: none;
}

#sidebar li a:hover { background: var(--slab); }

#sidebar li a.here {
  color: var(--accent);
  font-weight: 600;
  background: var(--slab);
}

.source {
  margin-top: 2.5rem;
  font-size: 0.8rem;
}

/* ---- content ---- */

/* Prose keeps a reading measure; tables and code get the whole column, which
   is what stops a paper's citation from wrapping four times in a cell. */
main {
  padding: 3rem 2.5rem 6rem;
  max-width: 62rem;
  min-width: 0;
}

main > * { max-width: var(--measure); }
main > table, main > pre { max-width: none; width: 100%; }

h1 {
  font-size: 2rem;
  line-height: 1.2;
  letter-spacing: -0.02em;
  margin: 0 0 1.25rem;
}

h2 {
  font-size: 1.3rem;
  letter-spacing: -0.01em;
  margin: 2.75rem 0 0.85rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--rule);
}

h3 {
  font-size: 1.05rem;
  margin: 2rem 0 0.6rem;
}

p, ul, ol { margin: 0 0 1rem; }

a { color: var(--link); }
a:hover { text-decoration-thickness: 2px; }

/* The citation under a page title. */
blockquote {
  margin: 0 0 1.75rem;
  padding: 0.1rem 0 0.1rem 1rem;
  border-left: 3px solid var(--rule);
  color: var(--muted);
  font-size: 0.92rem;
}
blockquote p { margin: 0.35rem 0; }

code {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.875em;
  background: var(--slab);
  /* Tight sides: wider padding reads as a space before a following comma. */
  padding: 0.1em 0.2em;
  border-radius: 3px;
}

pre {
  background: var(--slab);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 0.9rem 1.1rem;
  overflow-x: auto;
  line-height: 1.5;
}

pre code {
  background: none;
  padding: 0;
  font-size: 0.83rem;
}

/* Figures: the charts are SVG, and carry their own light and dark palettes.
   Markdown wraps a lone image in a paragraph, which the prose measure would
   otherwise squeeze to 34rem — so a paragraph holding one gives that up. */
main > p:has(img) { max-width: none; }

main img {
  display: block;
  width: 100%;
  max-width: 46rem;
  height: auto;
  margin: 0 0 1.5rem;
  border: 1px solid var(--rule);
  border-radius: 6px;
}

table {
  border-collapse: collapse;
  margin: 0 0 1.5rem;
  font-size: 0.9rem;
  /* Block, so a table wider than the column scrolls itself rather than
     widening the page. */
  display: block;
  overflow-x: auto;
}

th, td {
  border-bottom: 1px solid var(--rule);
  padding: 0.45rem 0.9rem 0.45rem 0;
  text-align: left;
  vertical-align: top;
}

th {
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

/* Numeric columns the Markdown right-aligns come through as inline styles,
   which win on their own. The padding has to swap sides with the text, or
   right-aligned neighbours end up with no gutter between them at all. */
th[style*="right"], td[style*="right"] { padding-right: 0; padding-left: 1.2rem; }

li { margin: 0.25rem 0; }

hr { border: 0; border-top: 1px solid var(--rule); margin: 2.5rem 0; }

/* ---- narrow screens: the sidebar becomes a header ---- */

@media (max-width: 52rem) {
  body { display: block; }
  #sidebar {
    position: static;
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid var(--rule);
    padding: 1.5rem 1.25rem;
  }
  #sidebar h2 { margin-top: 1rem; }
  main { padding: 2rem 1.25rem 4rem; }
}
