:root {
  --bg-1: #1a0710;
  --bg-2: #3b0a1f;
  --rose: #ff5c8a;
  --rose-soft: #ffb3c7;
  --gold: #ffd9a0;
  --text: #fff4f7;
  --muted: rgba(255, 228, 236, 0.62);
  --script: "Great Vibes", cursive;
  --serif: "Cormorant Garamond", "Noto Serif", Georgia, serif;
  --sans: "Segoe UI", "Noto Sans", "Nirmala UI", "Leelawadee UI", "Microsoft YaHei",
    "Yu Gothic", "Malgun Gothic", "Ebrima", "Gadugi", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  background: radial-gradient(ellipse at 50% 35%, var(--bg-2) 0%, var(--bg-1) 70%) fixed;
  background-color: var(--bg-1);
  color: var(--text);
  font-family: var(--serif);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

#root { height: 100%; }

.app {
  position: relative;
  height: 100%;
  height: 100dvh;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  justify-content: safe center; /* don't clip the top when content is taller */
  padding: 16px;
  gap: clamp(8px, 2vh, 24px);
}

/* ---------- floating background hearts ---------- */
.floaters {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
}
.floater {
  position: absolute;
  bottom: -40px;
  color: var(--rose);
  opacity: 0;
  animation: float-up linear infinite;
}
@keyframes float-up {
  0%   { transform: translateY(0) rotate(0deg); opacity: 0; }
  10%  { opacity: 0.35; }
  90%  { opacity: 0.2; }
  100% { transform: translateY(-110vh) rotate(25deg); opacity: 0; }
}

/* ---------- intro ---------- */
.intro {
  position: relative;
  z-index: 1;
  text-align: center;
  animation: fade-in 1.2s ease both;
}
.intro h1 {
  font-family: var(--script);
  font-weight: 400;
  font-size: clamp(2.6rem, 9vw, 5.5rem);
  margin: 0;
  color: var(--rose-soft);
  text-shadow: 0 0 24px rgba(255, 92, 138, 0.55);
  line-height: 1.1;
}
.intro p {
  font-size: clamp(1rem, 3.4vw, 1.35rem);
  color: var(--muted);
  font-style: italic;
  margin: 12px 0 32px;
}
.for-name {
  font-family: var(--script);
  font-size: clamp(1.6rem, 5vw, 2.4rem);
  color: var(--gold);
  margin-bottom: 8px;
}

.btn {
  font-family: var(--serif);
  font-size: 1.15rem;
  letter-spacing: 0.04em;
  color: var(--text);
  background: linear-gradient(135deg, #ff5c8a, #c2185b);
  border: none;
  border-radius: 999px;
  padding: 12px 32px;
  cursor: pointer;
  box-shadow: 0 6px 24px rgba(255, 92, 138, 0.4);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.btn:hover { transform: translateY(-2px) scale(1.03); box-shadow: 0 10px 30px rgba(255, 92, 138, 0.55); }
.btn:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }

.btn-ghost {
  font-family: var(--sans);
  font-size: 0.85rem;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 179, 199, 0.25);
  border-radius: 999px;
  padding: 6px 14px;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}
.btn-ghost:hover { background: rgba(255, 92, 138, 0.18); color: var(--text); }
.btn-ghost:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* ---------- heart stage ---------- */
.stage {
  position: relative;
  z-index: 1;
  flex-shrink: 0;
}
.stage.beating { animation: heartbeat 1.4s ease-in-out infinite; }

@keyframes heartbeat {
  0%, 100% { transform: scale(1); }
  14%      { transform: scale(1.06); }
  28%      { transform: scale(1); }
  42%      { transform: scale(1.04); }
  70%      { transform: scale(1); }
}

.word,
.filler {
  position: absolute;
  white-space: nowrap;
  line-height: 1;
  transform: translate(-50%, -50%);
  user-select: none;
}
.word {
  color: var(--rose-soft);
  opacity: 0.88;
  animation: word-in 0.9s cubic-bezier(0.2, 0.8, 0.2, 1) both;
  text-shadow: 0 0 6px rgba(255, 92, 138, 0.5);
}
.finale-word {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-weight: 600;
  color: #fff;
  opacity: 1;
  text-shadow: 0 0 10px var(--rose), 0 0 22px var(--rose);
  animation-duration: 1.6s;
}
.stage.done .word.finale-word { color: #fff; opacity: 1; }
.filler {
  color: var(--rose);
  font-size: 0.85em;
  animation: filler-in 0.5s ease both;
  text-shadow: 0 0 6px rgba(255, 92, 138, 0.7);
}
@keyframes filler-in {
  from { opacity: 0; transform: translate(-50%, -50%) scale(0.2); }
  to   { opacity: 0.9; transform: translate(-50%, -50%) scale(1); }
}
.word.current {
  color: #fff;
  opacity: 1;
  text-shadow: 0 0 10px var(--rose), 0 0 22px var(--rose);
}
.stage.done .word {
  color: #ffd0dc;
  opacity: 0.95;
}

@keyframes word-in {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(2.4); filter: blur(6px); }
  60%  { opacity: 1; filter: blur(0); }
  100% { transform: translate(-50%, -50%) scale(1); }
}

/* ---------- caption ---------- */
.caption {
  position: relative;
  z-index: 1;
  text-align: center;
  min-height: 7.5em;
  max-width: 92vw;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
}
.caption .lang {
  font-family: var(--serif);
  text-transform: uppercase;
  letter-spacing: 0.28em;
  font-size: clamp(0.72rem, 2.4vw, 0.9rem);
  color: var(--gold);
}
.caption .phrase {
  font-family: var(--sans);
  font-size: clamp(1.4rem, 5.5vw, 2.6rem);
  margin: 6px 0 4px;
  text-shadow: 0 0 18px rgba(255, 92, 138, 0.6);
  overflow-wrap: anywhere;
}
.caption .roman {
  font-style: italic;
  color: var(--muted);
  font-size: clamp(0.9rem, 3vw, 1.1rem);
  min-height: 1.3em;
}
.caption .phrase-anim { animation: fade-in 0.6s ease both; }

.finale {
  font-family: var(--script);
  font-size: clamp(1.9rem, 6.5vw, 3.4rem);
  color: var(--rose-soft);
  text-shadow: 0 0 24px rgba(255, 92, 138, 0.6);
  line-height: 1.2;
  animation: fade-in 1.6s ease both;
}

.controls {
  position: relative;
  z-index: 1;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
}
.counter {
  font-family: var(--sans);
  font-size: 0.8rem;
  color: var(--muted);
  min-width: 4.5em;
  text-align: center;
}

.progress {
  position: fixed;
  left: 0;
  top: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--rose), var(--gold));
  box-shadow: 0 0 10px var(--rose);
  transition: width 0.4s ease;
  z-index: 2;
}

