:root {
  --bg: #0a0a0f;
  --bg-2: #12121a;
  --panel: rgba(24, 24, 34, 0.86);
  --line: rgba(255, 255, 255, 0.08);
  --text: #eef0f6;
  --muted: #8b90a3;
  --accent: #ff4d8d;
  --accent-2: #7b5cff;
  --ok: #35d07f;
  --err: #ff5f56;
  --radius: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(1200px 700px at 15% -10%, #1b1030 0%, transparent 55%),
              radial-gradient(1000px 700px at 90% 0%, #2a0f24 0%, transparent 50%),
              var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  min-height: 100vh;
}

.app { max-width: 1560px; margin: 0 auto; padding: 18px 20px 60px; }

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 10px 4px 20px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 40px; height: 40px; display: grid; place-items: center;
  border-radius: 12px; font-size: 20px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 24px rgba(255, 77, 141, 0.28);
}
.brand h1 { margin: 0; font-size: 17px; letter-spacing: 0.3px; }
.brand .sub { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.top-actions { display: flex; align-items: center; gap: 10px; }
.dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--muted);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.04);
}
.dot.ok { background: var(--ok); box-shadow: 0 0 12px rgba(53, 208, 127, 0.7); }
.dot.err { background: var(--err); box-shadow: 0 0 12px rgba(255, 95, 86, 0.7); }
.status-text { font-size: 12px; color: var(--muted); }
.icon-btn {
  width: 34px; height: 34px; border-radius: 10px; cursor: pointer;
  background: rgba(255, 255, 255, 0.06); color: var(--text);
  border: 1px solid var(--line); font-size: 15px;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.12); }

/* ---------- 布局 ---------- */
.layout {
  display: grid; grid-template-columns: 380px minmax(0, 1fr); gap: 18px;
  align-items: start;
}
.panel {
  position: sticky; top: 14px;
  background: var(--panel); backdrop-filter: blur(18px);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; max-height: calc(100vh - 40px); overflow-y: auto;
}
.panel::-webkit-scrollbar, .results::-webkit-scrollbar { width: 8px; }
.panel::-webkit-scrollbar-thumb, .results::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12); border-radius: 6px;
}

.field { margin-bottom: 14px; }
.field > label {
  display: block; font-size: 12px; color: var(--muted);
  margin-bottom: 6px; letter-spacing: 0.4px;
}
.label-row { display: flex; align-items: center; justify-content: space-between; }
.label-row label { font-size: 12px; color: var(--muted); letter-spacing: 0.4px; }

textarea, select, input[type="text"], input:not([type]), .modal input {
  width: 100%; background: rgba(8, 8, 14, 0.85); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 11px;
  font-family: inherit; font-size: 13px; line-height: 1.55; resize: vertical;
  outline: none; transition: border-color 0.15s, box-shadow 0.15s;
}
textarea:focus, select:focus, input:focus {
  border-color: rgba(255, 77, 141, 0.55);
  box-shadow: 0 0 0 3px rgba(255, 77, 141, 0.12);
}
select { cursor: pointer; }

.mini-btn {
  background: rgba(255, 255, 255, 0.07); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 5px 9px; font-size: 12px; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; gap: 4px;
}
.mini-btn:hover { background: rgba(255, 255, 255, 0.14); }
.mini-btn.danger:hover { background: rgba(255, 95, 86, 0.22); border-color: rgba(255, 95, 86, 0.5); }

.primary {
  width: 100%; padding: 13px; border: none; border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; font-size: 14px; font-weight: 600; cursor: pointer;
  letter-spacing: 0.5px; box-shadow: 0 10px 28px rgba(255, 77, 141, 0.26);
  transition: transform 0.12s, filter 0.15s;
}
.primary:hover { filter: brightness(1.08); }
.primary:active { transform: translateY(1px); }
.primary:disabled { filter: grayscale(0.6) brightness(0.7); cursor: not-allowed; }
.primary.small { width: auto; padding: 9px 18px; font-size: 13px; }

