/* ---------------------------------------------------------------------------
   sidebar-layout theme
   Warm cream palette + frosted-glass sticky header + white cards, inspired
   by ccleaks.com/audit. Inter (body) + JetBrains Mono (code), self-hosted.
   --------------------------------------------------------------------------- */

@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/static/fonts/Inter-Regular.woff2") format("woff2");
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("/static/fonts/Inter-SemiBold.woff2") format("woff2");
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 750;
  font-display: swap;
  src: url("/static/fonts/Inter-Bold.woff2") format("woff2");
}
@font-face {
  font-family: "JetBrains Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/static/fonts/JetBrainsMono-Regular.woff2") format("woff2");
}

:root {
  color-scheme: light dark;

  /* Light palette (default) — warm cream + terminal-green. */
  --ink: #1a1715;             /* primary text */
  --ink-mute: #4a4540;        /* secondary text */
  --ink-faint: #5c5650;       /* tertiary text */
  --rule: #00000024;          /* visible hairlines */
  --rule-thin: #00000014;     /* very subtle hairlines */
  --bg: #f5f0e8;              /* page bg: warm cream */
  --bg-soft: #ede8df;         /* secondary fills (sidebar hover, code) */
  --bg-card: #ffffff;         /* card surfaces */
  --bg-glass: #f5f0e8b8;      /* header bg with alpha */
  --glass-inner-highlight: #ffffff99;
  --accent: #3a6ea5;          /* Windows-blue (matches logo) */
  --accent-ink: #2c5580;      /* darker blue for hover */
  --accent-tint: #3a6ea514;
  --accent-tint-strong: #3a6ea52e;

  /* Geometry */
  --max-content: 800px;       /* ~712px text measure inside .post padding */
  --sidebar-w: 280px;
  --toc-w: 240px;             /* right "On this page" pane */
  --header-h: 56px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  /* Typography */
  --font-sans: "Inter", "Inter Fallback", system-ui, arial;
  --font-mono: "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
  --tracking-eyebrow: 0.08em;

  /* Shadows */
  --shadow-sm: 0 1px 2px #0000000a, 0 1px 3px #0000000a;
  --shadow-md: 0 4px 12px #0000000f;
}

/* Dark palette — Claude warm-gray surface ramp (mirrors Anthropic's
   [data-theme=claude][data-mode=dark]) with a Windows-blue accent. */
[data-theme="dark"] {
  --ink: #faf9f5;             /* cream text (Claude text-000) */
  --ink-mute: #c2c0b6;        /* secondary (Claude text-200) */
  --ink-faint: #9c9a92;       /* tertiary (Claude text-400) */
  --rule: #ffffff20;
  --rule-thin: #ffffff0e;
  --bg: #1f1e1d;              /* page bg (Claude bg-200) */
  --bg-soft: #30302e;         /* lightest fill: hover, code, tags (bg-000) */
  --bg-card: #262624;         /* raised card surface (Claude bg-100) */
  --bg-glass: #1f1e1db8;      /* header bg with alpha */
  --glass-inner-highlight: #ffffff14;
  --accent: #6a9bd0;          /* Windows-blue, lifted for legibility on dark */
  --accent-ink: #8db8e0;      /* lighter blue for hover */
  --accent-tint: #6a9bd01f;
  --accent-tint-strong: #6a9bd03a;
  --shadow-sm: 0 1px 2px #00000033, 0 1px 3px #00000033;
  --shadow-md: 0 4px 12px #00000040;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* --- Sticky header (frosted glass, ccleaks-inspired) -------------------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 24px;
  height: var(--header-h);
  padding: 0 24px;
  background: var(--bg-glass);
  -webkit-backdrop-filter: blur(60px) saturate(210%) brightness(1.08);
  backdrop-filter: blur(60px) saturate(210%) brightness(1.08);
  border-bottom: 0.5px solid var(--rule-thin);
  box-shadow:
    inset 0 0.5px var(--glass-inner-highlight),
    0 1px 2px #0000000a,
    0 4px 24px #0000000f;
}

.site-name {
  font-weight: 600;
  font-size: 1.0625rem;
  color: var(--ink);
  text-decoration: none;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
}

