body {
  margin: 0;
  background-color: #1f2937;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  font-family: sans-serif;
  color: white;
}

/* ======= Верхняя надпись ======= */
.room-label {
  text-align: center;
  padding: 1rem;
  background-color: #111827;
  border-bottom: 1px solid #374151;
  font-size: 1.2rem;
}

.room-code {
  color: #60a5fa;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.2s ease;
}

.room-code:hover {
  color: #93c5fd;
  text-decoration: underline;
}

/* ======= Контейнер для видео ======= */
.video-container {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1rem;
  flex: 1;
  align-items: center;
  justify-content: center;
  position: relative;
}

.video-container video {
  width: 100%;
  max-width: 500px;
  border-radius: 16px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
  border: 2px solid #374151;
  background-color: black;
  object-fit: contain;
}

/* ======= Панель с кнопками ======= */
.button-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background-color: #111827;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 1rem;
  padding: 1rem;
  border-top: 1px solid #374151;
}

.button-bar button {
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 9999px;
  font-weight: 600;
  color: white;
  cursor: pointer;
  box-shadow: 0 4px 8px rgba(0,0,0,0.3);
  transition: background-color 0.2s ease, transform 0.1s ease;
}

.button-bar button:active {
  transform: scale(0.97);
}

.button-create {
  background-color: #16a34a;
}

.button-create:hover {
  background-color: #15803d;
}

.button-join {
  background-color: #2563eb;
}

.button-join:hover {
  background-color: #1d4ed8;
}

.button-leave {
  background-color: #dc2626;
}

.button-leave:hover {
  background-color: #b91c1c;
}

/* ======= Иконки микрофона и камеры ======= */
.icon-bar {
  display: flex;
  gap: 1rem;
  align-items: center;
}

.icon-button {
  background: none;
  border: 2px solid #374151;
  border-radius: 50%;
  width: 48px;
  height: 48px;
  font-size: 22px;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.icon-button:hover {
  background-color: #374151;
}

.mic-off .icon,
.cam-off .icon {
  text-decoration: line-through;
  opacity: 0.6;
}

/* ======= Десктопная версия ======= */
@media (min-width: 768px) {
  .video-container {
    flex-direction: row;
  }

  .video-container video {
    width: 48%;
  }
}

/* =====================================================
        REMOTE VIDEO + AVATAR — ОСНОВНАЯ ЛОГИКА
   ===================================================== */

/* Обёртка remoteVideo — используется и на ПК, и на мобильном */
.remote-wrap {
  position: relative;
  display: inline-block;
  width: 100%;
  max-width: 500px;
}

/* Remote video внутри wrapper */
.remote-wrap #remoteVideo {
  display: block;
  width: 100%;
  max-width: 500px;
  height: auto;
  object-fit: contain;
  background: black;
  border-radius: 16px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
  border: 2px solid #374151;
}

/* Аватар — изначальная позиция (для десктопа) */
.remote-avatar {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 40vw;
  max-width: 300px;
  height: auto;
  aspect-ratio: auto;
  display: none;
  z-index: 20;
}

.remote-avatar img {
  width: 100%;
  height: auto;
  object-fit: contain;
  border-radius: 12px;
}

/* =====================================================
                    МОБИЛЬНАЯ ВЕРСТКА
   ===================================================== */
@media (max-width: 767px) {

  /* remoteVideo занимает почти весь экран */
  #remoteVideo {
    position: fixed;
    top: 3rem;
    left: 0;
    width: 100%;
    height: calc(100% - 8rem);
    object-fit: contain;
    background-color: black;
    border: none;
    border-radius: 0;
  }

  /* wrapper следует за remoteVideo */
  .remote-wrap {
    position: fixed;
    top: 3rem;
    left: 0;
    width: 100%;
    height: calc(100% - 8rem);
    max-width: none;
  }

  .remote-wrap #remoteVideo {
    width: 100%;
    height: 100%;
    max-width: none;
    object-fit: contain;
    border-radius: 0;
    border: none;
  }

  /* === ВАЖНО: Аватар поверх remoteVideo, по центру === */
  .remote-avatar {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    max-width: none;
    height: auto;
    aspect-ratio: auto;
    z-index: 20;
  }

  .remote-avatar img {
    width: 100%;
    height: auto;
    object-fit: contain;
  }

  /* localVideo — маленькое окно в углу */
  #localVideo {
    position: fixed;
    bottom: 6rem;
    right: 1rem;
    width: 35%;
    max-width: 180px;
    aspect-ratio: 16/9;
    z-index: 10;
    cursor: grab;
    object-fit: contain;
    border: 2px solid #374151;
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
  }
}

/* =====================================================
                    ДЕСКТОП
   ===================================================== */
@media (min-width: 768px) {
  .remote-wrap {
    position: relative;
    max-width: 500px;
  }

  .remote-wrap #remoteVideo {
    width: 100%;
    height: auto;
  }

  .remote-avatar {
    width: 300px;
  }
}
