:root {
  --sidebar-w: 240px;
  --bg: #111214;
  --sidebar-bg: #1a1c1e;
  --surface: #232527;
  --surface2: #2d2f32;
  --accent: #5865f2;
  --accent2: #57f287;
  --text: #dde1ec;
  --muted: #72767d;
  --danger: #ed4245;
  --border: rgba(255,255,255,.06);
}

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

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

/* ── Root layout ── */
#layout {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* ── SIDEBAR ── */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--surface2) transparent;
}
#sidebar::-webkit-scrollbar { width: 4px; }
#sidebar::-webkit-scrollbar-thumb { background: var(--surface2); border-radius: 2px; }

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 14px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.logo-icon { font-size: 1.2rem; }
.logo-text { font-size: .95rem; font-weight: 700; flex: 1; letter-spacing: .01em; }
.status-dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
}
.status-dot.connected    { background: var(--accent2); box-shadow: 0 0 5px var(--accent2); }
.status-dot.disconnected { background: var(--muted); }

/* Section labels */
.sidebar-section-label {
  padding: 10px 14px 4px;
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--muted);
  flex-shrink: 0;
}

.sidebar-divider {
  height: 1px;
  background: var(--border);
  margin: 8px 0;
  flex-shrink: 0;
}

/* ── Bookmarks ── */
.bookmarks {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 6px;
}
.bookmark-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: none;
  color: var(--muted);
  padding: 7px 9px;
  border-radius: 6px;
  cursor: pointer;
  font-size: .87rem;
  text-align: left;
  width: 100%;
  transition: background .12s, color .12s;
}
.bookmark-btn:hover { background: var(--surface); color: var(--text); }
.bookmark-btn.active { background: var(--surface2); color: var(--text); }
.bm-icon {
  width: 16px; height: 16px; border-radius: 3px; object-fit: contain; flex-shrink: 0;
}

/* ── Now Playing (sidebar) ── */
.now-playing-sidebar {
  padding: 8px 14px 4px;
  flex-shrink: 0;
}
.np-thumb-wrap {
  width: 100%;
  aspect-ratio: 16/9;
  background: var(--surface);
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  margin-bottom: 8px;
}
#np-thumbnail { width: 100%; height: 100%; object-fit: cover; }
.np-title-text {
  font-size: .85rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}
.np-source-text { font-size: .72rem; color: var(--muted); }

/* Progress */
.progress-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  font-size: .7rem;
  color: var(--muted);
  flex-shrink: 0;
}
.progress-bar-bg {
  flex: 1; height: 3px; background: var(--surface2);
  border-radius: 2px; overflow: hidden;
}
.progress-fill {
  height: 100%; background: var(--accent);
  border-radius: 2px; transition: width .5s linear; width: 0%;
}

/* Player controls */
.player-controls {
  display: flex;
  justify-content: center;
  gap: 6px;
  padding: 4px 14px 6px;
  flex-shrink: 0;
}
.pc-btn {
  background: var(--surface2);
  color: var(--text);
  border: none;
  border-radius: 8px;
  padding: 7px 12px;
  font-size: .95rem;
  cursor: pointer;
  transition: background .12s, transform .1s;
  flex: 1;
}
.pc-btn:hover  { background: #3a3d42; }
.pc-btn:active { transform: scale(.92); }
.pc-btn.play   { background: var(--accent); color: #fff; }
.pc-btn.play:hover { background: #4752c4; }

/* Volume */
.volume-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 14px 6px;
  font-size: .85rem;
  flex-shrink: 0;
}
#volume-slider {
  flex: 1; -webkit-appearance: none; appearance: none;
  height: 4px; background: var(--surface2); border-radius: 2px;
  outline: none; cursor: pointer;
}
#volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--accent); cursor: pointer;
}
#volume-slider::-moz-range-thumb {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--accent); border: none; cursor: pointer;
}
#vol-label { font-size: .72rem; color: var(--muted); min-width: 28px; text-align: right; }

/* Loop / Shuffle */
.loop-shuffle-row {
  display: flex;
  gap: 4px;
  padding: 2px 14px 6px;
  flex-shrink: 0;
}
.ls-btn {
  flex: 1;
  background: var(--surface2);
  color: var(--muted);
  border: none;
  border-radius: 6px;
  padding: 5px 8px;
  font-size: .76rem;
  cursor: pointer;
  transition: background .12s, color .12s;
}
.ls-btn:hover  { color: var(--text); }
.ls-btn.active { color: var(--accent2); background: rgba(87,242,135,.1); }

/* ── Sidebar Search ── */
.sidebar-search { padding: 0 10px 6px; flex-shrink: 0; }
.source-toggle { display: flex; gap: 4px; margin-bottom: 6px; }
.src-btn {
  flex: 1;
  background: var(--surface2); color: var(--muted);
  border: none; border-radius: 6px;
  padding: 5px 0; font-size: .76rem; font-weight: 600;
  cursor: pointer; transition: background .12s, color .12s;
}
.src-btn:hover  { color: var(--text); }
.src-btn.active { background: var(--accent); color: #fff; }
.search-input-row { display: flex; gap: 4px; }

.sidebar-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--surface2);
  border-radius: 6px;
  color: var(--text);
  padding: 6px 10px;
  font-size: .82rem;
  outline: none;
  min-width: 0;
  transition: border-color .12s;
}
.sidebar-input:focus { border-color: var(--accent); }

