:root {
  --color-primary:   #9900FF;
  --color-accent-1:  #429DFF;
  --color-accent-2:  #F3A200;
  --color-accent-3:  #ACFF00;
  --color-accent-4:  #ED00A6;
  --color-error:     #E74C3C;
  --color-dark:      #222B34;
  --color-light:     #F5FAFD;
  --color-white:     #FFFFFF;

  --font-title: 'Muli', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-body:  'Open Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }

html {
  /* Base más grande de lo habitual (16px) para que todo el texto, que usa rem, se lea
     con claridad: pensado para niños con dificultades de aprendizaje/lectura. */
  font-size: 19px;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  overflow-x: hidden;
  font-family: var(--font-body);
  background: linear-gradient(135deg, #9900FF 0%, #F1E0FF 100%);
  background-attachment: fixed;
  color: var(--color-dark);
}

h1, h2, h3 { font-family: var(--font-title); margin: 0 0 8px; }
button { font-family: var(--font-body); cursor: pointer; }

/* ---------- Layout de pantallas ---------- */
.screen {
  display: none;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.screen.active { display: flex; }

.card {
  background: var(--color-white);
  border-radius: 18px;
  box-shadow: 0 12px 30px rgba(0,0,0,0.25);
  padding: 28px 26px;
  max-width: 480px;
  width: 100%;
  text-align: center;
}
.card--menu { max-width: 640px; }
.card--modal { max-width: 560px; max-height: 85vh; overflow-y: auto; text-align: left; }

.title { font-size: 1.8rem; color: var(--color-dark); }
.title--sm { font-size: 1.4rem; text-align: center; }
.subtitle { margin: 0 0 20px; color: #5a6472; font-size: 1.05rem; }

/* ---------- Botones ---------- */
.btn {
  display: block;
  width: 100%;
  padding: 13px 18px;
  margin: 8px 0;
  border: none;
  border-radius: 12px;
  font-size: 1.1rem;
  font-weight: 700;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary {
  background: linear-gradient(135deg, var(--color-primary), var(--color-accent-4));
  color: var(--color-white);
  box-shadow: 0 6px 14px rgba(153, 0, 255, 0.35);
}
.btn-ghost { background: var(--color-light); color: var(--color-dark); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.stack-buttons { display: flex; flex-direction: column; }

.icon-btn {
  background: rgba(255,255,255,0.15);
  border: none;
  color: var(--color-white);
  font-size: 1.3rem;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  line-height: 1;
}

/* ---------- Menú principal: tarjetas de juego ---------- */
.hub-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.hub-card {
  background: var(--color-light);
  border-radius: 16px;
  padding: 18px 16px;
  text-align: center;
  border-top: 5px solid var(--card-color, var(--color-primary));
}
.hub-card-icon { font-size: 2.2rem; margin-bottom: 4px; }
.hub-card-title { font-size: 1.15rem; margin: 4px 0; }
.hub-card-desc { font-size: 0.95rem; color: #5a6472; margin: 0 0 8px; min-height: 34px; }
.hub-card-progress { font-size: 0.88rem; font-weight: 700; color: var(--card-color, var(--color-primary)); margin: 0 0 10px; }
.hub-card-btn { margin: 0; }

/* ---------- Ajustes ---------- */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 16px 0;
  text-align: left;
}
.setting-row label { font-weight: 700; font-size: 1.02rem; }
.setting-row input[type="range"] { flex: 1; accent-color: var(--color-primary); }
.setting-row select {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 1rem;
  padding: 7px 10px;
  border-radius: 8px;
  border: 2px solid var(--color-light);
  background: var(--color-white);
  color: var(--color-dark);
}
.switch { width: 22px; height: 22px; accent-color: var(--color-primary); }
.settings-divider { border: none; border-top: 2px solid var(--color-light); margin: 18px 0 4px; }
.settings-group-label { font-size: 0.88rem; font-weight: 700; color: var(--color-primary); text-align: left; margin: 0; }

/* ---------- Pantalla de juego (cabecera común) ---------- */
.screen[id^="screen-game"] { align-items: stretch; padding: 0; }
.screen[id^="screen-game"].active { display: flex; flex-direction: column; }

.game-header {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 14px;
  color: var(--color-white);
  position: sticky;
  top: 0;
  z-index: 15;
  background: rgba(34, 43, 52, 0.55);
  backdrop-filter: blur(6px);
}
.game-header-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.game-info {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  align-self: center;
  background: rgba(255,255,255,0.15);
  padding: 6px 14px;
  border-radius: 20px;
  font-weight: 700;
  font-size: 0.95rem;
}
.mode-badge {
  padding: 4px 14px;
  border-radius: 14px;
  font-weight: 800;
  font-size: 1.02rem;
  background: var(--color-primary);
  color: var(--color-white);
}

.game-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 16px;
  padding: 20px 12px 30px;
}
.game-prompt { font-weight: 700; font-size: 1.25rem; margin: 0; text-align: center; color: var(--color-white); text-shadow: 0 1px 4px rgba(0,0,0,0.35); }

/* ---------- Juego 1: contar y teclado numérico ---------- */
.count-stage {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  align-items: center;
  width: 100%;
  max-width: 420px;
  background: var(--color-white);
  border-radius: 16px;
  padding: 18px;
  box-shadow: 0 8px 20px rgba(0,0,0,0.2);
  min-height: 70px;
}
.count-item { font-size: 2.1rem; line-height: 1; }

.sequence-track { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; width: 100%; max-width: 420px; }
.seq-slot {
  width: 46px; height: 46px;
  border-radius: 10px;
  background: rgba(255,255,255,0.25);
  border: 2px dashed rgba(255,255,255,0.6);
  color: var(--color-white);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 1.3rem;
}
.seq-slot.filled { background: var(--color-white); color: var(--color-dark); border-style: solid; border-color: var(--color-white); }

.keypad {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  max-width: 380px;
  width: 100%;
}
.keypad-btn {
  border: none;
  border-radius: 12px;
  background: var(--color-white);
  color: var(--color-dark);
  font-weight: 800;
  font-size: 1.4rem;
  padding: 14px 0;
  box-shadow: 0 4px 10px rgba(0,0,0,0.2);
  transition: background 0.2s ease, transform 0.1s ease;
}
.keypad-btn:active { transform: scale(0.95); }
.keypad-btn.correct { background: var(--color-accent-3); }
.keypad-btn.wrong { background: var(--color-error); color: var(--color-white); }
.keypad-backspace { max-width: 380px; }

/* ---------- Juego 2 y 3: tablero de memoria (parejas) ---------- */
.memory-grid {
  --cols: 4;
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  gap: 10px;
  max-width: 520px;
  width: 100%;
  perspective: 800px;
}
.memory-card {
  border: none;
  background: transparent;
  padding: 0;
  aspect-ratio: 3 / 4;
  min-height: 60px;
}
.memory-card-inner {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.45s ease;
}
.memory-card.is-flipped .memory-card-inner { transform: rotateY(180deg); }
.memory-card.is-matched { opacity: 0.55; }
.memory-card-face {
  position: absolute;
  inset: 0;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  backface-visibility: hidden;
  box-shadow: 0 4px 10px rgba(0,0,0,0.25);
}
.memory-card-back {
  background: linear-gradient(135deg, var(--color-primary), var(--color-accent-4));
  color: var(--color-white);
  font-size: 1.4rem;
}
.memory-card-front {
  background: var(--color-white);
  transform: rotateY(180deg);
  padding: 4px;
  text-align: center;
}
.memory-card-front--color { color: var(--color-white); }
.memory-card-color-label { font-weight: 800; font-size: 0.95rem; text-shadow: 0 1px 2px rgba(0,0,0,0.35); }
.memory-card-emoji { font-size: clamp(2.2rem, 9vw, 3.6rem); line-height: 1; }
.memory-card--word .memory-card-front { background: var(--color-light); }
.memory-card-word { font-weight: 800; font-size: 1rem; color: var(--color-dark); word-break: break-word; }

/* ---------- Juego 4: cubos que se mueven ---------- */
.cube-track-wrap { width: 100%; overflow-x: auto; padding: 10px 0; }
.cube-track { position: relative; margin: 0 auto; }
.cube {
  position: absolute;
  top: 0; left: 0;
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--color-accent-1), #2C6FCC);
  box-shadow: 0 6px 14px rgba(0,0,0,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
}
.cube-lid { position: absolute; top: 6%; left: 6%; right: 6%; height: 22%; background: rgba(255,255,255,0.25); border-radius: 6px; }
.cube-ball { font-size: 1.6rem; }
.cube--correct { background: linear-gradient(135deg, var(--color-accent-3), #7CC400); }
.cube--reveal-wrong { background: linear-gradient(135deg, var(--color-error), #B93A2C); }
.cube--guess-wrong { outline: 3px solid var(--color-error); }

/* ---------- Overlays ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(34, 43, 52, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}
.overlay.hidden { display: none; }

.instructions-list { padding-left: 20px; margin: 0 0 18px; font-size: 1.02rem; }
.instructions-list li { margin-bottom: 10px; line-height: 1.45; }

.result-icon { font-size: 2.8rem; margin-bottom: 6px; }
.result-text { color: #5a6472; margin: 8px 0 18px; font-size: 1.05rem; }
.result-stats { text-align: left; margin: 0 0 10px; }

.hidden { display: none !important; }

/* Confeti sencillo */
.confetti { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.confetti span {
  position: absolute;
  top: -10px;
  width: 8px;
  height: 14px;
  opacity: 0.9;
  animation: confetti-fall linear forwards;
}
@keyframes confetti-fall { to { transform: translateY(110vh) rotate(600deg); opacity: 0.3; } }

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  .card { padding: 22px 18px; }
}
@media (max-width: 480px) {
  .game-info { font-size: 0.85rem; padding: 5px 10px; gap: 7px; }
  .keypad-btn { font-size: 1.2rem; padding: 12px 0; }
  .count-item { font-size: 1.9rem; }
}
