/* ===== Design Tokens ===== */
:root {
  --bg: #0a0a0f;
  --bg-card: rgba(18, 18, 26, 0.72);
  --bg-card-solid: #12121a;
  --glass: rgba(255, 255, 255, 0.04);
  --glass-border: rgba(255, 255, 255, 0.08);
  --glass-hover: rgba(255, 255, 255, 0.07);
  --text: #f0ece4;
  --text-secondary: rgba(240, 236, 228, 0.6);
  --accent: #e2b96f;
  --accent-dim: rgba(226, 185, 111, 0.15);
  --accent-glow: rgba(226, 185, 111, 0.35);
  --success: #6dd59c;
  --success-dim: rgba(109, 213, 156, 0.12);
  --error: #f07070;
  --error-dim: rgba(240, 112, 112, 0.12);
  --radius: 20px;
  --radius-sm: 12px;
  --radius-xs: 8px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.45);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }

body {
  min-height: 100vh;
  min-height: 100dvh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* Ambient background */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 60% 50% at 20% 10%, rgba(226, 185, 111, 0.08), transparent),
    radial-gradient(ellipse 50% 40% at 80% 20%, rgba(180, 130, 60, 0.06), transparent),
    radial-gradient(ellipse 40% 30% at 50% 90%, rgba(100, 70, 30, 0.04), transparent);
  pointer-events: none;
  z-index: 0;
}

img { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }
button, input { font: inherit; }

/* ===== App Shell ===== */
.app-shell {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 480px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: 0 16px;
}

/* ===== Header ===== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  padding: 0 4px;
  background: rgba(10, 10, 15, 0.85);
  backdrop-filter: blur(20px) saturate(1.4);
  -webkit-backdrop-filter: blur(20px) saturate(1.4);
}

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

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: linear-gradient(135deg, #f4d49a, #c49245);
  box-shadow: 0 0 16px var(--accent-glow);
  animation: pulse-glow 2.5s ease-in-out infinite alternate;
}

.brand-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.5px;
}

.header-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 12px;
  border-radius: 100px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  color: var(--text-secondary);
  font-size: 0.75rem;
}

/* ===== Main Content ===== */
.app-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 12px 0 100px;
}

/* ===== Upload Section ===== */
.upload-section {
  display: flex;
  flex-direction: column;
  gap: 20px;
  animation: fade-up 500ms var(--ease) both;
}

.upload-hero {
  text-align: center;
  padding: 28px 16px 8px;
}

.upload-hero-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--accent-dim);
  border: 1px solid rgba(226, 185, 111, 0.2);
  color: var(--accent);
  margin-bottom: 16px;
}

.upload-title {
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.2;
  background: linear-gradient(135deg, #f5e6c8, #d4a85d);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.upload-desc {
  margin-top: 8px;
  font-size: 0.92rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

/* Dropzone */
.dropzone {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 220px;
  border-radius: var(--radius);
  border: 1.5px dashed rgba(226, 185, 111, 0.3);
  background:
    linear-gradient(180deg, rgba(226, 185, 111, 0.04), transparent),
    var(--bg-card);
  cursor: pointer;
  transition: all 280ms var(--ease);
  position: relative;
  overflow: hidden;
}

.dropzone::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 50%, rgba(226, 185, 111, 0.06), transparent 70%);
  opacity: 0;
  transition: opacity 280ms var(--ease);
}

.dropzone:hover::before,
.dropzone.is-dragover::before {
  opacity: 1;
}

.dropzone.is-dragover {
  border-color: var(--accent);
  transform: scale(1.01);
  box-shadow: 0 0 40px rgba(226, 185, 111, 0.12);
}

.dropzone-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  position: relative;
  z-index: 1;
}

.dropzone-icon {
  color: var(--accent);
  opacity: 0.7;
}

.dropzone-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--accent);
  opacity: 0.8;
}

