/* ==========================================================================
   base.css — tokens, reset, and the defenses.

   EVERY COLOUR IN THIS FILE IS DECLARED ONCE, HERE, IN :root. The values
   come from js/brand.js, which generates them from js/optics.js; main.js
   mirrors the same object into these properties at boot so a JS-driven
   accent swap and a CSS-driven one cannot disagree. tools/validate.mjs
   fails the build if any brand hex appears anywhere else in css/ or js/ —
   including as an rgb() triple, because a sibling hid nine stale copies of
   five colours from a string-only check that way.
   ========================================================================== */

:root {
  /* ---- ground ramp: cool, high-key. The site's whole register. ------- */
  --ground:    #ECF1F6;
  --ground-2:  #E1E9F1;
  --plate:     #F9FBFE;
  --plate-2:   #FFFFFF;
  --deep:      #1B2331;

  /* ---- ink ramp. Each step's lightness was SOLVED to hit a stated
         contrast ratio against --ground-2, the darkest surface body text
         sits on. --faint is real text — table headers, field labels,
         figure captions — so its target is 4.5 and not 3. A sibling
         shipped that step at 2.6:1. ------------------------------------ */
  --ink:       #232832;   /* 12.05 : 1 on --ground-2 */
  --ink-2:     #464C56;   /*  7.05 : 1 */
  --ink-3:     #575D66;   /*  5.42 : 1 */
  --faint:     #636972;   /*  4.51 : 1  <- binding case */

  /* ---- the ink ramp inverted, for --deep surfaces ------------------- */
  --ink-on-deep:   #DAE1EE;
  --ink-2-on-deep: #A6AEB9;
  --ink-3-on-deep: #9098A1;
  --faint-on-deep: #838A92;

  /* ---- accents. The hue of each is the colour a real nacre stack
         reflects at the tablet thickness named beside it; see
         js/brand.js. Lightness and chroma are chosen. ----------------- */
  --rose:     #A64A68;   /* 340 nm */
  --violet:   #87549E;   /* 360 nm */
  --indigo:   #5D60B1;   /* 380 nm */
  --blue:     #007098;   /* 400 nm */
  --teal:     #007851;   /* 420 nm */

  --rose-wash:   #FFE9F0;
  --violet-wash: #FCEBFF;
  --indigo-wash: #EDF0FF;
  --blue-wash:   #D9F9FF;
  --teal-wash:   #DCFBED;

  --rose-on-deep:   #C37088;
  --violet-on-deep: #A578BA;
  --indigo-on-deep: #7E83CB;
  --blue-on-deep:   #2494B7;
  --teal-on-deep:   #359A76;

  /* The primary accent. One name, so a swap is one line. */
  --accent:      var(--indigo);
  --accent-wash: var(--indigo-wash);

  /* ---- hairlines. Tuned as alpha over the ground rather than as flat
         greys, so a rule sitting on --plate-2 and one on --ground-2 read
         as the same weight. ------------------------------------------- */
  --rule:      rgba(35, 40, 50, 0.10);
  --rule-2:    rgba(35, 40, 50, 0.06);
  --rule-deep: rgba(218, 225, 238, 0.13);

  /* ---- elevation. A tablet is thin; its shadow is a contact shadow,
         not a drop shadow. --------------------------------------------- */
  --lift-1: 0 1px 1px rgba(28, 40, 66, .04), 0 2px 8px rgba(28, 40, 66, .045);
  --lift-2: 0 1px 2px rgba(28, 40, 66, .05), 0 10px 28px rgba(28, 40, 66, .075);
  --lift-3: 0 2px 4px rgba(28, 40, 66, .06), 0 26px 60px rgba(28, 40, 66, .11);

  /* ---- geometry ----------------------------------------------------- */
  --r:      16px;
  --r-sm:   11px;
  --r-lg:   22px;
  --r-pill: 999px;
  --maxw:   1140px;
  --maxw-prose: 68ch;
  --gutter: 24px;
  --band:   clamp(64px, 8vw, 108px);

  /* ---- type --------------------------------------------------------- */
  --display: 'Newsreader', 'Iowan Old Style', Georgia, 'Times New Roman', serif;
  --sans: 'Plus Jakarta Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'Spline Sans Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  --t-hero:  clamp(3rem, 8.5vw, 6.25rem);
  --t-h1:    clamp(2.25rem, 5vw, 3.5rem);
  --t-h2:    clamp(1.9rem, 3.9vw, 2.9rem);
  --t-h3:    clamp(1.18rem, 1.7vw, 1.35rem);
  --t-lead:  clamp(1.02rem, 1.4vw, 1.175rem);
  --t-body:  1rem;
  --t-small: 0.885rem;
  --t-micro: 0.775rem;

  --ease: cubic-bezier(.22, .61, .36, 1);
}

/* ==========================================================================
   Reset
   ========================================================================== */

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  /* The sticky header is 64px; without this an in-page jump lands with the
     target's heading underneath it. */
  scroll-padding-top: 88px;
}

