body.party-level { background: #e4dff3; }
body.party-level #level .header h1 { font-size: clamp(14px, 2.8vw, 32px); }
#partyWorld {
  position: absolute;
  inset: 0 auto auto 0;
  background: #273548 url('assets/party-garden-clean.jpg') center / 100% 100% no-repeat;
  pointer-events: none;
}
.party-star {
  position: absolute;
  z-index: 2;
  aspect-ratio: 1;
  background: url('assets/party-collectible-star.png') center / contain no-repeat;
  transform: translate(-50%, -70%);
  animation: party-star-glow 2s ease-in-out infinite alternate;
}
@keyframes party-star-glow {
  from { filter: drop-shadow(0 0 3px #ffdd7e); }
  to { filter: drop-shadow(0 0 10px #ffe4a8); }
}
#partyPickup {
  position: absolute;
  z-index: 20;
  aspect-ratio: 1;
  background: url('assets/party-collectible-star.png') center / contain no-repeat;
  filter: drop-shadow(0 0 12px #ffe17d);
  pointer-events: none;
}
body.party-level #total.party-counted { animation: party-counter-pulse .7s ease-out; }
body.party-level #total.party-counted::after {
  content: '+1';
  position: absolute;
  top: 100%;
  left: 50%;
  color: #b66c13;
  text-shadow: 0 1px #fff6ce, 0 0 7px #ffe080;
  font-size: clamp(13px, 1.6vw, 20px);
  animation: party-counter-gain .8s ease-out forwards;
}
@keyframes party-counter-pulse {
  35% { scale: 1.14; filter: drop-shadow(0 0 8px #fff0ad); }
}
@keyframes party-counter-gain {
  from { opacity: 1; transform: translate(-50%, 5px); }
  to { opacity: 0; transform: translate(-50%, -12px); }
}
#partyBear {
  position: absolute;
  z-index: 3;
  transform: translate(-50%, -86.5%);
}
#partyBearSprite {
  width: 100%;
  height: 100%;
  background: url('assets/party-bear-walk.png') 33.333% 0 / 400% 100% no-repeat;
  transform: scaleX(var(--party-facing, 1));
}
#partyBearShadow {
  position: absolute;
  z-index: 1;
  aspect-ratio: 4 / 1;
  transform: translate(-50%, -40%);
  background: radial-gradient(ellipse, #614c3a66, transparent 70%);
}
#partyBird {
  position: absolute;
  z-index: 4;
  transform: translate(-50%, -50%);
  animation: party-bird-hover 2s ease-in-out infinite;
}
@keyframes party-bird-hover { 50% { transform: translate(-50%, calc(-50% - 5px)); } }
body.party-level #level .scene-label { background: linear-gradient(145deg, #fff2cb, #d7b5ed); border-color: #fff2d3; color: #5d3972; }
body.party-level #level .feedback.success { color: #6d507b; }
body.party-level #level footer { background: #eee2f5; color: #6a547f; }
@media (max-width: 600px) {
  body.party-level #level .header h1 { font-size: 15px; }
}
@media (prefers-reduced-motion: reduce) {
  body.party-level #total.party-counted::after { display: none; }
}

#partyInvitationScene { position: absolute; inset: 0; overflow: hidden; background: #273548; }
#partyInvitationScene[hidden] { display: none; }
#partyInvitationStage {
  position: absolute;
  inset: 0;
  background: url('assets/party-invitation-visible-arch-v5.png') center / auto var(--invitation-stage-height) no-repeat;
  transition: transform 1.2s ease, filter 1.2s ease;
}
#partyInvitationArt { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); }
#partyInvitationBook {
  position: absolute;
  z-index: 10;
  left: 50%; top: 50%;
  width: var(--invitation-book-width);
  height: var(--invitation-book-height);
  transform: translate(-50%, -25%) perspective(900px) rotateX(62deg) scale(.40);
  transform-origin: 50% 80%;
  opacity: 0;
  pointer-events: none;
  transition: transform 1s cubic-bezier(.2,.7,.2,1), opacity .6s, width .4s, height .4s;
  perspective: 1400px;
  perspective-origin: 50% 45%;
}
.invitation-upright-art { display: block; width: 100%; height: 100%; filter: drop-shadow(0 12px 15px #25132766); }
.book-raised #partyInvitationBook { transform: translate(-50%, -50%) perspective(900px) rotateX(0deg) scale(1); opacity: 1; }
.book-raised:not(.sealed) #partyInvitationStage { filter: brightness(.62) blur(1px); }
#partyInvitationScene.book-cinema { position: fixed; z-index: 80; border-radius: 0; }
#partyInvitationWriting { position: absolute; inset: 0; z-index: 2; pointer-events: none; transition: opacity .5s ease; }
.invitation-leaf, .invitation-turn-surface {
  /* The same artwork and coordinates keep the resting sheets aligned with the binding.
     The mask follows the whole paper outline, including its curved gilded edges. */
  background: url('assets/party-invitation-paper-only.png') no-repeat;
  background-size: var(--invitation-book-width) var(--invitation-book-height);
  background-position: calc(var(--invitation-book-width) * -.5) 0;
  clip-path: polygon(0 14%, 5% 9%, 12% 5%, 21% 3%, 30% 3%, 44% 5%, 60% 7%, 79% 8%, 95% 8%, 97% 24%, 98% 51%, 99% 77%, 99% 93%, 96% 95%, 78% 95%, 58% 93%, 36% 91%, 21% 92%, 11% 95%, 0 99%);
}
.invitation-leaf { position: absolute; left: 50%; top: 0; width: 46%; height: 84%; }
.invitation-leaf.left, .invitation-turn-surface.back {
  background-position: calc(var(--invitation-book-width) * -.04) 0;
  clip-path: polygon(100% 14%, 95% 9%, 88% 5%, 79% 3%, 70% 3%, 56% 5%, 40% 7%, 21% 8%, 5% 8%, 3% 24%, 2% 51%, 1% 77%, 1% 93%, 4% 95%, 22% 95%, 42% 93%, 64% 91%, 79% 92%, 89% 95%, 100% 99%);
}
.invitation-leaf.left { left: 4%; }
.invitation-leaf[hidden], .invitation-leaf.flipped { visibility: hidden; }
#partyInvitationPageBack { display: none; }
.invitation-written-line,
.invitation-turn-ink {
  position: absolute;
  left: 16%; top: 28%; width: 70%;
  margin: 0;
  font-family: 'Kaiti SC', 'KaiTi', 'STKaiti', serif;
  font-size: clamp(18px, calc(var(--invitation-book-width) / 30), 26px);
  line-height: 1.45;
  color: #71401f;
  transition: text-shadow .5s;
}
.invitation-written-line[data-line="0"] { font-weight: bold; }
.invitation-written-line.active { color: #9c601c; text-shadow: 0 0 6px #ffe087; }
#partyInvitationTurn { position: absolute; inset: 0; z-index: 8; transform-style: preserve-3d; }
.invitation-turn-root { position: absolute; left: 50%; top: 0; width: 46%; height: 84%; transform-style: preserve-3d; }
.invitation-turn-strip {
  position: absolute;
  left: 100%; top: 0; height: 100%;
  transform-origin: left center;
  transform-style: preserve-3d;
}
.invitation-turn-root > .invitation-turn-strip { left: 0; }
.invitation-turn-face { position: absolute; inset: 0 -.5px 0 0; overflow: hidden; backface-visibility: hidden; }
.invitation-turn-face.front { transform: translateZ(.2px); }
.invitation-turn-face.back { transform: rotateY(180deg) translateZ(.2px); }
.invitation-turn-surface { position: absolute; top: 0; }
.invitation-turn-face::after {
  content: '';
  position: absolute;
  inset: 0;
  background: #6e442f;
  opacity: var(--page-shade, 0);
  pointer-events: none;
}
#partyInvitationPageShadow {
  position: absolute;
  z-index: 5;
  left: 50%; top: 0; width: 46%; height: 84%;
  opacity: 0;
  background: linear-gradient(90deg, #674527, #67452755 60%, transparent);
  filter: blur(7px);
  transform-origin: left center;
}
#partyInvitationQuill {
  position: absolute;
  z-index: 12;
  left: 88%; top: 80%;
  width: 15%;
  transform: translate(-21%, -93%);
  transform-origin: 21% 93%;
  pointer-events: none;
}
.writing #partyInvitationQuill { filter: drop-shadow(0 0 5px #ffeeb1); }
#partyInvitationBird {
  position: absolute;
  z-index: 5;
  left: 50%; top: 30%; width: 19%;
  transform: translate(-50%, -50%);
  animation: party-bird-hover 2s ease-in-out infinite;
}
#partyInvitationEnvelope {
  position: absolute;
  z-index: 6;
  left: 51%; top: 60%; width: 27%;
  transform: translate(-50%, -50%);
  opacity: 0;
  pointer-events: none;
}
#partyInvitationPaws { position: absolute; left: 57%; top: 65%; width: 29%; display: flex; gap: 6%; }
.invitation-paw {
  display: inline-block;
  flex: 1;
  width: 18px;
  height: 20px;
  position: relative;
  color: #af6f4c;
  transform: rotate(var(--paw-angle)) scale(0);
  opacity: 0;
  transition: transform .3s cubic-bezier(.3,1.5,.5,1), opacity .2s;
}
.invitation-paw::before {
  content: '';
  position: absolute;
  width: 20%; height: 25%;
  left: 4%; top: 20%;
  background: currentColor;
  border-radius: 50%;
  box-shadow: 4px -4px currentColor, 9px -4px currentColor, 13px 1px currentColor;
}
.invitation-paw::after { content: ''; position: absolute; width: 65%; height: 50%; left: 20%; top: 50%; background: currentColor; border-radius: 60% 60% 45% 45%; }
.invitation-paw.stamped, .invitation-letter-paws .invitation-paw { opacity: .9; transform: rotate(var(--paw-angle)) scale(1); }
#partyInvitationScene.sealed #partyInvitationWriting,
#partyInvitationScene.sealed #partyInvitationPaws,
#partyInvitationScene.sealed #partyInvitationQuill { opacity: 0; }
#partyInvitationScene.sealed #partyInvitationBook { opacity: 0; transform: translate(-50%, -20%) perspective(900px) rotateX(62deg) scale(.4); }
#partyInvitationScene.accepted #partyInvitationStage { transform-origin: 60% 24%; transform: translate(-10%, 25%) scale(1.8); filter: brightness(1.12); }
#partyInvitationScene.accepted #partyInvitationArt { opacity: 0; }
#partyInvitationLetter {
  width: min(640px, 94vw);
  max-width: 94vw;
  height: fit-content;
  max-height: 92dvh;
  padding: 12px;
  border: 4px solid #dfb866;
  border-radius: 25px;
  background: #d8bfdf;
  color: #69482e;
  box-shadow: 0 0 0 2px #937859, 0 20px 80px #23203b99;
  overflow-y: auto;
}
#partyInvitationLetter::backdrop { background: #25223b99; backdrop-filter: blur(5px); }
.invitation-letter-paper {
  position: relative;
  border: 2px solid #e5c487;
  border-radius: 14px;
  padding: 24px 28px;
  background: radial-gradient(ellipse at top, #fffef7, #fff1d9);
  box-shadow: inset 0 0 0 5px #fff9eb, inset 0 0 0 6px #eed9ac;
  text-align: left;
  font-family: 'Kaiti SC', 'KaiTi', 'STKaiti', serif;
}
#partyInvitationLetter h2 { margin: 0 0 22px; text-align: center; color: #956027; font-size: clamp(20px, 3.6vw, 28px); }
#partyInvitationLetter p { color: #77543b; font-size: 18px; line-height: 1.8; margin: 12px 0; }
#partyInvitationLetter .invitation-letter-welcome { color: #9a5730; font-weight: bold; text-align: center; }
#partyInvitationLetter .invitation-letter-signature { text-align: right; }
.invitation-letter-paws { display: flex; justify-content: flex-end; gap: 12px; padding: 2px 5px 12px; }
.invitation-letter-paws .invitation-paw { flex: none; }
#acceptPartyInvitation {
  display: block;
  margin: 14px auto 0;
  padding: 12px 22px;
  background: linear-gradient(#a078b6, #78528c);
  color: #fff7df;
  border: 2px solid #d6b8e1;
  box-shadow: inset 0 0 0 1px #c5a1d2, 0 3px #583569;
  border-radius: 12px;
  font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;
}
@media (max-width: 600px) {
  body.party-level #level.game.party-invitation-round {
    --practice-height: max(320px, calc(100dvh - 100px - 100vw * 9 / 16));
  }
  .invitation-letter-paper { padding: 18px 16px; }
  #partyInvitationLetter p { font-size: 15px; line-height: 1.7; margin: 9px 0; }
  #partyInvitationLetter h2 { margin-bottom: 16px; }
  #acceptPartyInvitation { font-size: 15px; padding: 11px 12px; }
}
@media (max-width: 600px) and (max-height: 600px) {
  body.party-level #level.game.party-invitation-round { --practice-height: 230px; }
}
@media (max-width: 600px) and (max-height: 380px) {
  body.party-level #level.game.party-invitation-round { --practice-height: 185px; }
}
@media (max-height: 500px) {
  .invitation-letter-paper { padding: 16px; }
  #partyInvitationLetter p { font-size: 15px; line-height: 1.6; }
}

