:root {
  --ink: #1c1a4a;
  --felt: #ff6f91;
  --felt-deep: #d6456e;
  --curtain: #c22f5a;
  --thread: #ffd35c;
  --paper: #fffdf8;
  --moonlight: #fff0c4;
  --starlight: #e6e8ff;
  --peek: max(0px, calc((100vw - 640px) / 2));
  --spring: cubic-bezier(0.3, 1.5, 0.5, 1);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; overflow-x: clip; }

body {
  --scene: #141a4f;
  margin: 0;
  background-color: var(--scene);
  color: var(--starlight);
  font-family: 'Shantell Sans', 'Comic Sans MS', 'Segoe Print', system-ui, sans-serif;
  font-variation-settings: 'BNCE' 0, 'INFM' 15;
  font-weight: 450;
  overflow-x: clip;
  transition: background-color 1200ms ease;
}

/* The night sky behind everything. */
#sky {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  background: linear-gradient(rgba(6, 8, 40, 0.55), transparent 70%);
  transition: opacity 1400ms ease;
}
#swirls { position: absolute; inset: 0; width: 100%; height: 100%; }
#swirls path { fill: none; stroke-width: 2.5; stroke-linecap: round; stroke-dasharray: 2 10; opacity: 0.32; }
#swirls .swirl-gold { stroke: var(--thread); }
#swirls .swirl-pale { stroke: #a9c4ff; }
body[data-ending='out'] #sky { opacity: 0.55; }

.sky-dot {
  position: absolute;
  width: var(--size);
  height: var(--size);
  border-radius: 50%;
  background: #fff6d6;
  opacity: 0;
  transition: opacity 1200ms ease;
}
.sky-dot.shown { opacity: var(--bright); animation: twinkle var(--twinkle) ease-in-out infinite alternate; animation-delay: var(--delay); }
@keyframes twinkle { to { opacity: calc(var(--bright) * 0.3); transform: scale(0.75); } }
.wish {
  width: 7px;
  height: 7px;
  box-shadow: 0 0 10px 3px rgba(255, 228, 140, 0.8);
  background: var(--thread);
}
body[data-ending='yes'] .sky-dot.shown { animation-duration: 1.1s; }
body[data-ending='out'] .sky-dot.shown { animation: none; }

.shooting {
  position: fixed;
  z-index: 1;
  width: 110px;
  height: 3px;
  border-radius: 3px;
  background: linear-gradient(90deg, transparent, #fff6d6);
  transform-origin: 100% 50%;
  pointer-events: none;
  animation: shoot 800ms cubic-bezier(0.2, 0.6, 0.4, 1) backwards;
  animation-delay: var(--delay, 0s);
}
@keyframes shoot {
  0% { transform: translate(0, 0) rotate(var(--angle)) scaleX(0.1); opacity: 0; }
  20% { opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) rotate(var(--angle)) scaleX(1); opacity: 0; }
}

main {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: clamp(6px, 2vh, 20px);
  width: min(100%, 30rem);
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: clamp(36px, 7vh, 72px) 20px max(10px, env(safe-area-inset-bottom));
}

/* The stage: strings, sun and heart. */
#strings {
  position: fixed;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
#strings line { stroke: var(--paper); stroke-width: 1.5; opacity: 0.5; }

/* Sized to the constellation, so its stars can't reach the words below. */
#stage {
  --puppet: calc(clamp(108px, 21vh, 180px) * var(--heart-fit, 1));
  position: relative;
  z-index: 2;
  display: flex;
  flex: none;
  align-self: center;
  align-items: center;
  justify-content: center;
  width: min(calc(var(--puppet) * 1.5), 100%);
  aspect-ratio: 200 / 186;
}

#glow {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 130%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(255, 233, 170, 0.5), rgba(255, 233, 170, 0.14) 60%, transparent);
  transform: translate(-50%, -50%) scale(var(--glow, 0.5));
  transition: transform 1000ms var(--spring);
  pointer-events: none;
}
body[data-ending='out'] #glow { opacity: 0.5; transition: transform 1200ms ease, opacity 1200ms ease; }

