:root {
  --bg-1: #ffd9e7;
  --bg-2: #ffeef5;
  --bg-3: #fff8fb;
  --ink: #5f3952;
  --accent: #ff6b9a;
  --accent-2: #ff8db5;
  --panel: rgba(255, 255, 255, 0.28);
  --panel-border: rgba(255, 255, 255, 0.55);
  --shadow: 0 30px 80px rgba(169, 72, 115, 0.18);
}

* {
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top, rgba(255,255,255,0.8), transparent 34%),
    radial-gradient(circle at 20% 20%, rgba(255, 255, 255, 0.35), transparent 18%),
    linear-gradient(160deg, var(--bg-1), var(--bg-2) 45%, var(--bg-3));
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image:
    radial-gradient(rgba(255,255,255,0.7) 1px, transparent 1px),
    radial-gradient(rgba(255,180,205,0.35) 1px, transparent 1px);
  background-size: 26px 26px, 18px 18px;
  background-position: 0 0, 9px 11px;
  opacity: 0.35;
  pointer-events: none;
}

.app-shell {
  position: relative;
  width: 100%;
  height: 100%;
}

.phase {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(16px, 3vw, 24px);
  transition: opacity 0.45s ease, transform 0.45s ease, filter 0.45s ease;
}

.phase.active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: scale(1);
}

.phase.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: scale(0.98);
  filter: blur(6px);
}

.panel,
.gift-scene,
.letter-shell,
.sticker-shell,
.bouquet-stage {
  width: min(92vw, 560px);
}

.passcode-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  padding: 28px 22px 24px;
  border: 1px solid var(--panel-border);
  border-radius: 34px;
  background: linear-gradient(180deg, rgba(255,255,255,0.38), rgba(255,255,255,0.18));
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.avatar {
  width: 120px;
  height: 120px;
  object-fit: cover;
  border-radius: 50%;
  border: 5px solid rgba(255,255,255,0.75);
  box-shadow: 0 14px 35px rgba(255, 116, 164, 0.22);
}

.heart-wrap {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.32);
  box-shadow: inset 0 8px 18px rgba(255,255,255,0.42);
}

.heart {
  font-size: 1.6rem;
  color: #ff4d88;
  animation: pulse 1.1s ease-in-out infinite;
  text-shadow: 0 0 18px rgba(255, 77, 136, 0.42);
}

.dots {
  display: flex;
  gap: 14px;
  padding: 10px 12px;
  border-radius: 999px;
  background: rgba(255,255,255,0.28);
}

.dot {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: rgba(112, 58, 90, 0.16);
  box-shadow: inset 0 2px 4px rgba(255,255,255,0.42);
  transition: transform 0.2s ease, background 0.2s ease;
}

.dot.filled {
  background: linear-gradient(180deg, #ff8db5, #ff5d94);
  transform: scale(1.06);
}

.dots.shake {
  animation: shake 0.48s ease;
}

.hint {
  margin: -4px 0 0;
  min-height: 1.35em;
  color: #c63456;
  font-weight: 700;
  text-align: center;
}

.hidden {
  display: none !important;
}

.keypad {
  width: min(100%, 320px);
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.key {
  min-height: 60px;
  border: none;
  border-radius: 18px;
  color: var(--ink);
  font-size: 1.2rem;
  font-weight: 700;
  background: linear-gradient(180deg, rgba(255,255,255,0.92), rgba(255, 236, 243, 0.92));
  box-shadow: 0 10px 20px rgba(177, 83, 121, 0.16), inset 0 1px 0 rgba(255,255,255,0.92);
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.08s ease, filter 0.2s ease;
}

.key:hover {
  filter: brightness(1.02);
}

.key:active {
  transform: translateY(2px) scale(0.98);
  box-shadow: inset 0 10px 18px rgba(176, 77, 118, 0.16), inset 0 -1px 0 rgba(255,255,255,0.55);
}

.key-clear,
.key-back {
  background: linear-gradient(180deg, rgba(255, 220, 232, 0.95), rgba(255, 205, 223, 0.95));
}

.key-back {
  font-size: 1rem;
}

.gift-scene,
.letter-shell,
.bouquet-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
}

.gift-scene {
  position: relative;
  z-index: 2;
}

.gift-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 3;
}

