: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; }
#menu { left: 244px; right: 132px; top: 6px; display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; }
#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; } }

@media (max-width: 720px) {
  #menu { top: 4px; left: 0; right: 0; justify-content: center; gap: 2px; }
  #menu button { font-size: 16px; padding: 1px 5px; }
  #bars, #topright { top: 62px; }
  #toasts { top: 172px; }
  #bossbar { top: 150px; }
  .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; }
.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; }

/* ---------- 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; }


/* ---------- Añadidos del kit marajastyle ---------- */
/* Logo del título: palabras apiladas en Press Start 2P con sombra en dos capas (como MARAJA ONLINE). */
.t-box .menu { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-top: 10px; }
.t-box .menu button { min-width: 220px; }
/* Ventana modal pequeña (confirmaciones, pausa) con el mismo marco que #panel. */
.modal { position: fixed; z-index: 40; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(380px, 92vw); background: var(--panel); border: 3px solid #0b0a12; outline: 2px solid var(--line); border-radius: 6px; padding: 12px; text-align: center; }
.modal h3 { font-size: 12px; color: var(--gold); margin: 0 0 10px; }

/* ---------- Maraja City Builder ---------- */
/* Recursos arriba a la derecha con sus iconos. */
.res { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; font-size: 22px; }
.res span { display: flex; align-items: center; gap: 2px; background: #17131fd9; border: 2px solid #0b0a12; border-radius: 4px; padding: 0 6px 0 2px; }
.res img { width: 24px; height: 24px; }
#topright { max-width: min(520px, 60vw); }
#zone { margin-top: 4px; }
/* Barra de construcción (como la de Maraja). */
#buildbar { left: 0; right: 0; bottom: 0; background: #17131ff2; border-top: 2px solid var(--line); padding: 6px max(6px, env(safe-area-inset-left)) max(6px, env(safe-area-inset-bottom)); display: flex; gap: 5px; overflow-x: auto; touch-action: pan-x; align-items: stretch; justify-content: center; }
#buildbar button { flex: 0 0 auto; font-size: 18px; line-height: 1.05; text-align: left; padding: 3px 8px; display: flex; align-items: center; gap: 6px; }
#buildbar button img { width: 32px; height: 32px; }
#buildbar button b { color: var(--gold); font-weight: 400; }
#buildbar button.pk { border-style: dashed; align-self: center; padding: 6px 10px; }
#buildbar small { display: block; color: var(--dim); font-size: 15px; }
#buildbar small.no { color: var(--bad); }
#prompt { bottom: 76px; }
/* Ficha del edificio en la vista interior. */
#inside { left: 50%; bottom: max(10px, env(safe-area-inset-bottom)); transform: translateX(-50%); width: min(560px, 96vw); background: var(--panel); border: 3px solid #0b0a12; outline: 2px solid var(--line); border-radius: 6px; padding: 8px 12px; }
#inside .ih { display: flex; align-items: center; gap: 8px; }
#inside .ih img { width: 32px; height: 32px; }
#inside h4 { margin: 0; color: var(--gold); font-weight: 400; font-size: 24px; }
#inside .row button { min-width: 36px; }
/* La cámara se mueve arrastrando: no hace falta joystick. */
#touch { display: none !important; }
@media (max-width: 720px) {
  .res { gap: 4px; font-size: 19px; } .res img { width: 20px; height: 20px; }
  #topright { left: 8px; right: 8px; top: 46px; max-width: none; }
  .res { justify-content: center; }
  #bars { top: 82px; } #zone { position: fixed; right: 8px; top: 82px; }
  #buildbar { justify-content: flex-start; }
  #buildbar button { font-size: 16px; padding: 2px 6px; }
}
