:root {
  /* "only dark" reduces DuckDuckGo / system force-dark from crushing contrast */
  color-scheme: only dark;
  --bg: #07080d;
  --surface: #12141c;
  --surface-2: #1a1e2a;
  --border: #2a3144;
  --text: #eef1f8;
  --muted: #a8b2c4;
  --accent: #6c8cff;
  --accent-2: #ff6bcb;
  --success: #4ade80;
  --warn: #fbbf24;
  --danger: #f87171;
  --radius: 16px;
  --glow: 0 0 40px rgba(108, 140, 255, 0.18);
}

/* DuckDuckGo Android force-dark / inverted controls */
html {
  color-scheme: only dark;
  background: #07080d;
}
body {
  /* ensure body wins over browser night-mode filters */
  forced-color-adjust: none;
  -webkit-text-size-adjust: 100%;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--text);
  background:
    radial-gradient(ellipse at 20% 0%, rgba(255, 107, 203, 0.12), transparent 45%),
    radial-gradient(ellipse at 80% 10%, rgba(108, 140, 255, 0.14), transparent 40%),
    var(--bg);
}

.app {
  max-width: 1280px;
  margin: 0 auto;
  padding: 1.25rem;
  height: 100vh;
  max-height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  box-sizing: border-box;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background:
    conic-gradient(from 180deg, var(--accent), var(--accent-2), var(--accent));
  box-shadow: var(--glow);
}

.brand h1 {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: 0.02em;
}

