/**
 * Flip Card Animation Tiers
 * 
 * Three animation levels for card reveal:
 *   - None (off): Instant swap, no transitions
 *   - Reduced (minimal): Simple CSS 3D flip, 0.3s
 *   - Playful: Card lifts, flips, lands with particle burst on safe, 0.5s
 *
 * Uses a front/back card structure:
 *   .flip-anim-card > .flip-anim-card-inner > (.flip-anim-front + .flip-anim-back)
 *
 * Trigger reveal by adding .is-revealed to .flip-anim-card
 */

/* ============================================
   Demo Page Layout
   ============================================ */

.anim-demo-page {
  max-width: 1200px;
  margin: 0 auto;
}

.anim-demo-tier {
  flex: 1;
  min-width: 280px;
}

.anim-demo-tier .card {
  height: 100%;
}

.anim-demo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  justify-items: center;
  padding: 8px 0;
}

.anim-demo-controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ============================================
   Base Card Structure (front/back)
   ============================================ */

.flip-anim-card {
  width: var(--flip-card-size, 80px);
  height: calc(var(--flip-card-size, 80px) * 1.3);
  perspective: 600px;
  cursor: pointer;
  position: relative;
}

.flip-anim-card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: none; /* overridden per tier */
  transform-style: preserve-3d;
}

.flip-anim-front,
.flip-anim-back {
  position: absolute;
  inset: 0;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  font-size: 32px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.flip-anim-front {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: rgba(255, 255, 255, 0.8);
  z-index: 2;
}

/* Card skin override (F15): when a skin image URL is applied via inline style,
   suppress the CSS gradient so background-image shows through. */
.flip-anim-front[style*="background-image"] {
  background: none;
  border-radius: 12px;
  overflow: hidden;
}

.flip-anim-front i {
  font-size: 36px;
}

.flip-anim-back {
  transform: rotateY(180deg);
  color: white;
}

.flip-anim-back.is-safe {
  background: linear-gradient(135deg, #ffd700 0%, #ffb347 100%);
}

.flip-anim-back.is-bust {
  background: linear-gradient(135deg, #3a539b 0%, #1e3a5f 100%);
}

.flip-anim-back .flip-card-emoji {
  font-size: 36px;
  line-height: 1;
}

/* Card hover (unrevealed only) */
.flip-anim-card:not(.is-revealed):hover .flip-anim-front {
  transform: translateY(-4px) scale(1.05);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.4);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

/* ============================================
   Tier 1: None (off) — Instant Swap
   ============================================ */

.flip-anim-none .flip-anim-card-inner {
  transition: none;
}

.flip-anim-none .flip-anim-card.is-revealed .flip-anim-card-inner {
  transform: rotateY(180deg);
}

/* ============================================
   Tier 2: Reduced (minimal) — Simple 3D Flip
   ============================================ */

.flip-anim-reduced .flip-anim-card-inner {
  transition: transform 0.3s ease;
}

.flip-anim-reduced .flip-anim-card.is-revealed .flip-anim-card-inner {
  transform: rotateY(180deg);
}

/* ============================================
   Tier 3: Playful — Lift + Flip + Land
   ============================================ */

/* --- Bust cards: standard lift-flip-land --- */
.flip-anim-playful .flip-anim-card.is-revealed.is-bust-reveal .flip-anim-card-inner {
  animation: flip-playful-reveal-bust 0.5s ease forwards;
}

@keyframes flip-playful-reveal-bust {
  0%   { transform: rotateY(0deg) translateY(0) scale(1); }
  30%  { transform: rotateY(60deg) translateY(-20px) scale(1.08); }
  60%  { transform: rotateY(140deg) translateY(-10px) scale(1.04); }
  100% { transform: rotateY(180deg) translateY(0) scale(1); }
}

/* --- Safe (winning) cards: dramatic launch + bounce landing --- */
.flip-anim-playful .flip-anim-card.is-revealed.is-safe-reveal .flip-anim-card-inner {
  animation: flip-playful-reveal-safe 0.7s cubic-bezier(0.22, 1.2, 0.36, 1) forwards;
}

@keyframes flip-playful-reveal-safe {
  0%   { transform: rotateY(0deg) translateY(0) scale(1); }
  20%  { transform: rotateY(40deg) translateY(-35px) scale(1.15); }
  50%  { transform: rotateY(160deg) translateY(-18px) scale(1.1); }
  70%  { transform: rotateY(180deg) translateY(6px) scale(0.95); }
  85%  { transform: rotateY(180deg) translateY(-4px) scale(1.06); }
  100% { transform: rotateY(180deg) translateY(0) scale(1); }
}

/* Golden glow ring expanding outward */
.flip-anim-playful .flip-anim-card.is-revealed.is-safe-reveal::after {
  content: '';
  position: absolute;
  inset: -10px;
  border-radius: 18px;
  border: 3px solid rgba(255, 215, 0, 0.6);
  background: radial-gradient(circle, rgba(255, 215, 0, 0.35) 0%, transparent 65%);
  animation: flip-safe-ring 0.8s ease-out forwards;
  pointer-events: none;
  z-index: 10;
}

@keyframes flip-safe-ring {
  0%   { opacity: 0; transform: scale(0.4); border-color: rgba(255, 215, 0, 0.8); }
  35%  { opacity: 1; transform: scale(1.2); border-color: rgba(255, 215, 0, 0.6); }
  60%  { opacity: 0.7; transform: scale(1.5); border-color: rgba(255, 215, 0, 0.3); }
  100% { opacity: 0; transform: scale(2); border-color: rgba(255, 215, 0, 0); }
}

/* Sparkle flash on the card itself */
.flip-anim-playful .flip-anim-card.is-revealed.is-safe-reveal::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 12px;
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0) 0%,
    rgba(255, 255, 255, 0.6) 45%,
    rgba(255, 255, 255, 0) 55%,
    rgba(255, 255, 255, 0) 100%
  );
  background-size: 300% 300%;
  animation: flip-safe-shine 0.6s ease-out 0.3s forwards;
  opacity: 0;
  pointer-events: none;
  z-index: 11;
}

