:root {
  --bg: #05070f;
  --panel-bg: rgba(15, 20, 35, 0.92);
  --panel-border: rgba(120, 160, 255, 0.18);
  --text: #e8edf7;
  --text-dim: #93a0bd;
  --accent: #4ea1ff;
  --fm: #36d399;
  --am: #ffb547;
  --net: #8b93a7;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.55);
  --radius: 14px;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: radial-gradient(circle at 50% 30%, #0a1226 0%, var(--bg) 70%);
  color: var(--text);
  overflow: hidden;
  /* App (nao documento): impede selecao acidental de texto ao arrastar o globo. */
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  /* Evita o "flash" azul de toque em mobile ao tocar nos controles. */
  -webkit-tap-highlight-color: transparent;
}

/* Reabilita selecao onde faz sentido: campos de texto e o painel de detalhes
   (para o usuario copiar nome/frequencia/link da estacao). */
input,
textarea,
#panel,
#listPanel {
  -webkit-user-select: text;
  -moz-user-select: text;
  -ms-user-select: text;
  user-select: text;
}

#globeViz {
  position: fixed;
  inset: 0;
  z-index: 0;
  /* O canvas WebGL nunca deve permitir selecao/realce de texto. */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

a { color: var(--accent); }

/* ---------- Topbar ---------- */
#topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 18px;
  background: linear-gradient(180deg, rgba(5, 7, 15, 0.88) 0%, rgba(5, 7, 15, 0) 100%);
  pointer-events: none;
}
#topbar > * { pointer-events: auto; }

.brand { display: flex; align-items: center; gap: 10px; }
.brand .logo { font-size: 26px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 17px; letter-spacing: .3px; }
.brand-text small { color: var(--text-dim); font-size: 11px; }

.filters {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.band-toggle {
  display: inline-flex;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  overflow: hidden;
  backdrop-filter: blur(8px);
}
.band-btn {
  border: 0;
  background: transparent;
  color: var(--text-dim);
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.band-btn:hover { color: var(--text); }
.band-btn.is-active { background: var(--accent); color: #04111f; }

#countrySelect, #sortSelect, #langSelect, .search-box input {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  color: var(--text);
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 13px;
  backdrop-filter: blur(8px);
  outline: none;
  max-width: 220px;
}
#countrySelect:focus, #sortSelect:focus, #langSelect:focus, .search-box input:focus {
  border-color: var(--accent);
}
#langSelect { max-width: 140px; }
.search-box input::placeholder { color: var(--text-dim); }

.icon-btn {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  color: var(--text);
  width: 38px; height: 38px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  backdrop-filter: blur(8px);
}
.icon-btn:hover { border-color: var(--accent); }
.icon-btn.is-active { background: rgba(78, 161, 255, 0.22); border-color: var(--accent); color: #cfe2ff; }

/* ---------- Acessibilidade: foco visivel por teclado ---------- */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}
.band-btn:focus-visible, .icon-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Lista de estacoes (acessivel/teclado/toque) ---------- */
.list-panel {
  position: fixed;
  top: 76px; left: 18px; bottom: 56px;
  width: 320px;
  max-width: calc(100vw - 36px);
  z-index: 14;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  display: flex;
  flex-direction: column;
  padding: 16px 12px 12px;
}
.list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 4px 6px;
}
.list-head h2 { margin: 0; font-size: 16px; }
.list-head .panel-close { position: static; }
.list-hint {
  margin: 0 4px 8px;
  font-size: 11px;
  color: var(--text-dim);
}
.list-items {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
  outline: none;
}
.list-items:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 8px;
}
.list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 10px;
  cursor: pointer;
  border: 1px solid transparent;
}
.list-item:hover { background: rgba(255, 255, 255, 0.05); }
.list-item.is-cursor {
  background: rgba(78, 161, 255, 0.14);
  border-color: rgba(78, 161, 255, 0.4);
}
.list-item.is-selected { background: rgba(78, 161, 255, 0.22); }
.li-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.li-body { display: flex; flex-direction: column; min-width: 0; }
.li-name {
  font-size: 13px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.li-meta {
  font-size: 11px; color: var(--text-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.list-empty, .list-more {
  padding: 12px 10px;
  font-size: 12px;
  color: var(--text-dim);
  text-align: center;
}
.list-more { font-style: italic; }

/* ---------- Stats ---------- */
.stats {
  position: fixed;
  left: 18px; bottom: 56px;
  z-index: 9;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 12px;
  color: var(--text-dim);
  backdrop-filter: blur(8px);
}
.stats #statCount { color: var(--text); font-weight: 700; }
.mode-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 9px;
  border-radius: 999px;
  background: rgba(78, 161, 255, 0.16);
  border: 1px solid rgba(78, 161, 255, 0.3);
  color: #bcd6ff;
  font-size: 11px;
  font-weight: 600;
}

/* ---------- Loading ---------- */
.loading {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  padding: 26px 34px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 14px;
}
.spinner {
  width: 34px; height: 34px;
  border: 3px solid rgba(255, 255, 255, 0.12);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Panel ---------- */
.panel {
  position: fixed;
  top: 76px; right: 18px; bottom: 56px;
  width: 340px;
  max-width: calc(100vw - 36px);
  z-index: 15;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  padding: 20px;
  overflow-y: auto;
  transition: transform .25s ease, opacity .25s ease;
}
.panel-close {
  position: absolute;
  top: 12px; right: 12px;
  width: 30px; height: 30px;
  border: 0;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border-radius: 8px;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.panel-close:hover { background: rgba(255, 255, 255, 0.14); }

.panel-head { display: flex; gap: 12px; align-items: center; margin: 4px 0 18px; padding-right: 28px; }
.p-favicon {
  width: 52px; height: 52px;
  border-radius: 10px;
  object-fit: cover;
  background: rgba(255, 255, 255, 0.06);
  flex-shrink: 0;
}
.p-favicon[src=""], .p-favicon:not([src]) { visibility: hidden; }
#pName { margin: 0; font-size: 18px; line-height: 1.25; }
.p-location { margin: 4px 0 0; color: var(--text-dim); font-size: 13px; }

.player {
  display: flex;
  align-items: center;
  gap: 14px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 16px;
}
.play-btn {
  width: 48px; height: 48px;
  border-radius: 50%;
  border: 0;
  background: var(--accent);
  color: #04111f;
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform .1s;
}
.play-btn:hover { transform: scale(1.06); }
.play-btn.is-playing { background: var(--fm); }
.play-btn.is-loading { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .5; } }
.player-meta { flex: 1; min-width: 0; }
#pNowPlaying {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-bottom: 8px;
}
.volume { display: flex; align-items: center; gap: 8px; }
.volume input { flex: 1; accent-color: var(--accent); }

.p-info {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 14px;
  margin: 0 0 16px;
}
.p-info > div { display: flex; flex-direction: column; }
.p-info dt { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .5px; }
.p-info dd { margin: 2px 0 0; font-size: 14px; font-weight: 600; }
.verified-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  color: #04111f;
  background: var(--fm);
  padding: 1px 6px;
  border-radius: 999px;
  vertical-align: middle;
}

.p-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.tag {
  background: rgba(78, 161, 255, 0.14);
  border: 1px solid rgba(78, 161, 255, 0.28);
  color: #bcd6ff;
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 999px;
}
.p-homepage {
  display: inline-block;
  font-size: 13px;
  text-decoration: none;
}
.p-homepage:hover { text-decoration: underline; }

/* ---------- Legend ---------- */
.legend {
  position: fixed;
  right: 18px; bottom: 56px;
  z-index: 9;
  display: flex;
  gap: 14px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 12px;
  color: var(--text-dim);
  backdrop-filter: blur(8px);
}
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot-fm { background: var(--fm); }
.dot-am { background: var(--am); }
.dot-net { background: var(--net); }

/* ---------- Footer ---------- */
#credits {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 8;
  text-align: center;
  font-size: 11px;
  color: var(--text-dim);
  padding: 8px;
  pointer-events: none;
}
#credits a { pointer-events: auto; }

