/* ============================================================
   Software Development with AI — design system: REDLINE
   ------------------------------------------------------------
   An engineering document that shows its markup. Corrections,
   revision stamps, and verification status are the identity:
   redline red for corrections/links, drafting blue for the
   author's own theses, amber for unverified/vendor claims,
   verification green for sourced/current status marks — the
   brief's provenance rules made visual.
   The ink is deliberately COOL graphite (#1F2328), not the
   corpus's warm ink: drafting-room graphite on drafting paper,
   argued and judge-passed — do not "fix" it warm.
   House rules that survive any redesign:
   - tokens on :root, dark variant re-declares them under .dark
   - reading surface never pure white, ink never pure black
   - one strong accent; further accents carry meaning
   ============================================================ */

:root {
  /* surfaces & ink */
  --c-bg: #F4F1EA;          /* drafting paper — warm print white, never pure */
  --c-surface: #ECE8DD;     /* raised panels, title blocks, table heads */
  --c-ink: #1F2328;         /* graphite ink — near-black, cool (see header) */
  --c-muted: #575D64;       /* secondary text, standfirsts, captions */
  --c-rule: #C8C2B2;        /* hairline rules — pencil guide lines */
  /* accents — each carries meaning, never decoration */
  --c-accent: #A8402F;      /* THE redline — corrections, links, primary accent */
  --c-accent-soft: #C0664E;
  --redline: var(--c-accent);
  --blueline: #2F5A75;      /* drafting blue — the author's own theses, distinct from consensus */
  --amber: #7D5711;         /* caution — unverified claims, vendor marketing (darkened for AA at loop round 1) */
  --verify: #2F6B4F;        /* verification green — sourced/current status marks */
  /* type */
  --font-display: "IBM Plex Serif", Georgia, serif;
  --font-body: "Source Serif 4", Georgia, serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
  --font-ui: "IBM Plex Mono", ui-monospace, monospace; /* mono carries the chrome — no grotesk */
  /* layout */
  --measure: 34rem;
  --rail: 16.5rem;
  --page: 72rem;
}

html.dark {
  --c-bg: #15181B;          /* the drafting room after hours — re-lit, not inverted */
  --c-surface: #1C2126;
  --c-ink: #E3DFD5;
  --c-muted: #9BA1A8;
  --c-rule: #363C44;
  --c-accent: #D4715C;
  --c-accent-soft: #B85E45;
  --blueline: #7FA8C4;
  --amber: #D0A355;
  --verify: #74AE90;
}

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

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  /* Seat the footer at the bottom on short pages — without this, a 404 at
     800px tall ends with the colophon mid-viewport and bare paper below. */
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--c-bg);
  color: var(--c-ink);
  font-family: var(--font-body);
  font-optical-sizing: auto;
  font-size: 1.0625rem;
  line-height: 1.65;
  /* paper grain — tiled feTurbulence, opacity baked in, never position:fixed */
  background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="240" height="240"><filter id="g"><feTurbulence type="fractalNoise" baseFrequency="0.9" numOctaves="2"/><feColorMatrix values="0 0 0 0 0.5 0 0 0 0 0.48 0 0 0 0 0.44 0 0 0 0.045 0"/></filter><rect width="240" height="240" filter="url(%23g)"/></svg>');
}

body > main { flex: 1 0 auto; }

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1.2;
  text-wrap: balance;
}

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

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__right { display: flex; align-items: center; gap: 1.4rem; }
.masthead__links { display: flex; align-items: center; gap: 1.1rem; }
.masthead__actions { display: flex; align-items: center; gap: 0.6rem; }

.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; }
  /* the toggle and burger stay side by side and always visible */
  .masthead__right { gap: 0.6rem; }
}

/* ---------- 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; }

/* ---------- 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; }
}

/* ============================================================
   REDLINE apparatus — masthead, hero, essay index, essay page,
   provenance devices, synthesis tables. Promoted from the
   judge-passed design.html mock; drift from it is unapproved.
   ============================================================ */

/* ---------- masthead (Redline overrides) ---------- */

.masthead { border-bottom: 2px solid var(--c-ink); background: transparent; }
.wordmark {
  font-family: var(--font-mono); font-weight: 600; font-size: .85rem;
  letter-spacing: .08em; text-transform: uppercase; color: var(--c-ink);
}
.wordmark__tick { color: var(--c-accent); }
.navlink {
  font-family: var(--font-mono); font-size: .78rem; letter-spacing: .06em;
  text-transform: uppercase; color: var(--c-muted);
}
.navlink:hover { color: var(--c-accent); }

/* ---------- home hero + title block ---------- */

