/* ==========================================================================
   1. CONFIGURATION & VARIABLES
   ========================================================================== */
@property --v { syntax: '<number>'; initial-value: 0; inherits: true; }

.stack-wrapper {
    --accent-forge: #00D1FF;
    --border-color: rgba(255, 255, 255, 0.1);
    display: grid;
    /* Par défaut : 1 colonne (Mobile) */
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto auto;
    gap: 2rem;
    align-items: center;
    max-width: 1200px;
    margin: 60px auto;
    padding: 0 5%;
    min-height: 80vh;
    position: relative;
}

/* Version Bureau (Desktop) */
@media (min-width: 1024px) {
    .stack-wrapper {
        grid-template-columns: 550px 1fr;
        grid-template-rows: auto auto 1fr auto;
        gap: 0 4rem;
        margin: 80px auto;
    }
}

/* ==========================================================================
   2. LES CARTES (STACK ITEMS)
   ========================================================================== */
.stack-item {
    grid-area: 1 / 1 / -1 / -1;
    display: grid;
    grid-template-columns: inherit;
    grid-template-rows: inherit;
    gap: inherit;
    --diff: calc(var(--k) - var(--i));
    --abs-diff: max(var(--diff), -1 * var(--diff));
    --not-top: min(1, var(--abs-diff));
    --top: calc(1 - var(--not-top));
    
    z-index: calc(var(--n) - var(--abs-diff));
    pointer-events: none; /* Désactivé par défaut */
}

/* Active le clic uniquement sur la carte du dessus */
.stack-item[style*="--top: 1"],
.stack-item {
    /* Le JS ou le CSS dynamique doit s'assurer que --top est géré */
    pointer-events: auto; 
}

/* IMAGE XXL & RESPONSIVE */
.stack-item img {
    grid-area: 1 / 1 / 2 / 2; /* Sur mobile : ligne 1 */
    width: 90vw;
    height: 90vw;
    max-width: 550px;
    max-height: 550px;
    margin: 0 auto;
    object-fit: cover;
    border-radius: 2rem;
    border: 2px solid var(--border-color);
    box-shadow: 0 20px 50px rgba(0,0,0,0.5);
    transition: transform 0.8s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.4s;
    transform: rotate(var(--a)) scale(var(--top));
}

@media (min-width: 1024px) {
    .stack-item img {
        grid-area: 1 / 1 / 5 / 2; /* Sur PC : prend toute la colonne 1 */
        width: 550px;
        height: 550px;
    }
}

/* TITRES & TEXTES */
.stack-item h2 {
    grid-area: 2 / 1 / 3 / 2; /* Mobile : ligne 2 */
    font-size: clamp(2rem, 8vw, 4.5rem); /* Taille fluide */
    color: var(--accent-forge);
    text-align: center;
    opacity: var(--top);
    transform: translateY(calc(var(--not-top) * 40px));
    transition: 0.5s;
    line-height: 1;
}

.stack-item em {
    grid-area: 3 / 1 / 4 / 2; /* Mobile : ligne 3 */
    font-size: clamp(1rem, 4vw, 1.5rem);
    color: rgba(255,255,255,0.6);
    font-style: normal;
    text-align: center;
    opacity: var(--top);
    transform: translateY(calc(var(--not-top) * 20px));
    transition: 0.5s 0.1s;
}

@media (min-width: 1024px) {
    .stack-item h2, .stack-item em {
        grid-column: 2; /* Retour à la colonne 2 sur PC */
        text-align: left;
    }
    .stack-item h2 { grid-row: 2; }
    .stack-item em { grid-row: 3; }
}

/* ==========================================================================
   3. NAVIGATION
   ========================================================================== */
.stack-nav {
    grid-area: 4 / 1 / 5 / 2;
    display: flex;
    gap: 2rem;
    justify-content: center;
    margin-top: 2rem;
    z-index: 1000;
}

@media (min-width: 1024px) {
    .stack-nav {
        grid-column: 2;
        grid-row: 4;
        justify-content: flex-start;
        margin-top: 0;
    }
}

.stack-btn {
    width: 60px; height: 60px;
    border-radius: 50%;
    border: 2px solid var(--accent-forge);
    background: rgba(0, 209, 255, 0.1);
    cursor: pointer;
    transition: 0.3s;
    display: flex; align-items: center; justify-content: center;
}

.stack-btn:hover { background: var(--accent-forge); box-shadow: 0 0 20px var(--accent-forge); }

/* ==========================================================================
   4. MODALE (POP-UP) RESPONSIVE
   ========================================================================== */
.modal {
    position: fixed; display: none; z-index: 9999;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.8); backdrop-filter: blur(15px);
    align-items: center; justify-content: center;
}

.modal.active { display: flex; }

.modal-content {
    background: rgba(20, 20, 35, 0.95);
    border: 1px solid var(--accent-forge);
    padding: 30px;
    border-radius: 24px;
    width: 95%;
    max-width: 900px;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8);
    color: white;
}

@media (min-width: 768px) {
    .modal-content { padding: 50px; width: 90%; }
}

/* Grille interne de la modale */
#modal-body > div {
    display: grid;
    grid-template-columns: 1fr; /* 1 colonne mobile */
    gap: 20px;
}

@media (min-width: 768px) {
    #modal-body > div {
        grid-template-columns: 1fr 1fr; /* 2 colonnes PC */
        gap: 40px;
    }
}

/* ==========================================================================
   5. EFFETS DE FOND (THEME FORGE)
   ========================================================================== */
.theme-forge .background {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: -1;
    background: #050505;
    background-image: radial-gradient(circle at 50% 50%, rgba(0, 209, 255, 0.1) 0%, transparent 80%),
                      linear-gradient(rgba(0, 209, 255, 0.05) 1px, transparent 1px),
                      linear-gradient(90deg, rgba(0, 209, 255, 0.05) 1px, transparent 1px);
    background-size: 100% 100%, 30px 30px, 30px 30px;
}

.stack-item.eject img {
    transform: translateX(-150%) rotate(-20deg) scale(0.8) !important;
    opacity: 0;
}