/* Septem of Swords: an envelope invite in the cotoaleksandra folio style */
:root {
  --paper: #e9e8e4;
  --ink: #2a2926;
  --mute: #6a6863;
  --rule: rgba(42, 41, 38, .38);
  --cream: #f4eedf;
  --cream-2: #ece3cd;
  --cream-3: #e2d7bc;
  --heavy: "Inter Tight", "Helvetica Neue", Arial, sans-serif;
  --script: "Monsieur La Doulaise", "Snell Roundhand", cursive;
  --pad: clamp(16px, 4vw, 48px);
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.16 0 0 0 0 0.15 0 0 0 0 0.14 0 0 0 0.1 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");

  /* card + envelope geometry */
  --cw: min(62vw, 300px, calc((100svh - 190px) * 7 / 12.6));
  --ch: calc(var(--cw) * 12 / 7);
  --ew: calc(var(--cw) * 1.16);
  --eh: calc(var(--ch) * 1.05);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  background: var(--paper) var(--grain);
  color: var(--ink); font: 15px/1.42 var(--heavy);
  min-height: 100svh; overflow-x: hidden;
}
body.locked { overflow: hidden; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid currentColor; outline-offset: 3px; }

.heavy { font-family: var(--heavy); font-weight: 800; letter-spacing: -.065em; line-height: .88; text-transform: uppercase; }
.script { font-family: var(--script); font-weight: 400; line-height: 1; letter-spacing: 0; text-transform: none; }

/* page furniture */
.furn {
  position: fixed; left: 0; right: 0; z-index: 20; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 12px var(--pad); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: -.01em; pointer-events: none;
}
.furn > * { pointer-events: auto; }
.furn span:last-child { justify-self: end; }
.furn--top { top: 0; }
.furn--bottom { bottom: 0; font-weight: 500; }
body.opened .furn--bottom { position: static; }
.lang { font-size: 12px; font-weight: 600; text-transform: uppercase; }
.lang b { font-weight: 800; }
.lang i { font-style: normal; opacity: .45; }

/* ───────── hero / stage ───────── */
.hero { min-height: 100svh; display: grid; place-content: center; justify-items: center; gap: 22px; padding: 56px 0 40px; }
.stage { position: relative; width: var(--ew); height: var(--eh); perspective: 1400px; }
.hint, .to-rsvp {
  font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: -.01em; min-height: 1.4em; text-align: center;
  transition: opacity .4s;
}
.to-rsvp { color: inherit; text-decoration: none; border-bottom: 1px solid var(--ink); }
.to-rsvp:hover { font-style: italic; }

/* envelope parts: transformed individually (no shared wrapper) so the card can sit between them */
.env { position: absolute; inset: 0; transition: transform 1s cubic-bezier(.6, -.05, .7, .2), opacity 1s; }
.stage.dropped .env, .stage.dropped .seal { transform: translateY(115vh) rotate(6deg); opacity: 0; pointer-events: none; }
.stage.gone .env, .stage.gone .seal { visibility: hidden; }
.env-back {
  z-index: 1; border-radius: 4px;
  background: var(--cream-3) var(--grain);
  box-shadow: 0 18px 40px -18px rgba(42, 41, 38, .5), 0 2px 6px rgba(42, 41, 38, .18);
}
.env-pocket-wrap { z-index: 3; filter: drop-shadow(0 -1px 1px rgba(42, 41, 38, .18)); pointer-events: none; }
.env-pocket {
  position: absolute; inset: 0; border-radius: 0 0 4px 4px;
  background:
    linear-gradient(to top right, transparent 49.6%, rgba(42,41,38,.07) 50%, transparent 50.6%) left bottom / 50% 62% no-repeat,
    linear-gradient(to top left, transparent 49.6%, rgba(42,41,38,.07) 50%, transparent 50.6%) right bottom / 50% 62% no-repeat,
    var(--grain), linear-gradient(180deg, var(--cream-2), var(--cream));
  clip-path: polygon(0 0, 50% 50%, 100% 0, 100% 100%, 0 100%);
}
.env-flap-wrap {
  z-index: 4; transform-origin: 50% 0; transform-style: preserve-3d;
  filter: drop-shadow(0 3px 2px rgba(42, 41, 38, .22));
  transition: transform .75s cubic-bezier(.45, 0, .2, 1);
  pointer-events: none;
}
.env-flap {
  position: absolute; inset: 0;
  background: var(--grain), linear-gradient(180deg, var(--cream), var(--cream-2));
  clip-path: polygon(0 0, 100% 0, 50% 56%);
  border-radius: 4px 4px 0 0;
}
.stage.open .env-flap-wrap { transform: rotateX(178deg); }
.stage.flap-behind .env-flap-wrap { z-index: 0; }
.stage.dropped .env-flap-wrap { transform: translateY(115vh) rotateX(178deg); }

