/* ==========================================================================
   LingoFlow Modern Stylesheet
   Night Owl / Glassmorphism / Indigo & Emerald Palette
   ========================================================================== */

:root {
  /* Dark Mode Palette (Default Night Owl) */
  --bg-primary: #090d16;
  --bg-secondary: #0f172a;
  --bg-surface: #141e33;
  --bg-card: rgba(20, 30, 51, 0.75);
  --bg-card-hover: rgba(28, 42, 70, 0.85);
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-focus: rgba(99, 102, 241, 0.5);
  
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  
  --primary-indigo: #6366f1;
  --primary-indigo-light: #818cf8;
  --primary-indigo-glow: rgba(99, 102, 241, 0.35);
  
  --accent-emerald: #10b981;
  --accent-emerald-light: #34d399;
  --accent-emerald-glow: rgba(16, 185, 129, 0.25);
  
  --accent-amber: #f59e0b;
  --accent-rose: #f43f5e;
  
  --glass-bg: rgba(15, 23, 42, 0.82);
  --glass-border: rgba(255, 255, 255, 0.12);
  --glass-blur: blur(14px);
  --shadow-elevated: 0 16px 36px rgba(0, 0, 0, 0.45);
  
  --font-story: 'Lora', 'Merriweather', Georgia, serif;
  --font-ui: 'Rubik', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;
  
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Light Mode Overrides */
body.light-mode {
  --bg-primary: #f8fafc;
  --bg-secondary: #f1f5f9;
  --bg-surface: #ffffff;
  --bg-card: rgba(255, 255, 255, 0.85);
  --bg-card-hover: #ffffff;
  --border-subtle: rgba(0, 0, 0, 0.08);
  --border-focus: rgba(99, 102, 241, 0.4);
  
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  
  --primary-indigo: #4f46e5;
  --primary-indigo-light: #6366f1;
  --primary-indigo-glow: rgba(79, 70, 229, 0.15);
  
  --accent-emerald: #059669;
  --accent-emerald-light: #10b981;
  --accent-emerald-glow: rgba(5, 150, 105, 0.15);
  
  --glass-bg: rgba(255, 255, 255, 0.88);
  --glass-border: rgba(0, 0, 0, 0.09);
  --shadow-elevated: 0 14px 30px rgba(0, 0, 0, 0.08);
}

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

body {
  font-family: var(--font-ui);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  direction: rtl;
  min-height: 100vh;
  overflow-x: hidden;
  transition: background-color var(--transition-normal), color var(--transition-normal);
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  outline: none;
}

.hidden {
  display: none !important;
}

/* ==========================================================================
   Global App Header
   ========================================================================== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  background: var(--glass-bg);
  border-bottom: 1px solid var(--border-subtle);
  transition: background-color var(--transition-normal);
}

.header-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.85rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  cursor: pointer;
  user-select: none;
}

.logo-mark {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--primary-indigo), var(--accent-emerald));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  box-shadow: 0 4px 14px var(--primary-indigo-glow);
  transition: transform var(--transition-normal);
}

.brand-group:hover .logo-mark {
  transform: scale(1.05) rotate(3deg);
}

.logo-wave {
  width: 22px;
  height: 22px;
}

.brand-text {
  display: flex;
  flex-direction: column;
}

.brand-name {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(90deg, var(--text-primary), var(--primary-indigo-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-tagline {
  font-size: 0.74rem;
  color: var(--text-secondary);
  font-weight: 400;
}

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

.header-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.9rem;
  border-radius: var(--radius-full);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  font-size: 0.86rem;
  font-weight: 500;
  transition: all var(--transition-fast);
  position: relative;
}

.header-btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-focus);
  transform: translateY(-1px);
}

.btn-icon {
  width: 18px;
  height: 18px;
}

.counter-badge {
  background: linear-gradient(135deg, var(--accent-emerald), #059669);
  color: #ffffff;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.15rem 0.55rem;
  border-radius: var(--radius-full);
  box-shadow: 0 2px 8px var(--accent-emerald-glow);
  transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.counter-badge.bump {
  transform: scale(1.25);
}

/* Floating +1 Animation */
.plus-one-float {
  position: absolute;
  top: -8px;
  left: 12px;
  font-size: 0.85rem;
  font-weight: 800;
  color: var(--accent-emerald);
  pointer-events: none;
  opacity: 0;
  transform: translateY(0);
}

.plus-one-float.animate {
  animation: floatUp 0.8s ease-out forwards;
}

@keyframes floatUp {
  0% { opacity: 0; transform: translateY(4px) scale(0.8); }
  30% { opacity: 1; transform: translateY(-10px) scale(1.2); }
  100% { opacity: 0; transform: translateY(-24px) scale(1); }
}

.theme-btn {
  padding: 0.55rem;
  border-radius: var(--radius-full);
}

/* ==========================================================================
   Main Content Views
   ========================================================================== */
.main-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 4rem;
}

