body {
    margin: 0;
    padding: 0;
    background-color: #1a1a1a;
    color: #fff;
    font-family: 'Press Start 2P', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    overflow: hidden;
    -webkit-user-select: none; /* Safari */
    -ms-user-select: none; /* IE 10+ */
    user-select: none; /* Standard syntax */
}

#game-container {
    position: relative;
    border: 4px solid #5a3d2b;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
    background-color: #000;
    width: clamp(320px, 90vw, 1400px);
    height: clamp(240px, 85vh, 900px);
    overflow: hidden;
    /* Assurez-vous que le contenu ne déborde pas */
    transition: border-color 0.1s ease-out, box-shadow 0.1s ease-out;
    /* Transition douce pour le retour de dégâts */
}

#game-container.damage-overlay {
    border-color: #ff0000;
    box-shadow: 0 0 25px 10px rgba(255, 0, 0, 0.7);
}

canvas {
    display: block;
    background-color: rgba(0, 0, 0, 0);
    width: 100%;
    height: 100%;
}

#ui-container {
    position: absolute;
    top: 10px;
    left: 10px;
    right: 10px;
    pointer-events: none;
}

#stats {
    display: flex;
    justify-content: space-between;
    font-size: 16px;
    color: #fff;
    text-shadow: 2px 2px 2px #000;
}

#health-bar-container,
#xp-bar-container {
    width: 100%;
    height: 20px;
    background-color: rgba(0, 0, 0, 0.4);
    border: 2px solid #fff;
    border-radius: 5px;
    margin-top: 10px;
    overflow: hidden;
    position: relative;
}

#health-bar {
    height: 100%;
    background-color: #c0392b;
}

#xp-bar {
    height: 100%;
    background-color: #2980b9;
    transition: width 0.2s ease-in-out;
}

.bar-text {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: #fff;
    text-shadow: 1px 1px 1px #000;
    pointer-events: none;
    z-index: 1;
}

#gold-display {
    position: absolute;
    top: 110px;
    right: 5px;
    font-size: 16px;
    color: #f1c40f;
    text-shadow: 2px 2px 2px #000;
    pointer-events: none;
    z-index: 5;
}

/*
========================================
--- Styles des Modales (Corrigé) ---
========================================
*/
.modal {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    display: none; /* Retour à la méthode originale */
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    z-index: 10;
    padding: 15px;
    box-sizing: border-box;
}

.modal-content {
    position: relative;
    background-color: #2c2c2c;
    padding: 20px;
    border: 4px solid #5a3d2b;
    border-radius: 10px;
    width: 100%;
    max-width: 650px;
    max-height: 90vh; /* Limite la hauteur pour éviter le débordement */
    overflow-y: auto;  /* Ajoute une barre de défilement si le contenu est trop grand */
    overflow-x: hidden; /* Empêche le défilement horizontal */
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.modal h2 {
    font-size: 24px;
    color: #f1c40f;
    margin-bottom: 20px;
}

/*
========================================
--- Styles des Boutons (Général) ---
========================================
*/
button {
    font-family: 'Press Start 2P', cursive;
    font-size: 16px;
    padding: 15px 30px;
    background-color: #f1c40f;
    color: #1a1a1a;
    border: none;
    cursor: pointer;
    margin: 10px 5px;
    border-radius: 5px;
    transition: transform 0.1s ease-in-out, background-color 0.1s ease-in-out;
}

button:not(:disabled):hover {
    transform: scale(1.05);
    background-color: #f3d058;
}

button:disabled {
    background-color: #555;
    color: #888;
    cursor: not-allowed;
    border-color: #444;
}

/*
========================================
--- Styles des Menus Spécifiques ---
========================================
*/

/* Menu Principal */
#main-menu {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(55, 55, 55, 0.9);
    display: flex; /* Affiché par défaut au lancement */
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 20;
}

#menu-background-canvas {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 200px;
    z-index: 1;
    pointer-events: none;
}

#main-menu h1 {
    font-size: clamp(26px, 8vw, 48px);
    color: #f1c40f;
    margin-bottom: 40px;
    text-shadow: 4px 4px 0px #e67e22;
    z-index: 2;
    position: relative;
    text-align: center; /* Assure le centrage horizontal */
}

#main-menu h1 span {
    display: inline-block;
    position: relative;
    animation: wave 1.5s infinite;
    animation-delay: calc(0.1s * var(--i));
}

@keyframes wave {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-15px); }
}

#main-menu button {
    z-index: 2;
    position: relative;
}

