/* ===================================================================
   BLOCK CITY BATTLE BUDDIES — Escenario, HUD y pantallas
   =================================================================== */

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

html, body {
    height: 100%; overflow: hidden;
    background: #10131a;
    font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
    color: #fff;
    -webkit-user-select: none; user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
}

/* ============================ MARCO ============================ */
.frame { position: fixed; inset: 0; display: flex; flex-direction: column; }

.viewport {
    position: relative; flex: 1; overflow: hidden;
    background: linear-gradient(180deg, #4d86e8 0%, #79a6ff 45%, #a9c8ff 78%, #cfe0ff 100%);
}

/* el mundo se escala para que 600 unidades de alto entren en la pantalla */
.world {
    position: absolute; left: 0; bottom: 0;
    width: 100%; height: 600px;
    transform-origin: left bottom;
    will-change: transform;
}
.layer { position: absolute; left: 0; bottom: 0; height: 600px; will-change: transform; }

/* ============================ CIELO ============================ */
.sun {
    position: absolute; top: 40px; right: 8%; width: 64px; height: 64px;
    background: #fff3b0; box-shadow: 0 0 0 6px rgba(255,243,176,.35), 0 0 40px 14px rgba(255,240,150,.45);
    z-index: 0;
}
.cloud {
    position: absolute; background: #fff;
    box-shadow: inset -6px -6px 0 rgba(200,214,235,.6);
    opacity: .95; z-index: 1;
}
.cloud::before, .cloud::after {
    content: ''; position: absolute; background: #fff;
    box-shadow: inset -5px -5px 0 rgba(200,214,235,.6);
}
.cloud::before { top: -14px; left: 22px; width: 46px; height: 16px; }
.cloud::after  { top: -10px; left: 74px; width: 34px; height: 12px; }

/* montañas de fondo */
.mount {
    position: absolute; bottom: 96px; background: #7f9c74;
    box-shadow: inset 8px 8px 0 rgba(255,255,255,.14), inset -10px -10px 0 rgba(0,0,0,.16);
    z-index: 1;
}
.mount::after {
    content:''; position:absolute; top:0; left:0; right:0; height: 26px;
    background: #e9f1f4;
    clip-path: polygon(0 100%, 18% 40%, 34% 78%, 50% 12%, 68% 66%, 84% 34%, 100% 100%);
}
.tree-bg { position: absolute; bottom: 90px; z-index: 1; opacity: .78; }
.tree-bg .tb-trunk { position: absolute; bottom: 0; left: 50%; margin-left: -7px; width: 14px; height: 40px; background: #5d4326; }
.tree-bg .tb-leaf  { position: absolute; bottom: 34px; left: 0; width: 100%; height: 56px; background: #3f7f39;
    box-shadow: inset 5px 5px 0 rgba(255,255,255,.12), inset -6px -6px 0 rgba(0,0,0,.2); }

/* ============================ BLOQUES ============================ */
.blk {
    position: absolute; z-index: 3;
    box-shadow: inset 3px 3px 0 rgba(255,255,255,.14), inset -3px -4px 0 rgba(0,0,0,.26);
}
/* césped + tierra */
.blk.grass {
    background:
        repeating-linear-gradient(90deg, rgba(0,0,0,.05) 0 12px, transparent 12px 24px),
        linear-gradient(180deg, #6aae4a 0 14px, #7b5a37 14px 100%);
}
.blk.grass::after {
    content:''; position:absolute; top:0; left:0; right:0; height: 16px;
    background: repeating-linear-gradient(90deg, #7cc25a 0 8px, #6fb551 8px 16px);
    box-shadow: inset 0 -3px 0 rgba(0,0,0,.16);
}
.blk.dirt  { background: repeating-linear-gradient(90deg, #7b5a37 0 10px, #745332 10px 20px); }
.blk.stone { background: repeating-linear-gradient(45deg, #8b8b8b 0 10px, #7f7f7f 10px 20px); }
.blk.wood  { background: repeating-linear-gradient(90deg, #a1793f 0 9px, #96703a 9px 18px); }
.blk.leaf  {
    background: repeating-linear-gradient(45deg, #3f8f3a 0 7px, #47a041 7px 14px);
    box-shadow: inset 3px 3px 0 rgba(255,255,255,.12), inset -3px -4px 0 rgba(0,0,0,.24);
}
.blk.log   {
    background: repeating-linear-gradient(0deg, #6b4d2b 0 10px, #5f4425 10px 20px);
    box-shadow: inset 3px 0 0 rgba(255,255,255,.12), inset -4px 0 0 rgba(0,0,0,.25);
}
.blk.plank { background: repeating-linear-gradient(0deg, #b9884b 0 8px, #a87a41 8px 16px); }
.blk.water {
    background: linear-gradient(180deg, rgba(60,120,220,.85), rgba(30,80,180,.9));
    box-shadow: inset 0 3px 0 rgba(255,255,255,.3);
    animation: waterWave 2.4s ease-in-out infinite; z-index: 2;
}
@keyframes waterWave { 0%,100% { filter: brightness(1) } 50% { filter: brightness(1.12) } }
.blk.lava {
    background: linear-gradient(180deg, #ffb03a, #e0500f);
    box-shadow: inset 0 4px 0 rgba(255,240,150,.5); z-index: 2;
    animation: lavaGlow 1.6s ease-in-out infinite;
}
@keyframes lavaGlow { 0%,100% { filter: brightness(1) } 50% { filter: brightness(1.25) } }

/* minerales (se rompen con el pico) */
.blk.ore { background: repeating-linear-gradient(45deg, #8b8b8b 0 10px, #7f7f7f 10px 20px); cursor: pointer; }
.blk.ore .gem { position: absolute; width: 9px; height: 9px; }
.blk.ore .g1 { top: 20%; left: 18%; }
.blk.ore .g2 { top: 55%; left: 55%; }
.blk.ore .g3 { top: 30%; left: 66%; }
.blk.ore.coal    .gem { background: #23232a; box-shadow: inset -2px -2px 0 #000; }
.blk.ore.iron    .gem { background: #d8a883; box-shadow: inset -2px -2px 0 #a97b57; }
.blk.ore.diamond .gem { background: #5decdb; box-shadow: inset -2px -2px 0 #2ab9ae; }
.blk.ore.cracked { filter: brightness(.85); }
.blk.ore.cracked::after {
    content:''; position:absolute; inset:0;
    background:
        linear-gradient(72deg, transparent 47%, rgba(0,0,0,.55) 47% 51%, transparent 51%),
        linear-gradient(-40deg, transparent 60%, rgba(0,0,0,.45) 60% 63%, transparent 63%);
}

/* cofre */
.chest { position: absolute; z-index: 4; width: 40px; height: 34px; }
.chest .ch-lid  { position:absolute; top:0; left:0; width:100%; height:12px; background:#b5772f;
    box-shadow: inset 2px 2px 0 rgba(255,255,255,.2), inset -2px -2px 0 rgba(0,0,0,.3); }
.chest .ch-box  { position:absolute; top:12px; left:0; width:100%; height:22px; background:#a0672a;
    box-shadow: inset 2px 2px 0 rgba(255,255,255,.16), inset -2px -3px 0 rgba(0,0,0,.32); }
.chest .ch-lock { position:absolute; top:8px; left:50%; margin-left:-5px; width:10px; height:10px; background:#d9d9d9;
    box-shadow: inset -2px -2px 0 #8f8f8f; z-index:2; }
.chest.open .ch-lid { transform: translateY(-10px) rotate(-14deg); transform-origin: left bottom; }
.chest.open { animation: chestPop .4s ease-out; }
@keyframes chestPop { 0% { transform: scale(1) } 50% { transform: scale(1.15) } 100% { transform: scale(1) } }

/* portal de fin de nivel (marco de obsidiana + remolino morado) */
.portal { position: absolute; z-index: 3; width: 100px; height: 160px; }
.portal .po-frame { position:absolute; inset:0; background:#1b1224;
    box-shadow: inset 3px 3px 0 rgba(255,255,255,.1), inset -3px -3px 0 rgba(0,0,0,.5); }
.portal .po-inner {
    position:absolute; top:20px; left:20px; right:20px; bottom:20px;
    background: linear-gradient(180deg,#8a3fd6,#5b1fa0);
    animation: poSwirl 2.2s ease-in-out infinite;
    box-shadow: 0 0 30px 8px rgba(150,70,230,.6);
}
@keyframes poSwirl { 0%,100% { filter: brightness(1) hue-rotate(0) } 50% { filter: brightness(1.35) hue-rotate(25deg) } }

/* ============================ ENTIDADES ============================ */
.ent { position: absolute; left: 0; bottom: 0; z-index: 10; transform-origin: bottom center; will-change: transform; }
.ent.dying { animation: entDie .5s ease-in forwards; pointer-events: none; }
@keyframes entDie { to { transform: rotate(80deg) scale(.5); opacity: 0; } }

/* burbuja de diálogo de los aliados */
.bubble {
    position: absolute; bottom: 100%; left: 50%; transform: translate(-50%, -12px);
    background: #f4f0e4; color: #2a2116; padding: 8px 12px; width: max-content; max-width: 260px;
    font-size: 15px; font-weight: 700; line-height: 1.35; text-align: center;
    border: 3px solid #2a2116; box-shadow: 4px 4px 0 rgba(0,0,0,.35);
    z-index: 25; opacity: 0; pointer-events: none; transition: opacity .25s;
}
.bubble.show { opacity: 1; animation: bubblePop .3s ease-out; }
@keyframes bubblePop { 0% { transform: translate(-50%,-4px) scale(.8) } 100% { transform: translate(-50%,-12px) scale(1) } }
.bubble::after {
    content:''; position:absolute; bottom:-11px; left:50%; margin-left:-8px;
    width:0; height:0; border-left:8px solid transparent; border-right:8px solid transparent;
    border-top:10px solid #2a2116;
}
.ally-mark {
    position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%);
    font-size: 22px; animation: markBob 1.4s ease-in-out infinite;
}
@keyframes markBob { 0%,100% { transform: translate(-50%,0) } 50% { transform: translate(-50%,-8px) } }

/* flecha del arco */
.arrow-p { position: absolute; left: 0; bottom: 0; z-index: 12; width: 26px; height: 6px; }
.arrow-p .a-shaft { position:absolute; left:4px; top:2px; width:18px; height:3px; background:#c9a15e; }
.arrow-p .a-tip   { position:absolute; right:0; top:0; width:7px; height:6px; background:#cfd6db;
    clip-path: polygon(0 0,100% 50%,0 100%); }
.arrow-p .a-fletch{ position:absolute; left:0; top:-1px; width:6px; height:8px; background:#f0f0f0; }

/* partículas de daño / recogida */
.pop {
    position: absolute; z-index: 30; font-weight: 900; font-size: 20px; color: #fff;
    text-shadow: 2px 2px 0 #000; pointer-events: none;
    animation: popUp .9s ease-out forwards;
}
.pop.heal { color: #7dff8a; }
.pop.gem  { color: #6ff0e4; }
@keyframes popUp { to { transform: translateY(-46px); opacity: 0; } }

.particle { position: absolute; z-index: 28; width: 7px; height: 7px; pointer-events: none;
    animation: partFly .6s ease-out forwards; }
@keyframes partFly { to { transform: translate(var(--dx), var(--dy)); opacity: 0; } }

/* destello rojo cuando el jugador recibe daño */
.dmg-flash {
    position: absolute; inset: 0; z-index: 50; pointer-events: none;
    background: radial-gradient(circle, transparent 40%, rgba(190,20,20,.55) 100%);
    opacity: 0;
}
.dmg-flash.on { animation: flashHit .4s ease-out; }
@keyframes flashHit { 0% { opacity: 1 } 100% { opacity: 0 } }

/* ============================ HUD ============================ */
.hud {
    position: absolute; top: 0; left: 0; right: 0; z-index: 60;
    display: flex; justify-content: space-between; align-items: flex-start;
    padding: 10px 12px; gap: 10px; pointer-events: none;
}
.hud-left, .hud-right { display: flex; flex-direction: column; gap: 6px; }
.hud-left { margin-top: 30px; }
.hud-right { align-items: flex-end; }

.hearts { display: flex; gap: 3px; }
.heart {
    position: relative; width: 20px; height: 18px; background: #e03636;
    filter: drop-shadow(2px 2px 0 rgba(0,0,0,.55));
    clip-path: polygon(
        22% 0%, 45% 0%, 45% 12%, 55% 12%, 55% 0%, 78% 0%, 78% 12%,
        89% 12%, 89% 24%, 100% 24%, 100% 53%, 89% 53%, 89% 65%,
        78% 65%, 78% 77%, 67% 77%, 67% 88%, 55% 88%, 55% 100%,
        45% 100%, 45% 88%, 33% 88%, 33% 77%, 22% 77%, 22% 65%,
        11% 65%, 11% 53%, 0% 53%, 0% 24%, 11% 24%, 11% 12%, 22% 12%
    );
}
.heart.empty { background: #4b2222; }
.heart.half::after {
    content: ''; position: absolute; top: 0; right: 0; width: 50%; height: 100%; background: #4b2222;
}
.heart.beat { animation: heartBeat .5s ease-out; }
@keyframes heartBeat { 0%,100% { transform: scale(1) } 40% { transform: scale(1.35) } }

/* vidas por partida */
.lives { display: flex; align-items: center; gap: 4px; }
.lives-label {
    font-size: 11px; font-weight: 900; letter-spacing: 1px; opacity: .9;
    text-shadow: 1px 1px 0 #000; margin-right: 2px;
}
.life {
    position: relative; width: 18px; height: 18px; background: #d8a373;
    box-shadow: inset -2px -2px 0 rgba(0,0,0,.28);
    filter: drop-shadow(2px 2px 0 rgba(0,0,0,.55));
}
.life::before { content:''; position:absolute; top:0; left:0; right:0; height:5px; background:#5a3b1d; }
.life::after  { content:''; position:absolute; top:8px; left:3px; width:3px; height:4px; background:#f6f6f6;
    box-shadow: 4px 0 0 #3b2a86, 8px 0 0 #f6f6f6, 12px 0 0 #3b2a86; }
.life.gone { filter: grayscale(1) brightness(.35); }

.hud-chip {
    background: rgba(15,18,26,.72); border: 2px solid rgba(255,255,255,.28);
    padding: 4px 10px; font-size: 14px; font-weight: 800; letter-spacing: .5px;
    display: flex; align-items: center; gap: 6px; text-shadow: 1px 1px 0 #000;
}
.hud-chip b { color: #ffd86b; }

/* hotbar de armas */
.hotbar {
    position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%); z-index: 60;
    display: flex; gap: 6px; padding: 6px; background: rgba(15,18,26,.68);
    border: 3px solid rgba(255,255,255,.25);
}
.slot {
    position: relative; width: 54px; height: 54px; background: rgba(120,120,120,.35);
    border: 3px solid rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center;
    cursor: pointer; pointer-events: auto;
}
.slot.locked { filter: grayscale(1) brightness(.45); }
.slot.active { border-color: #fff; box-shadow: 0 0 0 3px rgba(255,255,255,.35), inset 0 0 14px rgba(255,255,255,.25); }
.slot .key {
    position: absolute; top: -2px; left: 2px; font-size: 12px; font-weight: 900; color: #ffd86b;
    text-shadow: 1px 1px 0 #000;
}
.slot .ammo {
    position: absolute; bottom: -2px; right: 3px; font-size: 13px; font-weight: 900; color: #fff;
    text-shadow: 1px 1px 0 #000;
}
.slot .wpn { position: static; transform: scale(1.35) rotate(-40deg); width: 22px; height: 26px; }
.slot .icon-fist {
    width: 22px; height: 24px; background: #d8a373;
    box-shadow: inset 2px 2px 0 rgba(255,255,255,.25), inset -2px -3px 0 rgba(0,0,0,.3);
    position: relative;
}
.slot .icon-fist::after { content:''; position:absolute; bottom:4px; left:2px; width:18px; height:4px; background: rgba(0,0,0,.2); }

/* botón de música */
.music-btn {
    position: absolute; top: 10px; left: 50%; transform: translateX(-50%); z-index: 61;
    width: 40px; height: 40px; font-size: 20px; cursor: pointer; pointer-events: auto;
    background: rgba(15,18,26,.72); border: 2px solid rgba(255,255,255,.28); color: #fff;
}

/* volver al inicio */
.back-home {
    position: fixed; top: 10px; left: 12px; z-index: 200;
    background: rgba(15,18,26,.8); color: #fff; text-decoration: none;
    padding: 6px 12px; font-size: 13px; font-weight: 800;
    border: 2px solid rgba(255,255,255,.3);
}
.back-home:hover { background: #2f6fd0; }

/* ============================ CONTROLES TÁCTILES ============================ */
.touch { position: absolute; inset: 0; z-index: 55; pointer-events: none; display: none; }
body.is-touch .touch { display: block; }
.tbtn {
    position: absolute; pointer-events: auto;
    background: rgba(255,255,255,.16); border: 3px solid rgba(255,255,255,.4);
    color: #fff; font-size: 26px; font-weight: 900;
    display: flex; align-items: center; justify-content: center;
    width: 66px; height: 66px;
}
.tbtn:active, .tbtn.on { background: rgba(255,255,255,.42); }
.tbtn.left  { left: 14px;  bottom: 82px; }
.tbtn.right { left: 92px;  bottom: 82px; }
.tbtn.jump  { right: 100px; bottom: 96px; background: rgba(110,220,140,.28); }
.tbtn.hit   { right: 16px;  bottom: 80px; width: 78px; height: 78px; background: rgba(240,110,110,.3); font-size: 30px; }
.tbtn.swap  { right: 24px;  bottom: 176px; width: 56px; height: 56px; font-size: 20px; }

/* ============================ PANTALLAS ============================ */
.screen {
    position: absolute; inset: 0; z-index: 100;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    text-align: center; padding: 20px; gap: 14px;
    background: rgba(10,14,22,.9);
}
.screen[hidden] { display: none; }
.screen h1 {
    font-size: clamp(28px, 6vw, 54px); letter-spacing: 2px; line-height: 1.1;
    text-shadow: 4px 4px 0 #2c1d10, 0 0 26px rgba(120,220,120,.4);
}
.screen h1 span { color: #7cc25a; }
.screen p { font-size: clamp(14px, 2.4vw, 18px); max-width: 620px; line-height: 1.55; opacity: .92; }
.btn {
    background: #6aae4a; color: #fff; border: 4px solid #3d6b2b;
    padding: 12px 28px; font-size: 20px; font-weight: 900; letter-spacing: 1px; cursor: pointer;
    box-shadow: 0 6px 0 #3d6b2b; font-family: inherit;
}
.btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #3d6b2b; }
.btn.alt { background: #4a7ec9; border-color: #2c5290; box-shadow: 0 6px 0 #2c5290; }

.keys-help {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 8px 18px; max-width: 680px; font-size: 14px; text-align: left; margin-top: 4px;
}
.keys-help div { background: rgba(255,255,255,.07); padding: 7px 10px; border-left: 4px solid #7cc25a; }
.keys-help kbd {
    background: #f0ede4; color: #1a1a1a; padding: 1px 7px; font-weight: 900;
    border-bottom: 3px solid #9a9585; font-family: inherit; font-size: 13px;
}

.cast { display: flex; gap: 22px; flex-wrap: wrap; justify-content: center; margin: 6px 0; }
.cast figure { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.cast figcaption { font-size: 12px; font-weight: 800; letter-spacing: .5px; }
.cast .tag { font-size: 10px; opacity: .7; font-weight: 600; letter-spacing: 0; }

/* aviso de girar el celular */
#rotate-hint {
    position: fixed; inset: 0; z-index: 300; display: none;
    flex-direction: column; align-items: center; justify-content: center; gap: 12px;
    background: #10131a; text-align: center; padding: 24px;
}
.rotate-phone { font-size: 60px; animation: rotPhone 1.8s ease-in-out infinite; }
@keyframes rotPhone { 0%,40% { transform: rotate(0) } 60%,100% { transform: rotate(90deg) } }
@media (max-aspect-ratio: 1/1) and (pointer: coarse) {
    body.playing #rotate-hint { display: flex; }
}

@media (max-width: 620px) {
    .slot { width: 44px; height: 44px; }
    .heart { width: 16px; height: 14px; }
}
