/* =========================================================================
   Fonts
   ========================================================================= */

@font-face {
  font-family: 'Source Sans 3';
  src: url('/fonts/source-sans-3-latin-variable.woff2') format('woff2-variations');
  font-style: normal;
  font-weight: 200 900;
  font-display: swap;
}

@font-face {
  font-family: 'IBM Plex Mono';
  src: url('/fonts/ibm-plex-mono-latin-400.woff2') format('woff2');
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

@layer reset, base, layout, components, utilities, overrides;

/* =========================================================================
   Tokens — colors, type, space, radius, weights, layout widths
   ========================================================================= */

:root {
  color-scheme: light dark;

  --font-sans:
    'Source Sans 3', Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    'Segoe UI', sans-serif;
  --font-mono: 'IBM Plex Mono', 'JetBrains Mono', ui-monospace, SFMono-Regular, monospace;

  /* Palette — light-dark() pairs each token (light, dark) */
  --color-bg: light-dark(#fbfaf7, #151514);
  --color-fg: light-dark(#181817, #f1eee7);
  --color-muted: light-dark(#4d4b44, #b7afa3);
  --color-link: light-dark(#285f74, #8ab8c8);
  --color-link-hover: light-dark(
    color-mix(in oklch, #285f74 70%, black 30%),
    color-mix(in oklch, #8ab8c8 70%, white 30%)
  );
  --color-link-visited: var(--color-link);
  --color-accent: light-dark(oklch(55% 0.13 15), oklch(72% 0.13 15));
  --color-rule: light-dark(#d9d5ca, #39352f);
  --color-rule-medium: light-dark(#7a7466, #8a8478);
  --color-rule-strong: light-dark(#4a4340, #d0c5b7);
  --color-code-bg: light-dark(#efede6, #2f2c27);
  --color-callout-bg: light-dark(#f4f1e8, #211f1c);
  --color-selection-bg: light-dark(#ecddd0, #4a3a2e);

  --theme-switcher-track: var(--color-rule-medium);
  --theme-switcher-icon-light: #f0e2b6;
  --theme-switcher-icon-dark: #f1eee7;

  /* Typography */
  --fs-xs: 0.75rem;
  --fs-sm: 0.8125rem;
  --fs-caption: 0.875rem;
  --fs-base: 1rem;
  --fs-body: 1.1875rem;
  --fs-lg: 1.25rem;
  --fs-xl: 1.75rem;
  --fs-2xl: 2.1rem;
  --fs-3xl: clamp(2rem, 1.5rem + 1.8vw, 3rem);
  --fs-dek: clamp(1.08rem, 0.95rem + 0.6vw, 1.25rem);

  --leading-tight: 1.18;
  --leading-snug: 1.35;
  --leading-prose: 1.6;

  --weight-regular: 400;
  --weight-medium: 500;
  --weight-semibold: 650;
  --weight-bold: 700;

  /* Spacing */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;

  /* Radius */
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --radius-pill: 999px;

  /* Layout */
  --measure: 36rem;
  --measure-wide: 56rem;
  --page: 72rem;
  --gutter: clamp(20px, 4vw, 32px);
}

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

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

/* =========================================================================
   Reset
   ========================================================================= */

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

  body,
  h1,
  h2,
  h3,
  h4,
  h5,
  h6,
  p,
  figure,
  blockquote,
  dl,
  dd {
    margin: 0;
  }

  ul[role='list'],
  ol[role='list'] {
    list-style: none;
    padding: 0;
  }

  button,
  input,
  textarea,
  select {
    font: inherit;
  }

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

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

@layer base {
  html {
    background: var(--color-bg);
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
  }

  body {
    background: var(--color-bg);
    color: var(--color-fg);
    font-family: var(--font-sans);
    font-size: var(--fs-body);
    line-height: var(--leading-snug);
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    overflow-wrap: break-word;
    transition:
      background-color 200ms ease,
      color 200ms ease;
  }

  address {
    font-style: normal;
  }

  a {
    color: var(--color-link);
    text-decoration-thickness: 0.08em;
    text-underline-offset: 0.18em;
    transition: color 150ms ease;
  }

  a:hover {
    color: var(--color-link-hover);
  }

  a:active {
    opacity: 0.85;
    transition: opacity 80ms ease;
  }

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

  main:focus-visible {
    outline: none;
  }

  ::selection {
    background: var(--color-selection-bg);
    color: var(--color-fg);
  }
}

/* =========================================================================
   Utilities
   ========================================================================= */

@layer utilities {
  .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }
}

/* =========================================================================
   Layout — site shell, header, footer, skip link
   ========================================================================= */

@layer layout {
  :where(.site-header, .site-footer, .home-intro, .home-section, .page-shell, .post) {
    width: min(100% - 2 * var(--gutter), var(--page));
    margin-inline: auto;
  }

  .post {
    width: min(100% - 2 * var(--gutter), var(--measure-wide));
  }

  .skip-link {
    position: absolute;
    left: calc(var(--gutter) + env(safe-area-inset-left));
    top: calc(var(--space-3) + env(safe-area-inset-top));
    z-index: 10;
    transform: translateY(-150%);
    background: var(--color-fg);
    color: var(--color-bg);
    padding: var(--space-3) var(--space-4);
    min-block-size: 44px;
    display: inline-flex;
    align-items: center;
    text-decoration: none;
    transition: transform 150ms ease;
  }

  .skip-link:focus {
    transform: translateY(0);
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
  }

  .site-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    flex-wrap: wrap;
    padding-block: var(--space-8) var(--space-6);
    border-bottom: 1px solid var(--color-rule);
  }

  .site-title {
    color: var(--color-fg);
    font-size: var(--fs-lg);
    font-weight: var(--weight-bold);
    letter-spacing: -0.005em;
    text-decoration: none;
  }

  .site-title:visited {
    color: var(--color-fg);
  }

  .site-title[aria-current='page'] {
    color: var(--color-fg);
  }

  .header-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--space-2) var(--space-6);
    min-width: 0;
  }

  .site-nav {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1) var(--space-5);
  }

  .site-nav a,
  .site-footer a {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    color: var(--color-muted);
    text-decoration: none;
  }

  .site-nav a:visited,
  .site-footer a:visited {
    color: var(--color-muted);
  }

  .site-nav a:hover,
  .site-footer a:hover {
    color: var(--color-fg);
    text-decoration: underline;
    text-underline-offset: 0.25em;
  }

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

  .site-footer {
    border-top: 1px solid var(--color-rule);
    margin-top: var(--space-16);
    padding-block: var(--space-8) var(--space-10);
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
  }

  .footer-links,
  .footer-meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--space-2) var(--space-5);
    margin: 0;
    padding: 0;
    list-style: none;
    color: var(--color-muted);
    font-size: var(--fs-caption);
  }

  .footer-links a,
  .footer-meta a,
  .footer-meta span {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }

  .footer-links a,
  .footer-meta a {
    padding-inline: var(--space-1);
    margin-inline: calc(-1 * var(--space-1));
  }

  /* Page header (shared by .home-intro, .page-header, .post-header) */
  .home-intro {
    max-width: var(--measure-wide);
    padding-block: clamp(2rem, 5vw, 4rem) var(--space-6);
  }

  .home-intro h1,
  .page-header h1,
  .post-header h1 {
    max-width: var(--measure-wide);
    color: var(--color-fg);
    font-size: var(--fs-3xl);
    font-weight: var(--weight-semibold);
    line-height: var(--leading-tight);
    text-wrap: balance;
  }

  .home-intro p:not(.eyebrow),
  .page-header p,
  .dek {
    max-width: var(--measure);
    color: var(--color-muted);
    font-size: var(--fs-dek);
  }

  .page-header,
  .post-header {
    max-width: var(--measure-wide);
    padding-block: var(--space-10) var(--space-6);
  }

  .post-header .dek {
    margin-block: var(--space-4) 0;
  }

  .post-meta {
    margin-block: var(--space-3) 0;
    color: var(--color-muted);
    font-size: var(--fs-caption);
    line-height: 1.4;
  }

  .home-section,
  .page-shell {
    margin-top: var(--space-8);
  }
}

/* =========================================================================
   Components
   ========================================================================= */

@layer components {
  /* -- Eyebrow ---------------------------------------------------------- */

  .eyebrow {
    margin: 0 0 var(--space-3);
    color: var(--color-muted);
    font-size: var(--fs-caption);
    line-height: 1.4;
    font-weight: var(--weight-semibold);
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }

  /* -- Section heading -------------------------------------------------- */

  .section-heading {
    width: 100%;
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-4);
    flex-wrap: wrap;
    margin-bottom: var(--space-4);
    padding-top: var(--space-6);
  }

  :where(.section-heading, .archive-year, .project-section, .facts, .at-a-glance) h2 {
    font-size: var(--fs-lg);
    font-weight: var(--weight-semibold);
    line-height: var(--leading-snug);
  }

  .section-heading a {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    color: var(--color-muted);
    font-size: var(--fs-caption);
    text-decoration: none;
  }

  .section-heading a:hover {
    color: var(--color-fg);
    text-decoration: underline;
    text-underline-offset: 0.25em;
  }

  /* -- Breadcrumbs ------------------------------------------------------ */

  .breadcrumbs {
    margin: 0 0 var(--space-3);
    padding: 0;
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    color: var(--color-muted);
    font-size: var(--fs-caption);
  }

  .breadcrumbs li + li::before {
    content: '›';
    margin-right: var(--space-2);
    color: var(--color-rule-medium);
  }

  .breadcrumbs a {
    color: var(--color-muted);
    text-decoration: none;
  }

  .breadcrumbs a:hover {
    color: var(--color-fg);
    text-decoration: underline;
    text-underline-offset: 0.25em;
  }

  .breadcrumbs [aria-current='page'] {
    color: var(--color-fg);
  }

  /* -- Tag list + filter ------------------------------------------------ */

  .tag-cloud {
    margin-top: var(--space-2);
  }

  .tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1) var(--space-2);
    margin: var(--space-2) 0 0;
    padding: 0;
    list-style: none;
    color: var(--color-muted);
    font-size: var(--fs-caption);
  }

  .tag-list a {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    padding-inline: var(--space-2);
    margin-inline: calc(-1 * var(--space-2));
    color: var(--color-muted);
    text-decoration: none;
  }

  .tag-list a:visited {
    color: var(--color-muted);
  }

  .tag-list a::before {
    content: '#';
    color: var(--color-rule-medium);
  }

  .tag-list .tag-more::before {
    content: none;
  }

  .tag-list .tag-count {
    margin-inline-start: 0.35em;
    padding: 0 0.4em;
    border-radius: var(--radius-pill);
    background: var(--color-code-bg);
    color: var(--color-fg);
    font-size: var(--fs-caption);
    font-variant-numeric: tabular-nums;
  }

  .tag-list a:hover,
  .tag-list a[aria-current='page'],
  .tag-list a[aria-current='true'] {
    color: var(--color-fg);
  }

  .tag-filter {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: var(--space-2) var(--space-4);
    margin: 0 0 var(--space-8);
    padding-block: var(--space-3);
    border-block: 1px solid var(--color-rule);
  }

  .tag-filter > span {
    color: var(--color-muted);
    font-size: var(--fs-caption);
  }

  /* -- Lists: article + project ---------------------------------------- */

  .article-list,
  .project-list {
    list-style: none;
    margin: 0;
    padding: 0;
    width: 100%;
  }

  .project-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 24rem), 1fr));
    gap: var(--space-4);
    align-items: stretch;
  }

  .article-list > li {
    display: grid;
    grid-template-columns: 4.5rem minmax(0, 1fr) minmax(6rem, 8rem);
    grid-template-areas: 'date content thumb';
    align-items: center;
    gap: var(--space-4);
    padding-block: var(--space-6);
    border-top: 1px solid var(--color-rule);
  }

  .article-list > li:first-child {
    border-top: 0;
  }

  .article-list time {
    grid-area: date;
    color: var(--color-muted);
    font-size: var(--fs-caption);
    text-align: end;
  }

  .article-list > li > div {
    grid-area: content;
    min-width: 0;
    padding-right: var(--space-3);
  }

  .article-list .entry-title,
  .project-list h3 a {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    color: var(--color-fg);
    font-weight: var(--weight-semibold);
    text-decoration: none;
  }

  .article-list .entry-title:visited,
  .project-list h3 a:visited {
    color: var(--color-fg);
  }

  .article-list .entry-title:hover,
  .project-list h3 a:hover {
    color: var(--color-link-hover);
  }

  .article-list p,
  .project-list p {
    margin: var(--space-1) 0 0;
    color: var(--color-muted);
  }

  /* -- Thumbnail -------------------------------------------------------- */

  .entry-thumbnail {
    display: block;
    overflow: hidden;
    border: 1px solid var(--color-rule);
    border-radius: var(--radius-md);
    background: var(--color-code-bg);
    aspect-ratio: 4 / 3;
    transition: border-color 150ms ease;
  }

  .entry-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 300ms ease;
  }

  a.entry-thumbnail {
    text-decoration: none;
  }

  a.entry-thumbnail:hover,
  a.entry-thumbnail:focus-visible {
    border-color: var(--color-rule-strong);
  }

  .article-list > li:hover .entry-thumbnail img {
    transform: scale(1.02);
  }

  .article-thumbnail {
    grid-area: thumb;
    align-self: center;
  }

  /* -- Project card ----------------------------------------------------- */

  .project-card {
    --project-thumb-size: clamp(7rem, 18vw, 9.5rem);

    display: grid;
    grid-template-columns: var(--project-thumb-size) minmax(0, 1fr);
    grid-template-areas: 'thumb summary';
    min-height: var(--project-thumb-size);
    min-width: 0;
    overflow: hidden;
    border: 1px solid var(--color-rule);
    border-radius: var(--radius-lg);
    background: var(--color-bg);
    transition: border-color 150ms ease;
  }

  .project-card:hover {
    border-color: var(--color-rule-strong);
  }

  .project-card:target {
    border-color: var(--color-rule-strong);
  }

  .project-card .project-thumbnail {
    grid-area: thumb;
    width: 100%;
    height: 100%;
    border: 0;
    border-right: 1px solid var(--color-rule);
    border-radius: 0;
    aspect-ratio: 1 / 1;
  }

  .project-card .project-thumbnail img {
    transition: transform 300ms ease;
  }

  .project-card:hover .project-thumbnail img {
    transform: scale(1.02);
  }

  .project-card__summary {
    grid-area: summary;
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    min-width: 0;
    padding: var(--space-3) var(--space-4);
  }

  .project-card p {
    margin: 0;
  }

  .project-card .project-description {
    color: var(--color-fg);
    font-size: var(--fs-base);
    line-height: var(--leading-snug);
  }

  .project-card .project-meta {
    color: var(--color-muted);
    font-size: var(--fs-sm);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .project-essay-badge {
    display: inline-flex;
    align-items: center;
    margin-left: var(--space-2);
    padding: 0.1em 0.5em;
    background: var(--color-callout-bg);
    border: 1px solid var(--color-rule);
    border-radius: var(--radius-pill);
    color: var(--color-muted);
    font-size: var(--fs-xs);
    font-weight: var(--weight-medium);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    vertical-align: 0.15em;
  }

  .project-list h3 {
    font-size: var(--fs-base);
    line-height: var(--leading-snug);
  }

  /* -- Project links ---------------------------------------------------- */

  .project-links {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1) var(--space-3);
    margin: var(--space-3) 0 0;
    padding: 0;
    list-style: none;
  }

  .project-links a {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    color: var(--color-link);
  }

  .project-links a:hover,
  .project-links a:focus-visible {
    color: var(--color-link-hover);
  }

  .project-links a .download-indicator {
    margin-left: 0.25em;
    color: var(--color-muted);
    font-size: 0.85em;
  }

  .project-card .project-links {
    gap: 0 var(--space-3);
    margin-top: auto;
    font-size: var(--fs-caption);
  }

  .project-card .project-links a {
    min-height: 2.25rem;
  }

  /* -- Post layout ------------------------------------------------------ */

  .post > .prose,
  .post > .post-media,
  .facts {
    max-width: var(--measure);
    margin-inline: auto;
  }

  .post > .at-a-glance,
  .post > .post-thumbnail,
  .post-nav {
    max-width: var(--measure-wide);
    margin-inline: auto;
  }

  .archive-year,
  .project-section {
    width: 100%;
  }

  .archive-year + .archive-year,
  .project-section + .project-section {
    margin-top: var(--space-10);
  }

  .archive-year h2,
  .project-section h2 {
    margin-bottom: var(--space-3);
  }

  .about-section {
    width: 100%;
    margin-top: var(--space-10);
  }

  .about-section.facts {
    max-width: none;
  }

  .about-section.facts > .prose {
    margin-top: var(--space-4);
  }

  .about-links {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1) var(--space-4);
  }

  .post > .prose {
    margin-top: var(--space-8);
  }

  .post-thumbnail {
    margin: 0;
  }

  .post-thumbnail img {
    width: 100%;
    border: 1px solid var(--color-rule);
    border-radius: var(--radius-md);
    background: var(--color-code-bg);
  }

  /* -- Prose ------------------------------------------------------------ */

  .prose {
    max-inline-size: var(--measure);
    line-height: var(--leading-prose);
  }

  .prose > * + * {
    margin-top: 1.05em;
  }

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

  .prose p {
    text-wrap: pretty;
  }

  .prose h2,
  .prose h3 {
    position: relative;
    color: var(--color-fg);
    line-height: var(--leading-tight);
    scroll-margin-top: var(--space-8);
  }

  .prose h2 {
    margin-top: var(--space-12);
    font-size: var(--fs-xl);
    font-weight: var(--weight-semibold);
  }

  .prose h3 {
    margin-top: var(--space-8);
    font-size: var(--fs-lg);
    font-weight: var(--weight-semibold);
  }

  .prose h2:target,
  .prose h3:target {
    background: var(--color-callout-bg);
    border-inline-start: 2px solid var(--color-accent);
    padding-inline-start: var(--space-3);
    margin-inline-start: calc(-1 * var(--space-3) - 2px);
  }

  .prose .heading-anchor {
    margin-inline-start: 0.4em;
    color: var(--color-muted);
    font-weight: var(--weight-regular);
    font-size: 0.85em;
    text-decoration: none;
    opacity: 0.25;
    transition: opacity 150ms ease;
  }

  .prose .heading-anchor::before {
    content: '#';
  }

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

  @media (hover: none) {
    .prose .heading-anchor {
      opacity: 0.5;
    }
  }

  .prose ul,
  .prose ol {
    padding-inline-start: 1.25rem;
  }

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

  .prose strong {
    font-weight: var(--weight-bold);
    color: var(--color-fg);
  }

  .prose em {
    font-style: italic;
  }

  .prose blockquote {
    margin-inline: 0;
    padding: var(--space-2) var(--space-4);
    border-inline-start: 3px solid var(--color-rule-medium);
    background: var(--color-callout-bg);
    color: var(--color-muted);
    font-style: italic;
  }

  .prose blockquote > * + * {
    margin-top: 0.6em;
  }

  .prose hr {
    margin-block: var(--space-8);
    border: 0;
    height: 1px;
    background: var(--color-rule);
  }

  .prose table {
    width: 100%;
    max-width: 100%;
    border-collapse: collapse;
    font-size: 0.95em;
    display: block;
    overflow-x: auto;
  }

  .prose thead {
    background: var(--color-code-bg);
    text-align: start;
  }

  .prose th,
  .prose td {
    padding: var(--space-2) var(--space-3);
    border-bottom: 1px solid var(--color-rule);
    vertical-align: top;
  }

  .prose th {
    font-weight: var(--weight-semibold);
  }

  .prose code {
    font-family: var(--font-mono);
    font-size: 0.88em;
    background: var(--color-code-bg);
    border-radius: var(--radius-sm);
    padding: 0.08em 0.25em;
  }

  .prose pre {
    max-width: 100%;
    overflow-x: auto;
    scrollbar-gutter: stable;
    padding: var(--space-4);
    background: var(--color-code-bg);
    border: 1px solid var(--color-rule);
    border-radius: var(--radius-md);
    line-height: 1.55;
    scrollbar-width: thin;
    scrollbar-color: var(--color-rule-medium) var(--color-code-bg);
  }

  .prose pre::-webkit-scrollbar {
    height: 8px;
  }

  .prose pre::-webkit-scrollbar-track {
    background: var(--color-code-bg);
  }

  .prose pre::-webkit-scrollbar-thumb {
    background: var(--color-rule-medium);
    border-radius: var(--radius-sm);
  }

  .prose pre code {
    background: transparent;
    padding: 0;
  }

  /* Shiki dual-theme: defaultColor: false emits --shiki-light / --shiki-dark
     vars on every token; light-dark() picks the active variant from
     color-scheme on :root. */
  .prose pre.astro-code,
  .prose pre.astro-code code,
  .prose pre.astro-code span {
    color: light-dark(var(--shiki-light), var(--shiki-dark));
    background-color: light-dark(
      var(--shiki-light-bg, var(--color-code-bg)),
      var(--shiki-dark-bg, var(--color-code-bg))
    );
  }

  /* -- At-a-glance + facts --------------------------------------------- */

  .at-a-glance {
    margin-top: var(--space-8);
    padding-block: var(--space-5);
    border-block: 1px solid var(--color-rule);
  }

  .at-a-glance dl,
  .facts dl {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    margin: var(--space-4) 0 0;
  }

  .at-a-glance__row,
  .facts dl > div {
    display: grid;
    grid-template-columns: minmax(6rem, max-content) minmax(0, 1fr);
    gap: var(--space-4);
  }

  .at-a-glance dt,
  .facts dt {
    color: var(--color-muted);
    font-size: var(--fs-caption);
  }

  .facts {
    margin-top: var(--space-8);
    padding-top: var(--space-6);
    border-top: 1px solid var(--color-rule);
  }

  /* Float .at-a-glance beside .prose at wide viewports. */
  @media (min-width: 1100px) {
    .post {
      width: min(100% - 2 * var(--gutter), var(--page));
      display: grid;
      grid-template-columns: minmax(0, var(--measure)) minmax(14rem, 18rem);
      column-gap: var(--space-10);
      align-items: start;
    }

    .post > .post-header,
    .post > .post-thumbnail,
    .post > .post-media,
    .post > .post-nav {
      grid-column: 1 / -1;
      max-width: var(--measure-wide);
      margin-inline: auto;
      width: 100%;
    }

    .post > .prose {
      grid-column: 1;
      margin-inline: 0;
      margin-top: var(--space-8);
    }

    .post > .at-a-glance {
      grid-column: 2;
      grid-row: span 5;
      margin-top: var(--space-8);
      position: sticky;
      top: var(--space-6);
      align-self: start;
    }
  }

  /* -- Post media ------------------------------------------------------- */

  .post-media {
    max-inline-size: min(100%, var(--measure-wide));
    margin: var(--space-8) 0 0;
  }

  .post-media img,
  .post-media video {
    border: 1px solid var(--color-rule);
    border-radius: var(--radius-md);
    background: var(--color-code-bg);
    width: 100%;
  }

  .post-media figcaption,
  .media-transcript {
    max-width: var(--measure);
    margin-top: var(--space-2);
    color: var(--color-muted);
    font-size: var(--fs-caption);
    line-height: 1.45;
  }

  /* -- Post nav --------------------------------------------------------- */

  .post-nav {
    margin-top: var(--space-12);
    padding-top: var(--space-6);
    border-top: 1px solid var(--color-rule);
  }

  .post-nav__list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr));
    gap: var(--space-4);
    list-style: none;
    padding: 0;
    margin: 0;
  }

  .post-nav__next {
    justify-self: end;
  }

  .post-nav a {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--color-rule);
    border-radius: var(--radius-md);
    color: var(--color-fg);
    text-decoration: none;
    min-height: 44px;
    transition: border-color 150ms ease;
  }

  .post-nav a:visited {
    color: var(--color-fg);
  }

  .post-nav a:hover,
  .post-nav a:focus-visible {
    border-color: var(--color-rule-strong);
  }

  .post-nav a.next {
    text-align: end;
  }

  .post-nav .post-nav__label {
    color: var(--color-muted);
    font-size: var(--fs-caption);
  }

  .post-nav .post-nav__title {
    color: var(--color-fg);
    font-weight: var(--weight-semibold);
  }

  /* -- Post TOC --------------------------------------------------------- */

  .post-toc {
    margin-top: var(--space-6);
    padding: var(--space-3) var(--space-4);
    border-inline-start: 2px solid var(--color-rule);
    font-size: var(--fs-caption);
    color: var(--color-muted);
    max-height: 60vh;
    overflow-y: auto;
  }

  .post-toc .post-nav__title,
  .post-header h1,
  .post-nav .post-nav__title,
  .project-card h3 {
    overflow-wrap: anywhere;
  }

  .post-toc ol {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
  }

  .post-toc a {
    display: inline-flex;
    align-items: center;
    min-block-size: 24px;
    padding-block: 2px;
    color: var(--color-muted);
    text-decoration: none;
  }

  .post-toc a:hover,
  .post-toc a:focus-visible {
    color: var(--color-fg);
  }

  /* -- Post media gallery ----------------------------------------------- */

  .post-gallery {
    list-style: none;
    padding: 0;
    margin: var(--space-8) 0 0;
    display: grid;
    gap: var(--space-6);
  }

  /* -- External link affordance ----------------------------------------- */

  .external-link-icon {
    display: inline-block;
    margin-inline-start: 0.25em;
    vertical-align: -0.125em;
    opacity: 0.85;
  }

  /* -- Related ---------------------------------------------------------- */

  .related-posts {
    margin-top: var(--space-12);
    padding-top: var(--space-6);
    border-top: 1px solid var(--color-rule);
  }

  .related-posts h2 {
    font-size: var(--fs-lg);
    font-weight: var(--weight-semibold);
    margin-bottom: var(--space-4);
  }

  /* -- Empty state (e.g. 404) ----------------------------------------- */

  .empty-state {
    max-width: var(--measure);
    padding-block: var(--space-6);
  }

  /* -- Theme switcher --------------------------------------------------- */

  .theme-switcher {
    --switcher-w: 2.75rem;
    --switcher-h: 1.5rem;
    --switcher-icon: 1.05rem;
    --switcher-mask: 0.78rem;
    --switcher-gap: 0.22rem;
    --switcher-mask-offset: 0.32rem;

    position: relative;
    display: inline-block;
    width: var(--switcher-w);
    height: var(--switcher-h);
    margin: var(--space-2) 0;
    overflow: hidden;
    border: 1px solid var(--color-rule-medium);
    border-radius: var(--radius-pill);
    appearance: none;
    cursor: pointer;
    background: var(--theme-switcher-track);
    color: inherit;
    transition:
      background-color 200ms ease,
      border-color 150ms ease;
    box-shadow: inset 0 1px 2px rgb(0 0 0 / 18%);
  }

  .theme-switcher:hover {
    border-color: var(--color-rule-strong);
  }

  .theme-switcher::before,
  .theme-switcher::after {
    content: '';
    position: absolute;
    top: 50%;
    border-radius: var(--radius-pill);
    transition:
      transform 180ms ease,
      background-color 180ms ease;
  }

  .theme-switcher::before {
    z-index: 1;
    width: var(--switcher-icon);
    height: var(--switcher-icon);
  }

  .theme-switcher::after {
    z-index: 2;
    width: var(--switcher-mask);
    height: var(--switcher-mask);
  }

  .theme-switcher[aria-pressed='false']::before {
    transform: translateY(-50%)
      translateX(calc(var(--switcher-w) - var(--switcher-icon) - var(--switcher-gap)));
    background-color: var(--theme-switcher-icon-light);
  }

  .theme-switcher[aria-pressed='false']::after {
    transform: translateY(-50%) translateX(var(--switcher-w));
  }

  .theme-switcher[aria-pressed='true']::before {
    transform: translateY(-50%) translateX(var(--switcher-gap));
    background-color: var(--theme-switcher-icon-dark);
  }

  .theme-switcher[aria-pressed='true']::after {
    transform: translateY(-50%)
      translateX(calc(var(--switcher-gap) + var(--switcher-mask-offset)));
    background-color: var(--theme-switcher-track);
  }

  /* High-contrast / forced-colors fallback: render a text label. */
  @media (forced-colors: active) {
    .theme-switcher {
      width: auto;
      height: auto;
      padding: var(--space-1) var(--space-2);
      background: ButtonFace;
      color: ButtonText;
      border: 1px solid ButtonBorder;
      box-shadow: none;
    }

    .theme-switcher::before,
    .theme-switcher::after {
      content: none;
    }

    .theme-switcher::before {
      content: 'Light';
    }

    .theme-switcher[aria-pressed='true']::before {
      content: 'Dark';
    }
  }
}

