/* Polaroids above the glowing garden + realistic kraft handwritten letter */

:root {
  --vf-ink: #34302c;
  --vf-paper: #d9c8a8;
  --vf-hand: "Pangolin", "Caveat", "Segoe Print", "Comic Sans MS", cursive;
}

body {
  position: relative;
}

.polaroid-sky {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: 0;
  right: 0;
  z-index: 40;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: clamp(8px, 2.5vw, 18px);
  padding: 0 12px;
  pointer-events: none;
}

.polaroid {
  width: min(28vw, 132px);
  background:
    linear-gradient(180deg, #fffefb 0%, #f7f2ea 100%);
  padding: 7px 7px 22px;
  border-radius: 2px;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.85) inset,
    0 14px 28px rgba(0, 0, 0, 0.38),
    0 2px 6px rgba(0, 0, 0, 0.25);
  transform-origin: 50% 100%;
  animation: polaroid-float 5.6s ease-in-out infinite;
  opacity: 0;
  transition: opacity 0.8s ease, transform 0.8s ease;
}

body:not(.not-loaded) .polaroid {
  opacity: 1;
}

.polaroid:nth-child(1) {
  transform: rotate(-9deg) translateY(10px);
  animation-delay: 0s;
}

.polaroid:nth-child(2) {
  width: min(30vw, 148px);
  transform: rotate(2deg) translateY(0);
  animation-delay: 0.35s;
  z-index: 2;
}

.polaroid:nth-child(3) {
  transform: rotate(8deg) translateY(14px);
  animation-delay: 0.7s;
}

.polaroid.is-empty {
  display: none;
}

.polaroid img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  background: #1a2230;
  box-shadow: inset 0 0 0 1px rgba(40, 30, 20, 0.12);
}

.polaroid figcaption {
  margin-top: 7px;
  font-family: var(--vf-hand);
  font-size: clamp(11px, 2.8vw, 13px);
  color: #5a4a3a;
  text-align: center;
  line-height: 1.15;
  min-height: 1.15em;
}

@keyframes polaroid-float {
  0%, 100% { translate: 0 0; }
  50% { translate: 0 -7px; }
}

