:root {
  --bg: #1a2130;
  --panel: #222b3b;
  --panel-2: #29344a;
  --rule: #334058;
  --text: #e7ebf3;
  --muted: #8e9ab1;
  --accent: #f0b43c;
  --accent-ink: #1a2130;
  --ok: #5cc8a6;
  --warn: #f0b43c;
  --bad: #e5736b;
  --focus: #9cc2ff;
  --radius-lg: 14px;
  --radius: 8px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", Ubuntu, Cantarell, sans-serif;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #eef1f6;
    --panel: #ffffff;
    --panel-2: #f3f5f9;
    --rule: #d7dde8;
    --text: #1a2130;
    --muted: #5d6880;
    --accent: #b97c0c;
    --accent-ink: #ffffff;
    --ok: #1f8f6c;
    --bad: #c2463d;
    --focus: #2f6fd8;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }
code { font-size: .9em; background: var(--panel-2); padding: 1px 5px; border-radius: 4px; word-break: break-all; }
.muted { color: var(--muted); }
.small-text { font-size: 13px; }
.spacer { flex: 1; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- controls */
button, input, select { font: inherit; color: inherit; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; padding: 0 16px;
  border: 1px solid var(--rule); border-radius: var(--radius);
  background: var(--panel-2); cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); }
.btn.small { min-height: 32px; padding: 0 12px; font-size: 14px; }
.btn:disabled { opacity: .5; cursor: default; }
.upload { position: relative; }

input[type=text], input[type=password], input[type=number], input[type=search], input:not([type]) {
  width: 100%; min-height: 40px; padding: 8px 12px;
  background: var(--bg); border: 1px solid var(--rule); border-radius: var(--radius);
}
input::placeholder { color: var(--muted); opacity: .8; }

.icon-btn {
  position: relative;
  display: inline-grid; place-items: center;
  width: 42px; height: 42px; padding: 0;
  border: 0; border-radius: 50%; background: transparent; cursor: pointer; color: var(--text);
}
.icon-btn:hover { background: var(--panel-2); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.big { width: 60px; height: 60px; background: var(--accent); color: var(--accent-ink); }
.icon-btn.big:hover { background: var(--accent); filter: brightness(1.06); }
.icon-btn.big svg { width: 26px; height: 26px; fill: currentColor; stroke: none; }
.icon-btn[data-action=prev] svg path:last-child,
.icon-btn[data-action=skip] svg path:last-child { fill: currentColor; }
.icon-btn[data-action=stop] svg rect { fill: currentColor; stroke: none; }
.icon-btn.on { color: var(--accent); }
.badge { position: absolute; right: 6px; bottom: 6px; font-size: 10px; font-weight: 700; color: var(--accent); }

/* ---------- login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(360px, 100%); display: grid; gap: 10px; padding: 32px 28px;
  background: var(--panel); border: 1px solid var(--rule); border-radius: var(--radius-lg);
}
.login-card img { margin-bottom: 4px; }
.login-card h1 { font-size: 24px; margin-bottom: 12px; }
.login-card label { font-size: 14px; color: var(--muted); }
.login-step { display: grid; gap: 10px; }
.login-qr { width: 200px; height: 200px; margin: 0 auto; padding: 8px; background: #fff; border-radius: var(--radius); }
.login-secret { display: block; text-align: center; padding: 6px 8px; user-select: all; word-break: normal; overflow-wrap: anywhere; }
.form-error { color: var(--bad); font-size: 14px; min-height: 1.4em; }

/* ---------- top bar */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 24px; border-bottom: 1px solid var(--rule);
}
.conn {
  display: flex; align-items: center; gap: 12px; min-width: 0;
  padding: 6px 10px; margin-left: -10px;
  border: 0; border-radius: var(--radius); background: transparent; cursor: pointer; text-align: left;
}
.conn:hover { background: var(--panel); }
.conn-text { display: grid; min-width: 0; }
#conn-title { font-weight: 600; }
#conn-sub { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 4px color-mix(in srgb, var(--ok) 22%, transparent); }
.dot.busy { background: var(--warn); animation: blink 1.2s ease-in-out infinite; }
.dot.bad { background: var(--bad); }
@keyframes blink { 50% { opacity: .35; } }
.topbar-actions { margin-left: auto; display: flex; gap: 4px; }

.banner {
  margin: 16px 24px 0; padding: 10px 14px; border-radius: var(--radius);
  background: color-mix(in srgb, var(--warn) 16%, var(--panel)); border: 1px solid color-mix(in srgb, var(--warn) 45%, transparent);
}

/* ---------- layout */
.layout {
  display: grid; gap: 20px; padding: 20px 24px 40px;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
  grid-template-areas: "deck add" "lists lists";
  max-width: 1280px; margin: 0 auto;
}
.deck { grid-area: deck; }
.add { grid-area: add; }
.lists { grid-area: lists; }
.deck, .add, .lists {
  background: var(--panel); border: 1px solid var(--rule); border-radius: var(--radius-lg); padding: 22px;
  min-width: 0;
}

/* ---------- deck */
.deck-head { display: flex; gap: 18px; align-items: flex-start; min-height: 104px; }
.cover {
  flex: none; width: 104px; height: 104px; border-radius: 10px;
  background: var(--panel-2) center / cover no-repeat;
  display: grid; place-items: center;
}
.cover.empty::after {
  content: ""; width: 34px; height: 34px; border-radius: 50%;
  border: 2px solid var(--rule); box-shadow: inset 0 0 0 10px var(--panel-2), inset 0 0 0 12px var(--rule);
}
.deck-info { min-width: 0; display: grid; gap: 4px; }
.deck-state { font-size: 14px; color: var(--accent); font-weight: 600; }
.deck-state.idle { color: var(--muted); }
.deck-title {
  font-size: clamp(20px, 2.4vw, 28px); line-height: 1.2; font-weight: 700; letter-spacing: -.01em;
  overflow-wrap: anywhere;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.deck-meta { font-size: 14px; overflow-wrap: anywhere; }

.counter { display: flex; align-items: baseline; gap: 10px; margin: 22px 0 10px; }
.counter-pos { font-size: clamp(44px, 6vw, 64px); line-height: 1; font-weight: 300; letter-spacing: -.03em; }
.counter-dur { font-size: 20px; }

.seek {
  position: relative; height: 30px; cursor: pointer; touch-action: none;
  border-radius: 6px;
}
.seek::before {
  content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 6px; margin-top: -3px;
  background: var(--panel-2); border-radius: 3px;
}
.seek-fill {
  position: absolute; left: 0; top: 50%; height: 6px; margin-top: -3px; width: 0;
  background: var(--accent); border-radius: 3px;
}
.seek-head {
  position: absolute; top: 50%; left: 0; width: 16px; height: 16px; margin: -8px 0 0 -8px;
  border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px var(--panel);
}
.seek-ticks { position: absolute; inset: 0; pointer-events: none; }
.seek-ticks span { position: absolute; top: 3px; bottom: 3px; width: 1px; background: var(--rule); }
.seek.live { cursor: default; }
.seek.live .seek-fill { width: 100% !important; opacity: .35; }
.seek.live .seek-head { display: none; }
.seek.disabled { cursor: default; }
.seek.disabled .seek-head { display: none; }

.controls { display: flex; align-items: center; gap: 6px; margin-top: 16px; flex-wrap: wrap; }
.volume { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.volume svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.volume-value { width: 3ch; text-align: right; color: var(--text); }
input[type=range] { width: 130px; accent-color: var(--accent); }

/* ---------- add */
.add-form { display: grid; gap: 10px; }
.add-form label { font-weight: 600; }
.add-buttons { display: flex; gap: 8px; flex-wrap: wrap; }
.results { margin-top: 14px; }
.results .track-list { max-height: 420px; overflow: auto; }
.results-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; font-size: 14px; color: var(--muted); }
.loading { color: var(--muted); padding: 10px 0; }
.chat-help { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--rule); font-size: 14px; }
.chat-help h2 { font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.chat-help dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0; }
.chat-help dt { font-weight: 600; white-space: nowrap; }
.chat-help dd { margin: 0; color: var(--muted); }

/* ---------- lists */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--rule); margin: -6px -6px 12px; padding: 0 6px; overflow-x: auto; }
.tab {
  border: 0; background: transparent; padding: 10px 12px; cursor: pointer; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap;
}
.tab[aria-selected=true] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.count { color: var(--muted); font-weight: 400; }
.list-tools { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.list-tools input[type=search] { flex: 1; min-width: 180px; }
.empty { color: var(--muted); padding: 18px 0; }

.track-list { list-style: none; margin: 0; padding: 0; }
.track {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 6px;
}
.track + .track { border-top: 1px solid var(--rule); }
.track:hover { background: var(--panel-2); }
.track.dragging { opacity: .4; }
.track.drop-before { box-shadow: inset 0 2px 0 var(--accent); }
.grip { flex: none; width: 10px; height: 18px; cursor: grab; opacity: .5;
  background-image: radial-gradient(currentColor 1.3px, transparent 1.5px); background-size: 5px 6px; }
.track-list:not(.sortable) .grip { display: none; }
.track-num { min-width: 2ch; text-align: right; color: var(--muted); font-size: 13px; }
.track-thumb { flex: none; width: 44px; height: 44px; border-radius: 6px; object-fit: cover; background: var(--panel-2); }
.track-thumb.none { display: none; }
.track-body { flex: 1; display: grid; min-width: 0; }
.track-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.track-sub { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.track-actions { display: flex; gap: 2px; }
.track-actions .icon-btn { width: 34px; height: 34px; color: var(--muted); }
.track-actions .icon-btn:hover { color: var(--text); }
.track-actions .icon-btn svg { width: 18px; height: 18px; }
.track-actions .icon-btn.danger:hover { color: var(--bad); }
.track-actions .icon-btn.fill svg { fill: currentColor; stroke: none; }

/* ---------- users */
.users-intro { margin-bottom: 8px; }
.user-list { list-style: none; margin: 0; padding: 0; }
.user { display: grid; gap: 4px; padding: 12px 6px; }
.user + .user { border-top: 1px solid var(--rule); }
.user-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.user-name { font-size: 16px; font-weight: 600; overflow-wrap: anywhere; }
.user-badge {
  font-size: 12px; padding: 1px 8px; border-radius: 999px; color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 55%, transparent);
}
.user-uid { font-size: 12px; overflow-wrap: anywhere; }
.user-rights { display: flex; flex-wrap: wrap; gap: 4px 18px; margin-top: 4px; }
.user-rights label { display: flex; align-items: center; gap: 6px; min-height: 32px; cursor: pointer; }

/* ---------- dialogs */
.dialog {
  width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 32px);
  padding: 0; border: 1px solid var(--rule); border-radius: var(--radius-lg);
  background: var(--panel); color: var(--text);
}
.dialog.wide { width: min(760px, calc(100vw - 24px)); }
.dialog::backdrop { background: rgb(10 14 22 / .6); }
.dialog-inner { display: grid; gap: 14px; padding: 20px 22px 22px; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; }
.dialog-head h2 { font-size: 20px; }
.dialog h3 { font-size: 16px; margin-top: 6px; }
.dialog-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.dialog-foot {
  display: flex; justify-content: flex-end; gap: 8px;
  position: sticky; bottom: 0; margin: 0 -22px -22px; padding: 12px 22px 18px;
  background: var(--panel); border-top: 1px solid var(--rule);
}
fieldset { border: 1px solid var(--rule); border-radius: var(--radius); padding: 12px 14px 14px; margin: 0; display: grid; gap: 10px; }
legend { padding: 0 6px; font-weight: 600; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px 14px; }
.grid label { display: grid; gap: 4px; font-size: 14px; color: var(--muted); }
.grid label.check { display: flex; align-items: center; gap: 8px; color: var(--text); align-self: end; min-height: 40px; }
.grid .check-hint { display: grid; gap: 0; align-content: start; }
.grid .check-hint p { padding-left: 26px; }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); }