.hint { margin-top: 10px; font-size: 12px; color: var(--muted); min-height: 16px; line-height: 1.5; }
.hint.err { color: var(--err); }

/* ---------- chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 5px 10px; border-radius: 999px; cursor: pointer; font-size: 12px;
  background: rgba(255, 255, 255, 0.06); border: 1px solid var(--line);
  color: #d6d9e6; transition: all 0.14s; user-select: none;
}
.chip:hover { background: rgba(255, 77, 141, 0.18); border-color: rgba(255, 77, 141, 0.45); }
.chip.tpl { background: rgba(123, 92, 255, 0.14); border-color: rgba(123, 92, 255, 0.35); }
.chip.tpl:hover { background: rgba(255, 77, 141, 0.24); }

#tagGroups details {
  border: 1px solid var(--line); border-radius: 10px;
  margin-bottom: 6px; background: rgba(255, 255, 255, 0.02);
}
#tagGroups summary {
  cursor: pointer; padding: 8px 10px; font-size: 12px; color: #c8ccdb;
  list-style: none;
}
#tagGroups summary::-webkit-details-marker { display: none; }
#tagGroups summary::before { content: "▸ "; color: var(--muted); }
#tagGroups details[open] summary::before { content: "▾ "; }
#tagGroups .chips { padding: 0 10px 10px; }

/* ---------- 分段选择 ---------- */
.seg { display: flex; flex-wrap: wrap; gap: 5px; }
.seg button {
  flex: 1 1 auto; min-width: 44px; padding: 7px 6px; font-size: 12px;
  border-radius: 9px; cursor: pointer; color: #cfd3e2;
  background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line);
}
.seg button.active {
  background: linear-gradient(135deg, rgba(255, 77, 141, 0.9), rgba(123, 92, 255, 0.9));
  border-color: transparent; color: #fff; font-weight: 600;
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ---------- 参考图 ---------- */
.refs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.ref-item { position: relative; width: 64px; height: 64px; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); }
.ref-item img { width: 100%; height: 100%; object-fit: cover; }
.ref-item button {
  position: absolute; top: 2px; right: 2px; width: 18px; height: 18px;
  border-radius: 50%; border: none; cursor: pointer; font-size: 11px;
  background: rgba(0, 0, 0, 0.7); color: #fff; line-height: 1;
}
.drop {
  display: block; text-align: center; padding: 14px; cursor: pointer;
  border: 1px dashed rgba(255, 255, 255, 0.18); border-radius: 10px;
  color: var(--muted); font-size: 12px; transition: all 0.15s;
}
.drop:hover, .drop.over { border-color: var(--accent); color: var(--accent); background: rgba(255, 77, 141, 0.06); }

/* ---------- 结果区 ---------- */
.results { min-width: 0; }
.results-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.results-head h2 { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: 0.3px; }
.results-actions { display: flex; align-items: center; gap: 10px; }
.muted { color: var(--muted); font-size: 12px; }

