:root {
  --bg: #0a0a0c;
  --bg-card: rgba(20, 20, 24, 0.75);
  --bg-card-solid: #141418;
  --bg-elevated: rgba(28, 28, 34, 0.9);
  --text: #f5f5f7;
  --text-muted: rgba(255, 255, 255, 0.65);
  --border: rgba(255, 255, 255, 0.08);
  --radius: 16px;
  --radius-sm: 12px;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
  /* station color overrides when set on .player-scene */
  --station-color: #c1272d;
  --station-color-rgb: 193, 39, 45;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
  position: relative;
}

@media (min-width: 700px) {
  #app {
    padding: 24px;
  }
}

.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  color: var(--text-muted);
}

.loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--station-color);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Full-bleed blurred cover + station-colored overlay */
.player-scene {
  position: relative;
  width: 100%;
  max-width: 420px;
  border-radius: var(--radius);
  isolation: isolate;
  z-index: 1;
}

/* Two-column layout wrapper: vertical on mobile, horizontal on desktop */
.player-layout {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.player-main {
  flex: 1;
  min-width: 0;
}

.player-sidebar {
  flex-shrink: 0;
}

@media (min-width: 700px) {
  .player-scene {
    max-width: 760px;
  }

  .player-layout {
    flex-direction: row;
    gap: 24px;
    align-items: flex-start;
  }

  .player-main {
    flex: 1;
    min-width: 0;
  }

  .player-sidebar {
    width: 240px;
    flex-shrink: 0;
  }

  .player-sidebar .station-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }
}

/* Full-viewport blurred background (behind everything) */
.bg-layer {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: 0;
  pointer-events: none;
}

.bg-cover {
  position: absolute;
  inset: -15%;
  width: 130%;
  height: 130%;
  object-fit: cover;
  filter: blur(40px) saturate(1.2) brightness(0.45);
  transform: scale(1.05);
  transition: opacity 0.6s ease;
}

.bg-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    165deg,
    transparent 0%,
    rgba(var(--station-color-rgb), 0.12) 25%,
    rgba(0, 0, 0, 0.7) 60%,
    rgba(0, 0, 0, 0.92) 100%
  );
  pointer-events: none;
}

/* Glass card on top */
.player-container {
  position: relative;
  z-index: 1;
  width: 100%;
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(255, 255, 255, 0.05);
}

.station-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
}

.station-logo {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  background: var(--border);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.station-info h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.02em;
}

.station-info .tagline {
  margin: 4px 0 0;
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* Now playing: cover + track */
.now-playing-card {
  display: flex;
  gap: 16px;
  align-items: center;
  background: var(--bg-elevated);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-bottom: 20px;
  min-height: 88px;
}

.cover-wrap {
  flex-shrink: 0;
  width: 72px;
  height: 72px;
  border-radius: 10px;
  overflow: hidden;
  background: var(--border);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.cover-art {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.cover-wrap--loading {
  background: linear-gradient(90deg, var(--border) 25%, rgba(255,255,255,0.06) 50%, var(--border) 75%);
  background-size: 200% 100%;
  animation: skeleton 1.2s ease-in-out infinite;
}

@keyframes skeleton {
  to { background-position: 200% 0; }
}

.track-info {
  flex: 1;
  min-width: 0;
}

.now-playing-label {
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--station-color);
  margin-bottom: 4px;
  font-weight: 600;
}

.track-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.track-artist {
  font-size: 0.82rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

/* Controls: volume (mute + slider) left, play center */
.controls-row {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
}

.volume-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.volume-controls .volume-slider {
  flex: 1;
  min-width: 80px;
}

.volume-controls .btn-mute {
  flex-shrink: 0;
}

.controls-row .btn-play {
  flex-shrink: 0;
}

.btn-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, color 0.2s, transform 0.1s, border-color 0.2s;
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--station-color);
  border-color: rgba(var(--station-color-rgb), 0.4);
}

.btn-icon:active {
  transform: scale(0.95);
}

.btn-icon svg {
  width: 22px;
  height: 22px;
}

.btn-play {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: none;
  background: var(--station-color);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.1s, box-shadow 0.25s;
  box-shadow: 0 4px 20px rgba(var(--station-color-rgb), 0.45);
}

.btn-play:hover {
  filter: brightness(1.1);
  box-shadow: 0 6px 28px rgba(var(--station-color-rgb), 0.5);
}

.btn-play:active {
  transform: scale(0.96);
}

.btn-play svg {
  width: 26px;
  height: 26px;
}

.btn-play.paused .icon-pause {
  display: none;
}

.btn-play.playing .icon-play {
  display: none;
}

/* Volume (inside .volume-controls) */
.volume-controls .volume-slider {
  margin: 0;
}

.volume-slider {
  flex: 1;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  outline: none;
}

.volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--station-color);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.2s;
  box-shadow: 0 0 12px rgba(var(--station-color-rgb), 0.4);
}

