/* ========================================================================== */
/* --- MODULE RESPONSIVE SMARTPHONE (LIVING TALES TOGETHER) ---              */
/* Ciblage strict des écrans tactiles et smartphones (<= 820px)              */
/* ========================================================================== */

/* Par défaut sur écran de bureau (> 820px) : les éléments mobiles sont masqués */
.mobile-drawer-tab,
.mobile-drawer-header,
.mobile-drawer-backdrop,
.mobile-only {
    display: none !important;
}

@media (max-width: 820px) {
    /* --- 1. AFFICHAGE DES COMPOSANTS MOBILES DÉDIÉS --- */
    .mobile-only {
        display: block !important;
    }

    /* --- 2. GESTION DU HEADER EN JEU (MASQUAGE) --- */
    body.mobile-game-active .app-header,
    body:has(#gameScreen:not(.hidden)) .app-header {
        display: none !important;
    }

    /* --- 3. STRUCTURE DE L'ÉCRAN DE JEU (PLEINE LARGEUR & 100DVH) --- */
    #gameScreen {
        width: 100% !important;
        max-width: 100% !important;
        min-height: 100dvh;
        min-height: 100vh;
        padding: 8px 10px 50px 10px !important;
        margin: 0 auto !important;
        box-sizing: border-box !important;
        overflow-x: hidden;
    }

    .main-layout {
        display: block !important;
        grid-template-columns: none !important;
        grid-template-rows: none !important;
        gap: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        padding: 0 !important;
        margin: 0 !important;
        box-sizing: border-box !important;
    }

    .game-section {
        display: block !important;
        width: 100% !important;
        max-width: 100% !important;
        padding: 0 !important;
        margin: 0 !important;
        box-sizing: border-box !important;
    }

    .game-grid {
        display: block !important;
        grid-template-columns: none !important;
        grid-template-rows: none !important;
        gap: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        box-sizing: border-box !important;
    }

    /* --- 4. BARRE D'ACCÈS RAPIDE COMPACTE (CODEX & CARTE DU MONDE) --- */
    .game-nav-bar {
        display: flex !important;
        justify-content: center;
        gap: 12px;
        margin: 4px auto 14px auto !important;
        padding: 0 4px !important;
        width: 100% !important;
        max-width: 440px !important;
        box-sizing: border-box;
    }

    .game-nav-bar .btn-nav {
        flex: 1;
        padding: 10px 14px !important;
        font-size: 0.92em !important;
        font-weight: 700 !important;
        border-radius: 8px !important;
        background: rgba(22, 33, 62, 0.9) !important;
        border: 1px solid rgba(78, 204, 163, 0.45) !important;
        color: #4ecca3 !important;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
        cursor: pointer;
        transition: all 0.2s ease;
        touch-action: manipulation;
    }

    .game-nav-bar .btn-nav:active {
        transform: scale(0.97);
        background: #4ecca3 !important;
        color: #0d121f !important;
    }

    /* Menu Paramètres discret en haut à droite */
    .settings-menu-container {
        position: fixed !important;
        top: 10px !important;
        right: 12px !important;
        z-index: 920;
    }

    /* --- 5. NARRATION CENTRALE PLEIN ÉCRAN (LE RÉCIT D'ABORD) --- */
    .ia-response-section {
        display: block !important;
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        margin: 0 auto !important;
        padding: 14px 10px !important;
        box-sizing: border-box !important;
        float: none !important;
        flex: 1 1 100% !important;
    }

    .ia-response-section * {
        box-sizing: border-box !important;
    }

    #iaOutput {
        font-size: 1.05em !important;
        line-height: 1.65 !important;
        padding: 16px 14px !important;
        border-radius: 10px !important;
        word-break: break-word;
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    #privateOutput {
        font-size: 0.98em !important;
        line-height: 1.6 !important;
        padding: 16px 14px !important;
        margin-top: 16px !important;
        border-radius: 10px !important;
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    /* --- 6. LANGUETTES FLOTTANTES ERGONOMIQUES (À GAUCHE ET À DROITE) --- */
    .mobile-drawer-tab {
        display: flex !important;
        align-items: center;
        justify-content: center;
        gap: 6px;
        position: fixed;
        top: 75px;
        z-index: 999;
        padding: 10px 14px;
        background: rgba(13, 22, 38, 0.95);
        border: 2px solid #4ecca3;
        color: #4ecca3;
        font-size: 1.05em;
        font-weight: 700;
        cursor: pointer;
        touch-action: manipulation;
        user-select: none;
        transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
        backdrop-filter: blur(10px);
    }

    .mobile-tab-left {
        left: 0;
        border-left: none;
        border-radius: 0 20px 20px 0;
        box-shadow: 3px 3px 16px rgba(78, 204, 163, 0.4);
    }

    .mobile-tab-right {
        right: 0;
        border-right: none;
        border-radius: 20px 0 0 20px;
        box-shadow: -3px 3px 16px rgba(78, 204, 163, 0.4);
    }

    .mobile-drawer-tab:active,
    .mobile-drawer-tab.active {
        background: #4ecca3 !important;
        color: #0d121f !important;
        box-shadow: 0 0 20px rgba(78, 204, 163, 0.85) !important;
    }

    .mobile-drawer-tab .tab-icon {
        font-size: 1.2em;
        line-height: 1;
    }

    .mobile-drawer-tab .tab-arrow {
        font-size: 0.9em;
        line-height: 1;
        transition: transform 0.25s ease;
    }

    /* --- 7. VOLET GAUCHE (SIDEBAR : CONTEXTE, PNJS, COMPAGNONS & INVENTAIRE) --- */
    .sidebar {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        width: 100% !important;
        height: 100dvh !important;
        height: 100vh;
        max-height: 100dvh !important;
        background: #0f172a !important;
        z-index: 990 !important;
        transform: translateX(-100%);
        transition: transform 0.32s cubic-bezier(0.16, 1, 0.3, 1);
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        padding: 16px 14px 80px 14px !important;
        box-sizing: border-box !important;
        border-right: 2px solid #4ecca3 !important;
        box-shadow: 6px 0 30px rgba(0, 0, 0, 0.85) !important;
    }

    .sidebar.drawer-open-mobile {
        transform: translateX(0) !important;
    }

    /* --- 8. VOLET DROIT (PLAYER-CONTROLS-SECTION : ACTIONS & VALIDATION) --- */
    .player-controls-section {
        position: fixed !important;
        top: 0 !important;
        right: 0 !important;
        width: 100% !important;
        height: 100dvh !important;
        height: 100vh;
        max-height: 100dvh !important;
        background: #0f172a !important;
        z-index: 990 !important;
        transform: translateX(100%);
        transition: transform 0.32s cubic-bezier(0.16, 1, 0.3, 1);
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        padding: 16px 14px 80px 14px !important;
        box-sizing: border-box !important;
        border-left: 2px solid #4ecca3 !important;
        box-shadow: -6px 0 30px rgba(0, 0, 0, 0.85) !important;
    }

    .player-controls-section.drawer-open-mobile {
        transform: translateX(0) !important;
    }

    /* --- 9. EN-TÊTE SUPÉRIEUR DANS CHAQUE VOLET (TITRE + BOUTON FERMER) --- */
    .mobile-drawer-header {
        display: flex !important;
        justify-content: space-between;
        align-items: center;
        padding-bottom: 12px;
        margin-bottom: 16px;
        border-bottom: 1px solid rgba(78, 204, 163, 0.3);
    }

    .mobile-drawer-header h3 {
        margin: 0;
        color: #4ecca3;
        font-size: 1.2em;
        display: flex;
        align-items: center;
        gap: 8px;
    }

    .mobile-drawer-close-btn {
        background: rgba(233, 69, 96, 0.15);
        border: 1px solid #e94560;
        color: #ff6b81;
        padding: 6px 12px;
        border-radius: 6px;
        font-size: 0.88em;
        font-weight: 700;
        cursor: pointer;
        touch-action: manipulation;
        transition: all 0.2s ease;
    }

    .mobile-drawer-close-btn:active {
        background: #e94560;
        color: #ffffff;
    }

    /* --- 10. FOND DE VOILE D'ASSOMBRISSEMENT (BACKDROP) --- */
    .mobile-drawer-backdrop {
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100dvh;
        height: 100vh;
        background: rgba(0, 0, 0, 0.65);
        backdrop-filter: blur(4px);
        z-index: 985;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
    }

    .mobile-drawer-backdrop.active {
        display: block !important;
        opacity: 1;
        pointer-events: auto;
    }

    /* --- 11. INVENTAIRE TACTILE (TAP-TO-MOVE) --- */
    .inventory-card {
        touch-action: manipulation;
        cursor: pointer;
        transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
    }

    /* Carte sélectionnée prête au transfert */
    .inventory-card.mobile-item-selected {
        outline: 2px solid #4ecca3 !important;
        background: rgba(78, 204, 163, 0.3) !important;
        box-shadow: 0 0 14px rgba(78, 204, 163, 0.85) !important;
        transform: scale(1.04);
        border-color: #4ecca3 !important;
    }

    /* Zone réceptrice disponible illuminée */
    .inventory-zone.mobile-zone-target {
        border-color: #4ecca3 !important;
        background: rgba(78, 204, 163, 0.12) !important;
        box-shadow: inset 0 0 12px rgba(78, 204, 163, 0.35) !important;
        animation: pulseZoneTarget 1.4s infinite ease-in-out;
        cursor: pointer;
    }

    @keyframes pulseZoneTarget {
        0%, 100% {
            border-color: rgba(78, 204, 163, 0.4);
            box-shadow: inset 0 0 8px rgba(78, 204, 163, 0.2);
        }
        50% {
            border-color: rgba(78, 204, 163, 1);
            box-shadow: inset 0 0 16px rgba(78, 204, 163, 0.5);
        }
    }

    /* Secousse visuelle en cas de zone pleine */
    .inventory-zone.mobile-zone-full-shake {
        animation: shakeZone 0.35s ease-in-out;
        border-color: #e94560 !important;
    }

    @keyframes shakeZone {
        0%, 100% { transform: translateX(0); }
        20%, 60% { transform: translateX(-5px); }
        40%, 80% { transform: translateX(5px); }
    }

    /* --- 12. ADAPTATION TACTILE DES ACTIONS & DU BOUTON PRÊT --- */
    .input-group textarea {
        font-size: 16px !important; /* Empêche le zoom automatique forcé sur iOS Safari */
    }

    .ready-check-container button {
        padding: 14px !important;
        font-size: 1.1em !important;
        touch-action: manipulation;
    }

    /* --- 13. ADAPTATION DES MODALES PLEIN ÉCRAN (CODEX & CARTE) --- */
    .modal-content.codex-modal,
    .modal-content.map-modal {
        width: 96% !important;
        max-width: 96% !important;
        height: 90dvh !important;
        max-height: 90dvh !important;
        margin: 5dvh auto !important;
        padding: 16px !important;
        box-sizing: border-box !important;
    }

    /* --- 14. LISTE DES AVENTURES DANS LE HUB (EXPANSION NATURELLE SANS SCROLL INTERNE) --- */
    #myAdventuresPanel {
        min-width: 100% !important;
        width: 100% !important;
        padding: 16px 14px !important;
        box-sizing: border-box !important;
    }

    #myGamesList {
        max-height: none !important;
        overflow: visible !important;
        width: 100% !important;
    }

    /* --- 15. ADAPTATION DE LA SÉLECTION / CRÉATION DE HÉROS (#charSelectionScreen) --- */
    #charSelectionScreen {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        padding: 10px 8px 30px 8px !important;
    }

    #charSelectionScreen .room-banner-bar {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 10px !important;
        padding: 12px 14px !important;
        border-radius: 10px !important;
    }

    #charSelectionScreen .room-banner-bar > div {
        display: flex !important;
        flex-wrap: wrap !important;
        justify-content: space-between !important;
        align-items: center !important;
        gap: 8px !important;
        width: 100% !important;
    }

    #charSelectionScreen .room-banner-bar button {
        flex: 1 1 auto !important;
        text-align: center !important;
        padding: 8px 10px !important;
        font-size: 0.85em !important;
    }

    .char-tabs-wrapper {
        width: 100% !important;
        margin-bottom: 14px !important;
    }

    .char-mode-tabs {
        width: 100% !important;
        gap: 4px !important;
    }

    .char-tab-btn {
        flex: 1 1 50% !important;
        min-width: 0 !important;
        padding: 11px 6px !important;
        font-size: 0.85em !important;
        text-align: center !important;
        justify-content: center !important;
        gap: 6px !important;
        white-space: normal !important;
    }

    .char-tab-btn .char-tab-text {
        font-size: 0.9em !important;
        line-height: 1.2 !important;
    }

    .char-selection-layout {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
    }

    .char-new, .char-existing {
        padding: 18px 14px !important;
        border-radius: 12px !important;
        min-height: auto !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    .char-new h2, .char-existing h2 {
        font-size: 1.25em !important;
        padding-bottom: 10px !important;
        margin-bottom: 14px !important;
    }

    .char-new .input-group input {
        font-size: 16px !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    .char-new .twitch-char-toggle-container {
        padding: 10px 12px !important;
        margin-bottom: 14px !important;
    }

    .char-new #twitchChannelInput {
        font-size: 16px !important;
    }

    .char-btn-group {
        flex-direction: column !important;
        gap: 10px !important;
    }

    .char-btn-group #createNewCharBtn,
    .char-btn-group #loadCharBtn {
        width: 100% !important;
        flex: none !important;
        padding: 12px !important;
        font-size: 1em !important;
    }

    .char-list {
        margin-top: 15px !important;
        gap: 10px !important;
    }

    .char-item {
        padding: 14px 12px !important;
        border-radius: 10px !important;
        box-sizing: border-box !important;
    }

    .char-item h4 {
        font-size: 1.05em !important;
        padding-right: 32px !important;
    }

    .char-stats-preview {
        flex-wrap: wrap !important;
        gap: 8px !important;
        font-size: 0.8em !important;
    }

    .delete-char-btn {
        width: 32px !important;
        height: 32px !important;
        font-size: 1.3em !important;
        line-height: 28px !important;
        top: 6px !important;
        right: 6px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        touch-action: manipulation !important;
    }

    #backToHubFromCharBtn {
        width: 100% !important;
        max-width: 320px !important;
        padding: 12px 20px !important;
        box-sizing: border-box !important;
    }
}

