:root {
  --bg: #f6f5fb;
  --panel: #ffffff;
  --border: #e8e6f0;
  --border-strong: #d8d4e6;
  --text: #1a1a2e;
  --muted: #6b7088;
  --accent: #7c5bff;
  --accent-soft: #efeaff;
  --ok: #16a34a;
  --warn: #f59e0b;
  --err: #ef4444;
  --shadow: 0 2px 12px rgba(60, 50, 110, 0.06);
  --radius: 14px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.page { max-width: 1080px; margin: 0 auto; padding: 24px 20px 80px; }

/* ===== 顶部 ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 16px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo-box {
  width: 38px; height: 38px;
  background: linear-gradient(135deg, #7c5bff, #5b8cff);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow);
}
.brand h1 { font-size: 20px; font-weight: 700; margin: 0; }
.badge {
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
}
.meta { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.meta-item { font-size: 13px; }
.meta-item .lbl { color: var(--muted); }
.meta-item span:last-child { font-weight: 600; }
.key-input {
  display: flex; align-items: center;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
}
.key-input input {
  border: 0; outline: 0; background: transparent;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 13px;
  padding: 6px 10px;
  width: 220px;
  color: var(--text);
}
.key-clear {
  border: 0; background: transparent; cursor: pointer;
  color: var(--muted); font-size: 18px; line-height: 1;
  width: 24px; height: 24px;
  border-radius: 4px;
}
.key-clear:hover { background: var(--border); color: var(--text); }

/* ===== 主面板 ===== */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  margin-bottom: 28px;
}

.tabs { display: flex; gap: 10px; margin-bottom: 16px; }
.tab {
  flex: 1;
  padding: 14px 20px;
  border: 0;
  background: var(--bg);
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s;
}
.tab.active { background: var(--panel); color: var(--text); box-shadow: 0 1px 4px rgba(60,50,110,0.08); border: 1px solid var(--border); }
.tab:hover:not(.active) { color: var(--text); }

.ref-area {
  display: flex; gap: 10px; align-items: flex-start;
  margin-bottom: 12px;
}
.ref-preview {
  position: relative;
  min-height: 90px;
  flex: 1;
  border: 2px dashed var(--border-strong);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  background: var(--bg);
  transition: border-color 0.15s;
  overflow: hidden;
  padding: 10px;
}
.ref-preview:hover { border-color: var(--accent); }
.ref-preview.has-image { border-style: solid; border-color: var(--border); padding: 4px; }
.ref-preview img { max-width: 100%; max-height: 200px; border-radius: 6px; display: block; }
.ref-preview .empty { color: var(--muted); font-size: 13px; }
.ref-clear {
  align-self: center;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
}
.ref-clear:hover { color: var(--err); border-color: var(--err); }

#prompt {
  width: 100%;
  min-height: 96px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  font-family: inherit;
  font-size: 14px;
  resize: vertical;
  outline: 0;
  color: var(--text);
  background: var(--panel);
  margin-bottom: 18px;
}
#prompt:focus { border-color: var(--accent); }

.opt-block { margin-bottom: 16px; }
.opt-label { font-size: 13px; color: var(--text); font-weight: 600; margin-bottom: 8px; }
.opt-label .hint-inline {
  font-weight: 400;
  font-size: 11px;
  color: var(--muted);
  font-family: ui-monospace, monospace;
  margin-left: 6px;
}
.chip small {
  display: block;
  font-size: 10px;
  color: var(--muted);
  font-family: ui-monospace, monospace;
  margin-top: 2px;
}
.chip.active small { color: var(--accent); opacity: 0.7; }
.adv-grid code {
  font-size: 11px;
  color: var(--muted);
  background: var(--bg);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: ui-monospace, monospace;
}
.adv-grid input[type="range"] { padding: 0; }
.opt-row { display: grid; grid-template-columns: 2fr 1fr; gap: 24px; margin-bottom: 8px; }

.chip-group { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 7px 14px;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text);
  transition: all 0.12s;
  font-weight: 500;
  min-width: 44px;
}
.chip:hover { border-color: var(--border-strong); }
.chip.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: transparent;
  font-weight: 600;
}
.chip-2line {
  display: inline-flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 8px 18px;
  min-width: 80px;
  line-height: 1.2;
}
.chip-2line b { font-size: 15px; font-weight: 600; }
.chip-2line span { font-size: 11px; opacity: 0.8; }

