:root {
  --bg: #14161a;
  --panel: #1e2127;
  --panel2: #272b33;
  --line: #333844;
  --text: #eceef2;
  --muted: #9aa1ad;
  --accent: #3d8bfd;
  --accent2: #2f74db;
  --danger: #e5484d;
  --ok: #30a46c;
  --warn: #f5a524;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
a { color: var(--accent); }

/* кнопки и поля */
.btn {
  -webkit-appearance: none; appearance: none;
  border: 1px solid var(--line); background: var(--panel2); color: var(--text);
  border-radius: 10px; padding: 10px 16px; font: inherit; cursor: pointer;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: #313641; }
.btn:focus-visible, .ctl:focus-visible, .input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--accent2); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; }
.btn.big { padding: 14px 20px; font-size: 16px; width: 100%; }
.btn.small { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn[disabled] { opacity: .6; cursor: default; }
.input {
  width: 100%; padding: 12px 14px; font: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
}
.input.code { text-transform: uppercase; letter-spacing: 3px; font-weight: 600; text-align: center; font-size: 18px; }
.error { color: #ff8a8d; margin-top: 12px; }

/* главная */
.page { min-height: 100%; }
#home, #prejoin, #unsupported { display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.home-card {
  width: 100%; max-width: 400px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 28px 24px;
}
.logo { display: flex; align-items: center; gap: 10px; font-size: 26px; font-weight: 700; margin-bottom: 6px; }
.logo img { display: block; }
.home-card > p { margin: 0 0 22px; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); margin: 18px 0; font-size: 13px; }
.divider:before, .divider:after { content: ""; flex: 1; height: 1px; background: var(--line); }
.join-form { display: flex; gap: 8px; }
.join-form .btn { width: auto; flex: 0 0 auto; }
.recent { margin-top: 24px; border-top: 1px solid var(--line); padding-top: 14px; }
.recent-title { color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.recent ul { list-style: none; margin: 0; padding: 0; }
.recent li { display: flex; align-items: center; gap: 8px; padding: 6px 0; }
.recent li a { flex: 1; text-decoration: none; color: var(--text); font-weight: 600; letter-spacing: 2px; }
.recent li .when { color: var(--muted); font-size: 12px; }
.recent li button { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 16px; padding: 2px 6px; }
.back { font-size: 14px; text-decoration: none; color: var(--muted); }
.room-code-big { font-size: 30px; font-weight: 700; letter-spacing: 4px; margin: 14px 0 4px; }
.pre-form { margin-top: 18px; }
.field { display: block; margin-bottom: 14px; }
.field span { display: block; color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.check { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; cursor: pointer; }
.check input { width: 18px; height: 18px; }
.pre-form .btn { margin-top: 8px; }

/* комната */
.room { display: flex; flex-direction: column; height: 100%; height: 100vh; overflow: hidden; }
.topbar {
  flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.tb-left, .tb-right { display: flex; align-items: center; gap: 10px; }
.code-chip { font-weight: 700; letter-spacing: 2px; background: var(--panel2); padding: 4px 10px; border-radius: 8px; }
.net { font-size: 13px; }
.net.ok { color: var(--ok); } .net.warn { color: var(--warn); } .net.bad { color: var(--danger); }

.main { flex: 1 1 auto; display: flex; min-height: 0; }
.stage { flex: 1 1 auto; position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; }

/* без демонстрации: плитки на всю область */
.tiles { flex: 1 1 auto; display: flex; flex-wrap: wrap; align-content: center; justify-content: center; gap: 10px; padding: 10px; overflow: auto; }
.tile {
  position: relative; background: var(--panel); border: 2px solid transparent; border-radius: 12px; overflow: hidden;
  width: 320px; height: 200px; flex: 0 0 auto;
}
.tile video { width: 100%; height: 100%; object-fit: cover; display: block; background: #000; }
.tile.self video { -webkit-transform: scaleX(-1); transform: scaleX(-1); }
.tile .avatar {
  position: absolute; left: 50%; top: 50%; width: 64px; height: 64px; margin: -40px 0 0 -32px;
  border-radius: 50%; background: var(--panel2); display: flex; align-items: center; justify-content: center;
  font-size: 26px; font-weight: 700; color: var(--text);
}
.tile .label {
  position: absolute; left: 6px; right: 6px; bottom: 6px; display: flex; align-items: center; gap: 6px;
  font-size: 13px; background: rgba(0,0,0,.55); padding: 3px 8px; border-radius: 6px; white-space: nowrap; overflow: hidden;
}
.tile .label .nm { overflow: hidden; text-overflow: ellipsis; flex: 1 1 auto; }
.tile .label .q { color: var(--muted); font-size: 11px; flex: 0 0 auto; }
.tile .label .mic-off { color: var(--danger); }
.tile .hand { position: absolute; top: 6px; right: 8px; font-size: 22px; }
.tile.hand-up { border-color: var(--warn); }

/* с демонстрацией: экран большой, плитки полосой снизу */
.has-screen .tiles { flex: 0 0 auto; flex-wrap: nowrap; justify-content: flex-start; align-content: flex-start; padding: 6px 8px; overflow-x: auto; overflow-y: hidden; }
.has-screen .tile { width: 150px; height: 94px; }
.has-screen .tile .avatar { width: 40px; height: 40px; margin: -28px 0 0 -20px; font-size: 18px; }
.has-screen .tile .label { font-size: 11px; padding: 2px 6px; }
.screen-wrap { flex: 1 1 auto; position: relative; background: #000; min-height: 0; }
.screen-wrap video { position: absolute; left: 0; top: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
.screen-label { position: absolute; left: 10px; top: 10px; background: rgba(0,0,0,.6); padding: 3px 10px; border-radius: 6px; font-size: 13px; }
.fs-btn { position: absolute; right: 10px; top: 10px; background: rgba(0,0,0,.6); }
.screen-wrap:-webkit-full-screen .fs-btn { display: none; }
.screen-wrap:fullscreen .fs-btn { display: none; }

.self-share { flex: 1 1 auto; display: flex; align-items: center; justify-content: center; padding: 16px; min-height: 0; }
.self-share-box { text-align: center; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 22px; max-width: 100%; }
.self-share-box .row { display: flex; gap: 8px; justify-content: center; margin-top: 14px; flex-wrap: wrap; }
.self-share-box video { display: block; max-width: 100%; max-height: 40vh; margin-top: 14px; border-radius: 8px; background: #000; }
.pulse { width: 12px; height: 12px; border-radius: 50%; background: var(--danger); margin: 0 auto 10px; -webkit-animation: pulse 1.6s infinite; animation: pulse 1.6s infinite; }
@-webkit-keyframes pulse { 50% { opacity: .3; } }
@keyframes pulse { 50% { opacity: .3; } }

/* чат */
.chat { flex: 0 0 300px; display: flex; flex-direction: column; background: var(--panel); border-left: 1px solid var(--line); min-height: 0; }
.chat-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.chat-log { flex: 1 1 auto; overflow-y: auto; padding: 10px 12px; }
.msg { margin-bottom: 10px; word-wrap: break-word; overflow-wrap: anywhere; }
.msg .who { font-size: 12px; color: var(--muted); }
.msg.me .who { color: var(--accent); }
.msg .txt { white-space: pre-wrap; }
.msg.sys { color: var(--muted); font-size: 12px; font-style: italic; }
.chat-form { display: flex; gap: 6px; padding: 8px; border-top: 1px solid var(--line); }
.chat-form .btn { flex: 0 0 auto; }

/* панель управления */
.controls {
  flex: 0 0 auto; display: flex; justify-content: center; align-items: center; gap: 6px; flex-wrap: wrap;
  padding: 8px; background: var(--panel); border-top: 1px solid var(--line);
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
}
.ctl {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 72px;
  padding: 6px 10px; background: var(--panel2); border: 1px solid var(--line); color: var(--text);
  border-radius: 12px; font: inherit; cursor: pointer;
}
.ctl:hover { background: #313641; }
.ctl .ic { font-size: 20px; line-height: 24px; height: 24px; display: flex; align-items: center; }
.ctl .ic svg { width: 22px; height: 22px; display: block; }
.ctl .lbl { font-size: 12px; color: var(--muted); }
.ctl.off { background: #3a2124; border-color: #5a2b30; }
.ctl.off .ic { color: #ff8a8d; }
.ctl.on { background: #1d3557; border-color: var(--accent); }
.ctl.leave { background: var(--danger); border-color: var(--danger); }
.ctl.leave .lbl { color: #fff; }
.ctl-group { display: flex; align-items: center; gap: 4px; }
.quality { background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 6px; font: inherit; font-size: 12px; }
.badge { position: absolute; top: 2px; right: 8px; background: var(--danger); color: #fff; font-size: 11px; border-radius: 9px; padding: 0 5px; min-width: 16px; text-align: center; }

.toast { position: fixed; left: 50%; bottom: 96px; -webkit-transform: translateX(-50%); transform: translateX(-50%); background: #000; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 20; max-width: 90%; text-align: center; }
.overlay { position: fixed; left: 0; top: 0; right: 0; bottom: 0; background: rgba(0,0,0,.7); display: flex; align-items: center; justify-content: center; z-index: 30; padding: 16px; }
.overlay .btn { max-width: 360px; }

@media (max-width: 760px) {
  .chat { position: fixed; left: 0; right: 0; top: 0; bottom: 0; z-index: 15; flex: none; border: 0; }
  .tile { width: 46%; height: 140px; }
  .has-screen .tile { width: 110px; height: 72px; }
  .ctl { min-width: 54px; padding: 5px 6px; }
  .ctl .lbl { font-size: 11px; }
  #copyBtn { display: none; }
  .quality { max-width: 100px; }
}
