:root {
  --bg: #0d0f14;
  --surface: #151824;
  --surface-2: #1c2030;
  --border: #262b3d;
  --text: #eef0f4;
  --text-dim: #9aa0b2;
  --accent: #e3a83b;      /* radio-dial amber glow */
  --accent-soft: #4a3a1c;
  --accent-text: #1a1305;
  --danger: #d9756b;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  min-height: 100%;
}

body {
  padding-bottom: 130px; /* room for the player bar, now that its text can wrap to more than one line */
  padding-top: calc(56px + env(safe-area-inset-top)); /* room for the fixed top bar below */
  position: relative;
  /* Without an explicit z-index, `position: relative` alone does NOT make
     body establish its own stacking context — so body's own background and
     its z-indexed fixed children (.bg-art, .dial-glow) end up competing for
     paint order in the *parent* context instead, which is exactly the kind
     of edge case that renders inconsistently. Giving body a real z-index
     forces it to own its context, which guarantees — unconditionally, by
     spec — that body's own background paints below ANY z-indexed child,
     which is what actually makes .bg-art visible. */
  z-index: 0;
  overflow-x: hidden;
}

/* Signature element: an ambient amber glow, like a lit dial behind glass */
.dial-glow {
  position: fixed;
  top: -220px;
  left: 50%;
  transform: translateX(-50%);
  width: 720px;
  height: 420px;
  background: radial-gradient(ellipse at center, rgba(227, 168, 59, 0.16) 0%, rgba(227, 168, 59, 0.05) 45%, transparent 72%);
  pointer-events: none;
  z-index: 0;
}

/* Full-viewport backdrop built from the current track's album art, heavily
   blurred and darkened so it reads as ambient color rather than a picture.
   Placed first in the DOM at z-index: 0, same layer as .dial-glow below it,
   sitting beneath the rest of the UI (header/main/etc. are all explicitly
   z-index: 1+) — this only paints below body's own background because body
   now establishes its own stacking context (see the z-index on body above).

   The overshoot needed to push the blur's soft edges past what's visible
   (otherwise you get a faint vignette) is applied via `transform: scale()`
   AFTER `background-size: cover` sizes against the real viewport (`inset:
   0`) — not by inflating the box cover fills, which would crop the image
   tighter than a plain viewport-cover already does, i.e. more "zoomed in"
   than intended. scale(1.2) reproduces the exact same 10%-per-edge overshoot
   margin as that approach did, just without feeding into the cover crop.

   Only toggling opacity (never swapping display) is what makes the
   crossfade between tracks/stations smooth. */
.bg-art {
  position: fixed;
  inset: 0;
  background-size: cover;
  background-position: center;
  transform: scale(1.2);
  filter: blur(70px) saturate(1.4) brightness(0.4);
  opacity: 0;
  transition: opacity 0.7s ease;
  z-index: 0;
  pointer-events: none;
}
.bg-art.is-active { opacity: 1; }

.site-header {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 3rem 1.5rem 1.25rem;
}

.header-icon {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.45), 0 0 0 1px var(--border);
  margin-bottom: 0.75rem;
}

.wordmark-row {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.5rem;
}

.wordmark {
  font-family: 'DM Serif Display', serif;
  font-weight: 400;
  font-size: clamp(2rem, 6vw, 2.75rem);
  margin: 0;
  letter-spacing: 0.01em;
}

.tagline {
  color: var(--text-dim);
  margin: 0.4rem 0 0;
  font-size: 0.95rem;
}

/* Fixed top bar — pinned regardless of scroll, same treatment as the
   player bar at the bottom. Two slots (left/right), each holding whichever
   of its two buttons is relevant to the current view; activateTab() in
   app.js toggles which one shows via `hidden`, so exactly one per slot is
   ever visible at a time. */
.top-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: calc(0.6rem + env(safe-area-inset-top)) 1rem 0.6rem;
  background: rgba(21, 24, 36, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.top-bar-side { display: flex; align-items: center; gap: 0.5rem; }

.top-bar-btn {
  width: 44px;
  height: 44px;
}

.top-bar-btn[hidden] { display: none; }

.menu-wrap { position: relative; }

.menu-panel[hidden] { display: none; }

.menu-panel {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 20;
  min-width: 200px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.4rem;
  box-shadow: 0 12px 32px rgba(0,0,0,0.5);
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  font-family: inherit;
  font-size: 0.9rem;
  color: var(--text);
  background: transparent;
  border: none;
  border-radius: 8px;
  padding: 0.55rem 0.6rem;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s ease, color 0.15s ease;
}
.menu-item:hover { background: var(--surface); color: var(--accent); }
.menu-item svg { flex-shrink: 0; color: var(--text-dim); }

.section-heading {
  font-family: 'DM Serif Display', serif;
  font-weight: 400;
  font-size: 1.3rem;
  margin: 0;
}

.tab-count {
  color: inherit;
  opacity: 0.75;
  font-size: 0.7em;
}

main {
  position: relative;
  z-index: 1;
  max-width: 640px;
  margin: 0 auto;
  padding: 0 1.25rem;
}

.panel { display: none; }
.panel.is-active { display: block; }

.search-bar {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 1rem;
}

input[type="search"],
input[type="text"],
input[type="url"],
select {
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.65rem 0.85rem;
  width: 100%;
}

input:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.search-bar input[type="search"] { flex: 1; }

/* Custom country dropdown (flag + name; native <select> can't show images) */
.country-select {
  position: relative;
  flex: 0 0 auto;
  width: 44%;
  max-width: 220px;
}

.country-select-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.65rem 0.7rem;
  cursor: pointer;
}

