:root {
  --bg: #0f1115;
  --bg-soft: #161a22;
  --card: #1c2130;
  --card-2: #232838;
  --border: #2a3042;
  --border-soft: #232838;
  --text: #e7eaf3;
  --text-soft: #9aa3b8;
  --text-dim: #6b7384;
  --primary: #ffd60a;
  --primary-hover: #ffdf4d;
  --primary-text: #1a1400;
  --accent: #7c5cff;
  --danger: #ff5d6c;
  --success: #3ddc97;
  --warning: #ffb648;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --shadow-soft: 0 4px 20px rgba(0, 0, 0, 0.18);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: radial-gradient(circle at 20% 0%, #1b2138 0%, #0f1115 45%) fixed;
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

a {
  color: var(--primary);
  text-decoration: none;
}
a:hover { text-decoration: underline; }

.hidden { display: none !important; }

/* ===== Topbar ===== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  background: rgba(15, 17, 21, 0.75);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-soft);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand .logo {
  font-size: 30px;
  filter: drop-shadow(0 4px 10px rgba(255, 214, 10, 0.3));
}

.brand h1 {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.2px;
}
.brand p {
  font-size: 12px;
  color: var(--text-dim);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.scope-switch {
  display: inline-flex;
  background: var(--card);
  border: 1px solid var(--border);
  padding: 4px;
  border-radius: 999px;
  gap: 2px;
}

.scope-btn {
  padding: 6px 16px;
  font-size: 13px;
  color: var(--text-soft);
  border-radius: 999px;
  transition: all 0.18s;
  font-weight: 500;
}

.scope-btn.active {
  background: var(--primary);
  color: var(--primary-text);
  box-shadow: 0 2px 8px rgba(255, 214, 10, 0.3);
}

.scope-btn:not(.active):hover {
  color: var(--text);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 10px;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text-soft);
  font-size: 13px;
  transition: all 0.18s;
  font-weight: 500;
}

.icon-btn:hover {
  color: var(--text);
  border-color: #3a4159;
  background: var(--card-2);
}
.face-control-link {
  text-decoration: none;
  white-space: nowrap;
}

.icon-btn.primary {
  background: var(--primary);
  color: var(--primary-text);
  border-color: var(--primary);
}

.icon-btn.primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  color: var(--primary-text);
}

/* ===== Main ===== */
main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 32px 28px 120px;
}

/* ===== Upload ===== */
.upload-section {
  display: flex;
  justify-content: center;
  padding: 40px 0;
}

.upload-card {
  width: 100%;
  max-width: 720px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 40px;
  box-shadow: var(--shadow);
}

.upload-hero {
  text-align: center;
  margin-bottom: 24px;
}
.upload-hero .hero-icon {
  font-size: 40px;
  margin-bottom: 8px;
}
.upload-hero h2 {
  font-size: 22px;
  margin-bottom: 6px;
}
.upload-hero p {
  color: var(--text-dim);
  font-size: 13px;
}

.upload-dropzone {
  border: 2px dashed var(--border);
  border-radius: 16px;
  padding: 40px 24px;
  text-align: center;
  transition: all 0.2s;
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.015);
}

.upload-dropzone.dragover {
  border-color: var(--primary);
  background: rgba(255, 214, 10, 0.06);
  color: var(--text);
}

.upload-dropzone .dz-title {
  font-size: 15px;
  margin-top: 16px;
  color: var(--text);
  font-weight: 500;
}
.upload-dropzone .dz-sub {
  font-size: 12px;
  margin-top: 4px;
  color: var(--text-dim);
}

.upload-buttons {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 24px;
  flex-wrap: wrap;
}

.upload-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  background: var(--card-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.18s;
}

.upload-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  transform: translateY(-1px);
}

.upload-btn.primary {
  background: var(--primary);
  color: var(--primary-text);
  border-color: var(--primary);
  padding: 11px 22px;
  font-size: 14px;
}
.upload-btn.text-mode {
  background: linear-gradient(135deg, rgba(124, 92, 255, 0.22), rgba(78, 166, 255, 0.16));
  border-color: rgba(124, 92, 255, 0.55);
  color: #dfe4ff;
  padding: 11px 18px;
  font-size: 14px;
}
.upload-btn.text-mode:hover {
  color: #fff;
  border-color: #8f78ff;
  box-shadow: 0 6px 18px rgba(124, 92, 255, 0.25);
}
.upload-btn.primary:hover {
  background: var(--primary-hover);
  color: var(--primary-text);
  border-color: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(255, 214, 10, 0.35);
}
.upload-btn .caret {
  opacity: 0.75;
  transition: transform 0.2s;
}
.upload-btn.open .caret {
  transform: rotate(180deg);
}

.upload-main-wrap {
  position: relative;
  display: inline-block;
}

