/* ============================================================
   Video Reach Tracker: scroll-driven map story
   Palette: midnight teal, muted geography, warm paper, one green.
   ============================================================ */

:root {
  --midnight-950: #061317;
  --midnight-900: #08191e;
  --teal-800: #0d2c33;
  --teal-700: #12414a;
  --paper: #f2eee4;
  --paper-2: #e8e2d3;
  --paper-line: #d3ccb9;
  --ink: #0d2226;
  --ink-soft: #3d5559;
  --muted: #66797a;
  --on-dark: #e9efe9;
  --on-dark-soft: #9db6b0;
  --line-dark: rgba(233, 239, 233, 0.16);
  --green: #5fc197;
  --green-deep: #1f7a5a;
  --amber-bg: #f3dfae;
  --amber-ink: #5b3f00;

  --display: "Newsreader", Georgia, "Times New Roman", serif;
  --sans: "Hanken Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;

  --topbar: 60px;
  --gutter: clamp(16px, 4vw, 64px);
  --story-length: 300vh;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.55;
  color: var(--on-dark);
  background: var(--midnight-950);
  overflow-x: hidden;
}

h1, h2, h3, p, dl, dd, ol { margin: 0; padding: 0; }
img { display: block; max-width: 100%; }

:focus-visible {
  outline: 3px solid var(--green);
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  left: 16px;
  top: -64px;
  z-index: 100;
  padding: 10px 16px;
  background: var(--paper);
  color: var(--ink);
  border-radius: 4px;
}
.skip-link:focus { top: 12px; }

/* ---------- Buttons ---------- */

