/* ============================================
   LA ORQUESTA DE LOS SUEÑOS
   Hoja de estilos - Cuento interactivo
   ============================================ */

:root {
  --color-bg-1: #ffe5f1;
  --color-bg-2: #fff0d6;
  --color-bg-3: #d6f0ff;
  --color-primary: #ff6b9d;
  --color-primary-dark: #e85a8b;
  --color-secondary: #ffd166;
  --color-accent: #6bcfff;
  --color-text: #3d2c5c;
  --color-text-light: #6b5b8e;
  --color-cream: #fff8e7;
  --color-page: #fffaf0;
  --color-page-shadow: rgba(120, 80, 60, 0.18);
  --shadow-book: 0 25px 60px -15px rgba(120, 80, 60, 0.35), 0 10px 30px -10px rgba(120, 80, 60, 0.25);
  --shadow-soft: 0 8px 20px rgba(120, 80, 60, 0.12);
  --shadow-btn: 0 6px 14px rgba(255, 107, 157, 0.35);
  --radius: 22px;
  --radius-sm: 14px;
  --transition: 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  font-family: 'Fredoka', 'Comic Sans MS', system-ui, sans-serif;
  color: var(--color-text);
  background: linear-gradient(135deg, var(--color-bg-1) 0%, var(--color-bg-2) 50%, var(--color-bg-3) 100%);
  background-attachment: fixed;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

/* ============================================
   Notas musicales flotantes de fondo
   ============================================ */
.music-notes-bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.music-notes-bg span {
  position: absolute;
  font-size: clamp(1.5rem, 4vw, 2.5rem);
  color: rgba(255, 107, 157, 0.18);
  animation: floatNote 18s linear infinite;
}

.music-notes-bg span:nth-child(1)  { left:  5%; animation-delay:  0s; }
.music-notes-bg span:nth-child(2)  { left: 15%; animation-delay:  3s; }
.music-notes-bg span:nth-child(3)  { left: 25%; animation-delay:  6s; }
.music-notes-bg span:nth-child(4)  { left: 35%; animation-delay:  9s; }
.music-notes-bg span:nth-child(5)  { left: 45%; animation-delay:  1s; }
.music-notes-bg span:nth-child(6)  { left: 55%; animation-delay:  4s; }
.music-notes-bg span:nth-child(7)  { left: 65%; animation-delay:  7s; }
.music-notes-bg span:nth-child(8)  { left: 75%; animation-delay: 10s; }
.music-notes-bg span:nth-child(9)  { left: 85%; animation-delay:  2s; }
.music-notes-bg span:nth-child(10) { left: 92%; animation-delay:  5s; }
.music-notes-bg span:nth-child(11) { left: 40%; animation-delay:  8s; }
.music-notes-bg span:nth-child(12) { left: 70%; animation-delay: 11s; }

@keyframes floatNote {
  0%   { transform: translateY(110vh) rotate(0deg);   opacity: 0; }
  10%  { opacity: 0.6; }
  90%  { opacity: 0.6; }
  100% { transform: translateY(-15vh) rotate(360deg); opacity: 0; }
}

/* ============================================
   Contenedor principal del libro
   ============================================ */
.book-container {
  position: relative;
  z-index: 1;
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px 120px;
}



.page {
  position: absolute;
  inset: 24px 16px 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transform: scale(0.95) translateY(20px);
  transition: opacity 0.6s ease, transform 0.6s ease, visibility 0.6s;
  pointer-events: none;
}

.page.active {
  opacity: 1;
  visibility: visible;
  transform: scale(1) translateY(0);
  pointer-events: auto;
}

.page-inner {
  width: 100%;
  max-width: 920px;
  background: var(--color-page);
  border-radius: var(--radius);
  box-shadow: var(--shadow-book);
  padding: 28px;
  position: relative;
  border: 6px solid var(--color-cream);
}

/* Decoración de esquinas tipo libro antiguo */
.page-inner::before,
.page-inner::after {
  content: '';
  position: absolute;
  width: 30px;
  height: 30px;
  border: 3px solid var(--color-primary);
  border-radius: 50%;
  opacity: 0.5;
}
.page-inner::before { top: 12px; left: 12px; border-right: 0; border-bottom: 0; }
.page-inner::after  { bottom: 12px; right: 12px; border-left: 0; border-top: 0; }

/* ============================================
   PORTADA
   ============================================ */
.cover-page {
  background: linear-gradient(160deg, #ffe0ec 0%, #fff5d6 50%, #d6f0ff 100%);
  text-align: center;
  padding: 40px 28px;
}

.cover-decoration {
  position: absolute;
  font-size: clamp(1.8rem, 5vw, 2.5rem);
  animation: spin 12s linear infinite;
}
.cover-decoration.top-left     { top: 18px; left: 18px; }
.cover-decoration.top-right    { top: 18px; right: 18px; animation-direction: reverse; }
.cover-decoration.bottom-left  { bottom: 18px; left: 18px; animation-direction: reverse; }
.cover-decoration.bottom-right { bottom: 18px; right: 18px; }

@keyframes spin {
  to { transform: rotate(360deg); }
}

.cover-content {
  position: relative;
  z-index: 2;
}

.cover-subtitle {
  font-family: 'Caveat', cursive;
  font-size: clamp(1.1rem, 3vw, 1.5rem);
  color: var(--color-primary-dark);
  margin-bottom: 8px;
  font-weight: 500;
}

.cover-title {
  font-size: clamp(2rem, 7vw, 3.6rem);
  font-weight: 700;
  line-height: 1.05;
  margin-bottom: 16px;
  color: var(--color-text);
  text-shadow: 3px 3px 0 var(--color-secondary), 6px 6px 0 rgba(255, 107, 157, 0.2);
  animation: titleBounce 2.5s ease-in-out infinite;
}

.title-line {
  display: block;
}

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

.cover-illustration {
  width: 100%;
  max-width: 480px;
  margin: 20px auto;
  border-radius: var(--radius-sm);
  overflow: hidden;
  box-shadow: var(--shadow-soft);
  border: 4px solid white;
}

.cover-illustration img {
  width: 100%;
  height: auto;
  display: block;
  animation: gentleFloat 4s ease-in-out infinite;
}

@keyframes gentleFloat {
  0%, 100% { transform: translateY(0) rotate(-1deg); }
  50%      { transform: translateY(-8px) rotate(1deg); }
}

.btn-start {
  margin-top: 24px;
  padding: 16px 36px;
  font-size: clamp(1rem, 3vw, 1.25rem);
  font-family: inherit;
  font-weight: 600;
  color: white;
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
  border: none;
  border-radius: 50px;
  cursor: pointer;
  box-shadow: var(--shadow-btn);
  display: inline-flex;
  align-items: center;
  gap: 10px;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  position: relative;
  overflow: hidden;
}

.btn-start::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(120deg, transparent 30%, rgba(255, 255, 255, 0.4) 50%, transparent 70%);
  transform: translateX(-100%);
  transition: transform 0.6s ease;
}

.btn-start:hover::after,
.btn-start:focus-visible::after {
  transform: translateX(100%);
}

.btn-start:hover,
.btn-start:focus-visible {
  transform: translateY(-3px) scale(1.03);
  box-shadow: 0 10px 22px rgba(255, 107, 157, 0.5);
  outline: none;
}

.btn-start:active {
  transform: translateY(0) scale(0.98);
}

.btn-icon {
  font-size: 1.2em;
}

/* ============================================
   PÁGINAS DE HISTORIA
   ============================================ */
.story-page {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  align-items: center;
}

.page-image-wrap {
  position: relative;
  border-radius: var(--radius-sm);
  overflow: hidden;
  box-shadow: var(--shadow-soft);
  border: 5px solid white;
  background: var(--color-cream);
  aspect-ratio: 4 / 3;
}

.page-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  animation: imageFade 0.8s ease;
}

