* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* 움직임 박자 (js/motion.js 의 EASE 와 같은 값) */
:root { --ease-out: cubic-bezier(.22,1,.36,1); --ease-in: cubic-bezier(.55,0,.75,.2); --ease-inout: cubic-bezier(.65,0,.35,1); --ease-back: cubic-bezier(.34,1.56,.64,1); }
html, body { margin: 0; height: 100%; background: #1B2340; overflow: hidden; }
body { font-family: 'Gowun Dodum', sans-serif; color: #1B2340; user-select: none; -webkit-user-select: none; touch-action: manipulation; }

#app { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; }
#stage { position: relative; overflow: hidden; background: #8FCBF2; border-radius: 0; }
@media (min-aspect-ratio: 3/4) { #stage { border-radius: 1.2em; box-shadow: 0 1em 3em rgba(0,0,0,.4); } }
#fader { position: fixed; inset: 0; background: #1B2340; opacity: 0; pointer-events: none; transition: opacity .28s var(--ease-inout); z-index: 50; }
#fader.on { opacity: 1; pointer-events: auto; }

.scene-root { position: absolute; inset: 0; }
svg.scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; overflow: hidden; }
svg { overflow: visible; }
.hit { cursor: pointer; }

/* 버튼 */
.btn { font-family: 'Do Hyeon', sans-serif; font-size: 1.25em; border: 0; border-radius: 1em; padding: .55em 1.2em .45em;
  background: #fff; color: #1B2340; box-shadow: 0 .22em 0 #2F6FB3, 0 .5em 1em rgba(27,35,64,.18); cursor: pointer;
  transition: transform .34s var(--ease-back), box-shadow .12s ease; }
.btn:active { transform: translateY(.18em) scale(1.05, .9); box-shadow: 0 .04em 0 #2F6FB3; transition-duration: .06s; }
.btn.primary { background: #F4C34F; box-shadow: 0 .22em 0 #C98A26, 0 .5em 1em rgba(27,35,64,.2); }
.btn.primary:active { box-shadow: 0 .04em 0 #C98A26; }
.btn.small { font-size: 1em; padding: .4em .8em .32em; }
.btn.ghost { background: rgba(255,255,255,.85); }
.btn:disabled { opacity: .5; }

/* 덮개·카드 */
.overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; flex-direction: column;
  background: rgba(27,35,64,.45); z-index: 20; animation: fadeIn .25s var(--ease-out); padding: 1.2em; }
.card { background: #FFFDF7; border-radius: 1.4em; padding: 1.3em 1.2em 1.2em; width: 100%; max-width: 21em; text-align: center;
  box-shadow: 0 .35em 0 #D9CDB4, 0 1em 2em rgba(27,35,64,.25); animation: popIn .5s ease-out both; }
/* 연출: 카드가 먼저 서고, 안의 내용이 위에서부터 차례로 올라와 눈길을 이끈다 */
.card > * { animation: rise .42s var(--ease-out) both; }
.card > :nth-child(1) { animation-delay: .12s } .card > :nth-child(2) { animation-delay: .18s } .card > :nth-child(3) { animation-delay: .24s }
.card > :nth-child(4) { animation-delay: .30s } .card > :nth-child(5) { animation-delay: .36s } .card > :nth-child(6) { animation-delay: .42s }
.card > :nth-child(7) { animation-delay: .48s } .card > :nth-child(n+8) { animation-delay: .54s }
@keyframes rise { from { opacity: 0; transform: translateY(.8em) } to { opacity: 1; transform: none } }
.card h2 { margin: .1em 0 .2em; font-family: 'Black Han Sans', sans-serif; font-weight: 400; font-size: 1.9em; }
.card p { margin: .35em 0; line-height: 1.6; }
.card .sub { color: #5A6488; font-size: .95em; }
.row { display: flex; gap: .6em; justify-content: center; flex-wrap: wrap; margin-top: .9em; }

/* 대사 상자 */
.speech { position: absolute; left: .8em; right: .8em; bottom: 1em; z-index: 30; background: #FFFDF7; border-radius: 1.2em;
  padding: .9em 1.1em 1.1em; box-shadow: 0 .3em 0 #D9CDB4, 0 .8em 1.6em rgba(27,35,64,.25); animation: slideUp .38s var(--ease-back); min-height: 5.6em; }
.speech .who { position: absolute; top: -.9em; left: 1em; background: #F4C34F; border-radius: .8em; padding: .2em .8em .1em;
  font-family: 'Do Hyeon', sans-serif; font-size: 1.05em; box-shadow: 0 .15em 0 #C98A26; }
.speech .text { font-size: 1.08em; line-height: 1.6; }
.speech .text { animation: fadeIn .3s var(--ease-out); }
.speech .next { position: absolute; right: 1em; bottom: .5em; font-size: .9em; color: #8A93B3; animation: bob 1s ease-in-out infinite; }

/* 상단 HUD */
.hud { position: absolute; top: 0; left: 0; right: 0; z-index: 10; display: flex; align-items: center; gap: .5em; padding: .7em .7em 0; pointer-events: none; }
.hud > * { pointer-events: auto; }
.hud .title { font-family: 'Do Hyeon', sans-serif; font-size: 1.2em; background: rgba(255,255,255,.88); border-radius: .8em; padding: .3em .8em .2em; white-space: nowrap; }
.hud .bar { flex: 1; height: .8em; background: rgba(255,255,255,.6); border-radius: 1em; overflow: hidden; box-shadow: inset 0 .1em .2em rgba(0,0,0,.15); }
.hud .bar i { display: block; height: 100%; width: 0; background: linear-gradient(#FFD86B, #F0A833); border-radius: 1em; transition: width .45s var(--ease-out); }

/* 별 */
.stars { display: flex; justify-content: center; gap: .3em; margin: .3em 0 .2em; }
.stars svg { width: 2.6em; height: 2.6em; }
.stars .on { animation: starPop .6s ease-out both; }

/* 떠오르는 글씨 */
.float { position: absolute; z-index: 15; font-family: 'Do Hyeon', sans-serif; font-size: 1.4em; color: #fff; pointer-events: none;
  text-shadow: 0 .12em 0 #2F6FB3, 0 0 .4em rgba(27,35,64,.4); animation: floatUp 1s forwards; transform: translate(-50%, -50%); white-space: nowrap; --dx: 0em; --pop: 1.2; }
.float.gold { color: #FFE08A; text-shadow: 0 .12em 0 #B87A1E, 0 0 .4em rgba(27,35,64,.4); --pop: 1.5; }

.toast { position: absolute; left: 50%; top: 4.2em; transform: translateX(-50%); z-index: 25; background: #FFFDF7; border-radius: 1em;
  padding: .5em 1em .4em; font-family: 'Do Hyeon', sans-serif; font-size: 1.1em; box-shadow: 0 .25em 0 #D9CDB4; animation: toast 2.2s var(--ease-out) forwards; white-space: nowrap; }

.hint { position: absolute; z-index: 12; font-family: 'Do Hyeon', sans-serif; font-size: 1.05em; color: #fff; text-align: center;
  text-shadow: 0 .1em .3em rgba(27,35,64,.6); pointer-events: none; left: 0; right: 0; }

/* 스테이지 흐림 (지우개 도깨비가 지운 추억) */
.erase-veil { position: absolute; inset: 0; background: #F4F1EC; pointer-events: none; z-index: 5; transition: opacity .6s ease; mix-blend-mode: normal; }

/* 애니메이션 */
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
/* 튀어나올 때: 늘어났다 → 납작 → 제자리 (찌그러짐과 늘어남) */
@keyframes popIn { 0% { transform: translateY(1.2em) scale(.6, .6); opacity: 0 } 40% { transform: translateY(-.2em) scale(.94, 1.07); opacity: 1 }
  65% { transform: scale(1.04, .96) } 85% { transform: scale(.99, 1.01) } 100% { transform: none; opacity: 1 } }
@keyframes slideUp { from { transform: translateY(1.5em); opacity: 0 } to { transform: none; opacity: 1 } }
@keyframes bob { 0%,100% { transform: translateY(0) } 50% { transform: translateY(-.25em) } }
@keyframes starPop { 0% { transform: scale(0) rotate(-50deg) } 50% { transform: scale(1.4) rotate(10deg) } 72% { transform: scale(.88) rotate(-4deg) } 88% { transform: scale(1.05) rotate(1deg) } 100% { transform: scale(1) rotate(0) } }
@keyframes floatUp {
  0%   { opacity: 0; transform: translate(-50%, -50%) translate(0, .6em) scale(.3) }
  14%  { opacity: 1; transform: translate(-50%, -50%) translate(calc(var(--dx) * .12), -.25em) scale(var(--pop)); animation-timing-function: ease-out }
  30%  { transform: translate(-50%, -50%) translate(calc(var(--dx) * .3), -.8em) scale(.94) }
  42%  { transform: translate(-50%, -50%) translate(calc(var(--dx) * .45), -1.2em) scale(1); animation-timing-function: var(--ease-in) }
  100% { opacity: 0; transform: translate(-50%, -50%) translate(var(--dx), -2.6em) scale(.85) } }
@keyframes toast { 0% { opacity: 0; margin-top: -.8em } 8% { opacity: 1; margin-top: .2em } 14% { margin-top: 0 } 80% { opacity: 1; margin-top: 0 } 100% { opacity: 0; margin-top: -.4em } }
@keyframes shake { 0%,100% { transform: translateX(0) } 25% { transform: translateX(-.3em) } 75% { transform: translateX(.3em) } }
@keyframes pulse { 0%,100% { transform: scale(1) } 50% { transform: scale(1.08) } }
.shake { animation: shake .3s ease 2; }

.pulse { animation: pulse 1.4s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
.bob { animation: bob 1.6s ease-in-out infinite; transform-box: fill-box; }
.sway { animation: sway 1.2s ease-in-out; transform-box: fill-box; transform-origin: 50% 100%; }
@keyframes sway { 0%,100% { transform: rotate(0) } 25% { transform: rotate(-6deg) } 60% { transform: rotate(4deg) } }

/* 물건 도감 */
.album { background: #FFFDF7; border-radius: 1.4em; width: 100%; max-width: 22em; padding: 1em 1.1em 1.1em; text-align: center;
  box-shadow: 0 .35em 0 #D9CDB4, 0 1em 2em rgba(27,35,64,.25); animation: popIn .5s ease-out both; position: relative; }
.album .page-no { font-family: 'Do Hyeon', sans-serif; color: #8A93B3; font-size: .95em; }
.album svg.item { width: 7.5em; height: 7.5em; display: block; margin: .3em auto; }
.album h3 { margin: .1em 0; font-family: 'Black Han Sans', sans-serif; font-weight: 400; font-size: 1.6em; }
.album .memo { text-align: left; font-size: .98em; line-height: 1.7; background: #F6EFE1; border-radius: .9em; padding: .7em .9em; margin: .6em 0 .2em; min-height: 6.5em; }
.album .nav { display: flex; justify-content: space-between; align-items: center; margin-top: .8em; }
.album .dots { display: flex; gap: .35em; }
.album .dots i { width: .55em; height: .55em; border-radius: 50%; background: #D9D2C2; }
.album .dots i.on { background: #F0A833; }
.locked { filter: grayscale(1) brightness(.25) opacity(.35); }

.choices { display: grid; grid-template-columns: 1fr 1fr; gap: .5em; margin-top: .6em; }
.choice { background: #F6EFE1; border-radius: 1em; padding: .3em .2em .4em; border: .18em solid transparent; cursor: pointer; font-family: 'Do Hyeon', sans-serif; font-size: 1.05em; }
.choice.on { border-color: #F0A833; background: #FFF4D6; }
.choice svg { width: 100%; height: 5.5em; display: block; }

.link { background: none; border: 0; color: #8A93B3; font-size: .85em; text-decoration: underline; margin-top: .6em; cursor: pointer; font-family: inherit; }

/* 떡볶이 재료 버튼 */
.tray { position: absolute; left: 0; right: 0; bottom: 0; z-index: 9; display: grid; grid-template-columns: repeat(4, 1fr); gap: .45em; padding: .6em .7em 1em;
  background: linear-gradient(#C98A5A, #A86B40); border-radius: 1.2em 1.2em 0 0; box-shadow: 0 -.3em 0 #8E5832 inset; }
.ing { background: #FFFDF7; border: 0; border-radius: .9em; padding: .25em .1em .3em; font-family: 'Do Hyeon', sans-serif; font-size: .95em; color: #1B2340;
  box-shadow: 0 .2em 0 #D9CDB4; cursor: pointer; }
.ing { transition: transform .3s var(--ease-back); }
.ing:active { transform: translateY(.15em) scale(1.06, .9); box-shadow: 0 .05em 0 #D9CDB4; transition-duration: .05s; }
.ing svg { width: 2.6em; height: 2.6em; display: block; margin: 0 auto; }
.ing.want { box-shadow: 0 .2em 0 #D9CDB4, 0 0 0 .2em #F4C34F; }
.ticket { position: absolute; top: 3.4em; left: .7em; right: .7em; z-index: 9; background: #FFFDF7; border-radius: 1em; padding: .55em .8em .6em;
  box-shadow: 0 .25em 0 #D9CDB4; display: flex; align-items: center; gap: .6em; }
.ticket .menu { font-family: 'Black Han Sans', sans-serif; font-size: 1.35em; white-space: nowrap; }
.ticket .steps { display: flex; gap: .3em; flex-wrap: wrap; font-size: .9em; }
.ticket .steps span { background: #F1EADB; border-radius: .7em; padding: .15em .5em .1em; }
.ticket .steps span.done { background: #CDEBC5; text-decoration: line-through; color: #5B8A55; }
.ticket .steps span.now { background: #FFE6A3; font-weight: 700; }
.ticket .count { margin-left: auto; font-family: 'Do Hyeon', sans-serif; color: #8A93B3; white-space: nowrap; }
.action { position: absolute; left: 50%; transform: translateX(-50%); z-index: 9; }

/* 월드맵: 끌어서 움직이는 조이스틱, 발판 카드 */
.stick { position: absolute; z-index: 11; width: 5.2em; height: 5.2em; margin: -2.6em 0 0 -2.6em; border-radius: 50%; background: rgba(255,255,255,.28);
  box-shadow: inset 0 0 0 .18em rgba(255,255,255,.6); pointer-events: none; display: none; }
.stick.on { display: block; }
.stick i { position: absolute; left: 50%; top: 50%; width: 2.2em; height: 2.2em; margin: -1.1em 0 0 -1.1em; border-radius: 50%; background: #FFFDF7; box-shadow: 0 .2em 0 #D9CDB4; }
.mapcard { position: absolute; left: .8em; right: .8em; bottom: 1.1em; z-index: 12; background: #FFFDF7; border-radius: 1.2em; padding: .7em 1em .9em;
  text-align: center; box-shadow: 0 .3em 0 #D9CDB4, 0 .6em 1.2em rgba(27,35,64,.25); animation: popIn .42s ease-out both; transform-origin: 50% 100%; }
.mapcard h2 { margin: .05em 0 .2em; font-family: 'Black Han Sans', sans-serif; font-weight: 400; font-size: 1.5em; }
.mapcard .row { margin-top: .5em; }
.mapcard .sub { margin: 0; color: #5A6488; font-size: .95em; }
.mapcard .stars svg { width: 1.8em; height: 1.8em; }

/* 지우개 도깨비 등장: 위에서 쿵 떨어져(늘어남→납작) 자리 잡고, 그다음엔 건들건들 */
.card > .dk-enter, .dk-enter { transform-origin: 50% 100%; animation: dkDrop .8s ease-out both, dkIdle 2.4s .8s ease-in-out infinite; }
@keyframes dkDrop {
  0%   { transform: translateY(-4em) scale(.8, 1.25); opacity: 0; animation-timing-function: var(--ease-in) }
  40%  { transform: translateY(0) scale(.85, 1.2); opacity: 1 }
  55%  { transform: scale(1.28, .72) }
  72%  { transform: translateY(-.3em) scale(.94, 1.08) }
  86%  { transform: scale(1.04, .96) }
  100% { transform: none } }
@keyframes dkIdle { 0%,100% { transform: rotate(0) scale(1, 1) } 25% { transform: rotate(-3deg) scale(1.02, .98) } 50% { transform: translateY(-.15em) scale(.98, 1.03) } 75% { transform: rotate(3deg) scale(1.02, .98) } }

/* 얻은 물건: 아래에서 휙 올라와 호를 그리고 통 내려앉는다 */
.card > .item-get { animation: itemGet .8s .25s ease-out both; transform-origin: 50% 100%; }
@keyframes itemGet {
  0%   { transform: translateY(2em) scale(.2) rotate(-30deg); opacity: 0 }
  45%  { transform: translateY(-1em) scale(.9, 1.15) rotate(8deg); opacity: 1 }
  65%  { transform: translateY(0) scale(1.18, .86) rotate(0) }
  82%  { transform: scale(.96, 1.04) }
  100% { transform: none } }

/* 가만히 있어도 살아 있게: 숨쉬기, 고개 갸웃 (보조 동작·호감) */
.breathe { transform-box: fill-box; transform-origin: 50% 100%; animation: breathe 3.2s ease-in-out infinite; }
@keyframes breathe { 0%,100% { transform: scale(1, 1) } 50% { transform: scale(.988, 1.024) } }
.peek { transform-box: fill-box; transform-origin: 50% 90%; animation: peek 6s ease-in-out infinite; }
@keyframes peek { 0%,62%,100% { transform: rotate(0) } 68% { transform: rotate(-9deg) } 80% { transform: rotate(-9deg) } 86% { transform: rotate(2deg) } 92% { transform: rotate(0) } }
.squish-origin { transform-box: fill-box; transform-origin: 50% 100%; }

@media (prefers-reduced-motion: reduce) {
  .breathe, .peek, .dk-enter, .pulse, .bob { animation: none !important; }
}
