/* ============================================================
   TeclaRápida — Animations & Transitions
   Premium micro-animations with glassmorphic polish
   ============================================================ */

/* ─── Page Transitions ─── */
.screen {
  display: none;
  opacity: 0;
}

.screen.active {
  display: block;
  animation: fadeIn var(--duration-normal, 300ms) var(--ease-out, cubic-bezier(0.16, 1, 0.3, 1)) forwards;
}

/* ─── Core Keyframes ─── */

/* Smooth page entrance — scale from 98% for a subtle "coming into focus" feel */
@keyframes fadeIn {
  0% {
    opacity: 0;
    transform: scale(0.98) translateY(6px);
    filter: blur(2px);
  }
  100% {
    opacity: 1;
    transform: scale(1) translateY(0);
    filter: blur(0);
  }
}

@keyframes fadeOut {
  0% {
    opacity: 1;
    transform: scale(1) translateY(0);
    filter: blur(0);
  }
  100% {
    opacity: 0;
    transform: scale(0.98) translateY(-6px);
    filter: blur(2px);
  }
}

/* ─── Slide Up — cards / rows entering viewport ─── */
@keyframes slideUp {
  0% {
    opacity: 0;
    transform: translateY(20px) scale(0.98);
  }
  60% {
    opacity: 1;
    transform: translateY(-2px) scale(1.005);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* ─── Scale In — modals, cards, pop-in elements ─── */
@keyframes scaleIn {
  0% {
    opacity: 0;
    transform: scale(0.85);
    filter: blur(4px);
  }
  70% {
    opacity: 1;
    transform: scale(1.03);
    filter: blur(0);
  }
  100% {
    opacity: 1;
    transform: scale(1);
    filter: blur(0);
  }
}

/* ─── Shimmer — card hover shine streak ─── */
@keyframes shimmer {
  0% {
    background-position: -200% center;
  }
  100% {
    background-position: 200% center;
  }
}

/* ─── Breathe — subtle "alive" pulse for active elements ─── */
@keyframes breathe {
  0%, 100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.02);
    opacity: 0.95;
  }
}

/* ─── Gradient Shift — animated background gradients ─── */
@keyframes gradientShift {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}

