@import url('/assets/fonts/fonts.css');

/* ─── Tokens ─────────────────────────────────────────────────────────────────
   Colours are OKLCH. The brand hue is 156 (forest green, taken from the CV);
   every neutral is tinted a fraction toward it so the palette reads as one set.
   ───────────────────────────────────────────────────────────────────────── */

:root {
  --paper: oklch(98.6% 0.004 150);
  --paper-raised: oklch(96.6% 0.006 150);
  --ink: oklch(29% 0.026 240);
  --ink-2: oklch(45% 0.022 238);
  --ink-3: oklch(54.8% 0.018 235);
  --rule: oklch(89% 0.01 200);
  --rule-strong: oklch(79% 0.014 195);
  --accent: oklch(48% 0.105 156);
  --accent-bright: oklch(54.5% 0.115 156);
  --accent-soft: oklch(93.5% 0.03 156);
  --selection: oklch(89% 0.06 156);

  --sans: 'Archivo', ui-sans-serif, system-ui, sans-serif;
  --serif: 'Literata', ui-serif, Georgia, serif;
  --mono: 'Fira Code', ui-monospace, SFMono-Regular, monospace;

  --text-xs: 0.78rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-prose: 1.1875rem;
  --text-lg: 1.5rem;
  --text-xl: clamp(1.6rem, 1.35rem + 1vw, 1.95rem);
  --text-2xl: clamp(2rem, 1.4rem + 2.6vw, 3rem);
  --text-display: clamp(2.5rem, 1.3rem + 5vw, 4.5rem);

  --space-3xs: 0.25rem;
  --space-2xs: 0.5rem;
  --space-xs: 0.75rem;
  --space-sm: 1rem;
  --space-md: 1.5rem;
  --space-lg: 2rem;
  --space-xl: 3rem;
  --space-2xl: 4rem;
  --space-3xl: 6rem;
  --section-gap: clamp(3.5rem, 2rem + 6vw, 7rem);

  --shell: 68rem;
  --gutter: clamp(1.25rem, 5vw, 4rem);
  --measure: 64ch;
  --rail: 15rem;

  --prose-leading: 1.72;

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --duration: 380ms;

  color-scheme: light;
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --paper: oklch(22% 0.014 240);
  --paper-raised: oklch(26% 0.016 240);
  --ink: oklch(91% 0.012 210);
  --ink-2: oklch(75.5% 0.014 215);
  --ink-3: oklch(63.5% 0.014 215);
  --rule: oklch(33% 0.016 225);
  --rule-strong: oklch(43% 0.018 220);
  --accent: oklch(74.5% 0.115 156);
  --accent-bright: oklch(79% 0.12 156);
  --accent-soft: oklch(31% 0.045 156);
  --selection: oklch(38% 0.07 156);
  --prose-leading: 1.78;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --paper: oklch(22% 0.014 240);
    --paper-raised: oklch(26% 0.016 240);
    --ink: oklch(91% 0.012 210);
    --ink-2: oklch(75.5% 0.014 215);
    --ink-3: oklch(63.5% 0.014 215);
    --rule: oklch(33% 0.016 225);
    --rule-strong: oklch(43% 0.018 220);
    --accent: oklch(74.5% 0.115 156);
    --accent-bright: oklch(79% 0.12 156);
    --accent-soft: oklch(31% 0.045 156);
    --selection: oklch(38% 0.07 156);
    --prose-leading: 1.78;
  }
}

/* ─── Reset ──────────────────────────────────────────────────────────────── */

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

* {
  margin: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: 6rem;
}

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: var(--text-base);
  line-height: 1.6;
  font-kerning: normal;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection {
  background: var(--selection);
  color: var(--ink);
}

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

img {
  height: auto;
}

a {
  color: inherit;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
}

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

.skip-link {
  position: fixed;
  top: var(--space-sm);
  left: var(--space-sm);
  z-index: 100;
  padding: var(--space-2xs) var(--space-sm);
  background: var(--paper);
  border: 1px solid var(--accent);
  transform: translateY(-250%);
  transition: transform 160ms var(--ease);
}

.skip-link:focus {
  transform: none;
}

.shell {
  width: 100%;
  max-width: var(--shell);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

/* ─── Wordmark ───────────────────────────────────────────────────────────────
   Danny (bold, green) · James (light, ink) · Williams (bold, green) — the
   weight alternation is lifted straight from the CV masthead.
   ───────────────────────────────────────────────────────────────────────── */

.wordmark {
  font-family: var(--sans);
  letter-spacing: -0.025em;
  white-space: nowrap;
}

.wordmark b {
  font-weight: 700;
  color: var(--accent);
}

.wordmark i {
  font-weight: 300;
  font-style: normal;
  color: var(--ink-2);
}

.wordmark-large {
  font-size: var(--text-display);
  line-height: 0.98;
  letter-spacing: -0.04em;
  white-space: normal;
}

.wordmark-large i {
  font-weight: 200;
}

/* ─── Header ─────────────────────────────────────────────────────────────── */

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
}

.site-header-inner {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  min-height: 4.25rem;
}