@keyframes imageFade {
  from { opacity: 0; transform: scale(1.05); }
  to   { opacity: 1; transform: scale(1); }
}

.page-text {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.character-name {
  font-size: clamp(1.15rem, 3vw, 1.5rem);
  font-weight: 700;
  color: var(--color-primary-dark);
  margin-bottom: 4px;
  font-family: 'Caveat', cursive;
  font-size: clamp(1.4rem, 3.5vw, 1.8rem);
}

.story-text {
  font-size: clamp(0.95rem, 2.2vw, 1.1rem);
  line-height: 1.6;
  color: var(--color-text);
}

.story-text + .story-text {
  margin-top: 4px;
}

.moral {
  margin-top: 12px;
  padding: 12px 16px;
  background: linear-gradient(135deg, #fff4d6, #ffe5f1);
  border-left: 4px solid var(--color-primary);
  border-radius: var(--radius-sm);
  font-weight: 600;
  color: var(--color-primary-dark);
  font-size: clamp(0.95rem, 2.2vw, 1.1rem);
}

/* ============================================
   PÁGINA FINAL
   ============================================ */
.final-page {
  grid-template-columns: 1fr;
  max-width: 720px;
  margin: 0 auto;
  padding-bottom: 40px;
  max-height: calc(100vh - 160px);
  max-height: calc(100dvh - 160px);
  overflow-y: auto;
  overflow-x: hidden;
}

.final-page .page-image-wrap {
  max-width: 320px;
  margin: 0 auto;
  aspect-ratio: 16 / 11;
}

.btn-restart-wrap {
  text-align: center;
  margin-top: 8px;
  padding-bottom: 20px;
}

.questions-list {
  list-style: none;
  padding: 0;
  margin: 12px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.questions-list li {
  background: linear-gradient(135deg, #fff0d6, #ffe5f1);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: clamp(0.9rem, 2vw, 1.05rem);
  line-height: 1.45;
  box-shadow: var(--shadow-soft);
  border: 2px dashed rgba(255, 107, 157, 0.4);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.questions-list li:hover {
  transform: translateX(6px);
  box-shadow: 0 6px 16px rgba(255, 107, 157, 0.25);
}

.final-msg {
  text-align: center;
  font-size: clamp(1.1rem, 3vw, 1.4rem);
  font-weight: 600;
  color: var(--color-primary-dark);
  margin-top: 12px;
  font-family: 'Caveat', cursive;
  font-size: clamp(1.5rem, 4vw, 2rem);
}

.btn-restart {
  margin: 16px auto 0;
  padding: 14px 30px;
  font-size: clamp(1rem, 2.5vw, 1.15rem);
  font-family: inherit;
  font-weight: 600;
  color: white;
  background: linear-gradient(135deg, var(--color-accent) 0%, #4ab3e6 100%);
  border: none;
  border-radius: 50px;
  cursor: pointer;
  box-shadow: 0 6px 14px rgba(107, 207, 255, 0.4);
  display: inline-flex;
  align-items: center;
  gap: 10px;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.btn-restart:hover,
.btn-restart:focus-visible {
  transform: translateY(-3px) scale(1.03);
  box-shadow: 0 10px 22px rgba(107, 207, 255, 0.5);
  outline: none;
}

.btn-restart:active {
  transform: translateY(0) scale(0.98);
}

/* ============================================
   CONTROLES (barra inferior)
   ============================================ */
.controls {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: 50px;
  box-shadow: 0 10px 30px rgba(120, 80, 60, 0.25);
  max-width: calc(100% - 24px);
  border: 2px solid rgba(255, 215, 102, 0.5);
}

.controls[hidden] {
  display: none;
}

.ctrl-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--color-text);
  background: transparent;
  border: none;
  border-radius: 50px;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.15s ease, color 0.2s ease;
  white-space: nowrap;
}

.ctrl-btn:hover:not(:disabled),
.ctrl-btn:focus-visible:not(:disabled) {
  background: var(--color-bg-1);
  outline: none;
}

.ctrl-btn:active:not(:disabled) {
  transform: scale(0.95);
}

.ctrl-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.ctrl-btn.primary {
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
  color: white;
  box-shadow: var(--shadow-btn);
}

.ctrl-btn.primary:hover:not(:disabled),
.ctrl-btn.primary:focus-visible:not(:disabled) {
  background: linear-gradient(135deg, var(--color-primary-dark) 0%, var(--color-primary) 100%);
  color: white;
}

.audio-control {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 4px;
}

.audio-btn {
  padding: 8px;
  min-width: 44px;
  min-height: 44px;
  justify-content: center;
  background: var(--color-cream);
}

.audio-icon {
  font-size: 1.3rem;
  line-height: 1;
}

.audio-progress-wrap {
  width: 80px;
  height: 6px;
  background: rgba(120, 80, 60, 0.15);
  border-radius: 50px;
  overflow: hidden;
}

.audio-progress {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--color-primary), var(--color-accent));
  border-radius: 50px;
  transition: width 0.2s linear;
}

.page-indicator {
  padding: 6px 14px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--color-text-light);
  background: var(--color-cream);
  border-radius: 50px;
  min-width: 64px;
  text-align: center;
}

/* ============================================
   Indicador de "tocando" (cuando se reproduce audio)
   ============================================ */
.audio-playing .audio-icon {
  animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.15); }
}

