/* ══════════════════════════════════════════
   DESIGN TOKENS
══════════════════════════════════════════ */
:root {
  --bg: #06060e;
  --bg2: #0d0d1a;
  --bg3: #13132b;
  --surface: rgba(255, 255, 255, 0.04);
  --border: rgba(255, 255, 255, 0.08);
  --border2: rgba(255, 255, 255, 0.14);

  --accent: #a259ff;
  --accent2: #ff59a2;
  --accent3: #59c8ff;
  --gold: #ffd166;
  --green: #4ade80;

  --text: #f0f0ff;
  --text2: #9898bb;
  --text3: #4444aa;

  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 8px 32px rgba(0, 0, 0, .5);
}

/* ══════════════════════════════════════════
   RESET & BASE
══════════════════════════════════════════ */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', -apple-system, system-ui, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  overflow-x: hidden;
}

/* Ambient mesh background */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse at 20% 20%, rgba(162, 89, 255, .12) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 80%, rgba(255, 89, 162, .09) 0%, transparent 50%),
    radial-gradient(ellipse at 60% 10%, rgba(89, 200, 255, .07) 0%, transparent 45%);
  pointer-events: none;
  z-index: 0;
}

/* ══════════════════════════════════════════
   HEADER
══════════════════════════════════════════ */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(6, 6, 14, .88);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 16px;
  height: 62px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.logo-icon {
  width: 34px;
  height: 34px;
  background: linear-gradient(135deg, #a259ff, #ff59a2);
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  box-shadow: 0 4px 14px rgba(162, 89, 255, .4);
}

.logo-text {
  font-size: 17px;
  font-weight: 800;
  background: linear-gradient(135deg, #a259ff, #ff59a2);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -.3px;
}

.nav {
  display: flex;
  gap: 6px;
  flex: 1;
}

.nav-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text2);
  padding: 7px 16px;
  border-radius: 40px;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  font-family: inherit;
  transition: all .2s;
  white-space: nowrap;
}

.nav-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.nav-btn.active {
  background: linear-gradient(135deg, #a259ff, #ff59a2);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 3px 14px rgba(162, 89, 255, .35);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.search-input {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 15px;
  border-radius: 40px;
  width: 230px;
  font-size: 13.5px;
  font-family: inherit;
  transition: all .2s;
  outline: none;
}

.search-input::placeholder {
  color: var(--text3);
}

.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(162, 89, 255, .12);
}

.refresh-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text2);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 17px;
  font-family: inherit;
  transition: all .25s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.refresh-btn:hover {
  border-color: var(--accent3);
  color: var(--accent3);
  transform: rotate(90deg);
}

/* ══════════════════════════════════════════
   MAIN
══════════════════════════════════════════ */
.main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 36px 24px 60px;
  position: relative;
  z-index: 1;
}

/* .view display is controlled by inline style, NOT by CSS class */
.view {}

.view.hidden {}

.hidden {
  display: none !important;
}

.section-header {
  margin-bottom: 24px;
}

.section-title {
  font-size: 24px;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 4px;
}

.section-sub {
  font-size: 13.5px;
  color: var(--text2);
}

.updated-label {
  font-size: 12px;
  color: var(--text3);
  margin-top: 4px;
}

/* ══════════════════════════════════════════
   SONG GRID & CARD  (Overlay style)
══════════════════════════════════════════ */
.song-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

@media (max-width:960px) {
  .song-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width:560px) {
  .song-grid {
    grid-template-columns: 1fr;
  }
}

/* The card is a pure overlay card — thumbnail fills it, text overlays bottom */
.song-card {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg3);
  transition: transform .28s cubic-bezier(.22, .68, 0, 1.2), box-shadow .28s, border-color .2s;
  aspect-ratio: 16/9;
  /* Card itself is 16:9 — thumbnail fills it */
}

.song-card:hover {
  transform: translateY(-5px) scale(1.015);
  border-color: var(--accent);
  box-shadow: 0 14px 40px rgba(162, 89, 255, .22);
}

.song-card.is-local {
  border-color: rgba(74, 222, 128, .3);
}

.song-card.is-local:hover {
  border-color: var(--green);
  box-shadow: 0 14px 40px rgba(74, 222, 128, .18);
}

/* Thumbnail fills the entire card */
.song-thumb {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Dark gradient overlay from bottom */
.song-card::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom,
      rgba(0, 0, 0, 0) 20%,
      rgba(0, 0, 0, .5) 60%,
      rgba(0, 0, 0, .88) 100%);
  pointer-events: none;
}

/* Text overlay sits above the gradient */
.song-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 10px 12px 42px;
  z-index: 2;
}

.song-title {
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
  text-shadow: 0 1px 4px rgba(0, 0, 0, .6);
}

.song-artist {
  font-size: 11px;
  color: rgba(255, 255, 255, .7);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, .5);
}

/* Play button floats at bottom of overlay */
.song-actions {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 2;
  padding: 0 10px 10px;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity .2s ease, transform .2s ease;
}

.song-card:hover .song-actions {
  opacity: 1;
  transform: translateY(0);
}

