:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #eef2f7;
  --text: #18202f;
  --muted: #657184;
  --line: #dfe5ee;
  --accent: #0e766e;
  --accent-2: #7c3aed;
  --danger: #c2410c;
  --shadow: 0 18px 48px rgba(24, 32, 47, 0.08);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 12% -10%, rgba(14, 118, 110, 0.16), transparent 30%),
    radial-gradient(circle at 88% 0%, rgba(124, 58, 237, 0.12), transparent 28%),
    linear-gradient(180deg, #fbfcff 0%, var(--bg) 42%, #f8fafc 100%);
  color: var(--text);
}

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

button {
  cursor: pointer;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 72px;
  padding: 14px clamp(18px, 4vw, 48px);
  border-bottom: 1px solid rgba(223, 229, 238, 0.78);
  background: rgba(255, 255, 255, 0.84);
  backdrop-filter: blur(16px);
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: linear-gradient(135deg, #0e766e, #7c3aed);
  color: #fff;
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  color: var(--muted);
  font-size: 13px;
  margin-top: 2px;
}

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

.nav a,
.icon-text,
.ghost,
.primary {
  min-height: 38px;
  border-radius: 8px;
  border: 1px solid var(--line);
  padding: 8px 14px;
  text-decoration: none;
  color: var(--text);
  background: #fff;
}

.connection-state {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  border: 1px solid #f1d2b8;
  border-radius: 999px;
  padding: 6px 11px;
  color: #9a3412;
  background: #fff7ed;
  font-size: 13px;
  white-space: nowrap;
}

.connection-state::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #f97316;
}

.connection-state.ready {
  border-color: #b7e3d5;
  color: #047857;
  background: #ecfdf5;
}

.connection-state.ready::before {
  background: #10b981;
}

.primary {
  border-color: #111827;
  background: #111827;
  color: #fff;
  font-weight: 700;
  box-shadow: 0 12px 26px rgba(17, 24, 39, 0.18);
}

.ghost:hover,
.nav a:hover,
.icon-text:hover {
  border-color: #b7c1cf;
  background: #f8fafc;
}

main {
  width: min(1380px, calc(100% - 32px));
  margin: 0 auto;
}

.workspace {
  padding: 28px 0 28px;
}

.intro {
  display: grid;
  grid-template-columns: minmax(0, 0.95fr) minmax(360px, 0.75fr);
  gap: 28px;
  align-items: center;
  padding: 24px 0 26px;
}

.intro h1 {
  margin: 0;
  max-width: 760px;
  font-size: clamp(34px, 5.5vw, 64px);
  line-height: 1.08;
  letter-spacing: 0;
}

.intro p {
  margin: 14px 0 0;
  max-width: 720px;
  color: var(--muted);
  line-height: 1.7;
}

