* { box-sizing: border-box; }

/* The `hidden` attribute must always win over display rules below
   (this is what caused the "session not found" overlay to always show). */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: #101418;
  color: #e8ecf1;
  display: flex;
  flex-direction: column;
}

#follow-btn {
  position: fixed;
  bottom: 24px;
  right: 16px;
  z-index: 1200;
  background: #1976d2;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 10px 16px;
  font-size: 14px;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}
#follow-btn:hover { background: #1565c0; }

/* --- player bar: floating pill overlaying the map --- */
#playerbar {
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  z-index: 1100;
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(19, 25, 32, 0.92);
  backdrop-filter: blur(10px);
  border: 1px solid #2c3745;
  border-radius: 999px;
  padding: 8px 18px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.55);
  max-width: min(760px, calc(100vw - 24px));
}
#playerbar.loading #station-meta { animation: meta-pulse 1.2s ease-in-out infinite; }
@keyframes meta-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
#station-favicon { width: 40px; height: 40px; border-radius: 50%; object-fit: contain; background: #fff; flex-shrink: 0; }
.station-info { min-width: 0; }
#station-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 280px; }
#track-line { display: flex; align-items: center; gap: 8px; min-height: 18px; }
#track-text { font-size: 13px; color: #6ecbff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 240px; }
#heart-btn {
  background: none;
  border: none;
  color: #66788c; /* monotone/outlined when not hearted */
  font-size: 17px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  transition: transform 0.15s ease, color 0.15s ease;
}
#heart-btn:hover { transform: scale(1.2); }
#heart-btn.on { color: #ff2d55; transform: scale(1.4); } /* red + larger when hearted */
#heart-btn.pop { animation: heart-pop 0.5s ease; }
@keyframes heart-pop {
  0% { transform: scale(1); } 40% { transform: scale(1.8); } 100% { transform: scale(1.4); }
}
#station-meta { font-size: 12px; color: #8b98a8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 280px; }
.player-controls { display: flex; align-items: center; gap: 10px; margin-left: auto; flex-shrink: 0; }
#volume { width: 90px; accent-color: #1976d2; }
#stop-btn {
  background: #4a2530;
  color: #ff9db0;
  border: 1px solid #6b3542;
  border-radius: 4px;
  padding: 6px 14px;
  cursor: pointer;
}
#stop-btn:hover { background: #5a2c3a; }
#autoplay-hint {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1400;
  background: #4a3b1e;
  color: #ffd98a;
  font-size: 20px;
  font-weight: 600;
  padding: 20px 42px;
  border: 1px solid #8a6d2e;
  border-radius: 12px;
  cursor: pointer;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.7);
}
#autoplay-hint:hover { background: #5a4825; }

/* --- map --- */
#map { flex: 1; min-height: 0; background: #101418; }

/* station marker: orange dot by default; a loaded favicon replaces it,
   keeping its aspect ratio within a max 22px box */
.st-wrap { background: transparent; border: none; }
.st {
  position: relative;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #ff7043;
  border: 2px solid #fff;
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
}
.st img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 4px;
  background: #fff;
}
.st.has-favicon { background: transparent; border-color: transparent; box-shadow: none; }
/* out of range: greyed out, still clickable for its info */
.st.dim { filter: grayscale(1); opacity: 0.45; }
/* currently playing: pulsing ring */
.st.playing::after {
  content: '';
  position: absolute;
  inset: -7px;
  border-radius: 50%;
  border: 2px solid #ffab91;
  animation: st-pulse 1.6s ease-out infinite;
  pointer-events: none;
}
@keyframes st-pulse {
  0%   { transform: scale(0.65); opacity: 1; }
  100% { transform: scale(1.5);  opacity: 0; }
}

.plane-rot { display: flex; align-items: center; justify-content: center; transition: transform 0.4s linear; }

