/* ================= Story stage ================= */
.stage-wrap { container-type: inline-size; width: 100%; }
.stage {
  position: relative; width: 100%; aspect-ratio: 16 / 9; min-height: 340px;
  border-radius: 28px; overflow: hidden; isolation: isolate; outline: none;
  box-shadow: 0 18px 40px rgba(39, 56, 95, .22), inset 0 0 0 6px rgba(255, 255, 255, .7);
  background: #fbeedd; user-select: none; -webkit-user-select: none;
}
body.lv2 .stage { box-shadow: 0 18px 40px rgba(26, 38, 68, .3), inset 0 0 0 5px #d8b064; }
.stage.playing { aspect-ratio: auto; min-height: max(340px, 56.25cqw); }

.st-bg, .bg-layer { position: absolute; inset: 0; }
.bg-layer { opacity: 0; transition: opacity .6s ease; }
.bg-layer.on { opacity: 1; }
.bg-layer svg { width: 100%; height: 100%; display: block; }
.stage.playing .st-bg { filter: saturate(.9) brightness(.92); }
.stage.playing .st-bg::after { content: ''; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(255, 250, 240, .15), rgba(255, 245, 230, .55)); }
body.lv2 .stage.playing .st-bg::after { background: linear-gradient(180deg, rgba(26, 38, 68, .25), rgba(26, 38, 68, .5)); }

/* cast */
.st-cast { position: absolute; inset: 0; pointer-events: none; z-index: 2; --ks: 1; }
.actor {
  position: absolute; left: var(--x); bottom: var(--y); height: calc(var(--h) * var(--ks));
  transform: translateX(-50%); transition: left 1s ease-in-out, bottom .6s ease, filter .3s, opacity .3s;
}
.actor.no-anim { transition: none; }
.actor > svg { height: 100%; width: auto; display: block; overflow: visible; }
.actor.flip > svg { transform: scaleX(-1); }
.actor .person { animation: breathe 3.2s ease-in-out infinite; transform-origin: 0 300px; }
@keyframes breathe { 50% { transform: translateY(2px) scaleY(.99); } }
.actor.talking .person { animation: talkBob .5s ease-in-out infinite; }
@keyframes talkBob { 50% { transform: translateY(-5px); } }
.actor.dim { filter: brightness(.82) saturate(.85); }
.actor.walking .person { animation: walkBob .36s ease-in-out infinite; }
@keyframes walkBob { 50% { transform: translateY(-10px); } }
.actor.walking .leg-l { animation: legSwing .36s ease-in-out infinite; }
.actor.walking .leg-r { animation: legSwing .36s ease-in-out infinite reverse; }
@keyframes legSwing { 0% { transform: translateX(-6px); } 50% { transform: translateX(6px); } 100% { transform: translateX(-6px); } }
.actor .pose-wave .arm-r { animation: wave .8s ease-in-out infinite; }
@keyframes wave { 0%, 100% { transform: rotate(-150deg); } 50% { transform: rotate(-118deg); } }
.actor .pose-cheer .arm-l { animation: cheerL .7s ease-in-out infinite; }
.actor .pose-cheer .arm-r { animation: cheerR .7s ease-in-out infinite; }
@keyframes cheerL { 50% { transform: rotate(140deg); } }
@keyframes cheerR { 50% { transform: rotate(-140deg); } }
.actor .p-cat .tail { animation: tail 1.6s ease-in-out infinite; transform-origin: 40px 60px; }
@keyframes tail { 50% { transform: rotate(14deg); } }
.actor.pop-in { animation: popIn2 .45s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes popIn2 { from { transform: translateX(-50%) scale(.2); opacity: 0; } }
.actor.drop-in { animation: dropIn .6s cubic-bezier(.3, 1.4, .5, 1); }
@keyframes dropIn { from { transform: translateX(-50%) translateY(-120%); } }
.actor.pop-out { animation: popOut .35s forwards; }
@keyframes popOut { to { transform: translateX(-50%) scale(.1); opacity: 0; } }
.actor.jump { animation: jumpA .8s ease; }
@keyframes jumpA { 30% { bottom: calc(var(--y) + 9%); } 60% { bottom: var(--y); } 75% { bottom: calc(var(--y) + 3%); } }
.actor.shake { animation: shakeA .5s; }
@keyframes shakeA { 25% { transform: translateX(-54%); } 75% { transform: translateX(-46%); } }
.emo-pop { position: absolute; left: 50%; top: -4%; font-size: clamp(22px, 4cqw, 44px); animation: emoPop 1.6s ease forwards; transform: translateX(-50%); }
@keyframes emoPop { 0% { opacity: 0; transform: translate(-50%, 20px) scale(.4); } 20% { opacity: 1; transform: translate(-50%, 0) scale(1.2); } 80% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -30px); } }