.upload-menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px;
  box-shadow: var(--shadow);
  z-index: 20;
  min-width: 220px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  animation: menu-in 0.16s ease;
}

@keyframes menu-in {
  from { opacity: 0; transform: translateX(-50%) translateY(-4px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: transparent;
  border-radius: 8px;
  color: var(--text);
  text-align: left;
  transition: background 0.15s;
}
.menu-item:hover {
  background: var(--card-2);
}
.menu-item svg {
  flex-shrink: 0;
  color: var(--text-soft);
}
.menu-item:hover svg {
  color: var(--primary);
}
.menu-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  line-height: 1.3;
}
.menu-text span {
  font-size: 13px;
  font-weight: 500;
}
.menu-text small {
  font-size: 11px;
  color: var(--text-dim);
}

.upload-tip {
  text-align: center;
  margin-top: 14px;
  font-size: 12px;
  color: var(--text-dim);
}

.global-params {
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--border-soft);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

/* 始终可见的参数栏（单个/全部作用域）*/
.params-bar {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 18px;
  margin-bottom: 18px;
}
.params-bar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.params-bar-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.3px;
}
.params-bar-scope {
  font-size: 12px;
  color: var(--text-dim);
  padding: 3px 10px;
  background: var(--card-2);
  border: 1px solid var(--border-soft);
  border-radius: 999px;
}
.params-bar-scope.single {
  color: var(--primary);
  border-color: rgba(250, 204, 21, 0.4);
  background: rgba(250, 204, 21, 0.1);
}
.params-bar-body {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}

.param-item label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.param-item select {
  width: 100%;
  padding: 8px 12px;
  background: var(--card-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  font-size: 13px;
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7384' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 30px;
}

.param-item select:focus {
  outline: none;
  border-color: var(--primary);
}

/* ===== Workspace ===== */
.workspace {
  margin-top: 12px;
}

.row-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* 工作区顶部工具栏 */
.workspace-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 2px 12px;
  gap: 12px;
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.toolbar-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text-soft);
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 500;
  transition: all 0.18s;
}
.toolbar-btn:hover {
  color: var(--text);
  border-color: #3a4159;
  background: var(--card-2);
}
.toolbar-btn.active {
  color: var(--primary-text);
  background: var(--primary);
  border-color: var(--primary);
}

/* 醒目：工作区批量导出 */
.toolbar-btn-batch-export {
  font-size: 13px !important;
  font-weight: 800 !important;
  padding: 9px 20px !important;
  gap: 8px !important;
  letter-spacing: 0.03em;
  color: #fff !important;
  border: none !important;
  background: linear-gradient(135deg, #059669 0%, #0d9488 45%, #047857 100%) !important;
  box-shadow:
    0 0 0 1px rgba(16, 185, 129, 0.5),
    0 12px 28px rgba(5, 150, 105, 0.38);
}

.toolbar-btn-batch-export:hover {
  color: #fff !important;
  border: none !important;
  transform: translateY(-2px);
  box-shadow:
    0 0 0 1px rgba(52, 211, 153, 0.7),
    0 14px 36px rgba(5, 150, 105, 0.45);
}

.toolbar-btn-batch-export:active {
  transform: translateY(0);
}

.toolbar-btn-batch-export svg {
  stroke: currentColor;
  flex-shrink: 0;
}

.toolbar-btn-swap-export {
  font-size: 13px !important;
  font-weight: 800 !important;
  padding: 9px 18px !important;
  gap: 8px !important;
  color: #fff !important;
  border: none !important;
  background: linear-gradient(135deg, #7c3aed 0%, #2563eb 52%, #0f766e 100%) !important;
  box-shadow:
    0 0 0 1px rgba(124, 58, 237, 0.48),
    0 12px 28px rgba(37, 99, 235, 0.36);
}

.toolbar-btn-swap-export:hover {
  color: #fff !important;
  border: none !important;
  transform: translateY(-2px);
  box-shadow:
    0 0 0 1px rgba(147, 197, 253, 0.7),
    0 14px 36px rgba(37, 99, 235, 0.45);
}

.toolbar-btn-swap-export:disabled,
.toolbar-btn-batch-export:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.select-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 4px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  animation: fade-in 0.2s ease;
}

@keyframes fade-in {
  from { opacity: 0; transform: translateX(-4px); }
  to   { opacity: 1; transform: translateX(0); }
}

.toolbar-btn-sm {
  padding: 5px 10px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-soft);
  border-radius: 6px;
  font-size: 12px;
  transition: all 0.18s;
}
.toolbar-btn-sm:hover {
  color: var(--primary);
  background: rgba(255, 214, 10, 0.08);
}

.select-count {
  font-size: 12px;
  color: var(--text-dim);
  padding-left: 4px;
  border-left: 1px solid var(--border);
  margin-left: 2px;
}

