:root {
  color-scheme: light;
  --bg: #f8fafc;
  --card: #ffffff;
  --soft: #f1f5f9;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --shadow: 0 18px 48px rgba(15, 23, 42, .08);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f172a;
  --card: #111827;
  --soft: #1e293b;
  --text: #f8fafc;
  --muted: #94a3b8;
  --line: #334155;
  --primary: #818cf8;
  --primary-dark: #6366f1;
  --success: #4ade80;
  --danger: #fb7185;
  --warning: #fbbf24;
  --shadow: 0 20px 60px rgba(0, 0, 0, .3);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}
button, input, select, textarea { font: inherit; }
button { border: 0; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
a { color: inherit; text-decoration: none; }
svg { width: 18px; height: 18px; }
.hidden { display: none !important; }

.app-shell { min-height: 100vh; }
.topbar {
  min-height: 64px;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 30;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--card) 94%, transparent);
  backdrop-filter: blur(10px);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: max-content; }
.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: #fff;
  background: #ea580c;
}
.brand strong { display: block; font-size: 16px; line-height: 1.2; }
.brand small { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; }
.desktop-nav { display: flex; align-items: center; justify-content: center; gap: 2px; flex: 1; }
.desktop-nav a {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 0 10px;
  border-radius: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
  white-space: nowrap;
}
.desktop-nav a:hover { color: var(--text); background: var(--soft); }
.desktop-nav a.active { color: var(--primary); background: color-mix(in srgb, var(--primary) 10%, var(--card)); }
.desktop-nav svg { width: 16px; height: 16px; }
.header-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; min-width: max-content; }
.user-summary { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
#userName { color: var(--text); font-weight: 700; }
#userPoints { color: var(--primary); font-weight: 700; }
.icon-btn {
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--card);
}
.icon-btn:hover { color: var(--primary); border-color: var(--primary); }
.theme-light-icon { display: none; }
[data-theme="dark"] .theme-light-icon { display: block; }
[data-theme="dark"] .theme-dark-icon { display: none; }
.mobile-menu-btn, .mobile-nav { display: none; }

