/* Design tokens */
:root {
  --color-bg: #fefff5;
  --color-text: #2b342c;
  --color-cream: #f7f5e2;
  --color-card: rgba(230, 228, 206, 0.72);
  --color-white: #ffffff;
  --font-bellefair: "Bellefair", serif;
  --font-belleza: "Belleza", serif;
  --font-bellota: "Bellota Text", cursive;
  --content-width: 440px;
  --card-ratio-w: 344;
  --card-ratio-h: 258;
  --card-width-pct: 78.2%; /* 344px / 440px from Figma */
  --page-transition: 0.45s cubic-bezier(0.4, 0, 0.2, 1);
  --card-open-duration: 1s;
  --card-expand-duration: 0.7s;
}

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

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  background: #d4d2c8;
  color: var(--color-text);
  font-family: var(--font-belleza);
  -webkit-font-smoothing: antialiased;
}

img {
  display: block;
  max-width: 100%;
}

button {
  font: inherit;
  border: none;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* App shell — centers on desktop */
.app {
  display: flex;
  justify-content: center;
  align-items: stretch;
  min-height: 100dvh;
  height: 100dvh;
}

.invitation {
  width: 100%;
  max-width: var(--content-width);
  height: 100%;
  background: var(--color-bg);
  position: relative;
  overflow: hidden;
  box-shadow: 0 0 60px rgba(43, 52, 44, 0.12);
  container-type: inline-size;
  container-name: invitation;
}

@media (min-width: 520px) {
  .app {
    padding: 16px 0;
    height: 100dvh;
  }

  .invitation {
    height: calc(100dvh - 32px);
    border-radius: 16px;
    max-height: 920px;
  }
}

@media (min-width: 900px) {
  .invitation {
    max-width: 480px;
  }
}

/* ── Page system ──────────────────────────────────── */

.pages {
  position: relative;
  width: 100%;
  height: 100%;
}

.page {
  position: absolute;
  inset: 0;
  opacity: 0;
  visibility: hidden;
  transform: translateX(40px);
  transition:
    opacity var(--page-transition),
    transform var(--page-transition),
    visibility var(--page-transition);
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.page--active {
  opacity: 1;
  visibility: visible;
  transform: translateX(0);
  z-index: 2;
}

.page--exit-left {
  opacity: 0;
  transform: translateX(-40px);
  z-index: 1;
}

/* Page 1 must always fit one screen — no scroll */
.page--hero {
  overflow: hidden;
}

.page-back {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  left: 16px;
  z-index: 10;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-cream);
  color: var(--color-text);
  border-radius: 50%;
  font-size: 18px;
  line-height: 1;
  box-shadow: 0 2px 8px rgba(43, 52, 44, 0.1);
  transition: transform 0.15s;
}

.page-back:hover {
  transform: scale(1.05);
}

/* ── Page 1: Hero ─────────────────────────────────── */

.hero {
  position: relative;
  height: 100%;
  background: var(--color-bg);
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
  isolation: isolate;
}

.hero__bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
  pointer-events: none;
  z-index: 0;
}

.hero__header {
  position: relative;
  z-index: 2;
  display: flex;
  justify-content: flex-end;
  padding: max(12px, env(safe-area-inset-top)) 20px 0;
  flex-shrink: 0;
}

.lang-toggle {
  background: var(--color-cream);
  color: var(--color-text);
  font-family: var(--font-bellota);
  font-size: 13px;
  padding: 5px 10px;
  border-radius: 6px;
}

.hero__content {
  position: relative;
  z-index: 1;
  width: 100%;
  min-height: 0;
  padding: 0 16px;
  text-align: center;
  color: var(--color-white);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(6px, 1.5dvh, 14px);
}

.hero__families {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: clamp(2px, 1.5cqi, 8px);
  width: 100%;
  max-width: 100%;
  flex-shrink: 0;
}

.hero__family {
  flex: 1;
  min-width: 0;
  max-width: 42%;
}

.hero__family-label {
  font-family: var(--font-bellefair);
  font-size: clamp(12px, 3.8cqi, 17px);
  line-height: 1.2;
}

.hero__family-name {
  font-family: var(--font-belleza);
  font-size: clamp(14px, 5cqi, 23px);
  line-height: 1.15;
  margin-top: clamp(2px, 0.8dvh, 8px);
  word-wrap: break-word;
  hyphens: auto;
}