.view-section {
  display: none;
  opacity: 0;
  transition: opacity var(--transition-normal);
}

.view-section.active {
  display: block;
  opacity: 1;
}

/* ==========================================================================
   1. Library View
   ========================================================================== */
.hero-banner {
  margin-bottom: 2.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.hero-content {
  max-width: 760px;
}

.hero-title {
  font-size: 2.15rem;
  font-weight: 800;
  letter-spacing: -0.025em;
  line-height: 1.25;
  margin-bottom: 0.65rem;
  background: linear-gradient(135deg, var(--text-primary) 30%, var(--primary-indigo-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.hero-subtitle {
  font-size: 1.05rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

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

.level-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.level-pill {
  padding: 0.45rem 0.95rem;
  border-radius: var(--radius-full);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 0.86rem;
  font-weight: 600;
  transition: all var(--transition-fast);
}

.level-pill:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

.level-pill.active {
  background: var(--primary-indigo);
  color: #ffffff;
  border-color: var(--primary-indigo);
  box-shadow: 0 4px 14px var(--primary-indigo-glow);
}

.search-box {
  position: relative;
  min-width: 280px;
  flex-grow: 1;
  max-width: 360px;
}

.search-icon {
  position: absolute;
  top: 50%;
  right: 12px;
  transform: translateY(-50%);
  width: 17px;
  height: 17px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-box input {
  width: 100%;
  padding: 0.55rem 2.4rem 0.55rem 1rem;
  border-radius: var(--radius-full);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  font-size: 0.88rem;
  font-family: inherit;
  outline: none;
  transition: all var(--transition-fast);
}

.search-box input:focus {
  border-color: var(--primary-indigo);
  box-shadow: 0 0 0 3px var(--primary-indigo-glow);
}

/* Stories Grid */
.stories-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1.5rem;
}

.story-card {
  background: var(--bg-card);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: all var(--transition-normal);
  cursor: pointer;
  position: relative;
}

.story-card:hover {
  transform: translateY(-5px);
  border-color: var(--border-focus);
  box-shadow: var(--shadow-elevated);
}

.story-card-cover-wrap {
  width: 100%;
  height: 195px;
  position: relative;
  overflow: hidden;
  background-color: var(--bg-secondary);
}

.story-card-cover {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.5s ease;
}

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

.story-card-level {
  position: absolute;
  top: 12px;
  right: 12px;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(8px);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.story-card-level.Pre-A1,
.story-card-level.pre-a1 { color: #facc15; border-color: rgba(250, 204, 21, 0.5); background: rgba(45, 36, 10, 0.88); }
.story-card-level.A1 { color: #34d399; border-color: rgba(52, 211, 153, 0.3); }
.story-card-level.A2 { color: #38bdf8; border-color: rgba(56, 189, 248, 0.3); }
.story-card-level.B1 { color: #818cf8; border-color: rgba(129, 140, 248, 0.3); }
.story-card-level.B2 { color: #c084fc; border-color: rgba(192, 132, 252, 0.3); }
.story-card-level.C1 { color: #f472b6; border-color: rgba(244, 114, 182, 0.3); }

.story-card-mood {
  position: absolute;
  bottom: 10px;
  right: 12px;
  font-size: 0.72rem;
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-full);
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(6px);
  color: var(--text-secondary);
}

.story-card-body {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  flex-grow: 1;
}

.story-card-title-he {
  font-size: 1.22rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.2rem;
}

.story-card-title-en {
  font-family: var(--font-story);
  font-size: 0.95rem;
  color: var(--text-secondary);
  font-style: italic;
  margin-bottom: 0.85rem;
}

.story-card-meta {
  margin-top: auto;
  padding-top: 0.85rem;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.story-card-read-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-weight: 600;
  color: var(--primary-indigo-light);
  transition: transform var(--transition-fast);
}

.story-card:hover .story-card-read-btn {
  transform: translateX(-4px);
}

/* Loading State */
.loading-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 4rem 1rem;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.spinner {
  width: 38px;
  height: 38px;
  border: 3px solid var(--border-subtle);
  border-top-color: var(--primary-indigo);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ==========================================================================
   2. Reader View
   ========================================================================== */
.reader-nav-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  gap: 1rem;
}

.nav-back-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.95rem;
  border-radius: var(--radius-full);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  font-size: 0.88rem;
  font-weight: 600;
  transition: all var(--transition-fast);
}

.nav-back-btn svg {
  width: 17px;
  height: 17px;
}

.nav-back-btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-focus);
}

.reader-meta-title {
  text-align: center;
  display: flex;
  flex-direction: column;
}

.reader-meta-title .title-en {
  font-family: var(--font-story);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
}

.reader-meta-title .title-he {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.reader-badge-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.level-badge {
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-weight: 700;
  background: var(--primary-indigo);
  color: #ffffff;
}

.mood-badge {
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-full);
  font-size: 0.78rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
}

/* Atmospheric Animated Header (Ken Burns + Canvas Particles) */
.story-atmosphere-header {
  position: relative;
  width: 100%;
  height: 340px;
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-elevated);
  background: #000;
}

.kenburns-wrapper {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.kenburns-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  animation: kenburns 26s infinite alternate cubic-bezier(0.4, 0, 0.2, 1);
  transform-origin: center center;
  will-change: transform;
}

.kenburns-video {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 1;
}

.video-badge {
  display: inline-block;
  font-size: 0.74rem;
  font-weight: 700;
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-full);
  background: rgba(16, 185, 129, 0.28);
  border: 1px solid rgba(16, 185, 129, 0.5);
  color: #a7f3d0;
  backdrop-filter: blur(8px);
  margin-bottom: 0.45rem;
}

@keyframes kenburns {
  0% {
    transform: scale(1.0) translate(0%, 0%);
  }
  50% {
    transform: scale(1.12) translate(-1.5%, -1%);
  }
  100% {
    transform: scale(1.06) translate(1.5%, 0.8%);
  }
}

.atmosphere-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
  mix-blend-mode: screen;
}

.atmosphere-gradient-overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  background: linear-gradient(
    to bottom,
    rgba(9, 13, 22, 0.15) 0%,
    rgba(9, 13, 22, 0.35) 50%,
    rgba(9, 13, 22, 0.88) 100%
  );
}

.atmosphere-caption {
  position: absolute;
  bottom: 24px;
  right: 28px;
  left: 28px;
  z-index: 4;
  color: #ffffff;
  pointer-events: none;
}

.atmosphere-caption h2 {
  font-family: var(--font-story);
  font-size: 1.95rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.8);
}

.atmosphere-caption p {
  font-size: 0.95rem;
  color: rgba(255, 255, 255, 0.8);
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.8);
}

/* Sticky Audio Player Bar */
.sticky-player-bar {
  position: sticky;
  top: 68px;
  z-index: 90;
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  margin-bottom: 1.75rem;
  padding: 0.75rem 1.25rem;
}

.player-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.25rem;
}

.player-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.control-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  border-radius: var(--radius-full);
  color: var(--text-primary);
  transition: all var(--transition-fast);
}

