*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0f0f0f;
  --surface: #1a1a2e;
  --surface-2: #16213e;
  --primary: #e94560;
  --primary-hover: #ff6b81;
  --text: #eee;
  --text-dim: #aaa;
  --success: #00d2d3;
  --danger: #ee5a24;
  --radius: 12px;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 20px;
}

#app {
  width: 100%;
  max-width: 900px;
}

/* Home */
.home {
  text-align: center;
  padding-top: 20vh;
}

.home h1 {
  font-size: 3rem;
  margin-bottom: 0.5rem;
}

.subtitle {
  color: var(--text-dim);
  margin-bottom: 2rem;
  font-size: 1.1rem;
}

/* Buttons */
.btn {
  border: none;
  border-radius: var(--radius);
  padding: 12px 24px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-danger:hover:not(:disabled) {
  opacity: 0.8;
}

.btn-small {
  padding: 6px 12px;
  font-size: 0.85rem;
}

.btn-vote {
  background: var(--surface-2);
  color: var(--text);
  padding: 8px 16px;
  font-size: 1.2rem;
  border: 2px solid transparent;
}

.btn-vote:hover {
  border-color: var(--primary);
}

.btn-vote.active {
  border-color: var(--primary);
  background: var(--primary);
}

/* Chain view */
.chain-view {
  padding-bottom: 40px;
}

.chain-view h1 {
  font-size: 2rem;
  text-align: center;
  margin-bottom: 0.25rem;
}

.chain-view .subtitle {
  text-align: center;
  margin-bottom: 1.5rem;
}

/* Share section */
.share-section {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 24px;
  box-shadow: var(--shadow);
}

.history-col .share-section {
  margin-top: auto;
  margin-bottom: 0;
  padding: 14px;
  font-size: 0.85rem;
  opacity: 0.85;
}

.history-col .share-section h3 {
  font-size: 0.85rem;
}

.history-col .qr-code {
  max-width: 120px;
}

.history-col .share-link {
  font-size: 0.8rem;
  padding: 8px 10px;
}

.share-section h3 {
  margin-bottom: 12px;
  font-size: 1rem;
  color: var(--text-dim);
}

.share-link {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid #333;
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--text);
  font-size: 0.9rem;
  cursor: pointer;
  margin-bottom: 16px;
}

.share-link:focus {
  outline: 2px solid var(--primary);
}

.qr-container {
  text-align: center;
}

.qr-code {
  border-radius: 8px;
  background: white;
  padding: 8px;
}

/* Now Playing */
.now-playing {
  background: linear-gradient(135deg, var(--surface), var(--surface-2));
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 24px;
  text-align: center;
  box-shadow: var(--shadow);
  border: 1px solid rgba(233, 69, 96, 0.3);
  position: relative;
  overflow: hidden;
  background-size: cover;
  background-position: center;
}

.now-playing.has-artwork {
  background: none;
  background-size: cover;
  background-position: center;
}

.now-playing.has-artwork::before {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(8px);
  z-index: 0;
}

.now-playing > * {
  position: relative;
  z-index: 1;
}

.now-playing h2 {
  font-size: 1rem;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-bottom: 12px;
}

.song-title-large {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 12px;
}

.vote-display {
  color: var(--text-dim);
  font-size: 1.1rem;
  margin-bottom: 16px;
}

/* Queue */
.queue-section {
  margin-bottom: 24px;
}

.queue-section h2 {
  font-size: 1.2rem;
  margin-bottom: 16px;
  color: var(--text-dim);
}

.song-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.song-item {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: var(--shadow);
}

