/* ==========================================================================
   Blog styles. Plain CSS, no build step.
   Colours use light-dark(), so a theme is just a `color-scheme` value:
   the OS preference by default, overridden by <html data-theme="light|dark">.
   ========================================================================== */

/* ---------- Tokens ---------- */
:root {
  color-scheme: light dark;

  --bg: light-dark(#faf8f5, #141210);
  --surface: light-dark(#ffffff, #1c1a17);
  --surface-2: light-dark(#f2eee8, #24211d);
  --text: light-dark(#1f1c19, #ece7e0);
  --text-2: light-dark(#5c554d, #aaa196);
  --border: light-dark(#e6e0d7, #302c27);
  --accent: light-dark(#a8441c, #f0a070);
  --accent-ink: light-dark(#ffffff, #1a0f08);
  --shadow: light-dark(0 1px 2px rgb(60 40 20 / 6%), 0 1px 2px rgb(0 0 0 / 40%));
  --shadow-lift: light-dark(0 12px 32px -12px rgb(60 40 20 / 28%), 0 12px 32px -12px rgb(0 0 0 / 70%));

  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-serif: Charter, "Bitstream Charter", "Sitka Text", Cambria, "Iowan Old Style", Georgia, serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

  --radius: 1rem;
  --gutter: 1.25rem;
  --header-h: 4rem;
}

:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-top: calc(var(--header-h) + 1rem);
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 1rem/1.6 var(--font-sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

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

:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 4px; }

::selection { background: color-mix(in srgb, var(--accent) 30%, transparent); }

h1, h2, h3, h4 { font-family: var(--font-serif); line-height: 1.2; letter-spacing: -0.01em; text-wrap: balance; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: 1rem; top: -4rem; z-index: 100;
  padding: 0.6rem 1rem; border-radius: 0.5rem;
  background: var(--accent); color: var(--accent-ink); text-decoration: none; font-weight: 600;
}
.skip-link:focus { top: 1rem; }

.wrap { width: min(100% - 2 * var(--gutter), 70rem); margin-inline: auto; }
.wrap--narrow { width: min(100% - 2 * var(--gutter), 46rem); }

/* ---------- Header / footer ---------- */
.site-header {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--border);
}
.site-header__inner {
  display: flex; align-items: center; gap: 1rem;
  min-height: var(--header-h);
}
.brand { display: inline-flex; align-items: center; gap: 0.7rem; color: var(--text); text-decoration: none; font-weight: 650; letter-spacing: -0.01em; }
.brand__mark {
  display: inline-grid; place-items: center; flex: none;
  width: 2.25rem; height: 2.25rem; border-radius: 0.65rem;
  background: var(--accent); color: var(--accent-ink);
  font: 700 0.85rem/1 var(--font-serif); letter-spacing: 0.02em;
}
.site-nav { margin-inline-start: auto; }
.site-nav ul, .site-header__tools { display: flex; align-items: center; gap: 0.25rem; margin: 0; padding: 0; list-style: none; }
.site-nav a {
  display: block; padding: 0.4rem 0.75rem; border-radius: 999px;
  color: var(--text-2); text-decoration: none; font-size: 0.925rem; font-weight: 500;
}
.site-nav a:hover { color: var(--text); background: var(--surface-2); }
.site-nav a[aria-current] { color: var(--text); background: var(--surface-2); }

.icon-btn {
  display: inline-grid; place-items: center; width: 2.25rem; height: 2.25rem;
  border: 0; border-radius: 999px; background: none; color: var(--text-2); cursor: pointer;
}
.icon-btn:hover { color: var(--text); background: var(--surface-2); }
.icon-btn[hidden] { display: none; }

.site-footer { margin-top: 6rem; border-top: 1px solid var(--border); color: var(--text-2); font-size: 0.9rem; }
.site-footer__inner { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 1rem; padding-block: 2rem; }
.site-footer p { margin: 0; }
.site-footer ul { display: flex; gap: 1.25rem; margin: 0; padding: 0; list-style: none; }
.site-footer a { color: inherit; }
.site-footer a:hover { color: var(--text); }

@media (max-width: 40rem) {
  :root { --header-h: 1rem; }
  .site-header { position: static; }
  .site-header__inner { flex-wrap: wrap; padding-block: 0.6rem 0.4rem; min-height: 0; row-gap: 0.4rem; }
  .site-header__tools { margin-inline-start: auto; }
  .site-nav { order: 3; flex-basis: 100%; margin: 0 -0.5rem; }
}

/* ---------- Shared bits ---------- */
.eyebrow { margin: 0 0 1rem; color: var(--accent); font-size: 0.8rem; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; }
.eyebrow a { color: inherit; text-decoration: none; }
.eyebrow a:hover { text-decoration: underline; }

.section-title { margin: 3.5rem 0 1.25rem; font: 700 0.8rem/1 var(--font-sans); letter-spacing: 0.12em; text-transform: uppercase; color: var(--text-2); }

.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem 0.6rem; margin: 0; color: var(--text-2); font-size: 0.875rem; }
.meta a { color: inherit; }

.topic {
  --hue: 50;
  display: inline-block; padding: 0.2rem 0.65rem; border-radius: 999px;
  background: light-dark(oklch(94% 0.04 var(--hue)), oklch(30% 0.06 var(--hue)));
  color: light-dark(oklch(40% 0.13 var(--hue)), oklch(85% 0.1 var(--hue)));
  font-size: 0.75rem; font-weight: 650; letter-spacing: 0.04em; text-transform: uppercase; text-decoration: none;
}
a.topic:hover { background: light-dark(oklch(90% 0.06 var(--hue)), oklch(36% 0.08 var(--hue))); }

.button {
  display: inline-block; padding: 0.6rem 1.1rem; border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); color: var(--text); font-weight: 600; font-size: 0.925rem; text-decoration: none;
}
.button:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- Page headers ---------- */
.hero { position: relative; padding-block: clamp(3rem, 8vw, 6rem) 2rem; }
.hero::before {
  content: ""; position: absolute; z-index: -1; inset: -4rem -10vw auto auto; width: min(36rem, 80vw); aspect-ratio: 1;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--accent) 22%, transparent), transparent);
  pointer-events: none;
}
.hero__title { max-width: 20ch; margin: 0; font-size: clamp(2.4rem, 6.5vw, 4.25rem); line-height: 1.05; letter-spacing: -0.025em; }
.hero__lede { max-width: 38rem; margin: 1.5rem 0 0; color: var(--text-2); font-size: clamp(1.05rem, 1rem + 0.4vw, 1.25rem); }

.page-header { padding-block: clamp(2.5rem, 6vw, 4.5rem) 1rem; }
.page-title { margin: 0; font-size: clamp(2.2rem, 5vw, 3.5rem); letter-spacing: -0.02em; }
.page-lede { max-width: 38rem; margin: 0.75rem 0 0; color: var(--text-2); font-size: 1.1rem; }

/* ---------- Topic navigation ---------- */
.topic-nav { margin-block: 1.5rem 2.5rem; }
.topic-nav ul { display: flex; gap: 0.5rem; margin: 0; padding: 0 0 0.25rem; list-style: none; overflow-x: auto; scrollbar-width: none; }
.topic-nav a {
  --hue: 50;
  display: inline-flex; align-items: center; gap: 0.5rem; padding: 0.4rem 0.9rem; border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); color: var(--text); font-size: 0.9rem; font-weight: 550; text-decoration: none; white-space: nowrap;
}
.topic-nav a[style]::before { content: ""; width: 0.55rem; height: 0.55rem; border-radius: 50%; background: oklch(65% 0.15 var(--hue)); }
.topic-nav a:hover { border-color: var(--text-2); }
.topic-nav a[aria-current] { background: var(--text); border-color: var(--text); color: var(--bg); }

/* ---------- Cards & grid ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 19rem), 1fr)); gap: 1.5rem; }

.card {
  position: relative; display: flex; flex-direction: column; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lift); border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
.card__media { display: block; overflow: hidden; aspect-ratio: 16 / 9; background: var(--surface-2); }
.card__media img { width: 100%; height: 100%; object-fit: cover; transition: transform 0.5s ease; }
.card:hover .card__media img { transform: scale(1.03); }
.card__body { display: flex; flex: 1; flex-direction: column; align-items: flex-start; gap: 0.75rem; padding: 1.25rem 1.4rem 1.4rem; }
.card__body .topic { position: relative; z-index: 1; }
.card__title { margin: 0; font-size: 1.35rem; line-height: 1.25; }
.card__title a { color: var(--text); text-decoration: none; }
.card__title a::after { content: ""; position: absolute; inset: 0; } /* whole card is clickable */
.card__blurb {
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden;
  margin: 0; color: var(--text-2); font-size: 0.975rem;
}
.card .meta { margin-top: auto; padding-top: 0.25rem; }

.card--featured { flex-direction: row; align-items: stretch; }
.card--featured .card__media { flex: 1.45; aspect-ratio: auto; min-height: 18rem; }
.card--featured .card__body { flex: 1; justify-content: center; gap: 1rem; padding: clamp(1.5rem, 3vw, 2.75rem); }
.card--featured .card__title { font-size: clamp(1.7rem, 3vw, 2.4rem); line-height: 1.15; letter-spacing: -0.02em; }
.card--featured .card__blurb { -webkit-line-clamp: 5; font-size: 1.05rem; }
.card--featured .meta { margin-top: 0; }

@media (max-width: 52rem) {
  .card--featured { flex-direction: column; }
  .card--featured .card__media { flex: none; aspect-ratio: 16 / 9; min-height: 0; }
}

/* ---------- Pagination & archive ---------- */
.pagination { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-top: 3.5rem; }
.pagination__status { color: var(--text-2); font-size: 0.9rem; }

.archive-year .section-title { margin-top: 2.5rem; }
.archive-list { margin: 0; padding: 0; list-style: none; }
.archive-list li {
  display: grid; grid-template-columns: 4.5rem 1fr auto; align-items: baseline; gap: 1rem;
  padding: 0.85rem 0; border-bottom: 1px solid var(--border);
}
.archive-list time { color: var(--text-2); font-size: 0.875rem; font-variant-numeric: tabular-nums; }
.archive-list a:not(.topic) { color: var(--text); font-family: var(--font-serif); font-size: 1.15rem; text-decoration: none; }
.archive-list a:not(.topic):hover { color: var(--accent); }
@media (max-width: 36rem) {
  .archive-list li { grid-template-columns: 1fr auto; }
  .archive-list time { grid-column: 1 / -1; }
}

/* ---------- Post ---------- */
.post { --measure: 44rem; --wide: 66rem; }

.post-header { width: min(100% - 2 * var(--gutter), var(--measure)); margin: 0 auto; padding-block: clamp(2.5rem, 7vw, 5rem) 2rem; }
.post-title { margin: 1rem 0 0; font-size: clamp(2.2rem, 5.5vw, 3.6rem); line-height: 1.08; letter-spacing: -0.025em; }
.post-dek { margin: 1.25rem 0 0; color: var(--text-2); font: 1.2rem/1.5 var(--font-serif); font-size: clamp(1.1rem, 1rem + 0.5vw, 1.4rem); text-wrap: pretty; }
.post-header .meta { margin-top: 1.5rem; }

.post-cover { width: min(100% - 2 * var(--gutter), 68rem); margin: 1rem auto 3rem; }
.post-cover img { width: 100%; border-radius: var(--radius); background: var(--surface-2); box-shadow: var(--shadow); }

figcaption { margin-top: 0.75rem; color: var(--text-2); font-size: 0.85rem; line-height: 1.45; text-align: center; text-wrap: pretty; }

/* The prose container is a named-line grid so that individual blocks can
   break out of the reading column: .figure--wide and .figure--full. */
.prose {
  --edge: minmax(var(--gutter), 1fr);
  display: grid;
  grid-template-columns:
    [full-start] var(--edge)
    [wide-start] minmax(0, calc((var(--wide) - var(--measure)) / 2))
    [content-start] min(100% - 2 * var(--gutter), var(--measure))
    [content-end] minmax(0, calc((var(--wide) - var(--measure)) / 2))
    [wide-end] var(--edge)
    [full-end];
  font: 1.125rem/1.75 var(--font-serif);
  font-size: clamp(1.075rem, 1rem + 0.3vw, 1.2rem);
  hyphens: manual; overflow-wrap: break-word;
}
.prose > * { grid-column: content; min-width: 0; margin-block: 0; }
.prose > * + * { margin-top: 1.4em; }
.prose > .figure--wide, .prose > .pullquote, .prose > .figure-grid { grid-column: wide; }
.prose > .figure--full { grid-column: full; }

.prose h2, .prose h3, .prose h4 { margin-bottom: 0; }
.prose h2 { margin-top: 2.6em; font-size: 1.75em; }
.prose h3 { margin-top: 2em; font-size: 1.3em; }
.prose h4 { margin-top: 1.8em; font-size: 1.1em; }
.prose h2 + *, .prose h3 + *, .prose h4 + * { margin-top: 0.8em; }

.prose p { text-wrap: pretty; }
.prose .lead { color: var(--text-2); font-size: 1.2em; line-height: 1.6; }
.prose ul, .prose ol { padding-inline-start: 1.4em; }
.prose li + li { margin-top: 0.4em; }
.prose li::marker { color: var(--accent); }
.prose strong { font-weight: 700; }

.prose hr { width: 100%; height: auto; border: 0; text-align: center; margin-block: 2.5em 0; }
.prose hr::before { content: "\2022\2002\2022\2002\2022"; color: var(--text-2); letter-spacing: 0.4em; }
.prose hr + * { margin-top: 1em; }

.prose blockquote:not(.pullquote) {
  margin-inline: 0; padding: 0.1em 0 0.1em 1.4em; border-inline-start: 3px solid var(--accent);
  font-style: italic; color: var(--text);
}
.prose blockquote:not(.pullquote) p + p { margin-top: 0.8em; }
.prose blockquote cite, .prose blockquote footer { display: block; margin-top: 0.6em; color: var(--text-2); font: normal 0.85rem var(--font-sans); }

.pullquote {
  margin-block: 2.5em; padding: 1.75rem 0; border-block: 1px solid var(--border);
  font: italic 1.6rem/1.35 var(--font-serif); font-size: clamp(1.4rem, 1rem + 1.6vw, 2rem);
  text-align: center; text-wrap: balance; color: var(--text);
}
.pullquote p { margin: 0; }

.prose code, .prose kbd {
  padding: 0.12em 0.4em; border-radius: 0.35em; background: var(--surface-2);
  font: 0.85em var(--font-mono);
}
.prose kbd { border: 1px solid var(--border); border-bottom-width: 2px; background: var(--surface); }
.prose mark { padding: 0.05em 0.2em; border-radius: 0.2em; background: color-mix(in srgb, var(--accent) 28%, transparent); color: inherit; }
.prose sup, .prose sub { line-height: 0; }
.prose a.footnote, .prose a.reversefootnote { text-decoration: none; }

.prose div.highlighter-rouge {
  border: 1px solid var(--border); border-radius: 0.75rem; background: light-dark(#f6f2ec, #1b1815);
}
.prose div.highlighter-rouge pre, .prose div.highlighter-rouge .highlight { margin: 0; background: none; }
.prose pre { padding: 1.1rem 1.25rem; overflow-x: auto; font: 0.85rem/1.65 var(--font-mono); tab-size: 2; }
.prose pre code { padding: 0; background: none; font: inherit; }

.prose table { display: block; width: max-content; max-width: 100%; overflow-x: auto; border-collapse: collapse; font: 0.95rem/1.5 var(--font-sans); }
.prose th, .prose td { padding: 0.65rem 1rem; border-bottom: 1px solid var(--border); text-align: left; }
.prose th { border-bottom-width: 2px; color: var(--text-2); font-size: 0.8rem; letter-spacing: 0.06em; text-transform: uppercase; }
.prose tbody tr:hover { background: var(--surface-2); }

.prose details { padding: 0.9rem 1.1rem; border: 1px solid var(--border); border-radius: 0.75rem; background: var(--surface); font: 1rem/1.6 var(--font-sans); }
.prose summary { cursor: pointer; font-weight: 600; }
.prose details[open] summary { margin-bottom: 0.6rem; }

.prose .footnotes { margin-top: 3em; padding-top: 1.25rem; border-top: 1px solid var(--border); color: var(--text-2); font-size: 0.875em; }
.prose .footnotes ol { margin: 0; }
.prose .footnotes p { margin: 0; }

/* Table of contents (kramdown `{:toc}`) */
.toc { padding: 1.1rem 1.4rem; border: 1px solid var(--border); border-radius: 0.75rem; background: var(--surface); font: 0.95rem/1.5 var(--font-sans); }
.toc__title { margin: 0 0 0.5rem; color: var(--text-2); font-size: 0.75rem; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; }
.toc ul { margin: 0; padding-inline-start: 1.1rem; }
.toc > ul { padding-inline-start: 0; list-style: none; }
.toc li + li { margin-top: 0.3em; }
.toc a { color: var(--text); text-decoration: none; }
.toc a:hover { color: var(--accent); text-decoration: underline; }

/* Callouts: <aside class="callout callout--note|tip|warn" markdown="1"> */
.callout {
  --tone: 250;
  padding: 1rem 1.25rem; border: 1px solid light-dark(oklch(88% 0.05 var(--tone)), oklch(38% 0.07 var(--tone))); border-inline-start-width: 4px;
  border-radius: 0.75rem; background: light-dark(oklch(97% 0.02 var(--tone)), oklch(25% 0.03 var(--tone)));
  border-inline-start-color: light-dark(oklch(60% 0.15 var(--tone)), oklch(70% 0.14 var(--tone)));
  font: 1rem/1.6 var(--font-sans);
}
.callout--tip { --tone: 150; }
.callout--warn { --tone: 70; }
.callout > * { margin-block: 0; }
.callout > * + * { margin-top: 0.6em; }
.callout__title { font-weight: 700; }

/* Figures */
.figure { margin-inline: 0; }
.figure img { width: 100%; border-radius: 0.75rem; background: var(--surface-2); }
.figure--full img { border-radius: 0; }
.figure-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 16rem), 1fr)); gap: 1rem; }
.figure-grid .figure { margin: 0; }

