:root {
  --bg: #02040a;
  --ink: #eef4ff;
  --muted: #9aa9c4;
  --dim: #5f6e8a;
  --line: rgba(150, 180, 235, 0.14);
  --line-strong: rgba(150, 200, 255, 0.32);
  --glass: rgba(7, 12, 26, 0.55);
  --cyan: #7fe3ff;
  --gold: #ffc978;
  --magenta: #ff7ad9;
  --mint: #8ff5c4;
  --violet: #b9a4ff;
  --sans: "Inter Tight", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --gutter: clamp(18px, 4vw, 64px);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 1.5px solid var(--cyan); outline-offset: 3px; border-radius: 8px; }

/* ---------- Layers ---------- */

#scene {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: block;
  touch-action: none;
  cursor: grab;
}
#scene.dragging { cursor: grabbing; }
#scene.hovering { cursor: pointer; }

#overlay, #labels, .atmosphere-veil, .grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
}
#overlay { width: 100%; height: 100%; overflow: visible; }

.atmosphere-veil {
  background:
    linear-gradient(90deg, rgba(2, 4, 10, 0.88) 0%, rgba(2, 4, 10, 0.55) 26%, rgba(2, 4, 10, 0) 52%),
    linear-gradient(0deg, rgba(2, 4, 10, 0.85) 0%, rgba(2, 4, 10, 0) 22%),
    linear-gradient(180deg, rgba(2, 4, 10, 0.6) 0%, rgba(2, 4, 10, 0) 16%);
}

.grain {
  opacity: 0.07;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ---------- Masthead ---------- */

.masthead {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: calc(env(safe-area-inset-top) + 26px) var(--gutter) 0;
  pointer-events: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--ink);
  text-decoration: none;
  pointer-events: auto;
}
.mark { width: 28px; height: 28px; color: var(--ink); }
.wordmark { font-weight: 600; font-size: 17px; letter-spacing: -0.02em; }
.divider { width: 1px; height: 16px; background: var(--line-strong); }
.tagline {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.status {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #c6d4ec;
}
.status-count { color: var(--dim); }
.live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--mint);
  box-shadow: 0 0 0 0 rgba(143, 245, 196, 0.6);
  animation: live 2s ease-out infinite;
}
@keyframes live {
  0% { box-shadow: 0 0 0 0 rgba(143, 245, 196, 0.55); }
  70%, 100% { box-shadow: 0 0 0 9px rgba(143, 245, 196, 0); }
}

/* ---------- Story ---------- */

.story {
  position: fixed;
  left: var(--gutter);
  top: 50%;
  transform: translateY(-54%);
  width: min(420px, 36vw);
  pointer-events: none;
}

.story > * {
  transition: opacity 0.5s cubic-bezier(.2, .7, .2, 1), transform 0.6s cubic-bezier(.2, .7, .2, 1), filter 0.5s;
}
.story > :nth-child(2) { transition-delay: 0.04s; }
.story > :nth-child(3) { transition-delay: 0.08s; }
.story > :nth-child(4) { transition-delay: 0.12s; }
.story > :nth-child(5) { transition-delay: 0.16s; }
.story.swap > * {
  opacity: 0;
  transform: translateY(10px);
  filter: blur(4px);
  transition-duration: 0.22s;
  transition-delay: 0s;
}

.eyebrow {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--cyan);
}
.eyebrow-index {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--ink);
}
.eyebrow-index::after {
  content: "";
  width: 28px;
  height: 1px;
  background: linear-gradient(90deg, var(--cyan), transparent);
}

