/* --- 1. VARIABLES & RESET --- */
:root {
  --bg-dark: #0f172a;
  --sidebar-bg: #1e293b;
  --accent: #007aff;
  --text-primary: #f8fafc;
  --text-dim: #94a3b8;
  --glass: rgba(255, 255, 255, 0.05);
  --glass-border: rgba(255, 255, 255, 0.1);
  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);
}

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

body {
  background-color: var(--bg-dark);
  color: var(--text-primary);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  line-height: 1.5;
  min-height: 100vh;
  /* Prevent horizontal bounce on mobile */
  overflow-x: hidden; 
}

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

/* --- 2. MOBILE-FIRST LAYOUT (Default) --- */
.app-layout {
  display: flex;
  flex-direction: column; /* Stack vertically on mobile */
  min-height: 100vh;
}

/* SIDEBAR (On Mobile, this is the station list below the player) */
.sidebar {
  width: 100%;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  order: 2; /* Move below player on mobile */
  padding-bottom: var(--safe-bottom);
}

.sidebar-header {
  padding: 1.5rem;
  /* Solid background: the header sticks while the list scrolls under it,
     so a translucent fill lets cards bleed through and looks messy. */
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--glass-border);
  /* Small shadow: a big soft shadow on a sticky element is repainted
     on every scroll frame. */
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  position: sticky;
  top: 0;
  z-index: 10;
}

.sidebar-header h1 {
  font-size: 1.25rem;
  margin-bottom: 1rem;
}

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

.search-container i {
  position: absolute;
  left: 12px;
  color: var(--text-dim);
}

.search-container input {
  width: 100%;
  padding: 12px 12px 12px 40px;
  border-radius: 8px;
  border: 1px solid var(--glass-border);
  background: var(--glass);
  color: white;
  font-size: 1rem;
}

.stations-container {
  padding: 1rem;
  display: grid;
  grid-template-columns: 1fr; /* Single column on mobile */
  gap: 10px;
}

/* FILTERS (Province + Favorites) */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.filter-row {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}

.filter-select {
  flex: 1;
  min-width: 0;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--glass-border);
  background: var(--glass);
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: inherit;
}

.filter-select option {
  color: #0f172a;
}

.filter-select.active {
  border-color: var(--accent);
  color: var(--accent);
}

.fav-toggle-btn {
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--glass-border);
  background: var(--glass);
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
}

.fav-toggle-btn.active {
  background: rgba(0, 122, 255, 0.15);
  border-color: var(--accent);
  color: var(--accent);
}

/* RECENTLY PLAYED */
.recent-section {
  padding: 1rem 1rem 0;
}

.section-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 10px;
}

.recent-container {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.error-msg {
  color: var(--text-dim);
  text-align: center;
  padding: 1rem;
  font-size: 0.9rem;
}

/* PLAYER HERO (On Mobile, this is the top section) */
.player-hero {
  width: 100%;
  padding: calc(2rem + var(--safe-top)) 1.5rem 2rem;
  background: radial-gradient(circle at center, #1e293b 0%, #0f172a 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  order: 1; /* Keep player on top */
}

.now-playing-container {
  width: 100%;
  max-width: 400px;
  text-align: center;
}

#main-logo {
  width: clamp(180px, 50vw, 280px); /* Scales based on screen width */
  aspect-ratio: 1/1;
  border-radius: 20px;
  margin: 0 auto 1.5rem;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
  object-fit: cover;
}

.station-info h2 {
  font-size: clamp(1.2rem, 5vw, 1.75rem);
  margin-bottom: 0.25rem;
}

.station-info p {
  color: var(--text-dim);
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
}

/* --- 3. CONTROLS & UI ELEMENTS --- */
.eq-container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  background: var(--glass);
  padding: 15px;
  border-radius: 12px;
  margin-bottom: 1.5rem;
}

.eq-slider {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 11px;
  color: var(--text-dim);
  gap: 8px;
}

