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

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: #0a0a0f;
  color: #e0e0e0;
  min-height: 100vh;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-content {
  background: #1a1a2e;
  border: 1px solid #333;
  border-radius: 12px;
  padding: 40px;
  text-align: center;
  max-width: 400px;
  width: 90%;
}
.modal-content h2 {
  color: #00d4ff;
  margin-bottom: 8px;
}
.modal-content p {
  color: #888;
  margin-bottom: 20px;
}
.modal-content input {
  width: 100%;
  padding: 12px;
  background: #0a0a0f;
  border: 1px solid #333;
  border-radius: 8px;
  color: #fff;
  font-size: 16px;
  margin-bottom: 16px;
  text-align: center;
}
.modal-content input:focus {
  outline: none;
  border-color: #00d4ff;
}

/* Buttons */
.btn {
  padding: 10px 20px;
  border: 1px solid #333;
  border-radius: 8px;
  background: #1a1a2e;
  color: #e0e0e0;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s;
}
.btn:hover { background: #252545; border-color: #555; }
.btn-primary {
  background: #00d4ff;
  color: #000;
  border-color: #00d4ff;
  font-weight: 600;
}
.btn-primary:hover { background: #00b8e6; }
.btn-play {
  background: #00ff88;
  color: #000;
  border-color: #00ff88;
  font-weight: 700;
  font-size: 16px;
  padding: 12px 28px;
}
.btn-play:hover { background: #00e07a; }
.btn-play.playing {
  background: #ff4444;
  border-color: #ff4444;
}

/* Header */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  border-bottom: 1px solid #1a1a2e;
  background: #0d0d15;
}
header h1 {
  font-size: 20px;
  background: linear-gradient(135deg, #00d4ff, #00ff88);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.header-info {
  color: #666;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.btn-share {
  padding: 6px 14px;
  font-size: 12px;
  background: transparent;
  border: 1px solid #00d4ff55;
  color: #00d4ff;
}
.btn-share:hover {
  background: #00d4ff15;
  border-color: #00d4ff;
}

/* QR Modal */
.qr-modal {
  max-width: 300px;
}
.qr-modal h2 {
  margin-bottom: 16px;
}
#qrImage {
  display: block;
  margin: 0 auto 12px;
  border-radius: 8px;
  width: 200px;
  height: 200px;
}
.qr-url {
  font-size: 13px;
  color: #00d4ff;
  word-break: break-all;
  margin-bottom: 16px;
  user-select: all;
  -webkit-user-select: all;
}

/* Main Layout */
main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* Now Playing */
.now-playing {
  background: #111120;
  border: 1px solid #1a1a2e;
  border-radius: 12px;
  padding: 24px;
}
.now-playing-info {
  margin-bottom: 16px;
}
.now-playing-info .label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 2px;
  color: #00d4ff;
  margin-bottom: 4px;
}
.now-playing-row {
  display: flex;
  align-items: center;
  gap: 16px;
}
.now-playing-thumb {
  width: 100px;
  height: 75px;
  object-fit: cover;
  border-radius: 8px;
  flex-shrink: 0;
}
.track-title {
  font-size: 22px;
  font-weight: 600;
}
.track-meta {
  font-size: 13px;
  color: #666;
  margin-top: 4px;
}

#waveform {
  width: 100%;
  height: 120px;
  background: #0a0a12;
  border-radius: 8px;
  margin-bottom: 16px;
}

/* Progress Bar */
.progress-bar {
  width: 100%;
  height: 6px;
  background: #1a1a2e;
  border-radius: 3px;
  cursor: pointer;
  margin-bottom: 4px;
  position: relative;
}
.progress-bar:hover,
.progress-bar.dragging {
  height: 8px;
}
.progress-fill {
  height: 100%;
  background: #00d4ff;
  border-radius: 3px;
  width: 0%;
  pointer-events: none;
  transition: height 0.15s;
}
.progress-thumb {
  position: absolute;
  top: 50%;
  left: 0%;
  width: 14px;
  height: 14px;
  background: #00d4ff;
  border: 2px solid #fff;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s, transform 0.15s;
  box-shadow: 0 0 6px rgba(0, 212, 255, 0.5);
}
.progress-bar:hover .progress-thumb,
.progress-bar.dragging .progress-thumb {
  opacity: 1;
}
.progress-bar.dragging .progress-thumb {
  transform: translate(-50%, -50%) scale(1.3);
  box-shadow: 0 0 12px rgba(0, 212, 255, 0.7);
}
.progress-time {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: #555;
  margin-bottom: 12px;
}