/* ---------- tap-to-read heart ---------- */
.stage-button {
  position: relative;
  z-index: 1;
  padding: 0;
  border: none;
  background: none;
  color: inherit;
  font: inherit;
  cursor: zoom-in;
  border-radius: 12px;
}
.stage-button:disabled { cursor: default; }
.stage-button:focus-visible { outline: 2px solid var(--gold); outline-offset: 6px; }

.zoom-cta {
  position: relative;
  z-index: 1;
  margin-top: -4px;
  padding: 8px 14px;
  border: none;
  background: none;
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.95rem;
  color: var(--gold);
  text-decoration: underline dotted;
  text-underline-offset: 4px;
  cursor: pointer;
  animation: fade-in 1s ease 0.6s both;
}

.zoom-overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: radial-gradient(ellipse at 50% 40%, var(--bg-2) 0%, var(--bg-1) 75%);
  animation: overlay-in 0.35s ease both;
}
.zoom-hint {
  position: absolute;
  top: 18px;
  left: 0;
  right: 0;
  margin: 0;
  text-align: center;
  font-style: italic;
  color: var(--muted);
  pointer-events: none;
  z-index: 1;
}
.zoom-scroll {
  position: absolute;
  inset: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
.zoom-inner {
  width: max-content;
  min-width: 100%;
  min-height: 100%;
  padding: 64px 24px 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.zoom-inner .stage { animation: none; }
.zoom-overlay .letter-close { position: fixed; z-index: 2; }

/* ---------- music toggle ---------- */
.music-toggle {
  position: fixed;
  top: 14px;
  left: 16px;
  z-index: 5;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid rgba(255, 179, 199, 0.3);
  background: rgba(255, 255, 255, 0.06);
  color: var(--rose-soft);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.2s ease;
}
.music-toggle:hover { background: rgba(255, 92, 138, 0.22); }
.music-toggle:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.music-note-playing { animation: note-bob 1.6s ease-in-out infinite; }
@keyframes note-bob {
  0%, 100% { transform: translateY(0) rotate(0); }
  50%      { transform: translateY(-3px) rotate(-8deg); }
}
.music-slash {
  position: absolute;
  width: 26px;
  height: 2px;
  background: var(--rose-soft);
  transform: rotate(-45deg);
  border-radius: 2px;
}

/* ---------- letter ---------- */
.controls-finale { gap: 14px; }
.btn-letter { animation: letter-nudge 2.4s ease-in-out 1.2s infinite; }
@keyframes letter-nudge {
  0%, 100% { transform: translateY(0); }
  8%       { transform: translateY(-4px) rotate(-2deg); }
  16%      { transform: translateY(0) rotate(2deg); }
  24%      { transform: translateY(0) rotate(0); }
}

.letter-overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(15, 3, 8, 0.78);
  backdrop-filter: blur(6px);
  animation: overlay-in 0.4s ease both;
}
@keyframes overlay-in { from { opacity: 0; } to { opacity: 1; } }

.letter-close {
  position: absolute;
  top: 14px;
  right: 18px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid rgba(255, 179, 199, 0.3);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
}
.letter-close:hover { background: rgba(255, 92, 138, 0.25); }
.letter-close:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

.letter-scene {
  perspective: 1200px;
  display: flex;
  justify-content: center;
  width: 100%;
}

.envelope {
  --env-w: min(360px, 86vw);
  position: relative;
  width: var(--env-w);
  height: calc(var(--env-w) * 0.64);
  border: none;
  padding: 0;
  background: none;
  cursor: pointer;
  animation: env-drop 0.7s cubic-bezier(0.2, 0.9, 0.3, 1.2) both;
  filter: drop-shadow(0 18px 30px rgba(0, 0, 0, 0.45));
}
.envelope:focus-visible { outline: 2px solid var(--gold); outline-offset: 6px; border-radius: 6px; }
.envelope:not(.open):hover { transform: translateY(-4px) rotate(-1deg); transition: transform 0.25s ease; }
@keyframes env-drop {
  from { opacity: 0; transform: translateY(-40px) rotate(-6deg) scale(0.9); }
  to   { opacity: 1; transform: none; }
}

.envelope > span { position: absolute; display: block; }
.env-back {
  inset: 0;
  background: #b83a5e;
  border-radius: 6px;
}
.env-paper {
  left: 7%;
  right: 7%;
  top: 8%;
  height: 84%;
  background: #fff8ef;
  border-radius: 4px;
  z-index: 1;
  transition: transform 0.6s ease 0.35s;
}
.envelope.open .env-paper { transform: translateY(-42%); }
.env-front {
  inset: 0;
  z-index: 2;
  background: linear-gradient(160deg, #e66b8f, #cf4a72);
  clip-path: polygon(0 0, 50% 56%, 100% 0, 100% 100%, 0 100%);
  border-radius: 6px;
}
.env-flap {
  left: 0;
  right: 0;
  top: 0;
  height: 60%;
  z-index: 3;
  background: linear-gradient(180deg, #f07c9d, #d4567c);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  transform-origin: top center;
  transition: transform 0.5s ease, z-index 0s linear 0.25s;
}
.envelope.open .env-flap { transform: rotateX(180deg); z-index: 0; }
.env-seal {
  left: 50%;
  top: 60%;
  z-index: 4;
  width: 46px;
  height: 46px;
  margin: -23px 0 0 -23px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ff8fb0, #a3123f);
  color: #ffe3ec;
  font-size: 22px;
  line-height: 46px;
  text-align: center;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.35);
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.envelope.open .env-seal { opacity: 0; transform: scale(0.4); }
.env-hint {
  left: 0;
  right: 0;
  bottom: -2.2em;
  z-index: 4;
  font-family: var(--serif);
  font-style: italic;
  font-size: 1rem;
  color: var(--muted);
  text-align: center;
}

.letter-paper {
  position: relative;
  width: min(560px, 100%);
  max-height: 82vh;
  overflow-y: auto;
  padding: clamp(24px, 6vw, 48px) clamp(20px, 6vw, 52px);
  background: linear-gradient(180deg, #fffaf3, #fbefe4);
  color: #4a1426;
  border-radius: 6px;
  box-shadow: 0 30px 60px rgba(0, 0, 0, 0.5), inset 0 0 40px rgba(194, 24, 91, 0.06);
  font-family: var(--serif);
  font-size: clamp(1.05rem, 3.6vw, 1.25rem);
  line-height: 1.6;
  animation: paper-unfold 0.8s cubic-bezier(0.2, 0.8, 0.2, 1) both;
  transform-origin: top center;
}
@keyframes paper-unfold {
  from { opacity: 0; transform: translateY(60px) rotateX(-35deg) scale(0.92); }
  to   { opacity: 1; transform: none; }
}
.letter-paper p { margin: 0 0 1em; }
.letter-greeting,
.letter-signature {
  font-family: var(--script);
  font-size: 2.1em;
  line-height: 1.2;
  color: #a3123f;
}
.letter-body,
.letter-closing,
.letter-signature { animation: fade-in 0.8s ease both; }
.letter-closing { margin-top: 1.4em !important; font-style: italic; animation-delay: 2.3s; }
.letter-signature { margin: 0 !important; animation-delay: 2.6s; }

@keyframes fade-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---------- phones ---------- */
@media (max-width: 600px) {
  .app {
    padding: 56px 8px 16px;
    gap: 10px;
  }
  .caption { min-height: 6.5em; }
  .caption .phrase { font-size: clamp(1.25rem, 7vw, 1.8rem); }
  .btn-ghost {
    min-height: 44px;
    padding: 10px 18px;
    font-size: 0.95rem;
  }
  .btn { padding: 12px 26px; }
  .controls { gap: 10px; }
  .controls-finale { flex-direction: column; gap: 10px; }
  .finale { font-size: clamp(1.7rem, 8.5vw, 2.4rem); }
  .letter-overlay { align-items: flex-end; padding: 64px 10px 10px; }
  .letter-paper { max-height: calc(100dvh - 80px); }
  .music-toggle, .letter-close { width: 44px; height: 44px; }
}

/* Short screens (landscape phones): let the page scroll instead of clipping. */
@media (max-height: 560px) {
  .app { justify-content: flex-start; padding-top: 56px; }
}

@media (prefers-reduced-motion: reduce) {
  .floater, .stage.beating, .btn-letter { animation: none; }
  .letter-paper, .letter-paper p, .envelope { animation-duration: 0.01s !important; animation-delay: 0s !important; }
  .word, .filler { animation-duration: 0.01s; }
}
