/* ---- tokens.css ---- */
/*
 * Design tokens.
 *
 * Colours are written as light-dark(light, dark) pairs so both themes are
 * defined side by side. The active scheme comes from `color-scheme`:
 *   - no data-theme attribute  -> follows the operating system
 *   - data-theme="light|dark"  -> explicit choice saved by theme.js
 *
 * The palette borrows from drafting materials: film-grey paper, blue-black
 * technical-pen ink, graphite, and a single drafting blue. The dark theme is
 * a night blueprint slate rather than an inverted page.
 */

:root {
  color-scheme: light dark;

  /* Base palette */
  --paper: light-dark(#f6f7f5, #121920);
  --sheet: light-dark(#eceeea, #19222b);
  --ink: light-dark(#1b2127, #dce3e9);
  --graphite: light-dark(#4f5861, #9aa7b3);
  --rule: light-dark(#d5dad5, #26323d);
  --rule-strong: light-dark(#a3aca6, #405060);
  --drafting-blue: light-dark(#1f4f8f, #8db6ee);

  /* Semantic colours */
  --color-bg: var(--paper);
  --color-surface: var(--sheet);
  --color-fg: var(--ink);
  --color-fg-muted: var(--graphite);
  --color-border: var(--rule);
  --color-border-strong: var(--rule-strong);
  --color-accent: var(--drafting-blue);
  --color-link: var(--drafting-blue);
  --color-link-underline: color-mix(in srgb, var(--drafting-blue) 40%, transparent);
  --color-selection: light-dark(#cde3ef, #25415e);
  --color-focus: light-dark(#1f4f8f, #a9c9f5);

  --color-title-block-frame: light-dark(#6b747c, #5d6f80);

  --color-code-bg: light-dark(#eef0ec, #0e141a);
  --color-code-border: light-dark(#d9ddd7, #222d38);
  --color-inline-code-bg: light-dark(#e6e9e4, #1e2833);

  --color-warning: light-dark(#8f5a00, #e2a955);
  --color-observation: light-dark(#23695a, #74c4ad);

  /* Callout rules (left edge) and tints */
  --callout-note: var(--color-border-strong);
  --callout-warning: var(--color-warning);
  --callout-experiment: var(--color-accent);
  --callout-observation: var(--color-observation);
  --callout-takeaway: var(--color-fg);

  /* Typography: system fonts only, no downloads.
     Text: Charter, a sturdy transitional serif designed for legibility.
     Display: DIN / industrial grotesque, the lettering of engineering drawings.
     Mono: platform code fonts. */
  --font-text: Charter, 'Bitstream Charter', 'Sitka Text', Cambria, serif;
  --font-display: Bahnschrift, 'DIN Alternate', 'Franklin Gothic Medium', 'Nimbus Sans Narrow', sans-serif-condensed, sans-serif;
  --font-mono: ui-monospace, 'SF Mono', 'Cascadia Mono', 'Segoe UI Mono', 'Source Code Pro', Menlo, Consolas, 'DejaVu Sans Mono', monospace;

  /* Type scale (ratio ≈ 1.2 around an 18px reading size) */
  --text-xs: 0.8125rem;   /* 13 */
  --text-sm: 0.875rem;    /* 14 */
  --text-base: 1rem;      /* 16 */
  --text-md: 1.125rem;    /* 18: article body */
  --text-lg: 1.3125rem;   /* 21 */
  --text-xl: 1.625rem;    /* 26 */
  --text-2xl: clamp(1.75rem, 1.4rem + 1.4vw, 2.25rem);
  --text-3xl: clamp(2rem, 1.45rem + 2.4vw, 2.875rem);

  --leading-tight: 1.15;
  --leading-snug: 1.35;
  --leading-ui: 1.5;
  --leading-text: 1.7;

  /* Spacing scale */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 3rem;
  --space-8: 4rem;
  --space-9: 6rem;

  /* Layout */
  --container: 74rem;
  --gutter: clamp(1.25rem, 4vw, 2.5rem);
  --measure: 45rem;          /* ≈ 720px prose column */
  --toc-width: 14.5rem;
  --header-height: 3.75rem;
  --radius-sm: 3px;
  --tap-target: 2.75rem;     /* 44px */

  --duration: 150ms;
}

:root[data-theme='light'] {
  color-scheme: light;
}

:root[data-theme='dark'] {
  color-scheme: dark;
}

/* ---- base.css ---- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-top: var(--space-5);
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--color-bg);
  color: var(--color-fg);
  font-family: var(--font-text);
  font-size: var(--text-base);
  line-height: var(--leading-ui);
  font-kerning: normal;
  text-rendering: optimizeLegibility;
}

/* Only animates when the person switches theme (class set by theme.js). */
.theme-transition body {
  transition: background-color 200ms ease, color 200ms ease;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  line-height: var(--leading-tight);
  letter-spacing: -0.005em;
  text-wrap: balance;
}

p,
ul,
ol,
dl,
dd,
figure,
blockquote {
  margin: 0;
}

img,
svg,
video {
  max-width: 100%;
}

img {
  height: auto;
}

.icon {
  flex: none;
  display: inline-block;
  vertical-align: middle;
}

a {
  color: var(--color-link);
  text-decoration-line: underline;
  text-decoration-color: var(--color-link-underline);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
  transition: text-decoration-color var(--duration) ease, color var(--duration) ease;
}

a:hover {
  text-decoration-color: currentColor;
}

:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
  border-radius: 1px;
}

::selection {
  background: var(--color-selection);
}

code,
kbd,
pre,
samp {
  font-family: var(--font-mono);
  font-size: 1em;
}

button {
  font: inherit;
  color: inherit;
}

strong,
b {
  font-weight: 700;
}

time {
  font-variant-numeric: tabular-nums;
}

.visually-hidden {
  position: absolute !important; /* utility must win regardless of context */
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  z-index: 100;
  top: var(--space-2);
  left: var(--space-2);
  padding: var(--space-2) var(--space-4);
  background: var(--color-fg);
  color: var(--color-bg);
  font-size: var(--text-sm);
  text-decoration: none;
  transform: translateY(-200%);
}

.skip-link:focus {
  transform: none;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    /* Justified !important: user preference must override every component. */
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }
}

/* ---- layout.css ---- */
.container {
  width: min(100% - 2 * var(--gutter), var(--container));
  margin-inline: auto;
}

/* ---- Header ---- */

.site-header {
  border-bottom: 1px solid var(--color-border);
}

.site-header__inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  column-gap: var(--space-5);
  min-height: var(--header-height);
}

.site-mark {
  margin-inline-end: auto;
  padding-block: var(--space-3);
  font-family: var(--font-display);
  font-size: 1.0625rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--color-fg);
  text-decoration: none;
}

.site-mark:hover {
  color: var(--color-accent);
}

/* Navigation. Without JavaScript the links simply wrap below the site name.
   With JavaScript (html.js) small screens get a disclosure button. */

.site-nav {
  flex-basis: 100%;
  padding-block-end: var(--space-3);
}

.site-nav__list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-5);
  padding: 0;
  list-style: none;
}

.site-nav__list a {
  display: inline-block;
  padding-block: var(--space-2);
  color: var(--color-fg-muted);
  font-size: 0.9375rem;
  text-decoration: none;
}

.site-nav__list a:hover {
  color: var(--color-fg);
}

.site-nav__list a[aria-current='page'],
.site-nav__list a.is-active {
  color: var(--color-fg);
  text-decoration-line: underline;
  text-decoration-color: var(--color-accent);
  text-decoration-thickness: 2px;
  text-underline-offset: 0.45em;
}

.nav-toggle {
  display: none;
}

.js .nav-toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--tap-target);
  padding-inline: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: none;
  font-size: var(--text-sm);
  cursor: pointer;
}

.nav-toggle__bars,
.nav-toggle__bars::before {
  display: block;
  width: 14px;
  height: 1.5px;
  background: currentColor;
  transition: transform var(--duration) ease;
}

.nav-toggle__bars {
  position: relative;
  transform: translateY(-2.5px);
}

.nav-toggle__bars::before {
  content: '';
  position: absolute;
  top: 5px;
}

.nav-toggle[aria-expanded='true'] .nav-toggle__bars {
  transform: translateY(0) rotate(45deg);
}

.nav-toggle[aria-expanded='true'] .nav-toggle__bars::before {
  top: 0;
  transform: rotate(-90deg);
}

.js .site-nav {
  display: none;
}

.js .site-nav[data-open] {
  display: block;
  padding-block: var(--space-2) var(--space-5);
}

.js .site-nav[data-open] .site-nav__list {
  flex-direction: column;
  gap: 0;
}

.js .site-nav[data-open] .site-nav__list a {
  display: flex;
  align-items: center;
  min-height: var(--tap-target);
  font-size: var(--text-base);
}

/* ---- Main ---- */

.site-main {
  flex: 1;
  padding-block: var(--space-6) var(--space-9);
}

.site-main:focus {
  outline: none;
}

/* ---- Page header (listing, about, search, 404) ---- */

.page-header {
  max-width: var(--measure);
  margin-bottom: var(--space-7);
}

.page-header__title {
  font-size: var(--text-3xl);
  letter-spacing: -0.015em;
}

.page-header__title--tag {
  font-family: var(--font-mono);
  font-weight: 600;
  letter-spacing: -0.03em;
}

.page-header__lede {
  margin-top: var(--space-3);
  color: var(--color-fg-muted);
  font-size: var(--text-md);
}

.page-body {
  max-width: 60rem;
}

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

.site-footer {
  border-top: 1px solid var(--color-border);
  color: var(--color-fg-muted);
  font-size: var(--text-sm);
}

.site-footer__inner {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-2) var(--space-6);
  padding-block: var(--space-6) var(--space-7);
}

.site-footer__name a {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--color-fg);
  text-decoration: none;
}

.site-footer__links {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-5);
  padding: 0;
  list-style: none;
}

.site-footer__links a {
  display: inline-block;
  padding-block: var(--space-1);
  color: var(--color-fg-muted);
  text-decoration: none;
}

.site-footer__links a:hover {
  color: var(--color-fg);
  text-decoration: underline;
}

.site-footer__note {
  flex-basis: 100%;
}

/* ---- components.css ---- */
/* ---- Home ---- */

.intro {
  max-width: 46rem;
  padding-block: var(--space-5) var(--space-8);
}

.intro__title {
  font-size: var(--text-3xl);
  letter-spacing: -0.02em;
}

.intro__lede {
  max-width: 34em;
  margin-top: var(--space-3);
  color: var(--color-fg-muted);
  font-size: var(--text-lg);
  line-height: var(--leading-snug);
}

.intro .search {
  margin-top: var(--space-6);
}

.home-section + .home-section {
  margin-top: var(--space-8);
}

.home-section__title {
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--color-border-strong);
  font-size: var(--text-base);
  letter-spacing: 0.01em;
}

.home-section__more {
  margin-top: var(--space-5);
  font-size: var(--text-sm);
}

/* ---- Article entries (editorial list, not cards) ---- */

.entry-list {
  padding: 0;
  list-style: none;
}

.entry {
  padding-block: var(--space-6);
}

.entry-list > .entry + .entry {
  border-top: 1px solid var(--color-border);
}

.entry__body {
  display: flex;
  flex-direction: column;
}

.entry__date {
  order: -1;
  margin-bottom: var(--space-2);
  color: var(--color-fg-muted);
  font-size: var(--text-sm);
}

.entry__flag {
  margin-inline-end: var(--space-3);
  color: var(--color-accent);
  font-family: var(--font-display);
  font-weight: 700;
}

.entry__title {
  font-size: var(--text-lg);
  line-height: 1.25;
}

.entry__title a {
  color: var(--color-fg);
  text-decoration: none;
}

.entry__title a:hover {
  text-decoration: underline;
  text-decoration-thickness: 1px;
}

.entry__description {
  max-width: var(--measure);
  margin-top: var(--space-2);
  font-size: 1.0625rem;
  line-height: 1.55;
}

.entry__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-1) var(--space-5);
  margin-top: var(--space-3);
  color: var(--color-fg-muted);
  font-size: var(--text-sm);
}

.meta__category {
  color: var(--color-fg);
  text-decoration: none;
}

.meta__category:hover {
  text-decoration: underline;
  text-decoration-thickness: 1px;
}

.entry__meta .tag-list {
  margin: 0;
}

.entry--featured {
  padding-block: var(--space-6) var(--space-7);
  border-bottom: 1px solid var(--color-border-strong);
}

.entry--featured .entry__title {
  font-size: var(--text-xl);
  letter-spacing: -0.01em;
}

.entry--featured .entry__description {
  font-size: var(--text-md);
}

.archive-year + .archive-year {
  margin-top: var(--space-7);
}

.archive-year__title {
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--color-border-strong);
  font-size: var(--text-base);
  font-variant-numeric: tabular-nums;
}