body {
  font-family: var(--sans);
  font-size: var(--t-body);
  line-height: 1.62;
  color: var(--ink);
  background: var(--ground);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: 'kern' 1;
  /* min-width:0 discipline starts here. A grid or flex item defaults to
     min-width:auto, whose content-based minimum is the widest unbreakable
     descendant — one nowrap label three levels down scrolled a whole
     sibling site sideways at 500px. Every layout container below is
     capped; any NEW grid needs the same. */
  overflow-x: clip;
}

img, svg, canvas, video { display: block; max-width: 100%; }
/* `:not([fill])` matters. A bare `svg { fill: none }` beats the presentation
   attribute on the brand mark — CSS wins over presentation attributes — so
   the mark rendered as nothing in the header and footer of all nine pages
   while every stroke icon looked correct. */
svg:not([fill]) { fill: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; }
a { color: inherit; text-decoration: none; }
ul, ol { list-style: none; }
table { border-collapse: collapse; width: 100%; }
h1, h2, h3, h4, h5, h6 { font-weight: 400; line-height: 1.14; text-wrap: balance; }
p { text-wrap: pretty; }
:where(hr) { border: 0; border-top: 1px solid var(--rule); }

/* ==========================================================================
   Type primitives
   ========================================================================== */

.display { font-family: var(--display); font-optical-sizing: auto; letter-spacing: -0.014em; }
.mono {
  font-family: var(--mono);
  font-size: 0.9em;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.005em;
}
.num { font-variant-numeric: tabular-nums; }

.eyebrow {
  display: inline-flex; align-items: center; gap: 0.62em;
  font-family: var(--mono);
  font-size: var(--t-micro);
  font-weight: 500;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--accent);
}
.eyebrow::before {
  content: ''; width: 20px; height: 1px; flex: none;
  background: currentColor; opacity: .55;
}

.lead {
  font-size: var(--t-lead);
  color: var(--ink-2);
  line-height: 1.66;
  max-width: 60ch;
}

em { font-style: italic; }
strong, b { font-weight: 600; color: var(--ink); }
code, kbd, samp {
  font-family: var(--mono);
  font-size: 0.86em;
  background: var(--ground-2);
  border-radius: 5px;
  /* Tight horizontal padding on purpose: at 0.4em the box reads as a space
     before the following punctuation, so `totalSupply`. renders as
     "totalSupply ." */
  padding: 0.08em 0.22em;
}

/* ==========================================================================
   Accessibility defenses
   ========================================================================== */

/* Skip link. NOT positioned at left:-9999px — that reports as horizontal
   overflow (scrollWidth 1537 against innerWidth 1360 on a sibling), which
   then masks the next REAL overflow. Clipped instead. */
.skip {
  position: absolute; top: 8px; left: 8px; z-index: 200;
  clip-path: inset(50%);
  background: var(--deep); color: var(--ink-on-deep);
  padding: 10px 16px; border-radius: var(--r-sm);
  font-size: var(--t-small); font-weight: 600;
}
.skip:focus-visible { clip-path: none; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 3px;
}
/* Focus rings on --deep need the inverted accent or they vanish. */
.footer :focus-visible, .on-deep :focus-visible { outline-color: var(--indigo-on-deep); }

.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  clip-path: inset(50%); overflow: hidden; white-space: nowrap;
}

/* Scroll reveal is scoped to `.js`, set by an inline script in <head>
   BEFORE any stylesheet link. Written unscoped this rule hides the whole
   page from anyone without JavaScript — which is exactly what it did on a
   sibling, for 37 elements. validate.mjs fails if any document emits that
   script after a stylesheet. */
.js [data-reveal] {
  opacity: 0;
  transform: translateY(14px);
  transition: opacity .62s var(--ease), transform .62s var(--ease);
}
.js [data-reveal].shown { opacity: 1; transform: none; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
  .js [data-reveal] { opacity: 1; transform: none; }
}

/* An author `display` beats the UA stylesheet's [hidden]. Without this
   explicit rule the mobile nav sheet — which is display:flex — is
   permanently open below its breakpoint: invisible on a desktop, total on
   a phone. */
[hidden] { display: none !important; }

/* ==========================================================================
   Layout
   ========================================================================== */

.wrap {
  width: 100%;
  max-width: var(--maxw);
  margin-inline: auto;
  padding-inline: var(--gutter);
  min-width: 0;
}
/* A narrower MEASURE, not a narrower column. Setting max-width on the wrap
   itself re-centres it, so a narrow section's left edge jumped 150px in
   from every other section's and the page read as two documents. The wrap
   keeps its width and its gutter; the content inside is capped. */
.wrap-narrow > * { max-width: 840px; }

.band { padding-block: var(--band); }
.band-alt { background: var(--ground-2); }
.band-plate { background: var(--plate); }

