Skip to content
VibeCodeBench
Back to the app

The code

Build-a-Box Bakery by Claude Sonnet 5.5

Exactly as the AI wrote it. Shown as text, so nothing runs on this page.

Try 1 · index.html

worksshown58.8 KB · 971 lines · no libraries
Download
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
<meta name="color-scheme" content="light">
<title>Pip &amp; Crumb Bakehouse</title>
<style>
:root{
  --bg:#fff6e6;--paper:#fffdf8;--ink:#40291f;--ink2:#6a4d3d;--terra:#d4623a;--terra-d:#b34a27;
  --butter:#f7d98b;--mint:#9cc9ad;--mint-d:#2f7a5e;--berry:#b8465c;--kraft:#d8a468;--line:#ecd8b8;
  --hand:"Segoe Print","Bradley Hand","Chalkboard SE","Comic Sans MS",cursive;
  --serif:Georgia,"Iowan Old Style","Palatino Linotype",serif;
  --sans:system-ui,-apple-system,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;
  --stickyH:0px;
}
*{box-sizing:border-box}
html{scroll-behavior:smooth;-webkit-text-size-adjust:100%}
body{margin:0;background:var(--bg);color:var(--ink);font-family:var(--sans);line-height:1.5;
  background-image:radial-gradient(rgba(212,98,58,.07) 1.5px,transparent 1.6px);background-size:22px 22px}
