* { box-sizing: border-box; }

html, body { margin: 0; }

:root {
  --ink: #3f4230;
  --muted: #7a756b;
  --olive: #55603f;
  --olive-dark: #46502f;
  --cream: #fbf6ec;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);

  /* Card width: fits the viewport width and leaves room below for the
     hint (closed) or the hint + RSVP buttons (open). */
  --card-w: min(92vw, 900px, calc((100dvh - 130px) * 1.5));
  --card-w-open: min(80vw, 760px, calc((100dvh - 260px) * 1.5));
}

body {
  font-family: Georgia, "Times New Roman", serif;
  color: var(--muted);
  background:
    radial-gradient(circle at 20% 15%, #efe4d2 0, transparent 45%),
    radial-gradient(circle at 85% 90%, #e3e8dc 0, transparent 50%),
    #ece6db;
}

.stage {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 20px;
  perspective: 1800px;
}

/* ---------- Card ---------- */

.postcard {
  width: var(--card-w);
  aspect-ratio: 3 / 2;
  cursor: pointer;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  transition: width 0.6s var(--ease);
}

.rsvp-open .postcard { width: var(--card-w-open); }

.postcard__inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.9s var(--ease);
  border-radius: 6px;
  box-shadow: 0 20px 50px rgba(60, 50, 35, 0.25);
}

.postcard:focus-visible .postcard__inner {
  box-shadow: 0 0 0 3px var(--olive), 0 20px 50px rgba(60, 50, 35, 0.25);
}

.postcard.is-flipped .postcard__inner { transform: rotateY(180deg); }

.face {
  position: absolute;
  inset: 0;
  border-radius: 6px;
  overflow: hidden;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background: var(--cream);
}

.face--back { transform: rotateY(180deg); }

.face img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  user-select: none;
  -webkit-user-drag: none;
}

/* ---------- Hint / call to action (share one slot) ---------- */

.below {
  display: grid;
  place-items: center;
  margin-top: 18px;
  min-height: 64px;
}

.hint,
.cta {
  grid-area: 1 / 1;
  transition: opacity 0.4s ease, visibility 0.4s;
}

.hint {
  margin: 0;
  font-style: italic;
  font-size: 1rem;
}

.cta {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 6px 14px;
  border: 0;
  background: none;
  font: inherit;
  font-size: 1.15rem;
  letter-spacing: 0.02em;
  color: var(--ink);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.cta span {
  border-bottom: 1px solid rgba(63, 66, 48, 0.35);
  padding-bottom: 2px;
}

.cta:hover span { border-bottom-color: var(--ink); }

.cta:focus-visible {
  outline: 2px solid var(--olive);
  outline-offset: 4px;
  border-radius: 4px;
}

.cta__arrow {
  width: 22px;
  height: 22px;
  animation: nudge 1.8s ease-in-out infinite;
  transition: transform 0.4s var(--ease);
}

@keyframes nudge {
  0%, 100% { translate: 0 0; }
  50% { translate: 0 5px; }
}

.rsvp-open .cta__arrow {
  animation: none;
  transform: rotate(180deg);
}

/* Front: hint visible. Back: call to action visible. */
.cta { opacity: 0; visibility: hidden; }
.is-back .hint { opacity: 0; visibility: hidden; }
.is-back .cta { opacity: 1; visibility: visible; transition-delay: 0.35s; }

/* ---------- RSVP buttons ---------- */

.rsvp {
  display: grid;
  grid-template-rows: 0fr;
  opacity: 0;
  transition: grid-template-rows 0.6s var(--ease), opacity 0.4s ease;
}

.rsvp-open .rsvp {
  grid-template-rows: 1fr;
  opacity: 1;
  transition-delay: 0s, 0.15s;
}

.rsvp__inner {
  overflow: hidden;
  display: flex;
  gap: 14px;
  justify-content: center;
  padding: 6px 16px 20px; /* room for the button shadows */
}

.rsvp__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 50px;
  padding: 0 26px;
  border-radius: 999px;
  background: var(--olive);
  color: var(--cream);
  font-size: 1.05rem;
  letter-spacing: 0.02em;
  text-decoration: none;
  box-shadow: 0 6px 16px rgba(60, 50, 35, 0.18);
  transition: background 0.2s ease, transform 0.2s ease;
}

.rsvp__btn:hover { background: var(--olive-dark); transform: translateY(-1px); }

.rsvp__btn:focus-visible {
  outline: 2px solid var(--olive);
  outline-offset: 3px;
}

/* ---------- Portrait (phones held upright) ---------- */

@media (max-aspect-ratio: 1/1) {
  :root {
    --card-w: min(90vw, 520px, calc((100dvh - 130px) * 2 / 3));
    --card-w-open: min(76vw, 440px, calc((100dvh - 300px) * 2 / 3));
  }

  .postcard { aspect-ratio: 2 / 3; }

  .rsvp__inner {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    width: min(92vw, 372px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .postcard, .postcard__inner, .rsvp, .hint, .cta, .cta__arrow { transition: none; }
  .cta__arrow { animation: none; }
}
