:root {
  --primary-gold: #f59e0b;
  --gold-glow: rgba(245, 158, 11, 0.4);
  --deep-purple: #1e1b4b;
  --purple-light: #312e81;
  --paper-bg: #fffdf5;
  --paper-border: #451a03;
  --text-dark: #292524;
  --text-muted: #57534e;
  --gryffindor-red: #991b1b;
  --witch-purple: #7e22ce;
  --font-heading: 'Fredoka', 'Cinzel', cursive, sans-serif;
  --font-body: 'Lexend', sans-serif;
  --radius-lg: 24px;
  --radius-md: 14px;
  --radius-sm: 8px;
  --shadow-magic: 0 20px 50px rgba(0, 0, 0, 0.5), 0 0 30px rgba(245, 158, 11, 0.2);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-body);
  background: radial-gradient(circle at top center, #2e1065 0%, #0f172a 100%);
  color: var(--text-dark);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  overflow-x: hidden;
  padding-bottom: 20px;
}

#particle-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 99999;
}

/* Header Navbar */
.app-header {
  width: 100%;
  max-width: 1200px;
  padding: 14px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 10;
  gap: 12px;
  flex-wrap: wrap;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-link {
  text-decoration: none;
  color: #fbbf24;
  font-family: var(--font-heading);
  font-size: 1.15rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(245, 158, 11, 0.15);
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid rgba(245, 158, 11, 0.35);
  transition: all 0.2s ease;
}

.brand-link:hover {
  transform: translateY(-2deg);
  background: rgba(245, 158, 11, 0.25);
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3);
}

.title-group h1 {
  font-family: var(--font-heading);
  font-size: 1.35rem;
  color: #ffffff;
  line-height: 1.2;
  text-shadow: 0 2px 8px rgba(0,0,0,0.5);
}

