*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #06060a;
  --surface: rgba(255, 255, 255, 0.03);
  --surface-hover: rgba(255, 255, 255, 0.06);
  --surface-active: rgba(255, 255, 255, 0.08);
  --glass: rgba(255, 255, 255, 0.04);
  --glass-border: rgba(255, 255, 255, 0.08);
  --text: #e4e4e9;
  --text2: #71717a;
  --text3: #52525b;
  --accent: #3b82f6;
  --accent-glow: rgba(59, 130, 246, 0.25);
  --accent-hover: #60a5fa;
  --accent-dim: rgba(59, 130, 246, 0.12);
  --success: #22c55e;
  --error: #ef4444;
  --radius: 12px;
  --radius-sm: 8px;
  --font-heading: 'Space Grotesk', system-ui, sans-serif;
  --font-body: 'DM Sans', system-ui, sans-serif;
}

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* Background gradient mesh */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 60% 50% at 10% 20%, rgba(59, 130, 246, 0.08), transparent),
    radial-gradient(ellipse 50% 40% at 80% 70%, rgba(14, 165, 233, 0.06), transparent),
    radial-gradient(ellipse 40% 30% at 50% 50%, rgba(99, 102, 241, 0.04), transparent);
  pointer-events: none;
  z-index: 0;
}

/* --- Top bar --- */
.top-bar {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--glass-border);
  background: rgba(6, 6, 10, 0.7);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.brand {
  font-family: var(--font-heading);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.5px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
  display: inline-block;
}

.wechat-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 20px;
  border-radius: 24px;
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.2), rgba(14, 165, 233, 0.15));
  border: 1px solid rgba(59, 130, 246, 0.35);
  color: #93c5fd;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.25s;
  box-shadow: 0 0 20px rgba(59, 130, 246, 0.15);
  animation: badge-pulse 3s ease-in-out infinite;
}

@keyframes badge-pulse {
  0%, 100% { box-shadow: 0 0 20px rgba(59, 130, 246, 0.15); }
  50% { box-shadow: 0 0 28px rgba(59, 130, 246, 0.3); }
}

.wechat-badge:hover {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.3), rgba(14, 165, 233, 0.25));
  border-color: rgba(59, 130, 246, 0.55);
  transform: translateY(-1px);
}

.wechat-badge strong {
  color: #bfdbfe;
  font-weight: 700;
  font-size: 15px;
}

.top-right {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
}

.qr-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: 1px solid rgba(59, 130, 246, 0.3);
  border-radius: 10px;
  background: var(--accent-dim);
  color: var(--accent-hover);
  cursor: pointer;
  transition: all 0.25s;
  box-shadow: 0 0 16px rgba(59, 130, 246, 0.12);
  animation: qr-pulse 2.5s ease-in-out infinite;
}

@keyframes qr-pulse {
  0%, 100% { box-shadow: 0 0 16px rgba(59, 130, 246, 0.12); border-color: rgba(59, 130, 246, 0.3); }
  50% { box-shadow: 0 0 24px rgba(59, 130, 246, 0.3); border-color: rgba(59, 130, 246, 0.5); }
}

.qr-btn:hover {
  background: rgba(59, 130, 246, 0.2);
  border-color: rgba(59, 130, 246, 0.6);
  transform: scale(1.05);
}

.qr-popup {
  position: absolute;
  top: calc(100% + 12px);
  right: 0;
  background: rgba(15, 15, 25, 0.95);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 100;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.qr-popup.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.qr-popup img {
  width: 180px;
  height: 180px;
  border-radius: 8px;
  object-fit: cover;
  display: block;
}

.qr-popup p {
  margin-top: 10px;
  font-size: 12px;
  color: var(--text2);
  font-weight: 500;
}

/* --- Main layout --- */
.main-layout {
  position: relative;
  z-index: 1;
  display: flex;
  height: calc(100vh - 57px);
  overflow: hidden;
}

/* --- Left input panel --- */
.input-panel {
  width: 400px;
  min-width: 360px;
  padding: 24px 20px;
  border-right: 1px solid var(--glass-border);
  background: rgba(6, 6, 10, 0.5);
  backdrop-filter: blur(10px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.input-panel::-webkit-scrollbar {
  width: 4px;
}
.input-panel::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 2px;
}

.field label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text);
}

