/* ============================================================
   LEDURA home: seal, where the night turns into morning
   A gatefold letter closed by a gold wax seal. js/fx-seal.js pins
   the section, cracks the wax, opens the flaps and drives the sky
   clock (--dawn). The static state is the letter already open,
   the broken seal resting on its lower edge.
   --lit is the light this section stands in: the sky's --dawn when
   the sky runs, full morning when it does not.
   ============================================================ */
.seal { --lit: 1; position: relative; overflow: clip; }
html.has-sky .seal { --lit: var(--dawn); }

.seal-stage {
  --lw: clamp(290px, 29vw, 400px);
  min-height: 100svh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  align-items: center;
  gap: clamp(40px, 7vw, 120px);
  max-width: var(--maxw);
  margin: 0 auto;
  padding: clamp(96px, 13svh, 128px) var(--gutter) clamp(48px, 8svh, 88px);
}

/* ---------- copy: night ink until the light is up ---------- */
/* The switch is steep and early: the day reaches the middle of the
   screen (where the copy sits) at about a third of the sunrise. */
.seal-copy { --ink-mix: calc(clamp(0, (var(--lit) - .28) / .18, 1) * 100%); max-width: 30rem; }
.seal .seal-title {
  font-size: clamp(34px, 4vw, 60px);
  color: color-mix(in srgb, var(--ink) var(--ink-mix), var(--night-ink));
}
.seal .seal-copy p {
  margin: 18px 0 0;
  font-size: var(--fs-lead);
  color: color-mix(in srgb, var(--body) var(--ink-mix), var(--night-body));
}

/* ---------- the letter ---------- */
.letter {
  position: relative;
  justify-self: center;
  width: var(--lw);
  aspect-ratio: 4 / 5;
  perspective: 1600px;
}
/* The night still sits on the paper and lifts as the light arrives;
   the wax stays lit, the one warm thing on the dark desk. */
/* A warm dark veil (opacity only, cheap to scrub) rides on each face. */
.letter-paper::after, .letter-flap::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  /* candlelit, not grey: the veil carries a little gold, glowing from the wax */
  background: radial-gradient(circle at 50% 55%, color-mix(in srgb, var(--night-bg) 55%, var(--gold-deep)), color-mix(in srgb, var(--night-bg) 82%, var(--gold-deep)) 75%);
  opacity: calc((1 - var(--lit)) * .5);
  pointer-events: none;
}
.letter-paper {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 18px;
  padding: 13% 12%;
  border-radius: var(--r-sm);
  background:
    radial-gradient(120% 70% at 50% 0%, var(--elevated), transparent 70%),
    var(--surface-2);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--gold) 22%, transparent), var(--shadow-lg);
}
.letter-paper::before {          /* the inner gold rule of good stationery */
  content: "";
  position: absolute;
  inset: 12px;
  border: 1px solid color-mix(in srgb, var(--gold) 30%, transparent);
  border-radius: 6px;
  pointer-events: none;
}
.seal .letter-to {
  margin: 0;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--gold-deep);
}
.seal .letter-body {
  margin: 0;
  font-family: var(--serif);
  font-style: italic;
  font-weight: 400;
  font-size: clamp(21px, 1.8vw, 27px);
  line-height: 1.38;
  color: var(--ink);
  text-wrap: pretty;
}
.letter-mark { display: none; color: var(--gold); font-size: 18px; line-height: 1; }

/* ---------- the gatefold flaps (live only) ---------- */
.letter-flap {
  display: none;
  position: absolute;
  top: 0;
  bottom: 0;
  width: 50%;
  z-index: 2;
  backface-visibility: hidden;
  background: linear-gradient(90deg, var(--soft-tan), color-mix(in srgb, var(--champagne) 70%, var(--soft-tan)));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--gold) 25%, transparent);
}
.letter-flap--l { left: 0; transform-origin: 0 50%; border-radius: var(--r-sm) 0 0 var(--r-sm); }
.letter-flap--r {
  right: 0;
  transform-origin: 100% 50%;
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  background: linear-gradient(270deg, var(--soft-tan), color-mix(in srgb, var(--champagne) 70%, var(--soft-tan)));
}
/* the fold line: a soft shadow where the two flaps meet */
.letter-flap--l::after {
  content: "";
  position: absolute;
  inset: 0 0 0 auto;
  width: 18%;
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--gold-deep) 14%, transparent));
}

