/* ── Reset & base ────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --radius:    12px;
  --red:       #ff453a;   /* macOS system red */
  --green:     #30d158;   /* macOS system green */

  /* macOS Dark (default) */
  --bg:        #1c1c1e;   /* systemGray6 dark */
  --surface:   #2c2c2e;   /* systemGray5 */
  --surface2:  #3a3a3c;   /* systemGray4 */
  --surface3:  #48484a;   /* systemGray3 */
  --border:    rgba(255,255,255,.10);
  --border2:   rgba(255,255,255,.16);
  --text:      #f5f5f7;
  --text-2:    #aeaeb2;
  --text-3:    #8e8e93;   /* systemGray */
  --blue:      #0a84ff;   /* macOS system blue (dark) */
  --blue-2:    #0a84ff;
  --blue-3:    #5e9eff;
  --yellow:    #ffd60a;   /* macOS system yellow (dark) */
  --header-bg: rgba(28,28,30,.68);
  --stat-1:    #ffffff;
  --stat-2:    var(--blue-3);
  --shadow:    rgba(0,0,0,.40);
}

[data-theme="light"] {
  --bg:        #f5f5f7;   /* macOS window background */
  --surface:   #ffffff;
  --surface2:  #f0f0f2;
  --surface3:  #e7e7ea;
  --border:    rgba(0,0,0,.09);
  --border2:   rgba(0,0,0,.14);
  --text:      #1d1d1f;   /* Apple near-black */
  --text-2:    #6e6e73;
  --text-3:    #8e8e93;
  --blue:      #007aff;   /* macOS system blue (light) */
  --blue-2:    #007aff;
  --blue-3:    #3395ff;
  --yellow:    #ffb000;
  --header-bg: rgba(255,255,255,.68);
  --stat-1:    #1d1d1f;
  --stat-2:    var(--blue-2);
  --shadow:    rgba(0,0,0,.12);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Inter', 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  transition: background-color .35s ease, color .25s ease;
}

/* Smooth theme cross-fade on the main surfaces */
header, .panel, .a-card, .stat, .a-stat, .np-card, .search-wrap,
.tabs, select, .bar-track, .chip, .stat-row .stat {
  transition: background-color .3s ease, border-color .3s ease, color .25s ease;
}

/* ── Header ──────────────────────────────────────────────────── */
header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px;
  /* env(safe-area-inset-*) keeps the header clear of the iOS status bar / Dynamic Island in the installed PWA */
  padding: calc(15px + env(safe-area-inset-top)) calc(28px + env(safe-area-inset-right)) 15px calc(28px + env(safe-area-inset-left));
  border-bottom: 1px solid var(--border);
  background: var(--header-bg);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  position: sticky; top: 0; z-index: 50;
}
.header-left  { display: flex; align-items: center; gap: 13px; }
.header-right { display: flex; align-items: center; gap: 10px; }

/* Language toggle */
.lang-toggle {
  width: 38px; height: 38px; flex-shrink: 0;
  background: var(--surface2); border: 1px solid var(--border2);
  border-radius: 10px; color: var(--text-2); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 800; letter-spacing: .02em;
  transition: background .18s, color .18s, border-color .18s, transform .2s;
}
.lang-toggle:hover { color: var(--text); border-color: var(--blue-2); }
.lang-toggle:active { transform: scale(.92); }

/* Notification opt-in */
.notify-btn {
  width: 38px; height: 38px; flex-shrink: 0;
  background: var(--surface2); border: 1px solid var(--border2);
  border-radius: 10px; color: var(--text-2); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .18s, color .18s, border-color .18s, transform .2s;
}
.notify-btn:hover { color: var(--text); border-color: var(--blue-2); }
.notify-btn:active { transform: scale(.92); }
.notify-btn.active { color: var(--blue); border-color: var(--blue-2); background: var(--blue-3); }

