/* =========================================================================
   Marca Ball - Estilos globales y layout
   ========================================================================= */

/* Reset y estilos base */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background-color: #f5f5f5;
  color: #333;
  line-height: 1.6;
  overflow: hidden;
}

/* =========================================================================
   Utilidades generales
   ========================================================================= */

.screen {
  display: none;
  width: 100%;
  height: 100%;
}

.screen.active {
  display: block;
}

/* Clases de accesibilidad */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* =========================================================================
   PANTALLA_CONFIGURACIÓN (#config-screen)
   ========================================================================= */

#config-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  text-align: center;
}

.config-header h1 {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
}

.config-subtitle {
  font-size: 1.1rem;
  opacity: 0.9;
  margin-bottom: 2rem;
}

.config-main {
  width: 100%;
  max-width: 400px;
  background: white;
  padding: 2rem;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  color: #333;
}

#config-form {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

fieldset {
  border: none;
  padding: 0;
}

legend {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 1rem;
  padding: 0;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.form-group label {
  font-weight: 500;
  font-size: 0.95rem;
}

.form-group input,
.form-group select {
  padding: 0.875rem 1rem;
  font-size: 1rem;
  min-height: 44px;
  border: 2px solid #ddd;
  border-radius: 6px;
  font-family: inherit;
  transition: all 0.2s ease;
  -webkit-appearance: none;
  appearance: none;
  background-color: #fff;
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.field-error {
  display: none;
  color: #e74c3c;
  font-size: 0.85rem;
  margin-top: 0.25rem;
}

.field-error:not(:empty) {
  display: block;
}

.field-hint {
  font-size: 0.8rem;
  color: #7f8c8d;
}

/* Botones generales */
.btn {
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  font-family: inherit;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  touch-action: manipulation;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background-color: #667eea;
  color: white;
}

.btn-primary:hover {
  background-color: #5568d3;
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.btn-primary:disabled {
  background-color: #ccc;
  cursor: not-allowed;
}

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

.btn-secondary:hover {
  background-color: #7f8c8d;
}

.btn-large {
  width: 100%;
  padding: 1rem;
  font-size: 1.1rem;
  font-weight: 600;
}

/* Diálogo de recuperación */
#recover-dialog {
  background: white;
  padding: 2rem;
  border: none;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  max-width: 90%;
  max-width: min(90vw, 400px);
  animation: slideDown 0.3s ease-out;
}

#recover-dialog::backdrop {
  background-color: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
}

#recover-dialog h2 {
  margin-bottom: 1rem;
  color: #333;
  font-size: 1.5rem;
}

#recover-dialog p {
  margin-bottom: 1.5rem;
  color: #666;
  line-height: 1.5;
  font-size: 1rem;
}

.dialog-actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  justify-content: flex-end;
}

