Skip to content
VibeCodeBench
Back to the app

The code

Love Letter by GPT-6.2 Sol

Exactly as the AI wrote it. Shown as text, so nothing runs on this page.

index.html

works · auto-checked (Checked by an automated pass. Not hand-played yet.)62.4 KB · 1,375 lines · no libraries
Download
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#fbf2e7">
<title>Love Post</title>
<style>
  :root {
    color-scheme: light;
    --ink: #402522;
    --muted: #76534d;
    --red: #8e2d40;
    --red-deep: #762338;
    --gold: #b7804b;
    --line: #e6d1c0;
    --serif: Georgia, "Times New Roman", serif;
    --sans: system-ui, -apple-system, "Segoe UI", sans-serif;
    --hand: "Segoe Print", "Bradley Hand", "Noteworthy", "Apple Chancery", "Comic Sans MS", cursive;
    --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='144' height='144'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.82' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Cpath d='M0 0h144v144H0z' filter='url(%23n)' opacity='.42'/%3E%3C/svg%3E");
  }

  *, *::before, *::after { box-sizing: border-box; }
  [hidden] { display: none !important; }
  body {
    margin: 0;
    min-width: 0;
    min-height: 100vh;
    color: var(--ink);
    font: 15px/1.45 var(--sans);
    background: radial-gradient(ellipse at 91% 16%, #f6e2d5 0, transparent 53%),
                radial-gradient(ellipse at 4% 96%, #f4e3d0 0, transparent 54%),
                #fbf3e8;
  }
  body::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 8;
    pointer-events: none;
    background: var(--grain);
    opacity: .17;
    mix-blend-mode: multiply;
  }
  button, input, textarea { font: inherit; }
  button { cursor: pointer; touch-action: manipulation; }
  button:disabled { cursor: default; }
  button:focus-visible, .paper-option input:focus-visible + .paper-tile, .paper-letter:focus-visible {
    outline: 2px solid #a64a56;
    outline-offset: 3px;
  }
  svg { display: block; }
  .visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
  }
  .shell { width: min(1192px, calc(100% - 88px)); margin-inline: auto; }
  .topbar {
    min-height: 78px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid var(--line);
  }
  .brand {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--red-deep);
    font: 25px/1 var(--serif);
    letter-spacing: -.045em;
    white-space: nowrap;
  }
  .brand-mark {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    color: #fff0d7;
    background: var(--red);
    border: 1px solid var(--red-deep);
    border-radius: 11px;
    box-shadow: 0 3px 8px #75263b20, inset 0 0 0 2px #ffffff13;
  }
  .header-actions { display: flex; align-items: center; gap: 8px; }
  .sound, .demo-exit, .replay {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-height: 44px;
    padding: 0 13px;
    border: 1px solid #dec4b4;
    border-radius: 999px;
    background: #fff9eea0;
    color: var(--red-deep);
    font-size: 13px;
    font-weight: 650;
    white-space: nowrap;
  }
  .sound[aria-pressed="true"] .muted-mark,
  .sound[aria-pressed="false"] .sound-waves { display: none; }
  .demo-exit { background: transparent; }

  main.shell {
    display: grid;
    grid-template-columns: minmax(0, .86fr) minmax(0, 1.14fr);
    align-items: start;
    gap: clamp(30px, 4.8vw, 73px);
    padding-block: clamp(36px, 5.1vw, 70px) 42px;
  }
  .compose { min-width: 0; }
  h1 {
    margin: 0;
    font: 400 clamp(47px, 5.5vw, 79px)/.99 var(--serif);
    letter-spacing: -.064em;
  }
  h1 em { display: block; color: var(--red); font-weight: 400; }
  .intro {
    max-width: 335px;
    margin: 19px 0 25px;
    color: var(--muted);
    font-size: 15px;
    line-height: 1.6;
  }
  .composer { display: grid; gap: 16px; }
  .names, .papers { display: grid; gap: 12px; }
  .names { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .papers { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .field { min-width: 0; }
  .field > label, legend {
    display: block;
    margin: 0 0 6px;
    color: #5d3832;
    font-size: 13px;
    font-weight: 700;
  }
  input[type="text"], textarea {
    display: block;
    width: 100%;
    border: 1px solid #dcc3b3;
    border-radius: 9px;
    color: var(--ink);
    background: #fffbf4b8;
    font-size: 16px;
    box-shadow: inset 0 1px 2px #66412906;
    transition: border-color .18s, box-shadow .18s;
  }
  input[type="text"] { height: 49px; padding: 0 13px; }
  textarea { min-height: 100px; padding: 11px 13px 28px; resize: vertical; }
  input::placeholder, textarea::placeholder { color: #8e6c60; opacity: 1; }
  input[type="text"]:focus, textarea:focus {
    outline: none;
    border-color: #a14b55;
    box-shadow: 0 0 0 3px #a14b5520;
  }
  [aria-invalid="true"] { border-color: #b14754 !important; }
  .message-box { position: relative; }
  .counter {
    position: absolute;
    right: 13px;
    bottom: 7px;
    color: var(--muted);
    font-size: 11px;
    font-variant-numeric: tabular-nums;
    pointer-events: none;
  }
  fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
  legend { padding: 0; }
  .paper-option { position: relative; display: block; cursor: pointer; touch-action: manipulation; }
  .paper-option input { position: absolute; inset: 0; opacity: 0; margin: 0; pointer-events: none; }
  .paper-tile {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 57px;
    height: 100%;
    padding: 7px 8px;
    border: 1px solid #dfc8b7;
    border-radius: 9px;
    background: #fff9f082;
    color: #60403a;
    font-size: 12px;
    font-weight: 650;
    transition: background-color .18s, border-color .18s, box-shadow .18s;
  }
  .paper-option input:checked + .paper-tile {
    border-color: #a04e5b;
    background: #f8e6df;
    color: var(--red-deep);
    box-shadow: inset 0 0 0 1px #a04e5b30;
  }
  .swatch {
    flex: none;
    width: clamp(28px, 2.8vw, 36px);
    height: 34px;
    overflow: hidden;
    border-radius: 4px;
    box-shadow: 0 1px 2px #4a242321;
  }
  .swatch svg { width: 100%; height: 100%; }
  .swatch-rose { background: #edc3c4; color: #984455; }
  .swatch-cream { background: #f6e2ae; color: #91623e; }
  .swatch-moon { background: #673e53; color: #f9d7a5; }
  .paper-check {
    display: grid;
    place-items: center;
    position: absolute;
    top: 4px;
    right: 4px;
    width: 13px;
    height: 13px;
    border-radius: 50%;
    background: var(--red);
    color: #fff6ec;
    opacity: 0;
  }
  .paper-option input:checked + .paper-tile .paper-check { opacity: 1; }
  .send {
    position: relative;
    min-height: 52px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 9px;
    padding: 9px 36px;
    border: 1px solid #802638;
    border-radius: 10px;
    color: #fff6e8;
    background: linear-gradient(180deg, #a43a4d, #8a2a3e);
    box-shadow: inset 0 1px 0 #ffffff24, 0 5px 12px #8a2a3e2c;
    font-size: 15px;
    font-weight: 700;
    transition: background-color .2s, transform .2s, box-shadow .2s;
  }
  .send .send-arrow { position: absolute; right: 15px; }
  .send:active { transform: translateY(1px); box-shadow: 0 2px 4px #8a2a3e24; }
  .form-error { margin: -7px 0 0; color: #8a293a; font-size: 13px; }
  .privacy {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin: 12px 0 0;
    color: var(--muted);
    font-size: 12px;
  }

  .stage {
    --env-base: #f5d2ce;
    --env-light: #ffeee3;
    --env-fold: #e6abaa;
    --env-ink: #a75d63;
    --paper-base: #fff7ec;
    --paper-tint: #fae3da;
    --paper-ink: #5e3036;
    --paper-sign: #8d3548;
    --paper-rule: #cb9092;
    --art-wash: #f3ccca;
    --art-hill: #df9a9d;
    --art-floor: #eab9b6;
    --art-edge: #b9767d;
    scroll-margin-block: 12px;
    min-width: 0;
    padding: 15px 17px 13px;
    border: 1px solid #e1c5b3;
    border-radius: 20px;
    background: linear-gradient(155deg, #fff7eb, #f9e8db);
    box-shadow: 0 16px 42px #6f42331a, inset 0 1px 0 #fffcf4;
  }
  .stage[data-paper="cream"] {
    --env-base: #f2daaa;
    --env-light: #fff0c9;
    --env-fold: #e3bc82;
    --env-ink: #9b6a45;
    --paper-base: #fff7df;
    --paper-tint: #f5e3b9;
    --paper-ink: #593825;
    --paper-sign: #854b34;
    --paper-rule: #b9915a;
    --art-wash: #f1d7a6;
    --art-hill: #dcae76;
    --art-floor: #efc595;
    --art-edge: #b8835d;
  }
  .stage[data-paper="moonlight"] {
    --env-base: #744957;
    --env-light: #996378;
    --env-fold: #5c354b;
    --env-ink: #e1b58d;
    --paper-base: #704457;
    --paper-tint: #512e43;
    --paper-ink: #fff2db;
    --paper-sign: #ffd3a7;
    --paper-rule: #ba8b82;
    --art-wash: #926172;
    --art-hill: #a66c7f;
    --art-floor: #ad7784;
    --art-edge: #e0ac98;
  }
  .stage-head {
    min-height: 44px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin: 0 2px 11px;
  }
  .stage-head h2 {
    margin: 0;
    color: #63352f;
    font: 400 26px/1 var(--serif);
    letter-spacing: -.04em;
  }
  .replay { color: #763444; background: #fff9f0a8; }
  .scene {
    display: grid;
    place-items: center;
    position: relative;
    overflow: hidden;
    isolation: isolate;
    border: 1px solid #d1a395;
    border-radius: 12px;
    background: #e9b7ac;
  }
  .scene::before {
    content: "";
    grid-area: 1 / 1;
    width: 100%;
    aspect-ratio: 600 / 498;
  }
  .scene::after {
    content: "";
    position: absolute;
    inset: 8px;
    z-index: 1;
    border: 1px solid #fff4dda1;
    border-radius: 7px;
    pointer-events: none;
  }
  .landscape, .scene-shade {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
  }
  .scene-shade {
    opacity: 0;
    background: #6f374637;
    transition: opacity .6s;
    pointer-events: none;
  }
  .stage[data-phase="opening"] .scene-shade,
  .stage[data-phase="open"] .scene-shade { opacity: 1; }
  .stage-status {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    min-height: 36px;
    margin: 0;
    padding: 11px 5px 0;
    text-align: center;
    color: #704a43;
    font-size: 13px;
    line-height: 1.35;
    overflow-wrap: anywhere;
  }
  .stage-status svg { flex: none; color: #a34c58; }

  .courier-run { transform-origin: 0 0; }
  .courier-bob, .courier-tail, .paws-a, .paws-b, .firefly {
    transform-box: fill-box;
    transform-origin: center;
  }
  .courier-tail { transform-origin: 14% 70%; animation: tail-sway 3.6s ease-in-out infinite alternate; }
  .stage[data-phase="ready"] .courier-bob { animation: breathe 3.5s ease-in-out infinite; }
  .firefly { animation: twinkle 4.8s ease-in-out infinite; }
  .firefly-late { animation-delay: -2.4s; }
  .stage[data-phase="delivering"] .courier-run { animation: walk-across 3.7s linear both; }
  .stage[data-phase="delivering"] .courier-bob { animation: stride .35s ease-in-out infinite alternate; }
  .stage[data-phase="delivering"] .paws-a,
  .stage[data-phase="delivering"] .paws-b { transform-origin: center top; animation: paws .43s ease-in-out infinite alternate; }
  .stage[data-phase="delivering"] .paws-b { animation-direction: alternate-reverse; }
  .stage[data-phase="delivering"] .carried-envelope { animation: hand-off 3.7s linear both; }
  .stage[data-phase="arrived"] .courier-run,
  .stage[data-phase="opening"] .courier-run,
  .stage[data-phase="open"] .courier-run { visibility: hidden; }
  @keyframes tail-sway { from { transform: rotate(-3deg); } to { transform: rotate(6deg); } }
  @keyframes breathe { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }
  @keyframes twinkle { 0%, 100% { opacity: .58; } 50% { opacity: 1; } }
  @keyframes stride { from { transform: translateY(1px) rotate(1deg); } to { transform: translateY(-6px) rotate(-2deg); } }
  @keyframes paws { from { transform: rotate(-14deg); } to { transform: translateY(-4px) rotate(14deg); } }
  @keyframes walk-across {
    0% { transform: translate(-357px, 102px) scale(.68); opacity: 1; }
    52% { transform: translate(41px, 102px) scale(.68); }
    60% { transform: translate(51px, 114px) scale(.68, .64); }
    68% { transform: translate(56px, 102px) scale(.68); }
    100% { transform: translate(510px, 102px) scale(.68); opacity: 1; }
  }
  @keyframes hand-off { 0%, 58% { opacity: 1; } 63%, 100% { opacity: 0; } }

  .mail-button {
    display: grid;
    justify-items: center;
    position: absolute;
    z-index: 2;
    left: 50%;
    top: 54%;
    width: min(62%, 329px);
    padding: 0;
    border: 0;
    border-radius: 13px;
    color: var(--red-deep);
    background: transparent;
    transform: translate(-50%, -50%);
    opacity: 0;
    visibility: hidden;
  }
  .mail-face { width: 100%; height: auto; overflow: visible; filter: drop-shadow(0 13px 11px #68313a50); }
  .mail-flap { transform-box: fill-box; transform-origin: center top; }
  .mail-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-height: 44px;
    margin-top: 4px;
    padding: 0 16px;
    border: 1px solid #ffeddf;
    border-radius: 999px;
    background: #fff4e6;
    box-shadow: 0 4px 11px #66313935;
    font-size: 13px;
    font-weight: 750;
    opacity: 0;
  }
  .stage[data-phase="delivering"] .mail-button {
    visibility: visible;
    animation: mail-drop .8s 2.18s cubic-bezier(.23,.83,.33,1) both;
  }
  .stage[data-phase="arrived"] .mail-button,
  .stage[data-phase="opening"] .mail-button { visibility: visible; opacity: 1; }
  .stage[data-phase="arrived"] .mail-action { opacity: 1; animation: action-in .25s ease-out both; }
  .stage[data-phase="opening"] .mail-button { animation: mail-away .88s ease both; pointer-events: none; }
  .stage[data-phase="opening"] .mail-flap { animation: flap .62s cubic-bezier(.22,.72,.25,1) both; }
  @keyframes mail-drop {
    0% { opacity: 0; transform: translate(-51%, -5%) rotate(-15deg) scale(.28); }
    18% { opacity: 1; }
    72% { transform: translate(-50%, -57%) rotate(2deg) scale(1.035); }
    100% { opacity: 1; transform: translate(-50%, -50%) rotate(0) scale(1); }
  }
  @keyframes action-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
  @keyframes flap { 0% { transform: scaleY(1); } 75%, 100% { transform: scaleY(-.9); } }
  @keyframes mail-away {
    0%, 40% { opacity: 1; transform: translate(-50%, -50%); }
    100% { opacity: 0; transform: translate(-50%, 9%) scale(.87); }
  }

  .paper-letter {
    grid-area: 1 / 1;
    position: relative;
    z-index: 3;
    width: min(87%, 475px);
    margin: 22px 0;
    padding: 15px clamp(15px, 2.95vw, 34px) 20px;
    border: 1px solid var(--paper-rule);
    border-radius: 5px 5px 9px 5px;
    background: radial-gradient(ellipse at 50% 2%, var(--paper-base) 27%, var(--paper-tint));
    color: var(--paper-ink);
    box-shadow: 0 2px 0 var(--paper-rule), 0 5px 0 var(--paper-tint), 0 6px 0 var(--paper-rule), 0 15px 30px #53253555;
    transform-origin: 50% 88%;
    animation: lift-paper .72s cubic-bezier(.16,1,.35,1) both;
  }
  .paper-letter::before {
    content: "";
    position: absolute;
    inset: 6px;
    border: 1px solid var(--paper-rule);
    border-radius: 2px 2px 5px 2px;
    opacity: .63;
    pointer-events: none;
  }
  .stage[data-paper="cream"] .paper-letter::before { border-style: double; border-width: 3px; }
  .stage[data-paper="moonlight"] .paper-letter::before { border-style: dashed; }
  .popup-art { width: 100%; height: auto; overflow: visible; }
  .popup-art .fold {
    transform-box: fill-box;
    transform-origin: center bottom;
    animation: unfold .63s cubic-bezier(.19,1,.32,1) both;
  }
  .popup-art .fold-sky { animation-delay: .18s; }
  .popup-art .fold-plants { animation-delay: .3s; }
  .popup-art .fold-cats { animation-delay: .42s; }
  .popup-art .fold-hearts { animation-delay: .55s; }
  .letter-copy { position: relative; padding-inline: 3px; }
  .salutation, .letter-message, .signature {
    font: 500 clamp(14px, 1.66vw, 17px)/1.57 var(--hand);
    overflow-wrap: anywhere;
  }
  .salutation { margin: 2px 0 5px; font-weight: 700; }
  .letter-message { display: grid; margin: 0; }
  .letter-message .measure, .letter-message .typed {
    grid-area: 1 / 1;
    min-width: 0;
    white-space: pre-wrap;
  }
  .letter-message .measure { visibility: hidden; }
  .paper-letter.typing .typed::after {
    content: "";
    display: inline-block;
    width: 1.5px;
    height: .95em;
    margin-left: 2px;
    vertical-align: -.11em;
    background: var(--paper-sign);
    animation: blink .7s steps(2, start) infinite;
  }
  .signature {
    margin: 8px 0 0;
    color: var(--paper-sign);
    font-weight: 700;
    opacity: 0;
    transition: opacity .25s;
  }
  .paper-letter.signed .signature { opacity: 1; }
  @keyframes blink { to { visibility: hidden; } }
  @keyframes lift-paper {
    0% { opacity: 0; transform: perspective(610px) translateY(53px) rotateX(-43deg) scale(.65); }
    45% { opacity: 1; }
    100% { opacity: 1; transform: perspective(610px) translateY(0) rotateX(0) scale(1); }
  }
  @keyframes unfold {
    0% { opacity: 0; transform: scale(.92,.025) skewX(-10deg); }
    63% { opacity: 1; transform: scale(1,1.06); }
    100% { opacity: 1; transform: scale(1,1); }
  }

  @media (hover: hover) {
    .sound:hover, .replay:hover, .demo-exit:hover { background: #fffaf1; border-color: #b8817d; }
    .paper-option:hover .paper-tile { border-color: #b9827d; }
    .send:hover { box-shadow: inset 0 1px 0 #ffffff31, 0 7px 15px #8a2a3e40; }
    .mail-button:hover:not(:disabled) .mail-action { background: #fff9f1; }
  }
  @media (max-width: 1050px) {
    .shell { width: calc(100% - 60px); }
    main.shell { grid-template-columns: minmax(0, .97fr) minmax(0, 1.03fr); gap: 30px; }
  }
  @media (max-width: 790px) {
    .shell { width: min(600px, calc(100% - 34px)); }
    .topbar { min-height: 65px; }
    main.shell { grid-template-columns: minmax(0, 1fr); gap: 28px; padding-block: 30px 28px; }
    h1 { font-size: clamp(44px, 10.6vw, 67px); }
    .intro { margin-top: 14px; margin-bottom: 19px; }
    .composer { gap: 13px; }
    .paper-letter { padding-inline: clamp(13px, 4.2vw, 30px); }
    .salutation, .letter-message, .signature { font-size: clamp(14px, 3.7vw, 17px); }
  }
  @media (max-width: 440px) {
    .brand { font-size: 23px; gap: 8px; }
    .brand-mark { width: 33px; height: 33px; }
    .sound, .demo-exit, .replay { padding-inline: 10px; font-size: 12px; }
    .header-actions { gap: 5px; }
    .names { gap: 8px; }
    .paper-tile { min-height: 63px; padding: 6px 3px 5px; gap: 3px; justify-content: center; flex-direction: column; }
    .swatch { width: 33px; height: 26px; }
    .stage { padding: 10px 10px 12px; border-radius: 15px; }
    .stage-head { margin-bottom: 8px; }
    .stage-head h2 { font-size: 23px; }
    .scene::after { inset: 5px; }
    .paper-letter { width: 88%; margin-block: 17px; padding-top: 11px; padding-bottom: 15px; }
  }
  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .001ms !important; animation-delay: 0ms !important; transition-duration: .001ms !important; }
    .stage[data-phase="delivering"] .mail-button { visibility: hidden; }
  }
</style>
</head>
<body>
<header class="topbar shell">
  <div class="brand">
    <span class="brand-mark" aria-hidden="true">
      <svg width="23" height="23" viewBox="0 0 24 24" fill="none">
        <rect x="3" y="6" width="18" height="13" rx="2" stroke="currentColor" stroke-width="1.35"/>
        <path d="m4 7 7 5.1q1 .7 2 0L20 7M4 17l4.5-4m11.5 4-4.5-4" stroke="currentColor" stroke-width="1.2" stroke-linecap="round"/>
        <path d="M12 15.7c-1-.7-3.4-2-3.4-3.6 0-1.5 2-2 3.4-.4 1.4-1.6 3.4-1.1 3.4.4 0 1.6-2.4 2.9-3.4 3.6Z" fill="#f2bd82"/>
      </svg>
    </span>
    <span>Love Post</span>
  </div>
  <div class="header-actions">
    <button class="demo-exit" id="demo-exit" type="button" hidden>Exit demo</button>
    <button class="sound" id="sound" type="button" aria-pressed="true" aria-label="Sound">
      <svg width="17" height="17" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.65" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
        <path d="M3 9h4l5-4v14l-5-4H3z"/>
        <path class="sound-waves" d="M15.6 9a4.5 4.5 0 0 1 0 6M18 6.5a8 8 0 0 1 0 11"/>
        <path class="muted-mark" d="m16 10 5 5m0-5-5 5"/>
      </svg>
      <span id="sound-label">Sound on</span>
    </button>
  </div>
</header>

<main class="shell">
  <section class="compose" aria-labelledby="title">
    <h1 id="title">A little letter.<em>A lot of love.</em></h1>
    <p class="intro">Write a note for someone special. Our cat postman will take it from here.</p>

    <form class="composer" id="composer" novalidate autocomplete="off">
      <div class="names">
        <div class="field">
          <label for="from">From</label>
          <input id="from" name="from" type="text" maxlength="36" placeholder="Your name" required>
        </div>
        <div class="field">
          <label for="to">To</label>
          <input id="to" name="to" type="text" maxlength="36" placeholder="Their name" required>
        </div>
      </div>
      <div class="field">
        <label for="message">Your message</label>
        <div class="message-box">
          <textarea id="message" name="message" rows="2" maxlength="240" placeholder="I’ve been meaning to tell you…" required></textarea>
          <span class="counter" id="counter" aria-hidden="true">0 / 240</span>
        </div>
      </div>

      <fieldset>
        <legend>Paper style</legend>
        <div class="papers">
          <label class="paper-option">
            <input type="radio" name="paper" value="rose" checked>
            <span class="paper-tile">
              <span class="swatch swatch-rose" aria-hidden="true">
                <svg viewBox="0 0 38 34" fill="none">
                  <rect x="3" y="3" width="32" height="28" rx="2" stroke="currentColor" opacity=".46"/>
                  <path d="M18 26c4-4 5-9 4-14m-1 8c-4 1-7-1-8-4 4-1 6 1 8 4Zm0 2c2-4 5-5 8-4-2 3-5 4-8 4Z" stroke="currentColor" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round"/>
                  <path d="M22 14c-3-1-5-3-5-5s3-3 5 0c2-3 5-2 5 0s-2 4-5 5Z" fill="currentColor"/>
                </svg>
              </span>
              <span>Rose</span>
              <span class="paper-check" aria-hidden="true"><svg width="9" height="9" viewBox="0 0 12 12"><path d="m2.5 6 2.2 2.2 4.8-4.8" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"/></svg></span>
            </span>
          </label>
          <label class="paper-option">
            <input type="radio" name="paper" value="cream">
            <span class="paper-tile">
              <span class="swatch swatch-cream" aria-hidden="true">
                <svg viewBox="0 0 38 34" fill="none" stroke="currentColor" stroke-width="1">
                  <rect x="3" y="3" width="32" height="28" rx="2" opacity=".57"/>
                  <path d="M8 8h4M8 8v4m22-4h-4m4 0v4M8 26h4m-4 0v-4m22 4h-4m4 0v-4" stroke-linecap="round" opacity=".72"/>
                  <path d="M19 8q1.2 7.8 8 9-6.8 1.2-8 9-1.2-7.8-8-9 6.8-1.2 8-9Z" fill="currentColor" stroke="none"/>
                </svg>
              </span>
              <span>Cream</span>
              <span class="paper-check" aria-hidden="true"><svg width="9" height="9" viewBox="0 0 12 12"><path d="m2.5 6 2.2 2.2 4.8-4.8" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"/></svg></span>
            </span>
          </label>
          <label class="paper-option">
            <input type="radio" name="paper" value="moonlight">
            <span class="paper-tile">
              <span class="swatch swatch-moon" aria-hidden="true">
                <svg viewBox="0 0 38 34" fill="currentColor">
                  <rect x="3" y="3" width="32" height="28" rx="2" stroke="currentColor" fill="none" opacity=".63"/>
                  <path d="M20 8c-6 1-9 7-6 12 2 4 8 5 12 1-6 1-11-6-6-13Z"/>
                  <path d="M27 9q.4 2.6 3 3-2.6.4-3 3-.4-2.6-3-3 2.6-.4 3-3ZM10 17q.3 1.7 2 2-1.7.3-2 2-.3-1.7-2-2 1.7-.3 2-2Z"/>
                </svg>
              </span>
              <span>Moonlight</span>
              <span class="paper-check" aria-hidden="true"><svg width="9" height="9" viewBox="0 0 12 12"><path d="m2.5 6 2.2 2.2 4.8-4.8" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"/></svg></span>
            </span>
          </label>
        </div>
      </fieldset>

      <p class="form-error" id="form-error" role="alert" hidden></p>
      <button class="send" id="send" type="submit">
        <svg width="19" height="19" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.55" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m21 3-6.7 18-3.7-7.6L3 9.7 21 3Zm0 0L10.6 13.4"/></svg>
        Send letter
        <svg class="send-arrow" width="14" height="14" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2.5 8h10m-4-4 4 4-4 4"/></svg>
      </button>
    </form>
    <p class="privacy">
      <svg width="12" height="13" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.25" aria-hidden="true"><rect x="3.5" y="6.5" width="9" height="7" rx="1.4"/><path d="M5.5 6.5V5a2.5 2.5 0 0 1 5 0v1.5m-2.5 3v1.6" stroke-linecap="round"/></svg>
      Your letter stays in this tab.
    </p>
  </section>

  <section class="stage" id="stage" data-phase="ready" data-paper="rose" aria-labelledby="delivery-title">
    <div class="stage-head">
      <h2 id="delivery-title">The delivery</h2>
      <button class="replay" id="replay" type="button" aria-label="Replay delivery" hidden>
        <svg width="15" height="15" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.55" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3.5 8a6.8 6.8 0 1 1 .7 6.1M3.5 4v4.4h4.4"/></svg>
        Replay
      </button>
    </div>
    <div class="scene" id="scene">
      <svg class="landscape" viewBox="0 0 600 498" preserveAspectRatio="xMidYMid slice" role="img" aria-label="A cat postman in a blue cap and a rosy moonlit meadow">
        <defs>
          <linearGradient id="sky" x1="0" x2="0" y1="0" y2="1">
            <stop stop-color="#f6e5d6"/>
            <stop offset=".57" stop-color="#f1cbb9"/>
            <stop offset="1" stop-color="#e8afaa"/>
          </linearGradient>
          <radialGradient id="moon-halo">
            <stop offset=".38" stop-color="#fff5d9" stop-opacity=".94"/>
            <stop offset="1" stop-color="#fff0d3" stop-opacity="0"/>
          </radialGradient>
          <linearGradient id="moon-disc" x2=".65" y2="1">
            <stop stop-color="#fff8e3"/><stop offset="1" stop-color="#f7dca9"/>
          </linearGradient>
          <linearGradient id="grass" x1="0" x2=".28" y1="0" y2="1">
            <stop stop-color="#c9807a"/><stop offset="1" stop-color="#a85462"/>
          </linearGradient>
          <linearGradient id="trail" x1="0" x2="0" y1="0" y2="1">
            <stop stop-color="#e7aea1"/><stop offset="1" stop-color="#f1c8a4"/>
          </linearGradient>
          <linearGradient id="fur" x2=".7" y2="1">
            <stop stop-color="#f5d3a2"/><stop offset=".55" stop-color="#e6a976"/><stop offset="1" stop-color="#c87858"/>
          </linearGradient>
          <linearGradient id="wool" x2=".9" y2="1">
            <stop stop-color="#789fb4"/><stop offset=".55" stop-color="#4e7892"/><stop offset="1" stop-color="#34556e"/>
          </linearGradient>
          <linearGradient id="cap" x2=".7" y2="1">
            <stop stop-color="#6e9bb6"/><stop offset="1" stop-color="#3b627d"/>
          </linearGradient>
          <linearGradient id="leather" x2=".75" y2="1">
            <stop stop-color="#d29362"/><stop offset="1" stop-color="#a65c4c"/>
          </linearGradient>
          <g id="sky-spark">
            <path d="M0-10Q1.2-1.2 8 0 1.2 1.2 0 10-1.2 1.2-8 0-1.2-1.2 0-10Z"/>
          </g>
          <g id="meadow-sprig" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round">
            <path d="M0 0c6-30 1-64-10-87" stroke-width="2.6"/>
            <path d="M3-27C-17-30-23-42-20-50-6-46 0-39 3-27ZM2-42C17-48 22-61 20-69 8-66 4-54 2-42ZM-3-61C-20-63-25-73-26-81c13 1 20 10 23 20Z" fill="currentColor" stroke-width="1"/>
            <path d="M-10-85c-10-7-11-17-7-23 10 5 12 15 7 23Z" fill="currentColor" stroke-width="1"/>
          </g>
          <g id="meadow-bloom">
            <path d="M0 0c-5-5-16-4-17-11-1-5 5-10 12-5-2-10 7-13 11-8 2 2 3 5 2 8 8-4 14 2 11 7-3 5-11 5-19 9Z" fill="currentColor"/>
            <circle cx="1" cy="-11" r="3.2" fill="#f7d8a5"/>
          </g>
        </defs>

        <path d="M0 0h600v498H0z" fill="url(#sky)"/>
        <circle cx="466" cy="112" r="116" fill="url(#moon-halo)"/>
        <circle cx="466" cy="112" r="49" fill="url(#moon-disc)" stroke="#fff4da" stroke-width="1.3"/>
        <circle cx="466" cy="112" r="61" stroke="#fff2d8" stroke-width="1" stroke-dasharray="1 5" fill="none"/>
        <path d="M437 105c7-9 16-11 24-6m13-23c9 2 14 6 17 10m-33 47c6 5 12 7 20 5m10-27 5 2" fill="none" stroke="#ddb584" stroke-width="1.5" opacity=".45" stroke-linecap="round"/>
        <g fill="#eabf97" opacity=".44">
          <circle cx="452" cy="91" r="4"/><circle cx="484" cy="121" r="5"/><circle cx="448" cy="129" r="2.4"/><circle cx="473" cy="107" r="2.8"/>
        </g>
        <g fill="#ffebc6">
          <use href="#sky-spark" transform="translate(362 90) scale(.75)" class="firefly"/>
          <use href="#sky-spark" transform="translate(528 164) scale(.85)" class="firefly firefly-late"/>
          <use href="#sky-spark" transform="translate(82 132) scale(1.15)" class="firefly"/>
          <use href="#sky-spark" transform="translate(136 83) scale(.55)"/>
          <use href="#sky-spark" transform="translate(395 168) scale(.51)"/>
          <use href="#sky-spark" transform="translate(544 71) scale(.57)"/>
          <circle cx="338" cy="57" r="2.4"/><circle cx="110" cy="180" r="2"/><circle cx="555" cy="127" r="2.5"/>
          <circle cx="391" cy="121" r="2"/><circle cx="190" cy="107" r="2"/><circle cx="49" cy="85" r="2.7"/>
          <circle cx="317" cy="127" r="2.5"/><circle cx="568" cy="200" r="2.4"/>
        </g>
        <g fill="#fff2df" opacity=".54">
          <path d="M-13 191q27-13 55-7 24-20 56-8 21 1 38 16-77 8-149-1Z"/>
          <path d="M335 206q29-23 70-17 26-17 62-3 34-17 61 12 41-6 73 12-112 12-266-4Z"/>
          <path d="M27 220q36-13 64 2-42 5-64-2Z"/>
        </g>
        <path d="M0 294c67-22 104-39 169-22 63 16 107-23 166-30 69-8 124 34 177 19 32-9 62-11 88-6v109H0Z" fill="#dda19a"/>
        <path d="M0 316c86-34 145-22 212-4 45 12 98 1 153-17 84-27 168-39 235-14v97H0Z" fill="#d08a88"/>
        <path d="M0 352c70-28 134-37 216-17 66 16 126 17 197-9 81-30 141-25 187-16v188H0Z" fill="url(#grass)"/>
        <path d="M-21 464c77-23 125-60 189-81 97-32 190-10 292-40 17-5 35-13 53-22-19 20-58 38-109 52-75 21-153 34-205 71-24 17-47 35-64 54H-21Z" fill="url(#trail)"/>
        <path d="M-3 466c100-24 137-62 220-78 78-15 143-10 218-36M206 454c49-31 127-48 176-59" fill="none" stroke="#f9d7b7" stroke-width="1.7" stroke-linecap="round" opacity=".58"/>
        <path d="M0 364c52-15 91-16 130-13m270 5c62-21 112-29 151-26" fill="none" stroke="#f0b8aa" stroke-width="1.3" opacity=".68" stroke-linecap="round"/>
        <g fill="none" stroke="#f6c9b3" stroke-width="2" stroke-linecap="round" opacity=".68">
          <path d="m37 375 4-3m42 15 7-3m-36 34 4-3m102 43 8-2m185-16 5-3m162 13 6-4m29-85 7-2m-91 9 4-1m-63 84 6-1m-395 30 8-2"/>
          <path d="M124 338v-4m-2.5 2h5m416 82v-5m-2.5 2.5h5m-57-67v-4m-2 2h4"/>
        </g>

        <g transform="translate(147 91)">
          <g class="courier-run">
            <ellipse cx="151" cy="327" rx="101" ry="15" fill="#783846" opacity=".19"/>
            <ellipse cx="151" cy="326" rx="72" ry="8" fill="#773943" opacity=".14"/>
            <g class="courier-bob" stroke="#684344" stroke-linejoin="round" stroke-linecap="round">
              <g class="courier-tail">
                <path d="M203 270c31 19 69 15 76-12 4-15-8-25-18-19-8 5-2 12-5 18-5 9-25 3-38-5" fill="none" stroke-width="20"/>
                <path d="M203 270c31 19 69 15 76-12 4-15-8-25-18-19-8 5-2 12-5 18-5 9-25 3-38-5" fill="none" stroke="#d98f69" stroke-width="14"/>
                <path d="M270 237q-2 9 9 12" fill="none" stroke="#f4ca9e" stroke-width="6"/>
              </g>
              <g class="paws-a">
                <path d="M96 263q-7 21-8 45c-11 2-19 7-18 14 1 8 33 8 49 1l10-56Z" fill="#486278" stroke-width="3.5"/>
                <path d="M76 320c8-5 24-5 34 0m-22-12-4 7" fill="none" stroke="#91a8ab" stroke-width="1.8"/>
              </g>
              <g class="paws-b">
                <path d="M160 268q5 17 8 41c-10 5-11 13-3 16 12 5 42 4 48-2 4-5 1-13-9-15l-9-48Z" fill="#52728a" stroke-width="3.5"/>
                <path d="M168 320c9-4 26-5 36 0m-4-11 4 6" fill="none" stroke="#a0b4b3" stroke-width="1.8"/>
              </g>
              <path d="M111 178c-18 9-31 25-34 48l-5 36c6 12 16 15 32 9l6-13-2 30c26 12 65 13 98-1l-2-34q9 8 20-1c8-7 9-22 3-37-7-20-23-32-42-37Z" fill="url(#wool)" stroke-width="3.6"/>
              <path d="m102 207-8 48m103-49 9 47m-90 34c28 9 57 7 81-3" fill="none" stroke="#a5c2ca" stroke-width="2" opacity=".65"/>
              <path d="m113 181 29 40 39-40c-24 9-47 8-68 0Z" fill="#f4dcac" stroke-width="2.6"/>
              <path d="m114 179 29 39-23-8-13-24Zm66 1-36 38 26-7 20-24Z" fill="#7499aa" stroke-width="2.2"/>
              <path d="M144 222q1 33-4 66" fill="none" stroke="#364c64" stroke-width="2"/>
              <circle cx="152" cy="234" r="3.7" fill="#f3c983" stroke-width="1.1"/>
              <circle cx="152" cy="271" r="3.7" fill="#f3c983" stroke-width="1.1"/>
              <path d="M105 188c28 24 64 46 100 68l-6 10c-42-23-76-45-106-71Z" fill="#aa6550" stroke-width="2.1"/>
              <path d="M100 195c34 27 62 44 99 65" fill="none" stroke="#f1be8a" stroke-width="1.15" stroke-dasharray="2 3"/>
              <path d="M190 245c15-3 46-3 59 3l3 39q-1 10-12 13c-14 4-37 0-49-4-7-3-9-10-8-16Z" fill="url(#leather)" stroke-width="3"/>
              <path d="M186 248c17 0 43 0 65 3l-4 20q-21 14-58 0Z" fill="#d49a70" stroke-width="2.2"/>
              <path d="M191 273q24 11 50 1m-46 17q22 9 44 5" fill="none" stroke="#f2c89b" stroke-width="1.3" stroke-dasharray="3 2.6"/>
              <path d="M214 266h13v16h-13z" fill="#e1b174" stroke-width="1.6"/>
              <path d="M218 270h5v7h-5z" fill="#98534c" stroke-width="1"/>
              <path d="M86 83c-7-15-11-36-8-54 1-7 5-10 12-7 14 6 29 17 40 27 17-4 32-4 47 0 12-11 24-19 38-24 7-3 11 2 11 9 1 17-3 35-7 49 12 12 17 29 16 46-2 34-27 57-75 61-47 4-81-10-94-38-11-24-6-49 20-69Z" fill="url(#fur)" stroke-width="3.8"/>
              <path d="M88 33c-2 11 2 29 7 40l22-15C107 47 98 39 88 33Zm125 5c1 9-2 24-6 36l-19-15c7-8 16-15 25-21Z" fill="#cf827b" stroke-width="2"/>
              <path d="M83 121c7-9 20-10 31-4 13 7 22 14 37 12 13-1 24-10 38-15 15-5 32 0 39 9 2 32-28 59-71 62-44 4-79-11-86-37-3-10 1-20 12-27Z" fill="#f8dfb7" stroke="none"/>
              <path d="M86 102q9-6 17-6m97-4q10 1 18 8m-81-18 4 8m10-11 1 10m9-9-1 7" fill="none" stroke="#ae654e" stroke-width="2.6"/>
              <path d="M83 123q7-2 13-1m102-2q8-2 13 0" fill="none" stroke="#af705c" stroke-width="1.8"/>
              <ellipse cx="103" cy="137" rx="10" ry="6" fill="#e6a298" stroke="none"/>
              <ellipse cx="197" cy="134" rx="11" ry="6" fill="#e6a298" stroke="none"/>
              <ellipse cx="114" cy="114" rx="5.6" ry="7.1" fill="#513338" stroke="none"/>
              <ellipse cx="184" cy="111" rx="5.6" ry="7.1" fill="#513338" stroke="none"/>
              <circle cx="116" cy="111.5" r="1.6" fill="#fff0da" stroke="none"/>
              <circle cx="186" cy="108.5" r="1.6" fill="#fff0da" stroke="none"/>
              <path d="M144 130c3-3 11-4 14-1 3 4-4 9-7 9-4 0-9-5-7-8Z" fill="#a8565f" stroke="none"/>
              <path d="M151 137v5m0 0c-3 5-8 7-13 3m13-3c4 5 9 6 13 1" fill="none" stroke-width="1.9"/>
              <path d="M89 143c-13-5-24-6-34-5m35 12c-12 0-22 3-31 7m148-21c12-7 23-8 34-10m-32 17c11-2 22-2 32 1" fill="none" stroke-width="1.8"/>
              <g transform="rotate(-9 150 71)">
                <path d="M98 66c-2-9 0-22 7-33 8-12 26-17 47-17 23 0 43 8 47 23l1 20Z" fill="url(#cap)" stroke-width="3.25" stroke="#354d66"/>
                <path d="M103 53c16-18 61-23 92-12" fill="none" stroke="#aac4cf" stroke-width="2.2"/>
                <path d="M98 59c28-9 74-12 102-7l1 12c-29-4-74 0-101 8Z" fill="#365c77" stroke="#354d66" stroke-width="2.1"/>
                <path d="M104 69c33-10 72-12 97-9 8 2 13 7 10 12-8 12-64 17-98 10-10-2-15-7-9-13Z" fill="#314e69" stroke="#354d66" stroke-width="2.3"/>
                <path d="M121 73q45-9 79-5" fill="none" stroke="#87acbe" stroke-width="1.9"/>
                <circle cx="150" cy="41" r="13" fill="#efc986" stroke="#73584b" stroke-width="2"/>
                <path d="M150 47c-1.5-1.5-7-4-7-7.4 0-3.6 4.8-4.5 7-1.1 2.3-3.4 7-2.5 7 1.1 0 3.4-5.4 5.9-7 7.4Z" fill="#9b4a55" stroke="none"/>
              </g>
              <g class="carried-envelope">
                <g transform="rotate(-11 141 232)">
                  <rect x="86" y="210" width="106" height="65" rx="6" fill="var(--env-base)" stroke="var(--env-ink)" stroke-width="2.4"/>
                  <path d="m88 270 48-36m54 36-43-35" fill="none" stroke="var(--env-ink)" stroke-width="1.35" opacity=".8"/>
                  <path d="M87 217q0-7 6-7h92q6 0 6 6l-43 31q-6 5-12 0Z" fill="var(--env-light)" stroke="var(--env-ink)" stroke-width="1.7"/>
                  <circle cx="142" cy="245" r="10.5" fill="#a64052" stroke="#823248" stroke-width="1.4"/>
                  <path d="M142 249c-1-1-5-3-5-5s3-3 5-.6c2-2.4 5-1.4 5 .6s-4 4-5 5Z" fill="#f8c6a0" stroke="none"/>
                </g>
              </g>
              <path d="M78 246c-4 8-2 18 7 22 9 4 24 0 29-6 3-6-2-12-8-12-1-5-5-8-10-6Z" fill="#f0c192" stroke-width="2.7"/>
              <path d="M99 254q4 2 5 6m1-8q5 1 7 5" fill="none" stroke="#aa6d57" stroke-width="1.3"/>
              <path d="M214 227c-8-6-15-1-18 5-7 0-12 4-12 10 0 7 12 12 22 10 12-4 16-17 8-25Z" fill="#efc391" stroke-width="2.6"/>
              <path d="M192 237q4 0 7 4m-11 1q5 1 7 4" fill="none" stroke="#aa6d57" stroke-width="1.35"/>
            </g>
          </g>
        </g>

        <g opacity=".96">
          <use href="#meadow-sprig" color="#914c58" transform="translate(36 498) rotate(-14) scale(1.25)"/>
          <use href="#meadow-sprig" color="#b45d69" transform="translate(93 498) rotate(17) scale(.88)"/>
          <use href="#meadow-sprig" color="#e3a18e" transform="translate(68 495) rotate(-13) scale(.67)"/>
          <use href="#meadow-sprig" color="#934b5c" transform="translate(569 499) rotate(22) scale(1.43)"/>
          <use href="#meadow-sprig" color="#a85561" transform="translate(523 497) rotate(-22) scale(.9)"/>
          <use href="#meadow-sprig" color="#df9983" transform="translate(549 495) rotate(6) scale(.93)"/>
          <path d="M53 498c4-39-9-86-26-111m67 111c-3-31 1-58 13-74m433 74c-5-39-24-62-33-72m58 72c4-52 17-82 27-99" fill="none" stroke="#824554" stroke-width="2.1" stroke-linecap="round"/>
          <use href="#meadow-bloom" color="#e5a291" transform="translate(26 392) rotate(-18) scale(.89)"/>
          <use href="#meadow-bloom" color="#efb79e" transform="translate(108 428) rotate(18) scale(.61)"/>
          <use href="#meadow-bloom" color="#edaf9b" transform="translate(506 431) rotate(-24) scale(.71)"/>
          <use href="#meadow-bloom" color="#e7a087" transform="translate(592 403) rotate(7) scale(.9)"/>
          <circle cx="63" cy="404" r="2.7" fill="#f2c9a3"/>
          <circle cx="542" cy="393" r="2.8" fill="#f0c1a0"/>
        </g>
      </svg>
      <div class="scene-shade" aria-hidden="true"></div>

      <button class="mail-button" id="envelope" type="button" aria-label="Open your letter" disabled>
        <svg class="mail-face" viewBox="0 0 320 208" aria-hidden="true">
          <defs>
            <linearGradient id="envelope-paper" x1="0" x2=".6" y1="0" y2="1">
              <stop stop-color="var(--env-light)"/><stop offset="1" stop-color="var(--env-base)"/>
            </linearGradient>
            <linearGradient id="wax" x2=".8" y2="1">
              <stop stop-color="#ba5b64"/><stop offset="1" stop-color="#782539"/>
            </linearGradient>
          </defs>
          <rect x="17" y="21" width="286" height="168" rx="11" fill="var(--env-fold)" stroke="var(--env-ink)" stroke-width="2"/>
          <path d="M18 177 150 84a17 17 0 0 1 20 0l132 93v2a10 10 0 0 1-10 10H28a10 10 0 0 1-10-10Z" fill="var(--env-base)" stroke="var(--env-ink)" stroke-width="1.35"/>
          <path d="M25 170 151 84m144 86L169 84" fill="none" stroke="var(--env-light)" stroke-width="1.4" opacity=".8"/>
          <g fill="none" stroke="var(--env-ink)" opacity=".66" stroke-width="1.35" stroke-linecap="round">
            <path d="M36 164h53m-53 8h36"/>
            <rect x="254" y="143" width="32" height="28" rx="3" stroke-dasharray="2 2.5"/>
            <path d="M261 164c7-2 11-7 13-14m-4 10c-3 0-6-2-6-5 4 0 6 2 6 5Zm1 1c4-5 7-5 9-5-1 4-5 6-9 5Z"/>
          </g>
          <g class="mail-flap">
            <path d="M18 30q0-9 10-9h264q10 0 10 9l-127 94q-15 11-30 0Z" fill="url(#envelope-paper)" stroke="var(--env-ink)" stroke-width="1.65" stroke-linejoin="round"/>
            <path d="m28 32 122 84q10 7 20 0l122-84" stroke="var(--env-ink)" stroke-width="1" opacity=".51" stroke-dasharray="2 4" fill="none" stroke-linecap="round"/>
            <path d="M160 100c8-2 14 1 20 7 5 5 7 12 5 19-2 7-6 13-14 16-6 3-14 3-22 0-8-3-12-7-14-15-3-7 0-14 4-19 6-6 12-9 21-8Z" fill="url(#wax)" stroke="#81354b" stroke-width="1.75"/>
            <circle cx="160" cy="122" r="17.5" fill="none" stroke="#e29086" stroke-width="1.2" opacity=".8"/>
            <path d="M160 132c-2-2-11-7-11-12 0-5.5 7-7.2 11-1.8 4-5.4 11-3.7 11 1.8 0 5-9 10-11 12Z" fill="#f3ba9e"/>
          </g>
        </svg>
        <span class="mail-action">
          Open letter
          <svg width="12" height="12" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3 8h9M8.5 4.5 12 8l-3.5 3.5"/></svg>
        </span>
      </button>

      <article class="paper-letter" id="letter" tabindex="-1" aria-labelledby="salutation" hidden>
        <svg class="popup-art" viewBox="0 0 460 175" role="img" aria-label="Hearts and flowers frame two cats sitting together under a crescent moon">
          <defs>
            <linearGradient id="diorama-sky" x1="0" x2="0" y1="0" y2="1">
              <stop stop-color="var(--art-wash)"/><stop offset="1" stop-color="var(--art-hill)"/>
            </linearGradient>
            <linearGradient id="diorama-moon" x2=".65" y2="1">
              <stop stop-color="#fff2cb"/><stop offset="1" stop-color="#eeb979"/>
            </linearGradient>
            <linearGradient id="diorama-cat-gold" x2=".9" y2="1">
              <stop stop-color="#f5d4a2"/><stop offset="1" stop-color="#dc9677"/>
            </linearGradient>
            <linearGradient id="diorama-cat-rose" x2=".9" y2="1">
              <stop stop-color="#fff0d2"/><stop offset="1" stop-color="#eab6a3"/>
            </linearGradient>
            <path id="diorama-heart" d="M0 6C-2 4-8 0-8-4c0-4 5-5 8-1 3-4 8-3 8 1 0 4-6 8-8 10Z"/>
            <path id="diorama-star" d="M0-7Q1-1 6 0 1 1 0 7-1 1-6 0-1-1 0-7Z"/>
            <g id="diorama-flower">
              <g fill="currentColor" stroke="#945565" stroke-width=".75">
                <ellipse cx="0" cy="-5" rx="4.8" ry="7.6"/>
                <ellipse cx="0" cy="-5" rx="4.8" ry="7.6" transform="rotate(72)"/>
                <ellipse cx="0" cy="-5" rx="4.8" ry="7.6" transform="rotate(144)"/>
                <ellipse cx="0" cy="-5" rx="4.8" ry="7.6" transform="rotate(216)"/>
                <ellipse cx="0" cy="-5" rx="4.8" ry="7.6" transform="rotate(288)"/>
              </g>
              <circle r="3.6" fill="#f8d38f" stroke="#b87964" stroke-width=".7"/>
            </g>
          </defs>
          <g class="fold fold-sky">
            <path d="M65 136C78 114 99 98 132 97c5-26 21-44 46-51 9-22 27-35 51-35s43 14 52 35c24 6 43 24 49 50 32 1 55 16 65 40Z" fill="url(#diorama-sky)" stroke="var(--art-edge)" stroke-width="1.2"/>
            <path d="M72 129c28-23 60-17 90-10 48 13 68 6 105-9 33-13 76-13 120 19l7 12H66Z" fill="var(--art-hill)" opacity=".65"/>
            <path d="M239 22c-12 3-19 15-15 26 4 11 15 17 26 13-6 7-17 9-25 6-13-5-19-18-15-30 4-11 16-17 29-15Z" fill="#925467" opacity=".17" transform="translate(2 3)"/>
            <path d="M239 22c-12 3-19 15-15 26 4 11 15 17 26 13-6 7-17 9-25 6-13-5-19-18-15-30 4-11 16-17 29-15Z" fill="url(#diorama-moon)" stroke="#faf0d1" stroke-width="1"/>
            <g fill="#ffebc3">
              <use href="#diorama-star" transform="translate(187 57) scale(.85)"/>
              <use href="#diorama-star" transform="translate(266 42) scale(.96)"/>
              <use href="#diorama-star" transform="translate(298 68) scale(.63)"/>
              <use href="#diorama-star" transform="translate(157 94) scale(.62)"/>
              <use href="#diorama-star" transform="translate(316 103) scale(.55)"/>
              <circle cx="198" cy="32" r="1.7"/><circle cx="278" cy="70" r="1.9"/><circle cx="252" cy="33" r="1.7"/><circle cx="171" cy="73" r="1.6"/>
            </g>
          </g>
          <path d="M59 140c58-14 112-18 171-18s113 4 171 18l-30 21c-87 14-195 14-282 0Z" fill="var(--art-floor)" stroke="var(--art-edge)" stroke-width="1.15"/>
          <path d="M59 140c56 11 107 13 170 13 62 0 125-5 172-13l-30 21c-87 14-195 14-282 0Z" fill="var(--art-hill)" opacity=".6"/>
          <path d="M88 155q145 23 284 0" fill="none" stroke="var(--paper-base)" opacity=".53" stroke-dasharray="2 3.5"/>
          <g class="fold fold-plants" stroke="#9b626b" stroke-linecap="round" stroke-linejoin="round">
            <path d="M112 144c3-21 0-33-10-49m20 47c5-25 10-32 23-44m-43 45c-3-12-9-20-18-22m263 24c-1-18 4-34 14-49m-24 50c-5-19-12-24-22-29m42 30c3-11 9-18 22-24" fill="none" stroke-width="2.2"/>
            <g fill="#b16f78" stroke-width="1">
              <path d="M113 123c-12 0-19-6-20-12 12 0 17 4 20 12Zm2 7c12 0 18-6 20-11-10-1-17 4-20 11Zm-12 10c-10-2-14-6-15-12 9 0 13 5 15 12Zm243-4c-11-4-17-11-15-17 10 3 14 8 15 17Zm2-13c2-7 10-12 16-11-1 7-6 11-16 11Zm13 15c3-7 7-9 15-9-2 6-7 9-15 9Z"/>
            </g>
            <use href="#diorama-flower" color="#e1979c" transform="translate(102 96) scale(1.14)"/>
            <use href="#diorama-flower" color="#ebaf83" transform="translate(145 99) scale(.75)"/>
            <use href="#diorama-flower" color="#ecc49c" transform="translate(84 121) scale(.65)"/>
            <use href="#diorama-flower" color="#e5a19d" transform="translate(361 95) scale(1.14)"/>
            <use href="#diorama-flower" color="#eaae88" transform="translate(315 116) scale(.66)"/>
            <use href="#diorama-flower" color="#ebc298" transform="translate(379 121) scale(.71)"/>
          </g>
          <g class="fold fold-cats" stroke="#75494c" stroke-width="2.05" stroke-linecap="round" stroke-linejoin="round">
            <ellipse cx="231" cy="146" rx="77" ry="9" fill="#905061" opacity=".23" stroke="none"/>
            <path d="M185 131c-13 14-28 15-33 7-4-5 2-11 7-8" fill="none" stroke="#75494c" stroke-width="9"/>
            <path d="M185 131c-13 14-28 15-33 7-4-5 2-11 7-8" fill="none" stroke="#d89b7b" stroke-width="5.5"/>
            <path d="M274 133c14 15 29 14 34 6 3-6-2-10-8-8" fill="none" stroke="#75494c" stroke-width="9"/>
            <path d="M274 133c14 15 29 14 34 6 3-6-2-10-8-8" fill="none" stroke="#e8b5a1" stroke-width="5.5"/>
            <path d="M190 110c-10 8-15 21-11 33 3 10 34 15 49 6 10-7 9-30-3-38Z" fill="url(#diorama-cat-gold)"/>
            <path d="M239 109c-13 5-16 25-11 36 5 11 41 13 50 2 7-10 2-28-9-36Z" fill="url(#diorama-cat-rose)"/>
            <path d="M182 104c-4-8-6-20-4-25 1-3 4-2 7 0l12 11c7-3 14-3 21-1l11-12c3-3 6-2 7 2 2 7 0 15-2 22 5 11-4 22-20 24-17 3-37-5-32-21Z" fill="url(#diorama-cat-gold)"/>
            <path d="M229 100c-2-6-3-15-1-21 1-3 4-3 7-1l12 11c7-2 14-1 21 2l13-9c4-2 7-1 7 3 0 8-3 17-6 22 3 13-10 20-25 19-18-1-29-11-28-26Z" fill="url(#diorama-cat-rose)"/>
            <path d="m182 83 9 10-6 5Zm52 1 8 8-7 4Zm48 2-9 8 6 5Z" fill="#d88c8c" stroke="none"/>
            <path d="M190 106q3-4 6 .6m12 .5q3.5-4 6.5 0m27 .3q3.5-4 7.5 .3m12 .6q3.5-3.5 7 0" fill="none" stroke-width="1.55"/>
            <g fill="#a85f68" stroke="none">
              <path d="M202 114q-4-4 3-4 5 0 1 4-2 2-4 0Zm52 .5q-4-4 3-4 5.5 0 1 4-2 2-4 0Z"/>
              <ellipse cx="190" cy="113" rx="4.5" ry="2.7" opacity=".57"/>
              <ellipse cx="270" cy="116" rx="4.5" ry="2.7" opacity=".57"/>
            </g>
            <path d="M204 115q-1 4-4 3m4-3q2 3 5 1m47 0q-1 4-4 2m4-2q2 3 5 1m-70 25q6-3 11 2m63-2q5-4 10-1" fill="none" stroke-width="1.25"/>
            <path d="m184 111-9-2m9 5-9 1m106-3 9-1m-10 5 9 2" fill="none" stroke-width="1.05"/>
          </g>
          <g class="fold fold-hearts">
            <use href="#diorama-heart" fill="#aa465e" transform="translate(230 75) scale(.86) rotate(-9)"/>
            <use href="#diorama-heart" fill="#bd6472" transform="translate(176 93) scale(.43) rotate(-18)"/>
            <use href="#diorama-heart" fill="#bd6472" transform="translate(288 79) scale(.53) rotate(14)"/>
            <use href="#diorama-heart" fill="#e9a17e" transform="translate(148 122) scale(.36) rotate(19)"/>
            <use href="#diorama-heart" fill="#f0ae8b" transform="translate(324 85) scale(.34) rotate(-12)"/>
          </g>
        </svg>
        <div class="letter-copy">
          <p class="salutation" id="salutation" dir="auto"></p>
          <p class="letter-message" dir="auto">
            <span class="visually-hidden" id="spoken-message"></span>
            <span class="measure" id="measured-message" aria-hidden="true"></span>
            <span class="typed" id="typed-message" aria-hidden="true"></span>
          </p>
          <p class="signature" id="signature" dir="auto"></p>
        </div>
      </article>
    </div>
    <p class="stage-status" role="status" aria-atomic="true">
      <svg width="14" height="14" viewBox="0 0 18 18" fill="currentColor" aria-hidden="true"><path d="M9 15c-2-1.6-7-4.7-7-8.3C2 3.2 6.5 2 9 5.5c2.5-3.5 7-2.3 7 1.2 0 3.6-5 6.7-7 8.3Z"/></svg>
      <span id="status">Ready for your letter</span>
    </p>
  </section>
</main>

<script>
  (() => {
    "use strict";

    const byId = (id) => document.getElementById(id);
    const composer = byId("composer");
    const from = byId("from");
    const to = byId("to");
    const message = byId("message");
    const counter = byId("counter");
    const error = byId("form-error");
    const stage = byId("stage");
    const scene = byId("scene");
    const status = byId("status");
    const replay = byId("replay");
    const envelope = byId("envelope");
    const paper = byId("letter");
    const salutation = byId("salutation");
    const measured = byId("measured-message");
    const typed = byId("typed-message");
    const spoken = byId("spoken-message");
    const signature = byId("signature");
    const soundButton = byId("sound");
    const soundLabel = byId("sound-label");
    const demoExit = byId("demo-exit");
    const reducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)");
    const narrow = window.matchMedia("(max-width: 790px)");

    let lastLetter = null;
    let motionTimers = [];
    let writingFrame = 0;
    let soundOn = true;
    let audio;
    let output;
    let inDemo = false;
    let demoTimers = [];
    let demoIndex = 0;

    function unlockAudio() {
      if (!soundOn) return;
      try {
        const Audio = window.AudioContext || window.webkitAudioContext;
        if (!Audio) return;
        if (!audio) {
          audio = new Audio();
          output = audio.createGain();
          output.gain.value = .65;
          output.connect(audio.destination);
        }
        if (audio.state === "suspended" || audio.state === "interrupted") {
          audio.resume().catch(() => {});
        }
      } catch (_) {
        // The animation also works without an audio device.
      }
    }

    function notes(parts) {
      if (!soundOn || !audio || audio.state !== "running") return;
      const now = audio.currentTime;
      for (const [frequency, delay, duration, level, wave] of parts) {
        const start = now + delay;
        const note = audio.createOscillator();
        const volume = audio.createGain();
        note.type = wave || "sine";
        note.frequency.value = frequency;
        volume.gain.setValueAtTime(.0001, start);
        volume.gain.exponentialRampToValueAtTime(level, start + .022);
        volume.gain.exponentialRampToValueAtTime(.0001, start + duration);
        note.connect(volume).connect(output);
        note.start(start);
        note.stop(start + duration + .02);
        note.onended = () => { note.disconnect(); volume.disconnect(); };
      }
    }

    function paperRustle() {
      if (!soundOn || !audio || audio.state !== "running") return;
      const duration = .28;
      const sample = audio.createBuffer(1, Math.ceil(audio.sampleRate * duration), audio.sampleRate);
      const data = sample.getChannelData(0);
      for (let i = 0; i < data.length; i++) {
        const t = i / data.length;
        data[i] = (Math.random() * 2 - 1) * Math.sin(Math.PI * t) * (.5 + .5 * Math.sin(27 * t) ** 2);
      }
      const noise = audio.createBufferSource();
      const filter = audio.createBiquadFilter();
      const gain = audio.createGain();
      noise.buffer = sample;
      filter.type = "bandpass";
      filter.frequency.value = 1100;
      filter.Q.value = .55;
      gain.gain.value = .075;
      noise.connect(filter).connect(gain).connect(output);
      noise.start();
      noise.onended = () => { noise.disconnect(); filter.disconnect(); gain.disconnect(); };
    }

    soundButton.addEventListener("click", () => {
      soundOn = !soundOn;
      soundButton.setAttribute("aria-pressed", String(soundOn));
      soundLabel.textContent = soundOn ? "Sound on" : "Sound off";
      if (soundOn) unlockAudio();
      if (audio && output) output.gain.setTargetAtTime(soundOn ? .65 : 0, audio.currentTime, .035);
    });

    function selectedPaper() {
      return composer.querySelector('input[name="paper"]:checked').value;
    }

    function updateCount() {
      counter.textContent = message.value.length + " / " + message.maxLength;
    }

    function updatePaperPreview() {
      if (stage.dataset.phase === "ready") stage.dataset.paper = selectedPaper();
    }

    function clearError() {
      error.hidden = true;
      for (const field of [from, to, message]) {
        field.removeAttribute("aria-invalid");
        field.removeAttribute("aria-describedby");
      }
    }

    message.addEventListener("input", updateCount);
    composer.addEventListener("input", (event) => {
      if (event.target.getAttribute("aria-invalid") === "true") clearError();
    });
    composer.addEventListener("change", (event) => {
      if (event.target.name === "paper") updatePaperPreview();
    });

    function setPhase(phase, label) {
      stage.dataset.phase = phase;
      envelope.disabled = phase !== "arrived";
      if (label) status.textContent = label;
    }

    function later(callback, delay) {
      motionTimers.push(window.setTimeout(callback, delay));
    }

    function stopMotion() {
      for (const timer of motionTimers) window.clearTimeout(timer);
      motionTimers = [];
      window.cancelAnimationFrame(writingFrame);
      writingFrame = 0;
      paper.hidden = true;
      paper.classList.remove("typing", "signed");
      typed.textContent = "";
    }

    function showStage() {
      const bounds = stage.getBoundingClientRect();
      if (bounds.top < 10 || bounds.bottom > window.innerHeight - 10) {
        stage.scrollIntoView({
          block: narrow.matches ? "start" : "nearest",
          behavior: reducedMotion.matches ? "instant" : "smooth"
        });
      }
    }

    function startDelivery(letter, follow = false, focusFrom = null) {
      stopMotion();
      lastLetter = letter;
      replay.hidden = false;
      stage.dataset.paper = letter.paper;
      setPhase("ready");
      void scene.offsetWidth;
      setPhase("delivering", "Your letter is on its way…");
      if (follow) showStage();

      const duration = reducedMotion.matches ? 300 : 3700;
      later(() => notes([[392, 0, .3, .056], [523.25, .11, .34, .047], [659.25, .21, .45, .047]]), 75);
      if (!reducedMotion.matches) {
        later(() => notes([[180, 0, .11, .023, "triangle"], [164, .35, .12, .019, "triangle"]]), 850);
        later(() => notes([[172, 0, .12, .02, "triangle"], [154, .35, .12, .018, "triangle"]]), 1530);
        later(paperRustle, 2230);
      }
      later(() => {
        setPhase("arrived", "Special delivery for " + letter.to);
        notes([[523.25, 0, .37, .045], [783.99, .13, .53, .052]]);
        if (focusFrom && document.activeElement === focusFrom) envelope.focus({preventScroll: true});
      }, duration);
    }

    function writeMessage(text) {
      if (reducedMotion.matches) {
        typed.textContent = text;
        paper.classList.add("signed");
        return;
      }

      const characters = typeof Intl.Segmenter === "function"
        ? Array.from(new Intl.Segmenter(undefined, {granularity: "grapheme"}).segment(text), (part) => part.segment)
        : Array.from(text);
      const duration = Math.min(4200, Math.max(440, characters.length * 31));
      let start;
      let shown = 0;
      paper.classList.add("typing");

      function writeFrame(time) {
        if (start === undefined) start = time;
        const progress = (time - start) / duration;
        const visible = Math.min(characters.length, 1 + Math.floor(progress * characters.length));
        if (visible !== shown) {
          typed.textContent = characters.slice(0, visible).join("");
          shown = visible;
        }
        if (visible < characters.length) {
          writingFrame = window.requestAnimationFrame(writeFrame);
        } else {
          writingFrame = 0;
          paper.classList.remove("typing");
          paper.classList.add("signed");
        }
      }

      writingFrame = window.requestAnimationFrame(writeFrame);
    }

    function openLetter(focus = false) {
      if (!lastLetter || stage.dataset.phase !== "arrived") return;
      const {from: author, to: recipient, message: words} = lastLetter;
      const quick = reducedMotion.matches;
      salutation.textContent = "Dear " + recipient + ",";
      measured.textContent = words;
      spoken.textContent = words;
      signature.textContent = "— " + author;
      setPhase("opening", "Opening your letter…");

      later(() => {
        paperRustle();
        notes([[523.25, 0, .67, .044], [659.25, .11, .67, .046], [783.99, .22, .74, .047], [1046.5, .37, .83, .025]]);
      }, 50);
      later(() => {
        paper.hidden = false;
        if (focus) paper.focus({preventScroll: true});
      }, quick ? 20 : 305);
      later(() => {
        setPhase("open", "Delivered with love");
        writeMessage(words);
      }, quick ? 40 : 875);
    }

    composer.addEventListener("submit", (event) => {
      event.preventDefault();
      clearError();
      const incomplete = [
        [from, "Add your name in the From field."],
        [to, "Add their name in the To field."],
        [message, "Write a little message for your letter."]
      ].find(([field]) => !field.value.trim());

      if (incomplete) {
        const [field, help] = incomplete;
        error.textContent = help;
        error.hidden = false;
        field.setAttribute("aria-invalid", "true");
        field.setAttribute("aria-describedby", error.id);
        field.focus();
        return;
      }

      unlockAudio();
      if ([from, to, message].includes(document.activeElement)) document.activeElement.blur();
      startDelivery({
        from: from.value.trim(),
        to: to.value.trim(),
        message: message.value.trim(),
        paper: selectedPaper()
      }, true, event.submitter || byId("send"));
    });

    envelope.addEventListener("click", () => {
      unlockAudio();
      openLetter(true);
    });

    replay.addEventListener("click", () => {
      if (!lastLetter) return;
      unlockAudio();
      startDelivery(lastLetter, true, replay);
    });

    const demoLetters = [
      {from: "Avery", to: "Jamie", message: "Life is sweeter with you in it. I’d choose you in every little lifetime.", paper: "cream"},
      {from: "Charlie", to: "Sam", message: "You make the ordinary days feel like the good part of a story.", paper: "rose"},
      {from: "Robin", to: "Taylor", message: "I hope you know how often little things make me think of you.", paper: "moonlight"}
    ];

    function demoLater(callback, delay) {
      demoTimers.push(window.setTimeout(() => {
        if (inDemo) callback();
      }, delay));
    }

    function runDemo() {
      demoTimers = [];
      const sample = demoLetters[demoIndex % demoLetters.length];
      demoIndex++;
      clearError();
      stopMotion();
      lastLetter = null;
      replay.hidden = true;
      setPhase("ready", "Ready for your letter");
      updatePaperPreview();
      from.value = "";
      to.value = "";
      message.value = "";
      updateCount();
      if (narrow.matches) window.scrollTo({top: 0, behavior: reducedMotion.matches ? "instant" : "smooth"});

      demoLater(() => { from.value = sample.from; }, 290);
      demoLater(() => { to.value = sample.to; }, 560);
      demoLater(() => { message.value = sample.message; updateCount(); }, 850);
      demoLater(() => {
        composer.querySelector('input[name="paper"][value="' + sample.paper + '"]').checked = true;
        updatePaperPreview();
      }, 1260);
      demoLater(() => startDelivery(sample, true), 2170);
      demoLater(() => openLetter(), 6300);
      demoLater(() => startDelivery(sample, true), 12250);
      demoLater(() => openLetter(), 16450);
      demoLater(runDemo, 20400);
    }

    function startDemo() {
      if (inDemo) return;
      inDemo = true;
      demoExit.hidden = false;
      runDemo();
    }

    function stopDemo() {
      if (!inDemo) return;
      inDemo = false;
      demoExit.hidden = true;
      for (const timer of demoTimers) window.clearTimeout(timer);
      demoTimers = [];
    }

    for (const interaction of ["pointerdown", "touchstart", "keydown", "click", "wheel"]) {
      window.addEventListener(interaction, (event) => {
        if (event.isTrusted) stopDemo();
      }, {capture: true, passive: true});
    }
    demoExit.addEventListener("click", stopDemo);

    function syncDemo() {
      if (window.location.hash === "#demo") startDemo();
      else stopDemo();
    }
    window.addEventListener("hashchange", syncDemo);
    updateCount();
    updatePaperPreview();
    syncDemo();
  })();
</script>
</body>
</html>