/* Animation de combat — TerrierClash */

body.battle-overlay-active {
  overflow: hidden;
}

#battle-overlay.battle-overlay,
.battle-overlay {
  position: fixed;
  inset: 0;
  z-index: 9500;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  pointer-events: auto;
}

.battle-overlay.hidden {
  display: none !important;
}

.battle-overlay__dim {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 80% 60% at 50% 40%, rgba(30, 27, 45, 0.97), rgba(8, 9, 12, 0.98));
  backdrop-filter: blur(8px);
}

.battle-clash-flash {
  position: absolute;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  z-index: 14;
}

.battle-clash-flash--on {
  animation: battleFlash 0.16s ease-out forwards;
}

@keyframes battleFlash {
  0% {
    opacity: 0;
  }
  40% {
    opacity: 0.88;
  }
  100% {
    opacity: 0;
  }
}

.battle-particles {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 12;
  overflow: hidden;
}

.battle-container {
  position: relative;
  z-index: 5;
  isolation: isolate;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: min(4vw, 1.5rem);
  width: 100%;
  max-width: 920px;
  transform-origin: center center;
  transition: transform 0.85s cubic-bezier(0.34, 1.1, 0.64, 1);
  will-change: transform;
}

.battle-container--shake {
  animation: battleShake 0.22s ease-out;
}

@keyframes battleShake {
  0%,
  100% {
    transform: translate3d(0, 0, 0);
  }
  20% {
    transform: translate3d(-6px, 2px, 0);
  }
  40% {
    transform: translate3d(5px, -3px, 0);
  }
  60% {
    transform: translate3d(-3px, 2px, 0);
  }
  80% {
    transform: translate3d(4px, -1px, 0);
  }
}

/* Phase 1 — entrée */
.battle-phase--enter .battle-card {
  opacity: 0;
  animation: battleCardInLeft 0.62s cubic-bezier(0.22, 1, 0.36, 1) forwards;
  animation-delay: calc(var(--stagger, 0) * 1s);
}

.battle-phase--enter .team-right .battle-card {
  animation-name: battleCardInRight;
}

@keyframes battleCardInLeft {
  from {
    opacity: 0;
    transform: translateX(-120%) rotateY(-12deg) scale(0.92);
    filter: blur(4px);
  }
  to {
    opacity: 1;
    transform: translateX(0) rotateY(0) scale(1);
    filter: blur(0);
  }
}

@keyframes battleCardInRight {
  from {
    opacity: 0;
    transform: translateX(120%) rotateY(12deg) scale(0.92);
    filter: blur(4px);
  }
  to {
    opacity: 1;
    transform: translateX(0) rotateY(0) scale(1);
    filter: blur(0);
  }
}

/* Phase 2 — tension */
.battle-phase--tension .battle-container {
  transform: scale(1.06);
}

.battle-phase--tension .battle-tension-glow {
  opacity: 1;
}

.battle-phase--tension .vs {
  animation: battleVsPulse 0.55s ease-in-out infinite alternate;
}

.battle-tension-glow {
  position: absolute;
  left: 50%;
  top: 48%;
  width: 160px;
  height: 220px;
  margin-left: -80px;
  margin-top: -110px;
  background: radial-gradient(
    ellipse,
    rgba(251, 191, 36, 0.35) 0%,
    rgba(139, 92, 246, 0.2) 45%,
    transparent 70%
  );
  opacity: 0;
  pointer-events: none;
  z-index: 0;
  transition: opacity 0.4s ease;
}

@keyframes battleVsPulse {
  from {
    transform: scale(1);
    text-shadow: 0 0 20px rgba(251, 191, 36, 0.4);
    opacity: 0.85;
  }
  to {
    transform: scale(1.12);
    text-shadow: 0 0 36px rgba(251, 191, 36, 0.75);
    opacity: 1;
  }
}

.battle-phase--tension .team-left,
.battle-phase--tension .team-right {
  animation: battleTensionShake 0.12s ease-in-out infinite;
}

@keyframes battleTensionShake {
  0%,
  100% {
    transform: translateX(0);
  }
  50% {
    transform: translateX(1px);
  }
}

/* Phase 3 — clash */
.battle-phase--clash .team-left {
  animation: battleDashLeft 0.38s cubic-bezier(0.45, 0, 0.55, 1) forwards;
}

.battle-phase--clash .team-right {
  animation: battleDashRight 0.38s cubic-bezier(0.45, 0, 0.55, 1) forwards;
}

.battle-phase--clash .battle-card {
  filter: blur(1px);
}