.dropzone-hint {
  font-size: 0.88rem;
  color: var(--text-secondary);
}

/* Upload buttons */
.upload-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* Feature tags */
.feature-tags {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 32px;
  padding: 0 12px;
  border-radius: 100px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  color: var(--text-secondary);
  font-size: 0.78rem;
}

.tag svg { color: var(--accent); opacity: 0.7; }

/* ===== Buttons ===== */
.action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 48px;
  padding: 0 20px;
  border-radius: 14px;
  border: 1px solid var(--glass-border);
  background: var(--glass);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 200ms var(--ease);
  position: relative;
  overflow: hidden;
}

.action-btn:hover {
  background: var(--glass-hover);
  transform: translateY(-1px);
}

.action-btn:active {
  transform: scale(0.97);
}

.action-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.action-btn.primary {
  background: linear-gradient(135deg, #f0cd8d, #b8873e);
  color: #1a1408;
  font-weight: 700;
  border: none;
  box-shadow: 0 8px 24px rgba(226, 185, 111, 0.25);
}

.action-btn.primary::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(110deg, transparent 30%, rgba(255, 255, 255, 0.3) 50%, transparent 70%);
  transform: translateX(-120%);
  animation: sheen 3.5s ease-in-out infinite;
}

.action-btn.primary:disabled {
  box-shadow: none;
}

.action-btn.primary:disabled::after {
  animation: none;
}

.action-btn.primary > * { position: relative; z-index: 1; }

.action-btn.ghost {
  background: transparent;
  border-color: rgba(255, 255, 255, 0.12);
}

.text-btn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 0.88rem;
  padding: 4px 8px;
}

/* ===== Preview Section ===== */
.preview-section {
  animation: fade-up 400ms var(--ease) both;
}

.preview-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.preview-image-wrap {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-card-solid);
  border: 1px solid var(--glass-border);
}

.preview-image-wrap img {
  width: 100%;
  max-height: 420px;
  object-fit: cover;
  display: block;
  transition: filter 300ms var(--ease);
}

/* Image overlay (progress / detection) */
.image-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  background: linear-gradient(180deg, rgba(10, 10, 15, 0.1) 0%, rgba(10, 10, 15, 0.75) 100%);
  z-index: 2;
}

.image-overlay[hidden] { display: none; }

.overlay-progress {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: rgba(255, 255, 255, 0.1);
}

.overlay-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #c49245, #f0cd8d);
  border-radius: 0 2px 2px 0;
  transition: width 350ms var(--ease);
  box-shadow: 0 0 12px var(--accent-glow);
}

.overlay-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px;
}

.overlay-spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid rgba(226, 185, 111, 0.2);
  border-top-color: var(--accent);
  animation: spin 700ms linear infinite;
  flex-shrink: 0;
}

.overlay-label {
  flex: 1;
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.9);
  font-weight: 500;
}

.overlay-percent {
  font-size: 0.82rem;
  color: var(--accent);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* Status badge on image */
.image-status-badge {
  position: absolute;
  top: 12px;
  left: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border-radius: 100px;
  background: rgba(10, 10, 15, 0.75);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  font-size: 0.78rem;
  font-weight: 500;
  z-index: 3;
  animation: fade-in 250ms var(--ease) both;
}

.image-status-badge[hidden] { display: none; }

.image-status-badge.is-success {
  color: var(--success);
  border-color: rgba(109, 213, 156, 0.2);
}

.image-status-badge.is-error {
  color: var(--error);
  border-color: rgba(240, 112, 112, 0.2);
}

.image-status-badge.is-detecting {
  color: var(--accent);
  border-color: rgba(226, 185, 111, 0.2);
}

.badge-icon {
  font-size: 0.9rem;
  line-height: 1;
}

/* Preview actions */
.preview-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* ===== Result Section ===== */
.result-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: fade-up 400ms var(--ease) both;
}

.result-section[hidden] { display: none; }

