:root {
    --slot: 44px;
    --panel: #c6c6c6;
    --panel-dark: #555;
    --panel-light: #fff;
    --btn: #6d6d6d;
    --btn-hover: #7e88c7;
    --font: 'Trebuchet MS', 'Segoe UI', Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    overflow: hidden;
    background-color: #87CEEB;
    font-family: var(--font);
    user-select: none;
}

canvas#gameCanvas { display: block; position: fixed; inset: 0; width: 100%; height: 100%; }
.hidden { display: none !important; }

/* --- Informations (coordonnées, F3, FPS) --- */
#ui {
    position: fixed; inset: 0;
    pointer-events: none;
    font-family: 'Courier New', Consolas, monospace;
    font-size: 14px;
    color: white;
    z-index: 2;
}
#coords, #debug-right {
    position: absolute;
    top: 4px;
    white-space: pre;
    line-height: 1.45;
    text-shadow: 1px 1px 0 #222;
}
#coords { left: 6px; }
#debug-right { right: 6px; text-align: right; }
#fps { position: absolute; top: 6px; right: 10px; text-shadow: 1px 1px 0 #222; }
#debug-graph { position: absolute; left: 6px; bottom: 90px; background: rgba(0, 0, 0, 0.4); }
.debug-on #coords, .debug-on #debug-right { max-width: 49vw; font-size: 12px; }
.debug-on #coords > div, .debug-on #debug-right > div { background: rgba(60, 60, 60, 0.6); padding: 0 3px; white-space: normal; }
#loading {
    position: absolute; top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    font-size: 22px;
    font-family: var(--font);
    background: rgba(0, 0, 0, 0.55); padding: 14px 26px; border-radius: 6px;
}

