/* ─── Tokens ──────────────────────────────────────────────────────────────── */
:root {
  --font-sans: "Inter", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", "Fira Code", ui-monospace, monospace;
  --max-width: 52rem;
  --gap: 1.5rem;
}

/* ─── Reset ───────────────────────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ─── Base ────────────────────────────────────────────────────────────────── */
html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 1.0625rem;
  line-height: 1.75;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* ─── Centered column — zoom-safe via margin-inline: auto ─────────────────── */
header,
main,
footer {
  width: 100%;
  max-width: var(--max-width);
  margin-inline: auto;
  padding-inline: var(--gap);
}

main {
  flex: 1;
}

/* ─── Document header ────────────────────────────────────────────────────────*/
header {
  padding-top: 3.5rem;
  padding-bottom: 2rem;
  border-bottom: 2px solid var(--text);
}

.doc-title {
  font-size: clamp(2rem, 5.5vw, 3rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.05;
  margin-bottom: 0.625rem;
}

.doc-subtitle {
  font-size: 1rem;
  font-weight: 400;
  color: var(--text-muted);
  margin-bottom: 0;
}

.header-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.5rem;
  margin-top: 1.25rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.author a {
  color: var(--text-muted);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.author a:hover {
  color: var(--text);
}

.keywords {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  margin-top: 1rem;
}

.keyword {
  background: var(--bg-subtle);
  border-radius: 9999px;
  padding: 0.25rem 0.625rem;
  font-size: 0.6875rem;
  font-weight: 500;
  color: var(--text-muted);
}

/* ─── Tags (frontmatter `tags:` → accent pills) ──────────────────────────── */
.meta-status {
  color: var(--accent);
  font-weight: 600;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 1rem;
}

.tag {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  color: var(--accent);
  border-radius: 9999px;
  padding: 0.2rem 0.7rem;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  transition: background 0.15s ease;
}
.tag:hover {
  background: color-mix(in srgb, var(--accent) 18%, transparent);
}

/* ─── Main ───────────────────────────────────────────────────────────────────*/
main {
  padding-top: 2.5rem;
  padding-bottom: 4rem;
}

/* ─── TOC ────────────────────────────────────────────────────────────────────*/
#toc {
  padding-top: 1rem;
  margin-bottom: 2.5rem;
  border-top: 1px solid var(--border);
  font-size: 0.8125rem;
}

#toc h2 {
  font-size: 0.625rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 0 0 0.75rem;
  border: none;
  padding: 0;
}

#toc ul {
  list-style: none;
  padding-left: 0;
}
#toc ul ul {
  padding-left: 1.25rem;
}
#toc li {
  margin-bottom: 0.2rem;
  line-height: 1.4;
}
#toc a {
  color: var(--text-muted);
  text-decoration: none;
}
#toc a:hover {
  color: var(--text);
}

/* ─── Headings ───────────────────────────────────────────────────────────────*/
h1,
h2,
h3,
h4,
h5,
h6 {
  font-weight: 700;
  line-height: 1.2;
  color: var(--text);
}

h1 {
  font-size: 1.875rem;
  letter-spacing: -0.025em;
  margin: 2.5rem 0 0.875rem;
}
h2 {
  font-size: 1.375rem;
  letter-spacing: -0.015em;
  margin: 2.5rem 0 0.75rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.375rem;
}
h3 {
  font-size: 1.125rem;
  letter-spacing: -0.01em;
  margin: 2rem 0 0.5rem;
}
h4 {
  font-size: 0.8125rem;
  letter-spacing: 0.07em;
  margin: 1.75rem 0 0.375rem;
  text-transform: uppercase;
}
h5,
h6 {
  font-size: 0.75rem;
  letter-spacing: 0.07em;
  margin: 1.5rem 0 0.25rem;
  font-weight: 500;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* ─── Prose ──────────────────────────────────────────────────────────────────*/
p {
  margin-bottom: 1.125rem;
}

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

strong {
  font-weight: 700;
}
em {
  font-style: italic;
}

ul,
ol {
  padding-left: 1.5rem;
  margin-bottom: 1.125rem;
}
li {
  margin-bottom: 0.25rem;
  line-height: 1.65;
}
li > ul,
li > ol {
  margin-top: 0.25rem;
  margin-bottom: 0;
}

blockquote {
  border-left: 2px solid var(--accent);
  padding: 0 1.25rem;
  margin: 1.75rem 0;
  color: var(--text-muted);
  font-style: italic;
}
blockquote p {
  margin-bottom: 0;
}

/* ─── Code ───────────────────────────────────────────────────────────────────*/
code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--code-bg);
  padding: 0.1em 0.35em;
  border-radius: 2px;
}

pre {
  background: var(--code-bg);
  border-left: 2px solid var(--border);
  padding: 1rem 1.25rem;
  overflow-x: auto;
  margin-bottom: 1.5rem;
  line-height: 1.5;
}

pre code,
pre code.hljs {
  background: none;
  padding: 0;
  font-size: 0.8125rem;
  border-radius: 0;
}

/* ─── Tables ─────────────────────────────────────────────────────────────────*/
table {
  border-collapse: collapse;
  display: block;
  overflow-x: auto;
  width: 100%;
  margin: 1.5rem 0;
  font-size: 0.9375rem;
}

th,
td {
  border: 1px solid var(--border);
  padding: 0.5rem 0.875rem;
  text-align: left;
}
th {
  background: var(--bg-subtle);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
tr:nth-child(even) td {
  background: var(--bg-subtle);
}

/* ─── Misc ───────────────────────────────────────────────────────────────────*/
img {
  display: block;
  width: 100%;
  height: auto;
}
video {
  max-width: 100%;
  height: auto;
}
figure {
  margin: 2rem 0;
}
figcaption {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
}
hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 3rem 0;
}

/* ─── Mermaid ────────────────────────────────────────────────────────────────*/
.mermaid {
  display: flex;
  justify-content: center;
  margin: 2rem 0;
  overflow-x: auto;
}
.mermaid svg {
  max-width: 100%;
  height: auto;
}

/* ─── References ─────────────────────────────────────────────────────────────*/
#refs {
  font-size: 0.9rem;
}
#refs .csl-entry {
  margin-bottom: 0.875rem;
  padding-left: 1.5rem;
  text-indent: -1.5rem;
}

/* ─── Footer ─────────────────────────────────────────────────────────────────*/
footer {
  border-top: 1px solid var(--border);
  padding-top: 1.25rem;
  padding-bottom: 2rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
}

footer a {
  color: var(--text-muted);
}
footer a:hover {
  color: var(--text);
}

/* ─── Print ──────────────────────────────────────────────────────────────────*/
@media print {
  @page {
    margin: 2cm;
  }

  pre button {
    display: none;
  }

  h1,
  h2,
  h3,
  h4,
  h5,
  h6 {
    break-after: avoid;
  }

  pre,
  table,
  figure,
  blockquote,
  img {
    break-inside: avoid;
  }

  pre,
  pre code {
    white-space: pre-wrap;
    word-break: break-word;
  }

  table {
    overflow-x: visible;
  }
}

/* ─── Responsive ─────────────────────────────────────────────────────────────*/
@media (max-width: 640px) {
  :root {
    --gap: 1rem;
  }
  .doc-title {
    font-size: 1.875rem;
  }
}
