:root {
  --bg: #0a0a0f;
  --bg-card: #12121a;
  --bg-elevated: #1a1a26;
  --border: #2a2a3a;
  --text: #e8e8f0;
  --text-dim: #8888a0;
  --accent: #00f0ff;
  --accent-dim: #00a0b0;
  --accent-glow: rgba(0, 240, 255, 0.25);
  --pink: #ff00aa;
  --success: #00ff9d;
  --radius: 12px;
  --font-display: 'Orbitron', sans-serif;
  --font-body: 'Inter', system-ui, sans-serif;
}

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

html, body {
  height: 100%;
}

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* Background effects */
.bg-grid {
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(0, 240, 255, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 240, 255, 0.03) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none;
  z-index: 0;
}

.bg-glow {
  position: fixed;
  top: -20%;
  left: 50%;
  transform: translateX(-50%);
  width: 80vw;
  height: 50vh;
  background: radial-gradient(ellipse, rgba(0, 240, 255, 0.08) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

/* Toast / error banner */
.toast {
  position: fixed;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%) translateY(-120%);
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  max-width: min(92vw, 480px);
  padding: 0.75rem 1rem;
  background: rgba(30, 12, 20, 0.95);
  border: 1px solid rgba(255, 80, 100, 0.45);
  border-radius: 10px;
  color: #ffc0c8;
  font-size: 0.85rem;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(12px);
  transition: transform 0.3s ease, opacity 0.3s ease;
  opacity: 0;
  pointer-events: none;
}

.toast.visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
  pointer-events: auto;
}

.toast.info {
  border-color: rgba(0, 240, 255, 0.4);
  color: #b8f4ff;
  background: rgba(10, 24, 32, 0.95);
}

.toast.success {
  border-color: rgba(0, 255, 157, 0.4);
  color: #b8ffe0;
  background: rgba(10, 28, 22, 0.95);
}

.toast-icon {
  flex-shrink: 0;
  font-size: 1rem;
}

.toast-close {
  margin-left: auto;
  background: none;
  border: none;
  color: inherit;
  font-size: 1.2rem;
  cursor: pointer;
  opacity: 0.7;
  line-height: 1;
  padding: 0 0.15rem;
}

.toast-close:hover {
  opacity: 1;
}

/* Header */
.header {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: rgba(10, 10, 15, 0.85);
  backdrop-filter: blur(12px);
  flex-wrap: wrap;
  gap: 1rem;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.logo-icon {
  width: 42px;
  height: 42px;
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-glow);
  border-radius: 10px;
  border: 1px solid rgba(0, 240, 255, 0.3);
  animation: pulse-glow 3s ease-in-out infinite;
}

.logo-icon svg {
  width: 24px;
  height: 24px;
}

@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 8px var(--accent-glow); }
  50% { box-shadow: 0 0 20px var(--accent-glow), 0 0 30px rgba(0, 240, 255, 0.15); }
}

.logo-text h1 {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  background: linear-gradient(90deg, var(--accent), #00ffaa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.tagline {
  font-size: 0.7rem;
  color: var(--text-dim);
  letter-spacing: 0.04em;
}

.btn-update {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1.1rem;
  background: linear-gradient(135deg, rgba(0, 240, 255, 0.15), rgba(255, 0, 170, 0.1));
  border: 1px solid rgba(0, 240, 255, 0.4);
  border-radius: 999px;
  color: var(--accent);
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.25s ease;
}

.btn-update:hover {
  background: linear-gradient(135deg, rgba(0, 240, 255, 0.25), rgba(255, 0, 170, 0.2));
  box-shadow: 0 0 16px var(--accent-glow);
  transform: translateY(-1px);
}

.btn-update:active {
  transform: translateY(0);
}

.btn-update.loading {
  pointer-events: none;
  opacity: 0.7;
}

.btn-update.loading .btn-icon {
  animation: spin 1s linear infinite;
}

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

/* Main */
.main {
  position: relative;
  z-index: 5;
  flex: 1;
  padding: 1.25rem 1.5rem 8.5rem;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  margin-bottom: 1.25rem;
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 1rem;
  width: 18px;
  height: 18px;
  color: var(--text-dim);
  pointer-events: none;
}

#searchInput {
  width: 100%;
  padding: 0.85rem 2.5rem 0.85rem 2.75rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

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

#searchInput::placeholder {
  color: var(--text-dim);
}

.clear-btn {
  position: absolute;
  right: 0.75rem;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.3rem;
  cursor: pointer;
  line-height: 1;
  padding: 0.2rem;
}

.clear-btn:hover {
  color: var(--text);
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.filters select {
  flex: 1;
  min-width: 140px;
  padding: 0.65rem 0.9rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.85rem;
  outline: none;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238888a0' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2rem;
}

.filters select:focus {
  border-color: var(--accent);
}

/* AI Status */
.ai-status {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1.1rem;
  background: linear-gradient(90deg, rgba(0, 240, 255, 0.08), rgba(255, 0, 170, 0.06));
  border: 1px solid rgba(0, 240, 255, 0.25);
  border-radius: var(--radius);
  margin-bottom: 1rem;
  animation: fadeIn 0.3s ease;
}

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

.ai-pulse {
  width: 10px;
  height: 10px;
  background: var(--accent);
  border-radius: 50%;
  animation: pulse 1.2s ease-in-out infinite;
  flex-shrink: 0;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.85); }
}

#aiMessage {
  font-size: 0.9rem;
  color: var(--accent);
}

.stats-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 1rem;
}

.divider {
  opacity: 0.5;
}

/* Station Grid */
.station-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

.station-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  display: flex;
  gap: 0.9rem;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
}