.eq-slider input {
  width: 100%;
  accent-color: var(--accent);
}

.main-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.nav-btn {
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 1.5rem;
  padding: 10px;
  cursor: pointer;
}

.play-trigger {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  box-shadow: 0 10px 20px rgba(0, 122, 255, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
}

.volume-box {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-dim);
}

.volume-box input {
  flex: 1;
  accent-color: var(--text-dim);
}

/* EQ PRESETS */
.eq-presets {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-bottom: 1.5rem;
}

.preset-btn {
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--glass-border);
  background: var(--glass);
  color: var(--text-primary);
  font-size: 0.8rem;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s ease;
}

.preset-btn.active {
  background: rgba(0, 122, 255, 0.15);
  border-color: var(--accent);
  color: var(--accent);
}

/* PLAYER TOOLS (Shuffle / Share / Sleep Timer) */
.player-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 1.5rem;
}

.tool-btn {
  padding: 10px 16px;
  border-radius: 999px;
  border: 1px solid var(--glass-border);
  background: var(--glass);
  color: var(--text-primary);
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s ease;
}

.tool-btn:active {
  transform: scale(0.97);
}

.sleep-box {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-dim);
  font-size: 0.85rem;
}

.sleep-box .filter-select {
  flex: none;
  padding: 8px 10px;
  font-size: 0.85rem;
}

.sleep-status {
  min-width: 44px;
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
  font-size: 0.85rem;
}

.sleep-status.active {
  color: var(--accent);
}

/* TOUCH POLISH: remove the double-tap zoom delay on interactive elements */
button, select, .station-card, .province-chip {
  touch-action: manipulation;
}

/* STATION CARDS */
.station-card {
  display: flex;
  align-items: center;
  padding: 12px;
  background: var(--glass);
  border: 1px solid transparent;
  border-radius: 12px;
  cursor: pointer;
  /* Only the cheap properties transition; "all" made every class or
     state change on any of ~590 cards a candidate for animation work. */
  transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.1s ease;
  /* NOTE: content-visibility: auto was removed — with the chunked
     renderer the DOM is already bounded, and the property made a
     previously-played card stick in place while the rest of the
     list scrolled past it (rendering-containment artifact). */
}

/* Invisible marker the chunked renderer watches to load more cards */
.list-sentinel {
  height: 1px;
}

.station-card:active {
  transform: scale(0.98);
}

.station-card.active {
  background: rgba(0, 122, 255, 0.15);
  border-color: var(--accent);
}

.station-card img {
  width: 50px;
  height: 50px;
  border-radius: 8px;
  margin-right: 15px;
  object-fit: cover;
  flex: none;
}

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

/* FAVORITE HEART ON STATION CARDS */
.fav-btn {
  flex: none;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.1rem;
  padding: 10px;
  margin-left: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.fav-btn.favorited {
  color: var(--accent);
}

.name {
  display: block;
  font-weight: 600;
  font-size: 0.95rem;
}

.location {
  font-size: 0.8rem;
  color: var(--text-dim);
}

/* --- 4. TABLET & DESKTOP OVERRIDES --- */

/* Tablets (iPad) */
@media (min-width: 768px) {
  .stations-container {
    grid-template-columns: repeat(2, 1fr); /* Two columns of stations */
  }
}

/* Desktop */
@media (min-width: 1024px) {
  .app-layout {
    flex-direction: row; /* Horizontal layout */
    height: 100vh;
    overflow: hidden;
  }

  .sidebar {
    width: 400px;
    height: 100vh;
    order: 1;
    border-right: 1px solid var(--glass-border);
  }

  .stations-container {
    grid-template-columns: 1fr; /* Back to single column in the sidebar */
    overflow-y: auto;
  }

  .player-hero {
    flex: 1;
    height: 100vh;
    order: 2;
    padding: 2rem;
    justify-content: center;
  }

  .now-playing-container {
    max-width: 450px;
  }

  #main-logo {
    width: 320px;
  }

  /* Mini-player, province chips and the EQ toggle are mobile-only */
  .mini-player {
    display: none !important;
  }
}
/* Result count under the filters (added with the province-filter fix) */
.station-count {
  margin-top: 0.6rem;
  font-size: 0.8rem;
  color: var(--text-dim);
  min-height: 1em;
}

