:root {
  --bg: #f5f0eb;
  --bg-card: #fffcfa;
  --primary: #9b8aa8;
  --primary-dark: #7d6b8c;
  --accent: #c4a484;
  --text: #4a4543;
  --text-light: #8a8480;
  --border: #e8e0d8;
  --shadow: 0 8px 32px rgba(125, 107, 140, 0.12);
  --radius: 20px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

body {
  background: radial-gradient(ellipse at 50% 0%, #efe8f3 0%, var(--bg) 55%);
}

#app {
  max-width: 430px;
  min-height: 100dvh;
  margin: 0 auto;
  padding: 16px 20px calc(12px + var(--safe-bottom));
  position: relative;
  display: flex;
  flex-direction: column;
}

.app-footer {
  margin-top: auto;
  padding-top: 20px;
  text-align: center;
  font-size: 0.7rem;
  line-height: 1.65;
  color: var(--text-light);
  letter-spacing: 0.02em;
}

.app-footer-copy {
  opacity: 0.85;
}

.app-footer-credits {
  margin-top: 4px;
  color: var(--text-light);
}

.step {
  display: none;
  flex-direction: column;
  min-height: calc(100dvh - 40px);
  animation: fadeIn 0.35s ease;
}

.step.active {
  display: flex;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.step-dots {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 20px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
  transition: background 0.3s, transform 0.3s;
}

.dot.active {
  background: var(--primary);
  transform: scale(1.2);
}

h1 {
  font-size: 1.5rem;
  font-weight: 600;
  text-align: center;
  line-height: 1.4;
  margin-bottom: 8px;
}

.subtitle {
  text-align: center;
  color: var(--text-light);
  font-size: 0.9rem;
  margin-bottom: 28px;
  line-height: 1.6;
}

.hero-glow {
  width: 120px;
  height: 120px;
  margin: 0 auto 24px;
  border-radius: 50%;
  background: linear-gradient(135deg, #e8dff0, #f5ebe0);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
}

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 14px 24px;
  border: none;
  border-radius: 999px;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: transform 0.15s, opacity 0.2s;
  width: 100%;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  box-shadow: 0 6px 20px rgba(125, 107, 140, 0.35);
  margin-top: auto;
}

.btn-primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--primary-dark);
  border: 1px solid var(--border);
}

.btn-ghost {
  background: transparent;
  color: var(--text-light);
  font-size: 0.85rem;
  min-height: 44px;
  margin-top: 12px;
}

.upload-zone {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.preview-box {
  aspect-ratio: 3/4;
  max-height: 42vh;
  border-radius: var(--radius);
  border: 2px dashed var(--border);
  background: var(--bg-card);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.preview-box img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.preview-placeholder {
  color: var(--text-light);
  font-size: 0.9rem;
  text-align: center;
  padding: 20px;
}

.upload-actions {
  display: flex;
  gap: 12px;
}

.upload-actions .btn {
  flex: 1;
}

.analysis-wrap {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.analysis-box {
  background: var(--bg-card);
  border-radius: 14px;
  padding: 14px 16px;
  font-size: 0.88rem;
  line-height: 1.6;
  color: var(--text);
  border: 1px solid var(--border);
  min-height: 48px;
}

.analysis-box.loading {
  color: var(--text-light);
}

.analysis-box.error {
  border-color: #d4a5a5;
  background: #fff8f7;
  color: #8b5a5a;
}

.analysis-box.done::before {
  content: "✓ ";
  color: var(--primary);
}

.btn-retry-analysis {
  min-height: 44px;
  font-size: 0.9rem;
}

.btn-retry-analysis:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.progress-label {
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-light);
  margin-bottom: 8px;
}

.progress-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin-bottom: 24px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--primary));
  border-radius: 2px;
  transition: width 0.3s ease;
}

.question-title {
  font-size: 1.15rem;
  font-weight: 600;
  line-height: 1.5;
  margin-bottom: 6px;
}

.question-hint {
  font-size: 0.8rem;
  color: var(--accent);
  margin-bottom: 20px;
}

.options {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
}

.option {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg-card);
  border: 2px solid transparent;
  border-radius: 14px;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
  min-height: 48px;
}

.option:has(input:checked) {
  border-color: var(--primary);
  box-shadow: 0 4px 16px rgba(155, 138, 168, 0.2);
}

.option input {
  margin-top: 3px;
  accent-color: var(--primary);
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.option span {
  font-size: 0.92rem;
  line-height: 1.45;
}

.nav-row {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}

.nav-row .btn {
  flex: 1;
}

.confirm-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.confirm-thumb {
  width: 72px;
  height: 96px;
  border-radius: 12px;
  object-fit: cover;
  flex-shrink: 0;
}

.confirm-summary {
  font-size: 0.88rem;
  line-height: 1.5;
}

.accordion {
  margin-bottom: 20px;
}

.accordion-toggle {
  width: 100%;
  text-align: left;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 0.9rem;
  color: var(--primary-dark);
  cursor: pointer;
}

.accordion-body {
  display: none;
  padding: 12px 4px;
  font-size: 0.85rem;
  line-height: 1.7;
  color: var(--text-light);
}

.accordion-body.open {
  display: block;
}

.loading-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 24px;
}

.breath-ring {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  animation: spin 1.2s linear infinite, breath 2s ease-in-out infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes breath {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(155, 138, 168, 0.2);
  }
  50% {
    box-shadow: 0 0 0 16px rgba(155, 138, 168, 0);
  }
}

