body {
    margin: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100dvh; 
    background-color: #2c3e50;
    font-family: sans-serif;
    color: white;
    
    /* Solución anti-zoom táctil, crucial para móvil */
    -ms-touch-action: manipulation;
    touch-action: manipulation;
    
    /* Fondo dinámico de las imágenes */
    background-size: cover;
    background-position: center;
    transition: background-image 1s ease-in-out;
    
    filter: none;
    backdrop-filter: none;
}

/* 🟢 CAPA DE DESENFOQUE (Bajo el contenido principal, pero encima del body) */
#blurLayer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100dvh;
    background-color: transparent; 
    filter: blur(0px) brightness(1); 
    transition: filter 0.5s, background-color 0.5s;
    z-index: 5; 
}

/* CLASE QUE SE ACTIVA CON EL MENSAJE O EL VIDEO PARA APLICAR EL DESENFOQUE */
#blurLayer.memory-active-blur {
    filter: blur(5px) brightness(0.5); 
    background-color: rgba(0, 0, 0, 0.4); 
}

#gameContainer {
    display: flex;
    gap: 30px;
    background-color: transparent; 
    padding: 30px;
    border-radius: 10px;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
    position: relative;
    max-width: 700px; 
    z-index: 10; 
}

.main-game-area {
    display: flex;
    flex-direction: column;
    align-items: center;
}

#tetrisCanvas {
    width: 300px; 
    height: 600px;
    display: block;
    border: 5px solid #3498db;
    border-radius: 5px;
    background-color: transparent; 
}

#sidebar {
    width: 250px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    background-color: rgba(0, 0, 0, 0.7); 
    padding: 10px; 
    border-radius: 5px;
}

#sidebar h1 {
    font-size: 1.8em;
    text-align: center;
    color: #1abc9c;
    text-shadow: 0 0 5px #1abc9c;
    margin-top: 0;
}

.info-box {
    background-color: rgba(0, 0, 0, 0.5); 
    padding: 10px;
    border-radius: 5px;
    border-left: 5px solid #f39c12;
}

#memoryMessage {
    background-color: rgba(0, 0, 0, 0.7); 
    border-left: 5px solid #e74c3c;
    text-align: center;
    flex-grow: 1;
    min-height: 150px; 
    display: flex;
    flex-direction: column;
    justify-content: center;
    overflow: hidden;
}

#overlay {
    position: fixed; 
    top: 0;
    left: 0;
    width: 100%;
    height: 100dvh; 
    background-color: rgba(0, 0, 0, 0.7); 
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    border-radius: 10px;
    /* CRÍTICO: Debe estar sobre el juego */
    z-index: 50;
}

#startButton {
    padding: 10px 20px;
    font-size: 1.2em;
    background-color: #2ecc71;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s;
}

#touchControls {
    display: none; 
}


/* --- OVERLAY DE RECUERDO (IMAGEN) --- */

#memoryOverlay {
    position: fixed; 
    top: 0;
    left: 0;
    width: 100%;
    height: 100dvh; 
    background-color: rgba(0, 0, 0, 0.7); 
    display: none; 
    justify-content: center;
    align-items: center;
    
    filter: none; 
    backdrop-filter: none; 

    /* CRÍTICO: Debe estar sobre el blur layer */
    z-index: 100; 
    opacity: 1;
    transition: opacity 0.5s ease-in-out;
}

#memoryOverlay.hidden {
    opacity: 0;
}

#memoryOverlayContent {
    background-color: #34495e; 
    color: white;
    padding: 30px;
    border-radius: 15px;
    max-width: 90%;
    filter: none !important; 
    position: relative; 
    z-index: 101; 

    transform: scale(1);
    animation: bounceIn 0.5s cubic-bezier(0.68, -0.55, 0.27, 1.55);
}

#memoryOverlay.active-flash #memoryOverlayContent {
    /* La animación flash que pediste para la revelación */
    animation: flashBorder 0.2s infinite alternate, bounceIn 0.5s cubic-bezier(0.68, -0.55, 0.27, 1.55); 
}

#memoryOverlayContent h2 {
    color: #e74c3c;
    font-size: 2em;
    margin-top: 0;
}

.flashback-wrapper {
    overflow: hidden;
    border-radius: 10px;
}

.unlocked-memory-image-large {
    max-width: 100%;
    max-height: 40vh; 
    height: auto;
    border-radius: 10px;
    margin-top: 15px;
    border: 5px solid #1abc9c;
    object-fit: cover;
}


/* --- OVERLAY DE VIDEO (PREMIO) --- */
#videoOverlay {
    position: fixed; 
    top: 0;
    left: 0;
    width: 100%;
    height: 100dvh; 
    background-color: rgba(0, 0, 0, 0.9); 
    display: none; 
    justify-content: center;
    align-items: center;
    /* CRÍTICO: Debe ser la capa MÁS alta */
    z-index: 150; 
    opacity: 1;
    transition: opacity 0.5s ease-in-out;
}

#videoOverlay.hidden {
    opacity: 0;
}

#videoOverlayContent {
    background-color: #34495e; 
    color: white;
    padding: 30px;
    border-radius: 15px;
    max-width: 90%;
    text-align: center;
    filter: none !important; 
    z-index: 151; 
}

#prizeVideo {
    max-width: 100%;
    max-height: 70vh;
    border-radius: 10px;
    margin: 15px 0;
    border: 5px solid #2ecc71; 
}

#closeVideoBtn {
    padding: 10px 20px;
    font-size: 1.1em;
    background-color: #e74c3c;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s;
    margin-top: 15px;
}


/* --- KEYFRAMES Y MEDIA QUERIES --- */

/* Animación de entrada: aparece con un pequeño rebote */
@keyframes bounceIn {
    0% {
        opacity: 0;
        transform: scale(0.5);
    }
    50% {
        transform: scale(1.05);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes flashBorder {
    from {
        box-shadow: 0 0 10px #f1c40f, 0 0 20px #e67e22; 
    }
    to {
        box-shadow: 0 0 30px #e74c3c, 0 0 50px #c0392b; 
    }
}


/* --- AJUSTES DE MOVILIDAD (MEDIA QUERY) --- */
@media (max-width: 600px) {
    #gameContainer {
        flex-direction: row; 
        width: 100%;
        max-width: 98%; 
        padding: 2px; 
        gap: 3px; 
        align-items: flex-start; 
    }

    #tetrisCanvas {
        width: 180px; 
        height: 360px; 
        min-height: 360px; 
    }
    
    #sidebar {
        width: 100px; 
        padding: 5px 2px; 
        height: 360px; 
    }

    .info-box {
        font-size: 0.6em; 
        padding: 3px;
    }
    
    #memoryMessage {
        min-height: 40px; 
    }
    
    .main-game-area {
        gap: 2px; 
    }
    
    /* Disposición 2x2 para botones táctiles */
    #touchControls {
        display: grid; 
        grid-template-areas: 
            "left left right right"
            "rotate rotate down down";
        
        grid-template-columns: 1fr 1fr 1fr 1fr; 
        gap: 4px; 
        width: 100%; 
        max-width: 250px; 
        margin-top: 5px; 
        margin-bottom: 5px; 
    }
    
    #touchControls button {
        width: 100%;
        height: 50px; 
        font-size: 1.8em; 
    }

    #leftBtn { grid-area: left; } 
    #rightBtn { grid-area: right; }
    #rotateBtn { grid-area: rotate; }
    #downBtn { grid-area: down; }
}