body {
    font-family: 'Georgia', serif;
    background-color: #26170b;
    color: #f3e5ab;
    margin: 0;
    padding: 10px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100vw;
    overflow-x: hidden; /* Empêche le corps de la page de trembler */
}

h1 { margin: 0 0 4px 0; font-size: 1.6rem; color: #f1c40f; text-shadow: 2px 2px #000; text-align: center; }
h2 { margin: 0 0 15px 0; font-size: 1rem; color: #e67e22; font-weight: normal; text-align: center; }

/* LAYOUT PRINCIPAL */
#main-layout {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    width: 100%;
    max-width: 100vw;
    margin: 0 auto;
    box-sizing: border-box;
}

#game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 100vw;
    height: auto !important; /* Laisse le conteneur grandir selon la carte */
    box-sizing: border-box;
    position: relative;
    padding-bottom: 180px; /* Espace en bas pour que le panneau d'interface (#ui) ne recouvre pas le bas de la carte */
}

/* --- ZONE DE SCROLL POUR LA CARTE --- */
#grid-container {
    overflow-x: auto !important; /* Défilement horizontal uniquement si la carte est plus large que l'écran */
    overflow-y: visible !important; /* Laisse la carte s'afficher sur toute sa hauteur sans barre de défilement verticale */
    width: 100%;
    max-width: 100vw;
    max-height: none !important; /* Supprime la limite de hauteur */
    height: auto !important; /* S'adapte à la hauteur réelle de la grille */
    display: block;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x pan-y;
    box-sizing: border-box;
    padding: 0 10px;
    position: relative;
}

#grid {
    display: grid;
    gap: 0px;
    background: #271403;
    border: 1px solid #271403;
    position: relative; 
    margin: 0;
    z-index: 1;
    width: max-content;
}

/* --- WRAPPER --- */
#map-wrapper {
    position: relative;
    margin: 0 auto;
    width: max-content;
    padding-bottom: 20px !important; /* Espace réservé pour ne jamais masquer le bas de la grille sous le panneau UI */
}

#connections-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 5;
    background: transparent !important;
    pointer-events: none;
}

.cell {
    position: relative;
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    box-sizing: border-box;
    border: 1px solid rgba(39, 20, 3, 0.4);
    z-index: 1;
}
.cell:hover { filter: brightness(1.15); }

.cell.tower-cell {
    background: transparent !important;
    border: none !important;
}

.cell.wall { border: 1px solid #111; cursor: not-allowed; }
.cell.obstacle { cursor: not-allowed; border: 1px solid rgba(0, 0, 0, 0.3); }

.cell.tower-cell,
.cell.tower-cell-wall,
.tower-cell,
.tower-cell-wall {
    background-color: transparent !important;
}

.tower-content {
    position: relative;
    z-index: 10;
    font-size: 13px;
    line-height: 1;
}

.range-indicator {
    position: absolute;
    border-radius: 50%;
    background: rgba(231, 76, 60, 0.25);
    border: 2px dashed #e74c3c;
    pointer-events: none;
    z-index: 20;
    transform: translate(-50%, -50%);
    box-sizing: border-box;
    display: none;
}

.enemy-wrapper {
    position: absolute;
    width: var(--cell-size, 30px);
    height: var(--cell-size, 30px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    transition: left 0.15s linear, top 0.15s linear;
    z-index: 10;
}

.enemy-sprite {
    font-size: 20px;
    line-height: 1;
}

.hp-bar-bg {
    position: absolute;
    top: -6px;
    width: 18px;
    height: 3px;
    background-color: #c0392b;
    border: 1px solid #000;
    border-radius: 2px;
    overflow: hidden;
}

.hp-bar-fill {
    height: 100%;
    background-color: #2ecc71;
    width: 100%;
}

.projectile {
    position: absolute;
    font-size: 11px;
    z-index: 15;
    pointer-events: none;
    transition: all 0.2s linear;
}

.damage-pop {
    position: absolute;
    color: #ff3333;
    font-weight: bold;
    font-size: 10px;
    z-index: 20;
    pointer-events: none;
    text-shadow: 1px 1px #000;
    animation: floatUp 0.6s ease-out forwards;
}

.aoe-effect {
    position: absolute;
    border-radius: 50%;
    background: rgba(231, 76, 60, 0.4);
    border: 2px solid #e74c3c;
    z-index: 12;
    pointer-events: none;
    animation: expandAoe 0.4s ease-out forwards;
}

@keyframes floatUp {
    0% { opacity: 1; transform: translateY(0); }
    100% { opacity: 0; transform: translateY(-15px); }
}

@keyframes expandAoe {
    0% { transform: scale(0.2); opacity: 0.9; }
    100% { transform: scale(1.2); opacity: 0; }
}

/* --- INTERFACE UTILISATEUR (#UI) - VERSION GLOBALE PC --- */
#ui {
    position: fixed !important;
    bottom: 0 !important;
    left: 50% !important;
    /* Plus de transform fixe ici pour laisser la main au mobile */
    transform: translateX(-50%) !important;
    width: 100%;
    max-width: 800px;
    box-sizing: border-box;
    background: #321e0f;
    padding: 12px;
    border-radius: 8px 8px 0 0;
    border: 2px solid #5a3d28;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    box-shadow: 0 -4px 12px rgba(0,0,0,0.6);
    z-index: 9999 !important;
}

#stats-panel {
    grid-column: 1 / -1;
    background: #1a1006;
    padding: 6px 12px;
    border-radius: 5px;
    border: 1px solid #5a3d28;
    font-size: 1.5rem; /* taille bouton */
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.stats-items { display: flex; align-items: center; gap: 12px; white-space: nowrap; }
#stats-panel .separator { color: #5a3d28; font-weight: bold; }

.controls-group {
    display: flex;
    gap: 6px;
}

#start-btn, #pause-btn, #doc-btn {
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    font-size: 1.5rem; /* tailel botons tart pause */
    font-family: 'Georgia', serif;
    white-space: nowrap;
    padding: 6px 10px;
    color: white;
}