.hero__ampersand {
  flex-shrink: 0;
  width: clamp(24px, 7cqi, 38px);
  height: auto;
  margin-top: clamp(12px, 3dvh, 24px);
  align-self: flex-start;
}

.hero__invite-text {
  font-family: var(--font-bellefair);
  font-size: clamp(13px, 4cqi, 18px);
  line-height: 1.25;
  max-width: min(200px, 90%);
  flex-shrink: 0;
  margin-bottom: clamp(4px, 1dvh, 8px);
}

/* Figma: 344×258px photo on 440px-wide frame (~78% width) */
.hero__photo-card {
  position: relative;
  flex: 0 0 auto;
  display: block;
  width: min(var(--card-width-pct), 300px);
  aspect-ratio: 344 / 258;
  height: auto;
  border-radius: 4px;
  overflow: visible;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  padding: 0;
  margin-top: clamp(8px, 2dvh, 16px);
}

.hero__photo-card-scene {
  display: block;
  position: relative;
  width: 100%;
  aspect-ratio: 344 / 258;
  perspective: 1400px;
  transform-style: preserve-3d;
}

.hero__photo-card-base {
  position: absolute;
  inset: 0;
  border-radius: 4px;
  background: linear-gradient(160deg, #fffef8 0%, var(--color-cream) 50%, #e5e2cc 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  box-shadow: inset 0 0 0 1px rgba(43, 52, 44, 0.08);
  z-index: 1;
}

.hero__photo-card-inside-logo {
  width: 38%;
  height: auto;
  opacity: 0.85;
}

.hero__photo-card-inside-text {
  font-family: var(--font-bellefair);
  font-size: clamp(14px, 4cqi, 18px);
  color: var(--color-text);
  letter-spacing: 0.06em;
}

.hero__photo-card-cover {
  display: block;
  position: absolute;
  inset: 0;
  border-radius: 4px;
  overflow: hidden;
  transform: rotateY(0deg) translateZ(1px);
  transform-origin: left center;
  transform-style: preserve-3d;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  z-index: 2;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.22);
  transition:
    transform var(--card-open-duration) cubic-bezier(0.33, 1, 0.68, 1),
    box-shadow 0.4s ease,
    opacity 0.35s ease;
}

.hero__photo-card:not(.hero__photo-card--lift):not(.hero__photo-card--open):hover .hero__photo-card-cover {
  transform: rotateY(-4deg) translateZ(1px);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.34);
}

.hero__photo-card:not(.hero__photo-card--open):active .hero__photo-card-cover {
  transform: rotateY(0deg) scale(0.98) translateZ(1px);
}

/* Phase 1 — lift card toward viewer */
.hero__photo-card--lift .hero__photo-card-scene {
  transform: scale(1.06) translateY(-6px);
  transition: transform 0.35s cubic-bezier(0.34, 1.4, 0.64, 1);
}

.hero__photo-card--lift .hero__photo-card-cover {
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.38);
}

/* Phase 2 — fold cover open like an invitation */
.hero__photo-card--open .hero__photo-card-cover {
  transform: rotateY(-168deg) translateZ(1px);
  box-shadow: -8px 8px 30px rgba(0, 0, 0, 0.2);
}

.hero__photo-card--open .hero__photo-hint {
  opacity: 0;
}

/* Phase 3 — card expands to fill screen before page change */
.hero--card-expanding .hero__photo-card {
  position: absolute;
  top: var(--card-top, 50%);
  left: var(--card-left, 50%);
  width: var(--card-width, 80%);
  height: var(--card-height, 40%);
  max-width: none;
  max-height: none;
  aspect-ratio: unset;
  flex: none;
  z-index: 40;
  margin: 0;
  transition:
    top var(--card-expand-duration) cubic-bezier(0.4, 0, 0.2, 1),
    left var(--card-expand-duration) cubic-bezier(0.4, 0, 0.2, 1),
    width var(--card-expand-duration) cubic-bezier(0.4, 0, 0.2, 1),
    height var(--card-expand-duration) cubic-bezier(0.4, 0, 0.2, 1);
}

.hero--card-expanding .hero__content {
  pointer-events: none;
}

.hero__photo-card--expand {
  top: 0 !important;
  left: 0 !important;
  width: 100% !important;
  height: 100% !important;
}

