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

:root {
  --bg-1: #fff7ff;
  --bg-2: #eef7ff;
  --bg-3: #fff4cf;
  --ink: #42305f;
  --muted: #7b6f95;
  --purple: #8b5cf6;
  --pink: #ff78b7;
  --blue: #62c7ff;
  --gold: #ffd36e;
  --green: #8be7c4;
  --card: rgba(255, 255, 255, 0.76);
  --card-strong: rgba(255, 255, 255, 0.92);
  --border: rgba(139, 92, 246, 0.2);
  --shadow: 0 20px 60px rgba(111, 83, 170, 0.18);
  --radius: 28px;
}

html { scroll-behavior: smooth; }

body {
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 10%, rgba(255, 211, 110, 0.55), transparent 24%),
    radial-gradient(circle at 85% 8%, rgba(98, 199, 255, 0.4), transparent 28%),
    radial-gradient(circle at 50% 92%, rgba(255, 120, 183, 0.35), transparent 28%),
    linear-gradient(145deg, var(--bg-1), var(--bg-2) 48%, var(--bg-3));
  overflow-x: hidden;
}

.star-field::before,
.star-field::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: .72;
  transform: translateZ(0);
  animation: floatStars 18s ease-in-out infinite;
}

/* 轻量星光：每层 8 个点，总数 16 个，避免 canvas / 高频 JS 粒子 */
.star-field::before {
  background:
    radial-gradient(circle at 10% 14%, rgba(139, 92, 246, .42) 0 2px, transparent 3px),
    radial-gradient(circle at 26% 8%, rgba(255, 211, 110, .42) 0 2px, transparent 3px),
    radial-gradient(circle at 48% 16%, rgba(98, 199, 255, .36) 0 2px, transparent 3px),
    radial-gradient(circle at 74% 9%, rgba(255, 120, 183, .40) 0 2px, transparent 3px),
    radial-gradient(circle at 90% 20%, rgba(139, 92, 246, .36) 0 2px, transparent 3px),
    radial-gradient(circle at 17% 58%, rgba(255, 211, 110, .32) 0 2px, transparent 3px),
    radial-gradient(circle at 83% 62%, rgba(98, 199, 255, .30) 0 2px, transparent 3px),
    radial-gradient(circle at 52% 86%, rgba(255, 120, 183, .30) 0 2px, transparent 3px);
}

.star-field::after {
  animation-delay: -8s;
  opacity: .46;
  background:
    radial-gradient(circle at 7% 38%, rgba(255, 120, 183, .34) 0 1.5px, transparent 3px),
    radial-gradient(circle at 31% 34%, rgba(98, 199, 255, .28) 0 1.5px, transparent 3px),
    radial-gradient(circle at 67% 33%, rgba(255, 211, 110, .30) 0 1.5px, transparent 3px),
    radial-gradient(circle at 94% 45%, rgba(139, 92, 246, .32) 0 1.5px, transparent 3px),
    radial-gradient(circle at 22% 77%, rgba(139, 92, 246, .26) 0 1.5px, transparent 3px),
    radial-gradient(circle at 42% 70%, rgba(255, 120, 183, .28) 0 1.5px, transparent 3px),
    radial-gradient(circle at 71% 82%, rgba(98, 199, 255, .26) 0 1.5px, transparent 3px),
    radial-gradient(circle at 88% 74%, rgba(255, 211, 110, .28) 0 1.5px, transparent 3px);
}

@keyframes floatStars {
  0%, 100% { transform: translate3d(0, 0, 0); }
  50% { transform: translate3d(0, -8px, 0); }
}

.page { display: none; min-height: 100vh; padding: 22px 16px; position: relative; z-index: 1; }
.page.active { display: flex; align-items: center; justify-content: center; }
.container { width: 100%; max-width: 560px; margin: 0 auto; }

.home-container,
.quiz-container,
.result-container {
  text-align: center;
  padding: 30px 18px;
}

.blessing {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 9px 16px;
  border-radius: 999px;
  color: #8a5b18;
  background: rgba(255, 240, 190, 0.86);
  border: 1px solid rgba(255, 199, 90, 0.52);
  box-shadow: 0 8px 24px rgba(255, 189, 89, 0.22);
  font-size: 0.92rem;
  font-weight: 700;
  margin-bottom: 14px;
}
.blessing.small { margin-bottom: 12px; font-size: .84rem; }
.result-blessing { margin-top: 8px; }