@keyframes flip-safe-shine {
  0%   { opacity: 0; background-position: 100% 100%; }
  30%  { opacity: 1; }
  100% { opacity: 0; background-position: 0% 0%; }
}

/* Lingering golden glow behind safe card after reveal */
.flip-anim-playful .flip-anim-card.is-revealed.is-safe-reveal .flip-anim-back {
  box-shadow:
    0 4px 15px rgba(0, 0, 0, 0.3),
    0 0 18px 4px rgba(255, 215, 0, 0.35);
  animation: flip-safe-glow-pulse 2s ease-in-out 0.7s infinite;
}

@keyframes flip-safe-glow-pulse {
  0%, 100% { box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3), 0 0 18px 4px rgba(255, 215, 0, 0.35); }
  50%      { box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3), 0 0 24px 8px rgba(255, 215, 0, 0.5); }
}

/* Shake on bust reveal (playful tier only) */
.flip-anim-playful .flip-anim-card.is-revealed.is-bust-reveal {
  animation: flip-bust-shake 0.5s ease 0.3s;
}

@keyframes flip-bust-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px) rotate(-2deg); }
  40% { transform: translateX(6px) rotate(2deg); }
  60% { transform: translateX(-4px) rotate(-1deg); }
  80% { transform: translateX(4px) rotate(1deg); }
}

/* ============================================
   Disabled state (already revealed)
   ============================================ */

.flip-anim-card.is-revealed {
  cursor: default;
}

/* Pre-revealed cards (rendered during full DOM rebuild, e.g. page load or
   resuming an active round). Show in final flipped state with no animation
   or transition so only the *newly* clicked card animates. */
.flip-anim-card.is-pre-revealed .flip-anim-card-inner {
  transform: rotateY(180deg);
  transition: none !important;
  animation: none !important;
}
.flip-anim-card.is-pre-revealed {
  animation: none !important;
}
.flip-anim-card.is-pre-revealed::before,
.flip-anim-card.is-pre-revealed::after {
  display: none !important;
}

/* ============================================
   Responsive
   ============================================ */

@media (max-width: 575.98px) {
  .anim-demo-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }

  .flip-anim-card {
    --flip-card-size: 65px;
  }

  .flip-anim-front i {
    font-size: 28px;
  }

  .flip-anim-back .flip-card-emoji {
    font-size: 28px;
  }
}
