/* ===== 变量 ===== */
:root {
  --primary: #0052B4;
  --primary-dark: #003d8a;
  --primary-light: #E6F0FF;
  --bg-body: #F0F2F5;
  --bg-card: #FFFFFF;
  --bg-card-hover: #FAFBFC;
  --text-title: #1A1A1A;
  --text-body: #333333;
  --text-muted: #666666;
  --text-placeholder: #999999;
  --border-color: #E8E8E8;
  --border-focus: #0052B4;
  --success: #52C41A;
  --warning: #FAAD14;
  --error: #F5222D;
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.06), 0 2px 8px rgba(0, 0, 0, 0.04);
  --shadow-card-hover: 0 4px 12px rgba(0, 0, 0, 0.08);
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
}

/* ===== 基础 ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg-body);
  color: var(--text-body);
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

/* ===== 顶部导航 ===== */
.navbar {
  background: var(--primary);
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 2px 8px rgba(0, 82, 180, 0.25);
}

.navbar-inner {
  max-width: 720px;
  margin: 0 auto;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

.brand-icon {
  width: 32px;
  height: 32px;
  color: white;
  flex-shrink: 0;
}

.brand-text h1 {
  font-size: 1.1rem;
  font-weight: 600;
  color: white;
  letter-spacing: 0.02em;
}

.brand-text p {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.7);
  margin-top: 2px;
}

/* ===== 主内容 ===== */
.main {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
}

/* ===== 卡片 ===== */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  margin-bottom: 12px;
  display: flex;
  overflow: hidden;
  transition: box-shadow 0.2s ease;
}

.card:hover {
  box-shadow: var(--shadow-card-hover);
}

.card-accent {
  width: 4px;
  background: var(--primary);
  flex-shrink: 0;
}

.card-body {
  flex: 1;
  padding: 16px;
}

.card-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-title);
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.card-title svg {
  width: 18px;
  height: 18px;
  color: var(--primary);
  flex-shrink: 0;
}

.card-title .badge {
  margin-left: auto;
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 500;
}

/* ===== 提示词输入 ===== */
.prompt-wrap {
  position: relative;
}

.prompt-wrap textarea {
  width: 100%;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px 40px 12px 14px;
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--text-body);
  background: #FAFBFC;
  resize: vertical;
  min-height: 90px;
  font-family: inherit;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.prompt-wrap textarea::placeholder {
  color: var(--text-placeholder);
}

.prompt-wrap textarea:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(0, 82, 180, 0.1);
  background: white;
}

.prompt-clear {
  position: absolute;
  right: 8px;
  top: 8px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-placeholder);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.prompt-clear svg {
  width: 14px;
  height: 14px;
}

.prompt-clear:hover {
  background: var(--bg-body);
  color: var(--text-muted);
}

/* ===== 参考图片 ===== */
.ref-images {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-start;
}

.ref-add {
  width: 76px;
  height: 76px;
  border-radius: var(--radius-md);
  border: 1.5px dashed var(--border-color);
  background: #FAFBFC;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
  color: var(--text-muted);
  font-size: 0.75rem;
  flex-shrink: 0;
}

.ref-add svg {
  width: 20px;
  height: 20px;
}

.ref-add:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
}

.ref-item {
  width: 76px;
  height: 76px;
  border-radius: var(--radius-md);
  overflow: hidden;
  position: relative;
  border: 1px solid var(--border-color);
  flex-shrink: 0;
}

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

.ref-item .ref-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: none;
  background: rgba(245, 34, 45, 0.9);
  color: white;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.ref-item:hover .ref-remove {
  opacity: 1;
}

.hint {
  margin-top: 10px;
  font-size: 0.78rem;
  color: var(--text-placeholder);
  line-height: 1.5;
}

.hint a {
  color: var(--primary);
  text-decoration: none;
  margin-left: 4px;
}

.hint a:hover {
  text-decoration: underline;
}

.url-input-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  align-items: center;
}

.url-input-row input {
  flex: 1;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 0.85rem;
  color: var(--text-body);
  font-family: inherit;
  transition: border-color 0.2s ease;
}

.url-input-row input:focus {
  outline: none;
  border-color: var(--border-focus);
}

/* ===== 参数 ===== */
.params {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.param {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.param label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
}

.param select {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.88rem;
  color: var(--text-body);
  background: #FAFBFC;
  font-family: inherit;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23999999' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
  transition: border-color 0.2s ease;
}

.param select:focus {
  outline: none;
  border-color: var(--border-focus);
  background: white;
}

/* ===== 按钮 ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-secondary {
  background: #F0F0F0;
  color: var(--text-muted);
}

.btn-secondary:hover {
  background: #E0E0E0;
}

.btn-sm {
  padding: 6px 14px;
  font-size: 0.8rem;
}

/* ===== 生成按钮 ===== */
.generate-btn {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: var(--radius-lg);
  background: var(--primary);
  color: white;
  font-size: 1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 4px 12px rgba(0, 82, 180, 0.25);
  margin-bottom: 12px;
}

.generate-btn svg {
  width: 20px;
  height: 20px;
}

.generate-btn:hover {
  background: var(--primary-dark);
  box-shadow: 0 6px 16px rgba(0, 82, 180, 0.3);
}

.generate-btn:active {
  transform: translateY(1px);
}

.generate-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.generate-btn.generating {
  background: var(--primary-dark);
}

/* ===== 结果 ===== */
.result-wrap {
  animation: fadeInUp 0.35s ease;
}

.result-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.result-grid.multiple {
  grid-template-columns: 1fr 1fr;
}

.result-cell {
  position: relative;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border-color);
  cursor: pointer;
  aspect-ratio: 1;
  background: #FAFBFC;
}

