:root {
  --night: #101a2b;
  --night-soft: #17253a;
  --moon: #f7e8bd;
  --moon-bright: #fff4d5;
  --lantern: #d97a38;
  --osmanthus: #e8b95a;
  --leaf: #263c33;
  --paper: #f5e9cc;
  --serif: "Songti SC", "STSong", "Noto Serif CJK SC", serif;
  --kai: "Kaiti SC", "STKaiti", "KaiTi", serif;
  --safe-top: max(16px, env(safe-area-inset-top));
  --safe-bottom: max(20px, env(safe-area-inset-bottom));
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--night);
  color: var(--moon);
}

body {
  font-family: var(--kai);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior: none;
}

button,
a { font: inherit; }

button {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.app {
  position: relative;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  min-height: 560px;
  isolation: isolate;
  overflow: hidden;
  background:
    radial-gradient(circle at 73% 18%, rgba(247, 232, 189, .08), transparent 30%),
    linear-gradient(155deg, #16243a 0%, var(--night) 48%, #09111e 100%);
}

.scene,
.scene-shade,
.grain,
.light-wash,
.petals,
.spark-field {
  position: absolute;
  inset: 0;
}

.scene {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center center;
  user-select: none;
  -webkit-user-drag: none;
  transition: opacity 1.55s ease, filter 1.8s ease, transform 7s ease;
}

.scene-empty { z-index: -7; }

.scene-together {
  z-index: -6;
  opacity: 0;
  filter: brightness(.9) saturate(.92);
  transform: scale(1.015);
}

.app[data-stage="together"] .scene-together,
.app[data-stage="splitting"] .scene-together,
.app[data-stage="ending"] .scene-together {
  opacity: 1;
  filter: brightness(1.02) saturate(1.04);
  transform: scale(1);
}

.image-missing .scene { display: none; }

.scene-shade {
  z-index: -5;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(3, 8, 17, .48) 0%, rgba(7, 13, 24, .06) 34%, transparent 59%, rgba(3, 7, 14, .34) 100%),
    linear-gradient(90deg, rgba(6, 12, 22, .2), transparent 35%, rgba(6, 12, 22, .08));
  transition: opacity 1.5s ease;
}

.app[data-stage="ending"] .scene-shade { opacity: .82; }

.grain {
  z-index: 18;
  pointer-events: none;
  opacity: .1;
  mix-blend-mode: soft-light;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='90' height='90' viewBox='0 0 90 90'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.78' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.6'/%3E%3C/svg%3E");
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.moon-wrap {
  position: absolute;
  z-index: 1;
  top: clamp(72px, 10.5vh, 112px);
  right: clamp(28px, 8vw, 72px);
  width: clamp(118px, 35vw, 172px);
  aspect-ratio: 1;
  pointer-events: none;
  transform: translate(18vw, 31vh) scale(.54);
  opacity: .34;
  transition: transform 2.6s cubic-bezier(.19, .75, .2, 1), opacity 2.2s ease;
}

.moon {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  overflow: hidden;
  background:
    radial-gradient(circle at 38% 32%, rgba(255, 255, 255, .8) 0 3%, transparent 4%),
    radial-gradient(circle at 66% 61%, rgba(166, 139, 96, .13) 0 9%, transparent 10%),
    radial-gradient(circle at 33% 68%, rgba(150, 124, 84, .11) 0 13%, transparent 14%),
    radial-gradient(circle at 58% 36%, var(--moon-bright), var(--moon) 68%, #d9ba7f 100%);
  box-shadow: 0 0 0 1px rgba(255, 245, 214, .35), 0 0 46px 12px rgba(247, 232, 189, .16);
}

.moon::after {
  content: "";
  position: absolute;
  inset: -3%;
  border-radius: inherit;
  background: rgba(9, 17, 30, .77);
  transform: translateX(22%);
  box-shadow: -12px 0 24px rgba(10, 18, 31, .24);
  transition: transform 2.45s .2s cubic-bezier(.19, .75, .2, 1), opacity 1.8s .42s ease;
}

.moon-halo {
  position: absolute;
  inset: -42%;
  z-index: -1;
  border-radius: 50%;
  opacity: .12;
  background: radial-gradient(circle, rgba(255, 240, 197, .5), rgba(244, 223, 172, .09) 48%, transparent 70%);
  transform: scale(.72);
  transition: opacity 2.4s .4s ease, transform 2.6s .2s ease;
}

.app:not([data-stage="intro"]) .moon-wrap {
  transform: translate(0, 0) scale(1);
  opacity: 1;
}

.app:not([data-stage="intro"]) .moon::after {
  transform: translateX(112%);
  opacity: 0;
}

.app:not([data-stage="intro"]) .moon-halo {
  opacity: .72;
  transform: scale(1);
}

.light-wash {
  z-index: 0;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(ellipse at 72% 16%, rgba(255, 238, 190, .22), transparent 46%);
  transition: opacity 2.4s .45s ease;
}

.app:not([data-stage="intro"]) .light-wash { opacity: 1; }

.lamp-glow {
  position: absolute;
  z-index: 1;
  width: 118px;
  height: 150px;
  border-radius: 50%;
  pointer-events: none;
  opacity: 0;
  transform: scale(.72);
  background: radial-gradient(ellipse, rgba(229, 134, 66, .56), rgba(217, 122, 56, .21) 34%, transparent 72%);
  mix-blend-mode: screen;
  transition: opacity 1.1s ease, transform 1.35s cubic-bezier(.2, .8, .2, 1);
}

.lamp-left { top: 31.5%; left: 7%; transition-delay: .8s; }
.lamp-right { top: 42%; right: -2%; transition-delay: 1.25s; }

.app:not([data-stage="intro"]) .lamp-glow {
  opacity: .83;
  transform: scale(1);
}

.petals,
.spark-field {
  z-index: 5;
  overflow: hidden;
  pointer-events: none;
}

.petal {
  position: absolute;
  top: -20px;
  width: 5px;
  height: 8px;
  border-radius: 70% 15% 65% 20%;
  opacity: 0;
  background: var(--osmanthus);
  box-shadow: 0 0 4px rgba(232, 185, 90, .25);
  animation: petal-fall var(--fall, 9s) linear var(--delay, 0s) infinite;
}

.app[data-stage="intro"] .petal { animation-play-state: paused; }

@keyframes petal-fall {
  0% { opacity: 0; transform: translate3d(0, -3vh, 0) rotate(0deg); }
  12% { opacity: .75; }
  82% { opacity: .58; }
  100% { opacity: 0; transform: translate3d(var(--drift, 34px), 108vh, 0) rotate(310deg); }
}

.spark {
  position: absolute;
  left: 50%;
  top: 72%;
  width: var(--size, 5px);
  height: var(--size, 5px);
  border-radius: 50%;
  background: var(--moon-bright);
  box-shadow: 0 0 10px 3px rgba(232, 185, 90, .45);
  animation: spark-bloom 1.25s cubic-bezier(.12, .72, .18, 1) forwards;
}

@keyframes spark-bloom {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.2); }
  16% { opacity: 1; }
  100% { opacity: 0; transform: translate(calc(-50% + var(--x)), calc(-50% + var(--y))) scale(.08); }
}

.sound-toggle {
  position: absolute;
  z-index: 20;
  top: var(--safe-top);
  right: max(14px, env(safe-area-inset-right));
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid rgba(247, 232, 189, .42);
  border-radius: 50%;
  color: var(--moon);
  background: rgba(8, 15, 27, .46);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
  backdrop-filter: blur(8px);
  cursor: pointer;
  transition: background .25s ease, border-color .25s ease, transform .25s ease;
}

.sound-toggle:active { transform: scale(.94); }
.sound-toggle:hover { border-color: rgba(247, 232, 189, .72); }

.sound-toggle svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sound-toggle .icon-on { display: none; }
.sound-toggle.is-on .icon-on { display: block; }
.sound-toggle.is-on .icon-off { display: none; }

.opening-copy {
  position: absolute;
  z-index: 4;
  top: clamp(126px, 18.2vh, 184px);
  left: max(26px, 8vw);
  width: min(61vw, 255px);
  text-align: left;
  text-shadow: 0 2px 22px rgba(0, 0, 0, .72);
  transition: opacity .8s ease, transform .9s ease;
}

.opening-kicker {
  display: block;
  margin-bottom: 10px;
  color: rgba(247, 232, 189, .7);
  font-family: var(--serif);
  font-size: 12px;
  letter-spacing: .34em;
}

.opening-copy h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(27px, 7.4vw, 38px);
  font-weight: 500;
  line-height: 1.48;
  letter-spacing: .06em;
}

