:root {
  --bg: #0b0c10;
  --panel: #111217;
  --panel-2: #171920;
  --panel-3: #1e2029;
  --line: #22242d;
  --line-2: #2d303b;
  --text: #e7e8ee;
  --muted: #8a8d9a;
  --faint: #5c5f6b;
  --accent: #a594ff;
  --accent-soft: rgba(165, 148, 255, 0.14);
  --pink: #e98bd8;
  --grad: linear-gradient(135deg, #8f7bff 0%, #b98cf5 50%, #e98bd8 100%);
  --ok: #5fd3a5;
  --warn: #f2c46d;
  --danger: #ff6b81;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
  --font: ui-sans-serif, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
kbd {
  font: 11px var(--mono);
  padding: 1px 6px;
  border: 1px solid var(--line-2);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--panel-2);
}
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12px; }
.icon { display: inline-flex; line-height: 0; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #262832; border-radius: 10px; border: 3px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background-color: #343744; }
::-webkit-scrollbar-track { background: transparent; }

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

.topbar {
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px 0 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(13, 14, 19, 0.85);
  backdrop-filter: blur(12px);
  position: relative;
  z-index: 5;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 650;
  font-size: 15px;
  letter-spacing: 0.2px;
}
.brand span {
  background: linear-gradient(90deg, #fff 0%, #d9d2ff 60%, #f5c6ec 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand.big { font-size: 22px; gap: 12px; justify-content: center; }
.logo { filter: drop-shadow(0 0 12px rgba(165, 148, 255, 0.45)); }

.top-stats { display: flex; align-items: center; gap: 8px; }
.stat {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 30px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}
.stat #anlas { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.stat svg { color: var(--accent); }
.tier {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  padding: 1px 6px;
  border-radius: 5px;
  background: var(--accent-soft);
  color: var(--accent);
}
.tier:empty { display: none; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); }
.stat.idle .dot { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.stat.busy .dot { background: var(--warn); box-shadow: 0 0 8px var(--warn); animation: pulse 1.2s infinite; }
.stat.down .dot { background: var(--danger); }
@keyframes pulse { 50% { opacity: 0.35; } }
.battery {
  width: 26px;
  height: 11px;
  border: 1.5px solid var(--muted);
  border-radius: 3px;
  padding: 1px;
  position: relative;
}
.battery::after {
  content: "";
  position: absolute;
  right: -4px;
  top: 2.5px;
  width: 2px;
  height: 4px;
  border-radius: 0 1px 1px 0;
  background: var(--muted);
}
.battery i { display: block; height: 100%; border-radius: 1px; background: var(--ok); width: 0; transition: width 0.4s; }
.battery.low i { background: var(--danger); }

.user { display: flex; align-items: center; gap: 8px; margin-left: 6px; color: var(--muted); }
.avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--grad);
  color: #fff;
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
}

/* ---------- 布局 ---------- */

.layout {
  display: grid;
  grid-template-columns: 392px minmax(0, 1fr) 236px;
  height: calc(100vh - 54px);
}
.panel { background: var(--panel); min-height: 0; }
.controls { border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.controls-scroll { flex: 1; overflow-y: auto; padding: 6px 16px 20px; }
.history { border-left: 1px solid var(--line); display: flex; flex-direction: column; }

.sec { padding: 14px 0; border-bottom: 1px solid var(--line); }
.sec:last-child { border-bottom: 0; }
.sec-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.3px;
}
.sec-title.sub { margin-top: 12px; }
.count { color: var(--faint); font-weight: 500; margin-left: 2px; }
.hint { color: var(--faint); font-size: 12px; margin-top: 8px; line-height: 1.55; }
.hint.inline { margin: 0; font-weight: 400; letter-spacing: 0; }
.hint.warn, .warn-text { color: var(--warn); }
.hint.bad { color: var(--danger); }
.error-text { color: var(--danger); font-size: 12px; min-height: 18px; }

/* ---------- 基础控件 ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-2);
  background: var(--panel-2);
  transition: background 0.15s, border-color 0.15s, opacity 0.15s, transform 0.1s;
  white-space: nowrap;
}
.btn:hover { background: var(--panel-3); border-color: #3a3d4a; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.btn.block { width: 100%; }
.btn.small { height: 28px; padding: 0 10px; font-size: 12px; }
.btn.ghost { background: transparent; }
.btn.dashed { background: transparent; border-style: dashed; color: var(--muted); }
.btn.dashed:hover { color: var(--text); border-color: var(--accent); background: var(--accent-soft); }
.btn.primary { background: var(--grad); border: 0; color: #fff; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: rgba(255, 107, 129, 0.1); border-color: rgba(255, 107, 129, 0.4); }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  flex: none;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--panel-3); color: var(--text); }
.icon-btn:disabled { opacity: 0.35; cursor: not-allowed; }

input[type="text"], input[type="search"], input[type="password"], input:not([type]), input[type="number"], select, textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input:disabled { opacity: 0.5; }
textarea { resize: vertical; min-height: 44px; line-height: 1.55; font-size: 13px; }
textarea.tag-input { font-family: var(--font); }
select {
  appearance: none;
  padding-right: 28px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%238a8d9a' fill='none' stroke-width='1.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  cursor: pointer;
}
input[type="number"] { -moz-appearance: textfield; }
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; }
.mini-select { width: auto; height: 26px; padding: 2px 26px 2px 9px; font-size: 12px; background-color: var(--panel-2); }

/* 开关 */
.switch {
  appearance: none;
  width: 34px;
  height: 20px;
  flex: none;
  border-radius: 999px;
  background: var(--line-2);
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
  margin: 0;
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #cfd0d8;
  transition: transform 0.2s, background 0.2s;
}
.switch:checked { background: var(--grad); }
.switch:checked::after { transform: translateX(14px); background: #fff; }
.switch:focus { box-shadow: none; }

.mini-switch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  letter-spacing: 0;
}
.mini-switch input { display: none; }
.mini-switch i {
  width: 26px;
  height: 15px;
  border-radius: 999px;
  background: var(--line-2);
  position: relative;
  transition: background 0.2s;
}
.mini-switch i::after {
  content: "";
  position: absolute;
  top: 2.5px;
  left: 2.5px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #cfd0d8;
  transition: transform 0.2s;
}
.mini-switch input:checked + i { background: var(--grad); }
.mini-switch input:checked + i::after { transform: translateX(11px); background: #fff; }

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  margin-top: 10px;
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  border: 1px solid var(--line);
  cursor: pointer;
}
.switch-row b { display: block; font-weight: 600; font-size: 13px; }
.switch-row small { color: var(--faint); font-size: 12px; }

/* 分段选择 */
.seg {
  display: flex;
  gap: 3px;
  padding: 3px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--line);
}
.seg button {
  flex: 1;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  padding: 6px 4px;
  transition: background 0.15s, color 0.15s;
  line-height: 1.25;
}
.seg button:hover { color: var(--text); }
.seg button.on { background: var(--panel-3); color: var(--text); box-shadow: 0 1px 0 rgba(255, 255, 255, 0.05) inset, 0 2px 8px rgba(0, 0, 0, 0.3); }
.seg.models button { padding: 8px 4px; }
.seg.models b { display: block; font-size: 14px; font-weight: 650; }
.seg.models small { font-size: 11px; color: var(--faint); }
.seg.models button.on b { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.seg.small button { padding: 4px 0; font-variant-numeric: tabular-nums; }

/* 滑块 */
.field { display: grid; grid-template-columns: 82px 1fr; align-items: center; gap: 10px; margin-top: 8px; }
.field > label { color: var(--muted); font-size: 12px; }
.field.col { grid-template-columns: 1fr; gap: 5px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.slider { display: flex; align-items: center; gap: 10px; }
.slider input[type="number"] { width: 58px; flex: none; text-align: center; padding: 4px 4px; font-variant-numeric: tabular-nums; }
input[type="range"] {
  appearance: none;
  flex: 1;
  min-width: 0;
  height: 18px;
  background: transparent;
  cursor: pointer;
  --p: 50%;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 4px;
  background: linear-gradient(90deg, #8f7bff, #d58be3) 0 / var(--p) 100% no-repeat, var(--line-2);
}
input[type="range"]::-moz-range-track { height: 4px; border-radius: 4px; background: var(--line-2); }
input[type="range"]::-moz-range-progress { height: 4px; border-radius: 4px; background: linear-gradient(90deg, #8f7bff, #d58be3); }
input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 14px;
  height: 14px;
  margin-top: -5px;
  border-radius: 50%;
  background: #fff;
  border: 0;
  box-shadow: 0 0 0 4px rgba(165, 148, 255, 0.25), 0 2px 6px rgba(0, 0, 0, 0.4);
  transition: box-shadow 0.15s;
}
input[type="range"]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 0; }
input[type="range"]:hover::-webkit-slider-thumb { box-shadow: 0 0 0 6px rgba(165, 148, 255, 0.3), 0 2px 6px rgba(0, 0, 0, 0.4); }
input[type="range"]:focus { box-shadow: none; }

/* 尺寸 */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid var(--line-2);
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  transition: all 0.15s;
}
.chip small { color: var(--faint); font-family: var(--mono); font-size: 11px; }
.chip:hover { color: var(--text); border-color: #3a3d4a; }
.chip.on { color: var(--text); border-color: var(--accent); background: var(--accent-soft); }
.chip.on small { color: var(--accent); }
.chip:disabled { opacity: 0.35; cursor: not-allowed; }
.chip .ar { width: 10px; height: 10px; border: 1.5px solid currentColor; border-radius: 2px; }
.size-row { display: flex; align-items: center; gap: 6px; margin-top: 10px; }
.size-row .num { text-align: center; font-family: var(--mono); }

.seed-box { display: flex; gap: 2px; align-items: center; }
.seed-box input { font-family: var(--mono); min-width: 0; }

/* ---------- 提示词补全 ---------- */

.ta-wrap { position: relative; }
.suggest {
  position: fixed;
  z-index: 50;
  max-height: 260px;
  overflow-y: auto;
  padding: 4px;
  border-radius: 10px;
  border: 1px solid var(--line-2);
  background: rgba(23, 25, 32, 0.97);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
}
.sg-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
}
.sg-item .n { color: var(--faint); font-family: var(--mono); font-size: 11px; flex: none; }
.sg-tag { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sg-tag small { margin-left: 8px; color: var(--muted); font-size: 12px; }
.sg-item.on, .sg-item:hover { background: var(--accent-soft); }
.sg-item.on .n { color: var(--accent); }

/* ---------- 角色 ---------- */

.chars { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.char-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: opacity 0.15s;
}
.char-card.off { opacity: 0.5; }
.char-head { display: flex; align-items: center; gap: 8px; }
.char-head .idx {
  font-size: 11px;
  font-weight: 700;
  width: 20px;
  height: 20px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  background: var(--grad);
  color: #fff;
}
.char-head .name { flex: 1; color: var(--muted); font-size: 12px; }
.char-body { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: start; }
.char-body textarea { min-height: 36px; }
.char-texts { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.char-texts .neg { font-size: 12px; color: #c0c2cc; }
.pos-grid {
  display: grid;
  grid-template-columns: repeat(5, 12px);
  gap: 3px;
  padding: 5px;
  border-radius: 7px;
  background: var(--bg);
  border: 1px solid var(--line);
}
.pos-grid button {
  width: 12px;
  height: 12px;
  padding: 0;
  border-radius: 3px;
  border: 0;
  background: var(--line-2);
}
.pos-grid button:hover { background: #4a4d5c; }
.pos-grid button.on { background: var(--accent); box-shadow: 0 0 6px var(--accent); }

/* ---------- 参考图 ---------- */

.tabs { display: flex; gap: 2px; margin-bottom: 12px; border-bottom: 1px solid var(--line); }
.tabs button {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 4px 2px 10px;
  position: relative;
  font-weight: 600;
  font-size: 12px;
}
.tabs button:hover { color: var(--text); }
.tabs button.on { color: var(--text); }
.tabs button.on::after {
  content: "";
  position: absolute;
  left: 18%;
  right: 18%;
  bottom: -1px;
  height: 2px;
  border-radius: 2px;
  background: var(--grad);
}
.tabs .badge {
  display: inline-grid;
  place-items: center;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  margin-left: 5px;
  border-radius: 8px;
  background: var(--accent);
  color: #15121f;
  font-size: 10px;
  font-weight: 700;
  vertical-align: 1px;
}
.tabs .badge:empty { display: none; }
.tabs button.na { opacity: 0.45; }

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 92px;
  padding: 14px;
  border: 1.5px dashed var(--line-2);
  border-radius: 10px;
  color: var(--muted);
  text-align: center;
  cursor: pointer;
  transition: all 0.15s;
}
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.dropzone small { color: var(--faint); }
.notice {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: rgba(242, 196, 109, 0.08);
  border: 1px solid rgba(242, 196, 109, 0.22);
  color: var(--warn);
  font-size: 12px;
  margin-bottom: 10px;
}
.notice.info { background: var(--accent-soft); border-color: rgba(165, 148, 255, 0.25); color: #c9c0ff; }

.ref-card {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 12px;
  padding: 10px;
  border-radius: 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  margin-bottom: 8px;
}
.ref-thumb {
  width: 72px;
  height: 96px;
  border-radius: 7px;
  object-fit: cover;
  background: var(--bg);
  border: 1px solid var(--line);
}
.ref-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.ref-body .field { grid-template-columns: 52px 1fr; margin-top: 4px; }
.ref-top { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.ref-top .seg { flex: 1; padding: 2px; }
.ref-top .seg button { padding: 3px 0; font-size: 12px; }
.ref-status { font-size: 11px; color: var(--faint); }
.ref-status.ok { color: var(--ok); }

.base-card { border-radius: 10px; background: var(--panel-2); border: 1px solid var(--line); padding: 10px; }
.base-preview {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg);
  display: grid;
  place-items: center;
  max-height: 220px;
}
.base-img { position: relative; line-height: 0; }
.base-img img { max-width: 100%; max-height: 220px; display: block; }
.base-img .mask-overlay {
  position: absolute;
  inset: 0;
  background: var(--accent);
  opacity: 0.55;
  -webkit-mask-size: 100% 100%;
  mask-size: 100% 100%;
}
.base-tag {
  position: absolute;
  left: 8px;
  top: 8px;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  background: rgba(11, 12, 16, 0.75);
  backdrop-filter: blur(6px);
}
.base-actions { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.base-actions .btn { flex: 1; }

/* ---------- 生成按钮 ---------- */

.gen-bar { padding: 12px 16px 16px; border-top: 1px solid var(--line); background: var(--panel); }
.btn.gen {
  width: 100%;
  height: 46px;
  border: 0;
  border-radius: 11px;
  background: var(--grad);
  background-size: 160% 160%;
  color: #fff;
  font-size: 15px;
  font-weight: 650;
  letter-spacing: 1px;
  justify-content: space-between;
  padding: 0 16px 0 20px;
  box-shadow: 0 8px 28px rgba(165, 120, 255, 0.28);
  transition: background-position 0.4s, box-shadow 0.2s, filter 0.2s;
}
.btn.gen:hover { background-position: 100% 0; box-shadow: 0 10px 34px rgba(200, 130, 240, 0.38); filter: none; }
.btn.gen.running { background: var(--panel-3); box-shadow: none; color: var(--text); }
.btn.gen .cost {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0;
  padding: 3px 9px;
  border-radius: 7px;
  background: rgba(10, 8, 20, 0.28);
}
.btn.gen .cost:empty { display: none; }
.btn.gen.running .cost { display: none; }

/* ---------- 中间画布 ---------- */

.stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }
.viewer {
  flex: 1;
  min-height: 0;
  position: relative;
  display: grid;
  /* 固定单格：图片的 max-height: 100% 才有参照，竖图不会被裁掉 */
  grid-template: minmax(0, 1fr) / minmax(0, 1fr);
  place-items: center;
  padding: 24px;
  overflow: hidden;
  background:
    radial-gradient(60% 50% at 50% 40%, rgba(143, 123, 255, 0.08), transparent 70%),
    radial-gradient(40% 40% at 70% 80%, rgba(233, 139, 216, 0.05), transparent 70%);
}
.viewer > #empty, .viewer img#view-img { grid-area: 1 / 1; }
.viewer img#view-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 6px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
  background: repeating-conic-gradient(#1a1b22 0% 25%, #22232c 0% 50%) 50% / 20px 20px;
  animation: appear 0.35s ease;
  cursor: zoom-in;
}
.viewer.zoom { overflow: auto; place-items: start safe center; }
.viewer.zoom img#view-img { max-width: none; max-height: none; cursor: zoom-out; }
@keyframes appear { from { opacity: 0; transform: scale(0.985); } }
.empty { text-align: center; color: var(--muted); max-width: 360px; }
.empty h2 { margin: 16px 0 6px; font-size: 18px; font-weight: 600; color: var(--text); }
.empty p { margin: 6px 0; }
.empty .logo { opacity: 0.9; }

.viewer > .busy {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: rgba(11, 12, 16, 0.55);
  backdrop-filter: blur(6px);
  z-index: 2;
}
.busy-text { font-size: 14px; font-weight: 600; }
.ring {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: conic-gradient(from 0deg, transparent 0%, #8f7bff 40%, #e98bd8 70%, transparent 100%);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 4px), #000 calc(100% - 3px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 4px), #000 calc(100% - 3px));
  animation: spin 0.9s linear infinite;
  margin-bottom: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.drop-hint {
  position: absolute;
  inset: 14px;
  border: 2px dashed var(--accent);
  border-radius: 16px;
  background: rgba(165, 148, 255, 0.08);
  display: grid;
  place-items: center;
  z-index: 3;
  pointer-events: none;
  font-size: 15px;
  font-weight: 600;
  color: #d6cfff;
}

.batch { display: flex; justify-content: center; gap: 8px; padding: 0 16px 10px; }
.batch button {
  width: 52px;
  height: 52px;
  padding: 0;
  border-radius: 8px;
  overflow: hidden;
  border: 2px solid transparent;
  background: var(--panel-2);
  opacity: 0.6;
  transition: all 0.15s;
}
.batch button img { width: 100%; height: 100%; object-fit: cover; display: block; }
.batch button:hover { opacity: 1; }
.batch button.on { border-color: var(--accent); opacity: 1; }
.batch button.batch-dl { display: grid; place-items: center; color: var(--muted); border: 1px dashed var(--line-2); background: transparent; margin-left: 6px; }
.batch button.batch-dl:hover { color: var(--text); border-color: var(--accent); }

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  border-top: 1px solid var(--line);
  background: var(--panel);
  min-height: 54px;
}
.toolbar .meta { color: var(--faint); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.toolbar .meta b { color: var(--muted); font-weight: 500; }
.tools { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.tools .btn { height: 32px; padding: 0 10px; background: transparent; border-color: transparent; color: var(--muted); font-size: 12px; }
.tools .btn:hover { background: var(--panel-3); color: var(--text); }
.tools .sep { width: 1px; background: var(--line-2); margin: 6px 4px; }
.tool-cost {
  margin-left: 2px;
  padding: 1px 6px;
  border-radius: 6px;
  background: var(--panel-3);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.tool-cost:empty { display: none; }
.tool-cost.free { color: var(--ok, #5fd39a); }
.tools .btn:disabled .tool-cost { display: none; }

/* ---------- 历史 ---------- */

.hist-actions { display: flex; gap: 2px; }
.icon-btn.on { background: var(--accent-soft); color: var(--accent); }
.hist-bar { margin: 0 12px 8px; padding: 8px 10px; border-radius: var(--radius-sm); background: var(--panel-2); border: 1px solid var(--line-2); display: flex; flex-direction: column; gap: 8px; font-size: 12px; }
.hist-bar[hidden] { display: none; }
.hist-bar-top { display: flex; justify-content: space-between; align-items: center; color: var(--muted); }
.hist-bar-btns { display: flex; gap: 6px; }
.hist-bar-btns .btn.primary { flex: 1; }
.text-btn { border: 0; background: none; padding: 0; color: var(--accent); font-size: 12px; cursor: pointer; }
.text-btn:hover { text-decoration: underline; }
.hist-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 10px 8px 16px;
  font-weight: 600;
  font-size: 12px;
  color: var(--muted);
}
.hist-grid {
  flex: 1;
  overflow-y: auto;
  padding: 0 12px 16px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  align-content: start;
}
.hist-empty { padding: 24px 16px; text-align: center; font-size: 12px; }
.hist-item {
  position: relative;
  aspect-ratio: 3 / 4;
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel-2);
  border: 2px solid transparent;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
  content-visibility: auto;
}
.hist-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.hist-item:hover { transform: translateY(-1px); }
.hist-item.on { border-color: var(--accent); }
.hist-item .del {
  position: absolute;
  right: 4px;
  top: 4px;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: 0;
  display: grid;
  place-items: center;
  background: rgba(11, 12, 16, 0.7);
  color: #ddd;
  opacity: 0;
  transition: opacity 0.15s;
}
.hist-item:hover .del { opacity: 1; }
.hist-item .chk {
  position: absolute;
  left: 4px;
  top: 4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: none;
  place-items: center;
  border: 1.5px solid rgba(255, 255, 255, 0.75);
  background: rgba(11, 12, 16, 0.45);
  color: transparent;
}
.selecting .hist-item .chk { display: grid; }
.selecting .hist-item .del { display: none; }
.selecting .hist-item { user-select: none; }
.hist-item.sel { border-color: var(--accent); }
.hist-item.sel .chk { background: var(--accent); border-color: var(--accent); color: #14111f; }
.selecting .hist-item:not(.sel) img { opacity: 0.6; }
.hist-item .del:hover { color: var(--danger); }
.hist-item .tag {
  position: absolute;
  left: 4px;
  bottom: 4px;
  padding: 1px 6px;
  border-radius: 5px;
  font-size: 10px;
  font-weight: 600;
  background: rgba(11, 12, 16, 0.72);
  color: #d6cfff;
}

/* ---------- 浮层 ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(5, 6, 9, 0.62);
  backdrop-filter: blur(8px);
  animation: fade 0.18s ease;
}
@keyframes fade { from { opacity: 0; } }
.login { background: radial-gradient(50% 50% at 50% 45%, rgba(143, 123, 255, 0.16), rgba(5, 6, 9, 0.9)); backdrop-filter: blur(18px); z-index: 60; }
.login-card {
  width: min(380px, 100%);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 32px 28px 24px;
  border-radius: 18px;
  background: rgba(17, 18, 23, 0.92);
  border: 1px solid var(--line-2);
  box-shadow: var(--shadow), 0 0 0 1px rgba(255, 255, 255, 0.02) inset;
  text-align: center;
}
.login-card input { height: 42px; font-family: var(--mono); text-align: center; }
.login-card .btn { height: 42px; }
.login-card p { margin: 0; }

.modal {
  width: min(460px, 100%);
  max-height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
  border-radius: 16px;
  background: var(--panel);
  border: 1px solid var(--line-2);
  box-shadow: var(--shadow);
  animation: rise 0.2s ease;
}
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
.modal.wide { width: min(1100px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px 10px 20px; font-weight: 600; font-size: 15px; }
.modal-body { padding: 4px 20px 16px; overflow: auto; display: flex; flex-direction: column; gap: 10px; }
.modal-body .field { grid-template-columns: 70px 1fr; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px 16px; border-top: 1px solid var(--line); }

.modal.import-modal { width: min(760px, 100%); }
.import-modal .modal-foot { flex-wrap: wrap; }
.import { display: grid; grid-template-columns: minmax(0, 260px) minmax(0, 1fr); gap: 16px; align-items: start; }
.import-img { width: 100%; max-height: 52vh; object-fit: contain; border-radius: 8px; background: repeating-conic-gradient(#1a1b22 0% 25%, #22232c 0% 50%) 50% / 16px 16px; }
.import-info { display: flex; flex-direction: column; gap: 10px; min-width: 0; max-height: 52vh; overflow: auto; font-size: 12.5px; }
.import-facts { color: var(--muted); font-size: 11.5px; }
.import-block b { display: block; font-size: 11px; font-weight: 600; color: var(--muted); margin-bottom: 3px; }
.import-block p { margin: 0; padding: 8px 10px; border-radius: 8px; background: var(--panel-2); border: 1px solid var(--line); white-space: pre-wrap; word-break: break-word; line-height: 1.5; max-height: 140px; overflow: auto; }
.import-checks { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; font-size: 12.5px; }
.import-checks .check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.import-checks .check input { accent-color: var(--accent); margin: 0; }
@media (max-width: 640px) { .import { grid-template-columns: 1fr; } }

.emotions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; }
.emotions button {
  padding: 6px 2px;
  border-radius: 7px;
  border: 1px solid var(--line-2);
  background: transparent;
  color: var(--muted);
  font-size: 12px;
}
.emotions button:hover { color: var(--text); }
.emotions button.on { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }

.mask-tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.mask-tools .slider { width: 200px; }
.mask-tools .grow { flex: 1; }
.mask-stage {
  position: relative;
  margin: 0 auto;
  border-radius: 8px;
  overflow: hidden;
  touch-action: none;
  cursor: none;
  background: var(--bg);
}
.mask-stage img, .mask-stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; user-select: none; -webkit-user-drag: none; }
.mask-stage canvas { opacity: 0.6; }
.brush-cursor {
  position: absolute;
  border: 1.5px solid #fff;
  border-radius: 50%;
  pointer-events: none;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.6);
  transform: translate(-50%, -50%);
  display: none;
}

.menu {
  position: fixed;
  z-index: 45;
  min-width: 170px;
  padding: 5px;
  border-radius: 11px;
  background: rgba(23, 25, 32, 0.98);
  border: 1px solid var(--line-2);
  box-shadow: var(--shadow);
  animation: rise 0.14s ease;
}
.menu button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 12px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  text-align: left;
}
.menu button:hover { background: var(--accent-soft); }
.menu small { margin-left: auto; color: var(--faint); font-size: 11px; }

.toasts {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  z-index: 70;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.toast {
  max-width: min(560px, calc(100vw - 32px));
  padding: 10px 16px;
  border-radius: 10px;
  background: rgba(30, 32, 41, 0.97);
  border: 1px solid var(--line-2);
  box-shadow: var(--shadow);
  font-size: 13px;
  animation: rise 0.2s ease;
  pointer-events: auto;
  word-break: break-word;
}
.toast.error { border-color: rgba(255, 107, 129, 0.45); color: #ffc2cb; }
.toast.ok { border-color: rgba(95, 211, 165, 0.4); color: #c3f1dd; }
.toast.out { opacity: 0; transform: translateY(6px); transition: all 0.25s; }

/* ---------- 响应式 ---------- */

/* ---------- TAG 检索 ---------- */

.sec-actions { display: inline-flex; align-items: center; gap: 12px; }
.tag-open {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 6px;
  border: 1px solid var(--line-2);
  background: none;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}
.tag-open:hover, .tg-open .tag-open { color: var(--text); border-color: var(--accent); background: var(--accent-soft); }

.tag-panel {
  position: fixed;
  z-index: 40;
  top: 54px;
  bottom: 0;
  left: 392px;
  width: 400px;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--line-2);
  box-shadow: 16px 0 40px rgba(0, 0, 0, 0.45);
}
.tg-head { display: flex; align-items: center; gap: 10px; padding: 12px 10px 8px 16px; }
.tg-head b { font-size: 14px; }
.tg-status { flex: 1; color: var(--faint); font-size: 12px; }
.tg-search {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 16px;
  padding: 0 10px;
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  color: var(--faint);
}
.tg-search:focus-within { border-color: var(--accent); }
input.tg-input, input.tg-input:focus { flex: 1; min-width: 0; height: 36px; border: 0; outline: 0; background: none; box-shadow: none; padding: 0; font-size: 14px; }
.tg-cats { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 16px 0; }
.tg-cats .chip { padding: 3px 10px; }
.tg-targets { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; padding: 10px 16px; border-bottom: 1px solid var(--line); font-size: 12px; }
.tg-targets .faint { margin-right: 4px; }
.tg-targets button {
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: var(--panel-3);
  color: var(--muted);
  font-size: 12px;
}
.tg-targets button.on { color: var(--text); border-color: var(--accent); background: var(--accent-soft); }
.tg-body { flex: 1; overflow-y: auto; padding: 6px 8px 12px; outline: 0; }
.tg-msg { padding: 24px 12px; text-align: center; line-height: 1.7; }
.tg-foot { padding: 8px 16px 10px; border-top: 1px solid var(--line); color: var(--faint); font-size: 11px; }

.tg-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px;
  border-radius: 8px;
  cursor: pointer;
}
.tg-row:hover { background: var(--panel-2); }
.tg-names { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.tg-en { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tg-cn { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tg-cn.big { font-size: 14px; color: var(--text); white-space: normal; }
.tg-n { color: var(--faint); font: 11px var(--mono); }
.tg-dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.c0 { --c: #4ea8ff; }
.c1 { --c: #ff6b6b; }
.c3 { --c: #c27dff; }
.c4 { --c: #4fd07d; }
.c5 { --c: #f2a541; }
.tg-add {
  flex: none;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  border: 1px solid var(--line-2);
  background: var(--panel-2);
  color: var(--muted);
}
.tg-add:hover { color: var(--text); border-color: var(--accent); }
.tg-add.on { color: var(--ok); border-color: rgba(95, 211, 165, 0.5); background: rgba(95, 211, 165, 0.1); }

.tg-back { display: inline-flex; align-items: center; gap: 2px; margin: 4px 4px 8px; padding: 2px 6px; border: 0; background: none; color: var(--muted); font-size: 12px; }
.tg-back:hover { color: var(--text); }
.tg-detail { display: flex; flex-direction: column; gap: 8px; padding: 0 8px; }
.tg-title { display: flex; align-items: center; gap: 8px; font-size: 17px; word-break: break-word; }
.tg-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; }
.tg-meta a { display: inline-flex; align-items: center; gap: 3px; color: var(--accent); text-decoration: none; }
.tg-meta a:hover { text-decoration: underline; }
.tg-badge { padding: 1px 8px; border-radius: 999px; color: var(--c); background: color-mix(in srgb, var(--c) 14%, transparent); font-weight: 600; }
.tg-alias-of { color: var(--warn); font-size: 12px; }
.tg-actions { display: flex; gap: 8px; margin: 4px 0; }
.tg-main.on { background: rgba(95, 211, 165, 0.16); color: var(--ok); border-color: rgba(95, 211, 165, 0.5); }
.tg-sec { margin-top: 8px; }
.tg-sec-title { margin: 0 0 6px; color: var(--muted); font-size: 12px; font-weight: 600; }
.tg-sec .tg-row { margin: 0 -8px; }
.tg-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip.static { cursor: default; }

@media (max-width: 1180px) { .tag-panel { left: 360px; } }
@media (max-width: 820px) {
  .tag-panel { top: 0; left: 0; right: 0; width: auto; z-index: 60; border-right: 0; }
}

@media (max-width: 1180px) {
  .layout { grid-template-columns: 360px minmax(0, 1fr) 0; }
  .history { display: none; }
}

@media (max-width: 820px) {
  body { overflow: auto; }
  .topbar { padding: 0 12px; }
  .top-stats .stat#stat-queue span:last-child { display: none; }
  #user-name { display: none; }
  .layout { display: flex; flex-direction: column; height: auto; }
  .stage { order: -1; height: 72vh; border-bottom: 1px solid var(--line); }
  .viewer { padding: 12px; }
  .controls { border-right: 0; }
  .controls-scroll { overflow: visible; padding: 4px 16px 12px; }
  .gen-bar { position: sticky; bottom: 0; z-index: 4; }
  .history { display: flex; border-left: 0; border-top: 1px solid var(--line); }
  .hist-grid { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); overflow: visible; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .tools { justify-content: flex-start; }
  .tools .btn span:not(.icon) { display: none; }
}

@media (max-width: 420px) {
  .stat#stat-usage { display: none !important; }
  .top-gallery span:not(.icon) { display: none; }
  .top-gallery { padding: 0 8px; }
  .brand span { display: none; }
}

/* ---------- 标签模式 ---------- */

.prompt-tools { display: flex; align-items: center; gap: 6px; margin: -2px 0 8px; flex-wrap: wrap; }
.prompt-tools .grow { flex: 1; }
.prompt-tools .seg { padding: 2px; }
.prompt-tools .seg button { padding: 2px 10px; font-size: 12px; }
body.tagmode .controls textarea.tag-input { display: none; }
body:not(.tagmode) .tb { display: none; }

.tb {
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  background: var(--bg);
  outline: 0;
  transition: border-color 0.15s;
}
.tb:focus-within { border-color: var(--accent); }
.tb-chips { display: flex; flex-wrap: wrap; gap: 4px; padding: 6px; min-height: 40px; align-content: flex-start; }
.char-texts .tb-chips { min-height: 34px; }
.tb-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  padding: 2px 8px;
  border-radius: 6px;
  border: 1px solid var(--line-2);
  background: var(--panel-2);
  font-size: 12px;
  line-height: 18px;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  touch-action: pan-y;
}
.tb-chip:hover { border-color: #3a3d4a; }
.tb-chip.sel { border-color: var(--accent); background: var(--accent-soft); }
.tb-chip .tb-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tb-chip small { color: var(--faint); font-size: 11px; white-space: nowrap; }
.tb-chip.off { opacity: 0.45; border-style: dashed; }
.tb-chip.off .tb-text { text-decoration: line-through; }
.tb-chip.wild { border-color: rgba(242, 196, 109, 0.45); color: var(--warn); }
/* 权重高亮：加权绿、降权红，--wk 越大越深 */
.tb-chip.up { border-color: color-mix(in srgb, var(--ok) calc(var(--wk) * 75%), var(--line-2)); background: color-mix(in srgb, var(--ok) calc(var(--wk) * 22%), var(--panel-2)); }
.tb-chip.down { border-color: color-mix(in srgb, var(--danger) calc(var(--wk) * 75%), var(--line-2)); background: color-mix(in srgb, var(--danger) calc(var(--wk) * 22%), var(--panel-2)); }
.tb-chip.up.sel, .tb-chip.down.sel { border-color: var(--accent); }
.tb-wt { font: 600 10.5px var(--mono); color: var(--ok); }
.tb-wt.down { color: var(--danger); }
.tb.dragging .tb-chip { cursor: grabbing; }
.tb.dragging .tb-chip.sel { opacity: 0.5; }
.tb-chip.drop-before { box-shadow: -3px 0 0 -1px var(--accent); }
.tb-chip.drop-after { box-shadow: 3px 0 0 -1px var(--accent); }
.tb-add, .tb-edit {
  flex: 1 0 90px;
  width: auto !important;
  min-width: 90px;
  border: 0 !important;
  background: transparent !important;
  padding: 2px 4px !important;
  font-size: 12px;
  box-shadow: none !important;
}
.tb-edit { flex: 0 1 220px; border: 1px solid var(--accent) !important; border-radius: 6px; }
.tb-bar { display: flex; align-items: center; gap: 2px; padding: 2px 4px; border-top: 1px solid var(--line); color: var(--muted); }
.tb-btn {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
}
.tb-btn:hover:not(:disabled) { background: var(--panel-3); color: var(--text); }
.tb-btn:disabled { opacity: 0.3; cursor: default; }
.tb-btn.danger:hover:not(:disabled) { color: var(--danger); }
.tb-sep { width: 1px; height: 14px; background: var(--line-2); margin: 0 4px; }
.tb-sel { display: inline-flex; align-items: center; gap: 2px; }
.tb-w { min-width: 34px; text-align: center; font: 11px var(--mono); }
.tb-count { margin-left: auto; font-size: 11px; color: var(--faint); padding-right: 4px; }
.char-texts .tb-bar { padding: 1px 3px; }

.preset-bar { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.preset-bar .chip { height: 24px; padding: 0 9px; }
.chip.small { height: 24px; padding: 0 9px; }
.chip.dashed { border-style: dashed; }

.char-tools { display: inline-flex; }
.char-tools .icon-btn { width: 24px; height: 24px; }

/* ---------- 个人词库 ---------- */

.modal.lib-modal { width: min(760px, 100%); height: min(760px, calc(100vh - 32px)); }
.lib { display: flex; flex-direction: column; gap: 10px; min-height: 0; flex: 1; }
.lib-modal .modal-body { flex: 1; }
.lib-top { display: flex; align-items: center; gap: 12px; }
.lib-tabs { width: 300px; }
.lib-tabs button small { margin-left: 4px; color: var(--faint); font-size: 11px; }
.lib-status { margin-left: auto; font-size: 11.5px; color: var(--faint); }
.lib-status.ok { color: var(--ok); }
.lib-status.bad { color: var(--danger); }
.lib-pane { display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.lib-tools { display: flex; align-items: center; gap: 6px; }
.lib-tools input { flex: 1; min-width: 0; height: 30px; }
.lib-tools .grow, .lib-form-row .grow { flex: 1; }
.lib-tools .btn.on { border-color: var(--accent); color: var(--text); }
.lib-cats, .lib-targets { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; }
.lib-targets { font-size: 12px; }
.lib-catbar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 8px; background: var(--panel-2); font-size: 12px; }
.lib-catbar .muted { flex: 1; min-width: 160px; }
.lib-batch { display: flex; align-items: center; gap: 6px; font-size: 12px; }
.lib-list { display: flex; flex-direction: column; gap: 4px; }
.lib-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  cursor: pointer;
}
.lib-row:hover { border-color: #3a3d4a; }
.lib-row.in { border-color: rgba(165, 148, 255, 0.45); }
.lib-row.sel { border-color: var(--accent); background: var(--accent-soft); }
.lib-row.preset, .lib-row.snap { cursor: default; }
.lib-row input[type="checkbox"] { accent-color: var(--accent); margin: 0; }
.lib-mark { color: var(--faint); display: inline-grid; }
.lib-row.in .lib-mark { color: var(--accent); }
.lib-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.lib-main b { font-size: 12.5px; font-weight: 600; }
.lib-text { font-size: 12px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; word-break: break-word; }
.lib-text em { font-style: normal; font-size: 11px; color: var(--ok); }
.lib-text em.neg { color: var(--danger); }
.lib-main small { color: var(--faint); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-cat { flex: none; font-size: 11px; padding: 0 6px; border-radius: 5px; background: var(--panel-3); color: var(--muted); }
.lib-acts { display: inline-flex; align-items: center; gap: 2px; flex: none; }
.lib-acts .icon-btn { width: 26px; height: 26px; }
.lib-acts .icon-btn.on { color: var(--accent); }
.lib-empty { padding: 28px 10px; text-align: center; color: var(--faint); font-size: 12.5px; }
.lib-form { display: flex; flex-direction: column; gap: 6px; padding: 10px; border-radius: 10px; border: 1px solid var(--accent); background: var(--panel-2); }
.lib-form-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.lib-form-row input, .lib-form-row select { width: auto; flex: 1 1 140px; height: 30px; padding: 4px 8px; }
.snap-head { display: flex; align-items: center; gap: 8px; }
.snap-head small { margin-left: auto; }
.lib-rename { height: 26px; padding: 2px 6px !important; max-width: 260px; }
.lib-row.snap.auto { opacity: 0.8; }

@media (max-width: 640px) {
  .lib-tabs { width: auto; flex: 1; }
  .lib-top { flex-wrap: wrap; }
  .lib-status { margin-left: 0; }
  .lib-row { flex-wrap: wrap; }
  .lib-acts { margin-left: auto; }
}

/* ---------- 云端图库 ---------- */

.top-gallery { height: 30px; gap: 5px; }
#manage-link { white-space: nowrap; }

.tools .btn.starred { color: var(--accent); }
.tools .btn.starred svg { fill: currentColor; }
.modal.gal-modal { width: min(980px, 100%); }
.gal { display: flex; flex-direction: column; gap: 10px; min-height: 0; flex: 1; }
.gal-usage { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--muted); }
.gal-meter { flex: 1; max-width: 240px; height: 6px; border-radius: 3px; background: var(--panel-3); overflow: hidden; margin-left: auto; }
.gal-meter i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.gal-meter.full i { background: var(--danger); }
.gal-batch { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 12px; padding: 6px 10px; border-radius: 8px; background: var(--panel-2); }
.gal-batch[hidden] { display: none; }
.gal-batch .grow { flex: 1; }
.gal-grid { columns: 160px; column-gap: 8px; }
.gal-grid > .lib-empty, .gal-loadmore { column-span: all; }
.gal-loadmore { display: flex; margin: 4px auto 0; }
.gal-item {
  position: relative;
  break-inside: avoid;
  margin-bottom: 8px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel-2);
  border: 2px solid transparent;
  cursor: pointer;
  transition: border-color 0.15s;
}
.gal-item:hover { border-color: #3a3d4a; }
.gal-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gal-item img:not([src]) { visibility: hidden; }
.gal-item img.broken { visibility: hidden; }
.gal-item .tag { position: absolute; left: 4px; bottom: 4px; font-size: 10.5px; padding: 1px 6px; border-radius: 5px; background: rgba(11, 12, 16, 0.72); color: #ddd; }
.gal-album { position: absolute; right: 4px; bottom: 4px; max-width: 60%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 10.5px; padding: 1px 6px; border-radius: 5px; background: rgba(11, 12, 16, 0.72); color: var(--accent); }
.gal-more {
  position: absolute;
  right: 4px;
  top: 4px;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: 0;
  display: grid;
  place-items: center;
  background: rgba(11, 12, 16, 0.72);
  color: #ddd;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
}
.gal-item:hover .gal-more, .gal-more:focus-visible { opacity: 1; }
.gal-item .chk {
  position: absolute;
  left: 4px;
  top: 4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: none;
  place-items: center;
  border: 1.5px solid rgba(255, 255, 255, 0.75);
  background: rgba(11, 12, 16, 0.45);
  color: transparent;
}
.gal-batch:not([hidden]) ~ .gal-grid .chk { display: grid; }
.gal-batch:not([hidden]) ~ .gal-grid .gal-item { user-select: none; }
.gal-batch:not([hidden]) ~ .gal-grid .gal-item:not(.sel) img { opacity: 0.6; }
.gal-item.sel { border-color: var(--accent); }
.gal-item.sel .chk { background: var(--accent); border-color: var(--accent); color: #14111f; }
@media (hover: none) { .gal-more { opacity: 1; } }
@media (max-width: 640px) {
  .gal-grid { columns: 2; column-gap: 6px; }
  .gal-usage { flex-wrap: wrap; }
  .gal-meter { max-width: none; flex-basis: 100%; margin-left: 0; }
}

/* ---------- 文本模式权重高亮 ---------- */

.hl-wrap { position: relative; border-radius: var(--radius-sm); background: var(--bg); }
body.tagmode .controls .hl-wrap { display: none; }
textarea.hl-ta { position: relative; z-index: 1; background: transparent; display: block; }
.hl-back {
  position: absolute;
  left: 0;
  top: 0;
  box-sizing: border-box;
  border-style: solid;
  border-color: transparent;
  overflow: hidden;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: normal;
  color: transparent;
  pointer-events: none;
}
.hl-back mark { color: transparent; border-radius: 3px; box-decoration-break: clone; -webkit-box-decoration-break: clone; }
.hl-back .hl-up { background: color-mix(in srgb, var(--ok) calc(var(--wk) * 32%), transparent); }
.hl-back .hl-down { background: color-mix(in srgb, var(--danger) calc(var(--wk) * 32%), transparent); }
.hl-back .hl-off { background: rgba(140, 143, 160, 0.16); }

/* ---------- 参考素材库 ---------- */
.asset-bar { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-size: 11.5px; }
.asset-bar .faint { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.ref-name { font-size: 12px; font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ref-thumb.empty { display: grid; place-items: center; color: var(--faint); }
.ref-status.bad { color: var(--danger); }
.ref-top .icon-btn { flex: none; }
.ast-kinds { align-self: flex-start; }
.ast-kinds small { opacity: 0.6; }
.ast-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 8px; align-content: start; }
.ast-grid > .lib-empty { grid-column: 1 / -1; }
.ast-item {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel-2);
  border: 2px solid transparent;
  cursor: pointer;
  transition: border-color 0.15s;
  user-select: none;
}
.ast-item:hover { border-color: #3a3d4a; }
.ast-item.using { border-color: var(--ok); }
.ast-item.sel { border-color: var(--accent); }
.ast-img { position: relative; aspect-ratio: 1; display: grid; place-items: center; background: var(--bg); color: var(--faint); }
.ast-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ast-img img:not([src]), .ast-img img.broken { visibility: hidden; }
.ast-badge { position: absolute; left: 4px; bottom: 4px; font-size: 10.5px; padding: 1px 6px; border-radius: 5px; background: var(--ok); color: #0b0c10; font-weight: 600; }
.ast-name { padding: 5px 7px 6px; font-size: 12px; line-height: 1.35; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ast-name small { display: block; font-size: 10.5px; color: var(--faint); overflow: hidden; text-overflow: ellipsis; }
.ast-item:hover .gal-more, .ast-item .gal-more:focus-visible { opacity: 1; }
.ast-item .chk {
  position: absolute;
  left: 4px;
  top: 4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: none;
  place-items: center;
  border: 1.5px solid rgba(255, 255, 255, 0.75);
  background: rgba(11, 12, 16, 0.45);
  color: transparent;
}
.gal-batch:not([hidden]) ~ .ast-grid .chk { display: grid; }
.gal-batch:not([hidden]) ~ .ast-grid .ast-item:not(.sel) .ast-img { opacity: 0.6; }
.ast-item.sel .chk { background: var(--accent); border-color: var(--accent); color: #14111f; }
@media (max-width: 640px) { .ast-grid { grid-template-columns: repeat(3, 1fr); gap: 6px; } }

/* ---------- 灵感画廊 ---------- */

.modal.bru-modal { width: min(1100px, 100%); }
.bru-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.bru-head .seg { padding: 2px; }
.bru-head .seg button { padding: 4px 12px; font-size: 12.5px; }
.bru-ratings { font-size: 12px; }
.bru-actual { margin-left: 6px; font-size: 11.5px; }
.bru-hint { margin-left: auto; font-size: 11.5px; }
.bru-grid { columns: 180px; }
.bru-item img { height: auto; min-height: 60px; background: var(--panel-3); }
.bru-star { position: absolute; right: 4px; bottom: 4px; display: grid; place-items: center; width: 20px; height: 20px; border-radius: 5px; background: rgba(11, 12, 16, 0.72); color: var(--accent); }
.bru-star svg { fill: currentColor; }
.lib-empty.bad { color: var(--danger); }
.bru-nav { display: flex; align-items: center; gap: 6px; }
.bru-nav .grow, .bru-add .grow { flex: 1; }
.bru-detail { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); gap: 16px; align-items: start; }
.bru-left { display: flex; flex-direction: column; gap: 8px; position: sticky; top: 0; }
.bru-img { width: 100%; max-height: 62vh; object-fit: contain; border-radius: 8px; background: repeating-conic-gradient(#1a1b22 0% 25%, #22232c 0% 50%) 50% / 16px 16px; }
.bru-img:not([src]) { min-height: 240px; }
.bru-facts { font-size: 12px; }
.bru-links { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12.5px; overflow: hidden; }
.bru-links a { color: var(--accent); }
.bru-acts { display: flex; flex-wrap: wrap; gap: 6px; }
.bru-acts .btn.on { color: var(--accent); border-color: var(--accent); }
.bru-acts .btn.on svg { fill: currentColor; }
.bru-right { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.bru-group-head { display: flex; align-items: center; gap: 8px; font-size: 12.5px; margin-bottom: 5px; }
.bru-tags { display: flex; flex-wrap: wrap; gap: 5px; }
.bru-tag { height: auto; min-height: 24px; gap: 5px; }
.bru-tag small:empty { display: none; }
.bru-tag.c-artist span { color: #ff9b8a; }
.bru-tag.c-character span { color: #8be0a4; }
.bru-tag.c-copyright span { color: #d59bff; }
.bru-tag.c-meta span { color: #f2c46d; }
.bru-add { position: sticky; bottom: -16px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 10px 0; background: var(--panel); border-top: 1px solid var(--line); font-size: 12px; }
.bru-target { height: 28px; width: auto; flex: 0 0 auto; min-width: 84px; }
@media (max-width: 760px) {
  .bru-detail { grid-template-columns: 1fr; }
  .bru-left { position: static; }
  .bru-hint { display: none; }
  .bru-grid { columns: 130px; }
}
@media (max-width: 420px) {
  .top-stats { gap: 5px; }
  .top-stats .tier { display: none; }
  .user { margin-left: 0; gap: 6px; }
}