.site-name img {
  height: 30px;
  width: auto;
  display: block;
}

.top-nav { margin-left: auto; }
.top-nav ul {
  display: flex;
  gap: 24px;
  list-style: none;
  margin: 0;
  padding: 0;
}
.top-nav a {
  color: var(--ink-mute);
  text-decoration: none;
  font-size: 0.9375rem;
}
.top-nav a:hover { color: var(--ink); }
.top-nav a[aria-current="page"] { color: var(--accent); }

/* Dark/Light theme toggle button */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--rule-thin);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink-mute);
  cursor: pointer;
  transition: background 0.15s ease-out, color 0.15s ease-out,
              border-color 0.15s ease-out;
}
.theme-toggle:hover {
  color: var(--ink);
  border-color: var(--rule);
  background: var(--bg-soft);
}
.theme-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.theme-toggle svg { display: block; }

/* Show the moon (next-action: go dark) when light, sun (next-action: go
   light) when dark. */
:root[data-theme="light"] .icon-sun,
:root[data-theme="dark"]  .icon-moon { display: none; }

.sidebar-toggle {
  display: none;
  margin-left: auto;
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 6px 12px;
  font-family: inherit;
  font-size: 0.875rem;
  color: var(--ink-mute);
  cursor: pointer;
}

/* --- Layout grid: sidebar + content ------------------------------------- */

.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  gap: 48px;
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 24px 64px;
  /* Clip at the full-width layout, not at .post-content: a glossary card can then
     spill over the side gutters (fully visible, lifted by its z-index) while the
     page still cannot scroll sideways. overflow: clip creates no scroll container,
     so the sticky sidebar and TOC are unaffected. */
  overflow-x: clip;
}

.sidebar {
  position: sticky;
  top: calc(var(--header-h) + 32px);
  align-self: start;
  max-height: calc(100vh - var(--header-h) - 64px);
  overflow-y: auto;
  padding-right: 8px;
  font-size: 0.9375rem;
}

.sidebar-group { margin-bottom: 5px; }
.sidebar-group:last-child { margin-bottom: 0; }

/* The whole group is a <details>; <summary> is the clickable header. */
.sidebar-group-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 2.5px 0;
  border-bottom: 1px solid var(--rule);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
  cursor: pointer;
  user-select: none;
  list-style: none;          /* Firefox: hide default marker */
}
.sidebar-group-title::-webkit-details-marker { display: none; }
.sidebar-group-title::marker { content: ""; }

/* Custom chevron, rotates when open. */
.sidebar-group-title::before {
  content: "";
  width: 0;
  height: 0;
  border-left: 4px solid currentColor;
  border-top: 3px solid transparent;
  border-bottom: 3px solid transparent;
  transition: transform 0.15s ease-out;
  flex-shrink: 0;
}
.sidebar-group[open] > .sidebar-group-title::before {
  transform: rotate(90deg);
}

.sidebar-group-title:hover { color: var(--ink-mute); }
.sidebar-group-title:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.sidebar-group-label { flex: 1; }
.sidebar-group-count {
  font-weight: 400;
  font-size: 0.6875rem;
  color: var(--ink-faint);
}

/* "All <tag> posts →" link at the bottom of an expanded group. */
.sidebar-group-link {
  margin-top: 1.5px;
  padding-top: 1.5px;
  border-top: 1px dashed var(--rule);
}
.sidebar-group-link a {
  font-size: 0.75rem;
  color: var(--ink-faint);
  font-style: italic;
}
.sidebar-group-link a:hover { color: var(--accent); background: transparent; }

.sidebar-list {
  list-style: none;
  margin: 0;
  padding: 2.5px 0 0;
}
.sidebar-list li { margin: 0 0 1.5px; }
.sidebar-list a {
  display: block;
  padding: 1.5px 8px;
  margin-left: -8px;
  border-radius: 4px;
  color: var(--ink-mute);
  text-decoration: none;
  font-size: 0.875rem;
  line-height: 1.3;
}
.sidebar-list a:hover {
  background: var(--bg-soft);
  color: var(--ink);
}
.sidebar-list a[aria-current="page"] {
  background: var(--bg-soft);
  color: var(--accent);
  font-weight: 500;
}