.row-count {
  font-size: 12px;
  color: var(--text-dim);
}

/* 图片行 */
.img-row {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: grid;
  grid-template-columns: 160px 1fr 200px;
  gap: 12px;
  position: relative;
  transition: border-color 0.18s, padding 0.18s;
}

/* 选择模式：左侧插入复选框列 */
.row-list.select-mode .img-row {
  grid-template-columns: 28px 160px 1fr 200px;
  padding-left: 10px;
}

.row-checkbox {
  display: none;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  align-self: start;
  margin-top: 4px;
}

.row-list.select-mode .row-checkbox {
  display: flex;
}

.row-checkbox input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  background: var(--bg-soft);
  cursor: pointer;
  position: relative;
  transition: all 0.18s;
}
.row-checkbox input[type="checkbox"]:hover {
  border-color: var(--primary);
}
.row-checkbox input[type="checkbox"]:checked {
  background: var(--primary);
  border-color: var(--primary);
}
.row-checkbox input[type="checkbox"]:checked::after {
  content: "";
  position: absolute;
  left: 6px;
  top: 2px;
  width: 5px;
  height: 10px;
  border: solid var(--primary-text);
  border-width: 0 2.2px 2.2px 0;
  transform: rotate(45deg);
}

.img-row.checked {
  border-color: var(--primary);
  background: linear-gradient(to right, rgba(255, 214, 10, 0.05), var(--card));
}

.img-row.selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(255, 214, 10, 0.15);
}

.img-row:hover .row-delete {
  opacity: 1;
}

/* 左侧容器：主图 + 参考图 */
.row-left {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

/* 原图 */
.row-original {
  position: relative;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg);
  aspect-ratio: 1 / 1;
  cursor: pointer;
  flex-shrink: 0;
}

.row-original img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.row-index {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 2;
  min-width: 24px;
  height: 24px;
  padding: 0 7px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.72);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  line-height: 24px;
  text-align: center;
  backdrop-filter: blur(10px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}
.row-name-line {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  color: var(--text-soft);
  font-size: 12px;
  line-height: 1.3;
}
.row-name-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.row-name-add {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--card-2);
  border: 1px solid var(--border);
  color: var(--text-soft);
  font-size: 12px;
  transition: all 0.18s;
}
.row-name-add:hover {
  color: var(--primary);
  border-color: var(--primary);
  background: rgba(255, 214, 10, 0.08);
}
.text-source-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px;
  text-align: center;
  color: var(--text-soft);
  background:
    radial-gradient(circle at 50% 20%, rgba(124, 92, 255, 0.28), transparent 48%),
    linear-gradient(145deg, rgba(255,255,255,0.04), rgba(255,255,255,0.01));
}
.text-source-placeholder .text-source-icon {
  font-size: 28px;
  line-height: 1;
}
.text-source-placeholder .text-source-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.text-source-placeholder .text-source-sub {
  font-size: 11px;
  color: var(--text-dim);
}

/* 参考图区 */
.row-refs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.ref-item,
.ref-add {
  width: 36px;
  height: 36px;
  border-radius: 7px;
  overflow: hidden;
  position: relative;
  flex-shrink: 0;
}

.ref-item {
  background: var(--bg);
  border: 1px solid var(--border);
}
.ref-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  cursor: pointer;
}
.ref-item .ref-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 14px;
  height: 14px;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s;
}
.ref-item:hover .ref-remove {
  opacity: 1;
}
.ref-item .ref-remove:hover {
  background: var(--danger);
}
.ref-item .ref-mask {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 9px;
  line-height: 1;
}
.ref-item .ref-progress {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.2px;
  white-space: nowrap;
}
.ref-item .ref-mask.ref-fail {
  color: var(--danger);
  background: rgba(0, 0, 0, 0.7);
}

.ref-add {
  width: auto;
  min-width: 54px;
  padding: 0 8px;
  background: transparent;
  border: 1.5px dashed var(--border);
  color: var(--text-dim);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 11px;
  transition: all 0.18s;
  cursor: pointer;
}
.ref-add:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: rgba(255, 214, 10, 0.05);
}

.spinner-sm {
  width: 12px;
  height: 12px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.row-original .status-chip {
  position: absolute;
  bottom: 8px;
  left: 8px;
  padding: 4px 10px;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 11px;
  border-radius: 999px;
  backdrop-filter: blur(10px);
}

/* 中间提示词 + 标签 */
.row-middle {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.row-middle textarea {
  width: 100%;
  flex: 1;
  min-height: 92px;
  padding: 10px 12px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  line-height: 1.6;
  resize: vertical;
  transition: border-color 0.18s;
}

.row-middle textarea:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--bg);
}

