:root {
  --bg: #f3efe6;
  --bg-deep: #ebe4d6;
  --ink: #2a2420;
  --ink-soft: #5c534c;
  --red: #9c2f32;
  --red-deep: #7a2225;
  --line: rgba(156, 47, 50, 0.22);
  --paper: #faf7f0;
  --shadow: 0 22px 50px rgba(74, 42, 30, 0.18);
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --font-display: "Ma Shan Zheng", "Noto Serif SC", serif;
  --font-serif: "Noto Serif SC", "Songti SC", serif;
  --font-latin: "Cormorant Garamond", "Times New Roman", serif;
}

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

html {
  scroll-behavior: auto;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--font-serif);
  background:
    radial-gradient(120% 80% at 50% -10%, rgba(156, 47, 50, 0.08), transparent 55%),
    radial-gradient(90% 60% at 100% 20%, rgba(201, 160, 120, 0.12), transparent 50%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-deep) 100%);
  overflow-x: hidden;
}

body.is-gated {
  overflow: hidden;
  height: 100vh;
  height: 100dvh;
}

img {
  max-width: 100%;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}

[hidden] {
  display: none !important;
}

/* Gate */
.gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 32px 24px;
  background:
    radial-gradient(80% 60% at 50% 30%, rgba(156, 47, 50, 0.12), transparent 60%),
    linear-gradient(180deg, #f7f2e8 0%, #ebe3d4 100%);
  transition: opacity 0.55s var(--ease-out), visibility 0.55s;
}

.gate.is-leaving {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.gate__inner {
  text-align: center;
  max-width: 360px;
}

.gate__eyebrow {
  margin: 0 0 18px;
  font-family: var(--font-latin);
  font-style: italic;
  letter-spacing: 0.22em;
  color: var(--red);
}

.gate__title {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(2.2rem, 9vw, 3rem);
  font-weight: 400;
  letter-spacing: 0.08em;
}

.gate__title span {
  color: var(--red);
  margin: 0 0.15em;
}

.gate__lead {
  margin: 16px 0 36px;
  color: var(--ink-soft);
  letter-spacing: 0.18em;
  font-size: 0.95rem;
}

.gate__btn {
  width: auto;
  min-width: 180px;
}

/* Music */
.music-btn {
  position: fixed;
  top: calc(16px + env(safe-area-inset-top));
  right: 16px;
  z-index: 40;
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(250, 247, 240, 0.92);
  backdrop-filter: blur(8px);
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
}

.music-btn__disc {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--red);
  box-shadow: inset 0 0 0 3px var(--paper);
  background: var(--red);
}

.music-btn[aria-pressed="true"] .music-btn__disc {
  animation: spin-disc 3.2s linear infinite;
}

@keyframes spin-disc {
  to { transform: rotate(360deg); }
}

/* Scroll hint */
.scroll-hint {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(28px + env(safe-area-inset-bottom));
  z-index: 30;
  text-align: center;
  pointer-events: none;
  transition: opacity 0.45s var(--ease-out), transform 0.45s var(--ease-out);
}

.scroll-hint.is-hidden {
  opacity: 0;
  transform: translateY(12px);
}

.scroll-hint__text {
  margin: 0 0 10px;
  font-size: 0.95rem;
  letter-spacing: 0.28em;
  color: var(--red);
}

.scroll-hint__arrow {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-right: 1.5px solid var(--red);
  border-bottom: 1.5px solid var(--red);
  transform: rotate(45deg);
  animation: hint-bounce 1.6s var(--ease-out) infinite;
}

@keyframes hint-bounce {
  0%, 100% { transform: translateY(0) rotate(45deg); opacity: 0.35; }
  50% { transform: translateY(8px) rotate(45deg); opacity: 1; }
}

/* Flip stage — preserve-3d 不能加在带 filter 的节点上 */
.flip-stage {
  height: 360vh;
  position: relative;
}

.flip-stage__sticky {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 20px 72px;
  perspective: 1600px;
  perspective-origin: 50% 45%;
  -webkit-perspective: 1600px;
}