/* Post footer */
.post-footer { width: min(100% - 2 * var(--gutter), var(--measure)); margin: 4rem auto 0; }
.author-card { display: flex; gap: 1.1rem; align-items: flex-start; padding: 1.5rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); font-size: 0.95rem; }
.author-card .brand__mark { width: 3rem; height: 3rem; border-radius: 50%; font-size: 1rem; }
.author-card p { margin: 0; color: var(--text-2); }
.author-card strong { color: var(--text); }

.post-nav { display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: 1rem; margin-top: 1.5rem; }
.post-nav__link {
  display: flex; flex-direction: column; gap: 0.3rem; padding: 1.1rem 1.25rem;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); text-decoration: none;
}
.post-nav__link:hover { border-color: var(--accent); }
.post-nav__link--next { text-align: end; }
.post-nav__link--next:only-child { grid-column: 2; }
.post-nav__label { color: var(--text-2); font-size: 0.8rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; }
.post-nav__title { font: 1.1rem/1.3 var(--font-serif); }

.related { margin-top: 1rem; }

/* Reading progress: pure CSS, only where scroll-driven animations exist. */
.read-progress { display: none; }
@supports (animation-timeline: scroll()) {
  .read-progress {
    position: fixed; inset: 0 0 auto 0; z-index: 20; display: block; height: 3px;
    background: var(--accent); transform: scaleX(0); transform-origin: 0 50%;
    animation: read-progress linear both; animation-timeline: scroll(root block);
  }
}
@keyframes read-progress { to { transform: scaleX(1); } }