.row-tags {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.tag-btn {
  padding: 6px 14px;
  background: var(--card-2);
  border: 1px solid var(--border);
  color: var(--text-soft);
  border-radius: 999px;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.18s;
  font-weight: 500;
}

.tag-btn:hover {
  color: var(--primary);
  border-color: var(--primary);
  background: rgba(255, 214, 10, 0.08);
}

.tag-btn-flash {
  animation: tag-flash 0.25s ease;
}
@keyframes tag-flash {
  0%   { background: var(--primary); color: var(--primary-text); transform: scale(1); }
  50%  { transform: scale(1.06); }
  100% { background: var(--card-2); color: var(--text-soft); transform: scale(1); }
}

.tag-btn .tag-emoji {
  font-size: 13px;
}

/* 行内参数下拉（每张图独立的宽高比 / 分辨率 / 格式） */
.row-params {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.row-param-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px 4px 8px;
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  color: var(--text-soft);
  transition: border-color 0.15s, color 0.15s;
}
.row-param-item:hover {
  border-color: var(--primary);
  color: var(--primary);
}
.row-param-item > span {
  font-size: 13px;
  line-height: 1;
}
.row-param-item select {
  background: transparent;
  border: none;
  color: inherit;
  font-size: 12px;
  font-weight: 500;
  padding: 0 16px 0 2px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%238b8b94' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right 2px center;
  background-size: 10px;
}
.row-param-item select:focus {
  outline: none;
}
.row-param-item select option {
  color: #222;
}

/* 右侧：生成按钮 + 结果 */
.row-right {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.row-actions {
  display: flex;
  gap: 6px;
}

.row-generate {
  flex: 1;
  padding: 10px 16px;
  background: var(--primary);
  color: var(--primary-text);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.18s;
}

.row-generate:hover:not(:disabled) {
  background: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(255, 214, 10, 0.3);
}

.row-generate:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.row-local-edit {
  padding: 9px 12px;
  background: rgba(124, 92, 255, 0.12);
  color: #cfc7ff;
  border: 1px solid rgba(124, 92, 255, 0.35);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 700;
  transition: all 0.18s;
}

.row-local-edit:hover:not(:disabled) {
  color: #fff;
  background: rgba(124, 92, 255, 0.24);
  border-color: rgba(124, 92, 255, 0.72);
}

.row-local-edit:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.row-download-btn {
  padding: 8px 10px;
  background: var(--card-2);
  border: 1px solid var(--border);
  color: var(--text-soft);
  border-radius: var(--radius-sm);
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: all 0.18s;
  white-space: nowrap;
  min-width: 70px;
}
.row-download-btn:hover:not(:disabled) {
  border-color: var(--primary);
  color: var(--primary);
  background: rgba(255, 214, 10, 0.06);
}
.row-download-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.row-results {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
  gap: 6px;
  align-content: start;
  max-height: 200px;
  overflow-y: auto;
}

.row-results::-webkit-scrollbar {
  width: 4px;
}
.row-results::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.result-thumb {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  aspect-ratio: 1 / 1;
  background: var(--bg);
  cursor: pointer;
  border: 1px solid var(--border);
  transition: all 0.18s;
}

.result-thumb:hover {
  border-color: var(--primary);
  transform: scale(1.02);
}

.result-thumb.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  animation: pulse 1.6s ease-in-out infinite;
}

.result-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.result-thumb .thumb-download {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  padding: 0;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  border: none;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: all 0.18s;
  backdrop-filter: blur(8px);
  cursor: pointer;
}
.result-thumb .thumb-download:hover {
  background: var(--primary);
  color: var(--primary-text);
}

.result-thumb:hover .thumb-download {
  opacity: 1;
}

.result-thumb.failed {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--danger);
  background: rgba(255, 93, 108, 0.08);
  border-color: rgba(255, 93, 108, 0.3);
}

/* 删除按钮 */
.row-delete {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 28px;
  height: 28px;
  background: rgba(0, 0, 0, 0.4);
  color: var(--text-soft);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: all 0.18s;
  backdrop-filter: blur(8px);
  z-index: 2;
}

.row-delete:hover {
  background: var(--danger);
  color: #fff;
}

/* 加载占位 */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===== FAB 批量生成 ===== */
.fab {
  position: fixed;
  bottom: 32px;
  right: 32px;
  z-index: 40;
}

.fab button {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 14px 24px;
  background: var(--primary);
  color: var(--primary-text);
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 8px 28px rgba(255, 214, 10, 0.4), 0 2px 8px rgba(0, 0, 0, 0.2);
  transition: all 0.18s;
}

.fab button:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 32px rgba(255, 214, 10, 0.5), 0 4px 12px rgba(0, 0, 0, 0.3);
}

.fab button:disabled {
  opacity: 0.7;
  cursor: not-allowed;
  transform: none;
}

/* ===== 标签弹出选项面板 ===== */
.tag-popover {
  position: fixed;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  box-shadow: var(--shadow);
  z-index: 100;
  min-width: 320px;
  max-width: 440px;
}

