/* Modern CSS Reset & Variable Tokens */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  /* Colors */
  --bg-primary: #050614;
  --bg-secondary: #0a0b1e;
  --bg-tertiary: rgba(15, 17, 44, 0.6);
  --border-color: rgba(255, 255, 255, 0.08);
  --border-active: rgba(255, 255, 255, 0.2);
  
  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  --text-dim: #6b7280;

  /* Brainwave Accent Colors */
  --color-delta: #3b0764; /* Deep, restorative purple */
  --color-theta: #1d4ed8; /* Cool drifting blue */
  --color-alpha: #d97706; /* Golden amber/calm cyan transition */
  --color-alpha-cyan: #06b6d4;
  --color-beta: #ef4444;  /* Sharp, busy coral red */
  --color-gamma: #a855f7; /* Electric violet-white */

  /* Glassmorphism settings */
  --glass-bg: rgba(10, 11, 30, 0.7);
  --glass-blur: blur(20px);
  --shadow-premium: 0 20px 40px rgba(0, 0, 0, 0.5);

  /* Fonts */
  --font-heading: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body {
  background-color: var(--bg-primary);
  color: var(--text-main);
  font-family: var(--font-body);
  overflow: hidden;
  height: 100vh;
  width: 100vw;
  display: flex;
  flex-direction: column;
}

/* Common Screen Settings */
.screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  visibility: hidden;
  transition: opacity 1s cubic-bezier(0.4, 0, 0.2, 1), visibility 1s;
  z-index: 1;
}

.screen.active {
  opacity: 1;
  visibility: visible;
  z-index: 10;
}

/* --- Landing Screen --- */
#landing-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at center, #0f102c 0%, var(--bg-primary) 100%);
}

.landing-bg-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: 
    radial-gradient(circle at 20% 30%, rgba(217, 119, 6, 0.05) 0%, transparent 40%),
    radial-gradient(circle at 80% 70%, rgba(6, 182, 212, 0.05) 0%, transparent 40%);
  z-index: 1;
  pointer-events: none;
}

.landing-content {
  position: relative;
  max-width: 600px;
  width: 90%;
  padding: 3rem;
  border-radius: 24px;
  background: rgba(10, 11, 30, 0.6);
  border: 1px solid var(--border-color);
  backdrop-filter: var(--glass-blur);
  box-shadow: var(--shadow-premium);
  text-align: center;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
}

.glow-orb {
  position: absolute;
  top: -80px;
  width: 160px;
  height: 160px;
  background: radial-gradient(circle, rgba(217,119,6,0.3) 0%, rgba(6,182,212,0.1) 50%, transparent 100%);
  filter: blur(10px);
  border-radius: 50%;
  animation: slowPulse 8s infinite alternate ease-in-out;
  pointer-events: none;
}

.landing-title {
  font-family: var(--font-heading);
  font-size: 3rem;
  font-weight: 700;
  background: linear-gradient(135deg, #fff 30%, var(--text-muted) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.02em;
}

.landing-subtitle {
  font-family: var(--font-heading);
  font-size: 1.25rem;
  font-weight: 400;
  color: var(--color-alpha-cyan);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.landing-description {
  color: var(--text-muted);
  font-size: 0.975rem;
  line-height: 1.6;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.audio-notice {
  border-top: 1px solid var(--border-color);
  padding-top: 1rem;
  font-size: 0.9rem;
  color: var(--text-main);
  opacity: 0.85;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 0.875rem 2rem;
  border-radius: 50px;
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  border: none;
}

.btn-primary {
  background: linear-gradient(135deg, var(--color-alpha) 0%, #b45309 100%);
  color: #fff;
  box-shadow: 0 4px 20px rgba(217, 119, 6, 0.3);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(217, 119, 6, 0.5);
  background: linear-gradient(135deg, #f59e0b 0%, var(--color-alpha) 100%);
}

.btn-primary:active {
  transform: translateY(0);
}

/* --- Main Experience Screen --- */
#experience-screen {
  background-color: var(--bg-primary);
}

.main-layout {
  display: grid;
  grid-template-columns: 1fr 400px;
  height: 100vh;
  width: 100vw;
}

/* Visualizer (Left Panel) */
.visualizer-container {
  position: relative;
  background-color: #03040b;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-right: 1px solid var(--border-color);
}

#animation-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 2;
}

.canvas-glow {
  position: absolute;
  width: 100%;
  height: 100%;
  background: radial-gradient(circle at center, rgba(6, 182, 212, 0.03) 0%, transparent 70%);
  z-index: 1;
  pointer-events: none;
}

.canvas-tooltip {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(5px);
  border: 1px solid var(--border-color);
  padding: 6px 16px;
  border-radius: 20px;
  font-size: 0.8rem;
  color: var(--text-muted);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.5s ease;
}

.canvas-tooltip.active {
  opacity: 1;
}

/* Subtitle Overlay over Canvas */
.subtitle-overlay {
  position: absolute;
  bottom: 40px;
  left: 10%;
  right: 10%;
  z-index: 10;
  pointer-events: none;
  text-align: center;
}

#subtitle-text {
  display: inline-block;
  background: rgba(5, 6, 20, 0.75);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 1.25rem 2.5rem;
  border-radius: 16px;
  color: #ffffff;
  font-size: 1.25rem;
  line-height: 1.6;
  font-weight: 300;
  max-width: 800px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  transition: all 0.3s ease;
  animation: subtitlePulse 6s infinite alternate ease-in-out;
}

/* Script & Controls Panel (Right Panel) */
.control-panel {
  display: flex;
  flex-direction: column;
  background-color: var(--bg-secondary);
  border-left: 1px solid var(--border-color);
  z-index: 10;
  overflow: hidden;
  box-shadow: -10px 0 30px rgba(0,0,0,0.3);
}

.panel-header {
  padding: 1.5rem;
  border-bottom: 1px solid var(--border-color);
}

.panel-title {
  font-family: var(--font-heading);
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.panel-subtitle {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

/* Chapter Timeline Dots */
.chapter-navigation {
  padding: 1rem 1.5rem;
  background-color: rgba(5, 6, 20, 0.3);
  border-bottom: 1px solid var(--border-color);
}

.chapter-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  list-style: none;
}

.chapter-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
  opacity: 0.5;
  transition: all 0.25s ease;
}

.chapter-item:hover {
  opacity: 0.85;
}

.chapter-item.active {
  opacity: 1;
}

.chapter-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--text-dim);
  transition: all 0.3s ease;
  position: relative;
}

