* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  font: 15px/1.45 -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: #e9ebee;
  color: #1a1a1a;
  overflow: hidden;
}

.phone {
  display: flex; flex-direction: column;
  height: 100%; max-width: 430px; margin: 0 auto;
  background: #f2f3f5;
  position: relative;
  box-shadow: 0 0 24px rgba(0,0,0,.12);
}

/* ---------- 顶栏 ---------- */
.bar {
  flex: none; display: flex; align-items: center; gap: 6px;
  height: 52px; padding: 0 8px;
  background: #fff; border-bottom: 1px solid #e6e8eb;
  position: relative; z-index: 5;
}
.back, .gear {
  border: 0; background: none; padding: 6px; color: #333;
  display: flex; align-items: center; justify-content: center;
  border-radius: 10px; cursor: pointer;
}
.back:active, .gear:active { background: #f0f1f3; }
.title-wrap { flex: 1; text-align: center; overflow: hidden; }
.title { font-size: 16px; font-weight: 600; letter-spacing: .3px; }
.sub { font-size: 11px; color: #9aa0a6; margin-top: 1px; }
.sub.on { color: #06b56a; }

/* ---------- 消息区 ---------- */
.list {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  padding: 14px 12px 18px;
  display: flex; flex-direction: column; gap: 12px;
  scroll-behavior: smooth;
}
.list::-webkit-scrollbar { width: 0; }

.sys { align-self: center; font-size: 11px; color: #98a0a8; background: #e3e6ea; padding: 3px 10px; border-radius: 10px; }
.time { align-self: center; font-size: 11px; color: #a3a9b0; margin: 2px 0; }

.msg { display: flex; align-items: flex-start; gap: 8px; max-width: 100%; }
.msg.me { flex-direction: row-reverse; }

.avatar {
  flex: none; width: 38px; height: 38px; border-radius: 9px;
  background-size: cover; background-position: center;
  border: 1px solid rgba(0,0,0,.05);
}
.avatar.bot { background-image: url("/static/avatar-bot.jpg"); }
.avatar.me { background-image: url("/static/avatar-user.jpg"); }

.bubble {
  max-width: 66%;
  padding: 9px 13px;
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,.06);
  font-size: 15px; line-height: 1.42;
  word-break: break-word; white-space: pre-wrap;
  animation: pop .16s ease-out;
  position: relative;
}
.msg.me .bubble { background: linear-gradient(180deg, #29b6f6, #149fe8); color: #fff; box-shadow: 0 1px 3px rgba(20,159,232,.35); }
.bubble img { display: block; max-width: 180px; border-radius: 5px; }

.bubble.typing { display: flex; gap: 4px; padding: 12px 14px; }
.bubble.typing i {
  width: 6px; height: 6px; border-radius: 50%; background: #b9c0c8;
  animation: blink 1.2s infinite ease-in-out;
}
.bubble.typing i:nth-child(2) { animation-delay: .18s; }
.bubble.typing i:nth-child(3) { animation-delay: .36s; }

@keyframes blink { 0%,80%,100% { opacity: .3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-2px); } }
@keyframes pop { from { opacity: 0; transform: translateY(4px) scale(.98); } to { opacity: 1; transform: none; } }

/* ---------- 底栏 ---------- */
.inputbar {
  flex: none; display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: #f7f8fa; border-top: 1px solid #e6e8eb;
}
.plus {
  flex: none; width: 36px; height: 36px; border-radius: 50%;
  border: 1px solid #d5d9de; background: #fff; color: #5b636b;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.plus:active { background: #eef0f3; }
.field { flex: 1; background: #fff; border: 1px solid #e2e5e9; border-radius: 18px; padding: 4px 10px; min-height: 36px; display: flex; flex-direction: column; }
.field textarea {
  border: 0; outline: 0; resize: none; background: none;
  font: inherit; max-height: 96px; padding: 5px 2px; line-height: 1.4;
  width: 100%;
}
.thumb { position: relative; width: 56px; height: 56px; margin: 2px 0 6px; }
.thumb img { width: 100%; height: 100%; object-fit: cover; border-radius: 6px; }
.thumb .x {
  position: absolute; top: -6px; right: -6px; width: 18px; height: 18px;
  border-radius: 50%; background: rgba(0,0,0,.55); color: #fff;
  font-size: 13px; line-height: 18px; text-align: center; cursor: pointer;
}
.send {
  flex: none; width: 38px; height: 38px; border-radius: 50%; border: 0;
  background: linear-gradient(180deg, #29b6f6, #149fe8); color: #fff;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  box-shadow: 0 2px 6px rgba(20,159,232,.35);
}
.send:disabled { opacity: .45; box-shadow: none; }

/* ---------- 设置面板 ---------- */
.sheet {
  position: fixed; inset: 0; background: rgba(0,0,0,.35);
  display: flex; align-items: center; justify-content: center; z-index: 20;
  padding: 20px;
}
.sheet[hidden], .thumb[hidden] { display: none !important; }
.sheet-card {
  width: 100%; max-width: 360px; background: #fff; border-radius: 14px;
  padding: 18px; display: flex; flex-direction: column; gap: 12px;
}
.sheet-card h3 { margin: 0 0 2px; font-size: 17px; }
.sheet-card label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: #6b7280; }
.sheet-card input {
  border: 1px solid #dfe3e8; border-radius: 8px; padding: 8px 10px;
  font: inherit; font-size: 13px; color: #111; outline: 0;
}
.sheet-card input:focus { border-color: #29b6f6; }
.row { display: flex; gap: 10px; margin-top: 4px; }
.row button { flex: 1; border-radius: 9px; padding: 10px; font: inherit; font-size: 14px; cursor: pointer; border: 0; }
.primary { background: #149fe8; color: #fff; }
.ghost { background: #f1f3f5; color: #50575e; }
.hint { margin: 0; font-size: 11px; color: #98a0a8; min-height: 14px; }

@media (max-width: 430px) {
  .phone { max-width: none; box-shadow: none; }
  .bubble { max-width: 72%; }
}
.bubble.meme {
  background: transparent;
  padding: 0;
  box-shadow: none;
}
.bubble img.meme-img {
  max-width: 160px;
  max-height: 200px;
  border-radius: 10px;
  display: block;
}
.plus.on {
  color: #149fe8;
  background: #e4f4fe;
}
.bubble.voice {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 92px;
  padding: 9px 12px;
  cursor: pointer;
  user-select: none;
}
.bubble.voice .play {
  font-size: 11px;
  color: #7d8794;
}
.bubble.voice .bars {
  display: inline-flex;
  align-items: flex-end;
  gap: 2px;
  height: 12px;
}
.bubble.voice .bars i {
  width: 2px;
  background: #a9b3bf;
  border-radius: 1px;
  height: 40%;
}
.bubble.voice .bars i:nth-child(2) { height: 90%; }
.bubble.voice .bars i:nth-child(3) { height: 60%; }
.bubble.voice .dur { font-size: 12px; color: #7d8794; margin-left: 2px; }
.bubble.voice.playing .bars i { background: #149fe8; animation: vb .7s infinite alternate; }
.bubble.voice.playing .bars i:nth-child(2) { animation-delay: .2s; }
.bubble.voice.playing .bars i:nth-child(3) { animation-delay: .4s; }
@keyframes vb { from { height: 25%; } to { height: 100%; } }
.bubble.voice.fail { opacity: .55; }

.sub.typing { color: #149fe8; }
.sub.typing::after { content: ''; }

/* 翻唱/音频气泡 */
.bubble.audio { background: #fff; padding: 6px 8px; }
.bubble.audio audio { display: block; width: 240px; height: 36px; }


/* ---- 群聊：别人发的消息 ---- */
.msg.peer .col { display: flex; flex-direction: column; align-items: flex-start; gap: 3px;
  max-width: 66%; min-width: 0; flex: 0 1 auto; }
.msg.peer .bubble { max-width: 56vw; writing-mode: horizontal-tb; word-break: normal;
  overflow-wrap: anywhere; white-space: pre-wrap; }
.msg.peer .name { font-size: 11px; color: #97a1ad; padding-left: 2px; }
.avatar.txt {
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 600; color: #4a6fa5;
  background: #e9f0f9;
}


/* ---- 聊天列表抽屉 ---- */
.drawer-mask { position: absolute; inset: 0; background: rgba(0,0,0,.28); z-index: 30; }
.drawer {
  position: absolute; top: 0; left: 0; bottom: 0; width: 78%; max-width: 300px;
  background: #f7f8fa; z-index: 31; display: flex; flex-direction: column;
  box-shadow: 2px 0 12px rgba(0,0,0,.12);
}
.drawer-head { padding: 16px 16px 10px; font-size: 13px; color: #8a94a0; }
.chat-item { display: flex; align-items: center; gap: 10px; padding: 11px 16px; background: #fff; border-bottom: 1px solid #f0f2f5; cursor: pointer; }
.chat-item:active { background: #eef4fb; }
.chat-item.on { background: #e9f2fd; }
.ci-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.ci-name { font-size: 15px; color: #1f2733; }
.ci-sub { font-size: 12px; color: #97a1ad; }
.drawer-foot { margin-top: auto; padding: 14px 16px; font-size: 12px; color: #8a94a0; display: flex; justify-content: space-between; align-items: center; }
.linkbtn { border: 0; background: none; color: #149fe8; font-size: 12px; padding: 0; }
.avatar.grp { background: #e9f0f9; }

.drawer-head { display: flex; align-items: center; justify-content: space-between; }
.drawer-x { border: 0; background: none; font-size: 20px; line-height: 1; color: #97a1ad; padding: 0 2px; }

.drawer[hidden], .drawer-mask[hidden] { display: none !important; }

/* 头像选择面板 */
.avmask { position: fixed; inset: 0; background: rgba(15, 25, 35, .45); display: flex;
  align-items: center; justify-content: center; z-index: 60; padding: 20px; }
.avbox { background: #fff; border-radius: 16px; padding: 16px 14px 14px; width: 100%;
  max-width: 320px; box-shadow: 0 18px 50px rgba(10, 30, 50, .25); }
.avtitle { font-size: 15px; font-weight: 600; color: #1d2b3a; text-align: center; }
.avsub { font-size: 11px; color: #97a1ad; text-align: center; margin: 4px 0 12px; }
.avgrid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.avopt { font-size: 22px; line-height: 1; padding: 8px 0; border-radius: 12px; border: 1px solid #e6eef7;
  background: #f7fafd; cursor: pointer; }
.avopt:active { transform: scale(.94); }
.avup { display: block; width: 100%; margin-top: 12px; padding: 10px; border: 0; border-radius: 12px;
  background: linear-gradient(180deg, #29b6f6, #149fe8); color: #fff; font-size: 13px; cursor: pointer; }
.avatar.pic { background-size: cover; background-position: center; }

/* 群主标识 */
.badge { display: inline-block; margin-left: 4px; padding: 0 5px; border-radius: 6px;
  font-size: 10px; line-height: 15px; color: #7a5200;
  background: linear-gradient(180deg, #ffe08a, #f6c049); border: 1px solid #e0a92e; }
