/* Roundtable — layout: lobby is a two-column "preview + join card" that stacks on
   phones; the call is a full-height dark stage with an auto-fitting tile grid,
   a slide-in chat column and a bottom control dock. */
:root {
  --bg: #f3f1ee;
  --surface: #ffffff;
  --fg: #1d2226;
  --muted: #5f676e;
  --line: #dcd8d2;
  --accent: #c2662f;
  --accent-ink: #ffffff;
  --accent-soft: #f6e3d6;
  --danger: #c93a32;
  --ok: #2f8a5b;
  /* the meeting stage stays dark in both themes, like a dimmed room */
  --stage: #12161a;
  --stage-2: #1a2026;
  --tile: #222a31;
  --tile-fg: #eef1f3;
  --tile-muted: #9aa5ae;
  --dock: #1a2026;
  --speak: #f0a46c;

  --display: "Bricolage Grotesque", "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --body: "Figtree", "Segoe UI", system-ui, -apple-system, sans-serif;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15191d; --surface: #1e242a; --fg: #ecefF1; --muted: #9ba5ad; --line: #2e363d;
    --accent: #e0915a; --accent-ink: #1a1208; --accent-soft: #3a2a1f;
    --danger: #e45a50; --ok: #4fb985; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15191d; --surface: #1e242a; --fg: #eceff1; --muted: #9ba5ad; --line: #2e363d;
  --accent: #e0915a; --accent-ink: #1a1208; --accent-soft: #3a2a1f;
  --danger: #e45a50; --ok: #4fb985; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 var(--body);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- brand ---------- */
.brand { display: flex; align-items: center; gap: 10px; }
.brand-name { font: 700 20px/1 var(--display); letter-spacing: -0.01em; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 50%;
  border: 5px solid var(--accent); position: relative; flex: none;
}
.brand-mark::after { content: ""; position: absolute; inset: 5px; border-radius: 50%; background: var(--accent); }
.brand-mark.sm { width: 18px; height: 18px; border-width: 3.5px; }
.brand-mark.sm::after { inset: 3px; }
.brand-mark.lg { width: 56px; height: 56px; border-width: 9px; }
.brand-mark.lg::after { inset: 11px; }

/* ---------- buttons ---------- */
.primary, .ghost {
  border-radius: 999px; padding: 11px 22px; font-weight: 600; border: 1px solid transparent;
  transition: background .15s, border-color .15s, transform .1s;
}
.primary { background: var(--accent); color: var(--accent-ink); }
.primary:hover { filter: brightness(1.06); }
.primary:active { transform: translateY(1px); }
.primary:disabled { opacity: .6; cursor: progress; }
.primary.sm { padding: 8px 16px; }
.ghost { background: transparent; border-color: var(--line); }
.ghost:hover { border-color: var(--muted); }

/* ---------- lobby ---------- */
.lobby { max-width: 1120px; margin: 0 auto; padding: 24px 20px 48px; min-height: 100%; display: flex; flex-direction: column; gap: 32px; }
.lobby-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 40px; align-items: start; flex: 1; }
@media (max-width: 820px) { .lobby-grid { grid-template-columns: 1fr; gap: 24px; } }

