/* The whole stylesheet. Grayscale only, system fonts, one readable column.
   Type: one size for all body text (1.0625rem), one per heading level. Secondary text is grey, not smaller. */

/* Theme: follows the system until the visitor uses the toggle (theme.js sets data-theme). */
:root { --text: #111; --muted: #5c5c5c; --rule: #d9d9d9; --bg: #fff; --light-only: block; --dark-only: none; --image-filter: none; color-scheme: light; }
:root[data-theme="dark"] { --text: #e6e6e6; --muted: #a3a3a3; --rule: #3a3a3a; --bg: #121212; --light-only: none; --dark-only: block; --image-filter: brightness(0.82); color-scheme: dark; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --text: #e6e6e6; --muted: #a3a3a3; --rule: #3a3a3a; --bg: #121212; --light-only: none; --dark-only: block; --image-filter: brightness(0.82); color-scheme: dark; }
}

* { box-sizing: border-box; }
/* scroll-padding keeps #anchor targets clear of the sticky header. */
html { overflow-x: clip; scroll-padding-top: 7.5rem; }

body {
  max-width: 40rem;            /* ~70 characters per line */
  margin: 0 auto;
  padding: 0 1.25rem 4rem;
  font: 1.0625rem/1.65 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}

a { color: inherit; text-underline-offset: 0.2em; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid currentColor; outline-offset: 3px; }

/* Sticky header. The box-shadow and clip-path extend its background to the window edges, so wide
   figures never show through beside it. */
header {
  position: sticky; top: 0; z-index: 1;
  padding: 1.5rem 0 0.75rem; margin-bottom: 3rem;
  background: var(--bg); box-shadow: 0 0 0 100vmax var(--bg); clip-path: inset(0 -100vmax);
  border-bottom: 1px solid var(--rule);
}
header .name { display: block; font-size: 1.5rem; font-weight: 700; line-height: 1.2; text-decoration: none; margin-bottom: 0.5rem; }
header nav { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.15rem 0.9rem; }
/* The current page is bold. Each link reserves the width of its bold text (the hidden ::after), so
   switching pages never shifts the other links. */
header nav a { display: inline-flex; flex-direction: column; white-space: nowrap; }
header nav a::after { content: attr(data-label); font-weight: 600; height: 0; overflow: hidden; visibility: hidden; user-select: none; }
header nav a[aria-current="page"] { text-decoration: none; font-weight: 600; }

/* An icon pinned to the top-right corner of the header, level with the name, so it never competes with the links for room. */
.theme-toggle { position: absolute; top: 1.4rem; right: 0; display: inline-flex; align-items: center; justify-content: center; width: 2rem; height: 2rem; padding: 0; color: var(--muted); background: none; border: 0; cursor: pointer; }
.theme-toggle[hidden] { display: none; }
.theme-toggle:hover { color: var(--text); }
.theme-toggle svg { width: 1.25rem; height: 1.25rem; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
/* A moon in light mode (switch to dark), a sun in dark mode (switch to light). */
.icon-moon { display: var(--light-only); }
.icon-sun { display: var(--dark-only); }

h1 { font-size: 1.75rem; line-height: 1.25; margin: 0 0 0.75rem; }
h2 { font-size: 1.25rem; margin: 3rem 0 1rem; }
h3 { font-size: 1.0625rem; margin: 0; }
p, ul, ol { margin: 0 0 1rem; }
/* Browsers shrink monospace text by default; keep code at the body size. */
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 1em; }
/* Long inline code wraps instead of running off a narrow screen; code blocks scroll sideways instead. */
code { overflow-wrap: anywhere; }
pre { overflow-x: auto; }
pre code { overflow-wrap: normal; }
ul, ol { padding-left: 1.25rem; }
li { margin-bottom: 0.35rem; }

.muted, .meta { color: var(--muted); }
.meta { margin: 0.1rem 0 0.4rem; }
.entry { margin-bottom: 2rem; }

.table { overflow-x: auto; margin: 0 0 1.5rem; }
figure .table { margin: 0; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; vertical-align: top; padding: 0.4rem 0.75rem 0.4rem 0; border-bottom: 1px solid var(--rule); }

/* Figures fill the column; wide ones (plots) extend up to 60rem so their labels stay readable. */
/* Breadcrumbs: the path from the home page to this page. The current page is the last item, cut short with an
   ellipsis when its title is long, so the trail stays on one line. */
.crumbs ol { display: flex; align-items: baseline; margin: 0 0 0.4rem; padding: 0; list-style: none; color: var(--muted); }
.crumbs li { margin: 0; white-space: nowrap; }
.crumbs li + li::before { content: "/"; margin: 0 0.5em; }
/* The first item is the home page, drawn as a slash that starts the path ("/ Projects / ..."), so the next item
   needs no separator of its own. Its link is padded (and the margins cancel the padding, so nothing moves) so the small
   slash is easy to tap. */
.crumbs li:first-child + li::before { content: none; }
.crumbs li:first-child a { display: inline-block; padding: 0.25em 0.75em 0.25em 0.5em; margin: 0 -0.25em 0 -0.5em; text-decoration: none; }
.crumbs li:first-child a:hover { text-decoration: underline; }
.crumbs li:last-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; }

figure { margin: 2rem 0; }
figure img { display: block; width: 100%; height: auto; }
/* Figures that have no dark variant (no light-only/dark-only class) are dimmed in dark mode, so a white plot doesn't glare. */
figure img:not([class]) { filter: var(--image-filter); }
figure.wide { margin-inline: calc(50% - min(30rem, 50vw - 1.25rem)); }
figcaption { max-width: 37.5rem; margin: 0.5rem auto 0; color: var(--muted); }
.light-only { display: var(--light-only); }
.dark-only { display: var(--dark-only); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.num { white-space: nowrap; }

/* Previous and next each get half the width, so long titles wrap within their own side. */
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; margin-top: 3rem; padding-top: 1.25rem; border-top: 1px solid var(--rule); }
.pager a { text-decoration: none; }
.pager a span:last-child { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 0.2em; }
.pager a:hover span:last-child { text-decoration-thickness: 2px; }
.pager .label { display: block; color: var(--muted); }
.pager .next { grid-column: 2; text-align: right; }

footer { margin-top: 4.5rem; padding-top: 1.25rem; border-top: 1px solid var(--rule); color: var(--muted); }

/* Phones: the header scrolls away with the page (relative, not sticky), since a sticky one would take a sixth of the screen. */
@media (max-width: 30rem) {
  html { scroll-padding-top: 1rem; }
  header { position: relative; padding-top: 1rem; margin-bottom: 2rem; }
  header .name { font-size: 1.3rem; margin-bottom: 0.35rem; }
  header nav { gap: 0.1rem 0.75rem; }
  .theme-toggle { top: 0.75rem; }
}

@media print { header { position: static; border: 0; } header nav, footer, .pager { display: none; } body { max-width: none; } }
