/* One stylesheet for every site and page. A site can add its own in <site>/static/site.css. */

:root {
  --bg: #fefefc;
  --bg-soft: #f5f4ef;
  --ink: #1f1d1a;
  --ink-soft: #57524a;
  --ink-faint: #8a8478;
  --rule: #e3ded3;
  --accent: #2f5d8a;
  --accent-soft: #e4ecf4;
  --draft: #b0471f;
  --code-bg: #f5f4ef;
  --hl-keyword: #8b3a62;
  --hl-string: #4a7a3a;
  --hl-number: #a8591d;
  --hl-title: #2f5d8a;
  --hl-attr: #6b4f9a;
  --img-dim: 1;
  color-scheme: light;

  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --text: 680px;   /* reading column */
  --page: 1000px;  /* wide figures */
  --gutter: 16px;
}

/* Dark colours: when the toggle says dark, or the device prefers dark and the toggle hasn't said light. */
:root[data-theme="dark"] {
  --bg: #171614;
  --bg-soft: #22201d;
  --ink: #ece8e1;
  --ink-soft: #b9b2a6;
  --ink-faint: #8a8478;
  --rule: #34312c;
  --accent: #8fb6dd;
  --accent-soft: #1f2a35;
  --draft: #e98a62;
  --code-bg: #22201d;
  --hl-keyword: #e28fb6;
  --hl-string: #9fcf86;
  --hl-number: #f0a96b;
  --hl-title: #8fb6dd;
  --hl-attr: #c0a8ec;
  --img-dim: .92;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #171614;
    --bg-soft: #22201d;
    --ink: #ece8e1;
    --ink-soft: #b9b2a6;
    --ink-faint: #8a8478;
    --rule: #34312c;
    --accent: #8fb6dd;
    --accent-soft: #1f2a35;
    --draft: #e98a62;
    --code-bg: #22201d;
    --hl-keyword: #e28fb6;
    --hl-string: #9fcf86;
    --hl-number: #f0a96b;
    --hl-title: #8fb6dd;
    --hl-attr: #c0a8ec;
    --img-dim: .92;
    color-scheme: dark;
  }
}
.body img:not([src$=".svg"]) { opacity: var(--img-dim); }

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.65 var(--serif);
  overflow-x: clip;
}
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
img, svg, video { max-width: 100%; height: auto; }

/* ---------------------------------------------------------------- masthead */

.masthead {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  max-width: var(--page); margin: 0 auto; padding: 14px var(--gutter);
  font: 500 14px/1.2 var(--sans);
}
.masthead a { color: var(--ink); text-decoration: none; }
.masthead .brand { font-weight: 700; letter-spacing: .02em; text-transform: uppercase; font-size: 13px; }
.masthead nav { display: flex; gap: 18px; }
.masthead nav a { color: var(--ink-soft); }
.masthead nav a:hover { color: var(--ink); }
.page-home .masthead .brand { visibility: hidden; }  /* the banner below shows the name */
.masthead nav { align-items: center; }
.theme-toggle {
  display: inline-grid; place-items: center; width: 30px; height: 30px; margin: -6px -6px -6px 0; padding: 0;
  border: 0; border-radius: 50%; background: none; color: var(--ink-soft); cursor: pointer;
}
.theme-toggle:hover { color: var(--ink); background: var(--bg-soft); }
.theme-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.theme-toggle svg { width: 18px; height: 18px; }
/* shows the theme a click switches to; hidden until the page script has set data-theme */
:root:not([data-theme]) .theme-toggle, .theme-toggle .sun, :root[data-theme="dark"] .theme-toggle .moon { display: none; }
:root[data-theme="dark"] .theme-toggle .sun { display: block; }

.colophon {
  max-width: var(--page); margin: 80px auto 0; padding: 24px var(--gutter) 40px;
  border-top: 1px solid var(--rule);
  font: 13px/1.5 var(--sans); color: var(--ink-faint);
}
.colophon a { color: inherit; }
.colophon .cc { display: inline-block; vertical-align: middle; margin-right: .5rem; line-height: 0; }
.colophon .cc-icon { width: auto; height: 1.4em; }

