:root {
  --bg: #030308;
  --fg: #f2f3f7;
  --muted: #8b8fa3;
  --line: rgba(255, 255, 255, 0.14);
  --accent: #3d5bff;
  --sans: "Space Grotesk", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { background: var(--bg); }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
body.is-intro { overflow: hidden; }

.mono { font-family: var(--mono); font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; }

#gl {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  z-index: 0;
}

#scroll-track { height: 1000vh; }

/* ---------- Loader ---------- */
#loader {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  pointer-events: none;
}
#loader .wire {
  width: min(78vmin, 640px);
  height: auto;
  overflow: visible;
}
#loader line,
#loader circle,
#loader path {
  fill: none;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  animation: draw 1.1s var(--ease-out) forwards;
  animation-delay: var(--d, 0s);
}
#loader .guides * { stroke: rgba(255, 255, 255, 0.22); stroke-width: 0.8; }
#loader .guides .faint { stroke: rgba(255, 255, 255, 0.1); }
#loader .mark path { stroke-linejoin: round; stroke-linecap: round; }
#loader #z-outer { stroke: #fff; stroke-width: 7; }
#loader #z-inner { stroke: var(--bg); stroke-width: 3.4; }
#loader .mark { transform-origin: 300px 300px; transition: filter 0.4s ease; }
#loader #portal-origin { animation: none; stroke: none; }

@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes undraw { from { stroke-dashoffset: 0; } to { stroke-dashoffset: -1; } }

/* exit: guides retract (staggered), Z outline glows before the 3D one takes over */
#loader.exit .guides line,
#loader.exit .guides circle {
  animation: undraw 0.7s cubic-bezier(0.7, 0, 0.84, 0) forwards;
  animation-delay: calc(var(--d, 0s) * 0.6);
}
#loader.exit .mark { filter: drop-shadow(0 0 6px rgba(140, 170, 255, 0.9)) drop-shadow(0 0 22px rgba(90, 120, 255, 0.6)); }

.loader-label { transition: opacity 0.4s; }
#loader.idle .loader-label { animation: breathe 2.4s ease-in-out infinite; }
#loader.exit .loader-label { opacity: 0; animation: none; }
@keyframes breathe { 50% { opacity: 0.45; } }

.loader-label {
  position: absolute;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  color: var(--muted);
}

/* ---------- Nav ---------- */
.nav {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px clamp(16px, 3vw, 40px);
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.8s var(--ease-out), transform 0.8s var(--ease-out);
}
body.is-ready .nav { opacity: 1; transform: none; }
.brand { color: var(--fg); text-decoration: none; font-weight: 700; font-size: 18px; letter-spacing: 0.04em; }
.brand span { color: var(--muted); font-weight: 400; }
.nav nav { display: flex; gap: 28px; }
.nav nav a { color: var(--fg); text-decoration: none; font-family: var(--mono); font-size: 12px; opacity: 0.8; }
.nav nav a:hover { opacity: 1; }

.pill {
  font: 500 12px var(--mono);
  color: var(--fg);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 999px;
  padding: 8px 16px;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s var(--ease-out);
}
.pill:hover { background: rgba(255, 255, 255, 0.12); }
.pill:active { transform: scale(0.97); }

/* ---------- Quaternion readout (nod to the original's debug panel) ---------- */
.quat {
  position: fixed;
  top: 86px;
  right: clamp(16px, 3vw, 40px);
  z-index: 10;
  text-align: right;
  color: var(--muted);
  font-size: 10px;
  opacity: 0;
  transition: opacity 0.8s 0.2s;
}
.quat-title { color: var(--fg); margin-bottom: 4px; }
body.is-ready .quat { opacity: 1; }

