/**
 * Fixed Preloader CSS - Mobile Slide Animations Restored
 * Ensures proper animations on all devices without conflicts
 */

/* Preloader Base Styles */
#custom-preloader {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  height: 100dvh; /* Dynamic viewport height for mobile */
  z-index: 99999;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #ffffff; /* Or your preferred background */
  
  /* Hardware acceleration */
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  will-change: transform, opacity;
  
  /* Ensure it's above everything */
  pointer-events: auto;
}

/* Body scroll blocking when preloader is active */
body.preloader-active {
  overflow: hidden !important;
  touch-action: none !important;
  -webkit-overflow-scrolling: auto !important;
  overscroll-behavior: none !important;
}

/* Prevent iOS bounce when preloader active */
body.preloader-active,
body.preloader-active * {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

/* ===================================
   EXIT ANIMATIONS - WORKING ON MOBILE
   =================================== */

/* Slide Out Animation */
@keyframes slideOut {
  from {
    transform: translateY(0) translateZ(0);
    opacity: 1;
  }
  to {
    transform: translateY(-100vh) translateZ(0);
    opacity: 0;
  }
}

@-webkit-keyframes slideOut {
  from {
    -webkit-transform: translateY(0) translateZ(0);
    opacity: 1;
  }
  to {
    -webkit-transform: translateY(-100vh) translateZ(0);
    opacity: 0;
  }
}

.slide-out {
  animation: slideOut 0.75s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
  -webkit-animation: slideOut 0.75s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

/* Fade Out Animation */
@keyframes fadeOut {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

@-webkit-keyframes fadeOut {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

.fade-out {
  animation: fadeOut 0.75s ease-out forwards;
  -webkit-animation: fadeOut 0.75s ease-out forwards;
}

/* Zoom Out Animation */
@keyframes zoomOut {
  from {
    transform: scale(1) translateZ(0);
    opacity: 1;
  }
  to {
    transform: scale(0.3) translateZ(0);
    opacity: 0;
  }
}

@-webkit-keyframes zoomOut {
  from {
    -webkit-transform: scale(1) translateZ(0);
    opacity: 1;
  }
  to {
    -webkit-transform: scale(0.3) translateZ(0);
    opacity: 0;
  }
}

.zoom-out {
  animation: zoomOut 0.75s ease-out forwards;
  -webkit-animation: zoomOut 0.75s ease-out forwards;
}

/* Bounce Out Animation */
@keyframes bounceOut {
  0% {
    transform: scale(1) translateZ(0);
    opacity: 1;
  }
  20% {
    transform: scale(0.9) translateZ(0);
  }
  50%, 55% {
    transform: scale(1.1) translateZ(0);
    opacity: 1;
  }
  100% {
    transform: scale(0) translateZ(0);
    opacity: 0;
  }
}

@-webkit-keyframes bounceOut {
  0% {
    -webkit-transform: scale(1) translateZ(0);
    opacity: 1;
  }
  20% {
    -webkit-transform: scale(0.9) translateZ(0);
  }
  50%, 55% {
    -webkit-transform: scale(1.1) translateZ(0);
    opacity: 1;
  }
  100% {
    -webkit-transform: scale(0) translateZ(0);
    opacity: 0;
  }
}

.bounce-out {
  animation: bounceOut 0.75s ease-out forwards;
  -webkit-animation: bounceOut 0.75s ease-out forwards;
}

/* Flip Out Animation */
@keyframes flipOut {
  from {
    transform: perspective(400px) rotateY(0) translateZ(0);
    opacity: 1;
  }
  to {
    transform: perspective(400px) rotateY(90deg) translateZ(0);
    opacity: 0;
  }
}

@-webkit-keyframes flipOut {
  from {
    -webkit-transform: perspective(400px) rotateY(0) translateZ(0);
    opacity: 1;
  }
  to {
    -webkit-transform: perspective(400px) rotateY(90deg) translateZ(0);
    opacity: 0;
  }
}

.flip-out {
  animation: flipOut 0.75s ease-out forwards;
  -webkit-animation: flipOut 0.75s ease-out forwards;
}

/* ===================================
   MOBILE-SPECIFIC OPTIMIZATIONS
   =================================== */

/* Mobile exit animations - ensure they work */
@media (max-width: 768px), (pointer: coarse) {
  /* Ensure animations use GPU on mobile */
  #custom-preloader {
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
  }
  
  /* Mobile-specific slide animation */
  #custom-preloader.slide-out,
  #custom-preloader.mobile-exit.slide-out {
    animation: slideOutMobile 0.75s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
    -webkit-animation: slideOutMobile 0.75s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
  }
  
  @keyframes slideOutMobile {
    0% {
      transform: translate3d(0, 0, 0);
      opacity: 1;
    }
    100% {
      transform: translate3d(0, -100%, 0);
      opacity: 0;
    }
  }
  
  @-webkit-keyframes slideOutMobile {
    0% {
      -webkit-transform: translate3d(0, 0, 0);
      opacity: 1;
    }
    100% {
      -webkit-transform: translate3d(0, -100%, 0);
      opacity: 0;
    }
  }
  
  /* Ensure other animations also work on mobile */
  #custom-preloader.fade-out {
    animation-duration: 0.75s !important;
    -webkit-animation-duration: 0.75s !important;
  }
  
  #custom-preloader.zoom-out {
    transform-origin: center center;
    -webkit-transform-origin: center center;
  }
}

/* iOS-specific fixes */
@supports (-webkit-touch-callout: none) {
  /* iOS only styles */
  #custom-preloader {
    -webkit-transform: translateZ(0);
    -webkit-perspective: 1000;
  }
  
  body.preloader-active {
    position: fixed;
    width: 100%;
  }
}

/* Ensure Lottie player works correctly */
#custom-preloader lottie-player {
  width: 100%;
  height: 100%;
  max-width: 500px; /* Adjust as needed */
  max-height: 500px; /* Adjust as needed */
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
}

/* Custom animation duration using CSS variable */
#custom-preloader[style*="--animation-duration"] {
  animation-duration: var(--animation-duration) !important;
  -webkit-animation-duration: var(--animation-duration) !important;
}

/* Ensure animations work with different timing */
.slide-out[style*="--animation-duration"],
.fade-out[style*="--animation-duration"],
.zoom-out[style*="--animation-duration"],
.bounce-out[style*="--animation-duration"],
.flip-out[style*="--animation-duration"] {
  animation-duration: var(--animation-duration) !important;
  -webkit-animation-duration: var(--animation-duration) !important;
}

/* Fallback for older browsers */
.no-cssanimations #custom-preloader.slide-out,
.no-cssanimations #custom-preloader.fade-out,
.no-cssanimations #custom-preloader.zoom-out {
  display: none !important;
}

/* Debug helper classes */
.preloader-debug #custom-preloader {
  border: 2px solid red;
}

.preloader-debug #custom-preloader.slide-out::after,
.preloader-debug #custom-preloader.fade-out::after {
  content: attr(class);
  position: absolute;
  top: 10px;
  right: 10px;
  background: red;
  color: white;
  padding: 5px 10px;
  font-size: 12px;
  z-index: 100000;
}