/* ============================================================
   cygnus-supra — technical archive reading layer
   Aesthetic: workshop service manual / blueprint
   Defaults dark (garage / night use); honors prefers-color-scheme
============================================================ */

/* Fonts are vendored locally — see build/static/fonts.css, generated by
   build/scripts/fetch_fonts.py, and linked ahead of this file in base.html.j2.
   The archive must render with no third-party network access. */

/* --- Reset --- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; tab-size: 4; scroll-behavior: smooth; }
body {
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.65;
  color: var(--ink);
  background: var(--bg);
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "kern", "liga";
  background-image: var(--bg-noise);
}
img, picture, video, canvas, svg { display: block; max-width: 100%; height: auto; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
a { color: inherit; }
input { font: inherit; color: inherit; background: none; border: 0; }
::selection { background: var(--selection); color: var(--ink-strong); }

/* === DESIGN TOKENS === */

:root {
  --font-display: 'Schibsted Grotesk', ui-sans-serif, sans-serif;
  --font-body: 'Source Serif 4', Georgia, serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  /* DARK THEME — default */
  --bg:        #0c0e12;
  --bg-elev:   #14181f;
  --bg-rail:   #0a0c10;
  --ink:       #d8d6d2;
  --ink-strong:#f5f3ee;
  --ink-mute:  #767d88;
  --rule:      #1f242c;
  --rule-strong:#383f49;
  --mark:      rgba(232, 77, 57, 0.22);
  --accent:    #e84d39;
  --accent-soft:#a83524;
  --selection: #2c3e50;
  --shadow:    0 18px 40px -12px rgba(0,0,0,0.7);

  --warn-bg:   rgba(214,139,58,0.08);  --warn-rule: #d68b3a;
  --note-bg:   rgba(105,117,134,0.08); --note-rule: #6b7282;
  --spec-bg:   rgba(78,197,224,0.06);  --spec-rule: #4ec5e0;

  --bg-noise: none;

  --rail-width: 16rem;
  --right-width: 13rem;
  --header-h: 3.5rem;
  --content-max: 44rem;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg:        #f4efe6;
    --bg-elev:   #fbf7ee;
    --bg-rail:   #ede7d8;
    --ink:       #18161a;
    --ink-strong:#000000;
    --ink-mute:  #6b6358;
    --rule:      #d6cfc1;
    --rule-strong:#a89e88;
    --mark:      rgba(193,40,26,0.16);
    --accent:    #c1281a;
    --accent-soft:#963f30;
    --selection: #f3d693;
    --shadow:    0 14px 30px -14px rgba(34,28,18,0.25);
    --warn-bg:   rgba(214,139,58,0.13); --warn-rule: #b87420;
    --note-bg:   rgba(99,92,79,0.10);   --note-rule: #635c4f;
    --spec-bg:   rgba(46,134,171,0.06); --spec-rule: #2c779a;
  }
}

[data-theme="dark"] {
  --bg:#0c0e12; --bg-elev:#14181f; --bg-rail:#0a0c10;
  --ink:#d8d6d2; --ink-strong:#f5f3ee; --ink-mute:#767d88;
  --rule:#1f242c; --rule-strong:#383f49;
  --mark: rgba(232,77,57,0.22); --accent:#e84d39; --accent-soft:#a83524;
  --selection:#2c3e50; --shadow: 0 18px 40px -12px rgba(0,0,0,0.7);
  --warn-bg: rgba(214,139,58,0.08); --warn-rule:#d68b3a;
  --note-bg: rgba(105,117,134,0.08); --note-rule:#6b7282;
  --spec-bg: rgba(78,197,224,0.06); --spec-rule:#4ec5e0;
}
[data-theme="light"] {
  --bg:#f4efe6; --bg-elev:#fbf7ee; --bg-rail:#ede7d8;
  --ink:#18161a; --ink-strong:#000; --ink-mute:#6b6358;
  --rule:#d6cfc1; --rule-strong:#a89e88;
  --mark: rgba(193,40,26,0.16); --accent:#c1281a; --accent-soft:#963f30;
  --selection:#f3d693; --shadow: 0 14px 30px -14px rgba(34,28,18,0.25);
  --warn-bg: rgba(214,139,58,0.13); --warn-rule:#b87420;
  --note-bg: rgba(99,92,79,0.10); --note-rule:#635c4f;
  --spec-bg: rgba(46,134,171,0.06); --spec-rule:#2c779a;
}

