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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #0a0a0a;
  color: #e0e0e0;
  padding: 24px;
  max-width: 1200px;
  margin: 0 auto;
}

header {
  margin-bottom: 32px;
}

h1 {
  font-size: 28px;
  color: #1db954;
  margin-bottom: 4px;
}

.subtitle {
  color: #888;
  font-size: 14px;
}

.btn {
  display: inline-block;
  padding: 10px 20px;
  border: none;
  border-radius: 24px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  transition: opacity 0.2s;
}

.btn:hover { opacity: 0.85; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: #1db954;
  color: #000;
}

.btn-small {
  padding: 6px 12px;
  font-size: 12px;
  background: #333;
  color: #ccc;
  border-radius: 4px;
}

.toolbar {
  display: flex;
  gap: 24px;
  align-items: flex-start;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.filter-group label {
  font-size: 13px;
  color: #aaa;
}

#genre-filter {
  width: 240px;
  height: 80px;
  background: #1a1a1a;
  color: #e0e0e0;
  border: 1px solid #333;
  border-radius: 4px;
  padding: 4px;
  font-size: 13px;
}

#genre-filter option:checked {
  background: #1db954;
  color: #000;
}

.disabled-filter {
  opacity: 0.4;
}

.coming-soon {
  font-size: 11px;
  color: #666;
  font-style: italic;
}

#spinner {
  color: #1db954;
  font-size: 16px;
  padding: 20px 0;
}

#status {
  font-size: 13px;
  color: #888;
  margin-bottom: 12px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead th {
  text-align: left;
  padding: 8px 12px;
  border-bottom: 2px solid #333;
  color: #aaa;
  font-weight: 600;
  position: sticky;
  top: 0;
  background: #0a0a0a;
}

tbody tr {
  border-bottom: 1px solid #1a1a1a;
}

tbody tr:hover {
  background: #111;
}

tbody td {
  padding: 6px 12px;
  max-width: 250px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.muted {
  color: #555;
}

.dim {
  color: #666;
}

.mono {
  font-family: 'Courier New', Courier, monospace;
  font-variant-numeric: tabular-nums;
}

/* ─── Library size slider ─── */

#library-limit {
  width: 120px;
  accent-color: #1db954;
  cursor: pointer;
}

/* ─── BPM range sliders ─── */

.bpm-slider {
  width: 80px;
  accent-color: #1db954;
  cursor: pointer;
}

.bpm-val {
  min-width: 24px;
  text-align: center;
  font-size: 12px;
}

/* ─── Sortable columns ─── */

.sortable {
  cursor: pointer;
  user-select: none;
  position: relative;
}

.sortable:hover {
  color: #1db954;
}

.sortable::after {
  content: '';
  margin-left: 4px;
  font-size: 10px;
}

.sortable.sort-asc::after {
  content: '▲';
}

.sortable.sort-desc::after {
  content: '▼';
}

/* ─── Enrich bar ─── */

.enrich-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

/* ─── Filter panel ─── */

.filter-panel {
  background: #111;
  border: 1px solid #222;
  border-radius: 6px;
  padding: 12px 16px;
  margin-bottom: 16px;
}

.filter-row {
  display: flex;
  gap: 20px;
  align-items: center;
  flex-wrap: wrap;
}

.filter-row + .filter-row {
  margin-top: 10px;
}

.filter-panel label {
  font-size: 12px;
  color: #888;
  white-space: nowrap;
}

.input-num {
  width: 64px;
  padding: 4px 6px;
  background: #1a1a1a;
  border: 1px solid #333;
  border-radius: 3px;
  color: #e0e0e0;
  font-size: 12px;
  font-family: 'Courier New', monospace;
  font-variant-numeric: tabular-nums;
}

.input-num::placeholder {
  color: #555;
}

.input-num:focus {
  outline: none;
  border-color: #1db954;
}

/* Hide number input spinners */
.input-num::-webkit-outer-spin-button,
.input-num::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.input-num { -moz-appearance: textfield; }

.filter-panel select {
  padding: 4px 6px;
  background: #1a1a1a;
  border: 1px solid #333;
  border-radius: 3px;
  color: #e0e0e0;
  font-size: 12px;
  cursor: pointer;
}

.filter-panel select:focus {
  outline: none;
  border-color: #1db954;
}

