/* ================================================================
   Luca Jin — Theoretical Physics
   Aesthetic: Scholar's Notebook. Warm paper, classical serifs,
   oxblood accent, generous margins, subtle physics ornament.
   Designed for math-heavy reading on phone, tablet, laptop, desktop.
   ================================================================ */

:root {
  color-scheme: light;

  /* palette — light "warm paper" theme */
  --paper:        #f5f1e7;
  --paper-deep:   #ebe4d6;
  --paper-shade:  #e2d8c7;
  --ink:          #17130f;
  --ink-soft:     #2a241c;
  --muted:        #6b6053;
  --rule:         #cdc2a9;
  --rule-soft:    #e3dac3;
  --accent:       #792d2d;          /* oxblood */
  --accent-soft:  #8a3030;
  --accent-line:  rgba(107, 31, 31, 0.25);
  --highlight:    #b08732;          /* old gold */
  --callout-bg:   #fdf5dc;
  --shadow:       0 1px 2px rgba(20, 17, 13, 0.04);
  --shadow-soft:  0 6px 24px -12px rgba(20, 17, 13, 0.18);

  /* type */
  --display: 'Times New Roman', Times, serif;
  --body:    'Times New Roman', Times, serif;
  --mono:    'JetBrains Mono', 'Courier New', monospace;

  /* layout — measures in `ch` so text column scales with font.
     --measure-wide is generous (170ch) for the math notes so display
     equations like Schwartz P^μ derivations fit without overflowing
     onto a horizontal scrollbar on most desktop viewports. */
  --measure: 92ch;
  --measure-narrow: 60ch;
  --measure-wide: 170ch;
  --gutter: clamp(0.6rem, 2vw, 2.5rem);
  --rad: 2px;

  /* User-controlled multiplier on the root font-size, persisted in
     localStorage by font-size.js. 1 is neutral; A−/A+ buttons in the
     topbar step it in 0.1 increments between 0.7 and 1.5. Because
     almost every size in the stylesheet is in `rem` or `ch`, this
     scales the entire page (text, gutters, headings) uniformly. */
  --font-scale: 1;

  /* Motion tokens — single place for all animation curves and durations
     so the navigation chrome feels coherent. --ease-out is the gentle
     "ease-out-quint" curve used for reveals (drawers, fades, panels);
     --ease-snappy is the standard material ease for tiny hover states. */
  --ease-out:    cubic-bezier(0.16, 1, 0.3, 1);
  --ease-snappy: cubic-bezier(0.4, 0, 0.2, 1);
  --dur-fast:    0.18s;
  --dur-base:    0.28s;
  --dur-slow:    0.42s;
}

/* Dark "midnight study" theme — warm dark, terracotta accent */
[data-theme="dark"] {
  color-scheme: dark;

  --paper:        #15120e;
  --paper-deep:   #1f1b15;
  --paper-shade:  #28231c;
  --ink:          #f1e7d1;
  --ink-soft:     #d4c8ad;
  --muted:        #8c8170;
  --rule:         #3a342b;
  --rule-soft:    #2a251f;
  --accent:       #d68a6e;          /* warmed oxblood for dark bg */
  --accent-soft:  #e6a896;
  --accent-line:  rgba(214, 138, 110, 0.32);
  --highlight:    #d4a857;          /* lit gold */
  --callout-bg:   #2a2218;
  --shadow:       0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-soft:  0 8px 28px -14px rgba(0, 0, 0, 0.6);
}

@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;
  }
}

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

html {
  /* Font scales linearly with viewport so the page keeps LaTeX/A4-like
     proportions on every screen. Because --measure is in `ch` (and almost
     everything else is in `rem`), font and column grow together — the text
     column stays the same number of characters wide and the same fraction
     of the viewport, exactly like a LaTeX-typeset A4 sheet rescaled to a
     different physical size. The base scale is on the conservative side so
     it suits dense math reading; users can bump it up via the A+ button.
     The `--font-scale` multiplier is wired into the topbar A−/A+ control. */
  font-size: calc(clamp(14px, 0.95vw, 22px) * var(--font-scale, 1));
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--body);
  font-weight: 400;
  font-size: 1.08rem;
  line-height: 1.7;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
  transition: background-color 0.35s ease, color 0.35s ease;
}

/* Theme-fade: when the user toggles the theme, fade colors smoothly across
   most chrome. Keep transitions short to avoid feeling sluggish on nav. */
.topbar, .footer, .subnav,
.note__problem, .note__abstract, .note__toc,
aside.callout, aside.solution,
figure.tikz-figure, figure.tikz-source,
.tag, .entry, .catalogue__item, hr {
  transition: background-color 0.35s ease, border-color 0.35s ease, color 0.35s ease;
}

/* ---------- Typography ---------- */
h1, h2, h3, h4 {
  font-family: var(--display);
  font-weight: 500;
  letter-spacing: -0.005em;
  color: var(--ink);
  line-height: 1.18;
  text-wrap: balance;
}

h1 {
  font-size: clamp(2.4rem, 6vw, 4.4rem);
  font-weight: 400;
  font-style: italic;
  letter-spacing: -0.02em;
  margin: 0 0 0.4rem;
}

h2 {
  font-size: clamp(1.55rem, 3vw, 2.2rem);
  font-weight: 500;
  margin: 3.2rem 0 1rem;
  position: relative;
}

h2::before {
  content: "§";
  color: var(--accent);
  font-style: italic;
  margin-right: 0.5rem;
  font-weight: 400;
  opacity: 0.85;
}

h3 {
  font-size: clamp(1.15rem, 1.6vw, 1.3rem);
  font-weight: 500;
  margin: 1.8rem 0 0.5rem;
  color: var(--ink-soft);
}

p {
  margin: 0 0 1.1rem;
  text-wrap: pretty;
  hyphens: auto;
}

a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid var(--accent-line);
  transition: border-color 0.2s, color 0.2s;
}
a:hover, a:focus-visible {
  color: var(--accent-soft);
  border-bottom-color: var(--accent);
}
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--rad);
}

em { font-style: italic; }
strong { font-weight: 600; color: var(--ink); }
small { font-size: 0.85em; color: var(--muted); }

code, kbd {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--paper-deep);
  padding: 0.1em 0.35em;
  border-radius: var(--rad);
  word-break: break-word;
}

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

hr {
  border: 0;
  height: 1px;
  background: var(--rule);
  margin: 3rem auto;
  width: 60%;
}

/* an oxblood ornamental rule with a vertex dot in the middle */
hr.ornament-rule {
  position: relative;
  background: transparent;
  height: 12px;
  margin: 3rem auto;
}
hr.ornament-rule::before {
  content: "";
  position: absolute;
  left: 0; right: 0; top: 50%;
  height: 1px;
  background: linear-gradient(90deg,
    transparent 0%,
    var(--rule) 20%,
    var(--rule) 80%,
    transparent 100%);
}
hr.ornament-rule::after {
  content: "✦";
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -55%);
  background: var(--paper);
  color: var(--accent);
  padding: 0 0.6rem;
  font-size: 0.75rem;
}

/* ---------- Layout ----------
   The reading column grows with the viewport but stops at a comfortable
   measure so lines don't become unreadably long on huge screens.
   Note: scoped to main.page to avoid colliding with TikZJax's internal
   `<div class="page">` wrapper that it injects around every SVG.        */
main.page {
  width: min(var(--measure), calc(100vw - 2 * var(--gutter)));
  margin: 0 auto;
  padding: 3rem var(--gutter) 5rem;
}

main.page--index  { width: min(var(--measure-wide),  calc(100vw - 2 * var(--gutter))); }
main.page--wide   { width: min(var(--measure-wide),  calc(100vw - 2 * var(--gutter))); }
main.page--narrow { width: min(var(--measure-narrow), calc(100vw - 2 * var(--gutter))); }