#start-btn { background-color: #229954; border: 1px solid #1e8449; }
#start-btn:hover:not(:disabled) { background-color: #27ae60; }
#start-btn:disabled { background-color: #555; cursor: not-allowed; border-color: #333; }

#pause-btn { background-color: #d35400; border: 1px solid #a04000; }
#pause-btn:hover { background-color: #e67e22; }

#doc-btn { background-color: #2980b9; border: 1px solid #1b4f72; }
#doc-btn:hover { background-color: #3498db; }

.tower-buttons-group {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
}

.tower-btn, .action-btn {
    background-color: #b9770e;
    border: 2px solid #784212;
    color: white;
    padding: 8px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    font-family: 'Georgia', serif;
    font-size: 1.5rem; /* taille de la police dans le pannel de ocntrole */
    width: 100%;
    box-sizing: border-box;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 6px;
}

.tower-cost {
    background: rgba(0, 0, 0, 0.35);
    padding: 2px 6px;
    border-radius: 4px;
font-size: 1.3rem; /* <--- Augmentez cette valeur (ex: 1.1rem ou 1.2rem) pour grossir le texte et l'icône de l'or */
    color: #f1c40f;
    border: 1px solid rgba(241, 196, 15, 0.3);
}

.tower-btn:hover:not(:disabled), .action-btn:hover:not(:disabled) { background-color: #d35400; }
.tower-btn.selected {
    border-color: #f1c40f !important;
    background-color: #e67e22 !important;
    box-shadow: 0 0 8px #f1c40f;
}

#upgrade-panel {
    padding: 10px;
    background: #1e1108;
    border: 1px solid #f1c40f;
    border-radius: 5px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 1.5rem; /* taille des icones de sboutons dans le pannel de ocntrole */
    min-height: 120px;
    box-sizing: border-box;
}

.panel-header {
    font-weight: bold;
    color: #f1c40f;
    border-bottom: 1px solid #5a3d28;
    padding-bottom: 4px;
}

#upgrade-content { display: flex; flex-direction: column; gap: 6px; }
.placeholder-text { color: #888; font-style: italic; font-size: 0.8rem; margin-top: 10px; }

#upgrade-placeholder {
    width: 100%;
    height: 100%;
    min-height: 110px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    padding: 0 !important;
}

#minimap-canvas {
    width: auto !important;
    height: 100% !important;
    max-height: 150px !important;
    aspect-ratio: 1 / 1 !important;
    display: block;
    background-color: transparent;
    border-radius: 6px;
    margin: 0 auto;
}

/* MODALE DOCUMENTATION */
.modal, #doc-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.82);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 99999;
}

.modal-content {
    background-color: #26170b;
    border: 2px solid #f1c40f;
    border-radius: 8px;
    width: 90%;
    max-width: 580px;
    max-height: 85vh;
    padding: 16px;
    overflow-y: auto;
    box-shadow: 0 0 20px rgba(0,0,0,0.9);
    position: relative;
    color: #f3e5ab;
    box-sizing: border-box;
}

.close-btn {
    position: absolute;
    right: 15px;
    top: 10px;
    font-size: 26px;
    font-weight: bold;
    color: #e67e22;
    cursor: pointer;
}
.close-btn:hover { color: #f1c40f; }

.modal-title {
    margin-top: 0;
    font-size: 1.2rem;
    color: #f1c40f;
    text-align: left;
}

.doc-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
    border-bottom: 1px solid #5a3d28;
    padding-bottom: 8px;
}

.tab-btn {
    background: #1a1006;
    border: 1px solid #5a3d28;
    color: #f3e5ab;
    padding: 6px 14px;
    cursor: pointer;
    border-radius: 4px;
    font-weight: bold;
    font-family: 'Georgia', serif;
}

.tab-btn.active {
    background: #e67e22;
    color: white;
    border-color: #f1c40f;
}

.tab-content { display: none; }
.tab-content.active { display: block; }