.btn-play {
  width: 100%;
  background: linear-gradient(135deg, #a259ff, #ff59a2);
  border: none;
  color: #fff;
  padding: 6px 0;
  border-radius: var(--radius-sm);
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: opacity .2s;
  backdrop-filter: blur(4px);
}

.btn-play:hover {
  opacity: .85;
}

/* Rank badge */
.song-rank {
  position: absolute;
  top: 8px;
  left: 8px;
  background: linear-gradient(135deg, #a259ff, #ff59a2);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 20px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .5);
  min-width: 24px;
  text-align: center;
  z-index: 3;
}

.song-rank.top3 {
  background: linear-gradient(135deg, #ffd166, #ffaa00);
  color: #000;
  box-shadow: 0 2px 10px rgba(255, 209, 102, .5);
}

/* Local badge */
.local-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(74, 222, 128, .9);
  color: #000;
  font-size: 9px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 20px;
  z-index: 3;
  backdrop-filter: blur(4px);
}

/* OLD info/actions sections no longer used but kept for safety */
.song-info {
  display: none;
}


/* ══════════════════════════════════════════
   REGION TABS
══════════════════════════════════════════ */
.region-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 24px;
}

.region-tab {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text2);
  padding: 8px 18px;
  border-radius: 40px;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  font-family: inherit;
  transition: all .2s;
}

.region-tab:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.region-tab.active {
  background: linear-gradient(135deg, #a259ff, #ff59a2);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 3px 12px rgba(162, 89, 255, .3);
}

/* ══════════════════════════════════════════
   COUNTRY GRID
══════════════════════════════════════════ */
.country-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 12px;
}

.country-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 14px;
  cursor: pointer;
  transition: all .28s;
  display: flex;
  align-items: center;
  gap: 12px;
}

.country-card:hover {
  border-color: var(--accent2);
  transform: translateY(-3px);
  box-shadow: 0 8px 22px rgba(255, 89, 162, .14);
}

/* Fix #5: flag image */
.country-flag-img {
  width: 32px;
  height: 24px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
  /* Đừng để cờ bị méo nhỏ lại */
}

.country-info {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.country-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-color);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.country-topsong {
  font-size: 11px;
  color: var(--text2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

/* ── Local filter toggle ── */
.view-toggle {
  display: flex;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
}

.toggle-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text2);
  font-size: 12px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 7px;
  transition: .15s;
  white-space: nowrap;
}

.toggle-btn.active {
  background: var(--gradient);
  color: #fff;
  box-shadow: 0 2px 8px rgba(255, 35, 72, .3);
}

.toggle-btn:not(.active):hover {
  color: var(--text-color);
}

/* ── Song duration badge (bottom-right of thumbnail) ── */
.song-duration-badge {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: rgba(0, 0, 0, .75);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  pointer-events: none;
}


/* ══════════════════════════════════════════
   COUNTRY SONGS HEADER
══════════════════════════════════════════ */
.country-songs-header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
  margin-bottom: 20px;
}

.back-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text2);
  padding: 8px 16px;
  border-radius: 40px;
  cursor: pointer;
  font-size: 13.5px;
  font-family: inherit;
  font-weight: 500;
  transition: all .2s;
}

.back-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.selected-title-group {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
}

.selected-flag-img {
  width: 48px;
  height: 36px;
  object-fit: cover;
  border-radius: 5px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .4);
}

.count-badge {
  background: linear-gradient(135deg, #a259ff, #ff59a2);
  color: #fff;
  padding: 4px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

/* Legend */
.legend-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 18px;
  font-size: 12.5px;
  color: var(--text2);
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 5px;
}

.legend-dot.local {
  background: var(--green);
}

.legend-dot.global {
  background: var(--accent);
}

/* ══════════════════════════════════════════
   PAGINATION
══════════════════════════════════════════ */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 32px;
}

.page-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text2);
  min-width: 36px;
  height: 36px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13.5px;
  font-family: inherit;
  font-weight: 500;
  transition: all .2s;
}

.page-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.page-btn.active {
  background: linear-gradient(135deg, #a259ff, #ff59a2);
  border-color: transparent;
  color: #fff;
}

.page-btn:disabled {
  opacity: .3;
  cursor: default;
  pointer-events: none;
}

.page-info {
  color: var(--text2);
  font-size: 12.5px;
  padding: 0 6px;
}

/* ══════════════════════════════════════════
   LOADING / ERROR
══════════════════════════════════════════ */
.loading-state,
.error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 70px 24px;
  gap: 14px;
  color: var(--text2);
  text-align: center;
  font-size: 14px;
}

.error-state {
  color: #ff6b6b;
}

.spinner {
  width: 38px;
  height: 38px;
  border: 3px solid var(--border2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .75s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ══════════════════════════════════════════
   TOAST
══════════════════════════════════════════ */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 999;
  background: var(--bg3);
  border: 1px solid var(--border2);
  color: var(--text);
  padding: 11px 20px;
  border-radius: var(--radius);
  font-size: 13.5px;
  box-shadow: var(--shadow);
  animation: slideUp .25s ease;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(16px)
  }

  to {
    opacity: 1;
    transform: none
  }
}

/* ══════════════════════════════════════════
   FOOTER
══════════════════════════════════════════ */
.footer {
  text-align: center;
  padding: 22px;
  color: var(--text3);
  font-size: 12.5px;
  border-top: 1px solid var(--border);
  position: relative;
  z-index: 1;
}

.footer a {
  color: var(--accent);
  text-decoration: none;
}

.footer a:hover {
  text-decoration: underline;
}

/* ══════════════════════════════════════════
   RESPONSIVE
══════════════════════════════════════════ */
@media (max-width:768px) {
  .header-inner {
    flex-wrap: wrap;
    height: auto;
    padding: 10px 0;
    gap: 10px;
  }

  .nav {
    order: 3;
    width: 100%;
  }

  .search-input {
    width: 100%;
  }

  .header-right {
    width: 100%;
  }

  .song-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .main {
    padding: 20px 14px 48px;
  }

  .section-title {
    font-size: 20px;
  }
}
