/* VoxelCraft — HUD y overlays sobre el canvas WebGL */

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

html, body { width: 100%; height: 100%; overflow: hidden; background: #000; }

body {
    font-family: 'Courier New', monospace;
    color: #fff;
    text-shadow: 2px 2px #3f3f3f;
    user-select: none;
}

#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.hidden { display: none !important; }

/* ---- HUD ---- */

#version { position: absolute; top: 6px; left: 8px; z-index: 1; pointer-events: none; font-size: 14px; }

#debug {
    position: absolute; top: 28px; left: 8px; z-index: 1; pointer-events: none;
    font-size: 13px; line-height: 1.4; white-space: pre;
}

#crosshair {
    position: absolute; top: 50%; left: 50%; width: 18px; height: 18px;
    transform: translate(-50%, -50%); z-index: 2; pointer-events: none;
    mix-blend-mode: difference;
}
#crosshair::before, #crosshair::after {
    content: ""; position: absolute; background: #ddd;
}
#crosshair::before { left: 8px; top: 0; width: 2px; height: 18px; }
#crosshair::after  { left: 0; top: 8px; width: 18px; height: 2px; }

#hotbar {
    position: absolute; bottom: 4px; left: 50%; transform: translateX(-50%);
    z-index: 2; display: flex; gap: 2px;
    background: rgba(0,0,0,.45); padding: 3px; border: 2px solid #222;
}
.slot {
    width: 46px; height: 46px; border: 2px solid #555; background: rgba(255,255,255,.06);
    display: flex; align-items: center; justify-content: center; position: relative;
}
.slot.active { border-color: #fff; }
.slot .num {
    position: absolute; top: 0; left: 2px; font-size: 10px; color: #ccc; text-shadow: 1px 1px #000;
}
.slot canvas { image-rendering: pixelated; }
.slot .count, #picker-grid .count {
    position: absolute; top: 0; right: 2px; font-size: 10px; font-weight: bold;
    color: #fff; text-shadow: 1px 1px #000; pointer-events: none;
}
.slot.agotado canvas { opacity: .3; }

/* Corazones de salud (♥ rojo sobre ♥ apagado; media vida con clip):
   mitad izquierda sobre la hotbar — la barra de hambre es su espejo derecho */
#hearts {
    position: absolute; bottom: 64px; right: calc(50% + 3px);
    z-index: 2; display: flex; gap: 1px; pointer-events: none;
}
#hearts span { position: relative; width: 16px; height: 16px; }
#hearts span::before, #hearts span::after {
    content: "♥"; position: absolute; inset: 0;
    font-size: 15px; line-height: 16px; text-align: center;
}
#hearts span::before { color: #3b3b3b; text-shadow: 1px 1px #000; }
#hearts span::after { color: #e73c3c; text-shadow: 1px 1px #5a0000; }
#hearts span.empty::after { content: ""; }
#hearts span.half::after { clip-path: inset(0 50% 0 0); }

/* Raciones de hambre (🍗 vivo sobre 🍗 apagado; media ración con clip):
   espejo derecho de los corazones — row-reverse hace que la fila se llene
   desde la derecha y la media ración conserva su mitad derecha */
#hunger {
    position: absolute; bottom: 64px; left: calc(50% + 3px);
    z-index: 2; display: flex; flex-direction: row-reverse; gap: 1px; pointer-events: none;
}
#hunger span { position: relative; width: 16px; height: 16px; }
#hunger span::before, #hunger span::after {
    content: "🍗"; position: absolute; inset: 0;
    font-size: 13px; line-height: 16px; text-align: center;
}
#hunger span::before { filter: grayscale(1) brightness(.4); text-shadow: 1px 1px #000; }
#hunger span::after { filter: saturate(1.1); text-shadow: none; }
#hunger span.empty::after { content: ""; }
#hunger span.half::after { clip-path: inset(0 0 0 50%); }

