/* ==========================================================================
   oxagen.sh: hero treatments and scroll motion for the site pages
   A published page whose hero stands one product mockup names its own
   treatment (HERO_TREATMENTS in scripts/lib/site-page-schema.mjs): the
   angle, frame, and motion that mockup takes, so no two pages open alike.
   A product page composes its hero instead (assets/site-pages.css, the
   composed opening). The header carries
   .sp-treat and data-hero-treatment, the treatment's name.
   src/motion/hero-treatments.js writes --sp-p on it as the reader scrolls:
   0 as the page loads, 1 once the hero has settled. Every rule here reads
   --sp-p, or --sp-q, which is what is left to play, so a still page shows
   the settled composition. The same number lifts each mockup further down
   the page into place as it comes into view. The page links this file
   whenever it draws a mockup, beside /assets/product-mockups.js, which
   drives it. Under reduced motion every mockup holds its settled place.
   ========================================================================== */

.sp-treat {
  --sp-p: 1;
  --sp-q: calc(1 - var(--sp-p));
  /* How far each motion and angle goes: a phone takes a gentler share. */
  --sp-amp: 1;
}
/* Before the script runs, a hero stands where the page loads it. */
@media (prefers-reduced-motion: no-preference) {
  .js .sp-treat {
    --sp-p: 0;
  }
}
@media (max-width: 768px) {
  .sp-treat {
    --sp-amp: 0.35;
  }
}

.sp-treat-stage {
  position: relative;
  margin-top: clamp(
    calc(var(--ox-space) * 12),
    6vw,
    calc(var(--ox-space) * 20)
  );
}
/* The frame, its shapes, and its caption wait for the mockup to draw, so a
   script that never runs leaves no empty frame in a first pose. */
.sp-treat-stage:not(:has(.pm[data-pm-ready])) {
  visibility: hidden;
}
.sp-treat-scene {
  position: relative;
}
.sp-treat .sp-shot-frame {
  isolation: isolate;
}
.sp-treat-stage [data-shot] > figcaption {
  justify-content: center;
  text-align: center;
}

/* The shapes a treatment draws around its mockup. Each treatment shows the
   ones it uses. */
.sp-shot-deco {
  display: none;
  position: absolute;
  z-index: -1;
  inset: 0;
  pointer-events: none;
}
.sp-shot-deco > i {
  position: absolute;
  inset: 0;
  border-radius: var(--r-lg);
}

/* The spotlight's panel has no device frame of its own, so it takes a
   card's corner, ring, and shadow. */
.sp-treat[data-hero-treatment="spotlight"] .sp-shot-frame {
  border-radius: var(--r-lg);
  box-shadow:
    0 0 0 1px var(--glass-ring),
    var(--shadow-pop);
}
.sp-treat[data-hero-treatment="spotlight"] .sp-shot-view {
  overflow: clip;
  border-radius: var(--r-lg);
}

/* ---- pair: the desktop leans back a little, and the phone slides out
   from over it to its corner. Only a desktop view leans: the frame holds
   the phone too, the main view may itself be a phone, and a phone always
   comes to rest upright and facing the reader, so its motion slides and
   grows and never turns. ---- */
.sp-treat[data-hero-treatment="pair"] .sp-shot:not(.is-phone) .sp-shot-view {
  transform-origin: 0% 50%;
  transform: perspective(2000px)
    rotateY(calc((4deg + var(--sp-q) * 10deg) * var(--sp-amp)));
  will-change: transform;
}
.sp-treat[data-hero-treatment="pair"] .sp-shot-beside {
  z-index: 1;
  transform-origin: 100% 100%;
  transform: translate(calc(var(--sp-q) * -55%), calc(var(--sp-q) * -18%))
    scale(calc(1 - var(--sp-q) * 0.12));
  will-change: transform;
}

/* ---- spotlight: the panel waits under a veil of the page's ground, lit
   by a small spot that widens until the whole panel is clear ---- */
.sp-treat[data-hero-treatment="spotlight"] .sp-treat-scene {
  max-width: calc(var(--page-wrap) * 0.88);
  margin-inline: auto;
}
.sp-treat[data-hero-treatment="spotlight"] .sp-shot-deco {
  display: block;
  z-index: 1;
  overflow: clip;
  border-radius: var(--r-lg);
}
.sp-treat[data-hero-treatment="spotlight"] .sp-shot-deco > i:first-child {
  border-radius: inherit;
  background: radial-gradient(
    circle at calc(24% + var(--sp-p) * 26%) calc(30% + var(--sp-p) * 20%),
    transparent calc(12% + var(--sp-p) * 90%),
    color-mix(in srgb, var(--void) 78%, transparent)
      calc(30% + var(--sp-p) * 110%)
  );
}

/* ---- the mockups further down the page rise into place as they come
   into view. A chart or a record on a stage stays put. ---- */
.sp-sec :is(.sp-wide-figure, .sp-bleed-view, .sp-stage:has(.sp-shot)) {
  --sp-p: 1;
}
.sp-sec :is(.sp-wide-figure, .sp-stage:has(.sp-shot)) > .sp-figure {
  opacity: calc(0.5 + var(--sp-p) * 0.5);
  transform: translateY(calc((1 - var(--sp-p)) * var(--ox-space) * 14))
    scale(calc(0.96 + var(--sp-p) * 0.04));
}
.sp-sec .sp-bleed-view > .sp-figure {
  opacity: calc(0.5 + var(--sp-p) * 0.5);
  transform: translateX(calc((1 - var(--sp-p)) * var(--ox-space) * 20));
}
.sp-sec .sp-bleed.is-flip .sp-bleed-view > .sp-figure {
  transform: translateX(calc((1 - var(--sp-p)) * var(--ox-space) * -20));
}

/* A reader who turns motion off sees every mockup settled. */
html[data-motion="off"]
  :is(.sp-treat, .sp-sec .sp-wide-figure, .sp-sec .sp-bleed-view, .sp-sec .sp-stage:has(.sp-shot)) {
  --sp-p: 1 !important;
}
/* Print takes the settled pose too, whatever the scroll. */
@media print, (prefers-reduced-motion: reduce) {
  :is(.sp-treat, .sp-sec .sp-wide-figure, .sp-sec .sp-bleed-view, .sp-sec .sp-stage:has(.sp-shot)) {
    --sp-p: 1 !important;
  }
  .sp-treat[data-hero-treatment]
    :is(.sp-shot:not(.is-phone) .sp-shot-view, .sp-shot-beside) {
    will-change: auto;
  }
}
