/* =====================================================
   Podcast Player Block — Frontend Styles
   Podcasting 2.0 compliant player
   ===================================================== */

/* ── CSS Custom Properties (theming) ── */
.ppb-podcast-player {
  /* Dark theme defaults */
  --ppb-bg:       #0f0f1a;
  --ppb-surface:  #1a1a2e;
  --ppb-surface2: #22223a;
  --ppb-border:   rgba(255,255,255,.08);
  --ppb-text:     #f0f0ff;
  --ppb-text2:    rgba(240,240,255,.55);
  --ppb-accent:   #7c6ff7;
  --ppb-accent2:  #a78bfa;
  --ppb-track:    rgba(255,255,255,.1);
  --ppb-live:     #ff4545;
  --ppb-radius:   12px;
  --ppb-radius-sm:6px;
  --ppb-font:     'Georgia', 'Times New Roman', serif;
  --ppb-font-ui:  system-ui, -apple-system, sans-serif;
  --ppb-shadow:   0 8px 32px rgba(0,0,0,.4);
  --ppb-trans:    .2s ease;
  --ppb-art-size: 160px;
}

.ppb-podcast-player.ppb-scheme-light {
  --ppb-bg:       #f5f5fa;
  --ppb-surface:  #ffffff;
  --ppb-surface2: #eeeef5;
  --ppb-border:   rgba(0,0,0,.08);
  --ppb-text:     #1a1a2e;
  --ppb-text2:    rgba(26,26,46,.55);
  --ppb-track:    rgba(0,0,0,.1);
  --ppb-shadow:   0 8px 32px rgba(0,0,0,.12);
}

/* Artwork sizes */
.ppb-podcast-player.ppb-art-small  { --ppb-art-size:  80px; }
.ppb-podcast-player.ppb-art-medium { --ppb-art-size: 160px; }
.ppb-podcast-player.ppb-art-large  { --ppb-art-size: 240px; }
.ppb-podcast-player.ppb-art-full   { --ppb-art-size: 100%; }

/* Player sizes */
.ppb-podcast-player.ppb-size-compact .ppb-player  { gap: 10px; padding: 14px; }
.ppb-podcast-player.ppb-size-compact .ppb-controls{ gap: 6px; }
.ppb-podcast-player.ppb-size-compact .ppb-btn-play-main { width: 44px; height: 44px; }
.ppb-podcast-player.ppb-size-compact .ppb-artwork-wrap { --ppb-art-size: 80px; }
.ppb-podcast-player.ppb-size-compact .ppb-playlist { max-height: 240px; }

.ppb-podcast-player.ppb-size-large .ppb-player    { gap: 20px; padding: 32px; }
.ppb-podcast-player.ppb-size-large .ppb-btn-play-main { width: 72px; height: 72px; }
.ppb-podcast-player.ppb-size-large .ppb-artwork-wrap  { --ppb-art-size: 240px; }

/* ── Base ── */
*, *::before, *::after { box-sizing: border-box; }

.ppb-podcast-player {
  font-family: var(--ppb-font-ui);
  color: var(--ppb-text);
  background: var(--ppb-bg);
  border-radius: var(--ppb-radius);
  overflow: hidden;
  position: relative;
  width: 100%;
}

.ppb-player {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px;
  background: var(--ppb-surface);
  border: 1px solid var(--ppb-border);
  border-radius: var(--ppb-radius);
  box-shadow: var(--ppb-shadow);
  position: relative;
}

/* ── Layout: Artwork + Main side-by-side on wider viewports ── */
@media (min-width: 520px) {
  .ppb-player {
    display: grid;
    grid-template-columns: var(--ppb-art-size) 1fr;
    grid-template-rows: auto 1fr;
    gap: 16px 20px;
  }
  .ppb-live-banner  { grid-column: 1 / -1; }
  .ppb-artwork-wrap { grid-row: 1 / 3; align-self: start; }
  .ppb-main         { grid-column: 2; }
  .ppb-chapters-panel,
  .ppb-transcript-panel,
  .ppb-people-panel,
  .ppb-playlist     { grid-column: 1 / -1; }
}