.invite-scene {
  width: min(78vw, 340px);
  aspect-ratio: 1560 / 3139;
  max-height: min(70vh, 620px);
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
}

.invite-card {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
  will-change: transform;
}

.invite-card__face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 12px;
  overflow: hidden;
  background: var(--paper);
  box-shadow: var(--shadow);
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
}

.invite-card__face--front {
  transform: translateZ(1.5px);
  -webkit-transform: translateZ(1.5px);
}

.invite-card__face--back {
  transform: rotateY(180deg) translateZ(1.5px);
  -webkit-transform: rotateY(180deg) translateZ(1.5px);
}

.invite-card__face img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.flip-progress {
  margin: 22px 0 0;
  font-family: var(--font-latin);
  font-style: italic;
  font-size: 0.95rem;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  opacity: 0.85;
}

body.is-revealed .flip-stage {
  height: 0;
  overflow: hidden;
  pointer-events: none;
}

body.is-revealed .scroll-hint {
  opacity: 0;
  visibility: hidden;
}

/* Reveal */
.reveal {
  position: relative;
  z-index: 5;
  padding-bottom: calc(48px + env(safe-area-inset-bottom));
}

body.is-revealed .reveal {
  animation: reveal-rise 0.9s var(--ease-out) both;
}

@keyframes reveal-rise {
  from { opacity: 0; transform: translateY(40px); }
  to { opacity: 1; transform: translateY(0); }
}

.panel {
  max-width: 520px;
  margin: 0 auto;
  padding: 64px 28px 40px;
  text-align: center;
}

.panel--hero {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding-top: 48px;
}

.panel__eyebrow {
  margin: 0 0 12px;
  font-family: var(--font-latin);
  font-style: italic;
  font-size: 1.05rem;
  letter-spacing: 0.22em;
  color: var(--red);
}

.panel__title {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 9vw, 3.4rem);
  font-weight: 400;
  line-height: 1.2;
  color: var(--ink);
}

.panel__lead {
  margin: 14px 0 0;
  color: var(--ink-soft);
  font-size: 0.98rem;
  letter-spacing: 0.12em;
}

.when-block {
  margin-top: 36px;
  padding: 22px 18px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.when-block__solar {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: 0.06em;
}

.when-block__lunar {
  margin: 10px 0 0;
  color: var(--red);
  letter-spacing: 0.18em;
  font-size: 0.92rem;
}

.names {
  margin-top: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  font-family: var(--font-display);
  font-size: 1.35rem;
}

.names__heart {
  font-style: normal;
  color: var(--red);
  font-size: 1.6rem;
}

.place__name {
  margin: 28px 0 8px;
  font-size: 1.2rem;
  font-weight: 600;
  letter-spacing: 0.08em;
}

.place__addr {
  margin: 0 0 28px;
  color: var(--ink-soft);
  letter-spacing: 0.16em;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 28px;
  border-radius: 999px;
  text-decoration: none;
  font-family: var(--font-serif);
  font-size: 0.98rem;
  letter-spacing: 0.18em;
  cursor: pointer;
  transition: transform 0.25s var(--ease-out), background 0.25s ease, color 0.25s ease;
}

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

.btn--outline {
  border: 1px solid var(--red);
  color: var(--red);
  background: transparent;
}

.btn--primary {
  width: 100%;
  border: none;
  color: #fff;
  background: linear-gradient(180deg, var(--red) 0%, var(--red-deep) 100%);
  box-shadow: 0 10px 24px rgba(156, 47, 50, 0.28);
}

.btn--primary:disabled {
  opacity: 0.65;
  cursor: wait;
}

/* Photos */
.panel--photos {
  max-width: none;
  padding-left: 0;
  padding-right: 0;
}

.panel--photos .panel__eyebrow,
.panel--photos .panel__title,
.panel--photos .panel__lead {
  padding: 0 28px;
}

/* 3D Album */
.album {
  margin-top: 28px;
  padding: 0 16px;
}

.album__stage {
  position: relative;
  height: min(58vh, 440px);
  perspective: 1200px;
  -webkit-perspective: 1200px;
  touch-action: pan-y;
}

.album__card {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(72vw, 280px);
  height: min(52vh, 400px);
  margin: 0;
  border-radius: 14px;
  overflow: hidden;
  background: var(--paper);
  box-shadow: var(--shadow);
  transform-origin: center center;
  transition: transform 0.55s var(--ease-out), opacity 0.45s ease, filter 0.45s ease;
  cursor: grab;
  user-select: none;
}

.album__card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}

