/* ==========================================================================
   Spotless Mind — Base
   Reset, font loading, typography, page shell, ambient field, motion primitives.
   Every value below comes from tokens.css.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Font fallbacks — metric-matched so swapping to the webfont shifts nothing.
   size-adjust / ascent-override values were measured against the real faces
   (Newsreader vs Georgia, Public Sans vs Arial, Plex Mono vs Consolas).
   -------------------------------------------------------------------------- */
@font-face {
  font-family: 'Newsreader Fallback';
  src: local('Georgia'), local('Times New Roman'), local('Noto Serif');
  size-adjust: 102.87%;
  ascent-override: 71.94%;
  descent-override: 26.25%;
  line-gap-override: 0%;
}
@font-face {
  font-family: 'Public Sans Fallback';
  src: local('Arial'), local('Helvetica Neue'), local('Roboto');
  size-adjust: 105.07%;
  ascent-override: 90.42%;
  descent-override: 21.89%;
  line-gap-override: 0%;
}
@font-face {
  font-family: 'IBM Plex Mono Fallback';
  src: local('Consolas'), local('Menlo'), local('DejaVu Sans Mono');
  size-adjust: 109.13%;
  ascent-override: 94.38%;
  descent-override: 25.66%;
  line-gap-override: 0%;
}

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

html {
  background: var(--bg);
  overscroll-behavior-y: none;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--nav-height) + var(--space-5));
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}

body {
  background: var(--bg);
  color: var(--text-body);
  font-family: var(--font-body);
  font-size: var(--text-md);
  line-height: var(--leading-prose);
  font-synthesis-weight: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  min-height: 100svh;
}

img, svg, video, canvas { display: block; max-width: 100%; }
img { height: auto; }
input, button, textarea, select { font: inherit; color: inherit; }
button { background: none; border: none; cursor: pointer; }
a { color: var(--brand); text-underline-offset: .2em; }
ul, ol { list-style-position: outside; }
table { border-collapse: collapse; }
[hidden] { display: none !important; }

::selection { background: var(--brand); color: var(--text-on-brand); }

::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-track { background: var(--bg-sunk); }
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--radius-full);
  border: 3px solid var(--bg-sunk);
}
::-webkit-scrollbar-thumb:hover { background: var(--brand); }

/* --------------------------------------------------------------------------
   Focus — one visible, high-contrast ring everywhere. Never removed.
   -------------------------------------------------------------------------- */
:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 3px;
  border-radius: var(--radius-xs);
}
:focus:not(:focus-visible) { outline: none; }

.skip {
  position: absolute;
  left: -9999px;
  top: var(--space-2);
  z-index: var(--z-skip);
  background: var(--brand);
  color: var(--text-on-brand);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm);
  font-weight: var(--weight-semi);
  text-decoration: none;
  box-shadow: var(--shadow-4);
}
.skip:focus { left: var(--space-3); }

/* Screen-reader-only, but focusable when it needs to be */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* --------------------------------------------------------------------------
   Typography
   -------------------------------------------------------------------------- */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  color: var(--text);
  font-weight: var(--weight-semi);
  text-wrap: balance;
}

h1 {
  font-size: var(--text-4xl);
  line-height: var(--leading-tight);
  letter-spacing: var(--tracking-tighter);
}
h2 {
  font-size: var(--text-3xl);
  line-height: var(--leading-snug);
  letter-spacing: var(--tracking-tight);
  margin-bottom: var(--space-3);
}
h3 {
  font-size: var(--text-xl);
  line-height: var(--leading-snug);
  letter-spacing: var(--tracking-tight);
  margin-bottom: var(--space-2);
}
h4 {
  font-size: var(--text-lg);
  line-height: var(--leading-snug);
  letter-spacing: var(--tracking-tight);
}

p { text-wrap: pretty; }

/* The eyebrow: a mono kicker that labels each section. */
.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  font-weight: var(--weight-medium);
  letter-spacing: var(--tracking-wider);
  text-transform: uppercase;
  color: var(--brand);
  margin-bottom: var(--space-4);
}
.eyebrow::before {
  content: "";
  width: 1.625rem;
  height: 1px;
  background: currentColor;
  opacity: .55;
  flex: none;
}

/* Lead paragraph — the sentence under a heading. Held to a readable measure. */
.lead {
  color: var(--text-muted);
  font-size: var(--text-lg);
  line-height: var(--leading-prose);
  max-width: var(--measure);
}

/* Gradient display text. Both stops are dark enough to stay legible if the
   background-clip is unsupported and the fill falls back to a solid colour. */
.grad,
.shimmer {
  background-image: linear-gradient(105deg, var(--brand) 5%, var(--accent-cool) 55%, var(--accent-plum) 98%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  /* Fallback for clip-path-less engines */
  -webkit-text-fill-color: transparent;
}
@supports not ((-webkit-background-clip: text) or (background-clip: text)) {
  .grad, .shimmer { color: var(--brand); -webkit-text-fill-color: currentColor; }
}
.shimmer {
  background-size: 220% 100%;
  animation: shimmer 9s linear infinite;
}
@keyframes shimmer { to { background-position: 220% 0; } }
@media (prefers-reduced-motion: reduce) {
  .shimmer { animation: none; }
}

/* --------------------------------------------------------------------------
   Page shell
   -------------------------------------------------------------------------- */
.page {
  display: none;
  max-width: var(--page-max);
  margin-inline: auto;
  padding: calc(var(--nav-height) + var(--space-8)) var(--page-gutter) var(--space-10);
}
.page.active {
  display: block;
  animation: pageIn var(--dur-slower) var(--ease-entrance);
}
@keyframes pageIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .page.active { animation: none; }
}

