/* ==========================================================================
   Odisena — Institutional Systems Atlas
   Warm paper / dark ink foundation, one electric signal color, precise grid.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Production-safe font fallbacks (no dependencies, pure CSS).
   If the Fontshare/Google CDN fails, these metric-adjusted system fallbacks
   keep the type hierarchy intact and minimize layout shift (CLS). Each custom
   family has a size/metric-matched local fallback so line lengths stay stable
   whether or not the web font arrives. Web fonts use font-display: swap.
   -------------------------------------------------------------------------- */
@font-face {
  font-family: 'Zodiak Fallback';
  src: local('Georgia'), local('Times New Roman'), local('serif');
  size-adjust: 102%;
  ascent-override: 92%;
  descent-override: 24%;
  line-gap-override: 0%;
}
@font-face {
  font-family: 'Satoshi Fallback';
  src: local('Segoe UI'), local('Helvetica Neue'), local('Arial'), local('sans-serif');
  size-adjust: 100%;
  ascent-override: 96%;
  descent-override: 24%;
  line-gap-override: 0%;
}
@font-face {
  font-family: 'JetBrains Mono Fallback';
  src: local('SFMono-Regular'), local('Menlo'), local('Consolas'), local('monospace');
  size-adjust: 100%;
}

:root {
  /* Paper / ink foundation (light) */
  --paper: #f4ede0;        /* warm paper */
  --paper-2: #ece3d3;      /* recessed paper */
  --paper-3: #e3d8c4;      /* card edge / rule tint */
  --ink: #1b1712;          /* dark ink */
  --ink-2: #4a4238;        /* secondary ink */
  --ink-3: #746a5b;        /* muted ink */
  --hairline: #cdbfa6;     /* fine-line diagram stroke */
  --hairline-strong: #b3a58a;

  /* Electric signal — a single accent, used sparingly */
  --signal: #d8461f;       /* warm vermilion */
  --signal-ink: #ffffff;
  --signal-soft: rgba(216, 70, 31, 0.10);

  /* Semantic status hues (kept restrained, mono-adjacent) */
  --st-active: #3f7d4e;
  --st-external: #4a4238;
  --st-designed: #2f5f8a;
  --st-proposed: #8a6a2f;

  /* Type */
  --font-display: 'Zodiak', 'Zodiak Fallback', 'Georgia', serif;
  --font-body: 'Satoshi', 'Satoshi Fallback', 'Inter', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'JetBrains Mono Fallback', ui-monospace, 'SFMono-Regular', monospace;

  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.1875rem;
  --text-xl: 1.5rem;
  --text-2xl: 2.125rem;
  --text-3xl: 3rem;
  --text-hero: clamp(2.75rem, 6.5vw, 5.5rem);

  /* Space */
  --sp-1: 0.25rem; --sp-2: 0.5rem; --sp-3: 0.75rem; --sp-4: 1rem;
  --sp-6: 1.5rem; --sp-8: 2rem; --sp-12: 3rem; --sp-16: 4rem;
  --sp-24: 6rem; --sp-32: 8rem;

  --maxw: 1240px;
  --gutter: clamp(1.25rem, 4vw, 4rem);
  --radius: 3px;

  --bg: var(--paper);
  --bg-2: var(--paper-2);
  --bg-3: var(--paper-3);
  --fg: var(--ink);
  --fg-2: var(--ink-2);
  --fg-3: var(--ink-3);
  --line: var(--hairline);
}

/* Dark mode — dark ink foundation with warm paper accents */
:root[data-theme='dark'] {
  --bg: #14110d;
  --bg-2: #1c1813;
  --bg-3: #26211a;
  --fg: #f4ede0;
  --fg-2: #cabca6;
  --fg-3: #9b8f7c;
  --line: #3a3227;
  --signal: #ff5b2e;
  --signal-soft: rgba(255, 91, 46, 0.14);
  --st-active: #6fbf82;
  --st-external: #cabca6;
  --st-designed: #6fa8dc;
  --st-proposed: #d3ad61;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; overflow-x: hidden; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background 0.4s ease, color 0.4s ease;
}

/* Paper grain / grid texture — subtle, drawn not imaged */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    linear-gradient(to right, var(--line) 1px, transparent 1px),
    linear-gradient(to bottom, var(--line) 1px, transparent 1px);
  background-size: 88px 88px;
  opacity: 0.10;
}
:root[data-theme='dark'] body::before { opacity: 0.16; }

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 500;
  line-height: 1.08;
  letter-spacing: -0.01em;
  margin: 0 0 var(--sp-4);
  color: var(--fg);
}
h1 { font-size: var(--text-3xl); }
h2 { font-size: var(--text-2xl); }
h3 { font-size: var(--text-xl); }
p { margin: 0 0 var(--sp-4); max-width: 68ch; }

