/* ─── Design Tokens ─── */
:root {
  --bg: #F5F0E8;
  --brand-yellow: #f9e44d;
  --map-bg: #FFF3D7;
  --card: #FFFFFF;
  --primary: #B5622A;
  --primary-light: #F0E6DA;
  --text-main: #1A1A1A;
  --text-sub: #888888;
  --border: #ECECEC;
  --desc-color: #5C4033;

  --radius-card: 1rem;
  --radius-btn: 999px;
  --radius-tag: 999px;

  --fs-title: 1.625rem;
  --fs-question: 1.375rem;
  --fs-option: 1rem;
  --fs-body: 0.9375rem;
  --fs-sub: 0.8125rem;

  --page-padding: 1.5rem;
  --container-max: 23.4375rem;
  --touch-min: 3rem;
  --gap-touch: 0.5rem;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);

  --safe-padding-top: max(1.25rem, env(safe-area-inset-top, 0px));
  --safe-padding-bottom: max(1.25rem, env(safe-area-inset-bottom, 0px));
  --safe-padding-x: max(1.25rem, env(safe-area-inset-left, 0px), env(safe-area-inset-right, 0px));

  --screen-height: calc(
    100dvh - var(--safe-padding-top) - var(--safe-padding-bottom)
  );
}

/* ─── Reset & Base (Mobile First) ─── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  font-size: 100%;
  -webkit-text-size-adjust: 100%;
  min-height: 100%;
  background: var(--bg);
}

html[data-screen='welcome'],
html[data-screen='loading'] {
  background: var(--brand-yellow);
}

html[data-screen='map'] {
  background: var(--map-bg);
}

body {
  width: 100%;
  max-width: var(--container-max);
  margin: 0 auto;
  min-height: 100dvh;
  padding:
    var(--safe-padding-top)
    max(var(--page-padding), env(safe-area-inset-right, 0px))
    var(--safe-padding-bottom)
    max(var(--page-padding), env(safe-area-inset-left, 0px));
  background: var(--bg);
  font-family: -apple-system, 'PingFang SC', 'Helvetica Neue', sans-serif;
  color: var(--text-main);
  line-height: 1.5;
  overflow-x: hidden;
}

body:has(#screen-result.active) {
  overflow: hidden;
  height: 100dvh;
}

img {
  max-width: 100%;
  height: auto;
  display: block;
}

#app {
  width: 100%;
  min-height: var(--screen-height);
}

/* ─── Screen Switch ─── */
.screen {
  display: none;
}

.screen.active {
  display: block;
}

#screen-intro,
#screen-quiz,
#screen-result {
  min-height: var(--screen-height);
}

/* ─── Intro ─── */
#screen-intro {
  display: none;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  text-align: center;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: var(--page-padding);
}

#screen-intro.active {
  display: flex;
}

.intro-icon {
  font-size: clamp(3rem, 12vw, 4rem);
  line-height: 1;
  margin: var(--gap-touch) 0 1rem;
}

.intro-title {
  font-size: clamp(1.375rem, 5.5vw, var(--fs-title));
  font-weight: 700;
  color: var(--text-main);
}

.intro-subtitle {
  font-size: var(--fs-sub);
  color: var(--text-sub);
  margin-top: var(--gap-touch);
  margin-bottom: 1.25rem;
}

.intro-prologue {
  width: 100%;
  font-size: var(--fs-sub);
  color: var(--text-sub);
  line-height: 2;
  text-align: center;
  margin-bottom: 1.25rem;
}

.intro-prologue p + p {
  margin-top: 0.75rem;
}

.intro-guide {
  font-size: var(--fs-sub);
  color: var(--text-sub);
  line-height: 1.8;
  margin-bottom: 1.25rem;
}

.btn-start {
  width: 80%;
  min-height: var(--touch-min);
  padding: 0.875rem 1rem;
  font-size: var(--fs-option);
  font-weight: 600;
  font-family: inherit;
  color: #fff;
  background: var(--primary);
  border: none;
  border-radius: var(--radius-btn);
  cursor: pointer;
  transition: opacity 0.15s;
  flex-shrink: 0;
}

.btn-start:active {
  opacity: 0.85;
}

/* ─── Quiz ─── */
#screen-quiz.active {
  padding-top: var(--gap-touch);
}

.quiz-header {
  margin-bottom: 0;
}

.progress-label {
  font-size: var(--fs-sub);
  color: var(--text-sub);
  margin-bottom: var(--gap-touch);
}

