:root {
  --bg: #0f1115;
  --panel: #161920;
  --panel-2: #1c2029;
  --line: #252a35;
  --hover: #222733;
  --text: #e7e9ee;
  --muted: #8a92a5;
  --accent: #3b82f6;
  --accent-ink: #ffffff;
  --ok: #22c55e;
  --bad: #ef4444;
  --r-ctl: 7px;
  --r-card: 12px;
  --r-panel: 16px;
  color-scheme: dark;
}
body[data-accent="green"] { --accent: #22c55e; }
body[data-accent="purple"] { --accent: #8b5cf6; }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  display: flex; flex-direction: column; min-height: 100vh;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: default; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.num { font-variant-numeric: tabular-nums; }
svg { width: 20px; height: 20px; display: block; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* header */
.top {
  height: 58px; flex: none; display: flex; align-items: center; gap: 12px;
  padding: 0 16px; border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 600; font-size: 15px; }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 12px; min-width: 0; }
.server { display: flex; align-items: center; gap: 8px; min-width: 0; }
.server img { border-radius: 8px; background: var(--panel-2); }
.server span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 30vw; }
.avatar { border-radius: 50%; background: var(--panel-2); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.on { background: var(--ok); }
.dot.off { background: var(--bad); }

/* buttons */
.icon-btn {
  width: 36px; height: 36px; display: grid; place-items: center; border: 0; background: transparent;
  border-radius: var(--r-ctl); color: var(--muted); padding: 0; flex: none;
  transition: background .12s, color .12s;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn.lg svg { width: 24px; height: 24px; }
.icon-btn.sm { width: 28px; height: 28px; }
.icon-btn.sm svg { width: 16px; height: 16px; }
.icon-btn.on { color: var(--accent); }
.icon-btn:disabled { opacity: .35; background: transparent; }
.btn {
  border: 1px solid var(--line); background: var(--panel-2); border-radius: var(--r-ctl);
  padding: 7px 14px; font-weight: 500; transition: background .12s;
}
.btn:hover { background: var(--hover); }
.btn.sm { padding: 4px 10px; font-size: 12.5px; }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--hover); }
.btn.primary { background: var(--accent); border-color: transparent; color: var(--accent-ink); }
.play {
  width: 56px; height: 56px; border-radius: 50%; border: 0; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink); transition: filter .12s, transform .12s;
}
.play:hover { filter: brightness(1.08); }
.play:active { transform: scale(.96); }
.play svg { width: 26px; height: 26px; fill: currentColor; stroke: none; }

/* layout */
main {
  flex: 1 0 auto; display: grid; grid-template-columns: minmax(320px, 420px) minmax(0, 1fr); gap: 16px;
  padding: 16px; max-width: 1280px; width: 100%; margin: 0 auto;
}
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-panel); }

/* player */
.player { padding: 20px; display: flex; flex-direction: column; gap: 16px; align-self: start; position: sticky; top: 16px; }
.cover-wrap { aspect-ratio: 1; width: 100%; position: relative; }
.cover {
  width: 100%; height: 100%; object-fit: cover; border-radius: var(--r-card); background: var(--panel-2); display: block;
}
.cover.ph { display: grid; place-items: center; color: #3a4050; }
.cover.ph svg { width: 30%; height: 30%; stroke-width: 1.5; }
.meta h1 { margin: 0; font-size: 19px; font-weight: 600; line-height: 1.3; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.meta p { margin: 3px 0 0; }
.meta p:empty { display: none; }

input[type=range] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 18px; background: transparent; margin: 0;
  --p: 0%;
}
input[type=range]::-webkit-slider-runnable-track {
  height: 4px; border-radius: 4px; background: linear-gradient(var(--accent), var(--accent)) 0 / var(--p) 100% no-repeat, var(--line);
}
input[type=range]::-moz-range-track { height: 4px; border-radius: 4px; background: var(--line); }
input[type=range]::-moz-range-progress { height: 4px; border-radius: 4px; background: var(--accent); }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 13px; height: 13px; border-radius: 50%; background: var(--text); margin-top: -4.5px; border: 0;
}
input[type=range]::-moz-range-thumb { width: 13px; height: 13px; border-radius: 50%; background: var(--text); border: 0; }
input[type=range]:disabled { opacity: .4; }
.times { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; margin-top: 2px; }

