:root {
  --bg: #0b121e;
  --glass: rgba(15, 24, 39, 0.74);
  --glass-strong: rgba(18, 28, 45, 0.90);
  --bubble-her: rgba(26, 39, 60, 0.86);
  --bubble-me: linear-gradient(135deg, #2fb8ad, #2589c8);
  --line: rgba(186, 220, 255, 0.14);
  --line2: rgba(186, 220, 255, 0.24);
  --ink: #eef4fb;
  --ink-soft: #9bb0c8;
  --ink-faint: #6e839c;
  --primary: #5fe0d4;
  --warm: #f3c47a;
  --danger: #e4717a;
  --shadow: 0 14px 40px rgba(0, 0, 0, 0.36);
}

html[data-theme="light"] {
  --bg: #eef4fb;
  --glass: rgba(255, 255, 255, 0.78);
  --glass-strong: rgba(255, 255, 255, 0.94);
  --bubble-her: rgba(255, 255, 255, 0.92);
  --bubble-me: linear-gradient(135deg, #259aa8, #2d6fb8);
  --line: rgba(22, 52, 88, 0.10);
  --line2: rgba(22, 52, 88, 0.18);
  --ink: #162436;
  --ink-soft: #53677f;
  --ink-faint: #8093aa;
  --primary: #1f8f9b;
  --warm: #c58230;
  --danger: #c64b54;
  --shadow: 0 12px 32px rgba(24, 52, 88, 0.14);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 14.5px/1.6 -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }

.chat-bg {
  position: fixed;
  inset: 0;
  background-size: cover;
  background-position: center;
  transform: scale(1.03);
  filter: blur(10px) saturate(1.2);
  z-index: 0;
}
.chat-bg-scrim {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at 20% 10%, rgba(45, 128, 168, 0.18), transparent 55%),
              rgba(8, 14, 24, 0.52);
  z-index: 1;
}
html[data-theme="light"] .chat-bg-scrim {
  background: radial-gradient(circle at 20% 10%, rgba(160, 214, 242, 0.25), transparent 55%),
              rgba(241, 246, 252, 0.56);
}

/* 主窗口 */
.chat-shell {
  position: relative;
  z-index: 2;
  height: 100vh;
  height: 100dvh;
  max-width: 980px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--glass);
  backdrop-filter: blur(22px) saturate(1.4);
  -webkit-backdrop-filter: blur(22px) saturate(1.4);
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  box-shadow: var(--shadow);
}

/* 顶栏 */
.chat-topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--glass-strong) 82%, transparent);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 10px; min-width: 0; }

.icon-pill {
  width: 36px; height: 36px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--glass-strong) 65%, transparent);
  color: var(--ink);
  display: inline-flex; align-items: center; justify-content: center;
  text-decoration: none; cursor: pointer; font-size: 16px;
  transition: all .16s ease;
}
.icon-pill svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-pill:hover { border-color: var(--primary); color: var(--primary); }

.text-pill {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--glass-strong) 55%, transparent);
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 12.5px;
  white-space: nowrap;
  transition: all .16s ease;
}
.text-pill:hover { color: var(--primary); border-color: var(--primary); }

