:root {
  --bg: #0d1117;
  --bg2: #161b22;
  --bg3: #21262d;
  --border: #30363d;
  --text: #e6edf3;
  --text2: #8b949e;
  --accent: #58a6ff;
  --green: #3fb950;
  --red: #f85149;
  --yellow: #d29922;
  --purple: #bc8cff;
  --radius: 6px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.container { max-width: 960px; margin: 0 auto; padding: 2rem 1rem; }

h1 { font-size: 1.5rem; margin-bottom: 1.5rem; }
h2 { font-size: 1.25rem; margin-bottom: 1rem; }

/* Landing */
.url-form {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 2rem;
}
.url-form input {
  flex: 1;
  padding: 0.6rem 1rem;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.95rem;
}
.url-form input:focus { outline: none; border-color: var(--accent); }
.url-form button, .btn {
  padding: 0.6rem 1.2rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 500;
  white-space: nowrap;
}
.btn:hover { opacity: 0.85; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-sm { padding: 0.3rem 0.7rem; font-size: 0.8rem; }
.btn-secondary { background: var(--bg3); color: var(--text); }
.btn-danger { background: var(--red); }

/* Playlist history */
.playlist-list { list-style: none; }
.playlist-list li {
  padding: 0.75rem 1rem;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  transition: border-color 0.15s;
}
.playlist-list li:hover { border-color: var(--accent); }
.playlist-list .track-count { color: var(--text2); font-size: 0.85rem; }

/* Track table */
.track-table { width: 100%; border-collapse: collapse; }
.track-table th {
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-bottom: 2px solid var(--border);
  color: var(--text2);
  font-size: 0.85rem;
  font-weight: 500;
}
.track-table td {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.track-table tr:hover { background: var(--bg2); }
.track-table .num { color: var(--text2); width: 2rem; }
.track-table .song-info { min-width: 200px; }
.track-table .song-title { font-weight: 500; }
.track-table .song-artist { color: var(--text2); font-size: 0.85rem; }
.track-table .song-album { color: var(--text2); font-size: 0.75rem; font-style: italic; }
.track-table .duration { color: var(--text2); width: 4rem; }
.track-table .meta-col { white-space: nowrap; text-align: center; font-variant-numeric: tabular-nums; }

/* Clickable meta cells */
.meta-col.clickable {
  cursor: pointer;
  position: relative;
  transition: background 0.15s;
}
.meta-col.clickable:hover {
  background: var(--bg3);
}
.meta-col.clickable .refresh-hint {
  display: none;
  position: absolute;
  top: 2px;
  right: 2px;
  font-size: 0.6rem;
  color: var(--text2);
  opacity: 0.5;
}
.meta-col.clickable:hover .refresh-hint {
  display: block;
}
.meta-col.refreshing {
  opacity: 0.6;
  pointer-events: none;
}
.meta-col.refreshing::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* Cover art */
.cover-col {
  width: 40px;
  padding: 0.4rem 0.25rem !important;
}
.cover-thumb {
  width: 36px;
  height: 36px;
  border-radius: 4px;
  object-fit: cover;
  display: block;
}
.cover-placeholder {
  width: 36px;
  height: 36px;
  border-radius: 4px;
  background: var(--bg3);
}
.player-cover {
  width: 120px;
  height: 120px;
  border-radius: var(--radius);
  object-fit: cover;
  margin-right: 1rem;
  flex-shrink: 0;
  border: 1px solid var(--border);
}
.track-header {
  display: flex;
  align-items: flex-start;
  margin-bottom: 1.5rem;
}
.track-header-text {
  flex: 1;
  min-width: 0;
}
.meta-na { color: var(--text2); opacity: 0.4; }
.bpm-val { color: var(--accent); font-weight: 500; }
.key-val { color: var(--purple); font-weight: 500; font-size: 0.85rem; }
.year-val { color: var(--text2); font-size: 0.85rem; }
.rerelease { color: var(--yellow); font-size: 0.75rem; }
.rerelease-tag { color: var(--yellow); font-size: 0.7rem; background: rgba(210, 153, 34, 0.15); padding: 0.1rem 0.4rem; border-radius: 3px; margin-left: 0.3rem; }

/* Status icons */
.status { display: inline-block; width: 1.2rem; text-align: center; }
.status.yes { color: var(--green); }
.status.no { color: var(--text2); }
.status.warn { color: var(--yellow); }
.status.running { color: var(--yellow); animation: pulse 1s infinite; }
.status.failed { color: var(--red); }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

/* Track header meta */
.track-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}
.meta-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.6rem;
  border-radius: 12px;
  font-size: 0.8rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.meta-badge.bpm { background: rgba(88, 166, 255, 0.15); color: var(--accent); }
.meta-badge.key { background: rgba(188, 140, 255, 0.15); color: var(--purple); }
.meta-badge.year { background: rgba(139, 148, 158, 0.15); color: var(--text2); }
.meta-badge.album { background: rgba(139, 148, 158, 0.1); color: var(--text2); font-style: italic; }

.tempo-row .pitch-slider::-webkit-slider-thumb { background: var(--green); }
.tempo-row .pitch-slider::-moz-range-thumb { background: var(--green); }

/* Actions bar */
.actions-bar {
  display: flex;
  gap: 0.5rem;
  margin: 1rem 0;
  flex-wrap: wrap;
}

/* Back link */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  color: var(--text2);
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
.back-link:hover { color: var(--accent); text-decoration: none; }

/* Player */
.player-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1rem;
}

.transport {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.transport button {
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  font-size: 1.5rem;
  padding: 0.25rem;
}
.transport button:hover { color: var(--accent); }

.progress-bar {
  flex: 1;
  height: 6px;
  background: var(--bg3);
  border-radius: 3px;
  cursor: pointer;
  position: relative;
}
.progress-bar .fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  width: 0%;
  transition: width 0.1s linear;
}
.time-display {
  color: var(--text2);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
  min-width: 8rem;
  text-align: right;
}

.pitch-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0 0.75rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.25rem;
}
.pitch-label {
  font-size: 0.85rem;
  color: var(--text2);
  width: 3.5rem;
}
.pitch-slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--bg3);
  border-radius: 2px;
  outline: none;
}
.pitch-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--yellow);
  cursor: pointer;
}
.pitch-value {
  font-size: 0.85rem;
  color: var(--text2);
  min-width: 4rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
  transition: color 0.15s;
}
.pitch-value.pitch-sharp { color: #58d5ff; }
.pitch-value.pitch-flat { color: #ff9f43; }
.tuning-display {
  font-size: 0.8rem;
  color: var(--text2);
  min-width: 0;
  font-variant-numeric: tabular-nums;
  transition: color 0.15s;
}
.tuning-display.pitch-sharp { color: #58d5ff; }
.tuning-display.pitch-flat { color: #ff9f43; }
.pitch-reset {
  padding: 0.2rem 0.5rem;
  font-size: 0.7rem;
}

/* Stem channels */
.stem-channel {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}
.stem-channel:last-child { border-bottom: none; }
.stem-icon { width: 1.5rem; text-align: center; font-size: 1.1rem; }
.stem-name { width: 5rem; font-size: 0.85rem; color: var(--text2); }
.stem-volume {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--bg3);
  border-radius: 2px;
  outline: none;
}
.stem-volume::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}
.stem-btn {
  width: 2rem;
  height: 1.5rem;
  border: 1px solid var(--border);
  background: var(--bg3);
  color: var(--text2);
  border-radius: 3px;
  cursor: pointer;
  font-size: 0.7rem;
  font-weight: 600;
}
.stem-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.stem-btn.mute-active { background: var(--red); color: #fff; border-color: var(--red); }

/* Loading */
.loading {
  text-align: center;
  padding: 3rem;
  color: var(--text2);
}
.loading .spinner {
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 0.5rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Job status */
.job-status {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin: 1rem 0;
}
.job-status pre {
  background: var(--bg);
  padding: 0.75rem;
  border-radius: var(--radius);
  overflow-x: auto;
  font-size: 0.8rem;
  max-height: 300px;
  overflow-y: auto;
  color: var(--text2);
  white-space: pre-wrap;
}

/* Track detail header — styles above with cover art */
.track-header .title { font-size: 1.3rem; font-weight: 600; }
.track-header .artist { color: var(--text2); }

/* Responsive */
@media (max-width: 640px) {
  .container { padding: 1rem 0.75rem; }
  .url-form { flex-direction: column; }
  .track-table { font-size: 0.8rem; }
  .track-table .song-info { min-width: 120px; }
}

.tab-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 0 0.5rem;
  border-top: 1px solid var(--border);
  margin-top: 0.5rem;
}
.tab-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
}
.tab-tracks {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding-bottom: 0.5rem;
}
.tab-track {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--bg3);
  padding: 0.3rem 0.6rem;
  border-radius: 4px;
  font-size: 0.75rem;
  color: var(--text2);
}
.tab-track-name {
  color: var(--text);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tab-diff {
  color: var(--yellow);
  font-size: 0.65rem;
  letter-spacing: 1px;
}

/* Lyrics panel */
.lyrics-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 0 0.5rem;
  border-top: 1px solid var(--border);
  margin-top: 0.5rem;
}
.lyrics-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
}
.lyrics-btn {
  font-size: 1rem !important;
  padding: 0.25rem 0.5rem !important;
  line-height: 1;
}
.lyrics-btn.active {
  background: var(--accent) !important;
  color: #fff !important;
}
.lyrics-scroll {
  max-height: 350px;
  overflow-y: auto;
  padding: 1rem 0;
  scroll-behavior: smooth;
  mask-image: linear-gradient(to bottom, transparent 0%, black 10%, black 90%, transparent 100%);
  -webkit-mask-image: linear-gradient(to bottom, transparent 0%, black 10%, black 90%, transparent 100%);
}
.lyrics-line {
  padding: 0.45rem 0.75rem;
  font-size: 1.05rem;
  line-height: 1.6;
  color: var(--text2);
  transition: color 0.25s, transform 0.25s, font-weight 0.25s;
  cursor: pointer;
  border-radius: 4px;
}
.lyrics-line:hover {
  background: rgba(255, 255, 255, 0.03);
}
.lyrics-line.active {
  color: var(--text);
  font-weight: 600;
  font-size: 1.15rem;
  transform: scale(1.02);
}
.lyrics-line.past {
  color: var(--text2);
  opacity: 0.5;
}
.lyrics-line.lyrics-static {
  cursor: default;
}

