/* ── Variables ─────────────────────────────────────────────── */
:root {
  --bg:          #090912;
  --surface:     #0d0d1a;
  --card:        #13132a;
  --card-hover:  #17173a;
  --border:      rgba(139, 92, 246, 0.14);
  --border-sub:  rgba(255, 255, 255, 0.06);

  --text:        #e8e8f6;
  --text-muted:  #7070a8;
  --text-dim:    #3c3c60;

  --purple:  #8b5cf6;
  --pink:    #ec4899;
  --amber:   #f59e0b;
  --green:   #10b981;
  --red:     #ef4444;

  --grad: linear-gradient(135deg, #8b5cf6 0%, #ec4899 50%, #f59e0b 100%);
  --grad-text: linear-gradient(90deg, #a78bfa 0%, #f472b6 50%, #fbbf24 100%);

  --r-sm: 10px;
  --r:    16px;
  --r-lg: 24px;

  --phone-w: 390px;
  --shadow: 0 4px 32px rgba(0,0,0,.5);
}

/* ── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui,
               'Helvetica Neue', Arial, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  overflow-x: hidden;
}

/* ── Desktop side panels ───────────────────────────────────── */
.desktop-side {
  flex: 1;
  background: var(--bg);
  position: relative;
}

.desktop-side::after {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    45deg,
    transparent,
    transparent 40px,
    rgba(139,92,246,.02) 40px,
    rgba(139,92,246,.02) 80px
  );
}

/* ── App shell (phone column) ──────────────────────────────── */
.app-shell {
  width: 100%;
  max-width: var(--phone-w);
  min-height: 100dvh;
  background: var(--surface);
  position: relative;
  display: flex;
  flex-direction: column;
  box-shadow: 0 0 80px rgba(139,92,246,.08);
}

/* ── Header ────────────────────────────────────────────────── */
.app-header {
  position: sticky;
  top: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: rgba(13,13,26,.92);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-bottom: 1px solid var(--border-sub);
}

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

.brand-icon { border-radius: 8px; flex-shrink: 0; }

.brand-name {
  font-size: 19px;
  font-weight: 800;
  letter-spacing: -.4px;
  color: var(--text);
}

.g-text {
  background: var(--grad-text);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.order-badge {
  font-size: 11px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  color: var(--text-muted);
  background: var(--card);
  border: 1px solid var(--border-sub);
  padding: 4px 10px;
  border-radius: 100px;
  letter-spacing: .3px;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Progress bar ──────────────────────────────────────────── */
.progress-bar {
  height: 3px;
  background: rgba(255,255,255,.04);
}

.progress-fill {
  height: 100%;
  width: 0;
  background: var(--grad);
  border-radius: 0 3px 3px 0;
  transition: width .4s cubic-bezier(.4,0,.2,1);
}

/* ── Save indicator ────────────────────────────────────────── */
.save-indicator {
  position: fixed;
  top: 64px;
  right: calc(50% - var(--phone-w)/2 + 16px);
  max-width: calc(var(--phone-w) - 32px);
  background: rgba(16,185,129,.12);
  border: 1px solid rgba(16,185,129,.25);
  color: var(--green);
  font-size: 12px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 100px;
  z-index: 300;
  opacity: 0;
  transform: translateY(-6px) scale(.95);
  transition: all .25s cubic-bezier(.4,0,.2,1);
  pointer-events: none;
}

.save-indicator.visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

/* ── Error banner ──────────────────────────────────────────── */
.error-banner {
  background: rgba(239,68,68,.1);
  border-bottom: 1px solid rgba(239,68,68,.2);
  color: #fca5a5;
  font-size: 13px;
  padding: 10px 20px;
  text-align: center;
}

/* ── Page content ──────────────────────────────────────────── */
.page-content {
  flex: 1;
  padding: 28px 20px 140px;
}

.page-title {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -.6px;
  line-height: 1.2;
  margin-bottom: 8px;
}

.page-subtitle {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 32px;
}

/* ── Field section ─────────────────────────────────────────── */
.field-section { margin-bottom: 8px; }

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

.required-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--pink);
  flex-shrink: 0;
}

.field-desc {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 12px;
  line-height: 1.5;
}

/* ── Option pills ──────────────────────────────────────────── */
.options-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 8px 16px;
  border-radius: 100px;
  border: 1px solid var(--border-sub);
  background: var(--card);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all .18s ease;
  user-select: none;
  -webkit-user-select: none;
  line-height: 1;
  font-family: inherit;
}

.pill:active { transform: scale(.94); }

.pill:hover:not(.selected) {
  border-color: rgba(139,92,246,.3);
  color: var(--text);
}

/* Radio pill selected: solid gradient */
.radio-pill.selected {
  background: var(--grad);
  border-color: transparent;
  color: #fff;
  font-weight: 700;
  box-shadow: 0 4px 16px rgba(139,92,246,.35);
}

/* Checkbox pill selected: gradient border + tinted bg */
.checkbox-pill.selected {
  background: rgba(139,92,246,.12);
  border-color: var(--purple);
  color: #c4b5fd;
  font-weight: 600;
}

/* ── Text input ────────────────────────────────────────────── */
.text-input {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--border-sub);
  border-radius: var(--r);
  padding: 14px 16px;
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  line-height: 1.6;
  outline: none;
  resize: vertical;
  min-height: 88px;
  transition: border-color .2s ease, box-shadow .2s ease;
}

.text-input::placeholder { color: var(--text-dim); }

.text-input:focus {
  border-color: var(--purple);
  box-shadow: 0 0 0 3px rgba(139,92,246,.12);
}