/* ---------- Top bar ----------
   Full-viewport bar with internal content centered. This way the bar visibly
   spans whatever width the tab is, regardless of the reading column width. */
.topbar {
  width: 100%;
  padding: 1.2rem var(--gutter) 1rem;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  font-family: var(--display);
  font-size: 0.95rem;
  border-bottom: 1px solid var(--rule-soft);
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--paper);
}

.topbar > * { flex-shrink: 1; min-width: 0; }

.topbar__brand {
  font-style: italic;
  font-weight: 500;
  color: var(--ink);
  border: none;
  font-size: 1.1rem;
}

.topbar__brand small {
  font-style: normal;
  font-variant: small-caps;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-left: 0.4rem;
  font-size: 0.7rem;
}

.topbar__nav {
  display: flex;
  gap: clamp(0.9rem, 2.5vw, 1.8rem);
  flex-wrap: wrap;
}

.topbar__nav a {
  border: none;
  color: var(--ink-soft);
  font-variant: small-caps;
  letter-spacing: 0.08em;
  font-size: 0.85rem;
  position: relative;
  padding-bottom: 2px;
  transition: color var(--dur-fast) var(--ease-snappy);
}

/* Animated under-rule that grows from the centre on hover and stays full
   width when the link is active. Replaces the old `border-bottom` swap so
   the underline visibly slides in instead of snapping. */
.topbar__nav a::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 0;
  height: 1px;
  background: var(--accent);
  transform: translateX(-50%);
  transition: width var(--dur-base) var(--ease-out);
}
.topbar__nav a:hover, .topbar__nav a:focus-visible { color: var(--accent); }
.topbar__nav a:hover::after,
.topbar__nav a:focus-visible::after { width: 100%; }

.topbar__nav a.is-active { color: var(--accent); }
.topbar__nav a.is-active::after { width: 100%; }

/* ---------- Back to top ----------
   Floating circular button, fades in once the user has scrolled past the
   first viewport. Lives at body level (injected by theme.js) so it's
   independent of the reading-column layout. */
/* Floating page-controls cluster: Prev / Up / Next pill in the
   bottom-right of every page. The Up button always exists; Prev / Next
   are added by theme.js only on note pages. The cluster fades in once
   the user scrolls past the first viewport. */
.page-controls {
  position: fixed;
  right: clamp(16px, 2vw, 32px);
  bottom: clamp(16px, 2vw, 32px);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  border: 1px solid var(--rule);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow-soft);
  opacity: 0;
  transform: translateY(10px) scale(0.96);
  pointer-events: none;
  transition: opacity var(--dur-base) var(--ease-out),
              transform var(--dur-base) var(--ease-out);
  z-index: 10;
}
.page-controls.is-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}
.page-controls__btn {
  appearance: none;
  background: transparent;
  border: none;
  color: var(--ink-soft);
  width: 36px;
  height: 36px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  text-decoration: none;
  transition: color var(--dur-fast) var(--ease-snappy),
              background-color var(--dur-fast) var(--ease-snappy),
              transform var(--dur-fast) var(--ease-snappy);
  position: relative;
}
.page-controls__btn:hover,
.page-controls__btn:focus-visible {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}
.page-controls__btn:active { transform: scale(0.92); }
.page-controls__btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.page-controls__btn svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.page-controls__btn[aria-disabled="true"] {
  opacity: 0.3;
  cursor: not-allowed;
  pointer-events: none;
}
.page-controls__sep {
  width: 1px;
  height: 22px;
  background: var(--rule);
  flex: none;
}

/* Tooltip: shown on hover/focus of prev/next buttons so the user can
   see which note they're about to jump to without leaving the page. */
.page-controls__btn[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 10px);
  right: 0;
  white-space: nowrap;
  max-width: 16rem;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: var(--display);
  font-style: italic;
  font-size: 0.8rem;
  color: var(--ink-soft);
  background: var(--paper);
  border: 1px solid var(--rule);
  padding: 0.3rem 0.6rem;
  border-radius: var(--rad);
  box-shadow: var(--shadow-soft);
  opacity: 0;
  transform: translateY(4px);
  pointer-events: none;
  transition: opacity var(--dur-fast) var(--ease-snappy),
              transform var(--dur-fast) var(--ease-snappy);
}
.page-controls__btn[data-tip][data-side="left"]::after {
  right: auto;
  left: 0;
}
.page-controls__btn[data-tip]:hover::after,
.page-controls__btn[data-tip]:focus-visible::after {
  opacity: 1;
  transform: translateY(0);
}

/* Back-to-top retained as standalone button for backwards compatibility
   with any page that doesn't have the controls cluster — but the new
   cluster is preferred and built by theme.js on every page. */
