:root {
  --cream: #fff9ec;
  --brown: #6b4632;
  --home-bg: #ffe9c7;
  --wood: #b97f4d;
  --wood-dark: #8c5a33;
  --bag: #e58f50;
  --bag-dark: #c9733b;
}

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

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--cream);
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.sprite { position: absolute; width: 0; height: 0; }

.stage { position: fixed; inset: 0; background: var(--cream); }
.stage svg { display: block; width: 100%; height: 100%; }

/* 화면 전환 */
.screen {
  position: fixed;
  inset: 0;
  z-index: 1;
  opacity: 0;
  visibility: hidden;
  transition: opacity .25s ease, visibility 0s linear .25s;
}
.screen.active {
  opacity: 1;
  visibility: visible;
  transition: opacity .25s ease;
}
.screen:not(.active) * { animation-play-state: paused !important; }

.home {
  position: fixed;
  z-index: 5;
  left: 50%;
  bottom: calc(8px + env(safe-area-inset-bottom));
  width: clamp(56px, 14vh, 88px);
  height: clamp(56px, 14vh, 88px);
  padding: clamp(11px, 3vh, 18px);
  transform: translateX(-50%);
  border: 0;
  border-radius: 50%;
  color: var(--brown);
  background: var(--home-bg);
  cursor: pointer;
}
.home svg { display: block; width: 100%; height: 100%; }

/* 예삐의 집 */
#house { background: #ffecd0; }
#house > svg { display: block; width: 100%; height: 100%; }
.tap { cursor: pointer; outline: none; transform-box: fill-box; transform-origin: center; transition: transform .12s ease-out; }
.tap:active { transform: scale(.97); }
.yeppi-bob { transform-box: fill-box; transform-origin: 50% 100%; animation: bob 3.4s ease-in-out infinite; }
.yeppi-tail { transform-box: fill-box; transform-origin: 0% 70%; animation: tail 1.1s ease-in-out infinite alternate; }
.yeppi-eyes { transform-box: fill-box; transform-origin: center; animation: blink 4.6s linear infinite; }
@keyframes bob { 0%, 100% { transform: translateY(0) scaleY(1); } 50% { transform: translateY(-5px) scaleY(1.012); } }
@keyframes tail { from { transform: rotate(-9deg); } to { transform: rotate(13deg); } }
@keyframes blink { 0%, 95%, 100% { transform: scaleY(1); } 97.5% { transform: scaleY(.08); } }

/* 책장 */
#shelf {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3vh 4vw calc(clamp(56px, 14vh, 88px) + 16px + env(safe-area-inset-bottom));
  background: var(--wood);
}
.shelf-board {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(12px, 3vw, 44px);
  width: 100%;
  height: 100%;
  padding: 3vh 3vw 0;
  border-radius: 20px;
  border-bottom: clamp(10px, 3vh, 20px) solid #e0ac78;
  background: var(--wood-dark);
}
.book {
  position: relative;
  flex: 0 0 auto;
  width: min(25vw, 50vh);
  aspect-ratio: 3 / 4;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}
.book svg { display: block; width: 100%; height: 100%; }
.book.pop { animation: book-pop .34s ease-out; }
.book.wiggle { animation: book-wiggle .42s ease-in-out; }
@keyframes book-pop { 45% { transform: scale(1.06); } }
@keyframes book-wiggle { 25% { transform: rotate(-3deg); } 75% { transform: rotate(3deg); } }
.soon {
  position: absolute;
  left: 50%;
  top: 10%;
  padding: .25em .7em;
  transform: translateX(-50%) scale(.7);
  opacity: 0;
  border-radius: 999px;
  color: var(--brown);
  background: #fff;
  font: 700 clamp(18px, 5vh, 34px)/1.2 system-ui, sans-serif;
  transition: opacity .15s, transform .15s;
  pointer-events: none;
}
.book.say .soon { opacity: 1; transform: translateX(-50%) scale(1); }