/* ---- Tags (identifiers, so set in mono; plain text, not pills) ---- */

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-4);
  margin-top: var(--space-2);
  padding: 0;
  list-style: none;
}

.tag {
  color: var(--color-fg-muted);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  text-decoration: none;
}

.tag:hover {
  color: var(--color-link);
  text-decoration: underline;
}

.status-label {
  display: inline-block;
  padding: 0 0.4em;
  border: 1px solid var(--color-warning);
  border-radius: 2px;
  color: var(--color-warning);
  font-family: var(--font-display);
  font-size: var(--text-xs);
  font-weight: 700;
  line-height: 1.5;
}

.draft-notice {
  margin-bottom: var(--space-5);
  padding: var(--space-2) var(--space-3);
  border-left: 3px solid var(--color-warning);
  background: color-mix(in oklab, var(--color-warning) 7%, var(--color-bg));
  font-size: var(--text-sm);
}

/* ---- Title block: article metadata set like an engineering drawing's title block ---- */

.title-block {
  display: flex;
  flex-wrap: wrap;
  gap: 1px;
  margin-top: var(--space-6);
  border: 1px solid var(--color-title-block-frame);
  background: var(--color-border); /* shows through the 1px gaps as inner rules */
}

.title-block__cell {
  flex: 1 1 8.5rem;
  min-width: 0;
  padding: var(--space-2) var(--space-3) var(--space-3);
  background: var(--color-bg);
}

