/* =========================================================
   FONTS  (self-hosted WOFF2 — no external requests)
   ========================================================= */

/* Geist — variable font, upright */
@font-face {
  font-family: "Geist";
  src: url("../fonts/Geist[wght].woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0020-007E, U+00A0-00FF, U+0131, U+0152-0153, U+02BB-02BC,
                 U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC,
                 U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* Geist — variable font, italic */
@font-face {
  font-family: "Geist";
  src: url("../fonts/Geist-Italic[wght].woff2") format("woff2");
  font-weight: 100 900;
  font-style: italic;
  font-display: swap;
  unicode-range: U+0020-007E, U+00A0-00FF, U+0131, U+0152-0153, U+02BB-02BC,
                 U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC,
                 U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* JetBrains Mono */
@font-face {
  font-family: "JetBrains Mono";
  src: url("../fonts/JetBrainsMono-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0020-007E, U+00A0-00FF, U+0131, U+0152-0153, U+02BB-02BC,
                 U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC,
                 U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("../fonts/JetBrainsMono-Italic.woff2") format("woff2");
  font-weight: 400;
  font-style: italic;
  font-display: swap;
  unicode-range: U+0020-007E, U+00A0-00FF, U+0131, U+0152-0153, U+02BB-02BC,
                 U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC,
                 U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("../fonts/JetBrainsMono-Bold.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0020-007E, U+00A0-00FF, U+0131, U+0152-0153, U+02BB-02BC,
                 U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC,
                 U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("../fonts/JetBrainsMono-BoldItalic.woff2") format("woff2");
  font-weight: 700;
  font-style: italic;
  font-display: swap;
  unicode-range: U+0020-007E, U+00A0-00FF, U+0131, U+0152-0153, U+02BB-02BC,
                 U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC,
                 U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* =========================================================
   DESIGN TOKENS
   ========================================================= */

/*
 * Light palette — defined once on :root and re-applied on
 * [data-theme="light"] so it wins over the dark media query
 * when the user manually switches back to light.
 */
:root,
[data-theme="light"] {
  color-scheme: light;

  /* Typography */
  --font-sans: "Geist", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;
  --font-size-base: 1rem;
  --line-height: 1.65;
  --line-height-tight: 1.2;

  /* Spacing */
  --space-xs:  0.25rem;
  --space-sm:  0.5rem;
  --space-md:  1rem;
  --space-lg:  1.5rem;
  --space-xl:  2.5rem;
  --space-2xl: 4rem;

  /* Layout */
  --content-width: 64ch;
  --sidebar-width: 12rem;
  --sidebar-gap:   var(--space-lg);
  --header-height: 2.75rem;

  /* Transitions */
  --transition: 50ms ease;

  /* Palette */
  --bg:            #FAFAFA;
  --bg-elevated:   #F2F2F2;
  --bg-subtle:     #EBEBEB;
  --border:        #E0DFE4;
  --border-strong: #C8C7CC;
  --text:          #111112;
  --text-muted:    #6A696E;
  --text-faint:    #9A9A9F;
  --accent:        #7A5AAA;
  --accent-hover:  #5A3A90;
  --accent-subtle: #EDE8F2;
  --tag-bg:        #EDE8F2;
  --tag-text:      #5A3A90;
  --code-bg:       #F2F2F2;
  --code-text:     #111112;
  --callout-bg:    #EDE8F2;
  --callout-border:#7A5AAA;
  --link:          #5A3A90;
}

/*
 * Dark palette — applied by system preference and explicitly
 * by [data-theme="dark"] so the user override always wins.
 */
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg:            #0F0F10;
    --bg-elevated:   #191920;
    --bg-subtle:     #222230;
    --border:        #2A2830;
    --border-strong: #3A3848;
    --text:          #E4E3E8;
    --text-muted:    #78777C;
    --text-faint:    #55545A;
    --accent:        #9A7EC4;
    --accent-hover:  #B09AD8;
    --accent-subtle: #221A2E;
    --tag-bg:        #221A2E;
    --tag-text:      #B09AD8;
    --code-bg:       #191920;
    --code-text:     #E4E3E8;
    --callout-bg:    #1C1728;
    --callout-border:#9A7EC4;
    --link:          #B09AD8;
  }
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg:            #0F0F10;
  --bg-elevated:   #191920;
  --bg-subtle:     #222230;
  --border:        #2A2830;
  --border-strong: #3A3848;
  --text:          #E4E3E8;
  --text-muted:    #78777C;
  --text-faint:    #55545A;
  --accent:        #9A7EC4;
  --accent-hover:  #B09AD8;
  --accent-subtle: #221A2E;
  --tag-bg:        #221A2E;
  --tag-text:      #B09AD8;
  --code-bg:       #191920;
  --code-text:     #E4E3E8;
  --callout-bg:    #1C1728;
  --callout-border:#9A7EC4;
  --link:          #B09AD8;
}

/* =========================================================
   RESET & BASE
   ========================================================= */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html,
body {
  overflow-x: hidden;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-padding-top: 2rem;
}

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

/* Per-element fallback for browsers that support scroll-margin but not scroll-padding */
h1, h2, h3, h4, h5, h6 {
  scroll-margin-top: 2rem;
}

body {
  background-color: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--font-size-base);
  font-weight: 300;
  line-height: var(--line-height);
  transition: background-color var(--transition), color var(--transition);
}

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

a {
  color: var(--link);
  text-decoration: none;
  transition: color var(--transition);
}
a:hover { color: var(--accent); text-decoration: underline; }

code, kbd, samp {
  font-family: var(--font-mono);
  font-size: 0.875em;
}

/* =========================================================
   LAYOUT SKELETON
   ========================================================= */
.site-wrapper {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ---- Header / Nav ---- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  background-color: color-mix(in srgb, var(--bg) 85%, transparent);
}

.site-header__inner {
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 0 var(--space-lg);
  height: var(--header-height);
  display: flex;
  align-items: center;
  gap: var(--space-lg);
}

.site-logo {
  font-size: 1rem;
  font-weight: 500;
  letter-spacing: -0.02em;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}
.site-logo:hover { color: var(--accent); text-decoration: none; }

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

.site-nav a {
  font-size: 0.875rem;
  color: var(--text-muted);
  padding: 0.25rem 0.625rem;
  border-radius: 5px;
  transition: color var(--transition), background-color var(--transition);
  text-decoration: none;
}
.site-nav a:hover,
.site-nav a[aria-current="page"] {
  color: var(--text);
  background-color: var(--bg-subtle);
}

.site-header__actions {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-left: auto;
}

/* Theme toggle & RSS share a base icon-button style */
.theme-toggle,
.rss-link {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.375rem;
  border-radius: 6px;
  display: flex;
  align-items: center;
  transition: color var(--transition), background-color var(--transition);
  line-height: 1;
}
.theme-toggle { color: var(--text-muted); }
.rss-link     { color: var(--text-faint); text-decoration: none; }
.theme-toggle:hover,
.rss-link:hover {
  color: var(--accent);
  background-color: var(--bg-subtle);
  text-decoration: none;
}
/* theme-toggle hover keeps text colour (not accent) */
.theme-toggle:hover { color: var(--text); }
.theme-toggle svg,
.rss-link svg { width: 1rem; height: 1rem; }

/* Sun/moon icon visibility */
.icon-sun  { display: none; }
.icon-moon { display: block; }
[data-theme="dark"] .icon-sun  { display: block; }
[data-theme="dark"] .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .icon-sun  { display: block; }
  :root:not([data-theme]) .icon-moon { display: none; }
}

/* ---- Main ---- */
.site-main {
  flex: 1;
  padding: var(--space-xl) 0;
}

/* ---- Footer ---- */
.site-footer {
  border-top: 1px solid var(--border);
  padding: var(--space-lg);
  text-align: center;
  font-size: 0.8125rem;
  color: var(--text-faint);
}
.site-footer a       { color: var(--text-faint); }
.site-footer a:hover { color: var(--accent); text-decoration: none; }

/* =========================================================
   PAGE / PROSE CONTAINER
   ========================================================= */
/* .container--wide is kept as an alias in case templates use it */
.container,
.container--wide {
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 0 var(--space-lg);
}

/* =========================================================
   SHARED UTILITIES
   ========================================================= */

/* Bare list — removes bullets and padding */
.list-bare {
  list-style: none;
  padding: 0;
}

/* Uppercase label — used by section titles, ToC headings, nav labels */
.label-uppercase {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-faint);
}

/* Meta row — date / reading-time / tags inline strip
   (.meta-row kept as alias for any future template use) */
.post-item__meta,
.post-header__meta {
  display: flex;
  align-items: center;
  gap: 0;
  font-size: 0.75rem;
  color: var(--text-faint);
  flex-wrap: wrap;
}
.post-item__meta > * + *::before,
.post-header__meta > * + *::before {
  content: "·";
  margin: 0 0.5em;
  opacity: 0.5;
}

/* ToC link — shared by sidebar and mobile ToC */
.toc-link {
  display: block;
  padding: 0.2em 0.4em;
  border-radius: 5px;
  color: var(--text-muted);
  text-decoration: none;
  line-height: 1.4;
  overflow-wrap: break-word;
  transition: color var(--transition), background-color var(--transition);
}
.toc-link:hover {
  color: var(--accent);
  background-color: var(--bg-elevated);
  text-decoration: none;
}
.toc-link--nested {
  font-size: 0.9em;
  color: var(--text-faint);
}

/* =========================================================
   TYPOGRAPHY — PROSE
   ========================================================= */
.prose {
  color: var(--text);
  text-align: justify;
  hyphens: auto;
}

.prose h1, .prose h2, .prose h3,
.prose h4, .prose h5, .prose h6 {
  font-weight: 600;
  line-height: var(--line-height-tight);
  text-align: left;
  margin-top: 1.75em;
  margin-bottom: 0.75em;
  color: var(--text);
  letter-spacing: -0.03em;
}
.prose h1 { font-size: 1.875rem; margin-top: 0; }
.prose h2 { font-size: 1.375rem; }
.prose h3 { font-size: 1.125rem; font-weight: 500; }
.prose h4 { font-size: 1rem;     font-weight: 500; }

.prose h2 { border-bottom: 1px solid var(--border); padding-bottom: 0.6em; }

/* Anchor links on headings */
.prose h2 a, .prose h3 a, .prose h4 a {
  color: inherit;
  text-decoration: none;
}
.prose h2:hover a::after,
.prose h3:hover a::after {
  content: " #";
  color: var(--text-faint);
  font-weight: 400;
}

.prose p       { margin-bottom: 1em; }
.prose ul,
.prose ol      { margin-bottom: 1em; padding-left: 1.25em; }
.prose li      { margin-bottom: 0.2em; }
.prose li + li { margin-top: 0; }

.prose strong  { font-weight: 400; }
.prose em      { font-style: italic; }

.prose a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
}
.prose a:hover { color: var(--accent-hover); }