.hero__photo-card--expand .hero__photo-card-scene {
  transform: none;
}

.hero__photo-card--expand .hero__photo-card-cover {
  opacity: 0;
  pointer-events: none;
}

.hero__photo-card--expand .hero__photo-card-base {
  border-radius: 0;
}

.hero__photo-card--expand .hero__photo-card-inside-logo {
  width: min(120px, 28%);
  transition: width var(--card-expand-duration) ease;
}

.hero__photo-card--expand .hero__photo-card-inside-text {
  font-size: clamp(18px, 5cqi, 24px);
  transition: font-size var(--card-expand-duration) ease;
}

/* Dim hero while card opens */
.hero--opening .hero__families,
.hero--opening .hero__invite-text,
.hero--opening .hero__monogram {
  opacity: 0;
  transform: translateY(-12px);
  transition: opacity 0.5s ease, transform 0.5s ease;
}

.hero--opening .hero__footer,
.hero--opening .hero__header {
  opacity: 0;
  transition: opacity 0.4s ease;
}

.hero--opening .hero__bg {
  filter: brightness(0.65);
  transition: filter 0.8s ease;
}

.hero__photo-card--lift,
.hero__photo-card--open,
.hero__photo-card--expand {
  pointer-events: none;
}

.hero__photo-card--lift {
  z-index: 20;
}

/* Page reveal after card fully opens */
.page--reveal-in {
  animation: pageRevealIn 0.6s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

@keyframes pageRevealIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.hero__photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center center;
  display: block;
}

/* Figma node 38:65 — AN monogram below couple photo (149×132 on 440px frame) */
.hero__monogram {
  flex-shrink: 0;
  width: min(34cqi, 120px);
  height: auto;
  aspect-ratio: 149 / 132;
  margin-top: clamp(6px, 1.5dvh, 14px);
  object-fit: contain;
  pointer-events: none;
}

.hero__photo-hint {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 8px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.55));
  color: var(--color-white);
  font-family: var(--font-bellota);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  transition: opacity 0.25s ease;
}

.hero__footer {
  position: relative;
  z-index: 2;
  display: flex;
  justify-content: center;
  padding: clamp(8px, 2dvh, 16px) 0 max(12px, env(safe-area-inset-bottom));
  flex-shrink: 0;
}

/* Figma nodes 40:88 / 40:92 — 15×28 wrapper, arrow rotated 89.71° */
.scroll-hint {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 28px;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.scroll-hint__inner {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28.26px;
  height: 14.87px;
  transform: rotate(89.71deg);
  transition: transform 0.25s ease;
}

.scroll-hint__icon {
  display: block;
  width: 28.26px;
  height: 14.87px;
  max-width: none;
  flex-shrink: 0;
}

.scroll-hint:hover .scroll-hint__inner,
.scroll-hint:focus-visible .scroll-hint__inner {
  transform: rotate(89.71deg) translateY(3px);
}

.scroll-hint:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.6);
  outline-offset: 4px;
  border-radius: 2px;
}

.scroll-hint--venue:focus-visible {
  outline-color: rgba(43, 52, 44, 0.35);
}

/* Short viewports — landscape phones, small screens */
@media (max-height: 700px) {
  .hero__family-name {
    font-size: clamp(13px, 4.5cqi, 18px);
  }

  .hero__invite-text {
    font-size: clamp(12px, 3.5cqi, 15px);
  }

  .hero__photo-card {
    width: min(72%, 260px);
    margin-top: 4px;
  }

  .hero__monogram {
    width: min(30cqi, 100px);
    margin-top: 4px;
  }
}

@media (max-height: 600px) {
  .hero__header {
    padding-top: max(6px, env(safe-area-inset-top));
  }

  .hero__ampersand {
    margin-top: 8px;
    width: 22px;
  }

  .hero__content {
    gap: 4px;
  }

  .hero__photo-card {
    width: min(72%, 240px);
    margin-top: 2px;
  }

  .hero__monogram {
    width: min(28cqi, 88px);
    margin-top: 2px;
  }

  .hero__footer {
    padding: 4px 0 max(6px, env(safe-area-inset-bottom));
  }
}

/* ── Page 2: Venue ────────────────────────────────── */

/* Page 2 must fit card + RSVP in viewport */
.page--venue {
  overflow: hidden;
}