.country-select-btn span { flex: 1; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.country-select-btn .chevron { color: var(--text-dim); flex-shrink: 0; }

.country-select-flag {
  width: 18px;
  height: 13px;
  object-fit: cover;
  border-radius: 2px;
  flex-shrink: 0;
}

.country-select-panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 20;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem;
  box-shadow: 0 12px 32px rgba(0,0,0,0.5);
}

.country-select-panel input[type="search"] {
  margin-bottom: 0.4rem;
}

.country-select-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 260px;
  overflow-y: auto;
}

.country-select-list li {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.45rem 0.5rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.88rem;
}

.country-select-list li:hover,
.country-select-list li.is-active { background: var(--surface); color: var(--accent); }

.country-select-list img {
  width: 18px;
  height: 13px;
  object-fit: cover;
  border-radius: 2px;
  flex-shrink: 0;
}

.country-select-list .no-flag {
  width: 18px;
  height: 13px;
  flex-shrink: 0;
}

.status-line, .hint {
  color: var(--text-dim);
  font-size: 0.88rem;
  text-align: center;
  padding: 1rem 0;
}

.search-count-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding-bottom: 0.6rem;
}

.search-count {
  color: var(--text-dim);
  font-size: 0.78rem;
}

.btn-compact {
  font-size: 0.78rem;
  padding: 0.35rem 0.75rem;
  flex-shrink: 0;
}
.btn-compact[hidden] { display: none; }

.search-pager {
  display: flex;
  justify-content: center;
  gap: 0.75rem;
  padding: 1rem 0;
}

.station-list {
  list-style: none;
  margin: 0 0 1.5rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.station-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.65rem 0.75rem;
  transition: border-color 0.15s ease, background 0.15s ease;
  cursor: pointer;
}

.station-row.is-selected {
  border-color: var(--accent);
  background: rgba(227, 168, 59, 0.08);
}

.station-row.is-selected .station-name { color: var(--accent); }

.station-art {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: var(--surface-2);
  flex-shrink: 0;
  object-fit: cover;
}

.station-meta { flex: 1; min-width: 0; }

.station-name {
  font-weight: 500;
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.station-desc {
  font-size: 0.78rem;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.station-desc .station-flag {
  width: 16px;
  height: 12px;
  object-fit: cover;
  border-radius: 2px;
  flex-shrink: 0;
}

.station-desc .station-desc-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.station-actions {
  display: flex;
  gap: 0.4rem;
  flex-shrink: 0;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.icon-btn:hover { border-color: var(--accent); }
.icon-btn.is-playing { color: var(--accent); border-color: var(--accent); }
.icon-btn.danger:hover { border-color: var(--danger); color: var(--danger); }
a.icon-btn { text-decoration: none; }

.mine-toolbar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 1rem 0;
  flex-wrap: wrap;
}

.toolbar-spacer { flex: 1; }

.tag-filter {
  width: auto;
  max-width: 160px;
  font-size: 0.85rem;
  padding: 0.5rem 0.7rem;
}

.btn {
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 500;
  border-radius: 999px;
  padding: 0.55rem 1.1rem;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.1s ease;
}

.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.btn-ghost:hover:not(:disabled) { border-color: var(--accent); }

.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}

.btn-primary:hover { filter: brightness(1.08); }

/* Player bar */
.player-bar[hidden] { display: none; }

.player-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.75rem 1.25rem;
  background: rgba(21, 24, 36, 0.92);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
}
.player-toggle {
  width: 42px;
  height: 42px;
  border-radius: 999px;
  border: none;
  background: var(--accent);
  color: var(--accent-text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

/* The station's own logo — same treatment as .station-art in the lists,
   so it reads as the same kind of element. */
.player-station-logo {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--surface-2);
  flex-shrink: 0;
}

.player-info { min-width: 0; flex: 1; }

/* Simple in-flow flex child now — no longer fixed/centered-overlay
   positioned. That whole approach existed only because it needed to sit
   centered over the bar without colliding with the name/status text; now
   that it just lives at the end of the bar (name text has the rest of the
   row to itself), plain flex layout is all it needs. */
.player-art-btn {
  flex-shrink: 0;
  width: 46px;
  height: 46px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface-2);
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease;
}
.player-art-btn:hover { border-color: var(--accent); transform: scale(1.06); }
.player-art-btn[hidden] { display: none; }

.player-art { width: 100%; height: 100%; object-fit: cover; display: block; }

.player-title-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.2rem 0.55rem;
  min-width: 0;
}

/* No more truncation — full width to wrap into, and no fixed 60% cap that
   was cutting names short even when the row had room to spare. */
