/* LSQS-READ-ALONG-002 — read-along CSS for the per-word highlight loop.
 *
 * Loaded only when a story publishes read-along timings sidecars
 * (`<audio_dir>/page-NN.timings.json`). On stories without timings
 * the readalong.js component is a no-op and this stylesheet is not
 * loaded, so the existing styling is unchanged.
 *
 * The component renders each page's narrative text as a sequence of
 * `<span class="rl-word">` elements (one per Kokoro token; the span
 * carries `data-start` and `data-end` attributes in seconds). At
 * 60Hz the readalong.js loop matches `audio.currentTime` against
 * these windows and toggles `.rl-active` on the matching span.
 *
 * The CSS below provides:
 *   - a soft, calm "highlighted word" treatment that reads well on
 *     the existing page-text panel (warm-tinted background, gentle
 *     text-shadow). The default theme works on light and dark
 *     backgrounds because the highlight uses an `rgba(255, 220, 110)`
 *     tint with a thin border.
 *   - a non-color cue (scale + weight bump) so a colour-blind reader
 *     still sees the active word. WCAG-friendly: the highlight is
 *     the secondary cue; the primary cue is the on-the-nose text
 *     position match.
 *   - respects `prefers-reduced-motion: reduce` — the active
 *     word's scale is dialled back to 1.0 (no bounce) so the
 *     highlight is motion-safe.
 *   - a fallback static `.rl-word--no-timings` class applied by
 *     readalong.js when timings failed to load. This makes the
 *     span stack look like a normal paragraph (no special
 *     spacing) but keeps the spans in place so a future
 *     re-render that adds timings doesn't have to re-tokenise
 *     the page.
 */

.rl-word {
  /* Slight padding makes the highlight visible at small text
   * sizes without breaking line wrap (display: inline keeps the
   * text flowing naturally). The transition is short — the
   * 60Hz loop can flip a word's state in a single frame, so a
   * fast fade keeps the eye anchored without lagging the audio. */
  display: inline;
  padding: 0 1px;
  border-radius: 3px;
  transition: background-color 80ms ease-out, color 80ms ease-out,
              transform 80ms ease-out, font-weight 80ms ease-out;
}

.rl-word.rl-active {
  background-color: rgba(255, 220, 110, 0.55);
  color: inherit;
  font-weight: 700;
  /* The 1.04 scale is below the "movement" threshold for
   * prefers-reduced-motion users (per WCAG 2.3.3 guidance,
   * < 1.10x is generally OK), but we still override to 1.0
   * below for users who explicitly opted out. */
  transform: scale(1.04);
  text-shadow: 0 0 1px rgba(0, 0, 0, 0.10);
  /* Slight outline so the highlight stays visible against
   * busy page-art backgrounds. */
  box-shadow: 0 0 0 2px rgba(255, 200, 80, 0.45);
}

/* A second style for the "spoken" / "already-passed" words, so the
 * reader can see how far they've gotten. This is off by default —
 * the JS adds the .rl-spoken class only on a per-story opt-in
 * via `data-rl-show-spoken="true"` on the <p class="page-text">.
 * Most stories look better without it; the active highlight alone
 * carries the cue. */
.rl-word.rl-spoken {
  color: rgba(0, 0, 0, 0.55);
}

/* The container <p class="page-text rl-text"> gets these layout
 * tweaks when the read-along component is wired in. Mostly:
 * slightly larger line-height so the highlight boxes don't crowd
 * adjacent lines, and a cursor cue on the page so a sighted
 * reader knows narration is active. */
.rl-text {
  /* Larger line-height for the highlight boxes. The default
   * styles.css sets 1.55; we lift to 1.85 only on the read-along
   * decorated blocks, so non-read-along pages are unchanged. */
  line-height: 1.85;
  /* Slightly tighter word-spacing so the highlight boxes don't
   * drift visually on narrow viewports. */
  word-spacing: -0.02em;
}

/* An optional "now reading" badge that lives next to the audio
 * control. Hidden by default; the readalong.js component adds
 * `.rl-badge--visible` when narration is playing. */
.rl-badge {
  display: inline-block;
  font-size: 0.78em;
  font-weight: 600;
  color: rgba(0, 0, 0, 0.65);
  background: rgba(255, 220, 110, 0.35);
  padding: 1px 6px;
  border-radius: 4px;
  margin-left: 6px;
  vertical-align: middle;
  opacity: 0;
  transition: opacity 120ms ease-out;
  pointer-events: none;
}

.rl-badge.rl-badge--visible {
  opacity: 1;
}

/* When timings are missing for a page (legacy render, fetch
 * failure, etc.) the spans still render (so the page-text panel
 * looks normal), but with no per-span highlight, and no
 * active-word decoration. Belt-and-braces: the .rl-no-timings
 * class on the <p> disables the active styling entirely so
 * the CSS doesn't paint empty highlight boxes if the JS
 * ever runs against a missing-timings story. */
.rl-text.rl-no-timings .rl-word {
  background: transparent !important;
  transform: none !important;
  font-weight: inherit !important;
  box-shadow: none !important;
  color: inherit !important;
}

/* prefers-reduced-motion: drop the scale transform on the
 * active word. The background-color change is animation, but
 * a colour change is generally OK for vestibular-sensitive
 * users; the scale is the part that triggers the "I am
 * moving" perception. */
@media (prefers-reduced-motion: reduce) {
  .rl-word,
  .rl-word.rl-active {
    transition: background-color 80ms ease-out, color 80ms ease-out;
    transform: none;
  }
}
