* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-family: 'Noto Sans', sans-serif;
  touch-action: none;
}

#stats {
  margin-bottom: 20px;
  text-align: center;
  font-family: 'Space Mono', monospace;
}

#timer {
  font-size: 32px;
  font-weight: bold;
  color: #333;
  margin-bottom: 5px;
}

#best {
  font-size: 16px;
  color: #666;
}

#menu {
  display: flex;
  gap: 10px;
  margin-bottom: 30px;
  z-index: 100;
}

#menu button {
  padding: 12px 20px;
  font-size: 16px;
  font-family: 'Noto Sans', sans-serif;
  background: white;
  border: 2px solid #333;
  cursor: pointer;
  transition: transform 0.1s;
}

#menu button:active {
  transform: scale(0.95);
}

#menu button.selected {
  background: #333;
  color: white;
}

#container {
  position: relative;
  width: 300px;
  height: 200px;
  transition: transform 0.05s linear;
  will-change: transform;
}

#envelope {
  position: absolute;
  width: 100%;
  height: 100%;
  cursor: grab;
}

#envelope:active {
  cursor: grabbing;
}

.envelope-back,
.envelope-front {
  position: absolute;
  width: 100%;
  height: 100%;
  background: #f4f4f4;
  border: 2px solid #333;
}

.envelope-flap {
  position: absolute;
  width: 100%;
  height: 50%;
  background: #e8e8e8;
  border: 2px solid #333;
  border-bottom: none;
  top: 0;
  left: 0;
  transform-origin: bottom center;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  z-index: 10;
}

.envelope-flap.opening {
  animation: openFlap 0.4s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes openFlap {
  to {
    transform: rotateX(-180deg);
  }
}

#letter {
  position: absolute;
  width: 90%;
  height: 150%;
  background: white;
  border: 2px solid #333;
  left: 5%;
  top: 60%;
  opacity: 0;
  pointer-events: none;
  transition: top 0.5s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s;
}

#letter.visible {
  top: -25%;
  opacity: 1;
}

.letter-content {
  padding: 40px 20px;
  text-align: center;
}

.letter-content p {
  margin: 10px 0;
  font-size: 24px;
  color: #333;
}

.letter-content p:last-child {
  font-size: 48px;
}

#envelope.opened {
  pointer-events: none;
}

.tear-effect {
  position: absolute;
  width: 50%;
  height: 100%;
  background: #f4f4f4;
  border: 2px solid #333;
  top: 0;
  opacity: 0;
  pointer-events: none;
  z-index: 5;
}

#tear-left {
  left: 0;
  transform-origin: right center;
}

#tear-right {
  right: 0;
  transform-origin: left center;
}

.tearing #tear-left {
  animation: tearLeft 0.3s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.tearing #tear-right {
  animation: tearRight 0.3s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes tearLeft {
  0% {
    opacity: 1;
    transform: translateX(0) rotate(0deg);
  }
  100% {
    opacity: 0;
    transform: translateX(-150%) rotate(-30deg);
  }
}

@keyframes tearRight {
  0% {
    opacity: 1;
    transform: translateX(0) rotate(0deg);
  }
  100% {
    opacity: 0;
    transform: translateX(150%) rotate(30deg);
  }
}

.slicing .envelope-front {
  animation: sliceOpen 0.5s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes sliceOpen {
  0% {
    clip-path: inset(0 0 0 0);
  }
  100% {
    clip-path: inset(0 0 0 100%);
  }
}

.peeling .envelope-flap {
  animation: peelFlap 0.6s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes peelFlap {
  0% {
    transform: rotateX(0deg);
  }
  50% {
    transform: rotateX(-90deg) translateY(-10px);
  }
  100% {
    transform: rotateX(-180deg);
  }
}