/* ===== VARIABLES ===== */
:root {
  --bg: #0d0d17;
  --surface: #13131f;
  --surface-2: #1a1a2a;
  --surface-3: #222236;
  --accent: #7c3aed;
  --accent-hover: #6d28d9;
  --accent-dim: rgba(124, 58, 237, 0.18);
  --green: #10b981;
  --red: #ef4444;
  --yellow: #f59e0b;
  --text: #e8e8f0;
  --text-2: #8080a0;
  --text-3: #50506a;
  --border: #252538;
  --border-hover: #3a3a55;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --transition: 0.18s ease;
}

/* ===== RESET ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}
button { cursor: pointer; font-family: inherit; border: none; background: none; }
input { font-family: inherit; outline: none; }
img { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--surface); }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-hover); }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  transition: background var(--transition), transform var(--transition), opacity var(--transition);
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
  background: var(--surface-3);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--border); }

.btn-ghost {
  background: transparent;
  color: var(--text-2);
  padding: 6px 10px;
  font-size: 0.85rem;
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-2);
  border: none;
  transition: background var(--transition), color var(--transition);
  cursor: pointer;
}
.btn-icon:hover { background: var(--surface-3); color: var(--text); }

.btn-skip {
  background: var(--surface-3);
  color: var(--text-2);
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid var(--border);
  transition: all var(--transition);
  white-space: nowrap;
}
.btn-skip:hover { background: var(--red); color: #fff; border-color: var(--red); }
.btn-skip.voted { background: var(--red); color: #fff; border-color: var(--red); }

/* ===== INPUTS ===== */
.input {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 10px 14px;
  font-size: 0.9rem;
  width: 100%;
  transition: border-color var(--transition);
}
.input::placeholder { color: var(--text-3); }
.input:focus { border-color: var(--accent); }

/* ===== LANDING PAGE ===== */
body.landing {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.landing-container {
  max-width: 640px;
  width: 100%;
  text-align: center;
}

.logo {
  margin-bottom: 48px;
}

.logo-icon {
  display: inline-block;
  font-size: 3rem;
  margin-bottom: 12px;
  color: var(--accent);
  filter: drop-shadow(0 0 20px rgba(124,58,237,0.5));
}

.logo h1 {
  font-size: 2.8rem;
  font-weight: 800;
  letter-spacing: -1px;
  background: linear-gradient(135deg, #c4b5fd, var(--accent), #818cf8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.tagline {
  color: var(--text-2);
  font-size: 1.05rem;
  margin-top: 8px;
}

.landing-cards {
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 32px;
  width: 100%;
  text-align: left;
  transition: border-color var(--transition);
}
.card:hover { border-color: var(--border-hover); }

.card h2 {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 6px;
}

.card p {
  color: var(--text-2);
  font-size: 0.88rem;
  margin-bottom: 18px;
}

.divider {
  color: var(--text-3);
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 2px;
  text-transform: uppercase;
}

.input-group {
  display: flex;
  gap: 8px;
}

.input-group .input {
  flex: 1;
}

/* ===== ROOM PAGE ===== */
body.room-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* Header */
.room-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  min-height: 56px;
}

.room-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: -0.3px;
  color: var(--text);
}

.logo-icon-sm {
  color: var(--accent);
  font-size: 1.2rem;
}

.room-info {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 5px 10px;
}

.room-label {
  color: var(--text-3);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.room-code {
  font-family: 'Courier New', monospace;
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 2px;
}

.participants-info {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--text-2);
  font-size: 0.88rem;
  padding: 0 4px;
}

/* Main Layout */
.room-main {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 0;
  flex: 1;
  overflow: hidden;
}

/* Player Section */
.player-section {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-right: 1px solid var(--border);
  overflow: hidden;
}

.player-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  flex-shrink: 0;
  max-height: calc(100vh - 56px - 64px - 1px);
}

