/* =============================================================
   Roottx Reels Video — Frontend Styles
   ============================================================= */

/* ---- Wrapper ---- */
.rrv-wrapper {
  position: relative;
  width: 100%;
  box-sizing: border-box;
  /* Clip overflow so slides don't leak outside boxed containers */
  overflow: hidden;
}

/* Inner clip mask: allows nav arrows to sit just inside the bound */
.rrv-swiper-clip {
  overflow: hidden;
  width: 100%;
  position: relative;
}

/* ---- Swiper overrides ---- */
.rrv-swiper {
  width: 100%;
  padding: 12px 4px 20px !important;
  overflow: hidden !important;
}

/* Smooth slide transition easing */
.rrv-swiper .swiper-wrapper {
  align-items: stretch;
  transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1) !important;
}

.rrv-slide {
  height: auto !important;
  display: flex;
  align-items: stretch;
}

/* ---- Card ---- */
.rrv-card {
  position: relative;
  width: 100%;
  aspect-ratio: 9 / 16;
  border-radius: 16px;
  overflow: hidden;
  cursor: pointer;
  background: #111;
  user-select: none;
  -webkit-tap-highlight-color: transparent !important;
  -webkit-touch-callout: none;
  outline: none !important;
  transition: transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1),
              box-shadow 0.28s ease;
  will-change: transform;
}
.rrv-card:focus,
.rrv-card:active {
  outline: none !important;
}

/* Hover animation (class toggled by setting) */
.rrv-hover-anim .rrv-card:hover {
  transform: scale(1.03);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
}

/* ---- Skeleton Loader ---- */
.rrv-skeleton {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: linear-gradient(
    90deg,
    #1a1a2e 0%,
    #16213e 40%,
    #0f3460 50%,
    #16213e 60%,
    #1a1a2e 100%
  );
  background-size: 200% 100%;
  animation: rrv-shimmer 1.6s ease-in-out infinite;
  border-radius: 16px;
  transition: opacity 0.4s ease;
}
.rrv-skeleton.rrv-skeleton-hidden {
  opacity: 0;
  pointer-events: none;
}

@keyframes rrv-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ---- Thumbnail ---- */
.rrv-thumbnail {
  position: absolute;
  inset: 0;
  z-index: 2;
  background: #1a1a2e no-repeat center / cover;
  border-radius: 16px;
  transition: opacity 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}
.rrv-no-thumb {
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
}

/* Fade thumbnail out when playing */
.rrv-card.rrv-playing .rrv-thumbnail {
  opacity: 0;
  pointer-events: none;
}

/* ---- Play Icon ---- */
.rrv-play-icon {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3;
  transition: opacity 0.15s ease;
}
.rrv-play-icon svg {
  /*
   * Use card-relative sizing: .rrv-play-icon fills the card (position:absolute inset:0)
   * so width:26% = 26% of the card width. Works correctly in Elementor editor too.
   * min/max via clamp-style approach without viewport units.
   */
  width: 26%;
  max-width: 80px;
  min-width: 36px;
  height: auto;
  filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.5));
  animation: rrv-pulse 2.4s ease-in-out infinite;
}
.rrv-card.rrv-playing .rrv-play-icon {
  opacity: 0;
  pointer-events: none;
}

@keyframes rrv-pulse {
  0%, 100% { transform: scale(1);   opacity: 1;    }
  50%       { transform: scale(1.09); opacity: 0.85; }
}

/* ---- Loading Spinner ---- */
.rrv-loading-spinner {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 4;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 16px;
}
.rrv-loading-spinner.rrv-spinner-visible {
  display: flex;
}
.rrv-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(255, 255, 255, 0.25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: rrv-spin 0.7s linear infinite;
}
@keyframes rrv-spin {
  to { transform: rotate(360deg); }
}

/* ---- Video Wrap ---- */
.rrv-video-wrap {
  position: absolute;
  inset: 0;
  z-index: 5;
  border-radius: 16px;
  overflow: hidden;
  opacity: 0;
  transform: scale(0.95);
  transition: opacity 0.3s ease, transform 0.3s ease;
  pointer-events: none;
}
.rrv-card.rrv-playing .rrv-video-wrap {
  opacity: 1;
  transform: scale(1);
  pointer-events: auto;
}
.rrv-card.rrv-stopping .rrv-video-wrap {
  opacity: 0;
  transform: scale(0.97);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.rrv-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border-radius: 16px;
}

/* ---- YouTube iframe ---- */
.rrv-yt-wrap iframe {
  width: 100%;
  height: 100%;
  border: 0;
  border-radius: 16px;
  pointer-events: none; /* prevent iframe from capturing touch events */
}