a { color: var(--fg); text-decoration: none; }
a:hover { color: var(--signal); }

.mono {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--fg-3);
}

/* Layout primitives */
.shell { position: relative; z-index: 1; }
.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 var(--gutter); }
.section { padding: var(--sp-24) 0; }
.section--tight { padding: var(--sp-16) 0; }
.rule { border: 0; border-top: 1px solid var(--line); margin: 0; }

/* Eyebrow / kicker */
.kicker {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--signal);
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  margin-bottom: var(--sp-4);
}
.kicker::before {
  content: '';
  width: 22px; height: 1px; background: var(--signal); display: inline-block;
}

/* ---- Header / nav ---- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar__inner {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp-6); height: 64px;
}
.wordmark { display: inline-flex; align-items: center; gap: var(--sp-3); color: var(--fg); }
.wordmark .mark { color: var(--fg); flex: none; }
.wordmark__text {
  font-family: var(--font-display); font-size: 1.35rem; font-weight: 600;
  letter-spacing: -0.01em;
}
.nav { display: flex; align-items: center; gap: var(--sp-1); }
.nav a {
  font-size: var(--text-sm); color: var(--fg-2);
  padding: var(--sp-2) var(--sp-3); border-radius: var(--radius);
  transition: color 0.2s, background 0.2s;
}
.nav a:hover, .nav a[aria-current='page'] { color: var(--fg); background: var(--bg-3); }
.nav a[aria-current='page'] { box-shadow: inset 0 -2px 0 var(--signal); }

.topbar__tools { display: flex; align-items: center; gap: var(--sp-2); }

.btn {
  font-family: var(--font-body); font-size: var(--text-sm);
  border: 1px solid var(--line); background: transparent; color: var(--fg);
  padding: var(--sp-2) var(--sp-4); border-radius: var(--radius);
  cursor: pointer; display: inline-flex; align-items: center; gap: var(--sp-2);
  transition: border-color 0.2s, background 0.2s, color 0.2s;
}
.btn:hover { border-color: var(--signal); color: var(--signal); }
.btn--signal { background: var(--signal); color: var(--signal-ink); border-color: var(--signal); }
.btn--signal:hover { color: var(--signal-ink); filter: brightness(1.05); }
.btn--icon { padding: var(--sp-2); }

.menu-toggle { display: none; }

/* Focus visibility — universal */
:focus-visible {
  outline: 2px solid var(--signal);
  outline-offset: 3px;
  border-radius: 2px;
}
.skip-link {
  position: absolute; left: var(--sp-4); top: -60px; z-index: 100;
  background: var(--signal); color: var(--signal-ink);
  padding: var(--sp-2) var(--sp-4); border-radius: var(--radius);
  transition: top 0.2s;
}
.skip-link:focus { top: var(--sp-2); color: var(--signal-ink); }

/* ---- Domain switcher (constellation) ---- */
.switcher-backdrop {
  position: fixed; inset: 0; z-index: 90;
  background: color-mix(in srgb, var(--ink) 55%, transparent);
  opacity: 0; visibility: hidden; transition: opacity 0.25s;
}
.switcher-backdrop[data-open='true'] { opacity: 1; visibility: visible; }
.switcher {
  position: fixed; z-index: 91; top: 0; right: 0; height: 100%;
  width: min(460px, 92vw); background: var(--bg-2);
  border-left: 1px solid var(--line);
  transform: translateX(100%); transition: transform 0.3s ease;
  overflow-y: auto; padding: var(--sp-8) var(--sp-6);
}
.switcher[data-open='true'] { transform: translateX(0); }
.switcher h2 { font-size: var(--text-xl); }
.switcher__head { display: flex; justify-content: space-between; align-items: start; margin-bottom: var(--sp-2); }
.switcher__list { list-style: none; margin: var(--sp-6) 0 0; padding: 0; }
.switcher__item {
  border-top: 1px solid var(--line); padding: var(--sp-4) 0;
  display: grid; grid-template-columns: 1fr auto; gap: var(--sp-2) var(--sp-4);
}
.switcher__item a, .switcher__item span.host { font-family: var(--font-mono); font-size: var(--text-xs); }
.switcher__item .surf-name { font-family: var(--font-display); font-size: var(--text-lg); grid-column: 1; }
.switcher__item .surf-sum { grid-column: 1 / -1; color: var(--fg-3); font-size: var(--text-sm); }
.switcher__item .host { color: var(--fg-3); grid-column: 1; }

