:root {
  --pink: #e21878;
  --pink-deep: #b20d62;
  --card: #f7f1ea;
  --ink: #3c342f;
  --ink-soft: #756b66;
  --love: #d01238;
  --trunk: #7a4e2e;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

html {
  color-scheme: light;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100dvh;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #c01068;
  overscroll-behavior: none;
  touch-action: manipulation;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.sky {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  background:
    radial-gradient(ellipse 70% 42% at 50% 16%, rgba(255, 186, 220, 0.55), transparent 62%),
    radial-gradient(ellipse 120% 90% at 50% 42%, #ff4b9c 0%, var(--pink) 46%, var(--pink-deep) 100%);
}

.orb {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.55);
  filter: blur(2px);
  opacity: 0.55;
}

.orb-1 { width: 140px; height: 140px; left: -30px; top: 8%; opacity: 0.28; filter: blur(8px); }
.orb-2 { width: 90px; height: 90px; right: 6%; top: 12%; opacity: 0.4; }
.orb-3 { width: 180px; height: 180px; right: -50px; bottom: 10%; opacity: 0.22; filter: blur(10px); }
.orb-4 { width: 46px; height: 46px; left: 12%; bottom: 18%; opacity: 0.5; }
.orb-5 { width: 70px; height: 70px; left: 28%; top: 6%; opacity: 0.28; filter: blur(4px); }
.orb-6 { width: 34px; height: 34px; right: 22%; bottom: 8%; background: #ffd0e4; opacity: 0.7; }

.sky-hearts {
  position: absolute;
  inset: -4% -6%;
  width: 112%;
  height: 108%;
  animation: float-bg 16s ease-in-out infinite alternate;
}

.stage {
  position: relative;
  z-index: 1;
  height: 100dvh;
  display: grid;
  place-items: center;
  overflow: hidden;
  padding:
    max(16px, var(--safe-top))
    max(14px, var(--safe-right))
    max(16px, var(--safe-bottom))
    max(14px, var(--safe-left));
}

.card {
  position: relative;
  width: min(920px, 100%);
  height: min(680px, calc(100dvh - 32px - var(--safe-top) - var(--safe-bottom)));
  min-height: 0;
  border-radius: 36px;
  background: var(--card);
  box-shadow:
    0 28px 70px rgba(92, 0, 40, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.75);
  overflow: hidden;
}

.intro,
.finale {
  position: absolute;
  inset: 0;
}

.intro {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  width: 100%;
  margin: 0;
  padding: 24px;
  border: 0;
  background: transparent;
  color: var(--love);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.55s ease, transform 0.55s ease;
}

.intro:focus {
  outline: none;
}

.intro:focus-visible {
  outline: 2px solid var(--love);
  outline-offset: -12px;
}

.intro-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.intro-heart {
  width: clamp(54px, 10vw, 78px);
  height: auto;
  color: #e31b3c;
  filter: drop-shadow(0 8px 10px rgba(180, 20, 50, 0.18));
}

.intro-title {
  color: #c4233c;
  font-family: "Segoe Script", "Apple Chancery", "Snell Roundhand", "Segoe Print", cursive;
  font-size: clamp(32px, 6vw, 52px);
  line-height: 1;
  text-decoration: underline;
  text-underline-offset: 5px;
  text-decoration-thickness: 1.5px;
}

.intro-spark {
  width: 16px;
  height: auto;
  animation: bob 1.5s ease-in-out infinite;
}

.finale {
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.7s ease;
}

.card[data-phase="grow"] .intro,
.card[data-phase="letter"] .intro {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.card[data-phase="grow"] .finale,
.card[data-phase="letter"] .finale {
  opacity: 1;
  visibility: visible;
}

.letter {
  position: absolute;
  z-index: 3;
  left: 6.5%;
  top: 7%;
  bottom: 16%;
  width: min(47%, 40ch);
  display: flex;
  flex-direction: column;
  justify-content: center;
  color: var(--ink);
  font-size: clamp(14px, 1.65vw, 18px);
  line-height: 1.38;
  overflow: auto;
}

.letter p {
  margin: 0 0 0.72em;
}

.letter .sign {
  margin-top: 0.2em;
  margin-bottom: 0;
}

.inline-heart {
  display: inline-block;
  width: 0.95em;
  height: 0.9em;
  margin-left: 0.2em;
  vertical-align: -0.12em;
  color: #ff4d78;
}

.caret {
  display: inline-block;
  width: 1px;
  height: 0.95em;
  margin-left: 2px;
  background: #9a5348;
  vertical-align: -0.08em;
  animation: blink 0.9s steps(1) infinite;
}

.tree {
  position: absolute;
  z-index: 2;
  top: 4%;
  right: 2%;
  bottom: 3%;
  width: 52%;
}

.canopy {
  position: absolute;
  left: -4%;
  right: -4%;
  top: 0;
  height: 88%;
}

.trunk {
  position: absolute;
  left: 50%;
  bottom: 1%;
  width: 28px;
  height: 18%;
  background: linear-gradient(90deg, #a06b3d 0%, #6d4324 46%, #c08a52 100%);
  clip-path: polygon(34% 0, 66% 0, 86% 100%, 14% 100%);
  transform: translateX(-50%) scaleY(0);
  transform-origin: bottom center;
}

.card[data-phase="grow"] .trunk,
.card[data-phase="letter"] .trunk {
  animation: grow-trunk 1.15s cubic-bezier(0.16, 0.84, 0.32, 1) forwards;
}

.leaf {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: var(--s);
  height: var(--s);
  color: var(--c);
  opacity: 0;
  transform: translate(-50%, -50%) rotate(var(--r)) scale(0);
  animation-name: bloom;
  animation-duration: 0.55s;
  animation-timing-function: cubic-bezier(0.18, 1.35, 0.42, 1);
  animation-delay: var(--d);
  animation-fill-mode: forwards;
  animation-play-state: paused;
}

.card[data-phase="grow"] .leaf,
.card[data-phase="letter"] .leaf {
  animation-play-state: running;
}

.leaf.loose {
  animation-name: bloom, fall-away;
  animation-duration: 0.55s, 2.8s;
  animation-delay: var(--d), var(--fall);
  animation-timing-function: cubic-bezier(0.18, 1.35, 0.42, 1), ease-in;
}

.counter {
  position: absolute;
  z-index: 4;
  left: 6.5%;
  right: 48%;
  bottom: 5.5%;
  margin: 0;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.6s ease 0.35s, transform 0.6s ease 0.35s;
}

.card[data-phase="grow"] .counter,
.card[data-phase="letter"] .counter {
  opacity: 1;
  transform: none;
}

.counter-label {
  display: block;
  margin-bottom: 3px;
  color: var(--ink-soft);
  font-size: clamp(12px, 1.7vw, 16px);
}

.counter-value {
  display: flex;
  flex-wrap: wrap;
  gap: 0.12em 0.45em;
  color: #2c2623;
  font-size: clamp(14px, 2.05vw, 20px);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
  line-height: 1.3;
}

.group {
  white-space: nowrap;
}

.num {
  display: inline-block;
  min-width: 2ch;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.num.days {
  min-width: 3ch;
}

.confetti i,
.confetti .heart-bit {
  position: absolute;
  top: var(--top);
  left: var(--left);
  opacity: 0;
  animation: confetti 3.6s ease-in var(--delay) infinite;
}

.confetti i {
  width: var(--w);
  height: var(--h);
  border-radius: 1px;
  background: var(--c);
}

.confetti .heart-bit {
  width: var(--w);
  height: var(--w);
}

.gust {
  position: absolute;
  inset: 0;
  z-index: 2;
  overflow: hidden;
  pointer-events: none;
}

.tree.gusting {
  transform-origin: 50% 100%;
  animation: gust-sway 4.8s cubic-bezier(0.22, 0.7, 0.28, 1) forwards;
}

.gust-heart {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: var(--s);
  height: var(--s);
  color: var(--c);
  opacity: 0;
  pointer-events: none;
  animation: gust-fly var(--dur) cubic-bezier(0.16, 0.55, 0.24, 1) forwards;
}

html.reduce .intro {
  display: none;
}

html.reduce .finale,
html.reduce .counter {
  opacity: 1;
  visibility: visible;
  transform: none;
}

@keyframes float-bg {
  from { transform: translate3d(0, 0, 0); }
  to { transform: translate3d(0, -18px, 0); }
}

@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(7px); }
}

@keyframes blink {
  0%, 45% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

@keyframes grow-trunk {
  from { transform: translateX(-50%) scaleY(0); }
  to { transform: translateX(-50%) scaleY(1); }
}

@keyframes bloom {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) rotate(var(--r)) scale(0);
  }
  100% {
    opacity: 1;
    transform: translate(-50%, -50%) rotate(var(--r)) scale(1);
  }
}

@keyframes fall-away {
  0%, 38% {
    opacity: 1;
    transform: translate(-50%, -50%) rotate(var(--r)) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--dx)), calc(-50% + 120px)) rotate(calc(var(--r) + 50deg)) scale(0.85);
  }
}

