/**
 * style.css
 * Polished, colorful, touch-friendly UI for Kids Storybook.
 * Designed with high contrast, large hit targets, dyslexic-friendly text, and playful animations.
 */

:root {
  --primary: #4f46e5;
  --primary-light: #818cf8;
  --primary-dark: #3730a3;
  --bg-gradient: linear-gradient(135deg, #f0fdf4 0%, #e0f2fe 50%, #fef3c7 100%);
  --card-bg: #ffffff;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;
  --radius-xl: 32px;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 6px 18px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 12px 28px rgba(0, 0, 0, 0.12);
}

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

body {
  font-family: 'Nunito', 'Segoe UI', -apple-system, sans-serif;
  color: var(--text-main);
  background: var(--bg-gradient);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Base Container */
.app-wrapper {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.25rem;
}

/* Header & Navbar */
.site-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  padding: 1rem 1.5rem;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(12px);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  margin-bottom: 1.5rem;
}

.logo-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  cursor: pointer;
}

.logo-icon {
  font-size: 2.25rem;
  animation: logo-bounce 2s infinite ease-in-out;
}

@keyframes logo-bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px) rotate(-3deg); }
}

.logo-text h1 {
  font-size: 1.4rem;
  font-weight: 800;
  background: linear-gradient(90deg, #4f46e5, #0ea5e9, #f59e0b);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.logo-text p {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 600;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.btn-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1.1rem;
  background: #ffffff;
  border: 2px solid #e2e8f0;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 44px;
}

.btn-pill:hover {
  background: #f8fafc;
  border-color: var(--primary-light);
  transform: translateY(-1px);
}

.btn-pill.primary {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.25);
}

.btn-pill.primary:hover {
  background: var(--primary-dark);
}

/* Hero Section */
.hero-card {
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #ec4899 100%);
  color: #ffffff;
  border-radius: var(--radius-xl);
  padding: 2rem;
  box-shadow: var(--shadow-md);
  margin-bottom: 2rem;
  position: relative;
  overflow: hidden;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.hero-content {
  max-width: 650px;
  z-index: 2;
}

.hero-tag {
  display: inline-block;
  background: rgba(255, 255, 255, 0.25);
  padding: 0.35rem 0.85rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
}

.hero-title {
  font-size: 2.1rem;
  font-weight: 900;
  line-height: 1.25;
  margin-bottom: 0.75rem;
}

.hero-desc {
  font-size: 1.05rem;
  opacity: 0.95;
  margin-bottom: 1.25rem;
  line-height: 1.6;
}

.hero-illustration {
  font-size: 5.5rem;
  filter: drop-shadow(0 10px 15px rgba(0, 0, 0, 0.2));
  animation: float-animal 3.5s ease-in-out infinite alternate;
}

@keyframes float-animal {
  0% { transform: translateY(0) rotate(0deg); }
  100% { transform: translateY(-12px) rotate(4deg); }
}

/* Search and Filters Bar */
.filter-bar {
  background: #ffffff;
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  margin-bottom: 2rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.search-box {
  position: relative;
  width: 100%;
}

.search-box input {
  width: 100%;
  height: 50px;
  padding: 0 1rem 0 3rem;
  border: 2px solid #e2e8f0;
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-family: inherit;
  transition: all 0.2s ease;
  background: #f8fafc;
}

.search-box input:focus {
  outline: none;
  border-color: var(--primary);
  background: #ffffff;
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.15);
}

.search-icon {
  position: absolute;
  left: 1rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.2rem;
  color: var(--text-muted);
}

.filter-pills-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.filter-label {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
  margin-right: 0.25rem;
}

.chip {
  padding: 0.4rem 0.9rem;
  background: #f1f5f9;
  border: 2px solid transparent;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
  color: #475569;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.chip:hover {
  background: #e2e8f0;
}

.chip.active {
  background: #e0e7ff;
  color: var(--primary-dark);
  border-color: var(--primary-light);
}

/* Stats Counter */
.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  padding: 0 0.5rem;
}

