:root {
  --bg: #06070c;
  --ink: #ece9e1;
  --ink-dim: rgba(236, 233, 225, 0.68);
  --ink-faint: rgba(236, 233, 225, 0.42);
  --gold: #f2c46d;
  --cyan: #8fd8ff;
  --line: rgba(255, 255, 255, 0.08);
  --serif: "Instrument Serif", "Iowan Old Style", Georgia, serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-weight: 300;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

#stars {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}

/* ---- nav dots ---- */
.dots {
  position: fixed;
  right: 22px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 14px;
  z-index: 10;
}
.dots a {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.22);
  transition: background 0.4s, transform 0.4s;
}
.dots a.on {
  background: var(--gold);
  transform: scale(1.5);
}
@media (max-width: 860px) { .dots { display: none; } }

/* ---- hero ---- */
.hero {
  position: relative;
  height: 100vh;
  height: 100svh;
  min-height: 560px;
  overflow: hidden;
  z-index: 1;
}
.hero canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
.hero-shade {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse 34% 26% at 50% 40%, rgba(6, 7, 12, 0.5), rgba(6, 7, 12, 0) 100%);
}
.tc { display: none; }
@media (hover: none) and (pointer: coarse) {
  .pt { display: none; }
  .tc { display: inline; }
}
.hero-text {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  pointer-events: none;
  padding: 0 6vw 24vh;
}
.hero h1 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(88px, 17vw, 240px);
  line-height: 0.9;
  margin: 0 0 28px;
  letter-spacing: -0.03em;
  color: var(--ink);
  text-shadow: 0 0 60px rgba(6, 7, 12, 0.9), 0 0 120px rgba(6, 7, 12, 0.9);
  animation: rise 1.6s cubic-bezier(.2,.7,.2,1) both;
}
.hero p {
  max-width: 520px;
  text-wrap: balance;
  font-size: clamp(16px, 1.35vw, 19px);
  line-height: 1.6;
  color: rgba(236, 233, 225, 0.9);
  margin: 0;
  text-shadow: 0 0 12px rgba(6, 7, 12, 1), 0 0 30px rgba(6, 7, 12, 1), 0 0 60px rgba(6, 7, 12, 1);
  animation: rise 1.6s 0.25s cubic-bezier(.2,.7,.2,1) both;
}
.hero .hint {
  position: absolute;
  bottom: 34px;
  left: 0; right: 0;
  max-width: none;
  text-align: center;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-faint);
  animation: rise 1.6s 0.6s cubic-bezier(.2,.7,.2,1) both, pulse 3s 2s ease-in-out infinite;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(18px); }
  to { opacity: 1; transform: none; }
}
@keyframes pulse {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}

/* ---- sections ---- */
.sec {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(280px, 400px) minmax(0, 1fr);
  gap: clamp(32px, 5vw, 80px);
  align-items: center;
  padding: 10vh clamp(24px, 6vw, 96px);
}
.sec.flip { grid-template-columns: minmax(0, 1fr) minmax(280px, 400px); }
.sec.flip .copy { order: 2; }

.copy {
  opacity: 0;
  transform: translateY(22px);
  transition: opacity 1.1s cubic-bezier(.2,.7,.2,1), transform 1.1s cubic-bezier(.2,.7,.2,1);
}
.copy.in { opacity: 1; transform: none; }

.num {
  display: block;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.2em;
  color: var(--gold);
  margin-bottom: 22px;
}
.num::after {
  content: "";
  display: inline-block;
  width: 36px;
  height: 1px;
  background: var(--gold);
  margin-left: 14px;
  vertical-align: middle;
  opacity: 0.6;
}
h2 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(36px, 3.4vw, 54px);
  line-height: 1.04;
  letter-spacing: -0.015em;
  margin: 0 0 22px;
}
.copy p {
  font-size: 17px;
  line-height: 1.65;
  color: var(--ink-dim);
  margin: 0 0 18px;
  max-width: 42ch;
}
.copy .eq {
  font-family: var(--serif);
  font-style: italic;
  font-size: 26px;
  color: var(--ink);
  letter-spacing: 0.01em;
  margin: 26px 0 22px;
}
.copy .eq sub { font-size: 0.55em; font-style: normal; }
.copy .foot {
  font-size: 14px;
  color: var(--ink-faint);
}