.opening-copy h1 span { white-space: nowrap; }

.app:not([data-stage="intro"]) .opening-copy {
  opacity: 0;
  transform: translateY(-14px);
  pointer-events: none;
}

.start-zone {
  position: absolute;
  z-index: 7;
  left: max(24px, 8vw);
  bottom: calc(var(--safe-bottom) + 24px);
  display: flex;
  align-items: center;
  gap: 13px;
  transition: opacity .6s ease, transform .7s ease;
}

.start-button {
  min-height: 48px;
  padding: 11px 22px 10px;
  border: 1px solid rgba(247, 232, 189, .7);
  border-radius: 999px;
  color: #211b12;
  background: rgba(247, 232, 189, .91);
  box-shadow: 0 12px 30px rgba(0, 0, 0, .25), inset 0 1px rgba(255, 255, 255, .55);
  font-family: var(--serif);
  font-size: 15px;
  letter-spacing: .12em;
  cursor: pointer;
}

.swipe-hint {
  display: flex;
  align-items: center;
  gap: 5px;
  color: rgba(247, 232, 189, .72);
  font-size: 12px;
  letter-spacing: .12em;
}

.swipe-hint svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  animation: hint-rise 1.8s ease-in-out infinite;
}

@keyframes hint-rise {
  0%, 100% { transform: translateY(3px); opacity: .55; }
  50% { transform: translateY(-3px); opacity: 1; }
}

