:root {
  --bg: #f7f9fb;
  --card: #ffffff;
  --muted: #7b8a93;
  --accent: #2dd4bf;
  --accent-2: #2563eb;
  --danger: #ff5a5f;
  --glass: rgba(255,255,255,0.6);
  --shadow: 0 6px 18px rgba(19,24,31,0.08);
  --radius: 12px;
  --smooth: 200ms;
  font-family: Inter, "Segoe UI", Roboto, Arial, sans-serif;
}

body {
  background: var(--bg);
  margin: 0;
  color: #122;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.music-page {
  max-width: 1100px;
  margin: 60px auto 36px auto;
  padding: 16px;
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 32px;
}

@media (max-width: 900px) {
  .music-page {
    grid-template-columns: 1fr;
    gap: 24px;
  }
}

.controls-card,
.queue-card,
.player-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  transition: transform var(--smooth), box-shadow var(--smooth);
  margin-bottom: 24px;
}

.controls-card:hover,
.queue-card:hover {
  transform: translateY(-4px);
}

.form-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}

.form-row.small {
  gap: 10px;
  align-items: flex-start;
}

label {
  font-size: 13px;
  color: var(--muted);
}

.custom-select {
  position: relative;
  width: 100%;
  max-width: 100%; /* Ensure it doesn't exceed parent width */
}

.select-trigger {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(2, 6, 23, 0.06);
  background: #fbfdff;
  font-size: 14px;
  cursor: pointer;
  transition: box-shadow var(--smooth), border-color var(--smooth);
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #122;
  box-sizing: border-box; /* Include padding and border in width */
}

.select-trigger::after {
  content: '\f078';
  font-family: 'Font Awesome 6 Free';
  font-weight: 900;
  color: var(--muted);
  font-size: 12px;
}

.select-trigger:focus,
.select-trigger:hover {
  box-shadow: 0 6px 18px rgba(37, 99, 235, 0.08);
  border-color: rgba(37, 99, 235, 0.22);
}

.select-options {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  width: 100%; /* Match the width of the trigger */
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 100;
  max-height: 300px;
  overflow-y: auto;
  margin-top: 4px;
  padding: 8px 0;
  opacity: 0;
  transform: scale(0.95);
  transition: opacity var(--smooth), transform var(--smooth);
  box-sizing: border-box; /* Ensure padding doesn't cause overflow */
}

.select-options[style*="display: block"] {
  opacity: 1;
  transform: scale(1);
}

.optgroup {
  padding: 8px 12px;
}

.optgroup::before {
  content: attr(data-label);
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
  font-weight: 600;
}

.option {
  padding: 8px 12px;
  font-size: 14px;
  color: #122;
  cursor: pointer;
  transition: background var(--smooth);
  white-space: nowrap; /* Prevent text wrapping to avoid width issues */
  overflow: hidden;
  text-overflow: ellipsis; /* Handle long text gracefully */
}

.option:hover,
.option:focus {
  background: rgba(37, 99, 235, 0.08);
}

.btn-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 6px;
}

.btn {
  padding: 10px 14px;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  transition: transform var(--smooth), box-shadow var(--smooth), opacity var(--smooth);
}

.btn.primary {
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  color: white;
  box-shadow: 0 6px 18px rgba(37, 99, 235, 0.12);
}