/* ---------- the wax seal ---------- */
.wax {
  --ws: calc(var(--lw) * .36);
  position: absolute;
  z-index: 3;
  left: 50%;
  top: 100%;
  width: var(--ws);
  aspect-ratio: 1;
  margin: calc(var(--ws) / -2) 0 0 calc(var(--ws) / -2);
  transform: scale(.62);
  filter: drop-shadow(0 6px 10px color-mix(in srgb, var(--gold-deep) 35%, transparent));
}
.wax-half {
  position: absolute;
  inset: 0;
  /* the seal itself is a Blender render (assets/art/wax-seal.webp);
     each half shows its side of the same image, cut by the crack */
  background: url("../../assets/art/wax-seal.webp") center / contain no-repeat;
}
/* a crack that zigzags through the middle of the wax */
.wax-l { clip-path: polygon(0 0, 53% 0, 47% 17%, 55% 33%, 46% 51%, 54% 68%, 47% 84%, 51% 100%, 0 100%); }
.wax-r { clip-path: polygon(53% 0, 100% 0, 100% 100%, 51% 100%, 47% 84%, 54% 68%, 46% 51%, 55% 33%, 47% 17%); }
/* static: the broken seal rests where the letter was opened */
.wax-l { transform: translate(-4%, 2%) rotate(-6deg); }
.wax-r { transform: translate(4%, 2%) rotate(6deg); }

/* ---------- live (fx-seal): closed letter, whole seal on the fold ---------- */
.seal.is-live .letter-flap { display: block; }
.seal.is-live .letter-mark { display: block; }
/* the words are written down the page: --read (0 to 1) moves a soft ink edge */
.seal.is-live .letter-body {
  -webkit-mask-image: linear-gradient(180deg, var(--ink) calc(var(--read, 1) * 130% - 30%), transparent calc(var(--read, 1) * 130%));
  mask-image: linear-gradient(180deg, var(--ink) calc(var(--read, 1) * 130% - 30%), transparent calc(var(--read, 1) * 130%));
}
.seal.is-live .wax { top: 50%; transform: none; }
.seal.is-live .wax-half { transform: none; }

/* ---------- tablet portrait and phones: copy first, then the letter ---------- */
@media (max-width: 1023px) and (orientation: portrait) {
  .seal-stage {
    --lw: min(calc(100vw - 2 * var(--gutter)), 380px, 46svh);
    grid-template-columns: minmax(0, 1fr);
    align-content: center;
    gap: 36px;
  }
  .seal-copy { order: -1; text-align: center; margin: 0 auto; }
}
@media (max-width: 767px) {
  .seal-stage {
    --lw: min(calc(100vw - 2 * var(--gutter)), 360px, 50svh);
    gap: 28px;
    padding-top: 88px;
  }
  .seal .seal-title { font-size: clamp(30px, 8.4vw, 36px); }
  .seal .seal-copy p { margin-top: 12px; font-size: 16px; }
  .letter { aspect-ratio: 1; }
  .letter-paper { gap: 12px; padding: 8% 9%; }
  .seal .letter-body { font-size: clamp(17px, 4.8vw, 20px); line-height: 1.34; }
  .wax { filter: none; }       /* no re-rasterised shadow while the halves fall */
}

/* Phones held sideways: side by side, the letter sized to the height. */
@media (orientation: landscape) and (max-height: 520px) {
  .seal-stage { --lw: 52svh; grid-template-columns: auto minmax(0, 24rem); justify-content: center; padding-top: 76px; padding-bottom: 20px; gap: 32px; }
  .seal-copy { order: 0; text-align: left; margin: 0; }
  .seal .seal-title { font-size: clamp(26px, 7svh, 34px); }
  .seal .letter-body { font-size: 16px; }
  .letter-paper { gap: 8px; padding: 9% 10%; }
}
