/* The player on the surah pages.
 *
 * These are the pages Google ranks, and until now they had a "Listen to Surah
 * Al-Mulk" button that handed the visitor off to the app shell — so the one
 * thing someone arriving from a search for "al mulk" wants to do, hear it, took
 * them off the page they found. This bar keeps them on it.
 *
 * Self-contained: the surah pages load css/surah-page.css, not app-v46.css, so
 * this file declares its own layout against the same tokens and adds nothing a
 * standalone page does not already have.
 *
 * Rules it follows, from the platform guidelines and the design rules:
 *   - every control is at least 44x44
 *   - it sits in the bottom thumb zone, above the home indicator
 *   - it never appears from nothing and never moves under the reader's thumb
 *   - no transition runs longer than 200ms, and nothing uses transition: all
 */

.sp {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  /* The bar is a card that floats over the text rather than a slab glued to
     the bottom edge. */
  padding: 0 max(10px, env(safe-area-inset-left)) calc(10px + env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-right));
  transform: translateY(0);
  transition: transform 200ms cubic-bezier(0.23, 1, 0.32, 1), opacity 160ms cubic-bezier(0.23, 1, 0.32, 1);
}
.sp[hidden] { display: none; }

.sp-card {
  display: grid;
  gap: 2px;
  padding: 8px 12px 10px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--card) 92%, transparent);
  /* A blurred backplate, so the Arabic moving underneath never fights the
     controls for legibility. */
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  box-shadow: 0 10px 30px rgba(10, 20, 40, 0.16);
}

/* ---------------------------------------------------------------- the line */

.sp-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 22px;
}

.sp-where {
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
}
.sp-ayah {
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
  white-space: nowrap;
}
.sp-of {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sp-time {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  white-space: nowrap;
}

/* --------------------------------------------------------------- the scrub */

.sp-scrub {
  /* The visible track is 4px; the input is 44px tall so a thumb can hit it.
     The height is padding, not decoration. */
  display: block;
  position: relative;
  height: 44px;
  margin: -11px 0 -11px;
  cursor: pointer;
}
.sp-scrub input {
  -webkit-appearance: none;
  appearance: none;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  background: none;
  cursor: pointer;
}
.sp-scrub input::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 999px;
  background: var(--line);
}
.sp-scrub input::-moz-range-track {
  height: 4px;
  border-radius: 999px;
  background: var(--line);
}
.sp-scrub input::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  margin-top: -5px;
  border-radius: 50%;
  background: var(--emerald);
  border: 0;
  box-shadow: 0 1px 4px rgba(10, 20, 40, 0.3);
}
.sp-scrub input::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: 0;
  border-radius: 50%;
  background: var(--emerald);
}
.sp-scrub input:focus-visible { outline: 2px solid var(--focus); outline-offset: 4px; border-radius: 999px; }
/* The filled portion, drawn under the input so the native thumb still tracks. */
.sp-fill {
  position: absolute;
  left: 0;
  top: 50%;
  height: 4px;
  margin-top: -2px;
  border-radius: 999px;
  background: var(--emerald);
  pointer-events: none;
  width: 0;
}
.sp-ticks {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 4px;
  margin-top: -2px;
  pointer-events: none;
}
.sp-ticks i {
  position: absolute;
  top: 0;
  width: 1px;
  height: 4px;
  background: var(--line);
  opacity: 0.9;
}

/* -------------------------------------------------------------- the buttons */

.sp-row {
  display: grid;
  grid-template-columns: 44px 56px 44px minmax(0, 1fr) auto;
  align-items: center;
  gap: 4px;
}

.sp-btn {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 120ms cubic-bezier(0.23, 1, 0.32, 1), background 120ms ease;
}
.sp-btn:hover { background: var(--surface-2); }
.sp-btn:active { transform: scale(0.94); }
.sp-btn:disabled { opacity: 0.35; cursor: default; }
.sp-btn svg { width: 20px; height: 20px; }
.sp-btn.sp-jump svg { width: 18px; height: 18px; }

.sp-play {
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: 50%;
  background: var(--emerald);
  color: var(--on);
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(10, 20, 40, 0.22);
  transition: transform 120ms cubic-bezier(0.23, 1, 0.32, 1);
}
.sp-play:active { transform: scale(0.94); }
.sp-play svg { width: 24px; height: 24px; }
.sp-play .sp-ic-pause { display: none; }
.sp.is-playing .sp-play .sp-ic-play { display: none; }
.sp.is-playing .sp-play .sp-ic-pause { display: block; }

.sp-side {
  display: flex;
  align-items: center;
  gap: 2px;
  justify-content: flex-end;
  min-width: 0;
}

.sp-rate {
  height: 44px;
  min-width: 44px;
  padding: 0 10px;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 12.5px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: color 120ms ease, background 120ms ease;
}
.sp-rate:hover { background: var(--surface-2); color: var(--text); }
.sp-rate.on { color: var(--text); }

.sp-src {
  display: block;
  max-width: 130px;
  border: 0;
  border-radius: 10px;
  background: none;
  padding: 0 8px;
  height: 44px;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  font-weight: 650;
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  transition: color 120ms ease, background 120ms ease;
}
.sp-src:hover { background: var(--surface-2); color: var(--text); }

.sp-note {
  grid-column: 1 / -1;
  margin: 0 0 2px;
  font-size: 12px;
  line-height: 1.4;
  color: var(--muted);
}
.sp-note b { color: var(--text); }

/* ------------------------------------------------------- the reading column */

/* The bar is fixed, so the last ayah would sit under it forever. Reserve the
   space rather than letting the page end behind the controls. */
body.sp-up .wrap,
body:has(.sp:not([hidden])) .wrap { padding-bottom: 168px; }

/* The ayah being recited. One signal — a soft ground and a colour shift — so
   it reads at a glance while scrolling without becoming a second interface. */
.ayah.is-playing { background: color-mix(in srgb, var(--emerald) 8%, transparent); border-radius: 12px; }
.ayah.is-playing .ayah-n { color: var(--emerald); font-weight: 700; }
.ayah.is-playing .ayah-play svg { fill: var(--emerald); }

@media (max-width: 420px) {
  .sp-row { grid-template-columns: 44px 52px 44px minmax(0, 1fr) auto; gap: 2px; }
  .sp-src { max-width: 96px; }
  .sp-play { width: 52px; height: 52px; }
}

@media (prefers-reduced-motion: reduce) {
  .sp, .sp-btn, .sp-play, .sp-rate, .sp-src { transition: none; }
  .sp-btn:active, .sp-play:active { transform: none; }
}