.progress-wrap { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.progress { flex: 1; height: 6px; border-radius: 6px; background: rgba(255, 255, 255, 0.08); overflow: hidden; }
.progress-bar {
  height: 100%; width: 0%; border-radius: 6px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.35s ease;
}

.grid-results {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
}
.card {
  position: relative; border-radius: 12px; overflow: hidden; cursor: zoom-in;
  background: rgba(255, 255, 255, 0.04); border: 1px solid var(--line);
  aspect-ratio: 1 / 1;
}
.card img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform 0.35s; }
.card:hover img { transform: scale(1.04); }
.card .badge {
  position: absolute; left: 8px; bottom: 8px; padding: 3px 7px;
  border-radius: 6px; font-size: 10px; color: #fff;
  background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(4px);
  max-width: calc(100% - 16px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.card.skeleton {
  display: grid; place-items: center; cursor: default;
  background: linear-gradient(110deg, rgba(255,255,255,0.04) 25%, rgba(255,255,255,0.09) 37%, rgba(255,255,255,0.04) 63%);
  background-size: 400% 100%; animation: shimmer 1.4s ease infinite;
  color: var(--muted); font-size: 12px;
}
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
.empty {
  padding: 40px 16px; text-align: center; color: var(--muted); font-size: 13px;
  border: 1px dashed rgba(255, 255, 255, 0.1); border-radius: 12px;
}
.hidden { display: none !important; }

/* ---------- 大图 ---------- */
.lightbox {
  position: fixed; inset: 0; z-index: 60; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px;
  background: rgba(4, 4, 8, 0.94); backdrop-filter: blur(8px); padding: 22px;
}
.lightbox img { max-width: min(94vw, 1200px); max-height: 76vh; border-radius: 12px; object-fit: contain; }
.lb-close {
  position: absolute; top: 16px; right: 20px; width: 36px; height: 36px;
  border-radius: 50%; border: 1px solid var(--line); cursor: pointer;
  background: rgba(255, 255, 255, 0.08); color: #fff; font-size: 15px;
}
.lb-bar { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; justify-content: center; max-width: 94vw; }
.lb-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- 弹窗 ---------- */
.modal {
  position: fixed; inset: 0; z-index: 70; display: grid; place-items: center;
  background: rgba(4, 4, 8, 0.8); backdrop-filter: blur(6px); padding: 20px;
}
.modal-card {
  width: min(420px, 100%); background: #15151f; border: 1px solid var(--line);
  border-radius: 16px; padding: 20px;
}
.modal-card h3 { margin: 0 0 16px; font-size: 15px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }

/* ---------- 移动端 ---------- */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .panel { position: static; max-height: none; }
  .app { padding: 12px 12px 40px; }
  .grid-results { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
}

/* ---------- 模式切换 ---------- */
.tabs {
  grid-column: 1 / -1;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
}
.tab-list { display: flex; gap: 6px; flex-wrap: wrap; }
.tab {
  padding: 9px 18px; border-radius: 999px; cursor: pointer; font-size: 13px;
  background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line); color: #cfd3e2;
}
.tab.active {
  background: linear-gradient(135deg, rgba(255, 77, 141, 0.95), rgba(123, 92, 255, 0.95));
  border-color: transparent; color: #fff; font-weight: 600;
}
.model-pick {
  min-width: 260px; padding: 9px 12px; border-radius: 10px; font-size: 12px;
  background: rgba(255, 255, 255, 0.06); border: 1px solid var(--line); color: var(--text);
}
.mode-note {
  margin: 0 0 14px; padding: 10px 12px; border-radius: 10px;
  font-size: 12px; line-height: 1.65; color: var(--muted);
  background: rgba(123, 92, 255, 0.10); border: 1px solid rgba(123, 92, 255, 0.22);
}
.mode-note b { color: #d9c8ff; }

/* ---------- 换脸槽位 ---------- */
.slot-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.slot {
  position: relative; aspect-ratio: 3 / 4; border-radius: 12px; overflow: hidden;
  border: 1px dashed rgba(255, 255, 255, 0.18); background: rgba(255, 255, 255, 0.03);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.slot.over { border-color: var(--accent); background: rgba(255, 77, 141, 0.10); }
.slot img { width: 100%; height: 100%; object-fit: cover; display: none; }
.slot.filled img { display: block; }
.slot.filled .slot-empty { display: none; }
.slot-empty { text-align: center; color: var(--muted); font-size: 12px; }
.slot-empty span { display: block; font-size: 22px; line-height: 1.3; }
.slot-empty em { font-style: normal; }
.slot-clear {
  position: absolute; top: 6px; right: 6px; width: 22px; height: 22px;
  border-radius: 50%; border: none; cursor: pointer; display: none;
  background: rgba(0, 0, 0, 0.65); color: #fff; font-size: 11px; line-height: 1;
}
.slot.filled .slot-clear { display: block; }
.row-2 { display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: center; }
.tiny { font-size: 11px; }
.field.tight { margin-bottom: 0; }
