/* ==========================================================================
   Section: promotional-banner  →  assets/section-promotional-banner.css
   Figma 1142-6483: full-bleed 2×2 grid with 4px gaps, 64px below the section above.
   Row 1 is one wide panel (1440×820 at the design width), row 2 two columns (718×820):
   Men's Essentials and Women's Essentials.

   Each <promo-panel> is a scroll track holding one sticky frame:

     .promo-panel          the track — as tall as the frame, plus a panel height of runway for
                           every image after the first (the component sets that)
     .promo-panel__frame   sticks under the header; holds the media and the content

   So a panel with several images sticks to the top of the screen while the next image is pulled
   up over the one showing, and releases once the last one has landed. A panel with a single
   image never sticks (its track is exactly its frame) and takes the drift parallax instead.

   The title runs down its track (top inset → --cta-gap above the button). The component moves
   it at one steady speed from the moment the frame sticks until the panel has scrolled past, so
   it never pauses and lands above the button as the panel leaves; more images, slower title.
   Without the script it is sticky: it holds its spot on screen and is handed back when the
   button reaches it.
   ========================================================================== */
.promotional-banner {
  --panel-gap: 4px;
  --section-top: 64px;

  padding-top: var(--section-top);
}

.promotional-banner__grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--panel-gap);
}

/* ----------------------------------------------------------------- track */
.promo-panel {
  --sticky-top: calc(var(--header-height) + 1px); /* just under the solid header */
  --content-inset-x: 60px;
  --content-inset-y: 40px;
  --cta-height: 40px;
  --cta-gap: 24px;
  --parallax-shift: 8%;  /* drift distance, and the crop headroom it needs */
  --slide-runway: 100%;  /* scroll spent on each incoming image, as a share of the panel height */
  --slide-hold: 0.4;     /* runway held after the last image lands, before the frame releases */
  --media-bleed: 0px;    /* the drift mode opens this up to --parallax-shift */
  --overlay-color: #000000;
  --overlay-opacity: 0;
  --panel-bg: var(--color-page-bg);

  display: block;
  color: var(--color-text-inverse);
}

/* Figma's panel proportions. The component swaps this for a measured height once it takes over,
   so the frame is never taller than the room under the header. */
.promo-panel--wide {
  grid-column: 1 / -1;
  aspect-ratio: 1440 / 820;
  --panel-bg: var(--color-surface-muted);
  /* the panel is the viewport, so the gutter is the usual one */
  --edge: max(var(--page-gutter), calc((100% - var(--page-width)) / 2));
  --inset-start: var(--edge);
  --inset-end: var(--edge);
}

.promo-panel--column {
  aspect-ratio: 718 / 820;
  --panel-bg: #1c1c1c;
  /* the panel is half the viewport less half the gap, so the viewport is 2 × 100% + the gap and
     the page gutter comes out as 100% + gap/2 - page-width/2 — no 100vw, which would count the
     scrollbar and put this section's content out of step with every .page-width above it */
  --edge: max(var(--page-gutter), calc(100% + var(--panel-gap) / 2 - var(--page-width) / 2));
}

/* Which side of a panel is a page edge: the content lines up with the page container there and
   keeps the Figma inset on the side that faces the other panel. Identical at 1440, where the
   gutter and the inset are both 60px. */
.promo-panel--edge-start {
  --inset-start: var(--edge);
}

.promo-panel--edge-end {
  --inset-end: var(--edge);
}

/* ----------------------------------------------------------------- frame */
.promo-panel__frame {
  position: sticky;
  top: var(--sticky-top);
  height: var(--panel-h, 100%);
  overflow: clip;
  background: var(--panel-bg);
}

/* -----------------------------------------------------------------  media
   In the drift mode the crop window is --parallax-shift taller than the frame at both ends,
   which is exactly the headroom the drift needs: no edge can enter the frame, whatever crop or
   focal point an image is given. Sliding images need no headroom, so they get none. */
.promo-panel__media {
  position: absolute;
  inset: calc(-1 * var(--media-bleed)) 0;
}

.promo-panel[data-mode='drift'] {
  --media-bleed: var(--parallax-shift);
}

/* Images stack in document order, so a later one covers the one before it. --slide is how far
   below its resting place an image waits, --drift is the parallax offset, and
   --focal-x / --focal-y / --zoom are the Figma crop. */
.promo-panel__image {
  --focal-x: 50%;
  --focal-y: 50%;
  --zoom: 1;
  --slide: 0%;
  --drift: 0px;

  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: var(--focal-x) var(--focal-y);
  transform: translate3d(0, var(--slide), 0) translate3d(0, var(--drift), 0) scale(var(--zoom));
  transform-origin: var(--focal-x) var(--focal-y);
  will-change: transform;
}

/* Every image after the first waits a frame height below until it is pulled up */
.promo-panel__image + .promo-panel__image {
  --slide: 100%;
}

/* Figma tints each panel over its photo */
.promo-panel__frame::after {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--overlay-color);
  opacity: var(--overlay-opacity);
  pointer-events: none;
}

/* --------------------------------------------------------------- content */
.promo-panel__content {
  position: absolute;
  inset: var(--content-inset-y) var(--inset-end, var(--content-inset-x)) var(--content-inset-y)
    var(--inset-start, var(--content-inset-x));
  z-index: 1;
}

/* The title's run: from the top inset down to --cta-gap above the button. Sticky bottoms out at
   the end of this box, which is what hands the title back to the page at the right moment. */
.promo-panel__text-track {
  height: max(0px, calc(100% - var(--cta-height) - var(--cta-gap)));
}

.promo-panel__text {
  position: sticky;
  top: calc(var(--sticky-top) + var(--content-inset-y));
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: min(100%, var(--text-width, 680px));
}

.promo-panel[data-title-sticky='false'] .promo-panel__text {
  position: static;
}

/* the component drives the title with a transform instead */
.promo-panel[data-title-motion='scroll'] .promo-panel__text {
  position: relative;
  top: auto;
  will-change: transform;
}

.promo-panel__title {
  font-family: var(--font-display);
  font-size: var(--panel-title-size, var(--text-display-m-size));
  font-weight: 500;
  line-height: 1.2;
  color: var(--color-text-inverse);
}

.promo-panel__body {
  font-size: var(--text-body-m-size);
  line-height: 1.2;
  color: var(--color-text-inverse);
}

.promo-panel--column .promo-panel__text {
  --text-width: 600px;
  --panel-title-size: var(--text-display-l-size); /* 48px — Heading/H1 */
  gap: 0;
}

.promo-panel__cta {
  position: absolute;
  bottom: 0;
  left: 0;
  height: var(--cta-height);
}

/* ----------------------------------------------------------- responsive */
@media (max-width: 989px) {
  .promo-panel {
    --content-inset-x: 40px;
    --content-inset-y: 32px;
  }

  .promo-panel--wide .promo-panel__text {
    --panel-title-size: 44px;
  }

  .promo-panel--column .promo-panel__text {
    --panel-title-size: 36px;
  }
}

@media (max-width: 749px) {
  .promotional-banner {
    --section-top: 40px;
  }

  /* One column: the two lower panels stack and take a squarer crop */
  .promotional-banner__grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .promo-panel--wide,
  .promo-panel--column {
    aspect-ratio: 3 / 4;
  }

  .promo-panel {
    --content-inset-x: 20px;
    --content-inset-y: 24px;
    --cta-gap: 16px;
  }

  .promo-panel--wide .promo-panel__text {
    --panel-title-size: 36px;
  }

  .promo-panel--column .promo-panel__text {
    --panel-title-size: 32px;
  }
}
