/* "Where your payment goes": sticky year-by-year chart of the visitor's own
   estimator scenario with stepped narrative (partials/story.js). Paper ground
   breaks the dark estimator chapter before the cream team section. */

.story {
  --story-principal: var(--forest);
  --story-interest: var(--clay);
  --story-rule: rgba(29, 36, 33, .14);
  --story-plot-h: clamp(240px, 50svh, 500px);
  /* Scroll distance between the last step lighting up and the chart letting go. */
  --story-tail: 350px;
  /* Pinned graphic height. story.js writes the measured value; this is the no-JS estimate
     (plot plus the caption, axis, legend and note around it). */
  --story-graphic-h: calc(var(--story-plot-h) + 150px);
  position: relative;
  /* Same layer as .estimate; .team (z-index 3) keeps painting its numeral across our bottom edge. */
  z-index: 2;
  padding: clamp(96px, 11vw, 160px) var(--page-x) clamp(150px, 14vw, 210px);
  /* clip, not hidden: no scroll container, so the sticky graphic still works. */
  overflow-x: clip;
  color: var(--ink);
  background: var(--paper);
}

/* Head ---------------------------------------------------------------------- */

.story-head {
  display: grid;
  align-items: end;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, .85fr);
  column-gap: clamp(40px, 7vw, 120px);
  row-gap: 26px;
  margin-bottom: clamp(56px, 7vw, 104px);
}

.story-head .eyebrow {
  grid-column: 1 / -1;
  color: var(--muted);
}

.story-head h2 {
  max-width: 12ch;
  margin: 0;
  color: var(--forest);
  font-size: clamp(48px, 5.4vw, 84px);
  letter-spacing: -.045em;
  line-height: .94;
}

.story-lede {
  max-width: 440px;
  margin: 0;
  padding-bottom: 6px;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.7;
}

/* Body: steps scroll past a sticky graphic -------------------------------- */

.story-body {
  display: grid;
  grid-template-columns: minmax(260px, .7fr) minmax(0, 1.3fr);
  column-gap: clamp(40px, 6vw, 110px);
  align-items: start;
}

.story-graphic {
  position: sticky;
  top: calc(var(--header-h) + 20px);
  grid-column: 2;
  grid-row: 1;
  min-width: 0;
}

.story-chart {
  margin: 0;
}

.story-chart__caption {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 6px 20px;
  margin-bottom: 18px;
  font: 400 11px/1.4 var(--mono);
  letter-spacing: .1em;
  text-transform: uppercase;
}

.story-chart__label {
  color: var(--muted);
}

.story-chart__scenario {
  color: var(--forest);
  font-variant-numeric: tabular-nums;
}

.story-chart__frame {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  column-gap: 12px;
}

.story-chart__y {
  position: relative;
  width: 3.4em;
  height: var(--story-plot-h);
  color: var(--muted);
  font: 400 11px/1 var(--mono);
  letter-spacing: .03em;
}

.story-chart__y span {
  position: absolute;
  right: 0;
  translate: 0 -50%;
}

.story-chart__y span:nth-child(1) { top: 0; }
.story-chart__y span:nth-child(2) { top: 50%; }
.story-chart__y span:nth-child(3) { top: 100%; }

.story-chart__plot {
  position: relative;
  height: var(--story-plot-h);
}

