/* ===================================================================
   GPT 镜像 · 深色主题
   =================================================================== */
:root {
  --bg: #131315;
  --bg-elev: #1a1a1d;
  --sidebar: #0f0f11;
  --surface: #1f1f23;
  --surface-2: #26262b;
  --surface-3: #2f2f35;
  --border: #2c2c32;
  --border-soft: #23232a;
  --text: #ececee;
  --text-dim: #a8a8b2;
  --text-mute: #6e6e79;
  --accent: #19c37d;
  --accent-dim: #14a76a;
  --accent-soft: rgba(25, 195, 125, .12);
  --danger: #ff6b6b;
  --warn: #f0b429;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 18px 48px rgba(0, 0, 0, .45);
  --sidebar-w: 264px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
          "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --mono: "SFMono-Regular", "JetBrains Mono", Consolas, "Liberation Mono", Menlo, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
}

button { font-family: inherit; color: inherit; cursor: pointer; }
textarea, input, select { font-family: inherit; color: var(--text); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #3a3a42; border-radius: 8px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: #4a4a55; background-clip: content-box; }

.app { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }

/* =================== 侧边栏 =================== */
.sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  background: var(--sidebar);
  border-right: 1px solid var(--border-soft);
  display: flex; flex-direction: column;
  padding: 12px 10px;
  transition: width .22s cubic-bezier(.2,.7,.2,1), flex-basis .22s cubic-bezier(.2,.7,.2,1), opacity .18s;
  overflow: hidden;
}
.app.sb-collapsed .sidebar { width: 0; flex-basis: 0; padding: 12px 0; opacity: 0; }