.peer-info { display: flex; align-items: center; gap: 10px; min-width: 0; }
.peer-avatar-wrap { position: relative; width: 42px; height: 42px; flex: 0 0 42px; }
.peer-avatar {
  width: 42px; height: 42px; border-radius: 14px; object-fit: cover;
  border: 1.5px solid color-mix(in srgb, var(--primary) 45%, rgba(255,255,255,.3));
}
.peer-dot {
  position: absolute; right: -2px; bottom: -2px;
  width: 11px; height: 11px; border-radius: 50%;
  background: #4ade80; border: 2px solid var(--bg);
}
.peer-meta { min-width: 0; }
.peer-name-row { display: flex; align-items: center; gap: 7px; }
.peer-name-row strong { font-size: 15.5px; }
.peer-meta small { display: block; color: var(--ink-soft); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.role-badge {
  padding: 1px 7px; border-radius: 999px; font-size: 11px; font-weight: 600;
  background: color-mix(in srgb, var(--primary) 18%, transparent);
  color: var(--primary); border: 1px solid color-mix(in srgb, var(--primary) 35%, transparent);
}

/* 消息流 */
.chat-stream {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 16px 24px;
  scroll-behavior: smooth;
}
.stream-inner {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.msg-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  max-width: 82%;
}
.msg-row.me {
  margin-left: auto;
  flex-direction: row-reverse;
}
.msg-row.sys {
  max-width: 100%;
  margin: 0 auto;
  justify-content: center;
}
.msg-avatar {
  width: 36px; height: 36px; border-radius: 12px; object-fit: cover; flex: 0 0 36px;
  border: 1px solid var(--line2);
}
.msg-avatar.me-av {
  display: grid; place-items: center;
  background: color-mix(in srgb, var(--primary) 24%, transparent);
  color: var(--primary); font-weight: 700; font-size: 13px;
}

.msg-col { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.msg-row.me .msg-col { align-items: flex-end; }

.bubble {
  padding: 10px 14px;
  border-radius: 18px;
  border-top-left-radius: 6px;
  background: var(--bubble-her);
  border: 1px solid var(--line);
  color: var(--ink);
  word-break: break-word;
  white-space: pre-wrap;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.14);
}
.msg-row.me .bubble {
  border-top-left-radius: 18px;
  border-top-right-radius: 6px;
  background: var(--bubble-me);
  border-color: rgba(255, 255, 255, 0.16);
  color: #f6fbff;
}
.sys-pill {
  padding: 4px 12px; border-radius: 999px; font-size: 12px;
  color: var(--ink-soft); background: color-mix(in srgb, var(--glass-strong) 60%, transparent);
  border: 1px solid var(--line);
}
.proactive-tag {
  display: inline-block; margin-bottom: 4px; padding: 1px 7px; border-radius: 999px;
  font-size: 10.5px; font-weight: 600;
  background: color-mix(in srgb, var(--warm) 20%, transparent);
  color: var(--warm); border: 1px solid color-mix(in srgb, var(--warm) 40%, transparent);
}

/* 富媒体：图片 */
.part-img {
  display: block;
  max-width: min(280px, 68vw);
  max-height: 300px;
  border-radius: 14px;
  border: 1px solid var(--line2);
  cursor: zoom-in;
  object-fit: cover;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.22);
}

/* 富媒体：表情包（无底框） */
.part-sticker {
  display: block;
  max-width: 148px;
  max-height: 148px;
  border-radius: 12px;
  object-fit: contain;
}

/* 富媒体：微信风格语音气泡 */
.voice-bubble {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 132px;
  padding: 9px 14px;
  border-radius: 18px;
  background: var(--bubble-her);
  border: 1px solid var(--line2);
  color: var(--ink);
  cursor: pointer;
  user-select: none;
  transition: transform .14s ease, border-color .14s ease;
}
.msg-row.me .voice-bubble {
  background: var(--bubble-me);
  color: #f6fbff;
  border-color: rgba(255, 255, 255, 0.2);
}
.voice-bubble:hover { transform: translateY(-1px); border-color: var(--primary); }
.voice-play-ic { font-size: 13px; width: 16px; text-align: center; }
.voice-bars { display: inline-flex; align-items: center; gap: 3px; height: 16px; }
.voice-bars i {
  width: 3px; height: 6px; border-radius: 2px; background: currentColor; opacity: .7;
}
.voice-bars i:nth-child(2) { height: 11px; }
.voice-bars i:nth-child(3) { height: 15px; }
.voice-bars i:nth-child(4) { height: 9px; }
.voice-bubble.playing .voice-bars i { animation: vbar .7s ease-in-out infinite alternate; }
.voice-bubble.playing .voice-bars i:nth-child(2) { animation-delay: .12s; }
.voice-bubble.playing .voice-bars i:nth-child(3) { animation-delay: .24s; }
.voice-bubble.playing .voice-bars i:nth-child(4) { animation-delay: .36s; }
@keyframes vbar { from { height: 4px; opacity: .5; } to { height: 16px; opacity: 1; } }
.voice-dur { font-size: 12.5px; font-variant-numeric: tabular-nums; margin-left: auto; }
.voice-transcript {
  font-size: 12.5px; color: var(--ink-soft);
  padding: 6px 10px; border-radius: 10px;
  background: color-mix(in srgb, var(--glass-strong) 65%, transparent);
  border: 1px solid var(--line);
  max-width: min(320px, 70vw);
}

