/* ══════════════════════════════════════════════════
   TABLAS MÁGICAS — styles.css
   Diseño: colorido, lúdico, tipo app educativa
   Fuentes: Google Fonts via @import (sin dependencias JS)
══════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800;900&family=Fredoka+One&display=swap');

/* ── Variables globales ── */
:root {
  --primary:    #6C63FF;
  --primary-dk: #4B44CC;
  --secondary:  #FF6B6B;
  --accent:     #FFD93D;
  --green:      #6BCB77;
  --green-dk:   #4CAF60;
  --orange:     #FF9F43;
  --pink:       #FF78C4;
  --blue:       #4ECDC4;
  --bg:         #F0EEFF;
  --card:       #FFFFFF;
  --text:       #2D2D48;
  --muted:      #9090B0;
  --radius:     18px;
  --radius-sm:  10px;
  --shadow:     0 8px 30px rgba(108,99,255,0.15);
  --shadow-sm:  0 4px 12px rgba(0,0,0,0.08);
  --font-title: 'Fredoka One', cursive;
  --font-body:  'Nunito', sans-serif;
}

/* ── Reset & base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ══════════════════════════════════════════════════
   SISTEMA DE PANTALLAS
══════════════════════════════════════════════════ */
.screen {
  display: none;
  min-height: 100vh;
  padding: 1rem;
  animation: fadeIn 0.3s ease;
}
.screen.active { display: flex; flex-direction: column; }

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

/* ══════════════════════════════════════════════════
   PANTALLA: INICIO
══════════════════════════════════════════════════ */
#screen-home {
  align-items: center;
  justify-content: center;
  position: relative;
  background: linear-gradient(145deg, #e8e4ff 0%, #f9f0ff 50%, #fff5e0 100%);
}

/* Estrellas de fondo animadas */
.home-bg { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 0; }
.star {
  position: absolute;
  font-size: 2rem;
  opacity: 0.4;
  animation: floatStar 6s ease-in-out infinite;
}
.s1 { top: 10%; left: 8%;  animation-delay: 0s;   font-size: 2.5rem; }
.s2 { top: 20%; right: 10%; animation-delay: 1s;  font-size: 1.5rem; }
.s3 { top: 60%; left: 5%;  animation-delay: 2s;   font-size: 3rem;   }
.s4 { bottom: 15%; right: 8%; animation-delay: 0.5s; }
.s5 { bottom: 30%; left: 15%; animation-delay: 1.5s; }

@keyframes floatStar {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50%       { transform: translateY(-20px) rotate(15deg); }
}

.home-card {
  position: relative;
  z-index: 1;
  background: var(--card);
  border-radius: 28px;
  padding: 2.5rem 2rem;
  max-width: 420px;
  width: 100%;
  box-shadow: var(--shadow);
  text-align: center;
}

.home-logo {
  font-size: 5rem;
  animation: bounce 2s ease infinite;
}
@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-12px); }
}

.home-title {
  font-family: var(--font-title);
  font-size: 3rem;
  line-height: 1.1;
  color: var(--primary);
  margin: 0.5rem 0;
}
.home-title span { color: var(--secondary); }

.home-subtitle {
  color: var(--muted);
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 1.5rem;
}

/* XP / Progreso en inicio */
.progress-summary {
  background: var(--bg);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1.5rem;
}
.xp-bar-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}
.xp-label { font-size: 0.75rem; font-weight: 800; color: var(--primary); white-space: nowrap; }
.xp-bar {
  flex: 1;
  height: 10px;
  background: #ddd;
  border-radius: 99px;
  overflow: hidden;
}
.xp-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--pink));
  border-radius: 99px;
  transition: width 0.8s cubic-bezier(.34,1.56,.64,1);
  width: 0%;
}
.xp-value { font-size: 0.75rem; font-weight: 800; color: var(--primary); white-space: nowrap; }

.home-stats {
  display: flex;
  justify-content: space-around;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text);
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* Botones de inicio */
.home-buttons { display: flex; flex-direction: column; gap: 0.75rem; }

/* ══════════════════════════════════════════════════
   BOTONES GLOBALES
══════════════════════════════════════════════════ */
.btn {
  border: none;
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-weight: 800;
  font-size: 1.05rem;
  cursor: pointer;
  padding: 0.85rem 1.5rem;
  transition: transform 0.12s, box-shadow 0.12s, filter 0.12s;
  letter-spacing: 0.02em;
}
.btn:active { transform: scale(0.96); }

