/* =====================================================================
   栖迟酒馆 · 视觉系统
   白天「宣纸书卷」：暖米纸底 · 松烟墨字 · 朱砂点睛 · 青瓷玩家气泡
   黑夜「灯下夜读」：深黛夜色 · 月白正文 · 琥珀灯火 · 黛蓝玩家气泡
   全部使用系统字体，零外链，国内网络 / 微信内置浏览器秒开
   ===================================================================== */

:root,
[data-theme="light"] {
  color-scheme: light;
  --bg-canvas: #f6f1e8;
  --bg-chat: #f4eee4;
  --bg-sidebar: #f8f4ec;
  --bg-bar: rgba(248, 244, 236, 0.86);
  --bg-surface: #fffcf6;
  --bg-surface-2: #fbf7ef;
  --bg-hover: #f0e9dc;
  --bg-selected: #ece3d3;
  --bg-input: #fffdf9;
  --bg-bubble-ai: #fffcf6;
  --bg-bubble-user: #e5ece5;
  --bg-tag: #efe7d9;
  --bg-code: #f4ede1;

  --border: rgba(84, 60, 32, 0.1);
  --border-strong: rgba(84, 60, 32, 0.24);
  --border-user: rgba(58, 96, 74, 0.14);

  --text-normal: #2c2620;
  --text-dialogue: #1e1914;
  --text-action: #8e8070;
  --text-sub: #6d6257;
  --text-muted: #a69b8d;

  --accent: #b2462c;          /* 朱砂 */
  --accent-soft: rgba(178, 70, 44, 0.1);
  --accent-ink: #9c3a22;
  --primary-bg: #2f2924;      /* 松烟墨 */
  --primary-fg: #fbf6ee;
  --danger: #c0392b;
  --success: #3f8a5a;

  --shadow-sm: 0 1px 2px rgba(80, 56, 28, 0.05);
  --shadow-card: 0 1px 2px rgba(80, 56, 28, 0.04), 0 6px 18px -10px rgba(80, 56, 28, 0.22);
  --shadow-pop: 0 18px 48px -12px rgba(60, 40, 18, 0.32), 0 2px 6px rgba(60, 40, 18, 0.06);
  --glow: radial-gradient(1200px 520px at 50% -180px, rgba(255, 236, 200, 0.75), transparent 70%);
  --grain-opacity: 0.045;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg-canvas: #13151a;
  --bg-chat: #14161c;
  --bg-sidebar: #171a20;
  --bg-bar: rgba(22, 25, 31, 0.84);
  --bg-surface: #1d2027;
  --bg-surface-2: #1a1d23;
  --bg-hover: #242832;
  --bg-selected: #2a2f3a;
  --bg-input: #1c1f26;
  --bg-bubble-ai: #1c1f26;
  --bg-bubble-user: #253041;
  --bg-tag: #262a33;
  --bg-code: #181b21;

  --border: rgba(232, 222, 200, 0.075);
  --border-strong: rgba(232, 222, 200, 0.2);
  --border-user: rgba(140, 170, 210, 0.14);

  --text-normal: #e6e0d4;
  --text-dialogue: #f2ece0;
  --text-action: #8e8a82;
  --text-sub: #aaa398;
  --text-muted: #6e6a64;

  --accent: #d8a75e;          /* 琥珀灯火 */
  --accent-soft: rgba(216, 167, 94, 0.12);
  --accent-ink: #e2b46e;
  --primary-bg: #e4d3b0;
  --primary-fg: #1b1d22;
  --danger: #e0645a;
  --success: #6bbf86;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.25), 0 8px 22px -12px rgba(0, 0, 0, 0.6);
  --shadow-pop: 0 22px 56px -12px rgba(0, 0, 0, 0.7), 0 2px 8px rgba(0, 0, 0, 0.35);
  --glow: radial-gradient(900px 460px at 82% -160px, rgba(216, 167, 94, 0.09), transparent 70%);
  --grain-opacity: 0.03;
}

:root {
  --font-ui: -apple-system, BlinkMacSystemFont, "PingFang SC", "HarmonyOS Sans SC", "HarmonyOS_Sans_SC", "MiSans", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", "Noto Sans CJK SC", "Source Han Sans SC", sans-serif;
  --font-serif: "Songti SC", "STSongti-SC-Regular", "Noto Serif CJK SC", "Noto Serif SC", "Source Han Serif SC", "Source Han Serif CN", "STSong", "SimSun", "Songti TC", Georgia, serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --font-prose: var(--font-serif);
  --prose-size: 16px;
  --prose-leading: 1.82;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --ease: cubic-bezier(0.22, 0.8, 0.24, 1);
  --radius-card: 16px;
}

