/* A small paper keepsake tucked inside the terminal. */
#chat-dialog .chat-surprise[hidden] {
  display: none !important;
}

#chat-dialog .chat-surprise {
  --love-paper: #fff3dc;
  --love-ink: #6d283d;
  --love-rose: #d5949d;
  --heart-rise: clamp(220px, 48vh, 490px);
  position: absolute;
  inset: calc(var(--crt-frame-y) + var(--crt-bezel) + var(--crt-pad-y) + 58px)
    calc(var(--crt-frame-x) + var(--crt-bezel) + 8px)
    calc(var(--crt-frame-y) + var(--crt-bezel) + 8px);
  z-index: 12;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 22px 20px max(22px, env(safe-area-inset-bottom));
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #ae777e #281820;
  border-radius: 3px 3px 14px 14px;
  background: rgb(31 17 24 / 97%);
  color: var(--love-paper);
  isolation: isolate;
}

#chat-dialog[data-surprise="open"] .crt-terminal-header,
#chat-dialog[data-surprise="open"] .chat-section,
#chat-dialog[data-surprise="open"] .crt-terminal-footer {
  opacity: 0.12;
}

#chat-dialog .love-moment {
  position: relative;
  display: flex;
  flex: 0 0 auto;
  flex-direction: column;
  align-items: center;
  width: min(100%, 440px);
  margin-block: auto;
  isolation: isolate;
}

#chat-dialog .love-kicker {
  position: relative;
  z-index: 5;
  margin: 0 0 20px;
  color: #edc4c6;
  font: 400 10px/1.5 var(--mono);
  letter-spacing: 0.18em;
  text-align: center;
}

#chat-dialog .love-note {
  position: relative;
  z-index: 2;
  width: calc(100% - 46px);
  min-height: 258px;
  padding: 44px 30px 58px;
  border: 1px solid #e0c5a6;
  border-radius: 2px;
  background: var(--love-paper);
  color: var(--love-ink);
  box-shadow: 4px 5px 0 #e9d5b8, 0 12px 24px #08030645;
  text-align: center;
  transform: rotate(-2deg);
  animation: love-letter-arrive 900ms cubic-bezier(0.18, 0.72, 0.24, 1) both;
}

#chat-dialog .love-note h3 {
  margin: 0 0 14px;
  color: var(--love-ink);
  font: 400 clamp(44px, 6vw, 62px)/1.12 Georgia, "Times New Roman", serif;
  letter-spacing: -0.045em;
  text-wrap: balance;
}

#chat-dialog .love-stamp {
  position: absolute;
  top: 13px;
  right: 16px;
  display: grid;
  place-items: center;
  width: 30px;
  height: 33px;
  border: 1px dashed #b66e7d;
  color: #b45f75;
  font: 400 20px/1 Georgia, serif;
  transform: rotate(9deg);
}

#chat-dialog .love-caption {
  max-width: 27ch;
  margin: 0 auto;
  color: #825464;
  font: 400 16px/1.6 Georgia, "Times New Roman", serif;
  text-wrap: pretty;
}

#chat-dialog .love-signature {
  margin: 18px 0 0;
  color: #9b6471;
  font: italic 13px/1.5 Georgia, "Times New Roman", serif;
  text-align: right;
}

#chat-dialog .love-envelope {
  position: relative;
  flex: 0 0 auto;
  width: 100%;
  height: 126px;
  margin-top: -56px;
  border: 1px solid #b67e88;
  border-radius: 2px 2px 5px 5px;
  background: #bc8790;
  box-shadow: 0 12px 20px #08030640;
}

#chat-dialog .love-envelope::before,
#chat-dialog .love-envelope::after {
  content: "";
  position: absolute;
  inset: -1px;
  z-index: 3;
  border-radius: inherit;
  pointer-events: none;
}

#chat-dialog .love-envelope::before {
  background: #e6b2b5;
  clip-path: polygon(0 0, 50% 65%, 100% 0, 100% 100%, 0 100%);
}

#chat-dialog .love-envelope::after {
  background: #f0c5bf;
  clip-path: polygon(0 100%, 50% 34%, 100% 100%);
}

#chat-dialog .love-flap {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: #c88e97;
  clip-path: polygon(0 0, 100% 0, 50% 82%);
  transform: rotateX(180deg);
  transform-origin: center top;
  animation: love-envelope-open 900ms cubic-bezier(0.24, 0.65, 0.3, 1) both;
}

#chat-dialog .love-seal {
  position: absolute;
  top: 67%;
  left: 50%;
  z-index: 4;
  display: grid;
  place-items: center;
  width: 39px;
  height: 39px;
  border: 1px solid #a35069;
  border-radius: 50%;
  background: #873d55;
  color: #ffe6d6;
  box-shadow: 0 2px 0 #70273e;
  font: 400 24px/1 Georgia, serif;
  transform: translate(-50%, -50%);
  animation: love-seal-pulse 800ms ease-in-out 1s 3;
}

#chat-dialog .love-close {
  position: relative;
  z-index: 5;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-width: 164px;
  min-height: 44px;
  margin-top: 22px;
  padding: 11px 18px;
  border: 1px solid #edc4c6;
  border-radius: 3px;
  background: #fff0dd;
  color: #6d283d;
  font: 500 12px/1.5 var(--mono);
  cursor: pointer;
  transition: background-color 160ms ease, border-color 160ms ease;
}

#chat-dialog .love-close:hover {
  border-color: #fff3dc;
  background: #ffe0da;
}

#chat-dialog .love-close:focus-visible {
  outline: 3px solid #fff3dc;
  outline-offset: 5px;
}

#chat-dialog .love-particles {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