.result-card {
  border-radius: var(--radius);
  background: var(--bg-card);
  border: 1px solid var(--glass-border);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.result-status-bar {
  display: flex;
  align-items: center;
  height: 44px;
  padding: 0 16px;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--accent);
  background: var(--accent-dim);
  border-bottom: 1px solid rgba(226, 185, 111, 0.1);
  transition: all 250ms var(--ease);
}

.result-body {
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 120px;
}

.result-body h3 {
  font-size: 1.1rem;
  font-weight: 600;
  line-height: 1.4;
}

.result-body p {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.65;
  margin: 0;
}

.result-body.empty {
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 16px;
}

.result-body.generated {
  align-items: stretch;
  min-height: auto;
  animation: fade-up 350ms var(--ease) both;
}

.result-body.locked .generated-image {
  filter: saturate(0.9);
}

.result-body.unlocked .generated-image-wrap {
  border-color: rgba(226, 185, 111, 0.2);
}

/* Generated result image */
.generated-image-wrap {
  position: relative;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #08080c;
  border: 1px solid var(--glass-border);
}

.generated-image {
  width: 100%;
  max-height: 500px;
  object-fit: contain;
}

/* Lock overlay */
.result-lock {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 10px;
  padding: 16px;
  border-radius: var(--radius-sm);
  background: rgba(10, 10, 15, 0.88);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  animation: slide-up 350ms var(--ease) both;
}

.lock-copy {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
}