/* Anything that can be wider than its column scrolls INSIDE its own box.
   A table's min-content width will otherwise set the grid track and pan
   the entire page — 234px of overflow at 320px on a sibling, on the one
   page its whole argument rested on. */
.scroll-x {
  overflow-x: auto;
  min-width: 0;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}
.scroll-x > * { min-width: max-content; }

.grid { display: grid; gap: 20px; min-width: 0; }
.grid > * { min-width: 0; }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

@media (max-width: 900px) { .g-3, .g-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) { .g-2, .g-3, .g-4 { grid-template-columns: minmax(0, 1fr); } }

/* ==========================================================================
   The tablet — the one surface this site has.

   A card here is a nacre tablet: a thin plate with a bright edge where the
   light catches it. The edge is the only decoration on the whole site and
   it carries the palette, so a row of cards prints the interference series
   left to right.
   ========================================================================== */

.tablet {
  position: relative;
  background: var(--plate-2);
  border-radius: var(--r);
  box-shadow: var(--lift-1);
  padding: 26px;
  min-width: 0;
  isolation: isolate;
  transition: box-shadow .3s var(--ease), transform .3s var(--ease);
}
.tablet::before {
  content: '';
  position: absolute; inset: 0 0 auto 0; height: 2px;
  border-radius: var(--r) var(--r) 0 0;
  background: linear-gradient(90deg,
    transparent 4%, var(--edge, var(--accent)) 26%, var(--edge, var(--accent)) 74%, transparent 96%);
  opacity: .5;
}
.tablet-lift:hover { box-shadow: var(--lift-2); transform: translateY(-2px); }
.tablet-flat { box-shadow: none; background: var(--plate); }
.tablet-flat::before { opacity: .34; }

/* Rotating the edge colour across a row is done with :nth-child rather
   than a per-card attribute so adding a card cannot forget it. */
.edges > *:nth-child(5n + 1) { --edge: var(--rose); }
.edges > *:nth-child(5n + 2) { --edge: var(--violet); }
.edges > *:nth-child(5n + 3) { --edge: var(--indigo); }
.edges > *:nth-child(5n + 4) { --edge: var(--blue); }
.edges > *:nth-child(5n + 5) { --edge: var(--teal); }

/* ==========================================================================
   Controls
   ========================================================================== */

.btn {
  /* NO `gap` HERE. A flex container turns each contiguous run of text into
     its own anonymous item, so `The <span data-fact>fifteen</span> rules`
     became three items with two gaps and rendered as "The  fifteen  rules".
     The trailing glyph gets a margin instead. */
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: var(--t-small);
  padding: 11px 20px;
  border-radius: var(--r-pill);
  border: 1px solid transparent;
  white-space: nowrap;
  transition: background .2s var(--ease), color .2s var(--ease),
              border-color .2s var(--ease), transform .2s var(--ease),
              box-shadow .2s var(--ease);
}
.btn > [aria-hidden], .btn > svg { margin-left: .45em; }
/* Any label with inline markup in it — a [data-fact] span, a <b> — must be
   wrapped in this. A flex container makes each contiguous text run its own
   anonymous item AND DISCARDS the whitespace-only nodes between them, so
   `The <span>fifteen</span> rules` renders as "Thefifteenrules". Gap does
   not fix it; gap made it "The  fifteen  rules" instead. */
.btn-l { display: inline; }
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: none; }
.btn-lg { padding: 14px 26px; font-size: 0.98rem; }
.btn-primary { background: var(--deep); color: var(--ink-on-deep); }
.btn-primary:hover { background: #10161f; box-shadow: var(--lift-2); }
.btn-line {
  background: var(--plate-2); color: var(--ink);
  border-color: var(--rule); box-shadow: var(--lift-1);
}
.btn-line:hover { border-color: var(--accent); color: var(--accent); }
.btn-quiet { color: var(--ink-2); padding-inline: 12px; }
.btn-quiet:hover { color: var(--accent); }

.chip {
  display: inline-flex; align-items: center; gap: .5em;
  padding: 6px 13px;
  border-radius: var(--r-pill);
  background: var(--plate-2);
  box-shadow: var(--lift-1);
  font-size: var(--t-micro);
  font-weight: 500;
  color: var(--ink-2);
}
.chip .dot {
  width: 6px; height: 6px; border-radius: 50%; flex: none;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-wash);
}

/* The three states any capability on this site can be in. There is no
   fourth, and nothing is described in the present tense without one. */
.state {
  display: inline-flex; align-items: center; gap: .45em;
  font-family: var(--mono);
  font-size: var(--t-micro);
  font-weight: 500;
  letter-spacing: .04em;
  padding: 3px 9px;
  border-radius: 6px;
  white-space: nowrap;
}
.state::before { content: ''; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.state-live    { color: var(--teal);   background: var(--teal-wash); }
.state-written { color: var(--indigo); background: var(--indigo-wash); }
.state-unset   { color: var(--ink-3);  background: var(--ground-2); }