.back-to-top {
  position: fixed;
  right: clamp(16px, 2vw, 32px);
  bottom: clamp(16px, 2vw, 32px);
  width: 42px;
  height: 42px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  border: 1px solid var(--rule);
  color: var(--ink-soft);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  box-shadow: var(--shadow-soft);
  transition: opacity var(--dur-base) var(--ease-out),
              transform var(--dur-base) var(--ease-out),
              color var(--dur-fast) var(--ease-snappy),
              border-color var(--dur-fast) var(--ease-snappy),
              background-color var(--dur-fast) var(--ease-snappy);
  z-index: 10;
}
.back-to-top.is-visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
.back-to-top:hover,
.back-to-top:focus-visible {
  color: var(--accent);
  border-color: var(--accent);
}
.back-to-top:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.back-to-top svg {
  width: 17px;
  height: 17px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- Note sidebar (chapter nav) ----------
   Fixed-position panel in the left margin of note pages. Built by theme.js
   from the note's <h2 id> / <h3 id> headings. Hidden on viewports too narrow
   to comfortably accommodate the reading column plus a sidebar. */
.note__sidebar {
  display: none;
  position: fixed;
  top: 6.5rem;
  left: var(--gutter);
  width: 11rem;
  max-height: calc(100vh - 9rem);
  overflow-y: auto;
  font-family: var(--display);
  font-size: 0.85rem;
  z-index: 4;
  scrollbar-width: thin;
}
@media (min-width: 1280px) {
  .note__sidebar { display: block; }
}
.note__sidebar-label {
  font-variant: small-caps;
  letter-spacing: 0.12em;
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 0.6rem;
  padding-left: 0.7rem;
}
.note__sidebar-list {
  list-style: none;
  padding: 0;
  margin: 0;
  border-left: 1px solid var(--rule-soft);
}
.note__sidebar-list li {
  margin: 0;
}
.note__sidebar-list a {
  display: block;
  border: none;
  color: var(--ink-soft);
  padding: 0.28rem 0.7rem;
  margin-left: -1px;
  border-left: 2px solid transparent;
  line-height: 1.35;
  transition: color 0.15s, border-color 0.15s;
}
.note__sidebar-list a:hover,
.note__sidebar-list a:focus-visible {
  color: var(--accent);
}
.note__sidebar-list a.is-active {
  color: var(--accent);
  border-left-color: var(--accent);
}
.note__sidebar-list .sidebar-h3 a {
  padding-left: 1.4rem;
  font-size: 0.78rem;
  color: var(--muted);
}
.note__sidebar-list .sidebar-h3 a.is-active {
  color: var(--accent);
}
.note__sidebar-list .sidebar-h4 a {
  padding-left: 2rem;
  font-size: 0.74rem;
  color: var(--muted);
}
.note__sidebar-list .sidebar-h4 a.is-active {
  color: var(--accent);
}

/* ---------- Site nav toggle (plain-text label) ----------
   Renders as a single line of small-caps text — "Topics ▾". It is pinned
   below the topbar on wide screens and joins the header navigation in the
   drawer layout. No background, border, or shadow: it reads as text. */
.site-nav-toggle {
  appearance: none;
  background: transparent;
  border: none;
  color: var(--ink-soft);
  cursor: pointer;
  padding: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.34rem;
  font-family: var(--display);
  font-variant: small-caps;
  letter-spacing: 0.14em;
  font-size: 0.82rem;
  position: fixed;
  /* Below the topbar — never overlapping it. The top value tracks the
     topbar's lower edge so the label sits just below it both at the
     top of the page and after scroll. */
  top: clamp(4.6rem, 5.4vw, 5.4rem);
  left: clamp(0.8rem, 1.6vw, 1.8rem);
  z-index: 35;
  transition: color var(--dur-fast) var(--ease-snappy);
}
.site-nav-toggle:hover,
.site-nav-toggle:focus-visible {
  color: var(--accent);
  background: transparent;
}
.site-nav-toggle__chevron {
  width: 12px;
  height: 12px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform var(--dur-base) var(--ease-out);
}
:root.nav-on .site-nav-toggle__chevron,
body.nav-on .site-nav-toggle__chevron {
  transform: rotate(180deg);
}

/* (no inline close button — the "Topics ▾" pill above the sidebar
   acts as the toggle for both opening and closing) */

/* ---------- Site nav (cross-page navigator) ----------
   Fixed-position panel listing every category and its notes. Built by
   theme.js from assets/nav-manifest.json. Visibility on both desktop
   and mobile is gated by body.nav-on so the user can hide/show via the
   topbar toggle or the × button on the rail. */
.site-nav {
  position: fixed;
  display: block;
  font-family: var(--display);
  font-size: 0.86rem;
  z-index: 30;
  scrollbar-width: thin;
}
.site-nav__label {
  font-variant: small-caps;
  letter-spacing: 0.12em;
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 0.55rem;
  padding-left: 0.7rem;
}
.site-nav__list {
  list-style: none;
  padding: 0;
  margin: 0;
  border-left: 1px solid var(--rule-soft);
}
.site-nav__cat { margin: 0; }
.site-nav__cat-head {
  appearance: none;
  background: transparent;
  border: none;
  color: var(--ink-soft);
  font: inherit;
  width: 100%;
  text-align: left;
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
  padding: 0.34rem 0.7rem;
  margin-left: -1px;
  border-left: 2px solid transparent;
  cursor: pointer;
  line-height: 1.3;
  transition: color var(--dur-fast) var(--ease-snappy),
              border-color var(--dur-base) var(--ease-out),
              background-color var(--dur-fast) var(--ease-snappy);
}
.site-nav__cat-head:hover {
  background: color-mix(in srgb, var(--accent) 4%, transparent);
}
.site-nav__caret {
  display: inline-block;
  font-size: 0.85em;
  color: var(--muted);
  transform: rotate(0deg);
  transform-origin: 50% 55%;
  transition: transform var(--dur-base) var(--ease-out),
              color var(--dur-fast) var(--ease-snappy);
  width: 0.6em;
  flex: none;
}
.site-nav__cat.is-current .site-nav__caret,
.site-nav__cat.is-open    .site-nav__caret {
  transform: rotate(90deg);
  color: var(--accent);
}

.site-nav__cat-title {
  border: none;
  color: inherit;
  flex: 1 1 auto;
  transition: color var(--dur-fast) var(--ease-snappy);
}
.site-nav__cat-head:hover .site-nav__cat-title,
.site-nav__cat-head:focus-visible .site-nav__cat-title { color: var(--accent); }
.site-nav__cat.is-current .site-nav__cat-title { color: var(--accent); }
.site-nav__cat.is-current .site-nav__cat-head { border-left-color: var(--accent); }

/* Smooth grid-row collapse: animating grid-template-rows from 0fr → 1fr
   gives a perfectly content-sized slide regardless of how many notes
   are inside, and avoids the easing distortion that comes from picking
   an arbitrary max-height. Falls back gracefully in older browsers. */
.site-nav__notes-wrap {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows var(--dur-base) var(--ease-out);
}
.site-nav__cat.is-current .site-nav__notes-wrap,
.site-nav__cat.is-open    .site-nav__notes-wrap {
  grid-template-rows: 1fr;
}
.site-nav__notes-inner {
  overflow: hidden;
  min-height: 0;
}
.site-nav__notes {
  list-style: none;
  padding: 0.15rem 0 0.5rem 0;
  margin: 0;
  /* Stagger reveal of notes — applied by JS when category opens */
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity var(--dur-base) var(--ease-out) 0.05s,
              transform var(--dur-base) var(--ease-out) 0.05s;
}
.site-nav__cat.is-current .site-nav__notes,
.site-nav__cat.is-open    .site-nav__notes {
  opacity: 1;
  transform: translateY(0);
}
.site-nav__notes li { margin: 0; }
.site-nav__notes a {
  display: block;
  border: none;
  color: var(--muted);
  padding: 0.22rem 0.7rem 0.22rem 1.6rem;
  font-size: 0.8rem;
  line-height: 1.34;
  border-left: 2px solid transparent;
  margin-left: -1px;
  transition: color var(--dur-fast) var(--ease-snappy),
              border-color var(--dur-fast) var(--ease-snappy),
              padding-left var(--dur-base) var(--ease-out),
              background-color var(--dur-fast) var(--ease-snappy);
}
.site-nav__notes a:hover,
.site-nav__notes a:focus-visible {
  color: var(--accent);
  padding-left: 1.75rem;
  background: color-mix(in srgb, var(--accent) 4%, transparent);
}
.site-nav__notes a.is-active {
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 500;
}
.site-nav__foot {
  display: inline-block;
  border: none;
  color: var(--muted);
  font-variant: small-caps;
  letter-spacing: 0.1em;
  font-size: 0.72rem;
  margin-top: 0.8rem;
  padding: 0.25rem 0.6rem 0.25rem 0.7rem;
  border-radius: 999px;
  transition: color var(--dur-fast) var(--ease-snappy),
              background-color var(--dur-fast) var(--ease-snappy);
}
.site-nav__foot:hover, .site-nav__foot:focus-visible {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 6%, transparent);
}

/* ---------- Sidebar visibility: shared mechanism ----------
   On every viewport, the sidebar is hidden by default and revealed by
   adding body.nav-on. The transform drives the slide animation; the
   media queries below customise where the rail sits and (on desktop)
   how the page content shifts to make room for it. */

/* Desktop: rail sits in the left margin; body padding shifts the
   content right so the sidebar never covers it. Hidden state slides
   the rail off-screen and removes the padding, returning content to
   its centered, full-width position. */
@media (min-width: 1280px) {
  .site-nav {
    /* Sits just below the "Topics ▾" pill. Top edge stays put across
       open/close — only the bottom edge animates, so the contents
       gently fall down out of the pill and back up into it on close.
       Borderless and shadowless: the rail reads as paper-on-paper,
       so it feels like the page itself unfolded. */
    top: clamp(6.4rem, 7vw, 7.2rem);
    left: clamp(0.8rem, 1.6vw, 1.8rem);
    width: 13.5rem;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0.7rem 0.7rem 0.9rem 0.9rem;
    background: var(--paper);
    /* Hidden: clipped to zero height, faded out, no clicks. */
    max-height: 0;
    opacity: 0;
    pointer-events: none;
    /* Slow, gentle glide — paired with the tighter max-height cap above
       so the height genuinely animates across the full duration. */
    transition: max-height 1.1s var(--ease-out),
                opacity   0.7s var(--ease-out) 0.05s;
  }
  :root.nav-on .site-nav,
  body.nav-on .site-nav {
    /* Open: cap max-height to a value close to typical content
       (≈ 7 categories collapsed) so the animation actually traverses
       the full duration instead of finishing the visual change in the
       first 0.3 s. The viewport-relative cap still wins on shorter
       windows, and overflow-y: auto handles the case where the user
       has many categories expanded. */
    max-height: min(calc(100vh - 8.5rem), 34rem);
    opacity: 1;
    pointer-events: auto;
  }
  /* Drawer overlays the left margin instead of nudging body content
     right — the page column stays put and the rail simply "falls down"
     from beneath the Topics ▾ pill via its own max-height transition.
     Reading column on most viewports is centred with margins wider than
     the 14.5 rem rail, so it never overlaps; on narrow desktops the
     rail just floats over the gutter. */

  /* On-page TOC (h2/h3) lives on the right edge, opposite the rail. */
  .note__sidebar { left: auto; right: clamp(0.5rem, 1.4vw, 1.8rem); }
}