.sb-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px 12px; }
.brand { display: flex; align-items: center; gap: 9px; min-width: 0; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 9px;
  display: grid; place-items: center; color: #06110c;
  background: linear-gradient(140deg, #2ee89a, #12a86b);
  flex: 0 0 auto;
}
.brand-text { font-weight: 650; font-size: 14.5px; letter-spacing: .2px; white-space: nowrap; }

.new-chat {
  display: flex; align-items: center; gap: 9px;
  width: 100%; padding: 10px 12px; margin-bottom: 14px;
  background: transparent; border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-size: 14px; font-weight: 550;
  transition: background .15s, border-color .15s;
  white-space: nowrap;
}
.new-chat:hover { background: var(--surface); border-color: #3a3a42; }

.sb-section-label {
  font-size: 11.5px; color: var(--text-mute); font-weight: 600;
  letter-spacing: .6px; text-transform: uppercase;
  padding: 0 10px 8px;
}

.conv-list { flex: 1; overflow-y: auto; overflow-x: hidden; display: flex; flex-direction: column; gap: 2px; padding-right: 2px; }
.conv-item {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 10px; border-radius: 9px;
  font-size: 13.6px; color: var(--text-dim);
  background: transparent; border: 0; text-align: left; width: 100%;
  transition: background .14s, color .14s;
}
.conv-item:hover { background: var(--surface); color: var(--text); }
.conv-item.active { background: var(--surface-2); color: var(--text); }
.conv-item .ct { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-item .ci-ico { flex: 0 0 auto; display: grid; place-items: center; width: 16px; height: 16px; color: var(--accent); opacity: .85; }
.conv-item.is-img .ct { color: var(--text-dim); }
.conv-item .kill {
  opacity: 0; flex: 0 0 auto; width: 20px; height: 20px; border-radius: 5px;
  display: grid; place-items: center; border: 0; background: transparent; color: var(--text-mute);
}
.conv-item:hover .kill { opacity: 1; }
.conv-item .kill:hover { background: #3a2a2a; color: var(--danger); }
.conv-empty { color: var(--text-mute); font-size: 13px; padding: 10px 12px; }

.sb-foot { border-top: 1px solid var(--border-soft); padding-top: 8px; margin-top: 8px; }
.sb-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 10px; border-radius: 9px; background: transparent; border: 0;
  font-size: 13.6px; color: var(--text-dim); margin-bottom: 4px;
}
.sb-item:hover { background: var(--surface); color: var(--text); }
.account { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 9px; }
.avatar {
  width: 28px; height: 28px; border-radius: 50%; flex: 0 0 auto;
  background: linear-gradient(140deg, #4a4a58, #2a2a33);
  display: grid; place-items: center; font-size: 12.5px; font-weight: 650; color: #d8d8e0;
}
.account-meta { min-width: 0; }
.account-name { font-size: 13px; font-weight: 550; }
.account-sub { font-size: 11.5px; color: var(--text-mute); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sb-backdrop { display: none; }

/* =================== 主区域 =================== */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }

.topbar {
  height: 56px; flex: 0 0 56px;
  display: flex; align-items: center; gap: 10px;
  padding: 0 14px;
  border-bottom: 1px solid var(--border-soft);
  background: rgba(19, 19, 21, .78);
  backdrop-filter: blur(12px);
  z-index: 20;
}
.grow { flex: 1; }
.only-mobile { display: none !important; }

.icon-btn {
  width: 34px; height: 34px; flex: 0 0 auto;
  display: grid; place-items: center;
  border-radius: 9px; border: 0; background: transparent; color: var(--text-dim);
  transition: background .14s, color .14s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.model-picker { position: relative; }
.model-btn {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 11px; border-radius: 10px;
  background: transparent; border: 1px solid transparent;
  font-size: 15px; font-weight: 600; letter-spacing: .1px;
  transition: background .14s;
  max-width: 46vw;
}
.model-btn:hover { background: var(--surface); }
.model-btn .dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  flex: 0 0 auto;
}
#modelLabel { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.menu {
  position: absolute; top: calc(100% + 8px); left: 0;
  min-width: 268px; max-height: 60vh; overflow-y: auto;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 12px; padding: 6px; box-shadow: var(--shadow); z-index: 60;
}
.menu-item {
  display: flex; flex-direction: column; gap: 2px; width: 100%;
  padding: 9px 10px; border-radius: 8px; border: 0; background: transparent;
  text-align: left; color: var(--text-dim); font-size: 13.8px;
}
.menu-item:hover { background: var(--surface-2); color: var(--text); }
.menu-item.active { background: var(--accent-soft); color: var(--text); }
.menu-item small { font-size: 11.5px; color: var(--text-mute); }
.menu-label { font-size: 11px; color: var(--text-mute); padding: 8px 10px 4px; text-transform: uppercase; letter-spacing: .5px; }
.menu-label small { text-transform: none; letter-spacing: 0; margin-left: 6px; opacity: .8; }
.menu-label:not(:first-child) { border-top: 1px solid var(--border-soft); margin-top: 4px; }

.seg {
  display: flex; gap: 2px; padding: 3px;
  background: var(--surface); border-radius: 11px; border: 1px solid var(--border-soft);
}
.seg-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 8px; border: 0; background: transparent;
  font-size: 13px; font-weight: 550; color: var(--text-mute);
  transition: background .15s, color .15s;
}
.seg-btn:hover { color: var(--text); }
.seg-btn.active { background: var(--surface-3); color: var(--text); }

/* =================== 通用视图滚动 =================== */
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.scroll { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; scroll-behavior: smooth; }
.scroll::-webkit-scrollbar { width: 12px; }

/* =================== 欢迎页 =================== */
.hero {
  max-width: 780px; margin: 0 auto;
  padding: clamp(28px, 8vh, 96px) 20px 28px;
  display: flex; flex-direction: column; align-items: center;
  animation: fadeUp .5s cubic-bezier(.2,.7,.2,1);
}
.hero::before {
  content: ""; position: absolute; top: 56px; left: 50%; transform: translateX(-50%);
  width: min(760px, 92vw); height: 320px;
  background: radial-gradient(ellipse at 50% 0%, rgba(25,195,125,.10), transparent 70%);
  pointer-events: none;
}
.hero-title {
  font-size: clamp(24px, 3.4vw, 34px); font-weight: 600;
  letter-spacing: -.4px; margin: 0 0 34px; text-align: center;
}
.hero-grid {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px; width: 100%;
}
.hero-card {
  display: flex; flex-direction: column; gap: 5px;
  padding: 14px 16px; text-align: left;
  background: var(--bg-elev); border: 1px solid var(--border-soft);
  border-radius: 13px; transition: background .16s, border-color .16s, transform .16s;
}
.hero-card:hover { background: var(--surface); border-color: var(--border); transform: translateY(-1px); }
.hero-card strong { font-size: 14px; font-weight: 600; }
.hero-card span:last-child { font-size: 12.8px; color: var(--text-mute); line-height: 1.5; }
.hc-ico { color: var(--accent); font-size: 13px; }

/* =================== 消息线程 =================== */
.thread {
  max-width: 780px; margin: 0 auto;
  padding: 24px 20px 40px;
  display: flex; flex-direction: column; gap: 26px;
}

.msg { display: flex; flex-direction: column; animation: fadeUp .3s cubic-bezier(.2,.7,.2,1); }
.msg-user { align-items: flex-end; }
.msg-user .bubble {
  max-width: 86%; padding: 11px 16px;
  background: var(--surface-2); border-radius: 18px 18px 5px 18px;
  font-size: 15px; line-height: 1.65; white-space: pre-wrap; word-break: break-word;
}
.msg-user .msg-imgs { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; margin-bottom: 8px; }
.msg-user .msg-imgs img { width: 132px; height: 132px; object-fit: cover; border-radius: 12px; border: 1px solid var(--border); }

.msg-ai { align-items: flex-start; }
.ai-head { display: flex; align-items: center; gap: 9px; margin-bottom: 9px; }
.ai-avatar {
  width: 26px; height: 26px; border-radius: 50%; flex: 0 0 auto;
  background: linear-gradient(140deg, #2ee89a, #12996a);
  display: grid; place-items: center; color: #05120c;
}
.ai-name { font-size: 13px; font-weight: 600; color: var(--text-dim); }
.ai-body { width: 100%; font-size: 15.2px; line-height: 1.78; word-break: break-word; }

.ai-actions { display: flex; gap: 4px; margin-top: 10px; opacity: 0; transition: opacity .18s; }
.msg-ai:hover .ai-actions, .msg-ai.static .ai-actions { opacity: 1; }
.mini-btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 5px 9px; border-radius: 7px; border: 0; background: transparent;
  font-size: 12.3px; color: var(--text-mute); white-space: nowrap;
}
.mini-btn:hover { background: var(--surface-2); color: var(--text); }

.cursor::after {
  content: ""; display: inline-block; width: 7px; height: 15px;
  background: var(--accent); margin-left: 2px; vertical-align: -2px;
  animation: blink 1s steps(2, start) infinite; border-radius: 1px;
}
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

.usage-line { margin-top: 8px; font-size: 11.5px; color: var(--text-mute); font-family: var(--mono); }

/* 绘图历史消息 */
.msg-ai .img-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; }
.msg-ai .img-grid.one { grid-template-columns: minmax(0, 420px); }
.msg-ai .img-cell {
  margin: 0; overflow: hidden; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface);
}
.msg-ai .img-cell img { width: 100%; height: 100%; object-fit: cover; display: block; cursor: zoom-in; }
.msg-ai .img-cell img:hover { opacity: .92; }
.img-turn-meta { margin-top: 8px; font-size: 11.5px; color: var(--text-mute); font-family: var(--mono); }
.img-missing { padding: 12px 14px; border: 1px dashed var(--border); border-radius: 12px; font-size: 13px; color: var(--text-mute); }

