/* =========================================
   1. CONFIGURATION DE BASE (MOBILE FIRST)
   ========================================= */
body { 
    margin: 0; 
    padding: 0;
    overflow: hidden; /* INTERDIT LE SCROLL */
    background-color: #000; 
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; 
    user-select: none; 
    -webkit-user-select: none;
    touch-action: none; /* Bloque les gestes par défaut du navigateur */
    
    /* Force le plein écran fixe */
    position: fixed;
    width: 100%;
    height: 100%;
}

#game-container { 
    position: absolute; 
    top: 0; left: 0; 
    width: 100%; height: 100%; 
}

/* Zone invisible qui capture le doigt pour tourner la caméra */
#camera-touch-zone {
    position: absolute; 
    top: 0; left: 0; 
    width: 100%; height: 100%;
    z-index: 10; /* Au-dessus du jeu, mais en dessous de l'interface */
    touch-action: none; /* Indispensable pour éviter le scroll */
}

/* --- HUD UI (Couche globale) --- */
#ui-layer { 
    position: absolute; top: 0; left: 0; width: 100%; height: 100%; 
    pointer-events: none;
    z-index: 20;

    /* GESTION DES ZONES SÛRES (Encoches & Coins arrondis) */
    /* Cela crée un padding invisible qui repousse les boutons vers l'intérieur */
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    box-sizing: border-box; /* Important pour que le padding ne dépasse pas 100% */
}

/* Réactive les clics sur les éléments interactifs */
.stat-box, button, .btn-tool, .btn-action, #mobile-menu-btn, #joystick-zone {
    pointer-events: auto;
}

/* =========================================
   2. HUD - BARRE DU HAUT
   ========================================= */
#top-bar { 
    position: absolute; top: 10px; left: 10px; right: 10px; 
    display: flex; gap: 15px;
    color: white; font-weight: bold; font-size: 18px; 
    text-shadow: 2px 2px 0 #000;
    z-index: 30;
}

.stat-box {
    background: rgba(20, 20, 20, 0.9); /* Fond sombre opaque */
    padding: 8px 15px;
    border-radius: 20px;
    border: 2px solid #666;
    display: flex; align-items: center; gap: 8px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.5);
}

/* Bouton Vague (Flottant en haut) */
#btn-wave {
    background-color: #2196F3;
    border: 2px solid #fff;
    border-radius: 20px;
    padding: 10px 20px;
    font-size: 16px; font-weight: bold; color: white;
    box-shadow: 0 4px 0 #0d47a1;
    cursor: pointer;
    transition: transform 0.1s;
}
#btn-wave:active { transform: translateY(4px); box-shadow: 0 0 0; }

/* =========================================
   3. BARRE D'OUTILS (TOOLBAR) - DESIGN GÉNÉRAL
   ========================================= */
#toolbar {
    /* Style commun (Fond, bordures) */
    background: rgba(15, 15, 15, 0.95); /* Quasi noir opaque */
    border: 2px solid #555;
    border-radius: 12px;
    padding: 10px;
    
    /* Flexbox par défaut */
    display: flex; gap: 10px;
    pointer-events: auto;
    z-index: 50; /* Au-dessus du jeu */
}

/* --- STYLE DES BOUTONS --- */
.btn-tool {
    position: relative; 
    width: 75px; height: 85px;
    background-color: #2a2a2a; /* Gris foncé lisible */
    border: 2px solid #666; 
    border-radius: 8px; 
    color: white;
    cursor: pointer;
    
    display: flex; flex-direction: column; 
    align-items: center; justify-content: center;
    
    box-shadow: 0 4px 6px rgba(0,0,0,0.5);
    transition: transform 0.1s, background 0.2s;
}

.btn-tool:active { transform: scale(0.95); border-color: white; }
.btn-tool:hover { background-color: #444; }

.btn-tool .icon { font-size: 28px; margin-bottom: 5px; filter: drop-shadow(0 2px 2px black); }
.btn-tool .name { font-size: 11px; font-weight: 800; text-transform: uppercase; text-shadow: 1px 1px 0 black; }
.btn-tool .cost { font-size: 12px; color: #ffd700; font-weight: bold; margin-top: 2px; text-shadow: 1px 1px 0 black; }

/* Indicateurs de touches (1, 2, 3...) - Style Cyan */
.key-hint {
    position: absolute;
    top: -8px; left: -8px;
    width: 22px; height: 22px;
    
    background-color: #00ffff; /* Cyan Flashy */
    color: #000; font-weight: 900; font-size: 12px; font-family: monospace;
    
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%;
    border: 2px solid white;
    z-index: 10;
    box-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

/* =========================================
   4. VERSION PC (DESKTOP)
   ========================================= */
/* Si ce n'est PAS un mobile */
body:not(.is-mobile) #toolbar {
    position: absolute; 
    bottom: 20px;
    left: 50%; transform: translateX(-50%); /* Centrage parfait */
    
    /* --- PARAMÈTRES DE LARGEUR --- */
    width: fit-content;    /* La largeur s'adapte exactement au contenu */
    min-width: 60%;        /* Prend au minimum 60% de l'écran (esthétique) */
    max-width: 98%;        /* Ne touche jamais les bords de l'écran */
    
    flex-wrap: nowrap;     /* OBLIGE tout le monde à rester sur une seule ligne */
    justify-content: center;
    white-space: nowrap;
}

/* Cache le bouton burger sur PC */
body:not(.is-mobile) #mobile-menu-btn { display: none; }

/* =========================================
   5. VERSION MOBILE (SPÉCIFIQUE)
   ========================================= */
body.is-mobile #toolbar {
    /* Positionnement TIROIR (Drawer) */
    position: absolute;
    bottom: 0; left: 0;
    width: 100%; height: auto;
    
    /* Design Overlay */
    background: rgba(10, 10, 10, 0.98); /* Fond quasi noir total */
    border: none;
    border-top: 4px solid #ffd700; /* Ligne Or en haut */
    border-radius: 20px 20px 0 0;
    padding: 20px 10px 40px 10px; /* Padding bas pour iPhone X+ */
    
    /* Grille de boutons */
    display: grid;
    grid-template-columns: repeat(4, 1fr); /* 4 colonnes */
    gap: 12px;
    
    /* LOGIQUE D'ANIMATION (Caché par défaut) */
    transform: translateY(120%); /* Poussé vers le bas hors écran */
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    
    z-index: 200; /* TRES IMPORTANT : Au-dessus du Joystick (100) */
}

/* Classe ajoutée par JS pour ouvrir le menu */
body.is-mobile #toolbar.show {
    transform: translateY(0%); /* Revient à sa place */
}