/* Theme toggle */
.theme-toggle {
  width: 38px; height: 38px; flex-shrink: 0;
  background: var(--surface2); border: 1px solid var(--border2);
  border-radius: 10px; color: var(--text-2); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .18s, color .18s, border-color .18s, transform .2s;
}
.theme-toggle:hover { color: var(--text); border-color: var(--blue-2); }
.theme-toggle:active { transform: scale(.92); }
.theme-toggle svg { transition: transform .4s cubic-bezier(.4,0,.2,1); }
/* Icon reflects the chosen MODE (not the resolved theme). */
.theme-toggle .icon-auto,
.theme-toggle .icon-sun,
.theme-toggle .icon-moon { display: none; }
.theme-toggle[data-pref="system"] .icon-auto { display: block; }
.theme-toggle[data-pref="light"]  .icon-sun  { display: block; }
.theme-toggle[data-pref="dark"]   .icon-moon { display: block; }
.theme-toggle:hover svg { transform: rotate(20deg); }
.logo-mark {
  width: 42px; height: 42px;
  background: linear-gradient(135deg, var(--blue-2), #7aa0ff);
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center; font-size: 22px;
  box-shadow: 0 6px 18px rgba(47,107,255,.45);
}
.logo-name { font-size: 17px; font-weight: 800; letter-spacing: -.02em; }
.logo-sub  { font-size: 11.5px; color: var(--text-3); margin-top: 1px; }

.search-wrap {
  position: relative;
  display: flex; align-items: center; gap: 9px;
  background: var(--surface2); border: 1px solid var(--border2);
  border-radius: 10px; padding: 10px 14px; transition: border-color .15s;
}
.search-wrap:focus-within { border-color: var(--blue-2); }

/* Autosuggest dropdown */
.search-suggest {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 80;
  background: var(--surface2); border: 1px solid var(--border2); border-radius: 10px;
  box-shadow: 0 12px 34px var(--shadow); overflow: hidden auto; max-height: 340px;
}
.suggest-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px; cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.suggest-item:last-child { border-bottom: none; }
.suggest-item:hover, .suggest-item.active { background: var(--surface3); }
.suggest-logo {
  width: 30px; height: 30px; flex-shrink: 0; border-radius: 7px; object-fit: contain;
  background: #fff; border: 1px solid var(--border2); padding: 2px;
  display: flex; align-items: center; justify-content: center; font-size: 15px; color: #8a8a8e;
}
.suggest-text { min-width: 0; }
.suggest-name { font-size: 13px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.suggest-tag  { font-size: 11px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-wrap svg { color: var(--text-3); flex-shrink: 0; }
.search-wrap input {
  background: none; border: none; outline: none;
  color: var(--text); font-size: 14px; width: 240px;
}
.search-wrap input::placeholder { color: var(--text-3); }
.search-clear {
  background: var(--surface3); border: none; color: var(--text-2);
  width: 18px; height: 18px; border-radius: 50%; flex-shrink: 0;
  font-size: 10px; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, color .15s;
}
.search-clear:hover { background: var(--red); color: #fff; }

/* ── Layout ──────────────────────────────────────────────────── */
.layout {
  max-width: 1380px; margin: 0 auto; padding: 24px;
  display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 22px;
  align-items: start;
}
/* min-width:0 lets the content column shrink instead of overflowing right. */
/* Reserve a screen of height so the footer/layout doesn't jump when the
   station grid loads in asynchronously (kills the big CLS). */
.content { min-width: 0; min-height: 100vh; }
.sidebar {
  position: sticky; top: 88px;
  display: flex; flex-direction: column; gap: 16px;
  max-height: calc(100vh - 108px); overflow-y: auto;
  padding-right: 4px; scrollbar-width: thin; scrollbar-color: var(--border2) transparent;
}
.sidebar::-webkit-scrollbar { width: 7px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 4px; }

/* ── Stats row ───────────────────────────────────────────────── */
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px 10px; text-align: center;
  cursor: pointer; font: inherit; color: inherit;
  transition: border-color .15s, transform .1s, background .15s;
}
.stat:hover { border-color: var(--blue-2); transform: translateY(-1px); }
.stat:active { transform: scale(.97); }
.stat-value {
  font-size: 22px; font-weight: 800; letter-spacing: -.02em;
  color: var(--stat-2);                         /* solid fallback — always legible */
}
@supports ((-webkit-background-clip: text) or (background-clip: text)) {
  .stat-value {
    background: linear-gradient(135deg, var(--stat-1), var(--stat-2));
    -webkit-background-clip: text; background-clip: text;
    -webkit-text-fill-color: transparent;
  }
}
.stat-label { font-size: 10.5px; font-weight: 600; letter-spacing: .06em; color: var(--text-3); text-transform: uppercase; margin-top: 3px; }

/* ── Sidebar panels ──────────────────────────────────────────── */
.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
}
.panel-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }
.panel-head h3 { font-size: 14px; font-weight: 800; letter-spacing: -.01em; }
.panel-tag { font-size: 10.5px; color: var(--text-3); font-weight: 600; }

/* Ranked lists */
.rank-list { list-style: none; display: flex; flex-direction: column; gap: 2px; }
.rank-item {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 8px; border-radius: 9px; cursor: pointer;
  transition: background .14s;
}
.rank-item:hover { background: var(--surface2); }
.rank-item.playing { background: rgba(47,107,255,.12); }
.rank-num {
  width: 20px; flex-shrink: 0; text-align: center;
  font-size: 13px; font-weight: 800; color: var(--text-3);
}
.rank-item:nth-child(1) .rank-num { color: var(--yellow); }
.rank-item:nth-child(2) .rank-num { color: #cbd5e1; }
.rank-item:nth-child(3) .rank-num { color: #d6964a; }
.rank-logo {
  width: 30px; height: 30px; flex-shrink: 0; border-radius: 8px;
  object-fit: contain; background: #fff; padding: 2px; border: 1px solid var(--border2);
  display: flex; align-items: center; justify-content: center; font-size: 14px; color: #8a8a8e;
}
.rank-body { flex: 1; min-width: 0; }
.rank-name { font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rank-sub  { font-size: 10.5px; color: var(--text-3); margin-top: 1px; }
.rank-skeleton { font-size: 12px; color: var(--text-3); padding: 8px; }

/* Trending track list */
.track-list { list-style: none; display: flex; flex-direction: column; gap: 2px; }
.track-item {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 8px; border-radius: 9px; transition: background .14s;
}
.track-item.clickable { cursor: pointer; }
.track-item.clickable:hover { background: var(--surface2); }
.track-live { display: block; font-size: 10px; font-weight: 700; color: var(--green); margin-top: 2px; }
.track-live.muted { color: var(--text-3); font-weight: 600; }
.track-rank { width: 18px; flex-shrink: 0; text-align: center; font-size: 12px; font-weight: 800; color: var(--text-3); }
.track-body { flex: 1; min-width: 0; }
.track-title { font-size: 12.5px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.track-artist { font-size: 11px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.track-count {
  flex-shrink: 0; font-size: 10.5px; font-weight: 700; color: var(--blue-3);
  background: rgba(47,107,255,.12); border-radius: 20px; padding: 2px 8px;
}

/* Artist chips */
.chip-cloud { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  font-size: 12px; font-weight: 600; color: var(--text);
  background: var(--surface2); border: 1px solid var(--border2);
  border-radius: 20px; padding: 5px 11px;
}
.chip b { color: var(--blue-3); margin-left: 4px; font-weight: 800; }
.chip.clickable { cursor: pointer; display: inline-flex; align-items: center; gap: 5px; transition: border-color .14s, color .14s; }
.chip.clickable:hover { border-color: var(--blue-2); color: var(--blue-2); }
.chip-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--green); flex-shrink: 0; animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

/* ── Toolbar ─────────────────────────────────────────────────── */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.tabs { display: flex; gap: 6px; background: var(--surface); border: 1px solid var(--border); border-radius: 11px; padding: 5px; }
.tab {
  background: none; border: none; color: var(--text-2);
  font-size: 13px; font-weight: 600; padding: 8px 14px;
  border-radius: 8px; cursor: pointer; transition: all .15s;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--surface3); color: var(--text); }
.filter-wrap { display: flex; align-items: center; gap: 14px; }
select#genreFilter {
  background: var(--surface2); border: 1px solid var(--border2);
  border-radius: 9px; color: var(--text-2); font-size: 13px;
  padding: 9px 14px; cursor: pointer; outline: none; max-width: 180px;
}
.count { font-size: 13px; color: var(--text-3); }

/* ── States ──────────────────────────────────────────────────── */
.state { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; padding: 80px 20px; text-align: center; color: var(--text-2); }
.spinner { width: 44px; height: 44px; border: 4px solid var(--border2); border-top-color: var(--blue-2); border-radius: 50%; animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.btn { background: var(--blue-2); color: #fff; border: none; border-radius: 9px; padding: 10px 22px; font-size: 14px; font-weight: 600; cursor: pointer; transition: background .15s; }
.btn:hover { background: #1f55e0; }

/* ── Station grid (minimal cards) ────────────────────────────── */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
/* Only long lists (e.g. All Stations) skip off-screen render work — kept off
   short/initial views so it never delays the LCP element on first load. */
.grid.virtualize .card { content-visibility: auto; contain-intrinsic-size: auto 74px; }
.card {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 13px 15px 13px 13px;
  cursor: pointer; transition: border-color .15s, background .15s, transform .12s, box-shadow .15s;
  position: relative;
  animation: rise .3s ease both;
}
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.card:hover { border-color: var(--border2); background: var(--surface2); transform: translateY(-2px); box-shadow: 0 8px 22px var(--shadow); }
.card:active { transform: scale(.99); }
.card.playing { border-color: var(--blue-2); background: rgba(47,107,255,.07); }

/* Artwork with hover/playing overlay */
.card-art { position: relative; width: 54px; height: 54px; flex-shrink: 0; border-radius: 12px; overflow: hidden; }
.card-logo {
  width: 54px; height: 54px; border-radius: 12px;
  object-fit: contain; background: #fff; padding: 4px; border: 1px solid var(--border2);
  display: flex; align-items: center; justify-content: center; font-size: 24px; color: #8a8a8e;
  transition: transform .2s ease;
}
.card:hover .card-logo { transform: scale(1.06); }
.card-ov {
  position: absolute; inset: 0; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(8,11,18,.5); opacity: 0; transition: opacity .15s;
}
.card:hover .card-ov { opacity: 1; }
.card.playing .card-ov { opacity: 1; background: rgba(8,11,18,.45); }

.card-body { flex: 1; min-width: 0; }
.card-name { font-size: 14.5px; font-weight: 700; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-sub { display: flex; align-items: center; gap: 6px; margin-top: 4px; font-size: 12px; color: var(--text-2); }
.card-sub .dot { color: var(--text-3); }
.card-pop { color: var(--text-3); }
.card-live { display: flex; align-items: center; gap: 5px; margin-top: 4px; font-size: 12px; color: var(--blue-2); font-weight: 600; min-width: 0; }
.card-live .note { flex-shrink: 0; }
.card-live span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.card-fav { font-size: 16px; color: var(--text-3); cursor: pointer; background: none; border: none; line-height: 1; flex-shrink: 0; opacity: 0; transition: color .15s, transform .1s, opacity .15s; }
.card:hover .card-fav { opacity: 1; }
.card-fav.active { color: var(--yellow); opacity: 1; }
.card-fav:hover { transform: scale(1.2); }

/* Equalizer (in the artwork overlay when playing) */
.eq { display: inline-flex; align-items: flex-end; gap: 2.5px; height: 16px; }
.eq span { width: 3px; background: #fff; border-radius: 1px; animation: eq .9s ease-in-out infinite; }
.eq span:nth-child(2){ animation-delay:.2s } .eq span:nth-child(3){ animation-delay:.4s } .eq span:nth-child(4){ animation-delay:.1s }
@keyframes eq { 0%,100%{ height:4px } 50%{ height:16px } }

/* ── For You (personalized) ──────────────────────────────────── */
.fy-section { margin-bottom: 28px; }
.fy-section:last-child { margin-bottom: 0; }
.fy-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 14px; }
.fy-title { font-size: 18px; font-weight: 800; letter-spacing: -.02em; }
.fy-note { font-size: 12.5px; color: var(--text-3); }

.resume-card {
  display: flex; align-items: center; gap: 16px;
  background: linear-gradient(135deg, rgba(10,132,255,.14), var(--surface));
  border: 1px solid var(--blue-2); border-radius: var(--radius);
  padding: 16px; margin-bottom: 28px; cursor: pointer;
  transition: transform .12s, box-shadow .15s;
}
.resume-card:hover { transform: translateY(-2px); box-shadow: 0 10px 26px var(--shadow); }
.resume-logo {
  width: 60px; height: 60px; flex-shrink: 0; border-radius: 12px; object-fit: cover;
  background: var(--surface2); border: 1px solid var(--border2);
  display: flex; align-items: center; justify-content: center; font-size: 26px; color: var(--text-3);
}
.resume-body { flex: 1; min-width: 0; }
.resume-kicker { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--blue-2); }
.resume-name { font-size: 17px; font-weight: 800; letter-spacing: -.02em; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.resume-sub { font-size: 12.5px; color: var(--text-2); margin-top: 2px; }
.resume-play {
  width: 46px; height: 46px; flex-shrink: 0; border-radius: 50%;
  background: var(--blue-2); color: #fff; border: none;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  transition: filter .15s, transform .1s;
}
.resume-play:hover { filter: brightness(1.1); }
.resume-play:active { transform: scale(.94); }

/* ── Analytics view ──────────────────────────────────────────── */
.analytics { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.a-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 18px 20px;
  animation: rise .35s ease both;
}
.a-card.wide { grid-column: 1 / -1; }
.a-card h3 { font-size: 14px; font-weight: 800; margin-bottom: 4px; }
.a-card .a-sub { font-size: 11.5px; color: var(--text-3); margin-bottom: 16px; }

/* Big stat tiles (listening stats) */
.a-stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.a-stat { background: var(--surface2); border: 1px solid var(--border); border-radius: 11px; padding: 14px; }
.a-stat .v { font-size: 24px; font-weight: 800; letter-spacing: -.02em; color: var(--stat-2); }
@supports ((-webkit-background-clip: text) or (background-clip: text)) {
  .a-stat .v { background: linear-gradient(135deg, var(--stat-1), var(--stat-2)); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
}
.a-stat .v.small { font-size: 15px; }
.a-stat .l { font-size: 10.5px; font-weight: 600; letter-spacing: .05em; color: var(--text-3); text-transform: uppercase; margin-top: 5px; }

/* Horizontal bar charts */
.bars { display: flex; flex-direction: column; gap: 9px; }
.bar-row { display: grid; grid-template-columns: 116px 1fr 44px; align-items: center; gap: 10px; }
.bar-label { font-size: 12px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-transform: capitalize; }
.bar-track { height: 9px; background: var(--surface2); border-radius: 6px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 6px; background: linear-gradient(90deg, var(--blue-2), var(--blue-3)); animation: grow .6s ease both; }
.bar-fill.alt { background: linear-gradient(90deg, #e0b400, var(--yellow)); }
.bar-fill.alt2 { background: linear-gradient(90deg, #16a34a, #4ade80); }
@keyframes grow { from { width: 0 !important; } }
.bar-val { font-size: 11.5px; font-weight: 700; color: var(--text-2); text-align: right; }

.a-empty { font-size: 12.5px; color: var(--text-3); padding: 6px 0; line-height: 1.6; }

/* Clickable bars */
.bar-row.clickable { cursor: pointer; border-radius: 7px; padding: 3px 5px; margin: -3px -5px; transition: background .14s; }
.bar-row.clickable:hover { background: var(--surface2); }
.bar-row.clickable:hover .bar-label { color: var(--blue-2); }

/* ── Drill-down modal ────────────────────────────────────────── */
.modal { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; padding: 24px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.5); backdrop-filter: blur(3px); animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; } }
.modal-panel {
  position: relative; width: 100%; max-width: 920px; max-height: 82vh;
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border2);
  border-radius: 16px; box-shadow: 0 24px 70px rgba(0,0,0,.5);
  animation: pop .2s cubic-bezier(.4,0,.2,1);
}
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.98); } }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { font-size: 15px; font-weight: 800; }
.modal-close { width: 30px; height: 30px; flex-shrink: 0; border-radius: 8px; background: var(--surface2); border: 1px solid var(--border2); color: var(--text-2); cursor: pointer; font-size: 12px; transition: background .15s, color .15s; }
.modal-close:hover { background: var(--red); color: #fff; border-color: transparent; }
.modal-body { overflow-y: auto; padding: 18px 20px; }

@media (max-width: 720px) { .analytics { grid-template-columns: 1fr; } }

/* ── Now Playing card (in sidebar) ───────────────────────────── */
.np-card {
  background: linear-gradient(160deg, rgba(47,107,255,.14), var(--surface));
  border: 1px solid var(--blue-2); border-radius: var(--radius);
  padding: 14px; display: flex; flex-direction: column; gap: 12px;
  box-shadow: 0 8px 24px rgba(47,107,255,.15);
}
.np-top { display: flex; align-items: center; gap: 12px; }
.np-meta { flex: 1; min-width: 0; }
.player-logo { width: 54px; height: 54px; flex-shrink: 0; border-radius: 12px; object-fit: contain; padding: 4px; background: #fff; border: 1px solid var(--border2); box-shadow: 0 4px 14px rgba(0,0,0,.25); display: flex; align-items: center; justify-content: center; font-size: 24px; color: #8a8a8e; overflow: hidden; }
.player-name { font-size: 14px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-status { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.player-status.live   { color: var(--green); }
.player-status.buffer { color: var(--yellow); }
.player-status.error  { color: var(--red); }
.player-track { font-size: 12.5px; color: var(--yellow); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.np-controls { display: flex; align-items: center; gap: 10px; }
.play-btn { width: 44px; height: 44px; flex-shrink: 0; border-radius: 50%; background: var(--blue-2); color: #fff; border: none; display: flex; align-items: center; justify-content: center; cursor: pointer; transition: background .15s, transform .1s; }
.play-btn:hover { background: #1f55e0; }
.play-btn:active { transform: scale(.94); }
.skip-btn { width: 36px; height: 36px; flex-shrink: 0; border-radius: 50%; background: transparent; color: var(--text-2); border: none; display: flex; align-items: center; justify-content: center; cursor: pointer; transition: background .15s, color .15s, transform .1s; }
.skip-btn:hover { background: var(--surface3); color: var(--text); }
.skip-btn:active { transform: scale(.92); }
.fav-btn { background: none; border: none; font-size: 21px; color: var(--text-3); cursor: pointer; line-height: 1; transition: color .15s, transform .1s; flex-shrink: 0; }
.fav-btn:hover { transform: scale(1.15); }
.fav-btn.active { color: var(--yellow); }
.volume-wrap { display: flex; align-items: center; gap: 9px; color: var(--text-3); flex: 1; min-width: 0; padding-right: 8px; }
.volume-wrap input[type=range] { min-width: 0; }
input[type=range] { -webkit-appearance: none; appearance: none; flex: 1; height: 4px; border-radius: 3px; background: var(--border2); outline: none; cursor: pointer; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 14px; height: 14px; border-radius: 50%; background: var(--blue-2); }

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

@media (max-width: 1080px) {
  .layout { grid-template-columns: 1fr; }
  .content { order: 1; min-width: 0; }                     /* station list first; min-width:0 stops overflow */
  .sidebar { position: static; order: 2; min-width: 0; max-height: none; overflow: visible; padding-right: 0; }

  /* Now Playing becomes a sticky bottom mini-player (Spotify-style) */
  .np-card {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 60;
    flex-direction: row; align-items: center; gap: 12px;
    border-radius: 0; border-left: 0; border-right: 0;
    /* opaque bar so the scrolling list doesn't show through */
    background: var(--surface);
    /* clear the iOS home indicator on installed PWA */
    padding: 8px calc(14px + env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) calc(14px + env(safe-area-inset-left));
    box-shadow: 0 -6px 22px var(--shadow);
  }
  .np-card .np-top { order: 1; flex: 1; min-width: 0; }
  .np-card .np-controls { order: 2; margin: 0; flex: 0 0 auto; }
  .np-card .player-track,
  .np-card .volume-wrap,
  .np-card .skip-btn,
  .np-card .np-actions,
  .np-card .sleep-menu,
  .np-card .np-history,
  .np-card .np-note { display: none; }                     /* keep the mini-player short */
  .np-card::before, .np-card::after { display: none; }     /* no blurred backdrop in the slim bar */
  .np-card .player-logo { width: 42px; height: 42px; border-radius: 9px; box-shadow: none; }
  .np-card .play-btn { width: 44px; height: 44px; }
  body.has-player { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }  /* room for the fixed player */
  /* Toast normally sits at bottom:28px, which lands inside the fixed mini-player
     bar's ~72px height on mobile/tablet — float it above the bar instead. */
  body.has-player .toast { bottom: calc(72px + env(safe-area-inset-bottom) + 14px); }

  /* Chevron to expand the mini-player into the full-screen player */
  .np-expand { display: inline-flex; }

  /* Tap the mini-player → full-screen "Now Playing" (iOS-style) */
  .np-card.expanded {
    position: fixed; inset: 0; z-index: 200;
    flex-direction: column; align-items: stretch; gap: 16px;
    max-height: none; height: 100%; overflow-y: auto;
    border: 0; border-radius: 0; box-shadow: none;
    background: linear-gradient(165deg, #0c1430 0%, #160b26 52%, #07131f 100%);
    color: #fff;
    padding: calc(14px + env(safe-area-inset-top)) 22px calc(26px + env(safe-area-inset-bottom));
  }
  /* hide the slim-bar bits while full-screen */
  .np-card.expanded .np-top,
  .np-card.expanded .player-track { display: none; }
  .np-card.expanded .np-hero { display: flex; order: 0; }

  /* transport + volume */
  .np-card.expanded .np-controls {
    order: 2; margin: 0; flex-wrap: wrap; justify-content: center; gap: 18px;
  }
  .np-card.expanded .skip-btn { display: flex; color: rgba(255,255,255,.92); }
  .np-card.expanded .skip-btn:hover { background: rgba(255,255,255,.12); color: #fff; }
  .np-card.expanded .play-btn { width: 62px; height: 62px; }
  .np-card.expanded .play-btn svg { width: 28px; height: 28px; }
  .np-card.expanded .volume-wrap { display: flex; flex: 1 0 100%; color: rgba(255,255,255,.7); padding: 0 4px; }
  .np-card.expanded input[type=range] { background: rgba(255,255,255,.25); }

  /* action chips (Share / Sleep / Report) on the dark backdrop */
  .np-card.expanded .np-actions { order: 3; display: flex; }
  .np-card.expanded .np-act {
    background: rgba(255,255,255,.1); color: #fff; border-color: rgba(255,255,255,.16);
  }
  .np-card.expanded .np-act:hover { background: rgba(255,255,255,.18); }
  .np-card.expanded .sleep-menu:not(.hidden),
  .np-card.expanded .np-history:not(.hidden),
  .np-card.expanded .np-note:not(.hidden) { display: flex; order: 4; }
  .np-card.expanded .sleep-menu button {
    background: rgba(255,255,255,.1); color: #fff; border-color: rgba(255,255,255,.16);
  }
  .np-card.expanded .np-history { background: rgba(255,255,255,.06); border-radius: 12px; }
}

/* Expand chevron — hidden on desktop (actions already shown in the sidebar card) */
.np-expand {
  display: none; align-items: center; justify-content: center;
  width: 34px; height: 34px; flex: 0 0 auto;
  background: var(--surface2); border: 1px solid var(--border); border-radius: 9px;
  color: var(--text-2); cursor: pointer;
}
.np-expand:hover { color: var(--text); background: var(--surface3); }
.np-expand svg { transition: transform .2s; }

/* ── Full-screen "Now Playing" hero (mobile, animated artwork) ── */
.np-hero { display: none; flex-direction: column; align-items: center; text-align: center; position: relative; }
.np-hero-close {
  position: absolute; top: -2px; left: -6px; background: transparent; border: 0;
  color: rgba(255,255,255,.85); cursor: pointer; padding: 6px; line-height: 0;
}
.np-hero-close:hover { color: #fff; }
.np-hero-kicker {
  font-size: 11.5px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase;
  color: rgba(255,255,255,.45); margin: 2px 0 30px;
}
.np-art {
  position: relative; width: 250px; height: 250px; max-width: 66vw; max-height: 66vw;
  display: flex; align-items: center; justify-content: center; margin-bottom: 34px;
}
.np-art-glow {
  position: absolute; inset: -22px; border-radius: 50%;
  background: conic-gradient(from 0deg, #4f8cff, #a855f7, #ec4899, #f59e0b, #4f8cff);
  filter: blur(36px); opacity: .2; transition: opacity .6s;
  animation: npspin 16s linear infinite;
}
.np-art.playing .np-art-glow { opacity: .5; }
.np-art-logo {
  position: relative; width: 100%; height: 100%; border-radius: 28px; overflow: hidden;
  background: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 86px; box-shadow: 0 20px 54px rgba(0,0,0,.5);
  transform: scale(.965); transition: transform .5s ease;
}
.np-art.playing .np-art-logo { transform: scale(1); animation: npbreathe 2.8s ease-in-out infinite; }
.np-art-logo img { width: 100%; height: 100%; object-fit: contain; opacity: 0; transition: opacity .4s; }
.np-art-logo img.ld { opacity: 1; }
.np-hero-name { font-size: 23px; font-weight: 800; color: #fff; padding: 0 12px; line-height: 1.2; }
.np-hero-status { font-size: 14px; color: rgba(255,255,255,.6); margin-top: 8px; }
.np-hero-status.live   { color: #34d399; }
.np-hero-status.buffer { color: #fbbf24; }
.np-hero-status.error  { color: #f87171; }

@keyframes npspin   { to { transform: rotate(360deg); } }
@keyframes npbreathe { 0%,100% { transform: scale(1); } 50% { transform: scale(1.045); } }

@media (prefers-reduced-motion: reduce) {
  .np-art-glow, .np-art.playing .np-art-logo { animation: none; }
}

@media (max-width: 720px) {
  header { flex-wrap: wrap; gap: 10px; padding: calc(12px + env(safe-area-inset-top)) 14px 12px; }
  .header-right { width: 100%; }
  .search-wrap { flex: 1; }
  .search-wrap input { width: 100%; }
  .layout { padding: 14px; }

  /* Toolbar stacks; tabs scroll horizontally instead of wrapping */
  .toolbar { flex-direction: column; align-items: stretch; gap: 10px; min-width: 0; }
  .tabs { flex-wrap: wrap; min-width: 0; }                  /* wrap to a 2nd row instead of overflowing */
  .tab { flex: 0 0 auto; white-space: nowrap; }
  .filter-wrap { justify-content: space-between; min-width: 0; }
  select#genreFilter { flex: 1; min-width: 0; max-width: none; }

  .modal { padding: 10px; }
  .modal-body { padding: 14px; }
  .resume-name { font-size: 15px; }

  /* Analytics: stack the side-by-side cards/charts; tighten bar rows */
  .a-card.wide .a-stats { grid-template-columns: 1fr !important; gap: 18px; }
  .bar-row { grid-template-columns: 90px 1fr 36px; gap: 8px; }
  .bar-label { font-size: 11.5px; }
  .a-stat .v.small { font-size: 14px; line-height: 1.25; }
}

/* ── New features: install, player actions, sleep, history, region, toast ── */

/* Install button */
.install-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--blue); color: #fff; border: none; cursor: pointer;
  font-size: 13px; font-weight: 600; padding: 7px 12px; border-radius: 9px;
}
.install-btn:hover { filter: brightness(1.05); }

/* Player action row (Share / Sleep / Report) */
.np-actions { display: flex; gap: 8px; margin-top: 10px; }
.np-act {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--surface2); color: var(--text-2); border: 1px solid var(--border);
  border-radius: 9px; padding: 8px 6px; font-size: 12px; font-weight: 600; cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.np-act:hover { background: var(--surface3); color: var(--text); }
.np-act.active { color: var(--blue); border-color: var(--blue); }
.np-act.danger:hover { color: var(--red); border-color: var(--red); }

/* Sleep timer menu */
.sleep-menu { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.sleep-menu button {
  flex: 1 0 18%; background: var(--surface2); color: var(--text-2);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 0;
  font-size: 12px; font-weight: 600; cursor: pointer;
}
.sleep-menu button:hover { background: var(--surface3); color: var(--text); }
.sleep-menu button.off { color: var(--text-3); }

/* Recently-played history with music links */
.np-history { margin-top: 12px; border-top: 1px solid var(--border); padding-top: 10px; }
.hist-head { font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .04em; color: var(--text-3); margin-bottom: 8px; }
.hist-row { display: flex; align-items: center; gap: 8px; padding: 5px 0; }
.hist-text { min-width: 0; flex: 1; }
.hist-text b { display: block; font-size: 13px; font-weight: 600; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hist-text span { font-size: 11px; color: var(--text-3); }
.hist-links { display: flex; gap: 4px; flex-shrink: 0; }
.hist-links a {
  font-size: 10px; font-weight: 700; color: var(--text-2); text-decoration: none;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 6px; padding: 3px 6px; line-height: 1;
}
.hist-links a:hover { background: var(--blue); color: #fff; border-color: var(--blue); }

/* Region chips */
.region-bar { display: flex; flex-wrap: wrap; gap: 8px; padding: 4px 0 14px; }
.region-chip {
  flex: 0 0 auto; background: var(--surface2); color: var(--text-2);
  border: 1px solid var(--border); border-radius: 999px; padding: 6px 13px;
  font-size: 13px; font-weight: 500; cursor: pointer; white-space: nowrap;
  transition: background .15s, color .15s;
}
.region-chip:hover { background: var(--surface3); color: var(--text); }
.region-chip.active { background: var(--blue); color: #fff; border-color: var(--blue); }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 28px;
  transform: translateX(-50%) translateY(12px);
  background: var(--text); color: var(--bg); font-size: 13px; font-weight: 600;
  padding: 11px 18px; border-radius: 11px; box-shadow: var(--shadow);
  z-index: 1000; opacity: 0; transition: opacity .25s, transform .25s; pointer-events: none;
  max-width: 86vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* "Station doesn't share song info" note */
.np-note { display: flex; align-items: center; gap: 7px; margin-top: 12px;
  padding-top: 10px; border-top: 1px solid var(--border);
  font-size: 12px; color: var(--text-3); }
.np-note svg { flex-shrink: 0; opacity: .8; }

/* ── Shimmer loading skeletons ── */
@keyframes shimmer { 0% { background-position: -300px 0; } 100% { background-position: 300px 0; } }
.shimmer, .card.skel .sk, .rank-skeleton {
  background: linear-gradient(90deg, var(--surface2) 25%, var(--surface3) 37%, var(--surface2) 63%);
  background-size: 600px 100%; animation: shimmer 1.3s infinite linear; border-radius: 6px;
}
.card.skel { pointer-events: none; animation: none; }
.card.skel .card-art { background: none; }
.card.skel .sk-logo { width: 54px; height: 54px; border-radius: 12px; flex-shrink: 0; }
.card.skel .sk-lines { flex: 1; display: flex; flex-direction: column; gap: 8px; }
.card.skel .sk-line1 { height: 12px; width: 70%; }
.card.skel .sk-line2 { height: 10px; width: 45%; }
.rank-skeleton { color: transparent !important; height: 30px; margin: 4px 0; }

/* ── Friendlier empty / error states ── */
.state .state-icon {
  width: 56px; height: 56px; color: var(--text-3); opacity: .7; margin-bottom: 2px;
}
.state .state-icon svg { width: 100%; height: 100%; }

/* ── Polish: logo fade-in + clearer "now playing" cue ── */
img.card-logo, img.rank-logo, img.resume-logo, .player-logo img {
  opacity: 0; transition: opacity .3s ease;
}
img.card-logo.ld, img.rank-logo.ld, img.resume-logo.ld, .player-logo img.ld { opacity: 1; }

.card.playing {
  box-shadow: 0 0 0 1px var(--blue-2), 0 6px 24px rgba(10,132,255,.30);
}

/* Site footer (SEO content + internal links) */
.site-footer { margin: 30px 2px 12px; padding-top: 18px; border-top: 1px solid var(--border); }
.site-footer .seo-intro { font-size: 13px; line-height: 1.6; color: var(--text-2); max-width: 760px; }
.site-footer .seo-intro strong { color: var(--text); }
.site-footer .seo-links { margin-top: 12px; font-size: 12.5px; }
.site-footer .seo-links span { color: var(--text-3); font-weight: 600; margin-right: 4px; }
.site-footer .seo-links a { display: inline-block; color: var(--text-2); text-decoration: none;
  background: var(--surface2); border: 1px solid var(--border); border-radius: 8px;
  padding: 3px 9px; margin: 0 5px 6px 0; }
.site-footer .seo-links a:hover { color: #fff; background: var(--blue); border-color: var(--blue); }
.site-footer .seo-foot { margin-top: 12px; font-size: 12px; color: var(--text-3); }
.site-footer .seo-foot a { color: var(--text-2); text-decoration: none; }
.site-footer .seo-foot a:hover { color: var(--blue); }

/* ── iOS "Add to Home Screen" instructions sheet ── */
.ios-install { position: fixed; inset: 0; z-index: 1200; display: flex; align-items: flex-end;
  justify-content: center; background: rgba(0,0,0,.5); backdrop-filter: blur(2px); }
.ios-sheet { position: relative; width: 100%; max-width: 460px; margin: 0 10px 10px;
  background: var(--surface); border: 1px solid var(--border2); border-radius: 18px;
  padding: 20px 20px 22px; box-shadow: 0 -10px 40px rgba(0,0,0,.4);
  animation: iosUp .28s cubic-bezier(.2,.7,.3,1) both; }
@keyframes iosUp { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.ios-close { position: absolute; top: 12px; right: 12px; width: 28px; height: 28px; border-radius: 50%;
  background: var(--surface2); border: none; color: var(--text-2); font-size: 13px; cursor: pointer; }
.ios-head { display: flex; align-items: center; gap: 13px; margin-bottom: 16px; padding-right: 24px; }
.ios-title { font-size: 17px; font-weight: 800; }
.ios-sub { font-size: 13px; color: var(--text-3); margin-top: 2px; }
.ios-steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 11px;
  font-size: 14px; color: var(--text); }
.ios-steps li { line-height: 1.4; }
.ios-steps strong { font-weight: 700; }
.ios-steps svg { color: var(--blue); }
