/* ============================================================
   Kids' Comic Book Viewer Styles
   Warm Indian art style with child-friendly colors
   ============================================================ */

/* --- Global hidden attribute fix --- */
[hidden] { display: none !important; }

/* --- CSS Variables (extending main site palette) --- */
:root {
  --gold: #d4a853;
  --saffron: #ff6b00;
  --maroon: #5c1a1b;
  --dblue: #0a1628;
  --bg: #faf5eb;
  --white: #ffffff;
  --shadow-soft: 0 2px 12px rgba(0, 0, 0, 0.1);
  --shadow-medium: 0 4px 20px rgba(0, 0, 0, 0.15);
  --radius-panel: 12px;
  --radius-bubble: 16px;
  --teal: #2a9d8f;
}

/* --- Base & Typography --- */
@import url('https://fonts.googleapis.com/css2?family=Comic+Neue:wght@400;700&family=Cinzel:wght@500;700&display=swap');

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

body {
  font-family: 'Comic Neue', cursive, sans-serif;
  background: var(--bg);
  color: var(--dblue);
  line-height: 1.6;
  min-height: 100vh;
}

/* --- Main Container --- */
.comic-viewer {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 16px;
  padding-bottom: 80px; /* space for sticky nav */
}


/* ============================================================
   1. HEADER (sticky top)
   ============================================================ */
.comic-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--dblue);
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  border-bottom: 3px solid var(--gold);
}

.comic-header .logo-text {
  font-family: 'Cinzel', serif;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 1px;
}

.comic-header .back-link {
  color: var(--white);
  text-decoration: none;
  font-size: 0.9rem;
  opacity: 0.85;
  transition: opacity 0.2s;
}

.comic-header .back-link:hover {
  opacity: 1;
  text-decoration: underline;
}

/* --- CSS-only Toggle Switch --- */
.toggle-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
}

.toggle-label {
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.8);
  cursor: pointer;
  user-select: none;
}

.toggle-switch {
  position: relative;
  width: 44px;
  height: 24px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 24px;
  cursor: pointer;
  transition: background 0.3s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  background: var(--white);
  border-radius: 50%;
  transition: transform 0.3s;
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--saffron);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(20px);
}


/* ============================================================
   2. COVER PAGE
   ============================================================ */
.cover-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 0;
}

.cover-image-wrapper {
  position: relative;
  width: 100%;
  max-width: 600px;
  aspect-ratio: 3 / 4;
  border-radius: var(--radius-panel);
  overflow: hidden;
  box-shadow: var(--shadow-medium);
  border: 3px solid var(--maroon);
}

.cover-image-wrapper img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.cover-title-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 24px 16px;
  background: linear-gradient(transparent, rgba(10, 22, 40, 0.85));
  text-align: center;
}

.cover-title-overlay h1 {
  font-family: 'Cinzel', serif;
  font-size: 1.8rem;
  color: var(--gold);
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  margin-bottom: 4px;
}

.cover-title-overlay p {
  color: rgba(255, 255, 255, 0.9);
  font-size: 1rem;
}

/* "Open the Comic!" button */
.btn-open-comic {
  margin-top: 20px;
  padding: 14px 36px;
  font-family: 'Comic Neue', cursive;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--white);
  background: var(--saffron);
  border: none;
  border-radius: 50px;
  cursor: pointer;
  box-shadow: 0 4px 0 #cc5500, var(--shadow-soft);
  transition: transform 0.15s, box-shadow 0.15s;
}

.btn-open-comic:hover {
  transform: translateY(-3px);
  box-shadow: 0 7px 0 #cc5500, var(--shadow-medium);
}

.btn-open-comic:active {
  transform: translateY(1px);
  box-shadow: 0 2px 0 #cc5500;
}


/* ============================================================
   3. COMIC PAGE LAYOUTS (5 grid variants)
   ============================================================ */

/* Base comic page with 3D book flip */
.comic-viewer {
  perspective: 1200px;
}

.comic-page {
  padding: 16px 0;
  transform-origin: left center;
  backface-visibility: hidden;
}

.comic-page:not([hidden]) {
  animation: pageFlipIn 0.6s cubic-bezier(0.22, 0.61, 0.36, 1) forwards;
}

