/* =========================================================
   SCROLL SEQUENCE BOX
========================================================= */

.ssbox-wrap{
  position: relative;
  isolation: isolate;
  min-height: 0;
}

.ssbox-grid{
  display: grid;
  grid-template-columns:
    minmax(0, var(--ssbox-stage-w, 520px))
    minmax(0, 1fr);
  gap: var(--ssbox-gap, 48px);
  align-items: start;
}


/* =========================================================
   GRID STICKY
========================================================= */

.ssbox-wrap.grid-sticky .ssbox-grid{
  position: sticky;
  top: var(--ssbox-grid-top, 0px);
  width: 100%;
  left: 0;
  right: 0;
  z-index: 1;
}


/* =========================================================
   MEDIA POSITION
========================================================= */

.ssbox-wrap.media-right .ssbox-grid{
  grid-template-columns:
    minmax(0, 1fr)
    minmax(0, var(--ssbox-stage-w, 520px));
}

.ssbox-wrap.media-right .ssbox-media{
  order: 2;
}

.ssbox-wrap.media-right .ssbox-content{
  order: 1;
}


/* =========================================================
   MEDIA
========================================================= */

.ssbox-media{
  position: relative;
  min-width: 0;
  justify-self: start;
  align-self: stretch;
}


/* =========================================================
   STAGE
========================================================= */

.ssbox-stage{
  position: relative;
  width: var(--ssbox-stage-w, 520px);
  height: auto;
  aspect-ratio: var(--ssbox-stage-ar, 1.777778);
  max-width: 100%;
  border-radius: var(--ssbox-stage-r, 16px);
  overflow: hidden;
  background: transparent;
  justify-self: start;
}


/* Desktop sticky sequence */

.ssbox-wrap.is-sticky .ssbox-stage{
  position: sticky;
  top: var(--ssbox-top, 0px);
}


/* =========================================================
   CANVAS
========================================================= */

.ssbox-canvas{
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}


/* =========================================================
   OVERLAY
========================================================= */