#constellation {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 100%;
  height: auto;
  overflow: visible;
  transform: translate(-50%, -50%);
  pointer-events: none;
}
.con-line {
  stroke: #fff0b8;
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  opacity: 0.7;
  transition: stroke-dashoffset 700ms ease-out;
}
.con-line.lit { stroke-dashoffset: 0; }
.con-star {
  fill: #6d78b8;
  transform-box: fill-box;
  transform-origin: center;
  transform: scale(0.7);
  transition: fill 400ms ease, transform 500ms var(--spring);
}
.con-star.lit { fill: var(--thread); transform: scale(1); }
body[data-ending='yes'] .con-star.lit { animation: con-twinkle 900ms ease-in-out infinite alternate; }
@keyframes con-twinkle { to { transform: scale(1.35); } }

#puppet {
  position: relative;
  display: block;
  width: var(--puppet);
  padding: 0;
  border: 0;
  border-radius: 40%;
  background: none;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
#puppet:active { cursor: grabbing; }
#swing { display: block; will-change: transform; }
#heart { display: block; width: 100%; height: auto; overflow: visible; }

#body { transform-box: fill-box; transform-origin: 50% 90%; animation: breathe 2.8s ease-in-out infinite; }
@keyframes breathe { 50% { transform: scale(1.025, 0.98); } }
#heart.jelly #body { animation: jelly 620ms ease-out; }
@keyframes jelly {
  20% { transform: scale(1.18, 0.82); }
  45% { transform: scale(0.9, 1.12); }
  70% { transform: scale(1.05, 0.96); }
}
#heart[data-mood='happy'] #body { animation: beat 1.1s ease-in-out infinite; }
@keyframes beat {
  15% { transform: scale(1.09); }
  30% { transform: scale(1); }
  45% { transform: scale(1.06); }
  60% { transform: scale(1); }
}
body[data-ending='out'] #body { animation-duration: 4.6s; }

.felt { fill: var(--felt); }
.edge { fill: none; stroke: var(--paper); stroke-width: 2.5; stroke-dasharray: 6 7; stroke-linecap: round; opacity: 0.8; }
.tear { fill: none; stroke: var(--felt-deep); stroke-width: 4.5; stroke-linejoin: round; stroke-linecap: round; transition: opacity 700ms ease; }
.cheek { fill: #ffc2d1; opacity: 0.75; transition: opacity 200ms ease, fill 200ms ease; }
.leg { fill: none; stroke: var(--paper); stroke-width: 7; stroke-linecap: round; transform-box: fill-box; transform-origin: 50% 0; }
#heart[data-mood='happy'] .leg-left { animation: kick 500ms ease-in-out infinite alternate; }
#heart[data-mood='happy'] .leg-right { animation: kick 500ms ease-in-out infinite alternate-reverse; }
@keyframes kick { from { transform: rotate(-16deg); } to { transform: rotate(16deg); } }

#eyes { transition: transform 130ms ease-out; }
.eye { fill: var(--ink); }
.glint { fill: var(--paper); }
.eye-ball { transform-box: fill-box; transform-origin: center; transition: transform 70ms linear; }
#heart[data-blink='1'] .eye-ball { transform: scaleY(0.08); }
.eye-arcs { opacity: 0; }
.eye-arcs path { fill: none; stroke: var(--ink); stroke-width: 5; stroke-linecap: round; }
#heart[data-react='boop'] .eye-arcs,
#heart[data-react='whee'] .eye-arcs,
#heart[data-mood='happy']:not([data-react]) .eye-arcs { opacity: 1; }
#heart[data-react='boop'] .eye-open,
#heart[data-react='whee'] .eye-open,
#heart[data-mood='happy']:not([data-react]) .eye-open { opacity: 0; }
#heart[data-react='boop'] .cheek { fill: #ff9db5; opacity: 1; }

.mouth { fill: none; stroke: var(--ink); stroke-width: 4.5; stroke-linecap: round; stroke-linejoin: round; opacity: 0; transition: opacity 180ms ease; }
.mouth-happy, .mouth-oh { fill: var(--ink); }
#heart[data-mood='shy']:not([data-react]) .mouth-shy,
#heart[data-mood='hopeful']:not([data-react]) .mouth-hopeful,
#heart[data-mood='still']:not([data-react]) .mouth-still,
#heart[data-mood='happy']:not([data-react]) .mouth-happy,
#heart[data-react='boop'] .mouth-happy,
#heart[data-react='whee'] .mouth-happy,
#heart[data-react='oh'] .mouth-oh { opacity: 1; }
#heart[data-mood='happy'] .tear { opacity: 0; }

.stitch {
  fill: none;
  stroke: var(--thread);
  stroke-width: 5;
  stroke-linecap: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  opacity: 0;
  transition: stroke-dashoffset 380ms ease-out, opacity 80ms linear;
}
.stitch.sewn { stroke-dashoffset: 0; opacity: 1; }

#needle { transition: transform 380ms ease-out, opacity 300ms ease; }
#needle-inner.poke { animation: poke 340ms ease-in-out; }
@keyframes poke { 45% { transform: translate(-5px, 9px); } }
.shaft { fill: none; stroke: var(--paper); stroke-width: 3.5; stroke-linecap: round; }
.trail { fill: none; stroke: var(--thread); stroke-width: 3; stroke-linecap: round; }

/* The words. */
#screen {
  position: relative;
  z-index: 3;
  flex: 1;
  font-size: calc(clamp(1.25rem, 5.2vw, 1.55rem) * var(--text-fit, 1));
  line-height: 1.4;
  text-shadow: 0 1px 8px rgba(8, 10, 48, 0.75);
}
#screen p:first-child {
  color: var(--moonlight);
  font-size: calc(1em + 2px);
  font-weight: 600;
}
#screen:focus { outline: none; }
#screen p { margin: 0 0 0.65em; }
#screen ul { margin: 0 0 0.85em; padding: 0; list-style: none; }
#screen li {
  position: relative;
  margin-bottom: 0.55em;
  padding-left: 1.5em;
  color: var(--thread);
  font-weight: 650;
}
/* A little felt heart in place of a bullet. */
#screen li::before {
  content: '';
  position: absolute;
  top: 0.32em;
  left: 0.1em;
  width: 0.92em;
  height: 0.84em;
  background: var(--felt);
  clip-path: path('M7.4 13.2C3 10.2.7 7.5.7 4.6.7 2.3 2.5.8 4.3.8c1.3 0 2.5.8 3.1 2 .6-1.2 1.8-2 3.1-2 1.8 0 3.6 1.5 3.6 3.8 0 2.9-2.3 5.6-6.7 8.6Z');
}

