/* ==========================================================================
   两个人的 AI 伙伴 —— 界面样式 v5
   薄荷绿 · 米白 · 墨绿；无 emoji，全部图形用 SVG / CSS
   ========================================================================== */

:root {
  color-scheme: light;

  /* 底色 */
  --bg: #f4f7f2;
  --bg-glow-1: rgba(155, 221, 116, 0.20);
  --bg-glow-2: rgba(124, 179, 66, 0.10);
  --surface: #ffffff;
  --surface-2: #fbfdfa;
  --surface-sunk: #eef3ec;

  /* 主色 */
  --mint: #d4ebe8;
  --mint-soft: #e8f4f1;
  --green: #7cb342;
  --green-deep: #4f8c3e;
  --ink-green: #2f5240;
  --warm: #c08a5e;

  /* 文字 */
  --ink: #1c2b26;
  --ink-2: #43554e;
  --ink-dim: #7a8b84;
  --ink-faint: #a3b1ab;
  --on-green: #ffffff;

  /* 线条与阴影 */
  --line: rgba(28, 43, 38, 0.09);
  --line-strong: rgba(28, 43, 38, 0.16);
  --shadow-sm: 0 1px 2px rgba(28, 43, 38, 0.05);
  --shadow-md: 0 2px 6px rgba(28, 43, 38, 0.05), 0 10px 24px -8px rgba(28, 43, 38, 0.12);
  --shadow-lg: 0 8px 20px -6px rgba(28, 43, 38, 0.14), 0 28px 60px -18px rgba(28, 43, 38, 0.22);

  /* 气泡 */
  --bubble-mine-1: #d5ece2;
  --bubble-mine-2: #c3e3d4;
  --bubble-theirs: #ffffff;
  --bubble-ai-1: #f2f8f4;
  --bubble-ai-2: #e9f3ec;
  --bubble-ai-private-1: #fdf6ea;
  --bubble-ai-private-2: #f8ecdb;

  --danger: #c25543;
  --danger-soft: #fdeceb;
  --danger-line: rgba(194, 85, 67, 0.24);

  --glass: rgba(255, 255, 255, 0.76);
  --glass-strong: rgba(255, 255, 255, 0.92);
  --toast-bg: rgba(28, 43, 38, 0.92);
  --toast-ink: #f6f9f4;

  --r-xs: 8px;
  --r-sm: 12px;
  --r-md: 16px;
  --r-lg: 22px;
  --r-xl: 28px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  --ease: cubic-bezier(0.22, 0.9, 0.25, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --bg: #0e1513;
  --bg-glow-1: rgba(124, 179, 66, 0.14);
  --bg-glow-2: rgba(60, 120, 100, 0.12);
  --surface: #16211e;
  --surface-2: #1a2723;
  --surface-sunk: #101917;

  --mint: #24413a;
  --mint-soft: #1c312c;
  --green: #8ecb5b;
  --green-deep: #78b74a;
  --ink-green: #b9d8c6;
  --warm: #d3a279;

  --ink: #e8f0ec;
  --ink-2: #c2d2cb;
  --ink-dim: #8ea49b;
  --ink-faint: #647a72;
  --on-green: #0c1512;

  --line: rgba(232, 240, 236, 0.11);
  --line-strong: rgba(232, 240, 236, 0.2);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 2px 6px rgba(0, 0, 0, 0.28), 0 10px 26px -8px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 8px 22px -6px rgba(0, 0, 0, 0.5), 0 30px 70px -20px rgba(0, 0, 0, 0.7);

  --bubble-mine-1: #2c4a3f;
  --bubble-mine-2: #24443a;
  --bubble-theirs: #1d2a26;
  --bubble-ai-1: #1a2b25;
  --bubble-ai-2: #16241f;
  --bubble-ai-private-1: #2e261c;
  --bubble-ai-private-2: #292117;

  --danger: #e0755f;
  --danger-soft: rgba(224, 117, 95, 0.14);
  --danger-line: rgba(224, 117, 95, 0.3);

  --glass: rgba(20, 31, 28, 0.78);
  --glass-strong: rgba(20, 31, 28, 0.92);
  --toast-bg: rgba(232, 240, 236, 0.95);
  --toast-ink: #14201c;
}

/* ---------------------------------------------------------------- 基础 */

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  background:
    radial-gradient(1200px 620px at 12% -10%, var(--bg-glow-1), transparent 62%),
    radial-gradient(900px 520px at 96% 8%, var(--bg-glow-2), transparent 58%),
    var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior: none;
  line-height: 1.5;
}

