/* 图片生成网页的布局与视觉样式。 */
:root {
  color-scheme: dark;
  --bg: #1a1a1a;
  --surface: #212121;
  --surface-soft: #2d2d2d;
  --surface-strong: #3d3d3d;
  --surface-float: rgba(24, 24, 24, 0.96);
  --glass-bg: rgba(24, 24, 24, 0.78);
  --form-panel-bg: var(--glass-bg);
  --form-panel-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  --form-panel-blur: blur(8px) saturate(1.05);
  --site-panel-blur: var(--form-panel-blur);
  --rotation-summary-bg: var(--form-panel-bg);
  --rotation-summary-shadow: var(--shadow-lg);
  --control-glass-bg: transparent;
  --control-glass-bg-strong: transparent;
  --control-glass-line: rgba(255, 255, 255, 0.04);
  --custom-select-menu-bg: var(--form-panel-bg);
  --custom-select-shadow: var(--shadow-lg);
  --site-panel-bg: var(--form-panel-bg);
  --site-panel-line: var(--control-glass-line);
  --site-control-line: 0 0 0 1px #000000;
  --site-active-text: #8fbd9d;
  --size-custom-line: var(--site-control-line);
  --font-color: #888888;
  --text: var(--font-color);
  --muted: var(--font-color);
  --label-text: rgba(136, 136, 136, 0.3);
  --line: transparent;
  --accent: #ffffff;
  --accent-strong: var(--font-color);
  --accent-soft: rgba(255, 255, 255, 0.12);
  --status-text: #c7f7ec;
  --status-error: #ef5350;
  --danger: var(--status-error);
  --overlay: rgba(0, 0, 0, 0.58);
  --modal-backdrop: rgba(0, 0, 0, 0.72);
  --gallery-chip: rgba(12, 12, 12, 0.7);
  --gallery-text: #e0e0e0;
  --gallery-selection-bg: rgba(255, 255, 255, 0.08);
  --gallery-selection-line: rgba(255, 255, 255, 0.28);
  --gallery-delete-selected-line: #f6c945;
  --gallery-delete-selected-bg: rgba(0, 0, 0, 0.48);
  --gallery-delete-bg: var(--form-panel-bg);
  --gallery-delete-shadow: var(--shadow-lg);
  --task-state-bg: var(--gallery-chip);
  --code-bg: #181818;
  --code-text: var(--status-text);
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.3);
  --shadow-card: 0 10px 26px rgba(0, 0, 0, 0.26);
  --shadow-image: 2px 4px 12px rgba(0, 0, 0, 0.16);
  --image-dim-filter: brightness(0.68) saturate(0.96);
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

*::-webkit-scrollbar {
  width: 0;
  height: 0;
  display: none;
}

body {
  min-height: 100vh;
  margin: 0;
  background: radial-gradient(ellipse at center top, #2d2d2d 0%, #232323 50%, #1a1a1a 100%);
  background-attachment: fixed;
  color: var(--text);
  padding-bottom: 150px;
}

body.modal-open {
  overflow: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
  font-size: 12px;
}

button,
select,
input[type="file"],
input[type="range"] {
  cursor: pointer;
}

textarea,
input[type="password"],
input[type="text"],
input[type="file"],
input[type="number"],
select {
  width: 100%;
  border: 0;
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--text);
  outline: none;
  box-shadow: none;
  transition: background 0.16s ease, box-shadow 0.16s ease;
}

textarea {
  min-height: 38px;
  padding: 9px 11px;
  line-height: 1.45;
  resize: vertical;
}

input[type="password"],
input[type="text"],
input[type="file"],
input[type="number"],
select {
  height: 32px;
  padding: 0 9px;
}

input[type="file"] {
  display: block;
  line-height: 32px;
}

input[type="file"]::file-selector-button {
  height: 26px;
  margin: 0 8px 0 0;
  padding: 0 9px;
  border: 0;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
}

input[type="number"] {
  appearance: textfield;
  -moz-appearance: textfield;
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  margin: 0;
  appearance: none;
  -webkit-appearance: none;
}

textarea:focus,
input:focus,
select:focus {
  background: var(--surface-soft);
  box-shadow: none;
}

button,
.download-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 0 11px;
  border: 0;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
  color: var(--text);
  font-weight: 700;
  text-decoration: none;
  box-shadow: none;
}

button:disabled,
.disabled {
  cursor: not-allowed;
  opacity: 0.46;
  pointer-events: none;
}

.ghost {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  box-shadow: none;
}

.icon-button {
  width: 32px;
  min-width: 32px;
  padding: 0;
}

.app-shell {
  width: min(1440px, calc(100% - 32px));
  margin: 0 auto;
  padding: 20px 0;
}

.topbar {
  position: fixed;
  top: 14px;
  right: 16px;
  z-index: 120;
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(28px, 3vw, 42px);
  line-height: 1.1;
  letter-spacing: 0;
}

h2 {
  font-size: 20px;
  line-height: 1.25;
}