.home-hero {
  max-width: var(--page); margin: 0 auto; padding: 4.5rem 1.25rem 3rem;
  display: grid; grid-template-columns: minmax(0,1fr) 19rem; gap: 3rem; align-items: end;
}
.home-hero h1 {
  font-family: var(--font-display); font-weight: 700; margin: 0;
  font-size: clamp(2.6rem, 6vw, 4.4rem); line-height: 1.04; letter-spacing: -0.015em;
  text-wrap: balance;
}
.home-hero h1 .strike { position: relative; white-space: nowrap; }
.home-hero h1 .strike::after {
  content: ""; position: absolute; left: -1%; right: -1%; top: 54%; height: 3px;
  background: var(--c-accent); transform: rotate(-1.2deg);
}
.home-hero h1 .redink { color: var(--c-accent); }
.home-hero .standfirst { margin: 1.4rem 0 0; font-size: 1.15rem; color: var(--c-muted); max-width: 36rem; }

.title-block {
  border: 1.5px solid var(--c-ink); background: var(--c-surface);
  font-family: var(--font-mono); font-size: .74rem; line-height: 1.5;
}
.title-block .tb-row { display: flex; border-bottom: 1px solid var(--c-rule); }
.title-block .tb-row:last-child { border-bottom: none; }
.title-block .tb-k {
  flex: 0 0 6.2rem; padding: .45rem .6rem; color: var(--c-muted);
  letter-spacing: .05em; text-transform: uppercase; font-size: .64rem;
  border-right: 1px solid var(--c-rule);
}
.title-block .tb-v { padding: .45rem .6rem; }
.title-block .ok, .rev-stamp .ok { color: var(--verify); font-weight: 600; }

/* ---------- essay index (home) ---------- */

.index { max-width: var(--page); margin: 0 auto; padding: 1rem 1.25rem 4rem; }
.section-rule {
  display: flex; align-items: baseline; gap: 1rem; margin-bottom: .4rem;
  font-family: var(--font-mono); font-size: .72rem; letter-spacing: .1em;
  text-transform: uppercase; color: var(--c-muted);
}
.section-rule::after { content: ""; flex: 1; border-top: 1px solid var(--c-rule); }
.essay-row {
  display: grid; grid-template-columns: 4.5rem minmax(0,1fr) 13rem; gap: 1.5rem;
  padding: 1.35rem 0; border-bottom: 1px solid var(--c-rule); align-items: baseline;
}
.essay-row:hover .er-title { color: var(--c-accent); }
.er-no { font-family: var(--font-mono); font-weight: 500; font-size: 1.5rem; color: var(--c-accent); }
.er-no sup { font-size: .6rem; color: var(--c-muted); letter-spacing: .05em; }
.er-title {
  font-family: var(--font-display); font-weight: 600; font-size: 1.45rem;
  line-height: 1.2; color: var(--c-ink); transition: color .15s;
}
a.essay-row { text-decoration: none; }
.er-sub { margin: .3rem 0 0; color: var(--c-muted); font-size: .95rem; max-width: 34rem; }
.er-meta {
  font-family: var(--font-mono); font-size: .74rem; color: var(--c-muted);
  text-align: right; letter-spacing: .04em; align-self: start; padding-top: .5rem;
}

/* ---------- essay page frame ---------- */

.page { max-width: var(--page); margin: 0 auto; padding: 3.2rem 1.25rem 4rem; }
.kicker {
  font-family: var(--font-mono); font-size: .72rem; letter-spacing: .12em;
  text-transform: uppercase; color: var(--c-accent); font-weight: 500; margin: 0;
}
.kicker .sep { color: var(--c-rule); margin: 0 .5rem; }
.kicker .rev { color: var(--c-muted); }
.essay-title {
  font-family: var(--font-display); font-weight: 700; letter-spacing: -0.01em;
  font-size: clamp(2.1rem, 4.5vw, 3.2rem); line-height: 1.08; margin: .7rem 0 1rem;
  max-width: 44rem; text-wrap: balance;
}
.essay-standfirst { font-size: 1.14rem; color: var(--c-muted); max-width: 40rem; margin: 0 0 2.4rem; }
.essay-grid { display: grid; grid-template-columns: var(--rail) minmax(0, var(--measure)); gap: 4rem; }
.essay-grid .prose { margin: 0; padding: 0; max-width: var(--measure); }

