/* ─── Reset y base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --luna-morado:    #5B3FD4;
  --luna-morado-lt: #7C62E3;
  --luna-morado-bg: #EDE9FF;
  --luna-naranja:   #F97316;
  --luna-verde:     #16A34A;
  --luna-amarillo:  #FCD34D;
  --bg:             #F5F3FF;
  --blanco:         #FFFFFF;
  --texto:          #1E1B2E;
  --texto-suave:    #6B6880;
  --borde:          #DDD8F5;
  --radio:          16px;
  --radio-burbuja:  20px;
  --sombra:         0 2px 12px rgba(91,63,212,0.10);
}

html, body {
  height: 100%;
  font-family: 'Nunito', 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--texto);
  overflow: hidden;
}

/* ─── Layout principal: ocupa toda la pantalla ──────────────── */
#app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100vh;
  max-width: 900px;
  margin: 0 auto;
  background: var(--blanco);
  box-shadow: var(--sombra);
}

/* ─── Header ────────────────────────────────────────────────── */
#header {
  background: var(--luna-morado);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 14px;
}

#luna-avatar {
  width: 52px; height: 52px;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  border: 2px solid rgba(255,255,255,0.35);
  display: flex; align-items: center; justify-content: center;
  font-size: 28px;
  flex-shrink: 0;
  animation: flotando 3s ease-in-out infinite;
}

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

#header-info h1 {
  color: #fff;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.3px;
}
#header-info p {
  color: rgba(255,255,255,0.75);
  font-size: 13px;
  margin-top: 1px;
}

#cap-badge {
  margin-left: auto;
  background: rgba(255,255,255,0.18);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 20px;
  text-align: center;
  line-height: 1.4;
  flex-shrink: 0;
}

/* ─── Área de chat ───────────────────────────────────────────── */
#chat {
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}

/* Mensajes */
.msg {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  animation: aparecer 0.25s ease;
}
.msg.luna  { flex-direction: row; }
.msg.nino  { flex-direction: row-reverse; }

@keyframes aparecer {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.av {
  width: 34px; height: 34px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.av.luna-av { background: var(--luna-morado); }
.av.nino-av { background: var(--luna-morado-bg); font-size: 14px; font-weight: 700; color: var(--luna-morado); }

.burbuja {
  max-width: 72%;
  padding: 12px 16px;
  font-size: 15px;
  line-height: 1.65;
  border-radius: var(--radio-burbuja);
}
.luna .burbuja {
  background: #F3F0FF;
  border: 0.5px solid var(--borde);
  border-bottom-left-radius: 4px;
  color: var(--texto);
}
.nino .burbuja {
  background: var(--luna-morado);
  color: #fff;
  border-bottom-right-radius: 4px;
}

/* Tarjeta de imagen */
.img-card {
  border-radius: var(--radio);
  overflow: hidden;
  border: 0.5px solid var(--borde);
  background: #FAFAFA;
  max-width: 92%;
}
.img-card img {
  width: 100%;
  max-height: 480px;
  object-fit: contain; /* la imagen es una historia en 3 partes: no recortar */
  background: #FAFAFA;
  display: block;
}
.img-card .img-label {
  padding: 8px 14px;
  font-size: 12px;
  color: var(--texto-suave);
}

/* Guía de partes */
.guia-partes {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}
.parte {
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
}
.parte.primero { background: #EDE9FF; color: #5B3FD4; }
.parte.luego   { background: #FFF3E0; color: #C2410C; }
.parte.final   { background: #DCFCE7; color: #15803D; }
.parte.done    { opacity: 0.4; text-decoration: line-through; }

/* Typing */
#typing {
  display: none;
  align-items: center;
  gap: 10px;
}
.dots-wrap {
  background: #F3F0FF;
  border: 0.5px solid var(--borde);
  padding: 12px 16px;
  border-radius: 20px 20px 20px 4px;
  display: flex; gap: 5px;
}
.dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--luna-morado);
  opacity: 0.4;
  animation: rebote 1.2s infinite;
}
.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes rebote {
  0%,80%,100% { transform: translateY(0); opacity: 0.4; }
  40%         { transform: translateY(-6px); opacity: 1; }
}

/* ─── Panel inferior: solo micrófono (competencia ORAL) ─────────── */
#bottom {
  border-top: 0.5px solid var(--borde);
  background: var(--blanco);
  padding: 22px 24px 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

#voz-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

#btn-voz {
  width: 84px; height: 84px;
  border-radius: 50%;
  background: var(--luna-morado);
  border: none;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  font-size: 34px;
  box-shadow: 0 6px 18px rgba(91,63,212,0.30);
  transition: background 0.15s, transform 0.1s;
}
#btn-voz:hover    { background: var(--luna-morado-lt); }
#btn-voz:active   { transform: scale(0.96); }
#btn-voz.grabando { background: #EF4444; animation: pulso 1s infinite; }
#btn-voz:disabled { background: var(--borde); cursor: not-allowed; box-shadow: none; }
@keyframes pulso {
  0%,100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.35); }
  50%     { box-shadow: 0 0 0 14px rgba(239,68,68,0); }
}