.transport {
  display: flex;
  align-items: center;
  gap: 12px;
}
.volume-control {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  color: #666;
  font-size: 13px;
}
.volume-control input[type="range"] {
  width: 100px;
  accent-color: #00d4ff;
}

.dj-status {
  margin-top: 12px;
  font-size: 13px;
  color: #00ff88;
  min-height: 20px;
}

/* Add Song */
.add-song {
  background: #111120;
  border: 1px solid #1a1a2e;
  border-radius: 12px;
  padding: 24px;
}
.add-song h2 {
  font-size: 16px;
  margin-bottom: 16px;
}
.smart-form {
  display: flex;
  gap: 12px;
  align-items: center;
}
.smart-form input[type="text"] {
  flex: 1;
  padding: 10px 12px;
  background: #0a0a0f;
  border: 1px solid #333;
  border-radius: 8px;
  color: #e0e0e0;
  font-size: 14px;
}
.smart-form input:focus {
  outline: none;
  border-color: #00d4ff;
}

/* Suggestions Button */
.btn-suggest {
  margin-top: 12px;
  padding: 10px 20px;
  font-size: 13px;
  background: transparent;
  border: 1px solid #ff88ff55;
  color: #ff88ff;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  width: 100%;
}
.btn-suggest:hover:not(:disabled) {
  background: #ff88ff15;
  border-color: #ff88ff;
}
.btn-suggest:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.btn-suggest.loading {
  opacity: 0.6;
  pointer-events: none;
}

