/* ──────────────────────────────────────────────────────────────────────
   Lumi · Sofía — design system
   Paleta cálida + tipografías Nunito/Fredoka, tomadas del diseño definitivo
   (design/Sofia.html). Personaje "Sofía" con estados de ánimo + tab bar para
   las secciones Hablar / Actividades / Canciones.
   ────────────────────────────────────────────────────────────────────── */

:root {
  --cream:      #FBF6EF;
  --cream-2:    #F4ECE0;
  --surface:    #FFFFFF;
  --ink:        #463B30;
  --muted:      #A89A89;
  --hairline:   rgba(70, 59, 48, 0.08);

  --s1:         #FFB492;
  --s2:         #FF9472;
  --s3:         #F8804F;
  --coral:      #FF9472;
  --coral-deep: #F4744E;
  --coral-soft: #FFD9C9;
  --halo:       rgba(255, 148, 114, 0.30);
  --mint:       #74C9BE;
  --mint-soft:  #D7F0EC;
  --cheek:      #FFB7B0;
  --shadow-1:   rgba(244, 116, 78, 0.34);
  --shadow-2:   rgba(214, 90, 52, 0.30);

  --good:       #6FBE7E;
  --good-soft:  #DDF0DE;

  --font-ui:      'Nunito', system-ui, -apple-system, sans-serif;
  --font-display: 'Fredoka', 'Nunito', system-ui, sans-serif;
}

/* ── reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: var(--font-ui);
  background: #E9E2D6;
  background-image: radial-gradient(120% 80% at 50% -10%, #F3EADC 0%, #E6DDCF 60%, #DED4C4 100%);
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  color: var(--ink);
}
button { font-family: inherit; }

/* ── app shell ── */
.app {
  width: 100%;
  max-width: 480px;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: radial-gradient(125% 70% at 50% 8%, var(--cream) 0%, var(--cream) 55%, var(--cream-2) 100%);
  position: relative;
  overflow: hidden;
  box-shadow: 0 0 60px rgba(70, 59, 48, 0.08);
}

.ambient { position: absolute; border-radius: 50%; filter: blur(34px); opacity: 0.5; pointer-events: none; z-index: 0; }
.ambient.a1 { width: 220px; height: 220px; top: 64px; left: -70px; background: var(--coral-soft); }
.ambient.a2 { width: 190px; height: 190px; bottom: 220px; right: -64px; background: var(--mint-soft); }

/* ── shared topbar ── */
.topbar {
  position: relative;
  z-index: 4;
  padding: max(28px, env(safe-area-inset-top)) 22px 4px;
  flex-shrink: 0;
}
.topbar .greet { display: flex; align-items: center; gap: 9px; }
.topbar .wave { font-size: 22px; display: inline-block; transform-origin: 70% 70%; animation: wave 3.4s ease-in-out infinite; }
.topbar .gtext { line-height: 1.05; }
.topbar .ghi { font-family: var(--font-display); font-weight: 600; font-size: 20px; color: var(--ink); }
.topbar .gsub { font-size: 12.5px; font-weight: 700; color: var(--muted); letter-spacing: 0.2px; }

/* ── screens ── */
.screens { flex: 1; position: relative; z-index: 2; min-height: 0; }
.screen {
  position: absolute; inset: 0;
  display: none;
  flex-direction: column;
  min-height: 0;
}
.screen.active { display: flex; }
.screen-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* ═══════════════════════════════════════════════════════════════════════
   Pantalla "Hablar" — Sofía
   ═══════════════════════════════════════════════════════════════════════ */

.stage {
  position: relative;
  z-index: 3;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  padding: 0 24px;
  cursor: pointer;
  min-height: 0;
}

.sofia-wrap { position: relative; width: 240px; height: 240px; display: flex; align-items: center; justify-content: center; }

.halo {
  position: absolute;
  width: 240px; height: 240px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--halo) 0%, rgba(255,255,255,0) 68%);
  transition: transform .6s ease, opacity .6s ease, background .6s ease;
}
.mood-listening .halo { background: radial-gradient(circle, rgba(116,201,190,0.34) 0%, rgba(116,201,190,0) 68%); transform: scale(1.12); }
.mood-speaking  .halo { transform: scale(1.08); }

