/* ============================================================
   Card-Deal Modal — Daily Brew UX
   Animations, card-back, choice tiles, progress, confetti
   ============================================================ */

/* ---------- Modal Backdrop ---------- */
.card-deal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 9990;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

/* ---------- Modal Container ---------- */
.card-deal-modal {
  position: fixed;
  inset: 0;
  z-index: 9991;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.card-deal-modal .card-deal-viewport {
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  border-radius: 1.25rem;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.35);
}

@media (max-width: 639px) {
  .card-deal-modal {
    padding: 0;
    align-items: stretch;
  }
  .card-deal-modal .card-deal-viewport {
    max-width: 100%;
    max-height: 100vh;
    border-radius: 0;
    height: 100%;
  }
}

/* ---------- Card Step Visibility ---------- */
.card-step {
  display: none;
  opacity: 0;
}

.card-step.active {
  display: block;
  animation: cardDealIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.card-step.exiting {
  display: block;
  animation: cardDealOut 0.3s ease-in forwards;
}

.card-step.active.reverse {
  animation: cardDealInReverse 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.card-step.exiting.reverse {
  display: block;
  animation: cardDealOutReverse 0.3s ease-in forwards;
}

/* ---------- Card Deal Keyframes ---------- */
@keyframes cardDealIn {
  0% {
    opacity: 0;
    transform: translateX(80px) rotate(3deg) scale(0.95);
  }
  100% {
    opacity: 1;
    transform: translateX(0) rotate(0) scale(1);
  }
}

@keyframes cardDealOut {
  0% {
    opacity: 1;
    transform: translateX(0) rotate(0) scale(1);
  }
  100% {
    opacity: 0;
    transform: translateX(-80px) rotate(-3deg) scale(0.95);
  }
}

@keyframes cardDealInReverse {
  0% {
    opacity: 0;
    transform: translateX(-80px) rotate(-3deg) scale(0.95);
  }
  100% {
    opacity: 1;
    transform: translateX(0) rotate(0) scale(1);
  }
}

@keyframes cardDealOutReverse {
  0% {
    opacity: 1;
    transform: translateX(0) rotate(0) scale(1);
  }
  100% {
    opacity: 0;
    transform: translateX(80px) rotate(3deg) scale(0.95);
  }
}

/* ---------- Card Shake (Validation fail) ---------- */
.card-shake {
  animation: cardShake 0.4s ease-in-out;
}

@keyframes cardShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}

/* ---------- Choice Tile ---------- */
.choice-tile {
  cursor: pointer;
  border: 2px solid oklch(var(--b3, 0.87 0 0));
  border-radius: 0.75rem;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
}

.choice-tile:hover {
  border-color: oklch(var(--p, 0.65 0.2 260));
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.choice-tile:has(:checked) {
  border-color: oklch(var(--p, 0.65 0.2 260));
  background: oklch(var(--p, 0.65 0.2 260) / 0.08);
  box-shadow: 0 0 0 3px oklch(var(--p, 0.65 0.2 260) / 0.2);
  animation: choiceBounce 0.3s ease;
}

@keyframes choiceBounce {
  0% { transform: scale(1); }
  50% { transform: scale(1.04); }
  100% { transform: scale(1); }
}

/* ---------- Progress Bar ---------- */
.brew-progress-track {
  width: 100%;
  height: 6px;
  border-radius: 9999px;
  background: oklch(var(--b3, 0.87 0 0));
  overflow: hidden;
}

.brew-progress-fill {
  height: 100%;
  border-radius: 9999px;
  background: linear-gradient(90deg, #d97706, #f59e0b);
  transition: width 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  min-width: 0;
}

/* ---------- Card Flip (Results Reveal) ---------- */
/*
  Layout contract:
    .card-flip-container  → sets perspective and flex container
    .card-flip-inner      → maintains 3D transform context (preserve-3d)
    .card-flip-front      → normal document flow, dictates the natural height of the card
    .card-flip-back       → position: absolute; inset: 0 overlay pinned 1:1 to the front face
  Both faces share the exact same coordinate space at (0, 0), completely eliminating layout shifts.
*/
.card-flip-container {
  perspective: 1200px;
  position: relative;
  min-height: 480px;
  display: flex;
  flex-direction: column;
}

.card-flip-inner {
  position: relative;
  width: 100%;
  height: 100%;
  flex: 1;
  display: flex;
  flex-direction: column;
  transition: transform 0.7s cubic-bezier(0.4, 0, 0.2, 1);
  transform-style: preserve-3d;
  will-change: transform;
}

.result-card-reveal .card-flip-inner {
  transform: rotateY(180deg);
}

.result-card-reveal.revealed .card-flip-inner {
  transform: rotateY(0deg);
}

.card-flip-front {
  width: 100%;
  height: 100%;
  flex: 1;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  transform: rotateY(0deg);
}

.card-flip-back {
  position: absolute !important;
  inset: 0 !important;
  width: 100% !important;
  height: 100% !important;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  transform: rotateY(180deg);
  border-radius: 1rem;
  overflow: hidden;
  z-index: 2;
}

/* ---------- Card Back Design ---------- */
.card-back-design {
  background: linear-gradient(135deg, #78350f 0%, #451a03 50%, #78350f 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 2rem;
  overflow: hidden;
  border-radius: 1rem;
}

.card-back-design::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40' viewBox='0 0 40 40'%3E%3Cellipse cx='20' cy='20' rx='6' ry='9' fill='%23a16207' fill-opacity='0.15' transform='rotate(30 20 20)'/%3E%3C/svg%3E");
  background-repeat: repeat;
  opacity: 0.5;
}

.card-back-design::after {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: linear-gradient(
    60deg,
    transparent 20%,
    rgba(255, 255, 255, 0.05) 30%,
    rgba(255, 255, 255, 0.1) 32%,
    rgba(255, 255, 255, 0.05) 34%,
    transparent 44%
  );
  animation: shimmer 3s ease-in-out infinite;
}

@keyframes shimmer {
  0% { transform: translateX(-100%) translateY(-100%) rotate(0deg); }
  100% { transform: translateX(100%) translateY(100%) rotate(0deg); }
}

.card-back-design .card-back-logo {
  position: relative;
  z-index: 1;
  font-size: 3rem;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.3));
}

.card-back-design .card-back-text {
  position: relative;
  z-index: 1;
  color: #fbbf24;
  font-weight: 800;
  font-size: 0.875rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

/* ---------- Wild Card Golden Glow ---------- */
.wildcard-glow {
  animation: goldenPulse 2s ease-in-out infinite;
}

@keyframes goldenPulse {
  0%, 100% {
    box-shadow: 0 0 8px rgba(245, 158, 11, 0.3),
                0 0 20px rgba(245, 158, 11, 0.1);
  }
  50% {
    box-shadow: 0 0 16px rgba(245, 158, 11, 0.5),
                0 0 40px rgba(245, 158, 11, 0.2);
  }
}

.wildcard-entrance {
  animation: wildcardShake 0.5s ease-in-out;
}

@keyframes wildcardShake {
  0%, 100% { transform: rotate(0deg); }
  20% { transform: rotate(-2deg); }
  40% { transform: rotate(2deg); }
  60% { transform: rotate(-1deg); }
  80% { transform: rotate(1deg); }
}

/* ---------- Confetti Burst ---------- */
.confetti-burst {
  position: relative;
}

.confetti-burst::before,
.confetti-burst::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  pointer-events: none;
  z-index: 100;
}

.confetti-burst::before {
  background: #f59e0b;
  animation: confettiLeft 0.8s ease-out forwards;
}

.confetti-burst::after {
  background: #ef4444;
  animation: confettiRight 0.8s ease-out forwards;
}

@keyframes confettiLeft {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-120px, -80px) scale(0.5) rotate(720deg); }
}