.tagline {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

/* Host-only chrome (credits, ACE health) — hidden for public friends */
.host-only.hidden {
  display: none !important;
}

/* Account chip (signed-in) */
.auth-pill {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
}
.auth-user-chip {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.45rem 0.25rem 0.65rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(18, 20, 28, 0.92);
  font-size: 0.8rem;
}
.auth-user-chip.hidden { display: none !important; }
.auth-bal {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.auth-bal strong { color: #e9e0ff; }

.dj-auth-panel {
  margin: 0.25rem 0 0.75rem;
  padding: 0.85rem 0.9rem;
  border-radius: 14px;
  border: 1px solid rgba(108, 140, 255, 0.35);
  background: rgba(40, 55, 100, 0.2);
}
.dj-auth-panel.hidden { display: none !important; }
.dj-auth-tabs {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.65rem;
}
.dj-auth-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.dj-auth-form label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.8rem;
  color: var(--muted);
}
.dj-auth-form input {
  min-height: 48px;
  font-size: 16px;
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
}
.btn-auth-submit {
  min-height: 48px;
  margin-top: 0.25rem;
  font-weight: 700;
}

/* Always-visible Be the DJ entry point in the top bar */
.btn-be-dj {
  flex-shrink: 0;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
  border-color: rgba(196, 181, 253, 0.55) !important;
  background: linear-gradient(135deg, rgba(124, 108, 240, 0.95), rgba(108, 140, 255, 0.9)) !important;
  color: #fff !important;
  box-shadow: 0 0 0 1px rgba(196, 181, 253, 0.2), 0 8px 20px rgba(80, 70, 180, 0.25);
}
.btn-be-dj:hover {
  filter: brightness(1.06);
}
.btn-react {
  min-width: 4.5rem;
  font-size: 0.85rem;
}

.credits-pill {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.4rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(18, 20, 28, 0.9);
  font-size: 0.85rem;
}
.credits-pill .credits-label {
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.credits-pill strong {
  min-width: 1.5rem;
  text-align: center;
  color: var(--accent);
}

.health-bar {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.health-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(18, 20, 28, 0.8);
  font-size: 0.8rem;
}

.health-detail {
  color: var(--muted);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}

.dot[data-state="ok"] { background: var(--success); box-shadow: 0 0 8px var(--success); }
.dot[data-state="down"] { background: var(--danger); box-shadow: 0 0 8px var(--danger); }
.dot[data-state="warn"] { background: var(--warn); }

.layout {
  display: grid;
  /* Left: stations + DJ · Right: full player */
  grid-template-columns: minmax(280px, 340px) 1fr;
  grid-template-rows: minmax(0, 1fr) minmax(140px, 0.42fr);
  grid-template-areas:
    "stations player"
    "chat player";
  gap: 1rem;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.stations-panel { grid-area: stations; }
.player-panel { grid-area: player; }
.chat-panel { grid-area: chat; }

.stations-head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.stations-toggle {
  flex-shrink: 0;
  display: none; /* phone only */
}

.stations-collapsed-bar {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  margin-top: 0.35rem;
  padding: 0.55rem 0.7rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
}

.stations-collapsed-label {
  font-weight: 600;
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.now-station-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.btn-change-station {
  display: none; /* phone only */
  flex-shrink: 0;
  position: relative;
  overflow: visible;
}

.stations-btn-label {
  position: relative;
  z-index: 1;
}

.pick-station-hint {
  display: none;
  margin: 0.15rem 0 0.25rem;
  font-size: 0.82rem;
}

.pick-station-hint[hidden] {
  display: none !important;
}

/* Moving bubble orbit on the Stations button (phone, until tuned) */
.stations-orbit {
  pointer-events: none !important;
  position: absolute;
  inset: -5px;
  border-radius: 16px;
  z-index: 0;
  display: none;
  background: transparent;
  box-shadow: 0 0 0 2px rgba(108, 140, 255, 0.6);
  animation: stations-orbit-pulse 1.8s ease-in-out infinite;
}

/* Dim layer behind station sheet (phone only when open) */
.stations-sheet-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 70;
  background: rgba(0, 0, 0, 0.55);
  -webkit-tap-highlight-color: transparent;
}

body.stations-sheet-open .stations-sheet-backdrop,
.stations-sheet-backdrop.visible {
  display: block;
}

/*
 * Station sheet — iPhone WebKit (Safari/Chrome/DDG all same engine):
 * 1) Definite height (not just max-height)
 * 2) Absolute-fill list (flex overflow is flaky on iOS)
 * 3) Cards are DIVs not buttons (buttons capture touch → no scroll)
 * JS also sets pixel heights via visualViewport when open.
 */
.stations-panel.stations-sheet {
  position: fixed !important;
  left: 0.45rem;
  right: 0.45rem;
  top: max(0.65rem, env(safe-area-inset-top, 0px));
  bottom: auto;
  height: min(84dvh, 84vh, 640px) !important;
  max-height: min(84dvh, 84vh, 640px) !important;
  z-index: 80 !important;
  order: unset !important;
  overflow: hidden !important;
  display: flex !important;
  flex-direction: column !important;
  padding: 0.85rem 0.9rem 1rem;
  border: 2px solid #9ec0ff !important;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.7);
  background: #2a3148 !important;
  color: #ffffff !important;
  -webkit-text-fill-color: #ffffff !important;
  forced-color-adjust: none;
  filter: none !important;
  opacity: 1 !important;
  pointer-events: auto !important;
  /* auto: allow child list to pan-y (manipulation blocks nested scroll on iOS) */
  touch-action: auto;
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
}
.stations-panel.stations-sheet .panel-head {
  flex: 0 0 auto !important;
  min-height: 0;
  position: relative;
  z-index: 1;
}
.stations-panel.stations-sheet h2,
.stations-panel.stations-sheet .panel-head h2 {
  color: #ffffff !important;
  -webkit-text-fill-color: #ffffff !important;
  letter-spacing: 0.06em;
}
.stations-panel.stations-sheet .muted,
.stations-panel.stations-sheet .panel-head .muted {
  color: #d8e0f0 !important;
  -webkit-text-fill-color: #d8e0f0 !important;
}
.stations-panel.stations-sheet .stations-toggle,
.stations-panel.stations-sheet .btn {
  color: #ffffff !important;
  -webkit-text-fill-color: #ffffff !important;
  border-color: #9ec0ff !important;
  background: #3d4a6b !important;
  touch-action: manipulation;
}
.stations-panel.stations-sheet .stations-body {
  position: relative !important;
  display: block !important;
  flex: 1 1 auto !important;
  min-height: 12rem !important;
  overflow: hidden !important;
  /* height filled by JS on iOS; CSS fallback */
  height: 100%;
}
.stations-panel.stations-sheet .stations-expand-only {
  display: block !important;
}
.stations-panel.stations-sheet #stations-collapsed-bar {
  display: none !important;
}
/* Absolute fill scrollport — reliable on iOS Safari */
.stations-panel.stations-sheet .station-list {
  position: absolute !important;
  left: 0 !important;
  right: 0 !important;
  top: 0 !important;
  bottom: 0 !important;
  width: 100% !important;
  height: 100% !important;
  max-height: none !important;
  min-height: 0 !important;
  overflow-x: hidden !important;
  overflow-y: scroll !important;
  -webkit-overflow-scrolling: touch !important;
  overscroll-behavior: contain;
  touch-action: pan-y !important;
  background: #1a2035 !important;
  border: 1px solid #6b7fa8 !important;
  pointer-events: auto !important;
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
}
.stations-panel.stations-sheet .station-card {
  display: block !important;
  flex: 0 0 auto !important;
  background: #3d4d72 !important;
  background-color: #3d4d72 !important;
  background-image: linear-gradient(
    90deg,
    color-mix(in srgb, var(--station-color, #b8d0ff) 22%, #3d4d72) 0%,
    #3d4d72 55%
  ) !important;
  color: #ffffff !important;
  -webkit-text-fill-color: #ffffff !important;
  border: 1px solid #8aa0cc !important;
  border-left: 5px solid var(--station-color, #b8d0ff) !important;
  -webkit-appearance: none !important;
  appearance: none !important;
  opacity: 1 !important;
  filter: none !important;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  touch-action: pan-y !important;
  pointer-events: auto !important;
  cursor: pointer;
  min-height: 52px;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: rgba(158, 192, 255, 0.25);
}
.stations-panel.stations-sheet .station-card .name {
  color: #ffffff !important;
  -webkit-text-fill-color: #ffffff !important;
  font-weight: 800 !important;
  font-size: 1.02rem !important;
  opacity: 1 !important;
  pointer-events: none;
}
.stations-panel.stations-sheet .station-card .desc {
  color: #e4ebf8 !important;
  -webkit-text-fill-color: #e4ebf8 !important;
  opacity: 1 !important;
  pointer-events: none;
}
.stations-panel.stations-sheet .station-card.active {
  background: #4f6db8 !important;
  background-image: linear-gradient(
    90deg,
    color-mix(in srgb, var(--station-color, #c5d8ff) 35%, #4f6db8) 0%,
    #4f6db8 60%
  ) !important;
  border-color: var(--station-color, #c5d8ff) !important;
  box-shadow:
    inset 0 0 0 1px color-mix(in srgb, var(--station-color, #c5d8ff) 50%, transparent),
    0 2px 10px rgba(0, 0, 0, 0.28);
}
.stations-panel.stations-sheet .station-filter {
  background: #1a2035 !important;
  color: #ffffff !important;
  -webkit-text-fill-color: #ffffff !important;
  border: 1px solid #8aa0cc !important;
  font-size: 16px !important;
  touch-action: manipulation;
}
.stations-panel.stations-sheet .station-filter::placeholder {
  color: #b0bdd4 !important;
  opacity: 1 !important;
}
.stations-panel.stations-sheet.collapsed {
  display: none !important;
}
.stations-panel.stations-sheet .custom-editor:not(.hidden) {
  position: relative;
  z-index: 2;
  max-height: 38%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  background: #2a3148;
}
body.stations-sheet-open {
  overflow: hidden !important;
  overscroll-behavior: none;
  /* position:fixed is applied by JS (saves scrollY) */
  touch-action: none;
}
body.stations-sheet-open .stations-sheet-backdrop {
  pointer-events: auto;
  touch-action: none;
}
/* Sheet + list must still receive gestures when body is touch-action:none */
body.stations-sheet-open .stations-panel.stations-sheet,
body.stations-sheet-open .stations-panel.stations-sheet .station-list,
body.stations-sheet-open .stations-panel.stations-sheet .station-card {
  touch-action: pan-y !important;
}
body.stations-sheet-open .stations-panel.stations-sheet .stations-toggle,
body.stations-sheet-open .stations-panel.stations-sheet .btn,
body.stations-sheet-open .stations-panel.stations-sheet .station-filter {
  touch-action: manipulation !important;
}

.stations-orbit::before {
  content: "";
  position: absolute;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #fff 0%, #8eb0ff 45%, #6c8cff 100%);
  box-shadow: 0 0 12px 3px rgba(108, 140, 255, 0.85);
  top: -5px;
  left: 10%;
  animation: stations-bubble-fallback 2.4s linear infinite;
}

@keyframes stations-orbit-pulse {
  0%, 100% {
    box-shadow: 0 0 0 2px rgba(108, 140, 255, 0.5), 0 0 10px rgba(108, 140, 255, 0.25);
    transform: scale(1);
  }
  50% {
    box-shadow: 0 0 0 4px rgba(140, 175, 255, 0.9), 0 0 24px rgba(108, 140, 255, 0.55);
    transform: scale(1.03);
  }
}

@keyframes stations-bubble-fallback {
  0%   { top: -5px; left: 8%; }
  25%  { top: 42%; left: calc(100% - 5px); }
  50%  { top: calc(100% - 5px); left: 52%; }
  75%  { top: 38%; left: -5px; }
  100% { top: -5px; left: 8%; }
}

@keyframes stations-btn-glow {
  0%, 100% {
    filter: brightness(1);
    box-shadow: 0 0 0 0 rgba(108, 140, 255, 0.45);
  }
  50% {
    filter: brightness(1.12);
    box-shadow: 0 0 18px 2px rgba(108, 140, 255, 0.55);
  }
}

/* Pulse until station-tuned (stable: HTML starts needs-station; JS adds station-tuned) */
body:not(.station-tuned) .btn-change-station .stations-orbit {
  display: block;
}

body:not(.station-tuned) .btn-change-station {
  animation: stations-btn-glow 1.8s ease-in-out infinite;
}

body.station-tuned .stations-orbit {
  display: none !important;
}

body.station-tuned .btn-change-station {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
  font-weight: 600;
  animation: none;
  filter: none;
  box-shadow: none;
}

/* Desktop: never pulse */
@media (min-width: 901px) {
  body:not(.station-tuned) .btn-change-station {
    animation: none;
  }
  body:not(.station-tuned) .btn-change-station .stations-orbit {
    display: none !important;
  }
}

@media (max-width: 900px) {
  .app {
    height: auto;
    min-height: 100dvh;
    max-height: none;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 0.55rem 0.6rem calc(0.55rem + env(safe-area-inset-bottom));
    gap: 0.5rem;
    -webkit-overflow-scrolling: touch;
  }
  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.4rem;
    flex-shrink: 0;
  }
  .brand h1 {
    font-size: 1.1rem;
  }
  .tagline {
    font-size: 0.72rem;
  }
  .credits-pill {
    justify-content: space-between;
    width: 100%;
  }
  .health-bar {
    width: 100%;
    gap: 0.35rem;
  }
  .health-item {
    font-size: 0.7rem;
    padding: 0.3rem 0.45rem;
  }
  .health-detail {
    max-width: 72px;
  }
  #btn-restart-acestep {
    display: none; /* free space on phone; use desktop if needed */
  }

  .layout {
    display: flex;
    flex-direction: column;
    overflow: visible;
    gap: 0.5rem;
  }

  /* Player first — never buried under the dial */
  .player-panel {
    order: 1;
    padding: 0;
    flex: none;
    overflow: visible;
  }
  .stations-panel {
    order: 2;
    flex: none;
    min-height: 0;
    max-height: none;
    padding: 0.65rem 0.75rem;
    overflow: visible;
  }
  .chat-panel {
    order: 3;
    flex: none;
    max-height: 32vh;
    min-height: 120px;
    padding: 0.6rem 0.7rem;
  }

  .stations-toggle {
    display: inline-flex;
    min-height: 40px;
    touch-action: manipulation;
  }
  .btn-change-station {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 50px;
    min-width: 8rem;
    padding: 0.6rem 1.15rem;
    font-size: 1.05rem;
    font-weight: 700;
    touch-action: manipulation;
    border-radius: 14px;
    position: relative;
    z-index: 2; /* above orbit decoration */
    -webkit-tap-highlight-color: rgba(108, 140, 255, 0.25);
  }
  body:not(.station-tuned) .btn-change-station {
    min-height: 54px;
    min-width: 9rem;
    font-size: 1.12rem;
  }
  body.boot-ready:not(.station-tuned) .pick-station-hint {
    display: block;
  }
  body:not(.station-tuned) .play-gate {
    opacity: 0.78;
  }
  /* Collapsed dial is the default in HTML — keep collapsed styles even before JS */
  .stations-panel.collapsed .stations-body,
  .stations-panel.collapsed .stations-expand-only {
    display: none !important;
  }
  .stations-panel.collapsed #stations-collapsed-bar {
    display: flex;
  }
  .stations-hint {
    display: none;
  }

  /* Open dial = fixed sheet (iOS WebKit scroll-safe) */
  .stations-panel.stations-sheet {
    position: fixed !important;
    left: 0.5rem;
    right: 0.5rem;
    top: max(0.65rem, env(safe-area-inset-top, 0px));
    bottom: auto;
    height: min(84dvh, 84vh, 640px) !important;
    max-height: min(84dvh, 84vh, 640px) !important;
    z-index: 80 !important;
    order: unset !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
    padding: 0.75rem 0.85rem 0.9rem;
    border: 2px solid #9ec0ff !important;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.55);
    background: #2a3148 !important;
  }
  .stations-panel.stations-sheet.collapsed {
    display: none !important;
  }
  .stations-panel.stations-sheet .stations-body {
    position: relative !important;
    display: block !important;
    min-height: 12rem !important;
    flex: 1 1 auto !important;
    overflow: hidden !important;
  }
  .stations-panel.stations-sheet .stations-expand-only {
    display: block !important;
  }
  .stations-panel.stations-sheet #stations-collapsed-bar {
    display: none !important;
  }
  .stations-panel.stations-sheet .station-list {
    position: absolute !important;
    left: 0 !important;
    right: 0 !important;
    top: 0 !important;
    bottom: 0 !important;
    height: 100% !important;
    max-height: none !important;
    overflow-y: scroll !important;
    -webkit-overflow-scrolling: touch !important;
    touch-action: pan-y !important;
  }
  body.stations-sheet-open {
    overflow: hidden !important;
    overscroll-behavior: none;
  }

  /* Up next: compact on phone so it doesn't own the screen */
  .queue-box {
    padding-top: 0.45rem;
    margin-top: 0.1rem;
  }
  .queue-head {
    width: 100%;
    margin: 0;
    padding: 0.4rem 0.15rem;
    background: transparent;
    border: none;
    color: inherit;
    font: inherit;
    cursor: pointer;
    touch-action: manipulation;
  }
  .queue-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    min-height: 40px;
  }
  .queue-head-right {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
  }
  .queue-chevron {
    display: inline-block;
    font-size: 0.85rem;
    color: var(--muted);
    transition: transform 0.15s ease;
  }
  .queue-box.open .queue-chevron {
    transform: rotate(90deg);
  }
  .queue-list {
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    margin: 0;
    transition: max-height 0.2s ease, opacity 0.15s ease, margin 0.15s ease;
  }
  .queue-list.collapsed {
    max-height: 0 !important;
    opacity: 0;
    pointer-events: none;
  }
  .queue-box.open .queue-list {
    max-height: 5.5rem; /* ~2 short rows */
    opacity: 1;
    margin-top: 0.25rem;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .queue-list li {
    padding: 0.35rem 0.5rem;
    font-size: 0.82rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .library-list {
    max-height: min(42vh, 320px);
    min-height: 8rem;
  }

  /* Collapsed dial: one-line summary, no scroll trap */
  .stations-panel.collapsed .stations-body,
  .stations-panel.collapsed .stations-expand-only {
    display: none !important;
  }
  .stations-panel.collapsed #stations-collapsed-bar {
    display: flex;
  }
  .stations-panel:not(.collapsed) #stations-collapsed-bar {
    display: none !important;
  }

  /* Expanded: taller scrollable dial so stations are readable */
  .stations-panel:not(.collapsed) {
    max-height: min(48vh, 360px);
  }
  .stations-panel:not(.collapsed) .stations-body {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    min-height: 0;
    flex: 1 1 auto;
  }
  .station-filter {
    margin-bottom: 0.35rem;
    font-size: 16px; /* prevents iOS zoom on focus */
  }
  .station-list {
    display: flex;
    flex-direction: column;
    flex-wrap: nowrap;
    gap: 0.4rem;
    overflow-x: hidden;
    overflow-y: scroll;
    padding: 0.35rem 0.45rem 0.5rem 0.2rem;
    min-height: 8rem;
    max-height: min(32vh, 260px);
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-y;
    scrollbar-width: auto;
  }
  .station-card {
    flex: 0 0 auto;
    width: 100%;
    max-width: none;
    min-width: 0;
    min-height: 48px;
    padding: 0.65rem 0.75rem;
  }
  .station-card .name {
    font-size: 0.9rem;
    white-space: normal;
  }
  .station-card .desc {
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .player-scroll {
    max-height: none;
    overflow: visible;
    padding: 0.8rem;
    gap: 0.5rem;
  }
  .now-title {
    font-size: 1.3rem;
  }
  .now-caption {
    font-size: 0.85rem;
    min-height: 0;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .controls {
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.4rem;
    position: sticky;
    bottom: 0;
    padding: 0.45rem 0 calc(0.35rem + env(safe-area-inset-bottom));
    background: linear-gradient(transparent, rgba(7, 8, 13, 0.97) 25%);
    z-index: 5;
  }
  .controls .btn {
    min-height: 48px;
    min-width: 48px;
    font-size: 1rem;
    touch-action: manipulation;
  }
  .library-box {
    min-height: 0;
    /* Phones: collection is easy to miss under now-playing — give it room */
    order: 2;
    margin-top: 0.35rem;
    border-color: rgba(160, 220, 160, 0.35);
  }
  .library-list {
    max-height: min(48vh, 360px);
    min-height: 10rem;
  }
  .library-list li {
    min-height: 48px;
    gap: 0.4rem;
  }
  .library-list .lib-play,
  .library-list .lib-dl {
    min-height: 40px;
    min-width: 40px;
    padding: 0.3rem 0.45rem;
    font-size: 0.85rem;
  }
  .library-list .lib-row-new {
    background: rgba(100, 220, 140, 0.12);
    border-radius: 8px;
    padding-left: 0.35rem;
    padding-right: 0.35rem;
  }
  .library-list .dj-badge-new {
    vertical-align: middle;
  }
  .gen-box {
    padding: 0.6rem;
  }
  .gen-lyrics {
    max-height: 72px;
  }
  .btn-play-lg {
    width: 100%;
    min-height: 52px;
  }
}

.panel {
  background: rgba(18, 20, 28, 0.88);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem;
  box-shadow: var(--glow);
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.stations-panel {
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.stations-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  gap: 0.45rem;
}

.panel-head {
  flex-shrink: 0;
}

.panel-head h2 {
  margin: 0;
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.panel-head .muted,
.muted {
  color: var(--muted);
  font-size: 0.85rem;
}

.panel-head p {
  margin: 0.35rem 0 0.75rem;
}

.station-filter {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 999px;
  padding: 0.5rem 0.85rem;
  font-size: 0.85rem;
  margin-bottom: 0.65rem;
}

.station-filter:focus {
  outline: none;
  border-color: var(--accent);
}

.station-list {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  overflow-y: scroll;
  overflow-x: hidden;
  /* Fill panel so many stations stay visible + scrollable */
  flex: 1 1 auto;
  min-height: 180px;
  max-height: 100%;
  padding: 0.15rem 0.55rem 0.55rem 0.1rem;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-gutter: stable;
  scrollbar-width: auto;
  scrollbar-color: var(--accent) var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.18);
}

.station-list::-webkit-scrollbar {
  width: 12px;
}
.station-list::-webkit-scrollbar-track {
  background: var(--surface-2);
  border-radius: 999px;
  margin: 4px 0;
}
.station-list::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, var(--accent), #8b9fff);
  border-radius: 999px;
  border: 2px solid var(--surface-2);
}
.station-list::-webkit-scrollbar-thumb:hover {
  background: var(--accent-2);
}

.station-card {
  display: block;
  flex: 0 0 auto;
  text-align: left;
  border: 1px solid #3a4560;
  background-color: #243049;
  background-image: linear-gradient(
    90deg,
    color-mix(in srgb, var(--station-color, #8eb0ff) 18%, #243049) 0%,
    #243049 52%
  );
  color: #ffffff;
  border-radius: 12px;
  padding: 0.75rem 0.85rem;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s, background 0.15s, box-shadow 0.15s;
  border-left: 5px solid var(--station-color, #8eb0ff);
  width: 100%;
  box-sizing: border-box;
  /* DIV cards (not button) so iOS can scroll the list */
  -webkit-appearance: none !important;
  appearance: none !important;
  -webkit-text-fill-color: #ffffff !important;
  color: #ffffff !important;
  opacity: 1 !important;
  filter: none !important;
  mix-blend-mode: normal !important;
  forced-color-adjust: none;
  -webkit-tap-highlight-color: rgba(108, 140, 255, 0.2);
}

.station-card:hover,
.station-card:focus {
  border-color: var(--station-color, #8eb0ff);
  transform: translateY(-1px);
  outline: none;
}

.station-card:active {
  background-color: #2c3854;
}

.station-card.active {
  background-color: #2a3f6e;
  background-image: linear-gradient(
    90deg,
    color-mix(in srgb, var(--station-color, #9ec0ff) 32%, #2a3f6e) 0%,
    #2a3f6e 58%
  );
  border-color: var(--station-color, #9ec0ff);
  box-shadow:
    inset 0 0 0 1px color-mix(in srgb, var(--station-color, #9ec0ff) 55%, transparent),
    0 0 0 1px color-mix(in srgb, var(--station-color, #9ec0ff) 25%, transparent);
  color: #ffffff !important;
  -webkit-text-fill-color: #ffffff !important;
}

.station-card .name {
  font-weight: 700;
  margin-bottom: 0.25rem;
  font-size: 0.98rem;
  line-height: 1.3;
  color: #ffffff !important;
  -webkit-text-fill-color: #ffffff !important;
  opacity: 1 !important;
}

.station-card .desc {
  color: #d0d7e6 !important;
  -webkit-text-fill-color: #d0d7e6 !important;
  font-size: 0.8rem;
  line-height: 1.4;
  opacity: 1 !important;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.station-card .paid-tag {
  display: inline-block;
  margin-left: 0.35rem;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #c4b5fd;
  border: 1px solid rgba(196, 181, 253, 0.45);
  border-radius: 999px;
  padding: 0.05rem 0.4rem;
  vertical-align: middle;
}

.station-card.custom-card,
.station-card.dj-card {
  border-style: dashed;
  /* Keep left stripe as station color; only soft outer border for DJ cards */
  border-color: color-mix(in srgb, var(--station-color, #c4b5fd) 55%, #3a4560);
  border-left-style: solid;
  border-left-width: 5px;
  border-left-color: var(--station-color, #c4b5fd);
}

/* ===== Be the DJ full-screen app (mobile-first) ===== */
.dj-fs-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 20000;
  background: #07080d;
  /* no blur — blur felt like a fuzzy broken screen on phones */
}
.dj-fs-backdrop.visible {
  display: block;
}

.dj-fs {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 20010;
  width: 100%;
  height: 100%;
  max-height: 100dvh;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 0;
  background: #0a0c14;
  color: var(--text);
  flex-direction: column;
  overflow: hidden;
  -webkit-overflow-scrolling: touch;
}
.dj-fs:not(.hidden) {
  display: flex;
}
.dj-fs.hidden {
  display: none !important;
}

body.custom-editor-open,
body.dj-fs-open {
  overflow: hidden !important;
  position: fixed;
  width: 100%;
  height: 100%;
}
body.custom-editor-open .app,
body.dj-fs-open .app {
  visibility: hidden; /* hide radio under full-screen DJ */
  pointer-events: none;
}

.dj-fs-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding:
    max(0.65rem, env(safe-area-inset-top, 0px))
    max(0.75rem, env(safe-area-inset-right, 0px))
    0.55rem
    max(0.75rem, env(safe-area-inset-left, 0px));
  border-bottom: 1px solid var(--border);
  background: #12151f;
  min-height: 52px;
}
.dj-fs-title-wrap {
  flex: 1 1 auto;
  min-width: 0;
}
.dj-fs-title-wrap h2 {
  margin: 0;
  font-size: 1.1rem;
  line-height: 1.2;
}
.dj-fs-sub {
  margin: 0.1rem 0 0;
  font-size: 0.72rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dj-fs-close {
  min-height: 44px;
  min-width: 64px;
  font-weight: 700;
}
.dj-fs-credits {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.55rem;
  border-radius: 999px;
  border: 1px solid rgba(196, 181, 253, 0.35);
  background: rgba(196, 181, 253, 0.1);
  font-size: 0.8rem;
  flex-shrink: 0;
}
.dj-fs-credits strong {
  font-variant-numeric: tabular-nums;
  color: #e9e0ff;
}

.dj-fs-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding:
    0.75rem
    max(0.85rem, env(safe-area-inset-right, 0px))
    0
    max(0.85rem, env(safe-area-inset-left, 0px));
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}
.dj-fs-scroll.collapsed {
  /* kept for JS class toggles; full-screen never collapses body */
  display: flex;
}
.dj-fs-bottom-pad {
  height: max(1.5rem, env(safe-area-inset-bottom, 0px));
  flex-shrink: 0;
}
.dj-fs-actions {
  position: sticky;
  bottom: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  padding: 0.65rem 0 0.25rem;
  background: linear-gradient(180deg, transparent, #0a0c14 28%);
  z-index: 2;
}
.dj-fs-actions .btn {
  min-height: 48px;
  flex: 1 1 40%;
  font-size: 1rem;
  font-weight: 700;
}

.dj-credits-buy {
  margin: 0.25rem 0 0.55rem;
  padding: 0.65rem 0.7rem;
  border-radius: 12px;
  border: 1px solid rgba(74, 222, 128, 0.28);
  background: rgba(34, 120, 70, 0.12);
}
.dj-credit-pack {
  min-height: 44px;
  min-width: 4.2rem;
  font-weight: 700;
}

/* Legacy class hooks used by older CSS selectors */
.custom-editor { /* no-op alias */ }
.custom-editor.hidden { display: none !important; }
.custom-editor.expanded { /* handled by .dj-fs */ }

.custom-expand-toggle {
  display: none; /* removed from layout; topbar Be the DJ is entry */
}

.custom-editor-body {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  overflow-y: auto;
  min-height: 0;
  flex: 1;
  padding-right: 0.2rem;
  scrollbar-width: thin;
}

.custom-editor-body.collapsed {
  display: none;
}

.custom-editor.expanded .custom-editor-body {
  display: flex;
}

.custom-editor label {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 0.15rem;
}

.style-prompt-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.btn-xs {
  font-size: 0.72rem;
  padding: 0.2rem 0.5rem;
}

.dj-fs input,
.dj-fs textarea,
.dj-fs select,
.custom-editor input,
.custom-editor textarea {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 10px;
  padding: 0.7rem 0.75rem;
  font-size: 16px; /* iOS: avoid zoom-on-focus */
  font-family: inherit;
  resize: vertical;
  min-height: 44px;
}

.custom-style-input {
  min-height: 8rem;
  line-height: 1.45;
}

.custom-style-input.tall {
  min-height: min(40vh, 280px) !important;
}

.dj-fs input:focus,
.dj-fs textarea:focus,
.dj-fs select:focus {
  outline: none;
  border-color: var(--accent);
}

.tiny {
  font-size: 0.72rem;
  margin: 0;
}

.custom-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.35rem;
  flex-shrink: 0;
  position: sticky;
  bottom: 0;
  padding-top: 0.35rem;
  background: linear-gradient(transparent, rgba(14, 16, 24, 0.95) 30%);
}

.custom-actions .btn {
  font-size: 0.9rem;
  padding: 0.55rem 0.9rem;
}

.custom-editor.expanded .custom-actions .btn-primary {
  flex: 1;
}

.player-panel {
  align-items: stretch;
  gap: 0;
  overflow: hidden;
  padding: 0;
}

/* Scrollable center column — collection stays reachable while generating */
.player-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1.1rem;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.player-scroll::-webkit-scrollbar {
  width: 8px;
}
.player-scroll::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 999px;
}

.now-station {
  color: var(--accent);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 600;
}

.now-signature {
  margin: 0.25rem 0 0;
  font-size: 0.8rem;
  line-height: 1.35;
  min-height: 1.2em;
}

.now-title {
  margin: 0;
  font-size: 1.75rem;
  line-height: 1.2;
}

.now-caption {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
  min-height: 2.6em;
}

/* Mobile data / tunnel: full-song download progress */
.audio-load-bar {
  margin: 0.55rem 0 0.35rem;
  padding: 0.55rem 0.7rem;
  border-radius: 12px;
  border: 1px solid rgba(108, 140, 255, 0.35);
  background: rgba(108, 140, 255, 0.1);
}
.audio-load-bar.hidden {
  display: none !important;
}
.audio-load-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 0.4rem;
}
.audio-load-track {
  height: 8px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}
.audio-load-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), #a78bfa);
  transition: width 0.2s ease;
}

.progress-wrap { margin-top: 0.5rem; }

.progress-bar {
  height: 8px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.progress-bar.thin { height: 6px; }

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.2s linear;
}

.progress-fill.accent {
  background: var(--accent);
}

.time-row {
  display: flex;
  justify-content: space-between;
  margin-top: 0.35rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.play-gate {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.45rem;
  padding: 1rem 1.1rem;
  border-radius: 14px;
  border: 1px solid rgba(255, 107, 203, 0.45);
  background: linear-gradient(135deg, rgba(108, 140, 255, 0.2), rgba(255, 107, 203, 0.12));
  animation: pulse-nudge 1.6s ease-in-out infinite;
  margin: 0.35rem 0;
}

.play-gate.hidden { display: none; }

.play-gate p {
  margin: 0;
  font-size: 0.9rem;
}

.btn-play-lg {
  min-width: 180px;
  font-size: 1.15rem;
  padding: 0.85rem 1.5rem;
  font-weight: 700;
}

.play-nudge {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  flex-wrap: wrap;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  border: 1px solid rgba(108, 140, 255, 0.45);
  background: rgba(108, 140, 255, 0.14);
  animation: pulse-nudge 1.6s ease-in-out infinite;
}

.play-nudge.hidden { display: none !important; }

/* Phones: never show the pulse "play" strip — rebuffer is normal on tunnel/cell */
@media (max-width: 720px) {
  .play-nudge:not(.force-show) {
    display: none !important;
  }
}

.btn-play {
  min-width: 120px;
  font-size: 1.05rem;
  padding: 0.75rem 1.35rem;
}

@keyframes pulse-nudge {
  0%, 100% { box-shadow: 0 0 0 0 rgba(108, 140, 255, 0.25); }
  50% { box-shadow: 0 0 0 6px rgba(108, 140, 255, 0.05); }
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-top: 0.4rem;
}

.btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 999px;
  padding: 0.65rem 1.1rem;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}

.btn:hover:not(:disabled) {
  border-color: var(--accent);
  background: rgba(108, 140, 255, 0.12);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(135deg, #5a7cff, #7b5cff);
  border-color: transparent;
  font-weight: 600;
  min-width: 110px;
}

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.08);
  background: linear-gradient(135deg, #5a7cff, #7b5cff);
}

.btn-danger {
  border-color: rgba(248, 113, 113, 0.4);
  color: #fecaca;
}

.btn-ghost {
  min-width: 48px;
}

.btn-sm {
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
  min-width: auto;
}

.volume-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.volume-row input {
  flex: 1;
  accent-color: var(--accent);
}

.gen-box {
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 0.85rem;
  background: rgba(108, 140, 255, 0.06);
}

.gen-box.hidden { display: none; }

.gen-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
  margin-bottom: 0.25rem;
}

.gen-title {
  font-weight: 600;
  margin-bottom: 0.35rem;
}

.gen-meta {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.8rem;
  margin-bottom: 0.4rem;
}

.gen-caption {
  margin-top: 0.55rem;
  font-size: 0.85rem;
  line-height: 1.4;
}

.gen-lyrics {
  margin: 0.55rem 0 0;
  padding: 0.65rem 0.75rem;
  max-height: 140px;
  overflow-y: auto;
  font-size: 0.78rem;
  line-height: 1.35;
  white-space: pre-wrap;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 8px;
  border: 1px solid var(--border);
  color: var(--text);
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
}

.gen-lyrics.hidden { display: none; }

.queue-box {
  border-top: 1px solid var(--border);
  padding-top: 0.75rem;
  margin-top: 0.25rem;
}

.queue-head {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  margin-bottom: 0.4rem;
}

/* Desktop: queue always open (button still looks like a header) */
@media (min-width: 901px) {
  .queue-toggle {
    cursor: default;
    pointer-events: none;
  }
  .queue-chevron {
    display: none;
  }
  .queue-list,
  .queue-list.collapsed {
    max-height: none !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    overflow: visible;
  }
}

.queue-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.9rem;
}

.queue-list li {
  padding: 0.45rem 0.55rem;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid transparent;
}

.taste {
  margin: 0.25rem 0 0;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.4;
}

.error-line {
  color: var(--danger);
  font-size: 0.9rem;
  margin: 0;
}

.error-line.hidden { display: none; }

/* Station chat under stations on the left (grid area: chat) */
.chat-panel {
  min-height: 0;
  padding: 0.75rem 0.9rem;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.chat-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  flex-shrink: 0;
}

.chat-head-main {
  min-width: 0;
  flex: 1;
}

.chat-head-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.35rem;
  flex-shrink: 0;
}

.listeners-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
}

.listeners-pill strong {
  color: var(--text);
  font-variant-numeric: tabular-nums;
  min-width: 0.75rem;
  text-align: center;
}

.listeners-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
}

.listeners-pill.has-listeners .listeners-dot {
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
}

.chat-panel .panel-head h2 {
  font-size: 0.85rem;
}

.chat-panel .panel-head p {
  margin: 0.2rem 0 0.45rem;
  font-size: 0.75rem;
}

/* Expanded chat sheet */
.chat-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 85;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
}

.chat-backdrop.visible {
  display: block;
}

.chat-panel.expanded {
  position: fixed;
  left: max(0.75rem, env(safe-area-inset-left));
  right: max(0.75rem, env(safe-area-inset-right));
  top: max(3.5rem, env(safe-area-inset-top));
  bottom: max(0.75rem, env(safe-area-inset-bottom));
  width: auto;
  max-width: 520px;
  margin: 0 auto;
  z-index: 90;
  min-height: 0 !important;
  max-height: none !important;
  height: auto;
  order: unset;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(14, 16, 24, 0.98);
  box-shadow:
    0 0 0 1px rgba(108, 140, 255, 0.12),
    0 24px 64px rgba(0, 0, 0, 0.55),
    var(--glow);
  padding: 1rem 1.1rem;
}

.chat-panel.expanded .chat-log {
  min-height: 40vh;
  flex: 1 1 auto;
}

.chat-panel.expanded .chat-head-meta {
  flex-direction: row;
  align-items: center;
}

body.chat-expanded {
  overflow: hidden;
}

.chat-name-row {
  flex-shrink: 0;
  margin-bottom: 0.4rem;
}

.chat-name-row input {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 999px;
  padding: 0.4rem 0.75rem;
  font-size: 0.82rem;
}

.chat-name-row input:focus {
  outline: none;
  border-color: var(--accent);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.chat-log {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding-right: 0.25rem;
  margin-bottom: 0.5rem;
  min-height: 48px;
}

.chat-bubble .chat-who {
  display: block;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--accent);
  margin-bottom: 0.15rem;
}

.paid-badge {
  margin: 0 0 0.4rem;
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #c4b5fd;
  border: 1px solid rgba(196, 181, 253, 0.4);
  border-radius: 999px;
  padding: 0.2rem 0.55rem;
  background: rgba(196, 181, 253, 0.08);
}

.dj-paywall {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 0.5rem 0;
}

.dj-paywall.hidden,
.dj-form.hidden {
  display: none !important;
}

.dj-stats-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem 1rem;
  margin: 0 0 0.65rem;
  padding: 0.45rem 0.55rem;
  border-radius: 10px;
  background: rgba(196, 181, 253, 0.08);
  border: 1px solid rgba(196, 181, 253, 0.2);
  font-size: 0.85rem;
}
.dj-stat strong {
  color: #e9e0ff;
  font-variant-numeric: tabular-nums;
}

.dj-dna-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
  margin: 0.55rem 0 0.35rem;
  padding: 0.65rem 0.85rem;
  font-weight: 700;
  border: 1px solid rgba(196, 181, 253, 0.4) !important;
  background: rgba(196, 181, 253, 0.1) !important;
  color: #e9e0ff !important;
  border-radius: 12px;
}
.dj-dna-toggle[aria-expanded="true"] {
  border-color: rgba(108, 140, 255, 0.55) !important;
  background: rgba(108, 140, 255, 0.14) !important;
}
.dj-dna-chevron {
  transition: transform 0.15s ease;
  color: var(--muted);
}
.dj-dna-toggle[aria-expanded="true"] .dj-dna-chevron {
  transform: rotate(90deg);
}

.dj-dna-panel {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  margin: 0 0 0.75rem;
  padding: 0.75rem 0.8rem 0.9rem;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(18, 20, 28, 0.75);
}
.dj-dna-panel.collapsed,
.dj-dna-panel[hidden] {
  display: none !important;
}
.dj-dna-hint {
  margin: 0 0 0.25rem;
}
.dj-dna-save {
  min-height: 48px;
  margin-top: 0.35rem;
  font-weight: 700;
}

.dj-dna-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem 0.65rem;
  margin: 0.15rem 0 0.35rem;
}
.dj-dna-grid label {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.75rem;
  color: #b8c0d4;
}
.dj-dna-grid input,
.dj-dna-grid select {
  min-height: 40px;
  font-size: 16px;
}
@media (max-width: 520px) {
  .dj-dna-grid { grid-template-columns: 1fr; }
}

/* First free song CTA */
.dj-first-song {
  margin: 0.35rem 0 0.75rem;
  padding: 0.85rem 0.9rem;
  border-radius: 14px;
  border: 1px solid rgba(74, 222, 128, 0.4);
  background: linear-gradient(135deg, rgba(34, 120, 70, 0.28), rgba(124, 108, 240, 0.18));
}
.dj-first-song[hidden] { display: none !important; }
.dj-first-title {
  margin: 0 0 0.35rem;
  font-size: 1.05rem;
}
.dj-first-copy {
  margin: 0 0 0.65rem;
  line-height: 1.4;
}
.dj-first-btn {
  width: 100%;
  min-height: 52px;
  font-weight: 800;
  font-size: 1.05rem;
}
.dj-pay-hidden { display: none !important; }

/* Song Studio boxed entry (inside Be the DJ) */
.dj-studio-box {
  margin: 0.35rem 0 0.75rem;
  padding: 0.75rem 0.85rem 0.9rem;
  border-radius: 14px;
  border: 1px solid rgba(196, 181, 253, 0.4);
  background: linear-gradient(135deg, rgba(124, 108, 240, 0.16), rgba(80, 120, 200, 0.12));
}
.dj-studio-box-copy {
  margin: 0 0 0.65rem;
  line-height: 1.4;
}
.dj-studio-toggle {
  width: 100%;
  min-height: 48px;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
  font-size: 1rem;
  border-color: rgba(196, 181, 253, 0.45) !important;
  background: linear-gradient(135deg, rgba(124, 108, 240, 0.4), rgba(110, 168, 255, 0.25)) !important;
}
.dj-studio-toggle[aria-expanded="true"] {
  border-color: rgba(196, 181, 253, 0.75) !important;
  margin-bottom: 0.55rem;
}
.dj-studio-panel {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin: 0.15rem 0 0;
  padding: 0.65rem 0.15rem 0.25rem;
  border-radius: 0;
  border: none;
  border-top: 1px solid rgba(196, 181, 253, 0.22);
  background: transparent;
}
.dj-studio-panel.collapsed,
.dj-studio-panel[hidden] {
  display: none !important;
}
.dj-studio-panel label {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 0.1rem;
}
.dj-studio-panel input[type="text"],
.dj-studio-panel input[type="number"],
.dj-studio-panel textarea,
.dj-studio-panel select {
  width: 100%;
  min-height: 44px;
  font-size: 16px;
  box-sizing: border-box;
}
.dj-studio-panel textarea {
  min-height: 110px;
  resize: vertical;
  line-height: 1.35;
}
.dj-studio-details {
  margin: 0.25rem 0;
  border-radius: 10px;
  border: 1px solid var(--border);
  padding: 0.35rem 0.55rem 0.55rem;
  background: rgba(0, 0, 0, 0.18);
}
.dj-studio-details summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.85rem;
  padding: 0.35rem 0;
  list-style: none;
  color: #d4d8ee;
}
.dj-studio-details summary::-webkit-details-marker { display: none; }
.dj-studio-details[open] summary {
  margin-bottom: 0.35rem;
  color: #e9e0ff;
}
.dj-slider-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-top: 0.25rem;
}
.dj-slider-row input[type="range"] {
  flex: 1;
  min-height: 28px;
}
.dj-studio-full {
  grid-column: 1 / -1;
}
.dj-toggle-row {
  display: flex !important;
  flex-direction: row !important;
  align-items: center;
  gap: 0.5rem;
  margin: 0.4rem 0 0.2rem;
  font-size: 0.85rem !important;
  color: var(--text) !important;
}
.dj-toggle-row input {
  width: auto !important;
  min-height: auto !important;
}
.dj-studio-generate {
  min-height: 50px;
  margin-top: 0.45rem;
  font-weight: 800;
  font-size: 1.02rem;
  width: 100%;
}
.dj-studio-panel .req {
  color: #f0a0a0;
}

.dj-create-songs {
  margin: 0.75rem 0 0.5rem;
  padding: 0.65rem 0.7rem;
  border-radius: 12px;
  border: 1px solid rgba(110, 168, 255, 0.35);
  background: rgba(80, 120, 200, 0.1);
}

/* My songs (DJ owner — newest first, easy find after studio) */
.dj-my-songs {
  margin: 0.85rem 0 0.5rem;
  padding: 0.7rem 0.75rem 0.85rem;
  border-radius: 14px;
  border: 1px solid rgba(160, 220, 160, 0.45);
  background: linear-gradient(145deg, rgba(50, 130, 90, 0.18), rgba(40, 80, 100, 0.12));
  box-shadow: 0 0 0 1px rgba(120, 220, 160, 0.08);
}
.dj-my-songs.dj-my-songs-flash {
  animation: dj-songs-flash 1.2s ease-out 1;
}
@keyframes dj-songs-flash {
  0% { box-shadow: 0 0 0 2px rgba(160, 255, 180, 0.85); }
  100% { box-shadow: 0 0 0 1px rgba(120, 220, 160, 0.08); }
}
.dj-my-songs-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.45rem;
}
.dj-my-songs-head .dj-create-label {
  margin: 0;
  flex: 1;
  min-width: 0;
}
.dj-just-finished {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin: 0 0 0.65rem;
  padding: 0.65rem 0.7rem;
  border-radius: 12px;
  border: 1px solid rgba(180, 255, 160, 0.55);
  background: linear-gradient(135deg, rgba(80, 200, 120, 0.28), rgba(100, 160, 255, 0.18));
}
.dj-just-finished.hidden { display: none !important; }
.dj-just-finished-label {
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #b8f5c8;
}
.dj-just-finished-title {
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.25;
  color: #f2fff5;
  word-break: break-word;
}
.dj-just-finished-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.2rem;
}
.dj-just-finished-actions .btn {
  min-height: 40px;
  flex: 1 1 auto;
}
.dj-my-songs-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 18rem;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.dj-my-songs-list li {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.35rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  min-height: 48px;
  border-radius: 8px;
}
.dj-my-songs-list li:last-child { border-bottom: none; }
.dj-my-songs-list li.dj-song-new {
  background: rgba(100, 220, 140, 0.14);
  border: 1px solid rgba(140, 240, 160, 0.35);
  margin-bottom: 0.25rem;
  padding-left: 0.45rem;
  padding-right: 0.45rem;
}
.dj-my-songs-list li.dj-song-fresh {
  animation: dj-row-pulse 1.4s ease-out 1;
}
@keyframes dj-row-pulse {
  0% { background: rgba(160, 255, 180, 0.35); }
  100% { background: rgba(100, 220, 140, 0.14); }
}
.dj-my-songs-list .dj-song-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}
.dj-my-songs-list .dj-song-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.92rem;
  font-weight: 600;
}
.dj-my-songs-list .dj-song-meta {
  color: var(--muted);
  font-size: 0.7rem;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}
.dj-badge-new {
  display: inline-block;
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #0a2a14;
  background: #8ef0a8;
  border-radius: 4px;
  padding: 0.08rem 0.35rem;
  line-height: 1.2;
}
.dj-my-songs-list .dj-song-actions {
  display: flex;
  flex-shrink: 0;
  gap: 0.25rem;
}
.dj-my-songs-list .dj-song-play,
.dj-my-songs-list .dj-song-dl {
  flex-shrink: 0;
  min-height: 38px;
  padding: 0.25rem 0.5rem;
  font-size: 0.78rem;
}
#dj-my-songs-empty {
  margin: 0.25rem 0 0;
}
#dj-my-songs-empty.hidden {
  display: none;
}
.dj-create-label {
  margin: 0 0 0.45rem;
  font-size: 0.9rem;
}
.dj-pack-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.dj-pack-btn {
  flex: 1 1 auto;
  min-width: 5.5rem;
}
.dj-job-status {
  margin: 0.45rem 0 0;
  font-size: 0.8rem;
  line-height: 1.35;
  min-height: 1.2em;
}
.dj-job-progress {
  margin-top: 0.4rem;
}
.dj-job-progress.hidden { display: none; }
.dj-job-bar {
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}
.dj-job-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #7c6cf0, #9ec0ff);
  transition: width 0.35s ease;
}

