:root {
  --bg: #121316;
  --bg-2: #1b1d22;
  --bg-3: #262930;
  --bg-4: #343842;
  --fg: #e8eaed;
  --fg-dim: #9aa0a6;
  --accent: #8ab4f8;
  --accent-ink: #0b1a33;
  --green: #34d058;
  --red: #ea4335;
  --red-dim: #5c2420;
  --radius: 12px;
  --ctrl-h: 76px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); font-family: var(--font); overflow-x: hidden; }
body { font-size: 15px; line-height: 1.4; }
[hidden] { display: none !important; }
a { color: var(--accent); }
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- generic cards / forms (landing + prejoin) ---------- */
.center-page { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.card { width: 100%; max-width: 440px; background: var(--bg-2); border-radius: 16px; padding: 28px 24px; box-shadow: 0 8px 32px rgba(0,0,0,.4); }
.card h1 { margin: 0 0 6px; font-size: 26px; }
.card p.lead { margin: 0 0 22px; color: var(--fg-dim); }
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; color: var(--fg-dim); margin-bottom: 4px; }
.field input[type=text], .field select {
  width: 100%; padding: 11px 12px; background: var(--bg-3); border: 1px solid var(--bg-4); border-radius: 8px;
}
.check { display: flex; align-items: center; gap: 8px; margin: 6px 0; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 11px 18px; border: 0; border-radius: 999px; background: var(--bg-3); font-weight: 600; text-decoration: none; color: var(--fg); }
.btn:hover { background: var(--bg-4); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
.divider { text-align: center; color: var(--fg-dim); margin: 18px 0; font-size: 13px; }
.row { display: flex; gap: 8px; }
.row input { flex: 1; min-width: 0; padding: 11px 12px; background: var(--bg-3); border: 1px solid var(--bg-4); border-radius: 8px; }
.error { color: #ff8a80; min-height: 1.4em; margin-top: 10px; font-size: 14px; }
.note { color: var(--fg-dim); font-size: 13px; margin-top: 14px; }

/* ---------- meeting layout ---------- */
#meeting { height: 100dvh; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 14px; font-size: 13px; color: var(--fg-dim); }
.topbar .room-code { font-weight: 600; color: var(--fg); letter-spacing: .5px; }
.conn { display: inline-flex; align-items: center; gap: 6px; }
.conn::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--green); }
.conn.connecting::before, .conn.reconnecting::before { background: #fbbc04; }
.conn.disconnected::before { background: var(--red); }

.stage { position: relative; flex: 1; min-height: 0; display: flex; gap: 8px; padding: 0 8px 8px; }
.spotlight { flex: 1 1 auto; min-width: 0; position: relative; background: #000; border-radius: var(--radius); overflow: hidden; display: none; }
.stage.has-share .spotlight { display: block; }
.spotlight video { width: 100%; height: 100%; object-fit: contain; background: #000; }
.spot-label { position: absolute; left: 10px; top: 10px; background: rgba(0,0,0,.6); padding: 4px 10px; border-radius: 6px; font-size: 13px; }

.grid { flex: 1 1 auto; min-width: 0; display: grid; gap: 8px; grid-template-columns: 1fr; align-content: center; overflow-y: auto; }
.grid[data-count="2"], .grid[data-count="3"], .grid[data-count="4"] { grid-template-columns: repeat(2, 1fr); }
.grid[data-count="5"], .grid[data-count="6"], .grid[data-count="7"], .grid[data-count="8"] { grid-template-columns: repeat(3, 1fr); }
.grid[data-count="1"] { max-width: 960px; margin: 0 auto; width: 100%; }
.stage.has-share .grid { flex: 0 0 220px; grid-template-columns: 1fr !important; align-content: start; max-width: none; margin: 0; }

.tile { position: relative; background: var(--bg-3); border-radius: var(--radius); overflow: hidden; aspect-ratio: 16 / 9; display: flex; align-items: center; justify-content: center; outline: 3px solid transparent; transition: outline-color .15s; }
.tile.speaking { outline-color: var(--green); }
.tile video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; }
.tile.local video { transform: scaleX(-1); }
.avatar { width: min(30%, 96px); min-width: 48px; aspect-ratio: 1; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: flex; align-items: center; justify-content: center; font-size: clamp(18px, 3vw, 32px); font-weight: 700; }
.tile .label { position: absolute; left: 8px; bottom: 8px; right: 8px; display: flex; align-items: center; gap: 6px; font-size: 13px; pointer-events: none; }
.tile .label .nm { background: rgba(0,0,0,.6); padding: 2px 8px; border-radius: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.tile .mic-off { background: var(--red); border-radius: 50%; width: 22px; height: 22px; display: none; align-items: center; justify-content: center; flex: none; }
.tile.muted .mic-off { display: flex; }
.tile .mic-off svg { width: 13px; height: 13px; fill: #fff; }

/* subtitles */
.subs { position: absolute; left: 50%; transform: translateX(-50%); bottom: 18px; width: min(900px, calc(100% - 32px)); display: flex; flex-direction: column; gap: 4px; align-items: center; pointer-events: none; z-index: 5; }
.sub-line { background: rgba(0,0,0,.72); padding: 6px 14px; border-radius: 8px; font-size: clamp(16px, 2.4vw, 24px); line-height: 1.35; text-align: center; max-width: 100%; transition: opacity .8s; word-break: break-word; }
.sub-line .who { color: var(--accent); font-weight: 600; margin-right: 6px; font-size: .75em; }
.sub-line.partial .txt { opacity: .75; font-style: italic; }
.sub-line.fade { opacity: 0; }
.sub-line.older { opacity: .8; }
.sub-line.older.fade { opacity: 0; }

/* controls */
.controls { flex: none; display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 6px 8px; padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); background: var(--bg-2); }
.cbtn { position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 56px; padding: 6px 8px; background: transparent; border: 0; border-radius: 10px; font-size: 11px; color: var(--fg); }
.cbtn:hover { background: var(--bg-3); }
.cbtn .ico { width: 40px; height: 40px; border-radius: 50%; background: var(--bg-3); display: flex; align-items: center; justify-content: center; }
.cbtn svg { width: 20px; height: 20px; fill: currentColor; }
.cbtn.off .ico { background: var(--red-dim); color: #ffb4ab; }
.cbtn.on .ico { background: var(--accent); color: var(--accent-ink); }
.cbtn.danger .ico { background: var(--red); color: #fff; }
.cbtn .badge { position: absolute; top: 2px; right: 8px; background: var(--accent); color: var(--accent-ink); border-radius: 999px; font-size: 10px; font-weight: 700; min-width: 17px; height: 17px; display: flex; align-items: center; justify-content: center; padding: 0 4px; }
.lang-ctl { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; }
.lang-ctl .grp { display: flex; align-items: center; gap: 4px; }
.lang-ctl select { background: var(--bg-3); border: 1px solid var(--bg-4); border-radius: 8px; padding: 6px 4px; font-size: 13px; max-width: 120px; }

/* panels */
.panel { position: absolute; top: 0; right: 8px; bottom: 8px; width: 340px; max-width: calc(100% - 16px); background: var(--bg-2); border-radius: var(--radius); box-shadow: 0 8px 32px rgba(0,0,0,.5); z-index: 20; display: flex; flex-direction: column; }
.panel header { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid var(--bg-3); font-weight: 600; gap: 8px; }
.panel .x { background: transparent; border: 0; font-size: 22px; line-height: 1; padding: 2px 8px; border-radius: 6px; }
.panel .x:hover { background: var(--bg-3); }
.panel .body { flex: 1; min-height: 0; overflow-y: auto; padding: 8px 14px; }
.panel .foot { padding: 10px 14px; border-top: 1px solid var(--bg-3); display: flex; flex-direction: column; gap: 8px; }
.btn.small { padding: 6px 12px; font-size: 13px; }
.person { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--bg-3); }
.person .pname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person .tag { font-size: 11px; background: var(--bg-3); border-radius: 4px; padding: 1px 6px; color: var(--fg-dim); }
.person .tag.host { background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.person .st { display: inline-flex; gap: 4px; color: var(--fg-dim); }
.person .st svg { width: 16px; height: 16px; fill: currentColor; }
.person .st .bad { color: #ff8a80; }
.tline { margin-bottom: 10px; word-break: break-word; }
.tline .t { color: var(--fg-dim); font-size: 12px; margin-right: 4px; }
.tline .who { font-weight: 600; }
.tline .orig { color: var(--fg-dim); font-size: 13px; margin-left: 10px; font-style: italic; }
.empty { color: var(--fg-dim); padding: 16px 0; text-align: center; }

/* toasts */
.toasts { position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; width: calc(100% - 24px); max-width: 480px; pointer-events: none; }
.toast { background: var(--bg-4); color: var(--fg); padding: 10px 16px; border-radius: 10px; box-shadow: 0 4px 16px rgba(0,0,0,.5); font-size: 14px; pointer-events: auto; }
.toast.err { background: #5c2420; }
.audio-banner { position: fixed; bottom: 100px; left: 50%; transform: translateX(-50%); z-index: 90; }

@media (max-width: 760px) {
  .stage.has-share { flex-direction: column; }
  .stage.has-share .grid { flex: 0 0 110px; grid-template-columns: repeat(4, 1fr) !important; overflow-y: hidden; overflow-x: auto; }
  .stage.has-share .tile { min-width: 96px; }
  .stage.has-share .spotlight { flex: 1 1 0; min-height: 0; }
  .panel { inset: 0; width: auto; max-width: none; border-radius: 0; }
}
@media (max-width: 600px) {
  .grid[data-count="2"] { grid-template-columns: 1fr; }
  .grid[data-count="3"], .grid[data-count="4"], .grid[data-count="5"], .grid[data-count="6"], .grid[data-count="7"], .grid[data-count="8"] { grid-template-columns: repeat(2, 1fr); }
  .tile { aspect-ratio: 4 / 3; }
  .cbtn { min-width: 44px; padding: 4px; }
  .cbtn .lbl { display: none; }
  .cbtn .badge { right: 0; }
  .lang-ctl .cap { display: none; }
  .sub-line { font-size: 17px; }
}