button, input, textarea, select { font-family: inherit; font-size: inherit; color: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.hidden { display: none !important; }

::selection { background: rgba(124, 179, 66, 0.24); }

/* 细滚动条 */
* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
*::-webkit-scrollbar { width: 6px; height: 6px; }
*::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 99px; }
*::-webkit-scrollbar-track { background: transparent; }

/* ---------------------------------------------------------------- 骨架屏 */

.boot {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  color: var(--ink-dim);
  font-size: 14px;
  animation: fade-in 0.4s var(--ease);
}

.boot-mark {
  color: var(--green-deep);
  animation: breathe 2.4s ease-in-out infinite;
}

@keyframes breathe {
  0%, 100% { transform: scale(1); opacity: 0.9; }
  50% { transform: scale(1.06); opacity: 1; }
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ---------------------------------------------------------------- 登录 */

.screen {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 22px;
  overflow: hidden;
}

.aura {
  position: absolute;
  inset: -20%;
  background:
    radial-gradient(closest-side at 30% 24%, var(--bg-glow-1), transparent),
    radial-gradient(closest-side at 76% 70%, rgba(212, 235, 232, 0.5), transparent),
    radial-gradient(closest-side at 50% 100%, var(--bg-glow-2), transparent);
  filter: blur(8px);
  pointer-events: none;
}

.login-card {
  position: relative;
  width: 100%;
  max-width: 380px;
  padding: 34px 26px 22px;
  background: var(--glass-strong);
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(22px) saturate(150%);
  -webkit-backdrop-filter: blur(22px) saturate(150%);
  animation: card-rise 0.5s var(--ease-out) both;
}

@keyframes card-rise {
  from { opacity: 0; transform: translateY(14px) scale(0.985); }
  to { opacity: 1; transform: none; }
}

.brand { text-align: center; }

.brand-mark {
  color: var(--green-deep);
  width: 68px;
  height: 68px;
  margin: 0 auto 14px;
  display: grid;
  place-items: center;
  border-radius: 20px;
  background: linear-gradient(150deg, rgba(155, 221, 116, 0.22), rgba(124, 179, 66, 0.08));
  border: 1px solid rgba(124, 179, 66, 0.24);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

.brand h1 {
  font-size: 21px;
  font-weight: 650;
  letter-spacing: 0.4px;
}

.brand-sub {
  margin-top: 6px;
  font-size: 12.5px;
  color: var(--ink-dim);
  letter-spacing: 0.6px;
}

.login-step { margin-top: 26px; }

.step-label {
  font-size: 12px;
  color: var(--ink-faint);
  letter-spacing: 1.2px;
  text-transform: uppercase;
  margin-bottom: 10px;
}

.identity-btn {
  display: flex;
  align-items: center;
  gap: 13px;
  width: 100%;
  padding: 12px 14px;
  margin-bottom: 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  cursor: pointer;
  text-align: left;
  transition: transform 0.16s var(--ease), border-color 0.16s, box-shadow 0.2s, background 0.16s;
}

.identity-btn:hover {
  border-color: rgba(124, 179, 66, 0.45);
  background: var(--surface);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.identity-btn:active { transform: scale(0.985); }

.avatar {
  flex: none;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 14px;
  font-size: 17px;
  font-weight: 600;
  color: #fff;
  letter-spacing: 0;
}

.avatar-a { background: linear-gradient(145deg, #8fbe5c, #5c9440); }
.avatar-b { background: linear-gradient(145deg, #d9a97e, #b07a4d); }

.identity-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.identity-text b { font-size: 15.5px; font-weight: 600; }
.identity-note { font-size: 12px; color: var(--ink-faint); font-style: normal; }
.chev { color: var(--ink-faint); flex: none; }

/* PIN 步骤 */
.login-who {
  text-align: center;
  font-size: 13.5px;
  color: var(--ink-dim);
  margin-bottom: 18px;
}

.field { display: block; margin-bottom: 14px; }

.field > span {
  display: block;
  font-size: 12.5px;
  color: var(--ink-dim);
  margin-bottom: 6px;
  letter-spacing: 0.2px;
}

.field input,
.field select {
  width: 100%;
  padding: 12px 14px;
  font-size: 15px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  outline: none;
  transition: border-color 0.16s, box-shadow 0.16s, background 0.16s;
  -webkit-appearance: none;
  appearance: none;
}

.field input::placeholder { color: var(--ink-faint); }

.field input:focus,
.field select:focus {
  border-color: rgba(124, 179, 66, 0.6);
  background: var(--surface);
  box-shadow: 0 0 0 4px rgba(124, 179, 66, 0.12);
}

.field-pin input { letter-spacing: 2px; padding-right: 46px; }

.pin-wrap { position: relative; display: block; }

.eye-btn {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: none;
  background: none;
  color: var(--ink-faint);
  cursor: pointer;
  border-radius: 9px;
}

.eye-btn:hover { color: var(--ink-2); background: var(--surface-sunk); }

.btn-primary {
  width: 100%;
  padding: 13px 0;
  font-size: 15.5px;
  font-weight: 600;
  letter-spacing: 0.5px;
  color: var(--on-green);
  background: linear-gradient(160deg, var(--green), var(--green-deep));
  border: none;
  border-radius: var(--r-sm);
  cursor: pointer;
  box-shadow: 0 6px 16px -6px rgba(79, 140, 62, 0.55);
  transition: transform 0.14s var(--ease), box-shadow 0.2s, opacity 0.2s;
}

.btn-primary:hover { box-shadow: 0 8px 20px -6px rgba(79, 140, 62, 0.62); }
.btn-primary:active { transform: scale(0.985); }
.btn-primary:disabled { opacity: 0.55; cursor: default; box-shadow: none; }

.link-btn {
  display: block;
  width: 100%;
  margin-top: 12px;
  padding: 6px 0;
  border: none;
  background: none;
  color: var(--ink-dim);
  font-size: 13px;
  cursor: pointer;
  text-align: center;
}

.link-btn:hover { color: var(--ink); }

.login-error {
  margin-top: 12px;
  padding: 9px 12px;
  font-size: 13px;
  color: var(--danger);
  background: var(--danger-soft);
  border-radius: var(--r-xs);
  text-align: center;
}

.login-foot {
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  text-align: center;
  font-size: 11.5px;
  color: var(--ink-faint);
  letter-spacing: 0.4px;
}

/* ---------------------------------------------------------------- 应用外壳 */

#app {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 760px;
  margin: 0 auto;
  background: transparent;
}

@media (min-width: 761px) {
  #app {
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
    box-shadow: 0 0 80px -30px rgba(28, 43, 38, 0.18);
  }
}

/* ---------------------------------------------------------------- 顶栏 */

#topbar {
  position: relative;
  z-index: 5;
  padding-top: var(--safe-top);
  background: var(--glass);
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  border-bottom: 1px solid var(--line);
}

.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 46px;
  padding: 0 8px 0 16px;
}

.brand-mini {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.mini-mark {
  color: var(--green-deep);
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 9px;
  background: linear-gradient(150deg, rgba(155, 221, 116, 0.24), rgba(124, 179, 66, 0.08));
  border: 1px solid rgba(124, 179, 66, 0.2);
}

.brand-name {
  font-size: 14.5px;
  font-weight: 600;
  letter-spacing: 0.3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 3px rgba(124, 179, 66, 0.16);
  transition: background 0.3s, box-shadow 0.3s;
}

.live-dot.off {
  background: var(--ink-faint);
  box-shadow: 0 0 0 3px rgba(163, 177, 171, 0.14);
  animation: pulse-off 1.6s ease-in-out infinite;
}

@keyframes pulse-off {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 1; }
}

#panel-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: none;
  background: none;
  color: var(--ink-dim);
  border-radius: 12px;
  cursor: pointer;
  transition: color 0.16s, background 0.16s;
}

#panel-btn:hover { color: var(--ink); background: var(--surface-sunk); }

/* 分段控件 */
.segmented {
  position: relative;
  display: flex;
  gap: 2px;
  margin: 0 12px 10px;
  padding: 3px;
  background: var(--surface-sunk);
  border-radius: 13px;
}

.seg-glider {
  position: absolute;
  top: 3px;
  left: 3px;
  width: calc(50% - 4px);
  height: calc(100% - 6px);
  background: var(--surface);
  border-radius: 10px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.28s var(--ease-out);
}

.segmented[data-active="private"] .seg-glider { transform: translateX(calc(100% + 2px)); }

.tab {
  position: relative;
  z-index: 1;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 0;
  border: none;
  background: none;
  font-size: 14px;
  color: var(--ink-dim);
  cursor: pointer;
  border-radius: 10px;
  transition: color 0.2s;
}

.tab.active { color: var(--ink); font-weight: 600; }

.badge {
  min-width: 17px;
  height: 17px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--danger);
  color: #fff;
  font-size: 10.5px;
  line-height: 17px;
  font-weight: 600;
  text-align: center;
  animation: pop 0.28s var(--ease-out);
}

@keyframes pop {
  from { transform: scale(0.4); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* 连接横幅 */
#conn-banner {
  padding: 7px 14px;
  background: linear-gradient(90deg, rgba(192, 138, 94, 0.16), rgba(192, 138, 94, 0.08));
  border-bottom: 1px solid rgba(192, 138, 94, 0.2);
  color: var(--warm);
  font-size: 12.5px;
  text-align: center;
  animation: fade-in 0.2s;
}

/* ---------------------------------------------------------------- 消息区 */

#messages {
  position: relative;
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 18px 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  scroll-behavior: smooth;
  background-image: radial-gradient(circle at 1px 1px, var(--line) 1px, transparent 0);
  background-size: 26px 26px;
  overscroll-behavior-y: contain;
}

.msg-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 84%;
  margin-top: 10px;
  animation: msg-in 0.28s var(--ease-out) both;
}