.volume-slider::-webkit-slider-thumb:hover {
  transform: scale(1.12);
}

.volume-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--station-color);
  cursor: pointer;
  border: none;
  box-shadow: 0 0 12px rgba(var(--station-color-rgb), 0.4);
}

/* Stream error + retry */
.stream-error {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 10px 14px;
  margin-bottom: 14px;
  background: rgba(200, 60, 60, 0.15);
  border: 1px solid rgba(200, 60, 60, 0.4);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  color: #f88;
}

.btn-retry {
  padding: 4px 12px;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 6px;
  background: rgba(255,255,255,0.1);
  color: var(--text);
  font-size: 0.8rem;
  cursor: pointer;
}

.btn-retry:hover {
  background: rgba(255,255,255,0.15);
}

/* Mute button (same size as vol) */
.btn-mute .icon-muted,
.btn-mute .icon-unmuted {
  width: 22px;
  height: 22px;
}

/* Extra: sleep timer */
.extra-controls {
  margin-bottom: 14px;
}

.sleep-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: var(--radius-sm);
}

.sleep-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: var(--text-muted);
}

.sleep-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.sleep-unit {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.sleep-input {
  width: 3.5em;
  padding: 5px 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font-size: 0.8rem;
  text-align: center;
}

.sleep-input:focus {
  outline: none;
  border-color: rgba(var(--station-color-rgb), 0.5);
}

.sleep-input::placeholder {
  color: var(--text-muted);
}

/* Hide number input spinners */
.sleep-input::-webkit-outer-spin-button,
.sleep-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.sleep-input[type=number] {
  -moz-appearance: textfield;
}

.btn-sleep {
  margin-left: auto;
  padding: 5px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
  white-space: nowrap;
}

.btn-sleep:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.15);
}

/* Active state (countdown running) */
.sleep-wrap--active {
  background: rgba(var(--station-color-rgb), 0.08);
  border: 1px solid rgba(var(--station-color-rgb), 0.2);
}

.sleep-wrap--active .sleep-icon {
  color: var(--station-color);
}

.sleep-countdown {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.btn-sleep--cancel {
  border-color: rgba(200, 60, 60, 0.4);
  color: #f88;
}

.btn-sleep--cancel:hover {
  background: rgba(200, 60, 60, 0.15);
  border-color: rgba(200, 60, 60, 0.5);
}

/* Listening with (Discord) */
.listening-with {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  padding: 8px 12px;
  background: rgba(255,255,255,0.04);
  border-radius: var(--radius-sm);
}

.listening-with-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

.participants {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.participant-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
}

.participant-name {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.btn-invite {
  width: 100%;
  padding: 10px 14px;
  margin-bottom: 14px;
  border: 1px solid var(--station-color);
  border-radius: var(--radius-sm);
  background: rgba(var(--station-color-rgb), 0.15);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-invite:hover {
  background: rgba(var(--station-color-rgb), 0.25);
}

/* Station grid */
.station-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.station-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
  text-align: left;
  backdrop-filter: blur(8px);
}

.station-btn:hover {
  border-color: rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.08);
}

.station-btn.active {
  border-color: var(--station-color);
  background: rgba(var(--station-color-rgb), 0.18);
  box-shadow: 0 0 0 1px rgba(var(--station-color-rgb), 0.25);
}

.station-btn img {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  object-fit: cover;
}

.footer {
  margin-top: 16px;
  font-size: 0.72rem;
  color: var(--text-muted);
  text-align: center;
}

.footer a {
  color: var(--station-color);
  text-decoration: none;
}

.footer a:hover {
  text-decoration: underline;
}

.error-msg {
  color: #e55;
  font-size: 0.9rem;
  text-align: center;
  padding: 12px;
}

/* Reduced motion */
.reduce-motion .cover-wrap--loading,
.reduce-motion .loading-spinner {
  animation: none;
}

.reduce-motion .bg-cover {
  transition: none;
}

.reduce-motion .btn-play:hover,
.reduce-motion .volume-slider::-webkit-slider-thumb:hover {
  transform: none;
}

/* ======================================================
   Compact layout (Discord PiP / small panel)
   Display-only: no interactive controls, fully responsive.
   Adapts to square (mobile) and 16:9 (desktop) viewports.
   ====================================================== */
.layout-compact body,
body.layout-compact {
  min-height: 0;
  overflow: hidden;
}

.layout-compact #app {
  padding: 0;
  min-height: 0;
  height: 100vh;
  width: 100vw;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

.layout-compact .player-scene {
  max-width: 100%;
  width: 100%;
  border-radius: 0;
}

.layout-compact .player-layout {
  flex-direction: column;
  gap: 0;
}

.layout-compact .player-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  width: 100%;
  padding: 8px;
  border-radius: 0;
  border: none;
  box-shadow: none;
  background: rgba(10, 10, 12, 0.8);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

/* Hide station header in compact – the cover IS the identity */
.layout-compact .station-header {
  display: none;
}

/* Now-playing: vertical layout, centered, fills the space */
.layout-compact .now-playing-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 0;
  margin: 0;
  min-height: auto;
  gap: 0;
  border: none;
  background: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  width: 100%;
  flex: 0 0 auto;
}

