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

/* Ensure [hidden] always wins regardless of display rules elsewhere */
[hidden] { display: none !important; }

:root {
  --bg:           #1c1917;
  --surface:      #292524;
  --surface-2:    #3d3835;
  --border:       #44403c;
  --accent:       #7c3aed;
  --accent-hi:    #a78bfa;
  --accent-dim:   #4c1d95;
  --text:         #fafaf9;
  --text-muted:   #a8a29e;
  --text-dim:     #78716c;
  --danger:       #ef4444;
  --success:      #22c55e;
  --warn:         #f59e0b;
  --top-h:        48px;
  --bot-h:        82px;
  --sidebar-w:    272px;
  --font:         'IBM Plex Mono', 'Courier New', monospace;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.5;
}

button {
  font-family: var(--font);
  font-size: 13px;
  cursor: pointer;
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 3px 10px;
  transition: border-color .15s, color .15s, background .15s;
  white-space: nowrap;
}
button:hover  { border-color: var(--accent-hi); color: var(--accent-hi); }
button:active { background: var(--accent-dim); }
button:disabled { opacity: 0.35; pointer-events: none; }

input, select {
  font-family: var(--font);
  font-size: 13px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 8px;
  outline: none;
}
input:focus, select:focus { border-color: var(--accent); }
input::placeholder         { color: var(--text-dim); }

ul { list-style: none; }

.panel-label {
  color: var(--accent-hi);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .07em;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 5px;
}

.list-empty {
  font-size: 11px;
  color: var(--text-dim);
  font-style: italic;
  padding: 2px 0;
}

/* ── Scrollbars ──────────────────────────────────────────────────────── */
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
::-webkit-scrollbar       { width: 4px; height: 4px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ── Top bar ─────────────────────────────────────────────────────────── */
#top-bar {
  position: fixed; top: 0; left: 0; right: 0;
  height: var(--top-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  z-index: 100;
}
#logo {
  font-size: 16px; font-weight: 600;
  color: var(--accent-hi); letter-spacing: .12em;
}
#user-area { display: flex; align-items: center; gap: 10px; }
#user-greeting { color: var(--text-muted); font-size: 12px; }

/* ── Main layout ─────────────────────────────────────────────────────── */
#main {
  position: fixed;
  top: var(--top-h); left: 0; right: 0; bottom: var(--bot-h);
  display: flex;
}

/* ── Video section ───────────────────────────────────────────────────── */
#video-section {
  flex: 1; min-width: 0;
  position: relative;
  background: #000;
  overflow: hidden;
}

/* Idle screen */
#idle-screen {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; z-index: 2;
}
#idle-signal {
  font-size: 30px; font-weight: 600;
  color: var(--text-dim); letter-spacing: .04em;
  animation: flicker 6s infinite;
}
@keyframes flicker {
  0%,89%,91%,93%,100% { opacity: 1; }
  90%                  { opacity: .3; }
  92%                  { opacity: .8; }
}
#idle-sub  { font-size: 13px; color: var(--text-dim); }
#idle-join-btn {
  border-color: var(--accent); color: var(--accent-hi); padding: 6px 18px;
}
#idle-join-btn:hover { background: var(--accent-dim); }
#idle-guest-hint { font-size: 12px; color: var(--text-dim); }

/* YouTube player */
#yt-player-wrap {
  position: absolute; inset: 0; z-index: 1;
  display: none;
}
#yt-player-wrap.visible { display: block; }
#yt-player { width: 100%; height: 100%; }
#yt-player iframe { width: 100%; height: 100%; border: none; display: block; }
#yt-shield { position: absolute; inset: 0; z-index: 2; }

