:root {
  --ink: #30254d;
  --purple: #6d58a8;
  --purple-deep: #44336f;
  --lavender: #c6b4e7;
  --pink: #e9b7ca;
  --gold: #efc978;
  --cream: #fff9ed;
  --white: #fffdfb;
  --green: #71a58a;
  --shadow: 0 18px 45px rgba(57, 39, 91, 0.2);
}

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

html, body {
  margin: 0;
  min-height: 100%;
  overflow-x: hidden;
  color: var(--ink);
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background: #d8caeb;
}

button { font: inherit; }
button:focus-visible { outline: 4px solid rgba(239, 201, 120, .75); outline-offset: 3px; }

body {
  min-height: 100dvh;
  background:
    radial-gradient(circle at 80% 10%, rgba(255,255,255,.9), transparent 28%),
    linear-gradient(150deg, #ddd0ec 0%, #f6e9ec 48%, #d6c8e9 100%);
}

.sky { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.spark { position: absolute; width: 5px; height: 5px; border-radius: 50%; background: #fff7bc; box-shadow: 0 0 16px 5px rgba(255,247,188,.7); animation: twinkle 2.8s ease-in-out infinite; }
.s1 { left: 8%; top: 13%; }.s2 { left: 88%; top: 19%; animation-delay: .8s; }
.s3 { left: 68%; top: 61%; animation-delay: 1.7s; }.s4 { left: 19%; top: 76%; animation-delay: .4s; }
.s5 { left: 46%; top: 6%; animation-delay: 1.2s; }.s6 { left: 93%; top: 83%; animation-delay: 2.1s; }
@keyframes twinkle { 50% { transform: scale(1.8); opacity: .35; } }

#app { min-height: 100dvh; position: relative; z-index: 1; }
.screen { display: none; min-height: 100dvh; width: 100%; position: relative; }
.screen.active { display: flex; animation: screenIn .45s ease both; }
@keyframes screenIn { from { opacity: 0; transform: translateY(10px); } }

.welcome-screen {
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: max(32px, env(safe-area-inset-top)) 24px max(30px, env(safe-area-inset-bottom));
  overflow: hidden;
  background:
    linear-gradient(rgba(255,255,255,.14), rgba(255,255,255,.14)),
    radial-gradient(circle at 50% 41%, #fff5f2 0 20%, transparent 49%);
}

.welcome-screen::before, .welcome-screen::after {
  content: ""; position: absolute; width: 320px; height: 150px; opacity: .28;
  background: radial-gradient(ellipse at 50% 100%, transparent 48%, #7661a8 50% 53%, transparent 55%);
}
.welcome-screen::before { left: -120px; top: 17%; transform: rotate(25deg); }
.welcome-screen::after { right: -130px; top: 8%; transform: rotate(-28deg); }

.brand { text-align: center; z-index: 4; }
.brand-kicker { display: inline-block; color: #7d679b; font-weight: 700; letter-spacing: .18em; font-size: 13px; }
.brand h1 { margin: 7px 0 4px; font-family: "STKaiti", "KaiTi", serif; font-size: clamp(42px, 7vw, 62px); line-height: .98; color: var(--purple-deep); font-weight: 800; text-shadow: 0 2px #fff; letter-spacing: .05em; }
.brand h1 em { color: #ad6f91; font-style: normal; font-size: .72em; letter-spacing: .22em; padding-left: .22em; }
.brand p { margin: 8px 0 0; color: #796e86; font-size: 15px; }

.hero-portrait { width: min(340px, 63vw); height: min(47vh, 500px); position: relative; margin: 5px auto -4px; z-index: 2; }
.hero-portrait img { position: absolute; z-index: 2; inset: 0; width: 100%; height: 100%; object-fit: contain; object-position: center 26%; filter: drop-shadow(0 18px 16px rgba(75,53,105,.24)); }
.moon-gate { position: absolute; width: 92%; aspect-ratio: 1; border: 9px double rgba(183,143,94,.44); border-radius: 50%; left: 4%; top: 6%; background: linear-gradient(160deg, rgba(255,255,255,.66), rgba(255,243,250,.2)); box-shadow: inset 0 0 50px rgba(255,255,255,.7), 0 0 0 12px rgba(255,255,255,.15); }
.hero-name { position: absolute; z-index: 4; left: 50%; bottom: 5%; transform: translateX(-50%); white-space: nowrap; padding: 7px 18px; border: 1px solid rgba(239,201,120,.8); border-radius: 999px; background: rgba(68,51,111,.89); color: white; font-family: "STKaiti", "KaiTi", serif; font-size: 18px; box-shadow: 0 7px 20px rgba(45,32,72,.24); }

.welcome-actions { width: min(460px, 100%); display: flex; flex-direction: column; gap: 10px; align-items: center; z-index: 5; }
.mission-preview { display: flex; width: 100%; justify-content: center; gap: 7px; }
.mission-preview span { background: rgba(255,255,255,.55); padding: 7px 9px; border: 1px solid rgba(109,88,168,.13); border-radius: 13px; color: #675d78; font-size: 12px; white-space: nowrap; }
.primary-button { border: 0; cursor: pointer; color: white; background: linear-gradient(135deg, #8068b7, #5c468f); min-height: 58px; padding: 12px 28px; border-radius: 20px; font-weight: 800; font-size: 18px; box-shadow: 0 9px 0 #44336f, 0 15px 25px rgba(68,51,111,.25); transition: transform .15s, box-shadow .15s; }
.primary-button:active { transform: translateY(5px); box-shadow: 0 4px 0 #44336f, 0 9px 18px rgba(68,51,111,.2); }
.primary-button small { display: block; font-size: 11px; opacity: .72; font-weight: 500; margin-top: 2px; }
.welcome-actions .primary-button { width: 100%; }
.text-button { border: 0; background: transparent; color: #685983; font-weight: 700; padding: 9px 16px; cursor: pointer; }
.hidden { display: none !important; }

.topbar { height: 88px; padding: max(18px, env(safe-area-inset-top)) 22px 10px; display: flex; align-items: center; gap: 14px; width: 100%; }
.icon-button { width: 48px; height: 48px; flex: 0 0 48px; border: 1px solid rgba(78,58,116,.13); border-radius: 17px; background: rgba(255,255,255,.72); color: var(--purple-deep); box-shadow: 0 5px 14px rgba(63,43,91,.1); font-size: 28px; cursor: pointer; }
.speak-button { font-size: 22px; }
.chapter-title { flex: 1; display: flex; flex-direction: column; }
.chapter-title small { color: #847693; font-size: 11px; letter-spacing: .12em; }
.chapter-title strong { font-family: "STKaiti", "KaiTi", serif; font-size: 20px; }
.star-counter { min-width: 66px; height: 42px; border-radius: 18px; background: rgba(255,255,255,.7); display: flex; align-items: center; justify-content: center; gap: 7px; }
.star-counter span { color: #e9b33f; font-size: 23px; }

.map-screen { flex-direction: column; background: linear-gradient(180deg, rgba(245,238,250,.88), rgba(214,231,226,.9)); }
.map-copy { margin: 12px auto 4px; width: min(670px, calc(100% - 40px)); display: flex; align-items: center; gap: 12px; }
.pet-orb { width: 62px; height: 62px; flex: 0 0 62px; border-radius: 50%; display: grid; place-items: center; font-size: 27px; border: 4px solid rgba(255,255,255,.75); background: linear-gradient(145deg, #a894d1, #f0c9d8); box-shadow: var(--shadow); }
.speech { position: relative; flex: 1; padding: 13px 17px; border-radius: 8px 20px 20px 20px; background: rgba(255,255,255,.78); box-shadow: 0 8px 25px rgba(65,50,86,.1); display: flex; flex-direction: column; }
.speech strong { font-size: 16px; }.speech span { font-size: 12px; color: #786d82; margin-top: 2px; }

.adventure-map { position: relative; flex: 1; width: min(700px, 100%); margin: 0 auto; padding: 18px 30px 42px; display: grid; grid-template-rows: repeat(4, 1fr); gap: 13px; }
.path-line { position: absolute; left: 50%; top: 8%; bottom: 8%; width: 5px; transform: translateX(-50%); background: repeating-linear-gradient(to bottom, rgba(149,119,173,.28) 0 10px, transparent 10px 20px); }
.map-stop { position: relative; z-index: 2; align-self: center; width: min(390px, 84%); min-height: 94px; border: 0; cursor: pointer; border-radius: 32px; display: flex; align-items: center; gap: 14px; padding: 13px 20px 13px 14px; color: var(--ink); background: rgba(255,255,255,.84); box-shadow: 0 12px 28px rgba(63,47,87,.14), inset 0 0 0 2px rgba(255,255,255,.7); }
.map-stop:nth-of-type(odd) { justify-self: start; }.map-stop:nth-of-type(even) { justify-self: end; }
.stop-icon { width: 66px; height: 66px; flex: 0 0 66px; display: grid; place-items: center; border-radius: 23px; font-size: 34px; background: #f5dfeb; }
.castle .stop-icon { background: #e6ddf4; }.treasury .stop-icon { background: #dcecec; }.finale .stop-icon { background: #fff0ca; }
.stop-text { text-align: left; flex: 1; display: flex; flex-direction: column; }
.stop-text b { font-family: "STKaiti", "KaiTi", serif; font-size: 20px; }.stop-text small { color: #81738d; font-size: 12px; margin-top: 3px; }
.stop-state { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; color: white; background: var(--purple); font-weight: 800; }
.map-stop.locked { filter: grayscale(.7); opacity: .56; cursor: default; }
.map-stop.completed .stop-state { background: var(--green); font-size: 0; }
.map-stop.completed .stop-state::after { content: "✓"; font-size: 16px; }

.game-screen { flex-direction: column; align-items: center; padding-bottom: max(24px, env(safe-area-inset-bottom)); background: radial-gradient(circle at 50% 30%, #fffaf5, #e4d7ef 76%); }
.game-topbar { max-width: 780px; }
.progress-wrap { flex: 1; }
.progress-label { display: flex; justify-content: space-between; align-items: center; font-size: 13px; margin-bottom: 7px; color: #776989; }
.progress-track { width: 100%; height: 10px; background: rgba(255,255,255,.75); border-radius: 99px; overflow: hidden; }
.progress-track i { display: block; width: 14%; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #ba86ae, #7a62b2); transition: width .5s ease; }
.game-card { flex: 1; width: min(720px, calc(100% - 28px)); min-height: 540px; margin: 8px auto 0; padding: clamp(24px, 5vw, 45px); border-radius: 38px; background: rgba(255,253,251,.86); box-shadow: var(--shadow), inset 0 0 0 2px rgba(255,255,255,.8); text-align: center; display: flex; flex-direction: column; align-items: center; }
.level-badge { display: inline-block; border-radius: 999px; padding: 7px 14px; background: #eee5f5; color: #715c94; font-size: 12px; font-weight: 800; letter-spacing: .08em; }
.question-pinyin { margin-top: 14px; min-height: 20px; color: #9a78a8; font-size: clamp(13px, 2.5vw, 16px); font-weight: 700; letter-spacing: .06em; line-height: 1.45; }
.game-card h2 { margin: 2px 0 9px; font-family: "STKaiti", "KaiTi", serif; font-size: clamp(25px, 5vw, 34px); }
.copy-pinyin { min-height: 17px; color: #aa91b3; font-size: clamp(11px, 2vw, 13px); letter-spacing: .035em; line-height: 1.4; }
.game-card > p { margin: 0; color: #756b7c; font-size: 14px; }
.play-area { width: 100%; flex: 1; min-height: 230px; display: flex; align-items: center; justify-content: center; margin: 14px 0 8px; }
.answer-tray { width: 100%; display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; min-height: 64px; }
.answer-button { position: relative; min-width: 82px; min-height: 72px; border: 2px solid #eadff0; border-radius: 21px; background: white; color: var(--ink); font-size: 30px; cursor: pointer; box-shadow: 0 7px 0 #ddd0e5; transition: transform .15s, background .15s, opacity .2s; }
.answer-button:active { transform: translateY(4px); box-shadow: 0 3px 0 #ddd0e5; }
.answer-button.selected { background: #e5d9f3; border-color: #8b71b6; transform: translateY(3px); box-shadow: 0 4px 0 #a28dbd; }
.answer-button.wrong { animation: shake .35s; background: #f8e2e5; }
.answer-button.eliminated { opacity: .2; pointer-events: none; }
@keyframes shake { 25% { transform: translateX(-7px); } 75% { transform: translateX(7px); } }
.hint-text { min-height: 22px; color: #a1627d !important; font-weight: 700; margin: 10px 0 0 !important; }
.check-button { margin-top: 12px; min-width: 210px; }

.item-grid { display: grid; grid-template-columns: repeat(3, minmax(76px, 1fr)); gap: 13px; width: min(480px, 100%); }
.item-card { aspect-ratio: 1; border: 2px solid #eadff0; border-radius: 24px; background: #fff; font-size: clamp(38px, 8vw, 57px); cursor: pointer; box-shadow: 0 7px 0 #dfd2e6; }
.item-card.selected { background: #eadff6; border-color: #856caf; transform: translateY(3px); box-shadow: 0 4px 0 #a28dbd; }
.item-card.wrong { animation: shake .35s; background: #f8e2e5; }

.rule-banner { border: 2px dashed #bda8d2; background: #f6eff9; padding: 13px 22px; border-radius: 20px; font-size: 18px; font-weight: 800; }
.rule-banner b { color: #a65d80; }

.maze { --cols: 5; display: grid; grid-template-columns: repeat(var(--cols), 1fr); gap: 5px; width: min(390px, 90vw); padding: 9px; border-radius: 24px; background: #d5c6df; box-shadow: inset 0 0 18px rgba(68,51,111,.16); }
.maze-cell { aspect-ratio: 1; border: 0; border-radius: 12px; background: #fffaf5; font-size: clamp(22px, 5vw, 34px); cursor: pointer; color: #5d4e72; }
.maze-cell.wall { background: #8d7ca4; cursor: default; box-shadow: inset 0 0 0 3px rgba(255,255,255,.12); }
.maze-cell.visited { background: #e6daf2; }
.maze-cell.hero { background: #f5d8e7; box-shadow: 0 0 0 3px #c281a4 inset; }
.maze-cell.goal { background: #fff0b9; }
.maze-cell.next-step { animation: pulseCell 1.2s infinite; }
@keyframes pulseCell { 50% { box-shadow: 0 0 0 4px rgba(239,201,120,.75) inset; } }

.sort-stage { width: 100%; }
.sort-slots { display: flex; justify-content: center; gap: 9px; margin-top: 22px; min-height: 70px; }
.sort-slot { width: 64px; height: 64px; border: 2px dashed #b6a4c8; border-radius: 18px; display: grid; place-items: center; font-size: 25px; font-weight: 800; color: #6d58a8; background: rgba(238,229,245,.45); }
.sort-slot.filled { border-style: solid; background: #eee4f7; }
.number-gem { min-width: 76px; color: white; font-size: 23px; font-weight: 800; background: linear-gradient(145deg, #9b84c7, #65509a); border-color: #c8b5e0; box-shadow: 0 7px 0 #4d3c78; }
.number-gem.used { opacity: .2; pointer-events: none; }
.comparison { display: flex; align-items: center; justify-content: center; gap: 18px; }
.formula-card { min-width: 130px; padding: 27px 14px; border-radius: 27px; background: linear-gradient(145deg, #fff, #f0e7f5); box-shadow: 0 9px 0 #ddd0e6; font-size: 27px; font-weight: 800; }
.comparison-mark { font-size: 36px; color: #b3859e; }
.target-lock { width: min(300px, 90%); padding: 22px; border-radius: 28px; background: linear-gradient(145deg, #5a477d, #826cb0); color: white; box-shadow: 0 10px 0 #42345f; }
.target-lock small { display: block; opacity: .76; }.target-lock b { font-size: 56px; color: #ffe8a4; }
.pattern-stage { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 10px; }
.pattern-number { width: 68px; height: 68px; border-radius: 21px; display: grid; place-items: center; background: linear-gradient(145deg, #fff, #eee5f6); box-shadow: 0 7px 0 #d9cce3; color: #5f4a89; font-size: 25px; font-weight: 800; }
.pattern-number.mystery { background: #fff0c6; color: #b27838; box-shadow: 0 7px 0 #e3c990; }

.feedback { position: fixed; z-index: 20; left: 50%; bottom: 0; width: min(720px, calc(100% - 24px)); transform: translate(-50%, 110%); padding: 21px 26px max(25px, env(safe-area-inset-bottom)); border-radius: 34px 34px 0 0; background: #fffdf9; box-shadow: 0 -18px 60px rgba(55,39,77,.22); display: grid; grid-template-columns: 65px 1fr auto; grid-template-rows: auto auto; column-gap: 17px; align-items: center; transition: transform .45s cubic-bezier(.2,.85,.25,1.12); pointer-events: none; visibility: hidden; }
.feedback.show { transform: translate(-50%, 0); pointer-events: auto; visibility: visible; }
.feedback-star { grid-row: 1 / 3; width: 62px; height: 62px; display: grid; place-items: center; border-radius: 50%; background: #fff1b8; color: #e7ae35; font-size: 36px; animation: starPop .55s .25s both; }
@keyframes starPop { from { transform: scale(.2) rotate(-40deg); } }
.feedback strong { font-family: "STKaiti", "KaiTi", serif; font-size: 24px; }.feedback span { color: #746a7b; font-size: 13px; }
.feedback .primary-button { grid-column: 3; grid-row: 1 / 3; min-height: 51px; font-size: 15px; box-shadow: 0 6px 0 #44336f; }

.finish-screen { flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: max(40px, env(safe-area-inset-top)) 24px max(30px, env(safe-area-inset-bottom)); overflow: hidden; background: radial-gradient(circle at 50% 35%, #fffaf0, #dacbe9 66%); }
.finish-glow { position: absolute; width: 520px; height: 520px; border-radius: 50%; background: repeating-conic-gradient(from 0deg, rgba(255,255,255,.55) 0 4deg, transparent 4deg 14deg); animation: spin 24s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.finish-screen > *:not(.finish-glow) { position: relative; z-index: 2; }
.crown { font-size: 54px; color: #d5a747; text-shadow: 0 4px #fff2bb; }
.finish-screen h2 { margin: 8px 0; font-family: "STKaiti", "KaiTi", serif; font-size: clamp(34px, 7vw, 52px); color: var(--purple-deep); line-height: 1.08; }
.gem-reward { font-size: 86px; filter: drop-shadow(0 12px 12px rgba(91,60,130,.22)); animation: float 2.5s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(-9px); } }
.result-card { width: min(490px, 100%); padding: 18px 12px; margin: 11px 0; border-radius: 27px; display: grid; grid-template-columns: repeat(3,1fr); background: rgba(255,255,255,.72); box-shadow: 0 10px 30px rgba(60,43,84,.12); }
.result-card div { display: flex; flex-direction: column; border-right: 1px solid #e7ddea; }.result-card div:last-child { border: 0; }
.result-card b { color: #735b9f; font-size: 26px; }.result-card span { color: #7b7081; font-size: 11px; }
.reward-collection { width: min(560px, 100%); margin: 4px 0 8px; }
.reward-collection > strong { display: block; color: #66557f; font-size: 13px; margin-bottom: 9px; }
.reward-list { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; }
.reward-item { width: 60px; min-height: 66px; padding: 6px 3px; border-radius: 16px; background: rgba(255,255,255,.72); box-shadow: 0 5px 14px rgba(63,43,91,.1); display: flex; flex-direction: column; align-items: center; justify-content: center; }
.reward-item span { font-size: 27px; line-height: 1.1; }
.reward-item small { margin-top: 5px; color: #695b78; font-size: 10px; white-space: nowrap; }
.finish-message { color: #685f70; line-height: 1.7; }
.finish-screen .primary-button { min-width: 260px; }

@media (min-width: 800px) and (orientation: landscape) {
  .welcome-screen { display: none; }
  .welcome-screen.active { display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr auto; padding: 45px 8vw; }
  .brand { align-self: end; text-align: left; padding-left: 3vw; }
  .brand h1 { font-size: 70px; }
  .hero-portrait { grid-column: 2; grid-row: 1 / 3; width: min(460px, 42vw); height: 82vh; margin: auto; }
  .welcome-actions { align-self: start; padding-left: 3vw; }
  .mission-preview { justify-content: flex-start; }
  .game-card { min-height: 560px; }
}

@media (max-height: 720px) {
  .hero-portrait { height: 42vh; }
  .brand h1 { font-size: 38px; }
  .welcome-screen { padding-top: 18px; }
  .game-card { min-height: 470px; padding-top: 22px; }
  .question-pinyin { margin-top: 8px; }
}

@media (max-width: 520px) {
  .topbar { padding-left: 14px; padding-right: 14px; }
  .map-stop { width: 92%; min-height: 82px; border-radius: 26px; padding: 10px 14px 10px 10px; }
  .stop-icon { width: 58px; height: 58px; flex-basis: 58px; font-size: 29px; }
  .feedback { grid-template-columns: 54px 1fr; }
  .feedback-star { width: 52px; height: 52px; font-size: 30px; }
  .feedback .primary-button { grid-column: 1 / 3; grid-row: 3; margin-top: 15px; width: 100%; }
}

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