.progress-bar-track {
  height: 0.25rem;
  background: var(--border);
  border-radius: var(--radius-btn);
  margin-bottom: 0.75rem;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: var(--primary);
  border-radius: var(--radius-btn);
  transition: width 0.3s ease;
  width: 0;
}

.question-text {
  font-size: clamp(1.125rem, 4.5vw, var(--fs-question));
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.5;
  margin: 1.75rem 0 1.5rem;
}

.quiz-options {
  display: flex;
  flex-direction: column;
  gap: var(--gap-touch);
}

.option-card {
  width: 100%;
  min-height: var(--touch-min);
  padding: 0.875rem 1rem;
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-card);
  display: flex;
  align-items: flex-start;
  gap: 0.875rem;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  transition: border-color 0.15s, background 0.15s;
}

.option-card.selected,
.option-card:active {
  border-color: var(--primary);
  background: var(--primary-light);
}

.option-label {
  min-width: 1.75rem;
  height: 1.75rem;
  background: var(--primary-light);
  color: var(--primary);
  border-radius: 0.375rem;
  font-size: var(--fs-sub);
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.option-text {
  flex: 1;
  padding-top: 0.125rem;
  font-size: var(--fs-option);
  color: var(--text-main);
  line-height: 1.6;
}

/* ─── Result（参考版式：头部 ~15% / 描述 ~25% / 图片 ~40% / 底部 ~20%）─── */
#screen-result.active {
  display: flex;
  flex-direction: column;
  max-height: var(--screen-height);
  overflow: hidden;
}

#result-card {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* 头部区：标签 → 饼格名 → slogan */
.result-header-zone {
  flex: 0 0 auto;
  text-align: center;
  padding-bottom: 0.25rem;
}

.result-tag-wrap {
  margin-bottom: 0.375rem;
}

.result-tag {
  display: inline-block;
  background: transparent;
  color: var(--text-sub);
  font-size: 0.75rem;
  padding: 0;
  border-radius: 0;
  letter-spacing: 0.02em;
}

.result-name {
  font-size: clamp(1.625rem, 8vw, 2.125rem);
  font-weight: 700;
  color: var(--primary);
  text-align: center;
  margin-bottom: 0.375rem;
  line-height: 1.25;
}

.result-slogan {
  font-size: clamp(0.9375rem, 3.8vw, 1.0625rem);
  color: var(--text-main);
  font-weight: 600;
  font-style: normal;
  text-align: center;
  margin: 0 0 0.875rem;
  line-height: 1.5;
}

/* 症状描述区 */
.result-desc-block {
  flex: 0 0 auto;
  margin: 0 0 0.75rem;
}

.result-desc-title {
  font-size: 0.75rem;
  color: var(--text-sub);
  text-align: center;
  margin-bottom: 0.625rem;
  letter-spacing: 0.05em;
}

.result-description {
  text-align: center;
  color: var(--desc-color);
  font-size: 0.8125rem;
  line-height: 1.75;
}

.result-description p {
  margin-bottom: 0.5rem;
  text-wrap: pretty;
}

.result-description p:last-child {
  margin-bottom: 0;
}

.result-description strong {
  font-weight: 700;
}

.result-locked-wrap {
  position: relative;
  flex: 0 0 auto;
  width: 100%;
  border-radius: 12px;
  overflow: hidden;
  margin: 0.5rem 0 1.25rem;
  min-height: clamp(14rem, 42dvh, 22rem);
}

.result-image {
  width: 100%;
  display: block;
}

/* 中间打码区：沿用最初 blur(18px) brightness(0.7) 强度，整体上移 20px */
.result-locked-blur-zone {
  position: absolute;
  left: -2.5%;
  width: 105%;
  top: calc(30% - 20px);
  bottom: calc(25% + 20px);
  pointer-events: none;
  backdrop-filter: blur(18px) brightness(0.7);
  -webkit-backdrop-filter: blur(18px) brightness(0.7);
  background: rgba(0, 0, 0, 0.18);
  mask-image: linear-gradient(
    to bottom,
    transparent 0%,
    black 10%,
    black 90%,
    transparent 100%
  );
  -webkit-mask-image: linear-gradient(
    to bottom,
    transparent 0%,
    black 10%,
    black 90%,
    transparent 100%
  );
}

.result-locked-content {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(50% - 20px);
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 20px;
  pointer-events: none;
}

.locked-icon {
  font-size: 36px;
  margin-bottom: 4px;
}