/* Status chips */
.chip {
  font-family: var(--font-mono); font-size: 0.68rem; letter-spacing: 0.06em;
  text-transform: uppercase; padding: 3px 8px; border-radius: 999px;
  border: 1px solid currentColor; display: inline-flex; align-items: center; gap: 5px;
  white-space: nowrap;
}
.chip::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.chip--active { color: var(--st-active); }
.chip--external { color: var(--st-external); }
.chip--designed { color: var(--st-designed); }
.chip--proposed { color: var(--st-proposed); }

/* ---- Hero ---- */
.hero { padding: var(--sp-24) 0 var(--sp-16); position: relative; }
.hero h1 { font-size: var(--text-hero); font-weight: 500; max-width: 16ch; }
.hero__lede { font-size: var(--text-lg); color: var(--fg-2); max-width: 58ch; margin-top: var(--sp-6); }
.hero__meta {
  display: flex; flex-wrap: wrap; gap: var(--sp-6); margin-top: var(--sp-8);
  padding-top: var(--sp-6); border-top: 1px solid var(--line);
}
.hero__meta .mono { color: var(--fg-3); }

/* ---- Cards / grids ---- */
.grid { display: grid; gap: 1px; background: var(--line); border: 1px solid var(--line); }
.grid--2 { grid-template-columns: repeat(2, 1fr); }
.grid--3 { grid-template-columns: repeat(3, 1fr); }
.grid--4 { grid-template-columns: repeat(4, 1fr); }
.cell {
  background: var(--bg); padding: var(--sp-6);
  display: flex; flex-direction: column; gap: var(--sp-3);
  transition: background 0.2s;
}
a.cell:hover { background: var(--bg-2); }
.cell__idx { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--fg-3); }
.cell h3 { margin: 0; }
.cell p { margin: 0; color: var(--fg-2); font-size: var(--text-sm); }
.cell__foot { margin-top: auto; display: flex; align-items: center; gap: var(--sp-3); font-size: var(--text-sm); }
.cell__arrow { color: var(--signal); font-family: var(--font-mono); }

/* Feature two-column */
.two-col { display: grid; grid-template-columns: 0.9fr 1.1fr; gap: var(--sp-16); align-items: start; }
.stack > * + * { margin-top: var(--sp-4); }

/* Definition list / spec table */
.spec { width: 100%; border-collapse: collapse; }
.spec th, .spec td {
  text-align: left; padding: var(--sp-3) var(--sp-4);
  border-top: 1px solid var(--line); vertical-align: top; font-size: var(--text-sm);
}
.spec th { font-family: var(--font-mono); font-size: var(--text-xs); text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--fg-3); font-weight: 500; width: 34%; }

/* Callout / notice */
.notice {
  border: 1px solid var(--line); border-left: 3px solid var(--signal);
  background: var(--signal-soft); padding: var(--sp-6);
  border-radius: var(--radius); font-size: var(--text-sm);
}
.notice h3 { font-family: var(--font-body); font-size: var(--text-base); font-weight: 600; margin-bottom: var(--sp-2); }

/* Loop diagram (RFPA · AVPT) */
.loop-diagram { width: 100%; height: auto; color: var(--fg); }
.loop-diagram .lp-line { stroke: var(--line); stroke-width: 1; fill: none; }
.loop-diagram .lp-arc { stroke: var(--signal); stroke-width: 1.5; fill: none; }
.loop-diagram .lp-node { fill: var(--bg); stroke: var(--fg); stroke-width: 1.2; }
.loop-diagram text { font-family: var(--font-mono); font-size: 11px; fill: var(--fg); }
.loop-diagram .lp-sub { fill: var(--fg-3); font-size: 9px; }

/* Timeline */
.timeline { position: relative; margin-top: var(--sp-8); }
.tl-row {
  display: grid; grid-template-columns: 130px 1fr; gap: var(--sp-6);
  padding: var(--sp-4) 0; border-top: 1px solid var(--line); align-items: baseline;
}
.tl-date { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--fg-3); }
.tl-cat { display: flex; gap: var(--sp-3); align-items: center; flex-wrap: wrap; }

/* Catalog work */
.work { border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg); padding: var(--sp-8); margin-bottom: var(--sp-6); }
.work__head { display: flex; justify-content: space-between; gap: var(--sp-4); flex-wrap: wrap; align-items: start; }
.work h3 { margin: 0; }
.work__sub { color: var(--fg-3); font-style: italic; }

