:root {
  --bg: #12161d;
  --bg-2: #171d26;
  --line: #232b37;
  --text: #e7edf5;
  --muted: #8b98a9;
  --her: #2a3444;
  --me: #2f6df6;
  --me-2: #2b5fd9;
  --accent: #4fd1c5;
  --radius: 14px;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  overflow: hidden;
}
.shell {
  position: fixed; top: 0; bottom: 0; left: 0; right: 0;
  display: flex; flex-direction: column;
  width: 100%; max-width: 900px; margin: 0 auto;
  background: var(--bg-2);
  border-left: 1px solid var(--line); border-right: 1px solid var(--line);
  overflow: hidden;
}

/* ── 顶栏 ── */
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px calc(10px + env(safe-area-inset-top, 0px));
  background: rgba(23,29,38,.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  position: relative; z-index: 5;
}
.back { background: none; border: 0; color: var(--text); font-size: 26px; line-height: 1; cursor: pointer; }
.peer { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%;
  display: grid; place-items: center; font-size: 17px; flex: none;
  background: linear-gradient(140deg, #3a7bd5, #22d3ee); color: #06202b; font-weight: 700;
}
.avatar.me { background: linear-gradient(140deg, #7c8cff, #b06bff); color: #150a24; }
.peer-meta { display: flex; flex-direction: column; min-width: 0; }
.peer-meta strong { font-size: 16px; font-weight: 600; }
.state { font-size: 12px; color: var(--muted); }
.state.online { color: var(--accent); }
.top-actions { display: flex; gap: 4px; }
.top-actions button, .icon {
  background: none; border: 0; color: var(--text);
  font-size: 19px; padding: 8px; border-radius: 10px; cursor: pointer;
}
.top-actions button:hover, .icon:hover { background: rgba(255,255,255,.06); }

/* ── 消息区 ── */
.scroller { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 16px 14px 8px; scrollbar-width: thin; }
.list { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.load-more { text-align: center; color: var(--muted); font-size: 13px; padding: 8px 0 14px; cursor: pointer; }
.day { text-align: center; color: var(--muted); font-size: 12px; margin: 14px 0 4px; }

.row { display: flex; gap: 8px; align-items: flex-end; width: 100%; max-width: 100%; min-width: 0; }
.row.me { flex-direction: row-reverse; }
.row .avatar { width: 30px; height: 30px; font-size: 14px; flex: none; }
.bubble-wrap { display: flex; flex-direction: column; gap: 4px; flex: 0 1 auto; max-width: min(76%, 560px); min-width: 0; }
.row.me .bubble-wrap { align-items: flex-end; }
.name { font-size: 12px; color: var(--muted); padding: 0 4px; }
.bubble {
  padding: 9px 13px; border-radius: var(--radius);
  background: var(--her); word-break: break-word; overflow-wrap: anywhere; white-space: pre-wrap;
  border-top-left-radius: 4px; max-width: 100%;
}
.row.me .bubble { background: var(--me); border-top-left-radius: var(--radius); border-top-right-radius: 4px; }
.bubble img.media { max-width: 220px; max-height: 260px; border-radius: 10px; display: block; cursor: zoom-in; }
.bubble audio { max-width: 220px; }
.bubble .face { font-size: 26px; line-height: 1.2; }
.bubble.recalled { background: transparent; border: 1px dashed var(--line); color: var(--muted); font-style: italic; }

/* 2026-11-11：新消息的入场动画。只挂在刚追加的那一条（.newmsg），
   翻历史、整列重绘不动；只用 opacity/transform，不触发布局。 */
.row.newmsg { animation: rowIn .2s cubic-bezier(.2,.8,.25,1) both; }
@keyframes rowIn {
  from { opacity: 0; transform: translateY(8px) scale(.985); }
  to   { opacity: 1; transform: none; }
}
/* 发送中：半透明，等回执；失败：红框 + 提示，点一下重发 */
.row.pending .bubble { opacity: .55; transition: opacity .18s ease-out; }
.row.pending .meta span::after { content: ' · 发送中'; color: var(--muted); }
.row.failed .bubble { box-shadow: inset 0 0 0 1px rgba(224,122,122,.75); }
.row.failed .meta span::after { content: ' · 没发出去，点我重发'; color: #e07a7a; }
@media (prefers-reduced-motion: reduce) {
  .row.newmsg { animation: none; }
}
.quote {
  border-left: 3px solid rgba(255,255,255,.35);
  padding: 3px 8px; margin-bottom: 5px; font-size: 12.5px;
  color: rgba(255,255,255,.75); background: rgba(0,0,0,.16); border-radius: 6px;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.meta { font-size: 11px; color: var(--muted); padding: 0 4px; display: flex; gap: 6px; }
.msg-tools { display: flex; gap: 6px; opacity: 0; transition: opacity .15s; }
.row:hover .msg-tools { opacity: 1; }
.msg-tools button {
  background: rgba(255,255,255,.06); border: 0; color: var(--muted);
  font-size: 11px; padding: 3px 8px; border-radius: 8px; cursor: pointer;
}
.msg-tools button:hover { color: var(--text); }

.typing-hint { display: flex; gap: 4px; padding: 10px 4px; }
.typing-hint span {
  width: 6px; height: 6px; border-radius: 50%; background: var(--muted);
  animation: blink 1.2s infinite;
}
.typing-hint span:nth-child(2) { animation-delay: .2s; }
.typing-hint span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 60%, 100% { opacity: .25 } 30% { opacity: 1 } }

/* ── 回复条 / 表情 ── */
.reply-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px; background: #1d2531; border-top: 1px solid var(--line);
}
.reply-text { flex: 1; min-width: 0; font-size: 13px; color: var(--muted); display: flex; gap: 8px; }
.reply-text b { color: var(--accent); font-weight: 600; flex: none; }
.reply-text span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#replyCancel { background: none; border: 0; color: var(--muted); font-size: 16px; cursor: pointer; }

.emoji-panel {
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px;
  max-height: 168px; overflow-y: auto;
  padding: 10px 12px; background: #1a212b; border-top: 1px solid var(--line);
}
.emoji-panel button { background: none; border: 0; font-size: 22px; padding: 6px 0; cursor: pointer; border-radius: 8px; }
.emoji-panel button:hover { background: rgba(255,255,255,.08); }

.sticker-panel { background: #1a212b; border-top: 1px solid var(--line); padding: 8px 10px 10px; }
.sticker-search {
  width: 100%; box-sizing: border-box; margin-bottom: 8px;
  background: #111721; color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 10px; font: inherit; outline: none;
}
.sticker-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px;
  max-height: 210px; overflow-y: auto;
}
.sticker-grid button {
  background: #131a24; border: 1px solid var(--line); border-radius: 10px;
  padding: 4px; cursor: pointer; aspect-ratio: 1 / 1; overflow: hidden;
  display: grid; place-items: center;
}
.sticker-grid button:hover { border-color: #33507a; }
.sticker-grid img { max-width: 100%; max-height: 100%; object-fit: contain; }
.bubble img.sticker-img { max-width: 140px; max-height: 140px; background: transparent; }

.jump-btn {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: 84px; z-index: 6;
  background: rgba(47,109,246,.92); color: #fff; border: 0;
  border-radius: 999px; padding: 7px 14px; font: inherit; font-size: 13px;
  cursor: pointer; box-shadow: 0 6px 18px rgba(0,0,0,.35);
}

/* ── 输入区 ── */
.composer {
  display: flex; align-items: flex-end; gap: 4px; min-width: 0;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0px));
  background: var(--bg-2); border-top: 1px solid var(--line);
}
#input {
  flex: 1 1 auto; min-width: 0; width: 100%; resize: none; max-height: 140px;
  background: #111721; color: var(--text);
  border: 1px solid var(--line); border-radius: 20px;
  padding: 10px 14px; font: inherit; outline: none;
}
#input:focus { border-color: #33507a; }
.send {
  background: var(--me); color: #fff; border: 0; border-radius: 18px;
  padding: 10px 16px; font: inherit; font-weight: 600; cursor: pointer; flex: none;
  min-height: 44px;                 /* 手指按得到的尺寸，别做成小细条 */
  touch-action: manipulation;       /* 连点不要触发双击缩放，也别等 300ms */
  -webkit-tap-highlight-color: transparent;
}
.send:active { transform: scale(.97); }
.send:disabled { opacity: .4; }
.composer .icon { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.mic-on { color: #ff6b6b !important; }

/* 图片预览 */
.lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,.86);
  display: grid; place-items: center; z-index: 50; padding: 20px;
}
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }

@media (max-width: 520px) {
  .bubble-wrap { max-width: 84%; }
  .bubble img.media { max-width: 180px; }
}