.venue {
  position: relative;
  height: 100%;
  min-height: 0;
  --venue-footer-space: 100px;
  background: var(--color-bg);
  padding: max(48px, calc(env(safe-area-inset-top) + 32px)) 16px max(20px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(10px, 2dvh, 20px);
}

.venue__floral {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 145%;
  max-width: none;
  opacity: 0.56;
  pointer-events: none;
  z-index: 0;
}

/* Figma node 35:24 — scales to fit available height */
.venue__card-wrap {
  position: relative;
  z-index: 1;
  --venue-available-h: calc(100dvh - var(--venue-footer-space) - max(48px, calc(env(safe-area-inset-top) + 32px)) - max(20px, env(safe-area-inset-bottom)));
  width: min(90.9%, 400px, calc(var(--venue-available-h) * 400 / 617));
  aspect-ratio: 400 / 617;
  flex-shrink: 1;
  min-height: 0;
  max-height: var(--venue-available-h);
  container-type: size;
  container-name: venue-card;
}

.venue__card-frame {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill;
}

.venue__card-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.venue__card-overlay img {
  position: absolute;
  display: block;
  object-fit: contain;
  object-position: top left;
}

/* Figma positions on 400×617 card */
.venue__name--1 {
  left: 27.75%;
  top: 29.66%;
  width: 44.4%;
  height: 8.91%;
}

.venue__name--amp {
  left: 46.25%;
  top: 41.49%;
  width: 9.5%;
  height: 6.81%;
}

.venue__name--2 {
  left: 34.5%;
  top: 51.21%;
  width: 23%;
  height: 7.78%;
}

.venue__name--3 {
  left: 46%;
  top: 55.11%;
  width: 19.25%;
  height: 5%;
}

.venue__date {
  position: absolute;
  left: 50%;
  top: 63.86%;
  transform: translateX(-50%);
  margin: 0;
  font-family: var(--font-bellota);
  font-size: clamp(11px, 4.5cqi, 18px);
  line-height: 1;
  color: var(--color-text);
  white-space: nowrap;
}

.venue__details {
  position: absolute;
  left: 50%;
  top: 71%;
  transform: translateX(-50%);
  width: 58%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(6px, 1.8cqi, 10px);
  text-align: center;
}

.venue__location {
  margin: 0;
  font-family: var(--font-bellota);
  font-size: clamp(9px, 2.8cqi, 11px);
  line-height: 1.4;
  color: var(--color-text);
}

.venue__location strong {
  display: block;
  font-size: clamp(10px, 3.2cqi, 13px);
  font-weight: 700;
  margin-bottom: clamp(2px, 0.6cqi, 4px);
}

.venue__time {
  margin: 0;
  font-family: var(--font-bellota);
  font-size: clamp(10px, 3.5cqi, 14px);
  line-height: 1;
  color: var(--color-text);
  white-space: nowrap;
}

@media (max-height: 680px) {
  .venue {
    --venue-footer-space: 72px;
    gap: 8px;
    padding-top: max(44px, calc(env(safe-area-inset-top) + 24px));
  }

  .scroll-hint--venue {
    display: none;
  }
}

@media (max-height: 580px) {
  .venue {
    --venue-footer-space: 56px;
    gap: 6px;
  }
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--color-cream);
  color: var(--color-text);
  border-radius: 11px;
  font-family: var(--font-belleza);
  transition: transform 0.15s, box-shadow 0.15s;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(43, 52, 44, 0.12);
}

.btn:active {
  transform: translateY(0);
}

.btn--rsvp {
  position: relative;
  z-index: 1;
  font-family: var(--font-bellota);
  font-weight: 700;
  font-size: 14px;
  min-width: 89px;
  min-height: 34px;
  padding: 8px 24px;
  border-radius: 11px;
  flex-shrink: 0;
}

.scroll-hint--venue {
  margin-top: 0;
  flex-shrink: 0;
}

/* ── Page 3: RSVP ─────────────────────────────────── */

