:root {
  /* --- LIGHT THEME (Default) --- */
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --bg-gradient: linear-gradient(135deg, #f0f4ff, #e0eaff);

  --text-main: #1e293b;
  --text-sub: #64748b;

  --card-bg: rgba(255, 255, 255, 0.65);
  --card-hover-bg: #ffffff;
  --card-border: rgba(255, 255, 255, 0.8);

  --glass-bg: rgba(255, 255, 255, 0.85); /* Player background */
  --header-bg: rgba(240, 244, 255, 0.85);

  --input-bg: rgba(255, 255, 255, 0.6);
  --input-focus-bg: #ffffff;

  --shadow-soft: 0 4px 20px rgba(0, 0, 0, 0.03);
  --shadow-hover: 0 12px 30px rgba(37, 99, 235, 0.1);
  --glow-primary: 0 4px 14px rgba(37, 99, 235, 0.3);

  --scrollbar-thumb: #cbd5e1;
  --scrollbar-track: transparent;
}

/* --- DARK THEME OVERRIDES --- */
[data-theme="dark"] {
  --primary: #60a5fa; /* Lighter blue for dark mode */
  --primary-hover: #93c5fd;
  --bg-gradient: linear-gradient(135deg, #0f172a, #1e293b);

  --text-main: #f1f5f9;
  --text-sub: #94a3b8;

  --card-bg: rgba(30, 41, 59, 0.6);
  --card-hover-bg: rgba(51, 65, 85, 0.8);
  --card-border: rgba(255, 255, 255, 0.08);

  --glass-bg: rgba(15, 23, 42, 0.9);
  --header-bg: rgba(15, 23, 42, 0.85);

  --input-bg: rgba(30, 41, 59, 0.6);
  --input-focus-bg: rgba(30, 41, 59, 1);

  --shadow-soft: 0 4px 20px rgba(0, 0, 0, 0.2);
  --shadow-hover: 0 12px 30px rgba(0, 0, 0, 0.4);
  --glow-primary: 0 4px 14px rgba(96, 165, 250, 0.2);

  --scrollbar-thumb: #475569;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: "Inter", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 8px;
}
::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
}
::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--primary);
}

body {
  background: var(--bg-gradient);
  background-attachment: fixed;
  color: var(--text-main);
  min-height: 100vh;
  padding-bottom: 160px; /* Space for player */
  transition: background 0.3s ease, color 0.3s ease;
}

.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 40px 24px;
}

/* --- HEADER & SEARCH --- */
.header-section {
  margin-bottom: 30px;
  position: sticky;
  top: 20px;
  z-index: 50;
  background: var(--header-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 16px 20px;
  border-radius: 24px;
  border: 1px solid var(--card-border);
  box-shadow: var(--shadow-soft);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  transition: background 0.3s ease, border-color 0.3s ease;
}

h1 {
  font-size: 24px;
  font-weight: 800;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 10px;
  letter-spacing: -0.5px;
  margin: 0;
}
h1 span {
  color: var(--primary);
}

.controls-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-grow: 1;
  justify-content: flex-end;
}

.search-wrapper {
  position: relative;
  flex-grow: 1;
  max-width: 400px;
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-sub);
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: 12px 16px 12px 42px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: var(--input-bg);
  font-size: 14px;
  color: var(--text-main);
  outline: none;
  transition: all 0.2s ease;
}

.search-input:focus {
  background: var(--input-focus-bg);
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Theme Toggle Button */
.theme-toggle {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 1px solid var(--card-border);
  background: var(--input-bg);
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}
.theme-toggle:hover {
  background: var(--card-hover-bg);
  transform: scale(1.05);
}

.song-count {
  font-size: 12px;
  color: var(--text-sub);
  font-weight: 600;
  background: rgba(128, 128, 128, 0.1);
  padding: 4px 10px;
  border-radius: 20px;
  white-space: nowrap;
}

/* --- RESPONSIVE GRID --- */
.songs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 20px;
  animation: fadeIn 0.5s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* --- SONG CARD --- */
.song {
  background: var(--card-bg);
  padding: 14px;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.2s ease;
  border: 1px solid var(--card-border);
  box-shadow: var(--shadow-soft);
  position: relative;
  overflow: hidden;
}

@media (hover: hover) {
  .song:hover {
    transform: translateY(-6px);
    box-shadow: var(--shadow-hover);
    background: var(--card-hover-bg);
    border-color: var(--primary);
  }
}

.song.active {
  border: 2px solid var(--primary);
  background: var(--card-hover-bg);
  box-shadow: var(--glow-primary);
}

.song-img {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 14px;
  overflow: hidden;
  margin-bottom: 12px;
  background: rgba(128, 128, 128, 0.1);
  position: relative;
}

.song-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.song:hover .song-img img {
  transform: scale(1.08);
}

/* Play overlay on hover */
.play-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s;
}
.song:hover .play-overlay {
  opacity: 1;
}

