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

:root {
  --bg: #0b1018;
  --surface: #131b25;
  --border: rgba(255, 255, 255, 0.10);
  --text: #e9eef4;
  --muted: #95a3b2;
  --accent: #7fb4dd;
  --rule: rgba(255, 255, 255, 0.08);
  --serif: 'Instrument Serif', Georgia, serif;
  --sans: 'Instrument Sans', system-ui, sans-serif;
  --panel-h: 52px;
}

html {
  scroll-behavior: smooth;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-weight: 300;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

h1 {
  margin: auto;
}

.hero {
  position: relative;
  /* Scroll length of the hero scrub */
  min-height: 240vh;
}

.hero-stage {
  /* Native sticky pin */
  position: sticky;
  top: 0;
  width: 100%;
  height: 100vh;
  z-index: 0;
  overflow: hidden;
}

#hero-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.hero-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom,
      rgba(8, 14, 30, 0.55),
      rgba(8, 14, 30, 0.22) 42%,
      rgba(8, 14, 30, 0.70));
}

#hero-rain {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.hero-content {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 4vw 6vw;
  color: #fff;
  will-change: transform, opacity;
}

.hero-tag {
  font-size: 0.7rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.7);
  margin-bottom: 2rem;
  text-shadow: 0 1px 12px rgba(0, 0, 0, 0.5);
}

.hero h1 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(3rem, 7vw, 6.5rem);
  line-height: 1.05;
  max-width: 14ch;
  margin-bottom: 2.5rem;
  color: #fff;
  text-shadow: 0 2px 30px rgba(0, 0, 0, 0.65), 0 0 2px rgba(0, 0, 0, 0.4);
}

.hero h1 em {
  font-style: italic;
}

.hero-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 2.5rem;
  padding-top: 1.5rem;
  margin-top: 2rem;
  justify-content: center;
  border-top: 1px solid rgba(255, 255, 255, 0.25);
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.8);
  letter-spacing: 0.06em;
  text-shadow: 0 1px 10px rgba(0, 0, 0, 0.5);
}

.hero-scroll-hint {
  margin-top: 3rem;
  font-size: 0.75rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.7);
  animation: hint-bob 2.2s ease-in-out infinite;
}

@keyframes hint-bob {
  0%, 100% { transform: translateY(0); opacity: 0.6; }
  50% { transform: translateY(6px); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .hero-scroll-hint { animation: none; }
}

/* ─── SCROLLY WRAPPER ─── */
.scrolly {
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: start;
  max-width: 1400px;
  margin: 0 auto;
}

.viz-column, .steps-column {
  padding: 1.25rem 3rem;
}

/* ── LEFT: sticky visualization panel ── */
.viz-column {
  position: sticky;
  top: var(--panel-h);
  height: calc(100vh - var(--panel-h));
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding-top: 1rem;
  padding-bottom: 1rem;
  border-right: 1px solid var(--border);
}

.viz-frame {
  position: relative;
  width: 100%;
  /* Leave room for the legend below — don't let the square overflow */
  aspect-ratio: 1 / 1;
  max-height: calc(100vh - var(--panel-h) - 6rem);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  overflow: hidden;
}

.viz-panel {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.55s ease;
  pointer-events: none;
}

.viz-panel.active {
  opacity: 1;
  pointer-events: auto;
}

/* Progress dots */
.viz-dots {
  display: flex;
  gap: 6px;
  margin-top: 1.25rem;
}

.viz-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--border);
  transition: background 0.3s ease, transform 0.3s ease;
}

.viz-dot.active {
  background: var(--text);
  transform: scale(1.3);
}

/* ── RIGHT: scrolling steps ── */
.step {
  min-height: 65vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 4rem 0;
  border-bottom: 1px solid var(--rule);
}

.step:last-child {
  border-bottom: none;
}

.step-index {
  font-size: 0.65rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 2rem;
}

.step h2 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(1.8rem, 3vw, 2.75rem);
  line-height: 1.15;
  margin-bottom: 1.5rem;
}

.step h2 em {
  font-style: italic;
}

.step p {
  font-size: 1rem;
  color: var(--muted);
  max-width: 44ch;
  margin-bottom: 0.9rem;
}

.step p:last-of-type {
  margin-bottom: 0;
}

.footer {
  padding: 2.5rem 6vw;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.75rem;
  color: var(--muted);
  letter-spacing: 0.05em;
}

