/* ── HOW IT WORKS - a scroll story ──
   The section pins while the page scrolls, and the motion is scrubbed by the
   scroll itself: how-story.js turns the scroll position into three phase
   values, each 0..1, and every moving part below is a function of them -
     --a  assemble  the five pieces glide from scattered into the record's rows
     --s  seal      the outline draws round the record, the lock and the four
                    sources arrive
     --d  deliver   the record shrinks away, the Live Rights Passport rises
   data-step (0..2) picks the step text; --p (0..1) fills the progress rail.
   Brand blues only in the glass glow. Reduced motion: the delivered state. */

#how-it-works {
  padding-top: 24px;
  padding-bottom: 0;
}

/* the title rides with the pinned stage, so it stays on screen */
.hx-head {
  grid-column: 1 / -1;
  align-self: start;
  margin: 0;
}
.hx-head .section-title {
  margin-bottom: 0;
}
.hx-story {
  --hx-ease: cubic-bezier(0.22, 1, 0.36, 1);
  --hx-line: rgba(51, 73, 179, 0.16);
  --hx-card: rgba(255, 255, 255, 0.28);
  --hx-card-line: rgba(255, 255, 255, 0.75);
  --hx-chip-bg: rgba(255, 255, 255, 0.4);
  --hx-glass-edge: inset 0 1px 0 rgba(255, 255, 255, 0.9);
  --hx-orb-a: rgba(67, 89, 194, 0.32);
  --hx-orb-b: rgba(165, 191, 240, 0.4);
  --hx-chip-fg: var(--text);
  --hx-accent: var(--primary);
  --hx-glow: rgba(51, 73, 179, 0.22);

  /* phase values, set by how-story.js */
  --a: 0;
  --s: 0;
  --d: 0;

  /* stage geometry: desktop values; phones override below */
  --rs: 1;
  --ps: 1;
  --bx: 230px;
  --by1: -90px;
  --by2: 70px;

  position: relative;
  height: calc(600px + 110vh);
}
.theme-dark .hx-story {
  --hx-line: rgba(255, 255, 255, 0.1);
  --hx-card: rgba(255, 255, 255, 0.05);
  --hx-card-line: rgba(255, 255, 255, 0.14);
  --hx-chip-bg: rgba(255, 255, 255, 0.07);
  --hx-glass-edge: inset 0 1px 0 rgba(255, 255, 255, 0.12);
  --hx-orb-a: rgba(114, 135, 255, 0.34);
  --hx-orb-b: rgba(51, 73, 179, 0.4);
  --hx-accent: #a5bff0;
  --hx-glow: rgba(114, 135, 255, 0.3);
}
.hx-sticky {
  position: sticky;
  top: 84px;
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
  grid-template-rows: auto minmax(0, 1fr);
  gap: 8px 48px;
  align-items: center;
  height: 600px;
}

/* ── the steps, left ── */
.hx-steps {
  position: relative;
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0 0 0 28px;
  list-style: none;
}
.hx-rail {
  position: absolute;
  top: 10px;
  bottom: 10px;
  left: 0;
  width: 2px;
  border-radius: 2px;
  background: var(--hx-line);
}
.hx-rail span {
  position: absolute;
  inset: 0 0 auto;
  height: calc(var(--p, 0) * 100%);
  border-radius: 2px;
  background: linear-gradient(var(--primary), var(--primary2));
  box-shadow: 0 0 10px var(--hx-glow);
}
.hx-step {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  gap: 12px;
  padding: 16px 0;
  opacity: 0.35;
  transition: opacity 0.5s var(--hx-ease);
}
.hx-step-n {
  font-family: var(--font-head);
  font-size: 15px;
  font-weight: 600;
  color: var(--hx-accent);
}
.hx-step-h {
  margin: 0;
  font-family: var(--font-head);
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.015em;
  color: var(--text);
}
.hx-step-p {
  max-height: 0;
  margin: 0;
  overflow: hidden;
  font-size: 16px;
  line-height: 1.55;
  color: var(--muted);
  opacity: 0;
  transition:
    max-height 0.6s var(--hx-ease),
    opacity 0.5s var(--hx-ease),
    margin 0.6s var(--hx-ease);
}
.hx-story[data-step="0"] .hx-step[data-n="0"],
.hx-story[data-step="1"] .hx-step[data-n="1"],
.hx-story[data-step="2"] .hx-step[data-n="2"] {
  opacity: 1;
}
.hx-story[data-step="0"] .hx-step[data-n="0"] .hx-step-p,
.hx-story[data-step="1"] .hx-step[data-n="1"] .hx-step-p,
.hx-story[data-step="2"] .hx-step[data-n="2"] .hx-step-p {
  max-height: 6em;
  margin-top: 8px;
  opacity: 1;
}