/* === LAYOUT GRID === */

.page {
  display: grid;
  grid-template-columns: var(--rail-width) minmax(0, 1fr) var(--right-width);
  grid-template-rows: var(--header-h) 1fr auto;
  grid-template-areas:
    "header header header"
    "rail   main   right"
    "footer footer footer";
  min-height: 100vh;
  max-width: 90rem;
  margin: 0 auto;
}

/* === HEADER === */

.site-header {
  grid-area: header;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1.25rem;
  border-bottom: 1px solid var(--rule);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 50;
  font-family: var(--font-display);
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  text-decoration: none;
  letter-spacing: 0.04em;
}
.brand .logomark {
  width: 1.7rem; height: 1.7rem;
  display: grid; place-items: center;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--ink-strong);
  border: 1px solid var(--ink-strong);
  position: relative;
}
.brand .logomark::after {
  content: "";
  position: absolute;
  inset: -3px;
  border-top: 1px solid var(--accent);
  border-right: 1px solid var(--accent);
  width: 4px; height: 4px;
  top: -3px; left: auto; right: -3px; bottom: auto;
}
.brand-name {
  font-weight: 600;
  font-size: 0.9rem;
  text-transform: uppercase;
  color: var(--ink-strong);
  letter-spacing: 0.03em;
}
.brand-sub {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  color: var(--ink-mute);
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.search-trigger {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.7rem 0.4rem 0.8rem;
  border: 1px solid var(--rule);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--ink-mute);
  flex: 1;
  max-width: 28rem;
  margin-left: 1.5rem;
  background: var(--bg-elev);
  transition: border-color 120ms, color 120ms;
}
.search-trigger:hover { border-color: var(--rule-strong); color: var(--ink); }
.search-trigger kbd {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  padding: 1px 5px;
  border: 1px solid var(--rule-strong);
  color: var(--ink-mute);
}

.theme-toggle, .menu-toggle {
  display: grid; place-items: center;
  width: 2rem; height: 2rem;
  color: var(--ink-mute);
  transition: color 120ms;
}
.theme-toggle:hover, .menu-toggle:hover { color: var(--ink-strong); }
[data-theme="light"] .icon-moon, .icon-sun { display: block; }
[data-theme="light"] .icon-sun, .icon-moon { display: none; }
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) .icon-sun { display: block; }
  :root:not([data-theme]) .icon-moon { display: none; }
}
.menu-toggle { display: none; }

/* === LEFT RAIL (TOC) === */

.rail {
  grid-area: rail;
  background: var(--bg-rail);
  border-right: 1px solid var(--rule);
  padding: 1.25rem 0 4rem;
  overflow-y: auto;
  position: sticky;
  top: var(--header-h);
  height: calc(100vh - var(--header-h));
  font-family: var(--font-display);
  scrollbar-width: thin;
  scrollbar-color: var(--rule-strong) transparent;
}
.rail::-webkit-scrollbar { width: 6px; }
.rail::-webkit-scrollbar-track { background: transparent; }
.rail::-webkit-scrollbar-thumb { background: var(--rule-strong); border-radius: 3px; }

.rail-section { margin-bottom: 1.25rem; }
.rail-section-title {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--ink-mute);
  padding: 0 1.25rem;
  margin-bottom: 0.4rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.rail-section-title::before {
  content: "";
  display: inline-block;
  width: 0.6rem; height: 1px;
  background: var(--rule-strong);
}
.rail-section-title .count {
  margin-left: auto;
  color: var(--ink-mute);
  opacity: 0.6;
}

