:root {
  --bg-1: #f7fbff;
  --bg-2: #e8f3ff;
  --bg-3: #d4e8ff;
  --glass: rgba(255, 255, 255, 0.72);
  --glass-strong: rgba(255, 255, 255, 0.9);
  --glass-soft: rgba(255, 255, 255, 0.58);
  --border: rgba(43, 92, 145, 0.16);
  --border-strong: rgba(0, 122, 255, 0.42);
  --text: #102033;
  --muted: #4d637c;
  --faint: #7890a8;
  --dark: rgba(255, 255, 255, 0.62);
  --accent: #007aff;
  --accent-2: #56a6ff;
  --ok: #82e6ae;
  --warn: #ffd37a;
  --danger: #ff3b30;
  --shadow: 0 24px 70px rgba(56, 104, 153, 0.2);
  --shadow-soft: 0 12px 34px rgba(77, 126, 175, 0.16);
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;
  --radius-xl: 30px;
  --blur: blur(22px);
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--text);
  font-family: var(--font);
  background: var(--bg-1);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

[hidden] {
  display: none !important;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.background {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(circle at 12% 8%, rgba(255, 255, 255, 0.92), transparent 30%),
    radial-gradient(circle at 86% 16%, rgba(0, 122, 255, 0.18), transparent 30%),
    radial-gradient(circle at 52% 94%, rgba(86, 166, 255, 0.2), transparent 38%),
    linear-gradient(135deg, var(--bg-1), var(--bg-2) 46%, var(--bg-3));
}

.background::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(rgba(0, 122, 255, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 122, 255, 0.04) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: linear-gradient(to bottom, black, transparent 86%);
}

.glass {
  position: relative;
  background: var(--glass);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-soft);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
}

.glass::before {
  content: "";
  position: absolute;
  top: 0;
  left: 18px;
  right: 18px;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.92), transparent);
  pointer-events: none;
}

.topbar {
  width: min(1460px, calc(100% - 32px));
  margin: 16px auto 0;
  padding: 12px 16px;
  border-radius: var(--radius-xl);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand,
.top-actions,
.key-row,
.result-head,
.result-actions,
.stepper,
.lightbox-toolbar {
  display: flex;
  align-items: center;
}

.brand {
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  flex: 0 0 auto;
  background:
    linear-gradient(135deg, rgba(255,255,255,0.98), rgba(174,218,255,0.78)),
    linear-gradient(45deg, rgba(0,122,255,0.14), rgba(255,255,255,0));
  box-shadow: inset 0 1px 1px rgba(255,255,255,0.85), 0 14px 34px rgba(0, 122, 255, 0.18);
}

h1,
h2,
h3,
p {
  margin: 0;
}

.brand h1 {
  font-size: 17px;
  line-height: 1.2;
  letter-spacing: 0;
}

.brand p,
.result-head p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.top-actions {
  gap: 10px;
}

.status-pill {
  min-height: 36px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--glass-soft);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--faint);
}

.status-pill.ok .status-dot {
  background: #12b76a;
  box-shadow: 0 0 16px rgba(18, 183, 106, 0.55);
}

.status-pill.warn .status-dot {
  background: #f59e0b;
  box-shadow: 0 0 16px rgba(245, 158, 11, 0.45);
}

.status-pill.error .status-dot {
  background: var(--danger);
  box-shadow: 0 0 16px rgba(255, 59, 48, 0.4);
}

.app-shell {
  width: min(1460px, calc(100% - 32px));
  margin: 18px auto 28px;
  display: grid;
  grid-template-columns: minmax(360px, 430px) minmax(0, 1fr);
  gap: 18px;
}

.panel {
  border-radius: var(--radius-xl);
  padding: 20px;
  overflow: hidden;
}

.control-panel {
  align-self: start;
}

.result-panel {
  min-height: calc(100vh - 112px);
  display: flex;
  flex-direction: column;
}

.field-group {
  margin-bottom: 18px;
}

.field-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 9px;
}

label,
.field-head label {
  color: var(--text);
  font-size: 13px;
  font-weight: 650;
}

.field-head span,
.field-message {
  color: var(--faint);
  font-size: 12px;
}

.field-message {
  min-height: 18px;
  margin-top: 8px;
}

