/*
 * Endless entertainment — clean local gallery controller
 *
 * This file intentionally does NOT re-create Apple's page layout.
 * The captured Apple CSS still owns the tile sizes, spacing, dotnav and
 * responsive breakpoints.  These rules only normalize custom media and
 * add local motion states.
 */

.section-endless-entertainment-gallery .media-gallery-item-container,
.section-endless-entertainment-gallery .media-gallery-item {
  will-change: transform;
}

#tv-media-gallery {
  touch-action: pan-y;
  cursor: grab;
}

#tv-media-gallery.is-local-dragging {
  cursor: grabbing;
}

/*
 * Critical fix for the bottom rail:
 * Apple Music cards used special square-art rules (.media-gallery-bg-music)
 * with margin-left / border-radius. Those classes are removed in index.html,
 * and these rules provide a second safety net without changing positioning.
 */
#tv-media-gallery .media-gallery-bg-wrapper,
#fam-media-gallery .media-gallery-bg-wrapper {
  width: 100% !important;
  height: 100% !important;
  display: block !important;
  overflow: hidden !important;
  background: #000 !important;
}

#tv-media-gallery .media-gallery-bg,
#fam-media-gallery .media-gallery-bg {
  display: block !important;
  width: 100% !important;
  height: 100% !important;
  margin: 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
  box-shadow: none !important;
}

#tv-media-gallery .media-gallery-bg img,
#fam-media-gallery .media-gallery-bg img,
#tv-media-gallery .custom-gallery-video {
  display: block !important;
  width: 100% !important;
  height: 100% !important;
  max-width: none !important;
  max-height: none !important;
  margin: 0 !important;
  padding: 0 !important;
  object-fit: cover !important;
  object-position: center center !important;
  border: 0 !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  backface-visibility: hidden;
}

#tv-media-gallery .custom-gallery-video {
  background: #000;
}

/* There must never be captured Apple copy/logos over custom media. */
#tv-media-gallery .media-gallery-contents,
#fam-media-gallery .media-gallery-contents,
#tv-media-gallery .media-gallery-longnote,
#fam-media-gallery .media-gallery-longnote,
#tv-media-gallery .media-gallery-logo,
#fam-media-gallery .media-gallery-logo,
#tv-media-gallery .tv-gallery-atvplus-logo,
#fam-media-gallery .tv-gallery-atvplus-logo,
#tv-media-gallery .tv-gallery-media-logo,
#fam-media-gallery .tv-gallery-media-logo {
  display: none !important;
}

/* Pause the native Apple timed-dot animation without changing its shape. */
.section-endless-entertainment-gallery.local-gallery-paused
.media-gallery-dotnav-item.current
.media-gallery-dotnav-link::after {
  animation-play-state: paused !important;
}

/* Keep Apple's existing pause/play glyphs, switch only visibility. */
.section-endless-entertainment-gallery
.media-gallery-dotnav-iconcontrol-play {
  display: none;
}

.section-endless-entertainment-gallery.local-gallery-paused
.media-gallery-dotnav-iconcontrol-pause {
  display: none !important;
}

.section-endless-entertainment-gallery.local-gallery-paused
.media-gallery-dotnav-iconcontrol-play {
  display: block !important;
}

@media (prefers-reduced-motion: reduce) {
  .section-endless-entertainment-gallery .media-gallery-item-container {
    transition-duration: 1ms !important;
  }
}


/* -------------------------------------------------------------
 * Hover-to-play local MP4 preview
 * Idle = paused MP4 first frame + centered play icon.
 * Hover = play video + show sound toggle/countdown + pause carousel.
 * ------------------------------------------------------------- */
#tv-media-gallery .media-gallery-item.custom-video-slide {
  /* Keep Apple's carousel geometry intact. Never switch this LI to relative. */
  position: absolute !important;
}

#tv-media-gallery .custom-video-slide .media-gallery-bg-wrapper {
  overflow: hidden !important;
}

#tv-media-gallery .custom-gallery-video {
  cursor: default;
}

#tv-media-gallery .custom-video-ui {
  position: absolute;
  inset: 0;
  z-index: 8;
  overflow: hidden;
  pointer-events: none;
}

/* Idle state: only the play icon is visible on top of the paused MP4 frame. */
#tv-media-gallery .custom-video-play-indicator {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 72px;
  height: 72px;
  transform: translate(-50%, -50%);
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.56);
  color: #fff;
  opacity: 1;
  transition: opacity 140ms ease, transform 140ms ease;
  pointer-events: none;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

#tv-media-gallery .custom-video-play-indicator svg {
  width: 34px;
  height: 34px;
  display: block;
  fill: currentColor;
  transform: translateX(2px);
}

#tv-media-gallery .custom-video-slide.is-video-previewing
.custom-video-play-indicator {
  opacity: 0;
  transform: translate(-50%, -50%) scale(.92);
}

/* Hover-only controls. Kept inside the media wrapper so they can never leak
   into the neighboring slide or outside the card. */
#tv-media-gallery .custom-video-sound,
#tv-media-gallery .custom-video-countdown {
  opacity: 0;
  visibility: hidden;
  transition: opacity 140ms ease, visibility 140ms ease;
}

#tv-media-gallery .custom-video-slide.is-video-previewing
.custom-video-sound,
#tv-media-gallery .custom-video-slide.is-video-previewing
.custom-video-countdown {
  opacity: 1;
  visibility: visible;
}

#tv-media-gallery .custom-video-sound {
  position: absolute;
  top: 18px;
  right: 18px;
  width: 52px;
  height: 52px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.64);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  pointer-events: auto;
  -webkit-tap-highlight-color: transparent;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

#tv-media-gallery .custom-video-sound:hover {
  background: rgba(0, 0, 0, 0.76);
}

#tv-media-gallery .custom-video-sound:focus-visible {
  outline: 3px solid #fff;
  outline-offset: -6px;
}

#tv-media-gallery .custom-video-sound svg {
  width: 28px;
  height: 28px;
  display: block;
  fill: currentColor;
}

#tv-media-gallery .custom-video-sound .icon-sound-on {
  display: none;
}

#tv-media-gallery .custom-video-sound[aria-pressed="true"] .icon-sound-off {
  display: none;
}

#tv-media-gallery .custom-video-sound[aria-pressed="true"] .icon-sound-on {
  display: block;
}

#tv-media-gallery .custom-video-countdown {
  position: absolute;
  right: 18px;
  bottom: 18px;
  min-width: 58px;
  box-sizing: border-box;
  padding: 7px 10px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.72);
  color: #fff;
  font: 600 18px/1 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
  letter-spacing: .01em;
  text-align: center;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

/* While the MP4 is hovered/playing, freeze Apple's timed progress indicator. */
.section-endless-entertainment-gallery.local-gallery-hover-paused
.media-gallery-dotnav-item.current
.media-gallery-dotnav-link::after {
  animation-play-state: paused !important;
}

@media (max-width: 734px) {
  #tv-media-gallery .custom-video-play-indicator {
    width: 58px;
    height: 58px;
  }

  #tv-media-gallery .custom-video-play-indicator svg {
    width: 28px;
    height: 28px;
  }

  #tv-media-gallery .custom-video-sound {
    top: 12px;
    right: 12px;
    width: 44px;
    height: 44px;
  }

  #tv-media-gallery .custom-video-sound svg {
    width: 24px;
    height: 24px;
  }

  #tv-media-gallery .custom-video-countdown {
    right: 12px;
    bottom: 12px;
    min-width: 52px;
    padding: 6px 8px;
    font-size: 16px;
  }
}