.site-mark {
  font-size: 1.0625rem;
  text-decoration: none;
  margin-right: auto;
  transition: opacity var(--duration) var(--ease), transform var(--duration) var(--ease);
}

/* On the home page the masthead carries the name, so the header mark only
   arrives once you have scrolled past it. */
.site-header-home .site-mark {
  opacity: 0;
  transform: translateY(-0.4rem);
  pointer-events: none;
}

.site-header-home.is-scrolled .site-mark {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

.site-nav {
  display: flex;
  gap: clamp(var(--space-sm), 2.5vw, var(--space-lg));
  font-size: var(--text-sm);
  letter-spacing: 0.01em;
}

.site-nav a {
  position: relative;
  padding-block: 0.4rem;
  color: var(--ink-2);
  text-decoration: none;
  transition: color 160ms var(--ease);
}

.site-nav a::after {
  content: '';
  position: absolute;
  inset-inline: 0;
  bottom: 0;
  height: 2px;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 260ms var(--ease);
}

.site-nav a:hover {
  color: var(--ink);
}

.site-nav a[aria-current='page'] {
  color: var(--ink);
}

.site-nav a[aria-current='page']::after,
.site-nav a:hover::after {
  transform: scaleX(1);
}

.theme-toggle {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  margin-right: -0.35rem;
  color: var(--ink-3);
  transition: color 160ms var(--ease), transform 400ms var(--ease);
}

.theme-toggle svg {
  width: 1.05rem;
  height: 1.05rem;
  fill: currentColor;
  stroke: currentColor;
  stroke-width: 1.2;
}

.theme-toggle svg circle {
  fill: none;
}

.theme-toggle:hover {
  color: var(--accent);
}

:root[data-theme='dark'] .theme-toggle {
  transform: rotate(180deg);
}

/* ─── Masthead ───────────────────────────────────────────────────────────── */

.masthead {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-lg);
  padding-block: clamp(var(--space-2xl), 9vw, 6.5rem) var(--space-xl);
}

.masthead-text {
  min-width: 0;
}

.masthead h1 {
  font-size: inherit;
  font-weight: inherit;
}

.masthead-role {
  margin-top: var(--space-md);
  font-size: var(--text-lg);
  font-weight: 400;
  letter-spacing: -0.015em;
  color: var(--ink);
}

.masthead-role span {
  display: block;
  font-size: var(--text-base);
  color: var(--ink-3);
}

.masthead-contact {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2xs) var(--space-md);
  margin-top: var(--space-md);
  font-size: var(--text-sm);
}

.masthead-contact a {
  color: var(--ink-2);
  text-decoration: none;
  border-bottom: 1px solid var(--rule-strong);
  padding-bottom: 1px;
  transition: color 160ms var(--ease), border-color 160ms var(--ease);
}

.masthead-contact a:hover {
  color: var(--accent);
  border-color: var(--accent);
}

/* Jumps to the about section further down the page. Scoped to beat the
   plain contact-link rule above. */
.masthead-contact .masthead-jump {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  color: var(--ink-3);
  border-color: transparent;
}

.masthead-contact .masthead-jump:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.masthead-jump svg {
  width: 0.7em;
  height: 0.82em;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 260ms var(--ease);
}

.masthead-jump:hover svg {
  transform: translateY(2px);
}

.closing {
  scroll-margin-top: 6rem;
}

.masthead-portrait {
  flex: none;
  width: clamp(5.5rem, 13vw, 9.375rem);
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 50%;
  border: 1px solid var(--rule-strong);
}

.lede {
  max-width: 58ch;
  padding-bottom: var(--space-2xl);
  border-bottom: 1px solid var(--rule);
  font-family: var(--serif);
  font-size: clamp(1.125rem, 1rem + 0.6vw, 1.375rem);
  line-height: 1.62;
  color: var(--ink-2);
  text-wrap: pretty;
}

.lede strong {
  font-weight: 600;
  color: var(--ink);
}

.lede a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}

/* ─── Split layout: wide content column, narrow metadata rail ────────────── */

.split {
  display: grid;
  gap: var(--section-gap) var(--space-2xl);
  padding-block: var(--section-gap);
}

@media (min-width: 62rem) {
  .split {
    grid-template-columns: var(--rail) minmax(0, 1fr);
  }

  .split-main {
    grid-column: 2;
    grid-row: 1;
  }

  .split-rail {
    grid-column: 1;
    grid-row: 1;
    position: sticky;
    top: 6.5rem;
    align-self: start;
  }
}

.split-main {
  display: grid;
  gap: var(--section-gap);
}

.split-rail {
  display: grid;
  gap: var(--space-xl);
  align-content: start;
}

.rail-group h2 {
  margin-bottom: var(--space-xs);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--accent);
}

.rail-group ul {
  display: grid;
  gap: var(--space-xs);
  list-style: none;
  padding: 0;
  font-size: var(--text-sm);
}

.rail-primary {
  display: block;
  color: var(--ink);
  line-height: 1.35;
}

.rail-primary a {
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: color 160ms var(--ease), border-color 160ms var(--ease);
}

