:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --line: #e4e7ec;
  --text: #1b1f24;
  --muted: #6b7280;
  --accent: #8b5cf6;
  --accent-2: #6d5ae0;
  --accent-soft: #f1ecff;
  --danger: #e5484d;
  --ok: #0ca678;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 8px 24px rgba(16,24,40,.06);
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  font-family: -apple-system, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  background: var(--bg); color: var(--text);
  -webkit-font-smoothing: antialiased;
}
body { display: flex; flex-direction: column; }
button { font-family: inherit; cursor: pointer; }
.hidden { display: none !important; }
.grow { flex: 1; }

/* ---------- 顶栏 ---------- */
.topbar {
  height: 52px; flex: 0 0 52px; display: flex; align-items: center; gap: 8px;
  padding: 0 12px; background: var(--panel);
  border-bottom: 1px solid var(--line); position: relative; z-index: 20;
}
.brand { font-weight: 700; font-size: 16px; letter-spacing: .2px; }
.brand span { color: var(--accent); }
.tb-btn {
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
  border-radius: 8px; padding: 7px 12px; font-size: 13px; font-weight: 600;
}
.tb-btn:active { background: var(--bg); }

/* ---------- 模式切换 ---------- */
.modes {
  display: flex; gap: 8px; padding: 10px 12px 4px; background: var(--bg);
}
.mode {
  flex: 1; padding: 10px 0; border-radius: 10px; font-size: 14px; font-weight: 600;
  border: 1px solid var(--line); background: var(--panel); color: var(--muted);
}
.mode.on {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent; color: #fff;
  box-shadow: 0 4px 14px rgba(139,92,246,.35);
}

/* ---------- 主区 ---------- */
.pane { flex: 1; overflow-y: auto; padding: 10px 12px 90px; -webkit-overflow-scrolling: touch; }
section { margin-bottom: 14px; }

textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 12px;
  padding: 12px; font-size: 14px; line-height: 1.6; font-family: inherit;
  background: var(--panel); color: var(--text); resize: vertical; outline: none;
}
textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0 2px; }
.chip {
  border: 1px solid var(--line); background: var(--panel); color: var(--muted);
  border-radius: 999px; padding: 6px 12px; font-size: 12.5px;
}
.chip:active, .chip.on { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

.row { display: flex; gap: 10px; margin: 10px 0; }
.fld { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.fld > span { font-size: 12px; color: var(--muted); font-weight: 600; }
.fld select {
  border: 1px solid var(--line); border-radius: 10px; background: var(--panel);
  padding: 10px 8px; font-size: 13px; color: var(--text); outline: none;
}

.gen-btn {
  width: 100%; padding: 14px 0; border: none; border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; font-size: 15.5px; font-weight: 700; letter-spacing: 1px;
  box-shadow: 0 6px 18px rgba(139,92,246,.35);
}
.gen-btn:active { transform: scale(.985); }
.gen-btn:disabled { opacity: .55; }

/* ---------- 上传区 ---------- */
.drop {
  position: relative; border: 1.5px dashed #cfc6f2; border-radius: 14px;
  background: var(--panel); min-height: 170px; display: flex;
  align-items: center; justify-content: center; margin-bottom: 10px;
  overflow: hidden; cursor: pointer;
}
.drop.drag { border-color: var(--accent); background: var(--accent-soft); }
.drop-in { text-align: center; color: var(--muted); font-size: 13.5px; padding: 18px; }
.drop-ico {
  width: 46px; height: 46px; margin: 0 auto 10px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  font-size: 24px; line-height: 46px; font-weight: 300;
}
.drop-sub { font-size: 12px; margin-top: 6px; color: #9aa1ab; }
#srcPrev { max-width: 100%; max-height: 300px; object-fit: contain; }
.drop-x {
  position: absolute; top: 8px; right: 8px; border: none; border-radius: 8px;
  background: rgba(0,0,0,.55); color: #fff; padding: 6px 10px; font-size: 12px;
}

/* ---------- 结果区 ---------- */
#resultArea { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.res-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.res-head span { font-weight: 700; font-size: 14px; }
.link-btn { border: none; background: none; color: var(--accent); font-size: 13px; font-weight: 600; padding: 6px 4px; }

.loading { text-align: center; padding: 34px 0 26px; }
.spinner {
  width: 40px; height: 40px; margin: 0 auto 14px; border-radius: 50%;
  border: 3.5px solid var(--accent-soft); border-top-color: var(--accent);
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loadText { color: var(--muted); font-size: 13px; }

#resImg { width: 100%; border-radius: 10px; display: block; }
.res-acts { display: flex; gap: 8px; margin-top: 12px; }
.act {
  flex: 1; padding: 11px 0; border-radius: 10px; font-size: 13px; font-weight: 600;
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
}
.act:active { background: var(--bg); }
.act.danger { color: var(--danger); border-color: #f3c8c9; }
.act.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; border: none; }
.res-prompt { font-size: 12px; color: var(--muted); margin: 10px 2px 0; line-height: 1.5; word-break: break-all; }

/* ---------- 历史 ---------- */
.his-head { font-weight: 700; font-size: 14px; margin: 16px 2px 10px; }
.his-count { color: var(--muted); font-weight: 400; font-size: 12.5px; }
.his-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.his-cell { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--panel); border: 1px solid var(--line); cursor: pointer; }
.his-cell img { width: 100%; height: 100%; object-fit: cover; display: block; }
.his-empty { color: #b0b6bf; font-size: 13px; text-align: center; padding: 26px 0 8px; }

/* ---------- 弹层 ---------- */
.layer {
  position: fixed; inset: 0; z-index: 100; background: rgba(15,17,21,.45);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  width: 100%; max-width: 560px; background: var(--panel);
  border-radius: 18px 18px 0 0; padding: 14px 16px 30px;
  max-height: 86vh; overflow-y: auto;
}
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.sheet-head b { font-size: 15.5px; }

.set-sec { border-top: 1px solid var(--line); padding: 14px 0 6px; }
.set-sec:first-of-type { border-top: none; }
.set-title { font-weight: 700; font-size: 14px; margin-bottom: 10px; }
.key-state { float: right; font-size: 12px; font-weight: 600; color: var(--muted); }
.key-state.ok { color: var(--ok); }
.set-sec input, .set-sec select {
  width: 100%; border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 12px; font-size: 13px; background: var(--panel); color: var(--text); outline: none;
  font-family: ui-monospace, Menlo, Consolas, monospace;
}
.set-sec input:focus, .set-sec select:focus { border-color: var(--accent); }
.set-btns { display: flex; gap: 10px; margin-top: 10px; }
.btn { flex: 1; padding: 11px 0; border-radius: 10px; font-size: 13.5px; font-weight: 600; border: 1px solid var(--line); background: var(--panel); color: var(--text); }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; border: none; }
.btn.danger { color: var(--danger); }
.set-msg { font-size: 12.5px; margin: 8px 0 0; line-height: 1.6; word-break: break-all; }
.set-msg.ok { color: var(--ok); }
.set-msg.err { color: var(--danger); }
.set-tip { font-size: 12px; color: var(--muted); margin: 8px 0 0; line-height: 1.6; }

/* ---------- 安装引导 ---------- */
.inst-body { padding: 4px 0; }
.inst-steps { font-size: 13.5px; line-height: 1.9; color: var(--text); }
.inst-steps b { color: var(--accent); }
.inst-qr { text-align: center; margin: 14px 0; }
.inst-qr img { width: 148px; height: 148px; border-radius: 10px; }
.inst-qr-tip { font-size: 12px; color: var(--muted); margin-top: 8px; }
.inst-profile { margin-top: 12px; }
.inst-profile .btn { width: 100%; margin-bottom: 8px; }

/* ---------- 查看大图 ---------- */
.viewer { align-items: center; }
#viewImg { max-width: 94vw; max-height: 68vh; border-radius: 12px; }
.view-acts { position: fixed; bottom: 0; left: 0; right: 0; display: flex; gap: 8px; padding: 12px 14px 26px; background: linear-gradient(transparent, rgba(0,0,0,.55)); }
.view-acts .act { background: rgba(255,255,255,.92); border: none; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 78px; transform: translateX(-50%);
  background: rgba(20,22,28,.92); color: #fff; font-size: 13px; line-height: 1.6;
  padding: 10px 18px; border-radius: 999px; max-width: 84vw; text-align: center;
  z-index: 300; animation: fadeUp .25s ease;
}
.toast.err { background: var(--danger); }
@keyframes fadeUp { from { opacity: 0; transform: translate(-50%, 8px); } }

@media (min-width: 640px) {
  .pane { max-width: 620px; margin: 0 auto; }
  .layer { align-items: center; }
  .sheet { border-radius: 18px; margin-bottom: 6vh; }
}