.main { width: 100%; padding: 30px 16px 46px; }
.stepper {
  width: min(800px, 100%);
  margin: 0 auto 28px;
  display: flex;
  justify-content: space-between;
  position: relative;
  padding: 0 4px;
}
.step-track { position: absolute; left: 27px; right: 27px; top: 20px; height: 2px; background: var(--line); }
.step-track span { display: block; width: 0; height: 100%; background: var(--primary); transition: width .25s ease; }
.step {
  min-width: 54px;
  display: grid;
  justify-items: center;
  gap: 7px;
  position: relative;
  color: var(--muted);
  background: transparent;
  font-size: 12px;
  font-weight: 750;
}
.step-number {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 2px solid var(--line);
  border-radius: 50%;
  background: var(--card);
  box-shadow: 0 0 0 4px var(--bg);
  font-size: 14px;
}
.step.active { color: var(--text); }
.step.active .step-number { color: #fff; border-color: var(--primary); background: var(--primary); }
.step.done .step-number { color: #fff; border-color: var(--success); background: var(--success); }

.workspace {
  width: min(800px, 100%);
  min-height: 570px;
  margin: 0 auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  box-shadow: var(--shadow);
}
.panel { display: none; min-height: 492px; padding: 30px; }
.panel.active { display: block; }
.panel-heading { margin-bottom: 25px; }
.panel-heading h1 { margin: 0; font-size: 22px; line-height: 1.25; }
.panel-heading p { margin: 7px 0 0; color: var(--muted); font-size: 14px; line-height: 1.55; }
.row-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.form-grid { display: grid; gap: 16px; }
.two-columns { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.field { display: grid; gap: 7px; }
.field > span, .custom-size label span { color: var(--muted); font-size: 12px; font-weight: 750; }
.field select, .custom-size input {
  width: 100%;
  height: 43px;
  padding: 0 12px;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 7px;
  outline: none;
  background: var(--card);
}
.field select:focus, .custom-size input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 13%, transparent); }
.form-section { margin-top: 26px; }
.form-section h2 { margin: 0 0 11px; font-size: 13px; }
.compact-section { margin-top: 20px; }
.ratio-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 9px; }
.ratio-option {
  min-height: 104px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  padding: 10px 5px;
  color: var(--muted);
  border: 2px solid var(--line);
  border-radius: 7px;
  background: var(--card);
}
.ratio-option:hover { border-color: color-mix(in srgb, var(--primary) 45%, var(--line)); }
.ratio-option.selected { color: var(--text); border-color: var(--primary); background: color-mix(in srgb, var(--primary) 7%, var(--card)); }
.ratio-option strong { font-size: 12px; white-space: nowrap; }
.ratio-frame { width: 52px; height: 48px; display: grid; place-items: center; }
.ratio-box { display: block; border: 2px solid currentColor; border-radius: 3px; }
.ratio-square { width: 30px; height: 30px; }
.ratio-portrait { width: 21px; height: 38px; }
.ratio-detail { width: 27px; height: 36px; }
.ratio-landscape { width: 38px; height: 29px; }
.ratio-wide { width: 42px; height: 24px; }
.auto-box { width: 35px; height: 35px; display: grid; place-items: center; border: 2px dashed currentColor; border-radius: 5px; font-size: 8px; font-weight: 850; }
.segmented { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.segmented button {
  min-height: 40px;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--card);
  font-size: 13px;
  font-weight: 750;
}
.segmented button:hover { background: var(--soft); }
.segmented button.selected { color: var(--primary); border-color: var(--primary); background: color-mix(in srgb, var(--primary) 8%, var(--card)); }
.custom-size { display: grid; grid-template-columns: 1fr auto 1fr; align-items: end; gap: 10px; margin-top: 10px; padding: 12px; background: var(--soft); border-radius: 7px; }
.custom-size label { display: grid; gap: 5px; }
.custom-size b { padding-bottom: 11px; color: var(--muted); }

.count-badge { flex: none; padding: 5px 9px; color: var(--muted); border-radius: 999px; background: var(--soft); font-size: 12px; font-weight: 750; }
.drop-zone {
  width: 100%;
  min-height: 190px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px;
  color: var(--text);
  border: 2px dashed var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--soft) 55%, transparent);
}
.drop-zone:hover, .drop-zone.drag-over { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 7%, var(--card)); }
.drop-zone:disabled { cursor: wait; }
.drop-zone small { color: var(--muted); }
.upload-icon { width: 50px; height: 50px; display: grid; place-items: center; color: var(--primary); border-radius: 50%; background: color-mix(in srgb, var(--primary) 10%, var(--card)); }
.upload-icon svg { width: 25px; height: 25px; }
.reference-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 11px; margin-top: 20px; }
.reference-card { aspect-ratio: 1; position: relative; overflow: hidden; border: 1px solid var(--line); border-radius: 7px; background: var(--soft); cursor: grab; }
.reference-card.dragging { opacity: .45; }
.reference-card img { width: 100%; height: 100%; display: block; object-fit: cover; }
.reference-remove { position: absolute; top: 6px; right: 6px; width: 27px; height: 27px; display: grid; place-items: center; color: var(--danger); border-radius: 50%; background: #fff; box-shadow: 0 3px 10px rgba(15, 23, 42, .2); }
.reference-remove svg { width: 14px; height: 14px; }
.reference-order { position: absolute; right: 6px; bottom: 6px; min-width: 21px; height: 21px; display: grid; place-items: center; padding: 0 6px; color: #fff; border-radius: 10px; background: rgba(15, 23, 42, .75); font-size: 11px; font-weight: 800; }

.prompt-box textarea {
  width: 100%;
  min-height: 310px;
  display: block;
  padding: 18px;
  resize: vertical;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  background: color-mix(in srgb, var(--soft) 52%, transparent);
  font-size: 15px;
  line-height: 1.7;
}
.prompt-box textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 13%, transparent); background: var(--card); }
.prompt-meta { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 10px; color: var(--muted); font-size: 12px; }
.inline-error { display: none; margin-top: 14px; padding: 11px 12px; color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 28%, var(--line)); border-radius: 7px; background: color-mix(in srgb, var(--danger) 7%, var(--card)); font-size: 13px; }
.inline-error.show { display: block; }

