:root {
  --bg: #14121a;
  --panel: #1d1a26;
  --bubble-her: #2a2635;
  --bubble-me: #7b5cff;
  --text: #f2eefb;
  --muted: #9d94b3;
  --accent: #ff7fb0;
  --line: rgba(255, 255, 255, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  background:
    radial-gradient(120% 60% at 50% 0%, rgba(123, 92, 255, 0.28), transparent 60%),
    radial-gradient(80% 40% at 80% 100%, rgba(255, 127, 176, 0.14), transparent 60%),
    var(--bg);
}

header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
}

header .avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, #7b5cff, #ff7fb0);
  display: grid;
  place-items: center;
  font-size: 16px;
}

header .who { flex: 1; min-width: 0; }
header .who strong { font-size: 15px; }
header .who span { display: block; font-size: 11px; color: var(--muted); }

/* 顶上那颗胶囊：聊天底换成图之后会被亮的地方吃掉，单独给它一个深色底 */
header .who #subtitle {
  display: inline-block;
  margin-top: 3px;
  padding: 2px 9px;
  max-width: 100%;
  border-radius: 999px;
  background: rgba(16, 14, 22, 0.66);
  border: 1px solid rgba(255, 255, 255, 0.06);
  color: #cfc7e4;
  backdrop-filter: blur(6px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#online { width: 8px; height: 8px; border-radius: 50%; background: #6b6480; }
#online.on { background: #4ad991; box-shadow: 0 0 8px #4ad991; }

main {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.row { display: flex; gap: 8px; align-items: flex-end; }
.row.me { flex-direction: row-reverse; }

.bubble {
  max-width: 78%;
  padding: 9px 12px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--bubble-her);
  border-top-left-radius: 5px;
}

.row.me .bubble {
  background: linear-gradient(135deg, var(--bubble-me), #5f4bd6);
  border-top-left-radius: 16px;
  border-top-right-radius: 5px;
}

.bubble .quote {
  border-left: 3px solid var(--accent);
  padding: 2px 0 2px 8px;
  margin-bottom: 6px;
  font-size: 12px;
  color: var(--muted);
  white-space: pre-wrap;
}

.bubble img { max-width: 100%; border-radius: 10px; display: block; margin-top: 4px; }

.meta { font-size: 10px; color: var(--muted); align-self: flex-end; margin: 0 4px; }

#quote-bar {
  display: none;
  align-items: center;
  gap: 8px;
  margin: 0 12px 6px;
  padding: 6px 10px;
  border-radius: 10px;
  background: rgba(255, 127, 176, 0.12);
  border-left: 3px solid var(--accent);
  font-size: 12px;
  color: var(--muted);
}

#quote-bar.show { display: flex; }
#quote-bar span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#quote-bar button { background: none; border: 0; color: var(--muted); font-size: 16px; cursor: pointer; }

footer {
  padding: 8px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(20, 18, 26, 0.9);
}

/* 选好但还没发出去的图：先挂在输入框上面，按「发送」才真的发 */
#pending {
  position: relative;
  width: 76px;
  height: 76px;
  margin-bottom: 8px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
}

#pending img { width: 100%; height: 100%; object-fit: cover; display: block; }

#pending-cancel {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 0;
  background: rgba(16, 14, 22, 0.72);
  color: #fff;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
}

.tools { display: flex; gap: 6px; margin-bottom: 6px; }

.tools button {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  font-size: 15px;
  cursor: pointer;
}

.tools button:active { transform: scale(0.94); }

.composer { display: flex; gap: 8px; align-items: flex-end; }

textarea {
  flex: 1;
  resize: none;
  min-height: 40px;
  max-height: 120px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  outline: none;
}

#send {
  height: 40px;
  padding: 0 16px;
  border-radius: 12px;
  border: 0;
  background: linear-gradient(135deg, var(--bubble-me), var(--accent));
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

#send:disabled { opacity: 0.45; }

header #menu {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
}

#scrim[hidden],
#drawer[hidden],
#panel[hidden] { display: none !important; }

#scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 20;
}

#drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(78vw, 300px);
  z-index: 30;
  padding: 14px 12px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow-y: auto;
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  font-size: 15px;
}