/* ── Utility ── */
.ppb-hidden { display: none !important; }

/* ── Live Banner ── */
.ppb-live-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,69,69,.12);
  border: 1px solid rgba(255,69,69,.3);
  border-radius: var(--ppb-radius-sm);
  padding: 8px 12px;
  font-size: .8rem;
  font-weight: 600;
  color: var(--ppb-live);
  letter-spacing: .05em;
}
.ppb-live-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--ppb-live);
  animation: ppb-pulse 1.4s infinite;
  flex-shrink: 0;
}
.ppb-live-label { font-size: .7rem; letter-spacing: .15em; }
.ppb-live-title { color: var(--ppb-text); font-weight: 500; flex: 1; }
.ppb-live-chat  { color: var(--ppb-accent2); text-decoration: none; font-size: .78rem; }
.ppb-live-chat:hover { text-decoration: underline; }

@keyframes ppb-pulse {
  0%,100% { opacity: 1; transform: scale(1); }
  50%      { opacity: .4; transform: scale(.85); }
}

/* ── Artwork ── */
.ppb-artwork-wrap {
  position: relative;
  width: var(--ppb-art-size);
  max-width: 100%;
  aspect-ratio: 1;
  border-radius: var(--ppb-radius);
  overflow: hidden;
  background: var(--ppb-surface2);
  flex-shrink: 0;
}
.ppb-artwork-wrap img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: var(--ppb-radius);
  transition: opacity .3s ease, transform .4s ease;
}
.ppb-artwork-episode { z-index: 1; }
.ppb-artwork-chapter  { z-index: 2; border-radius: calc(var(--ppb-radius) - 4px); }
.ppb-artwork-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ppb-text2);
  padding: 20%;
}
.ppb-artwork-placeholder svg { width: 100%; height: 100%; }

/* Stacked artwork reveal */
.ppb-artwork-chapter:not(.ppb-hidden) {
  animation: ppb-artwork-in .35s ease forwards;
}
@keyframes ppb-artwork-in {
  from { opacity: 0; transform: scale(.92); }
  to   { opacity: 1; transform: scale(1); }
}

