/* =========================================================
   Night sky intro (the public first page)
   ========================================================= */
.screen.intro {
  position: fixed; inset: 0; z-index: 10;
  max-width: none; min-height: 0; margin: 0; padding: 0;
  display: none;
  overflow: hidden;
  color: #ffe9f1;
  background:
    radial-gradient(120% 60% at 50% 115%, rgba(255, 122, 168, .55), transparent 60%),
    radial-gradient(80% 50% at 85% 0%, rgba(120, 90, 200, .35), transparent 70%),
    linear-gradient(180deg, #0a0c26 0%, #161437 40%, #2c1a4d 72%, #5a2558 100%);
}
.screen.intro.is-active { display: block; animation: none; }
.screen.intro.leaving { animation: introOut .7s ease forwards; }
@keyframes introOut { to { opacity: 0; transform: scale(1.04); } }

#sky { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.intro-skip, .intro-replay {
  position: absolute; z-index: 5;
  padding: 8px 14px;
  border: 1px solid rgba(255, 214, 229, .35);
  border-radius: 999px;
  background: rgba(255, 255, 255, .06);
  color: rgba(255, 233, 241, .85);
  font: 700 .85rem "Nunito", "Gowun Dodum", sans-serif;
  cursor: pointer;
  backdrop-filter: blur(4px);
  transition: background .2s, opacity .4s;
}
.intro-skip { top: 16px; right: 16px; }
.intro-replay { bottom: 58px; left: 50%; transform: translateX(-50%); }
.intro-skip:hover, .intro-replay:hover { background: rgba(255, 255, 255, .14); }
.intro-skip.gone { opacity: 0; pointer-events: none; }

/* scenes stack on top of each other and cross-fade */
.intro-stage { position: absolute; inset: 0; z-index: 2; }
.scene {
  position: absolute; left: 0; right: 0; top: 44%;
  padding: 0 20px;
  display: flex; flex-direction: column; align-items: center;
  text-align: center;
  opacity: 0; visibility: hidden;
  transform: translateY(14px);
  transition: opacity .9s ease, transform .9s ease, visibility 0s .9s;
}
.scene.on { opacity: 1; visibility: visible; transform: none; transition: opacity .9s ease, transform .9s ease; }