.app:not([data-stage="intro"]) .start-zone {
  opacity: 0;
  transform: translateY(18px);
  pointer-events: none;
}

.moon-caption {
  position: absolute;
  z-index: 6;
  top: clamp(222px, 29vh, 282px);
  right: max(26px, 8vw);
  width: min(48vw, 205px);
  margin: 0;
  text-align: right;
  color: rgba(255, 244, 213, .88);
  font-family: var(--serif);
  font-size: clamp(15px, 4vw, 18px);
  line-height: 1.8;
  letter-spacing: .08em;
  text-shadow: 0 2px 16px rgba(0, 0, 0, .7);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 1s .55s ease, transform 1s .55s ease;
}

.app[data-stage="together"] .moon-caption {
  opacity: 1;
  transform: translateY(0);
}

.mooncake-control {
  position: absolute;
  z-index: 9;
  left: 50%;
  bottom: clamp(118px, 14.5vh, 154px);
  width: 76px;
  height: 76px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(12px) scale(.86);
  background: transparent;
  cursor: pointer;
  transition: opacity .65s ease, transform .75s cubic-bezier(.2, .78, .2, 1);
}

.app[data-stage="together"] .mooncake-control {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0) scale(1);
}

.app[data-stage="splitting"] .mooncake-control {
  opacity: 1;
  pointer-events: none;
  transform: translateX(-50%) translateY(0) scale(1);
}

.mooncake-control::before {
  content: "";
  position: absolute;
  inset: -12px;
  border-radius: 50%;
  border: 1px solid rgba(247, 232, 189, .5);
  animation: mooncake-pulse 2.4s ease-out infinite;
}

@keyframes mooncake-pulse {
  0% { opacity: .8; transform: scale(.78); }
  75%, 100% { opacity: 0; transform: scale(1.22); }
}

.cake-half {
  position: absolute;
  top: 9px;
  width: 30px;
  height: 57px;
  overflow: hidden;
  background:
    radial-gradient(circle at 52% 50%, transparent 0 8px, rgba(116, 58, 18, .33) 9px 10px, transparent 11px),
    repeating-conic-gradient(from 0deg, rgba(255, 226, 141, .5) 0 7deg, transparent 8deg 20deg),
    linear-gradient(135deg, #f1ba52, #c86d27);
  box-shadow: inset 0 0 0 2px rgba(111, 55, 20, .38), 0 8px 16px rgba(0, 0, 0, .3);
  transition: transform .9s cubic-bezier(.18, .78, .16, 1), opacity .55s .48s ease;
}

.cake-left { left: 8px; border-radius: 30px 4px 4px 30px; }
.cake-right { right: 8px; border-radius: 4px 30px 30px 4px; }

.mooncake-control.is-split .cake-left {
  transform: translate(-82px, -42px) rotate(-26deg);
  opacity: 0;
}

.mooncake-control.is-split .cake-right {
  transform: translate(82px, -42px) rotate(26deg);
  opacity: 0;
}

.mooncake-control.is-split::before { display: none; }

.cake-hint {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 11px);
  width: max-content;
  max-width: 70vw;
  transform: translateX(-50%);
  color: rgba(255, 244, 213, .86);
  font-size: 12px;
  letter-spacing: .14em;
  text-shadow: 0 2px 12px rgba(0, 0, 0, .8);
}

