:root {
  --bg: #050505;
  --panel: #0b0b0b;
  --panel-2: #111111;
  --panel-3: #171717;
  --text: #f2f2f2;
  --muted: #999999;
  --muted-2: #6f6f6f;
  --accent: #2f7dff;
  --danger: #d93636;
  --line: #242424;
  --line-2: #333333;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  overflow: hidden;
}

button, input, select { font: inherit; }

button {
  border: 1px solid var(--line-2);
  border-radius: 0;
  padding: 12px 15px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

button:hover { filter: brightness(1.08); }
button:disabled { cursor: not-allowed; opacity: .55; }

button.ghost {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line-2);
}

button.small { padding: 9px 11px; font-size: 13px; }
button.tiny { padding: 7px 9px; font-size: 12px; }
button.danger { background: var(--danger); border-color: var(--danger); }
button.off { background: #333; color: #ddd; }

input, select {
  width: 100%;
  border: 1px solid var(--line-2);
  border-radius: 0;
  background: #070707;
  color: var(--text);
  padding: 13px 14px;
  outline: none;
}

input[type="file"] { padding: 10px; }
input::placeholder { color: #555; }
input:focus, select:focus { border-color: var(--accent); }

.hidden { display: none !important; }

.join-screen {
  min-height: 100vh;
  padding: 24px;
  display: grid;
  grid-template-columns: minmax(360px, 520px) minmax(280px, 380px);
  grid-template-rows: auto auto;
  align-content: center;
  justify-content: center;
  gap: 14px;
}

.join-card,
.setup-card,
.rooms-card,
.modal-card {
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--panel);
  padding: 24px;
}

.join-card { grid-row: span 2; }

.brand-block {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
}

.logo {
  display: grid;
  place-items: center;
  overflow: hidden;
  background: #000;
  border: 1px solid var(--line-2);
}

.logo-large { width: 94px; height: 94px; }

.brand-logo,
.profile-preview img,
.avatar img,
.tile-avatar img,
.message-avatar img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

h1 {
  margin: 0;
  font-size: clamp(36px, 7vw, 56px);
  line-height: .95;
  letter-spacing: -.04em;
}

h2 { margin: 0; font-size: 20px; }

h3 {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .1em;
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  border: 1px solid var(--line-2);
  margin-bottom: 16px;
}

.tab {
  background: var(--panel-2);
  border: 0;
  border-right: 1px solid var(--line-2);
  color: var(--muted);
  box-shadow: none;
}

.tab:last-child { border-right: 0; }

.tab.active {
  background: var(--accent);
  color: #fff;
}

label {
  display: block;
  margin: 14px 0 7px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.profile-row {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.profile-preview,
.avatar,
.tile-avatar,
.message-avatar {
  overflow: hidden;
  background: #070707;
  border: 1px solid var(--line-2);
  color: var(--text);
  display: grid;
  place-items: center;
  font-weight: 900;
  text-transform: uppercase;
}

.profile-preview { width: 54px; height: 54px; }

.form-row.two {
  display: grid;
  grid-template-columns: 1fr 120px;
  gap: 10px;
}

.primary-btn { width: 100%; margin-top: 14px; }

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.mini-status {
  min-height: 20px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.active-rooms {
  display: grid;
  gap: 8px;
  max-height: 230px;
  overflow: auto;
}

.room-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line-2);
  background: var(--panel-2);
  cursor: pointer;
}

.room-item:hover { background: var(--panel-3); }

.room-item strong {
  font-size: 14px;
  word-break: break-all;
}

.room-item span {
  color: var(--muted);
  font-size: 12px;
}

.room-badge {
  padding: 4px 7px;
  border: 1px solid var(--line-2);
  color: var(--muted);
  font-size: 12px;
}

.empty-list {
  color: var(--muted);
  padding: 12px;
  border: 1px solid var(--line-2);
  text-align: center;
}

.app {
  height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  overflow: hidden;
}

.stage {
  position: relative;
  min-width: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: #060606;
}

.call-topbar {
  height: 64px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.call-topbar strong { font-size: 20px; }

.connection-status {
  padding: 7px 10px;
  border: 1px solid var(--line-2);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.connection-status.warn { color: #e7c169; }
.connection-status.bad { color: #ff8a8a; }

.video-grid {
  min-height: 0;
  padding: 14px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(285px, 1fr));
  align-content: center;
  gap: 12px;
  overflow: auto;
}

.tile {
  position: relative;
  overflow: hidden;
  min-height: 215px;
  border: 1px solid var(--line-2);
  background: #020202;
}

.tile video {
  width: 100%;
  height: 100%;
  min-height: 215px;
  object-fit: cover;
  display: block;
  background: #020202;
}

.tile audio { display: none; }

.tile .placeholder {
  min-height: 215px;
  display: grid;
  place-items: center;
  background: #080808;
}

.tile-avatar {
  width: 92px;
  height: 92px;
  font-size: 44px;
}

.tile .label {
  position: absolute;
  left: 10px;
  bottom: 10px;
  padding: 7px 9px;
  background: rgba(0, 0, 0, .75);
  border: 1px solid var(--line-2);
  font-size: 13px;
  font-weight: 700;
}

.controls {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  padding: 12px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.chat-panel {
  background: var(--panel);
  border-left: 1px solid var(--line);
  padding: 14px;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.room-box {
  border: 1px solid var(--line-2);
  background: var(--panel-2);
  padding: 12px;
  margin-bottom: 14px;
}

.room-box h2 {
  margin: 0 0 7px;
  word-break: break-all;
}

.room-meta {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 10px;
}

.room-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.user-list {
  display: grid;
  gap: 8px;
  max-height: 170px;
  overflow: auto;
  margin-bottom: 16px;
}

.user {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px;
  border: 1px solid var(--line-2);
  background: var(--panel-2);
}

.avatar {
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
}

.user-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-status {
  margin-left: auto;
  color: var(--muted);
  font-size: 13px;
}

.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.chat-head h3 { margin: 0; }

.messages {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.message {
  padding: 10px;
  border: 1px solid var(--line-2);
  background: var(--panel-2);
  line-height: 1.35;
  word-break: break-word;
  display: grid;
  grid-template-columns: 30px 1fr;
  gap: 8px;
}

.message.system {
  color: var(--muted);
  display: block;
}

.message-avatar {
  width: 30px;
  height: 30px;
  font-size: 12px;
}

.message-body { min-width: 0; }

.message b {
  display: block;
  margin-bottom: 4px;
  color: var(--text);
}

.message span {
  color: var(--muted-2);
  font-size: 12px;
  font-weight: 700;
}

.emoji-row {
  display: flex;
  gap: 7px;
  padding-top: 10px;
}

.emoji-btn {
  width: 40px;
  height: 36px;
  padding: 0;
  background: var(--panel-2);
  border: 1px solid var(--line-2);
}

.chat-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding-top: 10px;
}

.chat-form button {
  width: 48px;
  padding-inline: 0;
}

.toast {
  position: absolute;
  top: 78px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  padding: 10px 13px;
  background: #111;
  border: 1px solid var(--line-2);
  color: var(--text);
  max-width: min(520px, calc(100% - 32px));
  text-align: center;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(0,0,0,.7);
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal-card { width: min(440px, 100%); }

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.video-grid::-webkit-scrollbar,
.messages::-webkit-scrollbar,
.user-list::-webkit-scrollbar,
.active-rooms::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.video-grid::-webkit-scrollbar-thumb,
.messages::-webkit-scrollbar-thumb,
.user-list::-webkit-scrollbar-thumb,
.active-rooms::-webkit-scrollbar-thumb {
  background: #333;
}

@media (max-width: 980px) {
  body { overflow: auto; }

  .join-screen {
    grid-template-columns: minmax(280px, 520px);
    align-content: start;
    padding: 14px;
  }

  .join-card { grid-row: auto; }

  .app {
    height: auto;
    min-height: 100vh;
    grid-template-columns: 1fr;
  }

  .chat-panel {
    border-left: 0;
    border-top: 1px solid var(--line);
    min-height: 360px;
  }
}

@media (max-width: 560px) {
  .join-card,
  .setup-card,
  .rooms-card,
  .modal-card {
    padding: 18px;
  }

  .brand-block {
    flex-direction: column;
    align-items: flex-start;
  }

  .form-row.two,
  .room-actions,
  .profile-row {
    grid-template-columns: 1fr;
  }

  .profile-preview {
    width: 64px;
    height: 64px;
  }

  .video-grid {
    grid-template-columns: 1fr;
  }

  .controls button {
    flex: 1 1 140px;
  }
}








.tile.screen-tile video {
  object-fit: contain;
  background: #000;
}





.screen-viewer {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: #000;
  display: none;
}

.screen-viewer.open {
  display: block;
}

.screen-viewer video {
  width: 100vw;
  height: 100vh;
  object-fit: contain;
  background: #000;
  display: block;
}





body.viewer-open .chat-panel,
body.viewer-open .controls,
body.viewer-open .call-topbar {
  visibility: hidden;
}




.screen-viewer {
  position: fixed !important;
  inset: 0 !important;
  z-index: 2147483647 !important;
  background: #000 !important;
}

.screen-viewer.open {
  display: block !important;
}

.screen-viewer video {
  position: absolute;
  inset: 0;
  width: 100vw !important;
  height: 100vh !important;
  object-fit: contain !important;
  background: #000 !important;
}




.screen-viewer {
  position: fixed !important;
  inset: 0 !important;
  z-index: 2147483647 !important;
  background: #000 !important;
  display: none !important;
  pointer-events: auto !important;
}

.screen-viewer.open {
  display: block !important;
}

.screen-viewer video {
  position: fixed !important;
  inset: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  object-fit: contain !important;
  background: #000 !important;
  display: block !important;
  pointer-events: none !important;
}







body.viewer-open {
  overflow: hidden !important;
}

body.viewer-open .app > *:not(.screen-viewer) {
  visibility: hidden;
}
















.screen-choice-modal {
  position: fixed;
  inset: 0;
  z-index: 2147483646;
  background: rgba(0,0,0,.72);
  display: grid;
  place-items: center;
  padding: 18px;
}

.screen-choice-modal.hidden {
  display: none !important;
}

.screen-choice-card {
  width: min(420px, 100%);
  border: 1px solid var(--line-2);
  background: var(--panel);
  padding: 14px;
}

.screen-choice-card h2 {
  margin: 0 0 12px;
  font-size: 18px;
}

.screen-choice-list {
  display: grid;
  gap: 8px;
}

.screen-choice-btn {
  width: 100%;
  text-align: left;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line-2);
  padding: 12px 14px;
}

.screen-choice-btn:hover {
  background: var(--panel-3);
}


.settings-toggle {
  width: 100%;
  margin-top: 12px;
}

.compressor-panel {
  margin-top: 8px;
  padding: 12px;
  border: 1px solid var(--line-2);
  background: var(--panel-2);
}

.slider-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
}

.slider-row:first-child {
  margin-top: 0;
}

.slider-row label {
  margin: 0 0 3px;
}

.slider-row small {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.slider-row strong {
  color: var(--text);
  font-size: 13px;
  min-width: 54px;
  text-align: right;
}

.compressor-panel input[type="range"] {
  padding: 0;
  margin: 8px 0 6px;
  height: 26px;
  border: 0;
  background: transparent;
}

.compressor-panel button {
  margin-top: 10px;
}


.controls > .hidden {
  display: none !important;
}

.settings-block {
  margin-top: 12px;
}

.settings-block .settings-toggle + .settings-toggle {
  margin-top: 8px;
}

/* WNB View: большой просмотр сверху, участники ниже без сдвига страницы */
.app,
.stage,
.chat-panel {
  min-height: 0;
}

.chat-panel {
  height: 100vh;
  max-height: 100vh;
  overflow: hidden;
}

.video-grid.wnb-view-active {
  align-content: start;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  grid-auto-rows: auto;
}

.video-grid.wnb-view-active .tile {
  min-height: 132px;
}

.video-grid.wnb-view-active .tile video,
.video-grid.wnb-view-active .tile .placeholder {
  min-height: 132px;
}

.video-grid.wnb-view-active .wnb-view-tile {
  grid-column: 1 / -1;
  height: clamp(300px, calc(100vh - 330px), 560px);
  min-height: 0;
}

.video-grid.wnb-view-active .wnb-view-tile video,
.video-grid.wnb-view-active .wnb-view-tile iframe,
.video-grid.wnb-view-active .wnb-view-tile #watchPartyYouTube {
  width: 100%;
  height: 100%;
  min-height: 0;
  object-fit: contain;
  display: block;
  background: #000;
}

@supports (height: 100dvh) {
  .chat-panel {
    height: 100dvh;
    max-height: 100dvh;
  }

  .video-grid.wnb-view-active .wnb-view-tile {
    height: clamp(300px, calc(100dvh - 330px), 560px);
  }
}
