/* 移动端优先，深色，单手操作 */
:root {
  --bg: #0b141a;
  --panel: #111b21;
  --bar: #1f2c34;
  --mine: #005c4b;
  --theirs: #1f2c34;
  --text: #e9edef;
  --muted: #8696a0;
  --accent: #00a884;
  --danger: #f15c6d;
  /* Liquid Glass：玻璃底色 / 边缘高光 / 内部体积光。透明面板下面得有颜色才看得出玻璃，
     所以 body::before 铺一层固定的渐变光斑。 */
  --glass: rgba(255, 255, 255, .06);
  --glass-rim: rgba(255, 255, 255, .14);
  --glass-volume: inset 0 1px 0 rgba(255, 255, 255, .16), inset 0 -1px 0 rgba(0, 0, 0, .25);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overscroll-behavior: none;
}
/* 玻璃背后的光斑（固定，不随滚动） */
body::before {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(60% 45% at 8% 6%, rgba(0, 168, 132, .38), transparent 70%),
    radial-gradient(50% 40% at 95% 18%, rgba(59, 130, 246, .30), transparent 70%),
    radial-gradient(70% 55% at 55% 105%, rgba(139, 92, 246, .30), transparent 70%),
    var(--bg);
}
.hidden { display: none !important; }

/* —— Liquid Glass —— */
/* 隐藏的 SVG 滤镜容器（index.html 里 #liquid-glass-engine） */
.liquid-glass-filter { position: absolute; width: 0; height: 0; pointer-events: none; }
/* 玻璃面板：模糊+提饱和+边缘高光。::before 那层 backdrop-filter 用 SVG 折射滤镜，
   不支持 url() 的浏览器（Safari/Firefox）会整条丢弃，自动落回纯 blur。 */
.glass {
  position: relative; isolation: isolate;
  background: var(--glass);
  border: 1px solid var(--glass-rim);
  box-shadow: var(--glass-volume), 0 8px 30px rgba(0, 0, 0, .25);
  -webkit-backdrop-filter: blur(18px) saturate(170%);
  backdrop-filter: blur(18px) saturate(170%);
}
.glass::before {
  content: ""; position: absolute; inset: 0; z-index: -1; border-radius: inherit; pointer-events: none;
  -webkit-backdrop-filter: url(#liquid-glass-engine) brightness(112%) saturate(120%);
  backdrop-filter: url(#liquid-glass-engine) brightness(112%) saturate(120%);
}
@media (prefers-reduced-transparency: reduce) {
  .glass { background: rgba(17, 27, 33, .96); -webkit-backdrop-filter: none; backdrop-filter: none; }
  .glass::before, body::before { display: none; }
}

/* 登录 */
.login {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%; max-width: 360px;
  border-radius: 20px; padding: 28px 24px;
  display: flex; flex-direction: column; gap: 14px; text-align: center;
}
.login-card h1 { margin: 0; font-size: 22px; }
.login-card p { margin: 0; color: var(--muted); font-size: 14px; }
.login-card input {
  padding: 14px; border-radius: 10px; border: 1px solid var(--glass-rim);
  background: rgba(0, 0, 0, .3); color: var(--text); font-size: 16px;
}
.login-card button, .send {
  background: var(--accent); color: #04221c; border: none; cursor: pointer;
  font-weight: 600;
}
.login-card button { padding: 14px; border-radius: 10px; font-size: 16px; }
.error { color: var(--danger) !important; min-height: 1em; }

/* 会话列表（= 好友列表） */
.list { display: flex; flex-direction: column; height: 100dvh; }
.list-topbar { justify-content: space-between; }
.list-title { font-weight: 600; font-size: 18px; flex: 1; }
.conv-list { flex: 1; overflow-y: auto; }
.conv-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; cursor: pointer; border-bottom: 1px solid rgba(255, 255, 255, .06);
}
.conv-row:active { background: var(--glass); }
.conv-ava {
  width: 46px; height: 46px; border-radius: 50%; flex: none;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 600; font-size: 18px;
}
.conv-mid { flex: 1; min-width: 0; }
.conv-name { font-weight: 600; display: flex; align-items: center; gap: 6px; }
.conv-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.conv-dot.online { background: var(--accent); }
.conv-prev { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.conv-time { font-size: 11px; color: var(--muted); }
.conv-unread {
  background: var(--accent); color: #04221c; font-size: 12px; font-weight: 700;
  min-width: 18px; height: 18px; border-radius: 9px; padding: 0 5px;
  display: flex; align-items: center; justify-content: center;
}
.back-btn {
  background: none; border: none; color: var(--text); font-size: 30px;
  line-height: 1; padding: 0 4px 0 0; cursor: pointer; flex: none;
}
/* 群聊里对方消息上方显示发送者名 */
.bubble .sender { display: block; font-size: 12px; color: var(--accent); margin-bottom: 2px; font-weight: 600; }

/* 主布局 */
.app {
  display: flex; flex-direction: column;
  height: 100dvh;
}
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  border-width: 0 0 1px; border-radius: 0; box-shadow: var(--glass-volume);
}
.peer { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.peer-name { font-weight: 600; }
.peer-status { font-size: 12px; color: var(--muted); }
.peer-status.typing { color: var(--accent); }
.conn-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); }
.conn-dot.online { background: var(--accent); }
.push-btn {
  background: var(--accent); color: #04221c; border: none; cursor: pointer;
  font-size: 13px; font-weight: 600; padding: 6px 10px; border-radius: 16px;
  white-space: nowrap;
}
.logout-btn {
  background: none; border: 1px solid var(--muted); color: var(--muted);
  cursor: pointer; font-size: 12px; padding: 5px 9px; border-radius: 14px;
  white-space: nowrap;
}

