/* ═══════════════════════════════════════════════════════
   YT Audio Player v1.3 — Clean Dark Card
   ═══════════════════════════════════════════════════════ */

:root {
  --ytap-bg:        #0f0f14;
  --ytap-surface:   #1a1a24;
  --ytap-border:    #2a2a38;
  --ytap-accent:    #ff4d6d;
  --ytap-accent2:   #c9184a;
  --ytap-buffered:  #3a3a50;
  --ytap-text:      #e8e8f0;
  --ytap-muted:     #7c7c96;
  --ytap-radius:    18px;
  --ytap-thumb-sz:  76px;
  --ytap-track-h:   5px;
  --ytap-dot-sz:    13px;
}

/* ── Wrapper ─────────────────────────────────────────── */
.ytap-wrapper {
  margin: 24px 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  position: relative;          /* anchors the absolute iframe-wrap */
}

/* ── Hidden iframe ─────────────────────────────────────────────
   CRITICAL for background play:
   - NO position:fixed / left:-9999px  → browser flags as off-screen, suspends it
   - NO opacity:0                      → some browsers suspend zero-opacity media
   - NO overflow:hidden on wrapper     → clipping = browser thinks element not rendered
   - USE visibility:hidden             → invisible to humans, fully alive to browser engine
   - USE position:absolute, z-index:-1 → in document flow, behind everything
   ──────────────────────────────────────────────────────────────── */
.ytap-iframe-wrap {
  position: absolute;
  width: 1px; height: 1px;
  overflow: visible;
  visibility: hidden;
  pointer-events: none;
  z-index: -1;
}
.ytap-iframe-wrap iframe {
  width: 1px; height: 1px;
  border: 0; display: block;
}

/* ── Player card ─────────────────────────────────────── */
.ytap-player {
  background: var(--ytap-bg);
  border: 1px solid var(--ytap-border);
  border-radius: var(--ytap-radius);
  padding: 20px 22px 18px;
  max-width: 540px;
  position: relative;
  overflow: hidden;
  box-shadow:
    0 12px 40px rgba(0,0,0,.5),
    0 1px 0 rgba(255,255,255,.04) inset;
}
/* subtle accent tint in top-left corner */
.ytap-player::before {
  content: '';
  position: absolute; inset: 0;
  background: radial-gradient(ellipse at 12% 20%, rgba(255,77,109,.07) 0%, transparent 60%);
  pointer-events: none;
}

/* ── Top row ─────────────────────────────────────────── */
.ytap-top-row {
  display: flex; align-items: center; gap: 16px;
  margin-bottom: 20px;
}

/* Artwork */
.ytap-artwork {
  position: relative;
  width: var(--ytap-thumb-sz); height: var(--ytap-thumb-sz);
  flex-shrink: 0;
}
.ytap-thumb {
  width: 100%; height: 100%;
  object-fit: cover; border-radius: 11px; display: block;
  box-shadow: 0 6px 20px rgba(0,0,0,.45);
  border: 1.5px solid var(--ytap-border);
}

/* Pulsing ring while playing */
.ytap-ripple {
  position: absolute; inset: -4px; border-radius: 15px;
  border: 2px solid var(--ytap-accent);
  opacity: 0; transform: scale(.9);
  transition: opacity .3s, transform .3s;
  pointer-events: none;
}
.ytap-player.is-playing .ytap-ripple {
  opacity: .6; transform: scale(1.03);
  animation: ytap-ripple 2.2s ease-in-out infinite;
}
@keyframes ytap-ripple {
  0%,100% { transform: scale(1.03); opacity: .6; }
  50%      { transform: scale(1.08); opacity: .15; }
}

/* Equalizer overlay */
.ytap-equalizer {
  position: absolute; inset: 0; border-radius: 11px;
  background: rgba(0,0,0,.52);
  display: flex; align-items: flex-end; justify-content: center;
  gap: 3px; padding: 12px 9px;
  opacity: 0; transition: opacity .3s; pointer-events: none;
}
.ytap-player.is-playing .ytap-equalizer { opacity: 1; }
.ytap-equalizer span {
  display: block; width: 4px; border-radius: 2px;
  background: var(--ytap-accent); height: 30%; transform-origin: bottom;
}
.ytap-player.is-playing .ytap-equalizer span:nth-child(1) { animation: ytap-eq .9s  ease-in-out        infinite; }
.ytap-player.is-playing .ytap-equalizer span:nth-child(2) { animation: ytap-eq .7s  ease-in-out .15s   infinite; }
.ytap-player.is-playing .ytap-equalizer span:nth-child(3) { animation: ytap-eq 1.1s ease-in-out .05s   infinite; }
.ytap-player.is-playing .ytap-equalizer span:nth-child(4) { animation: ytap-eq .8s  ease-in-out .25s   infinite; }
.ytap-player.is-playing .ytap-equalizer span:nth-child(5) { animation: ytap-eq .95s ease-in-out .1s    infinite; }
@keyframes ytap-eq {
  0%,100% { transform: scaleY(.25); }
  50%     { transform: scaleY(1); }
}

