/* ── Design tokens ──────────────────────────────────────────────────────────── */
:root {
  /* Background layers — darker as you go deeper */
  --color-background:         #06070D;
  --color-surface:            #0A0C14;
  --color-surface-raised:     #0E1018;

  /* Border tones */
  --color-border-transparent: #14172200; /* invisible — used only for axis lines */
  --color-border-subtle:      #14172290; /* very faint visible border */
  --color-border-strong:      #222638;   /* standard card/divider border */

  /* Text tones */
  --color-text:               #EAE5DA;   /* primary readable text */
  --color-text-secondary:     #9895A4;   /* labels, subtext */
  --color-text-muted:         #6A6878;   /* footnotes, disabled states */

  /* Brand + signal colors */
  --color-amber:              #C8902A;   /* primary accent / overvalued signal */
  --color-amber-bright:       #E6A634;   /* hover / high-emphasis overvalued */
  --color-green:              #27B87A;   /* fair value / live indicator */
  --color-cobalt:             #4192F2;   /* undervalued signal */
  --color-crimson:            #D63E3E;   /* error / warning */
}

/* ── Reset ──────────────────────────────────────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

/* ── Base ───────────────────────────────────────────────────────────────────── */
html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: 'DM Sans', -apple-system, sans-serif;
  background: var(--color-background);
  color: var(--color-text);
  min-height: 100vh;
  overflow-x: hidden;
}

/* Subtle dot-grid texture overlaid on the full page background */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: radial-gradient(circle, #1E2030 1px, transparent 1px);
  background-size: 36px 36px;
  opacity: 0.28;
  pointer-events: none;
  z-index: 0;
}

/* Film-grain texture applied on top of the dot grid */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.72' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23g)' opacity='0.45'/%3E%3C/svg%3E");
  opacity: 0.038;
  pointer-events: none;
  z-index: 1;
  mix-blend-mode: screen;
}

/* ── Hero ───────────────────────────────────────────────────────────────────── */
.hero {
  padding: 80px 52px 40px;
  max-width: 1400px;
  margin: 0 auto;
  position: relative;
  z-index: 2;
}

.hero-eyebrow {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--color-text-secondary);
  margin-bottom: 22px;
}

.live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-green);
  box-shadow: 0 0 10px var(--color-green);
  animation: livepulse 2.8s ease-in-out infinite;
  flex-shrink: 0;
}

@keyframes livepulse {
  0%, 100% { opacity: 1;   box-shadow: 0 0 10px var(--color-green); }
  50%       { opacity: 0.4; box-shadow: 0 0 3px  var(--color-green); }
}

.hero-title {
  font-family: 'Cormorant Garant', Georgia, serif;
  font-size: clamp(60px, 9vw, 108px);
  font-weight: 600;
  line-height: 0.9;
  letter-spacing: -0.02em;
  color: var(--color-text);
  margin-bottom: 28px;
}

.hero-title em {
  font-style: italic;
  color: var(--color-amber);
}

.hero-rule {
  width: 48px;
  height: 1px;
  background: var(--color-amber);
  margin-bottom: 20px;
  opacity: 0.8;
}

.hero-desc {
  font-size: 14px;
  color: var(--color-text-secondary);
  line-height: 1.65;
  max-width: 520px;
  margin-bottom: 10px;
}

.hero-formula {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--color-text-secondary);
  letter-spacing: 0.04em;
}

/* ── Stats bar ──────────────────────────────────────────────────────────────── */
.stats-bar {
  display: flex;
  gap: 12px;
  padding: 0 52px 56px;
  max-width: 1400px;
  margin: 0 auto;
  flex-wrap: wrap;
  position: relative;
  z-index: 2;
}

.stat {
  background: var(--color-surface);
  border: 1px solid var(--color-border-subtle);
  border-left: 2px solid var(--color-border-strong);
  padding: 22px 28px 18px;
  flex: 1;
  min-width: 170px;
  position: relative;
  transition: border-left-color 0.5s ease;
}

.stat-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--color-text-secondary);
  margin-bottom: 12px;
}

.stat-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 34px;
  font-weight: 400;
  color: var(--color-text);
  line-height: 1;
  letter-spacing: -0.03em;
  transition: color 0.4s ease;
}

/* Valuation signal classes — applied dynamically by JavaScript */
.stat-value.overvalued  { color: var(--color-amber-bright); }
.stat-value.fair        { color: var(--color-green); }
.stat-value.undervalued { color: var(--color-cobalt); }