.topbar p,
.gallery-toolbar p {
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.45;
}

.settings-panel {
  padding: 10px;
  border: 0;
  border-radius: 8px;
  background: var(--site-panel-bg);
  backdrop-filter: var(--site-panel-blur);
  -webkit-backdrop-filter: var(--site-panel-blur);
  box-shadow: var(--shadow-lg);
}

.site-toggle {
  width: 38px;
  min-width: 38px;
  height: 38px;
  min-height: 38px;
  padding: 5px;
  background: transparent;
  box-shadow: none;
}

.site-toggle img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.site-panel {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: min(460px, calc(100vw - 28px));
  max-height: calc(100vh - 92px);
  overflow: auto;
}

.site-panel[hidden] {
  display: none;
}

.site-panel-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 6px;
  align-items: end;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--site-panel-line);
}

.site-panel-actions {
  display: flex;
  gap: 5px;
}

.site-panel-actions button {
  min-height: 28px;
  padding: 0 8px;
}

.site-panel-actions button.danger {
  color: var(--danger);
}

.site-picker {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.site-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  max-height: 116px;
  overflow: auto;
}

.site-option {
  display: inline-flex;
  align-items: center;
  max-width: 128px;
  min-height: 28px;
  padding: 6px 8px;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.site-option.active {
  color: var(--site-active-text);
}

.site-option-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 700;
}

.site-panel input[type="text"],
.site-panel input[type="password"],
.site-panel input[type="number"],
.site-panel select {
  border: 0;
  background: transparent;
  box-shadow: var(--site-control-line);
}

.site-panel input[type="text"]:focus,
.site-panel input[type="password"]:focus,
.site-panel input[type="number"]:focus,
.site-panel select:focus {
  background: transparent;
  box-shadow: var(--site-control-line);
}

.site-panel input:disabled {
  opacity: 0.46;
}

.settings-panel label,
.field label,
.upload-zone label,
.control-grid label {
  display: grid;
  gap: 5px;
  color: var(--label-text);
  font-size: 12px;
  font-weight: 700;
}

.settings-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
}

.site-connection-grid {
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 7px;
  padding-top: 9px;
}

.site-connection-grid label {
  min-width: 0;
}

.site-name-actions {
  align-self: end;
  padding-bottom: 1px;
}

.site-connection-grid label[for="baseUrl"],
.site-connection-grid label[for="apiKey"] {
  grid-column: 1 / -1;
}

.key-row {
  display: grid;
  grid-template-columns: minmax(120px, 1fr);
}

.settings-actions {
  display: flex;
  flex-wrap: nowrap;
  gap: 5px;
  align-items: center;
  margin-top: 9px;
}

.settings-actions button {
  min-height: 30px;
  padding: 0 9px;
}

.settings-actions #saveKey {
  flex: 1 1 auto;
  color: var(--gallery-text);
}

.settings-actions #fetchModels {
  flex: 0 0 auto;
}

.settings-actions .site-tool-choice-field {
  display: flex !important;
  grid-template-columns: none !important;
  grid-auto-flow: column;
  align-items: center;
  gap: 6px !important;
  color: var(--site-active-text);
  white-space: nowrap;
}

.site-tool-choice-field select {
  width: 58px;
  height: 30px;
  padding: 0 6px;
  color: var(--site-active-text);
}

.settings-actions .site-concurrency-field {
  display: flex !important;
  grid-template-columns: none !important;
  grid-auto-flow: column;
  align-items: center;
  gap: 6px !important;
  color: var(--site-active-text);
  white-space: nowrap;
}

.site-concurrency-field input {
  width: 48px;
  height: 30px;
  padding: 0 7px;
  color: var(--site-active-text);
  text-align: center;
}

.quantity-field input {
  text-align: center;
}

.settings-actions .site-proxy-field {
  margin-left: auto;
}

.model-library-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: start;
  margin-top: 7px;
  padding-top: 7px;
  border-top: 1px solid var(--site-panel-line);
}

.model-library {
  min-width: 0;
}

.model-library summary {
  cursor: pointer;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 700;
}

.model-library-github {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  color: var(--muted);
  text-decoration: none;
}

.model-library-github:hover {
  color: var(--site-active-text);
}

.model-library-github svg {
  display: block;
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.model-library-list {
  display: grid;
  gap: 6px;
  margin-top: 7px;
}

.model-library-card {
  display: grid;
  gap: 6px;
  padding: 0;
  border-radius: 8px;
  background: transparent;
}

.model-library-card.active {
  background: transparent;
}

.model-library-title {
  display: flex;
  gap: 8px;
  justify-content: space-between;
  align-items: center;
  color: var(--text);
  font-size: 12px;
}

.model-library-title span,
.model-library-empty,
.model-library-notice {
  color: var(--muted);
  font-size: 11px;
}

.model-library-notice {
  flex: 1 0 100%;
  line-height: 1.45;
}

.model-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.model-chip {
  min-height: 24px;
  padding: 0 7px;
  background: transparent;
  color: var(--text);
  font-size: 11px;
  font-weight: 700;
}

.model-chip.active {
  color: var(--gallery-text);
}

.checkbox-field {
  display: flex !important;
  grid-template-columns: none !important;
  grid-auto-flow: column;
  justify-content: start;
  align-items: center;
  gap: 8px !important;
  user-select: none;
}

.site-proxy-field {
  align-self: center;
  min-height: 30px;
  padding: 0 2px;
  white-space: nowrap;
}

.checkbox-field input {
  width: 16px;
  height: 16px;
  appearance: none;
  border: 0;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.12);
  accent-color: var(--accent);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), 0 10px 20px rgba(0, 0, 0, 0.18);
}

