/* ==========================================================================
   MD4C Blog — themes
   "academic" (default): journal-style serif typography.
   "modern": the plain sans-serif look.
   Both support light/dark (data-scheme) and are tuned by index.json "site".
   ========================================================================== */

:root {
  --font-serif: 'Source Serif 4 Variable', 'Iowan Old Style', 'Palatino Linotype', Palatino, Georgia, serif;
  --font-sans: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: ui-monospace, 'SF Mono', SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace;
  --font-display: var(--font-serif);

  --paper: #fbfaf6;
  --surface: #ffffff;
  --ink: #1d1d1f;
  --ink-soft: #46464b;
  --muted: #6b6a66;
  --rule: #dcd6c8;
  --rule-strong: #2a2a2d;
  --accent-base: #8b1e2d;
  --accent: var(--accent-base);
  --code-bg: #f3f0e8;
  --mark: #fbeeb0;
  --note: #2f5d8a;
  --tip: #2e6b3f;
  --warning: #8a5a00;
  --caution: #a32638;
  --hero-ink: #ffffff;

  --measure: 44rem;
  --text-size: 1.125rem;
  --leading: 1.7;
}

:root[data-theme="modern"] {
  --font-display: var(--font-sans);
  --paper: #fbfaf8;
  --ink: #1f2328;
  --ink-soft: #424a53;
  --muted: #656d76;
  --rule: #d8dee4;
  --rule-strong: #8c959f;
  --accent-base: #0b6bcb;
  --code-bg: #f3f4f6;
  --mark: #fff3a3;
  --text-size: 1.0625rem;
  --leading: 1.65;
}

@media (prefers-color-scheme: dark) {
  :root[data-scheme="auto"] {
    --paper: #141519;
    --surface: #1b1c21;
    --ink: #e8e6e0;
    --ink-soft: #c9c6be;
    --muted: #9c9991;
    --rule: #34353b;
    --rule-strong: #c9c6be;
    --accent: color-mix(in srgb, var(--accent-base) 50%, #ffffff);
    --code-bg: #212228;
    --mark: #5a4b0c;
    --note: #7fb0e0;
    --tip: #78c08c;
    --warning: #d9a640;
    --caution: #ef8a98;
  }
}
:root[data-scheme="dark"] {
  --paper: #141519;
  --surface: #1b1c21;
  --ink: #e8e6e0;
  --ink-soft: #c9c6be;
  --muted: #9c9991;
  --rule: #34353b;
  --rule-strong: #c9c6be;
  --accent: color-mix(in srgb, var(--accent-base) 50%, #ffffff);
  --code-bg: #212228;
  --mark: #5a4b0c;
  --note: #7fb0e0;
  --tip: #78c08c;
  --warning: #d9a640;
  --caution: #ef8a98;
}

/* ---------- Base ---------- */

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-serif);
  font-size: 16px;
  line-height: 1.55;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}
:root[data-font="sans"] body { font-family: var(--font-sans); }

a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: .18em; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.page { max-width: var(--measure); margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }
.error { color: var(--caution); }
.skip-link { position: absolute; left: -999px; top: 0; background: var(--surface); padding: 8px 12px; z-index: 10; }
.skip-link:focus { left: 16px; }
.sc { font-family: var(--font-sans); font-size: .74rem; letter-spacing: .14em; text-transform: uppercase; }

/* ---------- Masthead ---------- */

.masthead { border-bottom: 1px solid var(--rule); background: var(--paper); }
.masthead-inner { max-width: var(--measure); margin: 0 auto; padding: 2.75rem 16px 0; text-align: center; }
.site-title {
  display: inline-block;
  font-family: var(--font-display);
  font-size: clamp(1.9rem, 5vw, 2.6rem);
  font-weight: 600;
  font-variant-caps: small-caps;
  letter-spacing: .035em;
  line-height: 1.1;
  color: var(--ink);
  text-decoration: none;
}
.site-title:hover { color: var(--accent); }
.site-slogan { margin: .55rem 0 0; font-style: italic; font-size: 1.12rem; color: var(--ink-soft); }
#nav {
  display: flex; flex-wrap: wrap; justify-content: center; gap: .25rem 1.75rem;
  margin-top: 1.6rem; padding: .7rem 0;
  border-top: 1px solid var(--rule);
  font-family: var(--font-sans); font-size: .74rem; letter-spacing: .14em; text-transform: uppercase;
}
#nav a { color: var(--ink-soft); text-decoration: none; }
#nav a:hover { color: var(--accent); }