#estado-voz {
  font-size: 14px;
  font-weight: 600;
  color: var(--texto-suave);
  text-align: center;
}

/* ─── Pantalla de bloqueo: navegador sin reconocimiento de voz ──── */
#sin-voz {
  position: fixed; inset: 0;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  z-index: 50;
}
#sin-voz .caja {
  max-width: 440px;
  text-align: center;
  background: var(--blanco);
  border-radius: 20px;
  padding: 40px 32px;
  box-shadow: var(--sombra);
}
#sin-voz .icono { font-size: 48px; margin-bottom: 16px; }
#sin-voz h2 { font-size: 20px; color: var(--luna-morado); margin-bottom: 12px; }
#sin-voz p  { font-size: 15px; color: var(--texto-suave); line-height: 1.6; }

/* ─── Botón reutilizable (mismo estilo que index.html) ──────────── */
.btn-iniciar {
  display: inline-block;
  background: var(--luna-morado);
  color: #fff;
  font-size: 17px;
  font-weight: 700;
  font-family: inherit;
  padding: 14px 36px;
  border-radius: 28px;
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, transform 0.1s;
  box-shadow: 0 4px 14px rgba(91,63,212,0.25);
}
.btn-iniciar:hover  { background: var(--luna-morado-lt); }
.btn-iniciar:active { transform: scale(0.97); }

/* ─── Pantalla de cierre: se muestra al completar la sesión ─────── */
#pantalla-cierre {
  position: fixed; inset: 0;
  z-index: 60;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  padding: 5vh 6vw;
  background: #1E1B2E;
  animation: aparecer 0.4s ease;
}
#pantalla-cierre img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
}
#pantalla-cierre::before {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(90deg, rgba(30,27,46,0) 40%, rgba(30,27,46,0.35) 100%);
}
#pantalla-cierre .tarjeta-cierre {
  position: relative;
  z-index: 1;
  max-width: 360px;
  text-align: center;
  background: rgba(255,255,255,0.94);
  backdrop-filter: blur(6px);
  border-radius: 24px;
  padding: 32px 28px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.30);
}
#pantalla-cierre .tarjeta-cierre h2 {
  color: var(--luna-morado);
  font-size: 24px;
  font-weight: 800;
  margin-bottom: 8px;
  line-height: 1.3;
}
#pantalla-cierre .tarjeta-cierre p {
  color: var(--luna-naranja);
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 22px;
}
#pantalla-cierre .tarjeta-cierre .btn-iniciar {
  width: 100%;
}

@media (max-width: 720px) {
  #pantalla-cierre { align-items: flex-end; justify-content: center; padding: 0 20px 32px; }
  #pantalla-cierre .tarjeta-cierre { max-width: 100%; }
}