.checkbox-field input:checked {
  background:
    linear-gradient(135deg, transparent 0 42%, #111111 42% 56%, transparent 56%),
    linear-gradient(45deg, transparent 0 34%, #111111 34% 50%, transparent 50%),
    var(--accent);
}

.tabs {
  display: none;
  gap: 6px;
  margin-bottom: 10px;
  overflow-x: auto;
  justify-content: center;
}

.tab-button {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  box-shadow: none;
}

.tab-button.active {
  background: rgba(255, 255, 255, 0.16);
  color: var(--text);
}

.workspace {
  display: grid;
}

.panel {
  border: 0;
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.form-panel {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 80;
  width: min(1180px, calc(100% - 36px));
  max-height: min(46vh, 360px);
  padding: 2px;
  overflow: visible;
  transform: translateX(-50%);
  background: var(--form-panel-bg);
  backdrop-filter: var(--form-panel-blur);
  -webkit-backdrop-filter: var(--form-panel-blur);
  box-shadow: var(--form-panel-shadow);
}

.rotation-summary {
  position: absolute;
  right: 0;
  bottom: calc(100% + 5px);
  left: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 9px;
  align-items: center;
  width: auto;
  max-height: 72px;
  max-width: 100%;
  min-width: 0;
  overflow: auto;
  padding: 6px 8px;
  border-radius: 8px;
  background: var(--rotation-summary-bg);
  backdrop-filter: var(--form-panel-blur);
  -webkit-backdrop-filter: var(--form-panel-blur);
  box-shadow: var(--rotation-summary-shadow);
  color: var(--site-active-text);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.35;
  pointer-events: auto;
}

.rotation-summary-active {
  left: 0;
}

.rotation-summary[hidden] {
  display: none;
}

.rotation-site-list {
  display: flex;
  flex: 1 1 auto;
  flex-wrap: wrap;
  gap: 4px 9px;
  align-items: center;
  min-width: 0;
}

.rotation-site-list[hidden] {
  display: none;
}

.rotation-site-chip {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  min-width: 0;
  max-width: 220px;
  width: auto;
  min-height: 24px;
  padding: 0;
  background: transparent;
  color: var(--muted);
  box-shadow: none;
}

.rotation-site-chip.active {
  color: var(--site-active-text);
}

.rotation-site-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rotation-summary-empty {
  color: var(--muted);
  font-style: normal;
}

.rotation-toggle-field {
  justify-self: end;
  align-self: end;
  min-height: 28px;
  margin-left: 2px;
  color: var(--site-active-text);
  white-space: nowrap;
}

.rotation-toggle-field input {
  flex: 0 0 auto;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr) auto;
  gap: 6px;
  align-items: end;
}

.field {
  display: grid;
  gap: 6px;
}

.form-panel .field > label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.form-panel .field {
  grid-column: 1 / -1;
  grid-row: 1;
}

.form-panel .input-previews {
  grid-column: 1 / -1;
  grid-row: 1;
}

.input-previews {
  display: none;
  gap: 7px;
  align-items: center;
  min-width: 0;
  overflow-x: auto;
  padding: 2px 1px 4px;
}

.input-previews:has(.preview-strip:not(:empty)) {
  display: flex;
}

.input-previews:has(.preview-strip:not(:empty)) + .field {
  grid-row: 2;
}

.input-previews:has(.preview-strip:not(:empty)) ~ .upload-panel,
.input-previews:has(.preview-strip:not(:empty)) ~ .mode-field,
.input-previews:has(.preview-strip:not(:empty)) ~ .control-grid,
.input-previews:has(.preview-strip:not(:empty)) ~ .actions {
  grid-row: 3;
}

.form-panel .upload-panel {
  grid-column: 1;
  grid-row: 2;
  align-self: end;
  justify-self: start;
  z-index: 3;
}

.form-panel .control-grid {
  grid-column: 2 / 4;
  grid-row: 2;
}

.form-panel .mode-field {
  grid-column: 1;
  grid-row: 2;
  align-self: end;
}

.form-panel .upload-panel + .mode-field {
  grid-column: 2;
}

.form-panel .upload-panel + .mode-field + .control-grid {
  grid-column: 3;
}

.form-panel .actions {
  grid-column: 4;
  grid-row: 2;
  align-self: end;
}

.form-panel textarea {
  min-height: 42px;
  max-height: 68px;
  padding: 8px 10px;
  resize: none;
  background: var(--control-glass-bg);
  box-shadow: none;
}

.upload-panel {
  position: relative;
  display: flex;
  gap: 5px;
  align-items: end;
  border-radius: 8px;
}

.upload-panel input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.upload-field {
  display: grid;
  gap: 3px;
  color: var(--muted);
  font-size: 11px;
}

.upload-field.disabled {
  opacity: 0.42;
}

.upload-field.disabled .upload-button {
  cursor: default;
}

.upload-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  min-height: 28px;
  padding: 0 8px;
  border: 1px dashed var(--control-glass-line);
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  box-shadow: none;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  font-weight: 700;
  user-select: none;
}

.upload-button:focus-visible {
  outline: 0;
  box-shadow: none;
}

.upload-field:focus-within .upload-button {
  color: var(--muted);
  border-color: var(--muted);
  background: transparent;
  box-shadow: none;
}

.mode-field {
  display: grid;
  gap: 3px;
  min-width: 70px;
  color: var(--label-text);
  font-size: 11px;
  text-align: center;
}

.mode-field select {
  height: 28px;
  min-width: 0;
  padding: 0 7px;
  background: var(--control-glass-bg);
  text-align: center;
}

.form-panel select option {
  background: var(--surface-float);
  color: var(--text);
}

.custom-select-native {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

.custom-select {
  position: relative;
  width: 100%;
  min-width: 0;
}

.custom-select-button {
  position: relative;
  width: 100%;
  min-height: 28px;
  padding: 0 7px;
  justify-content: center;
  background: var(--control-glass-bg);
  color: var(--text);
  box-shadow: none;
}

.custom-select-button::after {
  content: none;
}

.custom-select.open .custom-select-button::after {
  transform: none;
}

.custom-select-value {
  min-width: 0;
  overflow: hidden;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.custom-select-menu {
  position: fixed;
  z-index: 220;
  display: grid;
  gap: 2px;
  max-height: 220px;
  overflow: auto;
  padding: 5px;
  border-radius: 8px;
  background: var(--custom-select-menu-bg);
  backdrop-filter: var(--form-panel-blur);
  -webkit-backdrop-filter: var(--form-panel-blur);
  box-shadow: var(--custom-select-shadow);
}

.custom-select-menu[hidden] {
  display: none;
}

.custom-select-option {
  min-height: 26px;
  padding: 0 8px;
  justify-content: flex-start;
  background: transparent;
  color: var(--text);
  box-shadow: none;
}

.custom-select-option.active {
  color: var(--gallery-text);
  font-weight: 700;
}

.control-grid {
  display: grid;
  grid-template-columns: minmax(82px, 128px) minmax(58px, 86px) repeat(6, minmax(48px, 76px)) minmax(88px, 110px);
  gap: 4px;
  align-items: end;
  justify-content: start;
}

.range-field {
  grid-column: auto;
}

.wide-field {
  grid-column: auto;
  min-width: 0;
}

.form-panel .control-grid label {
  gap: 3px;
  min-width: 0;
  font-size: 11px;
  text-align: center;
}

.form-panel .control-grid select,
.form-panel .control-grid input[type="text"],
.form-panel .control-grid input[type="number"] {
  height: 28px;
  min-width: 0;
  padding: 0 7px;
  background: var(--control-glass-bg);
  box-shadow: none;
  text-align: center;
}

.size-select {
  display: none;
}

.size-trigger {
  position: relative;
  width: 100%;
  min-height: 28px;
  padding: 0 7px;
  justify-content: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: var(--control-glass-bg);
  font-weight: 700;
}

.size-trigger::after {
  content: none;
}

.size-picker {
  position: fixed;
  z-index: 150;
  display: grid;
  gap: 5px;
  padding: 5px;
  border-radius: 8px;
  background: var(--custom-select-menu-bg);
  backdrop-filter: var(--form-panel-blur);
  -webkit-backdrop-filter: var(--form-panel-blur);
  box-shadow: var(--custom-select-shadow);
}

.size-picker[hidden] {
  display: none;
}

.size-picker-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.size-picker-options {
  display: grid;
  gap: 6px;
}

.size-picker-levels {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.size-picker-ratios {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.size-choice {
  min-height: 26px;
  padding: 0 8px;
  background: transparent;
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  box-shadow: none;
}

.size-choice.active {
  background: transparent;
  color: var(--gallery-text);
  box-shadow: none;
}

.size-picker .size-picker-custom {
  height: 28px;
  padding: 0 8px;
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: center;
  box-shadow: var(--size-custom-line);
}

.size-picker .size-picker-custom:focus {
  background: transparent;
  box-shadow: var(--size-custom-line);
}

.size-picker .size-picker-custom::placeholder {
  color: var(--muted);
}

.size-picker-output {
  display: grid;
  gap: 2px;
  padding: 3px 2px 0;
  border-radius: 0;
  background: transparent;
  text-align: center;
}

.size-picker-output span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.size-picker-output strong {
  color: var(--accent-strong);
  font-size: 16px;
  line-height: 1.1;
}

.form-panel .actions button {
  min-height: 28px;
  padding: 0 8px;
  background: var(--control-glass-bg-strong);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.actions {
  display: flex;
  flex-wrap: nowrap;
  gap: 5px;
  justify-content: flex-end;
}

.actions button {
  min-width: 54px;
  padding: 0 10px;
}

.upload-zone {
  display: grid;
  gap: 7px;
  padding: 9px;
  border: 0;
  border-radius: 8px;
  background: var(--surface-soft);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.preview-strip {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(48px, 60px));
  gap: 7px;
  min-height: 0;
}

.input-previews .preview-group {
  display: none;
  flex: 0 0 auto;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.input-previews .preview-group:has(.preview-strip:not(:empty)) {
  display: flex;
}

.preview-label {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 11px;
}

.input-previews .preview-strip {
  display: flex;
  flex-wrap: nowrap;
  overflow: visible;
}

.input-previews .preview-item {
  flex: 0 0 42px;
  width: 42px;
}

.preview-item {
  position: relative;
  overflow: hidden;
  aspect-ratio: 1;
  border: 0;
  border-radius: 8px;
  background: var(--surface-soft);
  box-shadow: var(--shadow);
}

.preview-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: filter 0.16s ease;
}

.preview-name {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 3px 5px;
  background: rgba(3, 8, 14, 0.72);
  color: var(--font-color);
  font-size: 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 190;
  display: grid;
  gap: 0;
  padding: 0;
  background: var(--overlay);
  backdrop-filter: blur(4px);
}

.drop-overlay[hidden] {
  display: none;
}

.drop-overlay::before {
  content: "";
  position: absolute;
  inset: 0;
  border: 2px dashed var(--muted);
  border-radius: 0;
  box-shadow: none;
  pointer-events: none;
}

.drop-overlay.split::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  border-left: 2px dashed var(--muted);
  pointer-events: none;
}

.drop-overlay.single {
  grid-template-columns: 1fr;
}

.drop-overlay.split {
  grid-template-columns: 1fr 1fr;
}

.drop-zone {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  min-width: 0;
  position: relative;
  z-index: 1;
  border: 0;
  background: transparent;
  color: var(--text);
}

.drop-zone[hidden] {
  display: none;
}

.drop-zone.active {
  background: transparent;
  box-shadow: none;
}

.drop-zone strong {
  color: var(--font-color);
  font-size: 18px;
}

.drop-zone span {
  color: var(--muted);
  font-size: 12px;
}

.result-layout {
  display: grid;
  width: min(1440px, 100%);
  margin: 0 auto;
}

.gallery-area {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.gallery-toolbar {
  display: flex;
  gap: 10px;
  justify-content: space-between;
  align-items: start;
}

.gallery-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  align-items: end;
  width: 100%;
}

.gallery-filters label {
  display: grid;
  gap: 4px;
  min-width: 104px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}

.gallery-filters select {
  height: 28px;
  min-width: 118px;
  padding: 0 8px;
  border-radius: 7px;
}

.gallery-filter-chips {
  display: flex;
  flex: 1 1 320px;
  flex-wrap: wrap;
  gap: 5px;
  align-items: end;
  min-width: 180px;
}

.gallery-filter-chip {
  min-height: 28px;
  padding: 0 9px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  white-space: nowrap;
}

.gallery-filter-chip.active {
  color: var(--gallery-text);
  font-weight: 800;
}

.download-link {
  flex: 0 0 auto;
}

.result-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  flex: 0 0 auto;
}

.result-actions button,
.result-actions .download-link {
  min-height: 28px;
  padding: 0 9px;
}

.gallery-grid {
  position: relative;
  min-height: 58vh;
}

.gallery-grid:empty::before {
  content: "暂无图片";
  min-height: 220px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--surface-soft);
  box-shadow: var(--shadow-card);
  color: var(--muted);
  font-size: 12px;
}

.gallery-grid.filtered-empty::after {
  content: "没有符合筛选的图片";
  min-height: 220px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--surface-soft);
  box-shadow: var(--shadow-card);
  color: var(--muted);
  font-size: 12px;
}

.gallery-item {
  position: relative;
  display: block;
  width: 100%;
  min-height: 0;
  margin: 0;
  padding: 0;
  overflow: visible;
  border-radius: 8px;
  background: transparent;
  box-shadow: none;
  text-align: left;
  break-inside: avoid;
  vertical-align: top;
  cursor: pointer;
}

.gallery-item.gallery-lazy-pending {
  width: 0 !important;
  height: 0 !important;
  min-height: 0;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

.gallery-item.gallery-lazy-enter {
  animation: gallery-lazy-enter 0.56s ease both;
}

@keyframes gallery-lazy-enter {
  from {
    opacity: 0;
    transform: translateY(6px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.gallery-grid.masonry-ready .gallery-item {
  position: absolute;
}

.gallery-item[hidden],
.gallery-item.filtered-out {
  display: none;
}

.gallery-item.active {
  box-shadow: none;
}

.gallery-item:focus {
  outline: 0;
  box-shadow: none;
}

.gallery-item.delete-selected::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  border: 1px solid var(--gallery-delete-selected-line);
  border-radius: 8px;
  background: var(--gallery-delete-selected-bg);
  pointer-events: none;
}

.gallery-item img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 8px;
  box-shadow: var(--shadow-image);
  transition: filter 0.16s ease;
}

.task-placeholder {
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--gallery-text);
  font-size: 12px;
  box-shadow: var(--shadow-image);
  transition: filter 0.16s ease;
}

.task-stop-button {
  position: absolute;
  z-index: 3;
  border-radius: 999px;
  background: var(--task-state-bg);
  color: var(--gallery-text);
  box-shadow: var(--shadow);
  font-size: 10px;
  font-weight: 700;
  line-height: 1.2;
}

.task-stop-button {
  left: 6px;
  bottom: 6px;
  min-height: 24px;
  padding: 0 8px;
  color: var(--danger);
}

.task-stalled-label {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 2;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--task-state-bg);
  color: var(--danger);
  box-shadow: var(--shadow);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
  pointer-events: none;
  transform: translate(-50%, -50%);
}

.task-site-label {
  position: absolute;
  left: 50%;
  bottom: 6px;
  z-index: 3;
  max-width: calc(100% - 96px);
  overflow: hidden;
  padding: 3px 7px;
  border-radius: 999px;
  background: var(--task-state-bg);
  color: var(--gallery-text);
  box-shadow: var(--shadow);
  font-size: 10px;
  font-weight: 700;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
  pointer-events: none;
  transform: translateX(-50%);
}

.gallery-badge,
.gallery-meta {
  position: absolute;
  z-index: 1;
  background: var(--gallery-chip);
  color: var(--gallery-text);
  font-size: 10px;
  line-height: 1.2;
  box-shadow: var(--shadow);
  transition: filter 0.16s ease;
}

.gallery-badge {
  top: 6px;
  left: 6px;
  padding: 3px 6px;
  border-radius: 6px;
  font-weight: 700;
}

.gallery-meta {
  right: 6px;
  bottom: 6px;
  padding: 3px 6px;
  border-radius: 6px;
  font-weight: 700;
  white-space: nowrap;
}

.gallery-group-count {
  position: absolute;
  right: 6px;
  top: 6px;
  z-index: 1;
  padding: 3px 6px;
  border-radius: 6px;
  background: var(--gallery-chip);
  color: var(--gallery-text);
  font-size: 10px;
  font-weight: 700;
  line-height: 1.2;
  box-shadow: var(--shadow);
  transition: filter 0.16s ease;
}

.gallery-meta:empty {
  display: none;
}

.gallery-box-selecting {
  user-select: none;
}

.gallery-selection-box {
  position: fixed;
  z-index: 90;
  border: 1px solid var(--gallery-selection-line);
  border-radius: 8px;
  background: var(--gallery-selection-bg);
  pointer-events: none;
}

.gallery-delete-bar {
  position: fixed;
  z-index: 150;
  display: flex;
  gap: 6px;
  align-items: center;
  width: fit-content;
  margin: 0;
  padding: 5px;
  border-radius: 8px;
  background: var(--gallery-delete-bg);
  backdrop-filter: var(--form-panel-blur);
  -webkit-backdrop-filter: var(--form-panel-blur);
  box-shadow: var(--gallery-delete-shadow);
}

.gallery-delete-bar[hidden] {
  display: none;
}

.gallery-delete-count {
  padding: 0 6px;
  color: var(--gallery-text);
  font-size: 12px;
  font-weight: 700;
}

.gallery-delete-bar button {
  min-height: 26px;
  padding: 0 9px;
  background: transparent;
  box-shadow: none;
}

.gallery-delete-bar button.danger {
  color: var(--danger);
}

.image-modal {
  position: fixed;
  inset: 0;
  z-index: 160;
  display: grid;
  place-items: center;
  padding: 18px;
  background: var(--modal-backdrop);
  overscroll-behavior: contain;
}

.image-modal[hidden] {
  display: none;
}

.modal-panel {
  display: grid;
  width: min(980px, calc(100vw - 56px));
  height: min(640px, calc(100vh - 56px));
  padding: 0;
  border-radius: 8px;
  background: transparent;
  box-shadow: none;
  overscroll-behavior: contain;
}

.modal-body {
  display: grid;
  grid-template-columns: minmax(360px, 1fr) 306px;
  gap: 12px;
  min-height: 0;
  height: 100%;
}

.modal-image-frame {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 0;
  padding: 10px;
  border-radius: 8px;
  background: var(--surface-float);
  box-shadow: var(--shadow-image);
  overscroll-behavior: contain;
}

.modal-head {
  display: grid;
  gap: 0;
  align-content: start;
}

.modal-head > div:first-child {
  display: none;
}

.modal-head h2 {
  font-size: 14px;
  line-height: 1.25;
}

.modal-head p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
}

.modal-actions {
  display: none;
  gap: 6px;
}

.modal-actions button,
.modal-actions .download-link {
  min-height: 26px;
  padding: 0 8px;
}

.modal-image-frame img {
  width: 100%;
  height: 100%;
  min-height: 0;
  object-fit: contain;
  border-radius: 8px;
  background: transparent;
  box-shadow: none;
  cursor: zoom-in;
  transition: filter 0.16s ease;
}

.image-zoom-open {
  overflow: hidden;
}

.image-zoom-overlay {
  position: fixed;
  inset: 0;
  z-index: 260;
  display: grid;
  place-items: center;
  padding: 18px;
  background: var(--modal-backdrop);
  cursor: grab;
  overscroll-behavior: contain;
}

.image-zoom-overlay[hidden] {
  display: none;
}

.image-zoom-overlay.dragging {
  cursor: grabbing;
}

.image-zoom-image {
  max-width: calc(100vw - 36px);
  max-height: calc(100vh - 36px);
  border-radius: 8px;
  object-fit: contain;
  transform-origin: center center;
  transition: transform 0.12s ease;
  user-select: none;
}

.image-zoom-overlay.dragging .image-zoom-image {
  transition: none;
}

.image-zoom-image.zoomed {
  cursor: grab;
}


body.images-dimmed .gallery-item img,
body.images-dimmed .task-placeholder,
body.images-dimmed .task-stop-button,
body.images-dimmed .gallery-badge,
body.images-dimmed .gallery-meta,
body.images-dimmed .gallery-group-count {
  filter: var(--image-dim-filter);
}

.modal-image-frame img:not([src]) {
  display: none;
}

.modal-failure {
  display: grid;
  align-content: center;
  gap: 10px;
  width: 100%;
  height: 100%;
  min-height: 0;
  padding: 18px;
  border-radius: 8px;
  background: transparent;
  color: var(--status-error);
  box-shadow: none;
  transition: filter 0.16s ease;
}

.modal-failure[hidden] {
  display: none;
}

.modal-failure strong {
  font-size: 18px;
}

.modal-failure pre {
  margin: 0;
  color: var(--status-error);
  font: 12px/1.55 Consolas, "Microsoft YaHei", monospace;
  white-space: pre-wrap;
  word-break: break-word;
  overscroll-behavior: contain;
}

.modal-failure.log-mode {
  color: var(--status-text);
}

.modal-failure.log-mode pre {
  color: var(--status-text);
}

.modal-failure span {
  color: var(--muted);
  font-size: 12px;
}

.modal-side {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 9px;
  min-height: 0;
  padding: 10px;
  border-radius: 8px;
  background: var(--surface-float);
  box-shadow: var(--shadow-image);
  overscroll-behavior: contain;
}

.modal-categories {
  display: grid;
  gap: 7px;
  align-items: start;
  min-width: 0;
}

.modal-categories[hidden] {
  display: none;
}

.modal-group-nav {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  grid-template-rows: 1fr auto 1fr;
  align-items: center;
  justify-items: center;
  padding: 10px;
  pointer-events: none;
}

.modal-group-nav[hidden] {
  display: none;
}

.modal-group-nav button {
  width: 30px;
  min-width: 30px;
  height: 30px;
  min-height: 30px;
  padding: 0;
  border-radius: 999px;
  background: var(--gallery-chip);
  color: var(--gallery-text);
  font-size: 24px;
  font-weight: 400;
  line-height: 1;
  box-shadow: var(--shadow-image);
  pointer-events: auto;
}

.modal-group-nav .prev {
  grid-column: 1;
  grid-row: 1 / 4;
  justify-self: start;
}

.modal-group-nav .next {
  grid-column: 3;
  grid-row: 1 / 4;
  justify-self: end;
}

.modal-group-nav .delete {
  position: absolute;
  bottom: 16px;
  right: 16px;
  width: auto;
  min-width: 0;
  height: auto;
  min-height: 0;
  padding: 0;
  border-radius: 0;
  background: transparent;
  color: var(--danger);
  box-shadow: none;
  font-size: 12px;
  font-weight: 700;
}

.modal-group-nav span {
  position: absolute;
  top: 16px;
  right: 16px;
  padding: 3px 7px;
  border-radius: 999px;
  background: var(--gallery-chip);
  color: var(--gallery-text);
  font-size: 11px;
  font-weight: 700;
}

.category-detail {
  grid-column: 1 / -1;
  padding: 8px;
}

.category-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  min-width: 0;
}

