:root {
  --bg: #0b0f14;
  --surface: #1a1d23;
  --border: #2a2d35;
  --text: #e0e0e0;
  --text-secondary: #a0a0a0;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --danger: #ef4444;
  --radius: 16px;
  --transition: 0.25s ease;
}

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

body {
  font-family: "Inter", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.header {
  width: 100%;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  /*background: var(--surface);
  border-bottom: 1px solid var(--border);*/
  position: fixed;
  top: 0;
  left: 0;
  z-index: 100;
}

#leaveRoomBtn {
  display: none !important;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 100%; /* займёт всю высоту шапки */
}

.logo-img {
  height: 100%; /* на всю высоту родителя (шапки) */
  max-height: 48px; /* но не больше 48px, чтобы не перетяжелять */
  width: auto;
  object-fit: contain;
  border-radius: 8px; /* небольшое скругление, чтобы было стильно */
}

.logo-text {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--text); /* белый в тёмной теме */
}

.room-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--border);
  padding: 4px 12px;
  border-radius: 24px;
  font-size: 0.8rem;
}

.btn {
  padding: 12px 24px;
  border: none;
  border-radius: 12px;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  color: var(--text-secondary);
}

.btn-primary {
  background: var(--accent);
  color: white;
}
.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-ghost {
  border: 1px solid var(--border);
}
.btn-ghost:hover {
  border-color: var(--accent);
  color: white;
}

.btn:disabled {
  opacity: 0.3;
  pointer-events: none;
}

.main-container {
  margin-top: 80px;
  width: 100%;
  max-width: 1200px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 32px;
  max-width: 440px;
  width: 100%;
  text-align: center;
}
.panel h2 {
  margin-bottom: 8px;
}
.panel p {
  color: var(--text-secondary);
  margin-bottom: 24px;
}

.input-group {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

#roomInput {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  outline: none;
}
#roomInput:focus {
  border-color: var(--accent);
}

.call-container {
  display: none;
  width: 100%;
  flex-direction: column;
  gap: 20px;
  animation: fadeIn 0.4s ease;
}
.call-container.active {
  display: flex;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.video-wrapper {
  background: #000;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
  aspect-ratio: 16/9;
  max-width: 600px;
  width: 100%;
  margin: 0 auto;
}
.video-wrapper video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.placeholder {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}
.placeholder.active {
  opacity: 1;
}

.video-label {
  position: absolute;
  bottom: 12px;
  left: 12px;
  background: rgba(0, 0, 0, 0.7);
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.8rem;
}

.local-video {
  position: fixed;
  bottom: 32px;
  right: 32px;
  width: 180px;
  border-radius: 16px;
  border: 2px solid var(--border);
  overflow: hidden;
  background: #000;
  z-index: 200;
  transition:
    width 0.3s,
    height 0.3s,
    border-radius 0.3s;
  cursor: pointer;
}
.local-video video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.local-video.collapsed {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 2px solid var(--border);
}
.local-video.collapsed video {
  display: none;
}
.local-video.collapsed .local-collapsed {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 100%;
  height: 100%;
  background: #000;
}
.local-collapsed {
  display: none;
}

.cam-indicator,
.audio-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #555;
  transition: background 0.2s;
}
.cam-indicator.on {
  background: #10b981;
}
.audio-indicator.speaking {
  background: #10b981;
  box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.7);
  animation: pulse-ring 0.6s infinite;
}

@keyframes pulse-ring {
  0% {
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.7);
  }
  50% {
    box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.3);
  }
  100% {
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.7);
  }
}

.controls {
  display: flex;
  gap: 12px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 10px;
}

.toggle-group {
  display: flex;
  gap: 8px;
}

.btn-icon {
  width: 48px;
  height: 48px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
  transition:
    border-color 0.2s,
    background 0.2s;
}
.btn-icon:hover {
  border-color: var(--accent);
}
.btn-icon.disabled {
  opacity: 0.4;
}

.icon-cam::before {
  content: "";
  display: block;
  width: 20px;
  height: 16px;
  background: currentColor;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2'%3E%3Cpath d='M23 7l-5 5 5 5V7z'/%3E%3Crect x='1' y='5' width='15' height='14' rx='2'/%3E%3C/svg%3E")
    no-repeat center;
  mask-size: contain;
  background: #fff;
}

