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

:root {
  --bg: #0d0d14;
  --panel: #1a1a26;
  --panel2: #23232f;
  --text: #e8e6e0;
  --muted: #8a8a99;
  --accent: #c9a227;
  --accent2: #8a1515;
}

html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  overflow: hidden;
}

.hidden { display: none !important; }

/* ---------- Лобби ---------- */
#lobby {
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 16px 32px;
  background:
    radial-gradient(ellipse at 50% -20%, rgba(201,162,39,.15), transparent 60%),
    var(--bg);
}
.lobby-card {
  width: 420px;
  max-width: 94vw;
  margin: auto;
  flex-shrink: 0;
  background: var(--panel);
  border: 1px solid #2e2e3e;
  border-radius: 16px;
  padding: 32px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.lobby-card h1 { font-size: 28px; margin-bottom: 4px; }
.subtitle { color: var(--muted); font-size: 14px; margin-bottom: 24px; }
.lobby-hint { font-size: 12px; color: var(--muted); margin-top: 12px; line-height: 1.45; }
.lobby-card label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 14px; }
.lobby-card input[type="text"] {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  background: var(--panel2);
  border: 1px solid #34344a;
  border-radius: 8px;
  color: var(--text);
  font-size: 15px;
}
.lobby-card input[type="text"]:focus { outline: none; border-color: var(--accent); }
.lobby-card select {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  background: var(--panel2);
  border: 1px solid #34344a;
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
}
.lobby-card select:focus { outline: none; border-color: var(--accent); }

.device-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 14px;
}
.device-pickers {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.device-row label,
.device-pickers label {
  margin-bottom: 0 !important;
  font-size: 13px;
  color: var(--muted);
}
.device-pickers select {
  min-width: 0;
}
.grant-btn {
  align-self: flex-start;
  padding: 6px 12px;
  font-size: 12px;
  background: var(--panel2);
  border: 1px solid #34344a;
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
}
.grant-btn:hover { border-color: var(--accent); }
#refreshDevicesBtn {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  background: var(--panel2);
  border: 1px solid #34344a;
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  font-size: 16px;
  margin-bottom: 1px;
}
#refreshDevicesBtn:hover { border-color: var(--accent); }

.cam-preview {
  width: 100%;
  max-height: 220px;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  margin-bottom: 12px;
  border-radius: 8px;
  background: #000;
  border: 1px solid #34344a;
  transform: scaleX(-1);
}

.role-select { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.role-option {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel2);
  border: 1px solid #34344a;
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
  margin-bottom: 0 !important;
}
.role-option:has(input:checked) { border-color: var(--accent); background: #2a2637; }
.role-option span { display: flex; flex-direction: column; color: var(--text); font-size: 15px; }
.role-option small { color: var(--muted); font-size: 12px; }

.checkbox-row { display: flex !important; align-items: center; gap: 8px; color: var(--text) !important; }

/* Проверка микрофона в лобби */
.mic-test { margin-bottom: 14px; }
#micTestBtn {
  width: 100%;
  padding: 8px;
  background: var(--panel2);
  border: 1px solid #34344a;
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  margin-bottom: 8px;
}
#micTestBtn:hover { border-color: var(--accent); }
.mic-meter-bar {
  position: relative;
  height: 14px;
  background: var(--panel2);
  border: 1px solid #34344a;
  border-radius: 7px;
  overflow: hidden;
  margin-bottom: 6px;
}
#micMeterFill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #2fbf71 0%, #c9e265 70%, #e2a03f 100%);
  transition: width .06s linear;
}
#micMeterFill.hot {
  background: linear-gradient(90deg, #2fbf71 0%, #e2a03f 60%, #e24a3f 100%);
}
#micMeterPeak {
  position: absolute;
  top: 0; bottom: 0;
  width: 2px;
  background: #fff;
  left: 0%;
  transition: left .1s linear;
  opacity: .8;
}
.mic-test-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}
.mic-test-row span { flex: 1; min-width: 0; }
#micMonitorBtn {
  flex-shrink: 0;
  background: var(--panel2);
  border: 1px solid #34344a;
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  padding: 4px 10px;
  font-size: 12px;
}
#micMonitorBtn:hover { border-color: var(--accent); }
#micMonitorBtn.on { border-color: var(--accent); background: #2a2637; }