.prose blockquote {
  margin: 1.25em 0;
  padding: 0.5em 1em;
  border-left: 3px solid var(--accent);
  background-color: var(--bg-elevated);
  border-radius: 0 6px 6px 0;
  color: var(--text-muted);
  font-style: italic;
}
.prose blockquote p { margin-bottom: 0; }

.prose hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.75em 0;
}

/* When <hr> is immediately followed by a heading, suppress the hr's
   bottom margin entirely — the heading's margin-top (1.75em) provides
   the gap below the rule, matching the gap above it. The heading's
   margin-bottom (0.75em) then mirrors the gap below the h2 underline. */
.prose hr + h1,
.prose hr + h2,
.prose hr + h3,
.prose hr + h4,
.prose hr + h5,
.prose hr + h6 {
  margin-top: 0.75em;
}

.prose hr:has(+ h1),
.prose hr:has(+ h2),
.prose hr:has(+ h3),
.prose hr:has(+ h4),
.prose hr:has(+ h5),
.prose hr:has(+ h6) {
  margin-bottom: 0;
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9em;
  margin-bottom: 1.5em;
  overflow-x: auto;
  display: block;
}
.prose th, .prose td {
  padding: 0.5em 0.875em;
  border: 1px solid var(--border);
  text-align: left;
}
.prose thead { background-color: var(--bg-subtle); }
.prose tbody tr:nth-child(even) { background-color: var(--bg-elevated); }