/* ─── Bounce In — playful element entrance ─── */
@keyframes bounceIn {
  0% {
    opacity: 0;
    transform: scale(0.3) translateY(10px);
  }
  40% {
    opacity: 1;
    transform: scale(1.12) translateY(-4px);
  }
  65% {
    transform: scale(0.95) translateY(1px);
  }
  85% {
    transform: scale(1.03) translateY(-1px);
  }
  100% {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* ─── Error Shake — refined, less aggressive ─── */
.shake {
  animation: shakeKeyframe 0.35s var(--ease-out, cubic-bezier(0.16, 1, 0.3, 1));
}

@keyframes shakeKeyframe {
  0%, 100% {
    transform: translateX(0);
  }
  15% {
    transform: translateX(-4px) rotate(-0.5deg);
  }
  30% {
    transform: translateX(3px) rotate(0.4deg);
  }
  45% {
    transform: translateX(-3px) rotate(-0.3deg);
  }
  60% {
    transform: translateX(2px) rotate(0.2deg);
  }
  75% {
    transform: translateX(-1px);
  }
  90% {
    transform: translateX(0.5px);
  }
}

/* ─── Pulse Primary — active key / element glow ring ─── */
@keyframes pulsePrimary {
  0% {
    box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.45);
  }
  50% {
    box-shadow: 0 0 0 8px rgba(99, 102, 241, 0.08);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(99, 102, 241, 0);
  }
}

.pulse-primary {
  animation: pulsePrimary 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

/* ─── Confetti Canvas ─── */
.confetti-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1000;
  display: none;
}

.confetti-canvas.active {
  display: block;
}

/* ─── Level Up Animation — dramatic multi-stage bounce ─── */
@keyframes levelUpAnimation {
  0% {
    opacity: 0;
    transform: scale(0.15) rotate(-8deg);
    filter: blur(8px) brightness(2);
  }
  35% {
    opacity: 1;
    transform: scale(1.18) rotate(2deg);
    filter: blur(0) brightness(1.3);
  }
  55% {
    transform: scale(0.92) rotate(-1deg);
    filter: brightness(1);
  }
  72% {
    transform: scale(1.06) rotate(0.5deg);
  }
  85% {
    transform: scale(0.98) rotate(0deg);
  }
  100% {
    opacity: 1;
    transform: scale(1) rotate(0deg);
    filter: blur(0) brightness(1);
  }
}

.level-up-animate {
  animation: levelUpAnimation 0.9s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

/* ─── Daily Streak Fire — organic flame movement ─── */
@keyframes fireFlame {
  0%, 100% {
    transform: scale(1) rotate(0deg) translateY(0);
    filter: brightness(1) saturate(1);
  }
  20% {
    transform: scale(1.08) rotate(-3deg) translateY(-1px);
    filter: brightness(1.15) saturate(1.2);
  }
  40% {
    transform: scale(1.18) rotate(2deg) translateY(-2px);
    filter: brightness(1.35) saturate(1.3);
  }
  60% {
    transform: scale(1.1) rotate(-1.5deg) translateY(-1px);
    filter: brightness(1.25) saturate(1.15);
  }
  80% {
    transform: scale(1.05) rotate(1deg) translateY(0);
    filter: brightness(1.1) saturate(1.05);
  }
}

.streak-fire-animated {
  display: inline-block;
  animation: fireFlame 1.2s ease-in-out infinite;
  transform-origin: bottom center;
}

/* ─── Achievement Toast — slide from right (desktop feel) ─── */
@keyframes toastSlideIn {
  0% {
    transform: translateX(120%) scale(0.85);
    opacity: 0;
    filter: blur(3px);
  }
  8% {
    transform: translateX(-3%) scale(1.02);
    opacity: 1;
    filter: blur(0);
  }
  12% {
    transform: translateX(1%) scale(1);
    opacity: 1;
  }
  88% {
    transform: translateX(0) scale(1);
    opacity: 1;
  }
  95% {
    opacity: 0.6;
    transform: translateX(10%) scale(0.97);
  }
  100% {
    transform: translateX(120%) scale(0.85);
    opacity: 0;
    filter: blur(2px);
  }
}

.achievement-toast {
  animation: toastSlideIn 4.5s cubic-bezier(0.23, 1, 0.32, 1) forwards;
}

/* ─── Transition Utility Classes ─── */
.transition-fast {
  transition: all var(--duration-fast, 150ms) var(--ease-out, cubic-bezier(0.16, 1, 0.3, 1));
}

.transition-normal {
  transition: all var(--duration-normal, 300ms) var(--ease-out, cubic-bezier(0.16, 1, 0.3, 1));
}

.transition-slow {
  transition: all var(--duration-slow, 500ms) var(--ease-in-out, cubic-bezier(0.65, 0, 0.35, 1));
}

/* ─── Appearance Utility — slideUp on enter ─── */
.animate-in {
  animation: slideUp var(--duration-slow, 500ms) var(--ease-out, cubic-bezier(0.16, 1, 0.3, 1)) both;
}

/* Staggered children: apply --stagger-index via JS or nth-child */
.animate-in[style*="--stagger-index"] {
  animation-delay: calc(var(--stagger-index, 0) * 60ms);
}

/* ─── Hover Lift — subtle rise with shadow ─── */
.hover-lift {
  transition:
    transform var(--duration-fast, 150ms) var(--ease-out, cubic-bezier(0.16, 1, 0.3, 1)),
    box-shadow var(--duration-normal, 300ms) var(--ease-out, cubic-bezier(0.16, 1, 0.3, 1));
  will-change: transform, box-shadow;
}

.hover-lift:hover {
  transform: translateY(-3px);
  box-shadow:
    0 8px 24px -4px rgba(0, 0, 0, 0.25),
    0 4px 8px -2px rgba(99, 102, 241, 0.08);
}

.hover-lift:active {
  transform: translateY(-1px);
  box-shadow:
    0 4px 12px -2px rgba(0, 0, 0, 0.2),
    0 2px 4px -1px rgba(99, 102, 241, 0.06);
}

/* ─── Hover Glow — subtle primary-color aura ─── */
.hover-glow {
  transition:
    box-shadow var(--duration-normal, 300ms) var(--ease-out, cubic-bezier(0.16, 1, 0.3, 1));
  will-change: box-shadow;
}

.hover-glow:hover {
  box-shadow:
    0 0 0 1px rgba(99, 102, 241, 0.15),
    0 0 20px -2px rgba(99, 102, 241, 0.2),
    0 0 40px -4px rgba(99, 102, 241, 0.08);
}

/* ─── Shimmer Hover Utility ─── */
.hover-shimmer {
  position: relative;
  overflow: hidden;
}

.hover-shimmer::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    105deg,
    transparent 35%,
    rgba(255, 255, 255, 0.04) 42%,
    rgba(255, 255, 255, 0.08) 50%,
    rgba(255, 255, 255, 0.04) 58%,
    transparent 65%
  );
  background-size: 200% 100%;
  background-position: -200% center;
  pointer-events: none;
  transition: none;
  border-radius: inherit;
}

.hover-shimmer:hover::after {
  animation: shimmer 0.8s var(--ease-out, cubic-bezier(0.16, 1, 0.3, 1)) forwards;
}

/* ─── Breathe Utility ─── */
.animate-breathe {
  animation: breathe 3s ease-in-out infinite;
}

/* ─── Gradient Shift Utility ─── */
.animate-gradient {
  background-size: 200% 200%;
  animation: gradientShift 6s ease-in-out infinite;
}

/* ─── Bounce In Utility ─── */
.animate-bounce-in {
  animation: bounceIn 0.6s var(--ease-spring, cubic-bezier(0.34, 1.56, 0.64, 1)) both;
}

/* ============================================================
   Accessibility — Reduced Motion
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *,
  ::before,
  ::after {
    animation-delay: -1ms !important;
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    background-attachment: scroll !important;
    scroll-behavior: auto !important;
    transition-duration: 0s !important;
    transition-delay: 0s !important;
  }

  /* Ensure hover utilities still feel responsive without motion */
  .hover-lift:hover {
    transform: none;
  }

  .hover-glow:hover {
    box-shadow:
      0 0 0 1px rgba(99, 102, 241, 0.2);
  }
}
