/* ============================================================
   AUDIO PLAYER — synchronized read-along for chapter pages.
   Floats a thin player bar at the bottom of the viewport.
   ============================================================ */

.audio-player {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 1rem;
  background: linear-gradient(180deg, rgba(34, 24, 18, 0.94) 0%, rgba(20, 14, 12, 0.98) 100%);
  color: #f4ecd8;
  font-family: "Inter", system-ui, sans-serif;
  font-size: 0.85rem;
  z-index: 100;
  border-top: 2px solid #8a6b1f;
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.4);
  transform: translateY(0);
  transition: transform 0.25s ease;
}
.audio-player.hidden {
  transform: translateY(110%);
}
.audio-player .ap-play {
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 50%;
  background: #8a6b1f;
  border: none;
  color: #fbf7ec;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
}
.audio-player .ap-play:hover {
  background: #a3823b;
}
.audio-player .ap-play:active {
  transform: scale(0.95);
}
.audio-player .ap-play svg {
  width: 1rem;
  height: 1rem;
  fill: #fbf7ec;
}

.audio-player .ap-progress-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
}
.audio-player .ap-time {
  font-variant-numeric: tabular-nums;
  font-size: 0.78rem;
  color: rgba(244, 236, 216, 0.7);
  letter-spacing: 0.04em;
  white-space: nowrap;
}
.audio-player .ap-bar {
  flex: 1;
  height: 4px;
  background: rgba(244, 236, 216, 0.18);
  border-radius: 4px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.audio-player .ap-bar-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0%;
  background: #d4a84a;
  transition: width 0.12s linear;
  border-radius: 4px;
}
.audio-player .ap-bar-buffer {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0%;
  background: rgba(212, 168, 74, 0.25);
  border-radius: 4px;
}

.audio-player .ap-speed,
.audio-player .ap-track,
.audio-player .ap-close {
  background: rgba(244, 236, 216, 0.10);
  border: 1px solid rgba(244, 236, 216, 0.18);
  color: #f4ecd8;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 500;
  padding: 0.32rem 0.6rem;
  border-radius: 0.3rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}
.audio-player .ap-speed:hover,
.audio-player .ap-track:hover,
.audio-player .ap-close:hover {
  background: rgba(244, 236, 216, 0.18);
}

.audio-player .ap-track.active {
  background: rgba(212, 168, 74, 0.30);
  border-color: #d4a84a;
  color: #fbf7ec;
}

.audio-player .ap-error {
  color: #e58a96;
  font-size: 0.8rem;
  font-style: italic;
}

/* Toggle button (shown when player is hidden) */
.audio-toggle {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  width: 3rem;
  height: 3rem;
  border-radius: 50%;
  background: #8a6b1f;
  color: #fbf7ec;
  border: 2px solid rgba(244, 236, 216, 0.18);
  cursor: pointer;
  z-index: 99;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.1s;
}
.audio-toggle:hover {
  background: #a3823b;
}
.audio-toggle:active {
  transform: scale(0.95);
}
.audio-toggle svg {
  width: 1.25rem;
  height: 1.25rem;
  fill: #fbf7ec;
}

/* ============================================================
   WORD HIGHLIGHTING — applied to .w spans during playback.
   The .w spans are injected by audio_player.js at runtime.
   ============================================================ */

.w {
  /* Default: invisible wrapper — preserves all inherited styling */
  display: inline;
  transition: background-color 0.15s ease;
  border-radius: 0.12em;
  padding: 0 0.04em;
  margin: 0 -0.04em;
}

.w.active {
  background-color: rgba(212, 168, 74, 0.35);
  box-shadow: 0 0 0 1px rgba(138, 107, 31, 0.45);
}

.w.played {
  /* Slight tint on words that have been read */
  background-color: rgba(212, 168, 74, 0.08);
}

/* Animation when the active word changes */
@keyframes word-pop {
  0% { background-color: rgba(212, 168, 74, 0.50); }
  100% { background-color: rgba(212, 168, 74, 0.35); }
}
.w.active {
  animation: word-pop 0.18s ease-out;
}

/* Auto-scroll target padding so highlighted word isn't at the very top */
body.audio-playing {
  scroll-behavior: smooth;
}

/* Dark mode highlighting */
body.dark .w.active {
  background-color: rgba(212, 168, 74, 0.50);
  box-shadow: 0 0 0 1px rgba(212, 168, 74, 0.65);
}
body.dark .w.played {
  background-color: rgba(212, 168, 74, 0.12);
}
