/* ===================================
   MEETGLE VIDEO CHAT - OPTIMIZED CSS
   =================================== */

/* === CSS VARIABLES === */
:root {
    --accent-color: #cc0000;
    /* Button colors now come from theme files */
    --button-color: var(--theme-button-primary, #EC4899);
    --button-hover-color: var(--theme-button-primary-hover, #A855F7);
    --button-active-color: var(--theme-button-primary-active, #EC4899);
    --button-padding: 10px 15px;
    --button-font-size: 16px;
    --transition-duration: 0.3s;
    --text-color: #333;
    --bg-dark: #23272A;
    --bg-darker: #171717;
  }

/* ===================================
   DYNAMIC BUTTON HOVER/ACTIVE STATES
   These styles use CSS variables that can be customized via WordPress settings
   =================================== */

/* Start Chat Button Hover/Active States */
#startChatBtn:hover {
  background: var(--button-hover-color) !important;
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0,0,0,0.2);
}

#startChatBtn:active {
  background: var(--button-active-color) !important;
  transform: translateY(0);
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}


/* Match Preferences Button Hover/Active States (same as help button) */
#matchPreferencesBtn:hover {
  background: rgba(255,255,255,0.2) !important;
  transform: scale(1.05);
  border-color: rgba(255,255,255,0.5);
}

#matchPreferencesBtn:active {
  background: rgba(255,255,255,0.15) !important;
  transform: scale(0.98);
}

/* === GLOBAL RESET === */
html,
body {
  margin: 0;
  padding: 0;
  box-sizing: border-box;

  /* Avoid 100vw / 100vh issues on iOS */
  width: 100%;
  height: 100%;
  min-height: 0;

  overflow-x: hidden;
  overflow-y: auto; /* default for desktop */
}

/* === SHARED MENU STYLES (settings + avatar dropdown) === */
.avatar-menu-item {
  padding: 10px 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  color: #333;
  font-size: 14px;
  line-height: 1;
  transition: background 0.15s;
}
.avatar-menu-item:hover {
  background: #f5f5f5;
}
.avatar-menu-divider {
  height: 1px;
  background: #e5e5e5;
  margin: 4px 0;
}

/* ===================================
   RESPONSIVE: MOBILE (≤900px)
   =================================== */
@media (max-width: 900px) {
  /* On mobile, lock the page to the viewport (no scroll) */
  html,
  body {
    overflow: hidden;       /* kill the scroll */
  }
}

/* === MAIN CONTAINER === */
#meetgle-container,
#meetgle-video-container {
  width: 100vw;
  min-height: 100vh;
  min-width: 100vw;
  max-width: 100vw;
  overflow: visible;
  display: flex;
  flex-direction: row;
  box-sizing: border-box;
  text-align: center;
  background-color: transparent;
}

/* === VIDEO LAYOUT === */
.video-chat-layout {
  display: flex;
  flex-direction: row;
  width: 100%;
  height: 100%;
}

.video-section {
  flex: 0 1 50%;
  min-width: 0;
  max-width: 50vw;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: stretch;
  height: 100%;
}

.controls-and-chat {
  flex: 0 1 50%;
  min-width: 320px;
  max-width: 50vw;
  display: flex;
  flex-direction: column;
  height: 100%;
  box-sizing: border-box;
  background-color: var(--bg-dark);
}

/* === VIDEO WRAPPERS === */
.video-wrapper {
  position: relative;
  background-color: #000;
  overflow: hidden;
  aspect-ratio: 16 / 9;
  border-radius: 0;
}

.video-wrapper.remote-video {
  flex: 1 1 0;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 0;
  margin-bottom: 0;
  background: #0b0b0e;
}

/* === ANONYMOUS IN-STREAM AD OVERLAY START === */
.anon-instream-ad {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: none;
  background: #000;
}

.anon-instream-ad.is-visible {
  display: block;
}

.anon-instream-ad video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  opacity: 1 !important;
  transition: none !important;
}

.anon-instream-ad__video {
  position: absolute;
  inset: 0;
  z-index: 1 !important;
}

.anon-instream-ad__overlay {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  padding: 18px 14px 32px;
  background: linear-gradient(to top, rgba(120, 0, 10, 0.86), rgba(0, 0, 0, 0.3) 55%, transparent);
  text-align: center;
  pointer-events: auto;
}

