:root {
  --night: #17243a;
  --night-deep: #101a2d;
  --lavender: #aeb7df;
  --pink: #e7a6b7;
  --pink-deep: #bd718b;
  --cream: #fff3d8;
  --ink: #594958;
  --pixel: 'Press Start 2P', monospace;
  --ui: 'Pixelify Sans', sans-serif;
  --hand: 'Caveat', cursive;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--night-deep);
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: #fff1e7;
  background: radial-gradient(ellipse at 50% 40%, #293955 0%, var(--night) 48%, var(--night-deep) 100%);
  font-family: var(--ui);
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
}

.sky {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}

.moon {
  position: absolute;
  width: 66px;
  height: 66px;
  right: max(11vw, 34px);
  top: 9vh;
  border-radius: 50%;
  background: #fff0cb;
  box-shadow: 0 0 22px #fff0cb55, 0 0 70px #c9c8ed33;
}

.moon::after {
  content: '';
  position: absolute;
  width: 58px;
  height: 58px;
  left: -13px;
  top: -7px;
  border-radius: 50%;
  background: #202e47;
}

.stars {
  position: absolute;
  inset: 0;
  opacity: .75;
  background-repeat: repeat;
}

.stars-a {
  background-image: radial-gradient(2px 2px at 20px 30px, #fff4d5 98%, transparent), radial-gradient(1px 1px at 90px 80px, #fff 98%, transparent), radial-gradient(2px 2px at 160px 150px, #d9dfff 98%, transparent), radial-gradient(1px 1px at 220px 40px, #fff 98%, transparent);
  background-size: 270px 210px;
  animation: star-drift 42s linear infinite;
}

.stars-b {
  opacity: .45;
  background-image: radial-gradient(1px 1px at 40px 60px, #fff 98%, transparent), radial-gradient(2px 2px at 120px 130px, #f4c9d7 98%, transparent), radial-gradient(1px 1px at 200px 20px, #fff 98%, transparent);
  background-size: 230px 180px;
  animation: star-drift 58s linear infinite reverse;
}

.shooting-star {
  position: absolute;
  width: 70px;
  height: 1px;
  top: 19%;
  left: -100px;
  transform: rotate(-28deg);
  background: linear-gradient(90deg, transparent, #fff5d7);
  opacity: 0;
  animation: shooting 11s ease-in-out 2s infinite;
}

.hill {
  position: absolute;
  bottom: -13vh;
  width: 120vw;
  height: 30vh;
  border-radius: 50% 50% 0 0;
}

.hill-back {
  left: -25vw;
  background: #253b4b;
  transform: rotate(-5deg);
  opacity: .9;
}

.hill-front {
  right: -25vw;
  bottom: -18vh;
  background: #1b3342;
  transform: rotate(5deg);
}

.fireflies {
  position: absolute;
  inset: 0;
}

.firefly {
  position: absolute;
  width: 4px;
  height: 4px;
  background: #f7dba5;
  box-shadow: 0 0 9px 3px #f7dba555;
  animation: firefly 4s ease-in-out infinite alternate;
}

.page-shell {
  position: relative;
  z-index: 1;
  width: min(100% - 36px, 850px);
  min-height: 100svh;
  margin: auto;
  display: flex;
  flex-direction: column;
}

.topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 25px 0 0;
  gap: 12px;
}

.pixel-label,
.sound-toggle,
.page-footer {
  font: 8px/1.8 var(--pixel);
  letter-spacing: .04em;
}

.pixel-label {
  color: #b6c0d5;
}

.sound-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid #71819b77;
  border-radius: 3px;
  padding: 9px 10px;
  color: #f8e5d8;
  background: #1b2a41a8;
  cursor: pointer;
  transition: background .2s, transform .2s;
}

.sound-toggle:hover {
  background: #33445f;
  transform: translateY(-2px);
}

.sound-icon {
  font: 16px var(--ui);
  color: #efb6c5;
}

.intro {
  text-align: center;
  margin: clamp(34px, 7vh, 70px) 0 0;
}

.eyebrow {
  color: #d5b8c5;
  font-size: 17px;
  margin: 0 0 12px;
  letter-spacing: .05em;
}

h1 {
  font: clamp(21px, 4vw, 32px)/1.55 var(--pixel);
  margin: 0;
  color: #fff0df;
  text-shadow: 3px 3px 0 #101a2d;
}

h1 span:first-of-type {
  color: #f0b5c5;
}

.title-heart {
  color: #ef9fb5;
  font-size: .8em;
}

.intro-copy {
  color: #c2cada;
  font-size: 18px;
  margin: 13px 0 0;
}

.gift-scene {
  position: relative;
  flex: 1;
  min-height: 480px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 30px 0 40px;
}

.twinkle {
  position: absolute;
  color: #f8dcb0;
  font-size: 23px;
  text-shadow: 0 0 12px #f8dcb0;
  animation: twinkle 2.5s ease-in-out infinite;
}

.twinkle-one {
  top: 20%;
  left: 16%;
}

.twinkle-two {
  top: 32%;
  right: 17%;
  animation-delay: .7s;
}

.twinkle-three {
  bottom: 25%;
  left: 23%;
  animation-delay: 1.3s;
}

.envelope-wrap {
  position: relative;
  width: min(330px, 76vw);
  height: 225px;
  display: grid;
  place-items: center;
  perspective: 900px;
  transition: transform .3s;
}

.envelope-shadow {
  position: absolute;
  width: 78%;
  height: 20px;
  bottom: 0;
  border-radius: 50%;
  background: #08132388;
  filter: blur(8px);
}

.envelope {
  position: relative;
  display: block;
  width: 100%;
  height: 190px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  transform-style: preserve-3d;
  filter: drop-shadow(0 12px 12px #08132355);
  transition: transform .2s;
  -webkit-tap-highlight-color: transparent;
}

.envelope:hover {
  transform: translateY(-4px);
}

.envelope:focus-visible {
  outline: 3px dashed #ffe6c4;
  outline-offset: 10px;
}

.envelope-back {
  position: absolute;
  inset: 0;
  background: #d78fa4;
  border: 4px solid #f3c2c7;
  image-rendering: pixelated;
}

.letter-peek {
  position: absolute;
  z-index: 1;
  width: 76%;
  height: 130px;
  left: 12%;
  top: -3px;
  background: #fff2d8;
  border: 3px solid #e7d1b5;
  transition: transform .65s cubic-bezier(.2, .8, .2, 1);
}

.letter-peek::before {
  content: '♡';
  position: absolute;
  right: 12px;
  top: 8px;
  color: #d78fa4;
  font: 23px var(--hand);
}

.envelope-front {
  position: absolute;
  z-index: 2;
  inset: 0;
  background: #e9aabc;
  clip-path: polygon(0 0, 50% 58%, 100% 0, 100% 100%, 0 100%);
  border: 0;
}

.envelope-front::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, #f3c0c8 0 49%, transparent 50%), linear-gradient(225deg, #d98da4 0 49%, transparent 50%);
  opacity: .45;
}

.envelope-flap {
  position: absolute;
  z-index: 4;
  left: 0;
  top: 0;
  width: 100%;
  height: 60%;
  background: #f2bdc8;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  transform-origin: top center;
  transform: rotateX(0);
  transition: transform .65s ease, z-index .1s .3s;
  backface-visibility: visible;
}

.wax-seal {
  position: absolute;
  z-index: 5;
  left: 50%;
  top: 51%;
  width: 43px;
  height: 43px;
  display: grid;
  place-items: center;
  transform: translate(-50%, -50%);
  background: #a95672;
  color: #ffe2d8;
  border: 3px solid #f1c2c5;
  box-shadow: 2px 3px 0 #8e4962;
  font: 22px var(--ui);
  transition: opacity .25s, transform .3s;
}

.pixel-flower {
  position: absolute;
  z-index: 5;
  color: #fff0d8;
  font-size: 19px;
  text-shadow: 2px 2px 0 #b76f87;
}

.flower-left {
  left: 22px;
  bottom: 20px;
}

.flower-right {
  right: 22px;
  bottom: 20px;
  color: #f7d5a6;
}

.envelope-wrap.wiggle {
  animation: wiggle .45s ease;
}

.envelope-wrap.wiggle .wax-seal {
  transform: translate(-50%, -50%) scale(1.15) rotate(-12deg);
}

.envelope-wrap.opening .envelope-flap {
  transform: rotateX(180deg);
  z-index: 0;
}

.envelope-wrap.opening .wax-seal {
  opacity: 0;
  transform: translate(-50%, -50%) scale(.3);
}

.envelope-wrap.opening .letter-peek {
  transform: translateY(-85px);
}

.tap-instructions {
  text-align: center;
  margin-top: 14px;
  transition: opacity .35s, transform .35s;
}

.tap-title {
  font: 10px var(--pixel);
  color: #ffe7d7;
  margin: 0 0 13px;
}

.tap-subtitle {
  font-size: 18px;
  color: #c9d0df;
  margin: 0;
}

.tap-subtitle span {
  color: #f4b6c6;
}

.tap-progress {
  display: flex;
  justify-content: center;
  gap: 9px;
  margin: 17px 0 8px;
}

.tap-progress span {
  width: 13px;
  height: 13px;
  border: 2px solid #d9b3c1;
  background: #26364e;
  transform: rotate(45deg);
  transition: background .25s, box-shadow .25s;
}

.tap-progress span.filled {
  background: #f1afc0;
  box-shadow: 0 0 10px #f1afc088;
  border-color: #ffe0df;
}

.tap-count {
  font: 8px var(--pixel);
  color: #9eacc4;
  margin: 12px 0 0;
}

.letter-card {
  display: none;
  position: fixed;
  z-index: 8;
  width: min(520px, 94vw);
  min-height: min(365px, calc(100svh - 32px));
  max-height: calc(100svh - 32px);
  overflow-y: auto;
  overscroll-behavior: contain;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -43%) scale(.85);
  opacity: 0;
  background: var(--cream);
  color: var(--ink);
  border: 5px solid #e7d3b3;
  box-shadow: 8px 10px 0 #0b1728aa, inset 0 0 0 2px #fff9e8;
  padding: 35px clamp(25px, 7vw, 55px) 34px;
  background-image: repeating-linear-gradient(0deg, transparent 0 31px, #c8aeb044 32px, #c8aeb044 33px);
}

.letter-card.visible {
  display: block;
  animation: unfold .9s cubic-bezier(.2, .8, .2, 1) forwards;
}

.paper-holes {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 13px;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
}

.paper-holes i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #dfc5a7;
  box-shadow: inset 1px 1px 2px #9e8067;
}