@keyframes msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.msg-row.grouped { margin-top: 3px; }
.msg-row.mine { align-self: flex-end; flex-direction: row-reverse; }
.msg-row.theirs, .msg-row.ai { align-self: flex-start; }

.msg-avatar {
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 12.5px;
  font-weight: 600;
  color: #fff;
  user-select: none;
  box-shadow: var(--shadow-sm);
}

.msg-avatar.ai {
  background: linear-gradient(150deg, #466f4d, #2f5240);
  color: #eaf5ea;
  box-shadow: 0 1px 3px rgba(28, 43, 38, 0.22);
}

.msg-avatar.a { background: linear-gradient(150deg, #8fbe5c, #5c9440); }
.msg-avatar.b { background: linear-gradient(150deg, #d9a97e, #b07a4d); }

.msg-avatar.ghost { visibility: hidden; }

.msg-body {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.mine .msg-body { align-items: flex-end; }

.msg-meta {
  display: flex;
  align-items: baseline;
  gap: 7px;
  padding: 0 4px;
  font-size: 11.5px;
  color: var(--ink-faint);
}

.msg-meta .sender { color: var(--ink-2); font-weight: 600; font-size: 12px; }
.msg-meta time { font-variant-numeric: tabular-nums; }

.bubble {
  position: relative;
  padding: 9px 13px;
  font-size: 15px;
  line-height: 1.62;
  border-radius: var(--r-md);
  word-break: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  user-select: text;
  -webkit-user-select: text;
  box-shadow: var(--shadow-sm);
}

.mine .bubble {
  color: var(--ink);
  background: linear-gradient(145deg, var(--bubble-mine-1), var(--bubble-mine-2));
  border-bottom-right-radius: 5px;
}

.theirs .bubble {
  background: var(--bubble-theirs);
  border: 1px solid var(--line);
  border-bottom-left-radius: 5px;
}

.ai .bubble {
  background: linear-gradient(145deg, var(--bubble-ai-1), var(--bubble-ai-2));
  border: 1px solid rgba(124, 179, 66, 0.14);
  border-bottom-left-radius: 5px;
}

:root[data-theme="dark"] .ai .bubble { border-color: rgba(142, 203, 91, 0.14); }

/* 私聊里 AI 的底色更暖：暗示私下场合 */
body[data-room="private"] .ai .bubble {
  background: linear-gradient(145deg, var(--bubble-ai-private-1), var(--bubble-ai-private-2));
  border-color: rgba(192, 138, 94, 0.18);
}

/* 分组时把圆角拉平，像一段连续说话 */
.msg-row.grouped .bubble { border-top-left-radius: 8px; }
.msg-row.grouped.mine .bubble { border-top-right-radius: 8px; }

/* 流式光标 */
.caret {
  display: inline-block;
  width: 2px;
  height: 1em;
  margin-left: 2px;
  vertical-align: -0.14em;
  background: var(--green-deep);
  border-radius: 1px;
  animation: blink 1s steps(2, start) infinite;
}

@keyframes blink {
  50% { opacity: 0; }
}

.msg-time {
  padding: 0 4px;
  font-size: 11px;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}

.msg-foot {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--ink-faint);
  padding: 0 4px;
}

.msg-foot .tick { color: var(--green-deep); opacity: 0.85; }

/* 日期分隔 */
.time-divider {
  align-self: center;
  margin: 16px 0 6px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 11.5px;
  color: var(--ink-dim);
  letter-spacing: 0.6px;
}

.time-divider::before,
.time-divider::after {
  content: "";
  width: 26px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--line-strong));
}

.time-divider::after { background: linear-gradient(270deg, transparent, var(--line-strong)); }

/* 加载更早 */
#load-earlier {
  align-self: center;
  margin: 6px 0;
  padding: 6px 15px;
  font-size: 12px;
  color: var(--ink-dim);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 99px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}

#load-earlier:disabled { opacity: 0.6; cursor: default; }

/* 空状态 */
.empty {
  margin: auto;
  padding: 20px 10px 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  animation: fade-in 0.5s 0.1s both;
}

.empty-art {
  margin-bottom: 18px;
  opacity: 0.95;
}

.empty-title {
  font-size: 15.5px;
  font-weight: 600;
  color: var(--ink-2);
}

.empty-sub {
  margin-top: 6px;
  font-size: 13px;
  color: var(--ink-faint);
  max-width: 260px;
  line-height: 1.6;
}

.suggestions {
  margin-top: 22px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  max-width: 320px;
}

.chip {
  padding: 7px 13px;
  font-size: 13px;
  color: var(--ink-2);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 99px;
  cursor: pointer;
  transition: border-color 0.16s, transform 0.14s, box-shadow 0.2s, color 0.16s;
  box-shadow: var(--shadow-sm);
}

.chip:hover {
  color: var(--ink);
  border-color: rgba(124, 179, 66, 0.45);
  box-shadow: var(--shadow-md);
}

.chip:active { transform: scale(0.96); }

/* 回到最新 */
#scroll-bottom {
  position: absolute;
  right: 16px;
  bottom: 92px;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  background: var(--glass-strong);
  color: var(--ink-2);
  border-radius: 50%;
  box-shadow: var(--shadow-md);
  backdrop-filter: blur(10px);
  cursor: pointer;
  z-index: 4;
  animation: pop 0.22s var(--ease-out);
}

.sb-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--green-deep);
  color: var(--on-green);
  font-size: 10px;
  line-height: 16px;
  font-weight: 600;
}