.word {
  display: inline-block;
  animation: word-hop 640ms cubic-bezier(0.25, 0.8, 0.35, 1) backwards;
  animation-delay: calc(var(--i) * var(--step, 45ms));
}
/* Each word drops in glowing like a little star, bounces, then settles. */
@keyframes word-hop {
  0% { opacity: 0; color: var(--thread); transform: translateY(-1em) rotate(var(--tilt)) scale(0.55); }
  50% { opacity: 1; color: var(--thread); transform: translateY(0.14em) rotate(0deg) scale(1.14, 0.88); }
  72% { transform: translateY(-0.08em) scale(0.97, 1.05); }
  88% { transform: translateY(0.02em) scale(1.01, 0.99); }
}
#screen.leaving .word { animation: word-out 240ms ease-in forwards; animation-delay: 0ms; }
@keyframes word-out {
  to { opacity: 0; transform: translateY(-0.9em) scale(0.8); }
}
body[data-ending='out'] .word { animation-name: word-soft; animation-duration: 800ms; animation-timing-function: ease; }
@keyframes word-soft { from { opacity: 0; } }

.finale {
  margin-top: 0.3em;
  font-size: 1.3em;
  font-weight: 700;
  font-variation-settings: 'BNCE' 50, 'INFM' 40;
  color: var(--thread);
}

mark {
  padding: 0 0.15em;
  border-radius: 0.25em;
  background: var(--paper);
  color: var(--ink);
  box-shadow: inset 0 -0.2em 0 var(--thread);
}

/* Controls. */
button {
  font: inherit;
  font-variation-settings: inherit;
  color: inherit;
  cursor: pointer;
}
:focus-visible { outline: 3px solid var(--thread); outline-offset: 3px; }

.answers {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 1rem;
  animation: controls-in 240ms ease-out backwards;
}
@keyframes controls-in { from { opacity: 0; } }

.answer {
  min-height: 56px;
  padding: 10px 16px;
  border: 3px solid var(--ink);
  border-radius: 18px 22px 16px 24px;
  background: var(--paper);
  color: var(--ink);
  font-size: 1.2rem;
  font-weight: 600;
  transition: transform 120ms ease-out;
}
#yes:active, .next:active, .back:active, .retry:active { transform: scale(0.94); }