.doc-card {
    background: #1e1108;
    border: 1px solid #5a3d28;
    border-radius: 6px;
    padding: 10px;
    margin-bottom: 10px;
}

.doc-card-header {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1rem;
    font-weight: bold;
    color: #f1c40f;
    margin-bottom: 6px;
}

.doc-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 6px;
    font-size: 0.8rem;
}

.doc-table th, .doc-table td {
    border: 1px solid #5a3d28;
    padding: 5px 6px;
    text-align: center;
}

.doc-table th { background-color: #1a1006; color: #e67e22; }

button:disabled,
button.disabled-btn {
    background-color: #555555 !important;
    border-color: #333333 !important;
    color: #888888 !important;
    cursor: not-allowed !important;
    opacity: 0.6;
    box-shadow: none !important;
}

/* Style des blocs C et D / volume */
.volume-control-btn {
    padding: 8px 12px !important;    /* Augmente le rembourrage interne (haut/bas) */
    min-height: 40px !important;     /* Définit une hauteur minimale plus confortable */
    gap: 8px;
    display: inline-flex;
    align-items: center;
}

.volume-label {
    cursor: pointer;
    user-select: none;
    font-size: 1.5rem; /* <--- Augmentez cette valeur (ex: 1.2rem ou 1.3rem*/
    white-space: nowrap;
}

.volume-label:hover {
    color: #f1c40f;
}

.volume-control-btn input[type="range"] {
    width: 55px;
    cursor: pointer;
    accent-color: #f1c40f;
    margin: 0;
}

.bottom-panel {
    display: flex;
    align-items: stretch;
    gap: 15px;
}

.info-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    box-sizing: border-box;
    border: 2px solid #d4ac0d;
    border-radius: 6px;
    padding: 10px;
    height: 100%;
}

#enemies-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 20;
}

#btn-c, #btn-d, .volume-control-btn {
    background-color: #2980b9 !important;
    border: 1px solid #1b4f72 !important;
    color: white !important;
}

#btn-c:hover, #btn-d:hover, .volume-control-btn:hover {
    background-color: #3498db !important;
}

/* --- ADAPTATION MOBILE : MODE PORTRAIT (Téléphone à la verticale) --- */
@media screen and (max-width: 768px) and (orientation: portrait) {
    #ui {
        transform: translateX(-50%) scale(0.5) !important; 
        transform-origin: bottom center !important;
        bottom: 0 !important;
        left: 50% !important;
        
        /* 270vw réduit à 30% donnera visuellement 81% de l'écran */
        width: 270vw !important; 
        max-width: none !important; 
    }
    
    .tower-btn, .action-btn, #start-btn, #pause-btn, #doc-btn, #stats-panel {
        font-size: 1.5rem !important;
        padding: 12px !important;
    }
}

/* --- ADAPTATION MOBILE : MODE PAYSAGE (Téléphone à l'horizontale) --- */
@media screen and (max-width: 950px) and (orientation: landscape) {
    #ui {
        transform: translateX(-50%) scale(0.45) !important; 
        transform-origin: bottom center !important;
        bottom: 0 !important;
        left: 50% !important;
        
        /* 170vw réduit à 30% donnera visuellement 51% de l'écran */
        width: 170vw !important; 
        max-width: none !important; 
    }
    
    .tower-btn, .action-btn, #start-btn, #pause-btn, #doc-btn, #stats-panel {
        font-size: 1.5rem !important;
        padding: 12px !important;
    }
}

/* --- ADAPTATION MOBILE : MODE PORTRAIT (Téléphone à la verticale) --- */
@media screen and (max-width: 768px) and (orientation: portrait) {
    #ui {
        /* 1. Ajuste le facteur d'échelle (ex: scale(0.4) pour réduire, scale(0.6) pour agrandir) */
        transform: translateX(-50%) scale(0.35) !important; 
        transform-origin: bottom center !important;
        bottom: 0 !important;
        left: 50% !important;
        
        /* 2. Ajuste la largeur brute avant le redimensionnement scale */
        width: 270vw !important; 
        max-width: none !important; 
    }
    
    /* 3. Ajuste la taille de la police et les marges internes des boutons si besoin */
    .tower-btn, .action-btn, #start-btn, #pause-btn, #doc-btn, #stats-panel {
        font-size: 1.5rem !important;
        padding: 12px !important;
    }
}

.doc-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
    border-bottom: 1px solid #5a3d28;
    padding-bottom: 8px;
    overflow-x: auto; /* Permet le défilement horizontal des onglets si l'écran est petit */
}

/* Force l'agrandissement des icônes (images/SVG) dans les boutons de la boutique */
.tower-btn img, 
.tower-icon img {
    width: 36px !important;  /* Modifiez cette valeur (ex: 40px, 48px) pour grossir l'icône */
    height: 36px !important; /* Doit être identique à la largeur pour garder les proportions */
    object-fit: contain;
}

.ghost-preview {
    position: absolute;
    pointer-events: none;
    z-index: 19;
    box-sizing: border-box;
}
/* 5 octobre 10h33