.locked-title {
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  text-align: center;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

.locked-sub {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.85);
  text-align: center;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.result-sub {
  flex: 0 0 auto;
  font-size: 0.75rem;
  color: var(--text-sub);
  text-align: center;
  margin: 0.375rem 0 0.5rem;
  padding: 0;
  border: none;
  border-radius: 0;
}

.result-brand {
  flex: 0 0 auto;
  text-align: center;
  font-size: 0.625rem;
  color: var(--text-sub);
  margin-top: 0.5rem;
  padding-top: 0.25rem;
  opacity: 0.7;
}

.result-actions {
  flex-shrink: 0;
  margin-top: 0.625rem;
  display: flex;
  flex-direction: column;
  gap: var(--gap-touch);
}

#btn-retry {
  width: 100%;
  min-height: var(--touch-min);
  font-size: var(--fs-option);
  font-family: inherit;
  cursor: pointer;
  border-radius: var(--radius-btn);
  padding: 0.625rem 1rem;
  background: transparent;
  color: var(--text-sub);
  border: 1.5px solid var(--border);
  transition: background 0.15s;
}

#btn-retry:active {
  background: var(--primary-light);
}

/* ─── Short viewport (mobile) ─── */
@media (max-height: 700px) {
  .result-name {
    font-size: 1.375rem;
  }

  .result-slogan {
    font-size: 0.875rem;
    margin-bottom: 0.625rem;
  }

  .result-description {
    font-size: 0.75rem;
    line-height: 1.65;
  }

  .result-locked-wrap {
    min-height: clamp(11rem, 38dvh, 16rem);
  }

  .result-brand {
    margin-top: 0.375rem;
  }
}

/* ─── Tablet+ enhancement ─── */
@media (min-width: 768px) {
  body {
    padding-top: max(2rem, var(--safe-top));
    padding-bottom: max(2rem, var(--safe-bottom));
  }

  .intro-prologue {
    max-width: 28rem;
  }

  .question-text {
    max-width: 28rem;
  }
}

/* ─── 来吃饼 H5：字体 ─── */
@font-face {
  font-family: 'ZhuiGuang';
  src: url('../assets/images/laichibingH5/平方追光体.ttf') format('truetype');
  font-display: swap;
}

/* ─── 来吃饼 H5：全屏页面（欢迎 / Loading / 地图）─── */
body[data-screen='welcome'],
body[data-screen='loading'] {
  max-width: none;
  width: 100%;
  background: var(--brand-yellow);
  padding-top: max(0px, env(safe-area-inset-top, 0px));
  padding-right: max(0px, env(safe-area-inset-right, 0px));
  padding-bottom: max(0px, env(safe-area-inset-bottom, 0px));
  padding-left: max(0px, env(safe-area-inset-left, 0px));
}

body[data-screen='map'] {
  max-width: none;
  width: 100%;
  background: var(--map-bg);
  padding-top: max(0px, env(safe-area-inset-top, 0px));
  padding-right: max(0px, env(safe-area-inset-right, 0px));
  padding-bottom: max(0px, env(safe-area-inset-bottom, 0px));
  padding-left: max(0px, env(safe-area-inset-left, 0px));
}

body[data-screen='welcome'] #app,
body[data-screen='loading'] #app,
body[data-screen='map'] #app {
  width: 100%;
  max-width: none;
  margin: 0;
  min-height: calc(100dvh - max(0px, env(safe-area-inset-top, 0px)) - max(0px, env(safe-area-inset-bottom, 0px)));
}

/* ─── 欢迎页 ─── */
#screen-welcome {
  position: relative;
  width: 100%;
  min-height: calc(100dvh - max(0px, env(safe-area-inset-top, 0px)) - max(0px, env(safe-area-inset-bottom, 0px)));
  background: var(--brand-yellow);
  overflow: hidden;
}

#screen-welcome.active {
  display: block;
}

.welcome-bg {
  width: 100%;
  height: calc(100dvh - max(0px, env(safe-area-inset-top, 0px)) - max(0px, env(safe-area-inset-bottom, 0px)));
  min-height: calc(100dvh - max(0px, env(safe-area-inset-top, 0px)) - max(0px, env(safe-area-inset-bottom, 0px)));
  display: flex;
  align-items: flex-start;
  justify-content: center;
  background: var(--brand-yellow);
}

.welcome-bg img {
  width: 100%;
  height: 100%;
  aspect-ratio: 3126 / 6001;
  object-fit: cover;
  object-position: top center;
}