[data-prose-font="sans"] { --font-prose: var(--font-ui); --prose-leading: 1.75; }
[data-prose-size="sm"] { --prose-size: 14.5px; }
[data-prose-size="md"] { --prose-size: 16px; }
[data-prose-size="lg"] { --prose-size: 17.5px; }

/* 主题图标 */
[data-theme="dark"] .icon-moon,
[data-theme="light"] .icon-sun { display: none; }
[data-theme="dark"] .icon-sun,
[data-theme="light"] .icon-moon { display: block; }

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: var(--bg-canvas);
  color: var(--text-normal);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  -webkit-text-size-adjust: 100%;
}

button, input, textarea, select { font-family: inherit; color: inherit; }
button { -webkit-user-select: none; user-select: none; }
code {
  font-family: var(--font-mono);
  font-size: 0.92em;
  background: var(--bg-tag);
  padding: 0 4px;
  border-radius: 4px;
}

/* 主题切换时的柔和过渡 */
.sidebar-panel, .chat-panel, .brand-header, .chat-topbar, .composer-area, .bottom-nav,
.msg-bubble, .char-card, .form-section, .capsule-composer, .modal-card, .btn, .chip-btn {
  transition: background-color 0.35s var(--ease), border-color 0.35s var(--ease), color 0.35s var(--ease), box-shadow 0.35s var(--ease);
}

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

/* ==================== 布局 ==================== */
.app-shell {
  display: flex;
  height: 100vh;
  height: 100dvh;
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
  background: var(--bg-canvas);
  position: relative;
  overflow: hidden;
}

/* ==================== 左栏 ==================== */
.sidebar-panel {
  width: 336px;
  min-width: 300px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100%;
  z-index: 20;
  position: relative;
}

.brand-header {
  padding: calc(10px + var(--safe-top)) 14px 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--bg-bar);
  -webkit-backdrop-filter: saturate(1.4) blur(16px);
  backdrop-filter: saturate(1.4) blur(16px);
  border-bottom: 1px solid var(--border);
}

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

.brand-title img {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  box-shadow: var(--shadow-card);
  flex-shrink: 0;
}

.brand-text { display: flex; flex-direction: column; min-width: 0; }

.brand-name {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 17px;
  letter-spacing: 2px;
  line-height: 1.2;
}

.brand-sub {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-right-group { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }

.api-badge {
  font-size: 11.5px;
  height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  cursor: pointer;
  border: 1px solid var(--border);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-surface);
  color: var(--text-sub);
  max-width: 132px;
  box-shadow: var(--shadow-sm);
}
.api-badge span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.api-badge:hover { border-color: var(--border-strong); color: var(--text-normal); }

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
  box-shadow: 0 0 0 3px var(--accent-soft);
  animation: pulse 2.2s ease-in-out infinite;
}
.status-dot.ready {
  background: var(--success);
  box-shadow: 0 0 0 3px rgba(80, 160, 110, 0.15);
  animation: none;
}
@keyframes pulse { 50% { opacity: 0.45; } }

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: var(--text-sub);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.18s, color 0.18s, transform 0.18s;
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:hover { color: var(--text-normal); background: var(--bg-hover); }
.icon-btn:active { transform: scale(0.92); }

.mobile-only { display: none; }

/* 分栏视图 */
.tab-view {
  display: none;
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px 20px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
.tab-view.active { display: block; animation: fadeIn 0.28s var(--ease); }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.toolbar-row { display: flex; gap: 8px; margin-bottom: 16px; }
.toolbar-row .btn { flex: 1; height: 38px; }

.list-caption {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: 2px;
  padding: 0 4px 8px;
  font-family: var(--font-serif);
}
.list-caption::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, var(--border-strong), transparent);
  align-self: center;
  margin-left: 6px;
}
.list-count { letter-spacing: 0; font-family: var(--font-ui); font-size: 11px; }

