/* ==========================================================================
   Design tokens
   Colors and fonts live here, so the whole look can be retuned in one place.
   ========================================================================== */

:root {
  --font-sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-serif: "Newsreader", ui-serif, Georgia, Cambria, "Times New Roman", serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --content-width: 46rem;
  --gutter: 1.5rem;
  --header-height: 3.75rem;
  --radius: 14px;
  --radius-sm: 8px;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);

  /* Light theme */
  --bg: #fbfaf8;
  --bg-elevated: #ffffff;
  --bg-subtle: #f3f1ec;
  --text: #1b1a17;
  --text-muted: #57534e;
  --text-subtle: #6f6a64;
  --border: #e6e2db;
  --border-strong: #d4cfc6;
  --accent: #3a6b52;
  --accent-soft: #e4ede6;
  --link-underline: rgb(58 107 82 / 0.4);
  --selection: rgb(58 107 82 / 0.18);
  --header-bg: rgb(251 250 248 / 0.8);
  --shadow: 0 1px 2px rgb(28 25 23 / 0.04), 0 6px 20px rgb(28 25 23 / 0.06);

  /* Syntax highlighting */
  --code-bg: #f4f2ee;
  --syn-comment: #716b64;
  --syn-keyword: #a1446b;
  --syn-string: #3a6b52;
  --syn-number: #a0522d;
  --syn-function: #2f5f8a;
  --syn-type: #8a5a00;

  color-scheme: light;
}

/* Dark theme: follows the OS setting unless the visitor picked a theme. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1110;
    --bg-elevated: #161917;
    --bg-subtle: #1c201e;
    --text: #e9e7e2;
    --text-muted: #b4afa7;
    --text-subtle: #8f8a83;
    --border: #262b28;
    --border-strong: #363c38;
    --accent: #8cc4a4;
    --accent-soft: #1c2a22;
    --link-underline: rgb(140 196 164 / 0.45);
    --selection: rgb(140 196 164 / 0.25);
    --header-bg: rgb(15 17 16 / 0.75);
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 8px 24px rgb(0 0 0 / 0.3);
    --code-bg: #161917;
    --syn-comment: #8d958f;
    --syn-keyword: #e59ab6;
    --syn-string: #9ccfae;
    --syn-number: #e3a87a;
    --syn-function: #8fb8e0;
    --syn-type: #e0c07a;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0f1110;
  --bg-elevated: #161917;
  --bg-subtle: #1c201e;
  --text: #e9e7e2;
  --text-muted: #b4afa7;
  --text-subtle: #8f8a83;
  --border: #262b28;
  --border-strong: #363c38;
  --accent: #8cc4a4;
  --accent-soft: #1c2a22;
  --link-underline: rgb(140 196 164 / 0.45);
  --selection: rgb(140 196 164 / 0.25);
  --header-bg: rgb(15 17 16 / 0.75);
  --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 8px 24px rgb(0 0 0 / 0.3);
  --code-bg: #161917;
  --syn-comment: #8d958f;
  --syn-keyword: #e59ab6;
  --syn-string: #9ccfae;
  --syn-number: #e3a87a;
  --syn-function: #8fb8e0;
  --syn-type: #e0c07a;
  color-scheme: dark;
}

/* ==========================================================================
   Base
   ========================================================================== */

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-top: calc(var(--header-height) + 1.5rem);
}

@media (prefers-reduced-motion: no-preference) {
  html {
    scroll-behavior: smooth;
  }
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

main {
  flex: 1;
  padding-block: 4rem 0;
}

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

a {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: var(--link-underline);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
  transition: color 0.15s ease, text-decoration-color 0.15s ease;
}

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

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

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

.icon {
  width: 1em;
  height: 1em;
  flex: none;
}

.container {
  width: 100%;
  max-width: calc(var(--content-width) + 2 * var(--gutter));
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.skip-link {
  position: absolute;
  left: 1rem;
  top: -4rem;
  z-index: 100;
  padding: 0.5rem 0.875rem;
  border-radius: var(--radius-sm);
  background: var(--text);
  color: var(--bg);
  font-size: 0.875rem;
  text-decoration: none;
}

.skip-link:focus {
  top: 1rem;
}

/* ==========================================================================
   Header & footer
   ========================================================================== */

.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--header-bg);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  height: var(--header-height);
}