.drawer-head button,
.panel-bar button {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-size: 16px;
  cursor: pointer;
}

.group-label {
  margin: 12px 4px 6px;
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.drawer .row {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  margin-bottom: 6px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.drawer .row b { font-size: 14px; font-weight: 600; }
.drawer .row i { font-size: 11px; color: var(--muted); font-style: normal; }
.drawer .row:active { background: rgba(123, 92, 255, 0.18); }

#panel {
  position: fixed;
  inset: 0;
  z-index: 25;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.panel-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}

#panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.rows { display: flex; flex-direction: column; gap: 6px; }

.item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.item b { font-size: 14px; font-weight: 600; }
.item i { font-size: 11px; color: var(--muted); font-style: normal; }

.text {
  margin: 0;
  font: inherit;
  font-size: 13px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
}

.ask {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.ask-input {
  flex: 1;
  min-height: 38px;
  max-height: 100px;
  padding: 9px 12px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  resize: none;
  outline: none;
}

.ask-send {
  height: 38px;
  padding: 0 14px;
  border-radius: 11px;
  border: 0;
  background: linear-gradient(135deg, var(--bubble-me), var(--accent));
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.ask-send:disabled { opacity: 0.5; }

.empty { color: var(--muted); font-size: 13px; text-align: center; margin-top: 30px; }

.art-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 6px;
}

.art-cell { display: block; border-radius: 10px; overflow: hidden; background: var(--panel); }
.art-cell img { width: 100%; display: block; }

.tabs { display: flex; gap: 6px; margin-bottom: 10px; }

.tab {
  padding: 7px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
}

.tab.on {
  color: var(--text);
  border-color: var(--bubble-me);
  background: rgba(123, 92, 255, 0.22);
}

.art-cell { position: relative; }
.art-link { display: block; }

.art-mark {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  border-radius: 8px;
  border: 0;
  background: rgba(20, 18, 26, 0.72);
  color: var(--text);
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  backdrop-filter: blur(4px);
}

.art-mark:active { transform: scale(0.92); }

.closet-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  font-size: 12px;
  color: var(--muted);
}

.closet-tip { flex: 1; }

.closet-reset {
  padding: 5px 10px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}

.closet-reset:disabled {
  opacity: 0.45;
  cursor: default;
  border-style: dashed;
}

.closet-actions { display: flex; gap: 6px; margin-top: 8px; }

.closet-act {
  padding: 6px 10px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: rgba(123, 92, 255, 0.18);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
}

.closet-act:disabled {
  background: transparent;
  color: var(--muted);
  border-style: dashed;
  cursor: default;
}

.closet-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.closet-card {
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--panel);
}

.closet-card.current { border-color: var(--bubble-me); box-shadow: 0 0 0 1px var(--bubble-me) inset; }
.closet-card img { width: 100%; display: block; }
.closet-card .no-art {
  height: 96px;
  display: grid;
  place-items: center;
  font-size: 12px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.03);
}
.closet-body { padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 2px; }
.closet-body b { font-size: 12px; }
.closet-body i { font-size: 11px; color: var(--muted); font-style: normal; }
.closet-body .tag { font-size: 10px; color: var(--accent); }

.login {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 12px;
  padding: 28px;
}

