:root {
  --blush: #f9dbe2;
  --blush-2: #fdeceb;
  --cream: #fffaf2;
  --rose: #b03a5e;
  --rose-soft: rgba(176, 58, 94, 0.72);
  --ink: #4a2531;
  --gold: #e3a81f;
  --gutter: 16px;
}

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

html, body { height: 100%; background: var(--cream); color: var(--ink); }

body {
  font-family: "Lora", Georgia, serif;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

main {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(80% 50% at 50% 38%, rgba(255, 255, 255, 0.7), transparent 70%),
    linear-gradient(165deg, var(--blush) 0%, var(--blush-2) 45%, var(--cream) 100%);
}

.hand { font-family: "Dancing Script", cursive; }

/* ---------- screens + crossfade ---------- */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding:
    max(var(--gutter), env(safe-area-inset-top))
    max(var(--gutter), env(safe-area-inset-right))
    max(var(--gutter), env(safe-area-inset-bottom))
    max(var(--gutter), env(safe-area-inset-left));
  opacity: 0;
  visibility: hidden;
  transition: opacity 1s ease, visibility 0s linear 1s;
}
.screen.active {
  opacity: 1;
  visibility: visible;
  transition: opacity 1.3s ease 0.45s, visibility 0s;
}
/* the burst should be seen right away */
#letter.active { transition: opacity 0.5s ease, visibility 0s; }

.center { display: flex; flex-direction: column; align-items: center; text-align: center; }

/* ---------- 1. welcome ---------- */
h1 {
  font-size: clamp(3.1rem, 15vw, 5rem);
  font-weight: 600;
  line-height: 1.1;
  color: var(--rose);
}
.sub {
  margin-top: 1rem;
  font-family: "Playfair Display", Georgia, serif;
  font-style: italic;
  font-size: clamp(1.2rem, 5.4vw, 1.5rem);
  color: var(--rose-soft);
}
.btn {
  margin-top: 3.4rem;
  font: 500 1rem "Lora", Georgia, serif;
  letter-spacing: 0.3em;
  padding: 0.85em 2.2em 0.85em 2.5em;
  color: var(--rose);
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid rgba(176, 58, 94, 0.35);
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(176, 58, 94, 0.12), inset 0 -2px 0 rgba(227, 168, 31, 0.35);
  cursor: pointer;
  transition: background 0.4s, border-color 0.4s, transform 0.3s;
}
.btn:hover, .btn:focus-visible { background: #fff; border-color: var(--rose); outline: none; }
.btn:active { transform: scale(0.97); }

.fade { opacity: 0; animation: fadeUp 2.2s ease forwards; }
.f1 { animation-delay: 0.6s; }
.f2 { animation-delay: 2.4s; }
.f3 { animation-delay: 4.3s; }
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); visibility: hidden; }
  1%   { visibility: visible; }
  to   { opacity: 1; transform: none; visibility: visible; }
}

/* ---------- 2. password ---------- */
h2 {
  font-family: "Playfair Display", Georgia, serif;
  font-style: italic;
  font-weight: 400;
  font-size: clamp(1.9rem, 8.5vw, 2.5rem);
  color: var(--rose);
}
.code { position: relative; margin-top: 2.4rem; }
.digits { display: flex; gap: clamp(14px, 5vw, 22px); }
.digit {
  width: clamp(60px, 18vw, 76px);
  height: clamp(72px, 22vw, 90px);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 18px;
  border: 1.5px solid rgba(176, 58, 94, 0.22);
  background: rgba(255, 255, 255, 0.65);
  box-shadow: 0 6px 18px rgba(176, 58, 94, 0.08);
  font-family: "Playfair Display", Georgia, serif;
  font-size: clamp(2.2rem, 10vw, 2.8rem);
  font-variant-numeric: lining-nums tabular-nums;
  color: var(--rose);
  transition: border-color 0.3s, box-shadow 0.3s, color 0.3s;
}
.digit.current { border-color: rgba(176, 58, 94, 0.7); box-shadow: 0 0 0 4px rgba(176, 58, 94, 0.08); }
.code.ok .digit { border-color: var(--gold); color: var(--gold); box-shadow: 0 0 0 4px rgba(227, 168, 31, 0.15); }

/* the real input sits invisibly on top of the boxes */
#code {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  border: 0;
  background: transparent;
  color: transparent;
  caret-color: transparent;
  font-size: 16px; /* stops iOS zoom on focus */
  z-index: 2;
}

.code.shake { animation: shake 0.5s ease; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-9px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(3px); }
}
.msg {
  margin-top: 1.5rem;
  min-height: 1.5em;
  font-style: italic;
  font-size: 1.1rem;
  color: var(--rose-soft);
  opacity: 0;
  transition: opacity 0.5s ease;
}
.msg.show { opacity: 1; }

/* ---------- 3. letter ---------- */
#flowers { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.card {
  position: relative;
  z-index: 1;
  width: min(35rem, 100%);
  max-height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: clamp(28px, 7vw, 52px) clamp(22px, 7vw, 52px);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.62);
  -webkit-backdrop-filter: blur(16px) saturate(130%);
  backdrop-filter: blur(16px) saturate(130%);
  border: 1px solid rgba(255, 255, 255, 0.8);
  box-shadow: 0 24px 60px rgba(176, 58, 94, 0.16);
  opacity: 0;
  transform: translateY(14px) scale(0.985);
  transition: opacity 1.8s ease, transform 1.8s ease;
  pointer-events: none;
  scrollbar-width: thin;
  scrollbar-color: rgba(176, 58, 94, 0.25) transparent;
}
.card.show { opacity: 1; transform: none; pointer-events: auto; }

.card p {
  font-size: clamp(18px, 4.8vw, 20px);
  line-height: 1.8;
  color: var(--ink);
  margin-bottom: 1.2em;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 1.5s ease, transform 1.5s ease;
}
.card.show p { opacity: 1; transform: none; }

.card .greet {
  font-size: clamp(2.1rem, 9vw, 2.6rem);
  line-height: 1.2;
  color: var(--rose);
  margin-bottom: 0.6em;
}
.card .closing {
  font-size: clamp(1.6rem, 7vw, 1.9rem);
  line-height: 1.3;
  color: var(--rose-soft);
  margin: 1.4em 0 0.1em;
  padding-top: 1em;
  border-top: 1px solid rgba(227, 168, 31, 0.45);
  width: 5.5em;
}
.card .sign {
  font-size: clamp(2.3rem, 10vw, 2.8rem);
  line-height: 1.2;
  color: var(--rose);
  margin-bottom: 0;
}

.music {
  position: absolute;
  z-index: 2;
  right: max(var(--gutter), env(safe-area-inset-right));
  bottom: max(var(--gutter), env(safe-area-inset-bottom));
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid rgba(176, 58, 94, 0.3);
  background: rgba(255, 255, 255, 0.7);
  color: var(--rose);
  font-size: 1.2rem;
  cursor: pointer;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.music.playing { border-color: var(--gold); color: var(--gold); }

@media (prefers-reduced-motion: reduce) {
  .fade { animation-duration: 3.5s; }
  .card { transition-duration: 3s; }
  .card p { transition-duration: 2.5s; }
  .card, .card p { transform: none; }
}