/* 按钮 */
.btn {
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-normal);
  height: 36px;
  padding: 0 14px;
  border-radius: 11px;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
}
.btn:hover { background: var(--bg-hover); border-color: var(--border-strong); }
.btn:active { transform: scale(0.98); }
.btn-ghost { background: transparent; box-shadow: none; }
.btn-primary {
  background: var(--primary-bg);
  border-color: var(--primary-bg);
  color: var(--primary-fg);
}
.btn-primary:hover { background: var(--primary-bg); border-color: var(--primary-bg); opacity: 0.9; }
.btn-sm { height: 32px; padding: 0 12px; font-size: 12.5px; border-radius: 9px; }
.btn-block { width: 100%; }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 28%, transparent); background: transparent; box-shadow: none; }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 8%, transparent); border-color: var(--danger); }
.btn[disabled] { opacity: 0.5; pointer-events: none; }
.push-left { margin-right: auto; }

.text-btn {
  border: none;
  background: none;
  color: var(--accent-ink);
  font-size: 12px;
  cursor: pointer;
  padding: 2px 0;
  font-weight: 500;
}
.text-btn:hover { text-decoration: underline; text-underline-offset: 3px; }

/* 角色书架 */
.char-list { display: flex; flex-direction: column; gap: 6px; }

.char-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px 10px 10px;
  border-radius: 14px;
  border: 1px solid transparent;
  cursor: pointer;
  position: relative;
}
.char-card:hover { background: var(--bg-hover); }
.char-card:active { transform: scale(0.99); }
.char-card.selected {
  background: var(--bg-surface);
  border-color: var(--border);
  box-shadow: var(--shadow-card);
}
.char-card.selected::before {
  content: "";
  position: absolute;
  left: -1px;
  top: 18px;
  bottom: 18px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}

.char-avatar {
  width: 54px;
  height: 54px;
  border-radius: 14px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--bg-tag);
  box-shadow: var(--shadow-card);
}

.char-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.char-name-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.char-name {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.char-sub-tag {
  font-size: 10.5px;
  color: var(--accent-ink);
  background: var(--accent-soft);
  padding: 1px 7px;
  border-radius: 999px;
  flex-shrink: 0;
  line-height: 1.6;
}
.char-tagline {
  font-size: 12.5px;
  color: var(--text-sub);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* 底部导航 */
.bottom-nav {
  display: flex;
  border-top: 1px solid var(--border);
  background: var(--bg-bar);
  -webkit-backdrop-filter: saturate(1.4) blur(16px);
  backdrop-filter: saturate(1.4) blur(16px);
  padding: 4px 0 calc(2px + var(--safe-bottom));
}
.nav-item {
  flex: 1;
  padding: 5px 4px 4px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 10.5px;
  letter-spacing: 1px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transition: color 0.2s;
}
.nav-item svg { transition: transform 0.25s var(--ease); }
.nav-item.active { color: var(--accent-ink); font-weight: 600; }
.nav-item.active svg { transform: translateY(-1px); }

/* ==================== 右栏 · 对话 ==================== */
.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--bg-chat);
  position: relative;
  min-width: 0;
  isolation: isolate;
}
/* 纸纹 + 柔光 */
.chat-panel::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--glow);
  pointer-events: none;
  z-index: -1;
}
.chat-panel::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: -1;
  opacity: var(--grain-opacity);
  background-image: url("data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.chat-topbar {
  padding: calc(8px + var(--safe-top)) 12px 8px 16px;
  min-height: 56px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-bar);
  -webkit-backdrop-filter: saturate(1.4) blur(16px);
  backdrop-filter: saturate(1.4) blur(16px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  z-index: 10;
}

.chat-topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }

.chat-char-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--bg-tag);
  box-shadow: 0 0 0 2px var(--bg-surface), 0 0 0 3px var(--border-strong);
}

