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

html {
  height: 100%;
  overflow: hidden;
}

html.story-mode {
  height: auto;
  overflow: visible;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  height: 100vh;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f5f5f5;
  color: #222;
}

body.story-mode {
  display: block;
  height: auto;
  overflow: visible;
}

#page-flash {
  position: fixed;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  z-index: 1000;
  transition: opacity 0.4s ease;
}

#page-flash.show {
  opacity: 1;
}

main {
  text-align: center;
  opacity: 0;
  transform: scale(0.92);
  transition: opacity 0.6s ease, transform 0.6s ease;
}

main.show {
  opacity: 1;
  transform: scale(1);
}

#intro {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 12px;
  padding: 0 24px;
}

#intro[hidden] {
  display: none;
}

#heart-scene {
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 1;
  transition: opacity 0.5s ease;
}

#heart-scene[hidden] {
  display: none;
}

#heart-scene.fade-out {
  opacity: 0;
}

#heart-scene svg {
  width: 260px;
  height: 244px;
}

#heart-scene path {
  fill: none;
  stroke: #ff6b81;
  stroke-width: 10;
}

#intro h1,
#intro p {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
}

#intro h1 {
  font-size: 2.25rem;
  font-weight: 700;
}

#intro p {
  color: #777;
}

#intro span {
  display: inline-block;
  opacity: 0;
}

#intro .space {
  width: 0.3em;
}

h1 {
  margin-bottom: 32px;
  font-weight: 600;
}

.stage {
  position: relative;
  display: flex;
  justify-content: center;
}

.envelope-scene {
  perspective: 1000px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.envelope-scene.is-zooming {
  animation: portal-zoom 0.7s cubic-bezier(0.45, 0, 0.55, 1);
}

@keyframes portal-zoom {
  0% {
    transform: scale(1);
    filter: blur(0);
  }
  50% {
    transform: scale(6);
    filter: blur(14px);
  }
  100% {
    transform: scale(1);
    filter: blur(0);
  }
}

.flash {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.95) 0%, rgba(255, 255, 255, 0) 70%);
  opacity: 0;
  pointer-events: none;
  z-index: 10;
}

.flash.is-flashing {
  animation: portal-flash 0.7s cubic-bezier(0.45, 0, 0.55, 1);
}

@keyframes portal-flash {
  0% {
    opacity: 0;
  }
  50% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}


.envelope {
  position: relative;
  width: 280px;
  height: 180px;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  transform-style: preserve-3d;
}

.envelope-back {
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, #f0dfc0, #dcc49a);
  border-radius: 6px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.18);
}

.letter {
  position: absolute;
  left: 8%;
  right: 8%;
  top: 6%;
  height: 82%;
  background: #fff;
  border-radius: 4px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.12);
  z-index: 2;
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transform: translateY(0);
  transition: transform 0.5s ease;
}

.letter-line {
  display: block;
  height: 6px;
  border-radius: 3px;
  background: #e2e2e2;
}

.letter-line:nth-child(2) {
  width: 85%;
}

.letter-line:nth-child(3) {
  width: 65%;
}

.envelope-flap {
  position: absolute;
  inset: 0;
  z-index: 3;
  backface-visibility: hidden;
}

.envelope-flap-bottom {
  background: linear-gradient(135deg, #e6d0a8, #d2b686);
  clip-path: polygon(0% 100%, 100% 100%, 50% 50%);
}

.envelope-flap-left {
  background: linear-gradient(135deg, #ddc59a, #cbb280);
  clip-path: polygon(0% 0%, 0% 100%, 50% 50%);
}

.envelope-flap-right {
  background: linear-gradient(135deg, #ddc59a, #cbb280);
  clip-path: polygon(100% 0%, 100% 100%, 50% 50%);
}

.envelope-flap-top {
  background: linear-gradient(135deg, #f5e6c8, #e6cd9e);
  clip-path: polygon(0% 0%, 100% 0%, 50% 50%);
  transform-origin: top center;
  transform: rotateX(0deg);
  transition: transform 0.6s ease 0.35s;
  z-index: 4;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
}

.envelope.is-open .envelope-flap-top {
  transform: rotateX(180deg);
  transition: transform 0.6s ease;
}

.envelope.is-open .letter {
  transform: translateY(-58%);
  transition: transform 0.5s ease 0.35s;
}

.hint {
  color: #777;
  font-size: 0.9rem;
}

#story[hidden] {
  display: none;
}

#story nav {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  width: 170px;
  height: 40px;
  align-items: center;
  justify-content: space-evenly;
  border-radius: 20px;
  background: #fff;
  box-shadow: 0 3px 7px rgba(0, 0, 0, 0.1);
  z-index: 20;
}

#story nav a {
  color: #ff6b81;
  text-decoration: none;
  font-weight: 600;
}

#music-widget {
  position: fixed;
  top: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  width: min(220px, 60vw);
  padding: 10px 14px;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 3px 7px rgba(0, 0, 0, 0.1);
  z-index: 20;
}

#music-widget[hidden] {
  display: none;
}

.music-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

#music-toggle {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 50%;
  background: #ff6b81;
  color: #fff;
  font-size: 0.7rem;
  line-height: 1;
  cursor: pointer;
}

#music-title {
  flex-shrink: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.75rem;
  color: #4b4750;
}

.music-vol-icon {
  flex-shrink: 0;
  font-size: 0.85rem;
}

#music-volume {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(to right, #ff6b81 0%, #ff6b81 50%, #f3c9d3 50%, #f3c9d3 100%);
  outline: none;
}

#music-volume::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #ff6b81;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
  cursor: pointer;
  margin-top: -5px;
}

#music-volume::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border: 2px solid #ff6b81;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
  cursor: pointer;
}

#music-volume::-moz-range-track {
  height: 6px;
  border-radius: 3px;
  background: transparent;
}

#music-volume::-moz-range-track {
  background: #f3c9d3;
  border-radius: 2px;
  height: 4px;
}

#story section {
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  text-align: center;
}

#story section h2 {
  font-size: 2rem;
  font-weight: 700;
  color: #2e2c33;
}

.moment-video video {
  width: min(320px, 80vw);
  max-height: 70vh;
  border-radius: 16px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.18);
  object-fit: cover;
  display: block;
}

#moment-1 {
  background: #bfe3ff;
}

#moment-2 {
  background: #ffd6e8;
}

#moment-3 {
  background: #e6d9ff;
}

#moment-4 {
  background: #d4f0e0;
}

#ending {
  background: #fff5f8;
}

.ending-caption {
  font-size: 2rem;
  font-weight: 700;
  color: #2e2c33;
}

.ending-hint {
  color: #4b4750;
  font-size: 0.9rem;
}

.ending-message {
  font-size: clamp(1.75rem, 6vw, 2.75rem);
  font-weight: 700;
  color: #ff6b81;
  white-space: nowrap;
  clip-path: inset(0 100% 0 0);
}

.ending-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 220px;
  height: 8px;
  border-radius: 4px;
  background: #f3c9d3;
  outline: none;
}

.ending-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #ff6b81;
  cursor: pointer;
}

.ending-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border: 2px solid #ff6b81;
  border-radius: 50%;
  background: #fff;
  cursor: pointer;
}

.ending-slider::-moz-range-track {
  background: #f3c9d3;
  border-radius: 4px;
  height: 8px;
}

.ending-sign {
  margin-top: 4px;
  font-size: 1.1rem;
  font-style: italic;
  font-weight: 700;
  color: #2e2c33;
}