/* 高级 */
.advanced {
  border-top: 1px solid var(--border);
  margin-top: 8px;
  padding-top: 12px;
}
.advanced summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
  padding: 6px 0;
  list-style: none;
}
.advanced summary::-webkit-details-marker { display: none; }
.advanced summary::before { content: '› '; display: inline-block; transition: transform 0.2s; }
.advanced[open] summary::before { transform: rotate(90deg); }
.adv-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-top: 12px;
  padding: 12px;
  background: var(--bg);
  border-radius: 10px;
}
.adv-grid label { display: block; }
.adv-grid label span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.adv-grid input, .adv-grid select {
  width: 100%; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 6px;
  font-family: inherit; font-size: 13px;
  background: var(--panel); color: var(--text);
}

/* 生成按钮 */
.gen-row {
  display: flex; align-items: center; gap: 14px;
  margin-top: 18px;
}
button.primary {
  background: var(--accent);
  color: white;
  border: 0;
  padding: 12px 28px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
button.primary:hover:not(:disabled) { opacity: 0.92; }
button.primary:disabled { opacity: 0.4; cursor: not-allowed; }
button.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 11px 20px;
  border-radius: 10px;
  font-size: 14px;
  cursor: pointer;
}
button.ghost:hover { border-color: var(--err); color: var(--err); }
.hotkey {
  color: var(--muted);
  font-size: 12px;
  font-family: ui-monospace, monospace;
}
.status {
  margin-left: auto;
  font-size: 13px;
  color: var(--muted);
  font-family: ui-monospace, monospace;
}
.status.ok { color: var(--ok); }
.status.warn { color: var(--warn); }
.status.err { color: var(--err); }

.progress {
  margin-top: 14px;
  background: var(--bg);
  border-radius: 10px;
  padding: 12px 14px;
}
.progress-head {
  display: flex; justify-content: space-between;
  font-size: 12px; color: var(--muted);
  margin-bottom: 8px;
  font-family: ui-monospace, monospace;
}
.progress-bar {
  height: 4px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}
#progressFill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #5b8cff);
  width: 0%;
  transition: width 0.3s;
}

/* ===== 历史记录 ===== */
.history-head {
  display: flex; align-items: baseline;
  justify-content: space-between;
  margin-bottom: 14px;
}
.history-title { font-size: 16px; font-weight: 700; }
.history-title .count { color: var(--muted); font-weight: 400; font-size: 13px; }
.history-clear {
  border: 0; background: transparent;
  color: var(--err);
  font-size: 13px;
  cursor: pointer;
  font-weight: 500;
}
.history-clear:hover { text-decoration: underline; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}
.card:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(60,50,110,0.1); }
.card .img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  background: var(--bg);
  display: block;
}
.card .info { padding: 12px; }
.card .title {
  font-size: 13px; font-weight: 500;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; line-height: 1.4;
  margin-bottom: 6px;
  min-height: 36px;
}
.card .meta-line {
  font-size: 11px; color: var(--muted);
  display: flex; gap: 6px; flex-wrap: wrap;
  font-family: ui-monospace, monospace;
}
.card .meta-line .dot { opacity: 0.5; }
.card .cost { color: var(--ok); font-weight: 600; }
.empty-history {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--muted);
  padding: 40px 20px;
  font-size: 13px;
}

/* ===== 大图预览 ===== */
.lightbox {
  position: fixed; inset: 0;
  background: rgba(15, 15, 30, 0.85);
  display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 14px;
  z-index: 1000;
  padding: 30px;
}
.lightbox img { max-width: 95vw; max-height: 80vh; border-radius: 8px; }
.lightbox .close {
  position: absolute; top: 16px; right: 20px;
  background: rgba(255,255,255,0.1); color: white;
  border: 0; width: 36px; height: 36px;
  border-radius: 50%;
  font-size: 22px;
  cursor: pointer;
}
.lightbox .close:hover { background: rgba(255,255,255,0.2); }
.lb-meta { color: rgba(255,255,255,0.7); font-size: 12px; font-family: ui-monospace, monospace; }
.lb-meta a { color: var(--accent); }

@media (max-width: 720px) {
  .opt-row { grid-template-columns: 1fr; }
  .adv-grid { grid-template-columns: 1fr; }
  .key-input input { width: 160px; }
  .meta { gap: 10px; }
}