/* 가방 */
#bag {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4vh 5vw calc(clamp(56px, 14vh, 88px) + 16px + env(safe-area-inset-bottom));
  background: var(--bag);
}
.pockets {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: clamp(14px, 3vw, 40px);
  width: 100%;
  height: 100%;
}
.pocket {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 2vh;
  border-radius: 28px;
  background: var(--bag-dark);
}
.bag-item {
  flex: 0 1 auto;
  height: 74%;
  aspect-ratio: 1;
  max-width: 100%;
  padding: 6%;
  border: 0;
  border-radius: 24px;
  background: #fff3df;
  cursor: pointer;
  transition: transform .12s ease-out;
}
.bag-item:active { transform: scale(.95); }
.bag-item svg { display: block; width: 100%; height: 100%; }
.bag-item.empty { background: rgba(255, 243, 223, .35); cursor: default; }
.bag-item.empty svg { opacity: .28; filter: grayscale(1); }
.dots { display: flex; gap: 8px; height: 16px; margin-top: 2vh; }
.dots i { width: 14px; height: 14px; border-radius: 50%; background: #fff3df; }
.cards { flex-direction: row; gap: clamp(8px, 1.6vw, 20px); }
.card-slot {
  flex: 1 1 0;
  max-height: 70%;
  aspect-ratio: 3 / 4;
  border: 4px dashed rgba(255, 243, 223, .6);
  border-radius: 14px;
}

/* 동화 */
#story { background: #fff0d2; }
#story > svg { display: block; width: 100%; height: 100%; }
.obj { cursor: pointer; transition: transform .75s cubic-bezier(.3, 1.25, .5, 1); }
.obj-in { transform-box: fill-box; transform-origin: 50% 90%; }
.obj-in.bounce { animation: obj-bounce .9s ease-in-out; }
.obj-in.shake { animation: obj-shake .8s ease-in-out; }
.obj-in.shine { animation: obj-shine .7s ease-out; }
@keyframes obj-bounce { 0%, 100% { transform: translateY(0); } 25% { transform: translateY(-46px) scale(1.05); } 50% { transform: translateY(0) scale(1.05, .94); } 72% { transform: translateY(-20px); } }
@keyframes obj-shake { 20% { transform: rotate(-7deg); } 45% { transform: rotate(6deg); } 70% { transform: rotate(-4deg); } }
@keyframes obj-shine { 40% { transform: scale(1.16); filter: brightness(1.14); } }
#s-plate { transform-box: fill-box; transform-origin: center; }
#s-plate.shine { animation: plate-shine 1.1s ease-in-out; }
@keyframes plate-shine { 35% { transform: scale(1.06); filter: brightness(1.06) drop-shadow(0 0 16px #ffe08a); } }

.sy .arm-l, .sy .arm-r { transform-box: fill-box; transform-origin: 50% 12%; transition: transform .3s ease; }
.sy.pose-tummy .arm-l { transform: rotate(-42deg); }
.sy.pose-tummy .arm-r { transform: rotate(42deg); }
.sy.pose-point .arm-r { transform: rotate(-112deg); }
.sy .sy-glint { transition: transform .25s ease; }
.sy.look-right .sy-glint { transform: translateX(8px); }
.sy.look-far .sy-glint { transform: translateX(13px); }
.sy .sy-dot { display: none; fill: #5ff0b8; }
.sy.seeing .sy-dot { display: inline; }
.sy.hearing .sy-ear { fill: #5ff0b8; }
.sy .sy-arcs, .sy .sy-talk { display: none; }
.sy.happy .sy-eyes { display: none; }
.sy.happy .sy-arcs { display: inline; }
.sy.hungry .sy-smile { transform: translateY(858px) scaleY(-1); }
.sy.talking .sy-smile { display: none; }
.sy.talking .sy-talk { display: inline; transform-box: fill-box; transform-origin: center; animation: sy-talk .34s ease-in-out infinite alternate; }
@keyframes sy-talk { from { transform: scaleY(.3); } to { transform: scaleY(1); } }

.book-open {
  position: fixed;
  z-index: 8;
  inset: 0;
  display: none;
  pointer-events: none;
  perspective: 1200px;
}
.book-open.play { display: flex; animation: book-gone .78s linear forwards; }
.book-open span { flex: 1; background: #f2a65e; border: 6px solid #fff0cf; }
.book-open span:first-child { transform-origin: left center; animation: open-l .74s ease-in forwards; }
.book-open span:last-child { transform-origin: right center; animation: open-r .74s ease-in forwards; }
@keyframes open-l { to { transform: rotateY(-88deg); } }
@keyframes open-r { to { transform: rotateY(88deg); } }
@keyframes book-gone { 0%, 92% { visibility: visible; } 100% { visibility: hidden; } }

.caption {
  position: fixed;
  z-index: 6;
  left: 50%;
  bottom: calc(10px + env(safe-area-inset-bottom));
  max-width: 88vw;
  padding: .3em .9em;
  transform: translateX(-50%);
  opacity: 0;
  border-radius: 999px;
  color: #4d3325;
  background: rgba(255, 253, 247, .94);
  font: 700 clamp(18px, 5.4vh, 36px)/1.25 system-ui, sans-serif;
  text-align: center;
  white-space: nowrap;
  pointer-events: none;
  transition: opacity .15s;
}
.caption.show { opacity: 1; }
.no-caption .caption { display: none; }

.cup-hand {
  position: fixed;
  z-index: 6;
  right: 1vw;
  top: 32vh;
  width: 14vh;
  opacity: 0;
  transform: translateX(30px) rotate(-14deg);
  pointer-events: none;
  transition: opacity .2s, transform .25s;
}
.cup-hand.show { opacity: 1; transform: translateX(0) rotate(-14deg); }
.cup-hand svg { display: block; width: 100%; }

.high-five {
  position: fixed;
  z-index: 6;
  right: 2vw;
  bottom: calc(2vh + env(safe-area-inset-bottom));
  display: none;
  width: clamp(104px, 30vh, 220px);
  height: clamp(130px, 37vh, 275px);
  padding: 0;
  transform-origin: 50% 90%;
  border: 0;
  background: none;
  cursor: pointer;
}
.high-five.show { display: block; }
.high-five svg { display: block; width: 100%; height: 100%; }
.high-five.wave { animation: palm-wave .8s ease-in-out; }
.high-five.hit { animation: palm-hit .4s ease-out; }
@keyframes palm-wave { 25% { transform: rotate(-9deg); } 70% { transform: rotate(9deg); } }
@keyframes palm-hit { 40% { transform: scale(1.2); } }

/* 보상과 사과 건네기 */
.fly-apple {
  position: fixed;
  z-index: 6;
  left: 50%;
  top: 42%;
  width: clamp(110px, 34vh, 240px);
  height: clamp(110px, 34vh, 240px);
  display: none;
  transform: translate(-50%, -50%) scale(1);
  pointer-events: none;
  transition: left .6s ease-in, top .6s ease-in, transform .6s ease-in;
}
.fly-apple svg { display: block; width: 100%; height: 100%; }
.fly-apple.show { display: block; }
.fly-apple.center { transition: transform .35s cubic-bezier(.3, 1.5, .5, 1); }
.fly-apple.small { transform: translate(-50%, -50%) scale(.2); }
.fly-apple.to-bag { left: calc(clamp(44px, 12vh, 76px) + 16px); top: calc(100% - clamp(44px, 12vh, 76px) - 16px); transform: translate(-50%, -50%) scale(.28); }
.fly-apple.from-bottom { top: 104%; transform: translate(-50%, -50%) scale(.8); }
.fly-apple.to-mouth { top: 68%; transform: translate(-50%, -50%) scale(.45); }

.reward-bag {
  position: fixed;
  z-index: 5;
  left: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  width: clamp(88px, 24vh, 152px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}
.reward-bag.show { opacity: 1; }
.reward-bag.pop { animation: book-pop .4s ease-out; }
.reward-bag svg { display: block; width: 100%; }

.controls {
  position: fixed;
  z-index: 7;
  top: calc(4px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
}
.control {
  width: 40px;
  height: 40px;
  padding: 8px;
  border: 0;
  border-radius: 50%;
  color: var(--brown);
  background: rgba(255, 249, 236, .72);
  cursor: pointer;
  transition: transform .7s linear, background .2s;
}
.control svg { display: block; width: 100%; height: 100%; }
.control.holding { transform: scale(1.25); background: #ffe0b0; }
.control.off { opacity: .5; }
#mute.off .wave { display: none; }

/* 오래 손대지 않으면 천천히 어두워진다 (화면 잔상 방지) */
.dim {
  position: fixed;
  z-index: 10;
  inset: 0;
  background: #000;
  opacity: 0;
  pointer-events: none;
  transition: opacity .5s ease-out;
}
.dim.on { opacity: .78; pointer-events: auto; transition: opacity 8s ease-in; }

/* 부모 안내·허락 */
.consent {
  position: fixed;
  z-index: 25;
  inset: 0;
  display: flex;
  align-items: safe center;
  justify-content: center;
  padding: 12px;
  overflow-y: auto;
  touch-action: pan-y;
  color: #4d3325;
  background: var(--cream);
  font: 16px/1.45 system-ui, "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  -webkit-user-select: text;
  user-select: text;
}
.consent-card {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(190px, 1fr);
  gap: clamp(16px, 3vw, 36px);
  width: min(100%, 920px);
  padding: clamp(14px, 3vh, 32px);
  border-radius: 22px;
  background: #fff3dc;
}
.consent h1 { margin: 0 0 8px; font-size: clamp(19px, 3.4vw, 28px); line-height: 1.3; }
.consent p { margin: 0 0 8px; }
.consent ul { margin: 0; padding-left: 20px; }
.consent li { margin: 3px 0; }
.consent-side { display: flex; flex-direction: column; justify-content: center; gap: 9px; }
.consent-side small { color: #7a5c49; font-size: 13px; line-height: 1.35; }
.switch {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  padding: 6px 14px;
  border-radius: 12px;
  background: #fff;
  font-weight: 700;
  cursor: pointer;
}
.switch input { width: 24px; height: 24px; margin: 0; accent-color: #e58f50; }
#consent-start {
  min-height: 50px;
  border: 0;
  border-radius: 14px;
  color: #3f2619;
  background: #ffc98f;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
}
@media (max-width: 620px) {
  .consent-card { grid-template-columns: 1fr; }
}
/* 가로 휴대폰에서도 안내 전체가 스크롤 없이 보이게 한다 */
@media (max-height: 430px) {
  .consent { padding: 6px; font-size: 13.5px; line-height: 1.32; }
  .consent-card { padding: 10px 14px; gap: 14px; border-radius: 16px; }
  .consent h1 { margin-bottom: 4px; font-size: 18px; }
  .consent p { margin-bottom: 4px; }
  .consent li { margin: 1px 0; }
  .consent-side { gap: 6px; }
  .switch { min-height: 40px; padding: 4px 12px; }
  #consent-start { min-height: 44px; font-size: 16px; }
  .consent-side small { font-size: 11.5px; line-height: 1.25; }
}

.rotate {
  display: none;
  position: fixed;
  z-index: 20;
  inset: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  color: var(--brown);
  background: var(--cream);
  font: 18px/1.4 system-ui, "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  text-align: center;
}
.rotate svg { width: min(38vw, 180px); height: min(38vw, 180px); }
.rotate p { margin: 0; font-weight: 700; }
.rotate small { max-width: 280px; color: #7a5c49; font-size: 14px; }
#rotate-now {
  min-width: 190px;
  min-height: 54px;
  border: 0;
  border-radius: 14px;
  color: #3f2619;
  background: #ffc98f;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
}
@media (orientation: portrait) and (max-width: 900px) {
  .rotate { display: flex; }
}
