/* Abyss Gate–style 1v1 battle layer (BUILD 20261111-ag1).
   FX timings, cut-in, cards, damage numbers and hit sprites are adapted from
   steveJea/vr-tcg staging (lunge/hitFx/shake/dmgNumber/cutIn + inline FX CSS). */

#battle.ag-mode {
  background: #09090b;
  font-family: "Noto Sans KR", system-ui, sans-serif;
}
#battle.ag-mode .battle-field,
#battle.ag-mode .battle-vignette { display: none; }
#battle.ag-mode.entering .ag-board,
#battle.ag-mode.entering .battle-bg { animation: battle-in 0.28s ease both; }
#battle.ag-mode.leaving .ag-board,
#battle.ag-mode.leaving .battle-bg { animation: battle-out 0.18s ease both; }

#battle.ag-mode .battle-bg {
  background-color: #09090b;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}
#battle.ag-mode .battle-bg::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(0,0,0,.32) 0%, rgba(0,0,0,.10) 28%, rgba(0,0,0,.08) 70%, rgba(0,0,0,.36) 100%);
  pointer-events: none;
}
#battle.ag-mode.bg-hospital .battle-bg::after {
  background: linear-gradient(180deg, rgba(0,0,0,.42) 0%, rgba(0,0,0,.16) 28%, rgba(0,0,0,.14) 70%, rgba(0,0,0,.44) 100%);
}
#battle.ag-mode.bg-hospital #ag-turn-info,
#battle.ag-mode.bg-hospital .u-hpnum,
#battle.ag-mode.bg-hospital .card-name,
#battle.ag-mode.bg-hospital .card-foot,
#battle.ag-mode.bg-hospital .rar-badge {
  text-shadow: 0 1px 2px #000, 0 0 8px rgba(0,0,0,.9), 0 2px 6px #000;
}

.ag-board {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  gap: 4px;
  padding: 12px 16px 16px;
  pointer-events: none;
}
/* agbattle1: Abyss Gate field box (dark rounded panel behind both rows) */
.ag-board::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(620px, 94vw);
  height: min(560px, 90%);
  transform: translate(-50%, -50%);
  border-radius: 18px;
  background: radial-gradient(120% 90% at 50% 50%, rgba(9,9,11,.30), rgba(9,9,11,.58));
  border: 1px solid rgba(255,255,255,.10);
  box-shadow: inset 0 0 70px rgba(0,0,0,.55), 0 10px 40px rgba(0,0,0,.35);
  -webkit-backdrop-filter: blur(1.5px);
  backdrop-filter: blur(1.5px);
  z-index: 0;
}
.ag-lane {
  position: relative;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}
.ag-lane.ag-ai { align-items: flex-end; padding-bottom: 10px; }
.ag-lane.ag-me { align-items: flex-start; padding-top: 10px; }

.ag-mid {
  flex: 0 0 auto;
  position: relative;
  height: 34px;
  width: min(560px, 86vw);
  align-self: center;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 6;
}
.ag-mid::before,
.ag-mid::after {
  content: "";
  position: absolute;
  left: 8%;
  right: 8%;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.28), transparent);
}
.ag-mid::before { top: 0; }
.ag-mid::after { bottom: 0; }
#ag-turn-info {
  position: relative;
  z-index: 1;
  padding: 2px 16px;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: .04em;
  color: #e4e4e7;
  text-shadow: 0 1px 3px #000;
  background: rgba(0,0,0,.45);
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.12);
  max-width: 80%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ag-unit {
  position: relative;
  width: min(116px, 30vw, calc((100dvh - 140px) * 0.2));
  display: flex;
  flex-direction: column;
  align-items: stretch;
  transform-origin: center center;
  will-change: transform;
}
@media (min-width: 768px) {
  .ag-unit { width: clamp(92px, 8.6vw, 128px); }
}
.ag-unit.fx-attacker { z-index: 8; filter: drop-shadow(0 10px 18px rgba(0,0,0,.65)); }
.ag-lane.ag-party { gap: 8px; padding: 0 16px; }
.ag-lane.ag-party .ag-unit {
  width: min(104px, 20vw, calc((100dvh - 140px) * 0.18));
  flex: 0 1 auto;
}
.ag-lane.ag-party[data-count="4"] .ag-unit,
.ag-lane.ag-party[data-count="5"] .ag-unit,
.ag-lane.ag-party[data-count="6"] .ag-unit {
  width: min(88px, 15vw, calc((100dvh - 140px) * 0.16));
}
.ag-unit.ag-join { opacity: 0.82; transform: scale(0.9); }
.ag-unit.ag-striking {
  opacity: 1;
  transform: scale(1.04);
  z-index: 9;
  filter: drop-shadow(0 0 16px rgba(250, 204, 21, 0.45));
}

