/* Homepage scroll story: four tumors that look alike, read three ways.
   On desktop the pinned stage is set as a spread: a running head across the top, the headline and the
   plates hung from one line, and the note closing on the plates' lower edge. paradigm-v8.js places the
   plates in .hm-story-area and reports --plates-b and --copy-y (canvas pixels) and --story (progress).
   Without .is-scrolly (no JS, reduced motion) every step is visible and the figure shows the last reading. */

.hm-story {
  position: relative;
  padding-top: var(--hm-gap, 160px);
  overflow-x: clip;
}

.hm-story:not(.is-scrolly) { padding-bottom: var(--hm-gap, 160px); }

/* Pinned scroll = height − 100vh; the beat timeline (T in paradigm-v8.js) is laid out in fractions of it. */
.hm-story.is-scrolly {
  height: 420vh;
  padding-top: 0;
}

.hm-story-stage { position: relative; }

.hm-story.is-scrolly .hm-story-stage {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100svh;
  display: flex;
  align-items: center;
  padding-top: calc(var(--nav-gap) + var(--nav-h));
}

.hm-story-fig {
  position: relative;
  z-index: 0;
  margin: 0;
}

.hm-story.is-scrolly .hm-story-fig {
  position: absolute;
  inset: 0;
}

.hm-story-fig canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.hm-story:not(.is-scrolly) .hm-story-fig {
  order: 2;
  width: 100%;
  aspect-ratio: 16 / 10;
  margin-top: clamp(40px, 6vw, 80px);
  margin-bottom: clamp(28px, 4vw, 48px);
}

.hm-story:not(.is-scrolly) .hm-story-stage {
  display: flex;
  flex-direction: column-reverse;
}

.hm-story-labels,
.hm-story-area { display: none; }

/* Copy */

.hm-story-grid {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  column-gap: clamp(20px, 2.4vw, 32px);
  align-items: center;
  pointer-events: none;
}

.hm-story-copy {
  grid-column: 1 / span 5;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  pointer-events: auto;
}

.hm-story-steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: clamp(48px, 5vw, 72px);
}