.rail-primary a:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.rail-secondary {
  display: block;
  color: var(--ink-3);
  line-height: 1.35;
}

/* ─── Section headings ───────────────────────────────────────────────────── */

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
  padding-bottom: var(--space-xs);
  border-bottom: 1px solid var(--rule);
}

.section-head h2 {
  font-size: var(--text-xl);
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--accent-bright);
}

.section-link {
  display: inline-flex;
  align-items: center;
  gap: 0.45em;
  flex: none;
  font-size: var(--text-sm);
  color: var(--ink-3);
  text-decoration: none;
  transition: color 160ms var(--ease);
}

.section-link svg {
  width: 1em;
  height: 0.75em;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  transition: transform 260ms var(--ease);
}

.section-link:hover {
  color: var(--accent);
}

.section-link:hover svg {
  transform: translateX(3px);
}

/* ─── Publication entry ──────────────────────────────────────────────────── */

.entry-list {
  display: grid;
  gap: var(--space-2xl);
  padding-block: var(--space-xl);
}

.block .entry + .entry {
  margin-top: var(--space-2xl);
}

.entry {
  display: grid;
  grid-template-columns: 2.5rem minmax(0, 1fr);
  align-items: start;
}

.entry-mark {
  padding-top: 0.2rem;
  color: var(--accent-bright);
}

.mark {
  width: 1.5rem;
  height: 1.5rem;
}

.entry-title {
  font-size: var(--text-lg);
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.02em;
  text-wrap: balance;
}

.entry-title a {
  text-decoration: none;
  background-image: linear-gradient(var(--accent), var(--accent));
  background-size: 0% 1px;
  background-position: 0 100%;
  background-repeat: no-repeat;
  transition: background-size 320ms var(--ease), color 160ms var(--ease);
}

.entry-title a:hover {
  color: var(--accent);
  background-size: 100% 1px;
}

.entry-meta {
  margin-top: var(--space-3xs);
  font-size: var(--text-sm);
  color: var(--ink-3);
}

.entry-meta b {
  font-weight: 600;
  color: var(--ink-2);
}

.entry-venue::before {
  content: ' · ';
  color: var(--rule-strong);
}

.entry-prose {
  margin-top: var(--space-sm);
  max-width: var(--measure);
  font-family: var(--serif);
  font-size: 1.0625rem;
  line-height: 1.66;
  color: var(--ink-2);
}

.entry-prose > * + * {
  margin-top: var(--space-sm);
}

.entry-prose a {
  color: var(--accent);
  text-underline-offset: 0.18em;
}

.entry-prose ul {
  display: grid;
  gap: var(--space-2xs);
  list-style: none;
  padding-left: 1.1em;
}

.entry-prose ul > li {
  position: relative;
}

.entry-prose ul > li::before {
  content: '';
  position: absolute;
  left: -1.1em;
  top: 0.82em;
  width: 0.34em;
  height: 1px;
  background: var(--accent);
}

.entry-prose strong {
  font-weight: 600;
  color: var(--ink);
}

.entry-skills {
  margin-top: var(--space-xs);
  font-family: var(--serif);
  font-style: italic;
  font-size: var(--text-sm);
  color: var(--ink-3);
}

.link-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-md);
  margin-top: var(--space-sm);
  font-size: var(--text-sm);
}

.link-row a {
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid color-mix(in oklch, var(--accent) 35%, transparent);
  transition: border-color 160ms var(--ease);
}

.link-row svg {
  width: 0.7em;
  height: 0.7em;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  transition: transform 240ms var(--ease);
}

.link-row a:hover {
  border-color: var(--accent);
}

.link-row a:hover svg {
  transform: translate(2px, -2px);
}

.entry-year {
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
  color: var(--ink-3);
  padding-top: 0.3rem;
}

@media (min-width: 62rem) {
  .entry-dated {
    grid-template-columns: var(--rail) 2.5rem minmax(0, 1fr);
  }
}

@media (max-width: 61.99rem) {
  .entry-dated .entry-year {
    grid-column: 2;
    padding-top: 0;
    order: -1;
  }
}

/* ─── Tags ───────────────────────────────────────────────────────────────────
   Set like the "Skills:" line on the CV rather than as pill chips. */

.tags {
  margin-top: var(--space-xs);
  font-family: var(--serif);
  font-style: italic;
  font-size: var(--text-sm);
  line-height: 1.4;
  color: var(--ink-3);
}

/* ─── Post rows ──────────────────────────────────────────────────────────── */

.post-list {
  display: grid;
  border-bottom: 1px solid var(--rule);
}

/* Between year groups the next row's top rule is enough on its own. */
.year-group .post-list {
  border-bottom: 0;
}

.year-group:last-of-type .post-list {
  border-bottom: 1px solid var(--rule);
}

.post-row {
  display: grid;
  grid-template-columns: 6.5rem 11rem minmax(0, 1fr);
  grid-template-areas:
    'date thumb text'
    'date thumb tags';
  gap: var(--space-2xs) var(--space-sm);
  align-items: baseline;
  padding-block: var(--space-md);
  border-top: 1px solid var(--rule);
  text-decoration: none;
  transition: background-color 200ms var(--ease);
}

