* { box-sizing: border-box; }
html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #1a1712;
  touch-action: none;
  font-family: Georgia, "Times New Roman", serif;
}
body {
  display: block;
}
#stage {
  position: fixed;
  left: 0;
  top: 0;
  width: 100vw;
  width: 100dvw;
  height: 100dvh;
  overflow: hidden;
  background: #1a1712;
  perspective: 900px;
  -webkit-tap-highlight-color: transparent;
}
#shop {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  user-select: none;
  pointer-events: none;
}
.envelope {
  position: absolute;
  transform-style: preserve-3d;
  transform-origin: 50% 50%;
  will-change: left, top, width, height, transform;
  pointer-events: none;
}
.envelope-face {
  position: absolute;
  inset: 0;
  overflow: hidden;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background:
    linear-gradient(135deg, rgba(255,255,255,.78) 0%, rgba(255,255,255,0) 28%),
    linear-gradient(135deg, #fff8e8 0%, #f7e9c7 58%, #e9ca8a 100%);
  border: 1px solid #b8863f;
  box-shadow: 0 10px 24px rgba(0,0,0,.42);
}
.envelope-face::after {
  content: "";
  position: absolute;
  inset: auto 0 0 0;
  height: 10%;
  background: linear-gradient(to bottom, transparent, rgba(0,0,0,.16));
  pointer-events: none;
}

.envelope-back {
  position: absolute;
  inset: 0;
  overflow: hidden;
  transform: rotateY(180deg);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  box-shadow: 0 10px 24px rgba(0,0,0,.42);
  pointer-events: none;
}
.envelope-back-art {
  width: 100%;
  height: 100%;
  display: block;
}
.recipient-mark {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
  pointer-events: none;
}
.stamp {
  position: absolute;
  right: 5.5%;
  top: 6.5%;
  width: 12%;
  aspect-ratio: 1.2;
  display: grid;
  place-items: center;
  background: #f0d995;
  border: 1px solid #8f6427;
  color: #1d5948;
  font-size: clamp(8px, 3.2vw, 23px);
}
.hint {
  position: absolute;
  color: #e1be72;
  font-family: system-ui, sans-serif;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: .25px;
  text-align: center;
  text-shadow: 0 1px 3px rgba(19,37,31,.8);
  opacity: 0;
  pointer-events: none;
}

/* GATE C CLEAN REBUILD — sibling layer only. The approved Gate B back
   selectors above are intentionally untouched. */
.gate-c-back-assembly {
  position: absolute;
  inset: 0;
  overflow: visible;
  transform: rotateY(180deg);
  transform-style: preserve-3d;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  box-shadow: 0 10px 24px rgba(0,0,0,.42);
  visibility: hidden;
  pointer-events: none;
}
.gate-c-back-body {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
.gate-c-rear-flap {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 39%;
  transform-origin: 50% 0%;
  transform: rotateX(0rad);
  transform-style: preserve-3d;
  will-change: transform;
  pointer-events: none;
}
.gate-c-rear-flap-art {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
}


.gate-d-card {
  position: absolute;
  visibility: hidden;
  transform-origin: 50% 50%;
  transform-style: preserve-3d;
  will-change: left, top, width, height, transform;
  pointer-events: none;
}
.gate-d-card-art {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: transparent;
  border: 0;
  box-shadow: 0 10px 24px rgba(0,0,0,.26);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.gate-d-card-photo {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 26% 28%, rgba(255,255,255,.95), rgba(255,255,255,0) 22%),
    linear-gradient(180deg, #e9d09c 0%, #8d6742 100%);
  border: 0;
}
.gate-d-card-title {
  position: absolute;
  left: 8%;
  right: 8%;
  top: 72%;
  text-align: center;
  color: #1f5b4d;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(16px, 3.6vw, 36px);
  font-weight: 900;
}
.gate-d-card-subtitle {
  position: absolute;
  left: 8%;
  right: 8%;
  top: 82%;
  text-align: center;
  color: #8b6d37;
  font-family: system-ui, sans-serif;
  font-size: clamp(9px, 2.1vw, 18px);
  font-weight: 800;
  letter-spacing: .4px;
}
.gate-d-body-mask {
  position: absolute;
  visibility: hidden;
  pointer-events: none;
  box-shadow: 0 10px 24px rgba(0,0,0,.42);
}
.gate-d-body-mask-art {
  width: 100%;
  height: 100%;
  display: block;
}


/* BOOK OPEN CONTINUITY FIX
   The settled Gate D card is the SAME physical card during opening.
   No second/replacement card is swapped in, so there is no handoff resize. */
.gate-f-cover-hinge {
  position: absolute;
  inset: 0;
  transform-origin: 0% 50%;
  transform: rotateY(0rad);
  transform-style: preserve-3d;
  will-change: transform;
  z-index: 2;
}
.gate-f-cover-front {
  transform: rotateY(0deg);
}
.gate-f-cover-inside {
  position: absolute;
  inset: 0;
  background: #fff5dc;
  color: #3a2a1a;
  font-family: Georgia, "Times New Roman", serif;
  transform: rotateY(180deg);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
}
.gate-f-inside-right {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  visibility: hidden;
  background: #fff5dc;
  color: #3a2a1a;
  font-family: Georgia, "Times New Roman", serif;
  overflow: hidden;
  z-index: 1;
  will-change: width;
}
.gate-f-inside-right-content {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}
.gate-f-inside-heading {
  position: absolute;
  left: 8%;
  right: 8%;
  top: 8%;
  font-size: 17px;
  font-style: italic;
  font-weight: 700;
}
.gate-f-inside-message {
  position: absolute;
  left: 9%;
  right: 9%;
  top: 32%;
  text-align: center;
  font-size: 18px;
  line-height: 1.3;
  font-weight: 700;
}
.gate-f-inside-cover-message {
  position: absolute;
  left: 8%;
  right: 8%;
  top: 42%;
  text-align: center;
  font-size: 20px;
  line-height: 1.2;
  font-weight: 700;
  font-style: italic;
}
.gate-f-inside-signature {
  position: absolute;
  left: 8%;
  right: 8%;
  bottom: 7%;
  text-align: center;
  color: #b6a17a;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 11px;
  font-weight: 700;
}
.card-open-hint {
  position: absolute;
  left: 0;
  right: 0;
  top: 12px;
  opacity: 0;
  pointer-events: none;
  text-align: center;
  color: #ffe7a8;
  font-family: system-ui, sans-serif;
  font-size: 14px;
  font-weight: 800;
  text-shadow: 0 1px 4px rgba(19,37,31,.8);
}


/* INSIDE GESTURES — exact native one-direction-at-a-time indicators. */
.gate-g-indicator {
  position: absolute;
  top: 50%;
  width: 52px;
  height: 88px;
  margin-top: -44px;
  border: 0;
  padding: 0;
  background: transparent;
  color: #ffe7a8;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 50px;
  font-weight: 400;
  line-height: 1;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  text-shadow: 0 1px 5px rgba(19,37,31,.8);
  -webkit-tap-highlight-color: transparent;
}
.gate-g-left { left: 8px; }
.gate-g-right { right: 8px; }
.gate-g-indicator.is-visible {
  opacity: .68;
  visibility: visible;
  pointer-events: auto;
}


/* NATIVE-AUTHORITY CLOSED-CARD RETURN CONTROL.
   Hidden on the first closed-card stop. It appears only AFTER the recipient
   has opened the card and physically closed it again. */
.send-to-envelope-button {
  position: absolute;
  left: 50%;
  bottom: 12px;
  width: 178px;
  height: 42px;
  margin-left: -89px;
  border-radius: 18px;
  border: 1.5px solid #e1be72;
  background: #2f5d50;
  color: #fff3d6;
  font-family: system-ui, sans-serif;
  font-size: 15px;
  font-weight: 900;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  z-index: 40;
  -webkit-tap-highlight-color: transparent;
}
.send-to-envelope-button.is-visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

/* FINAL FRONT-FACING ENVELOPE ACTIONS — exact native ordering:
   Replay | Save Card | Get FlagnPaws
   Remove | Print/PDF */
.receiver-final-actions {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  z-index: 45;
}
.receiver-final-actions.is-visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}
.receiver-final-row {
  display: flex;
  justify-content: center;
  gap: 6px;
}
.receiver-final-button {
  width: 112px;
  height: 40px;
  padding: 0 6px;
  border-radius: 14px;
  border: 1.1px solid #6a4d14;
  background: #e1be72;
  color: #000;
  font-family: system-ui, sans-serif;
  font-size: 13px;
  font-weight: 900;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 0 2px 4px rgba(0,0,0,.28);
  -webkit-tap-highlight-color: transparent;
}


/* WRAP-UP 2D VISUAL PASS — envelope + buttons only. */
.envelope-front-face,
.envelope-back-face {
  background:
    radial-gradient(circle at 22% 18%, rgba(255,255,255,.78) 0%, rgba(255,255,255,0) 22%),
    linear-gradient(180deg, #fffef8 0%, #f4ead6 48%, #ead9bb 100%);
  box-shadow:
    0 1px 0 rgba(255,255,255,.72) inset,
    0 -1px 0 rgba(202,177,133,.82) inset,
    0 0 0 1px rgba(164,133,84,.55),
    0 10px 16px rgba(0,0,0,.20);
}
.envelope-front-face::before {
  background:
    linear-gradient(135deg, transparent 48.7%, rgba(208,180,136,.95) 48.8% 50.2%, transparent 50.3%),
    linear-gradient(225deg, transparent 48.7%, rgba(208,180,136,.95) 48.8% 50.2%, transparent 50.3%),
    linear-gradient(180deg, rgba(255,255,255,.10) 0%, rgba(177,139,86,.10) 100%);
  background-size: 50% 100%, 50% 100%, 100% 100%;
  background-position: left bottom, right bottom, 0 0;
  background-repeat: no-repeat;
}
.envelope-front-face::after {
  content: "";
  position: absolute;
  left: 10px;
  right: 10px;
  top: 10px;
  bottom: 10px;
  box-shadow:
    0 0 0 1px rgba(255,255,255,.18) inset,
    0 0 0 1px rgba(190,159,111,.24);
  pointer-events: none;
}
.envelope-back-face::before {
  background:
    linear-gradient(180deg, #efdfc3 0%, #dcc39b 100%);
  box-shadow: 0 1px 0 rgba(255,255,255,.38) inset;
}
.envelope-flap {
  background:
    radial-gradient(circle at 50% 12%, rgba(255,255,255,.56), rgba(255,255,255,0) 40%),
    linear-gradient(180deg, #f3e4c8 0%, #d4ba8f 100%);
  box-shadow:
    0 1px 0 rgba(255,255,255,.54) inset,
    0 -1px 0 rgba(169,135,82,.35) inset;
}
.stage-stamp {
  background:
    linear-gradient(180deg, rgba(255,255,255,.16), rgba(255,255,255,0)),
    linear-gradient(135deg, #6b916d 0%, #3a5d45 100%);
  box-shadow:
    0 0 0 1px rgba(255,255,255,.64) inset,
    0 0 0 1px rgba(59,94,63,.72),
    0 1px 4px rgba(0,0,0,.18);
}
.send-to-envelope-button,
.receiver-final-button {
  border: 1.5px solid #6a4d14;
  background:
    linear-gradient(180deg, #f9e59f 0%, #e7c77a 48%, #d1a650 100%);
  color: #000;
  box-shadow:
    0 1px 0 rgba(255,255,255,.55) inset,
    0 -1px 0 rgba(121,86,27,.34) inset,
    0 4px 8px rgba(0,0,0,.16);
}
.send-to-envelope-button {
  width: 198px;
  margin-left: -99px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.send-envelope-icon {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.send-envelope-icon svg,
.receiver-final-icon svg {
  fill: #111;
}
.send-envelope-icon svg {
  width: 16px;
  height: 16px;
  display: block;
}
.receiver-final-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}
.receiver-final-icon {
  width: 15px;
  height: 15px;
  flex: 0 0 15px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.receiver-final-icon svg {
  width: 15px;
  height: 15px;
  display: block;
}
.receiver-final-icon.pdf .pdf-cut {
  fill: #e7c77a;
}


/* GC SHOP LOADING HANDOFF — exact first-paint shop only.
   The exact approved shop is embedded in index.html for first paint and this
   external copy remains the same image underneath. No normal loading wording. */
.loading-cover {
  position: fixed;
  inset: 0;
  z-index: 2147483647;
  box-sizing: border-box;
  background: #d8bd83 url("memories_shop_fascia.png") center center / cover no-repeat;
  opacity: 1;
  visibility: visible;
  transition: opacity 120ms ease, visibility 120ms ease;
  pointer-events: auto;
}
.loading-cover.is-ready {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
.loading-cover-message { display: none; }
.loading-cover.is-error {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(15,22,18,.48);
}
.loading-cover.is-error .loading-cover-message {
  display: block;
  width: min(84vw, 420px);
  padding: 12px 16px;
  border-radius: 14px;
  background: rgba(255,245,220,.94);
  color: #702b22;
  text-align: center;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 17px;
  line-height: 1.25;
}


#stage.receiver-finished .receiver-final-actions {
  display: flex !important;
  opacity: 1 !important;
  visibility: visible !important;
  pointer-events: auto !important;
}