.eyebrow {
  margin: 0 0 8px !important;
  color: var(--accent) !important;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.hero-showcase {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  height: 210px;
  align-items: end;
}

.hero-showcase img {
  width: 100%;
  height: 72%;
  border: 1px solid rgba(255, 255, 255, 0.75);
  border-radius: 8px;
  object-fit: cover;
  box-shadow: 0 18px 42px rgba(24, 32, 47, 0.15);
}

.hero-showcase img:nth-child(2) {
  height: 100%;
}

.hero-showcase img:nth-child(3) {
  height: 86%;
}

.hero-showcase img:nth-child(4) {
  height: 62%;
}

.studio-grid {
  display: grid;
  grid-template-columns: minmax(420px, 0.95fr) minmax(440px, 1.05fr);
  gap: 18px;
  align-items: start;
}

.panel,
.content-section,
.settings-dialog {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.panel {
  padding: 22px;
}

.composer,
.preview-panel {
  position: relative;
  overflow: hidden;
}

.composer::before,
.preview-panel::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 4px;
  background: linear-gradient(90deg, var(--accent), #2563eb, var(--accent-2));
}

.mode-tabs {
  display: flex;
  width: fit-content;
  padding: 4px;
  margin-bottom: 18px;
  border-radius: 8px;
  background: var(--surface-2);
}

.mode-tabs button {
  min-width: 72px;
  border: 0;
  border-radius: 7px;
  padding: 7px 16px;
  background: transparent;
  color: var(--muted);
}

.mode-tabs .active {
  color: var(--text);
  background: #fff;
  box-shadow: 0 2px 10px rgba(24, 32, 47, 0.08);
}

.edit-uploader {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 150px;
  gap: 12px;
  margin: 0 0 16px;
}

.upload-box {
  display: grid;
  place-items: center;
  min-height: 150px;
  border: 1px dashed #b9c6d6;
  border-radius: 8px;
  background: #f8fafc;
  color: var(--muted);
  text-align: center;
  cursor: pointer;
}

.upload-box input {
  display: none;
}

.upload-box span {
  color: var(--text);
  font-weight: 800;
}

.upload-box small {
  display: block;
  margin-top: 6px;
}

.edit-preview {
  display: grid;
  min-height: 150px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.edit-preview:empty::before {
  content: "预览";
  display: grid;
  place-items: center;
  color: #98a2b3;
}

.edit-preview img {
  width: 100%;
  height: 120px;
  object-fit: cover;
}

.edit-preview span {
  overflow: hidden;
  padding: 8px;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.field span,
.size-picker legend {
  color: #344054;
  font-size: 13px;
  font-weight: 700;
}

textarea,
input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 11px 12px;
  outline: none;
}

textarea::placeholder,
input::placeholder {
  color: #98a2b3;
}

textarea {
  resize: vertical;
  min-height: 160px;
  line-height: 1.65;
}

textarea:focus,
input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(14, 118, 110, 0.14);
}

.prompt-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0 22px;
}

.prompt-tools .ghost {
  border-color: #d9e2ed;
  background: #fbfdff;
}

.section-title,
.section-head,
.action-row,
.dialog-head,
.dialog-actions,
.section-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.section-title h2,
.section-head h2,
.dialog-head h2 {
  margin: 0;
  font-size: 18px;
}

.section-head p {
  margin: 6px 0 0;
  color: var(--muted);
}

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

.size-picker {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 20px 0 0;
  padding: 0;
  border: 0;
}

.size-picker legend {
  margin-bottom: 10px;
}

.size-picker label {
  position: relative;
}

.size-picker input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.size-picker span {
  display: block;
  min-height: 74px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px;
  background: #fff;
  font-size: 13px;
  font-weight: 700;
}

.size-picker small {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-weight: 500;
}

.size-picker input:checked + span {
  border-color: #111827;
  background: #111827;
  color: #fff;
}

.size-picker input:checked + span small {
  color: #d7dee9;
}

.action-row {
  margin-top: 22px;
}

.status {
  color: var(--muted);
  font-size: 14px;
}

.param-summary {
  margin-top: 6px;
  color: #98a2b3;
  font-size: 12px;
}

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

.status.ok {
  color: var(--accent);
}

.preview-panel {
  min-height: 620px;
}

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

.result-grid.empty {
  display: grid;
  place-items: center;
  min-height: 520px;
  border: 1px dashed #cbd5e1;
  border-radius: 8px;
  color: var(--muted);
  background: #fafcff;
}

.placeholder {
  padding: 18px;
  text-align: center;
}

.image-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.image-card:hover {
  transform: translateY(-2px);
  border-color: #c7d2e0;
  box-shadow: 0 16px 36px rgba(24, 32, 47, 0.12);
}

.image-wrap {
  aspect-ratio: 1 / 1;
  background: #eef2f7;
}

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

.card-body {
  padding: 12px;
}

.card-prompt {
  display: -webkit-box;
  min-height: 42px;
  margin: 0;
  overflow: hidden;
  color: #2d3748;
  line-height: 1.45;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.meta {
  margin: 8px 0 10px;
  color: var(--muted);
  font-size: 12px;
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.card-actions .ghost {
  min-height: 32px;
  padding: 6px 10px;
  font-size: 12px;
}

.favorite.active,
.ghost.active {
  border-color: #b7e3d5;
  color: #047857;
  background: #ecfdf5;
}

.loading-card {
  display: grid;
  place-items: center;
  min-height: 320px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(110deg, #f5f7fb 8%, #eef2f7 18%, #f5f7fb 33%);
  background-size: 200% 100%;
  animation: shimmer 1.2s linear infinite;
  color: var(--muted);
}

.loading-card div {
  width: 62px;
  height: 62px;
  border: 4px solid rgba(14, 118, 110, 0.18);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

.loading-card span {
  margin-top: 12px;
  font-size: 13px;
}

@keyframes shimmer {
  to {
    background-position-x: -200%;
  }
}

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

.content-section {
  margin: 20px 0;
  padding: 22px;
}

.inspiration-section {
  margin-top: 4px;
}

.inspiration-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.inspiration-card {
  position: relative;
  min-height: 240px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  background: #111827;
  color: #fff;
  text-align: left;
}

.inspiration-card img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.24s ease;
}

.inspiration-card::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent 28%, rgba(0, 0, 0, 0.72));
}

.inspiration-card span {
  position: absolute;
  z-index: 1;
  left: 12px;
  right: 12px;
  bottom: 12px;
  font-weight: 800;
  line-height: 1.35;
}

.inspiration-card:hover img {
  transform: scale(1.06);
}

.history-list {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.history-item {
  display: grid;
  grid-template-columns: 92px 1fr auto;
  gap: 14px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.history-item:hover {
  border-color: #c7d2e0;
  background: #fbfdff;
}

.history-item img {
  width: 92px;
  height: 92px;
  border-radius: 8px;
  object-fit: cover;
  background: #eef2f7;
}

.history-item p {
  margin: 0 0 8px;
  line-height: 1.5;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.gallery-grid .image-card:first-child {
  grid-column: span 2;
}

.inspiration-section .gallery-grid .image-card:first-child {
  grid-column: span 1;
}

.publish {
  border-color: #d8c7ff !important;
  color: #5b21b6 !important;
  background: #f5f3ff !important;
}

.empty-note {
  padding: 32px;
  color: var(--muted);
  text-align: center;
  border: 1px dashed #cbd5e1;
  border-radius: 8px;
  background: #fafcff;
}

.settings-dialog {
  width: min(560px, calc(100% - 32px));
  padding: 0;
}

.settings-dialog::backdrop {
  background: rgba(15, 23, 42, 0.36);
}

.settings-dialog form {
  display: grid;
  gap: 18px;
  padding: 22px;
}

.close-button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
}

.check-row input {
  width: auto;
}

@media (max-width: 980px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .nav {
    width: 100%;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .intro {
    grid-template-columns: 1fr;
  }

  .studio-grid {
    grid-template-columns: 1fr;
  }

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

  .hero-showcase {
    height: 180px;
  }
}

@media (max-width: 640px) {
  main {
    width: min(100% - 20px, 1380px);
  }

  .intro h1 {
    font-size: 32px;
  }

  .panel,
  .content-section {
    padding: 16px;
  }

  .form-grid,
  .size-picker,
  .result-grid,
  .gallery-grid,
  .edit-uploader,
  .inspiration-grid {
    grid-template-columns: 1fr;
  }

  .section-head,
  .section-actions,
  .action-row {
    align-items: stretch;
    flex-direction: column;
  }

  .history-item {
    grid-template-columns: 72px 1fr;
  }

  .history-item img {
    width: 72px;
    height: 72px;
  }

  .history-item .card-actions {
    grid-column: 1 / -1;
  }

  .gallery-grid .image-card:first-child {
    grid-column: span 1;
  }

  .hero-showcase {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    height: auto;
  }

  .hero-showcase img,
  .hero-showcase img:nth-child(2),
  .hero-showcase img:nth-child(3),
  .hero-showcase img:nth-child(4) {
    height: 150px;
  }
}