@keyframes gust-sway {
  0% { transform: rotate(0deg); }
  14% { transform: rotate(-5deg); }
  32% { transform: rotate(3.4deg); }
  50% { transform: rotate(-2.2deg); }
  68% { transform: rotate(1.15deg); }
  84% { transform: rotate(-0.35deg); }
  100% { transform: rotate(0deg); }
}

@keyframes gust-fly {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) rotate(var(--r)) scale(0.55);
  }
  16% { opacity: 1; }
  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) rotate(var(--spin)) scale(0.8);
  }
}

@keyframes confetti {
  0% {
    opacity: 0;
    transform: translate3d(0, 0, 0) rotate(0deg);
  }
  12% { opacity: 1; }
  100% {
    opacity: 0;
    transform: translate3d(var(--dx), 150px, 0) rotate(var(--spin));
  }
}

@media (max-width: 760px) {
  .card {
    width: 100%;
    height: calc(100dvh - 10px - var(--safe-top) - var(--safe-bottom));
    min-height: 0;
    border-radius: 26px;
  }

  .tree {
    top: 20px;
    right: auto;
    left: 4%;
    width: 92%;
    height: 42%;
    bottom: auto;
  }

  .canopy {
    left: 50%;
    right: auto;
    top: auto;
    bottom: 0;
    width: 100%;
    height: auto;
    aspect-ratio: 1;
    max-height: 100%;
    transform: translateX(-50%);
  }

  .leaf {
    width: calc(var(--s) * 0.78);
    height: calc(var(--s) * 0.78);
  }

  .trunk {
    width: 22px;
    height: 16%;
  }

  .letter {
    left: 7%;
    right: 7%;
    top: calc(43% + 12px);
    bottom: 11%;
    width: auto;
    max-width: none;
    justify-content: flex-start;
    font-size: clamp(13.5px, 3.55vw, 15.5px);
    line-height: 1.32;
  }

  .letter p {
    margin-bottom: 0.48em;
  }

  .counter {
    left: 7%;
    right: 7%;
    bottom: 3.2%;
  }

  .intro-title {
    font-size: clamp(30px, 9vw, 44px);
  }
}

@media (max-width: 760px) and (max-height: 720px) {
  .tree {
    top: 28px;
    height: 33%;
  }

  .letter {
    top: calc(34% + 20px);
    bottom: 12%;
    font-size: 13px;
    line-height: 1.28;
  }

  .letter p {
    margin-bottom: 0.38em;
  }
}

@media (max-height: 700px) and (orientation: landscape) {
  .card {
    height: calc(100dvh - 16px - var(--safe-top) - var(--safe-bottom));
    min-height: 0;
  }

  .letter {
    font-size: 13px;
    line-height: 1.28;
    bottom: 18%;
    overflow: auto;
  }

  .letter p {
    margin-bottom: 0.35em;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sky-hearts,
  .intro-spark,
  .leaf,
  .trunk,
  .caret,
  .confetti i,
  .confetti .heart-bit,
  .tree.gusting,
  .gust-heart {
    animation: none !important;
  }

  .leaf {
    opacity: 1 !important;
    transform: translate(-50%, -50%) rotate(var(--r)) scale(1) !important;
  }

  .trunk {
    transform: translateX(-50%) scaleY(1) !important;
  }

  .caret {
    display: none;
  }
}