.badge-draft {
  display: inline-block; vertical-align: middle;
  margin: 0 0 0 10px; padding: 2px 8px; border: 1px solid currentColor; border-radius: 3px;
  font: 700 11px/1.4 var(--sans); letter-spacing: .08em; text-transform: uppercase; color: var(--draft);
}
.hero .badge-draft { margin: 0 0 14px; }

/* ---------------------------------------------------------------- index pages */

.banner { border-bottom: 1px solid var(--rule); background: linear-gradient(180deg, var(--bg-soft), var(--bg)); }
.banner-inner { max-width: var(--page); margin: 0 auto; padding: 72px var(--gutter) 48px; }
.banner h1 { margin: 0; font: 700 clamp(36px, 7vw, 60px)/1.05 var(--sans); letter-spacing: -.025em; }
.banner p { margin: 14px 0 0; max-width: 560px; font-size: 19px; color: var(--ink-soft); }
.banner.small .banner-inner { padding: 40px var(--gutter) 28px; }
.banner.small h1 { font-size: clamp(30px, 5vw, 42px); }
.crumbs { font: 14px var(--sans) !important; margin: 0 0 8px !important; }
.crumbs a { color: var(--ink-faint); }

.listing { max-width: var(--page); margin: 0 auto; padding: 8px var(--gutter); }
.group-head {
  margin: 48px 0 0; padding-bottom: 8px; border-bottom: 1px solid var(--ink);
  font: 700 14px/1 var(--sans); letter-spacing: .08em; text-transform: uppercase;
}
.group-head a { color: var(--ink); text-decoration: none; }
.entries { list-style: none; margin: 0; padding: 0; }
.entry {
  display: grid; grid-template-columns: 96px minmax(0, 1fr) auto; gap: 8px 24px; align-items: start;
  padding: 26px 0; border-bottom: 1px solid var(--rule);
}
.entry time { padding-top: 6px; font: 500 13px/1.3 var(--sans); color: var(--ink-faint); text-transform: uppercase; letter-spacing: .04em; }
.entry h2 { margin: 0; font: 650 23px/1.25 var(--sans); letter-spacing: -.01em; }
.entry h2 a { color: var(--ink); text-decoration: none; }
.entry h2 a:hover { color: var(--accent); }
.entry-authors { margin: 6px 0 0; font: 14px/1.4 var(--sans); color: var(--ink-soft); }
.entry-desc { margin: 8px 0 0; color: var(--ink-soft); max-width: 600px; }
.entry-thumb img {
  display: block; width: 200px; aspect-ratio: 16 / 10; object-fit: cover;
  border: 1px solid var(--rule); border-radius: 4px; background: var(--bg-soft);
}
/* two to four featured images: a small grid, the first across the top when there are three */
.entry-thumb.multi { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; width: 200px; }
.entry-thumb.multi img { width: 100%; aspect-ratio: 1; }
.entry-thumb.multi img:first-child:nth-last-child(3) { grid-column: span 2; aspect-ratio: 2 / 1; }
.empty { color: var(--ink-faint); padding: 40px 0; }
.entry-tags { margin: 10px 0 0; display: flex; flex-wrap: wrap; gap: 6px; font: 12px/1.3 var(--sans); }
.entry-tags a { padding: 2px 8px; border-radius: 10px; color: var(--ink-soft); background: var(--bg-soft); border: 1px solid var(--rule); text-decoration: none; }
.entry-tags a:hover { color: var(--accent); border-color: var(--accent); }
.entry-tags .tag-series { color: var(--accent); background: var(--accent-soft); border-color: transparent; }

/* the front page's order, theme, and series controls (src/listing.civet) */
.controls {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 20px;
  max-width: var(--page); margin: 0 auto; padding: 18px var(--gutter) 0;
  font: 13px/1.3 var(--sans); color: var(--ink-faint);
}
.controls[hidden], .series-desc[hidden] { display: none; }
.controls label { display: flex; align-items: center; gap: 8px; text-transform: uppercase; letter-spacing: .06em; font-size: 11px; font-weight: 600; }
.controls select, .controls button {
  font: 14px/1.3 var(--sans); color: var(--ink); background: var(--bg); text-transform: none; letter-spacing: 0;
  border: 1px solid var(--rule); border-radius: 6px; padding: 5px 8px; max-width: 70vw;
}
.controls button { cursor: pointer; }
.controls button::after { content: " ⇅"; color: var(--ink-faint); }
.controls select:focus-visible, .controls button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.series-desc { max-width: var(--page); margin: 14px auto 0; padding: 0 var(--gutter); color: var(--ink-soft); }