.chat-form {
  flex-shrink: 0;
}

.chat-form .btn {
  padding: 0.4rem 0.65rem;
  font-size: 0.85rem;
}

.chat-bubble {
  max-width: 95%;
  padding: 0.45rem 0.6rem;
  border-radius: 10px;
  font-size: 0.8rem;
  line-height: 1.35;
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-bubble.user {
  align-self: flex-end;
  background: rgba(108, 140, 255, 0.2);
  border: 1px solid rgba(108, 140, 255, 0.35);
}

.chat-bubble.system {
  align-self: flex-start;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
}

.chat-form {
  display: flex;
  gap: 0.5rem;
}

.chat-form input {
  flex: 1;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 999px;
  padding: 0.7rem 1rem;
  font-size: 0.95rem;
}

.chat-form input:focus {
  outline: none;
  border-color: var(--accent);
}

/* Live / Library mode */
.mode-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}
.mode-toggle {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
}
.mode-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.35rem 0.9rem;
  border-radius: 999px;
  cursor: pointer;
}
.mode-btn.active {
  background: var(--accent);
  color: #fff;
}
.mode-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Collection panel — roomy; parent player-scroll handles page scroll */
.library-box {
  margin-top: 0.15rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.65rem 0.75rem;
  min-height: 180px;
  max-height: none;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  flex-shrink: 0;
}
.library-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}
.chip {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.75rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  cursor: pointer;
}
.chip.active {
  border-color: var(--accent);
  color: var(--text);
  background: rgba(108, 140, 255, 0.15);
}
.library-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 280px;
  overflow-y: auto;
  flex: 1;
  min-height: 120px;
}
.library-list li {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.15rem;
  border-bottom: 1px solid rgba(42, 49, 68, 0.5);
  font-size: 0.85rem;
}
.library-list li:last-child { border-bottom: none; }
.library-list .lib-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.library-list .lib-meta {
  color: var(--muted);
  font-size: 0.75rem;
  white-space: nowrap;
}
.library-list .lib-play,
.library-list .lib-dl {
  border: none;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0.15rem 0.3rem;
  flex-shrink: 0;
}
.library-list .lib-play:hover,
.library-list .lib-dl:hover { color: #fff; }
.library-list .lib-dl { color: var(--muted); }
.library-list .lib-liked { color: var(--accent-2); }

/* Pipeline sits under collection */
.player-scroll .gen-box {
  order: 0;
  margin-top: 0.25rem;
  flex-shrink: 0;
}