.button {
  display: inline-block;
  padding: 13px 24px;
  border-radius: 4px;
  background: var(--green);
  color: #04201a;
  font-weight: 600;
  text-decoration: none;
  transition: background-color 0.15s ease, transform 0.15s ease;
}
.button:hover { background: #7bd2ad; }
.button:active { transform: translateY(1px); }
.button-small { padding: 9px 16px; font-size: 0.92rem; }

/* ---------- Top bar ---------- */

.topbar {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 50;
  height: var(--topbar);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 var(--gutter);
  background: var(--midnight-950);
  border-bottom: 1px solid var(--line-dark);
}

.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.logo-chip { display: flex; padding: 4px 6px; background: #fff; border-radius: 4px; }
.logo-chip img { height: 32px; width: auto; }
.brand-name { font-weight: 500; color: var(--on-dark-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.notice {
  position: fixed;
  top: var(--topbar);
  left: 0;
  right: 0;
  z-index: 49;
  padding: 10px var(--gutter);
  background: var(--amber-bg);
  color: var(--amber-ink);
  font-size: 0.92rem;
}
.notice[hidden] { display: none; }

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

.story {
  position: relative;
  height: var(--story-length);
  background: var(--midnight-950);
}

.story-pin {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100svh;
  overflow: hidden;
}

.story-map { position: absolute; inset: 0; background: #0d2d33; }

.story-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(130% 95% at 58% 50%, transparent 52%, rgba(3, 12, 14, 0.5) 100%),
    linear-gradient(180deg, rgba(3, 12, 14, 0.5) 0, transparent 120px);
}

.chapters { position: absolute; inset: 0; pointer-events: none; }

.chapter {
  position: absolute;
  width: min(440px, 36vw);
  padding: 28px 32px 30px;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--paper-line);
  border-radius: 4px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.7) inset, 0 28px 60px -28px rgba(0, 0, 0, 0.7);
  will-change: opacity, transform;
}

/* Hidden until the scroll controller reveals them. */
.chapter { opacity: 0; visibility: hidden; }
#ch1 { opacity: 1; visibility: visible; }


.chapter h1,
.chapter h2 {
  font-family: var(--display);
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1.06;
}
.chapter h1 { font-size: clamp(1.9rem, 3vw, 2.9rem); }
.chapter h2 { font-size: clamp(1.8rem, 2.8vw, 2.7rem); }
.chapter p { margin-top: 14px; color: var(--ink-soft); max-width: 46ch; }
.chapter .button { margin-top: 20px; background: var(--green-deep); color: #fff; }
.chapter .button:hover { background: #17604a; }

/* Opening panel: the video, over the whole of India */
.chapter-video {
  left: var(--gutter);
  top: calc(var(--topbar) + 24px);
  width: min(580px, 42vw, calc((100svh - 240px) * 1.7778 + 56px));
  padding: 24px 28px 28px;
}
.chapter-video p { margin-top: 10px; max-width: 46ch; }
.video-frame {
  margin-top: 18px;
  aspect-ratio: 16 / 9;
  background: #000;
  border: 1px solid var(--paper-line);
}
.video-frame iframe { display: block; width: 100%; height: 100%; border: 0; }

/* Left-hand list of schools in the Delhi chapter */
.chapter-list {
  left: var(--gutter);
  top: calc(var(--topbar) + 24px);
  bottom: 24px;
  display: flex;
  flex-direction: column;
  width: min(340px, 32vw);
  padding: 22px 20px 6px 22px;
}
.chapter-list h2 { font-size: clamp(1.4rem, 2vw, 1.9rem); }
.chapter .list-note { margin-top: 6px; font-size: 0.85rem; color: var(--muted); }
.school-list {
  flex: 1;
  min-height: 0;
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
  overflow: hidden;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 16px, #000 calc(100% - 16px), transparent 100%);
  mask-image: linear-gradient(to bottom, transparent 0, #000 16px, #000 calc(100% - 16px), transparent 100%);
  border-top: 1px solid var(--paper-line);
}
.school-list li + li { border-top: 1px solid var(--paper-line); }
.school-list button {
  display: flex;
  width: 100%;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  padding: 9px 4px;
  border: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background-color 0.15s ease;
}
.school-list button:hover,
.school-list button:focus-visible { background: var(--paper-2); }
.school-list span { font-size: 0.88rem; line-height: 1.3; min-width: 0; }
.school-list strong { font-size: 0.88rem; font-weight: 600; font-variant-numeric: tabular-nums lining-nums; }

/* Small call-to-action: bottom right, so it never meets the school list on the left */
.chapter-popup {
  right: var(--gutter);
  bottom: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  width: min(440px, 40vw);
  padding: 14px 18px;
}
.popup-copy strong { display: block; font-family: var(--display); font-size: 1.2rem; font-weight: 500; line-height: 1.2; }
.popup-copy span { font-size: 0.88rem; color: var(--ink-soft); }
.chapter-popup .button { margin-top: 0; white-space: nowrap; }

/* ---------- School markers ---------- */

.pin {
  position: absolute;
  width: var(--d, 16px);
  height: var(--d, 16px);
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  pointer-events: none;
}
.story[data-reveal="1"] .pin { pointer-events: auto; }

.pin-dot {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 1.5px var(--midnight-950), 0 0 0 4px rgba(95, 193, 151, 0.28);
  transform: scale(calc(0.3 + 0.7 * var(--z, 0)));
  opacity: calc(0.6 + 0.4 * var(--z, 0));
  transition: transform 0.2s ease, background-color 0.2s ease;
}
.pin-ring {
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  border: 1.5px solid var(--paper);
  opacity: 0;
  transform: scale(0.2);
  transition: opacity 0.5s ease, transform 0.6s cubic-bezier(0.2, 0.9, 0.3, 1.25);
  transition-delay: calc(var(--i, 0) * 26ms);
}
.story[data-reveal="1"] .pin-ring { opacity: 0.85; transform: scale(1); }

.pin.is-unreported .pin-dot { background: #8aa7a5; }
.pin:hover .pin-dot,
.pin.is-active .pin-dot { transform: scale(1.3); background: #8fe0bd; }
.pin:hover .pin-ring,
.pin.is-active .pin-ring { border-color: var(--green); transition-delay: 0ms; }
.pin:focus-visible { outline: 2px solid var(--paper); outline-offset: 6px; border-radius: 50%; }

/* Map popups */
.school-card.maplibregl-popup { z-index: 5; }
.school-card .maplibregl-popup-content {
  padding: 12px 16px 13px;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--paper-line);
  border-radius: 4px;
  box-shadow: 0 18px 40px -16px rgba(0, 0, 0, 0.7);
  font-family: var(--sans);
}
.school-card .maplibregl-popup-tip { display: none; }
.school-card strong { display: block; font-family: var(--display); font-size: 1.1rem; font-weight: 500; line-height: 1.2; }
.school-card-reach { display: block; margin-top: 4px; font-size: 0.88rem; color: var(--ink-soft); }
.school-card-date { display: block; margin-top: 2px; font-size: 0.82rem; color: var(--muted); }

.maplibregl-ctrl-attrib { background: var(--midnight-900) !important; color: var(--on-dark-soft) !important; }
.maplibregl-ctrl-attrib a { color: var(--on-dark) !important; }
.maplibregl-ctrl-bottom-right { z-index: 2; }

/* ---------- Static fallback (no map) ---------- */

.story.is-static { height: auto; }
.story.is-static .story-pin { position: relative; height: auto; padding: calc(var(--topbar) + 48px) var(--gutter) 64px; display: grid; gap: 16px; background: var(--teal-800); }
.story.is-static .story-map,
.story.is-static .story-vignette,
.story.is-static .chapters { position: static; display: grid; gap: 16px; }
.story.is-static .chapter-list { height: auto; }
.story.is-static .school-list { overflow: visible; }
.story.is-static .chapter { position: static; width: auto; max-width: 640px; opacity: 1 !important; transform: none !important; visibility: visible !important; pointer-events: auto !important; }

/* ---------- Sections ---------- */

.section {
  position: relative;
  padding: clamp(72px, 11vw, 150px) var(--gutter);
  overflow: hidden;
}
.section > * { position: relative; z-index: 1; }
.section > .motif { position: absolute; z-index: 0; }

.section-dark { background: var(--midnight-950); }
.section-teal { background: linear-gradient(180deg, var(--midnight-950) 0, var(--teal-800) 24%, #0b2830 100%); }
.section-paper { background: var(--paper); color: var(--ink); }

.section h2 {
  font-family: var(--display);
  font-weight: 500;
  font-size: clamp(2.2rem, 5vw, 4.4rem);
  line-height: 1.02;
  letter-spacing: -0.02em;
}
.section-head { max-width: 62ch; margin-bottom: clamp(28px, 4vw, 52px); }
.section-head p { margin-top: 14px; color: var(--on-dark-soft); font-size: 1.05rem; }
.section-head-ink p { color: var(--ink-soft); }

.motif { pointer-events: none; opacity: 0.26; }
.motif svg { display: block; width: 100%; height: auto; }
.motif path { fill: none; stroke: var(--green); stroke-width: 1; stroke-linejoin: round; }
.motif-left { left: -8vw; bottom: -14%; width: min(72vw, 820px); }
.motif-right { right: -10vw; top: -8%; width: min(68vw, 760px); }

/* Sheets (light panels on dark sections) */
.sheet {
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--paper-line);
  border-radius: 4px;
  box-shadow: 0 40px 80px -48px rgba(0, 0, 0, 0.8);
  overflow: hidden;
}
.sheet-flat { background: #faf8f2; box-shadow: none; }
.sheet-head { padding: 0 clamp(14px, 2vw, 28px); border-bottom: 1px solid var(--paper-line); }

.tablist { display: flex; gap: 4px; }
.tablist [role="tab"] {
  padding: 16px 18px 14px;
  border: 0;
  border-bottom: 3px solid transparent;
  background: none;
  color: var(--muted);
  font: 500 1rem var(--sans);
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.tablist [role="tab"]:hover { color: var(--ink); }
.tablist [role="tab"][aria-selected="true"] { color: var(--ink); border-bottom-color: var(--green-deep); }
[role="tabpanel"][hidden] { display: none; }

.growth-stats { display: grid; grid-template-columns: repeat(3, 1fr); border-bottom: 1px solid var(--paper-line); }
.growth-stat { padding: 18px clamp(14px, 2vw, 28px); border-left: 1px solid var(--paper-line); min-width: 0; }
.growth-stat:first-child { border-left: 0; }
.growth-stat dt { font-size: 0.88rem; color: var(--muted); }
.growth-stat dd { margin-top: 2px; font-family: var(--display); font-size: clamp(1.4rem, 2.2vw, 2rem); font-weight: 500; font-variant-numeric: tabular-nums lining-nums; }

.chart-area { padding: 24px clamp(14px, 2vw, 28px) 8px; }
.chart-canvas { position: relative; height: clamp(300px, 44vh, 440px); }

.empty { padding: 56px 24px; text-align: center; color: var(--muted); }
.empty[hidden], #growthContent[hidden], .bubble-box[hidden] { display: none; }

.table-wrap { max-height: 340px; overflow: auto; margin: 14px clamp(14px, 2vw, 28px) 24px; border: 1px solid var(--paper-line); border-radius: 4px; background: #fff; }
table { width: 100%; border-collapse: collapse; font-size: 0.94rem; }
caption { padding: 10px 14px; text-align: left; font-weight: 600; color: var(--ink-soft); background: var(--paper-2); border-bottom: 1px solid var(--paper-line); }
th, td { padding: 10px 14px; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums lining-nums; }
th:first-child, td:first-child { text-align: left; }
thead th { position: sticky; top: 0; background: #fff; border-bottom: 1px solid var(--paper-line); font-weight: 600; color: var(--ink-soft); }
tbody tr + tr td { border-top: 1px solid #ece7d9; }
tbody tr:hover { background: #f7f4ec; }
td.positive { color: var(--green-deep); font-weight: 600; }
td.wrap-text { white-space: normal; min-width: 220px; }
td.muted { color: var(--muted); }
.schools-meta { padding: 16px clamp(14px, 2vw, 28px) 0; color: var(--muted); font-size: 0.92rem; }

.bubble-box { position: relative; height: clamp(340px, 54vh, 540px); padding: 12px; }

/* Footer */
.footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 32px;
  padding: 24px var(--gutter) 32px;
  background: #040e11;
  border-top: 1px solid var(--line-dark);
  font-size: 0.85rem;
  color: var(--on-dark-soft);
}
.footer a { color: var(--on-dark); }

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

@media (max-width: 900px) {
  /* Not enough width for list and popup side by side: stack them. */
  #ch3.chapter-list { bottom: 112px; }
  .chapter-popup { left: var(--gutter); right: var(--gutter); bottom: 28px; width: auto; }
  .maplibregl-ctrl-bottom-right { top: calc(var(--topbar) + 6px); bottom: auto; }

  .growth-stats { grid-template-columns: 1fr; }
  .growth-stat { border-left: 0; border-top: 1px solid var(--paper-line); padding: 12px clamp(14px, 2vw, 28px); }
  .growth-stat:first-child { border-top: 0; }
}

@media (max-width: 760px) {
  :root { --story-length: 280vh; }

  .brand-name { display: none; }

  .chapter {
    left: 12px;
    right: 12px;
    bottom: 12px;
    width: auto;
    padding: 18px 18px 20px;
  }
  .chapter h1,
  .chapter h2 { font-size: 1.7rem; }
  .chapter p { margin-top: 10px; font-size: 0.95rem; }
  .chapter-video { top: auto; width: auto; padding: 16px 16px 18px; }
  .chapter-video p { display: none; }
  .video-frame { margin-top: 12px; }
  #ch3.chapter-list { top: auto; bottom: 116px; height: 34vh; height: 34svh; padding: 16px 16px 4px; }
  .chapter-popup { left: 12px; right: 12px; bottom: 12px; width: auto; padding: 12px 14px; }
  .popup-copy strong { font-size: 1.05rem; }
  .pin-ring { inset: -6px; }

  .section { padding-top: 64px; padding-bottom: 64px; }
  .tablist [role="tab"] { flex: 1; padding: 14px 8px 12px; }
  .sheet-head { padding: 0 8px; }
  .table-wrap { margin: 12px 12px 18px; }
  .bubble-box { height: 340px; padding: 8px; }
  .footer { flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