/* ---------------------------------------------------------------- 输入区 */

#composer {
  padding: 9px 12px calc(9px + var(--safe-bottom));
  background: var(--glass);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(18px) saturate(150%);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
}

.composer-inner {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 4px 4px 4px 6px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 22px;
  transition: border-color 0.18s, box-shadow 0.18s, background 0.18s;
}

.composer-inner:focus-within {
  border-color: rgba(124, 179, 66, 0.55);
  background: var(--surface);
  box-shadow: 0 0 0 4px rgba(124, 179, 66, 0.10);
}

#input {
  flex: 1;
  min-height: 36px;
  max-height: 132px;
  padding: 8px 8px 8px 8px;
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
  background: none;
  border: none;
  outline: none;
  resize: none;
  overflow-y: auto;
}

#input::placeholder { color: var(--ink-faint); }

#send {
  flex: none;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 50%;
  background: var(--green-deep);
  color: var(--on-green);
  cursor: pointer;
  transition: transform 0.16s var(--ease), background 0.2s, opacity 0.2s;
  box-shadow: 0 4px 12px -4px rgba(79, 140, 62, 0.5);
}

#send:active:not(:disabled) { transform: scale(0.9); }
#send:disabled {
  background: var(--surface-sunk);
  color: var(--ink-faint);
  box-shadow: none;
  cursor: default;
}

