/* The guest's letter, on ivory marble.

   Shut, the section is the casket on the marble, with a line asking the guest
   to touch it. Open (.is-open, set by js/letter.js), it is the letter, with
   the casket below it (or beside it, on a tablet held sideways). The letter's
   place is taken the moment the casket is touched, so js/letter.js can fly
   the folded letter to exactly where it will lie, and the page does not jump
   when it unfolds. The casket's pieces are all one canvas (assets/letter/
   casket.css says where its hinge and rim are); the folded letter passes
   between the box's back and its front as it rises out. */

.letter {
  --band-h: 20px;
  --gold-deep: #86662a;
  position: relative;
  z-index: 1;                      /* the casket's pieces and the folded letter layer in here */
  display: flex;
  flex-direction: column;
  justify-content: center;         /* shut: the heading and the casket, together in the middle */
  min-height: 100vh;
  min-height: 100svh;
  padding: calc(var(--band-h) + 34px) 16px calc(var(--band-h) + 44px);
  background: url(../assets/letter/marble.webp) center top / 100% auto repeat-y, #f2ede3;
  color: var(--ink);
  container-type: inline-size;
  overflow-anchor: none;
  -webkit-tap-highlight-color: transparent;
}

html.is-tablet .letter,
html:not(.is-tablet) .card .letter { --band-h: 26px; }

/* The bands of gold, mirror and emerald where the marble meets the emerald
   sections, straddling the join. */
.lt-band {
  position: absolute;
  left: 0;
  right: 0;
  height: var(--band-h);
  background: url(../assets/letter/band.webp) center / auto 100% repeat-x;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, .35));
  pointer-events: none;
}

.lt-band-top { top: calc(var(--band-h) * -.5); }
.lt-band-bottom { bottom: calc(var(--band-h) * -.5); }

/* ------------------------------------------------------------ the heading */

.lt-head {
  text-align: center;
  margin: 0 0 8px;
}

.lt-head > * { margin: 0; }

.lt-kicker {
  font: 600 clamp(11px, 3cqi, 14px)/1.3 "Cormorant Garamond", Georgia, serif;
  letter-spacing: .28em;
  padding-left: .28em;
  text-transform: uppercase;
  color: var(--gold-deep);
}

/* The guest's name in gold leaf, deepened to read on the marble. */
.lt-for {
  font: 400 clamp(44px, 13cqi, 76px)/1.15 "Alex Brush", cursive;
  padding: 0 .3em .1em;
  background:
    linear-gradient(180deg, rgba(255, 240, 200, .25), transparent 40%, rgba(70, 42, 8, .42)),
    url(../assets/hero/gold.webp) 0 0 / 4em 4em;
  -webkit-background-clip: text;
          background-clip: text;
  color: transparent;
  filter: drop-shadow(0 1px 0 rgba(255, 255, 255, .8)) drop-shadow(0 1px 1.5px rgba(60, 36, 6, .45));
  overflow-wrap: anywhere;
}

/* ------------------------------------------------------------ the stage */

.lt-stage {
  position: relative;              /* no z-index: see .letter */
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
}

/* Open: the heading at the top, then the letter. */
.letter.is-open { justify-content: flex-start; }

.lt-slot {
  width: 100%;
  display: none;
  justify-content: center;
}

.letter.is-open .lt-slot { display: flex; }

/* ------------------------------------------------------------ the letter */

.lt-letter {
  --pb: clamp(22px, 6.6cqi, 40px);
  position: relative;
  width: min(100%, 580px);
  margin: 0;
  padding: clamp(18px, 5cqi, 34px) clamp(12px, 4cqi, 30px) clamp(26px, 7cqi, 44px);
  border: var(--pb) solid transparent;
  border-image: url(../assets/letter/paper.webp) 86 fill / var(--pb) round;
  box-shadow: 0 1px 2px rgba(60, 40, 10, .12), 0 14px 28px -12px rgba(50, 35, 10, .35);
  text-align: center;
  container-type: inline-size;
  font: 500 clamp(15.5px, 5.4cqi, 20px)/1.55 "Cormorant Garamond", Georgia, serif;
}

.letter:not(.is-read) .lt-slot .lt-letter { visibility: hidden; }

.lt-letter > * { margin: 0 0 .85em; }

.lt-verse {
  font: 400 clamp(19px, 6.6cqi, 28px)/2.05 "Amiri Quran", "Amiri", serif;
  color: var(--emerald);
  margin-bottom: .35em;
}

.lt-verse-en {
  font-style: italic;
  font-size: .9em;
  line-height: 1.45;
  color: rgba(11, 61, 49, .82);
  margin-bottom: .3em;
}

.lt-verse-ref {
  font: 600 clamp(10px, 2.9cqi, 13px)/1.3 "Cormorant Garamond", Georgia, serif;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--gold-deep);
}

