:root {
  --bg: #121418;
  --panel: #1a1d23;
  --panel-2: #22262e;
  --line: #2e333c;
  --text: #ecebe7;
  --muted: #9a9ea6;
  --accent: #ff7a1a;
  --accent-2: #e3b25a;
  --danger: #e5484d;
  --ok: #46a758;
  --radius: 14px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.4; }
h1, h2 { margin: 0; }
button, input { font: inherit; color: inherit; }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; letter-spacing: .02em; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 12px var(--accent); flex: none; }

.btn {
  border: 1px solid var(--line); background: var(--panel-2); border-radius: 10px;
  padding: 10px 16px; cursor: pointer; transition: background .15s, border-color .15s, transform .1s;
}
.btn:hover { border-color: #444a55; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #1a1209; font-weight: 600; }
.btn.primary:hover { background: #ff8c3a; }
.btn.danger { background: transparent; border-color: var(--danger); color: #ff9a9d; }
.btn.off { background: #3a1d1f; border-color: var(--danger); color: #ffb3b5; }
.btn.wide { width: 100%; padding: 13px; }

/* Вход */
.join { min-height: 100%; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(900px 500px at 80% -10%, rgba(255,122,26,.16), transparent 60%),
              radial-gradient(700px 400px at 0% 110%, rgba(227,178,90,.10), transparent 60%), var(--bg); }
.card { width: 100%; max-width: 420px; background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 28px; }
.card h1 { font-size: 30px; margin: 18px 0 8px; }
.lead { color: var(--muted); margin: 0 0 20px; }
form label { display: block; margin-bottom: 14px; color: var(--muted); font-size: 13px; }
form input:not([type=checkbox]) {
  display: block; width: 100%; margin-top: 6px; padding: 11px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); font-size: 16px;
}
form input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
.hint { color: #6d727b; }
.check { display: flex !important; align-items: center; gap: 10px; color: var(--text) !important; font-size: 15px !important; margin: 4px 0 18px !important; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.err { color: #ff9a9d; min-height: 1.4em; margin: 10px 0 0; font-size: 14px; }
.small { color: #6d727b; font-size: 12.5px; margin: 14px 0 0; }

/* Комната */
.room {
  height: 100dvh; display: grid;
  grid-template-columns: 1fr 340px;
  grid-template-rows: auto 1fr auto;
  grid-template-areas: "bar bar" "stage side" "controls side";
}
.bar { grid-area: bar; display: flex; justify-content: space-between; align-items: center; padding: 12px 18px; border-bottom: 1px solid var(--line); background: var(--panel); }
.count { color: var(--muted); font-size: 14px; }
.stage { grid-area: stage; padding: 14px; min-height: 0; display: flex; flex-direction: column; gap: 10px; }
.notice { margin: 0; padding: 10px 14px; border-radius: 10px; background: rgba(227,178,90,.12); border: 1px solid rgba(227,178,90,.35); color: var(--accent-2); font-size: 14px; }
.grid { flex: 1; min-height: 0; display: grid; gap: 10px; grid-template-columns: 1fr; align-content: center; justify-items: center; }
.grid .tile { width: 100%; aspect-ratio: 16 / 9; }
.grid[data-n="1"] .tile { max-width: calc((100dvh - 170px) * 16 / 9); }
.grid[data-n="3"] .tile, .grid[data-n="4"] .tile { max-width: calc((100dvh - 180px) / 2 * 16 / 9); }
.grid[data-n="2"] { grid-template-columns: 1fr 1fr; }
.grid[data-n="3"], .grid[data-n="4"] { grid-template-columns: 1fr 1fr; }
.grid[data-n="0"]::before { content: "Пока никого с камерой. Видео появится, когда кто-то включит камеру."; color: var(--muted); align-self: center; justify-self: center; text-align: center; padding: 20px; }

.tile { position: relative; background: #0b0c0f; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; min-height: 0; }
.tile video { width: 100%; height: 100%; object-fit: cover; display: block; background: #0b0c0f; }
.tile.me video { transform: scaleX(-1); }
.tile .avatar { position: absolute; inset: 0; display: none; place-items: center; }
.tile .avatar span { width: 84px; height: 84px; border-radius: 50%; display: grid; place-items: center; font-size: 34px; font-weight: 700; background: var(--panel-2); color: var(--accent-2); border: 1px solid var(--line); }
.tile.novideo .avatar { display: grid; }
.tile.novideo video { visibility: hidden; }
.tile .label { position: absolute; left: 10px; bottom: 10px; display: flex; gap: 6px; align-items: center; padding: 5px 10px; border-radius: 8px; background: rgba(10,11,14,.72); font-size: 13.5px; backdrop-filter: blur(6px); }
.tile .micoff { color: #ff9a9d; display: none; }
.tile.muted .micoff { display: inline; }
.tile .status { position: absolute; top: 10px; left: 10px; right: 10px; font-size: 12.5px; color: var(--accent-2); text-shadow: 0 1px 2px #000; }

.controls { grid-area: controls; display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; padding: 12px 14px 16px; }

.side { grid-area: side; border-left: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.side h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 8px; }
.people { padding: 14px 16px; border-bottom: 1px solid var(--line); max-height: 40%; overflow: auto; }
.people ul { list-style: none; margin: 0; padding: 0; }
.people li { display: flex; align-items: center; gap: 8px; padding: 6px 0; font-size: 14px; }
.people .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { font-size: 11px; padding: 2px 7px; border-radius: 6px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.tag.host { color: var(--accent-2); border-color: rgba(227,178,90,.45); }
.tag.cam { color: #8fd19e; border-color: rgba(70,167,88,.45); }
.kick { border: 0; background: none; color: #ff9a9d; cursor: pointer; font-size: 12px; padding: 2px 4px; }

.chat { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 14px 16px; }
.msgs { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; padding-right: 4px; }
.msg { background: var(--panel-2); border-radius: 10px; padding: 7px 10px; font-size: 14px; overflow-wrap: anywhere; }
.msg b { color: var(--accent-2); font-weight: 600; margin-right: 6px; }
.msg.mine b { color: var(--accent); }
.msg time { color: #6d727b; font-size: 11px; margin-left: 6px; }
.sys { color: #6d727b; font-size: 12.5px; text-align: center; }
.chatform { display: flex; gap: 8px; margin-top: 10px; }
.chatform input { flex: 1; min-width: 0; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); font-size: 16px; }
.chatform input:focus { outline: 2px solid var(--accent); border-color: transparent; }

@media (max-width: 860px) {
  .room {
    height: auto; min-height: 100dvh;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto auto;
    grid-template-areas: "bar" "stage" "controls" "side";
  }
  .stage { padding: 10px; }
  .grid .tile { max-width: none !important; }
  .grid[data-n="2"], .grid[data-n="3"], .grid[data-n="4"] { grid-template-columns: 1fr 1fr; }
  .grid[data-n="2"] .tile, .grid[data-n="3"] .tile, .grid[data-n="4"] .tile { aspect-ratio: 3 / 4; }
  .grid[data-n="0"] { min-height: 120px; }
  .controls { padding: 4px 10px 12px; }
  .controls .btn { flex: 1 1 40%; }
  .side { border-left: 0; border-top: 1px solid var(--line); }
  .people { max-height: none; }
  .chat { min-height: 320px; max-height: 60vh; }
}