#chat-dialog .love-heart {
  position: absolute;
  bottom: 5%;
  left: var(--x, 50%);
  color: #e6a2ad;
  opacity: 0;
  font: 400 var(--size, 24px)/1 Georgia, serif;
  animation: love-heart-flight var(--duration, 5s) ease-out var(--delay, 0s) both;
}

#chat-dialog .love-heart:nth-child(3n) {
  color: #ffe0cc;
}

#chat-dialog .love-heart:nth-child(3n + 2) {
  color: #bc6d84;
}

#chat-dialog .chat-surprise.is-paused *,
#chat-dialog .chat-surprise.is-paused *::before,
#chat-dialog .chat-surprise.is-paused *::after {
  animation-play-state: paused !important;
}

@keyframes love-letter-arrive {
  from {
    opacity: 0;
    transform: translateY(52px) rotate(2deg) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) rotate(-2deg) scale(1);
  }
}

@keyframes love-envelope-open {
  from { transform: rotateX(0deg); }
  to { transform: rotateX(180deg); }
}

@keyframes love-seal-pulse {
  0%, 100% { transform: translate(-50%, -50%) scale(1); }
  45% { transform: translate(-50%, -50%) scale(1.14); }
}

@keyframes love-heart-flight {
  0% {
    opacity: 0;
    transform: translate3d(0, 24px, 0) rotate(var(--tilt, -12deg)) scale(0.7);
  }
  12% { opacity: 0.85; }
  72% { opacity: 0.65; }
  100% {
    opacity: 0;
    transform: translate3d(var(--drift, 20px), calc(-1 * var(--heart-rise)), 0)
      rotate(calc(var(--tilt, -12deg) + 32deg)) scale(1.12);
  }
}

@media (max-width: 600px) {
  #chat-dialog .chat-surprise {
    padding: 18px 16px max(18px, env(safe-area-inset-bottom));
  }
  #chat-dialog .love-moment {
    width: min(100%, 360px);
  }
  #chat-dialog .love-kicker {
    margin-bottom: 16px;
    font-size: 9px;
    letter-spacing: 0.13em;
  }
  #chat-dialog .love-note {
    width: calc(100% - 26px);
    min-height: 234px;
    padding: 41px 18px 49px;
  }
  #chat-dialog .love-note h3 {
    margin-bottom: 12px;
    font-size: clamp(40px, 12vw, 52px);
  }
  #chat-dialog .love-caption {
    font-size: 15px;
  }
  #chat-dialog .love-signature {
    margin-top: 14px;
    font-size: 12px;
  }
  #chat-dialog .love-envelope {
    height: 102px;
    margin-top: -48px;
  }
  #chat-dialog .love-seal {
    width: 34px;
    height: 34px;
    font-size: 21px;
  }
  #chat-dialog .love-close {
    margin-top: 18px;
  }
}

@media (max-width: 600px) and (max-height: 600px) {
  #chat-dialog .love-kicker { margin-bottom: 10px; }
  #chat-dialog .love-note {
    min-height: 190px;
    padding: 29px 18px 35px;
  }
  #chat-dialog .love-note h3 { font-size: 38px; }
  #chat-dialog .love-caption { font-size: 13px; }
  #chat-dialog .love-signature { margin-top: 10px; font-size: 11px; }
  #chat-dialog .love-envelope { height: 82px; margin-top: -40px; }
  #chat-dialog .love-close { margin-top: 14px; }
}

/* Keep the letter and its exit together when a phone is turned sideways. */
@media (max-height: 540px) and (min-width: 600px) {
  #chat-dialog .chat-surprise {
    top: calc(var(--crt-frame-y) + var(--crt-bezel) + var(--crt-pad-y) + 48px);
    padding: 14px 24px max(14px, env(safe-area-inset-bottom));
  }
  #chat-dialog .love-moment {
    display: grid;
    grid-template-columns: minmax(0, 320px) auto;
    align-items: center;
    column-gap: 30px;
    width: min(100%, 540px);
  }
  #chat-dialog .love-kicker {
    display: none;
  }
  #chat-dialog .love-note {
    grid-area: 1 / 1;
    justify-self: center;
    align-self: start;
    width: calc(100% - 30px);
    min-height: 188px;
    padding: 23px 20px 48px;
  }
  #chat-dialog .love-note h3 {
    margin-bottom: 8px;
    font-size: 42px;
  }
  #chat-dialog .love-caption {
    font-size: 13px;
    line-height: 1.45;
  }
  #chat-dialog .love-signature {
    margin-top: 10px;
    font-size: 11px;
  }
  #chat-dialog .love-stamp {
    top: 8px;
    right: 10px;
    width: 22px;
    height: 25px;
    font-size: 16px;
  }
  #chat-dialog .love-envelope {
    grid-area: 1 / 1;
    align-self: end;
    height: 72px;
    margin: 0 0 -10px;
  }
  #chat-dialog .love-seal {
    width: 30px;
    height: 30px;
    font-size: 19px;
  }
  #chat-dialog .love-close {
    grid-area: 1 / 2;
    min-width: 158px;
    margin: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  #chat-dialog .love-note,
  #chat-dialog .love-flap,
  #chat-dialog .love-seal,
  #chat-dialog .love-heart {
    animation: none;
  }
  #chat-dialog .love-note {
    transform: none;
  }
  #chat-dialog .love-heart {
    bottom: calc(9% + var(--x, 50%) / 1.6);
    opacity: 0.45;
    transform: rotate(var(--tilt, -12deg));
  }
  #chat-dialog .love-heart:nth-child(even) {
    bottom: calc(92% - var(--x, 50%) / 1.6);
  }
  #chat-dialog .love-close {
    transition: none;
  }
}