/* --- Jeu --- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 4; }

#hotbar-ui {
    position: absolute; bottom: 14px; left: 50%;
    transform: translateX(-50%);
    display: flex;
    background-color: rgba(0, 0, 0, 0.45);
    border: 2px solid #555;
    padding: 3px;
    border-radius: 3px;
}

#status-bars {
    position: absolute; bottom: 74px; left: 50%;
    transform: translateX(-50%);
    width: calc(9 * (var(--slot) + 4px) + 12px);
    display: flex; justify-content: space-between;
    pointer-events: none;
}
.bar { display: flex; gap: 0; height: 20px; margin-bottom: 2px; }
#right-bars .bar { flex-direction: row-reverse; justify-content: flex-start; }
#right-bars { display: flex; flex-direction: column; align-items: flex-end; }
.bar i {
    display: block; width: 20px; height: 20px;
    background-size: 18px 18px; background-repeat: no-repeat; background-position: center;
    image-rendering: pixelated;
}
.bar i.shake { transform: translateY(-2px); }
.heart.full { background-image: url(textures/ui/heart_full.png); }
.heart.half { background-image: url(textures/ui/heart_half.png); }
.heart.empty { background-image: url(textures/ui/heart_empty.png); }
.food.full { background-image: url(textures/ui/food_full.png); }
.food.half { background-image: url(textures/ui/food_half.png); }
.food.empty { background-image: url(textures/ui/food_empty.png); }
.armor.full { background-image: url(textures/ui/armor_full.png); }
.armor.half { background-image: url(textures/ui/armor_half.png); }
.armor.empty { background-image: url(textures/ui/armor_empty.png); }
.bubble.full { background-image: url(textures/ui/bubble.png); }
.bubble.pop { background-image: url(textures/ui/bubble_pop.png); }
.bubble.empty { background: none; }

.slot {
    width: var(--slot); height: var(--slot);
    background-color: #8b8b8b;
    border: 2px solid;
    border-color: #373737 #fff #fff #373737;
    position: relative;
    cursor: pointer;
    margin: 0;
    border-radius: 0;
}
.slot:hover { background-color: #b0b0c8; }
.slot.big { width: calc(var(--slot) * 1.3); height: calc(var(--slot) * 1.3); }
.hotbar-slot {
    background-color: rgba(60, 60, 60, 0.6);
    border: 2px solid #3a3a3a;
    margin: 0 1px;
    cursor: default;
}
.hotbar-slot:hover { background-color: rgba(60, 60, 60, 0.6); }
.hotbar-slot.selected {
    border-color: #fff;
    box-shadow: 0 0 0 2px #000, 0 0 8px rgba(255, 255, 255, 0.6);
    z-index: 1;
}
.slot.selected { outline: 2px solid #fff; outline-offset: -2px; }

.slot-icon {
    width: 100%; height: 100%;
    padding: 3px;
    display: block;
    image-rendering: pixelated;
    object-fit: contain;
    pointer-events: none;
}
.count {
    position: absolute; bottom: 0; right: 3px;
    color: white; font-size: 14px; font-weight: bold;
    text-shadow: 2px 2px 0 #3f3f3f;
    pointer-events: none;
}
.dur {
    position: absolute; left: 4px; right: 4px; bottom: 3px; height: 3px;
    background: #000; display: none; pointer-events: none;
}
.dur > div { height: 100%; width: 100%; background: #4f4; }

#crosshair {
    position: absolute; top: 50%; left: 50%;
    width: 18px; height: 18px;
    transform: translate(-50%, -50%);
    mix-blend-mode: difference;
}
#crosshair::before, #crosshair::after { content: ''; position: absolute; background: white; }
#crosshair::before { left: 8px; top: 0; width: 2px; height: 18px; }
#crosshair::after { top: 8px; left: 0; width: 18px; height: 2px; }

#block-name {
    position: absolute; bottom: 106px; left: 50%;
    transform: translateX(-50%);
    color: white; font-size: 18px;
    text-shadow: 2px 2px 0 #3f3f3f;
    white-space: nowrap;
}
#chat-log {
    position: absolute; left: 8px; bottom: 90px;
    width: min(560px, 50vw);
    font-size: 14px; line-height: 1.35;
    color: white; text-shadow: 1px 1px 0 #222;
}
#chat-log div { background: rgba(0, 0, 0, 0.4); padding: 1px 5px; width: fit-content; max-width: 100%; transition: opacity 1s; }
#effects { position: absolute; top: 28px; right: 10px; text-align: right; font-size: 13px; text-shadow: 1px 1px 0 #222; color: white; }
#effects span { display: block; }
#effect-cheat { color: #ffcf4a; }
#effect-night { color: #9ad7ff; }

#chat-input {
    position: fixed; left: 8px; right: 8px; bottom: 8px; z-index: 30;
    font: 16px 'Courier New', monospace;
    background: rgba(0, 0, 0, 0.7); color: white; border: 1px solid #888; padding: 6px 8px;
    outline: none;
}

#underwater { position: fixed; inset: 0; background: rgba(20, 60, 160, 0.35); pointer-events: none; z-index: 3; }
#hurt-flash { position: fixed; inset: 0; pointer-events: none; z-index: 3; box-shadow: inset 0 0 120px 40px rgba(220, 0, 0, 0.55); background: rgba(200, 0, 0, 0.18); animation: hurt 0.4s ease-out forwards; }
@keyframes hurt { from { opacity: 1; } to { opacity: 0; } }
#fire-overlay { position: fixed; inset: 0; pointer-events: none; z-index: 3; background: linear-gradient(to top, rgba(255, 120, 0, 0.55), rgba(255, 120, 0, 0) 55%); }
#sleep-overlay { position: fixed; inset: 0; background: #000; z-index: 40; opacity: 0; pointer-events: none; transition: opacity 1.2s; }
#sleep-overlay.on { opacity: 1; }

/* --- Inventaire --- */
#inventory-ui {
    position: fixed; inset: 0; z-index: 10;
    display: flex; align-items: center; justify-content: center;
    background: rgba(0, 0, 0, 0.45);
}
.inv-panel {
    background: var(--panel);
    border: 3px solid;
    border-color: #fff #555 #555 #fff;
    border-radius: 4px;
    padding: 12px 14px 14px;
    box-shadow: 0 0 0 3px #000;
    max-height: 96vh;
    overflow: auto;
}
.inv-label { color: #404040; font-size: 14px; font-weight: bold; margin: 6px 0 3px; }
.slot-grid { display: grid; width: fit-content; }
.hotbar-row { margin-top: 8px; }
.inv-row { display: flex; align-items: center; gap: 12px; }
.inv-spacer { width: 8px; }
.arrow { font-size: 30px; color: #707070; }
.arrow.progress { position: relative; width: 48px; text-align: center; }
.arrow-fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: rgba(60, 200, 60, 0.45); }
.furnace-col { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.flame { width: 26px; height: 26px; background: url(textures/ui/furnace_flame_off.png) center/contain no-repeat; image-rendering: pixelated; position: relative; }
.flame-fill { position: absolute; left: 0; right: 0; bottom: 0; height: 0; background: url(textures/ui/flame.png) bottom/26px 26px no-repeat; image-rendering: pixelated; }
.armor-col { margin-right: 4px; }
.creative-tabs { display: flex; gap: 4px; align-items: center; margin-bottom: 8px; }
.creative-tabs .tab { width: 40px; height: 40px; background: #8b8b8b; border: 2px solid #373737; cursor: pointer; padding: 2px; }
.creative-tabs .tab img { width: 100%; height: 100%; image-rendering: pixelated; object-fit: contain; }
.creative-tabs .tab.active { background: #c6c6c6; border-color: #fff #373737 #c6c6c6 #fff; }
.creative-tabs .tab.trash { width: auto; padding: 0 10px; font: 13px var(--font); color: #222; }
.creative-search { flex: 1; min-width: 80px; height: 34px; background: #000; border: 2px solid #777; color: #fff; padding: 0 8px; font: 14px var(--font); }
.palette { max-height: 252px; overflow-y: auto; border: 2px solid #8b8b8b; padding: 2px; background: #8b8b8b; }

#held-item { position: fixed; width: 40px; height: 40px; z-index: 1000; pointer-events: none; transform: translate(-50%, -50%); }
#tooltip {
    position: fixed; z-index: 1001; pointer-events: none; white-space: pre;
    background: rgba(16, 0, 16, 0.92); border: 2px solid #2a0a5a; color: #fff;
    padding: 4px 8px; font-size: 14px; line-height: 1.4;
}

/* --- Menus --- */
.screen {
    position: fixed; inset: 0; z-index: 20;
    display: flex; align-items: center; justify-content: center;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    overflow: auto;
}
#screen-title {
    background:
        radial-gradient(ellipse at 50% 120%, rgba(255, 200, 100, 0.35), transparent 60%),
        linear-gradient(#5aa5e8 0%, #9fd0f5 55%, #6bbf4e 55%, #4e9a38 62%, #8a5a2c 62%, #6b431f 100%);
}
#screen-title .menu-box { background: rgba(0, 0, 0, 0.35); border-radius: 8px; padding: 22px 36px; }
#screen-death { background: rgba(120, 0, 0, 0.6); }
.menu-box { text-align: center; max-width: 620px; width: 92%; padding: 16px; margin: auto; }
.menu-box.wide { max-width: 520px; }
.menu-box h1, .menu-box h2 { margin: 0 0 14px; text-shadow: 4px 4px 0 #3f3f3f; }
.menu-box h1.logo { font-size: 56px; letter-spacing: 2px; color: #fff; text-shadow: 4px 4px 0 #3f3f3f, 0 0 20px rgba(0, 0, 0, 0.4); }
.menu-box h2 { font-size: 30px; }
.red { color: #ff5555; }
.splash { color: #ffff55; font-size: 18px; transform: rotate(-4deg); margin: -6px 0 18px; text-shadow: 2px 2px 0 #3f3f00; animation: pulse 1s infinite alternate; }
@keyframes pulse { from { transform: rotate(-4deg) scale(1); } to { transform: rotate(-4deg) scale(1.08); } }

.btn {
    display: block; width: min(420px, 100%);
    margin: 0 auto 10px;
    padding: 11px 16px;
    font: 18px var(--font);
    color: #fff;
    background: var(--btn);
    border: 2px solid #000;
    box-shadow: inset 2px 2px 0 #aaa, inset -2px -2px 0 #444;
    text-shadow: 2px 2px 0 #333;
    cursor: pointer;
}
.btn:hover { background: var(--btn-hover); }
.btn.primary { background: #4e8f3a; }
.btn.primary:hover { background: #63b04a; }
.btn.small { display: inline-block; width: auto; padding: 6px 16px; font-size: 15px; margin: 0 3px; }
.btn.active { background: #4e8f3a; }
.btn:disabled { opacity: 0.5; cursor: default; }
.footnote { color: #ccc; font-size: 13px; margin: 8px 0; line-height: 1.4; text-shadow: 1px 1px 0 #000; }
.help { font-size: 13px; line-height: 1.7; color: #ddd; margin-top: 14px; text-shadow: 1px 1px 0 #000; }

.field { display: block; text-align: left; margin: 0 auto 12px; width: min(420px, 100%); font-size: 15px; }
.field input[type=text] { display: block; width: 100%; margin-top: 4px; padding: 8px; font: 16px var(--font); background: #000; color: #fff; border: 2px solid #888; }
.seg { margin-top: 5px; }
.slider, .check { display: block; text-align: left; margin: 0 auto 12px; width: min(420px, 100%); font-size: 15px; }
.slider input { display: block; width: 100%; margin-top: 4px; }
.check input { margin-right: 8px; transform: scale(1.3); }

/* --- Triche --- */
.cheat-box { max-width: 760px; text-align: left; background: rgba(20, 20, 30, 0.92); border: 2px solid #666; border-radius: 6px; max-height: 92vh; overflow: auto; }
.cheat-box h2 { text-align: center; }
.tabs { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 12px; justify-content: center; }
.tabs .btn.small { margin: 0; }
.cheat-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 4px; border-bottom: 1px solid rgba(255, 255, 255, 0.08); font-size: 15px; }
.cheat-row small { display: block; color: #aaa; font-size: 12px; }
.cheat-row input[type=range] { width: 200px; }
.cheat-row input[type=number], .cheat-row input[type=text], .cheat-row select { background: #000; color: #fff; border: 1px solid #888; padding: 5px; font: 14px var(--font); width: 90px; }
.cheat-row input[type=text] { width: 180px; }
.cheat-actions { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 0; }
.cheat-actions .btn { width: auto; margin: 0; font-size: 14px; padding: 7px 12px; }
.switch { position: relative; width: 46px; height: 24px; background: #555; border: 2px solid #000; cursor: pointer; flex: none; }
.switch::after { content: ''; position: absolute; top: 1px; left: 1px; width: 18px; height: 18px; background: #bbb; transition: left 0.1s; }
.switch.on { background: #3f9a35; }
.switch.on::after { left: 23px; background: #fff; }
.item-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 4px; max-height: 260px; overflow: auto; margin-top: 8px; }
.item-list button { display: flex; align-items: center; gap: 6px; background: #333; color: #fff; border: 1px solid #666; padding: 3px 6px; cursor: pointer; font: 13px var(--font); text-align: left; }
.item-list button:hover { background: #4a4a7a; }
.item-list img { width: 22px; height: 22px; image-rendering: pixelated; }

@media (max-width: 800px) {
    :root { --slot: 36px; }
    .menu-box h1.logo { font-size: 38px; }
}

/* --- Carte --- */
#screen-map { background: #10121a; padding: 0; display: block; z-index: 25; }
#map-canvas { position: absolute; inset: 0; width: 100%; height: 100%; cursor: grab; image-rendering: pixelated; }
#map-bar { position: absolute; left: 0; right: 0; top: 0; display: flex; align-items: center; gap: 10px; padding: 8px 14px; background: rgba(0, 0, 0, 0.6); color: #fff; font-size: 14px; }
#map-bar .spacer { flex: 1; }
#map-bar .btn.small { margin: 0; }
#map-info { color: #cde; font-family: 'Courier New', monospace; }