.dialog-actions .btn {
  flex: 1;
  min-height: 44px;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* =========================================================================
   PANTALLA_PARTIDO (#game-screen) — CSS Grid Layout
   ========================================================================= */

#game-screen {
  display: grid;
  grid-template-columns: 88px 1fr 88px;
  grid-template-rows: 1fr;
  width: 100vw;
  height: 100dvh;
  overflow: hidden;
  background-color: #fff;
}

/* Columnas laterales: contenedores flex verticales */
.col-local,
.col-center,
.col-visitor {
  display: flex;
  flex-direction: column;
}

.col-local {
  grid-column: 1;
  position: relative;
  background-color: #f9f9f9;
  border-right: 1px solid #eee;
}

.col-center {
  grid-column: 2;
  align-items: center;
  justify-content: space-evenly;
  padding: 1rem;
  background-color: #fff;
}

.col-visitor {
  grid-column: 3;
  position: relative;
  background-color: #f9f9f9;
  border-left: 1px solid #eee;
}

/* =========================================================================
   Botones de puntuación (.score-btn)
   ========================================================================= */

.score-btn {
  flex: 1;
  min-height: 44px;
  padding: 0.5rem;
  font-size: clamp(1.2rem, 4vw, 2rem);
  font-weight: 700;
  color: #667eea;
  background-color: #f0f4ff;
  border: 2px solid #e8ecff;
  border-radius: 4px;
  cursor: pointer;
  touch-action: manipulation;
  transition: all 0.1s ease;
  font-family: inherit;
}

.score-btn:active {
  background-color: #e8ecff;
  border-color: #d0d9ff;
  transform: scale(0.95);
}

.score-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Botones de puntuación en la columna del equipo visitante */
.col-visitor .score-btn {
  color: #e74c3c;
}

.col-visitor .score-btn {
  background-color: #fff5f3;
  border-color: #ffe8e5;
}

.col-visitor .score-btn:active {
  background-color: #ffe8e5;
  border-color: #ffd1ca;
}

/* =========================================================================
   Botones de corrección (.correction-btn)
   ========================================================================= */

.correction-btn {
  height: 44px;
  min-height: 44px;
  padding: 0.5rem;
  font-size: 1rem;
  font-weight: 600;
  color: #e74c3c;
  background-color: #fff5f3;
  border: 2px solid #ffe8e5;
  border-radius: 4px;
  cursor: pointer;
  touch-action: manipulation;
  transition: all 0.1s ease;
  font-family: inherit;
}

.correction-btn:active {
  background-color: #ffe8e5;
  border-color: #ffd1ca;
  transform: scale(0.95);
}

/* Panel de corrección — overlay absoluto sobre columna lateral */
.correction-panel {
  position: absolute;
  bottom: 52px;
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.5rem;
  background-color: #fffbf8;
  border-top: 2px solid #e74c3c;
  border-bottom: 2px solid #e74c3c;
  z-index: 10;
  animation: slideUp 0.2s ease-out;
}

.col-visitor .correction-panel {
  background-color: #fffbf8;
  border-top-color: #e74c3c;
  border-bottom-color: #e74c3c;
}

.correction-panel[hidden] {
  display: none;
}

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

/* Botón de toggle de corrección */
.correction-toggle-btn {
  height: 44px;
  min-height: 44px;
  padding: 0.5rem;
  font-size: 1.2rem;
  background-color: #f0f4ff;
  color: #667eea;
  border: 2px solid #e8ecff;
  border-radius: 4px;
  cursor: pointer;
  touch-action: manipulation;
  transition: all 0.2s ease;
  font-family: inherit;
  margin-top: auto;
}

.col-visitor .correction-toggle-btn {
  background-color: #fff5f3;
  color: #e74c3c;
  border-color: #ffe8e5;
}

.correction-toggle-btn:active {
  transform: scale(0.95);
}

.correction-toggle-btn[aria-expanded="true"] {
  background-color: #e8ecff;
  color: #667eea;
  border-color: #d0d9ff;
}

.col-visitor .correction-toggle-btn[aria-expanded="true"] {
  background-color: #ffe8e5;
  color: #e74c3c;
  border-color: #ffd1ca;
}

/* =========================================================================
   Cabecera del partido (nombres de equipos y cuarto)
   ========================================================================= */

.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  width: 100%;
  margin-bottom: 1rem;
  text-align: center;
}

.team-name {
  font-size: clamp(0.8rem, 3vw, 1.2rem);
  font-weight: 600;
  color: #333;
  flex: 1;
  word-wrap: break-word;
  word-break: break-word;
  hyphens: auto;
  overflow-wrap: break-word;
}

.quarter-info {
  font-size: clamp(0.8rem, 2vw, 1rem);
  color: #666;
  white-space: nowrap;
  padding: 0 0.5rem;
}

/* =========================================================================
   Marcador
   ========================================================================= */

.scoreboard {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 2rem;
  width: 100%;
  margin-bottom: 2rem;
}

.score {
  font-size: clamp(2rem, 10vw, 4rem);
  font-weight: 700;
  color: #333;
  text-align: center;
  min-width: 80px;
}

.timer-container {
  display: flex;
  justify-content: center;
  align-items: center;
}

