/* 
 * 塔罗牌动画系统
 * Tarot Card Animation System
 * 
 * 包含：洗牌、切牌、展开、翻转等完整动画效果
 */

/* ========================================
   1. 基础卡牌样式
   ======================================== */

.card-container {
  perspective: 1000px;
  position: relative;
  display: inline-block;
}

.tarot-card {
  position: relative;
  width: 150px;
  height: 250px;
  transform-style: preserve-3d;
  transition: transform 0.6s cubic-bezier(0.4, 0.0, 0.2, 1);
  cursor: pointer;
  border-radius: 8px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.tarot-card.flipped {
  transform: rotateY(180deg);
}

.card-face {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  border-radius: 8px;
  overflow: hidden;
}

.card-back {
  background: var(--gradient-warm, linear-gradient(135deg, #e8b4a0, #d4a5a5));
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-front {
  transform: rotateY(180deg);
  background: white;
}

/* ========================================
   2. 洗牌动画 (Shuffle Animation)
   ======================================== */

@keyframes shuffle {
  0% {
    transform: translate(0, 0) rotate(0deg);
    opacity: 1;
  }
  25% {
    transform: translate(var(--shuffle-x, 0), var(--shuffle-y, 0)) rotate(var(--shuffle-rotate, 0));
    opacity: 0.8;
  }
  50% {
    transform: translate(calc(var(--shuffle-x, 0) * -0.5), calc(var(--shuffle-y, 0) * 1.2)) rotate(calc(var(--shuffle-rotate, 0) * -1));
    opacity: 0.9;
  }
  75% {
    transform: translate(var(--shuffle-x, 0), var(--shuffle-y, 0)) rotate(var(--shuffle-rotate, 0));
    opacity: 0.8;
  }
  100% {
    transform: translate(0, 0) rotate(0deg);
    opacity: 1;
  }
}

.shuffling {
  animation: shuffle 0.8s ease-in-out;
}

/* 洗牌时的堆叠效果 */
.card-deck {
  position: relative;
  width: 150px;
  height: 250px;
  margin: 0 auto;
}

.card-deck .tarot-card {
  position: absolute;
  top: 0;
  left: 0;
}

.card-deck.shuffling .tarot-card {
  animation: shuffle 0.8s ease-in-out;
}

/* 为每张牌设置不同的动画参数 */
.card-deck .tarot-card:nth-child(1) { --shuffle-x: 30px; --shuffle-y: -20px; --shuffle-rotate: 15deg; animation-delay: 0s; }
.card-deck .tarot-card:nth-child(2) { --shuffle-x: -40px; --shuffle-y: 25px; --shuffle-rotate: -20deg; animation-delay: 0.05s; }
.card-deck .tarot-card:nth-child(3) { --shuffle-x: 50px; --shuffle-y: 30px; --shuffle-rotate: 25deg; animation-delay: 0.1s; }
.card-deck .tarot-card:nth-child(4) { --shuffle-x: -30px; --shuffle-y: -25px; --shuffle-rotate: -15deg; animation-delay: 0.15s; }
.card-deck .tarot-card:nth-child(5) { --shuffle-x: 45px; --shuffle-y: -30px; --shuffle-rotate: 20deg; animation-delay: 0.2s; }

/* ========================================
   3. 切牌动画 (Cut Animation)
   ======================================== */

@keyframes cut-top {
  0% {
    transform: translateY(0) translateX(0);
  }
  30% {
    transform: translateY(-100px) translateX(0);
  }
  60% {
    transform: translateY(-100px) translateX(200px);
  }
  100% {
    transform: translateY(0) translateX(200px);
  }
}

@keyframes cut-bottom {
  0% {
    transform: translateX(0);
  }
  40% {
    transform: translateX(0);
  }
  100% {
    transform: translateX(-200px);
  }
}

.cutting-top {
  animation: cut-top 1.5s cubic-bezier(0.4, 0.0, 0.2, 1);
  z-index: 10;
}

.cutting-bottom {
  animation: cut-bottom 1.5s cubic-bezier(0.4, 0.0, 0.2, 1);
  z-index: 5;
}

/* ========================================
   4. 牌阵展开动画 (Spread Layout Animation)
   ======================================== */

/* 单牌展开 */
@keyframes single-card-reveal {
  0% {
    opacity: 0;
    transform: scale(0.3) translateY(-50px);
  }
  60% {
    opacity: 1;
    transform: scale(1.1) translateY(0);
  }
  100% {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.reveal-single {
  animation: single-card-reveal 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* 三牌阵展开 */
@keyframes spread-three-left {
  0% {
    opacity: 0;
    transform: translateX(100px) translateY(-30px) rotate(0deg);
  }
  100% {
    opacity: 1;
    transform: translateX(0) translateY(0) rotate(-5deg);
  }
}

@keyframes spread-three-center {
  0% {
    opacity: 0;
    transform: translateY(-50px) scale(0.8);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes spread-three-right {
  0% {
    opacity: 0;
    transform: translateX(-100px) translateY(-30px) rotate(0deg);
  }
  100% {
    opacity: 1;
    transform: translateX(0) translateY(0) rotate(5deg);
  }
}

.spread-three-card:nth-child(1) {
  animation: spread-three-left 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) 0.2s backwards;
}

.spread-three-card:nth-child(2) {
  animation: spread-three-center 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) 0.4s backwards;
}

.spread-three-card:nth-child(3) {
  animation: spread-three-right 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) 0.6s backwards;
}

/* 凯尔特十字展开 */
@keyframes celtic-cross-appear {
  0% {
    opacity: 0;
    transform: scale(0) rotate(90deg);
  }
  70% {
    transform: scale(1.1) rotate(-5deg);
  }
  100% {
    opacity: 1;
    transform: scale(1) rotate(0deg);
  }
}

.celtic-cross-card {
  animation: celtic-cross-appear 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55) backwards;
}

.celtic-cross-card:nth-child(1) { animation-delay: 0.1s; }
.celtic-cross-card:nth-child(2) { animation-delay: 0.2s; }
.celtic-cross-card:nth-child(3) { animation-delay: 0.3s; }
.celtic-cross-card:nth-child(4) { animation-delay: 0.4s; }
.celtic-cross-card:nth-child(5) { animation-delay: 0.5s; }
.celtic-cross-card:nth-child(6) { animation-delay: 0.6s; }
.celtic-cross-card:nth-child(7) { animation-delay: 0.7s; }
.celtic-cross-card:nth-child(8) { animation-delay: 0.8s; }
.celtic-cross-card:nth-child(9) { animation-delay: 0.9s; }
.celtic-cross-card:nth-child(10) { animation-delay: 1.0s; }

/* ========================================
   5. 翻牌动画增强 (Enhanced Flip Animation)
   ======================================== */

.tarot-card.flip-with-glow {
  animation: flip-and-glow 0.8s ease-in-out;
}

@keyframes flip-and-glow {
  0% {
    transform: rotateY(0deg);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
  }
  50% {
    transform: rotateY(90deg) scale(1.1);
    box-shadow: 0 10px 28px rgba(232, 180, 160, 0.38);
  }
  100% {
    transform: rotateY(180deg);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
  }
}

/* 发光效果 */
@keyframes card-glow-pulse {
  0%, 100% {
    box-shadow: 0 0 20px rgba(232, 180, 160, 0.30);
  }
  50% {
    box-shadow: 0 0 44px rgba(232, 180, 160, 0.55);
  }
}

.tarot-card.glowing {
  animation: card-glow-pulse 2s ease-in-out infinite;
}

/* ========================================
   6. 悬停效果 (Hover Effects)
   ======================================== */

.tarot-card:hover {
  transform: translateY(-10px) scale(1.05);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.3);
  transition: all 0.3s ease;
}

.tarot-card.flipped:hover {
  transform: rotateY(180deg) translateY(-10px) scale(1.05);
}

/* 悬停时的光晕效果 */
.tarot-card::before {
  content: '';
  position: absolute;
  top: -2px;
  left: -2px;
  right: -2px;
  bottom: -2px;
  background: linear-gradient(45deg, #e8b4a0, #d4a5a5, #a8c8a8, #c8a2c8);
  border-radius: 10px;
  opacity: 0;
  z-index: -1;
  transition: opacity 0.3s ease;
  background-size: 400% 400%;
  animation: gradient-rotate 3s ease infinite;
}

.tarot-card:hover::before {
  opacity: 0.8;
}

@keyframes gradient-rotate {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

/* ========================================
   7. 抽牌动画 (Draw Card Animation)
   ======================================== */

@keyframes draw-from-deck {
  0% {
    transform: translateY(0) scale(1);
    z-index: 1;
  }
  30% {
    transform: translateY(-30px) scale(1.1);
    z-index: 100;
  }
  60% {
    transform: translateY(-60px) translateX(0) scale(1.05);
  }
  100% {
    transform: translateY(0) translateX(var(--draw-final-x, 0)) scale(1);
    z-index: 50;
  }
}

.drawing-card {
  animation: draw-from-deck 1s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ========================================
   8. 粒子效果 (Particle Effects)
   ======================================== */

@keyframes particle-float {
  0% {
    opacity: 0;
    transform: translateY(0) translateX(0) scale(0);
  }
  30% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translateY(-100px) translateX(var(--particle-x, 0)) scale(1);
  }
}

.particle {
  position: absolute;
  width: 4px;
  height: 4px;
  background: radial-gradient(circle, rgba(232, 180, 160, 1) 0%, rgba(232, 180, 160, 0) 70%);
  border-radius: 50%;
  pointer-events: none;
  animation: particle-float 1.5s ease-out forwards;
}

/* ========================================
   9. 加载动画 (Loading Animation)
   ======================================== */

.loading-spinner {
  width: 50px;
  height: 50px;
  border: 4px solid rgba(232, 180, 160, 0.28);
  border-top-color: #e8b4a0;
  border-radius: 50%;
  animation: spinner-rotate 1s linear infinite;
}

@keyframes spinner-rotate {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* 塔罗牌背面图案动画 */
.card-back-pattern {
  width: 100%;
  height: 100%;
  background-image: 
    repeating-linear-gradient(45deg, transparent, transparent 10px, rgba(255,255,255,0.1) 10px, rgba(255,255,255,0.1) 20px),
    repeating-linear-gradient(-45deg, transparent, transparent 10px, rgba(255,255,255,0.05) 10px, rgba(255,255,255,0.05) 20px);
  animation: pattern-shift 20s linear infinite;
}

@keyframes pattern-shift {
  0% { background-position: 0 0, 0 0; }
  100% { background-position: 100px 100px, -100px 100px; }
}

/* ========================================
   10. 响应式调整 (Responsive)
   ======================================== */

@media (max-width: 768px) {
  .tarot-card {
    width: 120px;
    height: 200px;
  }
  
  /* 移动端减少动画复杂度 */
  .card-deck.shuffling .tarot-card {
    animation-duration: 0.6s;
  }
  
  .shuffling {
    animation-duration: 0.6s;
  }
}

@media (max-width: 480px) {
  .tarot-card {
    width: 100px;
    height: 167px;
  }
}

/* ========================================
   11. 辅助类 (Utility Classes)
   ======================================== */

.no-animation {
  animation: none !important;
  transition: none !important;
}

.slow-motion {
  animation-duration: 3s !important;
}

.fast-motion {
  animation-duration: 0.3s !important;
}

.fade-in {
  animation: fade-in 0.5s ease-in;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.fade-out {
  animation: fade-out 0.5s ease-out;
}

@keyframes fade-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* ========================================
   12. 仪式感增强 (Ritual Enhancement)
   ======================================== */

/* 神秘光环效果 */
.mystical-aura {
  position: relative;
}

.mystical-aura::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle, rgba(232, 180, 160, 0.20) 0%, transparent 70%);
  transform: translate(-50%, -50%);
  animation: aura-pulse 3s ease-in-out infinite;
  pointer-events: none;
}

@keyframes aura-pulse {
  0%, 100% {
    opacity: 0.3;
    transform: translate(-50%, -50%) scale(1);
  }
  50% {
    opacity: 0.6;
    transform: translate(-50%, -50%) scale(1.2);
  }
}

/* 星光闪烁效果 */
.starlight {
  position: absolute;
  width: 2px;
  height: 2px;
  background: white;
  border-radius: 50%;
  box-shadow: 0 0 4px 2px rgba(255, 255, 255, 0.8);
  animation: twinkle 2s ease-in-out infinite;
}

@keyframes twinkle {
  0%, 100% { opacity: 0; }
  50% { opacity: 1; }
}

/* ========================================
   13. 过渡状态 (Transition States)
   ======================================== */

.card-entering {
  animation: card-enter 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes card-enter {
  from {
    opacity: 0;
    transform: translateY(30px) scale(0.9);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.card-leaving {
  animation: card-leave 0.4s ease-out forwards;
}

@keyframes card-leave {
  from {
    opacity: 1;
    transform: scale(1);
  }
  to {
    opacity: 0;
    transform: scale(0.9) translateY(-20px);
  }
}

/* ========================================
   14. 性能优化 (Performance)
   ======================================== */

/* 使用will-change提示浏览器优化 */
.tarot-card {
  will-change: transform, opacity;
}

/* 硬件加速 */
.tarot-card,
.card-face {
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
}

/* 减少重绘 */
.card-container * {
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