/* ── Sidebar ─────────────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
}

#users-panel {
  padding: 8px 10px 6px; flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}
#users-list {
  display: flex; flex-wrap: wrap; gap: 4px;
  max-height: 44px; overflow: hidden;
}
#users-list li {
  font-size: 11px; color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 1px 7px;
}
#users-list li.me { color: var(--accent-hi); border-color: var(--accent-dim); }

#queue-panel {
  padding: 8px 10px 6px; flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}
#queue-list { display: flex; flex-direction: column; gap: 2px; }
.queue-item {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--text-muted); padding: 1px 4px;
}
.queue-item.queue-active { color: var(--accent-hi); }
.queue-num { font-size: 11px; color: var(--text-dim); min-width: 14px; }

#chat-panel {
  flex: 1; display: flex; flex-direction: column; min-height: 0;
  padding: 8px 10px 0;
}
#chat-log {
  flex: 1; overflow-y: auto; display: flex; flex-direction: column;
  gap: 1px; padding-right: 2px;
}
.chat-msg { font-size: 12px; line-height: 1.4; word-break: break-word; }
.chat-from { color: var(--accent-hi); font-weight: 500; }
.chat-msg.chat-system  { color: var(--text-dim); font-style: italic; }
.chat-msg.chat-error   { color: var(--danger); }
.chat-msg.chat-whisper { color: #f0abfc; }
.chat-msg.chat-whisper .chat-from { color: #f0abfc; }
.chat-msg.chat-emote   { color: var(--text-muted); font-style: italic; }

#chat-input-row { padding: 6px 0; border-top: 1px solid var(--border); }
#chat-input {
  width: 100%; background: transparent; border: none;
  border-bottom: 1px solid var(--border);
  padding: 3px 2px; color: var(--text);
}
#chat-input:focus { border-bottom-color: var(--accent); outline: none; }

/* ── Bottom bar ──────────────────────────────────────────────────────── */
#bottom-bar {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: var(--bot-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 14px 0 0; gap: 14px; z-index: 100;
}

#bar-left { flex-shrink: 0; align-self: stretch; display: flex; }
#btn-toggle-playlists {
  height: 100%; padding: 0 20px;
  border-top: none; border-bottom: none; border-left: none;
  border-right: 1px solid var(--border);
  font-size: 14px;
}

#bar-center { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 5px; }

#now-playing-row {
  display: flex; gap: 10px; align-items: baseline;
  overflow: hidden; white-space: nowrap;
}
#np-title {
  font-size: 12px; overflow: hidden; text-overflow: ellipsis;
  color: var(--text);
}
#np-title.np-empty { color: var(--text-dim); }
#np-owner { font-size: 11px; color: var(--text-dim); flex-shrink: 0; }
#btn-copy-link {
  flex-shrink: 0; border: none; background: none;
  font-size: 13px; padding: 0 3px; color: var(--text-dim);
}
#btn-copy-link:hover { color: var(--accent-hi); border: none; background: none; }

#seek-row { display: flex; align-items: center; gap: 8px; }
#time-current, #time-total {
  font-size: 11px; color: var(--text-dim); flex-shrink: 0; min-width: 34px;
}
#time-total { text-align: right; }

#seek-wrap { flex: 1; position: relative; height: 20px; display: flex; align-items: center; }

#seek-track {
  position: absolute; left: 0; right: 0; height: 3px;
  background: var(--surface-2); border-radius: 2px; overflow: hidden;
  pointer-events: none;
}
#seek-fill {
  height: 100%; background: var(--accent); width: 0%;
  transition: width .1s linear;
}
#seek-input {
  position: absolute; left: 0; right: 0;
  width: 100%; height: 100%;
  opacity: 0; cursor: pointer;
  margin: 0; padding: 0; border: none; background: none;
  -webkit-appearance: none;
}
#seek-input:disabled { cursor: default; pointer-events: none; }

#seek-preview {
  position: absolute; bottom: 28px;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 4px;
  pointer-events: none; z-index: 200;
  display: none;
  flex-direction: column; align-items: center; gap: 3px;
}
#seek-preview.visible { display: flex; }
#seek-preview-img { width: 120px; height: 68px; object-fit: cover; display: block; }
#seek-preview-time { font-size: 11px; color: var(--text-muted); }

#bar-right { flex-shrink: 0; display: flex; align-items: center; gap: 8px; }

#volume-control { display: flex; align-items: center; gap: 4px; margin-right: 4px; }

#btn-mute {
  border: none; background: none; padding: 0 2px;
  font-size: 15px; line-height: 1; color: var(--text-muted);
}
#btn-mute:hover { color: var(--text); border: none; background: none; }

#volume-input {
  -webkit-appearance: none; appearance: none;
  width: 72px; height: 20px;   /* tall hit area so it's actually draggable */
  background: transparent; border: none; padding: 0;
  cursor: pointer; outline: none;
}
#volume-input::-webkit-slider-runnable-track {
  height: 3px; background: var(--surface-2);
  border-radius: 2px;
}
#volume-input::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--accent-hi); cursor: pointer;
  margin-top: -4.5px;   /* center thumb on the 3px track */
}
#volume-input::-moz-range-track {
  height: 3px; background: var(--surface-2); border-radius: 2px; border: none;
}
#volume-input::-moz-range-thumb {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--accent-hi); cursor: pointer; border: none;
}