/* Mobile / tablet: drawer overlay with backdrop. No content shift —
   instead an overlay tints the rest of the page until dismissed. */
@media (max-width: 1279.98px) {
  .site-nav-toggle {
    position: static;
    flex: 0 0 auto;
  }
  .site-nav {
    top: 0;
    left: 0;
    width: min(18rem, 80vw);
    height: 100dvh;
    max-height: 100dvh;
    background: var(--paper);
    border-right: 1px solid var(--rule);
    box-shadow: var(--shadow-soft);
    padding: 1.4rem 0.8rem 1.4rem 1.1rem;
    transform: translateX(-105%);
    transition: transform var(--dur-slow) var(--ease-out);
  }
  :root.nav-on .site-nav,
  body.nav-on .site-nav { transform: translateX(0); }
  body.nav-on::before {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 20;
    animation: backdrop-in var(--dur-slow) var(--ease-out);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
  }
}
@keyframes backdrop-in {
  from { opacity: 0; -webkit-backdrop-filter: blur(0); backdrop-filter: blur(0); }
  to   { opacity: 1; -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px); }
}

/* ---------- Prev / Next pager ----------
   Two-column row injected at the end of every note. Left = previous,
   right = next, within the current category. The label arrows nudge in
   the travel direction on hover for a tactile feel. */
.note__pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin: 3rem 0 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--rule-soft);
}
.note__pager-side { min-width: 0; }
.note__pager-side--next { text-align: right; }
.note__pager-link {
  display: block;
  border: 1px solid var(--rule-soft);
  border-radius: var(--rad);
  padding: 0.75rem 0.95rem;
  text-decoration: none;
  color: var(--ink-soft);
  background: color-mix(in srgb, var(--paper-deep) 30%, transparent);
  transition: border-color var(--dur-base) var(--ease-out),
              color      var(--dur-fast) var(--ease-snappy),
              background-color var(--dur-fast) var(--ease-snappy),
              transform   var(--dur-base) var(--ease-out),
              box-shadow  var(--dur-base) var(--ease-out);
}
.note__pager-link:hover,
.note__pager-link:focus-visible {
  color: var(--accent);
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow-soft);
  background: var(--paper);
}
.note__pager-link:active { transform: translateY(0); box-shadow: none; }
.note__pager-label {
  display: block;
  font-family: var(--display);
  font-variant: small-caps;
  letter-spacing: 0.1em;
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 0.22rem;
  transition: color var(--dur-fast) var(--ease-snappy),
              transform var(--dur-base) var(--ease-out);
}
.note__pager-link:hover .note__pager-label,
.note__pager-link:focus-visible .note__pager-label { color: var(--accent); }
.note__pager-side--prev .note__pager-link:hover .note__pager-label,
.note__pager-side--prev .note__pager-link:focus-visible .note__pager-label {
  transform: translateX(-3px);
}
.note__pager-side--next .note__pager-link:hover .note__pager-label,
.note__pager-side--next .note__pager-link:focus-visible .note__pager-label {
  transform: translateX(3px);
}
.note__pager-title {
  display: block;
  font-family: var(--display);
  font-style: italic;
  font-size: 1.02rem;
  line-height: 1.3;
  color: inherit;
}
@media (max-width: 540px) {
  .note__pager { grid-template-columns: 1fr; }
  .note__pager-side--next { text-align: left; }
}

/* Make the current crumb visually distinct. */
.note__breadcrumb-here {
  color: var(--ink-soft);
}

/* ---------- Theme toggle ----------
   A small icon button at the right edge of the topbar nav. Houses two icons
   (sun / moon); CSS hides whichever doesn't match the current theme. */
.theme-toggle {
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: 999px;
  width: 2rem;
  height: 2rem;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-soft);
  cursor: pointer;
  font-family: var(--display);
  line-height: 1;
  margin-left: 0.4rem;
  transition: color 0.2s, border-color 0.2s, background-color 0.2s, transform 0.3s;
}
.theme-toggle:hover,
.theme-toggle:focus-visible {
  color: var(--accent);
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}
.theme-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.theme-toggle:active { transform: rotate(-12deg) scale(0.92); }
.theme-toggle {
  position: relative;
  overflow: hidden;
}
.theme-toggle svg {
  width: 1rem;
  height: 1rem;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-linejoin: round;
  position: absolute;
  inset: 0;
  margin: auto;
  transition: opacity var(--dur-base) var(--ease-snappy),
              transform var(--dur-base) var(--ease-out);
  transform-origin: center;
}
/* Both icons stay in the DOM; we crossfade + rotate so the swap looks
   like the moon spins out as the sun rises in (and vice versa) instead
   of one snapping over the other. */
.theme-toggle .icon-sun  { opacity: 0; transform: rotate(-90deg) scale(0.6); }
.theme-toggle .icon-moon { opacity: 1; transform: rotate(0deg) scale(1); }
[data-theme="dark"] .theme-toggle .icon-sun  { opacity: 1; transform: rotate(0deg) scale(1); }
[data-theme="dark"] .theme-toggle .icon-moon { opacity: 0; transform: rotate(90deg) scale(0.6); }

/* ---------- Font-size control ----------
   A−/A+ pair in the topbar that nudges the root font-size by 10% per
   click. Visually pairs with .theme-toggle. */
.font-toggle {
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: 999px;
  height: 2rem;
  min-width: 2rem;
  padding: 0 0.55rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-soft);
  cursor: pointer;
  font-family: var(--display);
  font-size: 0.85rem;
  font-weight: 500;
  line-height: 1;
  margin-left: 0.3rem;
  transition: color 0.2s, border-color 0.2s, background-color 0.2s;
}
.font-toggle:hover,
.font-toggle:focus-visible {
  color: var(--accent);
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}
.font-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.font-toggle__small { font-size: 0.7em; }
.font-toggle__large { font-size: 1em; }

/* ---------- Sub navigation (topic anchors) ---------- */
.subnav {
  position: sticky;
  top: 0;
  z-index: 5;
  width: 100%;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
  padding: 0.55rem var(--gutter);
  font-family: var(--display);
  font-size: 0.82rem;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  background: color-mix(in srgb, var(--paper) 92%, transparent);
}

.subnav__inner {
  width: min(var(--measure-wide), 100%);
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 1.4rem;
  align-items: baseline;
  overflow-x: auto;
  scrollbar-width: thin;
}

.subnav a {
  border: none;
  color: var(--ink-soft);
  font-variant: small-caps;
  letter-spacing: 0.08em;
  white-space: nowrap;
  padding: 0.15rem 0;
}

.subnav a:hover, .subnav a:focus-visible {
  color: var(--accent);
}

.subnav__label {
  color: var(--muted);
  font-style: italic;
  margin-right: 0.4rem;
  font-variant: normal;
  letter-spacing: 0;
}

/* anchored sections need scroll-margin so they don't slip under the sticky bar */
.section[id], h2[id] {
  scroll-margin-top: 4.5rem;
}

/* ---------- Hero ---------- */
.hero {
  padding-top: 2.2rem;
  padding-bottom: 1.4rem;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 2.5rem;
  position: relative;
}

.hero__eyebrow {
  font-family: var(--display);
  font-variant: small-caps;
  letter-spacing: 0.18em;
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 1.2rem;
}