/* 消息下方辅助栏（时间 + 听她说） */
.msg-foot {
  display: flex; align-items: center; gap: 8px;
  font-size: 11px; color: var(--ink-faint); padding: 0 2px;
}
.tts-btn {
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--glass-strong) 55%, transparent);
  color: var(--ink-soft);
  border-radius: 999px; padding: 2px 9px; font-size: 11px;
  cursor: pointer; transition: all .15s ease;
}
.tts-btn:hover { color: var(--primary); border-color: var(--primary); }
.tts-btn:disabled { opacity: .55; cursor: wait; }

/* 底部输入区 */
.chat-footer {
  position: relative;
  flex: 0 0 auto;
  padding: 10px 14px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--glass-strong) 88%, transparent);
}

.stage-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding-bottom: 10px; margin-bottom: 8px; border-bottom: 1px dashed var(--line);
}
.stage-thumb {
  position: relative; display: inline-flex; align-items: center; gap: 8px;
  padding: 4px 10px 4px 4px; border-radius: 12px;
  background: color-mix(in srgb, var(--glass-strong) 75%, transparent);
  border: 1px solid var(--line2); font-size: 12px; color: var(--ink-soft);
}
.stage-thumb img { width: 42px; height: 42px; border-radius: 8px; object-fit: cover; }
.stage-rm {
  border: 0; background: rgba(0,0,0,.45); color: #fff;
  width: 20px; height: 20px; border-radius: 50%; cursor: pointer; font-size: 12px;
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
.tool-btn {
  width: 38px; height: 38px; flex: 0 0 38px;
  border-radius: 12px; border: 1px solid var(--line);
  background: color-mix(in srgb, var(--glass-strong) 65%, transparent);
  color: var(--ink-soft);
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; transition: all .15s ease;
}
.tool-btn svg { width: 19px; height: 19px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tool-btn:hover, .tool-btn.active { color: var(--primary); border-color: var(--primary); }

#chat-input {
  flex: 1 1 auto;
  min-height: 38px;
  max-height: 128px;
  resize: none;
  padding: 8px 13px;
  border-radius: 14px;
  border: 1px solid var(--line2);
  background: color-mix(in srgb, var(--bg) 55%, transparent);
  color: var(--ink);
  font: inherit;
  outline: none;
}
#chat-input:focus { border-color: var(--primary); }

.btn-send, .btn-primary {
  border: 0;
  padding: 9px 16px;
  border-radius: 13px;
  background: linear-gradient(135deg, #32bfb4, #2885c7);
  color: #fff; font-weight: 600; font-size: 13.5px;
  cursor: pointer; white-space: nowrap;
  transition: transform .14s ease, filter .14s ease;
}
.btn-send:hover, .btn-primary:hover { filter: brightness(1.08); transform: translateY(-1px); }
.btn-send:disabled { opacity: .5; cursor: default; transform: none; }

.btn-soft {
  border: 1px solid color-mix(in srgb, var(--primary) 45%, transparent);
  background: color-mix(in srgb, var(--primary) 16%, transparent);
  color: var(--primary); padding: 7px 12px; border-radius: 11px;
  cursor: pointer; font-size: 12.5px; font-weight: 600;
}
.btn-ghost {
  border: 1px solid var(--line2); background: transparent; color: var(--ink-soft);
  padding: 7px 12px; border-radius: 11px; cursor: pointer; font-size: 12.5px;
}

/* 录音条 */
.rec-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  padding: 8px 12px; margin-bottom: 8px; border-radius: 14px;
  background: color-mix(in srgb, var(--danger) 12%, var(--glass-strong));
  border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent);
}
.rec-left, .rec-actions { display: flex; align-items: center; gap: 8px; }
.rec-dot {
  width: 10px; height: 10px; border-radius: 50%; background: var(--danger);
  animation: pulse 1s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .4; transform: scale(.8); } }
.rec-time { font: 600 13px ui-monospace, Consolas, monospace; font-variant-numeric: tabular-nums; }
.rec-wave { display: inline-flex; align-items: center; gap: 3px; height: 22px; }
.rec-wave i { width: 3px; height: 6px; border-radius: 2px; background: var(--primary); transition: height .08s ease; }

