@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;600;800&display=swap');

:root {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --accent-color: #3b82f6;
  --accent-hover: #2563eb;
  
  /* Estados del Tablero */
  --ficha-no-salida: #334155;
  --ficha-no-salida-hover: #475569;
  --ficha-no-salida-texto: #cbd5e1;
  
  --ficha-salida: #10b981;
  --ficha-salida-hover: #059669;
  --ficha-salida-texto: #ffffff;
  
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --shadow-glow: 0 0 15px rgba(16, 185, 129, 0.4);
}

/* Soporte para modo claro si el sistema lo prefiere */
@media (prefers-color-scheme: light) {
  :root {
    --bg-primary: #f1f5f9;
    --bg-secondary: #ffffff;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    
    --ficha-no-salida: #e2e8f0;
    --ficha-no-salida-hover: #cbd5e1;
    --ficha-no-salida-texto: #334155;
    
    --shadow-glow: 0 0 15px rgba(16, 185, 129, 0.3);
  }
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Outfit', sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  padding: 2rem 1rem;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: background-color 0.3s ease, color 0.3s ease;
}

header {
  text-align: center;
  margin-bottom: 2.5rem;
  max-width: 800px;
}

h1 {
  font-size: 2.5rem;
  font-weight: 800;
  background: linear-gradient(135deg, #3b82f6, #10b981);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 0.5rem;
  letter-spacing: -0.025em;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 1.1rem;
  font-weight: 400;
}

main {
  width: 100%;
  max-width: 1000px;
  background: var(--bg-secondary);
  border-radius: 24px;
  padding: 2rem;
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.05);
  margin-bottom: 2rem;
}

/* Panel de control */
.control-panel {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1.5rem;
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.stats {
  display: flex;
  gap: 1.5rem;
}

.stat-box {
  background: rgba(255, 255, 255, 0.03);
  padding: 0.5rem 1rem;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.stat-value {
  font-weight: 600;
  color: var(--accent-color);
}

.stat-value.salidos {
  color: var(--ficha-salida);
}

.btn-container {
  display: flex;
  gap: 0.75rem;
}

button.btn {
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.6rem 1.2rem;
  border-radius: 12px;
  border: none;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-primary {
  background: var(--accent-color);
  color: white;
}

.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.btn-danger {
  background: #ef4444;
  color: white;
}

.btn-danger:hover {
  background: #dc2626;
  transform: translateY(-1px);
}

.btn-secondary {
  background: #475569;
  color: white;
}

.btn-secondary:hover {
  background: #334155;
  transform: translateY(-1px);
}

/* Cuadrícula de números */
.tablero-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
  gap: 0.75rem;
  justify-content: center;
}

.ficha-num {
  aspect-ratio: 1;
  font-family: 'Outfit', sans-serif;
  font-size: 1.4rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 16px;
  background-color: var(--ficha-no-salida);
  color: var(--ficha-no-salida-texto);
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
  user-select: none;
}

.ficha-num:hover {
  background-color: var(--ficha-no-salida-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.ficha-num:active {
  transform: scale(0.95);
}

/* Ficha marcada (salida) */
.ficha-num.marcado {
  background-color: var(--ficha-salida);
  color: var(--ficha-salida-texto);
  box-shadow: var(--shadow-glow);
  transform: scale(1.03);
  animation: pulse-green 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.ficha-num.marcado:hover {
  background-color: var(--ficha-salida-hover);
}

/* Indicador de check pequeño */
.ficha-num::after {
  content: "✓";
  position: absolute;
  bottom: 4px;
  right: 6px;
  font-size: 0.65rem;
  opacity: 0;
  transform: scale(0);
  transition: all 0.2s ease;
}

.ficha-num.marcado::after {
  opacity: 0.8;
  transform: scale(1);
}

/* Animaciones */
@keyframes pulse-green {
  0% {
    transform: scale(0.95);
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
  }
  70% {
    transform: scale(1.08);
    box-shadow: 0 0 0 10px rgba(16, 185, 129, 0);
  }
  100% {
    transform: scale(1.03);
    box-shadow: var(--shadow-glow);
  }
}

/* NoScript fallback alert */
.noscript-alert {
  background-color: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.2);
  color: #f87171;
  padding: 1rem;
  border-radius: 12px;
  margin-bottom: 1.5rem;
  text-align: center;
  font-weight: 500;
}

footer {
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.9rem;
  max-width: 600px;
  line-height: 1.6;
}

footer p {
  margin-bottom: 0.5rem;
}

footer a {
  color: var(--accent-color);
  text-decoration: none;
}

footer a:hover {
  text-decoration: underline;
}

/* Responsividad extra */
@media (max-width: 480px) {
  h1 {
    font-size: 1.8rem;
  }
  
  main {
    padding: 1.25rem;
    border-radius: 16px;
  }
  
  .control-panel {
    flex-direction: column;
    align-items: stretch;
  }
  
  .stats {
    flex-direction: column;
    gap: 0.5rem;
  }
  
  .btn-container {
    width: 100%;
  }
  
  .btn-container button {
    flex: 1;
    justify-content: center;
  }

  .tablero-grid {
    grid-template-columns: repeat(auto-fill, minmax(55px, 1fr));
    gap: 0.5rem;
  }
  
  .ficha-num {
    font-size: 1.15rem;
    border-radius: 10px;
  }
}

/* --- Modal de Confirmación Personalizado --- */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  background-color: var(--bg-secondary);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 24px;
  padding: 2.25rem;
  max-width: 420px;
  width: 90%;
  box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.3), 0 8px 10px -6px rgb(0 0 0 / 0.3);
  transform: scale(0.92);
  transition: transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
  text-align: left;
}

.modal.active .modal-content {
  transform: scale(1);
}

.modal-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
  color: var(--text-primary);
}

.modal-message {
  font-size: 1rem;
  color: var(--text-secondary);
  margin-bottom: 2rem;
  line-height: 1.5;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

.modal-actions .btn {
  font-size: 0.95rem;
  padding: 0.65rem 1.4rem;
}

#btn-modal-cancel {
  background-color: var(--ficha-no-salida);
  color: var(--ficha-no-salida-texto);
}

#btn-modal-cancel:hover {
  background-color: var(--ficha-no-salida-hover);
  transform: translateY(-1px);
}