.btn-primary {
  background: linear-gradient(135deg, var(--primary), #8B78FF);
  color: #fff;
  box-shadow: 0 4px 0 var(--primary-dk);
}
.btn-primary:hover { filter: brightness(1.08); box-shadow: 0 6px 0 var(--primary-dk); transform: translateY(-2px); }

.btn-secondary {
  background: linear-gradient(135deg, var(--secondary), #FF9A9A);
  color: #fff;
  box-shadow: 0 4px 0 #CC4444;
}
.btn-secondary:hover { filter: brightness(1.08); transform: translateY(-2px); }

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 2px solid #ddd;
}
.btn-ghost:hover { background: #f5f5f5; }

.btn-danger {
  background: var(--secondary);
  color: #fff;
  box-shadow: 0 4px 0 #CC4444;
}

/* ══════════════════════════════════════════════════
   CABECERA DE PANTALLAS INTERNAS
══════════════════════════════════════════════════ */
.screen-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 2px dashed rgba(108,99,255,0.2);
}
.screen-header h2 {
  flex: 1;
  font-family: var(--font-title);
  font-size: 1.6rem;
  color: var(--primary);
}
.xp-badge {
  background: var(--accent);
  color: #5a4000;
  border-radius: 99px;
  padding: 0.25rem 0.75rem;
  font-size: 0.85rem;
  font-weight: 800;
}

.btn-back {
  background: var(--bg);
  border: 2px solid #ddd;
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.75rem;
  font-family: var(--font-body);
  font-weight: 700;
  cursor: pointer;
  color: var(--text);
  transition: background 0.15s;
  white-space: nowrap;
}
.btn-back:hover { background: #e0dcff; }

/* ══════════════════════════════════════════════════
   PANTALLA: SELECCIÓN DE TABLA
══════════════════════════════════════════════════ */
#screen-select {
  max-width: 540px;
  margin: 0 auto;
  width: 100%;
}

.select-hint {
  text-align: center;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 1rem;
}

.tables-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.table-btn {
  aspect-ratio: 1;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font-title);
  font-size: 1.5rem;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}
.table-btn:hover:not(.locked) { transform: translateY(-4px) scale(1.05); box-shadow: var(--shadow); }
.table-btn:active:not(.locked) { transform: scale(0.95); }

.table-btn.unlocked {
  background: linear-gradient(135deg, var(--primary), #9B8FFF);
  color: #fff;
  box-shadow: 0 4px 0 var(--primary-dk);
}
.table-btn.completed {
  background: linear-gradient(135deg, var(--green), #90E799);
  color: #fff;
  box-shadow: 0 4px 0 var(--green-dk);
}
.table-btn.locked {
  background: #e0e0ee;
  color: #aaa;
  cursor: not-allowed;
  box-shadow: none;
}

.table-btn .table-stars {
  font-size: 0.55rem;
  letter-spacing: 1px;
  line-height: 1;
}
.table-btn .lock-icon { font-size: 1.2rem; }

/* Dificultad */
.difficulty-wrap {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow-sm);
  text-align: center;
}
.difficulty-label {
  font-weight: 800;
  color: var(--text);
  margin-bottom: 0.75rem;
  font-size: 0.95rem;
}
.difficulty-btns {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}
.diff-btn {
  border: 2px solid #ddd;
  background: white;
  border-radius: 99px;
  padding: 0.4rem 1rem;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s;
  color: var(--text);
}
.diff-btn.active {
  border-color: var(--primary);
  background: var(--primary);
  color: white;
}
.difficulty-desc {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
}

/* ══════════════════════════════════════════════════
   PANTALLA: JUEGO
══════════════════════════════════════════════════ */
#screen-game {
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
  justify-content: flex-start;
  gap: 0.75rem;
}

/* HUD */
.game-hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.hud-left { display: flex; align-items: center; gap: 0.5rem; }
.hud-table {
  font-family: var(--font-title);
  font-size: 1.1rem;
  color: var(--primary);
}
.hud-center { flex: 1; display: flex; justify-content: center; }
.hud-right {}

/* Vidas */
.lives { display: flex; gap: 4px; }
.heart {
  font-size: 1.5rem;
  transition: transform 0.3s;
}
.heart.lost {
  filter: grayscale(1) opacity(0.4);
  transform: scale(0.85);
}

