/* ===== CSS Variables & Reset ===== */
:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-tertiary: #1a1a2e;
  --bg-card: #16162a;
  --bg-card-hover: #1e1e3a;
  --bg-player: #0d0d18;
  --text-primary: #e8e8f0;
  --text-secondary: #9898b0;
  --text-muted: #5a5a78;
  --accent: #6c5ce7;
  --accent-light: #a29bfe;
  --accent-glow: rgba(108, 92, 231, 0.3);
  --danger: #ff6b6b;
  --success: #51cf66;
  --border: rgba(255, 255, 255, 0.06);
  --border-light: rgba(255, 255, 255, 0.1);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.5);
  --transition: 0.2s ease;
  --sidebar-width: 240px;
  --player-height: 80px;
  --topbar-height: 64px;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
  height: 100vh;
  width: 100vw;
}

a {
  color: var(--accent-light);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  font-family: inherit;
  color: inherit;
}

input[type="text"] {
  font-family: inherit;
  font-size: inherit;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--text-muted);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

/* ===== Layout ===== */
#app {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-rows: 1fr auto;
  height: 100vh;
  width: 100vw;
}

/* ===== Sidebar ===== */
#sidebar {
  grid-row: 1 / 3;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 24px 16px 16px;
  overflow-y: auto;
  z-index: 100;
  transition: transform var(--transition);
}

.sidebar-header {
  margin-bottom: 28px;
  padding: 0 4px;
}

.logo {
  font-size: 1.4rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
  letter-spacing: -0.02em;
}

.logo-icon {
  font-size: 1.6rem;
}

.tagline {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-top: 4px;
  padding-left: 2px;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all var(--transition);
  position: relative;
}

.nav-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.nav-btn.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 12px var(--accent-glow);
}

.nav-btn svg {
  flex-shrink: 0;
}

.badge {
  background: var(--danger);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  margin-left: auto;
}

.badge.hidden {
  display: none;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.6;
}

.version {
  margin-top: 2px;
}

/* ===== Main Content ===== */
#main-content {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ===== Top Bar ===== */
#topbar {
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-primary);
  flex-shrink: 0;
}

#sidebar-toggle {
  display: none;
  color: var(--text-secondary);
}

#view-title {
  font-size: 1.3rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

#search-bar {
  flex: 1;
  max-width: 600px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 0 16px;
  height: 42px;
  transition: border-color var(--transition);
}

#search-bar:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

#search-bar svg {
  color: var(--text-muted);
  flex-shrink: 0;
}

#search-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 0.92rem;
}

#search-input::placeholder {
  color: var(--text-muted);
}

#search-clear {
  color: var(--text-muted);
}

/* ===== Content Area ===== */
#content-area {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

.view {
  display: none;
}

.view.active {
  display: block;
  animation: fadeIn 0.25s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.section-block {
  margin-bottom: 36px;
}

.section-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ===== Stations Grid ===== */
.stations-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.station-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}

.station-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-light);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.station-card.playing {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 4px 20px var(--accent-glow);
}

.station-card.playing .station-favicon {
  box-shadow: 0 0 12px var(--accent-glow);
}

.station-favicon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  background: var(--bg-tertiary);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  color: var(--text-muted);
}

.station-favicon img {
  width: 100%;
  height: 100%;
  border-radius: var(--radius-sm);
  object-fit: cover;
}

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

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

.station-tags {
  color: var(--text-secondary);
  font-size: 0.78rem;
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.station-bitrate {
  color: var(--text-muted);
  font-size: 0.7rem;
  margin-top: 2px;
}

.station-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
  opacity: 0;
  transition: opacity var(--transition);
}

.station-card:hover .station-actions {
  opacity: 1;
}

.btn-fav {
  color: var(--text-muted);
  padding: 4px;
  border-radius: 50%;
  transition: all var(--transition);
}

.btn-fav:hover {
  color: var(--danger);
  background: rgba(255, 107, 107, 0.1);
}

.btn-fav.active {
  color: var(--danger);
}

/* Playing animation on card */
.station-card.playing::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, var(--accent-glow) 0%, transparent 60%);
  pointer-events: none;
}

.now-playing-indicator {
  display: none;
  gap: 2px;
  align-items: flex-end;
  height: 16px;
}

.station-card.playing .now-playing-indicator {
  display: flex;
}

.now-playing-indicator span {
  width: 3px;
  background: var(--accent-light);
  border-radius: 2px;
  animation: equalizer 1s ease-in-out infinite;
}

.now-playing-indicator span:nth-child(1) { height: 60%; animation-delay: 0s; }
.now-playing-indicator span:nth-child(2) { height: 100%; animation-delay: 0.15s; }
.now-playing-indicator span:nth-child(3) { height: 40%; animation-delay: 0.3s; }
.now-playing-indicator span:nth-child(4) { height: 80%; animation-delay: 0.45s; }

@keyframes equalizer {
  0%, 100% { height: 20%; }
  50% { height: 100%; }
}

/* ===== Tags Grid (Countries, Genres, Languages) ===== */
.tags-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag-chip {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 8px 16px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  gap: 6px;
}

.tag-chip:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent);
  color: var(--text-primary);
}