/* dialog box (visual novel) */
.st-dialog {
  position: absolute; left: 3%; right: 3%; bottom: 3.5%; z-index: 20; display: flex; align-items: flex-end; gap: 10px;
  cursor: pointer; animation: dlIn .3s ease;
}
@keyframes dlIn { from { transform: translateY(20px); opacity: 0; } }
.st-dialog.hidden, .st-hint.hidden, .st-title.hidden { display: none; }
.dl-face { flex: none; width: clamp(64px, 11cqw, 120px); aspect-ratio: 1; border-radius: 50%; background: radial-gradient(circle at 50% 40%, #fff, #fdf0dc); border: 4px solid var(--tag); overflow: hidden; box-shadow: 0 6px 16px rgba(0, 0, 0, .18); }
.dl-face:empty { display: none; }
.dl-face svg { width: 100%; height: 100%; }
.dl-box {
  position: relative; flex: 1; background: rgba(255, 253, 247, .96); border-radius: 22px; padding: 14px 20px 16px;
  border: 3px solid var(--tag); box-shadow: 0 10px 24px rgba(39, 56, 95, .18); min-height: 64px;
}
body.lv2 .dl-box { background: rgba(255, 250, 240, .97); }
.dl-name { position: absolute; top: -16px; inset-inline-start: 18px; background: var(--tag); color: #fff; padding: 3px 14px; border-radius: 999px; font-size: clamp(.8rem, 1.6cqw, 1.05rem); letter-spacing: .02em; }
.dl-name:empty { display: none; }
.dl-text { margin: 4px 0 0; font-size: clamp(1rem, 2.15cqw, 1.45rem); font-weight: 700; line-height: 1.4; color: #2b2438; min-height: 1.4em; }
body.lv1 .dl-text { font-size: clamp(1.05rem, 2.4cqw, 1.6rem); }
.dl-next { position: absolute; inset-inline-end: 16px; bottom: 8px; color: var(--tag); animation: nextBob .8s infinite; font-size: 1rem; }
.st-dialog.typing .dl-next { opacity: 0; }
@keyframes nextBob { 50% { transform: translateY(4px); } }
.st-dialog.narrator .dl-box { background: rgba(39, 56, 95, .9); border-color: #d8b064; text-align: center; }
.st-dialog.narrator .dl-text { color: #fff8ec; font-style: italic; font-family: var(--f-title, inherit); }
.st-dialog.narrator .dl-next { color: #d8b064; }

/* skip */
.st-skip { position: absolute; top: 12px; inset-inline-end: 12px; z-index: 30; border: 0; border-radius: 999px; padding: 6px 12px; background: rgba(255, 255, 255, .75); font: 700 .8rem var(--f-body); color: #27385f; cursor: pointer; }
.stage.playing .st-skip, .stage.skipping .st-skip { display: none; }

/* chapter title */
.st-title { position: absolute; inset: 0; z-index: 40; display: grid; place-content: center; text-align: center; background: radial-gradient(circle, rgba(255, 248, 236, .92), rgba(255, 248, 236, .7)); animation: tIn .5s ease; }
body.lv2 .st-title { background: radial-gradient(circle, rgba(26, 38, 68, .92), rgba(26, 38, 68, .75)); color: #fff8ec; }
.st-title small { font-weight: 800; letter-spacing: .2em; text-transform: uppercase; color: var(--c, #e0708f); font-size: clamp(.8rem, 1.8cqw, 1.2rem); }
.st-title b { font-family: var(--f-title, inherit); font-size: clamp(1.6rem, 5cqw, 3.4rem); line-height: 1.1; padding: 0 20px; }
.st-title.out { animation: tOut .4s forwards; }
@keyframes tIn { from { opacity: 0; transform: scale(1.1); } }
@keyframes tOut { to { opacity: 0; transform: scale(.95); } }

/* choices */
.st-choice { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 35; background: rgba(255, 253, 247, .96); padding: 18px; border-radius: 24px; box-shadow: 0 14px 30px rgba(0, 0, 0, .2); text-align: center; width: min(92%, 640px); animation: popIn .35s; }
.st-choice p { margin: 0 0 12px; font-weight: 800; font-size: 1.15rem; }
.st-choice > div { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.ch-opt { border: 3px solid #e8d9bf; background: #fff; border-radius: 18px; padding: 10px 16px; font: 800 1.05rem var(--f-body); cursor: pointer; display: flex; align-items: center; gap: 8px; transition: transform .15s; }
.ch-opt:hover { transform: translateY(-3px); border-color: var(--c, #e0708f); }
.ch-opt .ci { font-size: 1.6rem; }

/* hint during games */
.st-hint { position: relative; z-index: 21; display: flex; align-items: center; gap: 10px; margin: 14px 14px 0; max-width: 760px; }
.st-hint .h-face { flex: none; width: clamp(52px, 7cqw, 76px); aspect-ratio: 1; border-radius: 50%; overflow: hidden; background: #fff; border: 3px solid var(--tag); }
.st-hint .h-face svg { width: 100%; height: 100%; }
.st-hint .h-txt { background: rgba(255, 253, 247, .97); border: 3px solid var(--tag); border-radius: 18px; padding: 8px 14px; font-weight: 800; font-size: clamp(.95rem, 1.9cqw, 1.25rem); box-shadow: 0 6px 14px rgba(0, 0, 0, .12); }
.st-hint.bump .h-txt { animation: bump .4s; }
@keyframes bump { 40% { transform: scale(1.05); } }
.stage:not(.playing) .st-hint { display: none; }
.stage.playing .st-hint { position: absolute; top: 0; left: 0; right: 60px; }

/* game board */
.st-play { position: relative; z-index: 10; display: none; }
.stage.playing .st-play { display: block; padding: clamp(84px, 12cqw, 110px) clamp(10px, 2.5cqw, 28px) clamp(14px, 2cqw, 24px); }
.stage.playing .st-cast { opacity: 0; transition: opacity .3s; }
.st-bravo { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 50; background: #fff; border: 4px solid #f6c64e; border-radius: 26px; padding: 16px 28px; font: 900 clamp(1.3rem, 3.6cqw, 2.2rem) var(--f-body); color: #27385f; box-shadow: 0 14px 34px rgba(0, 0, 0, .25); animation: popIn .45s cubic-bezier(.3, 1.6, .5, 1); white-space: nowrap; }
.st-bravo span { color: #f6c64e; margin-inline-end: 10px; }
.st-fx { position: absolute; inset: 0; pointer-events: none; z-index: 60; }
.spk { position: absolute; width: 14px; height: 14px; background: #f6c64e; clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%); animation: spk .8s ease-out forwards; }
@keyframes spk { to { transform: translate(var(--dx), var(--dy)) scale(.2) rotate(180deg); opacity: 0; } }
.nope { animation: nopeA .45s; }
@keyframes nopeA { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
.yes { animation: yesA .5s; }
@keyframes yesA { 40% { transform: scale(1.15); } }

/* end card */
.st-end { position: absolute; inset: 0; z-index: 45; display: grid; place-items: center; background: rgba(255, 248, 236, .55); backdrop-filter: blur(3px); animation: tIn .4s; }
body.lv2 .st-end { background: rgba(26, 38, 68, .45); }
.end-card { background: #fffdf7; border-radius: 30px; padding: 26px 26px 20px; text-align: center; width: min(92%, 560px); box-shadow: 0 20px 40px rgba(0, 0, 0, .25); border: 4px solid #f6c64e; position: relative; }
.end-rib { display: inline-block; margin-top: -50px; background: #e0708f; color: #fff; font: 900 clamp(1.1rem, 3cqw, 1.6rem) var(--f-body); padding: 10px 28px; border-radius: 14px; box-shadow: 0 6px 0 #b9506d; }
body.lv2 .end-rib { background: #27385f; box-shadow: 0 6px 0 #d8b064; }
.end-stars { font-size: clamp(2.4rem, 8cqw, 4rem); letter-spacing: 8px; margin: 10px 0; }
.end-stars span { color: #e6dccb; display: inline-block; }
.end-stars span.on { color: #f6c64e; animation: starIn .5s backwards cubic-bezier(.3, 1.8, .5, 1); text-shadow: 0 4px 0 #c99a2a; }
@keyframes starIn { from { transform: scale(0) rotate(-90deg); } }
.end-learn { background: #f0f7ff; border-radius: 18px; padding: 10px 14px; margin: 6px 0 14px; text-align: start; }
.end-learn p { margin: 4px 0 0; font-weight: 700; }
.end-btns { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* reusable game pieces */
.g-row { display: flex; flex-wrap: wrap; gap: clamp(8px, 1.6cqw, 18px); justify-content: center; align-items: flex-end; }
.g-card { background: rgba(255, 253, 247, .96); border-radius: 22px; padding: 12px; box-shadow: 0 8px 20px rgba(39, 56, 95, .15); border: 3px solid transparent; transition: transform .15s, border-color .2s; }
body.lv2 .g-card { background: rgba(255, 250, 240, .97); }
.g-tap { cursor: pointer; }
.g-tap:hover { transform: translateY(-4px); }
.g-btn { border: 0; border-radius: 16px; padding: 12px 20px; font: 900 1.1rem var(--f-body); background: #27385f; color: #fff; cursor: pointer; box-shadow: 0 5px 0 #121b33; }
.g-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #121b33; }
.g-btn.gold { background: #f6c64e; color: #27385f; box-shadow: 0 5px 0 #c99a2a; }
.g-btn.pink { background: #e0708f; box-shadow: 0 5px 0 #b9506d; }
.g-btn.green { background: #2e9d7d; box-shadow: 0 5px 0 #1d6c55; }
.g-btn[disabled] { opacity: .5; }
.g-svg { width: 100%; height: auto; display: block; }
.g-big { font-size: clamp(1.3rem, 3cqw, 2rem); font-weight: 900; }
.g-center { text-align: center; }
.g-counter { display: inline-flex; gap: 6px; align-items: center; background: #fff; border-radius: 999px; padding: 6px 14px; font-weight: 900; box-shadow: 0 4px 10px rgba(0, 0, 0, .1); }
.drop-zone.over { outline: 4px dashed #f6c64e; outline-offset: 4px; }
.drag-ghost { position: fixed; z-index: 9999; pointer-events: none; opacity: .9; transform: scale(1.08) rotate(-3deg); }

@media (max-width: 700px) {
  .stage { aspect-ratio: 4 / 5; border-radius: 20px; }
  .stage.playing { min-height: 125cqw; }
  .st-cast { --ks: .78; }
  .st-skip span { display: none; }
  .dl-face { width: 54px; }
  .stage.playing { display: flex; flex-direction: column; }
  .stage.playing .st-hint { order: -1; position: relative; right: auto; margin: 10px 54px 0 8px; }
  .stage.playing .st-hint .h-txt { font-size: .9rem; padding: 6px 10px; }
  .stage.playing .st-play { padding-top: 8px; }
}
.m-stage.is-story { background: none; padding: 0; box-shadow: none; min-height: 0; max-width: 1240px; }
body.lv2 .m-stage.is-story { background: none; }
.actor.flip .mso-t { transform: scaleX(-1); transform-box: fill-box; transform-origin: center; }