.results-count {
  font-size: 0.95rem;
  color: var(--text-muted);
  font-weight: 700;
}

/* Story Grid */
.story-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.5rem;
  margin-bottom: 3rem;
}

.story-card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 1rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  border: 2px solid #f1f5f9;
  position: relative;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  min-height: 290px;
}

.story-card:hover {
  transform: translateY(-6px);
  box-shadow: var(--shadow-md);
  border-color: var(--primary-light);
}

/* Card Animal Thumbnail */
.card-thumbnail-wrapper {
  position: relative;
  width: 100%;
  height: 130px;
  border-radius: var(--radius-md);
  overflow: hidden;
  margin-bottom: 0.85rem;
  background: #f1f5f9;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.05);
}

.card-thumbnail-svg {
  width: 100%;
  height: 100%;
  display: block;
  transition: transform 0.35s ease;
}

.story-card:hover .card-thumbnail-svg {
  transform: scale(1.06);
}

.thumb-overlay-top {
  position: absolute;
  top: 8px;
  left: 8px;
  right: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: none;
  z-index: 2;
}

.thumb-overlay-top .theme-badge,
.thumb-overlay-top .fav-btn {
  pointer-events: auto;
}

.card-animal-tag {
  position: absolute;
  bottom: 8px;
  left: 8px;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(6px);
  color: #ffffff;
  font-size: 0.75rem;
  font-weight: 800;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  text-transform: capitalize;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  z-index: 2;
}