.chat-char-title { min-width: 0; }
.title-line { display: flex; align-items: center; gap: 6px; min-width: 0; }
.chat-char-title h2 {
  font-family: var(--font-serif);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.5px;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lore-pill {
  font-size: 10px;
  padding: 0 6px;
  line-height: 17px;
  border-radius: 5px;
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
  color: var(--accent-ink);
  flex-shrink: 0;
  letter-spacing: 1px;
}
.chat-char-sub {
  font-size: 11.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.35;
}

.chat-actions { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }

/* 更多菜单 */
.menu-anchor { position: relative; }
.pop-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 168px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-pop);
  padding: 6px;
  z-index: 60;
  opacity: 0;
  transform: translateY(-6px) scale(0.97);
  transform-origin: top right;
  pointer-events: none;
  transition: opacity 0.18s var(--ease), transform 0.22s var(--ease);
}
.pop-menu.open { opacity: 1; transform: none; pointer-events: auto; }
.pop-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border: none;
  background: none;
  border-radius: 9px;
  font-size: 13.5px;
  color: var(--text-normal);
  cursor: pointer;
  text-align: left;
}
.pop-item svg { width: 16px; height: 16px; color: var(--text-sub); flex-shrink: 0; }
.pop-item:hover { background: var(--bg-hover); }
.pop-item.danger, .pop-item.danger svg { color: var(--danger); }
.pop-sep { height: 1px; background: var(--border); margin: 4px 6px; }

/* ==================== 消息流 ==================== */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* 场景题记 */
.scenario-banner {
  max-width: 720px;
  width: 100%;
  margin: 2px auto 2px;
  padding: 10px 14px 10px 14px;
  border-radius: 12px;
  border: 1px dashed var(--border-strong);
  font-family: var(--font-prose);
  font-size: 13px;
  line-height: 1.75;
  color: var(--text-sub);
  cursor: pointer;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  background: color-mix(in srgb, var(--bg-surface) 55%, transparent);
}
.scenario-banner .scene-seal {
  flex-shrink: 0;
  font-family: var(--font-serif);
  font-size: 11px;
  font-weight: 700;
  color: var(--accent-ink);
  border: 1.5px solid var(--accent);
  border-radius: 4px;
  padding: 0 4px;
  line-height: 18px;
  margin-top: 2px;
  letter-spacing: 1px;
}
.scenario-banner .scene-text {
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
}
.scenario-banner.expanded .scene-text { -webkit-line-clamp: unset; display: block; }

/* 楼层 */
.msg-row {
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}
.msg-row.user { align-items: flex-end; }
.msg-row.enter { animation: rise 0.42s var(--ease) both; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.msg-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  margin-bottom: 6px;
  padding: 0 2px;
  min-height: 24px;
}
.msg-row.user .msg-header { justify-content: flex-end; gap: 6px; }

.msg-author {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-sub);
  font-family: var(--font-serif);
  letter-spacing: 0.5px;
}
.msg-micro-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
  box-shadow: 0 0 0 1.5px var(--bg-surface), 0 0 0 2.5px var(--border);
}
.msg-inline-tools { display: inline-flex; align-items: center; gap: 2px; }

/* 角色气泡：一页书纸 */
.msg-bubble {
  padding: 14px 18px;
  border-radius: 4px var(--radius-card) var(--radius-card) var(--radius-card);
  background: var(--bg-bubble-ai);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
  color: var(--text-normal);
  width: 100%;
  overflow-wrap: anywhere;
  font-family: var(--font-prose);
  font-size: var(--prose-size);
  line-height: var(--prose-leading);
  letter-spacing: 0.2px;
}

/* 玩家气泡：青瓷 / 黛蓝 */
.msg-row.user .msg-bubble {
  width: auto;
  max-width: 86%;
  padding: 10px 15px;
  border-radius: var(--radius-card) 4px var(--radius-card) var(--radius-card);
  background: var(--bg-bubble-user);
  border-color: var(--border-user);
  box-shadow: var(--shadow-sm);
  line-height: 1.72;
}

.msg-bubble p { margin-bottom: 0.72em; }
.msg-bubble p:last-child { margin-bottom: 0; }

/* 动作 / 神态 / 环境：淡墨 */
.rp-action { color: var(--text-action); }
/* 纯叙述段落：略收字号，营造旁白感 */
.msg-bubble p.rp-narration { color: var(--text-action); font-size: 0.95em; }
/* 对白：浓墨 */
.rp-quote { color: var(--text-dialogue); font-weight: 500; }
[data-theme="dark"] .rp-quote { font-weight: 400; }

.rp-code {
  background: var(--bg-code);
  padding: 8px 11px;
  border-radius: 9px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-sub);
  margin: 10px 0 2px;
  white-space: pre-wrap;
  border: 1px solid var(--border);
  letter-spacing: 0;
}

/* 打字中 */
.typing-dots { display: inline-flex; gap: 5px; padding: 6px 0; }
.typing-dots i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: blink 1.2s infinite ease-in-out;
}
.typing-dots i:nth-child(2) { animation-delay: 0.15s; }
.typing-dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