/* ─── RESPONSIVE ─── */
@media (max-width: 900px) {
  .scrolly {
    grid-template-columns: 1fr;
  }

  .viz-column {
    position: relative;
    height: auto;
    border-right: none;
    border-left: none;
    border-bottom: 1px solid var(--border);
    padding: 2rem;
    padding-top: 2rem;
  }

  .scrolly--flipped .viz-column {
    border-left: none;
    border-bottom: 1px solid var(--border);
  }

  .viz-frame {
    aspect-ratio: 4/3;
    top: 0;
  }

  .step {
    min-height: auto;
    padding: 3rem 2rem;
  }
}

@media (max-width: 600px) {
  .hero h1 {
    font-size: clamp(2.2rem, 9vw, 3.6rem);
  }

  .hero-meta {
    gap: 1rem;
    font-size: 0.7rem;
  }

  .section-break {
    padding: 2.5rem 1.5rem 2rem;
  }

  .step {
    padding: 2.5rem 1.5rem;
  }

  .chart-section {
    padding: 0 1rem;
  }
}

@media (max-width: 500px) {
  .footer {
    flex-direction: column;
    gap: 0.5rem;
    text-align: center;
    padding: 2rem 1.5rem;
  }
}

/* ─── FLIPPED SCROLLY: viz on right ─── */
.scrolly--flipped .viz-column {
  border-right: none;
  border-left: 1px solid var(--border);
}

/* ─── SECTION BREAK ─── */
.section-break {
  max-width: 640px;
  margin: auto;
  padding: 3.5rem 2rem 3rem;
  text-align: center;
  border-top: 1px solid var(--border);
}

.section-break-label {
  font-size: 0.65rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 1.25rem;
}

.section-break h2 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(1.6rem, 2.5vw, 2.4rem);
  line-height: 1.25;
  margin-bottom: 1.25rem;
}

.section-break h2 em {
  font-style: italic;
}

.section-break p {
  font-size: 1rem;
  color: var(--muted);
  line-height: 1.7;
}

.visualization {
  width: 100%;
  height: 100%;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
}

.viz-stats {
  margin-top: 0.7rem;
  min-height: 2.2rem;
}

/* ─── NUMERIC LEGENDS (replace the in-canvas color bar + stats text) ─── */
.legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.35rem 0.8rem;
  font-family: var(--sans);
  font-size: 0.68rem;
  font-weight: 300;
  letter-spacing: 0.01em;
  color: var(--muted);
}

.legend .legend-label {
  font-weight: 500;
  color: var(--text);
}

.legend .sw {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  white-space: nowrap;
}

.legend .sw i {
  width: 14px;
  height: 10px;
  border-radius: 2px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}

.legend .ramp {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  white-space: nowrap;
}

.legend .ramp .bar {
  width: 120px;
  height: 10px;
  border-radius: 2px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2);
}

/* ─── CHART SECTION (volo ocean-volume chart) ─── */
.chart-section {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 100%;
  max-width: 1000px;
  margin: 2rem auto 3rem;
  padding: 0 2rem;
}

.chart-section #volo-container {
  width: 100%;
  height: auto;
}

#volo-container .tick text {
  fill: #aeb9c5;
}
#volo-container .domain,
#volo-container .tick line {
  stroke: rgba(255, 255, 255, 0.22);
}

.section-break.no-rule {
  border-top: none;
}

/* ─── PRECIPITATION SECTION + RAIN OVERLAY ─── */
.prec-section {
  position: relative;
}


#prec-section .scrolly {
  position: relative;
}

#prec-section .scrolly::before {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: min(640px, 100%);
  border-top: 1px solid var(--border);
}

#rain-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5;
  display: block;
}

#prec-viz-and-stats {
  gap: 0.6rem;
  padding: 0.75rem;
}

#prec-container {
  flex: 1 1 auto;
  min-height: 0;
  height: auto;
  overflow: hidden;
  cursor: grab;
}

#prec-container:active {
  cursor: grabbing;
}

#prec-canvas {
  touch-action: none;
}

.prec-region-panel {
  flex: 0 0 auto;
  width: 100%;
  margin-top: 0;
  text-align: left;
}

.prec-region-topline {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
  font-size: 0.68rem;
}

#prec-region-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
}

#prec-region-mean {
  color: var(--text);
  font-weight: 500;
  white-space: nowrap;
}

#prec-reset-btn {
  border: 1px solid var(--border);
  border-radius: 4px;
  background: transparent;
  color: var(--text);
  font: 500 0.68rem var(--sans);
  padding: 2px 8px;
  cursor: pointer;
}

#prec-reset-btn:hover {
  background: rgba(255, 255, 255, 0.10);
}

.prec-mean-chart {
  width: 100%;
  height: 110px;
  margin-top: 0.35rem;
}

.prec-region-panel .legend {
  justify-content: flex-start;
  gap: 0.3rem 0.55rem;
}