.lock-copy span {
  font-size: 0.78rem;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.lock-copy h3 {
  font-size: 1rem;
  font-weight: 600;
}

.lock-copy p {
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin: 0;
}

.lock-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.lock-actions .action-btn {
  width: 100%;
  height: 44px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
}

.lock-actions .pay-button {
  background: linear-gradient(135deg, #f0cd8d, #b8873e);
  color: #1a1408;
  border: none;
  font-weight: 600;
}

.lock-actions .wechat-pay-button {
  background: linear-gradient(135deg, #66d476, #48a850);
  color: #0e2e11;
  border: none;
  font-weight: 600;
}

/* Generating overlay */
.result-generating {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  text-align: center;
  background: rgba(10, 10, 15, 0.8);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.result-generating-core {
  width: 80px;
  height: 80px;
  position: relative;
}

.generating-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1px solid rgba(226, 185, 111, 0.2);
  animation: ring-pulse 1.8s var(--ease) infinite;
}

.ring-b { animation-delay: 250ms; }
.ring-c { animation-delay: 500ms; }

.generating-dot {
  position: absolute;
  inset: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, #f0cd8d, #b8873e);
  box-shadow: 0 0 30px var(--accent-glow);
  animation: dot-pulse 1s ease-in-out infinite alternate;
}

.result-generating-copy {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 280px;
}

.result-generating-copy span {
  font-size: 0.78rem;
  color: var(--accent);
}

.result-generating-copy h3 {
  font-size: 1rem;
  font-weight: 600;
}

.result-generating-copy p {
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin: 0;
}

/* Result copy section */
.result-copy {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.result-actions .action-btn {
  flex: 1;
  min-width: 120px;
  height: 44px;
  border-radius: var(--radius-sm);
}

/* ===== History ===== */
.history-card {
  border-radius: var(--radius);
  background: var(--bg-card);
  border: 1px solid var(--glass-border);
  padding: 16px;
  box-shadow: var(--shadow);
}

.history-card[hidden] { display: none; }

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.history-header h3 {
  font-size: 0.95rem;
  font-weight: 600;
}

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

.history-item {
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: 12px;
  align-items: center;
  padding: 8px;
  border-radius: var(--radius-sm);
  background: var(--glass);
  border: 1px solid var(--glass-border);
  cursor: pointer;
  transition: background 200ms var(--ease);
  width: 100%;
  text-align: left;
  color: var(--text);
}

.history-item:hover {
  background: var(--glass-hover);
}

.history-item img {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-xs);
  object-fit: cover;
}

.history-item span {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.history-item strong {
  font-size: 0.88rem;
  font-weight: 500;
}

.history-item small {
  font-size: 0.78rem;
  color: var(--text-secondary);
}

/* ===== Privacy Bar ===== */
.privacy-bar {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: 420px;
  width: calc(100% - 32px);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: rgba(10, 10, 15, 0.88);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  color: var(--text-secondary);
  font-size: 0.78rem;
  box-shadow: var(--shadow);
}

.privacy-bar svg {
  flex-shrink: 0;
  color: var(--accent);
}

/* ===== Mobile Dock ===== */
.mobile-dock {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: max(12px, var(--safe-bottom));
  z-index: 40;
  width: calc(100% - 24px);
  max-width: 460px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 10px;
  border-radius: 18px;
  background: rgba(14, 14, 20, 0.92);
  backdrop-filter: blur(24px) saturate(1.5);
  -webkit-backdrop-filter: blur(24px) saturate(1.5);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow-lg);
}

.mobile-dock:empty { display: none; }

.dock-button {
  height: 48px;
  border: none;
  border-radius: 12px;
  background: var(--glass);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 200ms var(--ease);
}

.dock-button:active { transform: scale(0.96); }
.dock-button:disabled { opacity: 0.4; cursor: not-allowed; }

.dock-primary {
  background: linear-gradient(135deg, #f0cd8d, #b8873e);
  color: #1a1408;
  font-weight: 700;
}

.dock-status {
  grid-column: 1 / -1;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--glass);
  color: var(--text);
  font-size: 0.88rem;
}

.dock-spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid rgba(226, 185, 111, 0.2);
  border-top-color: var(--accent);
  animation: spin 700ms linear infinite;
}

/* ===== Toast ===== */
.app-toast {
  position: fixed;
  left: 50%;
  bottom: 80px;
  z-index: 60;
  min-width: 140px;
  max-width: calc(100% - 40px);
  padding: 10px 18px;
  border-radius: 100px;
  background: rgba(18, 18, 26, 0.95);
  color: var(--text);
  border: 1px solid rgba(226, 185, 111, 0.2);
  box-shadow: var(--shadow);
  text-align: center;
  font-size: 0.88rem;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 10px);
  transition: opacity 200ms var(--ease), transform 200ms var(--ease);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.app-toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ===== Spinner for button ===== */
.button-spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid rgba(26, 20, 8, 0.25);
  border-top-color: #1a1408;
  animation: spin 700ms linear infinite;
}

/* ===== Animations ===== */
@keyframes fade-up {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slide-up {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

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

@keyframes pulse-glow {
  from { box-shadow: 0 0 12px rgba(226, 185, 111, 0.25); }
  to { box-shadow: 0 0 24px rgba(226, 185, 111, 0.5); transform: scale(1.05); }
}

@keyframes sheen {
  0%, 70% { transform: translateX(-120%); }
  100% { transform: translateX(130%); }
}

@keyframes ring-pulse {
  0% { opacity: 0.7; transform: scale(0.5); }
  80%, 100% { opacity: 0; transform: scale(1); }
}

@keyframes dot-pulse {
  from { transform: scale(0.9); }
  to { transform: scale(1.1); }
}

/* ===== Reduced Motion ===== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ===== Desktop tweaks (>480px) ===== */
@media (min-width: 481px) {
  .app-shell {
    max-width: 520px;
  }
  .preview-image-wrap img {
    max-height: 500px;
  }
  .privacy-bar {
    bottom: 80px;
  }
}

/* ===== Large screens ===== */
@media (min-width: 768px) {
  .app-shell {
    max-width: 560px;
    padding: 0 24px;
  }

  .upload-title {
    font-size: 2rem;
  }

  .dropzone {
    min-height: 260px;
  }

  .mobile-dock {
    max-width: 520px;
  }
}