#btn-join-queue  { border-color: var(--accent); color: var(--accent-hi); }
#btn-join-queue:hover { background: var(--accent-dim); }
#btn-leave-queue { border-color: var(--border); }

/* ── Steal playlist picker ────────────────────────────────────────────── */
#steal-menu {
  position: fixed; z-index: 300;
  background: var(--surface);
  border: 1px solid var(--border);
  min-width: 150px; max-height: 220px;
  overflow-y: auto;
  box-shadow: 0 -4px 14px rgba(0,0,0,.5);
}
.steal-pl-item {
  padding: 6px 14px; cursor: pointer;
  font-size: 12px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
  color: var(--text-muted);
}
.steal-pl-item:hover { background: var(--surface-2); color: var(--accent-hi); }
.steal-pl-item.steal-pl-active { color: var(--accent-hi); }
.steal-pl-empty {
  padding: 7px 14px; font-size: 11px;
  color: var(--text-dim); font-style: italic;
}

/* ── Playlist panel ──────────────────────────────────────────────────── */
#playlist-panel {
  position: fixed;
  top: var(--top-h); left: 0; bottom: var(--bot-h);
  width: calc(100% - var(--sidebar-w));
  background: rgba(28, 25, 23, .73);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border-right: 1px solid var(--border);
  z-index: 50;
  display: flex; flex-direction: column;
  transform: translateX(-100%);
  transition: transform .24s cubic-bezier(.4,0,.2,1);
}
#playlist-panel.open { transform: translateX(0); }

#playlist-overlay {
  position: fixed; inset: 0; z-index: 49;
  display: none;
}
#playlist-overlay.visible { display: block; }

#playlist-panel-top {
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  padding: 8px 12px;
}
#playlist-search-row { display: flex; gap: 6px; align-items: center; }
#search-input { flex: 1; }
#btn-close-playlists { border: none; font-size: 20px; color: var(--text-dim); padding: 0 4px; flex-shrink: 0; }
#btn-close-playlists:hover { color: var(--text); border: none; background: none; }

#playlist-panel-body { flex: 1; display: flex; min-height: 0; }

#playlist-col {
  width: 220px; flex-shrink: 0;
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 10px 10px 8px;
  overflow: hidden;
}
#playlist-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }

.pl-item {
  display: flex; align-items: center; gap: 4px;
  padding: 5px 8px; cursor: pointer;
  border: 1px solid transparent;
  font-size: 12px; color: var(--text-muted);
}
.pl-item:hover { border-color: var(--border); color: var(--text); }
.pl-item.pl-active { color: var(--accent-hi); border-color: var(--accent-dim); }
.pl-item.pl-selected { background: var(--surface-2); }
.pl-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pl-count { font-size: 11px; color: var(--text-dim); flex-shrink: 0; }
.pl-active-mark {
  font-size: 13px; color: var(--warn); padding: 0 3px; flex-shrink: 0;
}
.pl-activate {
  opacity: 0; font-size: 13px; padding: 0 3px;
  border: none; color: var(--text-dim); flex-shrink: 0;
}
.pl-item:hover .pl-activate { opacity: 1; }
.pl-activate:hover { color: var(--warn) !important; border: none !important; background: none !important; }

.pl-del {
  opacity: 0; font-size: 13px; padding: 0 3px;
  border: none; color: var(--text-dim);
}
.pl-item:hover .pl-del { opacity: 1; }
.pl-del:hover { color: var(--danger) !important; border: none !important; background: none !important; }

#playlist-create-row {
  display: flex; gap: 4px;
  padding-top: 8px; border-top: 1px solid var(--border); margin-top: 6px;
  flex-shrink: 0;
}
#new-playlist-name { flex: 1; font-size: 12px; padding: 3px 6px; }
#btn-create-playlist { flex-shrink: 0; font-size: 16px; padding: 2px 8px; }

#video-col {
  flex: 1; display: flex; flex-direction: column; min-height: 0;
  padding: 10px 10px 8px; overflow: hidden;
}
#video-col-header {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  flex-shrink: 0; margin-bottom: 4px;
}
#video-col-label { flex: 1; }
#video-filter { font-size: 12px; padding: 2px 6px; width: 130px; }
#video-list {
  flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 1px;
}