.rail-link {
  display: flex;
  align-items: baseline;
  gap: 0.55rem;
  padding: 0.32rem 1.25rem;
  text-decoration: none;
  font-size: 0.86rem;
  color: var(--ink);
  position: relative;
  transition: color 100ms, background-color 100ms, padding-left 200ms;
  line-height: 1.35;
}
.rail-link:hover {
  background: var(--bg-elev);
  color: var(--ink-strong);
  padding-left: 1.4rem;
}
.rail-link[aria-current="page"] {
  color: var(--accent);
  background: var(--bg-elev);
}
.rail-link[aria-current="page"]::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 2px;
  background: var(--accent);
}
.rail-link .num {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  color: var(--ink-mute);
  flex-shrink: 0;
  letter-spacing: 0.04em;
}
.rail-link .label {
  flex: 1;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* === MAIN === */

.main {
  grid-area: main;
  padding: 2.5rem 4rem 6rem;
  max-width: calc(var(--content-max) + 8rem);
  width: 100%;
  position: relative;
}

/* === RIGHT RAIL === */

.right-rail {
  grid-area: right;
  padding: 2.5rem 1.5rem 4rem 0.5rem;
  position: sticky;
  top: var(--header-h);
  height: calc(100vh - var(--header-h));
  overflow-y: auto;
  font-family: var(--font-display);
  font-size: 0.82rem;
}
.right-rail-title {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--ink-mute);
  margin-bottom: 0.6rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--rule);
}
.right-rail-list { list-style: none; }
.right-rail-list li { padding: 0.22rem 0; }
.right-rail-list a {
  color: var(--ink-mute);
  text-decoration: none;
  transition: color 120ms, padding-left 200ms;
  display: block;
}
.right-rail-list a:hover { color: var(--ink-strong); padding-left: 0.3rem; }
.right-rail-list a.active { color: var(--accent); }
.right-rail-list .h3 { padding-left: 0.9rem; font-size: 0.78rem; }

/* === SCROLL PROGRESS === */

.scroll-progress {
  position: fixed;
  top: var(--header-h);
  left: 0;
  height: 1px;
  background: var(--accent);
  width: 0;
  z-index: 60;
  transition: width 80ms linear;
}

/* === ARTICLE === */

.article-meta {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  color: var(--ink-mute);
  text-transform: uppercase;
  margin-bottom: 1.25rem;
  display: flex;
  gap: 0.8rem;
  flex-wrap: wrap;
  align-items: center;
}
.article-meta .meta-rule {
  flex: 1;
  height: 1px;
  background: var(--rule);
  min-width: 2rem;
}
.article-meta .tag {
  padding: 1px 6px;
  border: 1px solid var(--rule);
  color: var(--ink);
}
.article-meta .tag-tip { border-color: var(--accent-soft); color: var(--accent); }
.article-meta .breadcrumb { display: flex; gap: 0.4rem; }
.article-meta .breadcrumb a { color: var(--ink-mute); text-decoration: none; }
.article-meta .breadcrumb a:hover { color: var(--ink); }

.article-title {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: clamp(2rem, 4.5vw, 2.85rem);
  line-height: 1.05;
  letter-spacing: -0.02em;
  color: var(--ink-strong);
  margin-bottom: 0.5rem;
}
.article-subtitle {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 1.1rem;
  color: var(--ink-mute);
  margin-bottom: 2.5rem;
  line-height: 1.4;
}

/* article body — counter for numbered headings */
.article-body { counter-reset: section; padding-left: 0; }
@media (min-width: 64rem) {
  .article-body { padding-left: 3.5rem; }
}

.article-body {
  font-family: var(--font-body);
  font-size: 1.06rem;
  line-height: 1.7;
  max-width: 42rem;
}
.article-body > * + * { margin-top: 1em; }
.article-body p { hyphens: auto; word-spacing: 0.01em; }
.article-body p > a, .article-body li > a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  text-decoration-color: var(--accent-soft);
  transition: text-decoration-thickness 120ms;
}
.article-body p > a:hover, .article-body li > a:hover {
  text-decoration-thickness: 2px;
}