/* 绘图页：当前记入哪条历史 */
.img-session { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 12.5px; color: var(--text-mute); }
.img-session .is-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); flex: 0 0 auto; }
.img-session strong { color: var(--text-dim); font-weight: 550; }
.link-btn { border: 0; background: transparent; color: var(--accent); font-size: 12.5px; padding: 2px 4px; border-radius: 6px; }
.link-btn:hover { background: var(--accent-soft); }

/* 错误卡片 */
.err-card {
  display: flex; gap: 11px; padding: 12px 14px;
  background: rgba(255,107,107,.07); border: 1px solid rgba(255,107,107,.28);
  border-radius: 12px; font-size: 13.4px; color: #ffc9c9;
}
.err-card svg { flex: 0 0 auto; color: var(--danger); margin-top: 2px; }
.err-card strong { display: block; margin-bottom: 3px; color: #ffb3b3; font-size: 13px; }
.err-card .err-detail { color: #c99fa2; font-size: 12.2px; margin-top: 5px; word-break: break-all; font-family: var(--mono); }

/* Typing 三点 */
.typing { display: inline-flex; gap: 4px; align-items: center; height: 22px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--text-mute); animation: bounce 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .45; } 30% { transform: translateY(-4px); opacity: 1; } }

/* 思考过程折叠块 */
.think {
  margin: 0 0 14px; border: 1px solid var(--border-soft);
  border-radius: 12px; background: rgba(255, 255, 255, .022); overflow: hidden;
}
.think > summary {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 12px; font-size: 12.6px; color: var(--text-dim);
  cursor: pointer; user-select: none; list-style: none;
}
.think > summary::-webkit-details-marker { display: none; }
.think > summary::after {
  content: ""; margin-left: auto; width: 7px; height: 7px;
  border-right: 1.5px solid var(--text-mute); border-bottom: 1.5px solid var(--text-mute);
  transform: rotate(45deg) translateY(-2px); transition: transform .2s;
}
.think[open] > summary::after { transform: rotate(225deg) translateY(-2px); }
.think > summary em { font-style: normal; color: var(--text-mute); font-size: 11.6px; }
.think-dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft); flex: 0 0 auto;
}
.think-body {
  padding: 10px 14px 12px; border-top: 1px solid var(--border-soft);
  font-size: 13.2px; line-height: 1.72; color: var(--text-dim);
  white-space: pre-wrap; word-break: break-word;
  max-height: 300px; overflow-y: auto;
}