.vi-item {
  display: flex; align-items: center; gap: 7px;
  padding: 4px 6px; border: 1px solid transparent;
  cursor: grab; font-size: 12px; color: var(--text-muted);
  user-select: none;
}
.vi-item:hover        { border-color: var(--border); color: var(--text); }
.vi-item.vi-drag-over { border-color: var(--accent); background: rgba(124,58,237,.08); }
.vi-item.vi-dragging  { opacity: .35; }

.vi-handle { color: var(--text-dim); cursor: grab; font-size: 14px; flex-shrink: 0; }

.vi-thumb-link {
  flex-shrink: 0; display: block;
  width: 80px; height: 45px; overflow: hidden;
  border: 1px solid var(--border);
  opacity: .85; transition: opacity .15s;
}
.vi-thumb-link:hover { opacity: 1; border-color: var(--accent-hi); }
.vi-thumb {
  width: 80px; height: 45px; object-fit: cover;
  display: block; pointer-events: none;
}

.vi-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.vi-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vi-dur   { font-size: 11px; color: var(--text-dim); }

.vi-actions { display: flex; gap: 2px; opacity: 0; flex-shrink: 0; }
.vi-item:hover .vi-actions { opacity: 1; }
.vi-item.vi-now-playing { border-color: var(--accent-dim); background: rgba(124,58,237,.08); }
.vi-item.vi-now-playing .vi-title { color: var(--accent-hi); }
.vi-actions button { font-size: 11px; padding: 1px 5px; }
.vi-del:hover { border-color: var(--danger) !important; color: var(--danger) !important; }

#search-results-section {
  flex: 1; display: flex; flex-direction: column; min-height: 0; overflow: hidden;
}
#search-results-list {
  flex: 1; overflow-y: auto;
  display: flex; flex-direction: column; gap: 2px; margin-top: 4px;
}
#btn-clear-search {
  flex-shrink: 0; margin-top: 6px; font-size: 11px;
  border-color: var(--border); color: var(--text-dim);
  align-self: flex-start;
}
#btn-panel-join-queue {
  flex-shrink: 0; font-size: 11px;
  border-color: var(--accent); color: var(--accent-hi);
}
#btn-panel-join-queue:hover { background: var(--accent-dim); }

.sr-item {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 6px; border: 1px solid transparent;
  font-size: 12px; color: var(--text-muted);
}
.sr-item:hover { border-color: var(--border); color: var(--text); }
.sr-thumb-link {
  flex-shrink: 0; display: block;
  width: 80px; height: 45px; overflow: hidden;
  border: 1px solid var(--border); opacity: .85; transition: opacity .15s;
}
.sr-thumb-link:hover { opacity: 1; border-color: var(--accent-hi); }
.sr-thumb { width: 80px; height: 45px; object-fit: cover; display: block; pointer-events: none; }
.sr-info  { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.sr-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-dur   { font-size: 11px; color: var(--text-dim); }
.sr-add   { font-size: 11px; padding: 1px 8px; border-color: var(--accent); color: var(--accent-hi); flex-shrink: 0; align-self: center; }
.sr-add:hover { background: var(--accent-dim); border-color: var(--accent-hi); }

/* ── Chat @mention highlight ─────────────────────────────────────────── */
.chat-msg.chat-mention {
  background: rgba(124, 58, 237, .15);
  border-left: 2px solid var(--accent);
  padding-left: 4px;
  color: var(--text);
  margin-left: -4px;
}

/* ── Now-playing banner ──────────────────────────────────────────────── */
#np-banner {
  position: absolute; top: 0; left: 0; right: 0; z-index: 5;
  padding: 12px 18px 24px;
  background: linear-gradient(to bottom, rgba(0,0,0,.78) 0%, transparent 100%);
  display: flex; flex-direction: column; gap: 3px;
  pointer-events: none;
  opacity: 0; transform: translateY(-100%);
}
#np-banner.show { animation: banner-show 4s ease forwards; }
#np-banner-title { font-size: 14px; font-weight: 600; color: var(--text); }
#np-banner-owner { font-size: 12px; color: var(--text-muted); }
@keyframes banner-show {
  0%   { transform: translateY(-100%); opacity: 0; }
  10%  { transform: translateY(0);     opacity: 1; }
  78%  { transform: translateY(0);     opacity: 1; }
  100% { transform: translateY(-100%); opacity: 0; }
}