:root[data-theme="modern"] .masthead-inner {
  display: grid; grid-template-columns: 1fr auto; align-items: center;
  gap: .25rem 1rem; padding: 1rem 16px; text-align: left;
}
:root[data-theme="modern"] .site-title { font-size: 1.3rem; font-variant-caps: normal; letter-spacing: 0; font-weight: 700; }
:root[data-theme="modern"] .site-slogan { grid-row: 2; margin: 0; font-style: normal; font-size: .95rem; font-family: var(--font-sans); color: var(--muted); }
:root[data-theme="modern"] #nav {
  grid-row: 1 / span 2; grid-column: 2; margin: 0; padding: 0; border: 0;
  text-transform: none; letter-spacing: 0; font-size: .95rem; gap: 1rem;
}

/* Background image, as a masthead banner ... */
:root[data-bg="hero"] .masthead {
  background: linear-gradient(rgba(10, 10, 14, .45), rgba(10, 10, 14, .62)), var(--bg-image) center / cover no-repeat;
  border-bottom: 0;
}
:root[data-bg="hero"] .masthead-inner { padding-top: 5rem; }
:root[data-bg="hero"] .site-title,
:root[data-bg="hero"] .site-slogan,
:root[data-bg="hero"] #nav a { color: var(--hero-ink); }
:root[data-bg="hero"] #nav { border-top-color: rgba(255, 255, 255, .35); }
:root[data-theme="modern"][data-bg="hero"] .masthead-inner { padding-top: 3.5rem; padding-bottom: 1.25rem; }

/* ... or behind the whole page, with the text on a paper card. */
:root[data-bg="page"] body { background: var(--paper) var(--bg-image) center / cover no-repeat fixed; }
:root[data-bg="page"] .masthead { background: color-mix(in srgb, var(--paper) 88%, transparent); }
:root[data-bg="page"] main.page {
  background: var(--paper);
  margin-top: 2rem; margin-bottom: 2rem;
  padding: 2rem clamp(16px, 4vw, 3rem);
  border: 1px solid var(--rule);
  border-radius: 4px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .12);
}

main.page { padding-top: 2.5rem; padding-bottom: 4rem; min-height: 55vh; }
main.page:focus { outline: none; }

/* ---------- Article list ---------- */

.section-label {
  display: flex; align-items: center; gap: .9rem;
  margin: 0 0 .5rem; color: var(--muted);
}
.section-label::after { content: ""; flex: 1; border-top: 1px solid var(--rule); }
.section-label a { color: inherit; }

.entries { list-style: none; margin: 0; padding: 0; }
.entry {
  display: grid; grid-template-columns: 7.25rem 1fr; gap: 0 1.5rem;
  padding: 1.5rem 0; border-bottom: 1px solid var(--rule);
}
.entry time { color: var(--muted); padding-top: .45rem; font-variant-numeric: tabular-nums; }
.entry h2 {
  margin: 0; font-family: var(--font-display);
  font-size: 1.4rem; font-weight: 600; line-height: 1.28; text-wrap: balance;
}
.entry h2 a { color: var(--ink); text-decoration: none; }
.entry h2 a:hover { color: var(--accent); }
.entry .abstract { margin: .45rem 0 .55rem; color: var(--ink-soft); font-size: 1.02rem; line-height: 1.6; hyphens: auto; }
.keywords { color: var(--muted); }
.keywords a { color: var(--muted); text-decoration: none; }
.keywords a:hover { color: var(--accent); }
.keywords a + a::before { content: "·"; margin: 0 .5em; color: var(--rule); }

/* ---------- Article ---------- */

.back-link { display: inline-block; margin-bottom: 1.5rem; color: var(--muted); text-decoration: none; }
.back-link:hover { color: var(--accent); }