.hm-story-tag {
  display: block;
  margin: 0 0 clamp(18px, 2.4vh, 28px);
  padding: 0;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  line-height: 1;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.hm-story-tag.is-nuevo {
  color: #c8432c;
}

.hm-story-line {
  max-width: var(--measure-display);
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(34px, min(3.7vw, 6.6vh), 60px);
  font-weight: var(--weight-headline);
  line-height: 1.02;
  letter-spacing: -0.036em;
  color: var(--ink);
  text-wrap: balance;
}

.hm-story-note {
  max-width: var(--measure-note);
  margin: clamp(20px, 2.6vh, 30px) 0 0;
  font-size: clamp(16px, 1.15vw, 18px);
  line-height: 1.58;
  color: var(--ink-muted);
  text-wrap: pretty;
}

/* Chapter index: one segment per reading, the current one fills with the scroll. */
.hm-story-index { display: none; }

.is-scrolly .hm-story-index {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  width: min(100%, 360px);
  margin: clamp(36px, 6vh, 64px) 0 0;
  padding: 0;
}

.hm-story-index li {
  --fill: 0;
  padding-top: 12px;
  font-size: 12.5px;
  font-weight: 500;
  color: rgba(17, 13, 23, 0.38);
  background:
    linear-gradient(var(--blue), var(--blue)) 0 0 / calc(var(--fill) * 100%) 2px no-repeat,
    linear-gradient(rgba(17, 13, 23, 0.12), rgba(17, 13, 23, 0.12)) 0 0 / 100% 2px no-repeat;
  transition: color 0.4s var(--ease-out);
}

.hm-story-index li.is-on { color: var(--ink); }

/* Steps share one cell: the next one rises from below, the last one leaves upward. */
.is-scrolly .hm-story-steps { gap: 0; }

.is-scrolly .hm-story-steps li {
  grid-area: 1 / 1;
  align-self: start;
  opacity: 0;
  transform: translateY(-24px);
  transition: opacity 0.6s var(--ease-out), transform 0.9s var(--ease-out);
  pointer-events: none;
}

.is-scrolly .hm-story-steps li.is-on ~ li { transform: translateY(24px); }

.is-scrolly .hm-story-steps li.is-on {
  opacity: 1;
  transform: none;
  transition-delay: 0.1s;
  pointer-events: auto;
}

/* Stacked (phones, and tablets held upright): plates above, copy below. Spread: side by side. The same
   query lives in paradigm-v8.js (STACKED); keep the two in step. */
@media (max-width: 760px), (max-width: 1100px) and (orientation: portrait) {
  .hm-story.is-scrolly { height: 360vh; }
  .hm-story.is-scrolly .hm-story-stage {
    align-items: flex-end;
    padding-bottom: clamp(28px, 6vh, 56px);
  }
  .hm-story-grid { grid-template-columns: minmax(0, 1fr); }
  .hm-story-copy { grid-column: 1 / -1; }
  .hm-story-line { font-size: clamp(28px, 7.6vw, 40px); max-width: var(--measure-display); }
  .hm-story-note { margin-top: 12px; font-size: 15.5px; }
  .is-scrolly .hm-story-index { margin-top: 24px; }
  .hm-story-index b { display: none; }
}

/* Short phones (and every phone behind browser chrome): the plates get the room above the copy, so the copy
   tightens and the chapter index keeps only its progress bars, since each step's tag already names it. */
@media (max-width: 760px) and (max-height: 760px) {
  .hm-story.is-scrolly .hm-story-stage { padding-bottom: clamp(18px, 3.6vh, 32px); }
  .is-scrolly .hm-story-tag { margin-bottom: 12px; }
  .is-scrolly .hm-story-line { font-size: clamp(24px, min(7.6vw, 4.6vh), 40px); }
  .is-scrolly .hm-story-note { margin-top: 10px; font-size: 14.5px; line-height: 1.5; }
  .is-scrolly .hm-story-index { margin-top: 18px; }
  .is-scrolly .hm-story-index li { padding-top: 2px; font-size: 0; }
}

@media (max-width: 760px) and (max-height: 620px) {
  .is-scrolly .hm-story-tag { margin-bottom: 10px; }
  .is-scrolly .hm-story-line { font-size: clamp(22px, min(7vw, 4.3vh), 40px); }
  .is-scrolly .hm-story-note { margin-top: 8px; font-size: 14px; line-height: 1.45; }
  .is-scrolly .hm-story-index { margin-top: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  .is-scrolly .hm-story-steps li,
  .hm-story-index li { transition: none; }
}

/* The spread */
@media (min-width: 761px) and (orientation: landscape), (min-width: 1101px) {
  .hm-story.is-scrolly .hm-story-grid {
    height: calc(100svh - var(--nav-gap) - var(--nav-h) - clamp(48px, 8vh, 80px));
    align-items: stretch;
  }
  .is-scrolly .hm-story-copy {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: subgrid;
    grid-template-rows: auto minmax(0, 1fr);
    align-items: stretch;
    height: 100%;
  }

  /* Running head: the three readings as a quiet line over a hairline that fills with the scroll. */
  .is-scrolly .hm-story-index {
    position: relative;
    grid-column: 1 / -1;
    grid-row: 1;
    display: flex;
    gap: clamp(28px, 3.2vw, 52px);
    width: auto;
    margin: 0 0 clamp(36px, 6.5vh, 72px);
    padding: 0 0 13px;
    border-bottom: 1px solid rgba(17, 13, 23, 0.14);
  }
  .is-scrolly .hm-story-index::after {
    content: "";
    position: absolute;
    left: 0;
    bottom: -1px;
    width: calc(var(--story, 0) * 100%);
    height: 1px;
    background: var(--ink);
  }
  .is-scrolly .hm-story-index li {
    padding: 0;
    background: none;
    font-size: 13px;
    font-weight: 400;
    color: rgba(17, 13, 23, 0.36);
    transition: color 0.6s var(--ease-out);
  }
  .is-scrolly .hm-story-index li.is-on { color: var(--ink); }
  .hm-story-index b {
    margin-right: 0.7em;
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 400;
  }

  /* The headline hangs from the same line as the plates. */
  .is-scrolly .hm-story-steps {
    grid-column: 1 / 7;
    grid-row: 2;
    grid-template-rows: minmax(0, 1fr);
    min-height: 0;
  }
  .is-scrolly .hm-story-steps li,
  .is-scrolly .hm-story-steps li.is-on ~ li {
    align-self: stretch;
    transform: none;
  }
  .is-scrolly .hm-story-tag { display: none; }
  .is-scrolly .hm-story-line {
    max-width: none;
    margin-top: -0.14em;
    font-size: clamp(42px, min(4.5vw, 7.8vh), 76px);
    font-weight: var(--weight-headline);
    line-height: 1.01;
    letter-spacing: -0.034em;
    -webkit-mask-image: linear-gradient(to bottom, #000 40%, transparent 60%);
    mask-image: linear-gradient(to bottom, #000 40%, transparent 60%);
    -webkit-mask-size: 100% 300%;
    mask-size: 100% 300%;
    -webkit-mask-position: 0 100%;
    mask-position: 0 100%;
    transform: translateY(0.12em);
    transition: -webkit-mask-position 1.4s var(--ease-out), mask-position 1.4s var(--ease-out), transform 1.4s var(--ease-out);
  }
  .is-scrolly .hm-story-steps li.is-on .hm-story-line {
    -webkit-mask-position: 0 0;
    mask-position: 0 0;
    transform: none;
    transition-delay: 0.12s;
  }

  /* The note closes on the plates' lower edge. */
  .is-scrolly .hm-story-note {
    position: absolute;
    top: calc(var(--plates-b) - var(--copy-y));
    width: clamp(380px, 33vw, 520px);
    max-width: none;
    margin: 0;
    padding-top: 18px;
    border-top: 1px solid rgba(17, 13, 23, 0.14);
    font-size: clamp(16.5px, 1.3vw, 19px);
    line-height: 1.55;
    transform: translateY(calc(-100% + 0.36em));
  }

  .is-scrolly .hm-story-area {
    display: block;
    grid-column: 7 / 12;
    grid-row: 2;
    margin: 0 0 30px;
  }
}

/* Short wide screens: tighter type, and (.is-tight, set by paradigm-v8.js when the note would meet the
   headline) the note flows under the headline instead of closing on the plates. */
@media (min-width: 761px) and (orientation: landscape) and (max-height: 640px) {
  .is-scrolly .hm-story-index { margin-bottom: clamp(14px, 4vh, 36px); padding-bottom: 10px; }
  .is-scrolly .hm-story-line { font-size: clamp(24px, min(4.5vw, 7vh), 76px); }
}

@media (min-width: 761px) and (orientation: landscape), (min-width: 1101px) {
  .hm-story.is-tight .hm-story-note {
    position: relative;
    top: auto;
    width: auto;
    max-width: var(--measure-note);
    margin-top: clamp(12px, 2.4vh, 20px);
    padding-top: 0;
    border-top: 0;
    font-size: clamp(14px, 1.15vw, 17px);
    line-height: 1.5;
    transform: none;
  }
}

@media (min-width: 761px) and (orientation: landscape) and (prefers-reduced-motion: reduce),
  (min-width: 1101px) and (prefers-reduced-motion: reduce) {
  .is-scrolly .hm-story-line { transition: none; }
}