/* Racha */
.streak-badge {
  background: linear-gradient(135deg, var(--orange), #FFB347);
  color: white;
  border-radius: 99px;
  padding: 0.3rem 0.75rem;
  font-weight: 800;
  font-size: 0.9rem;
  box-shadow: 0 3px 0 #cc7700;
}

/* Barra de progreso de preguntas */
.question-progress {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.q-bar {
  flex: 1;
  height: 8px;
  background: #ddd;
  border-radius: 99px;
  overflow: hidden;
}
.q-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--orange));
  border-radius: 99px;
  transition: width 0.4s ease;
  width: 0%;
}
.q-count {
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--muted);
  white-space: nowrap;
}

/* Temporizador */
.timer-wrap {
  display: flex;
  justify-content: center;
}
.timer-ring {
  position: relative;
  width: 52px;
  height: 52px;
}
.timer-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.timer-bg  { fill: none; stroke: #eee; stroke-width: 4; }
.timer-arc {
  fill: none;
  stroke: var(--secondary);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-dasharray: 113;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 1s linear, stroke 0.3s;
}
.timer-arc.urgent { stroke: var(--secondary); }
#timer-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-title);
  font-size: 1.1rem;
  color: var(--text);
}

/* Tarjeta de pregunta */
.question-card {
  background: linear-gradient(135deg, var(--primary), #9B8FFF);
  border-radius: var(--radius);
  padding: 1.75rem 1rem;
  text-align: center;
  box-shadow: var(--shadow);
  animation: popIn 0.35s cubic-bezier(.34,1.56,.64,1);
}
@keyframes popIn {
  from { transform: scale(0.85); opacity: 0; }
  to   { transform: scale(1);    opacity: 1; }
}
.question-text {
  font-family: var(--font-title);
  font-size: 3rem;
  color: white;
  text-shadow: 0 3px 0 rgba(0,0,0,0.2);
}

/* Opciones */
.options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}
.option-btn {
  border: none;
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
  font-family: var(--font-title);
  font-size: 1.8rem;
  padding: 1rem;
  cursor: pointer;
  box-shadow: 0 4px 0 #ccc;
  transition: transform 0.1s, box-shadow 0.1s;
  text-align: center;
}
.option-btn:hover:not(:disabled) {
  transform: translateY(-3px);
  box-shadow: 0 7px 0 #bbb;
}
.option-btn:active:not(:disabled) { transform: translateY(1px); box-shadow: 0 2px 0 #bbb; }
.option-btn:disabled { cursor: default; }

.option-btn.correct {
  background: linear-gradient(135deg, var(--green), #90E799);
  color: white;
  box-shadow: 0 4px 0 var(--green-dk);
  animation: wiggleCorrect 0.4s ease;
}
.option-btn.wrong {
  background: linear-gradient(135deg, var(--secondary), #FF9A9A);
  color: white;
  box-shadow: 0 4px 0 #CC4444;
  animation: shakeWrong 0.4s ease;
}

@keyframes wiggleCorrect {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.12); }
  70%  { transform: scale(0.95); }
  100% { transform: scale(1); }
}
@keyframes shakeWrong {
  0%, 100% { transform: translateX(0); }
  25%       { transform: translateX(-6px); }
  75%       { transform: translateX(6px); }
}

/* Feedback */
.feedback {
  background: var(--card);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  text-align: center;
  font-weight: 800;
  font-size: 1.05rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  animation: fadeIn 0.2s ease;
}

/* Toast de XP */
.xp-toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: #5a4000;
  font-weight: 900;
  font-size: 1.1rem;
  border-radius: 99px;
  padding: 0.5rem 1.25rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
  z-index: 100;
  white-space: nowrap;
}
.xp-toast.show {
  opacity: 1;
  animation: toastUp 1.4s ease forwards;
}
@keyframes toastUp {
  0%   { opacity: 1; transform: translateX(-50%) translateY(0); }
  70%  { opacity: 1; transform: translateX(-50%) translateY(-20px); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-30px); }
}

/* ══════════════════════════════════════════════════
   PANTALLA: RESULTADO
══════════════════════════════════════════════════ */
#screen-result {
  align-items: center;
  justify-content: center;
  background: linear-gradient(145deg, #e8e4ff, #fff5e0);
}

