/* Chapter 1: the invitation */

/* the scene: a bunny (two layers) with the envelope between them */
@property --sw { syntax: '<number>'; inherits: true; initial-value: 1; }

.inv-scene {
  position: absolute;
  inset: 0;
  --bh: min(46dvh, 95vw, 340px);          /* bunny height */
  --ew: clamp(200px, 64vw, 300px);        /* envelope width once it's resting */
}
.inv-layer, .inv-track, .inv-env-bob { position: absolute; inset: 0; pointer-events: none; }
.inv-track, .inv-bob, .env-holder { will-change: transform; }

.bunny-box {
  position: absolute;
  width: calc(var(--bh) * .75);
  height: var(--bh);
  left: calc(50% - var(--bh) * .375);
  top: calc(50% - var(--bh) * .62);
  transform-origin: 50% 95%;
}
.bunny-box svg { display: block; width: 100%; height: 100%; overflow: visible; }
.bunny-box svg g { transform-box: fill-box; }
.bunny-box #head { transform-origin: 50% 100%; }
.bunny-box #ear-l { transform-origin: 62% 95%; }
.bunny-box #ear-r { transform-origin: 38% 95%; }
.bunny-box #eye-l, .bunny-box #eye-r { transform-origin: 50% 50%; }
.bunny-box #leg-l, .bunny-box #leg-r { transform-origin: 50% 20%; }
.bunny-box #arm-l, .bunny-box #arm-r { transform-origin: 50% 50%; }

.bunny-shadow {
  position: absolute;
  width: calc(var(--bh) * .39);
  height: calc(var(--bh) * .045);
  left: calc(50% - var(--bh) * .195);
  top: calc(50% + var(--bh) * .3025);
  border-radius: 50%;
  background: var(--ground-shadow);
}

/* the bunny's speech bubble, up beside the bunny's right ear */
.hey-bubble {
  position: absolute;
  left: calc(50% + var(--bh) * .1);
  top: calc(50% - var(--bh) * .58);
  transform: translateY(-100%);
}
.hey-inner {
  --line: clamp(3px, calc(var(--bh) * .012), 4px);
  position: relative;
  padding: .5em .95em .55em;
  background: #fff;
  border: var(--line) solid var(--cocoa);
  border-radius: 1.15em;
  font: 800 clamp(13px, calc(var(--bh) * .056), 19px)/1.25 var(--font-sans);  /* scales with the bunny */
  color: var(--cocoa);
  text-align: center;
  white-space: pre;
  transform-origin: 14% 100%;
}
.hey-inner::after {  /* the little tail, pointing down at the bunny */
  content: "";
  position: absolute;
  left: .85em;
  bottom: -.5em;
  width: .7em;
  height: .7em;
  background: #fff;
  border-right: var(--line) solid var(--cocoa);
  border-bottom: var(--line) solid var(--cocoa);
  transform: rotate(45deg) skew(8deg, 8deg);
}

/* the envelope */
.env-holder {
  position: absolute;
  width: var(--ew);
  aspect-ratio: 240 / 168;
  left: calc(50% - var(--ew) / 2);
  top: calc(50% - var(--ew) * .35 - 24px);
  transform-origin: 50% 50%;
}
.env-shadow {
  position: absolute;
  left: 12%; right: 12%;
  bottom: -11%;
  height: 8%;
  border-radius: 50%;
  background: var(--ground-shadow);
}
.envelope {
  position: relative;
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  pointer-events: none;
}
.envelope svg { display: block; width: 100%; height: auto; overflow: visible; transition: transform .35s var(--ease-bounce); }
/* outlines stay as thick as the bunny's while the envelope is small */
.envelope svg [stroke-width="5"]   { stroke-width: calc(5px * var(--sw)); }
.envelope svg [stroke-width="4.5"] { stroke-width: calc(4.5px * var(--sw)); }
.envelope svg [stroke-width="4"]   { stroke-width: calc(4px * var(--sw)); }

.is-live .envelope { pointer-events: auto; animation: env-float 3.4s ease-in-out infinite; }
.is-live .env-shadow { animation: env-shadow 3.4s ease-in-out infinite; }
.is-live .envelope:hover svg { transform: translateY(-5px) rotate(-1.5deg); }
.envelope:focus-visible { outline: 3px solid var(--candy); outline-offset: 10px; border-radius: 18px; }

.envelope-hint {
  position: absolute;
  left: 0; right: 0;
  top: calc(50% + var(--ew) * .35 + 10px);
  margin: 0;
  text-align: center;
  font: 600 var(--text-small)/1 var(--font-sans);
  color: var(--cocoa-soft);
}

@keyframes env-float  { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
@keyframes env-shadow { 0%, 100% { transform: scaleX(1); opacity: 1; } 50% { transform: scaleX(.9); opacity: .75; } }

@media (prefers-reduced-motion: reduce) {
  .is-live .envelope, .is-live .env-shadow { animation: none; }
  .envelope svg { transition: none; }
}

/* the letter */
.letter {
  width: min(440px, calc(100vw - 32px));
  max-height: calc(100dvh - 48px);
  overflow-y: auto;
  padding: clamp(30px, 6vw, 44px) clamp(24px, 6vw, 40px) clamp(28px, 5vw, 36px);
  background: var(--paper);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-soft);
  text-align: center;
}
.letter h1 {
  margin: 0 0 16px;
  font: 600 clamp(36px, 9vw, 44px)/1.05 var(--font-serif);
  color: var(--cocoa);
}
.letter .body { text-align: left; }
.letter .body p { margin: 0 0 1em; }
.letter .sign-off { margin-top: 1.4em; text-align: right; white-space: pre-line; font: italic 500 22px/1.3 var(--font-serif); }
.letter .ready-wrap { margin-top: 26px; }
