/* ==========================================================================
   Act 1, 2 & 5: Tactile 3D Stationery Envelope
   ========================================================================== */

.scene--envelope {
  z-index: var(--z-envelope);
  display: grid;
  place-items: center;
  padding: calc(20px + var(--safe-top)) calc(18px + var(--safe-right))
    calc(28px + var(--safe-bottom)) calc(18px + var(--safe-left));
  pointer-events: auto;
}

.scene--envelope.is-hidden {
  pointer-events: none;
  visibility: hidden;
}

.envelope-stage-wrap {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* Soft luminous shadow + subtle starlight halo beneath envelope */
.envelope-ground-shadow {
  position: absolute;
  width: min(84vw, 410px);
  height: 44px;
  bottom: 20px;
  border-radius: 50%;
  background: radial-gradient(
    ellipse at center,
    rgba(2, 6, 18, 0.62) 0%,
    rgba(4, 10, 26, 0.28) 52%,
    rgba(4, 10, 26, 0) 78%
  );
  filter: blur(10px);
  transform: translateY(16px) scale(0.92);
  pointer-events: none;
  will-change: transform, opacity;
}

/* Interactive envelope container */
.envelope-wrapper {
  position: relative;
  width: min(82vw, 390px, calc((var(--app-h) - 140px) * 1.38));
  aspect-ratio: 400 / 260;
  display: block;
  will-change: transform, opacity;
  opacity: 0;
}

.envelope-3d {
  position: relative;
  width: 100%;
  height: 100%;
  perspective: 1100px;
  perspective-origin: 50% 20%;
  border-radius: 6px;
}

/* Back body with subtle starlight rim glow against dark night sky */
.env-back {
  position: absolute;
  inset: 0;
  z-index: 1;
  border-radius: 6px;
  background: linear-gradient(160deg, #FCF8F0 0%, #F1E8D8 100%);
  border: 1px solid rgba(255, 246, 228, 0.55);
  box-shadow:
    0 22px 48px -10px rgba(2, 6, 18, 0.65),
    0 0 36px -6px rgba(236, 214, 178, 0.26),
    inset 0 1px 0 rgba(255, 255, 255, 0.85);
}

.env-back::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 6px;
  background-image: url("../assets/textures/paper-grain.svg");
  background-size: 220px 220px;
  opacity: 0.55;
  pointer-events: none;
}

/* Inner soft champagne lining visible when flap opens */
.env-liner {
  position: absolute;
  inset: 4px 5px 5px 5px;
  z-index: 2;
  border-radius: 4px;
  background:
    radial-gradient(circle at 50% 25%, rgba(255, 252, 245, 0.75), rgba(232, 218, 198, 0.85)),
    repeating-linear-gradient(
      135deg,
      rgba(196, 174, 144, 0.07) 0px,
      rgba(196, 174, 144, 0.07) 2px,
      transparent 2px,
      transparent 10px
    );
  box-shadow: inset 0 8px 18px rgba(105, 84, 58, 0.14);
}

/* Rising letter sheet inside envelope pocket */
.env-letter-card {
  position: absolute;
  left: 6%;
  right: 6%;
  top: 9%;
  bottom: 11%;
  z-index: 3;
  border-radius: 4px;
  background: linear-gradient(180deg, #FDFBF7 0%, #F9F4EA 100%);
  box-shadow:
    0 4px 16px rgba(78, 62, 44, 0.12),
    0 0 0 1px rgba(196, 178, 152, 0.28);
  overflow: hidden;
  will-change: transform, opacity;
  transform: translate3d(0, 0, 0);
}

.env-letter-paper {
  position: relative;
  width: 100%;
  height: 100%;
  padding: 12% 13%;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.env-letter-paper::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: url("../assets/textures/paper-grain.svg");
  background-size: 200px 200px;
  opacity: 0.45;
  pointer-events: none;
}

.env-letter-line {
  height: 2px;
  width: 82%;
  border-radius: 2px;
  background: rgba(128, 112, 94, 0.16);
}

.env-letter-line--title {
  width: 44%;
  height: 3px;
  margin-bottom: 6px;
  background: rgba(128, 112, 94, 0.24);
}

.env-letter-line--short {
  width: 58%;
}

/* Front V-cut pocket */
.env-pocket {
  position: absolute;
  inset: 0;
  z-index: 4;
  border-radius: 6px;
  overflow: hidden;
  pointer-events: none;
}

.env-pocket::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: url("../assets/textures/paper-grain.svg");
  background-size: 220px 220px;
  opacity: 0.45;
  mix-blend-mode: multiply;
}

.env-pocket-svg {
  width: 100%;
  height: 100%;
  display: block;
}

.env-front-inscription {
  position: absolute;
  left: 12%;
  right: 12%;
  bottom: 13%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-align: center;
  z-index: 2;
}

.env-recipient-name {
  font-size: clamp(15px, 4.1vw, 19px);
  font-weight: 400;
  letter-spacing: 0.22em;
  color: var(--ink-primary);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.7);
}