.title-block__cell--wide {
  flex-basis: 100%;
}

.title-block dt {
  color: var(--color-fg-muted);
  font-family: var(--font-display);
  font-size: var(--text-xs);
  letter-spacing: 0.02em;
}

.title-block dd {
  margin-top: 0.125rem;
  font-size: var(--text-base);
}

.title-block .tag-list {
  margin-top: 0.125rem;
}

.title-block .tag {
  font-size: var(--text-sm);
}

.article-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-top: var(--space-5);
}

.action {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--tap-target);
  padding-inline: var(--space-4);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  color: var(--color-fg);
  font-size: var(--text-sm);
  text-decoration: none;
  transition: border-color var(--duration) ease;
}

.action:hover {
  border-color: var(--color-fg);
}

.action .icon {
  color: var(--color-accent);
}

/* ---- Table of contents ---- */

.toc {
  font-size: var(--text-sm);
}

.toc__label {
  margin-bottom: var(--space-3);
  color: var(--color-fg-muted);
  font-family: var(--font-display);
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.02em;
}

.toc__list,
.toc__sublist {
  padding: 0;
  list-style: none;
}

.toc__list {
  border-left: 1px solid var(--color-border);
}

.toc a {
  display: block;
  margin-left: -1px;
  padding: 0.3rem 0 0.3rem var(--space-4);
  border-left: 2px solid transparent;
  color: var(--color-fg-muted);
  line-height: var(--leading-snug);
  text-decoration: none;
}

