/* 极简黑白：只有黑、白、灰。默认跟随系统，可手动切换。 */

:root {
  --bg: #000;
  --fg: #fff;
  --dim: #8c8c8c;
  --line: #2b2b2b;
  --surface: #0c0c0c;
  color-scheme: dark;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "PingFang SC",
    "Microsoft YaHei", sans-serif;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --bg: #fff;
    --fg: #000;
    --dim: #6e6e6e;
    --line: #dcdcdc;
    --surface: #f5f5f5;
    color-scheme: light;
  }
}

:root[data-theme="light"] {
  --bg: #fff;
  --fg: #000;
  --dim: #6e6e6e;
  --line: #dcdcdc;
  --surface: #f5f5f5;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font-size: 15px;
  font-weight: 400;
  line-height: 1.45;
}

button, input { font: inherit; color: inherit; border-radius: 0; }
button { cursor: pointer; }
button:disabled { opacity: 0.35; cursor: not-allowed; }
:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }

.icon {
  width: 22px;
  height: 22px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon.big { width: 40px; height: 40px; }

/* ---------- 主题切换按钮 ---------- */

.theme-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  background: none;
  border: 1px solid var(--line);
}
.theme-btn .icon { width: 16px; height: 16px; }
.theme-btn:hover { border-color: var(--fg); }
.lobby .theme-btn { position: fixed; top: 16px; right: 16px; }

/* ---------- 登录页 ---------- */

.lobby {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}

.card {
  width: min(100%, 380px);
  display: grid;
  gap: 18px;
}
.card h1 { margin: 0; font-size: 32px; font-weight: 300; letter-spacing: 0.04em; }
.card .sub { margin: -10px 0 8px; color: var(--dim); }

.field { display: grid; gap: 6px; }
.field > span { font-size: 12px; color: var(--dim); letter-spacing: 0.06em; }
.field input {
  padding: 10px 0;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--line);
}
.field input:focus { border-bottom-color: var(--fg); outline: none; }

.check { display: flex; align-items: center; gap: 8px; color: var(--dim); font-size: 14px; }
.check input { accent-color: var(--fg); }

.link {
  justify-self: start;
  margin-top: -10px;
  padding: 0;
  background: none;
  border: 0;
  color: var(--dim);
  font-size: 13px;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.link:hover { color: var(--fg); }

.primary {
  padding: 13px 16px;
  background: var(--fg);
  border: 1px solid var(--fg);
  color: var(--bg);
  letter-spacing: 0.08em;
}
.primary:hover:not(:disabled) { background: var(--bg); color: var(--fg); }

.error { margin: 0; font-size: 14px; border-left: 2px solid var(--fg); padding-left: 10px; }

/* ---------- 会议布局 ---------- */

.meeting {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100vh;
  height: 100dvh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
}
.room-info { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.room-name { overflow-wrap: anywhere; letter-spacing: 0.04em; }
.count { color: var(--dim); font-size: 13px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }

.status { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--dim); }
.status .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 1px solid var(--dim);
  background: transparent;
}
.status[data-state="connected"] .dot { background: var(--fg); border-color: var(--fg); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  background: none;
  border: 1px solid var(--line);
  font-size: 13px;
}
.chip .icon { width: 16px; height: 16px; }
.chip:hover:not(:disabled) { border-color: var(--fg); }
.chip.small { padding: 3px 10px; font-size: 12px; }
.chip.danger { border-color: var(--fg); }

.main {
  min-height: 0;
  padding: 12px;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
}
.main.has-stage { grid-template-rows: minmax(0, 1fr) auto; }

/* 共享画面 */

.stage {
  position: relative;
  min-height: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  overflow: hidden;
  display: grid;
}
.stage video {
  width: 100%;
  height: 100%;
  min-height: 0;
  object-fit: contain;
  background: var(--surface);
}
.stage-msg {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 6px;
  padding: 16px;
  text-align: center;
  background: var(--surface);
}
.stage-msg p { margin: 0; }
.stage-msg .hint { color: var(--dim); font-size: 13px; margin-bottom: 10px; }
.stage-msg.overlay { background: var(--surface); opacity: 0.92; color: var(--dim); }
.stage-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 12px;
  background: var(--bg);
  border-top: 1px solid var(--line);
  font-size: 13px;
}

/* 参与者方块 */

.tiles {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 480px));
  justify-content: center;
  align-content: center;
  min-height: 0;
  overflow: auto;
}

.has-stage .tiles {
  grid-template-columns: none;
  grid-auto-flow: column;
  grid-auto-columns: 150px;
  justify-content: start;
  align-content: start;
  overflow-x: auto;
  overflow-y: hidden;
}

@media (min-width: 900px) {
  .main.has-stage {
    grid-template-columns: minmax(0, 1fr) 220px;
    grid-template-rows: minmax(0, 1fr);
  }
  .has-stage .tiles {
    grid-auto-flow: row;
    grid-auto-columns: auto;
    grid-template-columns: minmax(0, 1fr);
    overflow-x: hidden;
    overflow-y: auto;
  }
}

.tile {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 16 / 10;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  overflow: hidden;
}
/* 正在说话：实线描边加粗 */
.tile.speaking { box-shadow: inset 0 0 0 2px var(--fg); border-color: var(--fg); }
.tile.sharing { cursor: pointer; }
.tile.on-stage { border-color: var(--fg); }

.avatar {
  display: grid;
  place-items: center;
  width: 26%;
  min-width: 44px;
  max-width: 88px;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 1px solid var(--fg);
  font-size: clamp(18px, 3vw, 32px);
  font-weight: 300;
  user-select: none;
}

.nameplate {
  position: absolute;
  left: 8px;
  bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: calc(100% - 16px);
  padding: 2px 8px;
  background: var(--bg);
  border: 1px solid var(--line);
  font-size: 13px;
}
.nameplate .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-muted { display: none; width: 14px; height: 14px; }
.tile.muted .icon-muted { display: block; }

.badge {
  position: absolute;
  top: 8px;
  padding: 1px 8px;
  background: var(--bg);
  border: 1px solid var(--line);
  font-size: 11px;
}
.badge-share { display: none; right: 8px; background: var(--fg); border-color: var(--fg); color: var(--bg); }
.tile.sharing .badge-share { display: block; }
.badge-conn { left: 8px; color: var(--dim); }

/* ---------- 控制栏 ---------- */

.controls {
  display: flex;
  justify-content: center;
  gap: 12px;
  padding: 12px 12px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}

.ctl {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 88px;
  padding: 10px 14px;
  background: none;
  border: 1px solid var(--line);
  font-size: 12px;
  letter-spacing: 0.04em;
}
.ctl:hover:not(:disabled) { border-color: var(--fg); }
/* 已静音 / 正在共享：反色 */
.ctl.off, .ctl.active { background: var(--fg); border-color: var(--fg); color: var(--bg); }
.ctl.danger { border-color: var(--fg); }
.ctl.danger:hover { background: var(--fg); color: var(--bg); }
.ctl.off .icon-mic, .ctl:not(.off) .icon-mic-off { display: none; }

/* ---------- 提示 ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 96px;
  max-width: min(92vw, 460px);
  padding: 10px 16px;
  background: var(--fg);
  color: var(--bg);
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 520px) {
  .ctl { min-width: 0; flex: 1; padding: 10px 6px; }
  .topbar-right { width: 100%; justify-content: space-between; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
