:root {
  --bg: #0e0f14;
  --bg-soft: #161821;
  --card: #1b1e29;
  --border: #2a2e3e;
  --text: #e7e9f0;
  --text-dim: #9aa0b4;
  --text-faint: #6b7186;
  --accent: #7c5cff;
  --accent-2: #4f8cff;
  --accent-grad: linear-gradient(135deg, #7c5cff 0%, #4f8cff 100%);
  --danger: #ff5c6c;
  --ok: #34d399;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent-2); }

/* ---------- topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: rgba(14, 15, 20, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { font-size: 18px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.logo { font-size: 20px; }
.icon-btn {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  width: 40px; height: 40px;
  border-radius: 10px;
  font-size: 18px;
  cursor: pointer;
  transition: 0.15s;
}
.icon-btn:hover { border-color: var(--accent); }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.topbar-link {
  color: var(--text-dim);
  font-size: 13.5px;
  text-decoration: none;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  transition: 0.15s;
  white-space: nowrap;
}
.topbar-link:hover { color: var(--text); border-color: var(--accent); background: rgba(124, 92, 255, 0.08); }
@media (max-width: 420px) {
  .brand { font-size: 16px; }
  .topbar-link { padding: 6px 9px; font-size: 12.5px; }
}

/* ---------- layout ---------- */
main { max-width: 1180px; margin: 0 auto; padding: 20px; }
.layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: start;
}
.col-right { display: flex; flex-direction: column; gap: 20px; }
@media (max-width: 880px) {
  .layout { grid-template-columns: 1fr; }
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 14px; font-size: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; }
.card-head h2 { margin: 0; }

/* ---------- settings modal (独立弹窗) ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(6, 7, 12, 0.66);
  backdrop-filter: blur(4px);
}
.modal-dialog {
  position: relative;
  width: 100%;
  max-width: 440px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  padding: 20px;
  animation: modal-pop 0.16s ease-out;
}
@keyframes modal-pop {
  from { transform: translateY(8px) scale(0.98); opacity: 0; }
  to { transform: none; opacity: 1; }
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 6px;
}
.modal-head h2 { margin: 0; font-size: 16px; }
.modal-close {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--text-dim);
  width: 30px;
  height: 30px;
  border-radius: 8px;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  transition: 0.15s;
}
.modal-close:hover { color: var(--text); border-color: var(--accent); }
.hint { color: var(--text-faint); font-size: 12.5px; margin: 0 0 12px; }

/* ---------- history viewer ---------- */
.viewer-dialog { max-width: min(900px, 92vw); }
.viewer-body {
  margin: 4px 0 8px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 160px;
  max-height: 72vh;
  overflow: hidden;
}
.viewer-body img { max-width: 100%; max-height: 70vh; display: block; object-fit: contain; }
.viewer-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.field-label { display: block; font-size: 13px; color: var(--text-dim); margin: 14px 0 8px; }
.input-row { display: flex; gap: 8px; }
input[type="password"], input[type="text"], textarea {
  flex: 1;
  width: 100%;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border 0.15s;
}
input:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 90px; line-height: 1.5; }
.toggle-btn {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: var(--radius-sm);
  padding: 0 14px;
  cursor: pointer;
  transition: 0.15s;
}
.toggle-btn:hover { color: var(--text); border-color: var(--accent); }
.settings-actions { display: flex; align-items: center; gap: 12px; margin-top: 16px; }
.status-dot { font-size: 12.5px; color: var(--text-faint); }
.status-dot.ok { color: var(--ok); }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: 14px;
  cursor: pointer;
  transition: 0.15s;
  font-family: inherit;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary {
  background: var(--accent-grad);
  border: none;
  color: #fff;
  font-weight: 600;
}
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.big { width: 100%; padding: 13px; font-size: 15px; margin-top: 18px; }
.btn.small { padding: 6px 10px; font-size: 12.5px; }
.btn.right { margin-left: auto; }

.prompt-actions { display: flex; gap: 8px; margin-top: 8px; }

/* ---------- segmented ---------- */
.seg {
  display: flex;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px;
  gap: 4px;
}
.seg-btn {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-dim);
  padding: 9px 0;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
  transition: 0.15s;
}
.seg-btn.active { background: var(--accent-grad); color: #fff; font-weight: 600; }

/* ---------- upload ---------- */
.upload { margin-bottom: 4px; }
.dropzone {
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 22px;
  text-align: center;
  color: var(--text-dim);
  cursor: pointer;
  transition: 0.15s;
  font-size: 13px;
}
.dropzone:hover, .dropzone.drag { border-color: var(--accent); color: var(--text); background: rgba(124, 92, 255, 0.06); }
.dz-icon { font-size: 26px; margin-bottom: 6px; }
.preview-wrap { margin-top: 10px; position: relative; }
.preview-wrap img { max-width: 100%; max-height: 240px; border-radius: var(--radius-sm); border: 1px solid var(--border); display: block; }
.preview-wrap .btn { margin-top: 8px; }

/* ---------- ratio grid ---------- */
.ratio-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
}
@media (max-width: 560px) {
  .ratio-grid { grid-template-columns: repeat(4, 1fr); }
}
.ratio-btn {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 4px;
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-family: inherit;
  transition: 0.15s;
}
.ratio-btn:hover { border-color: var(--accent); color: var(--text); }
.ratio-btn.active { border-color: var(--accent); color: var(--text); background: rgba(124, 92, 255, 0.12); }
.ratio-btn .shape {
  background: var(--border);
  border-radius: 3px;
  width: 26px;
  max-height: 26px;
}
.ratio-btn.active .shape { background: var(--accent); }

