/* ===== 全局 ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --primary: #4a90e2;
  --primary-dark: #357abd;
  --bg: #0f1218;
  --panel: #1a1f2a;
  --card: #222834;
  --text: #e8ecf3;
  --text-sub: #8a94a6;
  --border: #2c3444;
  --danger: #ff4d4f;
  --success: #7ee787;
}
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
.hidden { display: none !important; }

/* ===== 加入界面 ===== */
.join-screen {
  height: 100vh;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(160deg, #0f1218 0%, #1a2436 60%, #14233a 100%);
}
.join-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 40px 28px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.join-logo { font-size: 3rem; margin-bottom: 12px; }
.join-card h1 { font-size: 1.4rem; font-weight: 600; margin-bottom: 8px; }
.join-sub { color: var(--text-sub); font-size: 0.85rem; margin-bottom: 28px; line-height: 1.6; }
.name-input, .room-input {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #141a26;
  color: var(--text);
  font-size: 16px;
  outline: none;
  margin-bottom: 16px;
  text-align: center;
}
.name-input:focus, .room-input:focus { border-color: var(--primary); }
.join-btn {
  width: 100%;
  padding: 15px 0;
  border: none;
  border-radius: 12px;
  background: var(--primary);
  color: #fff;
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}
.join-btn:active { background: var(--primary-dark); }
.join-btn:disabled { opacity: 0.6; cursor: not-allowed; }
.join-tip { color: var(--text-sub); font-size: 0.75rem; margin-top: 14px; }

/* ===== 房间界面 ===== */
.room-screen {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 900px;
  margin: 0 auto;
}

/* 顶部栏 */
.room-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.room-header h1 { font-size: 1.1rem; font-weight: 600; }
.room-stats {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--text-sub);
}
.room-stats .dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--success);
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.8); }
}

/* 视频网格 */
.video-grid {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr;
  align-content: start;
}
/* 2 人：双列 */
.video-grid.count-2 { grid-template-columns: 1fr 1fr; }
/* 3+ 人：九宫格 */
.video-grid.count-3, .video-grid.count-many { grid-template-columns: 1fr 1fr; }

.video-card {
  position: relative;
  background: var(--card);
  border-radius: 14px;
  overflow: hidden;
  aspect-ratio: 16 / 10;
  border: 2px solid transparent;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.video-card.speaking {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(74,144,226,0.4), 0 6px 20px rgba(0,0,0,0.4);
}
.video-card video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: #0a0d12;
}
.video-card .avatar-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
  background: linear-gradient(135deg, #4a90e2, #7b5bd6);
  color: #fff;
}
.video-card .member-name {
  position: absolute;
  left: 10px;
  top: 10px;
  background: rgba(0,0,0,0.55);
  color: #fff;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.8rem;
  font-weight: 500;
  z-index: 2;
}
.video-card .self-tag {
  position: absolute;
  right: 10px;
  top: 10px;
  background: rgba(74,144,226,0.9);
  color: #fff;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.72rem;
  z-index: 2;
}
/* 波形条 */
.wave-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 28px;
  padding: 4px 8px;
  background: linear-gradient(transparent, rgba(0,0,0,0.6));
  z-index: 2;
}
.wave-bar .bar {
  flex: 1;
  background: rgba(255,255,255,0.35);
  border-radius: 2px;
  height: 3px;
  transition: height 0.08s linear, background 0.2s;
}
.wave-bar.speaking .bar {
  background: linear-gradient(180deg, #4a90e2, #7b5bd6);
}

/* 聊天区 */
.chat-panel {
  background: var(--panel);
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  flex-shrink: 0;
}
.chat-messages {
  height: 110px;
  overflow-y: auto;
  padding: 6px 2px;
  margin-bottom: 10px;
}
.chat-messages .message {
  margin-bottom: 6px;
  font-size: 0.88rem;
  line-height: 1.5;
}
.msg-user { color: var(--primary); font-weight: 600; margin-right: 6px; }
.msg-time { color: var(--text-sub); font-size: 0.7rem; margin-left: 6px; }
.msg-text { color: var(--text); word-break: break-word; }

.chat-form { display: flex; gap: 8px; }
.chat-form input {
  flex: 1;
  padding: 11px 16px;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 16px;
  background: #141a26;
  color: var(--text);
  outline: none;
}
.chat-form input:focus { border-color: var(--primary); }
.send-btn {
  padding: 11px 20px;
  border: none;
  border-radius: 20px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  font-size: 0.9rem;
  flex-shrink: 0;
}
.send-btn:active { background: var(--primary-dark); }

/* 底部控制 */
.room-footer {
  display: flex;
  gap: 10px;
  padding: 12px 16px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.control-btn {
  flex: 1;
  padding: 13px 0;
  border: none;
  border-radius: 24px;
  background: #2a3140;
  color: var(--text);
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 0.2s, color 0.2s;
}
.control-btn:active { opacity: 0.85; }
.control-btn.active { background: var(--danger); color: #fff; }
.control-btn.leave { background: var(--danger); color: #fff; }

/* 麦克风提示浮层 */
#mic-permission-tip {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  z-index: 9999;
  font-size: 14px;
  max-width: 90%;
  text-align: center;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

/* ===== 桌面适配 ===== */
@media (min-width: 700px) {
  .video-grid.count-3, .video-grid.count-many { grid-template-columns: 1fr 1fr 1fr; }
}

/* ===== 房间号相关 ===== */
.join-btns {
  display: flex;
  gap: 10px;
}
.join-btns .join-btn {
  flex: 1;
}
.join-btn.primary {
  background: var(--primary);
}
.join-btn:not(.primary) {
  background: #2a3140;
  color: var(--text);
}
.join-btn:not(.primary):active { background: #3a4252; }
.room-badge {
  background: rgba(74,144,226,0.2);
  color: var(--primary);
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 0.8rem;
  font-weight: 600;
  margin-right: 4px;
}
#room-id-display { letter-spacing: 1px; }
