:root {
  --bg: #0b0d10;
  --surface: #12151b;
  --surface2: #1b2029;
  --border: #242b37;
  --accent: #1ed760;
  --accent-hover: #1fdf64;
  --accent-dim: #169c46;
  --text: #f0f3f6;
  --text-dim: #8b949e;
  --warn: #e8b04b;
  --error: #ff6b6b;
  --radius: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html {
  overflow-x: hidden;
  max-width: 100vw;
  width: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  padding: 48px 20px 100px;
  display: flex;
  justify-content: center;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  max-width: 100vw;
  width: 100%;
}

main {
  width: 100%;
  max-width: 820px;
  overflow-x: hidden;
}

h1 {
  font-size: 3rem;
  font-weight: 800;
  letter-spacing: -0.04em;
  text-align: center;
  margin-bottom: 6px;
}

h1 span {
  color: var(--accent);
}

.subtitle {
  text-align: center;
  color: var(--text-dim);
  margin-bottom: 16px;
  font-size: 1.05rem;
}

.auth-bar {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 24px;
}

.auth-btn {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 8px 16px;
  box-shadow: none;
}

.auth-btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
  filter: none;
  box-shadow: none;
}

.auth-user {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.auth-logout {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.auth-logout:hover {
  text-decoration: underline;
}

form {
  display: flex;
  gap: 10px;
  width: 100%;
}

input[type="text"] {
  flex: 1;
  min-width: 0; /* Ensures flex input does not force container overflow on small screens */
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 1rem;
  padding: 14px 18px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input[type="text"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(30, 215, 96, 0.18);
}

button, .button {
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 1rem;
  font-weight: 700;
  padding: 14px 26px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.15s ease, box-shadow 0.2s ease, filter 0.2s ease;
  box-shadow: 0 4px 18px rgba(30, 215, 96, 0.25);
  white-space: nowrap;
}

button:hover:not(:disabled), .button:hover {
  transform: translateY(-1px);
  filter: brightness(1.08);
  box-shadow: 0 6px 26px rgba(30, 215, 96, 0.38);
}

button:active:not(:disabled), .button:active { transform: translateY(0); }

button:disabled {
  background: var(--surface2);
  color: var(--text-dim);
  cursor: default;
  box-shadow: none;
}

.error {
  background: rgba(255, 107, 107, 0.08);
  border: 1px solid rgba(255, 107, 107, 0.4);
  border-radius: 12px;
  color: var(--error);
  margin-top: 14px;
  padding: 12px 16px;
  animation: slide-down 0.25s ease;
}

/* ---------- Collection ---------- */

#collection {
  margin-top: 36px;
  animation: rise-in 0.3s ease;
  width: 100%;
}

#collection header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

#collection-title {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

#collection-meta {
  color: var(--text-dim);
  font-size: 0.92rem;
  margin-right: auto;
}

/* ---------- Table Container & Table ---------- */

.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  backdrop-filter: blur(12px);
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  border: none;
  border-radius: 0;
  overflow: hidden;
}

thead {
  background: rgba(255, 255, 255, 0.02);
  border-bottom: 1px solid var(--border);
}

th, td {
  padding: 13px 18px;
  text-align: left;
  font-size: 0.92rem;
}

th {
  color: var(--text-dim);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  white-space: nowrap;
  transition: color 0.15s ease;
}

th.sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
th.sortable:hover {
  color: var(--text);
}
th.sorted-asc, th.sorted-desc {
  color: var(--text);
}
.sort-indicator {
  font-size: 0.65rem;
  margin-left: 5px;
  color: var(--text-dim);
  display: inline-block;
  vertical-align: baseline;
  transition: color 0.15s ease;
}

tbody tr {
  border-top: 1px solid rgba(255, 255, 255, 0.04);
  transition: background 0.15s ease;
}
tbody tr:hover { background: rgba(255, 255, 255, 0.03); }