.player-wrapper iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.player-idle {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-3);
  gap: 12px;
  background: #07070f;
}

.idle-icon {
  font-size: 3rem;
  opacity: 0.3;
}

.player-idle p {
  font-size: 0.9rem;
  opacity: 0.5;
}

.current-song {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  min-height: 64px;
  flex-shrink: 0;
}

.current-thumb {
  width: 48px;
  height: 36px;
  border-radius: 4px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--surface-3);
}

.current-meta {
  flex: 1;
  min-width: 0;
}

.current-title {
  font-size: 0.88rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.current-channel {
  font-size: 0.78rem;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Sidebar */
.sidebar-section {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  overflow: hidden;
}

.search-bar {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.search-input {
  flex: 1;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 9px 13px;
  font-size: 0.88rem;
  transition: border-color var(--transition);
}
.search-input::placeholder { color: var(--text-3); }
.search-input:focus { border-color: var(--accent); }

/* Tabs */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  padding: 0 4px;
}

.tab {
  flex: 1;
  padding: 10px 8px;
  font-size: 0.83rem;
  font-weight: 600;
  color: var(--text-2);
  border-bottom: 2px solid transparent;
  transition: color var(--transition), border-color var(--transition);
  text-align: center;
}
.tab:hover { color: var(--text); }
.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* Tab Content */
.tab-content {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}
.tab-content.hidden { display: none; }

/* Song Lists */
.song-list {
  display: flex;
  flex-direction: column;
}

.empty-state {
  padding: 32px 16px;
  text-align: center;
  color: var(--text-3);
  font-size: 0.85rem;
}

/* Song Item (Queue) */
.song-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
.song-item:hover { background: var(--surface-2); }
.song-item:last-child { border-bottom: none; }

.song-thumb {
  width: 56px;
  height: 42px;
  border-radius: 4px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--surface-3);
}

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

.song-title {
  font-size: 0.83rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.song-meta {
  font-size: 0.75rem;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.song-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

/* Vote Buttons */
.vote-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
}

.vote-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 22px;
  border-radius: 4px;
  font-size: 0.75rem;
  color: var(--text-3);
  transition: color var(--transition), background var(--transition);
  cursor: pointer;
  border: none;
  background: none;
}
.vote-btn:hover { background: var(--surface-3); color: var(--text); }
.vote-btn.up.active { color: var(--green); }
.vote-btn.down.active { color: var(--red); }

.vote-count {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-2);
  min-width: 18px;
  text-align: center;
  line-height: 1;
}
.vote-count.positive { color: var(--green); }
.vote-count.negative { color: var(--red); }

.fav-btn {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  color: var(--text-3);
  transition: color var(--transition), background var(--transition);
  cursor: pointer;
  border: none;
  background: none;
  font-size: 1rem;
  line-height: 1;
}
.fav-btn:hover { background: var(--surface-3); color: var(--red); }
.fav-btn.active { color: var(--red); }

/* Search Result Item */
.search-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
.search-item:hover { background: var(--surface-2); }
.search-item:last-child { border-bottom: none; }

.add-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent-dim);
  color: var(--accent);
  font-size: 1.2rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  flex-shrink: 0;
  line-height: 1;
}
.add-btn:hover { background: var(--accent); color: #fff; }

/* Favorite Item */
.fav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
.fav-item:hover { background: var(--surface-2); }
.fav-item:last-child { border-bottom: none; }

.fav-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.remove-fav-btn {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  color: var(--text-3);
  font-size: 0.9rem;
  transition: color var(--transition), background var(--transition);
  cursor: pointer;
  border: none;
  background: none;
}
.remove-fav-btn:hover { background: var(--surface-3); color: var(--red); }

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.8);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 24px;
}
.modal-overlay.hidden { display: none; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border-hover);
  border-radius: 16px;
  padding: 36px 32px;
  width: 100%;
  max-width: 360px;
  box-shadow: var(--shadow);
  text-align: center;
}