/* 楼层工具 */
.swipe-pill {
  display: inline-flex;
  align-items: center;
  gap: 0;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  border-radius: 999px;
  padding: 0 2px;
  font-size: 11px;
  color: var(--text-muted);
  height: 24px;
  font-variant-numeric: tabular-nums;
}
.swipe-pill > span { padding: 0 2px; min-width: 26px; text-align: center; }

.micro-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  min-width: 26px;
  height: 24px;
  padding: 0 6px;
  border-radius: 999px;
  font-size: 13px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, background 0.15s;
}
.micro-btn svg { width: 14px; height: 14px; }
.micro-btn:hover:not(:disabled) { color: var(--text-normal); background: var(--bg-hover); }
.micro-btn:disabled { opacity: 0.3; cursor: default; }

/* ==================== 输入区 ==================== */
.composer-area {
  padding: 8px 14px calc(10px + var(--safe-bottom));
  background: linear-gradient(to top, var(--bg-chat) 55%, transparent);
}

.composer-inner {
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.quick-drawer {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  animation: fadeIn 0.22s var(--ease);
}
.quick-drawer[hidden] { display: none !important; }
.quick-drawer::-webkit-scrollbar { display: none; }

.chip-btn {
  white-space: nowrap;
  font-size: 12.5px;
  height: 30px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-sub);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  box-shadow: var(--shadow-sm);
}
.chip-btn:hover { color: var(--text-normal); border-color: var(--border-strong); }

.capsule-composer {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 5px 5px 5px 6px;
  box-shadow: var(--shadow-card);
}
.capsule-composer:focus-within {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  box-shadow: var(--shadow-card), 0 0 0 3px var(--accent-soft);
}

.composer-tool-btn,
.composer-asterisk-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-sub);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.25s var(--ease), background 0.18s, color 0.18s;
}
.composer-asterisk-btn {
  width: 30px;
  height: 30px;
  margin: 2px 0;
  font-family: var(--font-serif);
  font-size: 19px;
  font-weight: 700;
  padding-top: 6px;
  color: var(--accent-ink);
  background: var(--accent-soft);
}
.composer-tool-btn:hover { color: var(--text-normal); background: var(--bg-hover); }
.composer-asterisk-btn:active, .composer-tool-btn:active { transform: scale(0.9); }
.composer-tool-btn.active { color: var(--text-normal); background: var(--bg-hover); transform: rotate(45deg); }

.chat-textarea {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  color: var(--text-normal);
  padding: 7px 4px;
  font-size: 15px;
  line-height: 1.45;
  resize: none;
  max-height: 120px;
  min-height: 34px;
  outline: none;
}
.chat-textarea::placeholder { color: var(--text-muted); }