.env-front-text {
  font-size: clamp(11px, 3vw, 13px);
  letter-spacing: 0.16em;
  color: var(--ink-muted);
}

/* Top triangular flap hinged tightly along top edge (y = 0) */
.env-flap {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 62%;
  z-index: 6;
  transform-origin: 50% 0%;
  transform-style: preserve-3d;
  will-change: transform;
  pointer-events: none;
}

.env-flap-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.env-flap-front {
  transform: rotateX(0deg);
}

/* rotateY(180deg) keeps y=0 locked to the top hinge while facing -Z until parent passes 90deg! */
.env-flap-back {
  transform: rotateY(180deg);
}

.env-flap-svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* Refined champagne-rose wax seal */
.env-seal {
  position: absolute;
  left: 50%;
  top: 56%;
  width: clamp(42px, 11.5vw, 52px);
  height: clamp(42px, 11.5vw, 52px);
  z-index: 8;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(
    circle at 36% 32%,
    #EFE0CE 0%,
    #DFC3A6 48%,
    #C7A484 100%
  );
  box-shadow:
    0 5px 12px rgba(96, 70, 48, 0.24),
    inset 0 2px 3px rgba(255, 250, 244, 0.65),
    inset 0 -3px 5px rgba(132, 98, 68, 0.34);
  display: grid;
  place-items: center;
  will-change: transform, opacity;
  pointer-events: none;
}

.env-seal-ring {
  position: absolute;
  inset: 5px;
  border-radius: 50%;
  border: 1px solid rgba(255, 248, 238, 0.55);
  box-shadow: inset 0 1px 2px rgba(136, 102, 72, 0.28);
}

.env-seal-mark {
  position: relative;
  font-size: clamp(12px, 3.2vw, 15px);
  letter-spacing: 0.04em;
  color: rgba(112, 82, 56, 0.82);
  text-shadow: 0 1px 0 rgba(255, 248, 240, 0.55);
}

.env-seal-mark:empty::after {
  content: "";
  display: block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  border: 1px solid rgba(122, 90, 62, 0.5);
  box-shadow: 0 0 0 3px rgba(255, 248, 238, 0.22);
}

/* Whisper-subtle starlight hint under envelope */
.envelope-hint {
  margin: 34px 0 0;
  min-height: 20px;
  font-size: 13px;
  letter-spacing: 0.26em;
  color: rgba(250, 242, 228, 0.9);
  text-shadow: 0 1px 12px rgba(4, 8, 22, 0.85);
  opacity: 0;
  pointer-events: none;
  text-align: center;
}

/* 2D fallback when preserve-3d is unsupported */
.no-3d .env-flap {
  transform-style: flat;
}

.no-3d .env-flap-back {
  display: none;
}

/* Landscape adaptation */
.is-landscape .envelope-wrapper {
  width: min(52vw, 370px, calc((var(--app-h) - 105px) * 1.44));
}

.is-landscape .envelope-hint {
  margin-top: 14px;
}