/* Cover art: responsive, scales with the smaller viewport dimension */
.layout-compact .cover-wrap {
  /* Use the smaller of 55% viewport width or 55% viewport height */
  width: min(55vw, 55vh);
  height: min(55vw, 55vh);
  border-radius: min(3vw, 3vh);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  margin-bottom: min(2vh, 10px);
  flex-shrink: 0;
}

/* Track info: centered below cover */
.layout-compact .track-info {
  text-align: center;
  width: 100%;
  padding: 0 8px;
}

.layout-compact .now-playing-label {
  font-size: clamp(0.45rem, 2.5vw, 0.65rem);
  margin-bottom: 2px;
  text-align: center;
}

.layout-compact .track-artist {
  font-size: clamp(0.7rem, 5vw, 1rem);
  white-space: nowrap;
  text-align: center;
}

.layout-compact .track-title {
  font-size: clamp(0.85rem, 6.5vw, 1.25rem);
  margin-top: 2px;
  white-space: nowrap;
  text-align: center;
}

/* Hide all interactive controls – PiP is not interactive */
.layout-compact .controls-row,
.layout-compact .extra-controls,
.layout-compact .listening-with,
.layout-compact .btn-invite,
.layout-compact .player-sidebar,
.layout-compact .footer,
.layout-compact .stream-error {
  display: none;
}

/* Tone down the blurred background */
.layout-compact .bg-cover {
  filter: blur(30px) saturate(1.0) brightness(0.3);
}

/* ----- Aspect-ratio tweaks ----- */

/* Wide viewport (16:9 desktop PiP): vertical centered, header pinned top-left */
@media (min-aspect-ratio: 14/10) {
  /* Container uses relative positioning so header can be pinned */
  .layout-compact .player-container {
    position: relative;
  }

  /* Station header: pinned top-left, over the centered content */
  .layout-compact .station-header {
    display: flex;
    position: absolute;
    top: clamp(6px, 2vh, 12px);
    left: clamp(8px, 2vw, 14px);
    margin: 0;
    gap: 6px;
    z-index: 2;
  }

  .layout-compact .station-logo {
    width: clamp(16px, 5vh, 24px);
    height: clamp(16px, 5vh, 24px);
    border-radius: 5px;
    box-shadow: none;
  }

  .layout-compact .station-info h1 {
    font-size: clamp(0.55rem, 3.5vh, 0.78rem);
  }

  .layout-compact .station-info .tagline {
    display: none;
  }

  /* Now-playing: horizontal – cover left, text right */
  .layout-compact .now-playing-card {
    flex-direction: row;
    text-align: left;
    gap: min(3vw, 16px);
  }

  .layout-compact .cover-wrap {
    width: min(65vh, 40vw);
    height: min(65vh, 40vw);
    margin-bottom: 0;
  }

  .layout-compact .track-info {
    text-align: left;
    padding: 0;
  }

  .layout-compact .now-playing-label {
    text-align: left;
    font-size: clamp(0.5rem, 3vh, 0.75rem);
  }

  .layout-compact .track-title {
    text-align: left;
    font-size: clamp(1rem, 8vh, 1.5rem);
  }

  .layout-compact .track-artist {
    text-align: left;
    font-size: clamp(0.8rem, 6vh, 1.2rem);
  }
}

/* Tall / square viewport (mobile PiP): vertical layout, bigger cover */
@media (max-aspect-ratio: 14/10) {
  .layout-compact .cover-wrap {
    width: min(60vw, 45vh);
    height: min(60vw, 45vh);
  }
}
