/* letter-fx.css — "the owl delivers the letter" drop-in styles (all classes lf- prefixed) */

.lf-host {
  --lf-owl: clamp(104px, 30vw, 140px);
  --lf-env-w: 320px;
  --lf-env-h: 205px;
  position: fixed;
  inset: 0;
  visibility: hidden;
  pointer-events: none;
  overflow: hidden;
  contain: layout style;
}

.lf-host.lf-host--active {
  visibility: visible;
  pointer-events: auto;
}

/* Night-sky backdrop with warm subtle moonlight center */
.lf-scrim {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: radial-gradient(
    ellipse 72% 62% at 50% 48%,
    rgba(35, 48, 94, 0.78) 0%,
    rgba(13, 17, 46, 0.88) 58%,
    rgba(8, 10, 29, 0.94) 100%
  );
  opacity: 0;
  will-change: opacity;
}

/* 3D envelope stage */
.lf-stage {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  perspective: 1100px;
  -webkit-perspective: 1100px;
}

.lf-env-shadow {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--lf-env-w);
  height: 44px;
  margin-left: calc(var(--lf-env-w) * -0.5);
  margin-top: -22px;
  border-radius: 50%;
  background: radial-gradient(
    ellipse at center,
    rgba(6, 8, 22, 0.58) 0%,
    rgba(6, 8, 22, 0.22) 52%,
    rgba(6, 8, 22, 0) 76%
  );
  opacity: 0;
  visibility: hidden;
  will-change: transform, opacity;
}

.lf-env {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--lf-env-w);
  height: var(--lf-env-h);
  margin-left: calc(var(--lf-env-w) * -0.5);
  margin-top: calc(var(--lf-env-h) * -0.5);
  opacity: 0;
  visibility: hidden;
  will-change: transform, opacity;
}