/* drop cap */
.article-body > p:first-child::first-letter {
  font-family: var(--font-display);
  font-weight: 600;
  float: left;
  font-size: 3.4em;
  line-height: 0.85;
  margin: 0.05em 0.1em 0 -0.05em;
  color: var(--accent);
  padding-top: 0.05em;
}

.article-body h1 {
  font-family: var(--font-display);
  font-size: 1.85rem;
  font-weight: 600;
  color: var(--ink-strong);
  margin-top: 2em;
  letter-spacing: -0.01em;
}

.article-body h2 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.45rem;
  color: var(--ink-strong);
  margin-top: 2.6em;
  margin-bottom: 0.5em;
  letter-spacing: -0.01em;
  scroll-margin-top: 5rem;
  counter-increment: section;
  position: relative;
  padding-bottom: 0.45rem;
  border-bottom: 1px solid var(--rule);
}
@media (min-width: 64rem) {
  .article-body h2::before {
    content: counter(section, decimal-leading-zero);
    font-family: var(--font-mono);
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--accent);
    position: absolute;
    left: -3.5rem;
    top: 0.55rem;
    letter-spacing: 0.04em;
  }
}

.article-body h3 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.15rem;
  color: var(--ink-strong);
  margin-top: 2em;
  margin-bottom: 0.4em;
  scroll-margin-top: 5rem;
}
.article-body h4 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1rem;
  color: var(--ink);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 1.5em;
  margin-bottom: 0.3em;
}

.article-body img {
  margin: 1.75rem auto;
  max-width: 100%;
  border: 1px solid var(--rule);
  background: var(--bg-elev);
  cursor: zoom-in;
  transition: border-color 120ms, transform 200ms;
}
.article-body img:hover {
  border-color: var(--rule-strong);
}

.article-body ul, .article-body ol { padding-left: 1.5rem; }
.article-body li { margin-bottom: 0.4em; }
.article-body li::marker {
  color: var(--ink-mute);
  font-family: var(--font-mono);
  font-size: 0.85em;
}
.article-body ol > li::marker { color: var(--accent); }

.article-body blockquote {
  border-left: 2px solid var(--accent);
  margin: 1.25em 0;
  padding: 0.4rem 0 0.4rem 1.25rem;
  color: var(--ink-mute);
  font-style: italic;
}

.article-body code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  padding: 0.1em 0.35em;
  background: var(--bg-elev);
  border: 1px solid var(--rule);
}
.article-body pre {
  font-family: var(--font-mono);
  font-size: 0.85em;
  padding: 1rem 1.25rem;
  background: var(--bg-elev);
  border: 1px solid var(--rule);
  border-left: 2px solid var(--accent);
  overflow-x: auto;
  line-height: 1.5;
}
.article-body pre code { padding: 0; background: none; border: 0; }

.article-body table {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  border-collapse: collapse;
  width: 100%;
  margin: 1.5rem 0;
}
.article-body th, .article-body td {
  border: 1px solid var(--rule);
  padding: 0.5rem 0.75rem;
  text-align: left;
  vertical-align: top;
}
.article-body th {
  background: var(--bg-elev);
  font-family: var(--font-display);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.7rem;
  color: var(--ink-mute);
}

/* horizontal rule as a service-manual divider */
.article-body hr {
  border: 0;
  height: 1px;
  background: var(--rule);
  margin: 2.5em 0;
  position: relative;
}
.article-body hr::before {
  content: "✕";
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: var(--bg);
  padding: 0 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--ink-mute);
}

/* spec callout — torque values etc. */
.spec {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.5rem 1.5rem;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  margin: 1.75rem 0;
  padding: 1rem 1.25rem;
  background: var(--spec-bg);
  border-left: 2px solid var(--spec-rule);
}
.spec dt { color: var(--ink-mute); text-transform: uppercase; font-size: 0.7rem; letter-spacing: 0.06em; }
.spec dd { color: var(--ink-strong); }

