:root {
  --bg: #0a0d18;
  --panel: rgba(255, 255, 255, 0.045);
  --panel-strong: rgba(255, 255, 255, 0.07);
  --border: rgba(255, 255, 255, 0.09);
  --text: #eef0fb;
  --text-dim: #9aa0c2;
  --text-faint: #6b7194;
  --accent: #f5c451;
  --accent-dim: #a9884a;
  --accent2: #7c8cff;
  --up: #3ad07a;
  --up-bg: rgba(58, 208, 122, 0.14);
  --down: #ff5c7a;
  --down-bg: rgba(255, 92, 122, 0.14);
  --same: #8892b0;
  --same-bg: rgba(136, 146, 176, 0.14);
  --new: #4fc3f7;
  --new-bg: rgba(79, 195, 247, 0.14);
  --dropout: #ff9a5c;
  --dropout-bg: rgba(255, 154, 92, 0.14);
  --radius: 16px;
  --radius-sm: 10px;
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow-x: hidden;
}

.bg-glow {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(60vw 40vw at 12% -10%, rgba(124, 140, 255, 0.16), transparent 60%),
    radial-gradient(50vw 40vw at 100% 0%, rgba(245, 196, 81, 0.10), transparent 55%),
    radial-gradient(70vw 60vw at 50% 120%, rgba(58, 208, 122, 0.08), transparent 60%),
    var(--bg);
}

a { color: inherit; }

/* ---------- topbar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 14px 28px;
  background: rgba(10, 13, 24, 0.72);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; flex: 0 0 auto; }
.brand-logo {
  display: block;
  width: auto;
  height: 48px;
  max-width: min(236px, 24vw);
  object-fit: contain;
  filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.38));
}

.tabs { display: flex; gap: 6px; }
.tab {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-dim);
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}
.tab:hover { color: var(--text); background: var(--panel); }
.tab.active {
  color: #171100;
  background: var(--accent);
  box-shadow: 0 0 20px rgba(245, 196, 81, 0.35);
}

.search-wrap { margin-left: auto; position: relative; width: 300px; }
#search-input {
  width: 100%;
  padding: 9px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}
#search-input:focus { border-color: var(--accent2); }
#search-input::placeholder { color: var(--text-faint); }

.search-results {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 380px;
  max-height: 70vh;
  overflow-y: auto;
  background: #10152a;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 20px 50px rgba(0,0,0,0.5);
  padding: 8px;
}
.search-results.hidden { display: none; }
.sr-section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-faint);
  padding: 8px 10px 4px;
}
.sr-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.sr-item:hover { background: var(--panel-strong); }
.sr-item .sr-main { display: flex; flex-direction: column; overflow: hidden; }
.sr-item .sr-title { font-weight: 600; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sr-item .sr-sub { font-size: 12px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sr-item .sr-tag { font-size: 11px; color: var(--accent); white-space: nowrap; }
.sr-empty { padding: 14px; color: var(--text-faint); font-size: 13px; text-align: center; }

/* ---------- layout ---------- */

.app {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 24px 80px;
}

.footer {
  text-align: center;
  color: var(--text-faint);
  font-size: 12px;
  padding: 20px;
}

/* ---------- week nav ---------- */

.week-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-bottom: 28px;
}
.week-nav-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.week-nav-btn:hover:not(:disabled) { background: var(--panel-strong); border-color: var(--accent2); }
.week-nav-btn:disabled { opacity: 0.3; cursor: default; }