.category-chip-list em {
  color: var(--muted);
  font-size: 10px;
  font-style: normal;
  line-height: 24px;
  white-space: nowrap;
}

.category-chip {
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  white-space: nowrap;
}

.category-chip.active {
  color: var(--gallery-text);
  font-weight: 800;
}

.category-menu {
  position: fixed;
  z-index: 240;
  display: grid;
  gap: 4px;
  min-width: 86px;
  padding: 5px;
  border-radius: 8px;
  background: var(--surface-float);
  box-shadow: var(--shadow-lg);
}

.category-menu button {
  justify-content: start;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 6px;
  background: transparent;
}

.category-menu button.danger {
  color: var(--danger);
}

.modal-details {
  display: grid;
  align-content: start;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
  min-height: 0;
  overflow: auto;
  padding: 0;
  background: transparent;
  overscroll-behavior: contain;
}

.modal-detail-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 6px;
  align-items: center;
  align-content: start;
  min-width: 0;
  padding: 9px;
  border-radius: 8px;
  background: var(--surface);
}

.modal-detail-row.category-detail {
  grid-template-columns: 1fr;
  gap: 7px;
  min-height: 32px;
  padding: 4px 0 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.modal-detail-row.wide {
  grid-column: 1 / -1;
}

.modal-detail-row.prompt-detail {
  grid-template-columns: 1fr;
  gap: 3px;
  padding: 7px 8px;
}

.modal-detail-row.prompt-detail p {
  max-height: 66px;
  font-size: 10.5px;
  line-height: 1.35;
}

.modal-detail-row.size-detail p {
  max-height: 24px;
}

.modal-detail-row.subtle {
  background: transparent;
  padding: 2px 0 0;
}

.modal-detail-row span {
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}

.modal-detail-row p {
  color: var(--text);
  font-size: 11px;
  line-height: 1.25;
  white-space: nowrap;
  word-break: normal;
  max-height: 150px;
  overflow: auto;
  overscroll-behavior: contain;
}

.modal-detail-row.prompt-detail p {
  white-space: pre-wrap;
  word-break: break-word;
}

.modal-detail-row.tile p {
  max-height: 24px;
}

.modal-footer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
  min-width: 0;
}

