/* ========================================
   VARIABLES & RESET
   ======================================== */

:root {
    --bg-dark: #0a0e27;
    --bg-popup: rgba(10, 14, 39, 0.95);
    --accent-primary: #5599ff;
    --accent-secondary: #7df58b;
    --danger: #ff5757;
    --warning: #ffc107;
    --text-light: #e7ecf3;
    --text-muted: #8892b0;
    
    /* Couleurs pastels pour le sol */
    --pastel-grass: #c8e6c9;
    --pastel-grass2: #a5d6a7;
    --pastel-dirt: #d7ccc8;
    --pastel-dirt2: #bcaaa4;
    --pastel-water: #b3e5fc;
    --pastel-water2: #81d4fa;
    --pastel-forest: #aed581;
    --pastel-forest2: #9ccc65;
    
    --grid-color: #000000;
    --grid-opacity: 0.3;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg-dark);
    color: var(--text-light);
    overflow: hidden;
    height: 100vh;
    position: relative;
}

/* ========================================
   CANVAS DE JEU (FOND)
   ======================================== */

#gameCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: block;
    image-rendering: crisp-edges;
    image-rendering: pixelated;
    z-index: 1;
}

/* ========================================
   HUD SUPÉRIEUR (POPUP)
   ======================================== */

.game-hud {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 1.5rem;
    z-index: 100;
    background: var(--bg-popup);
    backdrop-filter: blur(20px);
    padding: 1rem 2rem;
    border-radius: 16px;
    border: 2px solid rgba(85, 153, 255, 0.3);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
    animation: slideDown 0.5s ease-out;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-30px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

.hud-item {
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.hud-icon {
    font-size: 1.5rem;
}

.energy-bar {
    width: 180px;
    height: 24px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    overflow: hidden;
    border: 2px solid rgba(85, 153, 255, 0.4);
}

.energy-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-secondary), var(--accent-primary));
    transition: width 0.3s ease;
    width: 100%;
}

.energy-value {
    font-weight: 700;
    color: var(--accent-secondary);
    min-width: 70px;
}

.hud-btn {
    padding: 0.5rem 1rem;
    background: rgba(85, 153, 255, 0.2);
    border: 2px solid var(--accent-primary);
    color: var(--text-light);
    border-radius: 10px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s ease;
}

.hud-btn:hover {
    background: rgba(85, 153, 255, 0.3);
    transform: scale(1.05);
}

.help-btn {
    background: rgba(255, 193, 7, 0.2);
    border-color: var(--warning);
}

.help-btn:hover {
    background: rgba(255, 193, 7, 0.3);
}

/* ========================================
   POPUP DE DÉPLACEMENT
   ======================================== */

/* ========================================
   POPUP DE DÉPLACEMENT (VERSION CORRIGÉE)
   Petit popup qui apparaît au-dessus de la destination
   ======================================== */

/* ========================================
   POPUP DE DÉPLACEMENT (VERSION FINALE)
   Petit popup qui apparaît au-dessus de la destination
   SANS animation transform pour éviter les bugs
   ======================================== */

.move-popup {
    /* Position absolue pour pouvoir placer sur le canvas */
    position: fixed;
    /* Par défaut invisible, sera positionné dynamiquement en JS */
    display: none;
    
    /* Style compact et discret */
    background: rgba(10, 14, 39, 0.98);
    backdrop-filter: blur(20px);
    border: 2px solid var(--accent-primary);
    border-radius: 12px;
    padding: 0.8rem;
    width: 180px; /* 🆕 Largeur fixe pour le calcul */
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.7);
    z-index: 150;
    
    /* 🆕 Animation avec OPACITÉ seulement (pas de transform) */
    animation: fadeInPopup 0.2s ease-out;
    
    /* Pointeur pour montrer qu'on peut cliquer */
    pointer-events: auto;
}

/* 🆕 Animation simple avec opacité uniquement */
@keyframes fadeInPopup {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* En-tête du popup (coût énergie) */
.move-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-size: 1rem;
    font-weight: 700;
    color: var(--accent-primary);
    margin-bottom: 0.6rem;
}

