:root {
  --bg: #0f1115;
  --panel: #1c2028;
  --panel2: #262b35;
  --text: #f2f3f5;
  --muted: #9aa0aa;
  --green: #16a34a;
  --red: #dc2626;
  --blue: #2563eb;
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
button {
  font: inherit;
  color: inherit;
  border: 0;
  border-radius: 12px;
  background: var(--panel2);
  padding: 10px 14px;
  cursor: pointer;
}
button:disabled { opacity: .5; cursor: default; }
.hidden { display: none !important; }
.empty {
  max-width: 520px;
  margin: 18vh auto 0;
  padding: 0 16px;
  text-align: center;
  color: var(--muted);
  font-size: 18px;
  line-height: 1.6;
}

/* ---------- Камера (iPhone) ---------- */
.cam-wrap {
  max-width: 520px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.cam-preview {
  position: relative;
  background: #000;
  border-radius: 18px;
  overflow: hidden;
  aspect-ratio: 3 / 4;
  max-height: 52vh;
  width: 100%;
}
.cam-preview video { width: 100%; height: 100%; object-fit: cover; display: block; }
.cam-preview video.mirror { transform: scaleX(-1); }
.cam-off {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted);
}
.live-badge {
  position: absolute; top: 12px; left: 12px;
  background: var(--red); color: #fff;
  font-weight: 700; font-size: 14px;
  padding: 4px 10px; border-radius: 8px;
}
.rec-badge {
  position: absolute; top: 12px; right: 12px;
  background: rgba(0, 0, 0, .65); color: #f87171;
  font-weight: 700; font-size: 15px; font-variant-numeric: tabular-nums;
  padding: 4px 10px; border-radius: 8px;
  animation: blink 1.4s infinite;
}
@keyframes blink { 50% { opacity: .55; } }
.big-btn.rec { background: var(--panel2); font-size: 20px; padding: 16px; }
.big-btn.rec.on { background: #7f1d1d; }
.recs { margin-top: 10px; border-top: 1px solid var(--panel2); padding-top: 10px; }
.recs h2 { font-size: 18px; margin: 0 0 6px; }
.recs .hint { text-align: left; margin-bottom: 6px; }
.rec-item { background: var(--panel); border-radius: 12px; padding: 12px; margin-bottom: 10px; }
.rec-title { font-weight: 600; }
.rec-info { color: var(--muted); font-size: 14px; margin: 4px 0 8px; }
.rec-item .row { justify-content: flex-start; }
.rec-item .row button { flex: 1; }
.cam-name {
  font: inherit; font-size: 17px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--panel2);
  border-radius: 12px;
  padding: 12px 14px;
  width: 100%;
}
.big-btn {
  font-size: 24px; font-weight: 700;
  padding: 22px; border-radius: 18px;
  color: #fff; width: 100%;
}
.big-btn.start { background: var(--green); }
.big-btn.stop { background: var(--red); }
.cam-extra { display: flex; gap: 10px; }
.cam-extra button { flex: 1; padding: 14px; }
.status { margin: 0; text-align: center; font-size: 17px; }
.status.live { color: #4ade80; font-weight: 600; }
.status.error { color: #f87171; }
.hint { margin: 0; text-align: center; color: var(--muted); font-size: 14px; line-height: 1.4; }

/* ---------- Режиссёр (ноутбук) ---------- */
.top {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 16px;
  background: var(--panel);
  position: sticky; top: 0; z-index: 5;
}
.logo { font-size: 18px; }
.conn { color: var(--muted); font-size: 14px; flex: 1; }
.conn.ok { color: #4ade80; }
.conn.bad { color: #f87171; }
button.primary { background: var(--blue); color: #fff; }
/* Камеры занимают весь экран под шапкой, без прокрутки */
body.view { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
.top-hint { color: var(--muted); font-size: 13px; }
.grid {
  flex: 1;
  min-height: 0;
  display: grid;
  gap: 8px;
  padding: 8px;
}
.tile {
  position: relative;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  min-width: 0;
  min-height: 0;
  border: 2px solid transparent;
}
.tile.sound { border-color: #4ade80; }
.tile.main { border-color: var(--blue); }
.tile video { cursor: pointer; }
.tile-rec { pointer-events: none; }
.tile video { width: 100%; height: 100%; object-fit: contain; display: block; }
.tile .overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); background: rgba(0, 0, 0, .55);
  pointer-events: none;
}
.tile-rec {
  position: absolute; top: 10px; left: 10px;
  background: rgba(0, 0, 0, .65); color: #f87171;
  font-weight: 700; font-size: 14px; font-variant-numeric: tabular-nums;
  padding: 3px 9px; border-radius: 8px;
}
.tile .stats {
  position: absolute; top: 10px; right: 10px; max-width: 70%;
  background: rgba(0, 0, 0, .55); color: #d1d5db;
  font-size: 12px; font-variant-numeric: tabular-nums;
  padding: 3px 8px; border-radius: 6px;
  pointer-events: none;
}
.tile .stats:empty { display: none; }
button.rec-all { background: var(--panel2); }
button.rec-all.on { background: #7f1d1d; color: #fff; }
.tile .bar {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px;
  background: linear-gradient(transparent, rgba(0, 0, 0, .75));
}
.tile .name { flex: 1; font-weight: 600; text-shadow: 0 1px 2px #000; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .bar button { padding: 6px 10px; background: rgba(255, 255, 255, .15); }
.tile .vol { width: 90px; }
.tile:fullscreen { border: 0; border-radius: 0; max-height: none; }
.tile:-webkit-full-screen { border: 0; border-radius: 0; max-height: none; }

.modal {
  position: fixed; inset: 0; z-index: 10;
  background: rgba(0, 0, 0, .6);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.modal-box {
  background: var(--panel);
  border-radius: 18px;
  padding: 20px;
  max-width: 380px; width: 100%;
  text-align: center;
}
.modal-box h2 { margin: 0 0 12px; font-size: 20px; }
.modal-box p { color: var(--muted); font-size: 14px; line-height: 1.5; }
.qr { background: #fff; border-radius: 12px; padding: 10px; width: 240px; margin: 0 auto; }
.qr svg { display: block; width: 100%; height: auto; }
.row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

@media (max-width: 900px) { .top-hint { display: none; } }
/* На телефоне — камеры друг под другом, с прокруткой */
@media (max-width: 600px) {
  body.view { height: auto; overflow: auto; }
  .grid { display: flex; flex-direction: column; }
  .tile { aspect-ratio: 16 / 9; }
  .top { flex-wrap: wrap; }
}