.flowers {
  /* Absolute children do not expand .flowers — keep a real hit box */
  position: relative;
  width: min(92vw, 560px);
  height: min(78vh, 620px);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.bouquet-hit {
  position: absolute;
  inset: 8% 10% 0;
  z-index: 30;
  border: 0;
  padding: 0;
  margin: 0;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.bouquet-hit:focus-visible {
  outline: 2px solid rgba(145, 233, 255, 0.75);
  outline-offset: 4px;
  border-radius: 24px;
}

.open-hint {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 45;
  margin: 0;
  display: grid;
  place-items: center;
  width: 76px;
  height: 64px;
  padding: 4px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.6s ease;
}

.envelope-icon {
  display: block;
  width: 68px;
  height: 54px;
  overflow: visible;
  filter: drop-shadow(0 3px 7px rgba(0, 0, 0, 0.4)) drop-shadow(0 0 12px rgba(242, 194, 169, 0.18));
  animation: envelope-float 4s ease-in-out infinite;
  transition: scale 0.2s ease;
}

.open-hint:hover .envelope-icon,
.open-hint:focus-visible .envelope-icon {
  scale: 1.08;
}

.open-hint:focus-visible {
  outline: 2px solid #f3cfbf;
  outline-offset: 3px;
}

.open-hint:active .envelope-icon {
  scale: 0.96;
}

@keyframes envelope-float {
  0%, 100% { transform: translateY(0) rotate(-5deg); }
  50% { transform: translateY(-4px) rotate(2deg); }
}

body:not(.not-loaded) .open-hint {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

body.is-letter-open .open-hint {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* ===== Kraft letter popup ===== */
.letter-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 16px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: rgba(4, 10, 18, 0);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.45s ease, background-color 0.45s ease;
}

.letter-overlay.is-visible {
  opacity: 1;
  pointer-events: auto;
  background: rgba(4, 10, 18, 0.62);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.letter-popup {
  --letter-ink: var(--vf-ink);
  position: relative;
  width: min(460px, 90vw);
  margin: 64px 0 28px;
  filter:
    drop-shadow(0 22px 30px rgba(8, 16, 24, 0.55))
    drop-shadow(0 3px 5px rgba(8, 16, 24, 0.35));
  transform-origin: 50% 70%;
  opacity: 0;
}

.letter-overlay.is-visible .letter-popup {
  animation: letter-emerge 1.2s cubic-bezier(0.22, 0.8, 0.25, 1) forwards;
}

.letter-overlay.is-leaving .letter-popup {
  animation: letter-leave 0.4s ease forwards;
}

@keyframes letter-emerge {
  0% {
    opacity: 0;
    transform: perspective(1400px) translateY(18vh) scale(0.42, 0.28) rotateX(42deg);
  }
  16% { opacity: 1; }
  52% {
    opacity: 1;
    transform: perspective(1400px) translateY(-4vh) scale(0.72, 0.68) rotateX(14deg) rotate(-3deg);
  }
  100% {
    opacity: 1;
    transform: perspective(1400px) translateY(0) scale(1) rotateX(0) rotate(-1.5deg);
  }
}

@keyframes letter-leave {
  from { opacity: 1; transform: rotate(-1.5deg); }
  to { opacity: 0; transform: translateY(18px) scale(0.94) rotate(-2deg); }
}

.letter-tape {
  position: absolute;
  z-index: 1;
  top: -34px;
  right: 6%;
  width: 46%;
  height: 118px;
  background-color: #93b39a;
  background-image:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/><feColorMatrix values='0 0 0 0 0.2  0 0 0 0 0.3  0 0 0 0 0.22  0 0 0 0.35 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>"),
    linear-gradient(160deg, rgba(255, 255, 255, 0.28) 0%, transparent 45%, rgba(40, 70, 50, 0.18) 100%);
  clip-path: polygon(3% 12%, 18% 4%, 34% 9%, 52% 1%, 70% 7%, 86% 0%, 100% 6%, 97% 38%, 100% 70%, 96% 100%, 0% 100%, 4% 64%, 0% 36%);
  transform: rotate(7deg);
  pointer-events: none;
}

.letter-paper {
  position: relative;
  z-index: 2;
  max-height: calc(88vh - 72px);
  padding: 64px 32px 26px 36px;
  color: var(--letter-ink);
  background-color: var(--vf-paper);
  background-image:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='220'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.36  0 0 0 0 0.27  0 0 0 0 0.17  0 0 0 0.55 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>"),
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='600' height='600'><filter id='b'><feTurbulence type='fractalNoise' baseFrequency='0.012' numOctaves='3' seed='7'/><feColorMatrix values='0 0 0 0 0.45  0 0 0 0 0.34  0 0 0 0 0.2  0 0 0 0.42 0'/></filter><rect width='100%25' height='100%25' filter='url(%23b)'/></svg>"),
    radial-gradient(ellipse at 30% 20%, rgba(250, 240, 218, 0.7) 0%, transparent 60%),
    radial-gradient(ellipse at 90% 95%, rgba(120, 90, 55, 0.3) 0%, transparent 55%),
    radial-gradient(ellipse at 0% 60%, rgba(120, 90, 55, 0.22) 0%, transparent 40%);
  background-size: 220px 220px, 600px 600px, 100% 100%, 100% 100%, 100% 100%;
  clip-path: polygon(
    0% 1.6%, 2.4% 0.9%, 4.1% 1.9%, 6.8% 0.4%, 8.9% 1.4%, 11.5% 0.7%, 13.2% 2%, 16.4% 1%, 18.3% 0.2%,
    21.7% 1.5%, 24.1% 0.6%, 26.9% 1.8%, 29.5% 0.9%, 32.2% 0.3%, 35.4% 1.6%, 37.1% 0.8%, 40.6% 2.1%,
    43.3% 0.5%, 46% 1.3%, 48.7% 0.2%, 51.9% 1.7%, 54.2% 0.9%, 57.3% 0.3%, 59.8% 1.9%, 62.5% 0.7%,
    65.4% 1.4%, 68.2% 0.2%, 70.9% 1.6%, 73.3% 0.8%, 76.6% 2%, 79.1% 0.5%, 81.8% 1.2%, 84.7% 0.3%,
    87.2% 1.8%, 90.1% 0.6%, 92.6% 1.5%, 95.3% 0.4%, 97.8% 1.7%, 100% 0.8%,
    99.1% 4.5%, 100% 8.2%, 98.9% 12.1%, 99.7% 16.8%, 98.6% 21.4%, 99.8% 25.9%, 99% 30.2%, 100% 34.8%,
    98.7% 39.6%, 99.6% 44.1%, 98.8% 48.7%, 99.9% 53.2%, 98.9% 57.9%, 99.7% 62.4%, 98.6% 67.1%,
    99.8% 71.6%, 99% 76.2%, 100% 80.9%, 98.8% 85.3%, 99.6% 89.8%, 98.9% 94.4%, 99.8% 98.2%,
    97.6% 99.3%, 94.9% 98.4%, 92.1% 99.8%, 89.4% 98.7%, 86.8% 99.5%, 83.9% 98.2%, 81.2% 99.7%,
    78.3% 98.9%, 75.6% 100%, 72.8% 98.5%, 70.1% 99.4%, 67.3% 98.1%, 64.4% 99.8%, 61.8% 98.8%,
    58.9% 99.6%, 56.2% 98.3%, 53.4% 100%, 50.6% 98.7%, 47.9% 99.5%, 45.1% 98.2%, 42.2% 99.9%,
    39.6% 98.6%, 36.8% 99.4%, 33.9% 98.1%, 31.3% 99.8%, 28.5% 98.9%, 25.7% 99.7%, 22.8% 98.3%,
    20.1% 99.9%, 17.4% 98.6%, 14.6% 99.5%, 11.8% 98.2%, 9.1% 99.8%, 6.3% 98.8%, 3.6% 99.6%, 0.9% 98.4%,
    0.2% 94.1%, 1.2% 89.7%, 0% 85.2%, 0.9% 80.6%, 0.1% 76.1%, 1.3% 71.5%, 0.3% 66.9%, 1.1% 62.3%,
    0% 57.8%, 1% 53.1%, 0.2% 48.6%, 1.4% 44%, 0.1% 39.5%, 0.9% 34.9%, 0% 30.4%, 1.2% 25.8%,
    0.3% 21.2%, 1.1% 16.7%, 0% 12.1%, 0.8% 7.6%, 0.1% 4.2%
  );
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.letter-close {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 6;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid rgba(60, 45, 30, 0.3);
  background: rgba(255, 248, 232, 0.45);
  color: #4d3e30;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
  transition: transform 0.18s ease, background 0.18s ease;
}

.letter-close svg {
  width: 12px;
  height: 12px;
  display: block;
}

.letter-close:hover,
.letter-close:focus-visible {
  background: rgba(255, 248, 232, 0.85);
  transform: scale(1.08) rotate(90deg);
  outline: none;
}

.letter-wish {
  position: relative;
  z-index: 2;
  margin: 0 0 14px;
  font-family: var(--vf-hand);
  font-size: clamp(22px, 5.2vw, 28px);
  font-weight: 400;
  line-height: 1.35;
  color: var(--vf-ink);
  text-shadow: 0 0 0.6px rgba(40, 32, 26, 0.55);
}

.letter-wish:empty {
  display: none;
}

.letter-body {
  position: relative;
  z-index: 2;
  font-family: var(--vf-hand);
  font-weight: 400;
  line-height: 1.55;
  text-align: left;
  color: var(--vf-ink);
  text-shadow: 0 0 0.6px rgba(40, 32, 26, 0.55);
  word-break: break-word;
  overflow-wrap: anywhere;
}

/* Leave room for the hanging flower sprig like a real letter */
.letter-body::before {
  content: "";
  float: right;
  width: 30%;
  height: 3.4em;
  font-size: 23px;
}

.letter-body p {
  margin: 0;
  font-size: clamp(20px, 4.8vw, 23px);
  letter-spacing: 0.01em;
}

.letter-body p + p {
  margin-top: 12px;
}

.letter-body .pt-char {
  opacity: 0;
  transition: opacity 0.06s linear;
}

.letter-body .pt-char.is-on {
  opacity: 1;
}

.letter-body .pt-caret {
  display: inline-block;
  width: 2px;
  height: 1em;
  margin-left: 2px;
  background: currentColor;
  vertical-align: -2px;
  animation: pt-caret-blink 0.7s steps(2, end) infinite;
  opacity: 0.7;
}

@keyframes pt-caret-blink {
  50% { opacity: 0; }
}

.letter-sign {
  position: relative;
  z-index: 2;
  margin: 18px 4px 0 auto;
  width: max-content;
  max-width: 100%;
  font-family: var(--vf-hand);
  font-size: clamp(21px, 5vw, 25px);
  color: var(--vf-ink);
  text-align: right;
  overflow-wrap: anywhere;
  opacity: 0;
  transform: translateY(4px) rotate(-2deg);
  transition: opacity 0.8s ease, transform 0.8s ease;
}

.letter-popup.is-ready .letter-sign {
  opacity: 1;
  transform: translateY(0) rotate(-2deg);
}

.letter-sign:empty {
  display: none;
}

.letter-flower {
  position: absolute;
  z-index: 3;
  top: -76px;
  right: -46px;
  width: 52%;
  max-width: 220px;
  height: auto;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
  transform-origin: 30% 20%;
  filter: drop-shadow(2px 4px 3px rgba(40, 30, 10, 0.35));
}

.letter-overlay.is-visible .letter-flower {
  animation: letter-flower-sway 5.5s ease-in-out 1.3s infinite;
}

@keyframes letter-flower-sway {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(-2.5deg); }
}

@media (max-width: 420px) {
  .polaroid {
    width: min(27vw, 108px);
    padding: 5px 5px 16px;
  }

  .polaroid:nth-child(2) {
    width: min(29vw, 118px);
  }

  .polaroid figcaption {
    font-size: 10px;
  }

  .letter-paper {
    padding: 56px 18px 18px 22px;
  }

  .letter-flower {
    top: -64px;
    right: -22px;
    width: 46%;
  }

  .letter-body p,
  .letter-wish {
    font-size: 19px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .envelope-icon {
    animation: none;
    transition: none;
  }

  .open-hint {
    transition: none;
  }

  .polaroid,
  .letter-overlay.is-visible .letter-flower {
    animation: none;
  }

  .letter-overlay.is-visible .letter-popup {
    animation: none;
    opacity: 1;
    transform: none;
  }

  .letter-body .pt-char {
    opacity: 1;
    transition: none;
  }
}

/* Fast, comfortable interactions for the garden and its keepsakes. */
.polaroid-open {
  display: block;
  width: 100%;
  border: 0;
  background: transparent;
  cursor: zoom-in;
  pointer-events: auto;
  border-radius: 2px;
}
.polaroid img { height: auto; }
.polaroid:hover, .polaroid:focus-within { animation-play-state: paused; }
.polaroid-open:focus-visible {
  outline: 3px solid #d98798;
  outline-offset: 4px;
}
.polaroid figcaption {
  overflow: hidden;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.letter-popup { margin: 48px 0 20px; }
.letter-paper { max-height: calc(100dvh - 152px); }
.letter-close {
  width: 44px;
  height: 44px;
  top: 10px;
  left: 10px;
  background: #f3e5cd;
}
.letter-close svg { width: 16px; height: 16px; }
.letter-read-all {
  position: absolute;
  top: 10px;
  right: 12px;
  z-index: 6;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid #ad9279;
  border-radius: 999px;
  background: #f5e8d5;
  color: #574032;
  font: 14px/1.2 var(--vf-hand);
  cursor: pointer;
}
.letter-read-all[hidden] { display: none; }
.letter-read-all:focus-visible,
.photo-viewer button:focus-visible {
  outline: 3px solid #d98798;
  outline-offset: 3px;
}
.letter-paper { border-top: 64px solid transparent; padding-top: 12px; }
.letter-body::before { display: none; }
.letter-sign { max-width: calc(100% - 12px); }
.letter-wish { overflow-wrap: anywhere; }
.letter-flower { height: auto; z-index: 1; }
.photo-overlay {
  position: fixed;
  inset: 0;
  z-index: 220;
  display: grid;
  place-items: center;
  padding: 72px 18px 24px;
  background: rgba(4, 10, 18, .92);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity .2s ease;
}
.photo-overlay.is-visible { opacity: 1; visibility: visible; pointer-events: auto; }
.photo-viewer {
  position: relative;
  width: min(560px, 100%);
  max-height: calc(100dvh - 96px);
  padding: 12px;
  overflow-y: auto;
  border-radius: 8px;
  background: #fff6eb;
  box-shadow: 0 18px 60px #0006;
  color: #574032;
  text-align: center;
}
#photoFull {
  display: block;
  width: 100%;
  height: min(58dvh, 540px);
  object-fit: contain;
  background: #eee1d6;
  border-radius: 3px;
}
#photoCaption {
  font: 18px/1.4 var(--vf-hand);
  margin: 12px 10px 2px;
  overflow-wrap: anywhere;
}
.photo-viewer button {
  display: inline-grid;
  place-items: center;
  border: 1px solid #cbb2a4;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  background: #fff6eb;
  color: #574032;
  font: 28px/1 system-ui, sans-serif;
  cursor: pointer;
}
.photo-close { position: absolute; z-index: 1; top: 18px; right: 18px; }
.photo-navigation { display: flex; justify-content: center; align-items: center; gap: 20px; margin-top: 8px; }
.photo-navigation button[hidden] { display: none; }
#photoCount { font: 13px/1.2 system-ui, sans-serif; }
.scene-paused .flowers *,
.scene-paused .polaroid,
.scene-paused .envelope-icon { animation-play-state: paused !important; }
@media (max-width: 600px) {
  .flower__light--5, .flower__light--6, .flower__light--7, .flower__light--8 { display: none; }
  .flower__g-long, .flower__g-right, .flower__g-front, .flower__g-fr, .long-g .leaf { animation: none; }
  .polaroid-sky { top: max(68px, calc(env(safe-area-inset-top) + 56px)); gap: 8px; padding: 0 18px; }
  .polaroid, .polaroid:nth-child(2) { width: min(25vw, 112px); }
}
@media (max-height: 500px) and (min-width: 601px) {
  .polaroid-sky { justify-content: flex-end; padding-right: 70px; top: 64px; gap: 8px; }
  .polaroid, .polaroid:nth-child(2) { width: 76px; padding: 4px 4px 12px; }
  .polaroid figcaption { font-size: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  .flowers *, .flowers *::before, .flowers *::after { animation: none !important; }
  .letter-overlay, .photo-overlay { transition: none; }
  .letter-overlay.is-leaving .letter-popup { animation: none; }
}