/* ---------------------------------------------------------------- Toast */

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + var(--safe-bottom));
  transform: translateX(-50%) translateY(6px);
  max-width: 78vw;
  padding: 9px 16px;
  background: var(--toast-bg);
  color: var(--toast-ink);
  font-size: 13px;
  line-height: 1.4;
  border-radius: 99px;
  box-shadow: var(--shadow-md);
  z-index: 40;
  animation: toast-in 0.24s var(--ease-out);
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ---------------------------------------------------------------- 面板 */

#panel {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(18, 28, 24, 0.38);
  backdrop-filter: blur(3px);
  animation: fade-in 0.2s;
}

:root[data-theme="dark"] .login-card {
  box-shadow: var(--shadow-lg), inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.panel-card {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  min-height: 44dvh;
  max-height: 92dvh;
  background: var(--surface);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  box-shadow: var(--shadow-lg);
  animation: sheet-up 0.34s var(--ease-out);
}

@keyframes sheet-up {
  from { transform: translateY(24px); opacity: 0.6; }
  to { transform: none; opacity: 1; }
}

.sheet-handle {
  width: 38px;
  height: 4px;
  margin: 8px auto 0;
  border-radius: 99px;
  background: var(--line-strong);
  flex: none;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px 6px;
  flex: none;
}

.panel-title {
  font-size: 17px;
  font-weight: 650;
  letter-spacing: 0.3px;
}

#panel-close {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: none;
  background: var(--surface-sunk);
  color: var(--ink-dim);
  border-radius: 50%;
  cursor: pointer;
}