@media (max-width: 720px) {
  .entry { grid-template-columns: minmax(0, 1fr); gap: 4px; }
  .entry time { padding: 0; }
  .entry-thumb { order: -1; margin-bottom: 8px; }
  .entry-thumb img, .entry-thumb.multi { width: 100%; }
}

/* ---------------------------------------------------------------- splash: a title centred on the screen */

.page-splash .masthead, .page-bare .masthead { position: absolute; z-index: 10; inset: 0 0 auto; max-width: none; justify-content: flex-end; }
.page-bare .masthead { justify-content: flex-start; }
.page-bare .masthead nav { margin-left: auto; }
.page-splash .brand, .page-splash .colophon, .page-bare .colophon { display: none; }
.splash { display: grid; place-items: center; min-height: 100vh; min-height: 100svh; padding: 72px var(--gutter); text-align: center; }
.splash h1 { margin: 0; font: 800 clamp(72px, 26vw, 220px)/.95 var(--sans); letter-spacing: -.04em; }
.splash .lede { margin: 20px auto 0; }
.splash .body { max-width: var(--text); margin: 32px auto 0; text-align: left; }

/* ---------------------------------------------------------------- article */

.hero { border-bottom: 1px solid var(--rule); background: linear-gradient(180deg, var(--bg-soft), var(--bg)); }
.hero-inner { max-width: var(--page); margin: 0 auto; padding: 64px var(--gutter) 40px; }
.hero h1 { margin: 0; max-width: 860px; font: 700 clamp(34px, 6vw, 54px)/1.08 var(--sans); letter-spacing: -.025em; }
.lede { margin: 18px 0 0; max-width: 720px; font-size: 21px; line-height: 1.5; color: var(--ink-soft); }

.byline {
  display: flex; flex-wrap: wrap; gap: 16px 48px;
  max-width: var(--page); margin: 0 auto; padding: 20px var(--gutter);
  border-bottom: 1px solid var(--rule);
  font: 14px/1.5 var(--sans);
}
.byline h3 { margin: 0 0 4px; font: 600 11px/1.4 var(--sans); letter-spacing: .08em; text-transform: uppercase; color: var(--ink-faint); }
.byline ul { list-style: none; margin: 0; padding: 0; }
.byline p { margin: 0; }
.byline a { color: var(--ink); }

.article-layout {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, var(--text)) minmax(0, 1fr);
  padding: 40px var(--gutter) 0;
}
.article-layout > .body { grid-column: 2; }
.article-layout > .toc { grid-column: 2; grid-row: 1; margin-bottom: 32px; }
.article-layout > .toc + .body { grid-row: 2; }

.toc { font: 14px/1.45 var(--sans); }
.toc h3 { display: flex; align-items: center; justify-content: space-between; margin: 0 0 8px; font: 600 11px/1.4 var(--sans); letter-spacing: .08em; text-transform: uppercase; color: var(--ink-faint); }
.toc-toggle { display: none; width: 24px; height: 24px; margin: -4px -6px -4px 8px; padding: 0; border: 0; border-radius: 4px; background: none; color: var(--ink-faint); cursor: pointer; }
.toc-toggle:hover { color: var(--ink); background: var(--bg-soft); }
.toc-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.toc-toggle svg { display: block; width: 16px; height: 16px; margin: auto; transition: transform .15s; }
.toc.folded .toc-toggle svg { transform: rotate(-90deg); }
.toc ol { margin: 0; padding: 0 0 0 1.4em; color: var(--ink-faint); }
.toc li { margin: 3px 0; }
.toc ol.numbered { list-style: none; padding-left: 0; }  /* the sections carry their own numbers */
.toc a { color: var(--ink-soft); text-decoration: none; }
.toc a:hover { color: var(--accent); }

