/* Media that grows from a rounded inset card to full bleed. scroll-zoom.js
   writes --mw-zoom-e (expansion), --mw-zoom-t (overlay title) and --mw-zoom-o
   (intro leaving) on the section; this file draws them. The two text blocks
   move with the scroll but never fade with it: their opacity swaps through
   .mw-zoom--intro-out and .mw-zoom--title-in with a timed transition, so text
   is always fully readable or gone wherever the visitor stops. Card geometry at the
   start, as insets of the full-bleed stage:
     --mw-zoom-x        side inset, each side (default 20%: a 60% wide card)
     --mw-zoom-top      top inset (default 18%)
     --mw-zoom-bottom   bottom inset (default 18%)
     --mw-zoom-radius   corner radius of the card (default 28px)
     --mw-zoom-media-from  media scale at the start (1.12 zooms out as it
                        grows; use the card width, e.g. .6, to show a whole
                        contained video inside the card)
     --mw-zoom-static-h height of the media under reduced motion (80svh)
     --mw-zoom-bg       frame colour behind contained media
     --mw-zoom-veil     gradient over the media that fades in with the title
   Without JavaScript and under reduced motion: final full-bleed state in the
   flow, intro above the media, title over it. */

.mw-zoom {
  --mw-zoom-x: 20%;
  --mw-zoom-top: 18%;
  --mw-zoom-bottom: 18%;
  --mw-zoom-radius: 28px;
  --mw-zoom-media-from: 1.12;
}

/* One cell: media frame, intro and overlay stacked. */
.mw-zoom:not(.mw-runway),
.mw-zoom > .mw-runway__stage {
  display: grid;
  grid-template: minmax(0, 1fr) / minmax(0, 1fr);
}

.mw-zoom__frame,
.mw-zoom__intro,
.mw-zoom__overlay {
  grid-area: 1 / 1;
  min-width: 0;
}

.mw-zoom__frame {
  --mw-zoom-k: calc(1 - var(--mw-zoom-e, 1));
  position: relative;
  overflow: hidden;
  overflow: clip;
  clip-path: inset(
    calc(var(--mw-zoom-top) * var(--mw-zoom-k))
    calc(var(--mw-zoom-x) * var(--mw-zoom-k))
    calc(var(--mw-zoom-bottom) * var(--mw-zoom-k))
    calc(var(--mw-zoom-x) * var(--mw-zoom-k))
    round calc(var(--mw-zoom-radius) * var(--mw-zoom-k)));
}

/* Zero specificity, so a frame that is also a .mw-media-stack keeps its
   --mw-media-bg. */
:where(.mw-zoom__frame) { background: var(--mw-zoom-bg, transparent); }

/* A veil over the media, under the corner controls: set --mw-zoom-veil to a
   gradient; it is fully on whenever the title is shown. */
.mw-zoom__frame::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  background: var(--mw-zoom-veil, none);
  pointer-events: none;
  transition: opacity .45s ease;
}

/* The media fills the stage and is scaled and moved to the card centre. */
.mw-zoom__media {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  translate: 0 calc((var(--mw-zoom-top) - var(--mw-zoom-bottom)) * .5 * var(--mw-zoom-k));
  scale: calc(var(--mw-zoom-media-from) + (1 - var(--mw-zoom-media-from)) * var(--mw-zoom-e, 1));
}

/* Controls that ride the card's lower right corner (the media-stack pause
   button when the frame is also a .mw-media-stack). */
.mw-zoom__frame > .mw-media-stack__toggle,
.mw-zoom__corner {
  position: absolute;
  right: calc(var(--mw-zoom-x) * var(--mw-zoom-k) + 16px);
  bottom: calc(var(--mw-zoom-bottom) * var(--mw-zoom-k) + 16px);
  z-index: 2;
}

.mw-zoom__intro,
.mw-zoom__overlay {
  position: relative;
  pointer-events: none;
}
.mw-zoom__intro :is(a, button, input, select, textarea, [tabindex]),
.mw-zoom__overlay :is(a, button, input, select, textarea, [tabindex]) { pointer-events: auto; }

.mw-zoom__intro {
  z-index: 3;
  align-self: start;
  translate: 0 calc(var(--mw-zoom-o, 0) * -64px);
  transition: opacity .35s ease, visibility 0s;
}
.mw-zoom--intro-out .mw-zoom__intro {
  opacity: 0;
  visibility: hidden;
  transition: opacity .35s ease, visibility 0s linear .35s;
}

.mw-zoom__overlay {
  z-index: 2;
  align-self: end;
  translate: 0 calc((1 - var(--mw-zoom-t, 1)) * 48px);
  transition: opacity .45s ease, visibility 0s;
}
/* Only while the runway is live (JavaScript on, motion allowed): before the
   title's band, the title and its veil are off. */
.mw-zoom.mw-runway:not(.mw-runway--static):not(.mw-zoom--title-in) .mw-zoom__overlay {
  opacity: 0;
  visibility: hidden;
  transition: opacity .45s ease, visibility 0s linear .45s;
}
.mw-zoom.mw-runway:not(.mw-runway--static):not(.mw-zoom--title-in) .mw-zoom__frame::after { opacity: 0; }

/* Reduced motion and no JavaScript: intro in the flow above the media. */
.mw-zoom:not(.mw-runway),
.mw-zoom.mw-runway--static > .mw-runway__stage {
  grid-template-rows: auto minmax(var(--mw-zoom-static-h, 80svh), 1fr);
}
.mw-zoom:not(.mw-runway) > .mw-zoom__intro,
.mw-zoom.mw-runway--static .mw-zoom__intro { grid-row: 1; }
.mw-zoom:not(.mw-runway) > :is(.mw-zoom__frame, .mw-zoom__overlay),
.mw-zoom.mw-runway--static :is(.mw-zoom__frame, .mw-zoom__overlay) { grid-row: 2; }
