/* 小窝 · 界面样式 */
:root {
  --bg: #070b14;
  --bg-soft: #0b1220;
  --panel: rgba(16, 24, 40, 0.72);
  --panel-solid: #101828;
  --line: rgba(148, 163, 184, 0.13);
  --line-strong: rgba(148, 163, 184, 0.24);
  --text: #e8eefb;
  --muted: #8fa0ba;
  --muted-2: #64748b;
  --accent: #6366f1;
  --accent-2: #22d3ee;
  --bubble: #141e33;
  --danger: #fb7185;
  --ok: #34d399;
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
.hidden { display: none !important; }

/* ---------------- 进入页 ---------------- */
.screen { position: fixed; inset: 0; }
.join {
  display: grid;
  place-items: center;
  padding: 20px;
  overflow: hidden;
  background:
    radial-gradient(1000px 600px at 15% 0%, rgba(99, 102, 241, 0.16), transparent 60%),
    radial-gradient(900px 700px at 90% 100%, rgba(34, 211, 238, 0.11), transparent 55%),
    var(--bg);
}
.aurora { position: absolute; inset: 0; filter: blur(70px); opacity: 0.55; pointer-events: none; }
.aurora i { position: absolute; display: block; border-radius: 50%; animation: drift 16s ease-in-out infinite alternate; }
.aurora i:nth-child(1) { width: 380px; height: 380px; left: -80px; top: 8%; background: rgba(79, 70, 229, 0.55); }
.aurora i:nth-child(2) { width: 300px; height: 300px; right: -60px; top: 22%; background: rgba(14, 165, 233, 0.4); animation-delay: -5s; }
.aurora i:nth-child(3) { width: 340px; height: 340px; left: 38%; bottom: -120px; background: rgba(168, 85, 247, 0.32); animation-delay: -9s; }
@keyframes drift {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to { transform: translate3d(30px, -26px, 0) scale(1.12); }
}

.join-card {
  position: relative;
  width: min(400px, 100%);
  padding: 36px 32px 24px;
  border-radius: 26px;
  background: rgba(13, 20, 35, 0.74);
  border: 1px solid var(--line);
  box-shadow: 0 40px 100px -30px rgba(0, 0, 0, 0.9), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(24px) saturate(1.2);
  -webkit-backdrop-filter: blur(24px) saturate(1.2);
  text-align: center;
  animation: rise 0.5s cubic-bezier(0.2, 0.7, 0.3, 1) both;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(14px) scale(0.985); }
  to { opacity: 1; transform: none; }
}
.logo { width: 64px; height: 64px; margin: 0 auto 16px; filter: drop-shadow(0 10px 24px rgba(99, 102, 241, 0.45)); }
.logo svg { width: 100%; height: 100%; display: block; }
.logo.small { width: 38px; height: 38px; margin: 0; filter: drop-shadow(0 4px 12px rgba(99, 102, 241, 0.35)); }
.join-card h1 { margin: 0; font-size: 30px; letter-spacing: 0.14em; font-weight: 700; }
.tagline { margin: 8px 0 26px; font-size: 13px; color: var(--muted); letter-spacing: 0.04em; }

.field { display: block; text-align: left; margin-bottom: 14px; }
.field > span { display: block; margin: 0 0 7px 2px; font-size: 12px; color: var(--muted); letter-spacing: 0.05em; }
.field input {
  width: 100%;
  height: 47px;
  padding: 0 14px;
  border-radius: 12px;
  background: rgba(2, 6, 23, 0.55);
  border: 1px solid var(--line);
  outline: none;
  font-size: 15px;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
.field input::placeholder { color: var(--muted-2); }
.field input:focus {
  border-color: rgba(99, 102, 241, 0.7);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.16);
  background: rgba(2, 6, 23, 0.75);
}
#code-field input { letter-spacing: 0.16em; text-transform: uppercase; }

.primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  height: 48px;
  margin-top: 6px;
  border-radius: 13px;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(135deg, #6366f1, #7c3aed 55%, #0ea5e9);
  box-shadow: 0 12px 30px -10px rgba(99, 102, 241, 0.8);
  transition: transform 0.12s, box-shadow 0.2s, opacity 0.2s;
}
.primary:hover { transform: translateY(-1px); box-shadow: 0 16px 34px -10px rgba(99, 102, 241, 0.9); }
.primary:active { transform: translateY(0) scale(0.995); }
.primary:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }
.primary svg { width: 18px; height: 18px; }

.error { min-height: 18px; margin: 12px 0 0; font-size: 12.5px; color: var(--danger); line-height: 1.5; }
.join-foot { margin: 18px 0 0; font-size: 11.5px; color: var(--muted-2); }

/* ---------------- 聊天骨架 ---------------- */
.chat { display: flex; flex-direction: row; height: 100dvh; position: relative; background:
  radial-gradient(900px 500px at 80% -10%, rgba(99, 102, 241, 0.12), transparent 60%),
  radial-gradient(700px 500px at 0% 110%, rgba(34, 211, 238, 0.07), transparent 60%),
  var(--bg);
}
.chat-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; position: relative; }

/* 左侧导航：聊天 / 表情 / 记忆 / 设置 */
.rail {
  flex: 0 0 78px;
  width: 78px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 8px calc(14px + var(--safe-b));
  background: #070c16;
  border-right: 1px solid var(--line);
  z-index: 7;
}
.rail-logo { width: 38px; height: 38px; margin-bottom: 10px; filter: drop-shadow(0 4px 12px rgba(99, 102, 241, 0.35)); }
.rail-logo svg { width: 100%; height: 100%; display: block; }
.rail-item {
  width: 60px;
  height: 58px;
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  color: var(--muted);
  font-size: 10.5px;
  letter-spacing: 0.04em;
  transition: background 0.15s, color 0.15s;
}
.rail-item svg { width: 21px; height: 21px; }
.rail-item:hover { background: rgba(148, 163, 184, 0.08); color: #e2e8f0; }
.rail-item.active {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.24), rgba(34, 211, 238, 0.1));
  color: #c7d2fe;
}
.rail-item.active svg { color: #a5b4fc; }
.rail-spacer { flex: 1 1 auto; }

@media (min-width: 761px) {
  .topbar .logo.small { display: none; }
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(11px + env(safe-area-inset-top, 0px)) 18px 11px;
  background: rgba(8, 13, 24, 0.72);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  z-index: 6;
}
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand-text { min-width: 0; }
.brand-text h1 { margin: 0; font-size: 16px; font-weight: 650; letter-spacing: 0.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conn { display: flex; align-items: center; gap: 6px; margin: 3px 0 0; font-size: 11px; color: var(--muted); }
.status-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.14); }
.status-dot.offline { background: #f59e0b; box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.14); animation: blink 1.2s ease-in-out infinite; }
@keyframes blink { 50% { opacity: 0.35; } }

.top-actions { display: flex; align-items: center; gap: 8px; }
.ghost {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 36px;
  min-width: 36px;
  padding: 0 11px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: rgba(148, 163, 184, 0.05);
  color: #cbd5e1;
  font-size: 13px;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.ghost:hover { background: rgba(148, 163, 184, 0.12); border-color: var(--line-strong); color: #fff; }
.ghost svg { width: 17px; height: 17px; }
#online-count { font-variant-numeric: tabular-nums; }

.presence {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 20px;
  font-size: 11.5px;
  color: var(--muted);
  border-bottom: 1px solid rgba(148, 163, 184, 0.06);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 0 0 auto;
}
.live-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--ok); flex: 0 0 auto; }

/* ---------------- 消息区 ---------------- */
.messages {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  padding: 18px 20px 6px;
  scrollbar-width: thin;
  scrollbar-color: rgba(148, 163, 184, 0.28) transparent;
}
.messages::-webkit-scrollbar { width: 8px; }
.messages::-webkit-scrollbar-thumb { background: rgba(148, 163, 184, 0.24); border-radius: 8px; }
.messages::-webkit-scrollbar-track { background: transparent; }

.msg {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  width: 100%;
  max-width: 880px;
  margin: 0 auto;
  padding: 5px 0;
  animation: pop 0.18s ease-out both;
}
@keyframes pop { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }
.msg.own { flex-direction: row-reverse; }
.msg.cont { padding-top: 1px; }
.msg.cont .avatar, .msg.cont .meta { visibility: hidden; height: 0; margin: 0; overflow: hidden; }
.msg .avatar {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  font-size: 14px;
  font-weight: 650;
  color: #fff;
  background: linear-gradient(135deg, var(--c, #6366f1), #0b1220 135%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.22);
  text-transform: uppercase;
  user-select: none;
}
.msg .body { display: flex; flex-direction: column; align-items: flex-start; max-width: min(74%, 560px); min-width: 0; }
.msg.own .body { align-items: flex-end; }
.msg .meta { display: flex; align-items: baseline; gap: 8px; margin: 0 0 4px 3px; height: 15px; }
.msg.own .meta { flex-direction: row-reverse; margin: 0 3px 4px 0; }
.msg .name { font-size: 11.5px; color: #a5b4fc; font-weight: 600; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg.own .name { color: #7dd3fc; }
.msg .time { font-size: 10px; color: var(--muted-2); font-variant-numeric: tabular-nums; }
.bot-tag {
  display: inline-block;
  padding: 1px 5px;
  border-radius: 5px;
  font-size: 9px;
  line-height: 1.4;
  color: #a5b4fc;
  background: rgba(99, 102, 241, 0.18);
  border: 1px solid rgba(99, 102, 241, 0.3);
  letter-spacing: 0.04em;
}

.bubble {
  position: relative;
  padding: 9px 13px;
  border-radius: 15px;
  background: var(--bubble);
  border: 1px solid rgba(148, 163, 184, 0.09);
  font-size: 14.5px;
  line-height: 1.58;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  box-shadow: 0 2px 8px -4px rgba(0, 0, 0, 0.5);
}
.msg.own .bubble {
  background: linear-gradient(135deg, #5b5ef0, #6d5cf6 55%, #7c3aed);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 6px 18px -8px rgba(99, 102, 241, 0.8);
}
.bubble a { color: #93c5fd; text-decoration: underline; text-underline-offset: 2px; }
.msg.own .bubble a { color: #e0f2fe; }
.bubble.has-media { padding: 4px; background: rgba(20, 30, 51, 0.9); border-color: rgba(148, 163, 184, 0.14); }
.msg.own .bubble.has-media { background: rgba(30, 27, 75, 0.55); }
.bubble .caption { padding: 6px 9px 5px; white-space: pre-wrap; }

.att-img {
  display: block;
  max-width: min(300px, 62vw);
  max-height: 330px;
  width: auto;
  height: auto;
  border-radius: 11px;
  cursor: zoom-in;
  background: rgba(2, 6, 23, 0.4);
}
.att-file {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 190px;
  max-width: 300px;
  padding: 9px 10px;
  border-radius: 11px;
  text-decoration: none;
  color: inherit;
  background: rgba(2, 6, 23, 0.28);
}
.att-file:hover { background: rgba(2, 6, 23, 0.45); }
.att-file .ficon {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: rgba(99, 102, 241, 0.2);
  color: #c7d2fe;
}
.att-file .ficon svg { width: 18px; height: 18px; }
.att-file .fmeta { min-width: 0; }
.att-file b { display: block; font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.att-file small { display: block; margin-top: 2px; font-size: 10.5px; color: var(--muted); }

.day { display: flex; justify-content: center; width: 100%; max-width: 880px; margin: 16px auto 10px; }
.day span {
  padding: 3px 11px;
  border-radius: 999px;
  font-size: 10.5px;
  color: var(--muted);
  background: rgba(148, 163, 184, 0.08);
  border: 1px solid rgba(148, 163, 184, 0.08);
  letter-spacing: 0.06em;
}
.load-more {
  display: block;
  margin: 4px auto 10px;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 11.5px;
  color: var(--muted);
  border: 1px solid var(--line);
  background: rgba(148, 163, 184, 0.05);
}
.load-more:hover { color: var(--text); border-color: var(--line-strong); }

.empty {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
  padding: 28px;
  color: var(--muted);
}
.empty .big { font-size: 42px; line-height: 1; filter: drop-shadow(0 8px 20px rgba(99, 102, 241, 0.35)); }
.empty h2 { margin: 4px 0 0; font-size: 17px; color: #dbeafe; font-weight: 600; }
.empty p { margin: 0; font-size: 12.5px; line-height: 1.7; max-width: 320px; }
.empty p.sub { margin-top: 4px; font-size: 11px; color: var(--muted-2); }

/* ---------------- 输入区 ---------------- */
.composer {
  flex: 0 0 auto;
  padding: 6px 16px calc(11px + var(--safe-b));
  background: linear-gradient(to top, rgba(7, 11, 20, 0.98) 30%, rgba(7, 11, 20, 0.82));
  border-top: 1px solid rgba(148, 163, 184, 0.08);
  z-index: 4;
}
.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  width: 100%;
  max-width: 880px;
  margin: 0 auto;
  padding: 5px 6px;
  border-radius: 19px;
  background: rgba(17, 26, 44, 0.82);
  border: 1px solid var(--line);
  box-shadow: 0 10px 30px -18px rgba(0, 0, 0, 0.9);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.composer-row:focus-within { border-color: rgba(99, 102, 241, 0.45); box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.08); }
.icon-btn {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: #9db0c9;
  transition: background 0.15s, color 0.15s, transform 0.1s;
}
.icon-btn:hover { background: rgba(148, 163, 184, 0.1); color: #e2e8f0; }
.icon-btn:active { transform: scale(0.94); }
.icon-btn svg { width: 21px; height: 21px; }
#input {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 20px;
  max-height: 132px;
  padding: 9px 4px;
  border: 0;
  outline: none;
  resize: none;
  background: transparent;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  scrollbar-width: none;
}
#input::placeholder { color: var(--muted-2); }
#input::-webkit-scrollbar { display: none; }
.send-btn {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(135deg, #6366f1, #7c3aed 60%, #0ea5e9);
  box-shadow: 0 6px 18px -8px rgba(99, 102, 241, 0.9);
  transition: transform 0.12s, opacity 0.15s, filter 0.15s;
}
.send-btn svg { width: 20px; height: 20px; }
.send-btn:hover { filter: brightness(1.08); }
.send-btn:active { transform: scale(0.94); }
.send-btn:disabled { opacity: 0.35; cursor: not-allowed; filter: grayscale(0.4); }

.upload-tip {
  width: 100%;
  max-width: 880px;
  margin: 0 auto 6px;
  padding: 0 6px;
  font-size: 11.5px;
  color: var(--muted);
}
.progress { height: 3px; margin-top: 5px; border-radius: 3px; background: rgba(148, 163, 184, 0.15); overflow: hidden; }
.progress i { display: block; height: 100%; width: 0%; border-radius: 3px; background: linear-gradient(90deg, #6366f1, #22d3ee); transition: width 0.2s; }

.jump-new {
  position: absolute;
  left: 50%;
  bottom: calc(92px + var(--safe-b));
  transform: translateX(-50%) translateY(6px);
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 13px;
  border-radius: 999px;
  font-size: 11.5px;
  color: #e0e7ff;
  background: rgba(49, 46, 129, 0.86);
  border: 1px solid rgba(129, 140, 248, 0.4);
  box-shadow: 0 8px 24px -8px rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(8px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
  z-index: 3;
}
.jump-new.show { opacity: 1; pointer-events: auto; transform: translateX(-50%) translateY(0); }
.jump-new svg { width: 14px; height: 14px; }

.typing {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 22px 3px;
  height: 20px;
  font-size: 11.5px;
  color: var(--muted);
  flex: 0 0 auto;
}
.dots { display: inline-flex; gap: 2.5px; align-items: center; }
.dots i { width: 3.5px; height: 3.5px; border-radius: 50%; background: #818cf8; animation: bounce 1.1s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: 0.15s; }
.dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: 0.5; } 30% { transform: translateY(-3px); opacity: 1; } }

/* ---------------- 表情 / 弹窗 ---------------- */
.emoji-panel {
  position: fixed;
  left: 50%;
  bottom: calc(86px + var(--safe-b));
  transform: translateX(-50%);
  width: min(380px, calc(100vw - 24px));
  max-height: 330px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  border-radius: 16px;
  background: rgba(13, 20, 35, 0.97);
  border: 1px solid var(--line-strong);
  box-shadow: 0 24px 60px -20px rgba(0, 0, 0, 0.95);
  backdrop-filter: blur(18px);
  z-index: 30;
  animation: panelIn 0.14s ease-out both;
}
@keyframes panelIn {
  from { opacity: 0; transform: translate(-50%, 6px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}
.panel-tabs { display: flex; gap: 4px; padding: 3px; border-radius: 10px; background: rgba(2, 6, 23, 0.5); flex: 0 0 auto; }
.panel-tab { flex: 1 1 0; padding: 6px 0; border-radius: 8px; font-size: 12px; color: var(--muted); transition: background 0.12s, color 0.12s; }
.panel-tab.active { background: rgba(99, 102, 241, 0.22); color: #e0e7ff; font-weight: 600; }
.panel-tab:hover { color: #e2e8f0; }
.emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; overflow-y: auto; padding: 2px; }
.emoji-grid button { font-size: 21px; line-height: 1; padding: 6px 0; border-radius: 9px; transition: background 0.12s, transform 0.1s; }
.emoji-grid button:hover { background: rgba(148, 163, 184, 0.14); transform: scale(1.12); }
.sticker-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; padding: 4px; overflow-y: auto; }
.sticker-grid button { position: relative; padding: 0; border-radius: 12px; overflow: hidden; transition: transform 0.12s, filter 0.12s; background: transparent; }
.sticker-grid button:hover { transform: translateY(-2px) scale(1.03); filter: brightness(1.05); }
.sticker-grid img { width: 100%; aspect-ratio: 1 / 1; display: block; }
.sticker-grid .sticker-add {
  display: grid;
  place-items: center;
  aspect-ratio: 1 / 1;
  border: 1.5px dashed rgba(148, 163, 184, 0.35);
  color: var(--muted);
  font-size: 30px;
  line-height: 1;
  background: rgba(148, 163, 184, 0.04);
}
.sticker-grid .sticker-add:hover { border-color: rgba(129, 140, 248, 0.7); color: #c7d2fe; background: rgba(99, 102, 241, 0.1); }
.sticker-del {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 13px;
  line-height: 1;
  color: #fff;
  background: rgba(15, 23, 42, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.28);
  opacity: 0;
  transition: opacity 0.12s, background 0.12s;
}
.sticker-grid button:hover .sticker-del { opacity: 1; }
.sticker-del:hover { background: rgba(244, 63, 94, 0.9); }

/* 聊天里的贴纸 */
.bubble.has-sticker { background: transparent; border: 0; padding: 0; box-shadow: none; }
.msg.own .bubble.has-sticker { background: transparent; box-shadow: none; }
.sticker-img {
  display: block;
  width: 148px;
  height: 148px;
  cursor: zoom-in;
  filter: drop-shadow(0 10px 20px rgba(0, 0, 0, 0.45));
  transition: transform 0.12s;
}
.sticker-img:hover { transform: scale(1.03); }

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(2, 6, 23, 0.66);
  backdrop-filter: blur(7px);
  z-index: 50;
  animation: fade 0.16s ease-out both;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal-card {
  position: relative;
  width: min(372px, 100%);
  padding: 26px 24px 20px;
  border-radius: 22px;
  background: linear-gradient(180deg, #111a2c, #0c1424);
  border: 1px solid var(--line-strong);
  box-shadow: 0 40px 100px -30px rgba(0, 0, 0, 0.95);
  text-align: center;
  animation: rise 0.22s ease-out both;
}
.modal-close { position: absolute; top: 12px; right: 12px; width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; color: var(--muted); }
.modal-close:hover { background: rgba(148, 163, 184, 0.12); color: #fff; }
.modal-close svg { width: 16px; height: 16px; }
.modal-card h2 { margin: 2px 0 6px; font-size: 18px; font-weight: 650; }
.modal-sub { margin: 0 0 16px; font-size: 12px; color: var(--muted); }
.qr-wrap { width: 184px; height: 184px; margin: 0 auto 14px; padding: 9px; border-radius: 15px; background: #fff; display: grid; place-items: center; }
.qr-wrap img { width: 100%; height: 100%; display: block; border-radius: 6px; }
.invite-url { display: flex; gap: 6px; }
.invite-url input {
  flex: 1 1 auto;
  min-width: 0;
  height: 38px;
  padding: 0 10px;
  border-radius: 10px;
  background: rgba(2, 6, 23, 0.55);
  border: 1px solid var(--line);
  font-size: 12px;
  color: #cbd5e1;
  outline: none;
}
.invite-url button {
  flex: 0 0 auto;
  padding: 0 15px;
  border-radius: 10px;
  font-size: 12.5px;
  font-weight: 600;
  color: #e0e7ff;
  background: rgba(99, 102, 241, 0.2);
  border: 1px solid rgba(99, 102, 241, 0.35);
}
.invite-url button:hover { background: rgba(99, 102, 241, 0.3); }
.host-select {
  width: 100%;
  height: 36px;
  margin-top: 8px;
  padding: 0 9px;
  border-radius: 10px;
  background: rgba(2, 6, 23, 0.55);
  border: 1px solid var(--line);
  font-size: 12px;
  color: #cbd5e1;
  outline: none;
}
.modal-row { display: flex; gap: 8px; margin-top: 12px; }
.secondary {
  flex: 1 1 0;
  height: 38px;
  border-radius: 11px;
  font-size: 12.5px;
  color: #dbe4f3;
  background: rgba(148, 163, 184, 0.08);
  border: 1px solid var(--line);
}
.secondary:hover { background: rgba(148, 163, 184, 0.15); }
.secondary.full { flex: none; width: 100%; margin-top: 9px; }
.install-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: 100%;
  height: 40px;
  margin-top: 10px;
  border-radius: 11px;
  font-size: 12.5px;
  font-weight: 600;
  color: #e0e7ff;
  background: rgba(99, 102, 241, 0.2);
  border: 1px solid rgba(99, 102, 241, 0.38);
  transition: background 0.15s;
}
.install-btn:hover { background: rgba(99, 102, 241, 0.3); }
.install-btn svg { width: 16px; height: 16px; }

.modal-tip { margin: 13px 0 0; font-size: 10.5px; line-height: 1.6; color: var(--muted-2); }
.bot-card { max-height: 92vh; overflow-y: auto; text-align: left; }
.bot-card h2, .bot-card .modal-sub { text-align: center; }
.bot-card .field { margin-bottom: 10px; }
.bot-card .field > span { margin-bottom: 5px; }
.bot-card .field input, .bot-card .field select {
  width: 100%;
  height: 40px;
  padding: 0 10px;
  border-radius: 10px;
  background: rgba(2, 6, 23, 0.55);
  border: 1px solid var(--line);
  font-size: 13px;
  outline: none;
}
.bot-card .field textarea {
  width: 100%;
  min-height: 120px;
  padding: 9px 10px;
  border-radius: 10px;
  background: rgba(2, 6, 23, 0.55);
  border: 1px solid var(--line);
  font-family: var(--font);
  font-size: 12px;
  line-height: 1.65;
  color: var(--text);
  outline: none;
  resize: vertical;
}
.bot-card .field input:focus, .bot-card .field select:focus { border-color: rgba(99, 102, 241, 0.7); }
.bot-card #bot-token { font-size: 11px; letter-spacing: 0.02em; color: #c7d2fe; }
#bot-test-result { min-height: 16px; color: #a5b4fc; }
.check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 2px 0 12px;
  font-size: 13px;
  color: #dbe4f3;
}
.check input { width: 17px; height: 17px; accent-color: #6366f1; }

.danger-link {
  margin-top: 12px;
  padding: 4px 8px;
  font-size: 10.5px;
  color: var(--muted-2);
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
}
.danger-link:hover { color: var(--danger); background: rgba(251, 113, 133, 0.08); }

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.9);
  cursor: zoom-out;
  animation: fade 0.15s ease-out both;
}
.lightbox img { max-width: 94vw; max-height: 90vh; border-radius: 8px; box-shadow: 0 30px 80px rgba(0, 0, 0, 0.8); }
.lightbox-save {
  position: fixed;
  left: 50%;
  bottom: calc(28px + var(--safe-b));
  transform: translateX(-50%);
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  color: #e0e7ff;
  background: rgba(49, 46, 129, 0.92);
  border: 1px solid rgba(129, 140, 248, 0.5);
  box-shadow: 0 12px 30px -10px rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(8px);
}
.lightbox-save:hover { background: rgba(67, 56, 202, 0.95); }
.lightbox-save:disabled { opacity: 0.6; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(104px + var(--safe-b));
  transform: translate(-50%, 10px);
  max-width: calc(100vw - 40px);
  padding: 9px 16px;
  border-radius: 999px;
  background: rgba(30, 41, 59, 0.96);
  border: 1px solid var(--line-strong);
  color: #e2e8f0;
  font-size: 12.5px;
  box-shadow: 0 12px 30px -10px rgba(0, 0, 0, 0.9);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 90;
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------------- 小屏 ---------------- */
@media (max-width: 640px) {
  .join-card { padding: 30px 22px 20px; border-radius: 22px; }
  .join-card h1 { font-size: 26px; }
  .field input, #input { font-size: 16px; } /* 小于 16px 时 iOS 会自动放大页面 */
  .topbar { padding: calc(9px + env(safe-area-inset-top, 0px)) 13px 9px; }
  .presence { padding: 6px 15px; }
  .messages { padding: 14px 12px 4px; }
  .msg .body { max-width: 78%; }
  .msg .avatar { width: 31px; height: 31px; border-radius: 10px; font-size: 13px; }
  .bubble { font-size: 14px; }
  .composer { padding: 5px 9px calc(9px + var(--safe-b)); }
  .icon-btn { width: 36px; }
  .send-btn { width: 38px; height: 38px; }
  .att-img { max-width: min(260px, 66vw); max-height: 280px; }
  .emoji-panel { bottom: calc(80px + var(--safe-b)); }
  .emoji-grid { grid-template-columns: repeat(7, 1fr); }
  .sticker-grid { grid-template-columns: repeat(4, 1fr); gap: 6px; }
  .sticker-img { width: 128px; height: 128px; }
  .ghost { padding: 0 9px; }
  .jump-new { bottom: calc(88px + var(--safe-b)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

/* 手机端：关掉最耗性能的模糊/动画，鸿蒙 WebView 会明显快一些 */
@media (max-width: 760px) {
  .rail { display: none; }
  .topbar, .composer, .emoji-panel, .modal-card, .join-card {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
  }
  .aurora { display: none; }
  .msg { animation: none; }
  .bubble { box-shadow: none; }
  .sticker-img { filter: none; }
  .chat { background: var(--bg); }
}

/* 视口高度兜底（老 iOS） */
@supports not (height: 100dvh) {
  .chat { height: 100vh; }
}