/* --- Simulación de Pantalla Completa Virtual y Rotación Horizontal (Móviles/iOS) --- */
body.virtual-fullscreen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  padding: 0 !important;
  margin: 0 !important;
  background-color: var(--bg-primary);
}

/* Ocultar elementos innecesarios para enfocar el tablero en pantalla completa */
body.virtual-fullscreen header,
body.virtual-fullscreen footer {
  display: none !important;
}

/* Modo retrato (móviles verticales): rotar el tablero 90 grados para emular horizontal */
@media (orientation: portrait) {
  body.virtual-fullscreen main {
    position: fixed;
    top: 0;
    left: 100%;
    width: 100vh; /* El ancho del tablero rotado es la altura física del celular */
    height: 100vw; /* La altura del tablero rotado es el ancho físico del celular */
    transform: rotate(90deg);
    transform-origin: top left;
    z-index: 9999;
    overflow-y: auto;
    border-radius: 0;
    box-shadow: none;
    border: none;
    padding: 1.25rem;
    margin: 0;
  }
}

/* Modo paisaje (móviles horizontales, tablets, computadores): expandir normalmente sin rotar */
@media (orientation: landscape) {
  body.virtual-fullscreen main {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 9999;
    overflow-y: auto;
    border-radius: 0;
    box-shadow: none;
    border: none;
    padding: 1.5rem;
    margin: 0;
  }
}

/* --- Estilos unificados para Pantalla Completa (Nativa y Virtual) --- */

/* Contenedor principal expandido al 100% */
body.virtual-fullscreen main,
main:fullscreen,
main:-webkit-full-screen {
  max-width: 100% !important;
  width: 100% !important;
  height: 100% !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  border: none !important;
  padding: 0.75rem !important;
  margin: 0 !important;
  background-color: var(--bg-secondary) !important;
  display: flex !important;
  flex-direction: column !important;
  justify-content: flex-start !important;
  overflow-y: auto !important;
}

/* Panel de control ultra compacto */
body.virtual-fullscreen main .control-panel,
main:fullscreen .control-panel,
main:-webkit-full-screen .control-panel {
  margin-bottom: 0.75rem !important;
  padding-bottom: 0.5rem !important;
  gap: 0.5rem !important;
}

body.virtual-fullscreen main .control-panel .stats,
main:fullscreen .control-panel .stats,
main:-webkit-full-screen .control-panel .stats {
  gap: 0.5rem !important;
}

body.virtual-fullscreen main .stat-box,
main:fullscreen .stat-box,
main:-webkit-full-screen .stat-box {
  padding: 0.25rem 0.6rem !important;
  font-size: 0.8rem !important;
  border-radius: 8px !important;
  gap: 0.35rem !important;
}

body.virtual-fullscreen main button.btn,
main:fullscreen button.btn,
main:-webkit-full-screen button.btn {
  font-size: 0.75rem !important;
  padding: 0.4rem 0.8rem !important;
  border-radius: 8px !important;
  gap: 0.35rem !important;
}

/* Forzar cuadrícula de 15 columnas para que quepan los 90 números en una sola vista horizontal de 6 filas */
body.virtual-fullscreen main .tablero-grid,
main:fullscreen .tablero-grid,
main:-webkit-full-screen .tablero-grid {
  grid-template-columns: repeat(15, 1fr) !important;
  gap: 0.3rem !important;
  width: 100% !important;
}

/* Fichas numéricas más compactas */
body.virtual-fullscreen main .ficha-num,
main:fullscreen .ficha-num,
main:-webkit-full-screen .ficha-num {
  font-size: 0.95rem !important; /* Letra ligeramente más pequeña y nítida */
  border-radius: 8px !important;
  aspect-ratio: 1 !important;
}

/* Ocultar checkmark ✓ o reducirlo para no saturar visualmente */
body.virtual-fullscreen main .ficha-num::after,
main:fullscreen .ficha-num::after,
main:-webkit-full-screen .ficha-num::after {
  font-size: 0.45rem !important;
  bottom: 1px !important;
  right: 3px !important;
}