.title-group .subtitle {
  font-size: 0.78rem;
  color: #cbd5e1;
  font-weight: 400;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.star-badge {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #ffffff;
  font-weight: 800;
  border: 1.5px solid #fde047;
  box-shadow: 0 0 12px rgba(245, 158, 11, 0.5);
}

.btn-pill {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #f8fafc;
  padding: 8px 14px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-pill:hover {
  background: rgba(245, 158, 11, 0.25);
  border-color: var(--primary-gold);
  transform: translateY(-2deg);
}

.btn-pill.active {
  background: var(--primary-gold);
  color: #0f172a;
  border-color: var(--primary-gold);
  box-shadow: 0 0 12px var(--gold-glow);
}

.btn-pill.highlight {
  background: linear-gradient(135deg, #0284c7, #0369a1);
  color: #fff;
  border: none;
  box-shadow: 0 4px 14px rgba(2, 132, 199, 0.45);
}

.btn-pill.highlight.purple {
  background: linear-gradient(135deg, #a855f7, #7e22ce);
  box-shadow: 0 4px 14px rgba(126, 34, 206, 0.45);
}

/* Storybook Wrapper */
.storybook-wrapper {
  width: 100%;
  max-width: 1120px;
  padding: 10px 20px 40px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.progress-bar-container {
  width: 100%;
  height: 28px;
  background: rgba(15, 23, 42, 0.75);
  border-radius: 14px;
  overflow: hidden;
  position: relative;
  border: 1px solid rgba(245, 158, 11, 0.35);
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.5);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 14px;
}

.progress-fill {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 8.33%;
  background: linear-gradient(90deg, #d97706, #f59e0b, #fde047);
  transition: width 0.4s ease;
  border-radius: 14px;
  z-index: 1;
}

.progress-text, .wizard-rank-badge {
  position: relative;
  z-index: 2;
  font-size: 0.78rem;
  font-weight: 700;
  color: #ffffff;
  text-shadow: 0 1px 4px rgba(0,0,0,0.9);
}

.wizard-rank-badge {
  color: #fde047;
}

/* Open Book Container */
.book-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: 100%;
  min-height: 580px;
  background: var(--paper-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-magic);
  border: 6px solid var(--paper-border);
  overflow: hidden;
  position: relative;
}

/* Book Pages */
.book-page {
  padding: 28px;
  display: flex;
  flex-direction: column;
}

.page-left {
  background: #18181b;
  justify-content: center;
  align-items: center;
  position: relative;
  cursor: pointer;
}

.image-frame {
  width: 100%;
  height: 100%;
  max-height: 490px;
  border-radius: var(--radius-md);
  overflow: hidden;
  position: relative;
  box-shadow: 0 10px 30px rgba(0,0,0,0.7);
  border: 3px solid #78350f;
  background: #0f172a;
}

.story-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.4s ease, opacity 0.3s ease;
}

.story-img.fade-out {
  opacity: 0;
  transform: scale(0.95);
}

.image-overlay-badge {
  position: absolute;
  bottom: 12px;
  left: 12px;
  background: rgba(15, 23, 42, 0.88);
  color: #fbbf24;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 700;
  border: 1px solid rgba(245, 158, 11, 0.5);
  backdrop-filter: blur(4px);
}

.magic-touch-hint {
  position: absolute;
  top: 12px;
  right: 12px;
  background: rgba(245, 158, 11, 0.85);
  color: #0f172a;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.72rem;
  font-weight: 800;
  backdrop-filter: blur(4px);
  pointer-events: none;
  animation: pulseHint 2s infinite ease-in-out;
}

@keyframes pulseHint {
  0%, 100% { opacity: 0.8; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.05); }
}

.page-right {
  background: linear-gradient(to right, #fffdf7 0%, #fefaf0 100%);
  justify-content: space-between;
  gap: 14px;
}

/* Witch Narrator Card */
.narrator-card {
  background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
  border: 2px solid #f59e0b;
  border-radius: var(--radius-md);
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 4px 14px rgba(245, 158, 11, 0.25);
  gap: 12px;
}

.narrator-profile {
  display: flex;
  align-items: center;
  gap: 12px;
}

.witch-avatar {
  font-size: 2rem;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
}

.narrator-info {
  display: flex;
  flex-direction: column;
}

.narrator-name {
  font-family: var(--font-heading);
  font-weight: 700;
  color: #78350f;
  font-size: 1rem;
}

.narrator-role {
  font-size: 0.78rem;
  color: #92400e;
  font-weight: 500;
}

.btn-narrate {
  background: linear-gradient(135deg, #7e22ce, #6b21a8);
  color: #ffffff;
  border: none;
  padding: 9px 16px;
  border-radius: 22px;
  font-weight: 700;
  font-size: 0.88rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 4px 12px rgba(126, 34, 206, 0.35);
  transition: all 0.2s ease;
  white-space: nowrap;
}

.btn-narrate:hover {
  transform: translateY(-2deg);
  box-shadow: 0 6px 16px rgba(126, 34, 206, 0.5);
  background: #6b21a8;
}

.btn-narrate.stop {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  box-shadow: 0 4px 12px rgba(220, 38, 38, 0.35);
}

/* Voice & Typography Tools */
.text-tools {
  display: grid;
  grid-template-columns: 1.4fr 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  background: rgba(245, 230, 211, 0.4);
  border: 1px solid #e7e5e4;
  border-radius: var(--radius-md);
}

.voice-picker-tool, .speed-selector, .font-scaler {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tool-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: #78350f;
  white-space: nowrap;
}

.speed-select {
  background: #ffffff;
  border: 1.5px solid #d97706;
  border-radius: 8px;
  padding: 5px 8px;
  font-size: 0.78rem;
  font-weight: 600;
  color: #451a03;
  outline: none;
  width: 100%;
  cursor: pointer;
}

.btn-round {
  background: #e7e5e4;
  border: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  color: #292524;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.btn-round:hover {
  background: var(--primary-gold);
  color: #ffffff;
  transform: scale(1.08);
}

/* Chapter Content */
.chapter-content {
  flex: 1;
  overflow-y: auto;
  padding-right: 6px;
}

.chapter-tag {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: #b45309;
  font-weight: 700;
}

.chapter-title {
  font-family: var(--font-heading);
  font-size: 1.55rem;
  color: #451a03;
  margin-bottom: 10px;
  line-height: 1.3;
}

.story-text-box {
  line-height: 1.8;
}

.story-text {
  font-size: 1.1rem;
  color: #292524;
  transition: font-size 0.2s ease;
}

.highlight-word {
  background-color: #fef08a;
  color: #854d0e;
  padding: 2px 6px;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 700;
  border-bottom: 2px solid #eab308;
  transition: all 0.2s ease;
}

.highlight-word:hover {
  background-color: #fde047;
  transform: scale(1.03);
}

.reading-active {
  background-color: #fde047 !important;
  box-shadow: 0 0 12px rgba(245, 158, 11, 0.7);
  border-radius: 6px;
}

/* Vocab Spotlight Card */
.vocab-card {
  background: #f0fdf4;
  border: 1.5px solid #bbf7d0;
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: 0.84rem;
  color: #166534;
  display: flex;
  align-items: center;
  gap: 10px;
  line-height: 1.4;
}

.vocab-icon {
  font-size: 1.2rem;
  flex-shrink: 0;
}

/* Interactive Soundboard Strip */
.soundboard-container {
  background: rgba(15, 23, 42, 0.75);
  border: 1.5px solid rgba(245, 158, 11, 0.35);
  border-radius: var(--radius-md);
  padding: 10px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  backdrop-filter: blur(8px);
}

.soundboard-title {
  font-size: 0.82rem;
  font-weight: 700;
  color: #fbbf24;
}

.soundboard-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.sfx-btn {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: #ffffff;
  padding: 6px 12px;
  border-radius: 16px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.sfx-btn:hover {
  background: var(--primary-gold);
  color: #0f172a;
  transform: translateY(-2deg);
  box-shadow: 0 4px 10px var(--gold-glow);
}

/* Desktop Navigation Controls */
.desktop-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
}

.btn-book-nav {
  background: #78350f;
  color: #ffffff;
  border: none;
  padding: 11px 22px;
  border-radius: 24px;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 14px rgba(120, 53, 15, 0.35);
  transition: all 0.2s ease;
}

.btn-book-nav:hover:not(:disabled) {
  background: #92400e;
  transform: translateY(-2deg);
  box-shadow: 0 6px 18px rgba(120, 53, 15, 0.45);
}

.btn-book-nav:disabled {
  background: #cbd5e1;
  color: #94a3b8;
  cursor: not-allowed;
  box-shadow: none;
}

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

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.25);
  cursor: pointer;
  transition: all 0.2s ease;
}

.dot.active {
  background: var(--primary-gold);
  transform: scale(1.4);
  box-shadow: 0 0 8px var(--gold-glow);
}

/* Thumbnail Scrubber Strip */
.thumbnail-strip {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 8px 4px;
  scrollbar-width: thin;
  scrollbar-color: var(--primary-gold) rgba(15, 23, 42, 0.5);
}

.thumb-item {
  width: 76px;
  height: 56px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 2.5px solid rgba(255, 255, 255, 0.3);
  cursor: pointer;
  opacity: 0.7;
  position: relative;
  flex-shrink: 0;
  transition: all 0.2s ease;
}

.thumb-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.thumb-item:hover {
  opacity: 1;
  transform: translateY(-2deg);
}

.thumb-item.active {
  opacity: 1;
  border-color: var(--primary-gold);
  box-shadow: 0 0 14px var(--gold-glow);
  transform: scale(1.08);
}

.thumb-num {
  position: absolute;
  bottom: 2px;
  right: 2px;
  background: rgba(0,0,0,0.85);
  color: #fff;
  font-size: 0.65rem;
  padding: 1px 5px;
  border-radius: 3px;
  font-weight: 700;
}

/* Mobile Floating Control Dock */
.mobile-dock {
  display: none;
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.94);
  border: 1.5px solid rgba(245, 158, 11, 0.6);
  backdrop-filter: blur(14px);
  padding: 10px 18px;
  border-radius: 32px;
  z-index: 90;
  gap: 12px;
  align-items: center;
  box-shadow: 0 12px 36px rgba(0,0,0,0.6);
}

.dock-btn {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: #ffffff;
  padding: 8px 14px;
  border-radius: 20px;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s ease;
}

.dock-btn.primary {
  background: linear-gradient(135deg, #7e22ce, #6b21a8);
  box-shadow: 0 3px 10px rgba(126, 34, 206, 0.4);
}

.dock-btn.spell {
  background: linear-gradient(135deg, #0284c7, #0369a1);
}

.dock-page-info {
  color: #fbbf24;
  font-weight: 700;
  font-size: 0.88rem;
  letter-spacing: 0.5px;
}

/* Quiz & Spell Modals */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(8px);
  z-index: 100;
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

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

.modal-card {
  background: #fffdf5;
  border: 4px solid #78350f;
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 480px;
  padding: 26px;
  box-shadow: var(--shadow-magic);
  position: relative;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  font-size: 1.8rem;
  color: #78350f;
  cursor: pointer;
}

.modal-header {
  text-align: center;
  margin-bottom: 16px;
}

.modal-header .hat-icon {
  font-size: 3rem;
}

.modal-header h2 {
  font-family: var(--font-heading);
  color: #451a03;
}

.quiz-option {
  background: #fef3c7;
  border: 2px solid #fcd34d;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  margin-bottom: 10px;
  cursor: pointer;
  font-weight: 600;
  color: #78350f;
  transition: all 0.2s ease;
}

.quiz-option:hover {
  background: #fde047;
  transform: translateX(4px);
}

/* Spell Game Modal Grid */
.spell-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 14px;
}

.spell-btn {
  background: #fef3c7;
  border: 2px solid #f59e0b;
  border-radius: var(--radius-md);
  padding: 14px 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: all 0.2s ease;
}

.spell-btn:hover {
  background: #fde047;
  transform: scale(1.04);
}

.spell-name {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 0.95rem;
  color: #451a03;
}

.spell-effect {
  font-size: 0.72rem;
  color: #78350f;
  text-align: center;
}

.spell-stage {
  background: #18181b;
  color: #fbbf24;
  border-radius: var(--radius-md);
  padding: 16px;
  text-align: center;
  font-weight: 700;
  font-size: 1.1rem;
  min-height: 70px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed #f59e0b;
}

/* Dyslexic Font */
body.font-dyslexic {
  font-family: 'Lexend', sans-serif;
  letter-spacing: 0.6px;
}

/* Mobile Responsive Adjustments */
@media (max-width: 820px) {
  .app-header {
    padding: 10px 16px;
  }
  .title-group h1 {
    font-size: 1.1rem;
  }
  .header-actions .label {
    display: none;
  }
  .book-container {
    grid-template-columns: 1fr;
    min-height: auto;
    border-width: 4px;
  }
  .page-left {
    height: 280px;
    padding: 16px;
    border-bottom: 3px solid #3f2312;
  }
  .page-right {
    padding: 20px;
  }
  .text-tools {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  .spell-grid {
    grid-template-columns: 1fr;
  }
  .desktop-nav {
    display: none;
  }
  .mobile-dock {
    display: flex;
  }
  .storybook-wrapper {
    padding-bottom: 90px;
  }
}