/* Sidebar scrollbar: thin, muted, theme-aware (only shows when it overflows). */
.sidebar {
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--ink-faint) 40%, transparent) transparent;
}
.sidebar::-webkit-scrollbar { width: 8px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--ink-faint) 38%, transparent);
  border-radius: 4px;
}
.sidebar::-webkit-scrollbar-thumb:hover {
  background: color-mix(in srgb, var(--ink-faint) 68%, transparent);
}

/* Topic icons. Each is a currentColor mask, so it follows the label colour in
   both themes. Related tags share an icon to keep the set small and maintainable. */
.sidebar {
  --ic-snow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 2v20M3.5 7l17 10M20.5 7l-17 10'/%3E%3C/svg%3E");
  --ic-gear: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='4'/%3E%3Cpath d='M12 2v3M12 19v3M2 12h3M19 12h3M4.9 4.9l2.1 2.1M17 17l2.1 2.1M19.1 4.9L17 7M7 17l-2.1 2.1'/%3E%3C/svg%3E");
  --ic-branch: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='7' cy='5' r='2.4'/%3E%3Ccircle cx='7' cy='19' r='2.4'/%3E%3Ccircle cx='17' cy='9' r='2.4'/%3E%3Cpath d='M7 7.4v9.2M7 13c0-3 1-5 4-6l2.5-1'/%3E%3C/svg%3E");
  --ic-term: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='4' width='18' height='16' rx='2'/%3E%3Cpath d='M7 9l3 3-3 3M13 15h4'/%3E%3C/svg%3E");
  --ic-window: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='4' width='18' height='16' rx='1'/%3E%3Cpath d='M3 9h18M11 9v11'/%3E%3C/svg%3E");
  --ic-cube: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 2.5l8.5 4.8v9.4L12 21.5l-8.5-4.8V7.3z'/%3E%3Cpath d='M12 12V2.5M3.5 7.3L12 12l8.5-4.7'/%3E%3C/svg%3E");
  --ic-layers: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 2.5l9 5-9 5-9-5z'/%3E%3Cpath d='M3 12.5l9 5 9-5M3 16.5l9 5 9-5'/%3E%3C/svg%3E");
  --ic-chip: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='6' y='6' width='12' height='12' rx='1'/%3E%3Cpath d='M9 2v4M15 2v4M9 18v4M15 18v4M2 9h4M2 15h4M18 9h4M18 15h4'/%3E%3C/svg%3E");
  --ic-shield: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 2.5l7.5 3v5.5c0 5-3.2 8-7.5 9.5-4.3-1.5-7.5-4.5-7.5-9.5V5.5z'/%3E%3C/svg%3E");
  --ic-sigma: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M17.5 4.5H6.5l6 7.5-6 7.5h11'/%3E%3C/svg%3E");
  --ic-lambda: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M7 4.5l8 15M12.5 12L6 19.5'/%3E%3C/svg%3E");
  --ic-pipe: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='9' width='18' height='6' rx='3'/%3E%3Cpath d='M9 9v6M15 9v6'/%3E%3C/svg%3E");
  --ic-doc: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6.5 3h7l4 4v14h-11z'/%3E%3Cpath d='M13.5 3v4h4M9 12h6M9 16h5'/%3E%3C/svg%3E");
}
.sidebar-group-label { --ti: var(--ic-doc); }
.sidebar-group-label::before {
  content: "";
  display: inline-block;
  flex-shrink: 0;
  width: 12px;
  height: 12px;
  margin-right: 6px;
  vertical-align: -2px;
  background-color: currentColor;
  opacity: 0.72;
  -webkit-mask: var(--ti) center / contain no-repeat;
  mask: var(--ti) center / contain no-repeat;
}
.sidebar-group-label[data-topic="nix"],
.sidebar-group-label[data-topic="nixos"],
.sidebar-group-label[data-topic="iac"]                 { --ti: var(--ic-snow); }
.sidebar-group-label[data-topic="rust"],
.sidebar-group-label[data-topic="build-systems"]       { --ti: var(--ic-gear); }
.sidebar-group-label[data-topic="git"]                 { --ti: var(--ic-branch); }
.sidebar-group-label[data-topic="just"],
.sidebar-group-label[data-topic="shell"],
.sidebar-group-label[data-topic="tooling"],
.sidebar-group-label[data-topic="workflow"],
.sidebar-group-label[data-topic="zellij"],
.sidebar-group-label[data-topic="linux"]               { --ti: var(--ic-term); }
.sidebar-group-label[data-topic="windows"],
.sidebar-group-label[data-topic="xfce"]                { --ti: var(--ic-window); }
.sidebar-group-label[data-topic="virtualbox"]          { --ti: var(--ic-cube); }
.sidebar-group-label[data-topic="caching"],
.sidebar-group-label[data-topic="ci"]                  { --ti: var(--ic-layers); }
.sidebar-group-label[data-topic="compilers"],
.sidebar-group-label[data-topic="parallelism"],
.sidebar-group-label[data-topic="embedded"],
.sidebar-group-label[data-topic="petri-nets"]          { --ti: var(--ic-chip); }
.sidebar-group-label[data-topic="privacy"],
.sidebar-group-label[data-topic="reverse-engineering"],
.sidebar-group-label[data-topic="wireguard"],
.sidebar-group-label[data-topic="tuya"],
.sidebar-group-label[data-topic="iot"]                 { --ti: var(--ic-shield); }
.sidebar-group-label[data-topic="mathjax"],
.sidebar-group-label[data-topic="proof"]               { --ti: var(--ic-sigma); }
.sidebar-group-label[data-topic="Haskell"]             { --ti: var(--ic-lambda); }
.sidebar-group-label[data-topic="pipes"]               { --ti: var(--ic-pipe); }