.result-cell img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.result-cell:hover img {
  transform: scale(1.02);
}

.result-actions {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 10px;
  display: flex;
  gap: 8px;
  justify-content: center;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.5), transparent);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.result-cell:hover .result-actions {
  opacity: 1;
}

.result-action {
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  border: none;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(4px);
  color: var(--text-body);
  font-size: 0.78rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all 0.2s ease;
  text-decoration: none;
}

.result-action:hover {
  background: white;
}

.result-action svg {
  width: 14px;
  height: 14px;
}

/* ===== 历史记录 ===== */
.history-wrap {
  margin-top: 4px;
}

.history-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 4px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.history-header svg {
  width: 16px;
  height: 16px;
}

.history-clear {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--text-placeholder);
  font-size: 0.78rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: all 0.2s ease;
}

.history-clear:hover {
  color: var(--error);
  background: rgba(245, 34, 45, 0.06);
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s ease;
}

.history-row:hover {
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(0, 82, 180, 0.08);
}

.history-thumb {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  flex-shrink: 0;
  border: 1px solid var(--border-color);
  background: #FAFBFC;
}

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

.history-info {
  flex: 1;
  min-width: 0;
}

.history-prompt {
  font-size: 0.85rem;
  color: var(--text-title);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
}

.history-meta {
  font-size: 0.75rem;
  color: var(--text-placeholder);
  margin-top: 2px;
}

/* ===== 加载 ===== */
.loading-mask {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(240, 242, 245, 0.92);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}

.loading-box {
  text-align: center;
  padding: 40px;
  background: white;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card-hover);
}

.loading-spinner {
  width: 48px;
  height: 48px;
  margin: 0 auto 16px;
  border-radius: 50%;
  border: 3px solid var(--primary-light);
  border-top-color: var(--primary);
  animation: spin 0.8s linear infinite;
}

.loading-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-title);
  margin-bottom: 4px;
}

.loading-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.loading-bar {
  width: 180px;
  height: 4px;
  background: var(--border-color);
  border-radius: 2px;
  margin: 16px auto 6px;
  overflow: hidden;
}

.loading-fill {
  height: 100%;
  width: 0%;
  background: var(--primary);
  border-radius: 2px;
  transition: width 0.5s ease;
}

.loading-percent {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ===== 预览 ===== */
.preview-mask {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
}

.preview-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(6px);
  animation: fadeIn 0.2s ease;
}

.preview-box {
  position: relative;
  z-index: 1;
  max-width: 92vw;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: zoomIn 0.25s ease;
}

.preview-box img {
  max-width: 100%;
  max-height: 72vh;
  border-radius: var(--radius-md);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.preview-close {
  position: absolute;
  top: -44px;
  right: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.15);
  color: white;
  font-size: 1.6rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  line-height: 1;
  padding-bottom: 2px;
}

.preview-close:hover {
  background: rgba(255, 255, 255, 0.25);
}

.preview-actions {
  margin-top: 16px;
}

.preview-download {
  padding: 10px 24px;
  border-radius: var(--radius-md);
  background: var(--primary);
  color: white;
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.2s ease;
}

.preview-download:hover {
  background: var(--primary-dark);
}

.preview-download svg {
  width: 16px;
  height: 16px;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  z-index: 400;
  padding: 10px 20px;
  border-radius: var(--radius-lg);
  background: white;
  border: 1px solid var(--border-color);
  color: var(--text-body);
  font-size: 0.88rem;
  box-shadow: var(--shadow-card-hover);
  opacity: 0;
  transition: all 0.3s ease;
  pointer-events: none;
  max-width: 90vw;
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.success {
  border-color: rgba(82, 196, 26, 0.4);
  background: rgba(82, 196, 26, 0.08);
  color: var(--success);
}

.toast.error {
  border-color: rgba(245, 34, 45, 0.3);
  background: rgba(245, 34, 45, 0.06);
  color: var(--error);
}

.toast.warning {
  border-color: rgba(250, 173, 20, 0.4);
  background: rgba(250, 173, 20, 0.08);
  color: var(--warning);
}

/* ===== 动画 ===== */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

@keyframes zoomIn {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

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

/* ===== 响应式 ===== */
@media (min-width: 640px) {
  .main {
    padding: 20px 24px 40px;
  }

  .navbar-inner {
    padding: 16px 24px;
  }

  .result-grid.multiple {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ===== 滚动条 ===== */
::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: #D9D9D9;
  border-radius: 2px;
}

::-webkit-scrollbar-thumb:hover {
  background: #BFBFBF;
}

/* ===== 选中 ===== */
::selection {
  background: rgba(0, 82, 180, 0.15);
  color: var(--primary-dark);
}