.invitation-delivery-envelope {
  position: fixed; z-index: 110; pointer-events: none;
  transform: translate(-50%, -50%); opacity: 0;
  filter: drop-shadow(0 14px 24px #25203d66);
}
.invitation-delivery-envelope.opened { animation: invitation-envelope-open .65s ease forwards; }
#partyInvitationLetter[open] { animation: invitation-letter-unfold .7s cubic-bezier(.2,.7,.2,1) both; }
@keyframes invitation-envelope-open { to { opacity: 0; transform: translate(-50%, -35%) scale(.9); } }
@keyframes invitation-letter-unfold {
  from { opacity: 0; transform: perspective(1000px) rotateX(-35deg) scale(.45); }
  to { opacity: 1; transform: perspective(1000px) rotateX(0) scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  #partyInvitationLetter[open], .invitation-delivery-envelope.opened { animation-duration: .01ms; }
}
/* Illustrated stationery shares the envelope's paper, goldwork and satin. */
#partyInvitationLetter {
  width: min(620px, 94vw); padding: 0; border: 0; border-radius: 18px;
  background: transparent; box-shadow: 0 16px 65px #20112c88;
  max-height: 94dvh;
}
#partyInvitationLetter .invitation-letter-paper {
  border-style: solid; border-width: 130px 44px 80px;
  border-image: url('assets/party-invitation-letter-paper.png') 250 95 220 95 fill / 130px 44px 80px stretch;
  border-radius: 0; padding: 2px 12px 8px;
  background: #fff2d1; box-shadow: none;
}
.invitation-letter-kicker {
  color: #8a5b96; font-family: 'PingFang SC', sans-serif;
  font-size: 12px; letter-spacing: .18em; text-align: center; margin-bottom: 10px;
}
#partyInvitationLetter h2 { font-size: 27px; letter-spacing: .06em; margin: 0 0 22px; color: #8b561b; }
#partyInvitationLetter p { font-size: 17px; line-height: 1.85; margin: 13px 0; color: #795135; }
#partyInvitationLetter .invitation-salutation { margin-bottom: 15px; color: #7e4b2d; }
#partyInvitationLetter .invitation-letter-welcome { margin: 22px 0 18px; letter-spacing: .04em; color: #906130; }
#partyInvitationLetter .invitation-letter-signature { font-size: 16px; color: #8a6595; }
#partyInvitationLetter .invitation-letter-paws { opacity: .62; padding-bottom: 12px; gap: 7px; }
#partyInvitationLetter #acceptPartyInvitation { font-size: 16px; margin-top: 14px; border-radius: 22px; padding: 12px 20px; }
@media (max-width: 600px) {
  #partyInvitationLetter .invitation-letter-paper {
    border-width: 112px 26px 60px;
    border-image-width: 112px 26px 60px;
    padding: 2px 8px 8px;
  }
  #partyInvitationLetter h2 { font-size: 21px; margin-bottom: 18px; }
  #partyInvitationLetter p { font-size: 15px; line-height: 1.8; margin: 12px 0; }
  #partyInvitationLetter .invitation-letter-signature { font-size: 15px; }
  #partyInvitationLetter #acceptPartyInvitation { font-size: 14px; padding: 11px 14px; }
}
/* Paper and fixed binding are independent artwork, including during the curl. */
.invitation-fixed-binding {
  position: absolute; inset: 0; z-index: 1;
  background: url('assets/party-invitation-upright.png') center / 100% 100% no-repeat;
  clip-path: polygon(39% 77%, 45% 76%, 50% 82%, 55% 76%, 62% 77%, 62% 88%, 59% 96%, 55% 100%, 50% 90%, 46% 100%, 40% 96%, 42% 88%, 39% 88%);
  pointer-events: none;
}
.invitation-turn-face::after { display: none; }
.invitation-turn-surface { filter: brightness(calc(1 - var(--page-shade, 0))); }
#partyInvitationLetter { border-radius: 0; box-shadow: 0 8px 28px #20112c66; }
#partyInvitationLetter .invitation-letter-paper {
  border-width: 90px 40px 55px;
  border-image: url('assets/party-invitation-thin-letter.png') 200 90 180 90 fill / 90px 40px 55px stretch;
  border-radius: 0; background: #fff6e2; padding: 2px 12px 8px;
}
@media (max-width: 600px) {
  #partyInvitationLetter .invitation-letter-paper {
    border-width: 70px 24px 45px;
    border-image-width: 70px 24px 45px;
    padding: 2px 8px 8px;
  }
}