.anon-instream-ad__label {
  display: inline-block;
  margin-bottom: 8px;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(0,0,0,0.45);
  border: 1px solid rgba(255,255,255,0.2);
  color: rgba(255,255,255,0.9);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.anon-instream-ad__message {
  margin: 0 0 10px;
  color: #fff;
  font-size: 26px;
  font-style: italic;
  line-height: 1.25;
  text-shadow: 0 2px 5px rgba(0,0,0,0.45);
}

.anon-instream-ad__cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 210px;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  background: linear-gradient(135deg, #ff3b44, #ff5c58);
  color: #fff;
  font-size: 16px;
  font-weight: 800;
  line-height: 1;
  text-decoration: none;
  box-shadow: 0 8px 16px rgba(0,0,0,0.25);
}
/* === ANONYMOUS IN-STREAM AD OVERLAY END === */

@media (max-width: 768px) {
  .anon-instream-ad__overlay {
    padding-bottom: 28px;
  }

  .anon-instream-ad__message {
    font-size: 20px;
  }

  .anon-instream-ad__cta {
    min-width: 180px;
    font-size: 15px;
    padding: 9px 14px;
  }
}

.video-wrapper.local-video {
  flex: 2 1 0;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 66.66%;
  min-height: 0;
  background-color: #0F0F0F;
  position: relative;
  overflow: hidden;
}

/* === BRANDED BACKGROUND FOR LOCAL VIDEO START === */
.video-wrapper.local-video::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #0F0F0F;
  z-index: 0;
}

/* Logo removed - now showing live counter instead */
.video-wrapper.local-video::after {
  display: none; /* Hide logo */
}
/* === BRANDED BACKGROUND FOR LOCAL VIDEO END === */

/* === SWIRL BACKGROUND CANVAS === */
#bg-swirl {
  pointer-events: none;
  z-index: 1;
  transition: opacity 0.5s ease-out;
}

/* Hide swirl and logo when chatting/searching */
.remote-video.has-video #bg-swirl,
.remote-video.has-video #remoteLogo {
  opacity: 0 !important;
}

#remoteLogo {
  opacity: 0.8;
  transition: opacity 0.5s ease-out;
}
/* === END SWIRL BACKGROUND === */

/* === LIVE COUNTER BACKGROUND FOR LOCAL VIDEO (WAITING STATE) === */
/* Shows scrolling profile gallery with online count overlay */
.local-video .live-counter-background {
  position: absolute;
  top: -1px;
  left: -1px;
  right: -1px;
  bottom: -1px;
  background: #0b0b0e;
  z-index: 2;
  opacity: 1;
  transition: opacity 0.5s ease-out;
  pointer-events: none;
  overflow: hidden;
}

#profile-showcase {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

#profile-showcase::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.4);
  z-index: 2;
  pointer-events: none;
}

/* Hide gallery when chat starts */
.local-video.has-stream .live-counter-background {
  opacity: 0;
  pointer-events: none;
}

/* === VIDEO ELEMENTS === */
.remote-video video,
.local-video video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 10; /* Above background layers */
}

/* === SMOOTH LOADING FOR REMOTE VIDEO ON MOBILE NETWORKS === */
/* Keep video invisible until ready, then do a quick fade-in */
/* This prevents users from seeing the WebRTC internal resize on slower connections */
.remote-video video {
  opacity: 0;
  transition: opacity 0.3s ease-in;
}

/* Add class via JavaScript when video is ready and properly sized */
.remote-video video.video-ready {
  opacity: 1;
}

/* Add a loading overlay that stays visible until video is ready */
.remote-video::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #0b0b0e;
  z-index: 15; /* Above video (z-index: 10) but below spinner (z-index: 20) */
  opacity: 0; /* ✅ FIX: Start hidden, only show when video is loading */
  transition: opacity 0.4s ease-out;
  pointer-events: none;
}

/* Show overlay when video is loading (has-video class added but video not ready yet) */
.remote-video.has-video:not(.video-loaded)::after {
  opacity: 1;
}

/* Hide the overlay when video is ready */
.remote-video.video-loaded::after {
  opacity: 0;
}

/* === BLUR EFFECT FOR PREVIEW === */
.remote-video.blurred video {
  filter: blur(20px);
  transition: filter 0.5s ease-out;
}

.local-video video {
  transform: none;
  background: transparent !important; /* Changed from #2a2a2a to transparent */
}

/* Hide native video controls */
video::-webkit-media-controls,
video::-moz-media-controls,
video::-ms-media-controls,
video::-o-media-controls {
  display: none !important;
}

/* === LOADING SPINNER === */
.remote-loading-spinner {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}

.spinner {
  border: 6px solid #f3f3f3;
  border-top: 6px solid var(--button-color);
  border-radius: 50%;
  width: 48px;
  height: 48px;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* === CONTROL BUTTONS === */
.control-container {
  display: none; /* Hidden by default, shown when chatting */
  justify-content: space-between;
  gap: 5px;
  flex-wrap: wrap;
  margin: 10px;
}

.control-container button {
  flex: 1;
  padding: 10px;
  font-size: 14px;
  background-color: var(--button-color);
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color var(--transition-duration) ease;
  text-align: center;
}

.control-container button:hover,
.control-container button:focus {
  background-color: var(--button-hover-color);
}

.control-container button:active {
  background-color: var(--button-active-color);
}

/* Old stopChatBtn rule removed - now using .btn-stop class */

/* === MUTE & CAMERA BUTTONS === */
#muteBtn,
#switchCameraBtn {
  font-size: 14px;
  color: #000;
  background-color: rgba(255, 255, 255, 0.7);
  border: none;
  padding: 3px 6px;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color var(--transition-duration) ease;
}