/* Blurred cover art background */
#bg-art {
  position: fixed;
  inset: 0;
  z-index: -1;
  background-size: cover;
  background-position: center;
  filter: blur(80px) brightness(0.2) saturate(1.3);
  transform: scale(1.3);
  transition: opacity 0.8s ease;
  opacity: 0;
  pointer-events: none;
}
#bg-art.active { opacity: 1; }

/* Hidden playlist badge */
.hidden-badge {
  font-size: 0.7rem;
  background: rgba(248, 81, 73, 0.15);
  color: var(--red);
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
  margin-left: 0.4rem;
  font-weight: 500;
}

/* Delete button */
.btn-danger {
  background: var(--red);
  margin-left: auto;
}
.btn-danger:hover { background: #e5443d; }

/* Admin-only controls in actions bar */
.actions-bar .btn-danger { order: 100; }

/* Spotify connection status */
.spotify-connected {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.4rem 0.8rem;
  background: rgba(63, 185, 80, 0.15);
  color: var(--green);
  border-radius: var(--radius);
  font-size: 0.8rem;
  font-weight: 500;
}
.spotify-connected::before {
  content: "\2713";
  font-weight: 700;
}

/* Enhanced tab section */
.tab-tracks-list {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-bottom: 0.75rem;
}
.tab-track {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg3);
  padding: 0.35rem 0.7rem;
  border-radius: 4px;
  font-size: 0.75rem;
  color: var(--text2);
  flex-wrap: wrap;
}
.tab-track-instrument {
  background: rgba(88, 166, 255, 0.1);
  color: var(--accent);
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
  font-size: 0.7rem;
  font-weight: 500;
  white-space: nowrap;
}
.tab-tuning {
  color: var(--text2);
  font-size: 0.65rem;
  opacity: 0.7;
}
.tab-video {
  margin-top: 0.75rem;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}
.tab-video iframe {
  display: block;
}

/* Mobile cards */
@media (max-width: 768px) {
  .track-cards {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }
  .track-card {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem;
  }
  .card-cover {
    width: 48px;
    height: 48px;
    flex-shrink: 0;
  }
  .card-cover-img {
    width: 48px;
    height: 48px;
    border-radius: 4px;
    object-fit: cover;
  }
  .card-info {
    flex: 1;
    min-width: 0;
  }
  .card-num {
    color: var(--text2);
    font-size: 0.75rem;
  }
  .card-title {
    font-weight: 500;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .card-artist {
    color: var(--text2);
    font-size: 0.8rem;
  }
  .card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    margin-top: 0.25rem;
  }
  .card-badge {
    font-size: 0.7rem;
    padding: 0.1rem 0.4rem;
    border-radius: 3px;
    background: var(--bg3);
    color: var(--text2);
  }
  .card-badge.bpm { color: var(--accent); }
  .card-badge.key { color: var(--purple); }
  .card-play-btn {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    border: none;
    cursor: pointer;
    font-size: 1rem;
  }
  .actions-bar {
    gap: 0.4rem;
  }
  .actions-bar .btn {
    font-size: 0.75rem;
    padding: 0.4rem 0.7rem;
  }
}