/* ── Divider ───────────────────────────────────────────────── */
.divider {
  height: 1px;
  background: var(--border-sub);
  margin: 24px 0;
}

/* ── Submit area ───────────────────────────────────────────── */
.submit-wrap {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: var(--phone-w);
  padding: 16px 20px max(20px, env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--surface) 65%, transparent);
  z-index: 100;
}

.submit-hint {
  text-align: center;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 10px;
  transition: opacity .3s;
}

.btn-generate {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 18px;
  border: none;
  border-radius: var(--r);
  background: var(--grad);
  color: #fff;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  transition: all .2s ease;
  letter-spacing: .2px;
  font-family: inherit;
  box-shadow: 0 8px 24px rgba(139,92,246,.35);
}

.btn-generate:disabled {
  background: var(--card);
  color: var(--text-dim);
  cursor: not-allowed;
  box-shadow: none;
}

.btn-generate:not(:disabled):active { transform: scale(.98); }

.btn-generate:not(:disabled):hover {
  box-shadow: 0 12px 32px rgba(139,92,246,.45);
  transform: translateY(-1px);
}

.btn-icon { font-size: 18px; }

/* ── Result page ───────────────────────────────────────────── */
.result-page { padding-bottom: 48px; }

/* Generating */
.gen-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 48px 24px 32px;
  text-align: center;
  gap: 20px;
}

.orb-wrap {
  position: relative;
  width: 100px;
  height: 100px;
  margin-bottom: 8px;
}

.orb {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: var(--grad);
  animation: orbPulse 2.2s ease-in-out infinite;
  box-shadow: 0 0 48px rgba(139,92,246,.5);
}

.orb-ring {
  position: absolute;
  inset: -12px;
  border-radius: 50%;
  border: 2px solid transparent;
  background: var(--grad) border-box;
  -webkit-mask: linear-gradient(#fff 0 0) padding-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: destination-out;
  mask-composite: exclude;
  animation: ringRotate 3s linear infinite;
  opacity: .5;
}

@keyframes orbPulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50%       { transform: scale(1.08); opacity: .85; }
}

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

.gen-title {
  font-size: 24px;
  font-weight: 800;
  line-height: 1.3;
  letter-spacing: -.4px;
}

.gen-hint {
  font-size: 13px;
  color: var(--text-muted);
}

.gen-steps {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 280px;
  margin-top: 8px;
}

.step {
  font-size: 13px;
  color: var(--text-dim);
  padding: 10px 16px;
  border-radius: var(--r-sm);
  background: var(--card);
  border: 1px solid var(--border-sub);
  transition: all .4s ease;
}

.step.active {
  color: var(--text);
  border-color: rgba(139,92,246,.35);
  background: rgba(139,92,246,.08);
  box-shadow: 0 0 16px rgba(139,92,246,.12);
}

/* Completed */
.result-header { margin-bottom: 20px; }

.badge-done {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 700;
  color: var(--green);
  background: rgba(16,185,129,.1);
  border: 1px solid rgba(16,185,129,.2);
  padding: 5px 12px;
  border-radius: 100px;
}

.result-img-wrap {
  position: relative;
  border-radius: var(--r-lg);
  overflow: hidden;
  background: #fff;
  box-shadow: var(--shadow), 0 0 40px rgba(139,92,246,.2);
  margin-bottom: 20px;
}

.result-img {
  width: 100%;
  display: block;
  border-radius: var(--r-lg);
}

.img-badge {
  position: absolute;
  bottom: 10px;
  right: 10px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .8px;
  color: rgba(255,255,255,.8);
  background: rgba(0,0,0,.5);
  backdrop-filter: blur(8px);
  padding: 3px 8px;
  border-radius: 6px;
}

.action-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 20px;
}

.btn-action {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 14px;
  border-radius: var(--r);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s ease;
  text-decoration: none;
  font-family: inherit;
  border: none;
}

.btn-primary {
  background: var(--grad);
  color: #fff;
  box-shadow: 0 6px 20px rgba(139,92,246,.3);
}

.btn-secondary {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border-sub);
}

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

.prompt-detail {
  margin-top: 24px;
  background: var(--card);
  border: 1px solid var(--border-sub);
  border-radius: var(--r);
  overflow: hidden;
}

.prompt-detail summary {
  padding: 14px 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  list-style: none;
}

.prompt-detail summary::-webkit-details-marker { display: none; }

.prompt-detail summary::before {
  content: '▶ ';
  font-size: 10px;
  transition: transform .2s;
  display: inline-block;
}

.prompt-detail[open] summary::before { transform: rotate(90deg); }

.prompt-text {
  padding: 0 16px 16px;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.6;
  border-top: 1px solid var(--border-sub);
  padding-top: 12px;
}

/* Failed */
.fail-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 48px 24px 32px;
  text-align: center;
  gap: 12px;
}

.fail-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: rgba(239,68,68,.1);
  border: 2px solid rgba(239,68,68,.2);
  color: var(--red);
  font-size: 24px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 8px;
}

.fail-title {
  font-size: 20px;
  font-weight: 800;
  color: var(--text);
}

.fail-desc {
  font-size: 14px;
  color: var(--text-muted);
  max-width: 260px;
}

.link-back {
  margin-top: 12px;
  font-size: 13px;
  color: var(--purple);
  text-decoration: none;
}

.link-back:hover { text-decoration: underline; }

/* ── Scrollbar ─────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(139,92,246,.2); border-radius: 4px; }

/* ── Mobile safety ─────────────────────────────────────────── */
@media (max-width: 390px) {
  .desktop-side { display: none; }
  .app-shell { max-width: 100%; }
  .save-indicator { right: 16px; }
  .submit-wrap { max-width: 100%; }
}