.comic-page.flip-out {
  animation: pageFlipOut 0.4s cubic-bezier(0.55, 0.06, 0.68, 0.19) forwards;
}

.comic-page[hidden] {
  display: none;
}

/* Shared panel grid styles */
.comic-layout-1,
.comic-layout-2,
.comic-layout-3,
.comic-layout-2-1,
.comic-layout-4 {
  display: grid;
  gap: 12px;
  width: 100%;
}

/* Layout 1: Single full-width panel */
.comic-layout-1 {
  grid-template-columns: 1fr;
}

/* Layout 3: First panel full-width, next two 50/50 (most common) */
.comic-layout-3 {
  grid-template-columns: 1fr 1fr;
}

.comic-layout-3 .panel:first-child,
.comic-layout-3 .comic-panel:first-child {
  grid-column: 1 / -1;
}

/* Layout 2: Two equal columns */
.comic-layout-2 {
  grid-template-columns: 1fr 1fr;
}

/* Layout 2-1: Two side-by-side on top, one full-width bottom */
.comic-layout-2-1 {
  grid-template-columns: 1fr 1fr;
}

.comic-layout-2-1 .panel:last-child,
.comic-layout-2-1 .comic-panel:last-child {
  grid-column: 1 / -1;
}

/* Layout 4: 2x2 grid */
.comic-layout-4 {
  grid-template-columns: 1fr 1fr;
}

/* --- Individual Panel: Image + Dialogue stacked --- */
.panel,
.comic-panel {
  position: relative;
  border: 3px solid var(--maroon);
  border-radius: var(--radius-panel);
  overflow: hidden;
  background: #fff;
  display: flex;
  flex-direction: column;
}

/* Panel image — fully visible, never cropped by bubbles */
.comic-panel .panel-img {
  width: 100%;
  height: auto;
  aspect-ratio: 4/3;
  object-fit: cover;
  display: block;
  border-bottom: 2px solid rgba(92,26,27,0.15);
}


/* ============================================================
   4. SPEECH BUBBLES — Comic Book Style
   ============================================================ */
.bubble,
.speech-bubble {
  position: relative;
  z-index: 2;
  background: #fff;
  border-radius: 0 0 var(--radius-panel) var(--radius-panel);
  padding: 10px 42px 12px 16px;
  font-size: 0.88rem;
  line-height: 1.55;
  border-left: 5px solid var(--gold);
  cursor: pointer;
  transition: background 0.2s;
  border-top: none;
  margin: 0;
  max-width: 100%;
}

.speech-bubble:hover {
  background: #fffbf0;
}

/* Speaker name label */
.bubble-speaker {
  display: block;
  font-family: 'Inter', sans-serif;
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 3px;
  opacity: 0.7;
}

