/**
 * VALIS Fixes v3.1
 * ═══════════════════════════════════════════════════════════════
 * Correcciones puntuales para problemas identificados:
 * 1. Botón referidos - posicionamiento y animaciones
 * 2. Divination - overflow y posición
 * 3. Premium - visibilidad de contenido
 */

/* ═══════════════════════════════════════════════════════════════
   FIX 1: BOTÓN DE REFERIDOS
   Alineado con el cuadrotexto (4vw margen)
   ═══════════════════════════════════════════════════════════════ */

#referralFloat {
    position: fixed !important;
    bottom: calc(4vh + 12px) !important;
    right: calc(4vw + 12px) !important;
    z-index: 9999 !important;
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    background: #1a1a1a !important;
    color: white !important;
    padding: 10px 14px !important;
    border: none !important;
    border-radius: 4px !important;
    cursor: pointer !important;
    align-items: center !important;
    gap: 6px !important;
    font-family: var(--valis-font-ui, 'Inter', sans-serif) !important;
    font-size: 12px !important;
    font-weight: 500 !important;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15) !important;
    transition: transform 0.2s, box-shadow 0.2s, background 0.2s !important;
    pointer-events: auto !important;
    -webkit-tap-highlight-color: transparent;
    /* Animación de respiración sutil */
    animation: referralBreathe 4s ease-in-out infinite;
}

#referralFloat:hover {
    transform: translateY(-2px) !important;
    box-shadow: 0 6px 16px rgba(0,0,0,0.2) !important;
    animation: none !important;
}

#referralFloat .referral-header-icon {
    width: 14px;
    height: 14px;
    stroke: rgba(255, 255, 255, 0.85);
    transition: stroke 0.2s;
}

#referralFloat:hover .referral-header-icon {
    stroke: white;
}

#referralFloat .referral-header-badge {
    color: var(--valis-cielo, #b4a06e);
    font-weight: 600;
}

/* Efecto glitch */
#referralFloat.glitch-active {
    animation: referralGlitch 0.3s ease-out !important;
}

/* Ocultar durante meditación y escenas inmersivas */
.valis-immersive-loader.active ~ #referralFloat,
body:has(.valis-immersive-loader.active) #referralFloat,
body[data-scene="meditation"] #referralFloat,
body[data-scene="premium"] #referralFloat {
    opacity: 0 !important;
    pointer-events: none !important;
}

/* ═══════════════════════════════════════════════════════════════
   TOOLTIP DE REFERIDOS - Alineado arriba del botón
   ═══════════════════════════════════════════════════════════════ */

#referralTooltip {
    position: fixed !important;
    bottom: calc(4vh + 60px) !important;
    right: calc(4vw + 12px) !important;
    max-width: 220px;
    padding: 16px;
    background: white;
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 4px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    z-index: 10000;
    opacity: 0;
    transform: translateY(8px);
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

#referralTooltip.visible {
    opacity: 1 !important;
    transform: translateY(0) !important;
    pointer-events: auto !important;
}

/* Flecha apuntando hacia abajo (al botón) */
#referralTooltip::after {
    content: '';
    position: absolute;
    bottom: -8px;
    right: 24px;
    border: 8px solid transparent;
    border-top-color: white;
    border-bottom: none;
}

#referralTooltip::before {
    content: '';
    position: absolute;
    bottom: -9px;
    right: 23px;
    border: 9px solid transparent;
    border-top-color: rgba(0, 0, 0, 0.08);
    border-bottom: none;
}

/* ═══════════════════════════════════════════════════════════════
   ANIMACIONES DE REFERIDOS
   ═══════════════════════════════════════════════════════════════ */

@keyframes referralBreathe {
    0%, 100% { 
        transform: scale(1); 
        box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    }
    50% { 
        transform: scale(1.02); 
        box-shadow: 0 6px 16px rgba(0,0,0,0.18);
    }
}

@keyframes referralGlitch {
    0% { transform: translate(0, 0); }
    10% { transform: translate(-2px, 1px); }
    20% { transform: translate(2px, -1px); }
    30% { transform: translate(-1px, 2px); }
    40% { transform: translate(1px, -2px); }
    50% { transform: translate(-2px, -1px); }
    60% { transform: translate(2px, 1px); }
    70% { transform: translate(0, 0); }
    100% { transform: translate(0, 0); }
}

/* ═══════════════════════════════════════════════════════════════
   FIX 2: DIVINATION - CANVAS Y OVERFLOW
   Mantener animación dentro del contenedor
   ═══════════════════════════════════════════════════════════════ */

/* Contenedor principal de adivinación */
.divination-action-area {
    overflow: hidden !important;
    position: relative !important;
    min-height: 280px !important;
    max-height: 360px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

/* ═══════════════════════════════════════════════════════════════
   FIX 3: PREMIUM SCENE - CONTENIDO VISIBLE
   Asegurar que las capas se muestren correctamente
   ═══════════════════════════════════════════════════════════════ */

/* Ocultar el loading cuando el body está visible */
#scenePremium.has-content .deep-reading-loading,
#scenePremium .deep-reading-loading[style*="display: none"] {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
}

/* Container principal visible cuando hay contenido */
#scenePremium .deep-reading-body {
    display: none;
}

#scenePremium .deep-reading-body.visible {
    display: flex !important;
    flex-direction: column !important;
    flex: 1 !important;
    overflow: hidden !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* Container de scroll con capas */
