:root {
    --fondo: #0b0d10;
    --caja: rgba(18, 20, 28, 0.92);
    --borde: rgba(255, 255, 255, 0.12);
    --texto: #f1ede4;
    --apagado: #a7a29a;
    --naranja: #ff8a1c;
    --naranja-osc: #c85f00;
    --verde: #7dff9e;
    --sombra: 0 10px 40px rgba(0, 0, 0, 0.5);
    --letra: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body {
    margin: 0;
    height: 100%;
    overflow: hidden;
    background: var(--fondo);
    color: var(--texto);
    font-family: var(--letra);
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
}
#vista { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; touch-action: none; }

/* --- Marcador --- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
#hud .arriba {
    position: absolute; top: 0; left: 0; right: 0;
    display: flex; align-items: flex-start; justify-content: space-between; gap: 10px;
    padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
}
#corazones { font-size: 22px; letter-spacing: 1px; filter: drop-shadow(0 2px 3px rgba(0,0,0,.6)); max-width: 40vw; line-height: 1.2; }
.centro { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 0; }
#fase {
    background: rgba(0, 0, 0, 0.55); border: 1px solid var(--borde); border-radius: 999px;
    padding: 6px 14px; font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%;
}
#jefe { width: min(360px, 70vw); text-align: center; font-weight: 700; font-size: 13px; text-shadow: 0 2px 3px #000; }
#jefe .barra { height: 12px; margin-top: 3px; background: rgba(0,0,0,.6); border: 2px solid rgba(255,255,255,.5); border-radius: 8px; overflow: hidden; }
#jefeVida { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, #ff3b3b, #ff9a2e); transition: width .15s; }
.derecha { display: flex; align-items: center; gap: 8px; }
#puntos { font-weight: 700; font-size: 17px; text-shadow: 0 2px 3px #000; white-space: nowrap; }
.redondo {
    pointer-events: auto; width: 40px; height: 40px; border-radius: 50%;
    border: 1px solid var(--borde); background: rgba(0,0,0,.55); font-size: 18px;
}
#hud .abajo {
    position: absolute; left: 0; right: 0; bottom: max(12px, env(safe-area-inset-bottom));
    display: flex; flex-direction: column; align-items: center; gap: 10px;
}
#armas { display: flex; gap: 6px; }
#gasolina { display: flex; align-items: center; gap: 6px; font-size: 16px; text-shadow: 0 1px 2px #000; }
#gasolina span { width: 120px; height: 10px; border-radius: 6px; background: rgba(0,0,0,.6); border: 2px solid rgba(255,255,255,.4); overflow: hidden; }
#gasolinaNivel { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, #ffb020, #ff6a1a); }
#gasolina.ahogada #gasolinaNivel { background: #8a8f99; }
#gasolina.ahogada { animation: latido .6s ease-in-out infinite; }
.ranura {
    position: relative; width: 46px; height: 46px; display: grid; place-items: center;
    font-size: 24px; border-radius: 12px; background: rgba(0,0,0,.5); border: 2px solid rgba(255,255,255,.08);
    filter: grayscale(1); opacity: .35;
}
.ranura.tiene { filter: none; opacity: 1; }
.ranura.mano { border-color: var(--verde); box-shadow: 0 0 12px rgba(125,255,158,.5); }
.ranura i { position: absolute; left: 2px; top: -2px; font-size: 11px; font-style: normal; color: #ffd34d; text-shadow: 0 1px 2px #000; letter-spacing: -1px; }
.ranura b { position: absolute; right: 3px; bottom: 0; font-size: 13px; text-shadow: 0 1px 2px #000; }
#botonNoche {
    pointer-events: auto; padding: 12px 22px; border-radius: 999px; border: 2px solid #8fa6ff;
    background: linear-gradient(#2a3466, #141a3a); font-weight: 700; font-size: 17px; box-shadow: var(--sombra);
    animation: latido 1.6s ease-in-out infinite;
}
#botonNoche.oculto { display: none; }
@keyframes latido { 50% { transform: scale(1.05); } }

/* --- Textos en el mundo --- */
#flotantes { position: fixed; inset: 0; pointer-events: none; z-index: 4; }
.flotante { position: absolute; left: 0; top: 0; font-weight: 800; font-size: 20px; color: #fff; text-shadow: 0 2px 0 #000, 0 0 6px #000; white-space: nowrap; }
.flotante.puntos { color: #ffe066; }
.flotante.clonk { color: #c9d4e8; font-size: 18px; }
.flotante.grito { color: #ff6a5a; font-size: 30px; }
.flotante.lento { font-size: 18px; }
#bocadillo {
    position: fixed; left: 50%; top: calc(max(10px, env(safe-area-inset-top)) + 78px); transform: translateX(-50%); z-index: 6; pointer-events: none;
    display: flex; align-items: center; gap: 10px; width: max-content; max-width: min(460px, 92vw); padding: 8px 14px 8px 8px; border-radius: 16px;
    background: #fff8e8; color: #3b2410; font-weight: 700; font-size: 15px; line-height: 1.3;
    box-shadow: var(--sombra); border: 3px solid var(--naranja);
    animation: habla .3s ease-out;
}
#bocadillo img { width: 46px; height: 46px; flex: none; }
@keyframes habla { from { opacity: 0; transform: translateX(-50%) translateY(-8px); } }
#flecha {
    position: fixed; left: 0; top: 0; z-index: 4; pointer-events: none;
    font-size: 40px; font-weight: 900; color: #ffe066; text-shadow: 0 0 8px #000, 0 2px 0 #000;
    animation: empuja .8s ease-in-out infinite;
}
@keyframes empuja { 50% { opacity: .55; } }
#rojo { position: fixed; inset: 0; pointer-events: none; z-index: 3; box-shadow: inset 0 0 120px 30px rgba(255, 0, 0, 0.75); opacity: 0; }
#rojo.pum { animation: pum .5s ease-out; }
@keyframes pum { from { opacity: 1; } to { opacity: 0; } }
#cartel {
    position: fixed; left: 50%; top: 34%; z-index: 7; pointer-events: none; transform: translate(-50%, -50%);
    display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; width: max-content; max-width: 92vw;
}
#cartel b { font-size: clamp(28px, 7vw, 56px); text-shadow: 0 4px 0 #000, 0 0 18px rgba(0,0,0,.8); color: #fff3d0; }
#cartel span { font-size: clamp(15px, 3.5vw, 22px); font-weight: 700; text-shadow: 0 2px 0 #000, 0 0 8px #000; }
#cartel.entra { animation: cartel .45s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes cartel { from { transform: translate(-50%, -50%) scale(.4); opacity: 0; } }

/* --- Mandos táctiles --- */
#zonaJoystick, #botonesTactiles { display: none; }
body.tactil.jugando #zonaJoystick { display: block; position: fixed; left: 0; top: 70px; bottom: 0; width: 50%; z-index: 2; }
#zonaJoystick .base, #zonaJoystick .palanca { position: fixed; left: 0; top: 0; border-radius: 50%; pointer-events: none; }
#zonaJoystick .base { width: 120px; height: 120px; margin: -60px 0 0 -60px; border: 3px solid rgba(255,255,255,.35); background: rgba(0,0,0,.2); }
#zonaJoystick .palanca { width: 56px; height: 56px; margin: -28px 0 0 -28px; background: rgba(255,255,255,.55); }
body.tactil.jugando #botonesTactiles {
    display: flex; align-items: flex-end; gap: 14px; position: fixed; z-index: 6;
    right: max(16px, env(safe-area-inset-right)); bottom: max(76px, calc(env(safe-area-inset-bottom) + 64px));
}
#botonesTactiles button {
    border-radius: 50%; border: 3px solid rgba(255,255,255,.4); background: rgba(0,0,0,.45);
    box-shadow: var(--sombra);
}
#botonAtacar { width: 92px; height: 92px; font-size: 40px; }
#botonBomba { width: 62px; height: 62px; font-size: 28px; margin-bottom: 40px; }
#botonBomba.agotado { opacity: .35; }
#botonesTactiles .apretado { background: rgba(255,255,255,.3); transform: scale(.94); }

