Back to the app
The code
The Most Uncomfortable Web Page 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">
<title>Comfort Portal</title>
<style>
:root{
--bg:#f3efe6; --ink:#2b2a33; --muted:#6c6878; --card:#fffdf8; --line:#e6e0d2;
--accent:#4f6bd8; --accent2:#3d58c4; --ok:#3fa56b;
--tilt:-0.6deg; --nudge:3px;
}
body.calm{ --tilt:0deg; --nudge:0px; }
*{box-sizing:border-box}
html,body{margin:0;min-height:100%}
body{
background-color:var(--bg); color:var(--ink);
font-family:system-ui,-apple-system,"Segoe UI",Roboto,sans-serif; font-size:16px; line-height:1.5;
background-image:linear-gradient(var(--line) 1px,transparent 1px),linear-gradient(90deg,var(--line) 1px,transparent 1px);
background-size:25px 25px,24px 24px; background-position:1px 0,0 1px;
overflow-x:hidden; -webkit-tap-highlight-color:transparent;
}
body.calm{background-size:24px 24px,24px 24px;background-position:0 0,0 0}
body.waiting{cursor:progress}
.top{display:flex;align-items:center;justify-content:space-between;gap:8px;padding:10px 14px 8px 17px;max-width:620px;margin:0 auto;rotate:.35deg;transition:rotate 1.5s}
body.calm .top{rotate:0deg}
.logo{display:flex;align-items:center;gap:8px;font-weight:800;font-size:18px;letter-spacing:.2px}
.logo svg{rotate:4deg;transition:rotate 1.5s;flex:0 0 auto}
body.calm .logo svg{rotate:0deg}
.logo sup{font-size:10px;margin-left:1px}
.hbtns{display:flex;gap:9px}
.ibtn{min-width:48px;height:48px;border-radius:14px 13px 14px 15px;border:2px solid #d7d0c0;background:#fff;color:var(--ink);font-family:inherit;font-size:14px;font-weight:700;position:relative;padding:0 12px;cursor:pointer;touch-action:manipulation;display:inline-flex;align-items:center;justify-content:center}
.ibtn:nth-child(2){margin-top:1px}
.badge{position:absolute;top:-6px;right:-7px;min-width:20px;height:20px;border-radius:10px;background:#e8604c;color:#fff;font-size:12px;line-height:20px;text-align:center;padding:0 5px;margin-top:1px}
.stepline{max-width:580px;margin:2px auto 0;padding:0 22px 0 21px;display:flex;justify-content:space-between;align-items:center;color:var(--muted);font-size:14px;font-weight:600}
.dots i{display:inline-block;width:11px;height:11px;border-radius:50%;border:2px solid #b9b09c;margin-left:6px;vertical-align:middle}
.dots i:nth-child(4){margin-left:8px}
.dots i.f{background:var(--accent);border-color:var(--accent)}
.dots i.up{position:relative;top:-2px}
body.calm .dots i.up{top:0}
body.calm .dots i:nth-child(4){margin-left:6px}
main#stage{position:relative;max-width:580px;margin:8px auto 18px;padding:26px 22px 24px 24px;background:var(--card);border:2px solid #e4ddcc;border-radius:22px 21px 23px 22px;box-shadow:3px 5px 0 #e0d8c6;rotate:var(--tilt);translate:var(--nudge) 0;transition:rotate 1.5s ease,translate 1.5s ease;overflow:hidden;min-height:300px}
@media (max-width:640px){ main#stage{margin:8px 16px 18px;padding:22px 16px 20px 17px} .stepline{padding:0 18px 0 17px} }
.enter{animation:enter .35s ease-out}
@keyframes enter{from{opacity:0;scale:.98}to{opacity:1;scale:1}}
.title{font-family:Georgia,"Times New Roman",serif;font-weight:700;font-size:clamp(26px,6.5vw,34px);line-height:1.15;margin:0 0 10px 1px;text-shadow:1px 1px 0 rgba(79,107,216,.25);letter-spacing:-.2px}
body.calm .title{text-shadow:none;margin-left:0}
.lead{margin:0 0 16px;color:var(--muted);text-indent:3px}
.j1{position:relative;top:1px}.j2{position:relative;top:-1px}.j3{position:relative;left:1px}
.btn{appearance:none;-webkit-appearance:none;border:2px solid #cfc7b5;background:#fff;color:var(--ink);font-family:inherit;font-size:17px;font-weight:700;min-height:56px;padding:12px 22px;border-radius:16px 15px 16px 17px;cursor:pointer;touch-action:manipulation;box-shadow:0 3px 0 #d9d1bf;transition:scale .2s,background .2s,opacity .2s}
.btn:active{translate:0 2px;box-shadow:0 1px 0 #d9d1bf}
.btn.primary{background:var(--accent);border-color:var(--accent2);color:#fff;box-shadow:0 3px 0 #2f469f}
.btn:disabled{opacity:.45;cursor:not-allowed}
.btn.big{font-size:20px;min-height:64px;padding:14px 28px}
.row{display:flex;flex-wrap:wrap;gap:10px 13px;justify-content:center;margin-top:14px}
.row .btn:nth-child(2){margin-top:1px}
.quip{min-height:24px;text-align:center;color:#7b5e9e;font-style:italic;margin:10px 0 0 2px}
.pills{display:flex;gap:8px;justify-content:center;margin:0 0 14px}
.pills span{padding:4px 12px;border-radius:99px;background:#eef1fb;color:var(--accent2);font-weight:700;font-size:13px}
.pills span:nth-child(3){rotate:3deg;translate:0 1px}
.arena{position:relative;height:280px;border:2px dashed #d8d0bf;border-radius:18px;background:repeating-linear-gradient(45deg,#fbf8f1 0 12px,#f6f2e8 12px 24px)}
#startBtn{position:absolute;width:180px;height:62px;left:calc(50% - 90px);top:calc(50% - 31px);transition:left .22s ease,top .22s ease,rotate .22s;z-index:2}
#layer{position:fixed;inset:0;pointer-events:none;z-index:50}
#layer>*{pointer-events:auto}
.cookie{position:fixed;background:#fff9ec;border:2px solid #e9cf9c;border-radius:18px 17px 19px 18px;padding:14px 14px 12px 15px;box-shadow:0 10px 30px rgba(60,40,10,.18);animation:pop .28s ease-out;transition:opacity .25s,scale .25s}
.cookie h4{margin:0 0 4px;display:flex;align-items:center;gap:8px;font-size:17px}
.cookie p{margin:0 0 12px;font-size:14.5px;color:#5b5346}
.ckrow{display:flex;gap:10px;justify-content:flex-end;align-items:center}
.ckrow .btn{min-height:48px;padding:8px 16px;font-size:16px}
.jar{display:flex;align-items:center;justify-content:center;gap:8px;font-weight:700;margin:0 0 4px}
.bye{opacity:0 !important;scale:.88 !important;pointer-events:none !important}
@keyframes pop{from{opacity:0;scale:.9}to{opacity:1;scale:1}}
.pbar{height:30px;border-radius:15px;background:#ece6d8;border:2px solid #d9d0bd;overflow:hidden;padding:2px 3px 2px 2px}
.pfill{height:100%;width:0;border-radius:12px;background:repeating-linear-gradient(-45deg,#5b77e0 0 14px,#6d88ea 14px 28px);animation:stripes 1.8s linear infinite;margin-top:1px}
@keyframes stripes{to{background-position:39.6px 0}}
.plabel{display:flex;justify-content:space-between;gap:10px;margin-top:8px;font-variant-numeric:tabular-nums;font-weight:700;font-size:15px}
#pp{position:relative;top:1px}
#eta{color:var(--muted);font-weight:600;text-align:right}
.nudge{animation:nudge .45s}
@keyframes nudge{25%{translate:-4px 0}75%{translate:4px 0}}
.terms{display:flex;flex-direction:column;gap:9px}
.term{display:flex;align-items:center;gap:12px;text-align:left;width:100%;min-height:56px;padding:10px 14px;border:2px solid #ddd5c4;background:#fff;border-radius:14px;font-family:inherit;font-size:15.5px;color:inherit;cursor:pointer;touch-action:manipulation;transition:border-color .2s}
.term:nth-child(3){margin-left:4px;width:calc(100% - 4px)}
.term:nth-child(5){padding-left:17px}
.term.on{border-color:#9fd0b2}
.cb{flex:0 0 28px;height:28px;border:2px solid #b9b09c;border-radius:7px;background:#fff;display:grid;place-items:center;transition:background .2s}
.term.on .cb{background:var(--ok);border-color:#2f8a56}
.term.on .cb::after{content:"";width:12px;height:7px;border-left:3px solid #fff;border-bottom:3px solid #fff;rotate:-45deg;translate:0 -2px}
.wig{animation:wig .5s}
@keyframes wig{0%,100%{translate:0 0}25%{translate:-5px 0}75%{translate:5px 0}}
.backdrop{position:fixed;inset:0;background:rgba(43,38,30,.28);animation:fade .3s;transition:opacity .3s}
@keyframes fade{from{opacity:0}to{opacity:1}}
.modal{position:fixed;left:50%;top:50%;width:min(340px,calc(100vw - 48px));background:#fff;border:2px solid #d9d1bf;border-radius:20px 19px 21px 20px;padding:20px 18px 16px;box-shadow:0 18px 50px rgba(30,25,15,.25);animation:pop .25s ease-out;transition:opacity .25s,scale .25s}
.modal h3{margin:0 0 6px;font-family:Georgia,serif;font-size:21px}
.modal p{margin:0 0 14px;color:var(--muted)}
.mrow{display:flex;gap:10px;flex-wrap:wrap}
.wigm{animation:wigm .5s}
@keyframes wigm{25%{margin-left:-6px}75%{margin-left:6px}}
#toast{position:fixed;left:50%;bottom:22px;translate:-50% 20px;rotate:-1deg;width:max-content;max-width:calc(100vw - 32px);background:#2f2c3a;color:#fff;padding:12px 18px;border-radius:14px;font-weight:600;opacity:0;transition:opacity .3s,translate .3s;z-index:90;pointer-events:none;text-align:center}
#toast.show{opacity:1;translate:-50% 0}
.foot{max-width:580px;margin:0 auto 30px;padding:0 16px;text-align:center;color:#9a937f;font-size:13px;rotate:-.8deg;translate:4px 0;transition:rotate 1.5s,translate 1.5s}
body.calm .foot{rotate:0deg;translate:0 0}
.confetti{position:absolute;inset:0;pointer-events:none;overflow:hidden;z-index:0}
.confetti i{position:absolute;top:-24px;width:9px;height:13px;border-radius:2px;opacity:.7;animation:fall linear infinite}
@keyframes fall{to{transform:translateY(950px) rotate(540deg)}}
.final{text-align:center;position:relative;z-index:1}
.stats{list-style:none;padding:0;margin:14px auto;max-width:380px;text-align:left}
.stats li{padding:8px 4px;border-bottom:1px dashed #e2dccd}
.stats b{display:inline-block;min-width:64px;color:var(--accent2)}
.souvenir{font-size:14px;color:var(--muted);margin:8px 0 0}
#finger{position:fixed;left:-60px;top:-60px;width:36px;height:36px;margin:-18px 0 0 -18px;border-radius:50%;background:rgba(255,255,255,.55);border:3px solid rgba(40,40,70,.6);box-shadow:0 4px 12px rgba(0,0,0,.2);z-index:100;pointer-events:none;opacity:0;transition-property:left,top,opacity;transition-timing-function:ease-in-out}
#finger.on{opacity:1}
#finger.tap{animation:tap .28s ease-out}
@keyframes tap{50%{scale:.72;background:rgba(79,107,216,.45)}}
</style>
</head>
<body>
<header class="top">
<div class="logo">
<svg width="30" height="30" viewBox="0 0 30 30" aria-hidden="true"><rect x="2" y="2" width="26" height="26" rx="8" fill="#4f6bd8"/><circle cx="11" cy="12" r="2" fill="#fff"/><circle cx="19.5" cy="12.6" r="2" fill="#fff"/><path d="M9 18.5c3 3 9 3 12-.5" stroke="#fff" stroke-width="2.4" fill="none" stroke-linecap="round"/></svg>
<span class="wob">Comfort Portal<sup>TM</sup></span>
</div>
<div class="hbtns">
<button class="ibtn" id="bell" aria-label="Notifications"><svg viewBox="0 0 24 24" width="22" height="22" aria-hidden="true"><path d="M12 3a6 6 0 0 0-6 6v4l-2 3h16l-2-3V9a6 6 0 0 0-6-6z" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round"/><path d="M10 19a2 2 0 0 0 4 0" stroke="currentColor" stroke-width="2" fill="none"/></svg><span class="badge" id="badge" hidden>1</span></button>
<button class="ibtn" id="snd">Sound: off</button>
</div>
</header>
<div class="stepline"><span id="step">Step 1 of 5</span><span class="dots" id="dots"></span></div>
<main id="stage"></main>
<footer class="foot wob">© 2026 Comfort Portal · All rights reserved · Some rights slightly misplaced</footer>
<div id="layer"></div>
<div id="toast" role="status" aria-live="polite"></div>
<div id="finger"></div>
<script>
(function(){
"use strict";
const $ = (s, r) => (r || document).querySelector(s);
const stageEl = $('#stage'), layer = $('#layer'), toastEl = $('#toast'), stepEl = $('#step'), dotsEl = $('#dots'), finger = $('#finger');
let tok = 0, cur = 0, demoOn = false, api = {}, suppressUntil = 0;
let stats = {};
const SP = () => demoOn ? 0.3 : 1;
const sleep = ms => new Promise(r => setTimeout(r, ms));
const rnd = (a, b) => a + Math.random() * (b - a);
const pick = a => a[Math.floor(Math.random() * a.length)];
function h(html){ const t = document.createElement('template'); t.innerHTML = html.trim(); return t.content.firstElementChild; }
/* ---------- soft sound (off by default) ---------- */
let ac = null, soundOn = false;
function blip(f, d, slideTo){
if (!soundOn) return;
try{
ac = ac || new (window.AudioContext || window.webkitAudioContext)();
if (ac.state === 'suspended') ac.resume();
d = d || 0.09;
const o = ac.createOscillator(), g = ac.createGain(), t = ac.currentTime;
o.type = 'sine'; o.frequency.setValueAtTime(f || 520, t);
if (slideTo) o.frequency.exponentialRampToValueAtTime(slideTo, t + d);
g.gain.setValueAtTime(0, t);
g.gain.linearRampToValueAtTime(0.045, t + 0.02);
g.gain.exponentialRampToValueAtTime(0.0001, t + d);
o.connect(g); g.connect(ac.destination);
o.start(t); o.stop(t + d + 0.03);
}catch(e){}
}
$('#snd').addEventListener('click', () => {
soundOn = !soundOn;
$('#snd').textContent = soundOn ? 'Sound: on (quiet)' : 'Sound: off';
blip(660, 0.12);
});
/* ---------- toast ---------- */
let toastT;
function toast(msg){
toastEl.textContent = msg; toastEl.classList.add('show');
clearTimeout(toastT); toastT = setTimeout(() => toastEl.classList.remove('show'), 2200);
}
/* ---------- one-pixel-off letters ---------- */
function wob(root){
const els = [...root.querySelectorAll('.wob')];
if (root.classList && root.classList.contains('wob')) els.push(root);
els.forEach(el => {
const w = document.createTreeWalker(el, NodeFilter.SHOW_TEXT);
const nodes = []; while (w.nextNode()) nodes.push(w.currentNode);
nodes.forEach(n => {
const s = n.nodeValue; if (!s.trim()) return;
const frag = document.createDocumentFragment(); let buf = '';
for (const ch of s){
if (ch !== ' ' && Math.random() < 0.07){
if (buf){ frag.appendChild(document.createTextNode(buf)); buf = ''; }
const sp = document.createElement('span'); sp.className = 'j' + (1 + Math.floor(Math.random() * 3)); sp.textContent = ch;
frag.appendChild(sp);
} else buf += ch;
}
if (buf) frag.appendChild(document.createTextNode(buf));
n.parentNode.replaceChild(frag, n);
});
});
}
/* ---------- notifications bell ---------- */
let bells = 0;
const badge = $('#badge');
function drawBadge(){ badge.hidden = bells === 0; badge.textContent = bells; }
setInterval(() => { if (cur < 5){ bells = Math.min(9, bells + 1); drawBadge(); } }, 6500);
$('#bell').addEventListener('click', () => {
toast(bells ? 'You have ' + bells + ' new notification' + (bells > 1 ? 's' : '') + '. They all say "hi". Marked as read.' : 'No new notifications. This is one.');
bells = 0; drawBadge(); blip(440);
});
const COOKIE_SVG = '<svg viewBox="0 0 24 24" width="22" height="22" aria-hidden="true"><path d="M21.5 12.5A9.5 9.5 0 1 1 11.5 2.5a3 3 0 0 0 3.5 3.5 3 3 0 0 0 3 3 3 3 0 0 0 3.5 3.5z" fill="#d9a25f" stroke="#b07a3a" stroke-width="1"/><circle cx="8" cy="9" r="1.4" fill="#6b3f1d"/><circle cx="12.5" cy="14" r="1.5" fill="#6b3f1d"/><circle cx="7.5" cy="15.5" r="1.2" fill="#6b3f1d"/><circle cx="16.5" cy="17" r="1.1" fill="#6b3f1d"/></svg>';
const STEPS = ['Step 1 of 5', 'Step 2 of 5', 'Step 3 of 5 (ish)', 'Step 4 of 5', 'Step 5 of 4', 'All steps complete'];
/* ---------- stage router ---------- */
function go(n){
tok++; cur = n; api = {};
layer.innerHTML = '';
document.body.classList.remove('calm', 'waiting');
stageEl.innerHTML = '';
stepEl.textContent = STEPS[n];
dotsEl.innerHTML = [0,1,2,3,4].map(k => '<i class="' + (k < n || n === 5 ? 'f ' : '') + (k === 2 ? 'up' : '') + '"></i>').join('');
if (n === 0) stats = { dodges:0, cookies:0, rejects:0, rewinds:0, betrayals:0, closes:0, t0:Date.now() };
STAGES[n](tok);
if (n !== 5) wob(stageEl);
stageEl.classList.remove('enter'); void stageEl.offsetWidth; stageEl.classList.add('enter');
try{ window.scrollTo(0, 0); }catch(e){}
}
/* ---------- 0: the shy Start button ---------- */
function s0(t){
stageEl.innerHTML =
'<h1 class="title wob">Welcome to the Comfort Portal</h1>' +
'<div class="pills"><span>calm</span><span>tidy</span><span>aligned</span></div>' +
'<p class="lead wob">A calm, tidy, perfectly organised place. Please press <b>Start</b> to begin your relaxing experience.</p>' +
'<div class="arena" id="arena"><button class="btn primary" id="startBtn">Start</button></div>' +
'<p class="quip" id="quip"> </p>';
const arena = $('#arena'), btn = $('#startBtn'), quip = $('#quip');
let left = demoOn ? 3 : 7, last = 0, readyAt = 0, qi = 0;
const quips = ['Whoops.', 'Too slow.', 'It is a little shy.', 'Almost had it.', 'It saw you coming.', 'It is getting tired.', 'One more time, probably.'];
function dodge(px, py){
if (left <= 0) return;
const aw = arena.clientWidth, ah = arena.clientHeight, bw = btn.offsetWidth, bh = btn.offsetHeight;
const cx = btn.offsetLeft + bw / 2, cy = btn.offsetTop + bh / 2;
const fx = px == null ? cx : px, fy = py == null ? cy : py;
let best = [0, 0], bd = -1;
for (let i = 0; i < 14; i++){
const x = rnd(4, Math.max(5, aw - bw - 4)), y = rnd(4, Math.max(5, ah - bh - 4));
const d = Math.hypot(x + bw / 2 - fx, y + bh / 2 - fy);
if (d > bd){ bd = d; best = [x, y]; }
}
btn.style.left = best[0] + 'px'; btn.style.top = best[1] + 'px';
btn.style.rotate = rnd(-6, 6).toFixed(1) + 'deg';
left--; stats.dodges++; last = performance.now();
quip.textContent = quips[Math.min(qi++, quips.length - 1)];
blip(rnd(520, 700), 0.1);
if (left <= 0){
readyAt = performance.now() + 450;
btn.textContent = 'Start (fine)';
btn.style.rotate = '-1.5deg';
quip.textContent = 'Okay. Okay. It is tired. It will stay still now.';
}
}
api.dodge = () => dodge();
api.move = e => {
if (demoOn || e.pointerType !== 'mouse' || left <= 0 || t !== tok) return;
if (performance.now() - last < 260) return;
const r = btn.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) < 34){ const a = arena.getBoundingClientRect(); dodge(e.clientX - a.left, e.clientY - a.top); }
};
btn.addEventListener('pointerdown', e => {
if (left > 0 && !demoOn){ const a = arena.getBoundingClientRect(); dodge(e.clientX - a.left, e.clientY - a.top); }
});
btn.addEventListener('click', () => {
const now = performance.now();
if (now - last < 450 || now < readyAt) return;
if (left > 0){ dodge(); return; }
blip(780, 0.12);
go(1);
});
}
/* ---------- 1: multiplying cookie notices ---------- */
const CK = [
['We value your privacy', 'We use cookies to improve your experience of our cookies.'],
['About that cookie', 'This cookie remembers that you accepted the previous cookie.'],
['Essential crumbs', 'Required for the cookie jar to work. The jar is also a cookie.'],
['Cookie counter', 'Counts how many cookies you have accepted. It is, of course, a cookie.'],
['Partner cookies', 'From our 1,204 trusted partners. They are all named Kevin.'],
['Last cookie', 'We promise. (We are a cookie notice. We cannot promise.)'],
['Okay, really the last one', 'This cookie stores your patience. It is nearly full.']
];
const REJ = ['Rejection noted. And ignored.', 'This cookie does not accept rejection.', 'Reject is decorative on this model.', 'The Accept button is right there. Growing.'];
function s1(t){
stageEl.innerHTML =
'<h2 class="title wob">A quick word about cookies</h2>' +
'<p class="lead wob">This site uses cookies. Some of the cookies also use cookies. Please review them, one at a time, forever.</p>' +
'<p class="jar">' + COOKIE_SVG + ' Cookies accepted: <b id="cnt">0</b></p>' +
'<p class="quip" id="quip"> </p>' +
'<div class="row"><button class="btn primary" id="next" disabled>Continue</button></div>';
const next = $('#next'), quip = $('#quip'), cnt = $('#cnt');
let planned = 1, accepted = 0, idx = 0;
next.addEventListener('click', () => go(2));
function done(){
next.disabled = false;
quip.textContent = 'Preferences saved: all of them.';
toast('Your cookie preferences have been saved. Mostly.');
blip(880, 0.15);
}
function spawn(){
const i = idx++;
const w = Math.min(320, window.innerWidth - 32);
const el = h('<div class="cookie" role="dialog" aria-label="Cookie notice"><h4>' + COOKIE_SVG + '<span>' + CK[i][0] + '</span></h4><p>' + CK[i][1] + '</p><div class="ckrow"><button class="btn rej">Reject</button><button class="btn primary acc">Accept</button></div></div>');
el.style.width = w + 'px';
el.style.rotate = rnd(-3.5, 3.5).toFixed(2) + 'deg';
el.style.left = '16px'; el.style.top = '70px';
layer.appendChild(el);
const eh = el.offsetHeight;
el.style.left = (16 + Math.random() * Math.max(0, window.innerWidth - 32 - w)) + 'px';
el.style.top = (70 + Math.random() * Math.max(0, window.innerHeight - 70 - 16 - eh)) + 'px';
const acc = el.querySelector('.acc'), rej = el.querySelector('.rej');
let rs = 1;
rej.addEventListener('click', () => {
stats.rejects++;
rs = Math.max(0.8, rs - 0.07);
rej.style.scale = rs; acc.style.scale = (2 - rs).toFixed(2);
toast(REJ[(stats.rejects - 1) % REJ.length]);
blip(330, 0.12, 280);
});
acc.addEventListener('click', () => {
if (el.dataset.gone || t !== tok) return; el.dataset.gone = '1';
accepted++; stats.cookies++; cnt.textContent = stats.cookies;
blip(600 + accepted * 30, 0.1);
el.classList.add('bye'); setTimeout(() => el.remove(), 300);
const cap = demoOn ? 4 : CK.length;
const n = planned === 1 ? 2 : (planned < cap ? 1 : 0);
planned += n;
for (let k = 0; k < n; k++) setTimeout(() => { if (t === tok) spawn(); }, (220 + k * 220) * SP());
if (n === 0 && accepted === planned) done();
else if (n) quip.textContent = pick(['Thank you! Here are more.', 'Cookies attract cookies.', 'They multiply when accepted. Like real cookies.', 'Nearly empty. Probably.', 'Accepting one releases another. Science.']);
});
}
setTimeout(() => { if (t === tok) spawn(); }, 500 * SP());
}
/* ---------- 2: the progress bar that slides back ---------- */
function s2(t){
document.body.classList.add('waiting');
stageEl.innerHTML =
'<h2 class="title wob">Preparing your experience</h2>' +
'<p class="lead wob">This will only take a moment. Moments vary in length.</p>' +
'<div class="pbar" id="pbar"><div class="pfill" id="pf"></div></div>' +
'<div class="plabel"><span id="pp">0%</span><span id="eta">Estimated time: 3 seconds</span></div>' +
'<p class="quip" id="quip">Loading...</p>' +
'<div class="row"><button class="btn" id="push">Push it a little</button><button class="btn primary" id="next" hidden>Continue</button></div>';
const pf = $('#pf'), pp = $('#pp'), eta = $('#eta'), quip = $('#quip'), push = $('#push'), next = $('#next'), pbar = $('#pbar');
let p = 0, pushes = 0;
const ok = () => t === tok;
const set = v => { p = v; pf.style.width = v + '%'; pp.textContent = (v >= 99 && v < 100 ? v.toFixed(2) : Math.floor(v)) + '%'; };
const eOut = x => 1 - Math.pow(1 - x, 3);
const eIO = x => x < .5 ? 4 * x * x * x : 1 - Math.pow(-2 * x + 2, 3) / 2;
const tween = (to, dur, ease) => new Promise(res => {
const from = p, t0 = performance.now(); dur = dur * SP(); ease = ease || (x => x);
(function f(now){
if (!ok()) return res();
const k = Math.min(1, (now - t0) / dur);
set(from + (to - from) * ease(k));
if (k < 1) requestAnimationFrame(f); else res();
})(t0);
});
const wait = ms => sleep(ms * SP());
function slideBack(){ stats.rewinds++; blip(600, 0.5, 300); }
push.addEventListener('click', () => {
pbar.classList.remove('nudge'); void pbar.offsetWidth; pbar.classList.add('nudge');
quip.textContent = ['Pushed. It did not help.', 'The bar appreciates your support.', 'Pushing harder does not help.', 'Please stop pushing the bar. It is shy too.'][pushes++ % 4];
blip(400, 0.08);
});
next.addEventListener('click', () => go(3));
(async () => {
await tween(99, 3200, eOut); if (!ok()) return;
quip.textContent = '99%. Nearly there...'; await wait(1000); if (!ok()) return;
quip.textContent = 'Oops. Found a few more files.'; eta.textContent = 'Estimated time: 4 minutes';
slideBack(); await tween(34, 900, eIO); if (!ok()) return;
await wait(300); if (!ok()) return;
quip.textContent = 'Loading again, more confidently.'; eta.textContent = 'Estimated time: 2 seconds';
await tween(99, 2400, eOut); if (!ok()) return;
quip.textContent = '99% again. This feels familiar.'; await wait(900); if (!ok()) return;
quip.textContent = 'Re-counting the percents...'; eta.textContent = 'Estimated time: yes';
slideBack(); await tween(68, 700, eIO); if (!ok()) return;
await wait(250); if (!ok()) return;
await tween(99, 1500, eOut); if (!ok()) return;
quip.textContent = '99%... just a few more decimals.'; eta.textContent = 'Estimated time: soon-ish';
await tween(99.97, 2600); if (!ok()) return;
await wait(600); if (!ok()) return;
set(100); quip.textContent = '100%. Rounded up out of kindness.'; eta.textContent = 'Estimated time: done (late)';
blip(880, 0.15); push.hidden = true; next.hidden = false; document.body.classList.remove('waiting');
})();
}
/* ---------- 3: jealous checkboxes ---------- */
const TERMS = ['I agree to agree.', 'I have read the terms I have not read.', 'I accept that this box is slightly off.', 'I will not mention the progress bar.', 'The cookies were my own choice.', 'I am a patient person.'];
const JEAL = ['Box # felt left out and unticked itself.', 'Box # changed its mind.', 'Box # wanted a turn being unticked.', 'Box # was ticked a little crooked, so it reset.', 'Box # got shy.'];
function s3(t){
stageEl.innerHTML =
'<h2 class="title wob">Terms & conditions</h2>' +
'<p class="lead wob">Please tick all six boxes. They are very easy boxes. Mostly.</p>' +
'<div class="terms" id="terms"></div>' +
'<p class="quip" id="quip"> </p>' +
'<div class="row"><button class="btn primary" id="next" disabled>I agree to everything</button></div>';
const box = $('#terms'), quip = $('#quip'), next = $('#next');
const state = TERMS.map(() => false);
let mischief = demoOn ? 1 : 4;
const rows = TERMS.map((txt, i) => {
const b = h('<button class="term" aria-pressed="false"><span class="cb"></span><span class="wob">' + txt + '</span></button>');
b.style.rotate = (i % 2 ? 1 : -1) * rnd(0.2, 0.8) + 'deg';
b.addEventListener('click', () => toggle(i));
box.appendChild(b); return b;
});
function render(i){ rows[i].setAttribute('aria-pressed', String(state[i])); rows[i].classList.toggle('on', state[i]); }
function check(){
const all = state.every(Boolean); next.disabled = !all;
if (all) quip.textContent = 'All six. Look at you.';
}
function toggle(i){
if (t !== tok) return;
state[i] = !state[i]; render(i); blip(state[i] ? 620 : 420, 0.07);
if (state[i] && mischief > 0){
const others = state.map((v, k) => (v && k !== i) ? k : -1).filter(k => k >= 0);
if (others.length){
const k = pick(others); mischief--; stats.betrayals++;
setTimeout(() => {
if (t !== tok || !state[k]) return;
state[k] = false; render(k);
rows[k].classList.remove('wig'); void rows[k].offsetWidth; rows[k].classList.add('wig');
quip.textContent = pick(JEAL).replace('#', k + 1);
blip(360, 0.15, 300);
check();
}, 350);
}
}
check();
}
next.addEventListener('click', () => go(4));
}
/* ---------- 4: Close buttons that spawn Close buttons ---------- */
const MODALS = [
{ t:'Subscribe to our newsletter?', b:'Weekly updates about this popup, delivered daily.', c:'Close', j:'flex-end', o:[0,-10], r:-1 },
{ t:'Closing so soon?', b:'This Close button closes the previous Close button.', c:'Close', j:'flex-start', o:[14,8], r:1.5, d:'Stay', dt:'You stayed. The popup got bored. Please close it anyway.' },
{ t:'Please confirm', b:'Close this to confirm that you wanted to close.', c:'Close', j:'center', o:[-12,18], r:-2 },
{ t:'Quick survey', b:'How was closing? Press Close to rate it five stars.', c:'Close', j:'space-between', o:[10,-14], r:2.4, d:'Five stars', dt:'Thank you! Closing is now rated 5.0. Please close.' },
{ t:'Nearly closed', b:'Statistically, this is the second-to-last Close button.', c:'Close', j:'flex-end', o:[-6,10], r:-1.2 },
{ t:'The final Close', b:'We saved the biggest one for you.', c:'Close everything', j:'center', o:[3,0], r:0.4 }
];
function s4(t){
stageEl.innerHTML =
'<h2 class="title wob">Almost done</h2>' +
'<p class="lead wob">Just one small popup, and then you are free. One. Small.</p>' +
'<p class="quip" id="quip"> </p>';
const quip = $('#quip');
let depth = 0;
const back = h('<div class="backdrop"></div>');
function open(){
if (t !== tok) return;
if (depth === 0) layer.appendChild(back);
const i = depth++, m = MODALS[i], last = i === MODALS.length - 1;
const el = h('<div class="modal" role="dialog" aria-label="' + m.t + '"><h3 class="wob">' + m.t + '</h3><p class="wob">' + m.b + '</p><div class="mrow" style="justify-content:' + m.j + '">' +
(m.d ? '<button class="btn decoy">' + m.d + '</button>' : '') +
'<button class="btn ' + (last ? 'primary big' : '') + ' close">' + m.c + '</button></div></div>');
el.style.translate = 'calc(-50% + ' + m.o[0] + 'px) calc(-50% + ' + m.o[1] + 'px)';
el.style.rotate = m.r + 'deg';
el.style.zIndex = 10 + i;
layer.appendChild(el); wob(el);
el.querySelector('.close').addEventListener('click', () => {
if (el.dataset.done || t !== tok) return; el.dataset.done = '1';
stats.closes++; blip(500 + i * 50, 0.09);
quip.textContent = 'Close buttons closed: ' + stats.closes + '. Popups remaining: ' + (last ? 'none (really)' : 'one, probably') + '.';
if (last) closeAll(); else setTimeout(open, 120 * SP());
});
const dec = el.querySelector('.decoy');
if (dec) dec.addEventListener('click', () => {
el.classList.remove('wigm'); void el.offsetWidth; el.classList.add('wigm');
toast(m.dt); blip(330, 0.1);
});
}
function closeAll(){
const ms = [...layer.querySelectorAll('.modal')].reverse();
ms.forEach((m, k) => setTimeout(() => { m.classList.add('bye'); blip(520 + k * 60, 0.07); }, k * 140));
setTimeout(() => back.classList.add('bye'), ms.length * 140);
setTimeout(() => { if (t === tok) go(5); }, ms.length * 140 + 550);
}
setTimeout(open, 700 * SP());
}
/* ---------- 5: thank you ---------- */
function fmt(s){ return s < 60 ? s + ' second' + (s === 1 ? '' : 's') : Math.floor(s / 60) + ' min ' + (s % 60) + ' s'; }
function s5(t){
document.body.classList.add('calm');
const secs = Math.max(1, Math.round((Date.now() - stats.t0) / 1000));
stageEl.innerHTML =
'<div class="confetti" id="conf"></div>' +
'<div class="final">' +
'<svg viewBox="0 0 24 24" width="58" height="58" aria-hidden="true"><path d="M12 21s-7.5-4.6-9.6-9.2C.9 8.4 3 4.5 6.8 4.5c2.1 0 3.6 1.1 4.4 2.6h1.6c.8-1.5 2.3-2.6 4.4-2.6 3.8 0 5.9 3.9 4.4 7.3C19.5 16.4 12 21 12 21z" fill="#e8604c"/></svg>' +
'<h1 class="title">Thank you for your patience.</h1>' +
'<p class="lead">Everything is perfectly straight now. You may relax your shoulders.</p>' +
'<ul class="stats">' +
'<li><b>' + stats.dodges + '</b>button dodges endured</li>' +
'<li><b>' + stats.cookies + '</b>cookies accepted (' + stats.rejects + ' rejections politely ignored)</li>' +
'<li><b>' + (stats.rewinds + 1) + '</b>visits to 99%</li>' +
'<li><b>' + stats.betrayals + '</b>boxes that unticked themselves</li>' +
'<li><b>' + stats.closes + '</b>Close buttons closed</li>' +
'<li><b>' + fmt(secs) + '</b> of your life, lovingly wasted</li>' +
'</ul>' +
'<p class="souvenir">We left exactly one pixe<span class="j1">l</span> out of place, as a souvenir.</p>' +
'<div class="row"><button class="btn primary" id="again">Do it all again</button></div>' +
'</div>';
const conf = $('#conf');
const cols = ['#f6c85f', '#9bd0f5', '#b8e3b0', '#f4a8a0', '#c9b6f2', '#ffd9a8'];
for (let i = 0; i < 28; i++){
const c = document.createElement('i');
c.style.left = rnd(0, 100) + '%';
c.style.background = pick(cols);
const dur = rnd(7, 12);
c.style.animationDuration = dur + 's';
c.style.animationDelay = (-rnd(0, dur)) + 's';
conf.appendChild(c);
}
$('#again').addEventListener('click', () => go(0));
blip(660, 0.2); setTimeout(() => blip(880, 0.25), 180);
}
const STAGES = [s0, s1, s2, s3, s4, s5];
/* ---------- global input ---------- */
addEventListener('pointermove', e => { if (api.move) api.move(e); });
/* ---------- #demo hands-free loop ---------- */
async function dsleep(ms){ await sleep(ms); if (!demoOn) throw new Error('stop'); }
async function fingerTo(el, ms){
if (!el) return;
const r = el.getBoundingClientRect();
finger.style.transitionDuration = ms + 'ms, ' + ms + 'ms, .3s';
finger.style.left = (r.left + r.width * 0.55) + 'px';
finger.style.top = (r.top + r.height * 0.6) + 'px';
await dsleep(ms);
}
async function tap(el){
finger.classList.remove('tap'); void finger.offsetWidth; finger.classList.add('tap');
await dsleep(120);
if (el && el.isConnected) el.click();
await dsleep(150);
}
async function until(fn, max){
const t0 = Date.now(); max = max || 15000;
while (!fn()){ if (Date.now() - t0 > max) return; await dsleep(100); }
}
async function demo(){
try{
while (demoOn){
go(0);
finger.style.left = (window.innerWidth * 0.5) + 'px'; finger.style.top = (window.innerHeight * 0.9) + 'px';
await dsleep(700);
for (let i = 0; i < 3; i++){
await fingerTo($('#startBtn'), 330);
if (api.dodge) api.dodge();
await dsleep(260);
}
await dsleep(250);
const sb = $('#startBtn'); await fingerTo(sb, 300); await tap(sb);
await dsleep(300);
// cookies
let rejected = false;
while (cur === 1){
const c = [...layer.querySelectorAll('.cookie:not(.bye)')].pop();
const nx = $('#next');
if (!c){ if (nx && !nx.disabled) break; await dsleep(100); continue; }
if (!rejected){ rejected = true; const r = c.querySelector('.rej'); await fingerTo(r, 300); await tap(r); }
const a = c.querySelector('.acc'); await fingerTo(a, 280); await tap(a); await dsleep(60);
}
let nx = $('#next'); await fingerTo(nx, 280); await tap(nx);
// progress
await dsleep(400);
const p = $('#push'); await fingerTo(p, 350); await tap(p);
await until(() => { const n = $('#next'); return n && !n.hidden; });
nx = $('#next'); await fingerTo(nx, 280); await tap(nx);
// terms
await dsleep(200);
while (cur === 3){
const n = $('#next');
if (n && !n.disabled){ await dsleep(380); if (!n.disabled) break; else continue; }
const r = [...document.querySelectorAll('.term')].find(x => !x.classList.contains('on'));
if (r){ await fingerTo(r, 220); await tap(r); await dsleep(160); } else await dsleep(100);
}
nx = $('#next'); await fingerTo(nx, 260); await tap(nx);
// close buttons
while (cur === 4){
const ms = [...layer.querySelectorAll('.modal:not(.bye)')];
const top = ms[ms.length - 1];
const c = top && !top.dataset.done ? top.querySelector('.close') : null;
if (c){ await fingerTo(c, 250); await tap(c); await dsleep(120); } else await dsleep(100);
}
// final
await dsleep(500);
await fingerTo($('#again'), 600);
await dsleep(2000);
}
}catch(e){}
}
function startDemo(){
if (demoOn) return;
demoOn = true; finger.classList.add('on'); demo();
}
function stopDemo(){
if (!demoOn) return;
demoOn = false; finger.classList.remove('on');
suppressUntil = performance.now() + 500;
setTimeout(() => go(0), 0);
}
addEventListener('pointerdown', e => { if (demoOn && e.isTrusted) stopDemo(); }, true);
addEventListener('keydown', e => { if (demoOn && e.isTrusted) stopDemo(); }, true);
addEventListener('click', e => { if (e.isTrusted && performance.now() < suppressUntil){ e.stopPropagation(); e.preventDefault(); } }, true);
addEventListener('hashchange', () => { if (location.hash === '#demo') startDemo(); });
/* ---------- boot ---------- */
wob(document.querySelector('.top'));
wob(document.querySelector('.foot'));
if (location.hash === '#demo') startDemo(); else go(0);
})();
</script>
</body>
</html>
