/* ==========================================================================
   Media optimisation
   - Click-to-play YouTube story facades (no third-party iframe before click)
   - Deferred background video placeholders that keep the poster painted
   - Off-screen rendering hints for below-the-fold media grids
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Story video facade
   The card keeps its existing fixed height (480px desktop / 320px mobile),
   so the facade simply fills the .csm-stories-video box and never changes
   the card's aspect ratio or causes layout shift.
   -------------------------------------------------------------------------- */
.cms-story-facade {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  min-height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: inherit;
  background: transparent;
  color: #ffffff;
  cursor: pointer;
  overflow: hidden;
  z-index: 4; /* above .csm-stories-card-link (z-index: 3), below the content overlay */
  appearance: none;
  -webkit-appearance: none;
  -webkit-tap-highlight-color: transparent;
}

.cms-story-facade:focus {
  outline: none;
}

.cms-story-facade:focus-visible {
  outline: 3px solid var(--color-yellow, #f0953a);
  outline-offset: -3px;
}

.cms-story-facade__poster {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  transition: transform 0.45s cubic-bezier(0.16, 1, 0.3, 1);
  will-change: transform;
}

.cms-story-facade:hover .cms-story-facade__poster,
.cms-story-facade:focus-visible .cms-story-facade__poster {
  transform: scale(1.04);
}

.cms-story-facade__play {
  position: absolute;
  top: 50%;
  left: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 70px;
  height: 70px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  color: var(--color-deepblue, #273169);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
  transform: translate(-50%, -50%);
  transition: transform 0.25s ease, background-color 0.25s ease;
  pointer-events: none;
  z-index: 2;
  animation: cms-story-play-pulse 2.6s ease-out infinite;
}

.cms-story-facade__play svg {
  width: 26px;
  height: 26px;
  margin-left: 3px;
  display: block;
}

.cms-story-facade:hover .cms-story-facade__play,
.cms-story-facade:focus-visible .cms-story-facade__play {
  background: #ffffff;
  transform: translate(-50%, -50%) scale(1.08);
  animation: none;
}

@keyframes cms-story-play-pulse {
  0%,
  100% {
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.28), 0 0 0 0 rgba(255, 255, 255, 0.45);
  }
  70% {
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.28), 0 0 0 18px rgba(255, 255, 255, 0);
  }
}

/* The injected iframe reuses the existing .csm-stories-video iframe rules. */
.cms-story-iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}

/* --------------------------------------------------------------------------
   2. Deferred background video
   Until media-optim.js hydrates the element it has no src, so the poster
   (or the section background colour) stays visible. Both video wrappers are
   absolutely positioned by the theme, so nothing reflows on hydration.
   -------------------------------------------------------------------------- */
video[data-an-lazy-video] {
  background-color: rgba(39, 49, 105, 0.65);
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
}

/* --------------------------------------------------------------------------
   3. Below-the-fold media grids
   content-visibility lets the browser skip layout/paint for off-screen
   galleries and logo walls. contain-intrinsic-size uses the previously
   rendered size where supported, with a sensible fallback height.
   -------------------------------------------------------------------------- */
@supports (content-visibility: auto) {
  .an-gallery {
    content-visibility: auto;
    contain-intrinsic-size: auto 420px;
  }

  .an-logo-wall {
    content-visibility: auto;
    contain-intrinsic-size: auto 120px;
  }
}

/* --------------------------------------------------------------------------
   4. Reduced motion
   No pulsing play icon, no hover scale, no poster zoom.
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .cms-story-facade__poster,
  .cms-story-facade__play {
    transition: none !important;
    animation: none !important;
    will-change: auto;
  }

  .cms-story-facade:hover .cms-story-facade__poster,
  .cms-story-facade:focus-visible .cms-story-facade__poster {
    transform: none !important;
  }

  .cms-story-facade:hover .cms-story-facade__play,
  .cms-story-facade:focus-visible .cms-story-facade__play {
    transform: translate(-50%, -50%) !important;
  }
}

/* Smaller screens: keep the control comfortably tappable without covering
   the brand overlay. */
@media (max-width: 575.98px) {
  .cms-story-facade__play {
    width: 56px;
    height: 56px;
  }

  .cms-story-facade__play svg {
    width: 22px;
    height: 22px;
  }
}