.hero__lede {
  font-family: var(--display);
  font-style: italic;
  font-size: clamp(1.1rem, 2vw, 1.4rem);
  color: var(--ink-soft);
  max-width: var(--measure-narrow);
  line-height: 1.5;
  margin: 0.6rem 0 1.6rem;
}

.hero__contents {
  max-width: var(--measure-narrow);
  margin: 0.6rem 0 1.6rem;
  padding-left: 1.35rem;
  color: var(--ink-soft);
  font-family: var(--display);
  font-size: clamp(1.05rem, 1.8vw, 1.25rem);
  line-height: 1.5;
}

.hero__contents li { margin: 0.15rem 0; }
.hero__contents li::marker { color: var(--accent); }

.hero__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem 2rem;
  font-size: 0.92rem;
  color: var(--muted);
  margin-bottom: 0.6rem;
}

.hero__meta a { color: var(--ink-soft); border-bottom-color: var(--rule); }
.hero__meta a:hover { color: var(--accent); border-bottom-color: var(--accent); }

/* drop cap on first paragraph after hero */
.dropcap::first-letter {
  font-family: var(--display);
  font-style: italic;
  font-weight: 500;
  font-size: 4.5rem;
  line-height: 0.9;
  float: left;
  padding: 0.3rem 0.5rem 0 0;
  color: var(--accent);
}

/* ---------- Sections ---------- */
.section { margin-bottom: 1rem; }

.entry {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.3rem;
  padding: 1rem 0;
  border-bottom: 1px dotted var(--rule);
}

.entry:last-child { border-bottom: none; }

.entry__head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.3rem 0.8rem;
}

.entry__title {
  font-family: var(--display);
  font-weight: 500;
  font-size: clamp(1.05rem, 1.6vw, 1.18rem);
  color: var(--ink);
}

.entry__date {
  font-family: var(--display);
  font-style: italic;
  color: var(--muted);
  font-size: 0.92rem;
  white-space: nowrap;
}

.entry__sub {
  font-style: italic;
  color: var(--muted);
  font-size: 0.95rem;
}

.entry__body {
  margin-top: 0.5rem;
  color: var(--ink-soft);
}

.entry__body ul {
  list-style: none;
  padding-left: 0;
  margin: 0.4rem 0;
}

.entry__body li {
  padding-left: 1.2rem;
  position: relative;
  margin-bottom: 0.25rem;
}

.entry__body li::before {
  content: "—";
  color: var(--accent);
  position: absolute;
  left: 0;
}

/* ---------- Notes index (catalogue) ----------
   2-col layout: [numeral][title + tag flowing inline]. Tag floats next to the
   title at wide widths, drops below when there isn't room — no media query
   needed.                                                                   */
.catalogue {
  list-style: none;
  padding: 0;
  margin: 1.2rem 0 0;
  display: grid;
  gap: 0.2rem;
}

.catalogue__item {
  padding: 1rem 0;
  border-bottom: 1px solid var(--rule);
  display: grid;
  /* Widened a touch so long markers ("PS4.") don't crowd the title;
     column gap also bumped from 1rem → 1.4rem so even short Roman
     numerals get a comfortable separation from the heading. */
  grid-template-columns: minmax(2.6rem, 4.4rem) 1fr;
  gap: 0.4rem 1.4rem;
  align-items: baseline;
}

.catalogue__main { min-width: 0; }      /* lets long titles wrap inside grid */

.catalogue__item:last-child { border-bottom: none; }

.catalogue-source {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.65rem 2rem;
  margin-top: 2.35rem;
  padding-bottom: 0.55rem;
  border-bottom: 1px solid var(--rule-soft);
}

.catalogue-source > a {
  flex: 0 0 auto;
  font-size: 0.72rem;
  font-variant: small-caps;
  letter-spacing: 0.09em;
  white-space: nowrap;
}

.catalogue-source + .catalogue { margin-top: 0.35rem; }

.catalogue__num {
  font-family: var(--display);
  font-style: italic;
  font-size: 1.4rem;
  color: var(--accent);
  font-feature-settings: "lnum";
}

.catalogue__main a {
  border: none;
  color: var(--ink);
  font-family: var(--display);
  font-size: clamp(1.1rem, 1.6vw, 1.25rem);
  font-weight: 500;
}

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

/* draft entries: muted, no link affordance */
.catalogue__main--draft {
  color: var(--muted);
  font-family: var(--display);
  font-size: clamp(1.1rem, 1.6vw, 1.25rem);
  font-weight: 500;
  font-style: italic;
}

.catalogue__desc {
  display: block;
  color: var(--muted);
  font-style: italic;
  font-size: 0.95rem;
  margin-top: 0.15rem;
}

.catalogue__tag {
  font-family: var(--display);
  font-variant: small-caps;
  letter-spacing: 0.1em;
  color: var(--muted);
  font-size: 0.78rem;
  grid-column: 2;
  margin-top: 0.2rem;
  white-space: nowrap;
}

.catalogue__tag--draft {
  color: var(--highlight);
  font-style: italic;
}

/* ---------- Archive format controls ---------- */
.catalogue__item {
  grid-template-columns: minmax(2.6rem, 4.4rem) minmax(0, 1fr) auto;
}

.catalogue__formats,
.note__formats {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-family: var(--display);
  font-variant: small-caps;
  letter-spacing: 0.08em;
  font-size: 0.74rem;
}

.catalogue__formats {
  grid-column: 3;
  grid-row: 1 / span 2;
  align-self: center;
}

.catalogue__formats a,
.note__formats a {
  min-height: 2rem;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.65rem;
  border: 1px solid var(--rule);
  color: var(--ink-soft);
  background: transparent;
}

.catalogue__formats a:hover,
.note__formats a:hover {
  color: var(--paper);
  border-color: var(--accent);
  background: var(--accent);
}

.note__formats {
  justify-content: flex-end;
  margin: 1.35rem 0 2rem;
  padding-block: 0.75rem;
  border-block: 1px solid var(--rule-soft);
}

.note__formats > span { margin-right: auto; color: var(--muted); }
.note__formats a[aria-current="page"] { color: var(--accent); border-color: var(--accent-line); }

.subject-index {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: 0 0 clamp(4rem, 8vw, 7rem);
  border-top: 1px solid var(--ink);
}

.subject-link {
  display: flex;
  justify-content: space-between;
  gap: 1.5rem;
  padding: 1rem 0;
  border-bottom: 1px solid var(--rule);
  color: var(--ink);
}

.subject-link:nth-child(odd) { padding-right: 1.5rem; }
.subject-link:nth-child(even) { padding-left: 1.5rem; border-left: 1px solid var(--rule); }
.subject-link span { font-size: 1.1rem; }
.subject-link small { white-space: nowrap; }
.subject-link:hover { color: var(--accent); }

.work-subject { padding-top: clamp(2rem, 4vw, 4rem); }
.work-subject + .work-subject { margin-top: clamp(4rem, 8vw, 7rem); border-top: 1px solid var(--ink); }
.work-subject__heading { display: flex; justify-content: space-between; align-items: end; gap: 2rem; margin-bottom: 2rem; }
.work-subject__heading h2 { margin: 0.35rem 0 0; }
.work-subject__heading > a { flex: 0 0 auto; font-family: var(--display); font-variant: small-caps; letter-spacing: .08em; font-size: .78rem; }

.entry--project { padding-block: 2rem; }
.entry--project .catalogue__formats { grid-column: auto; grid-row: auto; margin-top: .5rem; }
.project-page__eyebrow { margin: 2rem 0 .8rem; color: var(--accent); font-variant: small-caps; letter-spacing: .1em; }
.project-page .note__title { max-width: 19ch; }
.research-interests { max-width: 70ch; margin-top: 5rem; }