.rings { position: absolute; width: 240px; height: 240px; display: none; }
.mood-listening .rings { display: block; }
.ring {
  position: absolute; inset: 0; margin: auto;
  width: 168px; height: 168px;
  border-radius: 50%;
  border: 2px solid var(--mint);
  opacity: 0;
  animation: ringPulse 2.4s ease-out infinite;
}
.ring:nth-child(2) { animation-delay: .8s; }
.ring:nth-child(3) { animation-delay: 1.6s; }

.sofia-float { animation: float 5.5s ease-in-out infinite; will-change: transform; }
.mood-listening .sofia-float { animation-duration: 3.4s; }

.sofia-body {
  position: relative;
  width: 168px; height: 168px;
  border-radius: 49% 51% 47% 53% / 52% 48% 53% 47%;
  background: linear-gradient(155deg, var(--s1) 0%, var(--s2) 46%, var(--s3) 100%);
  box-shadow:
    0 20px 40px var(--shadow-1),
    inset 0 -12px 26px var(--shadow-2),
    inset 0 10px 20px rgba(255,255,255,0.34);
  animation: blob 9s ease-in-out infinite;
  transition: transform .35s cubic-bezier(.3,1.4,.5,1), background .6s ease, box-shadow .6s ease;
}
.mood-listening .sofia-body { transform: scale(1.04); }
.mood-thinking  .sofia-body { transform: rotate(-3deg); }

.sofia-body::before {
  content: '';
  position: absolute;
  top: 18px; left: 26px;
  width: 54px; height: 40px;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, rgba(255,255,255,0.7), rgba(255,255,255,0) 70%);
  filter: blur(2px);
}

.face { position: absolute; inset: 0; }
.eyes { position: absolute; top: 64px; left: 0; right: 0; display: flex; justify-content: center; gap: 30px; }
.eye {
  width: 21px; height: 27px;
  background: #43342A;
  border-radius: 50%;
  position: relative;
  animation: blink 5.2s infinite;
  transition: height .25s ease, border-radius .25s ease, transform .25s ease;
}
.eye::after {
  content: '';
  position: absolute;
  top: 5px; right: 4px;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: rgba(255,255,255,0.92);
}
.mood-listening .eye { height: 30px; transform: translateY(-1px); }
.mood-speaking .eye, .mood-playing .eye {
  height: 15px;
  background: transparent;
  border-bottom: 6px solid #43342A;
  border-radius: 0 0 24px 24px;
  animation: none;
}
.mood-speaking .eye::after, .mood-playing .eye::after { display: none; }

.cheek {
  position: absolute;
  top: 92px;
  width: 22px; height: 14px;
  border-radius: 50%;
  background: var(--cheek);
  opacity: 0.55;
  filter: blur(0.5px);
  transition: opacity .3s ease, transform .3s ease, background .6s ease;
}
.cheek.l { left: 30px; }
.cheek.r { right: 30px; }
.mood-speaking .cheek, .mood-playing .cheek { opacity: 0.85; transform: scale(1.1); }

