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

html {
  -webkit-tap-highlight-color: transparent;
}

html.envelope-closed,
html.envelope-opening,
html.card-emerging {
  overflow: hidden;
  height: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: Vazirmatn, Tahoma, sans-serif;
  background:
    url('../images/bg-wedding.png') center center / cover no-repeat fixed,
    #fcfbf4;
  color: #3a3428;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 80% 60% at 50% 40%, rgba(255, 255, 255, 0.18), transparent 65%),
    linear-gradient(180deg, rgba(252, 251, 244, 0.06) 0%, rgba(240, 232, 210, 0.14) 100%);
}

body.envelope-closed,
body.envelope-opening,
body.card-emerging {
  overflow: hidden;
  height: 100dvh;
}

body.card-resting,
body.invitation-open {
  overflow-x: hidden;
  overflow-y: auto;
  height: auto;
}

body.card-resting {
  background:
    url('../images/bg-wedding.png') center center / cover no-repeat fixed,
    #fcfbf4;
}

body.invitation-open {
  background: #080808;
}

:root {
  --cream: #f0edda;
  --gold: #b8863a;
  --ink: #3a3428;
  --card-radius: 16px;
}

.ambient-canvas {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: 0.85;
  transition: opacity 1.2s ease;
}

.toolbar {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  z-index: 60;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
}

.toolbar-btn {
  pointer-events: auto;
  width: 42px;
  height: 42px;
  border: 1px solid rgba(120, 90, 50, 0.22);
  background: rgba(255, 252, 245, 0.88);
  backdrop-filter: blur(8px);
  color: var(--gold);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: transform 0.25s ease, box-shadow 0.25s ease, background 0.25s ease;
}

.toolbar-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 20px rgba(184, 134, 58, 0.22);
}

.toolbar-btn[hidden] { display: none !important; }

body.envelope-closed .toolbar-btn--music,
body.envelope-opening .toolbar-btn--music,
body.card-emerging .toolbar-btn--music,
body.card-resting .toolbar-btn--music {
  opacity: 1;
  pointer-events: auto;
}

body.invitation-open .toolbar-btn {
  border-color: rgba(216, 182, 107, 0.28);
  background: rgba(12, 10, 8, 0.72);
  color: #d8b66b;
}

.envelope-intro {
  position: relative;
  z-index: 20;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding:
    max(64px, env(safe-area-inset-top))
    20px
    max(48px, env(safe-area-inset-bottom));
  background: transparent;
  overflow: hidden;
}

.envelope-intro::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 70% 55% at 50% 45%, rgba(255, 255, 255, 0.22), transparent 70%);
  pointer-events: none;
  animation: introGlow 6s ease-in-out infinite;
}

.envelope-intro::after {
  content: "";
  position: absolute;
  inset: -20%;
  background:
    radial-gradient(circle, rgba(216, 182, 107, 0.1) 0 1px, transparent 2px);
  background-size: 32px 32px;
  opacity: 0.28;
  pointer-events: none;
  animation: bgShimmer 22s linear infinite;
}

@keyframes bgShimmer {
  0% { transform: translate3d(0, 0, 0); }
  100% { transform: translate3d(16px, 20px, 0); }
}

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

.envelope-intro.is-done,
body.invitation-open .envelope-intro {
  display: none;
}

body.card-emerging .envelope-intro,
body.card-resting .envelope-intro {
  min-height: 100dvh;
  justify-content: center;
  padding-top: max(72px, calc(env(safe-area-inset-top) + 48px));
  padding-bottom: max(48px, calc(env(safe-area-inset-bottom) + 28px));
}