.compat-label {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  font-size: 11px !important;
  color: #aaa !important;
}

.compat-label input[type="checkbox"] {
  accent-color: #1db954;
  width: 13px;
  height: 13px;
  cursor: pointer;
}

/* ─── Table wrapper (horizontal scroll) ─── */

.table-wrap {
  overflow-x: auto;
}

.col-num {
  text-align: right;
  white-space: nowrap;
}

tbody td.mono {
  text-align: right;
}

#track-count {
  font-size: 13px;
  color: #888;
  margin: 8px 0;
}

.playlist-section {
  margin-top: 24px;
  padding-top: 24px;
  border-top: 1px solid #222;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

#playlist-name {
  background: #1a1a1a;
  border: 1px solid #333;
  border-radius: 4px;
  padding: 10px 14px;
  color: #e0e0e0;
  font-size: 14px;
  width: 280px;
}

#playlist-result {
  font-size: 13px;
  color: #1db954;
}

#playlist-result a {
  color: #1db954;
}

/* ─── Genre Map ─── */

.genre-map-container {
  margin-bottom: 16px;
  border: 1px solid #222;
  border-radius: 8px;
  overflow: hidden;
  background: #0a0a0a;
}

.genre-map-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: #1a1a1a;
  border-bottom: 1px solid #222;
}

.btn-tool {
  padding: 6px 12px;
  font-size: 12px;
  font-family: inherit;
  background: #333;
  color: #ccc;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s ease-out, color 0.15s ease-out;
  min-height: 32px;
}

.btn-tool:hover {
  background: #444;
}

.btn-tool.active {
  background: #1db954;
  color: #000;
}

.genre-map-stats {
  margin-left: auto;
  font-size: 12px;
  color: #888;
  font-variant-numeric: tabular-nums;
}

.genre-map-viewport {
  position: relative;
  height: 400px;
  overflow: hidden;
}

.genre-map-zoomable {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.lasso-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  z-index: 10;
}

.minimap-canvas {
  position: absolute;
  bottom: 8px;
  right: 8px;
  width: 120px;
  height: 80px;
  border: 1px solid #333;
  border-radius: 4px;
  z-index: 20;
  pointer-events: none;
}

.genre-label {
  position: absolute;
  background: none;
  border: none;
  padding: 2px 4px;
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
  transition: opacity 0.15s ease-out, transform 0.15s ease-out;
  opacity: 0;
  animation: genreFadeIn 0.3s ease-out forwards;
  animation-delay: calc(var(--index, 0) * 20ms);
}

@keyframes genreFadeIn {
  from { opacity: 0; transform: scale(0.8); }
  to { opacity: 1; transform: scale(1); }
}

.genre-label:hover {
  transform: scale(1.05);
}

.genre-label:focus-visible {
  outline: 2px solid #1db954;
  outline-offset: 2px;
  border-radius: 2px;
}

.genre-label.selected {
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
  transform: scale(1.1);
  filter: brightness(1.2);
}

.genre-label.dimmed {
  opacity: 0.3 !important;
}

.genre-label.family-highlight {
  opacity: 1 !important;
  filter: brightness(1.1);
}

.genre-map-unavailable {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 120px;
  color: #666;
  font-size: 14px;
}

/* ─── Track Lookup ─── */

.track-lookup {
  margin-bottom: 16px;
}

.lookup-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

#lookup-input {
  flex: 1;
  max-width: 480px;
  padding: 10px 14px;
  background: #1a1a1a;
  border: 1px solid #333;
  border-radius: 4px;
  color: #e0e0e0;
  font-size: 14px;
  font-family: inherit;
}

#lookup-input::placeholder {
  color: #555;
}

#lookup-input:focus {
  outline: none;
  border-color: #1db954;
}

#lookup-btn {
  padding: 10px 20px;
  background: #333;
  color: #ccc;
  border: none;
  border-radius: 4px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
  min-height: 44px;
}

#lookup-btn:hover { background: #444; }
#lookup-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.lookup-error {
  font-size: 13px;
  color: #e74c3c;
  margin-top: 4px;
  animation: lookupErrorFade 3s ease-out forwards;
}

@keyframes lookupErrorFade {
  0%, 70% { opacity: 1; }
  100% { opacity: 0; }
}

.lookup-history {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 6px;
}