.modal-duration,
.modal-time {
  color: var(--muted);
  font-size: 10px;
  line-height: 1.2;
}

.modal-duration:empty,
.modal-time:empty {
  visibility: hidden;
}

.modal-duration {
  justify-self: start;
}

.modal-duration.clickable {
  cursor: pointer;
  color: var(--gallery-text);
}

.modal-time {
  justify-self: end;
}

pre {
  min-height: 112px;
  max-height: 220px;
  margin: 0;
  padding: 10px;
  overflow: auto;
  border: 0;
  border-radius: 8px;
  background: var(--code-bg);
  color: var(--code-text);
  font: 12px/1.5 Consolas, "Courier New", monospace;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: none;
}

.error-text {
  color: var(--danger);
}

@media (max-width: 980px) {
  body {
    padding-bottom: 180px;
  }

  .app-shell {
    width: min(100% - 20px, 760px);
    padding: 10px 0;
  }

  .form-panel {
    bottom: 10px;
    width: min(100% - 20px, 760px);
    max-height: 54vh;
    padding: 2px;
  }

  .result-layout {
    grid-template-columns: 1fr;
  }

  .gallery-grid {
    min-height: 44vh;
  }

  .gallery-filters {
    width: 100%;
  }

  .modal-body {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) auto;
  }

  .modal-image-frame {
    height: 54vh;
    max-height: 54vh;
  }

  .modal-panel {
    width: min(100%, calc(100vw - 24px));
    height: min(760px, calc(100vh - 24px));
  }

  .modal-side {
    max-height: 34vh;
  }
}