.join-col h1 { font: 700 clamp(34px, 5vw, 52px)/1.02 var(--display); letter-spacing: -0.025em; margin: 8px 0 12px; text-wrap: balance; }
.lede { color: var(--muted); margin: 0 0 28px; max-width: 42ch; }
.join-form { display: grid; gap: 6px; }
.join-form label { font-size: 13px; font-weight: 600; letter-spacing: .02em; margin-top: 10px; }
.join-form input, .device-fields select, .device-fields input, .dlg input {
  width: 100%; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); min-width: 0;
}
.code-row { display: flex; gap: 8px; }
.code-row input { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: .04em; }
.hint { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.join-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.form-error { color: var(--danger); margin: 10px 0 0; font-weight: 500; }

.tile {
  position: relative; background: var(--tile); color: var(--tile-fg);
  border-radius: var(--radius); overflow: hidden; isolation: isolate;
}
.preview { aspect-ratio: 16 / 9; width: 100%; max-width: 100%; }
.preview video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); display: block; }
.preview-msg {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center;
  padding: 24px; color: var(--tile-muted); font-size: 14px;
}
.preview-controls { position: absolute; left: 0; right: 0; bottom: 14px; display: flex; justify-content: center; gap: 12px; z-index: 2; }
.round {
  width: 48px; height: 48px; border-radius: 50%; border: 0; display: grid; place-items: center;
  background: rgba(255,255,255,.16); color: #fff; backdrop-filter: blur(8px);
}
.round[aria-pressed="false"] { background: var(--danger); }
.round svg, .ctl svg { width: 22px; height: 22px; }
.meter { position: absolute; left: 14px; top: 14px; width: 6px; height: 46px; border-radius: 3px; background: rgba(255,255,255,.18); overflow: hidden; z-index: 2; }
.meter i { position: absolute; left: 0; right: 0; bottom: 0; height: 0%; background: var(--speak); transition: height .08s linear; }