/* --- Main content column ------------------------------------------------ */

.content {
  min-width: 0;
  max-width: var(--max-content);
}

/* --- Right pane: "On this page" TOC (post pages only) ------------------- */

/* Hidden by default; the third grid column + this pane only appear on post
   pages wide enough to hold all three columns. */
.toc { display: none; }

@media (min-width: 1241px) {
  .layout.has-toc {
    max-width: 1440px;
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--toc-w);
  }
  .layout.has-toc .toc { display: block; }
}

.toc {
  position: sticky;
  top: calc(var(--header-h) + 32px);
  align-self: start;
  max-height: calc(100vh - var(--header-h) - 64px);
  overflow-y: auto;
  font-size: 0.875rem;
}
.toc-title {
  margin: 0 0 8px;
  padding-bottom: 6px;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.toc-list { list-style: none; margin: 0; padding: 0; }
.toc-item { margin: 0; }
.toc-link {
  display: block;
  padding: 4px 0 4px 12px;
  margin-left: -1px;
  border-left: 2px solid var(--rule);
  color: var(--ink-mute);
  text-decoration: none;
  line-height: 1.4;
}
.toc-link:hover { color: var(--ink); text-decoration: none; }
.toc-h3 .toc-link { padding-left: 24px; font-size: 0.8125rem; }
.toc-link.active {
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 600;
}

h1, h2, h3, h4, h5, h6 {
  color: var(--ink);
  letter-spacing: -0.015em;
  line-height: 1.25;
}

h1 { font-size: 2rem; margin: 0 0 16px; font-weight: 600; }

/* Blog post title (Archive/tag page h1s keep the larger size). */
.post-header h1 { font-size: 25px; font-weight: 400; }

h2 { font-size: 1.5rem; margin: 40px 0 12px; font-weight: 600; }
h3 { font-size: 1.1875rem; margin: 32px 0 8px; font-weight: 600; }

p { margin: 0 0 16px; }

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

/* --- Post summary cards (index, tag) ------------------------------------ */

.post-list { display: flex; flex-direction: column; gap: 16px; }

/* Card grid: the title sprite spans the title + meta rows; the summary spans
   the full width below. With no sprite the icon column collapses to 0, so
   iconless cards keep their title/meta/summary flush-left. */
.post-summary {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-areas:
    "icon  title"
    "icon  meta"
    "summary summary";
  align-items: start;
  background: var(--bg-card);
  border: 1px solid var(--rule-thin);
  border-radius: var(--radius-lg);
  padding: 24px 28px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.15s ease-out, transform 0.15s ease-out;
}
.post-summary > .post-header-sprite { grid-area: icon; margin: 2px 18px 0 0; }
.post-summary > h2 { grid-area: title; }
.post-summary > .post-meta { grid-area: meta; }
.post-summary > .summary { grid-area: summary; }
/* Let the content column shrink below its content's min-content so a long title
   or the tag row cannot force the card wider than a narrow (phone) viewport. */
.post-summary > :is(h2, .post-meta, .summary) { min-width: 0; }
.post-summary:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.post-summary h2 { margin: 0 0 8px; font-size: 1.375rem; }
.post-summary h2 a { color: var(--ink); }
.post-summary h2 a:hover { color: var(--accent); }
.post-summary .summary {
  color: var(--ink-mute);
  margin-bottom: 0;
  font-size: 0.9375rem;
}

.post-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  font-size: 0.875rem;
  color: var(--ink-faint);
  margin-bottom: 8px;
}
.post-meta time { font-variant-numeric: tabular-nums; }

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  list-style: none;
  margin: 0;
  padding: 0;
}
.tag-list a {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--bg-soft);
  color: var(--ink-mute);
  font-size: 0.75rem;
}
.tag-list a:hover { background: var(--rule); text-decoration: none; }