#yes { grid-column: 1; }
#no { grid-column: 2; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; }

#no.escaping {
  position: fixed;
  z-index: 5;
  width: auto;
  min-height: 46px;
  white-space: nowrap;
  font-size: 1.02rem;
  font-variation-settings: 'BNCE' 85, 'INFM' 100;
  transition: left 150ms cubic-bezier(0.2, 0.9, 0.3, 1.2), top 150ms cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
#no.escaping::before,
#no.escaping::after {
  content: '';
  position: absolute;
  bottom: -11px;
  width: 13px;
  height: 9px;
  border-radius: 7px 7px 4px 4px;
  background: var(--paper);
}
#no.escaping::before { left: 28%; }
#no.escaping::after { right: 28%; }
#no.running::before { animation: scurry 90ms linear 3 alternate; }
#no.running::after { animation: scurry 90ms linear 3 alternate-reverse; }
@keyframes scurry { to { transform: translateY(-6px) rotate(-14deg); } }

.poof {
  position: fixed;
  z-index: 4;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--paper);
  pointer-events: none;
  animation: poof 420ms ease-out forwards;
}
@keyframes poof {
  to { transform: translate(var(--dx), var(--dy)) scale(0.2); opacity: 0; }
}

.out {
  display: block;
  min-height: 44px;
  margin-top: 0.8rem;
  padding: 8px 0;
  border: 0;
  background: none;
  font-size: 1.05rem;
  text-align: left;
  text-decoration: underline;
  text-underline-offset: 3px;
  animation: controls-in 240ms ease-out backwards;
}

.ask-note {
  margin: 0.2rem 0 0;
  font-size: 1rem;
  font-weight: 400;
  color: var(--starlight);
  animation: controls-in 240ms ease-out backwards;
}

#status {
  margin: 0.2rem 0 0;
  font-size: 1.05rem;
}
#status[data-state='failed'] { color: var(--thread); font-weight: 600; }

#nav {
  position: relative;
  z-index: 3;
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 56px;
}
#nav > * { animation: nav-in 320ms var(--spring) backwards; }
@keyframes nav-in { from { opacity: 0; transform: translateY(8px) scale(0.92); } }

.back {
  min-height: 44px;
  padding: 8px 12px 8px 0;
  border: 0;
  background: none;
  font-size: 1.05rem;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.next, .retry {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  margin-left: auto;
  padding: 10px 28px;
  border: 0;
  border-radius: 18px 22px 16px 24px;
  background: var(--curtain);
  color: var(--paper);
  font-size: 1.15rem;
  font-weight: 600;
  text-decoration: none;
  transition: transform 120ms ease-out;
}

/* The theatre. */
#valance {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 3;
  height: 30px;
  background:
    radial-gradient(circle at 24px 0, var(--curtain) 23px, transparent 24px) 0 6px / 48px 30px repeat-x,
    linear-gradient(var(--curtain), var(--curtain)) 0 0 / 100% 8px no-repeat;
  pointer-events: none;
}

