/* =========================================================
   TabYat — estilos generales
   Paleta pastel "constelación de estrellas"
   ========================================================= */

:root {
  --pink: #FF6FA0;
  --pink-dark: #E85289;
  --blue: #4EA8DE;
  --blue-dark: #2D86C4;
  --purple: #9B6FE0;
  --purple-dark: #7C4FC4;
  --amber: #FFC145;
  --amber-dark: #E8A11F;
  --mint: #2EC4B6;
  --mint-dark: #1FA093;
  --navy: #1B2A5B;
  --navy-soft: #33447A;
  --cream: #FFF9F2;
  --lavender: #F3EFFF;
  --white: #FFFFFF;
  --success: #3BC97A;
  --error: #FF6B6B;

  --radius-lg: 28px;
  --radius-md: 18px;
  --radius-sm: 12px;
  --shadow-soft: 0 8px 24px rgba(27, 42, 91, 0.12);
  --shadow-pop: 0 4px 0 rgba(0,0,0,0.15);
  --font-display: 'Chalkboard SE', 'Comic Sans MS', 'Trebuchet MS', 'Segoe UI Rounded', system-ui, sans-serif;
  --font-body: -apple-system, 'Segoe UI', 'Trebuchet MS', Roboto, system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow-x: hidden;
  background: linear-gradient(180deg, #F3EFFF 0%, #FFF9F2 55%, #FFF3E6 100%);
  color: var(--navy);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#app {
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  overflow: hidden;
}

/* fondo decorativo con estrellitas flotantes */
.bg-decor {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
  max-width: 560px;
  margin: 0 auto;
}
.bg-decor span {
  position: absolute;
  font-size: 22px;
  opacity: 0.25;
  animation: float-y 6s ease-in-out infinite;
}

@keyframes float-y {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-18px) rotate(12deg); }
}

h1, h2, h3, h4, button {
  font-family: var(--font-display);
  font-weight: 700;
}

/* =========================
   Pantallas
   ========================= */
.screen {
  position: relative;
  z-index: 1;
  display: none;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 18px 18px 28px;
  animation: screen-in 0.35s ease;
}
.screen.active { display: flex; }

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

/* =========================
   Barra superior
   ========================= */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}
.topbar .stat-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--white);
  border-radius: 999px;
  padding: 8px 14px;
  box-shadow: var(--shadow-soft);
  font-weight: 800;
  font-size: 15px;
  color: var(--navy);
}
.icon-btn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: none;
  background: var(--white);
  box-shadow: var(--shadow-soft);
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.icon-btn:active { transform: scale(0.92); }

/* =========================
   Botones
   ========================= */
.btn {
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 20px;
  padding: 16px 28px;
  cursor: pointer;
  color: var(--white);
  background: var(--purple);
  box-shadow: 0 5px 0 var(--purple-dark);
  transition: transform 0.08s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--purple-dark); }
.btn.big { font-size: 26px; padding: 22px 36px; border-radius: var(--radius-lg); }
.btn.pink { background: var(--pink); box-shadow: 0 5px 0 var(--pink-dark); }
.btn.blue { background: var(--blue); box-shadow: 0 5px 0 var(--blue-dark); }
.btn.mint { background: var(--mint); box-shadow: 0 5px 0 var(--mint-dark); }
.btn.amber { background: var(--amber); color: var(--navy); box-shadow: 0 5px 0 var(--amber-dark); }
.btn.ghost {
  background: var(--white);
  color: var(--navy);
  box-shadow: var(--shadow-soft);
}
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.45; pointer-events: none; }

/* =========================
   Home
   ========================= */
.home-header {
  text-align: center;
  margin-top: 6px;
}
.logo-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.logo-wrap img {
  width: min(260px, 78vw);
  height: auto;
  animation: bob 3.2s ease-in-out infinite;
}
@keyframes bob { 0%,100% { transform: translateY(0) rotate(-1deg);} 50% { transform: translateY(-8px) rotate(1deg);} }
.tagline { color: var(--navy-soft); font-weight: 700; margin: 4px 0 18px; }

.mascot-bubble {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  box-shadow: var(--shadow-soft);
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}
.mascot-bubble img { width: 56px; height: 56px; flex-shrink: 0; }
.mascot-bubble p { margin: 0; font-weight: 700; color: var(--navy-soft); font-size: 15px; line-height: 1.35; overflow-wrap: anywhere; min-width: 0; flex: 1; }
.mascot-bubble img, .mascot-bubble .emoji { flex-shrink: 0; }

