:root {
  --bg: rgb(var(--gray-255));
  --bg-side: rgb(var(--gray-250));
  --bg-soft: rgb(var(--gray-245));
  --fg: rgb(var(--gray-16));
  --fg-2: rgb(var(--gray-110));
  --fg-3: rgb(var(--gray-136));
  --line: rgb(var(--gray-236));
  --line-2: rgb(var(--gray-222));
  --ok: rgb(var(--gray-136));
  --warn: rgb(var(--gray-168));
  --bad: rgb(var(--gray-110));
  --shadow-sm: 0 1px 2px rgba(var(--gray-16), .05);
  --shadow-md: 0 10px 30px rgba(var(--gray-16), .10);
  --shadow-lg: 0 24px 70px rgba(var(--gray-16), .16);
  --r-sm: 11px;
  --r-md: 16px;
  --r-lg: 24px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

body { overflow: hidden; }

.app { display: flex; height: 100dvh; }

/* ================= 侧栏 ================= */
.side {
  flex: 0 0 272px;
  width: 272px;
  display: flex;
  flex-direction: column;
  background: var(--bg-side);
  border-right: 1px solid var(--line);
  min-height: 0;
}

.side-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px;
  padding: 16px 12px 0;
}

.draw-entry {
  flex: 1;
  height: 40px;
  display: flex; align-items: center; justify-content: center; gap: 7px;
  padding: 0 12px;
  border: 1px solid var(--line-2);
  border-radius: 11px;
  background: rgb(var(--gray-255));
  color: var(--fg-2);
  font: inherit; font-size: 13.2px; font-weight: 500;
  cursor: pointer;
  transition: .16s ease;
}
.draw-entry:hover { border-color: rgb(var(--gray-200)); color: var(--fg); background: rgb(var(--gray-250)); }
.draw-entry.on { border-color: rgb(var(--gray-222)); color: var(--fg); background: rgb(var(--gray-236)); font-weight: 600; }
.draw-entry.on:hover { border-color: rgb(var(--gray-200)); color: var(--fg); background: rgb(var(--gray-236)); }
.draw-entry.on svg { opacity: 1; }
.draw-entry svg { flex: 0 0 auto; opacity: .85; }

.icon-btn {
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--fg-3);
  cursor: pointer;
  transition: .16s ease;
}
.icon-btn:hover { background: rgb(var(--gray-255)); border-color: var(--line); color: var(--fg); }

.new-char {
  margin: 8px 12px 10px;
  height: 40px;
  display: flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px dashed var(--line-2);
  border-radius: 12px;
  background: rgb(var(--gray-255));
  color: var(--fg-2);
  font: inherit; font-size: 13.2px;
  cursor: pointer;
  transition: .18s ease;
}
.new-char:hover { border-style: solid; border-color: var(--fg); color: var(--fg); box-shadow: var(--shadow-sm); }

.char-list { flex: 1 1 auto; overflow-y: auto; padding: 0 8px 8px; min-height: 0; }
.char-list::-webkit-scrollbar { width: 8px; }
.char-list::-webkit-scrollbar-thumb { background: rgb(var(--gray-236)); border-radius: 8px; border: 2px solid var(--bg-side); }

.char {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px;
  border-radius: 13px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: .15s ease;
  margin-bottom: 2px;
}
.char { position: relative; overflow: hidden; }
.char:hover { background: rgb(var(--gray-255)); border-color: var(--line); }
.char.active { background: rgb(var(--gray-255)); border-color: var(--line-2); box-shadow: var(--shadow-sm); }
.char.active::before {
  content: ''; position: absolute; left: 2px; top: 20%; bottom: 20%;
  width: 3px; border-radius: 3px; background: var(--fg);
}

.char-av {
  flex: 0 0 36px;
  width: 36px; height: 36px;
  border-radius: 12px;
  display: grid; place-items: center;
  font-size: 14px; font-weight: 650;
  color: rgb(var(--gray-255));
  background: linear-gradient(150deg, rgb(var(--gray-56)), rgb(var(--gray-16)));
  user-select: none;
}
.char.active .char-av { background: linear-gradient(150deg, rgb(var(--gray-34)), rgb(var(--gray-16))); }