.chapter-item.active .chapter-dot {
  background-color: var(--color-alpha-cyan);
  box-shadow: 0 0 10px var(--color-alpha-cyan);
  transform: scale(1.3);
}

.chapter-name {
  font-size: 0.85rem;
  font-weight: 500;
}

/* Script Content Scroller */
.script-scroller-container {
  flex: 1;
  overflow-y: auto;
  padding: 2rem 1.5rem;
  position: relative;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.1) transparent;
}

/* Soft fading scroll edges */
.script-fade-top, .script-fade-bottom {
  position: absolute;
  left: 0;
  width: 100%;
  height: 25px;
  pointer-events: none;
  z-index: 2;
}
.script-fade-top {
  top: 0;
  background: linear-gradient(to bottom, var(--bg-secondary) 0%, transparent 100%);
}
.script-fade-bottom {
  bottom: 0;
  background: linear-gradient(to top, var(--bg-secondary) 0%, transparent 100%);
}

.script-content {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  padding-bottom: 2rem;
}

.script-paragraph {
  font-size: 0.95rem;
  line-height: 1.65;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  transition: all 0.2s ease;
  border-left: 2px solid transparent;
}

.script-paragraph:hover {
  background-color: rgba(255, 255, 255, 0.02);
  color: var(--text-main);
}

.script-paragraph.active {
  color: var(--text-main);
  background-color: rgba(255, 255, 255, 0.04);
  border-left: 2px solid var(--color-alpha-cyan);
}

/* Spans inside paragraph for sentence synchronization */
.script-sentence {
  transition: color 0.2s ease;
}

.script-sentence.highlight {
  color: #fff;
  text-shadow: 0 0 1px rgba(255, 255, 255, 0.5);
  font-weight: 500;
}

/* Glassmorphic Media Player Controls */
.player-controls-container {
  padding: 1.5rem;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  border-top: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  box-shadow: 0 -10px 35px rgba(0, 0, 0, 0.4);
}

/* Scrubbing timeline */
.timeline-container {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
}

.time-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  width: 32px;
  text-align: center;
}

.timeline-bar {
  flex: 1;
  height: 4px;
  background-color: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  position: relative;
  cursor: pointer;
  transition: height 0.2s ease;
}

.timeline-bar:hover {
  height: 6px;
}

.timeline-progress {
  height: 100%;
  width: 0%;
  background: linear-gradient(to right, var(--color-alpha-cyan), var(--color-alpha));
  border-radius: 10px;
  position: absolute;
  top: 0;
  left: 0;
}

.timeline-handle {
  width: 12px;
  height: 12px;
  background-color: #fff;
  border-radius: 50%;
  position: absolute;
  top: 50%;
  left: 0%;
  transform: translate(-50%, -50%) scale(0);
  box-shadow: 0 2px 6px rgba(0,0,0,0.5);
  transition: transform 0.2s ease;
  pointer-events: none;
}

.timeline-bar:hover .timeline-handle {
  transform: translate(-50%, -50%) scale(1);
}

/* Controls buttons row */
.controls-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

.btn-icon {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  width: 38px;
  height: 38px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}

.btn-icon:hover {
  color: var(--text-main);
  background-color: rgba(255, 255, 255, 0.05);
  border-color: var(--border-color);
}

.btn-icon:active {
  transform: scale(0.95);
}

.btn-play {
  width: 48px;
  height: 48px;
  background-color: var(--text-main);
  color: var(--bg-primary);
  border: none;
  box-shadow: 0 4px 12px rgba(255, 255, 255, 0.15);
}