.play-btn {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, var(--primary-indigo), var(--accent-emerald));
  color: #ffffff;
  box-shadow: 0 4px 14px var(--primary-indigo-glow);
}

.play-btn:hover {
  transform: scale(1.06);
}

.play-btn svg {
  width: 20px;
  height: 20px;
}

.text-btn {
  padding: 0.4rem 0.65rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  font-size: 0.78rem;
  font-weight: 600;
}

.text-btn svg {
  width: 15px;
  height: 15px;
}

.text-btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-focus);
}

.player-center {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  flex-grow: 1;
  max-width: 580px;
}

.time-label {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--text-secondary);
  min-width: 44px;
  text-align: center;
}

.progress-track {
  flex-grow: 1;
  height: 8px;
  background: var(--bg-surface);
  border-radius: var(--radius-full);
  position: relative;
  cursor: pointer;
  overflow: visible;
  border: 1px solid var(--border-subtle);
}

.progress-fill {
  position: absolute;
  top: 0;
  right: 0;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-emerald), var(--primary-indigo));
  border-radius: var(--radius-full);
  pointer-events: none;
  transition: width 0.05s linear;
}

/* In RTL, progress fill originates from right */
html[dir="rtl"] .progress-fill {
  right: 0;
  left: auto;
}

.progress-thumb {
  position: absolute;
  top: 50%;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 0 8px rgba(0, 0, 0, 0.4);
  transform: translate(50%, -50%);
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.progress-track:hover .progress-thumb {
  opacity: 1;
}

.player-right {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.speed-selector {
  display: flex;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  padding: 2px;
}

.speed-btn {
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius-full);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  transition: all var(--transition-fast);
}

.speed-btn.active {
  background: var(--primary-indigo);
  color: #ffffff;
}

.autoscroll-btn {
  padding: 0.45rem 0.75rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  font-size: 0.8rem;
  font-weight: 600;
}

.autoscroll-btn svg {
  width: 15px;
  height: 15px;
}

.autoscroll-btn.active {
  background: var(--bg-card-hover);
  color: var(--accent-emerald);
  border-color: var(--accent-emerald);
}

/* Reader Body & Tokens Stream */
.reader-body {
  margin-top: 1rem;
}

.reader-card {
  background: var(--bg-card);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 2.25rem 2.5rem;
  box-shadow: var(--shadow-elevated);
}

.reader-instructions {
  font-size: 0.86rem;
  color: var(--text-secondary);
  background: var(--bg-surface);
  border: 1px dashed var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.65rem 1rem;
  margin-bottom: 2rem;
  text-align: center;
}

.story-tokens-stream {
  font-family: var(--font-story);
  font-size: 1.45rem;
  line-height: 2.25;
  color: var(--text-primary);
  text-rendering: optimizeLegibility;
  word-spacing: 0.08em;
  letter-spacing: 0.01em;
  user-select: none;
}

/* Word Token Styling */
.word-token {
  display: inline;
  padding: 0.15rem 0.3rem;
  margin: 0 0.08rem;
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.12s ease-out;
  position: relative;
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(99, 102, 241, 0.15);
}

.word-token:hover {
  background: rgba(99, 102, 241, 0.18);
  color: var(--primary-indigo-light);
}

/* Synchronized Active Word (Karaoke Effect) */
.word-token.active-word {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.38), rgba(16, 185, 129, 0.32));
  color: #ffffff !important;
  box-shadow: 0 0 16px rgba(99, 102, 241, 0.55), 0 2px 6px rgba(0, 0, 0, 0.3);
  border-radius: 6px;
  font-weight: 600;
  transform: translateY(-1px);
}

