/* ============================================================
   Psychology of Intelligence Analysis — design system: SECOND READING
   ------------------------------------------------------------
   The book's thesis is that the same evidence, read a second time
   through a different mindset, says something different. The site
   is itself a second reading of the book, so every page is built
   as a working paper with an apparatus:

     - a CITATION RAIL beside the measure, carrying chapter, page
       and minutes. The brief's provenance rule made visible: you
       can scan the left edge and see the sourcing without reading
       a word.
     - ACCENT AS CONTENT DEVICE. Three accents, one meaning each,
       no decorative use:
         mulberry  --accent  the book: nav, part numbers, links
         ink-blue  --source  Heuer's verbatim words + citations
         rust      --trap    a named bias *with* its mechanism

   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
   Full argument and token record: specs/design.md
   ============================================================ */

:root {
  /* --- ground & ink: bond paper under a desk lamp --- */
  --paper:      #F0EDE6;  /* warm bond stock, never white */
  --surface:    #E7E2D7;  /* cards, table stripes, rail wash */
  --ink:        #1D1B16;  /* warm near-black, never #000 */
  --ink-soft:   #55503F;  /* secondary prose, captions */
  --ink-faint:  #6B6555;  /* rail labels — 4.96:1 on paper, AA */
  --rule:       #CFC8B6;  /* hairlines */

  /* --- semantic accents --- */
  --accent:     #6B3B62;  /* MULBERRY — the book */
  --accent-ink: #5A3153;  /* mulberry, pressed */
  --source:     #2F5171;  /* INK-BLUE — Heuer verbatim + its citation */
  --trap:       #9C4A2A;  /* RUST — a named bias and its mechanism */
  --wash-source:#E3E6EC;
  --wash-trap:  #EFE3D9;

  /* --- type --- */
  --font-display: "Petrona", 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, deliberately */

  /* --- measure, rail, page --- */
  --measure: 36rem;
  --rail:    11.5rem;
  --gap:     2.75rem;
  --page:    72rem;

  /* --- template aliases: keep the skeleton's class contract working --- */
  --c-bg: var(--paper);
  --c-surface: var(--surface);
  --c-ink: var(--ink);
  --c-muted: var(--ink-soft);
  --c-rule: var(--rule);
  --c-accent: var(--accent);
  --c-accent-soft: var(--accent-ink);

  color-scheme: light;
}

html.dark {
  /* Re-lit, not inverted: the same desk after dark, one lamp on. */
  --paper:      #16150F;
  --surface:    #201E17;
  --ink:        #E9E3D4;
  --ink-soft:   #B3AB95;
  --ink-faint:  #918A70;
  --rule:       #3A3529;

  --accent:     #C98BBD;
  --accent-ink: #DDA7D2;
  --source:     #82ACD2;
  --trap:       #D8825F;
  --wash-source:#1B222B;
  --wash-trap:  #251B14;

  color-scheme: dark;
}

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

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

html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background-color: var(--paper);
  /* Paper grain tiled as a background-image — never a fixed overlay; fixed
     layers seam-band in the shots harness's stitched full-page captures. */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)' opacity='0.05'/%3E%3C/svg%3E");
  background-blend-mode: multiply;
  background-size: 200px 200px;
  color: var(--ink);
  font-family: var(--font-body);
  font-optical-sizing: auto;
  font-size: clamp(1.02rem, 0.98rem + 0.22vw, 1.14rem);
  line-height: 1.66;
  font-variant-numeric: oldstyle-nums;
}

/* Dark needs its OWN grain. Opacity is baked into the SVG rect (corpus rule:
   0.04–0.05 in light). Dark blends `screen` instead of `multiply`, and a field
   much stronger than this lifts the near-black ground to charcoal — the dark
   theme stops being dark. 0.09 is the most it takes before that happens. */
html.dark body {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)' opacity='0.09'/%3E%3C/svg%3E");
  background-blend-mode: screen;
}

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

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

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