.post-row-date {
  grid-area: date;
}

.post-row-text {
  grid-area: text;
}

.post-row .tags {
  grid-area: tags;
  margin-top: 0;
}

/* Sized to the height the row already had, so the list rhythm does not change. */
.post-row-thumb {
  grid-area: thumb;
  align-self: start;
  display: block;
  overflow: hidden;
  border-radius: 2px;
  margin-top: 0.2rem;
}

.post-row-thumb img {
  width: 100%;
  aspect-ratio: 3 / 2;
  object-fit: cover;
  border: 1px solid var(--rule);
  border-radius: 2px;
  background: var(--paper-raised);
  transition: transform 600ms var(--ease);
}

.post-row:hover .post-row-thumb img {
  transform: scale(1.04);
}

.post-row:hover {
  background: var(--paper-raised);
  box-shadow: 0 0 0 var(--gutter) var(--paper-raised);
  clip-path: inset(0 calc(-1 * var(--gutter)));
}

.post-row-date {
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
  color: var(--ink-3);
  transition: color 200ms var(--ease);
}

.post-row:hover .post-row-date {
  color: var(--accent);
}

.post-row-text {
  display: grid;
  gap: 0.15rem;
}

.post-row-title {
  font-size: 1.1875rem;
  font-weight: 500;
  letter-spacing: -0.015em;
  line-height: 1.3;
  color: var(--ink);
  text-wrap: balance;
}

.post-row-subtitle {
  font-family: var(--serif);
  font-size: var(--text-sm);
  line-height: 1.5;
  color: var(--ink-3);
  max-width: 60ch;
}

/* ─── Page heads ─────────────────────────────────────────────────────────── */

.page-head {
  max-width: 54ch;
  padding-block: clamp(var(--space-2xl), 8vw, 5.5rem) var(--space-xl);
}

.page-head h1 {
  font-size: var(--text-2xl);
  font-weight: 700;
  letter-spacing: -0.035em;
  line-height: 1.05;
  color: var(--accent-bright);
}

.page-head p {
  margin-top: var(--space-md);
  font-family: var(--serif);
  font-size: 1.0625rem;
  line-height: 1.66;
  color: var(--ink-2);
}

.page-head a {
  color: var(--accent);
}

/* ─── Blog index ─────────────────────────────────────────────────────────── */

.year-group {
  display: grid;
  gap: var(--space-2xs);
  padding-bottom: var(--space-xl);
}

@media (min-width: 62rem) {
  .year-group {
    grid-template-columns: var(--rail) minmax(0, 1fr);
    gap: var(--space-2xl);
  }
}

.year-label {
  padding-top: var(--space-md);
  font-size: var(--text-lg);
  font-weight: 200;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  color: var(--ink-3);
  position: sticky;
  top: 6.5rem;
  align-self: start;
}

/* ─── Post page ──────────────────────────────────────────────────────────── */

.post-hero {
  width: 100%;
  aspect-ratio: 2.1 / 1;
  object-fit: cover;
  margin-bottom: var(--space-lg);
  border: 1px solid var(--rule);
  border-radius: 2px;
  background: var(--paper-raised);
}

.post-head {
  max-width: 44rem;
  padding-block: clamp(var(--space-xl), 7vw, 4.5rem) var(--space-lg);
}

.post-kicker {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2xs) var(--space-sm);
  margin-bottom: var(--space-md);
  font-size: var(--text-sm);
  color: var(--ink-3);
}

.post-kicker a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid transparent;
}

.post-kicker a:hover {
  border-color: var(--accent);
}

.post-kicker > * + *::before {
  content: '';
  display: inline-block;
  width: 3px;
  height: 3px;
  margin-right: var(--space-sm);
  margin-bottom: 0.2em;
  border-radius: 50%;
  background: var(--rule-strong);
}

.post-head h1 {
  font-size: var(--text-2xl);
  font-weight: 700;
  letter-spacing: -0.035em;
  line-height: 1.06;
  text-wrap: balance;
}

.post-subtitle {
  margin-top: var(--space-md);
  font-family: var(--serif);
  font-style: italic;
  font-size: clamp(1.0625rem, 1rem + 0.4vw, 1.25rem);
  line-height: 1.55;
  color: var(--ink-3);
  text-wrap: pretty;
}

.post-layout {
  display: grid;
  gap: var(--space-xl);
  padding-block: var(--space-lg) var(--space-3xl);
  border-top: 1px solid var(--rule);
}

@media (min-width: 62rem) {
  .post-layout {
    grid-template-columns: var(--rail) minmax(0, 1fr);
    gap: var(--space-2xl);
  }

  /* Without a contents list there is nothing to put in the margin, so the prose
     lines up with the title instead of sitting in an empty indent. */
  .post-layout-solo {
    grid-template-columns: minmax(0, 1fr);
  }

  .post-layout:not(.post-layout-solo) .prose {
    grid-column: 2;
    grid-row: 1;
  }

  .toc {
    grid-column: 1;
    grid-row: 1;
    position: sticky;
    top: 6.5rem;
    align-self: start;
    max-height: calc(100vh - 9rem);
    overflow-y: auto;
  }
}