/* Words marked to learn */
.word-token.learning-word {
  background: rgba(16, 185, 129, 0.15);
  text-decoration: underline dotted var(--accent-emerald);
  text-underline-offset: 6px;
  text-decoration-thickness: 2px;
  border-radius: 4px;
}

.word-token.paragraph-break::after {
  content: "";
  display: block;
  height: 1.4rem;
}

/* ==========================================================================
   Interactive Floating Popover
   ========================================================================== */
.word-popover {
  position: fixed;
  z-index: 2000;
  width: 320px;
  max-width: 92vw;
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  direction: rtl;
  opacity: 0;
  transform: translateY(8px) scale(0.96);
  pointer-events: none;
  transition: opacity 0.18s ease-out, transform 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}

.word-popover.visible {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.popover-arrow {
  position: absolute;
  width: 12px;
  height: 12px;
  background: inherit;
  border-left: 1px solid var(--glass-border);
  border-top: 1px solid var(--glass-border);
  transform: rotate(45deg);
  pointer-events: none;
}

.word-popover.arrow-bottom .popover-arrow {
  bottom: -7px;
  border-left: none;
  border-top: none;
  border-right: 1px solid var(--glass-border);
  border-bottom: 1px solid var(--glass-border);
}

.word-popover.arrow-top .popover-arrow {
  top: -7px;
  border-right: none;
  border-bottom: none;
  border-left: 1px solid var(--glass-border);
  border-top: 1px solid var(--glass-border);
}

.popover-inner {
  padding: 1.15rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.popover-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 0.65rem;
}

.lemma-group {
  display: flex;
  flex-direction: column;
  direction: ltr;
  text-align: left;
}

.popover-lemma {
  font-family: var(--font-story);
  font-size: 1.22rem;
  font-weight: 700;
  color: var(--primary-indigo-light);
}

.popover-ipa {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--text-muted);
}