.mouth {
  position: absolute;
  top: 104px; left: 50%;
  transform: translateX(-50%);
  width: 30px; height: 16px;
  border-bottom: 6px solid #43342A;
  border-radius: 0 0 30px 30px;
  transition: all .25s ease;
}
.mood-listening .mouth { width: 18px; height: 18px; border: 5px solid #43342A; border-radius: 50%; }
.mood-thinking  .mouth { width: 20px; height: 6px; border-bottom-width: 5px; border-radius: 8px; }
.mood-speaking  .mouth, .mood-playing .mouth {
  width: 30px; height: 26px;
  border: none;
  background: #4A372B;
  border-radius: 50% 50% 50% 50% / 38% 38% 62% 62%;
  animation: talk .42s ease-in-out infinite;
}
.mood-speaking .mouth::after, .mood-playing .mouth::after {
  content: '';
  position: absolute;
  bottom: 3px; left: 50%; transform: translateX(-50%);
  width: 16px; height: 9px;
  background: var(--cheek);
  border-radius: 50%;
}

/* ── caption / bubble ── */
.caption {
  position: relative;
  z-index: 3;
  text-align: center;
  margin-top: 6px;
  min-height: 58px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 3px;
  padding: 0 24px;
  flex-shrink: 0;
}
.caption .c-es { font-family: var(--font-display); font-weight: 600; font-size: 23px; color: var(--ink); letter-spacing: 0.2px; }
.caption .c-en { font-size: 13.5px; font-weight: 700; color: var(--muted); letter-spacing: 0.3px; }
.caption .c-es.heard { font-size: 18px; font-weight: 600; font-style: italic; color: var(--muted); }
.caption .thinking-label { font-size: 15px; font-weight: 800; color: var(--muted); letter-spacing: 0.2px; margin-bottom: 2px; }

.dots { display: inline-flex; gap: 7px; padding: 6px 0; }
.dots i { width: 11px; height: 11px; border-radius: 50%; background: var(--coral); display: inline-block; animation: dot 1.2s ease-in-out infinite; }
.dots i:nth-child(2) { animation-delay: .18s; }
.dots i:nth-child(3) { animation-delay: .36s; }

.bubble {
  display: inline-flex;
  align-items: center;
  gap: 13px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 26px;
  padding: 11px 20px 11px 13px;
  box-shadow: 0 10px 28px rgba(70,59,48,0.10);
  animation: pop .42s cubic-bezier(.2,1.5,.4,1) both;
  max-width: 100%;
}
.bubble .emoji {
  width: 46px; height: 46px;
  border-radius: 50%;
  background: var(--cream-2);
  display: flex; align-items: center; justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
}
.bubble .btext { text-align: left; line-height: 1.32; min-width: 0; }
.bubble .b-es { font-family: var(--font-display); font-weight: 600; font-size: 17px; color: var(--ink); }

/* ── mic dock ── */
.dock {
  position: relative;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 14px 0 calc(18px + env(safe-area-inset-bottom));
  flex-shrink: 0;
}
.mic-btn {
  position: relative;
  width: 92px; height: 92px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: linear-gradient(160deg, var(--s1) 0%, var(--s2) 50%, var(--s3) 100%);
  box-shadow: 0 12px 26px rgba(244,116,78,0.40), inset 0 2px 4px rgba(255,255,255,0.4);
  display: flex; align-items: center; justify-content: center;
  transition: transform .22s cubic-bezier(.3,1.5,.4,1), background .2s ease, box-shadow .2s ease;
}
.mic-btn:active { transform: scale(0.93); }
.mood-listening .mic-btn {
  background: linear-gradient(160deg, #8AD6CC 0%, #74C9BE 55%, #54B0A4 100%);
  box-shadow: 0 12px 26px rgba(116,201,190,0.46), inset 0 2px 4px rgba(255,255,255,0.4);
}
.mood-thinking .mic-btn, .mood-speaking .mic-btn {
  background: linear-gradient(160deg, #E3DCD0 0%, #D8CFC0 55%, #C9BEAC 100%);
  box-shadow: 0 8px 18px rgba(70,59,48,0.16), inset 0 2px 4px rgba(255,255,255,0.3);
  cursor: default;
}

/* ── mood "playing": Sofía canta/escucha un cuento; el mic se vuelve "terminar" ── */
.mood-playing .halo {
  background: radial-gradient(circle, rgba(255,200,87,0.36) 0%, rgba(255,200,87,0) 68%);
  transform: scale(1.1);
}
.mood-playing .sofia-float { animation-duration: 1.4s; }
.mood-playing .sofia-body { transform: scale(1.03); }
.mood-playing .mic-btn {
  background: linear-gradient(160deg, #FFDD8A 0%, #FFC857 55%, #F4A93F 100%);
  box-shadow: 0 12px 26px rgba(244,169,63,0.46), inset 0 2px 4px rgba(255,255,255,0.4);
}
.mood-playing .mic-btn::before { border-color: #FFC857; animation: micPulse 1.6s ease-out infinite; }
.mic-btn::before {
  content: '';
  position: absolute; inset: 0;
  border-radius: 50%;
  border: 3px solid var(--mint);
  opacity: 0;
}
.mood-listening .mic-btn::before { animation: micPulse 1.6s ease-out infinite; }

/* ── mood "asking": Sofía espera la respuesta del juego de aprender ── */
.mood-asking .halo {
  background: radial-gradient(circle, rgba(116,201,190,0.30) 0%, rgba(116,201,190,0) 68%);
  animation: haloPulse 2.4s ease-in-out infinite;
}
.mood-asking .bubble .emoji {
  width: 84px; height: 84px;
  font-size: 48px;
}

.dock .hint { font-size: 14px; font-weight: 800; color: var(--muted); letter-spacing: 0.2px; min-height: 18px; }

/* ── error banner ── */
.error-banner {
  display: none;
  position: relative; z-index: 5;
  margin: 0 22px;
  background: #ffe0e0;
  border: 1px solid #ffaaaa;
  border-radius: 12px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 700;
  color: #c00;
  text-align: center;
}
.error-banner.show { display: block; }

.section-head { padding: 4px 22px 10px; flex-shrink: 0; position: relative; z-index: 3; }
.section-head .ghi { font-family: var(--font-display); font-weight: 600; font-size: 20px; color: var(--ink); }
.section-head .gsub { font-size: 12.5px; font-weight: 700; color: var(--muted); letter-spacing: 0.4px; }

/* ═══════════════════════════════════════════════════════════════════════
   Overlays (Panel de padres) — panel contextual sobre Sofía
   ═══════════════════════════════════════════════════════════════════════ */

.overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--cream);
  transform: translateY(100%);
  transition: transform .3s ease;
}
.overlay.show { transform: translateY(0); }

.overlay-close {
  position: absolute;
  top: max(18px, env(safe-area-inset-top));
  right: 18px;
  z-index: 5;
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 1px solid var(--hairline);
  background: var(--surface);
  color: var(--ink);
  font-size: 15px;
  font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(70,59,48,0.08);
}
.overlay-close:active { transform: scale(0.93); }

/* ── botón discreto del panel de padres (mantener presionado para abrir) ── */
.parent-gate {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  right: 14px;
  z-index: 5;
  width: 34px; height: 34px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.5);
  color: var(--muted);
  font-size: 15px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  opacity: 0.55;
  transition: transform .15s ease, opacity .15s ease;
}
.parent-gate:active { transform: scale(0.9); opacity: 0.9; }

/* ═══════════════════════════════════════════════════════════════════════
   Panel de padres
   ═══════════════════════════════════════════════════════════════════════ */
.parent-body { padding: 4px 22px 28px; display: flex; flex-direction: column; gap: 14px; }

.parent-summary {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 18px;
  padding: 14px 16px;
  font-size: 14px;
  color: var(--ink);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.parent-chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.parent-chip {
  display: inline-flex;
  align-items: center;
  background: var(--cream-2);
  border-radius: 14px;
  padding: 4px 10px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--ink);
}
.parent-chip-active { background: var(--mint-soft); align-self: flex-start; }
.parent-titles { font-size: 13px; color: var(--muted); }

.parent-section-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
  color: var(--ink);
}

.parent-log { display: flex; flex-direction: column; gap: 10px; }
.parent-entry {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 16px;
  padding: 10px 14px;
  font-size: 13.5px;
  line-height: 1.4;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.parent-entry.blocked { border-color: var(--coral-soft); background: #FFF6F2; }
.parent-entry-time { font-size: 11.5px; font-weight: 800; color: var(--muted); letter-spacing: 0.3px; }
.parent-entry-said { color: var(--ink); font-weight: 600; }
.parent-entry-reply { color: var(--muted); }
.parent-entry-badge {
  align-self: flex-start;
  margin-top: 2px;
  font-size: 11px;
  font-weight: 800;
  color: var(--coral-deep);
  background: var(--coral-soft);
  border-radius: 10px;
  padding: 2px 8px;
}

/* ── keyframes ── */
@keyframes float { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-12px); } }
@keyframes blob {
  0%,100% { border-radius: 49% 51% 47% 53% / 52% 48% 53% 47%; }
  50%     { border-radius: 53% 47% 52% 48% / 47% 53% 48% 52%; }
}
@keyframes blink {
  0%, 92%, 100% { transform: scaleY(1); }
  95% { transform: scaleY(0.1); }
}
@keyframes wave {
  0%, 60%, 100% { transform: rotate(0deg); }
  70% { transform: rotate(16deg); }
  80% { transform: rotate(-8deg); }
  90% { transform: rotate(12deg); }
}
@keyframes talk {
  0%,100% { transform: translateX(-50%) scaleY(0.5); }
  50%     { transform: translateX(-50%) scaleY(1); }
}
@keyframes dot { 0%,100% { transform: translateY(0); opacity: .5; } 50% { transform: translateY(-7px); opacity: 1; } }
@keyframes pop { 0% { transform: scale(0.7); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
@keyframes ringPulse {
  0% { transform: scale(0.7); opacity: 0.7; }
  100% { transform: scale(1.4); opacity: 0; }
}
@keyframes micPulse {
  0% { transform: scale(1); opacity: 0.8; }
  100% { transform: scale(1.55); opacity: 0; }
}
@keyframes haloPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

@media (prefers-reduced-motion: reduce) {
  .sofia-float, .sofia-body, .eye, .topbar .wave, .mouth, .ring, .mic-btn::before,
  .mood-asking .halo { animation: none !important; }
}