.fav-btn {
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(4px);
  border: 1px solid rgba(0, 0, 0, 0.05);
  border-radius: 50%;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease;
  line-height: 1;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

.fav-btn:hover {
  transform: scale(1.2);
  background: #ffffff;
}

.story-title {
  font-size: 1.2rem;
  font-weight: 800;
  margin-bottom: 0.5rem;
  color: #1e293b;
  line-height: 1.35;
}

.story-preview {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 1rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.story-moral-chip {
  background: #f8fafc;
  border-left: 3px solid #f59e0b;
  padding: 0.4rem 0.6rem;
  font-size: 0.8rem;
  color: #475569;
  font-style: italic;
  margin-bottom: 1rem;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.card-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 0.75rem;
  border-top: 1px dashed #e2e8f0;
}

.length-badge {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.read-action {
  font-size: 0.9rem;
  font-weight: 800;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

/* ==========================================================
   STORY READER VIEW
   ========================================================== */

.reader-wrapper {
  max-width: 850px;
  margin: 0 auto;
}

.reader-navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
}

.reader-card {
  background: #ffffff;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  border: 2px solid #e2e8f0;
}

.reader-header {
  padding: 1.5rem 1.75rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  border-bottom: 1px solid #f1f5f9;
}

.reader-title-area h2 {
  font-size: 1.75rem;
  font-weight: 900;
  color: #0f172a;
  margin-bottom: 0.35rem;
}

/* Stage & Animated Visual SVG */
.reader-stage {
  position: relative;
  width: 100%;
  background: #f1f5f9;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  border-bottom: 2px solid #e2e8f0;
}

.story-svg-canvas {
  width: 100%;
  max-height: 420px;
  display: block;
}

/* SVG Keyframe Animations */
.anim-sun {
  animation: sun-pulse 4s ease-in-out infinite alternate;
  transform-origin: 340px 45px;
}
@keyframes sun-pulse {
  0% { transform: scale(0.96); opacity: 0.85; }
  100% { transform: scale(1.04); opacity: 1; }
}

.anim-cloud {
  animation: cloud-drift 18s linear infinite alternate;
}
@keyframes cloud-drift {
  0% { transform: translateX(0); }
  100% { transform: translateX(50px); }
}

.anim-cloud-slow {
  animation: cloud-drift-slow 24s linear infinite alternate;
}
@keyframes cloud-drift-slow {
  0% { transform: translateX(0); }
  100% { transform: translateX(-40px); }
}

.anim-character {
  animation: character-bounce 1.8s ease-in-out infinite alternate;
  transform-origin: bottom center;
}
@keyframes character-bounce {
  0% { transform: translateY(0); }
  100% { transform: translateY(-6px); }
}

/* Full Story Reading Box & Interactive Sentence Highlighting */
.story-reader-text-container {
  padding: 1.75rem 2rem;
  background: #ffffff;
  border-bottom: 1px solid #f1f5f9;
}

.narration-counter-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
}

.narration-counter {
  display: inline-block;
  font-size: 0.85rem;
  font-weight: 800;
  text-transform: uppercase;
  color: var(--primary);
  letter-spacing: 0.5px;
}

.click-hint {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
}

.story-full-paragraphs {
  font-size: 1.35rem;
  line-height: 2.1;
  font-weight: 600;
  color: #334155;
  text-align: left;
}

.story-read-sentence {
  display: inline;
  padding: 0.1rem 0.2rem;
  margin: 0;
  border-radius: 6px;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
  font-weight: 600;
}

.story-read-sentence:hover {
  background: #f1f5f9;
}

.story-read-sentence.active-reading {
  background: #fef08a;
  color: #78350f;
  font-weight: 600;
}

.story-read-sentence.active-reading.speaking {
  background: #fde047;
  color: #713f12;
  font-weight: 600;
}

/* Word-by-word karaoke narration highlight - strictly zero layout shift */
.story-read-sentence .story-word {
  display: inline;
  border-radius: 4px;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
  transition: background-color 0.08s ease, color 0.08s ease;
  font-weight: inherit;
}

.story-read-sentence.active-reading .story-word.word-speaking {
  background: #ea580c;
  color: #ffffff !important;
  border-radius: 4px;
  font-weight: inherit;
}

/* Progress bar inside reader */
.progress-bar-container {
  height: 8px;
  background: #e2e8f0;
  width: 100%;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #4f46e5, #06b6d4, #10b981);
  transition: width 0.3s ease;
}

/* Audio & Speed Controls Bar */
.art-style-btn {
  background: #ffffff;
  border: 1.5px solid #cbd5e1;
  border-radius: 9999px;
  padding: 0.35rem 0.85rem;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  color: #334155;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  transition: all 0.2s ease;
}
.art-style-btn:hover {
  background: #f1f5f9;
  border-color: #94a3b8;
  transform: translateY(-1px);
}

.reader-controls-bar {
  background: #f8fafc;
  padding: 1.25rem 1.75rem;
  border-top: 1px solid #e2e8f0;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.controls-row-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

.speed-control-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
}

.speed-slider {
  accent-color: var(--primary);
  width: 100px;
  cursor: pointer;
}

.speed-value-badge {
  background: #e2e8f0;
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  color: #1e293b;
  font-weight: 800;
  min-width: 40px;
  text-align: center;
}

.voice-select-group {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.voice-select-group select {
  font-family: inherit;
  font-size: 0.85rem;
  padding: 0.35rem 0.65rem;
  border-radius: var(--radius-sm);
  border: 1px solid #cbd5e1;
  background: #ffffff;
  color: #334155;
  max-width: 220px;
  cursor: pointer;
}

.voice-preview-btn {
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0.35rem 0.65rem;
  border-radius: var(--radius-sm);
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  color: #334155;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.voice-preview-btn:hover:not(:disabled) {
  background: #e2e8f0;
  border-color: #94a3b8;
  color: #0f172a;
}

.voice-preview-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.playback-buttons {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.circle-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: #ffffff;
  box-shadow: var(--shadow-sm);
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 1.25rem;
  cursor: pointer;
  transition: all 0.2s ease;
  color: #334155;
}

.circle-btn:hover {
  transform: scale(1.08);
  box-shadow: var(--shadow-md);
}

.circle-btn.play-btn {
  width: 58px;
  height: 58px;
  background: var(--primary);
  color: #ffffff;
  font-size: 1.5rem;
  box-shadow: 0 4px 14px rgba(79, 70, 229, 0.4);
}

.circle-btn.play-btn:hover {
  background: var(--primary-dark);
  transform: scale(1.1);
}

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

/* Moral Celebration Card & Full Story View */
.moral-celebration {
  text-align: center;
  padding: 1.5rem 0 0;
}

.trophy-icon {
  font-size: 4rem;
  margin-bottom: 0.75rem;
  animation: trophy-wobble 1.5s infinite ease-in-out;
}

@keyframes trophy-wobble {
  0%, 100% { transform: scale(1) rotate(0deg); }
  25% { transform: scale(1.1) rotate(-6deg); }
  75% { transform: scale(1.1) rotate(6deg); }
}

.celebration-title {
  font-size: 2rem;
  font-weight: 900;
  color: #0f172a;
  margin-bottom: 0.35rem;
}

.celebration-moral-box {
  background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
  border: 2px solid #f59e0b;
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.75rem;
  margin: 1.5rem auto 2rem;
  max-width: 650px;
  box-shadow: 0 6px 18px rgba(245, 158, 11, 0.2);
}

.moral-label {
  font-size: 0.85rem;
  font-weight: 800;
  text-transform: uppercase;
  color: #92400e;
  letter-spacing: 1px;
  margin-bottom: 0.35rem;
}

.moral-quote {
  font-size: 1.35rem;
  font-weight: 800;
  color: #78350f;
  line-height: 1.4;
}

/* Completed Full Story Container with Thumbnail as Background */
.completed-story-container {
  position: relative;
  border-radius: var(--radius-xl);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  border: 2px solid #e2e8f0;
  margin-bottom: 2rem;
  background: #ffffff;
}

.completed-story-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  opacity: 0.22;
  pointer-events: none;
  z-index: 1;
  overflow: hidden;
}

.completed-story-backdrop svg {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scale(1.05);
  filter: blur(1.5px);
}

.completed-story-content {
  position: relative;
  z-index: 2;
  padding: 2.5rem 2rem;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(12px);
}

.full-story-header {
  text-align: center;
  margin-bottom: 1.75rem;
}

.full-story-pill-row {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.75rem;
}

.full-story-title {
  font-size: 2.25rem;
  font-weight: 900;
  color: #0f172a;
  line-height: 1.25;
}

.full-story-subtitle {
  font-size: 0.95rem;
  color: var(--text-muted);
  font-weight: 700;
  margin-top: 0.35rem;
}

.full-story-body {
  background: rgba(255, 255, 255, 0.96);
  border: 2px solid #e2e8f0;
  border-radius: var(--radius-lg);
  padding: 2rem 2.25rem;
  margin: 1.5rem auto 2rem;
  max-width: 720px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.04);
  text-align: left;
}

.full-story-sentence {
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 1.85;
  color: #1e293b;
  margin-bottom: 0.85rem;
  display: block;
}

.celebration-actions {
  display: flex;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-top: 1.75rem;
}

/* Confetti Canvas */
#confettiCanvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 9999;
}

/* Footer */
.site-footer {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 600;
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .hero-card {
    flex-direction: column;
    text-align: center;
    padding: 1.5rem;
  }
  .hero-illustration {
    margin-top: 1rem;
    font-size: 4rem;
  }
  .narration-text {
    font-size: 1.2rem;
    min-height: 70px;
  }
  .playback-buttons {
    width: 100%;
    justify-content: center;
  }
}

/* Studio Audio & Narration Status Badges */
.badge-studio-audio {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: #dcfce7;
  color: #15803d;
  border: 1px solid #86efac;
  padding: 0.25rem 0.65rem;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.2px;
  box-shadow: 0 1px 3px rgba(22, 101, 52, 0.1);
}

.badge-browser-audio {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: #f1f5f9;
  color: #475569;
  border: 1px solid #cbd5e1;
  padding: 0.25rem 0.65rem;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 700;
}
