/* Shared stylesheet for the homepage, posts and 404.
   Tokens and base rules match the explainers (paper-editorial). Light only, like the explainers. */

@font-face { font-family: "Newsreader"; font-style: normal; font-weight: 400; font-display: swap; src: url("/assets/fonts/newsreader-400.woff2") format("woff2"); }
@font-face { font-family: "Newsreader"; font-style: normal; font-weight: 500; font-display: swap; src: url("/assets/fonts/newsreader-500.woff2") format("woff2"); }
@font-face { font-family: "Newsreader"; font-style: normal; font-weight: 600; font-display: swap; src: url("/assets/fonts/newsreader-600.woff2") format("woff2"); }
@font-face { font-family: "Newsreader"; font-style: italic; font-weight: 300 400; font-display: swap; src: url("/assets/fonts/newsreader-400-italic.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Sans"; font-style: normal; font-weight: 400; font-display: swap; src: url("/assets/fonts/plex-sans-400.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Sans"; font-style: normal; font-weight: 500; font-display: swap; src: url("/assets/fonts/plex-sans-500.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Sans"; font-style: normal; font-weight: 600; font-display: swap; src: url("/assets/fonts/plex-sans-600.woff2") format("woff2"); }

:root {
  color-scheme: light;

  --paper: #f4efe5;
  --plate: #ebe4d6;
  --plate-2: #e0d7c5;
  --page: #fbf8f1;
  --rule: #cbbfa9;
  --ink: #1d1a15;
  --ink-2: #4f483d;
  --ink-3: #6f675a;
  --ochre: #a86b12;
  --ochre-ink: #8a560c;
  --slate: #33628f;
  --green: #1f7357;
  --danger: #b23a2a;
  --selection: #e7cf9a;

  --font-serif: "Newsreader", "Iowan Old Style", Georgia, serif;
  --font-sans: "IBM Plex Sans", ui-sans-serif, system-ui, sans-serif;
  --font-code: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --measure: 640px;
  --gutter: 16px;

  /* Type scale */
  --fs-name: 2.6rem;
  --fs-title: 2.4rem;
  --fs-deck: 1.3rem;
  --fs-body: 1.15rem;
  --fs-h2: 1.5rem;
  --fs-h3: 1.2rem;
  --fs-meta: 0.82rem;
  --fs-caption: 0.8rem;
  --fs-kicker: 0.74rem;
  --lh-body: 1.6;
}

@media (max-width: 480px) {
  :root { --fs-name: 2.2rem; --fs-title: 2rem; --fs-deck: 1.18rem; --fs-body: 1.08rem; --fs-h2: 1.35rem; }
}
@media (min-width: 640px) {
  :root { --gutter: 24px; }
}

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

html {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-serif);
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  -webkit-text-size-adjust: 100%;
  overflow-x: clip;
  font-variant-numeric: oldstyle-nums proportional-nums;
}
body {
  margin: 0;
  background: var(--paper);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  overflow-x: clip;
}

::selection { background: var(--selection); }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }

a { color: inherit; text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; text-decoration-color: var(--ink-3); }
a:hover { text-decoration-color: currentColor; }

img, svg { max-width: 100%; height: auto; }

.num { font-variant-numeric: lining-nums tabular-nums; }
.sans { font-family: var(--font-sans); }
.nowrap { white-space: nowrap; }
.kicker { font-family: var(--font-sans); font-size: var(--fs-kicker); letter-spacing: 0.09em; text-transform: uppercase; font-weight: 500; color: var(--ink-3); }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

.skip-link { position: absolute; left: var(--gutter); top: -3rem; z-index: 10; padding: 0.4rem 0.7rem; background: var(--ink); color: var(--paper); font-family: var(--font-sans); font-size: var(--fs-meta); text-decoration: none; }
.skip-link:focus { top: 0.75rem; }

/* One narrow reading column */
.wrap { max-width: calc(var(--measure) + 2 * var(--gutter)); margin: 0 auto; padding: 0 var(--gutter); }
main.wrap { padding-top: 4.5rem; padding-bottom: 2rem; }
@media (max-width: 480px) { main.wrap { padding-top: 2.75rem; } }

/* ---------- Homepage ---------- */

/* Each part (intro, explainers, writing) is its own screen on larger displays,
   joined by small labeled arrows. Scrolling snaps one screen at a time. */
html:has(main.home) { scroll-behavior: smooth; }
body:has(> main.home) { position: relative; }

.panel { position: relative; padding: 3rem 0 1rem; }
.panel-intro { padding-top: 3rem; }
.panel-label { margin: 0 0 1.4rem; font-size: 1.75rem; font-weight: 500; line-height: 1.15; letter-spacing: -0.015em; }
.panel-nav, .folio { display: none; }

@media (min-width: 640px) and (min-height: 600px) {
  html:has(main.home) { scroll-snap-type: y mandatory; }
  .panel { display: flex; flex-direction: column; justify-content: center; min-height: 100svh; padding: 6.5rem 0; scroll-snap-align: start; scroll-snap-stop: always; }
  .panel-body { width: 100%; }
  /* The footer sits inside the last screen so there is no extra stop below it. */
  main.home + .site-footer { position: absolute; left: 0; right: 0; bottom: 0; max-width: none; margin: 0; padding: 0 0 2rem clamp(1.75rem, 10vw, 12rem); }

  .panel-nav { display: block; position: absolute; left: 0; right: 0; }
  .panel-nav-prev { top: 2rem; }
  .panel-nav-next { bottom: 2rem; }
  /* Catchwords: like the first word of the next page printed at the foot of a book page,
     the next section's name sits centered under the column with a hairline arrow. */
  .panel-nav .wrap { display: flex; justify-content: center; }
  .panel-nav a { display: inline-flex; flex-direction: column; align-items: center; gap: 0.45rem; font: italic 400 1.02rem/1 var(--font-serif); color: var(--ink-3); text-decoration: none; }
  .panel-nav a:hover { color: var(--ink); }
  .panel-nav svg { display: block; fill: none; stroke: currentColor; stroke-width: 1; stroke-linecap: round; stroke-linejoin: round; transition: transform 300ms ease; }
  .panel-nav-next a:hover svg { transform: translateY(3px); }
  .panel-nav-prev a:hover svg { transform: translateY(-3px); }

  /* Folio: the sections as small italic page numbers, the current one in ink with an ochre underline. */
  .folio { position: fixed; top: 1.4rem; right: 1.75rem; z-index: 5; display: flex; gap: 0.9rem; font: italic 400 1.02rem/1 var(--font-serif); }
  .folio a { padding: 0 0.1rem 4px; color: var(--ink-3); text-decoration: none; border-bottom: 1px solid transparent; transition: color 200ms ease, border-color 200ms ease; }
  .folio a:hover { color: var(--ink); }
  .folio a[aria-current="true"] { color: var(--ink); border-bottom-color: var(--ochre); }

  /* Each section's content fades up as it arrives and fades out as it leaves.
     Only when scripts run (the "js" class), so content is never hidden without them. */
  .js .panel-body, .js .panel-nav { opacity: 0; transform: translateY(14px); transition: opacity 700ms ease, transform 900ms cubic-bezier(0.2, 0.7, 0.2, 1); }
  .js .panel.is-visible .panel-body, .js .panel.is-visible .panel-nav { opacity: 1; transform: none; }
  .js .panel.is-visible .panel-nav { transition-delay: 200ms; }

  /* The text blocks sit on a left axis; the intro sits a little above center. */
  .panel-intro { padding-bottom: 10rem; }
  .panel .panel-body { margin-left: clamp(1.75rem, 10vw, 12rem); padding-left: 0; }
}

.masthead h1 { margin: 0; font-size: 1.75rem; font-weight: 500; line-height: 1.15; letter-spacing: -0.015em; }

.bio { margin-top: 1.4rem; color: var(--ink-2); }
.bio p { margin: 0 0 0.9em; }
.bio a { color: var(--ink); }

/* Profile links: full reading size, italic, separated by small dots. */
.profiles { display: flex; flex-wrap: wrap; margin: 1.4rem 0 0; padding: 0; list-style: none; font-style: italic; color: var(--ink); }
.profiles li + li::before { content: "·"; margin: 0 0.6rem; font-style: normal; color: var(--ink-3); }
.profiles a { text-decoration-color: var(--rule); }
.profiles a:hover { text-decoration-color: currentColor; }

/* Articles, set like a table of contents: title, dotted leader, date on the right. */
.entries { margin: 0; padding: 0; list-style: none; }
.entry { display: flex; align-items: baseline; gap: 0.6rem; }
.entry + .entry { margin-top: 0.9rem; }
.entry-title { flex: 0 1 auto; min-width: 0; margin: 0; font-size: 1.22rem; font-weight: 400; line-height: 1.35; }
.entry-title a { text-decoration: none; }
.entry-title a:hover { text-decoration: underline; text-decoration-color: var(--ink-3); text-underline-offset: 4px; }
.leader { flex: 1 1 2rem; min-width: 1.5rem; border-bottom: 1.5px dotted #b3a68e; transform: translateY(-0.28em); transition: border-color 200ms ease; }
.entry:hover .leader { border-color: var(--ink-3); }
.entry-date { flex: 0 0 auto; font-style: italic; color: var(--ink-3); white-space: nowrap; }
.entry-soon .entry-title { color: var(--ink-3); }
.entry-draft-flag { margin-left: 0.5rem; font-family: var(--font-sans); font-size: 0.66rem; letter-spacing: 0.09em; text-transform: uppercase; font-weight: 600; color: var(--danger); vertical-align: 0.15em; }
.empty { margin: 0; color: var(--ink-3); font-style: italic; }

/* Footer */
.site-footer { margin-top: 5rem; padding-bottom: 3rem; font-family: var(--font-sans); font-size: var(--fs-caption); line-height: 1.5; color: var(--ink-3); }
.site-footer p { margin: 0; }
.site-footer .sep { margin: 0 0.5rem; }
main.home + .site-footer { margin-top: 1.5rem; }

/* ---------- Posts ---------- */

.back { margin: 0 0 2.5rem; font-family: var(--font-sans); font-size: var(--fs-meta); }
.back a { text-decoration: none; color: var(--ink-2); }
.back a:hover { text-decoration: underline; text-decoration-color: currentColor; }

.post-head h1 { margin: 0; font-size: var(--fs-title); font-weight: 500; line-height: 1.08; letter-spacing: -0.02em; }
.post-deck { margin: 0.75rem 0 0; font-size: var(--fs-deck); font-style: italic; line-height: 1.4; color: var(--ink-2); }
.post-meta { margin: 1.1rem 0 0; padding-bottom: 1rem; border-bottom: 1px solid var(--rule); font-family: var(--font-sans); font-size: var(--fs-meta); color: var(--ink-3); }
.post-meta .sep { margin: 0 0.45rem; }
.draft-banner { margin: 0 0 1.5rem; padding: 0.5rem 0.75rem; border: 1px solid var(--danger); font-family: var(--font-sans); font-size: var(--fs-meta); color: var(--danger); }

.prose { margin-top: 2rem; }
.prose > * { margin-top: 0; margin-bottom: 1.1em; }
.prose h2 { margin-top: 2.2em; margin-bottom: 0.5em; font-size: var(--fs-h2); font-weight: 500; line-height: 1.2; letter-spacing: -0.012em; }
.prose h3 { margin-top: 1.8em; margin-bottom: 0.4em; font-size: var(--fs-h3); font-weight: 600; line-height: 1.3; }
.prose h4 { margin-top: 1.6em; margin-bottom: 0.3em; font-family: var(--font-sans); font-size: var(--fs-kicker); letter-spacing: 0.09em; text-transform: uppercase; font-weight: 600; color: var(--ink-2); }
.prose ul, .prose ol { padding-left: 1.4em; }
.prose li { margin-bottom: 0.35em; }
.prose li::marker { color: var(--ink-3); }
.prose strong { font-weight: 600; }
.prose hr { margin: 2.5em auto; width: 4rem; border: 0; border-top: 1px solid var(--rule); }

.prose blockquote { margin-left: 0; margin-right: 0; padding-left: 1.1rem; border-left: 2px solid var(--rule); font-style: italic; color: var(--ink-2); }
.prose blockquote p { margin: 0 0 0.7em; }
.prose blockquote p:last-child { margin-bottom: 0; }

.prose code { font-family: var(--font-code); font-size: 0.82em; padding: 0.08em 0.3em; background: var(--plate); }
.prose pre { overflow-x: auto; padding: 0.9rem 1rem; background: var(--plate); border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); font-size: 0.86rem; line-height: 1.55; tab-size: 2; }
.prose pre code { padding: 0; background: none; font-size: inherit; }

.prose figure { margin-left: 0; margin-right: 0; margin-top: 2em; margin-bottom: 2em; }
.prose figure img { display: block; margin: 0 auto; }
.prose figcaption { margin-top: 0.6rem; padding-top: 0.5rem; border-top: 1px solid var(--rule); font-family: var(--font-sans); font-size: var(--fs-caption); line-height: 1.45; color: var(--ink-2); }

.prose table { width: 100%; border-collapse: collapse; font-family: var(--font-sans); font-size: 0.86rem; font-variant-numeric: lining-nums tabular-nums; }
.prose th, .prose td { padding: 0.4rem 0.6rem 0.4rem 0; text-align: left; border-bottom: 1px solid var(--rule); vertical-align: top; }
.prose th { font-weight: 600; border-bottom: 1.5px solid var(--ink); }
.table-scroll { overflow-x: auto; }

.prose sup.fn-ref { line-height: 0; font-family: var(--font-sans); font-size: 0.68em; font-weight: 500; }
.prose sup.fn-ref a { padding: 0 0.1em; text-decoration: none; color: var(--ochre-ink); }
.prose sup.fn-ref a:hover { text-decoration: underline; }
.footnotes { margin-top: 3rem; padding-top: 0.8rem; border-top: 1px solid var(--rule); font-size: 0.95rem; line-height: 1.5; color: var(--ink-2); }
.footnotes h2 { margin: 0 0 0.6rem; font-family: var(--font-sans); font-size: var(--fs-kicker); letter-spacing: 0.09em; text-transform: uppercase; font-weight: 600; color: var(--ink-3); }
.footnotes ol { margin: 0; padding-left: 1.3em; }
.footnotes li { margin-bottom: 0.5em; }
.footnotes li::marker { font-family: var(--font-sans); font-size: 0.8em; color: var(--ink-3); }
.footnotes li p { display: inline; margin: 0; }
.fn-back { margin-left: 0.3em; font-family: var(--font-sans); text-decoration: none; color: var(--ink-3); }
.footnotes li:target { background: var(--plate); }

.math-display { display: block; margin: 1.4em 0; overflow-x: auto; overflow-y: hidden; text-align: center; }
.math-inline, .math-display { font-variant-numeric: lining-nums; }
/* KaTeX sets math at 1.21em by default, which looks large beside Newsreader. */
.prose .katex { font-size: 1.06em; }
.math-pending { font-family: var(--font-code); font-size: 0.85em; color: var(--ink-2); }

/* ---------- 404 ---------- */
.notfound h1 { margin: 0; font-size: var(--fs-title); font-weight: 500; letter-spacing: -0.02em; line-height: 1.1; }
.notfound p { margin: 1rem 0 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; scroll-behavior: auto !important; }
}
