/* Opening: palace wall frame + two 3D doors */
.opening {
  position: fixed;
  inset: 0;
  z-index: 10;
  overflow: hidden;
  pointer-events: none;
}
/* palace-wall colour from the very first paint until the door images are loaded: the page never flashes before the doors */
body.is-loading .opening { background: #d79d7d; }

/* The stage keeps the artwork's aspect ratio and covers the viewport (sized in stage.js) */
.opening__stage {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  will-change: transform, opacity;
}

.opening__frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
}

/* Doorway: positioned from assets/card/layout.json (percent of the frame) */
.doorway {
  position: absolute;
  z-index: 1;
  perspective: 1600px;
  perspective-origin: 50% 45%;
}

/* fills the hairline where the doors' soft edge meets the frame's soft edge (else the page shows through) */
.doorway__fill { position: absolute; inset: 0; background: #d39a72; }

.door {
  position: absolute;
  top: 0;
  width: 50%;
  height: 100%;
  transform-style: preserve-3d;
  will-change: transform;
}

.door--left  { left: 0;  transform-origin: 0% 50%; }
.door--right { right: 0; transform-origin: 100% 50%; }

.door__face {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.door__face--back { transform: rotateY(180deg); filter: brightness(0.85); }

/* the couple's crest, centred on the seam between the top and middle panels; each door shows its own half */
.door__crest {
  position: absolute;
  top: 36%;
  width: 124%;            /* = 62% of the doorway */
  max-width: none;
  aspect-ratio: 1;
  transform: translateY(-50%);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  filter: drop-shadow(0 3px 4px rgba(90, 55, 20, 0.35)); /* sits raised on the door */
  pointer-events: none;
}
.door--left  .door__crest { left: 38%;  clip-path: inset(0 50% 0 0); }
.door--right .door__crest { left: -62%; clip-path: inset(0 0 0 50%); }

/* Light leaking through the seam before and during opening */
.doorway__glow {
  position: absolute;
  left: 50%;
  top: 0;
  width: 6%;
  height: 100%;
  transform: translateX(-50%);
  background: radial-gradient(ellipse at center, rgba(255, 236, 190, .95) 0%, rgba(255, 210, 140, .5) 35%, rgba(255, 200, 120, 0) 70%);
  mix-blend-mode: screen;
  opacity: 0;
  z-index: 3;
}

.opening__petals {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 5;
}

/* Warm light that floods the screen as we pass through the doorway */
.opening__light {
  position: fixed;
  inset: 0;
  z-index: 6;
  background: radial-gradient(ellipse at 50% 50%, #fffaf0 0%, #fff3dc 45%, #f6e3c2 100%);
  opacity: 0;
  pointer-events: none;
}

/* Gentle note on the closed doors (no/unknown invitation link, or no connection) */
.door-note {
  position: absolute;
  inset: 0;
  z-index: 7;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 18px;
  pointer-events: none;
}
.door-note__card {
  pointer-events: auto;
  width: min(440px, 100%);
  padding: 22px 24px 20px;
  text-align: center;
  background: rgba(253, 248, 238, 0.94) url("../assets/paper/paper.webp") repeat;
  background-size: 400px;
  border: 1.5px solid #b0803a;
  border-radius: 14px;
  box-shadow: 0 12px 30px rgba(60, 30, 10, 0.35), inset 0 0 0 5px rgba(253, 248, 238, 0.9), inset 0 0 0 6px rgba(176, 128, 58, 0.55);
  color: #6b4a32;
  font-family: var(--font-serif);
}
.door-note__title { margin: 0 0 6px; font-family: var(--font-script); font-size: 40px; line-height: 1.1; color: #a6742e; }
.door-note__line { margin: 6px 0 0; font-size: 15px; line-height: 1.5; }
.door-note__retry {
  margin-top: 14px;
  padding: 0.55em 1.6em;
  border: 1.5px solid #b0803a;
  border-radius: 999px;
  background: #fff8ea;
  font: inherit;
  color: #7a4e1e;
  cursor: pointer;
}

/* Waiting lamp in the centre of the doors while the invitation is checked */
.door-wait {
  position: absolute;
  inset: 0;
  z-index: 7;
  display: grid;
  place-content: center;
  justify-items: center;
  text-align: center;
  pointer-events: none;
  isolation: isolate;
}
/* a soft glow of light behind the lamp and words (fades out at the edges, no box) */
.door-wait::before {
  content: "";
  position: absolute;
  left: 50%;
  top: var(--glow-y, 50%);
  width: 300px;
  height: 230px;
  transform: translate(-50%, -50%);
  background: radial-gradient(ellipse at center, rgba(255, 249, 236, 0.97) 0%, rgba(255, 246, 228, 0.9) 42%, rgba(255, 244, 225, 0) 72%);
  z-index: -1;
}
.door-wait__lamp { position: relative; width: 74px; }
.door-wait__lamp img { display: block; width: 100%; }
.door-wait__flame {
  position: absolute;
  left: 9.8%;
  top: 49%;
  width: 34%;
  aspect-ratio: 0.55;
  transform: translate(-50%, -100%);
  transform-origin: 50% 100%;
  border-radius: 50% 50% 50% 50% / 62% 62% 38% 38%;
  background: radial-gradient(ellipse at 50% 75%, #fff8d6 0 18%, #ffd36b 35%, #ff9a2e 62%, rgba(255, 120, 30, 0) 75%);
  filter: drop-shadow(0 0 8px rgba(255, 170, 60, 0.95));
  animation: wait-flicker 1.4s ease-in-out infinite;
}
@keyframes wait-flicker {
  0%, 100% { transform: translate(-50%, -100%) scale(1, 1) rotate(-2deg); }
  35% { transform: translate(-50%, -100%) scale(0.9, 1.1) rotate(2deg); }
  65% { transform: translate(-50%, -100%) scale(1.06, 0.94) rotate(-1deg); }
}
.door-wait__title { margin: 6px 0 0; font-family: var(--font-script); font-size: 40px; line-height: 1.1; color: #96621f; }
.door-wait__line { margin: 2px 0 0; font-family: var(--font-serif); font-size: 15px; font-style: italic; color: #5e3f28; }
.door-wait__dots i { font-style: normal; animation: wait-dot 1.2s infinite; opacity: 0.2; }
.door-wait__dots i:nth-child(2) { animation-delay: 0.2s; }
.door-wait__dots i:nth-child(3) { animation-delay: 0.4s; }
@keyframes wait-dot { 0%, 100% { opacity: 0.2; } 40% { opacity: 1; } }

/* while the door images are still downloading (slow networks): a soft "Swagatam" so the screen shows life */
body.is-loading .opening::after {
  content: "Swagatam";
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  font: 400 42px/1 var(--font-script);
  color: #fff6e6;
  text-shadow: 0 2px 10px rgba(120, 50, 20, 0.35);
  animation: loading-breathe 2.4s ease-in-out infinite;
}
@keyframes loading-breathe { 0%, 100% { opacity: 0.45; } 50% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { body.is-loading .opening::after { animation: none; opacity: 0.85; } }