.rsvp {
  position: relative;
  min-height: 100%;
  background: var(--color-bg);
  padding: max(56px, calc(env(safe-area-inset-top) + 40px)) 20px max(48px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  overflow-y: auto;
}

.rsvp__painting {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 107%;
  opacity: 0.5;
  pointer-events: none;
  z-index: 0;
}

.rsvp__content {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 384px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  container-type: inline-size;
}

/* Figma node 107:1440 — 120×36, left-aligned above RSVP title */
.btn--maps {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 120px;
  height: 36px;
  background: var(--color-cream);
  color: var(--color-text);
  border-radius: 11px;
  font-family: var(--font-belleza);
  font-size: 14px;
  line-height: 1;
  text-decoration: none;
  margin-bottom: clamp(16px, 3dvh, 24px);
  flex-shrink: 0;
  transition: transform 0.15s, box-shadow 0.15s;
}

.btn--maps:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(43, 52, 44, 0.12);
}

.btn--maps img {
  display: block;
  width: 15px;
  height: 20px;
  flex-shrink: 0;
}

.rsvp__title {
  align-self: center;
  width: min(245px, 64cqi);
  height: auto;
  margin-bottom: clamp(16px, 3dvh, 24px);
}

.rsvp__message {
  align-self: center;
  font-family: var(--font-belleza);
  font-size: clamp(17px, 5cqi, 20px);
  line-height: 1.3;
  max-width: 281px;
  margin: 0 auto clamp(20px, 4dvh, 32px);
  color: var(--color-text);
}

.rsvp__form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: clamp(12px, 2.5dvh, 16px);
}

/* Figma node 64:401 — 384×133 guest card */
.guest-card {
  background: var(--color-card);
  border-radius: 11px;
  min-height: 133px;
  padding: 18px 14px 14px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.guest-card__label {
  font-family: var(--font-belleza);
  font-size: clamp(17px, 5cqi, 20px);
  text-align: left;
  margin: 0 0 12px;
  color: var(--color-text);
}

.guest-card__options {
  display: flex;
  gap: 8px;
}

/* Figma — 161×48 / 158×48 cream buttons */
.guest-option {
  flex: 1;
  background: var(--color-cream);
  color: var(--color-text);
  font-family: var(--font-belleza);
  font-size: clamp(16px, 4.5cqi, 20px);
  padding: 10px 8px;
  border-radius: 11px;
  min-height: 48px;
  transition: box-shadow 0.2s, background 0.2s;
}

.guest-option--active {
  background: var(--color-cream);
  box-shadow: inset 0 0 0 2px var(--color-text);
}

.guest-option:not(.guest-option--active):hover {
  background: #ebe9d4;
}

/* Figma node 87:536 — 103×34 confirm button */
.btn--confirm {
  align-self: center;
  font-family: var(--font-bellota);
  font-weight: 700;
  font-size: 14px;
  min-width: 103px;
  min-height: 34px;
  padding: 8px 24px;
  margin-top: clamp(8px, 2dvh, 16px);
  border-radius: 11px;
}

/* ── Toast ────────────────────────────────────────── */

.toast {
  position: fixed;
  bottom: max(24px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--color-text);
  color: var(--color-cream);
  font-family: var(--font-bellota);
  font-size: 14px;
  padding: 12px 24px;
  border-radius: 11px;
  opacity: 0;
  transition: transform 0.3s, opacity 0.3s;
  z-index: 100;
  max-width: calc(var(--content-width) - 40px);
  text-align: center;
  pointer-events: none;
}

.toast--visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* ── Desktop refinements ──────────────────────────── */

@media (min-width: 768px) {
  .hero__content {
    padding: 0 24px;
    gap: 12px;
  }

  .hero__photo-card {
    width: min(var(--card-width-pct), 320px);
  }

  .hero__monogram {
    width: min(34cqi, 149px);
  }

  .hero__family-name {
    font-size: 21px;
  }

  .hero__invite-text {
    font-size: 17px;
  }

  .guest-option {
    font-size: 18px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .page {
    transition: none;
  }

  .hero__photo-card-cover,
  .hero__photo-card--lift .hero__photo-card-scene,
  .hero--opening .hero__families,
  .hero--opening .hero__invite-text,
  .hero--opening .hero__footer,
  .hero--opening .hero__header,
  .hero--opening .hero__bg,
  .hero--card-expanding .hero__photo-card,
  .hero__photo-hint {
    transition: none;
  }

  .page--reveal-in {
    animation: none;
  }

  .hero__photo-card,
  .btn,
  .page-back,
  .scroll-hint,
  .scroll-hint__inner {
    transition: none;
  }
}