.song-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.song-title {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.vote-counts {
  font-size: 0.85rem;
  color: var(--text-dim);
}

.vote-buttons {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.empty-state {
  text-align: center;
  color: var(--text-dim);
  padding: 24px;
  font-style: italic;
}

/* Add Song */
.add-song-section {
  display: flex;
  gap: 10px;
  position: sticky;
  bottom: 20px;
  background: var(--bg);
  padding: 16px 0;
  align-items: flex-start;
  z-index: 200;
}

.song-input-wrap {
  flex: 1;
  position: relative;
}

.song-input {
  width: 100%;
  background: var(--surface);
  border: 1px solid #333;
  border-radius: var(--radius);
  padding: 14px 18px;
  color: var(--text);
  font-size: 1rem;
}

.song-input:focus {
  outline: 2px solid var(--primary);
  border-color: transparent;
}

.song-input::placeholder {
  color: var(--text-dim);
}

/* Song search dropdown */
.song-dropdown {
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid #333;
  border-radius: var(--radius);
  margin-bottom: 4px;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.5);
  z-index: 100;
  overflow-y: auto;
  max-height: 50vh;
}

.song-dropdown-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  cursor: pointer;
  transition: background 0.15s;
}

.song-dropdown-item:hover,
.song-dropdown-item.highlighted {
  background: var(--surface-2);
}

.song-dropdown-art {
  width: 40px;
  height: 40px;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
}

.song-dropdown-info {
  flex: 1;
  min-width: 0;
}

.song-dropdown-title {
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.song-dropdown-artist {
  font-size: 0.8rem;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Two-column layout */
.layout {
  display: flex;
  gap: 20px;
  align-items: flex-start;
}

.main-col {
  flex: 1;
  min-width: 0;
}

/* History sidebar */
.history-col {
  width: 220px;
  flex-shrink: 0;
  position: sticky;
  top: 20px;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 40px);
}

.history-header {
  font-size: 1rem;
  color: var(--text-dim);
  margin-bottom: 10px;
  padding: 0 4px;
}

.history-list {
  max-height: 70vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-right: 4px;
}

.history-list::-webkit-scrollbar {
  width: 4px;
}

.history-list::-webkit-scrollbar-track {
  background: transparent;
}

.history-list::-webkit-scrollbar-thumb {
  background: #333;
  border-radius: 2px;
}

.history-item {
  background: var(--surface);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  opacity: 0.7;
  border-left: 3px solid var(--success);
}

.history-title {
  font-size: 0.85rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-votes {
  font-size: 0.75rem;
  color: var(--text-dim);
}

/* On narrow screens, stack history below */
@media (max-width: 700px) {
  .layout {
    flex-direction: column;
  }

  .history-col {
    width: 100%;
    position: static;
    order: 1;
  }

  .main-col {
    order: 0;
  }

  .history-list {
    max-height: 200px;
  }
}

/* Spotify Controls */
.spotify-section {
  margin-bottom: 16px;
}

.btn-spotify-connect {
  background: #1DB954;
  color: #fff;
  border: none;
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-spotify-connect:hover {
  background: #1ed760;
}

.spotify-connected {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid rgba(29, 185, 84, 0.4);
}

.spotify-user {
  color: #1DB954;
  font-weight: 600;
  font-size: 0.9rem;
}

.spotify-badge {
  font-weight: 600;
  font-size: 0.9rem;
}

.device-picker {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  width: 100%;
  margin-top: 4px;
}

.btn-muted {
  background: var(--surface-2);
  color: var(--text-dim);
  border: 1px solid #333;
  font-size: 0.8rem;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
}

.btn-muted:hover {
  background: #333;
}

.btn-spotify {
  background: #1DB954;
  color: #fff;
  border: none;
  padding: 8px 16px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-spotify:hover {
  background: #1ed760;
}

.playback-controls {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 12px;
}

.playback-info {
  margin-top: 10px;
}

.progress-bar {
  width: 100%;
  height: 4px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: #1DB954;
  border-radius: 2px;
  transition: width 0.5s linear;
}

.progress-time {
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 4px;
}

.text-dim {
  color: var(--text-dim);
  font-size: 0.85rem;
}

.no-spotify-warn {
  margin-left: 6px;
  color: #f39c12;
  font-size: 0.85rem;
  cursor: help;
}
