/* ============ 基础变量 & 重置 ============ */
:root {
  --bg-0: #070b1a;
  --bg-1: #0d1430;
  --card: rgba(22, 30, 58, 0.72);
  --card-line: rgba(120, 140, 220, 0.18);
  --text: #eef2ff;
  --text-dim: #9aa6cf;
  --accent: #6d8cff;
  --accent-2: #9b5cff;
  --accent-grad: linear-gradient(135deg, #6d8cff 0%, #9b5cff 100%);
  --danger: #ff4d6d;
  --ok: #2dd4a7;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  --radius: 20px;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: radial-gradient(1200px 800px at 20% -10%, #1a2350 0%, var(--bg-0) 55%);
  overflow: hidden;
  user-select: none;
}

.hidden { display: none !important; }

/* ============ 动态光球背景 ============ */
.bg-orbs { position: fixed; inset: 0; overflow: hidden; z-index: 0; pointer-events: none; }
.orb { position: absolute; border-radius: 50%; filter: blur(80px); opacity: 0.5; animation: float 18s ease-in-out infinite; }
.orb-1 { width: 420px; height: 420px; background: #6d8cff; top: -120px; left: -80px; }
.orb-2 { width: 380px; height: 380px; background: #9b5cff; bottom: -120px; right: -60px; animation-delay: -6s; }
.orb-3 { width: 300px; height: 300px; background: #2dd4a7; top: 40%; left: 55%; animation-delay: -12s; opacity: 0.3; }
@keyframes float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(40px, -30px) scale(1.1); }
  66% { transform: translate(-30px, 20px) scale(0.95); }
}

/* ============ 登录 / 大厅 ============ */
.lobby {
  position: relative; z-index: 1;
  min-height: 100%;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 24px;
}
.lobby-card {
  width: 100%; max-width: 440px;
  background: var(--card);
  backdrop-filter: blur(22px); -webkit-backdrop-filter: blur(22px);
  border: 1px solid var(--card-line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 26px;
  animation: cardIn 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
}
@keyframes cardIn { from { opacity: 0; transform: translateY(24px) scale(0.97); } to { opacity: 1; transform: none; } }

.brand { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; }
.brand-logo {
  width: 54px; height: 54px; border-radius: 16px;
  background: var(--accent-grad);
  display: grid; place-items: center; color: #fff;
  box-shadow: 0 8px 24px rgba(109, 140, 255, 0.5);
}
.brand-text h1 { font-size: 24px; font-weight: 800; letter-spacing: 0.5px; }
.brand-text p { font-size: 12.5px; color: var(--text-dim); margin-top: 2px; }

.lobby-preview {
  position: relative; width: 100%; aspect-ratio: 16/9;
  border-radius: 16px; overflow: hidden; margin-bottom: 18px;
  background: #050813; border: 1px solid var(--card-line);
}
.lobby-preview video { width: 100%; height: 100%; object-fit: cover; }
.preview-mask {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  color: var(--text-dim); background: #050813; cursor: pointer;
}
.preview-mask span { font-size: 13px; }
.lobby-cam-off {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  color: var(--text-dim); background: #050813; pointer-events: none;
}
.lobby-cam-off span { font-size: 13px; }

.lobby-media-ctrl {
  display: flex; gap: 10px; margin-bottom: 18px;
}
.lobby-ctrl-btn {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 10px; border-radius: 12px;
  background: rgba(255,255,255,0.06); border: 1px solid var(--card-line);
  color: var(--text); font-size: 14px; font-weight: 600; cursor: pointer;
  transition: all 0.18s;
}
.lobby-ctrl-btn:active { transform: scale(0.96); }
.lobby-ctrl-btn .ico-off { display: none; }
.lobby-ctrl-btn[data-on="false"] {
  background: rgba(255,77,109,0.14); border-color: rgba(255,77,109,0.35); color: var(--danger);
}
.lobby-ctrl-btn[data-on="false"] .ico-on { display: none; }
.lobby-ctrl-btn[data-on="false"] .ico-off { display: block; }

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 8px; font-weight: 600; }
.field label .hint { color: var(--accent); font-weight: 500; }

.select-wrap { display: flex; gap: 8px; }
select, input[type="text"], input[type="password"] {
  width: 100%; padding: 13px 14px;
  background: rgba(10, 16, 38, 0.7);
  border: 1px solid var(--card-line); border-radius: 12px;
  color: var(--text); font-size: 15px; outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
select { appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' fill='none' stroke='%239aa6cf' stroke-width='2'%3E%3Cpath d='M3 5l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; padding-right: 38px;
}
input::placeholder { color: #5b6690; }
select:focus, input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(109, 140, 255, 0.18); }

.room-row { display: flex; gap: 8px; }
.room-row input { flex: 1; }

.icon-btn-sm {
  flex: 0 0 auto; width: 48px; border-radius: 12px;
  background: rgba(10, 16, 38, 0.7); border: 1px solid var(--card-line);
  color: var(--text-dim); cursor: pointer; display: grid; place-items: center;
  transition: all 0.2s;
}
.icon-btn-sm:active { transform: scale(0.92); color: var(--accent); }

.ghost-btn {
  padding: 0 18px; border-radius: 12px;
  background: rgba(109, 140, 255, 0.14); border: 1px solid rgba(109, 140, 255, 0.3);
  color: #b9c6ff; font-size: 14px; font-weight: 600; cursor: pointer;
  transition: all 0.2s; white-space: nowrap;
}
.ghost-btn:active { transform: scale(0.96); }
.ghost-btn.full { width: 100%; padding: 13px; margin-top: 8px; }

.primary-btn {
  width: 100%; margin-top: 6px; padding: 15px;
  border: none; border-radius: 14px;
  background: var(--accent-grad); color: #fff;
  font-size: 16px; font-weight: 700; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  box-shadow: 0 10px 28px rgba(109, 140, 255, 0.45);
  transition: transform 0.15s, box-shadow 0.2s;
}
.primary-btn:active { transform: translateY(2px) scale(0.99); box-shadow: 0 6px 16px rgba(109, 140, 255, 0.4); }

.tip { margin-top: 14px; font-size: 12.5px; color: var(--danger); text-align: center; min-height: 16px; }
.lobby-foot { margin-top: 20px; font-size: 12px; color: #4b5680; z-index: 1; }

/* ===== 登录页 ===== */
.login-card {
  text-align: center;
  padding: 40px 32px;
  max-width: 420px;
}
.login-card .brand {
  justify-content: center;
  margin-bottom: 32px;
}
.login-card .field {
  text-align: left;
  margin-bottom: 20px;
}
.login-card .field label {
  font-size: 14px;
  margin-bottom: 10px;
}
.login-card .field input {
  padding: 16px 18px;
  font-size: 16px;
  border-radius: 14px;
  letter-spacing: 2px;
}
.login-card .field input::placeholder {
  letter-spacing: 0;
}
.login-card .primary-btn {
  margin-top: 16px;
  padding: 16px;
  font-size: 17px;
  border-radius: 14px;
}
.login-card .primary-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}
.login-card .tip {
  margin-top: 18px;
  font-size: 13px;
}

/* ============ Toast ============ */
.toast {
  position: fixed; left: 50%; bottom: 110px; transform: translateX(-50%) translateY(20px);
  background: rgba(20, 28, 56, 0.95); color: #fff; padding: 12px 20px; border-radius: 12px;
  font-size: 14px; border: 1px solid var(--card-line); box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: all 0.3s; z-index: 999;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ============ 会议室 ============ */
.room {
  position: relative; z-index: 1;
  height: 100%; display: flex; flex-direction: column;
}

.room-header {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; gap: 12px;
  background: rgba(8, 12, 30, 0.55);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--card-line);
}
.room-info { display: flex; align-items: center; gap: 10px; font-size: 15px; }
.room-name b { color: #fff; letter-spacing: 0.5px; }
.live-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--danger); box-shadow: 0 0 0 0 rgba(255,77,109,0.6); animation: pulse 1.8s infinite; }
@keyframes pulse { 0%{box-shadow:0 0 0 0 rgba(255,77,109,0.6);} 70%{box-shadow:0 0 0 8px rgba(255,77,109,0);} 100%{box-shadow:0 0 0 0 rgba(255,77,109,0);} }
.room-meta { display: flex; gap: 8px; }

.chip {
  font-size: 12.5px; padding: 6px 12px; border-radius: 20px;
  background: rgba(109, 140, 255, 0.16); border: 1px solid rgba(109,140,255,0.3);
  color: #c3cdff; cursor: pointer; transition: all 0.2s; white-space: nowrap;
}
.chip:active { transform: scale(0.94); }
.chip-soft { background: rgba(255,255,255,0.06); border-color: rgba(255,255,255,0.1); color: var(--text-dim); cursor: default; }

/* ===== 视频网格 ===== */
.stage { flex: 1; overflow: hidden; padding: 14px; }
.video-grid {
  height: 100%; display: grid; gap: 12px;
  grid-template-columns: 1fr;
  grid-auto-rows: 1fr;
  transition: all 0.3s;
}
.video-grid[data-count="2"] { grid-template-columns: 1fr 1fr; }
.video-grid[data-count="3"], .video-grid[data-count="4"] { grid-template-columns: 1fr 1fr; }
.video-grid[data-count="5"], .video-grid[data-count="6"] { grid-template-columns: repeat(3, 1fr); }
.video-grid[data-count="7"], .video-grid[data-count="8"], .video-grid[data-count="9"] { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 640px) {
  .video-grid[data-count="3"], .video-grid[data-count="4"],
  .video-grid[data-count="5"], .video-grid[data-count="6"] { grid-template-columns: 1fr 1fr; }
}

/* 点击放大：主画面 + 右侧缩略图 */
.video-grid[data-focus="1"] {
  grid-template-columns: 1fr min(180px, 30vw);
  grid-template-rows: repeat(var(--thumb-count, 1), 1fr);
}
.video-grid[data-focus="1"] .tile.focused {
  grid-column: 1;
  grid-row: 1 / -1;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(109, 140, 255, 0.5), 0 8px 24px rgba(0,0,0,0.35);
}
.video-grid[data-focus="1"] .tile.thumb {
  grid-column: 2;
  min-height: 72px;
  cursor: pointer;
}
.video-grid[data-focus="1"] .tile.thumb .tile-focus-hint { display: none; }
@media (max-width: 640px) {
  .video-grid[data-focus="1"] {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }
  .video-grid[data-focus="1"] .tile.focused {
    flex: 1;
    min-height: 0;
  }
  .video-grid[data-focus="1"] .tile.thumb {
    flex: 0 0 72px;
    min-height: 72px;
    max-height: 80px;
  }
}

.tile {
  position: relative; border-radius: 16px; overflow: hidden;
  background: #0a0f24; border: 1px solid var(--card-line);
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
  animation: tileIn 0.4s ease; min-height: 0;
}
.tile:not(.self) { cursor: pointer; }
.tile:not(.self):active { transform: scale(0.98); }
.tile-focus-hint {
  position: absolute; top: 10px; right: 10px;
  font-size: 11px; padding: 3px 8px; border-radius: 10px;
  background: rgba(8,12,30,0.65); color: var(--text-dim);
  opacity: 0; transition: opacity 0.2s; pointer-events: none;
}
.tile:not(.self):hover .tile-focus-hint { opacity: 1; }
.tile.focused .tile-focus-hint { display: none; }
@keyframes tileIn { from { opacity: 0; transform: scale(0.9); } to { opacity: 1; transform: none; } }
.tile.speaking { border-color: var(--ok); box-shadow: 0 0 0 2px var(--ok), 0 8px 24px rgba(0,0,0,0.35); }
.tile video { width: 100%; height: 100%; object-fit: cover; background: #0a0f24; }
.tile.cam-off video { opacity: 0; }

.tile-avatar {
  position: absolute; inset: 0; display: none;
  align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 40%, #1a2350, #0a0f24);
}
.tile.cam-off .tile-avatar { display: flex; }
.avatar-circle {
  width: 84px; height: 84px; border-radius: 50%;
  background: var(--accent-grad); color: #fff;
  display: grid; place-items: center; font-size: 32px; font-weight: 700;
  box-shadow: 0 8px 24px rgba(109,140,255,0.4);
}
.tile-name {
  position: absolute; left: 12px; bottom: 12px;
  display: flex; align-items: center; gap: 6px;
  background: rgba(8,12,30,0.7); backdrop-filter: blur(8px);
  padding: 5px 11px; border-radius: 20px; font-size: 12.5px; font-weight: 600;
}
.tile-name .mic-mini { display: none; color: var(--danger); }
.tile.muted .tile-name .mic-mini { display: inline-flex; }

/* ===== 控制栏 ===== */
.control-bar {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  background: rgba(8, 12, 30, 0.7);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid var(--card-line);
}
.ctrl-btn {
  flex: 1; max-width: 92px;
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  padding: 9px 4px; border: none; border-radius: 16px;
  background: rgba(255,255,255,0.06); color: var(--text);
  cursor: pointer; transition: all 0.18s;
}
.ctrl-btn:active { transform: scale(0.93); }
.ctrl-ico { position: relative; display: grid; place-items: center; }
.ctrl-label { font-size: 11.5px; color: var(--text-dim); font-weight: 600; }
.ctrl-btn .ico-off { display: none; }
.ctrl-btn[data-on="false"] { background: rgba(255,77,109,0.18); }
.ctrl-btn[data-on="false"] .ico-on { display: none; }
.ctrl-btn[data-on="false"] .ico-off { display: block; color: var(--danger); }
.ctrl-btn[data-on="false"] .ctrl-label { color: var(--danger); }
.ctrl-danger { background: var(--danger) !important; }
.ctrl-danger .ctrl-label { color: #fff; }
.badge {
  position: absolute; top: -6px; right: -8px; min-width: 16px; height: 16px;
  padding: 0 4px; border-radius: 9px; background: var(--danger); color: #fff;
  font-size: 10px; font-weight: 700; display: none; align-items: center; justify-content: center;
}
.badge.show { display: flex; }

/* ===== 聊天面板 ===== */
.chat-panel {
  position: fixed; top: 0; right: 0; z-index: 50;
  width: min(360px, 86vw); height: 100%;
  background: rgba(12, 18, 40, 0.96);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-left: 1px solid var(--card-line);
  display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform 0.32s cubic-bezier(0.2,0.8,0.2,1);
  box-shadow: -20px 0 50px rgba(0,0,0,0.4);
}
.chat-panel.open { transform: translateX(0); }
.chat-head { display: flex; align-items: center; justify-content: space-between; padding: 18px; font-weight: 700; border-bottom: 1px solid var(--card-line); }
.chat-list { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 80%; align-self: flex-start; }
.msg.me { align-self: flex-end; }
.msg-name { font-size: 11px; color: var(--text-dim); margin-bottom: 3px; padding: 0 4px; }
.msg-bubble { padding: 9px 13px; border-radius: 14px; font-size: 14px; line-height: 1.4; word-break: break-word;
  background: rgba(255,255,255,0.08); border-bottom-left-radius: 4px; }
.msg.me .msg-bubble { background: var(--accent-grad); border-bottom-left-radius: 14px; border-bottom-right-radius: 4px; }
.chat-input { display: flex; gap: 8px; padding: 14px; border-top: 1px solid var(--card-line); }
.chat-input input { flex: 1; }
.send-btn { flex: 0 0 auto; width: 48px; border: none; border-radius: 12px; background: var(--accent-grad); color: #fff; cursor: pointer; display: grid; place-items: center; transition: transform 0.15s; }
.send-btn:active { transform: scale(0.9); }

/* ===== 摄像头弹窗 ===== */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; padding: 24px;
  background: rgba(4,7,18,0.7); backdrop-filter: blur(6px); animation: fade 0.25s; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal-card { width: 100%; max-width: 400px; background: var(--card); border: 1px solid var(--card-line);
  border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); animation: cardIn 0.3s; }
.modal-card h3 { font-size: 18px; margin-bottom: 4px; }
.modal-sub { font-size: 12.5px; color: var(--text-dim); margin-bottom: 16px; }
.cam-options { list-style: none; display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.cam-options li { padding: 13px 14px; border-radius: 12px; background: rgba(10,16,38,0.6); border: 1px solid var(--card-line);
  cursor: pointer; font-size: 14px; display: flex; align-items: center; gap: 10px; transition: all 0.2s; }
.cam-options li:active { transform: scale(0.98); }
.cam-options li.active { border-color: var(--accent); background: rgba(109,140,255,0.16); }
.cam-options li .dot { width: 8px; height: 8px; border-radius: 50%; background: #3a4570; flex: 0 0 auto; }
.cam-options li.active .dot { background: var(--ok); box-shadow: 0 0 8px var(--ok); }