.toc {
  padding-top: var(--space-lg);
  font-size: var(--text-sm);
}

.toc h2 {
  margin-bottom: var(--space-xs);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--accent);
}

.toc ol {
  display: grid;
  gap: var(--space-2xs);
  list-style: none;
  padding: 0;
  counter-reset: toc;
}

.toc li {
  counter-increment: toc;
}

.toc a {
  display: block;
  color: var(--ink-3);
  text-decoration: none;
  line-height: 1.35;
  transition: color 160ms var(--ease);
}

.toc a::before {
  content: counter(toc) '. ';
  font-variant-numeric: tabular-nums;
  color: var(--rule-strong);
}

.toc a:hover,
.toc a.is-active {
  color: var(--accent);
}

/* ─── Prose ──────────────────────────────────────────────────────────────── */

.prose {
  font-family: var(--serif);
  font-size: var(--text-prose);
  line-height: var(--prose-leading);
  color: var(--ink-2);
  padding-top: var(--space-lg);
}

.prose > * {
  max-width: var(--measure);
}

.prose > *:first-child {
  margin-top: 0;
}

.prose > p {
  margin-top: var(--space-md);
  text-wrap: pretty;
}

@media (min-width: 40rem) {
  .prose > p,
  .prose > ul li,
  .prose > ol li {
    text-align: justify;
    hyphens: auto;
    text-wrap: initial;
  }
}

.prose > h2,
.prose > h3,
.prose > h4 {
  position: relative;
  font-family: var(--sans);
  color: var(--ink);
  letter-spacing: -0.025em;
  line-height: 1.2;
  text-wrap: balance;
}

.prose > h2 {
  margin-top: var(--space-2xl);
  margin-bottom: var(--space-sm);
  padding-bottom: var(--space-2xs);
  font-size: var(--text-xl);
  font-weight: 600;
  color: var(--accent-bright);
  border-bottom: 1px solid var(--rule);
}

.prose > h3 {
  margin-top: var(--space-xl);
  margin-bottom: var(--space-2xs);
  font-size: 1.5rem;
  font-weight: 600;
}

.prose > h4 {
  margin-top: var(--space-lg);
  margin-bottom: var(--space-3xs);
  font-size: 1.1875rem;
  font-weight: 600;
  color: var(--ink-2);
}

.heading-anchor {
  position: absolute;
  left: -1.1em;
  color: var(--rule-strong);
  text-decoration: none;
  opacity: 0;
  transition: opacity 160ms var(--ease);
}

.prose :is(h2, h3, h4):hover .heading-anchor {
  opacity: 1;
}

.heading-anchor:hover {
  color: var(--accent);
}

.prose strong {
  font-weight: 600;
  color: var(--ink);
}

.prose a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.16em;
  text-decoration-color: color-mix(in oklch, var(--accent) 40%, transparent);
  transition: text-decoration-color 160ms var(--ease);
}

.prose a:hover {
  text-decoration-color: var(--accent);
}

.prose > ul,
.prose > ol {
  margin-top: var(--space-md);
  padding-left: 1.4em;
}

.prose li + li {
  margin-top: var(--space-2xs);
}

.prose > ul {
  list-style: none;
  padding-left: 1.1em;
}

.prose > ul > li {
  position: relative;
}

.prose > ul > li::before {
  content: '';
  position: absolute;
  left: -1.1em;
  top: 0.88em;
  width: 0.34em;
  height: 1px;
  background: var(--accent);
}

.prose > ol::marker,
.prose > ol > li::marker {
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}

.prose > blockquote {
  margin-top: var(--space-lg);
  margin-bottom: var(--space-lg);
  padding-left: var(--space-md);
  font-style: italic;
  color: var(--ink-3);
  box-shadow: inset 1px 0 0 var(--rule-strong);
}

.prose > hr {
  width: 5rem;
  margin-block: var(--space-2xl);
  border: 0;
  border-top: 1px solid var(--rule-strong);
}

.prose > .figure {
  max-width: min(52rem, 100%);
  margin-block: var(--space-xl);
}

.prose > .figure img {
  width: 100%;
  border: 1px solid var(--rule);
  border-radius: 2px;
  background: var(--paper-raised);
}

.prose figcaption {
  margin-top: var(--space-xs);
  font-size: var(--text-sm);
  line-height: 1.5;
  color: var(--ink-3);
  text-align: left;
}

.figure-embed iframe {
  display: block;
  width: 100%;
  border: 1px solid var(--rule);
  border-radius: 2px;
  background: var(--paper-raised);
}

.figure-embed .figure {
  margin: 0;
}

.figure-embed a {
  display: block;
}

.embed-pair {
  display: grid;
  gap: var(--space-sm);
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
}

/* ─── 3D scatter ─────────────────────────────────────────────────────────────
   The rotatable plots in the ASOIAF post, drawn on a canvas by
   scripts/scatter3d.js. The frame, tooltip and legend are ordinary elements, so
   they inherit the page's type and both colour schemes for free.
   ───────────────────────────────────────────────────────────────────────── */