section { margin-block: var(--section-gap); }
section:first-of-type { margin-top: var(--block-gap); }

/* A constrained prose column for long-form text blocks */
.prose { max-width: var(--measure); }
.prose > * + * { margin-top: var(--space-4); }
.prose p { color: var(--text-muted); }

/* --------------------------------------------------------------------------
   Ambient field
   A layered mesh: three soft colour wells drifting behind a fine grain.
   Rendered with CSS gradients (no canvas, no per-frame cost) so it is free
   to run and still reads in both themes.
   -------------------------------------------------------------------------- */
.field {
  position: fixed;
  inset: 0;
  z-index: var(--z-field);
  pointer-events: none;
  overflow: hidden;
  background:
    radial-gradient(60rem 42rem at 12% -8%,  color-mix(in oklab, var(--field-1) 82%, transparent), transparent 62%),
    radial-gradient(52rem 40rem at 92% 12%,  color-mix(in oklab, var(--field-3) 72%, transparent), transparent 60%),
    radial-gradient(48rem 38rem at 68% 96%,  color-mix(in oklab, var(--field-2) 68%, transparent), transparent 62%);
  opacity: var(--field-opacity);
}

/* Two slow-drifting wells layered on top add movement without a repaint storm:
   they animate transform only, and they are composited on their own layer. */
/* The softness comes from the gradient's own falloff rather than a blur()
   filter: a filter on a layer this large forces a full-resolution re-raster
   on every paint, which is the single most expensive thing a decorative
   background can do. */
.field::before,
.field::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  opacity: .85;
  /* Capped so a very wide display does not promote two enormous layers */
  max-width: 62rem;
  max-height: 62rem;
}
.field::before {
  width: 56vw; height: 56vw;
  min-width: 26rem; min-height: 26rem;
  top: -16%; left: -12%;
  background: radial-gradient(closest-side,
    color-mix(in oklab, var(--field-1) 92%, transparent) 0%,
    color-mix(in oklab, var(--field-1) 46%, transparent) 42%,
    transparent 74%);
  animation: fieldDriftA 34s var(--ease-in-out) infinite alternate;
}
.field::after {
  width: 50vw; height: 50vw;
  min-width: 24rem; min-height: 24rem;
  bottom: -20%; right: -10%;
  background: radial-gradient(closest-side,
    color-mix(in oklab, var(--field-2) 88%, transparent) 0%,
    color-mix(in oklab, var(--field-2) 42%, transparent) 42%,
    transparent 74%);
  animation: fieldDriftB 44s var(--ease-in-out) infinite alternate;
}
@keyframes fieldDriftA {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to   { transform: translate3d(6vw, 5vh, 0) scale(1.16); }
}
@keyframes fieldDriftB {
  from { transform: translate3d(0, 0, 0) scale(1.1); }
  to   { transform: translate3d(-5vw, -4vh, 0) scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  .field::before, .field::after { animation: none; }
}

/* Fine film grain over the whole field — kills gradient banding and adds
   the tactile quality flat gradients lack. */
.grain {
  position: fixed;
  inset: 0;
  z-index: var(--z-grain);
  pointer-events: none;
  opacity: var(--grain-opacity);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.82' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 180px 180px;
}

/* --------------------------------------------------------------------------
   Scroll reveal
   Short, staggered, transform+opacity only. Disabled under reduced motion by
   the token collapse, and pre-revealed if JS never runs.
   -------------------------------------------------------------------------- */
.reveal {
  opacity: 0;
  transform: translate3d(0, var(--reveal-shift), 0);
  transition:
    opacity var(--dur-slower) var(--ease-entrance),
    transform var(--dur-slower) var(--ease-entrance);
  transition-delay: var(--reveal-delay, 0ms);
}
.reveal.in {
  opacity: 1;
  transform: none;
}
/* If scripting is off, never hide content. */
.no-js .reveal { opacity: 1; transform: none; }

@media (prefers-reduced-motion: reduce) {
  .reveal { opacity: 1; transform: none; transition: none; }
}

/* --------------------------------------------------------------------------
   Layout primitives
   -------------------------------------------------------------------------- */
.grid { display: grid; gap: var(--space-5); }
.g2 { grid-template-columns: repeat(auto-fit, minmax(min(19rem, 100%), 1fr)); }
.g3 { grid-template-columns: repeat(auto-fit, minmax(min(16rem, 100%), 1fr)); }
.g4 { grid-template-columns: repeat(auto-fit, minmax(min(13rem, 100%), 1fr)); }

.stack       { display: flex; flex-direction: column; gap: var(--space-4); }
.row         { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; }
.row-end     { justify-content: flex-end; }
.center      { text-align: center; }
.center-x    { margin-inline: auto; }

/* A section header: eyebrow + heading + lead, with optional trailing control */
.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-5);
  flex-wrap: wrap;
  margin-bottom: var(--block-gap);
}
.section-head > div:first-child { max-width: var(--measure); }
.section-head h2 { margin-bottom: var(--space-2); }
.section-head .lead { margin-bottom: 0; }

/* Anything wider than the screen scrolls inside its own box, never the page */
.scroll-x {
  overflow-x: auto;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
}