.brand {
  font-family: var(--font-serif);
  font-size: 1.3125rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}

.brand:hover {
  color: var(--text);
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.site-nav a {
  padding: 0.375rem 0.75rem;
  border-radius: 999px;
  font-size: 0.9375rem;
  color: var(--text-muted);
  text-decoration: none;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.site-nav a:hover,
.site-nav a[aria-current="page"] {
  color: var(--text);
  background: var(--bg-subtle);
}

.theme-toggle {
  display: inline-grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  margin-left: 0.375rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.theme-toggle:hover {
  color: var(--text);
  background: var(--bg-subtle);
  border-color: var(--border-strong);
}

.theme-toggle .icon {
  width: 1.05rem;
  height: 1.05rem;
}

/* Show the moon in light mode and the sun in dark mode */
.theme-toggle .icon-sun {
  display: none;
}

:root[data-theme="dark"] .theme-toggle .icon-sun {
  display: block;
}

:root[data-theme="dark"] .theme-toggle .icon-moon {
  display: none;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun {
    display: block;
  }

  :root:not([data-theme="light"]) .theme-toggle .icon-moon {
    display: none;
  }
}

.site-footer {
  margin-top: 5rem;
  padding-block: 2rem 2.5rem;
  border-top: 1px solid var(--border);
  font-size: 0.875rem;
  color: var(--text-subtle);
}

.footer-inner {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem 1.5rem;
}

.site-footer p {
  margin: 0;
}

/* ==========================================================================
   Shared components
   ========================================================================== */

.section {
  margin-top: 4.5rem;
}

.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.25rem 1rem;
  margin-bottom: 1.25rem;
}

.section-head .section-title {
  margin-bottom: 0;
}

.section-title {
  margin: 0 0 1.25rem;
  font-family: var(--font-serif);
  font-size: 1.875rem;
  font-weight: 500;
  line-height: 1.2;
  letter-spacing: -0.015em;
}

.section-note {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--text-subtle);
}

.section-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.875rem;
  color: var(--text-muted);
  text-decoration: none;
}

.section-link .icon {
  transition: transform 0.2s var(--ease);
}

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

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.3;
  text-decoration: none;
  transition: color 0.15s ease, border-color 0.15s ease, box-shadow 0.2s ease, transform 0.2s var(--ease);
}

.btn:hover {
  color: var(--accent);
  border-color: var(--accent);
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}

.btn .icon {
  width: 1rem;
  height: 1rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-subtle);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1.6;
  text-decoration: none;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.chip:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.eyebrow {
  margin: 0 0 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
}

/* ==========================================================================
   Home
   ========================================================================== */

.hero {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 2.5rem;
}

.hero-name {
  margin: 0 0 0.75rem;
  font-family: var(--font-serif);
  font-size: clamp(2.75rem, 7vw, 3.75rem);
  font-weight: 500;
  line-height: 1;
  letter-spacing: -0.025em;
}

.hero-tagline {
  max-width: 34ch;
  margin: 0 0 0.5rem;
  font-size: 1.125rem;
  line-height: 1.5;
  color: var(--text-muted);
}

.hero-email {
  margin: 0 0 1.5rem;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--text-subtle);
}

.hero-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.hero-photo {
  width: 10rem;
  height: 10rem;
  border-radius: 50%;
  object-fit: cover;
  box-shadow: 0 0 0 4px var(--bg), 0 0 0 5px var(--border-strong), var(--shadow);
}

.bio {
  margin-top: 3rem;
  font-size: 1.0625rem;
  line-height: 1.75;
  color: var(--text-muted);
}

.bio p {
  margin: 0 0 1.15em;
}

