:root {
  --bg: #0e1014;
  --surface: #161920;
  --surface-2: #1d212a;
  --surface-3: #252a35;
  --border: #2a303c;
  --text: #e9ebf1;
  --muted: #949cad;
  --accent: #8b5cf6;
  --accent-hover: #9d74fa;
  --accent-soft: rgba(139, 92, 246, .16);
  --on-accent: #fff;
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, .14);
  --ok: #22c55e;
  --ok-soft: rgba(34, 197, 94, .14);
  --warn: #f59e0b;
  --warn-soft: rgba(245, 158, 11, .14);
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 10px 40px rgba(0, 0, 0, .35);
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f5f8;
    --surface: #ffffff;
    --surface-2: #f2f3f7;
    --surface-3: #e7e9ef;
    --border: #dfe2ea;
    --text: #171a21;
    --muted: #646c7d;
    --accent: #7c3aed;
    --accent-hover: #6d28d9;
    --accent-soft: rgba(124, 58, 237, .1);
    --danger-soft: rgba(239, 68, 68, .1);
    --ok-soft: rgba(34, 197, 94, .12);
    --warn-soft: rgba(245, 158, 11, .14);
    --shadow: 0 10px 30px rgba(20, 24, 40, .1);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 26px; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 17px; font-weight: 650; }
p { margin: 0; }
[hidden] { display: none !important; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }

.wrap { max-width: 1100px; margin: 0 auto; padding: 0 16px 48px; }
.wrap.narrow { max-width: 640px; }

/* ---------- Верхняя панель ---------- */
.topbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 14px 0;
}
.logo {
  display: inline-flex; align-items: center; gap: 8px;
  font-weight: 800; font-size: 17px; letter-spacing: .02em; color: var(--text);
}
.logo:hover { text-decoration: none; }
.logo-mark {
  width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center;
  background: var(--accent); color: var(--on-accent); font-size: 13px;
}
.spacer { flex: 1; }

/* ---------- Карточки ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-top: 16px;
}
.card > h2 { margin-bottom: 12px; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }

.hero { padding: 36px 0 8px; }
.hero h1 { font-size: 32px; margin: 18px 0 8px; }
.hero p { font-size: 16px; max-width: 540px; }

/* ---------- Формы ---------- */
label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); }
label > input, label > textarea, label > select { margin-top: 6px; }
input, textarea, select {
  width: 100%;
  font: inherit; color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .7; }
textarea { resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
.hint { font-weight: 400; color: var(--muted); font-size: 12px; margin-top: 4px; }

.stack { display: grid; gap: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > input { flex: 1; min-width: 180px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 520px) { .grid-2 { grid-template-columns: 1fr; } }

.check { display: flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 500; color: var(--text); cursor: pointer; }
.check input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); }

