/* Chapter 2: a storybook page. A unicorn delivers a present inside an arch,
   and the letter inside it unfolds on soft paper. */

/* The page: a small heading, the arch, and the caption underneath, as one centred column.
   The arch's size comes from the screen; everything inside it is sized from its width. */
.delivery {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(12px, 2.2dvh, 20px);
  padding: max(20px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
           max(20px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  text-align: center;
  --ah: min(100dvh - 200px, 1.45 * min(92vw, 470px));   /* arch height */
  --aw: min(92vw, 470px, var(--ah) / 1.2);              /* arch width */
  --win: calc(var(--aw) - 20px);                        /* the picture inside the frame */
  --ground: calc(var(--win) * .23);                     /* the front hill's crest, up from the bottom */
  --pw: calc(var(--aw) * .42);                          /* present */
  --uw: calc(var(--aw) * .54);                          /* unicorn */
}
.delivery-heading {
  margin: 0;
  font: 600 clamp(24px, 3.4vw + 12px, 32px)/1.1 var(--font-serif);
  letter-spacing: .01em;
  color: var(--cocoa);
  text-wrap: balance;
  text-shadow: 0 0 14px var(--blush), 0 0 4px var(--blush);   /* stays crisp if a cloud drifts behind it */
}

/* The arch: a cocoa line, a paper mat, then a thin pink line around the picture */
.delivery-arch {
  position: relative;
  flex: none;
  width: var(--aw);
  height: var(--ah);
  padding: 7px;
  border: 3px solid var(--cocoa);
  border-radius: calc(var(--aw) / 2) calc(var(--aw) / 2) 24px 24px;
  background: var(--paper);
  box-shadow: 0 30px 50px -34px rgba(122, 75, 71, .55);
}
.gift-scene {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  border-radius: calc(var(--win) / 2) calc(var(--win) / 2) 14px 14px;
  clip-path: inset(0 round calc(var(--win) / 2) calc(var(--win) / 2) 14px 14px);
  background: linear-gradient(180deg, #FFD3DE 0%, #FFE3EA 55%, #FFF1EE 100%);
}
.gift-scene::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  border-radius: inherit;
  box-shadow: inset 0 0 0 2px var(--cherry);
  pointer-events: none;
}
.scene-land { position: absolute; inset: 0; pointer-events: none; }
.scene-hills { position: absolute; left: 0; bottom: 0; display: block; width: 100%; height: auto; overflow: visible; }

.trail-sparkle { position: absolute; pointer-events: none; }
.trail-sparkle svg { display: block; width: 100%; height: auto; }
.gift-layer, .gift-track { position: absolute; inset: 0; pointer-events: none; }
.gift-track, .present-holder { will-change: transform; }

.unicorn-box { position: absolute; width: var(--uw); aspect-ratio: 400 / 300; }
.unicorn-box svg { display: block; width: 100%; height: 100%; overflow: visible; }
.unicorn-box svg g { transform-box: fill-box; }
.unicorn-box #wing { transform-origin: 30% 90%; }
.unicorn-box #uni-head { transform-origin: 20% 80%; }
.unicorn-box #uni-tail { transform-origin: 100% 40%; }

/* the present lands on the front hill's crest, in the middle of the arch */
.present-holder {
  position: absolute;
  width: var(--pw);
  aspect-ratio: 1;
  left: calc(50% - var(--pw) / 2);
  bottom: calc(var(--ground) - var(--pw) * .035);
  transform-origin: 50% 12%;
}
.present-shadow {
  position: absolute;
  width: calc(var(--pw) * .8);
  height: calc(var(--pw) * .14);
  left: calc(50% - var(--pw) * .4);
  bottom: calc(var(--ground) - var(--pw) * .085);
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(122, 75, 71, .26), rgba(251, 111, 146, .12) 60%, rgba(251, 111, 146, 0));
}
.present-shadow.is-wiggling { animation: shadow-wiggle 2.4s ease-in-out infinite; }
@keyframes shadow-wiggle { 0%, 70%, 100% { transform: scale(1); opacity: 1; } 75% { transform: scale(.84, 1); opacity: .75; } 87% { transform: scale(1.04, 1); } }
.present {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  pointer-events: none;
  transform-origin: 50% 95%;
}
.present svg { display: block; width: 100%; height: 100%; overflow: visible; }
.is-live .present { pointer-events: auto; }
.is-live .present:hover svg { transform: translateY(-4px); }
.present svg { transition: transform .3s var(--ease-bounce); }
.present:focus-visible { outline: 3px solid var(--candy); outline-offset: 8px; border-radius: 18px; }
.is-wiggling .present { animation: present-wiggle 2.4s ease-in-out infinite; }
@keyframes present-wiggle {
  0%, 70%, 100% { transform: rotate(0deg) translateY(0); }
  75% { transform: rotate(-7deg) translateY(-8px); }
  81% { transform: rotate(6deg) translateY(-3px); }
  87% { transform: rotate(-4deg) translateY(0); }
  93% { transform: rotate(2deg); }
}

/* under the arch, like the words under a picture in a storybook */
.delivery-words { flex: none; display: flex; flex-direction: column; align-items: center; gap: 9px; }
.gift-line {
  margin: 0;
  font: italic 500 clamp(21px, 3.2vw, 27px)/1.2 var(--font-serif);
  color: var(--cocoa);
}
.present-hint {
  margin: 0;
  font: 600 var(--text-small)/1 var(--font-sans);
  color: var(--cocoa-soft);
}

/* A phone turned sideways: the arch on the left, the words beside it, like an open book */
@media (max-height: 520px) and (orientation: landscape) {
  .delivery {
    display: grid;
    grid-template-columns: auto minmax(0, 330px);
    grid-template-rows: 1fr 1fr;
    grid-template-areas: "arch heading" "arch words";
    align-content: center;
    justify-content: center;
    column-gap: clamp(24px, 5vw, 56px);
    row-gap: 14px;
    padding-top: max(12px, env(safe-area-inset-top));
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    --ah: calc(100dvh - 40px);
    --aw: min(var(--ah) / 1.12, 46vw);
    --pw: calc(var(--aw) * .38);
    --uw: calc(var(--aw) * .5);
  }
  .delivery-arch { grid-area: arch; }
  .delivery-heading { grid-area: heading; align-self: end; font-size: 26px; }
  .delivery-words { grid-area: words; align-self: start; }
  .gift-line { font-size: 23px; }
}
.burst-heart { position: absolute; width: 22px; pointer-events: none; z-index: 3; }
.burst-heart svg { display: block; width: 100%; height: auto; }

/* the letter, typed on soft paper */
.letter-viewer {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(10px, 1.8dvh, 16px);
  padding: max(18px, env(safe-area-inset-top)) 14px max(16px, env(safe-area-inset-bottom));
}
.letter-viewer .label { margin: 0; }
.letter-viewer .continue-wrap { margin: 0; }

.letter-paper {
  position: relative;
  width: min(600px, 100%);
  min-height: 0;
  max-height: min(calc(100dvh - 170px), 760px);
  display: flex;
  flex-direction: column;
  margin-top: 14px;                     /* room for the seal */
  background:
    radial-gradient(120% 60% at 50% 0%, rgba(255, 229, 236, .55), rgba(255, 229, 236, 0) 70%),
    linear-gradient(#FFFDFB, #FFF8F5);
  border-radius: 26px;
  box-shadow: var(--shadow-soft), inset 0 0 0 1px rgba(255, 179, 198, .45);
  transform-origin: 50% 0;             /* it unfolds downward */
}
/* a fine pink inner border, like letter paper */
.letter-paper::before {
  content: "";
  position: absolute;
  inset: 10px;
  border: 1.5px solid rgba(255, 143, 171, .32);
  border-radius: 18px;
  pointer-events: none;
  z-index: 1;
}
.letter-seal {
  position: absolute;
  top: -17px;
  left: 50%;
  translate: -50% 0;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--rouge);
  color: #FFE5EC;
  box-shadow: 0 6px 14px -6px rgba(230, 57, 80, .55), inset 0 0 0 3px rgba(255, 255, 255, .28);
  z-index: 2;
}
.letter-seal svg { width: 18px; height: auto; display: block; }

.letter-scroll {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  border-radius: 26px;
  scrollbar-width: thin;
  scrollbar-color: var(--pastel) transparent;
  /* text softly fades as it scrolls up under the top edge */
  -webkit-mask-image: linear-gradient(transparent 6px, #000 34px);
          mask-image: linear-gradient(transparent 6px, #000 34px);
}
.letter-scroll:focus { outline: none; }
.letter-scroll:focus-visible { box-shadow: inset 0 0 0 3px var(--candy); }
.letter-inner {
  max-width: 34em;
  margin: 0 auto;
  padding: clamp(40px, 6dvh, 54px) clamp(26px, 6vw, 54px) clamp(30px, 5dvh, 44px);
  color: var(--cocoa);
  text-align: left;
}
.letter-greeting {
  margin: 0;
  font: italic 600 clamp(28px, 3.2vw + 16px, 36px)/1.15 var(--font-serif);
  color: var(--cocoa);
}
.letter-rule {
  width: 72px;
  height: 10px;
  margin: 14px 0 22px;
  background:
    radial-gradient(circle, var(--candy) 2.5px, transparent 3px) center / 10px 10px no-repeat,
    linear-gradient(var(--pastel), var(--pastel)) left center / 28px 1.5px no-repeat,
    linear-gradient(var(--pastel), var(--pastel)) right center / 28px 1.5px no-repeat;
}
.letter-p {
  margin: 0 0 1.05em;
  font: 500 clamp(19px, .6vw + 16px, 21px)/1.68 var(--font-serif);
  white-space: pre-line;               /* keeps single line breaks inside a paragraph */
  overflow-wrap: break-word;
  text-wrap: pretty;
}
.letter-sign {
  margin: 1.6em 0 0;
  text-align: right;
  white-space: pre-line;
  font: italic 600 clamp(22px, 1vw + 18px, 26px)/1.3 var(--font-serif);
  color: var(--cocoa);
}

/* while there's more to read: a soft fade and a quiet hint at the bottom */
.letter-more {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 76px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 14px;
  border-radius: 0 0 26px 26px;
  background: linear-gradient(rgba(255, 248, 245, 0), #FFF8F5 70%);
  pointer-events: none;
  opacity: 0;
  transition: opacity .4s ease;
  z-index: 1;
}
.letter-more span {
  font: 700 13px/1 var(--font-sans);
  letter-spacing: .04em;
  color: var(--rouge);
  animation: letter-nudge 1.8s ease-in-out infinite;
}
.letter-more span::after { content: " ↓"; }
.letter-paper.has-more .letter-more { opacity: 1; }
@keyframes letter-nudge { 50% { transform: translateY(3px); } }

@media (max-height: 520px) {
  .letter-paper { max-height: calc(100dvh - 110px); margin-top: 8px; }
  .letter-viewer .label { display: none; }
  .letter-inner { padding: 30px 40px 24px; }
  .letter-greeting { font-size: 26px; }
  .letter-rule { margin: 10px 0 14px; }
  .letter-p { font-size: 18px; line-height: 1.6; }
  .letter-sign { font-size: 21px; }
}

@media (prefers-reduced-motion: reduce) {
  .is-wiggling .present, .present-shadow.is-wiggling { animation: none; }
  .present svg { transition: none; }
  .letter-more span { animation: none; }
}