.welcome-enter-btn {
  position: fixed;
  left: 50%;
  bottom: max(1.25rem, env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 10;
  width: min(72%, 16rem);
  min-height: var(--touch-min);
  padding: 0.75rem 1.5rem;
  font-family: 'ZhuiGuang', 'PingFang SC', sans-serif;
  font-size: 1.0625rem;
  font-weight: 700;
  color: #1a1a1a;
  background: rgba(255, 255, 255, 0.92);
  border: 2px solid #1a1a1a;
  border-radius: var(--radius-btn);
  cursor: pointer;
  box-shadow: 0 0.25rem 0 #1a1a1a;
}

.welcome-enter-btn:active {
  transform: translateX(-50%) translateY(0.125rem);
  box-shadow: 0 0.125rem 0 #1a1a1a;
}

/* ─── Loading 页 ─── */
#screen-loading {
  width: 100%;
  min-height: calc(100dvh - max(0px, env(safe-area-inset-top, 0px)) - max(0px, env(safe-area-inset-bottom, 0px)));
  display: none;
  align-items: center;
  justify-content: center;
  background: var(--brand-yellow);
  padding:
    max(0px, env(safe-area-inset-top, 0px))
    max(0px, env(safe-area-inset-right, 0px))
    max(0px, env(safe-area-inset-bottom, 0px))
    max(0px, env(safe-area-inset-left, 0px));
}

#screen-loading.active {
  display: flex;
}

.loading-inner {
  width: 72%;
  text-align: center;
}

.loading-icon-wrap {
  width: clamp(5rem, 28vw, 7rem);
  height: clamp(5rem, 28vw, 7rem);
  margin: 0 auto 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1 / 1;
}

.loading-icon {
  width: 100%;
  height: 100%;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  animation: loading-bounce 0.8s ease-in-out infinite alternate;
}

@keyframes loading-bounce {
  from { transform: scale(0.92) rotate(-4deg); }
  to { transform: scale(1.05) rotate(4deg); }
}

.loading-text {
  font-family: 'ZhuiGuang', 'PingFang SC', sans-serif;
  font-size: 1.125rem;
  color: #1a1a1a;
  margin-bottom: 1rem;
}

.loading-bar-track {
  height: 0.375rem;
  background: rgba(0, 0, 0, 0.12);
  border-radius: var(--radius-btn);
  overflow: hidden;
}

.loading-bar-fill {
  height: 100%;
  width: 0;
  background: #1a1a1a;
  border-radius: var(--radius-btn);
  transition: width 0.08s linear;
}

/* ─── 主地图 ─── */
#screen-map {
  width: 100%;
  min-height: calc(100dvh - max(0px, env(safe-area-inset-top, 0px)) - max(0px, env(safe-area-inset-bottom, 0px)));
  display: none;
  flex-direction: column;
  background: var(--map-bg);
}

#screen-map.active {
  display: flex;
}

.map-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.map-canvas {
  position: relative;
  width: 100%;
  aspect-ratio: 3126 / 6001;
  background: var(--map-bg);
}

.map-canvas--ui-ref {
  overflow: hidden;
}

.map-bg {
  display: block;
  width: 100%;
  height: 100%;
  aspect-ratio: 3126 / 6001;
  object-fit: contain;
  object-position: top center;
  pointer-events: none;
  user-select: none;
}

.map-path {
  display: none;
}

.map-nodes {
  position: absolute;
  inset: 0;
}

.map-node {
  position: absolute;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  transition: transform 0.15s;
}

.map-node-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.map-node-icon {
  width: 88%;
  height: auto;
  aspect-ratio: 1 / 1;
  max-height: 68%;
  object-fit: contain;
  display: block;
  flex-shrink: 0;
  transform: scale(var(--icon-scale, 1)) translateY(var(--icon-offset-y, 0px));
  transform-origin: center top;
  transition: filter 0.25s, opacity 0.25s;
}

.map-node-label {
  display: inline-block;
  margin-top: 0.25rem;
  padding: 0.2rem 0.55rem;
  font-family: 'ZhuiGuang', 'PingFang SC', sans-serif;
  font-size: 0.6875rem;
  font-weight: 700;
  color: #1a1a1a;
  background: #fff;
  border: 1.5px solid #1a1a1a;
  border-radius: 999px;
  white-space: nowrap;
  flex-shrink: 0;
  transition: opacity 0.25s;
}

.map-node--highlight .map-node-icon {
  animation: map-icon-bounce 0.9s ease-in-out infinite;
}

