:root {
  --color-fondo: #fef9ef;
  --color-primario: #6c5ce7;
  --color-primario-oscuro: #5344c9;
  --color-acento: #ff7675;
  --color-exito: #00b894;
  --color-texto: #2d3436;
  --radio: 16px;
  --sombra: 0 4px 14px rgba(45, 52, 54, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Comic Sans MS", "Trebuchet MS", system-ui, sans-serif;
  background: var(--color-fondo);
  color: var(--color-texto);
  line-height: 1.5;
}

header.hero {
  background: linear-gradient(135deg, var(--color-primario), #a29bfe);
  color: white;
  padding: 48px 24px;
  text-align: center;
  border-bottom-left-radius: 32px;
  border-bottom-right-radius: 32px;
}

header.hero h1 {
  margin: 0 0 8px;
  font-size: clamp(1.8rem, 5vw, 2.6rem);
}

header.hero p {
  margin: 0;
  font-size: 1.1rem;
  opacity: 0.95;
}

main {
  max-width: 900px;
  margin: 0 auto;
  padding: 32px 20px 64px;
}

/* ====== Hub de juegos (página de inicio) ====== */

.hero-home {
  position: relative;
  overflow: hidden;
}

.hero-emojis {
  font-size: 1.4rem;
  letter-spacing: 12px;
  opacity: 0.9;
  margin-bottom: 14px;
  animation: flotar 4s ease-in-out infinite;
}

@keyframes flotar {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.titulo-seccion {
  font-size: 1.6rem;
  margin: 8px 0 4px;
}

.juegos-hub {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 20px;
  margin-top: 20px;
}

.juego-card {
  position: relative;
  border-radius: 22px;
  padding: 24px;
  text-decoration: none;
  color: white;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 180px;
  box-shadow: var(--sombra);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.juego-card:hover {
  transform: translateY(-6px) rotate(-1deg);
  box-shadow: 0 12px 26px rgba(45, 52, 54, 0.22);
}

.juego-card .badge-emoji {
  font-size: 2rem;
  width: 60px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.25);
  border-radius: 16px;
  margin-bottom: 4px;
}

.juego-card h3 {
  margin: 0;
  font-size: 1.35rem;
}

.juego-card p {
  margin: 0;
  font-size: 0.95rem;
  opacity: 0.95;
  flex-grow: 1;
}

.juego-card .jugar {
  margin-top: 6px;
  align-self: flex-start;
  background: white;
  color: var(--color-texto);
  font-weight: bold;
  padding: 8px 18px;
  border-radius: 999px;
  font-size: 0.95rem;
}

.juego-card .candado {
  margin-top: 6px;
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.3);
  color: white;
  font-weight: bold;
  padding: 8px 18px;
  border-radius: 999px;
  font-size: 0.9rem;
}

/* Colores vibrantes de cada tarjeta */
.color-morado { background: linear-gradient(135deg, #6c5ce7, #a29bfe); }
.color-azul { background: linear-gradient(135deg, #0984e3, #74b9ff); }
.color-naranja { background: linear-gradient(135deg, #e17055, #fab1a0); }
.color-rosa { background: linear-gradient(135deg, #e84393, #fd79a8); }
.color-verde { background: linear-gradient(135deg, #00b894, #55efc4); }

/* Tarjetas de juegos que aún no están listos */
.juego-card.proximamente {
  cursor: default;
  filter: saturate(0.55);
  opacity: 0.85;
}

.juego-card.proximamente:hover {
  transform: none;
  box-shadow: var(--sombra);
}

a.volver {
  display: inline-block;
  margin-bottom: 20px;
  color: var(--color-primario-oscuro);
  text-decoration: none;
  font-weight: bold;
}

a.volver:hover {
  text-decoration: underline;
}

.leccion h2 {
  font-size: 1.6rem;
}

.explicacion {
  background: white;
  border-radius: var(--radio);
  box-shadow: var(--sombra);
  padding: 20px 24px;
  margin-bottom: 28px;
}

.juego {
  background: white;
  border-radius: var(--radio);
  box-shadow: var(--sombra);
  padding: 24px;
  text-align: center;
}

.tablero {
  display: grid;
  grid-template-columns: repeat(5, 56px);
  grid-template-rows: repeat(5, 56px);
  gap: 4px;
  justify-content: center;
  margin: 20px auto;
}

.celda {
  background: #f1f0fb;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
}

.controles {
  display: grid;
  grid-template-columns: repeat(3, 56px);
  grid-template-rows: repeat(3, 56px);
  gap: 6px;
  justify-content: center;
  margin: 20px auto;
}

.controles button {
  font-size: 1.4rem;
  border: none;
  border-radius: 10px;
  background: var(--color-primario);
  color: white;
  cursor: pointer;
}

.controles button:hover {
  background: var(--color-primario-oscuro);
}

.controles button:disabled {
  opacity: 0.4;
  cursor: default;
}

#arriba { grid-column: 2; grid-row: 1; }
#izquierda { grid-column: 1; grid-row: 2; }
#derecha { grid-column: 3; grid-row: 2; }
#abajo { grid-column: 2; grid-row: 3; }

.lista-instrucciones {
  min-height: 40px;
  background: #f8f7ff;
  border-radius: 10px;
  padding: 10px 14px;
  margin: 16px auto;
  max-width: 500px;
  font-size: 1.3rem;
  letter-spacing: 4px;
}

.acciones {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 12px;
}

.boton {
  border: none;
  border-radius: 999px;
  padding: 10px 22px;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
  color: white;
}

.boton.ejecutar { background: var(--color-exito); }
.boton.borrar { background: var(--color-acento); }
.boton:disabled { opacity: 0.5; cursor: default; }

.mensaje {
  margin-top: 16px;
  font-weight: bold;
  min-height: 24px;
}

.mensaje.exito { color: var(--color-exito); }
.mensaje.error { color: var(--color-acento); }

footer {
  text-align: center;
  padding: 20px;
  color: #b2b2b2;
  font-size: 0.85rem;
}

/* ====== Juego de banderas ====== */

.niveles {
  display: grid;
  gap: 14px;
  margin-top: 20px;
}

.nivel {
  border: none;
  border-radius: var(--radio);
  padding: 18px 20px;
  cursor: pointer;
  color: white;
  text-align: left;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  column-gap: 14px;
  align-items: center;
  transition: transform 0.15s ease;
}

.nivel:hover {
  transform: translateY(-3px);
}

.nivel .emoji {
  grid-row: 1 / 3;
  font-size: 1.8rem;
}

.nivel .nombre {
  font-size: 1.3rem;
  font-weight: bold;
}

.nivel .detalle {
  font-size: 0.9rem;
  opacity: 0.95;
}

.nivel.facil { background: linear-gradient(135deg, #00b894, #55efc4); }
.nivel.intermedio { background: linear-gradient(135deg, #f0932b, #ffbe76); }
.nivel.dificil { background: linear-gradient(135deg, #eb4d4b, #ff7979); }

.barra-superior {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.volver-juego {
  border: none;
  background: #f1f0fb;
  color: var(--color-primario-oscuro);
  border-radius: 10px;
  width: 40px;
  height: 40px;
  font-size: 1.3rem;
  cursor: pointer;
}

.volver-juego:hover { background: #e6e2ff; }

.puntos {
  font-weight: bold;
  font-size: 1.2rem;
  color: var(--color-primario-oscuro);
}

.contador {
  font-weight: bold;
  font-size: 1.1rem;
  color: #636e72;
}

.progreso {
  height: 10px;
  background: #f1f0fb;
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 20px;
}

.progreso-relleno {
  height: 100%;
  width: 0;
  background: var(--color-primario);
  border-radius: 999px;
  transition: width 0.3s ease;
}

.marco-bandera {
  width: 100%;
  max-width: 360px;
  aspect-ratio: 3 / 2;
  margin: 0 auto 22px;
  background: white;
  border: 4px solid #f1f0fb;
  border-radius: var(--radio);
  box-shadow: var(--sombra);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.marco-bandera img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.opciones {
  display: grid;
  gap: 12px;
  max-width: 420px;
  margin: 0 auto;
}

.opcion {
  border: 2px solid #dfe4ea;
  background: linear-gradient(180deg, #ffffff, #f1f2f6);
  border-radius: 12px;
  padding: 16px;
  font-size: 1.2rem;
  font-weight: bold;
  color: var(--color-texto);
  cursor: pointer;
  transition: transform 0.1s ease, border-color 0.1s ease;
}

.opcion:hover:not(:disabled) {
  transform: translateY(-2px);
  border-color: var(--color-primario);
}

.opcion:disabled { cursor: default; }

.opcion.correcta {
  background: #d6f5e9;
  border-color: var(--color-exito);
  color: #087f5b;
}

.opcion.incorrecta {
  background: #ffe0dd;
  border-color: var(--color-acento);
  color: #c0392b;
}

.mensaje-juego {
  margin-top: 18px;
  font-weight: bold;
  font-size: 1.2rem;
  min-height: 28px;
}

.mensaje-juego.exito { color: var(--color-exito); }
.mensaje-juego.error { color: var(--color-acento); }

.fin-emoji { font-size: 3.5rem; }
.fin-estrellas { font-size: 2.8rem; letter-spacing: 6px; }

.fin-puntaje { font-size: 1.3rem; font-weight: bold; margin: 4px 0; }
.fin-puntos { font-size: 1.1rem; color: var(--color-primario-oscuro); font-weight: bold; margin: 4px 0; }
.fin-nivel { color: #636e72; margin: 4px 0 8px; }

/* ====== Juego de números mágicos ====== */

.racha {
  font-weight: bold;
  font-size: 1.1rem;
  color: #e17055;
}

.manipulativos {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 14px;
  margin: 8px auto 20px;
  min-height: 40px;
}

.grupo-objetos {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: center;
  max-width: 220px;
  padding: 10px 14px;
  background: #f8f7ff;
  border-radius: 14px;
}

.objeto {
  font-size: 1.6rem;
  line-height: 1;
}

.objeto.quitado {
  opacity: 0.3;
  position: relative;
}

.objeto.quitado::after {
  content: "✖";
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  color: var(--color-acento);
  font-size: 1.1rem;
}

.signo-objetos {
  font-size: 1.8rem;
  font-weight: bold;
  color: var(--color-primario-oscuro);
}

.problema {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  margin: 10px auto 24px;
  font-size: clamp(2rem, 9vw, 3rem);
  font-weight: bold;
  color: var(--color-texto);
}

.problema .igual { color: #b2bec3; }

.respuesta {
  min-width: 80px;
  padding: 6px 18px;
  border: 3px dashed var(--color-primario);
  border-radius: 14px;
  color: var(--color-primario-oscuro);
  text-align: center;
  transition: transform 0.15s ease, background 0.15s ease;
}

.respuesta.correcta {
  border-style: solid;
  border-color: var(--color-exito);
  background: #d6f5e9;
  color: #087f5b;
  transform: scale(1.1);
}

.respuesta.incorrecta {
  border-style: solid;
  border-color: var(--color-acento);
  background: #ffe0dd;
  color: #c0392b;
}

.teclado {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  max-width: 320px;
  margin: 0 auto;
}

.tecla {
  border: none;
  background: linear-gradient(180deg, #ffffff, #eef0f5);
  border: 2px solid #dfe4ea;
  border-radius: 14px;
  padding: 18px 0;
  font-size: 1.6rem;
  font-weight: bold;
  color: var(--color-texto);
  cursor: pointer;
  transition: transform 0.1s ease;
}

.tecla:hover:not(:disabled) { transform: translateY(-2px); }
.tecla:active:not(:disabled) { transform: scale(0.95); }
.tecla:disabled { opacity: 0.5; cursor: default; }

.tecla-borrar {
  background: linear-gradient(180deg, #ffefea, #ffd9cf);
  border-color: #ffb3a0;
  color: #c0392b;
}

.tecla-comprobar {
  background: linear-gradient(135deg, #00b894, #55efc4);
  border-color: #00b894;
  color: white;
}