.rail { font-family: var(--font-mono); font-size: .74rem; }
.rail .rail-h {
  letter-spacing: .1em; text-transform: uppercase; color: var(--c-muted);
  font-size: .64rem; margin-bottom: .8rem; padding-bottom: .5rem; border-bottom: 1px solid var(--c-rule);
}
.rail ol { list-style: none; margin: 0; padding: 0; }
.rail li { margin: 0 0 .55rem; line-height: 1.45; }
.rail li a { color: var(--c-muted); text-decoration: none; }
.rail li a:hover { color: var(--c-accent); }
.rail li.active a { color: var(--c-accent); font-weight: 600; }
.rail li .no { color: var(--c-rule); margin-right: .4rem; }
.rev-stamp {
  margin-top: 2rem; border: 1px solid var(--c-rule); padding: .7rem .8rem;
  font-size: .68rem; line-height: 1.6; color: var(--c-muted);
}

/* ---------- essay prose apparatus ---------- */

.essay-prose > p:first-of-type::first-line { font-variant-caps: small-caps; letter-spacing: .03em; }
.essay-prose h2 {
  font-family: var(--font-display); font-weight: 600; font-size: 1.45rem;
  margin: 2.4rem 0 .9rem; padding-top: 1.2rem; border-top: 1px solid var(--c-rule);
  display: flex; gap: .8rem; align-items: baseline;
}
.essay-prose h2 .sec {
  font-family: var(--font-mono); font-size: .78rem; color: var(--c-accent);
  font-weight: 500; letter-spacing: .05em;
}
.essay-prose ul, .essay-prose ol { padding-left: 1.3rem; }
.essay-prose li { margin-bottom: .45rem; }

/* inline source citation — every figure carries one */
.cite {
  font-family: var(--font-mono); font-size: .72em; color: var(--c-muted);
  background: color-mix(in srgb, var(--verify) 9%, transparent);
  border-bottom: 1px dotted var(--verify);
  padding: .05em .3em; border-radius: 2px; white-space: nowrap;
}
@media (max-width: 700px) {
  /* chips must never force the page wider than a phone */
  .cite { white-space: normal; overflow-wrap: anywhere; }
}
/* caution badge — vendor / unverified / contested claims */
.badge-flag {
  font-family: var(--font-mono); font-size: .62rem; font-weight: 600;
  letter-spacing: .07em; text-transform: uppercase; color: var(--amber);
  border: 1px solid color-mix(in srgb, var(--amber) 55%, transparent);
  padding: .1em .4em; border-radius: 2px; white-space: nowrap; vertical-align: .1em;
}
/* the author's-position box — drafting blue, signed */
.thesis {
  border-left: 3px solid var(--blueline);
  background: color-mix(in srgb, var(--blueline) 7%, transparent);
  padding: 1rem 1.2rem; margin: 1.6rem 0;
}
.thesis .thesis-k {
  font-family: var(--font-mono); font-size: .64rem; font-weight: 600;
  letter-spacing: .1em; text-transform: uppercase; color: var(--blueline);
  display: block; margin-bottom: .45rem;
}
.thesis p { font-size: .98rem; margin: 0 0 .6rem; }
.thesis p:last-child { margin-bottom: 0; }
/* correction — the redline device itself */
.correction {
  border-left: 3px solid var(--c-accent);
  background: color-mix(in srgb, var(--c-accent) 6%, transparent);
  padding: 1rem 1.2rem; margin: 1.6rem 0; font-size: .98rem;
}
.correction .corr-k {
  font-family: var(--font-mono); font-size: .64rem; font-weight: 600;
  letter-spacing: .1em; text-transform: uppercase; color: var(--c-accent);
  display: block; margin-bottom: .45rem;
}
.correction p { margin: 0 0 .6rem; }
.correction p:last-child { margin-bottom: 0; }
.correction .was {
  text-decoration: line-through; text-decoration-color: var(--c-accent);
  text-decoration-thickness: 1.5px; color: var(--c-muted);
}

/* diagrams — inline SVG keyed to tokens */
figure.diagram { margin: 2rem 0; position: relative; }
figure.diagram .diagram-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
figure.diagram svg { width: 100%; height: auto; display: block; }
figure.diagram figcaption {
  font-family: var(--font-mono); font-size: .68rem; color: var(--c-muted);
  margin-top: .6rem; letter-spacing: .03em;
}
figure.diagram .scroll-hint { display: none; color: var(--c-accent); }
@media (max-width: 900px) {
  figure.diagram svg { min-width: 560px; }
  figure.diagram .scroll-hint { display: inline; }
  figure.diagram .diagram-scroll::after {
    content: ""; position: absolute; top: 0; right: 0; bottom: 1.6rem; width: 2.5rem;
    background: linear-gradient(to right, transparent, var(--c-bg));
    pointer-events: none;
  }
}

/* sources block */
.sources-list { font-size: .92rem; }
.sources-list li { margin-bottom: .55rem; }
.sources-list .src-date { font-family: var(--font-mono); font-size: .78em; color: var(--c-muted); }

