/* =====================
   CSS Variables & Reset
   ===================== */
:root {
  --bg: #0d0d1a;
  --surface: #161625;
  --surface2: #1e1e35;
  --surface3: #252540;
  --primary: #ff4757;
  --primary-dim: rgba(255, 71, 87, 0.15);
  --accent: #5352ed;
  --text: #f0f0f0;
  --text2: #9898b8;
  --text3: #5a5a7a;
  --border: rgba(255,255,255,0.06);
  --header-h: 56px;
  --nav-h: 64px;
  --mini-h: 64px;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --transition: 0.2s ease;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  font-size: 16px;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  height: 100%;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

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

input {
  font-family: inherit;
}

img {
  display: block;
  max-width: 100%;
}

/* =====================
   App Layout
   ===================== */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  height: 100vh;
  overflow: hidden;
  position: relative;
}

/* =====================
   Header
   ===================== */
#app-header {
  height: var(--header-h);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
}

.header-inner {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
}

.logo-text {
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--text);
}

.logo-accent {
  color: var(--primary);
}

.now-playing-badge {
  background: var(--primary);
  color: #fff;
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 1px;
  padding: 3px 8px;
  border-radius: 20px;
  animation: pulse-badge 2s infinite;
}

@keyframes pulse-badge {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* =====================
   Main content
   ===================== */
#main-content {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.view {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 8px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.view.active {
  opacity: 1;
  pointer-events: all;
  transform: translateY(0);
}

/* =====================
   Bottom Navigation
   ===================== */
.bottom-nav {
  height: var(--nav-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  flex-shrink: 0;
  z-index: 10;
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text3);
  transition: color var(--transition);
  position: relative;
}

.nav-btn svg {
  width: 22px;
  height: 22px;
}

.nav-btn span {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.2px;
}

.nav-btn.active {
  color: var(--primary);
}

.nav-btn.active::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 32px;
  height: 2px;
  background: var(--primary);
  border-radius: 0 0 2px 2px;
}

/* =====================
   Mini Player
   ===================== */
.mini-player {
  background: var(--surface2);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.mini-player.hidden {
  display: none;
}

.mini-player-inner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  height: var(--mini-h);
}

.mini-logo-wrap {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface3);
  flex-shrink: 0;
}

.mini-logo-wrap img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.mini-logo-fallback {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
}

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

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

.mini-name {
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}

.mini-meta {
  font-size: 0.75rem;
  color: var(--text2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

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

.mini-progress {
  height: 2px;
  background: var(--primary);
  width: 100%;
  position: absolute;
  bottom: 0;
  left: 0;
  opacity: 0;
}

.mini-player.is-playing .mini-progress {
  opacity: 1;
  animation: progress-pulse 3s ease-in-out infinite;
}

@keyframes progress-pulse {
  0% { opacity: 0.4; }
  50% { opacity: 1; }
  100% { opacity: 0.4; }
}

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

.icon-btn:active {
  background: var(--surface3);
}

.icon-btn svg {
  width: 22px;
  height: 22px;
}

.icon-btn.active {
  color: var(--primary);
}

/* =====================
   Spinner
   ===================== */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.spinner.hidden {
  display: none;
}

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

/* =====================
   Full Player Overlay
   ===================== */
.full-player {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.full-player.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(100%);
}

.fp-bg {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, #1a1a30 0%, var(--bg) 60%);
}

.fp-content {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: env(safe-area-inset-top, 0px) 0 env(safe-area-inset-bottom, 0px);
}

.fp-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  flex-shrink: 0;
}

.fp-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text2);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

/* Artwork */
.fp-artwork-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  min-height: 0;
}

.fp-artwork {
  position: relative;
  width: min(280px, 70vw);
  height: min(280px, 70vw);
  border-radius: 24px;
  background: var(--surface2);
  overflow: hidden;
  box-shadow: 0 16px 48px rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
}

#fp-logo {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 16px;
}

.fp-logo-fallback {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.fp-logo-fallback svg {
  width: 60%;
  height: 60%;
}

/* Radio waves animation */
.radio-waves {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.radio-waves.active .wave {
  animation: wave-expand 2s ease-out infinite;
}

.wave {
  position: absolute;
  border: 2px solid var(--primary);
  border-radius: 50%;
  width: 100%;
  height: 100%;
  opacity: 0;
}

.wave:nth-child(2) { animation-delay: 0.5s; }
.wave:nth-child(3) { animation-delay: 1s; }

@keyframes wave-expand {
  0% { transform: scale(0.5); opacity: 0.8; }
  100% { transform: scale(1.5); opacity: 0; }
}

/* Station info */
.fp-info {
  text-align: center;
  padding: 8px 24px 16px;
  flex-shrink: 0;
}

.fp-info h2 {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--text);
}

.fp-info p {
  font-size: 0.85rem;
  color: var(--text2);
}

.fp-bitrate {
  font-size: 0.75rem !important;
  color: var(--text3) !important;
  margin-top: 4px;
}

/* Controls */
.fp-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 32px 24px;
  flex-shrink: 0;
  gap: 16px;
}

