/* ============================================================
   AI Factories — design system: SWITCHBOARD
   ------------------------------------------------------------
   The site's central claim: "the hard, skilled job is deciding
   where each switch goes." Every device derives from the
   lit/dark switch. Light mode IS the lit factory (warm work
   lights over concrete, engineering grid); dark mode IS the
   lights-out floor (the grid fades, machines glow as indicator
   LEDs, human-judgment elements keep a warm lamp glow). Two
   accents, two actors: lamp amber = human judgment; machine
   steel-blue = automated verification. Vendor-reported claims
   are deliberately colorless. Record: specs/design.md.
   ============================================================ */

:root {
  /* lit factory — work lights on */
  --c-bg: #F2EEE3;          /* work-lit concrete, warm — never pure white */
  --c-surface: #FAF7EF;     /* raised panel / card */
  --c-ink: #201D16;         /* warm ink — never pure black */
  --c-muted: #5B5546;
  --c-rule: #D9D2BF;
  /* the two actors */
  --c-accent: #B4690E;      /* THE accent — the work lamp: human judgment, lit gates, links */
  --c-accent-soft: #8F5716; /* hover state of the lamp */
  --lamp: var(--c-accent);
  --machine: #2F5D7C;       /* machine verification: gauges, § anchors, measured claims */
  --ok: #3E6B4A;            /* green oracle — checks pass */
  --danger: #96341F;        /* red oracle — never-dark gates; the AS-OF stamp */
  --lamp-glow: rgba(180, 105, 14, 0.0);  /* glow only exists at night */
  --grid: rgba(32, 29, 22, 0.055);       /* engineering grid wash */
  --shadow: 0 1px 2px rgba(32,29,22,.06), 0 8px 24px rgba(32,29,22,.07);
  /* type */
  --font-display: "Big Shoulders Display", "Arial Narrow", sans-serif;
  --font-body: "Newsreader", Georgia, serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;
  --font-ui: "JetBrains Mono", ui-monospace, monospace; /* chrome speaks mono here */
  /* layout */
  --measure: 46rem;         /* textbook measure, wider than the reading editions */
  --page: 72rem;
}

html.dark {
  /* dark factory — lights out, machines see without light.
     Deliberately NOT a re-lit same world (departure argued in
     specs/design.md): same hall, lights off. */
  --c-bg: #131412;          /* unlit floor */
  --c-surface: #1B1D1A;     /* machine housing */
  --c-ink: #D6D2C4;
  --c-muted: #8F8B7C;
  --c-rule: #2A2C27;
  --c-accent: #E09B3D;      /* sodium work lamp — the human's island of light */
  --c-accent-soft: #C9882F;
  --machine: #6FA7C4;       /* indicator LED */
  --ok: #6FA47F;
  --danger: #C4674F;
  --lamp-glow: rgba(224, 155, 61, 0.14);  /* lit gates keep a real glow */
  --grid: rgba(214, 210, 196, 0.04);      /* the grid almost disappears */
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
}

/* ---------- base ---------- */

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background-color: var(--c-bg);
  /* engineering grid + tiled feTurbulence grain (opacity baked into the SVG
     rect; tiled as background-image, never position:fixed — fixed layers
     seam-band in the shots harness's stitched captures) */
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='240' height='240' filter='url(%23n)' opacity='0.05'/%3E%3C/svg%3E"),
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 240px 240px, 34px 34px, 34px 34px;
  color: var(--c-ink);
  font-family: var(--font-body);
  font-size: 1.0625rem;
  line-height: 1.65;
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: 0.005em;
  text-transform: uppercase;
  text-wrap: balance;
}

a { color: var(--c-accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--c-accent-soft); }

code, pre, .data { font-family: var(--font-mono); font-size: 0.9em; }

.skip-link {
  position: absolute; left: -999px; top: 0;
  background: var(--c-accent); color: var(--c-bg); padding: 0.5rem 1rem;
}
.skip-link:focus { left: 0; z-index: 10; }

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

.masthead { border-bottom: 1px solid var(--c-rule); }

.masthead__inner {
  max-width: var(--page); margin: 0 auto; padding: 0.9rem 1.25rem;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
}