.week-picker { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.week-picker select {
  background: transparent;
  border: none;
  color: var(--accent);
  font-size: 22px;
  font-weight: 800;
  text-align: center;
  cursor: pointer;
  outline: none;
}
.week-picker select option { background: #10152a; color: var(--text); }
.week-date { color: var(--text-dim); font-size: 13px; }

/* ---------- stat cards ---------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}
@media (max-width: 900px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }

.stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  cursor: pointer;
  transition: transform 0.15s, background 0.15s, border-color 0.15s;
}
.stat-card:hover { transform: translateY(-2px); background: var(--panel-strong); }
.stat-card.active-filter { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.stat-card .stat-num { font-size: 28px; font-weight: 800; line-height: 1; }
.stat-card .stat-label { margin-top: 6px; font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.6px; }
.stat-card.up .stat-num { color: var(--up); }
.stat-card.down .stat-num { color: var(--down); }
.stat-card.same .stat-num { color: var(--same); }
.stat-card.new .stat-num { color: var(--new); }
.stat-card.dropout .stat-num { color: var(--dropout); }

/* ---------- spotlight ---------- */

.spotlight-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 28px;
}
@media (max-width: 700px) { .spotlight-grid { grid-template-columns: 1fr; } }

.spotlight-card {
  border-radius: var(--radius);
  padding: 20px;
  border: 1px solid var(--border);
  position: relative;
  overflow: hidden;
}
.spotlight-card.climber { background: linear-gradient(135deg, rgba(58,208,122,0.16), rgba(58,208,122,0.03)); }
.spotlight-card.faller { background: linear-gradient(135deg, rgba(255,92,122,0.16), rgba(255,92,122,0.03)); }
.spotlight-label { font-size: 11px; text-transform: uppercase; letter-spacing: 1.2px; color: var(--text-dim); margin-bottom: 10px; }
.spotlight-title { font-size: 19px; font-weight: 800; margin-bottom: 2px; }
.spotlight-artist { font-size: 14px; color: var(--text-dim); margin-bottom: 14px; }
.spotlight-move { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 10px; font-weight: 800; font-size: 15px; }
.spotlight-move .pos-badge { font-size: 22px; }
.spotlight-empty { color: var(--text-faint); font-size: 14px; }

/* ---------- position badges & movement ---------- */

.pos-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 34px;
  padding: 0 6px;
  border-radius: 10px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  background: var(--panel-strong);
  border: 1px solid var(--border);
}
.pos-badge.p1 { background: linear-gradient(135deg, var(--accent), #ffe08a); color: #241a00; border-color: transparent; box-shadow: 0 0 16px rgba(245,196,81,0.45); }

.move {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12.5px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.move.up { color: var(--up); background: var(--up-bg); }
.move.down { color: var(--down); background: var(--down-bg); }
.move.same { color: var(--same); background: var(--same-bg); }
.move.new { color: var(--new); background: var(--new-bg); }

/* ---------- table ---------- */

.section-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-dim);
  margin: 30px 0 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.section-title .count-pill {
  background: var(--panel-strong);
  color: var(--text);
  padding: 1px 9px;
  border-radius: 999px;
  font-size: 11px;
}

.chart-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.chart-table thead th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-faint);
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
}
.chart-table thead th:hover { color: var(--text); }
.chart-table tbody tr {
  border-bottom: 1px solid rgba(255,255,255,0.04);
  transition: background 0.1s;
}
.chart-table tbody tr:last-child { border-bottom: none; }
.chart-table tbody tr:hover { background: var(--panel-strong); }
.chart-table tbody tr.filter-hidden { display: none; }
.chart-table td { padding: 10px 14px; font-size: 14px; vertical-align: middle; }
.chart-table td.title-cell { font-weight: 700; }
.chart-table td.artist-cell { color: var(--text-dim); }
.chart-table td.woc-cell { color: var(--text-faint); font-size: 12.5px; }
.title-cell .row-title-link { cursor: pointer; }
.title-cell .row-title-link:hover { text-decoration: underline; }
.artist-cell .row-artist-link { cursor: pointer; }
.artist-cell .row-artist-link:hover { text-decoration: underline; color: var(--text); }

.song-with-spotify { display: inline-flex; align-items: center; gap: 6px; min-width: 0; max-width: 100%; }
.song-with-spotify .row-title-link { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spotify-link {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  opacity: 0.55;
  transition: opacity 0.15s, transform 0.15s;
}
.spotify-link:hover { opacity: 1; transform: scale(1.12); }
.spotify-link svg { display: block; width: 14px; height: 14px; }
.as-title .spotify-link { margin-left: 8px; vertical-align: -3px; }

.spotify-fallback {
  position: fixed;
  z-index: 50;
  right: 20px;
  bottom: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: calc(100vw - 32px);
  padding: 11px 10px 11px 14px;
  border: 1px solid rgba(29, 185, 84, 0.45);
  border-radius: var(--radius-sm);
  background: rgba(14, 23, 20, 0.96);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
  color: var(--text);
  font-size: 13px;
}
.spotify-fallback a {
  color: #fff;
  background: #1db954;
  border-radius: 999px;
  padding: 6px 10px;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}
.spotify-fallback-close {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 21px;
  line-height: 1;
  padding: 1px 2px;
}

.dropout-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.dropout-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--dropout-bg);
  border: 1px solid rgba(255,154,92,0.25);
  color: var(--text);
  padding: 7px 12px;
  border-radius: 999px;
  font-size: 13px;
}
.dropout-chip .dc-pos { color: var(--dropout); font-weight: 800; }
.dropout-chip .dc-artist { color: var(--text-dim); }

/* ---------- facts page ---------- */

.facts-intro { color: var(--text-dim); margin-bottom: 24px; font-size: 14.5px; }

.facts-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}
@media (max-width: 800px) { .facts-grid { grid-template-columns: 1fr; } }