.scatter3d-stage {
  position: relative;
  aspect-ratio: 3 / 2;
  min-height: 17rem;
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: 2px;
  overflow: hidden;
}

.scatter3d canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: pan-y; /* a sideways drag rotates, a vertical one still scrolls the page */
  cursor: grab;
}

.scatter3d.is-dragging canvas {
  cursor: grabbing;
}

.scatter3d-tools {
  position: absolute;
  top: var(--space-2xs);
  right: var(--space-2xs);
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity 160ms var(--ease);
}

.scatter3d-stage:hover .scatter3d-tools,
.scatter3d-stage:focus-within .scatter3d-tools {
  opacity: 1;
}

@media (hover: none) {
  .scatter3d-tools {
    opacity: 1;
  }
}

.scatter3d-tools button {
  display: grid;
  place-items: center;
  width: 1.7rem;
  height: 1.7rem;
  color: var(--ink-3);
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 2px;
}

.scatter3d-tools button:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.scatter3d-tools svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.3;
  stroke-linecap: round;
}

.scatter3d-tip {
  position: absolute;
  z-index: 2;
  padding: 0.3em 0.55em;
  font-family: var(--sans);
  font-size: var(--text-xs);
  line-height: 1.35;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--rule-strong);
  border-radius: 2px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 120ms var(--ease);
}

.scatter3d-tip.is-shown {
  opacity: 1;
}

.scatter3d-tip b {
  font-weight: 600;
  letter-spacing: 0.03em;
}

.scatter3d-tip span {
  display: block;
  color: var(--ink-3);
}

.scatter3d-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-3xs) var(--space-md);
  margin-top: var(--space-2xs);
}

.scatter3d-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2em 0.9em;
}

.scatter3d-legend button {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  font-family: var(--sans);
  font-size: var(--text-xs);
  letter-spacing: 0.04em;
  color: var(--ink-2);
}

.scatter3d-legend button:hover {
  color: var(--ink);
}

.scatter3d-legend button[aria-pressed='false'] {
  color: var(--ink-3);
  opacity: 0.55;
  text-decoration: line-through;
}

.scatter3d-swatch {
  flex: 0 0 auto;
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
}

.scatter3d-hint {
  margin-left: auto;
  font-size: var(--text-xs);
  color: var(--ink-3);
}

.scatter3d:fullscreen {
  display: flex;
  flex-direction: column;
  padding: var(--space-md);
  background: var(--paper);
}

.scatter3d:fullscreen .scatter3d-stage {
  flex: 1;
  aspect-ratio: auto;
}

/* Verse — song lyrics and quoted couplets, set apart by space, not by a box. */
.callout-verse {
  padding: 0;
  background: none;
  border: 0;
  margin-block: var(--space-xl);
  text-align: center;
  font-size: 1.0625rem;
  line-height: 1.75;
  color: var(--ink-3);
}

.callout-verse p + p {
  margin-top: var(--space-md);
}

/* Footnotes */
.note-ref {
  font-family: var(--sans);
  font-size: 0.7em;
  font-weight: 500;
  line-height: 0;
}

.note-ref a {
  padding: 0 0.15em;
  color: var(--accent);
  text-decoration: none;
}

.notes {
  max-width: var(--measure);
  margin-top: var(--space-2xl);
  padding-top: var(--space-md);
  border-top: 1px solid var(--rule);
  font-size: 0.9375rem;
  line-height: 1.6;
  color: var(--ink-3);
}

.notes h2 {
  margin-bottom: var(--space-xs);
  font-family: var(--sans);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--accent);
}

.notes ol {
  display: grid;
  gap: var(--space-2xs);
  padding-left: 1.3em;
}

.notes li::marker {
  color: var(--rule-strong);
}

.notes a {
  color: var(--accent);
}

.note-back {
  text-decoration: none;
}

:target {
  scroll-margin-top: 7rem;
}

.prose > .table-scroll {
  max-width: min(52rem, 100%);
  margin-block: var(--space-lg);
  overflow-x: auto;
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--sans);
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
}

.prose th,
.prose td {
  padding: var(--space-2xs) var(--space-sm);
  text-align: left;
  border-bottom: 1px solid var(--rule);
}

.prose th {
  font-weight: 600;
  color: var(--ink);
  border-bottom-color: var(--rule-strong);
}

.callout {
  margin-block: var(--space-lg);
  padding: var(--space-md) var(--space-lg);
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: 2px;
  font-size: 1.0625rem;
  color: var(--ink-2);
}

.callout > * + * {
  margin-top: var(--space-sm);
}

/* Math */

.math-block {
  margin-block: var(--space-lg);
  overflow-x: auto;
  overflow-y: hidden;
  padding-block: var(--space-2xs);
}

.katex {
  font-size: 1.02em;
}

/* Code */

.prose > .code,
.code {
  position: relative;
  max-width: min(52rem, 100%);
  margin-block: var(--space-lg);
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: 3px;
}

.code pre {
  margin: 0;
  padding: var(--space-md);
  overflow-x: auto;
}

.code code,
.prose code {
  font-family: var(--mono);
  font-variant-ligatures: none;
  font-size: 0.855em;
  line-height: 1.65;
}

