* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #1a1b26;
  --bg-elev: #24263a;
  --bg-elev-2: #2d2f47;
  --border: #383b58;
  --text: #e6e8f0;
  --text-dim: #9ca0c2;
  --primary: #6366f1;
  --primary-hover: #7c7ff5;
  --danger: #ef4444;
  --success: #10b981;
  --warning: #f59e0b;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

.screen {
  display: none;
  width: 100%;
  height: 100vh;
}
.screen.active {
  display: flex;
}

/* ===== ЛОББИ ===== */
#lobby {
  align-items: center;
  justify-content: center;
  overflow-y: auto;
  padding: 24px;
}

.lobby-container {
  width: 100%;
  max-width: 880px;
}

.logo {
  font-size: 42px;
  font-weight: 800;
  text-align: center;
  background: linear-gradient(135deg, #6366f1, #a855f7);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin-bottom: 6px;
}

.subtitle {
  text-align: center;
  color: var(--text-dim);
  margin-bottom: 28px;
}

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  margin-bottom: 16px;
}

.card h2 {
  font-size: 18px;
  margin-bottom: 14px;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 720px) {
  .grid { grid-template-columns: 1fr; }
}

.label {
  display: block;
  font-size: 13px;
  color: var(--text-dim);
  margin: 10px 0 6px;
}

.input {
  width: 100%;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 11px 14px;
  border-radius: 10px;
  font-size: 14px;
  outline: none;
  transition: border-color .15s;
}
.input:focus {
  border-color: var(--primary);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--bg-elev-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
}
.btn:hover { background: #353859; }
.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}
.btn-danger:hover { background: #f56565; }

#createRoomBtn { margin-top: 14px; width: 100%; }

.btn-icon {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}
.btn-icon:hover { color: var(--text); background: var(--bg-elev-2); }

.row-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}
.row-between h2 { margin-bottom: 0; }

.rooms-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 280px;
  overflow-y: auto;
}

.room-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-elev-2);
  padding: 12px 14px;
  border-radius: 10px;
  cursor: pointer;
  transition: background .15s;
}
.room-item:hover { background: #353859; }

.room-item-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.room-item-name { font-weight: 500; }
.room-item-meta { font-size: 12px; color: var(--text-dim); }

.room-item-badges {
  display: flex;
  gap: 6px;
  align-items: center;
}
.badge {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--bg-elev);
  color: var(--text-dim);
}
.badge.lock { background: rgba(245, 158, 11, 0.15); color: var(--warning); }

.empty {
  text-align: center;
  color: var(--text-dim);
  padding: 24px;
  font-size: 14px;
}

.hint {
  margin-top: 18px;
  text-align: center;
  font-size: 12px;
  color: var(--text-dim);
}

/* ===== МОДАЛКА ===== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal.hidden { display: none; }
.modal-content {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  width: 90%;
  max-width: 380px;
}
.modal-content h3 { margin-bottom: 16px; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}
.error {
  color: var(--danger);
  font-size: 13px;
  min-height: 18px;
  margin-top: 8px;
}

/* ===== ЭКРАН КОМНАТЫ ===== */
#room {
  flex-direction: column;
}

.room-header {
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  padding: 14px 22px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.room-title { font-weight: 600; font-size: 17px; }
.room-meta { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

.room-main {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 320px;
  overflow: hidden;
}
@media (max-width: 900px) {
  .room-main { grid-template-columns: 1fr; }
  .chat-section { display: none; }
}

.videos-section {
  display: flex;
  flex-direction: column;
  padding: 16px;
  overflow: hidden;
}

.videos-grid {
  flex: 1;
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  grid-auto-rows: 1fr;
  overflow-y: auto;
  padding-bottom: 12px;
}

.video-tile {
  position: relative;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  aspect-ratio: 16 / 9;
  border: 2px solid transparent;
  min-height: 160px;
  transition: border-color .15s, box-shadow .15s;
}
.video-tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}
.video-tile .no-video {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 8px;
  color: var(--text-dim);
  background: linear-gradient(135deg, #2d2f47, #1a1b26);
}
.video-tile .avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  font-weight: 700;
  color: #fff;
}
.video-tile .name-tag {
  position: absolute;
  bottom: 8px;
  left: 8px;
  background: rgba(0,0,0,0.6);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.video-tile .mic-state {
  font-size: 12px;
}
.video-tile.self .name-tag::after {
  content: " (вы)";
  color: var(--text-dim);
}

.controls {
  display: flex;
  justify-content: center;
  gap: 10px;
  padding: 14px 0 4px;
}
.ctrl-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 12px;
  cursor: pointer;
  min-width: 80px;
  transition: all .15s;
}
.ctrl-btn:hover { background: var(--bg-elev-2); }
.ctrl-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.ctrl-btn.danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}
.ctrl-btn.ptt {
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
.ctrl-btn.ptt.holding {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
  transform: scale(0.97);
}
.ctrl-icon { font-size: 22px; }
.ctrl-label { font-size: 11px; }

/* Индикатор «говорит» */
.video-tile.speaking {
  border-color: var(--success);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.25);
}
.video-tile .speaking-indicator {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--success);
  opacity: 0;
  transition: opacity .15s;
  box-shadow: 0 0 8px var(--success);
}
.video-tile.speaking .speaking-indicator {
  opacity: 1;
  animation: pulse 1.2s infinite;
}
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.3); }
}

/* Эмодзи-пиккер */
.btn-icon-square {
  padding: 0;
  width: 40px;
  height: 40px;
  font-size: 18px;
  flex-shrink: 0;
}
.emoji-picker {
  position: absolute;
  bottom: 70px;
  left: 12px;
  right: 12px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  max-height: 240px;
  overflow-y: auto;
  z-index: 50;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.emoji-picker.hidden { display: none; }
.emoji-picker button {
  background: transparent;
  border: none;
  font-size: 22px;
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  transition: background .12s;
}
.emoji-picker button:hover { background: var(--bg-elev); }
.chat-section { position: relative; }

/* ===== ЧАТ ===== */
.chat-section {
  background: var(--bg-elev);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.chat-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.msg {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-width: 90%;
}
.msg.own { align-self: flex-end; align-items: flex-end; }
.msg .meta {
  font-size: 11px;
  color: var(--text-dim);
}
.msg .bubble {
  background: var(--bg-elev-2);
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 14px;
  word-wrap: break-word;
  word-break: break-word;
}
.msg.own .bubble {
  background: var(--primary);
  color: #fff;
}
.msg.system .bubble {
  background: transparent;
  color: var(--text-dim);
  font-style: italic;
  font-size: 12px;
}
.msg.system { align-self: center; }

.chat-form {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border);
}
.chat-form .btn { padding: 10px 14px; }

/* Скроллбар */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #4a4d72; }