@media (min-width: 1240px) {
  .article-layout > .toc {
    grid-column: 1; grid-row: 1 / span 2; justify-self: end;
    position: sticky; top: 24px; align-self: start;
    width: 200px; margin: 6px 48px 0 0;
  }
  .article-layout > .toc + .body { grid-row: 1; }

  /* once the article scrolls under it (src/toc.civet): at the left edge of the window, above wide
     figures, scrolling within itself when taller than the window, and foldable */
  .article-layout > .toc.stuck {
    position: fixed; z-index: 5; top: 16px; left: 10px; width: 220px; margin: 0;
    max-height: calc(100vh - 32px); overflow-y: auto; overscroll-behavior: contain;
    padding: 10px 12px; border: 1px solid var(--rule); border-radius: 6px; background: var(--bg);
  }
  .toc.stuck .toc-toggle { display: block; }
  .toc.stuck.folded { width: auto; }
  .toc.stuck.folded h3 { margin: 0; gap: 4px; }
  .toc.stuck.folded ol { display: none; }
}

.body > :first-child { margin-top: 0; }
.body p, .body ul, .body ol, .body blockquote, .body table, .body pre, .body figure { margin: 0 0 1.2em; }
.body li { margin: .3em 0; }
/* In-text headings are lighter than the title: a semibold weight, slightly smaller, with room to breathe. */
.body h2, .body h3, .body h4 { position: relative; font-family: var(--sans); letter-spacing: 0; line-height: 1.3; }
.body h2 { margin: 2.2em 0 .7em; font-size: 24px; font-weight: 600; }
.body h3 { margin: 1.8em 0 .5em; font-size: 19px; font-weight: 600; }
.body h4 { margin: 1.5em 0 .4em; font-size: 17px; font-weight: 600; }
.anchor {
  position: absolute; left: -1em; width: 1em; color: var(--ink-faint); text-decoration: none; opacity: 0;
}
.body h2:hover .anchor, .body h3:hover .anchor, .body h4:hover .anchor, .anchor:focus { opacity: 1; }
@media (max-width: 760px) { .anchor { display: none; } }

.body hr { border: 0; border-top: 1px solid var(--rule); margin: 2.5em 0; }
.body blockquote {
  padding: 0 0 0 1.1em; border-left: 3px solid var(--rule); color: var(--ink-soft); font-style: italic;
}

.body code { font: .86em/1.4 var(--mono); background: var(--code-bg); padding: .1em .3em; border-radius: 3px; }
.body pre {
  overflow-x: auto; padding: 14px 16px; border-radius: 4px; background: var(--code-bg);
  font: 13.5px/1.55 var(--mono);
}
.body pre code { font: inherit; background: none; padding: 0; }

.body table { border-collapse: collapse; width: 100%; font: 14px/1.4 var(--sans); display: block; overflow-x: auto; }
.body th, .body td { padding: 6px 12px; border-bottom: 1px solid var(--rule); }
.body th { border-bottom-color: var(--ink); font-weight: 600; text-align: left; }

.body figure img, .body figure svg, .body figure video { display: block; margin: 0 auto; }
.body figcaption { margin-top: 10px; font: 14px/1.5 var(--sans); color: var(--ink-soft); }
.body figcaption strong, .body figcaption b { color: var(--ink); }

/* <figure class="pair">: two images side by side, one caption under both */
.body figure.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: center; }
.body figure.pair figcaption { grid-column: 1 / -1; }
@media (max-width: 600px) { .body figure.pair { grid-template-columns: 1fr; } }

/* Break out of the text column: class="wide" (page width) or class="full" (window width). */
.body .wide, .body .full { position: relative; left: 50%; transform: translateX(-50%); }
.body .wide { width: min(var(--page), 100vw - 2 * var(--gutter)); }
.body .full { width: 100vw; }