.ssbox-overlay{
  position: absolute;
  inset: 0;
  background: var(--ssbox-overlay, #000);
  opacity: var(--ssbox-overlay-opacity, 0.2);
  pointer-events: none;
  z-index: 2;
}


/* Hide overlay until canvas is ready */

.ssbox-wrap:not(.is-fallback)
.ssbox-stage:not(.is-canvas-ready)
.ssbox-overlay{
  opacity: 0;
}


/* =========================================================
   CONTENT
========================================================= */

.ssbox-content{
  position: relative;
  min-width: 0;
}


/* =========================================================
   BLACK BACKGROUND KNOCKOUT
========================================================= */

.ssbox-wrap.has-black-knockout{
  isolation: auto;
}

.ssbox-wrap.has-black-knockout .ssbox-stage{
  mix-blend-mode: screen;
}


/* =========================================================
   FALLBACK IMAGE
========================================================= */

.ssbox-fallback-img{
  display: none;
  width: 100%;
  max-width: none;
  height: auto;
}

.ssbox-wrap.is-fallback{
  min-height: auto !important;
}

.ssbox-wrap.is-fallback .ssbox-canvas{
  display: none !important;
}

.ssbox-wrap.is-fallback .ssbox-fallback-img{
  display: block;
}

.ssbox-wrap.is-fallback .ssbox-media{
  min-height: 0 !important;
}

.ssbox-wrap.is-fallback .ssbox-stage{
  height: auto !important;
  aspect-ratio: auto !important;
  position: relative !important;
  top: auto !important;
}

.ssbox-wrap.is-fallback .ssbox-grid{
  position: static !important;
  top: auto !important;
}


/* =========================================================
   DESKTOP
   1025px AND ABOVE

   Preset ratios represent:
   CONTENT / MEDIA
========================================================= */

@media (min-width: 1025px){

  /*
   * MEDIA LEFT
   *
   * User-facing ratio:
   * CONTENT / MEDIA
   *
   * Visual grid:
   * MEDIA / CONTENT
   */

  .ssbox-wrap.has-column-split.media-left .ssbox-grid{
    display: grid;
    grid-template-columns:
      minmax(0, var(--ssbox-media-col, 1fr))
      minmax(0, var(--ssbox-content-col, 1fr));
  }


  /*
   * MEDIA RIGHT
   *
   * Visual grid:
   * CONTENT / MEDIA
   */

  .ssbox-wrap.has-column-split.media-right .ssbox-grid{
    display: grid;
    grid-template-columns:
      minmax(0, var(--ssbox-content-col, 1fr))
      minmax(0, var(--ssbox-media-col, 1fr));
  }


  /* Fill the assigned media column */

  .ssbox-wrap.has-column-split .ssbox-media{
    width: 100%;
    min-width: 0;
    justify-self: stretch;
  }


  /* Preset layouts use the grid track for stage width */

  .ssbox-wrap.has-column-split .ssbox-stage{
    width: 100%;
    max-width: 100%;
  }
}


/* =========================================================
   TABLET + MOBILE BASE
   1024px AND BELOW

   Always stack:
   1. MEDIA
   2. CONTENT
========================================================= */

@media (max-width: 1024px){

  .ssbox-wrap{
    min-height: auto;
  }


  /* One-column layout */

  .ssbox-wrap .ssbox-grid,
  .ssbox-wrap.media-right .ssbox-grid{
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    width: 100%;
  }


  /*
   * Disable whole-grid sticky behavior on smaller screens.
   * Stage pinning is controlled separately.
   */

  .ssbox-wrap.grid-sticky .ssbox-grid,
  .ssbox-wrap.grid-sticky.media-right .ssbox-grid{
    position: static;
    top: auto;
    left: auto;
    right: auto;
  }


  /* Media always first */

  .ssbox-wrap .ssbox-media,
  .ssbox-wrap.media-right .ssbox-media{
    order: 1;
    width: 100%;
    min-width: 0;
    justify-self: stretch;
    align-self: auto;
  }


  /* Content always second */

  .ssbox-wrap .ssbox-content,
  .ssbox-wrap.media-right .ssbox-content{
    order: 2;
    width: 100%;
    min-width: 0;
  }


  /* Prevent stage overflow */

  .ssbox-stage{
    max-width: 100%;
  }


  /*
   * Preset layouts become full-width once stacked.
   */

  .ssbox-wrap.has-column-split .ssbox-stage{
    width: 100%;
    max-width: 100%;
    justify-self: stretch;
  }


  /* Normal stack mode */

  .ssbox-wrap.mobile-stack .ssbox-stage,
  .ssbox-wrap.mobile-stack.is-sticky .ssbox-stage{
    position: relative;
    top: auto;
  }


  /* Fallback images always fill stacked media column */

  .ssbox-wrap.is-fallback .ssbox-media{
    min-height: 0 !important;
    width: 100%;
    justify-self: stretch;
  }

  .ssbox-wrap.is-fallback .ssbox-stage{
    width: 100% !important;
    max-width: none !important;
    justify-self: stretch;
  }

  .ssbox-wrap.is-fallback .ssbox-fallback-img{
    width: 100%;
    max-width: none;
    height: auto;
  }
}


/* =========================================================
   TABLET
   768px - 1024px

   Stack media above content.
   NO 200vh media track.
   NO pinned mobile sequence.
========================================================= */

@media (min-width: 768px) and (max-width: 1024px){

  /*
   * Explicitly remove the mobile extended scroll area.
   */

  .ssbox-wrap.mobile-pin-sequence .ssbox-media{
    min-height: 0;
  }


  /*
   * Tablet stage stays in normal document flow.
   * Media sits above the content instead of pinning.
   */

  .ssbox-wrap.mobile-pin-sequence .ssbox-stage,
  .ssbox-wrap.mobile-pin-sequence.is-sticky .ssbox-stage{
    position: relative;
    top: auto;
    z-index: auto;
    max-height: none;
  }


  /* Tablet media uses available width */

  .ssbox-wrap.has-column-split .ssbox-stage{
    width: 100%;
    max-width: 100%;
  }
}


/* =========================================================
   PHONE
   767px AND BELOW

   Allow pinned sequence behavior.
========================================================= */

@media (max-width: 767px){

  /*
   * Extended scroll area used to scrub the sequence
   * before the content appears.
   */

  .ssbox-wrap.mobile-pin-sequence .ssbox-media{
    min-height: var(--ssbox-mobile-sequence-h, 200vh);
  }


  /*
   * Pin sequence during the mobile scroll area.
   */

  .ssbox-wrap.mobile-pin-sequence .ssbox-stage,
  .ssbox-wrap.mobile-pin-sequence.is-sticky .ssbox-stage{
    position: sticky;
    top: var(--ssbox-top, 0px);
    z-index: 1;
    max-height: calc(100dvh - var(--ssbox-top, 0px));
  }


  /* Preset media remains full width */

  .ssbox-wrap.has-column-split .ssbox-stage{
    width: 100%;
    max-width: 100%;
  }
}