.brand { text-decoration: none; color: var(--c-ink); }
.brand__title { font-family: var(--font-display); font-size: 1.15rem; font-weight: 600; }

.masthead__links { display: flex; align-items: center; gap: 1.1rem; }

.navlink {
  font-family: var(--font-ui); font-size: 0.95rem;
  color: var(--c-ink); text-decoration: none;
}
.navlink:hover { color: var(--c-accent); }

.masthead__burger { display: none; }

.theme-toggle {
  background: none; border: 1px solid var(--c-rule); border-radius: 999px;
  width: 2.1rem; height: 2.1rem; padding: 0.35rem; cursor: pointer; color: var(--c-ink);
}
.theme-toggle svg { width: 100%; height: 100%; }
.theme-toggle__moon { display: none; }
html.dark .theme-toggle__sun { display: none; }
html.dark .theme-toggle__moon { display: block; }

@media (max-width: 40rem) {
  .masthead__burger {
    display: flex; flex-direction: column; gap: 4px;
    background: none; border: none; padding: 0.4rem; cursor: pointer;
  }
  .masthead__burger span { width: 20px; height: 2px; background: var(--c-ink); }
  .masthead__links {
    display: none; position: absolute; right: 1rem; top: 3.4rem;
    flex-direction: column; align-items: flex-end; gap: 0.8rem;
    background: var(--c-surface); border: 1px solid var(--c-rule);
    border-radius: 6px; padding: 1rem 1.25rem; z-index: 20;
  }
  .masthead__links.is-open { display: flex; }
}

/* ---------- content ---------- */

.hero { max-width: var(--measure); margin: 3.5rem auto 1rem; padding: 0 1.25rem; }
.hero__title { font-size: clamp(2rem, 6vw, 3.2rem); margin: 0 0 0.5rem; }
.hero__dek { color: var(--c-muted); font-size: 1.15rem; margin: 0; }

.prose { max-width: var(--measure); margin: 2rem auto 4rem; padding: 0 1.25rem; }
.prose h1 { font-size: clamp(1.7rem, 5vw, 2.4rem); }
.prose img { max-width: 100%; height: auto; }
.prose blockquote {
  margin: 1.5rem 0; padding: 0.25rem 0 0.25rem 1.1rem;
  border-left: 3px solid var(--c-accent); color: var(--c-muted); font-style: italic;
}
.prose table { border-collapse: collapse; width: 100%; }
.prose th, .prose td { border-bottom: 1px solid var(--c-rule); padding: 0.4rem 0.6rem; text-align: left; }
.prose th { font-family: var(--font-ui); font-size: 0.85rem; }

/* ---------- colophon ---------- */

.colophon { border-top: 1px solid var(--c-rule); margin-top: 2rem; }
.colophon__inner {
  max-width: var(--page); margin: 0 auto; padding: 2rem 1.25rem 2.5rem;
  font-family: var(--font-ui); font-size: 0.9rem; color: var(--c-muted);
}
.colophon__title { font-family: var(--font-display); color: var(--c-ink); margin: 0 0 0.5rem; }
.colophon__links { display: flex; flex-wrap: wrap; gap: 1rem; }
.colophon__links a { color: var(--c-muted); }
.colophon__foot { margin-top: 1.25rem; }

/* ---------- Switchboard components ---------- */

/* kicker — mono, power-glyph, lamp */
.kicker {
  font-family: var(--font-mono); font-size: 0.74rem; font-weight: 700;
  letter-spacing: 0.22em; text-transform: uppercase; color: var(--c-accent);
  margin: 0 0 1rem;
}
.kicker::before { content: "\23FB\00a0"; }

/* claim-class badges — the provenance rules made visible */
.badge {
  display: inline-block; font-family: var(--font-mono); font-size: 0.64rem;
  font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase;
  padding: 0.14rem 0.5rem; border-radius: 3px; vertical-align: 0.12em;
}
.badge--measured { color: var(--machine); border: 1px solid var(--machine); }
.badge--vendor   { color: var(--c-muted); border: 1px dashed var(--c-muted); }
.badge--ours     { color: var(--c-accent); border: 1px solid var(--c-accent); }