/* 数学公式 */
.math {
  font-family: "Cambria Math", "Latin Modern Math", Georgia, "Times New Roman", serif;
  font-size: 1.04em; letter-spacing: .1px;
}
.math-block { display: block; text-align: center; margin: 14px 0; overflow-x: auto; }
.md p > .math-block { margin: 10px 0; }
.math .frac {
  display: inline-flex; flex-direction: column; vertical-align: -.55em;
  text-align: center; margin: 0 .18em; font-size: .96em;
}
.math .frac > .num { border-bottom: 1px solid currentColor; padding: 0 .26em; }
.math .frac > .den { padding: 0 .26em; }
.math sup, .math sub { font-size: .72em; line-height: 0; }
.math .mtext { font-family: var(--font); font-size: .95em; }
.math .sqrt > .rad { border-top: 1px solid currentColor; padding: 0 .14em; margin-left: -.04em; }
.math .bar { text-decoration: overline; }

/* =================== Markdown =================== */
.ai-body > *:first-child, .md > *:first-child { margin-top: 0; }
.ai-body > *:last-child, .md > *:last-child { margin-bottom: 0; }
.md p { margin: 0 0 14px; }
.md h1, .md h2, .md h3, .md h4 { margin: 22px 0 10px; line-height: 1.35; font-weight: 650; letter-spacing: -.2px; }
.md h1 { font-size: 22px; }
.md h2 { font-size: 19px; }
.md h3 { font-size: 16.6px; }
.md h4 { font-size: 15.2px; }
.md ul, .md ol { margin: 0 0 14px; padding-left: 24px; }
.md li { margin: 5px 0; }
.md li > p { margin: 0; }
.md blockquote {
  margin: 0 0 14px; padding: 4px 0 4px 14px;
  border-left: 2.5px solid var(--accent); color: var(--text-dim);
}
.md hr { border: 0; border-top: 1px solid var(--border); margin: 20px 0; }
.md a { color: #6fd6a8; text-decoration: none; border-bottom: 1px solid rgba(111,214,168,.35); }
.md a:hover { border-bottom-color: #6fd6a8; }
.md strong { font-weight: 650; color: #fff; }
.md code.inline {
  font-family: var(--mono); font-size: 13px;
  background: var(--surface-2); border: 1px solid var(--border-soft);
  padding: 1.5px 5px; border-radius: 5px;
}
.md table { width: 100%; border-collapse: collapse; margin: 0 0 16px; font-size: 13.8px; }
.md th, .md td { border: 1px solid var(--border); padding: 8px 11px; text-align: left; }
.md th { background: var(--surface); font-weight: 600; }
.md tbody tr:nth-child(even) { background: rgba(255,255,255,.018); }

.code-block {
  margin: 0 0 16px; border-radius: 12px; overflow: hidden;
  border: 1px solid var(--border); background: #17171a;
}
.code-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 12px; background: #1d1d21; border-bottom: 1px solid var(--border-soft);
  font-size: 11.8px; color: var(--text-mute); font-family: var(--mono);
}
.code-head button {
  border: 0; background: transparent; color: var(--text-dim);
  font-size: 11.8px; display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 6px; border-radius: 5px; font-family: var(--font);
}
.code-head button:hover { background: var(--surface-3); color: var(--text); }
.code-block pre { margin: 0; padding: 13px 14px; overflow-x: auto; }
.code-block pre code { font-family: var(--mono); font-size: 13px; line-height: 1.65; color: #d5d5dd; white-space: pre; }
.tok-key { color: #c792ea; }
.tok-str { color: #a5e08a; }
.tok-num { color: #f0b46b; }
.tok-com { color: #6b6b78; font-style: italic; }
.tok-fn { color: #82ccf5; }

/* =================== 输入区 =================== */
.composer-wrap { padding: 8px 20px 18px; background: linear-gradient(to top, var(--bg) 62%, transparent); }
.composer {
  max-width: 780px; margin: 0 auto;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 22px; padding: 10px 12px 8px;
  box-shadow: 0 6px 24px rgba(0,0,0,.28);
  transition: border-color .18s, box-shadow .18s;
}
.composer:focus-within { border-color: #3f3f48; box-shadow: 0 8px 30px rgba(0,0,0,.36); }
.composer textarea {
  width: 100%; border: 0; background: transparent; resize: none;
  font-size: 15.2px; line-height: 1.6; padding: 6px 6px 2px;
  max-height: 210px; outline: none; overflow-y: auto;
}
.composer textarea::placeholder { color: var(--text-mute); }
.composer-bar { display: flex; align-items: center; gap: 3px; padding-top: 2px; }
.pill-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: 8px; border: 1px solid var(--border-soft);
  background: transparent; font-size: 12.5px; color: var(--text-dim);
}
.pill-btn:hover { background: var(--surface-2); color: var(--text); }

.send-btn, .stop-btn {
  width: 32px; height: 32px; border-radius: 50%; border: 0;
  display: grid; place-items: center; transition: transform .12s, background .15s, opacity .15s;
}
.send-btn { background: var(--accent); color: #05130d; }
.send-btn:hover:not(:disabled) { background: #21d78a; }
.send-btn:disabled { background: var(--surface-3); color: var(--text-mute); cursor: not-allowed; }
.stop-btn { background: var(--text); color: var(--bg); }

.composer-hint {
  max-width: 780px; margin: 9px auto 0; text-align: center;
  font-size: 11.4px; color: var(--text-mute);
  padding: 0 8px; line-height: 1.55;
}

/* 附件预览 */
.attach-row { display: flex; gap: 8px; flex-wrap: wrap; padding: 4px 4px 8px; }
.attach-thumb { position: relative; width: 62px; height: 62px; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); }
.attach-thumb img { width: 100%; height: 100%; object-fit: cover; }
.attach-thumb button {
  position: absolute; top: 2px; right: 2px; width: 18px; height: 18px;
  border-radius: 50%; border: 0; background: rgba(0,0,0,.68); color: #fff;
  display: grid; place-items: center; font-size: 11px; line-height: 1;
}

/* =================== 绘图视图 =================== */
.pane { max-width: 860px; margin: 0 auto; padding: 30px 20px 60px; }
.pane-head h2 { font-size: 21px; font-weight: 620; margin: 0 0 6px; letter-spacing: -.2px; }
.pane-head p { margin: 0 0 22px; font-size: 13px; color: var(--text-mute); }
.pane-head code, .kv code, .field-hint code {
  font-family: var(--mono); font-size: 12px;
  background: var(--surface-2); padding: 1.5px 5px; border-radius: 5px; color: #c8c8d2;
}

.img-form {
  background: var(--bg-elev); border: 1px solid var(--border-soft);
  border-radius: 16px; padding: 14px;
}
.img-form textarea {
  width: 100%; border: 0; background: transparent; resize: vertical;
  font-size: 14.8px; line-height: 1.65; outline: none; min-height: 76px;
  padding: 4px 2px;
}
.img-form textarea::placeholder { color: var(--text-mute); }
.img-form-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding-top: 10px; border-top: 1px solid var(--border-soft); }

/* ---------- 参考图 ---------- */
.ref-strip { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; padding-bottom: 11px; margin-bottom: 4px; border-bottom: 1px solid var(--border-soft); }
.ref-strip.has .ref-tip { display: none; }
.ref-thumbs { display: flex; gap: 8px; flex-wrap: wrap; }
.ref-thumb { position: relative; width: 54px; height: 54px; border-radius: 9px; overflow: hidden; border: 1px solid var(--border); background: var(--surface-2); }
.ref-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ref-thumb .idx {
  position: absolute; left: 3px; bottom: 3px; font-size: 9.5px; line-height: 1;
  padding: 3px 4px; border-radius: 4px; background: rgba(0,0,0,.62); color: #fff;
}
.ref-del {
  position: absolute; right: 2px; top: 2px; width: 17px; height: 17px; border-radius: 50%;
  border: 0; background: rgba(0,0,0,.66); color: #fff; font-size: 12px; line-height: 1;
  display: grid; place-items: center; cursor: pointer; padding: 0;
}
.ref-del:hover { background: rgba(220,60,60,.9); }
.ref-add {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 11px;
  border-radius: 9px; border: 1px dashed var(--border); background: transparent;
  color: var(--text-dim); font-size: 12.6px; font-family: var(--font); cursor: pointer;
}
.ref-add:hover { border-color: var(--accent); color: var(--text); }
.ref-tip { font-size: 11.6px; color: var(--text-mute); }
.img-form.drag { border-color: var(--accent); background: var(--surface-2); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  padding: 6px 11px; border-radius: 8px; font-size: 12.5px;
  background: transparent; border: 1px solid var(--border); color: var(--text-dim);
}
.chip:hover { background: var(--surface); color: var(--text); }
.chip.active { background: var(--accent-soft); border-color: rgba(25,195,125,.45); color: #7fe8b8; }

.primary-btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 16px; border-radius: 10px; border: 0;
  background: linear-gradient(140deg, #2ee89a, #12a86b);
  color: #04140e; font-size: 13.6px; font-weight: 650;
  transition: transform .12s, filter .15s;
}
.primary-btn:hover { filter: brightness(1.06); transform: translateY(-1px); }
.primary-btn:disabled { filter: grayscale(.5) brightness(.8); cursor: not-allowed; transform: none; }
.ghost-btn {
  padding: 9px 14px; border-radius: 10px; font-size: 13.4px;
  background: transparent; border: 1px solid var(--border); color: var(--text-dim);
}
.ghost-btn:hover { background: var(--surface); color: var(--text); }

.img-status {
  display: flex; align-items: center; gap: 13px;
  margin-top: 16px; padding: 14px 16px;
  background: var(--surface); border: 1px solid var(--border-soft); border-radius: 13px;
}
.img-status strong { display: block; font-size: 13.6px; margin-bottom: 3px; }
.img-status span { font-size: 12.3px; color: var(--text-mute); }
.spinner {
  width: 20px; height: 20px; flex: 0 0 auto; border-radius: 50%;
  border: 2px solid rgba(25,195,125,.22); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; margin-top: 22px; align-items: start; }
.gen-card {
  background: var(--bg-elev); border: 1px solid var(--border-soft);
  border-radius: 14px; overflow: hidden; display: flex; flex-direction: column;
  animation: fadeUp .4s cubic-bezier(.2,.7,.2,1);
}
.gen-card .thumb { position: relative; background: var(--surface); aspect-ratio: 1 / 1; overflow: hidden; }
.gen-card .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; cursor: zoom-in; transition: transform .35s; }
.gen-card:hover .thumb img { transform: scale(1.03); }
.gen-card .cap { padding: 10px 12px; font-size: 12.5px; color: var(--text-dim); line-height: 1.55; flex: 1; }
.gen-card .ops { display: flex; gap: 4px; padding: 0 8px 9px; flex-wrap: wrap; }
.gen-meta { font-size: 11px; color: var(--text-mute); font-family: var(--mono); padding: 0 12px 9px; }

.gallery-empty { text-align: center; color: var(--text-mute); padding: 46px 10px; font-size: 13px; }
.ge-art { color: var(--text-mute); opacity: .6; margin-bottom: 10px; }

/* 图片查看器 */
.lightbox {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(6,6,8,.88); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center; padding: 32px;
  animation: fade .2s;
}
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 12px; box-shadow: var(--shadow); }

/* =================== 弹层 =================== */
.modal { position: fixed; inset: 0; z-index: 150; background: rgba(5,5,7,.68); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; padding: 24px; animation: fade .16s; }
.modal-card {
  width: 100%; max-width: 520px; max-height: 86vh; display: flex; flex-direction: column;
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow);
  animation: pop .2s cubic-bezier(.2,.7,.2,1);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--border-soft); }
.modal-head h3 { margin: 0; font-size: 16px; font-weight: 620; }
.modal-body { padding: 16px 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 15px; }
.modal-foot { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-top: 1px solid var(--border-soft); }
.field label { display: block; font-size: 12.6px; color: var(--text-dim); margin-bottom: 7px; font-weight: 550; }
.field textarea, .field select {
  width: 100%; padding: 9px 11px; font-size: 13.6px; outline: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: 9px;
  resize: vertical;
}
.field textarea:focus, .field select:focus { border-color: #45454f; }
.field-hint { font-size: 11.8px; color: var(--text-mute); margin: 7px 0 0; line-height: 1.55; }
.kv { display: flex; flex-direction: column; gap: 7px; padding: 11px 13px; background: var(--surface); border-radius: 10px; border: 1px solid var(--border-soft); }
.kv > div { display: flex; align-items: center; justify-content: space-between; font-size: 12.4px; color: var(--text-mute); }

/* =================== Toast =================== */
.toast-wrap { position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%); z-index: 300; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  padding: 10px 16px; border-radius: 11px; font-size: 13.2px;
  background: var(--surface-3); border: 1px solid var(--border); color: var(--text);
  box-shadow: var(--shadow); animation: toastIn .24s cubic-bezier(.2,.7,.2,1);
  max-width: min(520px, 88vw);
}
.toast.err { background: #3a1f22; border-color: rgba(255,107,107,.4); color: #ffc9c9; }

@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: scale(.97) translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* =================== 响应式 =================== */
@media (max-width: 860px) {
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 120;
    transform: translateX(-100%); transition: transform .24s cubic-bezier(.2,.7,.2,1);
    box-shadow: 12px 0 40px rgba(0,0,0,.5); width: 272px; flex-basis: 272px;
  }
  .app.sb-open .sidebar { transform: none; opacity: 1; }
  .app.sb-collapsed .sidebar { width: 272px; flex-basis: 272px; opacity: 1; }
  .app.sb-open .sb-backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 110; }
  .only-mobile { display: grid !important; }
  #collapseBtn { display: none; }
  .hero-grid { grid-template-columns: 1fr; }
  .thread { padding: 18px 14px 30px; gap: 22px; }
  .composer-wrap { padding: 6px 12px 14px; }
  .msg-user .bubble { max-width: 92%; }
  .seg-btn span { display: none; }
  .seg-btn { padding: 6px 10px; }
  .gallery { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
  .pane { padding: 20px 14px 40px; }
}

@media (max-width: 560px) {
  /* 窄屏单列：双列时卡片过窄，操作按钮会被逐字折断 */
  .gallery { grid-template-columns: 1fr; gap: 14px; }
  .gen-card .cap { font-size: 12.8px; }
  .ref-thumb { width: 48px; height: 48px; }
  .ref-tip { display: none; }
}

/* =================== 登录 / 注册 =================== */
.auth {
  position: fixed; inset: 0; z-index: 400;
  display: flex; align-items: center; justify-content: center;
  padding: 24px 18px;
  overflow-y: auto;
  background:
    radial-gradient(880px 480px at 50% -12%, rgba(25, 195, 125, .10), transparent 62%),
    radial-gradient(700px 420px at 84% 104%, rgba(80, 96, 210, .09), transparent 62%),
    var(--bg);
}
.auth-card {
  width: 100%; max-width: 392px; margin: auto;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 18px; padding: 26px 26px 18px;
  box-shadow: var(--shadow);
  animation: pop .24s cubic-bezier(.2, .7, .2, 1);
}
.auth-brand { display: flex; align-items: center; gap: 11px; margin-bottom: 20px; }
.auth-brand h1 { margin: 0; font-size: 17px; font-weight: 650; letter-spacing: .2px; }
.auth-brand p { margin: 3px 0 0; font-size: 12.4px; color: var(--text-mute); }

.auth-tabs { display: flex; gap: 4px; background: var(--surface); padding: 4px; border-radius: 10px; margin-bottom: 18px; }
.auth-tab {
  flex: 1; border: 0; background: transparent; padding: 8px 0; border-radius: 7px;
  font-size: 13.4px; font-weight: 550; color: var(--text-dim); transition: background .16s, color .16s;
}
.auth-tab.active { background: var(--surface-3); color: var(--text); }

.auth-form { display: flex; flex-direction: column; gap: 13px; }
.af-field { display: flex; flex-direction: column; gap: 7px; }
.af-field > span { font-size: 12.4px; font-weight: 550; color: var(--text-dim); }
.af-field input {
  width: 100%; padding: 10px 12px; font-size: 14px; outline: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: 9px;
  transition: border-color .15s, box-shadow .15s;
}
.af-field input::placeholder { color: var(--text-mute); }
.af-field input:focus { border-color: #3c6b58; box-shadow: 0 0 0 3px rgba(25, 195, 125, .10); }

/* ---- 拼图验证码 ---- */
.captcha { width: 300px; max-width: 100%; margin: 3px auto 0; user-select: none; }
.cap-stage-wrap {
  position: relative; width: 100%; overflow: hidden;
  border: 1px solid var(--border); border-bottom: 0;
  border-radius: 10px 10px 0 0; background: #0d0d0f;
}
.cap-stage { position: relative; width: 300px; height: 150px; transform-origin: top left; }
.cap-stage img { position: absolute; display: block; -webkit-user-drag: none; user-select: none; }
#capBg { top: 0; left: 0; width: 300px; height: 150px; }
#capPiece { top: 0; left: 0; filter: drop-shadow(0 2px 6px rgba(0, 0, 0, .6)); will-change: transform; }
.cap-refresh {
  position: absolute; top: 6px; right: 6px; width: 26px; height: 26px; z-index: 3;
  display: grid; place-items: center; border: 0; border-radius: 7px;
  background: rgba(10, 10, 12, .55); color: #e8e8ee; backdrop-filter: blur(3px);
}
.cap-refresh:hover { background: rgba(20, 20, 24, .8); }
.cap-mask { position: absolute; inset: 0; z-index: 4; display: grid; place-items: center; background: rgba(10, 10, 12, .55); }
.cap-mask .spinner { width: 18px; height: 18px; }

.cap-ctrl {
  position: relative; width: 100%; height: 44px;
  border: 1px solid var(--border); border-radius: 0 0 10px 10px;
  background: var(--surface); overflow: hidden;
}
.cap-track { position: absolute; inset: 0; }
.cap-fill { position: absolute; top: 0; left: 0; height: 100%; width: 0; background: rgba(25, 195, 125, .16); border-right: 1px solid rgba(25, 195, 125, .45); }
.cap-label { position: absolute; inset: 0; display: grid; place-items: center; font-size: 12.6px; color: var(--text-mute); pointer-events: none; }
.cap-knob {
  position: absolute; top: 3px; left: 3px; z-index: 2;
  width: 38px; height: 36px; border-radius: 8px;
  border: 1px solid #3d3d46; background: linear-gradient(180deg, #35353d, #27272e);
  color: var(--text); display: grid; place-items: center;
  cursor: grab; touch-action: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .38);
  transition: background .15s, border-color .15s;
}
.cap-knob:hover { background: linear-gradient(180deg, #3c3c46, #2b2b33); }
.cap-knob:active { cursor: grabbing; }

.captcha.ok .cap-knob { background: linear-gradient(180deg, #1fa972, #148a5b); border-color: #1fa972; color: #04140d; cursor: default; }
.captcha.ok .cap-label { color: var(--accent); font-weight: 550; }
.captcha.ok .cap-fill { background: rgba(25, 195, 125, .22); }
.captcha.err .cap-ctrl { animation: shake .34s; border-color: #6b3436; }
.captcha.err .cap-label { color: #ff8f8f; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  22% { transform: translateX(-6px); }
  44% { transform: translateX(5px); }
  66% { transform: translateX(-3px); }
  88% { transform: translateX(2px); }
}

.auth-err {
  font-size: 12.8px; line-height: 1.5; color: #ffb3b3;
  background: rgba(255, 107, 107, .09); border: 1px solid rgba(255, 107, 107, .26);
  padding: 8px 11px; border-radius: 8px;
}
.auth-submit {
  width: 100%; padding: 11px 0; border: 0; border-radius: 10px;
  font-size: 14.2px; font-weight: 600; color: #04140d;
  background: linear-gradient(180deg, #23d68a, #16a86c);
  transition: filter .15s, opacity .15s;
}
.auth-submit:hover { filter: brightness(1.06); }
.auth-submit:disabled { opacity: .6; cursor: not-allowed; }

.auth-foot {
  display: flex; align-items: center; justify-content: center; gap: 7px;
  margin-top: 16px; font-size: 11.6px; color: var(--text-mute);
}
.dot-sep { opacity: .6; }

@media (max-width: 420px) {
  .auth { padding: 16px 12px; }
  .auth-card { padding: 20px 18px 16px; border-radius: 16px; }
}

/* 侧边栏账户行：用户名占满，退出按钮靠右 */
.account-meta { flex: 1 1 auto; }
#logoutBtn { flex: 0 0 auto; width: 28px; height: 28px; opacity: .55; }
.account:hover #logoutBtn { opacity: 1; }

/* 设置面板：修改密码 */
.pw-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.pw-row input {
  flex: 1 1 120px; min-width: 0; padding: 9px 11px; font-size: 13.4px; outline: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: 9px;
}
.pw-row input:focus { border-color: #45454f; }
.pw-row .ghost-btn { flex: 0 0 auto; }
