/* ─────────────────────────────────────────────────────────────────────────
 * Nexus Substrate — editorial system
 * Hansard / engineering notebook. Paper · ink · one accent. No purple.
 * ───────────────────────────────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; margin: 0; }

:root {
  /* Type — Fraunces (display serif, opsz + soft axes), Source Sans 3 (UI body), IBM Plex Mono (code) */
  --font-display: 'Fraunces', 'Source Serif 4', Georgia, serif;
  --font-body: 'Source Sans 3', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;

  /* Paper · Ink · Register */
  --paper:       oklch(0.971 0.012 75);     /* warm cream */
  --paper-deep:  oklch(0.945 0.015 75);     /* aside / quoted block */
  --rule:        oklch(0.78 0.018 60);      /* hairline */
  --rule-soft:   oklch(0.88 0.012 60);
  --ink:         oklch(0.18 0.025 30);      /* deep ink, warm */
  --ink-mid:     oklch(0.38 0.025 30);
  --ink-soft:    oklch(0.55 0.020 40);
  --register:    oklch(0.50 0.180 25);      /* ferric red — the one accent */
  --register-soft: oklch(0.66 0.13 25);
  --mark:        oklch(0.45 0.10 175);      /* muted teal — "passed" mark only */

  /* Compatibility aliases (legacy templates still referencing M3 names) */
  --color-primary:              var(--register);
  --color-on-primary:           var(--paper);
  --color-surface:              var(--paper);
  --color-on-surface:           var(--ink);
  --color-on-surface-variant:   var(--ink-mid);
  --color-surface-container:    var(--paper-deep);
  --color-surface-container-high: var(--paper-deep);
  --color-outline-variant:      var(--rule-soft);
  --color-inverse-surface:      var(--ink);
  --color-inverse-on-surface:   var(--paper);
  --color-code-surface:         var(--ink);
  --color-code-on-surface:      var(--paper);
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper:       oklch(0.16 0.012 40);    /* deep ink ground */
    --paper-deep:  oklch(0.20 0.014 40);
    --rule:        oklch(0.42 0.015 50);
    --rule-soft:   oklch(0.30 0.012 50);
    --ink:         oklch(0.94 0.012 75);    /* paper now reads as foreground */
    --ink-mid:     oklch(0.75 0.012 75);
    --ink-soft:    oklch(0.62 0.012 75);
    --register:    oklch(0.72 0.16 25);     /* lifted register for dark ground */
    --register-soft: oklch(0.55 0.14 25);
    --mark:        oklch(0.68 0.12 175);
  }
}

/* Base */
html { scroll-behavior: smooth; }
body {
  font-family: var(--font-body);
  font-feature-settings: 'kern' 1, 'liga' 1, 'calt' 1, 'ss01' 1;
  font-variation-settings: 'opsz' 14;
  background: var(--paper);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  margin: 0;
}

code, pre, kbd, samp { font-family: var(--font-mono); font-feature-settings: 'kern' 1, 'liga' 0; }

/* Selection — ferric red, ink text */
::selection { background: var(--register); color: var(--paper); }

/* Links — single underline by default, no transition spasms */
a { color: inherit; }

/* Subtle paper grain — extremely low-opacity SVG fiber, no jpeg artifacts */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.035;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' seed='3'/><feColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 0.7 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}
@media (prefers-color-scheme: dark) {
  body::before { opacity: 0.06; mix-blend-mode: screen; }
}

main { position: relative; z-index: 1; }

/* ─── Editorial typography scale ─────────────────────────────────────── */
.eyebrow {
  font-family: var(--font-body);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--register);
}

.display-large,
.display {
  font-family: var(--font-display);
  font-variation-settings: 'opsz' 144, 'SOFT' 30;
  font-weight: 500;
  font-size: clamp(2.75rem, 6.4vw, 5.5rem);
  line-height: 0.96;
  letter-spacing: -0.025em;
  color: var(--ink);
}

.headline-large,
.headline {
  font-family: var(--font-display);
  font-variation-settings: 'opsz' 72, 'SOFT' 50;
  font-weight: 500;
  font-size: clamp(1.85rem, 3.2vw, 2.4rem);
  line-height: 1.08;
  letter-spacing: -0.018em;
  color: var(--ink);
}

.title-large {
  font-family: var(--font-display);
  font-variation-settings: 'opsz' 24;
  font-weight: 600;
  font-size: 1.18rem;
  line-height: 1.25;
  color: var(--ink);
}

.lede {
  font-family: var(--font-display);
  font-variation-settings: 'opsz' 18, 'SOFT' 80;
  font-weight: 400;
  font-style: italic;
  font-size: clamp(1.125rem, 1.5vw, 1.3125rem);
  line-height: 1.55;
  color: var(--ink-mid);
}