.callout {
  margin: 1.75rem 0;
  padding: 1rem 1.25rem;
  font-family: var(--font-display);
  font-size: 0.96rem;
  border-left: 2px solid var(--note-rule);
  background: var(--note-bg);
}
.callout-warn { border-color: var(--warn-rule); background: var(--warn-bg); }
.callout strong {
  display: block;
  font-family: var(--font-mono);
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  color: var(--ink-mute);
  margin-bottom: 0.3rem;
}
.callout-warn strong { color: var(--warn-rule); }

/* article footer */
.article-footer {
  margin-top: 4.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--rule);
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}
.article-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
.article-nav a {
  display: block;
  padding: 1rem 1.1rem;
  border: 1px solid var(--rule);
  text-decoration: none;
  transition: border-color 150ms, background-color 150ms;
  font-family: var(--font-display);
}
.article-nav a:hover {
  border-color: var(--accent-soft);
  background: var(--bg-elev);
}
.article-nav .label {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-mute);
  margin-bottom: 0.3rem;
  display: flex; gap: 0.4rem; align-items: center;
}
.article-nav .next { text-align: right; }
.article-nav .next .label { justify-content: flex-end; }
.article-nav .title {
  font-family: var(--font-display);
  font-weight: 500;
  color: var(--ink-strong);
  font-size: 1rem;
}

.archive-meta {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-mute);
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}
.archive-meta dt { color: var(--ink-mute); opacity: 0.7; }
.archive-meta dd { color: var(--ink); }
.archive-meta-row { display: flex; gap: 0.5rem; }

/* === SECTION LANDING === */
.section-hero {
  margin-bottom: 3rem;
  padding-bottom: 1.75rem;
  border-bottom: 1px solid var(--rule);
}
.section-eyebrow {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--accent);
  margin-bottom: 0.6rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.section-eyebrow::before {
  content: "";
  width: 1.5rem; height: 1px;
  background: var(--accent);
}
.section-title {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: clamp(2.5rem, 6vw, 3.5rem);
  line-height: 1;
  letter-spacing: -0.025em;
  color: var(--ink-strong);
  margin-bottom: 0.7rem;
}
.section-summary {
  font-family: var(--font-display);
  color: var(--ink-mute);
  max-width: 38rem;
  font-size: 1.1rem;
  line-height: 1.5;
}

/* index of pages */
.index-list {
  list-style: none;
  border-top: 1px solid var(--rule);
}
.index-row {
  display: grid;
  grid-template-columns: 2.5rem 1fr auto;
  gap: 1.25rem;
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--rule);
  align-items: baseline;
  text-decoration: none;
  color: var(--ink);
  transition: padding-left 200ms, background-color 100ms;
}
.index-row:hover {
  background: var(--bg-elev);
  padding-left: 0.5rem;
}
.index-row .num {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--ink-mute);
  letter-spacing: 0.04em;
}
.index-row .row-title {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 500;
  color: var(--ink-strong);
}
.index-row .meta {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--ink-mute);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* === SEARCH OVERLAY === */
.search-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(8, 10, 14, 0.86);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: none;
  padding-top: 5rem;
  justify-content: center;
}
.search-overlay[aria-hidden="false"] { display: flex; }
.search-shell {
  width: min(40rem, calc(100% - 2rem));
  background: var(--bg);
  border: 1px solid var(--rule-strong);
  padding: 0.5rem 1.25rem 1.5rem;
  box-shadow: var(--shadow);
  max-height: calc(100vh - 8rem);
  display: flex;
  flex-direction: column;
}
.search-shell-head {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--ink-mute);
  padding: 0.4rem 0;
  display: flex;
  justify-content: space-between;
}
.search-input {
  width: 100%;
  font-family: var(--font-display);
  font-size: 1.5rem;
  padding: 0.5rem 0;
  color: var(--ink-strong);
  border-bottom: 1px solid var(--rule);
}
.search-input::placeholder { color: var(--ink-mute); }
.search-input:focus { outline: none; border-bottom-color: var(--accent); }
.search-results {
  margin-top: 1rem;
  overflow-y: auto;
  flex: 1;
}
.search-results-empty {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--ink-mute);
  padding: 1rem 0;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.search-result {
  display: block;
  padding: 0.85rem 0.5rem;
  border-bottom: 1px solid var(--rule);
  text-decoration: none;
  color: var(--ink);
}
.search-result:hover, .search-result:focus { background: var(--bg-elev); outline: none; }
.search-result-path {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-mute);
  margin-bottom: 0.25rem;
}
.search-result-title {
  font-family: var(--font-display);
  font-weight: 500;
  color: var(--ink-strong);
  font-size: 1rem;
  margin-bottom: 0.25rem;
}
.search-result-excerpt {
  font-family: var(--font-body);
  font-size: 0.88rem;
  color: var(--ink-mute);
  line-height: 1.4;
}
.search-result-excerpt mark {
  background: var(--mark);
  color: var(--ink-strong);
  padding: 0 2px;
}