.stat-sub {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  color: var(--color-text-secondary);
  margin-top: 9px;
  letter-spacing: 0.02em;
}

/* ── Chart area ─────────────────────────────────────────────────────────────── */
.chart-container {
  padding: 0 52px 88px;
  max-width: 1400px;
  margin: 0 auto;
  position: relative;
  z-index: 2;
}

.chart-wrapper {
  background: var(--color-surface);
  border: 1px solid var(--color-border-subtle);
  border-radius: 2px;
  padding: 28px 28px 18px;
  position: relative;
}

.canvas-area {
  position: relative;
  width: 100%;
}

.canvas-area canvas { width: 100% !important; }

/* ── Chart legend ───────────────────────────────────────────────────────────── */
.legend-custom {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  padding-left: 2px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--color-text-secondary);
  cursor: pointer;
  user-select: none;
  letter-spacing: 0.03em;
  transition: color 0.15s;
}

.legend-item:hover { color: var(--color-text); }

.legend-swatch {
  width: 18px;
  height: 2px;
  border-radius: 1px;
  flex-shrink: 0;
}

/* Dashed swatches use a CSS custom property set inline via JS */
.legend-swatch.dashed {
  background: repeating-linear-gradient(90deg, var(--color) 0, var(--color) 4px, transparent 4px, transparent 8px);
}

/* ── Loading & error states ─────────────────────────────────────────────────── */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 400px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  color: var(--color-text-secondary);
  letter-spacing: 0.08em;
  gap: 14px;
}

.loading .spinner {
  width: 16px;
  height: 16px;
  border: 1.5px solid var(--color-border-strong);
  border-top-color: var(--color-amber);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  flex-shrink: 0;
}

@keyframes spin { to { transform: rotate(360deg); } }

.error {
  color: var(--color-crimson);
  padding: 24px;
  text-align: center;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  letter-spacing: 0.06em;
}

/* ── Time-range controls ────────────────────────────────────────────────────── */
.controls {
  display: flex;
  gap: 6px;
  margin-bottom: 18px;
  justify-content: flex-end;
}

.controls button {
  background: transparent;
  border: 1px solid var(--color-border-strong);
  color: var(--color-text-secondary);
  padding: 5px 16px;
  border-radius: 100px;
  cursor: pointer;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.08em;
  transition: all 0.15s;
}

.controls button:hover {
  border-color: var(--color-text-secondary);
  color: var(--color-text-secondary);
}

.controls button.active {
  background: var(--color-amber);
  border-color: var(--color-amber);
  color: var(--color-background);
  font-weight: 500;
}

/* ── Chart footnotes ────────────────────────────────────────────────────────── */
.source-note {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--color-text-muted);
  margin-top: 18px;
  padding-left: 2px;
  letter-spacing: 0.03em;
}

.tooltip-note {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--color-text-muted);
  margin-top: 6px;
  padding-left: 2px;
  letter-spacing: 0.03em;
}

/* ── Indicator sections ─────────────────────────────────────────────────────── */
.indicator-section {
  border-top: 1px solid var(--color-border-subtle);
  position: relative;
  z-index: 2;
}

.section-head {
  padding: 88px 52px 0;
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: flex-start;
  gap: 32px;
  position: relative;
}

.section-num {
  font-family: 'Cormorant Garant', Georgia, serif;
  font-size: 100px;
  font-weight: 600;
  line-height: 1;
  color: var(--color-border-strong);
  letter-spacing: -0.04em;
  flex-shrink: 0;
  user-select: none;
  margin-top: -8px;
}

.section-text {
  padding-top: 8px;
}

.section-text h2 {
  font-family: 'Cormorant Garant', Georgia, serif;
  font-size: clamp(34px, 4vw, 52px);
  font-weight: 600;
  color: var(--color-text);
  line-height: 1;
  letter-spacing: -0.015em;
  margin-bottom: 8px;
}

.section-text p {
  font-size: 13px;
  color: var(--color-text-secondary);
  margin-bottom: 6px;
}

.section-text .formula {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--color-text-secondary);
  letter-spacing: 0.03em;
}

.section-blurb {
  font-size: 14px;
  color: var(--color-text-secondary);
  line-height: 1.7;
  max-width: 700px;
  margin-top: 20px;
  margin-bottom: 8px;
}

