:root {
  color-scheme: light;
  --plum: #452734;
  --muted: #744b58;
  --berry: #8a3d52;
  --paper: #fffbf5;
  --rose-shadow: #6d394731;
  --display: "Songti SC", "Noto Serif CJK SC", "STSong", "SimSun", serif;
  --body: "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", system-ui, sans-serif;
  --art-ratio: 1.5;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}
body {
  color: var(--plum);
  font: 16px/1.5 var(--body);
  background: #bb8180;
}

button, textarea, input { font: inherit; }
button { border: 0; color: inherit; cursor: pointer; }
button:focus-visible, textarea:focus-visible, input:focus-visible {
  outline: 3px solid #b95776;
  outline-offset: 4px;
}
button:disabled { cursor: default; }

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

.scene-toolbar {
  position: absolute;
  z-index: 6;
  top: max(13px, env(safe-area-inset-top));
  right: max(13px, env(safe-area-inset-right));
  display: flex;
  align-items: center;
  gap: 7px;
}

.toolbar-button, .back-button {
  border-radius: 100px;
}

.toolbar-button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 13px;
  background: #fffaf4cc;
  border: 1px solid #b777862d;
  font-size: .88rem;
}

.toolbar-button:hover { background: #fffaf5; }
.sound-button { justify-content: center; min-width: 44px; padding-inline: 0; }

.sound-icon {
  position: relative;
  width: 19px;
  height: 18px;
  display: inline-block;
}
.sound-icon::before {
  content: "";
  position: absolute;
  background: currentColor;
  inset: 3px auto 3px 0;
  width: 11px;
  clip-path: polygon(0 33%, 35% 33%, 100% 0, 100% 100%, 35% 67%, 0 67%);
}
.sound-icon::after {
  content: "";
  position: absolute;
  inset: 3px 0 3px 10px;
  border: 1.5px solid transparent;
  border-right-color: currentColor;
  border-radius: 50%;
}
.sound-button[aria-pressed="false"] .sound-icon::after {
  inset: 8px 0 auto 1px;
  width: 18px;
  height: 1.5px;
  background: currentColor;
  border: 0;
  transform: rotate(-44deg);
  box-shadow: 0 0 0 1px #fffaf4;
}

.stage {
  position: relative;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  isolation: isolate;
  background: #bb8180;
}

.scene-host, .scene, .room-viewport, .scene-image, .scene-shade {
  position: absolute;
  inset: 0;
}
.scene { overflow: hidden; }
.scene-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: var(--picture-position, 50% 50%);
  user-select: none;
  pointer-events: none;
}
.scene-shade { pointer-events: none; }
.scene-shade--warm {
  background: radial-gradient(ellipse at 50% 55%, #52263718, #3e142e7d 85%);
}
.scene-shade--dim {
  background: radial-gradient(ellipse at 50% 52%, #4e213840, #3d1835a6);
}
.scene-shade--indigo {
  background: radial-gradient(ellipse at 50% 46%, #15113621, #140d29b0);
}

.room-viewport { touch-action: none; overflow: hidden; }
.room-viewport.can-pan { cursor: grab; }
.room-viewport.is-dragging, .room-viewport.is-dragging button { cursor: grabbing; }
.room-world {
  position: absolute;
  left: 50%;
  top: 50%;
  width: max(100%, calc(100cqh * var(--art-ratio)));
  aspect-ratio: var(--art-ratio);
  user-select: none;
  transform: translate3d(calc(-50% + var(--pan-offset, 0px)), -50%, 0);
  will-change: transform;
}
.room-viewport.is-dragging .pet-breath .scene-image,
.room-viewport.is-dragging .candle-flame::before,
.room-viewport.is-dragging .candle-flame::after { animation-play-state: paused; }

.hotspot {
  --hit-size: 46px;
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: max(var(--hit-size), var(--w, 0px));
  height: max(var(--hit-size), var(--h, 0px));
  padding: 0;
  background: transparent;
  border-radius: 22px;
  transform: translate(-50%, -50%);
  -webkit-tap-highlight-color: transparent;
}
.hotspot:focus-visible { outline: 2px solid #fff1cb; outline-offset: -2px; }
.back-button {
  position: absolute;
  z-index: 6;
  top: max(13px, env(safe-area-inset-top));
  left: max(13px, env(safe-area-inset-left));
  width: 44px;
  height: 44px;
  padding: 0;
  display: grid;
  place-items: center;
  background: #fff9f0;
  box-shadow: 0 3px 14px #26122233;
}
.back-button:hover { background: #fff; }
.back-icon {
  width: 16px;
  height: 16px;
  background: currentColor;
  clip-path: polygon(0 50%, 45% 7%, 56% 20%, 31% 43%, 100% 43%, 100% 57%, 31% 57%, 56% 80%, 45% 93%);
}
.no-script { padding: 1rem; text-align: center; }

.scene-button {
  min-height: 46px;
  border-radius: 100px;
  padding: 8px 18px;
  background: var(--paper);
  border: 1px solid #fff7e8;
  box-shadow: 0 3px 16px #3612263f;
  color: #673649;
  font-weight: 680;
}
.scene-button:hover { background: white; }
.scene-button--berry { color: #fffaf4; background: #8b4057; border-color: #a85a73; }
.scene-button--berry:hover { background: #74334a; }

.detail-art {
  position: absolute;
  inset: 0;
  overflow: hidden;
}
.detail-world {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 100%;
  min-height: 100%;
  aspect-ratio: var(--detail-ratio, 1.5);
  transform: translate(-50%, -50%);
}
.detail-world .scene-image { object-fit: fill; }
.detail-focus { position: absolute; inset: 0; pointer-events: none; }
.detail-focus .hotspot { pointer-events: auto; }

.candle-effect {
  --flame-width: clamp(8px, 1.53cqw, 24px);
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: var(--flame-width);
  height: calc(var(--flame-width) * 1.66);
  transform: translate(-50%, -100%);
  pointer-events: none;
}
.room-world .candle-effect { --flame-width: clamp(4px, .47cqw, 8px); }
.candle-flame {
  position: absolute;
  inset: 0;
  transform-origin: 50% 100%;
  transition: opacity .14s ease, transform .19s ease-out;
}
.candle-flame::before, .candle-flame::after {
  position: absolute;
  content: "";
  animation-delay: var(--phase);
}
.candle-flame::before {
  inset: -104% -175% -85%;
  border-radius: 50%;
  background: radial-gradient(ellipse, #fff1ab66 0, #ffc86a28 42%, transparent 72%);
  animation: candle-halo 1.55s ease-in-out infinite alternate;
  animation-delay: var(--phase);
}
.candle-flame::after {
  inset: 0;
  border-radius: 81% 14% 64% 54% / 77% 26% 68% 37%;
  background: radial-gradient(ellipse at 49% 78%, #fffdf2 8%, #fff0aa 30%, #ffd258 60%, #ff8b35 95%);
  box-shadow: 0 0 8px #ffe18e8a;
  transform-origin: 50% 100%;
  animation: candle-flicker .42s ease-in-out infinite alternate;
  animation-delay: var(--phase);
}
.candle-effect.is-out .candle-flame { opacity: 0; transform: rotate(37deg) scale(.3, .45); }
.wick-smoke {
  position: absolute;
  bottom: 0;
  left: 50%;
  width: 55%;
  height: 70%;
  border-radius: 45%;
  opacity: 0;
  background: radial-gradient(ellipse, #fff7e9, #f0e2df55 49%, transparent 72%);
  filter: blur(1.5px);
}
.just-blown .wick-smoke { animation: wick-smoke 1.18s ease-out var(--smoke-delay) both; }
@keyframes candle-flicker {
  from { transform: rotate(-5deg) scale(.94, 1.06); opacity: .9; }
  52% { transform: rotate(5deg) scale(1.04, .88); opacity: .84; }
  to { transform: rotate(-1deg) scale(.92, 1.014); opacity: 1; }
}
@keyframes candle-halo { to { transform: scale(.82); opacity: .68; } }
@keyframes wick-smoke {
  0% { opacity: 0; transform: translate(-50%, 15%) scale(.35); }
  17% { opacity: .68; }
  48% { opacity: .38; transform: translate(90%, -144%) rotate(25deg) scale(1.45); }
  100% { opacity: 0; transform: translate(215%, -290%) rotate(49deg) scale(2.23); }
}
.candle-swipe {
  position: absolute;
  width: var(--band-width);
  height: max(54px, 17%);
  left: var(--x);
  top: var(--y);
  transform: translate(-50%, -52%);
  touch-action: none;
}
.candle-control {
  position: absolute;
  left: 50%;
  bottom: max(20px, calc(env(safe-area-inset-bottom) + 11px));
  transform: translateX(-50%);
  min-height: 43px;
  border-radius: 28px;
  padding: 7px 17px;
  background: #fff8eeed;
  color: #6b4050;
  box-shadow: 0 4px 16px #40212c45;
  font-size: .88rem;
  font-weight: 680;
}

.clock-hands {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: var(--clock-width);
  height: var(--clock-height);
  transform: translate(-50%, -50%);
  pointer-events: none;
}
.clock-hour, .clock-minute {
  position: absolute;
  bottom: 50%;
  left: 50%;
  border-radius: 60% 60% 24% 24%;
  background: #614333;
  transform-origin: center bottom;
}
.clock-hour { width: 5.5%; height: 28%; transform: translateX(-50%) rotate(160deg); }
.clock-minute { width: 3.8%; height: 40%; transform: translateX(-50%) rotate(120deg); }
.clock-pin {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 7%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #7f4f32;
  transform: translate(-50%, -50%);
}

.shelf-book {
  position: absolute;
  perspective: 480px;
  z-index: 3;
}
.shelf-pick {
  position: absolute;
  inset: -1px -5px;
  z-index: 2;
  padding: 0;
  background: transparent;
  border-radius: 4px;
  -webkit-tap-highlight-color: transparent;
}
.shelf-pick:focus-visible { outline: 2px solid #ffe9b8; outline-offset: 2px; }
.shelf-spine {
  z-index: 1;
  visibility: hidden;
  transform-origin: 50% 100%;
  pointer-events: none;
}
.book-recess {
  position: absolute;
  inset: 2% 1% 1%;
  visibility: hidden;
  border-radius: 8% 3% 3% 4%;
  background: linear-gradient(90deg, #4a221b, #6d362d 68%, #49231c);
  box-shadow: inset 3px 0 5px #301515a1;
}
.pulling-book .book-recess, .pulling-book .shelf-spine { visibility: visible; }

.book-layout {
  position: absolute;
  inset: max(60px, calc(env(safe-area-inset-top) + 43px)) 14px max(14px, env(safe-area-inset-bottom));
  display: grid;
  place-items: center;
}
.story-book {
  position: relative;
  width: min(90vw, 402px, calc((100cqh - 81px) * .755));
  aspect-ratio: .755;
  perspective: 850px;
}
.story-cover, .story-paper {
  position: absolute;
  inset: 0;
  width: 100%;
  display: grid;
  place-items: center;
  border-radius: 4px 13px 13px 4px;
  box-shadow: 5px 8px 0 #f3ddc2, 8px 11px 0 #8e594f, 12px 21px 54px #3b172789;
}
.story-cover {
  color: #ffe5b4;
  overflow: hidden;
  padding: 12%;
  background:
    radial-gradient(ellipse at 45% 30%, #ba7b6d44, transparent 64%),
    linear-gradient(113deg, #924f44, #7b3d3c 72%, #66363b);
  border: 1px solid #d39b7f;
}
.story-cover::after {
  position: absolute;
  content: "";
  inset: 8% 8% 8% 12%;
  border: 1px solid #e7b687a4;
  border-radius: 3px 8px 8px 3px;
  pointer-events: none;
}
.story-spine { left: 0; right: auto; width: 9%; object-fit: fill; opacity: .92; }
.story-cover-title {
  z-index: 1;
  font: 700 clamp(1.05rem, 4.9vw, 2.18rem)/1.65 var(--display);
  letter-spacing: .09em;
  text-align: center;
  text-shadow: 0 2px 2px #4a201ee0;
}
.story-paper {
  color: #784750;
  transform-origin: left center;
  border: 1px solid #cfb39a;
  background:
    linear-gradient(90deg, #dcbb9a90, #fff6e7 11%, #fffaf0 46%, #fbf0df 96%, #ecd7be);
}
.story-paper::after {
  position: absolute;
  content: "";
  inset: 5%;
  border: 1px solid #d6b99c82;
  pointer-events: none;
}
.story-page-center {
  position: absolute;
  inset: 7% 6% 15%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(4px, 1.2vh, 12px);
  text-align: center;
}
.story-qr {
  display: block;
  width: auto;
  max-width: 86%;
  height: auto;
  max-height: 73%;
  object-fit: contain;
  border-radius: 5px;
}
.story-pay-caption {
  margin: 0;
  font-size: clamp(.88rem, 3.3vw, 1.16rem);
  letter-spacing: .03em;
}
.story-joke-hint { color: #986d70; font-size: clamp(.64rem, 2.6vw, .82rem); }
.story-pagination {
  position: absolute;
  inset: auto 8% 4.7%;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.story-page-turn {
  min-height: 38px;
  min-width: 38px;
  padding: 3px 8px;
  background: transparent;
  color: #a16467;
  font-size: 1.22rem;
}
.story-next { font-size: .87rem; font-weight: 720; }
.story-final-line {
  margin: 0;
  color: #a65667;
  white-space: nowrap;
  font: 760 clamp(.93rem, min(7.35vw, 6cqh), 2.7rem)/1.2 var(--display);
  letter-spacing: .115em;
  transform: rotate(-3deg);
  text-shadow: 0 2px #fff9e9;
}

.pet-bubble {
  position: absolute;
  z-index: 3;
  left: var(--x);
  top: var(--y);
  transform: translate(-50%, -120%);
  padding: 8px 13px;
  border-radius: 18px 18px 18px 4px;
  font-size: .875rem;
  font-weight: 700;
  color: #613b47;
  background: #fff9e9;
  box-shadow: 0 4px 18px #562c4b38;
  animation: appear .32s ease both;
  pointer-events: none;
  white-space: nowrap;
}
.pet-breath {
  position: absolute;
  overflow: hidden;
  pointer-events: none;
  --fur-mask: radial-gradient(ellipse closest-side, #000 38%, #000c 60%, transparent 100%);
  -webkit-mask-image: var(--fur-mask);
  mask-image: var(--fur-mask);
}
.pet-breath .scene-image {
  transform-origin: center bottom;
  animation: breathing 3.6s ease-in-out infinite;
}
.pet-breath.is-purring .scene-image { animation-duration: 1.14s; }
@keyframes breathing { 46% { transform: scale(1.013, 1.075); } }
@keyframes appear { from { opacity: 0; } to { opacity: 1; } }

.paper-layout, .game-layout, .editor-layout {
  position: absolute;
  inset: 63px 17px 16px;
  display: grid;
  place-items: center;
}

.letter-stack {
  position: relative;
  width: min(590px, 91%);
  min-height: 0;
  height: min(420px, 86%);
  animation: stationery-in .6s cubic-bezier(.2,.8,.27,1) both;
}
@keyframes stationery-in {
  from { transform: translateY(24px) scale(.94); opacity: .1; }
  to { transform: none; opacity: 1; }
}

.envelope-back {
  position: absolute;
  inset: 28% -4% 1% -4%;
  transform: rotate(-7deg);
  border-radius: 11px;
  background:
    linear-gradient(143deg, transparent 49.5%, #a05d6f74 50%, transparent 50.5%),
    linear-gradient(217deg, transparent 49.5%, #a05d6f74 50%, transparent 50.5%),
    #d98498;
  border: 1px solid #b16377;
  box-shadow: 0 19px 50px #3c1c34a3;
}
.letter-paper {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: auto;
  overscroll-behavior: contain;
  color: #4f293c;
  padding: 45px clamp(22px, 7vw, 62px);
  border: 1px solid #ebc5b9;
  border-radius: 8px;
  box-shadow: 0 12px 28px #3c1c3433;
  background:
    linear-gradient(to right, transparent 8%, #e8bdb36b 8.2%, transparent 8.5%),
    repeating-linear-gradient(to bottom, transparent 0 33px, #b67b7729 33px 34px),
    #fff9ea;
  background-position: 0 0, 0 12px;
}
.letter-copy {
  margin: 0;
  font: 1.09rem/34px var(--display);
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}
.letter-paper::after {
  content: "✧";
  position: absolute;
  top: 12px;
  right: 19px;
  color: #a96374;
  font-size: 22px;
  line-height: 1;
  pointer-events: none;
}

.greeting-card {
  width: min(630px, 95%);
  max-height: 94%;
  min-height: min(290px, 70%);
  display: grid;
  grid-template-columns: .78fr 1.22fr;
  overflow: auto;
  border-radius: 12px;
  background: #fff7e9;
  box-shadow: 0 21px 70px #41172c94;
  animation: stationery-in .55s cubic-bezier(.2,.8,.27,1) both;
}
.card-decoration {
  min-height: 200px;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 30% 23%, #fff2d5 0 1px, transparent 2px),
    radial-gradient(circle at 70% 76%, #fff2d5 0 1px, transparent 2px),
    radial-gradient(circle at 83% 19%, #fff2d5 0 1px, transparent 2px),
    linear-gradient(144deg, #e2a4ad, #ac5a76 81%);
  border-right: 1px solid #86405454;
}
.card-seal {
  display: grid;
  place-items: center;
  width: 58%;
  aspect-ratio: 1;
  border: 1px solid #fff2d5aa;
  border-radius: 50%;
  color: #fff2d5;
  font: 700 clamp(2.2rem, 6vw, 4.6rem)/1 Georgia, serif;
  box-shadow: inset 0 0 0 6px #fff2d520, 0 0 0 4px #fff2d51f;
}
.card-text { align-self: center; padding: clamp(18px, 4vw, 42px); overflow-wrap: anywhere; }
.card-text h2 { margin: 0 0 16px; font: 700 clamp(1.5rem, 3.3vw, 2.65rem)/1.25 var(--display); }
.card-text p { margin: 0; font-size: 1rem; line-height: 1.8; white-space: pre-wrap; }
.card-text .card-from { margin-top: 18px; text-align: end; color: var(--berry); font-size: .875rem; }

.editor-panel {
  width: min(608px, 100%);
  max-height: 100%;
  padding: 20px clamp(16px, 5vw, 34px);
  overflow: auto;
  overscroll-behavior: contain;
  border-radius: 14px;
  background: #fffaf2;
  box-shadow: 0 14px 45px #37172d80;
}
.editor-panel h2 { margin: 0; font: 700 1.45rem/1.25 var(--display); }
.editor-panel > p { font-size: .875rem; margin-block: 8px 13px; color: var(--muted); }
.editor-panel label { display: block; margin-block: 11px 4px; font-weight: 660; }
.editor-panel input, .editor-panel textarea {
  display: block;
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--plum);
  border: 1px solid #b8788959;
  background: #fffdf8;
}
.editor-panel textarea { resize: vertical; min-height: 68px; }
.editor-buttons { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 15px; }
.editor-buttons .scene-button { box-shadow: none; }
.editor-buttons .scene-button:not(.scene-button--berry) { border-color: #b8788959; }
.editor-status { min-height: 1.4em; }

.carousel-box {
  position: absolute;
  inset: 0;
  width: 100%;
  display: block;
  background: transparent;
  padding: 0;
  perspective: 850px;
}
.carousel-box:focus-visible { outline-offset: -5px; }

.ballerina {
  position: absolute;
  inset: 39.4% 31% 35%;
  transform: rotateY(0);
  transform-origin: 50% 90%;
  animation: spin 4.2s linear infinite paused;
}
.carousel-box.is-playing .ballerina { animation-play-state: running; }
.ballerina i { position: absolute; display: block; }
.doll-leg {
  bottom: 0;
  left: 50%;
  width: 8%;
  height: 38%;
  border-radius: 80% 25% 60% 40%;
  background: linear-gradient(90deg, #fff3dc, #e7bd93);
}
.doll-leg--lifted { transform: rotate(-34deg); transform-origin: 55% 12%; height: 32%; }
.doll-body {
  top: 30%;
  bottom: 40%;
  left: 38%;
  right: 36%;
  background: linear-gradient(100deg, #fff8e7, #d5a57d);
  border-radius: 60% 60% 30% 30%;
}
.doll-tutu {
  bottom: 31%;
  left: 8%;
  right: 9%;
  height: 31%;
  background: repeating-conic-gradient(from 56deg at 50% 5%, #f3d7b7, #fff5e3 14deg, #e2bd99 22deg, #f4ddc0 27deg);
  clip-path: polygon(38% 0, 63% 0, 100% 83%, 88% 92%, 75% 88%, 62% 99%, 50% 91%, 31% 99%, 23% 91%, 9% 94%, 0 83%);
}
.doll-arm {
  top: 24%;
  left: 5%;
  width: 39%;
  height: 8%;
  border-radius: 60px;
  transform: rotate(28deg);
  background: linear-gradient(#fff4e0, #dcb28e);
}
.doll-arm--raised { left: 57%; transform: rotate(-46deg); }
.doll-face {
  top: 7%;
  left: 33%;
  right: 31%;
  height: 28%;
  border-radius: 50%;
  background: radial-gradient(circle at 63% 59%, #724d58 0 3%, transparent 4%), radial-gradient(circle at 36% 59%, #724d58 0 3%, transparent 4%), #ffeacb;
  box-shadow: inset 0 6px #b38a62, -2px -3px #bc936d;
}
.doll-bun {
  top: 0;
  left: 37%;
  width: 23%;
  height: 15%;
  border-radius: 50%;
  background: #bd956c;
}
@keyframes spin { to { transform: rotateY(360deg); } }

.sky-scene {
  background:
    radial-gradient(ellipse at 59% 83%, #56245a96, transparent 57%),
    radial-gradient(ellipse at 11% 28%, #2a326f6e, transparent 68%),
    linear-gradient(#10132f, #1e1a47 67%, #371e49);
}
.starfield { position: absolute; inset: 0; width: 100%; height: 100%; }
.sky-trigger { position: absolute; inset: 0; background: transparent; }
.sky-trigger:focus-visible { outline: 2px solid #f7ddaa; outline-offset: -4px; border-radius: 22px; }
.sky-caption {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 9%;
  margin: 0;
  color: #fff3dc;
  text-align: center;
  text-shadow: 0 0 22px #aa82dd;
  font: 650 clamp(1.05rem, 2.6vw, 1.75rem)/1.3 var(--display);
  letter-spacing: .18em;
  pointer-events: none;
  animation: appear .65s ease both;
}

.scene { container-type: size; }
.detail-backdrop {
  filter: blur(20px) brightness(.62);
  transform: scale(1.12);
}
.detail-world {
  min-height: 0;
  width: min(100cqw, calc(100cqh * var(--detail-ratio, 1.5)));
  box-shadow: 0 0 40px 12px #37182275;
}
.detail-art--zoom .detail-world {
  width: min(113cqw, calc(100cqh * var(--detail-ratio, 1.5)));
}
.detail-art--portrait .detail-world {
  width: min(117cqw, max(100cqw, calc(100cqh * var(--detail-ratio))));
  height: auto;
}
.art-spark {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: 8px;
  aspect-ratio: 1;
  background: #ffedc4;
  clip-path: polygon(50% 0, 62% 37%, 100% 50%, 62% 63%, 50% 100%, 38% 63%, 0 50%, 38% 37%);
  animation: glimmer 2.9s ease-in-out infinite alternate;
  animation-delay: var(--delay, 0s);
  pointer-events: none;
}
@keyframes glimmer { from { opacity: .12; scale: .55; } to { opacity: .95; scale: 1.1; } }

.figure-layout {
  position: absolute;
  inset: 63px 8px 17px;
  display: grid;
  place-items: center;
}
.figure-image {
  display: block;
  width: auto;
  height: min(82%, 420px);
  max-width: min(76%, 335px);
  object-fit: contain;
  border: 5px solid #fff6e9;
  border-radius: 17px;
  box-shadow: 0 18px 44px #342030a6;
  animation: stationery-in .42s ease both;
}

.ticket-lobby .scene-image { object-position: 50% 64%; }

.ticket-row {
  position: absolute;
  left: 50%;
  top: 59%;
  width: min(690px, 91%, calc(100cqh * 1.54));
  transform: translate(-50%, -50%);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: clamp(8px, 2.4vw, 23px);
  perspective: 980px;
  align-items: start;
}

.ticket, .scratch-ticket {
  --ticket-light: #f9dede;
  --ticket-dark: #bf6478;
  --ticket-ink: #633347;
  --foil: #dbb5bf;
  border-radius: 14px;
  color: var(--ticket-ink);
  background:
    radial-gradient(circle at 15% 16%, #fff0daaa 0 1px, transparent 2px),
    radial-gradient(circle at 81% 23%, #fff0daaa 0 1px, transparent 2px),
    radial-gradient(circle at 88% 77%, #fff0daaa 0 1px, transparent 2px),
    linear-gradient(154deg, var(--ticket-light), var(--ticket-dark));
  border: 1px solid #fff4e6cb;
}
.ticket[data-color="jade"], .scratch-ticket[data-color="jade"] {
  --ticket-light: #edf3dc;
  --ticket-dark: #98bba3;
  --ticket-ink: #31574a;
  --foil: #abbfb1;
}
.ticket[data-color="lilac"], .scratch-ticket[data-color="lilac"] {
  --ticket-light: #f0e2ff;
  --ticket-dark: #aa91ca;
  --ticket-ink: #543d71;
  --foil: #bfb2cc;
}

.ticket {
  position: relative;
  min-width: 0;
  min-height: 98px;
  aspect-ratio: .79;
  padding: 10% 8%;
  box-shadow: 0 23px 23px #1f12256e, 0 6px 9px #351e375a;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: 5px;
  animation: drift 2.9s ease-in-out infinite alternate both;
  animation-delay: var(--ticket-delay, 0s);
}
.ticket:not(.is-done):hover { filter: brightness(1.1); }
.ticket::before, .scratch-ticket::before {
  content: "";
  position: absolute;
  inset: 5px;
  border: 1px solid #fff5e6d0;
  border-radius: 10px;
  pointer-events: none;
}
.ticket.is-done {
  animation: none;
  transform: translateY(clamp(26px, 6.4vh, 68px)) rotateX(35deg) rotate(var(--lean, 0deg)) scale(.91);
  box-shadow: 0 3px 6px #2a142897;
}
@keyframes drift {
  from { transform: translateY(-7px) rotate(var(--lean, 0deg)); }
  to { transform: translateY(6px) rotate(calc(var(--lean, 0deg) + 2deg)); }
}
.ticket-icon {
  color: #ffe396;
  text-shadow: 0 2px #9f683f, 0 3px 12px #5b2d4166;
  font: 750 clamp(2rem, 5.2vw, 4.3rem)/1 var(--body);
}
.ticket-foil {
  flex: 0 1 auto;
  width: 100%;
  min-height: 31px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  border: 1px solid #fff5e8c0;
  background:
    repeating-linear-gradient(117deg, #fff1e621 0 3px, #4e2a4930 4px, transparent 5px 7px),
    var(--foil);
  font: 700 .875rem/1.2 var(--body);
}
.is-done .ticket-foil {
  background:
    repeating-linear-gradient(113deg, transparent 0 9px, #8a6e87a0 10px, transparent 13px 19px),
    #fff2db;
  border-style: dashed;
}

.scratch-ticket {
  position: relative;
  width: min(420px, 96%, calc((100cqh - 53px) * .87));
  padding: clamp(9px, 2.5vw, 18px);
  border-radius: 17px;
  box-shadow: 0 24px 70px #200f2b9e;
  animation: stationery-in .35s ease both;
}
.scratch-emblem {
  display: block;
  margin: 0 auto 4px;
  color: #ffe396;
  font: 800 clamp(2rem, min(10vw, 11cqh), 4.15rem)/1 var(--body);
  text-align: center;
  text-shadow: 0 2px #965a47, 0 4px 14px #48344844;
}
.scratch-rule {
  margin: 0 0 9px;
  font-size: clamp(.65rem, 2.25vw, .86rem);
  font-weight: 690;
  text-align: center;
}
.scratch-zone.ticket-zone { --mask-ratio: 1.25; }
.scratch-cells {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  grid-template-rows: repeat(4, minmax(0, 1fr));
  background: #e5cfdd;
  gap: 1px;
  pointer-events: none;
}
.scratch-cell {
  display: grid;
  place-content: center;
  justify-items: center;
  grid-auto-rows: min-content;
  min-width: 0;
  color: #5e4156;
  background: radial-gradient(ellipse at 26% 18%, #fff9f0, #f4d9db);
  font-family: var(--body);
  line-height: 1.12;
}
.scratch-cell.is-star {
  background: radial-gradient(ellipse at 26% 18%, #fffadf, #f2daa4);
  color: #946120;
}
.slot-symbol { font-size: clamp(1rem, min(5.4vw, 5.1cqh), 1.9rem); }
.is-star .slot-symbol { color: #bf8625; }
.slot-amount { font-size: clamp(.58rem, 2.2vw, .86rem); font-weight: 750; }
.cash-note {
  display: block;
  margin: 5px 2px 0 0;
  color: #6c4758;
  font-size: .64rem;
  text-align: right;
}

.scratch-zone {
  position: relative;
  aspect-ratio: var(--mask-ratio, 2.4);
  width: 100%;
  isolation: isolate;
  overflow: hidden;
  border-radius: 12px;
  background: #fff5df;
  box-shadow: 0 0 0 1px #5a344145, inset 0 1px 4px #44213027;
}
.scratch-zone canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
  transition: opacity .38s ease;
}
.scratch-assist {
  position: absolute;
  inset: 0;
  padding: 0;
  background: transparent;
  pointer-events: none;
}
.scratch-assist:focus-visible { outline-offset: -4px; }
.litter-message {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  pointer-events: none;
}

.litter-tray {
  position: relative;
  width: min(630px, 98%, calc((100cqh - 120px) * 1.8));
  min-width: min(100%, 245px);
  padding: clamp(14px, 4.3vw, 42px);
  border-radius: 25px;
  background: linear-gradient(156deg, #b8d5b8 0, #6e9784 38%, #4d7766 82%, #6a9987 99%);
  border: 2px solid #d3e1bb;
  box-shadow: 0 13px 0 #456451, 0 25px 0 #334e44, 0 37px 47px #331b3078, inset 0 3px 6px #f9edca9a;
  animation: stationery-in .39s ease both;
}
.litter-tray .scratch-zone {
  background: linear-gradient(127deg, #f3edd2, #e3d5b8);
  border-radius: 15px;
  border: 2px solid #497058;
  box-shadow: 0 0 0 4px #c7dec76b, inset 0 0 15px #624b3b3f;
}
.litter-message {
  color: #96604e;
  font: 750 clamp(1.45rem, 5.5vw, 3.2rem)/1.15 var(--display);
  letter-spacing: .13em;
  transform: rotate(-3deg);
  text-shadow: 0 1px #fff7d5;
}
.litter-surprise {
  position: absolute;
  left: 10%;
  bottom: 13%;
  transform: rotate(-10deg);
  font-size: clamp(.85rem, 3.15vw, 1.31rem);
  line-height: 1;
  pointer-events: none;
}
@media (max-width: 760px), (max-aspect-ratio: 8/9) {
  .greeting-card { width: 99%; grid-template-columns: .64fr 1.36fr; }
  .card-seal { width: 74%; }
  .ticket-row { gap: 8px; }
  .ticket { border-radius: 11px; padding: 11px 8px; }
  .ticket::before { inset: 4px; border-radius: 7px; }
}

@media (max-height: 500px) and (orientation: landscape) {
  .paper-layout, .game-layout, .editor-layout { inset-block: 50px 9px; }
  .card-decoration { min-height: 0; }
  .litter-tray { padding: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
  .carousel-box.is-playing .ballerina { animation: none !important; }
}
