:root {
  --bg: #0e141b;
  --panel: #151e28;
  --raise: #1d2835;
  --line: #2a3a4b;
  --text: #e8edf2;
  --muted: #8fa1b3;
  --accent: #f2b24c;
  --accent-ink: #2a1c03;
  --speak: #57d38c;
  --danger: #ef6b6b;
  --font: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 var(--font); }
[hidden] { display: none !important; }
.screen { height: 100%; }

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- вход ---------- */
#join { display: grid; place-items: center; padding: 24px; overflow: auto; }
.join-form { width: min(360px, 100%); display: grid; gap: 14px; }
.join-form h1 { margin: 0; font-size: 44px; line-height: 1; letter-spacing: -0.02em; }
.lead { margin: 0 0 6px; color: var(--muted); }
.logo { width: 72px; height: 48px; }
.logo.small { width: 36px; height: 24px; }

label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
input[type="text"], input:not([type]), input[type="password"], select {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 15px;
}
input::placeholder { color: #5d6f81; }

.primary {
  background: var(--accent);
  color: var(--accent-ink);
  border: 0;
  border-radius: 8px;
  padding: 11px 16px;
  font-weight: 600;
}
.primary:hover { filter: brightness(1.06); }
.primary:disabled { opacity: .5; cursor: default; }
.ghost {
  background: rgba(21, 30, 40, .85);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
}
.ghost:hover { background: var(--raise); }
.error { margin: 0; min-height: 1.4em; color: var(--danger); font-size: 14px; }

/* ---------- звонок ---------- */
#call { display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; }
.top {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; border-bottom: 1px solid var(--line);
}
.status {
  margin-left: auto; font-size: 13px; color: var(--muted);
  display: inline-flex; align-items: center; gap: 8px;
}
.status::before {
  content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted);
}
.status[data-state="ok"] { color: var(--speak); }
.status[data-state="ok"]::before { background: var(--speak); }
.status[data-state="connecting"]::before { background: var(--accent); }
.status[data-state="lost"] { color: var(--danger); }
.status[data-state="lost"]::before { background: var(--danger); }

.main { display: grid; grid-template-columns: minmax(0, 1fr) 320px; min-height: 0; }

#stage { display: flex; flex-direction: column; gap: 12px; padding: 16px; min-width: 0; min-height: 0; }
.people { flex: 1; display: flex; align-items: center; justify-content: center; gap: 56px; }
.tile { display: grid; justify-items: center; gap: 12px; }
.avatar {
  width: 128px; height: 128px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--raise); border: 2px solid var(--line);
  font-size: 48px; font-weight: 600;
  transition: border-color .12s, box-shadow .12s;
}
.tile.speaking .avatar { border-color: var(--speak); box-shadow: 0 0 0 5px rgba(87, 211, 140, .25); }
.tile.empty .avatar { background: transparent; border-style: dashed; color: var(--muted); }
.tname { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 8px; font-weight: 600; }
.flags { display: inline-flex; gap: 6px; }
.flag {
  font-size: 12px; font-weight: 500; color: var(--muted);
  border: 1px solid var(--line); border-radius: 999px; padding: 1px 8px;
}
.flag.live { color: var(--accent); border-color: var(--accent); }

/* когда идёт демка: люди сжимаются в строку, экран занимает сцену */
#stage.has-screen .people { flex: 0 0 auto; justify-content: flex-start; gap: 24px; }
#stage.has-screen .tile { grid-auto-flow: column; align-items: center; gap: 10px; }
#stage.has-screen .avatar { width: 40px; height: 40px; font-size: 18px; border-width: 2px; }
#stage.has-screen .tile.speaking .avatar { box-shadow: 0 0 0 3px rgba(87, 211, 140, .25); }

#screenWrap { position: relative; flex: 1; min-height: 0; background: #000; border-radius: 10px; overflow: hidden; }
#remoteVideo { width: 100%; height: 100%; object-fit: contain; display: block; }
#btnFull { position: absolute; right: 12px; bottom: 12px; opacity: 0; transition: opacity .15s; }
#screenWrap:hover #btnFull, #btnFull:focus-visible { opacity: 1; }

.local-share {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  font-size: 14px;
}
.local-share video { width: 96px; height: 54px; border-radius: 6px; background: #000; object-fit: contain; }
.local-share .ghost { margin-left: auto; }

/* ---------- чат ---------- */
.chat { display: flex; flex-direction: column; min-height: 0; background: var(--panel); border-left: 1px solid var(--line); }
.messages { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 92%; align-self: flex-start; }
.msg.mine { align-self: flex-end; }
.msg .meta { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.msg.mine .meta { text-align: right; }
.msg .text {
  background: var(--raise); border-radius: 10px; padding: 7px 11px;
  overflow-wrap: anywhere; white-space: pre-wrap;
}
.msg.mine .text { background: #3a2f17; }
.msg .text a { color: var(--accent); }
.sys { align-self: center; color: var(--muted); font-size: 13px; text-align: center; }
.chat-form { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); }
.chat-form input { flex: 1; min-width: 0; }

/* ---------- нижняя панель ---------- */
.bar { display: flex; justify-content: center; flex-wrap: wrap; gap: 10px; padding: 12px; border-top: 1px solid var(--line); }
.ctl {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--raise); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 16px; font-size: 14px;
}
.ctl:hover:not(:disabled) { border-color: #3d5268; }
.ctl:disabled { opacity: .4; cursor: default; }
.ctl svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ctl .slash { display: none; }
.ctl.off { color: var(--danger); border-color: rgba(239, 107, 107, .5); }
.ctl.off .slash { display: block; }
.ctl.live { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.ctl.danger:hover { background: rgba(239, 107, 107, .15); border-color: var(--danger); color: var(--danger); }

/* ---------- диалоги ---------- */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 14px; padding: 0; }
dialog::backdrop { background: rgba(5, 8, 12, .65); }
.dlg { display: grid; gap: 14px; padding: 22px; width: min(420px, 90vw); }
.dlg.wide { width: min(760px, 92vw); }
.dlg h2 { margin: 0; font-size: 20px; }
.check { display: flex; align-items: center; gap: 10px; color: var(--text); font-size: 14px; }
.hint { margin: -6px 0 0; color: var(--muted); font-size: 13px; }

.sources { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; max-height: 60vh; overflow-y: auto; }
.source { background: var(--raise); border: 1px solid var(--line); border-radius: 10px; padding: 8px; text-align: left; display: grid; gap: 6px; }
.source:hover { border-color: var(--accent); }
.source img { width: 100%; aspect-ratio: 16 / 9; object-fit: contain; background: #000; border-radius: 6px; }
.source span { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

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

@media (max-width: 860px) {
  .main { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) 240px; }
  .chat { border-left: 0; border-top: 1px solid var(--line); }
  .avatar { width: 96px; height: 96px; font-size: 36px; }
  .people { gap: 28px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

.diag { padding: 4px 16px; font: 12px/1.4 ui-monospace, Consolas, monospace; color: var(--muted); border-bottom: 1px solid var(--line); overflow-wrap: anywhere; user-select: text; }
