/* Animation d’ouverture de carte — TerrierClash */

body.card-opening-active {
  overflow: hidden;
}

.card-opening-overlay {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  pointer-events: auto;
}

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

.card-opening-overlay__dim {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.78);
  backdrop-filter: blur(6px);
}

.card-opening-overlay__glow {
  position: absolute;
  left: 50%;
  top: 42%;
  width: min(120vw, 520px);
  height: min(120vw, 520px);
  transform: translate(-50%, -50%);
  background: radial-gradient(
    circle,
    rgba(139, 92, 246, 0.35) 0%,
    rgba(59, 130, 246, 0.12) 40%,
    transparent 70%
  );
  pointer-events: none;
  opacity: 0.4;
  transition: opacity 0.4s ease;
}

.card-opening-overlay__flash {
  position: absolute;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  z-index: 3;
}

.card-opening-overlay__flash--on {
  animation: coFlash 0.14s ease-out forwards;
}

@keyframes coFlash {
  0% {
    opacity: 0;
  }
  35% {
    opacity: 0.92;
  }
  100% {
    opacity: 0;
  }
}

.card-opening-particles {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  overflow: hidden;
}

.co-particle {
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  margin: -3px 0 0 -3px;
  animation: coParticleFade 1s ease-out forwards;
  will-change: transform, opacity;
}

@keyframes coParticleFade {
  0% {
    opacity: 1;
    transform: translate(0, 0) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(var(--tx, 40px), var(--ty, -30px)) scale(0.2);
  }
}

.card-opening-stage {
  position: relative;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
  max-width: 100%;
}

.card-container {
  perspective: 1000px;
  width: min(72vw, 280px);
  height: min(95vw, 380px);
}

.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  border-radius: 16px;
  transition: transform 0.68s cubic-bezier(0.34, 1.3, 0.64, 1);
  will-change: transform;
  box-shadow:
    0 4px 24px rgba(0, 0, 0, 0.45),
    0 0 0 1px rgba(255, 255, 255, 0.06);
}

.card-opening-inner--flipped {
  transform: rotateY(180deg) scale(1.06);
}

@keyframes coFloat {
  0%,
  100% {
    transform: rotateY(180deg) scale(1.06) translateY(0);
  }
  50% {
    transform: rotateY(180deg) scale(1.06) translateY(-6px);
  }
}

.card-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 16px;
  overflow: hidden;
}

.card-front {
  background: linear-gradient(145deg, #1e1a2e 0%, #12101a 50%, #1a1530 100%);
  border: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.card-front__mark {
  font-size: 2.5rem;
  font-weight: 800;
  letter-spacing: -0.05em;
  background: linear-gradient(135deg, #c4b5fd, #60a5fa, #fb923c);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 40px rgba(139, 92, 246, 0.4);
}

.card-front__sub {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: rgba(255, 255, 255, 0.45);
  font-weight: 600;
}

.card-back {
  transform: rotateY(180deg);
  background: #0a0c10;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.card-back img {
  width: 100%;
  height: calc(100% - 3rem);
  object-fit: cover;
  display: block;
}

.card-back__pseudo {
  padding: 0.65rem 0.75rem;
  font-weight: 700;
  font-size: 0.95rem;
  text-align: center;
  background: linear-gradient(180deg, rgba(20, 22, 28, 0.95), rgba(15, 17, 21, 0.98));
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

/* Phase 1 — préparation */
.co-phase--prep .card-container {
  animation: coPrepIn 0.52s cubic-bezier(0.34, 1.2, 0.64, 1) forwards;
}

.co-phase--prep .card-inner {
  animation: coPrepGlow 0.52s ease-out forwards;
}

@keyframes coPrepIn {
  from {
    transform: scale(0.88);
    opacity: 0.85;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes coPrepGlow {
  from {
    box-shadow: 0 0 0 rgba(139, 92, 246, 0);
  }
  to {
    box-shadow:
      0 8px 32px rgba(0, 0, 0, 0.5),
      0 0 48px rgba(139, 92, 246, 0.25);
  }
}

/* Phase 2 — charge */
.co-phase--charge .card-inner:not(.card-opening-inner--flipped) {
  animation: coShake 0.14s ease-in-out infinite;
}

.co-phase--charge .card-opening-overlay__glow {
  animation: coGlowPulse 1.2s ease-in-out infinite;
  opacity: 0.85;
}

@keyframes coShake {
  0%,
  100% {
    transform: translate3d(0, 0, 0) rotateZ(-0.4deg) scale(1);
  }
  25% {
    transform: translate3d(1px, -1px, 0) rotateZ(0.5deg) scale(1.008);
  }
  50% {
    transform: translate3d(-1px, 1px, 0) rotateZ(-0.3deg) scale(0.995);
  }
  75% {
    transform: translate3d(0.5px, 0.5px, 0) rotateZ(0.35deg) scale(1.004);
  }
}

@keyframes coGlowPulse {
  0%,
  100% {
    transform: translate(-50%, -50%) scale(0.92);
    opacity: 0.55;
  }
  50% {
    transform: translate(-50%, -50%) scale(1.08);
    opacity: 1;
  }
}

/* Après flip : ne pas cumuler shake avec float */
.co-phase--charge .card-opening-inner--flipped {
  animation: none;
}

.co-phase--reveal .card-inner.card-opening-inner--flipped {
  animation: coFloat 3.5s ease-in-out infinite;
  box-shadow:
    0 8px 40px rgba(139, 92, 246, 0.35),
    0 0 60px rgba(59, 130, 246, 0.2),
    0 0 0 1px rgba(255, 255, 255, 0.1);
}

.card-opening-copy {
  text-align: center;
  max-width: 22rem;
  opacity: 0;
  transform: translateY(12px);
  transition:
    opacity 0.55s ease,
    transform 0.55s cubic-bezier(0.34, 1.2, 0.64, 1);
}

.card-opening-copy--visible {
  opacity: 1;
  transform: translateY(0);
}

.co-title {
  margin: 0 0 0.35rem;
  font-size: 1.15rem;
  font-weight: 700;
  background: linear-gradient(90deg, #e9d5ff, #93c5fd, #fdba74);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.co-pseudo {
  margin: 0 0 0.5rem;
  font-size: 1.25rem;
  font-weight: 700;
  color: #f1f3f7;
}

.co-desc {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.45;
  color: rgba(255, 255, 255, 0.65);
  max-height: min(42vh, 20rem);
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 0.35rem;
  text-align: left;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  -webkit-overflow-scrolling: touch;
}

.co-continue {
  margin-top: 0.25rem;
  min-width: 12rem;
  box-shadow: 0 4px 24px rgba(251, 146, 60, 0.25);
}

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

@media (prefers-reduced-motion: reduce) {
  .card-inner,
  .card-container,
  .card-opening-overlay__glow,
  .card-opening-overlay__flash--on,
  .co-particle {
    animation: none !important;
    transition-duration: 0.01ms !important;
  }

  .co-phase--charge .card-inner:not(.card-opening-inner--flipped) {
    animation: none !important;
  }

  .co-phase--reveal .card-inner.card-opening-inner--flipped {
    animation: none !important;
  }
}
