Back to the app
The code
The Most Uncomfortable Web Page by Claude Sonnet 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="color-scheme" content="light">
<title>Totally Normal Corp - Welcome Portal</title>
<style>
:root{--bg:#f4f1ea;--ink:#1d2433;--muted:#566074;--brand:#2f55d4;--brand-d:#1b3796;--acc:#ffd23f;--acc-d:#b8900f;--ok:#1f9d6b;--card:#fffdf8;--line:#d8d1c0}
*{box-sizing:border-box}
html{-webkit-text-size-adjust:100%}
body{margin:0;min-height:100vh;background-color:var(--bg);color:var(--ink);font:17px/1.45 ui-rounded,"Segoe UI",system-ui,-apple-system,Roboto,Helvetica,Arial,sans-serif;
background-image:linear-gradient(rgba(29,36,51,.06) 1px,transparent 1px),linear-gradient(90deg,rgba(29,36,51,.06) 1px,transparent 1px);
background-size:28px 28px,28px 28px;background-position:0 0,1px 0;overflow-x:hidden;-webkit-tap-highlight-color:transparent}
button{font-family:inherit}
#app{min-height:100vh;min-height:100dvh;display:flex;flex-direction:column}
/* header and footer */
.top{display:flex;align-items:center;justify-content:space-between;gap:8px 12px;flex-wrap:wrap;padding:10px 16px;background:#fff;border-bottom:2px solid var(--ink)}
.brand{display:flex;align-items:center;gap:8px;font-weight:900;letter-spacing:.2px}
.brand svg{transform:rotate(4deg);flex:none}
.brand sup{font-size:10px;position:relative;top:2px}
.chip{display:flex;align-items:center;font-size:13px;font-weight:700;color:var(--muted);background:#f0ede4;border:2px solid var(--ink);border-radius:999px;padding:3px 12px;transform:rotate(-1.2deg);max-width:100%}
.dots{display:inline-flex;margin-left:6px}
.dots i{display:inline-block;width:5px;height:5px;border-radius:50%;background:currentColor;margin-left:3px;animation:bounce 1.4s infinite ease-in-out}
.dots i:nth-child(2){animation-delay:.18s}
.dots i:nth-child(3){animation-delay:.36s}
@keyframes bounce{0%,60%,100%{transform:translateY(0)}30%{transform:translateY(-4px)}}
main{flex:1;display:flex;align-items:center;justify-content:center;padding:22px 16px 30px}
footer{display:flex;flex-wrap:wrap;gap:2px 14px;justify-content:center;align-items:center;padding:10px 16px 22px;font-size:13px;color:var(--muted)}
.fl{background:none;border:0;color:inherit;font:inherit;text-decoration:underline;min-height:40px;padding:0 6px;cursor:pointer;touch-action:manipulation}
.fl:nth-of-type(2){position:relative;top:2px}
.fl:nth-of-type(3){position:relative;top:-1px}
/* the card: a straight page on a crooked plate */
.card{position:relative;isolation:isolate;width:min(calc(100% - 8px),600px);left:3px;padding:20px 20px 24px}
.card::before{content:"";position:absolute;inset:0;z-index:-1;background:var(--card);border:2px solid var(--ink);border-radius:20px;box-shadow:6px 7px 0 rgba(29,36,51,.16);transform:rotate(-.5deg)}
.card.sc-final::before{transform:none;background:linear-gradient(180deg,#fffdf8,#eaf2ff)}
.meta{display:flex;justify-content:space-between;gap:4px 10px;flex-wrap:wrap;font-size:13px;font-weight:700;color:var(--muted);margin-bottom:10px}
.meta span:last-child{position:relative;top:1px}
h1,h2{margin:.1em 0 .35em;line-height:1.15;letter-spacing:-.3px}
h1{font-size:clamp(26px,7vw,38px)}
h2{font-size:clamp(23px,6vw,31px)}
.card h1,.card h2{transform:rotate(.4deg);transform-origin:left center}
.card p{margin:.2em 0 .8em;transform:rotate(-.15deg)}
.card.sc-final h1,.card.sc-final h2,.card.sc-final p{transform:none}
.o{position:relative;top:1px;font-style:normal}
.o.u{top:-1px}
.fine{font-size:13px;color:var(--muted);margin:8px 0 0}
.chips{display:flex;flex-wrap:wrap;gap:6px 4px;margin:10px 0 2px}
.chips span{display:inline-block;background:#fff;border:2px solid var(--ink);border-radius:999px;padding:4px 12px;font-size:14px;font-weight:700}
.chips span:nth-child(1){transform:rotate(-2deg)}
.chips span:nth-child(2){transform:translateY(2px) rotate(1.5deg);margin:0 8px 0 3px}
.chips span:nth-child(3){transform:translateY(-1px) rotate(-1deg)}
.row{display:flex;gap:10px;flex-wrap:wrap;margin-top:12px}
/* buttons */
.btn{appearance:none;-webkit-appearance:none;border:0;cursor:pointer;font:inherit;font-weight:800;font-size:18px;min-height:56px;padding:12px 28px;border-radius:14px;background:var(--brand);color:#fff;box-shadow:0 5px 0 var(--brand-d);touch-action:manipulation;user-select:none;-webkit-user-select:none;position:relative;white-space:nowrap}
.btn:active:not(:disabled){transform:translateY(3px);box-shadow:0 2px 0 var(--brand-d)}
.btn.small{min-height:52px;font-size:16px;padding:8px 20px}
.btn.alt{background:var(--acc);color:#2a2100;box-shadow:0 5px 0 var(--acc-d)}
.btn.alt:active:not(:disabled){box-shadow:0 2px 0 var(--acc-d)}
.btn.plain{background:#fff;color:var(--ink);border:2px solid var(--ink);box-shadow:0 4px 0 rgba(29,36,51,.25)}
.btn:disabled{background:#c9c6bd;color:#6c7080;box-shadow:0 5px 0 #a9a69c;cursor:not-allowed}
.dz{min-height:72px;display:flex;justify-content:center;align-items:center;margin:16px 0 4px;position:relative;z-index:5}
.btn.dodger{min-width:210px;z-index:30;transform:translate(var(--dx,0px),var(--dy,0px)) rotate(var(--rot,0deg));transition:transform .38s cubic-bezier(.3,1.35,.5,1)}
.btn.dodger:active:not(:disabled){transform:translate(var(--dx,0px),var(--dy,0px)) rotate(var(--rot,0deg));box-shadow:0 5px 0 var(--brand-d)}
/* cookie notices */
#ov{position:fixed;inset:0;z-index:200;pointer-events:none}
.cookie{position:absolute;width:min(88vw,350px);background:#fff;border:2px solid var(--ink);border-radius:14px;padding:11px 12px 12px;box-shadow:4px 5px 0 rgba(29,36,51,.22);pointer-events:auto;transform:rotate(var(--r,0deg));animation:cpop .22s ease-out both;font-size:14px;line-height:1.35}
.cookie.gone{animation:cgone .2s ease-in both;pointer-events:none}
.cookie.wig{animation:wig .5s ease-in-out}
.chead{display:flex;align-items:center;gap:8px;font-weight:800;margin-bottom:3px}
.cookie p{margin:0 0 8px}
.crow{display:flex;gap:6px;flex-wrap:wrap}
.cbtn{flex:1 1 92px;min-height:46px;border:2px solid var(--ink);background:#fff3c4;border-radius:10px;font:inherit;font-weight:800;font-size:14px;cursor:pointer;touch-action:manipulation;color:var(--ink)}
.cbtn:nth-child(2){background:#e4ecff}
.cbtn:nth-child(3){background:#e3f7ec}
@keyframes cpop{from{opacity:0;transform:rotate(var(--r,0deg)) scale(.88)}to{opacity:1;transform:rotate(var(--r,0deg)) scale(1)}}
@keyframes cgone{to{opacity:0;transform:rotate(var(--r,0deg)) scale(.85)}}
@keyframes wig{0%,100%{transform:rotate(var(--r,0deg))}25%{transform:translateX(-6px) rotate(var(--r,0deg))}75%{transform:translateX(6px) rotate(var(--r,0deg))}}
/* popups */
#dim{position:fixed;inset:0;z-index:150;background:rgba(29,36,51,.38);opacity:0;pointer-events:none;transition:opacity .25s}
#dim.on{opacity:1;pointer-events:auto}
.popup{position:absolute;left:50%;top:calc(50% + var(--y,0px));width:min(88vw,360px);background:#fffef6;border:3px solid var(--ink);border-radius:16px;box-shadow:6px 8px 0 rgba(29,36,51,.25);pointer-events:auto;overflow:hidden;transform:translate(calc(-50% + var(--x,0px)),-50%) rotate(var(--r,0deg));animation:ppop .26s cubic-bezier(.3,1.3,.5,1) both}
.popup.done{pointer-events:none}
.popup.out{animation:pout .3s ease-in both;pointer-events:none}
.pbar{display:flex;justify-content:space-between;gap:8px;background:var(--ink);color:#fff;padding:8px 12px;font-weight:800;font-size:14px}
.pbody{padding:12px 14px 14px}
.pbody p{margin:0 0 12px;font-size:16px;transform:none}
.prow{display:flex;gap:8px}
.prow.v0{justify-content:flex-end}
.prow.v1{justify-content:flex-start}
.prow.v2 .btn{width:100%}
.prow.v3{justify-content:center}
.popup .btn{min-height:52px;font-size:17px;padding:10px 22px}
@keyframes ppop{from{opacity:0;transform:translate(calc(-50% + var(--x,0px)),-44%) rotate(var(--r,0deg)) scale(.9)}to{opacity:1;transform:translate(calc(-50% + var(--x,0px)),-50%) rotate(var(--r,0deg)) scale(1)}}
@keyframes pout{to{opacity:0;transform:translate(calc(-50% + var(--x,0px)),-58%) rotate(var(--r,0deg)) scale(.9)}}
.gift{display:flex;justify-content:center;margin:8px 0}
.gift svg{width:120px;height:auto;transform:rotate(-4deg)}
/* progress */
.pwrap{margin:18px 0 8px}
.ptrack{height:36px;border:3px solid var(--ink);border-radius:12px;background:#fff;overflow:hidden;transform:rotate(-.7deg)}
.ptrack.oops{animation:oops .6s ease-in-out}
.pfill{height:100%;width:0;background:var(--brand);box-shadow:inset 0 -9px 0 rgba(0,0,0,.14)}
.ppct{margin-top:8px;font-size:32px;font-weight:900;text-align:right;position:relative;top:1px;font-variant-numeric:tabular-nums}
@keyframes oops{0%,100%{transform:rotate(-.7deg)}30%{transform:rotate(1.4deg)}60%{transform:rotate(-1.9deg)}}
/* captcha */
.grid{display:grid;grid-template-columns:repeat(3,1fr);gap:12px;width:min(100%,340px);margin:14px auto 8px}
.tile{aspect-ratio:1;border:4px solid var(--ink);border-radius:8px;background:#fffbe8;box-shadow:inset 0 0 0 6px #fff,inset 0 0 0 7px var(--line);padding:0;display:flex;align-items:center;justify-content:center;cursor:pointer;position:relative;touch-action:manipulation;transform:translate(var(--tx,0px),var(--ty,0px)) rotate(var(--a,0deg))}
.tile svg{width:62%;height:62%;display:block}
.tile.good{border-color:var(--ok)}
.tile.good::after{content:"\2713";position:absolute;right:5px;top:-1px;font-size:26px;color:var(--ok);font-weight:900}
.tile.wince{animation:wince .45s ease-in-out}
.grid.hint .tile[data-ok]{outline:4px solid var(--ok);outline-offset:3px}
@keyframes wince{0%,100%{transform:translate(var(--tx,0px),var(--ty,0px)) rotate(var(--a,0deg))}30%{transform:translate(calc(var(--tx,0px) - 5px),var(--ty,0px)) rotate(calc(var(--a,0deg) - 4deg))}65%{transform:translate(calc(var(--tx,0px) + 5px),var(--ty,0px)) rotate(calc(var(--a,0deg) + 4deg))}}
.cmsg{min-height:2.6em;text-align:center;font-weight:700}
/* terms */
.terms{height:200px;overflow-y:auto;-webkit-overflow-scrolling:touch;overscroll-behavior:contain;border:3px solid var(--ink);border-radius:12px;background:#fff;padding:10px 12px;font-size:15px;transform:rotate(.35deg);margin:8px 0}
.terms p{margin:0 0 10px;transform:none}
/* final screen */
.final{text-align:center;position:relative}
.rosette{width:112px;height:auto;margin:4px auto 0;display:block;animation:bob 5s ease-in-out infinite}
@keyframes bob{50%{transform:translateY(-6px)}}
.fs{position:absolute;color:#e0ad00;font-style:normal;font-size:22px;opacity:.55;pointer-events:none;animation:floaty 7s ease-in-out infinite}
.fs:nth-of-type(2){animation-duration:9s;animation-delay:-3s}
.fs:nth-of-type(3){animation-duration:8s;animation-delay:-5s}
@keyframes floaty{50%{transform:translateY(-10px) rotate(10deg)}}
.stats{display:grid;grid-template-columns:repeat(2,1fr);gap:10px;margin:16px 0 8px;text-align:left}
.stat{background:#fff;border:2px solid var(--ink);border-radius:12px;padding:8px 12px}
.stat b{display:block;font-size:26px;line-height:1.1}
.stat span{font-size:13px;color:var(--muted)}
.rate{display:flex;justify-content:center;gap:2px;margin-top:6px}
.star{font-size:36px;min-width:52px;min-height:52px;background:none;border:0;cursor:pointer;color:#c9c2a8;line-height:1;touch-action:manipulation}
.star.on{color:#e0ad00}
/* toast, cursors, demo */
#toast{position:fixed;left:50%;top:14px;transform:translate(-50%,-16px) rotate(-.8deg);background:var(--ink);color:#fff;padding:10px 16px;border-radius:12px;font-weight:700;font-size:15px;max-width:min(92vw,420px);text-align:center;opacity:0;pointer-events:none;transition:opacity .25s,transform .25s;z-index:500}
#toast.show{opacity:1;transform:translate(-50%,0) rotate(-.8deg)}
#twin{position:fixed;left:0;top:0;z-index:700;pointer-events:none;opacity:0;transition:opacity .3s;will-change:transform}
#ghost{position:fixed;left:0;top:0;z-index:650;pointer-events:none;opacity:0;transform:translate(-100px,-100px);filter:drop-shadow(0 2px 3px rgba(0,0,0,.3))}
#ghost .ring{position:absolute;left:-17px;top:-17px;width:34px;height:34px;border:3px solid var(--brand);border-radius:50%;opacity:0}
#ghost.tap .ring{animation:ring .55s ease-out}
@keyframes ring{0%{transform:scale(.4);opacity:.9}100%{transform:scale(1.6);opacity:0}}
#demoBadge{display:none;position:fixed;left:50%;bottom:8px;transform:translateX(-50%);z-index:660;background:var(--ink);color:#fff;font-size:13px;font-weight:800;padding:6px 14px;border-radius:999px;pointer-events:none;white-space:nowrap}
body.demo #demoBadge{display:block}
body.demo #twin{display:none}
@media (max-width:420px){.card{padding:16px 14px 20px}.btn{padding:12px 20px}.btn.dodger{min-width:190px}}
@media (prefers-reduced-motion:reduce){
*,*::before,*::after{animation-duration:.001ms!important;animation-iteration-count:1!important;transition-duration:.001ms!important}
}
</style>
</head>
<body>
<div id="app">
<header class="top">
<div class="brand">
<svg width="30" height="30" viewBox="0 0 30 30" aria-hidden="true"><rect x="2" y="2" width="26" height="26" rx="6" fill="#2f55d4"/><path d="M9 21 V9 L21 21 V9" fill="none" stroke="#fff" stroke-width="3.2" stroke-linecap="round" stroke-linejoin="round"/></svg>
<span class="jit">Totally Normal Corp</span><sup>TM</sup>
</div>
<div class="chip"><span id="chat">Support is typing</span><span class="dots" aria-hidden="true"><i></i><i></i><i></i></span></div>
</header>
<main><section class="card" id="card" aria-live="polite"><noscript>This page needs JavaScript in order to be uncomfortable.</noscript></section></main>
<footer>
<span class="jit">© 2O26 Totally Normal Corp. All rights reserved, mostly.</span>
<button class="fl" type="button" data-t="That link goes nowhere. Thank you for clicking.">Privacy</button>
<button class="fl" type="button" data-t="The terms are on step 5. Or 6.">Terms</button>
<button class="fl" type="button" data-t="Our crookedness policy allows up to 3 degrees.">Crookedness policy</button>
<button class="fl" type="button" id="snd">Sound: on</button>
</footer>
</div>
<div id="dim"></div>
<div id="ov"></div>
<div id="toast" role="status"></div>
<div id="twin" aria-hidden="true"><svg width="22" height="26" viewBox="0 0 22 26"><path d="M2 2 L2 21 L7 16.5 L10.5 24 L14 22.5 L10.5 15 L17 15 Z" fill="#ff8a1f" stroke="#1d2433" stroke-width="1.6" stroke-linejoin="round"/></svg></div>
<div id="ghost" aria-hidden="true"><span class="ring"></span><svg width="28" height="34" viewBox="0 0 28 34"><path d="M2 2 L2 27 L8.5 21.5 L13 31.5 L18 29.3 L13.5 19.5 L22 19.5 Z" fill="#fff" stroke="#2f55d4" stroke-width="2.4" stroke-linejoin="round"/></svg></div>
<div id="demoBadge">Demo · touch anywhere to take over</div>
<script>
(function(){
'use strict';
/* ---------- helpers ---------- */
const $=s=>document.querySelector(s);
const esc=s=>String(s).replace(/[&<>"']/g,c=>({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]));
const rnd=(a,b)=>a+Math.random()*(b-a);
const sleep=ms=>new Promise(r=>setTimeout(r,ms));
const sget=k=>{try{return window.localStorage.getItem(k);}catch(e){return null;}};
const sset=(k,v)=>{try{window.localStorage.setItem(k,v);}catch(e){}};
const isDemoUrl=()=>{try{return location.hash==='#demo'||/#demo$/.test(location.href);}catch(e){return false;}};
const fmtTime=ms=>{const s=Math.max(0,Math.round(ms/1000));return Math.floor(s/60)+':'+String(s%60).padStart(2,'0');};
const shuffle=a=>{a=a.slice();for(let i=a.length-1;i>0;i--){const j=Math.floor(Math.random()*(i+1));const t=a[i];a[i]=a[j];a[j]=t;}return a;};
const easeUp=k=>1-Math.pow(1-k,1.7);
const easeIO=k=>k*k*(3-2*k);
/* ---------- state ---------- */
let DEMO=isDemoUrl(),DEMOID=0,TOKEN=0;
let S={},cfg={};
let dg={el:null,left:0,tx:0,ty:0,last:0};
let cookieAlive=0,cookieBudget=0,cookieSeq=0,pSpeed=1,swallowUntil=0,soundOn=true,AC=null,lastSfx=0,toastT=0;
let gx=0,gy=0;
const card=$('#card'),ov=$('#ov'),dim=$('#dim'),toastEl=$('#toast'),ghost=$('#ghost'),twin=$('#twin');
function newState(){return {dodges:0,cookies:0,closes:0,rewinds:0,wrong:0,t0:performance.now(),scene:''};}
function makeCfg(){
if(DEMO){
return {dodges:2,cookieBudget:4,popOrder:[0,2,4],runs:[
{dur:1200,holdMs:600,back:35,backDur:400,go:'Verifying your patience…',hold:['99%. Almost there…','99%. Just one tiny thing…'],rew:'A pixel is missing. Rewinding.'},
{dur:700,holdMs:300,back:null,go:'Trying again, faster…',hold:['99%…','99%…']}
]};
}
return {dodges:5,cookieBudget:6,popOrder:[0,1,2,3,4],runs:[
{dur:4200,holdMs:1700,back:38,backDur:1000,go:'Verifying your patience…',hold:['99%. Almost there…','99%. Just one more tiny thing…'],rew:'Found a missing pixel. Rewinding, to be safe.'},
{dur:2800,holdMs:1400,back:71,backDur:800,go:'Verifying again (this time it is faster)…',hold:['99%. We promise.','99%. The 1 was upside down.'],rew:'The 1 was upside down. Rewinding.'},
{dur:1800,holdMs:1900,back:null,go:'Third time lucky…',hold:['99%…','99%… still 99%…']}
]};
}
/* ---------- content ---------- */
const META={
welcome:['Step 1 of 5','About 2 minutes left'],
progress:['Step 2 of 4','About 3 minutes left'],
popups:['Step 3 of 6','About 1 minute left (it was 4)'],
captcha:['Step 4 of 5','About 47 seconds left'],
terms:['Step 5 of 5','About 12 seconds left, give or take 40'],
final:['Step 6 of 5','Nothing left. Truly.']
};
const COOK=[
'We use cookies to make this page feel more normal. Please accept all of them.',
'This notice is a cookie about cookies. Please accept it.',
'You clicked! Here are two more, as a thank-you.',
'Your cookie choices are stored in another cookie.',
'Would you like fries with that cookie? (Not available.)',
'Cookie consent for the cookie consent. It is cookies all the way down.',
'Fun fact: this banner is slightly crooked. You are welcome.',
'Last cookie notice. (We said that earlier too.)'
];
const POPS=[
{t:'Special offer!',m:'You won a free extended warranty for something you do not own.'},
{t:'Are you sure?',m:'Closing this means missing out on nothing at all. Still want to close it?'},
{t:'Confirm closing',m:'Please close this window to confirm that you closed the previous window.'},
{t:'Almost closed',m:'Close this to close the thing that closes the other thing.'},
{t:'Last popup. Promise.',m:'We counted. This is the final one. Probably.'}
];
const DLAB=['Too slow!','Missed me!','Nope.','Hah! Again?','Almost…'];
const MOODS=['shy','playful','smug','giggly','winded'];
const WRONG=[
'That one is off by 2.4 degrees. We measured.',
'Close! Everything is crooked, though.',
'Nope. That frame is leaning on purpose.',
'That frame has opinions about gravity.'
];
const CHAT=['Support is typing','Support is still typing','Support is thinking about typing','Support has written a very long message (not yet)','Support is typing… again'];
const TERMS=[
'1. By reading this sentence you agree to everything in it, including this sentence.',
'2. The Company promises that all buttons are exactly where they are. Until they are not.',
'3. Any text that appears one pixel off is a feature and was measured by a professional.',
'4. You agree to keep your hands, paws and tails away from the Close button.',
'5. Cookies are not included. Neither is milk.',
'6. The honesty of the progress bar is limited to 99%.',
'7. We may rotate things by up to 3 degrees without notice. Or with notice, slightly off.',
'8. Tidy items shall be considered tidy-ish.'
];
const TERMS_EXT=[
['8(b). The previous section continues here, but wider.','9. This is a section about sections.','10. Please hold while we look for the end.'],
['10(b). The end is near. Shortly.','11. You are doing great. Keep scrolling.','12. This clause is intentionally left almost blank.'],
['13. This is the end. Probably. The really real end of the terms. Thank you for reading. Nobody does.']
];
const ICONS=[
'<svg viewBox="0 0 48 48"><circle cx="32" cy="15" r="6" fill="#f5b700"/><path d="M4 42 L18 22 L28 35 L34 29 L44 42 Z" fill="#2f8f6b"/></svg>',
'<svg viewBox="0 0 48 48"><path d="M7 24 L24 9 L41 24 V41 H7 Z" fill="#e4572e"/><rect x="20" y="28" width="8" height="13" fill="#fff4d6"/></svg>',
'<svg viewBox="0 0 48 48"><rect x="22" y="28" width="5" height="14" fill="#7a4b24"/><circle cx="24.5" cy="20" r="12" fill="#3aa35c"/></svg>',
'<svg viewBox="0 0 48 48"><path d="M13 36 a8 8 0 0 1 1 -16 a10 10 0 0 1 19 3 a7 7 0 0 1 0 13 Z" fill="#7aa7e8"/></svg>',
'<svg viewBox="0 0 48 48"><ellipse cx="22" cy="24" rx="15" ry="10" fill="#f08a24"/><path d="M34 24 L45 14 V34 Z" fill="#f08a24"/><circle cx="13" cy="22" r="2.2" fill="#1d2433"/></svg>',
'<svg viewBox="0 0 48 48"><polygon points="24,5 29.5,18 43,19 33,28 36,42 24,35 12,42 15,28 5,19 18.5,18" fill="#f5b700"/></svg>',
'<svg viewBox="0 0 48 48"><path d="M9 13 H33 V30 a8 8 0 0 1 -8 8 H17 a8 8 0 0 1 -8 -8 Z" fill="#8c5ad8"/><path d="M33 17 h4 a5 5 0 0 1 0 11 h-4" fill="none" stroke="#8c5ad8" stroke-width="3"/></svg>',
'<svg viewBox="0 0 48 48"><circle cx="22" cy="24" r="15" fill="#4a5fc1"/><circle cx="30" cy="19" r="13" fill="#fffbe8"/></svg>',
'<svg viewBox="0 0 48 48"><path d="M24 41 L7 24 a9.5 9.5 0 0 1 17 -8 a9.5 9.5 0 0 1 17 8 Z" fill="#d6455d"/></svg>'
];
const COOKIE_ICON='<svg width="22" height="22" viewBox="0 0 24 24" aria-hidden="true"><circle cx="12" cy="12" r="10" fill="#d9a05b" stroke="#1d2433" stroke-width="1.6"/><circle cx="8" cy="9" r="1.6" fill="#5b3a1a"/><circle cx="15" cy="8" r="1.4" fill="#5b3a1a"/><circle cx="14" cy="15" r="1.8" fill="#5b3a1a"/><circle cx="8" cy="15" r="1.3" fill="#5b3a1a"/></svg>';
/* ---------- small utilities ---------- */
function toast(m){
toastEl.textContent=m;toastEl.classList.add('show');
clearTimeout(toastT);toastT=setTimeout(()=>toastEl.classList.remove('show'),2300);
}
// wrap some characters so they sit exactly one pixel off
function jit(root){
root.querySelectorAll('.jit').forEach(el=>{
if(el.dataset.j)return;el.dataset.j='1';
const txt=el.textContent;
el.setAttribute('aria-label',txt);
let out='',n=0;
for(const ch of txt){
n++;
if(ch!==' '&&(n%9===4||(n%5===2&&Math.random()<.5)))out+='<i class="o'+(n%2?'':' u')+'">'+esc(ch)+'</i>';
else out+=esc(ch);
}
el.innerHTML=out;
});
}
// very quiet, soft blips; only after a real tap, never in demo
function sfx(kind){
const now=performance.now();
if(!soundOn||DEMO||!AC||AC.state!=='running'||now-lastSfx<70)return;
lastSfx=now;
try{
const t=AC.currentTime,o=AC.createOscillator(),g=AC.createGain();
const f={dodge:[520,340],pop:[400,520],bad:[320,240],ok:[440,660],tick:[600,600]}[kind]||[440,440];
o.type='sine';
o.frequency.setValueAtTime(f[0],t);o.frequency.linearRampToValueAtTime(f[1],t+.14);
g.gain.setValueAtTime(.0001,t);g.gain.linearRampToValueAtTime(.045,t+.04);g.gain.exponentialRampToValueAtTime(.0001,t+.26);
o.connect(g);g.connect(AC.destination);o.start(t);o.stop(t+.3);
}catch(e){}
}
function tween(a,b,ms,fn,tk,ease){
return new Promise(res=>{
const t0=performance.now();
const step=()=>{
if(tk!==TOKEN)return res(false);
const k=Math.min(1,(performance.now()-t0)/Math.max(1,ms));
fn(a+(b-a)*ease(k));
if(k<1)setTimeout(step,33);else res(true);
};
step();
});
}
const sleepTk=async(ms,tk)=>{await sleep(ms);return tk===TOKEN;};
/* ---------- scene management ---------- */
const ORDER=['welcome','progress','popups','captcha','terms','final'];
function clearOverlays(){ov.innerHTML='';dim.classList.remove('on');}
function go(name){
TOKEN++;const tk=TOKEN;
clearOverlays();dg.el=null;
S.scene=name;
const sc=SC[name],m=META[name];
card.className='card sc-'+name;
card.innerHTML='<div class="meta"><span>'+esc(m[0])+'</span><span>'+esc(m[1])+'</span></div>'+sc.html();
jit(card);
try{window.scrollTo(0,0);}catch(e){}
try{card.animate([{opacity:0,transform:'translateY(8px)'},{opacity:1,transform:'none'}],{duration:260,easing:'ease-out'});}catch(e){}
sc.init(tk);
}
function next(){
let i=ORDER.indexOf(S.scene)+1;
if(DEMO&&ORDER[i]==='terms')i++;
go(ORDER[Math.min(i,ORDER.length-1)]);
}
function resetAll(){
TOKEN++;
S=newState();cfg=makeCfg();
go('welcome');
}
/* ---------- scene 1: welcome, shy button, multiplying cookies ---------- */
function updateStatus(){
const c=$('#ccount'),m=$('#mood');
if(c)c.textContent=cookieAlive;
if(m){const used=cfg.dodges-dg.left;m.textContent=dg.left===0?'resigned':MOODS[Math.min(used,MOODS.length-1)];}
}
function dodge(px,py){
const el=dg.el;if(!el||dg.left<=0)return;
const now=performance.now();if(now-dg.last<420)return;dg.last=now;
const r=el.getBoundingClientRect(),w=r.width,h=r.height,vw=window.innerWidth,vh=window.innerHeight;
const cx=r.left+w/2-dg.tx,cy=r.top+h/2-dg.ty;
const mx=Math.min(14+w/2,vw/2),top=Math.min(74+h/2,vh/2),bot=Math.min(14+h/2,vh/2);
const cands=[];let best={X:vw/2,Y:vh/2},bd=-1;
for(let i=0;i<30;i++){
const X=rnd(mx,Math.max(mx,vw-mx)),Y=rnd(top,Math.max(top,vh-bot));
const d=Math.hypot(X-px,Y-py);
if(d>=190)cands.push({X:X,Y:Y});
if(d>bd){bd=d;best={X:X,Y:Y};}
}
const t=cands.length?cands[Math.floor(Math.random()*cands.length)]:best;
dg.tx=t.X-cx;dg.ty=t.Y-cy;dg.left--;S.dodges++;
el.style.setProperty('--dx',dg.tx.toFixed(1)+'px');
el.style.setProperty('--dy',dg.ty.toFixed(1)+'px');
el.style.setProperty('--rot',(dg.left===0?-2:rnd(-9,9)).toFixed(1)+'deg');
const used=cfg.dodges-dg.left;
el.textContent=dg.left>0?DLAB[(used-1)%DLAB.length]:'Okay. You win.';
sfx('dodge');updateStatus();
}
function spawnCookie(){
const id=cookieSeq++;
const el=document.createElement('div');el.className='cookie';
const w=Math.min(window.innerWidth*.88,350);
const left=8+Math.random()*Math.max(0,window.innerWidth-w-16);
const bottom=8+Math.random()*Math.min(200,window.innerHeight*.3);
el.style.left=left.toFixed(0)+'px';el.style.bottom=bottom.toFixed(0)+'px';
el.style.setProperty('--r',rnd(-2.6,2.6).toFixed(2)+'deg');
el.style.zIndex=String(100+id);
const labels=shuffle(['Accept all','Reject all','Settings']);
el.innerHTML='<div class="chead">'+COOKIE_ICON+'<span>Cookie notice #'+(id+1)+'</span></div><p>'+esc(COOK[id%COOK.length])+'</p><div class="crow">'+
labels.map(l=>'<button class="cbtn" type="button">'+l+'</button>').join('')+'</div>';
el.querySelectorAll('.cbtn').forEach(b=>b.addEventListener('click',()=>cookieAct(el)));
ov.appendChild(el);
}
function cookieAct(el){
if(el.dataset.gone)return;el.dataset.gone='1';
S.cookies++;sfx('pop');
cookieAlive--;
el.classList.add('gone');setTimeout(()=>{if(el.parentNode)el.parentNode.removeChild(el);},230);
const n=Math.min(2,cookieBudget);cookieBudget-=n;cookieAlive+=n;
const tk=TOKEN;
for(let i=0;i<n;i++)setTimeout(()=>{if(tk===TOKEN)spawnCookie();},160+i*170);
updateStatus();
if(cookieAlive===0)toast('All cookie notices dealt with. For now.');
}
function nudgeCookies(){
ov.querySelectorAll('.cookie').forEach(c=>{c.classList.add('wig');setTimeout(()=>c.classList.remove('wig'),520);});
}
/* ---------- scene 2: the progress bar ---------- */
async function runProgress(tk){
const fill=$('#pfill'),pct=$('#ppct'),note=$('#pnote'),track=$('#ptrack');
let cur=0;
const set=v=>{cur=v;fill.style.width=v+'%';pct.textContent=Math.floor(v+0.001)+'%';};
set(0);
if(!await sleepTk(DEMO?200:500,tk))return;
for(const r of cfg.runs){
if(tk!==TOKEN)return;
note.textContent=r.go;
if(!await tween(cur,99,r.dur*pSpeed,set,tk,easeUp))return;
note.textContent=r.hold[0];
if(!await sleepTk(r.holdMs/2,tk))return;
note.textContent=r.hold[1];
if(!await sleepTk(r.holdMs/2,tk))return;
if(r.back!==null){
note.textContent=r.rew;S.rewinds++;sfx('bad');
track.classList.add('oops');setTimeout(()=>track.classList.remove('oops'),650);
if(!await tween(99,r.back,r.backDur,set,tk,easeIO))return;
if(!await sleepTk(DEMO?100:350,tk))return;
}else{
if(!await tween(99,100,350,set,tk,easeIO))return;
note.textContent='100%. Patience verified. Thank you!';sfx('ok');
if(await sleepTk(DEMO?300:900,tk))next();
return;
}
}
}
/* ---------- scene 3: the Close button that spawns a Close button ---------- */
function spawnPopup(idx){
const order=cfg.popOrder,m=POPS[order[idx]],last=idx===order.length-1;
const el=document.createElement('div');el.className='popup';
el.style.setProperty('--r',rnd(-3.2,3.2).toFixed(2)+'deg');
el.style.setProperty('--x',Math.round(rnd(-22,22))+'px');
el.style.setProperty('--y',Math.round(rnd(-28,28))+'px');
el.style.zIndex=String(300+idx);
const extra=(idx%2===1&&!last)?'<button class="btn plain small later" type="button">Maybe later</button>':'';
el.innerHTML='<div class="pbar"><span>'+esc(m.t)+'</span><span>#'+(idx+1)+'</span></div><div class="pbody"><p>'+esc(m.m)+'</p><div class="prow v'+(idx%4)+'"><button class="btn close" type="button">'+(last?'Close (for real)':'Close')+'</button>'+extra+'</div></div>';
el.querySelectorAll('.btn').forEach(b=>b.addEventListener('click',()=>popClick(el,idx)));
ov.appendChild(el);
}
function popClick(el,idx){
if(el.classList.contains('done'))return;
el.classList.add('done');S.closes++;sfx('pop');
const last=idx===cfg.popOrder.length-1;
if(!last){spawnPopup(idx+1);return;}
sfx('ok');
const tk=TOKEN;
const list=Array.prototype.slice.call(ov.querySelectorAll('.popup')).reverse();
list.forEach((p,i)=>setTimeout(()=>p.classList.add('out'),i*120));
setTimeout(()=>{if(tk===TOKEN)dim.classList.remove('on');},list.length*120+120);
setTimeout(()=>{if(tk===TOKEN){ov.innerHTML='';next();}},list.length*120+560);
}
/* ---------- scenes ---------- */
const SC={
welcome:{
html:()=>'<h1 class="jit">Welcome! Everything here is completely normal.</h1>'+
'<p class="jit">To collect your reward, please complete a few quick steps. It might be five. It might be six.</p>'+
'<div class="chips"><span>100% aligned*</span><span>Cookie-friendly</span><span>Zero crooked things**</span></div>'+
'<p class="fine">*Approximately. **See: crooked things.</p>'+
'<div class="dz"><button class="btn dodger" id="cont" type="button">Continue</button></div>'+
'<p class="fine">Button mood: <b id="mood">shy</b> · Cookie notices pending: <b id="ccount">1</b></p>',
init(tk){
dg={el:$('#cont'),left:cfg.dodges,tx:0,ty:0,last:0};
cookieAlive=1;cookieBudget=cfg.cookieBudget;cookieSeq=0;
const el=dg.el;
el.addEventListener('pointerdown',e=>{if(dg.left>0){e.preventDefault();dodge(e.clientX,e.clientY);}});
el.addEventListener('click',e=>{
if(dg.left>0){dodge(e.clientX||window.innerWidth/2,e.clientY||window.innerHeight/2);return;}
if(cookieAlive>0){nudgeCookies();toast('Cookie notices first. They insist.');return;}
sfx('ok');next();
});
updateStatus();
setTimeout(()=>{if(tk===TOKEN)spawnCookie();},DEMO?250:900);
}
},
progress:{
html:()=>'<h2 class="jit">Verifying your patience</h2>'+
'<p id="pnote" aria-live="polite">Warming up…</p>'+
'<div class="pwrap"><div class="ptrack" id="ptrack"><div class="pfill" id="pfill"></div></div><div class="ppct" id="ppct">0%</div></div>'+
'<div class="row"><button class="btn alt small" id="faster" type="button">Make it faster</button><button class="btn plain small" id="cancel" type="button">Cancel</button></div>'+
'<p class="fine">Please keep this page open. Your patience is being measured with a very small ruler.</p>',
init(tk){
pSpeed=1;
$('#faster').addEventListener('click',()=>{pSpeed=Math.min(2,pSpeed*1.4);toast('Making it faster… (it is now slightly slower)');sfx('tick');});
$('#cancel').addEventListener('click',()=>{toast('Cancel is unavailable while your patience is being verified.');sfx('bad');});
runProgress(tk);
}
},
popups:{
html:()=>'<h2 class="jit">Your reward is almost ready</h2>'+
'<p>We are preparing a very real reward for a very real person.</p>'+
'<div class="gift"><svg viewBox="0 0 120 110" aria-hidden="true"><rect x="14" y="44" width="92" height="58" rx="6" fill="#e4572e" stroke="#1d2433" stroke-width="3"/><rect x="8" y="30" width="104" height="22" rx="6" fill="#ff7a4d" stroke="#1d2433" stroke-width="3"/><rect x="53" y="30" width="14" height="72" fill="#ffd23f" stroke="#1d2433" stroke-width="3"/><path d="M60 30 C40 6 18 18 34 30 Z M60 30 C80 6 102 18 86 30 Z" fill="#ffd23f" stroke="#1d2433" stroke-width="3" stroke-linejoin="round"/></svg></div>'+
'<p class="fine">Please do not close this page. Or do. Whatever.</p>',
init(tk){
setTimeout(()=>{if(tk===TOKEN){dim.classList.add('on');spawnPopup(0);}},DEMO?350:900);
}
},
captcha:{
html:()=>'<h2 class="jit">Prove you are human</h2>'+
'<p>Tap the <b>one picture frame that is perfectly straight</b>.</p>'+
'<div class="grid" id="grid"></div>'+
'<p class="cmsg" id="cmsg" aria-live="polite">Tip: it will be the tidy one.</p>',
init(tk){
let miss=0,locked=false,hinted=false;
const grid=$('#grid'),msg=$('#cmsg');
const say=t=>{msg.textContent=t;};
const build=()=>{
grid.innerHTML='';
const okIdx=Math.floor(Math.random()*9),ic=shuffle([0,1,2,3,4,5,6,7,8]);
for(let i=0;i<9;i++){
const straight=i===okIdx,b=document.createElement('button');
b.type='button';b.className='tile';
const a=straight?0:(Math.random()<.5?-1:1)*rnd(2.6,5.8);
b.style.setProperty('--a',a.toFixed(2)+'deg');
b.style.setProperty('--tx',(straight?0:rnd(-3,3)).toFixed(1)+'px');
b.style.setProperty('--ty',(straight?0:rnd(-3,3)).toFixed(1)+'px');
if(straight)b.dataset.ok='1';
b.setAttribute('aria-label','Picture frame '+(i+1));
b.innerHTML=ICONS[ic[i]];
b.addEventListener('click',()=>tap(b,straight));
grid.appendChild(b);
}
};
const tap=(b,ok)=>{
if(locked)return;
if(ok){
locked=true;sfx('ok');b.classList.add('good');
say('Straight! Suspiciously straight. Human confirmed.');
setTimeout(()=>{if(tk===TOKEN)next();},DEMO?600:1100);
return;
}
miss++;S.wrong++;sfx('bad');
b.classList.add('wince');setTimeout(()=>b.classList.remove('wince'),460);
say(WRONG[(miss-1)%WRONG.length]);
if(miss>=3&&!hinted){hinted=true;grid.classList.add('hint');say('Hint: the straight one is outlined in green. We feel bad now.');return;}
if(!hinted){
locked=true;
setTimeout(()=>{if(tk===TOKEN){build();locked=false;}},DEMO?450:700);
}
};
build();
}
},
terms:{
html:()=>'<h2 class="jit">Terms of Service</h2>'+
'<p>Scroll to the end to accept. We will tell you when it ends.</p>'+
'<div class="terms" id="terms" tabindex="0">'+TERMS.map(t=>'<p>'+esc(t)+'</p>').join('')+'</div>'+
'<p class="fine" id="tmsg" aria-live="polite">Scroll down to read the terms.</p>'+
'<div class="row"><button class="btn" id="agree" type="button" disabled>I agree</button><button class="btn plain" id="sbtn" type="button">Scroll for me</button></div>',
init(tk){
const box=$('#terms'),agree=$('#agree'),tmsg=$('#tmsg');
let ext=0;
const check=()=>{
if(tk!==TOKEN)return;
if(box.scrollTop+box.clientHeight>=box.scrollHeight-6){
if(ext<TERMS_EXT.length){
TERMS_EXT[ext].forEach(t=>{const p=document.createElement('p');p.textContent=t;box.appendChild(p);});
ext++;tmsg.textContent='The terms grew a little. Keep scrolling.';
}else{
agree.disabled=false;tmsg.textContent='That was the end. Really.';
}
}
};
box.addEventListener('scroll',check,{passive:true});
$('#sbtn').addEventListener('click',()=>{
try{box.scrollBy({top:150,behavior:'smooth'});}catch(e){box.scrollTop+=150;}
});
agree.addEventListener('click',()=>{sfx('ok');next();});
}
},
final:{
html:()=>{
const el=performance.now()-S.t0;
let rec='';
if(!DEMO){
const prev=parseFloat(sget('uncomfortable-best')||'');
if(!prev||el<prev){sset('uncomfortable-best',String(Math.round(el)));rec=prev?'New personal best for patience!':'First visit. Welcome to the family.';}
else rec='Your best patience so far: '+fmtTime(prev)+'.';
}
const st=(v,l)=>'<div class="stat"><b>'+esc(v)+'</b><span>'+esc(l)+'</span></div>';
return '<div class="final">'+
'<i class="fs" style="left:5%;top:10%">✦</i><i class="fs" style="right:6%;top:22%">✦</i><i class="fs" style="left:12%;top:46%">✦</i>'+
'<svg class="rosette" viewBox="0 0 120 140" aria-hidden="true"><path d="M38 78 L24 132 L46 120 L58 138 L66 84 Z" fill="#2f55d4"/><path d="M82 78 L96 132 L74 120 L62 138 L54 84 Z" fill="#1b3796"/><circle cx="60" cy="54" r="44" fill="#ffd23f" stroke="#1d2433" stroke-width="3"/><circle cx="60" cy="54" r="33" fill="none" stroke="#1d2433" stroke-width="2" stroke-dasharray="3 5"/><path d="M44 56 l11 12 l22 -26" fill="none" stroke="#1d2433" stroke-width="7" stroke-linecap="round" stroke-linejoin="round"/></svg>'+
'<h1>Thank you for your pat<span class="o">i</span>ence.</h1>'+
'<p>Everything is now perfectly aligned. Perfectly. (One letter is not. We could not resist.)</p>'+
'<div class="stats">'+st(fmtTime(el),'Time spent being patient')+st(String(S.dodges),'Shy-button dodges')+st(String(S.cookies),'Cookie notices dealt with')+st(String(S.closes),'Close buttons pressed')+st(String(S.rewinds),'Progress bar rewinds')+st(String(S.wrong),'Crooked frames mistaken')+'</div>'+
'<p class="fine">'+esc(rec)+'</p>'+
'<div class="rate" role="group" aria-label="Rate your experience">'+[1,2,3,4,5].map(n=>'<button class="star" type="button" data-n="'+n+'" aria-label="'+n+' stars">★</button>').join('')+'</div>'+
'<p class="fine" id="rmsg" aria-live="polite">How was your stay? Tap a star.</p>'+
'<div class="row" style="justify-content:center"><button class="btn" id="again" type="button">Do it all again</button></div>'+
'</div>';
},
init(tk){
document.querySelectorAll('.star').forEach(b=>b.addEventListener('click',()=>{
const n=parseInt(b.dataset.n,10);
document.querySelectorAll('.star').forEach(s=>s.classList.add('on'));
$('#rmsg').textContent='You gave '+n+'. We rounded it up to 5. Thank you for your patience.';
sfx('ok');
}));
$('#again').addEventListener('click',()=>{sfx('pop');resetAll();});
}
}
};
/* ---------- hands-free demo (#demo) ---------- */
const live=id=>DEMO&&id===DEMOID;
const dw=async(id,ms)=>{await sleep(ms);return live(id);};
function ghostTo(x,y,ms){
gx=x;gy=y;
ghost.style.transition='transform '+ms+'ms cubic-bezier(.45,.05,.25,1), opacity .3s';
ghost.style.transform='translate('+x.toFixed(1)+'px,'+y.toFixed(1)+'px)';
ghost.style.opacity='1';
}
function tapRing(){ghost.classList.remove('tap');void ghost.offsetWidth;ghost.classList.add('tap');}
async function gMove(id,el,ms,dx,dy){
const r=el.getBoundingClientRect();
ghostTo(r.left+r.width/2+(dx||0),r.top+r.height/2+(dy||0),ms);
return dw(id,ms);
}
async function gTap(id,el,ms){
if(!el)return live(id);
if(!await gMove(id,el,ms))return false;
tapRing();
if(!await dw(id,170))return false;
el.click();
return true;
}
async function waitScene(id,name,max){
const t0=performance.now();
while(live(id)&&S.scene!==name&&performance.now()-t0<max)await sleep(80);
return live(id)&&S.scene===name;
}
async function demoLoop(id){
while(live(id)){
resetAll();
ghostTo(window.innerWidth*.62,window.innerHeight*.55,0);
if(!await dw(id,800))return;
// 1. cookie notices multiply
for(let i=0;i<10&&cookieAlive>0;i++){
const cs=ov.querySelectorAll('.cookie:not(.gone)');
if(!cs.length){if(!await dw(id,120))return;continue;}
const c=cs[cs.length-1];
if(!await gTap(id,c.querySelector('.cbtn'),i===0?700:(i<2?380:220)))return;
if(!await dw(id,i===0?350:(i<2?300:80)))return;
}
if(!live(id))return;
// 2. the shy Continue button
const cont=$('#cont');
if(cont){
for(let i=0;i<cfg.dodges;i++){
if(!await gMove(id,cont,i===0?800:600,-20,-8))return;
dodge(gx,gy);
if(!await dw(id,560))return;
}
if(!await gTap(id,cont,700))return;
}
// 3. progress bar that rewinds at 99 percent
if(!await waitScene(id,'popups',16000))return;
// 4. Close spawns another Close
if(!await dw(id,650))return;
let tries=0;
for(let i=0;i<cfg.popOrder.length&&tries<20;){
const ps=ov.querySelectorAll('.popup:not(.done):not(.out)');
const p=ps[ps.length-1];
if(!p){tries++;if(!await dw(id,150))return;continue;}
if(!await gTap(id,p.querySelector('.close'),i===0?650:400))return;
if(!await dw(id,i<2?300:100))return;
i++;
}
// 5. crooked frames
if(!await waitScene(id,'captcha',5000))return;
if(!await dw(id,450))return;
const wrong=Array.prototype.slice.call(document.querySelectorAll('#grid .tile')).filter(t=>!t.dataset.ok)[0];
if(!await gTap(id,wrong,700))return;
if(!await dw(id,700))return;
const right=document.querySelector('#grid .tile[data-ok]');
if(!await gTap(id,right,600))return;
// 6. the thank-you screen
if(!await waitScene(id,'final',3000))return;
ghost.style.opacity='0';
if(!await dw(id,2200))return;
}
}
function startDemo(){
DEMO=true;
document.body.classList.add('demo');
const id=++DEMOID;
const run=()=>{demoLoop(id).catch(()=>{if(live(id))setTimeout(run,500);});};
run();
}
function endDemo(){
if(!DEMO)return;
DEMO=false;DEMOID++;
document.body.classList.remove('demo');
ghost.style.opacity='0';
resetAll();
}
/* ---------- global events ---------- */
['pointerdown','touchstart','mousedown','keydown'].forEach(t=>{
window.addEventListener(t,e=>{
if(!DEMO||!e.isTrusted)return;
swallowUntil=performance.now()+600;
e.stopPropagation();
endDemo();
},{capture:true,passive:true});
});
window.addEventListener('click',e=>{
if(performance.now()<swallowUntil){e.stopPropagation();e.preventDefault();}
},true);
window.addEventListener('pointerdown',e=>{
if(!e.isTrusted||DEMO)return;
try{
if(!AC){const C=window.AudioContext||window.webkitAudioContext;if(C)AC=new C();}
if(AC&&AC.state==='suspended')AC.resume();
}catch(err){}
},{capture:true,passive:true});
// a second, slightly wrong cursor that follows the real one (mouse only)
let twinOn=false,tx=0,ty=0,qx=0,qy=0;
function twinLoop(){
if(!twinOn)return;
qx+=(tx+30-qx)*.07;qy+=(ty+18-qy)*.07;
twin.style.transform='translate('+qx.toFixed(1)+'px,'+qy.toFixed(1)+'px)';
requestAnimationFrame(twinLoop);
}
window.addEventListener('pointermove',e=>{
if(e.pointerType!=='mouse')return;
if(!DEMO){
tx=e.clientX;ty=e.clientY;
if(!twinOn){twinOn=true;qx=tx;qy=ty;twin.style.opacity='1';twinLoop();}
}
if(DEMO||!dg.el||dg.left<=0)return;
const r=dg.el.getBoundingClientRect();
const dx=Math.max(r.left-e.clientX,0,e.clientX-r.right),dy=Math.max(r.top-e.clientY,0,e.clientY-r.bottom);
if(Math.hypot(dx,dy)<64)dodge(e.clientX,e.clientY);
},{passive:true});
document.addEventListener('pointerdown',e=>{
if(e.pointerType!=='mouse'){twinOn=false;twin.style.opacity='0';}
},true);
document.documentElement.addEventListener('mouseleave',()=>{twinOn=false;twin.style.opacity='0';});
window.addEventListener('hashchange',()=>{
if(isDemoUrl()){if(!DEMO)startDemo();}
else if(DEMO)endDemo();
});
document.querySelectorAll('.fl[data-t]').forEach(b=>b.addEventListener('click',()=>toast(b.dataset.t)));
$('#snd').addEventListener('click',e=>{
soundOn=!soundOn;e.currentTarget.textContent='Sound: '+(soundOn?'on':'off');
if(soundOn)sfx('ok');
});
// the support agent never quite finishes typing
let chatI=0;
setInterval(()=>{chatI=(chatI+1)%CHAT.length;$('#chat').textContent=CHAT[chatI];},4800);
/* ---------- go ---------- */
jit(document);
if(DEMO)startDemo();else resetAll();
})();
</script>
</body>
</html>