/* Play button — absolute within the speech bubble */
.bubble-play-btn {
  position: absolute;
  top: 50%;
  right: 8px;
  transform: translateY(-50%);
  background: var(--saffron);
  border: none;
  border-radius: 50%;
  width: 30px;
  height: 30px;
  font-size: 0.75rem;
  cursor: pointer;
  color: #fff;
  box-shadow: 0 2px 8px rgba(255,107,0,0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s, background 0.15s;
  flex-shrink: 0;
}

.bubble-play-btn:hover {
  transform: translateY(-50%) scale(1.15);
  background: #e85d00;
}

.speech-bubble.playing .bubble-play-btn {
  background: #e85d00;
  animation: glowPulse 1.2s ease-in-out infinite;
}

/* No triangular tails needed — dialogue sits directly below image */
.bubble::after,
.speech-bubble::after {
  display: none;
}

/* --- Character-specific border colors --- */
.bubble-narrator,
.speech-bubble.bubble-narrator {
  border-left-color: var(--gold);
}
.bubble-narrator .bubble-speaker { color: #b08930; }

.bubble-brahma,
.speech-bubble.bubble-brahma {
  border-left-color: var(--saffron);
}
.bubble-brahma .bubble-speaker { color: #cc5500; }

.bubble-narada,
.speech-bubble.bubble-narada {
  border-left-color: var(--teal);
}
.bubble-narada .bubble-speaker { color: #1a6b5a; }

/* --- Bubble positioning: all relative now (stacked below image) --- */
/* These classes kept for HTML compatibility but no absolute positioning */
.bubble-top-left,
.bubble-top-right,
.bubble-top-center,
.bubble-bottom-left,
.bubble-bottom-right,
.bubble-bottom-center,
.bubble-center-left,
.bubble-center-right {
  /* all static — sits below the image in flow */
}

/* Hide all legacy ::after tails */
.bubble-top-right::after,
.bubble-top-center::after,
.bubble-bottom-left::after,
.bubble-bottom-right::after,
.bubble-bottom-center::after,
.bubble-center-right::after {
  display: none;
}

/* (speaker label and play button already defined above in section 4) */

/* --- Legacy play button override --- */
.bubble-play-btn-legacy {
  bottom: 6px;
  right: 8px;
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 50%;
  background: var(--saffron);
  color: var(--white);
  font-size: 0.75rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s, background 0.15s;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

.bubble-play-btn:hover {
  transform: scale(1.15);
  background: #e55d00;
}

/* --- Playing state: glowing border animation --- */
@keyframes glowPulse {
  0%, 100% { box-shadow: 0 0 4px rgba(255, 107, 0, 0.4), var(--shadow-soft); }
  50% { box-shadow: 0 0 16px rgba(255, 107, 0, 0.7), var(--shadow-soft); }
}

.speech-bubble.playing,
.bubble.playing {
  border-color: var(--saffron) !important;
  animation: glowPulse 1.2s ease-in-out infinite;
  box-shadow: 0 0 20px rgba(255,107,0,0.3);
}


/* ============================================================
   5. KARAOKE TEXT HIGHLIGHTING
   ============================================================ */
.word {
  display: inline;
  transition: all 0.12s ease;
  border-radius: 3px;
  padding: 1px 0;
}

.word-active {
  background: linear-gradient(135deg, #fef08a, #fde047);
  padding: 2px 4px;
  border-radius: 4px;
  color: #78350f !important;
  font-weight: 700;
  box-shadow: 0 1px 4px rgba(253,224,71,0.5);
  transform: scale(1.05);
  display: inline-block;
}

/* Pulse effect on active word */
@keyframes wordPulse {
  0%, 100% { box-shadow: 0 1px 4px rgba(253,224,71,0.4); }
  50% { box-shadow: 0 2px 8px rgba(253,224,71,0.8); }
}
.word-active {
  animation: wordPulse 0.6s ease-in-out infinite;
}


/* ============================================================
   6. SIMPLE MODE TOGGLE
   ============================================================ */

/* Default: show full text, hide simple text */
.bubble-text-simple {
  display: none !important;
}

/* Simple mode active: swap text visibility */
.simple-mode .bubble-text {
  display: none;
}

.simple-mode .bubble-text-simple {
  display: block !important;
  font-size: 1.05rem;
  font-weight: 500;
  line-height: 1.6;
}


/* ============================================================
   7. PAGE NAVIGATION (sticky bottom)
   ============================================================ */
.comic-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: rgba(250, 245, 235, 0.8);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid rgba(212, 168, 83, 0.3);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

/* Nav buttons */
.nav-btn {
  padding: 8px 20px;
  font-family: 'Comic Neue', cursive;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--white);
  background: var(--maroon);
  border: none;
  border-radius: 24px;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s;
  display: flex;
  align-items: center;
  gap: 6px;
}

.nav-btn:hover {
  background: #7a2324;
  transform: translateY(-1px);
}

.nav-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

/* Dot indicators */
.nav-dots {
  display: flex;
  align-items: center;
  gap: 6px;
}

.nav-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: rgba(92, 26, 27, 0.25);
  border: none;
  cursor: pointer;
  transition: background 0.2s, transform 0.2s;
}

.nav-dot:hover {
  background: rgba(92, 26, 27, 0.5);
}

.nav-dot.active {
  background: var(--saffron);
  transform: scale(1.25);
}

/* Page counter */
.nav-page-counter {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--maroon);
  white-space: nowrap;
  min-width: 60px;
  text-align: center;
}


/* ============================================================
   8. PAGE TRANSITIONS
   ============================================================ */
/* 3D Book Page Flip Animations */
@keyframes pageFlipIn {
  0% {
    opacity: 0;
    transform: rotateY(-90deg) scale(0.95);
    box-shadow: -20px 0 40px rgba(0,0,0,0.3);
  }
  40% {
    opacity: 1;
  }
  100% {
    opacity: 1;
    transform: rotateY(0deg) scale(1);
    box-shadow: none;
  }
}

@keyframes pageFlipOut {
  0% {
    opacity: 1;
    transform: rotateY(0deg) scale(1);
  }
  60% {
    opacity: 0.6;
  }
  100% {
    opacity: 0;
    transform: rotateY(90deg) scale(0.95);
    box-shadow: 20px 0 40px rgba(0,0,0,0.3);
  }
}

/* Reverse flip for going to previous page */
.comic-page.flip-in-reverse:not([hidden]) {
  animation: pageFlipInReverse 0.6s cubic-bezier(0.22, 0.61, 0.36, 1) forwards;
}

@keyframes pageFlipInReverse {
  0% {
    opacity: 0;
    transform: rotateY(90deg) scale(0.95);
    box-shadow: 20px 0 40px rgba(0,0,0,0.3);
  }
  40% { opacity: 1; }
  100% {
    opacity: 1;
    transform: rotateY(0deg) scale(1);
    box-shadow: none;
  }
}


/* ============================================================
   9. PANEL IMAGE
   ============================================================ */
.panel-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}


/* ============================================================
   10. FUN FACTS PAGE (Page 7)
   ============================================================ */
.fact-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  padding: 16px 0;
}

.fact-card {
  border-radius: var(--radius-panel);
  padding: 20px;
  text-align: center;
  box-shadow: var(--shadow-soft);
  transition: transform 0.2s;
}

.fact-card:hover {
  transform: translateY(-4px);
}

/* Colorful card backgrounds */
.fact-card:nth-child(1) {
  background: #fff3e0; /* warm orange tint */
}

.fact-card:nth-child(2) {
  background: #e8f5e9; /* gentle green */
}

.fact-card:nth-child(3) {
  background: #e3f2fd; /* light blue */
}

.fact-card:nth-child(4) {
  background: #fce4ec; /* soft pink */
}

.fact-icon {
  font-size: 2.2rem;
  display: block;
  margin-bottom: 8px;
}

.fact-number {
  font-family: 'Cinzel', serif;
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--maroon);
  display: block;
  margin-bottom: 4px;
}