th.num, td.num {
  width: 58px;
  min-width: 58px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.track-link {
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.15s ease;
}
.track-link:hover {
  color: var(--accent);
  text-decoration: underline;
}

/* ---------- Status dots & action buttons ---------- */

.status-cell {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 32px;
}

.dot-indicator {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  display: inline-block;
}

.dot-green {
  background-color: var(--accent);
  box-shadow: 0 0 10px rgba(30, 215, 96, 0.7);
}

.dot-yellow {
  background-color: #f59e0b;
  box-shadow: 0 0 10px rgba(245, 158, 11, 0.6);
  animation: pulse-dot 1.2s ease-in-out infinite;
}

.dot-red {
  background-color: #ef4444;
  box-shadow: 0 0 10px rgba(239, 68, 68, 0.6);
}

.track-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.track-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  width: 30px;
  height: 30px;
  padding: 0;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.07);
  color: var(--text-dim);
  transition: transform 0.15s ease, background 0.15s ease, color 0.15s ease;
  box-shadow: none;
}

.track-btn:hover {
  transform: scale(1.12);
  color: #ffffff;
  background: rgba(255, 255, 255, 0.16);
}

.track-preview-btn.playing {
  background: var(--accent);
  color: #000000;
  box-shadow: 0 0 12px rgba(30, 215, 96, 0.4);
}
.track-preview-btn.playing:hover {
  background: var(--accent-hover);
  color: #000000;
}

.track-retry-btn {
  width: auto;
  height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  gap: 5px;
  font-size: 0.75rem;
  font-weight: 600;
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #fca5a5;
  white-space: nowrap;
}

.track-retry-btn:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.25);
  color: #ffffff;
  transform: translateY(-1px);
}
.track-retry-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---------- Zip / Download all row ---------- */

#zip-row {
  margin-top: 24px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
}

.zip-btn {
  font-size: 1.05rem;
  padding: 14px 28px;
  text-align: center;
}

.ios-tip {
  max-width: 540px;
  font-size: 0.86rem;
  color: var(--text-dim);
  line-height: 1.45;
  background: rgba(30, 35, 42, 0.85);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  text-align: left;
}
.ios-tip strong { color: var(--text); }
.ios-tip em {
  color: var(--accent);
  font-style: normal;
  font-weight: 600;
}

/* ---------- Spotify-Style Bottom Audio Player Bar ---------- */

.audio-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  height: 80px;
  background: #121212;
  border-top: 1px solid #282828;
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.7);
  padding: 0 20px;
  display: flex;
  align-items: center;
  animation: slide-up-bar 0.25s ease-out;
  box-sizing: border-box;
}

.audio-bar-inner {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

/* Left: Track info with thumbnail */
.player-left {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 25%;
  min-width: 180px;
  max-width: 280px;
  overflow: hidden;
}

.player-thumb-wrap {
  width: 52px;
  height: 52px;
  min-width: 52px;
  border-radius: 4px;
  overflow: hidden;
  background: #282828;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.player-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.player-thumb-fallback {
  color: #727272;
  display: flex;
  align-items: center;
  justify-content: center;
}

.player-text {
  display: flex;
  flex-direction: column;
  gap: 3px;
  overflow: hidden;
  min-width: 0;
}

.player-title {
  color: #ffffff;
  font-size: 0.88rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-artist {
  color: #b3b3b3;
  font-size: 0.74rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Center: Controls & seekbar (PC layout) */
.player-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  flex: 1;
  max-width: 600px;
}

.player-buttons {
  display: flex;
  align-items: center;
  gap: 16px;
}

.player-btn-secondary {
  background: transparent;
  border: none;
  color: #b3b3b3;
  cursor: pointer;
  padding: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  box-shadow: none;
  transition: color 0.15s ease, transform 0.15s ease;
  flex-shrink: 0;
}

.player-btn-secondary:hover {
  color: #ffffff;
  transform: scale(1.08);
}

.player-play-circle {
  background: #ffffff;
  border: none;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  min-width: 36px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #000000;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  transition: transform 0.15s ease, background 0.15s ease;
  flex-shrink: 0;
}

.player-play-circle:hover {
  transform: scale(1.06);
  background: #f0f0f0;
}

.player-timeline {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
}

.time-label {
  color: #a7a7a7;
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  min-width: 32px;
  text-align: center;
  flex-shrink: 0;
}

.seek-bar-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  min-width: 0;
}

/* Sleek sliders */
.player-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: #4d4d4d;
  outline: none;
  cursor: pointer;
  transition: background 0.1s ease;
}