.fp-loading-wrap {
  width: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.fp-status {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: var(--primary);
  background: var(--primary-dim);
  padding: 4px 8px;
  border-radius: 4px;
}

.fp-play-btn {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(255, 71, 87, 0.4);
  transition: transform var(--transition), box-shadow var(--transition);
}

.fp-play-btn:active {
  transform: scale(0.94);
  box-shadow: 0 2px 10px rgba(255, 71, 87, 0.3);
}

.fp-play-btn svg {
  width: 32px;
  height: 32px;
  color: #fff;
  margin-left: 3px;
}

.fp-play-btn.is-playing svg {
  margin-left: 0;
}

.volume-wrap {
  width: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.vol-icon-sm {
  width: 20px;
  height: 20px;
  color: var(--text2);
  display: none;
}

.volume-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 90px;
  height: 4px;
  border-radius: 2px;
  background: var(--surface3);
  outline: none;
  cursor: pointer;
  transform: rotate(-90deg);
  transform-origin: center;
}

.volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text);
  cursor: pointer;
}

/* Error */
.fp-error {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  margin: 0 16px 8px;
  background: rgba(255,71,87,0.1);
  border-radius: var(--radius-sm);
  color: var(--primary);
  font-size: 0.8rem;
  flex-shrink: 0;
}

.fp-error.hidden {
  display: none;
}

.fp-error svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

/* =====================
   Station Cards
   ===================== */
.station-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--transition);
  position: relative;
}

.station-card:active {
  background: var(--surface);
}

.station-card.is-playing {
  background: var(--primary-dim);
}

.station-card.is-playing .station-name {
  color: var(--primary);
}

.station-logo-wrap {
  width: 50px;
  height: 50px;
  border-radius: 10px;
  background: var(--surface2);
  overflow: hidden;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.station-logo-fallback {
  color: var(--text3);
}

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

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

.station-name {
  font-size: 0.95rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
  margin-bottom: 4px;
}

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

.station-votes {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 0.7rem;
  color: var(--text3);
  flex-shrink: 0;
}

.station-votes svg {
  width: 12px;
  height: 12px;
}

/* =====================
   Home View
   ===================== */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 16px 12px;
}

.section-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.section-link {
  font-size: 0.8rem;
  color: var(--primary);
  font-weight: 600;
}

/* Category chips */
.category-scroll {
  display: flex;
  gap: 8px;
  padding: 4px 16px 16px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.category-scroll::-webkit-scrollbar {
  display: none;
}

.category-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
  color: var(--text2);
}

.category-chip svg {
  width: 14px;
  height: 14px;
}

.category-chip.active,
.category-chip:active {
  background: var(--primary-dim);
  border-color: var(--primary);
  color: var(--primary);
}

/* Station list */
.stations-list {
  list-style: none;
}

/* =====================
   Search View
   ===================== */
.search-bar-wrap {
  padding: 16px 16px 8px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 5;
  border-bottom: 1px solid var(--border);
}

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

.search-input-wrap svg {
  position: absolute;
  left: 12px;
  width: 18px;
  height: 18px;
  color: var(--text3);
  pointer-events: none;
}

#search-input {
  width: 100%;
  padding: 11px 12px 11px 40px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color var(--transition);
}

#search-input:focus {
  border-color: var(--primary);
}

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

/* Filter chips for search */
.filter-row {
  display: flex;
  gap: 6px;
  padding: 10px 16px;
  overflow-x: auto;
  scrollbar-width: none;
  flex-shrink: 0;
}

.filter-row::-webkit-scrollbar {
  display: none;
}

.filter-chip {
  padding: 5px 12px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  color: var(--text2);
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}

.filter-chip.active {
  background: var(--primary-dim);
  border-color: var(--primary);
  color: var(--primary);
}

/* =====================
   Favorites View
   ===================== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 32px;
  text-align: center;
  gap: 12px;
  color: var(--text3);
}

.empty-state svg {
  width: 56px;
  height: 56px;
  opacity: 0.4;
}

.empty-state h3 {
  font-size: 1rem;
  color: var(--text2);
}

.empty-state p {
  font-size: 0.85rem;
  line-height: 1.5;
}

/* =====================
   Loading skeleton
   ===================== */
.skeleton-list {
  list-style: none;
}

.skeleton-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.skeleton-logo {
  width: 50px;
  height: 50px;
  border-radius: 10px;
  background: var(--surface2);
  animation: shimmer 1.5s infinite;
  flex-shrink: 0;
}

.skeleton-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.skeleton-line {
  height: 12px;
  border-radius: 6px;
  background: var(--surface2);
  animation: shimmer 1.5s infinite;
}

.skeleton-line.short {
  width: 60%;
}

@keyframes shimmer {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

/* =====================
   Toast
   ===================== */
.toast {
  position: fixed;
  bottom: calc(var(--nav-h) + var(--mini-h) + 12px);
  left: 50%;
  transform: translateX(-50%) translateY(0);
  background: var(--surface3);
  color: var(--text);
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 500;
  z-index: 200;
  box-shadow: var(--shadow);
  white-space: nowrap;
  max-width: calc(100% - 32px);
  text-align: center;
  transition: opacity 0.3s ease;
}

.toast.hidden {
  opacity: 0;
  pointer-events: none;
}

/* =====================
   Country flag / tag badges
   ===================== */
.badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  background: var(--surface3);
  color: var(--text2);
}

/* =====================
   Scrollbar (desktop)
   ===================== */
@media (pointer: fine) {
  .view::-webkit-scrollbar {
    width: 4px;
  }
  .view::-webkit-scrollbar-thumb {
    background: var(--surface3);
    border-radius: 2px;
  }
}

/* =====================
   Safe areas (notch/home bar)
   ===================== */
.bottom-nav {
  padding-bottom: env(safe-area-inset-bottom, 0px);
  height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
}

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

.text-center {
  text-align: center;
}

.full-width {
  width: 100%;
}