/* ── Main ── */
.ppb-main {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.ppb-meta { min-width: 0; }
.ppb-show-title {
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--ppb-accent2);
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ppb-episode-title {
  margin: 0 0 4px;
  font-size: 1rem;
  font-weight: 700;
  font-family: var(--ppb-font);
  line-height: 1.3;
  color: var(--ppb-text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.ppb-episode-meta {
  font-size: .72rem;
  color: var(--ppb-text2);
}

/* ── Waveform ── */
.ppb-waveform {
  display: flex;
  align-items: center;
  gap: 2px;
  height: 24px;
  overflow: hidden;
  margin-bottom: 4px;
}
.ppb-wave-bar {
  flex: 1;
  background: var(--ppb-accent);
  border-radius: 2px;
  height: 4px;
  opacity: .35;
  transform-origin: center;
  transition: height .15s ease, opacity .15s ease;
}
.ppb-wave-bar.ppb-playing {
  animation: ppb-wave var(--dur, .8s) ease-in-out infinite alternate;
  --dur: .7s;
  opacity: .7;
}
.ppb-wave-bar:nth-child(3n)   { --dur: .9s; }
.ppb-wave-bar:nth-child(5n)   { --dur: .6s; }
.ppb-wave-bar:nth-child(7n)   { --dur: 1.1s; }
.ppb-wave-bar:nth-child(11n)  { --dur: .75s; }

@keyframes ppb-wave {
  from { height: 4px; }
  to   { height: 20px; }
}

/* ── Progress ── */
.ppb-progress-area { display: flex; flex-direction: column; gap: 4px; }
.ppb-progress-track {
  position: relative;
  height: 6px;
  background: var(--ppb-track);
  border-radius: 3px;
  cursor: pointer;
  outline: none;
}
.ppb-progress-track:focus-visible {
  box-shadow: 0 0 0 3px rgba(124,111,247,.4);
}
.ppb-progress-buffered,
.ppb-progress-fill {
  position: absolute;
  inset: 0;
  border-radius: 3px;
  pointer-events: none;
}
.ppb-progress-buffered {
  background: rgba(255,255,255,.12);
  width: 0;
  transition: width .5s ease;
}
.ppb-progress-fill {
  background: linear-gradient(90deg, var(--ppb-accent), var(--ppb-accent2));
  width: 0;
}
.ppb-progress-thumb {
  position: absolute;
  top: 50%;
  left: 0;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--ppb-accent2);
  transform: translate(-50%, -50%) scale(0);
  transition: transform .15s ease;
  pointer-events: none;
  box-shadow: 0 0 0 3px rgba(167,139,250,.2);
}
.ppb-progress-track:hover .ppb-progress-thumb,
.ppb-progress-track:focus-visible .ppb-progress-thumb { transform: translate(-50%, -50%) scale(1); }

.ppb-time-row {
  display: flex;
  justify-content: space-between;
  font-size: .7rem;
  font-variant-numeric: tabular-nums;
  color: var(--ppb-text2);
  gap: 8px;
}
.ppb-chapter-current {
  flex: 1;
  text-align: center;
  font-size: .68rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ppb-accent2);
}

/* ── Controls ── */
.ppb-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.ppb-secondary {
  display: flex;
  align-items: center;
  gap: 4px;
  justify-content: center;
  flex-wrap: wrap;
}

/* Buttons */
.ppb-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--ppb-text2);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  padding: 6px;
  transition: color var(--ppb-trans), background var(--ppb-trans), transform .1s ease;
  -webkit-tap-highlight-color: transparent;
  position: relative;
}
.ppb-btn:hover { color: var(--ppb-text); background: var(--ppb-track); }
.ppb-btn:active { transform: scale(.93); }
.ppb-btn svg { width: 18px; height: 18px; display: block; }
.ppb-btn:focus-visible { outline: 2px solid var(--ppb-accent); outline-offset: 2px; }

.ppb-btn-rewind,
.ppb-btn-forward {
  position: relative;
  font-size: .6rem;
  font-weight: 700;
  flex-direction: column;
  gap: 0;
  padding: 4px;
}
.ppb-btn-rewind span,
.ppb-btn-forward span {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -48%);
  font-size: .58rem;
  font-weight: 800;
  color: var(--ppb-text);
}
.ppb-btn-rewind svg,
.ppb-btn-forward svg { opacity: .8; }

/* Big play button */
.ppb-btn-play-main {
  width: 56px; height: 56px;
  background: linear-gradient(135deg, var(--ppb-accent), var(--ppb-accent2));
  color: #fff;
  box-shadow: 0 4px 16px rgba(124,111,247,.4);
}
.ppb-btn-play-main:hover {
  background: linear-gradient(135deg, var(--ppb-accent2), var(--ppb-accent));
  color: #fff;
  transform: scale(1.05);
}
.ppb-btn-play-main:active { transform: scale(.97); }
.ppb-btn-play-main svg { width: 22px; height: 22px; }

/* Speed button */
.ppb-btn-speed {
  border-radius: var(--ppb-radius-sm);
  font-size: .75rem;
  font-weight: 700;
  padding: 4px 8px;
  border: 1px solid var(--ppb-border);
  min-width: 36px;
}

/* Volume */
.ppb-volume-wrap { display: flex; align-items: center; gap: 4px; }
.ppb-volume {
  -webkit-appearance: none;
  appearance: none;
  width: 70px; height: 4px;
  background: var(--ppb-track);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}
.ppb-volume::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--ppb-accent2);
  cursor: pointer;
}
.ppb-volume::-moz-range-thumb {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--ppb-accent2);
  border: none;
  cursor: pointer;
}

