Back to the app
The code
The Most Uncomfortable Web Page by Claude Fable 5.2
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>ComfortCheck Setup</title>
<style>
:root{
--bg:#efece3; --card:#fffdf7; --ink:#24272e; --mute:#686d79; --line:#d8d2c3;
--blue:#3565d4; --blue2:#3d6ce0; --blueD:#27489e; --gold:#f2b84b; --ok:#2c9667;
}
*,*::before,*::after{ box-sizing:border-box; }
/* The mouse pointer is mirrored. Its tip is still accurate. */
html{ cursor:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Cpath d='M20 2v17l-4.5-4.2-2.9 6.7-2.6-1.2 2.9-6.5-5.9-.2z' fill='white' stroke='black' stroke-width='1.4' stroke-linejoin='round'/%3E%3C/svg%3E") 20 2, auto; }
html,body{ margin:0; padding:0; overflow-x:hidden; }
body{
min-height:100vh;
font-family:system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
font-size:16px; line-height:1.45; color:var(--ink);
background-color:var(--bg);
/* graph paper whose squares are not quite square */
background-image:
linear-gradient(rgba(36,39,46,.05) 1px, transparent 1px),
linear-gradient(90deg, rgba(36,39,46,.05) 1px, transparent 1px);
background-size:100% 25px, 24px 100%;
-webkit-tap-highlight-color:transparent; -webkit-text-size-adjust:100%;
touch-action:manipulation;
}
button{ font-family:inherit; cursor:inherit; }
.hidden{ display:none !important; }
#app{ width:100%; max-width:580px; margin:0 auto; padding:12px 14px 28px; }
/* ---------- top bar ---------- */
.top{ display:flex; align-items:center; justify-content:space-between; gap:8px; min-height:48px; }
.logo{ display:flex; align-items:center; gap:8px; font-weight:800; font-size:17px; letter-spacing:-.01em; white-space:nowrap; }
.logo-mark{ position:relative; flex:0 0 auto; width:24px; height:23px; border-radius:6px 6px 6px 9px; background:var(--blue); transform:rotate(3deg); }
.logo-mark::after{ content:""; position:absolute; left:6px; top:6px; width:13px; height:7px; border-left:3px solid #fff; border-bottom:3px solid #fff; transform:rotate(-47deg); }
.logo sup{ font-size:8px; font-weight:600; margin-left:4px; position:relative; top:-2px; }
.top-right{ display:flex; align-items:center; gap:6px; }
.bell{ position:relative; width:42px; height:42px; border:none; background:transparent; padding:0; border-radius:50%; touch-action:manipulation; }
.bell svg{ width:24px; height:24px; fill:none; stroke:var(--ink); stroke-width:1.8; stroke-linecap:round; stroke-linejoin:round; transform:rotate(-6deg); }
.badge{ position:absolute; right:1px; top:3px; min-width:18px; height:18px; padding:0 5px; border-radius:9px; background:#d2574c; color:#fff; font-size:11px; font-weight:700; line-height:18px; text-align:center; }
.chip{ min-height:40px; padding:6px 12px 6px 13px; border-radius:999px; border:1.5px solid var(--line); background:#fff; color:var(--ink); font-size:13px; font-weight:600; white-space:nowrap; touch-action:manipulation; }
.steps{ display:flex; align-items:center; justify-content:space-between; gap:10px; margin:6px 2px 10px 3px; min-height:22px; font-size:13px; font-weight:600; color:var(--mute); }
.dots{ display:flex; align-items:center; }
.dots i{ display:block; position:relative; width:9px; height:9px; margin-left:7px; border-radius:50%; border:1.5px solid var(--mute); }
.dots i.on{ background:var(--blue); border-color:var(--blue); }
.dots i:nth-child(3){ margin-left:10px; top:1px; }
.dots i:nth-child(4){ width:10px; height:10px; }
.dots i:nth-child(n+6){ border-radius:3px; transform:rotate(9deg); }
/* ---------- the card (a tiny bit crooked) ---------- */
.card{
background:var(--card); border:1px solid var(--line); border-left-width:2px;
border-radius:18px 18px 18px 22px; padding:18px 18px 20px 19px;
box-shadow:0 10px 30px rgba(36,39,46,.08);
transform:rotate(-.35deg); transition:transform .9s cubic-bezier(.3,1.35,.5,1);
}
.card.tilted{ transform:rotate(1.4deg); }
.card.calm{ transform:none; }
.scene{ display:none; }
.scene.active{ display:block; animation:sceneIn .4s ease both; }
@keyframes sceneIn{ from{ opacity:0; transform:translateY(8px); } to{ opacity:1; transform:none; } }
h1{ font-size:24px; line-height:1.2; margin:2px 0 10px 2px; letter-spacing:-.015em; }
p{ margin:0 0 10px; }
.lead{ color:var(--mute); }
.uline{ text-decoration:underline; text-decoration-thickness:1px; text-underline-offset:3px; }
.px-down{ position:relative; top:1px; }
.px-up{ position:relative; top:-1px; }
.px-right{ position:relative; left:1px; }
.serif-one{ font-family:Georgia,"Times New Roman",serif; }
.rule{ height:2px; margin:0 9px 12px 0; background:var(--line); border-radius:2px; transform:rotate(.35deg); }
.msg{ min-height:1.5em; margin:12px 0 10px 1px; font-size:15px; color:var(--mute); }
.counter{ margin:10px 0 0; font-size:15px; }
.counter b{ position:relative; top:1px; font-size:18px; font-variant-numeric:tabular-nums; }
.tiny{ font-size:12.5px; color:var(--mute); }
/* ---------- buttons: text not quite centred, one corner rounder ---------- */
.btn{
-webkit-appearance:none; appearance:none; display:inline-flex; align-items:center; justify-content:center; gap:8px;
min-height:52px; padding:12px 22px 12px 25px;
font-size:17px; font-weight:650; color:var(--ink);
background:#fff; border:2px solid var(--ink); border-radius:12px 12px 12px 15px;
box-shadow:0 3px 0 var(--ink);
touch-action:manipulation; -webkit-user-select:none; user-select:none;
transition:transform .12s, box-shadow .12s;
}
.btn:active{ transform:translateY(-2px); } /* it goes up when pressed. sorry. */
.btn.primary{ background:var(--blue); color:#fff; border-color:var(--blueD); box-shadow:0 3px 0 var(--blueD); }
.btn.ghost{ background:transparent; }
.btn.small{ min-height:44px; padding:8px 14px 8px 16px; font-size:15px; }
.crooked{ transform:rotate(-1.4deg); }
.crooked:active{ transform:rotate(-1.4deg) translateY(-2px); }
.linkbtn{ min-height:44px; padding:8px 6px; background:none; border:none; color:var(--mute); font-size:14px; text-decoration:underline; touch-action:manipulation; }
.ico{ width:20px; height:20px; flex:0 0 auto; fill:none; stroke:currentColor; stroke-width:2.2; stroke-linecap:round; stroke-linejoin:round; }
.ico.flip{ transform:scaleX(-1); }
/* ---------- scene 0: the shy Start button ---------- */
.arena{ position:relative; height:clamp(190px, 36vh, 280px); margin-top:12px; overflow:hidden; background:#faf6ec; border:2px dashed var(--line); border-radius:14px; touch-action:manipulation; -webkit-user-select:none; user-select:none; }
.arena-hint{ position:absolute; left:0; right:0; bottom:8px; text-align:center; font-size:13px; color:var(--mute); pointer-events:none; }
.dodge{ position:absolute; left:0; top:0; padding:13px 30px 13px 33px; font-size:19px; white-space:nowrap; transform:rotate(var(--rot,0deg)); transition:left .2s cubic-bezier(.2,.8,.3,1.15), top .2s cubic-bezier(.2,.8,.3,1.15), transform .2s; }
.dodge:active{ transform:rotate(var(--rot,0deg)); }
.dodge.tired{ animation:pant 1.5s ease-in-out infinite; }
@keyframes pant{ 0%,100%{ transform:rotate(var(--rot,0deg)) scale(1); } 50%{ transform:rotate(var(--rot,0deg)) scale(1.045); } }
/* ---------- scene 1: cookie notices ---------- */
#cookieLayer{ position:fixed; left:0; right:0; top:0; bottom:0; pointer-events:none; z-index:60; }
.cookie{
position:absolute; left:50%; bottom:10px; width:min(92vw, 430px); padding:12px 14px;
background:#2b2e36; color:#f3efe6; border-radius:14px 14px 17px 14px; box-shadow:0 8px 24px rgba(0,0,0,.22);
pointer-events:auto;
transform:translateX(calc(-50% + var(--dx,0px))) rotate(var(--rot,0deg));
animation:cookieIn .26s ease-out backwards;
}
.cookie.out{ animation:cookieOut .28s ease-in forwards; pointer-events:none; }
@keyframes cookieIn{
from{ opacity:0; transform:translateX(calc(-50% + var(--dx,0px))) translateY(34px) rotate(var(--rot,0deg)); }
to{ opacity:1; transform:translateX(calc(-50% + var(--dx,0px))) translateY(0) rotate(var(--rot,0deg)); }
}
@keyframes cookieOut{
from{ opacity:1; transform:translateX(calc(-50% + var(--dx,0px))) translateY(0) rotate(var(--rot,0deg)); }
to{ opacity:0; transform:translateX(calc(-50% + var(--dx,0px))) translateY(40px) rotate(var(--rot,0deg)); }
}
.cookie-row{ display:flex; align-items:flex-start; gap:12px; }
.cookie-row p{ margin:0 0 10px; font-size:14.5px; line-height:1.35; }
.cookie-ico{
flex:0 0 34px; width:34px; height:33px; border-radius:50% 48% 52% 50%;
background:
radial-gradient(circle at 30% 30%, #5a3a1c 0 3px, transparent 4px),
radial-gradient(circle at 66% 40%, #5a3a1c 0 3.5px, transparent 4.5px),
radial-gradient(circle at 44% 70%, #5a3a1c 0 3px, transparent 4px),
radial-gradient(circle at 76% 72%, #5a3a1c 0 2.5px, transparent 3.5px),
#d9a45b;
}
.cookie-btns{ display:flex; justify-content:flex-end; gap:10px; }
.cookie .btn.ghost{ color:#f3efe6; border-color:#8c909c; box-shadow:0 3px 0 #8c909c; }
.cookie .btn.primary{ min-height:45px; }
/* ---------- scene 2: the Close button hydra ---------- */
.popup{
position:relative; min-height:250px; padding:58px 16px 16px 18px;
background:#fff6da; border:2px solid var(--ink); border-radius:14px 14px 14px 18px; box-shadow:5px 6px 0 rgba(36,39,46,.14);
transform:rotate(.7deg); transition:transform .45s ease, opacity .45s ease;
}
.popup.closed{ transform:rotate(5deg) translateY(16px) scale(.94); opacity:0; }
.popup-title{ margin-bottom:6px; font-size:20px; font-weight:800; }
.closeb{ position:absolute; left:0; top:0; white-space:nowrap; transform:rotate(var(--rot,0deg)); animation:closeIn .22s ease-out backwards; }
.closeb:active{ transform:rotate(var(--rot,0deg)) translateY(-2px); }
.closeb.pop{ animation:closeOut .24s ease-in forwards; pointer-events:none; }
@keyframes closeIn{ from{ opacity:0; transform:rotate(var(--rot,0deg)) scale(.5); } to{ opacity:1; transform:rotate(var(--rot,0deg)) scale(1); } }
@keyframes closeOut{ from{ opacity:1; transform:rotate(var(--rot,0deg)) scale(1); } to{ opacity:0; transform:rotate(var(--rot,0deg)) scale(.3); } }
/* ---------- scene 3: the progress bar ---------- */
.prog{ padding:8px 0 4px; }
.prog-top{ display:flex; align-items:center; gap:10px; font-weight:600; }
.spinner{ flex:0 0 auto; width:20px; height:19px; border:3px solid var(--line); border-top-color:var(--blue); border-radius:50% 46% 52% 48%; animation:spin 1.9s cubic-bezier(.55,-.25,.4,1.25) infinite; }
@keyframes spin{ to{ transform:rotate(360deg); } }
.pct{ margin-left:auto; position:relative; top:1px; font-size:22px; font-variant-numeric:tabular-nums; }
.track{ position:relative; height:26px; margin:12px 4px 8px 0; background:#fff; border:2px solid var(--ink); border-radius:13px 13px 13px 16px; transform:rotate(-.5deg); }
.fill{ position:absolute; left:-1px; top:1px; bottom:-1px; width:0; border-radius:11px; background:repeating-linear-gradient(115deg, var(--blue) 0 14px, var(--blue2) 14px 27px); }
.prog-eta{ min-height:1.4em; margin-left:3px; font-size:13.5px; color:var(--mute); }
/* ---------- scene 4: boxes and swapping buttons ---------- */
.check{ display:flex; align-items:center; gap:14px; width:100%; min-height:58px; margin:0 0 10px; padding:10px 12px; background:#fff; border:2px solid var(--line); border-radius:12px; font-size:16px; color:inherit; text-align:left; touch-action:manipulation; -webkit-user-select:none; user-select:none; }
.check:nth-child(2){ margin-left:3px; width:calc(100% - 1px); }
.box{ position:relative; flex:0 0 28px; width:28px; height:28px; background:#fff; border:2px solid var(--ink); border-radius:6px; }
.check:nth-child(2) .box{ flex-basis:29px; width:29px; }
.check:nth-child(3) .box{ border-radius:6px 6px 6px 10px; transform:rotate(2.5deg); }
.tick{ position:absolute; left:3px; top:-8px; width:31px; height:29px; fill:none; stroke:var(--ok); stroke-width:4; stroke-linecap:round; stroke-linejoin:round; opacity:0; transform:scale(.6); transition:opacity .15s, transform .15s; }
.check.on .tick{ opacity:1; transform:scale(1); }
.swap{ display:grid; grid-template-columns:1fr 1fr; gap:12px; margin-top:6px; }
.swap .btn{ width:100%; padding-left:10px; padding-right:10px; white-space:nowrap; transition:transform .16s ease; }
.swap.swapped #agreeBtn{ transform:translateX(calc(100% + 12px)); }
.swap.swapped #overBtn{ transform:translateX(calc(-100% - 12px)); }
/* ---------- scene 5: the picture ---------- */
.wall{ position:relative; height:226px; overflow:hidden; border:2px solid var(--line); border-radius:12px; background:repeating-linear-gradient(90deg, #ece5d3 0 22px, #e7dfcb 22px 45px); }
.nail{ position:absolute; left:50%; top:14px; width:8px; height:8px; margin-left:-4px; border-radius:50%; background:#55504a; z-index:2; }
.frame{ position:absolute; left:50%; top:18px; width:190px; height:146px; margin-left:-95px; background:#fff; border:9px solid #7a5230; box-shadow:0 6px 14px rgba(0,0,0,.2); transform-origin:50% 0; transform:rotate(3deg); transition:transform .5s cubic-bezier(.3,1.5,.5,1); }
.frame svg{ display:block; width:100%; height:100%; }
.skirting{ position:absolute; left:0; right:0; bottom:0; height:30px; background:#cdbfa3; border-top:2px solid #b8a988; }
.tiltread{ position:absolute; left:0; right:0; bottom:5px; text-align:center; font-size:13.5px; font-weight:600; color:#4d463a; }
.tiltbtns{ display:grid; grid-template-columns:1fr 1fr; gap:12px; margin-top:12px; }
.tiltbtns .btn{ padding-left:8px; padding-right:8px; white-space:nowrap; }
/* ---------- scene 6: thank you ---------- */
.cert{ position:relative; padding:22px 16px 16px; text-align:center; background:#fffef9; border:3px double var(--ink); border-radius:12px; }
.cert-kicker{ margin-bottom:8px; font-size:12px; font-weight:700; letter-spacing:.18em; text-transform:uppercase; color:var(--mute); }
.thanks{ margin:0 0 10px; font-size:30px; }
.stats{ list-style:none; max-width:350px; margin:14px auto 6px; padding:0; text-align:left; font-size:14.5px; }
.stats li{ display:flex; justify-content:space-between; gap:12px; padding:6px 0; border-bottom:1px dashed var(--line); }
.stats li b{ white-space:nowrap; font-variant-numeric:tabular-nums; }
.seal{ display:flex; align-items:center; justify-content:center; width:76px; height:76px; margin:14px auto 6px; border-radius:50%; border:3px solid var(--gold); color:#9a6a14; font-size:11.5px; font-weight:800; line-height:1.15; background:radial-gradient(circle, #fff6dc 0 60%, #fbe6ad 61% 100%); transform:rotate(-9deg); }
.seal-note{ font-size:12px; color:var(--mute); }
.rate{ margin:16px 0 4px; text-align:center; }
.rate p{ margin-bottom:4px; }
.stars{ display:flex; justify-content:center; gap:4px; }
.star{ width:48px; height:48px; padding:6px; border:none; background:none; touch-action:manipulation; }
.star svg{ width:100%; height:100%; fill:#fff; stroke:var(--ink); stroke-width:1.6; stroke-linejoin:round; transition:fill .2s; }
.star.on svg{ fill:var(--gold); }
.again-row{ margin-top:4px; text-align:center; }
/* slow, quiet confetti (one piece goes the wrong way) */
#confetti{ display:none; position:fixed; left:0; right:0; top:0; bottom:0; overflow:hidden; pointer-events:none; z-index:5; }
#confetti.on{ display:block; }
#confetti i{ position:absolute; top:-26px; width:9px; height:13px; border-radius:2px; opacity:.8; animation-name:fall; animation-timing-function:linear; animation-iteration-count:infinite; }
@keyframes fall{ from{ transform:translate3d(0,-30px,0) rotate(0deg); } to{ transform:translate3d(var(--sway,20px),112vh,0) rotate(var(--spin,300deg)); } }
/* ---------- footer ---------- */
.foot{ margin:18px 4px 0 6px; font-size:12.5px; color:var(--mute); }
.tiles{ display:flex; flex-wrap:wrap; align-items:center; gap:7px; }
.tile{ flex:0 0 auto; width:30px; height:30px; padding:0; border:none; border-radius:7px; background:#c9c2b0; touch-action:manipulation; transform:rotate(var(--r,0deg)); transition:transform .25s cubic-bezier(.3,1.5,.5,1); }
.tile:nth-child(3){ position:relative; top:1px; }
.tile:nth-child(7){ width:31px; background:#c5beac; }
.foot-note{ min-height:1.4em; margin:8px 0 10px; }
.eta{ font-weight:600; }
.fine{ margin-top:4px; }
/* ---------- floating bits ---------- */
#toast{ position:fixed; left:50%; top:52px; z-index:800; max-width:88vw; padding:10px 16px; background:#24272e; color:#fff; font-size:14px; text-align:center; border-radius:10px; opacity:0; transform:translateX(-50%) translateY(-12px); transition:opacity .25s, transform .25s; pointer-events:none; }
#toast.show{ opacity:.96; transform:translateX(-50%) translateY(0); }
#demoBadge{ display:none; position:fixed; left:50%; top:8px; z-index:900; padding:7px 14px; background:#24272e; color:#fff; font-size:13px; white-space:nowrap; border-radius:999px; opacity:.92; transform:translateX(-50%); pointer-events:none; }
body.demo #demoBadge{ display:block; }
#finger{ display:none; position:fixed; left:0; top:0; z-index:950; width:44px; height:44px; pointer-events:none; transition-property:transform; transition-timing-function:cubic-bezier(.4,0,.2,1); transition-duration:0ms; }
body.demo #finger{ display:block; }
#finger i{ position:absolute; left:0; top:0; right:0; bottom:0; border-radius:50%; background:rgba(36,39,46,.28); border:3px solid rgba(255,255,255,.92); box-shadow:0 2px 10px rgba(0,0,0,.25); transition:transform .1s, background-color .1s; }
#finger.down i{ transform:scale(.72); background:rgba(53,101,212,.5); }
@media (max-width:380px){
h1{ font-size:21px; }
.thanks{ font-size:25px; }
.logo{ font-size:15.5px; }
.chip{ padding:6px 9px; font-size:12px; }
.card{ padding:16px 14px 18px 15px; }
}
@media (prefers-reduced-motion:reduce){
#confetti{ display:none !important; }
.dodge.tired{ animation:none; }
}
</style>
</head>
<body>
<div id="demoBadge">Demo · tap anywhere to try it yourself</div>
<div id="finger" aria-hidden="true"><i></i></div>
<div id="toast" role="status" aria-live="polite"></div>
<div id="confetti" aria-hidden="true"></div>
<div id="cookieLayer"></div>
<div id="app">
<header class="top">
<div class="logo">
<span class="logo-mark" aria-hidden="true"></span>
<span class="logo-text">Comfort<span class="px-down">C</span>heck<sup>TM</sup></span>
</div>
<div class="top-right">
<button type="button" class="bell" id="bellBtn" aria-label="Notifications">
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M6 16v-6a6 6 0 0 1 12 0v6l1.5 2h-15z"/><path d="M10 20.5a2 2 0 0 0 4 0"/></svg>
<span class="badge" id="badge">1</span>
</button>
<button type="button" class="chip" id="soundBtn">Sound off</button>
</div>
</header>
<div class="steps"><span id="stepLabel">Step 1 of 5</span><span class="dots" id="dots" aria-hidden="true"></span></div>
<main class="card" id="card">
<!-- 0: the Start button that dodges -->
<section class="scene" id="s0">
<h1>Welcome. This will <span class="px-down">only</span> take a m<span class="serif-one">o</span>ment.</h1>
<div class="rule"></div>
<p class="lead"><span class="uline">Every word on this page is <span class="px-down">perfectly</span> <span class="px-right">aligned</span>.</span></p>
<div class="arena" id="arena">
<button type="button" class="btn primary dodge" id="startBtn">Start</button>
<div class="arena-hint">The button is not nervous. You are nervous.</div>
</div>
<p class="msg" id="msg0" aria-live="polite"></p>
<button type="button" class="linkbtn" id="skipBtn">Skip setup</button>
</section>
<!-- 1: cookie notices that multiply -->
<section class="scene" id="s1">
<h1>One small f<span class="px-up">o</span>rmality</h1>
<div class="rule"></div>
<p>Before we continue, please deal with the cookie notice. There is only <span class="px-down">one</span>.</p>
<p class="counter">Cookie notices open: <b id="cookieCount">0</b></p>
<p class="msg" id="msg1" aria-live="polite"></p>
<button type="button" class="btn primary crooked hidden" id="cont1">Continue</button>
</section>
<!-- 2: a Close button that spawns Close buttons -->
<section class="scene" id="s2">
<h1>A quick message from <span class="px-down">us</span></h1>
<div class="rule"></div>
<div class="popup" id="popup">
<div class="popup-title">Wait! Before you go</div>
<p>(You were not going anywhere.) Would you like our newsletter about our other newsletter?</p>
<p class="tiny">To dismiss this message, simply press Close.</p>
</div>
<p class="counter">Close buttons left: <b id="closeCount">1</b></p>
<p class="msg" id="msg2" aria-live="polite"></p>
<button type="button" class="btn primary crooked hidden" id="cont2">Continue</button>
</section>
<!-- 3: the progress bar that slides back -->
<section class="scene" id="s3">
<h1>Installing your comf<span class="px-down">o</span>rt</h1>
<div class="rule"></div>
<div class="prog">
<div class="prog-top">
<span class="spinner" aria-hidden="true"></span>
<span id="progLabel">Installing comfort…</span>
<span class="pct" id="pct">0%</span>
</div>
<div class="track"><div class="fill" id="fill"></div></div>
<div class="prog-eta" id="progEta"></div>
</div>
<p class="msg" id="msg3" aria-live="polite"></p>
<button type="button" class="btn primary hidden" id="pushBtn">Push the last 1%</button>
<button type="button" class="btn primary crooked hidden" id="cont3">Continue</button>
</section>
<!-- 4: boxes that untick, buttons that swap -->
<section class="scene" id="s4">
<h1>Please tick all three b<span class="serif-one">o</span>xes</h1>
<div class="rule"></div>
<div class="checks" id="checks">
<button type="button" class="check" data-i="0" aria-pressed="false">
<span class="box"><svg class="tick" viewBox="0 0 26 24" aria-hidden="true"><path d="M5 13l5 5L22 4"/></svg></span>
<span>I have read the terms. (There are no terms.)</span>
</button>
<button type="button" class="check" data-i="1" aria-pressed="false">
<span class="box"><svg class="tick" viewBox="0 0 26 24" aria-hidden="true"><path d="M5 13l5 5L22 4"/></svg></span>
<span>I agree that I agreed.</span>
</button>
<button type="button" class="check" data-i="2" aria-pressed="false">
<span class="box"><svg class="tick" viewBox="0 0 26 24" aria-hidden="true"><path d="M5 13l5 5L22 4"/></svg></span>
<span>I am perfectly comfortable.</span>
</button>
</div>
<p class="msg" id="msg4" aria-live="polite"></p>
<div class="swap" id="swap">
<button type="button" class="btn primary" id="agreeBtn">Continue</button>
<button type="button" class="btn ghost" id="overBtn">Start over</button>
</div>
</section>
<!-- 5: the picture that is never straight -->
<section class="scene" id="s5">
<h1>Last thing: straighten the picture</h1>
<div class="rule"></div>
<div class="wall">
<div class="nail"></div>
<div class="frame" id="frame">
<svg viewBox="0 0 180 130" preserveAspectRatio="none" aria-hidden="true">
<rect width="180" height="130" fill="#cfe6f5"/>
<circle cx="136" cy="33" r="14" fill="#f6c453"/>
<path d="M0 95 Q40 60 85 92 T180 80 V130 H0Z" fill="#8fc48a"/>
<path d="M0 108 Q60 88 110 106 T180 100 V130 H0Z" fill="#6aa86a"/>
<rect x="40" y="84" width="20" height="16" fill="#f3efe6"/>
<path d="M37 85 L50 74 L63 85Z" fill="#c8553d"/>
<rect x="47" y="91" width="6" height="9" fill="#7a5230"/>
</svg>
</div>
<div class="skirting"></div>
<div class="tiltread" id="tiltRead"></div>
</div>
<div class="tiltbtns" id="tiltBtns">
<button type="button" class="btn" id="tiltL"><svg class="ico" viewBox="0 0 24 24" aria-hidden="true"><polyline points="1 4 1 10 7 10"/><path d="M3.51 15a9 9 0 1 0 2.13-9.36L1 10"/></svg>Turn left</button>
<button type="button" class="btn" id="tiltR">Turn right<svg class="ico flip" viewBox="0 0 24 24" aria-hidden="true"><polyline points="1 4 1 10 7 10"/><path d="M3.51 15a9 9 0 1 0 2.13-9.36L1 10"/></svg></button>
</div>
<p class="msg" id="msg5" aria-live="polite"></p>
<button type="button" class="btn primary crooked hidden" id="goodBtn">Good enough</button>
<button type="button" class="btn primary hidden" id="cont5">Finish</button>
</section>
<!-- 6: thank you -->
<section class="scene" id="s6">
<div class="cert">
<div class="cert-kicker">Certificate of Patience</div>
<h1 class="thanks">Thank you for your patience.</h1>
<p>You finished all 5 steps. There were 7. Everything on this screen is perfectly straight. You earned it.</p>
<ul class="stats" id="stats"></ul>
<div class="seal" aria-hidden="true">100%<br>PATIENT</div>
<div class="seal-note">Except the seal. The seal was applied by hand.</div>
</div>
<div class="rate">
<p>Rate your experience</p>
<div class="stars" id="stars"></div>
<p class="msg" id="msg6" aria-live="polite"></p>
</div>
<div class="again-row"><button type="button" class="btn" id="againBtn">Do it all again</button></div>
</section>
</main>
<footer class="foot">
<div class="tiles" id="tiles"></div>
<div class="foot-note" id="footNote">Decorative tiles. Please do not try to straighten them.</div>
<div class="eta" id="eta"></div>
<div class="fine">© ComfortCheck. All rights <span class="serif-one">s</span>lightly reserved. If you have a mouse: yes, its pointer is facing the wrong way.</div>
</footer>
</div>
<script>
(function () {
'use strict';
/* ================= helpers ================= */
var CANCEL = { cancelled: true };
function noop() {}
function $(s, r) { return (r || document).querySelector(s); }
function $$(s, r) { return Array.prototype.slice.call((r || document).querySelectorAll(s)); }
function rand(a, b) { return a + Math.random() * (b - a); }
function clamp(v, a, b) { return Math.max(a, Math.min(b, v)); }
function now() { return Date.now(); }
function show(el) { el.classList.remove('hidden'); }
function hide(el) { el.classList.add('hidden'); }
function easeOut(k) { return 1 - Math.pow(1 - k, 2.4); }
function easeInOut(k) { return k < 0.5 ? 2 * k * k : 1 - Math.pow(-2 * k + 2, 2) / 2; }
/* Every timer belongs to a "run". Restarting kills the old run. */
var run = { dead: false };
function newRun() { run.dead = true; run = { dead: false }; }
function later(ms, fn) { var r = run; setTimeout(function () { if (!r.dead) fn(); }, ms); }
function sleep(ms) {
var r = run;
return new Promise(function (res, rej) {
setTimeout(function () { if (r.dead) rej(CANCEL); else res(); }, ms);
});
}
function nextFrame(fn) {
var done = false;
function goNow() { if (done) return; done = true; fn(); }
if (window.requestAnimationFrame) window.requestAnimationFrame(goNow);
setTimeout(goNow, 70);
}
function tween(from, to, ms, fn, ease) {
var r = run;
ease = ease || easeInOut;
return new Promise(function (res, rej) {
var t0 = now();
function step() {
if (r.dead) { rej(CANCEL); return; }
var k = clamp((now() - t0) / ms, 0, 1);
fn(from + (to - from) * ease(k));
if (k < 1) nextFrame(step); else res();
}
nextFrame(step);
});
}
/* ================= elements ================= */
var body = document.body;
var card = $('#card'), scenes = $$('.scene');
var stepLabel = $('#stepLabel'), dotsEl = $('#dots'), etaEl = $('#eta');
var toastEl = $('#toast'), cookieLayer = $('#cookieLayer'), confettiEl = $('#confetti'), finger = $('#finger');
var arena = $('#arena'), startBtn = $('#startBtn'), msg0 = $('#msg0'), skipBtn = $('#skipBtn');
var cookieCount = $('#cookieCount'), msg1 = $('#msg1'), cont1 = $('#cont1');
var popup = $('#popup'), closeCount = $('#closeCount'), msg2 = $('#msg2'), cont2 = $('#cont2');
var fill = $('#fill'), pct = $('#pct'), progLabel = $('#progLabel'), progEta = $('#progEta'), msg3 = $('#msg3'), pushBtn = $('#pushBtn'), cont3 = $('#cont3');
var checksEl = $('#checks'), checkEls = $$('.check'), msg4 = $('#msg4'), swapEl = $('#swap'), agreeBtn = $('#agreeBtn'), overBtn = $('#overBtn');
var frame = $('#frame'), tiltRead = $('#tiltRead'), tiltBtns = $('#tiltBtns'), tiltL = $('#tiltL'), tiltR = $('#tiltR'), msg5 = $('#msg5'), goodBtn = $('#goodBtn'), cont5 = $('#cont5');
var statsEl = $('#stats'), starsEl = $('#stars'), msg6 = $('#msg6'), againBtn = $('#againBtn');
var tilesEl = $('#tiles'), footNote = $('#footNote'), bellBtn = $('#bellBtn'), badge = $('#badge'), soundBtn = $('#soundBtn');
var S = { scene: -1, demo: false, t0: now(), stats: { dodges: 0, cookies: 0, closes: 0, lost: 0, unticks: 0, tilts: 0 } };
/* ================= sound: off by default, very soft, slightly out of tune ================= */
var soundOn = false, actx = null;
function plink(freq, dur) {
if (!soundOn || S.demo) return;
try {
var AC = window.AudioContext || window.webkitAudioContext;
if (!AC) return;
if (!actx) actx = new AC();
if (actx.state === 'suspended') actx.resume();
dur = dur || 0.4;
var t = actx.currentTime;
var g = actx.createGain();
g.gain.setValueAtTime(0.0001, t);
g.gain.linearRampToValueAtTime(0.03, t + 0.04);
g.gain.exponentialRampToValueAtTime(0.0001, t + dur);
g.connect(actx.destination);
[freq, freq * 1.03].forEach(function (f) {
var o = actx.createOscillator();
o.type = 'sine';
o.frequency.setValueAtTime(f, t);
o.connect(g);
o.start(t);
o.stop(t + dur + 0.05);
});
} catch (e) {}
}
soundBtn.addEventListener('click', function () {
soundOn = !soundOn;
soundBtn.textContent = soundOn ? 'Sound on (quiet)' : 'Sound off';
if (soundOn) plink(587, 0.5);
});
/* ================= toast ================= */
var toastTimer = 0;
function toast(text) {
toastEl.textContent = text;
toastEl.classList.add('show');
clearTimeout(toastTimer);
toastTimer = setTimeout(function () { toastEl.classList.remove('show'); }, 2600);
}
/* ================= scene switching ================= */
var STEP_LABELS = ['Step 1 of 5', 'Step 2 of 5', 'Step 2 of 5 (still)', 'Step 4 of 5', 'Step 5 of 5', 'Step 6 of 5', 'Step 7 of 5 — done'];
var DOTS_ON = [1, 2, 2, 4, 5, 6, 7];
var ETAS = ['1 minute', '1 minute', '2 minutes', '1 minute (optimistic)', '3 minutes', 'under 1 minute, give or take 4', '0 minutes. You did it.'];
var ENTER = [];
function renderDots(n) {
var on = DOTS_ON[n], total = Math.max(5, on), h = '';
for (var i = 0; i < total; i++) h += '<i' + (i < on ? ' class="on"' : '') + '></i>';
dotsEl.innerHTML = h;
}
function showScene(n) {
S.scene = n;
for (var i = 0; i < scenes.length; i++) scenes[i].classList.toggle('active', i === n);
stepLabel.textContent = STEP_LABELS[n];
renderDots(n);
etaEl.textContent = 'Estimated time remaining: ' + ETAS[n];
card.classList.toggle('calm', n === 6);
card.classList.remove('tilted');
if (n !== 1) cookieLayer.innerHTML = '';
confettiEl.classList.toggle('on', n === 6);
try { window.scrollTo(0, 0); } catch (e) {}
ENTER[n]();
}
function go(n) { if (S.scene === n) return; showScene(n); }
function resetGame() {
newRun();
S.stats = { dodges: 0, cookies: 0, closes: 0, lost: 0, unticks: 0, tilts: 0 };
S.t0 = now();
S.scene = -1;
showScene(0);
}
/* ================= scene 0: the Start button dodges ================= */
var MAX_DODGE = 6;
var DODGE_MSG = [
'Oops. Missed.',
'So close.',
'It is a little shy.',
'Try to look like you do not want it.',
'It is getting tired…',
'OK. It gave up. Go ahead, press it.'
];
var SKIP_MSG = ['Skipping is not included in your plan.', 'Still not included.', 'We admire the persistence. No.'];
var dg = null, pos = { x: 0, y: 0 }, skips = 0;
function setStartPos(x, y, rot) {
pos.x = x; pos.y = y;
startBtn.style.left = Math.round(x) + 'px';
startBtn.style.top = Math.round(y) + 'px';
if (rot != null) startBtn.style.setProperty('--rot', rot + 'deg');
}
ENTER[0] = function () {
dg = { count: 0, tired: false, tiredAt: 0, cool: 0 };
skips = 0;
startBtn.classList.remove('tired');
startBtn.textContent = 'Start';
skipBtn.textContent = 'Skip setup';
msg0.textContent = 'Press Start. It is right there.';
var aw = arena.clientWidth, ah = arena.clientHeight;
setStartPos((aw - startBtn.offsetWidth) / 2, (ah - startBtn.offsetHeight) / 2 - 8, -1);
};
function makeTired() {
dg.tired = true;
dg.tiredAt = now() + 450;
startBtn.classList.add('tired');
startBtn.textContent = 'Start (fine)';
msg0.textContent = DODGE_MSG[DODGE_MSG.length - 1];
}
function doDodge(px, py) {
if (!dg || dg.tired) return;
dg.count++;
S.stats.dodges++;
dg.cool = now() + 260;
var aw = arena.clientWidth, ah = arena.clientHeight, bw = startBtn.offsetWidth, bh = startBtn.offsetHeight;
var best = null, bestD = -1;
for (var i = 0; i < 12; i++) {
var x = rand(6, Math.max(6, aw - bw - 6));
var y = rand(6, Math.max(6, ah - bh - 30));
var d = Math.min(Math.hypot(x + bw / 2 - px, y + bh / 2 - py), 220) + Math.random() * 30;
if (d > bestD) { bestD = d; best = { x: x, y: y }; }
}
setStartPos(best.x, best.y, rand(-5, 5).toFixed(1));
msg0.textContent = DODGE_MSG[Math.min(dg.count, DODGE_MSG.length) - 1];
plink(500 + dg.count * 35, 0.3);
if (dg.count >= MAX_DODGE) makeTired();
}
/* mouse: it runs when the pointer gets close */
arena.addEventListener('pointermove', function (e) {
if (S.demo || !dg || dg.tired || e.pointerType === 'touch') return;
if (now() < dg.cool) return;
var r = arena.getBoundingClientRect();
var px = e.clientX - r.left, py = e.clientY - r.top;
var bw = startBtn.offsetWidth, bh = startBtn.offsetHeight;
var dx = Math.max(Math.abs(px - (pos.x + bw / 2)) - bw / 2, 0);
var dy = Math.max(Math.abs(py - (pos.y + bh / 2)) - bh / 2, 0);
if (Math.hypot(dx, dy) < 44) doDodge(px, py);
});
/* touch: it runs the moment the finger lands */
startBtn.addEventListener('pointerdown', function (e) {
if (S.demo || !dg || dg.tired) return;
var r = arena.getBoundingClientRect();
doDodge(e.clientX - r.left, e.clientY - r.top);
if (e.cancelable) e.preventDefault();
});
startBtn.addEventListener('click', function () {
if (S.demo || !dg) return;
if (dg.tired) {
if (now() > dg.tiredAt) { plink(700, 0.4); go(1); }
} else if (now() > dg.cool) {
/* fallback for anything that clicks without a pointer */
doDodge(pos.x + startBtn.offsetWidth / 2, pos.y + startBtn.offsetHeight / 2);
}
});
skipBtn.addEventListener('click', function () {
msg0.textContent = SKIP_MSG[Math.min(skips, SKIP_MSG.length - 1)];
skips++;
skipBtn.textContent = 'Skip setup (unavailable)';
});
window.addEventListener('resize', function () {
if (S.scene !== 0) return;
var aw = arena.clientWidth, ah = arena.clientHeight;
setStartPos(
clamp(pos.x, 6, Math.max(6, aw - startBtn.offsetWidth - 6)),
clamp(pos.y, 6, Math.max(6, ah - startBtn.offsetHeight - 6))
);
});
/* ================= scene 1: cookie notices that multiply ================= */
var COOKIE_TEXT = [
'We use cookies to improve your cookies. Is that okay?',
'Thank you. We need one more cookie to remember that you accepted cookies.',
'This notice is about the previous notice. Please accept it as well.',
'Our trusted partners (also us) would like a cookie too.',
'You are good at this. Here is another one.',
'This cookie notice does not use cookies. It uses a biscuit.',
'Last one. We promise. (The promise is stored in a cookie.)'
];
var ACCEPT = ['Accept', 'Accept again', 'OK', 'Fine', 'Sure', 'Accept (sigh)', 'Accept all 1'];
var DECLINE = ['Decline', 'Decline', 'Manage', 'No thanks', 'Decline', 'Later', 'Decline'];
var ck = null;
ENTER[1] = function () {
ck = { spawned: 0, open: 0, accepted: 0, schedule: S.demo ? [3, 0, 0, 0] : [2, 2, 1, 1, 0, 0, 0] };
cookieLayer.innerHTML = '';
hide(cont1);
msg1.textContent = '';
cookieCount.textContent = '0';
later(S.demo ? 120 : 650, function () { spawnCookie(0); });
};
function spawnCookie(delay) {
var i = ck.spawned++;
var el = document.createElement('div');
el.className = 'cookie';
el.innerHTML =
'<div class="cookie-row"><span class="cookie-ico" aria-hidden="true"></span><p></p></div>' +
'<div class="cookie-btns">' +
'<button type="button" class="btn small ghost" data-act="decline"></button>' +
'<button type="button" class="btn small primary" data-act="accept"></button>' +
'</div>';
$('p', el).textContent = COOKIE_TEXT[i % COOKIE_TEXT.length];
$('[data-act="decline"]', el).textContent = DECLINE[i % DECLINE.length];
$('[data-act="accept"]', el).textContent = ACCEPT[i % ACCEPT.length];
el.style.bottom = (10 + (i % 4) * 30 + Math.round(rand(0, 8))) + 'px';
el.style.setProperty('--rot', rand(-2.6, 2.6).toFixed(2) + 'deg');
el.style.setProperty('--dx', Math.round(rand(-9, 9)) + 'px');
el.style.zIndex = String(10 + i);
if (delay) el.style.animationDelay = delay + 'ms';
cookieLayer.appendChild(el);
ck.open++;
cookieCount.textContent = String(ck.open);
}
function dismissCookie(el, act) {
if (!ck || el.getAttribute('data-gone')) return;
el.setAttribute('data-gone', '1');
el.style.animationDelay = '0ms';
el.classList.add('out');
setTimeout(function () { if (el.parentNode) el.parentNode.removeChild(el); }, 320);
ck.open--;
ck.accepted++;
S.stats.cookies++;
var n = ck.schedule[ck.accepted - 1] || 0;
for (var k = 0; k < n; k++) spawnCookie(k * 110);
cookieCount.textContent = String(ck.open);
plink(act === 'decline' ? 392 : 587, 0.35);
if (ck.open === 0) {
msg1.textContent = 'All ' + ck.accepted + ' notices handled. Fun fact: this page does not use cookies.';
show(cont1);
} else if (act === 'decline') {
msg1.textContent = 'Your decline was saved as an accept, for your convenience.';
} else if (n > 1) {
msg1.textContent = 'Accepted. That opened ' + n + ' more.';
} else if (n === 1) {
msg1.textContent = 'Accepted. One more popped up to say thanks.';
} else {
msg1.textContent = 'Accepted. Nothing new appeared. Suspicious.';
}
}
cookieLayer.addEventListener('click', function (e) {
if (S.demo) return;
var b = e.target.closest('button[data-act]');
if (!b) return;
var c = b.closest('.cookie');
if (c) dismissCookie(c, b.getAttribute('data-act'));
});
cont1.addEventListener('click', function () { if (!S.demo) go(2); });
/* ================= scene 2: Close spawns Close ================= */
var CLOSE_LABELS = ['Close', 'Close', 'Close?', 'Really close', 'Close this one', 'Close (real)', 'Clos e', 'Close 2', 'Almost close'];
var hy = null;
ENTER[2] = function () {
hy = { spawned: 0, open: 0, closed: 0, schedule: S.demo ? [3, 0, 0, 0] : [2, 2, 1, 0, 0, 0] };
$$('.closeb', popup).forEach(function (b) { b.parentNode.removeChild(b); });
popup.classList.remove('closed');
show(popup);
hide(cont2);
msg2.textContent = '';
spawnClose(true);
};
function spawnClose(first) {
var i = hy.spawned++;
var b = document.createElement('button');
b.type = 'button';
b.className = 'btn small closeb';
b.textContent = first ? '× Close' : CLOSE_LABELS[i % CLOSE_LABELS.length];
popup.appendChild(b);
var W = popup.clientWidth, H = popup.clientHeight, bw = b.offsetWidth, bh = b.offsetHeight;
var x, y;
if (first) {
x = W - bw - 10; y = 10;
} else {
var others = $$('.closeb', popup).filter(function (o) { return o !== b && !o.getAttribute('data-gone'); });
var best = null, bestD = -1;
for (var k = 0; k < 14; k++) {
var cx = rand(8, Math.max(8, W - bw - 8)), cy = rand(8, Math.max(8, H - bh - 8));
var d = 9999;
for (var j = 0; j < others.length; j++) {
d = Math.min(d, Math.hypot(cx - others[j].offsetLeft, cy - others[j].offsetTop));
}
d += Math.random() * 20;
if (d > bestD) { bestD = d; best = { x: cx, y: cy }; }
}
x = best.x; y = best.y;
}
b.style.left = Math.round(x) + 'px';
b.style.top = Math.round(y) + 'px';
b.style.setProperty('--rot', (first ? 0 : rand(-9, 9)).toFixed(1) + 'deg');
b.style.zIndex = String(5 + i);
hy.open++;
closeCount.textContent = String(hy.open);
}
function pressClose(b) {
if (!hy || b.getAttribute('data-gone')) return;
b.setAttribute('data-gone', '1');
b.classList.add('pop');
setTimeout(function () { if (b.parentNode) b.parentNode.removeChild(b); }, 260);
hy.open--;
hy.closed++;
S.stats.closes++;
var n = hy.schedule[hy.closed - 1] || 0;
for (var k = 0; k < n; k++) spawnClose(false);
closeCount.textContent = String(hy.open);
plink(470 + hy.closed * 30, 0.3);
if (hy.open === 0) {
popup.classList.add('closed');
msg2.textContent = 'Closed. It only took ' + hy.closed + ' Close buttons.';
later(480, function () { hide(popup); show(cont2); });
} else if (n >= 2) {
msg2.textContent = 'That Close button closed. ' + (n === 2 ? 'Two' : 'Three') + ' more opened.';
} else if (n === 1) {
msg2.textContent = 'Closed one. Opened one. Balance.';
} else {
msg2.textContent = 'That one actually closed. Keep going.';
}
}
popup.addEventListener('click', function (e) {
if (S.demo) return;
var b = e.target.closest('.closeb');
if (b) pressClose(b);
});
cont2.addEventListener('click', function () { if (!S.demo) go(3); });
/* ================= scene 3: the progress bar slides back at 99% ================= */
var pg = null;
function setP(p) {
fill.style.width = p <= 100 ? p.toFixed(2) + '%' : 'calc(100% + ' + ((p - 100) * 10).toFixed(1) + 'px)';
pct.textContent = Math.floor(p + 0.0001) + '%';
}
async function runProgress(fast) {
var sp = fast ? 0.33 : 1;
setP(0);
progLabel.textContent = 'Installing comfort…';
progEta.textContent = 'About 4 seconds remaining';
msg3.textContent = '';
await sleep(250 * sp);
await tween(0, 99, 2800 * sp, setP, easeOut);
progLabel.textContent = 'Almost there…';
progEta.textContent = 'About 1 second remaining';
await sleep(900 * sp);
progLabel.textContent = 'Oh. Hang on.';
progEta.textContent = 'About 9 seconds remaining';
await tween(99, 41, 1500 * sp, setP, easeInOut);
S.stats.lost += 58;
msg3.textContent = 'It slid back. That is normal. It does that.';
await sleep(600 * sp);
progLabel.textContent = 'Re-installing comfort…';
await tween(41, 99, 2300 * sp, setP, easeOut);
if (!fast) {
progLabel.textContent = 'Finishing touches…';
progEta.textContent = 'Any moment now';
await sleep(1000);
progLabel.textContent = 'Double-checking the first part…';
progEta.textContent = 'About 12 seconds remaining';
await tween(99, 86, 1100, setP, easeInOut);
S.stats.lost += 13;
msg3.textContent = 'Only a small slide this time. That counts as progress.';
await sleep(600);
progLabel.textContent = 'Re-re-installing comfort…';
await tween(86, 99, 1500, setP, easeOut);
msg3.textContent = '';
}
progLabel.textContent = 'Stuck at 99%';
progEta.textContent = 'The last 1% is traditionally done by hand.';
show(pushBtn);
}
ENTER[3] = function () {
pg = { pushes: 0, busy: false, promise: null };
hide(pushBtn);
hide(cont3);
pushBtn.textContent = 'Push the last 1%';
pg.promise = runProgress(S.demo);
pg.promise.catch(noop);
};
function doPush() {
if (!pg || pg.busy) return Promise.resolve();
pg.busy = true;
pg.pushes++;
var slipFirst = pg.pushes === 1 && !S.demo;
var p = (async function () {
if (slipFirst) {
await tween(99, 100, 380, setP, easeOut);
progLabel.textContent = '100%! There it is.';
plink(660, 0.4);
await sleep(700);
progLabel.textContent = 'Oh no. It slipped.';
await tween(100, 99, 800, setP, easeInOut);
S.stats.lost += 1;
progLabel.textContent = 'Stuck at 99% (again)';
msg3.textContent = 'So close. Push again, and this time mean it.';
pushBtn.textContent = 'Push again (firmly)';
pg.busy = false;
} else {
await tween(99, 101, 520, setP, easeOut);
progLabel.textContent = 'Installed. Sort of.';
progEta.textContent = 'Finished 1% over budget.';
msg3.textContent = '101%. Too far, but nobody is touching it again.';
plink(700, 0.5);
hide(pushBtn);
show(cont3);
}
})();
p.catch(noop);
return p;
}
pushBtn.addEventListener('click', function () { if (!S.demo) doPush(); });
cont3.addEventListener('click', function () { if (!S.demo) go(4); });
/* ================= scene 4: boxes that untick, buttons that swap ================= */
var UNTICK = ['A box came unticked. They do that.', 'Another one slipped. Tick it again, gently.'];
var SWAP = ['Oh. The buttons swapped places. Try again.', 'They swapped back. One more time.'];
var ag = null;
function renderChecks() {
for (var i = 0; i < checkEls.length; i++) {
checkEls[i].classList.toggle('on', !!ag.on[i]);
checkEls[i].setAttribute('aria-pressed', ag.on[i] ? 'true' : 'false');
}
}
function allOn() { return !!(ag.on[0] && ag.on[1] && ag.on[2]); }
ENTER[4] = function () {
ag = { on: [false, false, false], budget: 2, swaps: 0, ignoreUntil: 0 };
renderChecks();
swapEl.classList.remove('swapped');
msg4.textContent = '';
};
function toggleCheck(i) {
ag.on[i] = !ag.on[i];
renderChecks();
plink(ag.on[i] ? 620 : 410, 0.25);
if (!ag.on[i]) return;
var others = [0, 1, 2].filter(function (j) { return j !== i && ag.on[j]; });
if (ag.budget > 0 && others.length) {
ag.budget--;
var victim = others[0], which = 1 - ag.budget;
later(430, function () {
if (!ag.on[victim]) return;
ag.on[victim] = false;
S.stats.unticks++;
renderChecks();
msg4.textContent = UNTICK[clamp(which, 0, UNTICK.length - 1)];
});
} else if (allOn()) {
msg4.textContent = 'All three ticked. Quick, press Continue before they notice.';
}
}
function doSwap() {
ag.swaps++;
swapEl.classList.toggle('swapped');
ag.ignoreUntil = now() + 500;
msg4.textContent = SWAP[Math.min(ag.swaps, SWAP.length) - 1];
plink(350, 0.3);
}
checksEl.addEventListener('click', function (e) {
if (S.demo || !ag) return;
var c = e.target.closest('.check');
if (c) toggleCheck(parseInt(c.getAttribute('data-i'), 10));
});
agreeBtn.addEventListener('pointerdown', function () {
if (S.demo || !ag) return;
if (allOn() && ag.swaps < 2) doSwap();
});
agreeBtn.addEventListener('click', function () {
if (S.demo || !ag || now() < ag.ignoreUntil) return;
if (!allOn()) { msg4.textContent = 'Please tick all three boxes first. All of them. At the same time.'; return; }
go(5);
});
overBtn.addEventListener('click', function () {
if (S.demo || !ag || now() < ag.ignoreUntil) return;
msg4.textContent = 'Starting over… just kidding. We would not do that to you. Today.';
});
/* ================= scene 5: the picture that is always 1 degree off ================= */
var fr = null;
function renderFrame() {
frame.style.transform = 'rotate(' + fr.angle + 'deg)';
var a = Math.abs(fr.angle);
tiltRead.textContent = a === 0
? 'Off by 0°. Perfectly straight.'
: 'Off by ' + a + '° (' + (fr.angle > 0 ? 'clockwise' : 'the other way') + ')';
}
ENTER[5] = function () {
fr = { angle: 3, taps: 0, done: false };
renderFrame();
hide(goodBtn);
hide(cont5);
show(tiltBtns);
msg5.textContent = 'It is only a little crooked. Two taps, at most.';
};
function tilt(dir) {
if (!fr || fr.done) return;
var next = fr.angle + dir * 2;
fr.taps++;
S.stats.tilts++;
if (Math.abs(next) > 9) {
msg5.textContent = 'It will not go any further. Mercifully.';
} else {
fr.angle = next;
renderFrame();
var a = Math.abs(next);
if (a === 1) msg5.textContent = fr.taps < 3 ? 'So close! The adjuster only moves in 2° steps.' : 'Still 1°. It is always going to be 1°.';
else if (a === 3) msg5.textContent = 'Now it is 3° off again. Somehow.';
else msg5.textContent = 'That is definitely worse.';
}
plink(440 + fr.angle * 12, 0.3);
if (fr.taps >= 3) show(goodBtn);
}
function goodEnough() {
if (!fr || fr.done) return;
fr.done = true;
fr.angle = 0;
renderFrame();
hide(tiltBtns);
hide(goodBtn);
card.classList.add('tilted');
msg5.textContent = 'The picture is straight now. Please do not look at the rest of the page.';
plink(523, 0.5);
if (!S.demo) later(900, function () { show(cont5); });
}
tiltL.addEventListener('click', function () { if (!S.demo) tilt(-1); });
tiltR.addEventListener('click', function () { if (!S.demo) tilt(1); });
goodBtn.addEventListener('click', function () { if (!S.demo) goodEnough(); });
cont5.addEventListener('click', function () { if (!S.demo) go(6); });
/* ================= scene 6: thank you ================= */
function fmtTime(ms) {
var s = Math.max(0, Math.round(ms / 1000));
var m = Math.floor(s / 60);
s = s % 60;
return m + ':' + (s < 10 ? '0' : '') + s;
}
function setStars(n) {
var list = starsEl.children;
for (var i = 0; i < list.length; i++) list[i].classList.toggle('on', i < n);
}
ENTER[6] = function () {
var st = S.stats;
var rows = [
['Time spent (the estimate was 1 minute)', fmtTime(now() - S.t0)],
['Times the Start button escaped', st.dodges],
['Cookie notices accepted', st.cookies],
['Cookies actually used', 0],
['Close buttons closed', st.closes],
['Progress lost along the way', st.lost + '%'],
['Boxes that unticked themselves', st.unticks],
['Picture adjustments', st.tilts]
];
statsEl.innerHTML = '';
rows.forEach(function (r) {
var li = document.createElement('li');
var a = document.createElement('span');
var b = document.createElement('b');
a.textContent = r[0];
b.textContent = String(r[1]);
li.appendChild(a);
li.appendChild(b);
statsEl.appendChild(li);
});
setStars(0);
msg6.textContent = '';
/* a soft little fanfare whose last note is slightly flat */
later(250, function () { plink(523, 0.6); });
later(480, function () { plink(659, 0.6); });
later(710, function () { plink(770, 0.9); });
};
(function buildStars() {
for (var i = 0; i < 5; i++) {
var b = document.createElement('button');
b.type = 'button';
b.className = 'star';
b.setAttribute('data-i', String(i));
b.setAttribute('aria-label', (i + 1) + (i ? ' stars' : ' star'));
b.innerHTML = '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M12 2.6l2.9 6 6.6 .9-4.8 4.6 1.2 6.5L12 17.5l-5.9 3.1 1.2-6.5L2.5 9.5l6.6-.9z"/></svg>';
starsEl.appendChild(b);
}
})();
starsEl.addEventListener('click', function (e) {
var b = e.target.closest('.star');
if (!b) return;
var tapped = parseInt(b.getAttribute('data-i'), 10) + 1, heard = tapped - 1;
setStars(heard);
msg6.textContent = heard === 0
? 'You tapped 1 star. We heard 0. Ouch, but fair.'
: 'You tapped ' + tapped + '. We heard ' + heard + '. Thank you for the ' + heard + (heard === 1 ? ' star!' : ' stars!');
plink(400 + heard * 60, 0.3);
});
againBtn.addEventListener('click', function () { if (!S.demo) resetGame(); });
(function buildConfetti() {
var colors = ['#3565d4', '#f2b84b', '#2c9667', '#e07a5f', '#8d7bd6'];
for (var i = 0; i < 22; i++) {
var c = document.createElement('i');
c.style.left = (2 + Math.random() * 96).toFixed(1) + '%';
c.style.background = colors[i % colors.length];
c.style.animationDuration = rand(9, 15).toFixed(1) + 's';
c.style.animationDelay = (-rand(0, 15)).toFixed(1) + 's';
c.style.setProperty('--sway', Math.round(rand(-40, 40)) + 'px');
c.style.setProperty('--spin', Math.round(rand(160, 420)) + 'deg');
if (i === 21) c.style.animationDirection = 'reverse';
confettiEl.appendChild(c);
}
})();
/* ================= always there: tiles, bell ================= */
var TILE_MSG = [
'Fixed. Another one moved. That is how tiles work.',
'You straightened one! Net change: zero.',
'Nearly. Keep going. (Do not keep going.)',
'There is always exactly one more.'
];
var tileState = [], tileFixes = 0;
function setTile(i, crooked) {
tileState[i] = crooked;
var r = crooked ? ((Math.random() < 0.5 ? -1 : 1) * rand(4, 9)).toFixed(1) + 'deg' : '0deg';
tilesEl.children[i].style.setProperty('--r', r);
}
(function buildTiles() {
for (var i = 0; i < 8; i++) {
var t = document.createElement('button');
t.type = 'button';
t.className = 'tile';
t.setAttribute('data-i', String(i));
t.setAttribute('aria-label', 'Decorative tile ' + (i + 1));
tilesEl.appendChild(t);
tileState.push(false);
}
setTile(5, true);
})();
tilesEl.addEventListener('click', function (e) {
var t = e.target.closest('.tile');
if (!t) return;
var i = parseInt(t.getAttribute('data-i'), 10);
if (tileState[i]) {
setTile(i, false);
var j = i;
while (j === i) j = Math.floor(Math.random() * tileState.length);
setTile(j, true);
footNote.textContent = TILE_MSG[tileFixes % TILE_MSG.length];
tileFixes++;
} else {
setTile(i, true);
footNote.textContent = 'That one was fine. It is not fine now.';
}
plink(300 + i * 25, 0.25);
});
var bellCount = 1;
var BELL_MSG = [
'You have {n} notifications. All of them are about this bell.',
'Marked as read. {n} unread.',
'Checking again does not help. {n} unread.'
];
bellBtn.addEventListener('click', function () {
bellCount++;
badge.textContent = String(bellCount);
toast(BELL_MSG[(bellCount - 2) % BELL_MSG.length].replace('{n}', String(bellCount)));
plink(880, 0.3);
});
/* ================= #demo: a hands-free loop of about 20 seconds ================= */
var fpos = { x: 0, y: 0 }, demoId = 0, swallowUntil = 0;
function fingerSet(x, y, ms) {
fpos.x = x; fpos.y = y;
finger.style.transitionDuration = (ms || 0) + 'ms';
finger.style.transform = 'translate(' + Math.round(x - 22) + 'px,' + Math.round(y - 22) + 'px)';
}
function ensureVisible(el) {
try {
var r = el.getBoundingClientRect(), vh = window.innerHeight;
if (r.bottom > vh - 10) window.scrollBy(0, r.bottom - vh + 24);
else if (r.top < 10) window.scrollBy(0, r.top - 24);
} catch (e) {}
}
function fingerTo(el, ms, fx) {
ensureVisible(el);
var r = el.getBoundingClientRect();
fingerSet(r.left + r.width * (fx == null ? 0.5 : fx), r.top + r.height * 0.5, ms);
return sleep(ms + 30);
}
function fingerTap() {
finger.classList.add('down');
return sleep(100).then(function () { finger.classList.remove('down'); });
}
function topOf(sel, root) {
var list = $$(sel, root).filter(function (el) { return !el.getAttribute('data-gone'); });
return list.length ? list[list.length - 1] : null;
}
async function demoOnce() {
var i, el, a;
resetGame();
fingerSet(window.innerWidth * 0.5, window.innerHeight * 0.82, 0);
await sleep(400);
/* 1. the Start button dodges */
for (i = 0; i < 3; i++) {
await fingerTo(startBtn, 350);
a = arena.getBoundingClientRect();
doDodge(fpos.x - a.left, fpos.y - a.top);
await sleep(230);
}
makeTired();
await sleep(150);
await fingerTo(startBtn, 380);
await fingerTap();
showScene(1);
/* 2. the cookie notice multiplies */
await sleep(450);
for (i = 0; i < 8; i++) {
el = topOf('.cookie', cookieLayer);
if (!el) break;
await fingerTo($('[data-act="accept"]', el), 250);
await fingerTap();
dismissCookie(el, 'accept');
await sleep(170);
}
await sleep(100);
await fingerTo(cont1, 260);
await fingerTap();
showScene(2);
/* 3. the Close button spawns Close buttons */
await sleep(300);
for (i = 0; i < 8; i++) {
el = topOf('.closeb', popup);
if (!el) break;
await fingerTo(el, 250);
await fingerTap();
pressClose(el);
await sleep(170);
}
await sleep(430);
await fingerTo(cont2, 260);
await fingerTap();
showScene(3);
/* 4. the progress bar slides back at 99% */
await pg.promise;
await sleep(150);
await fingerTo(pushBtn, 260);
await fingerTap();
await doPush();
await sleep(150);
await fingerTo(cont3, 260);
await fingerTap();
showScene(4);
/* 5. a box unticks itself, the buttons swap */
await sleep(250);
await fingerTo(checkEls[0], 260, 0.1);
await fingerTap();
toggleCheck(0);
await fingerTo(checkEls[1], 230, 0.1);
await fingerTap();
toggleCheck(1);
await sleep(600);
await fingerTo(agreeBtn, 260);
await fingerTap();
doSwap();
await sleep(460);
showScene(5);
/* 6. the picture is never straight, until the page is not */
await sleep(300);
await fingerTo(tiltL, 260);
await fingerTap();
tilt(-1);
await sleep(280);
await fingerTap();
tilt(-1);
await sleep(280);
show(goodBtn);
await fingerTo(goodBtn, 280);
await fingerTap();
goodEnough();
await sleep(850);
showScene(6);
/* 7. thank you */
fingerSet(window.innerWidth * 0.86, window.innerHeight * 0.9, 500);
await sleep(2400);
}
function isDemoHash() { return /#demo$/i.test(String(window.location.href)); }
function startDemo() {
if (S.demo) return;
S.demo = true;
body.classList.add('demo');
var my = ++demoId;
(async function loop() {
while (S.demo && my === demoId) {
try {
await demoOnce();
} catch (e) {
if (!S.demo || my !== demoId) return;
if (e !== CANCEL) await new Promise(function (r) { setTimeout(r, 800); });
}
}
})();
}
function stopDemo() {
if (!S.demo) return;
S.demo = false;
demoId++;
body.classList.remove('demo');
finger.classList.remove('down');
resetGame();
toast('Demo over. Your turn.');
}
/* any real touch, click or key ends the demo */
function onRealInput(e) {
if (!S.demo) return;
if (e && e.isTrusted === false) return;
stopDemo();
swallowUntil = now() + 700;
if (e) {
e.stopPropagation();
if (e.cancelable && e.type !== 'keydown') e.preventDefault();
}
}
['pointerdown', 'mousedown', 'touchstart', 'keydown'].forEach(function (type) {
window.addEventListener(type, onRealInput, { capture: true, passive: false });
});
window.addEventListener('click', function (e) {
if (now() < swallowUntil) { e.stopPropagation(); e.preventDefault(); }
}, true);
window.addEventListener('hashchange', function () {
if (isDemoHash()) startDemo(); else stopDemo();
});
/* ================= go ================= */
if (isDemoHash()) startDemo(); else resetGame();
})();
</script>
</body>
</html>
