:root {
  --ink: #2b1d14;
  --paper: #f6ead2;
  --paper-2: #ead8b4;
  --edge: #6b4526;
  --edge-dark: #3f2815;
  --accent: #3f8f3a;
  --accent-dark: #2a6627;
  --danger: #b33a2e;
  --muted: #7a5f45;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #1d5f96; }
body { font-family: 'Nunito', system-ui, sans-serif; color: var(--ink); -webkit-tap-highlight-color: transparent; }

#view {
  position: fixed; inset: 0; width: 100vw; height: 100vh; display: block;
}
#tags { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.tag {
  position: absolute; left: 0; top: 0; transform: translate(-50%, -100%);
  white-space: nowrap; text-align: center; will-change: transform;
}
.tag .name {
  font: 700 13px/1 'Nunito', sans-serif; color: #fff; padding: 2px 6px; border-radius: 4px;
  background: rgba(30, 20, 12, .55); text-shadow: 0 1px 0 #000;
}
.tag.me .name { background: rgba(42, 102, 39, .8); }
.tag .bubble {
  display: block; margin: 0 auto 4px; max-width: 220px; white-space: normal; width: max-content;
  font: 700 13px/1.3 'Nunito', sans-serif; background: var(--paper); color: var(--ink);
  border: 2px solid var(--edge-dark); border-radius: 6px; padding: 4px 8px; box-shadow: 0 2px 0 var(--edge-dark);
}
.tag .bubble:empty { display: none; }

.hidden { display: none !important; }

.overlay {
  position: fixed; inset: 0; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(ellipse at center, rgba(10, 30, 50, .15), rgba(10, 20, 35, .55));
  overflow-y: auto;
}
.panel {
  background: var(--paper); border: 3px solid var(--edge-dark); border-radius: 10px;
  box-shadow: inset 0 0 0 3px var(--paper-2), 0 6px 0 var(--edge-dark), 0 18px 40px rgba(0,0,0,.35);
}
.auth-panel { width: min(460px, 100%); padding: 22px 22px 20px; margin: auto; }
.logo {
  margin: 0; text-align: center; font: 700 44px/1 'Pixelify Sans', sans-serif; letter-spacing: 3px;
  color: #ffe9a8; -webkit-text-stroke: 2px var(--edge-dark); paint-order: stroke fill;
  text-shadow: 0 4px 0 var(--edge-dark);
}
.tagline { text-align: center; margin: 8px 0 16px; color: var(--muted); font-weight: 700; }

.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 14px; }
.tab {
  font: 800 15px 'Nunito', sans-serif; padding: 9px; border-radius: 6px; cursor: pointer;
  border: 2px solid var(--edge); background: var(--paper-2); color: var(--muted);
}
.tab.active { background: var(--edge); color: var(--paper); }

.form { display: grid; gap: 10px; }
.form label { display: grid; gap: 4px; font-weight: 800; font-size: 14px; }
.form input {
  font: 700 16px 'Nunito', sans-serif; padding: 10px 12px; border-radius: 6px;
  border: 2px solid var(--edge); background: #fffaf0; color: var(--ink); min-height: 44px;
}
.form input:focus { outline: 3px solid #e8b04a; outline-offset: 1px; }
.error { margin: 0; min-height: 1.2em; color: var(--danger); font-weight: 800; font-size: 14px; }

.btn {
  font: 800 16px 'Nunito', sans-serif; min-height: 46px; border-radius: 8px; cursor: pointer;
  border: 2px solid var(--edge-dark); padding: 10px 16px;
}
.btn.primary { background: var(--accent); color: #fff; box-shadow: 0 4px 0 var(--accent-dark); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.primary:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--accent-dark); }
.btn:disabled { opacity: .6; cursor: wait; }

.pick-title { font-weight: 800; font-size: 14px; margin-top: 4px; }
.picks { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.pick {
  display: grid; justify-items: center; gap: 2px; padding: 8px 4px; cursor: pointer; min-width: 0;
  border: 2px solid var(--paper-2); border-radius: 8px; background: #fffaf0; font: 800 13px 'Nunito', sans-serif; color: var(--ink);
}
.pick canvas { width: 72px; height: 72px; image-rendering: pixelated; }
.pick small { font-weight: 700; color: var(--muted); font-size: 11px; }
.pick.selected { border-color: var(--accent); background: #e9f5dc; box-shadow: 0 0 0 2px var(--accent) inset; }

/* HUD */
#hud { position: fixed; inset: 0; pointer-events: none; }
.hud-top { position: absolute; top: 12px; left: 12px; right: 12px; display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  pointer-events: auto; font: 800 14px 'Nunito', sans-serif; color: var(--paper);
  background: rgba(43, 29, 20, .78); border: 2px solid var(--edge-dark); border-radius: 6px; padding: 6px 10px;
}
.btn-chip { cursor: pointer; margin-left: auto; min-height: 36px; }
.btn-chip:hover { background: rgba(107, 69, 38, .9); }

#chat { position: absolute; left: 12px; bottom: 12px; width: min(360px, calc(100vw - 24px)); pointer-events: auto; }
#chatLog { list-style: none; margin: 0 0 6px; padding: 0; display: grid; gap: 3px; max-height: 190px; overflow: hidden; }
#chatLog li {
  font: 700 14px/1.3 'Nunito', sans-serif; color: #fff; text-shadow: 0 1px 0 #000;
  background: rgba(20, 14, 10, .5); padding: 3px 8px; border-radius: 4px; width: fit-content; max-width: 100%;
  overflow-wrap: anywhere; transition: opacity .6s;
}
#chatLog li b { color: #ffe08a; }
#chatLog li.sys { color: #bfe6ff; font-style: italic; }
#chatLog li.old { opacity: 0; }
#chat:focus-within #chatLog li.old { opacity: 1; }
#chatInput {
  width: 100%; font: 700 15px 'Nunito', sans-serif; padding: 8px 10px; min-height: 40px; border-radius: 6px;
  border: 2px solid var(--edge-dark); background: rgba(246, 234, 210, .85); color: var(--ink);
}
#chatInput:focus { outline: none; background: var(--paper); }

.help {
  position: absolute; right: 12px; top: 56px; font: 700 13px 'Nunito', sans-serif; color: #fff;
  text-shadow: 0 1px 0 #000; background: rgba(20, 14, 10, .45); padding: 6px 10px; border-radius: 6px; max-width: 45vw;
}

#stick {
  position: absolute; right: 24px; bottom: 90px; width: 120px; height: 120px; border-radius: 50%;
  background: rgba(20, 14, 10, .3); border: 2px solid rgba(255,255,255,.35); pointer-events: auto; touch-action: none;
}
#stickKnob {
  position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px; border-radius: 50%;
  background: rgba(246, 234, 210, .85); border: 2px solid var(--edge-dark);
}
#chatBtn {
  position: absolute; right: 24px; top: 64px; width: 48px; height: 48px; border-radius: 8px; pointer-events: auto;
  background: rgba(43, 29, 20, .78); border: 2px solid var(--edge-dark); color: var(--paper); display: grid; place-items: center;
}

