/* Camada escura/desfocada que cobre a tela toda */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 2000;
    display: flex;
    justify-content: center;
    align-items: center;
    
    /* Estado inicial: Escondido */
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
}

/* Quando o modal ganha a classe active, ele aparece */
.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

/* CONTAINER INTELIGENTE (Universal para qualquer tela) */
.modal-content {
    width: 92vw;
    height: 92vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
    position: relative; /* Essencial para alinhar o X em relação à imagem */
}

/* A IMAGEM FLUIDA PERFEITA */
.modal-img {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 8px;
    cursor: pointer; /* Indica que é clicável */
    
    /* Animação de surgimento da imagem */
    transform: scale(0.7);
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal-overlay.active .modal-img {
    transform: scale(1);
}

/* BOTÃO DE FECHAR (X) REESTRUTURADO
   Ele agora surge do topo centralizado e fica oculto por padrão
*/
.modal-close-btn {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translate(-50%, -50px); /* Começa acima da tela, escondido */
    background: rgba(252, 232, 180, 0.7);    /* Fundo escuro redondo para dar contraste se a imagem for clara */
    border: none;
    color: #313131;
    font-size: 2rem;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    cursor: pointer;
    z-index: 2100;
    display: flex;
    justify-content: center;
    align-items: center;
    
    opacity: 0;
    pointer-events: none;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.3s ease, color 0.2s ease;
}

/* Quando a imagem for tocada, o modal ganhará a classe 'show-close' via JS */
.modal-overlay.show-close .modal-close-btn {
    opacity: 1;
    pointer-events: auto;
    transform: translate(-50%, 0); /* Desce para a posição correta no meio do topo */
}

.modal-close-btn:hover {
    color: #ffdd77;
    background: rgba(126, 126, 126, 0.9);
}