.bio p:last-child {
  margin-bottom: 0;
}

.bio a,
.bio strong {
  color: var(--text);
}

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

.bio strong {
  font-weight: 600;
}

/* Publications */

.pub-list {
  display: grid;
  gap: 1rem;
}

.pub {
  padding: 1.375rem 1.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  transition: border-color 0.2s ease, box-shadow 0.25s ease, transform 0.25s var(--ease);
}

.pub:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}

.pub-venue {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0 0 0.55rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent);
}

.pub-venue::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.pub-title {
  margin: 0 0 0.4rem;
  font-size: 1.0625rem;
  font-weight: 600;
  line-height: 1.45;
  letter-spacing: -0.005em;
  text-wrap: pretty;
}

.pub-title a {
  color: var(--text);
  text-decoration: none;
}

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

.pub-authors {
  margin: 0 0 0.65rem;
  font-size: 0.9375rem;
  color: var(--text-muted);
}

.pub-authors strong {
  color: var(--text);
  font-weight: 600;
}

.pub-authors a {
  text-decoration-color: var(--border-strong);
}

.pub-summary {
  margin: 0 0 1rem;
  font-size: 0.9375rem;
  line-height: 1.65;
  color: var(--text-muted);
}

.pub-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0;
}

/* Miscellanea */

.misc {
  margin: 0;
}

.misc-row {
  display: grid;
  grid-template-columns: 11.5rem 1fr;
  gap: 0.5rem 1.5rem;
  padding: 1.1rem 0;
  border-top: 1px solid var(--border);
}

.misc-row:last-child {
  border-bottom: 1px solid var(--border);
}

.misc dt {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  align-self: start;
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1.6;
}

.misc-dot {
  width: 0.625rem;
  height: 0.625rem;
  border-radius: 3px;
  background: var(--dot);
  flex: none;
}

.misc dd {
  margin: 0;
}

.misc ul {
  display: grid;
  gap: 0.5rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.misc li {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.1rem 1rem;
  font-size: 0.9375rem;
  line-height: 1.6;
}

.misc-meta {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-subtle);
  white-space: nowrap;
}

.misc-empty {
  color: var(--text-subtle);
  font-style: italic;
}

/* Visitor map (markup injected by mapmyvisitors.com) */

.visitor-map {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-subtle);
  line-height: 0;
}

/* Hide the section when the widget never shows up (e.g. blocked by an ad blocker) */
#visitors:not(:has(#mapmyvisitors-widget)) {
  display: none;
}

/* ==========================================================================
   Writing listing
   ========================================================================== */

.page-header {
  margin-bottom: 3rem;
}

.page-title {
  margin: 0 0 0.75rem;
  font-family: var(--font-serif);
  font-size: clamp(2.5rem, 6vw, 3.25rem);
  font-weight: 500;
  line-height: 1.05;
  letter-spacing: -0.025em;
}

.page-subtitle {
  margin: 0 0 1.25rem;
  font-size: 1.125rem;
  color: var(--text-muted);
}

.post-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.post-item {
  --date-col: 7.25rem;
  display: grid;
  grid-template-columns: var(--date-col) 1fr auto;
  align-items: baseline;
  gap: 0.25rem 1.25rem;
  margin-inline: -0.875rem;
  padding: 0.9rem 0.875rem;
  border-radius: var(--radius-sm);
  color: inherit;
  text-decoration: none;
  transition: background-color 0.15s ease;
}

.year-group .post-item {
  --date-col: 4rem;
}

.post-item:hover {
  color: inherit;
  background: var(--bg-subtle);
}

.post-item-date,
.post-item-read {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-subtle);
  white-space: nowrap;
}

.post-item-title {
  display: block;
  font-family: var(--font-serif);
  font-size: 1.25rem;
  font-weight: 500;
  line-height: 1.35;
  letter-spacing: -0.01em;
  color: var(--text);
  transition: color 0.15s ease;
}

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

.post-item-desc {
  display: block;
  margin-top: 0.2rem;
  font-size: 0.9375rem;
  line-height: 1.55;
  color: var(--text-muted);
}