#scenePremium .deep-reading-scroll,
#scenePremium .deep-layers-container {
    display: flex !important;
    flex-direction: column !important;
    gap: 32px !important;
    padding: 24px !important;
    overflow-y: auto !important;
    flex: 1 !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* Capas individuales - TODAS las variantes - SOBRESCRIBIR HIDDEN */
#scenePremium .deep-layer:not(.really-hidden),
#scenePremium #layerA:not(.really-hidden),
#scenePremium #layerB:not(.really-hidden),
#scenePremium #layerD:not(.really-hidden),
#scenePremium #layerC:not(.really-hidden),
#scenePremium .deep-layer.deep-layer-a,
#scenePremium .deep-layer.deep-layer-b,
#scenePremium .deep-layer.deep-layer-d,
#scenePremium .deep-layer.deep-layer-c,
#scenePremium section.deep-layer {
    display: block !important;
    opacity: 1 !important;
    visibility: visible !important;
    margin-bottom: 24px !important;
    background: transparent !important;
}

/* Ocultar solo con clase específica */
#scenePremium .deep-layer.hidden {
    display: none !important;
}

/* Cuando se quita hidden, mostrar */
#scenePremium .deep-layer:not(.hidden) {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* Contenido de capa */
#scenePremium .deep-layer .layer-content,
#scenePremium .layer-content {
    font-family: 'Cormorant Garamond', Georgia, serif !important;
    font-size: 1.1rem !important;
    line-height: 1.9 !important;
    color: #1a1a1a !important;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

#scenePremium .deep-layer .layer-content p,
#scenePremium .layer-content p {
    margin-bottom: 1.25em !important;
    text-align: justify !important;
}

/* Forzar visibilidad del contenedor principal de la escena */
#scenePremium .scene-content,
#scenePremium .valis-deep-reading {
    display: flex !important;
    flex-direction: column !important;
    flex: 1 !important;
    overflow: hidden !important;
}

/* ═══════════════════════════════════════════════════════════════
   FIX 4: IMMERSIVE LOADER - DISPLAY CORRECTO
   ═══════════════════════════════════════════════════════════════ */

.valis-immersive-loader {
    display: none !important;
}

.valis-immersive-loader.active {
    display: flex !important;
}

/* ═══════════════════════════════════════════════════════════════
   FIX 5: LAYER C BUTTON
   ═══════════════════════════════════════════════════════════════ */

#btnShowTechnical:not(.hidden) {
    display: inline-flex !important;
}

/* ═══════════════════════════════════════════════════════════════
   FIX 6: ESTILOS ADICIONALES PARA CAPAS
   ═══════════════════════════════════════════════════════════════ */

/* Estilos por tipo de capa */
#scenePremium .layer-a .layer-content {
    font-style: italic;
}

#scenePremium .layer-d .layer-content {
    font-weight: 500;
}

/* Header oculto en capas dinámicas (sin títulos) */
#scenePremium .deep-layer .layer-header {
    display: none;
}

/* ═══════════════════════════════════════════════════════════════
   FIX 7: VIDEO LOOP OPTIMIZADO
   Usar will-change y contain para mejor rendimiento GPU
   ═══════════════════════════════════════════════════════════════ */

/* Video de fondo - optimizado para GPU */
.background-clouds,
.background-video,
.clouds-layer,
video[autoplay] {
    will-change: auto; /* Dejar que el navegador optimice */
    contain: strict; /* Aislar del resto del layout */
    transform: translateZ(0); /* Forzar composición GPU */
    backface-visibility: hidden;
}

/* Cuando el tab está oculto, el navegador pausará automáticamente */
/* No necesitamos pausar manualmente el video */

/* Reducir calidad del video cuando no es el foco */
@media (prefers-reduced-motion: reduce) {
    .background-clouds,
    .background-video,
    .clouds-layer {
        animation: none !important;
        display: none; /* Ocultar video completamente */
    }
}

/* ═══════════════════════════════════════════════════════════════
   MOBILE FIXES
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
    #referralFloat {
        bottom: calc(2vh + 8px) !important;
        right: calc(2vw + 8px) !important;
        padding: 8px 12px !important;
        font-size: 11px !important;
    }
    
    #referralTooltip {
        bottom: calc(2vh + 52px) !important;
        right: calc(2vw + 8px) !important;
        max-width: 200px;
        padding: 14px;
    }
    
    #scenePremium .deep-layer .layer-content {
        font-size: 1rem;
        line-height: 1.75;
    }
}

/* ═══════════════════════════════════════════════════════════════
   SELECTOR DE IDIOMA
   ═══════════════════════════════════════════════════════════════ */

.lang-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid rgba(139, 115, 85, 0.3);
    color: var(--valis-gold, #8B7355);
    padding: 6px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-family: var(--valis-font-ui, 'Inter', sans-serif);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.05em;
    transition: all 0.2s ease;
    min-width: 42px;
}

.lang-btn:hover {
    background: rgba(139, 115, 85, 0.15);
    border-color: var(--valis-gold, #8B7355);
}

.lang-btn:active {
    transform: scale(0.95);
}

.lang-current {
    text-transform: uppercase;
}

/* Responsive */
@media (max-width: 768px) {
    .lang-btn {
        padding: 5px 8px;
        font-size: 10px;
        min-width: 36px;
    }
}