.toc__sublist a {
  padding-left: calc(var(--space-4) + var(--space-4));
  font-size: var(--text-xs);
}

.toc a:hover {
  color: var(--color-fg);
}

.toc a[aria-current='location'] {
  border-left-color: var(--color-accent);
  color: var(--color-fg);
}

.toc-mobile {
  margin-bottom: var(--space-6);
  border-block: 1px solid var(--color-border);
  font-size: var(--text-sm);
}

.toc-mobile summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: var(--tap-target);
  font-family: var(--font-display);
  font-weight: 700;
  list-style: none;
  cursor: pointer;
}

.toc-mobile summary::-webkit-details-marker {
  display: none;
}

.toc-mobile summary::after {
  content: '+';
  color: var(--color-fg-muted);
  font-family: var(--font-mono);
  font-weight: 400;
}

.toc-mobile[open] summary::after {
  content: '−';
}

.toc-mobile nav {
  padding-bottom: var(--space-3);
}

.toc-mobile .toc__list {
  border-left: 0;
}

.toc-mobile a {
  display: flex;
  align-items: center;
  min-height: 2.25rem;
  color: var(--color-fg);
  text-decoration: none;
}

.toc-mobile .toc__sublist a {
  padding-left: var(--space-4);
  color: var(--color-fg-muted);
}

/* ---- Related articles and pager ---- */

.related__heading {
  font-size: var(--text-base);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--color-border-strong);
}

.related__list {
  padding: 0;
  list-style: none;
}

.related__item {
  padding-block: var(--space-4);
  border-bottom: 1px solid var(--color-border);
}

.related__title {
  color: var(--color-fg);
  font-family: var(--font-display);
  font-size: 1.0625rem;
  font-weight: 700;
  text-decoration: none;
}

.related__title:hover {
  text-decoration: underline;
}

.related__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0 var(--space-4);
  margin-top: var(--space-1);
  color: var(--color-fg-muted);
  font-size: var(--text-sm);
}

.pager {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--space-4) var(--space-6);
  margin-top: var(--space-7);
}

.pager__link {
  display: flex;
  flex-direction: column;
  max-width: 20rem;
  color: var(--color-fg);
  text-decoration: none;
}

.pager__link--next {
  margin-inline-start: auto;
  text-align: end;
}

.pager__label {
  color: var(--color-fg-muted);
  font-size: var(--text-xs);
}

.pager__title {
  font-size: var(--text-sm);
}

.pager__link:hover .pager__title {
  text-decoration: underline;
}

/* ---- Topic and tag indexes ---- */

.topic-index {
  max-width: var(--measure);
  padding: 0;
  list-style: none;
}

.topic-index__item {
  padding-block: var(--space-4);
  border-bottom: 1px solid var(--color-border);
}

.topic-index__row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0 var(--space-4);
}

.topic-index__name {
  color: var(--color-fg);
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 700;
  text-decoration: none;
}

.topic-index__name:hover {
  text-decoration: underline;
}

.topic-index__count {
  color: var(--color-fg-muted);
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
}

.topic-index__latest {
  margin-top: var(--space-1);
  color: var(--color-fg-muted);
  font-size: var(--text-sm);
}

.topic-index--compact {
  max-width: none;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
  column-gap: var(--space-7);
}

.topic-index--compact .topic-index__item {
  padding-block: var(--space-3);
}

.topic-index--compact .topic-index__name {
  font-size: var(--text-base);
}

.tag-index {
  columns: 14rem;
  column-gap: var(--space-7);
  padding: 0;
  list-style: none;
}

.tag-index__item {
  display: flex;
  align-items: baseline;
  break-inside: avoid;
  padding-block: var(--space-1);
}

.tag-index__name {
  display: inline-block;
  padding-block: var(--space-1);
  color: var(--color-fg);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  text-decoration: none;
}