#main-menu-gold, #upgrades-menu-gold {
    font-size: 20px;
    color: #f1c40f;
    text-shadow: 2px 2px 2px #000;
    margin-top: 20px;
    z-index: 2;
    position: relative;
}

.survival-text {
    margin-top: 40px;
    font-size: 14px;
    color: #ffffff;
    font-style: italic;
    text-shadow: 1px 1px 1px #000;
    animation: breathing-effect 1s ease-in-out infinite;
}

@keyframes breathing-effect {
  0%, 100% { transform: scale(1); opacity: 0.7; }
  50% { transform: scale(1.05); opacity: 1; }
}

/* Menu Améliorations (Level up) */
.upgrade-option {
    background-color: #4a4a4a;
    border: 2px solid #eee;
    padding: 15px;
    margin: 10px 0;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s ease-in-out;
    border-radius: 5px;
    display: flex;
    align-items: center;
    gap: 15px;
    width: 100%;
}

.upgrade-option:hover {
    background-color: #f1c40f;
    color: #1a1a1a;
    transform: scale(1.02);
}

.upgrade-icon {
    font-size: 28px;
    width: 40px;
    text-align: center;
}

/* Menu Améliorations Permanentes */
#permanent-upgrades-menu .modal-content {
    padding-top: 50px;
}

#upgrades-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
    width: 100%;
}

.permanent-upgrade-btn {
    height: 120px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    font-size: 11px; /* Taille de police réduite */
}

.permanent-upgrade-btn > div > div:nth-child(2) {
    margin-bottom: 5px; /* Ajoute un espace sous le titre */
}

.upgrade-cost {
    font-size: 10px; /* Taille de police réduite */
}

#resetUpgradesButton {
    position: absolute;
    top: 10px;
    right: 10px;
    padding: 5px 10px;
    font-size: 12px;
    background-color: #c0392b;
    color: #fff;
}

#resetUpgradesButton:hover {
    background-color: #e74c3c;
}

/* Menu Pause */
#pause-stats {
    margin-bottom: 20px;
    text-align: left;
}

#pause-upgrades {
    background-color: #1a1a1a;
    border: 2px solid #5a3d2b;
    border-radius: 5px;
    padding: 15px;
    margin: 20px 0;
    width: 100%;
    max-height: 150px;
    overflow-y: auto;
    text-align: left;
}

#pause-upgrades h3 {
    margin-top: 0;
    margin-bottom: 10px;
    color: #f1c40f;
    text-align: center;
}

#pause-upgrades-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

#pause-upgrades-list li {
    padding: 8px 5px;
    border-bottom: 1px solid #4a4a4a;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 10px;
}

#pause-upgrades-list li:last-child {
    border-bottom: none;
}

.pause-upgrade-icon {
    font-size: 20px;
    width: 25px;
    text-align: center;
}

/* Menu Options */
.volume-control {
    margin: 15px 0;
    text-align: left;
    width: 100%;
}

.volume-control label {
    display: block;
    margin-bottom: 5px;
    font-size: 14px;
}

.volume-control input[type="range"] {
    width: 100%;
    -webkit-appearance: none;
    appearance: none;
    height: 10px;
    background: #d3d3d3;
    outline: none;
    opacity: 0.7;
    transition: opacity .2s;
    border-radius: 5px;
}

.volume-control input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    background: #f1c40f;
    cursor: pointer;
    border-radius: 50%;
    border: 2px solid #1a1a1a;
}

.volume-control input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: #f1c40f;
    cursor: pointer;
    border-radius: 50%;
    border: 2px solid #1a1a1a;
}

.controls-info {
    margin-top: 30px;
    margin-bottom: 20px;
    text-align: left;
    background-color: rgba(0, 0, 0, 0.2);
    padding: 15px;
    border: 2px solid #5a3d2b;
    border-radius: 5px;
    width: 100%;
}

.controls-info h3 {
    color: #f1c40f;
    margin: 0 0 15px 0;
    padding-bottom: 5px;
    border-bottom: 2px solid #5a3d2b;
    text-align: center;
}

.controls-info p { margin: 10px 0 5px 0; }
.controls-info ul { list-style: none; padding-left: 10px; }
.controls-info li { padding: 4px 0; }

/* Menu Stats */
#stats-container {
    text-align: left;
    width: 100%;
}

#stats-container h3 {
    color: #f1c40f;
    margin-top: 20px;
    margin-bottom: 10px;
    border-bottom: 2px solid #5a3d2b;
    padding-bottom: 5px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 8px;
}

.stat-entry {
    font-size: 12px;
    padding: 8px;
    display: flex;
    justify-content: space-between;
}

