:root {
  --bg: #0e1116;
  --surface: #171c24;
  --surface-2: #1e2530;
  --border: #2a3340;
  --text: #e6ebf2;
  --muted: #8b96a5;
  --accent: #5ee0a0;
  --accent-dim: #2f8f66;
  --danger: #ff6b6b;
  --bubble-me: #234a3a;
  --bubble-other: #1e2530;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.view { display: none; height: 100%; }
.view.active { display: flex; }

/* ---------- 加入界面 ---------- */
#joinView { align-items: center; justify-content: center; padding: 24px; }
.join-wrap { width: 100%; max-width: 380px; }
.brand { text-align: center; margin-bottom: 34px; }
.brand-mark {
  width: 66px; height: 66px; margin: 0 auto 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 40px; color: #0e1116;
  background: linear-gradient(135deg, #7af0b6, #34a87a);
  border-radius: 20px;
  box-shadow: 0 8px 30px rgba(94,224,160,.25);
}
.brand h1 { margin: 0; font-size: 30px; letter-spacing: 4px; font-weight: 700; }
.brand-sub { margin: 6px 0 0; color: var(--muted); font-size: 13px; letter-spacing: 1px; }

.join-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 22px;
  display: flex; flex-direction: column; gap: 16px;
}
.field { display: flex; flex-direction: column; gap: 8px; }
.field span { font-size: 13px; color: var(--muted); }
.field input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color .2s;
}
.field input:focus { border-color: var(--accent-dim); }

.btn {
  border: none; border-radius: 12px; padding: 14px;
  font-size: 15px; font-weight: 600; cursor: pointer;
  transition: transform .1s, opacity .2s;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); color: #0b1f16; }
.btn.ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.join-notes {
  display: flex; flex-wrap: wrap; gap: 8px; justify-content: center;
  margin-top: 20px; font-size: 12px; color: var(--muted);
}
.join-notes span { background: var(--surface); border: 1px solid var(--border); padding: 6px 10px; border-radius: 20px; }