/* === LIGHTBOX === */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0,0,0,0.92);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  touch-action: none; /* let our PointerEvent handler own gestures */
  overscroll-behavior: contain;
}
.lightbox[aria-hidden="false"] { display: flex; }
.lightbox-img {
  max-width: 100%;
  max-height: 85vh;
  border: 1px solid rgba(255,255,255,0.12);
  background: var(--bg-elev);
  cursor: grab;
  transform-origin: center center;
  transition: transform 80ms ease-out;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
  will-change: transform;
}
.lightbox-img:active { cursor: grabbing; }
.lightbox.is-zoomed .lightbox-img {
  max-width: none;
  max-height: none;
  transition: transform 0ms; /* track the gesture exactly while zoomed */
}
.lightbox-hint {
  position: absolute;
  top: 1.25rem;
  left: 1.25rem;
  font-family: var(--font-mono);
  font-size: 0.66rem;
  color: rgba(255,255,255,0.45);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  pointer-events: none;
  max-width: calc(100% - 6rem); /* leave room for the close button on the right */
}
@media (hover: none) and (pointer: coarse) {
  .lightbox-hint::before { content: "Pinch to zoom · tap outside to close"; }
}
@media (hover: hover) {
  .lightbox-hint::before { content: "Scroll to zoom · drag to pan · esc to close"; }
}
.lightbox-meta {
  position: absolute;
  bottom: 1.25rem;
  left: 1.25rem;
  right: 1.25rem;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: rgba(255,255,255,0.6);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
}
.lightbox-close {
  position: absolute;
  top: 1.25rem; right: 1.25rem;
  width: 2.6rem; height: 2.6rem;
  font-family: var(--font-mono);
  font-size: 1.5rem;
  display: grid; place-items: center;
  border: 1px solid rgba(255,255,255,0.18);
  color: rgba(255,255,255,0.7);
  background: rgba(0,0,0,0.4);
  transition: color 120ms, border-color 120ms;
}
.lightbox-close:hover { color: white; border-color: white; }

/* === HOME === */
.home-hero {
  padding: 3rem 0 4rem;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 4rem;
  position: relative;
}
.home-hero::before {
  content: "";
  position: absolute;
  top: 0; left: 0;
  width: 4rem; height: 1px;
  background: var(--accent);
}
.home-eyebrow {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--ink-mute);
  margin: 1.25rem 0;
  display: flex;
  gap: 1rem;
  align-items: center;
}
.home-eyebrow .meta-rule { flex: 1; height: 1px; background: var(--rule); }
.home-eyebrow strong { color: var(--ink); font-weight: 500; }
.home-title {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: clamp(3rem, 7vw, 4.75rem);
  line-height: 0.95;
  letter-spacing: -0.025em;
  color: var(--ink-strong);
  margin-bottom: 1.25rem;
}
.home-title em { font-style: normal; color: var(--accent); }
.home-lede {
  font-family: var(--font-body);
  font-size: 1.2rem;
  line-height: 1.5;
  color: var(--ink);
  max-width: 38rem;
}

