:root {
  --bg: #f8f5f9;
  --card: #ffffff;
  --primary: #d84b7a;
  --primary-dark: #b63661;
  --primary-soft: #fdecf2;
  --secondary: #6d5ce7;
  --secondary-soft: #f0edff;
  --text: #221c2a;
  --muted: #6e667b;
  --border: #ebe4ef;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --radius: 18px;
  --shadow: 0 10px 30px rgba(82, 42, 92, 0.07);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: radial-gradient(circle at top right, #fde9f1 0%, #f8f5f9 45%, #f1eefb 100%);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.55;
}

.app-shell {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  padding: 16px 16px 88px;
  padding-top: calc(16px + env(safe-area-inset-top));
  padding-right: calc(16px + env(safe-area-inset-right));
  padding-bottom: calc(88px + env(safe-area-inset-bottom));
  padding-left: calc(16px + env(safe-area-inset-left));
  position: relative;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 2px 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 16px;
  color: var(--text);
}

.brand-dot {
  width: 28px;
  height: 28px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.pill-btn {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(255, 255, 255, 0.8);
  margin-bottom: 14px;
}

.hero-card {
  background: linear-gradient(135deg, #2d1b3d 0%, #5c2856 52%, #b53f6d 100%);
  color: #fff;
  position: relative;
  overflow: hidden;
}

.hero-card::after {
  content: "";
  position: absolute;
  right: -30px;
  top: -30px;
  width: 140px;
  height: 140px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
}

.hero-badge {
  display: inline-block;
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
  margin-bottom: 10px;
  letter-spacing: 0.5px;
}

.hero-title {
  margin: 0 0 6px;
  font-size: 22px;
  font-weight: 800;
}

.hero-sub {
  margin: 0;
  font-size: 13px;
  opacity: 0.9;
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: #f2ecf5;
  padding: 4px;
  border-radius: 12px;
  margin-bottom: 16px;
}

.tab-btn {
  border: none;
  background: transparent;
  padding: 10px;
  border-radius: 9px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: 0.2s;
}

.tab-btn.active {
  background: #fff;
  color: var(--primary);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.field {
  margin-bottom: 13px;
}

.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 5px;
}

.input, .select {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  font-size: 14px;
  color: var(--text);
  background: #fcfbfd;
  outline: none;
  transition: border-color 0.2s;
}

.input:focus, .select:focus {
  border-color: var(--primary);
  background: #fff;
}

.btn {
  width: 100%;
  border: none;
  border-radius: 13px;
  padding: 13px 16px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s, opacity 0.2s;
}

.btn:active {
  transform: scale(0.985);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), #c93b8b);
  color: #fff;
  box-shadow: 0 8px 18px rgba(216, 75, 122, 0.28);
}

.btn-secondary {
  background: var(--secondary-soft);
  color: var(--secondary);
}

.btn-outline {
  background: #fff;
  color: var(--primary);
  border: 1.5px solid var(--primary);
}

.btn-sm {
  width: auto;
  padding: 8px 14px;
  font-size: 13px;
  border-radius: 10px;
}

.code-banner {
  padding: 10px 12px;
  border-radius: 11px;
  font-size: 12px;
  margin-bottom: 12px;
  display: none;
}

.code-banner.ok {
  display: block;
  background: #ecfdf5;
  color: #065f46;
  border: 1px solid #a7f3d0;
}

.code-banner.err {
  display: block;
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.device-note {
  margin-top: 12px;
  padding: 10px 12px;
  background: #f6f3fa;
  border-radius: 11px;
  font-size: 11px;
  color: var(--muted);
}

.quota-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 14px;
}

.quota-box {
  background: rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  padding: 10px 8px;
  text-align: center;
}

.quota-num {
  font-size: 18px;
  font-weight: 800;
}

.quota-label {
  font-size: 11px;
  opacity: 0.85;
}

/* 答题页 */
.progress-wrap {
  margin-bottom: 16px;
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

.progress-track {
  height: 7px;
  background: #ebe4ef;
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--secondary));
  width: 0%;
  transition: width 0.25s ease;
}

.q-card {
  min-height: 290px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.q-text {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  margin: 4px 0 18px;
  line-height: 1.6;
}

.option-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.option-item {
  border: 1.5px solid var(--border);
  background: #fcfbfd;
  border-radius: 13px;
  padding: 13px 14px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  transition: all 0.15s;
}

.option-item.selected {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.q-nav {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.quiz-question.is-entering {
  animation: quiz-enter 180ms ease-out both;
}

@keyframes quiz-enter {
  from { opacity: 0; transform: translateY(7px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-height: 740px) {
  body.quiz-open .app-shell { padding-bottom: 16px; padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
  #viewQuiz .q-card { min-height: 0; padding: 14px; }
  #viewQuiz .q-text { margin-bottom: 10px; }
  #viewQuiz .option-list { gap: 6px; }
  #viewQuiz .option-item { min-height: 44px; padding: 8px 12px; }
  #viewQuiz .q-nav { margin-top: 10px; }
}

.quiz-open .bottom-nav {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  .quiz-question.is-entering { animation: none; }
  .progress-bar { transition: none; }
}

/* 画像卡片与图表 */
.section-title {
  font-size: 15px;
  font-weight: 800;
  margin: 0 0 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.tag {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-weight: 600;
}

.tag.purple {
  background: var(--secondary-soft);
  color: var(--secondary);
}

.bar-item {
  margin-bottom: 11px;
}

.bar-head {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  margin-bottom: 4px;
}

.bar-track {
  height: 8px;
  background: #f1ebf5;
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--primary), var(--secondary));
}

.chart-box {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 6px 0;
}

.list-ul {
  margin: 0;
  padding-left: 18px;
  font-size: 13px;
  color: #3a3145;
}

.list-ul li {
  margin-bottom: 6px;
}

/* 匹配榜 */
.match-item {
  border: 1.5px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fcfbfd;
  cursor: pointer;
}

.match-item.top1 {
  border-color: #f3a6c1;
  background: linear-gradient(135deg, #fff5f8, #f7f4ff);
}

.match-score {
  font-size: 24px;
  font-weight: 900;
  color: var(--primary);
}

/* 底部导航 */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 8px 10px;
  padding: 8px calc(10px + env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) calc(10px + env(safe-area-inset-left));
  z-index: 40;
}

.nav-btn {
  border: none;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 11px;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 0;
}

.nav-btn.active {
  color: var(--primary);
  font-weight: 700;
}

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

/* 弹窗 & Toast */
.toast {
  position: fixed;
  top: 20px;
  top: calc(20px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(34, 28, 42, 0.92);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 999;
  display: none;
  max-width: 88vw;
  text-align: center;
}

.modal-mask {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: rgba(20, 14, 28, 0.55);
  z-index: 100;
  display: none;
  align-items: flex-end;
  justify-content: center;
}

.modal-mask.show {
  display: flex;
}

.modal-sheet {
  width: 100%;
  max-width: 480px;
  max-height: 88vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: #fff;
  border-radius: 22px 22px 0 0;
  padding: 20px 18px 28px;
  padding: 20px calc(18px + env(safe-area-inset-right)) calc(28px + env(safe-area-inset-bottom)) calc(18px + env(safe-area-inset-left));
}

.share-qr {
  display: block;
  margin: 12px auto;
}

.poster-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.poster-heading h3 { margin: 0; }
.poster-tip { margin: 8px 0 12px; color: var(--muted); font-size: 13px; }

#posterPreviewImg {
  display: block;
  width: 100%;
  max-width: 330px;
  margin: 0 auto 12px;
  border-radius: 12px;
  -webkit-touch-callout: default;
}

#posterDownloadLink { display: block; text-align: center; text-decoration: none; }

.hidden {
  display: none !important;
}

.share-link-box {
  background: #f6f2fa;
  border: 1px dashed #c8b6da;
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 12px;
  word-break: break-all;
  color: #4a3d5c;
  margin: 10px 0;
}

.disclaimer {
  text-align: center;
  font-size: 11px;
  color: #968da3;
  margin-top: 16px;
}