.paper-content {
  position: relative;
  min-height: 290px;
}

.letter-date {
  font: 7px/1.7 var(--pixel);
  color: #a47b80;
  letter-spacing: .05em;
  margin: 0 0 18px;
}

.letter-greeting {
  font: 31px var(--hand);
  margin: 0 0 4px;
  color: #9f5d75;
}

.letter-message {
  min-height: 145px;
  white-space: pre-wrap;
  font: 23px/1.35 var(--hand);
  color: #594958;
}

.letter-message::after {
  content: '▌';
  color: #b86e87;
  animation: blink .8s steps(2) infinite;
}

.letter-message.done::after {
  display: none;
}

.letter-signoff {
  font: 22px var(--hand);
  margin: 12px 0 0;
  color: #77566a;
}

.letter-name {
  font: 29px var(--hand);
  font-weight: 700;
  color: #b36580;
  margin: -2px 0 0;
}

.paper-stamp {
  position: absolute;
  right: 0;
  bottom: -5px;
  transform: rotate(9deg);
  border: 2px solid #d49aa4;
  padding: 5px 7px;
  color: #bd7d8d;
  text-align: center;
  font: 6px/1.7 var(--pixel);
  opacity: .8;
}

.paper-stamp span {
  font-size: 12px;
}

.page-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: #8291aa;
  padding: 0 0 22px;
  text-align: center;
}

