:root {
  color-scheme: dark;
  --night: #061126;
  --night-soft: #0b2040;
  --gold: #ffd84a;
  --gold-soft: #fff1a6;
  --ink: #faf7ee;
  --muted: #bdc9d9;
}

* { box-sizing: border-box; }

html {
  min-height: 100%;
  background: var(--night);
}

body {
  min-height: 100svh;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 50% 56%, rgba(255, 212, 58, 0.13), transparent 24rem),
    radial-gradient(circle at 15% 10%, rgba(45, 93, 151, 0.35), transparent 22rem),
    linear-gradient(160deg, var(--night-soft) 0%, var(--night) 58%, #030815 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.32;
  background-image:
    radial-gradient(circle, rgba(255,255,255,0.82) 0 1px, transparent 1.5px),
    radial-gradient(circle, rgba(255,222,97,0.66) 0 1px, transparent 1.5px);
  background-position: 1rem 2rem, 5rem 8rem;
  background-size: 9rem 9rem, 13rem 13rem;
  mask-image: linear-gradient(to bottom, black, transparent 76%);
}

main {
  position: relative;
  z-index: 1;
  width: min(100%, 38rem);
  min-height: 100svh;
  margin: 0 auto;
  padding: max(1.35rem, env(safe-area-inset-top)) 1rem max(1.25rem, env(safe-area-inset-bottom));
  display: grid;
  grid-template-rows: auto minmax(25rem, 1fr) auto;
  align-items: center;
  text-align: center;
}

h1 {
  margin: 0.35rem 0 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2.65rem, 12vw, 5.1rem);
  font-weight: 400;
  letter-spacing: -0.055em;
  line-height: 0.95;
  text-wrap: balance;
}

h1 span {
  display: block;
  color: var(--gold);
  font-style: italic;
  text-shadow: 0 0 2rem rgba(255, 211, 61, 0.24);
}

.dedication {
  max-width: 29rem;
  margin: 0 auto;
  padding: 0.4rem 0.75rem 0.3rem;
  color: #f8f3e5;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.08rem, 4.5vw, 1.32rem);
  font-style: italic;
  line-height: 1.5;
  text-wrap: balance;
  text-shadow: 0 0.55rem 1.6rem rgba(0, 0, 0, 0.4);
}

.flower-stage {
  position: relative;
  align-self: stretch;
  width: 100%;
  min-height: 26rem;
  border: 0;
  padding: 0;
  overflow: hidden;
  color: inherit;
  background: transparent;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  isolation: isolate;
}

.flower-stage::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 12%;
  width: min(78vw, 26rem);
  aspect-ratio: 1.8;
  border-radius: 50%;
  z-index: -1;
  transform: translateX(-50%);
  background: radial-gradient(ellipse, rgba(255, 214, 65, 0.2), rgba(255, 214, 65, 0.05) 52%, transparent 72%);
  filter: blur(0.75rem);
  animation: glow 4s ease-in-out infinite;
}

.flower-stage:focus-visible {
  outline: 2px solid var(--gold-soft);
  outline-offset: -0.25rem;
  border-radius: 1.5rem;
}

#flower-canvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 26rem;
}

.stage-hint {
  position: absolute;
  left: 50%;
  bottom: 0.25rem;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  width: max-content;
  max-width: calc(100% - 2rem);
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  pointer-events: none;
}

.stage-hint::before {
  content: "";
  width: 0.42rem;
  height: 0.42rem;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 0 0 rgba(255, 216, 74, 0.45);
  animation: pulse 2s infinite;
}

.spark {
  position: fixed;
  z-index: 5;
  width: 0.42rem;
  height: 0.42rem;
  border-radius: 50%;
  pointer-events: none;
  background: var(--gold-soft);
  box-shadow: 0 0 0.8rem var(--gold);
  animation: scatter 1s ease-out forwards;
}

.flower-stage.failed canvas { display: none; }

.flower-stage.failed::after {
  content: "No se pudo abrir la animación. Actualiza la página para intentarlo otra vez.";
  position: absolute;
  inset: 35% 1.5rem auto;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.5;
}

@keyframes glow {
  0%, 100% { transform: translateX(-50%) scale(0.92); opacity: 0.7; }
  50% { transform: translateX(-50%) scale(1.06); opacity: 1; }
}

@keyframes pulse {
  70% { box-shadow: 0 0 0 0.55rem rgba(255, 217, 74, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 217, 74, 0); }
}

@keyframes scatter {
  from { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  to { opacity: 0; transform: translate(calc(-50% + var(--x)), calc(-50% + var(--y))) scale(0); }
}

@media (max-height: 740px) {
  main { grid-template-rows: auto minmax(20rem, 1fr) auto; }
  .flower-stage, #flower-canvas { min-height: 20rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }
}
