:root {
  color-scheme: light;
  --paper: #fff0f4;
  --ink: #632537;
  --berry: #d92353;
  --sprite-size: clamp(138px, 40vw, 224px);
  --boy-x: 50%;
  font-family: ui-rounded, "Arial Rounded MT Bold", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  -webkit-text-size-adjust: 100%;
}

* { box-sizing: border-box; }

html {
  min-width: 280px;
  min-height: 100%;
  background: var(--paper);
}

body {
  margin: 0;
  min-height: 100svh;
  min-height: 100dvh;
  color: var(--ink);
  background: radial-gradient(ellipse at 50% 46%, #fff9fa 0%, #fff4f7 38%, var(--paper) 78%);
}

button { font: inherit; }

.page {
  display: grid;
  place-items: center;
  min-height: 100svh;
  min-height: 100dvh;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  overflow: hidden;
}

.story {
  position: relative;
  width: min(100%, 760px);
  height: clamp(340px, 78svh, 640px);
  isolation: isolate;
}

.scene {
  position: absolute;
  top: 50%;
  left: 0;
  width: 100%;
  height: var(--sprite-size);
  transform: translateY(-50%);
}

.heart-anchor {
  position: absolute;
  left: 50%;
  top: 50%;
  width: clamp(172px, 50vw, 206px);
  aspect-ratio: 256 / 244;
  transform: translate(-50%, -50%);
  z-index: 3;
  transition: opacity 180ms ease, scale 200ms cubic-bezier(.4, 0, .2, 1);
}

.heart-button {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: none;
  color: white;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  animation: heartbeat 2.4s ease-in-out infinite;
  transform-origin: 50% 55%;
}

.heart-shape {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
  filter: drop-shadow(0 12px 18px #db265328) drop-shadow(0 3px 2px #b5103020);
  transition: filter 160ms ease;
}

.heart-label {
  position: absolute;
  inset: 31% 12% auto;
  font-size: 1.0625rem;
  font-weight: 850;
  line-height: 1.38;
  letter-spacing: .06em;
  text-align: center;
  text-shadow: 0 1px 2px #9d003630;
}

.heart-button:focus-visible {
  outline: 3px solid #8a143a;
  outline-offset: 12px;
  border-radius: 50%;
}

.heart-button:active { scale: .93; }

@media (hover: hover) {
  .heart-button:hover .heart-shape { filter: drop-shadow(0 14px 23px #db265340); }
}

.actor-anchor {
  position: absolute;
  width: var(--sprite-size);
  height: var(--sprite-size);
  top: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  opacity: 0;
  transition: opacity 160ms ease;
}

.boy-anchor { left: var(--boy-x); z-index: 2; }
.girl-anchor { left: 84%; z-index: 1; }
.couple-anchor { left: 77%; z-index: 2; }

.sprite {
  width: 100%;
  height: 100%;
  background-image: url("assets/us.png");
  background-size: 400% 200%;
  background-repeat: no-repeat;
  transform-origin: 50% 94%;
  filter: drop-shadow(0 5px 3px #53231a0b);
}

.boy-sprite { background-position: 0% 0%; }
.girl-sprite { background-position: 0% 100%; }
.couple-sprite { background-position: 66.666667% 100%; }
.hug-motion { width: 100%; height: 100%; transform-origin: 50% 94%; }

.love-burst {
  position: absolute;
  top: 43%;
  left: 77%;
  width: 0;
  height: 0;
  pointer-events: none;
  z-index: 0;
}

.little-heart {
  position: absolute;
  color: #e13b67;
  font-size: 1.125rem;
  line-height: 1;
  opacity: 0;
}

.little-heart:nth-child(2n) { font-size: .875rem; color: #f07d98; }

.dedication {
  position: absolute;
  top: calc(50% + var(--sprite-size) / 2 + 24px);
  left: 0;
  width: 100%;
  margin: 0;
  padding: 0 8px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.875rem, 7.8vw, 2.875rem);
  font-style: italic;
  font-weight: 400;
  line-height: 1.22;
  letter-spacing: -.025em;
  text-align: center;
  opacity: 0;
  transform: translateY(9px);
  transition: opacity 800ms ease, transform 800ms ease;
}

.dedication span { color: var(--berry); }

.story[data-state="revealing"] .heart-anchor,
.story[data-state="running"] .heart-anchor,
.story[data-state="hugging"] .heart-anchor,
.story[data-state="done"] .heart-anchor {
  opacity: 0;
  scale: .65;
  pointer-events: none;
}

.story[data-state="revealing"] .heart-button,
.story[data-state="running"] .heart-button,
.story[data-state="hugging"] .heart-button,
.story[data-state="done"] .heart-button { animation: none; }

.story.people-visible[data-state="revealing"] .boy-anchor,
.story.people-visible[data-state="revealing"] .girl-anchor,
.story[data-state="running"] .boy-anchor,
.story[data-state="running"] .girl-anchor { opacity: 1; }

.story[data-state="hugging"] .couple-anchor,
.story[data-state="done"] .couple-anchor { opacity: 1; }

.story[data-state="hugging"] .hug-motion { animation: happy-hug 1600ms cubic-bezier(.36, 0, .3, 1) 1 both; }
.story.celebrating .little-heart { animation: love-burst 1200ms ease-out 1 both; animation-delay: var(--delay); }
.story.love-visible .dedication { opacity: 1; transform: translateY(0); }

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

.error-message,
.no-script {
  position: absolute;
  top: calc(50% + 120px);
  left: 0;
  width: 100%;
  padding: 0 16px;
  font-size: 1rem;
  line-height: 1.5;
  text-align: center;
}

.error-message[hidden] { display: none; }

@keyframes heartbeat {
  0%, 45%, 100% { transform: scale(1) rotate(-3deg); }
  12% { transform: scale(1.065) rotate(-3deg); }
  23% { transform: scale(1) rotate(-3deg); }
  33% { transform: scale(1.035) rotate(-3deg); }
}

@keyframes happy-hug {
  0% { transform: scale(.97) rotate(-2deg); }
  18% { transform: translateY(-6px) scale(1.035) rotate(2deg); }
  35% { transform: translateY(0) scale(1.015) rotate(-2deg); }
  55% { transform: translateY(-4px) scale(1.05) rotate(2deg); }
  75% { transform: translateY(0) scale(1.015) rotate(-1deg); }
  100% { transform: none; }
}

@keyframes love-burst {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.3); }
  17% { opacity: .85; }
  65% { opacity: .7; }
  100% { opacity: 0; transform: translate(var(--x), var(--y)) scale(1.15) rotate(var(--turn)); }
}

@media (max-height: 580px) {
  :root { --sprite-size: 138px; }
  .story { height: max(300px, calc(100svh - 32px)); }
  .scene { top: 40%; }
  .dedication { top: calc(40% + var(--sprite-size) / 2 + 14px); font-size: 1.875rem; }
  .heart-anchor { width: 158px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; }
  .heart-anchor, .actor-anchor, .dedication { transition-duration: 120ms; }
  .dedication { transform: none; }
  .little-heart { display: none; }
}
