/* ===== Card envelopes (envelope.js): illustrated, soft blush, velvet =====
   The wrapper is W wide and 1.45 W tall: the envelope body fills the bottom 46.9% (0.68 W),
   the flap is 29.06% (0.4214 W) and hinges on the body's top edge, the card is 0.86 W wide. */
.envw { position: relative; inline-size: min(100%, var(--env-w, 360px)); aspect-ratio: 1 / 1.45; margin-inline: auto; perspective: 1100px; direction: ltr; --e-soft: cubic-bezier(.22, 1, .36, 1); --e-pop: cubic-bezier(.34, 1.45, .64, 1); }
.envw > * { position: absolute; }
.ev-svg { display: block; inline-size: 100%; block-size: 100%; overflow: visible; }
.ev-back { inset-inline: 0; inset-block-end: 0; block-size: 46.9%; z-index: 0; filter: drop-shadow(0 16px 16px rgb(60 30 30 / .22)) drop-shadow(0 2px 2px rgb(60 30 30 / .12)); }
.ev-front { inset-inline: 0; inset-block-end: 0; block-size: 46.9%; z-index: 4; pointer-events: none; }
.ev-pocket { position: absolute; inset: 0; }

/* the flap: closed it lies over everything; opened it flips up behind the card and shows its liner */
.ev-flap { inset-inline: 0; inset-block-end: 17.84%; block-size: 29.06%; transform-origin: 50% 0; transform-style: preserve-3d; z-index: 5;
  transition: transform .62s var(--e-soft), z-index 0s .3s; }
.ev-face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.ev-face.in { transform: rotateX(180deg); visibility: hidden; transition: visibility 0s .3s; }
.ev-face.out { transition: visibility 0s .3s; }
.envw:not(.is-closed) .ev-flap { transform: rotateX(180deg); z-index: 1; }
.envw:not(.is-closed) .ev-face.in { visibility: visible; }
.envw:not(.is-closed) .ev-face.out { visibility: hidden; }
.ev-fsh { transition: opacity .25s; }
.envw:not(.is-closed) .ev-fsh { opacity: 0; }

/* the card: tucked in (small), rising (still behind the pocket), then in front and readable */
.ev-card { inset-inline-start: 7%; inline-size: 86%; inset-block-end: 2.76%; transform-origin: 50% 100%; z-index: 2;
  transform: translateY(0) scale(.58); transition: transform .72s var(--e-soft), z-index 0s;
  filter: drop-shadow(0 6px 10px rgb(50 30 20 / .22)) drop-shadow(0 1px 1px rgb(50 30 20 / .18)); }
.envw.is-out .ev-card { transform: translateY(-62%) scale(.7); }
.envw.is-read .ev-card { transform: translateY(-9%) scale(1); z-index: 6; transition: transform .78s var(--e-pop), z-index 0s; }
.ev-card .fold { inline-size: 100%; }
.ev-card .gcard { inline-size: 100%; box-shadow: none; }
.envw .side.front::after, .envw .side.back::after { content: ""; position: absolute; inset: 0; z-index: 3; pointer-events: none; background: var(--grain); background-size: 160px; mix-blend-mode: multiply; opacity: .55; }
.envw .side { position: relative; }