.loading-steps {
  text-align: left;
  font-size: 0.88rem;
  line-height: 2;
  color: var(--text-light);
}

.loading-steps .done {
  color: var(--primary);
}

.loading-preview {
  width: 100px;
  height: 140px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  opacity: 0;
  transition: opacity 0.5s;
}

.loading-preview.visible {
  opacity: 1;
}

.loading-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.result-scroll {
  flex: 1;
  overflow-y: auto;
  padding-bottom: 16px;
}

.portrait-wrap {
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
  position: relative;
}

.portrait-wrap--static,
.portrait-wrap:has(.thumb-image) {
  cursor: default;
}

.portrait-wrap img.thumb-image {
  width: 100%;
  display: block;
  height: auto;
  max-height: none;
  aspect-ratio: auto;
  object-fit: contain;
  cursor: pointer;
  background: var(--bg-card);
}

.thumb-hint {
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-light);
  padding: 8px 12px 12px;
  margin: 0;
  background: var(--bg-card);
}

.portrait-countdown {
  margin: 12px 16px 0;
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(196, 92, 72, 0.08);
  border: 1px solid rgba(196, 92, 72, 0.2);
  text-align: center;
}

.portrait-countdown-label {
  margin: 0 0 6px;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--accent);
}

.portrait-countdown-hint {
  margin: 0;
  font-size: 0.78rem;
  color: var(--text-light);
  line-height: 1.45;
}

.share-footer {
  margin-top: auto;
  padding-top: 16px;
}

.share-footer .share-cta {
  text-decoration: none;
  display: flex;
}

.portrait-failed,
.portrait-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 20px;
  background: rgba(245, 240, 235, 0.92);
  text-align: center;
}

.portrait-failed[hidden],
.portrait-loading[hidden] {
  display: none !important;
}

.portrait-failed p,
.portrait-loading p {
  font-size: 0.88rem;
  color: var(--text-light);
  line-height: 1.5;
}

.portrait-failed .btn {
  width: auto;
  min-width: 160px;
  padding: 12px 20px;
}

.portrait-loading .breath-ring {
  width: 48px;
  height: 48px;
}

.portrait-wrap.is-regenerating .portrait-failed {
  display: none !important;
}

.portrait-wrap.is-regenerating #result-portrait {
  opacity: 0.35;
}

.portrait-wrap img {
  width: 100%;
  display: block;
  aspect-ratio: 9/16;
  object-fit: cover;
  background: var(--border);
}

.portrait-wrap img.thumb-image {
  aspect-ratio: auto;
  object-fit: contain;
}

.result-title {
  text-align: center;
  font-size: 1.25rem;
  margin-bottom: 20px;
  color: var(--primary-dark);
}

.stats-section h3 {
  font-size: 0.9rem;
  text-align: center;
  margin-bottom: 16px;
  color: var(--text-light);
  letter-spacing: 0.2em;
}

.stat-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  font-size: 0.88rem;
}

.stat-label {
  width: 64px;
  flex-shrink: 0;
}

.stat-bar {
  flex: 1;
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}

.stat-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--primary));
  border-radius: 4px;
  transition: width 0.8s ease;
}

.stat-value {
  width: 28px;
  text-align: right;
  font-weight: 600;
  color: var(--primary-dark);
}

.blessing-box {
  background: var(--bg-card);
  border-left: 3px solid var(--accent);
  padding: 16px 18px;
  border-radius: 0 14px 14px 0;
  margin: 24px 0;
  font-style: italic;
  line-height: 1.7;
  font-size: 0.95rem;
}

.blessing-box::before {
  content: "「前世寄语」";
  display: block;
  font-style: normal;
  font-size: 0.8rem;
  color: var(--accent);
  margin-bottom: 8px;
}

.result-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
}

.btn-share-main {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding-top: 14px;
  padding-bottom: 14px;
}

.btn-share-title {
  font-size: 1rem;
  font-weight: 600;
}

.btn-share-hint {
  font-size: 0.72rem;
  font-weight: 400;
  opacity: 0.88;
}

.share-url-preview {
  font-size: 0.72rem;
  line-height: 1.4;
  color: var(--text-light);
  word-break: break-all;
  text-align: center;
  padding: 0 4px;
  margin: -4px 0 0;
}

.toast {
  position: fixed;
  bottom: calc(32px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: rgba(74, 69, 67, 0.92);
  color: #fff;
  padding: 12px 24px;
  border-radius: 999px;
  font-size: 0.9rem;
  opacity: 0;
  transition: transform 0.35s, opacity 0.35s;
  z-index: 100;
  pointer-events: none;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}

.lightbox.open {
  display: flex;
}

.lightbox img {
  max-width: 100%;
  max-height: 90vh;
  border-radius: 8px;
}

input[type="file"] {
  display: none;
}

.camera-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(30, 28, 26, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  padding-bottom: calc(16px + var(--safe-bottom));
}

.camera-modal[hidden] {
  display: none !important;
}

.camera-modal-inner {
  width: 100%;
  max-width: 430px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.camera-video {
  width: 100%;
  max-height: 62vh;
  border-radius: var(--radius);
  background: #000;
  object-fit: cover;
  transform: scaleX(-1);
}

.camera-hint {
  text-align: center;
  font-size: 0.85rem;
  color: #e8e0d8;
}

.camera-actions {
  display: flex;
  gap: 10px;
}

.camera-actions .btn {
  flex: 1;
}