.tag-index__name:hover {
  color: var(--color-link);
  text-decoration: underline;
}

/* Dot leader, as in a printed index. */
.tag-index__leader {
  flex: 1;
  min-width: var(--space-4);
  margin-inline: var(--space-2);
  border-bottom: 1px dotted var(--color-border-strong);
  transform: translateY(-0.3em);
}

.tag-index__count {
  color: var(--color-fg-muted);
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
}

.breadcrumb ol {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
  padding: 0;
  list-style: none;
  color: var(--color-fg-muted);
  font-size: var(--text-sm);
}

.breadcrumb li + li::before {
  content: '/';
  margin-inline-end: var(--space-2);
  color: var(--color-border-strong);
}

.breadcrumb a {
  color: inherit;
}

.empty-state {
  max-width: var(--measure);
  padding-block: var(--space-6);
  color: var(--color-fg-muted);
}

.empty-state__hint {
  margin-top: var(--space-2);
  font-size: var(--text-sm);
}

.empty-state code {
  font-size: 0.9em;
}

.notfound-links {
  max-width: var(--measure);
  margin-top: var(--space-6);
  color: var(--color-fg-muted);
}

/* ---- Search ---- */

.search {
  position: relative;
  max-width: 34rem;
}

.search__field {
  position: relative;
  display: flex;
  align-items: center;
}

.search__field > .icon {
  position: absolute;
  left: 0.875rem;
  color: var(--color-fg-muted);
  pointer-events: none;
}

.search__input {
  width: 100%;
  min-height: 2.875rem;
  padding: 0.6rem 2.75rem 0.6rem 2.5rem;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  color: var(--color-fg);
  font: inherit;
  font-size: var(--text-base); /* 16px prevents zoom-on-focus in iOS Safari */
  appearance: none;
}

.search__input::placeholder {
  color: var(--color-fg-muted);
  opacity: 1;
}

.search__input::-webkit-search-cancel-button {
  cursor: pointer;
}

.search__input:focus-visible {
  outline-offset: 1px;
}

.search__hint {
  position: absolute;
  right: 0.75rem;
  padding: 0 0.4rem;
  border: 1px solid var(--color-border-strong);
  border-radius: 2px;
  color: var(--color-fg-muted);
  font-size: var(--text-xs);
  line-height: 1.5;
  pointer-events: none;
}

/* Native clear button, redrawn in the palette instead of the browser's system blue. */
.search__input::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
  width: 0.875rem;
  height: 0.875rem;
  background-color: var(--color-fg-muted);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3 3l10 10M13 3L3 13' stroke='black' stroke-width='1.75' stroke-linecap='round'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3 3l10 10M13 3L3 13' stroke='black' stroke-width='1.75' stroke-linecap='round'/%3E%3C/svg%3E") center / contain no-repeat;
  cursor: pointer;
}

.search__input::-webkit-search-cancel-button:hover {
  background-color: var(--color-fg);
}

/* The "/" shortcut is a JavaScript feature; don't advertise it without JS or on touch screens. */
html:not(.js) .search__hint {
  display: none;
}

@media (hover: none) {
  .search__hint {
    display: none;
  }
}

.search__input:focus + .search__hint,
.search__input:not(:placeholder-shown) + .search__hint {
  visibility: hidden;
}

.search__panel {
  background: var(--color-bg);
}

.search--dropdown .search__panel {
  position: absolute;
  z-index: 20;
  top: calc(100% + 0.375rem);
  left: 0;
  right: 0;
  max-height: min(28rem, 70vh);
  overflow-y: auto;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  /* The one shadow in the system: it separates a floating panel from the page. */
  box-shadow: 0 12px 28px -16px rgb(0 0 0 / 0.35);
}

.search__results {
  padding: 0;
  list-style: none;
}

.search__option {
  border-left: 2px solid transparent;
}

.search__option + .search__option {
  border-top: 1px solid var(--color-border);
}

.search__option a {
  display: block;
  padding: var(--space-3) var(--space-4);
  color: var(--color-fg);
  text-decoration: none;
}

.search__option[aria-selected='true'] {
  border-left-color: var(--color-accent);
  background: var(--color-surface);
}

.search__option-title {
  display: block;
  font-family: var(--font-display);
  font-weight: 700;
  line-height: var(--leading-snug);
}

.search__option-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0 var(--space-3);
  margin-top: 0.125rem;
  color: var(--color-fg-muted);
  font-size: var(--text-xs);
}

.search__option-snippet {
  display: block;
  margin-top: var(--space-1);
  color: var(--color-fg-muted);
  font-size: var(--text-sm);
}

.search__message {
  padding: var(--space-3) var(--space-4);
  color: var(--color-fg-muted);
  font-size: var(--text-sm);
}

.search__more {
  padding: var(--space-2) var(--space-4);
  border-top: 1px solid var(--color-border);
  font-size: var(--text-sm);
}

