/* ============================================
   Animations & Micro-interactions
   ============================================ */

/* === Page Transitions === */
@keyframes pageSlideIn {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes pageSlideOut {
  from {
    opacity: 1;
    transform: translateX(0);
  }
  to {
    opacity: 0;
    transform: translateX(-20px);
  }
}

@keyframes pageFadeIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.page-enter {
  animation: pageSlideIn 0.3s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.page-exit {
  animation: pageSlideOut 0.2s ease-in forwards;
}

.page-fade-in {
  animation: pageFadeIn 0.35s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

/* === Bounce In (quiz options) === */
@keyframes bounceIn {
  0% {
    opacity: 0;
    transform: scale(0.8) translateY(10px);
  }
  60% {
    opacity: 1;
    transform: scale(1.02) translateY(-2px);
  }
  100% {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.bounce-in {
  animation: bounceIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  opacity: 0;
}

.bounce-in:nth-child(1) { animation-delay: 0.05s; }
.bounce-in:nth-child(2) { animation-delay: 0.1s; }
.bounce-in:nth-child(3) { animation-delay: 0.15s; }
.bounce-in:nth-child(4) { animation-delay: 0.2s; }

/* === Ripple Effect === */
.ripple {
  position: relative;
  overflow: hidden;
}

.ripple::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
  transform: translate(-50%, -50%);
  opacity: 0;
}

.ripple.ripple-active::after {
  animation: rippleEffect 0.6s ease-out;
}

@keyframes rippleEffect {
  0% {
    width: 0;
    height: 0;
    opacity: 0.5;
  }
  100% {
    width: 300px;
    height: 300px;
    opacity: 0;
  }
}

/* === Skeleton Loading === */
@keyframes shimmer {
  0% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}

.skeleton {
  background: linear-gradient(90deg, #E0E4E8 25%, #F0F2F5 50%, #E0E4E8 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite ease-in-out;
  border-radius: 8px;
}

.skeleton-text {
  height: 14px;
  margin-bottom: 8px;
  border-radius: 6px;
}

.skeleton-text.short { width: 60%; }
.skeleton-text.medium { width: 80%; }
.skeleton-text.long { width: 95%; }

.skeleton-circle {
  border-radius: 50%;
}

.skeleton-card {
  height: 120px;
  border-radius: 12px;
}

/* === Flashcard 3D Flip (Spring Physics) === */
@keyframes springFlip {
  0% { transform: rotateY(0deg); }
  40% { transform: rotateY(190deg); }
  60% { transform: rotateY(175deg); }
  80% { transform: rotateY(182deg); }
  100% { transform: rotateY(180deg); }
}

@keyframes springUnflip {
  0% { transform: rotateY(180deg); }
  40% { transform: rotateY(-10deg); }
  60% { transform: rotateY(5deg); }
  80% { transform: rotateY(-2deg); }
  100% { transform: rotateY(0deg); }
}

.flashcard-spring-flip {
  animation: springFlip 0.7s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.flashcard-spring-unflip {
  animation: springUnflip 0.7s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

/* === Swipe Animations === */
@keyframes swipeLeft {
  to {
    transform: translateX(-120%) rotate(-8deg);
    opacity: 0;
  }
}

@keyframes swipeRight {
  to {
    transform: translateX(120%) rotate(8deg);
    opacity: 0;
  }
}

.swipe-left {
  animation: swipeLeft 0.4s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.swipe-right {
  animation: swipeRight 0.4s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

/* === Toast Slide === */
@keyframes toastSlideIn {
  from {
    transform: translateY(100px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes toastSlideOut {
  from {
    transform: translateY(0);
    opacity: 1;
  }
  to {
    transform: translateY(100px);
    opacity: 0;
  }
}

.toast-enter {
  animation: toastSlideIn 0.35s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.toast-exit {
  animation: toastSlideOut 0.25s ease-in forwards;
}

/* === Confetti === */
@keyframes confettiFall {
  0% {
    transform: translateY(-100vh) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translateY(100vh) rotate(720deg);
    opacity: 0;
  }
}

.confetti-piece {
  position: fixed;
  width: 10px;
  height: 10px;
  top: -10px;
  z-index: 9999;
  animation: confettiFall linear forwards;
}

/* === Flip Clock === */
@keyframes flipTop {
  0% { transform: rotateX(0deg); }
  100% { transform: rotateX(-90deg); }
}

@keyframes flipBottom {
  0% { transform: rotateX(90deg); }
  100% { transform: rotateX(0deg); }
}

.flip-clock-digit {
  position: relative;
  perspective: 200px;
}

.flip-clock-top {
  transform-origin: bottom;
}

.flip-clock-bottom {
  transform-origin: top;
}

.flip-clock-flip-top {
  animation: flipTop 0.3s ease-in forwards;
}

.flip-clock-flip-bottom {
  animation: flipBottom 0.3s ease-out 0.3s forwards;
}

/* === Bottom Sheet === */
@keyframes bottomSheetUp {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

@keyframes bottomSheetDown {
  from {
    transform: translateY(0);
  }
  to {
    transform: translateY(100%);
  }
}

.bottom-sheet-enter {
  animation: bottomSheetUp 0.35s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.bottom-sheet-exit {
  animation: bottomSheetDown 0.25s ease-in forwards;
}

/* === Progress Bar Animated === */
@keyframes progressGrow {
  from { width: 0%; }
}

.progress-animated {
  animation: progressGrow 0.8s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

/* === Pulse === */
@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.05); opacity: 0.8; }
}

.pulse {
  animation: pulse 2s ease-in-out infinite;
}

/* === Shake (error) === */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  10%, 50%, 90% { transform: translateX(-4px); }
  30%, 70% { transform: translateX(4px); }
}

.shake {
  animation: shake 0.5s ease-in-out;
}

/* === Scale Pop === */
@keyframes scalePop {
  0% { transform: scale(0.9); opacity: 0; }
  60% { transform: scale(1.02); }
  100% { transform: scale(1); opacity: 1; }
}

.scale-pop {
  animation: scalePop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* === Stagger children === */
.stagger-children > * {
  opacity: 0;
  animation: pageFadeIn 0.3s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.stagger-children > *:nth-child(1) { animation-delay: 0s; }
.stagger-children > *:nth-child(2) { animation-delay: 0.05s; }
.stagger-children > *:nth-child(3) { animation-delay: 0.1s; }
.stagger-children > *:nth-child(4) { animation-delay: 0.15s; }
.stagger-children > *:nth-child(5) { animation-delay: 0.2s; }
.stagger-children > *:nth-child(6) { animation-delay: 0.25s; }
.stagger-children > *:nth-child(7) { animation-delay: 0.3s; }
.stagger-children > *:nth-child(8) { animation-delay: 0.35s; }

/* === Number counter === */
@keyframes countUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.count-up {
  animation: countUp 0.5s ease-out forwards;
}