.title, .quiz-title, .result-title {
  font-weight: 900;
  line-height: 1.12;
  letter-spacing: .04em;
  background: linear-gradient(120deg, #7c3aed 0%, #ff69a7 45%, #f0a928 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 14px 34px rgba(139, 92, 246, 0.14);
}
.title { font-size: clamp(2.15rem, 9vw, 3.55rem); margin-bottom: 10px; }
.quiz-title { font-size: clamp(1.55rem, 7vw, 2.15rem); margin-bottom: 8px; }
.result-title { font-size: clamp(1.55rem, 7vw, 2.35rem); margin: 14px 0 4px; }

.subtitle, .quiz-subtitle {
  color: var(--muted);
  font-weight: 700;
  line-height: 1.55;
}
.subtitle { font-size: 1.05rem; margin-bottom: 18px; }
.quiz-subtitle { font-size: .9rem; margin-bottom: 20px; }

.portrait-card {
  position: relative;
  margin: 22px auto 24px;
  padding: 12px;
  border-radius: 34px;
  background:
    linear-gradient(white, white) padding-box,
    linear-gradient(135deg, rgba(255, 211, 110, .95), rgba(255, 120, 183, .8), rgba(98, 199, 255, .86)) border-box;
  border: 2px solid transparent;
  box-shadow: var(--shadow), 0 0 50px rgba(255, 120, 183, .22);
  max-width: 400px;
  animation: portraitFloat 4s ease-in-out infinite;
}

@keyframes portraitFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-7px); }
}

.portrait-card::before {
  content: "✦";
  position: absolute;
  right: 18px;
  top: 10px;
  font-size: 28px;
  color: #ffd36e;
  filter: drop-shadow(0 0 12px rgba(255, 211, 110, .8));
  z-index: 2;
}

.portrait-frame {
  position: relative;
  overflow: hidden;
  border-radius: 24px;
  background:
    radial-gradient(circle at 20% 20%, rgba(255, 255, 255, .85), transparent 20%),
    linear-gradient(145deg, rgba(238, 247, 255, .95), rgba(255, 244, 251, .95));
  min-height: 260px;
}

.portrait-frame::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 20% 18%, rgba(255, 255, 255, .42), transparent 20%),
    radial-gradient(circle at 80% 12%, rgba(255, 211, 110, .25), transparent 18%),
    linear-gradient(180deg, transparent 72%, rgba(139, 92, 246, .13));
  pointer-events: none;
}

.portrait-frame img {
  display: block;
  width: 100%;
  max-width: 1000px;
  height: auto;
  max-height: 430px;
  object-fit: contain;
  filter: brightness(1.08) saturate(1.08) contrast(1.02);
}

.portrait-fallback {
  display: none;
  min-height: 260px;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-weight: 800;
  padding: 28px;
}