/* Info */
.ytap-info { min-width: 0; flex: 1; }
.ytap-title {
  font-size: 15px; font-weight: 700;
  color: var(--ytap-text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  line-height: 1.3; letter-spacing: .01em;
}
.ytap-artist {
  font-size: 12px; color: var(--ytap-muted);
  margin-top: 3px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ytap-status {
  font-size: 11px; color: var(--ytap-muted);
  margin-top: 5px; min-height: 15px;
  display: flex; align-items: center; gap: 6px;
}
.ytap-status:empty { display: none; }
.ytap-spinner {
  width: 11px; height: 11px;
  border: 2px solid var(--ytap-border);
  border-top-color: var(--ytap-accent);
  border-radius: 50%;
  animation: ytap-spin .65s linear infinite;
  flex-shrink: 0;
}
@keyframes ytap-spin { to { transform: rotate(360deg); } }

/* ── Scrubber ─────────────────────────────────────────── */
.ytap-scrubber-row { margin-bottom: 6px; }

.ytap-scrubber-wrap {
  position: relative;
  height: 22px; display: flex; align-items: center;
}

/* Tooltip */
.ytap-tooltip {
  position: absolute;
  bottom: calc(100% + 7px);
  transform: translateX(-50%);
  background: rgba(0,0,0,.88);
  color: #fff; font-size: 11px; font-weight: 600;
  padding: 4px 9px; border-radius: 6px;
  pointer-events: none; white-space: nowrap;
  opacity: 0; transition: opacity .12s; z-index: 10;
}
.ytap-tooltip::after {
  content: '';
  position: absolute; top: 100%; left: 50%; transform: translateX(-50%);
  border: 5px solid transparent; border-top-color: rgba(0,0,0,.88);
}
.ytap-scrubber-wrap:focus-within .ytap-tooltip,
.ytap-seek:focus-visible ~ .ytap-tooltip { opacity: 1; }

/* Visual track layers */
.ytap-track {
  position: absolute; left: 0; right: 0;
  height: var(--ytap-track-h);
  border-radius: calc(var(--ytap-track-h) / 2);
  background: var(--ytap-border);
  pointer-events: none; overflow: visible;
}
.ytap-buffered {
  position: absolute; left: 0; top: 0; bottom: 0;
  width: 0%; background: var(--ytap-buffered);
  border-radius: inherit; transition: width .9s ease;
}
.ytap-played {
  position: absolute; left: 0; top: 0; bottom: 0;
  width: 0%;
  background: linear-gradient(90deg, var(--ytap-accent2), var(--ytap-accent));
  border-radius: inherit;
}
.ytap-dot {
  position: absolute; top: 50%; left: 0%;
  width: var(--ytap-dot-sz); height: var(--ytap-dot-sz);
  border-radius: 50%; background: #fff;
  box-shadow: 0 0 8px rgba(255,77,109,.7);
  transform: translate(-50%, -50%) scale(0);
  transition: transform .15s; pointer-events: none;
}
.ytap-seek:focus-visible ~ .ytap-track .ytap-dot { transform: translate(-50%, -50%) scale(1); }
.ytap-scrubber-wrap.dragging .ytap-dot { transform: translate(-50%, -50%) scale(1.2); }

/* Native range — invisible, full hit area */
.ytap-seek {
  position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: 0; cursor: pointer; margin: 0; padding: 0;
  -webkit-appearance: none; appearance: none; background: transparent; z-index: 2;
}
.ytap-seek:focus-visible { opacity: 0; outline: none; }
.ytap-seek:focus-visible ~ .ytap-track {
  outline: 2px solid var(--ytap-accent); outline-offset: 4px; border-radius: 4px;
}
.ytap-seek::-webkit-slider-thumb {
  -webkit-appearance: none; width: 22px; height: 22px;
  border-radius: 50%; background: transparent; cursor: pointer;
}
.ytap-seek::-moz-range-thumb {
  width: 22px; height: 22px; border-radius: 50%;
  background: transparent; border: none; cursor: pointer;
}

/* ── Time row ────────────────────────────────────────── */
.ytap-time-row {
  display: flex; justify-content: space-between;
  margin-bottom: 16px;
}
.ytap-time {
  font-size: 11px; color: var(--ytap-muted);
  font-variant-numeric: tabular-nums; letter-spacing: .03em;
  user-select: none;
}

/* ── Controls row ────────────────────────────────────── */
.ytap-controls-row {
  display: flex; align-items: center; gap: 6px;
}

/* Base button reset */
.ytap-btn {
  all: unset; display: flex; align-items: center; justify-content: center;
  cursor: pointer; border-radius: 50%; flex-shrink: 0;
  color: var(--ytap-text);
  transition: color .15s, background .15s, transform .12s, opacity .2s;
}
.ytap-btn:focus-visible {
  outline: 2px solid var(--ytap-accent); outline-offset: 3px;
}
.ytap-btn:disabled { opacity: .3; cursor: not-allowed; pointer-events: none; }

/* Speed button — pill shape */
.ytap-speed-btn {
  border-radius: 20px;
  background: var(--ytap-surface);
  border: 1.5px solid var(--ytap-border);
  color: var(--ytap-muted);
  font-size: 12px; font-weight: 700;
  letter-spacing: .02em;
  padding: 0 10px; height: 32px;
  min-width: 40px;
  transition: color .15s, background .15s, border-color .15s, transform .12s;
}
/* hover states moved to @media (hover: hover) block below — see end of file */
.ytap-speed-btn:active { transform: scale(.93); }
/* Highlight when not at 1× */
.ytap-speed-btn.active {
  color: var(--ytap-accent);
  border-color: var(--ytap-accent);
  background: rgba(255,77,109,.12);
}

/* Skip ±10 */
.ytap-skip-btn { width: 38px; height: 38px; color: var(--ytap-muted); }
.ytap-skip-btn svg { width: 23px; height: 23px; }
.ytap-skip-btn:active { transform: scale(.92); }

/* Play / Pause — centrepiece */
.ytap-play-btn {
  width: 52px; height: 52px;
  background: var(--ytap-accent);
  color: #fff;
  margin: 0 6px;
  box-shadow: 0 4px 18px rgba(255,77,109,.45);
}
.ytap-play-btn svg { width: 26px; height: 26px; }
.ytap-play-btn:active { transform: scale(.93); }
.ytap-player.is-playing .ytap-play-btn {
  animation: ytap-playglow 2.8s ease-in-out infinite;
}
@keyframes ytap-playglow {
  0%,100% { box-shadow: 0 4px 18px rgba(255,77,109,.45); }
  50%      { box-shadow: 0 4px 28px rgba(255,77,109,.75), 0 0 0 8px rgba(255,77,109,.08); }
}

/* Volume group */
.ytap-volume-group {
  display: flex; align-items: center; gap: 6px; margin-left: auto;
}
.ytap-mute-btn { width: 34px; height: 34px; color: var(--ytap-muted); }
.ytap-mute-btn svg { width: 19px; height: 19px; }
.ytap-mute-btn[aria-pressed="true"] { color: var(--ytap-accent); }

.ytap-volume-range {
  -webkit-appearance: none; appearance: none;
  width: 76px; height: var(--ytap-track-h);
  border-radius: 3px;
  background: var(--ytap-border);
  background-image: linear-gradient(var(--ytap-accent), var(--ytap-accent));
  background-repeat: no-repeat; background-size: 100% 100%;
  outline: none; cursor: pointer;
}
.ytap-volume-range:focus-visible {
  outline: 2px solid var(--ytap-accent); outline-offset: 4px; border-radius: 4px;
}
.ytap-volume-range::-webkit-slider-thumb {
  -webkit-appearance: none; width: 13px; height: 13px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.4), 0 0 5px rgba(255,77,109,.35);
  cursor: pointer; transition: transform .12s;
}
.ytap-volume-range::-moz-range-thumb {
  width: 13px; height: 13px; border-radius: 50%;
  background: #fff; border: none; cursor: pointer;
}

/* ── Reduced motion ──────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .ytap-ripple, .ytap-equalizer span,
  .ytap-spinner, .ytap-play-btn { animation: none !important; }
  .ytap-played, .ytap-dot { transition: none !important; }
}

/* ── Error ───────────────────────────────────────────── */
.ytap-error {
  color: #f87171; font-size: 13px;
  border: 1px solid rgba(248,113,113,.3);
  padding: 10px 14px; border-radius: 10px;
  background: rgba(248,113,113,.07);
}

/* ── Responsive ──────────────────────────────────────── */
@media (max-width: 460px) {
  :root { --ytap-thumb-sz: 60px; }
  .ytap-player { padding: 14px 14px 12px; }
  .ytap-play-btn { width: 46px; height: 46px; }
  .ytap-skip-btn { width: 33px; height: 33px; }
  .ytap-volume-range { width: 56px; }
}
@media (max-width: 340px) {
  .ytap-volume-group { display: none; }
}

/* ── Touch / mobile: prevent hover states sticking after tap ─────
   All :hover rules that cause visual state changes are re-declared
   under (hover: hover) so they only fire on real pointer devices.
   On touchscreens the browser's "sticky hover" is suppressed.
   Also disable webkit tap highlight flash on all player buttons.
─────────────────────────────────────────────────────────────────── */
.ytap-btn,
.ytap-speed-btn,
.ytap-mute-btn,
.ytap-skip-btn,
.ytap-play-btn {
  -webkit-tap-highlight-color: transparent;
}

@media (hover: hover) and (pointer: fine) {
  .ytap-speed-btn:hover {
    color: var(--ytap-text);
    border-color: var(--ytap-accent);
    background: rgba(255,77,109,.08);
  }
  .ytap-skip-btn:hover { color: var(--ytap-text); transform: scale(1.1); }
  .ytap-play-btn:hover { background: var(--ytap-accent2); transform: scale(1.07); }
  .ytap-mute-btn:hover { color: var(--ytap-text); }
  .ytap-volume-range::-webkit-slider-thumb:hover { transform: scale(1.25); }
  .ytap-scrubber-wrap:hover .ytap-tooltip { opacity: 1; }
  .ytap-scrubber-wrap:hover .ytap-dot { transform: translate(-50%, -50%) scale(1); }
}