/* ---------- error / toast ---------- */
.error {
  margin-top: 14px;
  background: rgba(255, 92, 108, 0.12);
  border: 1px solid rgba(255, 92, 108, 0.4);
  color: #ffb3bd;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
}
.toast {
  position: fixed;
  left: 50%;
  bottom: 30px;
  transform: translateX(-50%);
  background: #2a2e3e;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 11px 18px;
  border-radius: 10px;
  font-size: 14px;
  box-shadow: var(--shadow);
  z-index: 70;
  opacity: 0.97;
}

/* ---------- result ---------- */
/* 结果卡不使用 sticky：sticky 会遮挡其后跟随的历史记录（滚动时历史上滑到结果卡背后），
   且结果图较高时底部操作按钮会被挤出视口无法点击。改为随页面自然滚动。 */
.result-area {
  min-height: 240px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.result-area img { max-width: 100%; max-height: 70vh; display: block; }
.placeholder-text { color: var(--text-faint); font-size: 13px; }
.result-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 12px; }
.meta { color: var(--text-faint); font-size: 12px; margin-left: auto; }
.spinner {
  width: 38px; height: 38px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.loading-text { color: var(--text-dim); font-size: 13px; margin-left: 12px; }
.loading-wrap { display: flex; align-items: center; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- history ---------- */
.history-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; max-height: 72vh; overflow-y: auto; padding-right: 4px; }
.hist-item {
  position: relative;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: pointer;
  background: var(--bg-soft);
  aspect-ratio: 1 / 1;
  transition: 0.15s;
}
.hist-item:hover { border-color: var(--accent); transform: translateY(-2px); }
.hist-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.hist-item .hist-del {
  position: absolute; top: 4px; right: 4px;
  background: rgba(0,0,0,0.6); color: #fff; border: none;
  width: 22px; height: 22px; border-radius: 50%; cursor: pointer;
  font-size: 13px; line-height: 1; opacity: 0; transition: 0.15s;
}
.hist-item:hover .hist-del { opacity: 1; }
.hist-meta { color: var(--text-faint); font-size: 11px; padding: 4px 0 0; }

.hidden { display: none !important; }

/* ---------- top mode toggle (生图 / 视频) ---------- */
.topmode { display: flex; justify-content: center; margin-bottom: 20px; }
.topmode-seg { width: 320px; max-width: 100%; }

/* ---------- video params ---------- */
select {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 9px 10px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  cursor: pointer;
  transition: border 0.15s;
}
select:focus { border-color: var(--accent); }
select:disabled { opacity: 0.5; cursor: not-allowed; }
.vid-params { display: flex; flex-wrap: wrap; gap: 16px; margin: 4px 0 0; }
.vid-param { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-dim); }
.vid-param select { min-width: 116px; }

/* ---------- video model selector ---------- */
.vid-model-wrap {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 4px 0 6px;
}
.vid-model-wrap select {
  flex: 1;
  min-width: 0;
}
.vid-model-wrap .btn {
  flex-shrink: 0;
  padding: 9px 12px;
}

/* ---------- video result ---------- */
.result-area video { max-width: 100%; max-height: 70vh; display: block; }

/* ---------- video history ---------- */
.vid-list { display: flex; flex-direction: column; gap: 12px; max-height: 72vh; overflow-y: auto; padding-right: 2px; }
.vid-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  background: var(--bg-soft);
  cursor: pointer;
  transition: 0.15s;
}
.vid-item:hover { border-color: var(--accent); }
.vid-item-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.vid-tag { font-size: 11.5px; padding: 2px 8px; border-radius: 999px; font-weight: 600; }
.vid-tag.ok { background: rgba(52, 211, 153, 0.15); color: var(--ok); }
.vid-tag.fail { background: rgba(255, 92, 108, 0.15); color: var(--danger); }
.vid-tag.queue { background: rgba(79, 140, 255, 0.15); color: var(--accent-2); }
.vid-tag.prog { background: rgba(255, 160, 51, 0.15); color: #ffa033; }
.vid-mode { font-size: 11.5px; color: var(--text-faint); }
.vid-time { font-size: 11.5px; color: var(--text-faint); }
.vid-del {
  margin-left: auto;
  background: transparent;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
}
.vid-del:hover { color: var(--danger); }
.vid-prompt {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 8px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.vid-video-box { display: flex; flex-direction: column; gap: 8px; }
.vid-video-box video { width: 100%; max-height: 240px; border-radius: var(--radius-sm); background: #000; }
.vid-prog { font-size: 12.5px; color: var(--text-faint); }
.vid-err { font-size: 12.5px; color: #ffb3bd; }

/* ---------- 滚动条：历史/视频列表/弹窗等滚动区域统一收窄、暗色 ---------- */
.history-grid,
.vid-list,
.modal-dialog {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.history-grid::-webkit-scrollbar,
.vid-list::-webkit-scrollbar,
.modal-dialog::-webkit-scrollbar { width: 8px; height: 8px; }
.history-grid::-webkit-scrollbar-thumb,
.vid-list::-webkit-scrollbar-thumb,
.modal-dialog::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.history-grid::-webkit-scrollbar-thumb:hover,
.vid-list::-webkit-scrollbar-thumb:hover,
.modal-dialog::-webkit-scrollbar-thumb:hover { background: #3a3f52; }

/* ---------- 键盘可访问性：聚焦轮廓 ---------- */
.btn:focus-visible,
.seg-btn:focus-visible,
.ratio-btn:focus-visible,
.icon-btn:focus-visible,
.toggle-btn:focus-visible,
.modal-close:focus-visible,
.hist-del:focus-visible,
.vid-del:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}