:root {
  --bg: #0d0f14;
  --panel: #151922;
  --panel-2: #1c212c;
  --line: #262d3a;
  --text: #e7ebf3;
  --muted: #8a93a6;
  --accent: #5b8cff;
  --accent-soft: rgba(91, 140, 255, 0.15);
  --danger: #ff6b6b;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Arial, sans-serif;
}

button, input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  padding: 9px 14px;
  border-radius: 9px;
  transition: background .15s, border-color .15s;
}

button:hover:not(:disabled) { background: #232a38; border-color: #38425a; }
button:disabled { opacity: .45; cursor: not-allowed; }

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #08101f;
  font-weight: 600;
}
button.primary:hover:not(:disabled) { background: #6f9bff; border-color: #6f9bff; }

input[type="text"], input[type="url"] {
  background: #0f131b;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 12px;
  width: 100%;
  outline: none;
}
input:focus { border-color: var(--accent); }

/* ---------- Лендинг ---------- */
.landing {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}

.card {
  width: min(440px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px;
}

.card h1 { margin: 0 0 6px; font-size: 26px; letter-spacing: -0.02em; }
.card p.sub { margin: 0 0 22px; color: var(--muted); font-size: 14px; }

.field { margin-bottom: 14px; }
.field label { display: block; margin-bottom: 6px; font-size: 13px; color: var(--muted); }

.row { display: flex; gap: 8px; }
.row > input { flex: 1; }

.hint { margin-top: 18px; font-size: 12.5px; color: var(--muted); line-height: 1.6; }

/* ---------- Комната ---------- */
.room {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 14px;
  padding: 14px;
  height: 100vh;
}

.stage { display: flex; flex-direction: column; gap: 12px; min-width: 0; }

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.topbar .brand { font-weight: 600; letter-spacing: -0.01em; }
.topbar .room-id {
  color: var(--muted);
  font-size: 13px;
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 4px 9px;
  border-radius: 7px;
}
.topbar .spacer { flex: 1; }

.status {
  font-size: 12.5px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); }
.dot.on { background: #4ade80; }

.player-wrap {
  position: relative;
  background: #000;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 16 / 9;
}

video { width: 100%; height: 100%; display: block; background: #000; }

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 20px;
  background: rgba(9, 11, 16, .82);
  backdrop-filter: blur(3px);
}
.overlay.hidden { display: none; }
.overlay .msg { max-width: 420px; }
.overlay .msg h3 { margin: 0 0 8px; font-size: 17px; }
.overlay .msg p { margin: 0 0 14px; color: var(--muted); font-size: 14px; }

/* Не-хост не должен трогать плеер: перехватываем клики поверх видео. */
.guard {
  position: absolute;
  inset: 0;
  cursor: not-allowed;
}
.guard.hidden { display: none; }

.controls {
  display: flex;
  gap: 8px;
  align-items: center;
}
.controls .url-row { flex: 1; display: flex; gap: 8px; min-width: 0; }

.note {
  font-size: 12.5px;
  color: var(--muted);
  padding: 8px 11px;
  background: var(--accent-soft);
  border: 1px solid rgba(91, 140, 255, .25);
  border-radius: 9px;
}

/* ---------- Сайдбар ---------- */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel > h2 {
  margin: 0;
  padding: 12px 14px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  font-weight: 600;
}

.users { padding: 8px; display: flex; flex-direction: column; gap: 4px; max-height: 210px; overflow-y: auto; }

.user {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 9px;
  border-radius: 8px;
  font-size: 14px;
}
.user:hover { background: var(--panel-2); }
.user .crown { font-size: 12px; }
.user .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user .give {
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 6px;
  opacity: 0;
}
.user:hover .give { opacity: 1; }

.chat-panel { flex: 1; min-height: 0; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}

.msg-row { font-size: 14px; word-wrap: break-word; overflow-wrap: anywhere; }
.msg-row .who { color: var(--accent); font-weight: 600; margin-right: 5px; }
.msg-row.system { color: var(--muted); font-size: 12.5px; font-style: italic; }

.composer {
  display: flex;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--line);
}

::-webkit-scrollbar { width: 9px; }
::-webkit-scrollbar-thumb { background: #2a3140; border-radius: 9px; }
::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 900px) {
  .room {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
  }
  .sidebar { height: 60vh; }
}

/* Плеер YouTube занимает то же место, что и <video>. */
.yt { position: absolute; inset: 0; }
.yt iframe { width: 100%; height: 100%; border: 0; display: block; }
.hidden { display: none !important; }

/* ---------- Очередь ---------- */
.queue {
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 240px;
  overflow-y: auto;
}

.queue:empty::after {
  content: 'Пусто. Добавь ссылку под плеером.';
  color: var(--muted);
  font-size: 13px;
  padding: 6px 9px;
}

.qitem {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 9px;
  border-radius: 8px;
  font-size: 13.5px;
  border: 1px solid transparent;
}
.qitem:hover { background: var(--panel-2); }
.qitem.current { background: var(--accent-soft); border-color: rgba(91, 140, 255, .35); }

.qitem .idx { color: var(--muted); font-size: 12px; min-width: 14px; text-align: right; }
.qitem .qtitle {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.qitem .qby { color: var(--muted); font-size: 11.5px; }
.qitem .qdel {
  padding: 2px 7px;
  font-size: 12px;
  border-radius: 6px;
  opacity: 0;
}
.qitem:hover .qdel { opacity: 1; }
.qitem.playable .qtitle { cursor: pointer; }

/* ---------- Ожидание отстающих ---------- */
.stall {
  position: absolute;
  left: 12px;
  bottom: 12px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 13px;
  border-radius: 10px;
  background: rgba(9, 11, 16, .88);
  border: 1px solid var(--line);
  font-size: 13px;
}

.spinner {
  width: 13px;
  height: 13px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.user .buf { font-size: 11px; color: var(--muted); }

/* ---------- Настройки под плеером ---------- */
.note-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.note-row .note { flex: 1; min-width: 220px; }

.toggle {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
.toggle input { accent-color: var(--accent); cursor: pointer; }
.toggle.disabled { opacity: .45; cursor: not-allowed; }

/* ---------- Модальное окно ---------- */
.modal-back {
  position: fixed;
  inset: 0;
  background: rgba(6, 8, 12, .7);
  display: grid;
  place-items: center;
  z-index: 50;
  padding: 20px;
}

.modal {
  width: min(340px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px;
}
.modal h3 { margin: 0 0 14px; font-size: 17px; }
.modal-row { display: flex; justify-content: flex-end; margin-top: 14px; }

/* Собственные кнопки хоста: у YouTube-плеера нативные контролы задаются один
   раз при создании iframe, поэтому получивший пульт по ходу сеанса остался бы
   вообще без управления. */
.host-controls { display: flex; gap: 6px; }
.host-controls.hidden { display: none; }
.host-controls button { padding: 9px 11px; min-width: 44px; }