.article-header { text-align: center; margin: 0 0 2.25rem; padding-bottom: 1.75rem; border-bottom: 1px solid var(--rule); }
.article-title {
  margin: 0; font-family: var(--font-display);
  font-size: clamp(1.85rem, 4.6vw, 2.5rem); font-weight: 600;
  line-height: 1.18; letter-spacing: -.01em; text-wrap: balance;
}
.byline { margin: 1rem 0 0; color: var(--muted); }
.byline .author { color: var(--ink); }
.article-header .keywords { margin: .6rem 0 0; }
:root[data-theme="modern"] .article-header { text-align: left; }

.article-header:has(+ .toc) { border-bottom: 0; padding-bottom: .5rem; }
.toc {
  margin: 0 0 2.5rem; padding: 1rem 0 1.1rem;
  border-top: 1px solid var(--rule-strong); border-bottom: 1px solid var(--rule);
}
.toc h2 { margin: 0 0 .5rem; color: var(--muted); font-weight: 400; }
.toc ol { margin: 0; padding-left: 0; list-style: none; counter-reset: toc; }
.toc ol ol { padding-left: 1.6rem; counter-reset: toc-sub; }
.toc li { margin: .2rem 0; }
.toc a { color: var(--ink-soft); text-decoration: none; }
.toc a:hover { color: var(--accent); text-decoration: underline; }
:root[data-numbered="true"] .toc > ol > li { counter-increment: toc; }
:root[data-numbered="true"] .toc > ol > li > a::before { content: counter(toc) "\2002"; color: var(--muted); font-variant-numeric: tabular-nums; }
:root[data-numbered="true"] .toc ol ol > li { counter-increment: toc-sub; }
:root[data-numbered="true"] .toc ol ol > li > a::before { content: counter(toc) "." counter(toc-sub) "\2002"; color: var(--muted); }

/* ---------- Prose (rendered Markdown) ---------- */

.prose {
  font-size: var(--text-size);
  line-height: var(--leading);
  overflow-wrap: break-word;
  hyphens: auto;
  counter-reset: h2 figure table;
}
.prose p { margin: 0 0 1.15em; }
.prose > :first-child { margin-top: 0; }

.prose h1, .prose h2, .prose h3, .prose h4 {
  font-family: var(--font-display); color: var(--ink);
  line-height: 1.3; hyphens: manual; text-wrap: balance;
  scroll-margin-top: 1.5rem;
}
.prose h1 { font-size: 1.6rem; font-weight: 600; margin: 2.2em 0 .7em; }
.prose h2 { font-size: 1.42rem; font-weight: 600; margin: 2.3em 0 .7em; counter-reset: h3; }
.prose h3 { font-size: 1.16rem; font-weight: 600; margin: 1.9em 0 .55em; }
.prose h4 { font-size: 1rem; font-weight: 600; font-style: italic; margin: 1.6em 0 .4em; }
:root[data-numbered="true"] .prose h2 { counter-increment: h2; }
:root[data-numbered="true"] .prose h2::before { content: counter(h2) "\2003"; color: var(--muted); font-weight: 400; }
:root[data-numbered="true"] .prose h3 { counter-increment: h3; }
:root[data-numbered="true"] .prose h3::before { content: counter(h2) "." counter(h3) "\2003"; color: var(--muted); font-weight: 400; }
/* Posts that number their own headings ("## 2. Method") keep their numbers. */
:root[data-numbered="true"] .manual-numbers h2::before,
:root[data-numbered="true"] .manual-numbers h3::before,
:root[data-numbered="true"] .toc.manual-numbers a::before { content: none; }

.prose ul, .prose ol { padding-left: 1.6em; margin: 0 0 1.15em; }
.prose li { margin: .25em 0; }
.prose li > p { margin: 0 0 .5em; }
.prose li.task-list-item { list-style: none; }
.prose li.task-list-item input { margin: 0 .5em 0 -1.5em; accent-color: var(--accent); }