.field label svg {
  color: var(--text2);
}

.hint {
  font-weight: 400;
  color: var(--text3);
  font-size: 12px;
  margin-left: auto;
}

/* Key input */
.key-row {
  display: flex;
  gap: 8px;
}

.key-row input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  background: var(--glass);
  color: var(--text);
  font-size: 14px;
  font-family: var(--font-body);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.key-row input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.key-row input::placeholder {
  color: var(--text3);
}

.quota-info {
  margin-top: 8px;
  font-size: 13px;
  color: var(--text2);
}

.quota-bar-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.quota-bar {
  flex: 1;
  height: 4px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 2px;
  overflow: hidden;
}

.quota-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-hover));
  border-radius: 2px;
  transition: width 0.4s ease;
}

.quota-bar-wrap span {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.quota-bar-wrap strong {
  color: var(--accent-hover);
  font-weight: 700;
}

/* Textarea */
textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  background: var(--glass);
  color: var(--text);
  font-size: 14px;
  font-family: var(--font-body);
  line-height: 1.6;
  resize: vertical;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

textarea::placeholder {
  color: var(--text3);
}

/* Select dropdown */
.select-wrap {
  position: relative;
}

.select-wrap select {
  width: 100%;
  padding: 10px 36px 10px 14px;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  background: var(--glass);
  color: var(--text);
  font-size: 14px;
  font-family: var(--font-body);
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.select-wrap select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.select-wrap select option {
  background: #1a1a2e;
  color: var(--text);
}

.select-arrow {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text3);
  pointer-events: none;
}

/* Upload area */
.upload-area {
  border: 1.5px dashed rgba(255, 255, 255, 0.1);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.25s;
  position: relative;
  min-height: 100px;
  background: var(--glass);
}

.upload-area:hover {
  border-color: rgba(59, 130, 246, 0.4);
  background: var(--surface-hover);
}

.upload-placeholder {
  color: var(--text3);
}

.upload-placeholder svg {
  color: var(--text3);
  margin-bottom: 8px;
}

.upload-placeholder p {
  font-size: 12px;
  color: var(--text3);
}

.preview-img {
  max-width: 100%;
  max-height: 180px;
  border-radius: 8px;
  object-fit: contain;
}

/* Buttons */
.btn-outline {
  padding: 10px 18px;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font-body);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.btn-outline:hover {
  border-color: var(--accent);
  color: var(--accent-hover);
  background: var(--accent-dim);
}

.btn-outline:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-text {
  padding: 0;
  border: none;
  background: none;
  color: var(--text2);
  font-size: 12px;
  font-family: var(--font-body);
  cursor: pointer;
  transition: color 0.2s;
  margin-top: 6px;
}

.btn-text:hover {
  color: var(--error);
}

.btn-generate {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--accent), #1d4ed8);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  font-family: var(--font-body);
  cursor: pointer;
  transition: all 0.25s;
  margin-top: auto;
  box-shadow: 0 4px 24px var(--accent-glow);
  position: relative;
  overflow: hidden;
}

.btn-generate::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, transparent, rgba(255,255,255,0.1));
  opacity: 0;
  transition: opacity 0.25s;
}

.btn-generate:hover:not(:disabled)::before {
  opacity: 1;
}

.btn-generate:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 32px rgba(59, 130, 246, 0.35);
}

.btn-generate:active:not(:disabled) {
  transform: translateY(0);
}

.btn-generate:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  box-shadow: none;
}

.btn-action {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-family: var(--font-body);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}

