/* Palette drawn from the engagement photos: Teton sky blues, sage hills, pines, and golden grass */
:root {
  --sky-50: #f3f8f9;
  --sky-100: #e6f0f3;
  --sky-200: #d3e5eb;
  --sky-300: #b5d3df;
  --sky-500: #6f9fb3;
  --sage-100: #e8f0e4;
  --sage-200: #d4e3cf;
  --sage-300: #b9d0b3;
  --sage-500: #7d9e80;
  --pine: #4c6b55;
  --slate: #2e4650;
  --slate-dark: #22363e;
  --muted: #5d7480;
  --gold: #c49a5e;
  --paper: #fdfdfa;
  --danger: #a14848;

  /* Tileable paper tooth: lit fractal noise, multiplied over each paper color */
  --paper-texture: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='220'><filter id='p' x='0' y='0' width='100%' height='100%' color-interpolation-filters='sRGB'><feTurbulence type='fractalNoise' baseFrequency='0.95' numOctaves='3' stitchTiles='stitch'/><feDiffuseLighting lighting-color='%23fff' surfaceScale='0.7'><feDistantLight azimuth='225' elevation='74'/></feDiffuseLighting></filter><rect width='100%' height='100%' filter='url(%23p)'/></svg>");

  --font-serif: "Cormorant Garamond", Georgia, serif;
  --font-script: "Pinyon Script", cursive;

  --envelope-width: min(86vw, 440px);
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
}

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

/* Keep the hidden attribute authoritative over component display rules */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100svh;
  background-color: var(--sky-100);
  color: var(--slate);
  font-family: var(--font-serif);
  font-size: 1.125rem;
  -webkit-font-smoothing: antialiased;
}

/* Fixed pseudo-element instead of background-attachment: fixed, which iOS Safari ignores */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    linear-gradient(
      180deg,
      rgba(236, 245, 248, 0.62) 0%,
      rgba(225, 238, 242, 0.42) 45%,
      rgba(222, 235, 218, 0.72) 100%
    ),
    url("images/proposal-tetons.jpg") center 40% / cover no-repeat;
}

