Skip to content
VibeCodeBench
Back to the app

The code

Build-a-Box Bakery by Claude Opus 5.5

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

Try 1 · index.html

worksshown85.0 KB · 1,276 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>Hollow Oak Bakehouse</title>
<meta name="description" content="Hollow Oak Bakehouse, a small neighbourhood bakery on Marigold Lane. See today's bakes, build your own pastry box and check if we're open.">
<style>
:root{
  --cream:#fbf3e6; --paper:#fffaf2; --ink:#3b2416; --ink2:#6e5240; --line:#ead9bf;
  --crust:#c8553d; --crust2:#a9402b; --sage:#3e5b41; --sage2:#2e4631; --butter:#f2c46b;
  --kraft:#dcb482; --kraft2:#c49460; --ok:#2f7a4a; --warn:#c07a12; --shut:#b2412f;
  --serif:"Iowan Old Style","Palatino Linotype",Palatino,"Book Antiqua",Georgia,serif;
  --sans:system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
  color-scheme:light;
}
*{box-sizing:border-box}
[hidden]{display:none!important}
html{scroll-behavior:smooth;-webkit-text-size-adjust:100%}
body{margin:0;font-family:var(--sans);color:var(--ink);background:var(--cream);
  background-image:radial-gradient(rgba(59,36,22,.055) 1px,transparent 1.3px);background-size:22px 22px;
  line-height:1.5;overflow-x:hidden}
