body {
    margin: 0;
    overflow: hidden;
    background-color: #87CEEB;
}

canvas {
    display: block;
}

#ui {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    pointer-events: none;
    font-family: Arial, sans-serif;
    font-size: 16px;
    color: white;
    text-shadow: 2px 2px 4px #000000;
}

#coords {
    position: absolute;
    top: 10px;
    left: 10px;
}

#fps {
    position: absolute;
    top: 10px;
    right: 10px;
}

.hidden {
    display: none !important;
}

/* --- Style générique pour une case (slot) --- */
.slot {
    width: 40px;
    height: 40px;
    background-color: #444;
    border: 2px solid #aaa;
    position: relative;
    cursor: pointer;
    margin: 2px;
    box-sizing: border-box;
    border-radius: 4px;
    user-select: none;
}

.slot:hover {
    border-color: white;
}

.slot-icon {
    width: 100%;
    height: 100%;
    display: block;
    image-rendering: pixelated;
    object-fit: contain;
}

.count {
    position: absolute;
    bottom: 2px;
    right: 4px;
    color: white;
    font-size: 12px;
    font-weight: bold;
    text-shadow: 1px 1px 2px black;
}

/* --- Hotbar (quand elle est en jeu) --- */
/* Ce style s'applique par défaut, la plaçant en bas de l'écran */
#hotbar-ui {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex; /* Aligne les slots horizontalement */
    background-color: rgba(0, 0, 0, 0.5);
    border: 2px solid #555;
    padding: 5px;
    border-radius: 4px;
    z-index: 5;
}

.hotbar-slot.selected {
    border-color: #FFD700;
    box-shadow: 0 0 10px #FFD700;
    transform: scale(1.1);
}

/* --- Panneau d'inventaire complet --- */
#inventory-ui {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: rgba(0, 0, 0, 0.75);
    border: 4px solid #333;
    padding: 10px;
    z-index: 10;
    border-radius: 8px;
    
    /* NOUVEAU: Disposition en grille */
    display: grid;
    grid-template-areas:
        "crafting"
        "main-inv"
        "hotbar-inv";
    grid-gap: 15px;
}

/* Règle CRUCIALE: quand l'inventaire est visible, on repositionne la hotbar */
#inventory-ui:not(.hidden) #hotbar-ui {
    position: static;      /* Annule la position absolue */
    transform: none;       /* Annule le centrage */
    grid-area: hotbar-inv; /* La place dans la zone "hotbar" de la grille */
    margin: 0 auto;        /* La centre à l'intérieur de la grille */
}


/* --- Zone de Craft --- */
#crafting-area {
    grid-area: crafting;
    display: flex;
    align-items: center;
    justify-content: center;
}

#crafting-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr); /* Grille 3x3 */
}

#crafting-result-slot {
    width: 48px;
    height: 48px;
    margin-left: 30px;
}


/* --- Grille d'inventaire principale 9x3 --- */
#main-inventory-slots {
    grid-area: main-inv;
    display: grid;
    grid-template-columns: repeat(9, 1fr); /* Grille 9x3 */
}


/* --- Item tenu par la souris --- */
#held-item {
    position: fixed; /* 'fixed' est mieux pour le curseur */
    width: 40px;
    height: 40px;
    z-index: 1000;
    pointer-events: none; /* Crucial pour cliquer "à travers" */
    transform: translate(-50%, -50%); /* Centre sur le curseur */
}

#held-item .slot-icon {
    width: 100%;
    height: 100%;
}