.skip-link {
  position: absolute; left: -999px; top: 0;
  background: var(--accent); color: var(--paper); padding: 0.5rem 1rem;
  font-family: var(--font-mono); font-size: 0.8rem;
}
.skip-link:focus { left: 0; z-index: 30; }

/* ---------- masthead: a working paper's running head ---------- */

.masthead {
  border-bottom: 1px solid var(--rule);
  position: sticky; top: 0; z-index: 20;
  /* Inherit body's grain so the sticky bar has no tonal seam against the page
     it floats over — an opaque paper fill reads as a band, worst in dark. */
  background-color: var(--paper);
  background-image: inherit;
  background-blend-mode: inherit;
  background-size: 200px 200px;
}

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

.brand { text-decoration: none; color: var(--ink); display: flex; align-items: center; gap: 0.55rem; white-space: nowrap; }
.brand__mark { width: 17px; height: 17px; fill: var(--accent); flex: none; }
.brand__title {
  font-family: var(--font-mono); font-size: 0.7rem; font-weight: 600;
  letter-spacing: 0.1em; text-transform: uppercase;
}

.masthead__links { display: flex; align-items: center; gap: 1.1rem; margin-left: auto; }
/* The theme toggle lives OUTSIDE the collapsible menu so it survives JS-off and
   is reachable on mobile without opening anything. */
.masthead__actions { display: flex; align-items: center; gap: 0.6rem; margin-left: 1.1rem; }

.navlink {
  font-family: var(--font-mono); font-size: 0.7rem;
  letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--ink-soft); text-decoration: none;
}
.navlink:hover { color: var(--accent); }
.navlink[aria-current] { color: var(--accent); }

.masthead__burger { display: none; }

.theme-toggle {
  background: none; border: 1px solid var(--rule); border-radius: 999px;
  width: 2.1rem; height: 2.1rem; padding: 0.4rem; cursor: pointer; color: var(--ink-soft);
}
.theme-toggle:hover { border-color: var(--accent); color: var(--accent); }
.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(--ink); }
  .masthead__actions { margin-left: auto; }
  .masthead__links {
    display: none; position: absolute; right: 1rem; top: 3.4rem;
    flex-direction: column; align-items: flex-end; gap: 0.8rem;
    background: var(--surface); border: 1px solid var(--rule);
    border-radius: 4px; padding: 1rem 1.25rem; z-index: 20;
  }
  .masthead__links.is-open { display: flex; }
}

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

.wrap { max-width: calc(var(--rail) + var(--measure) + var(--gap)); margin-inline: auto; padding-inline: clamp(1rem, 4vw, 2rem); }

/* The hero sits in the measure column, not centred in the wrap — otherwise the
   title hangs left of every paragraph that follows it. */
.hero { max-width: var(--measure); margin: 3.5rem 0 1rem calc(var(--rail) + var(--gap)); }
.hero__title { font-size: clamp(2rem, 6vw, 3.2rem); margin: 0 0 0.5rem; }
.hero__dek { color: var(--ink-soft); 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(--accent); color: var(--ink-soft); font-style: italic;
}
.prose table { border-collapse: collapse; width: 100%; }
.prose th, .prose td { border-bottom: 1px solid var(--rule); padding: 0.4rem 0.6rem; text-align: left; }
.prose th { font-family: var(--font-mono); font-size: 0.64rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-faint); }

/* ---------- SECOND READING: the document grid (rail | measure) ---------- */

.sec {
  display: grid;
  grid-template-columns: var(--rail) minmax(0, var(--measure));
  gap: var(--gap);
  align-items: start;
  margin-block: 2.1rem;
}
.sec > .rail { grid-column: 1; }
.sec > .body { grid-column: 2; }
.body > * + * { margin-top: 0.95em; }
.body > h3 { margin-top: 2.2rem; }
/* Reset the UA margin, then restore the gap for adjacent paragraphs explicitly:
   `.body p` (0,1,1) outranks `.body > * + *` (0,1,0), so without this rule two
   consecutive <p> run together. */