.byline {
  font-family: var(--font-body);
  font-size: 0.825rem;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
  font-variant: small-caps;
}

/* ─── Rules — the workhorse divider ──────────────────────────────────── */
.rule       { border: 0; border-top: 1px solid var(--rule); margin: 0; }
.rule-thick { border: 0; border-top: 3px double var(--ink);  margin: 0; }
.rule-soft  { border: 0; border-top: 1px solid var(--rule-soft); margin: 0; }

.section-rule {
  display: flex;
  align-items: baseline;
  gap: 1.5rem;
  padding: 0 1.5rem;
  max-width: 78rem;
  margin: 0 auto;
}
.section-rule::before,
.section-rule::after {
  content: '';
  flex: 1;
  border-top: 1px solid var(--rule);
  position: relative;
  top: -0.3em;
}
.section-rule .marker {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--register);
  white-space: nowrap;
}

/* ─── Prose — used by DocsLayout for rendered markdown ───────────────── */
.prose {
  font-family: var(--font-body);
  font-size: 1.0625rem;
  line-height: 1.72;
  color: var(--ink);
  max-width: 36rem;
}
.prose h1 {
  font-family: var(--font-display);
  font-variation-settings: 'opsz' 72, 'SOFT' 40;
  font-weight: 500;
  font-size: clamp(1.85rem, 3vw, 2.4rem);
  letter-spacing: -0.015em;
  line-height: 1.08;
  margin: 0 0 1.25rem;
}
.prose h2 {
  font-family: var(--font-display);
  font-variation-settings: 'opsz' 48;
  font-weight: 600;
  font-size: 1.5rem;
  margin: 2.75rem 0 0.75rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--rule);
  line-height: 1.2;
}
.prose h3 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.22rem;
  margin: 2rem 0 0.6rem;
  line-height: 1.3;
}
.prose h4 {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 1.04rem;
  margin: 1.5rem 0 0.4rem;
  letter-spacing: 0.01em;
}
.prose p { margin: 0 0 1rem; }
.prose a {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-color: var(--register);
  text-decoration-thickness: 1.5px;
  text-underline-offset: 3px;
}
.prose a:hover { text-decoration-thickness: 3px; }
.prose ul, .prose ol { margin: 0 0 1rem; padding-left: 1.4rem; }
.prose li { margin-bottom: 0.3rem; }
.prose code {
  font-size: 0.9em;
  padding: 0.08em 0.32em;
  border-radius: 2px;
  background: var(--paper-deep);
  color: var(--register);
}
.prose pre {
  margin: 0 0 1.5rem;
  padding: 1.1rem 1.3rem;
  background: var(--ink);
  color: var(--paper);
  font-size: 0.875rem;
  line-height: 1.65;
  overflow-x: auto;
  border-left: 3px solid var(--register);
}
.prose pre code {
  padding: 0;
  background: none;
  color: inherit;
  font-size: inherit;
}
.prose table {
  display: block;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
  margin: 0 0 1.5rem;
  font-size: 0.92rem;
}
.prose th {
  text-align: left;
  font-weight: 600;
  padding: 0.55rem 0.8rem;
  border-bottom: 2px solid var(--ink);
  color: var(--ink);
  font-variant: small-caps;
  letter-spacing: 0.04em;
}
.prose td {
  padding: 0.5rem 0.8rem;
  border-bottom: 1px solid var(--rule-soft);
  color: var(--ink-mid);
}
.prose tr:last-child td { border-bottom: none; }
.prose blockquote {
  margin: 1.25rem 0;
  padding: 0.25rem 0 0.25rem 1.1rem;
  border-left: 3px solid var(--register);
  font-family: var(--font-display);
  font-style: italic;
  font-size: 1.05em;
  color: var(--ink-mid);
}
.prose blockquote p:last-child { margin-bottom: 0; }
.prose hr { border: 0; border-top: 1px solid var(--rule); margin: 2.5rem 0; }
.prose img { max-width: 100%; height: auto; }
.prose strong { font-weight: 700; color: var(--ink); }

/* ─── Mermaid diagrams — ink on paper, no purple ─────────────────────── */
.mermaid {
  display: flex;
  justify-content: center;
  padding: 2rem 1rem;
  background: var(--paper-deep);
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  overflow-x: auto;
  min-height: 120px;
  font-size: 0;
  color: transparent;
}
.mermaid[data-mermaid-rendered] { font-size: initial; color: inherit; }
.mermaid svg { max-width: 100%; height: auto; }

/* ─── Reduced motion ─────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
  html { scroll-behavior: auto; }
}
