* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: #000;
    overflow: hidden;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    perspective: 1000px; 
}

.scene3d {
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    transform-style: preserve-3d;
}

.gallery {
    position: relative;
    width: 450px;  
    height: 335px; 
    transform-style: preserve-3d;
}

.card {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-size: contain; 
    background-position: center;
    background-repeat: no-repeat;
    border: none;
    
    filter: drop-shadow(-15px 15px 35px rgba(0, 0, 0, 0.85)); 
    will-change: transform, opacity, filter, z-index; 
    
    /* BLOCCA TUTTE LE FOTO: le rende trasparenti al cursore del mouse */
    pointer-events: none !important; 
    
    transition: filter 0.2s ease-in-out; 
}

/* ========================================================= */
/* SBLOCCA SOLO LA FOTO CENTRALE E GESTISCI L'HOVER          */
/* ========================================================= */
.card.center-active {
    /* La foto centrale torna "solida" e cliccabile, ignorando i bordi delle altre */
    pointer-events: auto !important; 
    cursor: pointer;
}

.card.center-active:hover {
    /* --- OPZIONE 1: OMBRA BIANCA LUMINOSA (Glow) --- */
    /* Crea l'ombra nera e poi inverte TUTTO. È quella attiva adesso. */
    filter: drop-shadow(-15px 15px 35px rgba(0, 0, 0, 0.212)) invert(100%);
    
    /* --- OPZIONE 2: OMBRA NERA CLASSICA --- */
    /* Inverte solo la foto e poi crea l'ombra nera. 
       Se in futuro vuoi tornare indietro, cancella o commenta la riga dell'Opzione 1 
       e togli i commenti (/*) a questa riga qui sotto: */
       
    /* filter: invert(100%) drop-shadow(-15px 15px 35px rgba(0, 0, 0, 0.85)); */
}

/* --- STILI CONTATORE --- */
.counter {
    position: fixed;
    bottom: 25px; 
    left: 50%;
    transform: translateX(-50%);
    color: #ff0000; 
    font-family: 'Helvetica Neue', Arial, sans-serif; 
    font-size: 1.2rem;
    font-weight: bold;
    letter-spacing: 2px;
    z-index: 100000; 
    pointer-events: none; 
    
    transition: opacity 0.3s ease-in-out; 
}

/* IL TRUCCO: Nasconde SOLO il contatore principale (#counter) quando si apre la foto grande */
body:has(.lightbox.active) #counter {
    opacity: 0;
}

/* --- STILI LIGHTBOX (SFONDO NERO) --- */
.lightbox {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgb(0, 0, 0); 
    
    display: flex;
    justify-content: center; 
    align-items: center;     
    
    z-index: 99999;
    opacity: 0;
    pointer-events: none; 
    transition: opacity 0.3s ease-in-out;
}

.lightbox.active {
    opacity: 1;
    pointer-events: auto; 
}

/* --- IMMAGINE IN FULLSCREEN --- */
.lightbox img {
    max-width: 85vw;
    max-height: 80vh; 
    object-fit: contain; 
    border-radius: 4px;
    z-index: 2;
}

/* --- STILI PER LE FRECCE DI NAVIGAZIONE --- */
.lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    font-size: 4rem; 
    font-family: 'Helvetica Neue', Arial, sans-serif; 
    font-weight: 300; 
    color: #ff0000; 
    cursor: pointer;
    user-select: none;
    padding: 20px;
    z-index: 3;
    transition: transform 0.2s, text-shadow 0.2s; 
}

.lightbox-nav:hover {
    transform: translateY(-50%) scale(1.2); 
    text-shadow: 0 0 15px rgba(255, 0, 0, 0.6); 
}

.lightbox-prev {
    left: 30px;
}

.lightbox-next {
    right: 30px;
}

.back-button {
    position: fixed;
    top: 30px; 
    left: 30px;
    width: 50px;       /* Regola la dimensione a tuo piacimento */
    height: auto;
    z-index: 100001;   /* Deve essere superiore al lightbox */
    cursor: pointer;
    transition: transform 0.2s ease;
}

.back-button:hover {
    transform: scale(1.1); /* Piccolo effetto al passaggio del mouse */
}

/* Definiamo l'animazione */
@keyframes rotateY-infinite {
    from { transform: rotateY(0deg); }
    to { transform: rotateY(360deg); }
}

.back-button {
    width: 50px; 
    height: auto;
    display: block;
    
    /* Applichiamo l'animazione */
    animation: rotateY-infinite 4s linear infinite;
    
    /* Essenziale per rendere l'effetto 3D visibile */
    transform-style: preserve-3d;
}

/* === RESPONSIVE MOBILE === */
@media (max-width: 767px) {
    .gallery {
        width: 280px;  
        height: 210px; 
    }

    .back-button {
        top: 15px;
        left: 15px;
        width: 40px;
    }

    .lightbox img {
        max-width: 90vw;
        max-height: 75vh;
    }

    .lightbox-nav {
        font-size: 2.5rem;
        padding: 10px;
    }

    .lightbox-prev {
        left: 10px;
    }

    .lightbox-next {
        right: 10px;
    }

    .counter {
        font-size: 1rem;
        bottom: 15px;
    }
}