.login h1 { font-size: 20px; margin: 0 0 4px; }
.login p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.6; }
.login input {
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font: inherit;
  outline: none;
}
.login button {
  padding: 12px;
  border-radius: 12px;
  border: 0;
  background: linear-gradient(135deg, var(--bubble-me), var(--accent));
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.login .err { color: #ff8b8b; font-size: 13px; min-height: 18px; }

/* 图片放大：铺满一整层，点一下关掉 */
.lightbox {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(8, 6, 12, 0.94);
  align-items: center;
  justify-content: center;
  padding: 10px;
}
.lightbox.show { display: flex; }
.lightbox { touch-action: none; }
.lightbox img {
  touch-action: none;
  will-change: transform;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
}

/* 情绪抽屉：右侧滑出 */
#emotion-sheet { position: fixed; inset: 0; z-index: 60; }
#emotion-sheet[hidden] { display: none; }
#emotion-scrim { position: absolute; inset: 0; background: rgba(0, 0, 0, .55); opacity: 0; transition: opacity .24s ease; }
#emotion-panel {
  position: absolute; top: 0; right: 0; height: 100%;
  width: 70vw;
  background: #0a0f18;
  border-left: 1px solid rgba(120, 150, 200, .16);
  box-shadow: -18px 0 44px rgba(0, 0, 0, .55);
  display: flex; flex-direction: column; overflow: hidden;
  transform: translateX(100%);
  transition: transform .26s cubic-bezier(.22, .8, .28, 1);
}
#emotion-sheet.show #emotion-scrim { opacity: 1; }
#emotion-sheet.show #emotion-panel { transform: none; }
.emotion-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; border-bottom: 1px solid rgba(120, 150, 200, .14);
  font-size: 14px; color: #e6ecf6;
}
.emotion-bar strong { font-weight: 600; letter-spacing: .5px; }
.emotion-bar button {
  width: 30px; height: 30px; border-radius: 50%;
  border: 1px solid rgba(120, 150, 200, .22); background: rgba(255, 255, 255, .06);
  color: #cfd8e8; font-size: 16px; line-height: 1; cursor: pointer;
}
#emotion-frame { display: block; flex: 1 1 auto; width: 100%; height: 100%; min-height: 0; border: 0; background: #0a0f18; }#emotion-status { padding: 12px 14px 14px; border-bottom: 1px solid rgba(120,150,200,.12); background: #0a0f18; }
.es-head { display: flex; align-items: center; justify-content: space-between; font-size: 13px; color: #9aa7bd; margin-bottom: 8px; }
.es-head b { font-weight: 500; letter-spacing: 1px; }
.es-head span { font-size: 11.5px; color: #6b7890; }
.es-row { display: flex; align-items: center; justify-content: space-between; padding: 7px 0; font-size: 14px; color: #e6ecf6; border-bottom: 1px solid rgba(120,150,200,.07); }
.es-row:last-child { border-bottom: 0; }
.es-state { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.es-dot { width: 7px; height: 7px; border-radius: 50%; background: #35d07f; box-shadow: 0 0 8px rgba(53,208,127,.7); }
.es-row.bad .es-dot { background: #ff6b6b; box-shadow: 0 0 8px rgba(255,107,107,.7); }
.es-row.bad .es-state { color: #ff9a9a; }
.es-row .es-state { color: #43e08c; }
/* 顶上那颗「情绪」药丸：在线点 + 当前心情，点一下开抽屉 */
#emotion-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: 999px;
  border: 1px solid rgba(120, 150, 200, .22);
  background: rgba(16, 20, 30, .55);
  color: var(--text, #e6ecf6);
  font: inherit; cursor: pointer; flex: none;
  max-width: 42vw;
}
#emotion-chip b {
  font-size: 12px; font-weight: 500; letter-spacing: .3px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  background: linear-gradient(90deg, #8ec2ff, #ffa3c8);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
#emotion-chip:active { background: rgba(123, 92, 255, .25); }
header .who #subtitle {
  white-space: normal;
  line-height: 1.35;
  word-break: break-all;
}
/* 聊天里每条她的话前面那颗头像（QQ 那样：头像 + 气泡） */
.msg-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  object-fit: cover; flex: none; align-self: flex-end;
  background: rgba(255, 255, 255, .08);
  border: 1px solid rgba(150, 170, 220, .18);
}
.row { align-items: flex-end; }
.msg-avatar.mine { border-color: rgba(255, 160, 200, .3); }
.row.me { align-items: flex-end; }
/* 头像跟着气泡顶端走，时间戳还是贴底 */
.row { align-items: flex-start !important; }
.msg-avatar { align-self: flex-start !important; margin-top: 2px; }
.row .meta { align-self: flex-end; }
/* 底栏那排图标 + 表情面板 */
footer .tools {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 10px 8px;
}
footer .tools button {
  width: 42px; height: 42px; border-radius: 14px;
  border: 1px solid rgba(150, 170, 220, .14);
  background: rgba(255, 255, 255, .045);
  color: #cfd8ea; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background .15s ease, border-color .15s ease, transform .12s ease;
}
footer .tools svg {
  width: 21px; height: 21px;
  fill: none; stroke: currentColor; stroke-width: 1.7;
  stroke-linecap: round; stroke-linejoin: round;
}
footer .tools button:active { transform: scale(.94); }
footer .tools button:active { background: rgba(123, 92, 255, .28); }
#sticker-panel {
  max-height: 40vh; overflow-y: auto;
  padding: 8px 10px 10px;
  border-top: 1px solid rgba(140, 160, 210, .14);
  background: rgba(12, 15, 22, .92);
}
.sticker-head { display: flex; align-items: center; justify-content: space-between; font-size: 12px; color: #9aa7bd; margin-bottom: 6px; }
.sticker-head button { border: 0; background: transparent; color: #9aa7bd; font-size: 16px; }
#sticker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 6px; color: #7f8ca3; font-size: 12px; }
#sticker-grid button { padding: 0; border: 1px solid rgba(140, 160, 210, .14); border-radius: 10px; background: rgba(255, 255, 255, .04); overflow: hidden; aspect-ratio: 1 / 1; }
#sticker-grid img { width: 100%; height: 100%; object-fit: contain; display: block; }
/* 用量抽屉 */
#stats-sheet { position: fixed; inset: 0; z-index: 60; }
#stats-sheet[hidden] { display: none; }
#stats-scrim { position: absolute; inset: 0; background: rgba(0, 0, 0, .55); opacity: 0; transition: opacity .24s ease; }
#stats-panel {
  position: absolute; top: 0; right: 0; height: 100%; width: 70vw; max-width: none;
  background: #0a0f18; border-left: 1px solid rgba(120, 150, 200, .16);
  box-shadow: -18px 0 44px rgba(0, 0, 0, .55);
  display: flex; flex-direction: column; overflow: hidden;
  transform: translateX(100%); transition: transform .26s cubic-bezier(.22, .8, .28, 1);
}
#stats-sheet.show #stats-scrim { opacity: 1; }
#stats-sheet.show #stats-panel { transform: none; }
#stats-body { padding: 14px; overflow-y: auto; }
.stat-top { display: flex; gap: 10px; margin-bottom: 12px; }
.stat-top div { flex: 1; }
.stat-top span { display: block; font-size: 11.5px; color: #7f8ca3; margin-bottom: 4px; }
.stat-top b { font-size: 20px; font-weight: 600; background: linear-gradient(90deg, #8ec2ff, #ffa3c8); -webkit-background-clip: text; background-clip: text; color: transparent; }
.stat-seg { display: flex; gap: 8px; margin-bottom: 12px; }
.stat-seg button { flex: 1; padding: 7px 0; border-radius: 10px; border: 1px solid rgba(120, 150, 200, .18); background: rgba(255, 255, 255, .04); color: #93a1b8; font-size: 13px; }
.stat-seg button.on { background: linear-gradient(135deg, #2f6bff, #3d8bff); color: #fff; border-color: transparent; }
#stat-chart { display: flex; align-items: flex-end; gap: 8px; height: 120px; padding: 8px 4px 0; border-bottom: 1px solid rgba(120, 150, 200, .14); margin-bottom: 12px; }
#stat-chart .col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 4px; height: 100%; }
#stat-chart .bar { width: 100%; border-radius: 6px 6px 2px 2px; background: linear-gradient(180deg, #4b8dff, #2f66c8); min-height: 3px; }
#stat-chart .cap { font-size: 9.5px; color: #6b7890; white-space: nowrap; }
#stat-rows .srow { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; font-size: 13px; color: #dfe6f3; border-bottom: 1px solid rgba(120, 150, 200, .08); }
#stat-rows .srow span { color: #93a1b8; }
#stat-chart .bar.empty { background: rgba(120, 150, 200, .18); }
header .who #subtitle { cursor: pointer; }
#sticker-grid .sticker-add { font-size: 22px; color: #8ec2ff; border-style: dashed; }
#sticker-grid button { position: relative; }
#sticker-grid .sticker-del {
  position: absolute; top: 2px; right: 2px;
  width: 18px; height: 18px; border-radius: 50%;
  background: rgba(12, 15, 22, .82); color: #ff9a9a;
  font-size: 13px; line-height: 17px; text-align: center; font-style: normal;
}