/* ── the stage, right ── */
.hx-stage {
  position: relative;
  height: 100%;
  min-height: 0;
}
.hx-stage::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 520px;
  height: 420px;
  margin: -210px 0 0 -260px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 35%, var(--hx-orb-a), transparent 60%),
    radial-gradient(circle at 70% 70%, var(--hx-orb-b), transparent 55%);
  filter: blur(40px);
  pointer-events: none;
  animation: hx-drift 12s ease-in-out infinite alternate;
}
@keyframes hx-drift {
  to {
    transform: translate(24px, -16px) rotate(20deg) scale(1.06);
  }
}

/* small labels as tags */
.hx-raw-label,
.hx-backs-k {
  position: absolute;
  top: 2%;
  left: 50%;
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(67, 89, 194, 0.12);
  backdrop-filter: blur(22px) saturate(1.6);
  -webkit-backdrop-filter: blur(22px) saturate(1.6);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--hx-accent);
  white-space: nowrap;
  transform: translateX(-50%);
}
.hx-raw-label {
  opacity: calc(1 - var(--a) * 3);
}
.hx-backs-k {
  opacity: calc(var(--s) * (1 - var(--d) * 3));
}

/* the record: a card the five pieces glide into */
.hx-rec {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 300px;
  height: 340px;
  margin: -170px 0 0 -150px;
  opacity: calc(1 - var(--d) * 2.6);
  transform: scale(calc(var(--rs) * (1 - var(--d) * 0.45)));
}
.hx-card {
  position: absolute;
  inset: 0;
  border: 1px solid var(--hx-card-line);
  border-radius: 22px;
  background: var(--hx-card);
  backdrop-filter: blur(22px) saturate(1.6);
  -webkit-backdrop-filter: blur(22px) saturate(1.6);
  box-shadow:
    var(--hx-glass-edge),
    0 24px 60px rgba(15, 23, 42, 0.1);
  opacity: calc(0.15 + var(--a) * 0.85);
  transform: scale(calc(0.94 + var(--a) * 0.06));
}
.hx-card-h {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 20px 22px 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}
.hx-card-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--hx-accent);
}

/* the five pieces: from scattered (--sx, --sy, --sr) to the record's rows */
.hx-chip {
  position: absolute;
  top: 50%;
  left: 50%;
  display: flex;
  align-items: center;
  width: 244px;
  height: 40px;
  margin: -20px 0 0 -122px;
  padding: 0 16px;
  border: 1px solid var(--hx-card-line);
  border-radius: 12px;
  background: var(--hx-chip-bg);
  backdrop-filter: blur(22px) saturate(1.6);
  -webkit-backdrop-filter: blur(22px) saturate(1.6);
  box-shadow: var(--hx-glass-edge);
  font-size: 14px;
  font-weight: 600;
  color: var(--hx-chip-fg);

  --cx: var(--sx);
  --cy: var(--sy);

  transform: translate(
      calc(var(--cx) * (1 - var(--a))),
      calc(var(--cy) * (1 - var(--a)) + (-86px + var(--i) * 50px) * var(--a))
    )
    rotate(calc(var(--sr) * (1 - var(--a))));
}

/* the seal: an outline drawn round the record, then the lock */
.hx-seal {
  position: absolute;
  inset: -10px;
  width: calc(100% + 20px);
  height: calc(100% + 20px);
  overflow: visible;
  pointer-events: none;
}
.hx-seal rect {
  fill: none;
  stroke: var(--hx-accent);
  stroke-width: 2;
  stroke-dasharray: 1;
  stroke-dashoffset: calc(1 - var(--s));
  vector-effect: non-scaling-stroke;
  opacity: calc(var(--s) * 8);
}
.hx-lock {
  position: absolute;
  top: -18px;
  right: -18px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary2));
  color: #fff;
  box-shadow: 0 10px 24px var(--hx-glow);
  opacity: calc(var(--s) * 4 - 2.6);
  transform: scale(clamp(0, var(--s) * 4 - 2.8, 1));
}
.hx-stamp {
  position: absolute;
  bottom: -46px;
  left: 50%;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--hx-chip-bg);
  border: 1px solid var(--hx-card-line);
  font-family: var(--font-mono);
  font-size: 12px;
  white-space: nowrap;
  color: var(--hx-accent);
  opacity: calc(var(--s) * 3 - 2);
  transform: translate(-50%, calc(8px - var(--s) * 8px));
}