.lookup-history-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: #1a1a1a;
  border: 1px solid #222;
  border-radius: 9999px;
  color: #aaa;
  font-size: 11px;
  cursor: pointer;
  transition: border-color 0.15s;
}

.lookup-history-chip:hover {
  border-color: #1db954;
  color: #e0e0e0;
}

.lookup-history-chip img {
  width: 16px;
  height: 16px;
  border-radius: 2px;
}

/* Track card */

.track-card {
  display: flex;
  gap: 16px;
  padding: 16px;
  background: #141414;
  border: 1px solid #222;
  border-radius: 8px;
  margin-top: 12px;
}

.track-card-art {
  width: 64px;
  height: 64px;
  border-radius: 4px;
  background: #222;
  flex-shrink: 0;
  object-fit: cover;
}

.track-card-art-placeholder {
  width: 64px;
  height: 64px;
  border-radius: 4px;
  background: #222;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #555;
  font-size: 24px;
  flex-shrink: 0;
}

.track-card-info {
  flex: 1;
  min-width: 0;
}

.track-card-name {
  font-size: 16px;
  font-weight: 600;
  color: #e0e0e0;
  margin-bottom: 2px;
}

.track-card-artist {
  font-size: 13px;
  color: #888;
  margin-bottom: 6px;
}

.track-card-meta {
  display: flex;
  gap: 12px;
  font-size: 12px;
  color: #666;
  margin-bottom: 8px;
}

.track-card-genres {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.genre-chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 9999px;
  font-size: 11px;
  font-weight: 500;
  color: #fff;
  opacity: 0.85;
}

.track-card-close {
  background: none;
  border: none;
  color: #666;
  font-size: 18px;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  align-self: flex-start;
}

.track-card-close:hover { color: #e0e0e0; }

.track-card-hint {
  font-size: 11px;
  color: #555;
  margin-top: 6px;
}

.track-card-hint a {
  color: #1db954;
  text-decoration: none;
}

.track-card-hint a:hover { text-decoration: underline; }

/* Spotify embed */

.track-embed {
  margin-top: 8px;
  border-radius: 8px;
  overflow: hidden;
}

.track-embed iframe {
  border: none;
  width: 100%;
  height: 80px;
  border-radius: 8px;
}

/* Similar tracks */

.similar-tracks {
  margin-top: 8px;
}

.similar-tracks-toggle {
  background: none;
  border: none;
  color: #888;
  font-size: 13px;
  cursor: pointer;
  padding: 4px 0;
  font-family: inherit;
}

.similar-tracks-toggle:hover { color: #1db954; }

.similar-tracks-list {
  max-height: 300px;
  overflow-y: auto;
  margin-top: 4px;
  padding: 0;
  list-style: none;
}

.similar-tracks-list li {
  padding: 4px 8px;
  font-size: 12px;
  color: #aaa;
  border-bottom: 1px solid #1a1a1a;
}

.similar-tracks-list li:hover {
  background: #111;
  color: #e0e0e0;
}

.similar-tracks-list .overlap-count {
  color: #555;
  font-size: 11px;
  margin-left: 4px;
}

/* Spotlight pulse animation */

.genre-label.spotlight {
  animation: spotlightPulse 600ms ease 3 !important;
  opacity: 1 !important;
  font-weight: 700;
  filter: brightness(1.3);
}

@keyframes spotlightPulse {
  0%, 100% { opacity: 1; filter: brightness(1.3); }
  50% { opacity: 0.4; filter: brightness(0.8); }
}

@media (max-width: 1024px) {
  .genre-map-viewport {
    height: 320px;
  }
  .minimap-canvas {
    width: 100px;
    height: 65px;
  }
}

@media (max-width: 768px) {
  .genre-map-viewport {
    height: 240px;
  }
  .minimap-canvas {
    display: none;
  }
  .btn-tool {
    padding: 6px 8px;
    font-size: 11px;
  }
  #lookup-btn .btn-text { display: none; }
  #lookup-btn::before { content: '🔍'; }
  .track-card { flex-wrap: wrap; }
  .track-card-art, .track-card-art-placeholder { width: 48px; height: 48px; }
  .lookup-history { overflow-x: auto; flex-wrap: nowrap; }
  .similar-tracks-list { max-height: 200px; }
}