.reading-time::before { content: "·"; margin-right: 12px; color: var(--ink-faint); }

/* --- Post page ---------------------------------------------------------- */

.post {
  background: var(--bg-card);
  border: 1px solid var(--rule-thin);
  border-radius: var(--radius-lg);
  padding: 40px 44px;
  box-shadow: var(--shadow-sm);
}

.post-header {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-bottom: 32px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--rule-thin);
}
/* Large title sprite to the left, spanning the title + date/tags block. */
.post-header-sprite {
  flex: none;
  height: 3.6em;
  width: auto;
  image-rendering: pixelated;
}
.post-header-text { flex: 1 1 auto; min-width: 0; }
.post-header-text h1 { margin: 0 0 8px; }
.post-content { font-size: 1rem; line-height: 1.625; }
.post-content img { max-width: 100%; height: auto; }
/* Figures are click-to-zoom (the script makes them focusable buttons). The
   header sprite and site logo live outside .post-content, so they are
   untouched. */
.post-content img { cursor: zoom-in; }
.post-content img:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

/* Full-screen lightbox for a zoomed figure. Injected once by base.html and
   toggled with [hidden]; the dark scrim suits both themes because every figure
   carries its own light background. */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  overflow: auto;
  overscroll-behavior: contain;      /* don't chain scroll to the page behind */
  background: rgba(15, 18, 24, 0.86);
  backdrop-filter: blur(4px);
  cursor: zoom-out;
  animation: lb-fade 0.16s ease-out;
}
.lightbox[hidden] { display: none; }
/* The flex centering lives on a STATIC inner wrapper, not on the fixed scrim:
   Firefox collapses an aspect-ratio-only SVG (viewBox, no width/height) to
   zero when its flex parent is position:fixed. A static flex parent sizes it
   correctly. */
.lb-inner {
  /* content-box, not border-box: border-box + min-height:100% + padding makes
     Firefox collapse the aspect-ratio-only SVG to zero at small viewports. The
     figure's own max-height/width caps supply the margins, so no padding here. */
  box-sizing: content-box;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
}
.lightbox img {
  /* These figures carry a viewBox but no intrinsic width/height, so a box with
     only max-* and width:auto collapses to nothing, and object-fit paints
     nothing (Firefox needs an intrinsic size). A DEFINITE width makes the
     browser derive the height from the viewBox ratio; max-height then caps tall
     figures and the ratio is preserved. This scales small figures UP to fill. */
  width: min(96vw, 1500px);
  height: auto;
  max-height: 86vh;
  border-radius: 10px;
  /* box-shadow, NOT filter: drop-shadow — the latter, combined with the scrim's
     backdrop-filter, makes Firefox drop the SVG paint entirely. */
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.55);
  animation: lb-pop 0.18s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
