Skip to content
VibeCodeBench
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.)30.5 KB · 594 lines · no libraries
Download
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>A Perfectly Normal Page</title>
<style>
  :root{
    --bg:#f4f1ea; --ink:#2b2b2b; --card:#fffdf8; --line:#d9d2c3;
    --yellow:#ffd84d; --blue:#7fb3ff; --blue2:#9cc4ff; --green:#6cc070; --soft:#e3dccd;
  }
  *{box-sizing:border-box}
  html,body{margin:0;padding:0}
  body{
    background:var(--bg);
    background-image:linear-gradient(90deg, rgba(0,0,0,.035) 1px, transparent 1px),
                     linear-gradient(rgba(0,0,0,.035) 1px, transparent 1px);
    background-size:41px 40px; background-position:3px 0;
    color:var(--ink); font:18px/1.45 system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;
    min-height:100vh; overflow-x:hidden; -webkit-tap-highlight-color:transparent;
  }
  .top{display:flex;justify-content:space-between;align-items:center;padding:12px 16px 12px 17px;max-width:600px;margin:0 auto;gap:10px;flex-wrap:wrap}
  .logo{font-weight:800;letter-spacing:.5px;position:relative;transform:rotate(-1deg);display:inline-block}
  .logo::after{content:"";position:absolute;left:-3px;right:1px;bottom:-2px;height:3px;background:var(--ink);transform:rotate(.6deg)}
  nav{font-size:15px;opacity:.8}
  nav span{margin:0 6px;position:relative}
  nav .off{top:1px}
  nav .off2{top:-1px;left:1px}
  .step{font-size:14px;background:#fff;border:2px solid var(--ink);border-radius:999px;padding:2px 12px 3px 11px;transform:rotate(1.5deg)}
  .wrap{max-width:560px;margin:0 auto;padding:8px 16px 240px}
  .card{
    background:var(--card);border:1px solid var(--line);border-radius:18px 16px 19px 15px;
    padding:22px 20px 24px 23px;transform:rotate(-.5deg);box-shadow:3px 6px 0 var(--soft);
  }
  h1,h2{margin:.1em 0 .3em;line-height:1.15}
  h1{font-size:30px} h2{font-size:26px}
  .wob span{position:relative}
  .wob .u{top:1px} .wob .d{top:-1px} .wob .t{display:inline-block;transform:rotate(4deg)}
  .lead{margin:.4em 0 .6em 1px}
  .hint{min-height:1.5em;font-size:16px;opacity:.8;margin:.4em 0;font-style:italic;padding-left:2px}
  .dots{display:flex;gap:9px;margin:8px 0 14px}
  .dots i{width:9px;height:9px;border-radius:50%;background:var(--ink);opacity:.25}
  .dots i.odd{transform:translateY(1px);width:10px}
  .btn{
    font:inherit;font-size:19px;font-weight:650;min-height:56px;padding:0 26px 0 31px;
    border-radius:14px;border:2px solid var(--ink);background:#fff;color:var(--ink);
    box-shadow:0 4px 0 var(--ink);cursor:pointer;touch-action:manipulation;transform:rotate(.7deg);
    user-select:none;-webkit-user-select:none;
  }
  .btn:active{box-shadow:0 1px 0 var(--ink);translate:0 3px}
  .primary{background:var(--yellow)}
  .small{min-height:46px;font-size:16px;padding:0 16px 0 19px}
  .ghost{background:transparent}
  .big{font-size:20px;min-height:64px}
  .actions{display:flex;gap:12px;flex-wrap:wrap;margin-top:16px;min-height:60px}
  /* dodge arena */
  .arena{position:relative;height:250px;border:2px dashed #cfc6b3;border-radius:16px 15px 16px 17px;margin:16px 0 6px;overflow:hidden;touch-action:manipulation}
  .arena .btn{position:absolute;left:0;top:0;transition:left .28s cubic-bezier(.3,1.4,.5,1),top .28s cubic-bezier(.3,1.4,.5,1),transform .28s}
  .arena .btn.tired{background:#ffe99a}
  /* progress */
  .bar{height:36px;border:2px solid var(--ink);border-radius:10px;overflow:hidden;position:relative;background:#fff;margin:18px 0 6px;transform:rotate(.4deg)}
  .fill{height:100%;width:0;background:repeating-linear-gradient(45deg,var(--blue) 0 12px,var(--blue2) 12px 24px)}
  .pct{position:absolute;left:calc(50% + 1px);top:50%;transform:translate(-50%,-48%);font-weight:700;font-variant-numeric:tabular-nums}
  /* modal */
  .modal-wrap{background:rgba(43,43,43,.07);padding:12px;border-radius:16px;margin-top:12px}
  .modal{background:#fff;border:2px solid var(--ink);border-radius:14px;padding:16px;transform:rotate(1.2deg);transition:transform .45s ease,opacity .45s}
  .modal.shrink{transform:scale(.05) rotate(20deg);opacity:0}
  .mtitle{font-weight:700;font-size:20px;margin:0 0 4px}
  .msub{margin:0;font-size:15px;opacity:.75}
  .mzone{position:relative;height:270px}
  .close{position:absolute;min-height:48px;padding:0 16px 0 19px;white-space:nowrap;font-size:17px}
  .close.mini{min-height:44px}
  /* human check */
  .check{display:flex;align-items:center;gap:14px;width:100%;min-height:68px;text-align:left;padding:0 18px 0 21px}
  .box{flex:none;width:34px;height:34px;border:2px solid var(--ink);border-radius:6px;background:#fff;position:relative;transform:rotate(-2deg)}
  .check.on .box{background:var(--green)}
  .check.on .box::after{content:"";position:absolute;left:10px;top:3px;width:9px;height:18px;border:solid #fff;border-width:0 4px 4px 0;transform:rotate(41deg)}
  .grid{display:grid;grid-template-columns:repeat(3,1fr);gap:8px;max-width:300px;margin:10px 0}
  .tile{aspect-ratio:1/1;border:2px solid var(--ink);background:#fff;border-radius:8px;position:relative;padding:0;cursor:pointer;touch-action:manipulation}
  .tile::before{content:"";position:absolute;left:28%;top:28%;width:44%;height:44%;background:var(--ink);opacity:.8;border-radius:2px;transform:rotate(var(--r,0deg))}
  .tile.odd::before{left:calc(28% + 1px);top:calc(28% + 1px)}
  .tile.sel{background:#cfe3ff}
  .yn{display:flex;gap:12px;margin-top:12px}
  .yn.swap{flex-direction:row-reverse;justify-content:flex-end}
  .section{margin-top:18px;animation:rise .4s ease}
  @keyframes rise{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:none}}
  /* final */
  .stats{padding-left:22px;margin:10px 0}
  .stats li{margin:4px 0;position:relative}
  .stats li:nth-child(3){left:1px}
  .stats li:nth-child(2){top:1px}
  /* cookies */
  .cookie-layer{position:fixed;left:0;right:0;bottom:0;height:0;z-index:50}
  .cookie{
    position:absolute;bottom:14px;left:50%;width:min(420px,calc(100vw - 32px));
    transform:translate(calc(-50% + var(--dx,0px)),var(--dy,0px)) rotate(var(--r,0deg));
    background:#fffaf0;border:2px solid var(--ink);border-radius:14px 13px 15px 14px;padding:14px 14px 14px 15px;
    box-shadow:0 6px 0 rgba(0,0,0,.12);animation:cookieIn .35s ease;transition:opacity .3s
  }
  .cookie p{margin:0 0 10px;font-size:16px;display:flex;gap:10px;align-items:flex-start}
  .cookie .row{display:flex;gap:8px;flex-wrap:wrap}
  .cookie.gone{opacity:0;pointer-events:none}
  @keyframes cookieIn{from{opacity:0;margin-bottom:-30px}to{opacity:1;margin-bottom:0}}
  .ck{flex:none;width:26px;height:26px;border-radius:50%;margin-top:1px;
    background:radial-gradient(circle at 30% 35%,#5a3a1a 0 2.5px,transparent 3px),
               radial-gradient(circle at 65% 30%,#5a3a1a 0 2px,transparent 2.5px),
               radial-gradient(circle at 55% 68%,#5a3a1a 0 2.5px,transparent 3px),
               radial-gradient(circle at 28% 70%,#5a3a1a 0 1.5px,transparent 2px),#d9a35b;
    box-shadow:inset -2px -2px 0 rgba(0,0,0,.12)}
  /* toast */
  .toast{position:fixed;top:14px;left:50%;transform:translate(-50%,-20px) rotate(-1deg);background:var(--ink);color:#fff;border-radius:12px;
    padding:10px 16px 11px 17px;z-index:80;opacity:0;transition:opacity .4s,transform .4s;pointer-events:none;max-width:calc(100vw - 32px);font-size:16px;text-align:center}
  .toast.show{opacity:1;transform:translate(-50%,0) rotate(-1deg)}
  footer{text-align:center;font-size:13px;opacity:.6;margin-top:28px;transform:rotate(.6deg)}
  footer span{position:relative;top:1px}
  /* demo */
  #finger{position:fixed;left:-100px;top:-100px;width:46px;height:46px;margin:-23px 0 0 -23px;border-radius:50%;
    background:rgba(59,111,216,.28);border:3px solid rgba(59,111,216,.85);pointer-events:none;z-index:200;
    transition:left .35s ease,top .35s ease,transform .12s;display:none}
  #finger.press{transform:scale(.75)}
  body.demo #finger{display:block}
  #demoBadge{display:none;position:fixed;left:50%;bottom:8px;transform:translateX(-50%);z-index:150;background:#fff;border:2px solid var(--ink);
    border-radius:999px;padding:4px 14px;font-size:14px;pointer-events:none;white-space:nowrap}
  body.demo #demoBadge{display:block}
  canvas#conf{position:fixed;inset:0;pointer-events:none;z-index:40}
</style>
</head>
<body>
<header class="top">
  <span class="logo">NormalCo</span>
  <nav><span>Home</span><span class="off">About</span><span>Contcat</span><span class="off2">Help?</span></nav>
  <span class="step" id="step">Step 1 of 4</span>
</header>
<main class="wrap">
  <div class="card" id="stage"></div>
  <footer>&copy; 2026 NormalCo<span>.</span> All rights reserved. Some rights misplaced<span>.</span></footer>
</main>
<div class="cookie-layer" id="cookies"></div>
<div class="toast" id="toast"></div>
<canvas id="conf"></canvas>
<div id="finger"></div>
<div id="demoBadge">Demo playing &middot; tap anywhere to try it yourself</div>
<script>
(function(){
  "use strict";
  var $ = function(s){ return document.querySelector(s); };
  var app = $('#stage');
  var stats, cookieGen, cookieDone, timers = [], raf = 0;
  var demo = { active:false };
  function speed(){ return demo.active ? 3 : 1; }
  function rand(a,b){ return a + Math.random()*(b-a); }
  function later(fn, ms){ var t = setTimeout(fn, ms/speed()); timers.push(t); return t; }
  function button(label, cls, id){
    var b = document.createElement('button');
    b.className = 'btn ' + (cls||''); b.textContent = label; b.type = 'button';
    if(id) b.id = id;
    return b;
  }
  function wob(text){
    var chars = text.split(''), up = -1, dn = -1, tl = -1, out = '';
    var idx = []; chars.forEach(function(c,i){ if(c !== ' ') idx.push(i); });
    up = idx[Math.floor(Math.random()*idx.length)];
    dn = idx[Math.floor(Math.random()*idx.length)];
    tl = idx[idx.length-1 - Math.floor(Math.random()*3)];
    chars.forEach(function(c,i){
      var cls = i===up ? 'u' : i===dn ? 'd' : i===tl ? 't' : '';
      out += c === ' ' ? ' ' : '<span class="'+cls+'">'+c.replace('<','&lt;')+'</span>';
    });
    return '<span class="wob">'+out+'</span>';
  }
  function dots(){
    var odd = Math.floor(rand(1,6)), s = '<div class="dots">';
    for(var i=0;i<7;i++) s += '<i'+(i===odd?' class="odd"':'')+'></i>';
    return s + '</div>';
  }
  var toastT;
  function toast(msg){
    var t = $('#toast'); t.textContent = msg; t.classList.add('show');
    clearTimeout(toastT); toastT = setTimeout(function(){ t.classList.remove('show'); }, 2600);
  }

  var stepLabels = ['Step 1 of 4','Step 2 of 5','Step 3 of 4','Step 4 of 4½','Step 5 of 4'];
  var stages = [stageStart, stageProgress, stageClose, stageHuman, stageFinal];
  function goTo(i){
    timers.forEach(clearTimeout); timers = [];
    cancelAnimationFrame(raf); stopConfetti();
    app.innerHTML = '';
    $('#step').textContent = stepLabels[i];
    stages[i]();
    try{ window.scrollTo(0,0); }catch(e){}
  }
  function resetAll(){
    stats = { dodges:0, cookies:0, closes:0, rollbacks:0, pushes:0, robot:0, start:Date.now() };
    cookieGen = 0; cookieDone = false;
    $('#cookies').innerHTML = '';
  }

  /* ---------- Stage 0: the shy Start button ---------- */
  function stageStart(){
    app.innerHTML = '<h1>'+wob('Welcome to a Perfectly Normal Page')+'</h1>'+dots()+
      '<p class="lead">Everything here works. Mostly. Tap <b>Start</b> to begin.</p>'+
      '<div class="arena" id="arena"></div><p class="hint" id="hint">&nbsp;</p>';
    var b = button('Start','primary','startBtn');
    $('#arena').appendChild(b);
    makeDodgy(b, $('#arena'), $('#hint'), 4, function(){ goTo(1); });
    later(function(){ spawnCookie(0); }, 1300);
  }
  function makeDodgy(btn, arena, hint, max, onPress){
    var n = 0, lastDodge = 0, cool = false;
    var msgs = ['Missed!','Almost had it.','Ooh, so close.','It is a little shy.','Okay, okay. It will hold still now.'];
    function place(x,y){ btn.style.left = x+'px'; btn.style.top = y+'px'; }
    requestAnimationFrame(function(){
      place((arena.clientWidth-btn.offsetWidth)/2, (arena.clientHeight-btn.offsetHeight)/2);
    });
    function dodge(){
      var w = arena.clientWidth, h = arena.clientHeight, bw = btn.offsetWidth, bh = btn.offsetHeight;
      var cx = parseFloat(btn.style.left)||0, cy = parseFloat(btn.style.top)||0, x, y, tries = 0;
      do { x = rand(4, Math.max(5, w-bw-4)); y = rand(4, Math.max(5, h-bh-8)); tries++; }
      while(Math.hypot(x-cx, y-cy) < Math.min(w,h)*0.45 && tries < 30);
      place(x,y);
      n++; stats.dodges++; lastDodge = Date.now();
      btn.style.transform = n >= max ? 'rotate(-1.5deg)' : 'rotate('+rand(-9,9).toFixed(1)+'deg)';
      hint.textContent = msgs[Math.min(n-1, msgs.length-1)];
      if(n >= max){ btn.classList.add('tired'); btn.textContent = 'Start (fine)'; }
    }
    btn.addEventListener('pointerdown', function(e){ if(n < max){ e.preventDefault(); dodge(); } });
    arena.addEventListener('pointermove', function(e){
      if(e.pointerType !== 'mouse' || n >= max || cool) return;
      var r = btn.getBoundingClientRect();
      var d = Math.hypot(e.clientX-(r.left+r.width/2), e.clientY-(r.top+r.height/2));
      if(d < r.width/2 + 28){ cool = true; dodge(); setTimeout(function(){ cool = false; }, 380); }
    });
    btn.addEventListener('click', function(){
      if(n >= max && Date.now()-lastDodge > 300) onPress();
    });
  }

  /* ---------- Cookies that multiply ---------- */
  var cookieTexts = [
    'We use cookies to improve your experience. And because we like cookies.',
    'Thanks! Would you like to accept cookies about accepting cookies?',
    'This cookie notice uses cookies to remember that you saw it.',
    'Your cookie preferences have been saved. As a cookie.',
    'Still cookies. We baked extra.',
    'Cookie notice #6. Collect them all!',
    'Okay, this is genuinely the last one. Probably.'
  ];
  function spawnCookie(offset){
    if(cookieDone) return;
    var layer = $('#cookies');
    var c = document.createElement('div'); c.className = 'cookie';
    c.innerHTML = '<p><span class="ck"></span><span>'+cookieTexts[Math.min(cookieGen, cookieTexts.length-1)]+'</span></p>'+
      '<div class="row"><button type="button" class="btn small primary">Accept</button>'+
      '<button type="button" class="btn small ghost">Accept, but sadly</button></div>';
    var depth = layer.querySelectorAll('.cookie:not(.gone)').length;
    c.style.setProperty('--r', rand(-3,3).toFixed(1)+'deg');
    c.style.setProperty('--dx', rand(-14,14).toFixed(0)+'px');
    c.style.setProperty('--dy', (-(depth+offset)*16)+'px');
    cookieGen++;
    c.querySelectorAll('button').forEach(function(b){ b.addEventListener('click', function(){ acceptCookie(c); }); });
    layer.appendChild(c);
  }
  function acceptCookie(c){
    if(c.classList.contains('gone')) return;
    stats.cookies++;
    c.classList.add('gone'); setTimeout(function(){ c.remove(); }, 320);
    if(stats.cookies >= 6){
      cookieDone = true;
      $('#cookies').querySelectorAll('.cookie').forEach(function(x){ x.classList.add('gone'); setTimeout(function(){ x.remove(); }, 320); });
      toast('All '+cookieGen+' cookie notices accepted. You are now full.');
      return;
    }
    var live = $('#cookies').querySelectorAll('.cookie:not(.gone)').length;
    var spawn = live < 3 ? 2 : 1;
    for(var i=0;i<spawn;i++) (function(i){ setTimeout(function(){ spawnCookie(i); }, (260 + i*220)/speed()); })(i);
  }

  /* ---------- Stage 1: the 99% progress bar ---------- */
  function stageProgress(){
    app.innerHTML = '<h2>'+wob('Installing patience.exe')+'</h2>'+dots()+
      '<p class="lead" id="pmsg">Please wait. This will only take a moment.</p>'+
      '<div class="bar"><div class="fill" id="fill"></div><span class="pct" id="pct">0%</span></div>'+
      '<p class="hint" id="phint">&nbsp;</p><div class="actions" id="pact"></div>';
    var p = 0, backs = 0, state = 'run', target = 0, pushes = 0, last = performance.now();
    var fill = $('#fill'), pct = $('#pct');
    var msgs = ['Oops, recounting.','Found a few more bytes behind the sofa.','Reticulating splines again, but more carefully.'];
    function show(){
      fill.style.width = Math.min(p,100)+'%';
      pct.textContent = (p >= 99 && p < 100 ? p.toFixed(1) : Math.floor(p)) + '%';
    }
    function tick(now){
      var dt = Math.min(64, now-last) * speed(); last = now;
      if(state === 'run'){
        var rate = p < 60 ? 0.045 : p < 90 ? 0.02 : 0.008;
        p += rate * dt * (0.5 + Math.random());
        if(p >= 99){
          p = 99; state = 'hold';
          later(function(){
            if(backs < 3){
              state = 'back'; target = rand(58, 86);
              $('#phint').textContent = msgs[backs]; backs++; stats.rollbacks++;
            } else stuck();
          }, 750);
        }
      } else if(state === 'back'){
        p -= 0.06 * dt;
        if(p <= target){ p = target; state = 'run'; }
      }
      show();
      raf = requestAnimationFrame(tick);
    }
    raf = requestAnimationFrame(tick);
    function stuck(){
      state = 'stuck';
      $('#pmsg').textContent = 'Stuck at 99%. It needs a little emotional support.';
      $('#phint').innerHTML = '&nbsp;';
      var labels = ['Give it a gentle push','Push a bit harder','One more, with feeling'];
      var b = button(labels[0], 'primary', 'pushBtn');
      $('#pact').appendChild(b);
      b.addEventListener('click', function(){
        pushes++; stats.pushes++;
        if(pushes < 3){
          p = [99.4, 99.8][pushes-1]; show();
          b.textContent = labels[pushes];
          $('#phint').textContent = pushes === 1 ? 'It moved! Barely.' : 'It is thinking about it.';
        } else {
          b.remove(); state = 'done'; p = 100; show(); pct.textContent = '101%';
          $('#phint').textContent = 'Wait, that is too much.';
          later(function(){
            pct.textContent = '100%';
            $('#pmsg').textContent = 'Done! patience.exe installed. (It was already installed.)';
            $('#phint').innerHTML = '&nbsp;';
            var n = button('Next', 'primary', 'nextBtn');
            n.addEventListener('click', function(){ goTo(2); });
            $('#pact').appendChild(n);
          }, 900);
        }
      });
    }
  }

  /* ---------- Stage 2: Close buttons that spawn Close buttons ---------- */
  function stageClose(){
    app.innerHTML = '<h2>'+wob('One tiny thing')+'</h2>'+dots()+
      '<p class="lead">Before you continue, a small window would like a moment of your time.</p>'+
      '<div class="modal-wrap" id="mw"><div class="modal" id="modal">'+
      '<p class="mtitle">Subscribe to our newsletter about pop-ups?</p>'+
      '<p class="msub">Weekly. Sometimes daily. Occasionally every few minutes.</p>'+
      '<div class="mzone" id="mzone"></div></div></div><p class="hint" id="chint">&nbsp;</p>';
    var zone = $('#mzone'), taps = 0;
    var labels = ['Close','Close','Close (really)','Closé','Close ×','Close, please','Shut','Cloze','Close²','Close?','cLoSe'];
    var hints = ['Closed! Mostly.','Closed: 2. Remaining: yes.','They seem to enjoy this.','The window is multiplying out of politeness.','Closed: 5. Remaining: a few more, emotionally.','Nearly there. Probably.'];
    function addClose(x, y, first){
      var b = button(first ? 'Close' : labels[Math.floor(Math.random()*labels.length)], 'close' + (first ? '' : ' mini'));
      b.style.left = x+'%'; b.style.top = y+'%';
      b.style.transform = 'translate(-50%,-50%) rotate('+(first ? 1 : rand(-7,7)).toFixed(1)+'deg)';
      if(!first) b.style.fontSize = rand(14,20).toFixed(0)+'px';
      b.addEventListener('click', function(){
        taps++; stats.closes++; b.remove();
        $('#chint').textContent = hints[Math.min(taps-1, hints.length-1)];
        if(taps >= 7){ finale(); return; }
        var live = zone.querySelectorAll('.close').length;
        var spawn = live < 3 ? 2 : 1;
        for(var i=0;i<spawn;i++) addClose(rand(22,78), rand(14,86));
      });
      zone.appendChild(b);
    }
    addClose(50, 55, true);
    function finale(){
      zone.innerHTML = '';
      var b = button('Close all the Close buttons', 'primary big', 'closeAll');
      b.style.position = 'absolute'; b.style.left = '50%'; b.style.top = '50%';
      b.style.transform = 'translate(-50%,-50%) rotate(-1deg)'; b.style.maxWidth = '92%'; b.style.whiteSpace = 'normal';
      zone.appendChild(b);
      $('#chint').textContent = 'A wild master button appeared.';
      b.addEventListener('click', function(){
        $('#modal').classList.add('shrink');
        later(function(){
          $('#mw').innerHTML = '<p class="lead" style="margin:10px 4px">The window has been closed. It says goodbye, and that it will miss you.</p>';
          $('#chint').innerHTML = '&nbsp;';
          var n = button('Next', 'primary', 'nextBtn');
          n.addEventListener('click', function(){ goTo(3); });
          var a = document.createElement('div'); a.className = 'actions'; a.appendChild(n); app.appendChild(a);
        }, 480);
      });
    }
  }

  /* ---------- Stage 3: very human check ---------- */
  function stageHuman(){
    app.innerHTML = '<h2>'+wob('Quick human check')+'</h2>'+dots()+
      '<p class="lead">Nothing personal. We just need to be sure.</p>';
    var chk = document.createElement('button');
    chk.type = 'button'; chk.className = 'btn check'; chk.id = 'chk';
    chk.innerHTML = '<span class="box"></span><span>I am not a robot</span>';
    app.appendChild(chk);
    var hint = document.createElement('p'); hint.className = 'hint'; hint.innerHTML = '&nbsp;'; app.appendChild(hint);
    var tries = 0, locked = false;
    chk.addEventListener('click', function(){
      if(locked || chk.classList.contains('on')) return;
      chk.classList.add('on'); tries++;
      if(tries < 3){
        locked = true; stats.robot++;
        later(function(){
          chk.classList.remove('on'); locked = false;
          hint.textContent = ['Hm. That tap felt a little bit robotic.','Try again, but more human. Maybe sigh first.'][tries-1];
        }, 900);
      } else {
        hint.textContent = 'Very human. Lovely sighing.';
        locked = true;
        later(showGrid, 500);
      }
    });

    function showGrid(){
      var s = document.createElement('div'); s.className = 'section';
      s.innerHTML = '<p style="margin:0 0 4px"><b>Select all squares that contain a square.</b></p>';
      var g = document.createElement('div'); g.className = 'grid'; g.id = 'grid';
      var odd = Math.floor(rand(0,9));
      for(var i=0;i<9;i++){
        var t = document.createElement('button'); t.type = 'button'; t.className = 'tile' + (i===odd ? ' odd' : '');
        t.setAttribute('aria-label','square '+(i+1));
        t.style.setProperty('--r', (i===4 ? 3 : (i%3===2 ? -1.5 : 0))+'deg');
        t.addEventListener('click', function(){ this.classList.toggle('sel'); });
        g.appendChild(t);
      }
      s.appendChild(g);
      var gh = document.createElement('p'); gh.className = 'hint'; gh.innerHTML = '&nbsp;';
      var act = document.createElement('div'); act.className = 'actions';
      var v = button('Verify', 'primary', 'verifyBtn'); act.appendChild(v);
      s.appendChild(act); s.appendChild(gh);
      app.appendChild(s);
      var fails = 0;
      v.addEventListener('click', function(){
        var n = g.querySelectorAll('.sel').length;
        if(n === 9){ gh.textContent = 'Correct. They were all squares. Even that one.'; done(); }
        else if(fails === 0){ fails++; gh.textContent = n === 0 ? 'You selected nothing. Bold.' : 'Some squares feel left out. (Hint: they are all squares.)'; }
        else { gh.textContent = 'Close enough. We are not monsters.'; g.querySelectorAll('.tile').forEach(function(t){ t.classList.add('sel'); }); done(); }
      });
      function done(){ v.disabled = true; v.style.opacity = .5; later(showYesNo, 700); }
    }

    function showYesNo(){
      var s = document.createElement('div'); s.className = 'section';
      s.innerHTML = '<p style="margin:0"><b>Do you wish to continue?</b></p>';
      var yn = document.createElement('div'); yn.className = 'yn';
      var yes = button('Yes', 'primary', 'yesBtn'), no = button('No', '', 'noBtn');
      yn.appendChild(yes); yn.appendChild(no);
      var h = document.createElement('p'); h.className = 'hint'; h.innerHTML = '&nbsp;';
      s.appendChild(yn); s.appendChild(h); app.appendChild(s);
      var swapped = false;
      yes.addEventListener('click', function(){
        if(!swapped){ swapped = true; yn.classList.add('swap'); h.textContent = 'Sorry, they swapped places. Old habit. Yes is still Yes.'; return; }
        goTo(4);
      });
      no.addEventListener('click', function(){
        if(no.textContent === 'No'){ no.textContent = 'Also yes'; h.textContent = '"No" has been discontinued. Please enjoy "Also yes".'; return; }
        goTo(4);
      });
    }
  }

  /* ---------- Stage 4: thank you ---------- */
  function stageFinal(){
    var secs = Math.round((Date.now() - stats.start)/1000);
    var time = Math.floor(secs/60) + ':' + ('0'+(secs%60)).slice(-2);
    app.innerHTML = '<h1>'+wob('Thank you for your patience.')+'</h1>'+dots()+
      '<p class="lead">You made it. Everything is perfectly normal now. Please ignore that one slightly crooked thing.</p>'+
      '<ul class="stats">'+
      '<li>Start button dodges survived: <b>'+stats.dodges+'</b></li>'+
      '<li>Cookie notices accepted: <b>'+stats.cookies+'</b></li>'+
      '<li>Progress bar rollbacks endured: <b>'+stats.rollbacks+'</b></li>'+
      '<li>Close buttons closed: <b>'+stats.closes+'</b></li>'+
      '<li>Times mistaken for a robot: <b>'+stats.robot+'</b></li>'+
      '<li>Total patience spent: <b>'+time+'</b></li></ul>'+
      '<p class="hint">Your patience has been saved. Not as a cookie, we promise.</p>';
    var a = document.createElement('div'); a.className = 'actions';
    var again = button('Start over (it will be the same)', 'primary', 'againBtn');
    again.style.whiteSpace = 'normal';
    again.addEventListener('click', function(){ resetAll(); goTo(0); });
    a.appendChild(again); app.appendChild(a);
    startConfetti();
  }

  /* ---------- gentle, crooked confetti ---------- */
  var cv = $('#conf'), cx = cv.getContext('2d'), pieces = [], confRaf = 0, confEnd = 0;
  function sizeCanvas(){
    var d = window.devicePixelRatio || 1;
    cv.width = innerWidth*d; cv.height = innerHeight*d;
    cv.style.width = innerWidth+'px'; cv.style.height = innerHeight+'px';
    cx.setTransform(d,0,0,d,0,0);
  }
  window.addEventListener('resize', sizeCanvas); sizeCanvas();
  function startConfetti(){
    var cols = ['#ffd84d','#7fb3ff','#6cc070','#f2a07b','#c7a6ff'];
    pieces = [];
    for(var i=0;i<60;i++) pieces.push({ x:rand(0,innerWidth), y:rand(-innerHeight,-10), s:rand(7,13), vy:rand(.4,1.1), a:rand(0,6.28), va:rand(-.02,.02), sw:rand(0,6.28), c:cols[i%cols.length] });
    confEnd = performance.now() + 9000;
    cancelAnimationFrame(confRaf);
    (function loop(now){
      cx.clearRect(0,0,innerWidth,innerHeight);
      var alive = false;
      pieces.forEach(function(p){
        p.y += p.vy*speed(); p.sw += .02; p.a += p.va;
        if(p.y > innerHeight + 20){ if(now < confEnd){ p.y = -20; p.x = rand(0,innerWidth); } else return; }
        alive = true;
        cx.save(); cx.translate(p.x + Math.sin(p.sw)*12, p.y); cx.rotate(p.a);
        cx.fillStyle = p.c; cx.fillRect(-p.s/2, -p.s/2, p.s, p.s*0.92); cx.restore();
      });
      if(alive) confRaf = requestAnimationFrame(loop); else cx.clearRect(0,0,innerWidth,innerHeight);
    })(performance.now());
  }
  function stopConfetti(){ cancelAnimationFrame(confRaf); cx.clearRect(0,0,innerWidth,innerHeight); }

  /* ---------- hands-free demo (#demo) ---------- */
  var finger = $('#finger');
  function sleep(ms){
    return new Promise(function(res, rej){
      setTimeout(function(){ demo.active ? res() : rej('stopped'); }, ms);
    });
  }
  async function waitFor(sel, max){
    var t = 0;
    while(t < (max||10000)){ var el = document.querySelector(sel); if(el) return el; await sleep(100); t += 100; }
    return null;
  }
  async function tap(sel){
    var el = typeof sel === 'string' ? document.querySelector(sel) : sel;
    if(!el) return;
    var r = el.getBoundingClientRect();
    finger.style.left = (r.left + r.width/2) + 'px'; finger.style.top = (r.top + r.height/2) + 'px';
    await sleep(380);
    finger.classList.add('press');
    try{ el.dispatchEvent(new PointerEvent('pointerdown', { bubbles:true, cancelable:true, pointerType:'touch' })); }catch(e){}
    await sleep(110);
    finger.classList.remove('press');
    try{ el.dispatchEvent(new PointerEvent('pointerup', { bubbles:true, pointerType:'touch' })); }catch(e){}
    if(document.contains(el)) el.click();
  }
  async function runDemo(){
    if(demo.active) return;
    demo.active = true; document.body.classList.add('demo');
    try{
      while(demo.active){
        resetAll(); goTo(0);
        await sleep(500);
        for(var i=0;i<4;i++){ await tap('#startBtn'); await sleep(200); }
        await waitFor('.cookie:not(.gone)', 2000);
        await tap('.cookie:not(.gone):last-child .btn'); await sleep(350);
        await tap('.cookie:not(.gone):last-child .btn'); await sleep(250);
        await tap('#startBtn');
        var pb = await waitFor('#pushBtn', 12000);
        for(var j=0;j<3;j++){ await tap('#pushBtn'); await sleep(150); }
        await waitFor('#nextBtn', 3000); await tap('#nextBtn');
        await sleep(300);
        for(var k=0;k<7;k++){ var cs = document.querySelectorAll('#mzone .close'); if(!cs.length) break; await tap(cs[cs.length-1]); await sleep(120); }
        await waitFor('#closeAll', 2000); await tap('#closeAll');
        await waitFor('#nextBtn', 3000); await sleep(150); await tap('#nextBtn');
        await sleep(300);
        await tap('#chk'); await sleep(450);
        await tap('#chk'); await sleep(450);
        await tap('#chk');
        await waitFor('#grid', 3000); await sleep(200);
        var tiles = document.querySelectorAll('#grid .tile');
        await tap(tiles[0]); await tap(tiles[4]); await tap(tiles[8]);
        await tap('#verifyBtn'); await sleep(350); await tap('#verifyBtn');
        await waitFor('#yesBtn', 3000); await sleep(150);
        await tap('#yesBtn'); await sleep(450); await tap('#yesBtn');
        finger.style.left = '-100px'; finger.style.top = '-100px';
        await sleep(3500);
      }
    }catch(e){}
  }
  function stopDemo(){
    if(!demo.active) return;
    demo.active = false; document.body.classList.remove('demo');
    finger.style.left = '-100px'; finger.style.top = '-100px';
    try{ history.replaceState(null, '', location.pathname + location.search); }catch(e){}
    resetAll(); goTo(0);
  }
  window.addEventListener('pointerdown', function(e){
    if(e.isTrusted && demo.active){ e.preventDefault(); e.stopPropagation(); stopDemo(); }
  }, true);
  window.addEventListener('click', function(e){
    if(e.isTrusted && document.body.classList.contains('demo')){ e.preventDefault(); e.stopPropagation(); }
  }, true);
  window.addEventListener('hashchange', function(){ if(location.hash === '#demo') runDemo(); });

  resetAll(); goTo(0);
  if(location.hash === '#demo') runDemo();
})();
</script>
</body>
</html>