/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0d0d0f;
  --bg2: #16161a;
  --bg3: #1e1e24;
  --bg4: #26262e;
  --border: #2e2e38;
  --accent: #7c6af7;
  --accent2: #5b4de0;
  --accent3: #9d8fff;
  --text: #e8e8f0;
  --text2: #9999b0;
  --text3: #5a5a72;
  --red: #f74a4a;
  --green: #4af7a0;
  --yellow: #f7c94a;
  --radius: 10px;
  --shadow: 0 4px 24px rgba(0,0,0,0.5);
}

html, body { height: 100%; font-family: 'Inter', system-ui, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }

a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: inherit; }
input, textarea { font-family: inherit; }
img { display: block; }

/* === Scrollbar === */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg2); }
::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* === Utility === */
.hidden { display: none !important; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* === Buttons === */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius); border: none;
  font-size: 13px; font-weight: 600; transition: all 0.15s; line-height: 1;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent2); }
.btn-secondary { background: var(--bg4); color: var(--text); }
.btn-secondary:hover { background: var(--border); }
.btn-ghost { background: transparent; color: var(--text2); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg4); color: var(--text); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { opacity: 0.85; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { padding: 7px; border-radius: 8px; background: var(--bg4); border: none; color: var(--text2); transition: all 0.15s; }
.btn-icon:hover { background: var(--accent); color: #fff; }
.btn-icon svg { display: block; }

/* === Inputs === */
.input {
  background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); padding: 9px 12px; font-size: 14px; width: 100%; outline: none; transition: border 0.15s;
}
.input:focus { border-color: var(--accent); }
.input::placeholder { color: var(--text3); }

/* === Badge === */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 700; }
.badge-accent { background: rgba(124,106,247,0.2); color: var(--accent3); }
.badge-green { background: rgba(74,247,160,0.15); color: var(--green); }
.badge-red { background: rgba(247,74,74,0.15); color: var(--red); }

/* === Header === */
#app-header {
  height: 54px; background: var(--bg2); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; padding: 0 20px;
  position: sticky; top: 0; z-index: 100;
}
.logo { display: flex; align-items: center; gap: 10px; font-size: 18px; font-weight: 800; }
.logo-icon { width: 32px; height: 32px; background: var(--accent); border-radius: 8px; display: flex; align-items: center; justify-content: center; }
.logo span { background: linear-gradient(135deg, var(--accent3), var(--accent)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }

.header-right { display: flex; align-items: center; gap: 12px; }
.user-chip { display: flex; align-items: center; gap: 8px; background: var(--bg3); border: 1px solid var(--border); border-radius: 99px; padding: 4px 12px 4px 4px; cursor: pointer; transition: border 0.15s; }
.user-chip:hover { border-color: var(--accent); }
.user-chip .avatar { width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; color: #fff; }
.user-chip .username { font-size: 13px; font-weight: 600; }

/* === Pages === */
.page { display: none; height: calc(100vh - 54px); overflow-y: auto; }
.page.active { display: flex; flex-direction: column; }

/* === HOME PAGE === */
#page-home { padding: 32px 20px; max-width: 1100px; margin: 0 auto; width: 100%; }

.home-hero { text-align: center; margin-bottom: 40px; }
.home-hero h1 { font-size: 36px; font-weight: 900; margin-bottom: 10px; }
.home-hero h1 span { background: linear-gradient(135deg, var(--accent3), var(--accent)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.home-hero p { color: var(--text2); font-size: 16px; }

.home-actions { display: flex; gap: 16px; justify-content: center; flex-wrap: wrap; margin-bottom: 40px; }
.home-actions .big-btn {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  background: var(--bg2); border: 2px solid var(--border); border-radius: 16px;
  padding: 24px 32px; cursor: pointer; transition: all 0.2s; min-width: 180px;
}
.home-actions .big-btn:hover { border-color: var(--accent); background: var(--bg3); transform: translateY(-2px); }
.home-actions .big-btn svg { color: var(--accent); }
.home-actions .big-btn span { font-size: 15px; font-weight: 700; }
.home-actions .big-btn small { font-size: 12px; color: var(--text2); }

.section-title { font-size: 16px; font-weight: 700; margin-bottom: 14px; display: flex; align-items: center; gap: 8px; }
.section-title::after { content: ''; flex: 1; height: 1px; background: var(--border); }

/* Room cards */
.rooms-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.room-card {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; cursor: pointer; transition: all 0.15s;
}
.room-card:hover { border-color: var(--accent); background: var(--bg3); }
.room-card-thumb { width: 100%; aspect-ratio: 16/9; background: var(--bg4); border-radius: 6px; margin-bottom: 10px; overflow: hidden; }
.room-card-thumb img { width: 100%; height: 100%; object-fit: cover; }
.room-card-thumb .no-thumb { display: flex; align-items: center; justify-content: center; height: 100%; color: var(--text3); }
.room-card h3 { font-size: 14px; font-weight: 700; margin-bottom: 4px; }
.room-card-meta { display: flex; align-items: center; gap: 8px; color: var(--text2); font-size: 12px; }

.empty-state { text-align: center; padding: 40px; color: var(--text3); }
.empty-state svg { margin: 0 auto 12px; opacity: 0.4; }

/* === MODAL === */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7); backdrop-filter: blur(4px);
  z-index: 200; display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 16px;
  padding: 28px; width: 100%; max-width: 480px; position: relative;
}
.modal h2 { font-size: 20px; font-weight: 800; margin-bottom: 20px; }
.modal-close { position: absolute; top: 16px; right: 16px; background: none; border: none; color: var(--text2); cursor: pointer; padding: 4px; }
.modal-close:hover { color: var(--text); }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; color: var(--text2); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.5px; }
.form-row { display: flex; gap: 10px; }
.form-row .input { flex: 1; }

/* Avatar picker */
.avatar-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.avatar-opt { width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 18px; cursor: pointer; border: 2px solid transparent; transition: all 0.15s; }
.avatar-opt:hover { transform: scale(1.1); }
.avatar-opt.selected { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(124,106,247,0.4); }

/* === ROOM PAGE === */
/* Flex column: header (fixed) + body (fills rest) */
#page-room { display: none; height: calc(100vh - 54px); overflow: hidden; flex-direction: column; }
#page-room.active { display: flex; }

#room-header {
  flex-shrink: 0; background: var(--bg2); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; padding: 8px 16px;
}
.room-info { display: flex; align-items: center; gap: 10px; }
.room-id-badge { font-size: 11px; color: var(--text2); background: var(--bg4); padding: 3px 10px; border-radius: 6px; font-family: monospace; }