@media (max-width: 700px) {
  .catalogue__item { grid-template-columns: 2.7rem minmax(0, 1fr); }
  .catalogue__formats { grid-column: 2; grid-row: auto; justify-self: start; margin-top: .45rem; }
  .catalogue-source { align-items: flex-start; flex-direction: column; }
  .subject-index { grid-template-columns: 1fr; }
  .subject-link:nth-child(odd), .subject-link:nth-child(even) { padding-inline: 0; border-left: 0; }
  .work-subject__heading { align-items: flex-start; flex-direction: column; }
  .note__formats { justify-content: flex-start; flex-wrap: wrap; }
  .note__formats > span { width: 100%; margin-right: 0; }
}

/* ---------- Tags / pills ---------- */
.tags {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-top: 0.4rem;
}

.tag {
  font-family: var(--display);
  font-variant: small-caps;
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  padding: 0.15rem 0.55rem;
  border: 1px solid var(--rule);
  color: var(--muted);
  border-radius: var(--rad);
  transition: color var(--dur-fast) var(--ease-snappy),
              border-color var(--dur-fast) var(--ease-snappy),
              background-color var(--dur-fast) var(--ease-snappy),
              transform var(--dur-fast) var(--ease-snappy);
}
.tag:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 6%, transparent);
  transform: translateY(-1px);
}

/* ---------- Footer ----------
   Same full-bleed strategy as the topbar.                                  */
.footer {
  width: 100%;
  padding: 2.5rem var(--gutter) 3rem;
  border-top: 1px solid var(--rule);
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.6rem 1.2rem;
  font-size: 0.88rem;
  color: var(--muted);
  font-style: italic;
  font-family: var(--display);
}

.footer a { color: var(--muted); border-bottom-color: var(--rule); }
.footer a:hover { color: var(--accent); border-bottom-color: var(--accent); }

.footer__disclaimer {
  flex: 1 0 100%;
  max-width: 52rem;
  margin: 0 0 0.45rem;
  color: var(--ink-soft);
  font-style: normal;
}

/* ---------- Notes page (math content) ----------
   Math notes use --measure-wide (140 ch) rather than the prose --measure
   so display equations and TikZ diagrams have room. MathJax sets
   `min-width` on display equations in `em` — long integrals can need
   45–50 em, and with a smaller font cap that still spills past a 92-ch
   column. Keeping the limit in ch preserves the A4-like "constant
   chars per line" behavior; only the count is bumped.                  */
.note {
  width: min(var(--measure-wide), calc(100vw - 2 * var(--gutter)));
  margin: 0 auto;
  padding: 2.5rem var(--gutter) 6rem;
  overflow-wrap: break-word;
}

/* When the sticky sidebar shows, reserve room on the left so the body text
   doesn't run under it. The column shifts right rather than staying centered. */
@media (min-width: 1280px) {
  .note {
    margin-left: calc(11rem + var(--gutter) + 1.5rem);
    margin-right: auto;
    width: min(var(--measure),
      calc(100vw - 11rem - 2 * var(--gutter) - 1.5rem));
  }
}

.note__breadcrumb {
  font-family: var(--display);
  font-variant: small-caps;
  letter-spacing: 0.12em;
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 1rem;
}

.note__breadcrumb a { border: none; color: var(--ink-soft); }

.note__title {
  font-size: clamp(1.9rem, 4vw, 2.8rem);
  margin: 0 0 0.3rem;
  font-style: normal;
}

.note__subtitle {
  font-style: italic;
  color: var(--muted);
  font-family: var(--display);
  margin-bottom: 2.2rem;
  font-size: clamp(1rem, 1.6vw, 1.1rem);
}

.note h2, .note h3 { margin-top: 2.2rem; }
.note h2::before { content: ""; margin: 0; }
.note h2 {
  font-size: clamp(1.35rem, 2.2vw, 1.6rem);
  border-bottom: 1px solid var(--rule);
  padding-bottom: 0.3rem;
}
.note h3[data-section-heading] {
  font-size: clamp(1.12rem, 1.7vw, 1.3rem);
  color: var(--ink);
}
.note h4[data-section-heading] {
  margin: 1.7rem 0 0.55rem;
  font-family: var(--display);
  font-size: clamp(1rem, 1.45vw, 1.14rem);
  font-weight: 500;
  color: var(--ink-soft);
}
.note [data-section-heading] {
  scroll-margin-top: 7rem;
}
.note__heading-number {
  display: inline-block;
  margin-right: 0.55em;
  color: var(--accent);
  font-variant-numeric: tabular-nums lining-nums;
  font-style: normal;
}

.note__problem,
.note__abstract {
  background: var(--paper-deep);
  border-left: 3px solid var(--accent);
  padding: 1rem 1.4rem;
  margin: 1.5rem 0;
  font-size: 0.98rem;
  border-radius: 0 var(--rad) var(--rad) 0;
}

.note__problem-label,
.note__abstract-label {
  font-family: var(--display);
  font-variant: small-caps;
  letter-spacing: 0.12em;
  color: var(--accent);
  font-size: 0.78rem;
  display: block;
  margin-bottom: 0.4rem;
}

.note figure {
  margin: 1.8rem 0;
  text-align: center;
}
.note figure img {
  border: 1px solid var(--rule);
  border-radius: var(--rad);
  max-width: min(100%, 32rem);
  transition: filter 0.35s ease;
}

/* Dark mode: raster line-drawing figures (PNGs from LaTeX, etc.) ship
   with white backgrounds and dark strokes. invert + hue-rotate flips
   them so the "paper" becomes near-black (0.92 stops just shy of full
   so it sits at ≈ rgb(20,20,20), matching the page paper) and any
   colour content keeps its hue. Opt-out for any figure that is a
   photograph or already dark-themed: add class="no-invert" to <img>. */
[data-theme="dark"] .note figure img:not(.no-invert) {
  filter: invert(0.92) hue-rotate(180deg);
}
.note figcaption {
  font-family: var(--display);
  font-style: italic;
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: 0.5rem;
}
.note__figure-number {
  color: var(--accent);
  font-style: normal;
  font-variant: small-caps;
  letter-spacing: 0.03em;
}