.channel-list { list-style: none; margin: 0; padding: 0; max-height: 50vh; overflow: auto; border: 1px solid var(--rule); border-radius: var(--radius); }
.channel-list li + li { border-top: 1px solid var(--rule); }
.channel-list button {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 9px 12px; border: 0; background: transparent; cursor: pointer; text-align: left;
}
.channel-list button:hover { background: var(--panel-2); }
.channel-list button.here { color: var(--accent); font-weight: 600; }
.channel-list .ch-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.channel-list .ch-meta { font-size: 13px; color: var(--muted); }

/* ---------- toasts */
.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 10; width: min(380px, calc(100vw - 32px)); }
.toast {
  padding: 10px 14px; border-radius: var(--radius); background: var(--panel-2);
  border: 1px solid var(--rule); border-left: 4px solid var(--ok);
  box-shadow: 0 6px 24px rgb(0 0 0 / .25);
}
.toast.error { border-left-color: var(--bad); }
.toast.info { border-left-color: var(--muted); }

/* ---------- responsive */
@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); grid-template-areas: "deck" "add" "lists"; padding: 16px; gap: 16px; }
  .topbar { padding: 8px 16px; }
  .banner { margin: 12px 16px 0; }
}
@media (max-width: 560px) {
  .deck, .add, .lists { padding: 16px; }
  .deck-head { gap: 14px; min-height: 0; }
  .cover { width: 72px; height: 72px; }
  .controls .spacer { flex-basis: 100%; }
  .volume { flex: 1; }
  .volume input { flex: 1; width: auto; }
  .track { gap: 8px; }
  .track .track-num { display: none; }
  .track-thumb { width: 40px; height: 40px; }
  #logout { display: none; }
}
@media (pointer: coarse) {
  .track-list.sortable .grip { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .dot.busy { animation: none; }
}