.story h1 {
  margin: 22px 0 20px;
  font-size: clamp(44px, 5.4vw, 88px);
  line-height: 0.96;
  letter-spacing: -0.045em;
  font-weight: 600;
}
.story h1 em {
  font-style: normal;
  background: linear-gradient(100deg, #d8f6ff 0%, var(--cyan) 35%, var(--violet) 70%, var(--magenta) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.lede {
  margin: 0;
  max-width: 380px;
  font-size: 16px;
  line-height: 1.65;
  color: var(--muted);
}

.metric {
  display: flex;
  align-items: baseline;
  gap: 14px;
  margin-top: 30px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
  max-width: 340px;
}
.metric strong {
  font-size: 46px;
  line-height: 1;
  font-weight: 500;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
}
.metric span {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.coord {
  margin: 12px 0 0;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--dim);
}

/* ---------- Controls ---------- */

.controls {
  position: fixed;
  left: var(--gutter);
  right: var(--gutter);
  bottom: calc(env(safe-area-inset-bottom) + 26px);
  display: flex;
  align-items: flex-end;
  gap: 22px;
}

.timeline {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  flex: 1;
  max-width: 640px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.step {
  width: 100%;
  border: 0;
  background: none;
  padding: 0 2px 4px;
  text-align: left;
  color: var(--dim);
  transition: color 0.3s;
}
.step:hover { color: var(--muted); }
.step .bar {
  display: block;
  position: relative;
  height: 2px;
  margin-bottom: 12px;
  background: var(--line);
  border-radius: 2px;
  overflow: hidden;
}
.step .bar::after {
  content: "";
  position: absolute;
  inset: 0;
  transform-origin: left;
  transform: scaleX(var(--p, 0));
  background: linear-gradient(90deg, var(--cyan), #d8f6ff);
  box-shadow: 0 0 12px var(--cyan);
}
.step b {
  display: block;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.16em;
  margin-bottom: 5px;
}
.step .t-full, .step .t-short {
  font-size: 14px;
  font-weight: 500;
  letter-spacing: -0.01em;
}
.step[aria-current="step"] { color: var(--ink); }
.step .t-short { display: none; }

.buttons { display: flex; gap: 8px; margin-left: auto; }
.icon-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  background: var(--glass);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  backdrop-filter: blur(14px) saturate(140%);
  transition: border-color 0.2s, background 0.2s, transform 0.2s;
}
.icon-btn:hover { border-color: rgba(127, 227, 255, 0.6); background: rgba(18, 32, 60, 0.7); }
.icon-btn:active { transform: scale(0.95); }
.icon-btn svg { width: 18px; height: 18px; fill: currentColor; }
#toggle .i-play { display: none; }
#toggle.paused .i-play { display: block; }
#toggle.paused .i-pause { display: none; }

.hint, .credit {
  position: fixed;
  right: var(--gutter);
  margin: 0;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  pointer-events: none;
}
.hint { bottom: calc(env(safe-area-inset-bottom) + 92px); color: var(--muted); transition: opacity 0.6s; }
.hint.gone { opacity: 0; }
.credit-short { display: none; }
.credit { bottom: calc(env(safe-area-inset-bottom) + 8px); color: rgba(120, 136, 165, 0.6); letter-spacing: 0.08em; font-size: 9px; }

/* ---------- Node labels ---------- */

.label {
  position: absolute;
  left: 0;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px 9px 6px 10px;
  border: 1px solid var(--line);
  border-left: 2px solid var(--c, var(--cyan));
  border-radius: 4px 8px 8px 4px;
  background: rgba(4, 8, 20, 0.62);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.45s ease;
  will-change: transform, opacity;
}
.label.on { opacity: 1; }
.label b { font-size: 12px; font-weight: 600; letter-spacing: -0.005em; color: var(--ink); }
.label span {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ---------- Diamond overlay ---------- */

#overlay text {
  font-family: var(--mono);
  text-transform: uppercase;
  paint-order: stroke;
  stroke: rgba(2, 4, 10, 0.7);
  stroke-width: 3px;
  stroke-linejoin: round;
}
#overlay .d-name { font-size: 10.5px; letter-spacing: 0.16em; fill: #eef4ff; font-weight: 600; }
#overlay .d-sub { font-size: 9.5px; letter-spacing: 0.1em; fill: #8b9bb8; }
#overlay .d-cap { font-size: 9.5px; letter-spacing: 0.24em; fill: #7fe3ff; }

/* ---------- Tooltip ---------- */

.tooltip {
  position: fixed;
  left: 0;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 200px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: rgba(5, 10, 24, 0.82);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  backdrop-filter: blur(16px) saturate(140%);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, calc(-100% - 18px)) scale(0.98);
  transition: opacity 0.15s ease, transform 0.15s ease;
}
.tooltip.on { opacity: 1; transform: translate(-50%, calc(-100% - 22px)) scale(1); }
.tt-tier { font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--c, var(--cyan)); }
.tt-name { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.tt-place { font-size: 12.5px; color: var(--muted); }
.tt-coord { font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.1em; color: var(--dim); margin-top: 4px; }

/* ---------- Loader / fallbacks ---------- */

.loader {
  position: fixed;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  background: var(--bg);
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
  transition: opacity 1.1s ease, visibility 1.1s;
}
.loader i {
  display: block;
  width: 140px;
  height: 1px;
  background: var(--cyan);
  box-shadow: 0 0 10px var(--cyan);
  transform: scaleX(0.04);
  transform-origin: left;
  transition: transform 0.3s ease;
}
.ready .loader { opacity: 0; visibility: hidden; }

.no-webgl #scene { display: none; }
.no-webgl body {
  background:
    radial-gradient(ellipse at 65% 50%, rgba(40, 90, 180, 0.35), transparent 60%),
    var(--bg);
}
.no-webgl .loader span::after { content: " — WebGL unavailable"; }

.noscript {
  position: fixed;
  left: var(--gutter);
  bottom: 120px;
  color: var(--muted);
}

/* ---------- Responsive ---------- */

@media (max-width: 1100px) {
  .story { width: min(380px, 42vw); }
  .story h1 { font-size: clamp(40px, 5.6vw, 64px); }
  .lede { font-size: 15px; }
}

@media (max-width: 760px) {
  .masthead { padding-top: calc(env(safe-area-inset-top) + 18px); }
  .tagline, .divider, .status > span:not(.status-count) { display: none; }
  .story {
    top: calc(env(safe-area-inset-top) + 76px);
    transform: none;
    width: auto;
    right: var(--gutter);
  }
  .story h1 { font-size: clamp(36px, 10.5vw, 48px); margin: 14px 0 12px; }
  .lede { font-size: 13.5px; line-height: 1.55; max-width: 34ch; }
  .metric { margin-top: 16px; padding-top: 12px; }
  .metric strong { font-size: 32px; }
  .coord { display: none; }
  .atmosphere-veil {
    background:
      linear-gradient(180deg, rgba(2, 4, 10, 0.92) 0%, rgba(2, 4, 10, 0.6) 34%, rgba(2, 4, 10, 0) 56%),
      linear-gradient(0deg, rgba(2, 4, 10, 0.9) 0%, rgba(2, 4, 10, 0) 24%);
  }
  .controls { bottom: calc(env(safe-area-inset-bottom) + 30px); gap: 14px; }
  .step .t-full { display: none; }
  .step .t-short { display: inline; font-size: 13px; }
  .credit-long { display: none; }
  .credit-short { display: inline; }
  .icon-btn { width: 40px; height: 40px; }
  .hint { display: none; }
  .credit { right: auto; left: var(--gutter); }
}

@media (max-height: 640px) and (min-width: 761px) {
  .lede { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .live-dot { animation: none; }
  .story > *, .label, .tooltip, .loader { transition: none; }
}
