:root {
  --bg: #0a0d15;
  --panel: #111623;
  --card: #171d2c;
  --hover: #1f2637;
  --text: #e8ebf2;
  --muted: #9aa3b8;
  --subtle: #8a93a8;
  --divider: rgba(255, 255, 255, 0.07);
  --border: rgba(255, 255, 255, 0.09);
  --accent: #7c5cff;
  --accent-soft: rgba(124, 92, 255, 0.16);
  --accent-text: #b6a2ff;
  --electric: #2fb8ff;
  --live: #ff4d5e;
  --live-text: #ff8a96;
  --online: #3ecf8e;
  --shadow-2: 0 18px 40px -12px rgba(0, 0, 0, 0.85);
  --radius: 14px;
}

:root[data-theme="light"] {
  --bg: #f4f5f9;
  --panel: #ffffff;
  --card: #f6f7fa;
  --hover: #edeff5;
  --text: #12161f;
  --muted: #5c6478;
  --subtle: #6b7488;
  --divider: rgba(10, 13, 21, 0.08);
  --border: rgba(10, 13, 21, 0.12);
  --accent: #6a45f5;
  --accent-soft: rgba(106, 69, 245, 0.1);
  --accent-text: #5a38d6;
  --live: #e02034;
  --live-text: #c21b2c;
  --online: #17a06a;
  --shadow-2: 0 18px 40px -18px rgba(10, 13, 21, 0.25);
}

* { box-sizing: border-box; }