.modal h2 {
  font-size: 1.4rem;
  font-weight: 800;
  margin-bottom: 6px;
}

.modal p {
  color: var(--text-2);
  font-size: 0.88rem;
  margin-bottom: 20px;
}

.modal .input {
  margin-bottom: 12px;
  text-align: center;
  font-size: 1rem;
}

/* ===== TOAST ===== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(0);
  background: var(--surface-3);
  border: 1px solid var(--border-hover);
  color: var(--text);
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 0.85rem;
  font-weight: 500;
  z-index: 2000;
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
  white-space: nowrap;
  max-width: 90vw;
  overflow: hidden;
  text-overflow: ellipsis;
}
.toast.hidden {
  opacity: 0;
  transform: translateX(-50%) translateY(8px);
}
.toast.success { border-color: var(--green); color: var(--green); }
.toast.warn { border-color: var(--yellow); color: var(--yellow); }
.toast.error { border-color: var(--red); color: var(--red); }

/* ===== LOADING SPINNER ===== */
.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== COPY LINK FEEDBACK ===== */
.copy-success { color: var(--green) !important; }

/* ===== PARTICIPANTS POPOVER ===== */
.participants-btn {
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--text-2);
  font-size: 0.88rem;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: background var(--transition), color var(--transition);
}
.participants-btn:hover { background: var(--surface-2); color: var(--text); }

.participants-popover {
  position: absolute;
  top: 56px;
  right: 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  z-index: 500;
  min-width: 180px;
  box-shadow: var(--shadow);
}
.participants-popover.hidden { display: none; }
.participants-popover h4 {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-3);
  margin-bottom: 10px;
}
.participant-name {
  font-size: 0.85rem;
  padding: 4px 0;
  color: var(--text-2);
  display: flex;
  align-items: center;
  gap: 6px;
}
.participant-dot {
  width: 7px;
  height: 7px;
  background: var(--green);
  border-radius: 50%;
  flex-shrink: 0;
}

/* ===== PLAYLIST SECTION ===== */
.playlist-section {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.playlist-toggle {
  width: 100%;
  text-align: left;
  font-size: 0.82rem;
  padding: 4px 6px;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-2);
  cursor: pointer;
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  transition: color var(--transition), background var(--transition);
}
.playlist-toggle:hover { color: var(--text); background: var(--surface-2); }

.playlist-toggle-icon {
  font-size: 1rem;
  font-weight: 600;
  transition: transform 0.2s;
  display: inline-block;
}
.playlist-toggle.open .playlist-toggle-icon { transform: rotate(45deg); }

.playlist-input-area {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}
.playlist-input-area .input {
  flex: 1;
  font-size: 0.85rem;
  padding: 8px 11px;
}
.playlist-input-area.hidden { display: none; }

/* ===== MOBILE ===== */
@media (max-width: 768px) {
  body.room-page { overflow: auto; }

  .room-header { padding: 10px 14px; }
  .room-brand span:last-child { display: none; }

  .room-main {
    grid-template-columns: 1fr;
    overflow: visible;
    height: auto;
  }

  .player-section {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .player-wrapper {
    max-height: none;
  }

  .sidebar-section {
    height: 70vh;
    min-height: 400px;
  }

  .search-bar { padding: 10px; gap: 6px; }
  .search-bar .btn { padding: 9px 14px; font-size: 0.85rem; }

  .song-item, .search-item, .fav-item {
    padding: 9px 10px;
    gap: 8px;
  }

  .song-thumb { width: 48px; height: 36px; }

  .participants-popover { right: 8px; }

  .landing-cards { padding: 0 4px; }
  .card { padding: 22px 20px; }
  .logo h1 { font-size: 2.2rem; }

  .modal { padding: 28px 20px; }
}

@media (max-width: 400px) {
  .room-code { font-size: 0.78rem; letter-spacing: 1px; }
  .room-info { padding: 4px 8px; }
}