/* Body: 2-column grid (left-panel | sidebar) */
#room-body {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: 1fr 320px;
  overflow: hidden;
}

/* Left column: video + playback bar fills all available height */
#left-panel { display: flex; flex-direction: column; overflow: hidden; min-height: 0; background: #000; }

#video-area { flex: 1; min-height: 0; background: #000; position: relative; display: flex; flex-direction: column; }

/* Banners (mute, reconnect) — float over video */
.player-banner {
  position: absolute; top: 8px; left: 50%; transform: translateX(-50%); z-index: 10;
  background: rgba(0,0,0,0.78); backdrop-filter: blur(6px);
  color: #fff; font-size: 12px; font-weight: 600; padding: 6px 14px; border-radius: 99px;
  display: flex; align-items: center; gap: 6px;
  border: 1px solid rgba(255,255,255,0.15); transition: background 0.15s; white-space: nowrap;
}
#mute-banner { cursor: pointer; }
#mute-banner:hover, #reconnect-banner { background: rgba(124,106,247,0.8); }
#mute-banner, #reconnect-banner { position: absolute; top: 8px; left: 50%; transform: translateX(-50%); z-index: 10;
  background: rgba(0,0,0,0.78); backdrop-filter: blur(6px); color: #fff; font-size: 12px; font-weight: 600;
  padding: 6px 14px; border-radius: 99px; display: flex; align-items: center; gap: 6px;
  border: 1px solid rgba(255,255,255,0.15); white-space: nowrap; }
#reconnect-banner { background: rgba(247,74,74,0.85); top: auto; bottom: 8px; }

/* Buffering spinner */
#buffering-spinner {
  position: absolute; inset: 0; z-index: 9;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.35);
}
.spinner-ring {
  width: 36px; height: 36px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.2);
  border-top-color: #fff;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Video error overlay */
#video-error {
  position: absolute; inset: 0; z-index: 9;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  background: rgba(0,0,0,0.8); color: var(--red); font-size: 13px; font-weight: 600;
}
#video-error svg { color: var(--red); }

/* Now-playing title in header */
.now-playing-title {
  font-size: 13px; color: var(--text2); white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; max-width: 300px;
}
#player-wrapper { flex: 1; min-height: 0; width: 100%; background: #000; position: relative; }
#yt-player { width: 100%; height: 100%; }
.no-video-msg {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--text3); gap: 10px; background: var(--bg); font-size: 13px;
}