.send-circle-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: var(--primary-bg);
  color: var(--primary-fg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.2s var(--ease), opacity 0.2s, background 0.2s;
}
.send-circle-btn:hover { opacity: 0.9; }
.send-circle-btn:active { transform: scale(0.9); }
.send-circle-btn .icon-stop { display: none; }
.send-circle-btn.stop { background: var(--danger); color: #fff; }
.send-circle-btn.stop .icon-send { display: none; }
.send-circle-btn.stop .icon-stop { display: block; }

/* ==================== 表单 ==================== */
.form-section {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
}
.form-section h3 {
  font-family: var(--font-serif);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 1px;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.form-section h3::before {
  content: "";
  width: 3px;
  height: 13px;
  border-radius: 2px;
  background: var(--accent);
}
.section-desc { font-size: 12px; color: var(--text-muted); margin-bottom: 14px; line-height: 1.6; }

.field { margin-bottom: 12px; }
.field:last-child { margin-bottom: 0; }
.field label {
  display: block;
  font-size: 12px;
  color: var(--text-sub);
  margin-bottom: 5px;
}
.label-row { display: flex !important; justify-content: space-between; align-items: center; }
.field-inline { display: flex; gap: 12px; align-items: flex-end; }
.grow { flex: 1; min-width: 0; }
.narrow { width: 92px; flex-shrink: 0; }
.num-tag {
  font-variant-numeric: tabular-nums;
  color: var(--accent-ink);
  font-weight: 600;
  margin-left: 4px;
}

.field input:not([type="range"]),
.field select,
.field textarea {
  width: 100%;
  background: var(--bg-surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-normal);
  padding: 9px 11px;
  font-size: 14px;
  line-height: 1.55;
  outline: none;
  transition: border-color 0.18s, box-shadow 0.18s, background 0.18s;
  -webkit-appearance: none;
  appearance: none;
}
.field textarea { resize: vertical; }
.field textarea.mono { font-family: var(--font-mono); font-size: 12.5px; }
.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: color-mix(in srgb, var(--accent) 50%, var(--border));
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: var(--bg-input);
}
.field input::placeholder, .field textarea::placeholder { color: var(--text-muted); }

input[type="range"] {
  width: 100%;
  height: 34px;
  accent-color: var(--accent);
  background: transparent;
}

.hint-text { font-size: 11.5px; color: var(--text-muted); line-height: 1.6; margin-top: 6px; }
.footnote { text-align: center; font-size: 11px; color: var(--text-muted); letter-spacing: 2px; padding: 6px 0 4px; font-family: var(--font-serif); }

.btn-row { display: flex; gap: 8px; margin-top: 14px; }
.btn-row.wrap { flex-wrap: wrap; margin-top: 4px; }
.test-result { font-size: 12px; color: var(--text-sub); margin-top: 10px; line-height: 1.55; word-break: break-all; }
.test-result:empty { display: none; }
.test-result.ok { color: var(--success); }
.test-result.err { color: var(--danger); }

/* 服务商卡片 */
.provider-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}
.provider-card {
  position: relative;
  text-align: left;
  border: 1px solid var(--border);
  background: var(--bg-surface-2);
  border-radius: 12px;
  padding: 9px 11px 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-height: 52px;
  transition: border-color 0.18s, background 0.18s, box-shadow 0.18s, transform 0.15s;
}
.provider-card:active { transform: scale(0.98); }
.provider-card:hover { border-color: var(--border-strong); }
.provider-card .pc-name { font-size: 13.5px; font-weight: 600; color: var(--text-normal); line-height: 1.35; }
.provider-card .pc-badge { font-size: 10.5px; color: var(--text-muted); line-height: 1.4; }
.provider-card.recommended .pc-badge { color: var(--accent-ink); font-weight: 500; }
.provider-card.limited .pc-badge { color: var(--text-muted); }
.provider-card.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 0 0 1px var(--accent) inset;
}
.provider-card.active::after {
  content: "";
  position: absolute;
  right: 9px;
  top: 10px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
}
.provider-hint {
  font-size: 11.5px;
  color: var(--text-sub);
  line-height: 1.65;
  margin: 0 0 14px;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--bg-tag);
}
.provider-hint:empty { display: none; }
.provider-hint a { color: var(--accent-ink); text-decoration: none; font-weight: 500; white-space: nowrap; }

/* 阅读偏好 */
.pref-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 7px 0; }
.pref-row + .pref-row { border-top: 1px solid var(--border); }
.pref-label { font-size: 13px; color: var(--text-sub); flex-shrink: 0; }
.segmented {
  display: inline-flex;
  background: var(--bg-tag);
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}
.segmented button {
  border: none;
  background: transparent;
  font-size: 12.5px;
  padding: 5px 11px;
  border-radius: 8px;
  color: var(--text-sub);
  cursor: pointer;
  transition: background 0.2s, color 0.2s, box-shadow 0.2s;
  white-space: nowrap;
}
.segmented button.on { background: var(--bg-surface); color: var(--text-normal); box-shadow: var(--shadow-card); font-weight: 600; }