/* Dynamic gradient fill for seek bar */
.seek-slider {
  background: linear-gradient(
    to right,
    var(--seek-fill, #ffffff) 0%,
    var(--seek-fill, #ffffff) var(--seek-percent, 0%),
    #4d4d4d var(--seek-percent, 0%),
    #4d4d4d 100%
  );
}

.player-timeline:hover .seek-slider {
  --seek-fill: var(--accent);
}

.player-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.player-timeline:hover .player-slider::-webkit-slider-thumb,
.vol-bar-wrapper:hover .player-slider::-webkit-slider-thumb,
.player-slider:active::-webkit-slider-thumb,
.player-slider:focus::-webkit-slider-thumb {
  opacity: 1;
}

.player-slider::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border: none;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.player-timeline:hover .player-slider::-moz-range-thumb,
.vol-bar-wrapper:hover .player-slider::-moz-range-thumb,
.player-slider:active::-moz-range-thumb,
.player-slider:focus::-moz-range-thumb {
  opacity: 1;
}

/* Right: Volume & close */
.player-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  width: 25%;
  min-width: 160px;
}

.lyrics-btn {
  color: #b3b3b3;
  transition: color 0.15s ease, transform 0.15s ease;
}

.lyrics-btn:hover {
  color: #ffffff;
  transform: scale(1.1);
}

.lyrics-btn.active {
  color: var(--accent);
}

.vol-bar-wrapper {
  display: flex;
  align-items: center;
  width: 86px;
}

.vol-slider {
  background: linear-gradient(
    to right,
    var(--vol-fill, #ffffff) 0%,
    var(--vol-fill, #ffffff) var(--vol-percent, 100%),
    #4d4d4d var(--vol-percent, 100%),
    #4d4d4d 100%
  );
}

.vol-bar-wrapper:hover .vol-slider {
  --vol-fill: var(--accent);
}

.player-close-btn {
  margin-left: 6px;
  color: #8b949e;
}
.player-close-btn:hover {
  color: #ff6b6b;
}

/* ---------- Spotify Synchronized Lyrics Overlay ---------- */

.lyrics-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 80px; /* leaves room for bottom audio player bar */
  z-index: 990;
  display: flex;
  flex-direction: column;
  background: #121212;
  overflow: hidden;
  animation: lyrics-rise 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  user-select: none;
}

.lyrics-header {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 32px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.lyrics-track-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow: hidden;
  min-width: 0;
}

.lyrics-track-title {
  color: #ffffff;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lyrics-track-artist {
  color: rgba(255, 255, 255, 0.6);
  font-size: 0.9rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lyrics-close-btn {
  background: rgba(255, 255, 255, 0.08);
  border: none;
  color: #ffffff;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  min-width: 40px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
  box-shadow: none;
  flex-shrink: 0;
}

.lyrics-close-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: scale(1.08);
}

.lyrics-container {
  position: relative;
  z-index: 1;
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
  padding: 60px 40px 180px;
  mask-image: linear-gradient(to bottom, transparent 0%, black 12%, black 85%, transparent 100%);
  -webkit-mask-image: linear-gradient(to bottom, transparent 0%, black 12%, black 85%, transparent 100%);
}

.lyrics-container::-webkit-scrollbar {
  width: 8px;
}
.lyrics-container::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 4px;
}

.lyrics-lines {
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 22px;
  overflow-x: hidden;
}

.lyric-line {
  font-size: 1.85rem;
  font-weight: 700;
  line-height: 1.4;
  letter-spacing: -0.025em;
  color: rgba(255, 255, 255, 0.35);
  cursor: pointer;
  transition: color 0.2s ease, transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  transform-origin: left center;
  word-break: break-word;
}

.lyric-line:hover {
  color: rgba(255, 255, 255, 0.7);
  transform: translateX(4px);
}

.lyric-line.active {
  color: #ffffff;
  font-weight: 800;
  transform: scale(1.02);
}

.lyrics-status-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 280px;
  text-align: center;
  gap: 12px;
  color: rgba(255, 255, 255, 0.55);
  font-size: 1.15rem;
  font-weight: 500;
}

