:root {
  --fade-duration: 460ms;
  --card-width: min(100vw, calc(100vh * 9 / 16));
  --card-height: min(100vh, calc(100vw * 16 / 9));
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #111014;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  touch-action: manipulation;
}

body {
  display: grid;
  place-items: center;
}

button {
  font: inherit;
}

.phone-frame {
  position: relative;
  width: var(--card-width);
  height: var(--card-height);
  max-width: 100vw;
  max-height: 100vh;
  aspect-ratio: 9 / 16;
  overflow: hidden;
  background: #000;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.45);
  isolation: isolate;
  user-select: none;
  touch-action: manipulation;
}

.scene {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
  transform: scale(1.01);
  transition:
    opacity var(--fade-duration) ease,
    transform var(--fade-duration) ease;
}

.scene.is-active {
  opacity: 1;
  pointer-events: auto;
  transform: scale(1);
  z-index: 1;
}

.scene-image {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  pointer-events: none;
}

.scene-1.is-active .scene-image {
  animation: softReveal 700ms ease both;
}

.scene-1 {
  cursor: pointer;
}

.tap-pulse {
  position: absolute;
  left: 50%;
  bottom: 11%;
  width: 46%;
  aspect-ratio: 3.4 / 1;
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.28);
  transform: translateX(-50%);
  animation: pulseHint 1.8s ease-in-out infinite;
  pointer-events: none;
}

.scene-2.is-active .scene-image,
.scene-4.is-active .scene-image {
  animation: gentleZoom 1.9s ease both;
}

.music-toggle {
  position: absolute;
  z-index: 5;
  top: max(10px, env(safe-area-inset-top));
  right: max(10px, env(safe-area-inset-right));
  min-width: 76px;
  min-height: 32px;
  padding: 6px 9px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 999px;
  background: rgba(25, 20, 28, 0.38);
  color: rgba(255, 255, 255, 0.92);
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  backdrop-filter: blur(8px);
  cursor: pointer;
  touch-action: manipulation;
}

.music-toggle:active {
  transform: scale(0.96);
}

/* Scene 3 note overlay positions. Adjust these values if the artwork shifts. */
.note-cover {
  position: absolute;
  left: 10%;
  width: 80%;
  height: 17%;
  border: 0;
  border-radius: 18px;
  box-shadow:
    0 12px 22px rgba(92, 62, 83, 0.24),
    inset 0 1px 0 rgba(255, 255, 255, 0.56);
  cursor: pointer;
  touch-action: manipulation;
  transform-origin: center;
  transform-style: preserve-3d;
  transition:
    opacity 160ms ease 380ms,
    transform 520ms cubic-bezier(0.22, 0.8, 0.28, 1);
}

.note-cover::before {
  content: "";
  position: absolute;
  inset: 9px;
  border: 2px dashed rgba(255, 255, 255, 0.48);
  border-radius: 13px;
}

.note-cover::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.42), rgba(255, 255, 255, 0));
  pointer-events: none;
}