.fact-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}
.fact-card h3 {
  margin: 0 0 4px;
  font-size: 15px;
  color: var(--accent);
}
.fact-card .fact-hint { font-size: 12px; color: var(--text-faint); margin-bottom: 12px; }
.fact-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  padding: 7px 0;
  border-top: 1px solid rgba(255,255,255,0.05);
  font-size: 13.5px;
}
.fact-row:first-of-type { border-top: none; }
.fact-row .fr-main { display: flex; flex-direction: column; overflow: hidden; }
.fact-row .fr-title { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fact-row .fr-artist { color: var(--text-dim); font-size: 12px; }
.fact-row .fr-value-wrap { display: flex; flex-direction: column; align-items: flex-end; text-align: right; flex-shrink: 0; }
.fact-row .fr-value { color: var(--accent); font-weight: 800; white-space: nowrap; }
.fact-row .fr-sub { color: var(--text-faint); font-size: 11px; white-space: nowrap; margin-top: 1px; }

/* ---------- artist page ---------- */

.artist-header { margin-bottom: 20px; }
.artist-header h1 { margin: 0 0 6px; font-size: 26px; }
.artist-meta { color: var(--text-dim); font-size: 14px; }
.artist-song {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 10px;
}
.artist-song-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 4px; flex-wrap: wrap; }
.artist-song-head .as-title { font-weight: 800; font-size: 15px; }
.artist-song-head .as-peak { font-size: 12.5px; color: var(--text-dim); white-space: nowrap; }
.as-dates { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; color: var(--text-faint); margin-bottom: 8px; }
.as-dates .as-no1 { color: var(--accent); }
.sparkline { width: 100%; height: 46px; display: block; }

/* ---------- utility ---------- */

.loading, .empty-state {
  text-align: center;
  color: var(--text-faint);
  padding: 60px 20px;
  font-size: 14px;
}
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-dim);
  font-size: 13px;
  margin-bottom: 16px;
  cursor: pointer;
}
.back-link:hover { color: var(--text); }

/* ==================================================================
   RESPONSIVE — tablet and phone
   ================================================================== */

/* Tablet: tighten spacing, keep single-row topbar */
@media (max-width: 900px) {
  .app { padding: 22px 18px 60px; }
  .topbar { padding: 12px 18px; gap: 14px; }
  .search-wrap { width: 220px; }
}

/* Phone: stacked topbar, card-style chart rows, single-column facts */
@media (max-width: 640px) {
  html { font-size: 15px; }

  .topbar {
    flex-wrap: wrap;
    padding: 10px 14px;
    gap: 8px 12px;
  }
  .brand { order: 1; }
  .brand-logo { height: 38px; max-width: 150px; }
  .search-wrap { order: 2; width: auto; flex: 1 1 auto; min-width: 0; margin-left: 0; }
  .tabs { order: 3; width: 100%; justify-content: center; }
  .search-results { width: min(380px, calc(100vw - 28px)); right: 0; }
  .spotify-fallback { right: 12px; bottom: 12px; gap: 8px; }

  .app { padding: 18px 12px 60px; }

  .week-nav { gap: 8px; margin-bottom: 20px; }
  .week-picker select { font-size: 19px; }
  .week-nav-btn { width: 34px; height: 34px; }

  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stat-card { padding: 12px 8px; }
  .stat-card .stat-num { font-size: 22px; }
  .stat-card .stat-label { font-size: 10.5px; }

  .spotlight-card { padding: 14px; }
  .spotlight-title { font-size: 17px; }

  /* Chart table becomes a card list: no header row, each entry a 2-line grid */
  .chart-table thead { display: none; }
  .chart-table, .chart-table tbody { display: block; width: 100%; }
  .chart-table tr {
    display: grid;
    grid-template-columns: auto 1fr auto;
    grid-template-areas:
      "pos title move"
      "pos artist weeks";
    align-items: center;
    column-gap: 10px;
    row-gap: 3px;
    padding: 10px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  }
  .chart-table tbody tr:last-child { border-bottom: none; }
  .chart-table td { padding: 0; border: none; font-size: 13.5px; min-width: 0; }
  .chart-table td:nth-child(1) { grid-area: pos; }
  .chart-table td:nth-child(2) { grid-area: move; justify-self: end; }
  .chart-table td:nth-child(3) { grid-area: title; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .chart-table td:nth-child(4) { grid-area: artist; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .chart-table td:nth-child(5) { grid-area: weeks; justify-self: end; font-size: 11px; }

  .facts-grid { gap: 12px; }
  .fact-card { padding: 14px 16px; }

  .fact-row { flex-wrap: wrap; }
  .fact-row .fr-title { white-space: normal; }
  .fact-row .fr-value-wrap { align-items: flex-start; text-align: left; }

  .artist-header h1 { font-size: 22px; }
  .artist-song { padding: 12px 14px; }
}

@media (max-width: 380px) {
  .brand-logo { height: 33px; max-width: 128px; }
  .tab { padding: 7px 12px; font-size: 13px; }
}