/* ---------- Syntax highlighting (Rouge) ---------- */
.highlight .c, .highlight span[class^="c"] { color: light-dark(#8a8176, #8b8378); font-style: italic; }
.highlight span[class^="k"] { color: light-dark(#a33a8a, #e58ccf); }
.highlight span[class^="s"] { color: light-dark(#2f7d4f, #8fd19e); }
.highlight .m, .highlight span[class^="m"], .highlight .kc { color: light-dark(#b5560d, #f3a96a); }
.highlight .nf, .highlight .nc, .highlight .nn { color: light-dark(#1e5fb3, #7fb4f5); }
.highlight .nb, .highlight .bp, .highlight .nt { color: light-dark(#7a4bc2, #c0a2f2); }
.highlight .na, .highlight .nv { color: light-dark(#8a5a00, #e6c27a); }
.highlight .o, .highlight .ow, .highlight .p { color: light-dark(#6b6358, #b0a89c); }
.highlight .err { color: inherit; }

/* ---------- Motion & print ---------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .read-progress { display: none !important; }
}

@media print {
  :root { color-scheme: light; }
  .site-header, .site-footer, .topic-nav, .post-nav, .related, .read-progress, .skip-link { display: none !important; }
  body { background: #fff; color: #000; }
  .prose a[href^="http"]::after { content: " (" attr(href) ")"; font-size: 0.8em; word-break: break-all; }
}
