:root {
  --color-primary:   #429DFF;
  --color-accent-1:  #9900FF;
  --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 { font-size: 18px; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  overflow-x: hidden;
  font-family: var(--font-body);
  background: linear-gradient(135deg, #429DFF 0%, #E4F2FF 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(66, 157, 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 8px; }
.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-body--find { padding-top: 12px; }
.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: campo de caza (objetos que aparecen) ---------- */
.find-stage {
  position: relative;
  width: 100%;
  max-width: 560px;
  height: clamp(300px, 52vh, 420px);
  background: var(--color-white);
  border-radius: 18px;
  box-shadow: 0 8px 22px rgba(0,0,0,0.25);
  overflow: hidden;
}
.find-stage.flash-error { animation: flash-error-anim 0.26s ease; }
@keyframes flash-error-anim {
  0%, 100% { box-shadow: 0 8px 22px rgba(0,0,0,0.25); }
  40% { box-shadow: 0 0 0 6px var(--color-error) inset; }
}

.find-item {
  position: absolute;
  width: 22%;
  aspect-ratio: 1 / 1;
  max-width: 98px;
  border: none;
  background: transparent;
  font-size: clamp(2.3rem, 6.5vw, 3.5rem);
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: item-pop-in 0.22s ease;
  transition: left 0.6s ease, top 0.6s ease, opacity 0.25s ease, transform 0.2s ease;
}
@keyframes item-pop-in {
  from { transform: scale(0.3); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
.find-item.is-correct { animation: item-correct 0.25s ease; }
.find-item.is-wrong { animation: item-wrong-shake 0.25s ease; }
.find-item.is-popping { transform: scale(1.5); opacity: 0; }
.find-item.is-expiring { opacity: 0; transform: scale(0.7); }
@keyframes item-correct { 0% { transform: scale(1); } 50% { transform: scale(1.5); } 100% { transform: scale(1.5); opacity: 0; } }
@keyframes item-wrong-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

.find-banner {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: rgba(34, 43, 52, 0.82);
  color: var(--color-white);
  text-align: center;
  padding: 20px;
  z-index: 5;
  opacity: 0;
  transition: opacity 0.3s ease;
}
.find-banner.is-showing { opacity: 1; }
.find-banner.is-success { background: rgba(76, 175, 80, 0.88); }
.find-banner-title { font-size: 1.6rem; font-weight: 800; }
.find-banner-sub { font-size: 1.05rem; font-weight: 600; opacity: 0.9; }

/* ---------- Juego 2: Rally de Coches ---------- */
.timer-bar { width: 100%; height: 8px; background: rgba(255,255,255,0.25); border-radius: 6px; overflow: hidden; align-self: center; max-width: 420px; }
.timer-bar-fill { height: 100%; width: 100%; background: var(--color-accent-3); border-radius: 6px; }
.timer-bar-fill.is-low { background: var(--color-error); }

.reference-chip {
  width: 100px;
  background: rgba(255,255,255,0.9);
  border-radius: 12px;
  padding: 4px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.2);
}
.reference-chip .car-svg { width: 100%; display: block; }

.car-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  max-width: 480px;
  width: 100%;
}
.car-tile {
  border: none;
  background: var(--color-white);
  border-radius: 14px;
  padding: 10px;
  box-shadow: 0 6px 14px rgba(0,0,0,0.2);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.car-tile:active { transform: scale(0.95); }
.car-tile.is-correct { outline: 4px solid var(--color-accent-3); background: #eaffd8; }
.car-tile.is-wrong { outline: 4px solid var(--color-error); animation: item-wrong-shake 0.25s ease; }
.car-svg { width: 100%; height: auto; display: block; }

/* ---------- Juegos 3 y 4: campo de letras/números gemelos ---------- */
.find-model {
  font-size: 3rem;
  font-weight: 800;
  background: var(--color-white);
  color: var(--color-dark);
  width: 76px;
  height: 76px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 14px rgba(0,0,0,0.25);
}
.find-stage--field {
  width: 100%;
  max-width: 560px;
  height: clamp(280px, 46vh, 380px);
}
.find-tile {
  position: absolute;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 10px;
  background: var(--color-white);
  box-shadow: 0 4px 10px rgba(0,0,0,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: item-pop-in 0.2s ease;
  transition: left 0.6s ease, top 0.6s ease, opacity 0.25s ease, background 0.2s ease;
}
.find-tile-glyph { font-size: 1.5rem; font-weight: 800; color: var(--color-dark); display: inline-block; }
.find-tile.is-found { opacity: 0; transform: scale(0.5); background: var(--color-accent-3); }
.find-tile.is-wrong { background: var(--color-error); animation: item-wrong-shake 0.25s ease; }

/* ---------- 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; }
  .car-grid { grid-template-columns: repeat(2, 1fr); max-width: 340px; }
}
@media (max-width: 480px) {
  .game-info { font-size: 0.85rem; padding: 5px 10px; gap: 7px; }
  .find-model { width: 60px; height: 60px; font-size: 2.2rem; }
  .find-tile { width: 38px; height: 38px; }
  .find-tile-glyph { font-size: 1.25rem; }
}