#muteBtn:hover,
#switchCameraBtn:hover {
  background-color: rgba(200, 200, 200, 0.9);
}

#muteBtn.muted {
  background-color: #6c757d;
  color: #fff;
}

/* Heart & Spark buttons removed - now using .btn-heart and .btn-spark classes */

/* === FLAG & GENDER BUTTONS === */
#remoteFlag,
#remoteGender {
  font-size: 18px;
  border-radius: 4px;
  border: none;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.3s, box-shadow 0.2s;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.07);
  padding: 0;
  margin: 0;
  cursor: default;
  background: rgba(255, 255, 255, 0.7);
}

#remoteFlag:hover,
#remoteGender:hover {
  background: rgba(200, 200, 200, 0.9);
}

#remoteFlag:active,
#remoteGender:active {
  background: #f3f3f3;
}

/* Flag emoji styling */
#remoteFlag {
  color: #222;
  cursor: default;
  text-align: center;
  line-height: 36px;
  font-family: 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji', sans-serif;
  font-size: 22px;
  overflow: hidden;
  vertical-align: middle;
}

/* Gender SVG icon styling - separate from flag for precise centering */
#remoteGender {
  cursor: default;
  overflow: hidden;
  padding: 0;
  line-height: 0; /* Remove any line-height that might offset the image */
}

/* Center SVG images inside gender container */
#remoteGender img {
  display: block;
  width: 20px;
  height: 20px;
  object-fit: contain;
  margin: auto; /* Ensure centering with flexbox parent */
}

/* === HEART ANIMATIONS === */
.heart-anim-overlay {
  pointer-events: none;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 100;
  overflow: visible;
}

.heart-emoji {
  position: absolute;
  left: 50%;
  font-size: 2.5rem;
  opacity: 0.85;
  transform: translateX(-50%) scale(1);
  animation: heart-float 1.2s cubic-bezier(0.4, 0, 0.2, 1) forwards;
  pointer-events: none;
}

@keyframes heart-float {
  0% {
    top: 10%;
    opacity: 0.9;
    transform: translateX(-50%) scale(1.2);
  }
  60% {
    opacity: 1;
    transform: translateX(-50%) scale(1.1) rotate(-10deg);
  }
  80% {
    opacity: 0.8;
    transform: translateX(-50%) scale(1.05) rotate(10deg);
  }
  100% {
    top: 80%;
    opacity: 0;
    transform: translateX(-50%) scale(0.8) rotate(0deg);
  }
}

.heart-btn-anim-overlay {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
  z-index: 200;
}

.heart-btn-emoji {
  position: absolute;
  left: 50%;
  bottom: 8px;
  font-size: 1.7em;
  opacity: 0.9;
  transform: translateX(-50%) scale(1);
  animation: heart-btn-flutter 0.9s cubic-bezier(0.4, 0, 0.2, 1) forwards;
  pointer-events: none;
}

@keyframes heart-btn-flutter {
  0% {
    bottom: 8px;
    opacity: 0.9;
    transform: translateX(-50%) scale(1.2);
  }
  60% {
    opacity: 1;
    transform: translateX(-50%) scale(1.1) rotate(-10deg);
  }
  80% {
    opacity: 0.8;
    transform: translateX(-50%) scale(1.05) rotate(10deg);
  }
  100% {
    bottom: 38px;
    opacity: 0;
    transform: translateX(-50%) scale(0.8) rotate(0deg);
  }
}

/* ===================================
   RESPONSIVE: DESKTOP (900px+)
   =================================== */
@media (min-width: 901px) {
  #meetgle-video-container,
  .video-chat-layout {
    height: 100vh;
    min-height: 100vh;
    max-height: 100vh;
  }
}

/* ===================================
   RESPONSIVE: MOBILE (≤900px)
   =================================== */
