/* Content Aware Studies - Latent Space Viewer Styles */

.cas-latent-viewer {
  margin: 0;
  font-family: 'AllianceNo2-Medium', sans-serif;
  background: #000;
  overflow: hidden;
  width: 100%;
  height: 80vh; /* Reduced from 100vh to allow multiple instances */
  position: relative;
  /* Each viewer is contained within its wrapper */
  max-height: 80vh;
}

.cas-latent-viewer * {
  font-family: 'AllianceNo2-Medium', sans-serif;
}

.cas-latent-container {
  position: relative;
  width: 100%;
  height: 80vh; /* Match the height of the viewer */
  overflow: hidden;
}

/* Add wrapper styles for multiple instances */
.cas-latent-wrapper {
  width: 100%;
  position: relative;
  overflow: hidden;
  /* Add spacing between multiple instances */
  margin-bottom: 3rem;
  margin-top: 3rem;
  /* Set a specific height constraint */
  height: 80vh;
  min-height: 400px;
  max-height: 800px;
}

.cas-latent-video-container {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
 /* Explicit z-index */;
}

.cas-latent-video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  will-change: transform;
  transform: translateZ(0);
  /* Force GPU acceleration */
  backface-visibility: hidden;
 /* Prevent flicker */
  -webkit-transform: translateZ(0);
  /* iOS/Safari support */
  -webkit-backface-visibility: hidden;
 /* iOS/Safari support */;
}

.cas-latent-interaction-layer {
  position: absolute;
  inset: 0;
  cursor: move;
  touch-action: none;
  width: 100%;
  height: 100%;
  z-index: 10;
}

.cas-latent-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 60px;
  background: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
  z-index: 1001;
  color: white;
}

.cas-latent-header h1 {
  font-size: 1.5em;
  font-weight: normal;
}

.cas-latent-help-button {
  width: 32px;
  height: 32px;
  border: 1px solid white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  background: transparent;
  color: white;
  font-size: 1.2em;
}

.cas-latent-progress-container {
  position: absolute;
  top: 80px;
  left: 0;
  width: 100%;
  height: 4px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
  z-index: 1000;
  transition: opacity 0.3s;
}

/* Ensure elements with instance IDs are properly scoped */
[data-instance-id] {
  /* Ensure proper scoping for elements with instance IDs */
  position: relative;
}

.cas-latent-progress-bar {
  width: 0%;
  height: 100%;
  background: #fff;
  border-radius: 2px;
  transition: width 0.3s ease;
}

.cas-latent-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
 /* iOS/Safari support */
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  color: white;
  z-index: 1000;
 /* Higher z-index */
  width: 100%;
  height: 100%;
  /* Ensure overlay is contained within its parent */
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}

.cas-latent-instruction {
  display: none;
  width: 30vw;
  margin: 0 auto;
}

.cas-latent-instruction-text {
  margin-bottom: 20px;
  font-size: 1.1em;
  line-height: 1.4rem;
  letter-spacing: 0.07rem;
  hyphens: auto;
}

.cas-latent-instruction-subtext {
  margin-bottom: 20px;
  font-size: 1.1em;
  letter-spacing: 0.07rem;
  line-height: 1.4;
}

.cas-latent-hotkey {
  display: inline-block;
  padding: 0.1em 0.4em;
  margin: 0 0.2em;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 4px;
  font-family: monospace;
}

.cas-latent-start-button {
  width: 100%;
  background: white;
  color: black;
  border: 1px solid white;
  padding: 0.5em 1em;
  font-family: 'AllianceNo2-Medium', sans-serif;
  font-size: 1em;
  text-align: right;
  letter-spacing: 0.07rem;
  cursor: pointer;
  border-radius: 4px;
  margin-top: 10px;
}

.cas-latent-start-button:hover {
  background-color: black;
  color: white;
  border: 1px solid white;
}

.cas-latent-idle-video {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 0.5s;
}

/* .cas-latent-loading-text {
  font-size: 1.1em;
}

.cas-latent-loading-dots:after {
  content: '.';
  animation: cas-latent-dots 1.5s steps(5, end) infinite;
} */

/* Loading progress styles */
.cas-latent-loading-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 80%;
  max-width: 300px;
}

.cas-latent-loading-bar-wrapper {
  width: 100%;
  background: rgba(255, 255, 255, 0.1);
  height: 8px;
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 10px;
}

