:root {
  --bg: #0d0b14;
  --bg-2: #14111f;
  --card: #1a1626;
  --card-2: #221d33;
  --border: #2e2840;
  --text: #ece9f4;
  --text-2: #9a92b3;
  --accent: #8b5cf6;
  --accent-2: #22d3ee;
  --grad: linear-gradient(135deg, #8b5cf6 0%, #6366f1 50%, #22d3ee 100%);
  --danger: #f43f5e;
  --ok: #34d399;
  --warn: #fbbf24;
  --radius: 16px;
  --tabbar-h: 64px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
img { max-width: 100%; }
html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.55;
}

#app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100vh;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
  position: relative;
}

.hidden { display: none !important; }

/* ===== 顶栏 ===== */
#topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top, 0px));
  background: rgba(13, 11, 20, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo {
  width: 38px; height: 38px;
  border-radius: 12px;
  background: var(--grad);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 14px; color: #fff;
  box-shadow: 0 4px 14px rgba(139, 92, 246, 0.4);
}
.brand-name { font-weight: 700; font-size: 16px; }
.brand-sub { font-size: 12px; color: var(--text-2); }

.mode-chip {
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
  color: var(--text-2);
  background: var(--card);
}
.mode-chip.online { color: var(--ok); border-color: rgba(52, 211, 153, 0.4); }
.mode-chip.offline { color: var(--warn); border-color: rgba(251, 191, 36, 0.4); }

/* ===== 底部导航 ===== */
#tabbar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: 100%;
  max-width: 520px;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  display: flex;
  background: rgba(20, 17, 31, 0.92);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  z-index: 10;
}
.tab {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-2);
  font-size: 11px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
}
.tab-icon { font-size: 21px; filter: grayscale(1) opacity(0.55); transition: all 0.2s; }
.tab.active { color: var(--accent-2); }
.tab.active .tab-icon { filter: none; transform: scale(1.08); }

/* ===== 登录页 ===== */
.login-wrap {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  gap: 20px;
}
.login-hero {
  width: 76px; height: 76px;
  border-radius: 22px;
  background: var(--grad);
  display: flex; align-items: center; justify-content: center;
  font-size: 30px; font-weight: 800; color: #fff;
  box-shadow: 0 10px 34px rgba(139, 92, 246, 0.45);
}
.login-title { font-size: 22px; font-weight: 800; text-align: center; }
.login-sub { color: var(--text-2); font-size: 13px; text-align: center; }

.login-tabs {
  display: flex;
  width: 100%;
  background: var(--card);
  border-radius: var(--radius);
  padding: 4px;
  border: 1px solid var(--border);
}
.login-tabs button {
  flex: 1;
  padding: 9px 0;
  border: none;
  background: transparent;
  color: var(--text-2);
  font-size: 14px;
  border-radius: 12px;
  cursor: pointer;
}
.login-tabs button.active { background: var(--card-2); color: var(--text); font-weight: 600; }

.form { width: 100%; display: flex; flex-direction: column; gap: 14px; }
.form label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 6px; }
.form input, .form textarea, .form select {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 15px;
  font-family: inherit;
  outline: none;
}
.form input:focus, .form textarea:focus, .form select:focus { border-color: var(--accent); }
.form textarea { resize: none; min-height: 90px; }