.player-name {
  font-weight: 500;
  font-size: 0.92rem;
  white-space: normal;
  overflow-wrap: break-word;
  flex: 1 1 auto;
  min-width: 0;
}

.player-desc {
  font-family: 'DM Serif Display', serif;
  font-style: italic;
  font-size: 0.82rem;
  color: var(--accent);
  opacity: 0.85;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 1;
  min-width: 0;
  max-width: 100%;
}

.player-status {
  font-size: 0.76rem;
  color: var(--text-dim);
  white-space: normal;
  overflow-wrap: break-word;
}

.app-version {
  font-size: 0.68rem;
  color: var(--text-dim);
  opacity: 0.55;
  flex-shrink: 0;
  white-space: nowrap;
}

/* Video */
.video-badge {
  display: inline-flex;
  vertical-align: middle;
  margin-left: 0.4rem;
  color: var(--accent);
}

/* dialog.video-modal (not just .video-modal) — needs to outrank the later
   .modal { width: min(440px, 92vw); } rule regardless of source order. Both
   were plain single-class selectors with equal specificity, so the one that
   happened to come later in the file (.modal) was silently winning the
   cascade and clamping every video to ~440px, no matter the viewport. */
dialog.video-modal { width: min(640px, 94vw, calc(70vh * 16 / 9)); }

/* Video benefits from real screen space in a way the other modals don't —
   scale it up substantially on anything wider than a phone. The 16:9
   aspect-ratio on .video-modal-body means the video itself grows right
   along with the modal's width. The third min() term caps width by
   viewport *height* too, so a wide-but-short window (a laptop, say) can't
   produce a video taller than the screen. */
@media (min-width: 768px) {
  dialog.video-modal { width: min(1200px, 88vw, calc(75vh * 16 / 9)); }
}
@media (min-width: 1400px) {
  dialog.video-modal { width: min(1400px, 80vw, calc(75vh * 16 / 9)); }
}

.video-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.video-modal-header h2 {
  font-size: 1.15rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.video-modal-body {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 8px;
  overflow: hidden;
}

.video-modal-body video,
.video-modal-body iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}

/* Modals */
.modal {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  padding: 0;
  width: min(440px, 92vw);
}

.modal::backdrop { background: rgba(5, 6, 10, 0.72); }

/* Same "own class wins the cascade regardless of source order" issue noted
   above for dialog.video-modal — sized to the image itself (via its own
   width/aspect-ratio) rather than the generic .modal's fixed 440px cap. */
dialog.artwork-modal { width: min(480px, 92vw); }

.artwork-modal-img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 8px;
  background: var(--surface-2);
  display: block;
}

.modal-form {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.modal-form h2 {
  font-family: 'DM Serif Display', serif;
  font-weight: 400;
  margin: 0 0 0.25rem;
  font-size: 1.4rem;
}

.modal-form label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.82rem;
  color: var(--text-dim);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  margin-top: 0.5rem;
}

.modal-actions-stack {
  flex-direction: column;
  align-items: stretch;
}

.station-list-compact .station-row { padding: 0.5rem 0.6rem; }

.conflict-row {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 0.75rem;
  margin-bottom: 0.5rem;
}

.conflict-row .station-desc { margin-bottom: 0.4rem; }

.conflict-choice {
  display: flex;
  gap: 1rem;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.conflict-choice label { flex-direction: row; align-items: center; gap: 0.35rem; color: inherit; }

.toast {
  position: fixed;
  bottom: 96px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.6rem 1.1rem;
  border-radius: 999px;
  font-size: 0.85rem;
  z-index: 10;
}

@media (max-width: 480px) {
  .search-bar { flex-direction: column; }
  .search-bar select { max-width: 100%; }

  /* Reclaim horizontal space for station names — on a narrow phone, fixed-
     width elements (artwork, 3-4 action buttons) were eating most of the
     row, leaving very little room for text before it truncated. */
  main { padding: 0 0.75rem; }

  .station-row {
    padding: 0.55rem 0.6rem;
    gap: 0.5rem;
  }

  .station-art {
    width: 32px;
    height: 32px;
  }

  .station-actions { gap: 0.3rem; }

  .icon-btn {
    width: 30px;
    height: 30px;
  }

  .top-bar-btn {
    width: 40px;
    height: 40px;
  }

  /* The description line stays single-line/ellipsis (it's secondary info),
     but the name itself now wraps instead of truncating — this is the main
     fix, since a cut-off station name is the thing actually worth avoiding. */
  .station-name {
    white-space: normal;
    overflow-wrap: break-word;
  }

  /* Same reasoning as the station-art shrink above — on a narrow phone the
     toggle button, art thumbnail, and app-version text are all fixed-width
     and would otherwise crowd out the station name/status text between them. */
  .player-station-logo { width: 32px; height: 32px; }

  /* Now a plain in-flow flex item (see the base rule) — the old fixed/
     pinned-corner treatment only existed to dodge the name text when this
     button was centered over the bar. Just needs the same modest shrink as
     the other bar icons on a narrow phone. */
  .player-art-btn { width: 38px; height: 38px; }
}
