:root {
  --ink: #0c1419;
  --text: #f4f7f8;
  --muted: #9fb0ba;
  --steel-dark: #2c4f66;
  --steel: #3d6d8c;
  --steel-light: #789aae;
  --stone: #b3a7a3;
  --clarity: #4bd5fe;
  --digital: #2a86b4;
  --mustard: #dc7e2b;
  --rust: #c23e1b;
  --line: rgba(159, 176, 186, 0.18);
  --surface: rgba(255, 255, 255, 0.04);
  --surface-2: rgba(255, 255, 255, 0.07);
  --r: 14px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
html { scroll-behavior: smooth; }

body {
  font-family: "Inter", system-ui, sans-serif;
  color: var(--text);
  background:
    radial-gradient(130% 80% at 50% 0%, #1a2c37 0%, #101b22 42%, #070c10 100%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ---- Masthead ---- */
.masthead {
  position: relative;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: clamp(18px, 3vw, 30px) clamp(18px, 5vw, 56px);
}
.wordmark { color: var(--text); display: inline-flex; }
.wordmark svg { height: 21px; width: auto; display: block; }
.kicker {
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--steel-light);
  font-weight: 500;
}

/* ---- Hero ---- */
.hero {
  max-width: 1100px;
  margin: 0 auto;
  padding: clamp(40px, 9vh, 110px) clamp(18px, 5vw, 56px) clamp(30px, 7vh, 80px);
  text-align: center;
}
.hero-eyebrow {
  font-size: 12px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--steel-light);
  font-weight: 500;
  margin: 0 0 1.2rem;
}
.hero h1 {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 500;
  font-size: clamp(2.6rem, 8vw, 6rem);
  line-height: 0.98;
  letter-spacing: -0.02em;
  margin: 0 0 1rem;
  text-wrap: balance;
}
.hero-lede {
  font-size: clamp(1.05rem, 1.7vw, 1.3rem);
  line-height: 1.55;
  color: var(--muted);
  margin: 0 auto;
  max-width: 56ch;
  text-wrap: pretty;
}
.scroll-cue {
  margin-top: clamp(2rem, 5vh, 4rem);
  font-size: 11.5px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  opacity: 0.8;
}
.scroll-cue::after {
  content: "↓";
  display: block;
  margin-top: 0.6rem;
  font-size: 16px;
  animation: bob 1.8s var(--ease) infinite;
}
@keyframes bob { 0%,100%{transform:translateY(0)} 50%{transform:translateY(6px)} }

/* ---- Scrollytelling layout ---- */
.scrolly {
  position: relative;
  display: grid;
  /* minmax(0,...) lets the columns shrink below the canvas's intrinsic width
     instead of blowing the layout out past the viewport on small screens */
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
  max-width: 1320px;
  margin: 0 auto;
  padding: 0 clamp(18px, 4vw, 48px);
  align-items: stretch; /* stage column must span full height so its sticky child sticks */
}
.stage-col { position: relative; height: 100%; }
.stage-wrap {
  position: sticky;
  top: 0;
  height: 100vh;
  width: 100%;
  overflow: hidden;
}
#stage, #overlay { position: absolute; inset: 0; width: 100%; height: 100%; }
#stage { display: block; touch-action: none; cursor: grab; }
#stage:active { cursor: grabbing; }
#overlay { pointer-events: none; }

/* leader-line labels */
.leader-lines { position: absolute; inset: 0; pointer-events: none; }
.leader { stroke: var(--steel-light); stroke-width: 1; stroke-dasharray: 2 3; }
.label-layer { position: absolute; inset: 0; }
.part-label {
  position: absolute;
  top: 0; left: 0;
  display: flex; align-items: center; gap: 7px;
  white-space: nowrap;
  font-size: 12.5px; font-weight: 500;
  color: var(--text);
  background: rgba(10, 17, 22, 0.72);
  backdrop-filter: blur(6px);
  border: 1px solid var(--line);
  padding: 5px 10px;
  border-radius: 999px;
  transition: opacity 0.3s var(--ease);
  will-change: transform;
}
.part-label .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--clarity); box-shadow: 0 0 8px var(--clarity);
}

/* ---- Chapters column ---- */
.chapters { position: relative; z-index: 2; }
.chapter {
  min-height: 100vh;
  display: flex;
  align-items: center;
  padding: 6vh 0 6vh clamp(20px, 4vw, 70px);
}
.chapter-inner {
  background: rgba(10, 17, 22, 0.55);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: clamp(22px, 3vw, 36px);
  max-width: 520px;
  min-width: 0; /* allow shrink below widget min-content instead of overflowing */
  opacity: 0.35;
  transform: translateY(14px);
  transition: opacity 0.6s var(--ease), transform 0.6s var(--ease);
}
.chapter.is-active .chapter-inner { opacity: 1; transform: none; }
.ch-eyebrow {
  font-size: 11.5px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--clarity);
  font-weight: 600;
  margin: 0 0 0.9rem;
}
.ch-title {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 500;
  font-size: clamp(1.7rem, 3vw, 2.5rem);
  line-height: 1.05;
  letter-spacing: -0.015em;
  margin: 0 0 0.8rem;
  text-wrap: balance;
}
.ch-body {
  font-size: clamp(1rem, 1.3vw, 1.1rem);
  line-height: 1.6;
  color: var(--muted);
  margin: 0;
  text-wrap: pretty;
}
.widget-card {
  margin-top: 1.6rem;
  padding: 16px;
  background: rgba(6, 11, 15, 0.5);
  border: 1px solid var(--line);
  border-radius: 12px;
  min-height: 220px;
  min-width: 0;
  overflow: hidden; /* clip any fixed-width widget internals so the page never scrolls sideways */
}
.widget-card canvas,
.widget-card svg {
  max-width: 100%;
}

