/*
 * Clean Water Help — Story Engine styles (story.css)
 * ---------------------------------------------------
 * Shared styles for every "project story" page (scroll-driven narrative pages).
 * Load AFTER tokens.css and site.css:
 *   <link rel="stylesheet" href="../css/tokens.css">
 *   <link rel="stylesheet" href="../css/site.css">
 *   <link rel="stylesheet" href="../css/story.css">
 *
 * Design rules honored here:
 *  - Uses ONLY the locked brand tokens (navy / sky / orange, Prompt / Plex Serif / Plex Mono).
 *  - Normal scrolling only. Nothing hijacks or slows the scroll.
 *  - Every animation is wrapped in @media (prefers-reduced-motion: no-preference),
 *    so people who turn off motion get an instant, complete page.
 *  - Mobile first: every multi-column block collapses to one column under 768px.
 */

/* ── 1. PAGE SCAFFOLD ─────────────────────────────────────────────── */

.story-page { background: #fff; }

/* Thin reading-progress bar under the header. Uses the modern CSS
   "scroll-driven animation" feature; browsers without it simply never
   show the bar (safe fallback, no JavaScript needed). */
.story-progress {
  position: fixed; top: 0; left: 0; right: 0; height: 4px;
  background: var(--orange); transform-origin: 0 50%;
  transform: scaleX(0); z-index: 60; pointer-events: none;
}
@supports (animation-timeline: scroll()) {
  @media (prefers-reduced-motion: no-preference) {
    .story-progress {
      animation: story-progress-grow linear both;
      animation-timeline: scroll(root);
    }
  }
}
@keyframes story-progress-grow { from { transform: scaleX(0); } to { transform: scaleX(1); } }

/* Chapter rail: small fixed dots on the right (desktop only).
   story.js fills it automatically from every section[data-chapter]. */
.story-rail {
  position: fixed; right: 18px; top: 50%; transform: translateY(-50%);
  display: flex; flex-direction: column; gap: 14px; z-index: 50;
}
.story-rail a {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--gray-200); display: block; position: relative;
  transition: background var(--transition-fast), transform var(--transition-fast);
}
.story-rail a:hover { background: var(--gray-400); transform: scale(1.25); }
.story-rail a.is-active { background: var(--orange); transform: scale(1.3); }
.story-rail a span {
  position: absolute; right: 22px; top: 50%; transform: translateY(-50%);
  background: var(--navy); color: #fff; font-family: var(--fh);
  font-size: .72rem; padding: 4px 10px; border-radius: var(--radius-sm);
  white-space: nowrap; opacity: 0; pointer-events: none;
  transition: opacity var(--transition-fast);
}
.story-rail a:hover span, .story-rail a:focus-visible span { opacity: 1; }
@media (max-width: 1100px) { .story-rail { display: none; } }

/* Sticky support pill: appears after the hero, hides at the final ask.
   story.js adds/removes .is-shown. */
.story-pill {
  position: fixed; bottom: 22px; right: 22px; z-index: 55;
  opacity: 0; transform: translateY(14px); pointer-events: none;
  transition: opacity .3s ease, transform .3s ease;
}
.story-pill.is-shown { opacity: 1; transform: none; pointer-events: auto; }
.story-pill .btn-donate { box-shadow: var(--sh-lg); }
@media (max-width: 640px) {
  .story-pill { right: 12px; bottom: 12px; }
  .story-pill .btn-donate { padding: 12px 20px; font-size: .9rem; }
}

/* ── 2. REVEAL-ON-SCROLL (the default animation) ──────────────────── */

/* Only hide reveal content when JavaScript is actually running (the page
   adds class "js" to <html>); visitors without JavaScript see everything. */
@media (prefers-reduced-motion: no-preference) {
  html.js .reveal {
    opacity: 0; transform: translateY(26px);
    transition: opacity .7s cubic-bezier(.16,1,.3,1), transform .7s cubic-bezier(.16,1,.3,1);
    transition-delay: var(--reveal-delay, 0ms);
  }
  html.js .reveal.is-visible { opacity: 1; transform: none; }
}

/* ── 3. HERO ──────────────────────────────────────────────────────── */