.home-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
  gap: 1.25rem;
  margin-bottom: 4rem;
}
.home-card {
  display: block;
  padding: 1.5rem 1.5rem 1.75rem;
  border: 1px solid var(--rule);
  text-decoration: none;
  color: var(--ink);
  position: relative;
  transition: border-color 120ms, transform 200ms;
  background: var(--bg);
}
.home-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}
.home-card .num {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--ink-mute);
  letter-spacing: 0.08em;
}
.home-card h3 {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 1.4rem;
  color: var(--ink-strong);
  margin: 0.4rem 0 0.5rem;
  letter-spacing: -0.01em;
}
.home-card p {
  font-family: var(--font-body);
  font-size: 0.95rem;
  color: var(--ink-mute);
  line-height: 1.5;
}
.home-card .meta {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--ink-mute);
  margin-top: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.home-card::after {
  content: "→";
  position: absolute;
  top: 1.5rem; right: 1.5rem;
  font-family: var(--font-mono);
  color: var(--ink-mute);
  transition: color 150ms, transform 200ms;
}
.home-card:hover::after { color: var(--accent); transform: translateX(4px); }

.home-section-title {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--ink-mute);
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}
.home-section-title::after {
  content: "";
  flex: 1; height: 1px; background: var(--rule);
}

/* === SITE FOOTER === */
.site-footer {
  grid-area: footer;
  padding: 2rem 4rem;
  border-top: 1px solid var(--rule);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--ink-mute);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
  align-items: center;
}
.site-footer .sep { opacity: 0.4; }
.site-footer a { color: var(--ink-mute); transition: color 120ms; text-decoration: none; }
.site-footer a:hover { color: var(--ink); }
.site-footer .credit {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.site-footer .credit::before {
  content: "";
  width: 6px; height: 6px;
  background: var(--accent);
  display: inline-block;
}

/* === RESPONSIVE === */

@media (max-width: 72rem) {
  .right-rail { display: none; }
  .page {
    grid-template-columns: var(--rail-width) minmax(0, 1fr);
    grid-template-areas: "header header" "rail main" "footer footer";
  }
  .main { padding: 2.5rem 2.5rem 6rem; }
}

@media (max-width: 56rem) {
  .page {
    grid-template-columns: 1fr;
    grid-template-areas: "header" "main" "footer";
  }
  .rail {
    position: fixed;
    top: var(--header-h); left: 0;
    width: min(20rem, 80vw);
    height: calc(100vh - var(--header-h));
    z-index: 40;
    transform: translateX(-100%);
    transition: transform 220ms cubic-bezier(0.4, 0, 0.2, 1);
    border-right: 1px solid var(--rule-strong);
    box-shadow: var(--shadow);
  }
  .rail[data-open="true"] { transform: translateX(0); }
  .menu-toggle { display: grid; }
  .search-trigger { max-width: none; margin-left: 0.5rem; }
  .search-trigger kbd, .brand-sub { display: none; }
  .main { padding: 2rem 1.25rem 4rem; }
  .article-body { padding-left: 0; }
  .article-body h2::before { display: none; }
  .article-body > p:first-child::first-letter { font-size: 2.6em; }
  .home-title { font-size: clamp(2.5rem, 11vw, 4rem); }
  .article-title { font-size: clamp(1.75rem, 6vw, 2.25rem); }
  .site-footer { padding: 1.5rem 1.25rem; gap: 0.75rem; }
  .site-footer .credit { margin-left: 0; width: 100%; margin-top: 0.5rem; }
  .article-nav { grid-template-columns: 1fr; }
  .article-nav .next { text-align: left; }
  .article-nav .next .label { justify-content: flex-start; }
}

/* utility */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* References whose targets are gone from the original site. build.py de-links
   these rather than pointing readers at a server that no longer answers. */
.unarchived-ref {
  color: var(--ink-mute);
  text-decoration: underline dotted 1px;
  text-underline-offset: 2px;
  cursor: help;
}