.stage {
  position: relative;
  z-index: 1;
  width: min(calc(100vw - 40px), 460px);
  perspective: 1600px;
  perspective-origin: 50% 0%;
  animation: stageEnter 1.4s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes stageEnter {
  from {
    opacity: 0;
    transform: translateY(32px) scale(0.94);
    filter: blur(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
    filter: blur(0);
  }
}

.envelope {
  position: relative;
  width: 100%;
  aspect-ratio: 2048 / 1331;
  overflow: hidden;
  cursor: pointer;
  box-shadow:
    0 24px 56px rgba(70, 50, 20, 0.26),
    0 0 0 1px rgba(255, 255, 255, 0.35);
  background: #c8c8c8;
  transition: box-shadow 0.6s ease, transform 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}

body.envelope-closed .envelope {
  animation: envelopeFloat 5s ease-in-out infinite;
}

body.envelope-closed .envelope:hover {
  animation-play-state: paused;
  transform: translateY(-4px) scale(1.008);
  box-shadow:
    0 32px 64px rgba(70, 50, 20, 0.32),
    0 0 0 1px rgba(255, 255, 255, 0.45);
}

@keyframes envelopeFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.env-sheet {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.env-img--sheet {
  object-fit: cover;
}

.env-body {
  position: absolute;
  inset: 0;
  z-index: 1;
}

.envelope.is-opening,
.envelope.is-open {
  overflow: visible;
}

.envelope.is-open {
  cursor: default;
}

.envelope:focus-visible {
  outline: 1px solid rgba(184, 134, 58, 0.45);
  outline-offset: 8px;
}

.env-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  object-fit: fill;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.env-shadow {
  position: absolute;
  left: 8%;
  right: 8%;
  bottom: -18px;
  height: 26px;
  z-index: 0;
  background: radial-gradient(ellipse, rgba(60, 45, 20, 0.28) 0%, transparent 70%);
  filter: blur(8px);
  pointer-events: none;
}

.env-body {
  position: absolute;
  inset: 0;
  z-index: 1;
}

.card-slot {
  position: absolute;
  inset: 0;
  z-index: 2;
  overflow: hidden;
  clip-path: inset(0);
  pointer-events: none;
}

.envelope.is-opening .card-slot,
.envelope.is-open .card-slot {
  overflow: visible;
  clip-path: inset(-280% 1.2% 1.6% 1.2%);
}

.envelope.is-open .card-slot {
  pointer-events: auto;
}

body.card-resting .card-slot {
  z-index: 12;
}

body.card-resting .env-pocket {
  z-index: 4;
}

.invitation-card {
  position: absolute;
  left: 13.5%;
  width: 73%;
  height: 122%;
  top: 35%;
  bottom: auto;
  z-index: 2;
  overflow: hidden;
  pointer-events: none;
  transform-origin: 50% 100%;
  background: #111;
  border-radius: var(--card-radius);
  box-shadow: 0 14px 32px rgba(40, 28, 12, 0.28);
  opacity: 0;
  visibility: hidden;
  transition:
    transform 1s cubic-bezier(0.22, 1, 0.36, 1),
    left 0.9s cubic-bezier(0.22, 1, 0.36, 1),
    width 0.9s cubic-bezier(0.22, 1, 0.36, 1),
    box-shadow 0.8s ease,
    border-radius 0.9s cubic-bezier(0.22, 1, 0.36, 1),
    opacity 0.35s ease;
}

.invitation-card.is-tucked {
  transform: translate3d(0, 6%, 0);
}

body.envelope-opening .invitation-card,
body.card-emerging .invitation-card,
body.card-resting .invitation-card {
  opacity: 1;
  visibility: visible;
}

.invitation-card.is-emerging {
  transform: translate3d(0, -24%, 0) scale(1.01);
  transition-duration: 0.85s;
  animation: cardSlideUp 0.85s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.invitation-card.is-rising {
  transform: translate3d(0, -96%, 0) scale(1.015);
  transition-duration: 1.05s;
  transition-timing-function: cubic-bezier(0.16, 1, 0.3, 1);
}

.invitation-card.is-resting {
  z-index: 12;
  left: 10%;
  width: 80%;
  transform: translate3d(0, -48%, 0) scale(1);
  transition-duration: 1.15s;
  transition-timing-function: cubic-bezier(0.34, 1.12, 0.64, 1);
  pointer-events: auto;
  cursor: pointer;
  border-radius: var(--card-radius);
  box-shadow:
    0 28px 60px rgba(30, 18, 8, 0.38),
    0 2px 0 rgba(255, 255, 255, 0.08);
  animation: cardGlow 3.2s ease-in-out infinite;
}

.invitation-card.is-resting:hover {
  transform: translate3d(0, -50%, 0) scale(1.012);
  box-shadow:
    0 36px 72px rgba(30, 18, 8, 0.44),
    0 0 0 3px rgba(216, 182, 107, 0.22);
}

.invitation-card.is-expanding {
  border-radius: var(--card-radius);
}

@keyframes cardSlideUp {
  from { filter: brightness(0.92); }
  to { filter: brightness(1); }
}

@keyframes cardGlow {
  0%, 100% {
    box-shadow:
      0 28px 60px rgba(30, 18, 8, 0.38),
      0 0 0 0 rgba(216, 182, 107, 0);
  }
  50% {
    box-shadow:
      0 32px 68px rgba(30, 18, 8, 0.42),
      0 0 0 5px rgba(216, 182, 107, 0.14);
  }
}

.card-paper {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  user-select: none;
  border-radius: inherit;
}

.card-html {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: #080808;
  border-radius: inherit;
}

.invitation-card.is-emerging .card-html,
.invitation-card.is-rising .card-html,
.invitation-card.is-resting .card-html {
  overflow: hidden;
}

.invitation-card.is-page {
  position: relative;
  left: auto;
  top: auto;
  bottom: auto;
  width: 100%;
  height: auto;
  overflow: visible;
  pointer-events: auto;
  transform: none;
  box-shadow: none;
  background: #080808;
  cursor: default;
  opacity: 1;
  visibility: visible;
  border-radius: 0;
  animation: pageReveal 0.8s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes pageReveal {
  from { opacity: 0.85; }
  to { opacity: 1; }
}

.invitation-card.is-page .card-paper {
  display: none;
}

.invitation-card.is-page .card-html {
  position: relative;
  inset: auto;
  overflow: visible;
  background: transparent;
}

body.invitation-open .invite-root,
body.invitation-open .invite-root .wrap {
  height: auto;
  min-height: 100%;
  overflow: visible;
}

body.invitation-open .invite-root .hero {
  min-height: 100svh;
  height: auto;
}

body.card-resting .invite-root,
body.card-resting .invite-root .wrap {
  height: 100%;
  min-height: 0;
  max-width: none;
  margin: 0;
  overflow: hidden;
}

body.card-resting .invite-root .hero {
  min-height: 100%;
  height: 100%;
}

body.card-resting .invite-root .hero-content {
  padding: 18px 12px 22px;
}

body.card-resting .invite-root .names {
  font-size: clamp(28px, 7.6vw, 44px);
}

body.card-emerging .invite-root,
body.card-emerging .invite-root .wrap {
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

body.card-emerging .invite-root .hero {
  min-height: 100%;
  height: 100%;
}
body.envelope-closed .invite-root,
body.envelope-opening .invite-root,
body.envelope-closed .invite-root .wrap,
body.envelope-opening .invite-root .wrap {
  height: 100%;
  min-height: 0;
  max-width: none;
  margin: 0;
  overflow: hidden;
  background: #111;
}

body.envelope-closed .invite-root .hero,
body.envelope-opening .invite-root .hero {
  min-height: 100%;
  height: 100%;
}

body.envelope-closed .invite-root .hero-content,
body.envelope-opening .invite-root .hero-content {
  padding: 14px 10px 18px;
}

body.envelope-closed .invite-root .names,
body.envelope-opening .invite-root .names {
  font-size: clamp(26px, 7.4vw, 38px);
  margin: 8px 0 4px;
}

body.envelope-closed .invite-root .and,
body.envelope-opening .invite-root .and {
  font-size: 0.48em;
}

body.envelope-closed .invite-root .date,
body.envelope-opening .invite-root .date {
  margin-top: 10px;
  font-size: 12px;
}

body.envelope-closed .invite-root .kicker,
body.envelope-opening .invite-root .kicker {
  font-size: 9px;
  letter-spacing: 0.28em;
}

.env-shell {
  position: absolute;
  inset: 0;
  z-index: 1;
}

.env-pocket {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  clip-path: polygon(0 47%, 50% 34%, 100% 47%, 100% 100%, 0 100%);
}

.env-flap-shadow {
  position: absolute;
  left: 0;
  width: 100%;
  height: auto;
  z-index: 5;
  pointer-events: none;
  opacity: 0.72;
  mix-blend-mode: multiply;
  transition: opacity 0.55s ease;
}

.envelope.is-opening .env-flap-shadow,
.envelope.is-open .env-flap-shadow {
  opacity: 0;
}

.env-flap {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 65.4%;
  z-index: 6;
  transform-origin: 50% 0%;
  transform: perspective(1600px) rotateX(0deg);
  pointer-events: none;
  transition: transform 0.95s cubic-bezier(0.65, 0, 0.35, 1);
  will-change: transform;
}

.env-flap.is-open {
  transform: perspective(1600px) rotateX(168deg);
}

.env-flap.is-behind {
  z-index: 0;
}

.wax-seal {
  position: absolute;
  left: 50%;
  top: 63.2%;
  width: 20%;
  aspect-ratio: 1;
  z-index: 8;
  transform: translate(-50%, -50%);
  pointer-events: none;
  filter: drop-shadow(0 8px 16px rgba(80, 55, 15, 0.38));
  transition: opacity 0.38s ease, transform 0.38s ease, filter 0.38s ease;
}

body.envelope-closed .wax-seal {
  animation: sealBreath 3s ease-in-out infinite;
}

@keyframes sealBreath {
  0%, 100% { filter: drop-shadow(0 6px 14px rgba(60, 40, 10, 0.35)); }
  50% { filter: drop-shadow(0 10px 20px rgba(120, 80, 20, 0.42)); }
}

.wax-seal.is-releasing {
  animation: none;
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.82) rotate(-8deg);
  filter: drop-shadow(0 2px 6px rgba(60, 40, 10, 0.12));
}

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

.intro-hint {
  position: relative;
  z-index: 1;
  margin: 26px 0 0;
  font-size: 13px;
  color: rgba(90, 70, 45, 0.82);
  text-align: center;
  transition: opacity 0.25s ease;
  animation: hintFloat 3s ease-in-out infinite;
  text-shadow: 0 1px 8px rgba(255, 255, 255, 0.6);
}

@keyframes hintFloat {
  0%, 100% { opacity: 0.75; transform: translateY(0); }
  50% { opacity: 1; transform: translateY(-5px); }
}

.intro-hint.is-hidden {
  opacity: 0;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.55);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.35s ease, visibility 0.35s ease;
  backdrop-filter: blur(6px);
}

.modal-overlay.show {
  opacity: 1;
  visibility: visible;
}

.modal {
  width: 100%;
  max-width: 360px;
  padding: 26px 20px;
  background: rgba(250, 248, 242, 0.96);
  border: 1px solid rgba(120, 90, 50, 0.16);
  border-radius: 20px;
  text-align: center;
  box-shadow: 0 24px 64px rgba(40, 28, 12, 0.28);
  transform: scale(0.92) translateY(12px);
  transition: transform 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}

.modal-overlay.show .modal {
  transform: scale(1) translateY(0);
}

.modal h3 { margin: 0 0 10px; color: var(--gold); font-weight: 500; }
.modal p { margin: 0 0 14px; font-size: 13px; color: #7a7268; }
.modal input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid rgba(120, 90, 50, 0.18);
  background: #fff;
  font-family: inherit;
  direction: ltr;
  text-align: left;
}

.modal-actions { display: flex; gap: 10px; margin-top: 14px; }

.modal .btn {
  flex: 1;
  padding: 11px 16px;
  border: 1px solid rgba(184, 134, 58, 0.35);
  background: rgba(184, 134, 58, 0.08);
  font-family: inherit;
  cursor: pointer;
}

@media (prefers-reduced-motion: reduce) {
  .wax-seal,
  .envelope,
  .intro-hint,
  .stage,
  .invitation-card.is-resting {
    animation: none;
  }
  .env-flap,
  .invitation-card,
  .wax-seal {
    transition: none;
  }
}
