/* ── Apple-Lyrics-Style Subtitle Scroller ─────────────────────────────── */

.lyrics-container {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  overflow-x: hidden;
  /* Fade edges for cinematic feel */
  mask-image: linear-gradient(to bottom,
      transparent 0%,
      black 12%,
      black 88%,
      transparent 100%);
  -webkit-mask-image: linear-gradient(to bottom,
      transparent 0%,
      black 12%,
      black 88%,
      transparent 100%);
  /* Hide scrollbar but keep scrollable */
  scrollbar-width: none;
}

.lyrics-container::-webkit-scrollbar {
  display: none;
}

.lyrics-scroll-wrapper {
  padding: 40vh 0;
  /* generous top/bottom padding so first/last lines can center */
}

/* ── Individual lyric lines ────────────────────────────────────────────── */
.lyrics-line {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  padding: 10px 40px 10px 16px;
  font-size: 1.45rem;
  font-weight: 600;
  line-height: 1.55;
  position: relative;

  /* Default: far-away state */
  opacity: 0.15;
  color: var(--text-muted);
  transform: scale(0.94);
  filter: blur(1.5px);

  will-change: opacity, transform, filter;
  transition:
    opacity 0.5s cubic-bezier(0.4, 0, 0.2, 1),
    transform 0.5s cubic-bezier(0.4, 0, 0.2, 1),
    filter 0.5s cubic-bezier(0.4, 0, 0.2, 1),
    color 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Play button on each line ─────────────────────────────────────────── */
.line-play-btn {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  margin-right: 8px;
  margin-top: 2px;
  border-radius: 50%;
  background: transparent;
  color: var(--accent);
  font-size: 0.7rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s, background 0.2s;
  pointer-events: none;
}

.lyrics-line:hover .line-play-btn {
  opacity: 0.7;
  pointer-events: auto;
}

.lyrics-line:hover .line-play-btn:hover {
  opacity: 1;
  background: rgba(78, 205, 196, 0.15);
}

.line-text {
  flex: 1;
  min-width: 0;
}

/* ── Distance-based classes ────────────────────────────────────────────── */

/* ±1 away from active */
.lyrics-line.near {
  opacity: 0.5;
  color: var(--text-muted);
  transform: scale(0.98);
  filter: blur(0);
}

/* ±2 away from active */
.lyrics-line.far {
  opacity: 0.3;
  color: var(--text-muted);
  transform: scale(0.96);
  filter: blur(0.5px);
}

/* Active line — hero state */
.lyrics-line.active {
  opacity: 1;
  color: var(--text-primary);
  transform: scale(1.04);
  filter: blur(0);
}

/* Hover on non-active lines */
.lyrics-line:not(.active):hover {
  opacity: 0.7;
  filter: blur(0);
}

/* ── Partial / typing state ────────────────────────────────────────────── */
.lyrics-line.partial {
  /* Slightly dimmer, italic to signal in-progress */
  font-style: italic;
  opacity: 0.7;
  color: var(--text-muted);
  transform: scale(1.01);
  filter: blur(0);
}


/* ── Word-level spans ─────────────────────────────────────────────────── */
.lyrics-line .word {
  display: inline;
  cursor: pointer;
}

.lyrics-line .word:hover {
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-underline-offset: 3px;
}

/* ── Frosted-glass word highlight (active line with timestamps) ───────── */

/* Base: all words in active+timestamped line are inline-block for transforms */
.lyrics-line.active.has-word-timestamps .word {
  display: inline-block;
  transition:
    opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1),
    filter 0.25s cubic-bezier(0.4, 0, 0.2, 1),
    transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Future words: dimmed, no blur */
.lyrics-line.active.has-word-timestamps .word.word-future {
  opacity: 0.3;
  transform: scale(1);
}

/* Past words: clear, fully revealed */
.lyrics-line.active.has-word-timestamps .word.word-past {
  opacity: 1;
  transform: scale(1);
}

/* Current word: clear + slightly enlarged */
.lyrics-line.active.has-word-timestamps .word.word-active {
  opacity: 1;
  transform: scale(1.12);
  color: var(--accent);
}

/* Before any word is active, show all dimmed */
.lyrics-line.active.has-word-timestamps .word:not(.word-past):not(.word-active):not(.word-future) {
  opacity: 0.3;
}


/* Fallback: no word timestamps — all words full opacity, no effect */
.lyrics-line.active:not(.has-word-timestamps) .word {
  opacity: 1;
}

/* Non-active lines: words inherit line opacity, no individual effects */
.lyrics-line:not(.active) .word {
  filter: none;
  opacity: inherit;
}

/* ── User scrolling — make all lines readable ─────────────────────────── */
.lyrics-container.user-scrolling .lyrics-line {
  opacity: 0.7;
  filter: blur(0);
  transform: scale(1);
  color: var(--text-muted);
}

.lyrics-container.user-scrolling .lyrics-line.active {
  opacity: 1;
  color: var(--text-primary);
  transform: scale(1);
}

/* Disable frosted word effect while scrolling */
.lyrics-container.user-scrolling .lyrics-line.active.has-word-timestamps .word {
  opacity: 1;
  filter: blur(0);
  transform: scale(1);
}

/* ── Back-to-current button ───────────────────────────────────────────── */
.lyrics-back-btn {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  padding: 8px 20px;
  border-radius: 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 15;
  backdrop-filter: blur(10px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.lyrics-back-btn.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}

.lyrics-back-btn:hover {
  background: var(--accent);
  color: #000;
}

/* ── Refined line + translation ───────────────────────────────────────── */

/* Brief accent-highlight when a subtitle is corrected in-place */
@keyframes refined-flash {
  0%   { background-color: rgba(78, 205, 196, 0.18); border-radius: 6px; }
  100% { background-color: transparent; }
}

.lyrics-line.refined {
  animation: refined-flash 1.2s ease-out forwards;
}

.lyrics-line .line-text {
  display: block;
}

.lyrics-line .line-translation {
  flex: 1 1 100%;
  font-size: 0.82em;
  font-weight: 400;
  color: var(--text-muted);
  margin-top: 2px;
  margin-left: 36px;
  /* align with text (past play button) */
  line-height: 1.4;
  opacity: 0.7;
}

.lyrics-line.active .line-translation {
  opacity: 1;
  color: var(--accent-dim);
}

/* Hide translations when toggled off */
.lyrics-container.hide-translations .line-translation {
  display: none;
}

[data-theme="light"] .lyrics-line.active .line-translation {
  color: #2a7a76;
}

/* ── Empty / placeholder state ─────────────────────────────────────────── */
.lyrics-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-sub);
  font-size: 1rem;
  pointer-events: none;
  opacity: 0.6;
}

/* ── Mobile ───────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .lyrics-line {
    padding: 8px 12px 8px 8px;
    font-size: 1.15rem;
    line-height: 1.45;
  }

  .line-play-btn {
    width: 24px;
    height: 24px;
    margin-right: 6px;
    font-size: 0.6rem;
  }

  .lyrics-back-btn {
    bottom: 12px;
    padding: 6px 16px;
    font-size: 0.75rem;
  }

  .lyrics-line.active {
    transform: scale(1.02);
  }

  .lyrics-scroll-wrapper {
    padding: 30vh 0;
  }

  /* Smaller word scale on mobile to avoid overflow */
  .lyrics-line.active.has-word-timestamps .word.word-active {
    transform: scale(1.08);
  }
}

/* ── Light theme overrides ─────────────────────────────────────────────── */
[data-theme="light"] .lyrics-line.active {
  color: #111;
}

[data-theme="light"] .lyrics-line.near,
[data-theme="light"] .lyrics-line.far,
[data-theme="light"] .lyrics-line {
  color: #888;
}