.svg-defs {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

/* ---------- Envelope ---------- */

/* Fixed overlay: the envelope never affects layout, so revealing the invitation can't shift it */
.scene {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 32px;
  padding: 16px;
}

.scene__title {
  margin: 0;
  font-family: var(--font-script);
  font-size: clamp(3rem, 12vw, 4.4rem);
  line-height: 1;
  color: var(--slate);
  /* Soft glow keeps the script legible over the photo */
  text-shadow: 0 0 18px rgba(243, 248, 249, 0.95), 0 0 4px rgba(243, 248, 249, 0.9);
  animation: float 5s ease-in-out -1.2s infinite;
  transition: opacity 0.5s ease, transform 0.5s ease;
}

.scene.is-opening .scene__title {
  opacity: 0;
  transform: translateY(-12px);
  animation: none;
}

.envelope {
  position: relative;
  width: var(--envelope-width);
  aspect-ratio: 3 / 2;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  perspective: 1400px;
  animation: float 5s ease-in-out infinite;
}

.envelope:focus-visible {
  outline: 2px solid var(--sky-500);
  outline-offset: 12px;
  border-radius: 6px;
}

/* Freeze the float where it is rather than snapping back to rest */
.envelope.is-open {
  animation-play-state: paused;
  cursor: default;
}

.envelope > span,
.envelope > svg {
  position: absolute;
  display: block;
}

/* Inside of the envelope, seen through the opening: the blue liner, shaded toward the fold */
.envelope__back {
  inset: 0;
  border-radius: 3px;
  background:
    linear-gradient(to bottom, rgba(46, 70, 80, 0.18), transparent 35%),
    repeating-linear-gradient(35deg, transparent 0 5px, rgba(163, 194, 207, 0.3) 5px 6px),
    var(--paper-texture),
    linear-gradient(to bottom, var(--sky-200), var(--sky-300));
  background-blend-mode: normal, normal, multiply, normal;
  box-shadow:
    0 24px 40px -8px rgba(34, 54, 62, 0.35),
    0 6px 14px rgba(34, 54, 62, 0.15);
}

.envelope__letter {
  left: 5%;
  right: 5%;
  top: 5%;
  height: 90%;
  z-index: 2;
  /* A wash of paper color over the multiplied tooth keeps the card bright white rather than gray */
  background:
    linear-gradient(rgba(253, 253, 250, 0.6), rgba(253, 253, 250, 0.6)),
    var(--paper-texture),
    var(--paper);
  background-blend-mode: normal, multiply, normal;
  border-radius: 2px;
  outline: 1px solid var(--sage-300);
  outline-offset: -8px;
  box-shadow: 0 -1px 6px rgba(34, 54, 62, 0.12);
  will-change: transform;
}

.envelope__pocket {
  inset: 0;
  z-index: 3;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.envelope__flap {
  top: 0;
  left: 0;
  width: 100%;
  height: 62.5%;
  z-index: 4;
  transform-origin: top center;
  transform-style: preserve-3d;
  will-change: transform;
}

.envelope__monogram {
  mix-blend-mode: multiply;
}

.envelope__flap-face {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

/* The liner side faces away until the flap swings open */
.envelope__flap-face--inside {
  transform: rotateX(180deg);
}

.envelope__seal {
  top: 58%;
  left: 50%;
  z-index: 5;
  width: clamp(64px, 18vw, 82px);
  height: auto;
  aspect-ratio: 1;
  overflow: visible;
  transform: translate(-50%, -50%) rotate(-4deg);
  transition: transform 0.25s ease;
}

.envelope:not(.is-open):hover .envelope__seal {
  transform: translate(-50%, -50%) rotate(-4deg) scale(1.05);
}

.hint {
  margin: 0;
  padding: 6px 16px;
  border-radius: 999px;
  background: rgba(253, 253, 250, 0.7);
  backdrop-filter: blur(6px);
  font-style: italic;
  letter-spacing: 0.04em;
  color: var(--slate);
  animation: pulse 2.4s ease-in-out infinite;
  transition: opacity 0.3s;
}

.envelope.is-open + .hint {
  opacity: 0;
  animation: none;
}

/* ---------- Invitation and photos ---------- */

.stage {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: 1fr 1fr;
  justify-items: center;
  align-content: center;
  gap: 28px 16px;
  min-height: 100svh;
  padding: 32px 16px 48px;
  overflow-x: clip;
}

.invite {
  position: relative;
  z-index: 2;
  grid-column: 1 / -1;
  grid-row: 1;
  width: min(100%, 460px);
  padding: 14px;
  /* A wash of paper color over the multiplied tooth keeps the card bright white rather than gray */
  background:
    linear-gradient(rgba(253, 253, 250, 0.6), rgba(253, 253, 250, 0.6)),
    var(--paper-texture),
    var(--paper);
  background-blend-mode: normal, multiply, normal;
  border-radius: 3px;
  box-shadow: 0 30px 60px rgba(34, 54, 62, 0.25), 0 6px 14px rgba(34, 54, 62, 0.1);
  text-align: center;
  /* The reveal animation scales the card up from the letter's top-left corner */
  transform-origin: top left;
}

.print {
  --tilt: -4deg;
  --enter-from: translateY(-40px);
  position: relative;
  z-index: 1;
  grid-row: 2;
  width: min(100%, 210px);
  margin: 0;
  padding: 8px 8px 28px;
  background: #fff;
  box-shadow: 0 16px 32px rgba(34, 54, 62, 0.25), 0 3px 8px rgba(34, 54, 62, 0.12);
  opacity: 0;
}

.print img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 2 / 3;
  object-fit: cover;
}

.print--left {
  justify-self: end;
}

.print--right {
  --tilt: 3.5deg;
  justify-self: start;
}

.stage.is-revealed .print {
  animation: print-in 0.9s var(--ease-out) both;
}

.stage.is-revealed .print--right {
  animation-delay: 0.15s;
}

@media (min-width: 960px) {
  .stage {
    grid-template-columns: 1fr minmax(0, 460px) 1fr;
    align-items: center;
    gap: 0;
  }

  .invite {
    grid-column: 2;
  }

  .print {
    grid-row: 1;
    width: clamp(200px, 19vw, 290px);
    padding: 10px 10px 36px;
  }

  /* Prints tuck slightly behind the card edges and slide out from under it */
  .print--left {
    --tilt: -5deg;
    --enter-from: translateX(70%);
    grid-column: 1;
    margin-right: -28px;
  }

  .print--right {
    --tilt: 4deg;
    --enter-from: translateX(-70%);
    grid-column: 3;
    margin-left: -28px;
    margin-top: 80px;
  }
}

/* Vertical rhythm: every block is centered and separated by the same gap */
.invite__border {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 26px;
  padding: 50px 32px;
  border: 1px solid var(--sage-300);
  outline: 1px solid var(--sage-300);
  outline-offset: -6px;
}

:where(.invite) p {
  margin: 0;
}

.invite__header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

.invite__eyebrow {
  line-height: 1.7;
  font-size: 0.85rem;
  letter-spacing: 0.24em;
  /* Letter-spacing adds trailing space after the last letter; offset it so lines center optically */
  margin-right: -0.24em;
  text-transform: uppercase;
  color: var(--muted);
}

@media (max-width: 420px) {
  .invite__border {
    padding: 40px 18px;
  }

  .invite__eyebrow {
    font-size: 0.78rem;
    letter-spacing: 0.14em;
    margin-right: -0.14em;
  }
}

.invite__names {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 0;
  font-family: var(--font-script);
  font-weight: 400;
  font-size: clamp(2.8rem, 12vw, 3.8rem);
  line-height: 0.95;
  color: var(--slate);
}

.amp {
  margin: -2px 0 2px;
  font-size: 0.9em;
  line-height: 1;
  color: var(--gold);
}

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  width: min(100%, 200px);
  color: var(--gold);
}

.divider span {
  flex: 1;
  height: 1px;
  background: var(--sage-300);
}

/* Date and venue sit closer together than the other blocks so they read as one group */
.invite__details {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.invite__section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.invite__heading {
  margin-bottom: 4px;
  font-size: 1.3rem;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.invite__detail {
  color: var(--muted);
}

.invite__address {
  color: var(--muted);
  line-height: 1.45;
  text-decoration: none;
  transition: color 0.2s;
}

.invite__address:hover {
  color: var(--slate);
}

.invite__rsvp {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-top: 6px;
}

.invite .btn--primary {
  min-width: 170px;
  /* Same optical-centering offset as the eyebrow for the letter-spaced label */
  padding-left: calc(28px + 0.18em);
}

.invite__respond {
  font-size: 0.95rem;
  font-style: italic;
  color: var(--muted);
}

/* ---------- Buttons ---------- */

.btn {
  font: inherit;
  white-space: nowrap;
  cursor: pointer;
  border-radius: 999px;
  transition: background-color 0.2s, color 0.2s, transform 0.15s, box-shadow 0.2s;
}

.btn:active {
  transform: translateY(1px);
}

.btn:focus-visible {
  outline: 2px solid var(--sky-500);
  outline-offset: 3px;
}

.btn--primary {
  padding: 10px 28px;
  border: 1px solid var(--slate);
  background: var(--slate);
  color: var(--paper);
  font-size: 1.05rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.btn--primary:hover {
  background: var(--slate-dark);
  box-shadow: 0 6px 16px rgba(34, 54, 62, 0.25);
}

.btn--primary:disabled {
  opacity: 0.6;
  cursor: progress;
}

.btn--ghost {
  padding: 10px 22px;
  border: 1px solid var(--sky-300);
  background: transparent;
  color: var(--slate);
  letter-spacing: 0.08em;
}

.btn--ghost:hover {
  background: var(--sky-50);
}

.btn--link {
  padding: 4px 0;
  border: 0;
  background: none;
  color: var(--pine);
  font-style: italic;
}

.btn--link:hover {
  text-decoration: underline;
}

/* ---------- RSVP dialog ---------- */

.rsvp {
  width: min(calc(100vw - 32px), 460px);
  max-height: calc(100svh - 32px);
  overflow-y: auto;
  padding: 36px 28px 28px;
  border: 0;
  border-radius: 10px;
  background: var(--paper);
  color: var(--slate);
  box-shadow: 0 30px 80px rgba(34, 54, 62, 0.35);
}

.rsvp[open] {
  animation: dialog-in 0.45s var(--ease-out);
}

.rsvp::backdrop {
  background: rgba(46, 70, 80, 0.45);
  backdrop-filter: blur(4px);
}

.rsvp[open]::backdrop {
  animation: fade-in 0.3s ease;
}

.rsvp__close {
  position: absolute;
  top: 10px;
  right: 14px;
  padding: 4px 8px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 1.8rem;
  line-height: 1;
  cursor: pointer;
}

.rsvp__close:hover {
  color: var(--slate);
}

.rsvp__title {
  margin: 0 0 18px;
  text-align: center;
  font-family: var(--font-script);
  font-weight: 400;
  font-size: 2.6rem;
}

.field {
  margin: 0 0 20px;
  padding: 0;
  border: 0;
}

.field legend {
  margin-bottom: 8px;
  font-size: 0.85rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.guest-list {
  display: grid;
  gap: 8px;
  margin-bottom: 6px;
}

.guest-row {
  display: flex;
  gap: 8px;
  animation: row-in 0.3s var(--ease-out);
}

.guest-row input {
  flex: 1;
  min-width: 0;
}

.guest-row input,
.text-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--sky-300);
  border-radius: 6px;
  background: #fff;
  color: var(--slate);
  font: inherit;
}

textarea.text-input {
  resize: vertical;
}

.guest-row input:focus,
.text-input:focus {
  outline: none;
  border-color: var(--sky-500);
  box-shadow: 0 0 0 3px rgba(111, 159, 179, 0.22);
}

.guest-row__remove {
  flex: none;
  width: 40px;
  border: 1px solid var(--sky-300);
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 1.3rem;
  cursor: pointer;
}

.guest-row__remove:hover {
  color: var(--danger);
  border-color: var(--danger);
}

.contact-fields {
  display: grid;
  gap: 12px;
}

.input-label span {
  display: block;
  margin-bottom: 4px;
  font-size: 0.95rem;
}

.input-label em {
  color: var(--muted);
}

.choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.choice {
  position: relative;
}

.choice input {
  position: absolute;
  opacity: 0;
  inset: 0;
  margin: 0;
  cursor: pointer;
}

.choice span {
  display: block;
  padding: 12px 8px;
  border: 1px solid var(--sky-300);
  border-radius: 6px;
  text-align: center;
  transition: background-color 0.2s, border-color 0.2s, color 0.2s;
}

.choice input:hover + span {
  background: var(--sage-100);
}

.choice input:checked + span {
  border-color: var(--slate);
  background: var(--slate);
  color: var(--paper);
}

.choice input:focus-visible + span {
  outline: 2px solid var(--sky-500);
  outline-offset: 2px;
}

.rsvp__error {
  min-height: 1.4em;
  margin: 0 0 8px;
  color: var(--danger);
  font-size: 1rem;
  text-align: center;
}

.rsvp__actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.rsvp__thanks {
  text-align: center;
  animation: fade-in 0.4s ease;
}

.rsvp__photo {
  display: block;
  width: 100%;
  height: 240px;
  margin-bottom: 18px;
  border-radius: 6px;
  object-fit: cover;
  /* Frames both full glasses, stems and bases included */
  object-position: 50% 63%;
}

.rsvp__thanks p {
  margin: 0 0 24px;
  font-size: 1.2rem;
}

.rsvp__thanks .rsvp__note {
  margin-top: -12px;
  color: var(--muted);
  font-size: 1rem;
}

@media (max-width: 400px) {
  .choices {
    grid-template-columns: 1fr;
  }

  .rsvp__actions .btn {
    flex: 1;
  }
}

/* ---------- Keyframes ---------- */

@keyframes float {
  0%, 100% { transform: translateY(0) rotate(-0.8deg); }
  50% { transform: translateY(-8px) rotate(0.8deg); }
}

@keyframes pulse {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 1; }
}

@keyframes print-in {
  from { opacity: 0; transform: var(--enter-from) rotate(0deg) scale(0.92); }
  to { opacity: 1; transform: rotate(var(--tilt)); }
}

@keyframes dialog-in {
  from { opacity: 0; transform: translateY(24px) scale(0.96); }
  to { opacity: 1; transform: none; }
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes row-in {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: none; }
}

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