.btn {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 14px;
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  cursor: pointer;
  background: var(--grad);
  background-size: 200% 200%;
  box-shadow: 0 6px 20px rgba(139, 92, 246, 0.35);
}
.btn:active { opacity: 0.85; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-danger { background: linear-gradient(135deg, #9f1239, var(--danger)); box-shadow: 0 6px 20px rgba(244, 63, 94, 0.3); }
.btn-ghost-btn { background: var(--card-2); box-shadow: none; }

.btn-ghost {
  width: 100%;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-2);
  padding: 10px;
  border-radius: 12px;
  font-size: 13px;
  cursor: pointer;
}

/* ===== 通用视图 ===== */
.view { padding: 16px; display: flex; flex-direction: column; gap: 14px; }

.section-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.section-title {
  font-size: 13px;
  font-weight: 700;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.section-title .link { color: var(--accent-2); font-size: 12px; font-weight: 500; cursor: pointer; }

/* ===== 创作模式切换 ===== */
.mode-tabs {
  display: flex;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
  gap: 4px;
}
.mode-tabs button {
  flex: 1;
  padding: 9px 0;
  border: none;
  background: transparent;
  color: var(--text-2);
  font-size: 13px;
  border-radius: 12px;
  cursor: pointer;
}
.mode-tabs button.active {
  background: var(--card-2);
  color: var(--text);
  font-weight: 600;
  box-shadow: inset 0 0 0 1px rgba(139, 92, 246, 0.35);
}

/* ===== 标签联想 ===== */
.tag-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-chip {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 14px;
  background: var(--card-2);
  border: 1px solid var(--border);
  color: var(--text-2);
  cursor: pointer;
}
.tag-chip:active { background: var(--accent); color: #fff; }

/* ===== 上传区 ===== */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  min-height: 140px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-2);
  font-size: 13px;
  text-align: center;
  cursor: pointer;
  overflow: hidden;
  position: relative;
}
.upload-zone img { max-width: 100%; max-height: 300px; display: block; }
.upload-zone .hint-line { padding: 20px; }

/* 局部重绘画布 */
.inpaint-wrap { position: relative; }
.inpaint-wrap canvas { width: 100%; border-radius: var(--radius); border: 1px solid var(--border); display: block; touch-action: none; }
.inpaint-tools { display: flex; gap: 8px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.inpaint-tools .tool-btn {
  padding: 7px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card-2);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
}
.inpaint-tools .tool-btn.active { background: var(--accent); border-color: var(--accent); }
.inpaint-tools input[type=range] { flex: 1; min-width: 90px; accent-color: var(--accent); }

/* ===== 参数区 ===== */
.param-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.param-grid .full { grid-column: 1 / -1; }
.param label { display: block; font-size: 12px; color: var(--text-2); margin-bottom: 5px; }
.param select, .param input {
  width: 100%;
  background: var(--card-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
}
.param select:focus, .param input:focus { border-color: var(--accent); }

.size-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.size-btn {
  padding: 9px 4px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card-2);
  color: var(--text-2);
  font-size: 12px;
  cursor: pointer;
  text-align: center;
}
.size-btn.active { background: rgba(139, 92, 246, 0.18); border-color: var(--accent); color: var(--text); }

.range-row { display: flex; align-items: center; gap: 10px; }
.range-row input[type=range] { flex: 1; accent-color: var(--accent); }
.range-val { min-width: 44px; text-align: right; font-size: 13px; color: var(--text-2); font-variant-numeric: tabular-nums; }

.seed-row { display: flex; gap: 8px; align-items: center; }
.seed-row input { flex: 1; }
.dice-btn {
  width: 40px; height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card-2);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
}

.hint { font-size: 12px; color: var(--text-2); }
.cost-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-2);
}
.cost-line b { color: var(--accent-2); font-size: 15px; }

/* 生成按钮加载态 */
.btn .spin {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: -2px;
  margin-right: 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== 结果展示 ===== */
.result-img {
  width: 100%;
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  display: block;
}
.result-meta { font-size: 12px; color: var(--text-2); display: flex; flex-wrap: wrap; gap: 4px 14px; }
.result-actions { display: flex; gap: 8px; }
.result-actions .btn { flex: 1; padding: 11px; font-size: 13px; }

/* ===== 图库 ===== */
.gallery-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.gallery-item {
  position: relative;
  aspect-ratio: 3 / 4;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--card);
  cursor: pointer;
}
.gallery-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gallery-item .badge {
  position: absolute;
  top: 6px; right: 6px;
  background: rgba(0,0,0,0.65);
  color: #fff;
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 8px;
}
.load-more {
  width: 100%;
  padding: 12px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-2);
  font-size: 13px;
  cursor: pointer;
}