/* ---- Readout (finale) ---- */
.readout {
  position: absolute;
  right: 16px; bottom: 92px;
  display: flex; align-items: flex-end; gap: 18px;
  padding: 13px 16px;
  background: rgba(8, 13, 17, 0.62);
  border: 1px solid var(--line);
  border-radius: var(--r);
  backdrop-filter: blur(10px);
  opacity: 0; transform: translateY(8px);
  transition: opacity 0.4s var(--ease), transform 0.4s var(--ease);
  pointer-events: none;
}
.readout.show { opacity: 1; transform: none; }
.metric { display: flex; flex-direction: column; gap: 2px; }
.metric .num {
  font-variant-numeric: tabular-nums;
  font-size: 24px; font-weight: 600; line-height: 1; letter-spacing: -0.02em;
}
.metric .num i {
  font-style: normal; font-size: 12px; font-weight: 500;
  color: var(--muted); margin-left: 4px;
}
.metric .cap {
  font-size: 10.5px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted);
}
.mode-badge {
  align-self: center;
  font-size: 12px; font-weight: 600; letter-spacing: 0.04em;
  padding: 6px 11px; border-radius: 999px; border: 1px solid transparent;
  transition: all 0.25s var(--ease);
}
.mode-badge[data-mode="coast"] { color: var(--muted); border-color: var(--line); }
.mode-badge[data-mode="drive"] { color: #061318; background: var(--clarity); }
.mode-badge[data-mode="regen"] { color: #1a0d02; background: var(--mustard); }

/* ---- Dial (finale) ---- */
.dial-bar {
  position: absolute;
  left: 16px; right: 16px; bottom: 28px;
  display: flex; align-items: center; gap: 14px;
  padding: 12px 16px;
  background: rgba(8, 13, 17, 0.66);
  border: 1px solid var(--line);
  border-radius: var(--r);
  backdrop-filter: blur(10px);
  opacity: 0; transform: translateY(8px);
  transition: opacity 0.4s var(--ease), transform 0.4s var(--ease);
}
.dial-bar.show { opacity: 1; transform: none; }
.dial-end {
  font-size: 11.5px; font-weight: 600; letter-spacing: 0.04em;
  text-transform: uppercase; white-space: nowrap;
}
.dial-end.brake { color: var(--mustard); }
.dial-end.drive { color: var(--clarity); }
#dial {
  -webkit-appearance: none; appearance: none;
  flex: 1; height: 8px; border-radius: 999px;
  background: linear-gradient(90deg, var(--mustard) 0%, rgba(159,176,186,0.25) 50%, var(--clarity) 100%);
  outline: none; cursor: pointer;
}
#dial::-webkit-slider-thumb {
  -webkit-appearance: none; width: 24px; height: 24px; border-radius: 50%;
  background: #eef4f6; border: 3px solid var(--steel);
  box-shadow: 0 4px 14px rgba(0,0,0,0.45); cursor: grab;
}
#dial::-moz-range-thumb {
  width: 24px; height: 24px; border-radius: 50%;
  background: #eef4f6; border: 3px solid var(--steel);
  box-shadow: 0 4px 14px rgba(0,0,0,0.45); cursor: grab;
}
#dial:focus-visible { box-shadow: 0 0 0 3px rgba(75,213,254,0.4); }

.hint {
  position: absolute;
  bottom: 16px; left: 50%; transform: translateX(-50%);
  font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--muted); opacity: 0; pointer-events: none;
  transition: opacity 0.4s var(--ease);
}
.hint.show { opacity: 0.7; }

/* ---- Footer ---- */
.foot {
  max-width: 1100px; margin: 0 auto;
  display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px;
  padding: 40px clamp(18px, 5vw, 56px);
  margin-top: 8vh;
  border-top: 1px solid var(--line);
  font-size: 12px; color: var(--muted);
}
.foot .dim { opacity: 0.7; }

/* ---- Reveal ---- */
body { opacity: 0; transition: opacity 0.5s var(--ease); }
body.ready { opacity: 1; }

/* ---- Responsive: stack on narrow screens ---- */
@media (max-width: 860px) {
  .scrolly { grid-template-columns: minmax(0, 1fr); }
  .stage-col { position: sticky; top: 0; z-index: 1; }
  .stage-wrap { height: 56vh; }
  .chapters { z-index: 2; }
  .chapter {
    min-height: auto;
    padding: 8vh clamp(4px, 2vw, 18px);
    align-items: stretch;
  }
  .chapter-inner { max-width: none; opacity: 1; transform: none; }
  .readout { bottom: 84px; right: 12px; gap: 12px; padding: 10px 12px; }
  .metric .num { font-size: 20px; }
  .dial-bar { bottom: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
  .chapter-inner { opacity: 1; transform: none; }
  body { opacity: 1; }
}