/* Loading spinner on play button */
@keyframes ppb-spin { to { transform: rotate(360deg); } }
.ppb-icon-loading { animation: ppb-spin .8s linear infinite; }

/* ── Panels (chapters, transcript) ── */
.ppb-chapters-panel,
.ppb-transcript-panel {
  border-top: 1px solid var(--ppb-border);
  padding-top: 14px;
}
.ppb-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.ppb-panel-header h3 {
  margin: 0;
  font-size: .82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--ppb-text2);
}
.ppb-panel-close {
  border-radius: var(--ppb-radius-sm);
  font-size: .8rem;
  padding: 2px 6px;
}

/* Chapters list */
.ppb-chapters-list {
  list-style: none;
  margin: 0; padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 260px;
  overflow-y: auto;
  scrollbar-width: thin;
}
.ppb-chapter-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: var(--ppb-radius-sm);
  cursor: pointer;
  transition: background var(--ppb-trans);
}
.ppb-chapter-item:hover { background: var(--ppb-track); }
.ppb-chapter-item.ppb-active { background: rgba(124,111,247,.15); color: var(--ppb-accent2); }
.ppb-chapter-item img { width: 40px; height: 40px; border-radius: 4px; object-fit: cover; flex-shrink: 0; }
.ppb-ch-no-img { width: 40px; height: 40px; flex-shrink: 0; }
.ppb-ch-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ppb-ch-title { font-size: .82rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ppb-ch-time  { font-size: .68rem; color: var(--ppb-text2); font-variant-numeric: tabular-nums; }
.ppb-ch-link  { font-size: .82rem; color: var(--ppb-accent2); text-decoration: none; padding: 4px; border-radius: 4px; }
.ppb-ch-link:hover { background: var(--ppb-track); }

/* Transcript */
.ppb-transcript-body {
  max-height: 240px;
  overflow-y: auto;
  font-size: .82rem;
  line-height: 1.7;
  color: var(--ppb-text);
  scrollbar-width: thin;
}
.ppb-transcript-line { margin: 0 0 6px; }
.ppb-ts { font-size: .68rem; color: var(--ppb-accent2); margin-right: 8px; font-variant-numeric: tabular-nums; }
.ppb-transcript-raw { font-family: monospace; font-size: .75rem; white-space: pre-wrap; }

/* ── People ── */
.ppb-people-panel {
  border-top: 1px solid var(--ppb-border);
  padding-top: 12px;
}
.ppb-people-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.ppb-person {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--ppb-text);
  background: var(--ppb-surface2);
  border: 1px solid var(--ppb-border);
  border-radius: 999px;
  padding: 4px 10px 4px 4px;
  transition: background var(--ppb-trans), border-color var(--ppb-trans);
}
.ppb-person:hover:not(.ppb-person-no-link) { background: var(--ppb-track); border-color: var(--ppb-accent); }
.ppb-person-img {
  width: 28px; height: 28px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}
.ppb-person-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--ppb-accent), var(--ppb-accent2));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .75rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}
.ppb-person-info { display: flex; flex-direction: column; }
.ppb-person-name { font-size: .78rem; font-weight: 600; }
.ppb-person-role { font-size: .65rem; text-transform: capitalize; color: var(--ppb-text2); }

/* ── Playlist ── */
.ppb-playlist {
  border-top: 1px solid var(--ppb-border);
  padding-top: 12px;
}
.ppb-playlist .ppb-panel-header { flex-wrap: wrap; gap: 8px; }
.ppb-playlist-search-wrap { flex: 1; min-width: 180px; }
.ppb-playlist-search {
  width: 100%;
  background: var(--ppb-surface2);
  border: 1px solid var(--ppb-border);
  border-radius: var(--ppb-radius-sm);
  padding: 6px 10px;
  font-size: .78rem;
  color: var(--ppb-text);
  outline: none;
  transition: border-color var(--ppb-trans);
}
.ppb-playlist-search:focus { border-color: var(--ppb-accent); }
.ppb-playlist-search::placeholder { color: var(--ppb-text2); }