#toast {
  position: fixed; top: 64px; left: 50%; transform: translateX(-50%); z-index: 10;
  font: 800 15px 'Nunito', sans-serif; background: var(--paper); border: 2px solid var(--edge-dark);
  border-radius: 8px; padding: 10px 16px; box-shadow: 0 4px 0 var(--edge-dark); max-width: calc(100vw - 32px);
}

@media (max-width: 640px) {
  .logo { font-size: 36px; }
  .help { display: none; }
  #chatLog { max-height: 120px; }
  #chatLog li { font-size: 13px; }
  .pick canvas { width: 56px; height: 56px; }
}
@media (pointer: coarse) { .help { display: none; } }

/* ---------- v0.2: combate, equipo y ficha ---------- */
.tag .hpbar { display: block; width: 44px; height: 5px; margin: 3px auto 0; background: rgba(20, 14, 10, .7); border-radius: 3px; overflow: hidden; }
.tag .hpbar i { display: block; height: 100%; width: 100%; background: #6fd35a; transition: width .15s; }
.tag .hpbar.low i { background: #e8633a; }
.tag.mob .name { background: rgba(60, 20, 20, .6); font-size: 12px; }
.tag.mob .name .type { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 4px; vertical-align: 0; }
.tag.pet .name { display: none; }
.tag.pet .hpbar { width: 34px; }
.tag .eco { color: #ffe08a; }

.dmg {
  position: fixed; left: 0; top: 0; pointer-events: none; z-index: 6;
  font: 800 18px 'Pixelify Sans', sans-serif; color: #fff; -webkit-text-stroke: 3px #2b1d14; paint-order: stroke fill;
  will-change: transform, opacity;
}
.dmg.crit { color: #ffd23f; font-size: 24px; }
.dmg.eff { color: #ff9b4a; }
.dmg.weak { color: #b9c7d6; font-size: 15px; }
.dmg.hurt { color: #ff6b6b; }
.dmg.info { color: #bfe6ff; font-size: 15px; }

#notices { position: absolute; top: 56px; left: 50%; transform: translateX(-50%); display: grid; gap: 6px; justify-items: center; width: min(520px, calc(100vw - 24px)); }
.notice {
  font: 800 15px 'Nunito', sans-serif; background: var(--paper); color: var(--ink); border: 2px solid var(--edge-dark);
  border-radius: 8px; padding: 8px 14px; box-shadow: 0 3px 0 var(--edge-dark); text-align: center; animation: noticeIn .25s ease-out;
}
.notice.caught { background: #e9f5dc; border-color: var(--accent-dark); }
.notice.down, .notice.escape, .notice.warn { background: #fbe3d8; }
.notice small { display: block; font-weight: 700; color: var(--muted); }
.notice.out { opacity: 0; transition: opacity .5s; }
@keyframes noticeIn { from { transform: translateY(-8px); opacity: 0; } }

#actionBar {
  position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); display: flex; gap: 8px; align-items: stretch; pointer-events: auto;
}
.bar-card {
  background: rgba(43, 29, 20, .82); border: 2px solid var(--edge-dark); border-radius: 8px; padding: 6px 10px; color: var(--paper);
  display: grid; gap: 4px; align-content: center; min-width: 130px; font: inherit; text-align: left;
}
.pet-card { display: flex; gap: 8px; align-items: center; cursor: pointer; min-width: 210px; }
.pet-card:hover { background: rgba(70, 46, 28, .9); }
.pet-card canvas { width: 40px; height: 40px; image-rendering: pixelated; background: rgba(255,255,255,.08); border-radius: 6px; flex: none; }
.pet-info { display: grid; gap: 4px; flex: 1; min-width: 0; }
.bar-label { font: 800 13px 'Nunito', sans-serif; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-label .lvl { color: #ffe08a; }
.meter { position: relative; height: 12px; background: rgba(0,0,0,.45); border-radius: 4px; overflow: hidden; }
.meter i { position: absolute; inset: 0 auto 0 0; width: 100%; background: #6fd35a; transition: width .2s; }
.meter.hp.low i { background: #e8633a; }
.meter.xp { height: 5px; }
.meter.xp i { background: #5ab8e8; }
.meter span { position: relative; display: block; font: 800 10px/12px 'Nunito', sans-serif; text-align: center; color: #fff; text-shadow: 0 1px 0 #000; }
.actions { display: flex; gap: 6px; }
.act {
  display: grid; justify-items: center; align-content: center; gap: 2px; min-width: 64px; min-height: 56px; padding: 4px 8px; cursor: pointer;
  background: rgba(43, 29, 20, .82); color: var(--paper); border: 2px solid var(--edge-dark); border-radius: 8px; font: 800 12px 'Nunito', sans-serif;
}
.act:hover { background: rgba(107, 69, 38, .92); }
.act:active { transform: translateY(1px); }
.act kbd { font: 700 10px 'Nunito', sans-serif; color: #d9c6a4; }
.act.cooldown { opacity: .55; }
.act b { color: #ffe08a; }

#deadOverlay {
  position: absolute; inset: 0; display: grid; place-items: center; background: rgba(40, 10, 10, .35);
  font: 700 28px 'Pixelify Sans', sans-serif; color: #fff; -webkit-text-stroke: 4px #2b1d14; paint-order: stroke fill;
}

/* Si el chat y la barra no caben juntos, el chat sube. */
@media (max-width: 1100px) { #chat { bottom: 92px; } }
@media (max-width: 700px) {
  #actionBar { left: 8px; right: 8px; transform: none; flex-wrap: wrap; justify-content: center; bottom: 8px; }
  .bar-card { min-width: 0; flex: 1; }
  .pet-card { min-width: 0; flex: 2; }
  .act kbd { display: none; }
  .act { min-width: 56px; }
  #chat { bottom: 150px; width: min(300px, calc(100vw - 150px)); }
  #stick { bottom: 160px; }
  #notices { top: 50px; }
}

.team-panel { width: min(860px, 100%); max-height: calc(100vh - 32px); display: grid; grid-template-rows: auto 1fr; overflow: hidden; margin: auto; }
.team-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 8px; }
.team-head h2 { margin: 0; font: 700 26px 'Pixelify Sans', sans-serif; }
.team-head small { font: 700 14px 'Nunito', sans-serif; color: var(--muted); }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 8px; border: 2px solid var(--edge); background: var(--paper-2); color: var(--ink); cursor: pointer; }
.team-body { display: grid; grid-template-columns: minmax(0, 300px) minmax(0, 1fr); gap: 12px; padding: 0 16px 16px; min-height: 0; }
#teamList { list-style: none; margin: 0; padding: 2px; display: grid; gap: 6px; overflow-y: auto; align-content: start; max-height: 70vh; }
.vcard {
  display: flex; gap: 8px; align-items: center; width: 100%; padding: 6px 8px; cursor: pointer; text-align: left;
  border: 2px solid var(--paper-2); border-radius: 8px; background: #fffaf0; font: inherit; color: var(--ink);
}
.vcard.sel { border-color: var(--edge); box-shadow: 0 0 0 2px var(--edge) inset; }
.vcard canvas { width: 40px; height: 40px; image-rendering: pixelated; flex: none; }
.vcard .vc-main { flex: 1; min-width: 0; display: grid; gap: 3px; }
.vcard .vc-name { font-weight: 800; display: flex; gap: 6px; align-items: center; }
.vcard .meter { height: 6px; background: #e3d3b4; }
.vcard .vc-tags { display: flex; gap: 4px; flex-wrap: wrap; }
.chip-type { font: 800 11px 'Nunito', sans-serif; color: #fff; padding: 1px 6px; border-radius: 4px; text-shadow: 0 1px 0 rgba(0,0,0,.35); }
.chip-state { font: 800 11px 'Nunito', sans-serif; padding: 1px 6px; border-radius: 4px; background: var(--paper-2); color: var(--muted); }
.chip-state.active { background: var(--accent); color: #fff; }
.chip-state.down { background: var(--danger); color: #fff; }
#ficha { background: #fffaf0; border: 2px solid var(--paper-2); border-radius: 8px; padding: 12px 14px; overflow-y: auto; max-height: 70vh; }
.ficha-top { display: flex; gap: 12px; align-items: center; }
.ficha-top canvas { width: 96px; height: 96px; image-rendering: pixelated; background: #efe2c6; border-radius: 8px; flex: none; }
.ficha-top h3 { margin: 0 0 4px; font: 700 24px 'Pixelify Sans', sans-serif; }
.ficha-top p { margin: 2px 0; font-weight: 700; color: var(--muted); font-size: 14px; }
.ficha h4 { margin: 14px 0 6px; font: 800 13px 'Nunito', sans-serif; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.stat-row { display: grid; grid-template-columns: 78px 38px 1fr 86px; gap: 8px; align-items: center; font-size: 14px; font-weight: 700; margin-bottom: 5px; }
.stat-row .v { text-align: right; font-weight: 800; }
.stat-row .adapt { height: 8px; background: #e3d3b4; border-radius: 4px; overflow: hidden; }
.stat-row .adapt i { display: block; height: 100%; background: #5ab8e8; }
.stat-row .seed { font-size: 12px; color: var(--muted); text-align: right; }
.ficha-meta { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 14px; }
.ficha-meta dt { font-weight: 800; }
.ficha-meta dd { margin: 0; color: var(--muted); font-weight: 700; }
.ficha-actions { margin-top: 14px; display: flex; gap: 8px; flex-wrap: wrap; }
.btn.secondary { background: var(--paper-2); color: var(--ink); }
@media (max-width: 700px) {
  .team-body { grid-template-columns: minmax(0, 1fr); }
  #teamList { max-height: 32vh; }
  #ficha { max-height: none; }
  .stat-row { grid-template-columns: 70px 32px 1fr 74px; gap: 6px; font-size: 13px; }
}

/* ---------- v0.3: combate 3v3 ---------- */
.row { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 12px; }
#interact {
  position: absolute; left: 50%; bottom: 96px; transform: translateX(-50%); pointer-events: auto; cursor: pointer;
  display: flex; gap: 8px; align-items: center; min-height: 44px; padding: 8px 14px;
  font: 800 15px 'Nunito', sans-serif; color: var(--ink); background: var(--paper);
  border: 2px solid var(--edge-dark); border-radius: 8px; box-shadow: 0 3px 0 var(--edge-dark);
}
#interact kbd { font: 800 13px 'Nunito', sans-serif; background: var(--edge); color: var(--paper); border-radius: 4px; padding: 1px 7px; }
#challengeBox { position: absolute; top: 110px; left: 50%; transform: translateX(-50%); padding: 12px 16px; pointer-events: auto; width: min(420px, calc(100vw - 24px)); }
#challengeBox p { margin: 0; font-weight: 800; text-align: center; }
.tag.fighting .name::after { content: ' · en combate'; color: #ffd27a; font-weight: 700; }

body.in-battle #hud #actionBar, body.in-battle #hud #interact, body.in-battle #hud #stick, body.in-battle #hud #chatBtn, body.in-battle #hud #challengeBox, body.in-battle #hud #deadOverlay, body.in-battle #hud .help, body.in-battle #hud .hud-top, body.in-battle #hud #chat, body.in-battle #hud #notices, body.in-battle #tags { display: none; }
#battle { position: fixed; inset: 0; pointer-events: none; z-index: 4; font-family: 'Nunito', sans-serif; }
#battle button, #battle .overhead { pointer-events: auto; }

/* Barra superior: equipos, orden de turnos y quién actúa */
.b-top { position: absolute; top: 10px; left: 10px; right: 10px; display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: start; }
.b-team { display: grid; gap: 4px; }
.b-team.foe { justify-items: start; }
.b-team.mine { position: absolute; left: 10px; bottom: 10px; justify-items: start; }
.b-team-name { font: 700 18px 'Pixelify Sans', sans-serif; color: #fff; -webkit-text-stroke: 3px var(--edge-dark); paint-order: stroke fill; }
.roster { display: flex; gap: 4px; }
.roster-chip { position: relative; width: 44px; height: 50px; border-radius: 8px; background: rgba(43,29,20,.85); border: 2px solid var(--edge-dark); display: grid; place-items: center; }
.roster-chip.bench { opacity: .8; border-style: dashed; }
.roster-chip.down { opacity: .35; filter: grayscale(1); }
.roster-portrait { width: 36px; height: 36px; image-rendering: pixelated; }
.roster-hp { position: absolute; left: 4px; right: 4px; bottom: 3px; height: 4px; background: rgba(0,0,0,.6); border-radius: 2px; overflow: hidden; }
.roster-hp i { display: block; height: 100%; background: #6fd35a; }
.b-center { display: grid; gap: 6px; justify-items: center; }
.b-order-wrap { display: grid; justify-items: center; gap: 2px; background: rgba(43,29,20,.86); border: 2px solid var(--edge-dark); border-radius: 10px; padding: 4px 10px 6px; }
.b-order-wrap small { font-size: 11px; font-weight: 800; color: #d9c6a4; letter-spacing: .04em; text-transform: uppercase; }
#bOrder { display: flex; gap: 4px; align-items: center; }
.order-item { position: relative; width: 36px; height: 36px; border-radius: 8px; display: grid; place-items: center; background: rgba(255,255,255,.08); border: 2px solid; }
.order-item.mine { border-color: #58e07a; }
.order-item.foe { border-color: #ff6b5b; }
.order-item.now { width: 52px; height: 52px; background: rgba(255,255,255,.18); box-shadow: 0 0 0 3px rgba(255,210,63,.8); animation: nowPulse 1s ease-in-out infinite alternate; }
.order-item.now.mine { box-shadow: 0 0 0 3px #58e07a; }
.order-item.now.foe { box-shadow: 0 0 0 3px #ff6b5b; }
@keyframes nowPulse { to { transform: scale(1.06); } }
.order-portrait { width: 28px; height: 28px; image-rendering: pixelated; }
.order-item.now .order-portrait { width: 42px; height: 42px; }
.order-label { position: absolute; bottom: -9px; font: 800 10px 'Nunito', sans-serif; color: #2b1d14; background: #ffd23f; padding: 0 5px; border-radius: 4px; }
.order-sep { color: #d9c6a4; font-weight: 800; font-size: 20px; padding: 0 2px; }
.b-who { font: 800 16px 'Nunito', sans-serif; padding: 6px 16px; border-radius: 999px; border: 2px solid var(--edge-dark); background: var(--paper); color: var(--ink); box-shadow: 0 3px 0 var(--edge-dark); white-space: nowrap; }
.b-who.mine { background: #d9f7d4; border-color: #2a6627; box-shadow: 0 3px 0 #2a6627; }
.b-who.foe { background: #ffe0d9; border-color: #8b2b20; box-shadow: 0 3px 0 #8b2b20; }
.b-who.idle { opacity: .85; }
.b-tools { display: flex; gap: 6px; justify-content: flex-end; }

/* Aviso grande al empezar cada turno */
.b-banner { position: absolute; left: 0; right: 0; top: 34%; display: grid; justify-items: center; gap: 2px; opacity: 0; pointer-events: none; padding: 10px 0; }
.b-banner b { font: 700 40px 'Pixelify Sans', sans-serif; color: #fff; -webkit-text-stroke: 5px var(--edge-dark); paint-order: stroke fill; letter-spacing: 1px; }
.b-banner span { font: 800 17px 'Nunito', sans-serif; color: #fff; text-shadow: 0 2px 0 #000; }
.b-banner.mine { background: linear-gradient(90deg, transparent, rgba(42,102,39,.75) 30%, rgba(42,102,39,.75) 70%, transparent); }
.b-banner.foe { background: linear-gradient(90deg, transparent, rgba(139,43,32,.75) 30%, rgba(139,43,32,.75) 70%, transparent); }
.b-banner.neutral { background: linear-gradient(90deg, transparent, rgba(43,29,20,.75) 30%, rgba(43,29,20,.75) 70%, transparent); }
.b-banner.show { animation: bannerIn 1s cubic-bezier(.2,.9,.3,1.2) forwards; }
@keyframes bannerIn {
  0% { opacity: 0; transform: translateX(-60px) scaleY(.4); }
  18% { opacity: 1; transform: translateX(0) scaleY(1); }
  75% { opacity: 1; transform: translateX(0); }
  100% { opacity: 0; transform: translateX(60px); }
}

/* Narración de lo que ocurre */
#bCaption { position: absolute; left: 50%; bottom: 30%; transform: translateX(-50%); display: grid; gap: 4px; justify-items: center; pointer-events: none; width: min(640px, calc(100vw - 24px)); }
#bCaption .cap { font: 800 19px 'Nunito', sans-serif; color: #fff; background: rgba(20,14,10,.78); padding: 5px 16px; border-radius: 8px; border: 2px solid rgba(255,255,255,.12); text-align: center; animation: capIn .2s ease-out; transition: opacity .45s; }
#bCaption .cap.mine { border-color: #58e07a; }
#bCaption .cap.foe { border-color: #ff6b5b; }
#bCaption .cap.warn { color: #ffd98a; }
#bCaption .cap.out { opacity: 0; }
@keyframes capIn { from { transform: translateY(8px); opacity: 0; } }

/* Barras sobre la cabeza */
#bOverheads { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.overhead { position: absolute; left: 0; top: 0; display: grid; gap: 2px; justify-items: center; min-width: 104px; padding: 3px 6px 4px; border-radius: 7px; background: rgba(20,14,10,.72); border: 2px solid transparent; cursor: default; }
.overhead.mine { border-color: rgba(88,224,122,.55); }
.overhead.foe { border-color: rgba(255,107,91,.55); }
.overhead.acting { border-color: #ffd23f; box-shadow: 0 0 0 2px rgba(255,210,63,.4); }
.overhead.targetable { cursor: pointer; border-color: #ff9b5b; animation: pulse 0.8s infinite alternate; }
@keyframes pulse { to { box-shadow: 0 0 0 5px rgba(255, 155, 91, .45); } }
.oh-name { font: 800 12px 'Nunito', sans-serif; color: #fff; white-space: nowrap; text-shadow: 0 1px 0 #000; }
.oh-hp { position: relative; width: 96px; height: 9px; background: rgba(0,0,0,.65); border-radius: 3px; overflow: hidden; }
.oh-hp i { position: absolute; inset: 0 auto 0 0; }
.oh-hp .ghost { background: #ffe9a8; transition: width .9s ease-in .25s; }
.oh-hp .fill { background: #6fd35a; transition: width .15s; }
.oh-hp .fill.low { background: #e8633a; }
.oh-extra { display: flex; gap: 3px; flex-wrap: wrap; justify-content: center; min-height: 0; }
.oh-extra:empty { display: none; }
.oh-status { font: 800 10px 'Nunito', sans-serif; color: #fff; padding: 0 5px; border-radius: 4px; }
.oh-status.burn { background: #e8633a; }
.oh-status.para { background: #c9a321; }
.oh-status.slow { background: #3a8fe8; }
.oh-status.charge { background: #b34bd8; animation: pulse 0.6s infinite alternate; }
.oh-status.guard { background: #6b7b8c; }
.pips { display: inline-flex; gap: 2px; }
.pips i { width: 9px; height: 9px; border-radius: 2px; background: rgba(255,255,255,.2); }
.pips i.on { background: #5ab8e8; box-shadow: inset 0 -2px 0 rgba(0,0,0,.25); }
.pips.small i { width: 8px; height: 8px; }
.pips.tiny i { width: 6px; height: 6px; }
.pips em { font: 800 11px 'Nunito', sans-serif; color: #2a6fa8; font-style: normal; }

/* Menú de acciones */
#bMenu { position: absolute; right: 12px; bottom: 12px; width: min(560px, calc(100vw - 24px)); padding: 12px; animation: menuIn .22s cubic-bezier(.2,.9,.3,1.2); }
@keyframes menuIn { from { transform: translateY(24px); opacity: 0; } }
.menu-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.menu-portrait { width: 48px; height: 48px; image-rendering: pixelated; background: #efe2c6; border-radius: 8px; flex: none; }
.menu-titles { display: grid; gap: 2px; flex: 1; min-width: 0; }
.menu-title { font: 700 22px 'Pixelify Sans', sans-serif; line-height: 1.1; }
.menu-sub { font-weight: 700; color: var(--muted); font-size: 13px; }
.menu-energy { display: flex; align-items: center; gap: 6px; }
.menu-energy small { font-weight: 800; color: #2a6fa8; font-size: 13px; }
.menu-energy .pips i { background: #d8c7a6; width: 11px; height: 11px; }
.menu-energy .pips i.on { background: #3a8fe8; }
.menu-timer { flex: none; min-width: 52px; height: 36px; display: grid; place-items: center; border-radius: 8px; background: var(--paper-2); font: 800 16px 'Nunito', sans-serif; }
.menu-timer.urgent { background: #e8633a; color: #fff; animation: pulse 0.5s infinite alternate; }
.moves { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.move {
  --type: #b9a27e;
  display: grid; align-content: start; gap: 4px; text-align: left; padding: 8px 10px 10px; min-height: 104px; cursor: pointer; font: inherit; color: var(--ink);
  background: #fffaf0; border: 2px solid var(--edge); border-top: 6px solid var(--type); border-radius: 10px; box-shadow: 0 3px 0 var(--edge);
  transition: transform .08s;
}
.move:hover:not(:disabled) { transform: translateY(-2px); background: #fff4dc; }
.move:active:not(:disabled) { transform: translateY(1px); box-shadow: 0 1px 0 var(--edge); }
.move:disabled { opacity: .5; cursor: not-allowed; }
.move-top { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.move-top b { font-size: 15px; line-height: 1.1; flex: 1; min-width: 0; }
.move kbd, .act-btn kbd { font: 800 11px 'Nunito', sans-serif; background: var(--edge); color: var(--paper); border-radius: 4px; padding: 0 5px; }
.move .pips i { background: #d8c7a6; }
.move .pips i.on { background: #3a8fe8; }
.move-desc { color: var(--muted); font-weight: 700; font-size: 12px; line-height: 1.25; }
.move-hint { font-size: 12px; font-weight: 800; padding: 2px 6px; border-radius: 5px; background: #efe2c6; width: fit-content; }
.move-hint.good { background: #d9f7d4; color: #1f5a1d; }
.move-hint.bad { background: #f3dcd6; color: #8b2b20; }
.move-hint.no { background: #e6ddcc; color: #7a5f45; }
.menu-row { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.act-btn {
  flex: 1; display: grid; grid-template-columns: auto 1fr; column-gap: 8px; align-items: center; text-align: left; min-height: 48px; padding: 6px 12px; cursor: pointer;
  font: inherit; color: var(--ink); background: var(--paper-2); border: 2px solid var(--edge); border-radius: 10px; box-shadow: 0 3px 0 var(--edge);
}
.act-btn span { font-weight: 800; font-size: 15px; }
.act-btn small { grid-column: 2; color: var(--muted); font-weight: 700; font-size: 12px; }
.act-btn kbd { grid-row: span 2; }
.act-btn:disabled { opacity: .5; cursor: not-allowed; }
.act-btn.back { flex: none; margin-top: 8px; }
.targets { display: grid; gap: 6px; }
.target {
  display: flex; gap: 10px; align-items: center; text-align: left; padding: 6px 10px; min-height: 56px; cursor: pointer; font: inherit; color: var(--ink);
  background: #fffaf0; border: 2px solid var(--edge); border-radius: 10px; box-shadow: 0 3px 0 var(--edge);
}
.target:hover { background: #fff0cf; border-color: #e8963a; }
.target-portrait, .pick-portrait { width: 40px; height: 40px; image-rendering: pixelated; flex: none; }
.target-info { display: grid; gap: 3px; flex: 1; min-width: 0; }
.target-info small { font-weight: 800; font-size: 12px; color: var(--muted); }
.target-info small.good { color: #1f7a1c; }
.target-info small.bad { color: #9b3326; }
.mini-hp { display: block; height: 6px; background: #e3d3b4; border-radius: 3px; overflow: hidden; }
.mini-hp i { display: block; height: 100%; background: #6fd35a; }

#bResult { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(440px, calc(100vw - 24px)); padding: 20px; text-align: center; animation: resultIn .5s cubic-bezier(.2,.9,.3,1.3); }
@keyframes resultIn { from { transform: translate(-50%, -50%) scale(.6); opacity: 0; } }
#bResult h2 { margin: 0 0 8px; font: 700 40px 'Pixelify Sans', sans-serif; color: var(--accent-dark); }
#bResult.lost h2 { color: var(--danger); }
#bResult ul { list-style: none; padding: 0; margin: 0 0 14px; display: grid; gap: 4px; font-weight: 700; }

/* Números flotantes con rebote */
.dmg.big { font-size: 26px; }
.dmg.crit.big { font-size: 34px; }
.dmg.heal { color: #7dff9a; }
.dmg.status { font-size: 16px; }
.dmg.status.burn { color: #ff9b5b; }
.dmg.status.para { color: #ffe066; }
.dmg.status.slow { color: #8ecbff; }

@media (max-width: 900px) {
  .b-top { grid-template-columns: 1fr; justify-items: center; }
  .b-team.foe { order: 2; justify-items: center; }
  .b-tools { order: 0; justify-content: center; }
  .b-center { order: 1; }
  .b-team.mine { display: none; }
  #bMenu { left: 8px; right: 8px; bottom: 8px; width: auto; max-height: 52vh; overflow-y: auto; }
  .moves { grid-template-columns: 1fr; }
  .move { min-height: 0; }
  .b-banner b { font-size: 34px; }
  #bCaption { bottom: 56%; }
  .b-who { font-size: 14px; white-space: normal; text-align: center; }
}

.pick-panel { width: min(480px, 100%); padding: 16px; margin: auto; max-height: calc(100vh - 32px); overflow-y: auto; }
.pick-panel h2 { margin: 0 0 4px; font: 700 24px 'Pixelify Sans', sans-serif; }
.pick-panel p { margin: 0 0 10px; color: var(--muted); font-weight: 700; font-size: 14px; }
#pickList, #arenaTiers { display: grid; gap: 6px; }
.pick-row, .tier {
  display: flex; gap: 10px; align-items: center; width: 100%; text-align: left; padding: 6px 10px; min-height: 48px; cursor: pointer; font: inherit; color: var(--ink);
  background: #fffaf0; border: 2px solid var(--paper-2); border-radius: 8px;
}
.pick-row.on { border-color: var(--accent); background: #e9f5dc; }
.pick-order { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: 13px; background: var(--paper-2); flex: none; }
.pick-row.on .pick-order { background: var(--accent); color: #fff; }
.pick-row canvas { width: 36px; height: 36px; image-rendering: pixelated; flex: none; }
.pick-info, .tier { display: grid; gap: 1px; }
.pick-info small, .tier small { color: var(--muted); font-weight: 700; }
.tier b { font: 700 18px 'Pixelify Sans', sans-serif; }


/* Móvil: el botón de interactuar va por encima del joystick y del chat, sin salirse de pantalla */
@media (max-width: 700px) {
  #interact { bottom: 292px; max-width: calc(100vw - 24px); }
  #interactText { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

.pick-row.down { opacity: .55; cursor: not-allowed; filter: grayscale(.6); }

/* ---------- Ayuda contextual ---------- */
.help-btn {
  display: inline-grid; place-items: center; width: 22px; height: 22px; padding: 0; margin-left: 4px; flex: none; vertical-align: middle;
  font: 800 13px 'Nunito', sans-serif; color: var(--paper); background: var(--edge); border: 2px solid var(--edge-dark); border-radius: 50%; cursor: pointer;
}
.help-btn::before { content: ''; position: absolute; width: 44px; height: 44px; } /* área táctil amplia */
.help-btn { position: relative; }
.help-btn:hover { background: var(--edge-dark); }
.help-pop {
  position: fixed; z-index: 50; padding: 10px 12px; border-radius: 10px; background: var(--paper); color: var(--ink);
  border: 2px solid var(--edge-dark); box-shadow: 0 4px 0 var(--edge-dark), 0 12px 30px rgba(0,0,0,.35); animation: noticeIn .15s ease-out;
}
.help-pop b { display: block; font: 700 17px 'Pixelify Sans', sans-serif; margin-bottom: 4px; }
.help-pop p { margin: 0; font: 700 14px/1.4 'Nunito', sans-serif; color: #4a3727; }
.ficha-legend { margin: -2px 0 8px; font-size: 12px; font-weight: 700; color: var(--muted); display: flex; align-items: center; flex-wrap: wrap; gap: 2px; }
.stat-name { font: 700 14px 'Nunito', sans-serif; color: var(--ink); background: none; border: 0; padding: 4px 0; text-align: left; cursor: pointer; text-decoration: underline dotted #b9a27e; text-underline-offset: 3px; min-height: 32px; }
.help-pop p { white-space: pre-line; }
.ficha-meta dt { display: flex; align-items: center; }
.ficha-moves { list-style: none; margin: 0 0 8px; padding: 0; display: grid; gap: 6px; }
.ficha-moves li { display: grid; gap: 1px; padding: 6px 10px; border-radius: 8px; background: #f7eedb; border-left: 5px solid #b9a27e; }
.ficha-moves b { font-size: 14px; }
.ficha-moves small { font-weight: 800; color: #2a6fa8; font-size: 12px; }
.ficha-moves span { font-size: 13px; font-weight: 700; color: var(--muted); }

/* Ficha de unidad y guía en combate */
#bInfo, #bGuide {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 8; pointer-events: auto;
  width: min(440px, calc(100vw - 16px)); max-height: calc(100dvh - 24px); overflow-y: auto; padding: 14px 14px 12px;
}
#bInfo *, #bGuide * { pointer-events: auto; }
.b-info-close { position: absolute; top: 8px; right: 8px; width: 40px; height: 40px; }
.info-head { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; padding-right: 44px; }
.info-portrait { width: 64px; height: 64px; image-rendering: pixelated; background: #efe2c6; border-radius: 10px; flex: none; }
.info-titles { display: grid; gap: 4px; }
.info-titles b { font: 700 22px 'Pixelify Sans', sans-serif; line-height: 1.1; }
.info-tags { display: flex; gap: 6px; flex-wrap: wrap; }
.info-side { font: 800 11px 'Nunito', sans-serif; padding: 1px 7px; border-radius: 4px; color: #fff; }
.info-side.mine { background: #2a6627; }
.info-side.foe { background: #8b2b20; }
.info-hp { height: 16px; margin-bottom: 8px; }
.info-hp span { line-height: 16px; font-size: 11px; }
.info-lines { list-style: none; padding: 0; margin: 0 0 8px; display: grid; gap: 3px; font-size: 13px; font-weight: 700; color: #4a3727; }
.info-lines li.bad { color: #8b2b20; }
.info-lines li.good { color: #1f5a1d; }
.info-speed, .info-energy { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 6px; }
.info-speed b { color: var(--ink); font-size: 14px; }
.info-energy small { font-weight: 800; color: #2a6fa8; font-size: 13px; }
.info-stats { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px; margin-bottom: 8px; }
.info-stats span { display: grid; justify-items: center; background: #f7eedb; border-radius: 6px; padding: 3px 2px; }
.info-stats small { font-size: 10px; font-weight: 800; color: var(--muted); }
.info-stats b { font-size: 15px; }
.info-sub { margin: 6px 0; font: 700 16px 'Pixelify Sans', sans-serif; }
#bGuide h2 { margin: 0 44px 8px 0; font: 700 24px 'Pixelify Sans', sans-serif; }
.guide-sec h3 { margin: 10px 0 2px; font: 800 15px 'Nunito', sans-serif; }
.guide-sec p { margin: 0; font-size: 14px; font-weight: 700; line-height: 1.4; color: #4a3727; }
.guide-tip { margin: 12px 0 0; padding: 8px 10px; border-radius: 8px; background: #e9f5dc; font-weight: 800; font-size: 13px; }
.roster-chip, .order-item { cursor: pointer; }
.overhead { cursor: pointer; pointer-events: auto; }
.b-order-wrap small { display: flex; align-items: center; }
.b-order-wrap .help-btn { width: 18px; height: 18px; font-size: 11px; }

/* ---------- Amigos, chat privado y botones del HUD ---------- */
.hud-actions { margin-left: auto; display: flex; gap: 6px; }
.hud-actions .btn-chip { margin-left: 0; display: inline-flex; align-items: center; gap: 6px; min-height: 40px; }
.badge { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: #e8633a; color: #fff; font: 800 11px/18px 'Nunito', sans-serif; text-align: center; }
.social-panel { width: min(480px, 100%); max-height: calc(100dvh - 32px); display: grid; grid-template-rows: auto 1fr; overflow: hidden; margin: auto; }
.social-body { padding: 0 16px 16px; overflow-y: auto; display: grid; align-content: start; gap: 8px; min-height: 0; }
.soc-add { display: flex; gap: 8px; }
.soc-add input { flex: 1; min-width: 0; font: 700 16px 'Nunito', sans-serif; padding: 8px 10px; min-height: 44px; border-radius: 8px; border: 2px solid var(--edge); background: #fffaf0; color: var(--ink); }
.soc-h { margin: 8px 0 0; font: 800 13px 'Nunito', sans-serif; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.soc-empty { margin: 0; font-weight: 700; color: var(--muted); font-size: 14px; }
.soc-row { display: flex; align-items: center; gap: 8px; padding: 6px 8px; min-height: 52px; border-radius: 10px; background: #fffaf0; border: 2px solid var(--paper-2); }
.soc-info { display: grid; flex: 1; min-width: 0; }
.soc-name { font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.soc-info .soc-name { flex: none; }
.soc-status { font-size: 12px; font-weight: 700; color: var(--muted); }
.soc-dot { width: 10px; height: 10px; border-radius: 50%; background: #b9a27e; flex: none; }
.soc-dot.on { background: #3fbf4f; box-shadow: 0 0 0 3px rgba(63,191,79,.25); }
.btn.small { min-height: 38px; padding: 6px 12px; font-size: 14px; }
.icon-btn.small { width: 38px; height: 38px; }
.chat-head { display: flex; align-items: center; gap: 10px; }
.chat-head div { display: grid; }
.chat-head small { color: var(--muted); font-weight: 700; font-size: 12px; }
#dmLog { display: flex; flex-direction: column; gap: 6px; min-height: 240px; max-height: min(52dvh, 460px); overflow-y: auto; padding: 8px; border-radius: 10px; background: #f3e8d2; }
.dm { align-self: flex-start; max-width: 82%; display: grid; gap: 1px; padding: 6px 10px; border-radius: 10px 10px 10px 2px; background: #fffaf0; border: 2px solid var(--paper-2); }
.dm.mine { align-self: flex-end; background: #d9f7d4; border-color: #a6d99f; border-radius: 10px 10px 2px 10px; }
.dm-text { font-weight: 700; font-size: 15px; overflow-wrap: anywhere; }
.dm-time { font-size: 11px; font-weight: 700; color: var(--muted); justify-self: end; }