@keyframes battleDashLeft {
  0% {
    transform: translateX(0);
  }
  55% {
    transform: translateX(18%);
  }
  100% {
    transform: translateX(0);
  }
}

@keyframes battleDashRight {
  0% {
    transform: translateX(0);
  }
  55% {
    transform: translateX(-18%);
  }
  100% {
    transform: translateX(0);
  }
}

/* Phase 4 — résultat visuel sur les équipes */
.battle-phase--outcome .team-left,
.battle-phase--outcome .team-right {
  transition:
    opacity 0.45s ease,
    filter 0.45s ease,
    transform 0.45s ease;
}

.battle-container[data-winner='A'] .team-right {
  opacity: 0.45;
  filter: grayscale(0.65);
  transform: scale(0.96);
}

.battle-container[data-winner='A'] .team-left {
  filter: drop-shadow(0 0 16px rgba(234, 179, 8, 0.55));
}

.battle-container[data-winner='B'] .team-left {
  opacity: 0.45;
  filter: grayscale(0.65);
  transform: scale(0.96);
}

.battle-container[data-winner='B'] .team-right {
  filter: drop-shadow(0 0 16px rgba(234, 179, 8, 0.55));
}

.team {
  position: relative;
  z-index: 1;
  min-width: 0;
}

.battle-team__label {
  font-size: 0.78rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 0.65rem;
  color: rgba(255, 255, 255, 0.55);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.battle-team__row {
  display: flex;
  justify-content: center;
  gap: 6px;
  flex-wrap: nowrap;
  max-width: 100%;
  overflow-x: auto;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
}

.battle-card {
  width: min(18vw, 88px);
  flex-shrink: 0;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: #0a0c10;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  transform-style: preserve-3d;
  transition:
    box-shadow 0.2s ease,
    transform 0.2s ease;
}

.battle-card:hover {
  box-shadow: 0 0 18px rgba(167, 139, 250, 0.25);
}

.battle-card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
}

.battle-card__pseudo {
  display: block;
  font-size: 0.62rem;
  font-weight: 600;
  text-align: center;
  padding: 0.25rem 0.2rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: rgba(15, 17, 21, 0.95);
  color: rgba(255, 255, 255, 0.88);
}

.vs {
  position: relative;
  z-index: 2;
  font-size: clamp(1.5rem, 5vw, 2.25rem);
  font-weight: 800;
  font-style: italic;
  background: linear-gradient(135deg, #fde68a, #f59e0b, #ea580c);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  padding: 0 0.35rem;
}

/* Bloc résultat */
.battle-result {
  position: relative;
  z-index: 6;
  margin-top: 1.25rem;
  max-width: 28rem;
  width: 100%;
  padding: 1.25rem 1.35rem;
  border-radius: 16px;
  background: rgba(18, 20, 28, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
  text-align: center;
  opacity: 0;
  transform: translateY(16px);
  transition:
    opacity 0.45s ease,
    transform 0.45s cubic-bezier(0.34, 1.2, 0.64, 1);
}

.battle-result.battle-result--visible {
  opacity: 1;
  transform: translateY(0);
}

.battle-result.hidden {
  display: none !important;
}

.result-text {
  font-size: clamp(1.75rem, 5vw, 2.35rem);
  font-weight: 800;
  letter-spacing: 0.06em;
  margin: 0 0 0.65rem;
}

.result-text--win {
  background: linear-gradient(135deg, #fde047, #eab308, #84cc16);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 40px rgba(234, 179, 8, 0.35);
}

.result-text--loss {
  color: #94a3b8;
}

.result-phrase {
  font-size: 1.05rem;
  line-height: 1.55;
  color: #e8eaef;
  margin: 0 0 0.5rem;
}

.result-event {
  font-size: 0.95rem;
  font-style: italic;
  color: rgba(255, 255, 255, 0.55);
  margin: 0 0 0.75rem;
  line-height: 1.45;
}

.result-event.hidden {
  display: none !important;
}

.result-elo {
  font-size: 0.88rem;
  color: rgba(255, 255, 255, 0.65);
  margin: 0 0 0.85rem;
}

#battle-continue.hidden {
  display: none !important;
}

@media (prefers-reduced-motion: reduce) {
  .battle-card,
  .battle-phase--tension .vs,
  .battle-phase--clash .team-left,
  .battle-phase--clash .team-right,
  .battle-clash-flash--on,
  .battle-container--shake {
    animation: none !important;
  }

  .battle-phase--enter .battle-card {
    opacity: 1;
    animation: none !important;
    transform: none !important;
    filter: none !important;
  }

  .battle-phase--tension .battle-container {
    transform: none;
  }

  .battle-result {
    opacity: 1;
    transform: none;
  }
}