.story-chart__svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.story-chart__grid line {
  stroke: var(--story-rule);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.story-chart__x {
  display: flex;
  grid-column: 2;
  justify-content: space-between;
  margin-top: 12px;
  color: var(--muted);
  font: 400 11px/1 var(--mono);
  letter-spacing: .05em;
  text-transform: uppercase;
}

/* Bars: interest fills the column, principal rises from the base. */

.story-bar {
  transform-box: fill-box;
  transform-origin: 50% 100%;
  transition: opacity .45s ease;
}

.story-bar__interest {
  fill: var(--story-interest);
}

.story-bar__principal {
  fill: var(--story-principal);
  transform-box: fill-box;
  transform-origin: 50% 100%;
  transition: transform .6s var(--ease);
}

.story-bar[data-focus="dim"] {
  opacity: .42;
}

.story-bar[data-focus="off"] {
  opacity: .13;
}

/* First view: bars rise left to right, once. */
.js .story-chart:not(.is-drawn) .story-bar {
  transform: scaleY(0);
}

.js .story-chart .story-bar {
  transition:
    transform 1s var(--ease) calc(var(--i, 0) * 22ms),
    opacity .45s ease;
}

.story-chart__half {
  stroke: var(--ink);
  stroke-width: 1;
  stroke-dasharray: 3 5;
  vector-effect: non-scaling-stroke;
  opacity: 0;
  transition: opacity .4s ease;
}

.story-chart[data-state="all"] .story-chart__half,
.story-chart[data-state="crossover"] .story-chart__half {
  opacity: .7;
}

.story-balance {
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.75;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.story-balance--halo {
  stroke: var(--paper);
  stroke-width: 6;
}

/* Marker: one dot + tag that travels to the moment each step describes. */

.story-marker {
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  opacity: 0;
  pointer-events: none;
  transition:
    left .7s var(--ease),
    top .7s var(--ease),
    opacity .3s ease;
}

.story-marker.is-on {
  opacity: 1;
}

.story-marker__dot {
  position: absolute;
  top: -6px;
  left: -6px;
  width: 12px;
  height: 12px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--paper);
}

.story-marker__tag {
  position: absolute;
  bottom: 14px;
  left: 10px;
  padding: 7px 9px 6px;
  color: var(--paper);
  background: var(--ink);
  font: 400 11px/1.2 var(--mono);
  letter-spacing: .06em;
  text-transform: uppercase;
  white-space: nowrap;
}

.story-marker__tag {
  transition: opacity .2s ease;
}

/* Hide at once when the dot sets off; fade back in once it lands. */
.story-marker.is-moving .story-marker__tag {
  opacity: 0;
  transition: none;
}

.story-marker.is-flip .story-marker__tag {
  right: 10px;
  left: auto;
}

.story-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 24px;
  margin: 22px 0 0;
  padding: 18px 0 0;
  border-top: 1px solid var(--story-rule);
  list-style: none;
  color: var(--ink);
  font: 400 11px/1.3 var(--mono);
  letter-spacing: .09em;
  text-transform: uppercase;
}

.story-legend li {
  display: inline-flex;
  align-items: center;
  gap: 9px;
}

.story-legend__key {
  width: 10px;
  height: 10px;
}

.story-legend__key--principal { background: var(--story-principal); }
.story-legend__key--interest { background: var(--story-interest); }

.story-legend__key--balance {
  width: 20px;
  height: 2px;
  background: var(--ink);
}

.story-chart__note {
  margin: 14px 0 0;
  color: var(--muted);
  font: 400 11px/1.55 var(--mono);
  letter-spacing: .02em;
}

/* Steps --------------------------------------------------------------------- */

.story-steps {
  grid-column: 1;
  grid-row: 1;
  margin: 0;
  padding: 0;
  list-style: none;
}

.story-step {
  display: flex;
  min-height: 76svh;
  flex-direction: column;
  justify-content: center;
  padding: 8svh 0;
  border-top: 1px solid var(--story-rule);
}

.story-step:first-child {
  min-height: 60svh;
  justify-content: flex-start;
  padding-top: 0;
  border-top: 0;
}

/* The chart pins at header + 20px and this step lights when its top crosses 55svh, so it must be
   tail + pin offset + graphic height - 55svh tall for the chart to let go --story-tail later.
   Any taller and the chart sits frozen over dead scroll. */