.ending-card {
  position: absolute;
  z-index: 12;
  left: max(24px, 7vw);
  right: max(24px, 7vw);
  bottom: calc(var(--safe-bottom) + 18px);
  padding: 24px 24px 20px;
  border: 1px solid rgba(247, 232, 189, .48);
  border-radius: 2px 22px 2px 22px;
  color: var(--paper);
  background: linear-gradient(145deg, rgba(22, 30, 41, .9), rgba(13, 19, 29, .84));
  box-shadow: 0 22px 46px rgba(0, 0, 0, .36), inset 0 1px rgba(255, 255, 255, .08);
  backdrop-filter: blur(12px);
  opacity: 0;
  transform: translateY(32px);
  pointer-events: none;
  transition: opacity 1s ease, transform 1.05s cubic-bezier(.2, .78, .2, 1);
}

.ending-card::before {
  content: "";
  position: absolute;
  top: 14px;
  right: 18px;
  width: 29px;
  height: 29px;
  border: 1px solid rgba(232, 185, 90, .54);
  border-radius: 50%;
  box-shadow: inset 9px 0 0 rgba(232, 185, 90, .1);
}

.app[data-stage="ending"] .ending-card {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.ending-label {
  margin: 0 0 11px;
  color: rgba(232, 185, 90, .78);
  font-family: var(--serif);
  font-size: 11px;
  letter-spacing: .28em;
}

.ending-copy {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(18px, 4.9vw, 22px);
  font-weight: 500;
  line-height: 1.75;
  letter-spacing: .045em;
}

.ending-copy span { display: block; }

.poster-button {
  min-height: 46px;
  margin-top: 17px;
  padding: 9px 18px;
  border: 1px solid rgba(247, 232, 189, .62);
  border-radius: 999px;
  color: var(--moon-bright);
  background: rgba(247, 232, 189, .09);
  font-family: var(--serif);
  font-size: 14px;
  letter-spacing: .12em;
  cursor: pointer;
}

.poster-modal[hidden] { display: none; }

.poster-modal {
  position: fixed;
  z-index: 80;
  inset: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 12px;
  padding: var(--safe-top) max(16px, env(safe-area-inset-right)) var(--safe-bottom) max(16px, env(safe-area-inset-left));
  color: var(--paper);
  background: rgba(6, 11, 19, .95);
  backdrop-filter: blur(16px);
}

.poster-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.poster-head h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 500;
  letter-spacing: .1em;
}

.close-button {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid rgba(247, 232, 189, .38);
  border-radius: 50%;
  color: var(--moon);
  background: rgba(255, 255, 255, .04);
  cursor: pointer;
}

.close-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
}

.poster-stage {
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.poster-image {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: calc(100vh - 190px);
  max-height: calc(100dvh - 190px);
  border-radius: 3px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .48);
  object-fit: contain;
  -webkit-touch-callout: default;
}

.poster-fallback {
  max-width: 310px;
  margin: 0;
  text-align: center;
  font-size: 15px;
  line-height: 1.8;
  color: rgba(247, 232, 189, .82);
}

.poster-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-height: 48px;
}

.poster-tip {
  margin: 0;
  color: rgba(247, 232, 189, .7);
  font-size: 13px;
  line-height: 1.55;
  text-align: center;
}

.download-link {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  padding: 9px 17px;
  border: 1px solid rgba(247, 232, 189, .48);
  border-radius: 999px;
  color: var(--moon-bright);
  text-decoration: none;
  background: rgba(247, 232, 189, .08);
}

:focus-visible {
  outline: 3px solid var(--osmanthus);
  outline-offset: 4px;
}

@media (max-height: 710px) {
  .opening-copy { top: 112px; }
  .opening-copy h1 { font-size: 27px; line-height: 1.42; }
  .moon-wrap { top: 67px; width: 116px; }
  .moon-caption { top: 212px; font-size: 14px; }
  .mooncake-control { bottom: 103px; transform: translateX(-50%) scale(.9); }
  .app[data-stage="together"] .mooncake-control { transform: translateX(-50%) scale(.9); }
  .ending-card { padding: 17px 20px 15px; }
  .ending-copy { font-size: 17px; line-height: 1.58; }
  .poster-button { margin-top: 12px; }
}

@media (min-width: 700px) {
  .app { max-width: 520px; margin: 0 auto; box-shadow: 0 0 90px rgba(0, 0, 0, .46); }
  body { background: #070d17; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    transition-delay: 0ms !important;
  }
  .petals,
  .spark-field { display: none; }
}

.reduce-motion *,
.reduce-motion *::before,
.reduce-motion *::after {
  scroll-behavior: auto !important;
  animation-duration: .01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: .01ms !important;
  transition-delay: 0ms !important;
}

.reduce-motion .petals,
.reduce-motion .spark-field { display: none; }
