:root {
  --ink: #221c18;
  --blood: #8a0f16;
  --wax: #7c0d13;
  --parchment: #efe7da;
  --parchment-dim: #b9ab98;
  --night: #0b0807;
  --ember: #d96a2b;
  --serif: 'Cormorant Garamond', 'Cormorant', Georgia, serif;
  --script: 'Pinyon Script', 'Snell Roundhand', cursive;
  --ease-out: cubic-bezier(.16, .8, .2, 1);
  color-scheme: dark;
}

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

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--night);
  color: var(--parchment);
  font-family: var(--serif);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body:not(.is-open) { overflow: hidden; height: 100svh; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ───────── Backdrop: the art itself, blurred into candle-lit darkness ───────── */

.backdrop {
  position: fixed;
  inset: -10%;
  background: var(--night) url('../assets/art-clean.webp') center / cover no-repeat;
  filter: blur(28px) brightness(.17) saturate(.8);
  opacity: .35;
  transition: opacity 3s ease;
}

.is-open .backdrop { opacity: 1; }

/* ───────── Hero art ───────── */

.hero {
  position: relative;
  min-height: 100vh;
  min-height: 100svh;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.art {
  position: relative;
  width: min(104vw, 100svh * 2 / 3);
  aspect-ratio: 2 / 3;
  container-type: inline-size;
  touch-action: manipulation;
}

.art__canvas,
.art__still,
.art__ornaments,
.copy {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.art__still {
  opacity: 0;
  mask-image: radial-gradient(75% 70% at 50% 45%, #000 60%, transparent 100%);
  -webkit-mask-image: radial-gradient(75% 70% at 50% 45%, #000 60%, transparent 100%);
  transition: opacity 1.6s ease;
}

.no-webgl .art__still { opacity: 1; }

.art__ornaments {
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.6;
  stroke-linecap: round;
  pointer-events: none;
}

.draw {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  transition: stroke-dashoffset 1.8s ease-in-out var(--d);
}

.is-revealed .draw { stroke-dashoffset: 0; }

/* ───────── Live typography over the art ───────── */

.copy {
  color: var(--ink);
  font-variant-numeric: lining-nums;
  pointer-events: none;
}

.line {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(var(--y) / 1536 * 100%);
  margin: 0;
  text-align: center;
  white-space: nowrap;
  line-height: 1;
  font-size: calc(var(--size) * 1cqw);
  letter-spacing: var(--ls, 0);
  padding-left: var(--ls, 0);
  opacity: 0;
  filter: blur(8px);
  transform: translateY(-50%) translateY(.4em);
  transition:
    opacity 1.4s ease var(--d),
    filter 1.6s ease var(--d),
    transform 1.8s var(--ease-out) var(--d),
    letter-spacing 2.4s var(--ease-out) var(--d),
    padding-left 2.4s var(--ease-out) var(--d);
}

.caps {
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: calc(var(--ls) * 2.4);
  padding-left: calc(var(--ls) * 2.4);
}

.caps--date { font-weight: 500; }

.is-revealed .line {
  opacity: 1;
  filter: blur(0);
  transform: translateY(-50%);
  letter-spacing: var(--ls, 0);
  padding-left: var(--ls, 0);
}

/* Names materialise letter by letter, bleeding in as blood before drying to ink. */
.name {
  font-weight: 500;
  text-transform: uppercase;
  opacity: 1;
  filter: none;
  transform: translateY(-50%);
}

.name .ch {
  --at: calc(var(--d) + var(--i) * 150ms);
  display: inline-block;
  opacity: 0;
  color: var(--blood);
  filter: blur(14px);
  transform: translateY(.15em) scale(1.3);
  transition:
    opacity 1s ease var(--at),
    filter 1.3s ease var(--at),
    transform 1.6s var(--ease-out) var(--at),
    color 2.6s ease calc(var(--at) + 700ms);
}

.is-revealed .name .ch {
  opacity: 1;
  color: var(--ink);
  filter: blur(0);
  transform: none;
}

/* "and" is written by an invisible pen: a feathered mask wipes left to right. */
.amp {
  font-family: var(--script);
  opacity: 1;
  filter: none;
  transform: translateY(-50%);
  mask-image: linear-gradient(90deg, #000 45%, transparent 55%);
  -webkit-mask-image: linear-gradient(90deg, #000 45%, transparent 55%);
  mask-size: 260% 100%;
  -webkit-mask-size: 260% 100%;
  mask-repeat: no-repeat;
  -webkit-mask-repeat: no-repeat;
  mask-position: 100% 0;
  -webkit-mask-position: 100% 0;
  transition: mask-position 1.6s ease-in-out var(--d), -webkit-mask-position 1.6s ease-in-out var(--d);
}

.is-revealed .amp { mask-position: 0 0; -webkit-mask-position: 0 0; }

/* ───────── Scroll hint: a drop of wax runs down a thread ───────── */

.scroll-hint {
  position: absolute;
  bottom: max(1.2rem, env(safe-area-inset-bottom));
  left: 50%;
  display: grid;
  justify-items: center;
  gap: .5rem;
  color: var(--parchment-dim);
  font-size: .8rem;
  letter-spacing: .35em;
  text-transform: uppercase;
  text-decoration: none;
  opacity: 0;
  transform: translateX(-50%);
  transition: opacity 1.5s ease;
}

.scroll-hint i {
  position: relative;
  width: 1px;
  height: 42px;
  background: linear-gradient(var(--parchment-dim), transparent);
  overflow: hidden;
}

.scroll-hint i::after {
  content: '';
  position: absolute;
  left: -2px;
  top: -8px;
  width: 5px;
  height: 8px;
  border-radius: 50% 50% 50% 50% / 30% 30% 70% 70%;
  background: var(--blood);
  animation: drip 2.4s ease-in infinite;
}

.is-settled .scroll-hint { opacity: .85; }

@keyframes drip {
  0%, 20% { transform: translateY(0); opacity: 0; }
  30% { opacity: 1; }
  100% { transform: translateY(54px); opacity: 0; }
}

/* ───────── Details ───────── */

.details {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 2.2rem;
  max-width: 34rem;
  margin: 0 auto;
  padding: 5rem 1.25rem max(4rem, env(safe-area-inset-bottom));
  text-align: center;
}

.reveal-on-scroll {
  opacity: 0;
  filter: blur(4px);
  transform: translateY(24px);
  transition: opacity 1.2s ease, filter 1.2s ease, transform 1.2s var(--ease-out);
}

.reveal-on-scroll.is-visible { opacity: 1; filter: none; transform: none; }

.details__greeting {
  margin: 0;
  font-family: var(--script);
  font-size: clamp(2.2rem, 9vw, 3rem);
  color: var(--parchment);
}

.details__title {
  margin: 0;
  font-weight: 400;
  font-size: .85rem;
  letter-spacing: .3em;
  text-transform: uppercase;
  color: var(--parchment-dim);
}

.countdown {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: .5rem;
  width: 100%;
}

.countdown__cell { display: grid; gap: .35rem; }

.countdown__value {
  font-size: clamp(2.1rem, 11vw, 3.4rem);
  font-weight: 500;
  font-variant-numeric: lining-nums tabular-nums;
  line-height: 1;
  color: var(--parchment);
  text-shadow: 0 0 18px rgba(217, 106, 43, .25);
}

.countdown__label {
  font-size: .72rem;
  letter-spacing: .3em;
  text-transform: uppercase;
  color: var(--parchment-dim);
}

.details__when {
  margin: 0;
  font-size: 1.25rem;
  line-height: 1.6;
  letter-spacing: .04em;
}

.rsvp { display: grid; gap: .8rem; width: 100%; max-width: 20rem; }

.rsvp__ask {
  margin: 0 0 .4rem;
  font-style: italic;
  font-size: 1.15rem;
  color: var(--parchment-dim);
}

.btn {
  display: block;
  padding: 1rem 1.2rem;
  border-radius: 999px;
  font-size: .95rem;
  letter-spacing: .22em;
  text-transform: uppercase;
  text-decoration: none;
  transition: transform .2s ease, box-shadow .3s ease, background-color .3s ease;
}

.btn:active { transform: scale(.97); }

.btn--wax {
  color: #f7e9e2;
  background: radial-gradient(120% 140% at 30% 20%, #b3222a, var(--wax) 55%, #45050a);
  box-shadow: 0 10px 30px rgba(120, 10, 16, .45), inset 0 1px 0 rgba(255, 190, 190, .25);
}

.btn--wax:hover { box-shadow: 0 12px 38px rgba(160, 20, 26, .6), inset 0 1px 0 rgba(255, 190, 190, .3); }

.btn--ghost {
  color: var(--parchment-dim);
  border: 1px solid rgba(185, 171, 152, .35);
}

.btn--ghost:hover { background-color: rgba(239, 231, 218, .06); }

.links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: .6rem 1.6rem;
}

.links a {
  color: var(--parchment);
  font-size: 1.05rem;
  text-decoration: none;
  border-bottom: 1px solid rgba(185, 171, 152, .4);
  padding-bottom: .15rem;
}

.links a:hover { border-color: var(--parchment); }

.sign-off { display: grid; gap: 1rem; justify-items: center; padding-top: 1rem; }

.sign-off__names {
  margin: 0;
  font-family: var(--script);
  font-size: 2.6rem;
}

.replay {
  padding: .5rem 1rem;
  border: 0;
  background: none;
  color: var(--parchment-dim);
  font: inherit;
  font-size: .8rem;
  letter-spacing: .3em;
  text-transform: uppercase;
  cursor: pointer;
}

a:focus-visible, button:focus-visible {
  outline: 1px solid var(--ember);
  outline-offset: 4px;
}

/* ───────── Petals ───────── */

.petals {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 5;
  pointer-events: none;
}

/* ───────── Music toggle ───────── */

.sound-toggle {
  position: fixed;
  top: max(1rem, env(safe-area-inset-top));
  right: max(1rem, env(safe-area-inset-right));
  z-index: 10;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid rgba(185, 171, 152, .3);
  border-radius: 50%;
  background: rgba(11, 8, 7, .5);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  color: var(--parchment);
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 1.2s ease 2s;
}

.is-open .sound-toggle { opacity: .85; pointer-events: auto; }

.sound-toggle svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sound-toggle__off,
.sound-toggle[aria-pressed="true"] .sound-toggle__on { display: none; }
.sound-toggle[aria-pressed="true"] .sound-toggle__off { display: inline; }

/* ───────── Seal screen ───────── */

.seal-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 1.1rem;
  padding: 1.25rem;
  background:
    radial-gradient(55% 40% at 50% 50%, rgba(140, 24, 22, .32), transparent 70%),
    rgba(7, 5, 5, .86);
  text-align: center;
  transition: opacity 1.1s ease .15s, visibility 0s linear 1.3s;
}

.is-open .seal-screen { opacity: 0; visibility: hidden; }

.seal-screen__for {
  margin: 0;
  font-size: .8rem;
  letter-spacing: .4em;
  text-transform: uppercase;
  color: var(--parchment-dim);
}

.seal-screen__name {
  margin: -.2rem 0 .6rem;
  font-family: var(--script);
  font-size: clamp(2.4rem, 11vw, 3.6rem);
  line-height: 1.1;
}

.seal-screen__hint {
  margin: .6rem 0 0;
  font-size: .8rem;
  letter-spacing: .45em;
  padding-left: .45em;
  text-transform: uppercase;
  color: var(--parchment-dim);
  animation: breathe 2.6s ease-in-out infinite;
}

.is-breaking .seal-screen__hint { animation: none; opacity: 0; transition: opacity .3s ease; }

.seal {
  position: relative;
  width: min(58vw, 240px);
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  filter: drop-shadow(0 18px 28px rgba(0, 0, 0, .65));
  animation: heartbeat 1.9s ease-in-out infinite;
}

.seal__half,
.seal__crack {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.seal__half--right { opacity: 0; }

.seal__crack polyline {
  fill: none;
  stroke: #1a0003;
  stroke-width: 2.4;
  stroke-linejoin: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
}

.is-breaking .seal { animation: none; }
.is-breaking .seal__crack polyline { animation: crack .26s ease-out forwards; }
.is-breaking .seal__crack { animation: fade-out .2s ease .32s forwards; }

.is-breaking .seal__half--left {
  clip-path: polygon(0 0, 52% 0, 48% 20%, 54% 35%, 47% 50%, 53.5% 64%, 47.5% 80%, 51% 100%, 0 100%);
  animation: fall-left 1.3s .26s forwards;
}

.is-breaking .seal__half--right {
  opacity: 1;
  clip-path: polygon(52% 0, 100% 0, 100% 100%, 51% 100%, 47.5% 80%, 53.5% 64%, 47% 50%, 54% 35%, 48% 20%);
  animation: fall-right 1.3s .26s forwards;
}

@keyframes heartbeat {
  0%, 60%, 100% { transform: scale(1); }
  12% { transform: scale(1.045); }
  24% { transform: scale(1); }
  36% { transform: scale(1.03); }
}

@keyframes breathe { 50% { opacity: .35; } }
@keyframes crack { to { stroke-dashoffset: 0; } }
@keyframes fade-out { to { opacity: 0; } }

@keyframes fall-left {
  0% { transform: none; animation-timing-function: cubic-bezier(.2, .8, .3, 1); }
  18% { transform: translate(-7%, -3%) rotate(-7deg); animation-timing-function: cubic-bezier(.55, 0, .85, .3); }
  100% { transform: translate(-45%, 150%) rotate(-40deg); opacity: 0; }
}

@keyframes fall-right {
  0% { transform: none; animation-timing-function: cubic-bezier(.2, .8, .3, 1); }
  18% { transform: translate(7%, -2%) rotate(6deg); animation-timing-function: cubic-bezier(.55, 0, .85, .3); }
  100% { transform: translate(40%, 160%) rotate(34deg); opacity: 0; }
}

/* ───────── Reduced motion: keep the story, drop the theatrics ───────── */

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .seal, .seal-screen__hint, .scroll-hint i::after { animation: none; }
  .is-breaking .seal__half--left, .is-breaking .seal__half--right { animation: fade-out .3s forwards; }
  .line, .name .ch, .amp, .draw, .reveal-on-scroll { transition-duration: .01s; transition-delay: 0s; }
}
