/* ---------- Combate ---------- */
.battle {
  position: absolute; inset: 0; z-index: 20;
  display: grid; grid-template-rows: auto auto 1fr auto auto; gap: 8px;
  padding: 14px 12px max(16px, env(safe-area-inset-bottom));
  background: radial-gradient(ellipse at 50% 35%, #3a2440, #0c0a12 70%);
}
.battle[hidden] { display: none; }
.battle.shake-s { animation: bshake-s .25s; }
.battle.shake-l { animation: bshake-l .45s; }
@keyframes bshake-s { 25% { transform: translate(-3px, 1px); } 75% { transform: translate(3px, -1px); } }
@keyframes bshake-l { 15% { transform: translate(-7px, 3px); } 35% { transform: translate(6px, -4px); } 55% { transform: translate(-5px, 2px); } 80% { transform: translate(3px, -1px); } }
.b-head { display: flex; justify-content: space-between; font-family: var(--serif); font-size: 15px; padding-inline: 4px; }
.b-round { color: var(--muted); font-family: var(--sans); font-size: 13px; }
.b-side { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; }
.b-side.enemy { align-self: start; }
.b-side.ally { align-self: end; }
.bunit { position: relative; width: 18%; min-width: 58px; max-width: 92px; text-align: center; transition: opacity .3s, transform .15s; }
.bunit.boss { width: 24%; max-width: 118px; }
.bu-art { position: relative; aspect-ratio: 3 / 4; border-radius: 10px; overflow: hidden; border: 2px solid #4b3d78; }
.bunit.enemy .bu-art { border-color: #7a2c3a; }
.bunit.boss .bu-art { border-color: var(--bad); box-shadow: 0 0 18px -4px var(--bad); }
.bu-art .portrait { width: 100%; height: 100%; display: block; }
.bu-name { font-size: 11px; margin: 3px 0 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar.hp { height: 6px; }
.bar.hp i { background: linear-gradient(90deg, #2fae62, var(--good)); transition: width .25s; }
.bunit.enemy .bar.hp i { background: linear-gradient(90deg, #b8333f, var(--bad)); }
.bar.ult { height: 5px; margin-top: 3px; }
.bar.ult i { background: linear-gradient(90deg, #3f93e8, #7fd0ff); transition: width .25s; }
.bunit.enemy .bar.ult i { background: linear-gradient(90deg, #a05a1c, #e8963f); }
.bunit.dead { opacity: .25; filter: grayscale(1); }
.bunit.acting:not(.lunge) { transform: translateY(-6px) scale(1.05); }
.bunit.enemy.acting:not(.lunge) { transform: translateY(6px) scale(1.05); }
.bunit.healed .bu-art { box-shadow: 0 0 16px 2px var(--good); }

/* Definitiva lista: la tarjeta brilla y se toca para lanzarla. */
.bunit.ult-ready .bar.ult i { background: linear-gradient(90deg, #f4cd62, #fff1b0); }
.bunit.ult-ready.ally .bu-art { border-color: var(--gold); animation: ultglow 1s ease-in-out infinite; }
.bunit.ult-ready.enemy .bu-art { border-color: #e8963f; }
.bunit[data-action="battle-ult"] { cursor: pointer; }
.bunit[data-action="battle-ult"]::after {
  content: "¡Tocá!"; position: absolute; left: 50%; top: -8px; transform: translateX(-50%);
  background: var(--gold); color: #1d1405; font-size: 10px; font-weight: 800; padding: 1px 6px; border-radius: 99px; z-index: 6;
}
@keyframes ultglow { 50% { box-shadow: 0 0 20px 3px var(--gold); transform: scale(1.04); } }

/* Estados sobre la tarjeta */
.bu-fxs { position: absolute; z-index: 4; top: 3px; left: 3px; right: 3px; display: flex; flex-wrap: wrap; gap: 2px; pointer-events: none; }
.bu-fxs:empty { display: none; }
.fxi { display: inline-grid; place-items: center; width: 16px; height: 16px; border-radius: 50%; background: rgba(8,6,14,.82); border: 1px solid currentColor; }
.fxi svg { width: 11px; height: 11px; display: block; }

/* Números de daño */
.bu-nums { position: absolute; left: 0; right: 0; top: 18%; height: 40%; z-index: 7; pointer-events: none; }
.num {
  position: absolute; top: 20%; transform: translateX(-50%); white-space: nowrap;
  font-weight: 900; font-size: 17px; color: #fff;
  -webkit-text-stroke: 3px #000; paint-order: stroke fill; text-shadow: 0 2px 3px rgba(0,0,0,.8);
  animation: numrise .9s ease-out forwards;
}
.num.crit { color: var(--gold); font-size: 23px; }
.num.heal { color: #8cf2b0; }
.num.shield { color: #8fc7ff; }
.num.dodge { color: #cfe0ff; font-size: 15px; font-style: italic; }
.num.burn { color: #ffa45c; font-size: 15px; }
@keyframes numrise { 0% { opacity: 0; transform: translate(-50%, 8px) scale(.6); } 20% { opacity: 1; transform: translate(-50%, 0) scale(1.2); } 70% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -26px) scale(1); } }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

/* Cartel de habilidad */
.b-banner {
  position: absolute; z-index: 25; left: 0; right: 0; top: 38%; text-align: center; pointer-events: none;
  padding: 10px 0; background: linear-gradient(90deg, transparent, rgba(8,6,14,.88) 15%, rgba(8,6,14,.88) 85%, transparent);
  border-block: 1px solid var(--ec, var(--gold));
}
.b-banner[hidden] { display: none; }
.b-banner small { display: block; font-size: 12px; color: var(--muted); }
.b-banner strong { display: block; font-family: var(--serif); font-size: 26px; color: var(--ec, var(--gold)); text-shadow: 0 0 14px var(--ec, var(--gold)); }
.b-banner.show { animation: banner 1.05s ease-out forwards; }
@keyframes banner { 0% { opacity: 0; transform: scaleY(.3); } 15% { opacity: 1; transform: scaleY(1); } 80% { opacity: 1; } 100% { opacity: 0; } }

.b-log { align-self: center; min-height: 84px; font-size: 13px; text-align: center; color: var(--muted); display: flex; flex-direction: column; gap: 2px; justify-content: center; }
.b-log div:first-child { color: var(--text); }
.b-controls { display: flex; justify-content: center; gap: 8px; }
.b-controls[hidden] { display: none; }
.b-controls .btn.on { border-color: var(--gold); color: var(--gold); }
.b-result { position: absolute; inset: 0; z-index: 26; display: grid; place-items: center; background: rgba(6,5,10,.75); padding: 12px; overflow-y: auto; }
.b-result[hidden] { display: none; }
.b-result-card { width: 100%; max-width: 340px; max-height: 100%; overflow-y: auto; text-align: center; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 18px 16px; animation: reveal .4s; }
.b-result-card h2 { font-size: 30px; }
.b-result-card.win h2 { color: var(--gold); }
.b-result-card.lose h2 { color: var(--bad); }
.b-result-card .btn { margin-top: 14px; width: 100%; }
.rewards { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.rewards span { display: inline-flex; justify-content: center; align-items: center; gap: 5px; }

/* Daño por héroe */
.dmg-list { text-align: left; margin-top: 6px; }
.dmg-row { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; padding: 5px 0; font-size: 13px; }
.dmg-row .dv { font-variant-numeric: tabular-nums; }
.dmg-row .heal { color: var(--good); }
.dmg-row.down .dn { opacity: .55; }
.dbar { grid-column: 1 / -1; height: 5px; background: #0b0911; border-radius: 99px; overflow: hidden; }
.dbar i { display: block; height: 100%; background: linear-gradient(90deg, #7c5cff, #b585ff); }
.dmg-row.mvp .dbar i { background: linear-gradient(90deg, #c8921f, #f4cd62); }
.mvp-tag { background: var(--gold); color: #1d1405; font-size: 10px; padding: 1px 5px; border-radius: 4px; margin-right: 6px; }

/* Aviso de habilidad del jefe (la barra de definitiva enemiga está oculta) */
.boss-warn { margin-top: 2px; font-size: 10px; font-weight: 700; color: #f0b070; text-shadow: 0 0 6px rgba(232,150,63,.7); animation: bosswarn 1s ease-in-out infinite; }
.boss-warn[hidden] { display: none; }
.bunit.boss.ult-ready .bu-art { border-color: #e8963f; box-shadow: 0 0 16px -2px #e8963f; }
@keyframes bosswarn { 50% { opacity: .45; } }

/* Pisos de la Torre repetibles */
button.tfloor.repeat { width: 100%; font: inherit; color: inherit; text-align: left; cursor: pointer; }
button.tfloor.repeat:hover { border-color: var(--good); }
button.tfloor.repeat em { color: var(--gold); }

/* ---------- Animación de combate ---------- */
/* --spd = velocidad x1/x2/x4: las duraciones se dividen por ella. */
.battle { --spd: 1; }
.bunit.acting { z-index: 5; }
.bunit.lunge { animation: lunge calc(340ms / var(--spd)) ease-out; }
@keyframes lunge {
  0% { transform: translate(0, 0); }
  45% { transform: translate(var(--lx, 0), var(--ly, 0)) scale(1.08); }
  100% { transform: translate(0, 0); }
}
/* Entrada: los enemigos bajan, los aliados suben, uno detrás de otro. */
.battle.intro .bunit { animation: bu-in-ally .5s cubic-bezier(.2, .8, .3, 1.15) backwards; animation-delay: calc(var(--k) * 80ms + 80ms); }
.battle.intro .bunit.enemy { animation-name: bu-in-enemy; }
@keyframes bu-in-ally { from { opacity: 0; transform: translateY(60px) scale(.85); } }
@keyframes bu-in-enemy { from { opacity: 0; transform: translateY(-60px) scale(.85); } }
/* Destello al recibir daño o curación */
.bu-art::after { content: ""; position: absolute; inset: 0; pointer-events: none; opacity: 0; background: radial-gradient(circle, #fff 0%, rgba(255,90,90,.75) 70%); mix-blend-mode: screen; }
.bunit.hit .bu-art { animation: shake calc(300ms / var(--spd)); }
.bunit.hit .bu-art::after { animation: hitflash calc(300ms / var(--spd)) ease-out; }
.bunit.healed .bu-art::after { background: radial-gradient(circle, rgba(200,255,210,.9), rgba(95,211,138,.4) 70%); animation: hitflash calc(500ms / var(--spd)) ease-out; }
@keyframes hitflash { 0% { opacity: .9; } 100% { opacity: 0; } }
/* Caída al morir */
.bunit.dying { animation: bu-fall calc(620ms / var(--spd)) ease-in forwards; pointer-events: none; }
.bunit.enemy.dying { animation-name: bu-fall-enemy; }
@keyframes bu-fall { 0% { opacity: 1; filter: none; } 30% { transform: translateY(-6px) rotate(-4deg); filter: brightness(2); } 100% { opacity: .25; transform: translateY(10px) rotate(8deg) scale(.92); filter: grayscale(1); } }
@keyframes bu-fall-enemy { 0% { opacity: 1; filter: none; } 30% { transform: translateY(-4px) rotate(4deg); filter: brightness(2); } 100% { opacity: .25; transform: translateY(14px) rotate(-10deg) scale(.88); filter: grayscale(1); } }

/* Proyectiles e impactos (capa sobre el campo) */
.b-fxlayer { position: absolute; inset: 0; z-index: 9; pointer-events: none; overflow: hidden; }
.bfx { position: absolute; display: block; pointer-events: none; }
.proj { animation: proj var(--t, 230ms) linear forwards; }
@keyframes proj { from { transform: translate(-50%, -50%) rotate(var(--ang)); } to { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) rotate(var(--ang)); } }
.p-arrow { width: 40px; height: 4px; border-radius: 2px; background: linear-gradient(90deg, transparent, #d9c08a 30%, #fff); box-shadow: 0 0 8px var(--ec); }
.p-arrow::after { content: ""; position: absolute; right: -8px; top: -4px; border-style: solid; border-width: 6px 0 6px 9px; border-color: transparent transparent transparent #fff; }
.p-orb { width: 24px; height: 24px; border-radius: 50%; background: radial-gradient(circle, #fff 0%, var(--ec) 45%, transparent 72%); box-shadow: 0 0 18px 6px color-mix(in srgb, var(--ec) 60%, transparent); }
.imp { transform: translate(-50%, -50%); }
.i-slash, .i-arrow { width: 96px; height: 6px; border-radius: 3px; background: linear-gradient(90deg, transparent, #fff 45%, var(--ec) 60%, transparent); box-shadow: 0 0 12px #fff; animation: slash calc(280ms / var(--spd)) ease-out forwards; }
.i-arrow { width: 54px; }
@keyframes slash { from { opacity: 1; transform: translate(-50%, -50%) rotate(-35deg) scaleX(.2); } to { opacity: 0; transform: translate(-50%, -50%) rotate(-35deg) scaleX(1.2); } }
.i-orb { width: 84px; height: 84px; border-radius: 50%; background: radial-gradient(circle, #fff 0%, var(--ec) 35%, transparent 70%); animation: burst-o calc(380ms / var(--spd)) ease-out forwards; }
@keyframes burst-o { from { opacity: 1; transform: translate(-50%, -50%) scale(.3); } to { opacity: 0; transform: translate(-50%, -50%) scale(1.4); } }
.i-bash { width: 72px; height: 72px; border-radius: 50%; border: 4px solid #e8e2f6; box-shadow: 0 0 14px #fff, inset 0 0 14px var(--ec); animation: burst-o calc(340ms / var(--spd)) ease-out forwards; }
.i-light { width: 70px; height: 160px; background: linear-gradient(180deg, transparent, rgba(255,246,190,.9) 40%, rgba(140,242,176,.7) 75%, transparent); border-radius: 40px; filter: blur(2px); animation: beam calc(560ms / var(--spd)) ease-out forwards; }
@keyframes beam { 0% { opacity: 0; transform: translate(-50%, -60%) scaleX(.2); } 30% { opacity: 1; transform: translate(-50%, -60%) scaleX(1); } 100% { opacity: 0; transform: translate(-50%, -60%) scaleX(.6); } }
.i-ward { width: 88px; height: 88px; border-radius: 50%; border: 3px solid #8fc7ff; box-shadow: 0 0 18px #8fc7ff, inset 0 0 18px #8fc7ff; animation: burst-o calc(560ms / var(--spd)) ease-out forwards; }

/* Definitiva: fondo oscuro y retrato del que la lanza */
.b-ultcut { position: absolute; inset: 0; z-index: 24; pointer-events: none; overflow: hidden; }
.b-ultcut[hidden] { display: none; }
.b-ultcut.show { animation: uc-dim calc(950ms / var(--spd)) ease-out forwards; }
@keyframes uc-dim { 0% { background: rgba(4,3,8,0); } 15%, 75% { background: rgba(4,3,8,.74); } 100% { background: rgba(4,3,8,0); } }
.uc-art {
  position: absolute; top: 12%; width: 44%; max-width: 230px; aspect-ratio: 3 / 4; border-radius: 16px; overflow: hidden;
  border: 3px solid var(--ec); box-shadow: 0 0 40px -4px var(--ec); opacity: 0;
}
.b-ultcut.ally .uc-art { left: 6%; }
.b-ultcut.enemy .uc-art { right: 6%; }
.uc-art .portrait { width: 100%; height: 100%; display: block; }
.b-ultcut.show.ally .uc-art { animation: uc-in-l calc(950ms / var(--spd)) cubic-bezier(.2, .8, .3, 1) forwards; }
.b-ultcut.show.enemy .uc-art { animation: uc-in-r calc(950ms / var(--spd)) cubic-bezier(.2, .8, .3, 1) forwards; }
@keyframes uc-in-l { 0% { opacity: 0; transform: translateX(-60%); } 20%, 75% { opacity: 1; transform: translateX(0); } 100% { opacity: 0; transform: translateX(15%); } }
@keyframes uc-in-r { 0% { opacity: 0; transform: translateX(60%); } 20%, 75% { opacity: 1; transform: translateX(0); } 100% { opacity: 0; transform: translateX(-15%); } }
.b-banner.show { animation-duration: calc(1050ms / var(--spd)); }

.b-head { gap: 10px; align-items: baseline; }
.b-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.b-round { flex: none; }
.b-controls .btn { min-height: 44px; min-width: 96px; }
.bunit[data-action="battle-ult"]:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; border-radius: 10px; }
.num { animation-duration: calc(900ms / var(--spd)); }

@media (min-width: 960px) {
  .bunit { max-width: 116px; }
  .bunit.boss { max-width: 150px; }
  .bu-name { font-size: 13px; }
  .b-log { font-size: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  .b-fxlayer, .b-ultcut { display: none; }
  .bunit.dying { animation: none; opacity: .25; filter: grayscale(1); }
}
@media (min-width: 960px) { .battle { border-radius: inherit; } }

/* ---------- Íconos de habilidades, efectos de definitiva, XP y líder ---------- */
.bu-skill { position: absolute; top: -7px; right: -7px; width: 28px; height: 28px; z-index: 6; display: none; pointer-events: none; filter: drop-shadow(0 0 6px var(--gold)); animation: skpulse 1s ease-in-out infinite; }
.bunit.ult-ready .bu-skill { display: block; }
.bu-skill img { width: 100%; height: 100%; object-fit: contain; display: block; }
@keyframes skpulse { 50% { transform: scale(1.18); } }
.skill-row { display: flex; gap: 10px; align-items: center; }
.skill-row p { margin: 6px 0; }
.skill-ico { flex: none; width: 46px; height: 46px; border-radius: 12px; background: #0f0b1a; border: 1px solid var(--ec, var(--line)); display: grid; place-items: center; }
.skill-ico img { width: 38px; height: 38px; object-fit: contain; }

.ufx { width: var(--sz, 72px); height: auto; filter: drop-shadow(0 0 10px var(--ec)); will-change: transform, opacity; }
.ufx-fly { animation: ufx-fly var(--t, 290ms) cubic-bezier(.45, 0, .85, .6) forwards; }
@keyframes ufx-fly {
  0% { opacity: 0; transform: translate(-50%, -50%) rotate(var(--r0, 0deg)) scale(.4); }
  15% { opacity: 1; }
  100% { opacity: 1; transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) rotate(calc(var(--r0, 0deg) + var(--spin, 0deg))) scale(1); }
}
.ufx-burst { animation: ufx-burst calc(560ms / var(--spd)) ease-out forwards; }
@keyframes ufx-burst {
  0% { opacity: 0; transform: translate(-50%, -50%) rotate(var(--r0, 0deg)) scale(.3); filter: brightness(2.2) drop-shadow(0 0 16px var(--ec)); }
  25% { opacity: 1; }
  60% { opacity: .9; }
  100% { opacity: 0; transform: translate(-50%, -50%) rotate(calc(var(--r0, 0deg) + var(--spin, 0deg))) scale(var(--end, 1.5)); }
}

.xp-list { margin-top: 12px; text-align: left; }
.xp-row { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; align-items: baseline; padding: 4px 0; font-size: 13px; }
.xp-row .xv { color: #7fe3a3; font-weight: 700; }
.xbar { grid-column: 1 / -1; height: 6px; background: #0b0911; border-radius: 99px; overflow: hidden; }
.xbar i { display: block; height: 100%; background: linear-gradient(90deg, #3fb877, #9be15d); transition: width .6s ease-out; }
.lvup { color: var(--gold); animation: lvpop .7s ease-out both; }
@keyframes lvpop { 0% { transform: scale(.6); opacity: 0; } 60% { transform: scale(1.25); } 100% { transform: scale(1); opacity: 1; } }
.xp-row.up .xn { text-shadow: 0 0 8px rgba(244, 205, 98, .6); }
.xp-line { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 4px; }
.bar.xp i { background: linear-gradient(90deg, #3fb877, #9be15d); }
.bar.thin { margin-top: 6px; }

.stage-wrap { display: flex; flex-direction: column; gap: 4px; }
.sweep-row { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; padding: 0 4px 4px; }
.sweep-row .muted { margin-right: auto; }
.sweep-row .btn { min-height: 36px; display: inline-flex; align-items: center; gap: 4px; }

.crown { position: absolute; top: 3px; left: 3px; z-index: 3; width: 20px; height: 20px; color: var(--gold); filter: drop-shadow(0 1px 2px #000); }
.crown svg, .crown-i svg { width: 100%; height: 100%; display: block; }
.crown-i { display: inline-block; width: 16px; height: 16px; vertical-align: -3px; color: var(--gold); }
.tslot { position: relative; }
.leader-line { margin: 8px 0 0; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; }
@media (prefers-reduced-motion: reduce) { .bu-skill, .lvup { animation: none; } .xbar i { transition: none; } }
/* En la tarjeta del héroe la corona va arriba al centro, sin tapar la rareza ni el elemento. */
.hcard .crown { left: 50%; top: -2px; transform: translateX(-50%); width: 22px; height: 22px; }
