/* ==========================================================================
   BASE - reset, typography, shared primitives.
   ========================================================================== */

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

* { margin: 0; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  /* The rail nav is fixed; anchored sections need headroom. */
  scroll-padding-top: clamp(2rem, 8vh, 5rem);
}

/* Belt and braces: individual components handle reduced motion themselves,
   but this guarantees nothing animates even if one of them is missed. */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto !important; }

  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: var(--step-0);
  line-height: var(--leading-body);
  font-feature-settings: 'calt' 1;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
  min-height: 100vh;
  transition: background-color var(--dur-4) var(--ease-out),
              color var(--dur-4) var(--ease-out);
}

img, svg, video, canvas { display: block; max-width: 100%; }
img, video { height: auto; }

input, button, textarea, select { font: inherit; color: inherit; }

p, h1, h2, h3, h4, h5, h6, li { overflow-wrap: break-word; }

::selection { background: var(--select-bg); color: var(--ink); }

/* Scrollbar - thin, substrate-coloured, never a distraction. */
* { scrollbar-width: thin; scrollbar-color: var(--line-2) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--line-2);
  border-radius: 99px;
  border: 3px solid var(--bg);
}
*::-webkit-scrollbar-thumb:hover { background: var(--copper-lo); }

/* --------------------------------------------------------------------------
   Focus - a copper ring that never gets clipped.
   -------------------------------------------------------------------------- */

:focus { outline: none; }

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

.skip-link {
  position: fixed;
  top: var(--sp-4);
  left: var(--sp-4);
  z-index: 999;
  padding: var(--sp-3) var(--sp-5);
  background: var(--copper);
  color: #0a0b0e;
  font: 600 var(--step--1)/1 var(--font-mono);
  letter-spacing: var(--track-wide);
  text-transform: uppercase;
  text-decoration: none;
  border-radius: var(--radius);
  transform: translateY(calc(-100% - var(--sp-6)));
  transition: transform var(--dur-2) var(--ease-out);
}

.skip-link:focus-visible { transform: translateY(0); }

/* --------------------------------------------------------------------------
   Type primitives
   -------------------------------------------------------------------------- */

.display,
.h1, .h2, .h3 {
  font-family: var(--font-display);
  font-weight: 400;
  letter-spacing: var(--track-tight);
  line-height: var(--leading-tight);
  text-wrap: balance;
}

.display {
  font-size: var(--step-hero);
  font-variation-settings: 'SOFT' 0, 'WONK' 1, 'opsz' 144;
  letter-spacing: -0.045em;
}

.h1 {
  font-size: var(--step-6);
  font-variation-settings: 'SOFT' 0, 'WONK' 1, 'opsz' 96;
}

.h2 {
  font-size: var(--step-4);
  font-variation-settings: 'SOFT' 2, 'WONK' 1, 'opsz' 48;
  line-height: var(--leading-snug);
  letter-spacing: -0.025em;
}

.h3 {
  font-size: var(--step-2);
  font-variation-settings: 'SOFT' 4, 'WONK' 0, 'opsz' 24;
  line-height: var(--leading-snug);
  letter-spacing: -0.015em;
}

/* Sans headings - used where a serif would feel too editorial. */
.h-sans {
  font-family: var(--font-sans);
  font-weight: 560;
  letter-spacing: -0.02em;
  line-height: var(--leading-snug);
}

.lede {
  font-size: var(--step-1);
  line-height: var(--leading-loose);
  color: var(--ink-2);
  max-width: 56ch;
  font-weight: 380;
  text-wrap: pretty;
}

.prose { max-width: var(--measure); color: var(--ink-2); text-wrap: pretty; }
.prose + .prose { margin-top: var(--sp-4); }

/* The datasheet voice: small, monospaced, wide-tracked, all caps. */
.mono {
  font-family: var(--font-mono);
  font-size: var(--step--1);
  font-weight: 450;
  letter-spacing: var(--track-wide);
  font-feature-settings: 'zero' 1;
}

.label {
  font-family: var(--font-mono);
  font-size: var(--step--2);
  font-weight: 500;
  letter-spacing: var(--track-caps);
  text-transform: uppercase;
  color: var(--ink-3);
  font-feature-settings: 'zero' 1;
}

.label--copper { color: var(--copper); }
.label--signal { color: var(--signal); }

.num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-num;
  font-feature-settings: 'zero' 1, 'tnum' 1;
}

/* --------------------------------------------------------------------------
   Links
   -------------------------------------------------------------------------- */

a { color: inherit; }

.link {
  --link-color: var(--copper);
  position: relative;
  color: var(--ink);
  text-decoration: none;
  background-image: linear-gradient(var(--link-color), var(--link-color));
  background-repeat: no-repeat;
  background-position: 0 100%;
  background-size: 0% 1px;
  transition: background-size var(--dur-3) var(--ease-expo),
              color var(--dur-2) var(--ease-out);
  padding-bottom: 1px;
}

.link:hover,
.link:focus-visible { background-size: 100% 1px; color: var(--copper-hi); }