.search-go-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: .82rem;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
  transition: background .12s;
}
.search-go-btn:hover { background: #4752c4; }

#search-results {
  padding: 0 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
  max-height: 220px;
}
.search-result {
  background: var(--surface);
  border-radius: 6px;
  display: flex;
  gap: 8px;
  padding: 7px 8px;
  align-items: center;
  transition: background .12s;
}
.search-result:hover { background: var(--surface2); }
.result-thumb {
  width: 48px; height: 36px; border-radius: 4px;
  object-fit: cover; flex-shrink: 0; background: var(--surface2);
}
.result-thumb-placeholder {
  width: 48px; height: 36px; border-radius: 4px;
  background: var(--surface2); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem;
}
.result-info { flex: 1; min-width: 0; }
.result-title {
  font-size: .78rem; font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  margin-bottom: 2px;
}
.result-meta { font-size: .68rem; color: var(--muted); }
.result-actions { display: flex; gap: 3px; flex-shrink: 0; }
.result-play-btn {
  background: var(--accent); color: #fff; border: none;
  border-radius: 4px; padding: 4px 7px; font-size: .72rem;
  cursor: pointer; transition: background .12s;
}
.result-play-btn:hover { background: #4752c4; }
.result-queue-btn {
  background: var(--surface2); color: var(--text); border: none;
  border-radius: 4px; padding: 4px 7px; font-size: .72rem;
  cursor: pointer; transition: background .12s;
}
.result-queue-btn:hover { background: #3a3d42; }
.search-status { text-align: center; color: var(--muted); font-size: .8rem; padding: 12px; }

/* ── Queue ── */
.add-track-row {
  display: flex;
  gap: 4px;
  padding: 0 10px 6px;
  flex-shrink: 0;
}
#queue-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 0 10px;
  overflow-y: auto;
  max-height: 160px;
}
.queue-item {
  display: flex; align-items: center; gap: 6px;
  background: var(--surface); border-radius: 5px;
  padding: 6px 8px; font-size: .78rem;
}
.queue-item-num    { color: var(--muted); min-width: 14px; font-size: .7rem; }
.queue-item-title  { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queue-item-duration { color: var(--muted); font-size: .68rem; }
.queue-item-remove {
  background: none; border: none; color: var(--muted);
  cursor: pointer; font-size: .82rem; padding: 0 2px;
  transition: color .12s;
}
.queue-item-remove:hover { color: var(--danger); }
.empty-queue { color: var(--muted); font-size: .78rem; text-align: center; padding: 8px 0; }

/* Error toast (bottom of sidebar) */
.error-toast {
  margin: 8px 10px;
  background: var(--danger);
  color: #fff;
  border-radius: 6px;
  padding: 8px 12px;
  font-size: .8rem;
  animation: fadeIn .2s ease;
  flex-shrink: 0;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── MAIN ── */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
  overflow: hidden;
}

/* ── Browser bar ── */
.browser-bar {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 8px 10px;
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.nav-btn {
  background: var(--surface2); color: var(--text); border: none;
  border-radius: 6px; padding: 6px 10px; font-size: .95rem;
  cursor: pointer; flex-shrink: 0; transition: background .12s;
}
.nav-btn:hover { background: #3a3d42; }
.url-form { flex: 1; display: flex; gap: 5px; }
.url-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--surface2);
  border-radius: 6px;
  color: var(--text);
  padding: 6px 12px;
  font-size: .87rem;
  outline: none;
  min-width: 0;
  transition: border-color .12s;
}
.url-input:focus { border-color: var(--accent); }
.go-btn {
  background: var(--accent); color: #fff; border: none;
  border-radius: 6px; padding: 6px 14px; font-size: .87rem;
  cursor: pointer; flex-shrink: 0; transition: background .12s;
}
.go-btn:hover { background: #4752c4; }
.grab-btn {
  background: var(--accent2); color: #000; border: none;
  border-radius: 6px; padding: 6px 10px; font-size: .78rem;
  font-weight: 700; cursor: pointer; flex-shrink: 0;
  transition: opacity .12s; white-space: nowrap;
}
.grab-btn:hover { opacity: .85; }

/* ── Browser view wrap ── */
.browser-loading {
  text-align: center; color: var(--muted); font-size: .85rem;
  padding: 8px 0; animation: pulse 1.2s infinite; flex-shrink: 0;
}
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.35} }

.browser-view-wrap {
  flex: 1;
  position: relative;
  background: #000;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
}
#browser-view {
  width: 100%;
  height: auto;
  display: block;
  cursor: crosshair;
}
.browser-placeholder {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 10px; color: var(--muted); pointer-events: none;
}
.ph-icon  { font-size: 3.5rem; }
.ph-label { font-size: 1rem; }
.ph-sub   { font-size: .78rem; opacity: .55; }

/* ── Cursor overlay + KB hint ── */
.browser-cursor {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5;
}
.browser-kb-hint {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(88, 101, 242, .85);
  color: #fff;
  font-size: .75rem;
  padding: 4px 12px;
  border-radius: 20px;
  pointer-events: none;
  z-index: 10;
  white-space: nowrap;
}

/* ── Utility ── */
.hidden { display: none !important; }