/* prev/next pager */
.pager {
  display: flex; justify-content: space-between; gap: 1rem; margin-top: 3rem;
  padding-top: 1.2rem; border-top: 2px solid var(--c-ink);
}
.pager a { font-family: var(--font-mono); font-size: .76rem; text-decoration: none; color: var(--c-muted); }
.pager a b { color: var(--c-accent); font-weight: 600; display: block; font-size: .86rem; margin-top: .2rem; }
.pager a:last-child { text-align: right; }

/* ---------- synthesis apparatus ---------- */

.theses-list { list-style: none; counter-reset: th; padding: 0 !important; margin: 1rem 0 0; }
.theses-list > li {
  counter-increment: th; display: grid; grid-template-columns: 3.6rem minmax(0,1fr);
  gap: 1.2rem; padding: 1.15rem 0; border-bottom: 1px solid var(--c-rule); margin: 0;
}
.theses-list > li::before {
  content: counter(th, decimal-leading-zero);
  font-family: var(--font-mono); font-size: 1.35rem; color: var(--c-accent);
}
.theses-list b {
  font-family: var(--font-display); font-weight: 600; font-size: 1.12rem;
  display: block; margin-bottom: .25rem;
}
.theses-list p { font-size: .97rem; color: var(--c-muted); margin: 0 0 .5rem; }
.theses-list p:last-child { margin-bottom: 0; }

table.problems { width: 100%; border-collapse: collapse; margin: 1.4rem 0; font-size: .93rem; }
table.problems th {
  font-family: var(--font-mono); font-size: .64rem; letter-spacing: .09em;
  text-transform: uppercase; color: var(--c-muted); text-align: left;
  background: var(--c-surface); padding: .55rem .7rem; border: 1px solid var(--c-rule);
}
table.problems td { padding: .65rem .7rem; border: 1px solid var(--c-rule); vertical-align: top; }
.status {
  font-family: var(--font-mono); font-size: .62rem; font-weight: 600;
  letter-spacing: .07em; text-transform: uppercase; padding: .12em .45em; border-radius: 2px;
  white-space: nowrap;
}
.status.open { color: var(--amber); border: 1px solid color-mix(in srgb, var(--amber) 55%, transparent); }
.status.partial { color: var(--blueline); border: 1px solid color-mix(in srgb, var(--blueline) 55%, transparent); }
.status.measured { color: var(--verify); border: 1px solid color-mix(in srgb, var(--verify) 55%, transparent); }

/* comparison tables inside essays (horizontal vs vertical etc.) */
.essay-prose table:not(.problems) { border-collapse: collapse; width: 100%; margin: 1.4rem 0; font-size: .93rem; }
.essay-prose table:not(.problems) th {
  font-family: var(--font-mono); font-size: .64rem; letter-spacing: .09em;
  text-transform: uppercase; color: var(--c-muted); text-align: left;
  background: var(--c-surface); padding: .55rem .7rem; border: 1px solid var(--c-rule);
}
.essay-prose table:not(.problems) td { padding: .65rem .7rem; border: 1px solid var(--c-rule); vertical-align: top; }

/* ---------- colophon (Redline overrides) ---------- */

.colophon { border-top: 2px solid var(--c-ink); }
.colophon__inner {
  font-family: var(--font-mono); font-size: .7rem; color: var(--c-muted);
  display: flex; justify-content: space-between; gap: 1.5rem 2rem; flex-wrap: wrap;
  align-items: baseline;
}
.colophon__disclose, .colophon__rev { margin: 0; }
.colophon__disclose b { color: var(--c-accent); font-weight: 600; }
.colophon__disclose a { color: var(--c-muted); }
.colophon__links { gap: 1.1rem; }

/* home figure + index row internals */
.home-fig { max-width: 48rem; margin: 0 auto; padding: 0 1.25rem; }
.er-body { display: block; }
.er-title { display: block; }
.er-sub { display: block; margin-top: .3rem; color: var(--c-muted); font-size: .95rem; max-width: 34rem; }

/* ---------- responsive ---------- */

@media (max-width: 900px) {
  .home-hero { grid-template-columns: 1fr; gap: 2rem; padding-top: 3rem; }
  .title-block { max-width: 24rem; }
  .essay-grid { grid-template-columns: minmax(0, 1fr); gap: 2rem; }
  .rail { order: -1; }
  /* keep § anchors reachable on phones: contents render as wrapped chips */
  .rail ol { display: flex; flex-wrap: wrap; gap: .3rem .9rem; }
  .rail li { margin: 0; }
  .rev-stamp { margin-top: 1rem; }
  .essay-row { grid-template-columns: 3rem minmax(0,1fr); }
  .er-meta { display: none; }
}
