/* ============================================================
   Course narration — player chrome + read-along highlighting
   Pairs with course-tts.js. Uses the course design tokens where
   they exist and falls back to literals elsewhere.
   ============================================================ */

:root {
  --tts-accent: var(--accent, #1F8A4C);
  --tts-word: #FFD866;
  --tts-word-ink: #14261D;
  --tts-sent: rgba(31, 138, 76, 0.10);
  --tts-hover: rgba(31, 138, 76, 0.055);
  --tts-bar-h: 64px;
}

/* ---------- read-along highlighting ---------- */

::highlight(tts-sentence) {
  background-color: var(--tts-sent);
}
::highlight(tts-word) {
  background-color: var(--tts-word);
  color: var(--tts-word-ink);
}

/* Whole-block cue. With the Highlight API the sentence tint already carries
   the eye, so the block only gets a quiet marker in the margin; without it,
   the block tint IS the read-along. */
.tts-block-active {
  background: linear-gradient(90deg, rgba(31, 138, 76, 0.13), rgba(31, 138, 76, 0.04));
  box-shadow: -10px 0 0 rgba(31, 138, 76, 0.13), 10px 0 0 rgba(31, 138, 76, 0.04);
  border-radius: 3px;
}
.tts-hl-api .tts-block-active {
  background: none;
  box-shadow: -14px 0 0 -11px var(--tts-accent);
}

/* the little "play from here" handle that follows the hovered block */
.tts-handle {
  position: absolute;
  width: 30px; height: 30px;
  margin-left: -42px;
  display: none;
  align-items: center; justify-content: center;
  border: 1px solid var(--border, #E3E8E5);
  background: var(--bg-card, #fff);
  color: var(--tts-accent);
  border-radius: 50%;
  cursor: pointer;
  padding: 0;
  z-index: 40;
  box-shadow: 0 2px 8px rgba(15, 23, 20, 0.10);
  transition: transform 120ms cubic-bezier(0.2, 0, 0.2, 1), background 120ms;
}
.tts-handle.on { display: flex; }
.tts-handle:hover { transform: scale(1.12); background: var(--accent-soft, #EAF7EF); }
.tts-handle svg { width: 13px; height: 13px; fill: currentColor; }
@media (max-width: 1080px) { .tts-handle { display: none !important; } }

/* ---------- click-to-play (voice mode only) ---------- */

/* Once the player is open, a plain click on any readable block starts the
   narration there (course-tts.js). `.tts-clickable` is applied by the same
   pass that builds the click index, so this only ever matches blocks that
   really are clickable. Scoped under body.tts-active - added/removed by
   openPlayer()/closePlayer() - so nothing about ordinary reading changes
   while the player is closed. Kept deliberately quiet: a pointer cursor and
   a faint tint are enough to say "this is live" without looking like a
   button. */
body.tts-active .tts-clickable { cursor: pointer; }
body.tts-active .tts-clickable:hover {
  background: var(--tts-hover);
  border-radius: 3px;
}

/* ---------- "sign in to unlock the rest" hint ---------- */

/* Appended to .course-hero by updateContinueHint() only while the logged-out
   sign-in gate is still in the DOM - see the comment on that function for
   why this deliberately says nothing to a signed-in reader. */
.tts-continue-hint {
  margin: 10px 0 0;
  font: 500 13.5px/1.5 var(--font-sans, system-ui, sans-serif);
  color: var(--fg-muted, #7A8A82);
}
.tts-continue-hint a { color: var(--tts-accent); font-weight: 600; }

/* ---------- "back to reading" ---------- */

.tts-jump {
  position: fixed;
  left: 50%; bottom: 92px;
  transform: translateX(-50%) translateY(8px);
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 16px 9px 12px;
  font: 600 13.5px/1 var(--font-sans, system-ui, sans-serif);
  color: var(--fg, #14261D);
  background: var(--bg-card, #fff);
  border: 1px solid var(--border, #E3E8E5);
  border-radius: 999px;
  box-shadow: 0 6px 22px rgba(15, 23, 20, 0.16);
  cursor: pointer;
  z-index: 59;
  opacity: 0; pointer-events: none;
  transition: opacity 160ms, transform 160ms cubic-bezier(0.2, 0, 0.2, 1);
}
.tts-jump.on { opacity: 1; transform: translateX(-50%) translateY(0); pointer-events: auto; }
.tts-jump:hover { border-color: var(--tts-accent); }
.tts-jump .ar { display: inline-flex; color: var(--tts-accent); }
.tts-jump svg { width: 15px; height: 15px; fill: currentColor; transform: rotate(180deg); }
.tts-jump.up svg { transform: none; }

@media (max-width: 640px) {
  .tts-jump { bottom: 80px; font-size: 12.5px; padding: 8px 14px 8px 10px; }
}

/* ---------- hero call to action ---------- */

.tts-cta {
  display: inline-flex; align-items: center; gap: 10px;
  margin-top: 18px;
  padding: 11px 18px 11px 14px;
  font: 600 15px/1 var(--font-sans, system-ui, sans-serif);
  color: #fff; background: var(--tts-accent);
  border: none; border-radius: 999px; cursor: pointer;
  box-shadow: 0 3px 12px rgba(31, 138, 76, 0.28);
  transition: transform 120ms, box-shadow 120ms;
}
.tts-cta:hover { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(31, 138, 76, 0.34); }
.tts-cta .dot { display: inline-flex; }
.tts-cta svg { width: 16px; height: 16px; fill: currentColor; }
.tts-cta .meta { font-weight: 500; opacity: 0.82; }
.sidebar .tts-cta {
  width: 100%;
  justify-content: center;
  margin: 10px 0 18px;
  text-align: left;
}

/* ---------- player bar ---------- */

.tts-bar {
  position: fixed;
  left: 50%; bottom: 18px;
  transform: translateX(-50%) translateY(140%);
  width: min(760px, calc(100vw - 24px));
  background: var(--bg-card, #fff);
  border: 1px solid var(--border, #E3E8E5);
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(15, 23, 20, 0.18);
  font-family: var(--font-sans, system-ui, sans-serif);
  color: var(--fg, #14261D);
  z-index: 60;
  opacity: 0;
  transition: transform 260ms cubic-bezier(0.2, 0, 0.2, 1), opacity 200ms;
}
.tts-bar.open { transform: translateX(-50%) translateY(0); opacity: 1; }
.tts-bar[hidden] { display: none; }
.tts-bar:not(.open) { pointer-events: none; }

/* keep the last paragraph clear of the bar */
body.tts-reading { padding-bottom: 96px; }

.tts-scrub {
  position: relative;
  height: 5px;
  margin: 0 14px;
  border-radius: 3px;
  background: var(--bg-inset, #EEF2F0);
  cursor: pointer;
  margin-top: 10px;
}
.tts-scrub-fill {
  position: absolute; inset: 0 auto 0 0;
  width: 0;
  background: var(--tts-accent);
  border-radius: 3px;
  pointer-events: none;
}
.tts-scrub-knob {
  position: absolute; top: 50%; left: 0;
  width: 12px; height: 12px; margin: -6px 0 0 -6px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--tts-accent);
  pointer-events: none;
  opacity: 0;
  transition: opacity 120ms;
}
.tts-scrub:hover .tts-scrub-knob { opacity: 1; }

.tts-row {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px 10px;
}

.tts-btn {
  display: inline-flex; align-items: center; justify-content: center;
  height: 36px; min-width: 36px; padding: 0 8px;
  border: none; background: transparent;
  color: var(--fg-soft, #4A5A52);
  border-radius: 9px; cursor: pointer;
  font: 600 13px/1 var(--font-sans, system-ui, sans-serif);
  transition: background 120ms, color 120ms;
}
.tts-btn:hover { background: var(--bg-inset, #EEF2F0); color: var(--fg, #14261D); }
.tts-btn[aria-pressed="true"] { color: var(--tts-accent); background: var(--accent-soft, #EAF7EF); }
.tts-btn svg { width: 17px; height: 17px; fill: currentColor; }
.tts-btn:disabled { opacity: 0.35; cursor: default; }
.tts-btn:disabled:hover { background: transparent; }

.tts-play {
  height: 44px; width: 44px;
  background: var(--tts-accent); color: #fff;
  border-radius: 50%;
  flex: none;
}
.tts-play:hover { background: var(--accent-hover, #187A42); color: #fff; }
.tts-play svg { width: 19px; height: 19px; }

.tts-time {
  font: 500 12px/1 var(--font-mono, ui-monospace, monospace);
  color: var(--fg-muted, #7A8A82);
  white-space: nowrap;
  padding: 0 2px;
}
.tts-title {
  flex: 1 1 auto; min-width: 0;
  font: 600 13px/1.25 var(--font-sans, system-ui, sans-serif);
  color: var(--fg, #14261D);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tts-title span { display: block; font-weight: 500; font-size: 11.5px; color: var(--fg-muted, #7A8A82); }
.tts-rate { font-variant-numeric: tabular-nums; }

/* popovers (speed + settings) */
.tts-pop {
  position: absolute; bottom: calc(100% + 8px); right: 10px;
  min-width: 190px;
  background: var(--bg-card, #fff);
  border: 1px solid var(--border, #E3E8E5);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(15, 23, 20, 0.16);
  padding: 8px;
  display: none;
}
.tts-pop.open { display: block; }
.tts-pop h4 {
  margin: 4px 6px 6px;
  font: 600 11px/1 var(--font-sans, system-ui, sans-serif);
  letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--fg-muted, #7A8A82);
}
.tts-opt {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%;
  padding: 8px 10px;
  border: none; background: transparent;
  font: 500 13.5px/1 var(--font-sans, system-ui, sans-serif);
  color: var(--fg, #14261D);
  border-radius: 8px; cursor: pointer; text-align: left;
}
.tts-opt:hover { background: var(--bg-inset, #EEF2F0); }
.tts-opt[aria-checked="true"] { color: var(--tts-accent); font-weight: 650; }
.tts-opt[aria-checked="true"]::after { content: "✓"; font-size: 13px; }
.tts-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.tts-grid .tts-opt { justify-content: center; padding: 9px 4px; }
.tts-grid .tts-opt[aria-checked="true"]::after { content: none; }
.tts-grid .tts-opt[aria-checked="true"] { background: var(--accent-soft, #EAF7EF); }

/* collapsed pill */
.tts-bar.mini { width: auto; }
.tts-bar.mini .tts-scrub,
.tts-bar.mini .tts-wide { display: none; }

@media (max-width: 640px) {
  .tts-bar { bottom: 10px; border-radius: 14px; }
  .tts-row { gap: 4px; padding: 6px 8px 8px; }
  .tts-hide-sm { display: none; }
  .tts-title { font-size: 12.5px; }
  .tts-time { font-size: 11px; }
  .tts-title span { display: none; }
  .tts-play { height: 40px; width: 40px; }
  body.tts-reading { padding-bottom: 84px; }
}

@media (prefers-reduced-motion: reduce) {
  .tts-bar, .tts-cta, .tts-handle { transition: none; }
}