/* ---------- 聊天界面 ---------- */
#chatView { flex-direction: column; padding-top: var(--safe-top); }
.topbar {
  height: 58px; flex: 0 0 58px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.room-info { display: flex; flex-direction: column; gap: 2px; }
.room-label { font-size: 16px; font-weight: 600; }
.member-count { font-size: 12px; color: var(--muted); }
.top-actions { display: flex; gap: 8px; }

.icon-btn {
  width: 40px; height: 40px; flex: 0 0 40px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 12px;
  font-size: 18px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .2s, transform .1s;
}
.icon-btn:active { transform: scale(.94); }
.voice-btn.active { background: var(--accent); color: #0b1f16; border-color: var(--accent); }
.icon-btn.recording { background: #e5484d; color: #fff; border-color: #e5484d; animation: pulse 1s infinite; }

/* 录音状态条 */
.recording-bar {
  display: none; align-items: center; gap: 8px;
  margin-top: 8px; padding: 8px 12px;
  background: rgba(229,72,77,.12); border: 1px solid rgba(229,72,77,.35);
  border-radius: 10px; font-size: 13px; color: #ff8a8e;
}
.recording-bar.show { display: flex; }
.recording-bar .rec-dot { width: 9px; height: 9px; border-radius: 50%; background: #e5484d; animation: pulse 1s infinite; }
.recording-bar .rec-hint { margin-left: auto; color: var(--muted); font-size: 11px; }

/* 语音条消息 */
.voice-strip { display: flex; align-items: center; gap: 9px; min-width: 130px; cursor: pointer; user-select: none; }
.voice-strip .vplay {
  width: 30px; height: 30px; flex: 0 0 30px; border-radius: 50%;
  border: none; background: var(--accent); color: #0b1f16;
  font-size: 13px; display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.msg.theirs .voice-strip .vplay { background: var(--accent-dim); color: var(--text); }
.voice-strip .vbars { display: flex; align-items: center; gap: 2px; height: 20px; flex: 1; }
.voice-strip .vbars i { width: 3px; border-radius: 2px; background: currentColor; opacity: .55; display: block; }
.voice-strip.playing .vbars i { animation: vbar .8s ease-in-out infinite alternate; }
.voice-strip .vdur { font-size: 12px; opacity: .8; font-variant-numeric: tabular-nums; }
@keyframes vbar { from { transform: scaleY(.4); } to { transform: scaleY(1.2); } }

/* 图片 / 视频 / 文件附件气泡 */
.msg .bubble.media { padding: 4px; overflow: hidden; }
.media-img { display: block; max-width: 100%; max-height: 52vh; border-radius: 12px; cursor: zoom-in; }
.media-video { display: block; max-width: 100%; max-height: 52vh; border-radius: 12px; background: #000; }
.media-file { display: flex; align-items: center; gap: 10px; padding: 8px 10px; max-width: 220px; }
.media-file .fname { font-size: 13px; word-break: break-all; }
.media-loading { padding: 18px 22px; font-size: 13px; color: var(--muted); }

/* 图片放大预览 */
#lightbox {
  display: none; position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,.92); align-items: center; justify-content: center;
  padding: 20px;
}
#lightbox.show { display: flex; }
#lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; }

.messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px;
  display: flex; flex-direction: column; gap: 10px;
  -webkit-overflow-scrolling: touch;
}
.msg { max-width: 78%; display: flex; flex-direction: column; gap: 4px; animation: pop .2s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.msg .meta { font-size: 11px; color: var(--muted); padding: 0 4px; display: flex; gap: 8px; align-items: center; }
.msg .bubble {
  padding: 11px 14px;
  border-radius: 16px;
  font-size: 15px; line-height: 1.5;
  word-break: break-word;
  position: relative;
}
.msg .fuse {
  font-size: 10px; color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.msg.mine { align-self: flex-end; align-items: flex-end; }
.msg.mine .bubble { background: var(--bubble-me); border-bottom-right-radius: 4px; }
.msg.theirs { align-self: flex-start; align-items: flex-start; }
.msg.theirs .bubble { background: var(--bubble-other); border-bottom-left-radius: 4px; }
.msg.burning { animation: burn .6s ease-in forwards; }
@keyframes burn {
  0% { opacity: 1; }
  40% { opacity: 1; filter: blur(0); }
  100% { opacity: 0; filter: blur(6px); transform: scale(.96); }
}
.sys-msg { align-self: center; font-size: 12px; color: var(--muted); background: var(--surface); padding: 6px 12px; border-radius: 20px; }

/* 语音参与者条 */
.voice-bar {
  flex: 0 0 auto;
  display: none;
  gap: 8px; padding: 10px 16px;
  overflow-x: auto;
  border-top: 1px solid var(--border);
  background: rgba(94,224,160,.04);
}
.voice-bar.show { display: flex; }
.voice-chip {
  flex: 0 0 auto; display: flex; align-items: center; gap: 6px;
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 6px 12px; border-radius: 20px; font-size: 13px;
}
.voice-chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 1.4s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

/* 输入区 */
.composer {
  flex: 0 0 auto;
  padding: 10px 12px calc(10px + var(--safe-bottom));
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.composer-row { display: flex; gap: 8px; align-items: center; }
.composer-row input {
  flex: 1; min-width: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px; font-size: 15px;
  color: var(--text); outline: none;
}
.composer-row input:focus { border-color: var(--accent-dim); }
.send-btn {
  width: 44px; height: 44px; flex: 0 0 44px;
  border: none; border-radius: 12px;
  background: var(--accent); color: #0b1f16;
  font-size: 18px; cursor: pointer;
}
.send-btn:active { transform: scale(.94); }
.composer-meta {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 8px; font-size: 12px; color: var(--muted);
}
.ttl-select select {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 4px 8px; font-size: 12px; outline: none; margin-left: 4px;
}
.link-btn { background: none; border: none; color: var(--muted); font-size: 12px; cursor: pointer; text-decoration: underline; }

/* 提示 */
.toast {
  position: absolute; left: 50%; bottom: 120px; transform: translateX(-50%) translateY(10px);
  background: rgba(0,0,0,.8); color: #fff;
  padding: 10px 16px; border-radius: 20px; font-size: 13px;
  opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s;
  white-space: nowrap; z-index: 10;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