/* lampbox — our-experience / human-judgment aside; glows in the dark */
.lampbox {
  border: 1px solid var(--c-accent); border-left-width: 4px; border-radius: 6px;
  background: var(--c-surface); padding: 1.1rem 1.3rem; margin: 2rem 0;
  box-shadow: 0 0 0 4px var(--lamp-glow), 0 0 28px 4px var(--lamp-glow);
}
.lampbox .badge { margin-bottom: 0.5rem; }
.lampbox p { font-size: 0.98rem; margin: 0.4rem 0 0; }

/* AS-OF stamp — volatile-content marker */
.stamp {
  display: inline-block; font-family: var(--font-mono); font-weight: 700;
  font-size: 0.78rem; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--danger); border: 2px solid var(--danger); border-radius: 4px;
  padding: 0.4rem 0.9rem; transform: rotate(-1.5deg); margin: 0 0 1.6rem;
}

/* chapter apparatus */
.chapno {
  font-family: var(--font-display); font-weight: 800; font-size: 5rem;
  line-height: 1; color: var(--c-accent); display: block;
}
.anchor {
  font-family: var(--font-mono); color: var(--machine); font-size: 0.78rem;
  font-weight: 700; letter-spacing: 0.1em; margin-right: 0.6rem;
  text-decoration: none;
}
a.anchor:hover { color: var(--machine); text-decoration: underline; }
.dropcap::first-letter {
  font-family: var(--font-display); font-weight: 800; font-size: 3.4em;
  float: left; line-height: 0.82; padding-right: 0.12em; color: var(--c-accent);
}
.pull {
  border-left: 4px solid var(--machine); padding: 0.4rem 0 0.4rem 1.4rem;
  margin: 2rem 0; font-size: 1.3rem; line-height: 1.4; font-style: italic;
}
.pull .pull__who {
  display: block; font-family: var(--font-mono); font-style: normal;
  font-size: 0.68rem; letter-spacing: 0.14em; color: var(--c-muted);
  margin-top: 0.6rem; text-transform: uppercase;
}
.prevnext {
  display: flex; justify-content: space-between; gap: 1rem;
  border-top: 1px solid var(--c-rule); margin-top: 3.5rem; padding-top: 1.2rem;
  font-family: var(--font-mono); font-size: 0.8rem; letter-spacing: 0.06em;
}

/* token-keyed inline SVG diagrams */
figure.diagram {
  margin: 2.4rem 0; border: 1px solid var(--c-rule); border-radius: 6px;
  background: var(--c-surface); padding: 1.4rem 1.2rem 0.6rem;
  box-shadow: var(--shadow);
}
/* Each diagram ships a wide and a narrow SVG variant; CSS picks one. The
   narrow variants restack vertically so nothing clips or needs scrolling. */
figure.diagram svg { display: block; width: 100%; height: auto; }
figure.diagram svg.dg-narrow { display: none; max-width: 26rem; margin: 0 auto; }
@media (max-width: 40rem) {
  figure.diagram svg.dg-wide { display: none; }
  figure.diagram svg.dg-narrow { display: block; }
}
figure.diagram svg text { font-family: var(--font-mono); fill: var(--c-ink); }
figure.diagram figcaption {
  font-family: var(--font-mono); font-size: 0.68rem; letter-spacing: 0.08em;
  color: var(--c-muted); text-align: right; padding: 0.5rem 0.2rem 0.4rem;
}

/* hero plate — the one generated image; intrinsically lit, same in both themes */
figure.plate {
  margin: 0; border: 1px solid var(--c-rule); border-radius: 8px;
  overflow: hidden; box-shadow: var(--shadow); background: var(--c-surface);
}
figure.plate img {
  display: block; width: 100%; aspect-ratio: 2 / 1; height: auto;
  object-fit: cover;
}
figure.plate figcaption {
  font-family: var(--font-mono); font-size: 0.68rem; letter-spacing: 0.08em;
  color: var(--c-muted); padding: 0.6rem 0.9rem; border-top: 1px solid var(--c-rule);
}