.result-card {
  background: var(--card);
  border-radius: 28px;
  padding: 2rem 1.75rem;
  max-width: 400px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow);
  animation: popIn 0.4s cubic-bezier(.34,1.56,.64,1);
}

.result-emoji {
  font-size: 4.5rem;
  animation: bounce 1.5s ease infinite;
  display: block;
}

.result-title {
  font-family: var(--font-title);
  font-size: 2.2rem;
  color: var(--primary);
  margin: 0.5rem 0 0.2rem;
}
.result-subtitle { color: var(--muted); font-weight: 600; margin-bottom: 1rem; }

.result-stars {
  font-size: 2rem;
  letter-spacing: 4px;
  margin-bottom: 1.25rem;
  display: block;
}

.result-stats {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  margin-bottom: 1.25rem;
}
.stat-box {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  flex: 1;
}
.stat-num {
  display: block;
  font-family: var(--font-title);
  font-size: 1.8rem;
  color: var(--primary);
}
.stat-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted);
}

/* Logros nuevos */
.new-achievements {
  background: linear-gradient(135deg, #fff8dc, #fff3b0);
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
  padding: 0.75rem;
  margin-bottom: 1.25rem;
}
.new-ach-title { font-weight: 800; font-size: 0.9rem; margin-bottom: 0.5rem; }
.new-ach-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.result-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

/* ══════════════════════════════════════════════════
   PANTALLA: LOGROS
══════════════════════════════════════════════════ */
#screen-achievements {
  max-width: 540px;
  margin: 0 auto;
  width: 100%;
}

.achievements-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.ach-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  text-align: center;
  transition: transform 0.15s;
}
.ach-card:hover { transform: translateY(-3px); }
.ach-card.locked-ach {
  background: #f0f0f0;
  filter: grayscale(1);
  opacity: 0.6;
}
.ach-card.unlocked-ach {
  border: 2px solid var(--accent);
  background: linear-gradient(135deg, #fffde7, #fff9c4);
}

.ach-icon { font-size: 2.5rem; }
.ach-name { font-weight: 800; font-size: 0.85rem; color: var(--text); }
.ach-desc { font-size: 0.72rem; color: var(--muted); font-weight: 600; line-height: 1.3; }
.ach-xp-reward {
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--primary);
  background: var(--bg);
  border-radius: 99px;
  padding: 0.15rem 0.5rem;
}

/* ══════════════════════════════════════════════════
   OVERLAYS
══════════════════════════════════════════════════ */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 1rem;
}
.overlay-card {
  background: var(--card);
  border-radius: 24px;
  padding: 2rem;
  max-width: 340px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow);
  animation: popIn 0.3s cubic-bezier(.34,1.56,.64,1);
}
.overlay-emoji { font-size: 3rem; margin-bottom: 0.75rem; }
.overlay-text { font-weight: 700; font-size: 1rem; color: var(--text); margin-bottom: 1.25rem; }
.overlay-btns { display: flex; flex-direction: column; gap: 0.5rem; }

/* ══════════════════════════════════════════════════
   ANIMACIÓN: PARTÍCULAS DE ACIERTO
══════════════════════════════════════════════════ */
.particle {
  position: fixed;
  font-size: 1.5rem;
  pointer-events: none;
  z-index: 999;
  animation: particleFly 0.9s ease-out forwards;
}
@keyframes particleFly {
  0%   { opacity: 1; transform: translate(0, 0) scale(1); }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(0.3); }
}

/* ══════════════════════════════════════════════════
   RESPONSIVE
══════════════════════════════════════════════════ */
@media (max-width: 400px) {
  .tables-grid { grid-template-columns: repeat(5, 1fr); gap: 0.5rem; }
  .table-btn { font-size: 1.2rem; border-radius: 12px; }
  .question-text { font-size: 2.4rem; }
  .option-btn { font-size: 1.5rem; padding: 0.85rem; }
  .home-title { font-size: 2.5rem; }
  .result-title { font-size: 1.9rem; }
  .achievements-grid { grid-template-columns: 1fr 1fr; gap: 0.5rem; }
}

@media (min-width: 600px) {
  .screen { padding: 1.5rem 2rem; }
  .home-card { padding: 3rem 2.5rem; }
  .question-text { font-size: 3.5rem; }
  .option-btn { font-size: 2rem; }
}

/* Scrollbar personalizado */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #ccc; border-radius: 99px; }