.home-actions { display: flex; flex-direction: column; gap: 14px; margin-top: 6px; }

.home-menu-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 16px;
}
.menu-card {
  background: var(--white);
  border-radius: var(--radius-md);
  padding: 16px 12px;
  text-align: center;
  box-shadow: var(--shadow-soft);
  border: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.menu-card:active { transform: scale(0.96); }
.menu-card .emoji { font-size: 30px; }
.menu-card .label { font-weight: 800; font-size: 14px; color: var(--navy); }

/* =========================
   Mapa de constelación
   ========================= */
.section-title {
  font-size: 26px;
  color: var(--navy);
  margin: 4px 0 4px;
}
.section-sub { color: var(--navy-soft); font-weight: 700; margin: 0 0 16px; font-size: 14px; }

.constellation-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  overflow-y: auto;
  padding-bottom: 20px;
}
.planet-card {
  position: relative;
  border: none;
  border-radius: var(--radius-lg);
  padding: 18px 10px 14px;
  cursor: pointer;
  color: var(--white);
  text-align: center;
  box-shadow: var(--shadow-soft);
  overflow: hidden;
}
.planet-card:active { transform: scale(0.96); }
.planet-card .num {
  font-size: 40px;
  line-height: 1;
  text-shadow: 2px 2px 0 rgba(0,0,0,0.12);
}
.planet-card .name { font-size: 13px; font-weight: 800; opacity: 0.95; margin-top: 2px; }
.planet-card .stars { margin-top: 8px; font-size: 16px; letter-spacing: 2px; }
.planet-card .badge {
  position: absolute;
  top: 8px; right: 8px;
  background: rgba(255,255,255,0.9);
  color: var(--navy);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  padding: 3px 8px;
}
.planet-card.locked { filter: grayscale(0.5); opacity: 0.55; }
.planet-card .progress-ring {
  position: absolute;
  bottom: 0; left: 0;
  height: 6px;
  background: rgba(255,255,255,0.85);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* =========================
   Menú de tabla
   ========================= */
.table-hero {
  text-align: center;
  padding: 22px 16px;
  border-radius: var(--radius-lg);
  color: var(--white);
  box-shadow: var(--shadow-soft);
  margin-bottom: 18px;
}
.table-hero .big-num { font-size: 56px; line-height: 1; text-shadow: 2px 2px 0 rgba(0,0,0,0.12); }
.table-hero .mastery-label { font-weight: 800; margin-top: 4px; }
.table-hero button.listen-all {
  margin-top: 12px;
  background: rgba(255,255,255,0.9);
  color: var(--navy);
  border: none;
  border-radius: 999px;
  padding: 10px 18px;
  font-weight: 800;
  font-family: var(--font-display);
  cursor: pointer;
}

.mode-list { display: flex; flex-direction: column; gap: 12px; }
.mode-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--white);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  box-shadow: var(--shadow-soft);
  border: none;
  cursor: pointer;
  text-align: left;
}
.mode-card:active { transform: scale(0.98); }
.mode-card .mode-emoji {
  width: 50px; height: 50px;
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px;
  flex-shrink: 0;
}
.mode-card .mode-text strong { display: block; font-size: 16px; color: var(--navy); }
.mode-card .mode-text span { font-size: 12.5px; color: var(--navy-soft); font-weight: 700; }

/* =========================
   Explorar (arreglo visual)
   ========================= */
.explorer-wrap { display: flex; flex-direction: column; align-items: center; flex: 1; }
.explorer-fact {
  font-size: 36px;
  font-weight: 800;
  color: var(--navy);
  margin: 10px 0 18px;
  text-align: center;
}
.array-box {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
  padding: 18px;
  display: grid;
  gap: 6px;
  justify-content: center;
  min-height: 190px;
  align-content: center;
  width: 100%;
  max-width: 340px;
}
.array-row { display: flex; gap: 6px; justify-content: center; }
.array-dot {
  width: 26px; height: 26px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px;
  animation: pop-in 0.25s ease backwards;
}
@keyframes pop-in { from { transform: scale(0); } to { transform: scale(1); } }

.explorer-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-top: 20px;
  width: 100%;
}
.explorer-controls .icon-btn.big-nav { width: 58px; height: 58px; font-size: 26px; }
.explorer-progress {
  font-weight: 800;
  color: var(--navy-soft);
  font-size: 14px;
}

