:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #242836;
  --border: #2e3344;
  --text: #e8eaef;
  --muted: #8b92a5;
  --primary: #4f8cff;
  --primary-hover: #3d7aef;
  --success: #34c759;
  --radius: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

.app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 20px 48px;
}

header {
  text-align: center;
  margin-bottom: 32px;
}

header h1 {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.subtitle {
  color: var(--muted);
  margin-top: 6px;
  font-size: 14px;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

@media (max-width: 900px) {
  .grid { grid-template-columns: 1fr; }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.panel h2 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 20px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.field span { font-size: 13px; font-weight: 500; }

.field small { color: var(--muted); font-size: 12px; }

.field input,
.field select,
.field textarea {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 12px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--primary);
}

.field textarea { resize: vertical; font-family: inherit; }

.field.checkbox {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.field.checkbox input { width: auto; }

.row { display: flex; gap: 12px; }
.flex1 { flex: 1; }

#promptTemplate {
  font-size: 13px;
  line-height: 1.6;
  min-height: 220px;
}

.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  margin-bottom: 16px;
  overflow: hidden;
  position: relative;
}

.upload-zone:hover,
.upload-zone.dragover {
  border-color: var(--primary);
  background: rgba(79, 140, 255, 0.05);
}

.upload-placeholder {
  text-align: center;
  color: var(--muted);
  padding: 24px;
}

.upload-placeholder svg { margin-bottom: 8px; opacity: 0.5; }

.preview {
  max-width: 100%;
  max-height: 280px;
  object-fit: contain;
}

.hidden { display: none !important; }

.actions {
  display: flex;
  gap: 10px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, opacity 0.15s;
}

.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn.primary {
  flex: 1;
  background: var(--primary);
  color: #fff;
}

.btn.primary.full {
  width: 100%;
  flex: none;
}

.btn.primary:hover:not(:disabled) { background: var(--primary-hover); }

.btn.secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn.secondary:hover { background: var(--border); }

.progress-box {
  margin-bottom: 16px;
  padding: 14px 16px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.progress-bar {
  height: 6px;
  background: var(--surface2);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--primary);
  border-radius: 3px;
  transition: width 0.3s;
}

#progressText {
  font-size: 13px;
  color: var(--muted);
  margin-top: 8px;
}

.result-view {
  min-height: 360px;
  background: var(--surface2);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.result-pane { width: 100%; text-align: center; padding: 16px; }

.result-pane img {
  max-width: 100%;
  max-height: 480px;
  object-fit: contain;
  border-radius: 8px;
}

.empty-state {
  color: var(--muted);
  font-size: 14px;
  padding: 60px 20px;
}

.download-bar {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.download-bar .btn { flex: 1; }

.history-section {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.history-section h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 12px;
}

.history-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 12px;
  max-height: 320px;
  overflow-y: auto;
}

.history-empty {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  padding: 24px 12px;
}

.history-item {
  position: relative;
  background: var(--surface2);
  border: 2px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}

.history-item:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
}

.history-item.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary);
}

.history-item img {
  width: 100%;
  aspect-ratio: 2/3;
  object-fit: cover;
  display: block;
}

.history-info {
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.history-time {
  font-size: 11px;
  color: var(--muted);
}

.history-meta {
  font-size: 11px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-delete {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 2;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s;
}

.history-item:hover .history-delete,
.history-delete:focus {
  opacity: 1;
}

.history-delete:hover {
  background: #e5484d;
}