/* scene 1: hello */
.hello {
  margin: 0;
  font-family: "Caveat", "Nanum Pen Script", cursive; font-weight: 700;
  font-size: clamp(2.6rem, 11vw, 4.6rem); line-height: 1.05;
  color: #fff;
  text-shadow: 0 0 22px rgba(255, 143, 181, .65), 0 0 2px rgba(255, 255, 255, .8);
  min-height: 1.1em;
}
.hello-hi { color: #ffd0e1; }
.caret {
  display: inline-block;
  width: 3px; height: .85em;
  margin-left: 4px;
  vertical-align: -0.08em;
  background: #ffb3cf;
  border-radius: 2px;
  animation: caret 1s steps(1) infinite;
}
.caret.done { animation: caret 1s steps(1) 2 forwards; }
@keyframes caret { 50% { opacity: 0; } }
.hello-sub {
  margin: 14px 0 0;
  min-height: 1.4em;
  font-family: "Caveat", "Nanum Pen Script", cursive;
  font-size: clamp(1.5rem, 6vw, 2.1rem);
  color: #ffd6e5;
}
.ring-line {
  margin: 0 0 10px;
  padding: 5px 14px;
  border: 1px solid rgba(255, 214, 229, .4);
  border-radius: 999px;
  font: 800 .85rem "Nunito", "Gowun Dodum", sans-serif; letter-spacing: .06em;
  color: #ffe9f1;
  background: rgba(255, 255, 255, .07);
  animation: ringGlow 2.4s ease-in-out infinite;
}
@keyframes ringGlow { 50% { box-shadow: 0 0 18px rgba(255, 214, 229, .45); } }

/* scene 2: the route */
#sceneMap { top: calc(21vh + 150px); }
@media (min-width: 900px) { #sceneMap { top: calc(21vh + 160px); } .route { width: 400px; } }
.route { width: min(92vw, 440px); height: auto; overflow: visible; }
.route text { fill: #ffe9f1; font: 800 13px "Nunito", "Gowun Dodum", sans-serif; }
.route .city-sub { fill: #ffb3cf; font: 700 16px "Caveat", "Nanum Pen Script", cursive; }
.city-glow { fill: rgba(255, 143, 181, .35); animation: cityPulse 2s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes cityPulse { 50% { transform: scale(1.6); opacity: .4; } }
#routeTrail { stroke-dasharray: 1000; stroke-dashoffset: 1000; }
#plane { opacity: 0; }
.map-line {
  margin: 18px 0 0;
  max-width: 440px;
  min-height: 2.6em;
  font-family: "Caveat", "Nanum Pen Script", cursive;
  font-size: clamp(1.6rem, 6.4vw, 2.2rem); line-height: 1.2;
  color: #fff;
  text-shadow: 0 0 18px rgba(255, 143, 181, .5);
}
.map-line .w { display: inline-block; opacity: 0; transform: translateY(8px); filter: blur(4px); transition: opacity .6s, transform .6s, filter .6s; }
.map-line .w.in { opacity: 1; transform: none; filter: none; }

/* scene 3: the envelope */
#sceneEnvelope { top: 50%; transform: translateY(-46%); }
#sceneEnvelope.on { transform: translateY(-50%); }
.envelope {
  position: relative;
  width: min(84vw, 340px);
  aspect-ratio: 1.45;
  margin-top: 40px;
  perspective: 900px;
  filter: drop-shadow(0 26px 34px rgba(0, 0, 0, .45));
  animation: envFloat 4s ease-in-out infinite;
}
@keyframes envFloat { 50% { transform: translateY(-8px) rotate(-1deg); } }
.envelope.open { animation: none; }
.env-back, .env-front, .env-flap { position: absolute; left: 0; right: 0; border-radius: 10px; }
.env-back { inset: 0; background: #f6dbe3; }
.env-front {
  inset: 0; z-index: 3;
  background:
    linear-gradient(to top right, #fff1f5 50%, transparent 50.3%) left bottom / 50.2% 100% no-repeat,
    linear-gradient(to top left, #fff1f5 50%, transparent 50.3%) right bottom / 50.2% 100% no-repeat,
    linear-gradient(transparent 46%, #ffe6ee 46%) ;
  clip-path: polygon(0 26%, 50% 64%, 100% 26%, 100% 100%, 0 100%);
  pointer-events: none;
}
.env-flap {
  top: 0; height: 66%; z-index: 4;
  background: linear-gradient(180deg, #ffd3e1, #f7b8cb);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  transform-origin: top center;
  transition: transform .8s cubic-bezier(.5, 0, .3, 1), z-index 0s .4s;
}
.envelope.open .env-flap { transform: rotateX(180deg); z-index: 1; }

.env-letter {
  position: absolute; left: 6%; right: 6%; top: 8%; height: 86%;
  z-index: 2;
  display: flex; flex-direction: column; align-items: center;
  padding: 14px 16px 12px;
  border-radius: 8px;
  background:
    repeating-linear-gradient(#fffdf8 0 25px, #f3e2ea 25px 26px);
  color: var(--ink);
  transition: transform 1s cubic-bezier(.3, 1.2, .5, 1) .5s, height .6s ease .5s;
}
.envelope.open .env-letter { transform: translateY(-58%); z-index: 5; height: 128%; box-shadow: 0 20px 40px -18px rgba(0, 0, 0, .45); }
.letter-to { margin: 0; font-family: "Caveat", "Nanum Pen Script", cursive; font-size: 1.35rem; color: var(--ink-soft); }
.letter-title {
  margin: 2px 0 12px;
  font-family: "Caveat", "Nanum Pen Script", cursive; font-weight: 700;
  font-size: 1.65rem; line-height: 1.05;
  color: var(--berry);
}
.env-letter #keyInput {
  width: 100%;
  padding: 11px 14px;
  border-radius: 999px;
  border: 2px solid var(--pink-200);
  background: #fff;
  font: 700 1rem "Nunito", "Gowun Dodum", sans-serif;
  text-align: center;
  color: var(--ink);
  outline: none;
}
.env-letter #keyInput:focus { border-color: var(--pink-400); box-shadow: 0 0 0 4px rgba(255, 163, 196, .4); }
.env-letter .error { margin: 6px 0; min-height: 1.2em; font-size: .85rem; }
.env-letter .btn { padding: 10px 28px; font-size: 1.05rem; }
.env-letter:not(.ready) > *:not(.letter-to):not(.letter-title) { visibility: hidden; }
.envelope:not(.open) .env-letter > * { opacity: 0; }
.env-letter > * { transition: opacity .5s .6s; }

.wax {
  position: absolute; left: 50%; top: 66%; z-index: 6;
  width: 66px; height: 66px;
  margin: -33px 0 0 -33px;
  padding: 0; border: none; background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  animation: waxPulse 2.2s ease-in-out infinite;
}
@keyframes waxPulse { 50% { transform: scale(1.07); } }
.wax:focus-visible { outline: 3px dashed #ffb3cf; outline-offset: 6px; border-radius: 50%; }
.wax::before {
  content: ""; position: absolute; inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #e04a7f, #a81f50 70%);
  box-shadow: inset 0 0 0 4px rgba(255, 255, 255, .12), inset 0 0 0 9px rgba(0, 0, 0, .08);
}
.wax.broken::before { opacity: 0; }
.wax-half {
  opacity: 0;
  position: absolute; top: 0; width: 50%; height: 100%;
  background: radial-gradient(circle at 70% 35%, #e04a7f, #a81f50 70%);
  box-shadow: inset 0 0 0 4px rgba(255, 255, 255, .12);
  transition: transform .7s cubic-bezier(.4, 0, .6, 1), opacity .7s;
}
.wax-l { left: 0; border-radius: 33px 0 0 33px; clip-path: polygon(0 0, 100% 0, 80% 30%, 100% 55%, 82% 78%, 100% 100%, 0 100%); }
.wax-r { right: 0; border-radius: 0 33px 33px 0; background: radial-gradient(circle at 20% 35%, #e04a7f, #a81f50 70%); clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%, 18% 78%, 0 55%, 20% 30%); }
.wax-mark {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font: 700 2rem "Caveat", "Nanum Pen Script", cursive;
  color: rgba(255, 220, 232, .9);
  text-shadow: 0 -1px 0 rgba(0, 0, 0, .25);
  pointer-events: none;
  transition: opacity .3s;
}
.wax.broken { animation: none; pointer-events: none; }
.wax.broken .wax-mark { opacity: 0; }
.wax.broken .wax-half { animation: halfFall .8s cubic-bezier(.4, 0, .6, 1) forwards; }
.wax.broken .wax-l { --tx: -34px; --rot: -40deg; }
.wax.broken .wax-r { --tx: 34px; --rot: 35deg; }
@keyframes halfFall {
  0% { opacity: 1; transform: none; }
  25% { opacity: 1; transform: translateX(calc(var(--tx) * .2)); }
  100% { opacity: 0; transform: translate(var(--tx), 70px) rotate(var(--rot)); }
}

.tap-hint {
  margin: 22px 0 0;
  font-family: "Caveat", "Nanum Pen Script", cursive; font-size: 1.5rem;
  color: #ffd6e5;
  animation: hintBob 1.6s ease-in-out infinite;
}
@keyframes hintBob { 50% { transform: translateY(-4px); opacity: .7; } }

/* clocks */
.intro-foot {
  position: absolute; left: 0; right: 0; bottom: 14px; z-index: 3;
  display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 8px;
  padding: 0 16px;
  font: 700 .8rem "Nunito", "Gowun Dodum", sans-serif;
  color: rgba(255, 233, 241, .7);
}
.intro-foot b { color: #fff; font-weight: 800; }
.intro-foot .dot { opacity: .5; }

/* =========================================================
   After unlocking: photos fly into a heart
   ========================================================= */
.reveal {
  position: fixed; inset: 0; z-index: 60;
  display: grid; place-items: center;
  background: radial-gradient(circle at 50% 45%, #3a1f52, #0e0f2a 75%);
  overflow: hidden;
  transition: opacity .6s ease;
}
.reveal.fade { opacity: 0; }
.mosaic { position: relative; transition: transform .9s cubic-bezier(.6, 0, .4, 1), opacity .9s; }
.mosaic.shrink { transform: scale(.15) translateY(-40%); opacity: 0; }
.tile {
  position: absolute;
  border-radius: 6px;
  background: #ffc9dc center / cover no-repeat;
  box-shadow: 0 6px 14px -6px rgba(0, 0, 0, .55), 0 0 0 2px rgba(255, 255, 255, .85);
  opacity: 0;
  will-change: transform, opacity;
}
.tile.heart-tile { display: grid; place-items: center; background: none; box-shadow: none; font-size: 1.3em; }
.mosaic-glow {
  position: absolute; inset: -12%;
  background: radial-gradient(circle, rgba(255, 143, 181, .45), transparent 65%);
  opacity: 0; transition: opacity 1s;
  pointer-events: none;
}
.mosaic.lit .mosaic-glow { opacity: 1; animation: glowBeat 1.2s ease-in-out infinite; }
@keyframes glowBeat { 50% { transform: scale(1.06); } }
.reveal-line {
  position: absolute; left: 0; right: 0; bottom: 12%;
  text-align: center;
  font-family: "Caveat", "Nanum Pen Script", cursive; font-size: clamp(1.8rem, 7vw, 2.6rem);
  color: #fff;
  text-shadow: 0 0 18px rgba(255, 143, 181, .7);
  opacity: 0; transform: translateY(10px);
  transition: opacity .8s, transform .8s;
}
.reveal-line.in { opacity: 1; transform: none; }

@media (prefers-reduced-motion: reduce) {
  .scene { transition: opacity .01ms; }
  .envelope, .wax, .tap-hint { animation: none; }
}
@media (max-height: 640px) {
  #sceneMap { top: calc(17vh + 110px); }
  .route { width: min(80vw, 340px); }
  .scene { top: 38%; }
  .envelope { margin-top: 70px; }
}

/* Korean lines in the intro */
.route .city-ko { fill: #ffd0e1; font: 700 12px "Gowun Dodum", "Nunito", sans-serif; }
.hello-sub-ko { margin-top: 2px; font-size: clamp(1.25rem, 5vw, 1.7rem); opacity: .85; }
.map-line-ko { margin-top: 6px; min-height: 1.4em; font-size: clamp(1.25rem, 5vw, 1.7rem); opacity: .88; }
.reveal-line .ko { display: block; font-size: .72em; margin-top: 4px; opacity: .85; }
.intro-skip .ko, .intro-replay .ko { opacity: .8; }