#joinBtn {
  width: 100%;
  padding: 12px;
  margin-top: 8px;
  background: var(--accent);
  color: #1a1408;
  border: none;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}
#joinBtn:hover { filter: brightness(1.1); }
#joinBtn:disabled { opacity: .5; cursor: wait; }
.lobby-status { margin-top: 12px; font-size: 13px; color: var(--muted); min-height: 18px; }

/* ---------- Приложение ---------- */
#app {
  height: 100vh;
  display: flex;
}

#stageWrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 20px 52px;
  min-width: 0;
}

#stage {
  position: relative;
  width: min(100%, calc((100vh - 96px) * 16 / 9));
  aspect-ratio: 16 / 9;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 0 0 1px #2e2e3e, 0 30px 80px rgba(0,0,0,.6);
  background: #000;
}

#stageBg {
  position: absolute;
  inset: 0;
  background: #14141f;
  background-size: cover;
  background-position: center;
  transition: background .4s;
}

/* Актёр на сцене */
.actor {
  position: absolute;
  touch-action: none;
  user-select: none;
}
.actor canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  background: transparent;
  pointer-events: none;
}
.actor .name-tag {
  position: absolute;
  left: 50%; bottom: -4px;
  transform: translateX(-50%);
  background: rgba(0,0,0,.55);
  color: #fff;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  white-space: nowrap;
  opacity: 0.85;
  pointer-events: none;
}
.actor:hover .name-tag { opacity: 1; }
/* глобальное скрытие имён (переключатель режиссёра) */
#stage.hide-names .name-tag { display: none; }

.director-mode .actor { cursor: grab; }
.director-mode .actor:active { cursor: grabbing; }
.director-mode .actor:hover { outline: 1px dashed rgba(201,162,39,.7); outline-offset: 2px; }

.resize-handle {
  position: absolute;
  right: -6px; bottom: -6px;
  width: 14px; height: 14px;
  background: var(--accent);
  border-radius: 3px;
  cursor: nwse-resize;
  display: none;
}
.director-mode .actor:hover .resize-handle { display: block; }

/* Занавес */
.curtain {
  position: absolute;
  top: 0; bottom: 0;
  width: 51%;
  background:
    repeating-linear-gradient(90deg,
      #5a0d0d 0 18px, #8a1515 18px 34px, #6d1010 34px 52px);
  box-shadow: inset 0 -40px 60px rgba(0,0,0,.6);
  transition: transform 1.6s cubic-bezier(.6,.05,.3,1);
  z-index: 1000;
}
#curtainL { left: 0; transform: translateX(-101%); }
#curtainR { right: 0; transform: translateX(101%); }
.curtain-closed #curtainL { transform: translateX(0); }
.curtain-closed #curtainR { transform: translateX(0); }

/* ---------- Панель режиссёра ---------- */
#panel {
  width: 280px;
  flex-shrink: 0;
  background: var(--panel);
  border-left: 1px solid #2e2e3e;
  padding: 20px 16px;
  overflow-y: auto;
}
#panel h2 { font-size: 17px; margin-bottom: 16px; }
#panel section { margin-bottom: 22px; }
#panel h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  margin-bottom: 10px;
}

.wide-btn {
  width: 100%;
  padding: 10px;
  background: var(--accent2);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
}
.wide-btn:hover { filter: brightness(1.2); }

.bg-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}
.bg-swatch {
  aspect-ratio: 16/10;
  border-radius: 6px;
  border: 2px solid transparent;
  cursor: pointer;
  background-size: cover;
  background-position: center;
}
.bg-swatch:hover { border-color: var(--accent); }

