:root {
  --bg: var(--tg-theme-bg-color, #0f1115);
  --panel: var(--tg-theme-secondary-bg-color, #1b1f27);
  --text: var(--tg-theme-text-color, #f2f3f5);
  --hint: var(--tg-theme-hint-color, #8b93a1);
  --accent: var(--tg-theme-button-color, #3d8bfd);
  --accent-text: var(--tg-theme-button-text-color, #fff);
  --danger: #e5484d;
  --radius: 14px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

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

.screen {
  display: flex;
  flex-direction: column;
  gap: 14px;
  height: 100%;
  padding: 20px 16px calc(16px + env(safe-area-inset-bottom));
}

.hidden { display: none !important; }

#lobby { justify-content: center; }

h1 { margin: 0 0 4px; font-size: 22px; }

.hint { margin: 0; color: var(--hint); }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--hint); }

.field input {
  padding: 13px 14px;
  border: 1px solid #2b3240;
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  font-size: 16px;
}

.row { display: flex; gap: 10px; }

button {
  flex: 1;
  padding: 13px 16px;
  border: 0;
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
}

button.primary { background: var(--accent); color: var(--accent-text); }

.error { margin: 0; color: var(--danger); }

#call { padding: 12px 10px calc(12px + env(safe-area-inset-bottom)); }

#call header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 0 4px;
  font-size: 13px;
  color: var(--hint);
}

.grid {
  flex: 1;
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  align-content: center;
  overflow: auto;
}

.tile {
  position: relative;
  aspect-ratio: 3 / 4;
  min-height: 110px;
  border-radius: var(--radius);
  background: var(--panel);
  overflow: hidden;
  transition: box-shadow .15s;
}

.tile.speaking { box-shadow: inset 0 0 0 2px #37c26a; }
.tile.me { box-shadow: inset 0 0 0 2px #2b3240; }

.tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
}

.tile.has-video video { display: block; }

.tile .avatar {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 34px;
  font-weight: 600;
  color: var(--hint);
}

.tile.has-video .avatar { display: none; }

.tile .label {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 8px;
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  text-shadow: 0 1px 3px #000;
}

.tile .who {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tile .mic { font-size: 11px; }
.tile .mic:not(.off) { display: none; }

.controls {
  display: flex;
  justify-content: center;
  gap: 12px;
  padding-top: 10px;
}

.controls button {
  flex: 0 0 56px;
  height: 56px;
  border-radius: 50%;
  font-size: 20px;
  background: var(--panel);
  opacity: .55;
}

.controls button.on { opacity: 1; }
.controls button.danger { opacity: 1; background: var(--danger); transform: rotate(135deg); }

.toast {  position: fixed;
  left: 50%;
  bottom: calc(90px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: 90vw;
  padding: 10px 16px;
  border-radius: 12px;
  background: #000c;
  font-size: 13px;
  z-index: 10;
}

.boot {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  background: var(--bg);
  color: var(--hint);
  font-size: 14px;
}

button.big { padding: 18px; font-size: 17px; }
button.ghost { background: transparent; color: var(--hint); font-size: 14px; }
button.icon { flex: 0; padding: 4px 8px; background: transparent; color: var(--hint); font-size: 18px; }
button:disabled { opacity: .5; }

.section { margin: 6px 2px -4px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--hint); }

.people { display: flex; flex-direction: column; gap: 6px; }

.person {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--panel);
  text-align: left;
}

.pavatar {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  border-radius: 50%;
  background: #2b3240;
  font-size: 14px;
  font-weight: 600;
}

.pname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pgo { font-size: 12px; color: var(--hint); }

.manual { display: flex; gap: 8px; }
.manual input {
  flex: 1;
  padding: 12px 14px;
  border: 1px solid #2b3240;
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  font-size: 16px;
}
.manual button { flex: 0 0 auto; }

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 70vh;
  overflow: auto;
  padding: 12px 14px calc(14px + env(safe-area-inset-bottom));
  border-radius: 18px 18px 0 0;
  background: var(--bg);
  box-shadow: 0 -12px 40px #0009;
}

.sheetHead { display: flex; align-items: center; justify-content: space-between; font-weight: 600; }
.small { font-size: 12px; }