.popover-actions-right {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.popover-icon-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.popover-icon-btn:hover {
  background: var(--primary-indigo);
  color: #ffffff;
  border-color: var(--primary-indigo);
}

.popover-icon-btn svg {
  width: 15px;
  height: 15px;
}

.cefr-mini-badge {
  font-size: 0.72rem;
  font-weight: 800;
  padding: 0.15rem 0.45rem;
  border-radius: var(--radius-full);
  background: var(--primary-indigo-glow);
  color: var(--primary-indigo-light);
  border: 1px solid var(--primary-indigo);
}

.close-btn {
  font-size: 0.95rem;
}

.popover-translation-box {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.75rem 0.85rem;
}

.popover-hebrew {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.35rem;
}

.context-token-preview {
  font-size: 0.76rem;
  color: var(--text-muted);
  direction: rtl;
}

.context-token-preview strong {
  font-family: var(--font-story);
  color: var(--text-secondary);
  direction: ltr;
  display: inline-block;
}

.popover-footer {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.popover-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 600;
  transition: all var(--transition-fast);
}

.popover-btn svg {
  width: 14px;
  height: 14px;
}

.btn-known {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
}

.btn-known:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
  border-color: var(--border-focus);
}

.btn-learn {
  background: linear-gradient(135deg, var(--accent-emerald), #059669);
  color: #ffffff;
  box-shadow: 0 2px 10px var(--accent-emerald-glow);
}

.btn-learn:hover {
  transform: translateY(-1px);
  filter: brightness(1.08);
}

.btn-play-from {
  grid-column: 1 / -1;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--primary-indigo-light);
  font-size: 0.8rem;
  margin-top: 0.15rem;
}

.btn-play-from:hover {
  background: var(--primary-indigo-glow);
  border-color: var(--primary-indigo);
}

/* ==========================================================================
   Vocabulary Drawer / Modal
   ========================================================================== */
.vocab-drawer {
  position: fixed;
  inset: 0;
  z-index: 3000;
  visibility: hidden;
  transition: visibility var(--transition-normal);
}

.vocab-drawer.open {
  visibility: visible;
}

.drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  opacity: 0;
  transition: opacity var(--transition-normal);
}

.vocab-drawer.open .drawer-backdrop {
  opacity: 1;
}

.drawer-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 420px;
  max-width: 90vw;
  background: var(--bg-surface);
  border-left: 1px solid var(--border-subtle);
  box-shadow: -10px 0 40px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform var(--transition-normal);
  z-index: 2;
}

.vocab-drawer.open .drawer-panel {
  transform: translateX(0);
}

.drawer-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.drawer-title-group {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.drawer-title-group h3 {
  font-size: 1.15rem;
  font-weight: 700;
}

.drawer-count {
  font-size: 0.76rem;
  font-weight: 600;
  padding: 0.15rem 0.55rem;
  border-radius: var(--radius-full);
  background: var(--primary-indigo-glow);
  color: var(--primary-indigo-light);
}

.drawer-close-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-primary);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  transition: all var(--transition-fast);
}

.drawer-close-btn:hover {
  color: var(--text-primary);
  background: var(--bg-card-hover);
}

.drawer-search {
  padding: 0.85rem 1.5rem;
  border-bottom: 1px solid var(--border-subtle);
}

.drawer-search input {
  width: 100%;
  padding: 0.55rem 0.95rem;
  border-radius: var(--radius-sm);
  background: var(--bg-primary);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.85rem;
  outline: none;
}

.drawer-search input:focus {
  border-color: var(--primary-indigo);
}

.drawer-body {
  flex-grow: 1;
  overflow-y: auto;
  padding: 1rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.vocab-item-card {
  background: var(--bg-primary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.85rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.85rem;
  transition: all var(--transition-fast);
}

.vocab-item-card:hover {
  border-color: var(--border-focus);
  transform: translateX(-2px);
}

.vocab-item-content {
  flex-grow: 1;
}

.vocab-item-header {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  direction: ltr;
  text-align: left;
}

.vocab-item-lemma {
  font-family: var(--font-story);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
}

.vocab-item-ipa {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
}

.vocab-item-he {
  font-size: 0.88rem;
  color: var(--accent-emerald-light);
  font-weight: 600;
  margin-top: 0.2rem;
}

.vocab-item-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.vocab-action-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.vocab-action-btn:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

.vocab-action-btn.delete:hover {
  background: var(--accent-rose);
  color: #ffffff;
  border-color: var(--accent-rose);
}

.vocab-action-btn svg {
  width: 14px;
  height: 14px;
}

.drawer-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  gap: 0.75rem;
}

.drawer-footer-btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.6rem;
  border-radius: var(--radius-sm);
  background: var(--bg-primary);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  font-size: 0.82rem;
  font-weight: 600;
  transition: all var(--transition-fast);
}