/* 表情包浮层 */
.sticker-pop {
  position: absolute;
  right: 16px;
  bottom: 78px;
  width: min(380px, calc(100vw - 24px));
  max-height: 360px;
  display: flex; flex-direction: column;
  border-radius: 18px;
  background: var(--glass-strong);
  border: 1px solid var(--line2);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px);
  z-index: 20;
  overflow: hidden;
}
.sticker-head {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; border-bottom: 1px solid var(--line);
}
.sticker-head input {
  flex: 1; padding: 6px 10px; border-radius: 10px;
  border: 1px solid var(--line2); background: color-mix(in srgb, var(--bg) 55%, transparent);
  color: var(--ink); font: inherit; font-size: 13px; outline: none;
}
.icon-close {
  width: 28px; height: 28px; border-radius: 8px; border: 1px solid var(--line);
  background: transparent; color: var(--ink-soft); cursor: pointer; font-size: 16px;
}
.sticker-packs {
  display: flex; gap: 6px; padding: 8px 12px; overflow-x: auto; border-bottom: 1px solid var(--line);
  scrollbar-width: none;
}
.sticker-packs::-webkit-scrollbar { display: none; }
.pack-btn {
  padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line);
  background: transparent; color: var(--ink-soft); font-size: 12px; cursor: pointer; white-space: nowrap;
}
.pack-btn.on { color: var(--primary); border-color: var(--primary); background: color-mix(in srgb, var(--primary) 14%, transparent); }
.sticker-grid {
  flex: 1; overflow-y: auto; padding: 10px;
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
}
.sticker-item {
  border: 1px solid transparent; border-radius: 12px; padding: 6px;
  background: color-mix(in srgb, var(--bg) 35%, transparent);
  cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 4px;
  transition: all .14s ease;
}
.sticker-item:hover { border-color: var(--primary); transform: translateY(-2px); }
.sticker-item img { width: 64px; height: 64px; object-fit: contain; }
.sticker-item span { font-size: 10.5px; color: var(--ink-soft); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sticker-empty { grid-column: 1 / -1; text-align: center; padding: 28px 12px; color: var(--ink-soft); font-size: 13px; }

/* 拖拽与登录墙与灯箱 */
.drop-overlay {
  position: absolute; inset: 0; z-index: 30;
  background: rgba(12, 24, 42, 0.72); backdrop-filter: blur(8px);
  display: grid; place-items: center; padding: 20px;
}
.drop-box {
  padding: 28px 36px; border-radius: 20px; border: 2px dashed var(--primary);
  color: var(--primary); font-weight: 600; font-size: 16px;
}
.auth-wall {
  position: absolute; inset: 60px 0 0 0; z-index: 25;
  background: var(--glass-strong); backdrop-filter: blur(18px);
  display: grid; place-items: center; padding: 24px;
}
.auth-wall-card {
  max-width: 360px; text-align: center; padding: 28px 24px;
  border-radius: 22px; border: 1px solid var(--line2); background: var(--glass);
}
.auth-wall-card img { width: 92px; height: 92px; border-radius: 24px; margin-bottom: 12px; }
.auth-wall-card h2 { margin: 0 0 8px; font-size: 18px; }
.auth-wall-card p { margin: 0 0 18px; font-size: 13.5px; color: var(--ink-soft); }
.auth-wall-card a { display: inline-block; text-decoration: none; }

.lightbox {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(5, 10, 18, 0.86); backdrop-filter: blur(10px);
  display: grid; place-items: center; padding: 24px;
}
.lightbox img { max-width: 92vw; max-height: 88vh; border-radius: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.55); }
.lightbox-close {
  position: fixed; top: 18px; right: 22px;
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid rgba(255,255,255,.25);
  background: rgba(0,0,0,.45); color: #fff; font-size: 22px; cursor: pointer;
}

.toast {
  position: fixed; left: 50%; bottom: 86px; transform: translate(-50%, 16px); opacity: 0;
  z-index: 60; padding: 9px 16px; border-radius: 999px;
  background: rgba(14, 24, 40, 0.94); border: 1px solid var(--line2); color: #eef4fb;
  font-size: 13px; pointer-events: none; transition: all .2s ease;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 680px) {
  .chat-shell { border-left: 0; border-right: 0; }
  .desktop-only { display: none !important; }
  .msg-row { max-width: 90%; }
  .sticker-pop { right: 12px; bottom: 72px; }
}
