:root {
  --bg: #f5f6fb;
  --card: #ffffff;
  --ink: #1e2233;
  --muted: #747b93;
  --line: #e5e7f0;
  --accent: #5b5bd6;
  --accent-dark: #4646b8;
  --accent-soft: #eeeefe;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --ok: #16a34a;
  --ok-soft: #ecfdf3;
  --warn: #c2410c;
  --warn-soft: #fff7ed;
  --shadow: 0 6px 24px rgba(31, 35, 80, .07);
  --radius: 14px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-padding-top: 16px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.6;
}
button, input, select, textarea { font-family: inherit; }
button, a, [role="tab"] { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* 顶栏 */
.topbar {
  background: linear-gradient(100deg, #2b2c63, #4a49b5 60%, #6b5bd6);
  color: #fff;
  padding: 18px 0;
  box-shadow: 0 4px 18px rgba(40, 40, 100, .18);
}
.topbar-inner {
  max-width: 1320px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  width: 42px; height: 42px;
  display: grid; place-items: center;
  flex: none;
}
.brand-mark img { width: 100%; height: 100%; object-fit: contain; display: block; }
.brand h1 { margin: 0; font-size: 20px; letter-spacing: .5px; }
.brand p { margin: 2px 0 0; font-size: 12px; opacity: .8; }
.account { display: flex; align-items: center; gap: 8px; }
.account-info { display: flex; align-items: center; gap: 8px; }
.account-name { color: #fff; font-size: 12px; max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.balance-pill { color: #fff; background: rgba(255,255,255,.16); border: 1px solid rgba(255,255,255,.25); padding: 5px 10px; border-radius: 999px; font-size: 11px; white-space: nowrap; }
.balance-pill b { font-size: 12px; }
.account-btn { border: 1px solid rgba(255,255,255,.35); background: rgba(255,255,255,.08); color: #fff; border-radius: 8px; padding: 6px 11px; font-size: 12px; }
.account-btn:hover { background: rgba(255,255,255,.18); }
.account-btn.primary-outline { background: #fff; color: var(--accent-dark); border-color: #fff; font-weight: 600; }

/* 二栏布局 */
.layout {
  max-width: 1440px;
  margin: 26px auto 60px;
  padding: 0 24px;
  display: grid;
  grid-template-columns: minmax(360px, 2fr) minmax(0, 3fr);
  gap: 24px;
  align-items: start;
}
@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .workspace-panel { position: static !important; max-height: none !important; }
}
.section-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 0 0 14px; }
.section-heading.spaced { margin-top: 22px; }
.section-heading h2 { margin: 0; font-size: 16px; }
.col-left .section-heading { display: block; }
.col-left .section-heading h2 { font-size: 15px; white-space: nowrap; }
.col-left .section-heading .hint { display: block; margin-top: 2px; font-size: 11px; line-height: 1.4; }
.hint { font-size: 12px; color: #5f6785; }

/* 上传卡片 */
.cards { display: grid; gap: 14px; }
.col-left {
  background: linear-gradient(180deg, #ffffff 0%, #fafaff 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.col-left > .card, .col-left > .panel { box-shadow: none; }
.cards.three { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; align-items: stretch; }
@media (max-width: 560px) { .cards.three { grid-template-columns: 1fr; } }
.card, .panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.card-head { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 12px; }
.card-head .step {
  flex: none; width: 24px; height: 24px; border-radius: 7px;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
  font-weight: 700; font-size: 12px;
}
.card-head h3 { margin: 0; font-size: 14px; }
.card-head p { margin: 2px 0 0; font-size: 11px; color: var(--muted); line-height: 1.45; }
.cards.three .card { padding: 11px; display: flex; flex-direction: column; }
.cards.three .card-head { gap: 7px; margin-bottom: 9px; align-items: center; }
.cards.three .card-head .step { width: 21px; height: 21px; border-radius: 6px; font-size: 11px; }
.cards.three .card-head h3 { font-size: 13px; white-space: nowrap; }
.cards.three .dropzone { min-height: 96px; flex: 1; }
.cards.three .ph-icon { height: 26px; display: grid; place-items: center; }
.cards.three .ph-title { font-size: 12px; white-space: nowrap; }
.cards.three .ph-sub { font-size: 11px; white-space: nowrap; }
.ready-badge {
  position: absolute; left: 7px; top: 7px;
  display: inline-flex; align-items: center; gap: 3px;
  background: #15803d; color: #fff; border-radius: 999px;
  padding: 2px 7px; font-size: 10px; font-weight: 600;
}
.mini-hint { font-size: 12px; color: #5f6785; }
#maskHint { margin-top: 4px; }
.dropzone {
  position: relative; min-height: 112px;
  border: 1.5px dashed #c9cbe0; border-radius: 10px;
  display: grid; place-items: center; text-align: center;
  overflow: hidden; background: #fbfbfe;
  transition: border-color .15s, background .15s;
}
.dropzone:hover { border-color: var(--accent); background: #f7f7ff; }
.dropzone.dragover { border-color: var(--accent); background: var(--accent-soft); }
.dropzone.has-file { border-style: solid; padding: 0; background: #11131c; }
.dropzone.preview-mask.has-file {
  background-color: #fff;
  background-image: conic-gradient(#d9dce8 25%, #fff 0 50%, #d9dce8 0 75%, #fff 0);
  background-size: 16px 16px;
}
.dropzone .placeholder { padding: 12px; pointer-events: none; }
.ph-icon { font-size: 24px; line-height: 1; margin-bottom: 6px; color: var(--accent); font-weight: 700; }
.ph-title { font-weight: 600; font-size: 13px; }
.ph-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
.dropzone .preview { width: 100%; max-height: 140px; object-fit: contain; display: block; }
.file-meta {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: space-between; gap: 10px;
  padding: 5px 9px; background: rgba(0,0,0,.62); color: #fff; font-size: 10px; text-align: left;
}
.file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 75%; }
.file-size { opacity: .75; flex: none; }
.remove-btn {
  position: absolute; top: 7px; right: 7px;
  width: 25px; height: 25px; border-radius: 50%;
  border: none; background: rgba(0,0,0,.6); color: #fff; font-size: 12px; line-height: 1;
}
.remove-btn:hover { background: var(--danger); }
.crop-btn {
  position: absolute; left: 7px; bottom: 25px;
  display: inline-flex; align-items: center; gap: 4px;
  background: rgba(0,0,0,.68); color: #fff;
  border: 1px solid rgba(255,255,255,.3); border-radius: 7px;
  padding: 3px 7px; font-size: 10px;
}
.crop-btn:hover { background: var(--accent); border-color: #fff; }
.outline-btn {
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 9px; padding: 8px 13px; font-size: 12px;
  transition: border-color .15s, color .15s;
}
.outline-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.outline-btn:disabled { opacity: .45; cursor: not-allowed; }
#openMaskEditor { margin-top: 10px; width: 100%; }
.mini-hint { margin: 8px 0 0; font-size: 11px; color: var(--muted); }
.polarity { display: flex; align-items: center; gap: 6px; margin-top: 10px; font-size: 12px; cursor: pointer; }
.polarity input { accent-color: var(--accent); }
.mask-warning, .preset-warning {
  margin-top: 8px; padding: 7px 9px; border-radius: 8px;
  background: var(--warn-soft); border: 1px solid #fed7aa; color: var(--warn); font-size: 11px;
}

/* 编辑参考表单 */
.mask-tools { border-bottom: 1px solid var(--line); padding-bottom: 13px; margin-bottom: 14px; }
.mask-tools .outline-btn { width: 100%; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.edit-panel .field-row { margin-bottom: 13px; }
.field-row.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-row label { display: block; font-weight: 600; font-size: 12px; margin-bottom: 6px; }
.required { color: var(--danger); font-weight: 500; font-size: 11px; }
input[type=text], select, textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 9px;
  background: #fff; color: var(--ink); padding: 9px 11px;
  font-size: 13px; outline: none; transition: border-color .15s, box-shadow .15s;
}
input[type=text]:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(91,91,214,.12); }
textarea { resize: vertical; min-height: 130px; line-height: 1.65; }
.quote { margin: -3px 0 12px; padding: 7px 10px; border-radius: 8px; background: #f0f0f8; color: #4b4b7a; font-size: 12px; }
.primary-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: none; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: #fff; font-weight: 600; font-size: 14px;
  padding: 12px 18px; width: 100%;
  box-shadow: 0 4px 14px rgba(91,91,214,.3);
  transition: transform .12s, box-shadow .12s, opacity .15s;
  text-decoration: none;
}
.primary-btn:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(91,91,214,.4); }
.primary-btn:disabled { opacity: .6; cursor: not-allowed; box-shadow: none; }
.primary-btn.small { width: auto; padding: 8px 14px; font-size: 12px; }
.btn-spinner { width: 14px; height: 14px; border-radius: 50%; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.status { margin-top: 12px; padding: 9px 12px; border-radius: 9px; background: var(--accent-soft); color: var(--accent-dark); font-size: 12px; display: flex; align-items: center; gap: 8px; }
.error-box { margin-top: 12px; padding: 10px 12px; border-radius: 9px; background: var(--danger-soft); color: var(--danger); border: 1px solid #fecaca; font-size: 12px; white-space: pre-wrap; }
.error-box a { color: var(--danger); font-weight: 600; }

/* 右栏：tab 工作区 */
.workspace-panel { position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow: auto; padding: 0; }
.tabs { display: flex; gap: 4px; padding: 10px 12px 0; border-bottom: 1px solid var(--line); }
.tab {
  border: none; background: none; color: var(--muted);
  padding: 8px 14px; font-size: 13px; border-bottom: 2px solid transparent;
  border-radius: 8px 8px 0 0;
}
.tab:hover { color: var(--ink); background: #f7f7fb; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tab-count { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-dark); font-size: 10px; line-height: 16px; text-align: center; }
.tab-panel { padding: 16px; }
.panel-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin: 0 0 12px; }
.panel-heading h2 { margin: 0; font-size: 15px; }
.text-btn { border: none; background: none; color: var(--muted); font-size: 11px; padding: 2px 4px; }
.recent-block { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 14px; }
.recent-card { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 12px; align-items: center; border: 1px solid var(--line); border-radius: 10px; padding: 9px; }
.recent-card img { width: 96px; height: 72px; border-radius: 8px; object-fit: cover; background: #f0f0f8; }
.recent-card .recent-meta { min-width: 0; }
.recent-card .recent-title { font-size: 12px; font-weight: 600; margin: 0; }
.recent-card .recent-sub { font-size: 11px; color: #5f6785; margin: 2px 0 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.text-btn:hover { color: var(--danger); }

/* 案例中心 */
.case-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.case-card {
  border: 1px solid var(--line); border-radius: 11px; overflow: hidden;
  background: #fff; display: flex; flex-direction: column;
  transition: border-color .15s, box-shadow .15s;
}
.case-card:hover { border-color: var(--accent); box-shadow: 0 4px 14px rgba(91,91,214,.12); }
.case-card img { width: 100%; height: 78px; object-fit: contain; display: block; background: #f3f3fb; }
.case-card .case-body { padding: 9px 10px; flex: 1; display: flex; flex-direction: column; gap: 5px; }
.case-tag { align-self: flex-start; font-size: 10px; color: var(--accent-dark); background: var(--accent-soft); border-radius: 999px; padding: 1px 7px; }
.case-name { font-size: 13px; font-weight: 600; margin: 0; }
.case-desc { font-size: 11px; color: var(--muted); margin: 0; flex: 1; line-height: 1.45; }
.case-apply { align-self: flex-start; border: 1px solid var(--accent); color: var(--accent); background: #fff; border-radius: 7px; padding: 4px 11px; font-size: 11px; }
.case-apply:hover { background: var(--accent-soft); }

/* 任务中心 */
.task-list { display: grid; gap: 9px; }
.task-empty { text-align: center; color: var(--muted); font-size: 12px; padding: 26px 10px; border: 1px dashed var(--line); border-radius: 10px; }
.task-item {
  display: grid; grid-template-columns: 52px minmax(0, 1fr); gap: 10px;
  border: 1px solid var(--line); border-radius: 10px; padding: 9px;
  background: #fff; transition: border-color .15s, box-shadow .15s;
}
.task-item:hover { border-color: var(--accent); }
.task-item.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.task-thumb { width: 52px; height: 52px; border-radius: 8px; object-fit: cover; background: #f0f0f8; display: block; }
.task-thumb.empty { display: grid; place-items: center; color: var(--muted); font-size: 18px; }
.task-body { min-width: 0; }
.task-top { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.task-status { font-size: 10px; border-radius: 999px; padding: 1px 7px; font-weight: 600; }
.task-status.running { background: var(--accent-soft); color: var(--accent-dark); }
.task-status.success { background: var(--ok-soft); color: #15803d; }
.task-status.failed { background: var(--danger-soft); color: var(--danger); }
.task-time { font-size: 10px; color: var(--muted); }
.task-prompt { font-size: 11px; color: var(--ink); margin: 4px 0 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task-meta { font-size: 10px; color: var(--muted); margin-top: 2px; }
.task-actions { display: flex; gap: 8px; margin-top: 5px; flex-wrap: wrap; }
.task-actions button { border: none; background: none; color: var(--accent); font-size: 11px; padding: 0; }
.task-actions button.danger { color: var(--danger); }

.task-detail { border: 1px solid #cfd0f5; border-radius: 11px; padding: 10px; margin-bottom: 12px; background: #fcfcff; }
.task-detail .detail-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.task-detail .detail-head h3 { margin: 0; font-size: 13px; }
.task-detail .detail-img { width: 100%; border-radius: 9px; display: block; background: #0f1119; max-height: 340px; object-fit: contain; }
.task-detail .detail-actions { display: flex; gap: 8px; margin-top: 9px; flex-wrap: wrap; }
.detail-info { margin-top: 8px; font-size: 11px; color: var(--muted); }
.detail-prompt { margin-top: 6px; padding: 7px 8px; border-radius: 7px; background: #f2f2f9; font-size: 11px; color: var(--ink); white-space: pre-wrap; max-height: 92px; overflow: auto; }
.billing { margin-top: 8px; padding: 8px 10px; border-radius: 8px; background: var(--accent-soft); color: var(--accent-dark); font-size: 11px; }
.billing.free { background: var(--ok-soft); color: #15803d; }
.request-fields { margin-top: 7px; display: grid; gap: 3px; font-size: 10px; }
.request-fields div { background: #f5f5fb; border-radius: 6px; padding: 4px 7px; word-break: break-all; }
.request-fields b { color: var(--accent-dark); }
details.url-details { margin-top: 8px; font-size: 11px; color: var(--muted); }
details.url-details summary { cursor: pointer; }
details.url-details code { display: block; word-break: break-all; margin-top: 5px; font-size: 10px; color: var(--accent-dark); }

/* 裁切弹窗 */
.crop-card { width: min(900px, 100%); }
.crop-ratios { display: flex; gap: 6px; flex-wrap: wrap; margin: 12px 0; }
.crop-ratio { border: 1px solid var(--line); background: #fff; border-radius: 7px; padding: 5px 10px; font-size: 11px; }
.crop-ratio:hover { border-color: var(--accent); }
.crop-ratio.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-dark); font-weight: 600; }
.crop-stage { position: relative; width: max-content; max-width: 100%; margin: 0 auto; overflow: hidden; border-radius: 8px; background: #11131c; touch-action: none; }
.crop-stage img { display: block; max-width: 100%; max-height: 56vh; user-select: none; -webkit-user-drag: none; }
.crop-box { position: absolute; border: 2px solid #fff; box-shadow: 0 0 0 9999px rgba(15,17,30,.55); cursor: move; }
.crop-handle { position: absolute; width: 12px; height: 12px; background: #fff; border: 1px solid var(--accent); border-radius: 2px; }
.crop-handle.nw { left: -7px; top: -7px; cursor: nwse-resize; }
.crop-handle.ne { right: -7px; top: -7px; cursor: nesw-resize; }
.crop-handle.sw { left: -7px; bottom: -7px; cursor: nesw-resize; }
.crop-handle.se { right: -7px; bottom: -7px; cursor: nwse-resize; }

/* 弹窗 */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(15,17,30,.65); backdrop-filter: blur(3px); }
.auth-card, .modal-card { position: relative; z-index: 1; width: min(400px, 100%); max-height: 90vh; overflow: auto; background: #fff; border-radius: 16px; padding: 20px; box-shadow: 0 24px 70px rgba(0,0,0,.35); }
.modal-card { width: min(860px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-head h2 { margin: 0; font-size: 17px; }
.icon-btn { border: none; background: #f1f2f8; border-radius: 8px; width: 30px; height: 30px; color: var(--muted); }
.icon-btn:hover { background: #e6e7f0; color: var(--ink); }
.auth-tabs { display: flex; gap: 8px; margin: 14px 0; border-bottom: 1px solid var(--line); }
.auth-tabs button { border: none; background: none; padding: 8px 14px; font-size: 13px; color: var(--muted); border-bottom: 2px solid transparent; }
.auth-tabs button.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.auth-form { display: grid; gap: 10px; }
.auth-form label { display: grid; gap: 4px; font-size: 12px; font-weight: 600; }
.auth-form input, .auth-form select { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 12px; outline: none; }
.auth-form input:focus, .auth-form select:focus { border-color: var(--accent); }
.auth-card .tip { margin-top: 12px; font-size: 11px; color: var(--muted); }
.modal-hint { font-size: 12px; color: var(--muted); margin: 8px 0 12px; }

.legend { display: inline-block; width: 11px; height: 11px; border-radius: 3px; vertical-align: -1px; margin-right: 3px; }
.legend.red { background: rgba(239,68,68,.55); }
.legend.keep { background: #d1d5db; }
.tools { display: flex; flex-wrap: wrap; gap: 10px; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.tool-group { display: flex; gap: 8px; flex-wrap: wrap; }
.tool-btn { border: 1px solid var(--line); background: #fff; border-radius: 9px; padding: 8px 13px; font-size: 12px; }
.tool-btn.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-dark); font-weight: 600; }
.tool-size { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.tool-size input { width: 140px; accent-color: var(--accent); }
.canvas-wrap { position: relative; background: #11131c; border-radius: 10px; overflow: hidden; display: grid; place-items: center; min-height: 220px; touch-action: none; }
.canvas-wrap img { display: block; max-width: 100%; max-height: 56vh; object-fit: contain; user-select: none; -webkit-user-drag: none; }
.canvas-wrap canvas { position: absolute; }
.canvas-wrap #overlayCanvas { cursor: crosshair; z-index: 1; }
.canvas-wrap #strokeCanvas { pointer-events: none; z-index: 2; }
.brush-cursor {
  position: absolute; z-index: 3;
  border: 1.5px solid rgba(255,255,255,.95);
  box-shadow: 0 0 0 1px rgba(15,23,42,.55);
  border-radius: 50%;
  pointer-events: none;
  transform: translate(-50%, -50%);
  display: none;
}
.modal-foot { display: flex; justify-content: space-between; gap: 12px; margin-top: 14px; flex-wrap: wrap; }