.prose img {
  border-radius: 8px;
  margin: 1.5em auto;
  border: 1px solid var(--border);
}
.prose figure { margin: 1.5em 0; }
.prose figcaption {
  text-align: center;
  font-size: 0.85em;
  color: var(--text-faint);
  margin-top: 0.5em;
}

/* =========================================================
   CODE
   ========================================================= */
/* Inline code */
.prose code:not(pre code) {
  background-color: var(--code-bg);
  color: var(--accent);
  padding: 0.1em 0.4em;
  border-radius: 4px;
  font-size: 0.85em;
  border: 1px solid var(--border);
}

/* Zola 0.22 giallo line wrapper */
.giallo-l {
  display: inline-block;
  min-height: 1lh;
  width: 100%;
}
/* Zola 0.22 giallo line-number */
.giallo-ln {
  display: inline-block;
  user-select: none;
  margin-right: 0.4em;
  padding: 0.4em;
  min-width: 3ch;
  text-align: right;
  opacity: 0.8;
}

/* Fenced code blocks — .prose pre and Zola's pre.z-code share the same base */
.prose pre,
pre.z-code {
  position: relative;
  background-color: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1em 1.25em;
  overflow-x: auto;
  margin-bottom: 1.25em;
  font-size: 0.875em;
  line-height: 1.55;
  font-family: var(--font-mono);
}
.prose pre code { background: none; border: none; padding: 0; color: inherit; font-size: inherit; }