.field-message.ok {
  color: var(--ok);
}

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

.key-row {
  gap: 9px;
}

.input-with-action {
  position: relative;
  flex: 1;
}

input,
select,
textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.62);
  color: var(--text);
  outline: none;
  padding: 11px 13px;
  transition: border-color 180ms var(--ease), background 180ms var(--ease), box-shadow 180ms var(--ease);
}

textarea {
  min-height: 136px;
  resize: vertical;
  line-height: 1.55;
}

input::placeholder,
textarea::placeholder {
  color: var(--faint);
}

select {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) 19px,
    calc(100% - 12px) 19px;
  background-size: 6px 6px;
  background-repeat: no-repeat;
}

option {
  color: #102033;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--border-strong);
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.14);
}

.inside {
  position: absolute;
  right: 5px;
  top: 50%;
  transform: translateY(-50%);
}

#apiKey {
  padding-right: 48px;
}

.custom-model {
  margin-top: 9px;
}

.model-search {
  margin-bottom: 9px;
}

.model-card-list {
  display: grid;
  gap: 9px;
  margin-bottom: 10px;
}

.model-chip {
  width: 100%;
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  text-align: left;
  background: rgba(255, 255, 255, 0.62);
  box-shadow: 0 10px 26px rgba(77, 126, 175, 0.1);
  animation: cardIn 220ms var(--ease);
}

.model-chip:hover {
  border-color: rgba(0, 122, 255, 0.34);
  background: rgba(255, 255, 255, 0.82);
  transform: translateY(-1px);
}

.model-chip.active {
  border-color: rgba(0, 122, 255, 0.56);
  background: linear-gradient(135deg, rgba(255,255,255,0.92), rgba(220,238,255,0.82));
  box-shadow: 0 14px 34px rgba(0, 122, 255, 0.16);
}

.model-chip-body {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.model-chip strong,
.model-chip small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.model-chip strong {
  color: var(--text);
  font-size: 14px;
}

.model-chip small {
  color: var(--muted);
  font-size: 12px;
}

.model-chip em {
  width: fit-content;
  padding: 3px 8px;
  border-radius: 999px;
  color: #ffffff;
  background: #007aff;
  font-size: 11px;
  font-style: normal;
  font-weight: 700;
}

.model-remove {
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--border);
  font-size: 18px;
  line-height: 1;
}

.model-remove:hover {
  color: #ffffff;
  background: var(--danger);
  border-color: rgba(255, 59, 48, 0.3);
}

.icon-btn,
.icon-text-btn,
.secondary-btn,
.primary-btn,
.text-btn {
  min-height: 44px;
  border: 1px solid var(--border);
  color: var(--text);
  background: rgba(255, 255, 255, 0.66);
  transition: background 180ms var(--ease), border-color 180ms var(--ease), transform 180ms var(--ease), opacity 180ms var(--ease);
}

.icon-btn {
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  flex: 0 0 auto;
}

.icon-text-btn {
  border-radius: 999px;
  padding: 0 14px;
  font-weight: 700;
}

.secondary-btn,
.primary-btn {
  border-radius: var(--radius-md);
  padding: 0 15px;
  font-weight: 700;
  white-space: nowrap;
}

.primary-btn {
  width: 100%;
  min-height: 52px;
  color: #ffffff;
  background: linear-gradient(135deg, #007aff, #56a6ff);
  border-color: rgba(0, 122, 255, 0.28);
  box-shadow: 0 14px 40px rgba(0, 122, 255, 0.24);
}

.text-btn {
  min-height: auto;
  padding: 4px 8px;
  border: 0;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
}

.icon-btn:hover,
.icon-text-btn:hover,
.secondary-btn:hover,
.text-btn:hover {
  background: var(--glass-strong);
  border-color: var(--border-strong);
}

.primary-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 18px 48px rgba(0, 122, 255, 0.32);
}

button:disabled {
  opacity: 0.45;
}

.param-row {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  margin-top: 11px;
}

.param-row:has(.ratio-card-grid) {
  align-items: start;
}

.param-row > span {
  color: var(--muted);
  font-size: 13px;
}

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

