/* ============================================================
   RADIO WEB PLAYER — Embeddable Widget
   Layouts: landscape, portrait, bottomline
   Themes: dark, light
   ============================================================ */

/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { width: 100%; height: 100%; min-height: 320px; overflow: hidden; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif; }
body { display: flex; align-items: center; justify-content: center; }
img { display: block; object-fit: cover; }
button { border: none; background: none; cursor: pointer; color: inherit; outline: none; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── Theme Variables ── */
.theme-dark {
  --bg: #181818;
  --bg-surface: #282828;
  --text-primary: #fff;
  --text-secondary: #b3b3b3;
  --text-dim: #727272;
  --accent: #1db954;
  --seekbar-bg: #4d4d4d;
  --seekbar-fill: #b3b3b3;
  --seekbar-dot: #fff;
  --ad-bg: #1a1a1a;
  --border: rgba(255,255,255,0.08);
  --shadow: 0 4px 14px rgba(0,0,0,0.6);
}
.theme-light {
  --bg: #f5f5f5;
  --bg-surface: #ffffff;
  --text-primary: #181818;
  --text-secondary: #535353;
  --text-dim: #909090;
  --accent: #1db954;
  --seekbar-bg: #d4d4d4;
  --seekbar-fill: #535353;
  --seekbar-dot: #181818;
  --ad-bg: #ebebeb;
  --border: rgba(0,0,0,0.08);
  --shadow: 0 4px 14px rgba(0,0,0,0.15);
}

/* ── Player Container ── */
.player {
  width: 100%; height: 100%;
  background: var(--bg);
  color: var(--text-primary);
  position: relative;
  overflow: hidden;
}

/* ================================================================
   ARTWORK STACK — shared across all layouts
   Current in front, Next behind with 20-30% visible on the right
   ================================================================ */
.player-artwork-stack {
  position: relative;
  flex-shrink: 0;
}
.artwork-card {
  overflow: hidden;
  background: var(--bg-surface);
}
.artwork-card img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: none;
}
.artwork-card img.loaded { display: block; }

/* Current — front */
.artwork-current {
  position: relative;
  z-index: 2;
  border-radius: 10px;
  box-shadow: var(--shadow);
}
.artwork-placeholder {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-dim);
}
.artwork-placeholder svg { width: 40%; height: 40%; }
.artwork-card img.loaded ~ .artwork-placeholder { display: none; }

/* Next — behind current, peeking right */
.artwork-next {
  position: absolute;
  z-index: 1;
  top: 4%;
  right: 0;
  bottom: 4%;
  border-radius: 10px;
  box-shadow: var(--shadow);
  transition: opacity 0.4s ease;
}
.artwork-next.hidden {
  opacity: 0;
  pointer-events: none;
}