#panel-close:hover { color: var(--ink); }

.panel-tabs {
  display: flex;
  gap: 6px;
  padding: 6px 16px 12px;
  flex: none;
}

.ptab {
  padding: 7px 15px;
  border: 1px solid transparent;
  background: var(--surface-sunk);
  color: var(--ink-dim);
  font-size: 13.5px;
  border-radius: 99px;
  cursor: pointer;
  transition: all 0.18s;
}

.ptab.active {
  background: linear-gradient(160deg, rgba(124, 179, 66, 0.16), rgba(124, 179, 66, 0.08));
  border-color: rgba(124, 179, 66, 0.24);
  color: var(--ink);
  font-weight: 600;
}

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 2px 16px calc(24px + var(--safe-bottom));
  overscroll-behavior: contain;
}

@media (min-width: 720px) {
  #panel { align-items: center; padding: 24px; }
  .panel-card {
    max-width: 540px;
    max-height: 86dvh;
    border-radius: var(--r-xl);
  }
  .sheet-handle { display: none; }
  .panel-head { padding-top: 18px; }
}

/* ---------------------------------------------------------------- 记忆卡片 */

.banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  padding: 10px 13px;
  font-size: 13px;
  background: linear-gradient(100deg, rgba(192, 138, 94, 0.14), rgba(192, 138, 94, 0.06));
  border: 1px solid rgba(192, 138, 94, 0.22);
  border-radius: var(--r-sm);
  color: var(--ink-2);
}