.body p { margin: 0; }
.body p + p { margin-top: 0.95em; }
/* Same reason as above: a <p> following a list was dedenting flush against the
   last bullet and reading as a broken continuation of it. */
.body ul + p, .body ol + p { margin-top: 1.1em; }

/* The citation rail: mono, right-aligned against the measure, quiet until needed. */
.rail {
  font-family: var(--font-mono);
  font-size: 0.68rem; line-height: 1.5; letter-spacing: 0.06em;
  color: var(--ink-faint);
  text-align: right;
  padding-top: 0.42rem;
  border-right: 1px solid var(--rule);
  padding-right: 0.9rem;
}
.rail b { display: block; font-weight: 600; color: var(--source); letter-spacing: 0.08em; }
.rail span { display: block; margin-top: 0.28rem; text-transform: uppercase; }

.kicker {
  font-family: var(--font-mono); font-size: 0.68rem; letter-spacing: 0.2em;
  text-transform: uppercase; color: var(--accent); margin: 0 0 0.55rem;
}
h1.title { font-size: clamp(2.4rem, 1.6rem + 3.6vw, 3.9rem); font-weight: 700; letter-spacing: -0.015em; margin: 0; }
h2.part  { font-size: clamp(1.85rem, 1.4rem + 1.9vw, 2.6rem); font-weight: 650; letter-spacing: -0.01em; margin: 0; }
.body h3 { font-size: 1.16rem; font-weight: 650; }

.byline {
  font-family: var(--font-mono); font-size: 0.72rem; letter-spacing: 0.05em;
  color: var(--ink-soft); margin: 1rem 0 0;
}

/* First line of an opening paragraph: small caps, document-style. */
.lede { font-size: 1.16em; }
.lede::first-line { font-variant: all-small-caps; letter-spacing: 0.035em; }

/* The mirrored-inkblot section divider. */
.blotrule { display: flex; align-items: center; gap: 1rem; margin: 2.4rem 0; border: 0; }
.blotrule::before, .blotrule::after { content: ""; flex: 1; height: 1px; background: var(--rule); }
.blotrule svg { width: 16px; height: 16px; fill: var(--accent); opacity: 0.75; flex: none; }

/* Heuer, verbatim. Ink-blue means "his words, not the site's". */
.source {
  margin: 1.6rem 0; padding: 1rem 1.15rem 0.85rem;
  border-left: 3px solid var(--source);
  background: var(--wash-source);
}
.source blockquote { margin: 0; font-size: 1.07em; line-height: 1.55; text-indent: -0.42em; border: 0; padding: 0; font-style: normal; color: var(--ink); }
.source figcaption {
  font-family: var(--font-mono); font-size: 0.68rem; letter-spacing: 0.07em;
  text-transform: uppercase; color: var(--source); margin-top: 0.7rem;
}

/* A named bias — the markup cannot carry the name without the mechanism. */
.trap {
  margin: 1.5rem 0; padding: 0.9rem 1.1rem;
  border-left: 3px solid var(--trap);
  background: var(--wash-trap);
}
.trap__name {
  font-family: var(--font-mono); font-size: 0.7rem; font-weight: 600;
  letter-spacing: 0.14em; text-transform: uppercase; color: var(--trap);
  margin: 0 0 0.4rem;
}
.trap p + p { margin-top: 0.5rem; }
.trap .cite { font-family: var(--font-mono); font-size: 0.66rem; letter-spacing: 0.07em; color: var(--ink-faint); text-transform: uppercase; margin-top: 0.6rem; }

/* Every part page ends with one of these. */
.pointer {
  margin-top: 2.2rem; padding: 1rem 1.15rem;
  border: 1px solid var(--rule); border-top: 3px solid var(--accent);
  background: var(--surface);
}
.pointer p { margin: 0; }
.pointer .lab {
  font-family: var(--font-mono); font-size: 0.66rem; letter-spacing: 0.16em;
  text-transform: uppercase; color: var(--accent); display: block; margin-bottom: 0.4rem;
}