.note__citation {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.note__citation a {
  color: var(--accent);
  text-decoration: none;
}
.note__citation a:hover,
.note__citation a:focus-visible {
  text-decoration: underline;
  text-underline-offset: 0.18em;
}
.note__references {
  margin-top: 4.5rem;
  padding-top: 1.7rem;
  border-top: 1px solid var(--rule);
}
.note__references h2 {
  margin: 0 0 1.5rem;
}
.note__references ol {
  margin: 0;
  padding-left: 2rem;
}
.note__references li {
  margin: 0 0 1rem;
  padding-left: 0.5rem;
}
.note__references li::marker {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

/* TikZ figures (pre-rendered to inline SVG by build/svg_render.py). The
   diagram sits inline with the surrounding prose like a math display.
   SVG uses currentColor for strokes/fills, so it inherits the page's
   text color and just works in light + dark mode. */
.note figure.tikz-figure {
  background: transparent;
  padding: 0.2rem 0;
  border: none;
  text-align: center;
  display: block;
  width: max-content;
  max-width: 100%;
  margin: 1.4rem auto;
  overflow: visible;
}
.note figure.tikz-figure svg {
  color: var(--ink);
  /* SVG carries its natural width/height in `em` units (build/svg_render
     bakes `pt × 0.135 em` into each SVG so it scales with the user's
     font-size while keeping LaTeX-faithful proportions). max-height
     caps very tall diagrams (Rutherford, t/u-channel Møller, etc.) so
     they don't dominate the page; max-width caps wide schematics on
     small viewports. The cap is intentionally generous (≈ 18em) so
     that intrinsically tall-narrow diagrams render close to their
     LaTeX size — clipping them harder makes them appear smaller than
     wider diagrams of comparable intrinsic area, which inverts the
     visual hierarchy the LaTeX source intended. */
  max-width: 100%;
  max-height: 18em;
  height: auto;
  width: auto;
}

/* Wick-contraction equations are pre-rendered to SVG (simpler-wick is
   not supported by MathJax). The figure sits in the document flow like
   a numbered display equation. */
.note figure.wick-figure {
  display: block;
  margin: 1.4rem auto;
  text-align: center;
  background: transparent;
  border: none;
  padding: 0.2rem 0;
  max-width: 100%;
  overflow-x: auto;
}
.note figure.wick-figure svg {
  color: var(--ink);
  /* SVG carries its natural em-based width — same scheme as tikz-figure. */
  max-width: 100%;
  height: auto;
}

/* Inside an equation row the figure is a flex item — let the SVG's
   intrinsic dimensions drive sizing; no border, no padding override. */
.equation-row figure.tikz-figure {
  padding: 0;
  margin: 0 0.4rem;
  background: transparent;
  border: none;
  flex: 0 0 auto;
  max-width: 100%;
}

/* Equation rows that contain inline TikZ figures.  Visually presents the
   equation parts and the diagram on a single (wrapping) row, with the
   equation number floated to the right edge — like a numbered display
   equation in a textbook. */
.note .equation-row {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.4rem 1rem;
  margin: 1.6rem 0;
  position: relative;
  padding-right: 3rem;          /* room for the number */
}
.note .equation-row .equation-part {
  display: inline-block;
}
.note .equation-row > figure.tikz-figure,
.note .equation-row > figure.tikz-source {
  margin: 0;
  flex: 0 0 auto;
}
.note .equation-num {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  font-family: var(--display);
  font-style: italic;
  color: var(--muted);
  font-size: 0.95rem;
}
@media (max-width: 700px) {
  .note .equation-row { padding-right: 0; }
  .note .equation-num {
    position: static;
    transform: none;
    display: block;
    width: 100%;
    text-align: right;
    margin-top: 0.3rem;
  }
}

/* Per-page table of contents */
.note__toc {
  margin: 1.5rem 0 2.5rem;
  padding: 1rem 1.4rem;
  border: 1px solid var(--rule);
  border-radius: var(--rad);
  background: var(--paper-deep);
  font-family: var(--display);
  font-size: 0.95rem;
}
.note__toc-label {
  font-variant: small-caps;
  letter-spacing: 0.12em;
  color: var(--muted);
  font-size: 0.78rem;
  margin-bottom: 0.5rem;
}
.note__toc-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.note__toc-list li {
  break-inside: avoid;
  padding: 0.12rem 0;
}
.note__toc-list li.toc-h2 {
  font-weight: 500;
}
.note__toc-list li.toc-h3 {
  padding-left: 1.2rem;
  font-size: 0.9em;
  color: var(--ink-soft);
}
.note__toc-list li.toc-h4 {
  padding-left: 2.4rem;
  font-size: 0.84em;
  color: var(--muted);
}
.note__toc a {
  display: grid;
  grid-template-columns: 3.8em minmax(0, 1fr);
  align-items: baseline;
  gap: 0.25rem;
  border: none;
  color: var(--ink-soft);
}
.note__toc-number {
  color: var(--accent);
  font-variant-numeric: tabular-nums lining-nums;
}
.note__toc a:hover { color: var(--accent); }

@media (max-width: 720px) {
  .note__toc-list { columns: 1; }
}

/* tcolorbox callouts — warm-paper aside boxes for highlighted derivations. */
.note aside.callout {
  background: var(--callout-bg);
  border-left: 2px solid var(--highlight);
  border-radius: 0;
  padding: 0.85rem 1.2rem;
  margin: 1.5rem 0;
  color: var(--ink);
}
.note aside.callout > :first-child { margin-top: 0; }
.note aside.callout > :last-child  { margin-bottom: 0; }

/* Boxed-equation environments — saturated warm-accent tint as fill, no
   border. The deeper colour gives the result presence without harsh
   lines, distinct from the lighter callout fill. */
.note aside.boxed-equation {
  background: color-mix(in srgb, var(--accent) 15%, var(--paper));
  border: none;
  border-radius: 0;
  padding: 0.8rem 1.4rem;
  margin: 1.6rem auto;
  width: fit-content;
  max-width: 100%;
  color: var(--ink);
  text-align: center;
}
.note aside.boxed-equation > :first-child { margin-top: 0; }
.note aside.boxed-equation > :last-child  { margin-bottom: 0; }
.note aside.boxed-equation .equation-row { margin: 0.4rem 0; }
.note aside.boxed-equation mjx-container[display="true"] { margin: 0 !important; }

/* Solution environments — refined warm-paper variant of elegantphys.sty's
   tcolorbox. Cream fill ties into the rest of the palette; thin oxblood
   left bar and italicised "Solution." label match the accent. */
.note aside.solution {
  background: var(--paper-deep);
  border-left: 2px solid var(--accent);
  border-radius: 0;
  padding: 0.7rem 1.1rem;
  margin: 1.2rem 0;
  color: var(--ink);
}
.note aside.solution > :first-child { margin-top: 0; }
.note aside.solution > :last-child  { margin-bottom: 0; }
.note aside.solution::before {
  content: "Solution.";
  font-style: italic;
  font-weight: 600;
  margin-right: 0.6em;
  float: left;
  color: var(--accent);
}

/* Q.E.D. tombstone (rendered from \qed) */
.note .qed {
  float: right;
  color: var(--muted);
  font-size: 1.05em;
  margin-left: 0.5em;
}

/* Notebook stats panel (top of notes.html) */
.stats {
  list-style: none;
  padding: 0;
  margin: 2rem auto 0;
  width: min(100%, 38rem);
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border-block: 1px solid var(--rule);
  font-family: var(--display);
}
.stats > li {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 0;
  padding: 1rem 0.65rem 0.9rem;
}
.stats > li + li::before {
  content: "";
  position: absolute;
  inset: 0.8rem auto 0.8rem 0;
  width: 1px;
  background: var(--rule-soft);
}
.stats__num {
  font-size: clamp(1.55rem, 4vw, 2.25rem);
  font-weight: 500;
  color: var(--accent);
  line-height: 1;
  letter-spacing: -0.025em;
  font-variant-numeric: tabular-nums;
  min-width: 5ch;
  text-align: center;
  transition: color 180ms ease, transform 180ms ease;
}
.stats > li.is-counted .stats__num {
  transform: translateY(-0.06em);
}
.stats__label {
  font-size: 0.68rem;
  color: var(--muted);
  letter-spacing: 0.11em;
  text-transform: uppercase;
  margin-top: 0.4rem;
}

@media (max-width: 440px) {
  .stats > li {
    padding-inline: 0.3rem;
  }
  .stats__num {
    font-size: clamp(1.35rem, 7vw, 1.85rem);
  }
  .stats__label {
    font-size: 0.58rem;
    letter-spacing: 0.075em;
  }
}

@media (prefers-reduced-motion: reduce) {
  .stats__num {
    transition: none;
  }
  .stats > li.is-counted .stats__num {
    transform: none;
  }
}

/* tabular tables */
.note .note__table-scroll {
  max-width: 100%;
  overflow-x: auto;
}
.note table.note__table {
  border-collapse: collapse;
  margin: 1.2rem auto;
  font-size: 0.95em;
}
.note table.note__table td,
.note table.note__table th {
  border: 1px solid var(--rule);
  padding: 0.4rem 0.7rem;
  text-align: left;
}

/* tikz-feynman source listings — TikZJax can't render these, so we show
   the LaTeX source styled like a code block. */
.note figure.tikz-source {
  text-align: left;
  background: var(--paper-deep);
  border: 1px dashed var(--rule);
  border-radius: var(--rad);
  padding: 1rem 1.2rem;
  margin: 1.5rem 0;
  font-family: var(--mono);
  font-size: 0.85em;
  overflow-x: auto;
}
.note figure.tikz-source pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--ink-soft);
}
.note figure.tikz-source figcaption {
  text-align: center;
  margin-top: 0.7rem;
  font-size: 0.85rem;
}

