/* ==========================================================================
   reader.css - Immersive Children's Book Reader Modal & Story Views
   Designed for kids 5-7 with large friendly text, dual/single page responsive view,
   read-aloud sentence highlights, and celebratory finish confetti
   ========================================================================== */

#reader-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  background: radial-gradient(circle at 50% 30%, #1e1b4b 0%, #0f172a 60%, #020617 100%);
  opacity: 0;
  pointer-events: none;
  transform: scale(0.96);
  transition: opacity 0.3s ease, transform 0.3s var(--ease-bounce);
  overflow: hidden;
}

#reader-modal.active {
  opacity: 1;
  pointer-events: auto;
  transform: scale(1);
}

/* Reader Top Bar */
.reader-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 2px solid rgba(255, 255, 255, 0.1);
  flex-shrink: 0;
  z-index: 20;
}

.reader-book-info {
  display: flex;
  flex-direction: column;
}

.reader-book-title {
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 800;
  color: #fef08a;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
}

.reader-meta-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 2px;
}

.reader-book-author {
  font-family: var(--font-body);
  font-size: 13px;
  color: #94a3b8;
  font-weight: 600;
}

/* In-Reader Tier Indicator Badge */
.reader-tier-badge {
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.reader-tier-badge.tier-free {
  background: rgba(148, 163, 184, 0.2);
  border: 1px solid rgba(148, 163, 184, 0.4);
  color: #cbd5e1;
}

.reader-tier-badge.tier-come-alive {
  background: linear-gradient(135deg, #db2777 0%, #7c3aed 100%);
  border: 1.5px solid #ffffff;
  color: #ffffff;
  font-weight: 800;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.reader-tier-badge.tier-cinematic {
  background: linear-gradient(135deg, #0284c7 0%, #2563eb 50%, #d97706 100%);
  border: 1.5px solid #ffffff;
  color: #ffffff;
  font-weight: 800;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.reader-top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* In-Reader Upgrade Button */
.btn-reader-upgrade {
  display: flex;
  align-items: center;
  gap: 6px;
  background: linear-gradient(135deg, #ec4899 0%, #8b5cf6 50%, #f59e0b 100%);
  background-size: 200% 200%;
  animation: shimmerGlow 4s ease infinite;
  color: #ffffff;
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 800;
  border: 1px solid rgba(254, 240, 138, 0.8);
  box-shadow: 0 3px 10px rgba(236, 72, 153, 0.4);
  cursor: pointer;
  transition: transform 0.2s var(--ease-bounce);
}

.btn-reader-upgrade:hover {
  transform: scale(1.06);
  box-shadow: 0 4px 16px rgba(236, 72, 153, 0.6);
}

/* Read to Me Button */
.open-book-spread { perspective: 1200px; touch-action: pan-y; }
.open-book-spread .page-left, .open-book-spread .page-right {
  backface-visibility: hidden;
  border-bottom: 5px solid #e1cfb4;
  box-shadow: 0 3px 0 #f7ecda, 0 5px 0 #cdb99a;
}
.open-book-spread .page-left { transform-origin: right center; }
.open-book-spread .page-right { transform-origin: left center; }
.open-book-spread img { -webkit-user-drag: none; }
#reader-illustration[hidden] { display: none !important; }
@media (prefers-reduced-motion: reduce) {
  .open-book-spread .page-left, .open-book-spread .page-right { transform: none !important; }
}

.btn-read-aloud {
  display: flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  color: #ffffff;
  padding: 8px 18px;
  border-radius: var(--radius-pill);
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.3);
  transition: all 0.2s var(--ease-bounce);
  cursor: pointer;
}

.btn-read-aloud:hover {
  transform: scale(1.06);
  box-shadow: 0 6px 16px rgba(245, 158, 11, 0.6);
}

.btn-read-aloud.speaking {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  animation: pulseSpeaking 1.2s infinite alternate;
}

@keyframes pulseSpeaking {
  0% { transform: scale(1); box-shadow: 0 0 10px rgba(16, 185, 129, 0.4); }
  100% { transform: scale(1.05); box-shadow: 0 0 20px rgba(16, 185, 129, 0.8); }
}

/* Reader Close Button */
.btn-reader-close {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
  color: #ffffff;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid rgba(255, 255, 255, 0.3);
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
  transition: transform 0.2s var(--ease-bounce);
  cursor: pointer;
}

.btn-reader-close:hover {
  transform: scale(1.1) rotate(90deg);
}

/* ==========================================================================
   STORY BOOK STAGE (Open Book Presentation)
   ========================================================================== */
.reader-stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow: hidden;
  position: relative;
}

.open-book-spread {
  display: flex;
  width: 100%;
  max-width: 960px;
  height: 100%;
  max-height: 580px;
  background: #fdfcf7;
  border-radius: 16px;
  box-shadow: 
    0 20px 50px rgba(0, 0, 0, 0.7),
    0 0 0 8px #78350f,
    0 0 0 12px #451a03;
  position: relative;
  overflow: hidden;
  transition: all 0.3s ease;
}

/* Book Spine Center Gutter & Crease */
.book-gutter {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 40px;
  transform: translateX(-50%);
  background: linear-gradient(
    90deg, 
    transparent 0%, 
    rgba(0, 0, 0, 0.08) 20%, 
    rgba(0, 0, 0, 0.25) 50%, 
    rgba(0, 0, 0, 0.08) 80%, 
    transparent 100%
  );
  z-index: 10;
  pointer-events: none;
}

/* Page Left: Story Illustration */
.page-left {
  flex: 1;
  height: 100%;
  background: #f8fafc;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  position: relative;
  border-right: 1px solid rgba(0, 0, 0, 0.08);
  overflow: hidden;
}

.page-illustration-wrap {
  width: 100%;
  height: 100%;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
  background: #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.page-illustration-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 12s ease-in-out;
}

/* COME ALIVE Environmental Animation Layer */
.ambient-particles-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  overflow: hidden;
}

/* Dynamic Ambient Floating Leaves & Sparkles */
.ambient-leaf {
  position: absolute;
  width: 14px;
  height: 14px;
  background: rgba(74, 222, 128, 0.65);
  border-radius: 0 100% 0 100%;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
  animation: floatLeaf 8s linear infinite;
}

.ambient-sparkle {
  position: absolute;
  width: 8px;
  height: 8px;
  background: #fef08a;
  border-radius: 50%;
  box-shadow: 0 0 10px #fde047;
  animation: floatSparkle 4s ease-in-out infinite alternate;
}

@keyframes floatLeaf {
  0% { transform: translateY(-20px) translateX(0) rotate(0deg); opacity: 0; }
  15% { opacity: 0.8; }
  85% { opacity: 0.8; }
  100% { transform: translateY(320px) translateX(80px) rotate(360deg); opacity: 0; }
}

@keyframes floatSparkle {
  0% { transform: translateY(0) scale(0.6); opacity: 0.3; }
  50% { transform: translateY(-30px) scale(1.2); opacity: 0.9; }
  100% { transform: translateY(-60px) scale(0.8); opacity: 0.4; }
}

/* CINEMATIC Camera Movement & Vignette */
.cinematic-vignette-layer {
  position: absolute;
  inset: 0;
  box-shadow: inset 0 0 60px rgba(0, 0, 0, 0.65);
  pointer-events: none;
  z-index: 6;
  opacity: 0;
  transition: opacity 0.5s ease;
}

.mode-cinematic .cinematic-vignette-layer {
  opacity: 1;
}

.mode-cinematic .page-illustration-wrap img {
  animation: kenBurnsMotion 20s infinite alternate ease-in-out;
}

@keyframes kenBurnsMotion {
  0% { transform: scale(1.02) translate(0%, 0%); }
  50% { transform: scale(1.15) translate(-3%, -2%); }
  100% { transform: scale(1.1) translate(2%, 1%); }
}

.mode-come-alive .page-illustration-wrap img {
  animation: gentlePulseMotion 8s infinite alternate ease-in-out;
}

@keyframes gentlePulseMotion {
  0% { transform: scale(1); }
  100% { transform: scale(1.04); }
}

/* Page Right: Story Content & Text */
.page-right {
  flex: 1;
  height: 100%;
  background: #fffdfa;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 36px 40px;
  position: relative;
  overflow-y: auto;
  color: #1e293b;
  scrollbar-width: none;
}

.page-right::-webkit-scrollbar {
  display: none;
}

.page-chapter-title {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 800;
  color: #b45309;
  margin-bottom: 16px;
  letter-spacing: 0.5px;
}

.page-story-text {
  text-align: center;
  font-family: 'Fredoka', 'Quicksand', sans-serif;
  font-size: 24px;
  line-height: 1.7;
  color: #1e293b;
  font-weight: 500;
  white-space: pre-line;
  transition: color 0.2s ease;
}

.page-right { text-align: center; }
.page-illustration-wrap { background: #fffdf8; box-shadow: none; }
.page-illustration-wrap img { object-fit: contain; }
@media(max-width:680px) {
  .reader-stage { overflow-y: auto; align-items: flex-start; min-height: 0; }
  .reader-stage .open-book-spread { height: auto; max-height: none; min-height: 0; flex-shrink: 0; }
  .open-book-spread .page-right { order: 0; flex: none; height: auto; min-height: 160px; padding: 24px 22px; overflow: visible; }
  .open-book-spread .page-left { order: 1; flex: none; height: clamp(220px,48vh,370px); width: 100%; padding: 14px; }
  .open-book-spread .page-chapter-title { margin-bottom: 10px; }
  .open-book-spread .page-story-text { font-size: clamp(18px,5vw,24px); line-height: 1.6; }
}

/* Read-Aloud Highlight Style */
.page-story-text .reader-word {
  cursor: pointer;
  display: inline-block;
  transition: color 0.15s ease, transform 0.15s ease, background-color 0.15s ease;
  border-radius: 4px;
  padding: 0 2px;
}
.page-story-text .reader-word:focus-visible { outline: 2px solid #8b5cf6; outline-offset: 3px; }

.page-story-text .reader-word.active-word,
.page-story-text mark.active-word {
  background: linear-gradient(135deg, #fde047 0%, #facc15 100%);
  color: #713f12;
  border-radius: 6px;
  padding: 2px 6px;
  font-weight: 700;
  transform: scale(1.05);
  box-shadow: 0 2px 8px rgba(250, 204, 21, 0.4);
}

/* Page Corner Turn Indicator */
.page-corner-fold {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, transparent 50%, #e2e8f0 50%);
  pointer-events: none;
}

/* ==========================================================================
   MOBILE RESPONSIVENESS FOR READER
   Single page stacked vertically on small screens
   ========================================================================== */
@media (max-width: 680px) {
  .open-book-spread {
    flex-direction: column;
    max-height: 92%;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.7), 0 0 0 4px #78350f;
  }
  .book-gutter {
    display: none;
  }
  .page-left {
    flex: 0 0 42%;
    padding: 12px;
    border-right: none;
    border-bottom: 2px solid #e2e8f0;
  }
  .page-right {
    flex: 1;
    padding: 16px 20px;
  }
  .page-chapter-title {
    font-size: 18px;
    margin-bottom: 8px;
  }
  .page-story-text {
    font-size: 18px;
    line-height: 1.55;
  }
}

/* ==========================================================================
   READER BOTTOM CONTROLS
   Big friendly page flip buttons & star progress
   ========================================================================== */
.reader-bottom-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: rgba(15, 23, 42, 0.9);
  backdrop-filter: blur(10px);
  border-top: 2px solid rgba(255, 255, 255, 0.1);
  flex-shrink: 0;
  z-index: 20;
}

.reader-btn-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 24px;
  border-radius: var(--radius-pill);
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 700;
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
  transition: transform 0.2s var(--ease-bounce), opacity 0.2s ease;
}

.btn-nav-prev {
  background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%);
  border: 1px solid rgba(255, 255, 255, 0.25);
}

.btn-nav-next {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  border: 1px solid rgba(255, 255, 255, 0.25);
}

.reader-btn-nav:disabled {
  opacity: 0.35;
  pointer-events: none;
}

.reader-progress-dots {
  display: flex;
  align-items: center;
  gap: 8px;
}

.progress-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.25);
  transition: all 0.25s var(--ease-bounce);
}

