/* ============================================================
   TV EFFECT - Efecto de TV y Glitch para modo normal
   ============================================================ */

/* ============================================================
   1. CAPA PRINCIPAL DE TV
   ============================================================ */

.tv-effect-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 99995;
    overflow: hidden;
}

body.tv-effect-active .tv-effect-overlay {
    display: block;
}

/* ============================================================
   2. DISTORSIÓN DE LA IMAGEN DE FONDO (::before)
   ============================================================ */

body.tv-effect-active::before {
    animation: tvGlitchBackground 0.1s infinite !important;
}

/* Distorsión principal del fondo */
@keyframes tvGlitchBackground {
    0%, 100% {
        transform: translate(0, 0) scale(1);
        filter: grayscale(100%) brightness(0.7) hue-rotate(0deg);
    }
    2% {
        transform: translate(-3px, 1px) scale(1.01);
        filter: grayscale(100%) brightness(0.65) hue-rotate(0deg);
    }
    4% {
        transform: translate(3px, -1px) scale(0.99);
        filter: grayscale(100%) brightness(0.75) hue-rotate(0deg);
    }
    6% {
        transform: translate(-2px, 2px) scale(1.01);
        filter: grayscale(100%) brightness(0.6) hue-rotate(0deg);
    }
    8% {
        transform: translate(2px, -2px) scale(0.99);
        filter: grayscale(100%) brightness(0.8) hue-rotate(0deg);
    }
    10% {
        transform: translate(0, 0) scale(1);
        filter: grayscale(100%) brightness(0.7) hue-rotate(0deg);
    }
    85% {
        transform: translate(0, 0) scale(1);
        filter: grayscale(100%) brightness(0.7) hue-rotate(0deg);
    }
    88% {
        transform: translate(-5px, 3px) scale(1.02);
        filter: grayscale(100%) brightness(0.55) hue-rotate(0deg);
    }
    90% {
        transform: translate(5px, -3px) scale(0.98);
        filter: grayscale(100%) brightness(0.8) hue-rotate(0deg);
    }
    92% {
        transform: translate(-3px, -2px) scale(1.01);
        filter: grayscale(100%) brightness(0.6) hue-rotate(0deg);
    }
    94% {
        transform: translate(3px, 2px) scale(0.99);
        filter: grayscale(100%) brightness(0.75) hue-rotate(0deg);
    }
    96% {
        transform: translate(-8px, 4px) scale(1.02);
        filter: grayscale(100%) brightness(0.5) hue-rotate(0deg);
    }
    98% {
        transform: translate(8px, -4px) scale(0.98);
        filter: grayscale(100%) brightness(0.8) hue-rotate(0deg);
    }
}

/* ============================================================
   3. DISTORSIÓN INTENSA (evento aleatorio)
   ============================================================ */

body.tv-effect-active.intense-glitch::before {
    animation: tvGlitchIntense 0.5s ease !important;
}

@keyframes tvGlitchIntense {
    0% {
        transform: translate(0, 0) scale(1);
        filter: grayscale(100%) brightness(0.7);
    }
    10% {
        transform: translate(-10px, 5px) scale(1.03);
        filter: grayscale(100%) brightness(0.4);
    }
    20% {
        transform: translate(10px, -5px) scale(0.97);
        filter: grayscale(100%) brightness(0.9);
    }
    30% {
        transform: translate(-5px, 10px) scale(1.02);
        filter: grayscale(100%) brightness(0.5);
    }
    40% {
        transform: translate(5px, -10px) scale(0.98);
        filter: grayscale(100%) brightness(0.8);
    }
    50% {
        transform: translate(-15px, 5px) scale(1.04);
        filter: grayscale(100%) brightness(0.3);
    }
    60% {
        transform: translate(15px, -5px) scale(0.96);
        filter: grayscale(100%) brightness(0.9);
    }
    70% {
        transform: translate(-8px, 8px) scale(1.01);
        filter: grayscale(100%) brightness(0.5);
    }
    80% {
        transform: translate(8px, -8px) scale(0.99);
        filter: grayscale(100%) brightness(0.8);
    }
    90% {
        transform: translate(-5px, 3px) scale(1.01);
        filter: grayscale(100%) brightness(0.6);
    }
    100% {
        transform: translate(0, 0) scale(1);
        filter: grayscale(100%) brightness(0.7);
    }
}

/* ============================================================
   4. LÍNEAS DE TV (SCANLINES) - MÁS DENSAS
   ============================================================ */