.char-info { min-width: 0; flex: 1; }
.char-info b {
  display: block;
  font-size: 13.6px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.char-info small {
  display: block;
  font-size: 11.6px; color: var(--fg-3);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.side-foot { flex: 0 0 auto; padding: 10px 12px 14px; border-top: 1px solid var(--line); }

.provider-line {
  width: 100%; height: 36px;
  display: flex; align-items: center; gap: 8px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgb(var(--gray-255));
  color: var(--fg-2);
  font: inherit; font-size: 12.4px;
  cursor: pointer;
  transition: .16s ease;
  overflow: hidden;
}
.provider-line:hover { border-color: rgb(var(--gray-222)); color: var(--fg); }
.ptext { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--fg-3); flex: 0 0 auto; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px rgba(var(--gray-136), .12); }
.dot.warn { background: var(--warn); box-shadow: 0 0 0 3px rgba(var(--gray-168), .12); }
.dot.bad { background: var(--bad); }

/* ================= 主区 ================= */
.main { flex: 1 1 auto; display: flex; flex-direction: column; min-width: 0; position: relative; }

.chat-head {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 11px;
  padding: 11px max(18px, calc((100% - 860px) / 2));
  border-bottom: 1px solid var(--line);
  background: rgba(var(--gray-255), .88);
  backdrop-filter: saturate(180%) blur(14px);
  z-index: 4;
}

.mini-avatar {
  flex: 0 0 34px;
  width: 34px; height: 34px;
  border-radius: 11px;
  display: grid; place-items: center;
  font-size: 13px; font-weight: 650;
  color: rgb(var(--gray-255));
  background: linear-gradient(150deg, rgb(var(--gray-56)), rgb(var(--gray-16)));
  user-select: none;
}

.who { min-width: 0; flex: 1; }
.who b { display: block; font-size: 14.2px; font-weight: 620; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who small { display: block; font-size: 11.8px; color: var(--fg-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.head-actions { display: flex; align-items: center; gap: 6px; }

.pill {
  height: 32px;
  padding: 0 12px;
  display: inline-flex; align-items: center; gap: 5px;
  border: 1px solid var(--line-2);
  border-radius: 9px;
  background: rgb(var(--gray-255));
  color: var(--fg-2);
  font: inherit; font-size: 12.5px;
  cursor: pointer;
  transition: .16s ease;
  white-space: nowrap;
}
.pill:hover { border-color: rgb(var(--gray-200)); color: var(--fg); box-shadow: var(--shadow-sm); }
.pill.primary { background: var(--fg); border-color: var(--fg); color: rgb(var(--gray-255)); }
.pill.primary:hover { background: rgb(var(--gray-0)); border-color: rgb(var(--gray-0)); color: rgb(var(--gray-255)); }

/* ================= 消息区 ================= */
.messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 24px 20px 10px;
  min-height: 0;
}
.messages::-webkit-scrollbar { width: 10px; }
.messages::-webkit-scrollbar-thumb { background: rgb(var(--gray-236)); border-radius: 10px; border: 3px solid rgb(var(--gray-255)); }
.messages::-webkit-scrollbar-thumb:hover { background: rgb(var(--gray-222)); }

.row {
  display: flex; gap: 12px;
  max-width: 860px;
  margin: 0 auto 20px;
  animation: pop .22s ease both;
}
.row.me { flex-direction: row-reverse; }

@keyframes pop {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.avatar {
  flex: 0 0 34px;
  width: 34px; height: 34px;
  border-radius: 11px;
  display: grid; place-items: center;
  font-size: 12.5px; font-weight: 650;
  color: rgb(var(--gray-255));
  background: linear-gradient(150deg, rgb(var(--gray-56)), rgb(var(--gray-16)));
  margin-top: 2px;
  user-select: none;
}
.row.me .avatar { background: rgb(var(--gray-245)); color: var(--fg-2); }
.row.grouped { margin-top: -16px; margin-bottom: 6px; }
.row.grouped .avatar { opacity: 0; }
.row.grouped.ai .bubble { border-top-left-radius: 5px; }
.row.ai:has(+ .row.ai.grouped) .bubble { border-bottom-left-radius: 5px; }
.row.me:has(+ .row.me.grouped) .bubble { border-bottom-right-radius: 5px; }
.row.grouped.me .bubble { border-top-right-radius: 5px; }

.bubble {
  max-width: min(660px, 76%);
  padding: 12px 16px;
  border-radius: var(--r-md);
  font-size: 14.6px;
  line-height: 1.74;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.row.ai .bubble { background: rgb(var(--gray-255)); border: 1px solid var(--line); border-top-left-radius: 6px; box-shadow: var(--shadow-sm); }
.row.story-opening .avatar { display: none; }
.row.ai.story-opening .bubble { width: 100%; max-width: 660px; padding: 16px; border-radius: 16px; }
.story-opening-section + .story-opening-section { margin-top: 14px; padding-top: 12px; border-top: 1px solid rgb(var(--gray-222)); }
.story-opening-section h3 { margin: 0 0 5px; color: rgb(var(--gray-56)); font-size: 14px; }
.story-opening-section:first-child h3 { font-size: 17px; }
.story-opening-section p { margin: 0; }
.story-choices .story-choice { display: block; width: 100%; min-height: 44px; margin-top: 6px; padding: 8px 10px; text-align: left; white-space: normal; overflow-wrap: anywhere; }
.story-narration-body { width: 100%; max-width: 680px; min-width: 0; }
.story-narrator { color: var(--fg-3); font-size: 12px; font-weight: 600; margin-bottom: 6px; }
#messages.story-creation-chat .story-narration .bubble {
  width: 100%; max-width: none; padding: 0; border: 0; border-radius: 0;
  background: transparent; box-shadow: none; font-size: 14px; line-height: 1.65;
}
.story-narration :is(.story-intro-text, .story-past-choice) { margin: 0; }
.story-narration .story-intro-text + .story-opening-section { margin-top: 14px; }
.story-narration .story-opening-section h3 { font-size: 1em; }
.story-narration .story-choice { font-size: inherit; line-height: 1.45; }
.story-narration .story-past-choice + .story-past-choice { margin-top: 4px; }
.row.me .bubble { background: var(--fg); color: rgb(var(--gray-255)); border-top-right-radius: 6px; }
.row.sys .bubble { background: var(--bg-soft); border: 0; color: var(--fg-3); font-size: 13px; }
.row.err .bubble { background: rgb(var(--gray-245)); border: 1px solid rgb(var(--gray-222)); color: rgb(var(--gray-80)); font-size: 13.2px; }

.cursor {
  display: inline-block;
  width: 7px; height: 15px;
  margin-left: 2px;
  vertical-align: -2px;
  background: var(--fg-3);
  border-radius: 2px;
  animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.typing { display: inline-flex; gap: 4px; align-items: center; height: 20px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: rgb(var(--gray-200)); animation: bob 1.1s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes bob { 0%, 60%, 100% { transform: translateY(0); opacity: .55; } 30% { transform: translateY(-4px); opacity: 1; } }

/* 空状态 */
.empty {
  height: 100%;
  max-width: 860px;
  margin: 0 auto;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center;
  padding-bottom: 40px;
  animation: pop .3s ease both;
}
.empty-mark { font-family: Georgia, serif; font-size: 64px; line-height: .6; color: rgb(var(--gray-236)); margin-bottom: 6px; }
.empty h1 { font-size: 19px; font-weight: 600; margin: 10px 0 6px; letter-spacing: .3px; }
.empty p { margin: 0; color: var(--fg-3); font-size: 13.4px; }
.empty .cta {
  margin-top: 20px;
  height: 38px; padding: 0 20px;
  border: 1px solid var(--line-2);
  border-radius: 999px;
  background: rgb(var(--gray-255));
  color: var(--fg);
  font: inherit; font-size: 13.5px;
  cursor: pointer;
  transition: .2s ease;
  box-shadow: var(--shadow-sm);
}
.empty .cta:hover { border-color: var(--fg); transform: translateY(-1px); box-shadow: var(--shadow-md); }

.empty-av {
  width: 76px; height: 76px;
  border-radius: 24px;
  display: grid; place-items: center;
  font-size: 27px; font-weight: 650;
  color: rgb(var(--gray-255));
  background: linear-gradient(150deg, rgb(var(--gray-56)), rgb(var(--gray-16)));
  margin-bottom: 16px;
  box-shadow: 0 12px 30px rgba(var(--gray-16), .14);
}

.empty-tip { margin-top: 14px; font-size: 12.2px; color: rgb(var(--gray-200)); }

/* ================= 输入区 ================= */
.composer-wrap { flex: 0 0 auto; padding: 8px 20px 16px; position: relative; }

/* 输入框上方的轻提示：报错和提示都不进对话流 */
.notice {
  position: absolute;
  left: 50%;
  bottom: calc(100% - 2px);
  transform: translate(-50%, 8px);
  max-width: min(600px, calc(100% - 36px));
  padding: 9px 16px;
  border-radius: 12px;
  background: rgb(var(--gray-250));
  border: 1px solid rgb(var(--gray-222));
  color: rgb(var(--gray-80));
  font-size: 13px;
  line-height: 1.55;
  text-align: center;
  box-shadow: 0 8px 24px rgba(var(--gray-34), .07);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
  z-index: 40;
}
.notice.show { opacity: 1; transform: translate(-50%, 0); }
.notice.ok { background: rgb(var(--gray-245)); border-color: rgb(var(--gray-222)); color: rgb(var(--gray-80)); }

.composer {
  display: flex; align-items: flex-end; gap: 10px;
  max-width: 860px; margin: 0 auto;
  padding: 8px 8px 8px 18px;
  background: rgb(var(--gray-255));
  border: 1px solid var(--line-2);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  transition: border-color .18s ease, box-shadow .18s ease;
}
.composer:focus-within { border-color: rgb(var(--gray-200)); box-shadow: 0 4px 22px rgba(var(--gray-16), .07); }

.composer textarea {
  flex: 1 1 auto;
  border: 0; outline: 0; resize: none;
  background: transparent;
  font: inherit; font-size: 14.8px;
  line-height: 1.62;
  color: var(--fg);
  padding: 9px 0;
  max-height: 168px;
  min-height: 24px;
}
.composer textarea::placeholder { color: rgb(var(--gray-168)); }

.composer button {
  flex: 0 0 auto;
  width: 38px; height: 38px;
  border: 0; border-radius: 50%;
  background: var(--fg);
  color: rgb(var(--gray-255));
  display: grid; place-items: center;
  cursor: pointer;
  transition: .18s ease;
}
.composer button:hover:not(:disabled) { transform: scale(1.05); }
.composer button:disabled { background: rgb(var(--gray-236)); color: rgb(var(--gray-200)); cursor: not-allowed; }

.hint { max-width: 860px; margin: 8px auto 0; text-align: center; font-size: 11.4px; color: rgb(var(--gray-200)); letter-spacing: .2px; }

/* ================= 对话记录弹层 ================= */
.pop {
  position: absolute;
  right: 18px; top: 58px;
  width: 316px;
  max-height: 66vh;
  display: none;
  flex-direction: column;
  background: rgb(var(--gray-255));
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow-md);
  z-index: 12;
  overflow: hidden;
  animation: pop .18s ease both;
}
.pop.show { display: flex; }

.pop-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 12.8px;
  color: var(--fg-2);
}

.link-btn {
  border: 0; background: transparent;
  color: var(--fg-2);
  font: inherit; font-size: 12.4px;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 6px;
}
.link-btn:hover { color: var(--fg); background: var(--bg-soft); }

.pop-list { overflow-y: auto; padding: 6px; }
.pop-list::-webkit-scrollbar { width: 8px; }
.pop-list::-webkit-scrollbar-thumb { background: rgb(var(--gray-236)); border-radius: 8px; }

.hist {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 10px;
  border-radius: 10px;
  cursor: pointer;
  transition: .14s ease;
}
.hist:hover { background: var(--bg-soft); }
.hist.active { background: var(--bg-soft); }
.hist-main { flex: 1; min-width: 0; }
.hist-main b {
  display: block; font-size: 13.1px; font-weight: 550;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.hist-main small { font-size: 11.4px; color: var(--fg-3); }
.hist-del {
  flex: 0 0 auto;
  width: 24px; height: 24px;
  border: 0; border-radius: 7px;
  background: transparent; color: rgb(var(--gray-200));
  cursor: pointer; font-size: 15px; line-height: 1;
  opacity: 0; transition: .14s;
}
.hist:hover .hist-del { opacity: 1; }
.hist-del:hover { background: rgb(var(--gray-245)); color: var(--bad); }

.pop-empty { padding: 18px 12px; text-align: center; font-size: 12.6px; color: var(--fg-3); }

/* ================= 面板 ================= */
.sheet-mask {
  position: fixed; inset: 0;
  background: rgba(var(--gray-16), .18);
  backdrop-filter: blur(2px);
  opacity: 0; pointer-events: none;
  transition: opacity .22s ease;
  z-index: 20;
}
.sheet-mask.show { opacity: 1; pointer-events: auto; }

.sheet {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(430px, 100%);
  background: rgb(var(--gray-255));
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow-lg);
  transform: translateX(102%);
  transition: transform .28s cubic-bezier(.22, .8, .3, 1);
  z-index: 21;
  display: flex;
  flex-direction: column;
  padding: 22px 22px 26px;
  overflow-y: auto;
}
.sheet.show { transform: none; }

.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.sheet-head h2 { font-size: 16px; font-weight: 650; margin: 0; letter-spacing: .2px; }

.row2 { display: flex; gap: 12px; }

.avatar-edit { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.avatar-preview {
  flex: 0 0 auto;
  width: 64px; height: 64px;
  border-radius: 20px;
  display: grid; place-items: center;
  font-size: 23px; font-weight: 650;
  color: rgb(var(--gray-255));
  background: linear-gradient(150deg, rgb(var(--gray-56)), rgb(var(--gray-16)));
  overflow: hidden;
}
.avatar-preview img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar-actions { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.avatar-actions small { flex: 0 0 100%; font-size: 11.2px; color: var(--fg-3); }

/* 头像图片通用 */
.char-av img, .avatar img, .mini-avatar img, .empty-av img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
  border-radius: inherit;
}
.has-img { background: rgb(var(--gray-236)) !important; }

.field { display: block; margin-bottom: 15px; flex: 1; min-width: 0; }
.field > span { display: block; font-size: 12.2px; color: var(--fg-2); margin-bottom: 6px; letter-spacing: .2px; }
.field > span b { color: var(--fg); font-weight: 600; }

.field input[type=text],
.field input[type=password],
.field textarea {
  width: 100%;
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  background: rgb(var(--gray-250));
  padding: 10px 12px;
  font: inherit; font-size: 13.6px;
  color: var(--fg);
  outline: 0;
  transition: .16s ease;
  resize: vertical;
}
.field input:focus, .field textarea:focus {
  border-color: rgb(var(--gray-200));
  background: rgb(var(--gray-255));
  box-shadow: 0 0 0 3px rgba(var(--gray-16), .045);
}
.field small { display: block; margin-top: 5px; font-size: 11.2px; color: var(--fg-3); }

.field-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.field-head > span { font-size: 12.2px; color: var(--fg-2); letter-spacing: .2px; }

.mem-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-top: 7px; font-size: 11.2px; color: var(--fg-3);
}
.switch-btn {
  border: 1px solid var(--line-2);
  background: rgb(var(--gray-255));
  color: var(--fg-2);
  font: inherit; font-size: 11.6px;
  padding: 3px 9px;
  border-radius: 7px;
  cursor: pointer;
  transition: .16s ease;
}
.switch-btn:hover:not(:disabled) { border-color: var(--fg); color: var(--fg); }
.switch-btn:disabled { opacity: .55; cursor: default; }
#cMemory { line-height: 1.72; max-height: 300px; }
.switch { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; }
.switch input { accent-color: rgb(var(--gray-16)); width: 13px; height: 13px; cursor: pointer; }
#memStamp { text-align: right; }
.mem-flash { animation: memflash .9s ease; }
@keyframes memflash {
  0% { box-shadow: 0 0 0 0 rgba(var(--gray-136), .35); }
  100% { box-shadow: 0 0 0 10px rgba(var(--gray-136), 0); }
}

.field input[type=range] {
  width: 100%;
  -webkit-appearance: none; appearance: none;
  height: 4px; border-radius: 4px;
  background: linear-gradient(90deg, var(--fg) var(--pct, 50%), rgb(var(--gray-236)) var(--pct, 50%));
  outline: 0;
}
.field input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: rgb(var(--gray-255));
  border: 1.5px solid var(--fg);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
}

/* 预设接口列表 */
.preset-hint { display: block; margin: -2px 0 8px; font-size: 11.2px; color: var(--fg-3); }
.preset-list { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.preset {
  position: relative;
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  padding: 10px 22px 10px 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgb(var(--gray-255));
  cursor: pointer;
  transition: .16s ease;
  text-align: left;
  font: inherit;
}
.preset:hover { border-color: rgb(var(--gray-200)); background: rgb(var(--gray-255)); }
.preset.active { border-color: var(--fg); background: rgb(var(--gray-250)); box-shadow: 0 0 0 3px rgba(var(--gray-16), .05); }
.preset b { font-size: 12.8px; font-weight: 550; color: var(--fg); white-space: nowrap; }
.preset small { font-size: 10.6px; color: var(--fg-3); display: block; margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.preset .tick {
  position: absolute; right: 11px; top: 50%; transform: translateY(-50%);
  color: var(--fg); opacity: 0; font-size: 12px;
}
.preset.active .tick { opacity: 1; }

.sheet-foot {
  display: flex; gap: 10px;
  position: sticky;
  bottom: -26px;
  margin: 10px -22px -26px;
  padding: 13px 22px 20px;
  background: rgb(var(--gray-255));
  border-top: 1px solid var(--line);
  z-index: 2;
}

.test-btn, .save-btn {
  height: 40px;
  border-radius: var(--r-sm);
  font: inherit; font-size: 13.6px;
  cursor: pointer;
  transition: .18s ease;
}
.test-btn {
  flex: 0 0 auto; padding: 0 16px;
  background: rgb(var(--gray-255));
  border: 1px solid var(--line-2);
  color: var(--fg-2);
}
.test-btn:hover:not(:disabled) { border-color: var(--fg); color: var(--fg); }
.test-btn.danger:hover:not(:disabled) { border-color: var(--bad); color: var(--bad); background: rgb(var(--gray-250)); }
.save-btn {
  flex: 1 1 auto;
  background: var(--fg);
  border: 1px solid var(--fg);
  color: rgb(var(--gray-255));
}
.save-btn:hover { opacity: .88; }
.test-btn:disabled { opacity: .5; cursor: default; }

.test-out {
  margin-top: 12px;
  font-size: 12.4px;
  line-height: 1.6;
  color: var(--fg-3);
  white-space: pre-wrap;
  word-break: break-word;
}
.test-out.ok { color: rgb(var(--gray-110)); }
.test-out.bad { color: rgb(var(--gray-80)); }


/* ================= 生图 ================= */
/* 生图视图：独立于角色聊天 */
.draw-view { display: none; flex: 1 1 auto; min-height: 0; overflow-y: auto; }
.draw-view::-webkit-scrollbar { width: 10px; }
.draw-view::-webkit-scrollbar-thumb { background: rgb(var(--gray-236)); border-radius: 8px; border: 3px solid rgb(var(--gray-255)); }
body.draw-mode .draw-view { display: block; }
body.draw-mode .chat-head,
body.draw-mode .messages,
body.draw-mode .composer-wrap,
body.draw-mode .pop,
body.draw-mode .side-foot { display: none !important; }

.draw-inner { max-width: 860px; margin: 0 auto; padding: 32px 24px 70px; }
.draw-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.draw-head h2 { margin: 0; font-size: 19px; font-weight: 650; letter-spacing: .2px; }
.style-tag {
  padding: 3px 9px;
  border: 1px solid var(--line-2);
  border-radius: 999px;
  background: rgb(var(--gray-250));
  color: var(--fg-3);
  font-size: 11.4px; font-weight: 500;
  letter-spacing: .3px;
  white-space: nowrap;
}
.style-tag.model-tag {
  border-color: rgb(var(--gray-222));
  background: rgb(var(--gray-255));
  color: rgb(var(--gray-56));
  font-weight: 600;
}

.who-row { display: flex; align-items: center; gap: 10px; margin: 0 0 14px; flex-wrap: wrap; }
.who-label { flex: 0 0 auto; font-size: 12.2px; color: var(--fg-2); }
.who-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.who-chip {
  height: 28px; padding: 0 12px;
  max-width: 140px;
  border: 1px solid var(--line-2);
  border-radius: 999px;
  background: rgb(var(--gray-255));
  color: var(--fg-2);
  font: inherit; font-size: 12.3px;
  cursor: pointer;
  transition: .15s ease;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.who-chip:hover { border-color: rgb(var(--gray-200)); color: var(--fg); }
.who-chip.active { border-color: var(--fg); background: rgb(var(--gray-245)); color: var(--fg); font-weight: 600; }

.draw-box {
  padding: 15px 15px 14px;
  background: rgb(var(--gray-255));
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow-sm);
}

.draw-box textarea {
  width: 100%;
  min-height: 96px;
  padding: 13px 14px;
  border: 1px solid var(--line-2);
  border-radius: 13px;
  background: rgb(var(--gray-250));
  font: inherit; font-size: 14.4px; line-height: 1.72;
  color: var(--fg);
  outline: 0;
  resize: none;
  transition: .16s ease;
}
.draw-box textarea:focus { border-color: rgb(var(--gray-200)); background: rgb(var(--gray-255)); box-shadow: 0 0 0 3px rgba(var(--gray-16), .045); }

.draw-ops { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 12px; }
.ops-left { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; min-width: 0; }

.ai-btn {
  height: 30px; padding: 0 12px;
  border: 1px solid var(--line-2);
  border-radius: 999px;
  background: rgb(var(--gray-255));
  color: var(--fg-2);
  font: inherit; font-size: 12.4px;
  cursor: pointer;
  transition: .15s ease;
  white-space: nowrap;
}
.ai-btn:hover:not(:disabled) { border-color: rgb(var(--gray-200)); color: var(--fg); background: rgb(var(--gray-250)); }
.ai-btn:disabled { opacity: .55; cursor: default; }

.idea-out:empty { display: none; }
.idea-head { margin: 13px 0 2px; font-size: 12.4px; font-weight: 500; color: var(--fg-2); letter-spacing: .2px; }
.idea-sug {
  display: flex; align-items: flex-start; gap: 9px;
  width: 100%;
  text-align: left;
  margin-top: 9px;
  padding: 11px 13px;
  border: 1px solid var(--line-2);
  border-radius: 12px;
  background: rgb(var(--gray-255));
  color: var(--fg);
  font: inherit; font-size: 13px; line-height: 1.68;
  cursor: pointer;
  transition: .15s ease;
  animation: pop .18s ease both;
}
.idea-sug:hover { border-color: rgb(var(--gray-200)); box-shadow: var(--shadow-sm); transform: translateY(-1px); }
.sug-idx {
  flex: 0 0 auto;
  width: 19px; height: 19px;
  margin-top: 2px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: rgb(var(--gray-236));
  color: var(--fg-2);
  font-size: 11px; font-weight: 600;
  transition: .15s ease;
}
.idea-sug:hover .sug-idx { background: var(--fg); color: rgb(var(--gray-255)); }
.sug-txt { flex: 1; min-width: 0; }
.idea-err { margin-top: 9px; font-size: 12.4px; color: rgb(var(--gray-80)); }
.draw-err { display: none; margin-top: 10px; padding: 9px 11px; border-radius: 10px; background: rgb(var(--gray-245)); border: 1px solid rgb(var(--gray-222)); color: rgb(var(--gray-80)); font-size: 12.6px; line-height: 1.6; }
.draw-err.show { display: block; }

/* 画廊 */
.gal-head { display: none; margin: 28px 0 11px; font-size: 12.4px; color: var(--fg-3); letter-spacing: .2px; }
.gal-head.show { display: block; }
.draw-gallery { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 26px; }
.gal-head.show + .draw-gallery { margin-top: 0; }
.gal-item {
  position: relative;
  aspect-ratio: 1;
  border-radius: 14px;
  overflow: hidden;
  background: rgb(var(--gray-245));
  border: 1px solid var(--line);
  cursor: zoom-in;
  animation: pop .22s ease both;
}
.gal-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gal-cap {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 18px 9px 8px;
  background: linear-gradient(transparent, rgba(var(--gray-0), .6));
  color: rgb(var(--gray-255)); font-size: 11px; line-height: 1.4;
  opacity: 0; transition: .16s ease;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.gal-item:hover .gal-cap { opacity: 1; }
.gal-empty { grid-column: 1 / -1; padding: 30px 0 6px; text-align: center; font-size: 12.8px; color: var(--fg-3); }
.gal-slot { display: grid; place-items: center; aspect-ratio: 1; border-radius: 14px; border: 1px dashed var(--line-2); background: rgb(var(--gray-250)); }
.sizes { display: flex; gap: 6px; }
.draw-modes { margin-bottom: 12px; }
.draw-source {
  display: flex; align-items: center; gap: 12px; margin-bottom: 12px;
  padding: 10px; border: 1px dashed rgb(var(--gray-222)); border-radius: 12px;
}
.draw-source img { width: 76px; height: 76px; object-fit: contain; border-radius: 8px; background: rgb(var(--gray-245)); }
.draw-source-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; min-width: 0; }
.draw-source-actions span { flex-basis: 100%; white-space: normal; }
#drawView [hidden], #promptSheet [hidden] { display: none; }
.role-memory-text { white-space: pre-wrap; overflow-wrap: anywhere; }

.registration-welcome {
  box-sizing: border-box; width: min(440px, calc(100% - 32px)); max-height: calc(100% - 32px);
  margin: auto; padding: clamp(20px, 6vw, 32px); border: 1px solid rgb(var(--gray-222));
  border-radius: 24px; background: rgb(var(--gray-255)); color: var(--fg);
}
.registration-welcome::backdrop { background: rgb(0 0 0 / .6); }
.registration-welcome-eyebrow { margin: 0 0 8px; font-size: 13px; }
.registration-welcome h2 { margin: 0 0 12px; font-size: 26px; }
.registration-welcome p { color: var(--fg-3); line-height: 1.65; }
.registration-welcome ul { display: grid; gap: 10px; padding: 0; margin: 20px 0; list-style: none; }
.registration-welcome li { display: grid; gap: 5px; padding: 12px; border-radius: 12px; background: rgb(var(--gray-245)); }
.registration-welcome li span { font-size: 13px; color: var(--fg-3); line-height: 1.55; }
.registration-welcome .save-btn { width: 100%; min-height: 44px; }

.size-chip {
  height: 30px; padding: 0 13px;
  border: 1px solid var(--line-2);
  border-radius: 999px;
  background: rgb(var(--gray-255));
  color: var(--fg-2);
  font: inherit; font-size: 12.4px;
  cursor: pointer;
  transition: .15s ease;
}
.size-chip:hover { border-color: rgb(var(--gray-200)); color: var(--fg); }
.size-chip.active { border-color: var(--fg); color: var(--fg); background: rgb(var(--gray-245)); font-weight: 500; }

.draw-go {
  flex: 0 0 auto; min-height: 48px; min-width: 108px; padding: 0 24px;
  border: 1px solid var(--fg);
  border-radius: 11px;
  background: var(--fg);
  color: rgb(var(--gray-255));
  font: inherit; font-size: 16px; font-weight: 650; white-space: nowrap;
  cursor: pointer;
  transition: .16s ease;
}
.draw-go:hover:not(:disabled) { opacity: .88; }
.draw-go:disabled { opacity: .55; cursor: default; }

@media (max-width: 780px) {
  .draw-ops { flex-direction: column; align-items: stretch; }
  .draw-go { min-height: 52px; }
}

/* 图片消息 */
.bubble.img-bubble {
  padding: 7px;
  line-height: 0;
  max-width: min(374px, 74%);
  background: rgb(var(--gray-255));
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.chat-img {
  display: block;
  width: 100%;
  max-width: 360px;
  height: auto;
  border-radius: 11px;
  cursor: zoom-in;
  background: rgb(var(--gray-245));
}
.img-cap {
  padding: 7px 8px 9px;
  font-size: 11.8px;
  line-height: 1.5;
  color: var(--fg-3);
}

/* 生成中的占位 */
.drawing { display: flex; align-items: center; gap: 11px; }
.shimmer {
  width: 150px; height: 150px;
  border-radius: 12px;
  background: linear-gradient(100deg, rgb(var(--gray-245)) 25%, rgb(var(--gray-236)) 45%, rgb(var(--gray-245)) 65%);
  background-size: 220% 100%;
  animation: sh 1.3s linear infinite;
}
@keyframes sh { 0% { background-position: 180% 0; } 100% { background-position: -40% 0; } }
.draw-note { font-size: 12.6px; color: var(--fg-3); line-height: 1.6; }

/* 大图预览 */
.lightbox {
  position: fixed; inset: 0;
  display: none;
  align-items: center; justify-content: center;
  padding: 30px;
  background: rgba(var(--gray-16), .86);
  z-index: 60;
  cursor: zoom-out;
}
.lightbox.show { display: flex; animation: pop .16s ease both; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 10px; box-shadow: 0 30px 80px rgba(var(--gray-0), .45); }

/* ================= 手机端 ================= */
.only-mobile { display: none; }
.side-mask {
  position: fixed; inset: 0;
  background: rgba(var(--gray-16), .22);
  opacity: 0; pointer-events: none;
  transition: opacity .2s;
  z-index: 15;
}

@media (max-width: 780px) {
  .only-mobile { display: grid; }

  .side {
    position: fixed;
    top: 0; bottom: 0; left: 0;
    width: 278px; flex-basis: 278px;
    transform: translateX(-102%);
    transition: transform .26s cubic-bezier(.22, .8, .3, 1);
    z-index: 16;
    box-shadow: var(--shadow-lg);
  }
  .side.show { transform: none; }
  .side.show + .main { pointer-events: none; }
  .side-mask.show { opacity: 1; pointer-events: auto; }

  .chat-head { padding: 9px 12px; gap: 8px; }
  .head-actions .pill { padding: 0 9px; font-size: 12px; }
  #historyBtn { display: none; }
  .messages { padding: 16px 12px 6px; }
  .row { margin-bottom: 16px; }
  .bubble { max-width: 82%; font-size: 14.4px; }
  .composer-wrap { padding: 6px 10px calc(12px + env(safe-area-inset-bottom)); }
  .head-actions .pill { height: 34px; }
  .hint { display: none; }
  .avatar, .mini-avatar { flex-basis: 30px; width: 30px; height: 30px; font-size: 11px; border-radius: 9px; }
  .sheet { width: 100%; border-left: 0; padding: 18px 16px 24px; }
  .sheet-foot { bottom: -24px; margin: 10px -16px -24px; padding: 12px 16px calc(16px + env(safe-area-inset-bottom)); }
  .pop { right: 8px; left: 8px; width: auto; }
  .draw-inner { padding: 22px 16px 60px; }
  .draw-gallery { grid-template-columns: repeat(2, 1fr); gap: 9px; margin-top: 20px; }
  .draw-head h2 { font-size: 17px; }
  .bubble.img-bubble { max-width: 84%; }
  .chat-img { max-width: 100%; }
}

/* ---------------- 首次进入：三选一 ---------------- */
.welcome { position: fixed; inset: 0; z-index: 95; background: rgb(var(--gray-255)); display: none; overflow-y: auto; }
.welcome.show { display: block; }
.welcome-inner { max-width: 1010px; margin: 0 auto; min-height: 100%; display: flex; flex-direction: column; justify-content: center; padding: 26px 24px 24px; }
.welcome-head { text-align: center; margin-bottom: 26px; flex: 0 0 auto; }
.welcome-head h1 { margin: 0 0 10px; font-size: 26px; font-weight: 650; letter-spacing: .6px; }
.welcome-head p { margin: 0; color: rgb(var(--gray-136)); font-size: 14px; }
.wskip {
  margin-top: 14px; padding: 7px 16px; border: 0; background: none;
  color: rgb(var(--gray-168)); font-size: 13px; cursor: pointer; border-radius: 8px;
  transition: color .15s ease, background .15s ease;
}
.wskip:hover { color: rgb(var(--gray-80)); background: rgb(var(--gray-245)); }
.welcome-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 22px; }
.wcard {
  display: flex; flex-direction: column; overflow: hidden;
  background: rgb(var(--gray-255)); border: 1px solid rgb(var(--gray-236)); border-radius: 18px;
  cursor: pointer; transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.wcard:hover { transform: translateY(-3px); border-color: rgb(var(--gray-200)); box-shadow: 0 14px 34px rgba(var(--gray-34), .08); }
.wcard-pic { height: clamp(140px, 29vh, 300px); background: rgb(var(--gray-245)); overflow: hidden; flex: 0 0 auto; }
.wcard-pic img { width: 100%; height: 100%; object-fit: cover; object-position: center 16%; display: block; }
.wcard-body { display: flex; flex-direction: column; flex: 1; padding: 15px 18px 17px; }
.wcard-name { font-size: 18px; font-weight: 650; letter-spacing: .4px; }
.wcard-tag { margin-top: 7px; color: rgb(var(--gray-136)); font-size: 12.5px; }
.wcard-desc { text-wrap: pretty; margin-top: 12px; flex: 1; color: rgb(var(--gray-80)); font-size: 13.5px; line-height: 1.7; }
.wcard-go {
  margin-top: 14px; height: 36px; display: flex; align-items: center; justify-content: center;
  border-radius: 10px; background: rgb(var(--gray-255)); color: rgb(var(--gray-56));
  border: 1px solid rgb(var(--gray-222));
  font-size: 13px; font-weight: 600; letter-spacing: .3px;
  transition: background .16s ease, color .16s ease, border-color .16s ease;
}
.wcard:hover .wcard-go { background: rgb(var(--gray-56)); color: rgb(var(--gray-255)); border-color: rgb(var(--gray-56)); }

@media (max-width: 820px) {
  .welcome-inner { padding: 40px 16px 44px; }
  .welcome-head { margin-bottom: 26px; }
  .welcome-head h1 { font-size: 22px; }
  .welcome-head p { font-size: 13px; }
  .welcome-grid { grid-template-columns: 1fr; gap: 14px; }
  .wcard { flex-direction: row; align-items: stretch; }
  .wcard-pic { flex: 0 0 118px; height: auto; min-height: 118px; }
  .wcard-body { padding: 14px 15px; }
  .wcard-name { font-size: 16px; }
  .wcard-desc { font-size: 12.5px; line-height: 1.65; margin-top: 9px; }
  .wcard-go { margin-top: 12px; height: 34px; font-size: 12.5px; }
}


/* ================= 酒馆能力：侧栏分栏 / 世界书 / 人设 ================= */
.side-tabs { display: flex; gap: 4px; padding: 2px 12px 8px; }
.side-tab {
  flex: 1; height: 32px; border: 1px solid transparent; border-radius: 9px;
  background: transparent; color: var(--fg-3);
  font: inherit; font-size: 12.8px; font-weight: 500; cursor: pointer;
  transition: .15s ease;
}
.side-tab:hover { color: var(--fg-2); background: rgb(var(--gray-255)); }
.side-tab.active { background: rgb(var(--gray-255)); color: var(--fg); border-color: var(--line); box-shadow: var(--shadow-sm); }

.side-pane { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; }
[hidden] { display: none !important; }
.card-settings-head { margin-bottom: 14px; }
.card-settings-head h3 { margin: 0 0 4px; font-size: 15px; }
.card-settings-head p { margin: 0; color: var(--fg-2); font-size: 13px; line-height: 1.5; }
#charSheet label.field > small { margin: 0 0 2px; line-height: 1.45; }
.side-pane[hidden] { display: none; }
.pane-acts { display: flex; gap: 6px; padding: 0 12px 8px; }
.pane-acts .new-char { margin: 0; flex: 1 1 auto; }
.new-char.ghost { border-style: solid; flex: 0 0 auto; padding: 0 12px; font-size: 12.4px; }

.foot-link {
  width: 100%; height: 36px; margin-bottom: 6px;
  display: flex; align-items: center; gap: 7px; padding: 0 10px;
  border: 0; border-radius: 10px; background: transparent;
  color: var(--fg-2); font: inherit; font-size: 12.8px; cursor: pointer;
  transition: .15s ease;
}
.foot-link:hover { background: rgb(var(--gray-255)); color: var(--fg); }
.foot-link svg { opacity: .8; flex: 0 0 auto; }

/* 世界书条目 */
.wi-list { display: flex; flex-direction: column; gap: 8px; }
.wi-item { border: 1px solid var(--line); border-radius: 11px; background: rgb(var(--gray-255)); overflow: hidden; }
.wi-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; cursor: pointer; user-select: none; }
.wi-head b { font-size: 13px; font-weight: 550; color: var(--fg); }
.wi-head small { color: var(--fg-3); font-size: 11px; margin-left: auto; white-space: nowrap; }
.wi-dot { width: 6px; height: 6px; border-radius: 50%; background: rgb(var(--gray-200)); flex: 0 0 auto; }
.wi-dot.on { background: var(--ok); }
.wi-body { display: none; padding: 12px 12px 4px; border-top: 1px solid var(--line); background: rgb(var(--gray-250)); }
.wi-item.open .wi-body { display: block; }
.wi-body .field { margin-bottom: 11px; }
.wi-body .row2 { gap: 10px; }
.wi-flag { display: flex; gap: 14px; flex-wrap: wrap; padding: 2px 0 6px; }
.wi-flag label { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--fg-2); cursor: pointer; }
.wi-flag input { accent-color: rgb(var(--gray-16)); }
.wi-del {
  margin-left: auto; width: 24px; height: 24px; border: 0; border-radius: 7px;
  background: transparent; color: rgb(var(--gray-200)); font-size: 15px; line-height: 1; cursor: pointer;
}
.wi-del:hover { background: rgb(var(--gray-245)); color: var(--bad); }
.wi-empty { padding: 22px 10px; text-align: center; font-size: 12.6px; color: var(--fg-3); }

/* 人设切换 */
.pers-list { display: flex; flex-wrap: wrap; gap: 6px; }
.pers-chip {
  height: 32px; padding: 0 12px; border: 1px solid var(--line-2); border-radius: 9px;
  background: rgb(var(--gray-255)); color: var(--fg-2); font: inherit; font-size: 12.5px; cursor: pointer;
  transition: .15s ease;
}
.pers-chip:hover { border-color: rgb(var(--gray-200)); color: var(--fg); }
.pers-chip.active { border-color: var(--fg); color: var(--fg); background: rgb(var(--gray-245)); font-weight: 600; }
.pers-chip.add { border-style: dashed; color: var(--fg-3); }

/* 角色卡 / 世界书在侧栏里的条目 */
.book-item { display: flex; align-items: center; gap: 10px; padding: 10px 10px; border-radius: 12px; cursor: pointer; border: 1px solid transparent; margin-bottom: 2px; }
.book-item:hover { background: rgb(var(--gray-255)); border-color: var(--line); }
.book-item.active { background: rgb(var(--gray-255)); border-color: var(--line-2); box-shadow: var(--shadow-sm); }
.book-ic {
  flex: 0 0 30px; width: 30px; height: 30px; border-radius: 9px;
  display: grid; place-items: center; background: rgb(var(--gray-245)); color: var(--fg-2);
  font-size: 13px;
}
.book-item b { display: block; font-size: 13px; font-weight: 550; color: var(--fg); }
.book-item small { display: block; font-size: 11.2px; color: var(--fg-3); }

.char-fav { margin-left: 4px; color: rgb(var(--gray-168)); font-size: 12px; }

.wb-pick { display: flex; flex-wrap: wrap; gap: 6px; }


/* ===== 提示词结构面板 ===== */
.foot-row { display: flex; gap: 6px; align-items: center; }
.foot-row .foot-link { flex: 1 1 auto; min-width: 0; }
.foot-link.narrow { flex: 0 0 auto; }
.ps-lead { font-size: 12.5px; color: rgb(var(--gray-136)); line-height: 1.75; margin: -6px 0 14px; }
.seg-list { display: flex; flex-direction: column; gap: 8px; }
.seg-row {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 12px; border: 1px solid rgb(var(--gray-236)); border-radius: 12px;
  background: rgb(var(--gray-255)); transition: background .15s, border-color .15s;
}
.seg-row.off { background: rgb(var(--gray-250)); border-color: rgb(var(--gray-236)); }
.seg-main { flex: 1 1 auto; min-width: 0; }
.seg-name { font-size: 13.5px; font-weight: 600; color: rgb(var(--gray-56)); line-height: 1.3; }
.seg-row.off .seg-name { color: rgb(var(--gray-168)); }
.seg-desc { font-size: 11.5px; color: rgb(var(--gray-168)); margin-top: 3px; line-height: 1.5; }
.seg-tok { font-size: 11px; color: rgb(var(--gray-200)); font-variant-numeric: tabular-nums; flex: 0 0 auto; }
.seg-move { display: flex; flex-direction: column; gap: 1px; flex: 0 0 auto; }
.seg-move button {
  width: 28px; height: 19px; border: 0; background: transparent; cursor: pointer;
  color: rgb(var(--gray-200)); font-size: 9px; line-height: 1; padding: 0; border-radius: 3px;
  display: grid; place-items: center;
}
.seg-move button:hover:not(:disabled) { background: rgb(var(--gray-236)); color: rgb(var(--gray-110)); }
.seg-move button:disabled { opacity: .3; cursor: default; }
.seg-sw {
  position: relative; width: 34px; height: 20px; padding: 0; border: 0; flex: 0 0 auto;
  border-radius: 999px; background: rgb(var(--gray-236)); transition: background .18s; cursor: pointer;
}
.seg-sw::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px;
  border-radius: 50%; background: rgb(var(--gray-255)); box-shadow: 0 1px 3px rgba(var(--gray-16), .18);
  transition: transform .18s;
}
.seg-sw.on { background: rgb(var(--gray-16)); }
.seg-sw.on::after { transform: translateX(14px); }
.pm-presets.fold { margin-top: 0; margin-bottom: 10px; }
.pm-preset-row { display: flex; gap: 6px; margin-bottom: 8px; }
.pm-preset-row input, .pm-preset-row select {
  flex: 1 1 0; min-width: 0; min-height: 36px; padding: 6px 8px;
  border: 1px solid rgb(var(--gray-222)); border-radius: 8px; background: rgb(var(--gray-250));
  color: var(--fg); font: inherit;
}
.pm-preset-row button { flex-shrink: 0; }
.pm-summary, .pm-hits { font-size: 12px; line-height: 1.55; color: var(--fg-3); margin: 0 0 8px; }
.pm-hits { padding-inline-start: 18px; overflow-wrap: anywhere; }
.pm-preview {
  margin: 0; padding: 12px; border-radius: 10px; background: rgb(var(--gray-250));
  border: 1px solid rgb(var(--gray-236)); font-size: 11.5px; line-height: 1.7; color: rgb(var(--gray-80));
  white-space: pre-wrap; word-break: break-word; max-height: 300px; overflow: auto;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
}
.fold { border-top: 1px solid rgb(var(--gray-245)); margin-top: 16px; padding-top: 4px; }
.fold summary {
  list-style: none; cursor: pointer; padding: 10px 0; font-size: 13px; color: rgb(var(--gray-110));
  font-weight: 500; display: flex; align-items: center; gap: 6px;
}
.fold summary::-webkit-details-marker { display: none; }
.fold summary::before { content: '›'; font-size: 15px; color: rgb(var(--gray-200)); transition: transform .18s; }
.fold[open] summary::before { transform: rotate(90deg); }
.fold-in { padding: 2px 0 6px; }
@media (max-width: 640px) {
  .seg-row { padding: 10px; gap: 8px; }
  .seg-desc { font-size: 11px; }
}



/* ===== 模型列表 ===== */
.model-row { display: flex; gap: 8px; align-items: center; }
.model-row input { flex: 1 1 auto; min-width: 0; }
.mini-btn {
  flex: 0 0 auto; height: 40px; padding: 0 13px; border: 1px solid rgb(var(--gray-236));
  background: rgb(var(--gray-255)); border-radius: 10px; font-size: 12.5px; color: rgb(var(--gray-56));
  cursor: pointer; white-space: nowrap; transition: background .15s;
}
.mini-btn:hover:not(:disabled) { background: rgb(var(--gray-245)); }
.mini-btn:disabled { opacity: .5; cursor: default; }


/* ===== 空间切换：虚拟恋人 / 酒馆 ===== */
.space-switch {
  display: flex; gap: 3px; margin: 12px 12px 6px; padding: 3px;
  background: rgb(var(--gray-245)); border-radius: 10px;
}
.space-btn {
  flex: 1 1 0; height: 32px; border: 0; background: transparent; border-radius: 8px;
  font-size: 12.5px; color: rgb(var(--gray-136)); cursor: pointer; font-weight: 500;
  transition: background .15s, color .15s; font-family: inherit;
}
.space-btn:hover:not(.active) { color: rgb(var(--gray-80)); }
.space-btn.active {
  background: rgb(var(--gray-255)); color: rgb(var(--gray-16)); font-weight: 600;
  box-shadow: 0 1px 3px rgba(var(--gray-16), .1);
}
.pane-acts { display: flex; gap: 6px; }
.pane-acts .new-char { flex: 1 1 0; min-width: 0; }
.pane-acts .new-char.ghost { flex: 0 0 auto; padding-left: 10px; padding-right: 10px; }
@media (max-width: 640px) {
  .space-switch { margin: 10px 10px 4px; }
  .space-btn { height: 34px; font-size: 13px; }
}

/* 底部两个入口并排：覆盖单独一排时的 width:100% */
.foot-row .foot-link { width: auto; margin-bottom: 0; padding: 0 9px; }
.foot-link span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.foot-row { margin-bottom: 8px; }

/* 画图入口缩成 brand 旁边的小动作，别和空间切换抢层级 */
.side-brand { flex: 1 1 auto; }
.draw-entry {
  flex: 0 0 auto !important; height: 30px !important; padding: 0 10px !important;
  font-size: 12.3px !important; border-radius: 9px !important; gap: 5px !important;
}


/* ================= 广场 ================= */
.square-view { display: none; flex: 1 1 auto; min-height: 0; overflow-y: auto; }
.square-view::-webkit-scrollbar { width: 10px; }
.square-view::-webkit-scrollbar-thumb { background: rgb(var(--gray-236)); border-radius: 8px; border: 3px solid rgb(var(--gray-255)); }
body.square-mode .square-view { display: block; }
body.square-mode .chat-head,
body.square-mode .messages,
body.square-mode .composer-wrap,
body.square-mode .pop,
body.square-mode .draw-view,
body.square-mode .side-foot { display: none !important; }

.sq-inner { max-width: 980px; margin: 0 auto; padding: 30px 24px 70px; }
.sq-head { margin-bottom: 22px; }
.sq-head h1 { margin: 0 0 6px; font-size: 24px; font-weight: 650; letter-spacing: .3px; }
.sq-head p { margin: 0; font-size: 13.4px; color: var(--fg-2); line-height: 1.7; }

.sq-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.sq-segs { display: inline-flex; gap: 2px; background: rgb(var(--gray-245)); border-radius: 10px; padding: 3px; }
.sq-seg {
  border: 0; background: transparent; color: var(--fg-2);
  font: inherit; font-size: 13px; font-weight: 500;
  padding: 6px 14px; border-radius: 8px; cursor: pointer; transition: .15s ease;
}
.sq-seg:hover { color: var(--fg); }
.sq-seg.active { background: rgb(var(--gray-255)); color: var(--fg); font-weight: 600; box-shadow: 0 1px 3px rgba(var(--gray-16), .08); }
.sq-segs.small .sq-seg { padding: 5px 12px; font-size: 12.6px; }
.sq-right { display: flex; align-items: center; gap: 8px; }
.sq-pub {
  border: 1px solid var(--fg); background: var(--fg); color: rgb(var(--gray-255));
  font: inherit; font-size: 13px; font-weight: 550;
  padding: 8px 16px; border-radius: 9px; cursor: pointer; transition: .16s ease;
}
.sq-pub:hover { background: rgb(var(--gray-0)); }

.sq-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(184px, 1fr)); gap: 16px; }
.sq-card {
  border: 1px solid var(--line); border-radius: 14px; background: rgb(var(--gray-255));
  overflow: hidden; cursor: pointer; transition: .18s ease;
  display: flex; flex-direction: column;
}
.sq-card:hover { border-color: rgb(var(--gray-222)); box-shadow: 0 4px 16px rgba(var(--gray-16), .07); transform: translateY(-1px); }
.sq-cover { position: relative; aspect-ratio: 4 / 5; background: rgb(var(--gray-245)); overflow: hidden; }
.sq-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.sq-cover .ph {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 34px; font-weight: 600; color: rgb(var(--gray-200)); letter-spacing: 2px;
}
.sq-badge {
  position: absolute; top: 9px; left: 9px;
  background: rgba(var(--gray-255), .94); color: var(--fg-2);
  font-size: 11px; font-weight: 550; padding: 3px 8px; border-radius: 6px;
  backdrop-filter: blur(4px);
}
.sq-body { padding: 11px 12px 12px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.sq-name { font-size: 13.6px; font-weight: 600; margin: 0; line-height: 1.4; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sq-sum {
  font-size: 12.2px; color: var(--fg-2); line-height: 1.55; margin: 0;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  min-height: 38px;
}
.sq-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: auto; }
.sq-author { display: flex; align-items: center; gap: 5px; min-width: 0; }
.sq-author img, .sq-author .av {
  width: 16px; height: 16px; border-radius: 50%; object-fit: cover; flex: 0 0 auto;
  background: rgb(var(--gray-236)); display: flex; align-items: center; justify-content: center;
  font-size: 9px; color: rgb(var(--gray-136));
}
.sq-author span { font-size: 11.4px; color: var(--fg-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sq-nums { display: flex; gap: 9px; font-size: 11.4px; color: var(--fg-3); flex: 0 0 auto; }
.sq-nums b { font-weight: 500; }

.sq-empty { padding: 60px 20px; text-align: center; font-size: 13.4px; color: var(--fg-3); line-height: 1.8; }
.sq-more { display: flex; justify-content: center; padding: 26px 0 0; }

/* 详情 */
.po-cover {
  width: 100%; aspect-ratio: 4 / 5; max-height: 400px;
  border-radius: 13px; overflow: hidden; background: rgb(var(--gray-245)); margin-bottom: 16px;
  position: relative;
}
.po-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.po-cover .ph { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 46px; color: rgb(var(--gray-200)); }
.po-desc { font-size: 13.4px; line-height: 1.75; color: var(--fg-2); margin: 0 0 16px; white-space: pre-wrap; }
.po-ops { display: flex; align-items: center; gap: 9px; margin-bottom: 20px; flex-wrap: wrap; }
.po-like {
  border: 1px solid var(--line-2); background: rgb(var(--gray-255)); color: var(--fg-2);
  font: inherit; font-size: 13px; padding: 9px 15px; border-radius: 9px;
  cursor: pointer; transition: .16s ease; display: inline-flex; align-items: center; gap: 5px;
}
.po-like:hover { border-color: rgb(var(--gray-200)); }
.po-like.on { border-color: rgb(var(--gray-200)); background: rgb(var(--gray-245)); color: rgb(var(--gray-110)); }
.po-import { width: auto; flex: 1; min-width: 130px; padding: 9px 16px; font-size: 13px; }
.po-sec { font-size: 12.4px; color: var(--fg-2); font-weight: 600; letter-spacing: .2px; margin: 0 0 11px; padding-top: 4px; border-top: 1px solid var(--line); padding-top: 16px; }
.po-cms { display: flex; flex-direction: column; gap: 13px; margin-bottom: 14px; }
.po-cm { display: flex; gap: 9px; }
.po-cm-av {
  width: 26px; height: 26px; border-radius: 50%; flex: 0 0 auto; object-fit: cover;
  background: rgb(var(--gray-236)); display: flex; align-items: center; justify-content: center;
  font-size: 11px; color: rgb(var(--gray-136));
}
.po-cm-main { min-width: 0; flex: 1; }
.po-cm-top { display: flex; align-items: baseline; gap: 7px; margin-bottom: 3px; }
.po-cm-top b { font-size: 12.4px; font-weight: 600; }
.po-cm-top span { font-size: 11px; color: var(--fg-3); }
.po-cm-main p { margin: 0; font-size: 13px; line-height: 1.65; color: var(--fg); word-break: break-word; }
.po-input-row { margin-top: 4px; }

/* 表单：验证码行 / 下拉框 */
.code-row { display: flex; gap: 8px; align-items: center; }
.code-row input { flex: 1; min-width: 0; }
.code-row .mini-btn { flex: 0 0 auto; height: 38px; padding: 0 12px; }
.field select {
  width: 100%; border: 1px solid var(--line-2); border-radius: var(--r-sm);
  background: rgb(var(--gray-250)); padding: 10px 12px; font: inherit; font-size: 13.6px;
  color: var(--fg); outline: 0; cursor: pointer; appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6'><path d='M1 1l4 4 4-4' stroke='%238a8f99' stroke-width='1.5' fill='none' stroke-linecap='round'/></svg>");
  background-repeat: no-repeat; background-position: right 12px center;
}
.field select:focus { border-color: rgb(var(--gray-200)); background-color: rgb(var(--gray-255)); }

/* 注册与登录入口 */
#authBoot { display: none; }
body.auth-pending #authBoot {
  position: fixed; inset: 0; z-index: 100; display: grid; align-content: center; justify-items: center;
  gap: 12px; padding: 24px; background: rgb(var(--gray-255)); color: var(--fg);
}
#authBoot strong { font-size: 28px; font-weight: 650; }
#authBoot p { margin: 0; color: var(--fg-2); font-size: 14px; text-align: center; }
#authRetry { min-height: 46px; padding: 10px 20px; border: 1px solid var(--line); border-radius: 12px; background: var(--fg); color: rgb(var(--gray-255)); font: inherit; cursor: pointer; }
body:is(.auth-pending, .auth-required) #app,
body:is(.auth-pending, .auth-required) .sheet:not(#authSheet),
body:is(.auth-pending, .auth-required) .sheet-mask:not(#authMask),
body:is(.auth-pending, .auth-required) :is(.h5-shade, .h5-toast) { display: none !important; }
body.auth-required { overflow: hidden; background: rgb(var(--gray-255)); }
body.auth-required #authMask { position: fixed; inset: 0; z-index: 90; display: block; visibility: visible; opacity: 1; background: rgb(var(--gray-255)); }
body.auth-required #authSheet {
  position: fixed; inset: var(--h5-top, 0px) 0 auto; z-index: 91;
  display: flex; flex-direction: column; width: 100%; height: var(--h5-height, 100dvh); max-height: none;
  margin: 0; padding: max(64px, env(safe-area-inset-top)) max(28px, env(safe-area-inset-left), env(safe-area-inset-right)) max(48px, env(safe-area-inset-bottom));
  border: 0; border-radius: 0; overflow: auto; overscroll-behavior: contain;
  transform: none; visibility: visible; background: rgb(var(--gray-255)); box-shadow: none; transition: none;
}
body.auth-required .auth-form-panel { flex: 0 0 auto; width: 100%; max-width: 400px; margin: auto; }
#authSheet .sheet-head { margin-bottom: 36px; align-items: flex-start; }
#authSheet .sheet-head h3 { margin: 0; color: var(--fg); font-size: 32px; font-weight: 650; letter-spacing: -.8px; line-height: 1.35; }
#authTitle:focus { outline: none; }
#authSheet .sheet-sub { margin: 12px 0 0; color: var(--fg-2); font-size: 14px; line-height: 1.7; }
#authSheet .field { margin-bottom: 24px; }
#authSheet .field > :is(span, label) { display: block; margin: 0 0 10px; color: var(--fg); font-size: 14px; line-height: 1.5; }
#authSheet .field > span small { display: inline; margin: 0 0 0 7px; color: var(--fg-3); font-size: 12px; }
#authSheet input {
  width: 100%; min-width: 0; min-height: 54px; padding: 14px 16px; border: 1px solid var(--line-2); border-radius: 12px;
  background: rgb(var(--gray-255)); color: var(--fg); font: inherit; font-size: 16px; line-height: 1.5;
}
#authSheet input::placeholder { color: var(--fg-3); opacity: 1; }
#authSheet input:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }
#authSheet :is(button, a):focus-visible { outline: 2px solid var(--fg); outline-offset: 3px; }
#authSheet .code-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; }
#authSheet #auSend {
  min-height: 54px; padding: 0 16px; border: 1px solid var(--line-2); border-radius: 12px;
  background: rgb(var(--gray-250)); color: var(--fg); font: inherit; font-size: 13px; white-space: nowrap; cursor: pointer;
}
.auth-password-row { position: relative; }
#authSheet .auth-password-row input { padding-right: 64px; }
#auPasswordToggle { position: absolute; top: 1px; right: 2px; bottom: 1px; width: 58px; padding: 0; border: 0; border-radius: 10px; background: transparent; color: var(--fg-2); font: inherit; font-size: 13px; cursor: pointer; }
#authSheet #authOut { min-height: 0; margin: 0; padding: 0; color: var(--fg-2); font-size: 13px; line-height: 1.7; overflow-wrap: anywhere; }
#authSheet #authOut:not(:empty) { margin: 0 0 18px; }
#authSheet #auGo {
  width: 100%; min-height: 56px; margin-top: 6px; border: 1px solid var(--fg); border-radius: 12px;
  background: var(--fg); color: rgb(var(--gray-255)); font: inherit; font-size: 16px; font-weight: 600; cursor: pointer;
}
#authSheet button:disabled { opacity: .5; cursor: default; }
#authSheet .auth-switch { margin: 22px 0 0; text-align: center; }
#authSheet #auToggle { min-height: 42px; padding: 6px 4px; color: var(--fg-2); font-size: 14px; }
.auth-free-note { margin: 32px 0 0; color: var(--fg-3); font-size: 12px; line-height: 1.8; text-align: center; }
.auth-free-note span { padding: 0 8px; }
@media (max-width: 640px) {
  body.auth-required .auth-form-panel { margin-block: 0 auto; }
}
@media (max-width: 360px) {
  body.auth-required #authSheet { padding-inline: max(24px, env(safe-area-inset-left), env(safe-area-inset-right)); }
  #authSheet #auSend { padding-inline: 12px; }
}
.auth-switch { margin: 2px 0 14px; }
.sheet.wide { width: min(520px, 100%); }

@media (max-width: 640px) {
  .sq-inner { padding: 18px 14px 60px; }
  .sq-head h1 { font-size: 20px; }
  .sq-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 11px; }
  .sq-body { padding: 9px 10px 10px; }
  .sq-name { font-size: 12.8px; }
  .sq-sum { font-size: 11.6px; -webkit-line-clamp: 2; min-height: 34px; }
  .sq-bar { gap: 8px; }
  .sq-pub { padding: 7px 13px; font-size: 12.4px; }
  .po-cover { max-height: 320px; }
  .draw-entry { height: 28px !important; padding: 0 8px !important; font-size: 11.8px !important; }
}