/* =========================
   Lluvia de estrellas (arcade)
   ========================= */
.rain-stage {
  position: relative;
  flex: 1;
  background: linear-gradient(180deg, #2A2560 0%, #4B3F9E 55%, #6D5BC2 100%);
  border-radius: var(--radius-lg);
  overflow: hidden;
  min-height: 340px;
  margin-bottom: 16px;
}
.rain-stage .twinkle {
  position: absolute;
  width: 3px; height: 3px;
  background: #fff;
  border-radius: 50%;
  opacity: 0.7;
}
.falling-item {
  position: absolute;
  background: var(--white);
  border-radius: 16px;
  padding: 10px 16px;
  font-weight: 800;
  font-size: 20px;
  color: var(--navy);
  box-shadow: 0 4px 10px rgba(0,0,0,0.25);
  white-space: nowrap;
}
.rain-question-banner {
  position: absolute;
  top: 10px; left: 50%;
  transform: translateX(-50%);
  background: rgba(255,255,255,0.95);
  border-radius: 999px;
  padding: 8px 20px;
  font-weight: 800;
  font-size: 20px;
  color: var(--navy);
  box-shadow: var(--shadow-soft);
}
.rain-hud {
  display: flex;
  justify-content: space-between;
  margin-bottom: 10px;
  font-weight: 800;
  color: var(--navy);
}
.rain-lives span { font-size: 18px; margin-left: 2px; }

/* =========================
   Memorama
   ========================= */
.memory-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  flex: 1;
  align-content: start;
}
.memory-card {
  aspect-ratio: 1;
  border-radius: 12px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800;
  font-size: 15px;
  color: var(--white);
  background: var(--purple);
  box-shadow: 0 4px 0 var(--purple-dark);
  text-align: center;
  padding: 4px;
}
.memory-card.flipped { background: var(--white); color: var(--navy); box-shadow: var(--shadow-soft); }
.memory-card.matched { background: var(--success); color: var(--white); box-shadow: 0 4px 0 #2a9b5e; opacity: 0.85; }
.memory-card.wrong-flash { background: var(--error) !important; }

/* =========================
   Desafío adaptativo
   ========================= */
.challenge-wrap { display: flex; flex-direction: column; flex: 1; }
.timer-bar-track {
  height: 10px;
  border-radius: 999px;
  background: var(--white);
  box-shadow: var(--shadow-soft);
  overflow: hidden;
  margin-bottom: 18px;
}
.timer-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--mint), var(--blue));
  border-radius: 999px;
  transition: width 0.1s linear;
}
.challenge-question {
  text-align: center;
  font-size: 46px;
  font-weight: 800;
  color: var(--navy);
  margin: 20px 0 26px;
}
.challenge-answers {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.answer-btn {
  border: none;
  border-radius: var(--radius-md);
  background: var(--white);
  box-shadow: 0 5px 0 #d9d4ea;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 26px;
  padding: 22px 10px;
  color: var(--navy);
  cursor: pointer;
}
.answer-btn:active { transform: translateY(4px); box-shadow: 0 1px 0 #d9d4ea; }
.answer-btn.correct { background: var(--success); color: var(--white); box-shadow: 0 5px 0 #2a9b5e; }
.answer-btn.wrong { background: var(--error); color: var(--white); box-shadow: 0 5px 0 #c94d4d; }

.challenge-progress-row {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-bottom: 6px;
}
.qdot { width: 10px; height: 10px; border-radius: 50%; background: #E4E0F5; }
.qdot.done { background: var(--mint); }
.qdot.current { background: var(--purple); transform: scale(1.3); }

/* =========================
   Resultados
   ========================= */
.results-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.results-wrap img.mascot-big { width: 130px; margin-bottom: 6px; animation: celebrate 0.7s ease; }
@keyframes celebrate { 0% { transform: scale(0.5) rotate(-10deg); } 60% { transform: scale(1.15) rotate(8deg);} 100% { transform: scale(1) rotate(0);} }
.results-title { font-size: 30px; color: var(--navy); margin: 0 0 6px; }
.results-stats {
  display: flex;
  gap: 12px;
  margin: 18px 0;
  flex-wrap: wrap;
  justify-content: center;
}
.results-stat {
  background: var(--white);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-soft);
  padding: 14px 18px;
  min-width: 92px;
}
.results-stat .val { font-size: 26px; font-weight: 800; color: var(--purple); }
.results-stat .lbl { font-size: 12px; font-weight: 700; color: var(--navy-soft); }
.confetti-layer { position: fixed; inset: 0; pointer-events: none; z-index: 5; }

/* =========================
   Ajustes
   ========================= */
.settings-list { display: flex; flex-direction: column; gap: 14px; }
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--white);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  box-shadow: var(--shadow-soft);
}
.settings-row .label { font-weight: 800; font-size: 15px; }
.settings-row .desc { font-weight: 600; font-size: 12px; color: var(--navy-soft); margin-top: 2px; }

.switch { position: relative; width: 54px; height: 30px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute; inset: 0; background: #D8D4EE; border-radius: 999px; cursor: pointer; transition: 0.2s;
}
.switch .track::before {
  content: ""; position: absolute; width: 24px; height: 24px; border-radius: 50%;
  left: 3px; top: 3px; background: var(--white); box-shadow: 0 2px 4px rgba(0,0,0,0.2); transition: 0.2s;
}
.switch input:checked + .track { background: var(--mint); }
.switch input:checked + .track::before { transform: translateX(24px); }

.range-row { display: flex; align-items: center; gap: 10px; }
.range-row select {
  font-family: var(--font-display);
  font-weight: 800;
  border-radius: 10px;
  border: 2px solid var(--lavender);
  padding: 8px 10px;
  font-size: 15px;
  color: var(--navy);
}

/* =========================
   Utilidades
   ========================= */
.spacer { flex: 1; }
.center-col { display: flex; flex-direction: column; align-items: center; }
.hidden { display: none !important; }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--navy);
  color: var(--white);
  padding: 12px 20px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 14px;
  box-shadow: var(--shadow-soft);
  z-index: 50;
  opacity: 0;
  transition: 0.25s ease;
  pointer-events: none;
  max-width: 90%;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.shake { animation: shake 0.4s ease; }
@keyframes shake {
  10%, 90% { transform: translateX(-3px); }
  20%, 80% { transform: translateX(6px); }
  30%, 50%, 70% { transform: translateX(-10px); }
  40%, 60% { transform: translateX(10px); }
}

.pulse { animation: pulse 0.9s ease infinite; }
@keyframes pulse { 0%,100% { transform: scale(1);} 50% { transform: scale(1.06);} }

@media (min-width: 420px) {
  .constellation-grid { grid-template-columns: repeat(3, 1fr); }
}

/* Cuenta / registro / login */
.error-msg { color: #D6336C; font-weight: 700; text-align: center; font-size: 14px; margin: 8px 0; }

.avatar-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.avatar-option {
  width: 52px; height: 52px;
  border-radius: 14px;
  border: 3px solid transparent;
  background: var(--white);
  box-shadow: var(--shadow-soft);
  font-size: 24px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.avatar-option.selected { border-color: var(--purple); transform: scale(1.08); }

.profile-tile {
  background: var(--white);
  border: none;
  border-radius: var(--radius-lg);
  padding: 22px 10px;
  text-align: center;
  box-shadow: var(--shadow-soft);
  cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.profile-tile .avatar-big { font-size: 44px; }
.profile-tile .pname { font-weight: 800; color: var(--navy); }
.profile-tile .pstars { font-size: 12.5px; color: var(--navy-soft); font-weight: 700; }
.profile-tile.add-tile { border: 3px dashed var(--lavender); box-shadow: none; color: var(--navy-soft); }

.record-card {
  background: var(--white);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-soft);
}
.record-card .rc-title { font-weight: 800; font-size: 15px; margin-bottom: 6px; }
.record-card .rc-row { display: flex; justify-content: space-between; font-size: 13.5px; color: var(--navy-soft); font-weight: 700; padding: 3px 0; }
.record-card .rc-row b { color: var(--navy); }

.milestone-banner {
  background: linear-gradient(160deg, #FFE9F2, #FFF3D6);
  border-radius: var(--radius-lg);
  padding: 18px;
  margin-top: 16px;
  text-align: center;
  box-shadow: var(--shadow-soft);
}
.milestone-banner p { font-weight: 700; color: var(--navy); margin: 6px 0 14px; }

/* Loading */
#screen-loading { align-items: center; justify-content: center; text-align: center; }
#screen-loading .loading-logo { width: min(280px, 74vw); height: auto; animation: bob 1.6s ease-in-out infinite; }