.drawer-footer-btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-focus);
}

.drawer-footer-btn.danger:hover {
  background: rgba(244, 63, 94, 0.15);
  color: var(--accent-rose);
  border-color: var(--accent-rose);
}

.drawer-footer-btn svg {
  width: 14px;
  height: 14px;
}

/* Empty Vocab State */
.empty-vocab {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

/* ==========================================================================
   Responsive Breakpoints & Mobile Optimization
   ========================================================================== */
@media (max-width: 768px) {
  .header-container {
    padding: 0.65rem 1rem;
  }

  .brand-tagline {
    display: none;
  }

  .brand-name {
    font-size: 1.15rem;
  }

  .hero-title {
    font-size: 1.6rem;
    line-height: 1.3;
  }

  .hero-subtitle {
    font-size: 0.95rem;
  }

  .library-controls {
    flex-direction: column;
    align-items: stretch;
    gap: 0.85rem;
  }

  /* Horizontal swipe for level filter pills on mobile */
  .level-pills {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 0.25rem 0.25rem 0.5rem;
    margin: 0 -0.5rem;
    gap: 0.45rem;
  }

  .level-pills::-webkit-scrollbar {
    display: none;
  }

  .level-pill {
    flex-shrink: 0;
    white-space: nowrap;
    font-size: 0.84rem;
    padding: 0.42rem 0.85rem;
  }

  .search-box {
    width: 100%;
    max-width: 100%;
  }

  .stories-grid {
    grid-template-columns: 1fr;
    gap: 1.25rem;
  }

  .story-card-body {
    padding: 1rem 1.15rem;
  }

  .story-card-title-he {
    font-size: 1.15rem;
  }

  .story-atmosphere-header {
    height: 200px;
  }

  .atmosphere-caption h2 {
    font-size: 1.3rem;
  }

  .atmosphere-caption p {
    font-size: 0.85rem;
  }

  /* Compact touch-friendly sticky player bar on mobile */
  .sticky-player-bar {
    top: 56px;
    padding: 0.6rem 0.75rem;
    margin-bottom: 1.25rem;
  }

  .player-container {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
  }

  .player-left {
    order: 1;
    gap: 0.4rem;
  }

  .play-btn {
    width: 42px;
    height: 42px;
  }

  .text-btn {
    padding: 0.35rem 0.55rem;
    font-size: 0.75rem;
  }

  .player-right {
    order: 2;
    gap: 0.4rem;
  }

  .player-center {
    order: 3;
    width: 100%;
    max-width: 100%;
    margin-top: 0.25rem;
    gap: 0.6rem;
  }

  .time-slider {
    height: 6px;
  }

  .reader-card {
    padding: 1.25rem 0.95rem;
    border-radius: var(--radius-md);
  }

  .story-tokens-stream {
    font-size: 1.2rem;
    line-height: 2.2;
    letter-spacing: 0.01em;
  }

  .word-token {
    display: inline-block;
    padding: 0.2rem 0.35rem;
    margin: 0.12rem 0.06rem;
  }

  /* Popover constraints on mobile */
  .word-popover {
    width: 300px;
    max-width: calc(100vw - 20px);
    padding: 1rem;
  }

  .popover-lemma {
    font-size: 1.2rem;
  }

  .popover-translation {
    font-size: 1.15rem;
  }

  .popover-actions {
    flex-wrap: wrap;
    gap: 0.45rem;
  }

  .popover-btn {
    padding: 0.45rem 0.75rem;
    font-size: 0.82rem;
  }

  /* Drawer fullscreen on small mobile */
  .drawer-panel {
    width: 100%;
    max-width: 100vw;
  }

  .drawer-header {
    padding: 1rem 1.15rem;
  }

  .drawer-body {
    padding: 0.85rem 1rem;
  }
}

@media (max-width: 480px) {
  .header-actions .vocab-btn span:not(.vocab-badge) {
    display: none;
  }

  .vocab-btn {
    padding: 0.4rem 0.65rem;
  }

  .hero-title {
    font-size: 1.35rem;
  }

  .story-tokens-stream {
    font-size: 1.12rem;
    line-height: 2.15;
  }
}