.tag-popover .tp-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-soft);
}

.tag-popover .tp-title {
  font-size: 13px;
  font-weight: 600;
}

.tag-popover .tp-close {
  width: 22px;
  height: 22px;
  color: var(--text-dim);
  font-size: 14px;
  border-radius: 6px;
  transition: all 0.18s;
}

.tag-popover .tp-close:hover {
  background: var(--card-2);
  color: var(--text);
}

.tag-popover .tp-options {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.option-chip {
  padding: 6px 12px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  font-size: 12px;
  transition: all 0.15s;
}

.option-chip:hover {
  background: var(--primary);
  color: var(--primary-text);
  border-color: var(--primary);
}

.option-chip.active {
  background: var(--primary);
  color: var(--primary-text);
  border-color: var(--primary);
}

.tag-popover .tp-footer {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border-soft);
}

.tag-popover .tp-hint {
  font-size: 11px;
  color: var(--text-dim);
}

/* ===== Modal ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-mask {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
}

.modal-body {
  position: relative;
  width: 90%;
  max-width: 420px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  box-shadow: var(--shadow);
}

.modal-body h3 {
  font-size: 16px;
  margin-bottom: 6px;
}

.modal-body .modal-desc {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 16px;
}

.input-row label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.input-row input {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 13px;
  font-family: monospace;
}

.input-row input:focus {
  outline: none;
  border-color: var(--primary);
}

.modal-actions {
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.btn-ghost {
  padding: 8px 18px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-soft);
  border-radius: 8px;
  font-size: 13px;
  transition: all 0.18s;
}
.btn-ghost:hover {
  color: var(--text);
  border-color: #3a4159;
}

.btn-primary {
  padding: 8px 18px;
  background: var(--primary);
  color: var(--primary-text);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  transition: all 0.18s;
}
.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-primary:disabled,
.btn-ghost:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.local-edit-modal-body {
  width: min(1180px, calc(100vw - 32px));
  max-width: none;
  max-height: calc(100vh - 40px);
  overflow: auto;
}

.local-edit-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.local-edit-close {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  color: var(--text-soft);
  background: var(--bg-soft);
  border: 1px solid var(--border);
}

.local-edit-close:hover {
  color: var(--text);
  border-color: #3a4159;
}

.local-edit-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 16px;
  width: 100%;
  min-width: 0;
}

.local-edit-stage-wrap {
  min-width: 0;
  min-height: 420px;
  max-height: calc(100vh - 190px);
  overflow: hidden;
  border-radius: 14px;
  border: 1px solid var(--border);
  background:
    linear-gradient(45deg, rgba(255,255,255,0.035) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(255,255,255,0.035) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(255,255,255,0.035) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(255,255,255,0.035) 75%);
  background-size: 24px 24px;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
}

.local-edit-stage {
  min-width: 0;
  min-height: 420px;
  height: min(640px, calc(100vh - 190px));
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  overflow: hidden;
}

#localEditCanvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  border-radius: 10px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.38);
  cursor: crosshair;
  touch-action: none;
  background: #111;
}

.local-edit-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
  width: 100%;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background:
    radial-gradient(circle at 12% 0%, rgba(255, 214, 10, 0.08), transparent 28%),
    linear-gradient(180deg, rgba(255,255,255,0.045), rgba(255,255,255,0.014));
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.05),
    0 12px 28px rgba(0, 0, 0, 0.16);
}

.local-panel-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 14px;
  background: rgba(15, 17, 21, 0.28);
}

.local-panel-section-grow {
  flex: 1;
  min-height: 0;
}

.local-panel-title {
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.local-field {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.local-field span {
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 700;
}

.local-field select {
  width: 100%;
  min-height: 40px;
  padding: 0 12px;
  color: var(--text);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 13px;
}

.local-field select:focus {
  outline: none;
  border-color: var(--primary);
}

.local-tool-group {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.local-tool {
  min-height: 40px;
  padding: 9px 10px;
  border-radius: 10px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--text-soft);
  font-size: 13px;
  font-weight: 700;
  transition: all 0.16s;
}

.local-tool.active,
.local-tool:hover {
  color: var(--primary-text);
  background: var(--primary);
  border-color: var(--primary);
}

.local-slider {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--text-dim);
  font-size: 12px;
}

.local-slider span {
  display: flex;
  justify-content: space-between;
  color: var(--text-soft);
  font-weight: 600;
}

.local-slider input {
  width: 100%;
  accent-color: var(--primary);
}

#localPromptInput {
  min-height: 132px;
  height: 100%;
  resize: vertical;
  padding: 12px;
  color: var(--text);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-family: inherit;
  font-size: 13px;
  line-height: 1.6;
}

#localPromptInput:focus {
  outline: none;
  border-color: var(--primary);
}

.local-edit-hint {
  min-height: 38px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255, 214, 10, 0.07);
  color: var(--text-soft);
  font-size: 12px;
}

.local-edit-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: auto;
}

.local-edit-actions .btn-ghost,
.local-edit-actions .btn-primary {
  width: 100%;
  min-height: 42px;
  border-radius: 12px;
  font-weight: 800;
}

.local-edit-actions .btn-primary {
  box-shadow: 0 10px 24px rgba(255, 214, 10, 0.22);
}

.recharge-modal-body {
  max-width: 560px;
}
.recharge-plans {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}
.recharge-plan {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 20px 14px 14px;
  background: linear-gradient(180deg, rgba(255, 214, 10, 0.08), rgba(255, 214, 10, 0.02));
  border: 1px solid var(--border);
  border-radius: 14px;
}
.recharge-plan.featured {
  border-color: rgba(255, 214, 10, 0.55);
  box-shadow: 0 0 0 1px rgba(255, 214, 10, 0.14) inset;
}
.recharge-plan-badge {
  position: absolute;
  top: 0;
  left: 12px;
  transform: translateY(-50%);
  padding: 5px 10px;
  color: var(--primary-text);
  background: linear-gradient(135deg, var(--primary), #ff9f1c);
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.32);
  box-shadow: 0 8px 18px rgba(255, 159, 28, 0.24);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.2;
  white-space: nowrap;
}
.recharge-plan-name {
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 600;
}
.recharge-plan-price {
  color: var(--primary);
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.recharge-plan-points {
  color: var(--text);
  font-size: 13px;
}
.recharge-plan-points b {
  color: var(--primary);
}
.recharge-plan button {
  margin-top: auto;
  width: 100%;
}
.pay-qr-modal-body {
  max-width: 360px;
  text-align: center;
}
.pay-qr-box {
  display: flex;
  justify-content: center;
  padding: 12px;
  background: #fff;
  border-radius: 14px;
  margin: 10px auto 12px;
  width: min(260px, 100%);
}
.pay-qr-box img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 8px;
}
.pay-status {
  min-height: 20px;
  color: var(--text-soft);
  font-size: 13px;
  line-height: 1.5;
}

/* Preview */
.preview-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}