.btn-action:hover {
  border-color: rgba(59, 130, 246, 0.3);
  background: var(--surface-hover);
  color: var(--accent-hover);
}

/* --- Right result panel --- */
.result-panel {
  flex: 1;
  padding: 32px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

.result-panel::-webkit-scrollbar {
  width: 4px;
}
.result-panel::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.06);
  border-radius: 2px;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  gap: 8px;
  text-align: center;
}

.empty-icon {
  color: var(--text3);
  margin-bottom: 8px;
  opacity: 0.5;
}

.empty-state p {
  color: var(--text2);
  font-size: 15px;
  font-weight: 500;
}

.empty-state span {
  color: var(--text3);
  font-size: 13px;
}

/* Progress */
.progress-card {
  width: 100%;
  max-width: 560px;
  display: flex;
  align-items: flex-start;
  gap: 16px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 20px;
}

.progress-icon {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 2.5px solid rgba(59, 130, 246, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.progress-body {
  flex: 1;
  min-width: 0;
}

.progress-header {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 12px;
}

.progress-header span:last-child {
  color: var(--accent-hover);
  font-variant-numeric: tabular-nums;
}

.progress-bar {
  width: 100%;
  height: 4px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 2px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-hover), #38bdf8);
  background-size: 200% 100%;
  border-radius: 2px;
  width: 0%;
  transition: width 0.6s ease;
  animation: shimmer 2s linear infinite;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.progress-hint {
  margin-top: 10px;
  font-size: 12px;
  color: var(--text3);
}

/* Result image */
.result-card {
  width: 100%;
  max-width: 560px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 12px;
  text-align: center;
  animation: fadeIn 0.4s ease;
}

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

.result-img-wrap {
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: rgba(0, 0, 0, 0.3);
}

.result-card img {
  max-width: 100%;
  max-height: 65vh;
  object-fit: contain;
  display: block;
  margin: 0 auto;
}

.result-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 14px;
}

/* History */
.history-section {
  width: 100%;
  max-width: 560px;
}

.history-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 12px;
  color: var(--text2);
}

.history-header svg {
  color: var(--text3);
}

.history-header h3 {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

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

.history-item {
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: pointer;
  border: 1px solid var(--glass-border);
  transition: all 0.2s;
  background: rgba(0, 0, 0, 0.2);
}

.history-item:hover {
  border-color: rgba(59, 130, 246, 0.4);
  transform: scale(1.03);
}

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

/* Toast */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  padding: 10px 22px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  z-index: 999;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  opacity: 0;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

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

.toast.error {
  background: rgba(239, 68, 68, 0.15);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.25);
}

.toast.success {
  background: rgba(34, 197, 94, 0.15);
  color: #86efac;
  border: 1px solid rgba(34, 197, 94, 0.25);
}

.toast.info {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border: 1px solid var(--glass-border);
}

/* Hidden */
.hidden {
  display: none !important;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* Responsive */
@media (max-width: 768px) {
  .top-bar {
    padding: 12px 16px;
    flex-wrap: wrap;
    gap: 8px;
  }

  .wechat-badge {
    font-size: 12px;
    padding: 6px 12px;
  }

  .wechat-badge strong {
    font-size: 13px;
  }

  .qr-popup {
    right: -8px;
  }

  .qr-popup img {
    width: 150px;
    height: 150px;
  }

  .main-layout {
    flex-direction: column;
    height: auto;
  }

  .input-panel {
    width: 100%;
    min-width: unset;
    border-right: none;
    border-bottom: 1px solid var(--glass-border);
    max-height: none;
    overflow: visible;
    padding: 20px 16px;
    gap: 16px;
  }

  .result-panel {
    min-height: 50vh;
    padding: 20px 16px;
  }

  .progress-card {
    max-width: 100%;
  }

  .result-card {
    max-width: 100%;
  }

  .history-section {
    max-width: 100%;
  }
}