/* ---- Mute Button ---- */
.rrv-mute-btn {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 8;
  width: 60px;
  height: 60px;
  background: transparent !important;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.3s ease;
  -webkit-tap-highlight-color: transparent;
  outline: none;
}
.rrv-mute-btn:active,
.rrv-mute-btn:focus {
  background: transparent !important;
  outline: none;
  box-shadow: none;
}
.rrv-card.rrv-playing .rrv-mute-btn {
  opacity: 1;
}
.rrv-mute-btn svg {
  width: 44px;
  height: 44px;
  fill: #fff;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.75));
}

/* Desktop Mute Button (~50% smaller, matching mobile scale for balance) */
@media (min-width: 1024px) {
  .rrv-mute-btn {
    width: 60px;
    height: 60px;
    top: 16px;
    right: 16px;
  }
  .rrv-mute-btn svg {
    width: 44px;
    height: 44px;
  }
}

/* ---- Title ---- */
.rrv-title {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 6;
  padding: 32px 14px 14px;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-weight: 600;
  line-height: 1.3;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.7);
  background: linear-gradient(to top, rgba(0,0,0,0.75) 0%, transparent 100%);
  border-radius: 0 0 16px 16px;
  pointer-events: none;
}

/* ---- Error state ---- */
.rrv-error {
  color: #ef4444;
  padding: 12px 16px;
  background: #fee2e2;
  border-radius: 8px;
  font-family: sans-serif;
  font-size: 14px;
}

/* ---- Navigation arrows ---- */
.rrv-btn-prev,
.rrv-btn-next {
  color: #fff !important;
  background: rgba(0, 0, 0, 0.5) !important;
  backdrop-filter: blur(8px);
  width: 40px !important;
  height: 40px !important;
  border-radius: 50% !important;
  border: 1.5px solid rgba(255, 255, 255, 0.2) !important;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3) !important;
  transition: background 0.2s ease, transform 0.2s ease !important;
}
.rrv-btn-prev:hover,
.rrv-btn-next:hover {
  background: rgba(108, 99, 255, 0.75) !important;
  transform: scale(1.1) !important;
}
.rrv-btn-prev::after,
.rrv-btn-next::after {
  font-size: 14px !important;
  font-weight: 700 !important;
}

/* ---- Responsive adjustments ---- */
@media (max-width: 480px) {
  .rrv-card { border-radius: 12px; }
  .rrv-thumbnail,
  .rrv-video-wrap,
  .rrv-yt-wrap iframe,
  .rrv-video { border-radius: 12px; }
  .rrv-title { padding: 24px 10px 10px; }
}

/*
 * ---- Pre-initialization Fallback & Elementor Editor Fix ----
 *
 * When Swiper has NOT yet initialized (no .swiper-initialized class),
 * display slides as a responsive CSS grid. This fixes two things:
 *   1. Elementor editor preview — Swiper may not run there, so slides
 *      would stack or show as one huge card without this.
 *   2. Slow connections — gives a proper layout before JS loads.
 *
 * CSS custom properties (--rrv-cols-desktop, --rrv-gap) are set on
 * .rrv-wrapper via the inline style attribute by the shortcode PHP.
 */
.rrv-swiper:not(.swiper-initialized) {
  overflow: visible !important;
  padding: 0 !important;
}
.rrv-swiper:not(.swiper-initialized) .swiper-wrapper {
  display: grid !important;
  /* Use CSS var from wrapper (inherited) — desktop columns by default */
  grid-template-columns: repeat(var(--rrv-cols-desktop, 4), 1fr) !important;
  gap: var(--rrv-gap, 16px) !important;
  transform: none !important;
  transition: none !important;
  width: 100% !important;
  flex-wrap: wrap !important;
}
.rrv-swiper:not(.swiper-initialized) .swiper-slide {
  width: 100% !important;
  margin-right: 0 !important;
}
/* Tablet: ≤ 1024px */
@media (max-width: 1024px) {
  .rrv-swiper:not(.swiper-initialized) .swiper-wrapper {
    grid-template-columns: repeat(var(--rrv-cols-tablet, 2), 1fr) !important;
  }
}
/* Mobile: ≤ 767px */
@media (max-width: 767px) {
  .rrv-swiper:not(.swiper-initialized) .swiper-wrapper {
    grid-template-columns: repeat(var(--rrv-cols-mobile, 1), 1fr) !important;
  }
}

/*
 * ---- Elementor Editor Compatibility ----
 * Extra overrides specifically for .elementor-editor-active on body.
 */