/* Syntax highlight theme switching */
.prose pre .hl-light { display: block; }
.prose pre .hl-dark  { display: none; }
[data-theme="dark"]  .prose pre .hl-light { display: none; }
[data-theme="dark"]  .prose pre .hl-dark  { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .prose pre .hl-light { display: none; }
  :root:not([data-theme]) .prose pre .hl-dark  { display: block; }
}

/* =========================================================
   TAGS & LABELS
   ========================================================= */
.tag {
  display: inline-flex;
  align-items: center;
  font-size: 0.75rem;
  font-weight: 500;
  padding: 0.2em 0.65em;
  border-radius: 999px;
  background-color: var(--tag-bg);
  color: var(--tag-text);
  text-decoration: none;
  transition: background-color var(--transition), color var(--transition);
  letter-spacing: 0.01em;
}
.tag:hover {
  background-color: var(--accent);
  color: white;
  text-decoration: none;
}

.tags { display: flex; flex-wrap: wrap; gap: 0.375rem; }
/* Spacing modifier used after meta rows in post lists */
.tags--spaced { margin-bottom: 0.65rem; }

/* =========================================================
   SERIES BADGE (inline on posts)
   ========================================================= */
.series-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
  background-color: var(--bg-elevated);
  border: 1px solid var(--border);
  padding: 0.3em 0.8em;
  border-radius: 6px;
  text-decoration: none;
}
.series-badge:hover { color: var(--accent); text-decoration: none; }

/* =========================================================
   POST LIST
   ========================================================= */
.post-list {
  list-style: none;
  padding: 0;
}

.post-item {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 0.875rem 0;
  border-bottom: 1px solid var(--border);
}
.post-item:first-child { padding-top: 0; }

/* Text column always takes remaining space */
.post-item__content {
  flex: 1;
  min-width: 0;
}

/* Featured image — right side, 3:2 ratio, restrained size */
.post-item__image-link {
  flex-shrink: 0;
  display: block;
}
.post-item__image {
  width: 6rem;
  aspect-ratio: 3 / 2;
  overflow: hidden;
  border-radius: 5px;
  background-color: var(--bg-subtle);
}
.post-item__image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: opacity 0.2s ease;
}
.post-item__image-link:hover .post-item__image img {
  opacity: 0.85;
}

.post-item__title {
  font-size: 1.125rem;
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1.3;
  margin-bottom: 0.2rem;
}
.post-item__title a       { color: var(--text); text-decoration: none; }
.post-item__title a:hover { color: var(--accent); text-decoration: none; }

.post-item__meta {
  margin-bottom: 0.4rem;
}
.post-item__series {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  margin-bottom: 0.5rem;
}
.post-item__summary {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.55;
  margin-bottom: 0.5rem;
}

