/* ==========================================================================
   FinanceXLab — Animaciones
   Keyframes y clases de micro-interacción. El confeti de "subir de nivel"
   se dibuja con Canvas API (JS), no aquí. Respeta prefers-reduced-motion
   (regla global ya aplicada en base.css).
   ========================================================================== */

/* ---- Entrada de elementos ------------------------------------------------ */

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(16px) scale(0.99); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.animate-in {
  animation: fadeInUp 0.45s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
/* Delay escalonado para grupos de tarjetas/listas */
.animate-in:nth-child(1) { animation-delay: 0ms; }
.animate-in:nth-child(2) { animation-delay: 100ms; }
.animate-in:nth-child(3) { animation-delay: 200ms; }
.animate-in:nth-child(4) { animation-delay: 300ms; }
.animate-in:nth-child(5) { animation-delay: 400ms; }
.animate-in:nth-child(6) { animation-delay: 500ms; }

/* ---- Respuesta correcta / incorrecta ------------------------------------ */

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}

.correct {
  border-color: var(--accent-green) !important;
  transform: scale(1.02);
  transition: transform 0.3s ease, border-color 0.3s ease;
}

.incorrect {
  border-color: var(--accent-red) !important;
  animation: shake 0.4s ease;
}

@keyframes xpFloat {
  0%   { opacity: 0; transform: translateY(0) scale(0.8); }
  20%  { opacity: 1; transform: translateY(-8px) scale(1); }
  100% { opacity: 0; transform: translateY(-40px) scale(1); }
}
.xp-float {
  position: absolute;
  color: var(--accent-green);
  font-family: var(--font-mono);
  font-weight: 600;
  pointer-events: none;
  animation: xpFloat 0.9s ease forwards;
}

/* ---- Racha activa ------------------------------------------------------- */

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.15); opacity: 0.85; }
}
.racha-activa {
  display: inline-block;
  animation: pulse 1.6s ease-in-out infinite;
}

/* ---- Subir de nivel: overlay + badge ------------------------------------ */

@keyframes overlayFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes badgePop {
  0%   { transform: scale(0.4) rotate(-8deg); opacity: 0; }
  60%  { transform: scale(1.1) rotate(4deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}
.nivel-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1200;
  animation: overlayFadeIn 0.3s ease;
}
.nivel-badge {
  animation: badgePop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ---- Toast ---------------------------------------------------------- */

@keyframes toastSlideIn {
  from { opacity: 0; transform: translate(-50%, 20px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}
@keyframes toastSlideOut {
  from { opacity: 1; transform: translate(-50%, 0); }
  to   { opacity: 0; transform: translate(-50%, 20px); }
}
.toast-container {
  animation: toastSlideIn 0.3s ease;
}
.toast-container.toast-saliendo {
  animation: toastSlideOut 0.3s ease forwards;
}

/* ---- Spinner de carga ------------------------------------------------ */

@keyframes spin {
  to { transform: rotate(360deg); }
}
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
