:root {
  --bg: #0c0f17;
  --bg-2: #121624;
  --panel: #161b2b;
  --panel-2: #1c2236;
  --line: #262d42;
  --text: #e6e9f2;
  --muted: #8b93ab;
  --muted-2: #6a7390;
  --accent: #6d8bff;
  --accent-2: #8a6dff;
  --accent-ink: #0b0f1c;
  --danger: #ff5f6d;
  --warn: #ffb020;
  --ok: #38d39f;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 18px 50px -18px rgba(0,0,0,.7);
}

* { box-sizing: border-box; }
/* The whole UI toggles visibility via the `hidden` attribute, but author
   `display` rules (.btn=inline-flex, .modal=grid, …) override the UA
   `[hidden]{display:none}`, leaving "hidden" elements visible (every modal and
   control button shown at once). This global rule makes `hidden` authoritative. */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", system-ui, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background:
    radial-gradient(1100px 700px at 12% -8%, rgba(109,139,255,.10) 0, transparent 55%),
    radial-gradient(900px 600px at 100% 0, rgba(138,109,255,.10) 0, transparent 50%),
    var(--bg);
  background-color: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }

/* ---------------- buttons ---------------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  font: inherit; font-weight: 600; font-size: 14px;
  padding: 10px 16px; border-radius: var(--radius-sm);
  border: 1px solid transparent; cursor: pointer; color: var(--text);
  background: var(--panel-2); transition: filter .15s, transform .05s, background .15s, border-color .15s;
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-sm { padding: 7px 12px; font-size: 13px; }
.btn-block { width: 100%; justify-content: center; padding: 12px; font-size: 15px; }
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; border-color: transparent; }
.btn-danger { background: linear-gradient(135deg, #ff5f6d, #ff7a59); color: #fff; }
.btn-warn { background: linear-gradient(135deg, #ffb020, #ff8a3d); color: #2a1c00; }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--muted); }
.btn-ghost:hover { color: var(--text); border-color: var(--accent); filter: none; }

/* ---------------- auth ---------------- */
.auth-body { display: grid; place-items: center; padding: 24px; }
.auth-card {
  width: min(420px, 100%); background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 30px 28px; box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 14px; margin-bottom: 26px; }
.brand-mark { color: var(--accent); display: grid; place-items: center;
  width: 52px; height: 52px; border-radius: 13px;
  background: linear-gradient(135deg, rgba(109,139,255,.18), rgba(138,109,255,.14));
  border: 1px solid var(--line); }
.brand h1 { margin: 0; font-size: 22px; letter-spacing: .3px; }
.brand-sub { margin: 3px 0 0; color: var(--muted); font-size: 12.5px; }
.auth-form { display: grid; gap: 16px; }
.field { display: grid; gap: 7px; }
.field > span { font-size: 13px; color: var(--muted); display: flex; gap: 8px; align-items: baseline; }
.field > span small { color: var(--muted-2); font-size: 11.5px; }
input, select {
  font: inherit; color: var(--text); background: var(--bg-2);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 11px 13px; outline: none; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(109,139,255,.18); }
select { cursor: pointer; }
.form-error { margin: 4px 0 0; color: var(--danger); font-size: 13px; }
.auth-foot { margin: 22px 0 0; color: var(--muted); font-size: 13px; text-align: center; line-height: 1.6; }

/* ---------------- app shell ---------------- */
.app-body { display: flex; flex-direction: column; height: 100dvh; overflow: hidden; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 18px; height: 56px; flex: 0 0 auto;
  background: rgba(18,22,36,.85); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 12px; }