/* ---------- Кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 600; font-size: 14px;
  color: var(--text); background: var(--surface-3);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 9px 14px; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); border-color: var(--muted); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.big { padding: 14px 22px; font-size: 16px; }
.btn.block { width: 100%; }
.btn.file { position: relative; overflow: hidden; }
.icon-btn {
  width: 32px; height: 32px; flex: none; display: grid; place-items: center;
  border-radius: 8px; border: 1px solid transparent; background: transparent;
  color: var(--muted); cursor: pointer; font-size: 16px; line-height: 1;
}
.icon-btn:hover { color: var(--danger); background: var(--danger-soft); border-color: var(--danger-soft); }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  font: inherit; font-size: 12px; font-weight: 700;
  padding: 4px 10px; border-radius: 99px; border: 1px solid transparent; cursor: pointer;
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.on { background: var(--ok-soft); color: var(--ok); }
.pill.off { background: var(--warn-soft); color: var(--warn); }
.pill:hover { border-color: currentColor; }

.notice { border-radius: var(--radius-sm); padding: 10px 12px; font-size: 14px; }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.err { background: var(--danger-soft); color: var(--danger); }

.form-msg { font-size: 14px; min-height: 0; }
.form-msg:empty { display: none; }
.form-msg.ok { color: var(--ok); }
.form-msg.err { color: var(--danger); }

/* ---------- Список плейлистов на главной ---------- */
.plist { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.plist li {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface-2);
}
.plist .name { flex: 1; min-width: 150px; font-weight: 600; }
.plist .name small { display: block; font-weight: 400; color: var(--muted); }
.actions { margin-top: 14px; display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- Очередь ---------- */
.queue { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.qitem {
  display: grid; grid-template-columns: auto 96px 1fr auto; gap: 12px; align-items: center;
  padding: 8px; border-radius: var(--radius-sm); background: var(--surface-2);
  border: 1px solid transparent;
}
.qitem.mine { border-color: var(--accent); background: var(--accent-soft); }
.qnum { width: 24px; text-align: center; color: var(--muted); font-weight: 700; font-size: 13px; font-variant-numeric: tabular-nums; }
.thumb {
  width: 96px; aspect-ratio: 16 / 9; border-radius: 6px; object-fit: cover;
  background: var(--surface-3); display: block;
}
.qbody { min-width: 0; }
.qtitle {
  font-weight: 600; font-size: 14px; color: var(--text);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  word-break: break-word;
}
a.qtitle:hover { color: var(--accent); text-decoration: none; }
.qmeta { font-size: 12px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 2px; }
.qmeta b { color: var(--text); font-weight: 600; }
.badge { font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 99px; background: var(--accent); color: var(--on-accent); }
.empty { padding: 26px 12px; text-align: center; color: var(--muted); font-size: 14px; }

.now {
  display: grid; grid-template-columns: 160px 1fr; gap: 14px; align-items: center;
  padding: 12px; border-radius: var(--radius); margin-bottom: 14px;
  background: linear-gradient(135deg, var(--accent-soft), transparent 70%), var(--surface-2);
  border: 1px solid var(--border);
}
.now .thumb { width: 160px; }
.now-label { font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); }
.now .qtitle { font-size: 15px; }
@media (max-width: 520px) {
  .now { grid-template-columns: 110px 1fr; }
  .now .thumb { width: 110px; }
  .qitem { grid-template-columns: auto 72px 1fr auto; gap: 10px; }
  .thumb { width: 72px; }
}

/* ---------- Предпросмотр ролика в форме ---------- */
.preview {
  display: grid; grid-template-columns: 120px 1fr; gap: 12px; align-items: center;
  padding: 8px; border-radius: var(--radius-sm); background: var(--surface-2); font-size: 13px;
}
.preview .thumb { width: 120px; }
.preview.bad { grid-template-columns: 1fr; color: var(--danger); background: var(--danger-soft); }

/* ---------- Страница зрителя ---------- */
.viewer-head { margin: 8px 0 4px; }
.viewer-head p { margin-top: 4px; }
.rules { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.chip { font-size: 12px; padding: 3px 10px; border-radius: 99px; background: var(--surface-3); color: var(--muted); }
.chip b { color: var(--text); }
.viewer-grid { display: grid; grid-template-columns: minmax(0, 420px) minmax(0, 1fr); gap: 16px; align-items: start; }
.viewer-grid .card { margin-top: 0; }
@media (max-width: 860px) { .viewer-grid { grid-template-columns: 1fr; } }
.sticky { position: sticky; top: 16px; }
@media (max-width: 860px) { .sticky { position: static; } }

/* ---------- Студия ---------- */
.studio-body { min-height: 100vh; }
.studio { max-width: 1500px; margin: 0 auto; padding: 0 16px 24px; }
.studio .topbar .title { font-size: 18px; font-weight: 700; max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conn { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; }
.conn.off { background: var(--danger); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .3; } }

.studio-main { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 16px; align-items: start; }
@media (max-width: 1000px) { .studio-main { grid-template-columns: 1fr; } }

.player-box {
  position: relative; width: 100%; aspect-ratio: 16 / 9;
  background: #000; border-radius: var(--radius); overflow: hidden;
  border: 1px solid var(--border);
}
.player-box #player, .player-box iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.player-box.hide-video #player { visibility: hidden; }
.overlay {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding: 24px; text-align: center; color: #cfd3dc; background: #0b0c10;
}
.overlay.bg { background-size: cover; background-position: center; }
.overlay.bg::before { content: ""; position: absolute; inset: 0; background: rgba(8, 9, 12, .78); backdrop-filter: blur(6px); }
.overlay > * { position: relative; }
.overlay .big-icon { font-size: 44px; line-height: 1; opacity: .8; }
.overlay p { max-width: 440px; font-size: 14px; color: #a7adba; }
.overlay h3 { font-size: 18px; color: #fff; }
.overlay.error-ov { background: rgba(10, 10, 12, .88); }
.overlay.error-ov h3 { color: #fca5a5; }

.nowbar {
  display: flex; align-items: center; gap: 14px; margin-top: 12px;
  padding: 12px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.nowbar .info { flex: 1; min-width: 0; }
.nowbar .qtitle { font-size: 16px; -webkit-line-clamp: 1; }
.studio-opts { display: flex; gap: 18px; flex-wrap: wrap; align-items: center; margin-top: 12px; padding: 0 4px; }
kbd { font: 600 11px ui-monospace, monospace; padding: 1px 5px; border-radius: 4px; border: 1px solid var(--border); background: var(--surface-2); color: var(--muted); }

.side { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.side-col { min-width: 0; }
.side .queue { max-height: calc(100vh - 330px); min-height: 160px; overflow-y: auto; padding-right: 2px; }
@media (max-width: 1000px) { .side .queue { max-height: none; } }
.side .qitem { grid-template-columns: auto 80px 1fr auto; gap: 10px; }
.side .thumb { width: 80px; }

/* ---------- Диалоги ---------- */
dialog {
  width: min(520px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(5, 6, 10, .6); backdrop-filter: blur(2px); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.dlg-body { padding: 20px; display: grid; gap: 16px; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border); }
.dlg-close { font-size: 20px; }
.dlg-close:hover { color: var(--text); background: var(--surface-3); border-color: transparent; }
.copy-field { display: flex; gap: 8px; margin-top: 6px; }
.copy-field input { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.section-title { font-size: 14px; font-weight: 700; color: var(--text); }
.divider { height: 1px; background: var(--border); }

/* ---------- Уведомления ---------- */
#toasts { position: fixed; z-index: 1000; left: 50%; bottom: 20px; transform: translateX(-50%); display: grid; gap: 8px; width: min(440px, calc(100vw - 32px)); pointer-events: none; }
.toast {
  padding: 11px 16px; border-radius: var(--radius-sm); font-size: 14px; font-weight: 500;
  background: var(--surface-3); color: var(--text); border: 1px solid var(--border); box-shadow: var(--shadow);
  animation: toast-in .2s ease-out; transition: opacity .3s, transform .3s;
}
.toast.ok { border-color: var(--ok); }
.toast.err { border-color: var(--danger); }
.toast.out { opacity: 0; transform: translateY(6px); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

.spinner { width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Пока i18n.js не перевёл разметку, страницу не показываем — без мигания чужого языка.
   Если скрипт не загрузился, через 1,5 с страница всё равно появится. */
.i18n-pending body { visibility: hidden; animation: i18n-reveal 0s 1.5s forwards; }
@keyframes i18n-reveal { to { visibility: visible; } }

.lang-switch { display: inline-flex; padding: 2px; border-radius: 9px; background: var(--surface-2); border: 1px solid var(--border); }
.lang-switch button {
  font: inherit; font-size: 12px; font-weight: 700; letter-spacing: .03em;
  padding: 4px 9px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); cursor: pointer;
}
.lang-switch button:hover { color: var(--text); }
.lang-switch button.active { background: var(--surface-3); color: var(--text); }

/* Поле ника на главной */
.nick-row { display: flex; gap: 10px; align-items: stretch; flex-wrap: wrap; margin-top: 6px; }
.nick-row input { flex: 1; min-width: 180px; margin: 0; }
.nick-input.bad { border-color: var(--danger); }
.nick-input.bad:focus { box-shadow: 0 0 0 3px var(--danger-soft); }
.nick-status { font-size: 13px; margin-top: 8px; min-height: 20px; color: var(--muted); word-break: break-all; }
.nick-status .ok { color: var(--ok); font-weight: 600; }
.nick-status .err { color: var(--danger); word-break: normal; }
.nick-status code { font: 600 13px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; color: var(--text); }

/* Блок «Ссылка для зрителей» в студии */
.link-box {
  background: linear-gradient(135deg, var(--accent-soft), transparent 75%), var(--surface);
  border: 1px solid var(--accent); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 16px;
}
.link-box .section-title { display: flex; align-items: center; gap: 8px; }
.link-box p { font-size: 12px; color: var(--muted); margin-top: 2px; }
.link-box .copy-field { margin-top: 10px; flex-wrap: wrap; }
.link-box .copy-field input { flex: 1 1 100%; min-width: 0; font-size: 14px; font-weight: 600; color: var(--text); background: var(--surface-2); }
.link-box .copy-field .btn { flex: 1 1 0; }

.notfound { padding: 80px 16px; text-align: center; }
.notfound h1 { margin-bottom: 10px; }
.notfound p { margin-bottom: 20px; }