.fact-desc {
  font-size: 0.9rem;
  color: var(--dblue);
  line-height: 1.4;
}


/* ============================================================
   11. RESPONSIVE (max-width: 600px)
   ============================================================ */
@media (max-width: 600px) {

  /* All grids collapse to single column */
  .comic-layout-2,
  .comic-layout-3,
  .comic-layout-2-1,
  .comic-layout-4 {
    grid-template-columns: 1fr;
  }

  .comic-layout-3 .panel:first-child,
  .comic-layout-3 .comic-panel:first-child,
  .comic-layout-2-1 .panel:last-child,
  .comic-layout-2-1 .comic-panel:last-child {
    grid-column: auto;
  }

  /* Bubbles get wider */
  .bubble {
    max-width: 85%;
  }

  /* Panels get taller */
  .panel {
    min-height: 280px;
  }

  /* Navigation buttons: larger touch targets */
  .nav-btn {
    padding: 12px 24px;
    font-size: 1rem;
  }

  .nav-dot {
    width: 12px;
    height: 12px;
  }

  /* Cover image full-width */
  .cover-image-wrapper {
    max-width: 100%;
  }

  .cover-title-overlay h1 {
    font-size: 1.4rem;
  }

  /* Fact grid single column */
  .fact-grid {
    grid-template-columns: 1fr;
  }

  /* Header adjustments */
  .comic-header {
    padding: 8px 12px;
    flex-wrap: wrap;
    gap: 8px;
  }

  .comic-header .logo-text {
    font-size: 1.1rem;
  }
}


/* ============================================================
   12. PLACEHOLDER STYLES (when images aren't loaded)
   ============================================================ */
.panel-placeholder {
  width: 100%;
  height: 100%;
  min-height: 250px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #faf5eb 0%, #f0e6d3 50%, #faf5eb 100%);
  color: var(--maroon);
  font-size: 0.85rem;
  opacity: 0.7;
}

.panel-placeholder .placeholder-icon {
  font-size: 3rem;
  margin-bottom: 8px;
  opacity: 0.5;
}

.panel-placeholder .placeholder-text {
  font-style: italic;
}