/* 消息区 */
.messages {
  flex: 1; overflow-y: auto; padding: 12px 12px 6px;
  display: flex; flex-direction: column; gap: 4px;
}
.load-more { text-align: center; color: var(--muted); font-size: 13px; padding: 8px; }

.bubble {
  max-width: 78%; padding: 7px 10px 5px; border-radius: 10px;
  word-wrap: break-word; white-space: pre-wrap; position: relative;
}
/* ponytail: 气泡只做半透明+边缘高光、不加 backdrop-filter——上百个合成层手机滚动会掉帧 */
.bubble { border: 1px solid var(--glass-rim); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .12); }
.bubble.mine { align-self: flex-end; background: rgba(0, 168, 132, .30); border-bottom-right-radius: 3px; }
.bubble.theirs { align-self: flex-start; background: rgba(255, 255, 255, .08); border-bottom-left-radius: 3px; }
.bubble .meta {
  display: block; text-align: right; font-size: 11px; color: var(--muted);
  margin-top: 2px;
}
.bubble.mine .meta { color: #aebfb8; }
.tick.sending { opacity: .5; }
.tick.delivered { color: #53bdeb; }

.day-sep { align-self: center; color: var(--muted); font-size: 12px; margin: 8px 0; }

/* 输入栏 */
.composer {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 10px calc(env(safe-area-inset-bottom) + 8px);
  border-width: 1px 0 0; border-radius: 0; box-shadow: var(--glass-volume);
}
.composer textarea {
  flex: 1; resize: none; max-height: 120px;
  padding: 10px 14px; border-radius: 20px; border: 1px solid var(--glass-rim);
  background: rgba(0, 0, 0, .28); color: var(--text); font-size: 16px; line-height: 1.3;
}
.send {
  width: 44px; height: 44px; border-radius: 50%; flex: 0 0 auto;
  font-size: 18px; display: flex; align-items: center; justify-content: center;
}
.send:disabled { opacity: .5; }

/* 附件 / 录音按钮 */
.icon-btn {
  width: 40px; height: 40px; flex: 0 0 auto; border: none; background: none;
  font-size: 22px; cursor: pointer; border-radius: 50%; padding: 0;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:active { background: var(--glass); }
.icon-btn.recording { background: var(--danger); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .5; } }

/* 媒体气泡 */
.bubble.media { padding: 4px 4px 5px; }
.media-img {
  display: block; max-width: 220px; max-height: 280px; width: auto; height: auto;
  border-radius: 8px; cursor: pointer; object-fit: cover;
}
/* 语音消息：播放键 + 波形（即进度条）+ 时长/倍速 */
.voice { display: flex; align-items: center; gap: 8px; width: 240px; max-width: 64vw; padding: 2px 4px 0; white-space: normal; }
.vm-play {
  flex: none; width: 36px; height: 36px; border-radius: 50%; border: 0; padding: 0;
  background: var(--accent); color: #fff; font-size: 13px; cursor: pointer;
}
.vm-col { flex: 1; min-width: 0; }
.vm-wave { position: relative; height: 28px; cursor: pointer; touch-action: none; outline: none; }
.vm-wave:focus-visible { box-shadow: 0 0 0 2px var(--accent); border-radius: 4px; }
.vm-bars { position: absolute; inset: 0; display: flex; align-items: center; gap: 1px; pointer-events: none; }
.vm-bars i { flex: 1; min-width: 1px; border-radius: 1px; background: var(--muted); opacity: .55; }
.vm-done { clip-path: inset(0 100% 0 0); }
.vm-done i { background: var(--text); opacity: 1; }
.vm-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 2px; }
.vm-time { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.bubble.mine .vm-time { color: #aebfb8; }
.vm-rate {
  border: 1px solid var(--glass-rim); background: var(--glass); color: var(--text);
  border-radius: 9px; font-size: 11px; line-height: 1; padding: 3px 7px; cursor: pointer;
}
.voice audio { display: none; }
.media-uploading { opacity: .55; }

/* 图片全屏查看 */
.lightbox {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .92); z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 6px; }

/* 通话界面 */
.call-overlay { position: fixed; inset: 0; background: #0b141a; z-index: 60; }
#local-video {
  position: absolute; top: calc(env(safe-area-inset-top) + 14px); right: 14px;
  width: 108px; aspect-ratio: 3 / 4; object-fit: cover;
  border-radius: 10px; border: 1px solid rgba(255, 255, 255, .25); z-index: 2;
  background: #000;
}
.call-info {
  position: absolute; top: 16%; left: 0; right: 0; text-align: center; z-index: 2;
  color: #fff; text-shadow: 0 1px 6px rgba(0, 0, 0, .6); pointer-events: none;
}
.call-avatar { font-size: 64px; margin-bottom: 10px; }
.call-peer { font-size: 26px; font-weight: 600; }
.call-state { margin-top: 6px; color: #c8d2d8; font-size: 15px; }
.call-controls {
  position: absolute; bottom: calc(env(safe-area-inset-bottom) + 34px);
  left: 0; right: 0; display: flex; justify-content: center; gap: 14px; z-index: 2;
}
.call-ctl {
  width: 56px; height: 56px; border-radius: 50%; border: 1px solid var(--glass-rim); cursor: pointer;
  font-size: 22px; background: rgba(255, 255, 255, .10); color: #fff; flex: 0 0 auto;
  -webkit-backdrop-filter: blur(14px) saturate(160%); backdrop-filter: blur(14px) saturate(160%);
  display: flex; align-items: center; justify-content: center;
}
.call-ctl.hangup { background: var(--danger); }
.call-ctl.accept { background: var(--accent); }
.call-ctl.off { opacity: .45; }

/* 前置摄像头预览镜像（像照镜子）；发给对方的画面不受影响 */
#local-video.mirror { transform: scaleX(-1); }


/* —— SFU 群通话网格 —— */
.call-grid { position: absolute; inset: 0; display: grid; gap: 4px; background: #000; }
.call-grid[data-n="0"] { display: none; }
.call-grid[data-n="1"] { grid-template-columns: 1fr; }
.call-grid[data-n="2"], .call-grid[data-n="3"], .call-grid[data-n="4"] {
  grid-template-columns: repeat(2, 1fr);
}
.call-grid[data-n="5"], .call-grid[data-n="6"], .call-grid[data-n="7"],
.call-grid[data-n="8"], .call-grid[data-n="9"] {
  grid-template-columns: repeat(3, 1fr);
}
.call-tile { position: relative; overflow: hidden; background: #1a1a1a; border-radius: 8px; }
.call-tile video { width: 100%; height: 100%; object-fit: cover; }
.call-tile .tile-avatar {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 48px; background: #1a1a1a;
}
.call-tile .tile-avatar.hidden { display: none; }
.call-tile .tile-name {
  position: absolute; left: 8px; bottom: 6px; color: #fff; font-size: 13px;
  text-shadow: 0 1px 3px rgba(0,0,0,.8); z-index: 1;
}
