:root {
  --bg: #0f0b09;
  --paper: #f2e8d0;
  --ink: #2a1c13;
  --ink-soft: #4a3829;
  --gold: #6e5226;          /* libellés sur papier : contraste ≥ 5:1 */
  --gold-line: #b89a5b;
  --wax: #7b1e24;
  --cream: #f0e4cb;
  --serif: 'Lora', Georgia, 'Times New Roman', serif;
  --script: 'Pinyon Script', 'Snell Roundhand', cursive;
  --display: 'Playfair Display', Georgia, serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
.hidden { display: none !important; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--cream);
  font-family: var(--serif);
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-font-smoothing: antialiased;
}

#stage {
  position: fixed;
  inset: 0;
  height: 100dvh;
  overflow: hidden;
  display: grid;
  place-items: center;
  background:
    radial-gradient(ellipse 70% 50% at 50% 38%, rgba(214, 150, 78, .20) 0%, rgba(214, 150, 78, 0) 70%),
    radial-gradient(ellipse 110% 85% at 50% 45%, #2b1f16 0%, #150f0b 58%, #080605 100%);
}
/* grain de fond + vignette */
#stage::before {
  content: '';
  position: absolute; inset: 0;
  background-image: var(--grain);
  opacity: .55;
  pointer-events: none;
  z-index: 0;
}
#stage::after {
  content: '';
  position: absolute; inset: 0;
  box-shadow: inset 0 0 140px 30px rgba(0, 0, 0, .65);
  pointer-events: none;
  z-index: 0;
}
#stage > * { z-index: 1; }

/* ---------- Enveloppe ---------- */

#envelope-scene {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(1.6rem, 6dvh, 2.8rem);
  padding: 0 16px;
}

.for {
  text-align: center;
  line-height: 1;
}
.for small {
  display: block;
  font-family: var(--serif);
  font-size: .8rem;
  font-weight: 600;
  letter-spacing: .42em;
  text-transform: uppercase;
  color: #c9a96a;
  margin-bottom: .7rem;
  padding-left: .42em;
}
.for span {
  font-family: var(--script);
  font-size: clamp(3.2rem, 15vw, 4.4rem);
  color: #f6ecd6;
  text-shadow: 0 2px 18px rgba(214, 150, 78, .35);
}

.envelope {
  position: relative;
  width: min(88vw, 410px);
  aspect-ratio: 3 / 2;
  perspective: 1400px;
  filter: drop-shadow(0 26px 30px rgba(0, 0, 0, .65)) drop-shadow(0 4px 6px rgba(0, 0, 0, .5));
}
.envelope > * { position: absolute; }