.tag-chip .tag-count {
  background: var(--bg-tertiary);
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--accent-light);
  font-size: 0.88rem;
  font-weight: 500;
  margin-bottom: 16px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}

.back-btn:hover {
  background: var(--bg-tertiary);
}

/* ===== Player Bar ===== */
#player-bar {
  grid-column: 1 / 3;
  height: var(--player-height);
  background: var(--bg-player);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 20px;
  z-index: 200;
  backdrop-filter: blur(20px);
}

#player-bar.hidden {
  display: none;
}

.player-station {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
  max-width: 300px;
}

.player-favicon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  background: var(--bg-tertiary);
}

.player-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.player-name {
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-meta {
  color: var(--text-secondary);
  font-size: 0.75rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.play-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  box-shadow: 0 2px 12px var(--accent-glow);
}

.play-btn:hover {
  background: var(--accent-light);
  transform: scale(1.05);
}

.player-extras {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  justify-content: flex-end;
  max-width: 300px;
}

.volume-control {
  display: flex;
  align-items: center;
  gap: 8px;
}

#volume-slider {
  -webkit-appearance: none;
  width: 100px;
  height: 4px;
  border-radius: 2px;
  background: var(--bg-tertiary);
  outline: none;
}

#volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent-light);
  cursor: pointer;
  transition: all var(--transition);
}

#volume-slider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
  background: #fff;
}

#volume-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent-light);
  cursor: pointer;
  border: none;
}

/* ===== Icon Button ===== */
.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  color: var(--text-secondary);
  transition: all var(--transition);
}

.icon-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

/* ===== Loading & Empty States ===== */
.loading-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 120px;
}

.loader {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border-light);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state svg {
  margin-bottom: 16px;
  opacity: 0.3;
}

.empty-state p {
  font-size: 1.1rem;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text-secondary);
}

.empty-state span {
  font-size: 0.85rem;
}

/* ===== Load More Button ===== */
.load-more-wrapper {
  grid-column: 1 / -1;
  display: flex;
  justify-content: center;
  padding: 20px 0 8px;
}

.load-more-btn {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-light);
  color: var(--text-primary);
  padding: 12px 32px;
  border-radius: var(--radius-lg);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}

.load-more-btn:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 2px 12px var(--accent-glow);
}

/* ===== Utility ===== */
.hidden {
  display: none !important;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: calc(var(--player-height) + 20px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-tertiary);
  border: 1px solid var(--border-light);
  color: var(--text-primary);
  padding: 10px 20px;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 999;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  #app {
    grid-template-columns: 1fr;
  }

  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    transform: translateX(-100%);
    z-index: 300;
    box-shadow: var(--shadow-lg);
  }

  #sidebar.open {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 250;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition);
  }

  .sidebar-backdrop.active {
    opacity: 1;
    pointer-events: all;
  }

  #sidebar-toggle {
    display: flex;
  }

  #player-bar {
    grid-column: 1;
    padding: 0 12px;
    gap: 10px;
  }

  .player-station {
    max-width: 150px;
  }

  .player-extras {
    max-width: none;
    flex: 0;
  }

  .volume-control {
    display: none;
  }

  #content-area {
    padding: 16px;
  }

  .stations-grid {
    grid-template-columns: 1fr;
  }

  .station-actions {
    opacity: 1;
  }
}

@media (max-width: 480px) {
  .player-station {
    max-width: 120px;
  }

  .player-favicon {
    width: 40px;
    height: 40px;
  }

  .play-btn {
    width: 40px;
    height: 40px;
  }

  #btn-prev, #btn-next {
    display: none;
  }
}

/* ===== Globe View ===== */
#view-globe.active {
  display: flex;
  flex-direction: column;
  height: 100%;
  animation-name: globeFadeIn;
}

@keyframes globeFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

#globe-wrap {
  position: relative;
  /* Fill the content area (shrinks automatically when the player bar shows) */
  flex: 1;
  min-height: 320px;
  background: radial-gradient(ellipse at 50% 120%, #141430 0%, var(--bg-primary) 70%);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

#globe-3d {
  position: absolute;
  inset: 0;
  cursor: grab;
  touch-action: none;
}

#globe-3d canvas {
  display: block;
}

#globe-points {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
}

#globe-stats {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 3;
  padding: 7px 11px;
  border: 1px solid rgba(130, 255, 176, 0.22);
  border-radius: 999px;
  background: rgba(9, 13, 27, 0.74);
  color: #a7f3c2;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(8px);
  font-size: 0.76rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  pointer-events: none;
}

#globe-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-light);
  color: var(--text-primary);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  white-space: nowrap;
  box-shadow: var(--shadow);
  z-index: 5;
}

#globe-hint {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  color: var(--text-muted);
  font-size: 0.8rem;
  pointer-events: none;
  white-space: nowrap;
  z-index: 3;
}

#globe-zoom {
  position: absolute;
  right: 14px;
  bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 4;
}

#globe-zoom button {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-light);
  color: var(--text-primary);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  transition: background var(--transition);
}

#globe-zoom button:hover {
  background: var(--accent);
}

#globe-stations {
  margin-top: 20px;
}

@media (max-width: 640px) {
  #globe-wrap {
    height: 60vh;
  }

  #globe-hint {
    display: none;
  }

  #globe-stats {
    top: 10px;
    left: 10px;
  }
}