/* ===== 大图弹窗 ===== */
.modal { position: fixed; inset: 0; z-index: 1000; }
body.modal-open { overflow: hidden; }
body.modal-open #tabbar, body.modal-open .chat-input-bar { visibility: hidden; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.8); backdrop-filter: blur(2px); }
.modal-sheet {
  position: absolute;
  max-width: 520px;
  width: 100%;
  max-height: 92vh;
  overflow-y: auto;
  background: var(--bg-2);
  border-radius: 20px 20px 0 0;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  padding: 16px;
  padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
}
.modal-sheet img { width: 100%; border-radius: 14px; display: block; }
.modal-info { margin-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.modal-meta { font-size: 12px; color: var(--text-2); display: flex; flex-wrap: wrap; gap: 4px 14px; }
.modal-prompt {
  font-size: 13px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  max-height: 120px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}
.modal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.modal-actions .btn { padding: 11px; font-size: 13px; }

/* ===== 我的页 ===== */
.profile-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.avatar {
  width: 52px; height: 52px;
  border-radius: 50%;
  background: var(--grad);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 800; color: #fff;
}
.profile-name { font-weight: 700; font-size: 17px; }
.profile-role { font-size: 12px; color: var(--text-2); }
.quota-bar {
  height: 8px;
  border-radius: 6px;
  background: var(--card-2);
  overflow: hidden;
  margin-top: 10px;
}
.quota-bar .fill {
  height: 100%;
  background: var(--grad);
  border-radius: 6px;
  transition: width 0.3s;
}
.quota-text { font-size: 12px; color: var(--text-2); margin-top: 6px; }

.kv-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.kv-row:last-child { border-bottom: none; }
.kv-row .k { color: var(--text-2); }
.kv-row .v { color: var(--text); font-variant-numeric: tabular-nums; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + 24px);
  background: rgba(34, 29, 51, 0.97);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 24px;
  font-size: 13px;
  z-index: 200;
  max-width: 86%;
  text-align: center;
  animation: fadein 0.2s ease;
}
@keyframes fadein { from { opacity: 0; transform: translate(-50%, 6px); } to { opacity: 1; transform: translate(-50%, 0); } }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.empty { text-align: center; color: var(--text-2); padding: 60px 0; font-size: 14px; }
.empty .big { font-size: 44px; display: block; margin-bottom: 12px; }

.btn-ghost:active { background: var(--card); }

/* ===== 聊天室 ===== */
.tab { position: relative; }
.tab-badge {
  position: absolute;
  top: 6px;
  left: 50%;
  margin-left: 8px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  line-height: 16px;
  text-align: center;
  font-weight: 700;
}

.chat-view { padding-bottom: 120px; }
.chat-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-2);
}
.chat-online { display: flex; align-items: center; gap: 6px; }
.chat-online .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 6px rgba(52, 211, 153, 0.8);
}
.chat-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 200px;
}
.chat-empty { text-align: center; color: var(--text-2); padding: 40px 0; font-size: 13px; }
.msg { display: flex; flex-direction: column; align-items: flex-start; max-width: 100%; }
.msg.own { align-items: flex-end; }
.msg-meta { font-size: 11px; color: var(--text-2); margin-bottom: 3px; padding: 0 4px; }
.msg-bubble {
  background: var(--card);
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: 14px;
  max-width: 82%;
  word-break: break-word;
  white-space: pre-wrap;
  font-size: 14px;
}
.msg.own .msg-bubble {
  background: rgba(139, 92, 246, 0.22);
  border-color: rgba(139, 92, 246, 0.45);
}
.msg-img {
  max-width: 82%;
  border-radius: 12px;
  border: 1px solid var(--border);
  display: block;
}
.msg-img + .msg-bubble { margin-top: 6px; }