.album__card.is-center {
  z-index: 5;
  cursor: grab;
}

.album__card.is-prev {
  z-index: 3;
  opacity: 0.55;
  filter: brightness(0.9);
}

.album__card.is-next {
  z-index: 3;
  opacity: 0.55;
  filter: brightness(0.9);
}

.album__card.is-far {
  z-index: 1;
  opacity: 0;
  pointer-events: none;
}

.album__controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  margin-top: 18px;
}

.album__nav {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--red);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
}

.album__counter {
  margin: 0;
  min-width: 4.5em;
  font-family: var(--font-latin);
  font-style: italic;
  color: var(--ink-soft);
  letter-spacing: 0.06em;
}

/* Polaroid wall */
.polaroid-wall {
  margin: 48px auto 0;
  max-width: 640px;
  padding: 8px 20px 24px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 22px 14px;
  justify-items: center;
}

.polaroid {
  margin: 0;
  width: min(42vw, 200px);
  padding: 10px 10px 28px;
  background: #fffdf8;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.8) inset,
    0 14px 28px rgba(74, 42, 30, 0.14);
  border-radius: 2px;
  cursor: pointer;
  transition: transform 0.35s var(--ease-out), box-shadow 0.35s ease;
  animation: polaroid-in 0.7s var(--ease-out) both;
}

.polaroid:nth-child(odd) {
  transform: rotate(var(--tilt, -4deg));
}

.polaroid:nth-child(even) {
  transform: rotate(var(--tilt, 5deg));
  margin-top: 18px;
}

.polaroid:active,
.polaroid:hover {
  transform: rotate(0deg) scale(1.04);
  box-shadow: 0 18px 36px rgba(74, 42, 30, 0.22);
  z-index: 2;
}

.polaroid img {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  background: #eee;
}

.polaroid figcaption {
  margin-top: 10px;
  font-family: var(--font-latin);
  font-style: italic;
  font-size: 0.78rem;
  color: var(--ink-soft);
  letter-spacing: 0.04em;
}

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

/* Lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(30, 22, 18, 0.88);
}

.lightbox img {
  max-width: min(92vw, 720px);
  max-height: 82vh;
  object-fit: contain;
  border-radius: 6px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}

.lightbox__close {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top));
  right: 16px;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 1.8rem;
  line-height: 1;
  cursor: pointer;
}

.rsvp-form {
  margin: 32px auto 0;
  max-width: 360px;
  text-align: left;
}

.field {
  display: block;
  margin-bottom: 18px;
}

.field span {
  display: block;
  margin-bottom: 8px;
  font-size: 0.86rem;
  letter-spacing: 0.14em;
  color: var(--ink-soft);
}

.field input {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-serif);
  font-size: 1rem;
  outline: none;
}

.field input:focus {
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(156, 47, 50, 0.12);
}

.rsvp-form__msg {
  min-height: 1.4em;
  margin: 14px 0 0;
  text-align: center;
  font-size: 0.92rem;
  color: var(--red);
}

.closing {
  margin: 40px 0 0;
  font-family: var(--font-display);
  font-size: 1.35rem;
  color: var(--ink-soft);
  letter-spacing: 0.12em;
}

.confetti-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 50;
}

@media (min-width: 768px) {
  .invite-scene {
    width: min(42vw, 380px);
  }

  .polaroid-wall {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .polaroid {
    width: 180px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .scroll-hint__arrow,
  .music-btn[aria-pressed="true"] .music-btn__disc,
  .polaroid {
    animation: none;
  }

  body.is-revealed .reveal {
    animation: none;
  }
}