.progress-dot.active {
  background: #f59e0b;
  transform: scale(1.35);
  box-shadow: 0 0 10px #f59e0b;
}

.progress-dot.visited {
  background: #10b981;
}

/* ==========================================================================
   LOCKED BOOK MODAL DIALOG
   ========================================================================== */
.locked-card {
  background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
  border: 3px solid #f59e0b;
  border-radius: var(--radius-lg);
  padding: 32px 28px;
  max-width: 400px;
  width: 90%;
  text-align: center;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.8), 0 0 25px rgba(245, 158, 11, 0.3);
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  animation: popIn 0.3s var(--ease-bounce);
}

@keyframes popIn {
  0% { transform: scale(0.85); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.locked-icon-badge {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: linear-gradient(135deg, #f59e0b, #d97706);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 34px;
  margin-bottom: 16px;
  box-shadow: 0 6px 18px rgba(245, 158, 11, 0.5);
}

.locked-title {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 800;
  color: #fff;
  margin-bottom: 10px;
}

.locked-desc {
  font-family: var(--font-body);
  font-size: 16px;
  color: #cbd5e1;
  margin-bottom: 24px;
  line-height: 1.5;
}

.locked-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

.btn-unlock-confirm {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: #ffffff;
  padding: 14px;
  border-radius: var(--radius-pill);
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 800;
  border: 2px solid rgba(255, 255, 255, 0.3);
  box-shadow: 0 6px 16px rgba(16, 185, 129, 0.4);
}

.btn-unlock-cancel {
  background: rgba(255, 255, 255, 0.1);
  color: #cbd5e1;
  padding: 10px;
  border-radius: var(--radius-pill);
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 600;
}

/* ==========================================================================
   CONFETTI STORY COMPLETION CELEBRATION
   ========================================================================== */
#celebration-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.82);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

#celebration-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.celebration-card {
  background: linear-gradient(135deg, #4338ca 0%, #312e81 100%);
  border: 4px solid #fde047;
  border-radius: 28px;
  padding: 36px 32px;
  text-align: center;
  max-width: 440px;
  width: 90%;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.9), 0 0 35px rgba(253, 224, 71, 0.4);
  animation: celebrationBounce 0.5s var(--ease-bounce);
}

@keyframes celebrationBounce {
  0% { transform: scale(0.6) rotate(-5deg); }
  100% { transform: scale(1) rotate(0); }
}

.celebration-title {
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 900;
  color: #fde047;
  margin-bottom: 12px;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
}

.celebration-rewards {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin: 20px 0 28px 0;
}

.reward-badge {
  background: rgba(255, 255, 255, 0.15);
  border: 2px solid rgba(255, 255, 255, 0.3);
  padding: 10px 18px;
  border-radius: var(--radius-pill);
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 800;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 8px;
}
.page-turn-sheet { position: absolute; z-index: 40; pointer-events: none; transform-style: preserve-3d; will-change: transform; }
.page-turn-sheet .page-turn-face { position: absolute !important; inset: 0 !important; width: 100% !important; height: 100% !important; margin: 0 !important; backface-visibility: hidden; box-shadow: 0 5px 18px #311b1b22; }
.page-turn-sheet .page-turn-back { transform: rotateY(180deg); }
.reader-word[aria-disabled="true"] { cursor: text; }
.reader-word[aria-disabled="true"]:hover { transform: none; box-shadow: none; }