.cas-latent-loading-bar {
  width: 0%;
  height: 100%;
  background: #fff;
  border-radius: 4px;
  transition: width 0.3s ease;
}

.cas-latent-loading-percent {
  font-size: 14px;
  color: #fff;
  font-family: 'AllianceNo2-Medium', sans-serif;
  letter-spacing: 0.07rem;
}

/* Hide the old loading text */
.cas-latent-loading-text {
  display: none;
}

@keyframes cas-latent-dots {
  0%, 20% {
    content: '.';
  }

  40% {
    content: '..';
  }

  60% {
    content: '...';
  }

  80%, 100% {
    content: '';
  }
}

/* ------ Mobile and responsive fixes ------ */

/* Use a mobile-first approach - adjusted for multiple instances */
.cas-latent-viewer {
  /* Use proper positioning for multiple instances */
  position: relative;
  width: 100%;
  height: 80vh;
  /* Dynamic viewport height - adjusted for multiple instances */
  max-height: 800px;
  min-height: 400px;
}

.cas-latent-container {
  height: 80vh;
  max-height: 800px;
  min-height: 400px;
  width: 100%;
}

/* Fix for Safari/iOS -- apply these rules universally */
.cas-latent-video {
  object-fit: contain !important;
  height: 100% !important;
  width: 100% !important;
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
  opacity: 1 !important;
  visibility: visible !important;
  transform: translateZ(0) !important;
  -webkit-transform: translateZ(0) !important;
  backface-visibility: hidden !important;
  -webkit-backface-visibility: hidden !important;
  max-height: none !important;
  max-width: none !important;
}

/* Mobile devices */
@media (max-width:768px) {
  /* Adjusted container sizing for mobile with multiple instances */
  .cas-latent-viewer {
    height: 80vh;
    min-height: 400px;
    width: 100%;
    position: relative;
    overflow: hidden;
  }

  .cas-latent-container {
    height: 80vh;
    min-height: 400px;
    width: 100%;
    overflow: hidden;
  }
  
  /* Video element fixes for mobile */
  .cas-latent-video-container {
    z-index: 1;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
  }

  .cas-latent-video {
    /* Additional mobile-specific fixes */
    max-width: 100% !important;
    max-height: 100% !important;
    width: 100% !important;
    height: 100% !important;
    z-index: 1 !important;
  }
  
  /* Overlay positioning for mobile */
  .cas-latent-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    height: 100%;
    width: 100%;
    z-index: 1000;
  }
  
  /* Instruction area width for mobile */
  .cas-latent-instruction {
    width: 85vw;
    max-width: 500px;
    text-align: left;
    padding: 20px;
    box-sizing: border-box;
  }
  
  /* Button styling for mobile */
  .cas-latent-start-button {
    width: 100%;
    padding: 12px;
    font-size: 16px;
    border-radius: 6px;
    text-align: center;
    margin-top: 20px;
  }
  
  /* Fix z-index issues on mobile - adjusted for multiple instances */
  .cas-latent-interaction-layer {
    z-index: 50;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
  }
}

/* iOS/Safari specific fixes */
@supports (-webkit-touch-callout:none) {
  .cas-latent-video-container {
    -webkit-transform: translateZ(0);
  }

  .cas-latent-video {
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
  }

  .cas-latent-viewer, .cas-latent-container {
    height: -webkit-fill-available;
  }
}

/* Fix WordPress theme conflicts */
.entry-content {
  margin: 0 !important;
  max-width: 100% !important;
  padding: 0 !important;
}

/* Make the viewer take full width */
.cas-latent-wrapper {
  width: 100vw;
  position: relative;
  left: 50%;
  right: 50%;
  margin-left: -50vw;
  margin-right: -50vw;
  overflow: hidden;
  /* Add spacing between multiple instances */
  margin-bottom: 2rem;
  margin-top: 2rem;
}

/* Calculate dynamic viewport height for mobile */
:root {
  --vh: 1vh;
}

/* Fix for fixed positioning on iOS */
.cas-latent-overlay,
.cas-latent-interaction-layer,
.cas-latent-video-container {
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
}

/* Explicit video visibility fix */
video.cas-latent-video {
  display: block !important;
  opacity: 1 !important;
  visibility: visible !important;
}