.search mark {
  background: var(--color-selection);
  color: inherit;
  border-radius: 1px;
}

.search--page {
  max-width: var(--measure);
}

.search--page .search__panel {
  margin-top: var(--space-5);
  border-top: 1px solid var(--color-border-strong);
}

.search--page .search__option a {
  padding-block: var(--space-4);
}

.search--page .search__option-title {
  font-size: var(--text-lg);
}

.search--page .search__message {
  padding-inline: 0;
}

.search-help {
  max-width: var(--measure);
  margin-top: var(--space-3);
  color: var(--color-fg-muted);
  font-size: var(--text-sm);
}

/* ---- Theme switch ---- */

.theme-switch {
  display: none;
}

.js .theme-switch {
  display: inline-flex;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
}

.theme-switch__option {
  display: grid;
  place-items: center;
  width: var(--tap-target);
  height: 2.25rem;
  padding: 0;
  border: 0;
  border-radius: 2px;
  background: none;
  color: var(--color-fg-muted);
  cursor: pointer;
}

.theme-switch__option:hover {
  color: var(--color-fg);
}

.theme-switch__option[aria-pressed='true'] {
  background: var(--color-surface);
  color: var(--color-fg);
  box-shadow: inset 0 0 0 1px var(--color-border);
}

.js .site-nav[data-open] .theme-switch {
  margin-top: var(--space-4);
}

/* ---- article.css ---- */
/* ---- Article layout (single column; responsive.css adds the TOC column) ---- */

.article-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas:
    'header'
    'tocm'
    'body'
    'footer';
}

.article-header {
  grid-area: header;
  max-width: var(--measure);
  margin-bottom: var(--space-7);
}

.toc-mobile {
  grid-area: tocm;
}

.article-body {
  grid-area: body;
  min-width: 0;
}

.toc {
  grid-area: toc;
  display: none;
}

.article-footer {
  grid-area: footer;
  max-width: var(--measure);
  margin-top: var(--space-9);
}

.article-header__category {
  margin-bottom: var(--space-3);
  font-size: var(--text-sm);
}

.article-header__category a {
  color: var(--color-accent);
  text-decoration: none;
}

.article-header__category a:hover {
  text-decoration: underline;
}

.article-header__title {
  font-size: var(--text-3xl);
  letter-spacing: -0.02em;
}

.article-header__description {
  margin-top: var(--space-4);
  color: var(--color-fg-muted);
  font-size: var(--text-lg);
  line-height: 1.45;
}

/* ---- Prose ---- */

.prose {
  max-width: var(--measure);
  font-size: var(--text-md);
  line-height: var(--leading-text);
  overflow-wrap: break-word;
  hanging-punctuation: first;
}

.prose > * + * {
  margin-top: 1.25em;
}

.prose h2,
.prose h3,
.prose h4 {
  scroll-margin-top: var(--space-5);
}

.prose h2 {
  margin-top: 2.5em;
  font-size: 1.5rem;
  letter-spacing: -0.01em;
}

.prose h3 {
  margin-top: 2em;
  font-size: 1.25rem;
}

.prose h4 {
  margin-top: 1.75em;
  font-size: 1.0625rem;
}

.prose :is(h2, h3, h4) + :not(h2, h3, h4) {
  margin-top: 0.6em;
}

.prose > :first-child {
  margin-top: 0;
}

.heading-anchor {
  margin-inline-start: 0.35em;
  color: var(--color-fg-muted);
  font-weight: 400;
  text-decoration: none;
  opacity: 0;
  transition: opacity var(--duration) ease;
}

.prose :is(h2, h3, h4):hover .heading-anchor,
.heading-anchor:focus-visible {
  opacity: 1;
}

.prose a {
  overflow-wrap: anywhere;
}

/* External links: a small muted arrow after the link (hidden from screen readers). */
.external-mark {
  margin-inline-start: 0.1em;
  color: var(--color-fg-muted);
  font-size: 0.7em;
  vertical-align: 0.3em;
  line-height: 0;
}

.prose ul,
.prose ol {
  padding-inline-start: 1.5em;
}

.prose li {
  padding-inline-start: 0.25em;
}

.prose li + li,
.prose li > ul,
.prose li > ol {
  margin-top: 0.2em;
}

.prose li > p + p {
  margin-top: 0.75em;
}

.prose li::marker {
  color: var(--color-fg-muted);
}

.prose ol > li::marker {
  font-variant-numeric: tabular-nums;
}

.prose blockquote {
  padding-inline-start: 1.25em;
  border-left: 2px solid var(--color-border-strong);
  color: var(--color-fg-muted);
}

.prose blockquote > * + * {
  margin-top: 0.75em;
}

.prose hr {
  margin-block: 3em;
  border: 0;
  border-top: 1px solid var(--color-border);
}

.prose img {
  display: block;
  border: 1px solid var(--color-border);
}

.prose :not(pre) > code {
  padding: 0.1em 0.35em;
  border-radius: 3px;
  background: var(--color-inline-code-bg);
  font-size: 0.85em;
  overflow-wrap: anywhere;
}

