:root {
  --bg: #111317; --panel: #1b1e24; --panel2: #23272f; --line: #2e333d; --text: #e8eaed; --muted: #9aa0a6;
  --blue: #2d8cff; --blue2: #1f6fd6; --red: #e5484d; --green: #2fb36d; --amber: #f5a524;
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
input { font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px 12px; width: 100%; outline: none; }
input:focus { border-color: var(--blue); }
.muted { color: var(--muted); }
.error { color: var(--red); min-height: 1.2em; margin: 6px 0 0; }
.hint { color: var(--muted); font-size: 12.5px; }
.center { text-align: center; }
.small-text { font-size: 12px; }

.btn { padding: 9px 16px; border-radius: 8px; background: var(--panel2); border: 1px solid var(--line); font-weight: 600; }
.btn:hover { filter: brightness(1.15); }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.danger-outline { border-color: var(--red); color: #ff8a8d; background: transparent; }
.btn.small { padding: 5px 10px; font-size: 12.5px; }
.chip { font-size: 12px; padding: 4px 10px; border-radius: 99px; background: var(--panel2); border: 1px solid var(--line); }
.chip:hover { border-color: var(--blue); }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 20px; }
.brand.small { font-size: 15px; }
.logo { width: 30px; height: 30px; border-radius: 8px; background: var(--blue) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M5 8h9v8H5zM15 11l4-3v8l-4-3z' fill='white'/%3E%3C/svg%3E") center/70% no-repeat; }
.brand.small .logo { width: 24px; height: 24px; }

/* ---------- Lobby ---------- */
#lobby { min-height: 100%; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 600px at 20% 0%, #1a2a44 0%, transparent 60%), var(--bg); }
.lobby-card { display: grid; grid-template-columns: 1fr 1.2fr; gap: 32px; width: min(980px, 100%);
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 32px; }
.lobby-left h1 { margin: 22px 0 4px; font-size: 26px; }
.lobby-left label { display: grid; gap: 6px; margin-top: 16px; font-weight: 600; font-size: 13px; color: var(--muted); }
.row { display: flex; gap: 10px; margin-top: 20px; flex-wrap: wrap; }
.preview { position: relative; aspect-ratio: 16/9; background: #000; border-radius: var(--radius); overflow: hidden; }
.preview video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.preview-off { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); background: #0b0c0f; }
.preview-controls { position: absolute; left: 0; right: 0; bottom: 14px; display: flex; gap: 12px; justify-content: center; }
.round { width: 46px; height: 46px; border-radius: 50%; background: rgba(40,44,52,.85); display: grid; place-items: center; border: 1px solid #444; }
.round.off { background: var(--red); border-color: var(--red); }
.round svg { width: 22px; height: 22px; }
@media (max-width: 780px) { .lobby-card { grid-template-columns: 1fr; } .lobby-right { order: -1; } }

/* ---------- Meeting ---------- */
#meeting { height: 100%; display: flex; flex-direction: column; }
.topbar { height: 52px; display: flex; align-items: center; justify-content: space-between; padding: 0 16px; border-bottom: 1px solid var(--line); background: var(--panel); gap: 12px; }
.room-info { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.top-right { display: flex; align-items: center; gap: 14px; }
.rec-banner { background: rgba(229,72,77,.15); color: #ff8a8d; border: 1px solid rgba(229,72,77,.5); padding: 3px 10px; border-radius: 99px; font-size: 12.5px; font-weight: 600; }
.rec-banner::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--red); margin-right: 6px; animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: .25; } }

.main { flex: 1; display: flex; min-height: 0; }
.stage { flex: 1; min-width: 0; padding: 12px; display: flex; gap: 12px; }
.focus-area { display: none; }
.stage.mode-grid .grid { flex: 1; display: grid; gap: 10px; align-content: center; justify-content: center;
  grid-template-columns: repeat(var(--cols, 1), minmax(0, var(--tile-w, 1fr))); }
.stage.mode-focus .focus-area { display: flex; flex: 1; min-width: 0; }
.stage.mode-focus .grid { width: 220px; flex: none; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; }
.stage.mode-focus .grid .tile { width: 100%; flex: none; }

.tile { position: relative; aspect-ratio: 16/9; background: #0b0c0f; border-radius: var(--radius); overflow: hidden; border: 2px solid transparent; transition: border-color .15s; }
.tile.speaking { border-color: var(--green); }
.tile video { width: 100%; height: 100%; object-fit: cover; background: #000; display: block; }
.tile.self.mirror video { transform: scaleX(-1); }
.tile.screen video, .focus-area .tile video { object-fit: contain; }
.tile .avatar { position: absolute; inset: 0; display: none; place-items: center; background: #15171c; }
.tile .avatar span { width: 34%; max-width: 110px; aspect-ratio: 1; border-radius: 50%; display: grid; place-items: center; font-size: clamp(16px, 3vw, 38px); font-weight: 700; color: #fff; }
.tile.novideo .avatar { display: grid; }
.tile.novideo video { visibility: hidden; }
.tile .label { position: absolute; left: 8px; bottom: 8px; max-width: calc(100% - 16px); display: flex; align-items: center; gap: 6px;
  background: rgba(0,0,0,.6); padding: 3px 8px; border-radius: 6px; font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .label .mic-off { color: var(--red); display: none; }
.tile.muted .label .mic-off { display: inline; }
.tile .hand { position: absolute; top: 8px; left: 8px; font-size: 22px; display: none; filter: drop-shadow(0 1px 2px #000); }
.tile.hand-up .hand { display: block; }
.tile .status { position: absolute; top: 8px; right: 8px; font-size: 11px; background: rgba(0,0,0,.6); padding: 2px 8px; border-radius: 6px; color: var(--amber); }
.tile .pin { position: absolute; top: 8px; right: 8px; opacity: 0; background: rgba(0,0,0,.6); border-radius: 6px; padding: 2px 8px; font-size: 12px; }
.tile:hover .pin { opacity: 1; }
.tile .status:not(:empty) + .pin { display: none; }
.focus-area .tile { flex: 1; aspect-ratio: auto; height: 100%; }

.board-wrap { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--panel); border-radius: var(--radius); border: 1px solid var(--line); overflow: hidden; }
.board-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px; border-bottom: 1px solid var(--line); }
.tool-group { display: flex; gap: 4px; padding-right: 8px; border-right: 1px solid var(--line); }
.tool-group:last-of-type { border-right: 0; }
.tool { padding: 5px 10px; border-radius: 6px; background: var(--panel2); font-size: 12.5px; }
.tool.active { background: var(--blue); color: #fff; }
.swatch { width: 24px; height: 24px; border-radius: 50%; border: 2px solid transparent; }
.swatch.active { border-color: #fff; box-shadow: 0 0 0 2px var(--blue); }
.size { width: 28px; height: 28px; border-radius: 6px; background: var(--panel2); display: grid; place-items: center; }
.size i { display: block; border-radius: 50%; background: var(--text); }
.size.active { background: var(--blue); }
.board-holder { flex: 1; min-height: 0; display: grid; place-items: center; padding: 10px; background: #2a2e36; }
#board { background: #fff; max-width: 100%; max-height: 100%; aspect-ratio: 16/9; border-radius: 6px; touch-action: none; cursor: crosshair; box-shadow: 0 4px 20px rgba(0,0,0,.4); }
.board-wrap.locked #board { cursor: not-allowed; }

/* ---------- Side panel ---------- */
.side-panel { width: 330px; flex: none; border-left: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.panel-tabs { display: flex; border-bottom: 1px solid var(--line); }
.ptab { flex: 1; padding: 12px; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; }
.ptab.active { color: var(--text); border-color: var(--blue); }
.icon-x { width: 40px; font-size: 22px; color: var(--muted); }
.panel-body { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-list { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.msg .meta { font-size: 11.5px; color: var(--muted); }
.msg .meta b { color: var(--text); font-weight: 600; margin-right: 6px; }
.msg .text { white-space: pre-wrap; word-wrap: break-word; background: var(--panel2); padding: 7px 10px; border-radius: 8px; margin-top: 3px; display: inline-block; max-width: 100%; }
.msg.mine .text { background: #1d3a63; }
.msg.system { text-align: center; font-size: 12px; color: var(--muted); }
.chat-form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }
.host-actions { display: flex; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.people-list { list-style: none; margin: 0; padding: 6px 0; overflow-y: auto; }
.people-list li { display: flex; align-items: center; gap: 10px; padding: 8px 12px; }
.people-list li:hover { background: var(--panel2); }
.people-list .av { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 12px; color: #fff; flex: none; }
.people-list .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.people-list .nm small { color: var(--muted); margin-left: 4px; }
.people-list .icons { color: var(--muted); font-size: 13px; display: flex; gap: 6px; }
.people-list .icons .off { color: var(--red); }
.people-list li { flex-wrap: wrap; }
.people-list .acts { display: flex; gap: 4px; flex-wrap: wrap; width: 100%; padding-left: 40px; }
.people-list .acts button { font-size: 11.5px; padding: 3px 7px; border-radius: 5px; background: var(--panel2); border: 1px solid var(--line); }
.people-list .acts button.rm { color: #ff8a8d; }

/* ---------- Controls ---------- */
.controls { height: 72px; flex: none; display: flex; align-items: center; justify-content: space-between; padding: 0 16px; background: var(--panel); border-top: 1px solid var(--line); gap: 10px; }
.ctrl-group { display: flex; gap: 4px; align-items: center; }
.ctrl { position: relative; display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 70px; padding: 6px 8px; border-radius: 8px; color: var(--text); }
.ctrl:hover { background: var(--panel2); }
.ctrl .ic { width: 24px; height: 24px; display: grid; place-items: center; }
.ctrl .ic svg { width: 22px; height: 22px; }
.ctrl .lbl { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.ctrl.off .ic { color: var(--red); }
.ctrl.green .ic { color: var(--green); }
.ctrl.active { background: rgba(45,140,255,.15); }
.ctrl.active .ic, .ctrl.active .lbl { color: var(--blue); }
.ctrl.recording .ic, .ctrl.recording .lbl { color: var(--red); }
.badge { position: absolute; top: 2px; right: 14px; background: var(--red); color: #fff; font-size: 10.5px; min-width: 17px; height: 17px; border-radius: 9px; display: grid; place-items: center; padding: 0 4px; }
body:not(.is-host) .host-only { display: none !important; }
@media (max-width: 900px) {
  .ctrl { min-width: 48px; } .ctrl .lbl { display: none; }
  .side-panel { position: fixed; inset: 52px 0 72px auto; width: min(360px, 100%); z-index: 5; }
  .stage.mode-focus { flex-direction: column; }
  .stage.mode-focus .grid { width: auto; flex-direction: row; height: 110px; overflow-x: auto; }
  .stage.mode-focus .grid .tile { width: 180px; }
  .room-info #roomLabel { display: none; }
}

/* ---------- Overlay & toasts ---------- */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.7); display: grid; place-items: center; z-index: 20; }
.overlay-card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px 32px; text-align: center; max-width: 420px; }
.overlay-card h2 { margin: 0 0 8px; }
.toasts { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 30; align-items: center; pointer-events: none; }
.toast { background: #2b2f38; border: 1px solid var(--line); padding: 9px 16px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.4); animation: tin .2s ease; }
@keyframes tin { from { opacity: 0; transform: translateY(8px); } }
