:root {
  color-scheme: light;
  --bg: #f7f9fc;
  --fg: #202638;
  --muted: #667085;
  --panel: rgba(255, 255, 255, 0.86);
  --panel-solid: #ffffff;
  --border: rgba(130, 146, 168, 0.24);
  --primary: #6c4df6;
  --primary-2: #08a4bd;
  --primary-fg: #ffffff;
  --danger: #d92d20;
  --success: #148a5a;
  --shadow: 0 18px 55px rgba(35, 44, 72, 0.08);
  --radius: 10px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(900px 520px at 4% -12%, rgba(108, 77, 246, 0.2), transparent 62%),
    radial-gradient(780px 520px at 100% 0%, rgba(8, 164, 189, 0.17), transparent 62%),
    var(--bg);
  color: var(--fg);
  font-family:
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    "PingFang SC",
    "Microsoft YaHei",
    sans-serif;
}

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

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.hidden {
  display: none !important;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid var(--border);
  background: rgba(247, 249, 252, 0.8);
  backdrop-filter: blur(16px);
}

.app-header__inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 14px 20px;
}

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

.brand__icon {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: var(--primary-fg);
  font-weight: 800;
  box-shadow: 0 10px 28px rgba(108, 77, 246, 0.2);
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.15;
}

.brand p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.workspace {
  display: grid;
  grid-template-columns: 380px minmax(0, 1fr);
  gap: 24px;
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 20px 34px;
}

.panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.controls-panel {
  position: sticky;
  top: 86px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  height: fit-content;
  padding: 20px;
}

.field {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 8px;
}

.field--full {
  grid-column: 1 / -1;
}

.field__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.field label,
.field span,
.field__head label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

textarea,
select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--fg);
  outline: none;
  transition:
    border-color 0.16s ease,
    box-shadow 0.16s ease,
    background-color 0.16s ease;
}

textarea {
  min-height: 132px;
  resize: vertical;
  padding: 12px;
  line-height: 1.55;
}

select {
  height: 40px;
  padding: 0 12px;
}

textarea:focus,
select:focus {
  border-color: rgba(108, 77, 246, 0.55);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(108, 77, 246, 0.1);
}

.inline-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  border: 1px solid transparent;
  border-radius: 8px;
  white-space: nowrap;
  transition:
    transform 0.16s ease,
    background-color 0.16s ease,
    border-color 0.16s ease,
    opacity 0.16s ease;
}

.button:not(:disabled):active {
  transform: translateY(1px);
}

.button--small {
  height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

.button--large {
  height: 46px;
  padding: 0 18px;
  font-size: 16px;
  font-weight: 700;
}

.button--icon {
  width: 48px;
  height: 46px;
  padding: 0;
}

.button--primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: var(--primary-fg);
  box-shadow: 0 12px 30px rgba(8, 164, 189, 0.18);
}

.button--secondary {
  border-color: var(--border);
  background: #f1f5f9;
  color: var(--fg);
}

.button--ghost {
  background: transparent;
  color: var(--muted);
}

.button--ghost:hover {
  background: rgba(102, 112, 133, 0.08);
  color: var(--fg);
}

.button--ghost-danger {
  background: transparent;
  color: var(--danger);
}

.button--danger {
  background: var(--danger);
  color: #fff;
}

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

.reference-item,
.reference-upload {
  position: relative;
  overflow: hidden;
  aspect-ratio: 1;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(241, 245, 249, 0.7);
}

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

.reference-item button {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.88);
  color: var(--danger);
}

.reference-upload {
  display: grid;
  place-items: center;
  border-style: dashed;
  color: var(--muted);
  font-size: 24px;
}

.control-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.desktop-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.results {
  min-width: 0;
}

.progress-panel {
  margin-bottom: 16px;
  padding: 16px;
}

.progress-panel__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 14px;
}

.progress-track {
  height: 8px;
  margin-top: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(102, 112, 133, 0.14);
}

.progress-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary), var(--success));
  transition: width 0.2s ease;
}

.empty-state {
  display: grid;
  min-height: 320px;
  place-items: center;
  padding: 44px;
  text-align: center;
  border-style: dashed;
  box-shadow: none;
}

.empty-state__icon {
  display: grid;
  width: 58px;
  height: 58px;
  margin: 0 auto 16px;
  place-items: center;
  border-radius: 999px;
  background: rgba(108, 77, 246, 0.1);
  color: var(--primary);
  font-size: 26px;
}

.empty-state h2 {
  margin: 0 0 6px;
  font-size: 18px;
}

.empty-state p {
  margin: 0;
  color: var(--muted);
}

.image-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.image-card {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel-solid);
  box-shadow: 0 12px 35px rgba(35, 44, 72, 0.07);
}

.image-card__media {
  position: relative;
  overflow: hidden;
  aspect-ratio: 1;
  background: #eef2f7;
}

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

.image-card__loading,
.image-card__error {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(255, 255, 255, 0.68);
  text-align: center;
  color: var(--muted);
}

.image-card__error {
  color: var(--danger);
}

.spinner {
  width: 28px;
  height: 28px;
  margin: 0 auto 10px;
  border: 3px solid rgba(108, 77, 246, 0.18);
  border-top-color: var(--primary);
  border-radius: 999px;
  animation: spin 0.8s linear infinite;
}

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

.status-pill {
  position: absolute;
  top: 10px;
  left: 10px;
  border-radius: 999px;
  background: rgba(20, 138, 90, 0.92);
  color: #fff;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 700;
}

.image-card__delete {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.86);
  color: var(--danger);
}

.image-card__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 46px;
  padding: 9px 10px;
  color: var(--muted);
  font-size: 12px;
}

.image-card__meta {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bottom-actions {
  display: none;
}

.toast-region {
  position: fixed;
  top: 74px;
  left: 50%;
  z-index: 60;
  display: grid;
  gap: 8px;
  width: min(420px, calc(100vw - 32px));
  transform: translateX(-50%);
  pointer-events: none;
}

.toast {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
  padding: 10px 12px;
  color: var(--fg);
  font-size: 14px;
  backdrop-filter: blur(12px);
}

.toast--error {
  border-color: rgba(217, 45, 32, 0.2);
  color: var(--danger);
}

.preview {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(14, 20, 33, 0.72);
}

.preview img {
  max-width: min(100%, 1080px);
  max-height: calc(100vh - 48px);
  border-radius: 10px;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.3);
}

.preview__close {
  position: fixed;
  top: 20px;
  right: 20px;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--fg);
  font-size: 26px;
}

@media (max-width: 980px) {
  .workspace {
    grid-template-columns: 1fr;
    gap: 16px;
    padding: 16px 14px 96px;
  }

  .controls-panel {
    position: static;
    padding: 16px;
  }

  .desktop-actions {
    display: none;
  }

  .image-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }

  .bottom-actions {
    position: fixed;
    inset-inline: 0;
    bottom: 0;
    z-index: 30;
    display: flex;
    gap: 10px;
    padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--border);
    background: rgba(247, 249, 252, 0.92);
    box-shadow: 0 -12px 40px rgba(35, 44, 72, 0.1);
    backdrop-filter: blur(18px);
  }

  .bottom-actions .button--primary {
    flex: 1;
  }
}

@media (max-width: 560px) {
  .app-header__inner {
    padding: 12px 14px;
  }

  textarea {
    min-height: 116px;
    font-size: 16px;
  }

  .progress-panel__top {
    align-items: flex-start;
    flex-direction: column;
  }

  .image-card__foot {
    align-items: flex-start;
    flex-direction: column;
  }

  .image-card__foot .button {
    width: 100%;
  }
}