.year-group + .year-group {
  margin-top: 2.5rem;
}

.year-label {
  margin: 0 0 0.5rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--text-subtle);
}

.empty-state {
  padding: 3rem 1.5rem;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  text-align: center;
  color: var(--text-subtle);
}

/* ==========================================================================
   Writing post
   ========================================================================== */

.post {
  max-width: 42rem;
  margin-inline: auto;
}

.post-header {
  margin-bottom: 2.75rem;
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--border);
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 2.25rem;
  font-size: 0.875rem;
  color: var(--text-subtle);
  text-decoration: none;
}

.back-link .icon {
  transition: transform 0.2s var(--ease);
}

.back-link:hover .icon {
  transform: translateX(-3px);
}

.post-title {
  margin: 0 0 1rem;
  font-family: var(--font-serif);
  font-size: clamp(2.25rem, 6vw, 3.125rem);
  font-weight: 500;
  line-height: 1.1;
  letter-spacing: -0.025em;
  text-wrap: balance;
}

.post-dek {
  margin: 0 0 1.25rem;
  font-family: var(--font-serif);
  font-size: 1.3125rem;
  line-height: 1.5;
  color: var(--text-muted);
}

.post-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-subtle);
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 1rem 0 0;
  padding: 0;
  list-style: none;
}

.tag {
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 0.75rem;
}

.post-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 4rem;
}

.post-nav-link {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding: 1rem 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: inherit;
  text-decoration: none;
  transition: border-color 0.15s ease, box-shadow 0.2s ease;
}

.post-nav-link:hover {
  color: inherit;
  border-color: var(--border-strong);
  box-shadow: var(--shadow);
}

.post-nav-link.next {
  grid-column: 2;
  text-align: right;
}

.post-nav-label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8125rem;
  color: var(--text-subtle);
}

.post-nav-link.next .post-nav-label {
  justify-content: flex-end;
}

.post-nav-title {
  font-family: var(--font-serif);
  font-size: 1.125rem;
  line-height: 1.35;
}

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

/* Thin progress bar along the top while reading (browsers with scroll-driven animations) */
.reading-progress {
  display: none;
}

@supports (animation-timeline: scroll()) {
  .reading-progress {
    display: block;
    position: fixed;
    inset: 0 0 auto;
    z-index: 20;
    height: 2px;
    background: var(--accent);
    transform-origin: 0 50%;
    animation: reading-progress linear both;
    animation-timeline: scroll(root);
  }

  @keyframes reading-progress {
    from {
      transform: scaleX(0);
    }
    to {
      transform: scaleX(1);
    }
  }
}

/* ==========================================================================
   Prose (Markdown content of posts)
   ========================================================================== */

.prose {
  font-family: var(--font-serif);
  font-size: 1.1875rem;
  line-height: 1.7;
  overflow-wrap: break-word;
}

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

.prose p,
.prose ul,
.prose ol,
.prose dl,
.prose blockquote,
.prose table,
.prose figure,
.prose .highlighter-rouge,
.prose .katex-display {
  margin: 0 0 1.35rem;
}

.prose h2,
.prose h3,
.prose h4 {
  font-family: var(--font-serif);
  font-weight: 600;
  letter-spacing: -0.01em;
  scroll-margin-top: calc(var(--header-height) + 1.5rem);
}

.prose h2 {
  margin: 3rem 0 1rem;
  font-size: 1.75rem;
  line-height: 1.25;
}

.prose h3 {
  margin: 2.25rem 0 0.75rem;
  font-size: 1.375rem;
  line-height: 1.3;
}

.prose h4 {
  margin: 1.75rem 0 0.5rem;
  font-family: var(--font-sans);
  font-size: 1rem;
  letter-spacing: 0;
}

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

.prose strong {
  font-weight: 600;
}

.prose ul,
.prose ol {
  padding-left: 1.5rem;
}

.prose li + li {
  margin-top: 0.4rem;
}