/* Атрибут hidden обязан побеждать display из классов, иначе экраны наслаиваются. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font: 400 14px/1.5 "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

button { font: inherit; color: inherit; cursor: pointer; }

/* ── Экран входа ─────────────────────────────────────────────── */
.gate {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(120% 90% at 50% 0%, rgba(124, 92, 255, 0.18), transparent 60%), var(--bg);
}
.gate__card {
  width: min(440px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 28px;
  box-shadow: var(--shadow-2);
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.gate__title { font-size: 21px; font-weight: 600; letter-spacing: -0.02em; margin: 0; }
.gate__sub { margin: 0; color: var(--muted); font-size: 13px; }
.gate input {
  width: 100%;
  padding: 13px 14px;
  border-radius: 11px;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 15px;
}
/* Форма гостя: у неё не было своей раскладки, и поля слипались (скриншот живого прогона 18.11: зазор между «Имя» и «@ник» ≈2px).
   16px — шаг карточки .gate__card (gap выше), по скриншоту ровно такой же между заголовком, подписью и первым полем. */
.gate__form { display: flex; flex-direction: column; gap: 16px; }
.gate__note:empty { display: none; }
.gate input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.btn-primary {
  padding: 13px 18px;
  border: 0;
  border-radius: 11px;
  background: linear-gradient(180deg, #8468ff, #6a45f5);
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  box-shadow: 0 8px 20px -8px rgba(124, 92, 255, 0.8);
}
.btn-primary:disabled { opacity: 0.5; cursor: default; box-shadow: none; }

/* ── Каркас комнаты ──────────────────────────────────────────── */
.room { display: flex; flex-direction: column; height: var(--app-height, 100dvh); }

.topbar {
  flex: none;
  height: 58px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 16px;
  border-bottom: 1px solid var(--divider);
  background: var(--panel);
}
.brand { display: flex; align-items: center; gap: 9px; flex: none; }
.brand__mark {
  width: 26px; height: 26px; border-radius: 999px;
  background: conic-gradient(from 200deg, #7c5cff, #2fb8ff, #7c5cff);
  display: grid; place-items: center;
}
.brand__mark i { width: 14px; height: 14px; border-radius: 999px; background: var(--panel); display: block; }
.brand__text { font-size: 13px; font-weight: 600; white-space: nowrap; }
.brand__text span { color: var(--subtle); font-weight: 500; }

.titles { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.titles h1 {
  margin: 0; font-size: 14px; font-weight: 600; letter-spacing: -0.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.titles p { margin: 0; font-size: 11px; color: var(--muted); }

.badges { display: flex; align-items: center; gap: 9px; flex: none; }
.pill-live {
  display: flex; align-items: center; gap: 7px;
  padding: 5px 10px; border-radius: 999px;
  background: rgba(255, 77, 94, 0.12); border: 1px solid rgba(255, 77, 94, 0.28);
  font-size: 11px; font-weight: 600; letter-spacing: 0.08em; color: var(--live-text);
}
.dot { width: 7px; height: 7px; border-radius: 999px; background: var(--live); }
.dot--pulse { animation: pulse 2s infinite; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(255, 77, 94, 0.55); }
  70% { box-shadow: 0 0 0 7px rgba(255, 77, 94, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 77, 94, 0); }
}
.viewers { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.viewers .dot { background: var(--online); width: 6px; height: 6px; }
.elapsed { font-size: 12px; color: var(--subtle); font-variant-numeric: tabular-nums; }

.spacer { flex: 1; }

.icon-btn {
  height: 32px; min-width: 32px; padding: 0 10px;
  display: inline-flex; align-items: center; gap: 6px;
  border-radius: 9px; background: transparent;
  border: 1px solid var(--border); color: var(--muted); font-size: 12px;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }

.body { flex: 1; min-height: 0; display: flex; gap: 16px; padding: 16px; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 12px; }

/* ── Плеер ───────────────────────────────────────────────────── */
.stage {
  position: relative;
  background: #000;
  border: 1px solid var(--divider);
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 1760 / 900;
  max-height: calc(100dvh - 190px);
}
.stage video { width: 100%; height: 100%; display: block; object-fit: contain; background: #000; }

.stage__badge {
  position: absolute; top: 12px; left: 12px;
  display: flex; align-items: center; gap: 6px;
  padding: 5px 9px; border-radius: 8px;
  background: rgba(10, 13, 21, 0.6); backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 10px; font-weight: 600; letter-spacing: 0.1em; color: #ffd5d9;
}
.stage__controls {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 26px 14px 12px;
  background: linear-gradient(180deg, transparent, rgba(8, 10, 17, 0.9));
  display: flex; align-items: center; gap: 10px;
  opacity: 0; transition: opacity 0.18s;
}
.stage:hover .stage__controls, .stage__controls:focus-within { opacity: 1; }
.ctl {
  height: 30px; padding: 0 10px; border-radius: 8px;
  background: rgba(255, 255, 255, 0.1); border: 0; color: #fff; font-size: 12px;
}
.ctl:hover { background: rgba(255, 255, 255, 0.2); }
input[type="range"] { width: 84px; accent-color: #fff; }

.loader {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  padding: 9px 14px; border-radius: 10px;
  background: rgba(10, 13, 21, 0.72); border: 1px solid rgba(255, 255, 255, 0.12);
  color: #e8ebf2; font-size: 12px;
}
.problem {
  position: absolute; inset: auto 0 0 0; margin: auto; width: max-content;
  bottom: 50%; display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 16px 20px; border-radius: 12px;
  background: rgba(10, 13, 21, 0.9); border: 1px solid rgba(255, 77, 94, 0.35);
  color: #e8ebf2; font-size: 13px;
}

.overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center; gap: 32px;
  padding: 20px; background: #06080e; color: #e8ebf2; overflow: hidden;
}
/* Плакат показывается целиком и не перекрывается отсчётом: на нём свой заголовок. */
.overlay__cover {
  flex: 0 1 auto; height: 88%; aspect-ratio: 4 / 3; min-width: 0;
  background: center / contain no-repeat;
  border-radius: 12px;
}
.overlay__inner {
  flex: 0 0 auto;
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px;
}
.overlay__kicker {
  font-size: 12px; font-weight: 600; letter-spacing: 0.16em; text-transform: uppercase;
  color: #b6a2ff;
}
.overlay__lead { font-size: 15px; color: #c6cddb; }
.overlay__note { font-size: 12px; color: var(--subtle); margin-top: 6px; max-width: 260px; }
.countdown { display: flex; gap: 10px; font-variant-numeric: tabular-nums; margin-top: 2px; }
.countdown div {
  min-width: 86px; padding: 14px 10px; border-radius: 14px;
  background: #161c2c; border: 1px solid var(--border);
  font-size: 34px; font-weight: 500;
}
/* Второй span в ячейке — подпись «минут»; первый остаётся крупной цифрой. */
.countdown div span:nth-child(2) { display: block; font-size: 11px; color: var(--subtle); font-weight: 400; margin-top: 6px; }

/* ── Полка под плеером ───────────────────────────────────────── */
/* Полоса брони: то же место, что и полка, но заметная — это главное
   действие эфира, и мимо неё пройти нельзя. */
.cta {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 14px; border-radius: 12px;
  background: var(--accent-soft); border: 1px solid var(--accent);
  font-size: 12px; color: var(--muted);
  animation: cta-in .35s ease-out;
}
@keyframes cta-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
.cta__text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.cta__text b { color: var(--text); font-weight: 600; font-size: 14px; }
.cta__btn { flex: none; padding: 10px 18px; font-size: 13px; text-decoration: none; }
.cta__close {
  flex: none; width: 28px; height: 28px; border-radius: 8px;
  background: transparent; border: none; color: var(--subtle); font-size: 13px;
}
.cta__close:hover { background: var(--hover); color: var(--text); }

.shelf {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px; border-radius: 12px;
  background: var(--panel); border: 1px solid var(--divider);
  font-size: 12px; color: var(--muted);
}
.shelf b { color: var(--text); font-weight: 600; font-size: 13px; }

/* ── Чат ─────────────────────────────────────────────────────── */
.chat {
  width: 380px; flex: none;
  display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--divider);
  border-radius: var(--radius); overflow: hidden;
}
.chat__head {
  flex: none; padding: 11px 12px;
  border-bottom: 1px solid var(--divider);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.chat__head strong { font-size: 13px; }
.chat__feed {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  padding: 12px; display: flex; flex-direction: column; gap: 11px;
}
.msg { display: flex; gap: 9px; }
.msg__avatar {
  width: 27px; height: 27px; flex: none; border-radius: 999px;
  display: grid; place-items: center; font-size: 10px; font-weight: 600;
}
.msg__body { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 3px; }
.msg__head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.msg__name { font-size: 12px; font-weight: 600; }
.msg__time { font-size: 10px; color: var(--subtle); font-variant-numeric: tabular-nums; }
.msg__text { font-size: 13px; line-height: 1.45; word-wrap: break-word; overflow-wrap: anywhere; white-space: pre-wrap; }
.msg__quote {
  border-left: 2px solid var(--border); padding: 3px 0 3px 8px;
  font-size: 11px; color: var(--subtle);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.msg__reactions { display: flex; gap: 5px; margin-top: 2px; }
.reaction {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 7px; border-radius: 999px;
  background: var(--card); border: 1px solid var(--divider); font-size: 11px;
}
.reaction span { color: var(--muted); font-size: 10px; }

/* Сообщения из записи и живые выглядят одинаково: зритель не должен их
   различать. Класс msg--replay в разметке остаётся — он нужен пульту. */
.msg__text { color: var(--text); }
.msg__name { color: var(--text); }
.msg--own .msg__text {
  background: var(--accent-soft); border: 1px solid var(--border);
  padding: 7px 10px; border-radius: 10px;
}
/* Действия над сообщением: ответить, а у команды — ещё скрыть и лишить слова.
   На мышке появляются при наведении, на тач-экранах видны всегда. */
.msg__acts { display: flex; gap: 4px; align-items: center; opacity: 0; transition: opacity .12s; }
.msg:hover .msg__acts, .msg:focus-within .msg__acts { opacity: 1; }
@media (hover: none) { .msg__acts { opacity: .55; } }
.msg__act {
  padding: 1px 6px; border-radius: 6px; font-size: 10px; line-height: 16px;
  background: transparent; border: 1px solid transparent; color: var(--subtle);
}
.msg__act:hover { background: var(--hover); border-color: var(--divider); color: var(--text); }
.msg__act--danger:hover { color: var(--live-text); }

.reply-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px; border-radius: 9px;
  background: var(--card); border: 1px solid var(--divider);
  border-left: 2px solid var(--accent);
}
.reply-bar__body { flex: 1; min-width: 0; font-size: 11px; }
.reply-bar__name { font-weight: 600; margin-right: 6px; }
.reply-bar__text { color: var(--subtle); }
.reply-bar__body { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reply-bar__close { flex: none; font-size: 11px; color: var(--subtle); background: none; border: none; }

/* Для команды с правами модерации лента записи приглушена, живые реплики
   яркие и с пометкой. Зритель этих правил не получает — у него всё одинаково. */
body[data-moder="1"] .msg--replay .msg__text,
body[data-moder="1"] .msg--replay .msg__name { color: var(--muted); }
body[data-moder="1"] .msg--replay .msg__avatar { opacity: .5; }
body[data-moder="1"] .msg--live { border-left: 2px solid var(--accent); padding-left: 8px; margin-left: -10px; }
.badge-role--live { background: rgba(62, 207, 142, .16); color: #6dc9a4; }

/* Ссылка ведущего — главное действие эфира, её видно и пальцем не промахнёшься. */
.msg__link {
  color: var(--accent-text); text-decoration: underline; text-underline-offset: 2px;
  overflow-wrap: anywhere; padding: 1px 0;
}
.msg__link:hover { text-decoration-thickness: 2px; }

.badge-role {
  padding: 1px 6px; border-radius: 5px; font-size: 10px; font-weight: 500;
  background: var(--accent-soft); color: var(--accent-text);
}

.chat__new {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: 96px; z-index: 5;
  padding: 7px 13px; border-radius: 999px;
  background: var(--hover); border: 1px solid var(--border);
  font-size: 12px; font-weight: 500; box-shadow: var(--shadow-2);
}
.chat__wrap { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; }

.composer {
  flex: none; padding: 10px 12px 12px;
  border-top: 1px solid var(--divider);
  display: flex; flex-direction: column; gap: 8px;
}
.quick { display: flex; gap: 6px; align-items: center; }
.quick button {
  width: 36px; height: 30px; border-radius: 9px;
  background: var(--card); border: 1px solid var(--divider); font-size: 15px;
}
.quick button:hover { background: var(--hover); }
.quick .hint { flex: 1; text-align: right; font-size: 10px; color: var(--subtle); }
.composer__row { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea {
  flex: 1; min-height: 40px; max-height: 110px; resize: none;
  padding: 10px 12px; border-radius: 11px;
  background: var(--card); border: 1px solid var(--border); color: var(--text);
  font: inherit; font-size: 13px;
}
.composer textarea:disabled, .quick button:disabled { opacity: .5; cursor: not-allowed; }
.composer .btn-primary:disabled { opacity: .4; }
.composer textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.composer .btn-primary { padding: 11px 16px; }

.ended { display: grid; place-items: center; text-align: center; gap: 10px; height: 100%; }

@media (max-width: 900px) {
  .body { flex-direction: column; padding: 8px; gap: 8px; }
  /* Видео занимает столько, сколько нужно по пропорции, остальное отдаём чату. */
  .main { flex: none; }
  .chat { width: auto; flex: 1; min-height: 0; }
  .stage { max-height: none; }
  .titles h1 { font-size: 13px; }
  .titles p, .elapsed, .brand__text { display: none; }
  /* Инструкция про бота нужна как раз мобильным зрителям — показываем её,
     только компактнее. */
  /* На телефоне место дорого: полоса брони — только заголовок, кнопка и крестик. */
  .cta { padding: 9px 10px; gap: 8px; }
  .cta__text span { display: none; }
  .cta__text b { font-size: 13px; }
  .cta__btn { padding: 9px 14px; }
  .cta__close { width: 34px; height: 34px; font-size: 15px; }

  .shelf { padding: 8px 10px; font-size: 11px; gap: 6px; }
  .shelf b { font-size: 12px; }
  .topbar { gap: 8px; padding: 0 10px; height: 52px; }
  .titles { flex: 1; }
  .badges { gap: 7px; }
  .pill-live { padding: 4px 8px; font-size: 10px; }
  .viewers { font-size: 11px; }
  .icon-btn { padding: 0 8px; }
  .chat__feed { padding: 10px; gap: 10px; }
  /* Кнопки должны нажиматься пальцем, а не ногтем. */
  .quick button { width: 44px; height: 38px; }
  .composer .btn-primary { padding: 12px 14px; }
  .stage__controls { opacity: 1; }

  /* Шрифт меньше 16px заставляет Safari зумить страницу при фокусе на поле —
     после этого вёрстка уезжает за край экрана. Поэтому ровно 16. */
  .composer textarea, .gate input { font-size: 16px; }
  .quick .hint { display: none; }
  .composer__row { gap: 6px; }
  .composer .btn-primary { padding: 12px 0; width: 46px; font-size: 0; position: relative; }
  .composer .btn-primary::after {
    content: "↑"; font-size: 18px; font-weight: 600; position: absolute; inset: 0;
    display: grid; place-items: center;
  }
  .chat, .composer, .composer__row { min-width: 0; max-width: 100%; }

  /* iOS при фокусе на поле прокручивает саму страницу и уносит вёрстку вверх.
     Прокручивать нечего — страница прибита к экрану, скроллится только лента. */
  html, body { position: fixed; inset: 0; width: 100%; height: 100%; overflow: hidden; }

  /* При открытой клавиатуре важна лента, а не быстрые реакции и большая картинка. */
  body[data-keyboard="open"] .quick { display: none; }
  body[data-keyboard="open"] .stage { max-height: 26vh; }
  body[data-keyboard="open"] .chat__head { display: none; }
  .countdown div { min-width: 64px; padding: 9px 8px; font-size: 24px; border-radius: 11px; }
  /* На телефоне столбцы не помещаются: плакат сверху, отсчёт под ним. */
  /* До старта картинка не нужна, зато нужен читаемый плакат и отсчёт:
     разрешаем сцене стать выше, чем позволяет пропорция видео. */
  body[data-phase="pre"] .stage, body[data-phase="ended"] .stage { aspect-ratio: auto; height: 46dvh; }
  .overlay { flex-direction: column; gap: 8px; padding: 10px; justify-content: center; }
  /* Плакат — пустой блок с фоном: при width/height auto в колоночном flex он
     схлопывался в ноль, и на телефоне заставки просто не было. Задаём высоту
     явно, ширину во весь экран, картинка вписывается фоном. */
  .overlay__cover { width: 100%; height: 46%; max-width: 100%; aspect-ratio: auto; }
  .overlay__kicker { font-size: 11px; }
  .overlay__lead { font-size: 13px; }
  .overlay__note { display: none; }
}