.tv-scanlines {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: repeating-linear-gradient(
        to bottom,
        rgba(0, 0, 0, 0.15) 0px,
        rgba(0, 0, 0, 0.15) 1px,
        transparent 1px,
        transparent 2px
    );
    animation: tvScanlines 0.05s linear infinite;
    pointer-events: none;
    z-index: 1;
}

@keyframes tvScanlines {
    0% {
        background-position: 0 0;
    }
    100% {
        background-position: 0 2px;
    }
}

/* ============================================================
   5. LÍNEAS DE BARRIDO (SCAN) - MÚLTIPLES
   ============================================================ */

.tv-scan {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 3px;
    background: linear-gradient(
        to bottom,
        rgba(255, 255, 255, 0.12) 0%,
        rgba(255, 255, 255, 0.04) 50%,
        transparent 100%
    );
    box-shadow: 0 0 30px rgba(255, 255, 255, 0.08);
    animation: tvScan 5s linear infinite;
    pointer-events: none;
    z-index: 2;
}

.tv-scan-2 {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 2px;
    background: linear-gradient(
        to bottom,
        rgba(255, 255, 255, 0.06) 0%,
        transparent 100%
    );
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.04);
    animation: tvScan 7s linear infinite 2s;
    pointer-events: none;
    z-index: 2;
}

@keyframes tvScan {
    0% {
        top: -3px;
        opacity: 1;
    }
    95% {
        opacity: 1;
    }
    100% {
        top: 100%;
        opacity: 0;
    }
}

/* ============================================================
   6. EFECTO DE PARPADEO (FLICKER)
   ============================================================ */

.tv-flicker {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.03);
    animation: tvFlicker 0.12s infinite alternate;
    pointer-events: none;
    z-index: 3;
}

@keyframes tvFlicker {
    0% {
        opacity: 0;
    }
    100% {
        opacity: 1;
    }
}

/* ============================================================
   7. EFECTO DE GRANO (NOISE)
   ============================================================ */

.tv-noise {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    opacity: 0.05;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='1'/%3E%3C/svg%3E");
    background-repeat: repeat;
    background-size: 256px 256px;
}

/* ============================================================
   8. BORDES REDONDEADOS (EFECTO TUBO)
   ============================================================ */

.tv-vignette {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(
        ellipse at center,
        transparent 55%,
        rgba(0, 0, 0, 0.5) 100%
    );
    pointer-events: none;
    z-index: 5;
}

/* ============================================================
   9. RESPONSIVE
   ============================================================ */

@media (max-width: 768px) {
    .tv-scanlines {
        background: repeating-linear-gradient(
            to bottom,
            rgba(0, 0, 0, 0.10) 0px,
            rgba(0, 0, 0, 0.10) 1px,
            transparent 1px,
            transparent 2px
        );
    }
    
    .tv-scan-2 {
        display: none;
    }
    
    .tv-noise {
        opacity: 0.04;
    }
    
    @keyframes tvGlitchBackground {
        0%, 100% {
            transform: translate(0, 0) scale(1);
        }
        5% {
            transform: translate(-2px, 1px) scale(1.01);
        }
        10% {
            transform: translate(2px, -1px) scale(0.99);
        }
        85% {
            transform: translate(0, 0) scale(1);
        }
        90% {
            transform: translate(-4px, 2px) scale(1.01);
        }
        95% {
            transform: translate(4px, -2px) scale(0.99);
        }
    }
}

@media (max-width: 480px) {
    .tv-scanlines {
        background: repeating-linear-gradient(
            to bottom,
            rgba(0, 0, 0, 0.08) 0px,
            rgba(0, 0, 0, 0.08) 1px,
            transparent 1px,
            transparent 2px
        );
    }
    
    .tv-flicker {
        animation-duration: 0.2s;
    }
    
    .tv-noise {
        opacity: 0.03;
    }
    
    @keyframes tvGlitchBackground {
        0%, 100% {
            transform: translate(0, 0) scale(1);
        }
        5% {
            transform: translate(-1px, 0px) scale(1.01);
        }
        10% {
            transform: translate(1px, 0px) scale(0.99);
        }
        85% {
            transform: translate(0, 0) scale(1);
        }
        90% {
            transform: translate(-2px, 1px) scale(1.01);
        }
        95% {
            transform: translate(2px, -1px) scale(0.99);
        }
    }
}