/* read-aloud.css — the "Listen" player (static/js/read-aloud.js).
 *
 * A bento card above the reading: Listen/Pause, a paragraph slider, Stop
 * and speed. While it plays and its own place has scrolled away it
 * docks as a pill at the bottom centre of the window. The paragraph being
 * read gets a soft green wash and the word being spoken a slightly deeper
 * one, both drawn without moving a single line of text.
 *
 * Buttons keep buttons.css's rule: black text, a light fill, a coloured
 * edge. Every control is at least 44px.
 */

.ra[hidden] { display: none; }
.ra { margin: 0 0 var(--sp-6, 24px); }

.ra-card {
  --ra-green: var(--bento-success, #3D6B4C);
  --ra-wash: #E3F1E6;
  --ra-p: 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 10px 14px;
  padding: 10px 12px;
  border: 1px solid var(--bento-line, #E4D6C4);
  border-radius: 20px;
  background: var(--bento-white, #fff);
  color: var(--bento-ink, #211A14);
  box-shadow: 0 1px 2px rgba(17, 17, 17, 0.04);
}

/* Listen / Pause: the one control a reader needs, so the widest. */
.ra-play {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px 0 14px;
  border: 1px solid var(--ra-green);
  border-radius: 999px;
  background: var(--ra-wash);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 120ms ease, transform 100ms ease;
}
.ra-play:hover { background: #CFE6D5; }
.ra-play:active { transform: scale(0.97); }
.ra-play svg, .ra-stop svg { width: 18px; height: 18px; fill: currentColor; flex: none; }
.ra-play-ico { display: inline-grid; place-items: center; }

/* A small equaliser inside the button while the voice is going. */
.ra-eq { display: none; align-items: flex-end; gap: 2px; height: 14px; margin-left: 2px; }
.ra-eq i { width: 3px; height: 40%; border-radius: 2px; background: var(--ra-green); }
.is-playing .ra-eq { display: inline-flex; }
.is-playing .ra-eq i { animation: ra-eq 0.9s ease-in-out infinite; }
.is-playing .ra-eq i:nth-child(2) { animation-delay: -0.3s; }
.is-playing .ra-eq i:nth-child(3) { animation-delay: -0.6s; }
.is-playing .ra-eq i:nth-child(4) { animation-delay: -0.15s; }
@keyframes ra-eq { 0%, 100% { height: 30%; } 50% { height: 100%; } }

.ra-mid { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.ra-status {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.3;
  color: var(--bento-ink-soft, #5B4E42);
  overflow-wrap: anywhere;
}

/* The slider: a track that fills green up to the paragraph being read. */
.ra-seek {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 28px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}
.ra-seek:disabled { cursor: default; opacity: 0.55; }
.ra-seek::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(to right, var(--ra-green) calc(var(--ra-p) * 100%), var(--bento-sand, #F2E9DC) 0);
}
.ra-seek::-moz-range-track {
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(to right, var(--ra-green) calc(var(--ra-p) * 100%), var(--bento-sand, #F2E9DC) 0);
}
.ra-seek::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  margin-top: -6px;
  border-radius: 50%;
  border: 2px solid var(--ra-green);
  background: #fff;
}
.ra-seek::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--ra-green);
  background: #fff;
}
.ra-seek:focus-visible { outline: 2px solid var(--bento-info, #3D6B84); outline-offset: 2px; border-radius: 6px; }

.ra-stop {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid #B3261E;
  border-radius: 50%;
  background: #FBE3DF;
  cursor: pointer;
  transition: background 120ms ease, transform 100ms ease;
}
.ra-stop:hover:not(:disabled) { background: #F5CBC4; }
.ra-stop:active:not(:disabled) { transform: scale(0.94); }
.ra-stop:disabled { border-color: var(--bento-line, #E4D6C4); background: var(--bento-cream, #FAF6F0); cursor: default; }

.ra-opts { display: flex; gap: 8px; min-width: 0; }
.ra-select {
  min-height: 44px;
  max-width: 11.5em;
  padding: 0 28px 0 12px;
  border: 1px solid var(--bento-line, #E4D6C4);
  border-radius: 12px;
  background: var(--bento-cream, #FAF6F0);
  color: var(--bento-ink, #211A14);
  font: inherit;
  font-size: 0.9rem;
  text-overflow: ellipsis;
  cursor: pointer;
}
.ra-select[hidden] { display: none; }
.ra-play:focus-visible, .ra-stop:focus-visible, .ra-select:focus-visible {
  outline: 2px solid var(--bento-ink, #211A14);
  outline-offset: 2px;
}

.ra-sr {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* Narrow screens: Listen, the slider and Stop on one row; speed on a row
   of its own. */
@media (max-width: 640px) {
  .ra-card { grid-template-columns: auto minmax(0, 1fr) auto; }
  .ra-opts { grid-column: 1 / -1; }
  .ra-select { flex: 1; max-width: none; }
}

/* Docked: pinned to the bottom centre while playing once the card's own
   place has scrolled away, so Pause is always within reach. */
.ra-card.is-docked {
  position: fixed;
  left: 50%;
  bottom: max(12px, env(safe-area-inset-bottom));
  z-index: 90;
  width: min(560px, calc(100vw - 32px));
  transform: translateX(-50%);
  grid-template-columns: auto minmax(0, 1fr) auto;
  border-radius: 999px;
  padding: 6px 8px 6px 6px;
  box-shadow: 0 12px 32px rgba(17, 17, 17, 0.16), 0 2px 6px rgba(17, 17, 17, 0.06);
  animation: ra-dock 200ms cubic-bezier(0.2, 0.9, 0.3, 1.1);
}
.ra-card.is-docked .ra-opts { display: none; }
@keyframes ra-dock { from { opacity: 0; transform: translate(-50%, 12px); } }

/* The paragraph being read, and the word being spoken. A box-shadow and a
   background only: nothing reflows as the voice moves down the page. */
.ra-now {
  background: rgba(61, 107, 76, 0.09);
  box-shadow: 0 0 0 6px rgba(61, 107, 76, 0.09);
  border-radius: 6px;
  transition: background 200ms ease, box-shadow 200ms ease;
}
::highlight(ra-word) {
  background-color: rgba(61, 107, 76, 0.24);
  color: inherit;
}

@media (prefers-reduced-motion: reduce) {
  .is-playing .ra-eq i, .ra-card.is-docked { animation: none; }
  .ra-play, .ra-stop, .ra-now { transition: none; }
}

/* High contrast: the page is black, so the player is too, with yellow edges. */
html.high-contrast .ra-card { background: #000; border-color: #FFD400; color: #fff; }
html.high-contrast .ra-status { color: #fff; }
html.high-contrast .ra-select { background: #000; color: #fff; border-color: #FFD400; }
html.high-contrast .ra-now { background: #1f2a00; box-shadow: 0 0 0 6px #1f2a00; }
html.high-contrast ::highlight(ra-word) { background-color: #FFD400; color: #000; }

@media print { .ra { display: none !important; } .ra-now { background: none; box-shadow: none; } }