.elementor-editor-active .rrv-card {
  aspect-ratio: 9 / 16;
}
.elementor-editor-active .rrv-play-icon svg {
  width: 26%;
  max-width: 80px;
  min-width: 36px;
  animation: none;
}
.elementor-editor-active .rrv-skeleton {
  animation: none;
}
/* In Elementor editor, also apply grid layout regardless of swiper state */
.elementor-editor-active .rrv-swiper .swiper-wrapper {
  display: grid !important;
  grid-template-columns: repeat(var(--rrv-cols-desktop, 4), 1fr) !important;
  gap: var(--rrv-gap, 16px) !important;
  transform: none !important;
  transition: none !important;
  width: 100% !important;
}
.elementor-editor-active .rrv-swiper .swiper-slide {
  width: 100% !important;
  margin-right: 0 !important;
}
@media (max-width: 1024px) {
  .elementor-editor-active .rrv-swiper .swiper-wrapper {
    grid-template-columns: repeat(var(--rrv-cols-tablet, 2), 1fr) !important;
  }
}
@media (max-width: 767px) {
  .elementor-editor-active .rrv-swiper .swiper-wrapper {
    grid-template-columns: repeat(var(--rrv-cols-mobile, 1), 1fr) !important;
  }
}
/* Hide nav arrows in editor — they don't function there */
.elementor-editor-active .rrv-btn-prev,
.elementor-editor-active .rrv-btn-next {
  display: none !important;
}

/* =============================================================
   Desktop Popup Modal (Reels)
   ============================================================= */
.rrv-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 999999;
  background: rgba(0, 0, 0, 0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  backdrop-filter: blur(8px);
}
.rrv-modal-overlay.rrv-modal-active {
  opacity: 1;
  visibility: visible;
}

.rrv-body-no-scroll {
  overflow: hidden !important;
}

.rrv-modal-container {
  position: relative;
  height: 85vh;
  aspect-ratio: 9/16;
  background: #000;
  border-radius: 16px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
  overflow: hidden;
}

/* Close Button */
.rrv-modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255,255,255,0.1);
  color: #fff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 9999999;
  transition: background 0.2s;
  padding: 0;
}
.rrv-modal-close:hover {
  background: rgba(255,255,255,0.25);
}
.rrv-modal-close svg {
  width: 20px;
  height: 20px;
  fill: #fff;
}

/* Navigation Buttons */
.rrv-modal-nav {
  position: absolute;
  right: 24px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 16px;
  z-index: 9999999;
  /* Adjust right offset for desktop space if viewing on wide screen */
}

/* Fallback for responsive modal right position - handled in JS actually better, but just in case */
@media (min-width: 1024px) {
  .rrv-modal-nav {
    right: calc(50% - (85vh * 9 / 16 / 2) - 80px);
  }
  .rrv-modal-close {
    right: calc(50% - (85vh * 9 / 16 / 2) - 80px);
    top: calc(50% - 42.5vh);
  }
}

.rrv-modal-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  padding: 0;
}
.rrv-modal-btn:hover {
  background: rgba(255,255,255,0.3);
  transform: scale(1.1);
}
.rrv-modal-btn svg {
  width: 24px;
  height: 24px;
  fill: #fff;
}

/* Slides container */
.rrv-modal-track {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.rrv-modal-slide {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: #000;
  visibility: hidden;
  z-index: 1;
}
.rrv-modal-slide.rrv-slide-active {
  visibility: visible;
  z-index: 2;
  transform: translateY(0);
}

/* Transitions */
.rrv-modal-slide.rrv-animate-up-out {
  visibility: visible;
  transform: translateY(-100%);
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 3;
}
.rrv-modal-slide.rrv-animate-up-in {
  visibility: visible;
  z-index: 2;
  animation: rrv-slide-up-in 0.4s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.rrv-modal-slide.rrv-animate-down-out {
  visibility: visible;
  transform: translateY(100%);
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 3;
}
.rrv-modal-slide.rrv-animate-down-in {
  visibility: visible;
  z-index: 2;
  animation: rrv-slide-down-in 0.4s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes rrv-slide-up-in {
  0% { transform: translateY(100%); }
  100% { transform: translateY(0); }
}
@keyframes rrv-slide-down-in {
  0% { transform: translateY(-100%); }
  100% { transform: translateY(0); }
}

/* Override card styles inside modal */
.rrv-modal-slide .rrv-card {
  width: 100%;
  height: 100%;
  border-radius: 0;
  cursor: default; /* No pointer cursor on the whole card inside modal */
  transform: none !important;
  box-shadow: none !important;
}
.rrv-modal-slide .rrv-title {
  border-radius: 0;
  padding-bottom: 24px;
}
.rrv-modal-slide .rrv-mute-btn {
  /* Hide standard mute btn if we want to custom position or just let it be */
  cursor: pointer;
}