.icon-mic::before {
  content: "";
  display: block;
  width: 16px;
  height: 20px;
  background: currentColor;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2'%3E%3Cpath d='M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z'/%3E%3Cpath d='M19 10v2a7 7 0 0 1-14 0v-2'/%3E%3Cline x1='12' y1='19' x2='12' y2='23'/%3E%3Cline x1='8' y1='23' x2='16' y2='23'/%3E%3C/svg%3E")
    no-repeat center;
  mask-size: contain;
  background: #fff;
}

.voice-dot {
  position: absolute;
  bottom: 4px;
  right: 4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #555;
  transition:
    background 0.2s,
    box-shadow 0.2s;
  box-shadow: 0 0 0 0 transparent;
}
.voice-dot.speaking {
  background: #10b981;
  animation: pulse-ring 0.6s infinite;
}

.status-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
  font-size: 0.8rem;
  color: var(--text-secondary);
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #555;
}
.status-dot.connected {
  background: #10b981;
}
.status-dot.disconnected {
  background: #ef4444;
}

#startCallBtn.disabled {
  pointer-events: none;
}

@media (max-width: 768px) {
  .local-video {
    width: 120px;
    bottom: 20px;
    right: 20px;
  }
  .local-video.collapsed {
    width: 48px;
    height: 48px;
  }
}

/* ===========================
   СТИЛИ ДЛЯ ДЕМОНСТРАЦИИ
   =========================== */

/* Иконка демонстрации экрана */
.icon-screen::before {
  content: "";
  display: block;
  width: 20px;
  height: 20px;
  background: currentColor;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2'%3E%3Crect x='2' y='3' width='20' height='14' rx='2'/%3E%3Cpath d='M8 21h8'/%3E%3Cpath d='M12 17v4'/%3E%3C/svg%3E")
    no-repeat center;
  mask-size: contain;
  background: #fff;
}

/* Карусель участников слева */
.participants-strip {
  position: fixed;
  top: 80px; /* ниже шапки */
  left: 0;
  bottom: 0;
  width: 200px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 8px;
  gap: 12px;
  transform: translateX(0);
  transition:
    transform 0.3s ease,
    width 0.3s ease;
  z-index: 150;
  overflow: hidden;
}

.participants-strip.collapsed {
  transform: translateX(-100%);
}

.strip-videos {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  flex: 1;
  overflow-y: auto;
}

/* Карточка участника */
.participant-thumb {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  position: relative;
  border: 1px solid var(--border);
}

.participant-thumb video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.thumb-placeholder {
  width: 100%;
  height: 100%;
  background: #2a2d35;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.participant-name {
  position: absolute;
  bottom: 4px;
  left: 4px;
  background: rgba(0, 0, 0, 0.7);
  padding: 2px 6px;
  border-radius: 10px;
  font-size: 0.65rem;
  color: white;
}

.participants-strip.collapsed .strip-toggle-btn {
  display: none;
}

/* Кнопка сворачивания карусели */
.strip-toggle-btn {
  width: 100%;
  padding: 8px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 0.9rem;
  transition: background 0.2s;
}
.strip-toggle-btn:hover {
  background: var(--border);
}

.toggle-arrow {
  transition: transform 0.3s;
}
.participants-strip.collapsed .toggle-arrow {
  transform: rotate(0deg); /* по желанию, но лучше изменить стрелку */
}

/* Индикатор с числом участников при свёрнутой карусели */
#carouselCounter {
  font-weight: 600;
}

/* Плавающая кнопка-индикатор (вне панели) */
.carousel-floating-btn {
  position: fixed;
  left: 8px;
  bottom: 24px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--border);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  z-index: 300;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  transition: transform 0.2s;
}
.carousel-floating-btn:hover {
  transform: scale(1.1);
}

.participants-strip.collapsed .strip-toggle-btn .toggle-arrow {
  display: none;
}
.participants-strip.collapsed .strip-toggle-btn .toggle-count {
  display: block;
  font-size: 0.8rem;
}

/* Центральная область */
.center-video-area {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
}

/* Новый контейнер для демонстрации */
.main-video-wrapper {
  display: none;
  width: 100%;
  height: 100%;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
}
.main-video-wrapper video {
  width: 100%;
  height: 100%;
  object-fit: contain; /* чтобы экран вписывался целиком */
}
.screen-placeholder {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  color: var(--text-secondary);
  font-size: 1.2rem;
  pointer-events: none;
}

/* Класс screen-sharing на callContainer – переключает видимость */
.call-container.screen-sharing #remoteVideoWrapper {
  display: none;
}
.call-container.screen-sharing #mainVideoWrapper {
  display: block;
}
.call-container.screen-sharing .participants-strip {
  /* уже видна, если не свернута */
}
/* По умолчанию карусель скрыта, если не screen-sharing */
#participantsStrip {
  display: none;
}
.call-container.screen-sharing #participantsStrip {
  display: flex;
}