/* ============================================
   Animación de cambio de página
   ============================================ */
.page.transitioning {
  animation: pageTurn 0.6s ease;
}

@keyframes pageTurn {
  0%   { transform: scale(0.95) rotateY(20deg); opacity: 0; }
  100% { transform: scale(1) rotateY(0); opacity: 1; }
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 720px) {
  .book-container {
    padding: 16px 12px 110px;
  }

  .page {
    inset: 16px 12px 110px;
  }

  .page-inner {
    padding: 20px 18px;
  }

  .story-page {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .page-image-wrap {
    aspect-ratio: 16 / 11;
    max-height: 280px;
  }

  .cover-page {
    padding: 32px 18px;
  }

  .cover-illustration {
    max-width: 320px;
  }

  .btn-start {
    padding: 14px 28px;
  }

  .controls {
    bottom: 10px;
    padding: 8px 10px;
    gap: 6px;
  }

  .ctrl-label {
    display: none;
  }

  .ctrl-btn {
    padding: 10px 12px;
    min-width: 44px;
    min-height: 44px;
    justify-content: center;
  }

  .ctrl-btn.primary {
    padding: 10px 14px;
  }

  .audio-progress-wrap {
    width: 50px;
  }

  .page-indicator {
    padding: 4px 10px;
    font-size: 0.85rem;
    min-width: 54px;
  }

  .questions-list li {
    padding: 10px 14px;
  }
}

@media (max-width: 420px) {
  .cover-title {
    font-size: 2rem;
  }

  .story-text {
    font-size: 0.95rem;
  }

  .page-image-wrap {
    max-height: 220px;
  }
}

@media (min-width: 721px) and (max-width: 1024px) {
  .page-inner {
    max-width: 760px;
  }
}

/* Accesibilidad: respetar prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .music-notes-bg { display: none; }
}

/* Focus visible para navegación por teclado */
button:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 2px;
}
