/* =========================================================
   Reproductor de cuentos (pantalla completa, para tablet)
   Usa los colores y tipografías de estilos.css
   ========================================================= */
html, body.cuento { height: 100%; }
/* Lectura: el fondo más limpio de toda la web, para que mande la historia */
body[data-cielo="lectura"] { --cielo-arriba: #FFF8EE; --cielo-abajo: #FFFDF8; }
body[data-cielo="lectura"]::before { display: none; }
body.cuento {
  display: flex; flex-direction: column;
  min-height: 100%;
  overflow-x: hidden;
}

/* Barra superior */
.cuento-barra {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px var(--margen);
}
.cuento-barra .grupo { display: flex; gap: 10px; align-items: center; }
.icono-boton {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-width: 52px; min-height: 52px; padding: 8px 16px;
  font: inherit; font-weight: 700; font-size: 1rem;
  color: var(--tinta); text-decoration: none;
  background: var(--pildora, #fff); border: 0; border-radius: 999px; cursor: pointer;
  box-shadow: inset 0 0 0 1px var(--borde), 0 10px 24px -18px rgba(29,42,77,.45);
}
.icono-boton[hidden] { display: none; }
.icono-boton:hover { background: var(--cielo-2); }
.icono-boton:active { transform: translateY(2px); box-shadow: none; }
.icono-boton svg { width: 24px; height: 24px; flex: none; }
.icono-boton[aria-pressed="false"] .on, .icono-boton[aria-pressed="true"] .off { display: none; }

/* Barra de progreso: un tramo por escena */
.progreso { list-style: none; display: flex; gap: 4px; margin: 0; padding: 0; flex: 1; max-width: 420px; }
.progreso li { flex: 1; height: 14px; border-radius: 7px; background: var(--cielo-2); transition: background .6s ease; }
.progreso li.hecho { background: var(--acento); }
.progreso li.ahora { background: color-mix(in srgb, var(--acento) 45%, var(--cielo-2)); }

/* Móvil pequeño: los botones de arriba caben todos (antes «Para el adulto» se salía) */
@media (max-width: 440px) {
  .cuento-barra { gap: 6px; padding-inline: 10px; }
  .cuento-barra .grupo { gap: 5px; }
  .cuento-barra .icono-boton { min-width: 44px; min-height: 44px; padding: 6px; }
  .cuento-barra .icono-boton svg { width: 22px; height: 22px; }
  .cuento-barra .idioma-boton { height: 44px; }
}
/* Móviles muy estrechos (320-350 px): un poco más juntos para que quepan los seis */
@media (max-width: 350px) {
  .cuento-barra { gap: 4px; padding-inline: 6px; }
  .cuento-barra .grupo { gap: 3px; }
  .cuento-barra .icono-boton, .cuento-barra .tema-boton { min-width: 40px; width: auto; min-height: 40px; padding: 5px; }
  .cuento-barra .idioma-boton { height: 40px; }
}
/* En móviles la barra de progreso no cabe junto a los seis botones */
@media (max-width: 400px) {
  .cuento-barra .progreso { display: none; }
}
@media (max-width: 560px) {
  .icono-boton .texto-boton { display: none; }
  .icono-boton { padding: 8px; }
  .progreso { gap: 3px; }
  .progreso li { height: 12px; }
}

/* Escenario */
.escena {
  --tinte: var(--alegria);
  position: relative; flex: 1; min-height: 300px;
  margin: 0 var(--margen);
  border-radius: var(--r-l); border: 1px solid var(--border-color); overflow: hidden;
  background: radial-gradient(120% 100% at 50% 0%, color-mix(in srgb, var(--tinte) 50%, #ffffff) 0%, #FFFDF8 75%);
  transition: background .8s;
}
/* El escenario del cuento siempre es de día, también en modo oscuro */
.escena {
  --cielo: #FFF8EE; --cielo-2: #FFF0C7; --papel: #FFFCF5; --pildora: #FFFCF5;
  --tinta: #38251F; --tinta-2: #82543C; --borde: #38251F; --foco: #8A4A1F;
  --sol: var(--naranja); --sol-hover: #F6B063; --sobre-sol: #38251F; --enlace: #8A4A1F;
  color: var(--tinta);
}

.suelo { position: absolute; left: -5%; right: -5%; bottom: 0; height: 16%; background: var(--calma); border-top: 2px solid #38251F; border-radius: 50% 50% 0 0 / 40% 40% 0 0; }

.actor {
  position: absolute; background: none; border: 0; padding: 0; cursor: pointer;
  -webkit-tap-highlight-color: transparent; border-radius: 24px;
}
.actor:disabled { cursor: default; }
.actor svg { width: 100%; height: auto; overflow: visible; }

#actor-nina {
  width: min(44%, 52vh, 400px); left: 50%; bottom: 12%;
  transform: translateX(-62%) scale(var(--escala, 1)); transform-origin: 50% 85%;
  transition: transform .6s ease-in-out;
}
#actor-torre { width: min(12%, 14vh, 110px); right: 9%; bottom: 15.5%; }
#actor-sol { width: min(15%, 18vh, 140px); left: 6%; top: 7%; transition: left 1s ease-in-out, top 1s ease-in-out; }
#actor-sol.abrazando { left: 34%; top: 30%; }

/* Señal de "tócame" */
.actor.llama::after {
  content: ""; position: absolute; inset: -8%; border-radius: 50%;
  border: 4px solid var(--foco); opacity: 0; pointer-events: none;
}
@media (prefers-reduced-motion: no-preference) { .actor.llama::after { animation: llamar 1.6s ease-out infinite; } }
@media (prefers-reduced-motion: reduce) { .actor.llama::after { opacity: .8; } }
@keyframes llamar { 0% { transform: scale(.85); opacity: .9; } 100% { transform: scale(1.15); opacity: 0; } }

/* Torre de gotitas */
#actor-torre .gotas { transform-origin: 50% 100%; transition: transform .7s cubic-bezier(.5,-0.3,.7,1), opacity .7s; }
#actor-torre.cae .gotas { transform: rotate(80deg) translateY(-10%); opacity: 0; }
.gota { transition: opacity .3s; }

/* Portada del cuento (primera pantalla): como la portada de un libro abierto */
.inicio {
  position: absolute; inset: 0; z-index: 5; overflow-y: auto;
  display: grid; place-items: center;
  padding: clamp(14px, 3vw, 32px);
  background: color-mix(in srgb, var(--cielo) 78%, transparent);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.inicio[hidden] { display: none; }
.portadilla {
  position: relative; width: min(100%, 980px);
  display: grid; grid-template-columns: 1fr 1fr; align-items: stretch;
  background: var(--papel); border-radius: 10px 26px 26px 10px;
  box-shadow: 0 30px 60px -30px rgba(29, 42, 77, .55), 0 2px 0 rgba(29, 42, 77, .06);
}
/* Lomo del libro en el centro */
.portadilla::after {
  content: ""; position: absolute; top: 0; bottom: 0; left: 50%; width: 28px; transform: translateX(-50%); pointer-events: none;
  background: linear-gradient(90deg, transparent, rgba(29, 42, 77, .08) 45%, rgba(29, 42, 77, .12) 50%, rgba(29, 42, 77, .08) 55%, transparent);
}
.portadilla__dibujo { padding: clamp(12px, 2vw, 22px); display: grid; align-items: center; }
.portadilla__dibujo img { width: 100%; height: auto; aspect-ratio: 4 / 3; border-radius: 6px 16px 16px 6px; }
.portadilla__texto { padding: clamp(20px, 3.4vw, 44px) clamp(20px, 3.4vw, 44px) clamp(20px, 3vw, 36px); display: flex; flex-direction: column; justify-content: center; align-items: flex-start; text-align: left; }
.portadilla h1 { font-size: clamp(2rem, 4.4vw, 3.3rem); max-width: 13ch; margin: 0 0 12px; }
.portadilla__intro { font-size: 1.15rem; color: var(--tinta-2); margin: 0 0 16px; max-width: 38ch; }
.portadilla .botones { gap: 10px 12px; }
.portadilla .boton--suave { min-height: 48px; padding: 8px 16px; font-size: 1.05rem; }
.portadilla__aviso { margin: 10px 0 0; font-size: 1rem; color: var(--tinta-2); min-height: 1.5em; }
.portadilla__aviso:empty { min-height: 0; margin: 0; }
.guardar-texto svg path { fill: transparent; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; transition: fill .3s; }
.guardar-texto[aria-pressed="true"] svg path { fill: var(--golden); stroke: #8A6512; }
@media (prefers-reduced-motion: no-preference) { .guardar-texto.brilla svg { animation: estrella .7s var(--lento); } }
@media (max-width: 760px) {
  .inicio { position: fixed; inset: calc(76px + env(safe-area-inset-top, 0px)) 0 0 0; z-index: 20; place-items: start center; background: var(--cielo); backdrop-filter: none; }
  .portadilla { grid-template-columns: 1fr; border-radius: 22px; }
  .portadilla::after { display: none; }
  .portadilla__dibujo { padding-bottom: 0; }
  .portadilla__dibujo img { aspect-ratio: 16 / 9; border-radius: 14px; }
  .portadilla__texto { padding-top: 16px; }
  .portadilla .botones .boton:first-child { width: 100%; }
}

/* Texto y acciones: SIEMPRE del mismo alto, para que la escena del cuento
   no crezca ni encoja al pasar de página ni al salir una pregunta.
   - El texto tiene su hueco fijo (--lineas renglones); si una frase es
     muy larga, js/cuento-pie.js baja un poco la letra hasta que cabe.
   - Los botones tienen sitio para dos filas; «Escuchar otra vez» va a un
     lado (en el móvil solo con el dibujo). */
.cuento-pie {
  --letra: clamp(1.3rem, 2.7vw, 1.75rem);
  --lineas: 3;
  --boton: 56px;
  --hueco-texto: calc(var(--lineas) * 1.45 * var(--letra));
  --hueco-acciones: calc(2 * var(--boton) + 10px);
  padding: 14px var(--margen) calc(16px + env(safe-area-inset-bottom, 0px));
  display: grid; gap: 8px 24px; align-items: center;
  grid-template-columns: minmax(0, 1fr) fit-content(50%);
  grid-template-rows: var(--hueco-texto) 44px;
  grid-template-areas: "texto acciones" "repetir acciones";
  max-width: 1200px; width: 100%; margin: 0 auto; flex: none; box-sizing: border-box;
}
.narracion {
  grid-area: texto; align-self: stretch;
  margin: 0; font-size: var(--letra); line-height: 1.45; font-weight: 700; max-width: 42rem;
  overflow: hidden; display: flex; align-items: center;
}
.cuento-pie > #repetir { grid-area: repetir; justify-self: start; min-height: 44px; }
.acciones {
  grid-area: acciones; align-self: stretch;
  display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; align-content: center; align-items: center;
  min-height: var(--hueco-acciones);
}
.acciones .boton { min-height: var(--boton); font-size: 1.15rem; padding-block: 8px; }
@media (max-width: 760px) {
  .cuento-pie {
    --lineas: 4;
    --boton: 52px;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: var(--hueco-texto) var(--hueco-acciones);
    grid-template-areas: "texto texto" "repetir acciones";
    gap: 10px 10px;
  }
  .cuento-pie > #repetir { align-self: center; }
  /* Pregunta final «¿cómo te sientes?»: las cuatro caras ocupan todo el ancho
     (al lado de «Escuchar otra vez» no cabían y la última se cortaba) */
  .cuento-pie:has(.caras) {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "texto repetir" "acciones acciones";
  }
  .cuento-pie:has(.caras) > #repetir { align-self: start; }
  .caras .cara { min-width: 0; }
  .acciones { justify-content: stretch; }
  /* Cada botón mide justo lo mismo (también con dos renglones), así caben dos filas */
  .acciones .boton { flex: 1 1 40%; height: var(--boton); min-height: 0; padding: 4px 12px; font-size: 1rem; line-height: 1.15; }
}
/* Tablet en vertical: hay alto de sobra, el texto tiene un renglón más */
@media (min-width: 761px) and (max-aspect-ratio: 1/1) {
  .cuento-pie { --lineas: 4; }
}
/* Pantallas bajitas (móvil tumbado): menos renglones para dejar sitio a la escena */
@media (max-height: 560px) and (min-width: 761px) {
  .cuento-pie { --letra: 1.15rem; --boton: 48px; padding-block: 8px; }
}

.caras { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; width: 100%; }
.cara {
  font: inherit; font-weight: 800; color: var(--tinta); cursor: pointer;
  background: var(--pildora, #fff); border: 0; border-radius: var(--r-m); box-shadow: var(--sombra);
  padding: 8px 6px 10px; display: grid; justify-items: center; gap: 4px; min-height: 96px;
}
.cara svg { width: 64px; }
.cara:hover { background: var(--cielo-2); }
/* En pantallas anchas las caras van a la derecha del texto: más estrechas
   para que el texto no se quede sin sitio */
@media (min-width: 761px) {
  .caras { width: auto; grid-template-columns: repeat(4, minmax(0, 92px)); }
  .cara { min-height: 0; padding: 6px 4px 8px; font-size: .95rem; }
  .cara svg { width: min(58px, 100%); }
  .acciones .respiro { max-width: 290px; text-align: left; }
}

/* Panel para adultos */
.panel-adulto {
  width: min(560px, calc(100% - 32px)); max-height: calc(100% - 48px);
  border: 2px solid var(--borde); border-radius: var(--r-l); padding: 0;
  background: var(--papel); color: var(--tinta);
}
.panel-adulto::backdrop { background: rgba(17, 26, 52, .55); }
.panel-adulto .dentro { padding: 28px clamp(20px, 4vw, 36px) 32px; }
.panel-adulto h2 { font-size: 1.9rem; margin-right: 56px; }
.panel-adulto h3 { font-size: 1.2rem; margin: 20px 0 6px; }
.panel-adulto ul { margin: 0; padding-left: 1.2em; }
.panel-adulto li { margin-bottom: 4px; }
.panel-adulto .cerrar { position: absolute; top: 16px; right: 16px; }

/* Pantallas verticales (móvil): personajes más grandes */
@media (max-aspect-ratio: 4/5) {
  #actor-nina { width: min(64%, 46vh); }
  #actor-torre { width: min(15%, 14vh); right: 6%; }
  #actor-sol { width: min(22%, 16vh); }
  #actor-sol.abrazando { left: 12%; top: 48%; }
}

/* ---------------------------------------------------------
   Cuento: Los tres cerditos
   --------------------------------------------------------- */
.cielo-nina { position: absolute; width: min(8%, 12vh, 96px); left: 72.5%; bottom: 31%; } /* Nina mira el cuento desde la colina */
.cielo-nina .nina-figura { transition: transform .6s; }

.casa { width: min(21%, 30vh, 230px); bottom: 14%; }
#casa-paja { left: 3%; }
#casa-madera { left: 27%; }
#casa-ladrillo { left: 51%; }
.casa .silueta { fill: none; stroke: #38251F; stroke-width: 3; stroke-dasharray: 8 7; opacity: .45; }
.casa.hecha .silueta { opacity: 0; }
.casa .pieza { opacity: 0; transition: opacity .35s, transform .35s; transform-box: fill-box; transform-origin: 50% 100%; }
.casa .pieza.puesta { opacity: 1; }
.casa .piezas { transform-box: fill-box; transform-origin: 50% 100%; transition: transform .9s ease-in, opacity .9s; }
.casa.cae .piezas { transform: translate(-30px, 8px) rotate(-75deg); opacity: 0; }
.casa .humo { opacity: 0; transition: opacity 1s; }
.casa.humea .humo { opacity: 1; }
@media (prefers-reduced-motion: no-preference) {
  .casa .pieza.puesta { animation: aparecer .35s ease-out; }
  .casa.humea .humo { animation: humear 2.4s ease-in-out infinite alternate; }
}
@keyframes aparecer { from { transform: translateY(-14px) scale(.9); } to { transform: none; } }
@keyframes humear { to { transform: translate(4px, -6px); } }

.cerdito { width: min(6.6%, 9.6vh, 70px); bottom: 11%; z-index: 2; transition: left .9s ease-in-out; }
@media (prefers-reduced-motion: no-preference) {
  .cerdito.salta svg { animation: saltito .45s ease-out; }
  .cerdito.corre svg { animation: saltito .3s ease-out 3; }
}
@keyframes saltito { 50% { transform: translateY(-22%); } }

#actor-lobo { width: min(17%, 26vh, 190px); right: 4%; bottom: 13%; }
#actor-lobo .soplo { opacity: 0; }
#actor-lobo .lobo-3d { transform-box: fill-box; transform-origin: 50% 100%; transition: transform .4s ease-out; }
#actor-lobo.sopla .lobo-3d { transform: scale(1.06, 1.04); }
#actor-lobo.cansado .lobo-3d { transform: translateY(3%) rotate(-5deg); }
#actor-lobo.sopla .soplo { opacity: 1; }
@media (prefers-reduced-motion: no-preference) {
  #actor-lobo.llega { animation: llegar 1.2s ease-out; }
  #actor-lobo.sopla .soplo { animation: soplar .5s ease-out 3; }
}
@keyframes llegar { from { transform: translateX(130%); } }
@keyframes soplar { from { transform: translateX(10px); opacity: .2; } to { transform: translateX(-16px); opacity: 1; } }

@media (max-aspect-ratio: 4/5) {
  /* En el móvil de pie, casas y cerditos más grandes (antes se veían diminutos) */
  .casa { width: 26%; }
  #casa-paja { left: .5%; }
  #casa-madera { left: 26.5%; }
  #casa-ladrillo { left: 52.5%; }
  .cerdito { width: 10.5%; }
  #actor-lobo { width: 21%; right: 0; }
  .cielo-nina { width: 13%; left: 68%; bottom: 33%; }
}

/* De noche, la barra de progreso se ve sobre el fondo oscuro */
:root[data-theme="dark"] .progreso li { background: rgba(255, 255, 255, .16); }
:root[data-theme="dark"] .progreso li.ahora { background: color-mix(in srgb, var(--acento) 50%, rgba(255, 255, 255, .16)); }
:root[data-theme="dark"] .progreso li.hecho { background: var(--acento); }