.devices { margin-top: 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.devices summary { padding: 12px 16px; cursor: pointer; font-weight: 600; font-size: 14px; }
.device-fields { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 10px 14px; align-items: center; padding: 4px 16px 16px; }
.device-fields label { font-size: 13px; color: var(--muted); }
.device-fields select { padding: 9px 12px; }
@media (max-width: 480px) { .device-fields { grid-template-columns: 1fr; gap: 4px; } .device-fields select { margin-bottom: 8px; } }

/* ---------- avatar (camera off) ---------- */
.avatar { position: absolute; inset: 0; display: grid; place-items: center; background: var(--tile); }
.avatar span {
  width: clamp(56px, 26%, 120px); aspect-ratio: 1; border-radius: 50%; display: grid; place-items: center;
  font: 700 clamp(20px, 4vw, 40px)/1 var(--display); color: #1d1410; background: var(--av, #e0915a);
}

/* ---------- call ---------- */
.call {
  position: fixed; inset: 0; display: flex; flex-direction: column;
  background: var(--stage); color: var(--tile-fg);
  padding-top: env(safe-area-inset-top, 0px);
}
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 16px; min-height: 52px; }
.tb-left, .tb-right { display: flex; align-items: center; gap: 10px; min-width: 0; }
.room-code { font: 600 15px/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sep { color: var(--tile-muted); }
.timer { font-variant-numeric: tabular-nums; color: var(--tile-muted); font-size: 14px; }
.count { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--tile-muted); font-variant-numeric: tabular-nums; }
.count::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.chip { background: var(--stage-2); border: 1px solid #2d363e; border-radius: 999px; padding: 6px 14px; font-size: 13px; font-weight: 600; color: var(--tile-fg); }
.chip:hover { border-color: #4a5560; }

.call-body { flex: 1; min-height: 0; display: flex; gap: 12px; padding: 0 12px; }

.stage {
  flex: 1; min-width: 0; min-height: 0; display: grid; gap: 10px;
  grid-template-columns: repeat(var(--cols, 1), minmax(0, 1fr));
  grid-auto-rows: minmax(0, 1fr);
  align-content: center;
}
.stage.spotlight { grid-template-columns: minmax(0, 1fr) 220px; grid-template-rows: none; grid-auto-rows: auto; }
.stage.spotlight .ptile.pinned { grid-column: 1; grid-row: 1 / span 20; }
.stage.spotlight .ptile:not(.pinned) { grid-column: 2; aspect-ratio: 16/9; }
@media (max-width: 760px) {
  .stage.spotlight { grid-template-columns: repeat(3, minmax(0, 1fr)); grid-template-rows: minmax(0, 1fr); grid-auto-rows: auto; align-content: stretch; }
  .stage.spotlight .ptile.pinned { grid-column: 1 / -1; grid-row: auto; order: -1; }
  .stage.spotlight .ptile:not(.pinned) { grid-column: auto; aspect-ratio: auto; height: 96px; }
  .stage.spotlight .ptile:not(.pinned) .tag { left: 6px; bottom: 6px; padding: 3px 7px; font-size: 11.5px; }
  .stage.spotlight .ptile:not(.pinned) .hand { top: 6px; left: 6px; padding: 2px 7px; font-size: 11px; }
  .stage.spotlight .ptile:not(.pinned) .avatar span { width: 44px; font-size: 17px; }
}

.ptile { min-height: 0; cursor: pointer; outline: 2px solid transparent; transition: outline-color .15s; }
.ptile video { width: 100%; height: 100%; object-fit: cover; display: block; background: #0b0e11; }
.ptile.me video.mirror { transform: scaleX(-1); }
.ptile.screen video { object-fit: contain; }
.ptile.speaking { outline-color: var(--speak); }
.ptile .tag {
  position: absolute; left: 10px; bottom: 10px; z-index: 2; max-width: calc(100% - 20px);
  display: flex; align-items: center; gap: 6px; padding: 5px 10px 5px 8px; border-radius: 8px;
  background: rgba(10, 13, 16, .66); font-size: 13px; font-weight: 500; backdrop-filter: blur(6px);
}
.ptile .tag .nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ptile .tag svg { width: 15px; height: 15px; flex: none; }
.ptile .tag .muted-ic { color: #ff8a80; display: none; }
.ptile.mic-off .tag .muted-ic { display: block; }
.ptile .hand {
  position: absolute; top: 10px; left: 10px; z-index: 2; padding: 4px 10px; border-radius: 8px;
  background: var(--speak); color: #1d1410; font-weight: 700; font-size: 13px; display: none;
}
.ptile.hand-up .hand { display: block; animation: wave .9s ease-in-out 2; }
.ptile .net {
  position: absolute; top: 10px; right: 10px; z-index: 2; padding: 3px 8px; border-radius: 6px;
  font-size: 12px; background: rgba(10,13,16,.66); color: var(--tile-muted); display: none;
}
.ptile.connecting .net, .ptile.poor .net { display: block; }
.ptile .pin-hint { position: absolute; top: 10px; right: 10px; z-index: 2; opacity: 0; transition: opacity .15s; font-size: 12px; padding: 3px 8px; border-radius: 6px; background: rgba(10,13,16,.66); }
.ptile:hover .pin-hint { opacity: 1; }
.ptile.connecting .pin-hint, .ptile.poor .pin-hint { display: none; }
.ptile .burst { position: absolute; inset: auto 0 22% 0; z-index: 3; text-align: center; font-size: 46px; pointer-events: none; animation: rise 2.2s ease-out forwards; }
@keyframes rise { from { transform: translateY(20px) scale(.6); opacity: 0; } 15% { opacity: 1; transform: none; } to { transform: translateY(-60px); opacity: 0; } }
@keyframes wave { 50% { transform: rotate(-8deg); } }
@media (prefers-reduced-motion: reduce) { .ptile .burst, .ptile.hand-up .hand { animation: none; } }

/* ---------- chat ---------- */
.chat {
  width: 340px; flex: none; display: flex; flex-direction: column; min-height: 0;
  background: var(--stage-2); border-radius: var(--radius); overflow: hidden;
}
.chat-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px 6px 16px; }
.chat-head h2 { margin: 0; font: 700 17px/1 var(--display); }
.icon-btn { background: none; border: 0; font-size: 26px; line-height: 1; color: var(--tile-muted); padding: 2px 8px; border-radius: 8px; }
.icon-btn:hover { color: var(--tile-fg); }
.people { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 16px 10px; border-bottom: 1px solid #2b333a; }
.people .pp { font-size: 12px; padding: 3px 9px; border-radius: 999px; background: var(--tile); color: var(--tile-muted); }
.people .pp.raised { background: var(--speak); color: #1d1410; font-weight: 600; }
.messages { list-style: none; margin: 0; padding: 12px 16px; flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.messages li { min-width: 0; }
.messages .meta { font-size: 12px; color: var(--tile-muted); display: flex; gap: 8px; }
.messages .meta b { color: var(--tile-fg); font-weight: 600; }
.messages .body { white-space: pre-wrap; overflow-wrap: anywhere; margin-top: 2px; }
.messages .body a { color: var(--speak); }
.messages .sys { font-size: 12px; color: var(--tile-muted); text-align: center; }
.messages .empty { color: var(--tile-muted); font-size: 13px; margin: auto 0; text-align: center; }
.chat-form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid #2b333a; align-items: flex-end; }
.chat-form textarea {
  flex: 1; min-width: 0; resize: none; max-height: 120px; padding: 9px 12px; border-radius: 10px;
  border: 1px solid #2f3840; background: var(--tile); color: var(--tile-fg);
}
@media (max-width: 760px) {
  .chat { position: fixed; inset: auto 0 0 0; top: calc(env(safe-area-inset-top, 0px) + 52px); width: auto; z-index: 20; border-radius: 16px 16px 0 0; padding-bottom: env(safe-area-inset-bottom, 0px); }
}

/* ---------- control dock ---------- */
.controls {
  display: flex; justify-content: center; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 12px 12px calc(12px + env(safe-area-inset-bottom, 0px));
}
.ctl {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px;
  min-width: 64px; padding: 9px 10px 7px; border-radius: 14px; border: 0;
  background: var(--dock); color: var(--tile-fg);
}
.ctl:hover { background: #262e35; }
.ctl .lbl { font-size: 11.5px; font-weight: 500; color: var(--tile-muted); }
.ctl[aria-pressed="false"]#micBtn, .ctl[aria-pressed="false"]#camBtn { background: var(--danger); }
.ctl[aria-pressed="false"]#micBtn .lbl, .ctl[aria-pressed="false"]#camBtn .lbl { color: #fff; }
.ctl[aria-pressed="true"]#shareBtn, .ctl[aria-pressed="true"]#handBtn, .ctl[aria-pressed="true"]#chatBtn { background: var(--speak); color: #1d1410; }
.ctl[aria-pressed="true"] .lbl { color: inherit; }
.ctl.leave { background: var(--danger); color: #fff; }
.ctl.leave .lbl { color: #fff; }
.badge { position: absolute; top: 4px; right: 8px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--speak); color: #1d1410; font-size: 11px; line-height: 18px; }
.react-wrap { position: relative; }
.react-menu {
  position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%);
  display: flex; gap: 2px; padding: 6px; border-radius: 999px; background: var(--stage-2); border: 1px solid #2d363e; z-index: 30;
}
.react-menu button { background: none; border: 0; font-size: 24px; padding: 4px 6px; border-radius: 50%; }
.react-menu button:hover { background: var(--tile); }
@media (max-width: 560px) {
  .controls { gap: 4px; padding-inline: 6px; }
  .ctl { min-width: 0; flex: 1 1 0; max-width: 64px; padding: 8px 4px 6px; }
  .ctl .lbl { font-size: 10.5px; }
  .react-wrap { display: none; }
  .topbar .sep, .topbar .timer { display: none; }
}

/* ---------- dialog / toast / left ---------- */
.dlg { border: 0; border-radius: 16px; padding: 0; width: min(460px, calc(100vw - 32px)); background: var(--surface); color: var(--fg); }
.dlg::backdrop { background: rgba(8, 10, 12, .6); }
.dlg form { padding: 20px 22px; display: grid; gap: 8px; }
.dlg h2 { margin: 0 0 6px; font: 700 20px/1.2 var(--display); }
.dlg .device-fields { padding: 0 0 8px; }
.dlg label { font-size: 13px; color: var(--muted); }
.dlg-actions { display: flex; justify-content: flex-end; margin-top: 12px; }

.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  background: #0d1013; color: #eef1f3; padding: 10px 18px; border-radius: 10px; font-size: 14px; z-index: 50;
  max-width: calc(100vw - 32px); pointer-events: none; box-shadow: 0 8px 30px rgba(0,0,0,.3);
}

.left-screen { min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 10px; padding: 32px 20px; }
.left-screen h1 { font: 700 34px/1.1 var(--display); margin: 14px 0 0; }
.left-screen p { color: var(--muted); margin: 0; }