.lightbox figcaption {
  max-width: min(96vw, 70ch);
  margin: 0;
  color: #e7eaf0;
  font-size: 0.9rem;
  line-height: 1.5;
  text-align: center;
}
.lightbox .lb-close {
  position: fixed;
  top: 14px;
  right: 18px;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  font-size: 26px;
  line-height: 1;
  color: #e7eaf0;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  cursor: pointer;
}
.lightbox .lb-close:hover { background: rgba(255, 255, 255, 0.18); }
@keyframes lb-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes lb-pop {
  from { opacity: 0; transform: scale(0.96); }
  to   { opacity: 1; transform: scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  .lightbox, .lightbox img { animation: none; }
}

/* GitBook-style hover anchor. niche emits an empty <a class="anchor" id=…>
   as the first child of each heading; we render a "#" in the left gutter and
   reveal it when the heading is hovered. */
.post-content :is(h1, h2, h3, h4) {
  position: relative;
  scroll-margin-top: calc(var(--header-h) + 16px);
}
.post-content .anchor {
  position: absolute;
  scroll-margin-top: calc(var(--header-h) + 16px);
  left: -0.3em;
  transform: translateX(-100%);
  padding: 0 0.25em;
  color: var(--ink-faint);
  font-weight: 400;
  text-decoration: none;
  opacity: 0;
  transition: opacity 0.12s ease-out, color 0.12s ease-out;
}
.post-content .anchor::before { content: "#"; }
.post-content :is(h1, h2, h3, h4):hover > .anchor,
.post-content .anchor:focus-visible { opacity: 1; }
.post-content .anchor:hover { color: var(--accent); }

/* Section accent: a blue left bar on section headings (h2/h3 — niche shifts
   markdown levels down one, so `##` sections render as h3), and a smaller
   blue square on deeper h4 subsections. The heading text is indented to make
   room; the "#" anchor stays further out in the gutter, so they never collide. */
.post-content h2,
.post-content h3,
.post-content h4 { padding-left: 16px; }
.post-content h2::before,
.post-content h3::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.18em;
  bottom: 0.18em;
  width: 3px;
  border-radius: 2px;
  background: var(--accent);
}
.post-content h4::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.5em;
  width: 7px;
  height: 7px;
  border-radius: 2px;
  background: var(--accent);
}

blockquote {
  margin: 16px 0;
  padding: 0 16px;
  border-left: 3px solid var(--rule);
  color: var(--ink-mute);
}

ul, ol { padding-left: 24px; }
li { margin-bottom: 4px; }

code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--bg-soft);
  padding: 1px 5px;
  border-radius: 3px;
}

pre {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  line-height: 1.5;
  background: var(--bg-soft);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 16px;
  overflow-x: auto;
}
pre code { background: none; padding: 0; font-size: 1em; }

hr {
  border: none;
  border-top: 1px solid var(--rule);
  margin: 32px 0;
}

table {
  border-collapse: collapse;
  width: 100%;
  margin: 16px 0;
}
th, td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--rule);
  text-align: left;
}
th { font-weight: 600; }

/* --- Archive ------------------------------------------------------------ */

.archive-year {
  margin-bottom: 16px;
  background: var(--bg-card);
  border: 1px solid var(--rule-thin);
  border-radius: var(--radius-lg);
  padding: 24px 28px;
  box-shadow: var(--shadow-sm);
}
.archive-year h2 {
  font-size: 0.75rem;
  letter-spacing: var(--tracking-eyebrow);
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 0 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--rule-thin);
}
.archive-list { list-style: none; padding: 0; margin: 0; }
.archive-list li {
  display: flex;
  gap: 16px;
  padding: 6px 0;
  border-bottom: 1px solid var(--rule);
}
.archive-list li:last-child { border-bottom: none; }
.archive-list time {
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
  min-width: 90px;
}

/* --- Pagination --------------------------------------------------------- */

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 48px;
  padding-top: 24px;
  border-top: 1px solid var(--rule);
  font-size: 0.875rem;
}
.pagination span { color: var(--ink-faint); }

/* --- Wikilinks ---------------------------------------------------------- */