/* Gradient overlay — readable text on the visible right strip */
.artwork-overlay {
  position: absolute; inset: 0;
  background: linear-gradient(
    to right,
    rgba(0,0,0,0.15) 0%,
    rgba(0,0,0,0.55) 40%,
    rgba(0,0,0,0.80) 100%
  );
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: flex-end;
  text-align: right;
  padding: 8px 10px;
  color: #fff;
  border-radius: 10px;
}
.artwork-overlay-label {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  opacity: 0.6;
  margin-bottom: 4px;
}
.artwork-overlay-title {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
  max-width: 100%;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.artwork-overlay-artist {
  font-size: 11px;
  color: rgba(255,255,255,0.7);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* ── Song Info ── */
.player-info { min-width: 0; }
.song-title {
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.song-artist {
  color: var(--text-secondary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ── Controls ── */
.player-controls { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.btn-play {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: var(--text-primary);
  color: var(--bg);
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.1s, opacity 0.1s;
}
.btn-play:hover { transform: scale(1.06); }
.btn-play:active { transform: scale(0.96); }
.btn-play svg { width: 20px; height: 20px; }
.btn-play.playing .icon-play { display: none !important; }
.btn-play.playing .icon-pause { display: block !important; }
.btn-play.loading .icon-play { display: none !important; }
.btn-play.loading .icon-pause { display: none !important; }
.btn-play.loading .icon-loading { display: block !important; }

/* ── Seekbar ── */
.player-seekbar {
  display: flex; align-items: center; gap: 8px;
}
.time-current, .time-total {
  font-size: 11px; color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  min-width: 32px;
  flex-shrink: 0;
}
.time-total { text-align: right; }
.seekbar-track {
  flex: 1; height: 4px;
  background: var(--seekbar-bg);
  border-radius: 2px;
  position: relative;
  overflow: visible;
}
.seekbar-progress {
  height: 100%;
  background: var(--seekbar-fill);
  border-radius: 2px;
  width: 0%;
  transition: width 0.5s linear;
}
.seekbar-dot {
  width: 10px; height: 10px;
  background: var(--seekbar-dot);
  border-radius: 50%;
  position: absolute;
  top: 50%; transform: translate(-50%, -50%);
  left: 0%;
  transition: left 0.5s linear;
  opacity: 0;
}
.player:hover .seekbar-dot { opacity: 1; }

/* ── Next Song (text-only fallback, hidden by default — info is on artwork) ── */
.player-next { display: none; }

/* ── Volume ── */
.player-volume {
  display: flex; align-items: center; gap: 4px;
  flex-shrink: 0;
}
.btn-volume { width: 28px; height: 28px; display: flex; align-items: center; justify-content: center; color: var(--text-secondary); }
.btn-volume:hover { color: var(--text-primary); }
.btn-volume svg { width: 18px; height: 18px; }
.btn-volume.muted .icon-vol-on { display: none !important; }
.btn-volume.muted .icon-vol-off { display: block !important; }

.volume-slider {
  -webkit-appearance: none; appearance: none;
  width: 80px; height: 4px;
  background: var(--seekbar-bg);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}
.volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--seekbar-dot);
  cursor: pointer;
}
.volume-slider::-moz-range-thumb {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--seekbar-dot);
  border: none;
  cursor: pointer;
}

/* ── Theme Toggle ── */
.btn-theme {
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-dim);
  flex-shrink: 0;
}
.btn-theme:hover { color: var(--text-primary); }
.btn-theme svg { width: 16px; height: 16px; }
.theme-dark .btn-theme .icon-moon { display: none !important; }
.theme-dark .btn-theme .icon-sun { display: block !important; }
.theme-light .btn-theme .icon-sun { display: none !important; }
.theme-light .btn-theme .icon-moon { display: block !important; }

/* ── Structural wrappers (transparent by default, active in specific layouts) ── */
.player-left-col { display: contents; }
.player-controls-bar { display: contents; }
.player-bottom-controls { display: contents; }

/* ── Station Logo ── */
.player-logo { flex-shrink: 0; }
.player-logo img { object-fit: contain; display: none; }
.player-logo img.loaded { display: block; }

/* ── Ad Container ── */
.player-ad { display: none; overflow: hidden; background: var(--ad-bg); }
.player-ad.active { display: block; }
.player-ad a { display: block; width: 100%; height: 100%; }
.player-ad img, .player-ad video { width: 100%; height: 100%; object-fit: contain; }


/* ================================================================
   LAYOUT: PORTRAIT
   Vertical card — artwork stack centered, info below
   ================================================================ */
.layout-portrait .player {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 12px 20px 12px;
  gap: clamp(6px, 1.5vh, 14px);
  height: 100%;
  overflow: hidden;
}

/* ── Artwork stack — both cards always square, always together ── */
.layout-portrait .player-artwork-stack {
  position: relative;
  /* height-driven: scales with viewport, cards derive from it */
  height: clamp(80px, 28vh, 260px);
  /* width = current (1x height) + 25% of next peek (0.25 * 0.85 = ~0.21x height) */
  aspect-ratio: 1.21;
  flex-shrink: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  /* Shift left by half the peek so current card is visually screen-centered */
  transform: translateX(8.7%);
}
.layout-portrait .artwork-current {
  height: 100%;
  aspect-ratio: 1;            /* square: width = height */
  flex-shrink: 0;
  position: relative;
  z-index: 2;
}
.layout-portrait .artwork-next {
  height: 85%;
  aspect-ratio: 1;            /* square */
  position: absolute;
  top: 7.5%;
  right: 0;
  z-index: 1;
}

/* ── Next song overlay — vertical text strip on right edge (like Flutter RotatedBox) ── */
.layout-portrait .artwork-overlay {
  inset: 0 0 0 auto;
  width: 44px;
  background: linear-gradient(
    to left,
    rgba(0,0,0,0.85) 0%,
    rgba(0,0,0,0.45) 100%
  );
  writing-mode: vertical-rl;
  transform: rotate(180deg);  /* text reads top-to-bottom */
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
  align-items: center;
  text-align: center;
  padding: 6px 4px;
  gap: 4px;
  border-radius: 10px 0 0 10px;
  overflow: hidden;
  clip-path: inset(0);        /* clip scrolling text within overlay bounds */
}
.layout-portrait .artwork-overlay-label {
  font-size: 8px;
  letter-spacing: 1px;
  flex-shrink: 0;
  background: rgba(0,0,0,0.85);
  padding: 6px 4px;
  border-radius: 3px;
  position: relative;
  z-index: 2;
}
.layout-portrait .artwork-overlay-title {
  font-size: 11px;
  font-weight: 600;
  -webkit-line-clamp: unset;
  display: block;
  overflow: hidden;
  flex: 1;
  min-width: 0;
  min-height: 0;
}
.layout-portrait .artwork-overlay-title .marquee-inner {
  display: inline-block;
  white-space: nowrap;
  animation: vtextScroll 12s linear infinite;
}
/* Artist merged into title — hide in portrait */
.layout-portrait .artwork-overlay-artist {
  display: none;
}

/* Song info */
.layout-portrait .player-info {
  text-align: center;
  width: 100%;
  padding: 0 8px;
}
.layout-portrait .song-title { font-size: clamp(16px, 3.5vmin, 28px); font-weight: 700; line-height: 1.3; }
.layout-portrait .song-artist { font-size: clamp(13px, 2.8vmin, 22px); margin-top: 4px; }

/* Seekbar */
.layout-portrait .player-seekbar { width: 100%; padding: 0 4px; }
.layout-portrait .seekbar-dot { opacity: 1; }
.layout-portrait .time-current,
.layout-portrait .time-total {
  font-size: clamp(12px, 2.2vmin, 18px);
}

/* ── Controls — dynamic sizing like mobile app (18% / 10% of smallest dimension) ── */
.layout-portrait .player-controls { justify-content: center; }
.layout-portrait .btn-play {
  --base: min(100vw, 100vh);
  width: clamp(36px, calc(var(--base) * 0.10), 64px);
  height: clamp(36px, calc(var(--base) * 0.10), 64px);
}
.layout-portrait .btn-play svg {
  width: clamp(18px, calc(min(100vw, 100vh) * 0.06), 32px);
  height: clamp(18px, calc(min(100vw, 100vh) * 0.06), 32px);
}

/* ── Volume + Theme — inline row ── */
.layout-portrait .player-bottom-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}
.layout-portrait .player-volume { justify-content: center; }
.layout-portrait .btn-theme {
  position: static;
}

/* ── Logo — hidden ── */
.layout-portrait .player-logo { display: none; }

/* Ad */
.layout-portrait .player-ad {
  width: 100%;
  flex-shrink: 0;
  aspect-ratio: 4/1;
  max-height: 80px;
  border-radius: 4px;
  margin-top: auto;
}


/* ================================================================
   LAYOUT: LANDSCAPE
   Left column: Artwork + controls bar pinned below
   Right column: Song info (title, artist, next) centered
   Bottom: Ad
   ================================================================ */
.layout-landscape .player {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto auto;
  grid-template-areas:
    "artwork  info"
    "controls controls"
    "ad       ad";
  align-content: center;
  padding: clamp(6px, 2vh, 16px) clamp(8px, 2vw, 20px);
  gap: clamp(4px, 1vh, 8px) clamp(8px, 2vw, 20px);
  height: 100%;
}

/* ── Left column wrapper — transparent, children get grid areas ── */
.layout-landscape .player-left-col {
  display: contents;
}

/* ── Artwork — square cards, height-driven ── */
.layout-landscape .player-artwork-stack {
  grid-area: artwork;
  height: clamp(80px, 55vh, 280px);
  aspect-ratio: 1.21;
  display: flex;
  align-items: center;
  flex-shrink: 1;
  min-height: 0;
}
.layout-landscape .artwork-current {
  height: 100%;
  aspect-ratio: 1;
  flex-shrink: 0;
  position: relative;
  z-index: 2;
  order: 1;
}
.layout-landscape .artwork-next {
  height: 85%;
  aspect-ratio: 1;
  position: absolute;
  top: 7.5%;
  right: 0;
  z-index: 1;
}
.layout-landscape .artwork-card { border-radius: clamp(4px, 1vh, 10px); }
.layout-landscape .artwork-overlay { display: none; }

/* ── Controls bar — full-width row under artwork ── */
.layout-landscape .player-controls-bar {
  grid-area: controls;
  display: flex;
  align-items: center;
  gap: clamp(4px, 1vw, 8px);
  flex-shrink: 0;
}

/* Play button */
.layout-landscape .player-controls { padding: 0; flex-shrink: 0; }
.layout-landscape .btn-play {
  --base: 100vh;
  width: clamp(28px, calc(var(--base) * 0.07), 48px);
  height: clamp(28px, calc(var(--base) * 0.07), 48px);
}
.layout-landscape .btn-play svg {
  width: clamp(14px, calc(100vh * 0.04), 24px);
  height: clamp(14px, calc(100vh * 0.04), 24px);
}

/* Seekbar — fills remaining space */
.layout-landscape .player-seekbar { padding: 0; flex: 1; min-width: 0; }
.layout-landscape .time-current,
.layout-landscape .time-total {
  font-size: clamp(9px, 1.8vh, 14px);
}

/* Volume + Theme inline */
.layout-landscape .player-bottom-controls {
  display: flex;
  align-items: center;
  gap: clamp(2px, 0.5vw, 6px);
  flex-shrink: 0;
}

/* Volume — button only, vertical popup slider ── */
.layout-landscape .player-volume {
  position: relative;
  padding: 0;
}
.layout-landscape .volume-slider {
  display: none;
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  transform-origin: bottom center;
  writing-mode: vertical-lr;
  direction: rtl;
  width: 4px;
  height: clamp(50px, 12vh, 100px);
  margin-bottom: 4px;
  z-index: 10;
}
.layout-landscape .player-volume.vol-open .volume-slider {
  display: block;
}

/* Theme */
.layout-landscape .btn-theme { margin-right: 0; }

/* ── Song info — title, artist, next — centered vertically ── */
.layout-landscape .player-info {
  grid-area: info;
  align-self: stretch;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0;
  min-width: 0;
  padding-bottom: clamp(20px, 4vh, 40px); /* reserve space for absolute Next */
}
.layout-landscape .song-title {
  font-size: clamp(14px, 3.5vh, 28px);
  font-weight: 700;
  line-height: 1.3;
}
.layout-landscape .song-artist {
  font-size: clamp(12px, 2.8vh, 22px);
  margin-top: clamp(2px, 0.5vh, 6px);
}
.layout-landscape .player-next {
  display: flex;
  align-items: center;
  gap: 4px;
  position: absolute;
  bottom: 7.5%;
  left: 0;
}
.layout-landscape .next-label {
  font-size: clamp(10px, 2vh, 15px);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  flex-shrink: 0;
}
.layout-landscape .next-title {
  font-size: clamp(11px, 2.2vh, 17px);
  font-weight: 700;
  color: var(--text-secondary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.layout-landscape .next-artist {
  font-size: clamp(11px, 2.2vh, 17px);
  font-weight: 400;
  color: var(--text-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.layout-landscape .next-artist::before { content: '— '; }
.layout-landscape .next-artist:empty { display: none; }

/* ── Logo — hidden ── */
.layout-landscape .player-logo { display: none; }

/* ── Ad — full width bottom ── */
.layout-landscape .player-ad { grid-area: ad; width: 100%; height: clamp(30px, 6vh, 50px); }


/* ================================================================
   LAYOUT: BOTTOMLINE
   Small artwork+next, single row
   Line 1: Artist - Title
   Line 2: Next artist - title (smaller)
   Controls + volume to the right
   Seekbar as thin progress bar along the bottom
   ================================================================ */
.layout-bottomline .player {
  display: grid;
  grid-template-columns: auto 1fr auto auto auto;
  grid-template-rows: auto 3px;
  grid-template-areas:
    "artwork info  controls volume theme"
    "seekbar seekbar seekbar seekbar seekbar";
  align-items: center;
  height: 64px;
  width: 100%;
  border-top: 1px solid var(--border);
}

/* Small artwork */
.layout-bottomline .player-artwork-stack {
  grid-area: artwork;
  width: 72px; height: 50px;
  margin: 7px 8px 7px 10px;
}
.layout-bottomline .artwork-current {
  width: 50px; height: 50px;
  border-radius: 6px;
}
.layout-bottomline .artwork-card { border-radius: 6px; }
.layout-bottomline .artwork-next {
  width: 38px;
  top: 5%; bottom: 5%;
  right: 0;
  border-radius: 6px;
}
.layout-bottomline .artwork-overlay { display: none; }

/* Song info — current title/artist on line 1, next on line 2 */
.layout-bottomline .player-info {
  grid-area: info;
  padding-right: 12px;
  min-width: 0;
}
.layout-bottomline .song-title { font-size: 13px; line-height: 1.3; }
.layout-bottomline .song-artist { font-size: 11px; margin-top: 1px; }
/* Next info text shown below current in bottomline */
.layout-bottomline .player-next {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 2px;
}
.layout-bottomline .next-label {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  flex-shrink: 0;
}
.layout-bottomline .next-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.layout-bottomline .next-artist {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.layout-bottomline .next-artist::before { content: '— '; }
.layout-bottomline .next-artist:empty { display: none; }

/* Controls */
.layout-bottomline .player-controls { grid-area: controls; padding: 0 6px; }
.layout-bottomline .btn-play { width: 34px; height: 34px; }
.layout-bottomline .btn-play svg { width: 16px; height: 16px; }

/* Volume — button only, horizontal popup slider */
.layout-bottomline .player-volume {
  grid-area: volume;
  padding: 0 4px;
  position: relative;
}
.layout-bottomline .volume-slider {
  display: none;
  position: absolute;
  bottom: 100%;
  right: 0;
  width: 100px;
  height: 4px;
  margin-bottom: 8px;
  z-index: 10;
  border-radius: 2px;
}
.layout-bottomline .player-volume.vol-open .volume-slider {
  display: block;
}

/* Theme */
.layout-bottomline .btn-theme { grid-area: theme; margin-right: 8px; }

/* Logo — hidden */
.layout-bottomline .player-logo { display: none; }

/* Seekbar — thin strip full width at bottom */
.layout-bottomline .player-seekbar {
  grid-area: seekbar;
  padding: 0; gap: 0;
}
.layout-bottomline .time-current,
.layout-bottomline .time-total { display: none; }
.layout-bottomline .seekbar-track { height: 3px; border-radius: 0; }
.layout-bottomline .seekbar-progress { border-radius: 0; }
.layout-bottomline .seekbar-dot { display: none; }

/* Ad — hidden in bottomline, too cramped */
.layout-bottomline .player-ad { display: none !important; }


/* ================================================================
   RESPONSIVE
   ================================================================ */
@media (max-width: 500px) {
  .layout-landscape .player-volume .volume-slider { width: 60px; }
}
@media (max-width: 400px) {
  .layout-bottomline .player-volume { display: none; }
}
@media (max-height: 380px) {
  .layout-portrait .player { padding: 8px 12px; gap: 4px; }
  .layout-portrait .player-artwork-stack { height: clamp(60px, 22vh, 140px); }
  .layout-portrait .song-title { font-size: 15px; }
  .layout-portrait .song-artist { font-size: 12px; }
}

/* ================================================================
   ACCENT COLOR OVERRIDE
   ================================================================ */
.player[style*="--accent-override"] .seekbar-progress {
  background: var(--accent-override, var(--seekbar-fill));
}
.player[style*="--accent-override"] .seekbar-dot {
  background: var(--accent-override, var(--seekbar-dot));
}
.player[style*="--accent-override"] .btn-play {
  background: var(--accent-override, var(--text-primary));
}

/* ================================================================
   ANIMATIONS
   ================================================================ */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.artwork-card img.loaded { animation: fadeIn 0.3s ease; }

/* Continuous marquee scroll — moves exactly one copy then loops seamlessly */
@keyframes vtextScroll {
  0%   { transform: translateY(0); }
  100% { transform: translateY(-50%); }
}