body.lock{overflow:hidden}
button{font:inherit;color:inherit;cursor:pointer;-webkit-tap-highlight-color:transparent;touch-action:manipulation}
button:disabled{cursor:not-allowed}
:focus-visible{outline:3px solid #1f6feb;outline-offset:2px}
svg{display:block}
.sr{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
.wrap{max-width:1120px;margin:0 auto;padding:0 16px}
section{padding:52px 0;scroll-margin-top:8px}
h1,h2,h3{font-family:var(--serif);line-height:1.1;margin:0}
h2{font-size:clamp(1.8rem,5.5vw,2.6rem)}
.eyebrow{font-family:var(--hand);color:var(--terra-d);font-size:1.05rem;margin:0 0 6px}
.lede{color:var(--ink2);max-width:46ch;margin:10px 0 0}

/* buttons */
.btn{min-height:48px;padding:0 22px;border-radius:999px;border:2.5px solid var(--ink);background:var(--paper);font-weight:700;
  display:inline-flex;align-items:center;justify-content:center;gap:8px;transition:transform .12s ease,background .2s;box-shadow:0 3px 0 var(--ink)}
.btn.primary{background:var(--terra-d);color:#fff}
.btn:active,.pressed{transform:translateY(2px) scale(.97);box-shadow:0 1px 0 var(--ink)}
.btn:disabled{opacity:.5;box-shadow:none;transform:none}

/* header */
.top{position:relative;z-index:20;background:rgba(255,246,230,.94);border-bottom:2px solid var(--line)}
.top .wrap{display:flex;align-items:center;gap:14px;min-height:64px}
.brand{display:flex;align-items:center;gap:10px;font-family:var(--hand);font-weight:700;font-size:1.2rem;white-space:nowrap}
.top nav{display:none;margin-left:auto;gap:4px}
.top nav button{background:none;border:0;min-height:44px;padding:0 14px;font-weight:600;border-radius:999px}
.top nav button:active{background:var(--line)}
.iconbtn{width:46px;height:46px;border-radius:50%;border:2.5px solid var(--ink);background:var(--paper);display:grid;place-items:center;margin-left:auto;flex:none}
.top nav + .iconbtn{margin-left:0}
@media(min-width:720px){.top nav{display:flex}}

/* badge */
.badge{display:inline-flex;align-items:center;gap:8px;padding:8px 14px;border-radius:999px;font-weight:700;font-size:.95rem;border:2px solid transparent}
.badge .dot{width:11px;height:11px;border-radius:50%;flex:none}
.badge.open{background:#e1f4e7;color:#175336;border-color:#9fd3b2}.badge.open .dot{background:#22a35a;animation:pulse 1.8s infinite}
.badge.closed{background:#fde5df;color:#85261a;border-color:#efb2a6}.badge.closed .dot{background:#d0452d}
@keyframes pulse{0%{box-shadow:0 0 0 0 rgba(34,163,90,.6)}70%{box-shadow:0 0 0 8px rgba(34,163,90,0)}100%{box-shadow:0 0 0 0 rgba(34,163,90,0)}}

/* hero */
.hero{padding:28px 0 40px}
.hero .wrap{display:grid;gap:26px;align-items:center}
.hero h1{font-size:clamp(2.6rem,10vw,4.8rem);letter-spacing:-.02em}
.hero h1 em{display:block;color:var(--terra-d);font-size:.52em;font-style:italic;letter-spacing:0;margin-top:6px}
.cta{display:flex;flex-wrap:wrap;gap:12px;align-items:center;margin-top:22px}
.hero-art svg{width:100%;height:auto;border-radius:28px;border:3px solid var(--ink);box-shadow:0 8px 0 var(--ink)}
.ink{fill:none;stroke:#40291f;stroke-width:3.2;stroke-linecap:round;stroke-linejoin:round}
.ink2{fill:none;stroke:#40291f;stroke-width:1.8;stroke-linecap:round;stroke-linejoin:round;opacity:.7}
.cloud{stroke:#40291f;stroke-width:2;stroke-linejoin:round;opacity:.9}
.hi{fill:none;stroke:#f5a583;stroke-width:3;stroke-linecap:round}
.hand{font-family:var(--hand);font-weight:700}
.steam{fill:none;stroke:#fff;stroke-width:5;stroke-linecap:round;opacity:.85;animation:steam 3.6s ease-in-out infinite}
.steam.s2{animation-delay:1.2s}.steam.s3{animation-delay:2.4s}
@keyframes steam{0%{transform:translateY(8px);opacity:0}30%{opacity:.9}100%{transform:translateY(-22px);opacity:0}}
.sway{transform-origin:429px 284px;animation:sway 4s ease-in-out infinite}
@keyframes sway{0%,100%{transform:rotate(-6deg)}50%{transform:rotate(6deg)}}
.drift{animation:drift 14s ease-in-out infinite alternate}
@keyframes drift{from{transform:translateX(-10px)}to{transform:translateX(18px)}}
@media(min-width:900px){.hero .wrap{grid-template-columns:1fr 1.1fr;gap:44px}}

/* chalkboard */
.board{background:#2d3a35;border:10px solid #b98650;border-radius:22px;padding:22px 16px 18px;color:#f6efe0;
  box-shadow:inset 0 0 40px rgba(0,0,0,.35),0 8px 0 rgba(64,41,31,.9)}
.board-head{display:flex;flex-wrap:wrap;gap:10px 18px;align-items:baseline;justify-content:space-between;margin-bottom:8px}
.board h2{font-family:var(--hand);font-weight:700;color:#fff6dc}
.board .date{color:#d9cfb6;font-size:.95rem}
.legend{font-size:.85rem;color:#d9cfb6;margin:0 0 14px}
.menu{list-style:none;margin:0;padding:0;display:grid;gap:4px 34px}
@media(min-width:760px){.menu{grid-template-columns:1fr 1fr}}
.dish{display:grid;grid-template-columns:56px 1fr auto;gap:12px;align-items:center;padding:12px 0;border-bottom:2px dashed rgba(246,239,224,.25);position:relative}
.dish .pic{width:56px;height:56px;border-radius:50%;background:#f6efe0;display:grid;place-items:center}
.dish .pic svg{width:44px;height:44px}
.dish h3{font-family:var(--hand);font-size:1.12rem;color:#fff6dc}
.dish p{margin:2px 0 6px;font-size:.88rem;color:#d9cfb6;line-height:1.35}
.dish .price{font-family:var(--hand);font-weight:700;font-size:1.15rem;color:#ffd978}
.tags{display:flex;flex-wrap:wrap;gap:5px}
.tag{font-size:.72rem;font-weight:700;border:1.5px solid currentColor;border-radius:999px;padding:1px 8px;line-height:1.4}
.board .tag{color:#bfe3cc}
.fresh{font-size:.72rem;font-weight:700;border-radius:999px;padding:2px 9px;background:#ffd978;color:#40291f;white-space:nowrap}
.fresh.later{background:transparent;color:#ffd978;border:1.5px solid #ffd978}
.pick{position:absolute;right:0;top:-4px;background:var(--berry);color:#fff;font-size:.7rem;font-weight:800;padding:2px 9px;border-radius:999px;transform:rotate(3deg)}
.pickrow{padding-top:18px}

/* configurator */
.sechead{margin-bottom:22px}
.cfg{display:grid;gap:14px;grid-template-areas:"controls" "box" "picker"}
.controls{grid-area:controls}
.picker{grid-area:picker}
.boxpanel{grid-area:box;background:linear-gradient(#f3e1bd,#ecd2a3);border:3px solid var(--ink);border-radius:24px;padding:12px;box-shadow:0 6px 0 var(--ink);position:sticky;top:0;z-index:6}
.card{background:var(--paper);border:2.5px solid var(--line);border-radius:22px;padding:14px}
.lab{font-weight:800;font-size:.85rem;text-transform:uppercase;letter-spacing:.06em;color:var(--ink2);margin:0 0 8px}
.seg{display:grid;grid-template-columns:repeat(3,1fr);gap:8px}
.seg button{min-height:56px;border-radius:16px;border:2.5px solid var(--line);background:#fff;display:flex;flex-direction:column;align-items:center;justify-content:center;line-height:1.15;padding:6px 4px;transition:transform .12s,background .2s}
.seg button b{font-family:var(--serif);font-size:1.5rem}
.seg button small{font-size:.72rem;color:var(--ink2)}
.seg button[aria-checked="true"]{background:var(--ink);border-color:var(--ink);color:#fff}
.seg button[aria-checked="true"] small{color:#f1dfc4}
.chips{display:flex;flex-wrap:wrap;gap:8px}
.chip{min-height:46px;padding:0 16px;border-radius:999px;border:2.5px solid var(--line);background:#fff;font-weight:700;display:inline-flex;align-items:center;gap:8px;transition:background .2s,transform .12s}
.chip::before{content:"";width:16px;height:16px;border-radius:50%;border:2.5px solid var(--ink2)}
.chip[aria-pressed="true"]{background:var(--mint-d);border-color:var(--mint-d);color:#fff}
.chip[aria-pressed="true"]::before{background:#fff;border-color:#fff;box-shadow:inset 0 0 0 3px var(--mint-d)}
.fnote{font-size:.85rem;color:var(--ink2);margin:8px 2px 0;min-height:1.3em}
.controls .card + .card{margin-top:12px}

.boxwrap{display:grid;place-items:center}
#boxsvg{width:100%;height:auto;max-height:min(52vh,460px);overflow:visible}
.boxwrap.shake{animation:shake .4s}
@keyframes shake{20%{transform:translateX(-7px)}40%{transform:translateX(6px)}60%{transform:translateX(-4px)}80%{transform:translateX(3px)}}
.well{fill:rgba(184,134,80,.16);stroke:#c79a62;stroke-width:2;stroke-dasharray:4 5}
.wnum{font-family:var(--serif);font-size:20px;fill:#b98650;opacity:.55;text-anchor:middle;dominant-baseline:central}
.slot{outline:none}
.slot:focus-visible .ring{stroke:#1f6feb;stroke-width:4}
.ring{fill:none;stroke:transparent}
.drop{will-change:transform}
.drop.pop{animation:pop .6s cubic-bezier(.3,1.4,.5,1) both}
.drop.out{animation:out .17s ease-in both}
@keyframes pop{0%{transform:translateY(-60px) scale(.3) rotate(-25deg);opacity:0}45%{transform:translateY(6px) scale(1.2);opacity:1}65%{transform:translateY(-6px) scale(.93)}82%{transform:translateY(2px) scale(1.04)}100%{transform:none;opacity:1}}
@keyframes out{to{transform:scale(.2) translateY(-24px);opacity:0}}
.boxfull #boxsvg{animation:hop .5s .2s}
@keyframes hop{30%{transform:translateY(-8px) rotate(-1deg)}60%{transform:translateY(0) rotate(1deg)}100%{transform:none}}

.hint{margin:8px 4px 8px;font-size:.88rem;font-weight:600;color:var(--ink2);min-height:1.3em;text-align:center}
.bar{display:flex;gap:8px;align-items:center}
.total{display:flex;flex-direction:column;line-height:1.1;min-width:74px}
.total small{font-size:.7rem;font-weight:800;text-transform:uppercase;letter-spacing:.06em;color:var(--ink2)}
.total b{font-family:var(--serif);font-size:1.6rem}
.total s{font-size:.78rem;color:var(--ink2)}
.bar .btn{padding:0 16px}
.bar .grow{flex:1}

.legend2{font-size:.82rem;color:var(--ink2);margin:0 2px 10px}
.grid{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:10px}
.tile{position:relative;min-height:128px;border-radius:18px;border:2.5px solid var(--line);background:var(--paper);padding:10px 4px 8px;display:flex;flex-direction:column;align-items:center;gap:2px;
  transition:transform .12s,opacity .25s,border-color .2s,background .2s}
.tile svg{width:62px;height:62px}
.tile .tn{font-weight:700;font-size:.8rem;line-height:1.2;text-align:center;min-height:2.4em;display:flex;align-items:center}
.tile .tp{font-size:.82rem;color:var(--ink2);font-weight:600}
.tile .tg{display:flex;gap:3px;min-height:18px}
.tile .tag{font-size:.62rem;padding:0 5px;color:var(--mint-d)}
.tile:active,.tile.pressed{transform:scale(.95)}
.tile.dim{opacity:.35;filter:grayscale(.55);background:#f1e8d8}
.tile .cnt{position:absolute;top:6px;right:6px;min-width:22px;height:22px;border-radius:11px;background:var(--terra-d);color:#fff;font-size:.78rem;font-weight:800;display:none;place-items:center;padding:0 5px}
.tile.has .cnt{display:grid}
.tile.has{border-color:var(--terra)}

@media(min-width:860px){
  .cfg{grid-template-columns:minmax(0,1fr) minmax(0,1fr);grid-template-areas:"box controls" "box picker";align-items:start;gap:18px 26px}
  .boxpanel{top:16px;padding:18px}
  .tile .tn{font-size:.88rem}
}
@media(max-width:859px){
  #boxsvg{max-height:30vh;max-height:30dvh}
  .boxpanel{box-shadow:0 8px 14px -6px rgba(64,41,31,.45);border-radius:0 0 22px 22px;margin:0 -6px;border-top:0}
}
@media(max-height:560px) and (max-width:859px){.boxpanel{position:static;border-radius:22px;margin:0;border-top:3px solid var(--ink)}#boxsvg{max-height:60vh}}

/* hours */
.two{display:grid;gap:18px}
@media(min-width:800px){.two{grid-template-columns:1.1fr 1fr}}
.bigcard{background:var(--paper);border:3px solid var(--ink);border-radius:24px;padding:22px;box-shadow:0 6px 0 var(--ink)}
.hrs{list-style:none;margin:16px 0 0;padding:0}
.hrs li{display:flex;justify-content:space-between;gap:12px;padding:10px 12px;border-radius:12px;font-weight:600}
.hrs li:nth-child(odd){background:#fbf0dc}
.hrs li[aria-current="date"]{background:var(--butter);outline:2px solid var(--ink)}
.hrs .off{color:#85261a}
.statusline{margin:12px 0 0;color:var(--ink2);font-size:.95rem}
.story p{margin:10px 0 0;color:var(--ink2)}
.story .sig{font-family:var(--hand);color:var(--terra-d);font-size:1.1rem}
.addr{margin-top:16px;padding-top:14px;border-top:2px dashed var(--line);font-size:.95rem}

/* footer */
footer{background:#3a2820;color:#f3e6cf;padding:34px 0 40px;margin-top:28px}
footer .wrap{display:grid;gap:18px}
footer h3{font-family:var(--hand);font-size:1.4rem;color:#fff2d4}
footer p{margin:4px 0;color:#d9c9ac;font-size:.92rem}
.fbtns{display:flex;flex-wrap:wrap;gap:10px}
footer .btn{background:transparent;color:#fff2d4;border-color:#fff2d4;box-shadow:none}
@media(min-width:760px){footer .wrap{grid-template-columns:1fr auto;align-items:end}}

/* drawer */
.scrim{position:fixed;inset:0;background:rgba(40,25,18,.55);opacity:0;visibility:hidden;transition:opacity .25s,visibility .25s;z-index:60}
.scrim.open{opacity:1;visibility:visible}
.drawer{position:fixed;z-index:61;background:var(--paper);display:flex;flex-direction:column;visibility:hidden;transition:transform .32s cubic-bezier(.2,.9,.3,1),visibility .32s;
  left:0;right:0;bottom:0;max-height:90vh;max-height:90dvh;border-radius:26px 26px 0 0;border:3px solid var(--ink);border-bottom:0;transform:translateY(105%)}
.drawer.open{visibility:visible;transform:none}
@media(min-width:760px){.drawer{left:auto;top:0;bottom:0;right:0;width:430px;max-height:none;border-radius:26px 0 0 26px;border-bottom:3px solid var(--ink);border-right:0;transform:translateX(105%)}}
.dhead{display:flex;align-items:center;justify-content:space-between;padding:14px 16px 10px;border-bottom:2px dashed var(--line)}
.dhead h2{font-size:1.5rem}
.dbody{overflow:auto;padding:14px 16px;overscroll-behavior:contain;flex:1}
.dfoot{padding:12px 16px calc(14px + env(safe-area-inset-bottom));border-top:2px dashed var(--line);display:flex;gap:10px}
.dfoot .btn{flex:1;padding:0 12px}
.mini{width:68%;max-width:240px;margin:0 auto 12px;height:auto}
.lines{list-style:none;margin:0;padding:0}
.lines li{display:grid;grid-template-columns:44px 1fr auto;gap:10px;align-items:center;padding:8px 0;border-bottom:1px solid var(--line)}
.lines svg{width:44px;height:44px}
.lines .q{color:var(--ink2);font-weight:700}
.sum{margin:12px 0 0}
.sum div{display:flex;justify-content:space-between;padding:3px 0}
.sum .gt{font-family:var(--serif);font-size:1.5rem;font-weight:700;border-top:2px solid var(--ink);margin-top:6px;padding-top:8px}
.sum .save{color:var(--mint-d);font-weight:700}
.note{background:#fff1cf;border:2px solid var(--butter);border-radius:14px;padding:10px 12px;font-size:.88rem;margin:12px 0 0;color:#5b3d12}
.empty{text-align:center;color:var(--ink2);padding:18px 0}

/* toast, demo */
.toast{position:fixed;left:50%;bottom:calc(18px + env(safe-area-inset-bottom));transform:translate(-50%,30px);background:var(--ink);color:#fff;padding:12px 18px;border-radius:16px;font-weight:600;font-size:.92rem;
  max-width:min(92vw,420px);text-align:center;opacity:0;visibility:hidden;transition:transform .25s,opacity .25s,visibility .25s;z-index:80;pointer-events:none}
.toast.show{opacity:1;visibility:visible;transform:translate(-50%,0)}
#dpointer{position:fixed;left:0;top:0;width:34px;height:34px;margin:-4px 0 0 -4px;z-index:200;pointer-events:none;display:none;
  transition:transform .65s cubic-bezier(.4,.1,.2,1);filter:drop-shadow(0 3px 3px rgba(0,0,0,.35))}
#dpointer.on{display:block}
#dpointer i{position:absolute;left:-10px;top:-10px;width:30px;height:30px;border-radius:50%;background:rgba(212,98,58,.45);transform:scale(0);opacity:0}
#dpointer.down i{animation:ripple .4s ease-out}
@keyframes ripple{0%{transform:scale(.2);opacity:.9}100%{transform:scale(1.8);opacity:0}}
#dbanner{position:fixed;left:50%;top:10px;transform:translateX(-50%);background:rgba(64,41,31,.92);color:#fff;font-size:.82rem;font-weight:700;padding:7px 14px;border-radius:999px;z-index:199;display:none;pointer-events:none;white-space:nowrap}
#dbanner.on{display:block}

/* quality + motion */
.lowfx .steam,.lowfx .sway,.lowfx .drift,.lowfx .badge .dot{animation:none}
.lowfx .tile.dim{filter:none}
.lowfx .boxpanel,.lowfx .btn,.lowfx .hero-art svg{box-shadow:none}
@media(prefers-reduced-motion:reduce){
  html{scroll-behavior:auto}
  .steam,.sway,.drift,.badge .dot{animation:none}
  .drop.pop{animation-duration:.2s}
}
</style>
</head>
<body>

<!-- Pastry symbols: one consistent style (top-down, flat fills, brown ink outline) -->
<svg width="0" height="0" style="position:absolute" aria-hidden="true" focusable="false">
<defs>
<symbol id="p-croissant" viewBox="0 0 100 100"><g stroke="#40291f" stroke-width="3" stroke-linejoin="round" stroke-linecap="round">
<ellipse cx="18" cy="68" rx="8" ry="11" transform="rotate(-50 18 68)" fill="#e0983f"/>
<ellipse cx="82" cy="68" rx="8" ry="11" transform="rotate(50 82 68)" fill="#e0983f"/>
<ellipse cx="29" cy="50" rx="12" ry="16" transform="rotate(-28 29 50)" fill="#e9a94f"/>
<ellipse cx="71" cy="50" rx="12" ry="16" transform="rotate(28 71 50)" fill="#e9a94f"/>
<ellipse cx="50" cy="40" rx="15" ry="21" fill="#f2bd62"/>
<path d="M43 26q7-5 14 0M41 38q9-4 18 0M42 50q8-3 16 0" fill="none" stroke="#fff0c4" stroke-width="2.5"/></g></symbol>

<symbol id="p-twist" viewBox="0 0 100 100"><g stroke="#40291f" stroke-width="3" stroke-linejoin="round" stroke-linecap="round" transform="rotate(-18 50 50)">
<rect x="9" y="32" width="82" height="36" rx="18" fill="#e6b060"/>
<path d="M28 33l9 34M45 33l9 34M62 33l9 34" fill="none" stroke="#b9772f"/>
<path d="M16 48q34-8 68 0" fill="none" stroke="#fff3d6" stroke-width="4" opacity=".85"/>
<ellipse cx="24" cy="44" rx="6" ry="3" transform="rotate(-25 24 44)" fill="#f8e6bc" stroke-width="2"/>
<ellipse cx="44" cy="40" rx="6" ry="3" transform="rotate(20 44 40)" fill="#f8e6bc" stroke-width="2"/>
<ellipse cx="62" cy="55" rx="6" ry="3" transform="rotate(-15 62 55)" fill="#f8e6bc" stroke-width="2"/>
<ellipse cx="78" cy="46" rx="6" ry="3" transform="rotate(30 78 46)" fill="#f8e6bc" stroke-width="2"/></g></symbol>

<symbol id="p-bun" viewBox="0 0 100 100"><g stroke="#40291f" stroke-width="3" stroke-linejoin="round" stroke-linecap="round">
<circle cx="50" cy="50" r="37" fill="#dd9a55"/>
<path d="M50 50c3-4 9-2 9 3 0 7-10 9-15 4-6-7-1-17 8-19 11-2 19 6 18 16-1 13-14 20-26 17-14-4-20-20-14-33" fill="none" stroke="#a45f2c" stroke-width="3.5"/>
<path d="M28 30q10-11 25-9 9 2 5 9-8 4-14 2-8 7-16-2z" fill="#fff3dc" stroke-width="2.5"/>
<path d="M62 60q10-6 16 2 3 8-6 11-8 2-12-3z" fill="#fff3dc" stroke-width="2.5"/></g></symbol>

<symbol id="p-muffin" viewBox="0 0 100 100"><g stroke="#40291f" stroke-width="3" stroke-linejoin="round" stroke-linecap="round">
<circle cx="50" cy="50" r="38" fill="#ecd3a2"/>
<circle cx="50" cy="50" r="34" fill="none" stroke="#b98d4f" stroke-dasharray="5 5.4"/>
<circle cx="50" cy="50" r="28" fill="#d99a52"/>
<path d="M30 40q6-10 18-12" fill="none" stroke="#f3c47e"/>
<circle cx="40" cy="46" r="5.5" fill="#4a58a6"/><circle cx="59" cy="40" r="5.5" fill="#4a58a6"/><circle cx="53" cy="60" r="5.5" fill="#4a58a6"/><circle cx="36" cy="61" r="5" fill="#4a58a6"/><circle cx="65" cy="57" r="5" fill="#4a58a6"/>
<g stroke="none" fill="#cdd5ff"><circle cx="38.5" cy="44.5" r="1.4"/><circle cx="57.5" cy="38.5" r="1.4"/><circle cx="51.5" cy="58.5" r="1.4"/></g>
<g stroke="none" fill="#fff3d6"><circle cx="48" cy="34" r="1.6"/><circle cx="68" cy="46" r="1.6"/><circle cx="46" cy="68" r="1.6"/><circle cx="30" cy="52" r="1.6"/></g></g></symbol>

<symbol id="p-tart" viewBox="0 0 100 100"><g stroke="#40291f" stroke-width="3" stroke-linejoin="round" stroke-linecap="round">
<circle cx="50" cy="50" r="38" fill="#e3b265"/>
<circle cx="50" cy="50" r="34" fill="none" stroke="#b98230" stroke-width="2.5" stroke-dasharray="4 4.5"/>
<circle cx="50" cy="50" r="27" fill="#f8de4f"/>
<path d="M32 42q6-10 17-11" fill="none" stroke="#fff6a8" stroke-width="3.5"/>
<circle cx="42" cy="58" r="6.5" fill="#fff6e4"/><circle cx="60" cy="52" r="6.5" fill="#fff6e4"/><circle cx="52" cy="42" r="5.5" fill="#fff6e4"/>
<g stroke="none" fill="#e1a24a"><circle cx="42" cy="54.5" r="1.8"/><circle cx="60" cy="48.5" r="1.8"/><circle cx="52" cy="39" r="1.6"/></g></g></symbol>

<symbol id="p-brownie" viewBox="0 0 100 100"><g stroke="#40291f" stroke-width="3" stroke-linejoin="round" stroke-linecap="round" transform="rotate(8 50 50)">
<rect x="14" y="14" width="72" height="72" rx="10" fill="#6a3d2c"/>
<path d="M22 36l14 6 8-11M60 22l-4 14 14 8M30 68l12-6 6 14M64 64l10 6" fill="none" stroke="#9b6148"/>
<rect x="24" y="22" width="11" height="11" rx="2" fill="#3f2118" stroke-width="2.5"/>
<rect x="60" y="60" width="11" height="11" rx="2" fill="#3f2118" stroke-width="2.5"/>
<rect x="52" y="44" width="9" height="9" rx="2" fill="#3f2118" stroke-width="2.5"/>
<g stroke="none" fill="#fff3e2"><circle cx="40" cy="52" r="1.8"/><circle cx="72" cy="34" r="1.8"/><circle cx="30" cy="60" r="1.6"/><circle cx="48" cy="72" r="1.8"/><circle cx="68" cy="48" r="1.5"/></g></g></symbol>

<symbol id="p-cookie" viewBox="0 0 100 100"><g stroke="#40291f" stroke-width="3" stroke-linejoin="round" stroke-linecap="round">
<path d="M50 13c10-1 16 5 24 9 8 4 13 13 12 23 0 9 4 14-2 23-6 9-15 10-23 13-9 3-17-1-25-5-10-5-15-13-15-23 0-10 4-17 11-24 6-6 11-14 18-16z" fill="#d9a45f"/>
<ellipse cx="38" cy="38" rx="5" ry="3.2" transform="rotate(-30 38 38)" fill="#6b3a56" stroke-width="2"/>
<ellipse cx="62" cy="34" rx="5" ry="3.2" transform="rotate(25 62 34)" fill="#6b3a56" stroke-width="2"/>
<ellipse cx="54" cy="56" rx="5" ry="3.2" transform="rotate(-10 54 56)" fill="#6b3a56" stroke-width="2"/>
<ellipse cx="32" cy="62" rx="5" ry="3.2" transform="rotate(40 32 62)" fill="#6b3a56" stroke-width="2"/>
<ellipse cx="72" cy="58" rx="5" ry="3.2" transform="rotate(-35 72 58)" fill="#6b3a56" stroke-width="2"/>
<g stroke="none" fill="#f6e2aa"><ellipse cx="48" cy="26" rx="3" ry="1.6"/><ellipse cx="70" cy="46" rx="3" ry="1.6"/><ellipse cx="42" cy="48" rx="3" ry="1.6"/><ellipse cx="60" cy="70" rx="3" ry="1.6"/><ellipse cx="28" cy="48" rx="3" ry="1.6"/></g></g></symbol>

<symbol id="p-financier" viewBox="0 0 100 100"><g stroke="#40291f" stroke-width="3" stroke-linejoin="round" stroke-linecap="round" transform="rotate(-8 50 50)">
<rect x="13" y="27" width="74" height="46" rx="9" fill="#d6a94f"/>
<rect x="20" y="34" width="60" height="32" rx="5" fill="#e6c36c" stroke-width="2"/>
<rect x="28" y="40" width="9" height="5" rx="1.5" transform="rotate(-20 32 42)" fill="#8fbc5a" stroke-width="2"/>
<rect x="46" y="38" width="9" height="5" rx="1.5" transform="rotate(25 50 40)" fill="#8fbc5a" stroke-width="2"/>
<rect x="60" y="50" width="9" height="5" rx="1.5" transform="rotate(-15 64 52)" fill="#8fbc5a" stroke-width="2"/>
<rect x="36" y="53" width="9" height="5" rx="1.5" transform="rotate(10 40 55)" fill="#8fbc5a" stroke-width="2"/>
<g stroke="none" fill="#6f9b3f"><circle cx="70" cy="42" r="2"/><circle cx="52" cy="58" r="2"/><circle cx="26" cy="54" r="2"/></g></g></symbol>

<symbol id="p-macaroon" viewBox="0 0 100 100"><g stroke="#40291f" stroke-width="3" stroke-linejoin="round" stroke-linecap="round">
<circle cx="50" cy="50" r="34" fill="#f4e7c8"/>
<path d="M36 34q6-5 11 2M56 30q8 0 9 7M30 52q4-8 11-4M62 50q7-3 10 4M42 66q6 3 12-1M48 48q5-3 8 2" fill="none" stroke="#d3bb82" stroke-width="2.5"/>
<g stroke="none" fill="#cf9448"><circle cx="40" cy="30" r="3.2"/><circle cx="66" cy="42" r="3"/><circle cx="34" cy="60" r="3"/><circle cx="58" cy="68" r="3.2"/><circle cx="52" cy="38" r="2.6"/></g></g></symbol>
</defs>
</svg>

<header class="top">
  <div class="wrap">
    <div class="brand">
      <svg viewBox="0 0 100 100" width="38" height="38" aria-hidden="true"><circle cx="50" cy="50" r="47" fill="#f7d98b" stroke="#40291f" stroke-width="4"/><use href="#p-croissant" x="10" y="12" width="80" height="80"/></svg>
      Pip &amp; Crumb
    </div>
    <nav aria-label="Sections">
      <button type="button" data-scroll="#bakes">Today's bakes</button>
      <button type="button" data-scroll="#box">Build a box</button>
      <button type="button" data-scroll="#hours">Hours</button>
    </nav>
    <button type="button" class="iconbtn" id="mute" aria-pressed="false" aria-label="Sound on. Tap to mute" title="Sound">
      <svg id="muteIco" viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="#40291f" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"></svg>
    </button>
  </div>
</header>

<main>
<section class="hero" id="top">
  <div class="wrap">
    <div>
      <p class="eyebrow">Neighbourhood bakehouse, since 2016</p>
      <h1>Pip &amp; Crumb <em>Bakehouse</em></h1>
      <p class="lede">Odile and her nephew Tomas lit the ovens in a tired old cobbler's shop on Larkspur Lane. Her sourdough starter, Winifred, still does the heavy lifting. Come early. The croissants never hang around.</p>
      <div class="cta">
        <button type="button" class="btn primary" data-scroll="#box">Build your box</button>
        <span class="badge" data-badge role="status"></span>
      </div>
    </div>
    <div class="hero-art" id="heroArt"></div>
  </div>
</section>

<section id="bakes">
  <div class="wrap">
    <div class="board">
      <div class="board-head">
        <h2>Today's bakes</h2>
        <span class="date" id="today"></span>
      </div>
      <p class="legend">V = vegan &middot; NF = nut-free &middot; GF = gluten-free. Everything is baked on site, all through the morning.</p>
      <ul class="menu" id="menu"></ul>
    </div>
  </div>
</section>

<section id="box">
  <div class="wrap">
    <div class="sechead">
      <p class="eyebrow">The fun part</p>
      <h2>Build your box</h2>
      <p class="lede">Pick a size, then tap pastries to drop them in. Tap one in the box to take it back out. Fill the box and we take a little off.</p>
    </div>
    <div class="cfg">
      <div class="controls">
        <div class="card">
          <p class="lab" id="sizeLab">1. Box size</p>
          <div class="seg" role="radiogroup" aria-labelledby="sizeLab" id="seg">
            <button type="button" role="radio" aria-checked="false" data-size="4"><b>4</b><small>Petite</small></button>
            <button type="button" role="radio" aria-checked="true" data-size="6"><b>6</b><small>5% off when full</small></button>
            <button type="button" role="radio" aria-checked="false" data-size="12"><b>12</b><small>10% off when full</small></button>
          </div>
        </div>
        <div class="card">
          <p class="lab" id="dietLab">Dietary filters</p>
          <div class="chips" role="group" aria-labelledby="dietLab">
            <button type="button" class="chip" aria-pressed="false" data-f="v">Vegan</button>
            <button type="button" class="chip" aria-pressed="false" data-f="n">Nut-free</button>
            <button type="button" class="chip" aria-pressed="false" data-f="g">Gluten-free</button>
          </div>
          <p class="fnote" id="fnote" aria-live="polite">Pastries that don't match will dim.</p>
        </div>
      </div>

      <div class="boxpanel" id="boxpanel">
        <div class="boxwrap" id="boxwrap"></div>
        <p class="hint" id="hint" aria-live="polite"></p>
        <div class="bar">
          <div class="total"><small>Total</small><b id="total">$0.00</b><s id="was" hidden></s></div>
          <button type="button" class="btn" id="reset">Reset</button>
          <button type="button" class="btn primary grow" id="checkout" disabled>Checkout</button>
        </div>
      </div>

      <div class="picker">
        <p class="lab">2. Tap to add</p>
        <p class="legend2">V vegan &middot; NF nut-free &middot; GF gluten-free</p>
        <div class="grid" id="grid"></div>
      </div>
    </div>
  </div>
</section>

<section id="hours">
  <div class="wrap two">
    <div class="bigcard">
      <p class="eyebrow">Come say hello</p>
      <h2>Opening hours</h2>
      <p class="statusline"><span class="badge" data-badge></span></p>
      <p class="statusline" id="statusText"></p>
      <ul class="hrs" id="hrs"></ul>
    </div>
    <div class="bigcard story">
      <p class="eyebrow">Our story</p>
      <h2>Flour, patience &amp; a very old starter</h2>
      <p>Pip &amp; Crumb began in 2016 with one second-hand oven, a wobbly table and a jar of sourdough starter Odile inherited from her grandmother. She named it Winifred, because it is bossy and always right.</p>
      <p>Tomas joined to run the pastry side, and the shop has been warm, floury and slightly too small ever since. We bake in small batches, we use real butter, and we always keep a few vegan and gluten-free things on the board.</p>
      <p class="sig">Odile &amp; Tomas</p>
      <div class="addr"><b>14 Larkspur Lane</b>, Little Fennel<br>Ring us on (555) 0142. This is an invented bakery, so no real orders are taken here.</div>
    </div>
  </div>
</section>
</main>

<footer>
  <div class="wrap">
    <div>
      <h3>Pip &amp; Crumb Bakehouse</h3>
      <p>14 Larkspur Lane, Little Fennel &middot; (555) 0142</p>
      <p>Baked with butter, patience and a little stubbornness. A made-up bakery for a demo page.</p>
    </div>
    <div class="fbtns">
      <button type="button" class="btn" id="startOver">Start over</button>
      <button type="button" class="btn" data-scroll="#top">Back to top</button>
    </div>
  </div>
</footer>

<div class="scrim" id="scrim"></div>
<aside class="drawer" id="drawer" role="dialog" aria-modal="true" aria-labelledby="dTitle" aria-hidden="true">
  <div class="dhead">
    <h2 id="dTitle">Order summary</h2>
    <button type="button" class="iconbtn" id="dClose" aria-label="Close order summary" style="margin-left:0">
      <svg viewBox="0 0 24 24" width="22" height="22" fill="none" stroke="#40291f" stroke-width="2.6" stroke-linecap="round" aria-hidden="true"><path d="M5 5l14 14M19 5L5 19"/></svg>
    </button>
  </div>
  <div class="dbody" id="dBody"></div>
  <div class="dfoot">
    <button type="button" class="btn" id="dBack">Keep building</button>
    <button type="button" class="btn primary" id="dDone">Done</button>
  </div>
</aside>

<div class="toast" id="toast" role="status" aria-live="polite"></div>
<div id="dbanner">Demo running. Touch or click anywhere to take over.</div>
<div id="dpointer" aria-hidden="true"><i></i>
  <svg viewBox="0 0 34 34" width="34" height="34"><path d="M5 3l0 22 6-5 4 9 5-2-4-9 8 0z" fill="#fff" stroke="#40291f" stroke-width="2.4" stroke-linejoin="round"/></svg>
</div>

<script>
(function(){
'use strict';
var $=function(s,r){return (r||document).querySelector(s)};
var $$=function(s,r){return Array.prototype.slice.call((r||document).querySelectorAll(s))};

/* ---------- seeded randomness ---------- */
function mulberry32(a){return function(){a|=0;a=a+0x6D2B79F5|0;var t=Math.imul(a^a>>>15,1|a);t=t+Math.imul(t^t>>>7,61|t)^t;return((t^t>>>14)>>>0)/4294967296}}
var rnd=mulberry32(20260930);
var TILT=[];for(var ti=0;ti<12;ti++)TILT.push(Math.round((rnd()-.5)*26));

/* ---------- data ---------- */
var P=[
 {id:'croissant',name:'Butter Croissant',price:3.5,v:0,n:1,g:0,t:390,desc:'Three days of folding. Shatteringly crisp.'},
 {id:'twist',name:'Almond Twist',price:4.25,v:0,n:0,g:0,t:420,desc:'Twisted pastry, almond cream, toasted flakes.'},
 {id:'bun',name:'Cinnamon Swirl Bun',price:3.75,v:1,n:1,g:0,t:450,desc:'Soft, sticky, plant-based and very swirly.'},
 {id:'muffin',name:'Blueberry Muffin',price:3.25,v:0,n:1,g:0,t:480,desc:'Tall, tender and heavy with berries.'},
 {id:'tart',name:'Lemon Meringue Tart',price:4.0,v:0,n:1,g:1,t:540,desc:'Rice-flour shell, sharp curd, torched peaks.'},
 {id:'brownie',name:'Fudge Brownie',price:3.5,v:0,n:1,g:1,t:510,desc:'Flourless, dark and gloriously gooey.'},
 {id:'cookie',name:'Oat &amp; Raisin Cookie',price:2.75,v:1,n:1,g:0,t:600,desc:'Chewy middle, crisp edge, no butter at all.'},
 {id:'financier',name:'Pistachio Financier',price:4.5,v:0,n:0,g:1,t:570,desc:'Brown-butter almond-free? Never. Nutty and golden.'},
 {id:'macaroon',name:'Coconut Macaroon',price:2.95,v:1,n:1,g:1,t:660,desc:'Toasted coconut mound. Free of just about everything.'}
];
P[7].desc='Brown-butter cake with crushed pistachio. Nutty and golden.';
var BY={};P.forEach(function(p){BY[p.id]=p});
var RATE={4:0,6:.05,12:.10};
var FN={v:'vegan',n:'nut-free',g:'gluten-free'};
var HRS=[[8,14],[null,null],[7,17],[7,17],[7,17],[7,18],[7,16]];
var DAYS=['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
var MONTHS=['January','February','March','April','May','June','July','August','September','October','November','December'];

function money(n){return '$'+(Math.round(n*100)/100).toFixed(2)}
function plain(s){return s.replace(/&amp;/g,'&')}
function ico(id,cls){return '<svg viewBox="0 0 100 100" aria-hidden="true" focusable="false"'+(cls?' class="'+cls+'"':'')+'><use href="#p-'+id+'" width="100" height="100"/></svg>'}
function tagsHTML(p){var s='';if(p.v)s+='<span class="tag" title="Vegan">V</span>';if(p.n)s+='<span class="tag" title="Nut-free">NF</span>';if(p.g)s+='<span class="tag" title="Gluten-free">GF</span>';return s}

/* ---------- state ---------- */
var state={size:6,slots:[],filters:{v:false,n:false,g:false}};
for(var si=0;si<12;si++)state.slots.push(null);
function match(p){var f=state.filters;return (!f.v||p.v)&&(!f.n||p.n)&&(!f.g||p.g)}
function items(){return state.slots.slice(0,state.size).filter(Boolean)}

/* ---------- audio (starts only after a tap) ---------- */
var actx=null,master=null,muted=false;
try{muted=localStorage.getItem('pc-mute')==='1'}catch(e){}
function initAudio(){
  if(actx){if(actx.state==='suspended'){try{actx.resume()}catch(e){}}return}
  try{var AC=window.AudioContext||window.webkitAudioContext;if(!AC)return;actx=new AC();master=actx.createGain();master.gain.value=.5;master.connect(actx.destination)}catch(e){actx=null}
}
function tone(f1,f2,dur,type,vol,delay){
  if(!actx||muted)return;
  try{
    var t=actx.currentTime+(delay||0),o=actx.createOscillator(),g=actx.createGain();
    o.type=type||'sine';o.frequency.setValueAtTime(f1,t);o.frequency.exponentialRampToValueAtTime(Math.max(30,f2),t+dur);
    g.gain.setValueAtTime(.0001,t);g.gain.exponentialRampToValueAtTime(vol||.2,t+.012);g.gain.exponentialRampToValueAtTime(.0001,t+dur);
    o.connect(g);g.connect(master);o.start(t);o.stop(t+dur+.03);
  }catch(e){}
}
var sfx={
  add:function(){tone(420,780,.14,'sine',.28);tone(900,1180,.09,'triangle',.08,.05)},
  remove:function(){tone(520,230,.17,'triangle',.22)},
  full:function(){[523,659,784,1047].forEach(function(f,i){tone(f,f*1.01,.2,'sine',.2,i*.08)})},
  no:function(){tone(210,150,.16,'square',.08)},
  open:function(){tone(587,880,.22,'sine',.2);tone(880,1175,.2,'sine',.12,.1)},
  tick:function(){tone(700,600,.06,'triangle',.12)}
};
var ON='<path d="M4 9v6h4l5 4V5L8 9H4z"/><path d="M16.5 8.5a5 5 0 010 7M19 6a8.5 8.5 0 010 12"/>';
var OFF='<path d="M4 9v6h4l5 4V5L8 9H4z"/><path d="M17 9l5 6M22 9l-5 6"/>';
function paintMute(){
  var b=$('#mute');$('#muteIco').innerHTML=muted?OFF:ON;
  b.setAttribute('aria-pressed',muted?'true':'false');
  b.setAttribute('aria-label',muted?'Sound off. Tap to unmute':'Sound on. Tap to mute');
}
$('#mute').addEventListener('click',function(){
  muted=!muted;try{localStorage.setItem('pc-mute',muted?'1':'0')}catch(e){}
  paintMute();if(!muted){initAudio();sfx.tick()}
});
paintMute();

/* ---------- toast ---------- */
var toastT=0;
function toast(msg,ms){var t=$('#toast');t.textContent=msg;t.classList.add('show');clearTimeout(toastT);toastT=setTimeout(function(){t.classList.remove('show')},ms||2400)}

/* ---------- hand-drawn hero ---------- */
function f1(n){return Math.round(n*10)/10}
function J(a){return (rnd()-.5)*a}
function hl(x1,y1,x2,y2,w){w=w||2.2;var mx=(x1+x2)/2+J(w*2),my=(y1+y2)/2+J(w*2);
  return 'M'+f1(x1+J(w))+' '+f1(y1+J(w))+'Q'+f1(mx)+' '+f1(my)+' '+f1(x2+J(w))+' '+f1(y2+J(w))}
function hrect(x,y,w,h,fill){
  var a=function(){return J(3)},p='';
  if(fill)p='<path d="M'+f1(x+a()+1)+' '+f1(y+a()+1)+'L'+f1(x+w+a())+' '+f1(y+a()+2)+'L'+f1(x+w+a()-1)+' '+f1(y+h+a())+'L'+f1(x+a())+' '+f1(y+h+a()-1)+'Z" fill="'+fill+'"/>';
  return p+'<path class="ink" d="'+hl(x,y,x+w,y)+hl(x+w,y,x+w,y+h)+hl(x+w,y+h,x,y+h)+hl(x,y+h,x,y)+'"/>';
}
function heroSVG(){
  var o=[],i,d;
  o.push('<rect width="640" height="460" fill="#cfe8e8"/>');
  o.push('<circle cx="540" cy="74" r="32" fill="#ffd978"/><circle cx="540" cy="74" r="32" class="ink2"/>');
  d='';for(i=0;i<12;i++){var a=i/12*6.283+.1;d+=hl(540+Math.cos(a)*42,74+Math.sin(a)*42,540+Math.cos(a)*56,74+Math.sin(a)*56,2)}
  o.push('<path class="ink2" d="'+d+'"/>');
  o.push('<g class="drift"><path class="cloud" fill="#fffaf0" d="M44 128C20 128 18 100 42 98C40 76 70 70 82 86C92 66 126 70 130 92C154 92 160 126 136 128Z"/>'+
         '<g transform="translate(290 -34) scale(.7)"><path class="cloud" fill="#fffaf0" d="M44 128C20 128 18 100 42 98C40 76 70 70 82 86C92 66 126 70 130 92C154 92 160 126 136 128Z"/></g></g>');
  o.push('<path class="ink2" d="M250 66q8-8 14 0q6-8 14 0M300 90q6-6 11 0q5-6 11 0"/>');
  /* sidewalk */
  o.push('<path d="M0 402L640 402 640 460 0 460Z" fill="#e8d2ae"/><path class="ink" d="'+hl(0,402,640,402,3)+'"/>');
  d='';for(i=0;i<14;i++){d+=hl(10+i*47+J(10),424+(i%2)*14,38+i*47+J(10),424+(i%2)*14,1.5)}
  o.push('<path class="ink2" d="'+d+'"/>');
  /* building */
  o.push(hrect(92,150,456,254,'#f8dfb8'));
  o.push(hrect(92,346,456,58,'#cf7a52'));
  d='';for(i=1;i<4;i++){d+=hl(92,346+i*14.5,548,346+i*14.5,1.2)}
  for(var r=0;r<4;r++){for(var x=92+(r%2)*19;x<548;x+=38){d+=hl(x,346+r*14.5,x,360+r*14.5,1)}}
  o.push('<path class="ink2" d="'+d+'"/>');
  o.push(hrect(78,112,484,40,'#d4623a'));
  o.push('<path class="hi" d="'+hl(88,124,552,124,2)+'"/>');
  o.push(hrect(470,58,44,56,'#b25a3a')+hrect(464,48,56,12,'#8e4329'));
  o.push('<path class="ink2" d="'+hl(470,80,514,80,1)+hl(470,98,514,98,1)+hl(492,60,492,80,1)+hl(480,80,480,98,1)+'"/>');
  o.push('<g><path class="steam s1" d="M492 40q-12-12 0-24t0-20"/><path class="steam s2" d="M500 40q10-12 0-24t2-20"/><path class="steam s3" d="M486 40q-8-10 0-20t0-18"/></g>');
  /* sign */
  o.push(hrect(170,160,300,44,'#40291f'));
  o.push('<text x="320" y="192" text-anchor="middle" class="hand" font-size="26" fill="#ffe9bd" textLength="236" lengthAdjust="spacingAndGlyphs">Pip &amp; Crumb</text>');
  o.push('<circle cx="186" cy="182" r="4" fill="#ffe9bd"/><circle cx="454" cy="182" r="4" fill="#ffe9bd"/>');
  /* window */
  o.push(hrect(110,262,248,88,'#8e5a3a'));
  o.push(hrect(120,272,228,68,'#d8eef0'));
  o.push('<path class="ink" d="'+hl(234,272,234,340,1.5)+'"/>');
  var xs=[128,170,244,276,310];
  var wi=['croissant','bun','tart','brownie','cookie'];
  for(i=0;i<5;i++)o.push('<use href="#p-'+wi[i]+'" x="'+xs[i]+'" y="288" width="36" height="36"/>');
  o.push(hrect(120,326,228,10,'#b98650'));
  o.push('<path d="M140 274l30 0-34 64-24 0z" fill="#fff" opacity=".35"/><path d="M262 274l16 0-34 64-16 0z" fill="#fff" opacity=".3"/>');
  /* awning */
  var aw='',ol='',n=10,b0,b1,t0,t1;
  for(i=0;i<n;i++){t0=112+i*41.6;t1=t0+41.6;b0=100+i*44;b1=b0+44;
    aw+='<path d="M'+f1(t0)+' 214L'+f1(t1)+' 214L'+f1(b1)+' 250Q'+f1((b0+b1)/2)+' 270 '+f1(b0)+' 250Z" fill="'+(i%2?'#fff3dc':'#d4623a')+'"/>';
    ol+='M'+f1(b0+J(2))+' 250Q'+f1((b0+b1)/2+J(2))+' '+f1(270+J(3))+' '+f1(b1+J(2))+' 250';
    ol+=hl(112+i*41.6,214,100+i*44,250,1.5);
  }
  ol+=hl(112+n*41.6,214,100+n*44,250,1.5);
  o.push('<g>'+aw+'<path class="ink" d="'+ol+'"/></g>');
  o.push(hrect(104,206,432,12,'#8e4329'));
  /* door */
  o.push(hrect(380,262,98,142,'#40291f'));
  o.push(hrect(386,268,86,136,'#6fae98'));
  o.push(hrect(398,280,62,56,'#d8eef0'));
  o.push(hrect(398,352,62,38,'#5a977f'));
  o.push('<circle cx="458" cy="350" r="4.5" fill="#f7d98b" stroke="#40291f" stroke-width="2"/>');
  o.push('<g class="sway"><path class="ink" d="M429 284l0 10"/>'+hrect(409,294,40,24,'#fff3dc')+'<text x="429" y="311" text-anchor="middle" class="hand" font-size="13" fill="#b34a27">OPEN</text></g>');
  o.push(hrect(372,404,114,10,'#d9c3a0'));
  /* cat */
  o.push('<g><path class="ink" fill="#f0a24e" d="M336 398q-16-2-10-20"/><ellipse cx="352" cy="392" rx="17" ry="12" fill="#f0a24e" class="ink"/><circle cx="368" cy="380" r="9.5" fill="#f0a24e" class="ink"/>'+
         '<path class="ink" fill="#f0a24e" d="M361 373l-1-9 7 5M372 371l4-8 2 10"/><path class="ink2" d="M346 384l2 6M354 383l1 7"/><circle cx="365" cy="379" r="1.3" fill="#40291f"/><circle cx="371" cy="379" r="1.3" fill="#40291f"/></g>');
  /* A-board */
  o.push('<path class="ink" d="M34 410L48 350M86 410L72 350"/>'+hrect(44,352,32,44,'#2d3a35')+'<use href="#p-croissant" x="46" y="358" width="28" height="28"/><path class="ink2" d="M50 392l20 0" stroke="#fff"/>');
  /* planter */
  o.push('<path d="M504 404L510 380L534 380L540 404Z" fill="#cf7a52"/><path class="ink" d="M504 404L510 380L534 380L540 404Z"/>');
  var fc=['#d4623a','#b8465c','#f7d98b','#fff3dc','#d4623a'];
  for(i=0;i<5;i++){var fx=508+i*7+J(2),fy=360+J(10)-(i%2)*6;o.push('<path class="ink2" d="M'+f1(fx)+' 380L'+f1(fx)+' '+f1(fy+5)+'"/><circle cx="'+f1(fx)+'" cy="'+f1(fy)+'" r="'+f1(5+rnd()*2)+'" fill="'+fc[i]+'" stroke="#40291f" stroke-width="2"/>')}
  /* bike */
  o.push('<g><circle cx="574" cy="384" r="20" class="ink"/><circle cx="620" cy="384" r="20" class="ink"/>'+
         '<path class="ink" d="M574 384L588 358L612 358L620 384M588 358L598 384L574 384M598 384L612 358M586 350l12 0M612 358l-3-10l10 0"/>'+
         '<path class="ink" fill="#fff3dc" d="M624 352l12 0-2 14-8 0z"/><path class="ink" stroke="#c9843f" d="M628 352l6-12"/></g>');
  return '<svg viewBox="0 0 640 460" role="img" aria-label="Hand-drawn illustration of the Pip and Crumb bakery shop front, with a striped awning, a window full of pastries, a cat by the door and a bicycle with a baguette">'+o.join('')+'</svg>';
}
$('#heroArt').innerHTML=heroSVG();

/* ---------- opening hours ---------- */
function fmt(h){var hh=Math.floor(h),m=Math.round((h-hh)*60);return ((hh%12)||12)+(m?':'+('0'+m).slice(-2):'')+' '+(hh>=12?'pm':'am')}
function status(d){
  d=d||new Date();var day=d.getDay(),mins=d.getHours()+d.getMinutes()/60,t=HRS[day];
  if(t[0]!=null&&mins>=t[0]&&mins<t[1]){
    var left=(t[1]-mins)*60,soon=left<=30;
    return {open:true,text:'Open now. '+(soon?'Closing soon, at ':'Closes at ')+fmt(t[1])+'.'};
  }
  var k=(t[0]!=null&&mins<t[0])?0:1;
  for(;k<=7;k++){var dd=(day+k)%7;if(HRS[dd][0]!=null){
    return {open:false,text:'Closed right now. Opens '+(k===0?'today':k===1?'tomorrow':DAYS[dd])+' at '+fmt(HRS[dd][0])+'.'};}}
  return {open:false,text:'Closed right now.'};
}
function buildHours(){
  var order=[1,2,3,4,5,6,0],h='';
  order.forEach(function(d){var t=HRS[d];h+='<li data-day="'+d+'"><span>'+DAYS[d]+'</span><span'+(t[0]==null?' class="off"':'')+'>'+(t[0]==null?'Closed':fmt(t[0])+' to '+fmt(t[1]))+'</span></li>'});
  $('#hrs').innerHTML=h;
}
function updateHours(){
  var now=new Date(),s=status(now);
  $$('[data-badge]').forEach(function(b){
    b.className='badge '+(s.open?'open':'closed');
    b.innerHTML='<span class="dot"></span>'+(s.open?'Open':'Closed');
    b.setAttribute('aria-label',s.text);
  });
  $('#statusText').textContent=s.text;
  $$('#hrs li').forEach(function(li){if(+li.dataset.day===now.getDay())li.setAttribute('aria-current','date');else li.removeAttribute('aria-current')});
  $('#today').textContent=DAYS[now.getDay()]+' '+now.getDate()+' '+MONTHS[now.getMonth()];
  updateMenuStatus(now,s);
}

/* ---------- chalkboard menu ---------- */
function buildMenu(){
  var pickIdx=new Date().getDay()%P.length,h='';
  P.forEach(function(p,i){
    h+='<li class="dish'+(i===pickIdx?' pickrow':'')+'" data-id="'+p.id+'">'+(i===pickIdx?'<span class="pick">Baker\'s pick</span>':'')+
      '<div class="pic">'+ico(p.id)+'</div><div><h3>'+p.name+'</h3><p>'+p.desc+'</p><div class="tags">'+tagsHTML(p)+'<span class="fresh" data-fresh></span></div></div>'+
      '<div class="price">'+money(p.price)+'</div></li>';
  });
  $('#menu').innerHTML=h;
}
function updateMenuStatus(now,s){
  var mins=now.getHours()*60+now.getMinutes();
  $$('#menu .dish').forEach(function(li){
    var p=BY[li.dataset.id],el=$('[data-fresh]',li);
    if(!s.open&&mins>=p.t&&HRS[now.getDay()][0]==null){el.textContent='Back tomorrow';el.className='fresh later'}
    else if(mins>=p.t&&s.open){el.textContent='Fresh now';el.className='fresh'}
    else if(mins>=p.t){el.textContent='Baked today';el.className='fresh later'}
    else{el.textContent='Out at '+fmt(p.t/60);el.className='fresh later'}
  });
}

/* ---------- box rendering ---------- */
var LAYOUT={4:[2,2],6:[3,2],12:[4,3]};
var CELL=88,PAD=22,TOP=34;
function pieceMarkup(id,i,pop){
  return '<g class="drop'+(pop?' pop':'')+'"><g transform="rotate('+TILT[i]+')"><ellipse cx="3" cy="7" rx="31" ry="27" fill="rgba(80,40,10,.18)"/><use href="#p-'+id+'" x="-37" y="-37" width="74" height="74"/></g></g>';
}
function slotLabel(i){var id=state.slots[i];return id?'Slot '+(i+1)+': '+plain(BY[id].name)+'. Tap to remove.':'Slot '+(i+1)+': empty'}
function boxSVG(interactive){
  var c=LAYOUT[state.size][0],r=LAYOUT[state.size][1],W=c*CELL+PAD*2,H=r*CELL+PAD+TOP,s='',i;
  s+='<svg '+(interactive?'id="boxsvg" ':'class="mini" ')+'viewBox="0 0 '+W+' '+H+'" role="'+(interactive?'group':'img')+'" aria-label="Your '+state.size+' pastry box">';
  s+='<rect x="2" y="2" width="'+(W-4)+'" height="'+(H-4)+'" rx="16" fill="#d8a468" stroke="#40291f" stroke-width="3"/>';
  s+='<path d="M2 '+TOP+'V18Q2 2 18 2H'+(W-18)+'Q'+(W-2)+' 2 '+(W-2)+' 18V'+TOP+'Z" fill="#e8bd80" stroke="#40291f" stroke-width="3" stroke-linejoin="round"/>';
  s+='<text x="'+(W/2)+'" y="'+(TOP/2+7)+'" text-anchor="middle" font-family="Segoe Print,Bradley Hand,Chalkboard SE,Comic Sans MS,cursive" font-weight="700" font-size="15" fill="#6a3b1d">Pip &amp; Crumb &middot; baked today</text>';
  s+='<rect x="10" y="'+(TOP+2)+'" width="'+(W-20)+'" height="'+(H-TOP-12)+'" rx="12" fill="#fff1d8" stroke="#b98650" stroke-width="2"/>';
  for(i=0;i<state.size;i++){
    var cx=PAD+(i%c)*CELL+CELL/2,cy=TOP+Math.floor(i/c)*CELL+CELL/2;
    s+='<g transform="translate('+cx+' '+cy+')"><circle class="well" r="'+(CELL/2-7)+'"/><text class="wnum">'+(i+1)+'</text>';
    if(interactive){
      s+='<g class="slot" data-slot="'+i+'" role="button" aria-label="'+slotLabel(i)+'"'+(state.slots[i]?' tabindex="0"':'')+'><rect x="'+(-CELL/2)+'" y="'+(-CELL/2)+'" width="'+CELL+'" height="'+CELL+'" fill="transparent"/><circle class="ring" r="'+(CELL/2-4)+'"/><g class="pc">'+(state.slots[i]?pieceMarkup(state.slots[i],i,false):'')+'</g></g>';
    }else if(state.slots[i]){s+=pieceMarkup(state.slots[i],i,false).replace(' class="drop"',' class="drop"')}
    s+='</g>';
  }
  return s+'</svg>';
}
var slotPc=[],tmr=[];
function rebuildBox(){
  $('#boxwrap').innerHTML=boxSVG(true);
  slotPc=$$('#boxsvg .slot').map(function(g){return $('.pc',g)});
  var svg=$('#boxsvg');
  svg.addEventListener('click',function(e){var g=e.target.closest('.slot');if(g)removeAt(+g.dataset.slot)});
  svg.addEventListener('keydown',function(e){
    if(e.key==='Enter'||e.key===' '){var g=e.target.closest&&e.target.closest('.slot');if(g){e.preventDefault();removeAt(+g.dataset.slot)}}
  });
}
function paint(i,pop){
  var pc=slotPc[i],g=pc.parentNode,id=state.slots[i];clearTimeout(tmr[i]);
  if(id){pc.innerHTML=pieceMarkup(id,i,pop);g.setAttribute('tabindex','0')}
  else{
    var d=pc.firstElementChild;
    if(d){d.setAttribute('class','drop out');tmr[i]=setTimeout(function(){pc.innerHTML=''},180)}
    g.removeAttribute('tabindex');
  }
  g.setAttribute('aria-label',slotLabel(i));
}

/* ---------- picker tiles ---------- */
function buildTiles(){
  var h='';
  P.forEach(function(p){
    h+='<button type="button" class="tile" data-id="'+p.id+'"><span class="cnt" aria-hidden="true"></span>'+ico(p.id)+'<span class="tn">'+p.name+'</span><span class="tp">'+money(p.price)+'</span><span class="tg">'+tagsHTML(p)+'</span></button>';
  });
  $('#grid').innerHTML=h;
  $('#grid').addEventListener('click',function(e){var t=e.target.closest('.tile');if(t)add(t.dataset.id)});
}

/* ---------- actions ---------- */
function mismatch(p){var m=[];['v','n','g'].forEach(function(k){if(state.filters[k]&&!p[k])m.push(FN[k])});return m}
function add(id){
  var i=state.slots.slice(0,state.size).indexOf(null);
  if(i<0){
    var w=$('#boxwrap');w.classList.remove('shake');void w.offsetWidth;w.classList.add('shake');
    sfx.no();toast('The box is full. Tap a pastry in the box to remove it, or choose a bigger box.',2800);return;
  }
  state.slots[i]=id;paint(i,true);sfx.add();
  var n=items().length,p=BY[id],mm=mismatch(p);
  ui();
  if(n===state.size){
    var pn=$('#boxpanel');pn.classList.remove('boxfull');void pn.offsetWidth;pn.classList.add('boxfull');
    setTimeout(sfx.full,260);
  }
  if(mm.length)toast('Heads up: '+plain(p.name)+' is not '+mm.join(' or ')+'.',2800);
}
function removeAt(i){
  if(!state.slots[i])return;
  state.slots[i]=null;paint(i,false);sfx.remove();ui();
}
function setSize(n){
  if(n===state.size)return;
  var cur=items(),kept=cur.slice(0,n),trimmed=cur.length-kept.length;
  state.size=n;state.slots=[];for(var i=0;i<12;i++)state.slots.push(kept[i]||null);
  rebuildBox();ui();sfx.tick();
  if(trimmed>0)toast(trimmed+' pastr'+(trimmed>1?'ies':'y')+' didn\'t fit in the smaller box and '+(trimmed>1?'were':'was')+' removed.',2800);
}
function toggleFilter(k){state.filters[k]=!state.filters[k];ui();sfx.tick()}
function resetAll(silent){
  state.size=6;state.filters={v:false,n:false,g:false};
  state.slots=[];for(var i=0;i<12;i++)state.slots.push(null);
  rebuildBox();ui();if(!silent){sfx.remove();toast('Box cleared. Fresh start!')}
}

/* ---------- ui sync ---------- */
function calc(){
  var its=items(),sub=0;its.forEach(function(id){sub+=BY[id].price});
  var full=its.length===state.size,rate=full?RATE[state.size]:0;
  return {n:its.length,sub:sub,rate:rate,total:Math.round(sub*(1-rate)*100)/100,full:full,list:its};
}
function ui(){
  var c=calc(),sz=state.size;
  $$('#seg button').forEach(function(b){b.setAttribute('aria-checked',String(+b.dataset.size===sz))});
  $$('.chip').forEach(function(b){b.setAttribute('aria-pressed',String(!!state.filters[b.dataset.f]))});
  var counts={};c.list.forEach(function(id){counts[id]=(counts[id]||0)+1});
  var okN=0;
  $$('#grid .tile').forEach(function(t){
    var p=BY[t.dataset.id],ok=match(p),k=counts[p.id]||0;if(ok)okN++;
    t.classList.toggle('dim',!ok);t.classList.toggle('has',k>0);
    $('.cnt',t).textContent=k;
    var dn=[];if(p.v)dn.push('vegan');if(p.n)dn.push('nut-free');if(p.g)dn.push('gluten-free');
    t.setAttribute('aria-label',plain(p.name)+', '+money(p.price)+(dn.length?', '+dn.join(', '):'')+(ok?'':'. Does not match your filters')+(k?'. '+k+' in box':'')+'. Tap to add.');
  });
  var any=state.filters.v||state.filters.n||state.filters.g;
  $('#fnote').textContent=any?okN+' of '+P.length+' pastries match. The rest are dimmed.':'Pastries that don\'t match will dim.';
  $('#total').textContent=money(c.total);
  var was=$('#was');if(c.rate>0){was.hidden=false;was.textContent='was '+money(c.sub)}else was.hidden=true;
  var left=sz-c.n,hint;
  if(c.n===0)hint='Tap a pastry below to drop it in. 0 of '+sz+' slots filled.';
  else if(!c.full)hint=c.n+' of '+sz+' filled. '+(RATE[sz]?'Add '+left+' more to save '+Math.round(RATE[sz]*100)+'%.':left+' to go.');
  else hint='Box full!'+(c.rate?' '+Math.round(c.rate*100)+'% off applied.':'');
  $('#hint').textContent=hint;
  var co=$('#checkout');co.disabled=c.n===0;co.textContent=c.n?'Checkout · '+money(c.total):'Checkout';
  if(!c.full)$('#boxpanel').classList.remove('boxfull');
  measure();
}
function measure(){
  var bp=$('#boxpanel'),sticky=getComputedStyle(bp).position==='sticky'&&window.innerWidth<860;
  document.documentElement.style.setProperty('--stickyH',sticky?bp.offsetHeight+'px':'0px');
}

/* ---------- checkout drawer (summary only, no forms) ---------- */
var lastFocus=null;
function renderSummary(){
  var c=calc(),h='';
  var counts={};c.list.forEach(function(id){counts[id]=(counts[id]||0)+1});
  if(!c.n){h='<p class="empty">Your box is empty. Pick a few pastries first.</p>'}
  else{
    h+=boxSVG(false);
    h+='<ul class="lines">';
    P.forEach(function(p){var k=counts[p.id];if(k)h+='<li>'+ico(p.id)+'<span>'+p.name+' <span class="q">&times; '+k+'</span></span><b>'+money(p.price*k)+'</b></li>'});
    h+='</ul><div class="sum"><div><span>Box of '+state.size+' ('+c.n+' pastr'+(c.n>1?'ies':'y')+')</span><span>'+money(c.sub)+'</span></div>';
    if(c.rate>0)h+='<div class="save"><span>Full-box saving ('+Math.round(c.rate*100)+'%)</span><span>-'+money(c.sub-c.total)+'</span></div>';
    h+='<div class="gt"><span>Total</span><span>'+money(c.total)+'</span></div></div>';
    if(!c.full)h+='<p class="note">'+(state.size-c.n)+' slot'+(state.size-c.n>1?'s are':' is')+' still empty'+(RATE[state.size]?'. Fill the box to save '+Math.round(RATE[state.size]*100)+'%':'')+'.</p>';
    var f=[];['v','n','g'].forEach(function(k){if(state.filters[k])f.push(FN[k])});
    if(f.length){
      var bad=c.list.filter(function(id){return !match(BY[id])}).length;
      if(bad)h+='<p class="note">Careful: '+bad+' item'+(bad>1?'s':'')+' in this box '+(bad>1?'don\'t':'doesn\'t')+' match your '+f.join(' + ')+' filter.</p>';
    }
    h+='<p class="note">This is a summary only. Nothing is sent and nothing is paid here. Show it at the counter at 14 Larkspur Lane.</p>';
  }
  $('#dBody').innerHTML=h;
}
function trapKey(e){
  if(!$('#drawer').classList.contains('open'))return;
  if(e.key==='Escape'){closeDrawer();return}
  if(e.key==='Tab'){
    var f=$$('#drawer button').filter(function(b){return !b.disabled});
    if(!f.length)return;var first=f[0],last=f[f.length-1];
    if(e.shiftKey&&document.activeElement===first){e.preventDefault();last.focus()}
    else if(!e.shiftKey&&document.activeElement===last){e.preventDefault();first.focus()}
    else if(!$('#drawer').contains(document.activeElement)){e.preventDefault();first.focus()}
  }
}
function openDrawer(){
  renderSummary();lastFocus=document.activeElement;
  $('#drawer').classList.add('open');$('#scrim').classList.add('open');$('#drawer').setAttribute('aria-hidden','false');
  document.body.classList.add('lock');sfx.open();
  try{$('#dClose').focus({preventScroll:true})}catch(e){}
}
function closeDrawer(){
  $('#drawer').classList.remove('open');$('#scrim').classList.remove('open');$('#drawer').setAttribute('aria-hidden','true');
  document.body.classList.remove('lock');
  if(lastFocus&&lastFocus.focus){try{lastFocus.focus({preventScroll:true})}catch(e){}}
}
document.addEventListener('keydown',trapKey);
$('#checkout').addEventListener('click',openDrawer);
$('#dClose').addEventListener('click',closeDrawer);
$('#dBack').addEventListener('click',closeDrawer);
$('#dDone').addEventListener('click',function(){closeDrawer();toast('Lovely. See you at the counter!')});
$('#scrim').addEventListener('click',closeDrawer);

/* ---------- wiring ---------- */
$('#seg').addEventListener('click',function(e){var b=e.target.closest('button');if(b)setSize(+b.dataset.size)});
$$('.chip').forEach(function(b){b.addEventListener('click',function(){toggleFilter(b.dataset.f)})});
$('#reset').addEventListener('click',function(){resetAll(false)});
$('#startOver').addEventListener('click',function(){resetAll(true);window.scrollTo({top:0,behavior:'smooth'});toast('Fresh start!')});
$$('[data-scroll]').forEach(function(b){b.addEventListener('click',function(){var t=$(b.dataset.scroll);if(t)t.scrollIntoView({behavior:'smooth',block:'start'})})});

/* pointer-driven press feedback (touch + mouse) */
document.addEventListener('pointerdown',function(e){var b=e.target.closest&&e.target.closest('button,.slot');if(b&&!b.disabled)b.classList.add('pressed')});
['pointerup','pointercancel'].forEach(function(t){document.addEventListener(t,function(){$$('.pressed').forEach(function(b){b.classList.remove('pressed')})})});

/* audio unlocks on first real tap */
function unlock(e){if(e.isTrusted)initAudio()}
window.addEventListener('pointerdown',unlock,true);
window.addEventListener('keydown',unlock,true);
window.addEventListener('resize',measure);

/* ---------- adaptive quality ---------- */
var lowfx=false;
function setLow(){if(lowfx)return;lowfx=true;document.documentElement.classList.add('lowfx')}
(function(){
  var last=performance.now(),frames=0,bad=0;
  function loop(t){
    frames++;var dt=t-last;
    if(dt>=1000){
      if(dt<2500){var fps=frames*1000/dt;if(fps<42){bad++;if(bad>=3)setLow()}else bad=Math.max(0,bad-1)}
      frames=0;last=t;
    }
    if(!lowfx)requestAnimationFrame(loop);
  }
  requestAnimationFrame(loop);
})();

/* ---------- demo mode ---------- */
var demo={on:false};
function wait(ms){return new Promise(function(res,rej){setTimeout(function(){demo.on?res():rej(new Error('stop'))},ms)})}
var dp=$('#dpointer');
function movePtr(x,y,ms){dp.style.transitionDuration=(ms||650)+'ms';dp.style.transform='translate('+x+'px,'+y+'px)'}
function click(el){el.dispatchEvent(new MouseEvent('click',{bubbles:true,cancelable:true,view:window}))}
async function tap(el){
  if(!el)return;
  var r=el.getBoundingClientRect(),sh=parseFloat(getComputedStyle(document.documentElement).getPropertyValue('--stickyH'))||0;
  if(r.top<sh+10||r.bottom>window.innerHeight-10){
    window.scrollBy({top:r.top-(sh+90),behavior:'smooth'});await wait(750);r=el.getBoundingClientRect();
  }
  movePtr(r.left+r.width/2,r.top+r.height/2,560);await wait(620);
  dp.classList.remove('down');void dp.offsetWidth;dp.classList.add('down');await wait(140);
  click(el);await wait(260);
}
async function scrollTo(sel){var t=$(sel);if(t)t.scrollIntoView({behavior:'smooth',block:'start'});await wait(900)}
async function demoLoop(){
  try{
    while(demo.on){
      resetAll(true);
      movePtr(window.innerWidth*.7,window.innerHeight*.55,10);
      window.scrollTo({top:0,behavior:'smooth'});await wait(1700);
      await scrollTo('#bakes');await wait(1500);
      await scrollTo('#box');await wait(500);
      await tap($('[data-size="4"]'));
      await tap($('.tile[data-id="croissant"]'));
      await tap($('.tile[data-id="bun"]'));
      await tap($('[data-size="6"]'));
      await tap($('.tile[data-id="brownie"]'));
      await tap($('.tile[data-id="muffin"]'));
      await tap($('.chip[data-f="v"]'));await wait(700);
      await tap($('.tile[data-id="cookie"]'));
      await tap($('.tile[data-id="macaroon"]'));
      await wait(900);
      await tap($('.slot[data-slot="1"]'));
      await tap($('.chip[data-f="v"]'));
      await tap($('.tile[data-id="tart"]'));
      await tap($('#checkout'));await wait(2200);
      await tap($('#dClose'));
      await tap($('#reset'));
      await scrollTo('#hours');await wait(1800);
    }
  }catch(e){}
}
function endDemo(){
  if(!demo.on)return;demo.on=false;
  dp.classList.remove('on');$('#dbanner').classList.remove('on');
}
function startDemo(){
  demo.on=true;dp.classList.add('on');$('#dbanner').classList.add('on');
  ['pointerdown','keydown','wheel','touchstart'].forEach(function(t){
    window.addEventListener(t,function(e){if(e.isTrusted)endDemo()},{capture:true,passive:true});
  });
  demoLoop();
}

/* ---------- init ---------- */
buildHours();buildMenu();buildTiles();rebuildBox();updateHours();ui();
setInterval(updateHours,30000);
requestAnimationFrame(function(){requestAnimationFrame(function(){
  try{parent.postMessage({vcb:'ready'},'*')}catch(e){}
  if(/#demo$/.test(location.href))setTimeout(startDemo,400);
})});
})();
</script>
</body>
</html>

Try 2 · index.html

works60.8 KB · 923 lines · no libraries
Download
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
<title>Tansy &amp; Crumb Bakehouse</title>
<meta name="description" content="Tansy & Crumb, an invented neighborhood bakery. Build your own box of pastries.">
<style>
:root{
  --cream:#fff7e8; --paper:#fffdf7; --ink:#3b2a20; --ink2:#6a5448; --terra:#c4512c; --terra-d:#8f3718;
  --butter:#f4c95d; --sage:#3f5d4e; --sage-l:#dde9d8; --kraft:#d4a574; --line:#ead9bb; --shadow:0 10px 30px rgba(80,45,20,.12);
  --serif:"Iowan Old Style","Palatino Linotype",Palatino,Georgia,"Times New Roman",serif;
  --sans:system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
  --hand:"Segoe Print","Bradley Hand","Comic Sans MS","Chalkboard SE",cursive;
}
*{box-sizing:border-box}
html{-webkit-text-size-adjust:100%;scroll-behavior:smooth}
body{margin:0;background:var(--cream);color:var(--ink);font-family:var(--sans);font-size:16px;line-height:1.5;overflow-x:hidden;
  background-image:radial-gradient(circle at 12% 8%,rgba(244,201,93,.22),transparent 40%),radial-gradient(circle at 92% 30%,rgba(196,81,44,.08),transparent 38%)}
img,svg{display:block}
button{font:inherit;color:inherit;cursor:pointer;touch-action:manipulation;-webkit-tap-highlight-color:transparent}
h1,h2,h3{font-family:var(--serif);line-height:1.15;margin:0}
p{margin:0}
a{color:inherit}
:focus-visible{outline:3px solid var(--sage);outline-offset:3px;border-radius:8px}
.wrap{max-width:1140px;margin:0 auto;padding:0 20px}
.sr{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
section{scroll-margin-top:16px}

/* header */
.top{position:relative;z-index:30;background:rgba(255,247,232,.92);backdrop-filter:blur(8px);-webkit-backdrop-filter:blur(8px);border-bottom:2px solid var(--line)}
.top .wrap{display:flex;align-items:center;gap:14px;min-height:64px}
.logo{display:flex;align-items:center;gap:10px;text-decoration:none;font-family:var(--serif);font-weight:700;font-size:20px;letter-spacing:.2px}
.logo svg{width:36px;height:36px}
.nav{display:none;margin-left:auto;gap:4px}
.nav a{text-decoration:none;padding:11px 14px;border-radius:999px;font-weight:600;min-height:44px;display:flex;align-items:center}
.nav a:hover{background:var(--line)}
.snd{margin-left:auto;display:flex;align-items:center;gap:8px;min-height:44px;min-width:44px;padding:0 14px;border-radius:999px;border:2px solid var(--ink);background:var(--paper);font-weight:600;font-size:14px}
.nav+.snd{margin-left:8px}
.snd svg{width:22px;height:22px}
.snd .off{display:none}
.snd[aria-pressed="false"] .on{display:none}
.snd[aria-pressed="false"] .off{display:block}
@media(min-width:900px){
  .top{position:sticky;top:0}
  .nav{display:flex}
  section{scroll-margin-top:76px}
}

/* buttons */
.btn{display:inline-flex;align-items:center;justify-content:center;gap:8px;min-height:48px;padding:0 24px;border-radius:999px;border:2px solid var(--ink);
  background:var(--terra);color:#fff;font-weight:700;font-size:16px;text-decoration:none;box-shadow:0 4px 0 var(--ink);transition:transform .08s,box-shadow .08s,background .2s}
.btn:hover{background:#b3461f}
.btn:active{transform:translateY(3px);box-shadow:0 1px 0 var(--ink)}
.btn.ghost{background:var(--paper);color:var(--ink)}
.btn.ghost:hover{background:#fff0d6}
.btn.small{min-height:44px;padding:0 16px;font-size:14px;box-shadow:0 3px 0 var(--ink)}
.btn[aria-disabled="true"]{background:#d8c6b0;color:#7b6859;box-shadow:0 4px 0 #9b8873;border-color:#9b8873}
.btn.pulse{animation:pulse 1.2s ease-in-out infinite}
@keyframes pulse{0%,100%{transform:scale(1)}50%{transform:scale(1.05)}}

/* badge */
.badge{display:inline-flex;align-items:center;gap:10px;padding:8px 16px 8px 12px;border-radius:999px;background:var(--paper);border:2px solid var(--ink);font-weight:700;min-height:44px}
.badge .dot{width:14px;height:14px;border-radius:50%;background:#999;flex:none;box-shadow:0 0 0 4px rgba(0,0,0,.08)}
.badge small{font-weight:500;color:var(--ink2);font-size:14px}
.badge[data-state="open"] .dot{background:#2e9d52;box-shadow:0 0 0 4px rgba(46,157,82,.25);animation:blink 2s infinite}
.badge[data-state="soon"] .dot{background:#e8a317;box-shadow:0 0 0 4px rgba(232,163,23,.25)}
.badge[data-state="closed"] .dot{background:#c23b3b;box-shadow:0 0 0 4px rgba(194,59,59,.2)}
@keyframes blink{50%{box-shadow:0 0 0 8px rgba(46,157,82,.05)}}

/* hero */
.hero{padding:28px 0 36px}
.hero .wrap{display:grid;gap:22px;align-items:center}
.eyebrow{font-family:var(--hand);color:var(--terra-d);font-size:18px;margin-bottom:8px}
.hero h1{font-size:clamp(38px,9vw,66px);letter-spacing:-.5px}
.hero h1 em{font-style:normal;color:var(--terra)}
.lede{font-size:18px;color:var(--ink2);margin:14px 0 22px;max-width:34em}
.hero-cta{display:flex;flex-wrap:wrap;gap:14px;align-items:center}
.hero-art{width:100%;max-width:560px;margin:0 auto}
.hero-art svg{width:100%;height:auto;overflow:visible}
@media(min-width:860px){.hero{padding:48px 0 56px}.hero .wrap{grid-template-columns:1fr 1.05fr;gap:40px}}
.steam{transform-box:fill-box;transform-origin:center;animation:steam 4s ease-in infinite}
@keyframes steam{0%{transform:translateY(8px) scale(.6);opacity:0}25%{opacity:.85}100%{transform:translateY(-46px) scale(1.5);opacity:0}}
.sunrays{transform-box:fill-box;transform-origin:center;animation:spin 40s linear infinite}
@keyframes spin{to{transform:rotate(360deg)}}
.cloud{animation:drift 14s ease-in-out infinite alternate}
@keyframes drift{to{transform:translateX(26px)}}
.swing{transform-box:fill-box;transform-origin:50% 0;animation:swing 3.4s ease-in-out infinite alternate}
@keyframes swing{from{transform:rotate(-7deg)}to{transform:rotate(7deg)}}
.twinkle{transform-box:fill-box;transform-origin:center;animation:twinkle 3s ease-in-out infinite}
@keyframes twinkle{0%,100%{transform:scale(.4);opacity:.2}50%{transform:scale(1);opacity:1}}
.lowfx .steam,.lowfx .sunrays,.lowfx .cloud,.lowfx .swing,.lowfx .twinkle,.lowfx .badge .dot{animation:none!important}
.lowfx .scene{filter:none!important}
@media(prefers-reduced-motion:reduce){.steam,.sunrays,.cloud,.swing,.twinkle,.badge .dot{animation:none!important}}

/* section heads */
.sec{padding:44px 0}
.sec-head{margin-bottom:22px;max-width:40em}
.sec-head .eyebrow{margin-bottom:4px}
.sec-head h2{font-size:clamp(30px,6vw,44px)}
.sec-head p{color:var(--ink2);margin-top:8px}

/* bakes */
.bakes{display:flex;gap:16px;overflow-x:auto;scroll-snap-type:x mandatory;padding:8px 20px 22px;margin:0 -20px;-webkit-overflow-scrolling:touch}
.bake{flex:0 0 min(270px,78vw);scroll-snap-align:center;background:var(--paper);border:2px solid var(--ink);border-radius:24px;padding:16px;display:flex;flex-direction:column;gap:8px;box-shadow:0 5px 0 var(--ink)}
.bake-art{height:112px;display:grid;place-items:center;border-radius:16px;background:radial-gradient(circle at 50% 60%,#ffe9bd,#fbd9a0);border:2px dashed #e1b777}
.bake-art svg{width:96px;height:96px;transform:rotate(var(--tilt))}
.bake h3{font-size:21px}
.bake p{color:var(--ink2);font-size:15px;flex:1}
.chips{display:flex;flex-wrap:wrap;gap:6px}
.chip{font-size:12px;font-weight:700;padding:3px 10px;border-radius:999px;background:var(--sage-l);color:#27402f;border:1.5px solid #9dbd9a}
.chip.warn{background:#fde5d3;color:#7a3414;border-color:#e8b189}
.bake-foot{display:flex;align-items:center;gap:10px;flex-wrap:wrap;margin-top:6px}
.price{font-family:var(--serif);font-weight:700;font-size:20px}
.when{font-size:13px;color:var(--ink2);flex:1;min-width:70px}
@media(min-width:760px){
  .bakes{display:grid;grid-template-columns:repeat(auto-fill,minmax(210px,1fr));overflow:visible;padding:8px 0 22px;margin:0}
  .bake{flex:none}
}

/* builder */
.build{background:linear-gradient(#fff0d2,#ffe6bd);border-top:3px solid var(--ink);border-bottom:3px solid var(--ink);position:relative}
.build::before{content:"";position:absolute;inset:0 0 auto 0;height:10px;background:repeating-linear-gradient(90deg,var(--terra) 0 26px,var(--paper) 26px 52px);opacity:.9}
.build .sec{padding-top:54px}
.sizes{display:flex;gap:10px;flex-wrap:wrap;margin-bottom:18px}
.sizebtn{display:flex;align-items:center;gap:10px;min-height:56px;padding:6px 16px 6px 10px;border-radius:18px;border:2px solid var(--ink);background:var(--paper);text-align:left;flex:1 1 150px;max-width:230px}
.sizebtn[aria-pressed="true"]{background:var(--sage);color:#fff;box-shadow:0 4px 0 var(--ink)}
.sizebtn svg{width:40px;height:34px;flex:none}
.sizebtn b{font-family:var(--serif);font-size:20px;display:block;line-height:1.1}
.sizebtn span{font-size:13px;opacity:.85}
.cfg{display:grid;gap:14px}
.panel{background:var(--paper);border:2px solid var(--ink);border-radius:24px;box-shadow:0 6px 0 var(--ink);padding:12px 14px 14px;z-index:6}
.panel-top{display:flex;justify-content:space-between;align-items:baseline;margin-bottom:4px}
.panel-top h3{font-size:20px}
#count{font-weight:800;font-variant-numeric:tabular-nums}
.boxwrap{display:grid;place-items:center}
#boxSvg{width:100%;max-width:460px;height:auto;max-height:26vh;overflow:visible}
.totals{display:flex;align-items:center;justify-content:space-between;gap:10px;margin-top:8px;flex-wrap:wrap}
.tot-l .lbl{font-size:13px;color:var(--ink2);display:block;line-height:1.1}
#total{font-family:var(--serif);font-size:28px;font-weight:700;line-height:1.1;font-variant-numeric:tabular-nums}
#saveNote{display:block;font-size:12.5px;color:var(--terra-d);font-weight:600}
.acts{display:flex;gap:8px}
.picker-top{display:flex;flex-wrap:wrap;gap:10px;align-items:center;margin-bottom:10px}
.picker-top .hint{flex:1 1 100%;color:var(--ink2);font-size:15px}
.fchips{display:flex;gap:8px;flex-wrap:wrap}
.fchip{min-height:44px;padding:0 14px;border-radius:999px;border:2px solid var(--ink);background:var(--paper);font-weight:700;font-size:14px;display:flex;align-items:center;gap:6px}
.fchip .tick{width:16px;height:16px;border-radius:50%;border:2px solid var(--ink);display:grid;place-items:center;font-size:11px;line-height:1}
.fchip[aria-pressed="true"]{background:var(--butter);box-shadow:0 3px 0 var(--ink)}
.fchip[aria-pressed="true"] .tick{background:var(--ink);color:var(--butter)}
.fchip[aria-pressed="true"] .tick::after{content:"\2713"}
#showing{font-size:13px;color:var(--ink2);margin-left:auto}
.pgrid{display:grid;grid-template-columns:repeat(auto-fill,minmax(104px,1fr));gap:10px}
.pcard{position:relative;display:flex;flex-direction:column;align-items:center;gap:2px;padding:10px 6px 8px;min-height:130px;background:var(--paper);border:2px solid var(--ink);border-radius:18px;transition:opacity .25s,filter .25s,transform .1s}
.pcard svg{width:68px;height:68px}
.pcard:active{transform:scale(.95)}
.pc-name{font-weight:700;font-size:13px;line-height:1.2;text-align:center}
.pc-price{font-size:13px;color:var(--ink2);font-variant-numeric:tabular-nums}
.pc-tags{display:flex;gap:3px;min-height:16px}
.pc-tags i{font-style:normal;font-size:10.5px;font-weight:800;background:var(--sage-l);color:#27402f;border-radius:6px;padding:0 4px}
.pc-badge{position:absolute;top:-8px;right:-6px;background:var(--terra);color:#fff;font-weight:800;font-size:13px;min-width:28px;height:28px;border-radius:14px;display:grid;place-items:center;border:2px solid var(--ink);padding:0 6px}
.pcard.dim{opacity:.3;filter:grayscale(.8)}
.pcard.added{animation:nudge .35s}
@keyframes nudge{40%{transform:scale(.92)}100%{transform:scale(1)}}
.pcard.full:not(.dim){opacity:.75}
.shake{animation:shake .4s}
@keyframes shake{20%{transform:translateX(-7px)}45%{transform:translateX(6px)}70%{transform:translateX(-4px)}}
@media(min-width:900px){
  .cfg{grid-template-columns:minmax(0,1fr) 440px;gap:30px;align-items:start}
  .picker{grid-column:1;grid-row:1}
  .panel{grid-column:2;grid-row:1;position:sticky;top:84px;padding:16px 18px 18px}
  #boxSvg{max-height:none}
  .pgrid{grid-template-columns:repeat(auto-fill,minmax(118px,1fr));gap:12px}
}
@media(max-width:899px){
  .panel{position:sticky;top:0;margin:0 -6px}
  .panel-top h3{font-size:17px}
  .tot-l .lbl{display:none}
  #total{font-size:24px}
}
@media(max-width:899px) and (max-height:560px){.panel{position:static}#boxSvg{max-height:none}}

/* box svg */
.cell{fill:#f6e5c6;stroke:#c99d63;stroke-width:2;stroke-dasharray:6 5}
.slot.filled .cell{stroke-dasharray:none;stroke:#e0c595}
.slot.next .cell{stroke:var(--terra);animation:next 1.4s ease-in-out infinite}
@keyframes next{50%{stroke-opacity:.35}}
.slot .num{font-family:var(--hand);font-size:22px;fill:#c8a370;text-anchor:middle}
.slot.filled .num{display:none}
.slot.filled{cursor:pointer}
.slot .hit{fill:transparent}
.slot:focus-visible{outline:none}
.slot:focus-visible .cell{stroke:var(--sage);stroke-width:4;stroke-dasharray:none}
.bounce{transform-box:fill-box;transform-origin:50% 85%}
.bounce.pop{animation:drop .62s cubic-bezier(.3,.7,.4,1) both}
.bounce.out{animation:out .18s ease-in both}
@keyframes drop{0%{transform:translateY(-48px) scale(.5);opacity:0}45%{transform:translateY(3px) scale(1.15,.86);opacity:1}65%{transform:translateY(-7px) scale(.96,1.05)}82%{transform:translateY(0) scale(1.04,.97)}100%{transform:none;opacity:1}}
@keyframes out{to{transform:scale(.3) translateY(-10px);opacity:0}}
.rm circle{fill:var(--ink)}
.rm path{stroke:#fff;stroke-width:2.4;stroke-linecap:round}
.spark{transform-box:fill-box;transform-origin:center;animation:spark .9s ease-out both}
@keyframes spark{0%{transform:scale(0) rotate(0);opacity:1}100%{transform:scale(1.6) rotate(120deg);opacity:0}}

/* toast + pill */
.toast{position:fixed;left:50%;bottom:max(24px,env(safe-area-inset-bottom));transform:translate(-50%,30px);background:var(--ink);color:#fff;padding:12px 18px;border-radius:14px;font-weight:600;font-size:15px;max-width:min(92vw,420px);text-align:center;opacity:0;pointer-events:none;transition:opacity .2s,transform .2s;z-index:90}
.toast.show{opacity:1;transform:translate(-50%,0)}
.jump{position:fixed;right:max(14px,env(safe-area-inset-right));bottom:max(16px,env(safe-area-inset-bottom));z-index:40;min-height:52px;padding:0 20px;border-radius:999px;border:2px solid var(--ink);background:var(--butter);font-weight:800;box-shadow:0 4px 0 var(--ink);display:none;align-items:center;gap:8px}
.jump.show{display:flex;animation:rise .3s}
@keyframes rise{from{transform:translateY(20px);opacity:0}}

/* hours */
.hours-grid{display:grid;gap:20px}
.card{background:var(--paper);border:2px solid var(--ink);border-radius:24px;padding:22px;box-shadow:0 5px 0 var(--ink)}
.card h3{font-size:24px;margin-bottom:10px}
.card p+p{margin-top:10px}
.story{background:var(--sage);color:#f5fbf2}
.story p{color:#e4f0de}
.story .sig{font-family:var(--hand);color:var(--butter);margin-top:14px}
table.hrs{width:100%;border-collapse:collapse;margin:14px 0 4px}
.hrs th,.hrs td{padding:10px 8px;border-bottom:1.5px dashed var(--line);text-align:left;font-weight:500}
.hrs td{text-align:right;font-variant-numeric:tabular-nums}
.hrs tr:last-child th,.hrs tr:last-child td{border-bottom:0}
.hrs tr.today th,.hrs tr.today td{font-weight:800;background:#fff0c9}
.hrs tr.today th::after{content:" \00b7 today";font-weight:600;color:var(--terra-d);font-size:13px}
@media(min-width:860px){.hours-grid{grid-template-columns:1fr 1fr;gap:28px}}

/* footer */
footer{background:var(--ink);color:#f3e6d3;padding:40px 0 48px;margin-top:20px}
footer .wrap{display:grid;gap:22px}
footer h3{color:#fff;font-size:24px;margin-bottom:6px}
footer p{color:#d8c5ad;font-size:15px}
footer .small{font-size:13px;color:#b9a48b}
footer .btn.ghost{background:transparent;color:#fff;border-color:#f3e6d3;box-shadow:none}
@media(min-width:760px){footer .wrap{grid-template-columns:1.4fr 1fr 1fr}}

/* drawer */
.drawer{position:fixed;inset:0;z-index:100;visibility:hidden;transition:visibility 0s .3s}
.drawer.open{visibility:visible;transition:none}
.scrim{position:absolute;inset:0;background:rgba(40,22,10,.55);opacity:0;transition:opacity .3s}
.drawer.open .scrim{opacity:1}
.sheet{position:absolute;left:0;right:0;bottom:0;max-height:90vh;max-height:90dvh;background:var(--paper);border-radius:26px 26px 0 0;border:2px solid var(--ink);border-bottom:0;display:flex;flex-direction:column;transform:translateY(100%);transition:transform .32s cubic-bezier(.2,.8,.2,1);outline:none}
.drawer.open .sheet{transform:none}
.sheet header{display:flex;align-items:center;justify-content:space-between;padding:18px 20px 8px}
.sheet h2{font-size:28px}
.icon-btn{width:48px;height:48px;border-radius:50%;border:2px solid var(--ink);background:var(--paper);display:grid;place-items:center}
.icon-btn svg{width:20px;height:20px}
#drawerBody{padding:4px 20px 12px;overflow:auto;-webkit-overflow-scrolling:touch}
.sheet-foot{display:flex;gap:10px;flex-wrap:wrap;padding:12px 20px calc(18px + env(safe-area-inset-bottom));border-top:2px dashed var(--line)}
.sheet-foot .btn{flex:1 1 140px}
.mini-box{display:flex;gap:6px;flex-wrap:wrap;background:#f6e5c6;border:2px solid #c99d63;border-radius:16px;padding:10px;margin-bottom:12px}
.mini-box svg{width:44px;height:44px}
.mini-box .empty{width:44px;height:44px;border-radius:12px;border:2px dashed #c99d63}
.lines{list-style:none;margin:0;padding:0}
.lines li{display:flex;align-items:center;gap:12px;padding:8px 0;border-bottom:1.5px dashed var(--line)}
.lines svg{width:44px;height:44px;flex:none}
.lines .nm{flex:1;font-weight:600;line-height:1.25}
.lines .nm small{display:block;font-weight:400;color:var(--ink2)}
.lines .pr{font-variant-numeric:tabular-nums;font-weight:700}
.sum{margin-top:12px}
.sum div{display:flex;justify-content:space-between;padding:4px 0}
.sum .grand{font-family:var(--serif);font-size:26px;font-weight:700;border-top:2px solid var(--ink);margin-top:6px;padding-top:10px}
.sum .disc{color:#2c7a45;font-weight:600}
.note{margin-top:14px;background:#fff0c9;border-radius:14px;padding:12px 14px;font-size:14px;color:var(--ink2)}
@media(min-width:700px){
  .sheet{left:auto;top:0;width:430px;max-height:none;border-radius:26px 0 0 26px;border-bottom:2px solid var(--ink);transform:translateX(100%)}
  .drawer.open .sheet{transform:none}
}

/* demo */
#demoPtr{position:fixed;left:0;top:0;width:44px;height:44px;margin:-6px 0 0 -8px;z-index:200;pointer-events:none;display:none;transition:transform .55s cubic-bezier(.4,.1,.2,1);filter:drop-shadow(0 3px 3px rgba(0,0,0,.35))}
body.demo #demoPtr{display:block}
#demoPtr .ring{position:absolute;left:2px;top:0;width:30px;height:30px;margin:-8px;border-radius:50%;border:3px solid var(--terra);opacity:0}
#demoPtr.tap .ring{animation:ring .4s ease-out}
@keyframes ring{from{opacity:1;transform:scale(.3)}to{opacity:0;transform:scale(1.8)}}
#demoTag{position:fixed;left:50%;top:10px;transform:translateX(-50%);z-index:150;background:var(--ink);color:#fff;font-size:13px;font-weight:700;padding:6px 14px;border-radius:999px;display:none;pointer-events:none;opacity:.92}
body.demo #demoTag{display:block}
</style>
</head>
<body>

<!-- Pastry sprite: one consistent style (flat fills, warm brown outline, soft highlight) -->
<svg width="0" height="0" style="position:absolute" aria-hidden="true" focusable="false">
<defs>
<symbol id="p-croissant" viewBox="0 0 100 100"><g stroke="#4a3022" stroke-width="2.5" stroke-linejoin="round" stroke-linecap="round">
<path d="M10 68C8 46 28 26 50 26C72 26 92 46 90 68C84 74 76 70 70 62C60 68 40 68 30 62C24 70 16 74 10 68Z" fill="#e6a84e"/>
<path d="M34 30C38 42 38 54 32 62C40 66 46 66 50 66C54 54 54 40 50 26C44 26 38 28 34 30Z" fill="#f0bc66" stroke="none"/>
<path d="M34 30C38 42 38 54 32 62" fill="none"/><path d="M50 26C54 40 54 54 50 66" fill="none"/><path d="M66 30C62 42 62 54 68 62" fill="none"/>
<path d="M18 54C20 46 26 40 32 36" fill="none" stroke="#fbe0a6" stroke-width="3"/>
</g></symbol>
<symbol id="p-almond" viewBox="0 0 100 100"><g stroke="#4a3022" stroke-width="2.5" stroke-linejoin="round" stroke-linecap="round">
<use href="#p-croissant" x="0" y="0" width="100" height="100"/>
<g fill="#fbefd0" stroke-width="1.6">
<ellipse cx="38" cy="40" rx="6.5" ry="3.3" transform="rotate(-35 38 40)"/><ellipse cx="52" cy="36" rx="6.5" ry="3.3" transform="rotate(10 52 36)"/>
<ellipse cx="66" cy="42" rx="6.5" ry="3.3" transform="rotate(40 66 42)"/><ellipse cx="46" cy="50" rx="6.5" ry="3.3" transform="rotate(-10 46 50)"/>
<ellipse cx="29" cy="54" rx="6" ry="3" transform="rotate(-50 29 54)"/><ellipse cx="74" cy="56" rx="6" ry="3" transform="rotate(50 74 56)"/>
</g>
<g fill="#fff" stroke="none"><circle cx="44" cy="30" r="1.6"/><circle cx="60" cy="31" r="1.6"/><circle cx="56" cy="58" r="1.6"/><circle cx="36" cy="60" r="1.6"/><circle cx="80" cy="62" r="1.6"/></g>
</g></symbol>
<symbol id="p-painchoc" viewBox="0 0 100 100"><g stroke="#4a3022" stroke-width="2.5" stroke-linejoin="round" stroke-linecap="round">
<path d="M10 46Q10 30 26 30H74Q90 30 90 46V58Q90 74 74 74H26Q10 74 10 58Z" fill="#e0993f"/>
<path d="M22 38H78" fill="none" stroke="#f6cf84" stroke-width="3.5"/>
<path d="M34 31Q29 40 34 48" fill="none"/><path d="M50 30Q45 40 50 48" fill="none"/><path d="M66 30Q61 40 66 48" fill="none"/>
<rect x="18" y="52" width="64" height="12" rx="6" fill="#4a2a1c"/>
<path d="M28 57H50" fill="none" stroke="#8a5a3f" stroke-width="2"/>
</g></symbol>
<symbol id="p-swirl" viewBox="0 0 100 100"><g stroke="#4a3022" stroke-width="2.5" stroke-linejoin="round" stroke-linecap="round">
<circle cx="50" cy="50" r="35" fill="#ebb676"/>
<path d="M50 50a4 4 0 0 1 8 0a8 8 0 0 1-16 0a12 12 0 0 1 24 0a16 16 0 0 1-32 0a20 20 0 0 1 40 0a24 24 0 0 1-48 0" fill="none" stroke="#b2622b" stroke-width="4"/>
<path d="M22 40q7-9 14 0t14 0t14 0t14 0" fill="none" stroke="#fff7ea" stroke-width="4.5"/>
<path d="M26 62q7-8 13 0t13 0t13 0" fill="none" stroke="#fff7ea" stroke-width="4.5"/>
</g></symbol>
<symbol id="p-muffin" viewBox="0 0 100 100"><g stroke="#4a3022" stroke-width="2.5" stroke-linejoin="round" stroke-linecap="round">
<path d="M28 58L72 58L66 86L34 86Z" fill="#e8d5b0"/>
<path d="M40 61L38 84M50 61V85M60 61L62 84" fill="none" stroke="#b79b6c" stroke-width="1.8"/>
<path d="M18 60C12 38 32 18 50 18C68 18 88 38 82 60C72 65 28 65 18 60Z" fill="#dc9a4a"/>
<g fill="#5f64b8" stroke-width="2"><circle cx="38" cy="36" r="4.6"/><circle cx="58" cy="30" r="4.6"/><circle cx="68" cy="47" r="4.6"/><circle cx="46" cy="50" r="4.6"/><circle cx="29" cy="52" r="4"/></g>
<g fill="#fff" stroke="none"><circle cx="36.6" cy="34.6" r="1.2"/><circle cx="56.6" cy="28.6" r="1.2"/><circle cx="66.6" cy="45.6" r="1.2"/><circle cx="44.6" cy="48.6" r="1.2"/></g>
<g fill="#f6d28f" stroke="none"><circle cx="50" cy="40" r="1.4"/><circle cx="74" cy="38" r="1.4"/><circle cx="26" cy="42" r="1.4"/><circle cx="58" cy="56" r="1.4"/></g>
</g></symbol>
<symbol id="p-tart" viewBox="0 0 100 100"><g stroke="#4a3022" stroke-width="2.5" stroke-linejoin="round" stroke-linecap="round">
<path d="M14 60L86 60L77 84Q50 91 23 84Z" fill="#e2b373"/>
<path d="M26 62L30 85M38 62L40 88M50 62V89M62 62L60 88M74 62L70 85" fill="none" stroke-width="1.8"/>
<path d="M12 60C12 40 32 32 50 32C68 32 88 40 88 60Z" fill="#f7dc4d"/>
<path d="M24 52C28 45 36 42 43 41" fill="none" stroke="#fff6b8" stroke-width="3"/>
<circle cx="56" cy="44" r="10" fill="#fff3a8"/><circle cx="56" cy="44" r="7" fill="#f4cf2a" stroke="none"/>
<path d="M49 44H63M52.75 37.9L59.25 50.1M59.25 37.9L52.75 50.1" fill="none" stroke="#fff3a8" stroke-width="1.5"/>
</g></symbol>
<symbol id="p-cookie" viewBox="0 0 100 100"><g stroke="#4a3022" stroke-width="2.5" stroke-linejoin="round" stroke-linecap="round">
<path d="M50 14C68 12 85 27 86 48C88 69 71 86 50 86C29 86 13 71 14 50C15 29 32 15 50 14Z" fill="#d6a35e"/>
<g fill="#5b3a52" stroke-width="2"><ellipse cx="36" cy="36" rx="5" ry="3.4" transform="rotate(-25 36 36)"/><ellipse cx="62" cy="33" rx="5" ry="3.4" transform="rotate(20 62 33)"/><ellipse cx="70" cy="55" rx="5" ry="3.4" transform="rotate(-40 70 55)"/><ellipse cx="45" cy="58" rx="5" ry="3.4" transform="rotate(10 45 58)"/><ellipse cx="29" cy="58" rx="4.5" ry="3" transform="rotate(35 29 58)"/><ellipse cx="55" cy="73" rx="4.5" ry="3" transform="rotate(-15 55 73)"/></g>
<g stroke="#f4dcab" stroke-width="2.4" fill="none"><path d="M48 24l5 2M24 46l5-2M76 44l-5 3M58 48l5 3M40 70l5-2M68 68l-4-3M46 42l4-3"/></g>
</g></symbol>
<symbol id="p-brownie" viewBox="0 0 100 100"><g stroke="#4a3022" stroke-width="2.5" stroke-linejoin="round" stroke-linecap="round">
<path d="M14 52H86V76Q86 83 79 83H21Q14 83 14 76Z" fill="#4b2a1d"/>
<path d="M14 52L22 33Q23 30 27 30H73Q77 30 78 33L86 52Z" fill="#6b3d28"/>
<path d="M32 38L40 44L36 50M60 36L57 44L65 48" fill="none" stroke="#c18a63" stroke-width="1.8"/>
<path d="M26 66H74" fill="none" stroke="#7b4a34" stroke-width="2"/>
<g fill="#f7efe3" stroke="none"><circle cx="30" cy="40" r="1.7"/><circle cx="48" cy="36" r="1.7"/><circle cx="70" cy="40" r="1.7"/><circle cx="52" cy="46" r="1.7"/></g>
</g></symbol>
<symbol id="p-financier" viewBox="0 0 100 100"><g stroke="#4a3022" stroke-width="2.5" stroke-linejoin="round" stroke-linecap="round">
<path d="M14 54L86 54L80 80Q79 84 75 84H25Q21 84 20 80Z" fill="#e1ad58"/>
<path d="M14 54L22 36Q23 33 27 33H73Q77 33 78 36L86 54Z" fill="#efca78"/>
<path d="M26 66H74" fill="none" stroke="#f3d28f" stroke-width="3"/>
<g fill="#8bb36a" stroke-width="1.5"><rect x="28" y="40" width="8" height="4.5" rx="1.5" transform="rotate(-20 32 42)"/><rect x="42" y="37" width="8" height="4.5" rx="1.5" transform="rotate(15 46 39)"/><rect x="56" y="42" width="8" height="4.5" rx="1.5" transform="rotate(-10 60 44)"/><rect x="68" y="38" width="7" height="4.5" rx="1.5" transform="rotate(30 71 40)"/><rect x="46" y="47" width="7" height="4" rx="1.5" transform="rotate(-25 49 49)"/></g>
</g></symbol>
<symbol id="p-bar" viewBox="0 0 100 100"><g stroke="#4a3022" stroke-width="2.5" stroke-linejoin="round" stroke-linecap="round">
<path d="M14 46Q14 38 22 38H78Q86 38 86 46V76Q86 84 78 84H22Q14 84 14 76Z" fill="#e5bf86"/>
<path d="M14 46Q14 38 22 38H78Q86 38 86 46V56H14Z" fill="#fff3dc" stroke="none"/>
<path d="M14 56H86V68H14Z" fill="#cc3350" stroke="none"/>
<path d="M14 56H86M14 68H86" fill="none"/>
<path d="M14 46Q14 38 22 38H78Q86 38 86 46V76Q86 84 78 84H22Q14 84 14 76Z" fill="none"/>
<g fill="#e0b36a" stroke="none"><rect x="24" y="43" width="7" height="3" rx="1.5"/><rect x="42" y="46" width="7" height="3" rx="1.5"/><rect x="60" y="42" width="7" height="3" rx="1.5"/><rect x="72" y="48" width="7" height="3" rx="1.5"/></g>
<g fill="#d02a4b" stroke-width="2"><circle cx="40" cy="33" r="5"/><circle cx="50" cy="31" r="5"/><circle cx="60" cy="33" r="5"/><circle cx="50" cy="38" r="4.6"/></g>
</g></symbol>
</defs>
</svg>

<div id="demoTag">Demo mode &middot; touch anything to take over</div>
<svg id="demoPtr" viewBox="0 0 44 44" aria-hidden="true"><circle class="ring" cx="12" cy="8" r="0" /><path d="M8 4L8 30L15 24L20 36L25 34L20 22L30 22Z" fill="#fff" stroke="#3b2a20" stroke-width="2.5" stroke-linejoin="round"/></svg>

<header class="top">
  <div class="wrap">
    <a class="logo" href="#top" aria-label="Tansy &amp; Crumb Bakehouse, top of page">
      <svg viewBox="0 0 100 100" aria-hidden="true"><use href="#p-croissant"/></svg>
      <span>Tansy &amp; Crumb</span>
    </a>
    <nav class="nav" aria-label="Sections">
      <a href="#bakes-sec">Today's bakes</a><a href="#build">Build a box</a><a href="#hours">Hours</a>
    </nav>
    <button class="snd" id="soundBtn" type="button" aria-pressed="true" aria-label="Sound on. Tap to mute">
      <svg class="on" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4 9v6h4l5 4V5L8 9z"/><path d="M16.5 8.5a5 5 0 0 1 0 7M19 6a8.5 8.5 0 0 1 0 12"/></svg>
      <svg class="off" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4 9v6h4l5 4V5L8 9z"/><path d="M17 9l5 6M22 9l-5 6"/></svg>
      <span id="soundLbl">Sound on</span>
    </button>
  </div>
</header>

<main id="top">
<section class="hero" aria-labelledby="h1">
  <div class="wrap">
    <div>
      <p class="eyebrow">Wick Lane's corner bakehouse</p>
      <h1 id="h1">Tansy <em>&amp;</em> Crumb Bakehouse</h1>
      <p class="lede">Butter, patience and a sourdough starter named Gladys. We bake small batches before sunrise, then box them up warm for the neighborhood.</p>
      <div class="hero-cta">
        <a class="btn" id="heroCta" href="#build">Build your box</a>
        <span class="badge" data-live data-state="closed" role="status"><span class="dot"></span><span><span data-live-title>Checking hours</span> <small data-live-sub></small></span></span>
      </div>
    </div>
    <div class="hero-art" id="heroArt" role="img" aria-label="Hand-drawn illustration of the bakery shop front with a striped awning, a window full of pastries and a chalkboard sign"></div>
  </div>
</section>

<section class="sec" id="bakes-sec" aria-labelledby="bakesH">
  <div class="wrap">
    <div class="sec-head">
      <p class="eyebrow">Fresh from the ovens</p>
      <h2 id="bakesH">Today's bakes</h2>
      <p>Ten things we made this morning. Tap Add to drop one in your box.</p>
    </div>
    <div class="bakes" id="bakes" role="list"></div>
  </div>
</section>

<section class="build" id="build" aria-labelledby="buildH">
  <div class="wrap sec">
    <div class="sec-head">
      <p class="eyebrow">The fun part</p>
      <h2 id="buildH">Build your box</h2>
    </div>
    <div class="sizes" id="sizes" role="group" aria-label="Box size"></div>
    <div class="cfg">
      <div class="panel" id="boxPanel">
        <div class="panel-top"><h3>Your box</h3><span id="count" aria-live="polite">0 / 6</span></div>
        <div class="boxwrap"><svg id="boxSvg" role="group" aria-label="Pastry box"></svg></div>
        <div class="totals">
          <div class="tot-l"><span class="lbl">Total</span><span id="total">$0.00</span><span id="saveNote"></span></div>
          <div class="acts">
            <button class="btn ghost small" id="resetBtn" type="button">Reset</button>
            <button class="btn small" id="checkoutBtn" type="button" aria-disabled="true">Checkout</button>
          </div>
        </div>
      </div>
      <div class="picker">
        <div class="picker-top">
          <p class="hint">Tap a pastry to drop it in the box. Tap an item in the box to take it out.</p>
          <div class="fchips" role="group" aria-label="Dietary filters">
            <button class="fchip" type="button" data-filter="vegan" aria-pressed="false"><span class="tick"></span>Vegan</button>
            <button class="fchip" type="button" data-filter="nutfree" aria-pressed="false"><span class="tick"></span>Nut-free</button>
            <button class="fchip" type="button" data-filter="gf" aria-pressed="false"><span class="tick"></span>Gluten-free</button>
          </div>
          <span id="showing" aria-live="polite"></span>
        </div>
        <div class="pgrid" id="picker"></div>
      </div>
    </div>
  </div>
</section>

<section class="sec" id="hours" aria-labelledby="hoursH">
  <div class="wrap">
    <div class="sec-head">
      <p class="eyebrow">Come say hello</p>
      <h2 id="hoursH">Hours &amp; our story</h2>
    </div>
    <div class="hours-grid">
      <div class="card story">
        <h3>Little shop, long mornings</h3>
        <p>Marit and Joss opened Tansy &amp; Crumb in 2014, in a former key-cutting shop on Wick Lane with one oven and a wobbly table.</p>
        <p>Gladys, the sourdough starter, is older than the shop and still gets fed first. Everything is rolled, shaped and baked right here, usually before the first bus goes by.</p>
        <p class="sig">See you at the counter, Marit &amp; Joss</p>
      </div>
      <div class="card">
        <h3>Opening hours</h3>
        <span class="badge" data-live data-state="closed" role="status"><span class="dot"></span><span><span data-live-title>Checking hours</span> <small data-live-sub></small></span></span>
        <table class="hrs" id="hrs"><caption class="sr">Weekly opening hours</caption><tbody></tbody></table>
        <p style="font-size:14px;color:var(--ink2)">Times follow your device's local clock.</p>
      </div>
    </div>
  </div>
</section>
</main>

<footer>
  <div class="wrap">
    <div><h3>Tansy &amp; Crumb</h3><p>14 Wick Lane, Little Hollow<br>(555) 010-0142</p></div>
    <div><h3 style="font-size:19px">Good to know</h3><p>Pickup only. Order summaries stay on this page; nothing is sent anywhere and no payment is taken here.</p></div>
    <div><p class="small">An invented bakery made for a demo. Pastries drawn in code.</p><p style="margin-top:12px"><button class="btn ghost small" id="restartBtn" type="button">Start over</button></p></div>
  </div>
</footer>

<button class="jump" id="jump" type="button" aria-label="Back to your box"><span id="jumpTxt">Your box</span> &#8594;</button>
<div class="toast" id="toast" role="status" aria-live="polite"></div>

<div class="drawer" id="drawer" aria-hidden="true">
  <div class="scrim" id="scrim"></div>
  <section class="sheet" id="sheet" role="dialog" aria-modal="true" aria-labelledby="drawerTitle" tabindex="-1">
    <header>
      <h2 id="drawerTitle">Your order</h2>
      <button class="icon-btn" id="drawerClose" type="button" aria-label="Close order summary"><svg viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="2.6" stroke-linecap="round" aria-hidden="true"><path d="M4 4l12 12M16 4L4 16"/></svg></button>
    </header>
    <div id="drawerBody"></div>
    <div class="sheet-foot">
      <button class="btn ghost" id="keepBtn" type="button">Keep building</button>
      <button class="btn" id="newBtn" type="button">Start a new box</button>
    </div>
  </section>
</div>

<script>
(function(){
'use strict';
var $=function(s,r){return (r||document).querySelector(s)};
var $$=function(s,r){return Array.prototype.slice.call((r||document).querySelectorAll(s))};
var sleep=function(ms){return new Promise(function(r){setTimeout(r,ms)})};

/* ---------- seeded randomness ---------- */
function mulberry32(a){return function(){a|=0;a=a+0x6D2B79F5|0;var t=Math.imul(a^a>>>15,1|a);t=t+Math.imul(t^t>>>7,61|t)^t;return((t^t>>>14)>>>0)/4294967296}}
var rnd=mulberry32(20240611);

/* ---------- data ---------- */
var TAGNAME={vegan:'Vegan',nutfree:'Nut-free',gf:'Gluten-free'};
var TAGSHORT={vegan:'VG',nutfree:'NF',gf:'GF'};
var PASTRIES=[
 {id:'croissant',sym:'p-croissant',name:'Butter croissant',price:3.5,tags:['nutfree'],time:'6:30 am',desc:'Three days of folding. Shatters first, then melts.'},
 {id:'almond',sym:'p-almond',name:'Almond croissant',price:4.25,tags:[],time:'7:00 am',desc:'Twice-baked with frangipane and toasted flakes.'},
 {id:'painchoc',sym:'p-painchoc',name:'Pain au chocolat',price:3.95,tags:['nutfree'],time:'6:30 am',desc:'Two bars of dark chocolate rolled in butter dough.'},
 {id:'swirl',sym:'p-swirl',name:'Cardamom swirl',price:3.75,tags:['vegan','nutfree'],time:'7:15 am',desc:'Soft spiral with cardamom sugar and an oat-milk glaze.'},
 {id:'muffin',sym:'p-muffin',name:'Blueberry muffin',price:3.25,tags:['nutfree'],time:'7:00 am',desc:'Tall sugar-crusted dome packed with jammy berries.'},
 {id:'tart',sym:'p-tart',name:'Lemon tart',price:4.5,tags:['nutfree'],time:'8:00 am',desc:'Sharp lemon curd in a crisp shortcrust shell.'},
 {id:'cookie',sym:'p-cookie',name:'Oat & raisin cookie',price:2.75,tags:['vegan','nutfree'],time:'8:30 am',desc:'Chewy, brown-sugar sweet and entirely plant-based.'},
 {id:'brownie',sym:'p-brownie',name:'Fudgy brownie',price:3.95,tags:['gf','nutfree'],time:'8:00 am',desc:'Flourless, dark and dense with a crackly top.'},
 {id:'financier',sym:'p-financier',name:'Pistachio financier',price:3.95,tags:['gf'],time:'7:45 am',desc:'Brown-butter cake with ground pistachio, naturally gluten-free.'},
 {id:'bar',sym:'p-bar',name:'Raspberry coconut bar',price:3.5,tags:['vegan','gf','nutfree'],time:'9:00 am',desc:'Jammy raspberry under toasted coconut. Free of dairy, gluten and nuts.'}
];
var BYID={};PASTRIES.forEach(function(p){BYID[p.id]=p});
var SIZES=[{n:4,label:'Petite',cols:2,rows:2},{n:6,label:'Classic',cols:3,rows:2},{n:12,label:"Baker's dozen",cols:4,rows:3}];
var DISCOUNT=0.10;
var fmt=function(n){return '$'+n.toFixed(2)};

/* ---------- state ---------- */
var state={size:6,slots:[null,null,null,null,null,null],filters:{vegan:false,nutfree:false,gf:false}};
var lastAdded=-1;

/* ---------- audio (starts only after a real tap) ---------- */
var audio={ctx:null,muted:false};
function ensureAudio(e){
  if(e&&e.isTrusted===false)return;
  if(audio.ctx){ if(audio.ctx.state==='suspended'){try{audio.ctx.resume()}catch(x){}} return; }
  try{var AC=window.AudioContext||window.webkitAudioContext;if(AC){audio.ctx=new AC();}}catch(x){}
}
['pointerdown','keydown','touchend'].forEach(function(t){window.addEventListener(t,ensureAudio,true)});
function tone(f,d,o){
  o=o||{};
  if(!audio.ctx||audio.muted)return;
  try{
    var c=audio.ctx,t0=c.currentTime+(o.delay||0),osc=c.createOscillator(),g=c.createGain();
    osc.type=o.type||'sine';osc.frequency.setValueAtTime(f,t0);
    if(o.to)osc.frequency.exponentialRampToValueAtTime(o.to,t0+d);
    var v=o.gain||0.12;
    g.gain.setValueAtTime(0.0001,t0);g.gain.exponentialRampToValueAtTime(v,t0+0.01);g.gain.exponentialRampToValueAtTime(0.0001,t0+d);
    osc.connect(g);g.connect(c.destination);osc.start(t0);osc.stop(t0+d+0.02);
  }catch(x){}
}
var sfx={
  add:function(){tone(480,.12,{to:780,type:'triangle'});tone(1040,.08,{delay:.07,gain:.05})},
  remove:function(){tone(520,.14,{to:240,type:'triangle'})},
  full:function(){[523,659,784,1046].forEach(function(f,i){tone(f,.22,{delay:i*.09,type:'triangle',gain:.1})})},
  open:function(){tone(660,.16,{type:'sine'});tone(880,.2,{delay:.08,type:'sine'})},
  nope:function(){tone(200,.16,{type:'square',gain:.04})},
  tick:function(){tone(700,.05,{type:'sine',gain:.06})}
};
function updateSoundBtn(){
  var b=$('#soundBtn');b.setAttribute('aria-pressed',String(!audio.muted));
  b.setAttribute('aria-label',audio.muted?'Sound muted. Tap to turn on':'Sound on. Tap to mute');
  $('#soundLbl').textContent=audio.muted?'Muted':'Sound on';
}
$('#soundBtn').addEventListener('click',function(){audio.muted=!audio.muted;updateSoundBtn();if(!audio.muted){ensureAudio();sfx.tick()}});

/* ---------- toast ---------- */
var toastT=0;
function toast(msg){var t=$('#toast');t.textContent=msg;t.classList.add('show');clearTimeout(toastT);toastT=setTimeout(function(){t.classList.remove('show')},2300)}

/* ---------- hero illustration ---------- */
function heroSVG(){
  var s='',i;
  var W=428,x0=66,sw=W/7,r=sw/2;
  var stripes='';
  for(i=0;i<7;i++){var x=(x0+i*sw).toFixed(2);var col=i%2?'#fff1d6':'#d9653b';
    stripes+='<path d="M'+x+' 228H'+(x0+(i+1)*sw).toFixed(2)+'V250A'+r.toFixed(2)+' '+r.toFixed(2)+' 0 0 1 '+x+' 250Z" fill="'+col+'"/>';}
  var stones='';
  for(i=0;i<10;i++){var sx=20+i*55+rnd()*14;stones+='<path d="M'+sx.toFixed(1)+' 412v'+(34+rnd()*10).toFixed(0)+'" />';}
  stones+='<path d="M0 436H560" />';
  var planks='';
  for(i=0;i<5;i++){var py=(150+i*52+rnd()*6).toFixed(1);planks+='<path d="M80 '+py+'H'+(96+rnd()*14).toFixed(0)+'M'+(462-rnd()*14).toFixed(0)+' '+py+'H480" stroke-width="2" opacity=".35"/>';}
  var sparks='';
  for(i=0;i<9;i++){var cx=(24+rnd()*512).toFixed(0),cy=(20+rnd()*90).toFixed(0),dl=(rnd()*3).toFixed(2);
    sparks+='<path class="twinkle" style="animation-delay:'+dl+'s" d="M'+cx+' '+(cy-6)+'v12M'+(+cx-6)+' '+cy+'h12" stroke="#e8a317" stroke-width="2.5" stroke-linecap="round"/>';}
  var rays='';
  for(i=0;i<12;i++){var a=i*Math.PI/6;rays+='<path d="M'+(470+Math.cos(a)*34).toFixed(1)+' '+(64+Math.sin(a)*34).toFixed(1)+'L'+(470+Math.cos(a)*46).toFixed(1)+' '+(64+Math.sin(a)*46).toFixed(1)+'"/>';}
  s+='<svg viewBox="0 0 560 470" aria-hidden="true" focusable="false"><defs><filter id="rough" x="-2%" y="-2%" width="104%" height="104%"><feTurbulence type="fractalNoise" baseFrequency="0.035" numOctaves="2" seed="7" result="n"/><feDisplacementMap in="SourceGraphic" in2="n" scale="3.4"/></filter></defs>';
  s+='<ellipse cx="280" cy="250" rx="272" ry="212" fill="#fde7bd"/>';
  s+=sparks;
  s+='<g class="sunrays" stroke="#e8a317" stroke-width="4" stroke-linecap="round">'+rays+'</g><circle cx="470" cy="64" r="26" fill="#f8cf62" stroke="#3b2a20" stroke-width="3"/>';
  s+='<g class="cloud" fill="#fffaf0" stroke="#3b2a20" stroke-width="3" stroke-linejoin="round"><path d="M70 74q-4-18 14-20q8-14 24-6q18-4 20 14q12 2 8 12H66q-8-2-4-10z"/></g>';
  s+='<g class="scene" filter="url(#rough)" stroke="#3b2a20" stroke-width="3" stroke-linejoin="round" stroke-linecap="round">';
  s+='<rect x="0" y="410" width="560" height="60" fill="#e4cda6"/>'+'<g fill="none" stroke-width="2.2" opacity=".6">'+stones+'</g>';
  s+='<rect x="410" y="76" width="34" height="56" fill="#b5573a"/><path d="M404 76h46" stroke-width="5"/>';
  s+='<rect x="72" y="124" width="416" height="288" fill="#f4d9b5"/>'+planks;
  s+='<rect x="62" y="112" width="436" height="20" rx="4" fill="#3f5d4e"/>';
  s+='<rect x="130" y="138" width="300" height="54" rx="10" fill="#3f5d4e"/><rect x="138" y="144" width="284" height="42" rx="6" fill="none" stroke="#f4c95d" stroke-width="2"/>';
  s+='<text x="280" y="170" text-anchor="middle" font-family="Georgia,serif" font-weight="700" font-size="25" fill="#fff1d6" stroke="none" letter-spacing="1">Tansy &amp; Crumb</text>';
  s+='<text x="280" y="183" text-anchor="middle" font-family="Georgia,serif" font-size="9" fill="#f4c95d" stroke="none" letter-spacing="3">BAKEHOUSE &#183; EST. 2014</text>';
  s+='<polygon points="88,198 472,198 494,228 66,228" fill="#d9653b"/>'+stripes;
  s+='<rect x="100" y="296" width="192" height="96" rx="6" fill="#ffe8b0"/><rect x="92" y="392" width="208" height="12" rx="4" fill="#3f5d4e"/>';
  s+='<path d="M104 336H288M104 384H288" stroke-width="5"/>';
  var up=['p-muffin','p-cookie','p-brownie'],lo=['p-croissant','p-swirl','p-tart'];
  for(i=0;i<3;i++){s+='<use href="#'+up[i]+'" x="'+(112+i*58)+'" y="294" width="42" height="42"/><use href="#'+lo[i]+'" x="'+(112+i*58)+'" y="342" width="42" height="42"/>';}
  s+='<rect x="332" y="292" width="110" height="120" rx="6" fill="#3f5d4e"/><rect x="344" y="304" width="86" height="72" rx="4" fill="#ffe8b0"/>';
  s+='<rect x="344" y="386" width="86" height="20" rx="3" fill="none" stroke-width="2.5"/><circle cx="424" cy="382" r="5" fill="#f4c95d"/>';
  s+='<path d="M356 304v72M430 340H344" stroke-width="2" opacity=".5"/>';
  s+='<rect x="12" y="338" width="46" height="58" rx="4" fill="#34413a"/><path d="M16 396L8 412M54 396L62 412" />';
  s+='<path d="M20 352h28M20 362h22M20 372h26" stroke="#fff1d6" stroke-width="2.2" opacity=".9"/><path d="M22 384l5-6 5 6 5-6 5 6" stroke="#f4c95d" stroke-width="2.2" fill="none"/>';
  s+='<path d="M508 412l-4-34h44l-4 34z" fill="#c0583a"/><path d="M526 380q-22-10-20-34q18 6 20 34zM526 380q22-12 18-36q-18 8-18 36z" fill="#6f9a62"/>';
  s+='<circle cx="526" cy="342" r="7" fill="#f4c95d"/><circle cx="508" cy="354" r="6" fill="#f2a3a3"/><circle cx="545" cy="356" r="6" fill="#fff1d6"/>';
  s+='</g>';
  s+='<g class="swing"><path d="M386 306v14" stroke="#3b2a20" stroke-width="2.5"/><rect x="368" y="320" width="36" height="22" rx="5" fill="#f4c95d" stroke="#3b2a20" stroke-width="2.5"/><text x="386" y="335" text-anchor="middle" font-family="cursive" font-size="10" font-weight="700" fill="#3b2a20">OPEN</text></g>';
  s+='<g fill="#fffaf0" stroke="#3b2a20" stroke-width="2.5">'+[0,1.3,2.6].map(function(d,k){return '<circle class="steam" style="animation-delay:'+d+'s" cx="'+(422+k*4)+'" cy="66" r="'+(8+k)+'"/>'}).join('')+'</g>';
  s+='</svg>';
  return s;
}
$('#heroArt').innerHTML=heroSVG();

/* ---------- opening hours ---------- */
var DAYS=['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
var HOURS=[[480,840],null,[420,1020],[420,1020],[420,1020],[420,1020],[450,960]];
function tfmt(m){var h=Math.floor(m/60),mm=m%60,ap=h>=12?'pm':'am',h12=h%12||12;return h12+(mm?':'+(mm<10?'0':'')+mm:'')+' '+ap}
function liveStatus(d){
  var day=d.getDay(),m=d.getHours()*60+d.getMinutes(),h=HOURS[day],k;
  if(h&&m>=h[0]&&m<h[1]){
    var left=h[1]-m;
    return left<=30?{state:'soon',title:'Closing soon',sub:'closes at '+tfmt(h[1])}:{state:'open',title:'Open now',sub:'until '+tfmt(h[1])};
  }
  for(k=0;k<8;k++){
    var dd=(day+k)%7,hh=HOURS[dd];
    if(!hh)continue;
    if(k===0&&m>=hh[0])continue;
    var when=k===0?'today':(k===1?'tomorrow':DAYS[dd]);
    return {state:'closed',title:'Closed',sub:'opens '+when+' at '+tfmt(hh[0])};
  }
  return {state:'closed',title:'Closed',sub:''};
}
function renderHours(){
  var d=new Date(),st=liveStatus(d);
  $$('[data-live]').forEach(function(b){b.setAttribute('data-state',st.state);$('[data-live-title]',b).textContent=st.title;$('[data-live-sub]',b).textContent=st.sub});
  var rows='',order=[1,2,3,4,5,6,0];
  order.forEach(function(di){var h=HOURS[di];rows+='<tr'+(di===d.getDay()?' class="today" aria-current="date"':'')+'><th scope="row">'+DAYS[di]+'</th><td>'+(h?tfmt(h[0])+' &ndash; '+tfmt(h[1]):'Closed')+'</td></tr>'});
  var tb=$('#hrs tbody');if(tb.getAttribute('data-d')!==String(d.getDay())){tb.innerHTML=rows;tb.setAttribute('data-d',String(d.getDay()))}
}
renderHours();setInterval(renderHours,30000);

/* ---------- helpers ---------- */
function count(){return state.slots.filter(Boolean).length}
function subtotal(){return state.slots.reduce(function(a,id){return a+(id?BYID[id].price:0)},0)}
function isFull(){return count()===state.size}
function discount(){return isFull()?Math.round(subtotal()*DISCOUNT*100)/100:0}
function matches(p){return Object.keys(state.filters).every(function(k){return !state.filters[k]||p.tags.indexOf(k)>-1})}
function art(sym,cls){return '<svg viewBox="0 0 100 100" aria-hidden="true"'+(cls?' class="'+cls+'"':'')+'><use href="#'+sym+'"/></svg>'}
function chipsFor(p){var h=p.tags.map(function(t){return '<span class="chip">'+TAGNAME[t]+'</span>'}).join('');if(p.tags.indexOf('nutfree')<0)h+='<span class="chip warn">Contains nuts</span>';return h}

/* ---------- today's bakes + picker ---------- */
$('#bakes').innerHTML=PASTRIES.map(function(p){
  var tilt=((rnd()-.5)*8).toFixed(1);
  return '<article class="bake" role="listitem" style="--tilt:'+tilt+'deg"><div class="bake-art">'+art(p.sym)+'</div><h3>'+p.name+'</h3><p>'+p.desc+'</p><div class="chips">'+chipsFor(p)+'</div><div class="bake-foot"><span class="price">'+fmt(p.price)+'</span><span class="when">out at '+p.time+'</span><button class="btn small" type="button" data-add="'+p.id+'" aria-label="Add '+p.name+' to your box">Add to box</button></div></article>';
}).join('');
$('#picker').innerHTML=PASTRIES.map(function(p){
  return '<button class="pcard" type="button" data-pastry="'+p.id+'" aria-label="Add '+p.name+', '+fmt(p.price)+'"><span class="pc-badge" hidden></span>'+art(p.sym)+'<span class="pc-name">'+p.name+'</span><span class="pc-price">'+fmt(p.price)+'</span><span class="pc-tags">'+p.tags.map(function(t){return '<i title="'+TAGNAME[t]+'">'+TAGSHORT[t]+'</i>'}).join('')+'</span></button>';
}).join('');

/* ---------- size buttons ---------- */
function miniBox(sz){
  var c='',i,cs=9,gap=3,W=sz.cols*(cs+gap)+gap,H=sz.rows*(cs+gap)+gap;
  for(i=0;i<sz.n;i++){var cx=gap+(i%sz.cols)*(cs+gap),cy=gap+Math.floor(i/sz.cols)*(cs+gap);c+='<rect x="'+cx+'" y="'+cy+'" width="'+cs+'" height="'+cs+'" rx="3" fill="#f6e5c6"/>'}
  return '<svg viewBox="0 0 '+W+' '+H+'" aria-hidden="true"><rect x=".75" y=".75" width="'+(W-1.5)+'" height="'+(H-1.5)+'" rx="5" fill="#d4a574" stroke="currentColor" stroke-width="1.5"/>'+c+'</svg>';
}
$('#sizes').innerHTML=SIZES.map(function(z){return '<button class="sizebtn" type="button" data-size="'+z.n+'" aria-pressed="'+(z.n===state.size)+'">'+miniBox(z)+'<span><b>Box of '+z.n+'</b><span>'+z.label+'</span></span></button>'}).join('');

/* ---------- box rendering ---------- */
var CELL=84,PAD=22,NS='http://www.w3.org/2000/svg';
function layout(){return SIZES.filter(function(z){return z.n===state.size})[0]}
function buildBox(){
  var L=layout(),W=L.cols*CELL+PAD*2,H=L.rows*CELL+PAD*2,svg=$('#boxSvg'),s='',i;
  svg.setAttribute('viewBox','0 0 '+W+' '+H);
  svg.setAttribute('aria-label','Pastry box for '+state.size+', '+count()+' filled');
  s+='<rect x="3" y="6" width="'+(W-6)+'" height="'+(H-6)+'" rx="20" fill="rgba(60,30,10,.18)"/>';
  s+='<rect x="3" y="3" width="'+(W-6)+'" height="'+(H-6)+'" rx="20" fill="#e1b985" stroke="#3b2a20" stroke-width="3"/>';
  s+='<rect x="12" y="12" width="'+(W-24)+'" height="'+(H-24)+'" rx="12" fill="#b9854f" stroke="#3b2a20" stroke-width="2.5"/>';
  s+='<path d="M10 '+(H-8)+'" />';
  for(i=0;i<state.size;i++){
    var cx=PAD+(i%L.cols)*CELL,cy=PAD+Math.floor(i/L.cols)*CELL;
    s+='<g class="slot" data-slot="'+i+'" transform="translate('+cx+','+cy+')"><rect class="cell" x="3" y="3" width="'+(CELL-6)+'" height="'+(CELL-6)+'" rx="16"/><text class="num" x="'+(CELL/2)+'" y="'+(CELL/2+7)+'">'+(i+1)+'</text><g class="content"></g><rect class="hit" width="'+CELL+'" height="'+CELL+'"/></g>';
  }
  s+='<g id="sparks"></g>';
  svg.innerHTML=s;
  for(i=0;i<state.size;i++)paintSlot(i,false);
  markNext();
}
function paintSlot(i,animate){
  var g=$('#boxSvg .slot[data-slot="'+i+'"]');if(!g)return;
  var id=state.slots[i],c=$('.content',g);
  if(!id){g.classList.remove('filled');g.removeAttribute('role');g.removeAttribute('tabindex');g.removeAttribute('aria-label');c.innerHTML='';return}
  var p=BYID[id];
  g.classList.add('filled');g.setAttribute('role','button');g.setAttribute('tabindex','0');g.setAttribute('aria-label','Remove '+p.name+' from slot '+(i+1));
  c.innerHTML='<g class="bounce'+(animate?' pop':'')+'"><ellipse cx="42" cy="68" rx="26" ry="5" fill="rgba(60,30,10,.18)"/><circle cx="42" cy="42" r="34" fill="#fffaf0" stroke="#e4cfa6" stroke-width="2"/><circle cx="42" cy="42" r="28" fill="none" stroke="#f0dfbd" stroke-width="2" stroke-dasharray="3 4"/><use href="#'+p.sym+'" x="9" y="8" width="66" height="66"/><g class="rm" transform="translate(68,15)"><circle r="9"/><path d="M-3.4 -3.4L3.4 3.4M3.4 -3.4L-3.4 3.4"/></g></g>';
}
function markNext(){
  var n=state.slots.indexOf(null);
  $$('#boxSvg .slot').forEach(function(g,i){g.classList.toggle('next',i===n)});
}
function burst(){
  var L=layout(),W=L.cols*CELL+PAD*2,H=L.rows*CELL+PAD*2,g=$('#sparks'),s='',i;
  if(!g)return;
  for(i=0;i<10;i++){var x=(12+rnd()*(W-24)).toFixed(0),y=(12+rnd()*(H-24)).toFixed(0);
    s+='<path class="spark" style="animation-delay:'+(i*0.05).toFixed(2)+'s" d="M'+x+' '+(y-8)+'v16M'+(x-8)+' '+y+'h16" stroke="#f4c95d" stroke-width="4" stroke-linecap="round"/>';}
  g.innerHTML=s;setTimeout(function(){if(g)g.innerHTML=''},1400);
}

/* ---------- actions ---------- */
function add(id){
  var p=BYID[id];
  if(!matches(p)){toast(p.name+' does not match your filters.');sfx.nope();return false}
  var i=state.slots.indexOf(null);
  if(i<0){toast('Box is full. Tap an item to remove it, or pick a bigger box.');sfx.nope();var w=$('#boxSvg');w.classList.remove('shake');void w.getBoundingClientRect();w.classList.add('shake');return false}
  state.slots[i]=id;lastAdded=i;
  paintSlot(i,true);markNext();
  var card=$('.pcard[data-pastry="'+id+'"]');if(card){card.classList.remove('added');void card.offsetWidth;card.classList.add('added')}
  if(isFull()){sfx.full();burst();toast('Box full! Ready for checkout.')}else{sfx.add()}
  updateUI();return true;
}
function removeAt(i){
  if(!state.slots[i])return;
  var g=$('#boxSvg .slot[data-slot="'+i+'"]'),b=g&&$('.bounce',g);
  state.slots[i]=null;sfx.remove();
  if(b){b.classList.remove('pop');b.classList.add('out');setTimeout(function(){if(!state.slots[i])paintSlot(i,false)},170)}else paintSlot(i,false);
  markNext();updateUI();
}
function setSize(n,silent){
  if(n===state.size)return;
  var kept=state.slots.filter(Boolean),dropped=Math.max(0,kept.length-n);
  kept=kept.slice(0,n);
  state.size=n;state.slots=[];
  for(var i=0;i<n;i++)state.slots.push(kept[i]||null);
  $$('.sizebtn').forEach(function(b){b.setAttribute('aria-pressed',String(+b.getAttribute('data-size')===n))});
  buildBox();updateUI();sfx.tick();
  if(dropped&&!silent)toast(dropped+' pastr'+(dropped>1?'ies were':'y was')+' removed to fit the smaller box.');
}
function resetAll(){
  state.filters={vegan:false,nutfree:false,gf:false};
  $$('.fchip').forEach(function(b){b.setAttribute('aria-pressed','false')});
  state.size=6;state.slots=[null,null,null,null,null,null];
  $$('.sizebtn').forEach(function(b){b.setAttribute('aria-pressed',String(+b.getAttribute('data-size')===6))});
  buildBox();updateUI();
}

function updateUI(){
  var n=count(),sub=subtotal(),d=discount(),full=isFull();
  $('#count').textContent=n+' / '+state.size;
  $('#total').textContent=fmt(sub-d);
  $('#saveNote').textContent=full?('Full box, 10% off: -'+fmt(d)):(n?('Fill '+(state.size-n)+' more for 10% off'):'Fill the box for 10% off');
  var cb=$('#checkoutBtn');cb.setAttribute('aria-disabled',String(n===0));cb.classList.toggle('pulse',full);
  $('#boxSvg').setAttribute('aria-label','Pastry box for '+state.size+', '+n+' filled');
  var shown=0;
  PASTRIES.forEach(function(p){
    var c=$('.pcard[data-pastry="'+p.id+'"]'),m=matches(p),k=state.slots.filter(function(x){return x===p.id}).length,bd=$('.pc-badge',c);
    if(m)shown++;
    c.classList.toggle('dim',!m);c.classList.toggle('full',full);
    c.setAttribute('aria-disabled',String(!m));
    bd.hidden=!k;bd.textContent='×'+k;
  });
  $('#showing').textContent=(Object.keys(state.filters).some(function(k){return state.filters[k]}))?('Showing '+shown+' of '+PASTRIES.length):'';
  updateJump();
}

/* ---------- jump pill ---------- */
var buildVisible=true;
function updateJump(){
  var j=$('#jump'),n=count(),open=$('#drawer').classList.contains('open');
  var show=n>0&&!buildVisible&&!open;
  j.classList.toggle('show',show);
  $('#jumpTxt').textContent='Your box '+n+'/'+state.size+' · '+fmt(subtotal()-discount());
}
try{
  var io=new IntersectionObserver(function(es){es.forEach(function(e){buildVisible=e.isIntersecting;updateJump()})},{threshold:0.05});
  io.observe($('#build'));
}catch(x){}
$('#jump').addEventListener('click',function(){$('#build').scrollIntoView({behavior:'smooth',block:'start'})});

/* ---------- drawer ---------- */
var lastFocus=null;
function renderDrawer(){
  var counts={},order=[];
  state.slots.forEach(function(id){if(!id)return;if(!counts[id]){counts[id]=0;order.push(id)}counts[id]++});
  var z=layout(),sub=subtotal(),d=discount(),nuts=order.some(function(id){return BYID[id].tags.indexOf('nutfree')<0});
  var mini=state.slots.map(function(id){return id?art(BYID[id].sym):'<span class="empty"></span>'}).join('');
  var lines=order.map(function(id){var p=BYID[id],k=counts[id];return '<li>'+art(p.sym)+'<span class="nm">'+p.name+'<small>'+k+' × '+fmt(p.price)+'</small></span><span class="pr">'+fmt(p.price*k)+'</span></li>'}).join('');
  var notes=[];
  notes.push(nuts?'Contains tree nuts.':'No tree nuts in this box.');
  if(order.every(function(id){return BYID[id].tags.indexOf('vegan')>-1}))notes.push('All vegan.');
  if(order.every(function(id){return BYID[id].tags.indexOf('gf')>-1}))notes.push('All gluten-free.');
  $('#drawerBody').innerHTML='<p style="margin:0 0 10px;color:var(--ink2)">Box of '+z.n+' &middot; '+z.label+' &middot; '+count()+' of '+state.size+' filled</p><div class="mini-box" aria-hidden="true">'+mini+'</div><ul class="lines">'+lines+'</ul><div class="sum"><div><span>Subtotal</span><span>'+fmt(sub)+'</span></div>'+(d?'<div class="disc"><span>Full-box discount (10%)</span><span>-'+fmt(d)+'</span></div>':'')+'<div class="grand"><span>Total</span><span>'+fmt(sub-d)+'</span></div></div><p class="note">'+notes.join(' ')+' This is a summary only: nothing is sent and no payment is taken here. Show it at the counter on Wick Lane.</p>';
}
function openDrawer(){
  if(count()===0){toast('Add a pastry first.');sfx.nope();return}
  renderDrawer();
  var dr=$('#drawer');lastFocus=document.activeElement;
  dr.classList.add('open');dr.setAttribute('aria-hidden','false');
  try{$('main').inert=true;$('header.top').inert=true;$('footer').inert=true}catch(x){}
  sfx.open();updateJump();
  setTimeout(function(){try{$('#drawerClose').focus({preventScroll:true})}catch(x){}},60);
}
function closeDrawer(){
  var dr=$('#drawer');if(!dr.classList.contains('open'))return;
  dr.classList.remove('open');dr.setAttribute('aria-hidden','true');
  try{$('main').inert=false;$('header.top').inert=false;$('footer').inert=false}catch(x){}
  updateJump();
  try{if(lastFocus&&lastFocus.focus&&!demo.on)lastFocus.focus({preventScroll:true})}catch(x){}
}
$('#checkoutBtn').addEventListener('click',openDrawer);
$('#drawerClose').addEventListener('click',closeDrawer);
$('#keepBtn').addEventListener('click',closeDrawer);
$('#scrim').addEventListener('click',closeDrawer);
$('#newBtn').addEventListener('click',function(){closeDrawer();resetAll();toast('Fresh box, ready to fill.')});
document.addEventListener('keydown',function(e){
  var dr=$('#drawer');
  if(!dr.classList.contains('open'))return;
  if(e.key==='Escape'){closeDrawer();return}
  if(e.key==='Tab'){
    var f=$$('button',$('#sheet')).filter(function(b){return b.offsetParent!==null});
    if(!f.length)return;
    var first=f[0],last=f[f.length-1];
    if(e.shiftKey&&document.activeElement===first){e.preventDefault();last.focus()}
    else if(!e.shiftKey&&document.activeElement===last){e.preventDefault();first.focus()}
  }
});

/* ---------- wiring ---------- */
$('#picker').addEventListener('click',function(e){var c=e.target.closest('.pcard');if(c)add(c.getAttribute('data-pastry'))});
$('#bakes').addEventListener('click',function(e){var b=e.target.closest('[data-add]');if(!b)return;if(add(b.getAttribute('data-add'))&&!isFull()){toast('Added to your box ('+count()+'/'+state.size+')')}});
$('#sizes').addEventListener('click',function(e){var b=e.target.closest('.sizebtn');if(b)setSize(+b.getAttribute('data-size'))});
$$('.fchip').forEach(function(b){b.addEventListener('click',function(){
  var k=b.getAttribute('data-filter');state.filters[k]=!state.filters[k];b.setAttribute('aria-pressed',String(state.filters[k]));sfx.tick();updateUI();
})});
$('#boxSvg').addEventListener('click',function(e){var g=e.target.closest('.slot');if(g&&g.classList.contains('filled'))removeAt(+g.getAttribute('data-slot'))});
$('#boxSvg').addEventListener('keydown',function(e){
  var g=e.target.closest&&e.target.closest('.slot');
  if(g&&(e.key==='Enter'||e.key===' ')&&g.classList.contains('filled')){e.preventDefault();removeAt(+g.getAttribute('data-slot'))}
});
$('#checkoutBtn').addEventListener('keydown',function(){});
$('#resetBtn').addEventListener('click',function(){resetAll();toast('Box cleared.');sfx.remove()});
$('#restartBtn').addEventListener('click',function(){resetAll();window.scrollTo({top:0,behavior:'smooth'})});

/* ---------- adaptive quality ---------- */
(function(){
  var last=performance.now(),n=0,sum=0,slow=0,rounds=0;
  function f(t){
    var d=t-last;last=t;
    if(d<250){n++;sum+=d;if(d>38)slow++}
    if(n>=50){
      if(sum/n>26||slow>14)document.documentElement.classList.add('lowfx');
      n=0;sum=0;slow=0;rounds++;
    }
    if(rounds<5)requestAnimationFrame(f);
  }
  requestAnimationFrame(f);
})();

/* ---------- demo mode ---------- */
var demo={on:false,run:0};
function demoTarget(sel){return typeof sel==='string'?$(sel):sel}
async function demoTap(ok,sel,after){
  var el=demoTarget(sel);if(!el||!ok())return;
  var panel=$('#boxPanel'),ptr=$('#demoPtr'),r=el.getBoundingClientRect();
  if(!panel.contains(el)){
    var lim=window.innerWidth<900?panel.getBoundingClientRect().bottom+8:76;
    if(r.top<lim||r.bottom>window.innerHeight-12){
      window.scrollBy({top:r.top-(lim+(window.innerHeight-lim)*0.4),behavior:'smooth'});
      await sleep(800);if(!ok())return;
      r=el.getBoundingClientRect();
    }
  }
  ptr.style.transform='translate('+(r.left+r.width/2)+'px,'+(r.top+r.height/2)+'px)';
  await sleep(600);if(!ok())return;
  ptr.classList.remove('tap');void ptr.getBoundingClientRect();ptr.classList.add('tap');
  el.click();
  await sleep(after||600);
}
async function demoCycle(ok){
  closeDrawer();resetAll();
  window.scrollTo({top:0,behavior:'instant'});
  await sleep(600);if(!ok())return;
  await demoTap(ok,'#heroCta',1400);
  await demoTap(ok,'.sizebtn[data-size="12"]',600);
  await demoTap(ok,'.sizebtn[data-size="6"]',500);
  var ids=['croissant','swirl','tart'];
  for(var i=0;i<ids.length;i++)await demoTap(ok,'.pcard[data-pastry="'+ids[i]+'"]',400);
  await demoTap(ok,'.fchip[data-filter="vegan"]',800);
  await demoTap(ok,'.pcard[data-pastry="cookie"]',400);
  await demoTap(ok,'.pcard[data-pastry="swirl"]',400);
  await demoTap(ok,'.fchip[data-filter="vegan"]',500);
  await demoTap(ok,'#boxSvg .slot[data-slot="2"]',600);
  await demoTap(ok,'.pcard[data-pastry="brownie"]',400);
  await demoTap(ok,'.pcard[data-pastry="bar"]',900);
  await demoTap(ok,'#checkoutBtn',2600);
  await demoTap(ok,'#drawerClose',700);
  if(!ok())return;
  $('#hours').scrollIntoView({behavior:'smooth',block:'start'});
  await sleep(1500);
}
function endDemo(e){
  if(e&&e.isTrusted===false)return;
  if(!demo.on)return;
  demo.on=false;document.body.classList.remove('demo');
  ['pointerdown','keydown','wheel','touchstart'].forEach(function(t){window.removeEventListener(t,endDemo,true)});
}
async function startDemo(){
  var id=++demo.run;demo.on=true;document.body.classList.add('demo');
  var ptr=$('#demoPtr');
  ptr.style.transition='none';ptr.style.transform='translate('+(window.innerWidth*0.6)+'px,'+(window.innerHeight*0.55)+'px)';
  void ptr.getBoundingClientRect();ptr.style.transition='';
  ['pointerdown','keydown','wheel','touchstart'].forEach(function(t){window.addEventListener(t,endDemo,{capture:true,passive:true})});
  var ok=function(){return demo.on&&demo.run===id};
  while(ok()){try{await demoCycle(ok)}catch(x){await sleep(500)}}
}

/* ---------- boot ---------- */
buildBox();updateUI();updateSoundBtn();
requestAnimationFrame(function(){requestAnimationFrame(function(){
  try{parent.postMessage({vcb:'ready'},'*')}catch(x){}
  if(/#demo$/.test(location.href))setTimeout(startDemo,400);
})});
})();
</script>
</body>
</html>