.story-hero {
  position: relative; min-height: 88svh;
  display: flex; flex-direction: column; justify-content: flex-end;
  color: #fff; overflow: hidden; background: var(--navy);
}
.story-hero__img {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; object-position: center 30%;
}
.story-hero__scrim {
  position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(0,46,93,.45) 0%, rgba(0,46,93,.22) 38%, rgba(0,20,41,.93) 100%);
}
.story-hero__kicker, .story-hero h1, .story-hero__lede { text-shadow: 0 1px 14px rgba(0,20,41,.6); }
.story-hero__inner {
  position: relative; z-index: 2; width: min(1120px, 92%);
  margin: 0 auto; padding: 130px 0 46px;
}
.story-hero__kicker {
  font-family: var(--fh); font-weight: 600; font-size: .8rem;
  letter-spacing: .14em; text-transform: uppercase; color: #fff;
  margin-bottom: 14px;
}
.story-hero h1 {
  color: #fff; font-size: clamp(2.1rem, 5.2vw, 3.9rem);
  line-height: 1.06; max-width: 17ch; margin-bottom: 18px;
}
.story-hero__lede {
  font-size: clamp(1.05rem, 1.9vw, 1.3rem); line-height: 1.55;
  max-width: 52ch; color: #E8EFF5; margin-bottom: 26px;
}
.story-hero__cta { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; margin-bottom: 40px; }
.story-hero__ghost { color: #fff; font-family: var(--fh); font-weight: 500; border-bottom: 2px solid rgba(255,255,255,.45); padding-bottom: 2px; }
.story-hero__ghost:hover { color: var(--blue); border-color: var(--blue); }

.story-hero__stats {
  position: relative; z-index: 2; border-top: 1px solid rgba(255,255,255,.22);
  width: min(1120px, 92%); margin: 0 auto;
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px;
  padding: 20px 0 30px;
}
.story-hero__stat .n { font-family: var(--fm); font-size: clamp(1.3rem, 2.6vw, 1.9rem); color: var(--blue); }
.story-hero__stat .l { font-family: var(--fh); font-size: .82rem; color: #CCDAE6; margin-top: 2px; }
@media (max-width: 640px) {
  .story-hero { min-height: 76svh; }
  .story-hero__inner { padding-top: 104px; }
  .story-hero__stats { grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
  .story-hero__stat .l { font-size: .7rem; }
}

/* ── 4. CHAPTERS & PROSE ──────────────────────────────────────────── */

.story-ch { padding: clamp(64px, 9vw, 110px) 0; }
.story-ch--tint { background: var(--off-white); }
.story-ch--navy { background: var(--navy); color: #E8EFF5; }
.story-ch--navy h2, .story-ch--navy h3 { color: #fff; }

.story-wrap { width: min(1120px, 92%); margin: 0 auto; }
.story-prose { max-width: 68ch; }
.story-prose--center { margin: 0 auto; }
.story-ch h2 {
  font-size: clamp(1.7rem, 3.4vw, 2.5rem); line-height: 1.12; margin-bottom: 20px;
}
.story-ch h3 { font-size: 1.15rem; margin: 26px 0 10px; }
.story-lede { font-size: 1.12rem; line-height: 1.6; }

/* Big pull-quote */
.story-quote {
  border-left: 4px solid var(--blue); padding: 6px 0 6px 22px;
  margin: 30px 0; max-width: 60ch;
}
.story-quote p { font-size: 1.18rem; line-height: 1.5; font-style: italic; margin-bottom: 8px; }
.story-quote cite { font-style: normal; font-family: var(--fh); font-size: .85rem; color: var(--gray-500); }
.story-ch--navy .story-quote cite { color: var(--gray-300); }

/* Stat band: 2 to 4 big numbers. Use data-countup for animation. */
.story-stats {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 22px; margin: 36px 0;
}
.story-stat { border-top: 3px solid var(--blue); padding-top: 12px; }
.story-stat--orange { border-color: var(--orange); }
.story-stat .n { font-family: var(--fm); font-size: clamp(1.45rem, 2.4vw, 2.05rem); color: var(--navy); line-height: 1.1; white-space: nowrap; }
.story-stat .l { font-family: var(--fh); font-size: .86rem; color: var(--gray-500); margin-top: 4px; }
.story-ch--navy .story-stat .n { color: #fff; }
.story-ch--navy .story-stat .l { color: var(--gray-300); }

/* ── 5. SCROLLY SCENES (sticky figure + scrolling steps) ──────────── */

.scrolly { position: relative; display: grid; grid-template-columns: 1fr minmax(300px, 420px); gap: clamp(24px, 4vw, 64px); }
.scrolly--flip { grid-template-columns: minmax(300px, 420px) 1fr; }
.scrolly__figure {
  position: sticky; top: 84px; align-self: start;
  height: min(78vh, 720px); display: flex; align-items: center; justify-content: center;
}
.scrolly--flip .scrolly__figure { order: 2; }
.scrolly__steps { padding: 8vh 0 12vh; }
.scrolly--flip .scrolly__steps { order: 1; }
.step {
  min-height: 62vh; display: flex; align-items: center; margin: 0 0 8vh;
}
.step__card {
  background: #fff; border: 1px solid var(--gray-100);
  border-radius: var(--radius-lg); box-shadow: var(--sh-md);
  padding: 26px 28px; transition: box-shadow var(--transition-base), border-color var(--transition-base);
}
.step.is-active .step__card { border-color: var(--blue); box-shadow: var(--sh-lg); }
.step__card h3 { margin: 0 0 8px; font-size: 1.08rem; }
.step__card p { font-size: 1rem; margin: 0; }
.step__card .step__num { font-family: var(--fm); color: var(--blue); font-size: .82rem; display: block; margin-bottom: 6px; }

/* Mobile: figure pins at the top, step cards slide over the lower half */
@media (max-width: 900px) {
  .scrolly, .scrolly--flip { display: block; }
  .scrolly__figure, .scrolly--flip .scrolly__figure {
    position: sticky; top: 62px; height: 42svh; z-index: 1;
    background: inherit;
  }
  .scrolly__steps { position: relative; z-index: 2; padding-top: 4vh; }
  .step { min-height: 56svh; margin-bottom: 4vh; align-items: flex-end; padding-bottom: 4svh; }
  .step__card { margin: 0 2%; }
}

/* The map inside a scrolly figure */
.story-map { width: 100%; height: 100%; }
.story-map svg { width: 100%; height: 100%; display: block; }
.story-map path { vector-effect: non-scaling-stroke; }
.story-map .country { fill: var(--gray-100); stroke: #fff; stroke-width: 1; }
.story-map .drc { fill: var(--sky-300); fill-opacity: .28; stroke: var(--navy); stroke-width: 1.1; }
.story-map .drc.is-lit { fill-opacity: .5; }
.story-map .map-layer { opacity: 0; transition: opacity .5s ease .15s; pointer-events: none; }
.story-map .map-layer.is-active { opacity: 1; }
.story-map .dot { fill: var(--orange); }
.story-map .dot-ring { fill: none; stroke: var(--orange); transform-box: fill-box; transform-origin: center; }
@media (prefers-reduced-motion: no-preference) {
  .story-map .dot-ring { animation: map-ping 2.2s ease-out infinite; }
}
@keyframes map-ping {
  0% { transform: scale(.5); opacity: .9; }
  80%, 100% { transform: scale(2.1); opacity: 0; }
}
.story-map text { font-family: var(--fh); fill: var(--navy); }
.story-map .t-light { fill: var(--gray-500); }
.story-map .lake { fill: var(--sky-300); opacity: .55; }
.map-note { font-family: var(--fh); font-size: .72rem; color: var(--gray-400); text-align: center; margin-top: 6px; }

/* Swappable images inside a scrolly figure (generic scene type) */
.scene-imgs { position: relative; width: 100%; height: 100%; border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--sh-lg); }
.scene-imgs img {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
  opacity: 0; transition: opacity .6s ease;
}
.scene-imgs img.is-active { opacity: 1; }

/* ── 6. IMAGERY BLOCKS ────────────────────────────────────────────── */

.story-figure { margin: 34px 0; }
.story-figure img, .story-figure video { width: 100%; border-radius: var(--radius-lg); box-shadow: var(--sh-md); }
.story-figure figcaption { font-family: var(--fh); font-size: .8rem; color: var(--gray-400); margin-top: 10px; }
.story-ch--navy .story-figure figcaption { color: var(--gray-300); }

.story-duo { display: grid; grid-template-columns: 1.2fr .8fr; gap: 22px; align-items: start; margin: 34px 0; }
.story-trio { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; margin: 34px 0; }
.story-duo figure, .story-trio figure { margin: 0; }
.story-duo img, .story-trio img { width: 100%; height: 100%; object-fit: cover; border-radius: var(--radius-md); box-shadow: var(--sh-sm); }
@media (max-width: 768px) {
  .story-duo, .story-trio { grid-template-columns: 1fr; }
}

/* Split: text beside a tall image (use sparingly, max two per page) */
.story-split { display: grid; grid-template-columns: 1.05fr .95fr; gap: clamp(26px, 4vw, 60px); align-items: center; }
.story-split__media img { width: 100%; height: auto; border-radius: var(--radius-lg); box-shadow: var(--sh-lg); }
@media (max-width: 900px) { .story-split { grid-template-columns: 1fr; } }

/* Featured document (the handwritten letter) */
.story-letter { display: grid; grid-template-columns: minmax(280px, 420px) 1fr; gap: clamp(26px, 4vw, 60px); align-items: center; }
.story-letter__scan img {
  width: 100%; height: auto; border-radius: var(--radius-md);
  box-shadow: var(--sh-lg); border: 1px solid var(--gray-100); background: #fff;
}
.story-letter__trans { max-width: 56ch; }
.story-letter__trans .t {
  font-style: italic; font-size: 1.06rem; line-height: 1.65;
  border-left: 4px solid var(--orange); padding-left: 20px; margin: 18px 0;
}
@media (max-width: 900px) { .story-letter { grid-template-columns: 1fr; } .story-letter__scan { max-width: 380px; margin: 0 auto; } }

/* Click-to-play video: shows a lightweight poster until pressed */
.story-video { position: relative; cursor: pointer; }
.story-video img { width: 100%; border-radius: var(--radius-lg); box-shadow: var(--sh-md); display: block; }
.story-video__btn {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(0,20,41,.25); border: 0; border-radius: var(--radius-lg); width: 100%;
}
.story-video__btn span {
  width: 74px; height: 74px; border-radius: 50%; background: rgba(255,255,255,.94);
  display: flex; align-items: center; justify-content: center; box-shadow: var(--sh-lg);
  transition: transform var(--transition-fast);
}
.story-video__btn:hover span { transform: scale(1.07); }
.story-video__btn svg { width: 26px; height: 26px; fill: var(--navy); margin-left: 4px; }

/* ── 7. TIMELINE ("the journey so far") ───────────────────────────── */

.story-timeline { list-style: none; margin: 36px 0; padding: 0; position: relative; }
.story-timeline::before {
  content: ""; position: absolute; left: 7px; top: 6px; bottom: 6px;
  width: 2px; background: var(--gray-200);
}
.story-timeline li { position: relative; padding: 0 0 26px 34px; }
.story-timeline li:last-child { padding-bottom: 0; }
.story-timeline li::before {
  content: ""; position: absolute; left: 0; top: 5px; width: 16px; height: 16px;
  border-radius: 50%; background: #fff; border: 3px solid var(--blue);
}
.story-timeline li.is-next::before { border-color: var(--orange); border-style: dashed; }
.story-timeline .when { font-family: var(--fm); font-size: .82rem; color: var(--gray-500); display: block; }
.story-timeline .what { font-family: var(--fb); }
.story-timeline b { font-family: var(--fh); color: var(--navy); font-weight: 600; }

/* ── 8. DEEP-DIVE PANELS (progressive disclosure) ─────────────────── */

.story-deep { margin: 30px 0; }
.story-deep summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 12px;
  font-family: var(--fh); font-weight: 600; color: var(--navy);
  background: var(--off-white); border: 1px solid var(--gray-100);
  border-radius: var(--radius-md); padding: 14px 18px;
  transition: border-color var(--transition-fast);
}
.story-ch--tint .story-deep summary { background: #fff; }
.story-deep summary:hover { border-color: var(--blue); }
.story-deep summary::-webkit-details-marker { display: none; }
.story-deep summary::before {
  content: "+"; font-family: var(--fm); font-size: 1.1rem; color: var(--blue);
  width: 26px; height: 26px; border: 1.5px solid var(--blue); border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto;
}
.story-deep[open] summary::before { content: "\2212"; }
.story-deep summary .tag {
  margin-left: auto; font-size: .68rem; letter-spacing: .1em; text-transform: uppercase;
  color: var(--gray-400); font-weight: 500;
}
.story-deep__body { padding: 18px 6px 8px; max-width: 66ch; }
.story-deep__body p, .story-deep__body li { font-size: .98rem; }
.story-deep__body ul { padding-left: 20px; margin-bottom: 12px; }
.story-deep__body .mono { font-family: var(--fm); font-size: .9rem; color: var(--navy); }

/* Small spec cards (mono data) */
.spec-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin: 24px 0; }
.spec {
  background: #fff; border: 1px solid var(--gray-100); border-radius: var(--radius-md);
  padding: 14px 16px;
}
.story-ch--tint .spec { background: #fff; }
.spec .n { font-family: var(--fm); color: var(--navy); font-size: 1.15rem; }
.spec .l { font-family: var(--fh); font-size: .78rem; color: var(--gray-500); margin-top: 2px; }

/* ── 9. IMPACT SLIDER ─────────────────────────────────────────────── */

.impact { background: #fff; border: 1px solid var(--gray-100); border-radius: var(--radius-lg); box-shadow: var(--sh-md); padding: clamp(22px, 4vw, 40px); }
.impact__amount { font-family: var(--fm); font-size: clamp(2rem, 5vw, 3rem); color: var(--navy); }
.impact input[type="range"] {
  width: 100%; margin: 18px 0 8px; accent-color: var(--orange); height: 34px;
}
.impact__row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-top: 18px; }
.impact__cell { border-top: 3px solid var(--orange); padding-top: 10px; }
.impact__cell .n { font-family: var(--fm); font-size: clamp(1.4rem, 3vw, 2rem); color: var(--navy); }
.impact__cell .l { font-family: var(--fh); font-size: .82rem; color: var(--gray-500); }
.impact__note { font-family: var(--fh); font-size: .8rem; color: var(--gray-400); margin-top: 16px; }
@media (max-width: 640px) { .impact__row { grid-template-columns: 1fr 1fr 1fr; gap: 8px; } .impact__cell .l { font-size: .7rem; } }

/* ── 10. FINAL ASK ────────────────────────────────────────────────── */

.story-ways { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; margin: 40px 0 10px; }
.way {
  background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.16);
  border-radius: var(--radius-lg); padding: 26px 24px; display: flex; flex-direction: column; gap: 12px;
}
.way--lead { background: rgba(252,127,55,.12); border-color: rgba(252,127,55,.5); }
.way h3 { color: #fff; margin: 0; font-size: 1.2rem; }
.way p { color: var(--gray-200); font-size: .95rem; flex: 1; margin: 0; }
.way .btn-donate, .way .btn-primary, .way .btn-outline { align-self: flex-start; }
@media (max-width: 860px) { .story-ways { grid-template-columns: 1fr; } }

.share-row { display: flex; gap: 10px; flex-wrap: wrap; }
.share-btn {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: var(--fh); font-size: .85rem; font-weight: 500; color: #fff;
  border: 1px solid rgba(255,255,255,.4); border-radius: var(--radius-pill);
  background: transparent; padding: 9px 16px; cursor: pointer;
  transition: background var(--transition-fast), border-color var(--transition-fast);
}
.share-btn:hover { background: rgba(255,255,255,.12); border-color: #fff; color: #fff; }
.share-btn svg { width: 15px; height: 15px; fill: currentColor; }
.share-btn.is-done { background: var(--blue); border-color: var(--blue); color: var(--navy); }

/* Next-story handoff */
.story-next { display: block; background: var(--off-white); border-top: 1px solid var(--gray-100); }
.story-next__inner {
  width: min(1120px, 92%); margin: 0 auto; padding: 34px 0;
  display: flex; align-items: center; justify-content: space-between; gap: 18px;
}
.story-next .k { font-family: var(--fh); font-size: .78rem; letter-spacing: .12em; text-transform: uppercase; color: var(--gray-500); }
.story-next .t { font-family: var(--fh); font-weight: 700; color: var(--navy); font-size: clamp(1.2rem, 2.6vw, 1.7rem); }
.story-next .arrow { font-family: var(--fh); color: var(--orange); font-size: 1.6rem; transition: transform var(--transition-fast); }
.story-next:hover .arrow { transform: translateX(6px); }

/* Thermometer (matches site fund-thermo, tuned for light sections) */
.impact .fund-thermo { max-width: none; margin: 26px 0 0; }
.impact .fund-thermo__nums { color: var(--navy); font-family: var(--fh); }
.impact .fund-thermo__track { background: var(--gray-100); border-radius: var(--radius-pill); height: 12px; overflow: hidden; }
.impact .fund-thermo__fill { background: linear-gradient(90deg, var(--sky-300), var(--sky-400)); height: 100%; border-radius: var(--radius-pill); }
.impact .fund-thermo__date { font-family: var(--fh); font-size: .75rem; color: var(--gray-400); margin-top: 6px; }

/* Tablets: the pinned map fits its frame and clears the 74px header (Sep 28) */
@media (max-width: 900px) {
  .scrolly__figure, .scrolly--flip .scrolly__figure { top: 74px; }
  .scrolly__figure > div:not(.scene-imgs) { height: 100%; display: flex; flex-direction: column; }
  .story-map { flex: 1 1 auto; min-height: 0; }
}
@media (min-width: 600px) and (max-width: 900px) { .story-stats { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); } }
/* Phones: a darker lower scrim keeps the hero text readable over the photo */
@media (max-width: 640px) {
  .story-hero__scrim { background: linear-gradient(180deg, rgba(0,46,93,.35) 0%, rgba(0,46,93,.55) 30%, rgba(0,20,41,.88) 52%, rgba(0,20,41,.95) 100%); }
}