.mini-play-btn {
  width: 44px;
  height: 44px;
  background: var(--primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
  color: white;
}

.song-title {
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 3px;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.song-artist {
  font-size: 13px;
  color: var(--text-sub);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
}

/* Empty State */
.no-results {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 20px;
  color: var(--text-sub);
  display: none;
}

/* --- PLAYER BAR --- */
.player-container {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  width: 95%;
  max-width: 950px;
  background: var(--glass-bg);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border: 1px solid var(--card-border);
  border-radius: 24px;
  padding: 16px 32px;
  display: grid;
  grid-template-columns: 1fr 2fr 1fr;
  align-items: center;
  gap: 24px;
  box-shadow: 0 20px 50px -12px rgba(0, 0, 0, 0.2);
  z-index: 1000;
  transition: transform 0.4s cubic-bezier(0.33, 1, 0.68, 1);
}

.player-container.hidden {
  transform: translate(-50%, 180%);
}

/* Left: Song Info */
.player-left {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}
.player-art {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  overflow: hidden;
  flex-shrink: 0;
  background: rgba(128, 128, 128, 0.2);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
  transition: transform 0.3s ease;
}
.player-art img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.player-art.playing {
  transform: scale(1.05);
}
.player-info {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
}
.p-title {
  font-weight: 700;
  font-size: 15px;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.p-artist {
  font-size: 13px;
  color: var(--text-sub);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Center: Controls */
.player-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.controls {
  display: flex;
  align-items: center;
  gap: 28px;
}
.btn-control {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-sub);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}
.btn-control:hover {
  color: var(--primary);
  transform: scale(1.1);
}

.btn-play {
  width: 52px;
  height: 52px;
  background: var(--primary);
  border-radius: 50%;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--glow-primary);
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.btn-play:hover {
  background: var(--primary-hover);
  transform: scale(1.08);
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.4);
}
.btn-play:active {
  transform: scale(0.95);
}
.btn-play svg {
  width: 24px;
  height: 24px;
  fill: white;
}

/* Progress Bar */
.progress-wrapper {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 12px;
  color: var(--text-sub);
  font-family: "Inter", monospace;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.progress-bar-container {
  flex-grow: 1;
  height: 20px;
  display: flex;
  align-items: center;
  cursor: pointer;
  position: relative;
}
.progress-track {
  width: 100%;
  height: 4px;
  background: rgba(128, 128, 128, 0.2);
  border-radius: 4px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--primary);
  width: 0%;
  border-radius: 4px;
  transition: width 0.1s linear;
}
input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 100%;
  background: transparent;
  position: absolute;
  top: 0;
  left: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 2;
}
.progress-thumb {
  width: 12px;
  height: 12px;
  background: var(--primary);
  border-radius: 50%;
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%) scale(0);
  left: 0%;
  z-index: 1;
  pointer-events: none;
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  transition: transform 0.2s ease, left 0.1s linear;
}
.progress-bar-container:hover .progress-thumb {
  transform: translate(-50%, -50%) scale(1);
}

/* Right: Volume */
.player-right {
  display: flex;
  justify-content: flex-end;
  align-items: center;
}
.volume-container {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px;
  border-radius: 20px;
  transition: background 0.2s;
}
.volume-container:hover {
  background: rgba(128, 128, 128, 0.1);
}
.volume-icon {
  color: var(--text-sub);
  cursor: pointer;
}
.volume-slider {
  width: 0;
  overflow: hidden;
  transition: width 0.3s ease;
  display: flex;
  align-items: center;
}
.volume-container:hover .volume-slider {
  width: 80px;
}
.volume-slider input {
  opacity: 1;
  position: static;
  height: 4px;
  background: var(--text-sub);
  border-radius: 4px;
}
.volume-slider input::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 10px;
  height: 10px;
  background: var(--primary);
  border-radius: 50%;
}

/* Mobile */
@media (max-width: 768px) {
  .player-container {
    display: flex;
    justify-content: space-between;
    bottom: 12px;
    padding: 10px 16px;
    width: 94%;
    gap: 12px;
  }
  .player-right {
    display: none;
  }
  .player-left {
    flex: 1;
    margin-right: 10px;
  }
  .player-art {
    width: 44px;
    height: 44px;
  }
  .p-title {
    font-size: 14px;
  }
  .p-artist {
    font-size: 12px;
  }
  .player-center {
    width: auto;
    align-items: flex-end;
    gap: 0;
  }
  .controls {
    gap: 16px;
  }
  .btn-control svg {
    width: 22px;
    height: 22px;
  }
  .btn-play {
    width: 40px;
    height: 40px;
  }
  .btn-play svg {
    width: 18px;
    height: 18px;
  }
  .progress-wrapper {
    position: absolute;
    top: -2px;
    left: 0;
    width: 100%;
    gap: 0;
    padding: 0 16px;
  }
  .progress-bar-container {
    height: 6px;
  }
  .progress-track {
    height: 3px;
    background: rgba(0, 0, 0, 0.1);
  }
  .progress-thumb {
    display: none;
  }
  #curr-time,
  #dur-time {
    display: none;
  }
}

@media (max-width: 480px) {
  .songs {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }
  .header-section {
    flex-direction: column;
    align-items: stretch;
    top: 0;
    border-radius: 0 0 24px 24px;
    margin-top: -40px;
    padding-top: 50px;
  }
  .controls-right {
    justify-content: space-between;
    width: 100%;
  }
  .search-wrapper {
    max-width: 100%;
  }
}