/* Viñeta roja al recibir daño */
#damage {
    position: absolute; inset: 0; z-index: 3; pointer-events: none; opacity: 0;
    background: radial-gradient(ellipse at center, transparent 55%, rgba(190, 0, 0, .55) 100%);
    transition: opacity .5s ease-out;
}
#damage.hit { opacity: 1; transition: none; }

/* Pantalla de muerte */
#death { background: rgba(110, 0, 0, .5); }

/* ---- Overlays ---- */

.overlay {
    position: absolute; inset: 0; z-index: 10;
    display: flex; align-items: center; justify-content: center;
    background: rgba(0, 0, 0, .55);
}
.panel {
    background: rgba(20, 24, 30, .92); border: 2px solid #444;
    padding: 24px 32px; min-width: 340px; max-width: 90vw; max-height: 85vh;
    overflow: auto; text-align: center;
}
.panel h1 { font-size: 34px; margin-bottom: 4px; letter-spacing: 2px; }
.panel h2 { font-size: 20px; margin-bottom: 14px; }
.panel .subtitle { font-size: 12px; color: #aaa; margin-bottom: 18px; }
.panel .hint { font-size: 11px; color: #999; margin-top: 12px; }

button {
    display: block; width: 100%; margin: 6px 0; padding: 10px;
    font-family: inherit; font-size: 15px; color: #fff; text-shadow: 1px 1px #000;
    background: linear-gradient(#7d7d7d, #5c5c5c); border: 2px solid #000;
    cursor: pointer;
}
button:hover:not(:disabled) { background: linear-gradient(#8f9bd4, #6b77b0); }
button:disabled { color: #888; cursor: default; background: #3a3a3a; }

label { display: block; margin: 8px 0; font-size: 14px; text-align: left; }
input[type=text], input[type=password], input[type=email], select {
    width: 100%; margin-top: 4px; padding: 6px; font-family: inherit;
    background: #111; color: #fff; border: 2px solid #555;
}

/* Cuenta (inicio de sesión / registro / recuperación) */
.cuenta-estado { font-size: 12px; color: #9fc57f; margin-bottom: 10px; }
.cuenta-estado.sin-sesion { color: #aaa; }
.cuenta-error { font-size: 12px; color: #ff8a80; margin: 8px 0; }
.cuenta-aviso { font-size: 12px; color: #9fc57f; margin: 8px 0; }
.btn-enlace {
    display: inline-block; width: auto; margin: 0 0 6px; padding: 2px 6px;
    background: none; border: none; color: #9db4ff; font-size: 12px;
    text-shadow: none;
}
.btn-enlace:hover:not(:disabled) { background: none; text-decoration: underline; }

/* Multijugador: chat y alias sobre las cabezas */
#chat {
    position: absolute; left: 10px; bottom: 96px; z-index: 5;
    width: 42%; max-width: 460px; font-size: 13px;
}
#chat-log div {
    background: rgba(0, 0, 0, .45); padding: 2px 7px; margin-top: 2px;
    text-shadow: 1px 1px #000; word-break: break-word;
}
#chat-input {
    width: 100%; margin-top: 4px; padding: 6px; font-family: inherit;
    background: rgba(0, 0, 0, .65); color: #fff; border: 2px solid #666;
}
#chat-input:focus { outline: none; border-color: #aaa; }
#nametags { position: absolute; inset: 0; overflow: hidden; pointer-events: none; z-index: 4; }
#nametags div {
    position: absolute; transform: translate(-50%, -100%);
    background: rgba(0, 0, 0, .35); padding: 1px 6px;
    font-size: 12px; color: #fff; text-shadow: 1px 1px #000; white-space: nowrap;
}

#help-table { margin: 0 auto 10px; font-size: 13px; border-collapse: collapse; }
#help-table td { padding: 2px 10px; text-align: left; }
#help-table td:first-child { color: #ffd; }

/* Selector de bloques */
#picker-grid {
    display: grid; grid-template-columns: repeat(8, 52px); gap: 4px; justify-content: center;
}
#picker-grid .cell {
    width: 52px; height: 52px; border: 2px solid #555; background: rgba(255,255,255,.05);
    display: flex; align-items: center; justify-content: center; cursor: pointer;
    position: relative;
}
#picker-grid .cell:hover { border-color: #fff; background: rgba(255,255,255,.15); }
#picker-grid canvas { image-rendering: pixelated; }

/* Inventario creativo: pestañas por categoría + búsqueda + hotbar integrada
   (mismo banco de trabajo claro que el crafteo, al estilo Bedrock) */
.creative-cuerpo { display: flex; flex-direction: column; align-items: flex-start; }
#creative-tabs { display: flex; gap: 4px; margin-left: 10px; position: relative; z-index: 1; }
.ctab {
    width: 54px; height: 46px; cursor: pointer;
    background: #9a9a9a; border: 3px solid #1b1b1b; border-bottom: none;
    border-radius: 3px 3px 0 0;
    box-shadow: inset 2px 2px 0 #cfcfcf;
    display: flex; align-items: center; justify-content: center;
}
.ctab:hover { background: #b0b0b0; }
.ctab.activa {
    background: #c6c6c6; height: 52px; margin-top: -6px; margin-bottom: -3px;
    box-shadow: inset 2px 2px 0 #ffffff;
}
.ctab canvas { image-rendering: pixelated; }
.creative-panel { text-align: left; }
.creative-busqueda { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.creative-busqueda label { margin: 0; font-size: 14px; font-weight: bold; color: #3f3f3f; }
.creative-busqueda input {
    flex: 1; margin: 0; padding: 5px 8px; width: auto;
    font-family: inherit; font-size: 14px;
    background: #8b8b8b; color: #1b1b1b; caret-color: #1b1b1b;
    border: 2px solid; border-color: #373737 #ffffff #ffffff #373737;
}
.creative-busqueda input:focus { outline: none; background: #9c9c9c; }
#creative-grid {
    display: grid; grid-template-columns: repeat(9, 46px);
    grid-auto-rows: 46px; gap: 4px; align-content: start;
    height: 296px;               /* 6 filas de 46 px + huecos */
    overflow-y: scroll; padding-right: 4px;
}
#creative-grid::-webkit-scrollbar { width: 14px; }
#creative-grid::-webkit-scrollbar-track { background: #8b8b8b; border: 2px solid #555; }
#creative-grid::-webkit-scrollbar-thumb { background: #d6d6d6; border: 2px solid #555; }
.creative-vacio { grid-column: 1 / -1; color: #5a5a5a; font-size: 12px; padding: 18px 6px; }
#creative-hotbar { display: flex; gap: 4px; margin-top: 12px; padding-top: 10px; border-top: 2px solid #a5a5a5; }
#creative-hotbar .cslot .num {
    position: absolute; top: 0; left: 2px; font-size: 9px; color: #5a5a5a;
}

/* Pantalla de inventario y crafteo por cuadrícula (banco de trabajo claro) */
.craft-cuerpo { display: flex; gap: 14px; align-items: flex-start; }
.craft-panel {
    background: #c6c6c6; color: #3f3f3f;
    border: 3px solid #1b1b1b; border-radius: 3px;
    box-shadow: inset 2px 2px 0 #ffffff, inset -2px -2px 0 #555555;
    padding: 12px 14px; text-align: left;
}
/* la sombra de texto global es del tema oscuro: sobre el panel claro
   produce un doble contorno; aquí el texto va limpio (salvo cantidades) */
.craft-panel, .craft-panel * { text-shadow: none; }
.craft-etiqueta { margin: 6px 0 4px; font-size: 14px; color: #3f3f3f; font-weight: bold; }
.craft-linea { display: flex; align-items: center; gap: 12px; padding: 6px 0 10px; }
.craft-flecha { font-size: 28px; color: #8b8b8b; }
#craft-grid { display: grid; gap: 4px; }
#craft-inv { display: grid; grid-template-columns: repeat(9, 46px); gap: 4px; }
#craft-hotbar { display: flex; gap: 4px; margin-top: 10px; }
.craft-ayuda { margin: 10px 0 0; font-size: 11px; color: #5a5a5a; }
.cslot {
    width: 46px; height: 46px; background: #8b8b8b;
    border: 2px solid; border-color: #373737 #ffffff #ffffff #373737; /* hundida */
    display: flex; align-items: center; justify-content: center; position: relative;
    cursor: pointer;
}
.cslot:hover { background: #a0a0a0; }
.cslot.activo { background: #c5dbc0; border-color: #2e5a2e #eaffea #eaffea #2e5a2e; }
.cslot.resultado { width: 56px; height: 56px; cursor: default; }
.cslot.resultado.lista { background: #b8d8a8; cursor: pointer; }
.cslot canvas { image-rendering: pixelated; }
.cslot .count {
    position: absolute; top: 1px; right: 3px;
    font-size: 10px; font-weight: bold;
    color: #fff; text-shadow: 1px 1px #3f3f3f; pointer-events: none;
}
#craft-book-btn {
    width: 34px; height: 34px; padding: 0; margin: 0;
    background: #8b8b8b; border: 2px solid; border-color: #ffffff #373737 #373737 #ffffff;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
}
#craft-book-btn.activo { border-color: #373737 #ffffff #ffffff #373737; background: #a0a0a0; }
#craft-book-btn canvas { width: 26px; height: 26px; image-rendering: pixelated; }
#craft-cursor { position: fixed; z-index: 30; pointer-events: none; image-rendering: pixelated; }
#craft-tooltip {
    position: fixed; z-index: 31; pointer-events: none;
    background: rgba(18, 4, 24, .95); border: 2px solid #6a4fa0; border-radius: 2px;
    color: #fff; font-size: 13px; padding: 3px 8px; white-space: nowrap;
}
.craft-libro { width: 250px; display: flex; flex-direction: column; gap: 5px; max-height: 420px; overflow-y: auto; }
.receta {
    display: flex; align-items: center; gap: 10px;
    background: #b0b0b0; border: 2px solid; border-color: #ffffff #373737 #373737 #ffffff;
    padding: 4px 8px; cursor: pointer; color: #2e2e2e;
}
.receta.falta { opacity: .5; cursor: default; }
.receta:not(.falta):hover { background: #c9c9c9; }
.receta-info { flex: 1; display: flex; flex-direction: column; text-align: left; }
.receta-info span { font-size: 11px; color: #4c4c4c; }
.receta canvas { image-rendering: pixelated; }

/* Horno: fundición por sesión (mismo banco de trabajo claro que el crafteo) */
.furnace-titulo { margin-top: 0; font-size: 16px; }
.furnace-grid { display: grid; grid-template-columns: repeat(7, 46px); gap: 4px; }
#furnace-usos { font-weight: normal; font-size: 11px; color: #5a5a5a; }
#furnace-btn { display: inline-block; width: auto; margin: 0; padding: 8px 24px; font-size: 14px; }
#furnace-flecha { cursor: pointer; }
#furnace-flecha:hover:not(.inactiva) { color: #5a5a5a; }
#furnace-flecha.inactiva { cursor: default; opacity: .55; }

/* Cofre: intercambio de pilas (mismo banco de trabajo claro que el crafteo) */
.chest-titulo { margin-top: 0; font-size: 16px; }
#chest-grid, #chest-inv { display: grid; grid-template-columns: repeat(9, 46px); gap: 4px; }

/* Barra de progreso */
.bar { width: 300px; height: 18px; border: 2px solid #fff; margin: 0 auto; }
#progress-fill { height: 100%; width: 0%; background: #6c6; transition: width .1s linear; }