.lyrics-status-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.3);
}

@keyframes lyrics-rise {
  from { opacity: 0; transform: translateY(30px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Animations ---------- */

@keyframes pulse-dot {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.35); opacity: 0.6; }
}

@keyframes slide-down {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes rise-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes slide-up-bar {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.hidden { display: none !important; }

/* ---------- Mobile & Tablet Responsive Optimization ---------- */

@media (max-width: 720px) {
  body {
    padding: 24px 12px calc(105px + env(safe-area-inset-bottom, 0px));
  }

  h1 {
    font-size: 2.2rem;
  }

  .subtitle {
    margin-bottom: 24px;
    font-size: 0.95rem;
  }

  form {
    gap: 8px;
  }

  input[type="text"] {
    padding: 12px 14px;
    font-size: 0.92rem;
  }

  button, .button {
    padding: 12px 18px;
    font-size: 0.92rem;
  }

  #collection header {
    gap: 10px;
    margin-bottom: 14px;
  }

  #collection-title {
    font-size: 1.25rem;
  }

  #collection-meta {
    font-size: 0.85rem;
  }

  #start-btn {
    padding: 10px 18px;
    font-size: 0.88rem;
  }

  .table-responsive {
    border-radius: 12px;
  }

  th, td {
    padding: 10px 8px;
    font-size: 0.82rem;
  }

  th.num, td.num {
    width: 32px;
    min-width: 32px;
    padding-left: 8px;
    padding-right: 4px;
    text-align: center;
  }

  .status-cell {
    gap: 8px;
    justify-content: flex-end;
  }

  .track-actions {
    gap: 4px;
  }

  .track-btn {
    width: 28px;
    height: 28px;
  }

  .track-retry-btn {
    height: 26px;
    padding: 0 8px;
    font-size: 0.72rem;
  }

  .track-link {
    word-break: break-word;
  }

  /* Audio bar: sleek 2-row layout with full-width seek slider */
  .audio-bar {
    height: auto;
    min-height: 84px;
    padding: 8px 12px calc(8px + env(safe-area-inset-bottom, 0px));
  }

  .audio-bar-inner {
    display: grid;
    grid-template-columns: 1fr auto auto;
    grid-template-areas:
      "timeline timeline timeline"
      "left buttons right";
    gap: 6px 8px;
    align-items: center;
    width: 100%;
    max-width: 100%;
  }

  .player-center {
    display: contents;
  }

  .player-timeline {
    grid-area: timeline;
    width: 100%;
    gap: 8px;
    margin: 0;
  }

  .time-label {
    min-width: 28px;
    font-size: 0.7rem;
  }

  .seek-bar-wrapper {
    padding: 4px 0;
  }

  .player-slider {
    height: 5px;
  }

  .player-slider::-webkit-slider-thumb {
    opacity: 1;
    width: 14px;
    height: 14px;
  }

  .player-slider::-moz-range-thumb {
    opacity: 1;
    width: 14px;
    height: 14px;
  }

  .player-left {
    grid-area: left;
    width: auto;
    min-width: 0;
    max-width: none;
    gap: 8px;
  }

  .player-thumb-wrap {
    width: 38px;
    height: 38px;
    min-width: 38px;
  }

  .player-title {
    font-size: 0.82rem;
  }

  .player-artist {
    font-size: 0.7rem;
  }

  .player-buttons {
    grid-area: buttons;
    gap: 6px;
  }

  .player-play-circle {
    width: 34px;
    height: 34px;
    min-width: 34px;
  }

  .player-right {
    grid-area: right;
    width: auto;
    min-width: 0;
    gap: 4px;
    justify-content: flex-end;
  }

  #vol-btn,
  .vol-bar-wrapper {
    display: none !important;
  }

  .player-btn-secondary {
    padding: 5px;
  }

  .lyrics-overlay {
    bottom: 86px;
  }

  .lyrics-header {
    padding: 16px 16px 12px;
  }

  .lyrics-track-title {
    font-size: 1.15rem;
  }

  .lyrics-container {
    padding: 24px 16px 100px;
  }

  .lyric-line {
    font-size: 1.35rem;
  }
}