/* MathJax tweaks: keep displays from overflowing on phones. MathJax sets
   an inline `min-width: <natural-em>` on display containers — that's
   the equation's intrinsic width — which beats our cascade `min-width: 0`
   without `!important`. With it, a too-wide equation gets a horizontal
   scrollbar inside its container instead of pushing the page sideways. */
mjx-container[display="true"] {
  margin: 1.4rem 0 !important;
  overflow-x: auto;
  overflow-y: hidden;
  max-width: 100%;
  min-width: 0 !important;
}
/* Asides containing math also need to allow horizontal scroll for any
   single equation that's still wider than the column on small screens. */
.note aside.solution,
.note aside.boxed-equation,
.note aside.callout {
  overflow-x: auto;
  min-width: 0;
}

/* ---------- Decorative Feynman ornaments ---------- */
.ornament {
  display: block;
  margin: 2.5rem auto;
  width: 60px;
  height: 60px;
  opacity: 0.55;
}

.ornament path,
.ornament line,
.ornament circle { stroke: var(--accent); stroke-width: 1.2; fill: none; }

/* a corner-bound vertex used to mark the hero on wider screens */
.hero__vertex {
  position: absolute;
  top: 1rem;
  right: 0;
  width: clamp(36px, 6vw, 56px);
  height: clamp(36px, 6vw, 56px);
  opacity: 0.4;
  pointer-events: none;
}
.hero__vertex path,
.hero__vertex line,
.hero__vertex circle { stroke: var(--accent); stroke-width: 1; fill: none; }
@media (max-width: 460px) {
  .hero__vertex { display: none; }    /* avoid colliding with title on tiny screens */
}

/* ---------- Reveal animation on load ---------- */
@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.hero,
.section {
  animation: rise 0.7s ease-out both;
}

.section:nth-child(2) { animation-delay: 0.08s; }
.section:nth-child(3) { animation-delay: 0.16s; }
.section:nth-child(4) { animation-delay: 0.24s; }
.section:nth-child(5) { animation-delay: 0.32s; }

/* ---------- Smooth cross-page navigation ----------
   Cross-document View Transitions: in supporting browsers (Chromium 126+),
   navigating between pages on this site does a soft crossfade of the whole
   document instead of the usual hard repaint. Browsers without support
   ignore the rule and navigate normally — no JS shim needed. */
@view-transition { navigation: auto; }

::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: 0.55s;
  animation-timing-function: var(--ease-out);
}
::view-transition-old(root) {
  animation-name: page-fade-out;
}
::view-transition-new(root) {
  animation-name: page-fade-in;
}
@keyframes page-fade-out {
  to   { opacity: 0; transform: translateY(-4px); }
}
@keyframes page-fade-in {
  from { opacity: 0; transform: translateY(6px); }
}

/* Fallback for browsers without view transitions: a single soft fade-up
   on the whole main column at first paint. Cheap, runs once, doesn't
   compound with the existing per-section `rise` animation. */
@keyframes page-enter {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
@supports not (view-transition-name: none) {
  main.page, main.note {
    animation: page-enter 0.42s var(--ease-out) both;
  }
}

/* ---------- Feynman cell markers ----------
   Tiny stroked SVG (vertex / propagator / loop / s-channel / box) injected
   by theme.js as a decorative bullet on each catalogue row and research
   entry. Same line-art language as .ornament / .hero__vertex so they read
   as part of the same visual family. */
.feyn-mark {
  display: inline-block;
  width: 1.6em;
  height: 1.6em;
  vertical-align: -0.45em;
  flex: none;
  color: var(--accent);
  opacity: 0.7;
  transition: opacity var(--dur-base) var(--ease-out),
              transform var(--dur-base) var(--ease-out);
}
.feyn-mark svg {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
}
.feyn-mark svg line,
.feyn-mark svg path,
.feyn-mark svg ellipse,
.feyn-mark svg rect,
.feyn-mark svg circle {
  stroke: currentColor;
  fill: none;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}
.feyn-mark svg .vertex-dot {
  fill: currentColor;
  stroke: none;
}

/* When the catalogue row is hovered or focused, the diagram lights up and
   tilts subtly — a tactile cue that this row is the active target. */
.catalogue__item:hover .feyn-mark,
.catalogue__item:focus-within .feyn-mark,
.entry:hover .feyn-mark,
.entry:focus-within .feyn-mark {
  opacity: 1;
  transform: rotate(-6deg) scale(1.08);
}

/* In the catalogue grid the diagram sits inline beside the Roman
   numeral inside the first column — the glyph reads as a tiny marker,
   the numeral keeps the chronological signal. Both are vertically
   aligned to the baseline so the row height doesn't change. */
.catalogue__num.is-feyn {
  display: inline-flex;
  align-items: baseline;
  gap: 0.45em;
  white-space: nowrap;
}
.catalogue__num .feyn-mark {
  width: 1.15em;
  height: 1.15em;
  vertical-align: -0.18em;
  flex: none;
}

/* On research / education entries, the diagram sits to the left of the
   title in the head row. Doesn't shift layout because .entry__head
   already uses flex with baseline alignment. */
.entry__head .feyn-mark {
  width: 1.3em;
  height: 1.3em;
  margin-right: 0.5em;
  vertical-align: -0.32em;
}

/* ---------- Responsive breakpoints ----------
   Most sizing is fluid (clamp + ch-based measure); the rules below only
   handle layout regrouping that fluid sizing can't do.                  */

/* Phone (≤ 640px): stack the topbar, lighten paddings */
@media (max-width: 640px) {
  body { line-height: 1.62; }

  .topbar {
    padding-top: 1rem;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.4rem;
  }
  .topbar__brand small { display: block; margin-left: 0; margin-top: 0.1rem; }
  .topbar__nav { gap: 0.8rem 1.1rem; width: 100%; }

  .page  { padding: 1.6rem var(--gutter) 3.5rem; }
  .note  { padding: 1.6rem var(--gutter) 4rem; }
  .hero  { padding-top: 1.2rem; margin-bottom: 1.8rem; }

  .catalogue__item { padding: 0.9rem 0; }
  .entry { padding: 0.8rem 0; }
  .entry__head { gap: 0.2rem; }
  .entry__date { font-size: 0.85rem; }

  .hero__meta { gap: 0.4rem 1rem; font-size: 0.9rem; }

  .dropcap::first-letter { font-size: 3rem; padding-right: 0.4rem; }

  .footer { flex-direction: column; align-items: flex-start; padding: 1.8rem var(--gutter) 2.2rem; }
}

/* Tablet (≥ 700px): a touch more breathing room */
@media (min-width: 700px) {
  .page { padding-top: 3rem; }
}

/* ---------- Print ---------- */
@media print {
  @page { size: A4; margin: 18mm 16mm 20mm; }
  body {
    background: white;
    background-image: none;
    font-size: 11pt;
    line-height: 1.45;
  }
  .topbar, .footer, .ornament, .hero__vertex, .hero__formula,
  .site-nav, .site-nav-toggle, .note__pager,
  .back-to-top, .note__sidebar, .page-controls,
  .note__formats, .catalogue__formats { display: none !important; }
  main.note, main.page { width: 100%; max-width: none; margin: 0; padding: 0; }
  a { color: var(--ink); border: none; }
  h1, h2, h3, h4 { break-after: avoid-page; }
  .note h2[data-section-appendix] { break-before: page; }
  .note__problem, .note__abstract { break-inside: avoid; }
  .note__title { font-size: 34pt; line-height: 1.02; }
  .note__subtitle { max-width: 100%; }
  .note__toc { display: block !important; break-inside: avoid-page; }
  .note__toc--long { break-after: page; }
}