/* 头像 */
.avatar-upload-row { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.avatar-preview-img {
  width: 68px;
  height: 68px;
  border-radius: 18px;
  object-fit: cover;
  background: var(--bg-tag);
  box-shadow: var(--shadow-card);
}

/* ==================== 弹窗 ==================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 14, 8, 0.42);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s var(--ease), visibility 0s linear 0.25s;
}
[data-theme="dark"] .modal-backdrop { background: rgba(0, 0, 0, 0.55); }
.modal-backdrop.open { opacity: 1; visibility: visible; transition: opacity 0.25s var(--ease); }

.modal-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  width: 100%;
  max-width: 480px;
  max-height: 88vh;
  max-height: 88dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-pop);
  transform: translateY(14px) scale(0.98);
  transition: transform 0.32s var(--ease);
}
.modal-backdrop.open .modal-card { transform: none; }

.modal-header {
  padding: 14px 12px 12px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.modal-title { font-family: var(--font-serif); font-weight: 700; font-size: 16.5px; letter-spacing: 1px; }
.modal-sub { font-size: 11.5px; color: var(--text-muted); margin-top: 1px; }

.modal-body {
  padding: 16px 18px;
  overflow-y: auto;
  flex: 1;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.modal-footer {
  padding: 12px 18px calc(12px + var(--safe-bottom));
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.modal-footer .btn { height: 38px; padding: 0 16px; font-size: 13.5px; }

.step-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  margin: 2px 0 8px;
}
.step-label i {
  font-style: normal;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary-bg);
  color: var(--primary-fg);
  font-size: 11px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-serif);
}
.step-label .text-btn { margin-left: auto; }

.provider-tip {
  background: var(--bg-tag);
  border-radius: 12px;
  padding: 9px 11px;
  margin-bottom: 16px;
  font-size: 12px;
  line-height: 1.65;
  color: var(--text-sub);
}
.key-link {
  display: inline-block;
  margin-top: 4px;
  color: var(--accent-ink);
  font-weight: 600;
  text-decoration: none;
  font-size: 12.5px;
}
.key-link[hidden] { display: none; }

.adv { margin-top: 2px; }
.adv summary {
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  list-style: none;
  padding: 4px 0 8px;
}
.adv summary::-webkit-details-marker { display: none; }
.adv summary::before { content: "▸ "; }
.adv[open] summary::before { content: "▾ "; }

/* 轻提示 */
.toast {
  position: fixed;
  top: calc(14px + var(--safe-top));
  left: 50%;
  transform: translate(-50%, -12px);
  background: var(--primary-bg);
  color: var(--primary-fg);
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s var(--ease), transform 0.28s var(--ease);
  z-index: 200;
  box-shadow: var(--shadow-pop);
  max-width: calc(100vw - 32px);
  text-align: center;
  line-height: 1.5;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ==================== 手机小屏 ==================== */
@media (max-width: 820px) {
  .sidebar-panel {
    width: 100%;
    min-width: 0;
    position: absolute;
    inset: 0;
    border-right: none;
    transition: transform 0.38s var(--ease), opacity 0.3s var(--ease);
  }
  .app-shell.mobile-chat-open .sidebar-panel {
    transform: translateX(-24%);
    opacity: 0;
    pointer-events: none;
  }
  .chat-panel {
    width: 100%;
    position: absolute;
    inset: 0;
    transform: translateX(100%);
    transition: transform 0.38s var(--ease);
    z-index: 30;
    box-shadow: -12px 0 32px -16px rgba(0, 0, 0, 0.25);
  }
  .app-shell.mobile-chat-open .chat-panel { transform: translateX(0); }
  .mobile-only { display: inline-flex; }

  .brand-header { padding: calc(8px + var(--safe-top)) 10px 8px 14px; }
  .brand-title img { width: 32px; height: 32px; }

  .chat-topbar {
    padding: calc(5px + var(--safe-top)) 6px 5px 4px;
    min-height: 50px;
  }
  .chat-topbar-left { gap: 8px; }
  .chat-char-avatar { width: 32px; height: 32px; }
  .chat-char-title h2 { font-size: 15.5px; }
  .icon-btn { width: 36px; height: 36px; }

  .messages-container { padding: 12px 12px 16px; gap: 16px; }
  .msg-bubble { padding: 12px 14px; }
  .msg-row.user .msg-bubble { max-width: 88%; padding: 9px 13px; }

  .composer-area { padding: 6px 10px calc(8px + var(--safe-bottom)); }

  .modal-backdrop { align-items: flex-end; padding: 0; }
  .modal-card {
    max-width: none;
    border-radius: 22px 22px 0 0;
    max-height: 92vh;
    max-height: 92dvh;
    border-bottom: none;
    transform: translateY(100%);
  }
  .modal-card::before {
    content: "";
    display: block;
    width: 36px;
    height: 4px;
    border-radius: 4px;
    background: var(--border-strong);
    margin: 8px auto 0;
  }
  .modal-header { padding-top: 6px; }
}

@media (max-width: 360px) {
  .api-badge { max-width: 96px; }
  .brand-sub { display: none; }
}

@media (min-width: 1200px) {
  .messages-container { padding: 22px 32px 28px; }
}

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