.preview-modal img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
}

.preview-compare-badge {
  position: absolute;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  padding: 9px 16px;
  border-radius: 999px;
  background: rgba(15, 17, 21, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  backdrop-filter: blur(14px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
  pointer-events: none;
}

.preview-actions {
  position: absolute;
  right: 28px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.preview-action-btn {
  width: 132px;
  padding: 12px 14px;
  background: rgba(255, 214, 10, 0.94);
  color: var(--primary-text);
  border-radius: 14px;
  box-shadow: 0 8px 26px rgba(255, 214, 10, 0.25);
  font-weight: 700;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.preview-action-btn:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}
.preview-action-btn small {
  font-size: 11px;
  font-weight: 500;
  opacity: 0.72;
}

.preview-close {
  position: absolute;
  top: 24px;
  right: 24px;
  width: 36px;
  height: 36px;
  background: rgba(255,255,255,0.12);
  color: #fff;
  border-radius: 50%;
  font-size: 16px;
  transition: background 0.18s;
}
.preview-close:hover {
  background: rgba(255,255,255,0.25);
}

/* Toast */
.toast-container {
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 10px 18px;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  font-size: 13px;
  box-shadow: var(--shadow-soft);
  animation: toast-in 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
  pointer-events: auto;
}

.toast.success { border-color: var(--success); color: var(--success); }
.toast.error   { border-color: var(--danger);  color: var(--danger); }
.toast.warning { border-color: var(--warning); color: var(--warning); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* 响应式 */
@media (max-width: 900px) {
  .img-row {
    grid-template-columns: 110px 1fr;
  }
  .row-list.select-mode .img-row {
    grid-template-columns: 24px 110px 1fr;
  }
  .row-right {
    grid-column: 1 / -1;
    flex-direction: row;
    align-items: flex-start;
  }
  .row-generate { white-space: nowrap; }
  .row-results { flex: 1; }
  .global-params { grid-template-columns: 1fr 1fr; }
  .params-bar-body { grid-template-columns: 1fr 1fr; }
  main { padding: 20px 16px 100px; }
  .upload-card { padding: 24px; }
  .topbar { padding: 12px 16px; }
  .brand h1 { font-size: 14px; }
  .brand p { display: none; }
  .local-edit-modal-body { width: calc(100vw - 24px); }
}

/* ===== 手机竖屏专用适配（<= 640px） ===== */
@media (max-width: 640px) {
  body { font-size: 13.5px; }

  /* 顶栏：让它可以换行，并对齐安全区 */
  .topbar {
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 12px;
    padding-top: calc(10px + env(safe-area-inset-top, 0px));
  }
  .brand { gap: 10px; flex: 1 1 auto; min-width: 0; }
  .brand .logo { font-size: 24px; }
  .brand h1 { font-size: 15px; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .brand p { display: none; }
  .top-actions { flex: 0 0 auto; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

  /* scope 切换：手机上变紧凑 */
  .scope-switch { padding: 3px; }
  .scope-btn { padding: 5px 10px; font-size: 12px; }

  /* 图标按钮紧凑 */
  .icon-btn { padding: 7px 10px; font-size: 12.5px; gap: 6px; }
  .icon-btn svg { width: 16px; height: 16px; }
  /* 顶部"继续添加"在手机竖屏上只保留图标，节省空间 */
  .icon-btn.primary span { display: none; }
  .icon-btn.primary { padding: 8px; }

  /* 账号 chip 简化：隐藏用户名中段 */
  .user-chip { padding: 5px 8px 5px 6px; font-size: 12px; gap: 6px; }
  .user-chip .user-ava { width: 20px; height: 20px; font-size: 11px; }
  .user-chip .user-name { max-width: 70px; }

  /* 用户菜单：小屏改成从右侧贴屏，避免溢出 */
  .user-menu {
    right: 8px;
    left: 8px;
    min-width: 0;
    max-width: none;
  }

  /* 主内容 padding 再收紧（FAB 预留 110px） */
  main { padding: 14px 12px 120px; }

  /* 上传卡片 */
  .upload-section { padding: 16px 0; }
  .upload-card { padding: 18px 14px; border-radius: 16px; }
  .upload-hero h2 { font-size: 18px; }
  .upload-hero .hero-icon { font-size: 34px; }
  .upload-dropzone { padding: 24px 14px; }
  .upload-dropzone svg { width: 44px; height: 44px; }
  .upload-dropzone .dz-title { font-size: 14px; margin-top: 12px; }

  /* 参数栏 3 列 → 2 列，标题占一行 */
  .params-bar { padding: 12px 12px; margin-bottom: 12px; border-radius: 12px; }
  .params-bar-body { grid-template-columns: 1fr 1fr; gap: 10px; }
  .global-params { grid-template-columns: 1fr 1fr; gap: 10px; }

  /* 工作区 toolbar 换行 */
  .workspace-toolbar {
    padding: 2px 0 10px;
    gap: 8px;
  }
  .toolbar-btn { padding: 6px 10px; font-size: 12px; }

  /* 图片行：主图 + 提示词上下两层；右栏在最底下再一行 */
  .img-row {
    grid-template-columns: 88px 1fr;
    gap: 10px;
    padding: 10px;
    border-radius: 12px;
  }
  .row-list.select-mode .img-row {
    grid-template-columns: 22px 88px 1fr;
    padding-left: 8px;
  }
  .row-middle textarea { min-height: 72px; font-size: 14px; }
  .row-tags { gap: 6px; }
  .tag-btn { padding: 5px 10px; font-size: 12px; }
  .row-params { gap: 6px; }
  .row-param-item { font-size: 11.5px; padding: 3px 8px 3px 6px; }
  .row-param-item select { font-size: 11.5px; }

  .row-right {
    grid-column: 1 / -1;
    flex-direction: column;
    gap: 8px;
  }
  .row-actions { gap: 6px; }
  .row-generate { padding: 10px 14px; font-size: 13px; }
  .row-local-edit { padding: 9px 10px; font-size: 12px; }
  .row-download-btn { padding: 8px 12px; min-width: 56px; }
  /* 结果缩略图：自动尽量多列，最小 56px，适应 360 屏 */
  .row-results {
    grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
    gap: 5px;
    max-height: 170px;
  }

  /* 参考图 */
  .ref-item, .ref-add { width: 32px; height: 32px; }
  .ref-add { min-width: 48px; font-size: 10px; padding: 0 6px; }

  /* 行删除按钮始终半可见，适配无 hover 场景 */
  .row-delete { opacity: 0.6; background: rgba(0,0,0,0.55); }
  .row-delete:active { opacity: 1; }

  /* 标签弹出面板：占满屏宽 */
  .tag-popover {
    left: 8px !important;
    right: 8px;
    min-width: 0;
    max-width: none;
    width: auto;
  }

  /* 登录 / 兑换弹窗 */
  .modal-body {
    width: 94%;
    max-width: none;
    padding: 18px 16px;
    border-radius: 14px;
  }
  .local-edit-modal-body {
    max-height: calc(100vh - 20px);
    overflow-y: auto;
  }
  .local-edit-stage-wrap,
  .local-edit-stage {
    min-height: 280px;
  }
  .local-edit-stage {
    height: 52vh;
    padding: 12px;
  }
  #localEditCanvas {
    max-height: 52vh;
  }
  /* iOS 聚焦输入框时不自动放大：font-size 必须 >= 16px */
  .input-row input,
  .row-middle textarea,
  .param-item select,
  .row-param-item select { font-size: 16px; }
  .modal-actions .btn-primary,
  .modal-actions .btn-ghost { padding: 10px 16px; font-size: 14px; min-height: 40px; }
  .recharge-plans { grid-template-columns: 1fr; }

  /* 预览 */
  .preview-modal { padding: 16px; }
  .preview-close { top: calc(12px + env(safe-area-inset-top, 0px)); right: 12px; }
  .preview-actions {
    top: auto;
    right: 16px;
    left: 16px;
    bottom: calc(58px + env(safe-area-inset-bottom, 0px));
    transform: none;
    align-items: center;
  }
  .preview-compare-badge {
    bottom: calc(14px + env(safe-area-inset-bottom, 0px));
    width: max-content;
    max-width: calc(100% - 28px);
    text-align: center;
    font-size: 12px;
  }
  .preview-action-btn {
    width: 100%;
    max-width: 340px;
    flex-direction: row;
    justify-content: center;
  }

  /* FAB 避开刘海/底部安全区 */
  .fab {
    bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    right: 16px;
    left: 16px;
    display: flex;
    justify-content: center;
  }
  .fab button {
    padding: 13px 22px;
    font-size: 14px;
    width: 100%;
    max-width: 360px;
  }

  /* Toast 居中更靠上 */
  .toast-container {
    top: calc(64px + env(safe-area-inset-top, 0px));
    width: calc(100% - 24px);
    max-width: 420px;
  }
  .toast { width: 100%; text-align: center; }
}

@media (max-width: 760px) {
  .local-edit-layout { grid-template-columns: minmax(0, 1fr); }
  .local-edit-panel { padding: 12px; }
  .local-panel-section { padding: 10px; }
  #localPromptInput { min-height: 110px; }
}

/* 极小屏（<=360 iPhone SE 以下）的进一步兜底 */
@media (max-width: 360px) {
  .brand h1 { font-size: 14px; }
  .scope-btn { padding: 4px 8px; font-size: 11.5px; }
  .icon-btn { font-size: 12px; padding: 6px 8px; }
  .user-chip .user-name { max-width: 56px; }
  .upload-card { padding: 14px 10px; }
  .img-row { grid-template-columns: 80px 1fr; gap: 8px; }
  .row-list.select-mode .img-row { grid-template-columns: 22px 80px 1fr; }
}

/* ===== 顶栏账号区（2026-04 adjust 接入 face 用户系统） ===== */
.auth-wrap { position: relative; display: flex; align-items: center; }
.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px 6px 8px;
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 13px;
  line-height: 1;
}
.user-chip:hover { border-color: #3a4159; }
.user-chip .user-ava {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: linear-gradient(135deg, #7c5cff, #4ea6ff);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px;
}
.user-chip .user-name { color: var(--text); max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chip .user-points { color: var(--primary); font-weight: 600; }
.user-chip .caret { color: var(--text-dim); }

.user-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 260px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 12px;
  z-index: 200;
}
.user-menu-head {
  padding: 4px 4px 10px;
  border-bottom: 1px solid var(--border-soft);
  margin-bottom: 10px;
}
.user-menu-head .um-name { font-weight: 600; color: var(--text); font-size: 14px; }
.user-menu-head .um-points { color: var(--primary); font-size: 16px; margin-top: 4px; font-weight: 700; }
.user-menu-prices {
  font-size: 12px; color: var(--text-soft);
  padding: 6px 4px 10px;
  border-bottom: 1px dashed var(--border-soft);
  margin-bottom: 10px;
}
.user-menu-prices b { color: var(--primary); }
.user-menu-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.user-menu-actions .um-btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 8px 10px;
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  text-decoration: none;
}
.user-menu-actions .um-btn:hover { border-color: #3a4159; background: #2a2f42; text-decoration: none; }
.user-menu-actions .um-btn.danger { color: var(--danger); grid-column: 1 / -1; }

/* 登录弹窗 tabs & 错误 */
.login-modal .login-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}
.login-modal .login-tab {
  padding: 8px 16px;
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-soft);
  font-size: 14px;
}
.login-modal .login-tab.active { color: var(--primary); border-color: var(--primary); background: rgba(255,214,10,0.08); }
.login-error {
  min-height: 20px;
  color: var(--danger);
  font-size: 13px;
  margin: 4px 0 8px;
}
.login-remember-row {
  margin-top: -4px;
}
.login-remember-label {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 13px;
  color: var(--text-soft);
  cursor: pointer;
  line-height: 1.45;
}
.login-remember-label input {
  margin-top: 3px;
  flex-shrink: 0;
  accent-color: var(--primary);
}