.prose li > ul,
.prose li > ol {
  margin: 0.4rem 0 0;
}

.prose li::marker {
  color: var(--text-subtle);
}

.prose blockquote {
  margin-left: 0;
  margin-right: 0;
  padding: 0.1rem 0 0.1rem 1.25rem;
  border-left: 3px solid var(--accent);
  font-style: italic;
  color: var(--text-muted);
}

.prose blockquote > :last-child {
  margin-bottom: 0;
}

.prose hr {
  height: auto;
  margin: 3rem 0;
  border: 0;
  text-align: center;
}

.prose hr::before {
  content: "\2022\2002\2022\2002\2022";
  color: var(--text-subtle);
  font-size: 0.875rem;
  letter-spacing: 0.3em;
}

.prose img {
  display: block;
  margin-inline: auto;
  border-radius: 10px;
}

.prose figure {
  margin-inline: 0;
}

/* Captions: a <figcaption>, or an *italic line* right after a Markdown image */
.prose figcaption,
.prose img + em {
  display: block;
  margin-top: 0.75rem;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-style: normal;
  line-height: 1.5;
  text-align: center;
  color: var(--text-subtle);
}

.prose table {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
  font-family: var(--font-sans);
  font-size: 0.9375rem;
  line-height: 1.5;
}

.prose th,
.prose td {
  padding: 0.55rem 0.9rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

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

.prose code {
  padding: 0.12em 0.38em;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--code-bg);
  font-family: var(--font-mono);
  font-size: 0.8em;
  /* Show "->" and "!=" as typed, not as ligature arrows */
  font-variant-ligatures: none;
}

.prose .highlighter-rouge {
  position: relative;
}

.prose pre {
  margin: 0;
  padding: 1rem 1.15rem;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--code-bg);
  font-family: var(--font-mono);
  font-size: 0.875rem;
  font-variant-ligatures: none;
  line-height: 1.6;
  tab-size: 4;
}

.prose pre code {
  padding: 0;
  border: 0;
  background: none;
  font-size: inherit;
}

.copy-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  padding: 0.2rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-elevated);
  color: var(--text-muted);
  font: 500 0.75rem/1.5 var(--font-sans);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease, color 0.15s ease;
}

.copy-btn:hover {
  color: var(--text);
}

.highlighter-rouge:hover .copy-btn,
.copy-btn:focus-visible {
  opacity: 1;
}

@media (hover: none) {
  .copy-btn {
    opacity: 1;
  }
}

.heading-anchor {
  margin-left: 0.4em;
  font-family: var(--font-sans);
  font-weight: 400;
  color: var(--text-subtle);
  text-decoration: none;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.prose h2:hover .heading-anchor,
.prose h3:hover .heading-anchor,
.prose h4:hover .heading-anchor,
.heading-anchor:focus-visible {
  opacity: 1;
}

/* KaTeX defaults to 1.21em, which runs large next to Newsreader */
.prose .katex {
  font-size: 1.1em;
}

.prose .katex-display {
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0.25rem 0;
}

.prose sup {
  line-height: 0;
}

.prose .footnote {
  padding-inline: 0.1em;
  font-family: var(--font-sans);
  font-size: 0.8em;
  text-decoration: none;
}

.prose .footnotes {
  margin-top: 3.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  font-size: 0.9375rem;
  color: var(--text-muted);
}

.prose .footnotes p {
  margin-bottom: 0.5rem;
}

.prose .reversefootnote {
  text-decoration: none;
}

/* Table of contents, when a post opts in with {:toc} */
.prose #markdown-toc {
  padding: 1rem 1.25rem 1rem 2.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-subtle);
  font-family: var(--font-sans);
  font-size: 0.9375rem;
}

.prose #markdown-toc a {
  color: var(--text-muted);
  text-decoration: none;
}

.prose #markdown-toc a:hover {
  color: var(--accent);
}