/* wax seal */
.seal {
  position: absolute; z-index: 6; width: calc(var(--ew) * .3); aspect-ratio: 1;
  left: 50%; top: calc(var(--eh) * .56); transform: translate(-50%, -50%);
  filter: drop-shadow(0 3px 3px rgba(40, 5, 8, .45)); transition: transform 1s cubic-bezier(.6, -.05, .7, .2), opacity 1s;
  animation: breathe 2.8s ease-in-out infinite;
}
.seal svg { width: 100%; height: 100%; overflow: visible; }
.seal .half { transition: transform .7s cubic-bezier(.3, .6, .4, 1), opacity .7s .15s; transform-box: fill-box; }
.seal .half.l { transform-origin: 30% 80%; }
.seal .half.r { transform-origin: 70% 80%; }
.stage.cracked .seal { animation: crack-shake .28s linear; }
.stage.cracked .seal .half.l { transform: translate(-26px, 34px) rotate(-28deg); opacity: 0; }
.stage.cracked .seal .half.r { transform: translate(26px, 40px) rotate(24deg); opacity: 0; }
.stage.cracked .seal { pointer-events: none; }
@keyframes breathe { 50% { transform: translate(-50%, -50%) scale(1.04); } }
@keyframes crack-shake { 25% { transform: translate(-52%, -50%) rotate(-3deg); } 75% { transform: translate(-48%, -50%) rotate(3deg); } }