.ppb-playlist-items {
  list-style: none;
  margin: 0; padding: 0;
  max-height: 340px;
  overflow-y: auto;
  scrollbar-width: thin;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.ppb-playlist-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 8px;
  border-radius: var(--ppb-radius-sm);
  cursor: pointer;
  transition: background var(--ppb-trans);
}
.ppb-playlist-item:hover { background: var(--ppb-track); }
.ppb-playlist-item.ppb-active {
  background: rgba(124,111,247,.12);
  border-left: 3px solid var(--ppb-accent);
  padding-left: 5px;
}

.ppb-pli-art {
  position: relative;
  width: 48px; height: 48px;
  border-radius: 6px;
  overflow: hidden;
  flex-shrink: 0;
  background: var(--ppb-surface2);
}
.ppb-pli-art img { width: 100%; height: 100%; object-fit: cover; }
.ppb-pli-art-ph  { display: block; width: 100%; height: 100%; background: var(--ppb-track); }
.ppb-pli-play-icon {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,.4);
  color: #fff;
  font-size: .7rem;
  opacity: 0;
  transition: opacity var(--ppb-trans);
}
.ppb-playlist-item:hover .ppb-pli-play-icon,
.ppb-playlist-item.ppb-active .ppb-pli-play-icon { opacity: 1; }

.ppb-pli-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.ppb-pli-title { font-size: .82rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ppb-text); }
.ppb-pli-meta  { font-size: .68rem; color: var(--ppb-text2); }
.ppb-playlist-item.ppb-active .ppb-pli-title { color: var(--ppb-accent2); }

/* Empty state */
.ppb-empty { padding: 20px; text-align: center; font-size: .82rem; color: var(--ppb-text2); list-style: none; }

/* ── Loading / Error ── */
.ppb-loading,
.ppb-error {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(15,15,26,.85);
  backdrop-filter: blur(4px);
  border-radius: var(--ppb-radius);
  gap: 12px;
  z-index: 10;
}
.ppb-loading.ppb-hidden,
.ppb-error.ppb-hidden { display: none !important; }
.ppb-spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--ppb-track);
  border-top-color: var(--ppb-accent);
  border-radius: 50%;
  animation: ppb-spin .8s linear infinite;
}
.ppb-loading-text { font-size: .78rem; color: var(--ppb-text2); }
.ppb-error-msg { font-size: .82rem; color: var(--ppb-text); text-align: center; padding: 0 20px; }
.ppb-btn-retry {
  background: var(--ppb-accent);
  color: #fff;
  border-radius: var(--ppb-radius-sm);
  padding: 8px 16px;
  font-size: .78rem;
  font-weight: 600;
}
.ppb-btn-retry:hover { background: var(--ppb-accent2); color: #fff; }

/* ── Scrollbar styling ── */
.ppb-chapters-list::-webkit-scrollbar,
.ppb-playlist-items::-webkit-scrollbar,
.ppb-transcript-body::-webkit-scrollbar { width: 4px; }
.ppb-chapters-list::-webkit-scrollbar-track,
.ppb-playlist-items::-webkit-scrollbar-track,
.ppb-transcript-body::-webkit-scrollbar-track { background: transparent; }
.ppb-chapters-list::-webkit-scrollbar-thumb,
.ppb-playlist-items::-webkit-scrollbar-thumb,
.ppb-transcript-body::-webkit-scrollbar-thumb { background: var(--ppb-track); border-radius: 2px; }

/* ── Responsive ── */
@media (max-width: 519px) {
  .ppb-player { grid-template-columns: 1fr; }
  .ppb-artwork-wrap { width: 100%; aspect-ratio: 1; max-width: 200px; margin: 0 auto; }
  .ppb-volume-wrap { display: none; }
  .ppb-secondary { justify-content: space-evenly; }
}