/* cluster icons themed to match the dark map */
.marker-cluster-small,
.marker-cluster-medium,
.marker-cluster-large { background-clip: padding-box; }
.marker-cluster-small { background-color: rgba(255, 112, 67, 0.25); }
.marker-cluster-small div { background-color: rgba(255, 112, 67, 0.85); }
.marker-cluster-medium { background-color: rgba(255, 152, 0, 0.25); }
.marker-cluster-medium div { background-color: rgba(255, 152, 0, 0.85); }
.marker-cluster-large { background-color: rgba(244, 67, 54, 0.25); }
.marker-cluster-large div { background-color: rgba(244, 67, 54, 0.85); }
.marker-cluster span { color: #fff; font-weight: 600; }
/* groupings outside the playable circle are greyed out like the markers */
.marker-cluster.cluster-dim { filter: grayscale(1); opacity: 0.45; }
/* a grouping containing the playing station pulses */
.marker-cluster.cluster-playing::after {
  content: '';
  position: absolute;
  inset: -7px;
  border-radius: 50%;
  border: 2px solid #ffab91;
  animation: st-pulse 1.6s ease-out infinite;
  pointer-events: none;
}

/* --- station popup --- */
.station-popup { text-align: center; min-width: 180px; }
.station-popup .logo { max-width: 100%; max-height: 80px; border-radius: 8px; object-fit: contain; background: #fff; margin-bottom: 6px; }
.station-popup h3 { margin: 0 0 4px; font-size: 15px; }
.station-popup .meta { font-size: 12px; color: #555; margin: 0 0 6px; }
.station-popup .chips { display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; margin-bottom: 8px; }
.chip {
  background: #e8eef5;
  color: #33465e;
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 11px;
  border: none;
}
button.chip.more { background: #d3dce6; cursor: pointer; }
button.chip.more:hover { background: #c2cedb; }
.station-popup .dist { font-size: 11px; color: #999; margin: 8px 0 0; }
.station-popup button.play {
  background: #1976d2;
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 6px 16px;
  font-size: 13px;
  cursor: pointer;
}
.station-popup button.play:hover { background: #1565c0; }
.station-popup button.play:disabled { background: #9e9e9e; cursor: not-allowed; }
.station-popup .now-playing { font-size: 12px; color: #2e7d32; font-weight: 600; }

/* --- side panels (cluster list + tag picker) --- */
#cluster-panel, #tag-panel {
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  width: 340px;
  max-width: 90vw;
  background: #131920;
  border-left: 1px solid #262f3a;
  z-index: 1300;
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 16px rgba(0, 0, 0, 0.5);
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid #262f3a;
  font-weight: 600;
}
.panel-head button {
  background: none;
  border: none;
  color: #8b98a8;
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
}
.panel-head button:hover { color: #e8ecf1; }
.panel-sub { font-size: 12px; color: #8b98a8; padding: 8px 14px 0; margin: 0; }

#cluster-list { overflow-y: auto; flex: 1; padding: 8px; }
.station-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
}
.station-card:hover { background: #1a222c; }
.station-card.playing { outline: 1px solid #ff7043; background: #1a222c; }
.station-card.dim { opacity: 0.5; }
.station-card img, .station-card .card-dot {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  background: #fff;
  object-fit: cover;
}
.station-card .card-dot { background: #ff7043; border: 2px solid #fff; }
.station-card .card-info { min-width: 0; flex: 1; }
.station-card .card-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.station-card .card-meta { font-size: 11px; color: #8b98a8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.station-card .card-tags { font-size: 11px; color: #66788c; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.station-card button.card-play {
  background: #1976d2;
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 5px 12px;
  font-size: 12px;
  cursor: pointer;
  flex-shrink: 0;
}
.station-card button.card-play:hover { background: #1565c0; }
.station-card button.card-play:disabled { background: #37414d; color: #66788c; cursor: not-allowed; }
.station-card button.card-play.connecting { animation: meta-pulse 1.2s ease-in-out infinite; color: #cfe3ff; background: #2d3e54; }

/* --- tag picker panel --- */
#tag-list { list-style: none; margin: 0; padding: 8px 14px; overflow-y: auto; flex: 1; }
#tag-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid #1c242e;
}
#tag-list li .rank { color: #66788c; font-size: 12px; width: 18px; }
#tag-list li .tag-name { flex: 1; }
#tag-list li button {
  background: #243141;
  color: #cfe3ff;
  border: 1px solid #33465e;
  border-radius: 4px;
  padding: 2px 8px;
  cursor: pointer;
  font-size: 12px;
}
#tag-list li button:hover { background: #2d3e54; }
.tag-add { display: flex; gap: 8px; padding: 12px 14px; border-top: 1px solid #262f3a; }
.tag-add input {
  flex: 1;
  background: #0b0e12;
  border: 1px solid #33465e;
  border-radius: 6px;
  color: #e8ecf1;
  padding: 8px 10px;
}
.tag-add button {
  background: #1976d2;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 8px 14px;
  cursor: pointer;
}
.tag-add button:disabled { background: #37414d; color: #66788c; cursor: not-allowed; }

/* --- overlay --- */
#overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 16, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}
.overlay-card {
  background: #171d24;
  border: 1px solid #2c3745;
  border-radius: 10px;
  padding: 28px 34px;
  text-align: center;
  max-width: 420px;
}
.overlay-card a { color: #6ecbff; }

/* --- mobile --- */
@media (max-width: 640px) {
  #playerbar {
    left: 8px;
    right: 8px;
    bottom: 8px;
    transform: none;
    border-radius: 22px;
    flex-wrap: wrap;
    padding: 10px 14px;
    gap: 8px;
  }
  .station-info { flex: 1 1 100%; order: -1; }
  #station-name, #station-meta, #track-text { max-width: none; }
  #volume { width: 70px; }
  #follow-btn { bottom: auto; top: 12px; right: 12px; }
  #cluster-panel, #tag-panel { width: 100vw; }
}

/* --- right-click context menu (auto-tune, tags, selection radius) --- */
#context-menu {
  position: fixed;
  z-index: 1600;
  min-width: 220px;
  background: #131920;
  border: 1px solid #2c3745;
  border-radius: 8px;
  padding: 6px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 13px;
}
.ctx-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 5px;
  cursor: pointer;
  color: #e8ecf1;
  background: none;
  border: none;
  text-align: left;
  font: inherit;
  width: 100%;
}
.ctx-row:hover { background: #1f2a36; }
.ctx-row input[type="checkbox"] { accent-color: #1976d2; }
.ctx-row.ctx-radius { gap: 6px; }
.ctx-row.ctx-radius > span:first-child { flex: 1; }
.ctx-row.ctx-radius .ctx-unit { color: #8b98a8; }
#ctx-radius {
  width: 80px;
  background: #0b0e12;
  border: 1px solid #33465e;
  border-radius: 4px;
  color: #e8ecf1;
  padding: 4px 6px;
  font: inherit;
}
#ctx-radius:focus { outline: 1px solid #1976d2; border-color: #1976d2; }

/* --- landing page --- */
body.landing { align-items: center; justify-content: center; }
.landing-card {
  background: #171d24;
  border: 1px solid #2c3745;
  border-radius: 12px;
  padding: 36px 40px;
  max-width: 420px;
}


/* --- hearted tracks on the landing page --- */
.hearts-card { margin-top: 20px; text-align: left; max-height: 45vh; display: flex; flex-direction: column; }
.hearts-card h2 { margin: 0 0 10px; font-size: 17px; text-align: center; }
#hearts-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
#hearts-list li { padding: 8px 0; border-bottom: 1px solid #1c242e; display: flex; align-items: flex-start; gap: 8px; }
#hearts-list li .heart-body { flex: 1; min-width: 0; }
.heart-remove {
  background: none;
  border: none;
  color: #66788c;
  font-size: 16px;
  cursor: pointer;
  padding: 0 2px;
  line-height: 1.2;
}
.heart-remove:hover { color: #ff9db0; }
#hearts-list .heart-track { font-weight: 600; font-size: 14px; }
#hearts-list .heart-details { font-size: 12px; color: #8b98a8; margin-top: 2px; }
#hearts-list .heart-details a { color: #6ecbff; text-decoration: none; }
#hearts-list .heart-details a:hover { text-decoration: underline; }
#hearts-clear {
  margin-top: 10px;
  background: none;
  border: 1px solid #33465e;
  color: #8b98a8;
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
  align-self: center;
}
#hearts-clear:hover { color: #e8ecf1; }