.btn-play:hover {
  background-color: #ffffff;
  color: var(--bg-primary);
  transform: scale(1.05);
  box-shadow: 0 6px 18px rgba(255, 255, 255, 0.3);
}

.settings-toggles {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.control-group {
  position: relative;
}

/* popover sliders */
.slider-popover {
  position: absolute;
  bottom: 50px;
  right: 50%;
  transform: translateX(50%);
  background: rgba(10, 11, 30, 0.95);
  border: 1px solid var(--border-color);
  backdrop-filter: blur(10px);
  padding: 0.8rem 1rem;
  border-radius: 12px;
  width: 180px;
  box-shadow: var(--shadow-premium);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
  opacity: 0;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 100;
}

.speech-speed-popover {
  width: 240px;
}

.voice-dropdown {
  width: 100%;
  background-color: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 6px 10px;
  font-family: var(--font-body);
  font-size: 0.78rem;
  outline: none;
  cursor: pointer;
  transition: border-color 0.2s ease, background-color 0.2s ease;
}

.voice-dropdown:hover, .voice-dropdown:focus {
  border-color: var(--color-alpha-cyan);
  background-color: rgba(255, 255, 255, 0.12);
}

.voice-dropdown option {
  background-color: var(--bg-primary);
  color: var(--text-main);
  padding: 6px;
}

/* :focus-within lets keyboard and touch users open the popover — tapping the
   toggle button focuses it, since hover doesn't exist on touch devices. */
.control-group:hover .slider-popover,
.control-group:focus-within .slider-popover {
  opacity: 1;
  pointer-events: auto;
  bottom: 54px;
}

.slider-popover label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: flex;
  justify-content: space-between;
}

.slider-popover input[type="range"] {
  width: 100%;
  height: 4px;
  border-radius: 10px;
  background-color: rgba(255, 255, 255, 0.15);
  outline: none;
  -webkit-appearance: none;
}

.slider-popover input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background-color: var(--color-alpha-cyan);
  cursor: pointer;
  transition: transform 0.1s ease;
}

.slider-popover input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

.hidden {
  display: none !important;
}

/* Background floating radial gradient orb */
.background-glow-root {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.ambient-orb {
  position: absolute;
  width: 60vw;
  height: 60vw;
  border-radius: 50%;
  bottom: -30vw;
  left: -20vw;
  filter: blur(80px);
  opacity: 0.12;
  transition: background 1.5s ease, opacity 1.5s ease;
}

.glow-delta {
  background: radial-gradient(circle, var(--color-delta) 0%, transparent 70%);
}
.glow-theta {
  background: radial-gradient(circle, var(--color-theta) 0%, transparent 70%);
}
.glow-alpha {
  background: radial-gradient(circle, rgba(217, 119, 6, 0.7) 0%, rgba(6, 182, 212, 0.4) 50%, transparent 70%);
}
.glow-beta {
  background: radial-gradient(circle, var(--color-beta) 0%, transparent 70%);
}
.glow-gamma {
  background: radial-gradient(circle, var(--color-gamma) 0%, transparent 70%);
}

/* Animations */
@keyframes slowPulse {
  0% {
    transform: scale(0.95);
    opacity: 0.8;
  }
  100% {
    transform: scale(1.05);
    opacity: 1;
  }
}

@keyframes subtitlePulse {
  0% {
    box-shadow: 0 10px 30px rgba(0,0,0,0.4), 0 0 10px rgba(6, 182, 212, 0.05);
  }
  100% {
    box-shadow: 0 10px 30px rgba(0,0,0,0.4), 0 0 25px rgba(217, 119, 6, 0.15);
  }
}

/* Scrollbar customization */
.script-scroller-container::-webkit-scrollbar {
  width: 4px;
}
.script-scroller-container::-webkit-scrollbar-track {
  background: transparent;
}
.script-scroller-container::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
}
.script-scroller-container::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.25);
}

/* Accessibility: honour the OS "reduce motion" setting.
   This is a calm/meditative piece, but decorative looping motion (pulsing orbs,
   long cross-fades) can still trigger vestibular discomfort. We quiet the
   ambient chrome and shorten transitions while keeping the app fully usable.
   The narration-synced canvas is a deliberate, user-initiated experience, but we
   also dampen its heaviest motion from JS (see canvas.js / app.js). */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.2s !important;
    scroll-behavior: auto !important;
  }
  .glow-orb,
  #subtitle-text,
  .ambient-orb {
    animation: none !important;
  }
}

/* Responsive Grid stacking for mobile screens */
@media (max-width: 900px) {
  .main-layout {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 340px;
    height: 100vh;
  }
  .visualizer-container {
    border-right: none;
    border-bottom: 1px solid var(--border-color);
  }
  .control-panel {
    border-left: none;
  }
  .subtitle-overlay {
    bottom: 20px;
  }
  #subtitle-text {
    font-size: 1rem;
    padding: 0.8rem 1.5rem;
  }
  .slider-popover {
    bottom: unset;
    top: 50px;
    right: 50%;
  }
  .control-group:hover .slider-popover,
  .control-group:focus-within .slider-popover {
    top: 54px;
    bottom: unset;
  }
}