@media (max-width: 560px) {
  body {
    padding-bottom: 220px;
  }

  .key-row,
  .site-connection-grid,
  .control-grid {
    grid-template-columns: 1fr;
  }

  .site-panel-head,
  .settings-actions {
    grid-template-columns: 1fr;
  }

  .settings-actions {
    flex-wrap: wrap;
  }

  .settings-actions #saveKey,
  .settings-actions #fetchModels,
  .settings-actions .site-concurrency-field,
  .settings-actions .site-proxy-field {
    flex: 1 1 calc(50% - 5px);
  }

  .tab-panel.active {
    grid-template-columns: 1fr;
  }

  .wide-field,
  .form-panel .input-previews,
  .form-panel .field,
  .form-panel .control-grid,
  .form-panel .upload-panel,
  .form-panel .mode-field,
  .form-panel .actions,
  #imageForm .upload-zone,
  #responsesForm .upload-zone {
    grid-column: 1;
    grid-row: auto;
  }

  .form-panel .actions {
    grid-row: auto;
  }

  .gallery-filters label {
    min-width: calc(50% - 4px);
  }

  .gallery-filters select {
    min-width: 0;
  }

  .modal-categories {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .form-panel .upload-panel {
    grid-column: 1;
    grid-row: auto;
  }

  .gallery-toolbar {
    display: grid;
  }

  .result-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .modal-actions {
    display: none;
  }

  .modal-details {
    grid-template-columns: 1fr;
  }

  button,
  .download-link {
    width: 100%;
  }
}
