:root {
  --bg: #111317; --panel: #181b21; --panel2: #1f232b; --line: #2a2f39;
  --text: #e8eaf0; --muted: #8b93a3; --accent: #5b8cff; --green: #3ecf6e; --red: #ef5350;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; }
button, input, select { font: inherit; color: inherit; }
button { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; cursor: pointer; }
button:hover { border-color: #3a4150; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
input, select { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type=checkbox], input[type=radio] { width: auto; }
.hint { color: var(--muted); font-size: 12px; }
.error { color: var(--red); min-height: 1em; margin: 0; }
[hidden] { display: none !important; }

/* join */
.join { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; width: min(380px, 100%); display: grid; gap: 14px; }
.card h1 { margin: 0 0 6px; font-size: 22px; }
.card label { display: grid; gap: 6px; color: var(--muted); }
.card button.primary { padding: 10px; }

/* layout */
.app { display: grid; grid-template-columns: 260px 1fr 340px; height: 100vh; height: 100dvh; }
.people, .chat { background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.people { border-right: 1px solid var(--line); }
.chat { border-left: 1px solid var(--line); position: relative; }
.people header { padding: 14px 16px; font-weight: 700; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; }
.count { color: var(--muted); font-weight: 400; }
#peopleList { list-style: none; margin: 0; padding: 8px; overflow-y: auto; flex: 1; display: grid; gap: 4px; align-content: start; }
#peopleList li { padding: 8px; border-radius: 10px; display: grid; gap: 6px; }
#peopleList li:hover { background: var(--panel2); }
.p-top { display: flex; align-items: center; gap: 10px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; flex: none; box-shadow: 0 0 0 2px transparent; transition: box-shadow .1s; }
li.speaking .avatar { box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--green); }
.p-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.p-q { font-size: 8px; letter-spacing: 1px; color: var(--green); }
.p-q.good { color: #c8d14a; } .p-q.poor, .p-q.lost { color: var(--red); }
.watch { font-size: 12px; padding: 4px 8px; text-align: left; }
.watch.on { border-color: var(--accent); color: var(--accent); }
.vol { padding: 0; height: 14px; accent-color: var(--accent); }
.me { border-top: 1px solid var(--line); padding: 10px; display: grid; gap: 6px; }
.me-row { display: flex; gap: 6px; justify-content: space-between; }
.icon { width: 42px; height: 38px; padding: 0; font-size: 17px; display: grid; place-items: center; }
.icon.off { background: #3a1f22; border-color: var(--red); }
.icon.on { background: #1d2c4d; border-color: var(--accent); }
.icon.danger:hover { background: var(--red); }
.ptt-hint, .conn { text-align: center; color: var(--muted); font-size: 12px; }
.conn:empty { display: none; }

/* stage */
.stage { min-width: 0; min-height: 0; display: grid; background: #0b0c0f; }
.stage-empty { place-self: center; text-align: center; color: var(--muted); display: grid; gap: 6px; padding: 16px; }
.viewer { display: flex; flex-direction: column; min-height: 0; background: #000; }
.viewer-bar { display: flex; gap: 8px; align-items: center; padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--line); }
.viewer-bar .spacer { flex: 1; }
.stats { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
#viewerVideo { flex: 1; min-height: 0; width: 100%; object-fit: contain; background: #000; }
.viewer:fullscreen .viewer-bar { opacity: 0; transition: opacity .2s; position: absolute; inset: 0 0 auto; z-index: 1; }
.viewer:fullscreen:hover .viewer-bar { opacity: 1; }

/* chat */
.messages { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; }
.msg { padding: 2px 4px; }
.msg:not(.grouped) { margin-top: 10px; }
.msg-head { display: flex; gap: 8px; align-items: baseline; }
.msg-head time { color: var(--muted); font-size: 11px; }
.msg-text { white-space: pre-wrap; word-wrap: break-word; }
.msg-text a { color: var(--accent); }
.msg img.media { max-width: 100%; max-height: 260px; border-radius: 8px; margin-top: 4px; cursor: zoom-in; display: block; }
.msg img.sticker { width: 128px; height: 128px; object-fit: contain; margin-top: 4px; display: block; }
.typing { color: var(--muted); font-size: 12px; padding: 0 14px; min-height: 18px; }
.composer { display: flex; gap: 6px; padding: 10px; border-top: 1px solid var(--line); }
.composer .icon { width: 38px; flex: none; }
.chat.drop::after { content: "Drop to send"; position: absolute; inset: 0; display: grid; place-items: center; background: #5b8cff33; border: 2px dashed var(--accent); font-weight: 700; }

.picker { position: absolute; bottom: 60px; left: 8px; right: 8px; height: 380px; background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; display: flex; flex-direction: column; box-shadow: 0 10px 40px #0008; z-index: 5; }
.picker-tabs { display: flex; gap: 4px; padding: 8px; border-bottom: 1px solid var(--line); }
.picker-tabs button { border: none; background: none; }
.picker-tabs button.active { background: var(--bg); }
.picker-body { flex: 1; overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.grid { columns: 3 90px; column-gap: 6px; }
.grid img { width: 100%; border-radius: 6px; margin-bottom: 6px; cursor: pointer; display: block; break-inside: avoid; background: var(--bg); }
.grid img:hover { outline: 2px solid var(--accent); }
.grid.stickers { columns: 4 64px; }
.grid.stickers img { aspect-ratio: 1; object-fit: contain; background: none; }
.upload-btn { background: var(--bg); border: 1px dashed var(--line); border-radius: 8px; padding: 8px; text-align: center; cursor: pointer; }

/* dialogs */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 14px; padding: 22px; width: min(420px, calc(100% - 32px)); }
dialog::backdrop { background: #000a; }
dialog form { display: grid; gap: 12px; }
dialog h2 { margin: 0; font-size: 18px; }
dialog label { display: grid; gap: 6px; color: var(--muted); }
dialog label.check { display: flex; align-items: center; gap: 8px; color: var(--text); }
.options { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.options label { display: flex; gap: 8px; align-items: center; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px; cursor: pointer; }
.options label:has(input:checked) { border-color: var(--accent); }
.row { display: flex; gap: 8px; justify-content: flex-end; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--panel2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px; z-index: 50; box-shadow: 0 6px 24px #0008; cursor: default; max-width: calc(100% - 32px); }

/* small screens: stack, chat under the people list */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto auto 1fr; height: auto; min-height: 100dvh; }
  .people { border-right: none; border-bottom: 1px solid var(--line); max-height: 45vh; }
  .stage { min-height: 0; }
  .stage-empty { display: none; }
  .chat { border-left: none; min-height: 60vh; }
}