/* =========================================================================
   Responsive — tablet + mobile breakpoints
   ========================================================================= */

@layer overrides {
  /* Tablet */
  @media (max-width: 960px) {
    .article-list > li {
      grid-template-columns: 5rem minmax(0, 1fr) 7rem;
      gap: var(--space-4);
      padding-block: var(--space-5);
    }
  }

  /* Mobile */
  @media (max-width: 700px) {
    .site-header {
      padding-block: var(--space-6) var(--space-4);
    }

    .home-intro {
      padding-block: var(--space-8) var(--space-6);
    }

    .at-a-glance__row,
    .facts dl > div {
      grid-template-columns: 1fr;
      gap: var(--space-1);
    }

    .article-list > li {
      grid-template-columns: clamp(4rem, 22vw, 5rem) minmax(0, 1fr);
      grid-template-areas:
        'thumb content'
        'date content';
      gap: var(--space-2) var(--space-3);
      padding-block: var(--space-4);
    }

    .article-list > li > div {
      padding-right: 0;
    }

    .article-list .entry-thumbnail {
      aspect-ratio: 1;
    }

    .project-card {
      --project-thumb-size: 7rem;
    }

    .project-card .project-meta {
      -webkit-line-clamp: 3;
    }

    .project-card__summary {
      padding: var(--space-2) var(--space-3);
    }

    .page-header,
    .post-header {
      padding-block: var(--space-8) var(--space-5);
    }

    .post > .prose {
      margin-top: var(--space-6);
    }

    :focus-visible {
      outline-offset: 1px;
    }

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

    .post-nav__next {
      justify-self: stretch;
    }

    .post-nav a.next {
      text-align: start;
    }

    .header-actions {
      justify-content: space-between;
      width: 100%;
      gap: var(--space-2) var(--space-4);
    }

    .site-nav {
      gap: var(--space-1) var(--space-6);
    }
  }

  /* Reduced motion */
  @media (prefers-reduced-motion: reduce) {
    html {
      scroll-behavior: auto;
    }

    *,
    *::before,
    *::after {
      animation-duration: 0.01ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: 0.01ms !important;
    }

    ::view-transition-group(*),
    ::view-transition-old(*),
    ::view-transition-new(*) {
      animation: none;
    }
  }

  /* Print */
  @media print {
    :root {
      --color-bg: #fff;
      --color-fg: #000;
      --color-muted: #333;
      --color-link: #000;
      --color-link-hover: #000;
      --color-accent: #000;
      --color-rule: #999;
      --color-rule-medium: #777;
      --color-rule-strong: #333;
      --color-code-bg: #f4f4f4;
      --color-callout-bg: #f8f8f8;
    }

    body {
      font-size: 11pt;
      line-height: 1.4;
    }

    *,
    *::before,
    *::after {
      print-color-adjust: economy;
      -webkit-print-color-adjust: economy;
    }

    .site-header,
    .site-footer,
    .skip-link,
    .theme-switcher,
    .tag-filter,
    .post-nav,
    .related-posts,
    .heading-anchor {
      display: none;
    }

    main {
      padding: 0;
    }

    a,
    a:visited {
      color: var(--color-fg);
      text-decoration: underline;
    }

    .prose a[href]::after {
      content: ' (' attr(href) ')';
      font-size: 0.85em;
      color: var(--color-muted);
    }

    .prose a[href^='#']::after,
    .prose a[href^='/']::after {
      content: '';
    }

    .prose pre,
    .prose code,
    .post-thumbnail img,
    .post-media img {
      page-break-inside: avoid;
    }

    .prose h2,
    .prose h3 {
      page-break-after: avoid;
    }
  }
}