.move-icon {
    font-size: 1.2rem;
}

/* Informations de déplacement */
.move-info {
    background: rgba(85, 153, 255, 0.15);
    border-radius: 8px;
    padding: 0.5rem;
    margin-bottom: 0.6rem;
    text-align: center;
}

.move-cost {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.9rem;
}

.move-cost .label {
    color: var(--text-muted);
    font-weight: 500;
}

.energy-cost {
    color: var(--accent-secondary) !important;
    font-weight: 700;
    font-size: 1rem;
}

/* Barre de progression du timer */
.move-timer {
    height: 4px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 0.6rem;
}

.move-timer-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-secondary), var(--accent-primary));
    width: 100%;
    transition: width 0.1s linear;
}

/* Bouton annuler */
.move-buttons {
    display: flex;
    justify-content: center;
}

.cancel-btn {
    padding: 0.4rem 0.8rem;
    background: rgba(255, 87, 87, 0.2);
    border: 2px solid var(--danger);
    color: var(--danger);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 700;
    transition: all 0.2s ease;
    width: 100%;
}

.cancel-btn:hover {
    background: rgba(255, 87, 87, 0.3);
    transform: scale(1.05);
}

/* Distance (optionnel, masqué par défaut pour rester compact) */
.move-distance {
    display: none;
}


/* ========================================
   BARRE D'ACTION AUTOMATIQUE (POPUP)
   ======================================== */

.action-popup {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-popup);
    backdrop-filter: blur(20px);
    border: 2px solid var(--accent-secondary);
    border-radius: 16px;
    padding: 1.5rem;
    min-width: 300px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
    z-index: 100;
    display: none;
    animation: popUp 0.3s ease-out;
}

.action-header {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--accent-secondary);
    margin-bottom: 1rem;
    text-align: center;
}

.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.action-btn {
    padding: 0.8rem 1.2rem;
    background: rgba(125, 245, 139, 0.15);
    border: 2px solid var(--accent-secondary);
    color: var(--text-light);
    border-radius: 10px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.action-btn:hover {
    background: rgba(125, 245, 139, 0.25);
    transform: scale(1.05);
}

/* ========================================
   BARRE DE CHARGEMENT (DORMIR, CUISINER)
   ======================================== */

.loading-bar {
    position: fixed;
    top: 100px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-popup);
    backdrop-filter: blur(20px);
    border: 2px solid var(--warning);
    border-radius: 16px;
    padding: 1.5rem 2rem;
    min-width: 350px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
    z-index: 150;
    display: none;
    animation: slideDown 0.4s ease-out;
}

.loading-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.loading-icon {
    font-size: 3rem;
    animation: bounce 1s ease-in-out infinite;
}

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

.loading-text {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--warning);
}

.loading-progress {
    width: 100%;
    height: 20px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    overflow: hidden;
}

.loading-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-secondary), var(--warning));
    transition: width 0.1s linear;
    width: 0%;
}

/* ========================================
   INVENTAIRE (POPUP)
   ======================================== */

.inventory-panel {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg-popup);
    backdrop-filter: blur(20px);
    border: 2px solid var(--accent-primary);
    border-radius: 20px;
    padding: 2rem;
    width: 450px;
    max-width: 90vw;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7);
    z-index: 200;
    display: none;
    animation: zoomIn 0.3s ease-out;
}

@keyframes zoomIn {
    from {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.panel-header h3 {
    font-size: 1.5rem;
    color: var(--accent-secondary);
}

.close-btn {
    background: transparent;
    border: none;
    color: var(--danger);
    font-size: 1.8rem;
    cursor: pointer;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: all 0.3s ease;
}

.close-btn:hover {
    background: rgba(255, 87, 87, 0.2);
    transform: rotate(90deg);
}

.inventory-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.8rem;
    margin-bottom: 1rem;
}

.inventory-slot {
    aspect-ratio: 1;
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
}

.inventory-slot:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--accent-primary);
    transform: scale(1.05);
}

