/* KidVerse listening controls
   audio.css — the Listen card in the reader, and the audiobook page.

   Two contexts, one stylesheet:

   In the reader the card sits inside .kv-reader-root, which defines its own
   --kv-* palette and swaps it for the Paper / Sepia / Sky / Night themes. Using
   those variables means the player follows all four for free.

   On audio.html there is no reader, so the same rules fall back to the site
   palette (--surface, --text, --muted, --line), which already has bright and
   dark versions. Hence the doubled var() fallbacks: they are what lets one set
   of rules live correctly in both places. */

.kv-audio {
  display: grid;
  gap: 0.6rem;
}

/* ── The play button ─────────────────────────────────────── */

.kv-audio-play {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  padding: 0.6rem 0.85rem;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  font-family: var(--kv-font-head, 'Baloo 2', cursive);
  font-size: 0.92rem;
  font-weight: 800;
  /* Dark ink on the amber pill: white on #ff9f1c is only 2.05:1. */
  color: #3b2400;
  background: linear-gradient(135deg, var(--kv-orange, #ff9f1c), var(--kv-orange-deep, #e07b00));
  box-shadow: 0 6px 18px rgba(224, 123, 0, 0.28);
  transition: transform 0.15s ease, box-shadow 0.2s ease, filter 0.2s ease;
}

.kv-audio-play:hover  { filter: brightness(1.04); transform: translateY(-1px); }
.kv-audio-play:active { transform: translateY(0); }
.kv-audio-play:focus-visible {
  outline: 3px solid var(--kv-orange-deep, #e07b00);
  outline-offset: 2px;
}

.kv-audio-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.6rem;
  height: 1.6rem;
  flex: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.55);
  font-size: 0.78rem;
  line-height: 1;
}

/* A gentle pulse while it is playing — enough to see at a glance which story is
   speaking, not enough to distract from reading along. */
.kv-audio-play.is-playing .kv-audio-icon {
  animation: kv-audio-pulse 1.8s ease-in-out infinite;
}

@keyframes kv-audio-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.7); }
  50%      { box-shadow: 0 0 0 6px rgba(255, 255, 255, 0); }
}

/* ── Scrubber ────────────────────────────────────────────── */

.kv-audio-scrub { display: grid; gap: 0.28rem; }

.kv-audio-track {
  position: relative;
  height: 8px;
  border-radius: 999px;
  cursor: pointer;
  background: var(--kv-faint, var(--bg-soft, #eef8ff));
  border: 1px solid var(--kv-border, var(--line, rgba(77, 101, 184, 0.18)));
  overflow: hidden;
}

.kv-audio-track:focus-visible {
  outline: 3px solid var(--kv-orange-deep, #e07b00);
  outline-offset: 3px;
}

.kv-audio-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--kv-orange, #ff9f1c), var(--kv-orange-deep, #e07b00));
  transition: width 0.2s linear;
}

.kv-audio-times {
  display: flex;
  justify-content: space-between;
  font-family: var(--kv-font-story, 'Nunito', sans-serif);
  font-size: 0.72rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--kv-muted, var(--muted, #5d6987));
}

/* ── Secondary controls ──────────────────────────────────── */

.kv-audio-row {
  display: flex;
  gap: 5px;
  align-items: center;
  justify-content: space-between;
}

.kv-audio-row .kv-chip { flex: 1; justify-content: center; }

.kv-audio-note {
  margin: 0;
  font-family: var(--kv-font-story, 'Nunito', sans-serif);
  font-size: 0.72rem;
  line-height: 1.45;
  color: var(--kv-muted, var(--muted, #5d6987));
}

.kv-audio-note a,
.kv-audio-dl {
  color: var(--kv-orange-deep, #b35c00);
  font-weight: 800;
  text-decoration: underline;
}

/* ── The paragraph being read ────────────────────────────── */

/* Deliberately a tint and a rule rather than a highlighter block: a child is
   reading these words while they are spoken, so contrast must not drop. */
.kv-story-body .kv-speaking {
  position: relative;
  border-radius: 12px;
  background: var(--kv-orange-pale, #fff4e0);
  box-shadow: inset 3px 0 0 var(--kv-orange, #ff9f1c);
  transition: background 0.3s ease, box-shadow 0.3s ease;
}

.kv-story-body .kv-speaking > * { position: relative; }

@media (prefers-reduced-motion: reduce) {
  .kv-audio-play.is-playing .kv-audio-icon { animation: none; }
  .kv-audio-fill { transition: none; }
  .kv-story-body .kv-speaking { transition: none; }
}

/* ═══════════════════════════════════════════════════════════
   THE AUDIOBOOK PAGE
═══════════════════════════════════════════════════════════ */

.kv-audio-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
}

.kv-audio-item {
  display: grid;
  grid-template-columns: 84px 1fr;
  gap: 14px;
  align-items: center;
  padding: 14px;
  border-radius: var(--radius-md, 18px);
  background: var(--surface, #fff);
  border: 1px solid var(--line, rgba(77, 101, 184, 0.12));
  box-shadow: 0 10px 26px rgba(67, 107, 181, 0.08);
}

.kv-audio-item img {
  width: 84px;
  height: 84px;
  border-radius: 14px;
  object-fit: cover;
  background: var(--bg-soft, #eef8ff);
}

.kv-audio-item h3 {
  margin: 0 0 2px;
  font-family: 'Baloo 2', cursive;
  font-size: 1.02rem;
  color: var(--text, #23314b);
}

.kv-audio-item p {
  margin: 0 0 8px;
  font-size: 0.82rem;
  line-height: 1.45;
  color: var(--muted, #5d6987);
}

.kv-audio-item .kv-audio-meta {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--muted, #5d6987);
}

.kv-audio-item .kv-audio-meta a { color: var(--brand-deep, #ff6b6b); }

.kv-audio-item audio {
  width: 100%;
  margin-top: 8px;
  height: 34px;
}

/* ── Feed address ────────────────────────────────────────── */

.kv-feed-box {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 10px;
}

.kv-feed-url {
  flex: 1 1 260px;
  min-width: 0;
  padding: 9px 12px;
  border-radius: 999px;
  border: 1px solid var(--line, rgba(77, 101, 184, 0.18));
  background: var(--bg-soft, #eef8ff);
  color: var(--text, #23314b);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.82rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.kv-feed-copy {
  padding: 9px 18px;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  font-family: 'Baloo 2', cursive;
  font-weight: 800;
  color: #3b2400;
  background: linear-gradient(135deg, #ffd86f, #ff9f1c);
}

@media (max-width: 520px) {
  .kv-audio-item { grid-template-columns: 64px 1fr; }
  .kv-audio-item img { width: 64px; height: 64px; }
}