.btn.secondary {
  background: linear-gradient(90deg, cornflowerblue, #1d4ed8);
  color: white;
  box-shadow: 0 6px 18px rgba(37, 99, 235, 0.12);
}

.btn.ghost {
  background: transparent;
  color: var(--accent-2);
  border: 1px solid rgba(37, 99, 235, 0.08);
}

.btn:hover {
  opacity: 0.9;
  transform: translateY(-2px);
}

.btn:active {
  transform: translateY(1px) scale(0.995);
}

.queue-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.queue-list {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 420px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.queue-list li {
  padding: 10px;
  border-radius: 10px;
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(180deg, rgba(2, 6, 23, 0.01), transparent);
  font-size: 14px;
  color: #113;
  box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.02);
  opacity: 0;
  transform: translateY(6px);
  animation: fadeInUp 240ms forwards;
}

.queue-list li.empty {
  text-align: center;
  color: var(--muted);
  padding: 22px;
  opacity: 1;
  transform: none;
  animation: none;
}

.icon-btn,
.remove-queue,
.play-now-queue {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-btn.hidden {
  display: none;
}

.remove-queue {
  background: linear-gradient(90deg, #ff7a7a, #ff4f4f);
  color: white;
}

.play-now-queue {
  background: linear-gradient(90deg, #4f6bff, #1d4ed8);
  color: white;
  margin-right: 8px;
}

.queue-item-content {
  flex: 1;
  text-align: left;
  padding-right: 10px;
  font-size: 14px;
  color: #122;
  word-break: break-word;
}

.player-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: relative;
}

.player-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.player-top .left {
  display: flex;
  gap: 12px;
  align-items: center;
  overflow: hidden;
  max-width: 100%;
}

.cover-faux {
  width: 64px;
  height: 64px;
  background: linear-gradient(180deg, rgba(2, 6, 23, 0.03), transparent);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  color: var(--accent-2);
}

.meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.title-download {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
}

.music-name {
  flex: 1;
  white-space: normal;
  word-break: break-word;
  overflow: hidden;
}

.download-icon {
  flex-shrink: 0;
  cursor: pointer;
}

.music-name.scrollable::after {
  content: attr(data-text);
  position: absolute;
  left: 100%;
  padding-left: 40px;
  white-space: nowrap;
  animation: marquee-continuous 14s linear infinite;
}

@keyframes marquee-continuous {
  0% { transform: translateX(0%); }
  100% { transform: translateX(-100%); }
}

.meta-sub .small {
  font-size: 12px;
  color: var(--muted);
}

.player-controls {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}

.controls-left {
  display: flex;
  gap: 12px;
  align-items: center;
}

.btn-circle {
  width: 64px;
  height: 64px;
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 20px;
  background: linear-gradient(180deg, #ffffff, #f6fbff);
  box-shadow: 0 8px 20px rgba(2, 6, 23, 0.06);
  transition: transform var(--smooth), box-shadow var(--smooth);
  color: var(--accent-2);
}

.btn-circle:active { transform: scale(0.98); }

.btn-circle.pulse {
  animation: pulse 1.6s infinite;
  box-shadow: 0 8px 24px rgba(37, 99, 235, 0.12);
}

@keyframes pulse {
  0%,100% { transform: scale(1); }
  50% { transform: scale(1.03); }
}

.controls-middle {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

.progress {
  width: 100%;
  height: 10px;
  background: rgba(2, 6, 23, 0.05);
  border-radius: 999px;
  position: relative;
  cursor: pointer;
  user-select: none;
}

.progress-bar {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 160ms linear;
  position: relative;
}

.progress-cursor {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid #fff;
  box-shadow: 0 6px 14px rgba(2, 6, 23, 0.12);
  position: absolute;
  left: 0;
  top: 50%;
  transform: translate(-50%, -50%);
  transition: left 120ms linear;
  touch-action: none;
}

.time { font-size: 12px; color: var(--muted); }

.controls-right {
  display: flex;
  gap: 10px;
  align-items: center;
}

.volume-control {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
}

.volume-icon {
  font-size: 18px;
  color: var(--muted);
  cursor: pointer;
}

.volume-slider {
  display: block;
  opacity: 0;
  pointer-events: none;
  position: absolute;
  bottom: 48px;
  right: 0;
  padding: 10px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  background: var(--card);
  transition: opacity 0.2s ease;
}

.volume-slider.show {
  opacity: 1;
  pointer-events: auto;
}

.volume-input {
  width: 160px;
  -webkit-appearance: none;
  height: 6px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  outline: none;
}

.volume-input::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--accent-2);
  box-shadow: 0 6px 12px rgba(2, 6, 23, 0.12);
}

.info-overlay { position: fixed; inset: 0; background: rgba(2,6,23,0.45); z-index: 120; display: none; }

.info-box { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 121; width: 320px; max-width: 90%; padding: 18px; border-radius: 12px; box-shadow: var(--shadow); background: var(--card); display: none; }

.info-box.show, .info-overlay.show { display: block; }

.loading-container {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.28);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 140;
  visibility: hidden;
  opacity: 0;
  transition: opacity 180ms ease, visibility 180ms;
}

.loading-container.show {
  visibility: visible;
  opacity: 1;
}

.loading-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 20px 26px;
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.95), #fff);
  box-shadow: 0 14px 40px rgba(2, 6, 23, 0.12);
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 5px solid rgba(2, 6, 23, 0.06);
  border-top-color: var(--accent-2);
  animation: spin 1s linear infinite;
}

.loading-bars {
  display: flex;
  gap: 6px;
  align-items: end;
  height: 22px;
}

.loading-bars span {
  display: block;
  width: 6px;
  background: var(--accent-2);
  border-radius: 3px;
  animation: bars 900ms infinite ease-in-out;
}

.loading-bars span:nth-child(2) { animation-delay: 120ms; }
.loading-bars span:nth-child(3) { animation-delay: 240ms; }
.loading-bars span:nth-child(4) { animation-delay: 360ms; }