.inventory-slot.has-item {
    border-color: var(--accent-secondary);
}

.slot-icon {
    font-size: 2.5rem;
}

.slot-quantity {
    position: absolute;
    bottom: 6px;
    right: 6px;
    background: var(--accent-primary);
    color: var(--bg-dark);
    font-size: 0.8rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 6px;
    min-width: 24px;
    text-align: center;
}

.panel-info {
    text-align: center;
    font-size: 0.9rem;
    color: var(--text-muted);
}

/* ========================================
   MENU PERSONNAGE (POPUP)
   ======================================== */

.player-menu {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg-popup);
    backdrop-filter: blur(20px);
    border: 2px solid var(--accent-primary);
    border-radius: 20px;
    padding: 2rem;
    width: 400px;
    max-width: 90vw;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7);
    z-index: 200;
    display: none;
    animation: zoomIn 0.3s ease-out;
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.menu-btn {
    padding: 1.2rem;
    background: rgba(85, 153, 255, 0.15);
    border: 2px solid var(--accent-primary);
    color: var(--text-light);
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: all 0.3s ease;
}

.menu-btn:hover {
    background: rgba(85, 153, 255, 0.25);
    transform: translateX(10px);
}

.btn-icon {
    font-size: 2rem;
    flex-shrink: 0;
}

.btn-content {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    flex: 1;
}

.btn-text {
    font-size: 1.1rem;
    font-weight: 600;
}

.btn-benefit {
    font-size: 0.9rem;
    color: var(--accent-secondary);
    font-weight: 700;
}

/* ========================================
   POPUP D'AIDE
   ======================================== */

.help-panel {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg-popup);
    backdrop-filter: blur(20px);
    border: 2px solid var(--warning);
    border-radius: 20px;
    padding: 2rem;
    width: 600px;
    max-width: 90vw;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7);
    z-index: 250;
    display: none;
    animation: zoomIn 0.3s ease-out;
}

.help-content {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.help-section h4 {
    font-size: 1.2rem;
    color: var(--accent-secondary);
    margin-bottom: 0.8rem;
}

.help-section p {
    color: var(--text-muted);
    line-height: 1.6;
}

.control-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.8rem;
}

.control-item {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    padding: 0.8rem;
    background: rgba(85, 153, 255, 0.1);
    border-radius: 8px;
}

.control-item kbd {
    padding: 0.4rem 0.8rem;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--accent-primary);
    width: fit-content;
}

.control-item span {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.resource-grid {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.resource-item {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    padding: 0.8rem;
    background: rgba(125, 245, 139, 0.1);
    border-radius: 8px;
}

.resource-icon {
    font-size: 2rem;
    flex-shrink: 0;
}

.resource-item strong {
    display: block;
    color: var(--accent-secondary);
    margin-bottom: 0.2rem;
}

.resource-item p {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin: 0;
}

.help-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.help-list li {
    padding: 0.5rem 0;
    color: var(--text-muted);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.help-list li:last-child {
    border-bottom: none;
}

.help-list strong {
    color: var(--accent-secondary);
}

/* Scrollbar personnalisée pour l'aide */
.help-panel::-webkit-scrollbar {
    width: 8px;
}

.help-panel::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
}

.help-panel::-webkit-scrollbar-thumb {
    background: rgba(85, 153, 255, 0.5);
    border-radius: 10px;
}

.help-panel::-webkit-scrollbar-thumb:hover {
    background: rgba(85, 153, 255, 0.7);
}

/* ========================================
   RESPONSIVE
   ======================================== */

@media (max-width: 768px) {
    .game-hud {
        flex-direction: column;
        gap: 1rem;
        padding: 1rem;
    }
    
    .energy-bar {
        width: 140px;
    }
    
    .inventory-panel,
    .player-menu,
    .help-panel {
        width: 90vw;
    }
    
    .inventory-grid {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .control-grid {
        grid-template-columns: 1fr;
    }
    
    .move-popup {
        min-width: 280px;
    }
}