.lf-env-back {
  position: absolute;
  inset: 0;
  z-index: 1;
  border-radius: 10px;
  background: linear-gradient(180deg, #e5c689 0%, #f1daa7 42%, #f6e3b8 100%);
  border: 1.5px solid #c99a5b;
  box-shadow: 0 22px 46px rgba(5, 8, 26, 0.55);
  overflow: hidden;
}

.lf-env-glow {
  position: absolute;
  inset: 0;
  background: radial-gradient(
    ellipse 86% 74% at 50% 6%,
    rgba(255, 248, 220, 0.96) 0%,
    rgba(244, 185, 66, 0.56) 48%,
    rgba(244, 185, 66, 0) 84%
  );
  opacity: 0;
  will-change: opacity;
}

/* Open inner flap (sits behind rising parchment) */
.lf-flap-open {
  position: absolute;
  left: 0;
  bottom: 100%;
  width: 100%;
  height: 61%;
  z-index: 1;
  transform-origin: 50% 100%;
  opacity: 0;
  visibility: hidden;
  will-change: transform, opacity;
}

.lf-flap-open svg,
.lf-flap-closed svg,
.lf-env-front svg,
.lf-seal svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

/* Rising parchment sheet emerging from inside the envelope pocket */
.lf-sheet {
  position: absolute;
  left: 5%;
  top: 6%;
  width: 90%;
  height: 88%;
  z-index: 2;
  border-radius: 12px 12px 7px 7px;
  background: linear-gradient(180deg, #fffaf0 0%, #fcf0d4 58%, #f6e3b8 100%);
  border: 1.5px solid rgba(201, 154, 91, 0.72);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.85), 0 8px 20px rgba(28, 37, 80, 0.16);
  opacity: 0;
  visibility: hidden;
  will-change: transform, opacity;
  box-sizing: border-box;
}

.lf-sheet-orn {
  position: absolute;
  inset: 10px;
  border-radius: 7px;
  border: 1px solid rgba(201, 154, 91, 0.28);
  pointer-events: none;
}

/* Front folded pocket (covers lower portion of rising parchment) */
.lf-env-front {
  position: absolute;
  inset: 0;
  z-index: 3;
}

/* Closed outer flap (sits in front of pocket until rotated past 90deg) */
.lf-flap-closed {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 61%;
  z-index: 4;
  transform-origin: 50% 0%;
  will-change: transform, opacity;
}

/* Wax seal with embossed star, cracks, and flying shards */
.lf-seal {
  --lf-seal-s: calc(var(--lf-env-h) * 0.275);
  position: absolute;
  left: 50%;
  top: 56%;
  width: var(--lf-seal-s);
  height: var(--lf-seal-s);
  margin-left: calc(var(--lf-seal-s) * -0.5);
  margin-top: calc(var(--lf-seal-s) * -0.5);
  z-index: 5;
  will-change: transform, opacity;
}

.lf-seal-whole,
.lf-seal-cracks,
.lf-shard {
  position: absolute;
  inset: 0;
  will-change: transform, opacity;
}

.lf-seal-cracks {
  opacity: 0;
}

.lf-shard {
  opacity: 0;
  visibility: hidden;
}

/* The real letter window (dialog) */
.lf-win {
  position: absolute;
  left: 0;
  right: 0;
  margin-left: auto;
  margin-right: auto;
  top: calc(var(--lf-owl) * 0.8 + 6px + env(safe-area-inset-top));
  z-index: 3;
  width: min(580px, calc(100vw - 14px));
  min-height: 160px;
  max-height: calc(100vh - var(--lf-owl) * 0.8 - 16px - env(safe-area-inset-top));
  max-height: calc(100dvh - var(--lf-owl) * 0.8 - 16px - env(safe-area-inset-top));
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  border-radius: 22px;
  background: linear-gradient(180deg, #fff9ec 0%, #fcf0d4 55%, #f6e3b8 100%);
  border: 1.5px solid rgba(201, 154, 91, 0.58);
  box-shadow:
    0 24px 60px rgba(7, 10, 32, 0.62),
    inset 0 1px 0 rgba(255, 255, 255, 0.85);
  transform-origin: 50% 0%;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  box-sizing: border-box;
  will-change: transform, opacity, clip-path;
}

.lf-host.lf-host--open .lf-win {
  pointer-events: auto;
  will-change: auto;
}

.lf-body {
  opacity: 0;
  will-change: opacity;
}

.lf-host.lf-host--open .lf-body {
  will-change: auto;
}

/* Single 2D canvas for golden dust, warm glow, and light rays */
.lf-canvas {
  position: absolute;
  inset: 0;
  z-index: 4;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* The owl — exact SVG and colours preserved from reference */
.lf-owl {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 5;
  width: var(--lf-owl);
  height: var(--lf-owl);
  margin: calc(var(--lf-owl) * -0.5) 0 0 calc(var(--lf-owl) * -0.5);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  will-change: transform, opacity;
  filter: drop-shadow(0 10px 12px rgba(0, 0, 0, 0.44));
}

.lf-owl svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
  transform-origin: 50% 90%;
}

.lf-wing {
  transform-box: fill-box;
}

.lf-wing--l {
  transform-origin: 100% 35%;
}

.lf-wing--r {
  transform-origin: 0% 35%;
}

.lf-mail {
  transform-box: fill-box;
  transform-origin: 50% 0%;
}

@keyframes lf-perch {
  0%, 100% { transform: rotate(0deg) translateY(0px); }
  50% { transform: rotate(1.6deg) translateY(-2px); }
}

.lf-host.lf-host--idle .lf-owl svg {
  animation: lf-perch 4.5s ease-in-out infinite;
}

/* Close button — 44x44 minimum, top corner, RTL-safe explicit left */
.lf-x {
  position: absolute;
  z-index: 6;
  top: calc(10px + env(safe-area-inset-top));
  left: 10px;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  padding: 0 0 3px;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 244, 220, 0.55);
  background: rgba(17, 22, 58, 0.78);
  color: #fff4dc;
  font-family: var(--head, "Fredoka", "Assistant", system-ui, sans-serif);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  will-change: transform, opacity;
  -webkit-tap-highlight-color: transparent;
}

.lf-host.lf-host--open .lf-x {
  pointer-events: auto;
}

.lf-x:hover,
.lf-x:focus-visible {
  background: rgba(35, 48, 94, 0.94);
  border-color: #f4b942;
  color: #f4b942;
  outline: none;
}

/* Inside the open letter, hide any duplicate perched owl from mounted form module */
.lf-host .sc-owl__perch {
  display: none;
}
