:root {
  --bg: #0f1115;
  --panel: #181b22;
  --tile: #20242d;
  --text: #e8eaed;
  --muted: #9aa0a6;
  --accent: #4f8cff;
  --danger: #e5484d;
  --radius: 12px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

button, input { font: inherit; color: inherit; }
input {
  background: var(--tile);
  border: 1px solid #333844;
  border-radius: 8px;
  padding: 10px 12px;
  outline: none;
}
input:focus { border-color: var(--accent); }
button { cursor: pointer; border: 0; }
a { color: var(--accent); }
.muted { color: var(--muted); }

.primary {
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  padding: 10px 22px;
  text-decoration: none;
  display: inline-block;
  font-weight: 600;
}
.primary:disabled { opacity: .5; cursor: default; }
.primary.big { padding: 14px 30px; font-size: 17px; }

/* ---------- главная ---------- */
.landing { display: grid; place-items: center; padding: 16px; }
.hero { max-width: 480px; text-align: center; }
.hero h1 { font-size: 40px; margin: 0 0 12px; }
.hero p { color: var(--muted); margin: 0 0 28px; }
.join-form { display: flex; gap: 8px; margin-top: 28px; }
.join-form input { flex: 1; min-width: 0; }
.join-form button { background: var(--tile); border-radius: 8px; padding: 0 16px; }

/* ---------- лобби ---------- */
.lobby {
  min-height: 100%;
  display: flex;
  align-items: center;
  align-content: center;
  justify-content: center;
  gap: 32px;
  padding: 16px;
  flex-wrap: wrap;
}
.preview { width: min(640px, 100%); aspect-ratio: 16 / 9; }
.lobby-side { display: flex; flex-direction: column; gap: 12px; width: min(320px, 100%); }
.lobby-side h2 { margin: 0; }
.lobby-side p { margin: 0; min-height: 1em; }
.row { display: flex; gap: 10px; align-items: center; }
.row .primary { flex: 1; padding: 12px; }

/* ---------- звонок ---------- */
.call { display: flex; height: 100vh; height: 100dvh; }
.stage { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.grid {
  flex: 1;
  min-height: 0;
  display: grid;
  gap: 8px;
  padding: 8px;
  grid-template-columns: repeat(var(--cols, 1), minmax(0, 1fr));
  grid-template-rows: repeat(var(--rows, 1), minmax(0, 1fr));
}

.tile {
  position: relative;
  background: var(--tile);
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 0;
}
.tile video { width: 100%; height: 100%; object-fit: cover; display: block; background: #000; }
.tile.fit video { object-fit: contain; }
.tile.mirror video { transform: scaleX(-1); }

.avatar {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: #3a4150;
  display: none;
  place-items: center;
  font-size: 40px;
  font-weight: 600;
}
.tile.nocam video { visibility: hidden; }
.tile.nocam .avatar { display: grid; }

.label {
  position: absolute;
  left: 8px;
  bottom: 8px;
  max-width: calc(100% - 16px);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(0, 0, 0, .55);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.label .mic-off { width: 14px; height: 14px; fill: var(--danger); display: none; flex: none; }
.tile.muted .label .mic-off { display: block; }

.tile.connecting::after {
  content: "Подключение…";
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 6px;
  background: rgba(0, 0, 0, .55);
  color: var(--muted);
}

.controls {
  display: flex;
  justify-content: center;
  gap: 10px;
  padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
  flex-wrap: wrap;
}

.ctl {
  position: relative;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #2c313c;
  display: grid;
  place-items: center;
  flex: none;
}
.ctl svg { width: 22px; height: 22px; fill: currentColor; }
.ctl:hover { background: #3a4050; }
.ctl.active { background: var(--accent); }
.ctl.off { background: var(--danger); }
.ctl.off::after {
  content: "";
  position: absolute;
  width: 2px;
  height: 26px;
  background: #fff;
  transform: rotate(45deg);
}
.ctl.danger { background: var(--danger); width: 60px; border-radius: 24px; }

.badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--danger);
  font-size: 11px;
  line-height: 18px;
  font-weight: 700;
}

/* ---------- чат ---------- */
.chat {
  width: 320px;
  background: var(--panel);
  display: flex;
  flex-direction: column;
  border-left: 1px solid #262a33;
}
.chat header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  font-weight: 600;
}
.x { background: none; font-size: 24px; line-height: 1; color: var(--muted); }
.messages { flex: 1; overflow-y: auto; padding: 0 16px; display: flex; flex-direction: column; gap: 10px; }
.msg-head { font-size: 12px; color: var(--muted); }
.msg-body { white-space: pre-wrap; word-break: break-word; }
.msg.mine .msg-head { color: var(--accent); }
.chat-form { display: flex; gap: 8px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); }
.chat-form input { flex: 1; min-width: 0; }
.chat-form button { background: var(--accent); border-radius: 8px; padding: 0 14px; color: #fff; }

@media (max-width: 700px) {
  .chat { position: fixed; inset: 0; width: auto; z-index: 10; border: 0; }
  .ctl { width: 44px; height: 44px; }
}

/* ---------- оверлеи ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .7);
  display: grid;
  place-items: center;
  z-index: 20;
  padding: 16px;
}
.card {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-width: 360px;
}
.card p { margin: 0; }

.toast {
  position: fixed;
  left: 50%;
  top: 16px;
  transform: translateX(-50%);
  background: #2c313c;
  padding: 8px 16px;
  border-radius: 8px;
  z-index: 30;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .4);
}