/* Chapter bars */
.chapters { display: grid; grid-template-columns: repeat(auto-fill, minmax(46px, 1fr)); gap: 4px; margin-top: var(--sp-4); }
.ch-bar { height: 34px; border-radius: 2px; background: var(--bg-3); border: 1px solid var(--line); position: relative; }
.ch-bar[data-spec='true'] { border-style: dashed; border-color: var(--signal); }
.ch-bar[data-kind='ledger'] { background: var(--fg-3); }
.ch-bar[data-kind='front-matter'], .ch-bar[data-kind='prologue'] { background: var(--signal-soft); }

/* Footer */
.footer { border-top: 1px solid var(--line); padding: var(--sp-16) 0 var(--sp-12); background: var(--bg-2); }
.footer__grid { display: grid; grid-template-columns: 1.4fr 1fr 1fr 1fr; gap: var(--sp-8); }
.footer h4 { font-family: var(--font-mono); font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.1em; color: var(--fg-3); font-weight: 500; margin-bottom: var(--sp-4); }
.footer ul { list-style: none; margin: 0; padding: 0; }
.footer li { margin-bottom: var(--sp-2); }
.footer a { color: var(--fg-2); font-size: var(--text-sm); }
.footer a:hover { color: var(--signal); }
.footer__base { display: flex; justify-content: space-between; align-items: center; gap: var(--sp-4); flex-wrap: wrap; margin-top: var(--sp-12); padding-top: var(--sp-6); border-top: 1px solid var(--line); }

/* Page intro */
.page-head { padding: var(--sp-16) 0 var(--sp-8); border-bottom: 1px solid var(--line); }
.page-head h1 { font-size: var(--text-3xl); max-width: 20ch; }
.page-head .hero__lede { margin-top: var(--sp-4); }
.crumb { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--fg-3); margin-bottom: var(--sp-4); }
.crumb a { color: var(--fg-3); }
.crumb a:hover { color: var(--signal); }

/* Master vestibule — deliberately sparse */
.vestibule { min-height: 72vh; display: flex; align-items: center; }
.vestibule__inner { max-width: 720px; }
.vestibule .lock {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  font-family: var(--font-mono); font-size: var(--text-xs); text-transform: uppercase;
  letter-spacing: 0.12em; color: var(--fg-3);
  border: 1px solid var(--line); padding: var(--sp-2) var(--sp-4); border-radius: 999px;
}

/* 404 */
.fourohfour { min-height: 70vh; display: flex; align-items: center; }
.fourohfour .wrap { min-width: 0; max-width: 100%; }
.fourohfour__big { font-family: var(--font-mono); font-size: clamp(4rem, 14vw, 9rem); color: var(--signal); line-height: 1; }
/* Robust wrapping: an arbitrarily long unbroken route/proxy token must never
   cause horizontal overflow at any viewport. */
.route-token {
  display: block;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--fg-2);
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-left: 3px solid var(--signal);
  border-radius: var(--radius);
  padding: var(--sp-3) var(--sp-4);
  margin-top: var(--sp-2);
  max-width: 100%;
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
  white-space: pre-wrap;
  overflow-x: auto;
}

/* Utility */
.muted { color: var(--fg-3); }
.center { text-align: center; }
.flow > * + * { margin-top: var(--sp-6); }
.tags { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.lead-num { font-family: var(--font-display); font-size: var(--text-3xl); color: var(--signal); line-height: 1; }

/* ---- Responsive ---- */
@media (max-width: 900px) {
  .two-col { grid-template-columns: 1fr; gap: var(--sp-8); }
  .grid--4 { grid-template-columns: repeat(2, 1fr); }
  .grid--3 { grid-template-columns: 1fr; }
  .footer__grid { grid-template-columns: 1fr 1fr; gap: var(--sp-6); }
}
@media (max-width: 640px) {
  .nav { display: none; }
  .nav--open {
    display: flex; position: absolute; top: 64px; left: 0; right: 0;
    flex-direction: column; align-items: stretch; gap: 0;
    background: var(--bg-2); border-bottom: 1px solid var(--line); padding: var(--sp-2);
  }
  .nav--open a { padding: var(--sp-3) var(--sp-4); }
  .menu-toggle { display: inline-flex; }
  .grid--4, .grid--2 { grid-template-columns: 1fr; }
  .footer__grid { grid-template-columns: 1fr; }
  .tl-row { grid-template-columns: 1fr; gap: var(--sp-2); }
  .section { padding: var(--sp-16) 0; }
  .hero { padding: var(--sp-16) 0 var(--sp-12); }
}