/* Syntax highlighting (Rouge token classes) */
.highlight .c, .highlight .c1, .highlight .cm, .highlight .cs, .highlight .cd, .highlight .ch, .highlight .cpf {
  color: var(--syn-comment);
  font-style: italic;
}
.highlight .k, .highlight .kc, .highlight .kd, .highlight .kn, .highlight .kp, .highlight .kr, .highlight .kv,
.highlight .ow, .highlight .cp, .highlight .nd {
  color: var(--syn-keyword);
}
.highlight .s, .highlight .s1, .highlight .s2, .highlight .sa, .highlight .sb, .highlight .sc, .highlight .dl,
.highlight .sd, .highlight .se, .highlight .sh, .highlight .si, .highlight .sx, .highlight .sr, .highlight .ss,
.highlight .nt {
  color: var(--syn-string);
}
.highlight .m, .highlight .mb, .highlight .mf, .highlight .mh, .highlight .mi, .highlight .il, .highlight .mo,
.highlight .mx, .highlight .no, .highlight .nv, .highlight .vc, .highlight .vg, .highlight .vi, .highlight .vm {
  color: var(--syn-number);
}
.highlight .nf, .highlight .fm, .highlight .nb, .highlight .bp, .highlight .na {
  color: var(--syn-function);
}
.highlight .nc, .highlight .nn, .highlight .ne, .highlight .kt {
  color: var(--syn-type);
}
.highlight .o, .highlight .p {
  color: var(--text-muted);
}
.highlight .gd {
  color: var(--syn-keyword);
}
.highlight .gi {
  color: var(--syn-string);
}
.highlight .gh, .highlight .gu, .highlight .gs {
  font-weight: 600;
}
.highlight .ge {
  font-style: italic;
}
.highlight .gp, .highlight .go {
  color: var(--text-subtle);
}
.highlight .err {
  color: inherit;
  background: none;
}

/* ==========================================================================
   Motion & responsive
   ========================================================================== */

@media (prefers-reduced-motion: no-preference) {
  main > * {
    animation: rise 0.6s var(--ease) both;
  }

  main > :nth-child(2) { animation-delay: 60ms; }
  main > :nth-child(3) { animation-delay: 120ms; }
  main > :nth-child(4) { animation-delay: 180ms; }
  main > :nth-child(n + 5) { animation-delay: 240ms; }

  @keyframes rise {
    from {
      opacity: 0;
      transform: translateY(12px);
    }
  }
}

@media (max-width: 640px) {
  :root {
    --gutter: 1.25rem;
  }

  main {
    padding-top: 2.5rem;
  }

  .hero {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }

  .hero-photo {
    order: -1;
    width: 6.5rem;
    height: 6.5rem;
  }

  .hero-links {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .hero-links .btn {
    width: 100%;
    justify-content: center;
  }

  .section {
    margin-top: 3.5rem;
  }

  .misc-row {
    grid-template-columns: 1fr;
  }

  .post-item,
  .year-group .post-item {
    grid-template-columns: 1fr;
    gap: 0.15rem;
  }

  .post-item-read {
    display: none;
  }

  /* Put "Updated …" on its own line instead of wrapping after a dangling dot */
  .post-updated {
    flex-basis: 100%;
  }

  .post-updated > [aria-hidden] {
    display: none;
  }

  .post-nav {
    grid-template-columns: 1fr;
  }

  .post-nav-link.next {
    grid-column: auto;
  }

  .prose {
    font-size: 1.125rem;
  }
}

@media (max-width: 400px) {
  .site-nav {
    gap: 0;
  }

  .site-nav a {
    padding-inline: 0.5rem;
    font-size: 0.875rem;
  }
}

/* 320px phones: keep the header from pushing past the screen edge */
@media (max-width: 359px) {
  .header-inner {
    gap: 0.5rem;
  }

  .brand {
    font-size: 1.1875rem;
  }

  .site-nav a {
    padding-inline: 0.375rem;
    font-size: 0.8125rem;
  }

  .theme-toggle {
    width: 2rem;
    height: 2rem;
    margin-left: 0.125rem;
  }
}