.logo { display: inline-flex; align-items: center; gap: 9px; font-weight: 700; letter-spacing: .3px; color: var(--text); }
.logo svg { color: var(--accent); }
.pill { font-size: 12px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); }
.pill-muted { color: var(--muted); }
.pill-ok { color: var(--ok); border-color: rgba(56,211,159,.4); background: rgba(56,211,159,.08); }
.pill-bad { color: var(--danger); border-color: rgba(255,95,109,.4); background: rgba(255,95,109,.08); }
.presence { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.presence svg { color: var(--muted); }
.presence b { color: var(--text); }
.whoami { font-size: 13px; color: var(--muted); max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.stage-wrap { flex: 1 1 auto; display: grid; grid-template-columns: 1fr 320px; gap: 14px; padding: 14px; min-height: 0; }
.stage { display: flex; flex-direction: column; gap: 12px; min-width: 0; min-height: 0; }

.video-area {
  position: relative; flex: 1 1 auto; min-height: 0; border-radius: var(--radius);
  background: radial-gradient(120% 120% at 50% 0, #0f1320, #080a12);
  border: 1px solid var(--line); overflow: hidden; display: grid; place-items: center;
}
.screen-canvas { width: 100%; height: 100%; object-fit: contain; display: block; background: #000; }
.idle-state { text-align: center; color: var(--muted); padding: 24px; }
.idle-icon { color: var(--muted-2); opacity: .7; margin-bottom: 14px; }
.idle-state h2 { margin: 0 0 6px; font-size: 18px; color: var(--text); font-weight: 600; }
.idle-state p { margin: 0; font-size: 13.5px; }

.status-badge {
  position: absolute; top: 14px; left: 14px; z-index: 3;
  display: inline-flex; align-items: center; gap: 8px;
  padding: 7px 12px; border-radius: 999px; font-size: 12.5px; font-weight: 600;
  background: rgba(8,10,18,.72); border: 1px solid var(--line); backdrop-filter: blur(6px);
}
.status-badge .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); box-shadow: 0 0 0 0 rgba(255,95,109,.6); animation: pulse 1.8s infinite; }
@keyframes pulse { 0%{box-shadow:0 0 0 0 rgba(255,95,109,.55)} 70%{box-shadow:0 0 0 9px rgba(255,95,109,0)} 100%{box-shadow:0 0 0 0 rgba(255,95,109,0)} }

.stage-controls { position: absolute; top: 12px; right: 12px; z-index: 3; display: flex; gap: 8px; opacity: 0; transition: opacity .2s; }
.video-area:hover .stage-controls { opacity: 1; }
.ctrl-btn { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 9px; cursor: pointer;
  background: rgba(8,10,18,.7); border: 1px solid var(--line); color: var(--text); }
.ctrl-btn:hover { border-color: var(--accent); }

.control-bar { flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.control-left, .control-right { display: flex; align-items: center; gap: 10px; }
.stat-line { font-size: 12px; color: var(--muted-2); font-variant-numeric: tabular-nums; }
.mic-live { max-width: 200px; padding: 8px 10px; font-size: 13px; }

/* ---------------- chat ---------------- */
.chat { display: flex; flex-direction: column; min-height: 0; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.chat-head { flex: 0 0 auto; padding: 13px 16px; font-weight: 600; font-size: 14px;
  border-bottom: 1px solid var(--line); }
.chat-list { flex: 1 1 auto; overflow-y: auto; padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.chat-msg { font-size: 13.5px; line-height: 1.45; word-break: break-word; }
.chat-msg .who { font-weight: 600; font-size: 12.5px; color: var(--accent); margin-right: 6px; }
.chat-msg .who.me { color: var(--ok); }
.chat-msg .who.admin::after { content: "管理"; font-size: 10px; margin-left: 5px; padding: 1px 5px; border-radius: 6px;
  background: rgba(255,176,32,.16); color: var(--warn); font-weight: 600; }
.chat-msg .who.sharer::after { content: "分享中"; font-size: 10px; margin-left: 5px; padding: 1px 5px; border-radius: 6px;
  background: rgba(109,139,255,.18); color: var(--accent); font-weight: 600; }
.chat-msg .time { color: var(--muted-2); font-size: 11px; margin-left: 6px; }
.chat-msg .body { color: var(--text); }
.chat-sys { text-align: center; font-size: 12px; color: var(--muted-2); padding: 2px 0; }
.chat-form { flex: 0 0 auto; display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }
.chat-form input { flex: 1 1 auto; }

/* ---------------- modal ---------------- */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  background: rgba(5,7,12,.6); backdrop-filter: blur(3px); padding: 20px; }
.modal-card { width: min(560px, 100%); background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); }
.modal-narrow { width: min(420px, 100%); }
.modal-card h3 { margin: 0 0 18px; font-size: 18px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.check { display: flex; align-items: flex-start; gap: 10px; margin: 16px 0 4px; font-size: 13px; color: var(--muted); cursor: pointer; }
.check input { width: 16px; height: 16px; margin-top: 1px; accent-color: var(--accent); }
.modal-hint { color: var(--muted-2); font-size: 12.5px; margin: 10px 0 0; line-height: 1.5; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }

/* ---------------- toast ---------------- */
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  padding: 11px 18px; border-radius: 999px; font-size: 13.5px; z-index: 80; box-shadow: var(--shadow);
  animation: rise .25s ease; pointer-events: none; max-width: min(90vw, 520px); text-align: center; }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 10px);} to { opacity: 1; transform: translate(-50%, 0);} }

@media (max-width: 900px) {
  .stage-wrap { grid-template-columns: 1fr; grid-template-rows: 1fr 240px; }
  .form-grid { grid-template-columns: 1fr; }
  .whoami { display: none; }
}