/* Queue tab panel */
#tab-queue { flex-direction: column; overflow: hidden; min-height: 0; }
.queue-add-bar {
  flex-shrink: 0;
  display: flex; gap: 6px; padding: 8px 10px;
  background: var(--bg2); border-bottom: 1px solid var(--border);
}
.queue-add-bar .input { flex: 1; min-width: 0; font-size: 13px; }
.queue-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 8px; }
.queue-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; padding: 0 2px; }
.queue-header h3 { font-size: 12px; font-weight: 700; color: var(--text2); text-transform: uppercase; letter-spacing: 0.5px; }
.queue-list { display: flex; flex-direction: column; gap: 6px; }
.queue-empty-hint { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 24px 0; color: var(--text3); font-size: 13px; }
.queue-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  background: var(--bg3); border-radius: 8px; border: 1px solid transparent; transition: all 0.15s; cursor: pointer;
}
.queue-item.active { border-color: var(--accent); background: rgba(124,106,247,0.1); }
.queue-item:hover { background: var(--bg4); }
.queue-item .thumb { width: 64px; height: 36px; border-radius: 4px; background: var(--bg4); overflow: hidden; flex-shrink: 0; }
.queue-item .thumb img { width: 100%; height: 100%; object-fit: cover; }
.queue-item .info { flex: 1; min-width: 0; }
.queue-item .info .title { font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.queue-item .info .meta { font-size: 11px; color: var(--text2); }
.queue-item .actions { display: flex; gap: 4px; opacity: 0; transition: opacity 0.15s; flex-shrink: 0; }
.queue-item:hover .actions { opacity: 1; }
.queue-num { width: 20px; text-align: center; font-size: 11px; color: var(--text3); flex-shrink: 0; }

/* Sidebar: right column — full height, flex column */
#room-sidebar {
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--bg2); border-left: 1px solid var(--border);
}
.sidebar-tabs { display: flex; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.sidebar-tab {
  flex: 1; padding: 11px 8px; text-align: center; font-size: 12px; font-weight: 700;
  color: var(--text2); cursor: pointer; border-bottom: 2px solid transparent; transition: all 0.15s;
  display: flex; align-items: center; justify-content: center; gap: 5px;
}
.sidebar-tab:hover { color: var(--text); }
.sidebar-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.tab-panel { display: none; flex: 1; flex-direction: column; overflow: hidden; min-height: 0; }
.tab-panel.active { display: flex; }

/* Chat */
#chat-messages { flex: 1; min-height: 0; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.chat-msg { display: flex; gap: 8px; }
.chat-msg .av { width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 13px; flex-shrink: 0; }
.chat-msg .content { flex: 1; min-width: 0; }
.chat-msg .name { font-size: 11px; font-weight: 700; color: var(--text2); }
.chat-msg .name .time { font-weight: 400; margin-left: 6px; color: var(--text3); }
.chat-msg .text { font-size: 13px; word-break: break-word; line-height: 1.5; }
.chat-msg.system { padding: 2px 0; }
.chat-msg.system .text { color: var(--text3); font-style: italic; font-size: 12px; }
.chat-input-area { padding: 10px 12px; border-top: 1px solid var(--border); display: flex; gap: 8px; flex-shrink: 0; background: var(--bg2); }
.chat-input-area .input { flex: 1; }

/* Users panel */
#users-list { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.user-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; }
.user-item:hover { background: var(--bg3); }
.user-item .av { width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 14px; flex-shrink: 0; }
.user-item .name { flex: 1; font-size: 13px; font-weight: 600; }
.user-item .badges { display: flex; gap: 4px; }

/* Playback bar */
.playback-bar {
  background: var(--bg2); border-top: 1px solid var(--border);
  padding: 10px 14px; display: flex; align-items: center; gap: 10px; flex-shrink: 0;
}
.pb-controls { display: flex; align-items: center; gap: 6px; }
.pb-time { font-size: 11px; color: var(--text2); font-variant-numeric: tabular-nums; min-width: 76px; flex-shrink: 0; }
.pb-progress { flex: 1; -webkit-appearance: none; height: 4px; border-radius: 2px; background: var(--bg4); outline: none; cursor: pointer; }
.pb-progress::-webkit-slider-thumb { -webkit-appearance: none; width: 12px; height: 12px; border-radius: 50%; background: var(--accent); cursor: pointer; }
.pb-progress:disabled { opacity: 0.4; cursor: default; }
.pb-volume { display: flex; align-items: center; gap: 6px; }
.pb-volume-slider { width: 60px; -webkit-appearance: none; height: 4px; border-radius: 2px; background: var(--bg4); outline: none; cursor: pointer; }
.pb-volume-slider::-webkit-slider-thumb { -webkit-appearance: none; width: 10px; height: 10px; border-radius: 50%; background: var(--text2); cursor: pointer; }
.host-only-hint { font-size: 11px; color: var(--text3); white-space: nowrap; }

/* Invite modal */
.invite-code-box { background: var(--bg3); border: 1px solid var(--border); border-radius: 12px; padding: 16px; }
.invite-label { font-size: 11px; font-weight: 700; color: var(--text2); text-transform: uppercase; letter-spacing: 0.5px; }
.invite-code-display { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; }
.invite-code-display span { font-size: 28px; font-weight: 900; font-family: monospace; letter-spacing: 4px; color: var(--accent3); }

/* === PLAYLISTS PAGE === */
#page-playlists { padding: 24px; max-width: 900px; margin: 0 auto; width: 100%; }
.pl-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.pl-top h1 { font-size: 24px; font-weight: 800; }
.playlists-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; margin-bottom: 32px; }
.pl-card {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; cursor: pointer; transition: all 0.15s;
}
.pl-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.pl-card-cover { width: 100%; aspect-ratio: 16/9; background: var(--bg4); position: relative; overflow: hidden; }
.pl-card-cover img { width: 100%; height: 100%; object-fit: cover; }
.pl-card-cover .cover-grid { display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; height: 100%; }
.pl-card-cover .cover-grid img { width: 100%; height: 100%; object-fit: cover; }
.pl-card-cover .cover-grid .empty-cell { background: var(--bg3); }
.pl-card-body { padding: 12px; }
.pl-card-body h3 { font-size: 14px; font-weight: 700; margin-bottom: 4px; }
.pl-card-body .meta { font-size: 12px; color: var(--text2); }