.timer-display {
  font-size: clamp(1.5rem, 8vw, 3rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #667eea;
  text-align: center;
  min-width: 140px;
  padding: 0.5rem 1rem;
  background-color: #f0f4ff;
  border: 2px solid #667eea;
  border-radius: 8px;
  font-family: 'Monaco', 'Courier New', monospace;
}

/* =========================================================================
   Controles del temporizador
   ========================================================================= */

.timer-controls {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: 100%;
}

.btn-timer {
  padding: 0.75rem 1rem;
  font-size: clamp(0.9rem, 2.5vw, 1rem);
  font-weight: 500;
  background-color: #f0f4ff;
  color: #667eea;
  border: 2px solid #667eea;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  touch-action: manipulation;
}

.btn-timer:hover:not(:disabled) {
  background-color: #667eea;
  color: white;
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.btn-timer:active:not(:disabled) {
  transform: scale(0.95);
}

.btn-timer:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-end-quarter {
  background-color: #fff5f3;
  color: #e74c3c;
  border-color: #e74c3c;
}

.btn-end-quarter:hover:not(:disabled) {
  background-color: #e74c3c;
  color: white;
  box-shadow: 0 4px 12px rgba(231, 76, 60, 0.3);
}

/* =========================================================================
   Área de notificaciones
   ========================================================================= */

.notification {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  background-color: #2ecc71;
  color: white;
  padding: 1rem 1.5rem;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  font-size: 1rem;
  font-weight: 500;
  text-align: center;
  z-index: 1000;
  max-width: 90%;
  animation: slideInUp 0.3s ease-out;
}

.notification[hidden] {
  display: none;
}

.notification.hide {
  animation: slideOutDown 0.3s ease-out forwards;
}

@keyframes slideInUp {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(100px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

@keyframes slideOutDown {
  from {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
  to {
    opacity: 0;
    transform: translateX(-50%) translateY(100px);
  }
}

/* =========================================================================
   PANTALLA_ESTADÍSTICAS (#stats-screen)
   ========================================================================= */

#stats-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  overflow-y: auto;
}

.stats-main {
  width: 100%;
  max-width: 600px;
  background: white;
  padding: 2rem;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  color: #333;
}

.stats-header {
  text-align: center;
  margin-bottom: 2rem;
}

.stats-header h1 {
  font-size: 2rem;
  margin-bottom: 1rem;
}

.winner-display {
  font-size: 1.5rem;
  font-weight: 700;
  color: #2ecc71;
  padding: 0.75rem 1.5rem;
  background-color: #e8f8f5;
  border-left: 4px solid #2ecc71;
  border-radius: 4px;
  margin-top: 0.5rem;
}

.stats-scores {
  display: flex;
  justify-content: space-around;
  align-items: center;
  gap: 2rem;
  margin-bottom: 2rem;
  padding: 2rem 1.5rem;
  background-color: #f9f9f9;
  border-radius: 8px;
  border: 2px solid #f0f4ff;
}

.stats-team {
  text-align: center;
  flex: 1;
}

.stats-team-name {
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: #333;
}

.stats-total-score {
  display: block;
  font-size: 3rem;
  font-weight: 700;
  color: #667eea;
  line-height: 1;
}

.stats-separator {
  color: #ddd;
  font-size: 2rem;
  font-weight: 300;
}

/* Tabla de puntajes por cuarto */
.quarter-scores-section {
  margin-bottom: 2rem;
}

.quarter-scores-section h3 {
  text-align: center;
  margin-bottom: 1rem;
  font-size: 1.1rem;
  font-weight: 600;
  color: #333;
}

.quarter-scores-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
  overflow-x: auto;
}

.quarter-scores-table thead {
  background-color: #f0f4ff;
  border-bottom: 2px solid #667eea;
}

.quarter-scores-table th {
  padding: 1rem 0.75rem;
  text-align: center;
  font-weight: 600;
  color: #667eea;
  font-size: 0.9rem;
  letter-spacing: 0.5px;
}

.quarter-scores-table td {
  padding: 0.75rem 0.75rem;
  text-align: center;
  border-bottom: 1px solid #eee;
  font-weight: 500;
  color: #333;
}

.quarter-scores-table td:first-child {
  text-align: left;
  font-weight: 600;
  color: #667eea;
}

.quarter-scores-table tbody tr:nth-child(odd) {
  background-color: #fafafa;
}

.quarter-scores-table tbody tr:nth-child(even) {
  background-color: #f0f4ff;
}

.quarter-scores-table tbody tr:hover {
  background-color: #e8ecff;
}

.stats-actions {
  display: flex;
  justify-content: center;
  gap: 1rem;
}

.stats-actions .btn {
  flex: 1;
  max-width: 200px;
}

/* =========================================================================
   Media queries para ajustes responsivos
   ========================================================================= */

@media (max-width: 768px) {
  .config-main {
    max-width: 90%;
  }

  .stats-main {
    max-width: 95%;
  }

  #game-screen {
    grid-template-columns: 70px 1fr 70px;
  }

  .score-btn {
    font-size: clamp(1rem, 3vw, 1.5rem);
  }

  .timer-display {
    font-size: clamp(1.2rem, 6vw, 2.5rem);
  }
}

@media (max-width: 480px) {
  #config-screen {
    padding: 1rem;
  }

  .config-main {
    padding: 1.5rem;
  }

  .config-header h1 {
    font-size: 2rem;
  }

  #game-screen {
    grid-template-columns: 60px 1fr 60px;
  }

  .scoreboard {
    gap: 1rem;
  }

  .stats-main {
    padding: 1.5rem;
  }

  .quarter-scores-table {
    font-size: 0.85rem;
  }

  .quarter-scores-table th,
  .quarter-scores-table td {
    padding: 0.5rem 0.25rem;
  }
}