.bg-lib-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  padding: 4px;
  border-radius: 8px;
  border: 1px solid transparent;
}
.bg-lib-row.is-active { border-color: var(--accent); background: #2a2637; }
.bg-lib-thumb {
  flex: 0 0 48px;
  width: 48px;
  height: 32px;
  border-radius: 4px;
  border: 1px solid #34344a;
  background: #1a1a24 center / cover no-repeat;
  cursor: pointer;
  padding: 0;
  font-size: 14px;
  color: var(--muted);
}
.bg-lib-thumb.is-video {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #1a1a24;
}
.bg-lib-thumb:hover { border-color: var(--accent); }
.bg-lib-name {
  flex: 1;
  font-size: 12px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}
.bg-lib-row button:last-child {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid #34344a;
  border-radius: 6px;
  background: var(--panel2);
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
}
.bg-lib-row button:last-child:hover { border-color: #c06060; color: #e8c0c0; }

#stageBg video.stage-bg-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}

.bg-custom { display: flex; gap: 6px; margin-bottom: 8px; }
.bg-custom input[type="text"] {
  flex: 1;
  min-width: 0;
  padding: 7px 10px;
  background: var(--panel2);
  border: 1px solid #34344a;
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
}
.bg-custom button {
  padding: 7px 12px;
  background: var(--panel2);
  border: 1px solid #34344a;
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
}
.color-row { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.color-row input { width: 40px; height: 28px; border: none; background: none; cursor: pointer; }
.quality-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
  font-size: 13px;
  color: var(--muted);
}
.quality-row span { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.quality-row output { color: var(--text); font-variant-numeric: tabular-nums; min-width: 2.5em; text-align: right; }
.quality-row select,
.quality-row input[type="range"] { width: 100%; }
.quality-row select {
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 13px;
}

/* Список актёров */
.actor-row {
  display: flex;
  align-items: center;
  gap: 6px;
  position: relative;
  background: var(--panel2);
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 6px;
  font-size: 13px;
}
.actor-row .a-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.actor-tip {
  display: none;
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: calc(100% + 6px);
  z-index: 50;
  padding: 6px 10px;
  background: #1e1e2a;
  border: 1px solid var(--accent);
  border-radius: 8px;
  color: var(--text);
  font-size: 12px;
  line-height: 1.35;
  white-space: normal;
  word-break: break-word;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}
.actor-row.has-tip:hover .actor-tip { display: block; }
.actor-row button {
  background: none;
  border: 1px solid #3a3a4e;
  border-radius: 5px;
  color: var(--text);
  cursor: pointer;
  padding: 3px 7px;
  font-size: 12px;
}
.actor-row button:hover { border-color: var(--accent); }
.actor-row.is-hidden .a-name { opacity: .4; text-decoration: line-through; }

.hint { font-size: 11px; color: var(--muted); line-height: 1.5; margin-top: 6px; white-space: pre-line; }

/* Мизансцены */
.preset-row {
  display: flex;
  align-items: center;
  gap: 4px;
  position: relative;
  background: var(--panel2);
  border: 1px solid #34344a;
  border-radius: 8px;
  padding: 7px 8px;
  margin-bottom: 6px;
  font-size: 13px;
}
.preset-row .p-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: default; }
.preset-row button {
  background: none;
  border: 1px solid #3a3a4e;
  border-radius: 5px;
  color: var(--text);
  cursor: pointer;
  padding: 3px 5px;
  font-size: 12px;
  flex-shrink: 0;
}
.preset-row button:hover:not(:disabled) { border-color: var(--accent); }
.preset-row button:disabled { opacity: .3; cursor: default; }
.preset-row .p-apply { border-color: var(--accent); }
.preset-row.is-active {
  border-color: var(--accent);
  background: #2a2637;
  box-shadow: inset 0 0 0 1px rgba(201, 162, 39, 0.25);
}
.preset-row.is-active .p-name { color: var(--accent); font-weight: 600; }
.preset-row .p-apply.is-active {
  background: var(--accent);
  color: #1a1408;
  border-color: var(--accent);
}

.preset-tip {
  display: none;
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: calc(100% + 6px);
  z-index: 50;
  padding: 6px 10px;
  background: #1e1e2a;
  border: 1px solid var(--accent);
  border-radius: 8px;
  color: var(--text);
  font-size: 12px;
  line-height: 1.35;
  white-space: normal;
  word-break: break-word;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}
.preset-row.has-tip:hover .preset-tip {
  display: block;
}

/* Звук */
.sfx-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 10px;
}
.sfx-grid button {
  padding: 10px 0;
  font-size: 20px;
  background: var(--panel2);
  border: 1px solid #34344a;
  border-radius: 8px;
  cursor: pointer;
}
.sfx-grid button:hover { border-color: var(--accent); }
.sfx-grid button:active { transform: scale(.93); }

.ghost-btn {
  width: 100%;
  padding: 8px;
  margin-bottom: 8px;
  background: var(--panel2);
  border: 1px solid #34344a;
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}
.ghost-btn:hover { border-color: var(--accent); }

.track-row {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--panel2);
  border-radius: 8px;
  padding: 6px 10px;
  margin-bottom: 6px;
  font-size: 12px;
}
.track-row .t-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.track-row button {
  background: none;
  border: 1px solid #3a3a4e;
  border-radius: 5px;
  color: var(--text);
  cursor: pointer;
  padding: 3px 8px;
}
.track-row button:hover { border-color: var(--accent); }
.track-row .t-loop.on { border-color: var(--accent); background: #2a2637; }

/* Трансляция */
.stream-input {
  width: 100%;
  margin-bottom: 6px;
  padding: 7px 10px;
  background: var(--panel2);
  border: 1px solid #34344a;
  border-radius: 6px;
  color: var(--text);
  font-size: 12px;
}
.wide-btn.live { background: #16a34a; }
#streamStatus { min-height: 14px; }

/* Чистая сцена для захвата в трансляцию (?clean=1) */
body.clean #statusBar { display: none; }
body.clean #stageWrap { padding: 0; }
body.clean #stage {
  width: 100vw;
  max-width: calc(100vh * 16 / 9);
  border-radius: 0;
  box-shadow: none;
}
.clean-join {
  width: 100%;
  padding: 16px;
  background: var(--accent);
  color: #1a1408;
  border: none;
  border-radius: 10px;
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
}

body.dialog-open { overflow: hidden; }

/* ---------- Модальное окно ---------- */
.app-dialog {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.app-dialog-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
}
.app-dialog-card {
  position: relative;
  width: min(100%, 380px);
  background: var(--panel);
  border: 1px solid #3a3a50;
  border-radius: 14px;
  padding: 22px 22px 18px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.55);
}
.app-dialog-card h3 {
  font-size: 17px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text);
}
.app-dialog-msg {
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 14px;
  line-height: 1.45;
}
.app-dialog-input {
  display: block;
  width: 100%;
  margin-bottom: 16px;
  padding: 10px 12px;
  background: var(--panel2);
  border: 1px solid #34344a;
  border-radius: 8px;
  color: var(--text);
  font-size: 15px;
}
.app-dialog-input:focus {
  outline: none;
  border-color: var(--accent);
}
.app-dialog-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}
.app-dialog-actions .ghost-btn,
.app-dialog-actions .wide-btn {
  width: auto;
  min-width: 96px;
  padding: 9px 16px;
  font-size: 14px;
}