@media (max-width: 900px) {
  .video-chat-layout {
    flex-direction: column;
    height: 100vh !important;
    min-height: 100vh !important;
    max-height: 100vh !important;
  }

  .video-section,
  .controls-and-chat {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100vw !important;
    flex: unset !important;
    padding: 0 !important;
  }

  /* === EQUAL HEIGHT VIDEO WRAPPERS ON MOBILE (FALLBACK USING VH) === */
  .video-section {
    height: 50vh !important;
    min-height: 50vh !important;
    max-height: 50vh !important;
    margin: 0 !important;
    padding: 0 !important;
    display: block !important;
  }

  .controls-and-chat {
    height: 50vh !important;
    min-height: 50vh !important;
    max-height: 50vh !important;
    display: block !important;
  }

  .video-wrapper.remote-video,
  .video-wrapper.local-video {
    height: 50vh !important;
    min-height: 0 !important;
    max-height: 50vh !important;
    aspect-ratio: unset !important;
    flex: unset !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  /* === MODERN FIX FOR iOS / MOBILE BROWSERS USING SVH === */
  @supports (height: 100svh) {
    .video-chat-layout {
      height: 100svh !important;
      min-height: 100svh !important;
      max-height: 100svh !important;
    }

    .video-section,
    .controls-and-chat {
      height: 50svh !important;
      min-height: 50svh !important;
      max-height: 50svh !important;
    }

    .video-wrapper.remote-video,
    .video-wrapper.local-video {
      height: 50svh !important;
      min-height: 0 !important;
      max-height: 50svh !important;
    }
  }

  /* Only hide remote video background, keep local video gradient */
  .video-wrapper.remote-video::before {
    display: none !important;
  }

  .remote-video video,
  .local-video video {
    width: 100% !important;
    height: 100% !important;
    min-height: 0 !important;
    max-height: 100% !important;
  }

  /* Gender picker: fullscreen on mobile */
  #genderPickerContainer {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    transform: none !important;
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100vh !important;
    height: 100svh !important;
    border-radius: 0 !important;
    z-index: 999999 !important;
    justify-content: center !important;
    padding: 24px !important;
    box-sizing: border-box !important;
    background: rgba(20,20,30,0.95) !important;
    backdrop-filter: blur(20px) !important;
  }

  /* Show close button on mobile */
  #genderPickerClose {
    display: flex !important;
  }

  /* Account required modal: fullscreen on mobile */
  #accountRequiredModal {
    padding: 0 !important;
  }
  #accountRequiredModal > div {
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100vh !important;
    height: 100svh !important;
    max-height: 100vh !important;
    max-height: 100svh !important;
    border-radius: 0 !important;
    justify-content: center;
    display: flex !important;
    flex-direction: column !important;
  }

  /* VPN detection modal: fullscreen on mobile */
  #vpnDetectionModal {
    padding: 0 !important;
  }
  #vpnDetectionModal > div {
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100vh !important;
    height: 100svh !important;
    max-height: 100vh !important;
    max-height: 100svh !important;
    border-radius: 0 !important;
    justify-content: center;
    display: flex !important;
    flex-direction: column !important;
  }

  /* Spark cap modal: fullscreen on mobile */
  #sparkCapModal {
    padding: 0 !important;
  }
  #sparkCapModal > div {
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100vh !important;
    height: 100svh !important;
    max-height: 100vh !important;
    max-height: 100svh !important;
    border-radius: 0 !important;
    justify-content: center;
    display: flex !important;
    flex-direction: column !important;
  }
}

/* Removed old #heartBtn and #sparkBtn mobile styles - now using .btn-heart and .btn-spark classes */

#remoteFlag,
#remoteGender {
  font-size: 14px;
  width: 28px;
  height: 28px;
}

#remoteFlag {
  font-size: 16px;
  line-height: 28px;
}

/* Gender icon mobile - remove line-height override */
#remoteGender {
  line-height: 0;
}

/* Extra button bar styling */
.meetgle-extra-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 8px 16px;
  background: rgba(255,255,255,0.08);
  color: #fff;
  font-family: 'Nunito', -apple-system, BlinkMacSystemFont, sans-serif;
  font-weight: 700;
  font-size: 16px;
  text-decoration: none;
  cursor: pointer;
  border: none;
  line-height: 1;
  box-sizing: border-box;
  transition: filter 0.2s ease;
  border-radius: 10px 10px 0 0;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.meetgle-extra-btn:hover {
  filter: brightness(1.15);
  color: #fff;
  text-decoration: none;
}
.extra-btn-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.extra-btn-avatars {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}
.extra-btn-ava {
  display: block;
  width: 24px;
  height: 24px;
  min-width: 24px;
  min-height: 24px;
  border-radius: 50% !important;
  -webkit-border-radius: 50% !important;
  object-fit: cover;
  position: relative;
}
.extra-btn-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.extra-btn-cta {
  white-space: nowrap;
  color: #000;
  font-weight: 700;
  font-size: 12px;
  flex-shrink: 0;
  margin-left: 12px;
  background: var(--extra-btn-accent, #ff6b00);
  padding: 6px 12px;
  border-radius: 50px;
}

/* Next button font size on mobile */
#nextChatBtn {
  font-size: 14px !important;
}


/* ===================================
   RESPONSIVE: SMALL MOBILE (≤600px)
   =================================== */
@media (max-width: 600px) {
  .control-container {
    margin: 5px;
  }
}