/* Inline links inside prose keep a permanent hairline. */
.prose a {
  color: var(--ink);
  text-decoration: none;
  box-shadow: inset 0 -1px 0 var(--copper-lo);
  transition: box-shadow var(--dur-2) var(--ease-out), color var(--dur-2) var(--ease-out);
}
.prose a:hover { color: var(--copper-hi); box-shadow: inset 0 -2px 0 var(--copper); }

/* --------------------------------------------------------------------------
   Layout shell
   -------------------------------------------------------------------------- */

.shell {
  width: 100%;
  max-width: calc(var(--max) + var(--gutter) * 2);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.main { padding-left: var(--rail); }

.section {
  position: relative;
  padding-block: var(--section-y);
  scroll-margin-top: 0;
}

/* Hairline that separates every movement of the piece. */
.section + .section::before {
  content: '';
  position: absolute;
  inset-inline: var(--gutter);
  top: 0;
  height: 1px;
  background: linear-gradient(90deg,
    transparent, var(--line) 6%, var(--line) 94%, transparent);
}

/* --------------------------------------------------------------------------
   Section header - the datasheet slug line
   -------------------------------------------------------------------------- */

.section-head {
  display: grid;
  gap: var(--sp-5);
  margin-bottom: clamp(var(--sp-8), 6vw, var(--sp-11));
}

.section-slug {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  color: var(--ink-3);
}

.section-slug__no {
  color: var(--copper);
  font-variant-numeric: tabular-nums;
}

.section-slug__rule {
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, var(--line-2), transparent);
  min-width: var(--sp-6);
}

.section-title-row {
  display: grid;
  gap: var(--sp-6);
  align-items: end;
  grid-template-columns: 1fr;
}

@media (min-width: 860px) {
  .section-title-row {
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr);
    gap: var(--sp-9);
  }
}

/* --------------------------------------------------------------------------
   Grain - a single rasterised noise tile over everything.
   -------------------------------------------------------------------------- */

.grain {
  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='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  mix-blend-mode: overlay;
  will-change: transform;
}

[data-theme='light'] .grain { opacity: 0.05; mix-blend-mode: multiply; }

/* --------------------------------------------------------------------------
   Reveal - progressive enhancement only. Without JS everything is visible.
   -------------------------------------------------------------------------- */

.js [data-reveal] {
  opacity: 0;
  transform: translate3d(0, calc(22px * var(--motion)), 0);
  transition:
    opacity var(--dur-4) var(--ease-out),
    transform var(--dur-4) var(--ease-expo);
  transition-delay: calc(var(--i, 0) * 70ms);
}

.js [data-reveal='fade'] { transform: none; }

.js [data-reveal='wipe'] {
  clip-path: inset(0 100% 0 0);
  opacity: 1;
  transform: none;
  transition: clip-path var(--dur-5) var(--ease-expo);
  transition-delay: calc(var(--i, 0) * 70ms);
}

.js [data-reveal].is-in {
  opacity: 1;
  transform: none;
  clip-path: inset(0 0 0 0);
}

/* --------------------------------------------------------------------------
   Small shared parts
   -------------------------------------------------------------------------- */

.via {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--bg);
  border: 2px solid var(--copper);
  flex: none;
  position: relative;
}

.via::after {
  content: '';
  position: absolute;
  inset: 1.5px;
  border-radius: 50%;
  background: var(--copper);
  opacity: 0.25;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 5px 10px;
  border: 1px solid var(--line-2);
  border-radius: 99px;
  font-family: var(--font-mono);
  font-size: var(--step--2);
  letter-spacing: 0.06em;
  color: var(--ink-2);
  background: var(--surface);
  white-space: nowrap;
  transition: border-color var(--dur-2) var(--ease-out),
              color var(--dur-2) var(--ease-out),
              background-color var(--dur-2) var(--ease-out);
}

.tag:hover { border-color: var(--copper-lo); color: var(--ink); }

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
}

/* Buttons ---------------------------------------------------------------- */

.btn {
  --btn-fg: var(--ink);
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 0.9em 1.5em;
  border: 1px solid var(--line-2);
  border-radius: 99px;
  background: transparent;
  color: var(--btn-fg);
  font-family: var(--font-mono);
  font-size: var(--step--1);
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-decoration: none;
  cursor: pointer;
  overflow: hidden;
  isolation: isolate;
  transition: color var(--dur-2) var(--ease-out),
              border-color var(--dur-3) var(--ease-out),
              transform var(--dur-2) var(--ease-out);
}

/* The fill sweeps in from the pointer's side of the button. */
.btn::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  background: var(--copper);
  transform: scaleX(0);
  transform-origin: var(--btn-origin, left);
  transition: transform var(--dur-3) var(--ease-expo);
}

.btn:hover,
.btn:focus-visible { color: #0a0b0e; border-color: var(--copper); }
.btn:hover::before,
.btn:focus-visible::before { transform: scaleX(1); }
.btn:active { transform: translateY(1px); }

.btn--primary {
  border-color: var(--copper);
  color: var(--copper);
}

.btn__arrow {
  transition: transform var(--dur-3) var(--ease-spring);
}
.btn:hover .btn__arrow { transform: translateX(4px); }

/* Utilities -------------------------------------------------------------- */

.vh {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.stack { display: grid; gap: var(--sp-4); }
.stack-lg { display: grid; gap: var(--sp-6); }