.station-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, transparent 60%, rgba(0, 240, 255, 0.04));
  pointer-events: none;
}

.station-card:hover {
  border-color: rgba(0, 240, 255, 0.45);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35), 0 0 12px var(--accent-glow);
}

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

/* Live health badges */
.health-badge {
  position: absolute;
  top: 0.55rem;
  left: 0.55rem;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  font-size: 0.65rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  line-height: 1;
}

.health-badge.ok {
  background: rgba(0, 255, 157, 0.2);
  color: var(--success);
  border: 1px solid rgba(0, 255, 157, 0.5);
}

.health-badge.remote {
  background: rgba(0, 240, 255, 0.15);
  color: var(--accent);
  border: 1px solid rgba(0, 240, 255, 0.35);
  font-size: 0.55rem;
}

.health-badge.suspect {
  background: rgba(255, 180, 0, 0.2);
  color: #ffb400;
  border: 1px solid rgba(255, 180, 0, 0.45);
}

.station-favicon {
  width: 56px;
  height: 56px;
  border-radius: 10px;
  background: var(--bg-elevated);
  object-fit: cover;
  flex-shrink: 0;
  border: 1px solid var(--border);
}

.station-favicon.fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  color: var(--accent-dim);
}

.station-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

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

.station-meta {
  font-size: 0.75rem;
  color: var(--text-dim);
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.station-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.2rem;
}

.tag {
  font-size: 0.65rem;
  padding: 0.15rem 0.45rem;
  background: rgba(0, 240, 255, 0.1);
  border: 1px solid rgba(0, 240, 255, 0.2);
  border-radius: 999px;
  color: var(--accent-dim);
}

.play-indicator {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  width: 8px;
  height: 8px;
  background: var(--success);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--success);
  animation: pulse 1.5s ease-in-out infinite;
  display: none;
}

.station-card.playing .play-indicator {
  display: block;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 4rem 1rem;
  color: var(--text-dim);
}

.empty-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
  opacity: 0.6;
}

.empty-state h3 {
  color: var(--text);
  margin-bottom: 0.4rem;
}

/* Now Playing */
.now-playing {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem 1.25rem;
  background: rgba(12, 12, 20, 0.95);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(16px);
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.4);
}

.np-favicon {
  position: relative;
  width: 48px;
  height: 48px;
  flex-shrink: 0;
}

.np-favicon img {
  width: 100%;
  height: 100%;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--border);
}

.eq-bars {
  position: absolute;
  inset: 0;
  display: none;
  align-items: flex-end;
  justify-content: center;
  gap: 3px;
  padding: 6px;
  background: rgba(0, 0, 0, 0.55);
  border-radius: 8px;
}

.eq-bars.active {
  display: flex;
}

.eq-bars span {
  width: 4px;
  background: var(--accent);
  border-radius: 2px;
  animation: eq 0.8s ease-in-out infinite;
}

.eq-bars span:nth-child(1) { height: 40%; animation-delay: 0s; }
.eq-bars span:nth-child(2) { height: 70%; animation-delay: 0.15s; }
.eq-bars span:nth-child(3) { height: 50%; animation-delay: 0.3s; }
.eq-bars span:nth-child(4) { height: 85%; animation-delay: 0.45s; }

@keyframes eq {
  0%, 100% { transform: scaleY(0.4); }
  50% { transform: scaleY(1); }
}

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

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

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

/* Real-time buffer / stream stats */
.buffer-stats {
  margin-top: 0.35rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.buf-bar-track {
  height: 4px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 2px;
  overflow: hidden;
  max-width: 220px;
}

.buf-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--success));
  border-radius: 2px;
  transition: width 0.25s ease, background 0.3s ease;
}

.buf-bar-fill.low {
  background: linear-gradient(90deg, #ff6b35, #ffb400);
}

.buf-bar-fill.critical {
  background: linear-gradient(90deg, #ff3355, #ff6b35);
  animation: buf-pulse 0.8s ease-in-out infinite;
}

.buf-bar-fill.stalled {
  background: #ff3355;
  width: 100% !important;
  opacity: 0.6;
}

@keyframes buf-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.buf-details {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  font-size: 0.68rem;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.buf-details .buf-sep {
  opacity: 0.4;
}

#bufState {
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

#bufState.playing { color: var(--success); }
#bufState.buffering { color: #ffb400; }
#bufState.stalled { color: #ff3355; }
#bufState.paused { color: var(--text-dim); }
#bufState.ended { color: var(--text-dim); }

#bufTransport {
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--accent);
}

#bufTransport[title^="WebSocket"] {
  color: var(--success);
}

.np-controls {
  display: flex;
  gap: 0.4rem;
}

.np-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}

.np-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(0, 240, 255, 0.1);
}

.np-btn svg {
  width: 18px;
  height: 18px;
}

.np-btn.active {
  color: var(--pink);
  border-color: var(--pink);
}

/* Responsive */
@media (max-width: 600px) {
  .header {
    padding: 0.85rem 1rem;
  }

  .logo-text h1 {
    font-size: 0.95rem;
  }

  .tagline {
    display: none;
  }

  .btn-update .btn-text {
    display: none;
  }

  .main {
    padding: 1rem 1rem 8rem;
  }

  .buf-details {
    font-size: 0.62rem;
  }

  .buf-bar-track {
    max-width: 140px;
  }

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

  .now-playing {
    padding: 0.7rem 0.9rem;
  }
}

/* Loading skeleton */
.skeleton {
  background: linear-gradient(90deg, var(--bg-card) 25%, var(--bg-elevated) 50%, var(--bg-card) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius);
  height: 90px;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