.note-cover-pink {
  top: 24%;
  background: linear-gradient(135deg, #ffc3d8, #ff8fbb);
}

.note-cover-yellow {
  top: 45%;
  background: linear-gradient(135deg, #fff3a6, #ffd45f);
}

.note-cover-blue {
  top: 66%;
  background: linear-gradient(135deg, #bfeaff, #86c8ff);
}

.note-icon {
  position: absolute;
  top: 50%;
  left: 50%;
  color: rgba(255, 255, 255, 0.94);
  font-size: clamp(34px, 10vw, 58px);
  font-weight: 800;
  text-shadow: 0 2px 8px rgba(110, 73, 93, 0.2);
  transform: translate(-50%, -50%);
}

.note-mark {
  position: absolute;
  top: 14px;
  right: 16px;
  color: rgba(255, 255, 255, 0.42);
  font-size: 18px;
  font-weight: 900;
}

.note-cover.is-open {
  opacity: 0;
  pointer-events: none;
  transform: perspective(700px) rotateY(92deg) scale(1.025);
}

/* Scene 4 の名前表示位置・サイズはここで調整 */
.final-name {
  position: absolute;
  z-index: 5;
  top: 49%;
  left: 50%;
  width: 82%;
  max-width: 82%;
  height: 11.5%;
  margin: 0 auto;
  color: #ff4fa0;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 800;
  line-height: 0.96;
  letter-spacing: 0;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  text-wrap: balance;
  text-shadow:
    0 3px 0 rgba(255, 255, 255, 0.92),
    0 -2px 0 rgba(255, 255, 255, 0.82),
    2px 0 0 rgba(255, 238, 247, 0.92),
    -2px 0 0 rgba(255, 238, 247, 0.92),
    0 8px 18px rgba(179, 47, 116, 0.2);
  transform: translateX(-50%);
  pointer-events: none;
}

.replay-button {
  position: absolute;
  z-index: 6;
  left: 50%;
  bottom: 8%;
  min-width: 112px;
  min-height: 42px;
  padding: 10px 22px;
  border: 2px solid rgba(255, 255, 255, 0.86);
  border-radius: 999px;
  background: rgba(255, 79, 160, 0.86);
  color: #ffffff;
  font-size: 16px;
  font-weight: 800;
  line-height: 1;
  box-shadow:
    0 7px 18px rgba(179, 47, 116, 0.24),
    inset 0 1px 0 rgba(255, 255, 255, 0.38);
  cursor: pointer;
  transform: translateX(-50%);
  touch-action: manipulation;
}

.replay-button:active {
  transform: translateX(-50%) scale(0.96);
}

/* Scene 5's outer area matches the artwork's white panel and centers all copy. */
.message-area {
  position: absolute;
  z-index: 5;
  top: 20%;
  left: 50%;
  width: 64%;
  height: 56%;
  display: flex;
  align-items: center;
  justify-content: center;
  transform: translateX(-50%);
}

.message-content {
  width: 100%;
  max-height: 100%;
  color: #49323d;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(0.84rem, calc(var(--card-width) * 0.044), 1.08rem);
  line-height: 1.42;
  text-align: left;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.message-area.is-long .message-content {
  line-height: 1.42;
}

.message-content p {
  margin: 0;
}

.message-greeting {
  margin-bottom: 0.9em !important;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.message-body {
  white-space: pre-wrap;
}

.message-signoff {
  display: flex;
  flex-direction: column;
  margin-top: 1em !important;
}

.message-area.is-long .message-signoff {
  margin-top: 1em !important;
}

.message-sender {
  overflow-wrap: anywhere;
}

.scene-5-replay {
  bottom: max(4%, env(safe-area-inset-bottom));
}

.confetti-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.confetti {
  position: absolute;
  top: -8%;
  width: 7px;
  height: 12px;
  border-radius: 2px;
  opacity: 0.85;
  animation: confettiFall var(--fall-duration, 3.8s) linear forwards;
}

@keyframes softReveal {
  from {
    opacity: 0;
    transform: scale(1.02);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes gentleZoom {
  from {
    transform: scale(1.035);
  }
  to {
    transform: scale(1);
  }
}

@keyframes pulseHint {
  0%,
  100% {
    opacity: 0.16;
    transform: translateX(-50%) scale(0.96);
  }
  50% {
    opacity: 0.48;
    transform: translateX(-50%) scale(1.04);
  }
}

@keyframes confettiFall {
  0% {
    transform: translate3d(0, 0, 0) rotate(0deg);
  }
  100% {
    transform: translate3d(var(--drift, 0), 118vh, 0) rotate(420deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .scene,
  .note-cover {
    transition-duration: 180ms;
  }

  .scene-1.is-active .scene-image,
  .scene-2.is-active .scene-image,
  .scene-4.is-active .scene-image,
  .scene-5.is-active .scene-image,
  .tap-pulse,
  .confetti {
    animation-duration: 1ms;
    animation-iteration-count: 1;
  }

  .note-cover.is-open {
    transform: scale(0.98);
  }
}

@media (max-height: 600px) {
  .message-area {
    top: 19%;
    width: 66%;
    height: 56%;
  }

  .message-content {
    font-size: clamp(0.72rem, calc(var(--card-width) * 0.041), 0.9rem);
    line-height: 1.4;
  }

  .message-area.is-long .message-content {
    line-height: 1.45;
  }

  .message-greeting {
    margin-bottom: 0.9em !important;
  }

  .message-signoff {
    margin-top: 0.9em !important;
  }

  .scene-5-replay {
    min-height: 36px;
    padding: 8px 18px;
    font-size: 14px;
  }
}