.controls { display: flex; align-items: center; justify-content: center; gap: 14px; }
.row { display: flex; align-items: center; gap: 10px; }
.volume input { flex: 1; }
.volume .num { width: 28px; text-align: right; }
.opts { justify-content: space-between; flex-wrap: wrap; gap: 12px; }
.select { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.select select {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--r-ctl); padding: 5px 8px; color: var(--text);
}
.switch { display: flex; align-items: center; gap: 8px; color: var(--muted); user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track { width: 34px; height: 20px; border-radius: 10px; background: var(--line); position: relative; transition: background .12s; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: var(--text); transition: transform .12s; }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(14px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }
.channel { border-top: 1px solid var(--line); padding-top: 14px; }
.channel #voiceName { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* side */
.side { padding: 16px; display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }
.search { position: relative; }
.search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search-icon svg { width: 18px; height: 18px; }
.search input {
  width: 100%; height: 44px; border-radius: var(--r-card); border: 1px solid var(--line); background: var(--panel-2);
  padding: 0 14px 0 40px; outline: none; transition: border-color .12s;
}
.search input:focus { border-color: var(--accent); }
.search.busy .search-icon { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: translateY(-50%) rotate(360deg); } }

.results {
  margin-top: 8px; border: 1px solid var(--line); border-radius: var(--r-card); background: var(--panel-2);
  max-height: 50vh; overflow: auto;
}
.results-head { display: flex; align-items: center; gap: 8px; padding: 8px 8px 4px 14px; position: sticky; top: 0; background: var(--panel-2); z-index: 1; }
.results-head #resultsTitle { flex: 1; }

.tabs { display: flex; align-items: center; gap: 4px; margin: 16px 0 8px; }
.tab {
  border: 0; background: transparent; color: var(--muted); padding: 6px 12px; border-radius: var(--r-ctl); font-weight: 500;
  display: flex; align-items: center; gap: 6px;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--hover); color: var(--text); }