/* "To ..." written on the front */
.ev-label { position: absolute; inset-inline: 10%; inset-block-end: 13%; margin: 0; text-align: center; font: 600 clamp(1.1rem, 3.4vw, 1.5rem)/1.2 "Caveat", "Aref Ruqaa", cursive; color: #3B2430; opacity: .85; transition: opacity .3s; unicode-bidi: plaintext; }
.ev-label span { font-size: .8em; opacity: .75; }
.envw:not(.is-closed) .ev-label { opacity: 0; }

/* illustrated: satin bow at the flap tip, it comes undone */
.ev-bow { inset-inline-start: 50%; inset-block-start: 69%; inline-size: 33%; translate: -50% -50%; z-index: 7; pointer-events: none; overflow: visible; }
.ev-bow g { transform-box: fill-box; transition: transform .5s var(--e-soft), opacity .4s; }
.bw-loop.l { transform-origin: 100% 60%; } .bw-loop.r { transform-origin: 0 60%; }
.envw:not(.is-closed) .bw-loop.l { transform: rotate(-35deg) scale(.2); opacity: 0; }
.envw:not(.is-closed) .bw-loop.r { transform: rotate(35deg) scale(.2); opacity: 0; }
.envw:not(.is-closed) .bw-tail.l { transform: translate(-14px, 26px) rotate(-18deg); opacity: 0; }
.envw:not(.is-closed) .bw-tail.r { transform: translate(14px, 26px) rotate(18deg); opacity: 0; }
.envw:not(.is-closed) .bw-knot { opacity: 0; }
.ev-illus .ev-label { inset-block-end: 17%; color: #4A2236; }

/* velvet: the gold wax seal breaks in two */
.ev-seal { inset-inline-start: 50%; inset-block-start: 77%; inline-size: 17%; translate: -50% -50%; z-index: 7; pointer-events: none; overflow: visible; filter: drop-shadow(0 3px 3px rgb(40 15 10 / .4)); }
.sl-half { transition: transform .55s var(--e-pop), opacity .45s .15s; transform-box: view-box; transform-origin: 50% 50%; }
.envw:not(.is-closed) .sl-half.l { transform: translate(-18px, 10px) rotate(-28deg); opacity: 0; }
.envw:not(.is-closed) .sl-half.r { transform: translate(18px, 12px) rotate(24deg); opacity: 0; }
.ev-velvet .ev-label { inset-block-end: 6%; color: #F3DFA8; text-shadow: 0 1px 1px rgb(0 0 0 / .35); }
.ev-velvet .gcard { box-shadow: inset 0 0 0 10px var(--card-bg, #fff), inset 0 0 0 11.5px #B98A92; }

/* blush: a deckle-edged card */
.ev-blush .gcard { clip-path: var(--deckle); border-radius: 0; border: 0; rotate: 0deg; }
.ev-blush .gc-art.a { inset-block-start: 10px; inset-inline-end: 10px; transform: none; }
.ev-blush .gc-art.b { inset-block-end: 10px; inset-inline-start: 10px; transform: none; }
.ev-blush .tape { display: none; }

/* an envelope you can open (envelopeFlow): the whole envelope is a button until the card is out in front */
.envw.is-tappable { -webkit-tap-highlight-color: transparent; }
.envw.is-tappable.is-closed, .envw.is-tappable.is-out .ev-card { cursor: pointer; }   /* closed: open it; half out: bring the card out to read */
.envw.is-tappable:focus-visible { outline: 2.5px solid var(--ink); outline-offset: 8px; border-radius: 12px; }
@media (hover: hover) { .envw.is-tappable.is-closed:hover { transform: translateY(-3px) rotate(-.6deg); transition: transform var(--dur-pop) var(--ease); } }
.env-cta[aria-disabled="true"], .r3-read[aria-disabled="true"] { cursor: progress; }

/* no animation while a state is set directly */
.envw.no-anim *, .envw.no-anim { transition: none !important; }
html[data-motion="reduced"] .envw * { transition-duration: 1ms !important; transition-delay: 0ms !important; }

/* the stage behind an envelope */
.env-stage { position: relative; border: 1.5px solid var(--ink); border-radius: 22px; padding: clamp(16px, 4vw, 36px) clamp(14px, 4vw, 40px) clamp(14px, 3vw, 28px); overflow: hidden; }
.env-stage.es-velvet { background-size: 140px 180px, 160px; }
.env-stage.es-illus, .env-stage.es-blush { background-size: auto, 160px; }

/* envelope picker (Message Atelier) */
.env-pick { display: grid; gap: 10px; }
.env-styles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.env-opt { display: grid; justify-items: center; gap: 4px; padding: 10px 6px 8px; border: 1.5px solid var(--line); border-radius: 12px; background: var(--c-bg); font-size: .8rem; line-height: 1.2; text-align: center; transition: transform var(--dur-pop) var(--ease); }
.env-opt[aria-pressed="true"] { border: 2px solid var(--ink); background: #fff; box-shadow: 0 3px 0 var(--ink); }
.env-opt .mini { inline-size: 64px; block-size: 44px; border-radius: 4px; background: var(--v); position: relative; overflow: hidden; box-shadow: 0 3px 6px rgb(60 30 30 / .2); }
.env-opt .mini::before { content: ""; position: absolute; inset: 0 0 38%; background: color-mix(in srgb, var(--v) 88%, #fff); clip-path: polygon(0 0, 100% 0, 50% 100%); filter: drop-shadow(0 2px 1px rgb(0 0 0 / .2)); }
.env-opt .mini.is-velvet { background: radial-gradient(120% 90% at 30% 20%, color-mix(in srgb, var(--v) 70%, #fff), var(--v) 50%, color-mix(in srgb, var(--v) 70%, #2a0c12)); }
.env-opt .mini.is-velvet::after { content: ""; position: absolute; inset-inline-start: 50%; inset-block-start: 50%; inline-size: 12px; block-size: 12px; translate: -50% -40%; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #F6DE96, #C99A3E 60%, #8D6620); }
.env-opt .mini.is-illus::after { content: ""; position: absolute; inset-inline-start: 50%; inset-block-start: 52%; inline-size: 18px; block-size: 9px; translate: -50% -50%; border-radius: 50%; background: #B9CBEC; box-shadow: 0 0 0 1px #7F93C6; }
.env-opt:active { transform: scale(.95); }
.env-colors { display: flex; flex-wrap: wrap; gap: 10px; }
.env-toggle { justify-self: center; margin-block-start: 10px; }

/* placements */
.ev-card .fold { inline-size: 100% !important; }
.final-card .envw { --env-w: 400px; }
.final-card { gap: 8px; }
@media (max-width: 899px) {
  .final-card .envw { --env-w: 340px; transition: margin-block-start .6s var(--e-soft); }
  /* closed, the space the card will rise into is empty: fold it away so the envelope sits under the vase
     (envelopeFlow keeps the envelope still on screen while the space opens again). Only the paper itself takes taps. */
  .final-card .envw.is-closed { margin-block-start: calc(min(100vw - 32px, var(--env-w)) * -.7); pointer-events: none; }
  .final-card .envw.is-closed > .ev-back, .final-card .envw.is-closed > .ev-flap { pointer-events: auto; }
}
.pv-card { display: grid; gap: 8px; justify-items: stretch; align-content: start; }
.pv-card .env-stage { padding-block: 18px 14px; }
.pv-card .envw { --env-w: 330px; }
/* the card keeps its 4:5 shape in the envelope (the meanings side scrolls inside it if long) */
.ev-card .flipper > .side { aspect-ratio: 4 / 5; overflow: hidden; }
.ev-card .side .gcard { inline-size: 100% !important; block-size: 100%; aspect-ratio: auto; }
.ev-card .gc-back { overflow: hidden; }
/* the inside of the flap is drawn upside down so that, once the flap is lifted, its point faces up */
.ev-face.in .ev-svg { transform: scaleY(-1); }
.pv-pair:has(.env-stage) { grid-template-columns: minmax(0, .85fr) minmax(0, 1.15fr); align-items: center; }
@media (max-width: 640px) { .pv-pair:has(.env-stage) { grid-template-columns: 1fr; } }
/* the card is laid out at its natural 320px and zoomed to the envelope, so its type keeps the studio's proportions */
.ev-card .fold { inline-size: 320px !important; zoom: var(--cz, 1); }
/* gift: the invitation line sits in the empty space above the closed envelope */
.env-stage .gf-say { position: absolute; z-index: 8; inset-block-start: 9%; inset-inline: 8%; margin: 0; }
.ev-seal { inline-size: 20%; }