/* --- Capas (portada, pausa, final) --- */
.capa {
    position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; padding: 16px;
    overflow-y: auto; touch-action: pan-y;
    background: radial-gradient(ellipse at center, rgba(10,12,20,.35), rgba(5,6,10,.8));
}
#portada { background: linear-gradient(rgba(5,6,12,.25), rgba(5,6,12,.75)); }
.caja {
    width: min(640px, 100%); padding: 24px; border-radius: 22px; background: var(--caja); border: 1px solid var(--borde);
    box-shadow: var(--sombra); text-align: center;
}
.caja h1 { margin: 4px 0; font-size: clamp(30px, 7vw, 46px); color: #ffd28a; text-shadow: 0 3px 0 #5a2a00; }
.caja p { line-height: 1.45; }
.antetitulo { margin: 0; color: var(--naranja); font-weight: 700; text-transform: uppercase; letter-spacing: .08em; font-size: 12px; }
.provisional { margin: 0; color: var(--apagado); font-size: 13px; }
.elegir > span { display: block; font-weight: 700; margin: 6px 0 8px; }
.personajes { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.personaje {
    display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 2px;
    border-radius: 14px; border: 2px solid transparent; background: rgba(255,255,255,.06); touch-action: manipulation;
}
.personaje img { width: 100%; max-width: 76px; aspect-ratio: 1; object-fit: contain; }
.personaje span { font-size: 13px; font-weight: 700; }
.personaje.elegido { border-color: var(--naranja); background: rgba(255,138,28,.18); }
.elegir + .elegir { margin-top: 12px; }
.dificultades { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.dificultad {
    display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 8px 4px;
    border-radius: 14px; border: 2px solid transparent; background: rgba(255,255,255,.06); touch-action: manipulation;
}
.dificultad b { font-size: 26px; }
.dificultad span { font-weight: 800; font-size: 15px; }
.dificultad small { color: var(--apagado); font-size: 12px; }
.dificultad.elegido { border-color: var(--naranja); background: rgba(255,138,28,.18); }
.botones { display: flex; flex-direction: column; gap: 10px; align-items: center; margin-top: 16px; }
.principal, .secundario {
    min-width: 240px; padding: 14px 24px; border-radius: 14px; font-weight: 800; font-size: 19px; touch-action: manipulation;
}
.principal { border: 0; background: linear-gradient(var(--naranja), var(--naranja-osc)); color: #1d0e00; box-shadow: 0 4px 0 #7a3900; }
.principal:active { transform: translateY(2px); box-shadow: 0 2px 0 #7a3900; }
.secundario { border: 2px solid var(--borde); background: transparent; font-size: 16px; }
.record { margin: 10px 0 0; font-weight: 700; color: #ffe066; min-height: 1em; }
.teclas { color: var(--apagado); font-size: 13px; }
kbd { display: inline-block; padding: 1px 6px; border-radius: 5px; border: 1px solid var(--borde); background: rgba(255,255,255,.08); font-family: inherit; }
.volver { color: var(--apagado); font-size: 14px; }
body.tactil .teclas:not(.aviso) { display: none; }

@media (max-width: 600px) {
    #hud .arriba { flex-wrap: wrap; row-gap: 6px; }
    .centro { order: 3; flex-basis: 100%; }
    #bocadillo { top: calc(max(10px, env(safe-area-inset-top)) + 96px); font-size: 14px; }
    #cartel { top: 38%; }
}

@media (max-width: 520px) {
    .caja { padding: 18px 14px; }
    .personajes { gap: 5px; }
    .personaje span { font-size: 11px; }
    #corazones { font-size: 17px; }
    #fase { font-size: 13px; padding: 5px 10px; }
    #puntos { font-size: 14px; }
    .redondo { width: 34px; height: 34px; font-size: 15px; }
    .ranura { width: 40px; height: 40px; font-size: 20px; }
}