/* Boutons adaptés au mobile (plus plats) */
body.is-mobile .btn-tool {
    width: 100%; height: 70px;
}

/* On cache les hints clavier sur mobile */
body.is-mobile .key-hint { display: none !important; }
body.is-mobile .hide-mobile { display: none !important; }

/* BOUTON BURGER (Ouvrir Menu) */
#mobile-menu-btn {
    display: none; /* Caché par défaut */
}
body.is-mobile #mobile-menu-btn {
    display: flex;
    position: absolute; top: 15px; right: 15px;
    width: 50px; height: 50px;
    
    background: #2196F3;
    border: 3px solid white;
    border-radius: 12px;
    color: white; font-size: 28px;
    
    align-items: center; justify-content: center;
    box-shadow: 0 4px 0 #0d47a1;
    z-index: 50;
}
body.is-mobile #mobile-menu-btn:active { transform: translateY(2px); box-shadow: 0 0 0; }

/* Ecran de défaite compact */
#gameover-screen h1 {
    font-size: 3em; /* Un peu plus petit */
    margin-top: 0;
    margin-bottom: 10px;
}
#gameover-screen p {
    font-size: 1.2em;
    margin-bottom: 20px;
}
#gameover-screen button {
    /* On s'assure qu'il est accessible */
    margin-bottom: 20px;
    padding: 12px 30px;
}

/* =========================================
   6. ACTIONS FLOTTANTES (Couper/Grimper)
   ========================================= */
#context-buttons {
    position: absolute; 
    bottom: 50px; 
    right: 20px;
    display: flex; flex-direction: column; gap: 15px;
    z-index: 40;
}

.btn-action {
    width: 80px; height: 80px;
    border-radius: 50%;
    background: rgba(200, 40, 40, 0.9); /* Rouge Opaque */
    border: 3px solid white;
    color: white; font-weight: bold;
    
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    
    box-shadow: 0 4px 10px rgba(0,0,0,0.6);
}

.btn-action .emoji-icon { font-size: 26px; margin-bottom: 2px; }
.btn-action .text-label { font-size: 11px; text-transform: uppercase; }

/* =========================================
   7. JOYSTICK & SYSTÈME
   ========================================= */
#joystick-zone {
    position: absolute; bottom: 50px; left: 50px;
    width: 140px; height: 140px;
    background: rgba(255, 255, 255, 0.15); 
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-radius: 50%;
    display: none; /* Caché sur PC */
    align-items: center; justify-content: center;
    z-index: 100; /* En dessous du menu ouvert (200) */
}
body.is-mobile #joystick-zone { display: flex; }

#joystick-knob {
    width: 60px; height: 60px;
    background: rgba(255, 215, 0, 0.6);
    border-radius: 50%;
    pointer-events: none;
}

#system-msg {
    position: absolute; top: 30%; width: 100%; text-align: center;
    font-size: 40px; color: #ffd700; font-weight: bold;
    text-shadow: 0 0 10px black; pointer-events: none;
    opacity: 0; transition: opacity 0.5s;
    z-index: 1000;
}

/* =========================================
   8. AJUSTEMENTS WEB MOBILE (Barre URL)
   ========================================= */
/* Si on est sur un navigateur mobile (avec barre d'adresse en bas) */
body.is-mobile.is-web #joystick-zone {
    bottom: 80px; /* On remonte le joystick */
}

body.is-mobile.is-web #context-buttons {
    bottom: 120px; /* On remonte les boutons d'action */
}

/* --- ECRAN "TOURNEZ VOTRE APPAREIL" --- */
#rotate-screen-msg {
    display: none; /* Caché par défaut (si on est sur PC ou déjà en paysage) */
}

/* Si l'écran est plus haut que large (Portrait) ET que c'est un mobile */
@media screen and (orientation: portrait) and (max-width: 900px) {
    #rotate-screen-msg {
        display: flex;
        flex-direction: column;
        align-items: center; justify-content: center;
        position: fixed; top: 0; left: 0; width: 100%; height: 100%;
        background: #000;
        color: white; z-index: 9999;
        text-align: center;
        font-family: sans-serif;
    }
    
    /* On cache le jeu derrière pour éviter les bugs visuels */
    #game-container { display: none; }
}