/* ==========================================================================
   VARIABLES Y ESTILOS GLOBALES
   ========================================================================== */
:root {
  --primary: #6c5ce7;
  --primary-hover: #5b4bc4;
  --secondary: #00cec9;
  --secondary-hover: #00b3b0;
  --accent: #fd79a8;
  --accent-hover: #e84393;
  --warning: #fdcb6e;
  --success: #00b894;
  --danger: #ff7675;
  --dark: #2d3436;
  --light-bg: #f7f9fc;
  --card-bg: #ffffff;
  --text: #2d3436;
  --text-muted: #636e72;
  --border-radius: 20px;
  --border-radius-sm: 12px;
  --box-shadow: 0 10px 25px rgba(108, 92, 231, 0.12);
  --box-shadow-hover: 0 15px 30px rgba(108, 92, 231, 0.2);
  --font-heading: 'Fredoka', cursive, sans-serif;
  --font-body: 'Nunito', sans-serif;
  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  font-family: var(--font-body);
  background-color: var(--light-bg);
  background-image: radial-gradient(#e0e6ed 1.5px, transparent 1.5px);
  background-size: 24px 24px;
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* ==========================================================================
   HEADER Y NAVEGACIÓN
   ========================================================================== */
.main-header {
  background: var(--card-bg);
  padding: 1rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 4px 15px rgba(0,0,0,0.05);
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo-container {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
}

.logo-icon {
  font-size: 2rem;
  animation: bounce 2s infinite;
}

.logo-title {
  font-family: var(--font-heading);
  font-size: 1.6rem;
  color: var(--dark);
}

.logo-title .highlight {
  color: var(--primary);
}

.header-nav {
  display: flex;
  gap: 0.5rem;
}

/* ==========================================================================
   BOTONES Y ELEMENTOS DE INTERFAZ
   ========================================================================== */
.btn {
  font-family: var(--font-heading);
  font-size: 1rem;
  padding: 0.75rem 1.4rem;
  border-radius: var(--border-radius-sm);
  border: none;
  cursor: pointer;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  text-decoration: none;
}

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

.btn-primary {
  background-color: var(--primary);
  color: white;
  box-shadow: 0 4px 12px rgba(108, 92, 231, 0.3);
}
.btn-primary:hover {
  background-color: var(--primary-hover);
  transform: translateY(-2px);
}

.btn-secondary {
  background-color: var(--secondary);
  color: white;
  box-shadow: 0 4px 12px rgba(0, 206, 201, 0.3);
}
.btn-secondary:hover {
  background-color: var(--secondary-hover);
  transform: translateY(-2px);
}

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

.btn-outline {
  background: transparent;
  border: 2px solid #dfe6e9;
  color: var(--dark);
}
.btn-outline:hover {
  background: #f1f2f6;
}

.btn-danger-outline {
  background: transparent;
  border: 2px solid var(--danger);
  color: var(--danger);
}
.btn-danger-outline:hover {
  background: #ffeaa7;
}

.btn-icon-text {
  background: #f1f2f6;
  border: none;
  padding: 0.5rem 0.8rem;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 700;
  color: var(--dark);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.btn-sm { padding: 0.4rem 0.8rem; font-size: 0.85rem; }
.btn-lg { padding: 1rem 2rem; font-size: 1.2rem; }
.btn-xl { padding: 1.2rem 2.5rem; font-size: 1.4rem; border-radius: 25px; }

.full-width { width: 100%; }

/* ==========================================================================
   ESTRUCTURA DE PANTALLAS
   ========================================================================== */
.app-container {
  flex: 1;
  max-width: 1000px;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem;
}

.screen {
  display: none;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.screen.active {
  display: block;
  opacity: 1;
  animation: fadeIn 0.4s ease-out forwards;
}

.card {
  background: var(--card-bg);
  border-radius: var(--border-radius);
  padding: 1.8rem;
  box-shadow: var(--box-shadow);
  margin-bottom: 1.5rem;
}

/* ==========================================================================
   PANTALLA 1: INICIO (HERO)
   ========================================================================== */
.hero-card {
  text-align: center;
  padding: 3.5rem 2rem;
  background: linear-gradient(135deg, #ffffff 0%, #f3f0ff 100%);
  border-radius: var(--border-radius);
  box-shadow: var(--box-shadow);
}

.hero-badge {
  display: inline-block;
  background: #ffeaa7;
  color: #d63031;
  font-weight: 800;
  padding: 0.4rem 1rem;
  border-radius: 20px;
  font-size: 0.9rem;
  margin-bottom: 1rem;
}

.hero-title {
  font-family: var(--font-heading);
  font-size: 2.5rem;
  color: var(--dark);
  margin-bottom: 1rem;
  line-height: 1.2;
}

.hero-subtitle {
  font-size: 1.15rem;
  color: var(--text-muted);
  max-width: 650px;
  margin: 0 auto 2.5rem auto;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 2.5rem;
}

.safety-warning-banner {
  background: #fff9db;
  border: 1px solid #ffe066;
  padding: 0.8rem 1.2rem;
  border-radius: var(--border-radius-sm);
  display: flex;
  align-items: center;
  gap: 0.8rem;
  font-size: 0.85rem;
  text-align: left;
  max-width: 700px;
  margin: 0 auto;
}

/* ==========================================================================
   PANTALLA 2: SETUP Y JUGADORES
   ========================================================================== */
.setup-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

@media (max-width: 768px) {
  .setup-grid { grid-template-columns: 1fr; }
}

.player-form {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
  margin-bottom: 1.5rem;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 1.2rem;
  text-align: left;
}

.input-group.short { width: 110px; }

.input-group label {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--dark);
}

.input-group input, .input-group select {
  padding: 0.75rem 1rem;
  border: 2px solid #dfe6e9;
  border-radius: var(--border-radius-sm);
  font-family: var(--font-body);
  font-size: 1rem;
  outline: none;
  transition: var(--transition);
}

.input-group input:focus, .input-group select:focus {
  border-color: var(--primary);
}

.players-container {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  max-height: 320px;
  overflow-y: auto;
  padding-right: 0.3rem;
}

.player-item-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #f8f9fa;
  padding: 0.6rem 1rem;
  border-radius: var(--border-radius-sm);
  border-left: 5px solid var(--primary);
}

.player-info strong { font-size: 1.05rem; }
.player-info span { font-size: 0.85rem; color: var(--text-muted); margin-left: 0.5rem;}

.setup-navigation {
  display: flex;
  justify-content: space-between;
  margin-top: 2rem;
}

/* ==========================================================================
   PANTALLA 3: CARGANDO (BUFFER DE IA)
   ========================================================================== */
.loading-card {
  text-align: center;
  padding: 4rem 2rem;
  background: white;
  border-radius: var(--border-radius);
  box-shadow: var(--box-shadow);
}

.spinner {
  font-size: 4rem;
  animation: pulse 1.2s infinite alternate;
  margin-bottom: 1.5rem;
}

.loading-subtitle {
  color: var(--primary);
  font-weight: 700;
  margin-top: 0.5rem;
}

.loading-bar-container {
  width: 80%;
  height: 10px;
  background: #eee;
  border-radius: 10px;
  margin: 2rem auto 0 auto;
  overflow: hidden;
}

.loading-bar-progress {
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--secondary));
  animation: loadingBar 1.8s infinite ease-in-out;
}

/* ==========================================================================
   PANTALLA 4: ACTIVIDAD / RETO
   ========================================================================== */
.game-status-bar {
  display: flex;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.badge {
  padding: 0.4rem 0.9rem;
  border-radius: 20px;
  font-weight: 800;
  font-size: 0.85rem;
}
.badge-round { background: var(--dark); color: white; }
.badge-ai { background: #e0f7fa; color: #00838f; }

.player-turn-banner {
  text-align: center;
  margin-bottom: 1.5rem;
}

.turn-label { font-size: 0.9rem; font-weight: 800; color: var(--text-muted); letter-spacing: 1px; }
.turn-player-name { font-family: var(--font-heading); font-size: 2.8rem; color: var(--primary); line-height: 1.1; }
.player-age-tag { font-size: 1.1rem; color: var(--text-muted); font-weight: 600; }

.activity-card {
  border-top: 6px solid var(--accent);
}

.activity-header {
  margin-bottom: 1rem;
}

.tts-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: #f1f2f6;
  padding: 0.6rem 1rem;
  border-radius: var(--border-radius-sm);
  margin-bottom: 1.2rem;
  width: fit-content;
}

.tts-speed-wrapper {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
}

.tts-speed-select {
  padding: 0.2rem 0.5rem;
  border-radius: 8px;
  border: 1px solid #dfe6e9;
  font-family: var(--font-body);
  font-size: 0.85rem;
  outline: none;
  cursor: pointer;
}

.category-pill {
  display: inline-block;
  background: #ffeaa7;
  color: #d63031;
  font-size: 0.8rem;
  font-weight: 800;
  padding: 0.2rem 0.6rem;
  border-radius: 12px;
  text-transform: uppercase;
  margin-bottom: 0.4rem;
}

.activity-card h3 {
  font-family: var(--font-heading);
  font-size: 1.8rem;
}

.activity-description {
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 1.2rem;
  color: #2d3436;
}

.instructions-box {
  background: #f8f9fa;
  padding: 1.2rem;
  border-radius: var(--border-radius-sm);
  margin-bottom: 1.2rem;
}

.instructions-box ol {
  margin-left: 1.2rem;
  margin-top: 0.5rem;
}

.instructions-box li {
  margin-bottom: 0.4rem;
}

.activity-meta {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
  color: var(--text-muted);
}

.timer-container {
  background: #f1f2f6;
  padding: 1rem;
  border-radius: var(--border-radius-sm);
  text-align: center;
  margin-bottom: 1.5rem;
}

.timer-display {
  font-family: var(--font-heading);
  font-size: 2.5rem;
  color: var(--dark);
  margin-bottom: 0.5rem;
}

.activity-actions {
  display: flex;
  gap: 1rem;
  justify-content: space-between;
}

/* ==========================================================================
   PANTALLA 5: PUNTUACIÓN
   ========================================================================== */
.scoring-card {
  max-width: 600px;
  margin: 0 auto;
}

.scoring-rows {
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
  margin-bottom: 1.8rem;
}

.score-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.score-label {
  display: flex;
  flex-direction: column;
}

.score-label span { font-weight: 700; font-size: 1.05rem; }
.score-label small { color: var(--text-muted); font-size: 0.8rem; }

.star-rating {
  display: flex;
  gap: 0.3rem;
}

.star {
  font-size: 1.8rem;
  color: #dfe6e9;
  cursor: pointer;
  transition: transform 0.1s ease, color 0.15s ease;
  user-select: none;
}

.star.active { color: #f1c40f; }
.star:hover { transform: scale(1.2); }

.score-total-box {
  background: #f3f0ff;
  border: 2px dashed var(--primary);
  padding: 1rem;
  border-radius: var(--border-radius-sm);
  text-align: center;
  font-weight: 800;
  margin-bottom: 1.5rem;
}

.score-number {
  font-family: var(--font-heading);
  font-size: 2rem;
  color: var(--primary);
  margin: 0 0.4rem;
}

/* ==========================================================================
   PANTALLA 6: RESULTADOS FINALES
   ========================================================================== */
.results-header {
  text-align: center;
  margin-bottom: 2rem;
}

.results-header h2 {
  font-family: var(--font-heading);
  font-size: 2.5rem;
  color: var(--primary);
}

.podium-container {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 1rem;
  margin-bottom: 2rem;
}

.podium-place {
  background: white;
  border-radius: var(--border-radius-sm);
  padding: 1rem;
  text-align: center;
  box-shadow: var(--box-shadow);
  width: 140px;
}

.podium-1 { order: 2; height: 180px; border-top: 8px solid #f1c40f; }
.podium-2 { order: 1; height: 150px; border-top: 8px solid #bdc3c7; }
.podium-3 { order: 3; height: 130px; border-top: 8px solid #e67e22; }

.podium-crown { font-size: 1.8rem; }
.podium-name { font-weight: 800; margin-top: 0.3rem; }
.podium-score { font-family: var(--font-heading); font-size: 1.2rem; color: var(--primary); }

.leaderboard-list {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  margin-top: 1rem;
}

.leaderboard-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.8rem 1.2rem;
  background: #f8f9fa;
  border-radius: var(--border-radius-sm);
}

.results-actions {
  display: flex;
  justify-content: center;
  gap: 1rem;
  margin-top: 2rem;
}

/* ==========================================================================
   CONFIGURACIÓN Y AJUSTES
   ========================================================================== */
.password-input-wrapper {
  display: flex;
  gap: 0.5rem;
}

.password-input-wrapper input { flex: 1; }

.alert-box {
  padding: 1rem;
  border-radius: var(--border-radius-sm);
  font-size: 0.85rem;
  margin-bottom: 1.2rem;
}
.alert-warning { background: #fff9db; border-left: 4px solid var(--warning); }

.test-result-box {
  margin-top: 1rem;
  padding: 0.8rem 1rem;
  border-radius: var(--border-radius-sm);
  font-size: 0.9rem;
}
.test-success { background: #e6fffa; color: #00796b; border: 1px solid #b2f5ea; }
.test-error { background: #fff5f5; color: #c53030; border: 1px solid #feb2b2; }

.history-actions-bar {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.2rem;
  flex-wrap: wrap;
}

.file-label { cursor: pointer; }

/* ==========================================================================
   MODAL Y UTILIDADES
   ========================================================================== */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  padding: 1rem;
}

.modal-card {
  background: white;
  border-radius: var(--border-radius);
  max-width: 600px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  padding: 1.5rem;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  border-bottom: 1px solid #eee;
  padding-bottom: 0.5rem;
}

.close-btn {
  background: none;
  border: none;
  font-size: 1.8rem;
  cursor: pointer;
}

.center-btn-container { text-align: center; margin-top: 1.5rem; }

/* CONFETI */
.confetti-container {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  pointer-events: none;
  z-index: 999;
  overflow: hidden;
}

.confetti-piece {
  position: absolute;
  width: 10px;
  height: 10px;
  top: -10px;
  animation: fall 3s linear forwards;
}

/* ANIMACIONES */
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes bounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@keyframes pulse { from { transform: scale(1); } to { transform: scale(1.15); } }
@keyframes loadingBar { 0% { transform: translateX(-100%); } 100% { transform: translateX(100%); } }
@keyframes fall { to { transform: translateY(100vh) rotate(720deg); opacity: 0; } }

.pulse-animation { animation: pulse 2s infinite alternate; }

/* RESPONSIVE */
@media (max-width: 600px) {
  .hide-mobile { display: none; }
  .hero-title { font-size: 1.8rem; }
  .turn-player-name { font-size: 2.2rem; }
  .activity-actions { flex-direction: column; }
  .results-actions { flex-direction: column; }
}