.banner button {
  flex: none;
  padding: 6px 13px;
  font-size: 12.5px;
  color: var(--on-green);
  background: var(--green-deep);
  border: none;
  border-radius: 99px;
  cursor: pointer;
}

.mem-card {
  position: relative;
  margin-bottom: 9px;
  padding: 12px 14px 12px 16px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: border-color 0.18s, box-shadow 0.2s, transform 0.16s;
}

.mem-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 12px;
  bottom: 12px;
  width: 4px;
  border-radius: 0 4px 4px 0;
  background: var(--green);
  opacity: 0.85;
}

.mem-card[data-cat="preference"]::before { background: #6fa8c9; }
.mem-card[data-cat="event"]::before { background: var(--warm); }
.mem-card[data-cat="relation"]::before { background: #b58ac9; }

.mem-card:hover { border-color: var(--line-strong); box-shadow: var(--shadow-sm); }

.mem-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.mem-cat {
  font-size: 11.5px;
  color: var(--ink-dim);
  background: var(--surface-sunk);
  border-radius: 6px;
  padding: 2px 8px;
}

.mem-stars {
  display: inline-flex;
  gap: 2px;
  color: #d9a441;
}

.mem-stars svg { display: block; }

.mem-stars .off { opacity: 0.22; }

.mem-content {
  font-size: 14.5px;
  line-height: 1.55;
  color: var(--ink);
}

.mem-meta {
  margin-top: 7px;
  font-size: 11.5px;
  color: var(--ink-faint);
  line-height: 1.5;
}

.mem-detail {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--line-strong);
  cursor: default;
  animation: fade-in 0.2s;
}

.mem-detail .field { margin-bottom: 12px; }

.mem-detail .field input,
.mem-detail .field select { font-size: 14px; padding: 9px 12px; }

.mem-share {
  font-size: 13px;
  color: var(--ink-2);
  margin-bottom: 10px;
  line-height: 1.5;
}

.mem-share b { color: var(--green-deep); }

.mem-reason {
  font-size: 12.5px;
  color: var(--ink-dim);
  line-height: 1.55;
  margin-bottom: 12px;
  padding-left: 10px;
  border-left: 2px solid var(--line-strong);
}

.mem-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.mem-actions button {
  flex: 1;
  padding: 9px 0;
  font-size: 13.5px;
  color: var(--on-green);
  background: var(--green-deep);
  border: none;
  border-radius: var(--r-xs);
  cursor: pointer;
}

.mem-actions .btn-danger { background: var(--danger); color: #fff; }

.merge-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--line);
  font-size: 13.5px;
  line-height: 1.5;
}

.merge-row input { margin-top: 3px; accent-color: var(--green-deep); }

/* ---------------------------------------------------------------- 提醒 */

.rem-group-title {
  margin: 16px 0 8px;
  font-size: 12px;
  letter-spacing: 1px;
  color: var(--ink-faint);
  text-transform: uppercase;
}

.rem-group-title:first-child { margin-top: 2px; }

.rem-card {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  margin-bottom: 8px;
  padding: 12px 13px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  transition: opacity 0.2s;
}

.rem-check {
  position: relative;
  flex: none;
  margin-top: 1px;
}

.rem-check input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

.rem-check span {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border: 1.6px solid var(--line-strong);
  border-radius: 7px;
  color: transparent;
  transition: all 0.16s;
}

.rem-check input:checked + span {
  background: var(--green-deep);
  border-color: var(--green-deep);
  color: var(--on-green);
}