/* Side notes: in the margin on wide screens, inline elsewhere. */
.body aside {
  margin: 0 0 1.2em; padding: 10px 14px; border-radius: 4px; background: var(--bg-soft);
  font: 13.5px/1.5 var(--sans); color: var(--ink-soft);
}
@media (min-width: 1240px) {
  .body aside {
    float: right; clear: right; width: 220px; margin: 4px -268px 1em 0; padding: 0 0 0 12px;
    background: none; border-left: 2px solid var(--rule);
  }
}

.katex-display { display: block; margin: 0 0 1.2em; overflow-x: auto; overflow-y: hidden; padding: 4px 0; }
.katex { font-size: 1.08em; }

/* <div class="foreword">: a short note before an article, set apart from its text */
.body .foreword { margin: 0 0 2.4em; padding: 12px 16px; border-left: 3px solid var(--accent); background: var(--bg-soft); font: 15px/1.6 var(--sans); color: var(--ink-soft); }
.body .foreword p { margin: 0 0 .6em; }
.body .foreword p:last-child { margin-bottom: 0; }
.body .foreword strong { color: var(--ink); }

/* numbered headings and figures (front matter numbered: true) */
.secno { color: var(--ink-faint); font-weight: inherit; margin-right: .15em; }
.figno { font-weight: 600; color: var(--ink); }

/* citations [@key] and the References section (src/references.civet) */
.cites { font-family: var(--sans); font-size: .8em; white-space: nowrap; color: var(--ink-faint); }
.cite { text-decoration: none; padding: 0 .05em; }
.cite:hover { text-decoration: underline; }
.references { margin-top: 3em; padding-top: 1em; border-top: 1px solid var(--rule); font: 14px/1.55 var(--sans); color: var(--ink-soft); }
.references h2 { font-size: 13px; margin: 0 0 1em; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-faint); }
.references ol { padding-left: 2.4em; }
.references li { margin: 0 0 .6em; padding-left: .3em; }
.references li::marker { color: var(--ink-faint); }
.references li:target { background: var(--accent-soft); }
.references .ref-title { color: var(--ink); }
.references a { word-break: break-all; }
.references .ref-back { text-decoration: none; word-break: normal; }

/* marked-footnote */
.footnotes { margin-top: 3em; padding-top: 1em; border-top: 1px solid var(--rule); font: 14px/1.55 var(--sans); color: var(--ink-soft); }
.footnotes h2 { font-size: 13px; margin: 0 0 1em; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-faint); }
.footnotes ol { padding-left: 1.4em; }
.footnotes p { margin: 0 0 .5em; }
[data-footnote-ref] { text-decoration: none; font-family: var(--sans); font-size: .8em; padding: 0 .1em; }
[data-footnote-ref]::before { content: "["; }
[data-footnote-ref]::after { content: "]"; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.article-foot { max-width: var(--text); margin: 56px auto 0; padding: 0 var(--gutter); box-sizing: content-box; }
.cite { padding: 20px 0 0; border-top: 1px solid var(--rule); font: 14px/1.5 var(--sans); color: var(--ink-soft); }
.cite h3 { margin: 0 0 6px; font: 600 11px/1.4 var(--sans); letter-spacing: .08em; text-transform: uppercase; color: var(--ink-faint); }
.cite p { margin: 0 0 4px; }
.cite-url a { color: var(--ink-faint); word-break: break-all; }

/* ---------------------------------------------------------------- code highlighting (highlight.js classes) */

.hljs-comment, .hljs-quote { color: #8a8478; font-style: italic; }
.hljs-keyword, .hljs-selector-tag, .hljs-built_in, .hljs-meta .hljs-keyword { color: var(--hl-keyword); }
.hljs-string, .hljs-regexp, .hljs-addition, .hljs-attribute { color: var(--hl-string); }
.hljs-number, .hljs-literal, .hljs-symbol, .hljs-bullet { color: var(--hl-number); }
.hljs-title, .hljs-section, .hljs-name, .hljs-type, .hljs-class .hljs-title { color: var(--hl-title); }
.hljs-attr, .hljs-variable, .hljs-template-variable, .hljs-params { color: var(--hl-attr); }
.hljs-deletion { color: #b0471f; }
.hljs-emphasis { font-style: italic; }
.hljs-strong { font-weight: 700; }