.ratio-card {
  min-height: 78px;
  display: grid;
  place-items: center;
  gap: 7px;
  padding: 9px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--muted);
  background: rgba(255, 255, 255, 0.62);
  transition: transform 160ms var(--ease), border-color 160ms var(--ease), box-shadow 160ms var(--ease), background 160ms var(--ease);
}

.ratio-card:hover {
  transform: translateY(-1px);
  border-color: rgba(0, 122, 255, 0.32);
  background: rgba(255, 255, 255, 0.82);
}

.ratio-card.active {
  color: var(--accent);
  border-color: rgba(0, 122, 255, 0.58);
  background: linear-gradient(135deg, rgba(255,255,255,0.96), rgba(218,238,255,0.86));
  box-shadow: 0 12px 28px rgba(0, 122, 255, 0.16);
}

.ratio-shape {
  width: 34px;
  height: 34px;
  display: block;
  border: 2px solid currentColor;
  border-radius: 8px;
  background: rgba(0, 122, 255, 0.08);
}

.ratio-3-4,
.ratio-9-16,
.ratio-9-21 {
  width: 25px;
  height: 38px;
}

.ratio-4-3,
.ratio-16-9,
.ratio-21-9 {
  width: 42px;
  height: 25px;
}

.ratio-auto {
  width: 38px;
  height: 30px;
  border-style: dashed;
}

.ratio-card strong {
  font-size: 12px;
}

.segmented {
  min-height: 44px;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.58);
}

.segmented button {
  min-width: 0;
  border: 0;
  border-radius: 10px;
  color: var(--muted);
  background: transparent;
  font-size: 12px;
  font-weight: 700;
}

.segmented button.active {
  color: #ffffff;
  background: linear-gradient(180deg, #007aff, #4fa2ff);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.75);
}

.stepper {
  width: fit-content;
  gap: 8px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.58);
}

.stepper strong {
  width: 28px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.spinner {
  width: 17px;
  height: 17px;
  margin-right: 8px;
  display: none;
  vertical-align: -3px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #ffffff;
  animation: spin 800ms linear infinite;
}

.primary-btn.loading .spinner {
  display: inline-block;
}

.result-head {
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.result-head h2 {
  font-size: 18px;
}

.result-actions {
  gap: 8px;
}

.stage {
  position: relative;
  min-height: 520px;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background:
    linear-gradient(135deg, rgba(255,255,255,0.62), rgba(229,243,255,0.56)),
    radial-gradient(circle at 20% 15%, rgba(0,122,255,0.08), transparent 34%);
}

.empty-state,
.error-card,
.loader-card {
  text-align: center;
  padding: 24px;
}

.empty-glyph {
  width: 68px;
  height: 68px;
  margin: 0 auto 14px;
  border-radius: 18px;
  border: 1px solid var(--border);
  background:
    linear-gradient(135deg, rgba(255,255,255,0.18), rgba(255,255,255,0.04)),
    radial-gradient(circle at 35% 30%, rgba(0,122,255,0.26), transparent 30%);
}

.empty-state h3 {
  font-size: 16px;
}

.empty-state p {
  margin-top: 7px;
  color: var(--muted);
  font-size: 14px;
}

.main-image-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 520px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.main-image-wrap img {
  max-width: 100%;
  max-height: 68vh;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  cursor: zoom-in;
}

.image-meta {
  position: absolute;
  left: 16px;
  bottom: 16px;
  max-width: calc(100% - 32px);
  padding: 7px 12px;
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--border);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.error-card {
  width: min(420px, calc(100% - 36px));
  border: 1px solid rgba(255, 143, 154, 0.38);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.76);
}

.error-card strong {
  display: block;
  color: #b42318;
  font-size: 16px;
}

.error-card p {
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.55;
}

.loading-layer {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.42);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.loader-card {
  min-width: 172px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--glass);
}

.loader {
  width: 38px;
  height: 38px;
  display: block;
  margin: 0 auto 12px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.18);
  border-top-color: var(--accent);
  animation: spin 800ms linear infinite;
}

.thumb-strip {
  min-height: 92px;
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-top: 14px;
}

.thumb {
  position: relative;
  width: 78px;
  height: 78px;
  flex: 0 0 auto;
  overflow: hidden;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
  background: var(--dark);
}

.thumb.active {
  border-color: var(--accent);
}

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

