/* ==========================================================================
   Catppuccin Mocha (dark, default) / Latte (light)
   Latte accents are darkened where needed to meet WCAG AA on the light base.
   ========================================================================== */
:root {
  color-scheme: dark;
  --base: #1e1e2e; --mantle: #181825; --crust: #11111b;
  --surface0: #313244; --surface1: #45475a; --overlay0: #6c7086;
  --subtext0: #a6adc8; --subtext1: #bac2de; --text: #cdd6f4;
  --mauve: #cba6f7; --blue: #89b4fa; --sapphire: #74c7ec; --green: #a6e3a1;
  --peach: #fab387; --pink: #f5c2e7; --yellow: #f9e2af; --lavender: #b4befe;
  --glow: 0 0 0 1px color-mix(in srgb, var(--mauve) 45%, transparent),
          0 0 24px -4px color-mix(in srgb, var(--mauve) 45%, transparent);
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --base: #eff1f5; --mantle: #e6e9ef; --crust: #dce0e8;
    --surface0: #dfe2ea; --surface1: #bcc0cc; --overlay0: #8c8fa1;
    --subtext0: #5c5f77; --subtext1: #4c4f69; --text: #3a3c52;
    --mauve: #8839ef; --blue: #1756d6; --sapphire: #146f80; --green: #256b18;
    --peach: #a3480a; --pink: #b13e92; --yellow: #8f5a0c; --lavender: #4f5fd6;
  }
}
:root[data-theme="light"] {
  color-scheme: light;
  --base: #eff1f5; --mantle: #e6e9ef; --crust: #dce0e8;
  --surface0: #dfe2ea; --surface1: #bcc0cc; --overlay0: #8c8fa1;
  --subtext0: #5c5f77; --subtext1: #4c4f69; --text: #3a3c52;
  --mauve: #8839ef; --blue: #1756d6; --sapphire: #146f80; --green: #256b18;
  --peach: #a3480a; --pink: #b13e92; --yellow: #8f5a0c; --lavender: #4f5fd6;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--base);
  color: var(--text);
  font: 400 1.125rem/1.7 "IBM Plex Sans", system-ui, sans-serif;
  font-feature-settings: "kern", "liga";
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
code, pre, kbd, samp { font-family: "IBM Plex Mono", ui-monospace, monospace; }
a { color: inherit; }
:focus-visible { outline: none; box-shadow: var(--glow); border-radius: 4px; }
::selection { background: color-mix(in srgb, var(--mauve) 30%, transparent); }

.wrap { max-width: 68rem; margin: 0 auto; padding: 0 1.25rem; }

.gradient {
  width: fit-content; max-width: 100%;
  background: linear-gradient(100deg, var(--mauve) 10%, var(--blue) 90%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}

/* ---------- Header ---------- */
.site-header {
  border-bottom: 1px solid var(--surface0);
  font: 400 0.875rem/1.4 "IBM Plex Mono", monospace;
}
.header-inner {
  display: flex; flex-wrap: wrap; align-items: center; gap: .75rem 1.5rem;
  min-height: 3.75rem; padding-top: .75rem; padding-bottom: .75rem;
}
.crumb { color: var(--subtext0); min-width: 0; overflow-wrap: anywhere; }
.crumb a { text-decoration: none; }
.crumb a:hover { color: var(--text); }
.crumb-home {
  font-weight: 500;
  background: linear-gradient(90deg, var(--mauve), var(--blue));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.crumb .sep { color: var(--overlay0); padding: 0 .15em; }
.crumb [aria-current] { color: var(--text); }
.nav { margin-left: auto; display: flex; flex-wrap: wrap; gap: .5rem 1.25rem; align-items: center; }
.nav a { color: var(--subtext0); text-decoration: none; }
.nav a:hover, .nav a[aria-current] { color: var(--text); }
.theme-toggle {
  font: inherit; color: var(--subtext0); background: none; cursor: pointer;
  border: 1px solid var(--surface1); border-radius: 6px; padding: .3rem .55rem;
}
.theme-toggle:hover { color: var(--text); border-color: var(--overlay0); }
@media (max-width: 640px) {
  .nav { margin-left: 0; width: 100%; }
  .theme-toggle { margin-left: auto; }
}

/* ---------- Tags / lede ---------- */
.tags { display: flex; flex-wrap: wrap; gap: .5rem; font: .8125rem/1 "IBM Plex Mono", monospace; margin-bottom: 1.25rem; }
.tag { background: var(--surface0); color: var(--subtext1); padding: .35rem .55rem; border-radius: 5px; text-decoration: none; }
a.tag:hover { color: var(--text); box-shadow: var(--glow); }
.lede { color: var(--subtext1); font-size: 1.1875rem; }
.lede p { margin: 0; }
.lede a { color: var(--sapphire); text-underline-offset: .2em; text-decoration-thickness: 1px; }

/* ---------- Home ---------- */
.home-intro { padding: 4.5rem 0 1rem; max-width: 40rem; }
.home-intro h1 {
  margin: 0 0 .75rem; font-size: clamp(2.25rem, 6vw, 3.25rem); line-height: 1.1;
  font-weight: 700; letter-spacing: -0.025em;
}
.home-about { max-width: 44rem; margin: 1rem 0 4rem; padding-top: 2rem; border-top: 1px solid var(--surface0); }

/* ---------- Index lists ---------- */
.index { max-width: 44rem; padding-bottom: 3rem; }
.index section { margin-top: 2.75rem; }
.index-head {
  font: 500 .8125rem/1 "IBM Plex Mono", monospace; letter-spacing: .08em;
  margin: 0 0 .75rem; display: flex; gap: .6rem; align-items: baseline;
}
.index-head a { color: var(--blue); text-decoration: none; }
.index-head a:hover { text-decoration: underline; text-underline-offset: .25em; }
.index-head .count { color: var(--subtext0); }
.page-list { list-style: none; margin: 0; padding: 0; }
.page-list a {
  display: block; padding: .45rem .75rem; margin: 0 -.75rem; border-radius: 8px;
  font-weight: 500; text-decoration: none; transition: background .15s, box-shadow .15s, color .15s;
}
.page-list a:hover { background: var(--mantle); box-shadow: var(--glow); color: var(--mauve); }

/* ---------- Section page ---------- */
.section-head { padding: 3.5rem 0 .5rem; max-width: 44rem; }
.section-head h1 { margin: 0 0 .75rem; font-size: clamp(2.25rem, 5.5vw, 3rem); line-height: 1.12; font-weight: 700; letter-spacing: -0.025em; }
.section-head .lede { margin: 0; }
.section-head + .index { margin-top: 1.5rem; }

/* ---------- Article layout ---------- */
.article-grid { display: grid; grid-template-columns: minmax(0, 42rem); gap: 4rem; padding: 3.5rem 0 4rem; }
@media (min-width: 1100px) {
  .article-grid:has(.toc-aside:not([hidden])) { grid-template-columns: minmax(0, 42rem) 14rem; justify-content: space-between; }
}
.article-header { margin-bottom: 2.5rem; }
.article-header h1 {
  font-size: clamp(2.25rem, 5.5vw, 3rem); line-height: 1.12; font-weight: 700;
  letter-spacing: -0.025em; margin: 0;
}

/* ---------- Prose ---------- */
.prose { overflow-wrap: break-word; }
.prose > * { margin-top: 0; margin-bottom: 1.35em; }
.prose h1, .prose h2, .prose h3, .prose h4, .prose h5 { line-height: 1.25; letter-spacing: -0.01em; scroll-margin-top: 1.5rem; }
/* Page title is the only h1; any stray body h1 renders as a section heading. */
.prose h1, .prose h2 { font-size: 1.625rem; font-weight: 600; color: var(--blue); margin: 2.2em 0 .7em; }
.prose h3 { font-size: 1.3125rem; font-weight: 600; color: var(--green); margin: 2em 0 .6em; }
.prose h4, .prose h5 { font-size: 1.125rem; font-weight: 600; color: var(--peach); margin: 1.8em 0 .5em; }
.prose > :first-child { margin-top: 0; }
.prose strong { color: var(--peach); font-weight: 600; }
.prose em { color: var(--pink); }
.prose strong em, .prose em strong { color: var(--peach); }
.prose a {
  color: var(--sapphire); text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--sapphire) 40%, transparent);
  text-decoration-thickness: 1px; text-underline-offset: .22em; transition: text-decoration-color .15s;
}
.prose a:hover { text-decoration-color: currentColor; }
.prose :is(h1, h2, h3, h4, h5) code { background: none; padding: 0; font-size: .92em; }
.prose code { font-size: .86em; color: var(--green); background: var(--surface0); padding: .12em .38em; border-radius: 4px; }
.prose pre {
  background: var(--mantle); border: 1px solid var(--surface0); border-radius: 8px;
  padding: 1rem 1.25rem; overflow-x: auto; font-size: .875rem; line-height: 1.6;
}
.prose pre code { background: none; padding: 0; font-size: inherit; color: var(--text); }
.prose blockquote { margin-left: 0; margin-right: 0; padding: .1em 0 .1em 1.25em; border-left: 3px solid var(--lavender); color: var(--subtext1); }
.prose blockquote > :last-child { margin-bottom: 0; }
.prose ul, .prose ol { padding-left: 1.4em; }
.prose li { margin: .3em 0; }
.prose li::marker { color: var(--overlay0); }
.prose ol > li::marker { font: .875em "IBM Plex Mono", monospace; color: var(--subtext0); }
.prose hr { border: 0; border-top: 1px solid var(--surface0); margin: 2.5em 0; }
.prose img { max-width: 100%; height: auto; border-radius: 8px; }
.prose table {
  display: block; overflow-x: auto; border-collapse: collapse;
  font-size: .9375rem; line-height: 1.5; max-width: 100%;
}
.prose th, .prose td { padding: .55rem .9rem; border-bottom: 1px solid var(--surface0); text-align: left; vertical-align: top; }
.prose th { font: 500 .8125rem "IBM Plex Mono", monospace; color: var(--subtext0); border-bottom-color: var(--surface1); white-space: nowrap; }
.prose tbody tr:hover { background: var(--mantle); }

/* kramdown footnotes */
.prose sup a.footnote, .prose sup[role="doc-noteref"] a {
  font: 500 .72em "IBM Plex Mono", monospace; color: var(--yellow); text-decoration: none; padding: 0 .1em;
}
.prose sup a.footnote::before { content: "["; color: var(--overlay0); }
.prose sup a.footnote::after { content: "]"; color: var(--overlay0); }
.footnotes { margin-top: 3.5rem; padding-top: 1.5rem; border-top: 1px solid var(--surface0); font-size: .9375rem; color: var(--subtext1); }
.footnotes ol { margin: 0; }
.footnotes li { margin-bottom: .75em; }
.footnotes li::marker { font-family: "IBM Plex Mono", monospace; color: var(--yellow); font-size: .85em; }
.footnotes p { margin: 0; }
.footnotes a.reversefootnote { color: var(--overlay0); text-decoration: none; margin-left: .3em; }
.footnotes a.reversefootnote:hover { color: var(--yellow); }

/* ---------- TOC ---------- */
.toc { font: .8125rem/1.5 "IBM Plex Mono", monospace; }
.toc-title { color: var(--subtext0); margin: 0 0 .75rem; letter-spacing: .06em; }
.toc ol { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--surface0); }
.toc a {
  display: block; padding: .3rem 0 .3rem .9rem; margin-left: -1px;
  color: var(--subtext0); text-decoration: none; border-left: 1px solid transparent;
}
.toc a:hover { color: var(--text); }
.toc a.active { color: var(--blue); border-left-color: var(--blue); }
.toc .depth-1 a { padding-left: 1.8rem; }
.toc .depth-2 a { padding-left: 2.7rem; }
.toc-aside[hidden], .toc-inline[hidden] { display: none; }
.toc-aside { display: none; }
@media (min-width: 1100px) {
  .toc-aside:not([hidden]) { display: block; }
  .toc-aside .toc { position: sticky; top: 2rem; max-height: calc(100vh - 4rem); overflow-y: auto; }
  .toc-inline { display: none; }
}
.toc-inline { margin-bottom: 2rem; border: 1px solid var(--surface0); border-radius: 8px; padding: .75rem 1rem; }
.toc-inline summary { cursor: pointer; font: .8125rem "IBM Plex Mono", monospace; color: var(--subtext0); }
.toc-inline .toc { margin-top: .75rem; }

/* ---------- Footer ---------- */
.site-footer { border-top: 1px solid var(--surface0); font: .8125rem/1.6 "IBM Plex Mono", monospace; color: var(--subtext0); }
.footer-inner { display: flex; flex-wrap: wrap; align-items: baseline; gap: 1rem 1.5rem; padding-top: 1.75rem; padding-bottom: 2.5rem; }
.footer-links { display: flex; flex-wrap: wrap; gap: 1.25rem; }
.footer-links a { color: var(--subtext0); text-decoration: none; }
.footer-links a:hover { color: var(--text); }
.fine { margin: 0 0 0 auto; }
@media (max-width: 640px) { .fine { margin-left: 0; } }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}