/* home hero grid */
.factory-hero {
  max-width: var(--page); margin: 3.5rem auto 0; padding: 0 1.25rem;
  display: grid; grid-template-columns: 1.05fr 0.95fr; gap: 3rem; align-items: center;
}
.factory-hero h1 {
  font-size: clamp(2.6rem, 6vw, 4.6rem); margin: 0;
}
.factory-hero h1 .off { color: var(--c-muted); opacity: 0.55; }
.factory-hero .lede { font-size: 1.18rem; margin-top: 1.3rem; max-width: 34rem; }
.factory-hero .lede strong { color: var(--c-accent); font-weight: 600; }

/* wide sections on index-style pages */
.wide { max-width: var(--page); margin: 0 auto; padding: 0 1.25rem; }

/* chapter index cards */
.cards {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem;
  margin: 2rem 0 3rem; padding: 0; list-style: none;
}
.card {
  border: 1px solid var(--c-rule); border-radius: 6px; background: var(--c-surface);
  padding: 1.1rem 1.2rem 1rem; box-shadow: var(--shadow);
}
.card:hover { border-color: var(--c-accent); }
.card a { text-decoration: none; color: inherit; display: block; }
.card .card__no {
  font-family: var(--font-display); font-weight: 800; font-size: 2.4rem;
  line-height: 1; color: var(--c-accent); display: block;
}
.card h3 { font-size: 1.2rem; margin: 0.25rem 0 0.35rem; }
.card p { font-size: 0.92rem; color: var(--c-muted); line-height: 1.45; margin: 0; }

/* fact cards (snapshot chapter) */
.facts {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem;
  margin: 2rem 0; padding: 0; list-style: none;
}
.fact {
  border: 1px solid var(--c-rule); border-radius: 6px; background: var(--c-surface);
  padding: 1.1rem 1.2rem; box-shadow: var(--shadow); font-size: 0.95rem;
  line-height: 1.5;
}
.fact--vendor { border-style: dashed; }
.fact .fact__num {
  font-family: var(--font-display); font-weight: 800; font-size: 2.4rem;
  line-height: 1; display: block; margin: 0.35rem 0 0.3rem;
}
.fact--measured .fact__num { color: var(--machine); }
.fact--vendor .fact__num { color: var(--c-muted); }
.fact--ours .fact__num { color: var(--c-accent); }
.fact .fact__src {
  display: block; font-family: var(--font-mono); font-size: 0.66rem;
  letter-spacing: 0.08em; color: var(--c-muted); margin-top: 0.6rem;
}

/* glossary + updates */
.term { margin: 2.2rem 0; }
.term h3 { font-size: 1.35rem; margin: 0 0 0.3rem; }
.term .term__src {
  font-family: var(--font-mono); font-size: 0.68rem; letter-spacing: 0.08em;
  color: var(--c-muted); display: block; margin-bottom: 0.4rem;
}
.term p { margin: 0.3rem 0 0; }
.update { border-top: 1px solid var(--c-rule); padding: 1.6rem 0 0.4rem; margin-top: 1.6rem; }
.update .update__date {
  font-family: var(--font-mono); font-size: 0.72rem; letter-spacing: 0.12em;
  color: var(--danger); text-transform: uppercase;
}
.update h3 { margin: 0.3rem 0 0.5rem; }

/* gate table (c4) */
.gates { border-collapse: collapse; width: 100%; margin: 2rem 0; }
.gates th, .gates td { border-bottom: 1px solid var(--c-rule); padding: 0.55rem 0.6rem; text-align: left; vertical-align: top; }
.gates th { font-family: var(--font-mono); font-size: 0.72rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--c-muted); }
.gates .gate--dark td:first-child { color: var(--machine); font-family: var(--font-mono); font-size: 0.8rem; }
.gates .gate--lit td:first-child { color: var(--c-accent); font-family: var(--font-mono); font-size: 0.8rem; }

@media (max-width: 56rem) {
  .factory-hero { grid-template-columns: 1fr; gap: 2rem; }
  .cards, .facts { grid-template-columns: 1fr; }
}

/* ---------- motion & print floor (non-negotiable) ---------- */

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

@media print {
  .masthead, .colophon, .theme-toggle, .skip-link { display: none; }
  body { background: #fff; color: #000; }
}