/* Reading-time chip. */
.readtime {
  display: inline-flex; align-items: baseline; gap: 0.5rem; margin-top: 1.5rem;
  font-family: var(--font-mono); font-size: 0.72rem; letter-spacing: 0.13em; text-transform: uppercase;
  color: var(--ink-soft); border: 1px solid var(--rule); padding: 0.35rem 0.7rem; border-radius: 2px;
}
.readtime b { font-size: 0.95rem; color: var(--accent); font-weight: 600; letter-spacing: 0.04em; }

.claim {
  font-family: var(--font-display); font-size: clamp(1.3rem, 1.05rem + 1.1vw, 1.72rem);
  line-height: 1.35; font-weight: 400; font-style: italic;
  color: var(--ink); margin: 1.8rem 0 0; max-width: 34rem;
}

/* The reading path on the home page. */
.path { display: grid; gap: 1px; background: var(--rule); border: 1px solid var(--rule); margin-top: 2.4rem; }
.path a {
  display: grid; grid-template-columns: 4.9rem 1fr auto; gap: 1rem; align-items: baseline;
  padding: 1rem 1.15rem; background: var(--paper); text-decoration: none; color: inherit;
}
.path a:hover { background: var(--surface); }
.path .num { font-family: var(--font-mono); font-size: 0.72rem; letter-spacing: 0.1em; color: var(--accent); font-weight: 600; white-space: nowrap; }
/* The cards are the pitch page's only route into the reading path, so the title
   carries the mulberry that means "navigation" everywhere else on the site. */
.path .nm { font-family: var(--font-display); font-size: 1.12rem; font-weight: 600; color: var(--accent); }
.path a:hover .nm { text-decoration: underline; text-underline-offset: 0.16em; }
.path .mins::after { content: " \2192"; }
.path .nm small { display: block; font-family: var(--font-body); font-size: 0.86rem; font-weight: 400; color: var(--ink-soft); margin-top: 0.2rem; line-height: 1.45; }
.path .mins { font-family: var(--font-mono); font-size: 0.66rem; letter-spacing: 0.09em; color: var(--ink-faint); text-transform: uppercase; }

/* The chapter map table. */
.maptable { width: 100%; border-collapse: collapse; margin-top: 1.6rem; font-size: 0.94rem; }
.maptable caption { text-align: left; font-family: var(--font-mono); font-size: 0.66rem; letter-spacing: 0.16em; text-transform: uppercase; color: var(--ink-faint); padding-bottom: 0.7rem; }
.maptable th {
  text-align: left; font-family: var(--font-mono); font-weight: 600; font-size: 0.64rem;
  letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-faint);
  border-bottom: 1px solid var(--ink-soft); padding: 0.4rem 0.6rem 0.4rem 0;
}
.maptable td { border-bottom: 1px solid var(--rule); padding: 0.5rem 0.6rem 0.5rem 0; vertical-align: baseline; }
.maptable td.n, .maptable td.p { font-family: var(--font-mono); font-size: 0.8rem; font-variant-numeric: tabular-nums; color: var(--source); white-space: nowrap; }
.maptable td.p { text-align: right; padding-right: 0; color: var(--ink-faint); }
.maptable tr.parthead td {
  font-family: var(--font-mono); font-size: 0.64rem; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--accent); padding-top: 1.15rem; border-bottom: 1px solid var(--accent);
}


/* Numbered procedures (Heuer's ACH steps, his checklist). Paraphrased, never
   reproduced — see .src-note, which must accompany each of them. */
.steps { margin: 1.4rem 0 0; padding-left: 0; list-style: none; counter-reset: step; }
.steps li {
  position: relative; padding-left: 2.6rem; margin-top: 0.85rem;
}
.steps li::before {
  counter-increment: step; content: counter(step);
  position: absolute; left: 0; top: 0.05em;
  font-family: var(--font-mono); font-size: 0.72rem; font-weight: 600;
  color: var(--accent); border: 1px solid var(--rule); border-radius: 2px;
  width: 1.75rem; height: 1.55rem; display: grid; place-items: center;
}
.steps li b { font-weight: 650; }

