/**
 * Microinteracciones para Quiniela El Trébol
 * v1.0.0 - Animaciones suaves para botones L/E/V
 *
 * Principios de diseño:
 * - Feedback visual instantáneo (<200ms)
 * - Respeta prefers-reduced-motion
 * - Hardware-accelerated (transform, opacity)
 * - WCAG 2.1 AA compliant
 */

:root {
  /* Timing functions optimizadas */
  --ease-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-smooth: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-swift: cubic-bezier(0.4, 0, 0.6, 1);

  /* Durations */
  --duration-instant: 100ms;
  --duration-fast: 150ms;
  --duration-normal: 200ms;
  --duration-slow: 300ms;

  /* Colors para efectos */
  --ripple-color: rgba(255, 255, 255, 0.4);
  --glow-local: rgba(76, 175, 80, 0.3);
  --glow-empate: rgba(255, 193, 7, 0.3);
  --glow-visitante: rgba(33, 150, 243, 0.3);
}

/* ============================================================
   BOTONES L/E/V - Estados base mejorados
   ============================================================ */

.btn-option {
  /* Propiedades existentes se mantienen, agregamos mejoras */
  position: relative;
  overflow: hidden;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;

  /* Transiciones suaves para todas las propiedades */
  transition:
    transform var(--duration-fast) var(--ease-smooth),
    background-color var(--duration-fast) var(--ease-smooth),
    color var(--duration-fast) var(--ease-smooth),
    border-color var(--duration-fast) var(--ease-smooth),
    box-shadow var(--duration-normal) var(--ease-smooth);

  /* Hardware acceleration */
  will-change: transform;
  transform: translateZ(0);
  backface-visibility: hidden;
}

/* ============================================================
   HOVER - Feedback sutil
   ============================================================ */

.btn-option:hover {
  transform: translateY(-2px) translateZ(0) scale(1.02);
  box-shadow:
    0 4px 8px rgba(0, 0, 0, 0.1),
    0 2px 4px rgba(0, 0, 0, 0.06);
}

/* ============================================================
   ACTIVE - Animación de click (scale + bounce)
   ============================================================ */

.btn-option:active {
  transform: scale(0.95) translateZ(0);
  transition-duration: var(--duration-instant);
  transition-timing-function: var(--ease-swift);
}

/* ============================================================
   CHECKED - Estado seleccionado con glow
   ============================================================ */

input[type="checkbox"]:checked + .btn-option {
  animation: btn-pop var(--duration-normal) var(--ease-bounce);
  transform: translateZ(0);
}

/* Animación de "pop" cuando se selecciona */
@keyframes btn-pop {
  0% {
    transform: scale(1) translateZ(0);
  }
  50% {
    transform: scale(1.15) translateZ(0);
  }
  100% {
    transform: scale(1) translateZ(0);
  }
}

/* Glow específico por tipo de botón */
input[type="checkbox"]:checked + .btn-option-local {
  box-shadow:
    0 0 0 3px var(--glow-local),
    0 4px 12px rgba(76, 175, 80, 0.2);
}

input[type="checkbox"]:checked + .btn-option-empate {
  box-shadow:
    0 0 0 3px var(--glow-empate),
    0 4px 12px rgba(255, 193, 7, 0.2);
}

input[type="checkbox"]:checked + .btn-option-visitante {
  box-shadow:
    0 0 0 3px var(--glow-visitante),
    0 4px 12px rgba(33, 150, 243, 0.2);
}

/* ============================================================
   RIPPLE EFFECT - Efecto de onda al hacer click
   ============================================================ */

.btn-option::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-radius: 50%;
  background: var(--ripple-color);
  transform: translate(-50%, -50%);
  opacity: 0;
  pointer-events: none;
}

.btn-option.ripple-active::before {
  animation: ripple var(--duration-slow) var(--ease-smooth);
}

@keyframes ripple {
  0% {
    width: 0;
    height: 0;
    opacity: 0.5;
  }
  100% {
    width: 200%;
    height: 200%;
    opacity: 0;
  }
}