/* ── No-JavaScript fallback ─────────────────────────────────────────────────── */
.noscript-notice {
  background: #0A0C14;
  border: 1px solid #222638;
  color: #9895A4;
  font-family: Georgia, serif;
  font-size: 14px;
  line-height: 1.7;
  max-width: 640px;
  margin: 40px auto;
  padding: 32px 40px;
  text-align: center;
}

.noscript-notice strong { color: #EAE5DA; }

/* ── Side navigation ───────────────────────────────────────────────────────── */
.side-nav {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  padding-left: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s cubic-bezier(0.19, 1, 0.22, 1);
}

.side-nav.visible {
  opacity: 1;
  pointer-events: auto;
}

.side-nav-track {
  display: flex;
  flex-direction: column;
  gap: 0;
  position: relative;
  padding: 12px 0;
}

/* Vertical rail */
.side-nav-track::before {
  content: '';
  position: absolute;
  left: 3px;
  top: 20px;
  bottom: 20px;
  width: 1px;
  background: linear-gradient(
    to bottom,
    transparent,
    var(--color-border-strong) 15%,
    var(--color-border-strong) 85%,
    transparent
  );
}

.side-nav-link {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 18px 14px 0;
  text-decoration: none;
  position: relative;
  cursor: pointer;
}

/* Pip on the rail — default state */
.side-nav-link::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--color-border-strong);
  flex-shrink: 0;
  position: relative;
  z-index: 2;
  transition: background 0.3s ease, box-shadow 0.3s ease, transform 0.3s ease;
}

.side-nav-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  white-space: nowrap;
  transition: color 0.3s ease, transform 0.2s ease, opacity 0.2s ease;
  opacity: 0;
  transform: translateX(-6px);
}

.side-nav:hover .side-nav-label {
  opacity: 1;
  transform: translateX(0);
}

/* Hover */
.side-nav-link:hover::before {
  background: var(--color-text-secondary);
  transform: scale(1.3);
}

.side-nav-link:hover .side-nav-label {
  color: var(--color-text-secondary);
}

/* Active — amber glow */
.side-nav-link.active::before {
  background: var(--color-amber);
  box-shadow: 0 0 10px var(--color-amber), 0 0 3px var(--color-amber);
  transform: scale(1.4);
}

.side-nav-link.active .side-nav-label {
  color: var(--color-amber);
  opacity: 1;
  transform: translateX(0);
}

/* ── Responsive — tablet (≤ 768px) ─────────────────────────────────────────── */
@media (max-width: 768px) {
  .side-nav {
    display: none;
  }

  .canvas-area {
    height: 300px !important;
  }

  .canvas-area canvas {
    height: 300px !important;
  }

  .hero {
    padding: 52px 20px 32px;
  }

  .hero-title {
    font-size: clamp(52px, 14vw, 80px);
    line-height: 0.92;
  }

  .stats-bar {
    padding: 0 20px 44px;
    gap: 8px;
  }

  .stat {
    flex: 1 1 calc(50% - 4px);
    min-width: 0;
    padding: 18px 16px 14px;
  }

  .stat-value {
    font-size: 26px;
  }

  .chart-container {
    padding: 0 20px 64px;
  }

  .chart-wrapper {
    padding: 20px 16px 14px;
  }

  .section-head {
    padding: 56px 20px 0;
    flex-direction: column;
    gap: 0;
  }

  .section-num {
    font-size: 56px;
    margin-top: 0;
    margin-bottom: -4px;
    line-height: 1;
  }

  .section-text {
    padding-top: 0;
  }

  .section-text h2 {
    font-size: clamp(28px, 7vw, 40px);
  }

  .section-blurb {
    font-size: 13px;
  }

  .controls {
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 4px;
  }

  .controls button {
    padding: 5px 12px;
    font-size: 10px;
  }

  .legend-custom {
    gap: 12px;
  }
}

/* ── Responsive — mobile (≤ 480px) ─────────────────────────────────────────── */
@media (max-width: 480px) {
  .canvas-area {
    height: 260px !important;
  }

  .canvas-area canvas {
    height: 260px !important;
  }

  .hero {
    padding: 44px 16px 28px;
  }

  .stats-bar {
    padding: 0 16px 36px;
  }

  .stat {
    flex: 1 1 100%;
  }

  .chart-container {
    padding: 0 16px 52px;
  }

  .chart-wrapper {
    padding: 16px 12px 12px;
  }

  .section-head {
    padding: 48px 16px 0;
  }
}