.story-step:last-child {
  min-height: calc(var(--story-tail) + var(--header-h) + 20px + var(--story-graphic-h) - 55svh);
  /* The shared 8svh padding grows with tall screens and would push the step past that
     height (dead scroll again), so cap the top and drop the bottom. */
  padding-top: min(8svh, 64px);
  padding-bottom: 0;
}

.story-step p {
  margin: 0;
}

.story-step__kicker {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--clay);
  font: 400 11px/1.4 var(--mono);
  letter-spacing: .13em;
  text-transform: uppercase;
}

.story-step__kicker span {
  color: var(--muted);
}

.story-step__figure {
  margin-top: 22px !important;
  color: var(--forest);
  font: 400 clamp(56px, 6.2vw, 96px)/.9 var(--serif);
  letter-spacing: -.04em;
  font-variant-numeric: tabular-nums;
}

.story-step__text {
  max-width: 34ch;
  margin-top: 18px !important;
  color: var(--ink);
  font-size: 16px;
  line-height: 1.65;
}

.story.is-live:not(.is-static) .story-step {
  opacity: .3;
  transition: opacity .5s ease;
}

.story.is-live:not(.is-static) .story-step.is-active {
  opacity: 1;
}

/* Foot: full disclosure and the way back up ------------------------------- */

.story-foot {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 24px 60px;
  align-items: end;
  margin-top: clamp(40px, 5vw, 72px);
  padding-top: 26px;
  border-top: 1px solid var(--story-rule);
}

.story-disclosure {
  max-width: 760px;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.7;
}

.story-back {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  color: var(--forest);
  font: 400 11px/1.4 var(--mono);
  letter-spacing: .12em;
  text-decoration: underline;
  text-decoration-color: rgba(23, 53, 46, .3);
  text-decoration-thickness: 1px;
  text-underline-offset: 6px;
  text-transform: uppercase;
  transition: color .25s ease, text-decoration-color .25s ease;
}

.story-back:hover,
.story-back:focus-visible {
  color: var(--clay);
  text-decoration-color: currentColor;
}

/* Stacked: the chart pins under the header, steps scroll beneath it -------- */

@media (max-width: 860px) {
  .story {
    --story-plot-h: clamp(150px, 28svh, 250px);
  }

  .story-head {
    grid-template-columns: 1fr;
  }

  .story-head h2 {
    font-size: clamp(44px, 11vw, 64px);
  }

  .story-body {
    grid-template-columns: minmax(0, 1fr);
  }

  .story-graphic {
    top: var(--header-h);
    z-index: 2;
    grid-column: 1;
    margin-inline: calc(var(--page-x) * -1);
    padding: 14px var(--page-x) 14px;
    border-bottom: 1px solid var(--story-rule);
    background: var(--paper);
  }

  .story-chart__caption {
    margin-bottom: 12px;
  }

  .story-chart__label {
    display: none;
  }

  .story-legend {
    gap: 8px 16px;
    margin-top: 12px;
    padding-top: 10px;
    letter-spacing: .05em;
  }

  .story-chart__note {
    margin-top: 8px;
  }

  .story-steps {
    grid-row: 2;
  }

  .story-step,
  .story-step:first-child {
    min-height: 62svh;
    justify-content: flex-start;
    padding: 56px 0 40px;
    border-top: 1px solid var(--story-rule);
  }

  .story-step:first-child {
    border-top: 0;
  }

  /* Stacked, the chart pins at the header and this step lights 72px below it (or at 60svh,
     whichever is lower; see readingLine in story.js). No trailing padding: the foot has its own margin. */
  .story-step:last-child {
    min-height: calc(var(--story-tail) - max(60svh - var(--header-h) - var(--story-graphic-h), 72px));
    justify-content: flex-start;
    padding: 56px 0 0;
    border-top: 1px solid var(--story-rule);
  }

  .story-step__figure {
    font-size: clamp(48px, 14vw, 72px);
  }

  .story-foot {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  .js .story-chart:not(.is-drawn) .story-bar {
    transform: none;
  }

  .story-marker {
    display: none;
  }
}