.who-btn {
  display: flex; align-items: center; gap: 8px; width: 100%;
  border: 0; background: transparent; padding: 8px 9px; margin-bottom: 6px;
  border-radius: 9px; font: inherit; font-size: 12.8px; color: var(--fg-2);
  cursor: pointer; transition: .15s ease; text-align: left;
}
.who-btn:hover { background: rgb(var(--gray-245)); color: var(--fg); }
.who-av {
  width: 22px; height: 22px; border-radius: 50%; flex: 0 0 auto;
  background: rgb(var(--gray-236)); color: rgb(var(--gray-136));
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600; overflow: hidden;
}
.who-av img { width: 100%; height: 100%; object-fit: cover; }
.who-av.guest { border: 1px dashed rgb(var(--gray-222)); background: rgb(var(--gray-255)); color: rgb(var(--gray-200)); }
.pf-av-row { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.pf-av {
  width: 62px; height: 62px; border-radius: 50%; flex: 0 0 auto;
  background: rgb(var(--gray-236)); color: rgb(var(--gray-136)); overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 600;
}
.pf-av img { width: 100%; height: 100%; object-fit: cover; }
.pf-hint { margin: 6px 0 0; font-size: 11.2px; color: var(--fg-3); }


/* 详情弹层：对齐与比例微调 */
.po-ops { align-items: stretch; }
.po-like { min-height: 38px; padding: 9px 18px; justify-content: center; }
.po-import { min-height: 38px; }
.po-cover { aspect-ratio: 3 / 4; max-height: 288px; }
.po-cm-av { width: 30px; height: 30px; font-size: 12px; }
.po-cm { gap: 10px; }
.po-cms { gap: 15px; margin-bottom: 18px; }
.po-sec { margin-bottom: 13px; }
.po-input-row { align-items: stretch; }
.po-input-row input { height: 40px; padding: 0 13px; }
.po-input-row .mini-btn { height: 40px !important; padding: 0 16px; }

.test-btn.danger.armed { background: rgb(var(--gray-110)) !important; border-color: rgb(var(--gray-110)) !important; color: rgb(var(--gray-255)) !important; }

/* 文件选择框：display:none 在部分环境会让 input.click() 失效，改成移出视口 */
.hidden-file {
  position: fixed !important;
  left: -9999px !important; top: 0 !important;
  width: 1px; height: 1px; opacity: 0;
  pointer-events: none;
  display: block !important;
}

/* 品牌行（月见 + 广场 + 画图）只在首页/聊天页出现；
   广场、画图是独立页面，各自有自己的标题，不再重复一行品牌 */
body.square-mode .side-head,
body.draw-mode .side-head { display: none !important; }

/* 这两个页面的返回按钮，桌面端也要有，否则进去出不来 */
#sqBack, #drawBack { display: inline-flex !important; }