.wikilink.broken-link {
  color: #cc4b00;
  border-bottom: 1px dashed currentColor;
}

/* --- Footer ------------------------------------------------------------- */

.site-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 16px;
  border-top: 1px solid var(--rule);
  padding: 24px;
  color: var(--ink-faint);
  font-size: 0.875rem;
}
.footer-copy { margin-right: 4px; }
.footer-icon {
  display: inline-flex;
  color: var(--ink-faint);          /* grey, matches footer text */
  transition: color 0.15s ease-out, opacity 0.15s ease-out;
}
.footer-icon svg { width: 18px; height: 18px; display: block; fill: currentColor; }
.footer-icon:hover { color: var(--ink); }
.footer-icon--muted { opacity: 0.45; }   /* the secondary GitHub, lighter */
.footer-icon--muted:hover { opacity: 1; color: var(--ink); }

/* --- Mobile ------------------------------------------------------------- */

@media (max-width: 880px) {
  .layout {
    grid-template-columns: 1fr;
    gap: 0;
    padding: 16px 16px 32px;
  }
  .sidebar {
    position: static;
    max-height: 0;
    overflow: hidden;
    padding: 0;
    border-bottom: 1px solid var(--rule);
    transition: max-height 0.2s ease-out;
  }
  .sidebar.open {
    max-height: 80vh;
    overflow-y: auto;
    padding: 16px 0;
    margin-bottom: 24px;
  }
  .top-nav { display: none; }
  .sidebar-toggle { display: inline-block; }
}

/* ---- inline glossary callouts (hover / focus) ---- */
.gloss {
  position: relative;
  cursor: help;
  font-weight: 600;
  border-bottom: 1px dashed var(--accent);
}
.gloss::after {
  content: "?";
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.4em;
  height: 1.4em;
  font-family: var(--font-mono);
  font-style: normal;
  font-weight: 700;
  font-size: 0.58em;
  vertical-align: super;
  margin-left: 2px;
  color: var(--bg-card);
  background: var(--accent);
  border-radius: 50%;
}
.gloss:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 2px;
}
.gloss > .gloss-card {
  position: absolute;
  z-index: 60; /* above the sticky site-header (z-index 50) so first-line cards are not occluded */
  cursor: auto; /* the help cursor belongs to the term, not the whole card */
  left: 50%;
  bottom: 165%;
  width: min(300px, 78vw);
  transform: translateX(-50%) translateY(6px);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.15s ease, transform 0.15s ease;
  background: var(--bg-card);
  border: 1px solid var(--rule);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  text-align: left;
  white-space: normal;
  font-weight: 400;
}
.gloss:hover > .gloss-card,
.gloss:focus > .gloss-card,
.gloss:focus-within > .gloss-card {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}
.gloss > .gloss-card::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 7px solid transparent;
  border-top-color: var(--bg-card);
}
.gloss-card .gc-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 9px;
  padding: 8px 8px 8px 13px;
  background: var(--accent-tint);
  border-bottom: 1px solid var(--rule);
}
.gloss-card .gc-name {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--ink);
}
/* Close button, injected by base.html so a pinned (clicked/tapped) card can be
   dismissed without clicking elsewhere. */
.gloss-card .gc-close {
  flex: none;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--ink-faint);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}
.gloss-card .gc-close:hover {
  background: var(--bg-soft);
  color: var(--ink);
}
/* The close button sets data-dismissed, which must beat :hover/:focus-within. */
.gloss[data-dismissed] > .gloss-card {
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
}
.gloss-card .gc-body {
  padding: 11px 13px;
  font-size: 0.82rem;
  line-height: 1.5;
  color: var(--ink-mute);
}
.gloss-card .gc-foot {
  padding: 8px 13px;
  border-top: 1px solid var(--rule);
  font-family: var(--font-mono);
  font-size: 0.72rem;
}
.gloss-card .gc-foot a {
  color: var(--accent);
  text-decoration: none;
}
.gloss-card .gc-foot a:hover {
  text-decoration: underline;
}
@media (prefers-reduced-motion: reduce) {
  .gloss > .gloss-card { transition: none; }
}