/* ---------- Copy blocks ---------- */
.hero-copy,
.work-copy {
  position: fixed;
  z-index: 10;
  left: clamp(16px, 3vw, 40px);
  bottom: clamp(24px, 6vh, 64px);
  max-width: 420px;
  pointer-events: none;
  transition: opacity 0.6s var(--ease-out), transform 0.6s var(--ease-out);
}
.eyebrow { color: var(--muted); margin-bottom: 12px; }
.hero-copy h1 { font-size: clamp(32px, 4.4vw, 56px); line-height: 1.02; font-weight: 700; letter-spacing: -0.02em; }
.scroll-hint { margin-top: 18px; color: var(--fg); opacity: 0.7; }

.hero-copy, .work-copy { opacity: 0; transform: translateY(12px); }
body.is-ready.phase-hero .hero-copy { opacity: 1; transform: none; }
body.is-ready.phase-works .work-copy { opacity: 1; transform: none; }

.work-copy h2 { font-size: clamp(28px, 3.6vw, 44px); font-weight: 700; letter-spacing: -0.02em; line-height: 1.05; }
.work-copy p#work-desc { margin-top: 10px; color: var(--muted); font-size: 15px; line-height: 1.5; }
.work-copy.swap h2,
.work-copy.swap #work-desc { animation: swap 0.5s var(--ease-out); }
@keyframes swap { from { opacity: 0; transform: translateY(8px); filter: blur(4px); } }

/* ---------- Progress ---------- */
.progress {
  position: fixed;
  z-index: 10;
  left: clamp(16px, 3vw, 40px);
  top: 50%;
  width: 2px;
  height: 120px;
  transform: translateY(-50%);
  background: var(--line);
  opacity: 0;
  transition: opacity 0.8s;
}
body.is-ready .progress { opacity: 1; }
.progress i { position: absolute; left: 0; top: 0; width: 100%; height: 100%; background: var(--fg); transform-origin: top; transform: scaleY(0); }

/* ---------- Controls ---------- */
.panel {
  position: fixed;
  z-index: 15;
  right: clamp(16px, 3vw, 40px);
  bottom: clamp(16px, 4vh, 40px);
  width: 250px;
  padding: 12px 14px;
  background: rgba(10, 11, 20, 0.62);
  border: 1px solid var(--line);
  border-radius: 12px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  opacity: 0;
  transition: opacity 0.8s 0.3s;
}
body.is-ready .panel { opacity: 1; }
.panel summary { cursor: pointer; color: var(--fg); list-style: none; }
.panel summary::before { content: "▸ "; }
.panel[open] summary::before { content: "▾ "; }
.panel label {
  display: grid;
  grid-template-columns: 82px 1fr 40px;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  font: 11px var(--mono);
  color: var(--muted);
}
.panel output { text-align: right; color: var(--fg); }
.panel input[type="range"] { width: 100%; accent-color: var(--accent); }
.panel .pill { margin-top: 12px; width: 100%; }

@media (max-width: 700px) {
  .nav nav { display: none; }
  .quat { display: none; }
  .panel { width: auto; left: 16px; right: 16px; bottom: 16px; }
  .panel:not([open]) { left: auto; }
  .hero-copy, .work-copy { bottom: 150px; right: 16px; }
  .progress { display: none; }
}

/* soft shade behind the bottom-left copy so it stays readable over the LED wall */
body::after {
  content: "";
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: 45vh;
  z-index: 5;
  pointer-events: none;
  background: linear-gradient(to top, rgba(3, 3, 8, 0.85), rgba(3, 3, 8, 0));
  opacity: 0;
  transition: opacity 0.8s;
}
body.is-ready.phase-works::after { opacity: 1; }

/* reduced motion: no line drawing / pulsing / sliding copy - just show and fade */
@media (prefers-reduced-motion: reduce) {
  #loader line,
  #loader circle,
  #loader path { animation: none; stroke-dashoffset: 0; }
  #loader.idle .loader-label { animation: none; }
  #loader.exit .guides line,
  #loader.exit .guides circle { animation: none; opacity: 0; }
  .hero-copy, .work-copy, .nav { transform: none !important; }
  .work-copy.swap h2,
  .work-copy.swap #work-desc { animation: none; }
}