/* the sources it is backed by glide in from the record */
.hx-backs {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.hx-back {
  position: absolute;
  top: 50%;
  left: 50%;
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(67, 89, 194, 0.1);
  color: var(--hx-accent);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  opacity: calc(var(--s) * (1 - var(--d) * 3));
  transform: translate(calc(-50% + var(--x) * var(--s)), calc(-50% + var(--y) * var(--s)))
    scale(calc(0.6 + var(--s) * 0.4));
}
.hx-back:nth-of-type(1) {
  --x: calc(var(--bx) * -1);
  --y: var(--by1);
}
.hx-back:nth-of-type(2) {
  --x: var(--bx);
  --y: var(--by1);
}
.hx-back:nth-of-type(3) {
  --x: calc(var(--bx) * -1);
  --y: var(--by2);
}
.hx-back:nth-of-type(4) {
  --x: var(--bx);
  --y: var(--by2);
}

/* delivery: the passport rises as the record shrinks away */
.hx-pass {
  position: absolute;
  top: 50%;
  left: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: 260px;
  padding: 34px 24px 28px;
  border: 1px solid var(--hx-card-line);
  border-radius: 24px;
  background: var(--hx-card);
  backdrop-filter: blur(22px) saturate(1.6);
  -webkit-backdrop-filter: blur(22px) saturate(1.6);
  box-shadow:
    0 30px 70px rgba(15, 23, 42, 0.14),
    0 0 0 calc(var(--d) * 8px) var(--hx-glow);
  opacity: calc(var(--d) * 2.2 - 0.7);
  transform: translate(-50%, calc(-50% + (1 - var(--d)) * 30px)) scale(calc(var(--ps) * (0.8 + var(--d) * 0.2)));
}
.hx-pass img {
  width: 96px;
  height: 96px;
  object-fit: contain;
}
.hx-pass-name {
  font-family: var(--font-head);
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
}
.hx-pass-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(67, 89, 194, 0.1);
  font-size: 13px;
  font-weight: 600;
  color: var(--hx-accent);
}

/* ── tablets and phones: one compact screen pins under the nav bar - the
   title, a fixed-size stage and the active step's text right under it ── */
@media (max-width: 900px) {
  .hx-story {
    --hx-nav: 92px;

    height: calc(640px + 110vh);
  }
  .hx-sticky {
    position: sticky;
    top: var(--hx-nav);
    display: flex;
    flex-direction: column;
    gap: 0;
    height: auto;
    min-height: 0;
    max-height: none;
  }
  .hx-head {
    order: -2;
    flex: 0 0 auto;
    padding: 10px 0 0;
  }
  .hx-stage {
    order: -1;
    flex: 0 0 auto;
    align-self: stretch;
    width: 100%;
    height: clamp(320px, calc(100svh - var(--hx-nav) - 260px), 460px);
    min-height: 0;
    overflow: clip;
  }
  .hx-stage::before {
    width: 280px;
    height: 280px;
    margin: -140px 0 0 -140px;
    filter: blur(50px);
  }

  /* the caption: all three steps sit in one spot, only the active one shows */
  .hx-steps {
    flex: 0 0 auto;
    display: grid;
    min-height: 120px;
    padding: 4px 0 0 20px;
  }
  .hx-step {
    grid-area: 1 / 1;
    align-content: start;
    min-height: 0;
    padding: 0;
    opacity: 0;
    transform: translateY(8px);
    transition:
      opacity 0.35s var(--hx-ease),
      transform 0.35s var(--hx-ease);
  }
  .hx-story[data-step="0"] .hx-step[data-n="0"],
  .hx-story[data-step="1"] .hx-step[data-n="1"],
  .hx-story[data-step="2"] .hx-step[data-n="2"] {
    opacity: 1;
    transform: none;
  }
  .hx-step-h {
    font-size: 21px;
  }
  .hx-step-p {
    max-height: none;
    margin-top: 6px;
    font-size: 15px;
    opacity: 1;
  }
  .hx-rail {
    top: 6px;
    bottom: 4px;
  }
}
@media (max-width: 520px) {
  .hx-story {
    --rs: 0.72;
    --ps: 0.85;
    --bx: 70px;
    --by1: -150px;
    --by2: 150px;
  }

  /* the start positions are inline per piece, so phones switch which pair
     is read rather than overriding them */
  .hx-chip {
    --cx: var(--mx);
    --cy: var(--my);
  }
  .hx-backs-k,
  .hx-stamp {
    display: none;
  }
}

/* ── reduced motion: the delivered state; the steps read as a list ── */
@media (prefers-reduced-motion: reduce) {
  .hx-story *,
  .hx-story *::before,
  .hx-story *::after {
    transition: none !important;
    animation: none !important;
  }
  .hx-story .hx-step {
    opacity: 1;
  }
  .hx-story .hx-step .hx-step-p {
    max-height: none;
    margin-top: 8px;
    opacity: 1;
  }
}