@keyframes confettiRight {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(120px, -80px) scale(0.5) rotate(-720deg); }
}

/* Extra confetti particles via box-shadow on a wrapper */
.confetti-particles {
  position: fixed;
  top: 50%;
  left: 50%;
  width: 6px;
  height: 6px;
  z-index: 99999;
  pointer-events: none;
  border-radius: 1px;
  animation: confettiExplode 1s ease-out forwards;
  box-shadow:
    -30px -60px 0 #f59e0b,
     30px -70px 0 #ef4444,
    -50px -40px 0 #22c55e,
     50px -50px 0 #3b82f6,
    -20px -80px 0 #a855f7,
     20px -90px 0 #ec4899,
    -60px -30px 0 #f97316,
     60px -40px 0 #14b8a6,
      0px -100px 0 #eab308,
     40px -20px 0 #8b5cf6,
    -40px -55px 0 #06b6d4,
     10px -65px 0 #f43f5e;
}

@keyframes confettiExplode {
  0% {
    opacity: 1;
    transform: scale(0);
  }
  50% {
    opacity: 1;
    transform: scale(1.5);
  }
  100% {
    opacity: 0;
    transform: scale(2.5) translateY(40px);
  }
}

/* ---------- Smooth Reveal for Results Section ---------- */
.results-stagger-enter {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.5s ease, transform 0.5s ease;
}

.results-stagger-enter.visible {
  opacity: 1;
  transform: translateY(0);
}

/* ---------- Detail Modal Overlay ---------- */
.card-detail-overlay {
  position: fixed;
  inset: 0;
  z-index: 9995;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  padding: 1rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.card-detail-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.card-detail-overlay .detail-card {
  max-width: 480px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  border-radius: 1rem;
  animation: cardDealIn 0.3s ease forwards;
}
