:root {
  --bg: #14111c; --panel: #241f31; --panel2: #2f2940; --line: #4a4160; --ink: #e8e4d0; --dim: #9a93ad;
  --gold: #ffe07a; --hp: #e0403a; --mp: #3a7ae0; --xp: #c084fc; --ok: #4ade80; --bad: #f87171;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #000; color: var(--ink); font-family: VT323, monospace; font-size: 20px; user-select: none; -webkit-user-select: none; touch-action: none; overscroll-behavior: none; }
canvas#game { position: fixed; left: 0; top: 0; image-rendering: pixelated; image-rendering: crisp-edges; background: #000; }
canvas#overlay { position: fixed; left: 0; top: 0; pointer-events: none; }
.hidden { display: none !important; }
img, .px { image-rendering: pixelated; }
h1, h2, h3, .pix { font-family: 'Press Start 2P', monospace; font-weight: 400; }
button { font-family: VT323, monospace; font-size: 20px; color: var(--ink); background: var(--panel2); border: 2px solid var(--line); border-bottom-width: 4px; border-radius: 4px; padding: 4px 10px; cursor: pointer; }
button:hover { background: #3a3350; }
button:active { border-bottom-width: 2px; transform: translateY(2px); }
button.sel { border-color: var(--gold); color: var(--gold); }
button.primary { background: #3d6b3a; border-color: #2a4a28; }
button.primary:hover { background: #4a8246; }
button.danger { background: #6b3a3a; border-color: #4a2828; }
button:disabled { opacity: .45; cursor: default; }
input[type=text] { font-family: VT323, monospace; font-size: 24px; color: var(--ink); background: #17131f; border: 2px solid var(--line); border-radius: 4px; padding: 4px 8px; width: 100%; user-select: text; -webkit-user-select: text; }

/* ---------- HUD ---------- */
#hud > * { position: fixed; z-index: 5; }
#bars { left: max(8px, env(safe-area-inset-left)); top: 8px; width: min(230px, 46vw); }
.who { display: flex; justify-content: space-between; text-shadow: 0 2px 0 #000; font-size: 22px; line-height: 1; margin-bottom: 3px; }
#h-lvl { color: var(--gold); }
.bar { position: relative; height: 16px; background: #17131fd9; border: 2px solid #0b0a12; margin-bottom: 2px; }
.bar i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; }
.bar span { position: absolute; inset: 0; text-align: center; font-size: 15px; line-height: 12px; text-shadow: 0 1px 0 #000, 1px 0 0 #000; }
.bar.hp i { background: var(--hp); } .bar.mp i { background: var(--mp); } .bar.xp i { background: var(--xp); }
.bar.xp { height: 10px; } .bar.xp span { font-size: 12px; line-height: 6px; }
#buffs { display: flex; gap: 4px; flex-wrap: wrap; font-size: 15px; }
#buffs span { background: #17131fd9; border: 1px solid var(--gold); color: var(--gold); padding: 0 4px; }
#topright { right: max(8px, env(safe-area-inset-right)); top: 8px; text-align: right; text-shadow: 0 2px 0 #000; font-size: 18px; line-height: 1.05; }
#minimap { width: 112px; height: 112px; border: 2px solid #0b0a12; outline: 2px solid var(--line); image-rendering: pixelated; display: block; margin-left: auto; margin-bottom: 4px; background: #000; }
#clock { color: var(--dim); }
#menu { left: 50%; top: 6px; transform: translateX(-50%); display: flex; gap: 4px; }
#menu button { position: relative; font-size: 17px; padding: 2px 7px; background: #241f31e6; }
#menu i { position: absolute; right: -4px; top: -4px; width: 10px; height: 10px; background: var(--gold); border: 2px solid #0b0a12; border-radius: 50%; display: none; }
#menu i.on { display: block; }
#bossbar { left: 50%; top: 96px; transform: translateX(-50%); width: min(420px, 80vw); text-align: center; color: #f6757a; text-shadow: 0 2px 0 #000; pointer-events: none; }
#bossbar .bar { height: 14px; } #bossbar .bar i { background: linear-gradient(#f6757a, #a22633); }
#prompt { left: 50%; bottom: 84px; transform: translateX(-50%); background: #17131fe6; border: 2px solid var(--line); padding: 2px 12px; border-radius: 4px; white-space: nowrap; }
#prompt b { color: var(--gold); font-weight: 400; }
#skillbar { left: 50%; bottom: max(8px, env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; gap: 6px; }
.sk { position: relative; width: 52px; height: 52px; background: #241f31e6; border: 2px solid var(--line); border-radius: 6px; padding: 0; overflow: hidden; }
.sk img { width: 32px; height: 32px; margin-top: 4px; }
.sk .key { position: absolute; left: 3px; top: 0; font-size: 15px; color: var(--gold); text-shadow: 0 1px 0 #000; }
.sk .cnt { position: absolute; right: 3px; bottom: -2px; font-size: 16px; text-shadow: 0 1px 0 #000; }
.sk .cd { position: absolute; left: 0; right: 0; bottom: 0; background: #000000b0; height: 0; }
.sk.locked img { filter: grayscale(1) brightness(.5); }
.sk.nomp { border-color: #3a4a7a; } .sk.nomp img { filter: saturate(.3); }
.sk.sep { margin-left: 8px; }
#toasts { left: 50%; top: 52px; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 3px; pointer-events: none; width: 92vw; }
.toast { background: #17131fe6; border: 2px solid var(--line); padding: 1px 12px; border-radius: 4px; animation: toast 4s forwards; text-align: center; }
@keyframes toast { 0% { opacity: 0; transform: translateY(-6px); } 6% { opacity: 1; transform: none; } 85% { opacity: 1; } 100% { opacity: 0; } }
#buildbar { left: 0; right: 0; bottom: 0; background: #17131ff2; border-top: 2px solid var(--line); padding: 6px; display: flex; gap: 5px; overflow-x: auto; touch-action: pan-x; align-items: stretch; }
#buildbar button { flex: 0 0 auto; font-size: 17px; line-height: 1.05; text-align: left; padding: 3px 8px; }
#buildbar small { display: block; color: var(--dim); font-size: 15px; }
#buildbar small.no { color: var(--bad); }

@media (max-width: 720px) {
  #menu { top: 4px; width: 100%; justify-content: center; gap: 2px; }
  #menu button { font-size: 16px; padding: 1px 5px; }
  #bars, #topright { top: 38px; }
  #minimap { width: 88px; height: 88px; }
  .sk { width: 46px; height: 46px; } .sk img { margin-top: 2px; }
  #skillbar { gap: 4px; }
}

/* ---------- Controles táctiles ---------- */
#touch > * { position: fixed; z-index: 6; }
#joy { left: max(18px, env(safe-area-inset-left)); bottom: 78px; width: 124px; height: 124px; border-radius: 50%; background: #ffffff14; border: 2px solid #ffffff30; touch-action: none; }
#stick { position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px; border-radius: 50%; background: #ffffff40; border: 2px solid #ffffff70; }
#btn-atk, #btn-act { border-radius: 50%; border: 2px solid #ffffff70; background: #7a2a2aa0; touch-action: none; padding: 0; }
#btn-atk { right: max(18px, env(safe-area-inset-right)); bottom: 84px; width: 86px; height: 86px; font-size: 22px; }
#btn-act { right: max(112px, calc(env(safe-area-inset-right) + 94px)); bottom: 150px; width: 70px; height: 70px; background: #2a5a7aa0; font-size: 18px; line-height: 1; }
body.touch #prompt { display: none !important; }
body.touch #skillbar { bottom: max(6px, env(safe-area-inset-bottom)); }

/* ---------- Paneles ---------- */
#panel { position: fixed; z-index: 20; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(720px, 96vw); max-height: min(560px, 92vh); background: var(--panel); border: 3px solid #0b0a12; outline: 2px solid var(--line); border-radius: 6px; display: flex; flex-direction: column; box-shadow: 0 10px 40px #000a; }
.p-head { display: flex; align-items: center; gap: 4px; padding: 6px; border-bottom: 2px solid var(--line); background: #1c1826; flex-wrap: wrap; }
.p-head h3 { font-size: 12px; margin: 0 6px; color: var(--gold); flex: 1; }
.p-head .tabs { display: flex; gap: 3px; flex: 1; flex-wrap: wrap; }
.p-head button { font-size: 18px; padding: 1px 8px; }
.p-body { padding: 10px; overflow-y: auto; touch-action: pan-y; flex: 1; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 560px) { .cols { grid-template-columns: 1fr; } html, body { font-size: 18px; } }
.box { background: #1c1826; border: 2px solid var(--line); border-radius: 4px; padding: 8px; }
.box h4 { margin: 0 0 4px; color: var(--gold); font-weight: 400; font-size: 22px; }
.row { display: flex; align-items: center; gap: 8px; padding: 2px 0; }
.row .g { flex: 1; } .dim { color: var(--dim); } .gold { color: var(--gold); } .ok { color: var(--ok); } .bad { color: var(--bad); }
.small { font-size: 17px; line-height: 1.05; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, 44px); gap: 4px; }
.slot { position: relative; width: 44px; height: 44px; background: #17131f; border: 2px solid var(--line); border-radius: 4px; cursor: pointer; }
.slot img { width: 32px; height: 32px; margin: 4px; display: block; }
.slot b { position: absolute; right: 2px; bottom: -3px; font-weight: 400; font-size: 17px; text-shadow: 0 1px 0 #000, 1px 0 0 #000; }
.slot.sel { outline: 2px solid var(--gold); }
.slot.glow3 { box-shadow: 0 0 8px 1px #c084fc, inset 0 0 8px #c084fc66; animation: glow 1.6s ease-in-out infinite; }
.slot.glow4 { box-shadow: 0 0 10px 2px #fb923c, inset 0 0 10px #fb923c88; animation: glow 1.1s ease-in-out infinite; }
@keyframes glow { 50% { filter: brightness(1.45); box-shadow: 0 0 14px 3px currentColor; } }
.slot.glow3 { color: #c084fc; } .slot.glow4 { color: #fb923c; } .slot.glow3 b, .slot.glow4 b { color: var(--ink); }
.shine { text-shadow: 0 0 8px currentColor; }
.slot.empty { cursor: default; opacity: .5; }
.slot .lbl { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; line-height: .9; font-size: 13px; color: var(--dim); }
.pbar { height: 8px; background: #17131f; border: 1px solid var(--line); } .pbar i { display: block; height: 100%; background: #7af0ff; }
.portrait { width: 96px; height: 100px; background: #17131f; border: 2px solid var(--line); border-radius: 4px; flex: 0 0 auto; }
.cmp { margin: 6px 0; padding: 4px 8px; }
.btns { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.speech { background: #f5f0e0; color: #1b1622; border-radius: 4px; padding: 6px 10px; margin: 8px 0; font-size: 22px; line-height: 1.1; border: 2px solid #0b0a12; }
.rec { display: flex; align-items: center; gap: 8px; padding: 4px; border-bottom: 1px solid #3a3350; }
.rec .g { flex: 1; line-height: 1.05; }
.rec.locked { opacity: .5; }
#mapcv { width: 100%; image-rendering: pixelated; border: 2px solid var(--line); background: #0b0a12; display: block; }

/* ---------- Pantalla de título ---------- */
#title { position: fixed; inset: 0; z-index: 30; background: radial-gradient(ellipse at 50% 30%, #2c2440, #0d0b14 75%); display: flex; align-items: flex-start; justify-content: center; overflow-y: auto; touch-action: pan-y; padding: 16px; }
.t-box { width: min(760px, 100%); margin: auto; text-align: center; }
.t-box h1 { font-size: clamp(20px, 5vw, 38px); color: var(--gold); text-shadow: 0 4px 0 #6a3a1a, 0 8px 0 #000; margin: 12px 0 6px; line-height: 1.3; }
.t-box .sub { color: var(--dim); margin-bottom: 18px; }
.t-box .big { font-size: 26px; padding: 6px 22px; margin: 4px; }
.create { text-align: left; }
.create .opts { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 8px; }
.create label { display: block; color: var(--gold); margin-top: 4px; }
.sw { width: 30px; height: 30px; border-radius: 4px; padding: 0; }
.prev { display: flex; gap: 12px; align-items: center; }
.prev canvas { width: 120px; height: 125px; image-rendering: pixelated; background: #17131f; border: 2px solid var(--line); border-radius: 4px; flex: 0 0 auto; }

/* ---------- Muñeco de equipo ---------- */
.dollhead { display: flex; align-items: center; gap: 8px; background: linear-gradient(#e8c79a, #c9a06a); color: #3e2731; border: 2px solid #733e39; border-radius: 4px; padding: 2px 8px; width: 280px; max-width: 100%; margin: 0 auto 6px; }
.dollhead .gold { color: #733e39; flex: 1; font-size: 22px; }
.dollhead .lv { background: #262b44; color: var(--gold); border: 2px solid #feae34; border-radius: 50%; min-width: 30px; height: 30px; display: grid; place-items: center; }
.doll { position: relative; width: 280px; height: 280px; margin: 0 auto 6px; border: 3px solid #733e39; outline: 2px solid #3e2731; border-radius: 6px;
  background: radial-gradient(circle at 50% 45%, #5a4a52 0, #3a2c34 55%, #2a2030 100%); background-color: #3a2c34; overflow: hidden; }
.doll::before { content: ''; position: absolute; inset: 0; background-image: radial-gradient(#00000030 1px, transparent 1px); background-size: 6px 6px; }
.doll .sil, .doll .sil2 { position: absolute; left: 32px; top: 22px; width: 216px; height: 225px; image-rendering: pixelated; pointer-events: none; }
.doll .sil { filter: brightness(0); opacity: .75; }
.doll .sil2 { opacity: .22; }
.doll .ped { position: absolute; left: 80px; top: 222px; width: 120px; height: 34px; border-radius: 50%; background: radial-gradient(ellipse, #8b9bb4 0, #5a6988 60%, #3a4466 100%); border: 2px solid #262b44; z-index: 0; opacity: .9; }
.doll .sil, .doll .sil2 { z-index: 1; }
.slot.ds { position: absolute; z-index: 2; background: #17131fd9; box-shadow: 0 2px 0 #00000080; }
.slot.ds.empty { opacity: .8; border-style: dashed; }
.slot .sc { position: absolute; left: 2px; top: -3px; font-style: normal; font-size: 14px; color: var(--ok); text-shadow: 0 1px 0 #000, 1px 0 0 #000; }
.slot .up { position: absolute; left: 1px; top: -2px; font-style: normal; font-size: 13px; color: var(--ok); text-shadow: 0 1px 0 #000; }
.bagmini { max-height: 196px; overflow-y: auto; touch-action: pan-y; padding: 2px; }