@keyframes bars {
  0% { height: 6px; opacity: 0.7; }
  50% { height: 20px; opacity: 1; }
  100% { height: 6px; opacity: 0.7; }
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.hidden { display: none !important; }

.small-icon {
  font-size: 18px;
  color: var(--muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
}

.btn-circle i,
.small-icon i {
  color: var(--accent-2);
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

#clearQueueBtn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: none;
  background: linear-gradient(90deg, #ff7a7a, #ff4f4f);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

#clearQueueBtn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 14px rgba(255, 90, 95, 0.3);
}

#clearQueueBtn:active {
  transform: translateY(1px) scale(0.98);
}

#clearQueueBtn:disabled {
  opacity: 0.4;
  cursor: default;
}

.btn-circle.replay-anim {
  animation: replayPop 0.4s ease forwards;
}

@keyframes replayPop {
  0% { transform: scale(1); opacity: 0; }
  50% { transform: scale(1.3); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

.queue-list li.clear-anim {
  animation: removeQueue 300ms forwards;
}

@keyframes removeQueue {
  0% { opacity: 1; transform: translateY(0); height: auto; margin-bottom: 6px; }
  100% { opacity: 0; transform: translateY(-20px); height: 0; margin-bottom: 0; }
}

#serverErrorContainer {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #ffffff;
  color: #000000;
  padding: 24px 32px;
  border-radius: 14px;
  font-weight: 500;
  font-size: 15px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.25);
  z-index: 200;
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
  max-width: 400px;
  border: 1px solid rgba(0, 0, 0, 0.1);
}

#serverErrorContainer.show {
  opacity: 1;
  pointer-events: auto;
  animation: bounceIn 0.4s ease forwards;
  display: flex;
}

#serverErrorContainer.hide {
  animation: fadeOutBounce 0.3s ease forwards;
}

@keyframes bounceIn {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.9); }
  60% { opacity: 1; transform: translate(-50%, -50%) scale(1.05); }
  100% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

@keyframes fadeOutBounce {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(0.95); }
}

#serverErrorContainer button {
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  background: #007aff;
  color: white;
  transition: background 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 2px 4px rgba(0, 122, 255, 0.2);
}

#serverErrorContainer button:hover {
  background: #0062cc;
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 4px 8px rgba(0, 122, 255, 0.3);
}

#serverErrorContainer button:active {
  transform: scale(0.98);
  box-shadow: 0 1px 2px rgba(0, 122, 255, 0.2);
}

#serverErrorContainer::before {
  content: "⚠️";
  font-size: 32px;
  margin-bottom: 8px;
}

#userErrorContainer {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #ffffff;
  color: #000000;
  padding: 24px 32px;
  border-radius: 14px;
  font-weight: 500;
  font-size: 15px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.25);
  z-index: 200;
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
  max-width: 400px;
  border: 1px solid rgba(0, 0, 0, 0.1);
}

#userErrorContainer.show {
  opacity: 1;
  pointer-events: auto;
  animation: bounceIn 0.4s ease forwards;
  display: flex;
}

#userErrorContainer.hide {
  animation: fadeOutBounce 0.3s ease forwards;
}

#userErrorContainer button {
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  background: #007aff;
  color: white;
  transition: background 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 2px 4px rgba(0, 122, 255, 0.2);
}

#userErrorContainer button:hover {
  background: #0062cc;
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 4px 8px rgba(0, 122, 255, 0.3);
}

#userErrorContainer button:active {
  transform: scale(0.98);
  box-shadow: 0 1px 2px rgba(0, 122, 255, 0.2);
}

#userErrorContainer::before {
  content: "⚠️";
  font-size: 32px;
  margin-bottom: 8px;
}

#coverModal {
  display: none;
  position: fixed;
  z-index: 150;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: rgba(2,6,23,0.45);
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s ease;
}

#coverModal.show {
  opacity: 1;
}

#coverModal.hide {
  opacity: 0;
}

.modal-content {
  background: var(--card);
  padding: 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: center;
  position: relative;
  max-width: 400px;
  width: 90%;
  opacity: 0;
  transform: scale(0.9);
}

#coverModal.show .modal-content {
  animation: modalBounceIn 0.4s ease forwards;
}

#coverModal.hide .modal-content {
  animation: modalFadeOut 0.3s ease forwards;
}

@keyframes modalBounceIn {
  0% { opacity: 0; transform: scale(0.9); }
  60% { opacity: 1; transform: scale(1.05); }
  100% { opacity: 1; transform: scale(1); }
}

@keyframes modalFadeOut {
  0% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(0.95); }
}

.close-modal {
  position: absolute;
  top: 10px;
  right: -2px;
  cursor: pointer;
  font-size: 24px;
  color: var(--muted);
}

.modal-content img {
  width: 100%;
  height: auto;
  border-radius: 10px;
  margin-bottom: 16px;
}

.modal-content button {
  margin-top: 10px;
}

.btn i {
  margin-right: 6px;
}

.btn.primary i,
.btn.secondary i,
.btn.ghost i {
  font-size: 14px;
  vertical-align: middle;
}