@keyframes map-icon-bounce {
  0%, 100% {
    transform: scale(var(--icon-scale, 1)) translateY(var(--icon-offset-y, 0px));
  }
  50% {
    transform: scale(var(--icon-scale, 1)) translateY(calc(var(--icon-offset-y, 0px) - 0.5rem));
  }
}

@keyframes node-bounce {
  0%, 100% { transform: translateY(0); }
  30% { transform: translateY(-12px); }
  60% { transform: translateY(-6px); }
}

.map-node.node-guiding {
  animation: node-bounce 0.8s ease infinite;
  z-index: 20 !important;
}

.map-node:active {
  transform: scale(0.98);
}

.map-node-lock-mask,
.map-node-bounce-icon,
.map-node-hit {
  display: none;
}

.map-footer {
  flex-shrink: 0;
  padding:
    0.875rem 1rem
    max(1.25rem, env(safe-area-inset-bottom, 0px));
  background: var(--map-bg);
  border-top: 1.5px solid rgba(0, 0, 0, 0.08);
  text-align: center;
}

.map-hint {
  font-family: 'ZhuiGuang', 'PingFang SC', sans-serif;
  font-size: 0.875rem;
  color: #666;
  margin-bottom: 0.625rem;
}

.map-test-btn {
  width: 100%;
  min-height: var(--touch-min);
  padding: 0.75rem 1rem;
  font-family: 'ZhuiGuang', 'PingFang SC', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  color: #1a1a1a;
  background: #fff;
  border: 2px solid #1a1a1a;
  border-radius: var(--radius-btn);
  cursor: pointer;
}

.map-test-btn:active {
  background: var(--brand-yellow);
}

.map-result-badge {
  font-family: 'ZhuiGuang', 'PingFang SC', sans-serif;
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--primary);
  line-height: 1.5;
}

/* ─── 地图弹窗 ─── */
.map-modal {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  padding:
    max(1.25rem, env(safe-area-inset-top, 0px))
    max(1.25rem, env(safe-area-inset-right, 0px))
    max(1.25rem, env(safe-area-inset-bottom, 0px))
    max(1.25rem, env(safe-area-inset-left, 0px));
}

.map-modal[hidden] {
  display: none;
}

.map-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
}

.map-modal-panel {
  position: relative;
  width: min(100%, 20rem);
  z-index: 1;
}

.map-modal-close {
  position: absolute;
  top: -0.25rem;
  right: 0;
  z-index: 2;
  width: 2rem;
  height: 2rem;
  border: 2px solid #1a1a1a;
  border-radius: 50%;
  background: #fff;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}

.map-modal-frame {
  position: relative;
}

.map-modal-bg {
  width: 100%;
  height: auto;
  aspect-ratio: 800 / 884;
  object-fit: contain;
}

.map-modal-content {
  position: absolute;
  inset: 12% 10% 14%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  text-align: center;
}

.map-modal-title {
  font-family: 'ZhuiGuang', 'PingFang SC', sans-serif;
  font-size: calc(1.125rem + 4pt);
  font-weight: 700;
  color: #1a1a1a;
  margin-bottom: 0.75rem;
}

.map-modal-body {
  font-size: calc(0.875rem + 2pt);
  line-height: 1.75;
  color: #333;
}

.map-modal-body p + p {
  margin-top: 0.5rem;
}

/* ─── 结果页：返回地图 ─── */
#btn-back-map {
  width: 100%;
  min-height: var(--touch-min);
  padding: 0.75rem 1rem;
  font-size: var(--fs-option);
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  border-radius: var(--radius-btn);
  background: #fff;
  color: var(--primary);
  border: 1.5px solid var(--primary);
  transition: background 0.15s;
}

#btn-back-map:active {
  background: var(--primary-light);
}

/* ─── 测试页字体增强 ─── */
body[data-screen='intro'] .intro-title,
body[data-screen='intro'] .btn-start,
body[data-screen='quiz'] .question-text,
body[data-screen='result'] .result-name {
  font-family: 'ZhuiGuang', 'PingFang SC', sans-serif;
}

/* ─── 全局返回按钮 ─── */
.global-back-btn {
  position: fixed;
  top: max(16px, env(safe-area-inset-top, 0px));
  left: max(16px, env(safe-area-inset-left, 0px));
  z-index: 1100;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.7);
  color: #1a1a1a;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  transition: transform 0.12s ease;
}

.global-back-btn[hidden] {
  display: none !important;
}

.global-back-btn:active {
  transform: scale(0.9);
}