/* Панель управления поверх демонстрации */
.call-container.screen-sharing .controls {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  border-radius: 40px;
  padding: 8px 16px;
  gap: 10px;
  z-index: 200;
  margin-top: 0;
}
.call-container.screen-sharing .status-bar {
  display: none; /* чтобы не мешала, можно оставить в углу */
}
/* Плейсхолдер внутри миниатюры (видео выключено) */
.thumb-no-video {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #1a1a1a;
  display: none;
}
.thumb-no-video.show {
  display: block;
}

/* Адаптация для мобильных: карусель сверху или скрываем */
@media (max-width: 768px) {
  .participants-strip {
    width: 100%;
    height: 120px;
    top: auto;
    bottom: 0;
    flex-direction: row;
    padding: 8px 4px;
  }
  .strip-videos {
    flex-direction: row;
    gap: 8px;
  }
  .participant-thumb {
    width: 100px;
    flex-shrink: 0;
  }
  .strip-toggle-btn {
    width: auto;
    align-self: center;
  }
  .call-container.screen-sharing .controls {
    bottom: 100px;
  }
}

/* ===========================
   FULLSCREEN DEMO (screen-sharing)
   =========================== */

/* Иконка выхода (дверь) */
.icon-exit::before {
  content: "";
  display: block;
  width: 20px;
  height: 20px;
  background: currentColor;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2'%3E%3Cpath d='M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4'/%3E%3Cpath d='M16 17l5-5-5-5'/%3E%3Cpath d='M21 12H9'/%3E%3C/svg%3E")
    no-repeat center;
  mask-size: contain;
  background: #fff;
}

/* Верхняя плашка (комната + статус) */
.demo-top-bar {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(8px);
  border-radius: 24px;
  padding: 6px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 400;
  font-size: 0.9rem;
  color: white;
  white-space: nowrap;
}

/* Переопределения при активации screen-sharing */
body:has(.call-container.screen-sharing) .header {
  display: none;
}

.call-container.screen-sharing .controls {
  position: fixed !important;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  border-radius: 40px;
  padding: 8px 16px;
  gap: 10px;
  z-index: 300;
  margin-top: 0;
}

.call-container.screen-sharing .main-video-wrapper {
  display: block;
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 1;
  border-radius: 0;
  background: #000;
}

.call-container.screen-sharing .main-video-wrapper video {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.call-container.screen-sharing .screen-placeholder {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  font-size: 1.2rem;
  color: var(--text-secondary);
}

.call-container.screen-sharing #remoteVideoWrapper {
  display: none;
}

/* Карусель в fullscreen - уже fixed, но проверим z-index */
.call-container.screen-sharing .participants-strip {
  z-index: 250;
  /* если карусель скрыта, индикатор остаётся */
}

/* Локальное видео: скрываем, если нет камеры */
.local-video.no-camera {
  display: none !important;
}
/* Иконки зума */
.icon-zoom-in::before {
  content: "";
  display: block;
  width: 20px;
  height: 20px;
  background: currentColor;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='M21 21l-4.3-4.3'/%3E%3Cpath d='M11 8v6'/%3E%3Cpath d='M8 11h6'/%3E%3C/svg%3E")
    no-repeat center;
  mask-size: contain;
  background: #fff;
}
.icon-zoom-out::before {
  content: "";
  display: block;
  width: 20px;
  height: 20px;
  background: currentColor;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='M21 21l-4.3-4.3'/%3E%3Cpath d='M8 11h6'/%3E%3C/svg%3E")
    no-repeat center;
  mask-size: contain;
  background: #fff;
}
.icon-zoom-reset::before {
  content: "";
  display: block;
  width: 20px;
  height: 20px;
  background: currentColor;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2'%3E%3Cpath d='M4 4v6h6'/%3E%3Cpath d='M20 20v-6h-6'/%3E%3Cpath d='M4 10a8 8 0 0 1 8-8'/%3E%3Cpath d='M20 14a8 8 0 0 1-8 8'/%3E%3C/svg%3E")
    no-repeat center;
  mask-size: contain;
  background: #fff;
}

/* Inner-контейнер для зума */
.main-video-inner {
  width: 100%;
  height: 100%;
  transform-origin: 0 0;
  transition: transform 0.2s ease;
  cursor: grab;
}
.main-video-inner:active {
  cursor: grabbing;
}
.main-video-inner.zoomed {
  cursor: grab;
}
