:root {
  --bg: #000; --card: #0e0e10; --line: #222226; --text: #fff; --muted: #9a9aa3;
  --accent: #fff; --accent-text: #000; --red: #ff3b4d; --green: #3ddc84;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }

.screen { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 16px; }
.card { width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: 14px; text-align: center; }
.logo { width: 72px; height: 72px; align-self: center; }
h1 { margin: 0; font-weight: 300; font-size: 40px; letter-spacing: -1px; }
h2 { margin: 0; font-weight: 500; font-size: 20px; }
.muted { color: var(--muted); margin: 0; }
.mono { font-family: ui-monospace, monospace; color: var(--muted); font-size: 16px; }
.err { color: var(--red); min-height: 1.4em; margin: 0; }

.field { display: flex; flex-direction: column; gap: 6px; text-align: left; color: var(--muted); font-size: 14px; }
input { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 13px 14px; min-width: 0; outline: none; }
input:focus { border-color: #555; }
.row { display: flex; gap: 8px; }
.row input { flex: 1; }

.btn { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 13px 18px; cursor: pointer; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
.btn:active, .ctl:active, .chip:active { transform: scale(.97); }
button:disabled { opacity: .5; cursor: default; }
#downloads { display: grid; gap: 10px; margin-top: 6px; padding-top: 16px; border-top: 1px solid var(--line);
  text-align: left; scroll-margin-top: 16px; }
.download-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.download-btn { display: grid; align-content: center; gap: 3px; padding: 9px 12px; color: var(--text); text-decoration: none; }
.download-btn strong { font-size: 15px; font-weight: 600; }
.download-btn small, .download-note { font-size: 12px; color: var(--muted); }
.download-btn:hover { border-color: var(--muted); }
#downloads a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.download-note a { color: var(--text); text-underline-offset: .18em; }
.toggles { justify-content: center; }
.chip { border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 9px 14px; cursor: pointer; opacity: .5; }
.chip.on { opacity: 1; border-color: #555; }

.preview { position: relative; aspect-ratio: 4/3; background: var(--card); border-radius: 22px; overflow: hidden; border: 1px solid var(--line); }
#lobby .preview { max-height: 34vh; }
.preview video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.preview .avatar { position: absolute; inset: 0; margin: auto; }

.avatar { width: 84px; height: 84px; border-radius: 50%; background: #1b1b20; display: flex; align-items: center; justify-content: center;
  font-size: 34px; font-weight: 500; }
.avatar.big { width: 110px; height: 110px; font-size: 44px; }

/* Звонок */
.call { padding: 0; display: block; height: 100dvh; position: relative; overflow: hidden; }
.grid { position: absolute; inset: 0; bottom: 92px; display: grid; gap: 8px; padding: 8px; }
.grid[data-n="1"] { grid-template-columns: 1fr; }
.grid[data-n="2"], .grid[data-n="3"], .grid[data-n="4"] { grid-template-columns: 1fr 1fr; }
@media (orientation: portrait) {
  .grid[data-n="2"] { grid-template-columns: 1fr; }
}
.tile { position: relative; background: var(--card); border-radius: 20px; overflow: hidden; min-height: 0; display: flex; align-items: center; justify-content: center; }
.tile video { width: 100%; height: 100%; object-fit: cover; position: absolute; inset: 0; }
.tile.off video { visibility: hidden; }
.tile .avatar { position: relative; z-index: 1; }
.tile:not(.off) .avatar { display: none; }
.tile .label { position: absolute; left: 10px; bottom: 10px; z-index: 2; background: rgba(0,0,0,.55); padding: 4px 10px;
  border-radius: 999px; font-size: 14px; max-width: calc(100% - 20px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .status { position: absolute; inset: auto 0 44px; text-align: center; z-index: 2; color: var(--muted); font-size: 14px; }

/* Своё видео — маленьким окошком в углу */
.tile.me { position: absolute; right: 14px; bottom: 106px; width: 28vw; max-width: 200px; aspect-ratio: 3/4; z-index: 5;
  border: 1px solid #333; box-shadow: 0 6px 24px rgba(0,0,0,.6); }
.tile.me video { transform: scaleX(-1); }
.tile.me.back video { transform: none; }
.tile.me .avatar { width: 52px; height: 52px; font-size: 22px; }
.tile.me .label { font-size: 12px; bottom: 6px; left: 6px; }

.waiting { position: absolute; inset: 0; bottom: 92px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; color: var(--muted); }
.waiting p { margin: 0; }
#waitingStatus { max-width: 28rem; padding-inline: 1rem; text-align: center; }
#lobbyHint:empty { display: none; }
.private-overlay { position: absolute; inset: 0 0 92px; z-index: 6; display: grid; place-items: center;
  overflow: auto; padding: 16px; background: var(--bg); }
.private-overlay .card { margin: auto; padding: 20px; border: 1px solid var(--line);
  border-radius: 22px; background: var(--card); }
.private-code-block { display: grid; gap: 10px; }
.private-code { font: 700 clamp(16px, 4vw, 24px)/1.4 ui-monospace, monospace; letter-spacing: .02em; color: var(--green); }
.knock-list { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.knock-list:empty { display: none; }
.knock-list li { padding: 10px; border: 1px solid var(--line); border-radius: 14px; }
.knock-list li p { margin: 0 0 8px; }
.knock-list .row { justify-content: center; flex-wrap: wrap; }
.knock-list .btn { padding: 8px 12px; }
.private-verified { position: absolute; top: max(14px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  z-index: 5; margin: 0; padding: 7px 12px; border: 1px solid var(--line); border-radius: 999px;
  background: rgba(14, 14, 16, .9); color: var(--green); font-size: 13px; white-space: nowrap; }

.controls { position: absolute; left: 0; right: 0; bottom: 0; height: 92px; display: flex; justify-content: center; align-items: center; gap: 10px;
  padding: 0 12px env(safe-area-inset-bottom); background: linear-gradient(transparent, #000 30%); z-index: 6; }
.ctl { position: relative; width: 54px; height: 54px; border-radius: 50%; border: 1px solid var(--line); background: #17171b; font-size: 22px; cursor: pointer; flex-shrink: 0; }
.ctl.off { background: #fff; filter: grayscale(1); }
.ctl.off::after { content: ""; position: absolute; left: 50%; top: 12px; bottom: 12px; width: 2px; background: var(--red); transform: rotate(45deg); }
.ctl.red { background: var(--red); border-color: var(--red); transform: rotate(135deg); color: #fff; }
.badge { position: absolute; top: 2px; right: 2px; min-width: 18px; height: 18px; border-radius: 9px; background: var(--red); font-size: 11px;
  display: flex; align-items: center; justify-content: center; padding: 0 4px; color: #fff; }

.toast { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); background: #1b1b20; border: 1px solid var(--line);
  padding: 10px 16px; border-radius: 999px; z-index: 10; font-size: 14px; max-width: calc(100% - 32px); text-align: center; }

.chat { position: absolute; right: 0; top: 0; bottom: 92px; width: min(360px, 100%); background: #0a0a0c; border-left: 1px solid var(--line);
  z-index: 7; display: flex; flex-direction: column; }
.chat header { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.icon { background: none; border: 0; font-size: 18px; cursor: pointer; color: var(--muted); }
.chatlog { list-style: none; margin: 0; padding: 12px 16px; flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.chatlog li { background: #17171b; padding: 8px 12px; border-radius: 14px; align-self: flex-start; max-width: 85%; overflow-wrap: anywhere; }
.chatlog li.mine { background: #fff; color: #000; align-self: flex-end; }
.chatlog li.sys { background: none; color: var(--muted); font-size: 13px; align-self: center; }
.chatlog .who { display: block; font-size: 12px; color: var(--muted); }
.chat form { padding: 10px; border-top: 1px solid var(--line); }