.rem-main { flex: 1; min-width: 0; }

.rem-content {
  font-size: 14.5px;
  line-height: 1.5;
  word-break: break-word;
}

.rem-when {
  margin-top: 5px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}

.rem-when.soon { color: var(--green-deep); font-weight: 600; }
.rem-when.late { color: var(--danger); }

.rem-tag {
  padding: 1px 7px;
  font-size: 10.5px;
  border-radius: 5px;
  background: var(--surface-sunk);
  color: var(--ink-dim);
}

.rem-card.done { opacity: 0.55; }
.rem-card.done .rem-content { text-decoration: line-through; color: var(--ink-dim); }

/* ---------------------------------------------------------------- 设置 */

.group {
  margin-bottom: 16px;
  padding: 14px 14px 6px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
}

.group-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

.group-title {
  font-size: 13.5px;
  font-weight: 650;
  letter-spacing: 0.3px;
}

.group-hint { font-size: 11.5px; color: var(--ink-faint); }

.group .field > span { font-size: 12px; }

.hint {
  display: block;
  margin-top: 5px;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--ink-dim);
  font-style: normal;
  word-break: break-all;
}

.actions-2 {
  display: flex;
  gap: 9px;
  margin: 4px 0 14px;
}

.btn-ghost {
  flex: 1;
  padding: 11px 0;
  font-size: 14px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: border-color 0.16s, background 0.16s;
}

.btn-ghost:hover { border-color: var(--line-strong); background: var(--surface-sunk); }

.actions-2 .btn-primary { flex: 1; padding: 11px 0; font-size: 14px; }

.btn-block { width: 100%; }
.group > .btn-ghost.btn-block { margin-bottom: 12px; }

.btn-danger {
  width: 100%;
  padding: 11px 0;
  font-size: 14px;
  color: var(--danger);
  background: var(--danger-soft);
  border: 1px solid var(--danger-line);
  border-radius: var(--r-sm);
  cursor: pointer;
  margin-bottom: 12px;
}

#set-status {
  margin-top: 4px;
  margin-bottom: 12px;
  padding: 10px 12px;
  font-size: 12.5px;
  line-height: 1.55;
  border-radius: var(--r-sm);
  background: var(--surface);
  border: 1px solid var(--line);
  word-break: break-all;
}

#set-status.ok { color: var(--green-deep); border-color: rgba(124, 179, 66, 0.3); }
#set-status.err { color: var(--danger); border-color: var(--danger-line); }

.theme-switch {
  display: flex;
  gap: 4px;
  padding: 3px;
  background: var(--surface-sunk);
  border-radius: 11px;
  margin-bottom: 12px;
}

.theme-switch button {
  flex: 1;
  padding: 8px 0;
  font-size: 12.5px;
  color: var(--ink-dim);
  background: none;
  border: none;
  border-radius: 9px;
  cursor: pointer;
  transition: all 0.18s;
}

.theme-switch button.active {
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

.panel-foot {
  text-align: center;
  font-size: 11.5px;
  color: var(--ink-faint);
  padding: 6px 0 10px;
  letter-spacing: 0.3px;
}

/* ---------------------------------------------------------------- 无障碍 / 动效降级 */

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

:focus-visible {
  outline: 2px solid var(--green-deep);
  outline-offset: 2px;
}

/* 小屏微调 */
@media (max-width: 360px) {
  .msg-row { max-width: 90%; }
  .login-card { padding: 26px 18px 18px; }
}

/* 面板内的空状态：居中，别贴在标题下面 */
.panel-body .empty-hint {
  margin: 46px auto;
  padding: 0 20px;
  text-align: center;
  line-height: 1.7;
  color: var(--ink-faint);
  font-size: 13.5px;
}

/* 暗色下 AI 头像保持可辨：提亮一档并加细边 */
:root[data-theme="dark"] .msg-avatar.ai {
  background: linear-gradient(150deg, #4a7a55, #315240);
  box-shadow: inset 0 0 0 1px rgba(180, 220, 190, 0.12);
}