.footer-flower {
  color: #e9afbf;
  font: 17px var(--ui);
}

.toast {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 15px);
  opacity: 0;
  pointer-events: none;
  background: #fff0dc;
  color: #674c60;
  padding: 10px 15px;
  border: 2px solid #e7b8bf;
  font: 10px var(--ui);
  box-shadow: 3px 3px 0 #0d192b;
  transition: opacity .2s, transform .2s;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.confetti-heart {
  position: absolute;
  z-index: 9;
  pointer-events: none;
  color: #f2a8bd;
  font-size: 18px;
  animation: heart-float 1.5s ease-out forwards;
}

body.opened .intro {
  opacity: .35;
  transition: opacity .8s;
}

@keyframes wiggle {

  0%,
  100% {
    transform: rotate(0)
  }

  20% {
    transform: rotate(-4deg)
  }

  40% {
    transform: rotate(4deg)
  }

  60% {
    transform: rotate(-3deg)
  }

  80% {
    transform: rotate(2deg)
  }
}

@keyframes twinkle {

  0%,
  100% {
    opacity: .35;
    transform: scale(.8)
  }

  50% {
    opacity: 1;
    transform: scale(1.2)
  }
}

@keyframes star-drift {
  from {
    transform: translateY(0)
  }

  to {
    transform: translateY(80px)
  }
}