#charms {
  position: fixed;
  top: 0;
  left: 50%;
  z-index: 2;
  width: min(100%, 30rem);
  height: 0;
  transform: translateX(-50%);
}
.charm {
  position: absolute;
  top: 12px;
  left: var(--x);
  width: 30px;
  padding-top: var(--drop);
  transform-origin: 50% 0;
  background: linear-gradient(var(--paper), var(--paper)) 50% 0 / 1.5px var(--drop) no-repeat;
  animation: sway 5s ease-in-out infinite alternate;
  animation-delay: var(--delay);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.charm svg { display: block; width: 100%; height: auto; }
.charm.swinging { animation: swing-hard 1100ms ease-out; }
@keyframes sway { from { transform: rotate(-3deg); } to { transform: rotate(3deg); } }
@keyframes swing-hard {
  15% { transform: rotate(26deg); }
  40% { transform: rotate(-18deg); }
  65% { transform: rotate(10deg); }
  85% { transform: rotate(-4deg); }
}
.moon-shape { fill: #fff0b8; }
.star-shape { fill: var(--thread); }
.peony-outer { fill: #ffa9c6; }
.peony-middle { fill: #ff7fa8; }
.peony-heart { fill: none; stroke: #d6336f; stroke-width: 2; stroke-linecap: round; }
.peony-leaf { fill: #58b368; }
.fox-fur { fill: #f28a3a; }
.fox-cheek { fill: var(--paper); }
.fox-face { fill: var(--ink); }
body[data-ending='out'] #charms { opacity: 0.4; transition: opacity 1200ms ease; }
body[data-ending='out'] .charm { animation: none; }

#curtains {
  position: fixed;
  inset: 0;
  z-index: 2;
  overflow: hidden;
  pointer-events: none;
}
#curtains.closed { z-index: 4; pointer-events: auto; }

.curtain {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 51%;
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.09) 0 16px, rgba(70, 0, 40, 0.14) 34px, rgba(255, 255, 255, 0.09) 52px),
    var(--curtain);
  transition: transform 950ms cubic-bezier(0.6, 0.05, 0.2, 1);
}
.curtain::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  width: 9px;
  background: repeating-linear-gradient(0deg, var(--thread) 0 7px, #f0b93a 7px 11px);
}
.curtain-left { left: 0; transform: translateX(calc(-100% - 2px + var(--peek))); }
.curtain-left::after { right: 0; }
.curtain-right { right: 0; transform: translateX(calc(100% + 2px - var(--peek))); }
.curtain-right::after { left: 0; }
#curtains.closed .curtain { transform: translateX(0); transition-duration: 680ms; transition-timing-function: cubic-bezier(0.5, 0, 0.2, 1.04); }

#stamp {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 76px;
  fill: var(--thread);
  transform: translate(-50%, -50%) scale(0);
}
#curtains.closed:not(.lobby) #stamp { animation: stamp 700ms 420ms var(--spring) forwards; }
@keyframes stamp { to { transform: translate(-50%, -50%) scale(1) rotate(-6deg); } }

#lobby {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 30px;
  color: var(--moonlight);
  text-align: center;
  transition: opacity 300ms ease;
}
#lobby-title {
  margin: auto 20px 0;
  font-size: clamp(1.7rem, 8vw, 2.4rem);
  font-weight: 700;
  font-variation-settings: 'BNCE' 30, 'INFM' 30;
}
#pull {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: auto;
  padding: 0 24px 16px;
  border: 0;
  background: none;
  color: var(--paper);
  font-size: 1.15rem;
  font-weight: 600;
  -webkit-tap-highlight-color: transparent;
}
#pull-swing {
  display: flex;
  flex-direction: column;
  align-items: center;
  transform-origin: 50% 0;
  animation: cord-sway 2.4s ease-in-out infinite alternate;
}
.cord { width: 3px; height: clamp(24px, 7vh, 60px); background: var(--thread); }
#pull svg { width: 64px; margin: -2px 0 12px; fill: var(--thread); }
#pull-label { text-decoration: underline; text-underline-offset: 3px; }
#pull.tug #pull-swing { animation: tug 340ms ease-in-out; }
@keyframes cord-sway { from { transform: rotate(-3deg); } to { transform: rotate(3deg); } }
@keyframes tug { 45% { transform: translateY(28px) scaleY(1.05); } }
#lobby.gone { opacity: 0; }

/* Little things that fly. */
.pop, .floater, .poof, .shooting { will-change: transform, opacity; }
.pop {
  position: fixed;
  z-index: 2;
  fill: var(--felt);
  pointer-events: none;
  animation: pop 800ms ease-out forwards;
}
@keyframes pop {
  from { transform: translate(-50%, -50%) scale(0.2); opacity: 1; }
  to { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(1) rotate(var(--turn)); opacity: 0; }
}
.floater {
  position: fixed;
  z-index: 2;
  pointer-events: none;
  animation: burst 2600ms cubic-bezier(0.15, 0.7, 0.4, 1) backwards;
  animation-delay: var(--delay);
}
@keyframes burst {
  0% { transform: translate(-50%, -50%) scale(0.1); opacity: 1; }
  70% { opacity: 1; }
  100% { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(1) rotate(var(--turn)); opacity: 0; }
}

.sr-only {
  position: absolute;
  top: 0;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
  #curtains.closed:not(.lobby) #stamp { transform: translate(-50%, -50%) scale(1); }
}