/* --- 5. MOBILE EXPERIENCE PACK --- */

/* Province chips + EQ toggle: hidden by default, shown below desktop */
.province-chips {
  display: none;
}

.eq-toggle {
  display: none;
}

/* STICKY MINI-PLAYER (bar itself is styled for all widths but the
   desktop media query above force-hides it at >=1024px) */
.mini-player {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px calc(10px + var(--safe-bottom));
  /* Nearly opaque solid fill. A backdrop-filter blur here forced the
     phone to re-blur everything scrolling under this fixed bar on
     every frame — a major scroll-jank source — for almost no visual
     difference over this dark a background. */
  background: rgba(15, 23, 42, 0.97);
  border-top: 1px solid var(--glass-border);
}

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

.mini-player img {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  object-fit: cover;
  flex: none;
}

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

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

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

.mini-btn {
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 1.1rem;
  padding: 10px;
  cursor: pointer;
  flex: none;
}

.mini-play {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

@media (max-width: 1023px) {
  /* Keep the last cards / proxy note clear of the fixed mini-player */
  body.has-mini-player .sidebar {
    padding-bottom: calc(88px + var(--safe-bottom));
  }

  /* PROVINCE CHIPS */
  .province-chips {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-top: 12px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .province-chips::-webkit-scrollbar {
    display: none;
  }

  .province-chip {
    flex: none;
    padding: 8px 14px;
    border-radius: 999px;
    border: 1px solid var(--glass-border);
    background: var(--glass);
    color: var(--text-primary);
    font-size: 0.82rem;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s ease;
  }

  .province-chip.active {
    background: rgba(0, 122, 255, 0.15);
    border-color: var(--accent);
    color: var(--accent);
  }

  /* SLIM STICKY HEADER: the solid header was eating ~half the phone
     screen, so tighten every row inside it (mobile/tablet only) */
  .sidebar-header {
    padding: 0.7rem 1rem 0.55rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  }

  .sidebar-header h1 {
    font-size: 1.02rem;
    margin-bottom: 0.5rem;
  }

  .search-container input {
    padding: 9px 12px 9px 38px;
    font-size: 0.95rem;
  }

  .filter-row {
    margin-top: 8px;
    gap: 8px;
  }

  .filter-select,
  .fav-toggle-btn {
    padding: 8px 10px;
    font-size: 0.85rem;
  }

  .station-count {
    margin-top: 0.35rem;
    font-size: 0.75rem;
  }

  .province-chips {
    padding-top: 8px;
  }

  .province-chip {
    padding: 6px 12px;
    font-size: 0.8rem;
  }

  /* COMPACT PLAYER: small artwork + info in one row, list starts higher */
  .player-hero {
    padding: calc(1rem + var(--safe-top)) 1rem 1.25rem;
  }

  .now-playing-container {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    text-align: left;
  }

  .artwork-card {
    flex: none;
  }

  #main-logo {
    width: 112px;
    margin: 0;
    border-radius: 14px;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.4);
  }

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

  .station-info h2 {
    font-size: 1.15rem;
  }

  .station-info p {
    margin-bottom: 0;
  }

  .now-playing-container > .eq-toggle,
  .now-playing-container > .eq-container,
  .now-playing-container > .eq-presets,
  .now-playing-container > .main-controls,
  .now-playing-container > .player-tools,
  .now-playing-container > .volume-box {
    flex: 0 0 100%;
  }

  /* EQ COLLAPSE behind the Tune toggle */
  .eq-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-top: 1rem;
    padding: 9px 16px;
    border-radius: 999px;
    border: 1px solid var(--glass-border);
    background: var(--glass);
    color: var(--text-primary);
    font-size: 0.85rem;
    font-family: inherit;
    cursor: pointer;
  }

  .eq-container:not(.open),
  .eq-presets:not(.open) {
    display: none;
  }

  .eq-container.open {
    margin-top: 1rem;
    margin-bottom: 1rem;
  }

  .eq-presets.open {
    margin-bottom: 0.5rem;
  }

  .main-controls {
    margin-top: 1.25rem;
    margin-bottom: 1rem;
  }

  .player-tools {
    margin-top: 0;
    margin-bottom: 1rem;
  }
}