.prose :not(pre) > code {
  padding: 0.1em 0.35em;
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: 2px;
  color: var(--ink);
  white-space: nowrap;
}

.code-lang {
  position: absolute;
  top: 0;
  right: 0;
  padding: 0.2rem 0.5rem;
  font-family: var(--sans);
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-3);
  border-left: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  border-bottom-left-radius: 3px;
}

.hljs {
  color: var(--ink);
}

.hljs-comment,
.hljs-quote {
  color: var(--ink-3);
  font-style: italic;
}

.hljs-keyword,
.hljs-selector-tag,
.hljs-literal,
.hljs-doctag {
  color: var(--accent);
}

.hljs-string,
.hljs-regexp,
.hljs-addition {
  color: oklch(48% 0.1 20);
}

:root[data-theme='dark'] .hljs-string,
:root[data-theme='dark'] .hljs-regexp,
:root[data-theme='dark'] .hljs-addition {
  color: oklch(78% 0.09 28);
}

.hljs-number,
.hljs-built_in,
.hljs-type {
  color: oklch(45% 0.11 285);
}

:root[data-theme='dark'] .hljs-number,
:root[data-theme='dark'] .hljs-built_in,
:root[data-theme='dark'] .hljs-type {
  color: oklch(80% 0.09 285);
}

.hljs-title,
.hljs-section,
.hljs-attr,
.hljs-name {
  color: var(--ink);
  font-weight: 600;
}

.hljs-meta,
.hljs-symbol,
.hljs-variable,
.hljs-params {
  color: var(--ink-2);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .hljs-string,
  :root:not([data-theme='light']) .hljs-regexp,
  :root:not([data-theme='light']) .hljs-addition {
    color: oklch(78% 0.09 28);
  }

  :root:not([data-theme='light']) .hljs-number,
  :root:not([data-theme='light']) .hljs-built_in,
  :root:not([data-theme='light']) .hljs-type {
    color: oklch(80% 0.09 285);
  }
}

/* ─── Post navigation ────────────────────────────────────────────────────── */

.post-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-md);
  padding-block: var(--space-xl) var(--space-3xl);
  border-top: 1px solid var(--rule);
}

.post-nav-item {
  display: grid;
  gap: var(--space-3xs);
  font-size: 1.0625rem;
  font-weight: 500;
  line-height: 1.35;
  letter-spacing: -0.015em;
  text-decoration: none;
  color: var(--ink);
  transition: color 160ms var(--ease);
}

.post-nav-item span {
  font-size: var(--text-xs);
  font-weight: 400;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.post-nav-next {
  text-align: right;
}

.post-nav-item:hover {
  color: var(--accent);
}

/* ─── Projects ───────────────────────────────────────────────────────────── */

.project-list {
  display: grid;
  gap: var(--space-3xl);
  padding-bottom: var(--space-3xl);
  border-top: 1px solid var(--rule);
  padding-top: var(--space-2xl);
}

.project {
  display: grid;
  gap: var(--space-lg);
  align-items: start;
  scroll-margin-top: 7rem;
}

@media (min-width: 52rem) {
  .project {
    grid-template-columns: minmax(0, 21rem) minmax(0, 1fr);
    gap: var(--space-2xl);
  }
}

.project-image {
  display: block;
  overflow: hidden;
  border: 1px solid var(--rule);
  border-radius: 2px;
  background: var(--paper-raised);
}

/* These are plots, not photographs — never crop them. */
.project-image img {
  width: 100%;
  transition: transform 700ms var(--ease);
}

.project-image:hover img {
  transform: scale(1.03);
}

.project-year {
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

.project-body h2 a {
  text-decoration: none;
  background-image: linear-gradient(var(--accent), var(--accent));
  background-size: 0% 1px;
  background-position: 0 100%;
  background-repeat: no-repeat;
  transition: background-size 320ms var(--ease), color 160ms var(--ease);
}

.project:hover h2 a,
.project-body h2 a:hover {
  color: var(--accent);
  background-size: 100% 1px;
}

.read-more {
  margin-top: var(--space-sm);
  font-size: var(--text-sm);
}

.read-more a {
  display: inline-flex;
  align-items: center;
  gap: 0.45em;
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid color-mix(in oklch, var(--accent) 35%, transparent);
  transition: border-color 160ms var(--ease);
}

.read-more svg {
  width: 1em;
  height: 0.75em;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  transition: transform 260ms var(--ease);
}

.read-more a:hover {
  border-color: var(--accent);
}

.read-more a:hover svg,
.project:hover .read-more svg {
  transform: translateX(3px);
}

.project-body h2 {
  margin-top: var(--space-3xs);
  font-size: var(--text-lg);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
  text-wrap: balance;
}

/* ─── Lightbox ───────────────────────────────────────────────────────────── */

.zoomable {
  cursor: zoom-in;
}

.lightbox {
  width: 100%;
  max-width: 100%;
  height: 100%;
  max-height: 100%;
  padding: clamp(var(--space-sm), 4vw, var(--space-2xl));
  border: 0;
  background: none;
  overflow: hidden;
  place-items: center;
  align-content: center;
  gap: var(--space-md);
  cursor: zoom-out;
}

.lightbox[open] {
  display: grid;
}

.lightbox::backdrop {
  background: color-mix(in oklch, var(--paper) 88%, transparent);
  backdrop-filter: blur(3px);
}

.lightbox img {
  max-width: 100%;
  max-height: 82vh;
  width: auto;
  object-fit: contain;
  border: 1px solid var(--rule);
  border-radius: 2px;
  background: var(--paper);
}

.lightbox-caption {
  max-width: 60ch;
  font-family: var(--serif);
  font-size: var(--text-sm);
  line-height: 1.5;
  text-align: center;
  color: var(--ink-3);
  cursor: auto;
}

.lightbox-caption a {
  color: var(--accent);
}

@media (prefers-reduced-motion: no-preference) {
  .lightbox[open] {
    animation: zoom-in 260ms var(--ease);
  }

  .lightbox[open]::backdrop {
    animation: fade-in 260ms var(--ease);
  }
}

@keyframes zoom-in {
  from {
    opacity: 0;
    transform: scale(0.97);
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

/* ─── Closing note ───────────────────────────────────────────────────────── */

.closing {
  display: grid;
  gap: var(--space-lg);
  padding-block: var(--space-2xl) var(--space-3xl);
  border-top: 1px solid var(--rule);
}

@media (min-width: 62rem) {
  .closing {
    grid-template-columns: var(--rail) minmax(0, 1fr);
    gap: var(--space-2xl);
  }
}

.closing h2 {
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--accent);
  padding-top: 0.4rem;
}

.closing-body {
  max-width: var(--measure);
  font-family: var(--serif);
  font-size: 1.0625rem;
  line-height: 1.7;
  color: var(--ink-2);
}

.closing-body > * + * {
  margin-top: var(--space-sm);
}

.closing-body a {
  color: var(--accent);
  text-underline-offset: 0.18em;
}

/* ─── Footer ─────────────────────────────────────────────────────────────── */

.site-footer {
  border-top: 1px solid var(--rule);
  padding-block: var(--space-lg);
}

.site-footer-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-sm) var(--space-lg);
  font-size: var(--text-sm);
  color: var(--ink-3);
}

.footer-mark {
  font-size: var(--text-base);
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-md);
}

