/* ==========================================================================
   Base: reset, page chrome, header, film grain
   ========================================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--bg);
  color-scheme: dark;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-display);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

/* Lock scrolling while the loader is up */
html.is-loading body {
  overflow: hidden;
}

h1, p, ul, dl, dd {
  margin: 0;
}

ul,
ol {
  margin: 0;
  padding: 0;
  list-style: none;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 4px;
}

::selection {
  background: var(--accent);
  color: var(--accent-ink);
}

.skip-link {
  position: fixed;
  left: var(--gutter);
  top: -100px;
  z-index: calc(var(--z-loader) + 1);
  padding: 0.6rem 0.9rem;
  background: var(--fg);
  color: var(--bg);
  font-family: var(--font-mono);
  font-size: 0.75rem;
}

.skip-link:focus {
  top: var(--gutter);
}

/* --------------------------------------------------------------------------
   Header
   -------------------------------------------------------------------------- */

.site-header {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: var(--z-header);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  padding: calc(var(--gutter) * 0.75) var(--gutter);
  pointer-events: none; /* let the scene receive pointer moves in the gaps */
}

.site-header > * {
  pointer-events: auto;
}

.brand {
  font-weight: 800;
  font-stretch: 118%;
  font-size: 0.95rem;
  letter-spacing: -0.01em;
  text-transform: uppercase;
}

.nav {
  display: flex;
  gap: clamp(1rem, 2.4vw, 2.25rem);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.nav a {
  position: relative;
  display: inline-block;
  padding: 0.35rem 0;
  color: var(--fg-muted);
  transition: color 0.3s var(--ease-out);
}

/* Hairline that draws in from the left on hover */
.nav a::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 1px;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.45s var(--ease-out);
}

.nav a:hover,
.nav a:focus-visible {
  color: var(--fg);
}

.nav a:hover::after,
.nav a:focus-visible::after {
  transform: scaleX(1);
}

.nav a:active {
  color: var(--accent);
}

/* --------------------------------------------------------------------------
   Film grain
   An SVG turbulence tile, jittered in steps so it reads like film noise.
   It is a single composited layer (transform-only animation), so it is cheap.
   -------------------------------------------------------------------------- */

.grain {
  position: fixed;
  inset: -50%;
  z-index: var(--z-grain);
  pointer-events: none;
  opacity: 0.075;
  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.85' numOctaves='2' 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");
  animation: grain-jitter 0.8s steps(6) infinite;
  will-change: transform;
}

@keyframes grain-jitter {
  0%   { transform: translate3d(0, 0, 0); }
  17%  { transform: translate3d(-4%, 3%, 0); }
  33%  { transform: translate3d(3%, -5%, 0); }
  50%  { transform: translate3d(-6%, -2%, 0); }
  67%  { transform: translate3d(5%, 4%, 0); }
  83%  { transform: translate3d(-2%, 6%, 0); }
  100% { transform: translate3d(0, 0, 0); }
}

/* --------------------------------------------------------------------------
   Reduced motion: keep the grain, stop it moving
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .grain {
    animation: none;
  }

  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