.workspace-footer { min-height: 76px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 24px; border-top: 1px solid var(--line); background: color-mix(in srgb, var(--soft) 42%, var(--card)); }
.primary-btn, .secondary-btn, .text-btn {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border-radius: 7px;
  font-size: 14px;
  font-weight: 800;
}
.primary-btn { padding: 0 20px; color: #fff; background: var(--primary); }
.primary-btn:hover { background: var(--primary-dark); }
.secondary-btn { padding: 0 17px; color: var(--text); border: 1px solid var(--line); background: var(--card); }
.secondary-btn:hover { background: var(--soft); }
.secondary-btn.small { min-height: 34px; padding: 0 11px; color: var(--primary); font-size: 12px; }
.secondary-btn.small svg { width: 15px; height: 15px; }
.text-btn { padding: 0 8px; color: var(--muted); background: transparent; }
.text-btn:hover { color: var(--primary); }

.result-panel { min-height: 568px; }
.loading-state, .failure-state { min-height: 505px; display: grid; place-items: center; align-content: center; text-align: center; }
.loading-state h1, .failure-state h1 { margin: 15px 0 0; font-size: 22px; }
.loading-state p, .failure-state p { max-width: 560px; margin: 8px auto 20px; color: var(--muted); font-size: 14px; line-height: 1.65; }
.aurora-loader { position: relative; width: 148px; height: 148px; display: grid; place-items: center; }
.aurora-loader::before, .aurora-loader::after { content: ""; position: absolute; inset: -8px; border: 1.5px solid rgba(99, 102, 241, .34); border-radius: 50%; animation: ring-expand 2.5s ease-out infinite; }
.aurora-loader::after { border-color: rgba(6, 182, 212, .28); animation-delay: 1.25s; }
.aurora-core {
  width: 148px;
  height: 148px;
  border-radius: 50%;
  background: linear-gradient(45deg, #06b6d4, #2563eb, #7c3aed, #db2777, #0891b2, #4f46e5, #06b6d4);
  background-size: 400% 400%;
  box-shadow: 0 0 34px rgba(59, 130, 246, .48), 0 0 68px rgba(139, 92, 246, .3), inset 0 0 34px rgba(255, 255, 255, .28);
  animation: aurora-breathe 3s ease-in-out infinite, aurora-color 8s ease-in-out infinite;
}
.progress-bar { width: min(390px, 90%); height: 8px; overflow: hidden; border-radius: 10px; background: var(--soft); }
.progress-bar span { display: block; width: 5%; height: 100%; border-radius: inherit; background: var(--primary); transition: width .3s ease; }
.status-row { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px 16px; margin-top: 14px; color: var(--muted); font-size: 12px; font-weight: 700; }
.result-layout { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(280px, .8fr); gap: 25px; align-items: start; }
.result-preview { width: 100%; min-height: 360px; display: flex; align-items: flex-start; justify-content: center; padding: 0; background: transparent; }
.result-preview img { display: block; max-width: 100%; max-height: 68vh; object-fit: contain; }
.result-side { min-width: 0; display: grid; gap: 17px; }
.result-side .panel-heading { margin: 0; }
.result-info { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.result-info > div { min-width: 0; min-height: 66px; padding: 11px; border-radius: 7px; background: var(--soft); }
.result-info span { display: block; color: var(--muted); font-size: 11px; }
.result-info strong { display: block; margin-top: 8px; overflow: hidden; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.result-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.result-actions button { width: 100%; min-height: 47px; padding: 0 10px; }
.prompt-history { padding-top: 14px; border-top: 1px solid var(--line); }
.prompt-history > div { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.prompt-history .icon-btn { width: 32px; height: 32px; }
.prompt-history p { max-height: 140px; margin: 9px 0 0; padding: 12px; overflow: auto; color: var(--muted); border-radius: 7px; background: var(--soft); font-size: 12px; line-height: 1.65; white-space: pre-wrap; overflow-wrap: anywhere; }
.failure-icon { width: 62px; height: 62px; display: grid; place-items: center; color: var(--danger); border-radius: 50%; background: color-mix(in srgb, var(--danger) 10%, var(--card)); }
.failure-icon svg { width: 30px; height: 30px; }
.failure-actions { display: flex; justify-content: center; gap: 10px; }

.image-modal { position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; padding: 24px 24px 78px; background: rgba(2, 6, 23, .9); }
.image-modal img { max-width: 96vw; max-height: calc(100vh - 110px); object-fit: contain; }
.modal-close { position: fixed; top: 20px; right: 20px; width: 40px; height: 40px; display: grid; place-items: center; color: #fff; border-radius: 50%; background: rgba(15, 23, 42, .85); }
.modal-download { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: #fff; color: #0f172a; }
.toast { position: fixed; left: 50%; bottom: 28px; z-index: 80; max-width: min(90vw, 520px); padding: 11px 15px; color: #fff; border-radius: 7px; background: #0f172a; box-shadow: 0 14px 34px rgba(15, 23, 42, .3); transform: translateX(-50%); font-size: 13px; }
.toast.error { background: #991b1b; }

@keyframes ring-expand { from { transform: scale(.86); opacity: 1; } to { transform: scale(1.46); opacity: 0; } }
@keyframes aurora-breathe { 0%, 100% { transform: scale(1); opacity: .88; } 35% { transform: scale(1.07); opacity: 1; } 70% { transform: scale(1.02); opacity: .94; } }
@keyframes aurora-color { 0%, 100% { filter: hue-rotate(0deg); background-position: 0 50%; } 50% { filter: hue-rotate(150deg); background-position: 100% 50%; } }

@media (max-width: 1180px) {
  .brand small, .desktop-nav svg, .user-summary { display: none; }
  .desktop-nav a { padding: 0 8px; }
}
@media (max-width: 900px) {
  .desktop-nav { display: none; }
  .topbar { justify-content: space-between; }
  .mobile-menu-btn { display: inline-grid; }
  .mobile-nav.open { display: grid; position: fixed; left: 0; right: 0; top: 64px; z-index: 29; padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--card); box-shadow: var(--shadow); }
  .mobile-nav a, .mobile-nav button { min-height: 40px; display: flex; align-items: center; padding: 0 12px; color: var(--muted); border-radius: 7px; background: transparent; font-size: 14px; font-weight: 650; text-align: left; }
  .mobile-nav a.active { color: var(--primary); background: color-mix(in srgb, var(--primary) 9%, var(--card)); }
}
@media (max-width: 700px) {
  .topbar { padding: 0 14px; }
  .brand strong { font-size: 15px; }
  .main { padding: 21px 10px 30px; }
  .stepper { margin-bottom: 20px; }
  .step > span:last-child { display: none; }
  .step-number { width: 36px; height: 36px; box-shadow: 0 0 0 3px var(--bg); }
  .step-track { left: 24px; right: 24px; top: 18px; }
  .workspace { min-height: calc(100vh - 140px); }
  .panel { min-height: 475px; padding: 22px 16px; }
  .two-columns { grid-template-columns: 1fr; }
  .ratio-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .segmented { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .reference-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .prompt-box textarea { min-height: 290px; }
  .workspace-footer { position: sticky; bottom: 0; z-index: 5; padding: 13px 15px; }
  .result-layout { grid-template-columns: 1fr; }
  .result-preview { min-height: 0; }
  .result-preview img { max-height: none; }
  .loading-state, .failure-state { min-height: 440px; }
}
@media (max-width: 420px) {
  .brand-mark { width: 34px; height: 34px; }
  .brand strong { font-size: 14px; }
  .ratio-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .reference-grid, .result-info, .result-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .failure-actions { display: grid; width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
}