/* Numbered series list variant */
.post-item--numbered {
  display: flex;
  gap: var(--space-md);
  align-items: baseline;
}
.post-item__num {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
  min-width: 1.5rem;
  flex-shrink: 0;
}
.post-item__body {
  flex: 1;
  min-width: 0;
}

/* =========================================================
   POST FEATURED IMAGE (full-width, top of post)
   ========================================================= */
.post-featured-image {
  width: 100%;
  aspect-ratio: 21 / 9;
  overflow: hidden;
  border-radius: 8px;
  margin-bottom: var(--space-lg);
  background-color: var(--bg-subtle);
}
.post-featured-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* =========================================================
   POST HEADER
   ========================================================= */
.post-header { margin-bottom: var(--space-md); }
.post-header__title {
  font-size: clamp(1.5rem, 4vw, 2rem);
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -0.03em;
  margin-bottom: 0.5rem;
}
.post-header__meta {
  margin-bottom: 0.75rem;
}
.post-header__divider {
  border: none;
  border-top: 1px solid var(--border);
  margin-top: var(--space-md);
}

/* =========================================================
   SERIES NAVIGATION (list of posts in the same series)
   ========================================================= */
.series-nav {
  background-color: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: var(--space-sm) var(--space-md);
  margin: 0 0 var(--space-md) 0;
}
.series-nav__title {
  font-weight: 600; /* CHECK: consider aligning to 500 type scale */
  margin-bottom: var(--space-sm);
}
.series-nav__series-name {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: var(--space-md);
  display: block;
}
.series-nav__list {
  list-style: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.series-nav__list li a {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: var(--text-muted);
  padding: 0.25em 0.5em;
  border-radius: 5px;
  text-decoration: none;
  transition: background-color var(--transition), color var(--transition);
}
.series-nav__list li a:hover { background-color: var(--bg-subtle); color: var(--text); }
.series-nav__list li.current a { color: var(--accent); font-weight: 600; /* CHECK */ }
.series-nav__list li .num {
  font-size: 0.75rem;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
  min-width: 1.5em;
}

/* =========================================================
   PREV / NEXT POST NAVIGATION
   ========================================================= */
.post-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-md);
  margin-top: var(--space-lg);
  padding-top: var(--space-lg);
  border-top: 1px solid var(--border);
}
.post-nav__item {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  text-decoration: none;
  padding: var(--space-md);
  border: 1px solid var(--border);
  border-radius: 8px;
  transition: border-color var(--transition), background-color var(--transition);
}
.post-nav__item:hover {
  border-color: var(--accent);
  background-color: var(--accent-subtle);
  text-decoration: none;
}
.post-nav__item--next { text-align: right; }
.post-nav__label {
  font-weight: 600; /* CHECK: consider aligning to 500 type scale */
}
.post-nav__title {
  font-size: 0.9rem;
  font-weight: 600; /* CHECK: consider aligning to 500 type scale */
  color: var(--text);
  line-height: 1.35;
}
@media (max-width: 700px) {
  .post-nav { grid-template-columns: 1fr; }
}

/* =========================================================
   POST LAYOUT (anchor for the floating ToC sidebar)
   ========================================================= */
.post-layout {
  position: relative;
}

/* =========================================================
   TOC SIDEBAR (desktop — floats outside the container)
   ========================================================= */
.toc-sidebar {
  display: none;
  font-size: 0.8125rem;
}

/*
 * Show only when there is room to the left of the container:
 * sidebar-width (12rem) + gap (1.5rem) + container-padding (1.5rem) + content (64ch≈590px) ≈ 830px.
 * 860px gives a small safety buffer.
 */
@media (min-width: 860px) {
  .toc-sidebar {
    display: block;
    position: absolute;
    right: calc(100% + var(--sidebar-gap));
    top: 0;
    width: var(--sidebar-width);
    /* Stretch to the full height of .post-layout so sticky has room to travel */
    height: 100%;
  }

  .toc-sidebar__inner {
    position: sticky;
    top: calc(var(--header-height) + var(--space-lg));
    max-height: calc(100vh - var(--header-height) - var(--space-lg) * 2);
    overflow-y: auto;
  }
}

.toc-sidebar__inner {
  padding: var(--space-md) 0;
}

.toc-sidebar__heading {
  margin-bottom: var(--space-sm);
}