.card-frame {
  position: relative;
  width: 100%;
  border-radius: 10px;
  overflow: hidden;
  background: linear-gradient(180deg, color-mix(in srgb, var(--rc, #71717a) 35%, #18181b), #18181b 60%);
  box-shadow: 0 0 0 2px var(--rc, #71717a), 0 10px 24px rgba(0,0,0,.55);
}
.rar-n { --rc: #9ca3af; }
.rar-r { --rc: #84cc16; }
.rar-hr { --rc: #3b82f6; }
.rar-sr { --rc: #a855f7; }
.rar-ur { --rc: #eab308; box-shadow: 0 0 0 2px #eab308, 0 0 8px 1px rgba(234,179,8,.5); }
.rar-mr { --rc: #ef4444; box-shadow: 0 0 0 2px #ef4444, 0 0 10px 2px rgba(239,68,68,.6); }
.rar-boss { --rc: #ef4444; box-shadow: 0 0 0 2px #ef4444, 0 0 10px 2px rgba(239,68,68,.55); }

.card-art { width: 100%; aspect-ratio: 3 / 4; background: #111; overflow: hidden; }
.card-img { width: 100%; height: 100%; object-fit: cover; object-position: top center; display: block; pointer-events: none; -webkit-touch-callout: none; }
.card-ph {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  font-family: "Black Han Sans", sans-serif;
  font-size: 44px; color: #fff;
  background: radial-gradient(circle at 50% 30%, color-mix(in srgb, var(--rc, #71717a) 55%, #222), #111);
}

.rar-badge {
  position: absolute;
  left: 5px;
  top: 5px;
  z-index: 2;
  font-size: 9px;
  font-weight: 900;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 4px;
  color: #fff;
  background: var(--rc, #71717a);
  border: 1px solid rgba(255,255,255,.5);
  letter-spacing: .02em;
  text-shadow: 0 1px 2px #000;
}

.card-foot {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 18px 5px 5px;
  background: linear-gradient(to top, #000 0%, rgba(0,0,0,.88) 55%, transparent);
}
.card-name {
  font-size: 11px;
  font-weight: 800;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 1px 2px #000;
}
@media (min-width: 768px) { .card-name { font-size: 12px; } }
.card-stats {
  display: flex;
  justify-content: space-between;
  gap: 4px;
  margin-top: 2px;
  font-size: 8px;
  font-weight: 800;
  letter-spacing: -.02em;
  white-space: nowrap;
}
@media (min-width: 768px) { .card-stats { font-size: 9px; } }
.card-stats .ag-st { display: inline-flex; align-items: baseline; gap: 2px; min-width: 0; }
.card-stats .ag-st em { font-style: normal; font-size: .78em; opacity: .75; font-weight: 700; }
.card-stats .ag-atk { color: #fb923c; }
.card-stats .ag-hp { color: #f87171; }
.card-stats .ag-def { color: #38bdf8; }
.card-stats b { font-weight: 900; color: inherit; }

.u-hpnum {
  text-align: center;
  font-size: 17px;
  line-height: 19px;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 1px 2px #000, 0 0 6px rgba(239,68,68,.8);
  margin-top: 5px;
  font-variant-numeric: tabular-nums;
}
.u-hpnum.low { color: #fdba74; text-shadow: 0 1px 2px #000, 0 0 8px rgba(249,115,22,.95); }
@media (min-width: 768px) { .u-hpnum { font-size: 19px; line-height: 21px; } }

.hp-bar, .mp-bar {
  position: relative;
  height: 6px;
  margin-top: 3px;
  background: rgba(255,255,255,.1);
  border-radius: 999px;
  overflow: hidden;
}
.mp-bar { height: 5px; }
.hp-fill, .mp-fill {
  position: relative;
  z-index: 1;
  height: 100%;
  border-radius: inherit;
  transition: width .35s ease-out;
}
.hp-fill { background: #ef4444; }
.hp-bar.hp-low .hp-fill { background: linear-gradient(90deg, #f97316, #facc15); }
.mp-fill { background: #3b82f6; }
.hp-ghost {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  background: rgba(254, 240, 138, .75);
  border-radius: inherit;
  transition: width .45s ease-out .3s;
  pointer-events: none;
}

.ag-unit.fx-dying {
  animation: agDie .55s ease-in forwards;
  pointer-events: none;
}
@keyframes agDie {
  0% { filter: brightness(1.6) sepia(1) saturate(6) hue-rotate(-30deg); opacity: 1; translate: 0 0; scale: 1; }
  30% { filter: brightness(1.2) sepia(1) saturate(5) hue-rotate(-30deg); opacity: 1; }
  100% { filter: grayscale(1) brightness(.5); opacity: 0; translate: 0 28px; rotate: -8deg; scale: .86; }
}

/* --- FX copied/adapted from vr-tcg index.html inline styles --- */
.fx-shake { animation: fxShake .16s linear; }
@keyframes fxShake { 0%,100% { translate: 0 0; } 15% { translate: -6px 0; } 30% { translate: 6px 0; } 45% { translate: -5px 0; } 60% { translate: 4px 0; } 75% { translate: -2px 0; } }
.fx-hitflash { filter: brightness(2.6) saturate(.4) contrast(1.1); }
/* agbattle1: white → red flash overlay on the hit card (shows during hit-stop) */
.ag-unit.fx-hitflash { filter: brightness(1.35) saturate(1.1); }
.ag-unit.fx-hitflash .card-frame::after,
.ag-unit.fx-hitflash-block .card-frame::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  border-radius: inherit;
  animation: agHitTint .3s ease-out forwards;
}
.ag-unit.fx-hitflash-block .card-frame::after { animation-name: agBlockTint; }
.ag-unit.fx-hitflash .card-frame { box-shadow: 0 0 0 2px #fff, 0 0 26px 6px rgba(255,255,255,.75), 0 0 46px 10px rgba(239,68,68,.55); }
@keyframes agHitTint {
  0% { background: rgba(255,255,255,.95); }
  28% { background: rgba(255,255,255,.75); }
  45% { background: rgba(239,68,68,.55); }
  100% { background: rgba(239,68,68,0); }
}
@keyframes agBlockTint {
  0% { background: rgba(186,230,253,.75); }
  100% { background: rgba(125,211,252,0); }
}
.fx-knock { animation: fxKnock .3s cubic-bezier(.15,.85,.3,1); }
.fx-knock.fx-shake { animation: fxKnock .3s cubic-bezier(.15,.85,.3,1), fxShake .2s linear; }
@keyframes fxKnock {
  0% { transform: translate(0, 0) scale(1) rotate(0deg); }
  14% { transform: translate(var(--kbx, 0px), var(--kby, 24px)) scale(.92, 1.04) rotate(var(--kbr, 0deg)); }
  38% { transform: translate(var(--kbx, 0px), var(--kby, 24px)) scale(1) rotate(calc(var(--kbr, 0deg) * .6)); }
  70% { transform: translate(calc(var(--kbx, 0px) * -.12), calc(var(--kby, 24px) * -.12)) rotate(calc(var(--kbr, 0deg) * -.25)); }
  100% { transform: none; }
}
.fx-sidestep { animation: fxSidestep .22s cubic-bezier(.2,.85,.3,1); }
@keyframes fxSidestep {
  0% { transform: none; }
  32% { transform: translate(var(--sbx, 22px), var(--sby, 0px)); }
  100% { transform: none; }
}
.fx-stop .ag-unit, .fx-stop .ag-unit *, .fx-stop .fx-hit { animation-play-state: paused !important; }
.fx-screen { animation: fxScreen var(--shake-ms, .24s) linear; }
/* agbattle1: first frame punches toward the hit direction, then decays */
@keyframes fxScreen {
  0%,100% { translate: 0 0; }
  10% { translate: var(--sx, 0px) var(--sy, 0px); }
  25% { translate: calc(var(--amp) * -1) calc(var(--amp) * .55); }
  42% { translate: calc(var(--amp) * .85) calc(var(--amp) * -.45); }
  60% { translate: calc(var(--amp) * -.5) calc(var(--amp) * .3); }
  80% { translate: calc(var(--amp) * .25) calc(var(--amp) * -.1); }
}
#battle.ag-mode .battle-bg { inset: -20px; }

.fx-dmg {
  position: fixed;
  z-index: 80;
  pointer-events: none;
  font-weight: 900;
  font-family: "Black Han Sans", "Noto Sans KR", system-ui, sans-serif;
  font-size: 2.35rem;
  line-height: 1;
  white-space: nowrap;
  color: #f87171;
  -webkit-text-stroke: 1.5px #450a0a;
  paint-order: stroke fill;
  text-shadow: 0 3px 0 #000, 0 0 8px #000, 0 0 16px rgba(239,68,68,.8);
  transform: translate(-50%, -50%) rotate(var(--rz, 0deg));
  animation: fxDmg 1.3s cubic-bezier(.22,.8,.3,1) forwards;
  font-variant-numeric: tabular-nums;
}
@keyframes fxDmg {
  0% { opacity: 0; translate: 0 6px; scale: 2.4; }
  5% { opacity: 1; scale: .82; }
  11% { scale: 1.18; }
  17% { scale: .96; }
  24% { scale: 1; }
  55% { opacity: 1; translate: 0 -24px; }
  100% { opacity: 0; translate: 0 -56px; }
}
.fx-dmg-crit {
  font-size: 3.6rem;
  color: #fde047;
  -webkit-text-stroke: 2px #7c2d12;
  text-shadow: 0 0 8px #f59e0b, 0 4px 0 #000, 0 0 26px #facc15;
  animation: fxCritNum 1.5s cubic-bezier(.22,.8,.3,1) forwards;
  z-index: 82;
}
@keyframes fxCritNum {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(2.8) rotate(-6deg); }
  8% { opacity: 1; transform: translate(-50%, -55%) scale(.88) rotate(2deg); }
  14% { transform: translate(-50%, -60%) scale(1.12) rotate(0); }
  20% { transform: translate(-50%, -62%) scale(1); }
  55% { opacity: 1; transform: translate(-50%, -100%) scale(1.02); }
  100% { opacity: 0; transform: translate(-50%, -160%) scale(1.05); }
}
.fx-dmg[data-n]::after { content: attr(data-n); margin-left: 3px; font-size: .7em; color: #fff; text-shadow: 0 1px 2px #000; }
.fx-merged { scale: 1.18; transition: scale .12s ease-out; }

.fx-hit {
  position: fixed;
  z-index: 75;
  pointer-events: none;
  transform: translate(-50%, -50%) scale(.45);
  opacity: 0;
  animation: fxHit .18s ease-out forwards;
  will-change: transform, opacity;
}
.fx-hit.blood { animation-duration: .2s; }
@keyframes fxHit {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.45) rotate(var(--rot, 0deg)); }
  25% { opacity: 1; }
  60% { opacity: .9; transform: translate(-50%, -50%) scale(1.05) rotate(var(--rot, 0deg)); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.25) rotate(var(--rot, 0deg)); }
}

.fx-crit {
  position: fixed;
  z-index: 81;
  pointer-events: none;
  transform: translate(-50%, -50%);
}
.fx-crit i {
  position: absolute; inset: 0; border-radius: 50%;
  background: radial-gradient(circle, rgba(255,251,200,.95) 0 12%, rgba(250,204,21,.65) 28%, rgba(245,158,11,0) 62%),
    repeating-conic-gradient(rgba(253,224,71,.85) 0 4deg, transparent 4deg 22deg);
  -webkit-mask: radial-gradient(circle, #000 30%, transparent 70%);
  mask: radial-gradient(circle, #000 30%, transparent 70%);
  animation: fxCrit .5s ease-out forwards;
}
.fx-crit b {
  position: absolute; left: 50%; top: 18%;
  transform: translate(-50%, 0) rotate(-8deg);
  font: 900 1.5rem/1 "Barlow Condensed", system-ui, sans-serif;
  letter-spacing: .08em;
  color: #fff7ae;
  -webkit-text-stroke: 1px #b45309;
  text-shadow: 0 0 10px #f59e0b, 0 2px 3px #000;
  animation: fxCritTxt .5s ease-out forwards;
}
@keyframes fxCrit { 0% { opacity: 0; transform: scale(.3) rotate(0); } 25% { opacity: 1; } 100% { opacity: 0; transform: scale(1.25) rotate(25deg); } }
@keyframes fxCritTxt {
  0% { opacity: 0; transform: translate(-50%, 0) rotate(-8deg) scale(2); }
  25% { opacity: 1; transform: translate(-50%, 0) rotate(-8deg) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -20px) rotate(-8deg) scale(1); }
}

#battle.ag-mode.bfx-hit::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  box-shadow: inset 0 0 60px 12px rgba(239,68,68,.45);
  animation: bfxHitEdge .3s ease-out forwards;
}
#battle.ag-mode.bfx-hit-strong::after {
  box-shadow: inset 0 0 0 4px rgba(255,255,255,.8), inset 0 0 110px 26px rgba(253,186,116,.85);
  animation-duration: .38s;
}
@keyframes bfxHitEdge { 0% { opacity: 1; } 100% { opacity: 0; } }
.ag-board.bfx-zoom { animation: bfxZoom .26s ease-out; }
.ag-board.bfx-zoom-strong { animation: bfxZoomStrong .36s cubic-bezier(.2,.9,.3,1); }
@keyframes bfxZoom { 0% { scale: 1; } 30% { scale: 1.03; } 100% { scale: 1; } }
@keyframes bfxZoomStrong { 0% { scale: 1; } 22% { scale: 1.075; } 55% { scale: 1.02; } 100% { scale: 1; } }

/* agbattle1: full-screen impact flash */
.fx-screenflash {
  position: absolute;
  inset: 0;
  z-index: 79;
  pointer-events: none;
  background: radial-gradient(circle at 50% 50%, rgba(255,255,255,.32), rgba(255,255,255,.08) 55%, transparent 80%);
  animation: fxScreenFlash .14s ease-out forwards;
}
.fx-screenflash.strong {
  background: radial-gradient(circle at 50% 50%, rgba(255,255,255,.7) 0%, rgba(255,250,220,.45) 30%, rgba(253,186,116,.18) 65%, transparent 90%);
  animation-duration: .23s;
}
@keyframes fxScreenFlash { 0% { opacity: 1; } 100% { opacity: 0; } }

/* --- Skill cut-in (slashCut, bands, speed lines, white flash) --- */
#cutin.hidden, .cutin.hidden { display: none !important; }
.cutin {
  position: fixed;
  left: 0; right: 0;
  z-index: 90;
  pointer-events: none;
  text-align: center;
  --dir: 1;
  --dur: .75s;
  text-shadow: 0 2px 8px #000;
  animation: slashCut var(--dur) both;
  clip-path: polygon(5% 0, 100% 0, 95% 100%, 0 100%);
}
.cutin.cutin-ai { --dir: -1; clip-path: polygon(0 0, 95% 0, 100% 100%, 5% 100%); }
.cutin-me { background: linear-gradient(90deg, transparent, rgba(16,185,129,.55) 20%, rgba(16,185,129,.55) 80%, transparent); }
.cutin-ai { background: linear-gradient(90deg, transparent, rgba(220,38,38,.55) 20%, rgba(220,38,38,.55) 80%, transparent); }
.cutin.cutin-img {
  top: 0; bottom: 0;
  margin: auto;
  padding: 0;
  aspect-ratio: 16/9;
  max-height: 52vh;
  width: min(100vw, calc(52vh * 16 / 9));
  overflow: hidden;
  background: #000;
  border-block: 0;
  box-shadow: 0 0 40px rgba(0,0,0,.8);
}
.cutin.cutin-img.cutin-me { box-shadow: 0 0 40px rgba(0,0,0,.8), inset 0 0 0 2px rgba(110,231,183,.6); }
.cutin.cutin-img.cutin-ai { box-shadow: 0 0 40px rgba(0,0,0,.8), inset 0 0 0 2px rgba(252,165,165,.6); }
@media (orientation: portrait) {
  .cutin.cutin-img { aspect-ratio: auto; width: 100vw; height: min(42vh, 90vw); max-height: none; }
}
.cutin-img .cutin-media {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; object-position: top center;
  animation: slashDrift var(--dur) linear both;
}
.cutin-img .cutin-text {
  position: absolute; left: 0; right: 0;
  display: flex; flex-direction: column-reverse; align-items: center; gap: 2px;
}
.cutin-img .cutin-text.cutin-text-bottom {
  top: auto; bottom: 0;
  padding: 1.6rem .75rem .7rem;
  background: linear-gradient(transparent, rgba(0,0,0,.6) 45%, rgba(0,0,0,.88));
}
.cutin-img .cutin-text > div:last-child {
  font-size: clamp(26px, 5.2vw, 56px) !important;
  line-height: 1.1;
  font-weight: 900;
  letter-spacing: -.01em;
  overflow-wrap: anywhere;
  -webkit-text-stroke: 1.5px rgba(0,0,0,.9);
  paint-order: stroke fill;
  text-shadow: 0 0 6px #000, 0 0 18px currentColor, 0 3px 0 #000;
}
.cutin-img.cutin-me .cutin-text > div:last-child { color: #a7f3d0; }
.cutin-img.cutin-ai .cutin-text > div:last-child { color: #fecaca; }
.cutin .cutin-text { position: relative; overflow: hidden; animation: slashTitle var(--dur) both; }
.cutin-img .cutin-text { position: absolute; }
.cutin .cutin-text::after {
  content: "";
  position: absolute; top: 0; bottom: 0; width: 30%; left: -40%;
  background: linear-gradient(105deg, transparent, rgba(255,255,255,.75), transparent);
  transform: skewX(-20deg);
  animation: slashShine var(--dur) ease-in-out both;
  pointer-events: none;
}
.cutin::after {
  content: "";
  position: absolute; inset: 0;
  background: #fff; opacity: 0;
  pointer-events: none;
  animation: slashFlash var(--dur) both;
  mix-blend-mode: screen;
}
.cutin.cutin-hit::before {
  content: "";
  position: absolute; inset: 0;
  background: #fff;
  pointer-events: none;
  mix-blend-mode: screen;
  animation: cutHit .18s ease-out both;
  z-index: 2;
}
@keyframes cutHit { from { opacity: .8; } to { opacity: 0; } }
@keyframes slashCut {
  0%   { transform: translateX(calc(var(--dir) * -125%)) skewX(calc(var(--dir) * -20deg)); animation-timing-function: cubic-bezier(.15,.85,.3,1); }
  19%  { transform: translateX(0) skewX(calc(var(--dir) * -4deg)); }
  26%  { transform: none; }
  81%  { transform: none; animation-timing-function: cubic-bezier(.7,0,.85,.15); }
  100% { transform: translateX(calc(var(--dir) * 125%)) skewX(calc(var(--dir) * -20deg)); }
}
@keyframes slashFlash { 0%, 16% { opacity: 0; } 20% { opacity: .85; } 34%, 100% { opacity: 0; } }
@keyframes slashDrift {
  0% { transform: scale(1.12) translateX(calc(var(--dir) * 2%)); }
  100% { transform: scale(1.04) translateX(calc(var(--dir) * -2%)); }
}
@keyframes slashTitle {
  0%, 14% { opacity: 0; transform: translate(calc(var(--dir) * -40%), -40%) skewX(calc(var(--dir) * -18deg)); }
  34% { opacity: 1; transform: none; animation-timing-function: ease-out; }
  100% { opacity: 1; transform: none; }
}
@keyframes slashShine { 0%, 30% { left: -40%; } 58%, 100% { left: 120%; } }
@keyframes cutInFade { 0% { opacity: 0; } 15% { opacity: 1; } 85% { opacity: 1; } 100% { opacity: 0; } }

.cutin .cut-band {
  position: absolute; left: 0; right: 0; height: 2px;
  background: var(--bandc, #34d399);
  z-index: 3; pointer-events: none;
  animation: bfxBand var(--dur) ease-out both;
}
.cutin .cut-band-t { top: 0; }
.cutin .cut-band-b { bottom: 0; }
.cutin.cutin-ai { --bandc: #f87171; }
@keyframes bfxBand {
  0% { opacity: 0; scale: .6 1; }
  18% { opacity: 1; scale: 1 1; }
  82% { opacity: 1; }
  100% { opacity: 0; }
}
.cutin .cut-speed {
  position: absolute; inset: 0; z-index: 1; pointer-events: none; opacity: .45; mix-blend-mode: screen;
  background: repeating-linear-gradient(105deg, transparent 0 18px, rgba(255,255,255,.18) 18px 20px);
  animation: cutSpeed var(--dur) linear both;
}
@keyframes cutSpeed {
  0% { opacity: 0; background-position: calc(var(--dir) * -40px) 0; }
  20% { opacity: .45; }
  80% { opacity: .35; }
  100% { opacity: 0; background-position: calc(var(--dir) * 80px) 0; }
}

/* --- Hit impact burst, sparks, terrain dust (BUILD 20261121-hitfx1) --- */
.fx-hitfx {
  position: fixed;
  left: var(--x, 50%);
  top: var(--y, 50%);
  width: 0;
  height: 0;
  z-index: 78;
  pointer-events: none;
  --burst-ms: 160ms;
  --spark-ms: 280ms;
  --dust-ms: 380ms;
  --scale: 1;
}
.fx-hitfx .fx-hitburst {
  position: absolute;
  left: 0;
  top: 0;
  width: calc(150px * var(--scale) * var(--k, 1));
  height: calc(150px * var(--scale) * var(--k, 1));
  transform: translate(-50%, -50%);
  animation: fxHitBurst var(--burst-ms) ease-out forwards;
  will-change: transform, opacity;
}
.fx-hitfx .fx-hitstar {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle, rgba(255,255,255,.95) 0 8%, var(--burst1, #fde68a) 16%, transparent 46%),
    repeating-conic-gradient(from 10deg, var(--burst0, #fff7e6) 0 3deg, transparent 3deg 20deg);
  -webkit-mask: radial-gradient(circle, #000 18%, transparent 68%);
  mask: radial-gradient(circle, #000 18%, transparent 68%);
  filter: drop-shadow(0 0 6px var(--burst1, #fde68a));
}
.fx-hitfx .fx-hitslash {
  position: absolute;
  left: 50%;
  top: 50%;
  width: calc(128px * var(--scale) * var(--k, 1));
  height: 6px;
  border-radius: 2px;
  background: linear-gradient(90deg, transparent 0%, var(--col, #fff) 18%, #fff 50%, var(--col, #fde68a) 82%, transparent 100%);
  box-shadow: 0 0 12px 2px var(--burst1, #fde68a), 0 0 3px #fff;
  transform: translate(-50%, -50%) rotate(var(--rot, 0deg)) scaleX(.2);
  animation: fxHitSlash var(--burst-ms) ease-out forwards;
}
@keyframes fxHitBurst {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.35) rotate(-8deg); }
  14% { opacity: 1; transform: translate(-50%, -50%) scale(1.1) rotate(0deg); }
  55% { opacity: 1; transform: translate(-50%, -50%) scale(1.16) rotate(3deg); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.3) rotate(8deg); }
}
@keyframes fxHitSlash {
  0% { opacity: 0; transform: translate(-50%, -50%) rotate(var(--rot, 0deg)) scaleX(.15); }
  16% { opacity: 1; transform: translate(-50%, -50%) rotate(var(--rot, 0deg)) scaleX(1); }
  58% { opacity: 1; transform: translate(-50%, -50%) rotate(var(--rot, 0deg)) scaleX(1.06); }
  100% { opacity: 0; transform: translate(-50%, -50%) rotate(var(--rot, 0deg)) scaleX(1.18); }
}
.fx-hitfx .fx-hitspark {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--len, 14px);
  height: 2px;
  border-radius: 1px;
  background: linear-gradient(90deg, var(--col, #fff), transparent);
  box-shadow: 0 0 5px var(--col, #fff);
  transform: rotate(var(--rot, 0deg));
  animation: fxHitSpark var(--spark-ms) ease-out forwards;
  animation-delay: var(--delay, 0ms);
  will-change: transform, opacity;
}
@keyframes fxHitSpark {
  0% { opacity: 1; transform: rotate(var(--rot, 0deg)) translate(4px, 0) scaleX(1); }
  100% { opacity: 0; transform: rotate(var(--rot, 0deg)) translate(var(--dist, 48px), 0) scaleX(.35); }
}
.fx-hitfx .fx-dustpuff {
  position: absolute;
  left: 0;
  top: var(--base, 72px);
  width: 0;
  height: 0;
  z-index: 1;
}
.fx-hitfx .fx-dustcloud {
  position: absolute;
  left: 0;
  top: 0;
  width: calc(88px * var(--k, 1));
  height: calc(38px * var(--k, 1));
  margin-left: calc(-44px * var(--k, 1));
  margin-top: calc(-18px * var(--k, 1));
  border-radius: 50%;
  background: radial-gradient(ellipse at 50% 60%, var(--col, #c4b49a) 0 42%, transparent 74%);
  opacity: .7;
  filter: blur(2.2px);
  box-shadow: 0 0 8px var(--col, #8a7a62);
  animation: fxDustPuff var(--dust-ms) ease-out forwards;
  animation-delay: var(--delay, 0ms);
}
.fx-hitfx .fx-dustbit {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--size, 18px);
  height: calc(var(--size, 18px) * .85);
  margin-left: calc(var(--size, 18px) / -2);
  margin-top: calc(var(--size, 18px) / -2);
  border-radius: 50%;
  background: radial-gradient(circle at 40% 40%, var(--col, #c4b49a) 0 52%, rgba(0,0,0,.25) 68%, transparent 76%);
  opacity: .9;
  filter: blur(.4px);
  box-shadow: 0 0 4px var(--col, #8a7a62);
  animation: fxDustPuff var(--dust-ms) ease-out forwards;
  animation-delay: var(--delay, 0ms);
  will-change: transform, opacity;
}
.fx-hitfx[data-group="water"] .fx-dustbit {
  height: calc(var(--size, 16px) * 1.15);
  border-radius: 40% 40% 50% 50%;
  filter: blur(.45px);
  opacity: .8;
  box-shadow: 0 0 5px var(--col, #7dd3fc);
}
.fx-hitfx[data-group="fire"] .fx-dustbit {
  height: var(--size, 10px);
  filter: blur(.35px);
  box-shadow: 0 0 6px var(--col, #fb923c);
  opacity: .85;
}
.fx-hitfx[data-group="rad"] .fx-dustbit {
  filter: blur(.7px);
  box-shadow: 0 0 5px var(--col, #84cc16);
}
.fx-hitfx[data-group="hospital"] .fx-dustbit { opacity: .45; filter: blur(1.2px); }
.fx-hitfx[data-group="forest"] .fx-dustbit { filter: blur(.8px); }
.fx-hitfx[data-result="dodge"] .fx-dustbit { opacity: .5; filter: blur(1.1px); }
.fx-hitfx[data-result="block"] .fx-hitburst { opacity: .85; }
.fx-hitfx .fx-hitring {
  position: absolute;
  left: 0;
  top: 0;
  width: calc(120px * var(--scale) * var(--k, 1));
  height: calc(120px * var(--scale) * var(--k, 1));
  border-radius: 50%;
  border: 5px solid #fff;
  box-shadow: 0 0 14px 3px var(--col, #fde68a), inset 0 0 10px var(--col, #fde68a);
  transform: translate(-50%, -50%) scale(.2);
  opacity: 0;
  animation: fxHitRing .26s cubic-bezier(.1,.8,.3,1) forwards;
}
.fx-hitfx .fx-hitring2 {
  border-color: var(--col, #fde68a);
  animation-duration: .36s;
  animation-delay: 40ms;
}
@keyframes fxHitRing {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(.2); border-width: 6px; }
  60% { opacity: .85; }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.7); border-width: 0; }
}
@keyframes fxDustPuff {
  0% { opacity: 0; transform: translate(0, 0) scale(.35); }
  18% { opacity: .9; transform: translate(calc(var(--dx, 0px) * .35), calc(var(--dy, -18px) * .35)) scale(.8); }
  55% { opacity: .75; transform: translate(calc(var(--dx, 0px) * .75), calc(var(--dy, -18px) * .75)) scale(1.15); }
  100% { opacity: 0; transform: translate(var(--dx, 0px), var(--dy, -18px)) scale(1.45); }
}

@media (prefers-reduced-motion: reduce) {
  .fx-shake { animation-duration: .06s; }
  .fx-knock, .fx-sidestep, .fx-screen { animation: none; }
  .fx-dmg { animation-duration: .5s; }
  .fx-dmg-crit { animation-duration: .6s; }
  .fx-crit i { animation-duration: .2s; }
  .hp-ghost { transition: none; }
  .ag-unit.fx-dying { animation-duration: .2s; }
  .cutin { animation: cutInFade var(--dur) both !important; clip-path: none !important; }
  .cutin::after, .cutin .cutin-text::after, .cutin.cutin-hit::before { display: none; }
  .cutin-img .cutin-media, .cutin .cutin-text, .cutin .cut-band, .cutin .cut-speed { animation: none !important; }
  .cutin .cut-speed { display: none; }
  .ag-board.bfx-zoom, .ag-board.bfx-zoom-strong { animation: none; }
  .fx-screenflash { display: none; }
  .ag-unit.fx-hitflash .card-frame::after, .ag-unit.fx-hitflash-block .card-frame::after { animation-duration: .12s; }
  .fx-hitfx { display: none !important; }
}

#battle.ag-mode .battle-toggle { z-index: 100; }

#battle.ag-mode .battle-toggle,
#battle #battle-toggle-scene {
  position: absolute;
  top: 14px;
  right: 14px;
  left: auto;
  z-index: 100;
}

/* flow1: action menu, ready, BATTLE!!, special banner. Functional, not polished. */
#battle.ag-mode.choosing .ag-unit[data-side="player"],
#battle.ag-mode.choosing .ag-menu,
#battle.ag-mode.choosing .ag-ready,
#battle.ag-mode.choosing .ag-profile { pointer-events: auto; }
.ag-unit.ag-pickable { cursor: pointer; outline: 2px solid rgba(250,204,21,.85); }

.ag-menu {
  position: absolute;
  z-index: 70;
  left: 50%;
  top: calc(50% + 30px);
  transform: translateX(78px);
  display: flex;
  flex-direction: column;
  min-width: 132px;
  background: #1d2a44;
  border: 1px solid rgba(255,255,255,.2);
  padding: 4px;
}
.ag-menu.hidden { display: none; }
.ag-act {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  background: transparent;
  color: #fff;
  border: 0;
  font-weight: 800;
  font-size: 14px;
  cursor: pointer;
}
.ag-act:hover, .ag-act.on { background: #2c4470; }
.ag-act[disabled] { opacity: .4; cursor: default; }
@media (max-width: 500px) {
  .ag-menu {
    left: 8px;
    right: 8px;
    top: auto;
    bottom: 6px;
    transform: none;
  }
}

.ag-ready {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 70;
  pointer-events: auto;
  padding: 10px 22px;
  border: 0;
  border-radius: 8px;
  background: #2b4d9b;
  color: #fff;
  font-weight: 900;
  font-size: 16px;
  cursor: pointer;
}
.ag-ready.hidden { display: none; }

.ag-flash {
  position: absolute;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.ag-flash.hidden { display: none; }
.ag-flash b {
  font: 900 64px/1 "Black Han Sans", "Barlow Condensed", sans-serif;
  font-style: italic;
  color: #fff;
  letter-spacing: .06em;
  text-shadow: 0 3px 0 #000, 0 0 18px #000;
}
@media (max-width: 500px) { .ag-flash b { font-size: 48px; } }

.ag-skill-banner {
  position: absolute;
  left: 0;
  right: 0;
  top: 34%;
  height: 28%;
  min-height: 120px;
  z-index: 75;
  overflow: hidden;
  background: #111;
  pointer-events: none;
}
.ag-skill-banner.hidden { display: none; }
.ag-skill-banner.from-ai { transform: translateX(100%); }
.ag-skill-banner.from-me { transform: translateX(-100%); }
.ag-skill-banner.in { transition: transform .28s ease-out; transform: translateX(0); }
.ag-skill-banner.out { transition: transform .2s ease-in; }
.ag-skill-banner.from-ai.out { transform: translateX(100%); }
.ag-skill-banner.from-me.out { transform: translateX(-100%); }
.ag-skill-art {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: top center;
}
.ag-skill-art.ph {
  display: flex;
  align-items: center;
  justify-content: center;
  font: 900 64px/1 "Black Han Sans", sans-serif;
  color: #fff;
}
.ag-skill-name {
  position: absolute;
  left: 14px;
  bottom: 10px;
  color: #fff;
  font-size: 28px;
  font-weight: 900;
  text-shadow: 0 2px 6px #000;
}

.ag-profile {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 80;
  width: min(320px, 86vw);
  background: #14161c;
  color: #fff;
  border: 1px solid rgba(255,255,255,.2);
  padding: 16px;
  pointer-events: auto;
}
.ag-profile.hidden { display: none; }
.ag-profile header { display: flex; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.ag-profile header b { font-size: 20px; }
.ag-profile header i { font-style: normal; opacity: .8; }
.ag-profile p { margin: 4px 0; }
.ag-profile-close {
  margin-top: 12px;
  padding: 6px 14px;
  background: #2b4d9b;
  color: #fff;
  border: 0;
  cursor: pointer;
  font-weight: 800;
}