.chat-input-bar {
  position: fixed;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 520px;
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  background: rgba(20, 17, 31, 0.95);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  z-index: 9;
}
.chat-input-bar input {
  flex: 1;
  background: var(--card-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 22px;
  padding: 10px 16px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
}
.chat-input-bar input:focus { border-color: var(--accent); }
.chat-send-btn {
  border: none;
  border-radius: 22px;
  padding: 0 20px;
  background: var(--grad);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}
.chat-send-btn:disabled { opacity: 0.5; }
.modal-actions .wide { grid-column: 1 / -1; }
/* ===== 机器人消息 ===== */
.msg.bot .msg-bubble {
  background: rgba(34, 211, 238, 0.10);
  border-color: rgba(34, 211, 238, 0.38);
}
.msg.bot .msg-img { max-width: 92%; }
.msg.bot .msg-meta { color: var(--accent-2); }
/* ===== QQ 头像 ===== */
.avatar-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar-letter { display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; }
.avatar { overflow: hidden; }
.avatar .avatar-letter { color: #fff; font-size: 22px; font-weight: 800; }

.msg-body { display: flex; gap: 8px; align-items: flex-start; max-width: 100%; }
.msg.own .msg-body { flex-direction: row-reverse; }
.msg-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--card-2);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.msg-avatar .avatar-letter { font-size: 15px; font-weight: 700; color: var(--text-2); }
.msg-content { display: flex; flex-direction: column; gap: 6px; min-width: 0; max-width: calc(100% - 42px); }
.msg.own .msg-content { align-items: flex-end; }

.admin-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--card-2);
  border: 1px solid var(--border);
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.admin-avatar .avatar-letter { font-size: 13px; font-weight: 700; color: var(--text-2); }
/* ===== 折叠卡片（参数） ===== */
details.section-card > summary { cursor: pointer; list-style: none; user-select: none; }
details.section-card > summary::-webkit-details-marker { display: none; }
.fold-arrow { display: inline-block; color: var(--text-2); font-size: 12px; transition: transform 0.2s; }
details[open] > summary .fold-arrow { transform: rotate(180deg); }

/* ===== 生成按钮吸底跟随画面 ===== */
#wb-generate {
  position: sticky;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 12px);
  z-index: 8;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.18);
}
/* ===== 折叠栏右侧显示当前分辨率 ===== */
.fold-right { margin-left: auto; display: inline-flex; align-items: center; gap: 8px; }
.fold-current { font-size: 12px; color: var(--accent-2); font-weight: 600; }

/* ===== 聊天 @提及 ===== */
.mention-me { color: var(--accent-2); font-weight: 700; background: rgba(34, 211, 238, 0.14); border-radius: 4px; padding: 0 2px; }
.msg-meta { cursor: pointer; }
/* ===== 出图后标题栏压缩成一行 ===== */
.view-heading.compact { flex-direction: row; align-items: center; gap: 10px; padding: 10px 14px; }
.view-heading.compact .compact-title { margin: 0; font-size: 13px; font-weight: 700; }
.view-heading.compact .guide-entry { margin-left: auto; }
.view-heading.compact .background-hide { width: 34px; height: 34px; padding: 0; font-size: 16px; line-height: 1; }

/* ===== 聊天 @ 成员选择器 ===== */
.at-picker {
  position: fixed;
  z-index: 60;
  width: 240px;
  max-height: 260px;
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.at-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: none;
  color: var(--text);
  padding: 8px 10px;
  border-radius: 8px;
  text-align: left;
  font-size: 14px;
  cursor: pointer;
  width: 100%;
}
.at-item:hover { background: var(--card-2); }
.at-item .avatar-img, .at-item .avatar-letter { width: 24px; height: 24px; }
.at-item .hint { margin-left: auto; font-size: 11px; }
/* ===== 预设新建入口与表单 ===== */
.preset-new-btn {
  border: 1px solid var(--border);
  background: var(--card-2);
  color: var(--accent-2);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
.preset-new-form { display: flex; flex-direction: column; gap: 10px; }
.preset-new-form input,
.preset-new-form textarea {
  width: 100%;
  background: var(--card-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  resize: vertical;
}
.preset-new-form input:focus, .preset-new-form textarea:focus { border-color: var(--accent); }
.preset-new-actions { display: flex; gap: 8px; }
.preset-new-actions .btn { flex: 1; }

/* 紧凑标题栏「隐藏」按钮为文字样式 */
.view-heading.compact .background-hide { width: auto; height: auto; padding: 6px 10px; font-size: 12px; line-height: 1.4; }