@keyframes shooting {

  0%,
  75%,
  100% {
    opacity: 0;
    transform: translate(0, 0) rotate(-28deg)
  }

  78% {
    opacity: 1
  }

  88% {
    opacity: 0;
    transform: translate(55vw, 25vh) rotate(-28deg)
  }
}

@keyframes firefly {
  from {
    opacity: .15;
    transform: translateY(0)
  }

  to {
    opacity: .9;
    transform: translateY(-15px)
  }
}

@keyframes blink {
  50% {
    opacity: 0
  }
}

@keyframes unfold {
  0% {
    opacity: 0;
    transform: translate(-50%, -35%) scale(.82) rotateX(-22deg)
  }

  60% {
    opacity: 1;
    transform: translate(-50%, -53%) scale(1.02) rotateX(4deg)
  }

  100% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1) rotateX(0)
  }
}

@keyframes heart-float {
  0% {
    opacity: 1;
    transform: translate(0, 0) scale(.7)
  }

  100% {
    opacity: 0;
    transform: translate(var(--drift), -95px) scale(1.3) rotate(20deg)
  }
}

@media (max-width: 600px) {
  .page-shell {
    width: min(100% - 28px, 500px);
  }

  .topline {
    padding-top: 17px;
  }

  .pixel-label,
  .sound-toggle {
    font-size: 6px;
  }

  .sound-toggle {
    padding: 7px 8px;
  }

  .intro {
    margin-top: 7vh;
  }

  .eyebrow {
    font-size: 15px;
  }

  h1 {
    font-size: clamp(18px, 5vw, 25px);
  }

  .intro-copy {
    font-size: 16px;
  }

  .gift-scene {
    min-height: 440px;
    padding-top: 15px;
  }

  .envelope-wrap {
    width: min(290px, 78vw);
    height: 205px;
  }

  .envelope {
    height: 170px;
  }

  .letter-card {
    width: min(94vw, 460px);
    min-height: min(345px, calc(100svh - 32px));
    padding: 28px 26px 25px 34px;
  }

  .paper-content {
    min-height: 290px;
  }

  .letter-message {
    font-size: 21px;
    min-height: 135px;
  }

  .letter-greeting {
    font-size: 28px;
  }

  .letter-name {
    font-size: 26px;
  }

  .letter-date {
    font-size: 6px;
  }

  .twinkle-one {
    left: 5%;
  }

  .twinkle-two {
    right: 5%;
  }

  .twinkle-three {
    left: 9%;
  }
}

@media (prefers-reduced-motion: reduce) {

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