/* Playlist detail */
#pl-detail { display: none; }
#pl-detail.active { display: block; }
.pl-detail-header { display: flex; align-items: flex-start; gap: 20px; margin-bottom: 24px; padding: 20px; background: var(--bg2); border-radius: 12px; border: 1px solid var(--border); }
.pl-detail-cover { width: 120px; height: 90px; border-radius: 8px; background: var(--bg4); overflow: hidden; flex-shrink: 0; }
.pl-detail-cover img { width: 100%; height: 100%; object-fit: cover; }
.pl-detail-info { flex: 1; }
.pl-detail-info h2 { font-size: 22px; font-weight: 800; margin-bottom: 6px; }
.pl-detail-info .meta { color: var(--text2); font-size: 13px; margin-bottom: 12px; }
.pl-video-list { display: flex; flex-direction: column; gap: 6px; }
.pl-video-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; background: var(--bg2); border-radius: 8px; border: 1px solid var(--border); transition: all 0.15s; }
.pl-video-item:hover { border-color: var(--accent); }
.pl-video-item .num { width: 24px; text-align: right; font-size: 12px; color: var(--text3); flex-shrink: 0; }
.pl-video-item .thumb { width: 80px; height: 45px; border-radius: 4px; overflow: hidden; background: var(--bg4); flex-shrink: 0; }
.pl-video-item .thumb img { width: 100%; height: 100%; object-fit: cover; }
.pl-video-item .info { flex: 1; min-width: 0; }
.pl-video-item .info .title { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pl-video-item .info .meta { font-size: 11px; color: var(--text2); }
.pl-video-item .actions { display: flex; gap: 4px; opacity: 0; transition: opacity 0.15s; }
.pl-video-item:hover .actions { opacity: 1; }

/* Add video to playlist form */
.pl-add-bar { display: flex; gap: 8px; margin-bottom: 16px; }

/* Toast */
#toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--bg3); border: 1px solid var(--border); border-radius: 10px; padding: 12px 16px; font-size: 13px; font-weight: 500; animation: slideIn 0.2s ease; max-width: 300px; display: flex; align-items: center; gap: 8px; }
.toast.success { border-color: var(--green); }
.toast.error { border-color: var(--red); }
@keyframes slideIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }

/* Profile modal extra */
.color-swatches { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.color-swatch { width: 28px; height: 28px; border-radius: 50%; cursor: pointer; border: 2px solid transparent; transition: all 0.15s; }
.color-swatch:hover { transform: scale(1.15); }
.color-swatch.selected { border-color: #fff; box-shadow: 0 0 0 2px rgba(255,255,255,0.3); }

/* Responsive tweaks */
@media (max-width: 768px) {
  #room-body { grid-template-columns: 1fr; grid-template-rows: auto 360px; }
  #left-panel { min-height: 200px; }
  #room-sidebar { grid-column: 1; border-left: none; border-top: 1px solid var(--border); }
}