.gift-stack {
  position: relative;
  width: min(74vw, 360px);
  aspect-ratio: 1 / 1;
  filter: drop-shadow(0 30px 60px rgba(157, 79, 112, 0.24));
}

.gift-base,
.gift-lid {
  position: absolute;
  left: 50%;
  width: 100%;
  height: auto;
  transform: translateX(-50%);
  user-select: none;
  pointer-events: none;
}

.gift-base {
  bottom: 0;
}

.gift-lid {
  top: 100px;
  transform-origin: 50% 100%;
  transition: transform 0.85s cubic-bezier(0.2, 1.2, 0.2, 1), opacity 0.85s ease;
}

.gift-stack.open .gift-lid {
  transform: translate(-50%, -138%) rotate(-18deg) scale(0.92);
  opacity: 0;
}

.gift-glow {
  position: absolute;
  inset: 16% 20% 4% 20%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,0.9), rgba(255,255,255,0));
  opacity: 0;
  filter: blur(12px);
  transform: scale(0.6);
  transition: opacity 0.55s ease, transform 0.55s ease;
}

.gift-stack.open .gift-glow {
  opacity: 0.95;
  transform: scale(1.25);
}

.open-btn,
.continue-btn {
  border: none;
  border-radius: 999px;
  padding: 14px 28px;
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: white;
  background: linear-gradient(135deg, #ff6f9f, #ff8bbb 60%, #ffb2cc);
  box-shadow: 0 14px 26px rgba(255, 102, 155, 0.34);
  cursor: pointer;
  transform: translateY(0);
  transition: transform 0.2s ease, opacity 0.3s ease, box-shadow 0.2s ease;
}

.open-btn:hover,
.continue-btn:hover {
  transform: translateY(-2px);
}

.open-btn:active,
.continue-btn:active {
  transform: translateY(2px) scale(0.98);
}

.continue-btn {
  opacity: 0;
}

.continue-btn.reveal {
  opacity: 1;
}

.particle-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.particle {
  position: fixed;
  left: 0;
  top: 0;
  width: 42px;
  height: 42px;
  object-fit: contain;
  will-change: transform, opacity;
  filter: drop-shadow(0 8px 12px rgba(170, 74, 117, 0.2));
}

.letter-shell {
  width: min(92vw, 680px);
}

.sticker-shell {
  width: min(92vw, 720px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.letter-card {
  width: 100%;
  padding: clamp(20px, 3vw, 28px) clamp(18px, 3vw, 24px) clamp(18px, 3vw, 24px);
  border-radius: 34px;
  border: 1px solid rgba(255,255,255,0.6);
  background: linear-gradient(180deg, rgba(255,255,255,0.58), rgba(255,255,255,0.26));
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
}

.sticker-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: fit-content;
  max-width: 100%;
  padding: 16px 16px 18px;
  border-radius: 34px;
  border: 1px solid rgba(255,255,255,0.6);
  background: linear-gradient(180deg, rgba(255,255,255,0.56), rgba(255,255,255,0.24));
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
}

.sticker-art {
  display: block;
  height: auto;
  object-fit: contain;
  opacity: 0;
  transform: scale(0.2) rotate(-14deg);
}

.sticker-card.pop-in .sticker-art {
  animation: popIn 0.6s cubic-bezier(0.16, 1.14, 0.3, 1.08) forwards;
}

.sticker-art--small {
  width: min(72vw, 260px);
}

.sticker-art--medium {
  width: min(78vw, 320px);
}

.sticker-art--large {
  width: min(84vw, 390px);
}

.sticker-card--small {
  transform: translateY(0);
}

.sticker-card--medium {
  transform: translateY(0);
}

.sticker-card--large {
  transform: translateY(0);
}

.sticker-caption {
  margin: 0;
  text-align: center;
  font-weight: 800;
  line-height: 1.5;
  color: #6c4760;
  font-size: clamp(0.95rem, 2.4vw, 1.15rem);
}

.letter-header {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 18px;
}

.stamp {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
  border-radius: 999px;
  background: linear-gradient(135deg, #ff739f, #ffb0c9);
  color: white;
  font-weight: 800;
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.letter-header h2 {
  margin: 0;
  font-size: clamp(1.7rem, 4vw, 2.5rem);
}

.letter-text {
  margin: 0;
  min-height: 220px;
  white-space: pre-line;
  line-height: 1.8;
  font-size: clamp(1rem, 2.35vw, 1.12rem);
  color: #69465d;
}

.continue-btn {
  display: inline-flex;
  align-self: flex-end;
  margin-top: 14px;
  opacity: 0;
  transform: translateY(10px);
}

.continue-btn.reveal {
  animation: fadeRise 0.45s ease forwards;
}

.bouquet-stage {
  gap: 16px;
}

.bouquet-wrap {
  position: relative;
  width: min(78vw, 420px);
  min-height: 340px;
  transform-origin: center bottom;
  filter: drop-shadow(0 24px 50px rgba(160, 79, 118, 0.24));
}

.bouquet-wrap.assembled {
  animation: float 4.5s ease-in-out infinite;
}

.bouquet-paper {
  display: block;
  width: 100%;
  height: auto;
  user-select: none;
  pointer-events: none;
}

.bouquet-items {
  position: absolute;
  inset: 0;
}

.bouquet-piece {
  position: absolute;
  width: 62%;
  max-width: 360px;
  object-fit: contain;
  transform: translate(-50%, -50%) scale(0.2) rotate(0deg);
  opacity: 0;
  z-index: 2;
}

.bouquet-piece.pop-in {
  animation: popIn 0.55s cubic-bezier(0.16, 1.14, 0.3, 1.08) forwards;
}

.final-note {
  margin: 0;
  max-width: 38ch;
  text-align: center;
  font-weight: 700;
  line-height: 1.6;
  color: #6c4760;
}

@keyframes pulse {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.18);
  }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

@keyframes fadeRise {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes popIn {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.2) rotate(-16deg);
  }
  70% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.08) rotate(var(--rotate));
  }
  100% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1) rotate(var(--rotate));
  }
}

