:root {
  --bg: #120f10;
  --panel: rgba(33, 28, 29, 0.92);
  --ink: #f3eeea;
  --muted: #a89d95;
  --line: rgba(255, 255, 255, 0.08);
  --accent: #4b89ff;
  --accent-soft: rgba(75, 137, 255, 0.18);
  --radius-lg: 20px;
  --radius-md: 14px;
  --font-display: "Avenir Next", "Segoe UI", "PingFang SC", "Hiragino Sans GB", sans-serif;
  --font-body: "Source Han Sans SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

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

body {
  font-family: var(--font-body);
  color: var(--ink);
  background:
    linear-gradient(rgba(255,255,255,0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.04) 1px, transparent 1px),
    radial-gradient(circle at top center, rgba(75,137,255,0.12), transparent 28%),
    var(--bg);
  background-size: 30px 30px, 30px 30px, auto, auto;
}

/* ---------- layout ---------- */
.app {
  width: min(1000px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 40px 0 60px;
}

.header {
  text-align: center;
  margin-bottom: 36px;
}

.header h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(28px, 5vw, 42px);
  line-height: 1.1;
}

.subtitle {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 15px;
}

.main {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 24px;
  border-radius: var(--radius-lg);
  background: var(--panel);
  border: 1px solid var(--line);
}

/* ---------- mode tabs ---------- */
.mode-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  gap: 8px;
}

.mode-tab {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 14px;
  background: rgba(255,255,255,0.03);
  color: var(--muted);
  font: inherit;
  font-size: 16px;
  cursor: pointer;
  transition: all 180ms ease;
}

.mode-tab.active {
  border-color: rgba(75,137,255,0.48);
  color: #d7e5ff;
  background: rgba(75,137,255,0.16);
}

.mode-icon { font-size: 20px; }

/* ---------- form ---------- */
.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

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

textarea, input, select {
  font: inherit;
  width: 100%;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius-md);
  background: rgba(255,255,255,0.04);
  color: var(--ink);
  padding: 12px 14px;
  outline: none;
  min-height: 46px;
}

textarea {
  min-height: 120px;
  resize: vertical;
}

textarea:focus, input:focus, select:focus {
  border-color: rgba(75,137,255,0.42);
  box-shadow: 0 0 0 4px rgba(75,137,255,0.14);
}

.config-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.source-previews {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.source-preview-item {
  position: relative;
}

.source-previews img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: var(--radius-md);
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.06);
}

.source-preview-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 20px;
  height: 20px;
  border: 0;
  border-radius: 50%;
  background: rgba(0,0,0,0.55);
  color: #fff;
  font-size: 12px;
  line-height: 20px;
  text-align: center;
  cursor: pointer;
}

.source-preview-remove:hover {
  background: rgba(220,50,50,0.85);
}

/* ---------- button ---------- */
.primary {
  border: 0;
  border-radius: 999px;
  min-height: 48px;
  padding: 0 24px;
  cursor: pointer;
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  color: #191617;
  background: linear-gradient(135deg, #f9f7f2, #dbd6cd);
  box-shadow: 0 10px 24px rgba(255,255,255,0.12);
  transition: transform 180ms ease, filter 180ms ease, opacity 180ms ease;
}

.primary:hover { transform: translateY(-1px); }
.primary:disabled { opacity: 0.55; cursor: wait; transform: none; }

.secondary {
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 999px;
  min-height: 40px;
  padding: 0 20px;
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  background: rgba(255,255,255,0.06);
  transition: background 180ms ease, border-color 180ms ease;
}

.secondary:hover {
  background: rgba(255,255,255,0.12);
  border-color: rgba(255,255,255,0.25);
}

.result-actions {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}

.status {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}

/* ---------- result ---------- */
.result {
  padding-top: 8px;
}

.result h2 {
  margin: 0 0 12px;
  font-size: 18px;
}

.result img {
  width: 100%;
  max-height: 480px;
  object-fit: contain;
  border-radius: var(--radius-lg);
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.06);
}

/* ---------- history ---------- */
.history-lock {
  text-align: center;
  padding: 40px 0;
}

.history-lock-row {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.history-lock input {
  width: auto;
  min-width: 200px;
}

.history-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}

.history-card {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: rgba(255,255,255,0.03);
  transition: border-color 180ms ease;
}

.history-card:hover {
  border-color: rgba(255,255,255,0.18);
}

.history-delete {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 50%;
  background: rgba(0,0,0,0.55);
  color: #fff;
  font-size: 13px;
  line-height: 24px;
  text-align: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 150ms ease, background 150ms ease;
}

.history-card:hover .history-delete {
  opacity: 1;
}

.history-delete:hover {
  background: rgba(220,50,50,0.85);
}

.history-card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
}

.history-info {
  padding: 8px 10px;
}

.history-name {
  margin: 0;
  font-size: 12px;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-time {
  margin: 4px 0 6px;
  font-size: 11px;
  color: var(--muted);
}

.history-download {
  display: inline-block;
  font-size: 12px;
  color: var(--accent);
  text-decoration: none;
}

.history-download:hover {
  text-decoration: underline;
}

/* ---------- prompt library ---------- */
.prompt-library {
  margin: 0;
}

.prompt-library iframe {
  width: 100%;
  height: calc(100vh - 170px);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: #fff;
  display: block;
}

/* ---------- responsive ---------- */
@media (min-width: 768px) {
  .app { padding: 56px 0 80px; }
  .result img { max-height: 640px; }
  .history-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
}

@media (max-width: 640px) {
  .app { padding-top: 20px; }
  .config-row { grid-template-columns: 1fr; }
  .result img { max-height: 320px; }
}