body.locked{overflow:hidden}
button{font:inherit;color:inherit;cursor:pointer;-webkit-tap-highlight-color:transparent;touch-action:manipulation}
:focus-visible{outline:3px solid #2b6fd6;outline-offset:2px}
.wrap{max-width:1160px;margin:0 auto;padding:0 20px}
h1,h2,h3{font-family:var(--serif);line-height:1.08;margin:0;letter-spacing:-.01em}
section{scroll-margin-top:70px}
.kicker,.eyebrow{display:inline-flex;gap:8px;align-items:center;font-size:12.5px;font-weight:800;letter-spacing:.16em;text-transform:uppercase;color:var(--crust2)}

/* buttons */
.btn{min-height:46px;padding:0 20px;border-radius:999px;border:2px solid var(--ink);background:var(--paper);font-weight:700;
  display:inline-flex;align-items:center;justify-content:center;gap:8px;transition:transform .12s,box-shadow .12s,background .2s,opacity .2s;
  box-shadow:0 3px 0 var(--ink);white-space:nowrap;user-select:none;-webkit-user-select:none}
.btn.pressing{transform:translateY(2px);box-shadow:0 1px 0 var(--ink)}
.btn.primary{background:var(--crust);color:#fff8ee}
.btn.sage{background:var(--sage);color:#fff8ee}
.btn.small{min-height:44px;padding:0 14px;font-size:14px}
.btn[disabled]{opacity:.45;cursor:not-allowed;box-shadow:0 3px 0 var(--ink);transform:none}
.icon-btn{width:44px;height:44px;border-radius:50%;border:2px solid var(--ink);background:var(--paper);display:grid;place-items:center;padding:0;transition:transform .12s}
.icon-btn.pressing{transform:scale(.92)}

/* header */
.top{position:sticky;top:0;z-index:40;background:rgba(251,243,230,.9);-webkit-backdrop-filter:blur(10px);backdrop-filter:blur(10px);border-bottom:1px solid var(--line)}
.top-in{display:flex;align-items:center;gap:14px;height:64px}
.brand{display:flex;align-items:center;gap:10px;background:none;border:0;padding:0;min-height:44px;text-align:left}
.brand b{font-family:var(--serif);font-size:20px;display:block;line-height:1}
.brand small{display:block;font-size:10.5px;letter-spacing:.2em;text-transform:uppercase;color:var(--ink2);margin-top:3px}
.nav{display:flex;gap:2px;margin-left:auto}
.nav button{background:none;border:0;padding:0 14px;min-height:44px;border-radius:999px;font-weight:650;color:var(--ink2)}
.nav button.pressing{background:rgba(59,36,22,.08)}
.top-actions{display:flex;align-items:center;gap:8px}
.top-status{display:inline-flex;align-items:center;gap:7px;font-size:13px;font-weight:700;padding:0 10px;color:var(--ink2)}
.cart-btn{display:flex;align-items:center;gap:8px;min-height:44px;padding:0 14px 0 10px;border-radius:999px;border:2px solid var(--ink);background:var(--butter);font-weight:800;box-shadow:0 2px 0 var(--ink);transition:transform .12s}
.cart-btn.bump{animation:bump .45s}
.cart-btn.pressing{transform:translateY(2px)}
@media (max-width:860px){.nav,.top-status{display:none}.top-actions{margin-left:auto}}

/* hero */
.hero{padding:44px 0 28px}
.hero-grid{display:grid;grid-template-columns:1fr 1.08fr;gap:44px;align-items:center}
.hero h1{font-size:clamp(38px,5.3vw,64px);margin:14px 0 16px}
.hero h1 em{color:var(--crust);font-style:italic}
.lead{font-size:18px;color:var(--ink2);max-width:33em;margin:0}
.hero-cta{display:flex;flex-wrap:wrap;gap:12px;margin:26px 0 18px}
.pill{display:inline-flex;align-items:center;gap:9px;padding:9px 15px;border-radius:999px;background:var(--paper);border:1.5px solid var(--line);font-size:14px;font-weight:650}
.dot{width:10px;height:10px;border-radius:50%;background:var(--shut);box-shadow:0 0 0 3px rgba(178,65,47,.18);flex:none}
.dot.open{background:var(--ok);animation:breathe 2.2s ease-in-out infinite}
.dot.soon{background:var(--warn);box-shadow:0 0 0 3px rgba(192,122,18,.2)}
.facts{display:flex;flex-wrap:wrap;gap:22px;margin-top:22px;font-size:14px;color:var(--ink2)}
.facts b{display:block;font-family:var(--serif);font-size:24px;color:var(--ink);line-height:1.1}
.art-card{border-radius:30px;border:2px solid var(--ink);box-shadow:7px 7px 0 var(--ink);overflow:hidden;background:#fde8c8}
.shop{width:100%;height:auto;display:block}
.steam{fill:none;stroke:#fffdf8;stroke-width:6;stroke-linecap:round;opacity:0;transform-box:fill-box;transform-origin:50% 100%;animation:steam 3.6s ease-out infinite}
.steam.s2{animation-delay:1.2s}.steam.s3{animation-delay:2.4s}
.door-sign{transform-origin:454px 344px;animation:swing 4s ease-in-out infinite}
.cloud{animation:drift 14s ease-in-out infinite alternate}
.cloud.c2{animation-duration:19s}
.lowfx .rough{filter:none}
.lowfx .steam,.lowfx .cloud,.lowfx .door-sign,.lowfx .dot.open{animation:none}
.lowfx .steam{opacity:.6}
@media (max-width:880px){.hero-grid{grid-template-columns:1fr;gap:30px}.hero{padding-top:26px}}

/* story */
.story{padding:34px 0 10px}
.story-card{display:grid;grid-template-columns:170px 1fr;gap:30px;align-items:center;background:var(--paper);border:2px solid var(--ink);border-radius:26px;padding:30px;box-shadow:5px 5px 0 var(--ink)}
.stamp-badge{width:150px;height:150px;border-radius:50%;border:3px dashed var(--crust);display:grid;place-items:center;text-align:center;transform:rotate(-8deg);color:var(--crust2);font-family:var(--serif)}
.stamp-badge b{display:block;font-size:44px;line-height:1}
.stamp-badge span{font-size:12px;letter-spacing:.2em;text-transform:uppercase;font-family:var(--sans);font-weight:800}
.story-card h2{font-size:clamp(28px,3.4vw,38px);margin-bottom:10px}
.story-card p{margin:0 0 10px;color:var(--ink2)}
.sig{font-family:var(--serif);font-style:italic;font-size:19px;color:var(--ink)!important}
@media (max-width:640px){.story-card{grid-template-columns:1fr;padding:22px;gap:14px}.stamp-badge{width:110px;height:110px}.stamp-badge b{font-size:32px}}

/* sections */
.sec{padding:60px 0}
.sec-head{margin-bottom:26px}
.sec-head h2{font-size:clamp(32px,4.2vw,46px);margin-top:6px}
.sec-head p{margin:8px 0 0;color:var(--ink2);max-width:40em;font-size:16.5px}

/* bakes */
.bakes{display:grid;grid-template-columns:repeat(auto-fill,minmax(232px,1fr));gap:18px}
.card{background:var(--paper);border:2px solid var(--ink);border-radius:22px;padding:14px;display:flex;flex-direction:column;gap:8px;box-shadow:4px 4px 0 var(--ink)}
.card-art{position:relative;aspect-ratio:4/3;border-radius:15px;display:grid;place-items:center;background:var(--bg);border:1.5px solid rgba(59,36,22,.12)}
.card-art svg{width:60%;height:auto;filter:drop-shadow(0 3px 0 rgba(59,36,22,.12))}
.oven{position:absolute;left:8px;bottom:8px;font-size:11.5px;font-weight:700;background:rgba(255,250,242,.9);border-radius:999px;padding:3px 9px;color:var(--ink2)}
.card h3{font-size:21px;margin-top:4px}
.desc{font-size:14.5px;color:var(--ink2);margin:0;flex:1}
.tags{display:flex;gap:6px;flex-wrap:wrap;align-items:center}
.tag{font-size:11px;font-weight:800;letter-spacing:.05em;padding:3px 9px;border-radius:999px;background:#e9f1e2;color:var(--sage2);border:1px solid #c7d9bb}
.contains{font-size:11.5px;color:var(--ink2);font-style:italic}
.card-foot{display:flex;align-items:center;justify-content:space-between;gap:8px;margin-top:4px}
.price{font-weight:800;font-size:18px}
@media (max-width:560px){
  .bakes{grid-template-columns:1fr 1fr;gap:12px}
  .card{padding:10px;border-radius:18px;box-shadow:3px 3px 0 var(--ink);gap:6px}
  .card h3{font-size:16.5px}
  .desc{font-size:13px;display:-webkit-box;-webkit-line-clamp:3;-webkit-box-orient:vertical;overflow:hidden}
  .card-foot{flex-direction:column;align-items:stretch}
  .card .btn{width:100%;padding:0 8px}
  .oven{font-size:10px}
}

/* builder */
#build{background:linear-gradient(180deg,rgba(242,196,107,.0),rgba(242,196,107,.16) 20%,rgba(242,196,107,.16) 80%,rgba(242,196,107,0))}
.builder{display:grid;grid-template-columns:minmax(0,1fr) minmax(340px,440px);grid-template-areas:"ctl box" "pal box";gap:22px 28px;align-items:start}
.ctl{grid-area:ctl}.pal{grid-area:pal}.box-col{grid-area:box;position:sticky;top:82px}
.panel{background:var(--paper);border:2px solid var(--ink);border-radius:24px;padding:20px;box-shadow:5px 5px 0 var(--ink)}
.ctl-label{font-size:12px;font-weight:800;letter-spacing:.14em;text-transform:uppercase;color:var(--ink2);margin:0 0 10px}
.ctl-row{display:flex;align-items:center;justify-content:space-between;gap:10px;flex-wrap:wrap;margin-bottom:10px}
.ctl-row .ctl-label{margin:0}
.sizes{display:grid;grid-template-columns:repeat(3,1fr);gap:10px;margin-bottom:20px}
.size-btn{min-height:66px;border-radius:16px;border:2px solid var(--ink);background:#fff;display:flex;align-items:center;justify-content:center;gap:10px;padding:8px;transition:background .2s,color .2s,transform .12s;text-align:left}
.size-btn b{font-family:var(--serif);font-size:26px;line-height:1;display:block}
.size-btn small{display:block;font-size:11.5px;color:var(--ink2);font-weight:650;line-height:1.2}
.size-btn[aria-pressed="true"]{background:var(--ink);color:#fff6ea}
.size-btn[aria-pressed="true"] small{color:#e8d6c0}
.size-btn.pressing{transform:scale(.96)}
.filters{display:flex;flex-wrap:wrap;gap:8px}
.chip{min-height:44px;padding:0 15px 0 11px;border-radius:999px;border:2px solid var(--ink);background:#fff;display:inline-flex;align-items:center;gap:7px;font-weight:700;font-size:14px;transition:background .2s,color .2s,transform .12s}
.chip[aria-pressed="true"]{background:var(--sage);color:#fff}
.chip.pressing{transform:scale(.95)}
.match-count{font-size:13px;color:var(--ink2);font-weight:600}
.palette{display:grid;grid-template-columns:repeat(auto-fill,minmax(112px,1fr));gap:10px}
.pick{position:relative;border:2px solid var(--ink);border-radius:18px;background:#fff;padding:10px 6px 10px;display:flex;flex-direction:column;align-items:center;gap:2px;min-height:44px;
  transition:opacity .3s,filter .3s,transform .14s,box-shadow .14s;text-align:center;box-shadow:0 3px 0 var(--ink);user-select:none;-webkit-user-select:none}
.pick svg{width:72%;max-width:84px;height:auto;aspect-ratio:1;filter:drop-shadow(0 2px 0 rgba(59,36,22,.12))}
.pick .nm{font-size:13px;font-weight:750;line-height:1.15}
.pick .pr{font-size:12.5px;color:var(--ink2);font-weight:650}
.pick .badges{position:absolute;top:6px;right:6px;display:flex;gap:2px}
.pick .badges i{font-style:normal;font-size:9px;font-weight:800;background:#e9f1e2;color:var(--sage2);border-radius:6px;padding:1px 4px}
.pick .qty{position:absolute;top:6px;left:6px;min-width:22px;height:22px;padding:0 6px;border-radius:999px;background:var(--crust);color:#fff;font-size:12px;font-weight:800;display:grid;place-items:center}
.pick.pressing{transform:translateY(2px) scale(.97);box-shadow:0 1px 0 var(--ink)}
.pick.dim{opacity:.3;filter:grayscale(.9)}
.pick.wiggle{animation:wiggle .4s}

.box-panel{padding:18px 18px 20px}
.box-stage{position:relative;padding:4px 2px 0}
.lid{height:62px;margin:0 7%;background:linear-gradient(180deg,#ead0a2,#dcb482);border:3px solid var(--ink);border-bottom:0;border-radius:16px 16px 0 0;
  transform:perspective(380px) rotateX(40deg);transform-origin:50% 100%;display:grid;place-items:center}
.sticker{width:50px;height:50px;border-radius:50%;background:var(--crust);border:2.5px solid var(--ink);display:grid;place-items:center;box-shadow:0 2px 0 rgba(59,36,22,.25)}
.lid.happy .sticker{animation:wiggle .5s 2}
.box{background:var(--kraft2);border:3px solid var(--ink);border-radius:12px;padding:12px 12px 6px;box-shadow:0 16px 22px -14px rgba(59,36,22,.7),inset 0 0 0 3px rgba(255,255,255,.14)}
.box.shake{animation:shake .45s}
.floor{display:grid;grid-template-columns:repeat(var(--cols,3),1fr);gap:6px;padding:8px;background:var(--kraft);border-radius:6px;box-shadow:inset 0 5px 10px rgba(80,45,15,.35);border:2px solid rgba(59,36,22,.55)}
.floor.settle{animation:settle .4s ease-out}
.stamp{text-align:center;font-size:10px;font-weight:800;letter-spacing:.24em;text-transform:uppercase;color:rgba(59,36,22,.6);padding-top:5px}
.slot{position:relative;aspect-ratio:1;border:0;padding:0;background:transparent;border-radius:8px;min-width:44px;min-height:44px}
.slot::before{content:"";position:absolute;inset:0;border-radius:7px;box-shadow:inset 0 0 0 1.5px rgba(80,45,15,.2)}
.slot .ring{position:absolute;inset:14%;border-radius:50%;border:2px dashed rgba(59,36,22,.33);display:grid;place-items:center;font-family:var(--serif);font-weight:700;color:rgba(59,36,22,.42);font-size:clamp(13px,2.4vw,18px);transition:opacity .25s,border-color .25s}
.slot.next .ring{border-color:var(--crust);color:var(--crust);animation:pulse 1.5s ease-in-out infinite}
.slot .liner{position:absolute;inset:4%;opacity:0;transform:scale(.6);transition:opacity .25s,transform .3s cubic-bezier(.3,1.4,.5,1)}
.slot .liner svg{width:100%;height:100%;display:block}
.slot.filled .liner{opacity:1;transform:none}
.slot.filled .ring{opacity:0;animation:none}
.slot .pz{position:absolute;inset:10%;pointer-events:none}
.slot .pz svg{width:100%;height:100%;display:block;filter:drop-shadow(0 2px 1.5px rgba(59,36,22,.35))}
.slot .pz.pop{animation:drop .6s ease-out both}
.slot .pz.out{animation:out .2s ease-in forwards}
.slot.filled{cursor:pointer}
.slot.filled.pressing .pz{transform:scale(.9)}
.slot.mismatch::after{content:"!";position:absolute;top:1px;right:1px;width:18px;height:18px;border-radius:50%;background:var(--warn);color:#fff;font-size:12px;font-weight:900;display:grid;place-items:center;border:1.5px solid var(--ink)}
.crumb{position:absolute;left:50%;top:55%;width:9px;height:9px;border-radius:3px;border:1.5px solid var(--ink);pointer-events:none;animation:burst .9s cubic-bezier(.2,.7,.4,1) forwards}

.box-info{margin-top:16px}
.fill-row{display:flex;justify-content:space-between;font-weight:800;margin-bottom:8px;font-size:15px}
.fill-row span:last-child{color:var(--ink2);font-weight:650}
.progress{height:12px;border-radius:99px;background:#efe1ca;overflow:hidden;border:1.5px solid var(--ink)}
.progress i{display:block;height:100%;width:0;background:repeating-linear-gradient(45deg,var(--crust) 0 8px,#da6c53 8px 16px);transition:width .45s cubic-bezier(.3,1.3,.5,1)}
.hint{font-size:14px;color:var(--ink2);min-height:1.5em;margin:10px 0 6px}
.warn-note{font-size:13px;color:#8a5308;background:#fdf0d6;border:1px solid #efd29a;border-radius:10px;padding:6px 10px;margin:0 0 8px}
.sum{border-top:2px dashed var(--line);padding-top:12px;margin-top:8px;display:grid;gap:4px}
.sum-row{display:flex;justify-content:space-between;font-size:15px}
.sum-row.save{color:var(--ok);font-weight:750}
.sum-row.total{font-size:24px;font-family:var(--serif);font-weight:700;margin-top:2px}
.box-actions{display:flex;gap:10px;margin-top:14px}
.box-actions .btn{flex:1;padding:0 12px}

@media (max-width:899px){
  .builder{grid-template-columns:1fr;grid-template-areas:"ctl" "box" "pal";gap:16px}
  .box-col{position:static}
  .box-panel{max-width:460px;margin:0 auto;width:100%}
  #build{padding-bottom:100px}
  .panel{padding:14px;border-radius:20px;box-shadow:4px 4px 0 var(--ink)}
  .palette{grid-template-columns:repeat(auto-fill,minmax(92px,1fr));gap:8px}
  .pick .nm{font-size:12px}
  .size-btn{flex-direction:column;gap:4px;text-align:center;min-height:76px}
  .size-btn small{font-size:10.5px}
}

/* mini bar (phones) */
.minibar{position:fixed;left:10px;right:10px;bottom:calc(10px + env(safe-area-inset-bottom));z-index:35;background:var(--ink);color:#fff6ea;border-radius:20px;padding:8px;display:none;align-items:center;gap:10px;
  box-shadow:0 14px 30px -8px rgba(0,0,0,.5);transform:translateY(150%);transition:transform .35s cubic-bezier(.3,1.2,.5,1)}
.minibar.show{transform:none}
.mb-view{flex:1;display:flex;align-items:center;gap:12px;background:none;border:0;color:inherit;text-align:left;min-height:44px;padding:0 6px}
.mb-dots{display:flex;flex-wrap:wrap;gap:4px;max-width:96px}
.mb-dots i{width:10px;height:10px;border-radius:50%;border:1.5px solid #e8d6c0}
.mb-dots i.on{background:var(--butter);border-color:var(--butter)}
.mb-dots i.new{animation:dotpop .45s}
.mb-total{line-height:1.15}
.mb-total span{font-size:12px;opacity:.8;display:block}
.mb-total strong{font-size:18px}
.minibar .btn{box-shadow:none;border-color:#fff6ea}
@media (max-width:899px){.minibar{display:flex}}

/* hours */
.hours-grid{display:grid;grid-template-columns:1.1fr 1fr;gap:24px;align-items:start}
.status-card{background:var(--sage);color:#fff7ea;border-radius:26px;border:2px solid var(--ink);padding:30px;box-shadow:5px 5px 0 var(--ink);position:relative;overflow:hidden;min-height:100%}
.status-card::after{content:"";position:absolute;right:-60px;bottom:-60px;width:200px;height:200px;border-radius:50%;border:24px solid rgba(255,255,255,.07)}
.badge{display:inline-flex;align-items:center;gap:10px;padding:10px 18px;border-radius:999px;font-weight:900;font-size:18px;background:#fff7ea;color:var(--shut);letter-spacing:.04em;border:2px solid var(--ink)}
.badge.open{color:var(--ok)}.badge.soon{color:var(--warn)}
.status-card h3{font-size:clamp(28px,3.4vw,36px);margin:20px 0 8px}
.status-card p{margin:0 0 8px;opacity:.92}
.status-card .clock{font-size:14px;opacity:.75}
.addr{margin-top:20px;padding-top:16px;border-top:1.5px dashed rgba(255,247,234,.3);font-size:15px}
.hours-list{list-style:none;margin:0;padding:8px 0;background:var(--paper);border:2px solid var(--ink);border-radius:26px;box-shadow:5px 5px 0 var(--ink)}
.hours-list li{display:flex;justify-content:space-between;align-items:center;gap:10px;padding:12px 22px;border-bottom:1px dashed var(--line);font-size:15.5px}
.hours-list li:last-child{border-bottom:0}
.hours-list li.today{background:#fdebc9;font-weight:800}
.hours-list .today-tag{font-size:10.5px;letter-spacing:.12em;text-transform:uppercase;background:var(--ink);color:#fff;border-radius:999px;padding:2px 8px;margin-left:8px;vertical-align:2px}
.hours-list .shut{color:var(--shut);font-weight:700}
@media (max-width:760px){.hours-grid{grid-template-columns:1fr}.status-card{padding:22px}.hours-list li{padding:11px 16px}}

/* footer */
footer{background:var(--ink);color:#f3e5d0;padding:52px 0 30px;margin-top:30px;position:relative}
footer::before{content:"";position:absolute;left:0;right:0;top:-12px;height:13px;background:radial-gradient(circle at 12px 13px,var(--ink) 12px,transparent 12.5px) repeat-x;background-size:24px 13px}
.foot-grid{display:grid;grid-template-columns:1.5fr 1fr 1fr;gap:28px}
footer h4{margin:0 0 10px;font-size:12px;letter-spacing:.16em;text-transform:uppercase;color:var(--butter)}
footer p{margin:0 0 6px;font-size:14.5px;opacity:.88}
.foot-brand{display:flex;gap:12px;align-items:center;margin-bottom:12px}
.foot-brand b{font-family:var(--serif);font-size:24px}
.foot-actions{display:flex;flex-wrap:wrap;gap:10px}
footer .btn{background:transparent;color:#fff6ea;border-color:#f3e5d0;box-shadow:0 3px 0 #f3e5d0}
footer .btn.pressing{box-shadow:0 1px 0 #f3e5d0}
.fine{font-size:12.5px;opacity:.65;margin-top:32px;border-top:1px solid rgba(255,255,255,.14);padding-top:16px;display:flex;justify-content:space-between;flex-wrap:wrap;gap:10px}
@media (max-width:760px){.foot-grid{grid-template-columns:1fr}}

/* drawer */
.scrim{position:fixed;inset:0;background:rgba(40,22,12,.48);opacity:0;pointer-events:none;transition:opacity .3s;z-index:60}
.scrim.show{opacity:1;pointer-events:auto}
.drawer{position:fixed;z-index:61;top:0;right:0;bottom:0;width:min(440px,100%);background:var(--paper);border-left:2px solid var(--ink);display:flex;flex-direction:column;
  transform:translateX(104%);visibility:hidden;transition:transform .38s cubic-bezier(.2,.9,.3,1),visibility 0s .38s;box-shadow:-20px 0 40px -20px rgba(0,0,0,.4)}
.drawer.open{transform:none;visibility:visible;transition:transform .38s cubic-bezier(.2,.9,.3,1)}
.grip{display:none;width:44px;height:5px;border-radius:9px;background:#d9c7ac;margin:10px auto 0}
.drawer-head{display:flex;align-items:center;justify-content:space-between;gap:10px;padding:18px 20px 14px;border-bottom:2px dashed var(--line)}
.drawer-head h3{font-size:28px}
.drawer-head p{margin:2px 0 0;font-size:13.5px;color:var(--ink2)}
.drawer-body{flex:1;overflow:auto;padding:14px 20px 18px;overscroll-behavior:contain}
.drawer-foot{padding:14px 20px calc(14px + env(safe-area-inset-bottom));display:flex;gap:10px;border-top:2px dashed var(--line)}
.drawer-foot .btn{flex:1;padding:0 10px}
.mini-box{display:grid;grid-template-columns:repeat(var(--cols),1fr);gap:4px;padding:8px;background:var(--kraft);border:2.5px solid var(--ink);border-radius:10px;max-width:220px;margin:4px auto 14px;box-shadow:inset 0 3px 6px rgba(80,45,15,.3)}
.mini-box span{aspect-ratio:1;border-radius:6px;background:rgba(255,250,240,.35);display:grid;place-items:center}
.mini-box svg{width:88%;height:88%}
.line{display:grid;grid-template-columns:46px 1fr auto;gap:12px;align-items:center;padding:8px 0;border-bottom:1px solid var(--line)}
.line svg{width:46px;height:46px}
.line b{display:block;font-size:15px}
.line small{color:var(--ink2);font-size:13px}
.line .amt{font-weight:800}
.totals{display:grid;gap:4px;margin:14px 0}
.totals div{display:flex;justify-content:space-between}
.totals .save{color:var(--ok);font-weight:750}
.totals .grand{font-family:var(--serif);font-size:24px;font-weight:700;border-top:2px solid var(--ink);padding-top:8px;margin-top:4px}
.pickup{background:#fdf0d6;border:2px dashed var(--crust);border-radius:16px;padding:14px;text-align:center}
.pickup small{display:block;font-size:11.5px;letter-spacing:.14em;text-transform:uppercase;font-weight:800;color:var(--crust2)}
.pickup .code{font-family:ui-monospace,"Cascadia Mono",Menlo,Consolas,monospace;font-size:24px;font-weight:800;letter-spacing:.14em;margin:4px 0}
.pickup p{margin:0;font-size:13.5px;color:var(--ink2)}
.note{font-size:12.5px;color:var(--ink2);margin:12px 0 0;text-align:center}
@media (max-width:640px){
  .drawer{top:auto;left:0;width:100%;max-height:90vh;border-left:0;border-top:2px solid var(--ink);border-radius:26px 26px 0 0;transform:translateY(104%)}
  .grip{display:block}
  .drawer-head{padding-top:10px}
}

/* toast */
.toast{position:fixed;left:50%;bottom:24px;transform:translate(-50%,30px);opacity:0;background:var(--ink);color:#fff6ea;padding:12px 18px;border-radius:14px;font-weight:650;font-size:14.5px;z-index:80;
  width:max-content;max-width:min(92vw,440px);text-align:center;transition:transform .3s cubic-bezier(.3,1.3,.5,1),opacity .25s;pointer-events:none;box-shadow:0 10px 30px -10px rgba(0,0,0,.5)}
.toast.show{transform:translate(-50%,0);opacity:1}
@media (max-width:899px){.toast{bottom:calc(92px + env(safe-area-inset-bottom))}}

/* demo */
#demoPtr{position:fixed;left:0;top:0;z-index:100;width:34px;height:34px;pointer-events:none;opacity:0;transition:transform .55s cubic-bezier(.45,0,.25,1),opacity .3s;transform:translate(50vw,50vh)}
#demoPtr.on{opacity:1}
#demoPtr svg{transform-origin:4px 3px;transition:transform .12s;filter:drop-shadow(0 3px 3px rgba(0,0,0,.35))}
#demoPtr.press svg{transform:scale(.8)}
.ripple{position:fixed;z-index:99;width:50px;height:50px;margin:-25px 0 0 -25px;border-radius:50%;border:3px solid var(--crust);pointer-events:none;animation:ripple .55s ease-out forwards}
#demoTag{position:fixed;top:74px;left:50%;transform:translateX(-50%);z-index:100;background:var(--crust);color:#fff;padding:7px 15px;border-radius:999px;font-size:13px;font-weight:800;pointer-events:none;border:2px solid var(--ink);white-space:nowrap}

/* keyframes */
@keyframes drop{0%{transform:translateY(-40%) scale(.45);opacity:0}45%{transform:translateY(0) scale(1.15);opacity:1}62%{transform:scale(.9,1.07)}80%{transform:scale(1.05,.96)}100%{transform:none;opacity:1}}
@keyframes out{to{transform:scale(.2) rotate(-25deg);opacity:0}}
@keyframes pulse{0%,100%{transform:scale(1);opacity:1}50%{transform:scale(.88);opacity:.55}}
@keyframes shake{0%,100%{transform:none}20%{transform:translateX(-8px) rotate(-1deg)}40%{transform:translateX(7px) rotate(1deg)}60%{transform:translateX(-5px)}80%{transform:translateX(3px)}}
@keyframes wiggle{0%,100%{transform:none}25%{transform:rotate(-5deg)}75%{transform:rotate(5deg)}}
@keyframes bump{0%,100%{transform:none}40%{transform:scale(1.14)}}
@keyframes settle{0%{transform:scale(.95);opacity:.5}60%{transform:scale(1.01);opacity:1}100%{transform:none}}
@keyframes breathe{0%,100%{box-shadow:0 0 0 3px rgba(47,122,74,.28)}50%{box-shadow:0 0 0 7px rgba(47,122,74,.04)}}
@keyframes steam{0%{opacity:0;transform:translateY(8px) scale(.8)}25%{opacity:.9}100%{opacity:0;transform:translateY(-30px) scale(1.2)}}
@keyframes swing{0%,100%{transform:rotate(-3deg)}50%{transform:rotate(3deg)}}
@keyframes drift{from{transform:translateX(-14px)}to{transform:translateX(20px)}}
@keyframes ripple{from{transform:scale(.4);opacity:1}to{transform:scale(1.5);opacity:0}}
@keyframes dotpop{0%{transform:scale(.3)}60%{transform:scale(1.5)}100%{transform:none}}
@keyframes burst{from{transform:translate(-50%,-50%) rotate(0);opacity:1}to{transform:translate(calc(-50% + var(--dx)),calc(-50% + var(--dy))) rotate(220deg) scale(.5);opacity:0}}
@media (prefers-reduced-motion:reduce){
  html{scroll-behavior:auto}
  *,*::before,*::after{animation-duration:.01ms!important;animation-iteration-count:1!important;transition-duration:.01ms!important}
}
</style>
</head>
<body>

<header class="top">
  <div class="wrap top-in">
    <button class="brand" type="button" data-goto="top" aria-label="Hollow Oak Bakehouse, back to top">
      <span id="logoTop"></span>
      <span><b>Hollow Oak</b><small>Bakehouse</small></span>
    </button>
    <nav class="nav" aria-label="Sections">
      <button type="button" data-goto="bakes">Today's bakes</button>
      <button type="button" data-goto="build">Build a box</button>
      <button type="button" data-goto="hours">Hours</button>
    </nav>
    <div class="top-actions">
      <span class="top-status"><span class="dot" id="topDot"></span><span id="topStatusText">…</span></span>
      <button class="icon-btn" id="muteBtn" type="button" aria-pressed="false" aria-label="Mute sounds"></button>
      <button class="cart-btn" id="cartBtn" type="button" aria-label="Go to your box">
        <svg width="24" height="22" viewBox="0 0 24 22" aria-hidden="true"><path d="M3 8h18l-2 12H5z" fill="#c8553d" stroke="#3b2416" stroke-width="2" stroke-linejoin="round"/><path d="M3 8l3-6h12l3 6" fill="#fff6ea" stroke="#3b2416" stroke-width="2" stroke-linejoin="round"/></svg>
        <span id="cartCount">0/6</span>
      </button>
    </div>
  </div>
</header>

<main>
  <section class="hero" id="top">
    <div class="wrap hero-grid">
      <div>
        <span class="eyebrow">Marigold Lane · since 2011</span>
        <h1>Warm from the oven, <em>just around the corner.</em></h1>
        <p class="lead">Hollow Oak is a tiny neighbourhood bakehouse with one stubborn brick oven, two siblings and a very old sourdough starter. Come early, bring a friend, leave with a box.</p>
        <div class="hero-cta">
          <button class="btn primary" type="button" data-goto="build">Build your box</button>
          <button class="btn" type="button" data-goto="bakes">See today's bakes</button>
        </div>
        <span class="pill"><span class="dot" id="heroDot"></span><span id="heroStatus">Checking the oven…</span></span>
        <div class="facts">
          <div><b>4:30</b>ovens on</div>
          <div><b>12</b>bakes daily</div>
          <div><b>81</b>layers per croissant</div>
        </div>
      </div>
      <div class="art-card" id="heroArt"></div>
    </div>
  </section>

  <section class="story" aria-labelledby="storyTitle">
    <div class="wrap">
      <div class="story-card">
        <div class="stamp-badge"><div><span>Est.</span><b>2011</b><span>Marigold Ln</span></div></div>
        <div>
          <h2 id="storyTitle">Our story</h2>
          <p>Ines Varga opened Hollow Oak in what used to be a bicycle repair shop. The ceiling hooks are still there; these days they hold baskets of loaves instead of wheels. Her brother Tomas arrived a year later carrying a sourdough starter he had kept alive through three house moves and one very hot summer.</p>
          <p>We bake in small batches with flour milled two valleys over, fold our croissants for three days, and anything left at closing goes to the community fridge on Pell Street.</p>
          <p class="sig">Ines &amp; Tomas</p>
        </div>
      </div>
    </div>
  </section>

  <section class="sec" id="bakes" aria-labelledby="bakesTitle">
    <div class="wrap">
      <div class="sec-head">
        <span class="kicker">Out of the oven this morning</span>
        <h2 id="bakesTitle">Today's bakes</h2>
        <p>Everything is made on site from 4:30 a.m. Labels show what's vegan, nut-free or gluten-free. Ask us about anything else; we know every ingredient by name.</p>
      </div>
      <div class="bakes" id="bakesGrid"></div>
    </div>
  </section>

  <section class="sec" id="build" aria-labelledby="buildTitle">
    <div class="wrap">
      <div class="sec-head">
        <span class="kicker">The fun part</span>
        <h2 id="buildTitle">Build your box</h2>
        <p>Pick a size, tap pastries to drop them in, and tap anything in the box to take it out. Fill a box of 6 and save 5%, or a box of 12 and save 10%.</p>
      </div>
      <div class="builder">
        <div class="panel ctl">
          <p class="ctl-label">1 · Box size</p>
          <div class="sizes" id="sizes" role="group" aria-label="Box size"></div>
          <div class="ctl-row"><p class="ctl-label">2 · Dietary filters</p><span class="match-count" id="matchCount"></span></div>
          <div class="filters" id="filters" role="group" aria-label="Dietary filters"></div>
        </div>

        <div class="box-col">
          <div class="panel box-panel">
            <div class="box-stage" id="boxStage">
              <div class="lid" id="lid"><span class="sticker" id="sticker"></span></div>
              <div class="box" id="box">
                <div class="floor" id="floor" role="group" aria-label="Your box"></div>
                <div class="stamp" id="stamp">Hollow Oak · box of 6</div>
              </div>
            </div>
            <div class="box-info">
              <div class="fill-row"><span id="fillCount">0 of 6 filled</span><span id="boxName">Box of 6</span></div>
              <div class="progress" aria-hidden="true"><i id="progress"></i></div>
              <p class="hint" id="hint" aria-live="polite"></p>
              <p class="warn-note" id="mismatchNote" hidden></p>
              <div class="sum">
                <div class="sum-row"><span>Subtotal</span><span id="subtotal">$0.00</span></div>
                <div class="sum-row save" id="saveRow" hidden><span id="saveLabel">Full-box saving</span><span id="saving">-$0.00</span></div>
                <div class="sum-row total"><span>Total</span><span id="total">$0.00</span></div>
              </div>
              <div class="box-actions">
                <button class="btn" type="button" id="clearBtn">Empty box</button>
                <button class="btn primary" type="button" id="checkoutBtn">Checkout</button>
              </div>
            </div>
          </div>
        </div>

        <div class="panel pal">
          <div class="ctl-row"><p class="ctl-label">3 · Tap to add</p><button class="btn small" type="button" id="choiceBtn">Baker's choice</button></div>
          <div class="palette" id="palette"></div>
        </div>
      </div>
    </div>
  </section>

  <section class="sec" id="hours" aria-labelledby="hoursTitle">
    <div class="wrap">
      <div class="sec-head">
        <span class="kicker">Come say hello</span>
        <h2 id="hoursTitle">Opening hours</h2>
        <p>Times are shown in your local time. We close when the shelves are empty, which on Saturdays can be a little early.</p>
      </div>
      <div class="hours-grid">
        <div class="status-card">
          <span class="badge" id="badge"><span class="dot" id="badgeDot"></span><span id="badgeText">…</span></span>
          <h3 id="statusTitle">…</h3>
          <p id="statusText"></p>
          <p class="clock" id="clock"></p>
          <div class="addr"><b>14 Marigold Lane</b>, Old Mill Quarter<br>Opposite the green bench and the very old oak tree.</div>
        </div>
        <ul class="hours-list" id="hoursList"></ul>
      </div>
    </div>
  </section>
</main>

<footer>
  <div class="wrap">
    <div class="foot-grid">
      <div>
        <div class="foot-brand"><span id="logoFoot"></span><b>Hollow Oak Bakehouse</b></div>
        <p>Small batches, slow dough, and a kettle that's always on. Made by hand on Marigold Lane.</p>
      </div>
      <div>
        <h4>Visit</h4>
        <p>14 Marigold Lane<br>Old Mill Quarter</p>
        <p>Tue to Sun · closed Mondays</p>
      </div>
      <div>
        <h4>This page</h4>
        <div class="foot-actions">
          <button class="btn small" type="button" id="restartBtn">Restart</button>
          <button class="btn small" type="button" data-goto="top">Back to top</button>
        </div>
      </div>
    </div>
    <div class="fine"><span>Hollow Oak Bakehouse is a made-up bakery. Illustrations drawn in code.</span><span>Orders are summaries only, pay at the counter.</span></div>
  </div>
</footer>

<div class="minibar" id="minibar">
  <button class="mb-view" type="button" id="mbView" aria-label="Show your box">
    <span class="mb-dots" id="mbDots"></span>
    <span class="mb-total"><span id="mbCount">0 of 6</span><strong id="mbTotal">$0.00</strong></span>
  </button>
  <button class="btn primary small" type="button" id="mbCheckout">Checkout</button>
</div>

<div class="scrim" id="scrim"></div>
<aside class="drawer" id="drawer" role="dialog" aria-modal="true" aria-labelledby="drawerTitle" aria-hidden="true">
  <div class="grip" aria-hidden="true"></div>
  <div class="drawer-head">
    <div><h3 id="drawerTitle">Your box</h3><p id="drawerSub"></p></div>
    <button class="icon-btn" type="button" id="drawerClose" aria-label="Close order summary">
      <svg width="18" height="18" viewBox="0 0 18 18" aria-hidden="true"><path d="M3 3l12 12M15 3L3 15" stroke="#3b2416" stroke-width="2.6" stroke-linecap="round"/></svg>
    </button>
  </div>
  <div class="drawer-body" id="drawerBody"></div>
  <div class="drawer-foot">
    <button class="btn" type="button" id="keepEditing">Keep editing</button>
    <button class="btn sage" type="button" id="newBox">Start a new box</button>
  </div>
</aside>

<div class="toast" id="toast" role="status" aria-live="polite"></div>
<div id="demoPtr" aria-hidden="true"><svg width="34" height="34" viewBox="0 0 34 34"><path d="M4 3 L4 27 L10.5 21 L15 31 L19.5 29 L15 19.5 L24 19.5 Z" fill="#fff" stroke="#3b2416" stroke-width="2.4" stroke-linejoin="round"/></svg></div>
<div id="demoTag" hidden>Demo · tap anywhere to take over</div>

<script>
(() => {
'use strict';
const $ = (s, r = document) => r.querySelector(s);
const $$ = (s, r = document) => Array.from(r.querySelectorAll(s));
const TAU = Math.PI * 2;
const REDUCED = window.matchMedia && matchMedia('(prefers-reduced-motion: reduce)').matches;

/* ---------- seeded randomness ---------- */
function mulberry32(a){return function(){a|=0;a=a+0x6D2B79F5|0;let t=Math.imul(a^a>>>15,1|a);t=t+Math.imul(t^t>>>7,61|t)^t;return((t^t>>>14)>>>0)/4294967296;};}
function hashStr(s){let h=2166136261;for(let i=0;i<s.length;i++){h^=s.charCodeAt(i);h=Math.imul(h,16777619);}return h>>>0;}
const f1 = n => (Math.round(n*10)/10).toString();

/* ---------- drawing helpers ---------- */
const INK = '#4a2a1a';
const ST = `stroke="${INK}" stroke-width="3" stroke-linejoin="round" stroke-linecap="round"`;
const sh = (cy=84, rx=30) => `<ellipse cx="50" cy="${cy}" rx="${rx}" ry="5" fill="#3b2314" opacity=".14"/>`;
const ln = (d, c, w=2.5) => `<path d="${d}" fill="none" stroke="${c}" stroke-width="${w}" stroke-linecap="round" stroke-linejoin="round"/>`;
const HL = d => `<path d="${d}" fill="none" stroke="#fff" stroke-width="3" stroke-linecap="round" opacity=".6"/>`;
function smoothClosed(p){
  const n=p.length; let d=`M${f1(p[0][0])} ${f1(p[0][1])}`;
  for(let i=0;i<n;i++){
    const p0=p[(i-1+n)%n],p1=p[i],p2=p[(i+1)%n],p3=p[(i+2)%n];
    const c1=[p1[0]+(p2[0]-p0[0])/6,p1[1]+(p2[1]-p0[1])/6];
    const c2=[p2[0]-(p3[0]-p1[0])/6,p2[1]-(p3[1]-p1[1])/6];
    d+=` C${f1(c1[0])} ${f1(c1[1])} ${f1(c2[0])} ${f1(c2[1])} ${f1(p2[0])} ${f1(p2[1])}`;
  }
  return d+'Z';
}
function blob(cx,cy,r,jit,n,rng){const pts=[];for(let i=0;i<n;i++){const a=i/n*TAU;const rr=r*(1+(rng()-.5)*jit);pts.push([cx+Math.cos(a)*rr,cy+Math.sin(a)*rr]);}return smoothClosed(pts);}
function scallop(cx,cy,r,amp,n){
  const P=(a,rr)=>`${f1(cx+Math.cos(a)*rr)} ${f1(cy+Math.sin(a)*rr)}`; let d='';
  for(let i=0;i<n;i++){const a0=i/n*TAU,a1=(i+1)/n*TAU,am=(a0+a1)/2; if(!i) d+=`M${P(a0,r)}`; d+=` Q${P(am,r+amp*2)} ${P(a1,r)}`;}
  return d+'Z';
}

/* ---------- pastries: one consistent style ---------- */
function croissantArt(fill, line, extra){
  const e=(cx,cy,rx,ry,rot)=>`<ellipse cx="${cx}" cy="${cy}" rx="${rx}" ry="${ry}" transform="rotate(${rot} ${cx} ${cy})" fill="${fill}" ${ST}/>`;
  return sh(80,34)+e(18,66,8,12,-58)+e(82,66,8,12,58)+e(31,55,12,17,-36)+e(69,55,12,17,36)+e(50,48,16,23,0)
    +ln('M37 50 Q50 58 63 50 M39 38 Q50 45 61 38',line)
    +ln('M22 56 q4 6 10 8 M78 56 q-4 6 -10 8',line)
    +HL('M44 31 q6 -5 12 0')+(extra||'');
}
const DRAW = {
  croissant: () => croissantArt('#eba84c','#b9692a'),
  almond: rng => {
    const al=[[42,36,-25],[57,40,20],[48,53,-5],[31,53,-40],[69,55,35],[60,29,10],[38,46,15],[24,64,-60],[76,64,60]];
    let x=al.map(([x,y,r])=>`<ellipse cx="${x}" cy="${y}" rx="4.6" ry="2.4" transform="rotate(${r} ${x} ${y})" fill="#f6e3c0" stroke="${INK}" stroke-width="1.4"/>`).join('');
    for(let i=0;i<20;i++) x+=`<circle cx="${f1(24+rng()*52)}" cy="${f1(30+rng()*36)}" r="1.3" fill="#fff"/>`;
    return croissantArt('#d69443','#a35a1f',x);
  },
  painchoc: () => sh(80,34)
    +`<rect x="10" y="41" width="16" height="7" rx="2" fill="#4a2617" ${ST}/><rect x="10" y="53" width="16" height="7" rx="2" fill="#4a2617" ${ST}/>`
    +`<rect x="74" y="41" width="16" height="7" rx="2" fill="#4a2617" ${ST}/><rect x="74" y="53" width="16" height="7" rx="2" fill="#4a2617" ${ST}/>`
    +`<rect x="18" y="30" width="64" height="42" rx="13" fill="#e4a24d" ${ST}/>`
    +ln('M30 33 Q35 51 30 69 M70 33 Q65 51 70 69','#b66a26')
    +ln('M40 43 q10 -4 20 0 M41 57 q9 4 18 0','#b66a26')
    +HL('M26 41 q4 -6 12 -7'),
  cinnamon: () => {
    let sp=''; for(let t=0;t<=6*Math.PI;t+=.3){const r=2.5+t*1.33; sp+=(t?' L':'M')+f1(50+Math.cos(t)*r)+' '+f1(50+Math.sin(t)*r);}
    return sh(86,30)+`<circle cx="50" cy="50" r="32" fill="#d8954e" ${ST}/>`+ln(sp,'#7d4019',3.2)
      +`<path d="M26 42 C34 30 42 34 40 44 S50 58 56 46 S70 36 73 52" fill="none" stroke="#fff6e6" stroke-width="5" stroke-linecap="round"/>`;
  },
  cardamom: rng => {
    const lobes=[[34,58,17,15,-20],[66,58,17,15,20],[50,35,16,14,0]];
    let s=sh(84,32)+lobes.map(([x,y,rx,ry,r])=>`<ellipse cx="${x}" cy="${y}" rx="${rx}" ry="${ry}" transform="rotate(${r} ${x} ${y})" fill="#e2aa5e" ${ST}/>`).join('');
    s+=ln('M22 56 q8 -9 18 -2 M78 56 q-8 -9 -18 -2 M41 30 q9 7 18 0','#b06a28');
    s+=`<ellipse cx="50" cy="52" rx="11" ry="12" fill="#cf9045" ${ST}/>`+ln('M45 47 q5 5 10 0','#9e5a22',2);
    for(let i=0;i<16;i++){const L=lobes[i%3]; s+=`<circle cx="${f1(L[0]+(rng()-.5)*20)}" cy="${f1(L[1]+(rng()-.5)*16)}" r="1.9" fill="#fffdf6" stroke="#d9c7a8" stroke-width=".6"/>`;}
    return s+HL('M40 28 q6 -5 14 -3');
  },
  muffin: () => {
    let s=sh(88,24)+`<path d="M27 56 L34 86 H66 L73 56 Z" fill="#93b6d4" ${ST}/>`+ln('M38 61 L41 84 M50 61 V84 M62 61 L59 84','#6a8fb0');
    s+=`<path d="M20 60 C16 38 34 22 50 22 C66 22 84 38 80 60 C66 66 34 66 20 60 Z" fill="#e9b466" ${ST}/>`;
    [[36,44],[56,33],[63,51],[45,55],[71,42],[29,54],[50,43]].forEach(([x,y])=>{s+=`<circle cx="${x}" cy="${y}" r="4.6" fill="#44508f" stroke="${INK}" stroke-width="2"/><circle cx="${x-1.4}" cy="${y-1.6}" r="1.2" fill="#c9d1ff"/>`;});
    return s+HL('M29 40 q6 -10 15 -12');
  },
  tart: () => {
    let s=sh(86,32)+`<path d="${scallop(50,50,31,2.6,18)}" fill="#e1a962" ${ST}/>`+`<circle cx="50" cy="50" r="23" fill="#fbe2bd" stroke="${INK}" stroke-width="2.5"/>`;
    for(let i=0;i<6;i++){const a=i/6*TAU-Math.PI/2,x=50+Math.cos(a)*13,y=50+Math.sin(a)*13;
      s+=`<circle cx="${f1(x)}" cy="${f1(y)}" r="6.4" fill="#d33a4f" stroke="${INK}" stroke-width="2"/>`;
      s+=`<circle cx="${f1(x-2)}" cy="${f1(y-1.5)}" r="1" fill="#f7a1ad"/><circle cx="${f1(x+1.8)}" cy="${f1(y)}" r="1" fill="#f7a1ad"/><circle cx="${f1(x-.2)}" cy="${f1(y+2.2)}" r="1" fill="#f7a1ad"/>`;}
    s+=`<path d="M45 52 q4 -12 15 -10 q-3 11 -15 10Z" fill="#6aa864" stroke="${INK}" stroke-width="2" stroke-linejoin="round"/>`+ln('M47 51 L56 44','#3f7a3c',1.5);
    return s;
  },
  macaron: rng => {
    let s=sh(82,32)+`<rect x="20" y="56" width="60" height="18" rx="9" fill="#b3d189" ${ST}/>`
      +`<rect x="21" y="47" width="58" height="11" rx="5.5" fill="#f7edd3" ${ST}/>`
      +`<path d="M19 50 C19 25 81 25 81 50 Z" fill="#bcd894" ${ST}/>`;
    let w='M22 51'; for(let i=0;i<11;i++) w+=' q2.6 3 5.2 0'; s+=ln(w,INK,1.8);
    let w2='M23 59'; for(let i=0;i<10;i++) w2+=' q2.7 3 5.4 0'; s+=ln(w2,INK,1.6);
    for(let i=0;i<8;i++) s+=`<rect x="${f1(30+rng()*40)}" y="${f1(33+rng()*10)}" width="3" height="2" rx=".8" fill="#6f9a48" transform="rotate(${Math.round(rng()*90)} 50 40)" />`;
    return s+HL('M30 39 q7 -8 18 -9');
  },
  brownie: rng => {
    let s=sh(84,32)+`<g transform="rotate(-6 50 50)"><rect x="22" y="24" width="56" height="54" rx="7" fill="#4e2b19" ${ST}/>`
      +`<rect x="22" y="24" width="56" height="42" rx="7" fill="#6c3f27" ${ST}/>`
      +ln('M29 35 l8 4 l6 -3 l9 5 l8 -2 l9 3 M30 52 l7 -3 l10 4 l7 -2 l9 3','#9a6444',2);
    for(let i=0;i<7;i++){const x=30+rng()*40,y=30+rng()*30; s+=`<path d="M${f1(x)} ${f1(y-2.2)} l2.2 2.2 l-2.2 2.2 l-2.2 -2.2z" fill="#fffaf0"/>`;}
    return s+HL('M29 30 h14')+'</g>';
  },
  cookie: rng => {
    let s=sh(84,30)+`<path d="${blob(50,50,31,.14,14,rng)}" fill="#dca45f" ${ST}/>`;
    for(let i=0;i<8;i++){const a=rng()*TAU,r=Math.sqrt(rng())*20; s+=`<path d="${blob(50+Math.cos(a)*r,50+Math.sin(a)*r,4.6,.5,6,rng)}" fill="#432414"/>`;}
    for(let i=0;i<10;i++){const a=rng()*TAU,r=Math.sqrt(rng())*24; s+=`<circle cx="${f1(50+Math.cos(a)*r)}" cy="${f1(50+Math.sin(a)*r)}" r="1.2" fill="#b77b39"/>`;}
    return s+HL('M29 37 q6 -9 16 -11');
  },
  polenta: () => {
    let s=sh(86,30)+`<path d="M16 72 Q50 90 84 72 L84 78 Q50 96 16 78 Z" fill="#c98a34" ${ST}/>`
      +`<path d="M50 15 L84 72 Q50 90 16 72 Z" fill="#f4cb52" ${ST}/>`
      +`<circle cx="50" cy="60" r="13" fill="#f39c2f" ${ST}/><circle cx="50" cy="60" r="9.5" fill="#ffc362"/>`;
    for(let i=0;i<8;i++){const a=i/8*TAU; s+=ln(`M50 60 L${f1(50+Math.cos(a)*9.5)} ${f1(60+Math.sin(a)*9.5)}`,'#fff3d6',1.5);}
    return s+HL('M45 30 L37 44');
  },
  oatbar: rng => {
    let s=sh(82,34)+`<rect x="16" y="34" width="68" height="42" rx="9" fill="#a8763f" ${ST}/>`+`<rect x="16" y="30" width="68" height="36" rx="9" fill="#c8955a" ${ST}/>`;
    for(let i=0;i<14;i++){const x=24+rng()*52,y=36+rng()*24,r=Math.round(rng()*180); s+=`<ellipse cx="${f1(x)}" cy="${f1(y)}" rx="3.4" ry="1.9" transform="rotate(${r} ${f1(x)} ${f1(y)})" fill="#efd8aa" stroke="#8b5a2b" stroke-width="1"/>`;}
    for(let i=0;i<5;i++) s+=`<path d="${blob(26+rng()*48,38+rng()*22,3,.5,6,rng)}" fill="#5b2a18"/>`;
    return s+ln('M24 40 l8 6 l8 -6 l8 6 l8 -6 l8 6 l8 -6','#fff6e6',2.4);
  }
};
const ART = {};
const pastry = id => ART[id] || (ART[id] = DRAW[id](mulberry32(hashStr(id))));
const pastrySVG = id => `<svg viewBox="0 0 100 100" aria-hidden="true" focusable="false">${pastry(id)}</svg>`;

const LINER = (() => {
  let s=`<svg viewBox="0 0 100 100" aria-hidden="true"><path d="${scallop(50,50,42,2.4,22)}" fill="#fffaf0" stroke="#cdb48e" stroke-width="2"/><circle cx="50" cy="50" r="33" fill="#f4e8d3"/>`;
  for(let i=0;i<22;i++){const a=(i+.5)/22*TAU; s+=`<path d="M${f1(50+Math.cos(a)*34)} ${f1(50+Math.sin(a)*34)} L${f1(50+Math.cos(a)*43)} ${f1(50+Math.sin(a)*43)}" stroke="#e5d3b6" stroke-width="1.5"/>`;}
  return s+'</svg>';
})();

const logo = (sz=40) => `<svg width="${sz}" height="${sz}" viewBox="0 0 40 40" aria-hidden="true"><circle cx="20" cy="20" r="18" fill="#c8553d" stroke="#3b2416" stroke-width="2.5"/><path d="M12 20 q0 9 8 12 q8 -3 8 -12 z" fill="#f2c46b" stroke="#fbefd9" stroke-width="2" stroke-linejoin="round"/><path d="M10.5 20 Q20 8 29.5 20 Z" fill="#7b4a33" stroke="#fbefd9" stroke-width="2" stroke-linejoin="round"/><path d="M20 12 V7" stroke="#fbefd9" stroke-width="2.5" stroke-linecap="round"/></svg>`;

/* ---------- menu ---------- */
const TAGS = { v:{label:'Vegan',short:'VG'}, nf:{label:'Nut-free',short:'NF'}, gf:{label:'Gluten-free',short:'GF'} };
const MENU = [
  {id:'croissant',name:'Butter Croissant',price:3.4,tags:['nf'],oven:'6:40 am',desc:'Three days of folding, 81 layers and a crust that shatters on the first bite.'},
  {id:'painchoc',name:'Pain au Chocolat',price:3.8,tags:['nf'],oven:'6:55 am',desc:'Two batons of dark chocolate tucked into our croissant dough.'},
  {id:'almond',name:'Almond Croissant',price:4.2,tags:[],oven:'7:20 am',desc:'Twice-baked with frangipane, toasted almond flakes and a snow of sugar.'},
  {id:'cinnamon',name:'Cinnamon Swirl',price:3.9,tags:['nf'],oven:'7:05 am',desc:'Brown-butter cinnamon filling, a soft middle and a vanilla glaze.'},
  {id:'cardamom',name:'Cardamom Knot',price:3.9,tags:['v','nf'],oven:'7:30 am',desc:'Oat-milk dough, freshly ground cardamom and crunchy pearl sugar.'},
  {id:'muffin',name:'Blueberry Muffin',price:3.2,tags:['v','nf'],oven:'7:15 am',desc:'Bursting with berries under a crackly demerara top. Fully vegan.'},
  {id:'tart',name:'Raspberry Tart',price:4.6,tags:['nf'],oven:'8:30 am',desc:'Vanilla custard in crisp sweet pastry, crowned with raspberries and mint.'},
  {id:'macaron',name:'Pistachio Macaron',price:2.4,tags:['gf'],oven:'9:00 am',desc:'Chewy almond shells sandwiching pistachio buttercream.'},
  {id:'brownie',name:'Flourless Brownie',price:3.5,tags:['gf','nf'],oven:'8:10 am',desc:'Dense, fudgy, naturally gluten-free and finished with sea salt.'},
  {id:'cookie',name:'Chunky Choc Cookie',price:2.8,tags:['v','nf'],oven:'9:20 am',desc:'Crisp edges, a gooey middle and big chunks of dark chocolate.'},
  {id:'polenta',name:'Orange Polenta Cake',price:3.6,tags:['gf','nf'],oven:'8:45 am',desc:'Olive-oil polenta sponge soaked in warm orange syrup.'},
  {id:'oatbar',name:'Oat & Date Bar',price:2.9,tags:['v','gf','nf'],oven:'8:00 am',desc:'Gluten-free oats, sticky dates and a little maple. No nuts at all.'}
];
const BY_ID = Object.fromEntries(MENU.map(p => [p.id, p]));
const BG = ['#fde6c3','#f9dcd2','#e3ecd9','#f6e3b8','#e2e7f1','#f3dde6'];
const SIZES = {4:{cols:2,disc:0,desc:'a little treat'},6:{cols:3,disc:.05,desc:'save 5% when full'},12:{cols:4,disc:.10,desc:'save 10% when full'}};
const money = n => '$' + (Math.round(n*100)/100).toFixed(2);
const matches = (p, f) => [...(f||state.filters)].every(t => p.tags.includes(t));

/* ---------- sound (starts only after a tap) ---------- */
const muteBtn = $('#muteBtn');
const ICON_ON = `<svg width="22" height="22" viewBox="0 0 22 22" aria-hidden="true"><path d="M3 8h4l5-4v14l-5-4H3z" fill="#f2c46b" stroke="#3b2416" stroke-width="2" stroke-linejoin="round"/><path d="M15 7.5q2.5 3.5 0 7M17.5 5q4.5 6 0 12" fill="none" stroke="#3b2416" stroke-width="2" stroke-linecap="round"/></svg>`;
const ICON_OFF = `<svg width="22" height="22" viewBox="0 0 22 22" aria-hidden="true"><path d="M3 8h4l5-4v14l-5-4H3z" fill="#e8d6c0" stroke="#3b2416" stroke-width="2" stroke-linejoin="round"/><path d="M15 8l5 6M20 8l-5 6" stroke="#b2412f" stroke-width="2.2" stroke-linecap="round"/></svg>`;
const Sound = {
  ctx:null, master:null, muted:false,
  init(){
    if(this.ctx){ if(this.ctx.state==='suspended') this.ctx.resume(); return; }
    const AC = window.AudioContext || window.webkitAudioContext; if(!AC) return;
    try{ this.ctx=new AC(); this.master=this.ctx.createGain(); this.master.gain.value=this.muted?0:.5; this.master.connect(this.ctx.destination); }catch(e){ this.ctx=null; }
  },
  tone(f,dur=.15,type='sine',vol=.3,slide=0,delay=0){
    const c=this.ctx; if(!c||this.muted) return;
    const t=c.currentTime+delay, o=c.createOscillator(), g=c.createGain();
    o.type=type; o.frequency.setValueAtTime(f,t); if(slide) o.frequency.exponentialRampToValueAtTime(slide,t+dur);
    g.gain.setValueAtTime(.0001,t); g.gain.exponentialRampToValueAtTime(vol,t+.012); g.gain.exponentialRampToValueAtTime(.0001,t+dur);
    o.connect(g); g.connect(this.master); o.start(t); o.stop(t+dur+.05);
  },
  pop(i){ const sc=[523.25,587.33,659.25,783.99,880,1046.5,1174.66,1318.5,1567.98,1760,2093,2349.3]; const f=sc[i%12]; this.tone(f*.5,.08,'triangle',.22,f); this.tone(f,.2,'sine',.16,0,.04); },
  remove(){ this.tone(560,.16,'triangle',.2,240); },
  nope(){ this.tone(190,.08,'square',.05); this.tone(150,.12,'square',.05,0,.1); },
  full(){ [659.25,783.99,1046.5,1318.5].forEach((f,i)=>this.tone(f,.4,'sine',.15,0,i*.08)); },
  click(){ this.tone(880,.05,'triangle',.08); },
  whoosh(){
    const c=this.ctx; if(!c||this.muted) return;
    const len=Math.floor(c.sampleRate*.35), b=c.createBuffer(1,len,c.sampleRate), d=b.getChannelData(0), r=mulberry32(9);
    for(let i=0;i<len;i++) d[i]=(r()*2-1)*(1-i/len);
    const s=c.createBufferSource(); s.buffer=b; const f=c.createBiquadFilter(); f.type='bandpass'; f.Q.value=1.2;
    const t=c.currentTime; f.frequency.setValueAtTime(400,t); f.frequency.exponentialRampToValueAtTime(2400,t+.3);
    const g=c.createGain(); g.gain.value=.2; s.connect(f); f.connect(g); g.connect(this.master); s.start();
  },
  setMuted(m){
    this.muted=m;
    if(this.master&&this.ctx) this.master.gain.setTargetAtTime(m?0:.5,this.ctx.currentTime,.02);
    muteBtn.setAttribute('aria-pressed',String(m)); muteBtn.setAttribute('aria-label',m?'Unmute sounds':'Mute sounds');
    muteBtn.innerHTML = m?ICON_OFF:ICON_ON;
    try{ localStorage.setItem('hollowoak-muted', m?'1':'0'); }catch(e){}
  }
};
let storedMute=false; try{ storedMute = localStorage.getItem('hollowoak-muted')==='1'; }catch(e){}
Sound.setMuted(storedMute);
['pointerdown','keydown'].forEach(ev => window.addEventListener(ev, e => { if(e.isTrusted) Sound.init(); }, {capture:true, passive:true}));
muteBtn.addEventListener('click', () => { Sound.init(); Sound.setMuted(!Sound.muted); if(!Sound.muted) Sound.click(); });

/* ---------- press feedback via pointer events ---------- */
document.addEventListener('pointerdown', e => {
  const b = e.target.closest('.pick,.btn,.size-btn,.chip,.slot.filled,.cart-btn,.icon-btn,.nav button');
  if(!b) return;
  b.classList.add('pressing');
  const up = () => { b.classList.remove('pressing'); window.removeEventListener('pointerup',up); window.removeEventListener('pointercancel',up); };
  window.addEventListener('pointerup',up); window.addEventListener('pointercancel',up);
});

/* ---------- toast ---------- */
let toastT;
function toast(msg){ const t=$('#toast'); t.textContent=msg; t.classList.add('show'); clearTimeout(toastT); toastT=setTimeout(()=>t.classList.remove('show'),2600); }

/* ---------- hero illustration ---------- */
function buildHero(){
  const rng = mulberry32(2011);
  const S = (w=4) => `stroke="${INK}" stroke-width="${w}" stroke-linejoin="round" stroke-linecap="round"`;
  let s = `<svg class="shop" viewBox="0 -40 640 560" role="img" aria-label="Hand-drawn illustration of the Hollow Oak Bakehouse shop front with a striped awning, a window full of pastries and a green door">
  <defs>
    <filter id="rough" x="-3%" y="-3%" width="106%" height="106%"><feTurbulence type="fractalNoise" baseFrequency="0.035" numOctaves="2" seed="7" result="n"/><feDisplacementMap in="SourceGraphic" in2="n" scale="3.4" xChannelSelector="R" yChannelSelector="G"/></filter>
    <linearGradient id="sky" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stop-color="#fde9cc"/><stop offset="1" stop-color="#f7cfa2"/></linearGradient>
    <pattern id="awn" width="48" height="10" patternUnits="userSpaceOnUse"><rect width="24" height="10" fill="#c8553d"/><rect x="24" width="24" height="10" fill="#fbefd9"/></pattern>
  </defs>
  <rect x="0" y="-40" width="640" height="510" fill="url(#sky)"/>
  <circle cx="574" cy="78" r="38" fill="#f6c768" opacity=".9"/>
  <g class="cloud"><path d="M40 40 a16 16 0 0 1 28 -10 a20 20 0 0 1 36 4 a13 13 0 0 1 4 26 h-66 a12 12 0 0 1 -2 -20z" fill="#fff8ee" opacity=".92"/></g>
  <g class="cloud c2"><path d="M300 -6 a12 12 0 0 1 22 -8 a16 16 0 0 1 28 4 a10 10 0 0 1 3 20 h-52 a10 10 0 0 1 -1 -16z" fill="#fff8ee" opacity=".85"/></g>
  <path class="steam" d="M466 4 q-9 -9 0 -18 q9 -9 0 -20"/>
  <path class="steam s2" d="M476 4 q-9 -9 0 -18 q9 -9 0 -20"/>
  <path class="steam s3" d="M486 4 q-9 -9 0 -18 q9 -9 0 -20"/>
  <g class="rough" filter="url(#rough)">`;
  // ground
  s += `<rect x="-10" y="468" width="660" height="60" fill="#e4cfae"/>`;
  for(let x=20;x<640;x+=58) s += `<path d="M${x} 474 l-7 46" stroke="#cdb48c" stroke-width="2.5" stroke-linecap="round"/>`;
  s += `<path d="M-10 468 H650" ${S(4)} fill="none"/>`;
  // chimney
  s += `<rect x="456" y="14" width="36" height="40" fill="#b0603f" ${S(3.5)}/><rect x="450" y="6" width="48" height="12" rx="2" fill="#7b4a33" ${S(3.5)}/>`;
  // facade
  s += `<rect x="92" y="62" width="456" height="406" fill="#f3ddc0" ${S()}/>`;
  s += `<rect x="92" y="62" width="22" height="406" fill="#e7c9a3" ${S(3)}/><rect x="526" y="62" width="22" height="406" fill="#e7c9a3" ${S(3)}/>`;
  const avoid = [[136,88,256,196],[384,88,504,196]];
  for(let i=0;i<40;i++){
    const x=120+rng()*384, y=80+rng()*106;
    if(avoid.some(a => x+22>a[0] && x<a[2] && y+10>a[1] && y<a[3])) continue;
    s += `<rect x="${f1(x)}" y="${f1(y)}" width="22" height="10" rx="2" fill="none" stroke="#d6ad85" stroke-width="2"/>`;
  }
  // cornice
  s += `<rect x="76" y="46" width="488" height="26" rx="5" fill="#7b4a33" ${S()}/>`;
  for(let x=96;x<540;x+=20) s += `<rect x="${x}" y="72" width="9" height="8" fill="#9a6247" stroke="${INK}" stroke-width="2"/>`;
  // bird
  s += `<ellipse cx="236" cy="38" rx="11" ry="8" fill="#6e5240" ${S(2.5)}/><circle cx="246" cy="30" r="6" fill="#6e5240" ${S(2.5)}/><path d="M251.5 29 l6 2 l-6 2z" fill="#f2c46b" stroke="${INK}" stroke-width="1.5" stroke-linejoin="round"/><circle cx="247.5" cy="28.5" r="1.3" fill="#fff"/><path d="M226 37 l-9 -4" ${S(2.5)}/>`;
  // upper windows
  [146,394].forEach(wx => {
    s += `<rect x="${wx}" y="96" width="100" height="78" rx="4" fill="#cfe4ea" ${S()}/>`;
    s += `<path d="M${wx+4} 100 q16 30 6 70 L${wx+4} 170 Z" fill="#f2b6a0" stroke="${INK}" stroke-width="2"/>`;
    s += `<path d="M${wx+96} 100 q-16 30 -6 70 L${wx+96} 170 Z" fill="#f2b6a0" stroke="${INK}" stroke-width="2"/>`;
    s += `<path d="M${wx+50} 96 V174 M${wx} 135 H${wx+100}" ${S(3)}/>`;
    s += `<path d="M${wx+26} 124 l14 -16 M${wx+32} 130 l12 -14" stroke="#fff" stroke-width="3" stroke-linecap="round" opacity=".85"/>`;
    for(let k=0;k<7;k++){
      const fx=wx+4+k*15.5, fy=160-rng()*5, col=['#e86f5a','#f6c768','#f3a6c0','#fffaf0'][Math.floor(rng()*4)];
      s += `<path d="M${f1(fx)} 176 q-5 -8 0 -13 q5 5 0 13" fill="#6aa864" stroke="${INK}" stroke-width="1.5"/>`;
      s += `<circle cx="${f1(fx)}" cy="${f1(fy)}" r="4.6" fill="${col}" stroke="${INK}" stroke-width="1.5"/><circle cx="${f1(fx)}" cy="${f1(fy)}" r="1.4" fill="#c07a12"/>`;
    }
    s += `<rect x="${wx-8}" y="172" width="116" height="16" rx="3" fill="#9c5b3c" ${S(3)}/>`;
  });
  // sign board
  s += `<rect x="150" y="204" width="340" height="58" rx="10" fill="#3e5b41" ${S()}/>`;
  s += `<rect x="158" y="212" width="324" height="42" rx="6" fill="none" stroke="#f2c46b" stroke-width="2" stroke-dasharray="2 5"/>`;
  s += `<text x="320" y="241" text-anchor="middle" font-family="Iowan Old Style,Palatino Linotype,Palatino,Georgia,serif" font-size="28" font-weight="700" letter-spacing="4" fill="#fbefd9">HOLLOW OAK</text>`;
  s += `<text x="320" y="254" text-anchor="middle" font-family="system-ui,Segoe UI,Arial,sans-serif" font-size="9" font-weight="700" letter-spacing="4" fill="#f2c46b">BAKEHOUSE · EST 2011</text>`;
  // awning
  s += `<path d="M108 278 H532 L556 318 H84 Z" fill="url(#awn)" ${S()}/>`;
  const sw=(556-84)/12;
  for(let i=0;i<12;i++){ const x0=84+i*sw; s += `<path d="M${f1(x0)} 318 a${f1(sw/2)} 15 0 0 0 ${f1(sw)} 0 Z" fill="${i%2?'#fbefd9':'#c8553d'}" ${S(3)}/>`; }
  s += `<rect x="100" y="270" width="440" height="11" rx="4" fill="#7b4a33" ${S(3)}/>`;
  // shop window
  s += `<rect x="120" y="340" width="250" height="128" rx="6" fill="#d7ebee" ${S()}/>`;
  s += `<text x="245" y="358" text-anchor="middle" font-family="Iowan Old Style,Palatino Linotype,Georgia,serif" font-style="italic" font-size="14" fill="#b8862e">fresh every morning</text>`;
  ['croissant','cinnamon','tart','muffin','painchoc'].forEach((id,i) => { s += `<svg x="${134+i*46}" y="364" width="40" height="40" viewBox="0 0 100 100">${pastry(id)}</svg>`; });
  ['brownie','macaron','cookie','cardamom','polenta'].forEach((id,i) => { s += `<svg x="${134+i*46}" y="414" width="40" height="40" viewBox="0 0 100 100">${pastry(id)}</svg>`; });
  s += `<path d="M124 404 H366 M124 454 H366" stroke="#9c5b3c" stroke-width="5" stroke-linecap="round"/>`;
  s += `<path d="M150 462 l56 -100 M172 462 l44 -80" stroke="#fff" stroke-width="5" stroke-linecap="round" opacity=".35"/>`;
  s += `<rect x="112" y="462" width="266" height="9" rx="2" fill="#9c5b3c" ${S(3)}/>`;
  // lamp
  s += `<circle cx="384" cy="346" r="15" fill="#f6c768" opacity=".35"/><path d="M384 328 v10" ${S(3)}/><path d="M376 338 h16 l-3 14 h-10 z" fill="#f6c768" ${S(3)}/>`;
  // door
  s += `<rect x="398" y="326" width="112" height="142" rx="4" fill="#3e5b41" ${S()}/>`;
  s += `<rect x="414" y="340" width="80" height="62" rx="4" fill="#d7ebee" ${S(3)}/>`;
  s += `<path d="M424 394 l26 -46 M440 396 l22 -40" stroke="#fff" stroke-width="3" stroke-linecap="round" opacity=".6"/>`;
  s += `<rect x="414" y="412" width="80" height="44" rx="3" fill="none" stroke="#2c4330" stroke-width="3"/>`;
  s += `<circle cx="499" cy="410" r="4.5" fill="#f2c46b" stroke="${INK}" stroke-width="2"/>`;
  s += `<rect x="390" y="466" width="128" height="10" rx="2" fill="#bba184" ${S(3)}/>`;
  // number plaque
  s += `<circle cx="103" cy="300" r="10" fill="#fbefd9" stroke="${INK}" stroke-width="2"/><text x="103" y="304" text-anchor="middle" font-family="Georgia,serif" font-size="10" font-weight="700" fill="${INK}">14</text>`;
  // chalkboard
  s += `<path d="M40 472 L54 386 M94 472 L80 386" ${S(4)}/>`;
  s += `<rect x="36" y="388" width="62" height="68" rx="4" fill="#2f3a33" ${S(3)}/>`;
  s += `<g font-family="Segoe Print,Bradley Hand,Comic Sans MS,cursive" fill="#f4efe4" text-anchor="middle"><text x="67" y="404" font-size="9" letter-spacing="2">TODAY</text><text x="67" y="420" font-size="10.5">cardamom</text><text x="67" y="434" font-size="10.5">knots!</text></g>`;
  s += `<path d="M67 441 c-3 -4 -8 0 0 6 c8 -6 3 -10 0 -6z" fill="#e86f5a"/>`;
  // planter
  s += `<ellipse cx="572" cy="404" rx="9" ry="20" transform="rotate(-30 572 404)" fill="#5f9a5a" ${S(2.5)}/><ellipse cx="590" cy="402" rx="9" ry="22" transform="rotate(25 590 402)" fill="#7db46c" ${S(2.5)}/><ellipse cx="580" cy="396" rx="8" ry="24" fill="#6aa864" ${S(2.5)}/>`;
  s += `<path d="M558 436 h44 l-6 32 h-32 z" fill="#c8553d" ${S(3)}/><rect x="553" y="429" width="54" height="10" rx="2" fill="#a9402b" ${S(3)}/>`;
  s += `</g>`;
  // door sign (live)
  s += `<g class="door-sign"><path d="M440 344 L432 358 M468 344 L476 358" stroke="${INK}" stroke-width="2"/><circle cx="454" cy="343" r="2.5" fill="${INK}"/>
    <rect x="418" y="356" width="72" height="26" rx="5" fill="#fbefd9" stroke="${INK}" stroke-width="2.5"/>
    <text id="doorText" x="454" y="374" text-anchor="middle" font-family="system-ui,Segoe UI,Arial,sans-serif" font-weight="800" font-size="12.5" letter-spacing="1" fill="#2f7a4a">OPEN</text></g>`;
  s += `</svg>`;
  $('#heroArt').innerHTML = s;
}

/* ---------- today's bakes ---------- */
function buildBakes(){
  $('#bakesGrid').innerHTML = MENU.map((p,i) => {
    const contains = [!p.tags.includes('nf')&&'nuts', !p.tags.includes('gf')&&'gluten'].filter(Boolean);
    return `<article class="card">
      <div class="card-art" style="--bg:${BG[i%BG.length]}">${pastrySVG(p.id)}<span class="oven">Out at ${p.oven}</span></div>
      <h3>${p.name}</h3>
      <p class="desc">${p.desc}</p>
      <div class="tags">${p.tags.map(t=>`<span class="tag">${TAGS[t].label}</span>`).join('')}${contains.length?`<span class="contains">Contains ${contains.join(' &amp; ')}</span>`:''}</div>
      <div class="card-foot"><span class="price">${money(p.price)}</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('');
}

/* ---------- configurator ---------- */
const state = { size:6, slots:Array(6).fill(null), filters:new Set(), drawer:false };
const floor = $('#floor'), palette = $('#palette'), boxEl = $('#box');
let slotEls = [], slotTok = [], tokCounter = 0;
const choiceRng = mulberry32(42);

function sizeIcon(n){
  const c=SIZES[n].cols, r=n/c, cw=26/c, ch=18/r;
  let s=`<svg width="34" height="26" viewBox="0 0 34 26" aria-hidden="true"><rect x="1.5" y="1.5" width="31" height="23" rx="4" fill="none" stroke="currentColor" stroke-width="2"/>`;
  for(let y=0;y<r;y++) for(let x=0;x<c;x++) s+=`<circle cx="${f1(4+cw*(x+.5))}" cy="${f1(4+ch*(y+.5))}" r="${f1(Math.min(cw,ch)*.34)}" fill="currentColor"/>`;
  return s+'</svg>';
}
const FICON = {
  v:`<svg width="20" height="20" viewBox="0 0 20 20" aria-hidden="true"><path d="M4 16C4 7 9 4 17 3C17 11 13 16 4 16Z" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round"/><path d="M4 16L12 8" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>`,
  nf:`<svg width="20" height="20" viewBox="0 0 20 20" aria-hidden="true"><path d="M5 9Q10 3 15 9Z" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round"/><path d="M6 9q0 6 4 8q4 -2 4 -8" fill="none" stroke="currentColor" stroke-width="2"/><path d="M3 3L17 17" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>`,
  gf:`<svg width="20" height="20" viewBox="0 0 20 20" aria-hidden="true"><path d="M10 18V5M10 8q-4 -1 -4 -4q4 1 4 4M10 8q4 -1 4 -4q-4 1 -4 4M10 13q-4 -1 -4 -4q4 1 4 4M10 13q4 -1 4 -4q-4 1 -4 4" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linejoin="round"/><path d="M3 3L17 17" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>`
};

function buildControls(){
  $('#sizes').innerHTML = [4,6,12].map(n => `<button class="size-btn" type="button" data-size="${n}" aria-pressed="false" aria-label="Box of ${n}">${sizeIcon(n)}<span><b>${n}</b><small>${SIZES[n].desc}</small></span></button>`).join('');
  $('#filters').innerHTML = ['v','nf','gf'].map(t => `<button class="chip" type="button" data-f="${t}" aria-pressed="false">${FICON[t]}${TAGS[t].label}</button>`).join('');
  palette.innerHTML = MENU.map(p => `<button class="pick" type="button" data-id="${p.id}" aria-label="Add ${p.name}, ${money(p.price)}"><span class="qty" hidden></span><span class="badges">${p.tags.map(t=>`<i>${TAGS[t].short}</i>`).join('')}</span>${pastrySVG(p.id)}<span class="nm">${p.name}</span><span class="pr">${money(p.price)}</span></button>`).join('');
  $('#sticker').innerHTML = logo(36);
}
function renderSizes(){ $$('.size-btn').forEach(b => b.setAttribute('aria-pressed', String(+b.dataset.size===state.size))); }

function renderBox(animate){
  const n = state.size;
  floor.style.setProperty('--cols', SIZES[n].cols);
  floor.innerHTML = state.slots.map((_,i) => `<button class="slot" type="button" data-i="${i}"><span class="ring">${i+1}</span><span class="liner">${LINER}</span><span class="pz"></span></button>`).join('');
  slotEls = Array.from(floor.children);
  slotTok = state.slots.map(() => 0);
  state.slots.forEach((id,i) => {
    setSlot(i);
    if(id && animate){ const pz=slotEls[i].querySelector('.pz'); pz.style.animationDelay=(i*45)+'ms'; pz.classList.add('pop'); }
  });
  floor.classList.remove('settle'); void floor.offsetWidth; floor.classList.add('settle');
  $('#stamp').textContent = `Hollow Oak · box of ${n}`;
  $('#boxName').textContent = `Box of ${n}`;
  $('#mbDots').innerHTML = state.slots.map(() => '<i></i>').join('');
  afterChange();
}

function setSlot(i, mode){
  const el = slotEls[i]; if(!el) return;
  const id = state.slots[i], pz = el.querySelector('.pz');
  pz.classList.remove('pop','out'); pz.style.visibility=''; pz.style.animationDelay='';
  if(id){
    const p = BY_ID[id];
    el.classList.add('filled');
    if(pz.dataset.id !== id){ pz.innerHTML = pastrySVG(id); pz.dataset.id = id; }
    el.setAttribute('aria-label', `${p.name} in slot ${i+1}. Tap to remove.`);
    if(mode==='pending') pz.style.visibility='hidden';
    else if(mode==='pop'){ void pz.offsetWidth; pz.classList.add('pop'); }
  } else {
    el.classList.remove('filled','mismatch');
    pz.innerHTML=''; pz.dataset.id='';
    el.setAttribute('aria-label', `Empty slot ${i+1}`);
  }
}

function isVisible(el){ const r=el.getBoundingClientRect(); return r.width>0 && r.bottom>64 && r.top<innerHeight-20; }

function fly(srcSvg, target, done){
  const a=srcSvg.getBoundingClientRect(), b=target.getBoundingClientRect();
  if(!a.width || !b.width || !srcSvg.animate){ done(); return; }
  const c = srcSvg.cloneNode(true);
  Object.assign(c.style,{position:'fixed',left:a.left+'px',top:a.top+'px',width:a.width+'px',height:a.height+'px',margin:'0',zIndex:'70',pointerEvents:'none',transformOrigin:'0 0',filter:'drop-shadow(0 6px 6px rgba(59,36,22,.3))'});
  document.body.appendChild(c);
  const s=b.width/a.width, dx=b.left-a.left, dy=b.top-a.top, lift=Math.min(130, Math.abs(dx)*.25+60);
  const anim = c.animate([
    {transform:'translate(0px,0px) scale(1)'},
    {transform:`translate(${dx*.5}px,${dy*.5-lift}px) scale(${(1+s)/2*1.12}) rotate(-8deg)`, offset:.5},
    {transform:`translate(${dx}px,${dy}px) scale(${s})`}
  ], {duration:520, easing:'cubic-bezier(.45,0,.4,1)'});
  let finished=false; const fin=()=>{ if(finished) return; finished=true; c.remove(); done(); };
  anim.onfinish = fin; setTimeout(fin, 900);
}

function addPastry(id, srcEl){
  const i = state.slots.indexOf(null);
  if(i < 0){ boxFull(); return false; }
  state.slots[i] = id;
  const tok = ++tokCounter; slotTok[i] = tok;
  const slotEl = slotEls[i];
  const svg = srcEl && srcEl.querySelector('svg');
  const canFly = !!svg && !REDUCED && isVisible(slotEl) && isVisible(srcEl);
  setSlot(i, canFly ? 'pending' : 'pop');
  if(canFly) fly(svg, slotEl.querySelector('.pz'), () => { if(slotTok[i]===tok && state.slots[i]===id) setSlot(i,'pop'); });
  Sound.pop(i);
  afterChange(i);
  const cb=$('#cartBtn'); cb.classList.remove('bump'); void cb.offsetWidth; cb.classList.add('bump');
  if(!isVisible(slotEl)) toast(`Added ${BY_ID[id].name} · ${state.slots.filter(Boolean).length} of ${state.size}`);
  if(state.slots.indexOf(null) < 0) setTimeout(celebrate, canFly ? 560 : 260);
  return true;
}

function removeAt(i){
  const id = state.slots[i]; if(!id) return;
  const el = slotEls[i]; if(el.classList.contains('removing')) return;
  el.classList.add('removing');
  const pz = el.querySelector('.pz'); pz.style.visibility=''; pz.classList.remove('pop'); pz.classList.add('out');
  Sound.remove();
  const tok = ++tokCounter; slotTok[i] = tok;
  setTimeout(() => {
    el.classList.remove('removing');
    if(slotTok[i] !== tok || slotEls[i] !== el) return;
    state.slots[i] = null; setSlot(i); afterChange();
  }, REDUCED ? 0 : 190);
}

function boxFull(){
  boxEl.classList.remove('shake'); void boxEl.offsetWidth; boxEl.classList.add('shake');
  Sound.nope();
  toast(state.size < 12 ? `Your box of ${state.size} is full. Tap a pastry in the box to swap it, or pick a bigger box.` : 'Your box of 12 is full. Tap a pastry in the box to swap it out.');
}

function celebrate(){
  if(state.slots.indexOf(null) >= 0) return;
  Sound.full();
  const lid=$('#lid'); lid.classList.remove('happy'); void lid.offsetWidth; lid.classList.add('happy');
  if(!REDUCED){
    const stage=$('#boxStage'), r=mulberry32(state.size*7+3), cols=['#c8553d','#f2c46b','#6aa864','#fbefd9','#93b6d4'];
    for(let k=0;k<14;k++){
      const c=document.createElement('span'); c.className='crumb';
      const a=-Math.PI/2+(r()-.5)*Math.PI*1.3, d=90+r()*90;
      c.style.setProperty('--dx', f1(Math.cos(a)*d)+'px'); c.style.setProperty('--dy', f1(Math.sin(a)*d)+'px');
      c.style.background=cols[k%cols.length]; c.style.animationDelay=(k*12)+'ms';
      stage.appendChild(c); setTimeout(()=>c.remove(), 1100);
    }
  }
  const disc=SIZES[state.size].disc;
  toast(disc ? `Box full! You're saving ${Math.round(disc*100)}%.` : 'Box full! Ready when you are.');
}

const totalEl=$('#total'); let shownTotal=0, tweenRaf=0;
function tweenTotal(to){
  cancelAnimationFrame(tweenRaf);
  const from=shownTotal, t0=performance.now();
  if(REDUCED){ shownTotal=to; totalEl.textContent=money(to); return; }
  const step=now=>{ const k=Math.min(1,(now-t0)/380), e=1-Math.pow(1-k,3); shownTotal=from+(to-from)*e; totalEl.textContent=money(shownTotal); if(k<1) tweenRaf=requestAnimationFrame(step); else shownTotal=to; };
  tweenRaf=requestAnimationFrame(step);
}
function calc(){
  const items=state.slots.filter(Boolean), n=items.length, size=state.size;
  const sub=items.reduce((s,id)=>s+BY_ID[id].price,0), rate=SIZES[size].disc, full=n===size;
  const save=full?Math.round(sub*rate*100)/100:0;
  return {items,n,size,sub,rate,full,save,total:sub-save};
}
function afterChange(newIdx){
  const c=calc();
  $('#fillCount').textContent = `${c.n} of ${c.size} filled`;
  $('#progress').style.width = (c.n/c.size*100)+'%';
  $('#hint').textContent = c.n===0 ? 'Your box is empty. Tap a pastry to drop it in.'
    : c.full ? (c.rate ? `Full box! ${Math.round(c.rate*100)}% off is applied.` : 'Full box! Ready when you are.')
    : `${c.size-c.n} more to fill the box${c.rate?` and save ${Math.round(c.rate*100)}%`:''}.`;
  $('#subtotal').textContent = money(c.sub);
  $('#saveRow').hidden = !c.save;
  $('#saveLabel').textContent = `Full box (${Math.round(c.rate*100)}% off)`;
  $('#saving').textContent = '-' + money(c.save);
  tweenTotal(c.total);
  $('#checkoutBtn').disabled = c.n===0;
  $('#mbCheckout').disabled = c.n===0;
  $('#cartCount').textContent = `${c.n}/${c.size}`;
  $('#mbCount').textContent = `${c.n} of ${c.size} in your box`;
  $('#mbTotal').textContent = money(c.total);
  $$('#mbDots i').forEach((d,i)=>{ d.classList.toggle('on', !!state.slots[i]); d.classList.remove('new'); });
  if(typeof newIdx==='number'){ const d=$$('#mbDots i')[newIdx]; if(d){ void d.offsetWidth; d.classList.add('new'); } }
  // next empty slot
  const nx = state.slots.indexOf(null);
  slotEls.forEach((el,i)=>el.classList.toggle('next', i===nx));
  // qty badges
  const counts={}; c.items.forEach(id=>counts[id]=(counts[id]||0)+1);
  $$('.pick').forEach(el=>{ const q=counts[el.dataset.id]||0, b=el.querySelector('.qty'); b.hidden=!q; b.textContent='×'+q; });
  updateMismatch();
}
function updateMismatch(){
  let k=0;
  slotEls.forEach((el,i)=>{ const id=state.slots[i]; const bad=!!id && !matches(BY_ID[id]); el.classList.toggle('mismatch',bad); if(bad) k++; });
  const note=$('#mismatchNote');
  note.hidden=!k;
  if(k){ const names=[...state.filters].map(t=>TAGS[t].label.toLowerCase()).join(' + '); note.textContent=`${k} item${k>1?'s':''} in your box ${k>1?"aren't":"isn't"} ${names}. Tap to remove ${k>1?'them':'it'}.`; }
}
function updateFilters(){
  let m=0;
  $$('.pick').forEach(el=>{ const ok=matches(BY_ID[el.dataset.id]); el.classList.toggle('dim',!ok); el.setAttribute('aria-disabled',String(!ok)); if(ok) m++; });
  $$('.chip').forEach(b=>b.setAttribute('aria-pressed',String(state.filters.has(b.dataset.f))));
  $('#matchCount').textContent = state.filters.size ? `${m} of ${MENU.length} match` : `All ${MENU.length} pastries`;
  updateMismatch();
}
function whyNot(p){
  const r=[];
  if(state.filters.has('v') && !p.tags.includes('v')) r.push("isn't vegan");
  if(state.filters.has('nf') && !p.tags.includes('nf')) r.push('contains nuts');
  if(state.filters.has('gf') && !p.tags.includes('gf')) r.push('contains gluten');
  return `${p.name} ${r.join(' and ')}. Switch the filter off to add it.`;
}
function setSize(n){
  if(n===state.size) return;
  const items=state.slots.filter(Boolean), kept=items.slice(0,n), dropped=items.length-kept.length;
  state.size=n; state.slots=Array(n).fill(null); kept.forEach((id,i)=>state.slots[i]=id);
  renderSizes(); renderBox(true); Sound.click();
  if(dropped>0) toast(`${dropped} pastr${dropped>1?'ies':'y'} didn't fit in a box of ${n}, so we set ${dropped>1?'them':'it'} aside.`);
}
function emptyBox(silent){
  if(!state.slots.some(Boolean)){ if(!silent) toast('Your box is already empty.'); return; }
  state.slots=Array(state.size).fill(null); renderBox(false);
  if(!silent){ Sound.remove(); toast('Box emptied. Start fresh!'); }
}
function bakersChoice(){
  const pool=MENU.filter(p=>matches(p)), empties=state.slots.filter(s=>!s).length;
  if(!empties){ boxFull(); return; }
  for(let k=0;k<empties;k++){
    const p=pool[Math.floor(choiceRng()*pool.length)];
    setTimeout(()=>addPastry(p.id, palette.querySelector(`.pick[data-id="${p.id}"]`)), k*150);
  }
}

/* events */
$('#sizes').addEventListener('click', e=>{ const b=e.target.closest('.size-btn'); if(b) setSize(+b.dataset.size); });
$('#filters').addEventListener('click', e=>{
  const b=e.target.closest('.chip'); if(!b) return;
  const f=b.dataset.f; state.filters.has(f)?state.filters.delete(f):state.filters.add(f);
  updateFilters(); Sound.click();
});
palette.addEventListener('click', e=>{
  const el=e.target.closest('.pick'); if(!el) return;
  const p=BY_ID[el.dataset.id];
  if(!matches(p)){ el.classList.remove('wiggle'); void el.offsetWidth; el.classList.add('wiggle'); Sound.nope(); toast(whyNot(p)); return; }
  addPastry(p.id, el);
});
floor.addEventListener('click', e=>{
  const s=e.target.closest('.slot'); if(!s) return;
  const i=+s.dataset.i;
  if(state.slots[i]) removeAt(i); else toast('Empty spot. Tap a pastry to fill it.');
});
$('#bakesGrid').addEventListener('click', e=>{
  const b=e.target.closest('[data-add]'); if(!b) return;
  const card=b.closest('.card');
  if(addPastry(b.dataset.add, card.querySelector('.card-art')) && !isVisible(floor)) {/* toast shown in addPastry */}
});
$('#clearBtn').addEventListener('click', ()=>emptyBox(false));
$('#choiceBtn').addEventListener('click', bakersChoice);
$('#checkoutBtn').addEventListener('click', openDrawer);
$('#mbCheckout').addEventListener('click', openDrawer);
$('#mbView').addEventListener('click', ()=>$('.box-panel').scrollIntoView({behavior:REDUCED?'auto':'smooth',block:'center'}));
$('#cartBtn').addEventListener('click', ()=>goto('build'));
function goto(id){
  if(id==='top'){ window.scrollTo({top:0,behavior:REDUCED?'auto':'smooth'}); return; }
  const t=document.getElementById(id); if(t) t.scrollIntoView({behavior:REDUCED?'auto':'smooth',block:'start'});
}
document.addEventListener('click', e=>{ const g=e.target.closest('[data-goto]'); if(g) goto(g.dataset.goto); });

/* ---------- drawer ---------- */
const drawer=$('#drawer'), scrim=$('#scrim'); let lastFocus=null;
function pickupCode(){
  const h=hashStr(state.slots.map(s=>s||'-').join('|')+'#'+state.size).toString(36).toUpperCase().padStart(6,'0').slice(-6);
  return `HO-${h.slice(0,3)}-${h.slice(3)}`;
}
function buildSummary(){
  const c=calc(), counts=new Map();
  c.items.forEach(id=>counts.set(id,(counts.get(id)||0)+1));
  const st=getStatus();
  $('#drawerSub').textContent = `Box of ${c.size} · ${c.n} pastr${c.n===1?'y':'ies'}${c.full?'':` · ${c.size-c.n} empty`}`;
  let h=`<div class="mini-box" style="--cols:${SIZES[c.size].cols}" aria-hidden="true">${state.slots.map(id=>`<span>${id?pastrySVG(id):''}</span>`).join('')}</div>`;
  counts.forEach((q,id)=>{ const p=BY_ID[id]; h+=`<div class="line">${pastrySVG(id)}<div><b>${p.name}</b><small>${q} × ${money(p.price)}</small></div><span class="amt">${money(q*p.price)}</span></div>`; });
  h+=`<div class="totals"><div><span>Subtotal</span><span>${money(c.sub)}</span></div>`;
  if(c.save) h+=`<div class="save"><span>Full box, ${Math.round(c.rate*100)}% off</span><span>-${money(c.save)}</span></div>`;
  else if(c.rate) h+=`<div style="color:var(--ink2);font-size:13.5px"><span>Fill all ${c.size} spots to save ${Math.round(c.rate*100)}%</span><span></span></div>`;
  h+=`<div class="grand"><span>Total</span><span>${money(c.total)}</span></div></div>`;
  h+=`<div class="pickup"><small>Your pickup code</small><div class="code">${pickupCode()}</div><p>${st.open?`We're open now, until ${fmtMin(HOURS[new Date().getDay()][1])}. Show this at the counter and we'll pack it while the kettle boils.`:`We're closed right now. ${st.next}. Show this at the counter and we'll pack it fresh.`}</p></div>`;
  h+=`<p class="note">This is a summary only. Nothing is sent or charged from this page; you pay at the counter.</p>`;
  $('#drawerBody').innerHTML=h;
}
function openDrawer(){
  if(!state.slots.some(Boolean)){ Sound.nope(); toast('Your box is empty. Add a pastry first.'); return; }
  buildSummary();
  lastFocus=document.activeElement;
  drawer.classList.add('open'); drawer.setAttribute('aria-hidden','false');
  scrim.classList.add('show'); document.body.classList.add('locked');
  state.drawer=true; updateMiniVis(); Sound.whoosh();
  $('#drawerBody').scrollTop=0;
  setTimeout(()=>{ try{ $('#drawerClose').focus({preventScroll:true}); }catch(e){} }, 60);
}
function closeDrawer(){
  if(!state.drawer) return;
  drawer.classList.remove('open'); drawer.setAttribute('aria-hidden','true');
  scrim.classList.remove('show'); document.body.classList.remove('locked');
  state.drawer=false; updateMiniVis();
  if(lastFocus && lastFocus.focus){ try{ lastFocus.focus({preventScroll:true}); }catch(e){} }
}
$('#drawerClose').addEventListener('click', closeDrawer);
$('#keepEditing').addEventListener('click', closeDrawer);
scrim.addEventListener('click', closeDrawer);
$('#newBox').addEventListener('click', ()=>{ closeDrawer(); emptyBox(true); toast('Fresh box, ready to fill.'); Sound.click(); });
document.addEventListener('keydown', e=>{ if(e.key==='Escape' && state.drawer) closeDrawer(); });
drawer.addEventListener('keydown', e=>{
  if(e.key!=='Tab') return;
  const f=$$('button',drawer).filter(b=>!b.disabled); if(!f.length) return;
  const 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(); }
});

/* mini bar visibility */
let buildVisible=false;
function updateMiniVis(){ $('#minibar').classList.toggle('show', buildVisible && !state.drawer); }
if('IntersectionObserver' in window){
  new IntersectionObserver(es=>{ es.forEach(en=>buildVisible=en.isIntersecting); updateMiniVis(); }, {rootMargin:'-25% 0px -15% 0px'}).observe($('#build'));
} else { buildVisible=true; updateMiniVis(); }

/* ---------- hours & live status ---------- */
const DAYS=['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
const HOURS={0:[480,780],1:null,2:[420,1020],3:[420,1020],4:[420,1020],5:[420,1080],6:[450,960]};
function fmtMin(m){ const d=new Date(2020,0,6,Math.floor(m/60),m%60); try{ return d.toLocaleTimeString([], {hour:'numeric',minute:'2-digit'}); }catch(e){ return `${Math.floor(m/60)}:${String(m%60).padStart(2,'0')}`; } }
function getStatus(now=new Date()){
  const d=now.getDay(), m=now.getHours()*60+now.getMinutes(), h=HOURS[d];
  if(h && m>=h[0] && m<h[1]){
    const left=h[1]-m;
    return {open:true, soon:left<=45, label:left<=45?'Closing soon':'Open now',
      text:left<=45?`Closing soon · ${left} min left`:`Open now · until ${fmtMin(h[1])}`,
      title:left<=45?'Last call for pastries!':'Come on in, the oven is warm.',
      detail:left<=45?`We close at ${fmtMin(h[1])}, so grab the last of today's bakes.`:`We're open until ${fmtMin(h[1])} today. ${left>=120?`That's ${Math.floor(left/60)} hours and ${left%60} minutes of croissant time.`:`About ${left} minutes to go.`}`};
  }
  let next='';
  if(h && m<h[0]) next=`We open today at ${fmtMin(h[0])}`;
  else for(let k=1;k<=7;k++){ const dd=(d+k)%7; if(HOURS[dd]){ next=`We open ${k===1?'tomorrow':DAYS[dd]} at ${fmtMin(HOURS[dd][0])}`; break; } }
  return {open:false, soon:false, label:'Closed', text:`Closed · ${next.replace('We open ','opens ')}`, title:"We're resting the dough.", detail:`${next}. The first croissants come out about twenty minutes later.`, next};
}
function renderHours(){
  const now=new Date(), d=now.getDay(), st=getStatus(now);
  const cls = st.open ? (st.soon?'soon':'open') : '';
  ['#heroDot','#topDot','#badgeDot'].forEach(s=>{ const el=$(s); el.className='dot'+(cls?' '+cls:''); });
  $('#heroStatus').textContent=st.text;
  $('#topStatusText').textContent=st.label;
  const b=$('#badge'); b.className='badge'+(cls?' '+cls:''); $('#badgeText').textContent=st.label;
  $('#statusTitle').textContent=st.title; $('#statusText').textContent=st.detail;
  let clock; try{ clock=now.toLocaleTimeString([], {hour:'numeric',minute:'2-digit'}); }catch(e){ clock=now.toTimeString().slice(0,5); }
  $('#clock').textContent=`It's ${clock} on ${DAYS[d]} where you are.`;
  const dt=$('#doorText'); if(dt){ dt.textContent=st.open?'OPEN':'CLOSED'; dt.setAttribute('fill', st.open?'#2f7a4a':'#b2412f'); }
  $('#hoursList').innerHTML=[1,2,3,4,5,6,0].map(i=>{ const h=HOURS[i]; return `<li class="${i===d?'today':''}"><span>${DAYS[i]}${i===d?'<span class="today-tag">Today</span>':''}</span>${h?`<span>${fmtMin(h[0])} – ${fmtMin(h[1])}</span>`:'<span class="shut">Closed</span>'}</li>`; }).join('');
}

/* ---------- reset ---------- */
function resetAll(silent){
  closeDrawer();
  state.filters.clear(); state.size=6; state.slots=Array(6).fill(null);
  renderSizes(); renderBox(false); updateFilters();
  if(!silent){ toast('Everything reset. Fresh from the oven!'); Sound.click(); window.scrollTo({top:0,behavior:REDUCED?'auto':'smooth'}); }
}
$('#restartBtn').addEventListener('click', ()=>resetAll(false));

/* ---------- performance guard ---------- */
function fpsCheck(){
  if(document.hidden || document.documentElement.classList.contains('lowfx')) return;
  let frames=0; const t0=performance.now();
  const f=t=>{ frames++; if(t-t0<2000) requestAnimationFrame(f); else if(frames*1000/(t-t0)<42) document.documentElement.classList.add('lowfx'); };
  requestAnimationFrame(f);
}

/* ---------- demo mode ---------- */
const demo={on:false,timers:new Set()}; const STOP={};
const ptr=$('#demoPtr'), demoTag=$('#demoTag');
function dwait(ms){ return new Promise((res,rej)=>{ const t=setTimeout(()=>{ demo.timers.delete(t); demo.on?res():rej(STOP); },ms); demo.timers.add(t); }); }
function movePtr(x,y){ ptr.style.transform=`translate(${x-4}px,${y-3}px)`; }
function ripple(x,y){ const r=document.createElement('div'); r.className='ripple'; r.style.left=x+'px'; r.style.top=y+'px'; document.body.appendChild(r); setTimeout(()=>r.remove(),600); }
async function dtap(el){
  if(!demo.on) throw STOP; if(!el) return;
  let r=el.getBoundingClientRect();
  const bottomSafe=innerHeight-(innerWidth<900?96:24);
  if(r.top<74 || r.bottom>bottomSafe){ el.scrollIntoView({block:'center',behavior:'smooth'}); await dwait(650); r=el.getBoundingClientRect(); }
  const x=r.left+r.width/2, y=r.top+r.height/2;
  movePtr(x,y); await dwait(580);
  ptr.classList.add('press'); ripple(x,y); await dwait(120);
  el.click(); ptr.classList.remove('press'); await dwait(380);
}
const pickEl = id => palette.querySelector(`.pick[data-id="${id}"]`);
async function demoLoop(){
  try{
    while(demo.on){
      resetAll(true);
      window.scrollTo({top:0,behavior:'auto'});
      movePtr(innerWidth*.62, innerHeight*.45);
      await dwait(1000);
      $('#build').scrollIntoView({behavior:'smooth',block:'start'});
      await dwait(900);
      await dtap($('.size-btn[data-size="4"]'));
      for(const id of ['croissant','cinnamon','tart','macaron']) await dtap(pickEl(id));
      await dwait(500);
      await dtap($('.size-btn[data-size="12"]'));
      await dtap($('.chip[data-f="v"]'));
      await dwait(350);
      await dtap(pickEl('cardamom'));
      await dtap(pickEl('cookie'));
      await dtap(slotEls[2]);
      await dtap($('.chip[data-f="v"]'));
      await dtap(pickEl('muffin'));
      await dtap($('#checkoutBtn'));
      await dwait(2300);
      await dtap($('#drawerClose'));
      await dtap($('#clearBtn'));
      await dwait(700);
    }
  }catch(e){ if(e!==STOP) console.error(e); }
}
function startDemo(){ demo.on=true; ptr.classList.add('on'); demoTag.hidden=false; demoLoop(); }
function stopDemo(){
  if(!demo.on) return;
  demo.on=false; demo.timers.forEach(clearTimeout); demo.timers.clear();
  ptr.classList.remove('on','press'); demoTag.hidden=true;
}
['pointerdown','keydown','wheel','touchstart'].forEach(ev=>window.addEventListener(ev, e=>{ if(demo.on && e.isTrusted) stopDemo(); }, {capture:true, passive:true}));

/* ---------- boot ---------- */
$('#logoTop').innerHTML=logo(40); $('#logoFoot').innerHTML=logo(44);
buildHero(); buildBakes(); buildControls();
renderSizes(); renderBox(false); updateFilters(); renderHours();
setInterval(renderHours, 20000);
document.addEventListener('visibilitychange', ()=>{ if(!document.hidden) renderHours(); });

requestAnimationFrame(()=>requestAnimationFrame(()=>{
  try{ parent.postMessage({vcb:'ready'}, '*'); }catch(e){}
  setTimeout(fpsCheck, 600);
  if(/#demo$/.test(location.href)) setTimeout(startDemo, 400);
}));
})();
</script>
</body>
</html>

Try 2 · index.html

works79.9 KB · 1,167 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>Larkspur Lane Bakehouse</title>
<meta name="description" content="A small neighborhood bakery. See today's bakes, build your own pastry box and check our opening hours.">
<style>
:root{
  --cream:#fbf4e6; --paper:#fffaf0; --ink:#3b2416; --ink2:#6b4c36; --line:rgba(59,36,22,.16);
  --kraft:#c99a62; --kraft-d:#a8773f; --berry:#c8475b; --berry-d:#a63546;
  --sage:#6f8f5e; --sage-d:#4f6d40; --butter:#f2c66d;
  --serif:"Iowan Old Style","Palatino Linotype",Palatino,"Book Antiqua",Georgia,serif;
  --sans:system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
  --hand:"Segoe Print","Bradley Hand","Marker Felt","Chalkboard SE","Comic Neue",cursive;
  color-scheme:light;
}
*{box-sizing:border-box}
[hidden]{display:none!important}
html{-webkit-text-size-adjust:100%}
body{margin:0;font-family:var(--sans);color:var(--ink);background-color:var(--cream);
  background-image:radial-gradient(rgba(59,36,22,.055) 1px,transparent 1.3px);background-size:22px 22px;
  line-height:1.55;overflow-x:hidden;-webkit-font-smoothing:antialiased}
body.locked{overflow:hidden}
h1,h2,h3{font-family:var(--serif);line-height:1.1;margin:0}
p{margin:0}
button{font:inherit;color:inherit}
:focus-visible{outline:3px solid var(--berry);outline-offset:3px}
.wrap{max-width:1160px;margin:0 auto;padding:0 16px}
.skip{position:absolute;left:12px;top:-60px;z-index:100;background:var(--ink);color:var(--cream);padding:12px 16px;border-radius:10px;text-decoration:none}
.skip:focus{top:12px}
.pa{display:block;width:100%;height:100%;overflow:visible}
.pa .sh{opacity:.15}
.pa .sh *{fill:#4a2c17!important;stroke:#4a2c17!important}

/* buttons */
.btn{display:inline-flex;align-items:center;justify-content:center;gap:8px;min-height:48px;padding:0 22px;border-radius:999px;
  border:2.5px solid var(--ink);font:700 1rem/1 var(--sans);cursor:pointer;text-decoration:none;color:var(--ink);
  background:var(--paper);box-shadow:0 4px 0 var(--ink);transition:transform .12s,box-shadow .12s,opacity .2s;
  -webkit-tap-highlight-color:transparent;touch-action:manipulation;user-select:none;white-space:nowrap}
.btn:active{transform:translateY(3px);box-shadow:0 1px 0 var(--ink)}
.btn-primary{background:var(--berry);color:#fff}
.btn-small{min-height:44px;padding:0 16px;font-size:.92rem}
.btn[disabled]{opacity:.42;cursor:not-allowed;transform:none;box-shadow:0 4px 0 var(--ink)}
@media (hover:hover){.btn:not([disabled]):hover{transform:translateY(-1px);box-shadow:0 5px 0 var(--ink)}}

/* header */
.site-head{position:relative;z-index:30;background:rgba(251,244,230,.94);border-bottom:2px solid var(--line)}
@media (min-width:900px){.site-head{position:sticky;top:0;backdrop-filter:blur(8px);-webkit-backdrop-filter:blur(8px)}}
.head-in{display:flex;align-items:center;gap:14px;min-height:66px}
.brand{display:flex;align-items:center;gap:10px;text-decoration:none;color:var(--ink);min-height:44px}
.brand-mark{width:44px;height:44px;border-radius:50%;background:var(--butter);border:2.5px solid var(--ink);padding:4px;flex:none}
.brand b{font-family:var(--serif);font-size:1.12rem;display:block;line-height:1.05}
.brand small{font-family:var(--hand);color:var(--berry);font-size:.86rem;display:block;line-height:1.15}
.nav{display:flex;gap:2px;margin-left:auto}
.nav a{padding:0 14px;min-height:44px;display:inline-flex;align-items:center;border-radius:999px;color:var(--ink);text-decoration:none;font-weight:650}
@media (hover:hover){.nav a:hover{background:rgba(59,36,22,.07)}}
.head-actions{display:flex;gap:8px;align-items:center}
@media (max-width:699px){.nav{display:none}.head-actions{margin-left:auto}}
.icon-btn{width:44px;height:44px;border-radius:50%;border:2.5px solid var(--ink);background:var(--paper);display:grid;place-items:center;cursor:pointer;padding:0;flex:none;touch-action:manipulation}
.icon-btn svg{display:block}
.box-chip{min-height:44px;padding:0 14px 0 10px;border-radius:999px;border:2.5px solid var(--ink);background:var(--butter);font-weight:800;display:inline-flex;align-items:center;gap:6px;cursor:pointer;font-variant-numeric:tabular-nums;touch-action:manipulation}
.box-chip.bump{animation:bump .35s}

/* hero */
.hero{padding:34px 0 56px;position:relative}
.hero-grid{display:grid;gap:30px;align-items:center}
@media (min-width:900px){.hero-grid{grid-template-columns:1fr 1.08fr;gap:52px}.hero{padding:56px 0 84px}}
.eyebrow{display:block;font:800 .76rem/1.2 var(--sans);letter-spacing:.15em;text-transform:uppercase;color:var(--sage-d)}
.hero h1{font-size:clamp(2.5rem,7.2vw,4.5rem);margin:10px 0 16px;letter-spacing:-.01em}
.hero h1 .script{display:block;font-family:var(--hand);font-weight:400;color:var(--berry);font-size:.6em;transform:rotate(-2.5deg);transform-origin:left;margin-top:6px}
.story{font-size:1.06rem;max-width:34em;color:var(--ink2)}
.cta-row{display:flex;flex-wrap:wrap;gap:12px;margin:24px 0 20px}
.status{display:inline-flex;align-items:center;gap:9px;padding:8px 15px;border-radius:999px;font-weight:750;font-size:.93rem;border:2px solid currentColor;background:var(--paper);min-height:40px}
.status .dot{width:10px;height:10px;border-radius:50%;background:currentColor;animation:pulse 2s infinite;flex:none}
.status .txt{color:var(--ink)}
.status.open{color:#3f7a3a}.status.soon{color:#b7791f}.status.closed{color:var(--berry-d)}
.status.big{font-size:1.04rem;padding:10px 18px}
.hero-facts{display:flex;flex-wrap:wrap;gap:8px 18px;margin-top:18px;color:var(--ink2);font-size:.9rem}
.hero-facts span::before{content:"✶ ";color:var(--berry)}
.hero-art{position:relative;background:var(--paper);border:2.5px solid var(--ink);border-radius:28px;padding:8px;box-shadow:8px 8px 0 var(--ink);transform:rotate(1deg)}
.hero-art svg{width:100%;height:auto;display:block;border-radius:20px}
.hero-art .caption{position:absolute;left:18px;bottom:-18px;background:var(--butter);border:2px solid var(--ink);border-radius:999px;padding:4px 14px;font-family:var(--hand);font-size:.9rem;transform:rotate(-3deg)}
.puff{animation:puff 4.8s ease-in infinite;transform-box:fill-box;transform-origin:center;opacity:0}
.sway{transform-box:fill-box;transform-origin:50% 0;animation:sway 3.4s ease-in-out infinite}

/* sections */
.sec{padding:52px 0;scroll-margin-top:76px}
.sec-head{display:flex;flex-wrap:wrap;align-items:flex-end;justify-content:space-between;gap:12px 24px;margin-bottom:26px}
.sec-head h2{font-size:clamp(2rem,4.6vw,2.9rem);margin-top:6px}
.sec-head p{margin-top:8px;color:var(--ink2);max-width:36em}
.hand-note{font-family:var(--hand);color:var(--berry);font-size:1.05rem;transform:rotate(-2deg)}
.divider{display:flex;justify-content:center;opacity:.55;margin:4px 0}

/* bakes */
.bakes{display:grid;gap:22px 18px;grid-template-columns:repeat(auto-fill,minmax(260px,1fr))}
.bake{position:relative;background:var(--paper);border:2.5px solid var(--ink);border-radius:22px;padding:18px;display:grid;grid-template-columns:92px 1fr;gap:4px 16px;align-items:center;box-shadow:5px 5px 0 var(--ink)}
.plate{width:92px;height:92px;border-radius:50%;background:radial-gradient(circle,#fff 56%,#efe3cf 57.5%,#fff 60%,#f4ead9 100%);border:2px solid var(--ink);display:grid;place-items:center}
.plate .pa{width:74px;height:74px}
.bake h3{font-size:1.18rem}
.bake .time{font-size:.8rem;color:var(--sage-d);font-weight:750;margin-top:3px}
.bake .tags{margin-top:6px;display:flex;gap:5px;flex-wrap:wrap}
.bake p{grid-column:1/-1;margin-top:10px;font-size:.94rem;color:var(--ink2)}
.bake .row{grid-column:1/-1;display:flex;align-items:center;justify-content:space-between;gap:8px;margin-top:12px}
.bake .price{font:800 1.2rem var(--sans);color:var(--berry-d)}
.ribbon{position:absolute;top:-13px;right:16px;background:var(--butter);border:2px solid var(--ink);border-radius:999px;padding:2px 12px;font:800 .74rem/1.6 var(--sans);transform:rotate(3deg);letter-spacing:.04em}

.tag{display:inline-grid;place-items:center;height:21px;padding:0 6px;border-radius:6px;font:800 .66rem/1 var(--sans);letter-spacing:.05em;border:1.5px solid currentColor}
.tag-vegan{color:#3f7a3a;background:#e6f0dc}.tag-nutfree{color:#8a5a1f;background:#f7e9cf}.tag-gf{color:#2f6c8a;background:#e0eef5}

/* builder */
.builder{display:grid;gap:26px;align-items:start}
@media (min-width:900px){.builder{grid-template-columns:minmax(0,1fr) 430px}.panel{position:sticky;top:84px}}
.step{margin-bottom:26px}
.step-h{display:flex;align-items:center;gap:10px;font:700 1.12rem var(--serif);margin:0 0 12px}
.step-n{width:30px;height:30px;border-radius:50%;background:var(--ink);color:var(--cream);display:grid;place-items:center;font:800 .88rem var(--sans);flex:none}
.step-h .spacer{flex:1}
.sizes{display:grid;grid-template-columns:repeat(3,1fr);gap:10px}
.size{border:2.5px solid var(--ink);background:var(--paper);border-radius:18px;padding:12px 6px 10px;cursor:pointer;display:flex;flex-direction:column;align-items:center;gap:5px;min-height:44px;touch-action:manipulation;box-shadow:0 4px 0 var(--ink);transition:transform .12s,box-shadow .12s,background .2s}
.size:active{transform:translateY(3px);box-shadow:0 1px 0 var(--ink)}
.size[aria-pressed="true"]{background:var(--butter)}
.size .dots{display:grid;gap:3px;margin-bottom:3px}
.size .dots i{width:9px;height:9px;border-radius:50%;background:var(--kraft-d);display:block}
.size[aria-pressed="true"] .dots i{background:var(--berry)}
.size b{font-size:1rem;line-height:1.1}
.size small{font-size:.74rem;color:var(--ink2);line-height:1.2;text-align:center}
.filters{display:flex;flex-wrap:wrap;gap:8px;align-items:center}
.filter{min-height:44px;padding:0 16px 0 12px;border-radius:999px;border:2px solid var(--ink);background:var(--paper);font-weight:650;font-size:.95rem;cursor:pointer;display:inline-flex;align-items:center;gap:8px;touch-action:manipulation;transition:background .2s,color .2s}
.filter .check{width:20px;height:20px;border-radius:6px;border:2px solid currentColor;display:grid;place-items:center;flex:none;background:var(--paper)}
.filter[aria-pressed="true"]{background:var(--sage);color:#fff}
.filter[aria-pressed="true"] .check::after{content:"";width:9px;height:5px;border-left:2.6px solid var(--sage-d);border-bottom:2.6px solid var(--sage-d);transform:translate(0,-1px) rotate(-45deg)}
.link-btn{min-height:44px;padding:0 10px;border:0;background:none;text-decoration:underline;font-weight:650;cursor:pointer;color:var(--ink2)}
.filter-note{font-size:.88rem;color:var(--ink2);margin-top:8px;min-height:1.4em}
.grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(148px,1fr));gap:12px}
@media (max-width:419px){.grid{grid-template-columns:repeat(2,minmax(0,1fr));gap:10px}}
.tile{position:relative;border:2.5px solid var(--ink);background:var(--paper);border-radius:18px;padding:14px 8px 10px;display:flex;flex-direction:column;align-items:center;text-align:center;gap:4px;cursor:pointer;
  transition:transform .14s,opacity .25s,filter .25s,box-shadow .14s;box-shadow:0 4px 0 var(--ink);touch-action:manipulation;-webkit-tap-highlight-color:transparent;min-height:44px;user-select:none}
.tile:active{transform:translateY(3px) scale(.98);box-shadow:0 1px 0 var(--ink)}
.tile-art{width:78px;height:78px;transition:transform .25s cubic-bezier(.3,1.5,.5,1);display:block}
.tile-name{font-weight:750;font-size:.92rem;line-height:1.2;margin-top:2px}
.tile-row{display:flex;gap:5px;align-items:center;justify-content:center;flex-wrap:wrap}
.tile-price{font-weight:850;color:var(--berry-d);margin-right:2px}
.tile-count{position:absolute;top:8px;left:8px;min-width:26px;height:26px;border-radius:999px;background:var(--ink);color:var(--cream);font:800 .8rem/26px var(--sans);text-align:center;padding:0 7px;transform:scale(0);transition:transform .22s cubic-bezier(.3,1.6,.5,1)}
.tile-count.has{transform:scale(1)}
.tile-add{position:absolute;top:8px;right:8px;width:26px;height:26px;border-radius:50%;border:2px solid var(--ink);background:var(--butter);font:900 1.05rem/22px var(--sans)}
.tile .miss{display:none;font-size:.72rem;font-weight:800;color:var(--berry-d);line-height:1.2}
.tile.dim{opacity:.36;filter:grayscale(.9);box-shadow:0 2px 0 rgba(59,36,22,.35)}
.tile.dim .miss{display:block}
@media (hover:hover){.tile:hover .tile-art{transform:rotate(-7deg) scale(1.07)}}

/* panel + box */
.panel{background:var(--paper);border:2.5px solid var(--ink);border-radius:26px;padding:18px 18px 20px;box-shadow:6px 6px 0 var(--ink);align-self:start}
.panel-head{display:flex;align-items:center;gap:12px;margin-bottom:14px}
.ph-title{display:flex;flex-direction:column;min-width:0}
.panel-title{font:700 1.3rem/1.15 var(--serif)}
.count{font-size:.85rem;color:var(--ink2);font-weight:650;font-variant-numeric:tabular-nums}
.panel-total{margin-left:auto;font:850 1.5rem var(--sans);font-variant-numeric:tabular-nums;color:var(--berry-d)}
.panel-total.bump{animation:bump .35s}
.head-checkout{display:none}
.box{width:100%;margin:0 auto;transition:width .3s}
.box[data-size="4"]{width:min(100%,290px)}
.box.shake{animation:shake .42s}
.box.happy{animation:happy .6s}
.box.pop{animation:boxpop .38s}
.lid{position:relative;height:42px;margin:0 8px -1px;background-color:#d6a86f;
  background-image:repeating-linear-gradient(90deg,rgba(91,59,32,.09) 0 2px,transparent 2px 9px);
  clip-path:polygon(5% 0,95% 0,100% 100%,0 100%);display:flex;align-items:center;justify-content:center;gap:9px;color:#5b3b20;font:800 .72rem var(--sans);letter-spacing:.14em;text-transform:uppercase}
.sticker{width:30px;height:30px;border-radius:50%;background:var(--berry);color:#fff;font:400 .85rem/1 var(--hand);display:grid;place-items:center;box-shadow:0 0 0 2px #fffaf0}
.tray{display:grid;grid-template-columns:repeat(var(--cols,3),minmax(0,1fr));gap:8px;padding:12px;border-radius:6px 6px 14px 14px;
  background-color:var(--kraft);background-image:repeating-linear-gradient(115deg,rgba(255,255,255,.05) 0 2px,transparent 2px 8px);
  box-shadow:inset 0 0 0 3px var(--kraft-d),inset 0 7px 14px rgba(59,36,22,.32),0 10px 22px rgba(59,36,22,.2)}
.slot{position:relative;aspect-ratio:1;border:0;padding:0;border-radius:12px;background:#b78550;box-shadow:inset 0 2px 6px rgba(59,36,22,.38);cursor:pointer;min-width:44px;min-height:44px;touch-action:manipulation;-webkit-tap-highlight-color:transparent}
.liner{position:absolute;inset:7%;border-radius:50%;background:repeating-conic-gradient(#fffaf0 0 9deg,#f1e2c8 9deg 18deg);box-shadow:0 1px 3px rgba(59,36,22,.25)}
.liner::after{content:"";position:absolute;inset:17%;border-radius:50%;background:#fbf1de;box-shadow:inset 0 1px 4px rgba(59,36,22,.15)}
.num{position:absolute;inset:0;display:grid;place-items:center;z-index:1;font-family:var(--hand);color:rgba(91,59,32,.4);font-size:clamp(.8rem,3vw,1.1rem)}
.slot.filled .num{display:none}
.item{position:absolute;inset:5%;z-index:2;display:block;pointer-events:none}
.item.pending{visibility:hidden}
.item.drop{animation:drop .55s cubic-bezier(.3,.7,.4,1) both}
.item.land{animation:land .42s ease-out both}
.item.leaving{animation:leave .24s ease-in forwards}
.slot.mismatch .item{opacity:.45;filter:grayscale(.8)}
.meter{height:12px;border-radius:999px;background:#efe3cf;border:2px solid var(--ink);overflow:hidden;margin-top:16px}
.meter span{display:block;height:100%;width:0;background:repeating-linear-gradient(45deg,var(--berry) 0 8px,#d9607a 8px 16px);transition:width .45s cubic-bezier(.3,1.4,.5,1)}
.panel-foot{margin-top:14px}
.hint{font-size:.9rem;color:var(--ink2)}
.deal{font-size:.86rem;font-weight:750;color:var(--sage-d);margin-top:4px}
.sums{margin:14px 0 16px;padding:12px 0 0;border-top:2px dashed var(--line)}
.sums div{display:flex;justify-content:space-between;padding:3px 0;font-variant-numeric:tabular-nums}
.sums dt{color:var(--ink2)}.sums dd{margin:0;font-weight:700}
.sums .save dd,.sums .save dt{color:var(--sage-d)}
.sums .grand{font-size:1.15rem;padding-top:6px}.sums .grand dt{color:var(--ink);font-weight:800}
.foot-checkout{width:100%}
@media (max-width:899px){
  .panel{position:sticky;top:0;z-index:25;order:-1;margin:0 -16px;border-radius:0 0 22px 22px;border-top:0;border-left:0;border-right:0;
    padding:10px 16px 12px;box-shadow:0 10px 18px rgba(59,36,22,.16)}
  .panel .lid,.panel .panel-foot,.panel .eyebrow{display:none}
  .head-checkout{display:inline-flex}
  .panel-head{margin-bottom:8px;gap:10px}
  .panel-title{font-size:1.08rem}
  .panel-total{font-size:1.18rem}
  .panel .box,.panel .box[data-size]{width:min(100%,max(calc(var(--cols) * 54px + 20px),calc(23vh * var(--cols) / var(--rows))))}
  .tray{padding:8px;gap:6px;border-radius:12px}
  .meter{margin-top:8px;height:8px;border-width:1.5px}
}

/* hours */
.hours-grid{display:grid;gap:24px}
@media (min-width:860px){.hours-grid{grid-template-columns:1.1fr 1fr}}
.card{background:var(--paper);border:2.5px solid var(--ink);border-radius:24px;padding:22px;box-shadow:6px 6px 0 var(--ink)}
.card h3{font-size:1.4rem;margin-bottom:12px}
.hours-table{width:100%;border-collapse:collapse;margin-top:16px;font-size:1rem}
.hours-table td{padding:11px 10px;border-bottom:1.5px dashed var(--line)}
.hours-table td:last-child{text-align:right;font-variant-numeric:tabular-nums}
.hours-table tr.today td{background:#fbe9c4;font-weight:800;border-bottom-color:transparent}
.hours-table tr.today td:first-child{border-radius:12px 0 0 12px}
.hours-table tr.today td:last-child{border-radius:0 12px 12px 0}
.today-tag{display:inline-block;margin-left:8px;font:800 .66rem/1 var(--sans);letter-spacing:.1em;text-transform:uppercase;background:var(--ink);color:var(--cream);padding:4px 7px;border-radius:6px;vertical-align:2px}
.localtime{font-size:.88rem;color:var(--ink2);margin-top:14px}
.map{border-radius:16px;overflow:hidden;border:2px solid var(--ink);margin:6px 0 14px}
.map svg{display:block;width:100%;height:auto}
.addr{font-size:1rem}
.addr b{display:block;font-family:var(--serif);font-size:1.15rem}
.small{font-size:.86rem;color:var(--ink2);margin-top:10px}

/* footer */
.foot{position:relative;background:var(--ink);color:var(--cream);padding:46px 0 calc(30px + env(safe-area-inset-bottom));margin-top:48px}
.foot::before{content:"";position:absolute;left:0;right:0;top:-14px;height:14px;background:radial-gradient(circle at 14px 14px,var(--ink) 13px,transparent 13.5px) 0 0/28px 14px repeat-x}
.foot-grid{display:grid;gap:24px}
@media (min-width:760px){.foot-grid{grid-template-columns:1.4fr 1fr 1fr;align-items:start}}
.foot h4{margin:0 0 8px;font:700 1.05rem var(--serif);color:var(--butter)}
.foot p,.foot li{color:#ead9c2;font-size:.94rem}
.foot ul{list-style:none;margin:0;padding:0}
.foot .brand{color:var(--cream)}
.foot .btn{background:transparent;color:var(--cream);border-color:var(--cream);box-shadow:0 4px 0 var(--cream)}
.fine{margin-top:28px;padding-top:16px;border-top:1.5px dashed rgba(251,244,230,.25);font-size:.8rem;color:#bfa58a;display:flex;flex-wrap:wrap;gap:8px 20px;justify-content:space-between}

/* drawer */
.scrim{position:fixed;inset:0;background:rgba(40,24,14,.48);opacity:0;pointer-events:none;transition:opacity .28s;z-index:60}
.scrim.on{opacity:1;pointer-events:auto}
.drawer{position:fixed;top:0;right:0;height:100%;width:min(440px,100%);background:var(--cream);border-left:3px solid var(--ink);z-index:61;display:flex;flex-direction:column;
  transform:translateX(105%);visibility:hidden;transition:transform .36s cubic-bezier(.2,.9,.3,1),visibility 0s linear .36s;box-shadow:-10px 0 30px rgba(0,0,0,.18)}
.drawer.open{transform:none;visibility:visible;transition:transform .36s cubic-bezier(.2,.9,.3,1)}
@media (max-width:599px){
  .drawer{top:auto;bottom:0;height:auto;max-height:90vh;max-height:90dvh;width:100%;border-left:0;border-top:3px solid var(--ink);border-radius:26px 26px 0 0;transform:translateY(105%)}
  .drawer::before{content:"";width:46px;height:5px;border-radius:9px;background:rgba(59,36,22,.25);position:absolute;top:8px;left:50%;margin-left:-23px}
}
.drawer-head{display:flex;align-items:center;justify-content:space-between;gap:12px;padding:20px 16px 12px 20px;border-bottom:2px dashed var(--line)}
.drawer-head h2{font-size:1.55rem}
.drawer-body{overflow:auto;padding:18px 20px;flex:1;overscroll-behavior:contain;-webkit-overflow-scrolling:touch}
.drawer-foot{display:flex;gap:10px;padding:12px 16px calc(14px + env(safe-area-inset-bottom));border-top:2px dashed var(--line)}
.drawer-foot .btn{flex:1;padding:0 10px}
.mini-wrap{text-align:center;margin-bottom:16px}
.mini{display:grid;grid-template-columns:repeat(var(--cols),1fr);gap:5px;padding:8px;background:var(--kraft);border-radius:12px;box-shadow:inset 0 0 0 2.5px var(--kraft-d),inset 0 5px 9px rgba(0,0,0,.22);width:min(100%,calc(var(--cols) * 60px + 16px));margin:0 auto}
.mini-slot{aspect-ratio:1;border-radius:8px;background:#b78550;box-shadow:inset 0 2px 4px rgba(0,0,0,.25);padding:6%}
.mini-cap{font-size:.85rem;color:var(--ink2);margin-top:8px}
.lines{list-style:none;margin:0;padding:0}
.line{display:grid;grid-template-columns:46px 1fr auto;gap:12px;align-items:center;padding:10px 0;border-bottom:1.5px dashed var(--line)}
.line-art{width:46px;height:46px}
.line-txt b{display:block;font-size:.98rem}
.line-txt small{color:var(--ink2);font-size:.82rem}
.line-amt{font-weight:800;font-variant-numeric:tabular-nums}
.diet{list-style:none;margin:6px 0 0;padding:0;display:grid;gap:6px;font-size:.88rem}
.diet li{display:flex;align-items:center;gap:8px}
.note{margin-top:18px;background:var(--paper);border:2px solid var(--ink);border-radius:16px;padding:14px 16px;font-size:.9rem}
.note b{font-family:var(--serif);font-size:1.02rem}
.note p{margin-top:4px;color:var(--ink2)}

/* toast & demo */
.toast{position:fixed;left:50%;bottom:calc(18px + env(safe-area-inset-bottom));transform:translate(-50%,160%);background:var(--ink);color:var(--cream);padding:12px 18px;border-radius:14px;font-weight:650;font-size:.94rem;max-width:min(92vw,460px);width:max-content;z-index:80;transition:transform .32s cubic-bezier(.2,1.2,.4,1);text-align:center;box-shadow:0 10px 24px rgba(0,0,0,.25);pointer-events:none}
.toast.on{transform:translate(-50%,0)}
.flyer{position:fixed;z-index:70;pointer-events:none;will-change:transform}
#demoPtr{position:fixed;left:0;top:0;z-index:95;pointer-events:none;display:none;transition:transform .6s cubic-bezier(.45,.05,.3,1);filter:drop-shadow(0 3px 4px rgba(0,0,0,.35))}
#demoPtr.on{display:block}
#demoPtr svg{position:absolute;left:-5px;top:-3px}
#demoPtr .ring{position:absolute;left:-18px;top:-18px;width:36px;height:36px;border-radius:50%;border:3px solid var(--berry);opacity:0}
#demoPtr.tap .ring{animation:ring .5s ease-out}
.demo-badge{position:fixed;top:12px;left:50%;transform:translateX(-50%);z-index:90;background:var(--berry);color:#fff;border:2px solid var(--ink);border-radius:999px;padding:8px 16px;font-weight:750;font-size:.85rem;box-shadow:0 4px 0 var(--ink);pointer-events:none;white-space:nowrap}

/* keyframes */
@keyframes pulse{0%{box-shadow:0 0 0 0 currentColor}70%,100%{box-shadow:0 0 0 8px transparent}}
@keyframes puff{0%{transform:translate(0,0) scale(.45);opacity:0}15%{opacity:.9}100%{transform:translate(22px,-78px) scale(1.7);opacity:0}}
@keyframes sway{0%,100%{transform:rotate(-3deg)}50%{transform:rotate(3deg)}}
@keyframes drop{0%{transform:translateY(-35%) scale(.4);opacity:0}45%{transform:translateY(0) scale(1.13);opacity:1}65%{transform:scale(.92)}82%{transform:scale(1.04)}100%{transform:scale(1)}}
@keyframes land{0%{transform:scale(1.16,.82)}40%{transform:scale(.9,1.1)}70%{transform:scale(1.05,.96)}100%{transform:scale(1)}}
@keyframes leave{to{transform:translateY(-18%) scale(.2) rotate(25deg);opacity:0}}
@keyframes shake{0%,100%{transform:translateX(0)}20%{transform:translateX(-8px) rotate(-1deg)}40%{transform:translateX(7px) rotate(1deg)}60%{transform:translateX(-4px)}80%{transform:translateX(3px)}}
@keyframes happy{0%,100%{transform:none}30%{transform:scale(1.035) rotate(-1.2deg)}60%{transform:scale(.99) rotate(1deg)}}
@keyframes boxpop{0%{transform:scale(.95)}60%{transform:scale(1.02)}100%{transform:scale(1)}}
@keyframes bump{0%{transform:scale(1)}40%{transform:scale(1.18)}100%{transform:scale(1)}}
@keyframes ring{0%{transform:scale(.3);opacity:1}100%{transform:scale(1.5);opacity:0}}

.lowfx .rough{filter:none}
.lowfx .puff,.lowfx .sway,.lowfx .status .dot{animation:none}
.lowfx .puff{opacity:0}
@media (prefers-reduced-motion:reduce){
  *,*::before,*::after{animation-duration:.001ms!important;animation-iteration-count:1!important;transition-duration:.001ms!important}
  .puff{opacity:0}
}
</style>
</head>
<body>
<a class="skip" href="#build">Skip to the box builder</a>

<header class="site-head">
  <div class="wrap head-in">
    <a class="brand" href="#top" aria-label="Larkspur Lane Bakehouse, back to top">
      <span class="brand-mark" id="brandMark"></span>
      <span><b>Larkspur Lane</b><small>Bakehouse</small></span>
    </a>
    <nav class="nav" aria-label="Sections">
      <a href="#bakes">Today's bakes</a>
      <a href="#build">Build a box</a>
      <a href="#hours">Hours</a>
    </nav>
    <div class="head-actions">
      <button class="box-chip" id="headBox" type="button" aria-label="Go to your box">
        <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round"><path d="M3 9h18v11H3z" fill="#c99a62"/><path d="M3 9l3-5h12l3 5"/><path d="M9 13h6"/></svg>
        <span id="headCount">0/6</span>
      </button>
      <button class="icon-btn" id="muteBtn" type="button" aria-pressed="false" aria-label="Mute sound"></button>
    </div>
  </div>
</header>

<main id="top">
  <!-- HERO -->
  <section class="hero">
    <div class="wrap hero-grid">
      <div>
        <span class="eyebrow">Neighborhood bakery · Millbrook</span>
        <h1>Larkspur Lane <span class="script">Bakehouse</span></h1>
        <p class="story">In 1987, Marguerite Ilves turned a shuttered bicycle repair shop on Larkspur Lane into a one-oven bakery. Her grandson Teo still lights that same oven at 4&nbsp;a.m., folds croissant dough by hand and bakes in small batches until the shelves are full — and then, usually by noon, until they're empty again.</p>
        <div class="cta-row">
          <a class="btn btn-primary" id="heroCta" href="#build">Build your box</a>
          <a class="btn" href="#bakes">Today's bakes</a>
        </div>
        <div class="status js-status" role="status"><span class="dot"></span><span class="txt">Checking hours…</span></div>
        <div class="hero-facts"><span>Baking since 1987</span><span>12 pastries every morning</span><span>Vegan &amp; gluten-free options</span></div>
      </div>
      <div class="hero-art" id="heroArt"><span class="caption">come say hi!</span></div>
    </div>
  </section>

  <!-- TODAY'S BAKES -->
  <section class="sec" id="bakes">
    <div class="wrap">
      <div class="sec-head">
        <div>
          <span class="eyebrow" id="bakesDate">Today</span>
          <h2>Today's bakes</h2>
          <p>Out of the oven this morning. Everything is made in our kitchen from flour to finish — tap <b>Add to box</b> to start a box with any of them.</p>
        </div>
        <span class="hand-note">still warm, promise →</span>
      </div>
      <div class="bakes" id="bakesGrid"></div>
    </div>
  </section>

  <!-- BUILD YOUR BOX -->
  <section class="sec" id="build">
    <div class="wrap">
      <div class="sec-head">
        <div>
          <span class="eyebrow">The fun part</span>
          <h2>Build your box</h2>
          <p>Choose a size, tap pastries to drop them in, tap anything in the box to take it back out.</p>
        </div>
        <span class="hand-note">mix &amp; match!</span>
      </div>

      <div class="builder">
        <div class="controls">
          <div class="step">
            <h3 class="step-h"><span class="step-n">1</span>Pick a box<span class="spacer"></span><button class="btn btn-small" id="resetBtn" type="button">↺ Start over</button></h3>
            <div class="sizes" id="sizes" role="group" aria-label="Box size"></div>
          </div>
          <div class="step">
            <h3 class="step-h"><span class="step-n">2</span>Dietary filters</h3>
            <div class="filters" id="filterRow" role="group" aria-label="Dietary filters">
              <button class="filter" type="button" data-filter="vegan" aria-pressed="false"><span class="check"></span>Vegan</button>
              <button class="filter" type="button" data-filter="nutfree" aria-pressed="false"><span class="check"></span>Nut-free</button>
              <button class="filter" type="button" data-filter="gf" aria-pressed="false"><span class="check"></span>Gluten-free</button>
              <button class="link-btn" type="button" id="clearFilters" hidden>Clear</button>
            </div>
            <p class="filter-note" id="filterNote" aria-live="polite"></p>
          </div>
          <div class="step">
            <h3 class="step-h"><span class="step-n">3</span>Tap to fill</h3>
            <div class="grid" id="pastryGrid"></div>
          </div>
        </div>

        <aside class="panel" id="panel" aria-label="Your box">
          <div class="panel-head">
            <div class="ph-title">
              <span class="eyebrow">Your box</span>
              <span class="panel-title" id="boxLabel">Box of 6</span>
              <span class="count" id="fillCount">0 of 6 filled</span>
            </div>
            <div class="panel-total" id="totalAmt">$0.00</div>
            <button class="btn btn-primary btn-small head-checkout js-checkout" type="button">Checkout</button>
          </div>
          <div class="box" id="box" data-size="6">
            <div class="lid"><span class="sticker">LL</span><span id="lidLabel">box of 6</span></div>
            <div class="tray" id="tray" role="group" aria-label="Box slots"></div>
          </div>
          <div class="meter" aria-hidden="true"><span id="meterFill"></span></div>
          <div class="panel-foot">
            <p class="hint" id="hint" aria-live="polite">Tap any pastry to drop it in.</p>
            <p class="deal" id="dealNote" hidden></p>
            <dl class="sums">
              <div><dt>Subtotal</dt><dd id="subAmt">$0.00</dd></div>
              <div class="save" id="discRow" hidden><dt>Dozen deal (10%)</dt><dd id="discAmt">−$0.00</dd></div>
              <div class="grand"><dt>Total</dt><dd id="totalAmt2">$0.00</dd></div>
            </dl>
            <button class="btn btn-primary foot-checkout js-checkout" type="button">Checkout</button>
          </div>
        </aside>
      </div>
    </div>
  </section>

  <!-- HOURS -->
  <section class="sec" id="hours">
    <div class="wrap">
      <div class="sec-head">
        <div>
          <span class="eyebrow">Visit</span>
          <h2>Opening hours</h2>
          <p>Shown in your local time. Early birds get the warmest croissants.</p>
        </div>
      </div>
      <div class="hours-grid">
        <div class="card">
          <div class="status big js-status" role="status"><span class="dot"></span><span class="txt">Checking hours…</span></div>
          <table class="hours-table"><tbody id="hoursBody"></tbody></table>
          <p class="localtime" id="localTime"></p>
        </div>
        <div class="card">
          <h3>Find us</h3>
          <div class="map" id="mapArt"></div>
          <p class="addr"><b>14 Larkspur Lane, Millbrook</b>Three doors down from Willow Park, the green door with the striped awning.</p>
          <p class="small">Our kitchen handles nuts, gluten and dairy every day. Filters are a helpful guide — please ask us about allergies at the counter.</p>
        </div>
      </div>
    </div>
  </section>
</main>

<footer class="foot">
  <div class="wrap">
    <div class="foot-grid">
      <div>
        <a class="brand" href="#top"><span class="brand-mark" id="brandMark2"></span><span><b>Larkspur Lane</b><small>Bakehouse</small></span></a>
        <p style="margin-top:12px;max-width:30em">A tiny bakery with a big oven, baking for the neighborhood since 1987. Flour on our aprons, butter in everything (except the vegan bits).</p>
      </div>
      <div>
        <h4>Hours</h4>
        <ul><li>Tue–Fri · 7 am – 6 pm</li><li>Saturday · 8 am – 4 pm</li><li>Sunday · 8 am – 1 pm</li><li>Monday · closed</li></ul>
      </div>
      <div>
        <h4>Say hello</h4>
        <p>14 Larkspur Lane, Millbrook</p>
        <p style="margin:14px 0">Pre-made boxes ready from 8 am.</p>
        <a class="btn btn-small" href="#top">↑ Back to top</a>
      </div>
    </div>
    <div class="fine"><span>© Larkspur Lane Bakehouse — an invented bakery.</span><span>Every pastry here is drawn in code.</span></div>
  </div>
</footer>

<div class="scrim" id="scrim"></div>
<aside class="drawer" id="drawer" role="dialog" aria-modal="true" aria-labelledby="drawerTitle" aria-hidden="true">
  <div class="drawer-head">
    <div><span class="eyebrow">Checkout</span><h2 id="drawerTitle">Order summary</h2></div>
    <button class="icon-btn" id="drawerClose" type="button" aria-label="Close summary">
      <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.8" stroke-linecap="round"><path d="M6 6l12 12M18 6L6 18"/></svg>
    </button>
  </div>
  <div class="drawer-body" id="drawerBody"></div>
  <div class="drawer-foot">
    <button class="btn" id="keepEditing" type="button">Keep editing</button>
    <button class="btn btn-primary" id="newBox" type="button">Start a new box</button>
  </div>
</aside>

<div class="toast" id="toast" role="status" aria-live="polite"></div>
<div id="demoPtr" aria-hidden="true"><span class="ring"></span><svg width="30" height="30" viewBox="0 0 24 24"><path d="M4 2 L4 20 L9 15.5 L12.5 22 L15.5 20.6 L12 14 L19 14 Z" fill="#fff" stroke="#3b2416" stroke-width="1.6" stroke-linejoin="round"/></svg></div>
<div class="demo-badge" id="demoBadge" hidden>Demo · tap anywhere to take over</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 TAU=Math.PI*2;
function f(n){return Math.round(n*10)/10;}

/* ---------- seeded randomness ---------- */
function mulberry(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;};}

/* ---------- path helpers ---------- */
function smooth(pts){
  var n=pts.length,d='';
  for(var i=0;i<n;i++){
    var p0=pts[(i-1+n)%n],p1=pts[i],p2=pts[(i+1)%n],p3=pts[(i+2)%n];
    if(i===0)d+='M'+f(p1[0])+' '+f(p1[1]);
    d+='C'+f(p1[0]+(p2[0]-p0[0])/6)+' '+f(p1[1]+(p2[1]-p0[1])/6)+' '+f(p2[0]-(p3[0]-p1[0])/6)+' '+f(p2[1]-(p3[1]-p1[1])/6)+' '+f(p2[0])+' '+f(p2[1]);
  }
  return d+'Z';
}
function blob(cx,cy,r,amp,n,seed){var R=mulberry(seed),pts=[];for(var i=0;i<n;i++){var a=i/n*TAU,rr=r+(R()*2-1)*amp;pts.push([cx+Math.cos(a)*rr,cy+Math.sin(a)*rr]);}return smooth(pts);}
function flute(cx,cy,r,amp,n){var pts=[];for(var i=0;i<n*2;i++){var a=i/(n*2)*TAU,rr=i%2?r-amp:r+amp;pts.push([cx+Math.cos(a)*rr,cy+Math.sin(a)*rr]);}return smooth(pts);}

/* ---------- pastry illustrations (one shared style) ---------- */
var INK='#4a2c17';
function st(w){return 'stroke="'+INK+'" stroke-width="'+(w||3)+'" stroke-linejoin="round" stroke-linecap="round"';}
var CR=[[21,63],[32,47],[50,40],[68,47],[79,63]];
function arcPt(R){var t=R()*4,i=Math.min(3,Math.floor(t)),u=t-i,a=CR[i],b=CR[i+1];return[a[0]+(b[0]-a[0])*u+(R()*2-1)*5,a[1]+(b[1]-a[1])*u+(R()*2-1)*5];}
function croissant(fill,hi,extra){
  var segs=[[21,63,9,13,-55],[79,63,9,13,55],[32,47,11,16,-30],[68,47,11,16,30],[50,40,13,18,0]],s='';
  segs.forEach(function(g){var x=g[0],y=g[1],rx=g[2],ry=g[3],r=g[4];
    s+='<ellipse cx="'+x+'" cy="'+y+'" rx="'+rx+'" ry="'+ry+'" transform="rotate('+r+' '+x+' '+y+')" fill="'+fill+'" '+st()+'/>';
    s+='<ellipse cx="'+x+'" cy="'+f(y-ry*.38)+'" rx="'+f(rx*.45)+'" ry="'+f(ry*.28)+'" transform="rotate('+r+' '+x+' '+y+')" fill="'+hi+'"/>';
  });
  return s+(extra||'');
}
var ART={
  croissant:function(){return croissant('#e3a04f','#f4c97f','');},
  almond:function(){
    var R=mulberry(11),x='',i,p;
    for(i=0;i<9;i++){p=arcPt(R);x+='<ellipse cx="'+f(p[0])+'" cy="'+f(p[1])+'" rx="4.8" ry="2.2" transform="rotate('+f(R()*180)+' '+f(p[0])+' '+f(p[1])+')" fill="#f6e6c4" '+st(1.4)+'/>';}
    for(i=0;i<28;i++){p=arcPt(R);x+='<circle cx="'+f(p[0])+'" cy="'+f(p[1])+'" r="'+f(.8+R()*.9)+'" fill="#fffaf0"/>';}
    return croissant('#cf883c','#e6aa60',x);
  },
  painchoc:function(){
    var s='';
    [[6,35],[6,55],[74,37],[74,56]].forEach(function(c){s+='<rect x="'+c[0]+'" y="'+c[1]+'" width="20" height="9" rx="2.5" fill="#3d2213" '+st(2.4)+'/>';});
    s+='<rect x="14" y="26" width="72" height="48" rx="15" fill="#df9f4e" '+st()+'/>';
    s+='<rect x="22" y="31" width="56" height="9" rx="4.5" fill="#f3c67e"/>';
    [31,45,59,72].forEach(function(x){s+='<path d="M'+x+' 29 Q'+(x-4)+' 50 '+x+' 71" fill="none" stroke="#a8662c" stroke-width="2.2" stroke-linecap="round"/>';});
    return s;
  },
  swirl:function(){
    var s='<path d="'+blob(50,50,36,2.2,14,21)+'" fill="#d9974e" '+st()+'/>',sp='';
    s+='<path d="'+blob(44,44,20,2,9,22)+'" fill="#e6ad66"/>';
    for(var th=.8;th<=5.2*Math.PI;th+=.22){var r=1.85*th;sp+=(sp?'L':'M')+f(50+Math.cos(th)*r)+' '+f(50+Math.sin(th)*r);}
    s+='<path d="'+sp+'" fill="none" stroke="#8f4a1f" stroke-width="4.6" stroke-linecap="round" stroke-linejoin="round"/>';
    s+='<path d="M22 38 C34 28 44 50 56 36 S76 44 80 52" fill="none" stroke="#fff6e6" stroke-width="3.6" stroke-linecap="round"/>';
    s+='<path d="M24 62 C36 52 48 72 60 58 S74 66 78 70" fill="none" stroke="#fff6e6" stroke-width="3.6" stroke-linecap="round"/>';
    return s;
  },
  muffin:function(){
    var R=mulberry(33),s='<path d="'+flute(50,50,39,2.2,18)+'" fill="#efe2cf" '+st()+'/>';
    s+='<path d="'+blob(50,50,32,3.2,11,31)+'" fill="#dfa95f" '+st()+'/>';
    s+='<path d="'+blob(44,43,16,2,8,32)+'" fill="#edc17f"/>';
    for(var i=0;i<12;i++){var a=R()*TAU,r=R()*24;s+='<circle cx="'+f(50+Math.cos(a)*r)+'" cy="'+f(50+Math.sin(a)*r)+'" r="'+f(1.3+R()*1.3)+'" fill="#f7dfa8"/>';}
    [[38,40],[60,36],[64,58],[42,62],[52,50],[30,54]].forEach(function(b){
      s+='<circle cx="'+b[0]+'" cy="'+b[1]+'" r="5" fill="#4b4a8c" '+st(2)+'/><circle cx="'+(b[0]-1.6)+'" cy="'+(b[1]-1.6)+'" r="1.4" fill="#9a9bd8"/>';
    });
    return s;
  },
  lemon:function(){
    var R=mulberry(41),s='<rect x="16" y="16" width="68" height="68" rx="9" fill="#f0c95a" '+st()+'/>';
    s+='<rect x="22" y="21" width="56" height="10" rx="5" fill="#f8de8a"/>';
    for(var i=0;i<26;i++)s+='<circle cx="'+f(22+R()*56)+'" cy="'+f(22+R()*56)+'" r=".9" fill="#d5a238"/>';
    s+='<path d="M24 30 L36 70 L46 28 L58 72 L68 30 L78 66" fill="none" stroke="#fffbea" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/>';
    s+='<circle cx="50" cy="50" r="15" fill="#fff6c2" '+st(2.5)+'/><circle cx="50" cy="50" r="11.5" fill="#f7dc4a"/>';
    for(var k=0;k<8;k++){var a=k/8*TAU;s+='<path d="M50 50 L'+f(50+Math.cos(a)*11.5)+' '+f(50+Math.sin(a)*11.5)+'" stroke="#fff6c2" stroke-width="1.6"/>';}
    return s+'<circle cx="50" cy="50" r="1.8" fill="#fff6c2"/>';
  },
  macaron:function(){
    var R=mulberry(45),s='<path d="'+flute(50,50,36,1.6,30)+'" fill="#a7c47a" '+st()+'/>';
    s+='<circle cx="50" cy="50" r="30" fill="#c3db96" '+st(2.5)+'/>';
    s+='<path d="M29 42 Q35 27 54 24" fill="none" stroke="#eaf3d3" stroke-width="5" stroke-linecap="round"/>';
    for(var i=0;i<9;i++){var a=R()*TAU,r=R()*9;s+='<circle cx="'+f(58+Math.cos(a)*r)+'" cy="'+f(58+Math.sin(a)*r)+'" r="'+f(1.2+R()*1.2)+'" fill="'+(i%3?'#7f9f4f':'#b88aa8')+'"/>';}
    return s;
  },
  tart:function(){
    var s='<path d="'+flute(50,50,38,2.6,22)+'" fill="#d89b55" '+st()+'/>';
    s+='<circle cx="50" cy="50" r="29.5" fill="#fbeed6" '+st(2.5)+'/>';
    var pts=[[50,50]];for(var i=0;i<7;i++){var a=i/7*TAU+.3;pts.push([50+Math.cos(a)*17.5,50+Math.sin(a)*17.5]);}
    pts.forEach(function(p){var x=f(p[0]),y=f(p[1]);
      s+='<circle cx="'+x+'" cy="'+y+'" r="7" fill="#c8475b" '+st(2)+'/>';
      s+='<circle cx="'+f(p[0]-2.2)+'" cy="'+f(p[1]-2)+'" r="1.4" fill="#ec8a9b"/><circle cx="'+f(p[0]+2.2)+'" cy="'+f(p[1]-.8)+'" r="1.4" fill="#ec8a9b"/><circle cx="'+f(p[0])+'" cy="'+f(p[1]+2.4)+'" r="1.4" fill="#ec8a9b"/>';
    });
    return s+'<ellipse cx="40" cy="22" rx="7" ry="3.6" transform="rotate(-25 40 22)" fill="#6f9f5e" '+st(1.8)+'/>';
  },
  cookie:function(){
    var R=mulberry(53),s='<path d="'+blob(50,50,35,3,13,51)+'" fill="#7a4a2c" '+st()+'/>';
    s+='<path d="'+blob(44,44,20,2,9,52)+'" fill="#8d5a37"/>';
    for(var i=0;i<8;i++){var a=R()*TAU,r=6+R()*19,cx=50+Math.cos(a)*r,cy=50+Math.sin(a)*r,pts=[];
      for(var k=0;k<5;k++){var b=k/5*TAU+R(),rr=3+R()*2.4;pts.push(f(cx+Math.cos(b)*rr)+','+f(cy+Math.sin(b)*rr));}
      s+='<polygon points="'+pts.join(' ')+'" fill="#2d1810" stroke="#2d1810" stroke-width="1.2" stroke-linejoin="round"/>';}
    for(var j=0;j<7;j++){var a2=R()*TAU,r2=R()*24,x=f(50+Math.cos(a2)*r2),y=f(50+Math.sin(a2)*r2);s+='<rect x="'+x+'" y="'+y+'" width="2.4" height="2.4" transform="rotate('+f(R()*90)+' '+x+' '+y+')" fill="#fffaf0"/>';}
    return s;
  },
  donut:function(){
    var R=mulberry(62),s='<path d="M14 50a36 36 0 1 0 72 0a36 36 0 1 0 -72 0ZM39 50a11 11 0 1 1 22 0a11 11 0 1 1 -22 0Z" fill="#e2a65a" fill-rule="evenodd" '+st()+'/>';
    s+='<path d="'+blob(50,50,30.5,2.6,12,61)+' M35 50a15 15 0 1 1 30 0a15 15 0 1 1 -30 0Z" fill="#ea7f97" fill-rule="evenodd" '+st(2.5)+'/>';
    s+='<path d="M28 40 Q34 27 50 23" fill="none" stroke="#f7b8c6" stroke-width="4" stroke-linecap="round"/>';
    var cols=['#fffaf0','#f2c66d','#6f8f5e','#7fb3d5'];
    for(var i=0;i<18;i++){var a=i/18*TAU+R()*.3,r=19+R()*8,x=50+Math.cos(a)*r,y=50+Math.sin(a)*r,b=R()*Math.PI;
      s+='<path d="M'+f(x-Math.cos(b)*2.5)+' '+f(y-Math.sin(b)*2.5)+'L'+f(x+Math.cos(b)*2.5)+' '+f(y+Math.sin(b)*2.5)+'" stroke="'+cols[i%4]+'" stroke-width="2.6" stroke-linecap="round"/>';}
    return s;
  },
  brownie:function(){
    var s='<rect x="15" y="17" width="70" height="66" rx="7" fill="#4f2c1a" '+st()+'/>';
    s+='<rect x="21" y="23" width="58" height="54" rx="5" fill="#673c25"/>';
    s+='<path d="M26 34 L38 40 L46 36 M56 29 L62 41 L74 44 M28 62 L40 57 L50 66 L60 62 M66 54 L74 68" fill="none" stroke="#3a1f12" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/>';
    [[37,49],[62,53],[46,69]].forEach(function(h){
      s+='<ellipse cx="'+h[0]+'" cy="'+h[1]+'" rx="7.5" ry="6.4" fill="#b97a40" '+st(2)+'/><ellipse cx="'+h[0]+'" cy="'+(h[1]+.5)+'" rx="4.6" ry="3.8" fill="#f0d9a8"/><path d="M'+h[0]+' '+(h[1]-3)+' v7" stroke="'+INK+'" stroke-width="1.3" stroke-linecap="round"/>';
    });
    return s;
  },
  turnover:function(){
    var R=mulberry(77),s='<path d="M24 78 Q13 78 19 68 L43 25 Q50 13 57 25 L81 68 Q87 78 76 78 Z" fill="#dc9a4c" '+st()+'/>';
    s+='<path d="M30 68 L47 32" stroke="#f1c27a" stroke-width="6" stroke-linecap="round"/>';
    for(var x=28;x<=72;x+=6)s+='<path d="M'+x+' 77 v-6" stroke="#a8662c" stroke-width="2" stroke-linecap="round"/>';
    [[42,52,49,45],[46,61,54,53],[50,70,58,62]].forEach(function(l){
      s+='<path d="M'+l[0]+' '+l[1]+' L'+l[2]+' '+l[3]+'" stroke="#f3d27a" stroke-width="5" stroke-linecap="round"/><path d="M'+l[0]+' '+l[1]+' L'+l[2]+' '+l[3]+'" stroke="'+INK+'" stroke-width="2.2" stroke-linecap="round"/>';
    });
    for(var i=0;i<18;i++){var u=R(),v=R();if(u+v>1){u=1-u;v=1-v;}var px=50+(-26)*u+26*v,py=24+48*u+48*v;s+='<circle cx="'+f(px)+'" cy="'+f(py)+'" r="'+f(.7+R()*.8)+'" fill="#fffaf0"/>';}
    return s;
  }
};
var artCache={};
function artInner(id){if(!artCache[id])artCache[id]=ART[id]();return artCache[id];}
function artSvg(id){var a=artInner(id);return '<svg class="pa" viewBox="0 0 100 100" aria-hidden="true" focusable="false"><g class="sh" transform="translate(2.5 4)">'+a+'</g>'+a+'</svg>';}

/* ---------- menu ---------- */
var PASTRIES=[
  {id:'croissant',name:'Butter Croissant',price:3.5,tags:['nutfree'],desc:'Seventy-two flaky layers and a crackly, burnished crust.'},
  {id:'almond',name:'Almond Croissant',price:4.25,tags:[],desc:'Twice-baked with frangipane, toasted almonds and icing sugar.'},
  {id:'painchoc',name:'Pain au Chocolat',price:3.75,tags:['nutfree'],desc:'Two batons of dark chocolate rolled into buttery dough.'},
  {id:'swirl',name:'Cinnamon Swirl',price:3.95,tags:['nutfree'],desc:'Brown-sugar spiral, warm spice and a vanilla drizzle.'},
  {id:'muffin',name:'Blueberry Muffin',price:3.25,tags:['vegan','nutfree'],desc:'Oat-milk batter, bursting berries, crunchy sugar top.'},
  {id:'lemon',name:'Lemon Polenta Square',price:3.6,tags:['gf','nutfree'],desc:'Golden cornmeal cake soaked in lemon syrup.'},
  {id:'macaron',name:'Pistachio Macaron',price:2.75,tags:['gf'],desc:'Crisp shell, chewy middle, pistachio buttercream.'},
  {id:'tart',name:'Raspberry Tart',price:4.5,tags:['nutfree'],desc:'Vanilla custard in short crust, crowned with raspberries.'},
  {id:'cookie',name:'Midnight Cookie',price:2.5,tags:['vegan','gf','nutfree'],desc:'Dark cocoa, chocolate chunks and flaky sea salt.'},
  {id:'donut',name:'Rhubarb Ring Doughnut',price:3.1,tags:['vegan','nutfree'],desc:'Fluffy yeasted ring with rhubarb icing and sprinkles.'},
  {id:'brownie',name:'Hazelnut Brownie',price:3.4,tags:['gf'],desc:'Fudgy, flourless and studded with roasted hazelnuts.'},
  {id:'turnover',name:'Apple Turnover',price:3.8,tags:['vegan','nutfree'],desc:'Spiced orchard apples in a crisp, sugared pastry.'}
];
var byId={};PASTRIES.forEach(function(p){byId[p.id]=p;});
var TAG={vegan:['VG','Vegan','Not vegan'],nutfree:['NF','Nut-free','Contains nuts'],gf:['GF','Gluten-free','Contains gluten']};
var SIZES=[{n:4,label:'Little box',sub:'A treat for two'},{n:6,label:'Classic',sub:'Most loved'},{n:12,label:'Dozen',sub:'Fill it: 10% off'}];
var COLS={4:2,6:3,12:4},ROWS={4:2,6:2,12:3};
function money(v){return '$'+v.toFixed(2);}
function tagHTML(p){return p.tags.map(function(t){return '<span class="tag tag-'+t+'" title="'+TAG[t][1]+'">'+TAG[t][0]+'</span>';}).join('');}

/* ---------- state ---------- */
var state={size:6,slots:[null,null,null,null,null,null],filters:[],key:0,muted:false};
try{state.muted=localStorage.getItem('llb-muted')==='1';}catch(e){}
var reduced=window.matchMedia&&window.matchMedia('(prefers-reduced-motion: reduce)').matches;
function lowMotion(){return reduced||document.documentElement.classList.contains('lowfx');}
function restart(el,cls){if(!el)return;el.classList.remove(cls);void el.offsetWidth;el.classList.add(cls);}

/* ---------- audio (starts only after a real tap) ---------- */
var actx=null,master=null;
function initAudio(){
  if(actx)return;
  try{var AC=window.AudioContext||window.webkitAudioContext;if(!AC)return;actx=new AC();master=actx.createGain();master.gain.value=state.muted?0:.5;master.connect(actx.destination);}catch(e){actx=null;}
}
function unlock(e){if(!e.isTrusted)return;initAudio();if(actx&&actx.state==='suspended'){try{actx.resume();}catch(_){}}}
window.addEventListener('pointerdown',unlock,true);
window.addEventListener('keydown',unlock,true);
function tone(freq,to,dur,type,vol,delay){
  if(!actx||state.muted)return;
  try{
    var t=actx.currentTime+(delay||0),o=actx.createOscillator(),g=actx.createGain();
    o.type=type;o.frequency.setValueAtTime(freq,t);if(to)o.frequency.exponentialRampToValueAtTime(to,t+dur);
    g.gain.setValueAtTime(.0001,t);g.gain.exponentialRampToValueAtTime(vol,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 NOTES=[523,587,659,698,784,880,988,1047,1175,1319,1397,1568];
var sfx={
  pop:function(i){var b=NOTES[i%12];tone(b*.55,b,.13,'sine',.32);tone(b*2,b*2.03,.06,'triangle',.05);},
  out:function(){tone(640,250,.16,'triangle',.22);},
  full:function(){[784,988,1175,1568].forEach(function(n,i){tone(n,0,.38,'sine',.16,i*.08);});},
  nope:function(){tone(190,140,.18,'square',.06);tone(170,120,.18,'square',.05,.1);},
  tick:function(){tone(1250,900,.05,'sine',.12);},
  open:function(){tone(660,0,.3,'sine',.14);tone(990,0,.35,'sine',.1,.07);}
};
var muteBtn=$('#muteBtn');
var ICON_ON='<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 9v6h4l5 4V5L8 9z" fill="currentColor"/><path d="M16.5 8.5a5 5 0 0 1 0 7M19 6a8.5 8.5 0 0 1 0 12"/></svg>';
var ICON_OFF='<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 9v6h4l5 4V5L8 9z" fill="currentColor"/><path d="M16.5 9.5l5 5M21.5 9.5l-5 5"/></svg>';
function paintMute(){muteBtn.innerHTML=state.muted?ICON_OFF:ICON_ON;muteBtn.setAttribute('aria-pressed',state.muted?'true':'false');muteBtn.setAttribute('aria-label',state.muted?'Unmute sound':'Mute sound');}
muteBtn.addEventListener('click',function(){
  state.muted=!state.muted;initAudio();
  if(master)master.gain.value=state.muted?0:.5;
  try{localStorage.setItem('llb-muted',state.muted?'1':'0');}catch(e){}
  paintMute();if(!state.muted)sfx.tick();
  toast(state.muted?'Sound off':'Sound on');
});
paintMute();

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

/* ---------- hero illustration ---------- */
function heroSVG(){
  var I='#3b2416',R=mulberry(1987);
  function sw(w){return 'stroke="'+I+'" stroke-width="'+w+'" stroke-linejoin="round" stroke-linecap="round"';}
  var g='',c='',i,x;
  g+='<path d="'+blob(300,240,262,14,18,5)+'" fill="#f6e2c2"/>';
  g+='<circle cx="532" cy="22" r="26" fill="#f2c66d" '+sw(3)+'/>';
  for(i=0;i<10;i++){var a=i/10*TAU;g+='<path d="M'+f(532+Math.cos(a)*34)+' '+f(22+Math.sin(a)*34)+'L'+f(532+Math.cos(a)*44)+' '+f(22+Math.sin(a)*44)+'" '+sw(3)+'/>';}
  g+='<path d="M58 4 q8 -8 16 0 q8 -8 16 0" fill="none" '+sw(2.5)+'/><path d="M118 -24 q6 -6 12 0 q6 -6 12 0" fill="none" '+sw(2.5)+'/>';
  // chimney + parapet
  g+='<rect x="404" y="8" width="40" height="52" fill="#b5654a" '+sw(3.5)+'/><path d="M404 26 h40 M404 44 h40 M424 8 v18 M414 26 v18 M434 44 v16" '+sw(1.6)+' fill="none"/><rect x="398" y="0" width="52" height="12" rx="2" fill="#9c5440" '+sw(3.5)+'/>';
  g+='<rect x="92" y="56" width="416" height="26" fill="#ecc9a2" '+sw(3.5)+'/>';
  // building
  g+='<rect x="80" y="96" width="440" height="336" fill="#f3d3b4" '+sw(3.5)+'/>';
  [[88,106,18],[104,118,18],[480,106,18],[496,118,16],[86,264,16],[92,294,16],[86,324,16],[480,262,16],[494,290,16],[482,318,16],[492,346,14]].forEach(function(b){g+='<rect x="'+b[0]+'" y="'+b[1]+'" width="'+b[2]+'" height="9" rx="1" fill="#e8bf98" '+sw(1.6)+'/>';});
  g+='<rect x="66" y="78" width="468" height="22" rx="5" fill="#6f8f5e" '+sw(3.5)+'/>';
  for(x=82;x<520;x+=18)g+='<rect x="'+x+'" y="100" width="9" height="7" fill="#5b774c" '+sw(1.8)+'/>';
  // lamps
  [124,476].forEach(function(lx){g+='<circle cx="'+lx+'" cy="140" r="22" fill="#f2c66d" opacity=".3"/><path d="M'+lx+' 116 v12" '+sw(3)+'/><path d="M'+(lx-9)+' 128 h18 l-4 17 h-10 z" fill="#f2c66d" '+sw(3)+'/>';});
  // sign board
  g+='<rect x="150" y="114" width="300" height="58" rx="10" fill="#3b2416" '+sw(3)+'/><rect x="159" y="122" width="282" height="42" rx="6" fill="none" stroke="#f2c66d" stroke-width="1.6" stroke-dasharray="5 4"/>';
  c+='<text x="300" y="148" text-anchor="middle" font-family="Iowan Old Style,Palatino Linotype,Palatino,Georgia,serif" font-weight="700" font-size="23" letter-spacing="3" fill="#fbf4e6">LARKSPUR LANE</text>';
  c+='<text x="300" y="161.5" text-anchor="middle" font-family="system-ui,sans-serif" font-weight="700" font-size="9.5" letter-spacing="3.5" fill="#f2c66d">BAKEHOUSE · EST. 1987</text>';
  // awning
  var n=12,tl=104,tr=496,bl=90,br=510,aT=190,aB=230;
  g+='<rect x="98" y="183" width="404" height="9" rx="3" fill="#3b2416"/>';
  for(i=0;i<n;i++){
    var x0t=tl+(tr-tl)*i/n,x1t=tl+(tr-tl)*(i+1)/n,x0b=bl+(br-bl)*i/n,x1b=bl+(br-bl)*(i+1)/n,col=i%2?'#fbf4e6':'#c8475b';
    g+='<path d="M'+f(x0t)+' '+aT+' L'+f(x1t)+' '+aT+' L'+f(x1b)+' '+aB+' A'+f((x1b-x0b)/2)+' 11 0 0 1 '+f(x0b)+' '+aB+' Z" fill="'+col+'" '+sw(2.5)+'/>';
  }
  // window
  g+='<rect x="110" y="252" width="220" height="148" rx="4" fill="#fff0cc" '+sw(3.5)+'/>';
  g+='<path d="M110 282 H330" '+sw(3)+'/>';
  g+='<path d="M126 302 l18 -14 M132 316 l28 -22" stroke="#fffaf0" stroke-width="4" stroke-linecap="round" opacity=".9"/>';
  c+='<text x="220" y="273" text-anchor="middle" font-family="Segoe Print,Bradley Hand,Marker Felt,Chalkboard SE,cursive" font-size="14" fill="#c8475b">fresh every morning</text>';
  // upper shelf + loaves + cake
  g+='<ellipse cx="148" cy="324" rx="24" ry="12" fill="#d39348" '+sw(3)+'/>';
  [-12,-2,8].forEach(function(k){g+='<path d="M'+(144+k)+' 316 l7 14" stroke="#f3c67e" stroke-width="3" stroke-linecap="round"/>';});
  g+='<circle cx="196" cy="322" r="14" fill="#c98540" '+sw(3)+'/><path d="M188 314 l16 16 M204 314 l-16 16" stroke="#f3c67e" stroke-width="2.6" stroke-linecap="round"/>';
  g+='<path d="M252 330 h36 M270 330 v6" '+sw(3)+'/><rect x="250" y="300" width="40" height="28" rx="4" fill="#f8dfe4" '+sw(3)+'/>';
  g+='<path d="M250 308 q5 6 10 0 q5 6 10 0 q5 6 10 0 q5 6 10 0" fill="none" stroke="#c8475b" stroke-width="2.6" stroke-linecap="round"/>';
  g+='<path d="M270 291 q3 -6 7 -7" fill="none" '+sw(2)+'/><circle cx="270" cy="295" r="5" fill="#c8475b" '+sw(2.5)+'/>';
  g+='<rect x="300" y="314" width="20" height="22" rx="4" fill="#cfe3c0" '+sw(2.5)+'/><rect x="298" y="309" width="24" height="6" rx="2" fill="#c8475b" '+sw(2)+'/>';
  g+='<rect x="116" y="336" width="208" height="7" fill="#b07a48" '+sw(2.5)+'/>';
  // lower shelf: baguettes + croissants
  g+='<rect x="130" y="344" width="11" height="44" rx="5.5" transform="rotate(-12 135 366)" fill="#d8a056" '+sw(2.5)+'/><rect x="148" y="342" width="11" height="46" rx="5.5" transform="rotate(9 153 366)" fill="#cf9548" '+sw(2.5)+'/>';
  g+='<path d="M124 364 h44 l-5 22 h-34 z" fill="#b07a48" '+sw(3)+'/><path d="M128 371 h36 M130 378 h32" stroke="#8a5a30" stroke-width="2"/>';
  [180,216,252].forEach(function(cx){g+='<g transform="translate('+cx+' 360) scale(.34)">'+croissant('#e3a04f','#f4c97f','')+'</g>';});
  g+='<rect x="290" y="360" width="30" height="20" rx="3" transform="rotate(5 305 370)" fill="#fffaf0" '+sw(2)+'/>';
  g+='<rect x="116" y="386" width="208" height="7" fill="#b07a48" '+sw(2.5)+'/>';
  // sill + flower box
  g+='<rect x="104" y="398" width="232" height="10" rx="2" fill="#ecc9a2" '+sw(3)+'/>';
  var fcols=['#c8475b','#f2c66d','#fbf4e6','#e98395'];
  for(i=0;i<11;i++){
    var fx=f(126+i*19+(R()-.5)*6),fy=f(400+(R()-.5)*6),fr=f(5.5+R()*2);
    g+='<ellipse cx="'+(fx-6)+'" cy="'+(fy+6)+'" rx="6" ry="3" transform="rotate(-30 '+(fx-6)+' '+(fy+6)+')" fill="#7fa36c" '+sw(1.8)+'/>';
    g+='<ellipse cx="'+(fx+6)+'" cy="'+(fy+6)+'" rx="6" ry="3" transform="rotate(30 '+(fx+6)+' '+(fy+6)+')" fill="#7fa36c" '+sw(1.8)+'/>';
    g+='<circle cx="'+fx+'" cy="'+fy+'" r="'+fr+'" fill="'+fcols[i%4]+'" '+sw(2)+'/><circle cx="'+fx+'" cy="'+fy+'" r="1.7" fill="'+I+'"/>';
  }
  g+='<rect x="114" y="406" width="212" height="22" rx="3" fill="#6f8f5e" '+sw(3)+'/><path d="M150 410 v14 M186 410 v14 M222 410 v14 M258 410 v14 M294 410 v14" stroke="#5b774c" stroke-width="2"/>';
  // door
  g+='<rect x="352" y="244" width="126" height="188" rx="4" fill="#ecc9a2" '+sw(3)+'/>';
  g+='<rect x="362" y="254" width="106" height="178" rx="4" fill="#6f8f5e" '+sw(3.5)+'/>';
  g+='<rect x="376" y="268" width="78" height="84" rx="4" fill="#fff0cc" '+sw(3)+'/>';
  g+='<path d="M384 300 l14 -12 M388 312 l22 -18" stroke="#fffaf0" stroke-width="3.5" stroke-linecap="round" opacity=".9"/>';
  g+='<rect x="376" y="364" width="78" height="54" rx="4" fill="#64834f" '+sw(2.5)+'/>';
  g+='<circle cx="461" cy="360" r="4.5" fill="#f2c66d" '+sw(2.5)+'/>';
  g+='<rect x="346" y="428" width="138" height="9" rx="2" fill="#d9c3a0" '+sw(3)+'/>';
  // plant
  g+='<circle cx="490" cy="378" r="11" fill="#7fa36c" '+sw(2.5)+'/><circle cx="508" cy="374" r="11" fill="#86ab72" '+sw(2.5)+'/><circle cx="499" cy="390" r="15" fill="#7fa36c" '+sw(2.5)+'/>';
  g+='<path d="M484 400 h30 l-4 30 h-22 z" fill="#b5654a" '+sw(3)+'/>';
  // ground
  g+='<path d="M8 432 H592 V448 Q300 458 8 448 Z" fill="#e2cba6" '+sw(3)+'/>';
  for(x=40;x<592;x+=44)g+='<path d="M'+x+' 435 l-4 11" stroke="'+I+'" stroke-width="1.6" stroke-linecap="round" opacity=".5"/>';
  // chalkboard
  g+='<path d="M534 446 L541 374 M580 446 L573 374" stroke="#b07a48" stroke-width="5" stroke-linecap="round"/>';
  g+='<rect x="534" y="378" width="44" height="54" rx="3" fill="#2f3b33" '+sw(3)+'/>';
  c+='<text x="556" y="394" text-anchor="middle" font-family="system-ui,sans-serif" font-weight="800" font-size="7.5" letter-spacing="1" fill="#fbf4e6">TODAY</text>';
  c+='<text x="556" y="407" text-anchor="middle" font-family="Segoe Print,Bradley Hand,Marker Felt,cursive" font-size="8" fill="#f2c66d">box of 6</text>';
  c+='<circle cx="556" cy="420" r="6" fill="none" stroke="#fbf4e6" stroke-width="1.4"/><path d="M552 420 h8 M556 416 v8" stroke="#fbf4e6" stroke-width="1.2"/>';
  c+='<text x="305" y="374" text-anchor="middle" transform="rotate(5 305 370)" font-family="Segoe Print,Bradley Hand,cursive" font-size="8" fill="#c8475b">fresh!</text>';
  // smoke + swinging door sign (outside the rough filter so they stay cheap)
  var p='';
  [0,1.6,3.2].forEach(function(d,k){p+='<circle class="puff" cx="'+(422+k*2)+'" cy="-8" r="'+(9+k)+'" fill="#fffaf0" '+sw(2)+' style="animation-delay:-'+d+'s"/>';});
  var sign='<g class="sway"><path d="M402 290 L415 276 L428 290" fill="none" stroke="'+I+'" stroke-width="1.8"/><circle cx="415" cy="276" r="2.4" fill="'+I+'"/><rect x="389" y="290" width="52" height="22" rx="4" fill="#fffaf0" '+sw(2.2)+'/><text id="doorSign" x="415" y="305.5" text-anchor="middle" font-family="system-ui,sans-serif" font-weight="800" font-size="10.5" letter-spacing="1.2" fill="#3f7a3a">OPEN</text></g>';
  return '<svg viewBox="0 -64 600 528" role="img" aria-labelledby="heroArtT"><title id="heroArtT">Hand-drawn illustration of the Larkspur Lane Bakehouse shop front, with a striped awning, a window full of bread and a green door</title>'+
    '<defs><filter id="rough" x="-3%" y="-3%" width="106%" height="106%"><feTurbulence type="fractalNoise" baseFrequency="0.035" numOctaves="2" seed="4" result="n"/><feDisplacementMap in="SourceGraphic" in2="n" scale="3.4" xChannelSelector="R" yChannelSelector="G"/></filter></defs>'+
    '<g class="rough" filter="url(#rough)">'+g+'</g>'+p+c+sign+'</svg>';
}
function mapSVG(){
  var I='#3b2416',s='<svg viewBox="0 0 320 190" role="img" aria-label="Hand-drawn map: the bakery sits on Larkspur Lane next to Mill Street, near Willow Park"><rect width="320" height="190" fill="#e7efd9"/>';
  s+='<path d="'+blob(262,44,48,6,10,9)+'" fill="#b9d39a" stroke="'+I+'" stroke-width="2"/>';
  [[244,34],[268,52],[284,30],[256,60]].forEach(function(t){s+='<circle cx="'+t[0]+'" cy="'+t[1]+'" r="7" fill="#7fa36c" stroke="'+I+'" stroke-width="1.8"/>';});
  s+='<path d="M-10 172 C80 140 160 200 330 150" fill="none" stroke="'+I+'" stroke-width="20"/><path d="M-10 172 C80 140 160 200 330 150" fill="none" stroke="#9cc7d9" stroke-width="16"/>';
  ['M0 104 H320','M118 0 V190','M200 104 L300 0'].forEach(function(d){s+='<path d="'+d+'" stroke="'+I+'" stroke-width="18" fill="none"/>';});
  ['M0 104 H320','M118 0 V190','M200 104 L300 0'].forEach(function(d){s+='<path d="'+d+'" stroke="#fffaf0" stroke-width="14" fill="none"/>';});
  s+='<path d="M0 104 H320" stroke="#e2cba6" stroke-width="1.5" stroke-dasharray="6 6"/>';
  s+='<text x="26" y="96" font-family="Segoe Print,Bradley Hand,cursive" font-size="10" fill="'+I+'">Larkspur Ln</text>';
  s+='<text x="124" y="24" font-family="Segoe Print,Bradley Hand,cursive" font-size="10" fill="'+I+'">Mill St</text>';
  s+='<text x="232" y="94" font-family="Segoe Print,Bradley Hand,cursive" font-size="10" fill="'+I+'">Willow Park</text>';
  s+='<rect x="150" y="70" width="30" height="22" fill="#f3d3b4" stroke="'+I+'" stroke-width="2"/><path d="M148 70 h34 v5 h-34z" fill="#c8475b" stroke="'+I+'" stroke-width="1.6"/>';
  s+='<path d="M165 60 c-9 0 -14 -7 -14 -13 a14 14 0 0 1 28 0 c0 6 -5 13 -14 13z" transform="translate(0 -6)" fill="#c8475b" stroke="'+I+'" stroke-width="2"/><circle cx="165" cy="41" r="4.5" fill="#fffaf0"/>';
  return s+'</svg>';
}

/* ---------- render static parts ---------- */
$('#heroArt').insertAdjacentHTML('afterbegin',heroSVG());
$('#mapArt').innerHTML=mapSVG();
$('#brandMark').innerHTML=artSvg('croissant');
$('#brandMark2').innerHTML=artSvg('croissant');
try{$('#bakesDate').textContent=new Date().toLocaleDateString(undefined,{weekday:'long',month:'long',day:'numeric'});}catch(e){}

var FEATURED=[['croissant','6:40 am',"Baker's pick"],['swirl','7:05 am',''],['tart','7:30 am',''],['muffin','6:55 am',''],['brownie','8:10 am',''],['turnover','7:45 am','New']];
$('#bakesGrid').innerHTML=FEATURED.map(function(fe){var p=byId[fe[0]];
  return '<article class="bake">'+(fe[2]?'<span class="ribbon">'+fe[2]+'</span>':'')+
    '<div class="plate">'+artSvg(p.id)+'</div><div><h3>'+p.name+'</h3><div class="time">Out of the oven · '+fe[1]+'</div><div class="tags">'+tagHTML(p)+'</div></div>'+
    '<p>'+p.desc+'</p><div class="row"><span class="price">'+money(p.price)+'</span><button class="btn btn-small js-add" type="button" data-id="'+p.id+'" aria-label="Add '+p.name+' to your box">+ Add to box</button></div></article>';
}).join('');

$('#sizes').innerHTML=SIZES.map(function(s){
  var dots='';for(var i=0;i<s.n;i++)dots+='<i></i>';
  return '<button class="size" type="button" data-size="'+s.n+'" aria-pressed="false"><span class="dots" style="grid-template-columns:repeat('+COLS[s.n]+',9px)">'+dots+'</span><b>'+s.label+' · '+s.n+'</b><small>'+s.sub+'</small></button>';
}).join('');

var grid=$('#pastryGrid');
grid.innerHTML=PASTRIES.map(function(p){
  var tl=p.tags.length?', '+p.tags.map(function(t){return TAG[t][1];}).join(', '):'';
  return '<button type="button" class="tile" data-id="'+p.id+'" aria-label="Add '+p.name+', '+money(p.price)+tl+'">'+
    '<span class="tile-art">'+artSvg(p.id)+'</span><span class="tile-name">'+p.name+'</span>'+
    '<span class="tile-row"><span class="tile-price">'+money(p.price)+'</span>'+tagHTML(p)+'</span><span class="miss"></span>'+
    '<span class="tile-count" aria-hidden="true"></span><span class="tile-add" aria-hidden="true">+</span></button>';
}).join('');
var tiles=$$('.tile',grid);

/* ---------- box ---------- */
var tray=$('#tray'),boxEl=$('#box'),panel=$('#panel');
function isMatch(id){var p=byId[id];return state.filters.every(function(t){return p.tags.indexOf(t)>=0;});}
function renderTray(){
  var n=state.size;
  boxEl.style.setProperty('--cols',COLS[n]);boxEl.style.setProperty('--rows',ROWS[n]);
  tray.style.setProperty('--cols',COLS[n]);
  boxEl.setAttribute('data-size',n);
  $('#lidLabel').textContent='box of '+n;
  var h='';for(var i=0;i<n;i++)h+='<button type="button" class="slot" data-i="'+i+'"></button>';
  tray.innerHTML=h;
  for(var j=0;j<n;j++)renderSlot(j);
}
function renderSlot(i,mode){
  var b=tray.children[i];if(!b)return;var s=state.slots[i];
  b.innerHTML='<span class="liner"><span class="num">'+(i+1)+'</span></span>'+(s?'<span class="item" data-key="'+s.key+'">'+artSvg(s.id)+'</span>':'');
  b.classList.toggle('filled',!!s);
  b.classList.toggle('mismatch',!!s&&!isMatch(s.id));
  b.setAttribute('aria-label',s?'Slot '+(i+1)+': '+byId[s.id].name+'. Tap to remove.':'Slot '+(i+1)+': empty');
  if(s&&mode){var it=b.querySelector('.item');it.classList.add(mode);}
}
function filledCount(){return state.slots.filter(Boolean).length;}
function slotOnScreen(el){var r=el.getBoundingClientRect();return r.bottom>0&&r.top<innerHeight&&r.width>0;}

function fly(src,dst,id,done){
  if(lowMotion()||!src||!dst||!document.body.animate)return false;
  var a=src.getBoundingClientRect(),b=dst.getBoundingClientRect();
  if(a.width===0||b.width===0||a.bottom<0||a.top>innerHeight||b.bottom<0||b.top>innerHeight)return false;
  var size=Math.min(a.width,a.height),g=document.createElement('div');
  g.className='flyer';g.innerHTML=artSvg(id);
  g.style.width=g.style.height=size+'px';
  g.style.left=(a.left+a.width/2-size/2)+'px';g.style.top=(a.top+a.height/2-size/2)+'px';
  document.body.appendChild(g);
  var dx=b.left+b.width/2-(a.left+a.width/2),dy=b.top+b.height/2-(a.top+a.height/2),sc=(b.width*.9)/size;
  var finished=false;function fin(){if(finished)return;finished=true;g.remove();done();}
  try{
    var an=g.animate([
      {transform:'translate(0px,0px) scale(1) rotate(0deg)'},
      {transform:'translate('+f(dx*.5)+'px,'+f(dy*.5-Math.min(120,Math.abs(dx)*.25+50))+'px) scale('+f((1+sc)/2*1.12)+') rotate(-14deg)',offset:.5},
      {transform:'translate('+f(dx)+'px,'+f(dy)+'px) scale('+f(sc)+') rotate(0deg)'}
    ],{duration:480,easing:'cubic-bezier(.45,0,.25,1)'});
    an.onfinish=fin;
  }catch(e){fin();}
  setTimeout(fin,800);
  return true;
}
function reveal(i,key){
  var s=state.slots[i];if(!s||s.key!==key)return;
  var b=tray.children[i];if(!b)return;var it=b.querySelector('.item.pending');if(!it)return;
  it.classList.remove('pending');it.classList.add('land');
  sfx.pop(i);afterFill();
}
function afterFill(){
  if(filledCount()===state.size&&!tray.querySelector('.pending')){
    setTimeout(function(){restart(boxEl,'happy');sfx.full();},120);
    toast(state.size===12?'Dozen complete — 10% off applied!':'Box full — looking delicious!');
  }
}
function addItem(id,srcEl,fromCard){
  var i=state.slots.indexOf(null);
  if(i<0){restart(boxEl,'shake');sfx.nope();toast('Your box is full. Tap a pastry in the box to swap it, or pick a bigger box.');return false;}
  var key=++state.key;state.slots[i]={id:id,key:key};
  var slotEl=tray.children[i];
  renderSlot(i,'pending');
  var flew=fly(srcEl,slotEl,id,function(){reveal(i,key);});
  if(!flew){
    var it=slotEl.querySelector('.item');it.classList.remove('pending');it.classList.add('drop');
    sfx.pop(i);
    if(fromCard||!slotOnScreen(slotEl)){
      var n=filledCount();
      if(n<state.size)toast('Added '+byId[id].name+' · '+n+'/'+state.size+' in your box');
    }
    afterFill();
  }
  if(!isMatch(id)&&!fromCard)toast('Added — heads up, '+byId[id].name+' doesn’t match your filters');
  restart($('#headBox'),'bump');
  update();
  return true;
}
function removeItem(i){
  var s=state.slots[i];if(!s)return;
  var b=tray.children[i],old=b.querySelector('.item');
  state.slots[i]=null;renderSlot(i);
  if(old&&!lowMotion()){old.classList.remove('drop','land','pending');old.classList.add('leaving');b.appendChild(old);setTimeout(function(){if(old.parentNode)old.remove();},280);}
  sfx.out();update();
}
function setSize(n){
  if(n===state.size)return;
  var items=state.slots.filter(Boolean),dropped=0;
  if(items.length>n){dropped=items.length-n;items=items.slice(0,n);}
  state.size=n;state.slots=[];for(var i=0;i<n;i++)state.slots.push(items[i]||null);
  renderTray();
  if(!lowMotion()){$$('.item',tray).forEach(function(it,k){it.style.animationDelay=(k*35)+'ms';it.classList.add('drop');});}
  restart(boxEl,'pop');sfx.tick();
  if(dropped)toast('Moved to a box of '+n+' — '+dropped+' pastr'+(dropped===1?'y':'ies')+' didn’t fit');
  update();
}
function resetBuilder(silent){
  state.size=6;state.slots=[null,null,null,null,null,null];state.filters=[];
  renderTray();applyFilters();update();
  if(!silent){restart(boxEl,'pop');sfx.out();toast('Fresh box, ready to fill');}
}

/* ---------- filters ---------- */
function applyFilters(){
  $$('.filter').forEach(function(b){b.setAttribute('aria-pressed',state.filters.indexOf(b.getAttribute('data-filter'))>=0?'true':'false');});
  var shown=0;
  tiles.forEach(function(t){
    var id=t.getAttribute('data-id'),ok=isMatch(id);if(ok)shown++;
    t.classList.toggle('dim',!ok);
    var miss=state.filters.filter(function(x){return byId[id].tags.indexOf(x)<0;}).map(function(x){return TAG[x][2];});
    t.querySelector('.miss').textContent=miss.join(' · ');
  });
  for(var i=0;i<state.slots.length;i++){var s=state.slots[i],b=tray.children[i];if(b)b.classList.toggle('mismatch',!!s&&!isMatch(s.id));}
  $('#clearFilters').hidden=!state.filters.length;
  $('#filterNote').textContent=state.filters.length?shown+' of '+PASTRIES.length+' pastries are '+state.filters.map(function(x){return TAG[x][1].toLowerCase();}).join(' + ')+'. The rest are dimmed.':'Showing all '+PASTRIES.length+' pastries.';
}
$('#filterRow').addEventListener('click',function(e){
  var b=e.target.closest('.filter');if(!b)return;
  var t=b.getAttribute('data-filter'),k=state.filters.indexOf(t);
  if(k>=0)state.filters.splice(k,1);else state.filters.push(t);
  sfx.tick();applyFilters();
});
$('#clearFilters').addEventListener('click',function(){state.filters=[];sfx.tick();applyFilters();});

/* ---------- totals ---------- */
var lastTotal=-1;
function update(){
  var items=state.slots.filter(Boolean),n=items.length,cap=state.size;
  var sub=items.reduce(function(a,it){return a+byId[it.id].price;},0);
  var disc=(cap===12&&n===12)?Math.round(sub*10)/100:0,total=sub-disc;
  $('#boxLabel').textContent='Box of '+cap;
  $('#fillCount').textContent=n+' of '+cap+' filled';
  $('#headCount').textContent=n+'/'+cap;
  var ta=$('#totalAmt');ta.textContent=money(total);
  if(total!==lastTotal&&lastTotal>=0)restart(ta,'bump');lastTotal=total;
  $('#subAmt').textContent=money(sub);$('#totalAmt2').textContent=money(total);
  $('#discRow').hidden=!disc;$('#discAmt').textContent='−'+money(disc);
  $('#meterFill').style.width=(n/cap*100)+'%';
  $('#hint').textContent=n===0?'Tap any pastry to drop it in.':n<cap?(cap-n)+' slot'+(cap-n===1?'':'s')+' left · tap a pastry in the box to take it out.':'Box full! Tap anything in the box to swap it.';
  var dn=$('#dealNote');dn.hidden=cap!==12;dn.textContent=n===12?'Dozen deal applied: 10% off.':'Fill all 12 slots to save 10%.';
  $$('.js-checkout').forEach(function(b){b.disabled=n===0;});
  $$('.size').forEach(function(b){b.setAttribute('aria-pressed',+b.getAttribute('data-size')===cap?'true':'false');});
  var counts={};items.forEach(function(it){counts[it.id]=(counts[it.id]||0)+1;});
  tiles.forEach(function(t){var c=counts[t.getAttribute('data-id')]||0,el=t.querySelector('.tile-count');el.textContent=c?'×'+c:'';el.classList.toggle('has',c>0);});
}

/* ---------- events ---------- */
grid.addEventListener('click',function(e){var b=e.target.closest('.tile');if(!b)return;addItem(b.getAttribute('data-id'),b.querySelector('.tile-art'),false);});
$('#bakesGrid').addEventListener('click',function(e){var b=e.target.closest('.js-add');if(!b)return;var card=b.closest('.bake');addItem(b.getAttribute('data-id'),card&&card.querySelector('.plate'),true);});
tray.addEventListener('click',function(e){
  var s=e.target.closest('.slot');if(!s)return;var i=+s.getAttribute('data-i');
  if(state.slots[i])removeItem(i);else{sfx.tick();toast('Tap a pastry from the menu to fill this slot');}
});
$('#sizes').addEventListener('click',function(e){var b=e.target.closest('.size');if(b)setSize(+b.getAttribute('data-size'));});
$('#resetBtn').addEventListener('click',function(){resetBuilder(false);});
$('#headBox').addEventListener('click',function(){scrollToId('build');});

function scrollToId(id){var t=document.getElementById(id);if(!t)return;t.scrollIntoView({behavior:lowMotion()?'auto':'smooth',block:'start'});}
document.addEventListener('click',function(e){
  var a=e.target.closest('a[href^="#"]');if(!a)return;
  var id=a.getAttribute('href').slice(1);
  if(id==='top'){e.preventDefault();window.scrollTo({top:0,behavior:lowMotion()?'auto':'smooth'});return;}
  if(document.getElementById(id)){e.preventDefault();scrollToId(id);}
});

/* ---------- drawer ---------- */
var drawer=$('#drawer'),scrim=$('#scrim'),lastFocus=null;
function drawerHTML(){
  var items=state.slots.filter(Boolean),cap=state.size,n=items.length,groups=[],gm={};
  items.forEach(function(it){if(!gm[it.id]){gm[it.id]={id:it.id,q:0};groups.push(gm[it.id]);}gm[it.id].q++;});
  var sub=items.reduce(function(a,it){return a+byId[it.id].price;},0),disc=(cap===12&&n===12)?Math.round(sub*10)/100:0,total=sub-disc;
  var mini='<div class="mini" style="--cols:'+COLS[cap]+'">'+state.slots.map(function(s){return '<span class="mini-slot">'+(s?artSvg(s.id):'')+'</span>';}).join('')+'</div>';
  var lines=groups.map(function(g){var p=byId[g.id];
    return '<li class="line"><span class="line-art">'+artSvg(g.id)+'</span><span class="line-txt"><b>'+p.name+'</b><small>'+g.q+' × '+money(p.price)+(p.tags.length?' · '+p.tags.map(function(t){return TAG[t][1];}).join(', '):'')+'</small></span><span class="line-amt">'+money(g.q*p.price)+'</span></li>';}).join('');
  var diet=['vegan','nutfree','gf'].map(function(t){var c=items.filter(function(it){return byId[it.id].tags.indexOf(t)>=0;}).length;
    return '<li><span class="tag tag-'+t+'">'+TAG[t][0]+'</span>'+TAG[t][1]+': <b>'+c+' of '+n+'</b></li>';}).join('');
  return '<div class="mini-wrap">'+mini+'<p class="mini-cap">Box of '+cap+' · '+n+' pastr'+(n===1?'y':'ies')+(n<cap?' · '+(cap-n)+' empty slot'+(cap-n===1?'':'s'):'')+'</p></div>'+
    '<ul class="lines">'+lines+'</ul>'+
    '<dl class="sums"><div><dt>Subtotal</dt><dd>'+money(sub)+'</dd></div>'+(disc?'<div class="save"><dt>Dozen deal (10%)</dt><dd>−'+money(disc)+'</dd></div>':'')+'<div class="grand"><dt>Total</dt><dd>'+money(total)+'</dd></div></dl>'+
    '<ul class="diet">'+diet+'</ul>'+
    '<div class="note"><b>How pickup works</b><p>Nothing has been sent or charged — this is just your summary. Show it at the counter, we’ll pack your box fresh while you wait, and you pay in the shop.</p></div>';
}
function openDrawer(){
  if(!filledCount()){restart(boxEl,'shake');toast('Add at least one pastry first');return;}
  $('#drawerTitle').textContent='Your box of '+state.size;
  $('#drawerBody').innerHTML=drawerHTML();$('#drawerBody').scrollTop=0;
  lastFocus=document.activeElement;
  drawer.classList.add('open');drawer.setAttribute('aria-hidden','false');try{drawer.inert=false;}catch(e){}
  scrim.classList.add('on');document.body.classList.add('locked');
  sfx.open();
  setTimeout(function(){try{$('#drawerClose').focus({preventScroll:true});}catch(e){}},60);
}
function closeDrawer(){
  if(!drawer.classList.contains('open'))return;
  drawer.classList.remove('open');drawer.setAttribute('aria-hidden','true');try{drawer.inert=true;}catch(e){}
  scrim.classList.remove('on');document.body.classList.remove('locked');
  if(lastFocus&&lastFocus.focus){try{lastFocus.focus({preventScroll:true});}catch(e){}}
}
try{drawer.inert=true;}catch(e){}
$$('.js-checkout').forEach(function(b){b.addEventListener('click',openDrawer);});
$('#drawerClose').addEventListener('click',closeDrawer);
$('#keepEditing').addEventListener('click',closeDrawer);
scrim.addEventListener('click',closeDrawer);
$('#newBox').addEventListener('click',function(){closeDrawer();resetBuilder(false);});
document.addEventListener('keydown',function(e){
  if(!drawer.classList.contains('open'))return;
  if(e.key==='Escape'){closeDrawer();return;}
  if(e.key==='Tab'){
    var fs=$$('button,[href]',drawer).filter(function(el){return !el.disabled&&el.offsetParent!==null;});
    if(!fs.length)return;var first=fs[0],last=fs[fs.length-1];
    if(e.shiftKey&&document.activeElement===first){e.preventDefault();last.focus();}
    else if(!e.shiftKey&&document.activeElement===last){e.preventDefault();first.focus();}
  }
});

/* ---------- opening hours ---------- */
var HOURS=[[480,780],null,[420,1080],[420,1080],[420,1080],[420,1080],[480,960]];
var DAYN=['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
function fmt(m){var h=Math.floor(m/60),mm=m%60,ap=h>=12?'pm':'am';h=h%12||12;return h+(mm?':'+(mm<10?'0':'')+mm:'')+' '+ap;}
function fmtNow(d){var h=d.getHours(),m=d.getMinutes();return fmt(h*60+m).replace(/^(\d+) /,'$1:00 ').replace(/:00:/,':');}
function hourStatus(now){
  var d=now.getDay(),m=now.getHours()*60+now.getMinutes(),t=HOURS[d];
  if(t&&m>=t[0]&&m<t[1]){var left=t[1]-m;return left<=30?{cls:'soon',text:'Closing soon · open until '+fmt(t[1]),sign:'OPEN'}:{cls:'open',text:'Open now · until '+fmt(t[1]),sign:'OPEN'};}
  if(t&&m<t[0])return {cls:'closed',text:'Closed · opens today at '+fmt(t[0]),sign:'CLOSED'};
  for(var k=1;k<=7;k++){var dd=(d+k)%7;if(HOURS[dd])return {cls:'closed',text:'Closed · opens '+(k===1?'tomorrow':DAYN[dd])+' at '+fmt(HOURS[dd][0]),sign:'CLOSED'};}
  return {cls:'closed',text:'Closed',sign:'CLOSED'};
}
$('#hoursBody').innerHTML=[1,2,3,4,5,6,0].map(function(d){return '<tr data-d="'+d+'"><td>'+DAYN[d]+'</td><td>'+(HOURS[d]?fmt(HOURS[d][0])+' – '+fmt(HOURS[d][1]):'Closed · baker’s day off')+'</td></tr>';}).join('');
function refreshHours(){
  var now=new Date(),s=hourStatus(now),today=now.getDay();
  $$('.js-status').forEach(function(el){el.classList.remove('open','soon','closed');el.classList.add(s.cls);el.querySelector('.txt').textContent=s.text;});
  $$('#hoursBody tr').forEach(function(tr){
    var isT=+tr.getAttribute('data-d')===today;tr.classList.toggle('today',isT);
    var first=tr.children[0],tag=first.querySelector('.today-tag');
    if(isT&&!tag)first.insertAdjacentHTML('beforeend','<span class="today-tag">Today</span>');
    if(!isT&&tag)tag.remove();
  });
  var ds=$('#doorSign');if(ds){ds.textContent=s.sign;ds.setAttribute('fill',s.sign==='OPEN'?'#3f7a3a':'#a63546');}
  var hh=now.getHours(),mm=now.getMinutes();
  $('#localTime').textContent='Your local time: '+DAYN[today]+', '+((hh%12)||12)+':'+(mm<10?'0':'')+mm+' '+(hh>=12?'pm':'am');
}
refreshHours();setInterval(refreshHours,20000);
document.addEventListener('visibilitychange',function(){if(!document.hidden)refreshHours();});

/* ---------- init builder ---------- */
renderTray();applyFilters();update();

/* ---------- adaptive quality ---------- */
(function(){
  if(reduced)return;
  var frames=0,start=0;
  function tick(t){
    if(!start)start=t;frames++;
    if(t-start<2200){requestAnimationFrame(tick);return;}
    if(document.visibilityState==='visible'&&frames*1000/(t-start)<40)document.documentElement.classList.add('lowfx');
  }
  requestAnimationFrame(tick);
})();

/* ---------- demo mode ---------- */
var ptr=$('#demoPtr'),badge=$('#demoBadge');
function movePtr(x,y){ptr.style.transform='translate('+Math.round(x)+'px,'+Math.round(y)+'px)';}
function wait(ms,tk){return new Promise(function(res,rej){setTimeout(function(){tk.alive?res():rej(new Error('stop'));},ms);});}
function visibleEl(sel){return $$(sel).filter(function(e){return e.offsetParent!==null;})[0];}
function tap(el,tk,after){
  if(!el)return wait(10,tk);
  var r=el.getBoundingClientRect();
  var inPanel=panel.contains(el)||drawer.contains(el);
  var stuck=window.innerWidth<900&&!inPanel;
  var lim=stuck?Math.max(70,panel.getBoundingClientRect().bottom+8):70;
  if(r.top<lim||r.bottom>innerHeight-10){
    window.scrollBy(0,(r.top+r.height/2)-(lim+(innerHeight-lim)/2));
  }
  return wait(140,tk).then(function(){
    r=el.getBoundingClientRect();movePtr(r.left+r.width/2,r.top+r.height/2);
    return wait(620,tk);
  }).then(function(){
    ptr.classList.remove('tap');void ptr.offsetWidth;ptr.classList.add('tap');
    el.click();
    return wait(after==null?320:after,tk);
  });
}
function demoOnce(tk){
  closeDrawer();resetBuilder(true);window.scrollTo(0,0);
  movePtr(innerWidth*.5,innerHeight*.55);
  var seq=[
    function(){return wait(900,tk);},
    function(){return tap(visibleEl('#heroCta'),tk,1150);},
    function(){return tap($('.tile[data-id="croissant"]'),tk,420);},
    function(){return tap($('.tile[data-id="painchoc"]'),tk,420);},
    function(){return tap($('.tile[data-id="swirl"]'),tk,420);},
    function(){return tap($('.filter[data-filter="vegan"]'),tk,520);},
    function(){return tap($('.tile[data-id="muffin"]'),tk,420);},
    function(){return tap($('.tile[data-id="donut"]'),tk,420);},
    function(){return tap(tray.children[0],tk,450);},
    function(){return tap($('.tile[data-id="cookie"]'),tk,420);},
    function(){return tap($('.filter[data-filter="vegan"]'),tk,380);},
    function(){return tap($('.size[data-size="12"]'),tk,520);},
    function(){return tap($('.tile[data-id="tart"]'),tk,420);},
    function(){return tap(visibleEl('.js-checkout'),tk,2500);},
    function(){return tap($('#drawerClose'),tk,500);},
    function(){return tap($('#resetBtn'),tk,900);}
  ];
  return seq.reduce(function(pr,step){return pr.then(step);},Promise.resolve());
}
function startDemo(){
  var tk={alive:true},EV=['pointerdown','keydown','wheel','touchstart'];
  ptr.classList.add('on');badge.hidden=false;
  function stop(e){
    if(!e.isTrusted)return;tk.alive=false;
    ptr.classList.remove('on');badge.hidden=true;
    EV.forEach(function(t){window.removeEventListener(t,stop,true);});
  }
  EV.forEach(function(t){window.addEventListener(t,stop,{capture:true,passive:true});});
  (function loop(){if(!tk.alive)return;demoOnce(tk).then(loop,function(){});})();
}

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