.prose strong {
  font-weight: 700;
}

/* ---- Code blocks ---- */

.code-block {
  border: 1px solid var(--color-code-border);
  border-radius: var(--radius-sm);
  background: var(--color-code-bg);
}

.prose > .code-block,
.callout__body > .code-block {
  margin-top: 1.5em;
}

.prose > .code-block + *,
.callout__body > .code-block + * {
  margin-top: 1.5em;
}

.code-block__bar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 2.25rem;
  padding-inline: var(--space-4) var(--space-1);
  border-bottom: 1px solid var(--color-code-border);
  color: var(--color-fg-muted);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  line-height: 1.4;
}

.code-block__caption {
  min-width: 0;
  overflow: hidden;
  color: var(--color-fg);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.code-block__copy {
  margin-inline-start: auto;
  min-width: 4.5rem;
  min-height: 1.875rem;
  padding: 0 var(--space-2);
  border: 1px solid transparent;
  border-radius: 2px;
  background: none;
  color: var(--color-fg-muted);
  font-family: var(--font-display);
  font-size: 0.75rem;
  cursor: pointer;
  transition: border-color var(--duration) ease, color var(--duration) ease;
}

.code-block__copy:hover {
  border-color: var(--color-border-strong);
  color: var(--color-fg);
}

.code-block__copy[data-state='copied'] {
  color: var(--color-observation);
}

.code-block pre {
  margin: 0;
  padding: var(--space-4);
  overflow-x: auto;
  font-size: 0.875rem;
  line-height: 1.6;
  tab-size: 4;
}

.code-block pre:focus-visible {
  outline-offset: -2px;
}

.code-block code {
  display: block;
  width: max-content;
  min-width: 100%;
  color: var(--color-fg);
}

/* ---- Callouts ---- */

.callout {
  padding: var(--space-3) var(--space-4) var(--space-4) var(--space-5);
  border-left: 2px solid var(--callout-rule, var(--callout-note));
  background: var(--callout-bg, transparent);
}

.prose > .callout {
  margin-top: 1.75em;
}

.prose > .callout + * {
  margin-top: 1.75em;
}

.callout__label {
  color: var(--callout-label, var(--color-fg-muted));
  font-family: var(--font-display);
  font-size: var(--text-sm);
  line-height: var(--leading-snug);
}

.callout__kind {
  font-weight: 700;
}

.callout__title {
  margin-inline-start: 0.35em;
  color: var(--color-fg);
  font-family: var(--font-text);
  font-size: var(--text-base);
}

.callout__body {
  margin-top: var(--space-2);
  font-size: 0.9444em; /* 17px inside 18px prose */
}

.callout__body > * + * {
  margin-top: 0.9em;
}

.callout--note {
  --callout-rule: var(--callout-note);
}

.callout--warning {
  --callout-rule: var(--callout-warning);
  --callout-label: var(--color-warning);
  --callout-bg: color-mix(in oklab, var(--color-warning) 6%, var(--color-bg));
}

.callout--experiment {
  --callout-rule: var(--callout-experiment);
  --callout-label: var(--color-accent);
}

.callout--observation {
  --callout-rule: var(--callout-observation);
  --callout-label: var(--color-observation);
}

.callout--takeaway {
  --callout-rule: var(--callout-takeaway);
  --callout-label: var(--color-fg);
  --callout-bg: var(--color-surface);
  border-left-width: 3px;
}

/* ---- Tables ---- */

.table-scroll {
  overflow-x: auto;
}

.prose > .table-scroll {
  margin-top: 1.5em;
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8889em; /* 16px */
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
}

.prose th,
.prose td {
  min-width: 6rem;
  padding: 0.55em 1em 0.55em 0;
  text-align: start;
  vertical-align: top;
}

.prose :is(th, td):last-child {
  padding-inline-end: 0;
}

.prose th {
  border-bottom: 1px solid var(--color-border-strong);
  font-family: var(--font-display);
  font-size: 0.9375em;
  font-weight: 700;
  vertical-align: bottom;
}

.prose td {
  border-bottom: 1px solid var(--color-border);
}

.prose tr:last-child td {
  border-bottom-color: var(--color-border-strong);
}

/* ---- Static page (About) ---- */

.page-article .prose {
  font-size: var(--text-md);
}

/* ---- syntax.css ---- */
/*
 * Syntax highlighting for highlight.js class names (generated at build time).
 * A restrained palette: comments recede, keywords and strings are distinct,
 * everything else stays close to the ink colour. Each value is a light/dark pair
 * checked for at least 4.5:1 contrast against the code background.
 */

.hljs {
  color: var(--color-fg);
  background: transparent;
}

.hljs-comment,
.hljs-quote {
  color: light-dark(#5d6660, #8391a0);
  font-style: italic;
}

.hljs-keyword,
.hljs-selector-tag,
.hljs-literal,
.hljs-doctag {
  color: light-dark(#8a2856, #ee9ec4);
}

.hljs-string,
.hljs-regexp,
.hljs-char.escape_ {
  color: light-dark(#2c652d, #a4d48f);
}

.hljs-number,
.hljs-symbol,
.hljs-bullet {
  color: light-dark(#8f4700, #f0b374);
}

.hljs-title,
.hljs-title.function_,
.hljs-section {
  color: light-dark(#1f4f8f, #8db6ee);
}

.hljs-title.class_,
.hljs-type,
.hljs-title.class_.inherited__ {
  color: light-dark(#6d4a00, #e8c97a);
}

.hljs-built_in,
.hljs-variable.language_ {
  color: light-dark(#0c5f63, #78d0cc);
}

.hljs-attr,
.hljs-attribute,
.hljs-property,
.hljs-selector-attr,
.hljs-selector-class,
.hljs-selector-id {
  color: light-dark(#5a3d93, #c5acf4);
}

.hljs-meta,
.hljs-meta .hljs-keyword {
  color: light-dark(#56606a, #9aa7b3);
}

.hljs-meta .hljs-string {
  color: light-dark(#2c652d, #a4d48f);
}

.hljs-name,
.hljs-tag {
  color: light-dark(#1f4f8f, #8db6ee);
}

.hljs-variable,
.hljs-template-variable,
.hljs-params,
.hljs-subst,
.hljs-operator,
.hljs-punctuation {
  color: inherit;
}

.hljs-link {
  color: var(--color-link);
  text-decoration: underline;
}

.hljs-emphasis {
  font-style: italic;
}

.hljs-strong {
  font-weight: 700;
}

.hljs-addition {
  display: inline-block;
  width: 100%;
  background: light-dark(#dcefdc, #173222);
  color: light-dark(#1f5a22, #b4e3a3);
}

.hljs-deletion {
  display: inline-block;
  width: 100%;
  background: light-dark(#f6dfdf, #3a1c20);
  color: light-dark(#8a1f1f, #f3b1b1);
}

/* ---- responsive.css ---- */
/*
 * Breakpoints, smallest first. Base styles in the other files are the phone layout.
 *   40rem  (640px)  entries gain a date margin column
 *   48rem  (768px)  inline navigation replaces the menu button
 *   60rem  (960px)  code blocks extend slightly beyond the prose column
 *   68rem (1088px)  articles gain the sticky "On this page" sidebar
 */

@media (min-width: 40rem) {
  .entry__body {
    display: grid;
    grid-template-columns: 8.5rem minmax(0, 1fr);
    column-gap: var(--space-6);
  }

  .entry__body > * {
    grid-column: 2;
  }

  .entry__body > .entry__date {
    grid-column: 1;
    grid-row: 1 / span 4;
    margin: 0;
    padding-top: 0.2rem;
  }

  .entry--featured .entry__date {
    padding-top: 0.45rem;
  }

  .entry__flag {
    display: block;
    margin-bottom: var(--space-1);
  }

  .code-block pre {
    font-size: 0.9375rem;
  }
}

@media (min-width: 48rem) {
  .site-header__inner {
    flex-wrap: nowrap;
  }

  .js .nav-toggle {
    display: none;
  }

  .site-nav,
  .js .site-nav {
    display: flex;
    flex-basis: auto;
    align-items: center;
    gap: var(--space-5);
    padding: 0;
  }

  .site-nav__list {
    flex-wrap: nowrap;
  }

  .theme-switch__option {
    width: 2rem;
    height: 2rem;
  }
}

@media (min-width: 60rem) {
  .prose > .code-block {
    margin-inline: calc(-1 * var(--space-4));
  }
}

@media (min-width: 68rem) {
  .has-toc .article-layout {
    grid-template-columns: minmax(0, var(--measure)) var(--toc-width);
    grid-template-areas:
      'header .'
      'body   toc'
      'footer .';
    column-gap: clamp(3rem, 7vw, 6rem);
  }

  .has-toc .toc {
    display: block;
    position: sticky;
    top: var(--space-6);
    align-self: start;
    max-height: calc(100vh - 2 * var(--space-6));
    overflow-y: auto;
  }

  .has-toc .toc-mobile {
    display: none;
  }
}

/* Touch screens have no hover, so the search shortcut hint is noise there. */
@media (hover: none) {
  .search__hint {
    display: none;
  }
}

@media print {
  .site-header,
  .site-footer,
  .toc,
  .toc-mobile,
  .article-footer,
  .heading-anchor,
  .code-block__copy,
  .skip-link {
    display: none;
  }

  :root {
    color-scheme: light;
  }

  body {
    background: #fff;
    color: #000;
  }

  .external-mark {
    display: none;
  }

  .prose a.link-external::after {
    content: ' (' attr(href) ')';
    font-size: 0.8em;
    overflow-wrap: anywhere;
  }

  .code-block pre {
    white-space: pre-wrap;
  }
}