figcaption {
  padding: 12px 8px 2px;
  display: grid;
  gap: 4px;
}
figcaption strong { color: #6d4edb; font-size: .98rem; }
figcaption span { color: var(--muted); font-size: .88rem; line-height: 1.55; }

.intro-card, .question-box, .result-card, .result-hero {
  background: var(--card);
  backdrop-filter: blur(18px);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.intro-card {
  border-radius: var(--radius);
  padding: 20px 18px;
  text-align: left;
  line-height: 1.75;
  color: #5b4f72;
  font-size: .96rem;
  margin: 0 auto 22px;
}
.intro-card p + p { margin-top: 12px; }

.btn-primary, .btn-secondary {
  min-height: 50px;
  border: 0;
  border-radius: 999px;
  padding: 14px 22px;
  font-size: 1rem;
  font-weight: 900;
  cursor: pointer;
  transition: transform .18s ease, box-shadow .18s ease, opacity .18s ease;
  -webkit-tap-highlight-color: transparent;
}

.btn-primary {
  color: white;
  background: linear-gradient(135deg, var(--purple), var(--pink) 58%, #ffb84d);
  box-shadow: 0 13px 30px rgba(139, 92, 246, .27);
}
.btn-secondary {
  color: #7657c7;
  background: rgba(255, 255, 255, .78);
  border: 1px solid rgba(139, 92, 246, .24);
}
.btn-primary:hover, .btn-secondary:hover { transform: translateY(-2px); }
.btn-primary:disabled, .btn-secondary:disabled { opacity: .42; cursor: not-allowed; transform: none; box-shadow: none; }

.soft-hint { margin: 14px 0 26px; color: var(--muted); font-size: .88rem; }
.footer-note { color: rgba(80, 69, 102, .72); font-size: .78rem; line-height: 1.65; margin-top: 22px; }

.quiz-header { margin: 0 auto 18px; }
.quiz-progress { color: #7c58d8; font-weight: 900; margin-bottom: 10px; }
.progress-bar { height: 10px; background: rgba(255, 255, 255, .56); border: 1px solid rgba(139, 92, 246, .14); border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; border-radius: inherit; background: linear-gradient(90deg, var(--green), var(--blue), var(--pink)); transition: width .28s ease; }

.question-box {
  border-radius: var(--radius);
  padding: 22px 18px;
  text-align: left;
}
.question-kicker { color: #8b5cf6; font-weight: 900; margin-bottom: 10px; }
.question-text { font-size: 1.15rem; line-height: 1.65; margin-bottom: 18px; }
.options-list { display: grid; gap: 12px; }
.option-btn {
  width: 100%;
  border: 1px solid rgba(139, 92, 246, .16);
  border-radius: 20px;
  background: rgba(255, 255, 255, .72);
  color: #514366;
  padding: 16px 16px;
  text-align: left;
  font-size: .98rem;
  font-weight: 700;
  line-height: 1.58;
  cursor: pointer;
  transition: all .18s ease;
}
.option-btn:hover { transform: translateY(-2px); border-color: rgba(139, 92, 246, .42); box-shadow: 0 10px 24px rgba(139, 92, 246, .12); }
.option-btn.selected { color: #fff; background: linear-gradient(135deg, #8b5cf6, #ff78b7); border-color: transparent; box-shadow: 0 12px 26px rgba(139, 92, 246, .25); }
.quiz-actions { display: grid; grid-template-columns: 1fr 1.45fr; gap: 12px; margin-top: 18px; }

.result-badge {
  display: inline-block;
  color: #fff;
  background: linear-gradient(135deg, #8b5cf6, #62c7ff);
  padding: 9px 18px;
  border-radius: 999px;
  font-size: .9rem;
  font-weight: 900;
  box-shadow: 0 12px 30px rgba(98, 199, 255, .26);
}
.result-hero {
  display: flex;
  gap: 16px;
  align-items: center;
  text-align: left;
  border-radius: var(--radius);
  padding: 18px;
  margin: 20px 0;
}
.result-orb {
  flex: 0 0 78px;
  width: 78px;
  height: 78px;
  display: grid;
  place-items: center;
  border-radius: 24px;
  font-size: 2.35rem;
  background: linear-gradient(145deg, rgba(255,255,255,.95), rgba(255,244,207,.9));
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.8), 0 12px 28px rgba(255, 211, 110, .28);
}
.result-element { color: #6d4edb; font-weight: 900; line-height: 1.55; }
.result-position { color: var(--muted); line-height: 1.55; margin-top: 4px; }
.result-cards { display: grid; gap: 13px; text-align: left; }
.result-card {
  border-radius: 22px;
  padding: 17px 16px;
}
.result-card h2 { color: #7c3aed; font-size: 1rem; margin-bottom: 8px; }
.result-card p { color: #56496d; line-height: 1.72; font-size: .95rem; }
.result-card.encouragement { background: rgba(255, 244, 207, .82); border-color: rgba(255, 190, 80, .34); }
.tags { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 18px 0 6px; }
.tags span { padding: 8px 12px; border-radius: 999px; background: rgba(255,255,255,.78); color: #7657c7; font-size: .82rem; font-weight: 900; border: 1px solid rgba(139,92,246,.18); }
.result-actions { display: grid; grid-template-columns: 1fr 1.25fr; gap: 12px; margin-top: 18px; }

@media (max-width: 430px) {
  .page { padding: 16px 12px; }
  .home-container, .quiz-container, .result-container { padding: 22px 6px; }
  .intro-card { font-size: .91rem; }
  .portrait-card { margin-top: 18px; }
  .portrait-frame { min-height: 220px; }
  .quiz-actions, .result-actions { grid-template-columns: 1fr; }
  .result-hero { align-items: flex-start; }
}


/* ========== 手机端性能优化 ========== */
@media (max-width: 640px) {
  body {
    /* 移动端使用静态渐变，避免复杂绘制 */
    background: linear-gradient(155deg, #fff7ff 0%, #eef7ff 52%, #fff4cf 100%);
  }

  .star-field::before,
  .star-field::after {
    animation-duration: 24s;
    opacity: .38;
  }

  .portrait-card {
    animation: none;
    box-shadow: 0 12px 28px rgba(111, 83, 170, 0.14);
  }

  .intro-card, .question-box, .result-card, .result-hero {
    backdrop-filter: none;
    background: rgba(255, 255, 255, 0.88);
    box-shadow: 0 10px 26px rgba(111, 83, 170, 0.12);
  }

  .portrait-frame img {
    filter: brightness(1.04) saturate(1.03);
  }

  .title, .subtitle, .portrait-card, .btn-primary {
    content-visibility: visible;
  }
}

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

@media print {
  body { background: #fff; }
  .page:not(.active), .star-field, .result-actions { display: none !important; }
  .page.active { display: block; padding: 0; }
  .result-container { max-width: 720px; }
  .result-card, .result-hero { box-shadow: none; break-inside: avoid; }
}

/* ========== 冒险卡保存反馈 ========== */
.adventure-card-view {
  border-radius: var(--radius);
}

.save-status {
  min-height: 24px;
  margin-top: 12px;
  color: var(--muted);
  font-size: .9rem;
  font-weight: 800;
  line-height: 1.5;
}

.save-status[data-state="loading"] { color: #7c58d8; }
.save-status[data-state="success"] { color: #3b9b73; }
.save-status[data-state="error"] { color: #d44f7a; }

.save-preview {
  margin: 16px auto 0;
  padding: 14px;
  border-radius: 24px;
  background: rgba(255, 255, 255, .86);
  border: 1px solid rgba(139, 92, 246, .2);
  box-shadow: 0 10px 26px rgba(111, 83, 170, 0.12);
}

.save-preview p {
  color: #7657c7;
  font-weight: 900;
  font-size: .9rem;
  margin-bottom: 10px;
}

.save-preview img {
  display: block;
  width: 100%;
  max-width: 360px;
  margin: 0 auto;
  border-radius: 18px;
  box-shadow: 0 12px 28px rgba(111, 83, 170, 0.16);
}

@media print {
  .save-status, .save-preview { display: none !important; }
}