/* a fine gold rule with a small emerald-and-gold lozenge */
.lt-rule {
  position: relative;
  height: 14px;
  margin: 1.1em auto 1.2em;
  width: 62%;
  background: linear-gradient(90deg, transparent, #b8944e 18%, #b8944e 82%, transparent) center / 100% 1px no-repeat;
}

.lt-rule i {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 9px;
  height: 9px;
  translate: -50% -50%;
  rotate: 45deg;
  background: var(--emerald);
  box-shadow: 0 0 0 2px #f4eee1, 0 0 0 3px #b8944e;
}

.lt-greeting {
  font: 400 clamp(30px, 10cqi, 44px)/1.2 "Alex Brush", cursive;
  color: var(--emerald);
  margin-bottom: .35em !important;
}

.lt-urdu {
  font: 400 clamp(17px, 5.8cqi, 25px)/2.3 "Noto Nastaliq Urdu", serif;
  color: var(--emerald);
  margin: 1.1em 0 0 !important;
}

.lt-urdu-en {
  font-style: italic;
  font-size: .88em;
  color: rgba(11, 61, 49, .75);
}

.lt-closing {
  font-style: italic;
  margin: 1.4em 0 0 !important;
}

.lt-sign {
  font: 400 clamp(34px, 11cqi, 50px)/1.15 "Alex Brush", cursive;
  color: var(--emerald);
  margin-bottom: .2em !important;
}

/* The monogram seal: the couple's initials, engraved in the gold. */
.lt-seal,
.pk-seal,
.lt-flyseal {
  aspect-ratio: 1;
  background: url(../assets/letter/seal.webp) center / contain no-repeat;
  container-type: size;
  display: grid;
  place-items: center;
}

.lt-seal {
  width: clamp(64px, 22cqi, 104px);
  margin: .2em auto 0 !important;
  filter: drop-shadow(0 3px 4px rgba(50, 30, 5, .35));
}

.lt-mono {
  font: 700 31cqw/1 "Cormorant Garamond", Georgia, serif;
  letter-spacing: .01em;
  color: #47300a;
  text-shadow: 0 .035em 0 rgba(255, 240, 196, .85), 0 -.025em .01em rgba(40, 24, 2, .55);
  translate: 0 -.03em;
}

.lt-mono i {
  font-size: .62em;
  font-style: italic;
  margin: 0 .04em;
  vertical-align: .18em;
}

/* ------------------------------------------------------------ the casket */

.lt-keep {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

.letter.is-open .lt-keep { margin-top: clamp(22px, 6cqi, 40px); }

.lt-casket {
  position: relative;               /* no z-index: its pieces layer with the letter */
  display: block;
  width: min(84cqi, 520px);
  aspect-ratio: var(--casket-r);
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  border-radius: 12px;
  -webkit-tap-highlight-color: transparent;
}

/* Shut, the room kept above the box for the lid to stand up in is not
   needed, so the casket sits up into it, closer to the heading. */
.letter:not(.is-open) .lt-casket {
  margin-top: calc(min(84cqi, 520px) / var(--casket-r) * -.19);
}

.letter.is-open .lt-casket {
  width: min(56cqi, 300px);
  cursor: default;
}

.lt-casket:focus-visible { outline: 2px solid var(--gold-deep); outline-offset: 6px; }

/* a soft shadow on the marble under its feet */
.lt-casket::before {
  content: "";
  position: absolute;
  left: 9%;
  right: 9%;
  bottom: 1%;
  height: 7%;
  background: radial-gradient(closest-side, rgba(45, 32, 12, .5), transparent);
  filter: blur(3px);
}

:where(.lt-casket) > span {
  position: absolute;
  inset: 0;
  background: center / 100% 100% no-repeat;
  pointer-events: none;
}

.c-lid-open {
  z-index: 1;
  background-image: url(../assets/letter/casket-open.webp);
  clip-path: inset(0 0 calc(100% - var(--hinge)) 0);
  transform-origin: 50% var(--hinge);
  opacity: 0;
}

.c-body {
  z-index: 2;
  background-image: url(../assets/letter/casket-open.webp);
  clip-path: inset(var(--hinge) 0 0 0);
}

.c-front {
  z-index: 4;
  background-image: url(../assets/letter/casket-open.webp);
  clip-path: inset(var(--rim) 0 0 0);
}

.c-lid {
  z-index: 5;
  background-image: url(../assets/letter/casket-lid.webp);
  transform-origin: 50% var(--hinge);
}

/* now and then, light runs over the shut lid's mirrors */
.c-lid::after {
  content: "";
  position: absolute;
  inset: 0;
  -webkit-mask: url(../assets/letter/casket-lid.webp) center / 100% 100% no-repeat;
          mask: url(../assets/letter/casket-lid.webp) center / 100% 100% no-repeat;
  background: linear-gradient(105deg, transparent 38%, rgba(255, 250, 232, .75) 50%, transparent 62%) -160% 0 / 260% 100% no-repeat;
  mix-blend-mode: screen;
  animation: lt-sheen 5.5s ease-in-out 1.2s infinite;
}

@keyframes lt-sheen {
  0% { background-position: -160% 0; }
  38%, 100% { background-position: 260% 0; }
}

/* the mirror inside the lid catches the light as it stands up */
.c-sheen {
  position: absolute;
  inset: var(--mirror);
  background: linear-gradient(110deg, transparent 30%, rgba(255, 252, 240, .85) 48%, rgba(255, 240, 200, .3) 56%, transparent 70%) -170% 0 / 260% 100% no-repeat;
  mix-blend-mode: screen;
}

.letter.is-open .c-lid { opacity: 0; }
.letter.is-open .c-lid-open { opacity: 1; }
.letter.is-open .c-lid::after { animation: none; }

.lt-hint {
  margin: 14px 0 0;
  font: italic 500 clamp(15px, 4.4cqi, 19px)/1.3 "Cormorant Garamond", Georgia, serif;
  color: var(--gold-deep);
  animation: lt-hint 2.8s ease-in-out infinite;
}

.letter.is-open .lt-hint { display: none; }

@keyframes lt-hint {
  0%, 100% { opacity: .55; }
  50% { opacity: 1; }
}

.lt-sr {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ------------------------------------------------------------ the folded letter */

/* Three panels, each showing its third of a copy of the letter; the top and
   bottom ones folded over the middle, their backs plain paper. */
.lt-packet {
  position: absolute;
  z-index: 3;
  perspective: 1800px;
  transform-style: preserve-3d;
  pointer-events: none;
  transform-origin: 50% 50%;
}

.pk-panel {
  position: absolute;
  left: 0;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
}

.pk-mid { top: 0; }
.pk-top { bottom: 100%; transform-origin: 50% 100%; }
.pk-bottom { top: 100%; transform-origin: 50% 0; }

.pk-face,
.pk-back {
  position: absolute;
  inset: 0;
  overflow: hidden;
  -webkit-backface-visibility: hidden;
          backface-visibility: hidden;
}

.pk-face > .lt-letter {
  position: absolute;
  left: 0;
  box-shadow: none;
}

.pk-face .lt-seal { visibility: hidden; }

.pk-back {
  transform: rotateX(180deg);
  background:
    linear-gradient(180deg, rgba(120, 90, 40, .12), transparent 18%, transparent 82%, rgba(120, 90, 40, .12)),
    url(../assets/letter/paper-back.webp) center / cover;
  box-shadow: inset 0 0 0 1px rgba(150, 118, 60, .3);
}

.pk-mid .pk-face { box-shadow: 0 10px 24px -10px rgba(50, 35, 10, .45); }

.pk-seal {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 34%;
  max-height: 86%;
  translate: -50% -50%;
  transform: translateZ(4px);
  filter: drop-shadow(0 3px 4px rgba(50, 30, 5, .4));
}

.lt-flyseal {
  position: absolute;
  z-index: 6;
  pointer-events: none;
  filter: drop-shadow(0 5px 8px rgba(50, 30, 5, .35));
}

/* ------------------------------------------------------------ arriving */

/* The heading and the casket come up as the section comes into view. */
.lt-head,
.lt-keep {
  transition: opacity 1s ease, translate 1.2s cubic-bezier(.2, .7, .2, 1);
}

.lt-keep { transition-delay: .15s; }

.letter:not(.is-seen) .lt-head,
.letter:not(.is-seen) .lt-keep {
  opacity: 0;
  translate: 0 16px;
}

/* ------------------------------------------------------------ sideways tablets */

/* Open, the casket stands to the left of the letter, level with the middle of
   the screen as the letter scrolls past. */
@media (min-aspect-ratio: 6/5) {
  html.is-tablet .letter.is-open .lt-stage {
    display: grid;
    grid-template-columns: min(28cqi, 330px) minmax(0, 580px);
    justify-content: center;
    align-items: start;
    column-gap: clamp(24px, 4.5cqi, 60px);
  }
  html.is-tablet .letter.is-open .lt-slot { grid-column: 2; grid-row: 1; }
  html.is-tablet .letter.is-open .lt-keep {
    grid-column: 1;
    grid-row: 1;
    position: sticky;
    top: calc(50svh - 12cqi);
    margin-top: 12vh;
  }
  html.is-tablet .letter.is-open .lt-casket { width: 100%; }
}

/* ------------------------------------------------------------ calm */

@media (prefers-reduced-motion: reduce) {
  .c-lid::after,
  .lt-hint { animation: none; }
  .lt-head,
  .lt-keep { transition: none; }
  .lt-hint { opacity: .9; }
}