.footer-links a {
  color: var(--ink-3);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: color 160ms var(--ease), border-color 160ms var(--ease);
}

.footer-links a:hover {
  color: var(--accent);
  border-color: var(--accent);
}

/* ─── Entrance ───────────────────────────────────────────────────────────── */

@media (prefers-reduced-motion: no-preference) {
  .masthead-text > *,
  .masthead-portrait,
  .lede {
    animation: rise 700ms var(--ease) backwards;
  }

  .masthead-text > *:nth-child(2) {
    animation-delay: 70ms;
  }

  .masthead-text > *:nth-child(3) {
    animation-delay: 130ms;
  }

  .masthead-portrait {
    animation-delay: 40ms;
  }

  .lede {
    animation-delay: 190ms;
  }
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(0.75rem);
  }
}

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

/* ─── Narrow viewports ───────────────────────────────────────────────────── */

@media (max-width: 61.99rem) {
  .split-rail {
    padding-top: var(--space-xl);
    border-top: 1px solid var(--rule);
    grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
    gap: var(--space-lg);
  }
}

@media (max-width: 40rem) {
  :root {
    --rail: 100%;
  }

  /* Wordmark and toggle on one row, navigation on the next. */
  .site-header-inner {
    flex-wrap: wrap;
    align-items: center;
    gap: 0 var(--space-md);
    padding-bottom: var(--space-2xs);
    min-height: 0;
  }

  .site-mark {
    min-height: 3.25rem;
    display: flex;
    align-items: center;
  }

  .site-nav {
    order: 3;
    width: 100%;
    justify-content: space-between;
    gap: var(--space-sm);
    margin-top: -0.25rem;
  }

  .site-header-home .site-mark {
    opacity: 1;
    transform: none;
    pointer-events: auto;
  }

  /* Column flex: leave align-items at stretch, or the text block sizes to
     max-content and the name runs off the screen. */
  .masthead {
    flex-direction: column-reverse;
    gap: var(--space-md);
  }

  .masthead-portrait {
    align-self: flex-start;
  }

  .entry {
    grid-template-columns: 2rem minmax(0, 1fr);
  }

  .mark {
    width: 1.25rem;
    height: 1.25rem;
  }

  .post-row {
    grid-template-columns: 7.5rem minmax(0, 1fr);
    grid-template-areas:
      'thumb date'
      'thumb text'
      'tags  tags';
    gap: var(--space-3xs) var(--space-sm);
  }

  .post-row-thumb {
    margin-top: 0.15rem;
  }

  .post-row .tags {
    margin-top: var(--space-2xs);
  }

  .year-label {
    position: static;
  }

  .post-nav {
    grid-template-columns: 1fr;
    gap: var(--space-lg);
  }

  .post-nav-next {
    text-align: left;
  }
}
