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">
<title>Comfort Setup (Almost Ready)</title>
<style>
:root{color-scheme:light;--bg:#f4efe6;--ink:#2b2a33;--card:#fffdf8;--acc:#ff7a3d;--teal:#3c6e71;--line:#d8cfbd;--soft:#e9e0cf;--mute:#6a6556}
*{box-sizing:border-box;-webkit-tap-highlight-color:transparent}
body{margin:0;min-height:100vh;background:var(--bg);color:var(--ink);font:17px/1.45 system-ui,-apple-system,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;overflow-x:hidden;touch-action:manipulation}
body::before{content:"";position:fixed;inset:-25%;z-index:-1;pointer-events:none;background-image:radial-gradient(circle,#cdc3ad 1.6px,transparent 1.9px);background-size:24px 24px;transform:rotate(.9deg)}
#app{width:min(94vw,560px);margin:0 auto;padding:12px 0 96px;position:relative}
header{display:flex;justify-content:space-between;align-items:baseline;padding:4px 6px 10px;font-weight:800}
#brand{position:relative;left:-1px;top:1px}
#step{font-weight:600;font-size:14px;color:var(--mute);position:relative;left:2px;top:-1px;transform:rotate(.5deg)}
#card{position:relative;min-height:470px;overflow:hidden;background:var(--card);border:2px solid var(--ink);border-radius:20px;padding:18px 16px 22px;box-shadow:7px 8px 0 var(--soft);transform:rotate(-.5deg);transition:transform 2s cubic-bezier(.2,.7,.2,1)}
body.straight #card{transform:none}
#stage.in{animation:in .45s ease backwards}
@keyframes in{from{opacity:0;transform:translateY(10px)}}
h1,h2,h3,h4{line-height:1.15;letter-spacing:-.2px}
h1{font-size:clamp(26px,7.4vw,34px);margin:.1em 0 .35em}
h2{font-size:clamp(23px,6.4vw,28px);margin:.1em 0 .3em}
p{margin:.4em 0}
.w{display:inline-block;white-space:nowrap}
.j{display:inline-block}
.n1{position:relative;left:1px;top:-1px}
.n2{position:relative;left:-1px;top:1px}
.tiny{font-size:13px;color:var(--mute)}
.hero{display:flex;gap:12px;align-items:center}
.hero svg{flex:none;transform:rotate(-6deg)}
.hero h1{flex:1;min-width:0;margin:0}
.tiles{display:flex;gap:7px;margin:12px 0 4px}
.tiles div{flex:1;border:2px solid var(--ink);border-radius:10px;padding:8px 4px;text-align:center;font-weight:700;font-size:15px;background:#fff}
.tiles div:nth-child(1){transform:rotate(-1.4deg)}
.tiles div:nth-child(2){transform:rotate(1deg) translateY(2px);margin-left:1px}
.tiles div:nth-child(3){transform:rotate(-.6deg) translateX(2px)}
.btn{font:inherit;font-weight:800;font-size:19px;min-height:58px;padding:0 26px;border-radius:14px;border:2px solid var(--ink);background:var(--acc);color:#1d1308;box-shadow:0 4px 0 var(--ink);cursor:pointer;touch-action:manipulation;user-select:none;-webkit-user-select:none}
.btn:active{transform:translateY(3px);box-shadow:0 1px 0 var(--ink)}
.btn.alt{background:#fff}
.btn.sm{min-height:48px;font-size:16px;padding:0 16px}
.btn[disabled]{opacity:.55;cursor:default}
#pad{position:relative;height:210px;margin-top:12px;border:2px dashed #cbbfa6;border-radius:14px;overflow:hidden;background:repeating-linear-gradient(135deg,transparent 0 11px,rgba(0,0,0,.03) 11px 22px)}
#go{position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);transition:left .32s cubic-bezier(.3,1.5,.5,1),top .32s cubic-bezier(.3,1.5,.5,1)}
#go:active{transform:translate(-50%,-46%)}
#go.tired{background:#bfe3d0;transform:translate(-50%,-50%) rotate(4deg)}
#dc{min-height:26px;margin:10px 0 0;font-weight:700;text-align:center;position:relative;left:-1px}
#zone{position:relative;height:350px;margin-top:8px;border:2px solid var(--line);border-radius:14px;background:#faf6ec;overflow:hidden}
.ph{padding:14px}
.ph i{display:block;height:10px;border-radius:6px;background:#e6dece;margin:0 0 12px}
.ph i:nth-child(3n){width:62%}
.ph i:nth-child(3n+1){width:91%;margin-left:1px}
.ph i:nth-child(3n+2){width:78%}
.ck,.pop{position:absolute;background:#fff;border:2px solid var(--ink);border-radius:14px;padding:11px 12px 12px;box-shadow:4px 5px 0 rgba(43,42,51,.18);animation:pop .3s ease backwards}
.ck{width:86%}
.pop{width:82%}
@keyframes pop{from{opacity:0;translate:0 12px;scale:.94}}
.ck h4,.pop h3{margin:0 0 3px;font-size:17px}
.ck p,.pop p{margin:0 0 9px;font-size:14px;line-height:1.35}
.rw{display:flex;gap:8px}
.ck .btn{flex:1;padding:0 8px}
.row{display:flex;margin:2px 0 8px}
.row.r{justify-content:flex-end}
.row.l{justify-content:flex-start}
.row.c{justify-content:center}
.pop .row:last-child{margin:8px 0 0}
.ck.out{opacity:0;scale:.88;transition:opacity .22s,scale .22s;pointer-events:none}
.pop.dead{opacity:.55;filter:grayscale(1);pointer-events:none;transition:opacity .3s}
.pop.out{transform:translateY(130%) rotate(10deg)!important;opacity:0;transition:transform .8s cubic-bezier(.5,0,.8,.4),opacity .8s}
.bar{position:relative;height:40px;border:2px solid var(--ink);border-radius:12px;background:#fff;overflow:hidden;margin:14px 0 8px}
#fill{position:absolute;left:0;top:0;bottom:0;width:0;background:linear-gradient(90deg,#6fb6a8,#92d0c2)}
#pct{position:absolute;right:10px;top:50%;margin-top:-11px;line-height:22px;font-weight:800;font-variant-numeric:tabular-nums;transform:translate(1px,1px)}
#msg{min-height:26px;font-weight:700;margin:6px 0 2px}
#tasks{list-style:none;padding:0;margin:10px 0 12px}
#tasks li{position:relative;padding:7px 10px 7px 40px;margin:0 0 7px;border:2px solid var(--line);border-radius:10px;background:#fff;font-size:15px;opacity:.6;transition:opacity .4s}
#tasks li::before{content:"";position:absolute;left:10px;top:50%;margin-top:-11px;width:22px;height:22px;border:2px solid var(--ink);border-radius:6px;background:#fff;text-align:center;font-size:14px;line-height:18px;font-weight:800}
#tasks li.on{opacity:1}
#tasks li.on::before{content:"\2713";background:#bfe3d0}
#tasks li:nth-child(1){transform:rotate(-.6deg)}
#tasks li:nth-child(2){transform:rotate(.5deg) translateX(2px)}
#tasks li:nth-child(3){transform:rotate(-.3deg) translateX(-1px)}
#tasks li:nth-child(4){transform:rotate(.7deg) translateY(1px)}
.fin{text-align:center}
.fin svg{display:block;margin:2px auto 6px;animation:br 4s ease-in-out infinite}
@keyframes br{50%{transform:scale(1.04)}}
.fin h1{font-size:clamp(28px,8vw,38px)}
.stats{list-style:none;margin:12px auto;padding:8px 14px;max-width:360px;border:2px solid var(--ink);border-radius:12px;background:#fff;text-align:left;font-size:15px}
.stats li{display:flex;justify-content:space-between;gap:10px;padding:4px 0;border-bottom:1px dashed var(--line)}
.stats li:last-child{border:0}
.stats b{font-variant-numeric:tabular-nums}
#tip{min-height:24px;margin:14px 6px 0;text-align:center;font-size:14px;color:var(--mute);transition:opacity .6s;position:relative;left:1px}
footer{display:flex;justify-content:space-between;align-items:center;padding:6px 6px 0}
.lnk{font:inherit;font-size:15px;min-height:44px;padding:0 12px;background:none;border:2px solid transparent;border-radius:10px;color:var(--teal);text-decoration:underline;cursor:pointer}
#toast{position:fixed;left:50%;bottom:64px;transform:translate(-50%,10px);opacity:0;background:var(--ink);color:#fff;padding:10px 16px;border-radius:12px;font-size:15px;max-width:88vw;text-align:center;transition:opacity .35s,transform .35s;pointer-events:none;z-index:97}
#toast.show{opacity:1;transform:translate(-50%,0)}
#ghost{position:fixed;left:0;top:0;width:46px;height:46px;margin:-23px 0 0 -23px;border-radius:50%;background:rgba(60,110,113,.3);border:3px solid rgba(60,110,113,.8);pointer-events:none;z-index:99;opacity:0;transition:transform .46s cubic-bezier(.4,0,.2,1),opacity .3s}
#ghost.on{opacity:1}
#ghost.tap{animation:ring .4s ease-out}
@keyframes ring{from{box-shadow:0 0 0 0 rgba(60,110,113,.45)}to{box-shadow:0 0 0 24px rgba(60,110,113,0)}}
#demoTag{position:fixed;left:50%;bottom:12px;transform:translateX(-50%);background:var(--ink);color:#fff;font-size:13px;padding:7px 14px;border-radius:99px;opacity:0;pointer-events:none;transition:opacity .3s;z-index:98;white-space:nowrap}
body.demo #demoTag{opacity:.92}
@media (prefers-reduced-motion:reduce){*{animation-duration:.01ms!important;transition-duration:.01ms!important}}
</style>
</head>
<body>
<div id="app">
<header><span id="brand">Comfortably™</span><span id="step">Step 1 of 4</span></header>
<main id="card"><div id="stage"></div></main>
<p id="tip" aria-live="off"></p>
<footer><button class="lnk" id="back">Back</button><button class="lnk" id="snd">Sound: on</button></footer>
</div>
<div id="toast" role="status"></div>
<div id="ghost" aria-hidden="true"></div>
<div id="demoTag">Hands-free demo. Touch anywhere to take over.</div>
<script>
(function () {
'use strict';
const $ = s => document.querySelector(s);
const stage = $('#stage'), stepEl = $('#step'), ghost = $('#ghost');
const STEPS = ['Step 1 of 4', 'Step 2 of 4', 'Step 3 of 4', 'Step 4 of 6', 'Step 6 of 6'];
let gen = 0, demo = false, snd = true, st = {}, toastT = 0, ac = null;
const rnd = (a, b) => a + Math.random() * (b - a);
const pick = a => a[Math.floor(Math.random() * a.length)];
const sget = k => { try { return localStorage.getItem(k); } catch (e) { return null; } };
const sset = (k, v) => { try { localStorage.setItem(k, v); } catch (e) {} };
// every timer is tied to the current screen: changing screen cancels the old ones
const after = (ms, fn) => { const g = gen; return setTimeout(() => { if (g === gen) fn(); }, ms); };
const lastOf = sel => { const a = [...stage.querySelectorAll(sel)]; return a[a.length - 1]; };
function toast(m) {
const t = $('#toast');
t.textContent = m; t.classList.add('show');
clearTimeout(toastT); toastT = setTimeout(() => t.classList.remove('show'), 1900);
}
// very soft synthesized blips, only after a real tap, never in demo
function blip(f, d, type, v, slide) {
if (!snd || demo) return;
try {
ac = ac || new (window.AudioContext || window.webkitAudioContext)();
if (ac.state === 'suspended') ac.resume();
d = d || .15; v = v || .035;
const o = ac.createOscillator(), g = ac.createGain(), t = ac.currentTime;
o.type = type || 'sine';
o.frequency.setValueAtTime(f, t);
if (slide) o.frequency.exponentialRampToValueAtTime(Math.max(60, f + slide), t + d);
g.gain.setValueAtTime(0.0001, t);
g.gain.exponentialRampToValueAtTime(v, t + .03);
g.gain.exponentialRampToValueAtTime(0.0001, t + d);
o.connect(g); g.connect(ac.destination);
o.start(t); o.stop(t + d + .05);
} catch (e) {}
}
// letters sit up to one pixel off their baseline and a hair crooked
function jit(el) {
const t = el.textContent;
let s = 7;
for (const c of t) s = (s * 31 + c.charCodeAt(0)) >>> 0;
const r = () => (s = (Math.imul(s, 1664525) + 1013904223) >>> 0) / 4294967296;
el.setAttribute('aria-label', t);
el.textContent = '';
t.split(' ').forEach((w, i) => {
if (i) el.appendChild(document.createTextNode(' '));
const ws = document.createElement('span');
ws.className = 'w'; ws.setAttribute('aria-hidden', 'true');
for (const ch of w) {
const j = document.createElement('span');
j.className = 'j'; j.textContent = ch;
j.style.transform = 'translateY(' + Math.round(r() * 2 - 1) + 'px) rotate(' + ((r() - .5) * 2.4).toFixed(1) + 'deg)';
ws.appendChild(j);
}
el.appendChild(ws);
});
}
const jitAll = root => root.querySelectorAll('.jit').forEach(jit);
const face = ok => '<svg viewBox="0 0 120 120" width="92" height="92" aria-hidden="true"><ellipse cx="60" cy="113" rx="32" ry="4.5" fill="#e3dac8"/><circle cx="60" cy="58" r="44" fill="#ffd36e" stroke="#2b2a33" stroke-width="4"/><circle cx="44" cy="50" r="' + (ok ? 6 : 7.5) + '" fill="#2b2a33"/><circle cx="76" cy="' + (ok ? 50 : 54) + '" r="' + (ok ? 6 : 4.5) + '" fill="#2b2a33"/><path d="' + (ok ? 'M38 72Q60 92 82 72' : 'M36 78Q58 94 86 70') + '" fill="none" stroke="#2b2a33" stroke-width="4.5" stroke-linecap="round"/>' + (ok ? '' : '<path d="M98 28q6 9 0 14q-6-5 0-14z" fill="#7fc4d8" stroke="#2b2a33" stroke-width="2"/>') + '</svg>';
const badge = '<svg viewBox="0 0 120 130" width="104" height="112" aria-hidden="true"><path d="M38 80 22 124l22-8 10 12 14-40z" fill="#ff7a3d" stroke="#2b2a33" stroke-width="3" stroke-linejoin="round"/><path d="M82 80l16 44-22-8-10 12-14-40z" fill="#ff9a66" stroke="#2b2a33" stroke-width="3" stroke-linejoin="round"/><circle cx="60" cy="56" r="44" fill="#ffd36e" stroke="#2b2a33" stroke-width="4"/><circle cx="60" cy="56" r="33" fill="none" stroke="#2b2a33" stroke-width="2.5" stroke-dasharray="3 5"/><path d="M42 57l12 12 25-26" fill="none" stroke="#2b2a33" stroke-width="7" stroke-linecap="round" stroke-linejoin="round"/></svg>';
/* ---------- screen 1: the button that dodges ---------- */
function s0() {
const NEED = demo ? 2 : 5;
let dodges = 0, tired = false, last = 0, done = false;
stage.innerHTML = '<div class="hero">' + face(false) + '<h1 class="jit">Welcome to your Comfort Setup</h1></div>' +
'<p class="n1">Answer a few quick things and we will tune this page to your exact level of calm.</p>' +
'<p class="tiny n2">Estimated time: 4 minutes. Actual time: see the last page.</p>' +
'<div class="tiles"><div>Neat ✓</div><div>Tidy ✓</div><div>Aligned ✓</div></div>' +
'<div id="pad"><button class="btn" id="go">Start</button></div>' +
'<p id="dc" aria-live="polite">Press Start whenever you are ready.</p>';
jitAll(stage);
const pad = $('#pad'), btn = $('#go'), dc = $('#dc');
let cx = pad.clientWidth / 2, cy = pad.clientHeight / 2;
const quips = ['Too slow.', 'Nope, over here.', 'Almost had it.', 'It moved. Not our fault.', 'Missed by a pixel.', 'Try being quicker.', 'Rude, honestly.'];
function dodge() {
last = Date.now(); dodges++; st.dodges++;
const W = pad.clientWidth, H = pad.clientHeight, hw = btn.offsetWidth / 2 + 8, hh = btn.offsetHeight / 2 + 8;
let x, y, n = 0;
do {
x = rnd(hw, Math.max(hw, W - hw)); y = rnd(hh, Math.max(hh, H - hh));
} while (++n < 14 && Math.hypot(x - cx, y - cy) < 100);
cx = x; cy = y; btn.style.left = x + 'px'; btn.style.top = y + 'px';
blip(540 - dodges * 35, .14, 'sine', .03, 150);
if (dodges >= NEED) {
tired = true; btn.classList.add('tired'); btn.textContent = 'Okay… fine.';
dc.textContent = 'It has given up. Press it gently.';
} else dc.textContent = quips[(dodges - 1) % quips.length] + ' (dodged ' + dodges + ')';
}
// touch: it leaves the moment a finger lands. mouse: it also leaves when the pointer gets close.
btn.addEventListener('pointerdown', () => { if (!tired) dodge(); });
pad.addEventListener('pointermove', e => {
if (tired || e.pointerType !== 'mouse' || Date.now() - last < 450) return;
const r = btn.getBoundingClientRect();
if (Math.hypot(e.clientX - r.left - r.width / 2, e.clientY - r.top - r.height / 2) < 90) dodge();
});
btn.addEventListener('click', () => {
if (!tired || done) return;
done = true; blip(660, .2); dc.textContent = 'Thank you. That was not so hard.';
after(500, () => show(1));
});
}
/* ---------- screen 2: cookie notices that multiply ---------- */
function s1() {
let budget = demo ? 2 : 6, alive = 1, done = false, z = 1;
stage.innerHTML = '<h2 class="jit">Before we begin: cookies</h2>' +
'<p class="n2">We need your permission to remember that you were here.</p>' +
'<p class="tiny" id="cc" aria-live="polite"></p>' +
'<div id="zone"><div class="ph">' + '<i></i>'.repeat(14) + '</div></div>';
jitAll(stage);
const zone = $('#zone'), cc = $('#cc');
const heads = ['We value your privacy', 'Also: cookies', 'Cookie notice (the sequel)', 'Another cookie notice', 'A notice about the notices', 'Still us. The cookies.', 'Last one. Probably.'];
const texts = ['We use cookies to remember that you visited. You are visiting.', 'These cookies are crunchy and legally required.', 'You already accepted, but we like hearing it.', 'Our previous notice felt lonely.', 'Choosing either button counts as choosing both.'];
const count = () => { cc.textContent = alive > 0 ? 'Notices needing your attention: ' + alive : 'All notices dealt with.'; };
function note() {
const b = document.createElement('div');
b.className = 'ck';
b.style.cssText = 'left:' + rnd(2, 12).toFixed(1) + '%;top:' + rnd(2, 48).toFixed(1) + '%;transform:rotate(' + rnd(-2.6, 2.6).toFixed(1) + 'deg);z-index:' + (++z);
b.innerHTML = '<h4>' + pick(heads) + '</h4><p>' + pick(texts) + '</p><div class="rw"><button class="btn sm">Accept all</button><button class="btn sm alt">Reject all</button></div>';
b.querySelectorAll('button').forEach(x => x.addEventListener('click', () => hit(b)));
zone.appendChild(b); blip(360 + z * 30, .12, 'triangle', .03);
}
function hit(b) {
if (b.dataset.x) return;
b.dataset.x = '1'; b.classList.add('out'); st.cookies++;
after(240, () => b.remove());
const n = Math.min(2, budget); budget -= n; alive += n - 1; // each answer buys two more notices, until the supply runs out
for (let i = 0; i < n; i++) after(170 + i * 150, note);
count();
if (alive < 1 && !done) { done = true; toast('That was the last cookie notice. Probably.'); after(900, () => show(2)); }
}
note(); count();
}
/* ---------- screen 3: a Close button that spawns another Close button ---------- */
function s2() {
const total = demo ? 3 : 5;
let n = 0, z = 1;
stage.innerHTML = '<h2 class="jit">One tiny announcement</h2>' +
'<p class="n1">Please close it when you have finished reading.</p>' +
'<p class="tiny" id="pc" aria-live="polite"></p>' +
'<div id="zone"><div class="ph">' + '<i></i>'.repeat(14) + '</div></div>';
jitAll(stage);
const zone = $('#zone'), pc = $('#pc');
const P = [['Join our newsletter!', 'Be the fourth person to read it. Weekly. Sometimes daily.'], ['Are you sure you want to close that?', 'It was doing so well.'], ['Rate your closing experience', '★★★★★ (optional, and compulsory)'], ['Please confirm the closing', 'To confirm closing, please close this.'], ['Final popup', 'Truly. We checked. Twice.']];
function pop() {
const k = n++, pos = [0, 1, 4, 2, 3][k % 5], atTop = pos === 0 || pos === 4, isLast = k === total - 1;
const b = document.createElement('div');
b.className = 'pop';
b.style.cssText = 'left:' + (rnd(3, 9) + k * 1.2).toFixed(1) + '%;top:' + (6 + k * 7 + rnd(0, 5)).toFixed(1) + '%;transform:rotate(' + rnd(-2.4, 2.4).toFixed(1) + 'deg);z-index:' + (++z);
const row = '<div class="row ' + ['r', 'l', 'r', 'c', 'l'][pos] + '"><button class="btn sm cl">' + (isLast ? 'Close (really)' : 'Close') + '</button></div>';
b.innerHTML = (atTop ? row : '') + '<h3>' + P[k % 5][0] + '</h3><p>' + P[k % 5][1] + '</p>' + (atTop ? '' : row);
b.querySelector('.cl').addEventListener('click', () => shut(b, isLast));
zone.appendChild(b); pc.textContent = 'Windows open: ' + (k + 1); blip(300 + k * 45, .14, 'triangle', .03);
}
function shut(b, isLast) {
if (b.dataset.x) return;
b.dataset.x = '1'; b.classList.add('dead'); st.closes++;
if (!isLast) {
toast(pick(['Closed. And now another.', 'Close accepted. Replacement opening.', 'Closing detected. Please close again.']));
pop(); return;
}
pc.textContent = 'Windows open: 0';
zone.querySelectorAll('.pop').forEach((p, i) => after(i * 90, () => p.classList.add('out')));
toast('Everything is closed. Truly.'); blip(660, .22);
after(1200, () => show(3));
}
pop();
}
/* ---------- screen 4: the progress bar that slides back at 99% ---------- */
function s3() {
stage.innerHTML = '<h2 class="jit">Installing Comfort™</h2>' +
'<p class="n2">Please keep this page open. It enjoys the company.</p>' +
'<div class="bar" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"><div id="fill"></div><b id="pct">0%</b></div>' +
'<p id="msg" aria-live="polite"></p>' +
'<ul id="tasks"><li>Straightening the pictures (one resists)</li><li>Aligning the text (give or take a pixel)</li><li>Folding the towels (corners do not meet)</li><li>Making everything perfectly tidy</li></ul>' +
'<button class="btn alt sm" id="fast">Make it faster (3)</button>';
jitAll(stage);
const fill = $('#fill'), pct = $('#pct'), msg = $('#msg'), bar = $('.bar'), fast = $('#fast');
const li = [...stage.querySelectorAll('#tasks li')], TH = [18, 42, 70, 100];
const S = demo
? [[99, 1200, 'Warming up the pixels…'], [99, 600, 'Almost there…'], [64, 500, 'Oops. A small setback.'], [99, 900, 'Again, slightly angrier.'], [99, 450, 'So close…'], [100, 500, 'Done. Honestly.']]
: [[99, 4200, 'Warming up the pixels…'], [99, 1200, 'Almost there…'], [62, 900, 'Oops. A small setback.'], [99, 2600, 'Trying again, slightly angrier.'], [99, 1100, 'So close. Hold on.'], [80, 800, 'Rewinding, to be safe.'], [99, 2000, 'This time for real.'], [99, 800, 'Just a moment…'], [100, 800, 'Done. Honestly.']];
let i = 0, v0 = 0, v = 0, t0 = performance.now(), left = 3, fin = false;
const g = gen;
msg.textContent = S[0][2];
function render() {
const r = Math.floor(v + .0001);
fill.style.width = v + '%'; pct.textContent = r + '%'; bar.setAttribute('aria-valuenow', r);
li.forEach((el, k) => el.classList.toggle('on', v >= TH[k])); // ticks un-tick when the bar slides back
}
function frame(now) {
if (g !== gen) return;
const seg = S[i], p = Math.max(0, Math.min(1, (now - t0) / seg[1])), back = seg[0] < v0;
v = p >= 1 ? seg[0] : v0 + (seg[0] - v0) * (back ? p * p * (3 - 2 * p) : p);
render();
if (p >= 1) {
if (++i >= S.length) {
fin = true; fast.disabled = true;
blip(660, .25); after(180, () => blip(880, .35));
after(900, () => show(4));
return;
}
if (S[i][0] < v) { st.back++; blip(430, .6, 'sine', .035, -260); }
v0 = v; t0 = now; msg.textContent = S[i][2];
}
requestAnimationFrame(frame);
}
fast.addEventListener('click', () => {
if (left < 1 || fin) return;
left--; v0 = Math.max(0, v - 4); v = v0; t0 = performance.now();
fast.textContent = left ? 'Make it faster (' + left + ')' : 'Already as fast as it gets';
if (!left) fast.disabled = true;
msg.textContent = 'Making it faster. This may take longer.';
blip(300, .2, 'sine', .03, -80); render();
});
render();
requestAnimationFrame(frame);
}
/* ---------- screen 5: thank you ---------- */
function s4() {
document.body.classList.add('straight');
const secs = Math.max(0, Math.round((Date.now() - st.t0) / 1000));
const tm = Math.floor(secs / 60) + ':' + String(secs % 60).padStart(2, '0');
let times = 1;
if (!demo) { times = (parseInt(sget('patience'), 10) || 0) + 1; sset('patience', String(times)); }
stage.innerHTML = '<div class="fin">' + badge + '<h1>Thank you for your patience</h1>' +
'<p>Everything is now perfectly straight. We checked. Twice.</p>' +
'<ul class="stats"><li>Buttons that dodged you<b>' + st.dodges + '</b></li><li>Cookie notices dealt with<b>' + st.cookies + '</b></li><li>Windows closed<b>' + st.closes + '</b></li><li>Setbacks at 99%<b>' + st.back + '</b></li><li>Time well spent<b>' + tm + '</b></li></ul>' +
'<p class="tiny n2">' + (demo ? 'This was a demo. Touch anywhere to try it yourself.' : 'Times you have been this patient: ' + times) + '</p>' +
'<button class="btn" id="again">Do it all again</button></div>';
$('#again').addEventListener('click', restart);
blip(523, .3); after(160, () => blip(659, .3)); after(320, () => blip(784, .5));
}
/* ---------- the hands-free demo: a ghost finger driving the real screens ---------- */
function tap(el, cb) {
try { el.scrollIntoView({ block: 'nearest' }); } catch (e) {}
const r = el.getBoundingClientRect();
ghost.classList.add('on');
ghost.style.transform = 'translate(' + (r.left + r.width / 2) + 'px,' + (r.top + r.height / 2) + 'px)';
after(470, () => {
ghost.classList.remove('tap'); void ghost.offsetWidth; ghost.classList.add('tap');
el.dispatchEvent(new Event('pointerdown', { bubbles: true }));
after(90, () => { if (el.isConnected) el.click(); if (cb) cb(); });
});
}
const chase = (sel, gap) => { const b = lastOf(sel); if (b) tap(b, () => after(gap, () => chase(sel, gap))); };
const DEMO = [
() => after(500, () => chase('#go', 330)),
() => after(600, () => chase('.ck:not(.out) .btn:not(.alt)', 420)),
() => after(700, () => chase('.pop:not(.dead) .cl', 380)),
() => {},
() => after(3300, restart)
];
function show(n) {
gen++;
stepEl.textContent = STEPS[n];
stage.className = ''; void stage.offsetWidth; stage.className = 'in';
try { scrollTo(0, 0); } catch (e) {}
if (demo) ghost.classList.remove('on');
[s0, s1, s2, s3, s4][n]();
if (demo) DEMO[n]();
}
function restart() {
document.body.classList.remove('straight');
st = { dodges: 0, cookies: 0, closes: 0, back: 0, t0: Date.now() };
show(0);
}
const isDemoUrl = () => location.href.endsWith('#demo') || location.hash === '#demo';
function startDemo() { demo = true; document.body.classList.add('demo'); restart(); }
function endDemo() {
if (!demo) return;
demo = false; document.body.classList.remove('demo'); ghost.classList.remove('on');
restart();
}
// any real touch, click or press ends the demo (synthetic events from the demo itself are not trusted)
['pointerdown', 'touchstart', 'mousedown'].forEach(t => addEventListener(t, e => { if (demo && e.isTrusted) endDemo(); }, true));
addEventListener('hashchange', () => { if (isDemoUrl()) { if (!demo) startDemo(); } else endDemo(); });
/* ---------- small extras ---------- */
$('#back').addEventListener('click', () => toast(pick(['Back is facing forward today.', 'Back is under maintenance.', 'There is no back. Only mildly onward.', 'Back left a note: "brb".'])));
$('#snd').addEventListener('click', e => {
snd = !snd; e.currentTarget.textContent = 'Sound: ' + (snd ? 'on' : 'off'); sset('snd', snd ? '1' : '0');
if (snd) blip(520);
});
if (sget('snd') === '0') { snd = false; $('#snd').textContent = 'Sound: off'; }
const tips = ['Tip: blinking is optional.', 'Tip: everything is exactly where you left it, plus one pixel.', 'Tip: the Back button is shy.', 'Tip: sit up straight. We will not.', 'Tip: this page is 98.6% on your side.', 'Tip: if a button runs away, it likes you.', 'Tip: nothing here is crooked. You are tilting.'];
const tipEl = $('#tip');
let ti = 0;
tipEl.textContent = tips[0];
setInterval(() => {
tipEl.style.opacity = '0';
setTimeout(() => { ti = (ti + 1) % tips.length; tipEl.textContent = tips[ti]; tipEl.style.opacity = '1'; }, 650);
}, 5200);
if (isDemoUrl()) startDemo(); else restart();
})();
</script>
</body>
</html>
