/*
 * Homepage slider: video slides.
 *
 * Complements index.css. index.css has drifted from index.scss and is no longer
 * rebuilt from it, so these rules live in their own file instead of the SCSS.
 *
 * Markup:    resources/views/components/homepage/slider.blade.php
 * Behaviour: public/assets/js/slider-video.js
 *
 * Layouts:
 *   - horizontal video     full-bleed (object-fit: cover) behind the text, all screens
 *   - vertical video only  >= 851px: "card" (blurred image backdrop + 9:16 video on the right)
 *                          <= 850px: full-bleed like the horizontal one
 *   - both videos          horizontal above 550px, vertical (full-bleed) at 550px and below
 * Slides without video keep their original markup and are not affected.
 */

/* ---------- Base: full-bleed video behind the text ---------- */

.slider__item--video {
  position: relative;
  overflow: hidden;
}

.slider__item--video .slider__cart {
  z-index: 2;
}

/* No z-index here on purpose: .slider__media must not create a stacking context,
   so its children (video 0, overlay 1, controls 3) compete with .slider__cart (2). */
.slider__media {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
}

/* Same darkening the image slides get from their inline gradient. It only fades in
   together with the video, otherwise the fallback image would be darkened twice. */
.slider__media::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 1;
  background: rgba(27, 32, 42, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.6s ease;
}

.slider__media.is-ready::after {
  opacity: 1;
}

.slider__video {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.6s ease;
}

.slider__media.is-ready .slider__video {
  opacity: 1;
}

/* The video failed or stalled: fall back to the slide image. */
.slider__media.is-failed::after {
  display: none;
}

.slider__media.is-failed .slider__video,
.slider__media.is-failed .slider__controls {
  display: none;
}

/* Which video is shown: horizontal wins, vertical only takes over on small phones. */
.slider__item--has-horizontal .slider__video--vertical {
  display: none;
}

@media (max-width: 550px) {
  .slider__item--has-horizontal.slider__item--has-vertical .slider__video--horizontal {
    display: none;
  }

  .slider__item--has-horizontal.slider__item--has-vertical .slider__video--vertical {
    display: block;
  }
}

/* ---------- Controls (play / pause, sound) ---------- */

/* Bottom-right, level with the slider dots (their centre sits ~42px above the slide
   bottom); the right edge follows the container of the text (60px / 1320px max).
   At 850px and below they move to the top-right corner, see the rule further down. */
.slider__controls {
  position: absolute;
  z-index: 3;
  right: 60px;
  right: max(60px, calc((100% - 1320px) / 2));
  bottom: 22px;
  display: flex;
}

.slider__control {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 2px solid rgba(255, 255, 255, 0.6);
  border-radius: 50%;
  background: rgba(27, 32, 42, 0.35);
  color: #fff;
  font-size: 14px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.slider__control + .slider__control {
  margin-left: 10px;
}

.slider__control:hover {
  border-color: #fff;
  background: rgba(27, 32, 42, 0.7);
}

/* index.css resets button { outline: none }, keep keyboard focus visible. */
.slider__control:focus-visible {
  border-color: #fff;
  background: rgba(27, 32, 42, 0.7);
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.slider__control i {
  pointer-events: none;
}

/* The dots row grows with the number of slides (11 dots are ~380px wide, and it wraps
   below 380px), so on narrow screens the bottom-right corner is not free: top-right. */
@media (max-width: 850px) {
  .slider__controls {
    top: 12px;
    right: 12px;
    bottom: auto;
  }
}

@media (max-width: 650px) {
  .slider__control {
    width: 34px;
    height: 34px;
    font-size: 12px;
  }
}

/* ---------- Vertical video only: blurred backdrop + 9:16 card ---------- */

.slider__backdrop {
  position: absolute;
  /* bleed: the slide clips it, so the blurred edges never show */
  top: -40px;
  right: -40px;
  bottom: -40px;
  left: -40px;
  z-index: 0;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  filter: blur(28px);
}

.slider__backdrop::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: rgba(27, 32, 42, 0.55);
}

@media (max-width: 850px) {
  .slider__backdrop {
    display: none;
  }
}

@media (min-width: 851px) {
  /* text on the left, card on the right */
  .slider__item--vertical-only .container {
    position: relative;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 40px;
    height: 100%;
  }

  /* back in the flow (index.css centres it absolutely); the left margin and the
     padding from index.css stay, so the text lines up with the other slides */
  .slider__item--vertical-only .slider__cart {
    position: relative;
    top: auto;
    flex: 1 1 auto;
    min-width: 0;
    margin-right: 0;
    transform: none;
    -webkit-transform: none;
    -moz-transform: none;
    -o-transform: none;
    -ms-transform: none;
  }

  /* The card is 9:16 and 80px shorter than the slide. Its right margin keeps it clear
     of the "next" arrow, which ends 90px (> 1440px), 80px (<= 1440px) or 70px (<= 1150px,
     40px wide) from the right edge of the slide; the container adds more above 1320px. */
  .slider__item--vertical-only .slider__media {
    position: relative;
    top: auto;
    right: auto;
    bottom: auto;
    left: auto;
    flex: 0 0 auto;
    height: calc(100% - 80px);
    aspect-ratio: 9 / 16;
    margin-right: 40px;
    overflow: hidden;
    border-radius: 16px;
    background: #1b202a;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
    isolation: isolate;
  }

  /* shown uncropped, whatever the real aspect ratio of the uploaded file is */
  .slider__item--vertical-only .slider__video {
    object-fit: contain;
  }

  /* the card is not darkened */
  .slider__item--vertical-only .slider__media::after {
    display: none;
  }

  .slider__item--vertical-only .slider__controls {
    right: 12px;
    bottom: 12px;
  }

  /* The video failed: show the plain slide image instead of an empty card. */
  .slider__item--vertical-only .slider__media.is-failed {
    display: none;
  }

  .slider__item--vertical-only:has(.slider__media.is-failed) .slider__backdrop {
    display: none;
  }
}

@media (min-width: 851px) and (max-width: 1440px) {
  .slider__item--vertical-only .slider__media {
    margin-right: 100px;
  }
}

@media (min-width: 851px) and (max-width: 1150px) {
  .slider__item--vertical-only .slider__media {
    margin-right: 80px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .slider__video,
  .slider__media::after,
  .slider__control {
    transition: none;
  }
}
