Skip to content
VibeCodeBench
Back to the app

The code

The Most Uncomfortable Web Page by GPT-6.2 Sol

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.)28.2 KB · 727 lines · no libraries
Download
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#f5efe2">
<title>Please Hold — Office of Minor Inconveniences</title>
<style>
  :root {
    --paper: #f5efe2;
    --white: #fffcf3;
    --ink: #24231f;
    --muted: #656052;
    --blue: #263acb;
    --deep: #17278f;
    --orange: #ff895f;
    --yellow: #ffd96f;
    --line: #c9c1b2;
    --mono: "Courier New", Courier, monospace;
    --sans: Arial, Helvetica, sans-serif;
  }

  * { box-sizing: border-box; }

  body {
    margin: 0;
    min-width: 280px;
    min-height: 100vh;
    color: var(--ink);
    background-color: var(--paper);
    background-image: radial-gradient(#5f503417 .7px, transparent .85px);
    background-size: 6px 6px;
    font-family: var(--sans);
  }

  button { color: inherit; font: inherit; cursor: pointer; touch-action: manipulation; }
  button:focus-visible { outline: 3px solid var(--blue); outline-offset: 4px; }
  button:disabled { cursor: wait; }
  [hidden] { display: none !important; }

  .shell { width: min(1180px, calc(100% - 88px)); margin: 0 auto; }
  .masthead {
    min-height: 82px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    border-bottom: 1px solid var(--ink);
  }
  .brand, .system-status { display: flex; align-items: center; }
  .brand { gap: 11px; }
  .brand-mark {
    width: 37px;
    aspect-ratio: 1;
    display: grid;
    place-content: center;
    gap: 2px;
    background: var(--blue);
    transform: rotate(-4deg);
  }
  .brand-mark i { display: block; width: 17px; height: 3px; background: var(--white); }
  .brand-mark i:nth-child(2) { transform: translateX(2px); }
  .brand-mark i:nth-child(3) { transform: translateX(-2px); }
  .brand-name { font-weight: 800; font-size: 13px; line-height: 1.1; }
  .system-status, .eyebrow, .ticket-label, .terminal-bar, .readout-label, .ticks, .desk-label, .footer, .receipt-label {
    font: 700 11px/1.25 var(--mono);
    letter-spacing: .075em;
    text-transform: uppercase;
  }
  .system-status { gap: 9px; color: var(--deep); }
  .status-dot { flex: 0 0 auto; width: 8px; height: 8px; border-radius: 50%; background: var(--blue); box-shadow: 0 0 0 3px #263acb22; }
  .hero {
    display: grid;
    grid-template-columns: minmax(0, .96fr) minmax(0, 1.04fr);
    gap: clamp(34px, 5.5vw, 86px);
    align-items: center;
    padding: 48px 0 43px;
  }
  .intro { position: relative; }
  .eyebrow {
    display: inline-block;
    padding: 7px 10px 6px;
    border: 1px solid var(--ink);
    background: var(--yellow);
    box-shadow: 2px 2px var(--ink);
    transform: rotate(-3deg);
  }
  .hero-title, .finish-title {
    font-family: "Arial Black", Arial, sans-serif;
    font-weight: 900;
    color: var(--blue);
    letter-spacing: -.095em;
  }
  .hero-title {
    font-size: clamp(76px, 10.2vw, 149px);
    line-height: .78;
    margin: 23px 0 25px -7px;
  }
  .hero-title span { display: block; transform: translate(3px, 1px) rotate(-2deg); }
  .hero-title b { color: var(--orange); -webkit-text-stroke: 1px var(--ink); margin-left: 2px; }
  .intro-copy { font-size: clamp(16px, 1.65vw, 21px); line-height: 1.35; font-weight: 600; margin: 0 0 24px; }
  .intro-copy span { display: inline-block; transform: translate(1px, 1px); }

  .ticket {
    position: relative;
    max-width: 330px;
    min-height: 79px;
    padding: 13px 17px 12px;
    display: grid;
    grid-template-columns: 1fr .9fr 47px;
    align-items: center;
    gap: 13px;
    background: var(--orange);
    border: 1px solid var(--ink);
    box-shadow: 3px 3px var(--ink);
    transform: rotate(2deg);
  }
  .ticket::before, .ticket::after {
    content: "";
    position: absolute;
    width: 12px;
    height: 12px;
    top: calc(50% - 6px);
    border: 1px solid var(--ink);
    border-radius: 50%;
    background: var(--paper);
  }
  .ticket::before { left: -7px; clip-path: inset(0 0 0 50%); }
  .ticket::after { right: -7px; clip-path: inset(0 50% 0 0); }
  .ticket-label { font-size: 10px; display: block; }
  .ticket-number { display: block; font: 700 29px/.95 var(--mono); letter-spacing: -.085em; margin-top: 4px; }
  .ticket-stub { border-left: 1px dashed #29231db3; padding-left: 13px; }
  .barcode { height: 34px; background: repeating-linear-gradient(90deg, var(--ink) 0 2px, transparent 2px 4px, var(--ink) 4px 5px, transparent 5px 8px, var(--ink) 8px 11px, transparent 11px 12px, var(--ink) 12px 13px, transparent 13px 16px); }

  .terminal {
    position: relative;
    min-width: 0;
    border: 2px solid var(--ink);
    border-radius: 9px;
    background: var(--white);
    box-shadow: 7px 7px 0 var(--ink);
  }
  .terminal-bar {
    display: flex;
    min-height: 47px;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 17px;
    border-bottom: 2px solid var(--ink);
    border-radius: 6px 6px 0 0;
    background: var(--blue);
    color: var(--white);
  }
  .terminal-name, .terminal-id { display: flex; align-items: center; gap: 9px; }
  .terminal-icon {
    width: 16px;
    height: 12px;
    border: 1px solid currentColor;
    border-radius: 2px;
    position: relative;
  }
  .terminal-icon::after { content: ""; position: absolute; left: 3px; bottom: 3px; height: 1px; width: 6px; background: currentColor; }
  .terminal-id::before { content: ""; width: 6px; height: 6px; background: var(--yellow); border-radius: 50%; }
  .terminal-body { padding: 22px 24px 15px; }
  .readout {
    padding: 20px 20px 15px;
    border: 1px solid #a8aff0;
    border-radius: 4px;
    color: var(--deep);
    background-color: #eeefff;
    background-image: linear-gradient(#263acb0d 1px, transparent 1px), linear-gradient(90deg, #263acb0d 1px, transparent 1px);
    background-size: 12px 12px;
  }
  .readout-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
  .readout-label { margin: 2px 0 0; }
  .readout-number {
    margin: 0;
    font: 700 clamp(54px, 6.1vw, 88px)/.86 var(--mono);
    letter-spacing: -.10em;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
  }
  .readout-number span { font-size: .47em; letter-spacing: -.07em; margin-left: 3px; }
  .gauge { position: relative; height: 23px; border: 1px solid var(--deep); margin-top: 19px; overflow: hidden; background: #fffcf39e; }
  .gauge::after {
    content: "";
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(90deg, transparent 0 calc(10% - 1px), #1828953f calc(10% - 1px) 10%);
    pointer-events: none;
  }
  .gauge-fill { height: 100%; width: 0%; background: repeating-linear-gradient(-55deg, var(--blue) 0 7px, #4d5de0 7px 12px); transition: width .6s cubic-bezier(.25,.75,.2,1); }
  .ticks { display: flex; justify-content: space-between; margin-top: 6px; font-size: 10px; }
  .diagnostic {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    min-height: 41px;
    padding-top: 14px;
    font: 700 12px/1.35 var(--mono);
  }
  .diagnostic::before { content: ">"; color: var(--blue); font-weight: bold; }
  .action-track {
    min-height: 73px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-top: 1px dashed var(--line);
    margin-top: 8px;
  }
  .primary {
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    border: 1px solid var(--ink);
    border-radius: 4px;
    padding: 0 15px;
    min-height: 50px;
    font-weight: 800;
    background: var(--blue);
    color: var(--white);
    box-shadow: 3px 3px 0 var(--ink);
    transition: transform .23s ease-out, background-color .15s;
  }
  #advance {
    width: min(300px, calc(100% - 42px));
    transform: translate(var(--dodge-x, 0px), var(--dodge-y, 0px));
  }
  .primary:hover { background: var(--deep); }
  .primary:disabled { opacity: .75; }
  .arrow { font: 400 24px/1 var(--mono); }

  .paperwork { border-top: 1px solid var(--ink); padding-top: 13px; }
  .desk-label { display: flex; align-items: center; gap: 8px; margin: 0 0 10px; color: var(--muted); }
  .desk-label::before { content: ""; width: 9px; height: 9px; background: var(--orange); border: 1px solid var(--ink); transform: rotate(-8deg); }
  .cards { display: grid; gap: 12px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .card {
    min-width: 0;
    display: grid;
    grid-template-columns: 35px minmax(0, 1fr);
    column-gap: 10px;
    align-items: start;
    padding: 12px 12px 7px;
    border: 1px solid var(--ink);
    border-radius: 5px;
    background: var(--white);
  }
  .card-heading { margin: 1px 0 4px; font-weight: 800; font-size: 15px; }
  .card-copy { margin: 0; min-height: 16px; font-size: 12px; line-height: 1.35; color: var(--muted); }
  .mini-action, .demo-button {
    min-height: 44px;
    border: 0;
    padding: 0 5px;
    margin-left: -5px;
    background: transparent;
    color: var(--deep);
    font: 700 12px/1.2 var(--mono);
    text-decoration: underline;
    text-underline-offset: 3px;
    text-align: left;
  }
  .mini-action:hover, .demo-button:hover { color: var(--blue); }
  .icon-box { position: relative; width: 33px; height: 33px; display: grid; place-items: center; border: 1px solid var(--ink); border-radius: 4px; background: var(--yellow); transform: rotate(-4deg); }
  .card:nth-child(2) .icon-box { background: #e2e5ff; transform: rotate(3deg); }
  .card:nth-child(3) .icon-box { background: #ffc3ad; transform: rotate(-2deg); }
  .cookie-icon {
    width: 20px;
    height: 20px;
    border: 1px solid var(--ink);
    border-radius: 47% 53% 51% 49%;
    background: radial-gradient(circle at 6px 5px, var(--ink) 1.2px, transparent 1.6px), radial-gradient(circle at 12px 8px, var(--ink) 1.2px, transparent 1.6px), radial-gradient(circle at 8px 13px, var(--ink) 1.2px, transparent 1.6px), var(--orange);
  }
  .close-icon { width: 19px; height: 16px; border: 1px solid var(--ink); display: grid; place-items: center; background: var(--white); font: 700 13px/1 var(--mono); }
  .align-icon { display: grid; justify-items: start; gap: 3px; }
  .align-icon i { display: block; width: 17px; height: 2px; background: var(--ink); }
  .align-icon i:nth-child(2) { transform: translateX(2px) rotate(5deg); }
  .align-icon i:nth-child(3) { transform: translateX(-1px); width: 12px; }
  .align-icon[data-aligned="left"] i:nth-child(1) { transform: translateX(3px) rotate(-5deg); }
  .align-icon[data-aligned="left"] i:nth-child(2) { transform: none; }
  .align-icon[data-aligned="right"] i:nth-child(2) { transform: translateX(-2px) rotate(-7deg); }
  .align-icon[data-aligned="right"] i:nth-child(3) { transform: translateX(3px); }

  .cookie-pile, .close-pile {
    grid-column: 1 / -1;
    display: grid;
    gap: 6px;
    margin: 2px 0 5px;
  }
  .notice {
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding-left: 8px;
    border: 1px solid var(--ink);
    border-radius: 3px;
    background: #fff0bd;
    font: 700 11px/1.2 var(--mono);
  }
  .notice:nth-child(even) { background: #ffe1d4; transform: translateX(1px) rotate(-.6deg); }
  .notice button, .spawned-close {
    min-height: 44px;
    min-width: 44px;
    border: 0;
    background: transparent;
    color: var(--deep);
    font: 700 14px/1 var(--mono);
  }
  .close-pile { display: flex; flex-wrap: wrap; align-items: center; }
  .spawned-close { border: 1px solid var(--ink); border-radius: 3px; padding: 0 8px; background: #e2e5ff; transform: rotate(-2deg); font-size: 12px; }
  .spawned-close:nth-child(even) { transform: rotate(2deg); background: var(--white); }

  .footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 61px;
    color: var(--muted);
  }
  .demo-button { margin: 0 -5px 0 0; text-align: right; letter-spacing: 0; }

  .finish {
    margin-top: 45px;
    padding: clamp(24px, 5.5vw, 68px) 22px;
    text-align: center;
    border: 2px solid var(--ink);
    border-radius: 9px;
    box-shadow: 7px 7px var(--ink);
    background-color: var(--white);
    background-image: linear-gradient(#263acb10 1px, transparent 1px), linear-gradient(90deg, #263acb10 1px, transparent 1px);
    background-size: 18px 18px;
  }
  .finish-title { margin: 20px auto 12px; font-size: clamp(46px, 8.8vw, 113px); line-height: .87; }
  .finish-title:focus { outline: 0; }
  .finish-copy { margin: 16px auto 20px; font-size: clamp(15px, 1.8vw, 21px); line-height: 1.4; }
  .receipt {
    position: relative;
    width: min(100%, 360px);
    margin: 0 auto 24px;
    text-align: left;
    display: grid;
    gap: 9px;
    padding: 15px 13px;
    border: 1px solid var(--ink);
    background: var(--paper);
    box-shadow: 3px 3px var(--ink);
    transform: rotate(-1deg);
  }
  .receipt-row { display: flex; justify-content: space-between; gap: 10px; align-items: center; border-bottom: 1px dashed var(--line); padding-bottom: 5px; }
  .receipt-row:last-child { border: 0; padding-bottom: 0; }
  .receipt-row strong { font: 700 14px/1.1 var(--mono); color: var(--deep); text-align: right; }

  @media (max-width: 1020px) {
    .shell { width: calc(100% - 60px); }
    .hero { gap: 38px; }
  }
  @media (max-width: 740px) {
    .shell { width: calc(100% - 38px); max-width: 550px; }
    .masthead { min-height: 67px; }
    .hero { grid-template-columns: 1fr; gap: 24px; padding: 25px 0 28px; }
    .intro { padding-left: 5px; }
    .hero-title { font-size: clamp(69px, 15.5vw, 107px); margin: 18px 0 15px -4px; line-height: .83; }
    .hero-title span { display: inline-block; }
    .intro-copy { margin-bottom: 16px; }
    .ticket { max-width: 290px; min-height: 60px; padding: 8px 14px; }
    .ticket-number { font-size: 23px; }
    .barcode { height: 27px; }
    .terminal { margin-right: 5px; box-shadow: 5px 5px var(--ink); }
    .terminal-body { padding: 13px 14px 8px; }
    .readout { padding: 14px 12px 10px; }
    .gauge { margin-top: 12px; }
    .cards { grid-template-columns: 1fr; }
    .card { padding: 10px 11px 4px; }
    .finish { margin-top: 25px; }
  }
  @media (max-width: 430px) {
    .shell { width: calc(100% - 30px); }
    .brand-name { font-size: 11px; }
    .brand { gap: 8px; }
    .brand-mark { width: 31px; }
    .system-status { font-size: 9px; letter-spacing: .035em; max-width: 113px; gap: 6px; }
    .hero-title { font-size: clamp(46px, 14.5vw, 65px); letter-spacing: -.09em; }
    .readout-label { font-size: 10px; max-width: 95px; }
    .terminal-bar { padding-inline: 11px; }
    .footer { font-size: 10px; }
  }
  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; }
  }
</style>
</head>
<body>
<div class="shell">
  <header class="masthead">
    <div class="brand">
      <span class="brand-mark" aria-hidden="true"><i></i><i></i><i></i></span>
      <span class="brand-name">Office of Minor<br>Inconveniences</span>
    </div>
    <div class="system-status"><span class="status-dot" aria-hidden="true"></span> Mostly operational</div>
  </header>

  <main>
    <div id="waiting-room">
      <section class="hero">
        <div class="intro">
          <div class="eyebrow">Department of waiting</div>
          <h1 class="hero-title">Please <span>hold<b>.</b></span></h1>
          <p class="intro-copy">You’re in the right place.<br><span>That’s about all we can promise.</span></p>
          <div class="ticket" aria-label="Now serving 000. Your ticket is 001.">
            <div><span class="ticket-label">Now serving</span><strong class="ticket-number">000</strong></div>
            <div class="ticket-stub"><span class="ticket-label">Your ticket</span><strong class="ticket-number">001</strong></div>
            <div class="barcode" aria-hidden="true"></div>
          </div>
        </div>

        <section class="terminal" id="terminal" aria-labelledby="terminal-name">
          <header class="terminal-bar">
            <span class="terminal-name" id="terminal-name"><span class="terminal-icon" aria-hidden="true"></span> Patience terminal</span>
            <span class="terminal-id">Desk 01</span>
          </header>
          <div class="terminal-body">
            <div class="readout">
              <div class="readout-top">
                <p class="readout-label">Estimated progress</p>
                <p class="readout-number" aria-hidden="true"><b id="percent">0</b><span>%</span></p>
              </div>
              <div class="gauge" id="gauge" role="progressbar" aria-label="Queue progress" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"><div class="gauge-fill" id="gauge-fill"></div></div>
              <div class="ticks" aria-hidden="true"><span>00</span><span>25</span><span>50</span><span>75</span><span>100</span></div>
            </div>
            <div class="diagnostic"><span id="diagnostic" role="status">Ready when we are.</span></div>
            <div class="action-track" id="action-track">
              <button class="primary" id="advance" type="button"><span id="advance-label">Begin waiting</span><span class="arrow" aria-hidden="true">↗</span></button>
            </div>
          </div>
        </section>
      </section>

      <section class="paperwork" aria-labelledby="paperwork-heading">
        <h2 class="desk-label" id="paperwork-heading">Optional paperwork</h2>
        <div class="cards">
          <article class="card" id="cookie-card">
            <span class="icon-box" aria-hidden="true"><span class="cookie-icon"></span></span>
            <div>
              <h3 class="card-heading">Cookie notice</h3>
              <p class="card-copy" id="cookie-copy" role="status">One completely unnecessary notice.</p>
              <button class="mini-action" id="dismiss-cookie" type="button">Dismiss notice ↗</button>
            </div>
            <div class="cookie-pile" id="cookie-pile" hidden></div>
          </article>
          <article class="card" id="close-card">
            <span class="icon-box" aria-hidden="true"><span class="close-icon">×</span></span>
            <div>
              <h3 class="card-heading">Closing department</h3>
              <p class="card-copy" id="close-copy" role="status">Now accepting requests to stop.</p>
              <button class="mini-action" id="close-desk" type="button">Close ↗</button>
            </div>
            <div class="close-pile" id="close-pile" hidden></div>
          </article>
          <article class="card" id="align-card">
            <span class="icon-box" aria-hidden="true"><span class="align-icon" id="align-icon"><i></i><i></i><i></i></span></span>
            <div>
              <h3 class="card-heading" id="align-heading">Alignment desk</h3>
              <p class="card-copy" id="align-copy" role="status">Off by the approved amount.</p>
              <button class="mini-action" id="align-button" type="button">Fix alignment ↗</button>
            </div>
          </article>
        </div>
      </section>
    </div>

    <section class="finish" id="finish" hidden>
      <div class="eyebrow">Finally processed</div>
      <h1 class="finish-title" id="finish-title" tabindex="-1">Thank you for<br>your patience.</h1>
      <p class="finish-copy">Your wait has been processed in the order it was experienced.</p>
      <div class="receipt" aria-label="Waiting receipt">
        <div class="receipt-row"><span class="receipt-label">Ticket</span><strong>001 / Complete</strong></div>
        <div class="receipt-row"><span class="receipt-label">Button evasions</span><strong id="evasion-total">02</strong></div>
        <div class="receipt-row"><span class="receipt-label">Patience refund</span><strong>0 minutes</strong></div>
      </div>
      <button class="primary" id="restart" type="button">Take another number <span class="arrow" aria-hidden="true">↺</span></button>
    </section>
  </main>

  <footer class="footer">
    <span>Office hours vary by minute.</span>
    <button class="demo-button" id="demo" type="button">Run demo ▷</button>
  </footer>
</div>

<script>
  "use strict";

  const byId = (id) => document.getElementById(id);
  const room = byId("waiting-room");
  const finish = byId("finish");
  const advance = byId("advance");
  const advanceLabel = byId("advance-label");
  const diagnostic = byId("diagnostic");
  const cookiePile = byId("cookie-pile");
  const closePile = byId("close-pile");
  const demoButton = byId("demo");
  const reducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)");

  let dodges = 0;
  let stage = 0;
  let cookieCount = 0;
  let closeCount = 0;
  let alignmentCount = 0;
  let progressTimer;
  let demoActive = false;
  let demoTimers = [];

  function setProgress(value) {
    byId("percent").textContent = value;
    byId("gauge").setAttribute("aria-valuenow", value);
    byId("gauge-fill").style.width = value + "%";
  }

  function moveButton(direction) {
    const track = byId("action-track");
    const space = Math.max(0, (track.clientWidth - advance.offsetWidth) / 2 - 4);
    advance.style.setProperty("--dodge-x", direction * Math.min(64, space) + "px");
    advance.style.setProperty("--dodge-y", direction * 6 + "px");
  }

  function showFinish() {
    room.hidden = true;
    finish.hidden = false;
    byId("evasion-total").textContent = String(dodges).padStart(2, "0");
    window.scrollTo(0, 0);
    if (!demoActive) byId("finish-title").focus({ preventScroll: true });
  }

  function advanceQueue(event) {
    if (advance.disabled || finish.hidden === false) return;

    if (dodges < 2) {
      dodges += 1;
      const buttonBox = advance.getBoundingClientRect();
      const firstDirection = event && event.detail && event.clientX > buttonBox.left + buttonBox.width / 2 ? -1 : 1;
      moveButton(dodges === 1 ? firstDirection : -Math.sign(parseFloat(advance.style.getPropertyValue("--dodge-x")) || 1));
      diagnostic.textContent = dodges === 1 ? "The button has requested personal space." : "It says it’s ready this time.";
      advanceLabel.textContent = "Try that again";
      return;
    }

    moveButton(0);
    stage += 1;
    if (stage === 1) {
      setProgress(64);
      diagnostic.textContent = "Great news. We found the queue.";
      advanceLabel.textContent = "Advance the queue";
      return;
    }

    advance.disabled = true;
    if (stage === 2) {
      setProgress(99);
      diagnostic.textContent = "Any second now…";
      progressTimer = window.setTimeout(() => {
        setProgress(73);
        diagnostic.textContent = "We rounded down for accuracy.";
        advanceLabel.textContent = "Try to finish";
        advance.disabled = false;
      }, 1050);
      return;
    }

    setProgress(100);
    diagnostic.textContent = "Please hold while we confirm you’re done.";
    advanceLabel.textContent = "Verifying completion…";
    progressTimer = window.setTimeout(showFinish, 800);
  }

  function dismissCookie(event) {
    const fromNotice = event.currentTarget !== byId("dismiss-cookie");
    if (cookieCount === 4) {
      cookieCount = 0;
      cookiePile.replaceChildren();
      cookiePile.hidden = true;
      byId("cookie-copy").textContent = "The notices have gone on break.";
      if (fromNotice) byId("dismiss-cookie").focus({ preventScroll: true });
      return;
    }

    const nextCount = cookieCount ? cookieCount + 1 : 2;
    for (let number = cookieCount + 1; number <= nextCount; number += 1) {
      const notice = document.createElement("div");
      notice.className = "notice";
      const message = document.createElement("span");
      message.textContent = number === 1 ? "Dismissal receipt" : "Notice about notice " + (number - 1);
      const button = document.createElement("button");
      button.type = "button";
      button.textContent = "×";
      button.setAttribute("aria-label", "Dismiss " + message.textContent.toLowerCase());
      button.addEventListener("click", dismissCookie);
      notice.append(message, button);
      cookiePile.append(notice);
    }
    cookieCount = nextCount;
    cookiePile.hidden = false;
    byId("cookie-copy").textContent = cookieCount === 4 ? "Four notices. One more dismissal clears them." : cookieCount + " notices. Your dismissal was noted.";
  }

  function requestClose(event) {
    closeCount += 1;
    if (closeCount > 3) {
      closeCount = 0;
      closePile.replaceChildren();
      closePile.hidden = true;
      byId("close-copy").textContent = "Request closed. The department is still here.";
      if (event.currentTarget !== byId("close-desk")) byId("close-desk").focus({ preventScroll: true });
      return;
    }

    const button = document.createElement("button");
    button.type = "button";
    button.className = "spawned-close";
    button.textContent = ["Close ×", "Close again ×", "Really close ×"][closeCount - 1];
    button.addEventListener("click", requestClose);
    closePile.append(button);
    closePile.hidden = false;
    byId("close-copy").textContent = ["Please close the new Close button.", "Closing now requires a second opinion.", "One last Close should do it."][closeCount - 1];
  }

  function fixAlignment() {
    alignmentCount += 1;
    const left = alignmentCount % 2 === 1;
    byId("align-icon").dataset.aligned = left ? "left" : "right";
    byId("align-heading").style.transform = left ? "translateX(1px) rotate(-1deg)" : "translateY(1px) rotate(1deg)";
    byId("align-copy").textContent = left ? "Fixed one line. The next line moved." : "Now off by one pixel in a new direction.";
  }

  function resetRoom() {
    window.clearTimeout(progressTimer);
    dodges = 0;
    stage = 0;
    cookieCount = 0;
    closeCount = 0;
    alignmentCount = 0;
    cookiePile.replaceChildren();
    closePile.replaceChildren();
    cookiePile.hidden = true;
    closePile.hidden = true;
    byId("cookie-copy").textContent = "One completely unnecessary notice.";
    byId("close-copy").textContent = "Now accepting requests to stop.";
    byId("align-copy").textContent = "Off by the approved amount.";
    byId("align-heading").style.removeProperty("transform");
    delete byId("align-icon").dataset.aligned;
    finish.hidden = true;
    room.hidden = false;
    setProgress(0);
    diagnostic.textContent = "Ready when we are.";
    advanceLabel.textContent = "Begin waiting";
    advance.disabled = false;
    moveButton(0);
    window.scrollTo(0, 0);
  }

  function stopDemo() {
    if (!demoActive) return;
    demoActive = false;
    demoTimers.forEach((timer) => window.clearTimeout(timer));
    demoTimers = [];
    demoButton.textContent = "Run demo ▷";
  }

  function showForDemo(id) {
    byId(id).scrollIntoView({ block: "nearest", behavior: reducedMotion.matches ? "instant" : "smooth" });
  }

  function startDemo() {
    demoActive = true;
    demoButton.textContent = "Demo playing · tap to stop";
    function playLoop() {
      if (!demoActive) return;
      resetRoom();
      function schedule(time, action) {
        demoTimers.push(window.setTimeout(action, time));
      }

      schedule(1150, () => { showForDemo("terminal"); advance.click(); });
      schedule(2350, () => advance.click());
      schedule(3450, () => advance.click());
      schedule(5000, () => advance.click());
      schedule(7600, () => { showForDemo("cookie-card"); byId("dismiss-cookie").click(); });
      schedule(8850, () => { cookiePile.lastElementChild.lastElementChild.click(); showForDemo("cookie-pile"); });
      schedule(10300, () => { byId("close-desk").click(); showForDemo("close-card"); });
      schedule(11700, () => { closePile.lastElementChild.click(); showForDemo("close-pile"); });
      schedule(13100, () => { byId("align-button").click(); showForDemo("align-card"); });
      schedule(15100, () => { showForDemo("terminal"); advance.click(); });
      schedule(20000, () => {
        demoTimers = [];
        playLoop();
      });
    }
    playLoop();
  }

  function stopOnRealInput(event) {
    if (event.isTrusted && demoActive && !demoButton.contains(event.target)) stopDemo();
  }

  advance.addEventListener("click", advanceQueue);
  byId("dismiss-cookie").addEventListener("click", dismissCookie);
  byId("close-desk").addEventListener("click", requestClose);
  byId("align-button").addEventListener("click", fixAlignment);
  byId("restart").addEventListener("click", () => {
    resetRoom();
    advance.focus({ preventScroll: true });
  });
  demoButton.addEventListener("click", () => {
    if (demoActive) stopDemo();
    else startDemo();
  });

  document.addEventListener("pointerdown", stopOnRealInput, { capture: true, passive: true });
  document.addEventListener("touchstart", stopOnRealInput, { capture: true, passive: true });
  document.addEventListener("keydown", stopOnRealInput, true);
  if (location.hash === "#demo") startDemo();
</script>
</body>
</html>