:root {
  --accent: #6c63ff;
  --accent-soft: rgba(108, 99, 255, 0.15);
  --accent-hover: #5a51e8;
  --radius: 16px;
  --radius-sm: 10px;
  --transition: 0.3s ease;
}

[data-theme="dark"] {
  --bg: #0f0f13;
  --card: #1a1a24;
  --card-hover: #20202c;
  --text: #f0f0f5;
  --text-muted: #8a8a99;
  --border: rgba(255, 255, 255, 0.06);
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  --shadow-lift: 0 10px 24px rgba(0, 0, 0, 0.45);
  --input-bg: #15151d;
  --error: #ff6b6b;
  --error-bg: rgba(255, 107, 107, 0.1);
}

[data-theme="light"] {
  --bg: #f5f5f5;
  --card: #ffffff;
  --card-hover: #fafafa;
  --text: #15151d;
  --text-muted: #6b6b7a;
  --border: rgba(0, 0, 0, 0.08);
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  --shadow-lift: 0 8px 20px rgba(0, 0, 0, 0.1);
  --input-bg: #ffffff;
  --error: #d63838;
  --error-bg: rgba(214, 56, 56, 0.08);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background var(--transition), color var(--transition);
  padding-bottom: env(safe-area-inset-bottom);
}

.container {
  max-width: 560px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}

/* ---------- Header ---------- */
.header {
  position: relative;
  text-align: center;
  padding: 28px 0 24px;
}

.title {
  font-size: 2rem;
  font-weight: 800;
  margin: 0;
  letter-spacing: -0.02em;
}

.title-emoji {
  display: inline-block;
  filter: drop-shadow(0 2px 6px rgba(108, 99, 255, 0.4));
}

.subtitle {
  margin: 6px 0 0;
  color: var(--text-muted);
  font-size: 0.95rem;
  font-weight: 500;
}

.theme-toggle {
  position: absolute;
  top: 12px;
  right: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--transition), background var(--transition), border-color var(--transition);
}

.theme-toggle:hover {
  transform: rotate(15deg);
  background: var(--card-hover);
}

/* ---------- Controls ---------- */
.controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 18px;
}

.search-wrap {
  position: relative;
  width: 100%;
}

.search-icon {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

#search {
  width: 100%;
  padding: 14px 16px 14px 44px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}

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

.filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.country-filters {
  flex-wrap: wrap;
  row-gap: 8px;
}

.country-chip .flag {
  font-size: 1rem;
  line-height: 1;
}

.chip-count {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.7rem;
  font-weight: 700;
  min-width: 22px;
  text-align: center;
}

.country-chip[aria-pressed="true"] .chip-count {
  background: rgba(255, 255, 255, 0.25);
  color: #fff;
}

.result-count {
  margin-left: auto;
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 500;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}

.chip:hover {
  background: var(--card-hover);
}

.chip[aria-pressed="true"] {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ---------- Now Playing ---------- */
.now-playing {
  position: sticky;
  top: 8px;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  margin-bottom: 14px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  color: #fff;
  box-shadow: 0 8px 24px rgba(108, 99, 255, 0.35);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.now-playing.hidden {
  display: none;
}

.np-info {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.np-text {
  min-width: 0;
}

.np-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.85;
  font-weight: 600;
}

.np-name {
  font-weight: 700;
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 320px;
}

.np-stop {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), transform var(--transition);
  flex-shrink: 0;
}

.np-stop:hover {
  background: rgba(255, 255, 255, 0.32);
  transform: scale(1.05);
}

/* Equalizer */
.equalizer {
  display: inline-flex;
  align-items: flex-end;
  gap: 3px;
  height: 22px;
  flex-shrink: 0;
}

.equalizer span {
  display: inline-block;
  width: 3px;
  background: #fff;
  border-radius: 2px;
  animation: eq 1s ease-in-out infinite;
}

.equalizer span:nth-child(1) { height: 40%; animation-delay: -0.2s; }
.equalizer span:nth-child(2) { height: 70%; animation-delay: -0.4s; }
.equalizer span:nth-child(3) { height: 50%; animation-delay: -0.1s; }
.equalizer span:nth-child(4) { height: 85%; animation-delay: -0.3s; }

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

/* ---------- Station List ---------- */
.station-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.station-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px;
  border-radius: var(--radius);
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  transition: transform var(--transition), box-shadow var(--transition), background var(--transition), border-color var(--transition);
}

.station-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lift);
  background: var(--card-hover);
}

.station-card.is-favorite {
  border-color: var(--accent);
  background: linear-gradient(180deg, var(--accent-soft) 0%, var(--card) 80%);
}

.station-card.is-playing {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft), var(--shadow-lift);
}

.station-logo {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-sm);
  background: var(--input-bg);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 1px solid var(--border);
}

.station-logo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.station-logo .fallback-icon {
  width: 28px;
  height: 28px;
  color: var(--accent);
}

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

.station-name {
  font-weight: 700;
  font-size: 0.98rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 6px;
}

.card-flag {
  font-size: 0.95rem;
  line-height: 1;
  flex-shrink: 0;
}

.city {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 110px;
  font-weight: 500;
}

.city::after {
  content: '·';
  margin-left: 6px;
  color: var(--text-muted);
}

.station-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.tag {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 110px;
}

.tag::after {
  content: '·';
  margin-left: 6px;
  color: var(--text-muted);
}

.tag:last-of-type::after {
  display: none;
}

.bitrate {
  display: inline-block;
  font-size: 0.7rem;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  letter-spacing: 0.02em;
}

.station-error {
  margin-top: 6px;
  font-size: 0.78rem;
  color: var(--error);
  background: var(--error-bg);
  padding: 4px 8px;
  border-radius: 6px;
  display: inline-block;
}

.station-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.fav-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: transparent;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--transition), background var(--transition);
}

.fav-btn:hover {
  background: var(--accent-soft);
  transform: scale(1.1);
}

.play-btn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--transition), background var(--transition), box-shadow var(--transition);
  box-shadow: 0 4px 12px rgba(108, 99, 255, 0.35);
}

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

.play-btn:active {
  transform: scale(0.96);
}

.play-btn svg {
  width: 18px;
  height: 18px;
  fill: #fff;
}

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

/* ---------- Loading / Empty ---------- */
.loading, .empty, .error-box {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-muted);
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 0 auto 12px;
  animation: spin 0.9s linear infinite;
}

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

.error-box {
  color: var(--error);
}

/* ---------- Footer ---------- */
.footer {
  margin-top: 32px;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
}

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

.footer a:hover {
  text-decoration: underline;
}

/* ---------- Responsive ---------- */
@media (max-width: 420px) {
  .container {
    padding: 16px 12px 36px;
  }
  .title {
    font-size: 1.7rem;
  }
  .station-card {
    gap: 10px;
    padding: 12px;
  }
  .station-logo {
    width: 48px;
    height: 48px;
  }
  .play-btn {
    width: 42px;
    height: 42px;
  }
  .fav-btn {
    width: 34px;
    height: 34px;
  }
  .np-name {
    max-width: 200px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