.toc-sidebar__list,
.toc-sidebar__list ol,
.toc ol {
  list-style: none;
  padding: 0;
  margin: 0;
}

.toc-sidebar__list,
.toc ol {
  display: flex;
  flex-direction: column;
  gap: 0.05em;
}

/* =========================================================
   TABLE OF CONTENTS (mobile collapsible — .toc--mobile)
   ========================================================= */
.toc {
  margin-bottom: var(--space-lg);
  font-size: 0.875rem;
}
.toc summary {
  cursor: pointer;
  user-select: none;
  padding: 0;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.4em;
  margin-bottom: var(--space-sm);
}
.toc summary::-webkit-details-marker { display: none; }
.toc summary::after {
  content: "▾";
  font-size: 0.9em;
  transition: transform var(--transition);
}
details:not([open]).toc summary::after { transform: rotate(-90deg); }

.toc ol ol {
  padding-left: 1em;
  margin-top: 0.05em;
}
.toc li { margin: 0; }

/* Hide mobile ToC when desktop sidebar is visible */
@media (min-width: 860px) {
  .toc--mobile { display: none; }
}

/* =========================================================
   COPY BUTTON (on code blocks)
   ========================================================= */
.copy-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.3em;
  padding: 0.2em 0.55em;
  font-size: 0.75rem;
  font-family: var(--font-sans);
  font-weight: 500;
  color: var(--text-faint);
  background-color: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 5px;
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--transition), color var(--transition), background-color var(--transition);
  line-height: 1;
  white-space: nowrap;
  z-index: 1;
}
.prose pre:hover .copy-btn,
.copy-btn:focus-visible {
  opacity: 1;
}
.copy-btn:hover {
  color: var(--text);
  background-color: var(--bg-elevated);
  border-color: var(--border-strong);
}
.copy-btn--copied {
  color: var(--accent) !important;
  border-color: var(--accent) !important;
  opacity: 1 !important;
}

/* =========================================================
   SECTION / PAGE HEADERS
   ========================================================= */
.page-header {
  margin-bottom: var(--space-md);
  padding-bottom: var(--space-sm);
  border-bottom: 1px solid var(--border);
}
/* Avatar variant — row layout used on the About page */
.page-header--with-avatar {
  display: flex;
  align-items: flex-start;
  gap: var(--space-lg);
}
.page-header__avatar {
  width: 5rem;
  height: 5rem;
  border-radius: 50%;
  border: 2px solid var(--border);
  flex-shrink: 0;
  background-color: var(--bg-subtle);
  object-fit: cover;
}
@media (max-width: 500px) {
  .page-header--with-avatar { flex-direction: column; gap: var(--space-md); }
  .page-header__avatar       { width: 4rem; height: 4rem; }
}
.page-header__title {
  font-size: 1.625rem;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.15;
  margin-bottom: 0.35rem;
}
.page-header__description {
  font-size: 0.9375rem;
  text-align: justify;
  color: var(--text-muted);
  line-height: 1.6;
}

/* =========================================================
   HOME PAGE
   ========================================================= */
.home-intro {
  margin-bottom: var(--space-md);
  padding-bottom: var(--space-sm);
  border-bottom: 1px solid var(--border);
}
.home-intro__greeting {
  font-size: clamp(1.5rem, 5vw, 2.25rem);
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.1;
  margin-bottom: var(--space-sm);
}
.home-intro__bio {
  font-size: 1rem;
  color: var(--text-muted);
  text-align: justify;
  line-height: 1.65;
}
.home-intro__links {
  display: flex;
  gap: var(--space-md);
  margin-top: var(--space-md);
  flex-wrap: wrap;
}
.home-intro__links a {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 0.375em;
  transition: color var(--transition);
}
.home-intro__links a:hover { color: var(--accent); }
.home-intro__links svg     { width: 1em; height: 1em; }

/* Section title — extends .label-uppercase with margin and slightly wider tracking */
.section-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  margin-bottom: var(--space-md);
}

/* =========================================================
   SERIES LIST
   ========================================================= */
.series-list {
  list-style: none;
  padding: 0;
}

