/* NightVenture — correctifs runtime Phaser persistants et contrôles tactiles. */

/* Le HUD legacy peut masquer #navigationPrincipale après avoir déplacé la barre.
   Ces sélecteurs plus précis maintiennent toujours le conteneur disponible. */
html body.nv-mode-playing.nv-phaser-persistent-active
#appShell
#navigationPrincipale.nv-hud-sidebar-disabled,
html body.nv-phaser-persistent-active
#appShell
#navigationPrincipale {
    display: block !important;
    position: fixed !important;
    inset: auto 0 0 0 !important;
    z-index: 3100 !important;
    width: 100vw !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    pointer-events: none !important;
    transform: none !important;
}

/* La barre reste en bas même lorsque HUD_Layout.js la déplace dans le header. */
html body.nv-mode-playing.nv-phaser-persistent-active
#barreVuePrincipale,
html body.nv-phaser-persistent-active
#barreVuePrincipale.nv-hud-navigation {
    position: fixed !important;
    top: auto !important;
    right: auto !important;
    bottom: env(safe-area-inset-bottom) !important;
    left: 50% !important;
    z-index: 3101 !important;
    display: flex !important;
    flex-flow: row nowrap !important;
    align-items: center !important;
    justify-content: flex-start !important;
    gap: 6px !important;
    width: max-content !important;
    max-width: calc(100vw - 12px) !important;
    min-height: 38px !important;
    margin: 0 !important;
    padding: 6px 8px !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    border: 1px solid rgba(143, 211, 255, 0.22) !important;
    border-bottom: 0 !important;
    border-radius: 14px 14px 0 0 !important;
    background: rgba(5, 13, 25, 0.94) !important;
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.36) !important;
    pointer-events: auto !important;
    transform: translateX(-50%) !important;
    scrollbar-width: thin;
}

/* Une fois détachée du header, la navigation devient un enfant direct du body.
   On neutralise ici toute visibilité héritée de l'ancien HUD. */
html body.nv-phaser-persistent-active > #barreVuePrincipale.nv-phaser-navigation-docked {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    clip: auto !important;
    contain: none !important;
    isolation: isolate !important;
}

html body.nv-phaser-persistent-active #barreVuePrincipale button {
    flex: 0 0 auto !important;
    width: auto !important;
    min-width: max-content !important;
    white-space: nowrap !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* Contrôles mobiles Phaser. */
.nv-phaser-mobile-controls {
    position: fixed;
    inset: 0;
    z-index: 3050;
    display: none;
    pointer-events: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

.nv-phaser-mobile-controls__joystick {
    position: absolute;
    left: max(16px, env(safe-area-inset-left));
    bottom: calc(66px + env(safe-area-inset-bottom));
    width: 124px;
    height: 124px;
    border: 1px solid rgba(143, 211, 255, 0.34);
    border-radius: 50%;
    background: radial-gradient(circle, rgba(19, 56, 91, 0.50), rgba(5, 18, 34, 0.72));
    box-shadow: inset 0 0 24px rgba(72, 155, 214, 0.14), 0 8px 28px rgba(0, 0, 0, 0.30);
    backdrop-filter: blur(4px);
    pointer-events: auto;
    touch-action: none;
}

.nv-phaser-mobile-controls__knob {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 50px;
    height: 50px;
    border: 1px solid rgba(143, 211, 255, 0.72);
    border-radius: 50%;
    background: rgba(10, 38, 66, 0.94);
    box-shadow: 0 0 18px rgba(72, 173, 238, 0.25);
    transform: translate(-50%, -50%);
    pointer-events: none;
}

.nv-phaser-mobile-controls__actions {
    position: absolute;
    right: max(16px, env(safe-area-inset-right));
    bottom: calc(68px + env(safe-area-inset-bottom));
    display: grid;
    grid-template-columns: repeat(2, auto);
    gap: 10px;
    align-items: end;
    justify-items: end;
    pointer-events: none;
}

.nv-phaser-mobile-controls__button {
    display: grid !important;
    place-items: center !important;
    width: 58px !important;
    min-width: 58px !important;
    height: 58px !important;
    min-height: 58px !important;
    padding: 0 !important;
    border: 1px solid rgba(143, 211, 255, 0.48) !important;
    border-radius: 50% !important;
    background: rgba(7, 29, 52, 0.90) !important;
    color: #9edcff !important;
    font-size: 0.67rem !important;
    font-weight: 800 !important;
    line-height: 1 !important;
    text-align: center !important;
    box-shadow: 0 7px 22px rgba(0, 0, 0, 0.30) !important;
    pointer-events: auto;
    touch-action: none;
}

.nv-phaser-mobile-controls__button.is-held {
    border-color: #d7f1ff !important;
    background: rgba(21, 76, 118, 0.96) !important;
    color: #ffffff !important;
    transform: scale(0.94);
}

.nv-phaser-mobile-controls__button--jump {
    grid-row: 1 / span 2;
    width: 72px !important;
    min-width: 72px !important;
    height: 72px !important;
    min-height: 72px !important;
}

body.nv-phaser-overlay-open .nv-phaser-mobile-controls,
body.nv-phaser-manual-paused .nv-phaser-mobile-controls {
    opacity: 0.18;
    pointer-events: none;
}

body.nv-phaser-overlay-open .nv-phaser-mobile-controls *,
body.nv-phaser-manual-paused .nv-phaser-mobile-controls * {
    pointer-events: none !important;
}

@media (hover: none) and (pointer: coarse), (max-width: 760px) {
    body.nv-phaser-persistent-active .nv-phaser-mobile-controls {
        display: block;
    }
}

@media (max-width: 430px) {
    .nv-phaser-mobile-controls__joystick {
        left: 10px;
        width: 112px;
        height: 112px;
    }

    .nv-phaser-mobile-controls__actions {
        right: 10px;
        gap: 7px;
    }

    .nv-phaser-mobile-controls__button {
        width: 52px !important;
        min-width: 52px !important;
        height: 52px !important;
        min-height: 52px !important;
    }

    .nv-phaser-mobile-controls__button--jump {
        width: 64px !important;
        min-width: 64px !important;
        height: 64px !important;
        min-height: 64px !important;
    }
}
