:root { --bg:#0e1014; --tile:#1a1e27; --line:#2a3040; --txt:#e9ecf1; --mut:#8a93a6; --acc:#f5b342; --ok:#4ade80; --bad:#f87171; }
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--txt); font: 15px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button { font: inherit; color: var(--txt); background: #262c3a; border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; cursor: pointer; }
button:hover { background: #313849; }
button.on { background: #2f4a3a; border-color: var(--ok); }
button.off { background: #4a2f2f; border-color: var(--bad); }
button.danger { background: #4a2626; }
button.ghost { background: transparent; }
input { font: inherit; color: var(--txt); background: #12151c; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.grow { flex: 1; }
.small { color: var(--mut); font-size: 13px; }
.err { color: var(--bad); }
[hidden] { display: none !important; }

/* вход */
#join { height: 100%; display: flex; align-items: center; justify-content: center; }
#joinForm { width: 360px; max-width: 92vw; display: flex; flex-direction: column; gap: 12px; background: var(--tile); padding: 28px; border-radius: 16px; border: 1px solid var(--line); }
#joinForm h1 { margin: 0; letter-spacing: 2px; }
#joinForm p { margin: 0; }
#btnJoin { background: var(--acc); color: #111; font-weight: 600; border: 0; padding: 12px; }

/* приложение */
#app { height: 100%; display: grid; grid-template-columns: 1fr auto; grid-template-rows: 1fr auto; }
#stage { grid-column: 1; grid-row: 1; display: flex; flex-direction: column; min-height: 0; min-width: 0; }
#mainArea { flex: 1; position: relative; min-height: 0; }
#grid { position: absolute; inset: 8px; display: grid; grid-template-columns: repeat(var(--cols, 2), minmax(0, 1fr)); grid-auto-rows: minmax(0, 1fr); gap: 8px; }
#main { position: absolute; inset: 8px; }
#pip { position: absolute; right: 24px; bottom: 24px; width: 22%; min-width: 180px; aspect-ratio: 16/9; z-index: 3; box-shadow: 0 8px 30px rgba(0,0,0,.6); border-radius: 10px; }
#sceneTitle { position: absolute; left: 16px; top: 14px; z-index: 4; background: rgba(0,0,0,.55); padding: 4px 10px; border-radius: 8px; font-size: 13px; color: var(--mut); pointer-events: none; }
#sceneTitle:empty { display: none; }
#strip { height: 124px; display: flex; gap: 8px; padding: 0 8px 8px; overflow-x: auto; overflow-y: hidden; }
#strip .tile { flex: 0 0 auto; width: auto; height: 100%; aspect-ratio: 16/9; }

.tile { position: relative; background: var(--tile); border-radius: 10px; overflow: hidden; min-height: 0; min-width: 0; width: 100%; height: 100%; border: 2px solid transparent; }
.tile video { width: 100%; height: 100%; object-fit: cover; display: block; background: #000; }
.tile.screen video { object-fit: contain; }
.tile.mirror video { transform: scaleX(-1); }
.tile .ph { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; color: var(--mut); text-align: center; padding: 8px; font-size: 14px; }
.tile.empty .ph { display: flex; }
.tile.empty video { display: none; }
.tile .label { position: absolute; left: 8px; bottom: 6px; background: rgba(0,0,0,.55); padding: 2px 8px; border-radius: 6px; font-size: 13px; max-width: calc(100% - 16px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile.speaking { border-color: var(--ok); }
.tile .label .badge { color: var(--acc); }
.tile .label .mic { color: var(--bad); }

/* панель режиссёра */
#panel { grid-column: 2; grid-row: 1 / 3; width: 320px; border-left: 1px solid var(--line); padding: 12px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; background: #0b0d11; }
#panel h2, #panel h3 { margin: 4px 0; }
#panel h3 { margin-top: 10px; color: var(--mut); font-weight: 500; }
.grp { display: flex; flex-direction: column; gap: 6px; }
.grp.row { flex-direction: row; align-items: center; }
.grp.row input { flex: 1; min-width: 0; }
#sceneInfo { text-align: center; font-size: 13px; color: var(--mut); }
.prow { display: flex; align-items: center; gap: 6px; padding: 6px 0; border-bottom: 1px solid #161a22; flex-wrap: wrap; }
.prow .pn { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.prow .pn.speaking { color: var(--ok); }
.prow .st { color: var(--mut); font-size: 12px; }
.prow .acts { display: flex; gap: 4px; width: 100%; }
.prow .acts button { padding: 4px 6px; font-size: 13px; flex: 1; }
.prow .acts button.cur { border-color: var(--acc); }

/* нижняя панель */
#bar { grid-column: 1; grid-row: 2; display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-top: 1px solid var(--line); background: #0b0d11; }
#brand { font-weight: 700; letter-spacing: 2px; color: var(--acc); }
#meName { color: var(--mut); }
#stat { color: var(--mut); font-size: 13px; }

/* модалка и тосты */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.7); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal .box { background: var(--tile); border: 1px solid var(--line); border-radius: 16px; padding: 24px; width: 380px; max-width: 92vw; display: flex; flex-direction: column; gap: 10px; text-align: center; }
.modal .box h2 { margin: 0; }
#btnAskYes { background: var(--acc); color: #111; font-weight: 600; border: 0; padding: 12px; }
#toasts { position: fixed; top: 14px; left: 50%; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast { background: rgba(20,24,32,.95); border: 1px solid var(--acc); border-radius: 10px; padding: 10px 16px; font-size: 16px; box-shadow: 0 6px 24px rgba(0,0,0,.5); }
.toast.big { font-size: 22px; padding: 16px 28px; }

@media (max-width: 800px) {
  #app { grid-template-columns: 1fr; }
  #panel { display: none; }
  #strip { height: 84px; }
  #pip { width: 32%; min-width: 120px; }
}