/* Audio engine status line (inside the EQ/Tune area) */
.audio-diag {
  margin-top: 0.6rem;
  font-size: 0.72rem;
  color: var(--text-secondary, #94a3b8);
  text-align: center;
  opacity: 0.85;
}

/* --- 6. SPOTIFY-STYLE MOBILE SHELL --- */
/* Tab bar + Now Playing sheet exist in the DOM at all sizes but are
   only ever shown below desktop width. */
.tab-bar {
  display: none;
}

.np-sheet {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: radial-gradient(circle at top, #1e293b 0%, #0f172a 70%);
  transform: translateY(102%);
  transition: transform 0.34s cubic-bezier(0.32, 0.72, 0.28, 1);
  overflow-y: auto;
  padding: calc(0.25rem + var(--safe-top)) 1.25rem calc(1.5rem + var(--safe-bottom));
}

.np-sheet[hidden] {
  display: none;
}

.np-sheet.open {
  transform: translateY(0);
}

.np-close {
  position: sticky;
  top: 0;
  display: flex;
  margin: 0 auto 0.25rem;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.25rem;
  padding: 10px 20px;
  cursor: pointer;
  z-index: 2;
}

body.sheet-open {
  overflow: hidden;
}

@media (min-width: 1024px) {
  /* Desktop keeps the in-flow hero player; sheet + tabs never show */
  .np-sheet,
  .tab-bar {
    display: none !important;
  }
}

@media (max-width: 1023px) {
  /* LIST-FIRST: the hero leaves the flow on mobile — its controls
     live in the Now Playing sheet (JS moves the same DOM node). */
  .player-hero {
    display: none;
  }

  /* BOTTOM TAB BAR (Home / Favorites / Recent) */
  .tab-bar {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    background: #0b1220;
    border-top: 1px solid var(--glass-border);
    padding: 6px 8px calc(6px + var(--safe-bottom));
  }

  .tab-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 0.68rem;
    font-family: inherit;
    padding: 6px 0 2px;
    cursor: pointer;
  }

  .tab-btn i {
    font-size: 1.15rem;
  }

  .tab-btn.active {
    color: var(--accent);
  }

  /* Mini-player floats as a card above the tab bar (Spotify-style) */
  .mini-player {
    left: 8px;
    right: 8px;
    bottom: calc(62px + var(--safe-bottom));
    border: 1px solid var(--glass-border);
    border-radius: 14px;
    cursor: pointer;
  }

  /* Keep list content clear of tab bar (+ mini-player when present) */
  .sidebar {
    padding-bottom: calc(78px + var(--safe-bottom));
  }

  body.has-mini-player .sidebar {
    padding-bottom: calc(158px + var(--safe-bottom));
  }

  /* NOW PLAYING SHEET: centered, artwork-led layout */
  .np-sheet .now-playing-container {
    display: block;
    max-width: 430px;
    margin: 0 auto;
    text-align: center;
  }

  .np-sheet .artwork-card {
    display: flex;
    justify-content: center;
  }

  .np-sheet #main-logo {
    width: min(68vw, 280px);
    margin: 0 auto 1.25rem;
  }

  .np-sheet .station-info {
    flex: none;
    padding-left: 0;
    text-align: center;
  }

  .np-sheet .station-info p {
    margin-bottom: 1.25rem;
  }
}