.prose blockquote {
  margin: 1.6em 0; padding: .1em 0 .1em 1.4em;
  border-left: 2px solid var(--rule);
  color: var(--ink-soft); font-size: .97em;
}

.prose code { font-family: var(--font-mono); font-size: .84em; background: var(--code-bg); padding: .12em .32em; border-radius: 3px; hyphens: none; }
.prose pre {
  font-size: .82rem; line-height: 1.6;
  background: var(--code-bg); border: 1px solid var(--rule); border-radius: 4px;
  padding: .95rem 1.1rem; overflow-x: auto; margin: 1.6em 0; hyphens: none;
}
.prose pre code { background: none; padding: 0; font-size: inherit; }

.prose mark { background: var(--mark); color: inherit; padding: 0 .1em; }
.prose hr { border: 0; margin: 2.5em 0; text-align: center; color: var(--muted); }
.prose hr::after { content: "\2042"; font-size: 1.2rem; }
.prose img, .prose video { max-width: 100%; height: auto; }

/* Figures: a paragraph holding only an image becomes a numbered figure. */
.prose figure { margin: 2.2em 0; text-align: center; counter-increment: figure; }
.prose figure img { display: block; margin: 0 auto; border-radius: 2px; }
.prose figcaption { margin: .75em auto 0; max-width: 36rem; font-family: var(--font-sans); font-size: .84rem; line-height: 1.5; color: var(--muted); }
.prose figcaption::before { content: "Figure " counter(figure) ". "; font-weight: 600; color: var(--ink-soft); }

/* Tables: booktabs style — rules above, below and under the header only. */
.prose .table-wrap { overflow-x: auto; margin: 2em 0; counter-increment: table; }
.prose table {
  border-collapse: collapse; margin: 0 auto;
  border-top: 2px solid var(--rule-strong); border-bottom: 2px solid var(--rule-strong);
  font-size: .93em; line-height: 1.45; font-variant-numeric: lining-nums tabular-nums; hyphens: none;
}
.prose th { border-bottom: 1px solid var(--rule-strong); font-weight: 600; }
.prose th, .prose td { padding: .5em .95em; vertical-align: top; }
.prose tbody tr + tr td { border-top: 1px solid color-mix(in srgb, var(--rule) 55%, transparent); }

