/* ============================================================
   PMI App — coquille applicative + navigation AJAX
   - Mobile/tablette : plein écran, comportement inchangé.
   - Desktop (≥1024px) : l'app reste dans une colonne phone
     centrée (430px), jamais étirée en plein écran.
   ============================================================ */

/* Base coquille (pages du mini-jeu uniquement : les autres templates
   utilisent aussi #pmi-app mais restent visuellement inchangés) */
body[class*="pmi-screen-"] #pmi-app {
    position: relative;
    min-height: 100dvh;
    background: #000;
}

/* Transition de navigation (désactivée en mouvement réduit) */
body[class*="pmi-screen-"] #pmi-app.is-leaving {
    opacity: 0;
}
@media (prefers-reduced-motion: no-preference) {
    body[class*="pmi-screen-"] #pmi-app {
        transition: opacity .18s ease;
    }
}

/* Loader plein écran pendant le fetch AJAX (voile + spinner + texte) */
body[class*="pmi-screen-"] #pmi-app.is-loading::after {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 9999;
    display: flex;
    background: rgba(0, 0, 0, .55);
}
body[class*="pmi-screen-"] #pmi-app.is-loading::before {
    content: '';
    position: absolute;
    z-index: 10000;
    top: 50%;
    left: 50%;
    width: 44px;
    height: 44px;
    margin: -22px 0 0 -22px;
    border-radius: 50%;
    border: 4px solid rgba(255, 255, 255, .25);
    border-top-color: #ff0b0b;
    animation: pmi-spin .8s linear infinite;
}
@keyframes pmi-spin {
    to { transform: rotate(360deg); }
}

/* Loader persistant du routeur (créé en JS, hors #pmi-app pour survivre
   aux swaps) : fond noir plein écran + spinner + mention */
#pmi-nav-loader {
    position: fixed;
    inset: 0;
    z-index: 99990;
    display: none;
    flex-direction: column;
    gap: 16px;
    align-items: center;
    justify-content: center;
    background: #000;
}
#pmi-nav-loader.on {
    display: flex;
}
#pmi-nav-loader .pmi-nav-spin {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    border: 4px solid rgba(255, 255, 255, .2);
    border-top-color: #ff0b0b;
    animation: pmi-spin .8s linear infinite;
}
#pmi-nav-loader .pmi-nav-label {
    color: #fff;
    font-size: 14px;
    letter-spacing: 3px;
}
@media (prefers-reduced-motion: reduce) {
    #pmi-nav-loader .pmi-nav-spin {
        animation: none;
        border-top-color: rgba(255, 255, 255, .2);
    }
}

/* ============================================================
   Desktop : cadre phone centré
   ============================================================ */
@media (min-width: 1024px) {
    body[class*="pmi-screen-"] {
        background:
            radial-gradient(1200px 600px at 50% -10%, #1a1a1a 0%, #050505 60%) fixed,
            #050505;
    }

    body[class*="pmi-screen-"] #pmi-app {
        width: min(430px, 100%);
        min-height: 0;
        height: min(900px, calc(100dvh - 40px));
        margin: 20px auto;
        border-radius: 34px;
        overflow: hidden;
        isolation: isolate;
        border: 1px solid #2b2b2b;
        box-shadow:
            0 40px 100px rgba(0, 0, 0, .7),
            0 0 0 8px #0d0d0d;
    }

    /* Les écrans 100vh se calent sur le cadre, pas le viewport */
    body[class*="pmi-screen-"] #pmi-app section.bandeau,
    body[class*="pmi-screen-"] #pmi-app .video-slider-container {
        height: 100% !important;
        max-width: none !important;
    }
    body[class*="pmi-screen-"] #pmi-app .video-viewport {
        height: 100%;
    }

    /* Le plateau memory (fixed) devient absolu dans le cadre */
    body[class*="pmi-screen-"] #pmi-app .grid {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        max-width: none;
        height: 100%;
    }

    /* Modales + toasts : cantonnés au cadre, pas au viewport */
    body[class*="pmi-screen-"] #pmi-app .token-modal,
    body[class*="pmi-screen-"] #pmi-app #toast-container {
        position: absolute;
    }
}

/* Petit desktop / paysage court : le cadre prend tout l'écran */
@media (min-width: 1024px) and (max-height: 500px) {
    body[class*="pmi-screen-"] #pmi-app {
        height: 100dvh;
        margin: 0 auto;
        border-radius: 0;
        border: 0;
        box-shadow: none;
    }
}