.series-item {
  display: flex;
  align-items: flex-start;
  gap: var(--space-md);
  padding: 0.875rem 0;
  border-bottom: 1px solid var(--border);
}
.series-item:first-child { padding-top: 0; }

.series-item__body { flex: 1; min-width: 0; }
.series-item__title {
  font-size: 1.125rem;
  font-weight: 500;
  line-height: 1.3;
  margin-bottom: 0.3rem;
  letter-spacing: -0.01em;
}
.series-item__title a       { color: var(--text); text-decoration: none; }
.series-item__title a:hover { color: var(--accent); }
.series-item__meta {
  font-size: 0.8125rem;
  color: var(--text-faint);
  margin-bottom: 0.5rem;
}
.series-item__description {
  font-size: 0.9375rem;
  color: var(--text-muted);
  line-height: 1.6;
}
.series-item__count {
  flex-shrink: 0;
  font-size: 0.8125rem;
  font-weight: 600; /* CHECK: consider aligning to 500 type scale */
  color: var(--text-faint);
  background-color: var(--bg-subtle);
  border: 1px solid var(--border);
  padding: 0.25em 0.65em;
  border-radius: 999px;
  white-space: nowrap;
}

/* =========================================================
   TAGS CLOUD PAGE
   ========================================================= */
.tags-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  align-items: center;
}

/* =========================================================
   CALLOUT / NOTE BOX
   ========================================================= */
.callout {
  background-color: var(--callout-bg);
  border-left: 3px solid var(--callout-border);
  border-radius: 0 8px 8px 0;
  padding: var(--space-md) var(--space-lg);
  margin: 1.5em 0;
}
.callout p        { margin-bottom: 0; }
.callout strong   { color: var(--callout-border); }

/* =========================================================
   SEARCH
   ========================================================= */
.search-form {
  display: flex;
  gap: var(--space-sm);
  margin-bottom: var(--space-lg);
}
.search-input {
  flex: 1;
  font-size: 1rem;
  font-family: var(--font-sans);
  padding: 0.625rem 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background-color: var(--bg-elevated);
  color: var(--text);
  outline: none;
  transition: border-color var(--transition);
}
.search-input:focus       { border-color: var(--accent); }
.search-input::placeholder { color: var(--text-faint); }

.search-results {
  list-style: none;
  padding: 0;
}
.search-result {
  padding: var(--space-md) 0;
  border-bottom: 1px solid var(--border);
}
.search-result__title a       { color: var(--text); font-weight: 600; /* CHECK */ }
.search-result__title a:hover { color: var(--accent); }
.search-result__excerpt       { font-size: 0.9rem; color: var(--text-muted); margin-top: 0.25rem; }
.search-result mark {
  background-color: var(--accent-subtle);
  color: var(--accent);
  border-radius: 2px;
  padding: 0 2px;
}
#search-status { font-size: 0.875rem; color: var(--text-faint); margin-bottom: var(--space-lg); }

/* =========================================================
   PAGE-HEADER EYEBROW (tag/series label above the h1)
   ========================================================= */
.page-header__eyebrow {
  display: block;
  font-size: 0.6em;
  font-weight: 400;
  color: var(--text-faint);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 0.25em;
}

/* Tags-cloud count badge */
.tag__count {
  opacity: 0.6;
  font-size: 0.8em;
  margin-left: 0.3em;
}

/* One-off utilities */
.text-muted { color: var(--text-muted); }
.mt-lg      { margin-top: var(--space-lg); }

/* =========================================================
   RESPONSIVE
   ========================================================= */
@media (max-width: 768px) {
  .site-header__inner,
  .container,
  .container--wide { padding-left: var(--space-md); padding-right: var(--space-md); }
  .site-main        { padding-top: var(--space-lg); padding-bottom: var(--space-lg); }
  .site-nav a       { padding: 0.25rem 0.5rem; }
}

@media (max-width: 500px) {
  .site-nav     { gap: 0; }
  .site-nav a   { font-size: 0.8125rem; }
}

@media (max-width: 400px) {
  .site-logo { font-size: 0.9375rem; }
  .site-main { padding-top: var(--space-md); padding-bottom: var(--space-md); }
  .container,
  .container--wide { padding-left: var(--space-sm); padding-right: var(--space-sm); }
}