/* ── Theater mode ────────────────────────────────────────────────────── */
body.theater #sidebar { display: none; }
#btn-theater {
  border: none; background: none; color: var(--text-dim);
  font-size: 13px; padding: 2px 5px;
}
#btn-theater:hover  { color: var(--text); border: none; background: none; }
body.theater #btn-theater { color: var(--accent-hi); border: none; }

/* ── Floating emoji reactions ────────────────────────────────────────── */
#float-container {
  position: absolute; inset: 0;
  pointer-events: none; z-index: 4; overflow: hidden;
}
.float-emoji {
  position: absolute; bottom: 8px;
  font-size: 40px; line-height: 1;
  pointer-events: none; user-select: none;
  animation: float-up 3s ease-out forwards;
}
@keyframes float-up {
  0%   { transform: translateY(0) scale(1);    opacity: 1; }
  20%  { transform: translateY(-40px) scale(1.2); opacity: 1; }
  100% { transform: translateY(-320px) scale(0.7); opacity: 0; }
}

/* ── Reaction bar ────────────────────────────────────────────────────── */
#reaction-bar {
  display: flex; gap: 2px;
  padding: 4px 0 2px; flex-shrink: 0;
  border-top: 1px solid var(--border);
}
.reaction-btn {
  font-size: 16px; padding: 2px 5px;
  border: 1px solid transparent; background: none;
  cursor: pointer; border-radius: 2px;
  transition: transform .1s, border-color .1s;
  line-height: 1;
}
.reaction-btn:hover  { border-color: var(--border); transform: scale(1.25); background: none; color: inherit; }
.reaction-btn:active { transform: scale(0.9); }

/* ── Chat scroll-to-bottom button ────────────────────────────────────── */
#chat-panel { position: relative; }
#btn-scroll-bottom {
  position: absolute; bottom: 68px; left: 50%; transform: translateX(-50%);
  font-size: 11px; padding: 3px 10px; white-space: nowrap;
  background: var(--surface-2); border-color: var(--accent); color: var(--accent-hi);
  z-index: 10; box-shadow: 0 2px 6px rgba(0,0,0,.4);
}
#btn-scroll-bottom:hover { background: var(--accent-dim); }

/* ── Queue ETA ───────────────────────────────────────────────────────── */
#queue-eta {
  font-size: 11px; color: var(--accent-hi);
  padding: 3px 4px 0; font-style: italic;
}

/* ── Auth modal ──────────────────────────────────────────────────────── */
#auth-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.65);
  z-index: 200;
}
#auth-modal {
  position: fixed; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 24px 24px 20px;
  z-index: 201; width: 300px;
  display: flex; flex-direction: column; gap: 12px;
}
#btn-close-auth {
  position: absolute; top: 8px; right: 10px;
  border: none; font-size: 20px;
  color: var(--text-dim); padding: 0 4px;
}
#btn-close-auth:hover { color: var(--text); border: none; background: none; }

#auth-tabs { display: flex; gap: 0; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.auth-tab { border: none; color: var(--text-dim); padding: 4px 14px; font-size: 13px; }
.auth-tab.active { color: var(--accent-hi); border-bottom: 2px solid var(--accent); }
.auth-tab:hover { color: var(--text); background: none; border-color: transparent; }
.auth-tab.active:hover { color: var(--accent-hi); }

#auth-error {
  color: var(--danger); font-size: 12px;
  border: 1px solid var(--danger); padding: 4px 8px;
}
#auth-login-pane,
#auth-register-pane { display: flex; flex-direction: column; gap: 8px; }
#auth-login-pane input,
#auth-register-pane input { width: 100%; }
#btn-do-login, #btn-do-register {
  border-color: var(--accent); color: var(--accent-hi); padding: 7px;
}
#btn-do-login:hover, #btn-do-register:hover { background: var(--accent-dim); }

.vi-item {
  position: relative;
}

.vi-item.vi-drag-over-top::before,
.vi-item.vi-drag-over-bottom::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--accent, #4ea3ff);
  pointer-events: none;
}

.vi-item.vi-drag-over-top::before { top: 0; }
.vi-item.vi-drag-over-bottom::after { bottom: 0; }