@keyframes float {
  0%, 100% { transform: translateY(0px); }
  50% { transform: translateY(-10px); }
}

@media (max-width: 540px) {
  body {
    overflow-y: auto;
    overflow-x: hidden;
  }

  .app-shell {
    min-height: 100dvh;
    height: auto;
  }

  .phase {
    position: relative;
    min-height: 100dvh;
    align-items: flex-start;
    padding: 14px 14px 28px;
  }

  .phase.hidden {
    display: none !important;
  }

  .phase.active {
    display: flex;
  }

  .passcode-panel {
    width: min(100%, 400px);
    padding: 20px 16px 18px;
    gap: 14px;
  }

  .avatar {
    width: 92px;
    height: 92px;
  }

  .key {
    min-height: 50px;
    border-radius: 15px;
    font-size: 1.05rem;
  }

  .letter-card {
    padding: 18px 14px 16px;
    border-radius: 28px;
    width: 100%;
    max-height: none;
  }

  .letter-text {
    min-height: 0;
    line-height: 1.65;
    font-size: 0.98rem;
    overflow-wrap: anywhere;
    word-break: break-word;
  }

  .letter-shell {
    width: min(100%, 680px);
    margin: 0 auto;
  }

  .sticker-card {
    padding: 12px 12px 14px;
    border-radius: 28px;
    gap: 12px;
  }

  .sticker-art--small {
    width: min(80vw, 230px);
  }

  .sticker-art--medium {
    width: min(84vw, 275px);
  }

  .sticker-art--large {
    width: min(90vw, 320px);
  }

  .gift-scene,
  .letter-shell,
  .sticker-shell,
  .bouquet-stage {
    width: min(100%, 560px);
  }

  .sticker-caption {
    font-size: 0.96rem;
  }

  .continue-btn {
    padding: 12px 20px;
    font-size: 0.95rem;
  }

  .gift-stack {
    width: min(78vw, 300px);
  }

  .gift-lid {
    top: 86px;
  }
}

@media (max-width: 380px) {
  .phase {
    padding-inline: 10px;
    padding-bottom: 24px;
  }

  .keypad {
    gap: 10px;
  }

  .key {
    min-height: 46px;
    font-size: 1rem;
  }

  .stamp {
    padding: 7px 12px;
    font-size: 0.76rem;
  }

  .letter-header h2 {
    font-size: 1.5rem;
  }

  .sticker-art--small {
    width: min(82vw, 210px);
  }

  .sticker-art--medium {
    width: min(86vw, 255px);
  }

  .sticker-art--large {
    width: min(92vw, 300px);
  }
}