/* ---------- Статус-бар ---------- */
#statusBar {
  position: fixed;
  left: 0;
  bottom: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 14px;
  background: rgba(13, 13, 20, 0.94);
  border-top: 1px solid #23232f;
  font-size: 13px;
  color: var(--muted);
  z-index: 2000;
  box-sizing: border-box;
}
.status-main {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 10px;
  min-width: 0;
  flex: 1;
}
.status-end {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
#roomLabel {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: min(42vw, 320px);
}
#inviteBtn {
  background: var(--panel2);
  border: 1px solid #34344a;
  color: var(--text);
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
  font-size: 12px;
}
#inviteBtn:hover { border-color: var(--accent); }
.exit-btn {
  background: rgba(32, 18, 18, 0.95);
  border: 1px solid #4a3030;
  color: #c0a0a0;
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 12px;
  white-space: nowrap;
}
.exit-btn:hover { border-color: #c06060; color: #e8c0c0; }
#micBtn {
  background: var(--panel2);
  border: 1px solid #34344a;
  color: var(--text);
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
  font-size: 14px;
}
#micBtn:hover { border-color: var(--accent); }
#micBtn.mic-muted { border-color: #8a3030; background: #2a1a1a; }
#hearBtn {
  background: var(--panel2);
  border: 1px solid #34344a;
  color: var(--text);
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
  font-size: 12px;
}
#hearBtn:hover { border-color: var(--accent); }
#hearBtn.off { border-color: #8a3030; background: #2a1a1a; color: #f0a0a0; }
.wide-btn.mic-muted { border-color: #8a3030; background: #2a1a1a; color: #f0a0a0; }
.actor .name-tag.is-muted { opacity: 1; color: #f0a0a0; }
#segStatus {
  font-size: 12px;
  color: #9ab89a;
  white-space: nowrap;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
}
