Back to the app
The code
Love Letter by Claude Opus 5.5
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.)<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
<meta name="theme-color" content="#b8283a">
<title>Love Letter Post</title>
<style>
:root{--vh:1vh;--red:#b8283a;--red2:#8e1c2c;--gold:#d6a645;--gold2:#a87a22;--cream:#fff6e6;--hand:"Segoe Script","Bradley Hand","Snell Roundhand","Lucida Handwriting","Brush Script MT","Apple Chancery","Dancing Script",cursive;--floor:calc(var(--vh)*26);--pw:min(34vw,170px);--ew:min(66vw,270px)}
body{--paper:#fff6e6;--line:rgba(184,40,58,.14);--ink:#5e1824;--sky1:#3a1230;--sky2:#a6394c;--env:#f8e8cb;--env2:#e6c999;--env3:#f2dbb1}
body[data-paper="1"]{--paper:#ffe6e3;--line:rgba(184,40,58,.2);--ink:#7e1828;--sky1:#4c0d22;--sky2:#d65a6e;--env:#f9d0cb;--env2:#e9a59f;--env3:#f4bdb7}
body[data-paper="2"]{--paper:#f7e3ad;--line:rgba(140,90,20,.2);--ink:#553309;--sky1:#1d1636;--sky2:#8a5a36;--env:#f0d48f;--env2:#d4ab55;--env3:#e7c473}
*{box-sizing:border-box;-webkit-tap-highlight-color:transparent}
html,body{margin:0;height:100%;overflow:hidden;touch-action:manipulation}
body{font-family:Georgia,"Times New Roman",serif;color:var(--ink);background:radial-gradient(120% 80% at 50% 0%,#fff8ec,#f6dcc0 60%,#ecc49c);-webkit-user-select:none;user-select:none}
input,textarea{-webkit-user-select:text;user-select:text}
button{font:inherit;cursor:pointer;touch-action:manipulation;color:inherit}
.off{display:none!important}
.reset,.reset *{transition:none!important;animation:none!important}
#bg{position:fixed;inset:0;overflow:hidden;pointer-events:none;z-index:0}
.bh{position:absolute;bottom:-60px;opacity:.2;animation:rise 14s linear infinite}
.bh svg,.fh svg,.ph svg,[data-h] svg{width:100%;height:100%;display:block}
@keyframes rise{to{transform:translateY(calc(var(--vh)*-115)) rotate(25deg)}}
/* compose */
#compose{position:fixed;inset:0;z-index:2;display:flex;flex-direction:column;overflow-y:auto;padding:max(16px,env(safe-area-inset-top)) 16px 24px;animation:fin .5s}
@keyframes fin{from{opacity:0;transform:translateY(12px)}}
.sheet{margin:auto;width:100%;max-width:440px;background:var(--cream);border:2px solid var(--gold);border-radius:20px;padding:14px 18px 20px;box-shadow:0 14px 40px rgba(120,30,40,.22),inset 0 0 0 5px var(--cream),inset 0 0 0 6.5px rgba(214,166,69,.55)}
.logo{width:88px;margin:0 auto -2px}
.logo svg{width:100%;display:block;overflow:visible}
h1{margin:0;text-align:center;color:var(--red);font-size:28px;letter-spacing:.02em}
.sub{margin:4px 0 8px;text-align:center;color:#9a6a3a;font-style:italic;font-size:15px}
label{display:flex;justify-content:space-between;margin:12px 0 5px;color:var(--red2);font-size:13px;font-weight:bold;letter-spacing:.08em;text-transform:uppercase}
#cnt{font-weight:normal;letter-spacing:0;color:#a88456}
.row{display:flex;gap:10px}.row>div{flex:1;min-width:0}
input,textarea{width:100%;font:inherit;font-size:18px;color:#4a1420;background:#fffdf8;border:2px solid #ead3a2;border-radius:12px;padding:12px 13px;outline:none;transition:border-color .2s}
input:focus,textarea:focus{border-color:var(--red)}
textarea{height:108px;resize:none;font-family:var(--hand);font-size:19px;line-height:1.45}
.shk{animation:shk .45s;border-color:var(--red)}
@keyframes shk{20%,60%{transform:translateX(-7px)}40%,80%{transform:translateX(7px)}}
.papers{display:flex;gap:8px}
.pbtn{flex:1;min-height:68px;padding:7px;border:2px solid #ead3a2;border-radius:14px;background:#fffaf0;color:var(--red2);font-size:15px;font-weight:bold;display:flex;flex-direction:column;gap:5px}
.pbtn i{display:block;height:30px;border-radius:8px;border:1px solid rgba(150,100,40,.3)}
.pbtn.on{border-color:var(--red);box-shadow:0 0 0 3px rgba(184,40,58,.22);background:#fff}
.pbtn[data-p="0"] i{background:repeating-linear-gradient(transparent 0 6px,rgba(184,40,58,.25) 6px 7px),#fff6e6}
.pbtn[data-p="1"] i{background:radial-gradient(circle at 5px 5px,rgba(184,40,58,.4) 2px,transparent 2.6px) 0 0/10px 10px,#ffe6e3}
.pbtn[data-p="2"] i{background:linear-gradient(135deg,#fbecc0,#e2bb62 60%,#f3d98f)}
#err{min-height:1.3em;margin:10px 0 0;text-align:center;color:var(--red);font-size:15px}
.send{width:100%;margin-top:6px;min-height:62px;border:0;border-radius:16px;background:linear-gradient(#cc3447,#9c1e30);color:#ffe3a3;font-size:22px;font-weight:bold;box-shadow:0 6px 0 #6b1321,0 12px 22px rgba(107,19,33,.35);display:flex;align-items:center;justify-content:center;gap:10px}
.send:active,.bb:active{transform:translateY(4px);box-shadow:0 2px 0 #6b1321}
.ih{width:24px;height:24px;display:inline-block;animation:beat 1.2s infinite}
@keyframes beat{0%,100%{transform:scale(1)}15%{transform:scale(1.2)}30%{transform:scale(.95)}45%{transform:scale(1.12)}}
/* stage */
#stage{position:fixed;inset:0;z-index:1;overflow:hidden}
.ground{position:absolute;left:0;right:0;bottom:0;height:var(--floor);z-index:1;background:linear-gradient(#f1c991,#d99f64);box-shadow:inset 0 5px 0 rgba(255,255,255,.35)}
.ground:before{content:"";position:absolute;left:0;right:0;top:30%;border-top:5px dashed rgba(255,247,230,.75)}
.ground:after{content:"";position:absolute;left:0;right:0;bottom:0;height:40%;background:linear-gradient(transparent,rgba(150,70,30,.18))}
#caption{position:absolute;left:16px;right:16px;top:calc(var(--vh)*10);z-index:5;text-align:center;font-family:var(--hand);font-size:clamp(22px,6.4vw,36px);color:var(--red);text-shadow:0 2px 0 rgba(255,250,240,.9);opacity:0;transform:translateY(-8px);transition:opacity .5s,transform .5s}
#caption.on{opacity:1;transform:none}
.pm{position:absolute;left:0;bottom:calc(var(--floor) - 18px);width:var(--pw);z-index:2;transform:translateX(-200%);transition:opacity .4s}
.pm svg{width:100%;display:block;overflow:visible}
.pm.gone{opacity:0}
.leg{transform-box:fill-box;transform-origin:50% 8%}
.walk .l1{animation:sw .44s ease-in-out infinite alternate}
.walk .l2{animation:sw .44s ease-in-out infinite alternate-reverse}
@keyframes sw{from{transform:rotate(24deg)}to{transform:rotate(-24deg)}}
.walk .bob{animation:bob .22s ease-in-out infinite alternate}
@keyframes bob{to{transform:translateY(-4px)}}
.tail{transform-box:fill-box;transform-origin:100% 100%;animation:wag 1.3s ease-in-out infinite alternate}
@keyframes wag{from{transform:rotate(-10deg)}to{transform:rotate(12deg)}}
.cap{transform-box:fill-box;transform-origin:10% 100%}
.tip .cap{animation:tipc 1s ease-in-out}
@keyframes tipc{30%,70%{transform:translate(-2px,-9px) rotate(-16deg)}}
.ph{position:absolute;bottom:calc(var(--floor) + var(--pw)*1.15);width:34px;height:34px;margin-left:-17px;z-index:5;animation:phA 1.5s ease-out forwards}
@keyframes phA{0%{transform:scale(0);opacity:0}25%{transform:scale(1.25);opacity:1}100%{transform:translateY(-60px) scale(.9);opacity:0}}
/* envelope */
.env{position:absolute;left:50%;bottom:calc(var(--floor) - 18px);z-index:3;width:var(--ew);height:calc(var(--ew)*.62);transform-origin:50% 100%;opacity:0;cursor:pointer}
.ein{position:absolute;inset:0;perspective:800px;transform-origin:50% 100%}
.env.ready .ein{animation:wig 2.4s ease-in-out infinite}
@keyframes wig{0%,60%,100%{transform:none}70%{transform:rotate(-3deg)}80%{transform:rotate(3deg)}90%{transform:rotate(-1.5deg)}}
.eb,.ep,.ef,.efl{position:absolute;border-radius:9px}
.eb{inset:0;background:var(--env2);box-shadow:0 12px 22px rgba(90,30,20,.3)}
.ep{left:7%;right:7%;top:7%;height:82%;z-index:1;border-radius:4px;background:repeating-linear-gradient(transparent 0 9px,var(--line) 9px 10px),var(--paper);transition:transform .5s .3s}
.env.open .ep{transform:translateY(-42%)}
.ef{inset:0;z-index:2;background:var(--env);clip-path:polygon(0 0,50% 54%,100% 0,100% 100%,0 100%)}
.efl{left:0;top:0;width:100%;height:58%;z-index:3;background:var(--env3);clip-path:polygon(0 0,100% 0,50% 100%);transform-origin:50% 0;border-radius:9px 9px 0 0;transition:transform .55s ease-in-out,z-index 0s .27s}
.env.open .efl{transform:rotateX(180deg);z-index:0}
.seal{position:absolute;left:50%;top:54%;z-index:4;width:20%;height:32%;transform:translate(-50%,-50%);transition:transform .35s,opacity .35s;filter:drop-shadow(0 2px 1px rgba(80,10,20,.4))}
.env.open .seal{transform:translate(-50%,-50%) scale(1.7);opacity:0}
.addr{position:absolute;left:0;right:0;bottom:8%;z-index:2;padding:0 8%;text-align:center;font-family:var(--hand);font-size:calc(var(--ew)*.085);color:var(--ink);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.hint{position:absolute;left:50%;top:calc(100% + 8px);transform:translateX(-50%);white-space:nowrap;font-family:var(--hand);font-size:22px;color:var(--red);opacity:0;transition:opacity .4s}
.env.ready .hint{opacity:1;animation:pulse 1.4s ease-in-out infinite}
@keyframes pulse{50%{opacity:.45}}
/* card */
#cardWrap{position:absolute;left:0;right:0;top:calc(58px + env(safe-area-inset-top));bottom:96px;z-index:4;display:none;align-items:center;justify-content:center}
#cardWrap.on{display:flex}
.card{width:min(92vw,420px);opacity:0;transform:translateY(50px) scale(.55);transition:transform .7s cubic-bezier(.2,1.25,.4,1),opacity .4s}
.card.show{opacity:1;transform:none}
.card.flash{animation:fl .5s}
@keyframes fl{40%{transform:scale(1.04)}}
.ctop{position:relative;z-index:2;height:min(calc(var(--vh)*40),280px);border-radius:14px 14px 0 0;overflow:hidden;background:linear-gradient(var(--sky1),var(--sky2));box-shadow:inset 0 0 0 3px rgba(214,166,69,.75);transform-origin:50% 100%;transform:perspective(1000px) rotateX(-176deg)}
.card.unfold .ctop{animation:unf 1.2s forwards}
@keyframes unf{0%{transform:perspective(1000px) rotateX(-176deg);animation-timing-function:ease-in}50%{transform:perspective(1000px) rotateX(-90deg);animation-timing-function:ease-out}100%{transform:perspective(1000px) rotateX(0deg)}}
.cover{position:absolute;inset:0;z-index:5;background:var(--paper);display:flex;flex-direction:column;align-items:center;justify-content:center;gap:8px;transform:scaleY(-1);box-shadow:inset 0 0 0 3px var(--gold)}
.cover span{width:64px;height:64px}
.cover b{font-family:var(--hand);font-weight:normal;font-size:26px;color:var(--red)}
.card.unfold .cover{animation:cov 1.2s forwards}
@keyframes cov{0%,49%{opacity:1}51%,100%{opacity:0}}
.scene{position:absolute;inset:0}
.stars,.pl,.pl svg{position:absolute;inset:0;width:100%;height:100%}
.tw{animation:tw 2.4s ease-in-out infinite alternate}
@keyframes tw{from{opacity:.2}to{opacity:1}}
.pl{transform-origin:50% 100%;transform:perspective(600px) rotateX(88deg);opacity:0;transition:transform .8s cubic-bezier(.2,1.5,.4,1),opacity .3s}
.pl.moon{transform:scale(.2);transform-origin:73% 29%}
.popped .pl{transform:none;opacity:1}
.pl:nth-child(2){transition-delay:.14s}.pl:nth-child(3){transition-delay:.3s}.pl:nth-child(4){transition-delay:.48s}
.lean,.lean2{transform-box:fill-box;transform-origin:50% 100%;animation:lean 3s ease-in-out infinite alternate}
.lean2{animation-name:lean2}
@keyframes lean{to{transform:rotate(5deg)}}@keyframes lean2{to{transform:rotate(-5deg)}}
.beat{transform-box:fill-box;transform-origin:50% 50%;animation:beat 1.3s infinite}
.fh{position:absolute;bottom:16%;z-index:3;opacity:0;animation:fhA 4s ease-in infinite}
@keyframes fhA{0%{opacity:0;transform:translateY(0) scale(.5)}15%{opacity:.95}100%{opacity:0;transform:translate(14px,-170px) scale(1.1)}}
.cbot{position:relative;z-index:1;min-height:140px;max-height:calc(var(--vh)*100 - min(calc(var(--vh)*40),280px) - 190px);overflow-y:auto;padding:12px 20px 18px;border-radius:0 0 14px 14px;background:repeating-linear-gradient(transparent 0 33px,var(--line) 33px 34px) 0 10px,var(--paper);box-shadow:0 16px 34px rgba(90,20,30,.3),inset 0 0 0 3px rgba(214,166,69,.6),inset 0 14px 14px -10px rgba(90,40,20,.25)}
body[data-paper="1"] .cbot{background:radial-gradient(circle at 9px 9px,rgba(184,40,58,.13) 2.6px,transparent 3.2px) 0 0/22px 22px,var(--paper)}
body[data-paper="2"] .cbot{background:radial-gradient(ellipse at 25% 15%,rgba(255,255,255,.45),transparent 55%),radial-gradient(ellipse at 85% 95%,rgba(150,95,20,.22),transparent 55%),var(--paper);box-shadow:0 16px 34px rgba(90,20,30,.3),inset 0 0 0 3px #b8892c,inset 0 0 0 7px rgba(255,246,220,.6),inset 0 0 28px rgba(140,90,20,.35)}
#msg{font-family:var(--hand);font-size:23px;line-height:1.5;color:var(--ink)}
.ln{margin:0 0 .15em}.dear{margin-bottom:.3em}.sign{text-align:right;margin-top:.4em}.name{margin-top:0;font-size:1.2em;color:var(--red)}
.w{display:inline-block;white-space:nowrap}
.ch{display:inline-block;animation:ink .5s ease-out both}
@keyframes ink{0%{opacity:0;transform:translateY(-4px) scale(1.3);filter:blur(1.5px);color:var(--gold)}100%{opacity:1;transform:none;filter:none}}
.nib{display:inline-block;width:2px;height:1em;margin-left:1px;vertical-align:-.12em;background:var(--red);animation:blink .8s steps(1) infinite}
@keyframes blink{50%{opacity:0}}
/* bar + fixed ui */
#bar{position:absolute;left:50%;bottom:0;z-index:6;max-width:100%;display:flex;align-items:center;gap:8px;padding:10px 12px calc(10px + env(safe-area-inset-bottom));background:rgba(255,248,236,.96);border:2px solid var(--gold);border-bottom:0;border-radius:20px 20px 0 0;box-shadow:0 -6px 22px rgba(120,40,30,.18);transform:translate(-50%,115%);transition:transform .5s cubic-bezier(.2,1.2,.4,1)}
#bar.on{transform:translate(-50%,0)}
.bb{min-width:70px;min-height:60px;padding:6px 8px;border:0;border-radius:14px;background:linear-gradient(#cc3447,#9c1e30);color:#ffe3a3;font-size:13px;font-weight:bold;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:3px;box-shadow:0 4px 0 #6b1321}
.bb svg{width:24px;height:24px}
.mini{gap:6px}
.mini .pbtn{flex:none;width:50px;height:50px;min-height:0;padding:4px;border-radius:50%}
.mini .pbtn i{height:100%;border-radius:50%}
#muteB{position:fixed;top:calc(10px + env(safe-area-inset-top));right:10px;z-index:20;width:52px;height:52px;padding:0;border-radius:50%;border:2px solid var(--gold);background:rgba(255,248,236,.92);color:var(--red);display:flex;align-items:center;justify-content:center;box-shadow:0 4px 12px rgba(120,40,30,.18)}
#muteB svg{width:26px;height:26px}
#muteB .x,#muteB.m .wv{display:none}#muteB.m .x{display:inline}
#demoTag{position:fixed;top:calc(14px + env(safe-area-inset-top));left:12px;z-index:20;padding:9px 14px;border-radius:99px;background:var(--red);color:#ffe3a3;font-size:14px;box-shadow:0 4px 12px rgba(120,20,30,.3);display:none}
#demoTag.on{display:block}
#tapEl{position:fixed;left:-99px;top:0;z-index:30;width:64px;height:64px;margin:-32px 0 0 -32px;border-radius:50%;background:rgba(255,255,255,.4);border:3px solid #fff;box-shadow:0 0 0 3px rgba(184,40,58,.55);pointer-events:none;opacity:0}
#tapEl.go{animation:tapA .75s ease-out}
@keyframes tapA{0%{opacity:0;transform:scale(1.7)}30%{opacity:1;transform:scale(.8)}100%{opacity:0;transform:scale(1.25)}}
@media (max-width:340px){.row{flex-direction:column;gap:0}}
</style>
</head>
<body data-paper="0">
<div id="bg"></div>
<main id="compose">
<div class="sheet">
<div class="logo" id="logo"></div>
<h1>Love Letter Post</h1>
<p class="sub">Write it, seal it, and a little cat will deliver it.</p>
<div class="row">
<div><label for="fromI">From</label><input id="fromI" maxlength="24" placeholder="Your name" autocomplete="off"></div>
<div><label for="toI">For</label><input id="toI" maxlength="24" placeholder="Their name" autocomplete="off"></div>
</div>
<label for="msgI">Your message <span id="cnt">0/180</span></label>
<textarea id="msgI" maxlength="180" placeholder="Write something sweet..."></textarea>
<label>Paper style</label>
<div class="papers" id="cp">
<button class="pbtn" data-p="0"><i></i><span>Cream</span></button>
<button class="pbtn" data-p="1"><i></i><span>Rose</span></button>
<button class="pbtn" data-p="2"><i></i><span>Gold</span></button>
</div>
<p id="err" aria-live="polite"></p>
<button id="sendB" class="send">Send with love <span class="ih" data-h="#ffd77a"></span></button>
</div>
</main>
<section id="stage" class="off">
<div id="caption"></div>
<div class="ground"></div>
<div class="pm" id="pm"><svg viewBox="0 0 140 170" aria-hidden="true"><g class="bob">
<path class="tail" d="M44 130C16 130 8 104 22 84" fill="none" stroke="#d9802f" stroke-width="10" stroke-linecap="round"/>
<g class="leg l2"><rect x="72" y="132" width="15" height="28" rx="7" fill="#d47a2c"/><ellipse cx="81" cy="160" rx="11" ry="6" fill="#f6e3c7"/></g>
<g class="leg l1"><rect x="52" y="132" width="15" height="28" rx="7" fill="#ec9a4a"/><ellipse cx="61" cy="160" rx="11" ry="6" fill="#fff1dc"/></g>
<ellipse cx="68" cy="116" rx="30" ry="29" fill="#ec9a4a"/>
<ellipse cx="73" cy="122" rx="18" ry="20" fill="#fff1dc"/>
<path d="M48 92L90 136" stroke="#7a1a28" stroke-width="5" stroke-linecap="round"/>
<rect x="28" y="110" width="30" height="25" rx="6" fill="#b8283a"/><path d="M28 119h30" stroke="#8e1c2c" stroke-width="3"/>
<path d="M43 131c-5-3.5-7-5.5-7-8a3 3 0 0 1 7-1 3 3 0 0 1 7 1c0 2.5-2 4.5-7 8z" fill="#e3b24f"/>
<path d="M46 54L43 26L66 40ZM84 39L104 27L100 56Z" fill="#ec9a4a"/><path d="M49 47L48 33L59 40ZM88 39L99 33L97 48Z" fill="#f4a9a0"/>
<circle cx="72" cy="66" r="30" fill="#ec9a4a"/>
<ellipse cx="78" cy="79" rx="17" ry="11" fill="#fff1dc"/>
<ellipse cx="65" cy="66" rx="3.8" ry="4.8" fill="#3a1a14"/><ellipse cx="89" cy="66" rx="3.8" ry="4.8" fill="#3a1a14"/>
<circle cx="66.3" cy="64.3" r="1.4" fill="#fff"/><circle cx="90.3" cy="64.3" r="1.4" fill="#fff"/>
<path d="M74 74h8l-4 4z" fill="#e07a88"/><path d="M78 78q-2 5-6 2M78 78q2 5 6 2" stroke="#3a1a14" stroke-width="1.6" fill="none" stroke-linecap="round"/>
<circle cx="57" cy="77" r="5" fill="#f28b8b" opacity=".5"/><circle cx="99" cy="77" r="5" fill="#f28b8b" opacity=".5"/>
<path d="M60 80L42 78M60 83L43 86M96 80L114 77M96 83L113 86" stroke="#7a4a2a" stroke-width="1.2" stroke-linecap="round" opacity=".6"/>
<g class="cap"><path d="M43 50C43 22 101 22 101 50Z" fill="#2f5fa8"/><rect x="42" y="43" width="60" height="9" rx="4" fill="#1f4683"/><path d="M97 49C111 46 123 50 126 57C113 58 101 56 94 53Z" fill="#183a6e"/><circle cx="72" cy="36" r="5.5" fill="#e3b24f" stroke="#a87a22"/></g>
<path d="M92 102Q106 116 121 113" stroke="#d47a2c" stroke-width="9" fill="none" stroke-linecap="round"/>
<path d="M56 100Q70 114 88 112" stroke="#ec9a4a" stroke-width="10" fill="none" stroke-linecap="round"/>
<g class="he"><rect x="84" y="95" width="42" height="28" rx="3" fill="#fff6e6" stroke="#d6a645" stroke-width="1.5"/><path d="M84 96l21 15 21-15" fill="none" stroke="#d6a645" stroke-width="1.5"/><path d="M105 117c-4-3-6-4.5-6-6.5a2.5 2.5 0 0 1 6-1 2.5 2.5 0 0 1 6 1c0 2-2 3.5-6 6.5z" fill="#b8283a"/></g>
<circle cx="88" cy="112" r="6.5" fill="#fff1dc"/><circle cx="122" cy="113" r="6" fill="#fff1dc"/>
</g></svg></div>
<div class="env" id="env" role="button" aria-label="Open the letter">
<div class="ein"><div class="eb"></div><div class="ep"></div><div class="ef"></div><div class="efl"></div><div class="seal" data-h="#b8283a"></div><div class="addr" id="addr"></div></div>
<div class="hint">Tap to open</div>
</div>
<div id="cardWrap"><div class="card" id="card">
<div class="ctop">
<svg class="stars" id="stars" viewBox="0 0 400 300" preserveAspectRatio="xMidYMax slice"></svg>
<div class="scene" id="scene">
<div class="pl moon"><svg viewBox="0 0 400 300" preserveAspectRatio="xMidYMax slice"><defs><radialGradient id="mg"><stop offset="0" stop-color="#ffe9a8" stop-opacity=".85"/><stop offset="1" stop-color="#ffe9a8" stop-opacity="0"/></radialGradient></defs><circle cx="292" cy="86" r="80" fill="url(#mg)"/><circle cx="292" cy="86" r="40" fill="#fff0c4"/><circle cx="279" cy="76" r="8" fill="#f3dc9c"/><circle cx="305" cy="98" r="6" fill="#f3dc9c"/><circle cx="301" cy="71" r="4" fill="#f3dc9c"/></svg></div>
<div class="pl"><svg viewBox="0 0 400 300" preserveAspectRatio="xMidYMax slice"><path d="M0 300V222Q70 194 140 212T280 204T400 210V300Z" fill="#5a1526"/><path d="M0 300V252Q100 232 200 247T400 246V300Z" fill="#7b2234"/></svg></div>
<div class="pl"><svg viewBox="0 0 400 300" preserveAspectRatio="xMidYMax slice">
<path d="M150 196C128 196 118 232 122 252H178C182 232 172 196 150 196Z" fill="#e8913a"/>
<path d="M133 222q17-8 34 0M130 237q20-8 40 0" stroke="#c46f25" stroke-width="4" fill="none" stroke-linecap="round"/>
<g class="lean"><g transform="rotate(9 156 196)"><path d="M140 176L143 152L154 165ZM160 165L171 152L174 176Z" fill="#e8913a"/><path d="M144 170L145 158L151 165ZM163 165L169 158L170 170Z" fill="#c46f25"/><circle cx="157" cy="182" r="20" fill="#e8913a"/><path d="M147 172q10-5 20 0" stroke="#c46f25" stroke-width="3.5" fill="none" stroke-linecap="round"/></g></g>
<path d="M260 196C238 196 228 232 232 252H288C292 232 282 196 260 196Z" fill="#f6e7d0"/>
<path d="M242 232q18 8 36 0" stroke="#dcc6a5" stroke-width="4" fill="none" stroke-linecap="round"/>
<g class="lean2"><g transform="rotate(-9 254 196)"><path d="M237 176L240 152L251 165ZM257 165L268 152L271 176Z" fill="#f6e7d0"/><path d="M241 170L242 158L248 165ZM260 165L266 158L267 170Z" fill="#dcc6a5"/><circle cx="254" cy="182" r="20" fill="#f6e7d0"/></g></g>
<path d="M178 250Q192 257 205 250C177 232 180 206 196 207C201 207 205 211 205 216" stroke="#e8913a" stroke-width="7" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M232 250Q218 257 205 250C233 232 230 206 214 207C209 207 205 211 205 216" stroke="#f6e7d0" stroke-width="7" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<g transform="translate(193 126)"><path id="bh0" class="beat" fill="#ff4d63"/></g>
</svg></div>
<div class="pl"><svg id="flw" viewBox="0 0 400 300" preserveAspectRatio="xMidYMax slice"></svg></div>
</div>
<div class="cover"><span data-h="#d6a645"></span><b id="coverTo">For you</b></div>
</div>
<div class="cbot" id="msgBox"><div id="msg" aria-live="polite"></div></div>
</div></div>
<nav id="bar">
<button id="replayB" class="bb" aria-label="Replay the delivery"><svg viewBox="0 0 24 24"><path d="M4 12a8 8 0 1 0 2.4-5.7M4 4v5h5" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"/></svg><span>Replay</span></button>
<div class="papers mini">
<button class="pbtn" data-p="0" aria-label="Cream paper"><i></i></button>
<button class="pbtn" data-p="1" aria-label="Rose paper"><i></i></button>
<button class="pbtn" data-p="2" aria-label="Gold paper"><i></i></button>
</div>
<button id="newB" class="bb" aria-label="Write a new letter"><svg viewBox="0 0 24 24"><path d="M4 20h4L19 9l-4-4L4 16v4zM13.5 6.5l4 4" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"/></svg><span>New letter</span></button>
</nav>
</section>
<button id="muteB" aria-label="Sound on or off"><svg viewBox="0 0 24 24"><path d="M3 9v6h4l5 4V5L7 9H3z" fill="currentColor"/><path class="wv" d="M15.5 8.5a5 5 0 0 1 0 7M18.5 5.5a9 9 0 0 1 0 13" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"/><path class="x" d="M16 9l6 6M22 9l-6 6" stroke="currentColor" stroke-width="2.2" stroke-linecap="round"/></svg></button>
<div id="demoTag">Demo · tap anywhere to try it</div>
<div id="tapEl"></div>
<script>
(()=>{
const E=i=>document.getElementById(i),$$=s=>[...document.querySelectorAll(s)],R=document.documentElement,B=document.body,K='love-letter-post-v1';
const HP='M12 21.4C6.4 16.9 1.5 13 1.5 8.1 1.5 5 3.9 2.6 7 2.6c2 0 3.8 1 5 2.6 1.2-1.6 3-2.6 5-2.6 3.1 0 5.5 2.4 5.5 5.5 0 4.9-4.9 8.8-10.5 13.3z';
const heart=c=>'<svg viewBox="0 0 24 24" aria-hidden="true"><path d="'+HP+'" fill="'+c+'"/></svg>';
$$('[data-h]').forEach(e=>e.innerHTML=heart(e.dataset.h));
E('bh0').setAttribute('d',HP);
const setVH=()=>R.style.setProperty('--vh',innerHeight/100+'px');setVH();addEventListener('resize',setVH);
const [compose,stage,fromI,toI,msgI,cnt,err,sendB,pm,env,addr,caption,cardWrap,card,scene,msgBox,msg,bar,replayB,newB,muteB,tapEl,demoTag,coverTo]='compose stage fromI toI msgI cnt err sendB pm env addr caption cardWrap card scene msgBox msg bar replayB newB muteB tapEl demoTag coverTo'.split(' ').map(E);
const he=pm.querySelector('.he'),ctop=document.querySelector('.ctop');
E('logo').innerHTML=pm.innerHTML;
/* decorations drawn in code */
const bg=E('bg');
for(let i=0;i<12;i++){const d=document.createElement('div'),s=14+Math.random()*26;d.className='bh';d.style.cssText=`left:${Math.random()*96}%;width:${s}px;height:${s}px;animation-duration:${10+Math.random()*10}s;animation-delay:${-Math.random()*18}s`;d.innerHTML=heart(['#e0344a','#d6a645','#f08a9a'][i%3]);bg.appendChild(d)}
let st='';for(let i=0;i<28;i++)st+=`<circle class="tw" cx="${Math.random()*400|0}" cy="${Math.random()*180|0}" r="${(Math.random()*1.5+.6).toFixed(1)}" fill="#ffeab0" style="animation-delay:${(-Math.random()*3).toFixed(2)}s"/>`;
E('stars').innerHTML=st;
let fl='<path d="M0 300V284Q50 274 100 284T200 282T300 284T400 280V300Z" fill="#6f7a33"/>';
[[30,256,14,'#d8344a'],[64,272,11,'#fff3dc'],[97,264,9,'#e9b949'],[12,282,9,'#fff3dc'],[120,287,7,'#d8344a'],[370,256,14,'#d8344a'],[336,272,11,'#e9b949'],[303,266,9,'#fff3dc'],[388,282,9,'#e9b949'],[280,288,7,'#d8344a']].forEach(([x,y,r,c])=>{
const m=(y+(300-y)*.5).toFixed(0);
fl+=`<path d="M${x} ${y}Q${x-5} ${m} ${x} 300" stroke="#55682a" stroke-width="3" fill="none"/><ellipse cx="${x+6}" cy="${m}" rx="7" ry="3" fill="#7c8f3a" transform="rotate(-30 ${x+6} ${m})"/>`;
for(let k=0;k<5;k++){const a=k*1.2566-1.5708;fl+=`<circle cx="${(x+Math.cos(a)*r*.72).toFixed(1)}" cy="${(y+Math.sin(a)*r*.72).toFixed(1)}" r="${(r*.56).toFixed(1)}" fill="${c}"/>`}
fl+=`<circle cx="${x}" cy="${y}" r="${(r*.4).toFixed(1)}" fill="#f2c14e" stroke="#b9862a"/>`;
});
E('flw').innerHTML=fl;
/* soft sounds made with Web Audio */
const S={ac:null,out:null,nb:null,muted:false,
init(){try{if(!this.ac){const A=window.AudioContext||window.webkitAudioContext;if(!A)return;const ac=this.ac=new A();this.out=ac.createGain();this.out.gain.value=this.muted?0:.7;const comp=ac.createDynamicsCompressor();this.out.connect(comp);comp.connect(ac.destination);
const d=ac.createDelay(1),fb=ac.createGain(),lp=ac.createBiquadFilter(),wet=ac.createGain();d.delayTime.value=.23;fb.gain.value=.3;lp.type='lowpass';lp.frequency.value=1800;wet.gain.value=.35;this.out.connect(d);d.connect(lp);lp.connect(fb);fb.connect(d);lp.connect(wet);wet.connect(comp);
const n=ac.sampleRate,b=ac.createBuffer(1,n,n),c=b.getChannelData(0);for(let i=0;i<n;i++)c[i]=Math.random()*2-1;this.nb=b}
if(this.ac.state==='suspended')this.ac.resume()}catch(e){}},
ok(){return this.ac&&this.ac.state==='running'&&!this.muted},
tone(f,dur,o={}){if(!this.ok())return;try{const ac=this.ac,t=ac.currentTime+(o.at||0),os=ac.createOscillator(),g=ac.createGain();os.type=o.type||'sine';os.frequency.setValueAtTime(f,t);if(o.slide)os.frequency.exponentialRampToValueAtTime(Math.max(30,f+o.slide),t+dur);g.gain.setValueAtTime(0,t);g.gain.linearRampToValueAtTime(o.vol||.15,t+.01);g.gain.exponentialRampToValueAtTime(.0001,t+dur);os.connect(g);g.connect(this.out);os.start(t);os.stop(t+dur+.05)}catch(e){}},
noise(dur,o={}){if(!this.ok())return;try{const ac=this.ac,t=ac.currentTime+(o.at||0),s=ac.createBufferSource(),f=ac.createBiquadFilter(),g=ac.createGain();s.buffer=this.nb;f.type=o.type||'bandpass';f.frequency.value=o.f||1500;f.Q.value=o.q||1;g.gain.setValueAtTime(0,t);g.gain.linearRampToValueAtTime(o.vol||.1,t+.01);g.gain.exponentialRampToValueAtTime(.0001,t+dur);s.connect(f);f.connect(g);g.connect(this.out);s.start(t,Math.random()*.5);s.stop(t+dur+.05)}catch(e){}},
step(i){this.noise(.07,{type:'lowpass',f:500,vol:.16});this.tone(i%2?150:180,.08,{vol:.05,slide:-60})},
tick(){this.tone(880,.07,{type:'triangle',vol:.05})},
pop(at=0){this.tone(420,.14,{type:'triangle',vol:.07,slide:520,at})},
drop(){this.tone(300,.18,{vol:.09,slide:-170});this.noise(.12,{f:900,vol:.08})},
chime(){[784,988,1175,1568].forEach((f,i)=>{this.tone(f,1.1,{vol:.08,at:i*.11});this.tone(f*2,.5,{vol:.02,at:i*.11})})},
rustle(){for(let i=0;i<3;i++)this.noise(.18,{f:2600+i*700,q:.7,vol:.09,at:i*.09})},
pen(){this.noise(.035,{type:'highpass',f:4500,vol:.03})},
melody(){[659,784,880,988,880,784,659,587,659].forEach((f,i)=>{this.tone(f,.9,{vol:.05,at:i*.26});this.tone(f*2,.35,{vol:.015,at:i*.26,type:'triangle'})})}};
/* state + helpers */
let gen=0,demo=false,swallow=false,swT=0,paper=0;
const wait=(ms,g)=>new Promise((res,rej)=>setTimeout(()=>g===gen?res():rej('x'),ms));
const tween=(ms,fn,g)=>new Promise((res,rej)=>{const t0=performance.now();const f=t=>{if(g!==gen)return rej('x');const p=Math.max(0,Math.min(1,(t-t0)/ms));fn(p);p<1?requestAnimationFrame(f):res()};requestAnimationFrame(f)});
const vals=()=>({from:fromI.value.trim(),to:toI.value.trim(),msg:msgI.value.trim()});
const cap=t=>{if(t)caption.textContent=t;caption.classList.toggle('on',!!t)};
const upd=()=>{cnt.textContent=msgI.value.length+'/180'};
const show=w=>{compose.classList.toggle('off',w!=='c');stage.classList.toggle('off',w!=='s')};
function save(){if(demo)return;try{localStorage.setItem(K,JSON.stringify(Object.assign(vals(),{paper,muted:S.muted})))}catch(e){}}
function load(){try{const d=JSON.parse(localStorage.getItem(K)||'null');if(d){fromI.value=d.from||'';toI.value=d.to||'';msgI.value=d.msg||'';setPaper((d.paper|0)%3);S.muted=!!d.muted;muteB.classList.toggle('m',S.muted)}}catch(e){}}
function setPaper(i,fx){paper=i;B.dataset.paper=i;$$('.pbtn').forEach(b=>b.classList.toggle('on',+b.dataset.p===i));if(fx){card.classList.remove('flash');void card.offsetWidth;card.classList.add('flash')}}
function shake(el){el.classList.remove('shk');void el.offsetWidth;el.classList.add('shk')}
function resetStage(){
stage.classList.add('reset');
pm.className='pm';pm.style.transform='';he.style.opacity=1;
env.className='env';env.style.cssText='';
cardWrap.classList.remove('on');card.className='card';scene.classList.remove('popped');msg.innerHTML='';
$$('.fh,.ph').forEach(e=>e.remove());
bar.classList.remove('on');cap('');
void stage.offsetWidth;stage.classList.remove('reset');
}
function popHeart(x){const d=document.createElement('div');d.className='ph';d.style.left=x+'px';d.innerHTML=heart('#e0344a');stage.appendChild(d);setTimeout(()=>d.remove(),1600)}
function floatHearts(){for(let i=0;i<8;i++){const d=document.createElement('span'),s=10+Math.random()*12;d.className='fh';d.style.cssText=`left:${8+Math.random()*84}%;width:${s}px;height:${s}px;animation-delay:${i*.5}s;animation-duration:${3.5+Math.random()*2}s`;d.innerHTML=heart(['#ff7d8f','#ffd77a','#ffb3c0'][i%3]);ctop.appendChild(d)}}
/* the delivery: cat postman walks in, leaves the envelope, tips his cap, walks off */
async function deliver(g){
const v=vals();show('s');resetStage();
const to=v.to||'you';addr.textContent='For '+to;coverTo.textContent='For '+to;
cap('Special delivery for '+to+'!');
const W=stage.clientWidth,pw=pm.offsetWidth,ph=pm.offsetHeight,cx=W/2-.75*pw,x0=-pw-20;
pm.classList.add('walk');let sc=0;
await tween(3000,p=>{pm.style.transform=`translateX(${x0+(cx-x0)*p}px)`;const s=p*13|0;if(s>sc){sc=s;S.step(s)}},g);
pm.classList.remove('walk');await wait(220,g);
he.style.opacity=0;
const ew=env.offsetWidth,eh=env.offsetHeight,s0=.3*pw/ew;
env.style.transition='none';env.style.opacity=1;env.style.transform=`translate(-50%,${-.276*ph}px) scale(${s0})`;void env.offsetWidth;
env.style.transition='transform .38s cubic-bezier(.55,0,1,.45)';env.style.transform=`translate(-50%,0) scale(${s0})`;
await wait(380,g);S.drop();pm.classList.add('tip');S.chime();popHeart(cx+.5*pw);
cap('From '+(v.from||'someone')+', with love');
await wait(1000,g);
pm.classList.remove('tip');pm.classList.add('walk');
env.style.transition='transform 1s cubic-bezier(.3,1.4,.5,1)';env.style.transform=`translate(-50%,${.2*eh}px) scale(1)`;
setTimeout(()=>{if(g===gen){env.classList.add('ready');bar.classList.add('on')}},800);
sc=0;const x1=W+30;
await tween(1800,p=>{pm.style.transform=`translateX(${cx+(x1-cx)*p}px)`;const s=p*8|0;if(s>sc){sc=s;S.step(s)}},g);
pm.classList.remove('walk');
}
/* opening: flap, pop-up card unfolds, scene pops up, message is written by hand */
async function openLetter(g,ms){
const v=vals();ms=ms||55;
env.classList.remove('ready');env.classList.add('open');pm.classList.add('gone');bar.classList.add('on');cap('');S.rustle();
await wait(650,g);
env.style.transition='transform .6s ease-in,opacity .5s';env.style.transform+=' translateY(25%)';env.style.opacity=0;
cardWrap.classList.add('on');void card.offsetWidth;card.classList.add('show');S.pop();
await wait(550,g);
card.classList.add('unfold');S.rustle();
await wait(1200,g);
scene.classList.add('popped');[0,.14,.3,.48].forEach(a=>S.pop(a));S.melody();floatHearts();
await wait(800,g);
await write(v,g,ms);
}
async function write(v,g,ms){
msg.innerHTML='';msgBox.scrollTop=0;
const L=v.msg.length;msg.style.fontSize=(L>120?18:L>70?20:23)+'px';
const nib=document.createElement('span');nib.className='nib';let n=0;
for(const [c,t] of [['dear','Dear '+(v.to||'you')+','],['body',v.msg],['sign','With love,'],['sign name',v.from||'me']]){
const ln=document.createElement('div');ln.className='ln '+c;msg.appendChild(ln);let w=null;
for(const ch of t){
if(ch==='\n'){ln.appendChild(document.createElement('br'));w=null}
else if(ch===' '){ln.appendChild(document.createTextNode(' '));w=null}
else{if(!w){w=document.createElement('span');w.className='w';ln.appendChild(w)}const s=document.createElement('span');s.className='ch';s.textContent=ch;w.appendChild(s)}
(w||ln).appendChild(nib);
if(ch!==' '&&n++%2===0)S.pen();
msgBox.scrollTop=msgBox.scrollHeight;
await wait(ch===' '?ms*.7:/[.,!?;:]/.test(ch)?ms*5:ms,g);
}
await wait(ms*5,g);
}
}
/* hands-free demo for #demo */
function fakeTap(el){const r=el.getBoundingClientRect();tapEl.style.left=r.left+r.width/2+'px';tapEl.style.top=r.top+r.height/2+'px';tapEl.classList.remove('go');void tapEl.offsetWidth;tapEl.classList.add('go')}
async function typeIn(el,t,g,ms){el.value='';for(const c of t){el.value+=c;upd();await wait(ms,g)}}
async function runDemo(){
if(demo)return;demo=true;demoTag.classList.add('on');const g=++gen;
try{for(;;){
resetStage();show('c');fromI.value=toI.value=msgI.value='';upd();setPaper(0);err.textContent='';
await wait(600,g);
fakeTap(fromI);await typeIn(fromI,'Milo',g,90);
fakeTap(toI);await typeIn(toI,'Luna',g,90);
fakeTap(msgI);await typeIn(msgI,'I look at the moon and think of you. Will you count the stars with me?',g,24);
await wait(300,g);fakeTap($$('#cp .pbtn')[1]);setPaper(1);S.pop();
await wait(600,g);fakeTap(sendB);S.tick();await wait(250,g);
await deliver(g);
await wait(250,g);fakeTap(env);await openLetter(g,26);
const bp=$$('#bar .pbtn');
await wait(900,g);fakeTap(bp[2]);setPaper(2,true);S.pop();
await wait(1100,g);fakeTap(bp[0]);setPaper(0,true);S.pop();
await wait(1400,g);
}}catch(e){}
}
function stopDemo(){demo=false;gen++;demoTag.classList.remove('on');tapEl.classList.remove('go');resetStage();show('c');fromI.value=toI.value=msgI.value='';err.textContent='';setPaper(0);load();upd()}
/* any real touch ends the demo (and that touch does not press a button) */
function real(e){
if(!e.isTrusted)return;
if(e.type!=='keydown')S.init();
if(demo){stopDemo();if(e.type!=='keydown'){swallow=true;clearTimeout(swT);swT=setTimeout(()=>swallow=false,700)}}
if(swallow&&e.cancelable&&e.type!=='keydown')e.preventDefault();
}
['pointerdown','mousedown','touchstart','keydown','wheel'].forEach(t=>addEventListener(t,real,{capture:true,passive:false}));
addEventListener('touchend',e=>{if(e.isTrusted)S.init()},true);
addEventListener('click',e=>{if(swallow){e.preventDefault();e.stopPropagation();swallow=false}},true);
/* controls */
$$('.pbtn').forEach(b=>b.addEventListener('click',()=>{S.init();S.pop();setPaper(+b.dataset.p,cardWrap.classList.contains('on'));save()}));
sendB.addEventListener('click',()=>{
S.init();const v=vals(),miss=[];
if(!v.from)miss.push([fromI,'who it is from']);if(!v.to)miss.push([toI,'who it is for']);if(!v.msg)miss.push([msgI,'a message']);
if(miss.length){miss.forEach(m=>shake(m[0]));err.textContent='Please add '+miss.map(m=>m[1]).join(' and ')+'.';S.tone(196,.25,{vol:.06,type:'triangle'});return}
err.textContent='';save();S.tick();const g=++gen;deliver(g).catch(()=>{});
});
env.addEventListener('click',()=>{if(!env.classList.contains('ready'))return;S.init();const g=++gen;openLetter(g).catch(()=>{})});
replayB.addEventListener('click',()=>{S.init();S.tick();const g=++gen;deliver(g).catch(()=>{})});
newB.addEventListener('click',()=>{S.tick();gen++;resetStage();show('c')});
muteB.addEventListener('click',()=>{S.init();S.muted=!S.muted;if(S.out)S.out.gain.value=S.muted?0:.7;muteB.classList.toggle('m',S.muted);save();S.tick()});
[fromI,toI,msgI].forEach(i=>i.addEventListener('input',()=>{upd();err.textContent='';i.classList.remove('shk');save()}));
setPaper(0);load();upd();
if(location.hash==='#demo')setTimeout(runDemo,300);
addEventListener('hashchange',()=>{if(location.hash==='#demo')runDemo()});
})();
</script>
</body>
</html>