/* ───────── the card ───────── */
.card {
  position: absolute; z-index: 2; left: 50%; top: 50%; width: var(--cw); height: var(--ch);
  transform: translate(-50%, -48%) scale(.94);
  transition: transform 1.1s cubic-bezier(.3, .7, .2, 1);
  perspective: 1600px; outline: none;
}
.stage.rising .card { transform: translate(-50%, -112%) scale(.94); }
.stage.dropped .card { transform: translate(-50%, -50%) scale(1); z-index: 7; cursor: pointer; }
.card-inner { position: absolute; inset: 0; transform-style: preserve-3d; transition: transform 1s cubic-bezier(.4, .1, .2, 1); }
.card.flipped .card-inner { transform: rotateY(180deg); }
.stage.dropped .card:hover .card-inner { transform: rotateY(-6deg); }
.stage.dropped .card.flipped:hover .card-inner { transform: rotateY(186deg); }
.face {
  position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  background: var(--grain), linear-gradient(160deg, #fbf7ec, var(--cream));
  border-radius: calc(var(--cw) * .04);
  box-shadow: 0 20px 40px -20px rgba(42, 41, 38, .55), 0 1px 3px rgba(42, 41, 38, .25);
  padding: calc(var(--cw) * .045);
}
.face.back { transform: rotateY(180deg); }
.face-frame {
  height: 100%; border: 1.5px solid var(--ink); outline: 1px solid var(--ink); outline-offset: -5px;
  border-radius: calc(var(--cw) * .02); display: flex; flex-direction: column; padding: calc(var(--cw) * .05);
}
.c-top { display: flex; justify-content: space-between; align-items: baseline; font-size: calc(var(--cw) * .036); font-weight: 600; text-transform: uppercase; }
.c-top b { font-weight: 800; font-size: calc(var(--cw) * .085); letter-spacing: -.04em; }
.c-window { position: relative; flex: 1; margin: calc(var(--cw) * .03) 0; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); overflow: hidden; }
.c-window canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.c-placeholder { position: absolute; left: 50%; top: 8px; transform: translateX(-50%); white-space: nowrap; background: #fbf7ec; padding: 1px 6px; font-size: calc(var(--cw) * .032); font-weight: 600; text-transform: uppercase; color: var(--mute); }
.c-title { position: relative; display: flex; flex-direction: column; align-items: center; padding-top: calc(var(--cw) * .02); }
.c-title .heavy { font-size: calc(var(--cw) * .2); }
.c-title .script { font-size: calc(var(--cw) * .15); margin-top: calc(var(--cw) * -.07); position: relative; }

/* card back: the info */
.back-frame { gap: calc(var(--cw) * .03); }
.b-title { display: flex; flex-direction: column; align-items: center; margin: calc(var(--cw) * .05) 0 calc(var(--cw) * .02); font-weight: inherit; }
.b-title .script { font-size: calc(var(--cw) * .2); position: relative; z-index: 1; margin-bottom: calc(var(--cw) * -.07); }
.b-title .heavy { font-size: calc(var(--cw) * .15); }
.ruled { list-style: none; font-size: calc(var(--cw) * .043); }
.ruled li { display: flex; justify-content: space-between; gap: 10px; padding: calc(var(--cw) * .018) 0; border-bottom: 1px solid var(--rule); }
.ruled li:first-child { border-top: 1px solid var(--rule); }
.ruled li span { font-weight: 800; text-transform: uppercase; letter-spacing: -.02em; }
.ruled li i { text-align: right; }
.ruled a { color: inherit; }
.b-note { font-size: calc(var(--cw) * .043); line-height: 1.35; margin-top: calc(var(--cw) * .05); }
.b-sign { margin-top: auto; text-align: right; font-size: calc(var(--cw) * .17); line-height: .8; }

/* ───────── RSVP ───────── */
.rsvp { max-width: 560px; margin: 0 auto; padding: 40px var(--pad) 90px; }
.rsvp-head { display: flex; flex-direction: column; align-items: center; margin-bottom: 34px; }
.rsvp-head .script { font-size: clamp(52px, 12vw, 84px); margin-bottom: -.32em; position: relative; z-index: 1; }
.rsvp-head .heavy { font-size: clamp(64px, 16vw, 120px); }
.f { margin-bottom: 26px; }
.f > label, .f > .lbl { display: block; font-size: 13px; font-weight: 800; text-transform: uppercase; letter-spacing: -.02em; margin-bottom: 8px; }
.f input[type=text], .f textarea {
  width: 100%; border: 0; border-bottom: 1px solid var(--ink); background: transparent; padding: 8px 0; font: 17px var(--heavy); color: var(--ink); border-radius: 0; resize: vertical;
}
.f textarea { border: 1px solid var(--rule); padding: 10px; min-height: 96px; }
.f input:focus, .f textarea:focus { outline: none; border-color: var(--ink); box-shadow: 0 1px 0 var(--ink); }
.opts { display: flex; gap: 10px; flex-wrap: wrap; }
.opt { position: relative; }
.opt input { position: absolute; opacity: 0; pointer-events: none; }
.opt span {
  display: inline-block; padding: 9px 20px; border: 1px solid var(--ink); border-radius: 999px;
  font-size: 14px; font-weight: 600; text-transform: uppercase; letter-spacing: -.01em; cursor: pointer; transition: background .15s, color .15s;
}
.opt span::before { content: "( "; } .opt span::after { content: " )"; }
.opt input:checked + span { background: var(--ink); color: var(--paper); }
.opt input:focus-visible + span { outline: 2px solid var(--ink); outline-offset: 3px; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }
.err { color: #8a1520; font-size: 13px; font-weight: 600; margin: -8px 0 16px; }
.send {
  width: 100%; padding: 18px; background: var(--ink); color: var(--paper);
  font-size: 15px; font-weight: 800; text-transform: uppercase; letter-spacing: -.02em; transition: opacity .2s;
}
.send:hover { font-style: italic; }
.send:disabled { opacity: .5; cursor: wait; }
.thanks { text-align: center; padding: 20px 0; }
.thanks .script { display: block; font-size: clamp(56px, 14vw, 96px); margin-bottom: -.3em; position: relative; z-index: 1; }
.thanks .heavy { display: block; font-size: clamp(34px, 9vw, 64px); }
.thanks p { margin-top: 18px; color: var(--mute); }
.thanks button { margin-top: 14px; font-size: 12px; font-weight: 600; text-transform: uppercase; border-bottom: 1px solid var(--ink); }

/* entrance */
.stage { animation: arrive 1s cubic-bezier(.2, .7, .2, 1) both; }
@keyframes arrive { from { transform: translateY(24px) rotate(-2deg); opacity: 0; } }
.stage.idle .env-back, .stage.idle .env-pocket-wrap, .stage.idle .env-flap-wrap { animation: none; }

@media (prefers-reduced-motion: reduce) {
  .seal { animation: none; }
  .env, .card, .card-inner, .env-flap-wrap { transition-duration: .01s !important; }
}

/* ?open=1: skip the envelope with no animation */
.stage.instant .card, .stage.instant .card-inner, .stage.instant .env, .stage.instant .seal, .stage.instant .env-flap-wrap { transition: none !important; }

/* ───────── image capture mode (tools/capture.sh) ───────── */
.capture *, .capture *::before, .capture *::after { animation: none !important; transition: none !important; }
.capture .furn, .capture .hint, .capture .to-rsvp, .capture .rsvp { display: none !important; }
.capture-front, .capture-back { --cw: 600px; --ch: calc(var(--cw) * 12 / 7); --ew: calc(var(--cw) * 1.16); --eh: calc(var(--ch) * 1.05); }
.capture-front .hero, .capture-back .hero { padding: 0; min-height: 0; height: 100vh; }
.capture-front .face, .capture-back .face { box-shadow: none; }
.capture-og { --cw: 262px; --ch: calc(var(--cw) * 12 / 7); --ew: calc(var(--cw) * 1.16); --eh: calc(var(--ch) * 1.05); }
.capture-og .hero { height: 100vh; min-height: 0; padding: 0; place-content: center end; padding-right: 120px; }
.og-text { position: fixed; left: 80px; top: 0; bottom: 0; display: flex; flex-direction: column; justify-content: center; }
.og-text .script { font-size: 120px; margin-bottom: -46px; margin-left: 10px; position: relative; z-index: 1; }
.og-text .heavy { font-size: 142px; }
.og-text p { margin-top: 30px; font-size: 22px; font-weight: 600; text-transform: uppercase; letter-spacing: -.01em; }
.og-furn { position: fixed; left: 80px; right: 80px; display: flex; justify-content: space-between; font-size: 18px; font-weight: 600; text-transform: uppercase; }
.og-furn.top { top: 36px; } .og-furn.bottom { bottom: 36px; font-weight: 500; }
.hint-small { margin-top: 8px; font-size: 12px; line-height: 1.4; color: var(--mute); }