.stat-label { color: #ccc; }
.stat-value { color: #f1c40f; font-weight: bold; }


/*
========================================
--- Éléments d'UI en jeu ---
========================================
*/

/* Icônes de statut */
#status-icons-container {
    position: absolute;
    top: 105px;
    left: 0;
    display: flex;
    flex-direction: column;
    gap: 5px;
    z-index: 5;
    pointer-events: none;
}

.icon-row {
    display: flex;
    gap: 5px;
}

.status-icon {
    width: 40px;
    height: 40px;
    background-color: rgba(0, 0, 0, 0.6);
    border: 2px solid #fff;
    border-radius: 5px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 24px;
    position: relative;
    color: #fff;
    pointer-events: all;
}

.level-badge {
    position: absolute;
    bottom: -2px;
    right: -2px;
    background-color: #f1c40f;
    color: #1a1a1a;
    font-size: 10px;
    padding: 1px 4px;
    border-radius: 3px;
    border: 1px solid #1a1a1a;
}

/* Info-bulle */
.tooltip {
    position: absolute;
    display: none;
    background-color: rgba(0, 0, 0, 0.85);
    color: #fff;
    padding: 8px;
    border-radius: 5px;
    border: 1px solid #f1c40f;
    font-size: 12px;
    z-index: 100;
    pointer-events: none;
    white-space: nowrap;
}

/* Contrôles du son et plein écran */
#sound-controls {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 30;
    display: flex; /* Affiché par défaut */
    flex-direction: row;
    align-items: center;
    gap: 7px;
}

#sound-controls button {
    font-size: 20px; /* Taille de l'icône */
    padding: 8px;
    min-width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease-in-out; /* Ajout d'une transition douce */
}

.btn-text {
    display: none; /* Cache le texte par défaut */
    margin-left: 8px;
    font-size: 14px; /* Taille de police pour le texte au survol */
    white-space: nowrap; /* Empêche le texte de passer à la ligne */
}

/* Effet au survol pour les appareils avec souris */
@media (hover: hover) {
    #sound-controls button:hover {
        min-width: auto; /* Permet au bouton de s'élargir */
        padding: 8px 15px; /* Ajuste le padding pour le texte */
    }

    #sound-controls button:hover .btn-text {
        display: inline; /* Affiche le texte au survol */
    }
}


#fullscreenButton {
    display: none; /* Affiché via JS si compatible */
}

#game-container:fullscreen {
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    border: none;
}

/* Contrôles mobile */
#mobile-controls {
    position: absolute;
    bottom: 30px;
    left: 30px;
    z-index: 100;
    display: none; /* Caché par défaut */
    user-select: none;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.azerty-horizontal-row {
    display: flex;
    justify-content: center;
    gap: 10px;
}

.zqs-button {
    width: 60px;
    height: 60px;
    background-color: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    color: white;
    font-family: 'Press Start 2P', cursive, sans-serif; /* Ajout de sans-serif en fallback */
    font-size: 24px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    touch-action: manipulation;
}

.zqs-button:active {
    background-color: rgba(255, 255, 255, 0.5);
}

/* Affiche les contrôles tactiles uniquement en jeu ET sur un appareil tactile */
@media (hover: none) and (pointer: coarse) {
    body.in-game #mobile-controls {
        display: flex; /* Utilise flex pour conserver la disposition en colonne */
    }
}

/*
========================================
--- Media Queries (Responsive) ---
========================================
*/
@media (max-width: 670px) {
    body { font-size: 14px; }
    #main-menu h1 { animation: none; }
    .modal h2 { font-size: 20px; }
    button { font-size: 14px; padding: 12px 20px; }
    #stats { font-size: 12px; }
    .bar-text { font-size: 11px; }
    #gold-display { font-size: 12px; }
    #pause-upgrades-list li { font-size: 12px; }
    .stat-entry { font-size: 12px; }
}

@media (max-width: 480px) {
    .modal-content { padding: 15px; }
    #upgrades-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
    .stats-grid { grid-template-columns: 1fr; }
    .permanent-upgrade-btn { height: 110px; }
}

@media (max-width: 350px) {
    .modal h2 { font-size: 18px; }
    button { font-size: 12px; padding: 10px 15px; }
    .permanent-upgrade-btn { font-size: 10px; height: 100px; padding: 8px; }
    .upgrade-cost { font-size: 10px; }
    #stats, #gold-display { font-size: 10px; }
    .bar-text { font-size: 9px; }
    #resetUpgradesButton { top: 5px; right: 5px; font-size: 10px; padding: 4px 8px;}
}