.stage {
  position: relative;
  width: 100%;
  height: clamp(380px, 72vh, 820px);
  border-radius: 20px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255,255,255,0.025), rgba(255,255,255,0.006));
  overflow: hidden;
  box-shadow: 0 40px 120px -40px rgba(0, 0, 0, 0.8), inset 0 1px 0 rgba(255,255,255,0.05);
}
.stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* ---- controls ---- */
.controls {
  position: absolute;
  left: 18px;
  bottom: 18px;
  display: flex;
  gap: 10px;
  align-items: center;
  z-index: 2;
}
.controls.col { flex-direction: column; align-items: flex-start; gap: 10px; }
.controls.tr { left: auto; bottom: auto; right: 18px; top: 18px; }
.stage-col { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.stage-col .stage { height: clamp(340px, 64vh, 760px); }
.stage-col .controls { position: static; flex-direction: column; align-items: flex-start; gap: 10px; padding: 0 4px; }
.stage-col .readout { position: static; white-space: nowrap; }
.seg {
  display: inline-flex;
  padding: 3px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(6, 7, 12, 0.6);
  backdrop-filter: blur(10px);
}
button {
  font: inherit;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-dim);
  background: transparent;
  border: 0;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.3s, color 0.3s;
}
.seg button.on { background: rgba(255, 255, 255, 0.1); color: var(--ink); }
button.ghost {
  border: 1px solid var(--line);
  background: rgba(6, 7, 12, 0.6);
  backdrop-filter: blur(10px);
  padding: 11px 16px;
}
button.ghost:hover { color: var(--ink); border-color: rgba(255,255,255,0.2); }
button.ghost.on { color: var(--gold); border-color: rgba(242, 196, 109, 0.5); }

.readout {
  position: absolute;
  left: 18px;
  bottom: 18px;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.06em;
  color: var(--ink-dim);
  padding: 9px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(6, 7, 12, 0.6);
  backdrop-filter: blur(10px);
  z-index: 2;
  white-space: nowrap;
}
.controls .readout { position: static; }
.readout b { color: var(--gold); font-weight: 400; }

.slider {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(6, 7, 12, 0.6);
  backdrop-filter: blur(10px);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-dim);
}
.slider { padding-bottom: 22px; align-items: flex-start; }
.slider > span:first-child { padding-top: 1px; }
.track { position: relative; display: block; width: 200px; }
.track .tick {
  position: absolute;
  top: 14px;
  transform: translateX(-50%);
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--ink-faint);
  text-align: center;
  white-space: nowrap;
}
.track .tick i { display: block; width: 1px; height: 5px; margin: 0 auto 3px; background: rgba(255,255,255,0.35); }
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 200px;
  display: block;
  height: 2px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 0 4px rgba(242, 196, 109, 0.18);
  cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px; border: 0; border-radius: 50%;
  background: var(--gold); cursor: pointer;
}

/* ---- coda ---- */
.coda {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 10vh 6vw;
  overflow: hidden;
}
.coda canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
.coda-text {
  position: relative;
  z-index: 0;
  opacity: 0;
  transform: translateY(22px);
  transition: opacity 1.4s cubic-bezier(.2,.7,.2,1), transform 1.4s cubic-bezier(.2,.7,.2,1);
}
.coda-text.in { opacity: 1; transform: none; }
.coda-text::before {
  content: "";
  position: absolute;
  inset: -40% -18%;
  z-index: -1;
  background: radial-gradient(ellipse 60% 55% at 50% 50%, rgba(6, 7, 12, 0.82), rgba(6, 7, 12, 0) 100%);
  pointer-events: none;
}
.coda-text p {
  font-family: var(--serif);
  font-size: clamp(34px, 4.6vw, 72px);
  line-height: 1.1;
  margin: 0;
  letter-spacing: -0.015em;
}
.coda-text .dim { color: var(--ink-faint); font-style: italic; margin-top: 12px; }
.credit {
  position: absolute;
  bottom: 28px;
  left: 0; right: 0;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--ink-faint);
}

@media (max-width: 860px) {
  .sec, .sec.flip { grid-template-columns: 1fr; padding: 6vh 20px; gap: 22px; min-height: 0; align-content: center; }
  .sec.flip .copy { order: 0; }
  .stage, .stage-col .stage { height: min(52vh, 460px); }
  .copy p { font-size: 15px; margin-bottom: 12px; }
  .copy .eq { font-size: 22px; margin: 14px 0 12px; }
  .num { margin-bottom: 12px; }
  h2 { font-size: clamp(30px, 8vw, 40px); margin-bottom: 12px; }
  .hero-text { justify-content: flex-end; padding-bottom: 18vh; }
  .hero h1 { margin-bottom: 18px; }
  .hero-shade { background: radial-gradient(ellipse 80% 30% at 50% 72%, rgba(6, 7, 12, 0.7), rgba(6, 7, 12, 0) 100%); }
  .track, input[type="range"] { width: 150px; }
  .readout { font-size: 11px; white-space: normal; max-width: calc(100% - 36px); }
  .stage-col .readout { white-space: nowrap; max-width: none; }
  .controls { max-width: calc(100% - 36px); }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .hero h1, .hero p, .hero .hint { animation: none; }
}