.thumb button {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  min-height: 24px;
  border-radius: 8px;
  border: 1px solid var(--border);
  color: var(--text);
  background: rgba(255, 255, 255, 0.74);
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
}

.lightbox.open,
.lightbox.closing {
  display: flex;
}

.lightbox.open {
  opacity: 1;
  pointer-events: auto;
}

.lightbox-backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: rgba(225, 239, 255, 0.64);
  backdrop-filter: blur(28px);
  -webkit-backdrop-filter: blur(28px);
  opacity: 0;
  transition: opacity 260ms var(--ease), backdrop-filter 260ms var(--ease);
}

.lightbox.open .lightbox-backdrop {
  opacity: 1;
}

.lightbox.closing .lightbox-backdrop {
  opacity: 0;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.lightbox > img {
  position: relative;
  z-index: 1;
  max-width: 90vw;
  max-height: 82vh;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  cursor: grab;
  transform-origin: center center;
  user-select: none;
  opacity: 0;
  --pan-x: 0px;
  --pan-y: 0px;
  --zoom: 1;
  transform: translate(var(--pan-x), calc(var(--pan-y) + 14px)) scale(calc(var(--zoom) * 0.92));
  transition: opacity 280ms var(--ease), transform 280ms var(--ease), border-radius 280ms var(--ease);
  will-change: transform, opacity;
}

.lightbox.open > img {
  opacity: 1;
  transform: translate(var(--pan-x), var(--pan-y)) scale(var(--zoom));
}

.lightbox.closing > img {
  opacity: 0;
  transform: translate(var(--pan-x), calc(var(--pan-y) + 18px)) scale(calc(var(--zoom) * 0.94));
}

.lightbox > img.dragging {
  cursor: grabbing;
}

.lightbox-toolbar {
  position: absolute;
  z-index: 2;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  gap: 7px;
  padding: 7px;
  border-radius: 999px;
  opacity: 0;
  transition: opacity 220ms var(--ease), transform 220ms var(--ease);
}

.lightbox.open .lightbox-toolbar {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.lightbox.closing .lightbox-toolbar {
  opacity: 0;
  transform: translateX(-50%) translateY(10px);
}

#zoomText {
  min-width: 58px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.danger:hover {
  background: rgba(255, 143, 154, 0.22);
  border-color: rgba(255, 143, 154, 0.4);
}

.toast {
  position: fixed;
  z-index: 60;
  top: 20px;
  left: 50%;
  transform: translate(-50%, -120%);
  max-width: min(640px, calc(100% - 32px));
  padding: 11px 16px;
  border-radius: 999px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  transition: transform 220ms var(--ease);
}

.toast.show {
  transform: translate(-50%, 0);
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes cardIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .result-panel {
    min-height: auto;
  }
}

@media (max-width: 680px) {
  .topbar,
  .app-shell {
    width: min(100% - 20px, 1460px);
  }

  .topbar {
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
  }

  .brand p {
    display: none;
  }

  .brand {
    min-width: 0;
    gap: 9px;
  }

  .brand h1 {
    max-width: 170px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
    border-radius: 11px;
  }

  .top-actions {
    align-items: center;
    flex-direction: row;
    gap: 7px;
    flex: 0 0 auto;
  }

  .status-pill {
    min-height: 34px;
    padding: 6px 10px;
    font-size: 12px;
  }

  .icon-text-btn {
    min-height: 40px;
    padding: 0 12px;
  }

  .panel {
    padding: 15px;
    border-radius: 22px;
  }

  .key-row,
  .result-head {
    align-items: stretch;
    flex-direction: column;
  }

  .param-row {
    grid-template-columns: 1fr;
    gap: 7px;
  }

  .model-chip {
    min-height: 68px;
  }

  .model-chip strong,
  .model-chip small {
    white-space: normal;
  }

  .ratio-card-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .segmented {
    grid-auto-flow: row;
    grid-template-columns: repeat(2, 1fr);
  }

  .stage,
  .main-image-wrap {
    min-height: 360px;
  }

  .main-image-wrap img {
    max-height: 54vh;
  }

  .lightbox-toolbar {
    width: calc(100% - 24px);
    justify-content: center;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    transition-duration: 1ms !important;
  }
}