/* Search Results */
.search-results {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}
.search-result {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: #0d0d18;
  border-radius: 8px;
  transition: background 0.2s;
}
.search-result:hover { background: #151528; }
.search-result img {
  width: 80px;
  height: 60px;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
}
.search-result .result-info {
  flex: 1;
  min-width: 0;
}
.search-result .result-title {
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.search-result .result-meta {
  font-size: 12px;
  color: #666;
  margin-top: 2px;
}
.search-result .btn-add {
  padding: 6px 14px;
  font-size: 12px;
  background: #00d4ff15;
  border: 1px solid #00d4ff55;
  color: #00d4ff;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
  flex-shrink: 0;
}
.search-result .btn-add:hover {
  background: #00d4ff30;
  border-color: #00d4ff;
}
.search-close {
  display: block;
  margin-left: auto;
  background: transparent;
  border: 1px solid #333;
  color: #888;
  font-size: 14px;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}
.search-close:hover {
  border-color: #ff4444;
  color: #ff4444;
}
.search-loading {
  text-align: center;
  padding: 20px;
  color: #666;
  font-size: 13px;
}
.search-loading-typeahead {
  padding: 10px;
  font-size: 12px;
  color: #555;
}

/* Queue */
.queue-section {
  background: #111120;
  border: 1px solid #1a1a2e;
  border-radius: 12px;
  padding: 24px;
}
.queue-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.queue-header h2 { font-size: 16px; }
#queueCount { color: #666; font-size: 13px; }

.queue-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.queue-empty {
  text-align: center;
  padding: 32px;
  color: #444;
  font-size: 14px;
}

.queue-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: #0d0d18;
  border-radius: 8px;
  transition: background 0.2s;
}
.queue-item:hover { background: #151528; }
.queue-item.now-playing-item {
  background: #0a1a2e;
  border: 1px solid #00d4ff33;
}
.queue-item.downloading {
  opacity: 0.6;
}

.queue-item .position {
  font-size: 13px;
  color: #444;
  min-width: 24px;
  text-align: center;
}
.queue-thumb {
  width: 56px;
  height: 42px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
}
.queue-item .song-info {
  flex: 1;
  min-width: 0;
}
.queue-item .song-title {
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.queue-item .song-detail {
  font-size: 12px;
  color: #555;
  margin-top: 2px;
}
.queue-item .song-tags {
  display: flex;
  gap: 6px;
  margin-top: 4px;
}
.tag {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  background: #1a1a2e;
  color: #888;
}
.tag.bpm { color: #00d4ff; border: 1px solid #00d4ff33; }
.tag.key { color: #ff88ff; border: 1px solid #ff88ff33; }
.tag.energy { color: #00ff88; border: 1px solid #00ff8833; }

.queue-item .actions {
  display: flex;
  gap: 6px;
}
.queue-item .actions button {
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 6px;
  background: transparent;
  border: 1px solid #333;
  color: #888;
  cursor: pointer;
  transition: all 0.2s;
}
.queue-item .actions .vote-btn:hover {
  border-color: #00ff88;
  color: #00ff88;
}
.queue-item .actions .remove-btn:hover,
.queue-item .actions .cancel-btn:hover {
  border-color: #ff4444;
  color: #ff4444;
}
.queue-item .actions .cancel-btn {
  border-color: #ff444466;
  color: #ff4444;
}

/* History */
.history-section {
  opacity: 0.7;
  border-color: #151520;
}
.history-section h2 { color: #888; }
#historyCount { color: #555; font-size: 13px; }
.history-item {
  background: #0a0a12 !important;
}
.history-item .song-title {
  color: #999;
}
.history-item .position {
  color: #555;
  font-size: 10px;
}
.queue-item .actions .requeue-btn:hover {
  border-color: #00d4ff;
  color: #00d4ff;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: #0a0a0f; }
::-webkit-scrollbar-thumb { background: #333; border-radius: 3px; }

/* Responsive — Desktop */
@media (min-width: 1024px) {
  header {
    padding: 16px calc((100% - 1400px) / 2 + 24px);
  }

  main {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto auto;
    gap: 24px;
    align-items: start;
  }

  .now-playing {
    grid-column: 1;
    grid-row: 1 / -1;
    position: sticky;
    top: 24px;
    max-height: calc(100vh - 48px);
    overflow-y: auto;
  }

  .add-song {
    grid-column: 2;
    grid-row: 1;
  }

  .queue-section {
    grid-column: 2;
    grid-row: 2;
  }

  .queue-section.history-section {
    grid-column: 2;
    grid-row: 3;
  }

  .queue-list {
    max-height: 400px;
    overflow-y: auto;
  }

  #waveform {
    height: 150px;
  }

  .now-playing-thumb {
    width: 140px;
    height: 105px;
  }

  .track-title {
    font-size: 24px;
  }
}

/* Responsive — Mobile */
@media (max-width: 600px) {
  header {
    padding: 12px 16px;
    position: sticky;
    top: 0;
    z-index: 10;
  }
  header h1 { font-size: 17px; }

  main {
    padding: 12px;
    gap: 12px;
  }

  /* Now Playing — compact on mobile */
  .now-playing {
    padding: 16px;
    border-radius: 10px;
  }
  .now-playing-thumb {
    width: 72px;
    height: 54px;
  }
  .now-playing-row {
    gap: 12px;
  }
  .track-title {
    font-size: 17px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .track-meta {
    font-size: 11px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  #waveform {
    height: 80px;
    margin-bottom: 12px;
  }
  .progress-bar {
    height: 10px;
  }
  .progress-bar:hover, .progress-bar.dragging {
    height: 12px;
  }
  .progress-thumb {
    width: 20px;
    height: 20px;
    opacity: 1;
  }
  .transport {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .btn-play {
    font-size: 15px;
    padding: 12px 16px;
  }
  .volume-control {
    grid-column: 1 / -1;
    margin-left: 0;
    justify-content: center;
  }
  .volume-control input[type="range"] {
    width: 100%;
    flex: 1;
  }
  .dj-status {
    font-size: 12px;
    margin-top: 8px;
  }

  /* Add Song — stack vertically */
  .add-song {
    padding: 16px;
    border-radius: 10px;
  }
  .add-song h2 {
    font-size: 15px;
    margin-bottom: 12px;
  }
  .smart-form {
    flex-direction: column;
    gap: 10px;
  }
  .smart-form input[type="text"] {
    width: 100%;
    font-size: 16px; /* prevents iOS zoom on focus */
    padding: 12px;
  }
  .smart-form .btn-primary {
    width: 100%;
    padding: 14px;
    font-size: 15px;
  }
  .btn-suggest {
    font-size: 14px;
    padding: 12px;
  }
  .search-result {
    gap: 8px;
    padding: 8px 10px;
  }
  .search-result img {
    width: 64px;
    height: 48px;
  }
  .search-result .result-title {
    font-size: 13px;
  }
  .search-result .result-meta {
    font-size: 11px;
  }

  /* Queue — tighter spacing */
  .queue-section {
    padding: 16px;
    border-radius: 10px;
  }
  .queue-item {
    padding: 10px 12px;
    gap: 8px;
  }
  .queue-item .position {
    min-width: 20px;
    font-size: 12px;
  }
  .queue-thumb {
    width: 48px;
    height: 36px;
  }
  .queue-item .song-title {
    font-size: 13px;
  }
  .queue-item .song-detail {
    font-size: 11px;
  }
  .queue-item .song-tags {
    flex-wrap: wrap;
    gap: 4px;
  }
  .queue-item .actions {
    flex-direction: column;
    gap: 4px;
  }
  .queue-item .actions button {
    padding: 6px 10px;
    font-size: 12px;
  }

  /* History */
  .history-section {
    padding: 16px;
    border-radius: 10px;
  }
}