/* ============================================================
   FOCUS - Accesibilidad (teclado)
   ============================================================ */

input[type="checkbox"]:focus-visible + .btn-option {
  outline: 3px solid rgba(33, 150, 243, 0.5);
  outline-offset: 2px;
  border-radius: 8px;
}

/* ============================================================
   DISABLED - Estado deshabilitado
   ============================================================ */

input[type="checkbox"]:disabled + .btn-option {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  pointer-events: none;
}

input[type="checkbox"]:disabled + .btn-option:hover {
  transform: none;
  box-shadow: none;
}

/* ============================================================
   LOADING STATE - Para feedback durante guardado
   ============================================================ */

.btn-option.is-loading {
  pointer-events: none;
  opacity: 0.7;
  position: relative;
}

.btn-option.is-loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 16px;
  height: 16px;
  margin: -8px 0 0 -8px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spinner 0.6s linear infinite;
}

@keyframes spinner {
  to { transform: rotate(360deg); }
}

/* ============================================================
   PULSE - Animación sutil de "latido" para llamar atención
   ============================================================ */

.btn-option.pulse {
  animation: pulse 2s var(--ease-smooth) infinite;
}

@keyframes pulse {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(33, 150, 243, 0.4);
  }
  50% {
    box-shadow: 0 0 0 8px rgba(33, 150, 243, 0);
  }
}

/* ============================================================
   SHAKE - Para errores o validación
   ============================================================ */

.btn-option.shake {
  animation: shake 0.4s var(--ease-smooth);
}

@keyframes shake {
  0%, 100% { transform: translateX(0) translateZ(0); }
  25% { transform: translateX(-8px) translateZ(0); }
  75% { transform: translateX(8px) translateZ(0); }
}

/* ============================================================
   CARD HOVER - Efecto en toda la card del partido
   ============================================================ */

.card {
  transition:
    transform var(--duration-fast) var(--ease-smooth),
    box-shadow var(--duration-fast) var(--ease-smooth);
}

.card:hover {
  transform: translateY(-2px) translateZ(0);
  box-shadow:
    0 10px 25px rgba(0, 0, 0, 0.1),
    0 5px 10px rgba(0, 0, 0, 0.05);
}

/* Highlight sutil cuando se selecciona cualquier opción */
.card:has(input[type="checkbox"]:checked) {
  background: linear-gradient(
    to bottom,
    rgba(33, 150, 243, 0.02),
    transparent
  );
  border-color: rgba(33, 150, 243, 0.2);
}

/* ============================================================
   RESPONSIVE - Ajustes para móvil
   ============================================================ */

@media (max-width: 768px) {
  /* En móvil, el efecto hover puede ser molesto, lo reducimos */
  .btn-option:hover {
    transform: translateZ(0);
    box-shadow: none;
  }

  /* Mantenemos solo el feedback de tap (active) */
  .btn-option:active {
    transform: scale(0.92) translateZ(0);
  }
}

/* ============================================================
   ACCESSIBILITY - Respeta preferencias del usuario
   ============================================================ */

/* Usuarios que prefieren movimiento reducido */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .btn-option {
    transition: none !important;
    animation: none !important;
  }

  .btn-option:hover {
    transform: none;
  }

  .btn-option:active {
    transform: none;
  }

  input[type="checkbox"]:checked + .btn-option {
    animation: none;
  }
}

/* ============================================================
   PRINT - Ocultar efectos en impresión
   ============================================================ */

@media print {
  .btn-option::before,
  .btn-option::after {
    display: none !important;
  }

  .btn-option {
    transition: none !important;
    animation: none !important;
    transform: none !important;
    box-shadow: none !important;
  }
}

/* ============================================================
   HIGH CONTRAST - Modo alto contraste
   ============================================================ */

@media (prefers-contrast: high) {
  .btn-option {
    border-width: 2px;
  }

  input[type="checkbox"]:checked + .btn-option {
    border-width: 3px;
  }

  input[type="checkbox"]:focus-visible + .btn-option {
    outline-width: 4px;
  }
}