/* Where the site paraphrases a structure of Heuer's rather than quoting it, the
   boundary is stated on the page — brief §4 forbids reproducing his boxes. */
.src-note {
  font-family: var(--font-mono); font-size: 0.68rem; line-height: 1.6;
  letter-spacing: 0.04em; color: var(--ink-faint);
  border-left: 2px solid var(--rule); padding-left: 0.8rem; margin-top: 1.4rem;
}

/* A test the reader can apply to their own drafts — the site's own words, so it
   carries the mulberry accent, not the ink-blue reserved for Heuer verbatim. */
.pull {
  font-family: var(--font-display); font-size: 1.16em; line-height: 1.4;
  font-style: italic; border-left: 3px solid var(--accent);
  padding: 0.15rem 0 0.15rem 1.1rem; margin: 1.5rem 0;
}

.rules { margin: 1.2rem 0 0; padding-left: 1.1rem; }
.rules li { margin-top: 0.5rem; padding-left: 0.3rem; }
.rules li::marker { color: var(--accent); }

/* Prev/next chain between part pages. */
.chain { display: flex; flex-wrap: wrap; gap: 1rem; justify-content: space-between; margin-top: 2.6rem; border-top: 1px solid var(--rule); padding-top: 1rem; }
.chain a { font-family: var(--font-mono); font-size: 0.68rem; letter-spacing: 0.09em; text-transform: uppercase; text-decoration: none; }
.chain a:hover { text-decoration: underline; }

/* ---------- colophon: the disclosure lives here, on every page ---------- */

.colophon { border-top: 1px solid var(--rule); margin-top: 3.5rem; }
.colophon__inner {
  max-width: var(--page); margin: 0 auto; padding: 1.6rem 1.25rem 2.6rem;
  font-family: var(--font-mono); font-size: 0.66rem; line-height: 1.7;
  letter-spacing: 0.05em; color: var(--ink-faint);
}
.colophon__title { font-family: var(--font-display); font-size: 1rem; letter-spacing: 0; color: var(--ink); margin: 0 0 0.5rem; }
.colophon__links { display: flex; flex-wrap: wrap; gap: 1rem; }
.colophon__links a { color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.1em; }
.colophon__foot { margin-top: 1.25rem; }
/* The AI-authorship disclosure is non-negotiable (brief §5) — it does not get to
   be the faintest thing on the page. */
.colophon__disclosure { font-size: 0.74rem; color: var(--ink-soft); margin: 1.25rem 0 0; }
.colophon__disclosure a { color: var(--accent); }
.colophon__rights { margin: 0.7rem 0 0; }

/* ---------- narrow: the rail folds into an inline chip row ---------- */

@media (max-width: 46rem) {
  .sec { grid-template-columns: minmax(0, 1fr); gap: 0.75rem; }
  .sec > .rail, .sec > .body { grid-column: 1; }
  .rail {
    text-align: left; border-right: 0; border-left: 2px solid var(--rule);
    padding: 0.1rem 0 0.1rem 0.7rem;
  }
  .rail b { display: inline; }
  .rail span { display: inline; margin-left: 0.6rem; }
  /* The folded rail chip already says "Part III · Ch. 9–13"; the kicker beneath
     it repeats that within 40px. One of them goes on narrow screens. */
  .sec > .rail + .body > .kicker { display: none; }
  .path a { grid-template-columns: 4.4rem 1fr; }
  .path .mins { grid-column: 2; }
  .hero { margin-left: 0; }
}

/* ---------- 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__links, .theme-toggle, .skip-link { display: none; }
  body { background: #fff; color: #000; background-image: none; }
  .sec { display: block; }
  .rail { text-align: left; border: 0; padding: 0 0 0.5rem; }
}