.hidden { display: none !important; }

/* ---------- File:// banner ---------- */
.file-banner {
  position: fixed;
  left: 50%;
  bottom: 92px;
  transform: translateX(-50%);
  z-index: 30;
  max-width: 560px;
  width: calc(100vw - 36px);
  background: rgba(40, 28, 12, 0.96);
  border: 1px solid rgba(255, 181, 71, 0.45);
  color: #ffe6bf;
  padding: 14px 40px 14px 16px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.5;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}
.file-banner strong { color: var(--am); }
.file-banner code {
  background: rgba(255, 255, 255, 0.1);
  padding: 1px 6px;
  border-radius: 5px;
  font-size: 12px;
}
.file-banner button {
  position: absolute;
  top: 8px; right: 8px;
  width: 26px; height: 26px;
  border: 0;
  background: rgba(255, 255, 255, 0.08);
  color: #ffe6bf;
  border-radius: 6px;
  font-size: 16px;
  cursor: pointer;
}
.file-banner button:hover { background: rgba(255, 255, 255, 0.18); }

/* ---------- Mobile ---------- */
@media (max-width: 720px) {
  #topbar { flex-direction: column; align-items: stretch; gap: 10px; }
  .filters { justify-content: stretch; flex-wrap: wrap; }
  #countrySelect, #sortSelect, .search-box { flex: 1 1 45%; }
  #langSelect { flex: 1 1 45%; max-width: none; }
  .search-box input { max-width: none; width: 100%; }
  /* alvos de toque maiores */
  .band-btn { padding: 10px 18px; }
  .icon-btn { width: 44px; height: 44px; }
  .panel {
    top: auto; left: 0; right: 0; bottom: 0;
    width: 100%;
    max-height: 62vh;
    border-radius: var(--radius) var(--radius) 0 0;
  }
  /* lista vira bottom-sheet, com itens de toque confortaveis */
  .list-panel {
    top: auto; left: 0; right: 0; bottom: 0;
    width: 100%;
    max-height: 70vh;
    border-radius: var(--radius) var(--radius) 0 0;
  }
  .list-item { padding: 12px 12px; }
  .li-name { font-size: 14px; }
  .legend { display: none; }
  .stats { bottom: 16px; }
}

/* Favoritos + acoes do painel */
.p-actions { display: flex; gap: 8px; margin: -4px 0 12px; }
.icon-btn.is-fav { color: #ffd24a; border-color: rgba(255,210,74,0.55); }

/* Barra de chips de genero + Surpreenda-me/Recentes */
.genre-chips {
  position: fixed; top: 64px; left: 50%; transform: translateX(-50%);
  z-index: 9; display: flex; gap: 6px; max-width: min(92vw, 760px);
  overflow-x: auto; padding: 4px; pointer-events: auto; scrollbar-width: none;
}
.genre-chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; cursor: pointer; white-space: nowrap;
  background: var(--panel-bg); color: var(--text-dim);
  border: 1px solid var(--panel-border); border-radius: 999px;
  padding: 5px 12px; font-size: 12px; backdrop-filter: blur(8px);
}
.chip:hover { border-color: var(--accent); }
.chip.is-active { background: rgba(78,161,255,0.22); border-color: var(--accent); color: #cfe2ff; }
@media (max-width: 720px) { .genre-chips { display: none; } }