.count { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.tab-tools { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.list { list-style: none; margin: 0; padding: 0; }
.item {
  display: grid; grid-template-columns: 22px 44px minmax(0, 1fr) auto auto; align-items: center; gap: 12px;
  padding: 6px 8px; border-radius: var(--r-card); transition: background .1s;
}
.results .item { grid-template-columns: 44px minmax(0, 1fr) auto auto; padding: 6px 8px 6px 10px; }
.item:hover { background: var(--hover); }
.item .idx { color: var(--muted); font-size: 12px; text-align: right; font-variant-numeric: tabular-nums; }
.item img, .item .thumb-ph { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; background: var(--panel-2); display: block; }
.item .t { min-width: 0; }
.item .t b { display: block; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .t span { display: block; font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .d { color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.item .acts { display: flex; gap: 2px; opacity: 0; transition: opacity .1s; }
.item:hover .acts, .item:focus-within .acts { opacity: 1; }
.results .item .acts { opacity: 1; }
.queue .item[draggable=true] { cursor: grab; }
.item.dragging { opacity: .4; }
.item.drop-before { box-shadow: inset 0 2px 0 var(--accent); }
.item.drop-after { box-shadow: inset 0 -2px 0 var(--accent); }
.empty { text-align: center; padding: 40px 0; }

/* gate */
.gate { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 24px; gap: 4px; }
.gate h2 { margin: 12px 0 0; font-size: 18px; font-weight: 600; }
.gate p { max-width: 360px; margin: 4px 0 14px; }
.gate code { background: var(--panel-2); padding: 1px 6px; border-radius: 5px; color: var(--text); }

/* drawer */
.drawer-bg { position: fixed; inset: 0; background: rgba(5, 6, 9, .45); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); z-index: 20; }
.drawer {
  position: fixed; top: 0; bottom: 0; left: 0; width: min(340px, 88vw); background: var(--panel); border-right: 1px solid var(--line);
  z-index: 21; transform: translateX(-102%); transition: transform .18s ease; padding: 16px 20px; display: flex; flex-direction: column; gap: 22px;
  border-radius: 0 var(--r-panel) var(--r-panel) 0;
}
.drawer.open { transform: none; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; }
.drawer-head h2 { margin: 0; font-size: 16px; font-weight: 600; }
.field { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.field .label { font-weight: 500; }
.field p { margin: 0; }
.seg { display: inline-flex; background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--r-ctl); padding: 3px; gap: 3px; }
.seg button { border: 0; background: transparent; padding: 5px 14px; border-radius: 5px; color: var(--muted); }
.seg button.active { background: var(--hover); color: var(--text); }
.swatches { display: flex; gap: 12px; }
.sw { width: 30px; height: 30px; border-radius: 50%; border: 0; background: var(--c); padding: 0; outline-offset: 3px; }
.sw.active { outline: 2px solid var(--text); }
.drawer-foot { margin-top: auto; }

/* backends */
.backends { list-style: none; margin: 0; padding: 0; width: 100%; display: grid; gap: 4px; }
.backends li {
  display: grid; grid-template-columns: 8px minmax(0, 1fr) auto; align-items: center; gap: 10px;
  padding: 7px 6px 7px 10px; border-radius: var(--r-ctl); border: 1px solid transparent;
}
.backends li:hover { background: var(--hover); }
.backends li.active { background: var(--hover); border-color: var(--line); }
.backends .bk { min-width: 0; text-align: left; background: none; border: 0; padding: 0; }
.backends .bk b { display: block; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.backends .bk span { display: block; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.add-backend { display: flex; gap: 6px; width: 100%; }
.add-backend input {
  flex: 1; min-width: 0; height: 32px; border-radius: var(--r-ctl); border: 1px solid var(--line); background: var(--panel-2);
  padding: 0 10px; outline: none; font-size: 13px;
}
.add-backend input:focus { border-color: var(--accent); }
.gate-actions { display: flex; gap: 8px; }
.drawer { overflow-y: auto; }

/* logo follows the accent colour */
.logo { stroke: none; flex: none; }
.brand .logo { width: 30px; height: 30px; }
.gate .logo { width: 80px; height: 80px; }
.logo rect { fill: var(--accent); transition: fill .15s; }
.logo path { fill: #fff; }

/* tutorial */
.modal-bg { position: fixed; inset: 0; background: rgba(5, 6, 9, .55); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); z-index: 40; }
.modal {
  position: fixed; z-index: 41; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(520px, calc(100vw - 32px)); max-height: calc(100vh - 32px); overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-panel); padding: 18px 22px 20px;
  display: flex; flex-direction: column; gap: 12px;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-right: -8px; }
.modal h2 { margin: 0; font-size: 18px; font-weight: 600; }
.help-body { color: #c9cdd8; line-height: 1.6; }
.help-body p { margin: 0 0 10px; }
.help-body ol { margin: 0 0 10px; padding-left: 20px; }
.help-body li { margin-bottom: 6px; }
.help-body b { color: var(--text); font-weight: 600; }
.help-body code { background: var(--panel-2); border: 1px solid var(--line); padding: 1px 6px; border-radius: 5px; color: var(--text); font-size: 12.5px; }
.help-body a { color: var(--accent); }
.help-swatches { display: flex; gap: 10px; margin: 4px 0 10px; }
.help-dots { display: flex; gap: 6px; justify-content: center; }
.help-dots span { width: 7px; height: 7px; border-radius: 50%; background: var(--line); }
.help-dots span.on { background: var(--accent); }
.modal-foot { display: flex; justify-content: space-between; gap: 8px; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--panel-2); border: 1px solid var(--line);
  padding: 10px 16px; border-radius: var(--r-card); z-index: 30; max-width: calc(100vw - 32px); box-shadow: 0 6px 20px rgba(0,0,0,.35);
}
.toast.err { border-color: #5b2a2a; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* mobile */
@media (max-width: 860px) {
  main { grid-template-columns: 1fr; padding: 12px 16px; }
  .player { position: static; padding: 16px; }
  .cover-wrap { max-width: 300px; margin: 0 auto; }
  .server span { display: none; }
  .item { grid-template-columns: 44px minmax(0, 1fr) auto; }
  .item .idx, .item .d { display: none; }
  .item .acts { opacity: 1; }
  .results .item { grid-template-columns: 44px minmax(0, 1fr) auto; }
}
