/* Тёмная тема сразу и единственная: смотрим кино в темноте.
   Одна резиновая вёрстка на grid — мобильная раскладка не отдельное приложение,
   а другое расположение тех же блоков. */

:root {
  --bg: #0d0d10;
  --panel: #16161c;
  --panel-2: #1e1e26;
  --line: #2a2a34;
  --text: #e9e9ef;
  --muted: #8b8b9a;
  --accent: #e0567a;
  --accent-dim: #7a2e42;
  --ok: #4ec98a;
  --warn: #e0b055;
  --tap: 44px;          /* минимальная зона под палец */
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;
  overscroll-behavior: none;
}
button, input, select { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.spacer { flex: 1; }
[hidden] { display: none !important; }

.screen { min-height: 100dvh; }

/* ─── кнопки ─── */
.btn {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 10px;
  padding: 0 14px;
  min-height: var(--tap);
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .08s;
}
.btn:hover { background: #262633; }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: #ea6486; }
.btn.ghost { background: transparent; }
.btn.small { min-height: 34px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.btn.icon { min-width: var(--tap); padding: 0 10px; }
.btn.select { padding: 0 8px; background: var(--panel-2); }

/* ─── вход ─── */
.gate { display: grid; place-items: center; padding: 24px; }
.gate-card { text-align: center; max-width: 320px; width: 100%; }
.gate-logo { font-size: 56px; color: var(--accent); line-height: 1; }
.gate h1 { margin: 12px 0 2px; font-size: 26px; font-weight: 600; letter-spacing: .5px; }
.gate p { margin: 0 0 28px; }
#pin-form { display: grid; gap: 10px; }
#pin {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  min-height: var(--tap); padding: 0 14px; text-align: center;
  font-size: 22px; letter-spacing: 8px;
}
#pin:focus { outline: none; border-color: var(--accent); }
.error { color: var(--accent); font-size: 14px; margin-top: 12px; }

/* ─── библиотека ─── */
.library { padding: 24px; max-width: 1100px; margin: 0 auto; }
.lib-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.lib-head h2 { margin: 0; font-size: 20px; font-weight: 600; }
.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 16px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; cursor: pointer; text-align: left; padding: 0; display: grid;
}
.card:hover { border-color: var(--accent-dim); }
.card-art { aspect-ratio: 16/9; background: #000 center/cover no-repeat; display: grid; place-items: center; color: var(--muted); font-size: 28px; }
.card-body { padding: 10px 12px 12px; }
.card-title { font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.card-meta { font-size: 12px; color: var(--muted); }
.card-progress { height: 3px; background: var(--line); margin-top: 8px; border-radius: 2px; overflow: hidden; }
.card-progress i { display: block; height: 100%; background: var(--accent); }
.empty { text-align: center; padding: 40px 0; }
code { background: var(--panel-2); padding: 2px 6px; border-radius: 6px; font-size: 13px; }

/* ─── зал ─── */
.room {
  display: grid;
  grid-template-columns: 1fr 320px;
  grid-template-areas: "stage side";
  height: 100dvh;
}
.stage { grid-area: stage; display: grid; grid-template-rows: 1fr auto; min-width: 0; min-height: 0; background: #000; }
.side {
  grid-area: side; background: var(--panel); border-left: 1px solid var(--line);
  display: grid; grid-template-rows: auto 1fr auto; min-height: 0;
}

.video-wrap { position: relative; min-height: 0; display: grid; }
video { width: 100%; height: 100%; object-fit: contain; background: #000; display: block; }

/* контролы */
.controls {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgba(0,0,0,.85));
  opacity: 0; transition: opacity .2s; pointer-events: none;
}
.video-wrap:hover .controls, .controls.show { opacity: 1; pointer-events: auto; }

.timeline { position: relative; height: 22px; display: flex; align-items: center; cursor: pointer; touch-action: none; }
.timeline::before { content: ''; position: absolute; left: 0; right: 0; height: 4px; background: rgba(255,255,255,.2); border-radius: 2px; }
.tl-buffer, .tl-played { position: absolute; left: 0; height: 4px; border-radius: 2px; }
.tl-buffer { background: rgba(255,255,255,.3); }
.tl-played { background: var(--accent); }
.tl-knob { position: absolute; width: 13px; height: 13px; border-radius: 50%; background: #fff; transform: translateX(-50%); pointer-events: none; }

.ctl-row { display: flex; align-items: center; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.ctl-row .btn { background: rgba(255,255,255,.1); border-color: transparent; backdrop-filter: blur(6px); }
.time { font-variant-numeric: tabular-nums; font-size: 13px; color: #ddd; white-space: nowrap; }
.vol { display: flex; align-items: center; gap: 6px; }
.vol input { width: 90px; accent-color: var(--accent); }

.big-play {
  position: absolute; inset: 0; margin: auto; width: 88px; height: 88px; border-radius: 50%;
  background: rgba(224,86,122,.9); border: none; color: #fff; font-size: 34px; cursor: pointer;
}

.overlay { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,.7); backdrop-filter: blur(3px); }
.overlay-box { text-align: center; }
.countdown { font-size: 64px; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }

.reactions { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.reactions span { position: absolute; font-size: 42px; animation: floatUp 2.4s ease-out forwards; }
@keyframes floatUp {
  0%   { transform: translateY(0) scale(.5); opacity: 0; }
  15%  { transform: translateY(-20px) scale(1.15); opacity: 1; }
  100% { transform: translateY(-260px) scale(1); opacity: 0; }
}

.react-bar { display: flex; gap: 8px; padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); background: var(--bg); }
.btn.react { font-size: 20px; min-width: var(--tap); padding: 0; }

/* панель */
.side-head { display: flex; gap: 6px; padding: 10px; border-bottom: 1px solid var(--line); align-items: center; }
.tab { background: transparent; border: none; color: var(--muted); cursor: pointer; padding: 8px 10px; border-radius: 8px; min-height: 36px; }
.tab.active { color: var(--text); background: var(--panel-2); }
.tab-panel { min-height: 0; overflow: auto; padding: 12px; display: grid; align-content: start; gap: 10px; }
.tab-panel[data-panel="chat"] { grid-template-rows: 1fr auto; padding: 0; }

.chat-log { overflow: auto; padding: 12px; display: grid; align-content: start; gap: 8px; }
.msg { max-width: 90%; padding: 7px 11px; border-radius: 12px; background: var(--panel-2); font-size: 14px; word-break: break-word; }
.msg.mine { justify-self: end; background: var(--accent-dim); }
.msg .who { display: block; font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.msg.system { justify-self: center; background: transparent; color: var(--muted); font-size: 12px; }
.chat-form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }
.chat-form input { flex: 1; min-width: 0; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 0 12px; min-height: 40px; }
.chat-form input:focus { outline: none; border-color: var(--accent-dim); }

.stat { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 14px; }
.stat span { color: var(--muted); }
.stat.slider { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; }
.stat.slider input { grid-column: 1 / -1; accent-color: var(--accent); }
.hint { font-size: 12px; color: var(--muted); margin: 0; }

.voice-bar { border-top: 1px solid var(--line); padding: 10px; display: grid; gap: 8px; }
.btn.mic { width: 100%; }
.btn.mic.live { background: var(--ok); border-color: var(--ok); color: #04120a; font-weight: 600; }
.btn.mic.muted { background: var(--panel-2); }
.level { height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; }
#level-fill { height: 100%; width: 0; background: var(--ok); transition: width .08s; }
.ptt-toggle { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
kbd { background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; font-size: 11px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 16px; font-size: 14px; z-index: 50; max-width: 90vw;
}

/* ─── телефон ───
   Те же блоки, другая раскладка: видео сверху, панель снизу.
   Отлаживаем на ноутбуках, но путь сюда не закрываем. */
@media (max-width: 860px) {
  .room {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    grid-template-areas: "stage" "side";
  }
  .side { border-left: none; border-top: 1px solid var(--line); }
  .stage { grid-template-rows: auto auto; }
  .video-wrap { aspect-ratio: 16/9; height: auto; }
  .controls { opacity: 1; pointer-events: auto; }  /* на тач-экране нет наведения */
  .vol { display: none; }                          /* на iOS громкость всё равно за кнопками */
  .library { padding: 16px; }
  .lib-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
}

@media (max-width: 860px) and (orientation: landscape) {
  .room { grid-template-columns: 1fr 280px; grid-template-rows: 1fr; grid-template-areas: "stage side"; }
  .video-wrap { aspect-ratio: auto; height: auto; }
  .react-bar { display: none; }
}

/* ─── админка ─── */
.admin { padding: 24px; max-width: 1100px; margin: 0 auto; }
.admin-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; align-items: start; }
.card-block {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; display: grid; gap: 10px; align-content: start;
}
.card-block h3 { margin: 0; font-size: 15px; font-weight: 600; }
.card-block h4 { margin: 8px 0 0; font-size: 13px; font-weight: 600; color: var(--muted); }
.row { display: flex; gap: 8px; align-items: center; }
.row input[type="text"], .row input:not([type]), .row input[type="password"] {
  flex: 1; min-width: 0; background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 8px; min-height: 38px; padding: 0 10px;
}
.row label, label.row { cursor: pointer; }
.small { font-size: 13px; }

.bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }

.convert { background: var(--panel-2); border-radius: 8px; padding: 10px; font-size: 13px; display: grid; gap: 6px; }

.invite-result { display: grid; gap: 6px; background: var(--panel-2); padding: 10px; border-radius: 8px; }
.invite-result input { font-size: 12px; }

.person, .film-row {
  display: flex; align-items: center; gap: 8px; padding: 8px 0;
  border-bottom: 1px solid var(--line); font-size: 14px;
}
.person:last-child, .film-row:last-child { border-bottom: none; }
.person .who { flex: 1; min-width: 0; }
.person .who i { display: block; font-size: 12px; color: var(--muted); font-style: normal; }
.badge { font-size: 11px; padding: 2px 7px; border-radius: 20px; background: var(--panel-2); color: var(--muted); }
.badge.on { background: rgba(78,201,138,.15); color: var(--ok); }
.badge.off { background: rgba(224,86,122,.15); color: var(--accent); }
.film-row .name { flex: 1; min-width: 0; }
.film-row .name i { display: block; font-size: 12px; color: var(--muted); font-style: normal; }
.btn.danger { background: transparent; border-color: var(--accent-dim); color: var(--accent); }
.btn.danger:hover { background: rgba(224,86,122,.12); }

#setup-form, #invite-form { display: grid; gap: 10px; }
#setup-form input, #invite-form input {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  min-height: var(--tap); padding: 0 14px; text-align: center; font-size: 16px;
}
#setup-pin { letter-spacing: 4px; }
#setup-form input:focus, #invite-form input:focus, #pin:focus { outline: none; border-color: var(--accent); }
.gate .hint { margin-top: 16px; font-size: 12px; color: var(--muted); }

@media (max-width: 860px) {
  .admin { padding: 16px; }
  .admin-grid { grid-template-columns: 1fr; }
}

.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn:disabled:hover { background: var(--panel-2); }
.btn.primary:disabled:hover { background: var(--accent); }
.badge:empty { display: none; }

/* ─── трансляция экрана ─── */
#screen { width: 100%; height: 100%; object-fit: contain; background: #000; display: block; }
.screen-badge {
  position: absolute; top: 12px; left: 12px; z-index: 3;
  background: rgba(0,0,0,.65); backdrop-filter: blur(6px);
  border: 1px solid var(--line); border-radius: 20px;
  padding: 6px 12px; font-size: 13px; display: flex; align-items: center; gap: 7px;
}
.screen-badge::before {
  content: ''; width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent); animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .3 } }
.btn.icon.sharing { background: var(--accent); border-color: var(--accent); color: #fff; }