/* Footnotes */
.prose .footnotes { margin-top: 3em; padding-top: 1.1em; border-top: 1px solid var(--rule); font-size: .88em; color: var(--ink-soft); }
.prose .footnotes::before { content: "Notes"; display: block; margin-bottom: .6em; font-family: var(--font-sans); font-size: .74rem; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.prose .footnotes ol { padding-left: 1.4em; }
.prose sup a { text-decoration: none; font-weight: 600; padding: 0 .1em; }
.prose .footnote-backref { text-decoration: none; margin-left: .3em; }

/* Admonitions */
.prose [class^="admonition-"]:not(.admonition-title) {
  margin: 1.8em 0; padding: .85em 1.15em .2em;
  background: var(--surface); border: 1px solid var(--rule); border-left: 3px solid var(--adm, var(--note)); border-radius: 0 4px 4px 0;
  font-size: .97em;
}
.prose .admonition-tip { --adm: var(--tip); }
.prose .admonition-warning, .prose .admonition-important { --adm: var(--warning); }
.prose .admonition-caution { --adm: var(--caution); }
.prose .admonition-title { margin: 0 0 .45em; font-family: var(--font-sans); font-size: .72rem; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: var(--adm, var(--note)); }

/* Math */
.prose x-equation { font-family: var(--font-serif); font-style: italic; }
.prose x-equation[type="display"], .prose .katex-display { display: block; margin: 1.4em 0; overflow-x: auto; overflow-y: hidden; text-align: center; }
.prose .katex { font-size: 1.06em; }

/* ---------- Citation ---------- */

.cite {
  margin-top: 3.5rem; padding: 1.2rem 1.3rem;
  background: var(--surface); border: 1px solid var(--rule); border-radius: 4px;
  font-family: var(--font-sans); font-size: .86rem; line-height: 1.55; color: var(--ink-soft);
}
.cite h2 { margin: 0 0 .5rem; color: var(--muted); font-weight: 400; }
.cite p { margin: 0; font-family: var(--font-serif); font-size: 1rem; color: var(--ink); overflow-wrap: anywhere; }
.cite details { margin-top: .8rem; }
.cite summary { cursor: pointer; color: var(--muted); }
.cite pre { margin: .6rem 0 0; padding: .8rem 1rem; background: var(--code-bg); border-radius: 3px; overflow-x: auto; font-family: var(--font-mono); font-size: .78rem; }

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

.site-footer { border-top: 1px solid var(--rule); padding: 1.75rem 0 2.5rem; text-align: center; font-family: var(--font-sans); font-size: .8rem; color: var(--muted); }
.site-footer p { margin: .25rem 0; }
.footer-note:empty { display: none; }
:root[data-bg="page"] .site-footer { background: color-mix(in srgb, var(--paper) 88%, transparent); }

/* ---------- Small screens ---------- */

@media (max-width: 640px) {
  .entry { grid-template-columns: 1fr; }
  .entry time { padding-top: 0; margin-bottom: .3rem; }
  .masthead-inner { padding-top: 2rem; }
  :root[data-bg="hero"] .masthead-inner { padding-top: 3.5rem; }
  :root[data-theme="modern"] .masthead-inner { grid-template-columns: 1fr; }
  :root[data-theme="modern"] #nav { grid-row: auto; grid-column: 1; }
  .prose { --text-size: 1.0625rem; }
}

/* ---------- Print ---------- */

@media print {
  :root { --paper: #fff; --ink: #000; --ink-soft: #222; --muted: #555; --rule: #999; --rule-strong: #000; --accent: #000; --code-bg: #f4f4f4; }
  body { background: #fff !important; font-size: 11pt; }
  .masthead { background: none !important; border-bottom: 1px solid #999; }
  .site-title, .site-slogan { color: #000 !important; }
  #nav, .back-link, .skip-link, .colophon, .cite details { display: none; }
  main.page { box-shadow: none !important; border: 0 !important; padding: 0 !important; margin: 0 auto !important; max-width: none; }
  .prose { font-size: 11pt; line-height: 1.5; }
  .prose a { color: inherit; text-decoration: none; }
  .prose a[href^="http"]::after { content: " <" attr(href) ">"; font-size: .8em; color: #555; word-break: break-all; }
  .prose h2, .prose h3 { break-after: avoid; }
  .prose figure, .prose pre, .prose table, .cite { break-inside: avoid; }
}

/* ---------- Home: filters and archive ---------- */

.filters { margin: 0 0 1.25rem; font-family: var(--font-sans); }
.filter-row { display: flex; gap: .6rem; }
.filters input[type="search"], .filters select {
  font: inherit; font-size: .92rem; color: var(--ink);
  background: var(--surface); border: 1px solid var(--rule); border-radius: 4px;
  padding: .5rem .7rem;
}
.filters input[type="search"] { flex: 1; min-width: 0; }
.filters input:focus-visible, .filters select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.tag-chips { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .8rem; }
.tag-chip {
  font-family: var(--font-sans); font-size: .7rem; cursor: pointer;
  color: var(--ink-soft); background: transparent;
  border: 1px solid var(--rule); border-radius: 999px; padding: .3rem .7rem;
}
.tag-chip .count { color: var(--muted); margin-left: .2em; letter-spacing: 0; }
.tag-chip:hover { border-color: var(--accent); color: var(--accent); }
.tag-chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--paper); }
.tag-chip[aria-pressed="true"] .count { color: inherit; opacity: .8; }
.filter-status { margin: .9rem 0 0; color: var(--muted); }
.filter-status a { color: var(--accent); }

.year-heading {
  margin: 2rem 0 0; padding-bottom: .4rem; border-bottom: 1px solid var(--rule-strong);
  color: var(--ink-soft); font-weight: 600;
}
.year-group:first-child .year-heading { margin-top: .75rem; }
.empty { margin-top: 1.5rem; }

@media (max-width: 640px) {
  .filter-row { flex-direction: column; }
}
@media print {
  #filters { display: none; }
}