.env-back {
  inset: 0;
  border-radius: 5px;
  background:
    var(--grain),
    linear-gradient(180deg, #d8c498 0%, #cdb887 100%);
}

.env-letter {
  left: 5%; right: 5%; top: 7%; bottom: 3%;
  border-radius: 2px;
  background: var(--grain), var(--paper);
  box-shadow: 0 0 0 1px rgba(110, 82, 38, .25);
  padding: 9% 12% 0;
}
.env-letter span {
  display: block;
  height: 2px;
  margin-bottom: 11%;
  background: rgba(110, 82, 38, .22);
}
.env-letter span:nth-child(2) { width: 70%; margin-left: auto; margin-right: auto; }
.env-letter span:nth-child(3) { width: 45%; margin-left: auto; margin-right: auto; }

/* poche avant : ombre portée vers le haut sur la lettre */
.env-pocket {
  inset: 0;
  border-radius: 5px;
  background:
    var(--grain),
    linear-gradient(168deg, #f1e4c6 0%, #e6d4ad 55%, #dac592 100%);
  clip-path: polygon(0 0, 50% 55%, 100% 0, 100% 100%, 0 100%);
}
.env-pocket::after {
  /* arêtes de pliure */
  content: '';
  position: absolute; inset: 0;
  background:
    linear-gradient(to top right, transparent calc(50% - 1px), rgba(110, 82, 38, .35) 50%, transparent calc(50% + 1px)) 0 0 / 50% 55% no-repeat,
    linear-gradient(to top left,  transparent calc(50% - 1px), rgba(110, 82, 38, .35) 50%, transparent calc(50% + 1px)) 100% 0 / 50% 55% no-repeat;
}

/* rabat : face extérieure (papier) / face intérieure (doublure bordeaux) */
.env-flap {
  left: 0; top: 0; width: 100%; height: 61%;
  transform-origin: 50% 0;
  transform-style: preserve-3d;
  z-index: 3;
}
.flap-face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.flap-face i { position: absolute; inset: 0; }
.flap-out .edge {
  background: #b89c63;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
}
.flap-out .skin {
  background:
    var(--grain),
    linear-gradient(180deg, #f3e7ca 0%, #e8d7b0 70%, #dcc89a 100%);
  clip-path: polygon(3px 0, calc(100% - 3px) 0, 50% calc(100% - 5px));
}
.flap-in {
  transform: rotateX(180deg);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  background:
    repeating-linear-gradient(45deg, rgba(255, 255, 255, .055) 0 2px, transparent 2px 11px),
    repeating-linear-gradient(-45deg, rgba(255, 255, 255, .055) 0 2px, transparent 2px 11px),
    linear-gradient(180deg, #4a0e15 0%, #6b1720 100%);
}

/* ---------- Sceau ---------- */

.seal {
  position: absolute;
  left: 50%; top: 61%;
  width: clamp(78px, 25%, 104px);
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border: 0; background: none; cursor: pointer;
  z-index: 5;
  filter: drop-shadow(0 5px 6px rgba(0, 0, 0, .55));
  touch-action: manipulation;
}
.seal:focus-visible { outline: 2px solid var(--cream); outline-offset: 8px; border-radius: 50%; }
.seal-ring {
  position: absolute; inset: -8px;
  border-radius: 50%;
  border: 1.5px solid rgba(240, 200, 150, .55);
  animation: ring 2.4s ease-out infinite;
  pointer-events: none;
}
.seal-half { position: absolute; inset: 0; }
.seal-half svg { width: 100%; height: 100%; display: block; overflow: visible; }
.seal-l { clip-path: polygon(0 0, 53% 0, 46% 16%, 55% 34%, 47% 52%, 56% 71%, 49% 100%, 0 100%); }
.seal-r { clip-path: polygon(53% 0, 100% 0, 100% 100%, 49% 100%, 56% 71%, 47% 52%, 55% 34%, 46% 16%); }
.seal.broken { pointer-events: none; }
.seal.broken .seal-ring { display: none; }
.wax-bit {
  position: absolute; left: 50%; top: 50%;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #b03a41, #6a141b);
  pointer-events: none;
}

@keyframes ring {
  0%   { transform: scale(.92); opacity: .9; }
  100% { transform: scale(1.35); opacity: 0; }
}

.hint {
  font-style: italic;
  font-size: clamp(1.05rem, 4.4vw, 1.25rem);
  color: rgba(240, 228, 203, .85);
  text-align: center;
  letter-spacing: .01em;
  max-width: 22em;
}

/* ---------- Carte ---------- */

#card-stage {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  perspective: 1400px;
  padding: 12px 14px;
}

.card {
  position: relative;
  width: min(92vw, 440px);
  padding: clamp(2rem, 6dvh, 2.9rem) clamp(1.5rem, 7vw, 2.3rem) clamp(1.8rem, 5dvh, 2.5rem);
  background-color: var(--paper);
  background-image: var(--grain);
  background-size: 256px 256px;
  color: var(--ink);
  text-align: center;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .7), 0 3px 8px rgba(0, 0, 0, .45);
  transform-origin: 50% 50%;
  will-change: transform;
}
/* double filet doré */
.card::before {
  content: '';
  position: absolute; inset: 10px;
  border: 2px solid var(--gold-line);
  pointer-events: none;
}
.card::after {
  content: '';
  position: absolute; inset: 16px;
  border: 1px solid var(--gold-line);
  pointer-events: none;
}

.c-eyebrow {
  font-size: clamp(.82rem, 3.4vw, .95rem);
  letter-spacing: .3em;
  text-transform: uppercase;
  color: var(--gold);
  font-weight: 700;
  padding-left: .3em;
}
.c-names {
  font-family: var(--script);
  font-weight: 400;
  font-size: clamp(3.3rem, 15.5vw, 4.5rem);
  line-height: 1.02;
  margin: .3em 0 .12em;
  color: var(--wax);
  text-wrap: balance;
}
.c-for {
  font-style: italic;
  font-size: clamp(1.1rem, 4.6vw, 1.3rem);
  color: var(--ink-soft);
}

.c-orn {
  display: flex; align-items: center; justify-content: center; gap: .8rem;
  margin: clamp(1rem, 3.2dvh, 1.5rem) auto;
}
.c-orn i { display: block; width: 52px; height: 1px; background: var(--gold-line); }
.c-orn b { font-size: .7rem; line-height: 1; color: var(--gold); font-weight: 400; }

.c-info { display: grid; gap: clamp(1rem, 3dvh, 1.45rem); }
.c-row dt {
  font-size: clamp(.74rem, 3vw, .84rem);
  letter-spacing: .28em;
  text-transform: uppercase;
  color: var(--gold);
  font-weight: 700;
  margin-bottom: .3em;
  padding-left: .28em;
}
.c-row dd {
  font-size: clamp(1.28rem, 5.6vw, 1.55rem);
  font-weight: 500;
  line-height: 1.28;
  color: var(--ink);
  text-wrap: balance;
}
.c-row dd b { display: block; font-weight: 700; font-size: 1.08em; }
.c-row dd span { display: block; font-size: .8em; font-weight: 400; color: var(--ink-soft); margin-top: .1em; }

/* dress code : bandeau teinté pleine largeur */
.c-dress {
  height: 0; opacity: 0; overflow: hidden;
  margin: 0 calc(-1 * clamp(1.5rem, 7vw, 2.3rem) + 22px);
  background: rgba(123, 30, 36, .09);
}
.c-dress dt, .c-dress dd { padding-left: 0; }
.c-dress dt { padding-top: 1.05rem; margin-bottom: .2em; color: var(--wax); }
.c-dress dd {
  font-style: italic;
  font-weight: 500;
  color: var(--wax);
  padding: 0 .8rem 1.1rem;
  font-size: clamp(1.3rem, 5.8vw, 1.6rem);
}

.c-actions { margin-top: clamp(1.3rem, 4dvh, 1.9rem); min-height: 4.6rem; }
.btn {
  font-family: var(--serif);
  font-size: clamp(1.08rem, 4.6vw, 1.25rem);
  font-weight: 600;
  letter-spacing: .04em;
  color: #fbf0dc;
  background: linear-gradient(180deg, #92252d 0%, #6e171e 100%);
  border: 1px solid #4a0f15;
  padding: 1em 1.7em;
  border-radius: 3px;
  box-shadow: inset 0 1px 0 rgba(255, 200, 190, .25), 0 3px 0 #3f0b11, 0 12px 22px rgba(80, 15, 25, .35);
  cursor: pointer;
  touch-action: manipulation;
}
.btn:active { transform: translateY(2px); box-shadow: inset 0 1px 0 rgba(255, 200, 190, .25), 0 1px 0 #3f0b11; }
.btn:disabled { opacity: .65; cursor: default; }
.c-after {
  margin-top: .8rem;
  font-style: italic;
  font-size: 1rem;
  color: var(--gold);
  min-height: 1.4em;
}

@media (max-height: 780px) {
  .card { padding-top: 1.8rem; padding-bottom: 1.5rem; }
  .c-names { font-size: clamp(2.9rem, 13.5vw, 3.8rem); }
  .c-info { gap: .95rem; }
  .c-orn { margin: .9rem auto; }
  .c-row dd { font-size: clamp(1.15rem, 5vw, 1.35rem); }
  .c-dress dt { padding-top: .8rem; }
  .c-dress dd { padding-bottom: .8rem; font-size: clamp(1.15rem, 5vw, 1.35rem); }
  .c-actions { margin-top: 1.1rem; min-height: 4rem; }
  .btn { padding: .85em 1.5em; }
}
@media (max-height: 640px) {
  .card { padding-top: 1.4rem; padding-bottom: 1.2rem; }
  .c-names { font-size: 2.6rem; }
  .c-info { gap: .7rem; }
  .c-orn { margin: .6rem auto; }
  .c-row dd { font-size: 1.1rem; }
  .c-dress dd { font-size: 1.1rem; }
  .c-actions { margin-top: .8rem; min-height: 3.6rem; }
}

/* ---------- Dress code géant ---------- */

#giant {
  position: absolute; inset: 0;
  z-index: 10;
  background-color: var(--paper);
  background-image: var(--grain);
  background-size: 256px 256px;
  color: var(--wax);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center;
  overflow: hidden;
}
.g-label {
  font-size: clamp(1rem, 4.4vw, 1.4rem);
  letter-spacing: .42em;
  text-transform: uppercase;
  color: var(--gold);
  font-weight: 700;
  margin-bottom: 2dvh;
  padding-left: .42em;
}
.g-text {
  font-family: var(--display);
  font-style: italic;
  font-weight: 800;
  font-size: min(23vw, 14.5dvh);
  line-height: .93;
  letter-spacing: -.02em;
  white-space: nowrap;
}
.g-text span { display: block; }

/* ---------- Combustion & cendres ---------- */

#burn {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  z-index: 20;
  pointer-events: none;
}

#ashes-scene {
  position: absolute; inset: 0;
  z-index: 15;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 1.6rem;
  padding: 0 16px;
}
#ash-pile { width: min(80vw, 340px); height: auto; }
.ash-text {
  font-style: italic;
  font-size: clamp(1.15rem, 4.8vw, 1.4rem);
  color: rgba(240, 228, 203, .8);
  text-align: center;
}

#preview-badge {
  position: absolute; top: max(10px, env(safe-area-inset-top)); right: 10px;
  z-index: 60;
  display: flex; gap: .5rem; align-items: center;
  font-size: .85rem;
  background: rgba(0, 0, 0, .6);
  border: 1px solid rgba(240, 228, 203, .25);
  border-radius: 99px;
  padding: .25rem .4rem .25rem .8rem;
  color: var(--cream);
}
#preview-badge button {
  font: inherit; color: var(--bg); background: var(--cream);
  border: 0; border-radius: 99px; padding: .15rem .7rem; cursor: pointer;
}

@media (prefers-reduced-motion: reduce) {
  .seal-ring { animation: none; opacity: .6; }
}
