:root {
  --bg: #0b0d12;
  --bg-soft: #12151d;
  --card: #171b25;
  --line: #262c3a;
  --txt: #e8ebf2;
  --txt-dim: #8b93a7;
  --accent: #4f8cff;
  --accent-soft: rgba(79, 140, 255, .14);
  --green: #35d07f;
  --red: #ff5d5d;
  --radius: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--txt);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body { overscroll-behavior: none; }

.hidden { display: none !important; }

/* ── экраны ─────────────────────────────────────────────── */

.screen { min-height: 100dvh; display: flex; flex-direction: column; }

#screen-create, #screen-error {
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card h1 { font-size: 22px; font-weight: 650; letter-spacing: -.01em; }
.sub { color: var(--txt-dim); font-size: 14px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field span { font-size: 12px; color: var(--txt-dim); text-transform: uppercase; letter-spacing: .06em; }

input {
  width: 100%;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 13px;
  color: var(--txt);
  font-size: 15px;
  outline: none;
  transition: border-color .15s;
}
input:focus { border-color: var(--accent); }
input::placeholder { color: #5a627a; }

/* ── кнопки ─────────────────────────────────────────────── */

.btn {
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--txt);
  border-radius: 10px;
  padding: 10px 15px;
  font-size: 14px;
  font-weight: 550;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .06s;
  text-align: center;
  text-decoration: none;
  display: inline-block;
}
.btn:hover { background: #1c2130; }
.btn:active { transform: scale(.985); }

.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #3f7cf5; }

.btn.danger { color: var(--red); border-color: rgba(255,93,93,.35); }
.btn.danger:hover { background: rgba(255,93,93,.1); }

.btn.ghost { background: transparent; }
.btn.small { padding: 7px 12px; font-size: 13px; }
.btn.wide { width: 100%; margin-top: 4px; }

.err { color: var(--red); font-size: 13px; min-height: 1em; }

/* ── верхняя панель ────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-soft);
  flex-wrap: wrap;
}

.room-info { display: flex; flex-direction: column; min-width: 0; }
.room-title { font-weight: 650; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-meta { font-size: 12px; color: var(--txt-dim); font-variant-numeric: tabular-nums; }

.topbar-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* ── баннер ─────────────────────────────────────────────── */

.banner {
  padding: 9px 16px;
  background: rgba(255,180,60,.12);
  border-bottom: 1px solid rgba(255,180,60,.25);
  color: #ffc55c;
  font-size: 13px;
  text-align: center;
}

/* ── сетка участников ──────────────────────────────────── */

.tiles {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  gap: 14px;
  padding: 20px 16px;
  align-content: start;
}

.tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 14px 8px 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  transition: border-color .18s, background .18s;
}

.tile.speaking { border-color: var(--green); background: rgba(53,208,127,.07); }
.tile.self { border-color: var(--accent); background: var(--accent-soft); }

.avatar {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: linear-gradient(150deg, #2a3242, #1b2130);
  border: 2px solid var(--line);
  display: grid;
  place-items: center;
  font-size: 22px;
  font-weight: 650;
  color: var(--txt-dim);
  position: relative;
  flex-shrink: 0;
  transition: border-color .18s, color .18s;
}
.tile.speaking .avatar { border-color: var(--green); color: var(--green); }
.tile.self .avatar { border-color: var(--accent); color: #cfe0ff; }

.avatar .muted-ico {
  position: absolute;
  right: -3px;
  bottom: -3px;
  width: 21px;
  height: 21px;
  border-radius: 50%;
  background: var(--red);
  color: #fff;
  font-size: 11px;
  display: grid;
  place-items: center;
  border: 2px solid var(--card);
}

.tile-name {
  font-size: 13px;
  font-weight: 550;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tile-state { font-size: 11px; color: var(--txt-dim); height: 1.2em; }
.tile.speaking .tile-state { color: var(--green); }

/* ── нижние контролы ───────────────────────────────────── */

.controls {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--bg-soft);
}

.ctl {
  display: flex;
  align-items: center;
  gap: 9px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 16px;
  color: var(--txt);
  font-size: 14px;
  font-weight: 550;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.ctl:hover { background: #1c2130; }
.ctl[aria-pressed="true"] { border-color: var(--red); color: var(--red); }
.ctl-ico { font-size: 17px; line-height: 1; }

.level-wrap {
  flex: 1;
  height: 8px;
  background: var(--bg);
  border-radius: 99px;
  overflow: hidden;
  border: 1px solid var(--line);
}
.level {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--green), #9be15d);
  border-radius: 99px;
  transition: width .08s linear;
}
.level.hot { background: linear-gradient(90deg, #ffb03a, var(--red)); }

/* ── панель организатора ───────────────────────────────── */

.host-panel {
  border-top: 1px solid var(--line);
  background: var(--card);
  padding: 14px 16px calc(16px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 46dvh;
  overflow-y: auto;
}

.host-head { display: flex; align-items: center; justify-content: space-between; }
.host-head h2 { font-size: 15px; font-weight: 650; }

.invite-row { display: flex; gap: 8px; }
.invite-row input { flex: 1; }

.invite-out { display: flex; gap: 8px; }
.invite-out input {
  flex: 1;
  font-size: 12px;
  color: var(--txt-dim);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.host-list { list-style: none; display: flex; flex-direction: column; gap: 2px; }

.host-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 10px;
}
.host-item:hover { background: var(--bg-soft); }
.host-item.speaking { background: rgba(53,208,127,.08); }

.host-item .hname {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.host-item .hname .tag {
  font-size: 10px;
  color: var(--accent);
  border: 1px solid rgba(79,140,255,.4);
  border-radius: 5px;
  padding: 1px 5px;
  margin-left: 6px;
  vertical-align: middle;
}
.host-item .hname .tag.off { color: var(--txt-dim); border-color: var(--line); }

/* переключатель */
.switch {
  position: relative;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
  cursor: pointer;
}
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute; inset: 0;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 99px;
  transition: background .18s, border-color .18s;
}
.switch .track::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--txt-dim);
  transition: transform .18s, background .18s;
}
.switch input:checked + .track { background: rgba(53,208,127,.18); border-color: var(--green); }
.switch input:checked + .track::after { transform: translateX(18px); background: var(--green); }

.icon-btn {
  background: transparent;
  border: none;
  color: var(--txt-dim);
  cursor: pointer;
  padding: 5px 7px;
  border-radius: 7px;
  font-size: 13px;
  flex-shrink: 0;
}
.icon-btn:hover { color: var(--red); background: rgba(255,93,93,.1); }

/* ── мобильное ─────────────────────────────────────────── */

@media (max-width: 480px) {
  .tiles { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; padding: 14px 12px; }
  .avatar { width: 50px; height: 50px; font-size: 19px; }
  .ctl-label { display: none; }
  .ctl { padding: 11px 14px; }
  .topbar { padding: 11px 12px; }
  .room-meta { font-size: 11px; }
}

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