/* ==========================================================================
   NOETIC — reset + typographic base
   ========================================================================== */

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  /* fallback anchor offset when smooth-scroll engine is off */
  scroll-padding-top: 6rem;
}

body {
  background: var(--bg);
  color: var(--tx-mid);
  font-family: var(--font-sans);
  font-size: var(--t-base);
  line-height: var(--lh-body);
  font-synthesis-weight: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-x: clip;
  min-height: 100vh;
}

/* Ambient ground: a static gradient that exists even before (or without) WebGL,
   so the page is never a flat black rectangle. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -2;
  pointer-events: none;
  background:
    radial-gradient(120% 70% at 50% -10%, color-mix(in oklab, var(--vi-600) 22%, transparent), transparent 60%),
    radial-gradient(90% 60% at 85% 110%, color-mix(in oklab, var(--cy-600) 14%, transparent), transparent 62%),
    radial-gradient(70% 50% at 10% 40%, color-mix(in oklab, var(--mg-500) 7%, transparent), transparent 70%),
    var(--ink-1000);
}

/* Fine grain — kills gradient banding on dark screens. */
body::after {
  content: "";
  position: fixed;
  inset: -50%;
  z-index: -1;
  pointer-events: none;
  opacity: 0.035;
  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='0.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  animation: grain 6s steps(6) infinite;
}
@keyframes grain {
  0%   { transform: translate(0, 0); }
  20%  { transform: translate(-3%, 2%); }
  40%  { transform: translate(2%, -3%); }
  60%  { transform: translate(-2%, -2%); }
  80%  { transform: translate(3%, 1%); }
  100% { transform: translate(0, 0); }
}

img, svg, canvas, video { display: block; max-width: 100%; }
canvas { touch-action: none; }

h1, h2, h3, h4 {
  color: var(--tx-hi);
  font-weight: 600;
  line-height: var(--lh-snug);
  letter-spacing: var(--tr-snug);
  text-wrap: balance;
}
h1 { font-size: var(--t-3xl); line-height: var(--lh-tight); letter-spacing: var(--tr-tight); }
h2 { font-size: var(--t-2xl); line-height: var(--lh-tight); letter-spacing: var(--tr-tight); }
h3 { font-size: var(--t-lg); }
h4 { font-size: var(--t-md); }

p { max-width: var(--measure); text-wrap: pretty; }

a { color: inherit; text-decoration: none; }
a:not([class]) {
  color: var(--cy-400);
  text-decoration: underline;
  text-decoration-color: color-mix(in oklab, var(--cy-400) 40%, transparent);
  text-underline-offset: 0.25em;
  transition: text-decoration-color var(--d-fast) var(--e-swift);
}
a:not([class]):hover { text-decoration-color: var(--cy-400); }

ul, ol { list-style: none; }

button, input, textarea, select {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
}
button { cursor: pointer; }

::selection { background: color-mix(in oklab, var(--vi-500) 55%, transparent); color: #fff; }

:focus-visible {
  outline: 2px solid var(--cy-500);
  outline-offset: 3px;
  border-radius: var(--r-sm);
}

/* Scrollbar — only styled where the native one is still in play. */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--ink-1000); }
::-webkit-scrollbar-thumb {
  background: color-mix(in oklab, var(--vi-500) 45%, var(--ink-800));
  border-radius: var(--r-full);
  border: 2px solid var(--ink-1000);
}
::-webkit-scrollbar-thumb:hover { background: var(--vi-500); }

/* ---- Utility ------------------------------------------------------------ */
.u-sr {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap; border: 0;
}
.u-mono {
  font-family: var(--font-mono);
  font-size: var(--t-xs);
  letter-spacing: var(--tr-wide);
  text-transform: uppercase;
  color: var(--tx-lo);
}
.u-grad {
  background: var(--grad-signal);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.u-measure-wide { max-width: 76ch; }
.u-center { margin-inline: auto; }

/* Skip link */
.skip {
  position: absolute; top: -100%; left: var(--s-4); z-index: var(--z-overlay);
  padding: var(--s-3) var(--s-5);
  background: var(--ink-800); color: var(--tx-hi);
  border: 1px solid var(--cy-500); border-radius: var(--r-md);
}
.skip:focus { top: var(--s-4); }

/* ---- Reduced motion: the global kill switch -----------------------------
   The inline head script resolves the OS setting together with the visitor's
   own choice (footer toggle / ?motion=) and stamps .motion-reduced or
   .motion-full on <html>. Keying off the class rather than the media query is
   what lets the toggle work in both directions.

   The media block below is the no-JavaScript path only, where no class exists
   and the handful of ambient CSS animations are all that could move.
   ------------------------------------------------------------------------ */
:root.motion-reduced *,
:root.motion-reduced *::before,
:root.motion-reduced *::after {
  animation-duration: 0.01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.01ms !important;
  scroll-behavior: auto !important;
}
:root.motion-reduced body::after { animation: none; }

@media (prefers-reduced-motion: reduce) {
  :root:not(.js) *,
  :root:not(.js) *::before,
  :root:not(.js) *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---- Motion toggle (footer) --------------------------------------------- */
.motion-switch {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  padding: 0.35em 0.8em;
  border: 1px solid var(--line);
  border-radius: var(--r-full);
  font-family: var(--font-mono);
  font-size: var(--t-xs);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--tx-lo);
  transition: color var(--d-fast) var(--e-swift), border-color var(--d-fast) var(--e-swift);
}
.motion-switch:hover { color: var(--tx-hi); border-color: var(--line-strong); }
.motion-switch::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
}
:root.motion-full .motion-switch::before { background: var(--cy-500); box-shadow: 0 0 8px var(--cy-500); }
:root:not(.js) .motion-switch { display: none; }
