🎮ArcadeLab

Low Voltage Ascenders 4.6.7

by SuperPirate58
2121 lines337.3 KB
▶ Play
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Low Voltage Ascenders 4.6.7 Deferred Profile Gate & Drift Hotfix</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<style>
*{box-sizing:border-box}
html,body{margin:0;height:100%;overflow:hidden;background:#dce7ec;font-family:"Trebuchet MS","Segoe UI",Verdana,sans-serif;color:#1d2a4a;user-select:none;-webkit-user-select:none}
canvas#cv{position:absolute;left:0;top:0;width:100%;height:100%;display:block}
.screen{position:absolute;left:0;top:0;right:0;bottom:0;display:none;align-items:flex-start;justify-content:center;background:linear-gradient(155deg,#e8f1f5 0%,#b8d3df 45%,#6d96a8 100%);overflow:auto;padding:14px}
.screen.show{display:flex}
.wrap{width:1080px;max-width:100%;margin:auto}
h1.title{margin:0;font-size:46px;font-style:italic;letter-spacing:1px;color:#fff;text-shadow:0 3px 0 #00529b,0 6px 12px rgba(30,40,120,.45);line-height:1}
h1.title span{color:#ffe14a}
.sub{color:#eaf3ff;font-size:13px;margin:4px 0 10px;text-shadow:0 1px 3px rgba(0,0,0,.3)}
.topbar{display:flex;align-items:flex-end;justify-content:space-between;gap:12px;flex-wrap:wrap}
.pill{background:rgba(255,255,255,.92);border-radius:20px;padding:6px 14px;font-weight:700;display:inline-flex;align-items:center;gap:8px;box-shadow:0 2px 6px rgba(30,40,120,.25)}
.wiz{display:inline-block;width:20px;height:20px;border-radius:50%;background:radial-gradient(circle at 35% 30%,#fff7b0,#ffc61a 60%,#d98a00);border:2px solid #fff;box-shadow:0 1px 3px rgba(0,0,0,.3);text-align:center;font-size:11px;line-height:16px;color:#a25b00;font-weight:900}
.xpbar{width:130px;height:10px;border-radius:6px;background:#d6defa;overflow:hidden}
.xpbar>div{height:100%;background:linear-gradient(90deg,#4cd1ff,#7a6bff)}
.grid{display:grid;grid-template-columns:1.25fr 1fr;gap:12px;margin-top:10px}
@media(max-width:900px){.grid{grid-template-columns:1fr}}
.card{background:rgba(255,255,255,.94);border-radius:16px;padding:12px 14px;box-shadow:0 4px 14px rgba(30,40,120,.25)}
.card h2{margin:0 0 8px;font-size:15px;color:#075aa8;letter-spacing:.5px;text-transform:uppercase}
.chars{display:grid;grid-template-columns:repeat(3,minmax(118px,1fr));gap:8px}
.ch{position:relative;border:3px solid transparent;border-radius:12px;background:linear-gradient(180deg,#eef4ff,#dfe8ff);text-align:center;padding:4px 2px 6px;cursor:pointer;transition:transform .1s}
.ch:hover{transform:translateY(-2px)}
.ch.sel{border-color:#ff5ca8;background:linear-gradient(180deg,#fff0f8,#ffd9ec)}
.ch canvas{width:100%;max-width:120px;height:auto;display:block;margin:0 auto}
.ch b{display:block;font-size:14px}
.ch small{font-size:10.5px;color:#4b5b8a}.employee-level-badge{position:absolute;right:4px;top:4px;z-index:2;min-width:47px;padding:3px 5px;border-radius:10px;background:linear-gradient(180deg,#0067c6,#003f7d);border:2px solid #fff;color:#fff!important;font:900 10px/1.05 "Trebuchet MS",sans-serif;box-shadow:0 2px 6px rgba(0,0,0,.35);letter-spacing:.2px}.employee-level-badge small{display:block;color:#f2c500!important;font-size:7px;letter-spacing:.7px}.employee-xp-line{display:block;margin-top:3px;color:#365b6d!important;font-size:9px!important;font-weight:800}
.stat{display:flex;align-items:center;gap:8px;margin:7px 0;font-size:14px;font-weight:700}
.stat .nm{width:132px;line-height:1.05}
.stat .bar{flex:1;height:14px;border-radius:8px;background:#d6defa;position:relative;overflow:hidden}
.stat .bar i{position:absolute;left:0;top:0;bottom:0;background:linear-gradient(90deg,#46d3ff,#6a7bff)}
.stat .bar u{position:absolute;top:0;bottom:0;background:#ffcf3a;text-decoration:none}
.stat .bar em{position:absolute;top:0;bottom:0;background:#7ef0a0;font-style:normal}
.stat .v{width:44px;text-align:right}
button.b{font:inherit;font-weight:700;border:0;border-radius:10px;padding:6px 12px;background:#e5ebff;color:#075aa8;cursor:pointer;box-shadow:0 2px 0 #aab6ee}
button.b:hover{background:#d6e0ff}
button.b:active{transform:translateY(1px);box-shadow:0 1px 0 #aab6ee}
button.b:disabled{opacity:.45;cursor:default}
button.b.sm{padding:1px 9px;font-size:15px;border-radius:8px}
button.go{font-size:24px;padding:12px 34px;background:linear-gradient(180deg,#ffe85a,#ffb21a);color:#7a3d00;box-shadow:0 4px 0 #c47a00,0 8px 16px rgba(0,0,0,.25);font-style:italic;letter-spacing:1px}
button.go:hover{background:linear-gradient(180deg,#fff08a,#ffc13d)}
.boards .bd{display:flex;align-items:center;gap:10px;padding:6px 8px;border-radius:10px;border:3px solid transparent;margin-bottom:6px;background:#eef3ff}
.boards .bd.sel{border-color:#38c8ff;background:#e1f6ff}
.boards .sw{width:46px;height:18px;border-radius:9px;box-shadow:0 0 10px currentColor inset,0 0 8px currentColor}
.boards .info{flex:1;font-size:13px;line-height:1.2}
.boards .info small{color:#51629a}.gear-glow-blue{box-shadow:0 0 14px #1686c4,0 0 6px #fff inset!important}.gear-glow-gold{box-shadow:0 0 16px #ffd84d,0 0 7px #fff3a6 inset!important}.set-panel{border-left:8px solid var(--eaton-blue)}.set-row{display:flex;justify-content:space-between;gap:12px;padding:8px 0;border-bottom:1px solid #c9d8df}.set-row:last-child{border-bottom:0}.set-status{font-weight:900;white-space:nowrap}.set-status.active{color:#087b50}.set-status.inactive{color:#6b7a80}.section-toggle{width:100%;display:flex;justify-content:space-between;align-items:center;font-size:16px!important;padding:10px 12px!important}.gear-list{margin-top:10px}.caps .bd{display:flex;align-items:center;gap:10px;padding:8px;border-radius:10px;border:3px solid transparent;margin-bottom:6px;background:#eef3ff}.caps .bd.sel{border-color:#f2c500;background:#fff7cf}.cap-swatch{width:42px;height:28px;border-radius:18px 18px 7px 7px;border:3px solid rgba(255,255,255,.8);box-shadow:0 2px 6px rgba(0,0,0,.25)}
.row{display:flex;gap:6px;align-items:center;flex-wrap:wrap}
.seg button{border-radius:0}
.seg button:first-child{border-radius:10px 0 0 10px}
.seg button:last-child{border-radius:0 10px 10px 0}
.seg button.on{background:#075aa8;color:#fff;box-shadow:0 2px 0 #003b70}
.help{font-size:12.5px;line-height:1.55;color:#33427a}
.help kbd{background:#fff;border:1px solid #9fb0f0;border-bottom-width:2px;border-radius:5px;padding:0 6px;font-size:12px;font-family:inherit;font-weight:700;color:#075aa8}
.cta{display:flex;justify-content:center;margin-top:12px}
table.res{width:100%;border-collapse:collapse;font-size:15px}
table.res td,table.res th{padding:5px 8px;text-align:left}
table.res th{font-size:11px;text-transform:uppercase;color:#6a77ad}
table.res tr.me td{background:#fff2b8;font-weight:800}
table.res tr:nth-child(even) td{background:#f1f5ff}
table.res tr.me:nth-child(even) td{background:#fff2b8}
.big{font-size:60px;font-style:italic;font-weight:900;color:#ff5ca8;text-shadow:0 3px 0 #fff,0 6px 10px rgba(0,0,0,.2);line-height:1}
.rew{display:flex;gap:10px;flex-wrap:wrap;margin:8px 0}
.lvl{background:#fff2b8;border:2px solid #ffc61a;border-radius:10px;padding:6px 10px;font-weight:800;color:#8a5200;margin-bottom:8px}
#pause,#results{background:rgba(35,45,120,.5)}
#pause .card{margin:auto;text-align:center;min-width:300px}
.smooth-settings{display:grid;gap:10px;text-align:left;padding:12px;background:#eef3ff;border-radius:10px;margin:10px 0}.smooth-settings label{display:flex;align-items:center;justify-content:space-between;gap:12px;font-size:13px}.smooth-settings select{font:inherit;max-width:65%;padding:7px;border:1px solid #9fb0f0;border-radius:7px}.smooth-settings small{max-width:360px;line-height:1.4;color:#51629a}#smoothMonitor{position:fixed;right:8px;bottom:6px;z-index:4;pointer-events:none;background:#152344aa;color:#e3f6ff;font:11px system-ui;padding:4px 7px;border-radius:5px} 
.main-menu{max-width:780px;text-align:center}.factory-hero{position:relative;overflow:hidden;padding:28px 20px 22px;background:linear-gradient(145deg,#fff,#dcebf2);border:3px solid #075aa8}.factory-hero:before{content:"";position:absolute;inset:auto 0 0;height:34%;background:repeating-linear-gradient(90deg,#174e75 0 42px,#f1c40f 42px 52px,#174e75 52px 94px);opacity:.13}.factory-hero>*{position:relative}.version{display:inline-block;margin-top:7px;padding:4px 12px;border-radius:20px;background:#075aa8;color:#fff;font-weight:800;letter-spacing:.7px}.menu-grid{display:grid;grid-template-columns:repeat(2,minmax(180px,1fr));gap:14px;margin-top:18px}.menu-tile{min-height:105px;border:0;border-radius:16px;padding:16px;background:linear-gradient(160deg,#fff,#dceaf1);color:#075aa8;box-shadow:0 5px 0 #7d9fad,0 10px 24px rgba(16,54,75,.24);font:900 22px "Trebuchet MS",sans-serif;cursor:pointer}.menu-tile small{display:block;margin-top:7px;color:#4d6875;font-size:12px;font-weight:700}.menu-tile:hover{transform:translateY(-2px);background:linear-gradient(160deg,#fff,#cce7f3)}.submenu-head{display:flex;align-items:center;gap:12px;margin-bottom:10px}.submenu-head h2{margin:0;color:#075aa8;font-size:25px;text-transform:uppercase}.navrow{display:flex;gap:7px;flex-wrap:wrap;margin:10px 0}.navrow .b.on{background:#075aa8;color:#fff}.lva-badge{display:inline-flex;align-items:center;justify-content:center;width:24px;height:24px;border-radius:5px;background:#075aa8;color:#fff;font-size:11px;font-weight:900}.settings-grid{display:grid;grid-template-columns:1fr 1fr;gap:12px}.setting-line{display:flex;justify-content:space-between;align-items:center;gap:12px;padding:8px 0;border-bottom:1px solid #d4e1e7}.setting-line select{font:inherit;padding:6px;border:1px solid #87aabb;border-radius:7px}.reset-zone{border:2px solid #c94a43;background:#fff3f1}.reset-zone p{margin:4px 0 12px;color:#66312e;line-height:1.45}.danger{background:#b72f2a!important;color:#fff!important;box-shadow:0 2px 0 #741b18!important}.danger:hover{background:#c93d36!important}.reset-confirm{position:fixed;inset:0;z-index:20;display:flex;align-items:center;justify-content:center;padding:18px;background:rgba(13,28,45,.76)}.reset-confirm .card{width:min(520px,100%);padding:20px;text-align:center;border:3px solid #c94a43}.reset-confirm p{font-size:16px;line-height:1.5;color:#27374b;user-select:text;-webkit-user-select:text}.reset-confirm .row{justify-content:center;margin-top:16px}.credit-mark{font-size:28px;font-weight:900;color:#075aa8;letter-spacing:1px}.factory-note{color:#486270;line-height:1.55}.role{display:block;color:#075aa8!important;font-weight:800}.safety-stripe{height:7px;background:repeating-linear-gradient(135deg,#f2c500 0 8px,#1b3340 8px 16px);border-radius:4px;margin:8px 0}.jump-rule{padding:8px 10px;border-radius:9px;background:#e7f3f8;color:#294e60;font-size:13px;margin-top:8px}.title .volt{color:#f2c500}.training-tile{grid-column:1}.credits-tile{grid-column:1/-1}.training-list{display:grid;grid-template-columns:repeat(2,minmax(180px,1fr));gap:10px;margin:12px 0}.training-list span{padding:10px;border-radius:10px;background:#e7f3f8;color:#294e60;font-weight:800}@media(max-width:650px){.training-tile,.credits-tile{grid-column:auto}.training-list{grid-template-columns:1fr}}@media(max-width:650px){.menu-grid,.settings-grid{grid-template-columns:1fr}h1.title{font-size:35px}.menu-tile{min-height:82px}.submenu-head{align-items:flex-start}}
#touchControls{position:fixed;inset:0;z-index:6;display:none;pointer-events:none;--touch-size:62px}#touchControls.active{display:block}.touchCluster{position:absolute;bottom:max(14px,env(safe-area-inset-bottom));pointer-events:auto}.touchCluster.dpad{left:max(14px,env(safe-area-inset-left));display:grid;grid-template-columns:repeat(3,var(--touch-size));grid-template-rows:repeat(3,54px);gap:5px}.touchCluster.actions{right:max(14px,env(safe-area-inset-right));display:flex;flex-direction:column;align-items:center;gap:8px}.touchBtn{width:var(--touch-size);height:54px;border:2px solid rgba(255,255,255,.78);border-radius:15px;background:rgba(14,38,62,.78);color:#fff;font:900 13px "Trebuchet MS",sans-serif;box-shadow:0 3px 10px rgba(0,0,0,.38);touch-action:none;-webkit-tap-highlight-color:transparent}.touchBtn:active,.touchBtn.on{background:rgba(242,197,0,.92);color:#17313f;transform:translateY(1px)}.dpad-up{grid-column:2;grid-row:1}.dpad-left{grid-column:1;grid-row:2}.dpad-right{grid-column:3;grid-row:2}.dpad-down{grid-column:2;grid-row:3}.touchBtn.drift{width:94px;height:84px;border-radius:50%;background:linear-gradient(145deg,rgba(0,103,198,.92),rgba(0,63,125,.94));border:4px solid rgba(242,197,0,.9);font-size:15px}.touchMiniRow{display:flex;gap:7px}.touchInventory{display:flex;gap:8px}.touchBtn.inventory{width:76px;height:52px;font-size:10px;line-height:1.1;padding:3px}.touchBtn.inventory strong{display:block;font-size:16px;color:#f2c500}.touchBtn.inventory.empty{opacity:.62}.touchBtn.inventory.hidden{display:none}.touchBtn.compact{width:68px;height:42px;font-size:11px}.touchState{min-width:138px;padding:5px 8px;border-radius:13px;background:rgba(13,36,55,.82);border:1px solid rgba(255,255,255,.65);color:#fff;text-align:center;font:900 10px "Trebuchet MS",sans-serif;letter-spacing:.7px}.jump-mode .touchCluster.dpad{filter:drop-shadow(0 0 10px rgba(173,124,255,.9))}.jump-mode .touchBtn[data-jump-code]{background:rgba(91,53,160,.9);border-color:#fff}.jump-mode .touchBtn[data-jump-code].on{background:#ffe14a;color:#251743}@media(max-width:650px){#touchControls{--touch-size:54px}.touchCluster.dpad{grid-template-rows:repeat(3,48px);gap:4px}.touchBtn{height:48px;font-size:12px}.touchBtn.drift{width:82px;height:76px}.touchBtn.inventory{width:70px;height:50px}.touchBtn.compact{width:58px;height:38px}.touchState{min-width:122px}.chars{grid-template-columns:repeat(2,minmax(118px,1fr))}.stat .nm{width:105px}.boards .bd{align-items:flex-start}}
.toggle-switch{position:relative;display:inline-block;width:52px;height:28px;flex:0 0 52px}.toggle-switch input{position:absolute;opacity:0;width:1px;height:1px}.toggle-switch i{position:absolute;inset:0;border-radius:16px;background:#aab8c1;box-shadow:inset 0 0 0 2px #73838d;transition:.18s}.toggle-switch i:after{content:"OFF";position:absolute;left:55px;top:4px;width:28px;color:#5d3333;font:900 10px/16px sans-serif;letter-spacing:.4px}.toggle-switch i:before{content:"";position:absolute;width:20px;height:20px;left:4px;top:4px;border-radius:50%;background:#fff;box-shadow:0 2px 4px rgba(0,0,0,.3);transition:.18s}.toggle-switch input:checked+i{background:#19a974;box-shadow:inset 0 0 0 2px #087b50,0 0 9px rgba(25,169,116,.35)}.toggle-switch input:checked+i:after{content:"ON";color:#075a37}.toggle-switch input:checked+i:before{transform:translateX(24px)}.toggle-switch input:focus-visible+i{outline:3px solid #38c8ff;outline-offset:2px}.setting-line .toggle-switch,.smooth-settings .toggle-switch{margin-right:32px}.guest-card{border-left:8px solid #8b5a2b}.unlock-zone{border-left:8px solid #f2c500}.patch-notes{text-align:left;margin-top:12px}.patch-notes li{margin:6px 0}.custom-status{padding:8px 10px;margin:7px 0;background:#e7f3f8;border-left:5px solid #0067c6;color:#294e60;font-weight:800}

/* ===== Eaton LVA control-console interface · v4.6.7 Deferred Profile Gate & Drift Hotfix ===== */
:root{--eaton-blue:#0067c6;--eaton-blue-dark:#003f7d;--eaton-orange:#f58220;--eaton-steel:#d9e0e3;--eaton-ink:#17313f;--eaton-safety:#f2c500;--panel:#f6f9fa}
html,body{background:#cfd8dc;color:var(--eaton-ink)}
.screen{background:radial-gradient(circle at 16% 8%,rgba(255,255,255,.96),rgba(255,255,255,0) 30%),linear-gradient(145deg,#edf2f4 0%,#cbd7dc 52%,#91a6af 100%);padding:18px}
.screen:before{content:"";position:fixed;inset:0;pointer-events:none;opacity:.17;background-image:linear-gradient(rgba(0,103,198,.24) 1px,transparent 1px),linear-gradient(90deg,rgba(0,103,198,.24) 1px,transparent 1px);background-size:28px 28px;mask-image:linear-gradient(to bottom,#000,transparent 84%)}
.wrap{position:relative;padding:10px 12px 18px;border-top:9px solid var(--eaton-blue);border-bottom:5px solid var(--eaton-blue-dark);background:linear-gradient(90deg,rgba(255,255,255,.2),rgba(255,255,255,.58),rgba(255,255,255,.2));box-shadow:0 14px 34px rgba(18,48,65,.24)}
.wrap:before,.wrap:after{content:"";position:absolute;top:7px;width:8px;height:8px;border-radius:50%;background:#72858f;box-shadow:inset 0 1px 2px #fff}
.wrap:before{left:8px}.wrap:after{right:8px}
h1.title,h1.title span,h1.title .volt{color:var(--eaton-blue);text-shadow:0 2px 0 #fff,0 4px 12px rgba(0,63,125,.22)}
.sub{color:var(--eaton-blue);font-weight:900;letter-spacing:.65px;text-shadow:none;text-transform:uppercase}
.card{position:relative;background:linear-gradient(155deg,rgba(255,255,255,.98),rgba(235,241,244,.97));border:1px solid #8aa1ab;border-top:5px solid var(--eaton-blue);border-radius:9px;box-shadow:0 4px 0 #718791,0 11px 25px rgba(18,48,65,.22)}
.card:before{content:"";position:absolute;right:9px;top:8px;width:7px;height:7px;border-radius:50%;background:#19a974;box-shadow:0 0 0 2px #d6e0e4,0 0 8px rgba(25,169,116,.65)}
.card h2,.submenu-head h2,.credit-mark,.role{color:var(--eaton-blue)!important}
.pill{background:#f8fbfc;border:1px solid #86a1ad;color:var(--eaton-blue);box-shadow:0 2px 0 #9eafb6}
.version{background:#e6f2fc;color:var(--eaton-blue);border:2px solid var(--eaton-blue);box-shadow:inset 0 0 0 2px #fff}
.lva-badge{background:var(--eaton-safety);color:var(--eaton-blue);border:2px solid var(--eaton-blue-dark)}
button.b{border:1px solid #80a0af;background:linear-gradient(#f8fbfc,#dfe9ed);color:var(--eaton-blue);box-shadow:0 3px 0 #89a0aa}
button.b:hover{background:linear-gradient(#fff,#d7edf7);border-color:var(--eaton-blue)}
.seg button.on,.navrow .b.on{background:linear-gradient(#ffdf4d,var(--eaton-safety));color:var(--eaton-blue);border-color:var(--eaton-blue-dark);box-shadow:0 3px 0 #9a7d00}
button.go{background:linear-gradient(180deg,#ffdc48,var(--eaton-orange));color:var(--eaton-blue-dark);border:2px solid var(--eaton-blue-dark);box-shadow:0 4px 0 #a64d00,0 9px 18px rgba(0,63,125,.25)}
button.go:hover{background:linear-gradient(180deg,#fff07e,#ff9a3c)}
.danger{background:#fff0ee!important;color:var(--eaton-blue)!important;border:2px solid #b72f2a!important;box-shadow:0 3px 0 #8e2925!important}
.factory-hero{padding:22px 22px 20px;background:linear-gradient(120deg,#fff 0%,#edf4f7 56%,#c6d6dd 100%);border:2px solid #526c79;border-top:10px solid var(--eaton-blue);overflow:hidden;text-align:left}
.factory-hero:before{height:100%;opacity:.11;background:repeating-linear-gradient(135deg,var(--eaton-blue) 0 4px,transparent 4px 26px)}
.factory-hero:after{content:"";position:absolute;right:-52px;bottom:-72px;width:245px;height:245px;border:25px solid rgba(0,103,198,.11);border-radius:50%;box-shadow:0 0 0 18px rgba(245,130,32,.09)}
.console-kicker{display:flex;align-items:center;gap:12px;min-height:38px;padding:4px 10px;margin-bottom:8px;background:linear-gradient(90deg,#eef5f8,#d7e2e7);border:1px solid #8ca1ab;border-left:6px solid var(--eaton-orange);color:var(--eaton-blue-dark);font-size:11px;font-weight:900;letter-spacing:1.4px;text-transform:uppercase}
.eaton-wordmark{display:inline-block;width:118px;height:36px;flex:0 0 118px;background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPQAAABKCAYAAACM73n7AAAelUlEQVR42u2deZxdV33Yv79z71tmkyzJFgiMoSwGZLEUK6DFWDOfxAEMBvIJoyZpQxODZ4QhtEBSAi2fpxfaNE1Y0hJsz4BcCDG0mjokJDbwKVQSlka2kVNK7IHatcEmtrFkW8ts7917z/n1j3NnrPEsmuXeN2+UOZ/PteTRmbv8zm9fhd7Df4uadaCKiGH6UlR1+o9FEORZWwXEzbhfRODZ+/3dYcb9M70LqLp53xsU6xzGdJC4q7n5isfSd1QatSpqGEJYd+R6MO9B9BRKODccZ/nOhcJltnvPdqYz3lsFFTftjAQFWkDGUW1B5ELgOMrfk+hnuXnnvVTUUBXXMFhPnO2ewa+iwaVoUpt160JwfX64q2CKiPw2fduGqFQM1ers377rQMihroSewx8mKL4blwwDwdLO1BGCeR0m2IRaTV/87C3+PyKzAeXZP/DfN9P+mX6mmoJpIfsXsBdJKLeHxGN/CwxTUcNeFGkgglXFce3hDsR8gLB4KXHkEMzc7z4Le1ooXJDp95nrTGe89wT/k7OfpygxxhQpdkD9DGD+CGcf4As7b57c10hi9sxD6Rl8FU6vIZB2rEyFddb4dTbuKpZSW0B0ugDA0GVzY9nLO4RDgJjnU2x/DbWTDjFmaWcaEIKM4WyCEE1DdWV2zBIVz6GmcXOdk3tOvf8CpKVK+j4673uL1gmKa6mPfpObrxim+94isiWi0SssW7R+CpsoMI6eLR1mfPc5KHpG3jx/OC783mft1wmObQkL7UCNaKSPRG5m37YfAtC9P2Cg2zVUCwKooqhC7z1PItEpXNKCUEdF5o9fS8Fd57C1Vgg+SEWvo8o8mZlYkpqiZhQmNLe5cH2OMxKVENSkItygKgs7aJ2FpWe1fzbgzuPeIg6VMvXhMwQ86P99wLJ8K/AakBo4S2roHDBYKlzm3L+ovV6LM0E7NjlEYP41N237QUrIRTZf5Kh2JcsDXlFQoX/r4/QODiPBxaibgPc8v3UpuCuCIiiXp5rJ/M5UVbwoVoM+W5tY4JkqZ9ty59lSNYSFEkn9bvp3fptuDRjYbVldC6UTL7lELUoLYauQjP57+q74xLPU3ahJDl7gaLAwTpYNpHDWIryY9x19NTdu/2HD/TVTJMV5hoYINrUVEyoVAwOrxLkI6kCxiFqCYivCz6iPbKXvik9QORBSSaVfQx1f85HUy7VcnbDcgdNuUKHnnoYLzPD8RUQnOOsQ/SuqVTeJfKtrYYwRVaTQShL9iKDwNvpe/xDdGlCVpEmPXtBBaZzjc8qjHUEIljKIcnJ/w9/iPEVy9WEGVUPdfg2Avegqfc6bjBXUgTqCYgvODuGiX+bG1z9ERUMGpIlNF1Fk2d7PEEcO1Z3sObKRzd3JgvxSqxJ6VrhaRMuo+yk1qxOyZnXNW78RBIcErah9GPRX+WLXP9C9v3klc0UNIo7eo52gl4CNvZOpgQcvGJJ6TBBuR3UTVTnO0P4AsOcC+KqEnhuwCaU1gsqn+VrXk/QcKyyrbTX2lCBGaHolQR2CeJu53IqzZ3D8C/p3/phdGja1U3EopVxhA2jL9JBqoxihJIQFB27L8qgI5x0xi6JqsBEEwfCquF0Q7ATViLBcRpMjYN5K//bDVNRwqFlt5mkrhmV10gUkdQP8LpWKaTQTPP9Ubp+JVyIeH4HwfgBOPuRWqXWeDN4EJWzyKMNPXc0tV59J1eyVE+5TWV5NSADnFGTDnKmfqxJ63gB1hMUQMYfpf8NRKgfC1fjzvDVuS1AqYOMvpsRcXIXdojQdh0gH7xl8aSpkZJWgly6pH/O2VWd+7Pq8CoVpQqGthXjs63xh5ydTRhivvO9wppHZ+jPa0WiNUvsFGP0IAL2Ni0efXwQtoj4VIra44DMADOByI+amSqhYEuAcJiji4gfoaPtNugcMezstrMRQn9QRXT6tQtLqiSQCoZXu/cGqyr0E9ghaRt04Ln4k10dVxdF79GXz2tu6QVGnTRo7E7CWsFzA1vfx6deOTjLHlbQGxKIq9G2/HeQnSFBEjFsGFFSUgKTmQN/Fhue/mv6tcUMIW1TMeUbPlmKrAb2ZsFzzQMwYMStqQIXe770LVa8FdGuwgqEWU2xvIR75K/qu+ONVn0NWclpqBOUWnJYBOH6RzMlTM8F/Oc/SIQVH2CKIuZv+rTHPLhjPYg0NhJ5JhFdj5MXsOhBy/KCsUHgpIgEucoh8DhHl4Co1Zqt+mx4ADnU2hEk2jqBFfHHZtGsWCTrT3rnvbRFTYvzkCeCB1LNoMz8iui3XH2hHWU9Q3sylpU4OdSWLltIzwuQc35rdcgRhmSS6m5t2HJjsorG6stAWDUldQTupHAgbldhkcuZQJu0YoSghSnHahQZTEHji7zPuRaYhu6T3hpCwXET1+/TtuJu9B7Mvl+xWw4BYXLgFE7wjheDzAFh3zzlgKWZKG58JwpzpO/23zky8qoU5CX5BSJdqaGI+DaJ0Hlz5Tj5VaXT+9BxatGJob2SNuMnxgwJUE1QTgrAMbgx4ctqlmiCmjEjJX6YMWphxL5ipeyf2uzFUn0ZthNGHqFRMrqqjDdcRBIAD55577gYFj4FoDVMUIH1/ygilWb7zSUSLfs/Z3yolDCMePqoLaowwowwJiiTRAzy95jZAqO5d+QUssqzFGWdDV0BipLCOPUc/CCrsz98xFuYCUDRE3VMguxGxWNtFUPgqN77+oZR36WTxd+/gTpzdhgQjSGJwUkA4Qd+Or027d8+Rd4J7EUoNI755nbPthPLX3LDj/3Hd4C8xFtzNTVUH1eyRcyDtRCHuw9gEX9AuH+D939nH5696anpBu6hvFvf2Mfbc3YOtv8l/pxqcMxipc9P2fTNK4p4jv43TNoIUOdUJGDB6G1b+K2HYhU3G0MX6CdRS6jCMnfojNg8k9BwL6Zd45VJyytyuv+u5JElHWi22vJJaiAiLJaLRV4Io3zlmppmBoprtI3sHHwIuAeJsAvLiEGlB3f+mf8frzkv7qOfoP4B7HpgaogW0eAn9Wx9HVRoS7ukd/BjltX9I7cwwqsVFIL8jKJRI6g8gLV1suvwJqmjDu6FycKqGONSpKdNc+Ht0a8CAWHrv2g32v4PWF9w/LXuCTjCmiLU/QuRqnrv9cdgL1aqj51iB/q0x1x35Y4otv0dcG81CwOaUwaKAFOjpK7DpMQudhmqnnRFhKhXD0F55pqNINzDAjPbvREvcKd1HutPkEdHJzo95JkRce7gDXBkxDnVgghBbXws8fk7bbjdmXt8JvtnexJ6J1XpRgS931uFIK0th7CKKCQwm+AF9Wx9n14EQGmTn7ToQsvGiiZZFbsYzfvyekP7Lk0UxGJVxhOQZTXBZ7fkC1saEpVeTRK+iKo96WJ+V4y2SKccJc+ROyo8vVfp79Bk1YwYVqEpKgN1TiXTee896Yp6ZW5UDIdUuS2gqhKUN2Pqot+kDwH0K9Bp2D0xXqaY6weZv281E6D3HDIiiR5b2nSqCS0D0NlSFvTgONUAlruyVSQfR+++6FKcvw8YlSBNAxJyiKgcnCf1cva1nVhANTZPBI4qIw4QK9TEAOiFPWId5sqfzKgTyeMeE7b+WoAhJ3YfcnAPRC7002b8SbE1ACyQ6gpRuTX0e+avXVXFUUXoH3426HST2LRRaL6HQ/owgrQ8rPYdvBfNT2tb8R6pbnvZtgRcQrXCqmCy/SWOE4uwtfs9JBgaXCCK/ReXAIOQbSciBoB2IUZyGfGhw/WTHkDyXKRriMwn9V53ODyFJ6L1zM+LeSjSagAS+f1USg9lCz5FfpH/ndydtueZdjiAs4ez3aY3yP5tKxRNz9/61rLv4IxRa/x2oEI8r0diob7c86XsoUGx9FwiMnf419txZ4aZtN9OjBfolmZcKLaYENgSNliyoRQ1BqZ2kXl+KfUMSAfp2ql3X5g3uHAhaDKoxwksY4+8gmL0v8kLhPdPviFosazDtA8CeVDXOWDM4aKArQQ9dSPGCTUSj3oHh7diEckcbteHXAN9N49HN3HPLEZTBje7jszvGPbxyal7QvT+gutvy3u9dSrH1dpx7CfHoGBiLaggSTvoC/CQKJR5Pc8nDizHBPnrv6KBP/vM5JfXmifwF+SnCaTBtCMmiHb2+zWBMEt2JmG2gdnH3UoMQgSlz/R2XccMb7/Pm5D0rSOXWSdK7ZE6uqou697MhbymWCsTjPuRyMI8POuilSO/gm3Fnaxzi2wT7tQLMCwWRgHjcYROvzeRVXjpBgO+982KK4XdAno9LvN8BLc7IzX3s1uOkJuOoEwodf0rv947Td+XX5mTW1UlJ/316Bx9DgleiLl5C6CoAOQP8IYXyN4nHYq+VLQrsMcVyG/H4R4F3T2/vm53Jn2OmmChQB6IZL5nl53NdMsP/K45odJzIfQqAQznYKNWqS1XCXyepCWfniCsh9REH2sPv/N1F9F+eNEWm0szH7UCKqHsSJa1Gy6NfuQoDuy2/c3+JUG8HfQHJeM0nxMy3IEh8hmFcG6fQ8RWuO/x2ql3JOauWKhXjMweXzKccSgvICPH4I6gpL7q1kUxKonV07w/YdHlupk7eudwy66Vz/Nv8fwegAJzhBdGjKfVp5sgJ0Hv0ZYjZADyL66tBXYQJLqM+7HN29+5tToIWdYRFg7jvs+/KH+ZTWaVCN4aPHltLdPxWwpZXYaPTiFl4PrOqQa0QjQsmvIVrj2zxc7PmYJjVqsskNVZxGNNG//bDKF+l1GYQt0jHGIHXIKWLdc97PVVJqA8HK5Gg81YhHaU2QeW/UO20aQeRjMslD3rnF+63CAodQDwNnwSHCYDwGv+DvU1rQKd/PJmbut2NYTPKqWgLxTVvJRobQaW86C6cvhZgjEK5ndD9Pog2bCKFqneIGjOc2vrhIpmFgEQUW9sgXA/A+pKsEvRMXDQsCWLu89z/YPbf83iHT+dUNmBCZkVMdYB5j0+UGWjeckrnFJGf5Hb/AbE+H0D/hGRMkSXWiqsoQkg0XscU3s71d72W/q2zV7d5lTurAmPLk3evw4WfJx5/ItUGF+2+AAHjNoEKa+q6StDPpiATlhl76hGIHvDzqzoztp9VOHm540OD60G3YKNk5mHbIqh6aC5Dp8cFIFWIi+u40T9Nzeds37VS8fjUc3grEv5TrE3IoomGIuASCq0dJMmveGk5MIfKrUlmjqaaC+nfehq142CWctOAaBiU36f7aBk6o1WCnkpEjkIpRLmDviuHePyaIPNMscpBH1MeNVsptu3ExvXZiyEkwbmX0HN4K/u7m3eWlmrA+Jp8VNah7vS+5sMUWsqIqWV33BJQH1ZEruOD30y7kZ5l+/jJGUrP4OtANqEuya44QwWR+72Te9E4JigW3Dqee6FLsx7PFt//yAlaVHAOoIaqsGlYc+QdF4DU8fHlqd52IQJN0OgMhdZ1EL4BEfWdTZoQZkJMe5S9FtG9P2BgS8yeA1vAXUU8GqNayI4RIWlcuYN62/rpzCQVyUHwEuACsC6TaEMQ+XRb0c9gTJq+u+j7RgTl9dSf/GBehTArl6BVAmw0DvI/fEipM4dwVVdC5UCI6mcotZcor11Dy9oOyms7aEmv8toOyhd0UGhfT+sGA+7N9HyjFbqbK7lEUB8KMqeo5zYFQ6G4kbB0IS5LCTl55paw2I4UP+CZyMB0/E1cHUgyT+d2csJnBtoljFUShwlB3K68jnllTs7wXUqKqHua/h3f8sSXU2HG0All3Qs+yNjTrWjsscTyTCT6bLK10cRgdJo3/TOnGPnmtAmedSWKJUhim7nAmHxzvXDKM6eIKJFMv9EWPV6Fa+4nOf11wtZ3ktTGFkU7ooKznjGtEvSzBEFQMNjkntz7YPk47V+yus6lzXgkNeafEdd9uClzpVKd7+TE+oZ9VyGNPd+wZYTewXsJC+/0LXoXUZ6pEpDU6wTFq7ju6Fv4wvZvAkUyrKBceQQtCCoJYUmJ489yKFWL8+zbVDkQptVW516bhrWRPaQW4RTLK6SWIrdcnFv11kTFk0j7Mik3p0jqkqauLvIj1RKWWnFR2yTcMmxashIltAMNsJFM9o7Kc9zNhC29uuZeE7nbqt8gKP4iNlmm5gJiUgda9ozw+u8NYPUjiFyEw2FEF8EghaQGYn6Div4lPx+MsnzXlecUU1GMlEjqDyPuJ6AyWWmzuhZiiOZjQ8N9SJCPE3cyJ1qnjwmemJzRar+F8FPEFDKdnLEX4cZdP0P1BCb0nVcXpe2IwcYJzr3dF5SQZEmGK9DLrY6wVcDcRv8VD9JzT3j+zJg6H5ZrBc2LwfoEHszJWXd8dsc4fkZ0tpxraEB84oy7FTGK0SXgnFhMqH6UkiQrpNoqtyMNsDGgPwPg5OWrxLxAksiXno1ijOByeY5BLeCe8ER2Qhumhhy/SHwWoBnAFJYGRcESlkJwewCbJe/JmaDVZXqJWm8/x08xGtwwqWqtrnkcRZqppKwjLJcyv//QCd+aWc2D1M78HBOUl5BVNRsjCrC2TlBPz767ccx8Y/p9lGKisUf9MLzFfp96BUJpAx1ZGRJa1GCClqlXOMMVzHLNsFeCVsJyAeE0t2w7s0qli0ImQ314JPPbDuy29NwTsm/7j4BvUCgHkPVYVwE4ziinGu4kGOh29NwT0r/1QURvptgesuimFj41HeEVIC8gqTvIJlU4Hy+39zGOofZBVII0jDHLvGFJuzSe5WAQUXQmZDAW4guA/wAsrivkP3IDFwmLFPTXgC9RQabmFC9xTaTfGnccMYIfhiiLbrA3hQ+ppdhSJhr9HF/u8pNFZ9bO/EDXPOvdrEbYBNSZRfGPifpoke0Il+Hq0fwbPzScoMUBLSg/pmS6sOOe4M6sU3hi+vbnPAfGT06HyplZGtipDbjlai+dq9VV7/bCGK0jCAy4NwBfmsx/zmpVu7yDR+L/RDR6NRK+BueiJUsfEQtBibg2gnN/7Xucz1Jtdf297dgzxVwccxP+GiPHSMZqiBRAFpkzblzKdi5ATJJV7D7HvtwifC4vtXhy5MwqQS/OtdHqHT05jMHtdgE3yAg9Rz5Ey7pDjD2VgBQRXYKkVjAmIK5/mC9eeT+nZ2gY2K0BIpY9R98E+iJUYxSTqQY+INZrhTu+Rc+RnyDySpTxJaj5vtgjw2SffJ1iuw6EnviyvmSVkBeNPwKiGwDf9D1zWxPnx6eWhqidvI1Sewci0RL6WseYsBUb/R++eOUXJvuVzb7iTJ1xswkUMQ9jCpq9n6CZCXrjiXReUtbX6lqkP0ywkUXZxnsPv3ZeTfcWrpop1U5L/9YneU7tncRjPyAsdaDu7JlV55JI4v0wGlNqa8clZwitb9FcOUe/NpWcu8Xs9d+IVggKknsYsKkIemVivU8gmJgznMXVNDa0CuoiguIGjLzIq90XSR4P8j25Oy2ceRM2uY9SewuCTUOQds7fRS04R7GtHWu/DfZd3HDlXQyd0HM6QUUbRGBykng8WtywwBVF0C6NsTnNvqNkY7B+sm1vVhdNQtSKICah2AqYdQC8vCOnMM9uS/eA4aY3HSeKfhkb3YEJ2wjCFjAFkBiIEYkQifzfSTCUkaAFUyrh3H/jyQffSt8b/+e8R+K4IMwqBDSLgE4LRNxpcI/6SR3aNJGWfCZnOBch8mJ6B+/2jomlIqJaTLAeZ3+DL+z8/oLnHS1kve+OdVhXxoSWOO0hVTbT443xmGBtAG1Tf95acrj4mQMeGSvwZfl5EznEQuojiuj1XH/vADdsGcnNL+GLNQSRx3jz7VdxyZpuJPgo6EZKbRtReaZNl6qni2j0p4icIgg+wJ+9bpBKReZVTTeZz+9OAjWEcNGdRudEb1F6jhW48fIT9B79KqW2j1Mfyb72u3kIesL7oiUIfmHpeCKAs7ReEDD61Br/s+58HHiHuhKcfJKg9W3YuEaQcvokmd4bS0pCoCVwUyVcVEtA4xQKjpa2dnoGP0n/ji83R9xcDM7GwKvTut6cHzcx9P7qOvAXwF/Qe+dmotFrUw9d2qbIWVRqWPkT9u14evL3q3vx+c7nWM9MzjhA79GHQV6B6Diak7QWUa478hgukWYyXfMLW6k4cEtsEieKON/GdezkMC78+VRunOHqxI/5VF5JofxCbJxggnDOIVwzMiuZan6EBYiTa6noV3wSR7UZLC1LGLaQ1PYAn6Ebw0CO87g8E/OFFbsHDH3bhoDfnXV/9/7Ap3UuxgmqAkdNrhNlJ6ajvPfOW4lr/wYxL0BtPavkkOYk6OnYvRj1UIA65Y5W6sN/zhe3DdFzrEBV4sylc7Ur4frBN2O5gvpwDcHikrElcnFDPN4GPKepKsImHUeym55jN/F/D0YNeKqmRQh+IMJkE8XNZ20ZgoHueGn5+aIwmL+fZa8a9m1/gp7BRwjCF2KdNoO/u7kbHPjgRZh29zzpD+tY9s95eYdwCHByAaW2IrXhUT80TZYGHy+XHMJGeo68gv6dP4aKgWVWu5WAJBonCH8BW+/iUNdtuXd9ebZ67LumruylKvQefeIZzWD5fZ9NHrYyFglKxGNPUU8+B0Df5RkjnQqb/sbyL39SxumvktTJrN+Fv8s4xfZ1IO8BoOeaoClAKyhiDMIH6Okr+EHkKiueyDKdnDHX2pvWHNg+7zOSiYGGqwQ9h2YjqAbAU3xp188mnRF52Hj2dAD6FpLIZm4LqQPRi+jpK+TaP3xhUjokicYwhTdjtryc6l49LxJp/bC6pGHSUtx92MihrtgMmcjNTdAqijEAP/PdIvKQIGnmUfuZLkzQCibKlMMLIdGow+k7SC57cT7ZWYuy7xWY6KL5MRCl82Cwcik5xY33DL4UZQNpv9zcHvcHf+Cno4yWRkFvJyyHqZG1StBzijZTUERupFp1VHJgu92XpZlh5p/7VL6MM40UQaRGsWUtYaGjeUALQAEbxyBv4b13XUZnZ/OO8DnnOeJH4QRyOSIbUZfvnG5VGLov5JZtZ1D9JmFZYJmbbYhKkx+eC3CJ4Or3A+Qy1XGitYzKGtT62HHmEx9QXx+cvKjJbBpQF1Fas44g/k3vrDq4wtOBgzHQhEbo3N1DNi3U+Dnx+ChIYVntaJUm5sYiCWG5iLPfxRYfpaKG/d3ZT0vs7HRcP/hShC04a8kDJkJAEoGID0I3VUqshNROR1D4PfYceZsf/6MreOaZMzTKgN6dprf27fg6rn6vb7u0vGmgzXtwqkpYMqBH2bfjaYbuCzPnfhMTK5NgJ4X2S1Ct+Q4rkrXandYk6AU0Q2xjJuYZGAPm4x4u/SvXllZzdlVXo3BVUHl61Sk2t8OmQFKvIeZ+UPHqTcZr07CvCpLkn4Bqft1nEZRxJHwuPYd7AfG14k1jTwfYeBRT2MZ1d3yM/t7Y1zSvRAmtLfj8Cm0svrqjTZAo1qQErfhm+rb+CDdt+8qkepOxwUG1K2HjCy9A5X1Eo4pIjpJJLYWyAfMSQNl4wjQZzAOSyGJKn6DnjmtWnOo9mQ6s9wJPgoQNsWcnzEBj+rBR7OeHL5/a3aQH5iTtHXg8TRTIfk0UyieuAyMbkIzDVdMlhyGpKcIvsefIRga6Yx+Kax7ZhiEiMC1IuBcg855jea6J4oy+bUOgJ5AgaGgzDBMZ0KcxFFNvt6wS9DMqjAOjKIepVh1792YPnKHLJLV/PoQpBKjL9/BVDDaJUV6J00tAdPIdmkdKh9joNIXya+i98wYGxNK9v8gKomsvACRsmMY9UU55Q+cTwKcotAmCYZkM6iZVudVgAgH98hTiy+dANvsqPpP3AQgiEYVyCXFpo/vuJoM7imoL0WiNUtv76D3yrxjYHVH5XyvHnq7u1eVpCySKk+E0UWdV5T6LwGKKrSXi8T+H0iPsOhDmFubx2Wcb/EDLBoghUQMOXPjrVNQwQBP2FBf1oazhEQg+Re/hd3h7+kB5ZeR6i++k2UitYqK9r/Aw0WiEUFiuXmOhn35HghCz7LqVCkiEKZQReZi+rWP0HCtwKGtCTiuLegffTVC8jCQ6CRQ8IuT6eQlJXATtWlo5pTpUE9/GJw8im2i0ZyNM4VZ67vgVqm/8m+Ym5BQO7z/8PBJpxdk6IktLMNF5/vaAWLo1oJ9vc92RQcLSFbh4FAgaT9DCRkodJZwtNce5uDaCIjg3ktszJoa3q7uYto1FRo8XMQ3SKkXAxpvpOXoF/dsPU1GzcOKWVlrWhdj6+nzfOxUyYfkb7Bn8twyf+jNuufpM2hmkuUo5Kvh3et/RC1F9PqX2EOdKiydn8Wclo/O8wwCwWzGDJyivDYlG1i5HGCtE3VuIx4uLHtOT9XJWiGqKM38P+O4QmatID6WhhuAhxk5dS1J/EGoBgclfBU6AsGig8Li3+Ragmk3AQsyNxGO3k9SVIMpHq4o1IHAODXYRBj9CdTNrN7wY+EHqpGwugvZMUbhx+w/pGXwDzq4hGtfFV/yHkCQgxafPUuXnoOc0fBXwcWojnyepLUu3gf8PvoKdGcoprfUAAAAASUVORK5CYII=) center/contain no-repeat}
.signal-led{margin-left:auto;width:10px;height:10px;border-radius:50%;background:#19a974;box-shadow:0 0 10px #19a974}
.hero-kicker{color:var(--eaton-blue);font-weight:900;letter-spacing:1.8px;text-transform:uppercase;font-size:12px}
.hero-display{display:grid;grid-template-columns:1fr 190px;gap:18px;align-items:center;margin-top:8px}
.breaker-console{display:grid;grid-template-columns:repeat(2,1fr);gap:7px;padding:10px;background:#414f56;border:5px solid #26343b;box-shadow:inset 0 0 0 2px #87969d,0 5px 14px rgba(0,0,0,.25)}
.breaker-cell{height:55px;position:relative;background:linear-gradient(145deg,#cbd3d6,#9ca9ae);border:2px solid #6b7a80;box-shadow:inset 0 0 0 1px #eef3f5}
.breaker-cell:before{content:"";position:absolute;left:12px;top:9px;width:27px;height:33px;background:#242d31;border:3px solid #68767c;box-shadow:inset 0 0 0 2px #111}
.breaker-cell:after{content:"";position:absolute;right:9px;top:11px;width:8px;height:8px;border-radius:50%;background:#21b56f;box-shadow:0 15px 0 #e13d32,0 0 7px #21b56f}
.value-strip{display:grid;grid-template-columns:repeat(4,1fr);gap:5px;margin:10px 0 2px}
.value-chip{padding:7px 5px;background:#e4edf1;border-bottom:3px solid var(--eaton-blue);color:var(--eaton-blue-dark);font-size:10px;font-weight:900;letter-spacing:.8px;text-align:center}
.menu-grid{gap:12px}
.menu-tile{position:relative;overflow:hidden;min-height:112px;padding:15px 16px 15px 72px;text-align:left;background:linear-gradient(145deg,#fff,#dbe7ec);color:var(--eaton-blue);border:1px solid #76909c;border-left:8px solid var(--eaton-blue);border-radius:7px;box-shadow:0 5px 0 #6e848e,0 10px 18px rgba(16,54,75,.18)}
.menu-tile:after{content:"";position:absolute;right:9px;top:9px;width:8px;height:8px;border-radius:50%;background:#19a974;box-shadow:0 0 7px #19a974}
.menu-tile:hover{background:linear-gradient(145deg,#fff,#cce5f2);border-left-color:var(--eaton-orange)}
.tile-icon{position:absolute;left:14px;top:22px;display:grid;place-items:center;width:42px;height:42px;background:var(--eaton-blue);color:var(--eaton-safety);border:3px solid #fff;box-shadow:0 0 0 2px var(--eaton-blue-dark);font-size:22px}
.menu-tile small{color:#365b6d}
.safety-stripe{height:9px;border:1px solid #526771;background:repeating-linear-gradient(135deg,var(--eaton-safety) 0 9px,#17313f 9px 18px)}
.training-list span,.jump-rule{background:#e2eef3;border-left:4px solid var(--eaton-blue);color:#274e61}
.setting-line{border-bottom:1px solid #aec0c8}.setting-line:focus-within{background:#e9f4fa}
.ch{border-radius:7px;background:linear-gradient(180deg,#f6fafb,#dce7eb);border:2px solid #9cb0b9}
.ch.sel{border-color:var(--eaton-orange);background:linear-gradient(180deg,#fff7e8,#ffe1bd);box-shadow:0 0 0 2px var(--eaton-blue)}
.boards .bd,.caps .bd{border-radius:6px;background:#e8f0f3}
#pause,#results{background:rgba(18,49,65,.68)}
@media(max-width:820px){.menu-grid,.settings-grid{grid-template-columns:1fr}.training-tile,.credits-tile{grid-column:auto}.menu-tile{min-height:92px}}
@media(max-width:650px){.screen{padding:8px}.wrap{padding:7px}.console-kicker{gap:7px;letter-spacing:.6px}.eaton-wordmark{width:84px;height:28px;flex-basis:84px}.hero-display{grid-template-columns:1fr}.breaker-console{display:none}.value-strip{grid-template-columns:repeat(2,1fr)}.menu-tile{padding-left:65px}}

.circuit-stack{display:grid;gap:14px;margin:12px 0}.circuit-card{position:relative;overflow:hidden;padding:14px;border:2px solid #6f8792;border-left-width:9px;border-radius:9px;background:linear-gradient(145deg,#f9fbfc,#dce6ea);box-shadow:0 4px 0 #6f8189}.circuit-card:after{content:"";position:absolute;right:-32px;top:-42px;width:130px;height:130px;border:18px solid rgba(255,255,255,.2);border-radius:50%}.circuit-head{position:relative;z-index:1;display:flex;align-items:flex-start;justify-content:space-between;gap:12px;margin-bottom:9px}.circuit-head h3{margin:0;font-size:19px;color:#073f78}.circuit-head p{margin:3px 0 0;color:#365b6d;font-size:12px;line-height:1.4}.difficulty-badge,.difficulty-lock{display:inline-flex;align-items:center;gap:6px;padding:5px 9px;border-radius:16px;background:#eef6fa;border:2px solid #0067c6;color:#003f7d;font-size:11px;font-weight:900;letter-spacing:.6px;text-transform:uppercase;white-space:nowrap}.circuit-tracks{position:relative;z-index:1;display:grid;grid-template-columns:repeat(3,minmax(140px,1fr));gap:8px}.circuit-track{min-height:88px!important;text-align:left;position:relative}.circuit-track.on{border-color:var(--eaton-orange)!important;background:linear-gradient(180deg,#fff7e8,#ffe1bd)!important;color:var(--eaton-blue-dark)!important;box-shadow:0 0 0 2px var(--eaton-blue),0 4px 0 var(--eaton-orange)!important;transform:translateY(-1px)}.circuit-track.on:after{content:"SELECTED";position:absolute;right:7px;top:6px;padding:2px 5px;border-radius:9px;background:var(--eaton-blue);color:#fff;font-size:8px;font-weight:900;letter-spacing:.6px}.circuit-track small{display:block;margin-top:5px;line-height:1.32;color:#385866}.circuit-copper{border-left-color:#c66d23;background:linear-gradient(145deg,#fff9ef,#e6c49c)}.circuit-copper .difficulty-badge{border-color:#a9571b;background:#fff1dd;color:#70340d}.circuit-assembly{border-left-color:#0067c6;background:linear-gradient(145deg,#f7fcff,#c9e2f1)}.circuit-arc{border-left-color:#f58220;background:linear-gradient(145deg,#172a42,#294d6e)}.circuit-arc h3,.circuit-arc p{color:#f2f7fa}.circuit-arc .difficulty-badge{border-color:#f58220;background:#102239;color:#ffd1a8}.circuit-arc .circuit-track{background:linear-gradient(#ecf7ff,#b9d9ea);border-color:#71b5df}.open-race{margin-top:14px;padding-top:12px;border-top:2px solid #a9bbc3}.open-race h3{margin:0 0 5px;color:#0067c6}.open-race>small{display:block;color:#516b78;margin-bottom:8px}.track-difficulty{font-weight:900;text-transform:uppercase}.track-difficulty.easy{color:#23835c}.track-difficulty.normal{color:#0067c6}.track-difficulty.hard{color:#c15b12}@media(max-width:820px){.circuit-tracks{grid-template-columns:1fr}.circuit-head{flex-direction:column}.circuit-track{min-height:72px!important}}

.profile-grid{display:grid;grid-template-columns:repeat(2,minmax(250px,1fr));gap:12px}.profile-grid input,.profile-grid select,.profile-grid textarea{width:100%;font:inherit;padding:9px;border:1px solid #87aabb;border-radius:7px;background:#fff;color:#17313f}.profile-grid textarea{min-height:108px;resize:vertical;user-select:text;-webkit-user-select:text}.profile-status{margin:8px 0;padding:9px 11px;border-left:5px solid var(--eaton-blue);background:#e7f3f8;color:#274e61;font-weight:800}.profile-status.error{border-left-color:#b72f2a;background:#fff0ee;color:#76251f}.profile-name{font-size:24px;font-weight:900;color:var(--eaton-blue)}.startup-profile-prompt .card{border-color:var(--eaton-blue);box-shadow:0 0 0 4px rgba(245,130,32,.28),0 18px 55px rgba(0,0,0,.35)}.startup-profile-prompt .startup-default{box-shadow:0 0 0 3px var(--eaton-safety),0 4px 0 #0c4f82}.startup-profile-prompt .startup-choice{display:grid;grid-template-columns:1fr 1fr;gap:10px;margin-top:16px}.startup-profile-prompt .startup-choice small{display:block;margin-top:4px;font-size:10px;line-height:1.25}.startup-profile-prompt .recommendation{margin-top:12px;padding:9px;border-left:5px solid var(--eaton-orange);background:#fff3e5;color:#5e3515;font-weight:900;text-align:left}@media(max-width:560px){.startup-profile-prompt .startup-choice{grid-template-columns:1fr}}.state-key{display:flex;flex-wrap:wrap;gap:6px;margin-top:8px}.state-key span{padding:4px 8px;border-radius:12px;background:#e4edf1;color:#284d5e;font-size:11px;font-weight:900}@media(max-width:720px){.profile-grid{grid-template-columns:1fr}}

/* ===== v4.6.7 Deferred Profile Gate & Drift Hotfix systems ===== */
.game-difficulty-card{margin-bottom:10px;border-left:8px solid var(--eaton-orange)}.game-difficulty-card .row{justify-content:space-between}.game-difficulty-card p{margin:5px 0 0}
.range-line{display:grid;grid-template-columns:minmax(170px,1fr) minmax(180px,2fr) 90px;align-items:center;gap:12px}.range-line input{width:100%;accent-color:var(--eaton-blue)}.range-value{font-weight:900;color:var(--eaton-blue);text-align:right}
.grand-prix-btn{position:relative;z-index:2;margin:0 0 10px;width:100%;padding:10px!important;background:linear-gradient(90deg,var(--eaton-blue),#0b87d5)!important;color:#fff!important;border:2px solid #fff!important;box-shadow:0 3px 0 var(--eaton-blue-dark)!important;text-transform:uppercase;letter-spacing:1px}.grand-prix-btn:hover{background:linear-gradient(90deg,#0b87d5,var(--eaton-orange))!important}
.gp-status{padding:8px 10px;margin:8px 0;border-left:5px solid var(--eaton-orange);background:#e7f3f8;color:#294e60;font-weight:800}.gp-standings td:nth-child(3),.gp-standings th:nth-child(3){text-align:right}
.podium-card{max-width:900px!important;overflow:hidden}.podium-stage{display:flex;align-items:flex-end;justify-content:center;gap:12px;min-height:410px;padding:18px 8px 0;background:radial-gradient(circle at 50% 0,#fff 0,#dceef7 45%,#91b1c0 100%);border:2px solid #678491;border-radius:8px}.podium-slot{width:min(29%,220px);text-align:center;display:flex;flex-direction:column;align-items:center}.podium-slot canvas{width:120px;height:150px;max-width:100%}.podium-reward{min-height:48px;margin-bottom:4px;padding:5px 8px;border-radius:8px;background:#fff;border:2px solid var(--eaton-blue);color:var(--eaton-blue-dark);font-size:12px;font-weight:900}.podium-name{min-height:34px;color:var(--eaton-blue-dark);font-weight:900}.podium-block{width:100%;display:grid;place-items:center;color:#fff;font-size:64px;font-weight:900;border:4px solid rgba(255,255,255,.75);box-shadow:inset 0 0 0 3px rgba(0,0,0,.12)}.place-1 .podium-block{height:155px;background:linear-gradient(#f2c500,#b88800)}.place-2 .podium-block{height:112px;background:linear-gradient(#aebbc1,#73858e)}.place-3 .podium-block{height:82px;background:linear-gradient(#d07b42,#8d4720)}.podium-headline{font-size:32px!important;color:var(--eaton-blue)!important;margin-bottom:10px}.podium-note{margin:10px 0;color:#365b6d;font-weight:800}
@media(max-width:650px){.range-line{grid-template-columns:1fr}.range-value{text-align:left}.podium-stage{gap:4px;min-height:330px}.podium-slot{width:32%}.podium-slot canvas{width:82px;height:103px}.podium-reward{font-size:9px;padding:3px}.podium-name{font-size:11px}.podium-block{font-size:40px}.place-1 .podium-block{height:120px}.place-2 .podium-block{height:88px}.place-3 .podium-block{height:65px}.podium-headline{font-size:23px!important}}
</style>
</head>
<body>
<canvas id="cv"></canvas>
<div id="menu" class="screen"></div>
<div id="results" class="screen"></div>
<div id="pause" class="screen"><div class="card"><h2>Production Paused</h2><div class="smooth-settings"><label>Graphics <select id="smoothQuality"><option value="performance">Performance Saver · 1×</option><option value="balanced" selected>Balanced · 1.25×</option><option value="high">High · up to 2×</option></select></label><label><span>Stable camera</span><span class="toggle-switch"><input type="checkbox" id="smoothCamera" aria-label="Stable camera" checked><i></i></span></label><label><span>Impact screen shake</span><span class="toggle-switch"><input type="checkbox" id="smoothShake" aria-label="Impact screen shake" checked><i></i></span></label><label><span>Show frame rate</span><span class="toggle-switch"><input type="checkbox" id="smoothFPS" aria-label="Show frame rate" checked><i></i></span></label><small>Visual interpolation remains active. Performance Saver culls off-screen objects, trims particles and shadows, and keeps physics at 60 Hz.</small></div><div class="row" style="justify-content:center;margin:8px 0"><button class="b" id="bResume">Resume</button><button class="b" id="bRestart">Restart activity</button><button class="b" id="bQuit">Main Menu</button></div><div class="help">Main Menu → Settings contains the complete control guide.</div></div></div>
<div id="smoothMonitor" aria-hidden="true">LVA 4.6.7 Deferred Profile Gate & Drift Hotfix · 60 FPS</div>
<div id="touchControls" aria-label="Mobile driving controls"><div class="touchCluster dpad" aria-label="Directional pad"><button class="touchBtn dpad-up" data-touch="ArrowUp" data-jump-code="KeyA" data-drive-label="▲ GO" data-jump-label="A">▲ GO</button><button class="touchBtn dpad-left" data-touch="ArrowLeft" data-jump-code="KeyF" data-drive-label="◀ LEFT" data-jump-label="F">◀ LEFT</button><button class="touchBtn dpad-right" data-touch="ArrowRight" data-jump-code="KeyS" data-drive-label="RIGHT ▶" data-jump-label="S">RIGHT ▶</button><button class="touchBtn dpad-down" data-touch="ArrowDown" data-jump-code="KeyD" data-drive-label="▼ BRAKE" data-jump-label="D">▼ BRAKE</button></div><div class="touchCluster actions"><div class="touchState" id="touchState">STATE · BASE</div><button class="touchBtn drift" data-touch="ShiftLeft">DRIFT</button><div class="touchInventory" aria-label="Touch inventory slots"><button class="touchBtn inventory" data-touch-action="item-slot" data-slot="0"><strong>Q</strong><span>EMPTY</span></button><button class="touchBtn inventory hidden" data-touch-action="item-slot" data-slot="1"><strong>E</strong><span>EMPTY</span></button></div><div class="touchMiniRow"><button class="touchBtn compact" data-touch-action="pause">PAUSE</button></div></div></div><script>
'use strict';
/* Low Voltage Ascenders — embedded LVA environment assets v0.1
   Paste this file into the game's single HTML <script> block. */
window.LVAEnvironmentAssets = (() => {
  const svg = {"switchgear_lineup_front":"<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"1200\" height=\"720\" viewBox=\"0 0 1200 720\" role=\"img\" aria-label=\"Cartoon LVA switchgear lineup, front view\">\n<defs>\n <linearGradient id=\"steel\" x1=\"0\" y1=\"0\" x2=\"1\" y2=\"1\"><stop offset=\"0\" stop-color=\"#DCE3E2\"/><stop offset=\"1\" stop-color=\"#9FAAAC\"/></linearGradient>\n <linearGradient id=\"dark\" x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\"><stop offset=\"0\" stop-color=\"#343D41\"/><stop offset=\"1\" stop-color=\"#172027\"/></linearGradient>\n <filter id=\"shadow\" x=\"-30%\" y=\"-30%\" width=\"160%\" height=\"170%\"><feDropShadow dx=\"0\" dy=\"12\" stdDeviation=\"10\" flood-color=\"#000\" flood-opacity=\".25\"/></filter>\n</defs><ellipse cx=\"600\" cy=\"680\" rx=\"520\" ry=\"25\" fill=\"#000\" opacity=\".18\"/><g transform=\"translate(85 70)\"><rect width=\"260\" height=\"590\" rx=\"8\" fill=\"url(#steel)\" stroke=\"#172027\" stroke-width=\"8\"/>\n<rect x=\"0\" y=\"0\" width=\"260\" height=\"59.0\" rx=\"6\" fill=\"url(#dark)\"/><text x=\"20.8\" y=\"41.300000000000004\" font-family=\"Arial,sans-serif\" font-size=\"20\" font-weight=\"800\" fill=\"#F7FAF9\">LVA</text><path d=\"M 0 196.7 H 260\" stroke=\"#172027\" stroke-width=\"7\"/><path d=\"M 0 393.3 H 260\" stroke=\"#172027\" stroke-width=\"7\"/><g transform=\"translate(67.6 89.975)\">\n<rect width=\"124.8\" height=\"75.71666666666667\" rx=\"10\" fill=\"#172027\" stroke=\"#0C1114\" stroke-width=\"6\"/>\n<rect x=\"10.0\" y=\"6.1\" width=\"42.4\" height=\"40.9\" rx=\"5\" fill=\"#343D41\" stroke=\"#DCE3E2\" stroke-width=\"4\"/>\n<rect x=\"16.2\" y=\"11.4\" width=\"30.0\" height=\"13.6\" rx=\"3\" fill=\"#B9CFB4\"/>\n<g fill=\"#DCE3E2\"><circle cx=\"21.2\" cy=\"31.0\" r=\"3\"/><circle cx=\"28.7\" cy=\"31.0\" r=\"3\"/><circle cx=\"36.2\" cy=\"31.0\" r=\"3\"/><circle cx=\"43.7\" cy=\"31.0\" r=\"3\"/></g><rect x=\"62.4\" y=\"9.1\" width=\"49.9\" height=\"36.3\" rx=\"7\" fill=\"#3B4445\" stroke=\"#9FAAAC\" stroke-width=\"4\"/>\n<rect x=\"69.9\" y=\"16.7\" width=\"17.5\" height=\"12.1\" rx=\"3\" fill=\"#E43D3D\"/><path d=\"M 78.6 18.9 v 7.6\" stroke=\"white\" stroke-width=\"5\"/>\n<rect x=\"92.4\" y=\"16.7\" width=\"15.0\" height=\"12.1\" rx=\"3\" fill=\"#47B95C\"/><path d=\"M 99.8 18.9 v 7.6\" stroke=\"white\" stroke-width=\"5\"/>\n<path d=\"M 62.4 9.1 h 42.4 q 10.0 0 10.0 6.1\" fill=\"none\" stroke=\"#F7FAF9\" stroke-width=\"4\" opacity=\".55\"/>\n<rect x=\"10.0\" y=\"53.0\" width=\"104.8\" height=\"13.6\" rx=\"4\" fill=\"#9FAAAC\"/>\n<rect x=\"18.7\" y=\"56.8\" width=\"44.9\" height=\"3.8\" fill=\"#DCE3E2\"/><rect x=\"18.7\" y=\"62.1\" width=\"68.6\" height=\"1.9\" fill=\"#707C7F\"/>\n</g><rect x=\"213.2\" y=\"103.1\" width=\"15.6\" height=\"41.3\" rx=\"3\" fill=\"#172027\"/><g transform=\"translate(67.6 240.91666666666666)\">\n<rect width=\"124.8\" height=\"108.16666666666667\" rx=\"10\" fill=\"#172027\" stroke=\"#0C1114\" stroke-width=\"6\"/>\n<rect x=\"10.0\" y=\"8.7\" width=\"42.4\" height=\"58.4\" rx=\"5\" fill=\"#343D41\" stroke=\"#DCE3E2\" stroke-width=\"4\"/>\n<rect x=\"16.2\" y=\"16.2\" width=\"30.0\" height=\"19.5\" rx=\"3\" fill=\"#B9CFB4\"/>\n<g fill=\"#DCE3E2\"><circle cx=\"21.2\" cy=\"44.3\" r=\"3\"/><circle cx=\"28.7\" cy=\"44.3\" r=\"3\"/><circle cx=\"36.2\" cy=\"44.3\" r=\"3\"/><circle cx=\"43.7\" cy=\"44.3\" r=\"3\"/></g><rect x=\"62.4\" y=\"13.0\" width=\"49.9\" height=\"51.9\" rx=\"7\" fill=\"#3B4445\" stroke=\"#9FAAAC\" stroke-width=\"4\"/>\n<rect x=\"69.9\" y=\"23.8\" width=\"17.5\" height=\"17.3\" rx=\"3\" fill=\"#E43D3D\"/><path d=\"M 78.6 27.0 v 10.8\" stroke=\"white\" stroke-width=\"5\"/>\n<rect x=\"92.4\" y=\"23.8\" width=\"15.0\" height=\"17.3\" rx=\"3\" fill=\"#1677C8\"/><path d=\"M 99.8 27.0 v 10.8\" stroke=\"white\" stroke-width=\"5\"/>\n<path d=\"M 62.4 13.0 h 42.4 q 10.0 0 10.0 8.7\" fill=\"none\" stroke=\"#F7FAF9\" stroke-width=\"4\" opacity=\".55\"/>\n<rect x=\"10.0\" y=\"75.7\" width=\"104.8\" height=\"19.5\" rx=\"4\" fill=\"#9FAAAC\"/>\n<rect x=\"18.7\" y=\"81.1\" width=\"44.9\" height=\"5.4\" fill=\"#DCE3E2\"/><rect x=\"18.7\" y=\"88.7\" width=\"68.6\" height=\"2.7\" fill=\"#707C7F\"/>\n</g><rect x=\"213.2\" y=\"259.6\" width=\"15.6\" height=\"59.0\" rx=\"3\" fill=\"#172027\"/><g transform=\"translate(67.6 437.5833333333333)\">\n<rect width=\"124.8\" height=\"108.16666666666667\" rx=\"10\" fill=\"#172027\" stroke=\"#0C1114\" stroke-width=\"6\"/>\n<rect x=\"10.0\" y=\"8.7\" width=\"42.4\" height=\"58.4\" rx=\"5\" fill=\"#343D41\" stroke=\"#DCE3E2\" stroke-width=\"4\"/>\n<rect x=\"16.2\" y=\"16.2\" width=\"30.0\" height=\"19.5\" rx=\"3\" fill=\"#B9CFB4\"/>\n<g fill=\"#DCE3E2\"><circle cx=\"21.2\" cy=\"44.3\" r=\"3\"/><circle cx=\"28.7\" cy=\"44.3\" r=\"3\"/><circle cx=\"36.2\" cy=\"44.3\" r=\"3\"/><circle cx=\"43.7\" cy=\"44.3\" r=\"3\"/></g><rect x=\"62.4\" y=\"13.0\" width=\"49.9\" height=\"51.9\" rx=\"7\" fill=\"#3B4445\" stroke=\"#9FAAAC\" stroke-width=\"4\"/>\n<rect x=\"69.9\" y=\"23.8\" width=\"17.5\" height=\"17.3\" rx=\"3\" fill=\"#E43D3D\"/><path d=\"M 78.6 27.0 v 10.8\" stroke=\"white\" stroke-width=\"5\"/>\n<rect x=\"92.4\" y=\"23.8\" width=\"15.0\" height=\"17.3\" rx=\"3\" fill=\"#47B95C\"/><path d=\"M 99.8 27.0 v 10.8\" stroke=\"white\" stroke-width=\"5\"/>\n<path d=\"M 62.4 13.0 h 42.4 q 10.0 0 10.0 8.7\" fill=\"none\" stroke=\"#F7FAF9\" stroke-width=\"4\" opacity=\".55\"/>\n<rect x=\"10.0\" y=\"75.7\" width=\"104.8\" height=\"19.5\" rx=\"4\" fill=\"#9FAAAC\"/>\n<rect x=\"18.7\" y=\"81.1\" width=\"44.9\" height=\"5.4\" fill=\"#DCE3E2\"/><rect x=\"18.7\" y=\"88.7\" width=\"68.6\" height=\"2.7\" fill=\"#707C7F\"/>\n</g><rect x=\"213.2\" y=\"456.3\" width=\"15.6\" height=\"59.0\" rx=\"3\" fill=\"#172027\"/><circle cx=\"12\" cy=\"16\" r=\"4\" fill=\"#172027\" opacity=\".65\"/><circle cx=\"12\" cy=\"574\" r=\"4\" fill=\"#172027\" opacity=\".65\"/><circle cx=\"248\" cy=\"16\" r=\"4\" fill=\"#172027\" opacity=\".65\"/><circle cx=\"248\" cy=\"574\" r=\"4\" fill=\"#172027\" opacity=\".65\"/></g><g transform=\"translate(345 70)\"><rect width=\"260\" height=\"590\" rx=\"8\" fill=\"url(#steel)\" stroke=\"#172027\" stroke-width=\"8\"/>\n<rect x=\"0\" y=\"0\" width=\"260\" height=\"59.0\" rx=\"6\" fill=\"url(#dark)\"/><text x=\"20.8\" y=\"41.300000000000004\" font-family=\"Arial,sans-serif\" font-size=\"20\" font-weight=\"800\" fill=\"#F7FAF9\">LVA</text><path d=\"M 0 196.7 H 260\" stroke=\"#172027\" stroke-width=\"7\"/><path d=\"M 0 393.3 H 260\" stroke=\"#172027\" stroke-width=\"7\"/><g transform=\"translate(67.6 89.975)\">\n<rect width=\"124.8\" height=\"75.71666666666667\" rx=\"10\" fill=\"#172027\" stroke=\"#0C1114\" stroke-width=\"6\"/>\n<rect x=\"10.0\" y=\"6.1\" width=\"42.4\" height=\"40.9\" rx=\"5\" fill=\"#343D41\" stroke=\"#DCE3E2\" stroke-width=\"4\"/>\n<rect x=\"16.2\" y=\"11.4\" width=\"30.0\" height=\"13.6\" rx=\"3\" fill=\"#B9CFB4\"/>\n<g fill=\"#DCE3E2\"><circle cx=\"21.2\" cy=\"31.0\" r=\"3\"/><circle cx=\"28.7\" cy=\"31.0\" r=\"3\"/><circle cx=\"36.2\" cy=\"31.0\" r=\"3\"/><circle cx=\"43.7\" cy=\"31.0\" r=\"3\"/></g><rect x=\"62.4\" y=\"9.1\" width=\"49.9\" height=\"36.3\" rx=\"7\" fill=\"#3B4445\" stroke=\"#9FAAAC\" stroke-width=\"4\"/>\n<rect x=\"69.9\" y=\"16.7\" width=\"17.5\" height=\"12.1\" rx=\"3\" fill=\"#E43D3D\"/><path d=\"M 78.6 18.9 v 7.6\" stroke=\"white\" stroke-width=\"5\"/>\n<rect x=\"92.4\" y=\"16.7\" width=\"15.0\" height=\"12.1\" rx=\"3\" fill=\"#47B95C\"/><path d=\"M 99.8 18.9 v 7.6\" stroke=\"white\" stroke-width=\"5\"/>\n<path d=\"M 62.4 9.1 h 42.4 q 10.0 0 10.0 6.1\" fill=\"none\" stroke=\"#F7FAF9\" stroke-width=\"4\" opacity=\".55\"/>\n<rect x=\"10.0\" y=\"53.0\" width=\"104.8\" height=\"13.6\" rx=\"4\" fill=\"#9FAAAC\"/>\n<rect x=\"18.7\" y=\"56.8\" width=\"44.9\" height=\"3.8\" fill=\"#DCE3E2\"/><rect x=\"18.7\" y=\"62.1\" width=\"68.6\" height=\"1.9\" fill=\"#707C7F\"/>\n</g><rect x=\"213.2\" y=\"103.1\" width=\"15.6\" height=\"41.3\" rx=\"3\" fill=\"#172027\"/><g transform=\"translate(67.6 240.91666666666666)\">\n<rect width=\"124.8\" height=\"108.16666666666667\" rx=\"10\" fill=\"#172027\" stroke=\"#0C1114\" stroke-width=\"6\"/>\n<rect x=\"10.0\" y=\"8.7\" width=\"42.4\" height=\"58.4\" rx=\"5\" fill=\"#343D41\" stroke=\"#DCE3E2\" stroke-width=\"4\"/>\n<rect x=\"16.2\" y=\"16.2\" width=\"30.0\" height=\"19.5\" rx=\"3\" fill=\"#B9CFB4\"/>\n<g fill=\"#DCE3E2\"><circle cx=\"21.2\" cy=\"44.3\" r=\"3\"/><circle cx=\"28.7\" cy=\"44.3\" r=\"3\"/><circle cx=\"36.2\" cy=\"44.3\" r=\"3\"/><circle cx=\"43.7\" cy=\"44.3\" r=\"3\"/></g><rect x=\"62.4\" y=\"13.0\" width=\"49.9\" height=\"51.9\" rx=\"7\" fill=\"#3B4445\" stroke=\"#9FAAAC\" stroke-width=\"4\"/>\n<rect x=\"69.9\" y=\"23.8\" width=\"17.5\" height=\"17.3\" rx=\"3\" fill=\"#E43D3D\"/><path d=\"M 78.6 27.0 v 10.8\" stroke=\"white\" stroke-width=\"5\"/>\n<rect x=\"92.4\" y=\"23.8\" width=\"15.0\" height=\"17.3\" rx=\"3\" fill=\"#1677C8\"/><path d=\"M 99.8 27.0 v 10.8\" stroke=\"white\" stroke-width=\"5\"/>\n<path d=\"M 62.4 13.0 h 42.4 q 10.0 0 10.0 8.7\" fill=\"none\" stroke=\"#F7FAF9\" stroke-width=\"4\" opacity=\".55\"/>\n<rect x=\"10.0\" y=\"75.7\" width=\"104.8\" height=\"19.5\" rx=\"4\" fill=\"#9FAAAC\"/>\n<rect x=\"18.7\" y=\"81.1\" width=\"44.9\" height=\"5.4\" fill=\"#DCE3E2\"/><rect x=\"18.7\" y=\"88.7\" width=\"68.6\" height=\"2.7\" fill=\"#707C7F\"/>\n</g><rect x=\"213.2\" y=\"259.6\" width=\"15.6\" height=\"59.0\" rx=\"3\" fill=\"#172027\"/><rect x=\"213.2\" y=\"456.3\" width=\"15.6\" height=\"59.0\" rx=\"3\" fill=\"#172027\"/><circle cx=\"12\" cy=\"16\" r=\"4\" fill=\"#172027\" opacity=\".65\"/><circle cx=\"12\" cy=\"574\" r=\"4\" fill=\"#172027\" opacity=\".65\"/><circle cx=\"248\" cy=\"16\" r=\"4\" fill=\"#172027\" opacity=\".65\"/><circle cx=\"248\" cy=\"574\" r=\"4\" fill=\"#172027\" opacity=\".65\"/></g><g transform=\"translate(605 70)\"><rect width=\"260\" height=\"590\" rx=\"8\" fill=\"url(#steel)\" stroke=\"#172027\" stroke-width=\"8\"/>\n<rect x=\"0\" y=\"0\" width=\"260\" height=\"59.0\" rx=\"6\" fill=\"url(#dark)\"/><text x=\"20.8\" y=\"41.300000000000004\" font-family=\"Arial,sans-serif\" font-size=\"20\" font-weight=\"800\" fill=\"#F7FAF9\">LVA</text><path d=\"M 0 196.7 H 260\" stroke=\"#172027\" stroke-width=\"7\"/><path d=\"M 0 393.3 H 260\" stroke=\"#172027\" stroke-width=\"7\"/><g transform=\"translate(67.6 89.975)\">\n<rect width=\"124.8\" height=\"75.71666666666667\" rx=\"10\" fill=\"#172027\" stroke=\"#0C1114\" stroke-width=\"6\"/>\n<rect x=\"10.0\" y=\"6.1\" width=\"42.4\" height=\"40.9\" rx=\"5\" fill=\"#343D41\" stroke=\"#DCE3E2\" stroke-width=\"4\"/>\n<rect x=\"16.2\" y=\"11.4\" width=\"30.0\" height=\"13.6\" rx=\"3\" fill=\"#B9CFB4\"/>\n<g fill=\"#DCE3E2\"><circle cx=\"21.2\" cy=\"31.0\" r=\"3\"/><circle cx=\"28.7\" cy=\"31.0\" r=\"3\"/><circle cx=\"36.2\" cy=\"31.0\" r=\"3\"/><circle cx=\"43.7\" cy=\"31.0\" r=\"3\"/></g><rect x=\"62.4\" y=\"9.1\" width=\"49.9\" height=\"36.3\" rx=\"7\" fill=\"#3B4445\" stroke=\"#9FAAAC\" stroke-width=\"4\"/>\n<rect x=\"69.9\" y=\"16.7\" width=\"17.5\" height=\"12.1\" rx=\"3\" fill=\"#E43D3D\"/><path d=\"M 78.6 18.9 v 7.6\" stroke=\"white\" stroke-width=\"5\"/>\n<rect x=\"92.4\" y=\"16.7\" width=\"15.0\" height=\"12.1\" rx=\"3\" fill=\"#47B95C\"/><path d=\"M 99.8 18.9 v 7.6\" stroke=\"white\" stroke-width=\"5\"/>\n<path d=\"M 62.4 9.1 h 42.4 q 10.0 0 10.0 6.1\" fill=\"none\" stroke=\"#F7FAF9\" stroke-width=\"4\" opacity=\".55\"/>\n<rect x=\"10.0\" y=\"53.0\" width=\"104.8\" height=\"13.6\" rx=\"4\" fill=\"#9FAAAC\"/>\n<rect x=\"18.7\" y=\"56.8\" width=\"44.9\" height=\"3.8\" fill=\"#DCE3E2\"/><rect x=\"18.7\" y=\"62.1\" width=\"68.6\" height=\"1.9\" fill=\"#707C7F\"/>\n</g><rect x=\"213.2\" y=\"103.1\" width=\"15.6\" height=\"41.3\" rx=\"3\" fill=\"#172027\"/><rect x=\"213.2\" y=\"259.6\" width=\"15.6\" height=\"59.0\" rx=\"3\" fill=\"#172027\"/><g transform=\"translate(67.6 437.5833333333333)\">\n<rect width=\"124.8\" height=\"108.16666666666667\" rx=\"10\" fill=\"#172027\" stroke=\"#0C1114\" stroke-width=\"6\"/>\n<rect x=\"10.0\" y=\"8.7\" width=\"42.4\" height=\"58.4\" rx=\"5\" fill=\"#343D41\" stroke=\"#DCE3E2\" stroke-width=\"4\"/>\n<rect x=\"16.2\" y=\"16.2\" width=\"30.0\" height=\"19.5\" rx=\"3\" fill=\"#B9CFB4\"/>\n<g fill=\"#DCE3E2\"><circle cx=\"21.2\" cy=\"44.3\" r=\"3\"/><circle cx=\"28.7\" cy=\"44.3\" r=\"3\"/><circle cx=\"36.2\" cy=\"44.3\" r=\"3\"/><circle cx=\"43.7\" cy=\"44.3\" r=\"3\"/></g><rect x=\"62.4\" y=\"13.0\" width=\"49.9\" height=\"51.9\" rx=\"7\" fill=\"#3B4445\" stroke=\"#9FAAAC\" stroke-width=\"4\"/>\n<rect x=\"69.9\" y=\"23.8\" width=\"17.5\" height=\"17.3\" rx=\"3\" fill=\"#E43D3D\"/><path d=\"M 78.6 27.0 v 10.8\" stroke=\"white\" stroke-width=\"5\"/>\n<rect x=\"92.4\" y=\"23.8\" width=\"15.0\" height=\"17.3\" rx=\"3\" fill=\"#47B95C\"/><path d=\"M 99.8 27.0 v 10.8\" stroke=\"white\" stroke-width=\"5\"/>\n<path d=\"M 62.4 13.0 h 42.4 q 10.0 0 10.0 8.7\" fill=\"none\" stroke=\"#F7FAF9\" stroke-width=\"4\" opacity=\".55\"/>\n<rect x=\"10.0\" y=\"75.7\" width=\"104.8\" height=\"19.5\" rx=\"4\" fill=\"#9FAAAC\"/>\n<rect x=\"18.7\" y=\"81.1\" width=\"44.9\" height=\"5.4\" fill=\"#DCE3E2\"/><rect x=\"18.7\" y=\"88.7\" width=\"68.6\" height=\"2.7\" fill=\"#707C7F\"/>\n</g><rect x=\"213.2\" y=\"456.3\" width=\"15.6\" height=\"59.0\" rx=\"3\" fill=\"#172027\"/><circle cx=\"12\" cy=\"16\" r=\"4\" fill=\"#172027\" opacity=\".65\"/><circle cx=\"12\" cy=\"574\" r=\"4\" fill=\"#172027\" opacity=\".65\"/><circle cx=\"248\" cy=\"16\" r=\"4\" fill=\"#172027\" opacity=\".65\"/><circle cx=\"248\" cy=\"574\" r=\"4\" fill=\"#172027\" opacity=\".65\"/></g><g transform=\"translate(865 70)\"><rect width=\"260\" height=\"590\" rx=\"8\" fill=\"url(#steel)\" stroke=\"#172027\" stroke-width=\"8\"/>\n<rect x=\"0\" y=\"0\" width=\"260\" height=\"59.0\" rx=\"6\" fill=\"url(#dark)\"/><text x=\"20.8\" y=\"41.300000000000004\" font-family=\"Arial,sans-serif\" font-size=\"20\" font-weight=\"800\" fill=\"#F7FAF9\">LVA</text><path d=\"M 0 196.7 H 260\" stroke=\"#172027\" stroke-width=\"7\"/><path d=\"M 0 393.3 H 260\" stroke=\"#172027\" stroke-width=\"7\"/><rect x=\"213.2\" y=\"103.1\" width=\"15.6\" height=\"41.3\" rx=\"3\" fill=\"#172027\"/><g transform=\"translate(67.6 240.91666666666666)\">\n<rect width=\"124.8\" height=\"108.16666666666667\" rx=\"10\" fill=\"#172027\" stroke=\"#0C1114\" stroke-width=\"6\"/>\n<rect x=\"10.0\" y=\"8.7\" width=\"42.4\" height=\"58.4\" rx=\"5\" fill=\"#343D41\" stroke=\"#DCE3E2\" stroke-width=\"4\"/>\n<rect x=\"16.2\" y=\"16.2\" width=\"30.0\" height=\"19.5\" rx=\"3\" fill=\"#B9CFB4\"/>\n<g fill=\"#DCE3E2\"><circle cx=\"21.2\" cy=\"44.3\" r=\"3\"/><circle cx=\"28.7\" cy=\"44.3\" r=\"3\"/><circle cx=\"36.2\" cy=\"44.3\" r=\"3\"/><circle cx=\"43.7\" cy=\"44.3\" r=\"3\"/></g><rect x=\"62.4\" y=\"13.0\" width=\"49.9\" height=\"51.9\" rx=\"7\" fill=\"#3B4445\" stroke=\"#9FAAAC\" stroke-width=\"4\"/>\n<rect x=\"69.9\" y=\"23.8\" width=\"17.5\" height=\"17.3\" rx=\"3\" fill=\"#E43D3D\"/><path d=\"M 78.6 27.0 v 10.8\" stroke=\"white\" stroke-width=\"5\"/>\n<rect x=\"92.4\" y=\"23.8\" width=\"15.0\" height=\"17.3\" rx=\"3\" fill=\"#1677C8\"/><path d=\"M 99.8 27.0 v 10.8\" stroke=\"white\" stroke-width=\"5\"/>\n<path d=\"M 62.4 13.0 h 42.4 q 10.0 0 10.0 8.7\" fill=\"none\" stroke=\"#F7FAF9\" stroke-width=\"4\" opacity=\".55\"/>\n<rect x=\"10.0\" y=\"75.7\" width=\"104.8\" height=\"19.5\" rx=\"4\" fill=\"#9FAAAC\"/>\n<rect x=\"18.7\" y=\"81.1\" width=\"44.9\" height=\"5.4\" fill=\"#DCE3E2\"/><rect x=\"18.7\" y=\"88.7\" width=\"68.6\" height=\"2.7\" fill=\"#707C7F\"/>\n</g><rect x=\"213.2\" y=\"259.6\" width=\"15.6\" height=\"59.0\" rx=\"3\" fill=\"#172027\"/><g transform=\"translate(67.6 437.5833333333333)\">\n<rect width=\"124.8\" height=\"108.16666666666667\" rx=\"10\" fill=\"#172027\" stroke=\"#0C1114\" stroke-width=\"6\"/>\n<rect x=\"10.0\" y=\"8.7\" width=\"42.4\" height=\"58.4\" rx=\"5\" fill=\"#343D41\" stroke=\"#DCE3E2\" stroke-width=\"4\"/>\n<rect x=\"16.2\" y=\"16.2\" width=\"30.0\" height=\"19.5\" rx=\"3\" fill=\"#B9CFB4\"/>\n<g fill=\"#DCE3E2\"><circle cx=\"21.2\" cy=\"44.3\" r=\"3\"/><circle cx=\"28.7\" cy=\"44.3\" r=\"3\"/><circle cx=\"36.2\" cy=\"44.3\" r=\"3\"/><circle cx=\"43.7\" cy=\"44.3\" r=\"3\"/></g><rect x=\"62.4\" y=\"13.0\" width=\"49.9\" height=\"51.9\" rx=\"7\" fill=\"#3B4445\" stroke=\"#9FAAAC\" stroke-width=\"4\"/>\n<rect x=\"69.9\" y=\"23.8\" width=\"17.5\" height=\"17.3\" rx=\"3\" fill=\"#E43D3D\"/><path d=\"M 78.6 27.0 v 10.8\" stroke=\"white\" stroke-width=\"5\"/>\n<rect x=\"92.4\" y=\"23.8\" width=\"15.0\" height=\"17.3\" rx=\"3\" fill=\"#47B95C\"/><path d=\"M 99.8 27.0 v 10.8\" stroke=\"white\" stroke-width=\"5\"/>\n<path d=\"M 62.4 13.0 h 42.4 q 10.0 0 10.0 8.7\" fill=\"none\" stroke=\"#F7FAF9\" stroke-width=\"4\" opacity=\".55\"/>\n<rect x=\"10.0\" y=\"75.7\" width=\"104.8\" height=\"19.5\" rx=\"4\" fill=\"#9FAAAC\"/>\n<rect x=\"18.7\" y=\"81.1\" width=\"44.9\" height=\"5.4\" fill=\"#DCE3E2\"/><rect x=\"18.7\" y=\"88.7\" width=\"68.6\" height=\"2.7\" fill=\"#707C7F\"/>\n</g><rect x=\"213.2\" y=\"456.3\" width=\"15.6\" height=\"59.0\" rx=\"3\" fill=\"#172027\"/><circle cx=\"12\" cy=\"16\" r=\"4\" fill=\"#172027\" opacity=\".65\"/><circle cx=\"12\" cy=\"574\" r=\"4\" fill=\"#172027\" opacity=\".65\"/><circle cx=\"248\" cy=\"16\" r=\"4\" fill=\"#172027\" opacity=\".65\"/><circle cx=\"248\" cy=\"574\" r=\"4\" fill=\"#172027\" opacity=\".65\"/></g></svg>","arc_resistant_lineup_perspective":"<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"1200\" height=\"760\" viewBox=\"0 0 1200 760\" role=\"img\" aria-label=\"Cartoon arc-resistant switchgear lineup, perspective view\">\n<defs>\n <linearGradient id=\"steel\" x1=\"0\" y1=\"0\" x2=\"1\" y2=\"1\"><stop offset=\"0\" stop-color=\"#DCE3E2\"/><stop offset=\"1\" stop-color=\"#9FAAAC\"/></linearGradient>\n <linearGradient id=\"dark\" x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\"><stop offset=\"0\" stop-color=\"#343D41\"/><stop offset=\"1\" stop-color=\"#172027\"/></linearGradient>\n <filter id=\"shadow\" x=\"-30%\" y=\"-30%\" width=\"160%\" height=\"170%\"><feDropShadow dx=\"0\" dy=\"12\" stdDeviation=\"10\" flood-color=\"#000\" flood-opacity=\".25\"/></filter>\n</defs><ellipse cx=\"620\" cy=\"706\" rx=\"500\" ry=\"28\" fill=\"#000\" opacity=\".2\"/><path d=\"M180 165 L320 90 L320 650 L180 700 Z\" fill=\"#707C7F\" stroke=\"#172027\" stroke-width=\"9\"/><path d=\"M180 165 L320 90 H1040 L905 165 Z\" fill=\"#DCE3E2\" stroke=\"#172027\" stroke-width=\"9\"/><path d=\"M320 90 L345 35 H520 L500 90 Z\" fill=\"#9FAAAC\" stroke=\"#172027\" stroke-width=\"7\"/><rect x=\"375\" y=\"55\" width=\"13\" height=\"18\" rx=\"3\" fill=\"#343D41\"/><rect x=\"400\" y=\"55\" width=\"13\" height=\"18\" rx=\"3\" fill=\"#343D41\"/><rect x=\"425\" y=\"55\" width=\"13\" height=\"18\" rx=\"3\" fill=\"#343D41\"/><rect x=\"450\" y=\"55\" width=\"13\" height=\"18\" rx=\"3\" fill=\"#343D41\"/><rect x=\"475\" y=\"55\" width=\"13\" height=\"18\" rx=\"3\" fill=\"#343D41\"/><path d=\"M500 90 L525 35 H700 L680 90 Z\" fill=\"#9FAAAC\" stroke=\"#172027\" stroke-width=\"7\"/><rect x=\"555\" y=\"55\" width=\"13\" height=\"18\" rx=\"3\" fill=\"#343D41\"/><rect x=\"580\" y=\"55\" width=\"13\" height=\"18\" rx=\"3\" fill=\"#343D41\"/><rect x=\"605\" y=\"55\" width=\"13\" height=\"18\" rx=\"3\" fill=\"#343D41\"/><rect x=\"630\" y=\"55\" width=\"13\" height=\"18\" rx=\"3\" fill=\"#343D41\"/><rect x=\"655\" y=\"55\" width=\"13\" height=\"18\" rx=\"3\" fill=\"#343D41\"/><path d=\"M680 90 L705 35 H880 L860 90 Z\" fill=\"#9FAAAC\" stroke=\"#172027\" stroke-width=\"7\"/><rect x=\"735\" y=\"55\" width=\"13\" height=\"18\" rx=\"3\" fill=\"#343D41\"/><rect x=\"760\" y=\"55\" width=\"13\" height=\"18\" rx=\"3\" fill=\"#343D41\"/><rect x=\"785\" y=\"55\" width=\"13\" height=\"18\" rx=\"3\" fill=\"#343D41\"/><rect x=\"810\" y=\"55\" width=\"13\" height=\"18\" rx=\"3\" fill=\"#343D41\"/><rect x=\"835\" y=\"55\" width=\"13\" height=\"18\" rx=\"3\" fill=\"#343D41\"/><path d=\"M860 90 L885 35 H1060 L1040 90 Z\" fill=\"#9FAAAC\" stroke=\"#172027\" stroke-width=\"7\"/><rect x=\"915\" y=\"55\" width=\"13\" height=\"18\" rx=\"3\" fill=\"#343D41\"/><rect x=\"940\" y=\"55\" width=\"13\" height=\"18\" rx=\"3\" fill=\"#343D41\"/><rect x=\"965\" y=\"55\" width=\"13\" height=\"18\" rx=\"3\" fill=\"#343D41\"/><rect x=\"990\" y=\"55\" width=\"13\" height=\"18\" rx=\"3\" fill=\"#343D41\"/><rect x=\"1015\" y=\"55\" width=\"13\" height=\"18\" rx=\"3\" fill=\"#343D41\"/><g transform=\"translate(320 165)\"><rect width=\"180\" height=\"485\" rx=\"8\" fill=\"url(#steel)\" stroke=\"#172027\" stroke-width=\"8\"/>\n<rect x=\"0\" y=\"0\" width=\"180\" height=\"48.5\" rx=\"6\" fill=\"url(#dark)\"/><text x=\"14.4\" y=\"33.95\" font-family=\"Arial,sans-serif\" font-size=\"16\" font-weight=\"800\" fill=\"#F7FAF9\"></text><path d=\"M 0 242.5 H 180\" stroke=\"#172027\" stroke-width=\"7\"/><g transform=\"translate(46.800000000000004 92.15)\">\n<rect width=\"86.39999999999999\" height=\"106.7\" rx=\"10\" fill=\"#172027\" stroke=\"#0C1114\" stroke-width=\"6\"/>\n<rect x=\"6.9\" y=\"8.5\" width=\"29.4\" height=\"57.6\" rx=\"5\" fill=\"#343D41\" stroke=\"#DCE3E2\" stroke-width=\"4\"/>\n<rect x=\"11.2\" y=\"16.0\" width=\"20.7\" height=\"19.2\" rx=\"3\" fill=\"#B9CFB4\"/>\n<g fill=\"#DCE3E2\"><circle cx=\"14.7\" cy=\"43.7\" r=\"3\"/><circle cx=\"19.9\" cy=\"43.7\" r=\"3\"/><circle cx=\"25.1\" cy=\"43.7\" r=\"3\"/><circle cx=\"30.2\" cy=\"43.7\" r=\"3\"/></g><rect x=\"43.2\" y=\"12.8\" width=\"34.6\" height=\"51.2\" rx=\"7\" fill=\"#3B4445\" stroke=\"#9FAAAC\" stroke-width=\"4\"/>\n<rect x=\"48.4\" y=\"23.5\" width=\"12.1\" height=\"17.1\" rx=\"3\" fill=\"#E43D3D\"/><path d=\"M 54.4 26.7 v 10.7\" stroke=\"white\" stroke-width=\"5\"/>\n<rect x=\"63.9\" y=\"23.5\" width=\"10.4\" height=\"17.1\" rx=\"3\" fill=\"#47B95C\"/><path d=\"M 69.1 26.7 v 10.7\" stroke=\"white\" stroke-width=\"5\"/>\n<path d=\"M 43.2 12.8 h 29.4 q 6.9 0 6.9 8.5\" fill=\"none\" stroke=\"#F7FAF9\" stroke-width=\"4\" opacity=\".55\"/>\n<rect x=\"6.9\" y=\"74.7\" width=\"72.6\" height=\"19.2\" rx=\"4\" fill=\"#9FAAAC\"/>\n<rect x=\"13.0\" y=\"80.0\" width=\"31.1\" height=\"5.3\" fill=\"#DCE3E2\"/><rect x=\"13.0\" y=\"87.5\" width=\"47.5\" height=\"2.7\" fill=\"#707C7F\"/>\n</g><rect x=\"147.6\" y=\"110.6\" width=\"10.8\" height=\"58.2\" rx=\"3\" fill=\"#172027\"/><g transform=\"translate(46.800000000000004 297.0625)\">\n<rect width=\"86.39999999999999\" height=\"133.375\" rx=\"10\" fill=\"#172027\" stroke=\"#0C1114\" stroke-width=\"6\"/>\n<rect x=\"6.9\" y=\"10.7\" width=\"29.4\" height=\"72.0\" rx=\"5\" fill=\"#343D41\" stroke=\"#DCE3E2\" stroke-width=\"4\"/>\n<rect x=\"11.2\" y=\"20.0\" width=\"20.7\" height=\"24.0\" rx=\"3\" fill=\"#B9CFB4\"/>\n<g fill=\"#DCE3E2\"><circle cx=\"14.7\" cy=\"54.7\" r=\"3\"/><circle cx=\"19.9\" cy=\"54.7\" r=\"3\"/><circle cx=\"25.1\" cy=\"54.7\" r=\"3\"/><circle cx=\"30.2\" cy=\"54.7\" r=\"3\"/></g><rect x=\"43.2\" y=\"16.0\" width=\"34.6\" height=\"64.0\" rx=\"7\" fill=\"#3B4445\" stroke=\"#9FAAAC\" stroke-width=\"4\"/>\n<rect x=\"48.4\" y=\"29.3\" width=\"12.1\" height=\"21.3\" rx=\"3\" fill=\"#E43D3D\"/><path d=\"M 54.4 33.3 v 13.3\" stroke=\"white\" stroke-width=\"5\"/>\n<rect x=\"63.9\" y=\"29.3\" width=\"10.4\" height=\"21.3\" rx=\"3\" fill=\"#1677C8\"/><path d=\"M 69.1 33.3 v 13.3\" stroke=\"white\" stroke-width=\"5\"/>\n<path d=\"M 43.2 16.0 h 29.4 q 6.9 0 6.9 10.7\" fill=\"none\" stroke=\"#F7FAF9\" stroke-width=\"4\" opacity=\".55\"/>\n<rect x=\"6.9\" y=\"93.4\" width=\"72.6\" height=\"24.0\" rx=\"4\" fill=\"#9FAAAC\"/>\n<rect x=\"13.0\" y=\"100.0\" width=\"31.1\" height=\"6.7\" fill=\"#DCE3E2\"/><rect x=\"13.0\" y=\"109.4\" width=\"47.5\" height=\"3.3\" fill=\"#707C7F\"/>\n</g><rect x=\"147.6\" y=\"320.1\" width=\"10.8\" height=\"72.8\" rx=\"3\" fill=\"#172027\"/><circle cx=\"12\" cy=\"16\" r=\"4\" fill=\"#172027\" opacity=\".65\"/><circle cx=\"12\" cy=\"469\" r=\"4\" fill=\"#172027\" opacity=\".65\"/><circle cx=\"168\" cy=\"16\" r=\"4\" fill=\"#172027\" opacity=\".65\"/><circle cx=\"168\" cy=\"469\" r=\"4\" fill=\"#172027\" opacity=\".65\"/></g><g transform=\"translate(500 165)\"><rect width=\"180\" height=\"485\" rx=\"8\" fill=\"url(#steel)\" stroke=\"#172027\" stroke-width=\"8\"/>\n<rect x=\"0\" y=\"0\" width=\"180\" height=\"48.5\" rx=\"6\" fill=\"url(#dark)\"/><text x=\"14.4\" y=\"33.95\" font-family=\"Arial,sans-serif\" font-size=\"16\" font-weight=\"800\" fill=\"#F7FAF9\"></text><path d=\"M 0 242.5 H 180\" stroke=\"#172027\" stroke-width=\"7\"/><g transform=\"translate(46.800000000000004 92.15)\">\n<rect width=\"86.39999999999999\" height=\"106.7\" rx=\"10\" fill=\"#172027\" stroke=\"#0C1114\" stroke-width=\"6\"/>\n<rect x=\"6.9\" y=\"8.5\" width=\"29.4\" height=\"57.6\" rx=\"5\" fill=\"#343D41\" stroke=\"#DCE3E2\" stroke-width=\"4\"/>\n<rect x=\"11.2\" y=\"16.0\" width=\"20.7\" height=\"19.2\" rx=\"3\" fill=\"#B9CFB4\"/>\n<g fill=\"#DCE3E2\"><circle cx=\"14.7\" cy=\"43.7\" r=\"3\"/><circle cx=\"19.9\" cy=\"43.7\" r=\"3\"/><circle cx=\"25.1\" cy=\"43.7\" r=\"3\"/><circle cx=\"30.2\" cy=\"43.7\" r=\"3\"/></g><rect x=\"43.2\" y=\"12.8\" width=\"34.6\" height=\"51.2\" rx=\"7\" fill=\"#3B4445\" stroke=\"#9FAAAC\" stroke-width=\"4\"/>\n<rect x=\"48.4\" y=\"23.5\" width=\"12.1\" height=\"17.1\" rx=\"3\" fill=\"#E43D3D\"/><path d=\"M 54.4 26.7 v 10.7\" stroke=\"white\" stroke-width=\"5\"/>\n<rect x=\"63.9\" y=\"23.5\" width=\"10.4\" height=\"17.1\" rx=\"3\" fill=\"#47B95C\"/><path d=\"M 69.1 26.7 v 10.7\" stroke=\"white\" stroke-width=\"5\"/>\n<path d=\"M 43.2 12.8 h 29.4 q 6.9 0 6.9 8.5\" fill=\"none\" stroke=\"#F7FAF9\" stroke-width=\"4\" opacity=\".55\"/>\n<rect x=\"6.9\" y=\"74.7\" width=\"72.6\" height=\"19.2\" rx=\"4\" fill=\"#9FAAAC\"/>\n<rect x=\"13.0\" y=\"80.0\" width=\"31.1\" height=\"5.3\" fill=\"#DCE3E2\"/><rect x=\"13.0\" y=\"87.5\" width=\"47.5\" height=\"2.7\" fill=\"#707C7F\"/>\n</g><rect x=\"147.6\" y=\"110.6\" width=\"10.8\" height=\"58.2\" rx=\"3\" fill=\"#172027\"/><g transform=\"translate(46.800000000000004 297.0625)\">\n<rect width=\"86.39999999999999\" height=\"133.375\" rx=\"10\" fill=\"#172027\" stroke=\"#0C1114\" stroke-width=\"6\"/>\n<rect x=\"6.9\" y=\"10.7\" width=\"29.4\" height=\"72.0\" rx=\"5\" fill=\"#343D41\" stroke=\"#DCE3E2\" stroke-width=\"4\"/>\n<rect x=\"11.2\" y=\"20.0\" width=\"20.7\" height=\"24.0\" rx=\"3\" fill=\"#B9CFB4\"/>\n<g fill=\"#DCE3E2\"><circle cx=\"14.7\" cy=\"54.7\" r=\"3\"/><circle cx=\"19.9\" cy=\"54.7\" r=\"3\"/><circle cx=\"25.1\" cy=\"54.7\" r=\"3\"/><circle cx=\"30.2\" cy=\"54.7\" r=\"3\"/></g><rect x=\"43.2\" y=\"16.0\" width=\"34.6\" height=\"64.0\" rx=\"7\" fill=\"#3B4445\" stroke=\"#9FAAAC\" stroke-width=\"4\"/>\n<rect x=\"48.4\" y=\"29.3\" width=\"12.1\" height=\"21.3\" rx=\"3\" fill=\"#E43D3D\"/><path d=\"M 54.4 33.3 v 13.3\" stroke=\"white\" stroke-width=\"5\"/>\n<rect x=\"63.9\" y=\"29.3\" width=\"10.4\" height=\"21.3\" rx=\"3\" fill=\"#1677C8\"/><path d=\"M 69.1 33.3 v 13.3\" stroke=\"white\" stroke-width=\"5\"/>\n<path d=\"M 43.2 16.0 h 29.4 q 6.9 0 6.9 10.7\" fill=\"none\" stroke=\"#F7FAF9\" stroke-width=\"4\" opacity=\".55\"/>\n<rect x=\"6.9\" y=\"93.4\" width=\"72.6\" height=\"24.0\" rx=\"4\" fill=\"#9FAAAC\"/>\n<rect x=\"13.0\" y=\"100.0\" width=\"31.1\" height=\"6.7\" fill=\"#DCE3E2\"/><rect x=\"13.0\" y=\"109.4\" width=\"47.5\" height=\"3.3\" fill=\"#707C7F\"/>\n</g><rect x=\"147.6\" y=\"320.1\" width=\"10.8\" height=\"72.8\" rx=\"3\" fill=\"#172027\"/><circle cx=\"12\" cy=\"16\" r=\"4\" fill=\"#172027\" opacity=\".65\"/><circle cx=\"12\" cy=\"469\" r=\"4\" fill=\"#172027\" opacity=\".65\"/><circle cx=\"168\" cy=\"16\" r=\"4\" fill=\"#172027\" opacity=\".65\"/><circle cx=\"168\" cy=\"469\" r=\"4\" fill=\"#172027\" opacity=\".65\"/></g><g transform=\"translate(680 165)\"><rect width=\"180\" height=\"485\" rx=\"8\" fill=\"url(#steel)\" stroke=\"#172027\" stroke-width=\"8\"/>\n<rect x=\"0\" y=\"0\" width=\"180\" height=\"48.5\" rx=\"6\" fill=\"url(#dark)\"/><text x=\"14.4\" y=\"33.95\" font-family=\"Arial,sans-serif\" font-size=\"16\" font-weight=\"800\" fill=\"#F7FAF9\"></text><path d=\"M 0 242.5 H 180\" stroke=\"#172027\" stroke-width=\"7\"/><g transform=\"translate(46.800000000000004 92.15)\">\n<rect width=\"86.39999999999999\" height=\"106.7\" rx=\"10\" fill=\"#172027\" stroke=\"#0C1114\" stroke-width=\"6\"/>\n<rect x=\"6.9\" y=\"8.5\" width=\"29.4\" height=\"57.6\" rx=\"5\" fill=\"#343D41\" stroke=\"#DCE3E2\" stroke-width=\"4\"/>\n<rect x=\"11.2\" y=\"16.0\" width=\"20.7\" height=\"19.2\" rx=\"3\" fill=\"#B9CFB4\"/>\n<g fill=\"#DCE3E2\"><circle cx=\"14.7\" cy=\"43.7\" r=\"3\"/><circle cx=\"19.9\" cy=\"43.7\" r=\"3\"/><circle cx=\"25.1\" cy=\"43.7\" r=\"3\"/><circle cx=\"30.2\" cy=\"43.7\" r=\"3\"/></g><rect x=\"43.2\" y=\"12.8\" width=\"34.6\" height=\"51.2\" rx=\"7\" fill=\"#3B4445\" stroke=\"#9FAAAC\" stroke-width=\"4\"/>\n<rect x=\"48.4\" y=\"23.5\" width=\"12.1\" height=\"17.1\" rx=\"3\" fill=\"#E43D3D\"/><path d=\"M 54.4 26.7 v 10.7\" stroke=\"white\" stroke-width=\"5\"/>\n<rect x=\"63.9\" y=\"23.5\" width=\"10.4\" height=\"17.1\" rx=\"3\" fill=\"#47B95C\"/><path d=\"M 69.1 26.7 v 10.7\" stroke=\"white\" stroke-width=\"5\"/>\n<path d=\"M 43.2 12.8 h 29.4 q 6.9 0 6.9 8.5\" fill=\"none\" stroke=\"#F7FAF9\" stroke-width=\"4\" opacity=\".55\"/>\n<rect x=\"6.9\" y=\"74.7\" width=\"72.6\" height=\"19.2\" rx=\"4\" fill=\"#9FAAAC\"/>\n<rect x=\"13.0\" y=\"80.0\" width=\"31.1\" height=\"5.3\" fill=\"#DCE3E2\"/><rect x=\"13.0\" y=\"87.5\" width=\"47.5\" height=\"2.7\" fill=\"#707C7F\"/>\n</g><rect x=\"147.6\" y=\"110.6\" width=\"10.8\" height=\"58.2\" rx=\"3\" fill=\"#172027\"/><rect x=\"147.6\" y=\"320.1\" width=\"10.8\" height=\"72.8\" rx=\"3\" fill=\"#172027\"/><circle cx=\"12\" cy=\"16\" r=\"4\" fill=\"#172027\" opacity=\".65\"/><circle cx=\"12\" cy=\"469\" r=\"4\" fill=\"#172027\" opacity=\".65\"/><circle cx=\"168\" cy=\"16\" r=\"4\" fill=\"#172027\" opacity=\".65\"/><circle cx=\"168\" cy=\"469\" r=\"4\" fill=\"#172027\" opacity=\".65\"/></g><g transform=\"translate(860 165)\"><rect width=\"180\" height=\"485\" rx=\"8\" fill=\"url(#steel)\" stroke=\"#172027\" stroke-width=\"8\"/>\n<rect x=\"0\" y=\"0\" width=\"180\" height=\"48.5\" rx=\"6\" fill=\"url(#dark)\"/><text x=\"14.4\" y=\"33.95\" font-family=\"Arial,sans-serif\" font-size=\"16\" font-weight=\"800\" fill=\"#F7FAF9\"></text><path d=\"M 0 242.5 H 180\" stroke=\"#172027\" stroke-width=\"7\"/><rect x=\"147.6\" y=\"110.6\" width=\"10.8\" height=\"58.2\" rx=\"3\" fill=\"#172027\"/><g transform=\"translate(46.800000000000004 297.0625)\">\n<rect width=\"86.39999999999999\" height=\"133.375\" rx=\"10\" fill=\"#172027\" stroke=\"#0C1114\" stroke-width=\"6\"/>\n<rect x=\"6.9\" y=\"10.7\" width=\"29.4\" height=\"72.0\" rx=\"5\" fill=\"#343D41\" stroke=\"#DCE3E2\" stroke-width=\"4\"/>\n<rect x=\"11.2\" y=\"20.0\" width=\"20.7\" height=\"24.0\" rx=\"3\" fill=\"#B9CFB4\"/>\n<g fill=\"#DCE3E2\"><circle cx=\"14.7\" cy=\"54.7\" r=\"3\"/><circle cx=\"19.9\" cy=\"54.7\" r=\"3\"/><circle cx=\"25.1\" cy=\"54.7\" r=\"3\"/><circle cx=\"30.2\" cy=\"54.7\" r=\"3\"/></g><rect x=\"43.2\" y=\"16.0\" width=\"34.6\" height=\"64.0\" rx=\"7\" fill=\"#3B4445\" stroke=\"#9FAAAC\" stroke-width=\"4\"/>\n<rect x=\"48.4\" y=\"29.3\" width=\"12.1\" height=\"21.3\" rx=\"3\" fill=\"#E43D3D\"/><path d=\"M 54.4 33.3 v 13.3\" stroke=\"white\" stroke-width=\"5\"/>\n<rect x=\"63.9\" y=\"29.3\" width=\"10.4\" height=\"21.3\" rx=\"3\" fill=\"#1677C8\"/><path d=\"M 69.1 33.3 v 13.3\" stroke=\"white\" stroke-width=\"5\"/>\n<path d=\"M 43.2 16.0 h 29.4 q 6.9 0 6.9 10.7\" fill=\"none\" stroke=\"#F7FAF9\" stroke-width=\"4\" opacity=\".55\"/>\n<rect x=\"6.9\" y=\"93.4\" width=\"72.6\" height=\"24.0\" rx=\"4\" fill=\"#9FAAAC\"/>\n<rect x=\"13.0\" y=\"100.0\" width=\"31.1\" height=\"6.7\" fill=\"#DCE3E2\"/><rect x=\"13.0\" y=\"109.4\" width=\"47.5\" height=\"3.3\" fill=\"#707C7F\"/>\n</g><rect x=\"147.6\" y=\"320.1\" width=\"10.8\" height=\"72.8\" rx=\"3\" fill=\"#172027\"/><circle cx=\"12\" cy=\"16\" r=\"4\" fill=\"#172027\" opacity=\".65\"/><circle cx=\"12\" cy=\"469\" r=\"4\" fill=\"#172027\" opacity=\".65\"/><circle cx=\"168\" cy=\"16\" r=\"4\" fill=\"#172027\" opacity=\".65\"/><circle cx=\"168\" cy=\"469\" r=\"4\" fill=\"#172027\" opacity=\".65\"/></g></svg>","magnum_breaker":"<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"640\" height=\"640\" viewBox=\"0 0 640 640\" role=\"img\" aria-label=\"Cartoon Magnum-style low-voltage breaker\">\n<defs>\n <linearGradient id=\"steel\" x1=\"0\" y1=\"0\" x2=\"1\" y2=\"1\"><stop offset=\"0\" stop-color=\"#DCE3E2\"/><stop offset=\"1\" stop-color=\"#9FAAAC\"/></linearGradient>\n <linearGradient id=\"dark\" x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\"><stop offset=\"0\" stop-color=\"#343D41\"/><stop offset=\"1\" stop-color=\"#172027\"/></linearGradient>\n <filter id=\"shadow\" x=\"-30%\" y=\"-30%\" width=\"160%\" height=\"170%\"><feDropShadow dx=\"0\" dy=\"12\" stdDeviation=\"10\" flood-color=\"#000\" flood-opacity=\".25\"/></filter>\n</defs><ellipse cx=\"320\" cy=\"590\" rx=\"240\" ry=\"24\" fill=\"#000\" opacity=\".2\"/><rect x=\"70\" y=\"40\" width=\"500\" height=\"520\" rx=\"35\" fill=\"url(#steel)\" stroke=\"#172027\" stroke-width=\"12\" filter=\"url(#shadow)\"/><rect x=\"95\" y=\"70\" width=\"450\" height=\"55\" rx=\"10\" fill=\"url(#dark)\"/><circle cx=\"145\" cy=\"98\" r=\"9\" fill=\"#47B95C\" stroke=\"#172027\" stroke-width=\"5\"/><circle cx=\"142\" cy=\"95\" r=\"2\" fill=\"white\" opacity=\".8\"/><circle cx=\"205\" cy=\"98\" r=\"9\" fill=\"#ECECEC\" stroke=\"#172027\" stroke-width=\"5\"/><circle cx=\"202\" cy=\"95\" r=\"2\" fill=\"white\" opacity=\".8\"/><circle cx=\"265\" cy=\"98\" r=\"9\" fill=\"#E43D3D\" stroke=\"#172027\" stroke-width=\"5\"/><circle cx=\"262\" cy=\"95\" r=\"2\" fill=\"white\" opacity=\".8\"/><rect x=\"120\" y=\"160\" width=\"400\" height=\"335\" rx=\"22\" fill=\"#172027\" stroke=\"#DCE3E2\" stroke-width=\"8\"/><g transform=\"translate(145 185)\">\n<rect width=\"350\" height=\"280\" rx=\"10\" fill=\"#172027\" stroke=\"#0C1114\" stroke-width=\"6\"/>\n<rect x=\"28.0\" y=\"22.4\" width=\"119.0\" height=\"151.2\" rx=\"5\" fill=\"#343D41\" stroke=\"#DCE3E2\" stroke-width=\"4\"/>\n<rect x=\"45.5\" y=\"42.0\" width=\"84.0\" height=\"50.4\" rx=\"3\" fill=\"#B9CFB4\"/>\n<g fill=\"#DCE3E2\"><circle cx=\"59.5\" cy=\"114.8\" r=\"3\"/><circle cx=\"80.5\" cy=\"114.8\" r=\"3\"/><circle cx=\"101.5\" cy=\"114.8\" r=\"3\"/><circle cx=\"122.5\" cy=\"114.8\" r=\"3\"/></g><rect x=\"175.0\" y=\"33.6\" width=\"140.0\" height=\"134.4\" rx=\"7\" fill=\"#3B4445\" stroke=\"#9FAAAC\" stroke-width=\"4\"/>\n<rect x=\"196.0\" y=\"61.6\" width=\"49.0\" height=\"44.8\" rx=\"3\" fill=\"#E43D3D\"/><path d=\"M 220.5 70.0 v 28.0\" stroke=\"white\" stroke-width=\"5\"/>\n<rect x=\"259.0\" y=\"61.6\" width=\"42.0\" height=\"44.8\" rx=\"3\" fill=\"#47B95C\"/><path d=\"M 280.0 70.0 v 28.0\" stroke=\"white\" stroke-width=\"5\"/>\n<path d=\"M 175.0 33.6 h 119.0 q 28.0 0 28.0 22.4\" fill=\"none\" stroke=\"#F7FAF9\" stroke-width=\"4\" opacity=\".55\"/>\n<rect x=\"28.0\" y=\"196.0\" width=\"294.0\" height=\"50.4\" rx=\"4\" fill=\"#9FAAAC\"/>\n<rect x=\"52.5\" y=\"210.0\" width=\"126.0\" height=\"14.0\" fill=\"#DCE3E2\"/><rect x=\"52.5\" y=\"229.6\" width=\"192.5\" height=\"7.0\" fill=\"#707C7F\"/>\n</g><path d=\"M505 185 q35 0 35 35 v180 q0 35 -35 35\" fill=\"none\" stroke=\"#343D41\" stroke-width=\"28\" stroke-linecap=\"round\"/></svg>","control_station":"<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"640\" height=\"480\" viewBox=\"0 0 640 480\" role=\"img\" aria-label=\"Cartoon control station panel\">\n<defs>\n <linearGradient id=\"steel\" x1=\"0\" y1=\"0\" x2=\"1\" y2=\"1\"><stop offset=\"0\" stop-color=\"#DCE3E2\"/><stop offset=\"1\" stop-color=\"#9FAAAC\"/></linearGradient>\n <linearGradient id=\"dark\" x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\"><stop offset=\"0\" stop-color=\"#343D41\"/><stop offset=\"1\" stop-color=\"#172027\"/></linearGradient>\n <filter id=\"shadow\" x=\"-30%\" y=\"-30%\" width=\"160%\" height=\"170%\"><feDropShadow dx=\"0\" dy=\"12\" stdDeviation=\"10\" flood-color=\"#000\" flood-opacity=\".25\"/></filter>\n</defs><rect x=\"45\" y=\"45\" width=\"550\" height=\"390\" rx=\"28\" fill=\"url(#steel)\" stroke=\"#172027\" stroke-width=\"11\" filter=\"url(#shadow)\"/><rect x=\"45\" y=\"45\" width=\"550\" height=\"85\" rx=\"24\" fill=\"url(#dark)\"/><text x=\"80\" y=\"102\" fill=\"#F7FAF9\" font-family=\"Arial\" font-weight=\"800\" font-size=\"34\">LVA CONTROL</text><rect x=\"90\" y=\"165\" width=\"210\" height=\"170\" rx=\"12\" fill=\"#172027\"/><rect x=\"120\" y=\"195\" width=\"150\" height=\"85\" rx=\"6\" fill=\"#9DE3F2\"/><path d=\"M135 250 l30 -20 35 10 45 -35\" fill=\"none\" stroke=\"#1677C8\" stroke-width=\"8\"/><circle cx=\"390\" cy=\"195\" r=\"9\" fill=\"#47B95C\" stroke=\"#172027\" stroke-width=\"5\"/><circle cx=\"387\" cy=\"192\" r=\"2\" fill=\"white\" opacity=\".8\"/><circle cx=\"455\" cy=\"195\" r=\"9\" fill=\"#E43D3D\" stroke=\"#172027\" stroke-width=\"5\"/><circle cx=\"452\" cy=\"192\" r=\"2\" fill=\"white\" opacity=\".8\"/><circle cx=\"520\" cy=\"195\" r=\"9\" fill=\"#F2C14E\" stroke=\"#172027\" stroke-width=\"5\"/><circle cx=\"517\" cy=\"192\" r=\"2\" fill=\"white\" opacity=\".8\"/><circle cx=\"420\" cy=\"300\" r=\"50\" fill=\"#343D41\" stroke=\"#172027\" stroke-width=\"10\"/><path d=\"M420 300 L452 270\" stroke=\"#F7FAF9\" stroke-width=\"14\" stroke-linecap=\"round\"/><rect x=\"350\" y=\"370\" width=\"190\" height=\"28\" rx=\"8\" fill=\"#1677C8\"/></svg>","switchboard_obstacle":"<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"640\" height=\"760\" viewBox=\"0 0 640 760\" role=\"img\" aria-label=\"Cartoon switchboard obstacle\">\n<defs>\n <linearGradient id=\"steel\" x1=\"0\" y1=\"0\" x2=\"1\" y2=\"1\"><stop offset=\"0\" stop-color=\"#DCE3E2\"/><stop offset=\"1\" stop-color=\"#9FAAAC\"/></linearGradient>\n <linearGradient id=\"dark\" x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\"><stop offset=\"0\" stop-color=\"#343D41\"/><stop offset=\"1\" stop-color=\"#172027\"/></linearGradient>\n <filter id=\"shadow\" x=\"-30%\" y=\"-30%\" width=\"160%\" height=\"170%\"><feDropShadow dx=\"0\" dy=\"12\" stdDeviation=\"10\" flood-color=\"#000\" flood-opacity=\".25\"/></filter>\n</defs><ellipse cx=\"320\" cy=\"710\" rx=\"260\" ry=\"26\" fill=\"#000\" opacity=\".2\"/><g transform=\"translate(95 60)\"><rect width=\"450\" height=\"630\" rx=\"8\" fill=\"url(#steel)\" stroke=\"#172027\" stroke-width=\"8\"/>\n<rect x=\"0\" y=\"0\" width=\"450\" height=\"63.0\" rx=\"6\" fill=\"url(#dark)\"/><text x=\"36.0\" y=\"44.1\" font-family=\"Arial,sans-serif\" font-size=\"36\" font-weight=\"800\" fill=\"#F7FAF9\">LVA // MAIN</text><path d=\"M 0 210.0 H 450\" stroke=\"#172027\" stroke-width=\"7\"/><path d=\"M 0 420.0 H 450\" stroke=\"#172027\" stroke-width=\"7\"/><path d=\"M 225.0 63.0 V 630\" stroke=\"#172027\" stroke-width=\"7\"/><g transform=\"translate(58.5 96.07499999999999)\">\n<rect width=\"108.0\" height=\"80.85000000000001\" rx=\"10\" fill=\"#172027\" stroke=\"#0C1114\" stroke-width=\"6\"/>\n<rect x=\"8.6\" y=\"6.5\" width=\"36.7\" height=\"43.7\" rx=\"5\" fill=\"#343D41\" stroke=\"#DCE3E2\" stroke-width=\"4\"/>\n<rect x=\"14.0\" y=\"12.1\" width=\"25.9\" height=\"14.6\" rx=\"3\" fill=\"#B9CFB4\"/>\n<g fill=\"#DCE3E2\"><circle cx=\"18.4\" cy=\"33.1\" r=\"3\"/><circle cx=\"24.8\" cy=\"33.1\" r=\"3\"/><circle cx=\"31.3\" cy=\"33.1\" r=\"3\"/><circle cx=\"37.8\" cy=\"33.1\" r=\"3\"/></g><rect x=\"54.0\" y=\"9.7\" width=\"43.2\" height=\"38.8\" rx=\"7\" fill=\"#3B4445\" stroke=\"#9FAAAC\" stroke-width=\"4\"/>\n<rect x=\"60.5\" y=\"17.8\" width=\"15.1\" height=\"12.9\" rx=\"3\" fill=\"#E43D3D\"/><path d=\"M 68.0 20.2 v 8.1\" stroke=\"white\" stroke-width=\"5\"/>\n<rect x=\"79.9\" y=\"17.8\" width=\"13.0\" height=\"12.9\" rx=\"3\" fill=\"#47B95C\"/><path d=\"M 86.4 20.2 v 8.1\" stroke=\"white\" stroke-width=\"5\"/>\n<path d=\"M 54.0 9.7 h 36.7 q 8.6 0 8.6 6.5\" fill=\"none\" stroke=\"#F7FAF9\" stroke-width=\"4\" opacity=\".55\"/>\n<rect x=\"8.6\" y=\"56.6\" width=\"90.7\" height=\"14.6\" rx=\"4\" fill=\"#9FAAAC\"/>\n<rect x=\"16.2\" y=\"60.6\" width=\"38.9\" height=\"4.0\" fill=\"#DCE3E2\"/><rect x=\"16.2\" y=\"66.3\" width=\"59.4\" height=\"2.0\" fill=\"#707C7F\"/>\n</g><rect x=\"184.5\" y=\"110.0\" width=\"13.5\" height=\"44.1\" rx=\"3\" fill=\"#172027\"/><rect x=\"409.5\" y=\"110.0\" width=\"13.5\" height=\"44.1\" rx=\"3\" fill=\"#172027\"/><rect x=\"184.5\" y=\"277.2\" width=\"13.5\" height=\"63.0\" rx=\"3\" fill=\"#172027\"/><g transform=\"translate(283.5 257.25)\">\n<rect width=\"108.0\" height=\"115.50000000000001\" rx=\"10\" fill=\"#172027\" stroke=\"#0C1114\" stroke-width=\"6\"/>\n<rect x=\"8.6\" y=\"9.2\" width=\"36.7\" height=\"62.4\" rx=\"5\" fill=\"#343D41\" stroke=\"#DCE3E2\" stroke-width=\"4\"/>\n<rect x=\"14.0\" y=\"17.3\" width=\"25.9\" height=\"20.8\" rx=\"3\" fill=\"#B9CFB4\"/>\n<g fill=\"#DCE3E2\"><circle cx=\"18.4\" cy=\"47.4\" r=\"3\"/><circle cx=\"24.8\" cy=\"47.4\" r=\"3\"/><circle cx=\"31.3\" cy=\"47.4\" r=\"3\"/><circle cx=\"37.8\" cy=\"47.4\" r=\"3\"/></g><rect x=\"54.0\" y=\"13.9\" width=\"43.2\" height=\"55.4\" rx=\"7\" fill=\"#3B4445\" stroke=\"#9FAAAC\" stroke-width=\"4\"/>\n<rect x=\"60.5\" y=\"25.4\" width=\"15.1\" height=\"18.5\" rx=\"3\" fill=\"#E43D3D\"/><path d=\"M 68.0 28.9 v 11.6\" stroke=\"white\" stroke-width=\"5\"/>\n<rect x=\"79.9\" y=\"25.4\" width=\"13.0\" height=\"18.5\" rx=\"3\" fill=\"#47B95C\"/><path d=\"M 86.4 28.9 v 11.6\" stroke=\"white\" stroke-width=\"5\"/>\n<path d=\"M 54.0 13.9 h 36.7 q 8.6 0 8.6 9.2\" fill=\"none\" stroke=\"#F7FAF9\" stroke-width=\"4\" opacity=\".55\"/>\n<rect x=\"8.6\" y=\"80.9\" width=\"90.7\" height=\"20.8\" rx=\"4\" fill=\"#9FAAAC\"/>\n<rect x=\"16.2\" y=\"86.6\" width=\"38.9\" height=\"5.8\" fill=\"#DCE3E2\"/><rect x=\"16.2\" y=\"94.7\" width=\"59.4\" height=\"2.9\" fill=\"#707C7F\"/>\n</g><rect x=\"409.5\" y=\"277.2\" width=\"13.5\" height=\"63.0\" rx=\"3\" fill=\"#172027\"/><g transform=\"translate(58.5 467.25)\">\n<rect width=\"108.0\" height=\"115.50000000000001\" rx=\"10\" fill=\"#172027\" stroke=\"#0C1114\" stroke-width=\"6\"/>\n<rect x=\"8.6\" y=\"9.2\" width=\"36.7\" height=\"62.4\" rx=\"5\" fill=\"#343D41\" stroke=\"#DCE3E2\" stroke-width=\"4\"/>\n<rect x=\"14.0\" y=\"17.3\" width=\"25.9\" height=\"20.8\" rx=\"3\" fill=\"#B9CFB4\"/>\n<g fill=\"#DCE3E2\"><circle cx=\"18.4\" cy=\"47.4\" r=\"3\"/><circle cx=\"24.8\" cy=\"47.4\" r=\"3\"/><circle cx=\"31.3\" cy=\"47.4\" r=\"3\"/><circle cx=\"37.8\" cy=\"47.4\" r=\"3\"/></g><rect x=\"54.0\" y=\"13.9\" width=\"43.2\" height=\"55.4\" rx=\"7\" fill=\"#3B4445\" stroke=\"#9FAAAC\" stroke-width=\"4\"/>\n<rect x=\"60.5\" y=\"25.4\" width=\"15.1\" height=\"18.5\" rx=\"3\" fill=\"#E43D3D\"/><path d=\"M 68.0 28.9 v 11.6\" stroke=\"white\" stroke-width=\"5\"/>\n<rect x=\"79.9\" y=\"25.4\" width=\"13.0\" height=\"18.5\" rx=\"3\" fill=\"#47B95C\"/><path d=\"M 86.4 28.9 v 11.6\" stroke=\"white\" stroke-width=\"5\"/>\n<path d=\"M 54.0 13.9 h 36.7 q 8.6 0 8.6 9.2\" fill=\"none\" stroke=\"#F7FAF9\" stroke-width=\"4\" opacity=\".55\"/>\n<rect x=\"8.6\" y=\"80.9\" width=\"90.7\" height=\"20.8\" rx=\"4\" fill=\"#9FAAAC\"/>\n<rect x=\"16.2\" y=\"86.6\" width=\"38.9\" height=\"5.8\" fill=\"#DCE3E2\"/><rect x=\"16.2\" y=\"94.7\" width=\"59.4\" height=\"2.9\" fill=\"#707C7F\"/>\n</g><rect x=\"184.5\" y=\"487.2\" width=\"13.5\" height=\"63.0\" rx=\"3\" fill=\"#172027\"/><g transform=\"translate(283.5 467.25)\">\n<rect width=\"108.0\" height=\"115.50000000000001\" rx=\"10\" fill=\"#172027\" stroke=\"#0C1114\" stroke-width=\"6\"/>\n<rect x=\"8.6\" y=\"9.2\" width=\"36.7\" height=\"62.4\" rx=\"5\" fill=\"#343D41\" stroke=\"#DCE3E2\" stroke-width=\"4\"/>\n<rect x=\"14.0\" y=\"17.3\" width=\"25.9\" height=\"20.8\" rx=\"3\" fill=\"#B9CFB4\"/>\n<g fill=\"#DCE3E2\"><circle cx=\"18.4\" cy=\"47.4\" r=\"3\"/><circle cx=\"24.8\" cy=\"47.4\" r=\"3\"/><circle cx=\"31.3\" cy=\"47.4\" r=\"3\"/><circle cx=\"37.8\" cy=\"47.4\" r=\"3\"/></g><rect x=\"54.0\" y=\"13.9\" width=\"43.2\" height=\"55.4\" rx=\"7\" fill=\"#3B4445\" stroke=\"#9FAAAC\" stroke-width=\"4\"/>\n<rect x=\"60.5\" y=\"25.4\" width=\"15.1\" height=\"18.5\" rx=\"3\" fill=\"#E43D3D\"/><path d=\"M 68.0 28.9 v 11.6\" stroke=\"white\" stroke-width=\"5\"/>\n<rect x=\"79.9\" y=\"25.4\" width=\"13.0\" height=\"18.5\" rx=\"3\" fill=\"#1677C8\"/><path d=\"M 86.4 28.9 v 11.6\" stroke=\"white\" stroke-width=\"5\"/>\n<path d=\"M 54.0 13.9 h 36.7 q 8.6 0 8.6 9.2\" fill=\"none\" stroke=\"#F7FAF9\" stroke-width=\"4\" opacity=\".55\"/>\n<rect x=\"8.6\" y=\"80.9\" width=\"90.7\" height=\"20.8\" rx=\"4\" fill=\"#9FAAAC\"/>\n<rect x=\"16.2\" y=\"86.6\" width=\"38.9\" height=\"5.8\" fill=\"#DCE3E2\"/><rect x=\"16.2\" y=\"94.7\" width=\"59.4\" height=\"2.9\" fill=\"#707C7F\"/>\n</g><rect x=\"409.5\" y=\"487.2\" width=\"13.5\" height=\"63.0\" rx=\"3\" fill=\"#172027\"/><circle cx=\"12\" cy=\"16\" r=\"4\" fill=\"#172027\" opacity=\".65\"/><circle cx=\"12\" cy=\"614\" r=\"4\" fill=\"#172027\" opacity=\".65\"/><circle cx=\"438\" cy=\"16\" r=\"4\" fill=\"#172027\" opacity=\".65\"/><circle cx=\"438\" cy=\"614\" r=\"4\" fill=\"#172027\" opacity=\".65\"/></g><path d=\"M70 660 H570 L535 715 H105 Z\" fill=\"#172027\"/></svg>","panel_bank_tile":"<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"1200\" height=\"600\" viewBox=\"0 0 1200 600\" role=\"img\" aria-label=\"Cartoon modular panel-bank environment tile\">\n<defs>\n <linearGradient id=\"steel\" x1=\"0\" y1=\"0\" x2=\"1\" y2=\"1\"><stop offset=\"0\" stop-color=\"#DCE3E2\"/><stop offset=\"1\" stop-color=\"#9FAAAC\"/></linearGradient>\n <linearGradient id=\"dark\" x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\"><stop offset=\"0\" stop-color=\"#343D41\"/><stop offset=\"1\" stop-color=\"#172027\"/></linearGradient>\n <filter id=\"shadow\" x=\"-30%\" y=\"-30%\" width=\"160%\" height=\"170%\"><feDropShadow dx=\"0\" dy=\"12\" stdDeviation=\"10\" flood-color=\"#000\" flood-opacity=\".25\"/></filter>\n</defs><rect width=\"1200\" height=\"600\" fill=\"#CDD4D5\"/><rect y=\"520\" width=\"1200\" height=\"80\" fill=\"#343D41\"/><g transform=\"translate(0 35)\"><rect width=\"200\" height=\"485\" rx=\"8\" fill=\"url(#steel)\" stroke=\"#172027\" stroke-width=\"8\"/>\n<rect x=\"0\" y=\"0\" width=\"200\" height=\"48.5\" rx=\"6\" fill=\"url(#dark)\"/><text x=\"16.0\" y=\"33.95\" font-family=\"Arial,sans-serif\" font-size=\"16\" font-weight=\"800\" fill=\"#F7FAF9\"></text><path d=\"M 0 242.5 H 200\" stroke=\"#172027\" stroke-width=\"7\"/><g transform=\"translate(52.0 92.15)\">\n<rect width=\"96.0\" height=\"106.7\" rx=\"10\" fill=\"#172027\" stroke=\"#0C1114\" stroke-width=\"6\"/>\n<rect x=\"7.7\" y=\"8.5\" width=\"32.6\" height=\"57.6\" rx=\"5\" fill=\"#343D41\" stroke=\"#DCE3E2\" stroke-width=\"4\"/>\n<rect x=\"12.5\" y=\"16.0\" width=\"23.0\" height=\"19.2\" rx=\"3\" fill=\"#B9CFB4\"/>\n<g fill=\"#DCE3E2\"><circle cx=\"16.3\" cy=\"43.7\" r=\"3\"/><circle cx=\"22.1\" cy=\"43.7\" r=\"3\"/><circle cx=\"27.8\" cy=\"43.7\" r=\"3\"/><circle cx=\"33.6\" cy=\"43.7\" r=\"3\"/></g><rect x=\"48.0\" y=\"12.8\" width=\"38.4\" height=\"51.2\" rx=\"7\" fill=\"#3B4445\" stroke=\"#9FAAAC\" stroke-width=\"4\"/>\n<rect x=\"53.8\" y=\"23.5\" width=\"13.4\" height=\"17.1\" rx=\"3\" fill=\"#E43D3D\"/><path d=\"M 60.5 26.7 v 10.7\" stroke=\"white\" stroke-width=\"5\"/>\n<rect x=\"71.0\" y=\"23.5\" width=\"11.5\" height=\"17.1\" rx=\"3\" fill=\"#47B95C\"/><path d=\"M 76.8 26.7 v 10.7\" stroke=\"white\" stroke-width=\"5\"/>\n<path d=\"M 48.0 12.8 h 32.6 q 7.7 0 7.7 8.5\" fill=\"none\" stroke=\"#F7FAF9\" stroke-width=\"4\" opacity=\".55\"/>\n<rect x=\"7.7\" y=\"74.7\" width=\"80.6\" height=\"19.2\" rx=\"4\" fill=\"#9FAAAC\"/>\n<rect x=\"14.4\" y=\"80.0\" width=\"34.6\" height=\"5.3\" fill=\"#DCE3E2\"/><rect x=\"14.4\" y=\"87.5\" width=\"52.8\" height=\"2.7\" fill=\"#707C7F\"/>\n</g><rect x=\"164.0\" y=\"110.6\" width=\"12.0\" height=\"58.2\" rx=\"3\" fill=\"#172027\"/><g transform=\"translate(52.0 297.0625)\">\n<rect width=\"96.0\" height=\"133.375\" rx=\"10\" fill=\"#172027\" stroke=\"#0C1114\" stroke-width=\"6\"/>\n<rect x=\"7.7\" y=\"10.7\" width=\"32.6\" height=\"72.0\" rx=\"5\" fill=\"#343D41\" stroke=\"#DCE3E2\" stroke-width=\"4\"/>\n<rect x=\"12.5\" y=\"20.0\" width=\"23.0\" height=\"24.0\" rx=\"3\" fill=\"#B9CFB4\"/>\n<g fill=\"#DCE3E2\"><circle cx=\"16.3\" cy=\"54.7\" r=\"3\"/><circle cx=\"22.1\" cy=\"54.7\" r=\"3\"/><circle cx=\"27.8\" cy=\"54.7\" r=\"3\"/><circle cx=\"33.6\" cy=\"54.7\" r=\"3\"/></g><rect x=\"48.0\" y=\"16.0\" width=\"38.4\" height=\"64.0\" rx=\"7\" fill=\"#3B4445\" stroke=\"#9FAAAC\" stroke-width=\"4\"/>\n<rect x=\"53.8\" y=\"29.3\" width=\"13.4\" height=\"21.3\" rx=\"3\" fill=\"#E43D3D\"/><path d=\"M 60.5 33.3 v 13.3\" stroke=\"white\" stroke-width=\"5\"/>\n<rect x=\"71.0\" y=\"29.3\" width=\"11.5\" height=\"21.3\" rx=\"3\" fill=\"#1677C8\"/><path d=\"M 76.8 33.3 v 13.3\" stroke=\"white\" stroke-width=\"5\"/>\n<path d=\"M 48.0 16.0 h 32.6 q 7.7 0 7.7 10.7\" fill=\"none\" stroke=\"#F7FAF9\" stroke-width=\"4\" opacity=\".55\"/>\n<rect x=\"7.7\" y=\"93.4\" width=\"80.6\" height=\"24.0\" rx=\"4\" fill=\"#9FAAAC\"/>\n<rect x=\"14.4\" y=\"100.0\" width=\"34.6\" height=\"6.7\" fill=\"#DCE3E2\"/><rect x=\"14.4\" y=\"109.4\" width=\"52.8\" height=\"3.3\" fill=\"#707C7F\"/>\n</g><rect x=\"164.0\" y=\"320.1\" width=\"12.0\" height=\"72.8\" rx=\"3\" fill=\"#172027\"/><circle cx=\"12\" cy=\"16\" r=\"4\" fill=\"#172027\" opacity=\".65\"/><circle cx=\"12\" cy=\"469\" r=\"4\" fill=\"#172027\" opacity=\".65\"/><circle cx=\"188\" cy=\"16\" r=\"4\" fill=\"#172027\" opacity=\".65\"/><circle cx=\"188\" cy=\"469\" r=\"4\" fill=\"#172027\" opacity=\".65\"/></g><g transform=\"translate(200 35)\"><rect width=\"200\" height=\"485\" rx=\"8\" fill=\"url(#steel)\" stroke=\"#172027\" stroke-width=\"8\"/>\n<rect x=\"0\" y=\"0\" width=\"200\" height=\"48.5\" rx=\"6\" fill=\"url(#dark)\"/><text x=\"16.0\" y=\"33.95\" font-family=\"Arial,sans-serif\" font-size=\"16\" font-weight=\"800\" fill=\"#F7FAF9\"></text><path d=\"M 0 242.5 H 200\" stroke=\"#172027\" stroke-width=\"7\"/><g transform=\"translate(52.0 92.15)\">\n<rect width=\"96.0\" height=\"106.7\" rx=\"10\" fill=\"#172027\" stroke=\"#0C1114\" stroke-width=\"6\"/>\n<rect x=\"7.7\" y=\"8.5\" width=\"32.6\" height=\"57.6\" rx=\"5\" fill=\"#343D41\" stroke=\"#DCE3E2\" stroke-width=\"4\"/>\n<rect x=\"12.5\" y=\"16.0\" width=\"23.0\" height=\"19.2\" rx=\"3\" fill=\"#B9CFB4\"/>\n<g fill=\"#DCE3E2\"><circle cx=\"16.3\" cy=\"43.7\" r=\"3\"/><circle cx=\"22.1\" cy=\"43.7\" r=\"3\"/><circle cx=\"27.8\" cy=\"43.7\" r=\"3\"/><circle cx=\"33.6\" cy=\"43.7\" r=\"3\"/></g><rect x=\"48.0\" y=\"12.8\" width=\"38.4\" height=\"51.2\" rx=\"7\" fill=\"#3B4445\" stroke=\"#9FAAAC\" stroke-width=\"4\"/>\n<rect x=\"53.8\" y=\"23.5\" width=\"13.4\" height=\"17.1\" rx=\"3\" fill=\"#E43D3D\"/><path d=\"M 60.5 26.7 v 10.7\" stroke=\"white\" stroke-width=\"5\"/>\n<rect x=\"71.0\" y=\"23.5\" width=\"11.5\" height=\"17.1\" rx=\"3\" fill=\"#47B95C\"/><path d=\"M 76.8 26.7 v 10.7\" stroke=\"white\" stroke-width=\"5\"/>\n<path d=\"M 48.0 12.8 h 32.6 q 7.7 0 7.7 8.5\" fill=\"none\" stroke=\"#F7FAF9\" stroke-width=\"4\" opacity=\".55\"/>\n<rect x=\"7.7\" y=\"74.7\" width=\"80.6\" height=\"19.2\" rx=\"4\" fill=\"#9FAAAC\"/>\n<rect x=\"14.4\" y=\"80.0\" width=\"34.6\" height=\"5.3\" fill=\"#DCE3E2\"/><rect x=\"14.4\" y=\"87.5\" width=\"52.8\" height=\"2.7\" fill=\"#707C7F\"/>\n</g><rect x=\"164.0\" y=\"110.6\" width=\"12.0\" height=\"58.2\" rx=\"3\" fill=\"#172027\"/><g transform=\"translate(52.0 297.0625)\">\n<rect width=\"96.0\" height=\"133.375\" rx=\"10\" fill=\"#172027\" stroke=\"#0C1114\" stroke-width=\"6\"/>\n<rect x=\"7.7\" y=\"10.7\" width=\"32.6\" height=\"72.0\" rx=\"5\" fill=\"#343D41\" stroke=\"#DCE3E2\" stroke-width=\"4\"/>\n<rect x=\"12.5\" y=\"20.0\" width=\"23.0\" height=\"24.0\" rx=\"3\" fill=\"#B9CFB4\"/>\n<g fill=\"#DCE3E2\"><circle cx=\"16.3\" cy=\"54.7\" r=\"3\"/><circle cx=\"22.1\" cy=\"54.7\" r=\"3\"/><circle cx=\"27.8\" cy=\"54.7\" r=\"3\"/><circle cx=\"33.6\" cy=\"54.7\" r=\"3\"/></g><rect x=\"48.0\" y=\"16.0\" width=\"38.4\" height=\"64.0\" rx=\"7\" fill=\"#3B4445\" stroke=\"#9FAAAC\" stroke-width=\"4\"/>\n<rect x=\"53.8\" y=\"29.3\" width=\"13.4\" height=\"21.3\" rx=\"3\" fill=\"#E43D3D\"/><path d=\"M 60.5 33.3 v 13.3\" stroke=\"white\" stroke-width=\"5\"/>\n<rect x=\"71.0\" y=\"29.3\" width=\"11.5\" height=\"21.3\" rx=\"3\" fill=\"#1677C8\"/><path d=\"M 76.8 33.3 v 13.3\" stroke=\"white\" stroke-width=\"5\"/>\n<path d=\"M 48.0 16.0 h 32.6 q 7.7 0 7.7 10.7\" fill=\"none\" stroke=\"#F7FAF9\" stroke-width=\"4\" opacity=\".55\"/>\n<rect x=\"7.7\" y=\"93.4\" width=\"80.6\" height=\"24.0\" rx=\"4\" fill=\"#9FAAAC\"/>\n<rect x=\"14.4\" y=\"100.0\" width=\"34.6\" height=\"6.7\" fill=\"#DCE3E2\"/><rect x=\"14.4\" y=\"109.4\" width=\"52.8\" height=\"3.3\" fill=\"#707C7F\"/>\n</g><rect x=\"164.0\" y=\"320.1\" width=\"12.0\" height=\"72.8\" rx=\"3\" fill=\"#172027\"/><circle cx=\"12\" cy=\"16\" r=\"4\" fill=\"#172027\" opacity=\".65\"/><circle cx=\"12\" cy=\"469\" r=\"4\" fill=\"#172027\" opacity=\".65\"/><circle cx=\"188\" cy=\"16\" r=\"4\" fill=\"#172027\" opacity=\".65\"/><circle cx=\"188\" cy=\"469\" r=\"4\" fill=\"#172027\" opacity=\".65\"/></g><g transform=\"translate(400 35)\"><rect width=\"200\" height=\"485\" rx=\"8\" fill=\"url(#steel)\" stroke=\"#172027\" stroke-width=\"8\"/>\n<rect x=\"0\" y=\"0\" width=\"200\" height=\"48.5\" rx=\"6\" fill=\"url(#dark)\"/><text x=\"16.0\" y=\"33.95\" font-family=\"Arial,sans-serif\" font-size=\"16\" font-weight=\"800\" fill=\"#F7FAF9\"></text><path d=\"M 0 242.5 H 200\" stroke=\"#172027\" stroke-width=\"7\"/><g transform=\"translate(52.0 92.15)\">\n<rect width=\"96.0\" height=\"106.7\" rx=\"10\" fill=\"#172027\" stroke=\"#0C1114\" stroke-width=\"6\"/>\n<rect x=\"7.7\" y=\"8.5\" width=\"32.6\" height=\"57.6\" rx=\"5\" fill=\"#343D41\" stroke=\"#DCE3E2\" stroke-width=\"4\"/>\n<rect x=\"12.5\" y=\"16.0\" width=\"23.0\" height=\"19.2\" rx=\"3\" fill=\"#B9CFB4\"/>\n<g fill=\"#DCE3E2\"><circle cx=\"16.3\" cy=\"43.7\" r=\"3\"/><circle cx=\"22.1\" cy=\"43.7\" r=\"3\"/><circle cx=\"27.8\" cy=\"43.7\" r=\"3\"/><circle cx=\"33.6\" cy=\"43.7\" r=\"3\"/></g><rect x=\"48.0\" y=\"12.8\" width=\"38.4\" height=\"51.2\" rx=\"7\" fill=\"#3B4445\" stroke=\"#9FAAAC\" stroke-width=\"4\"/>\n<rect x=\"53.8\" y=\"23.5\" width=\"13.4\" height=\"17.1\" rx=\"3\" fill=\"#E43D3D\"/><path d=\"M 60.5 26.7 v 10.7\" stroke=\"white\" stroke-width=\"5\"/>\n<rect x=\"71.0\" y=\"23.5\" width=\"11.5\" height=\"17.1\" rx=\"3\" fill=\"#47B95C\"/><path d=\"M 76.8 26.7 v 10.7\" stroke=\"white\" stroke-width=\"5\"/>\n<path d=\"M 48.0 12.8 h 32.6 q 7.7 0 7.7 8.5\" fill=\"none\" stroke=\"#F7FAF9\" stroke-width=\"4\" opacity=\".55\"/>\n<rect x=\"7.7\" y=\"74.7\" width=\"80.6\" height=\"19.2\" rx=\"4\" fill=\"#9FAAAC\"/>\n<rect x=\"14.4\" y=\"80.0\" width=\"34.6\" height=\"5.3\" fill=\"#DCE3E2\"/><rect x=\"14.4\" y=\"87.5\" width=\"52.8\" height=\"2.7\" fill=\"#707C7F\"/>\n</g><rect x=\"164.0\" y=\"110.6\" width=\"12.0\" height=\"58.2\" rx=\"3\" fill=\"#172027\"/><rect x=\"164.0\" y=\"320.1\" width=\"12.0\" height=\"72.8\" rx=\"3\" fill=\"#172027\"/><circle cx=\"12\" cy=\"16\" r=\"4\" fill=\"#172027\" opacity=\".65\"/><circle cx=\"12\" cy=\"469\" r=\"4\" fill=\"#172027\" opacity=\".65\"/><circle cx=\"188\" cy=\"16\" r=\"4\" fill=\"#172027\" opacity=\".65\"/><circle cx=\"188\" cy=\"469\" r=\"4\" fill=\"#172027\" opacity=\".65\"/></g><g transform=\"translate(600 35)\"><rect width=\"200\" height=\"485\" rx=\"8\" fill=\"url(#steel)\" stroke=\"#172027\" stroke-width=\"8\"/>\n<rect x=\"0\" y=\"0\" width=\"200\" height=\"48.5\" rx=\"6\" fill=\"url(#dark)\"/><text x=\"16.0\" y=\"33.95\" font-family=\"Arial,sans-serif\" font-size=\"16\" font-weight=\"800\" fill=\"#F7FAF9\"></text><path d=\"M 0 242.5 H 200\" stroke=\"#172027\" stroke-width=\"7\"/><rect x=\"164.0\" y=\"110.6\" width=\"12.0\" height=\"58.2\" rx=\"3\" fill=\"#172027\"/><g transform=\"translate(52.0 297.0625)\">\n<rect width=\"96.0\" height=\"133.375\" rx=\"10\" fill=\"#172027\" stroke=\"#0C1114\" stroke-width=\"6\"/>\n<rect x=\"7.7\" y=\"10.7\" width=\"32.6\" height=\"72.0\" rx=\"5\" fill=\"#343D41\" stroke=\"#DCE3E2\" stroke-width=\"4\"/>\n<rect x=\"12.5\" y=\"20.0\" width=\"23.0\" height=\"24.0\" rx=\"3\" fill=\"#B9CFB4\"/>\n<g fill=\"#DCE3E2\"><circle cx=\"16.3\" cy=\"54.7\" r=\"3\"/><circle cx=\"22.1\" cy=\"54.7\" r=\"3\"/><circle cx=\"27.8\" cy=\"54.7\" r=\"3\"/><circle cx=\"33.6\" cy=\"54.7\" r=\"3\"/></g><rect x=\"48.0\" y=\"16.0\" width=\"38.4\" height=\"64.0\" rx=\"7\" fill=\"#3B4445\" stroke=\"#9FAAAC\" stroke-width=\"4\"/>\n<rect x=\"53.8\" y=\"29.3\" width=\"13.4\" height=\"21.3\" rx=\"3\" fill=\"#E43D3D\"/><path d=\"M 60.5 33.3 v 13.3\" stroke=\"white\" stroke-width=\"5\"/>\n<rect x=\"71.0\" y=\"29.3\" width=\"11.5\" height=\"21.3\" rx=\"3\" fill=\"#1677C8\"/><path d=\"M 76.8 33.3 v 13.3\" stroke=\"white\" stroke-width=\"5\"/>\n<path d=\"M 48.0 16.0 h 32.6 q 7.7 0 7.7 10.7\" fill=\"none\" stroke=\"#F7FAF9\" stroke-width=\"4\" opacity=\".55\"/>\n<rect x=\"7.7\" y=\"93.4\" width=\"80.6\" height=\"24.0\" rx=\"4\" fill=\"#9FAAAC\"/>\n<rect x=\"14.4\" y=\"100.0\" width=\"34.6\" height=\"6.7\" fill=\"#DCE3E2\"/><rect x=\"14.4\" y=\"109.4\" width=\"52.8\" height=\"3.3\" fill=\"#707C7F\"/>\n</g><rect x=\"164.0\" y=\"320.1\" width=\"12.0\" height=\"72.8\" rx=\"3\" fill=\"#172027\"/><circle cx=\"12\" cy=\"16\" r=\"4\" fill=\"#172027\" opacity=\".65\"/><circle cx=\"12\" cy=\"469\" r=\"4\" fill=\"#172027\" opacity=\".65\"/><circle cx=\"188\" cy=\"16\" r=\"4\" fill=\"#172027\" opacity=\".65\"/><circle cx=\"188\" cy=\"469\" r=\"4\" fill=\"#172027\" opacity=\".65\"/></g><g transform=\"translate(800 35)\"><rect width=\"200\" height=\"485\" rx=\"8\" fill=\"url(#steel)\" stroke=\"#172027\" stroke-width=\"8\"/>\n<rect x=\"0\" y=\"0\" width=\"200\" height=\"48.5\" rx=\"6\" fill=\"url(#dark)\"/><text x=\"16.0\" y=\"33.95\" font-family=\"Arial,sans-serif\" font-size=\"16\" font-weight=\"800\" fill=\"#F7FAF9\"></text><path d=\"M 0 242.5 H 200\" stroke=\"#172027\" stroke-width=\"7\"/><g transform=\"translate(52.0 92.15)\">\n<rect width=\"96.0\" height=\"106.7\" rx=\"10\" fill=\"#172027\" stroke=\"#0C1114\" stroke-width=\"6\"/>\n<rect x=\"7.7\" y=\"8.5\" width=\"32.6\" height=\"57.6\" rx=\"5\" fill=\"#343D41\" stroke=\"#DCE3E2\" stroke-width=\"4\"/>\n<rect x=\"12.5\" y=\"16.0\" width=\"23.0\" height=\"19.2\" rx=\"3\" fill=\"#B9CFB4\"/>\n<g fill=\"#DCE3E2\"><circle cx=\"16.3\" cy=\"43.7\" r=\"3\"/><circle cx=\"22.1\" cy=\"43.7\" r=\"3\"/><circle cx=\"27.8\" cy=\"43.7\" r=\"3\"/><circle cx=\"33.6\" cy=\"43.7\" r=\"3\"/></g><rect x=\"48.0\" y=\"12.8\" width=\"38.4\" height=\"51.2\" rx=\"7\" fill=\"#3B4445\" stroke=\"#9FAAAC\" stroke-width=\"4\"/>\n<rect x=\"53.8\" y=\"23.5\" width=\"13.4\" height=\"17.1\" rx=\"3\" fill=\"#E43D3D\"/><path d=\"M 60.5 26.7 v 10.7\" stroke=\"white\" stroke-width=\"5\"/>\n<rect x=\"71.0\" y=\"23.5\" width=\"11.5\" height=\"17.1\" rx=\"3\" fill=\"#47B95C\"/><path d=\"M 76.8 26.7 v 10.7\" stroke=\"white\" stroke-width=\"5\"/>\n<path d=\"M 48.0 12.8 h 32.6 q 7.7 0 7.7 8.5\" fill=\"none\" stroke=\"#F7FAF9\" stroke-width=\"4\" opacity=\".55\"/>\n<rect x=\"7.7\" y=\"74.7\" width=\"80.6\" height=\"19.2\" rx=\"4\" fill=\"#9FAAAC\"/>\n<rect x=\"14.4\" y=\"80.0\" width=\"34.6\" height=\"5.3\" fill=\"#DCE3E2\"/><rect x=\"14.4\" y=\"87.5\" width=\"52.8\" height=\"2.7\" fill=\"#707C7F\"/>\n</g><rect x=\"164.0\" y=\"110.6\" width=\"12.0\" height=\"58.2\" rx=\"3\" fill=\"#172027\"/><g transform=\"translate(52.0 297.0625)\">\n<rect width=\"96.0\" height=\"133.375\" rx=\"10\" fill=\"#172027\" stroke=\"#0C1114\" stroke-width=\"6\"/>\n<rect x=\"7.7\" y=\"10.7\" width=\"32.6\" height=\"72.0\" rx=\"5\" fill=\"#343D41\" stroke=\"#DCE3E2\" stroke-width=\"4\"/>\n<rect x=\"12.5\" y=\"20.0\" width=\"23.0\" height=\"24.0\" rx=\"3\" fill=\"#B9CFB4\"/>\n<g fill=\"#DCE3E2\"><circle cx=\"16.3\" cy=\"54.7\" r=\"3\"/><circle cx=\"22.1\" cy=\"54.7\" r=\"3\"/><circle cx=\"27.8\" cy=\"54.7\" r=\"3\"/><circle cx=\"33.6\" cy=\"54.7\" r=\"3\"/></g><rect x=\"48.0\" y=\"16.0\" width=\"38.4\" height=\"64.0\" rx=\"7\" fill=\"#3B4445\" stroke=\"#9FAAAC\" stroke-width=\"4\"/>\n<rect x=\"53.8\" y=\"29.3\" width=\"13.4\" height=\"21.3\" rx=\"3\" fill=\"#E43D3D\"/><path d=\"M 60.5 33.3 v 13.3\" stroke=\"white\" stroke-width=\"5\"/>\n<rect x=\"71.0\" y=\"29.3\" width=\"11.5\" height=\"21.3\" rx=\"3\" fill=\"#1677C8\"/><path d=\"M 76.8 33.3 v 13.3\" stroke=\"white\" stroke-width=\"5\"/>\n<path d=\"M 48.0 16.0 h 32.6 q 7.7 0 7.7 10.7\" fill=\"none\" stroke=\"#F7FAF9\" stroke-width=\"4\" opacity=\".55\"/>\n<rect x=\"7.7\" y=\"93.4\" width=\"80.6\" height=\"24.0\" rx=\"4\" fill=\"#9FAAAC\"/>\n<rect x=\"14.4\" y=\"100.0\" width=\"34.6\" height=\"6.7\" fill=\"#DCE3E2\"/><rect x=\"14.4\" y=\"109.4\" width=\"52.8\" height=\"3.3\" fill=\"#707C7F\"/>\n</g><rect x=\"164.0\" y=\"320.1\" width=\"12.0\" height=\"72.8\" rx=\"3\" fill=\"#172027\"/><circle cx=\"12\" cy=\"16\" r=\"4\" fill=\"#172027\" opacity=\".65\"/><circle cx=\"12\" cy=\"469\" r=\"4\" fill=\"#172027\" opacity=\".65\"/><circle cx=\"188\" cy=\"16\" r=\"4\" fill=\"#172027\" opacity=\".65\"/><circle cx=\"188\" cy=\"469\" r=\"4\" fill=\"#172027\" opacity=\".65\"/></g><g transform=\"translate(1000 35)\"><rect width=\"200\" height=\"485\" rx=\"8\" fill=\"url(#steel)\" stroke=\"#172027\" stroke-width=\"8\"/>\n<rect x=\"0\" y=\"0\" width=\"200\" height=\"48.5\" rx=\"6\" fill=\"url(#dark)\"/><text x=\"16.0\" y=\"33.95\" font-family=\"Arial,sans-serif\" font-size=\"16\" font-weight=\"800\" fill=\"#F7FAF9\"></text><path d=\"M 0 242.5 H 200\" stroke=\"#172027\" stroke-width=\"7\"/><g transform=\"translate(52.0 92.15)\">\n<rect width=\"96.0\" height=\"106.7\" rx=\"10\" fill=\"#172027\" stroke=\"#0C1114\" stroke-width=\"6\"/>\n<rect x=\"7.7\" y=\"8.5\" width=\"32.6\" height=\"57.6\" rx=\"5\" fill=\"#343D41\" stroke=\"#DCE3E2\" stroke-width=\"4\"/>\n<rect x=\"12.5\" y=\"16.0\" width=\"23.0\" height=\"19.2\" rx=\"3\" fill=\"#B9CFB4\"/>\n<g fill=\"#DCE3E2\"><circle cx=\"16.3\" cy=\"43.7\" r=\"3\"/><circle cx=\"22.1\" cy=\"43.7\" r=\"3\"/><circle cx=\"27.8\" cy=\"43.7\" r=\"3\"/><circle cx=\"33.6\" cy=\"43.7\" r=\"3\"/></g><rect x=\"48.0\" y=\"12.8\" width=\"38.4\" height=\"51.2\" rx=\"7\" fill=\"#3B4445\" stroke=\"#9FAAAC\" stroke-width=\"4\"/>\n<rect x=\"53.8\" y=\"23.5\" width=\"13.4\" height=\"17.1\" rx=\"3\" fill=\"#E43D3D\"/><path d=\"M 60.5 26.7 v 10.7\" stroke=\"white\" stroke-width=\"5\"/>\n<rect x=\"71.0\" y=\"23.5\" width=\"11.5\" height=\"17.1\" rx=\"3\" fill=\"#47B95C\"/><path d=\"M 76.8 26.7 v 10.7\" stroke=\"white\" stroke-width=\"5\"/>\n<path d=\"M 48.0 12.8 h 32.6 q 7.7 0 7.7 8.5\" fill=\"none\" stroke=\"#F7FAF9\" stroke-width=\"4\" opacity=\".55\"/>\n<rect x=\"7.7\" y=\"74.7\" width=\"80.6\" height=\"19.2\" rx=\"4\" fill=\"#9FAAAC\"/>\n<rect x=\"14.4\" y=\"80.0\" width=\"34.6\" height=\"5.3\" fill=\"#DCE3E2\"/><rect x=\"14.4\" y=\"87.5\" width=\"52.8\" height=\"2.7\" fill=\"#707C7F\"/>\n</g><rect x=\"164.0\" y=\"110.6\" width=\"12.0\" height=\"58.2\" rx=\"3\" fill=\"#172027\"/><g transform=\"translate(52.0 297.0625)\">\n<rect width=\"96.0\" height=\"133.375\" rx=\"10\" fill=\"#172027\" stroke=\"#0C1114\" stroke-width=\"6\"/>\n<rect x=\"7.7\" y=\"10.7\" width=\"32.6\" height=\"72.0\" rx=\"5\" fill=\"#343D41\" stroke=\"#DCE3E2\" stroke-width=\"4\"/>\n<rect x=\"12.5\" y=\"20.0\" width=\"23.0\" height=\"24.0\" rx=\"3\" fill=\"#B9CFB4\"/>\n<g fill=\"#DCE3E2\"><circle cx=\"16.3\" cy=\"54.7\" r=\"3\"/><circle cx=\"22.1\" cy=\"54.7\" r=\"3\"/><circle cx=\"27.8\" cy=\"54.7\" r=\"3\"/><circle cx=\"33.6\" cy=\"54.7\" r=\"3\"/></g><rect x=\"48.0\" y=\"16.0\" width=\"38.4\" height=\"64.0\" rx=\"7\" fill=\"#3B4445\" stroke=\"#9FAAAC\" stroke-width=\"4\"/>\n<rect x=\"53.8\" y=\"29.3\" width=\"13.4\" height=\"21.3\" rx=\"3\" fill=\"#E43D3D\"/><path d=\"M 60.5 33.3 v 13.3\" stroke=\"white\" stroke-width=\"5\"/>\n<rect x=\"71.0\" y=\"29.3\" width=\"11.5\" height=\"21.3\" rx=\"3\" fill=\"#1677C8\"/><path d=\"M 76.8 33.3 v 13.3\" stroke=\"white\" stroke-width=\"5\"/>\n<path d=\"M 48.0 16.0 h 32.6 q 7.7 0 7.7 10.7\" fill=\"none\" stroke=\"#F7FAF9\" stroke-width=\"4\" opacity=\".55\"/>\n<rect x=\"7.7\" y=\"93.4\" width=\"80.6\" height=\"24.0\" rx=\"4\" fill=\"#9FAAAC\"/>\n<rect x=\"14.4\" y=\"100.0\" width=\"34.6\" height=\"6.7\" fill=\"#DCE3E2\"/><rect x=\"14.4\" y=\"109.4\" width=\"52.8\" height=\"3.3\" fill=\"#707C7F\"/>\n</g><rect x=\"164.0\" y=\"320.1\" width=\"12.0\" height=\"72.8\" rx=\"3\" fill=\"#172027\"/><circle cx=\"12\" cy=\"16\" r=\"4\" fill=\"#172027\" opacity=\".65\"/><circle cx=\"12\" cy=\"469\" r=\"4\" fill=\"#172027\" opacity=\".65\"/><circle cx=\"188\" cy=\"16\" r=\"4\" fill=\"#172027\" opacity=\".65\"/><circle cx=\"188\" cy=\"469\" r=\"4\" fill=\"#172027\" opacity=\".65\"/></g><path d=\"M0 548 H1200\" stroke=\"#F2C14E\" stroke-width=\"12\" stroke-dasharray=\"44 26\"/></svg>","breaker_pickup":"<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"384\" height=\"384\" viewBox=\"0 0 384 384\" role=\"img\" aria-label=\"Cartoon breaker pickup icon\">\n<defs>\n <linearGradient id=\"steel\" x1=\"0\" y1=\"0\" x2=\"1\" y2=\"1\"><stop offset=\"0\" stop-color=\"#DCE3E2\"/><stop offset=\"1\" stop-color=\"#9FAAAC\"/></linearGradient>\n <linearGradient id=\"dark\" x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\"><stop offset=\"0\" stop-color=\"#343D41\"/><stop offset=\"1\" stop-color=\"#172027\"/></linearGradient>\n <filter id=\"shadow\" x=\"-30%\" y=\"-30%\" width=\"160%\" height=\"170%\"><feDropShadow dx=\"0\" dy=\"12\" stdDeviation=\"10\" flood-color=\"#000\" flood-opacity=\".25\"/></filter>\n</defs><path d=\"M192 25 l145 84 v166 l-145 84 -145-84 V109 Z\" fill=\"#1677C8\" stroke=\"#172027\" stroke-width=\"12\"/><circle cx=\"192\" cy=\"192\" r=\"126\" fill=\"#DCE3E2\" stroke=\"#F7FAF9\" stroke-width=\"8\"/><g transform=\"translate(108 92)\">\n<rect width=\"168\" height=\"200\" rx=\"10\" fill=\"#172027\" stroke=\"#0C1114\" stroke-width=\"6\"/>\n<rect x=\"13.4\" y=\"16.0\" width=\"57.1\" height=\"108.0\" rx=\"5\" fill=\"#343D41\" stroke=\"#DCE3E2\" stroke-width=\"4\"/>\n<rect x=\"21.8\" y=\"30.0\" width=\"40.3\" height=\"36.0\" rx=\"3\" fill=\"#B9CFB4\"/>\n<g fill=\"#DCE3E2\"><circle cx=\"28.6\" cy=\"82.0\" r=\"3\"/><circle cx=\"38.6\" cy=\"82.0\" r=\"3\"/><circle cx=\"48.7\" cy=\"82.0\" r=\"3\"/><circle cx=\"58.8\" cy=\"82.0\" r=\"3\"/></g><rect x=\"84.0\" y=\"24.0\" width=\"67.2\" height=\"96.0\" rx=\"7\" fill=\"#3B4445\" stroke=\"#9FAAAC\" stroke-width=\"4\"/>\n<rect x=\"94.1\" y=\"44.0\" width=\"23.5\" height=\"32.0\" rx=\"3\" fill=\"#E43D3D\"/><path d=\"M 105.8 50.0 v 20.0\" stroke=\"white\" stroke-width=\"5\"/>\n<rect x=\"124.3\" y=\"44.0\" width=\"20.2\" height=\"32.0\" rx=\"3\" fill=\"#47B95C\"/><path d=\"M 134.4 50.0 v 20.0\" stroke=\"white\" stroke-width=\"5\"/>\n<path d=\"M 84.0 24.0 h 57.1 q 13.4 0 13.4 16.0\" fill=\"none\" stroke=\"#F7FAF9\" stroke-width=\"4\" opacity=\".55\"/>\n<rect x=\"13.4\" y=\"140.0\" width=\"141.1\" height=\"36.0\" rx=\"4\" fill=\"#9FAAAC\"/>\n<rect x=\"25.2\" y=\"150.0\" width=\"60.5\" height=\"10.0\" fill=\"#DCE3E2\"/><rect x=\"25.2\" y=\"164.0\" width=\"92.4\" height=\"5.0\" fill=\"#707C7F\"/>\n</g></svg>","panel_hazard_gate":"<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"800\" height=\"600\" viewBox=\"0 0 800 600\" role=\"img\" aria-label=\"Cartoon panel hazard gate\">\n<defs>\n <linearGradient id=\"steel\" x1=\"0\" y1=\"0\" x2=\"1\" y2=\"1\"><stop offset=\"0\" stop-color=\"#DCE3E2\"/><stop offset=\"1\" stop-color=\"#9FAAAC\"/></linearGradient>\n <linearGradient id=\"dark\" x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\"><stop offset=\"0\" stop-color=\"#343D41\"/><stop offset=\"1\" stop-color=\"#172027\"/></linearGradient>\n <filter id=\"shadow\" x=\"-30%\" y=\"-30%\" width=\"160%\" height=\"170%\"><feDropShadow dx=\"0\" dy=\"12\" stdDeviation=\"10\" flood-color=\"#000\" flood-opacity=\".25\"/></filter>\n</defs><rect x=\"60\" y=\"90\" width=\"680\" height=\"430\" rx=\"18\" fill=\"url(#steel)\" stroke=\"#172027\" stroke-width=\"14\"/><rect x=\"85\" y=\"120\" width=\"630\" height=\"70\" rx=\"10\" fill=\"url(#dark)\"/><text x=\"240\" y=\"168\" fill=\"#F7FAF9\" font-family=\"Arial\" font-size=\"34\" font-weight=\"800\">LOCKED PANEL</text><rect x=\"125\" y=\"235\" width=\"150\" height=\"205\" rx=\"14\" fill=\"#707C7F\" stroke=\"#172027\" stroke-width=\"8\"/><circle cx=\"165\" cy=\"280\" r=\"9\" fill=\"#E43D3D\" stroke=\"#172027\" stroke-width=\"5\"/><circle cx=\"162\" cy=\"277\" r=\"2\" fill=\"white\" opacity=\".8\"/><rect x=\"325\" y=\"235\" width=\"150\" height=\"205\" rx=\"14\" fill=\"#707C7F\" stroke=\"#172027\" stroke-width=\"8\"/><circle cx=\"365\" cy=\"280\" r=\"9\" fill=\"#E43D3D\" stroke=\"#172027\" stroke-width=\"5\"/><circle cx=\"362\" cy=\"277\" r=\"2\" fill=\"white\" opacity=\".8\"/><rect x=\"525\" y=\"235\" width=\"150\" height=\"205\" rx=\"14\" fill=\"#707C7F\" stroke=\"#172027\" stroke-width=\"8\"/><circle cx=\"565\" cy=\"280\" r=\"9\" fill=\"#E43D3D\" stroke=\"#172027\" stroke-width=\"5\"/><circle cx=\"562\" cy=\"277\" r=\"2\" fill=\"white\" opacity=\".8\"/><path d=\"M90 470 H710\" stroke=\"#F2C14E\" stroke-width=\"28\" stroke-dasharray=\"55 24\"/></svg>"};
  const cache = new Map();
  const manifest = {"switchgear_lineup_front":{"id":"switchgear_lineup_front","file":"../02_svg_assets/switchgear_lineup_front.svg","native":[1200,720],"anchor":[0.5,1.0],"collision":[0.07,0.1,0.86,0.82],"suggestedUse":["landmark","finish backdrop","foreground prop"]},"arc_resistant_lineup_perspective":{"id":"arc_resistant_lineup_perspective","file":"../02_svg_assets/arc_resistant_lineup_perspective.svg","native":[1200,760],"anchor":[0.5,1.0],"collision":[0.15,0.12,0.72,0.8],"suggestedUse":["hero backdrop","boss arena"]},"magnum_breaker":{"id":"magnum_breaker","file":"../02_svg_assets/magnum_breaker.svg","native":[640,640],"anchor":[0.5,0.5],"collision":[0.11,0.06,0.78,0.82],"suggestedUse":["interactive prop","UI close-up"]},"control_station":{"id":"control_station","file":"../02_svg_assets/control_station.svg","native":[640,480],"anchor":[0.5,1.0],"collision":[0.07,0.09,0.86,0.82],"suggestedUse":["tutorial terminal","lap control"]},"switchboard_obstacle":{"id":"switchboard_obstacle","file":"../02_svg_assets/switchboard_obstacle.svg","native":[640,760],"anchor":[0.5,1.0],"collision":[0.11,0.08,0.78,0.84],"suggestedUse":["static obstacle","factory wall"]},"panel_bank_tile":{"id":"panel_bank_tile","file":"../02_svg_assets/panel_bank_tile.svg","native":[1200,600],"anchor":[0.0,1.0],"collision":null,"repeat":"x","suggestedUse":["parallax background","wall tile"]},"breaker_pickup":{"id":"breaker_pickup","file":"../02_svg_assets/breaker_pickup.svg","native":[384,384],"anchor":[0.5,0.5],"collision":[0.15,0.15,0.7,0.7],"suggestedUse":["collectible","boost token"]},"panel_hazard_gate":{"id":"panel_hazard_gate","file":"../02_svg_assets/panel_hazard_gate.svg","native":[800,600],"anchor":[0.5,1.0],"collision":[0.075,0.15,0.85,0.72],"suggestedUse":["checkpoint","locked route gate"]}};
  function url(id){ if(!svg[id]) throw new Error(`Unknown LVA asset: ${id}`); return 'data:image/svg+xml;charset=utf-8,'+encodeURIComponent(svg[id]); }
  function image(id){ if(cache.has(id)) return cache.get(id); const p=new Promise((resolve,reject)=>{ const img=new Image(); img.onload=()=>resolve(img); img.onerror=reject; img.src=url(id); }); cache.set(id,p); return p; }
  async function preload(ids=Object.keys(svg)){ await Promise.all(ids.map(image)); }
  async function draw(ctx,id,x,y,w,h,{anchor=true,alpha=1,flipX=false}={}){ const img=await image(id); const m=manifest[id]; let dx=x,dy=y; if(anchor&&m){dx-=w*m.anchor[0];dy-=h*m.anchor[1];} ctx.save();ctx.globalAlpha*=alpha;if(flipX){ctx.translate(dx+w,dy);ctx.scale(-1,1);ctx.drawImage(img,0,0,w,h);}else ctx.drawImage(img,dx,dy,w,h);ctx.restore(); }
  function collisionRect(id,x,y,w,h,{anchor=true}={}){const m=manifest[id];if(!m||!m.collision)return null;let dx=x,dy=y;if(anchor){dx-=w*m.anchor[0];dy-=h*m.anchor[1];}const c=m.collision;return{x:dx+w*c[0],y:dy+h*c[1],width:w*c[2],height:h*c[3]};}
  return {svg,manifest,url,image,preload,draw,collisionRect};
})();

/* =========================================================
   LOW VOLTAGE ASCENDERS 4.6.7 DEFERRED PROFILE GATE & DRIFT HOTFIX – single-player LVA factory racer
   Quarter-view factory-floor racer · 15 tracks · 3 themed circuits · expanded training ground · 15 employees · dual progression · 120-point Drift Meter
   ========================================================= */
const TAU=Math.PI*2;
const clamp=(v,a,b)=>v<a?a:v>b?b:v;
const lerp=(a,b,t)=>a+(b-a)*t;
const rnd=(a=0,b=1)=>a+Math.random()*(b-a);
const pick=a=>a[Math.floor(Math.random()*a.length)];
function angDiff(a,b){let d=(b-a)%TAU;if(d>Math.PI)d-=TAU;if(d<-Math.PI)d+=TAU;return d;}
function hash2(x,y,s){let h=(Math.imul(x|0,374761393)+Math.imul(y|0,668265263)+Math.imul(s|0,1442695041))|0;h=Math.imul(h^(h>>>13),1274126177);return((h^(h>>>16))>>>0)/4294967296;}
function shade(hex,f){const n=parseInt(hex.slice(1),16);const r=clamp(((n>>16)&255)*f,0,255)|0,g=clamp(((n>>8)&255)*f,0,255)|0,b=clamp((n&255)*f,0,255)|0;return'rgb('+r+','+g+','+b+')';}
function fmtTime(t){if(t==null||!isFinite(t))return'--:--.--';const m=Math.floor(t/60),s=t-m*60;return m+':'+(s<10?'0':'')+s.toFixed(2);}
const ord=n=>n+(['th','st','nd','rd'][(n%100>10&&n%100<14)?0:(n%10<4?n%10:0)]);

const cv=document.getElementById('cv');let ctx=cv.getContext('2d');
let W=800,H=600,DPR=1;
const SMOOTH={quality:'balanced',camera:true,shake:true,showFPS:true,fps:60,frameMs:16.67,lookX:0,lookY:0,resetCamera:true};
const PERF={low:false,slowT:0,fastT:0};
function lowDetail(){return SMOOTH.quality==='performance'||PERF.low;}
function particleScale(){return lowDetail()?.34:SMOOTH.quality==='balanced'?.72:1;}
function updatePerformanceGovernor(dt){
  if(SMOOTH.quality==='performance'){PERF.low=true;PERF.slowT=PERF.fastT=0;return;}
  if(SMOOTH.quality==='high'){PERF.low=false;PERF.slowT=PERF.fastT=0;return;}
  const fast=G.player&&G.player.speed>42,under=SMOOTH.fps<(fast?56:50);
  if(under){PERF.slowT+=dt;PERF.fastT=0;if(PERF.slowT>.7)PERF.low=true;}
  else{PERF.fastT+=dt;PERF.slowT=Math.max(0,PERF.slowT-dt*.5);if(PERF.low&&PERF.fastT>2.4)PERF.low=false;}
}
function screenVisible(o,margin=120){if(!o)return false;proj(o.x,o.y,o.z||0);return PX>-margin&&PX<W+margin&&PY>-margin*1.5&&PY<H+margin;}
const smoothCanvas=(w,h)=>{const c=document.createElement('canvas');c.width=w;c.height=h;return c;};
let scenerySprites=new Map();
const LVA_IMAGES=new Map();
async function initLVAAssets(){
  const ids=['switchgear_lineup_front','arc_resistant_lineup_perspective','magnum_breaker','control_station','switchboard_obstacle','panel_bank_tile','breaker_pickup','panel_hazard_gate'];
  await LVAEnvironmentAssets.preload(ids);
  await Promise.all(ids.map(async id=>LVA_IMAGES.set(id,await LVAEnvironmentAssets.image(id))));
}
function resize(){DPR=Math.min(SMOOTH.quality==='high'?2:SMOOTH.quality==='performance'?1:1.25,window.devicePixelRatio||1);W=window.innerWidth;H=window.innerHeight;cv.width=Math.floor(W*DPR);cv.height=Math.floor(H*DPR);ctx.setTransform(DPR,0,0,DPR,0,0);}

/* ===================== TRACK ===================== */
const T={};
function crPoint(p0,p1,p2,p3,t){
  const d=(p,q)=>Math.pow(Math.hypot(q[0]-p[0],q[1]-p[1]),.5)||1e-4;
  const t0=0,t1=t0+d(p0,p1),t2=t1+d(p1,p2),t3=t2+d(p2,p3),tt=t1+(t2-t1)*t;
  const mix=(p,q,ta,tb)=>{const f=(tt-ta)/(tb-ta);return p.map((v,i)=>v+(q[i]-v)*f);};
  const A1=mix(p0,p1,t0,t1),A2=mix(p1,p2,t1,t2),A3=mix(p2,p3,t2,t3);
  return mix(mix(A1,A2,t0,t2),mix(A2,A3,t1,t3),t1,t2);
}
const TRACKS=[
 {id:'easy',name:'Busway Sprint',tag:'Easy',difficulty:0,desc:'A short, extra-wide course with long straights and fewer turns.',width:30,scale:.78,raw:[[0,0,0],[190,0,0],[315,35,0],[385,125,0],[360,235,0],[255,305,0],[80,310,0],[-65,250,0],[-105,135,0],[-65,45,0]]},
 {id:'current',name:'LVA Assembly Circuit',tag:'Medium',difficulty:1,desc:'The original balanced factory-floor course with a wider racing surface.',width:26.4,scale:.8,raw:[[0,0,0],[150,0,0],[300,0,0],[400,40,0],[440,130,0],[400,210,0],[300,230,0],[230,290,0],[240,380,0],[160,430,0],[60,400,0],[40,320,0],[-40,280,0],[-120,330,0],[-200,290,0],[-200,190,0],[-120,140,0],[-100,60,0]]},
 {id:'hard',name:'Arcworks Overpass',tag:'Hard',difficulty:2,desc:'A wider figure-eight with a supported raised deck, open crossing, and Eaton service tunnel.',width:25.2,scale:1.05,tunnel:[.31,.45],overpass:true,raw:[[240,0,0],[222,-71,0],[170,-100,0],[92,-71,0],[0,0,0],[-92,71,0],[-170,100,0],[-222,71,0],[-240,0,0],[-222,-71,0],[-170,-100,1],[-92,-71,5],[0,0,9],[92,71,6],[170,100,2],[222,71,0]]},
 {id:'copper',name:'Copper Coil Run',tag:'Medium',difficulty:1,desc:'A wider night-shift route with sweeping bends, compressed switchbacks, and a decisive launch straight.',width:26.4,scale:.88,raw:[[0,0,0],[120,-20,0],[240,20,0],[310,100,0],[280,200,0],[200,270,0],[80,300,0],[-40,270,0],[-125,200,0],[-150,95,0],[-105,10,0],[-20,-35,0],[30,40,0],[70,105,0],[35,170,0],[-35,190,0],[-85,130,0],[-65,65,0]]},
 {id:'kitty',name:"Johannes's Kitty Corner",tag:'Hard',difficulty:2,desc:'The longest, most complicated route: twin lobes, tight reversals, an open raised crossing, five ramps, and seven boost zones.',width:24,scale:1.12,tunnel:[.84,.92],overpass:true,ramps:5,pads:7,raw:[[0,0,0],[73,96,0],[142,180,0],[205,239,0],[258,271,0],[301,277,0],[332,264,0],[352,241,0],[362,217,0],[364,198,0],[361,184,0],[355,171,0],[348,151,0],[344,116,0],[342,62,0],[344,-11,0],[348,-97,0],[355,-185,0],[361,-261,0],[364,-315,0],[362,-338,0],[352,-329,0],[332,-292,0],[301,-236,0],[258,-174,.7],[205,-116,3.3],[142,-68,5.9],[73,-30,8.4],[0,0,11],[-73,30,8.4],[-142,68,5.9],[-205,116,3.3],[-258,174,.7],[-301,236,0],[-332,292,0],[-352,329,0],[-362,338,0],[-364,315,0],[-361,261,0],[-355,185,0],[-348,97,0],[-344,11,0],[-342,-62,0],[-344,-116,0],[-348,-151,0],[-355,-171,0],[-361,-184,0],[-364,-198,0],[-362,-217,0],[-352,-241,0],[-332,-264,0],[-301,-277,0],[-258,-271,0],[-205,-239,0],[-142,-180,0],[-73,-96,0]]},
 {id:'arden',name:'Arden Plant Tour',tag:'Medium',difficulty:1,desc:'A gray plant-map route through every major Arden production area, from Lab and Steel Shop to Final, Test, and Shipping.',width:27,scale:.9,plantTour:true,ramps:4,pads:6,raw:[[-240,-120,0],[-155,-126,0],[-75,-124,0],[10,-122,0],[95,-122,0],[180,-118,0],[235,-92,0],[248,-40,0],[240,0,0],[235,35,0],[180,-25,0],[115,-45,0],[40,-55,0],[-40,-55,0],[-120,-55,0],[-248,-47,0],[-240,10,0],[-230,48,0],[-180,64,0],[-110,62,0],[-20,62,0],[60,62,0],[150,62,0],[225,75,0],[270,110,0],[245,145,0],[150,154,0],[40,156,0],[-70,154,0],[-170,150,0],[-245,138,0],[-278,104,0],[-282,35,0],[-278,-45,0],[-270,-95,0]]},

 // Copper Current Circuit · Easy · broad sight lines and forgiving radii.
 {id:'busbar-blvd',name:'Bus Bar Boulevard',tag:'Easy · Copper',desc:'A broad copper-fabrication oval built for clean lines and first-lap confidence.',circuit:'copper-current',difficulty:0,theme:'copper',width:33,scale:.82,ramps:2,pads:6,raw:[[0,-150,0],[115,-145,0],[210,-100,0],[265,-20,0],[250,78,0],[190,150,0],[90,190,0],[-30,188,0],[-140,150,0],[-220,78,0],[-242,-20,0],[-185,-105,0],[-88,-145,0]]},
 {id:'crossbus-carousel',name:'Crossbus Carousel',tag:'Easy · Copper',desc:'Long copper sweeps circle a crossbus staging island with generous recovery room.',circuit:'copper-current',difficulty:0,theme:'copper',width:32,scale:.86,ramps:2,pads:6,raw:[[-245,-80,0],[-155,-135,0],[-35,-145,0],[85,-125,0],[195,-75,0],[250,10,0],[235,105,0],[155,170,0],[35,195,0],[-85,180,0],[-190,125,0],[-245,40,0]]},
 {id:'panel-parkway',name:'Panel Parkway',tag:'Easy · Copper',desc:'A roomy panel-bank tour with three gentle rhythm changes and bright copper landmarks.',circuit:'copper-current',difficulty:0,theme:'copper',width:31,scale:.84,ramps:2,pads:7,raw:[[-255,-115,0],[-145,-150,0],[-25,-145,0],[85,-105,0],[190,-130,0],[255,-65,0],[260,25,0],[210,110,0],[115,155,0],[10,140,0],[-80,180,0],[-185,145,0],[-250,70,0]]},

 // Assembly Shift Circuit · Normal · balanced floor flow and active ramp timing.
 {id:'front-end-flow',name:'Front-End Flow',tag:'Normal · Assembly',desc:'Switchgear frames and workstations shape a balanced sequence of bends and launch zones.',circuit:'assembly-shift',difficulty:1,theme:'assembly',width:27,scale:.9,ramps:3,pads:5,raw:[[-245,-95,0],[-150,-140,0],[-35,-135,0],[70,-95,0],[170,-125,0],[245,-65,0],[252,25,0],[190,85,0],[105,70,0],[35,115,0],[-60,155,0],[-165,132,0],[-240,72,0],[-215,5,0],[-130,-25,0],[-42,-62,0],[48,-35,0],[140,-55,0]]},
 {id:'midline-momentum',name:'Midline Momentum',tag:'Normal · Assembly',desc:'Alternating midline switchbacks reward deliberate drifts without becoming a stoppage.',circuit:'assembly-shift',difficulty:1,theme:'assembly',width:25.5,scale:.92,ramps:3,pads:5,raw:[[0,-155,0],[105,-145,0],[195,-95,0],[238,-15,0],[205,70,0],[125,118,0],[55,92,0],[12,32,0],[-48,72,0],[-118,138,0],[-205,112,0],[-248,35,0],[-225,-52,0],[-158,-118,0],[-78,-98,0],[-28,-38,0]]},
 {id:'final-line-frenzy',name:'Final Line Frenzy',tag:'Normal · Assembly',desc:'A longer final-assembly route mixes sweepers, a late chicane, and four production ramps.',circuit:'assembly-shift',difficulty:1,theme:'assembly',width:25,scale:.92,ramps:4,pads:5,raw:[[-260,-112,0],[-155,-145,0],[-45,-132,0],[48,-82,0],[145,-120,0],[235,-78,0],[270,-5,0],[242,72,0],[170,125,0],[80,150,0],[-5,122,0],[-82,168,0],[-175,142,0],[-245,85,0],[-265,18,0],[-220,-42,0],[-145,-62,0],[-70,-20,0],[5,18,0],[82,-18,0],[162,-42,0]]},

 // Arc-Resistant Circuit · Hard · narrow technical layouts, elevation and low-visibility test-bay tone.
 {id:'breaker-blackout',name:'Breaker Blackout',tag:'Hard · Arc-Test',desc:'A narrow blackout route chains late-apex hairpins around breaker racks and live status lights.',circuit:'arc-resistant',difficulty:2,theme:'arc',width:23,scale:.96,ramps:4,pads:4,raw:[[0,-165,0],[95,-150,0],[178,-112,0],[235,-48,0],[242,28,0],[198,92,0],[125,116,0],[62,75,0],[18,18,0],[-35,58,0],[-92,125,0],[-175,118,0],[-238,60,0],[-252,-18,0],[-218,-88,0],[-148,-142,0],[-78,-118,0],[-40,-58,0]]},
 {id:'test-bay-tempest',name:'Test Bay Tempest',tag:'Hard · Arc-Test',desc:'An elevated test-bay figure eight adds an open crossing, service tunnel, and five pressure ramps.',circuit:'arc-resistant',difficulty:2,theme:'arc',width:22.5,scale:1.08,ramps:5,pads:5,tunnel:[.30,.43],overpass:true,raw:[[245,0,0],[225,-72,0],[168,-108,0],[90,-76,0],[0,0,0],[-90,76,0],[-168,108,0],[-225,72,0],[-245,0,0],[-225,-72,0],[-168,-108,1],[-90,-76,5],[0,0,10],[90,76,6],[168,108,2],[225,72,0]]},
 {id:'arc-vault-apex',name:'Arc Vault Apex',tag:'Hard · Arc-Test',desc:'The circuit boss: twin vaults, a raised central strike zone, five ramps, and almost no free recovery.',circuit:'arc-resistant',difficulty:2,theme:'arc',width:21.5,scale:1.04,ramps:5,pads:6,tunnel:[.79,.9],overpass:true,raw:[[0,-8,10],[70,-42,7],[140,-92,3],[205,-150,0],[255,-205,0],[285,-245,0],[278,-275,0],[245,-286,0],[192,-260,0],[128,-210,0],[65,-145,0],[0,-78,0],[-65,-145,0],[-128,-210,0],[-192,-260,0],[-245,-286,0],[-278,-275,0],[-285,-245,0],[-255,-205,0],[-205,-150,0],[-140,-92,3],[-70,-42,7],[0,8,10],[70,42,7],[140,92,3],[205,150,0],[255,205,0],[285,245,0],[278,275,0],[245,286,0],[192,260,0],[128,210,0],[65,145,0],[0,78,0],[-65,145,0],[-128,210,0],[-192,260,0],[-245,286,0],[-278,275,0],[-285,245,0],[-255,205,0],[-205,150,0],[-140,92,3],[-70,42,7]]}
];
const CIRCUITS=[
 {id:'copper-current',name:'Copper Current Circuit',short:'COPPER CURRENT',difficulty:0,theme:'copper',feel:'Bright copper fabrication · wide lanes · gentle radii',trackIds:['busbar-blvd','crossbus-carousel','panel-parkway']},
 {id:'assembly-shift',name:'Assembly Shift Circuit',short:'ASSEMBLY SHIFT',difficulty:1,theme:'assembly',feel:'Eaton-blue assembly floor · balanced chicanes · active ramps',trackIds:['front-end-flow','midline-momentum','final-line-frenzy']},
 {id:'arc-resistant',name:'Arc-Resistant Circuit',short:'ARC-RESISTANT',difficulty:2,theme:'arc',feel:'Dark test bay · narrow technical lines · elevated crossings',trackIds:['breaker-blackout','test-bay-tempest','arc-vault-apex']}
];
const TRACK_THEMES={
 default:{skyTop:'#9fb4bf',skyMid:'#dce7ec',skyBottom:'#eef3f5',grid:'#294c5e',tileA:'#bfcacf',tileB:'#c8d2d6',edgeA:'#71848d',edgeB:'#3e4c53',edgeC:'#637780',edgeD:'#344249',roadA:'#4b626d',roadB:'#526975',lane:'rgba(255,255,255,.55)',edge:'#f2c500',curbA:'#f2c500',curbB:'#213746',curbSideA:'#a38400',curbSideB:'#172832',accent:'#075aa8',cabinet:'#e9edf0'},
 copper:{skyTop:'#8d7059',skyMid:'#d8b58e',skyBottom:'#f5e8d5',grid:'#7d4b27',tileA:'#b58b67',tileB:'#c49a73',edgeA:'#80583d',edgeB:'#4c3426',edgeC:'#714a34',edgeD:'#3b2921',roadA:'#594f49',roadB:'#625750',lane:'rgba(255,243,218,.68)',edge:'#e88935',curbA:'#d87a2c',curbB:'#f2c500',curbSideA:'#8d4618',curbSideB:'#8a6e00',accent:'#c76824',cabinet:'#ead8c7'},
 assembly:{skyTop:'#7da7bf',skyMid:'#d7e8f0',skyBottom:'#f4f8fa',grid:'#0067c6',tileA:'#bacad1',tileB:'#c9d6dc',edgeA:'#5f7d8c',edgeB:'#304955',edgeC:'#526e7b',edgeD:'#273e49',roadA:'#405b69',roadB:'#496675',lane:'rgba(255,255,255,.68)',edge:'#f2c500',curbA:'#0067c6',curbB:'#f2c500',curbSideA:'#003f7d',curbSideB:'#8a7200',accent:'#0067c6',cabinet:'#e4edf1'},
 arc:{skyTop:'#07111f',skyMid:'#132b45',skyBottom:'#294b63',grid:'#00b7ff',tileA:'#263b4c',tileB:'#2d465a',edgeA:'#1b2f40',edgeB:'#08131f',edgeC:'#17293a',edgeD:'#050d16',roadA:'#1d2b38',roadB:'#263847',lane:'rgba(115,220,255,.75)',edge:'#f58220',curbA:'#f58220',curbB:'#0067c6',curbSideA:'#873a08',curbSideB:'#00345f',accent:'#00a8e8',cabinet:'#8fa4af'}
};
function circuitForTrack(id){return CIRCUITS.find(c=>c.trackIds.includes(id))||null;}
const TRACK_WIDTH_MULT=1.10,ASSET_SCALE=.50;
function trackDifficulty(t=trackDef(SV?.track)){return clamp(Number.isFinite(t?.difficulty)?t.difficulty:1,0,2);}
function trackTheme(){return TRACK_THEMES[T.def?.theme]||TRACK_THEMES.default;}
const ARDEN_AREAS=[
 {label:'LAB',x:-225,y:-112,w:38,h:28},{label:'PAINT',x:-174,y:-112,w:54,h:28},{label:'WELD',x:-116,y:-112,w:44,h:28},{label:'STEEL SHOP',x:-45,y:-112,w:82,h:28},{label:'COPPER',x:28,y:-112,w:45,h:28},{label:'TRANSFORMERS',x:132,y:-110,w:112,h:32},
 {label:'OFFICE',x:-224,y:-42,w:46,h:48},{label:'LVA',x:-135,y:-50,w:122,h:62},{label:'MVD',x:-34,y:-50,w:70,h:62},{label:'DRIVES',x:35,y:-50,w:64,h:62},{label:'AIS',x:88,y:-38,w:28,h:82},{label:'WAREHOUSE',x:132,y:-28,w:66,h:72},
 {label:'INNOV',x:210,y:-72,w:34,h:30},{label:'FAB',x:210,y:-36,w:34,h:26},{label:'FAST',x:210,y:-3,w:34,h:26},{label:'REC',x:210,y:30,w:34,h:26},
 {label:'HR',x:-206,y:42,w:30,h:28},{label:'CAFE',x:-162,y:58,w:38,h:28},{label:'MVC',x:-99,y:50,w:92,h:52},{label:'SHIPPING',x:-10,y:56,w:54,h:48},{label:'DRIVES TEST',x:54,y:56,w:68,h:48},{label:'OEM / B-MOD',x:135,y:56,w:80,h:48}
];
function nearestArdenArea(p){let best=ARDEN_AREAS[0],d=1e18;for(const a of ARDEN_AREAS){const q=(p.x-a.x)*(p.x-a.x)+(p.y-a.y)*(p.y-a.y);if(q<d){d=q;best=a;}}return best;}
function trackDef(id){return TRACKS.find(t=>t.id===id)||TRACKS[0];}
function findTrackCrossings(X,Y,Wd,ds){
  const N=X.length,out=new Uint8Array(N),cross=(ax,ay,bx,by)=>ax*by-ay*bx;
  for(let i=0;i<N;i++){
    const i2=(i+1)%N,rix=X[i2]-X[i],riy=Y[i2]-Y[i],ril=Math.hypot(rix,riy)||1;
    for(let j=i+18;j<N;j++){
      const sep=Math.min(j-i,N-(j-i));if(sep<18)continue;
      const j2=(j+1)%N,rsx=X[j2]-X[j],rsy=Y[j2]-Y[j],rsl=Math.hypot(rsx,rsy)||1,den=cross(rix,riy,rsx,rsy);
      if(Math.abs(den)<.001||Math.abs(den)/(ril*rsl)<.3)continue;
      const qx=X[j]-X[i],qy=Y[j]-Y[i],a=cross(qx,qy,rsx,rsy)/den,b=cross(qx,qy,rix,riy)/den;
      if(a<-.01||a>1.01||b<-.01||b>1.01)continue;
      const rad=Math.ceil((Math.max(Wd[i],Wd[j])*.7+4)/ds);
      for(let k=-rad;k<=rad;k++){out[(i+k+N)%N]=1;out[(j+k+N)%N]=1;}
    }
  }
  return out;
}
function buildTrack(id){
  const def=trackDef(id||'easy'),SC=def.scale;
  const raw=def.raw.map(p=>[p[0]*SC,p[1]*SC,(p[2]||0)]),dense=[],n=raw.length;
  for(let i=0;i<n;i++){const p0=raw[(i+n-1)%n],p1=raw[i],p2=raw[(i+1)%n],p3=raw[(i+2)%n];for(let k=0;k<24;k++)dense.push(crPoint(p0,p1,p2,p3,k/24));}
  const m=dense.length,cum=[0];
  for(let i=1;i<=m;i++){const a=dense[i-1],b=dense[i%m];cum.push(cum[i-1]+Math.hypot(b[0]-a[0],b[1]-a[1]));}
  const Ld=cum[m],N=Math.round(Ld/2),ds=Ld/N;
  const X=new Float32Array(N),Y=new Float32Array(N),Z=new Float32Array(N);
  let seg=0;
  for(let j=0;j<N;j++){const tg=j*ds;while(cum[seg+1]<tg)seg++;const f=(tg-cum[seg])/(cum[seg+1]-cum[seg]||1),a=dense[seg],b=dense[(seg+1)%m];X[j]=a[0]+(b[0]-a[0])*f;Y[j]=a[1]+(b[1]-a[1])*f;Z[j]=Math.max(0,(a[2]||0)+((b[2]||0)-(a[2]||0))*f);}
  const TX=new Float32Array(N),TY=new Float32Array(N),NX=new Float32Array(N),NY=new Float32Array(N),S=new Float32Array(N),Wd=new Float32Array(N),K=new Float32Array(N),KA=new Float32Array(N),ang=new Float32Array(N);
  for(let j=0;j<N;j++){
    const a=(j+N-2)%N,b=(j+2)%N;let dx=X[b]-X[a],dy=Y[b]-Y[a];const l=Math.hypot(dx,dy)||1;dx/=l;dy/=l;
    TX[j]=dx;TY[j]=dy;NX[j]=-dy;NY[j]=dx;S[j]=j*ds;ang[j]=Math.atan2(dy,dx);Wd[j]=def.width*TRACK_WIDTH_MULT+1.6*Math.sin(j/N*TAU*5+1);
  }
  for(let j=0;j<N;j++)K[j]=angDiff(ang[(j+N-3)%N],ang[(j+3)%N])/(6*ds);
  for(let j=0;j<N;j++){let q=0;for(let k=-15;k<=15;k++)q+=Math.abs(K[(j+k+N)%N]);KA[j]=q/31;}
  const LX=new Float32Array(N),LY=new Float32Array(N),RX=new Float32Array(N),RY=new Float32Array(N);
  for(let j=0;j<N;j++){LX[j]=X[j]-NX[j]*Wd[j]/2;LY[j]=Y[j]-NY[j]*Wd[j]/2;RX[j]=X[j]+NX[j]*Wd[j]/2;RY[j]=Y[j]+NY[j]*Wd[j]/2;}
  const cross=findTrackCrossings(X,Y,Wd,ds);
  Object.assign(T,{N,ds,L:N*ds,x:X,y:Y,z:Z,tx:TX,ty:TY,nx:NX,ny:NY,S,w:Wd,k:K,ka:KA,ang,lx:LX,ly:LY,rx:RX,ry:RY,cross,def});
  let minx=1e9,maxx=-1e9,miny=1e9,maxy=-1e9;for(let j=0;j<N;j++){minx=Math.min(minx,X[j]);maxx=Math.max(maxx,X[j]);miny=Math.min(miny,Y[j]);maxy=Math.max(maxy,Y[j]);}
  T.bb=[minx,miny,maxx,maxy];mmB=null;
}
function trkAt(s,lat){
  const L=T.L;s=((s%L)+L)%L;const f=s/T.ds,fi=Math.floor(f),i=fi%T.N,j=(i+1)%T.N,u=f-fi;
  const x=lerp(T.x[i],T.x[j],u),y=lerp(T.y[i],T.y[j],u);
  let tx=lerp(T.tx[i],T.tx[j],u),ty=lerp(T.ty[i],T.ty[j],u);const l=Math.hypot(tx,ty)||1;tx/=l;ty/=l;
  const A=trkAt;A.tx=tx;A.ty=ty;A.nx=-ty;A.ny=tx;A.w=lerp(T.w[i],T.w[j],u);A.x=x+A.nx*(lat||0);A.y=y+A.ny*(lat||0);A.z=lerp(T.z[i],T.z[j],u);A.cx=x;A.cy=y;A.i=i;
}
const Q={i:0,s:0,lat:0,along:0,w:20};
function trkQuery(x,y,hint){
  const N=T.N;let best=1e18,bi=0;
  if(hint<0){for(let i=0;i<N;i++){const dx=x-T.x[i],dy=y-T.y[i],d=dx*dx+dy*dy;if(d<best){best=d;bi=i;}}}
  else for(let k=-30;k<=30;k++){const i=(hint+k+N)%N,dx=x-T.x[i],dy=y-T.y[i],d=dx*dx+dy*dy;if(d<best){best=d;bi=i;}}
  const dx=x-T.x[bi],dy=y-T.y[bi];
  Q.i=bi;Q.along=dx*T.tx[bi]+dy*T.ty[bi];Q.lat=dx*T.nx[bi]+dy*T.ny[bi];Q.s=((T.S[bi]+Q.along)%T.L+T.L)%T.L;Q.w=T.w[bi];
}
const wrapD=(a,L)=>{let d=a%L;if(d>L/2)d-=L;if(d<-L/2)d+=L;return d;};

/* ---------- track features ---------- */
const FEAT={ramps:[],pads:[],boxes:[],tiles:[],tileMap:new Map(),scenery:[],assetProps:[],gantryS:0,tunnel:null};
const TRAIN={xmin:-210,xmax:210,ymin:-150,ymax:150,obstacles:[],assets:[],ramps:[],pads:[],boxes:[],testTrack:[],seed:0};
function buildTrainingGround(){
  TRAIN.seed=(Math.random()*1e9)|0;TRAIN.obstacles=[];TRAIN.assets=[];TRAIN.ramps=[];TRAIN.pads=[];TRAIN.boxes=[];
  TRAIN.testTrack=[[-160,-74],[-80,-112],[35,-112],[128,-72],[165,0],[132,74],[48,112],[-55,105],[-132,64],[-168,0]];
  const segDist=(p,a,b)=>{const vx=b[0]-a[0],vy=b[1]-a[1],d=vx*vx+vy*vy||1,t=clamp(((p.x-a[0])*vx+(p.y-a[1])*vy)/d,0,1);return Math.hypot(p.x-(a[0]+vx*t),p.y-(a[1]+vy*t));};
  const clearTrack=(p,r)=>TRAIN.testTrack.every((a,i)=>segDist(p,a,TRAIN.testTrack[(i+1)%TRAIN.testTrack.length])>r+14);
  const occupied=[{x:0,y:0,r:18}];
  const place=(r,edge=10)=>{for(let q=0;q<260;q++){const p={x:rnd(TRAIN.xmin+edge,TRAIN.xmax-edge),y:rnd(TRAIN.ymin+edge,TRAIN.ymax-edge),r};if(clearTrack(p,r)&&occupied.every(o=>Math.hypot(p.x-o.x,p.y-o.y)>p.r+o.r+5)){occupied.push(p);return p;}}return{x:rnd(-190,190),y:rnd(-130,130),r};};
  const kinds=['switchgear','breaker','tool','line','panel','wire','cart','quality'];
  for(let i=0;i<4;i++){const kind=kinds[i],rad=kind==='line'?8:kind==='switchgear'?5:kind==='tool'?4:3.5,p=place(rad);TRAIN.obstacles.push({x:p.x,y:p.y,r:rad,kind,rot:pick([0,Math.PI/2]),sz:rnd(.8,1.25),hue:Math.random()});}
  for(let i=0;i<5;i++){const p=place(8),rot=pick([0,Math.PI/2,Math.PI,Math.PI*1.5]);TRAIN.ramps.push({x:p.x,y:p.y,rot,w:rnd(9,13),len:rnd(10,15),vz:rnd(12,18)});}
  for(let i=0;i<6;i++){const p=place(5);TRAIN.pads.push({x:p.x,y:p.y,rot:pick([0,Math.PI/2,Math.PI,Math.PI*1.5]),w:8,len:8});}
  for(let i=0;i<20;i++){const p=place(2.5,6);TRAIN.boxes.push({x:p.x,y:p.y,s:rnd(0,100),t:0});}
  TRAIN.assets=[
   {asset:'panel_bank_tile',x:-168,y:-144,w:76,backdrop:true},{asset:'panel_bank_tile',x:-84,y:-144,w:76,backdrop:true},{asset:'panel_bank_tile',x:0,y:-144,w:76,backdrop:true},{asset:'panel_bank_tile',x:84,y:-144,w:76,backdrop:true},{asset:'panel_bank_tile',x:168,y:-144,w:76,backdrop:true},
   {asset:'switchgear_lineup_front',x:-176,y:132,w:34,r:9},{asset:'arc_resistant_lineup_perspective',x:-105,y:132,w:32,r:8},{asset:'control_station',x:-38,y:132,w:19,r:5},{asset:'switchboard_obstacle',x:28,y:132,w:20,r:6},{asset:'magnum_breaker',x:84,y:132,w:14,r:4},{asset:'breaker_pickup',x:130,y:132,w:11,r:3},{asset:'panel_hazard_gate',x:182,y:128,w:24,r:7}
  ];
  for(const q of TRAIN.assets)if(q.r)TRAIN.obstacles.push({x:q.x,y:q.y,r:q.r*ASSET_SCALE,kind:'lvaAsset',asset:q.asset,w:q.w});
}

function buildFeatures(){
  const N=T.N,L=T.L;FEAT.tunnel=T.def.tunnel?{start:T.def.tunnel[0]*L,end:T.def.tunnel[1]*L}:null;
  // ramps: lowest-curvature spots, spaced apart, away from start
  const cand=[];for(let j=0;j<N;j++){if(j>N-40||j<30)continue;cand.push(j);}
  cand.sort((a,b)=>T.ka[a]-T.ka[b]);
  const chosen=[],rampGoal=T.def.ramps||3,rampGap=rampGoal>3?.14:.2;
  for(const j of cand){if(chosen.length>=rampGoal)break;if(chosen.every(c=>Math.min(Math.abs(c-j),N-Math.abs(c-j))>N*rampGap))chosen.push(j);}
  chosen.sort((a,b)=>a-b);
  const sizes=[3,4,2];
  FEAT.ramps=chosen.map((j,i)=>({s:T.S[j],lat:0,w:Math.min(13,T.w[j]-5),len:9,n:sizes[i%3],vz:[15,17.5,12.5][i%3]}));
  const nearRamp=s=>FEAT.ramps.some(r=>Math.abs(wrapD(s-r.s,L))<28);
  // boost pads: shortly after tight corners
  const pads=[];
  for(let j=0;j<N;j++){
    const a=T.ka[j],b=T.ka[(j+1)%N],c=T.ka[(j+N-1)%N];
    if(a>.011&&a>=b&&a>=c){
      let s=T.S[j]+55;
      if(!nearRamp(s)&&pads.every(p=>Math.abs(wrapD(s-p.s,L))>150))pads.push({s,lat:0,w:10,len:8});
    }
  }
  const padGoal=T.def.pads||5;
  if(T.def.pads)for(let q=0;pads.length<padGoal&&q<padGoal*5;q++){
    const s=((q+1)/(padGoal+1)*L+37)%L;
    if(!nearRamp(s)&&pads.every(p=>Math.abs(wrapD(s-p.s,L))>Math.min(120,L/(padGoal*2.2))))pads.push({s,lat:0,w:10,len:8});
  }
  FEAT.pads=pads.slice(0,padGoal);
  // item boxes
  const fr=[.19,.37,.57,.76,.93];
  FEAT.boxes=[];
  for(const f of fr){
    let s=f*L;if(nearRamp(s))s+=34;
    for(const lat of[-6,0,6]){trkAt(s,lat);FEAT.boxes.push({s,lat,x:trkAt.x,y:trkAt.y,z:trkAt.z,t:0});}
  }
  FEAT.gantryS=0;
  // island tiles + scenery
  const TS=10,bb=T.bb,tm=FEAT.tileMap;tm.clear();FEAT.tiles=[];
  const i0=Math.floor((bb[0]-120)/TS),i1=Math.ceil((bb[2]+120)/TS),j0=Math.floor((bb[1]-120)/TS),j1=Math.ceil((bb[3]+120)/TS);
  const roadSampleStep=N>1200?6:3;
  for(let i=i0;i<=i1;i++)for(let j=j0;j<=j1;j++){
    const cx=(i+.5)*TS,cy=(j+.5)*TS;let best=1e18;
    for(let k=0;k<N;k+=roadSampleStep){const dx=cx-T.x[k],dy=cy-T.y[k],d=dx*dx+dy*dy;if(d<best)best=d;}
    const d=Math.sqrt(best);
    if(d<72){const t={i,j,x:cx,y:cy,c:(i+j)&1,d};tm.set(i*4096+j,t);FEAT.tiles.push(t);}
  }
  for(const t of FEAT.tiles){t.nx=!tm.has((t.i+1)*4096+t.j);t.ny=!tm.has(t.i*4096+t.j+1);}
  FEAT.tiles.sort((a,b)=>(a.i+a.j)-(b.i+b.j));
  FEAT.scenery=[];FEAT.assetProps=[];
  if(T.def.plantTour){
    const plantAssets=['switchgear_lineup_front','arc_resistant_lineup_perspective','magnum_breaker','control_station','switchboard_obstacle','breaker_pickup','panel_hazard_gate'];
    ARDEN_AREAS.forEach((a,i)=>FEAT.assetProps.push({asset:plantAssets[i%plantAssets.length],x:a.x+(i%2?5:-5),y:a.y+(i%3-1)*4,w:30+(i%4)*4}));
    return;
  }
  for(const t of FEAT.tiles){
    if(t.d<T.w[0]/2+10)continue;
    const r=hash2(t.i,t.j,31);
    if(r<.3){
      const x=t.x+(hash2(t.i,t.j,32)-.5)*7,y=t.y+(hash2(t.i,t.j,33)-.5)*7;
      trkQuery(x,y,-1);const dx=x-T.x[Q.i],dy=y-T.y[Q.i];if(Math.hypot(dx,dy)<T.w[Q.i]/2+9)continue;
      const u=hash2(t.i,t.j,36),mix=T.def.theme==='copper'?['busbar','wire','cart','busbar','panel','wire','workbench','safety']:T.def.theme==='assembly'?['switchgear','panel','workbench','cart','breakerRack','panel','switchgear','safety']:T.def?.theme==='arc'?['breakerRack','switchgear','safety','breakerRack','panel','wire','switchgear','safety']:['switchgear','panel','breakerRack','wire','busbar','workbench','cart','safety'],kind=mix[Math.min(mix.length-1,Math.floor(u*mix.length))];
      FEAT.scenery.push({x,y,kind,sz:.8+hash2(t.i,t.j,34)*.7,hue:hash2(t.i,t.j,35),rot:pick([0,Math.PI/2])});
    }
  }
  const trackAssets=['switchgear_lineup_front','arc_resistant_lineup_perspective','magnum_breaker','control_station','switchboard_obstacle','panel_bank_tile','breaker_pickup','panel_hazard_gate'];
  FEAT.assetProps=FEAT.scenery.map((o,i)=>({asset:trackAssets[i%trackAssets.length],x:o.x,y:o.y,w:28+(i%5)*4}));
  FEAT.scenery=[];
}

/* ===================== DATA ===================== */
const CHARS=[
 {id:0,name:'DJ',role:'Front-End Super',hair:'#5b4636',hair2:'#3a2a22',outfit:'#4c9a62',accent:'#d8efff',style:'short',eye:'#47677a',skin:'#f0c8a8',mackey:true,base:{acc:2,spd:4,trn:2,drf:2}},
  {id:1,name:'BC',role:'Cell Phone Specialist',hair:'#5b2b20',hair2:'#31150f',outfit:'#db1832',accent:'#ffffff',style:'koolaid',eye:'#32160f',skin:'#efb18d',koolaid:true,base:{acc:2,spd:2,trn:2,drf:2}},
  {id:2,name:'TJ',role:'Chief of Cigars',hair:'#17120f',hair2:'#080706',outfit:'#111820',accent:'#f2c500',style:'manager',eye:'#21140d',skin:'#70472f',jenkins:true,base:{acc:2,spd:2,trn:4,drf:2}},
  {id:3,name:'DB',role:'Lead Golfer',hair:'#4b2f23',hair2:'#241711',outfit:'#1769aa',accent:'#8fd7ff',style:'golf',eye:'#324b63',skin:'#f1c7aa',dallas:true,base:{acc:3,spd:3,trn:3,drf:3}},
  {id:4,name:'CC',role:'Quality Queen',hair:'#f1cf58',hair2:'#c69b2c',outfit:'#f2f6fb',accent:'#2d67a3',style:'quality',eye:'#5b7890',skin:'#f1c7aa',cassandra:true,base:{acc:2,spd:2,trn:4,drf:2}},
  {id:5,name:'RR',role:'Rotator',hair:'#b74224',hair2:'#762415',outfit:'#0b6b3a',accent:'#f2c500',style:'rotator',eye:'#50708a',skin:'#edc1a3',ryan:true,base:{acc:3,spd:2,trn:2,drf:3}},
  {id:6,name:'JG',role:'Wire Queen',hair:'#5a2e20',hair2:'#32170f',outfit:'#704329',accent:'#4b2b1d',style:'bun',eye:'#4c3428',skin:'#f0c7aa',jg:true,safetyGlasses:true,base:{acc:3,spd:3,trn:2,drf:2}},
  {id:7,name:'JW',role:'Final Micro-Manager',hair:'#15110f',hair2:'#090807',outfit:'#4d6940',accent:'#d5a84c',style:'slick',eye:'#32231a',skin:'#c98f67',jw:true,base:{acc:2,spd:3,trn:3,drf:2}},
  {id:8,name:'RM',role:'Midline Big Brother',hair:'#17120f',hair2:'#080706',outfit:'#111820',accent:'#2d6ca3',style:'ranger',eye:'#24180f',skin:'#6b4434',rm:true,base:{acc:2,spd:1,trn:3,drf:3}},
  {id:9,name:'CB',role:'Lead Shooter',hair:'#111820',hair2:'#05090d',outfit:'#174f86',accent:'#0d1822',style:'plaid',eye:'#201710',skin:'#efd0b5',cb:true,base:{acc:3,spd:2,trn:3,drf:2}},
  {id:10,name:'SB',role:'Water Hazard Spider',hair:'#4b5056',hair2:'#20252a',outfit:'#83c9ed',accent:'#d7f0ff',style:'golf-pro',eye:'#201710',skin:'#b77855',sb:true,base:{acc:2,spd:3,trn:2,drf:3}},
  {id:11,name:'GZ',role:'Warehouse Wizard',hair:'#111820',hair2:'#05090d',outfit:'#123d70',accent:'#70b7ee',style:'long-curls',eye:'#2b1a12',skin:'#c98f67',gz:true,base:{acc:2,spd:3,trn:3,drf:2}},
  {id:12,name:'XE',role:'Seaman Swimmer',hair:'#111820',hair2:'#05090d',outfit:'#111820',accent:'#2d6ca3',style:'afro',eye:'#24180f',skin:'#633f31',xe:true,base:{acc:3,spd:2,trn:2,drf:3}},
  {id:13,name:'RB',role:'Pom Pom Patriot',hair:'#111820',hair2:'#05090d',outfit:'#f4f5f7',accent:'#c52233',style:'short-black',eye:'#24180f',skin:'#57372b',rb:true,base:{acc:2,spd:3,trn:3,drf:2}},
  {id:14,name:'PB',role:'Pride Pioneer',hair:'#704329',hair2:'#704329',outfit:'#c79ad8',accent:'#744a82',style:'long-purple-brown',eye:'#3b291f',skin:'#edc3a6',pb:true,base:{acc:2,spd:2,trn:3,drf:3}},
];
const CUSTOM_CHARS=[3,5,0,2,7,8,6,4,1,9,10,11,12,13,14].map(id=>CHARS.find(c=>c.id===id));
const BOARDS=[
 {id:'starter',name:'Bus Bar Basic',color:'#1686c4',bonus:{acc:0,spd:0,trn:0,drf:0},cost:0,note:'Standard LVA transport'},
 {id:'flare',name:'Arc Runner',color:'#f28c28',bonus:{acc:0,spd:1,trn:0,drf:0},cost:400,note:'Quick off the assembly line'},
 {id:'aero',name:'Quencher Q2',color:'#19a974',bonus:{acc:1,spd:0,trn:1,drf:0},cost:1000,note:'Balanced and insulated'},
 {id:'nova',name:'Breaker XL',color:'#f2c500',bonus:{acc:0,spd:2,trn:0,drf:0},cost:1000,note:'High-current top speed'},
 {id:'vector',name:'Shift Vector',color:'#7c5cff',bonus:{acc:0,spd:0,trn:1,drf:2},cost:2200,note:'Links long controlled drifts'},
 {id:'rotator',name:'Rotator R-6',color:'#d94c3d',bonus:{acc:1,spd:0,trn:0,drf:2},cost:2200,note:'Redline rotation package'},
 {id:'fairway',name:'Fairway Flux',color:'#2a8fc9',bonus:{acc:1,spd:1,trn:0,drf:2},cost:3800,note:'Blue course-control vehicle'},
 {id:'pride',name:'Eaton Pride Board',color:'#0067c6',bonus:{acc:0,spd:0,trn:0,drf:0},cost:1500,reward:.1,set:'pride',pride:true,note:'White E · +0.1 additive XP and E-Star reward bonus'},
 {id:'gold',name:'The Golden Board',color:'#f6c928',bonus:{acc:0,spd:0,trn:0,drf:0},cost:6000,golden:true,set:'holy',note:'Glowing flagship with golden dust'},
];
const HATS=[
 {id:'acc',name:'Quick-Start Bump Cap',color:'#f28c28',bonus:{acc:1,spd:0,trn:0,drf:0},cost:500,note:'+1 Acceleration'},
 {id:'spd',name:'Power-Line Bump Cap',color:'#d94c3d',bonus:{acc:0,spd:1,trn:0,drf:0},cost:650,note:'+1 Top speed'},
 {id:'trn',name:'Pivot-Pro Bump Cap',color:'#1686c4',bonus:{acc:0,spd:0,trn:1,drf:0},cost:650,note:'+1 Turning'},
 {id:'drf',name:'Drift-Line Bump Cap',color:'#7c5cff',bonus:{acc:0,spd:0,trn:0,drf:1},cost:750,note:'+1 Drift skill'},
 {id:'acc2',name:'Quick-Start Bump Cap +2',color:'#ff9b3d',bonus:{acc:2,spd:0,trn:0,drf:0},cost:400,note:'+2 Acceleration · 80% of +1 counterpart price'},
 {id:'spd2',name:'Power-Line Bump Cap +2',color:'#ef5f50',bonus:{acc:0,spd:2,trn:0,drf:0},cost:520,note:'+2 Top speed · 80% of +1 counterpart price'},
 {id:'trn2',name:'Pivot-Pro Bump Cap +2',color:'#38a8e0',bonus:{acc:0,spd:0,trn:2,drf:0},cost:520,note:'+2 Turning · 80% of +1 counterpart price'},
 {id:'drf2',name:'Drift-Line Bump Cap +2',color:'#9a82ff',bonus:{acc:0,spd:0,trn:0,drf:2},cost:600,note:'+2 Drift skill · 80% of +1 counterpart price'},
 {id:'pride',name:'Eaton Pride Bump Cap',color:'#0067c6',bonus:{acc:0,spd:0,trn:0,drf:0},cost:1500,reward:.1,set:'pride',pride:true,note:'White E · +0.1 additive XP and E-Star reward bonus'},
 {id:'gold',name:'The Golden Bump Cap',color:'#f6c928',bonus:{acc:0,spd:0,trn:0,drf:0},cost:6000,golden:true,set:'holy',deepPockets:true,note:'Deep Pockets Trait · unlocks a second pickup slot'},
];
const STAT_NAMES={acc:'Acceleration',spd:'Top speed',trn:'Turning',drf:'Drift skill'};
const STAT_KEYS=['acc','spd','trn','drf'];
const STAT_MAX=20;
const BASE_COMBO_KEYS=[2,3,4];
function boardStatTotal(b){return STAT_KEYS.reduce((n,k)=>n+(b.bonus[k]||0),0);}
function equipmentIds(r){return{board:r?r.boardId:SV.board,hat:r?r.hatId:SV.hat};}
function prideSetActive(r){const e=equipmentIds(r);return e.board==='pride'&&e.hat==='pride';}
function holySetActive(r){const e=equipmentIds(r);return e.board==='gold'&&e.hat==='gold';}
function invincibleStateActive(r){return!!r&&(r.invincibleT>0||holySetActive(r));}
function deepPocketsActive(r){const e=equipmentIds(r);return e.hat==='gold';}
function equipmentRewardBonus(){const b=boardOf(SV.board),h=hatOf(SV.hat);return(b.reward||0)+(h?.reward||0)+(prideSetActive()?.3:0);}
function rewardBreakdown(){return{game:DIFFS[SV.diff].reward,track:DIFFS[trackDifficulty(T.def)].reward,gear:equipmentRewardBonus()};}
function jumpComboKeys(){return BASE_COMBO_KEYS[SV.diff];}
const DRIFT_METER_MAX=120;
const DRIFT_FORWARD_SPEED_MULT=1.07;
const DRIFT_FORWARD_ACCEL_MULT=1.04;
const DRIFT_FORWARD_BOOST_SECONDS=1;
const DRIFT_TIGHTEN_RAMP_SECONDS=2.4;
const DRIFT_TIGHTEN_MIN_TURN=.56;
const DRIFT_TIGHTEN_MAX_TURN=1.28;
const KART_DRIFT_BLUE_FLICKS=2;
const KART_DRIFT_ORANGE_FLICKS=4;
const KART_DRIFT_BLUE_BOOST=.8;
const KART_DRIFT_ORANGE_BOOST=1.35;
const TRANSITION_SECONDS=.3;
const STANDARD_BOOST_SECONDS=2.3;
const BROWN_NOSE_SECONDS=STANDARD_BOOST_SECONDS*3;
const MAX_ESTAR_BANK=999999;
const EMPLOYEE_STAT_RESET_COST=500;
const STAT_POINT_COST=1000;
const DEFAULT_INITIAL_DRIFT_ANGLE=22;
const DEFAULT_BUNNY_HOP_PERCENT=15;
const DIFFS=[{n:'Easy',m:.92,reward:0},{n:'Medium',m:1,reward:.1},{n:'Hard',m:1.08,reward:.2}];
function raceRewardMultiplier(){const b=rewardBreakdown();return 1+b.game+b.track+b.gear;}
function lapRewardMultiplier(laps=(G.laps||SV.laps)){return laps===1?.5:laps===5?1.5:1;}
function initialDriftAngleDeg(){return clamp(SV.initialDriftAngle==null?DEFAULT_INITIAL_DRIFT_ANGLE:+SV.initialDriftAngle,1,90);}
function initialDriftAngleRad(){return initialDriftAngleDeg()*Math.PI/180;}
function bunnyHopPercent(){return clamp(Math.round(SV.bunnyHopTimer==null?DEFAULT_BUNNY_HOP_PERCENT:+SV.bunnyHopTimer),0,100);}
function bunnyHopSeconds(){return bunnyHopPercent()/100;}
const AI_NAMES=CHARS.map(c=>c.name);

/* ===================== SAVE ===================== */
const SAVE_KEY='low-voltage-ascenders-v3.0';
const V22_SAVE_KEY='low-voltage-ascenders-v2.2';
const V21_SAVE_KEY='low-voltage-ascenders-v2.1';
const V20_SAVE_KEY='low-voltage-ascenders-v2.0';
const V19_SAVE_KEY='low-voltage-ascenders-v1.9';
const V18_SAVE_KEY='low-voltage-ascenders-v1.8';
const V17_SAVE_KEY='low-voltage-ascenders-v1.7';
const V16_SAVE_KEY='low-voltage-ascenders-v1.6';
const V15_SAVE_KEY='low-voltage-ascenders-v1.5';
const V14_SAVE_KEY='low-voltage-ascenders-v1.4';
const V13_SAVE_KEY='low-voltage-ascenders-v1.3';
const V12_SAVE_KEY='low-voltage-ascenders-v1.2';
const LEGACY_SAVE_KEY='hoverboard-asdf-recreation-v1';
const PROFILE_INDEX_KEY='low-voltage-ascenders-profiles-v3';
const PROFILE_ACTIVE_KEY='low-voltage-ascenders-active-profile-v3';
const PROFILE_PREFIX='low-voltage-ascenders-profile-v3:';
const PROFILE_PROVIDER={id:'portable-local-v1',canCloudSync:false,registryBridge:'manual-code-v1'}; // ArcadeLab remains offline; Option C synchronizes by manual portable-code transfer.
const START_POINTS={0:0,1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:0,9:0,10:0,11:0,12:0,13:0,14:0};
const LEGACY_START_POINTS={0:10,1:7,2:10,3:10,4:10,5:10};
const blankAlloc=()=>({acc:0,spd:0,trn:0,drf:0});
function freshBuilds(){const o={};for(const c of CHARS)o[c.id]={points:START_POINTS[c.id]||0,alloc:blankAlloc(),sharedAlloc:blankAlloc()};return o;}
function freshEmployeeProgress(){const o={};for(const c of CHARS)o[c.id]={level:1,xp:0};return o;}
function detectMobileDevice(){try{return matchMedia('(pointer: coarse)').matches||navigator.maxTouchPoints>0;}catch(e){return false;}}
const MOBILE_DEVICE=detectMobileDevice();
function defSave(){return{wiz:0,xp:0,level:1,statBank:0,employeeProgress:freshEmployeeProgress(),builds:freshBuilds(),owned:['starter'],board:'starter',ownedHats:[],hat:null,char:0,diff:0,laps:3,track:'easy',auto:MOBILE_DEVICE,autoMobileDefault461Applied:MOBILE_DEVICE,bestLap:null,bestRace:null,races:0,wins:0,fork:false,classicDrift:false,initialDriftAngle:DEFAULT_INITIAL_DRIFT_ANGLE,bunnyHopTimer:DEFAULT_BUNNY_HOP_PERCENT,mobileControlsTest:false,defaults225Applied:true,defaults400Applied:true,defaults420Applied:true,defaults430Applied:true,defaults440Applied:true,defaults466Applied:true,defaults467Applied:true};}
function normalizeBuilds(b,legacy=false){const f=freshBuilds();if(!b)return f;for(const c of CHARS){const id=c.id,q=b[id]||b[String(id)];if(q){const pts=Math.max(0,+q.points||0);f[id].points=Math.max(0,pts-(legacy?(LEGACY_START_POINTS[id]||0):0));f[id].alloc=Object.assign(blankAlloc(),q.alloc||{});f[id].sharedAlloc=Object.assign(blankAlloc(),q.sharedAlloc||{});for(const k of STAT_KEYS){f[id].alloc[k]=Math.max(0,Math.floor(+f[id].alloc[k]||0));f[id].sharedAlloc[k]=clamp(Math.floor(+f[id].sharedAlloc[k]||0),0,f[id].alloc[k]);}}}return f;}
function normalizeLoadedSave(s,legacy=false){const d=Object.assign(defSave(),s||{});d.builds=normalizeBuilds(s&&s.builds,legacy);const ep=freshEmployeeProgress(),rawEP=s&&s.employeeProgress||{};for(const c of CHARS){const q=rawEP[c.id]||rawEP[String(c.id)]||{};ep[c.id].level=clamp(Math.floor(+q.level||1),1,30);ep[c.id].xp=ep[c.id].level>=30?0:Math.max(0,Math.floor(+q.xp||0));}d.employeeProgress=ep;d.char=CHARS.some(c=>c.id===d.char)?d.char:0;if(!BOARDS.some(b=>b.id===d.board))d.board='starter';d.owned=(d.owned||['starter']).filter(id=>BOARDS.some(b=>b.id===id));if(!d.owned.includes('starter'))d.owned.unshift('starter');d.ownedHats=(d.ownedHats||[]).filter(id=>HATS.some(h=>h.id===id));d.hat=HATS.some(h=>h.id===d.hat)&&d.ownedHats.includes(d.hat)?d.hat:null;if(!TRACKS.some(t=>t.id===d.track))d.track='easy';if(!(s&&s.defaults430Applied)){if(!s||!s.track||s.track==='current')d.track='easy';d.defaults430Applied=true;}if(!(s&&s.defaults400Applied)){d.diff=0;d.classicDrift=!!(s&&s.marioDrift===false);d.initialDriftAngle=30;d.defaults400Applied=true;}if(!(s&&s.defaults420Applied)){if(!s||s.initialDriftAngle==null||+s.initialDriftAngle===30)d.initialDriftAngle=20;d.defaults420Applied=true;}if(!(s&&s.defaults440Applied)){d.bunnyHopTimer=s&&s.bunnyHopTimer!=null?+s.bunnyHopTimer:100;d.defaults440Applied=true;}if(!(s&&s.defaults466Applied)){if(!s||s.initialDriftAngle==null||+s.initialDriftAngle===20)d.initialDriftAngle=30;if(!s||s.bunnyHopTimer==null||+s.bunnyHopTimer===100)d.bunnyHopTimer=DEFAULT_BUNNY_HOP_PERCENT;d.defaults466Applied=true;}if(!(s&&s.defaults467Applied)){if(!s||s.initialDriftAngle==null||+s.initialDriftAngle===30)d.initialDriftAngle=DEFAULT_INITIAL_DRIFT_ANGLE;d.defaults467Applied=true;}if(MOBILE_DEVICE&&!(s&&s.autoMobileDefault461Applied)){d.auto=true;d.autoMobileDefault461Applied=true;}d.statBank=Math.max(0,Math.floor(+d.statBank||0));d.diff=clamp(Math.floor(+d.diff||0),0,2);d.classicDrift=!!d.classicDrift;d.initialDriftAngle=clamp(Math.round(d.initialDriftAngle==null?DEFAULT_INITIAL_DRIFT_ANGLE:+d.initialDriftAngle),1,90);d.bunnyHopTimer=clamp(Math.round(d.bunnyHopTimer==null?DEFAULT_BUNNY_HOP_PERCENT:+d.bunnyHopTimer),0,100);d.mobileControlsTest=!!d.mobileControlsTest;delete d.marioDrift;delete d.multiDrift;delete d.progressiveDrift;return d;}
const SESSION_STORAGE=new Map();
let STORAGE_MODE='persistent',STORAGE_DETAIL='';
const STORAGE={
  getItem(key){
    if(STORAGE_MODE!=='session')try{const v=window.localStorage.getItem(key);if(v!==null)return v;}catch(e){STORAGE_MODE='session';STORAGE_DETAIL=e&&e.name||'StorageError';}
    return SESSION_STORAGE.has(key)?SESSION_STORAGE.get(key):null;
  },
  setItem(key,value){
    value=String(value);SESSION_STORAGE.set(key,value);
    if(STORAGE_MODE==='session')return false;
    try{window.localStorage.setItem(key,value);return true;}catch(e){STORAGE_MODE='session';STORAGE_DETAIL=e&&e.name||'StorageError';return false;}
  },
  removeItem(key){
    SESSION_STORAGE.delete(key);
    if(STORAGE_MODE==='session')return false;
    try{window.localStorage.removeItem(key);return true;}catch(e){STORAGE_MODE='session';STORAGE_DETAIL=e&&e.name||'StorageError';return false;}
  }
};
(function probeStorage(){const k='__lva_storage_probe__';try{window.localStorage.setItem(k,'1');window.localStorage.removeItem(k);}catch(e){STORAGE_MODE='session';STORAGE_DETAIL=e&&e.name||'StorageError';}})();
function profileKey(name){return PROFILE_PREFIX+name.trim().toLowerCase();}
function profileList(){try{const a=JSON.parse(STORAGE.getItem(PROFILE_INDEX_KEY)||'[]');return Array.isArray(a)?a.filter(x=>typeof x==='string'):[];}catch(e){return[];}}
function saveProfileList(a){return STORAGE.setItem(PROFILE_INDEX_KEY,JSON.stringify([...new Set(a)]));}
function pinHash(name,pin){let h=2166136261>>>0,str='LVA3|'+name.trim().toLowerCase()+'|'+pin;for(let i=0;i<str.length;i++){h^=str.charCodeAt(i);h=Math.imul(h,16777619)>>>0;}return h.toString(36);}
function checksum(str){let h=2166136261>>>0;for(let i=0;i<str.length;i++){h^=str.charCodeAt(i);h=Math.imul(h,16777619)>>>0;}return h.toString(36);}
function b64enc(str){return btoa(unescape(encodeURIComponent(str))).replace(/\+/g,'-').replace(/\//g,'_').replace(/=+$/,'');}
function b64dec(str){str=str.replace(/-/g,'+').replace(/_/g,'/');while(str.length%4)str+='=';return decodeURIComponent(escape(atob(str)));}
function readProfile(name){try{const r=JSON.parse(STORAGE.getItem(profileKey(name)));return r&&r.name&&r.pinHash&&r.save?r:null;}catch(e){return null;}}
let ACTIVE_PROFILE_NAME=null,GUEST_MODE=false;
function loadSave(){try{const active=STORAGE.getItem(PROFILE_ACTIVE_KEY),rec=active&&readProfile(active);if(rec){ACTIVE_PROFILE_NAME=rec.name;return normalizeLoadedSave(rec.save,false);}const keys=[SAVE_KEY,V22_SAVE_KEY,V21_SAVE_KEY,V20_SAVE_KEY,V19_SAVE_KEY,V18_SAVE_KEY,V17_SAVE_KEY,V16_SAVE_KEY,V15_SAVE_KEY,V14_SAVE_KEY,V13_SAVE_KEY,V12_SAVE_KEY,LEGACY_SAVE_KEY];let raw=null,used='';for(const k of keys){raw=STORAGE.getItem(k);if(raw){used=k;break;}}const parsed=raw&&JSON.parse(raw);if(parsed&&typeof parsed==='object')return normalizeLoadedSave(parsed,used===LEGACY_SAVE_KEY||used===V12_SAVE_KEY||used===V13_SAVE_KEY||used===V14_SAVE_KEY||used===V15_SAVE_KEY||used===V16_SAVE_KEY);}catch(e){}return defSave();}
function persist(){if(GUEST_MODE)return true;if(ACTIVE_PROFILE_NAME){const old=readProfile(ACTIVE_PROFILE_NAME);if(old){old.save=SV;old.updated=Date.now();return STORAGE.setItem(profileKey(old.name),JSON.stringify(old));}}return STORAGE.setItem(SAVE_KEY,JSON.stringify(SV));}
function validProfileName(name){return /^[A-Za-z0-9][A-Za-z0-9 _.-]{2,19}$/.test(name);}
function storageModeMessage(){return STORAGE_MODE==='persistent'?'Progress is saved in this browser.':'ArcadeLab sandbox storage is restricted. This profile is session-only; generate a fresh portable save code before closing or reloading the game.';}
function createProfile(name,pin){
  name=(name||'').trim();
  if(!validProfileName(name))return{ok:false,msg:'Profile name must be 3–20 characters and use letters, numbers, spaces, _, . or -.'};
  if(!/^\d{4}$/.test(pin||''))return{ok:false,msg:'PIN must be exactly four digits.'};
  if(profileList().some(n=>n.toLowerCase()===name.toLowerCase()))return{ok:false,msg:'That profile name already exists in this browser session.'};
  try{
    const seed=profileList().length?defSave():(STARTUP_UNPROFILED_SAVE||SV),rec={format:3,name,pinHash:pinHash(name,pin),provider:PROFILE_PROVIDER.id,save:normalizeLoadedSave(seed,false),updated:Date.now()};
    STORAGE.setItem(profileKey(name),JSON.stringify(rec));saveProfileList(profileList().concat(name));ACTIVE_PROFILE_NAME=name;GUEST_MODE=false;STORAGE.setItem(PROFILE_ACTIVE_KEY,name);SV=normalizeLoadedSave(rec.save,false);persist();
    return{ok:true,msg:'Profile created and loaded. '+storageModeMessage()};
  }catch(e){return{ok:false,msg:'Profile creation could not finish. Reload the game and try again.'};}
}
function activateProfile(name,pin){const rec=readProfile(name);if(!rec)return{ok:false,msg:'Profile not found in this browser session. Import its portable save code instead.'};if(!/^\d{4}$/.test(pin||'')||rec.pinHash!==pinHash(rec.name,pin))return{ok:false,msg:'Incorrect four-digit PIN.'};ACTIVE_PROFILE_NAME=rec.name;GUEST_MODE=false;STORAGE.setItem(PROFILE_ACTIVE_KEY,rec.name);SV=normalizeLoadedSave(rec.save,false);persist();return{ok:true,msg:'Profile loaded. '+storageModeMessage()};}
function signOutProfile(){persist();GUEST_MODE=false;ACTIVE_PROFILE_NAME=null;STORAGE.removeItem(PROFILE_ACTIVE_KEY);SV=defSave();}
function encodeProfileCode(){if(!ACTIVE_PROFILE_NAME)return'';const rec=readProfile(ACTIVE_PROFILE_NAME);if(!rec)return'';const raw=JSON.stringify({format:'LVA3-PORTABLE',name:rec.name,pinHash:rec.pinHash,provider:PROFILE_PROVIDER.id,save:rec.save});return'LVA3-'+b64enc(raw)+'-'+checksum(raw);}
function importProfileCode(code,pin){try{code=(code||'').trim();if(!code.startsWith('LVA3-'))throw Error('prefix');const body=code.slice(5),cut=body.lastIndexOf('-');if(cut<1)throw Error('shape');const raw=b64dec(body.slice(0,cut));if(checksum(raw)!==body.slice(cut+1))throw Error('checksum');const p=JSON.parse(raw);if(p.format!=='LVA3-PORTABLE'||!validProfileName(p.name)||!p.pinHash||!p.save)throw Error('payload');if(!/^\d{4}$/.test(pin||'')||p.pinHash!==pinHash(p.name,pin))return{ok:false,msg:'The PIN does not match this portable profile.'};const same=profileList().find(n=>n.toLowerCase()===p.name.toLowerCase()),old=same&&readProfile(same);if(old&&old.pinHash!==p.pinHash)return{ok:false,msg:'A different profile in this browser session already uses that name.'};const rec={format:3,name:p.name,pinHash:p.pinHash,provider:PROFILE_PROVIDER.id,save:normalizeLoadedSave(p.save,false),updated:Date.now()};STORAGE.setItem(profileKey(rec.name),JSON.stringify(rec));if(!same)saveProfileList(profileList().concat(rec.name));ACTIVE_PROFILE_NAME=rec.name;GUEST_MODE=false;STORAGE.setItem(PROFILE_ACTIVE_KEY,rec.name);SV=rec.save;persist();return{ok:true,msg:'Portable profile imported and loaded. '+storageModeMessage()};}catch(e){return{ok:false,msg:'Invalid or damaged LVA portable save code.'};}}
function charById(id){return CHARS.find(c=>c.id===id)||CHARS[0];}
function buildOf(id=SV.char){if(!SV.builds[id])SV.builds[id]={points:START_POINTS[id]||0,alloc:blankAlloc(),sharedAlloc:blankAlloc()};if(!SV.builds[id].sharedAlloc)SV.builds[id].sharedAlloc=blankAlloc();return SV.builds[id];}
function employeeProgressOf(id=SV.char){if(!SV.employeeProgress)SV.employeeProgress=freshEmployeeProgress();if(!SV.employeeProgress[id])SV.employeeProgress[id]={level:1,xp:0};return SV.employeeProgress[id];}
function unlockEverything(){SV.owned=BOARDS.map(b=>b.id);SV.ownedHats=HATS.map(h=>h.id);SV.level=30;SV.xp=0;SV.wiz=MAX_ESTAR_BANK;SV.statBank=0;for(const c of CHARS){const ep=employeeProgressOf(c.id);ep.level=30;ep.xp=0;const b=buildOf(c.id);b.points=0;for(const k of STAT_KEYS){b.alloc[k]=Math.max(0,STAT_MAX-c.base[k]);b.sharedAlloc[k]=0;}}persist();}
function purchaseStatPoint(){if(SV.wiz<STAT_POINT_COST)return{ok:false,msg:'Insufficient E-Stars to purchase a stat point.'};SV.wiz-=STAT_POINT_COST;SV.statBank=(SV.statBank||0)+1;return{ok:true,msg:'Purchased 1 shared stat point for '+STAT_POINT_COST.toLocaleString()+' E-Stars.'};}
function hatOf(id){return HATS.find(h=>h.id===id)||null;}
let SV=loadSave();
const STARTUP_UNPROFILED_SAVE=!ACTIVE_PROFILE_NAME?normalizeLoadedSave(SV,false):null;
let PROFILE_GATE_PROMPT=false,PENDING_PROFILE_ACTION=null;
persist();
const MAX_LEVEL=30;
const employeeXpNeed=l=>100+50*(l-1);
const playerXpNeed=l=>employeeXpNeed(l)*2;
const xpNeed=playerXpNeed; // Backward-compatible name now points to Player Level requirements (100% increase).
function boardOf(id){return BOARDS.find(b=>b.id===id)||BOARDS[0];}
function playerStats(){
  const ch=charById(SV.char),bd=boardOf(SV.board),hat=hatOf(SV.hat),b=buildOf(),o={};
  for(const k of STAT_KEYS)o[k]=Math.min(STAT_MAX,ch.base[k]+b.alloc[k]+(bd.bonus[k]||0)+(hat?.bonus[k]||0));
  return o;
}
function driftRate(r){return 10+r.stats.drf*2;}
function driftTightenAmount(r){
  if(!r.isPlayer)return 1;
  const q=clamp(r.driftDirT/DRIFT_TIGHTEN_RAMP_SECONDS,0,1),smooth=q*q*(3-2*q);
  return DRIFT_TIGHTEN_MIN_TURN+(DRIFT_TIGHTEN_MAX_TURN-DRIFT_TIGHTEN_MIN_TURN)*smooth;
}
function driftVisualAngle(r){
  if(!r.drifting)return 0;
  if(!r.isPlayer)return r.driftDir*.35;
  if(!SV.classicDrift)return r.driftDir*.18-r.steer*.08;
  const q=clamp(r.driftDirT/DRIFT_TIGHTEN_RAMP_SECONDS,0,1),smooth=q*q*(3-2*q);
  return r.driftDir*(.14+.38*smooth);
}

/* ===================== GAME STATE ===================== */
let GRAND_PRIX=null;
const G={state:'menu',t:0,cd:0,racers:[],player:null,pickups:[],dropBoxes:[],missiles:[],mines:[],emps:[],parts:[],banners:[],laps:3,raceTime:0,shake:0,finishT:0,finishOrder:0,paused:false,startPress:-1,wrongT:0,rewards:null,perfects:0,ambient:0,training:false,timeScale:1};
const PLAYER_STATES=Object.freeze({BASE:'Base',BOOST:'Boost',DRIFT:'Drift',TRANSITION:'Transition',JUMP:'Jump',WIPEOUT:'Wipeout',PICKUP:'Pickup',INVINCIBLE:'Invincible'});
function resolveRacerState(r){if(!r)return PLAYER_STATES.BASE;if(invincibleStateActive(r))return PLAYER_STATES.INVINCIBLE;if(r.stunT>0)return PLAYER_STATES.WIPEOUT;if(r.isPlayer&&r.air&&r.tricks&&!r.hop)return PLAYER_STATES.JUMP;if(r.boostT>0||r.bunnyBoostT>0)return PLAYER_STATES.BOOST;if(r.isPlayer&&(r.inp.drift||r.drifting))return PLAYER_STATES.DRIFT;if(r.transitionT>0)return PLAYER_STATES.TRANSITION;if(hasCarriedItem(r))return PLAYER_STATES.PICKUP;return PLAYER_STATES.BASE;}
function updateRacerState(r,dt=0){r.stateFlags={invincible:invincibleStateActive(r),boost:r.boostT>0||r.bunnyBoostT>0,drift:!!(r.inp.drift||r.drifting),transition:r.transitionT>0,jump:!!(r.isPlayer&&r.air&&r.tricks&&!r.hop),wipeout:r.stunT>0,pickup:hasCarriedItem(r)};const next=resolveRacerState(r);if(r.pcState!==next){r.prevPCState=r.pcState||PLAYER_STATES.BASE;r.pcState=next;r.stateT=0;}else r.stateT=(r.stateT||0)+dt;return next;}
const cam={x:0,y:0,zoom:1,K:16};
const keys={};
let PX=0,PY=0;
function proj(x,y,z){const k=cam.K*cam.zoom;PX=((x-cam.x)-(y-cam.y))*k+W/2;PY=((x-cam.x)+(y-cam.y))*k*.5-(z||0)*k*.95+H/2+(cam.sy||0);}

/* ===================== AUDIO ===================== */
let AC=null,audioOn=true,engOsc=null,engGain=null,engFilt=null;
function ensureAudio(){if(!AC){try{AC=new(window.AudioContext||window.webkitAudioContext)();}catch(e){AC=null;}}if(AC&&AC.state==='suspended')AC.resume();}
function tone(f,d,type,v,slide){
  if(!AC||!audioOn)return;try{
    const o=AC.createOscillator(),g=AC.createGain(),t=AC.currentTime;o.type=type||'square';o.frequency.setValueAtTime(f,t);
    if(slide)o.frequency.exponentialRampToValueAtTime(Math.max(20,f*slide),t+d);
    g.gain.setValueAtTime(v||.05,t);g.gain.exponentialRampToValueAtTime(.0001,t+d);o.connect(g);g.connect(AC.destination);o.start(t);o.stop(t+d+.02);}catch(e){}
}
const SFX={
  beep:()=>tone(440,.18,'square',.06),go:()=>tone(880,.5,'square',.07),
  pickup:()=>{tone(660,.08,'triangle',.06);setTimeout(()=>tone(990,.1,'triangle',.06),70);},
  roll:()=>tone(520+Math.random()*300,.05,'square',.03),
  boost:()=>tone(220,.5,'sawtooth',.05,3.2),
  hit:()=>tone(160,.35,'sawtooth',.08,.35),
  wall:()=>tone(110,.1,'square',.05,.6),
  shield:()=>tone(700,.25,'sine',.06,.4),
  launch:()=>tone(300,.3,'triangle',.06,2.2),
  land:()=>tone(90,.15,'sine',.08,.5),
  trick:()=>tone(900,.08,'square',.04),
  perfect:()=>{tone(784,.1,'triangle',.07);setTimeout(()=>tone(1047,.1,'triangle',.07),90);setTimeout(()=>tone(1319,.2,'triangle',.07),180);},
  missile:()=>tone(500,.4,'sawtooth',.05,.3),
  lap:()=>{tone(660,.12,'triangle',.06);setTimeout(()=>tone(880,.2,'triangle',.06),110);},
  win:()=>{[523,659,784,1047].forEach((f,i)=>setTimeout(()=>tone(f,.25,'triangle',.07),i*130));},
};
function startEngine(){
  if(!AC||engOsc)return;try{engOsc=AC.createOscillator();engGain=AC.createGain();engFilt=AC.createBiquadFilter();engOsc.type='sawtooth';engFilt.type='lowpass';engFilt.frequency.value=500;engGain.gain.value=.0;engOsc.connect(engFilt);engFilt.connect(engGain);engGain.connect(AC.destination);engOsc.start();}catch(e){engOsc=null;}
}
function stopEngine(){if(engOsc){try{engOsc.stop();}catch(e){}engOsc=null;}}
function updateEngine(sp,boost){if(engOsc&&AC){engOsc.frequency.value=55+sp*3.4+(boost?25:0);engGain.gain.value=audioOn&&G.state!=='menu'&&!G.paused?.018:0;engFilt.frequency.value=380+sp*14;}}

/* ===================== RACERS ===================== */
function makeRacer(ch,isPlayer,slot,stats){
  const row=Math.floor(slot/2),col=slot%2,equippedBoard=isPlayer?boardOf(SV.board):BOARDS[(slot*2+ch.id)%BOARDS.length];
  const s0=T.L-8-row*8,lat=col?5.2:-5.2;
  trkAt(s0,lat);
  const r={ch,isPlayer,name:isPlayer?'YOU':ch.name,x:trkAt.x,y:trkAt.y,z:0,baseZ:trkAt.z||0,vz:0,h:Math.atan2(trkAt.ty,trkAt.tx),vx:0,vy:0,
    stats,boardId:equippedBoard.id,boardColor:equippedBoard.color,hatId:isPlayer?SV.hat:null,
    steer:0,thr:0,inp:{steer:0,thr:0,brk:0,drift:false,use:false},
    air:false,drifting:false,driftDir:0,lastDriftDir:0,driftT:0,driftDirT:0,driftBoostT:0,transitionT:0,bunnyBoostT:0,driftMeter:0,kartFlicks:0,kartLastSteer:0,kartFlickCool:0,boostT:0,stunT:0,invT:0,invincibleT:0,shieldT:0,blindT:0,blindWanderT:0,blindSteer:0,spin:0,
    item:null,itemCharges:0,item2:null,item2Charges:0,pickupOrder:[],roll:0,rollItem:null,rollSlot:0,setTouchT:0,idx:-1,s:0,prog:0,crossed:0,lapStart:0,lapTimes:[],lap:1,finished:false,finishTime:0,rank:1,
    trail:[],trailT:0,tricks:null,trickRot:0,wallT:0,bob:Math.random()*6,speed:0,pcState:PLAYER_STATES.BASE,prevPCState:PLAYER_STATES.BASE,stateT:0,stateFlags:{},
    skill:isPlayer?1:rnd(.95,1.03),aiLat:0,aiLatS:0,aiT:0,aiItemT:0,cornerT:0,trickWill:false,bumpT:0,rampCool:0,lapFlash:0};
  trkQuery(r.x,r.y,-1);r.idx=Q.i;r.s=Q.s;r.prog=-(T.L-r.s);r.crossed=0;
  return r;
}
function bannerAdd(text,col,dur){G.banners.push({text,col:col||'#fff',t:0,dur:dur||1.6});if(G.banners.length>3)G.banners.shift();}
function addPart(x,y,z,vx,vy,vz,life,r,col,grav){if(G.parts.length>(lowDetail()?140:SMOOTH.quality==='balanced'?300:420))G.parts.shift();G.parts.push({x,y,z,vx,vy,vz,life,max:life,r,col,g:grav==null?18:grav});}
function burst(x,y,z,n,col,sp,life,r){for(let i=0;i<n;i++){const a=rnd(0,TAU),v=rnd(.3,1)*sp;addPart(x,y,z,Math.cos(a)*v,Math.sin(a)*v,rnd(2,sp*.6),rnd(.3,1)*life,r||2,col);}}

function startRace(){
  G.training=false;buildTrack(SV.track);buildFeatures();scenerySprites.clear();acc=0;SMOOTH.resetCamera=true;SMOOTH.lookX=0;SMOOTH.lookY=0;
  ensureAudio();
  G.racers=[];G.pickups=[];G.dropBoxes=[];G.missiles=[];G.mines=[];G.emps=[];G.parts=[];G.banners=[];G.shake=0;G.finishT=0;G.finishOrder=0;G.raceTime=0;G.paused=false;G.perfects=0;
  G.laps=SV.laps;G.rewards=null;G.wrongT=0;G.startPress=-1;
  const pst=playerStats(),pch=charById(SV.char);
  const others=GRAND_PRIX?GRAND_PRIX.racerIds.filter(id=>id!==pch.id).map(charById):Array.from({length:5},(_,i)=>CHARS[(pch.id+1+i)%CHARS.length]).sort(()=>Math.random()-.5);
  const pSlot=4;
  const list=[];
  // player slot fixed, others random
  let oi=0;
  for(let s=0;s<6;s++){
    if(s===pSlot){G.player=makeRacer(pch,true,s,pst);list.push(G.player);}
    else{const ch=others[oi++];const lv=clamp(SV.level,1,15),base=ch.base;
      const st={acc:Math.min(STAT_MAX,base.acc+Math.floor(lv/3)),spd:Math.min(STAT_MAX,base.spd+Math.floor(lv/4)),trn:Math.min(STAT_MAX,base.trn+Math.floor(lv/4)),drf:Math.min(STAT_MAX,base.drf+Math.floor(lv/5))};
      const r=makeRacer(ch,false,s,st);r.name=ch.name;list.push(r);}
  }
  G.racers=list;
  FEAT.boxes.forEach(b=>b.t=0);
  G.state='countdown';G.cd=3.99;
  cam.x=G.player.x;cam.y=G.player.y;
    captureVisualState(true);
  document.getElementById('menu').classList.remove('show');
  document.getElementById('results').classList.remove('show');
  document.getElementById('pause').classList.remove('show');
  startEngine();syncTouchControls();
}
function startGrandPrix(circuitId){
  const circuit=CIRCUITS.find(c=>c.id===circuitId);if(!circuit)return;
  const rivals=CHARS.filter(c=>c.id!==SV.char).sort(()=>Math.random()-.5).slice(0,5).map(c=>c.id);
  const ids=[SV.char,...rivals],points={},rewards={};for(const id of ids){points[id]=0;rewards[id]={xp:0,wiz:0};}
  GRAND_PRIX={circuitId:circuit.id,trackIds:circuit.trackIds.slice(),raceIndex:0,racerIds:ids,points,rewards,lastRanks:{}};
  SV.track=GRAND_PRIX.trackIds[0];persist();startRace();
}

function startTraining(){
  G.training=true;acc=0;SMOOTH.resetCamera=true;SMOOTH.lookX=0;SMOOTH.lookY=0;ensureAudio();buildTrainingGround();
  G.racers=[];G.pickups=[];G.dropBoxes=[];G.missiles=[];G.mines=[];G.emps=[];G.parts=[];G.banners=[];G.shake=0;G.raceTime=0;G.paused=false;G.perfects=0;G.useReq=false;G.useSlotReq=-1;
  const pch=charById(SV.char),pst=playerStats(),p=makeRacer(pch,true,0,pst);p.x=0;p.y=0;p.z=0;p.baseZ=0;p.h=0;p.vx=0;p.vy=0;p.idx=0;p.s=0;p.prog=0;p.crossed=1;p.lap=1;p.name='YOU';
  G.player=p;G.racers=[p];TRAIN.boxes.forEach(b=>b.t=0);G.state='training';cam.x=0;cam.y=0;captureVisualState(true);
  elMenu.classList.remove('show');elRes.classList.remove('show');elPause.classList.remove('show');startEngine();syncTouchControls();bannerAdd('TRAINING GROUND','#f2c500',2.2);
}

/* ===================== ITEMS ===================== */
const ITEM_DEF={
  missile:{name:'Arc Event',col:'#ff6a2a'},
  flash:{name:'Ark-Flash',col:'#fff4a3'},
  shield:{name:'Arc Shield',col:'#4bd0ff'},
  boost:{name:'Power Surge',col:'#f2c500'},
  tripulse:{name:'Three-Phase Boost',col:'#ff9f43'},
  shift:{name:'Shift-Diff',col:'#ad7cff'},
  mine:{name:'Breaker',col:'#7f8c8d'},
  emp:{name:'Ground Fault Pulse',col:'#6bffd0'},
  culture:{name:'Culture Token',col:'#2fb77d'},
  brownnose:{name:'Brown Nose',col:'#8b5a2b'},
};
function rollItem(r){
  const p=r.rank-1;
  const w={missile:10+p*4,flash:5+p*2,shield:Math.max(6,20-p*3),boost:10+p*5,tripulse:8+p*4,shift:6+p*2,mine:Math.max(6,20-p*2),emp:4+p*3,culture:r.isPlayer?1:0,brownnose:r.isPlayer?3:0};
  let tot=0;for(const k in w)tot+=w[k];let u=Math.random()*tot;
  for(const k in w){u-=w[k];if(u<=0)return k;}
  return'boost';
}
function triggerShiftJump(r){
  r.air=true;r.z=Math.max(r.z,.15);r.vz=Math.max(r.vz,17);r.hop=false;r.rampCool=1.2;r.drifting=false;r.driftT=0;r.driftDirT=0;
  const keysS=['A','S','D','F'],comboN=r.isPlayer?jumpComboKeys():BASE_COMBO_KEYS[SV.diff],seq=[];
  for(let i=0;i<comboN;i++){let k;do{k=pick(keysS);}while(i&&k===seq[i-1]);seq.push(k);}
  if(r.isPlayer){r.tricks={seq,prog:0,err:0};r.trickRot=0;SFX.launch();bannerAdd('SHIFT-DIFF JUMP!','#ad7cff',1.2);}
  else{r.tricks=null;r.trickWill=true;r.aiTrickN=comboN;}
}
function itemSlotCount(r){return deepPocketsActive(r)?2:1;}
function slotItem(r,slot){return slot===1?r.item2:r.item;}
function slotCharges(r,slot){return slot===1?r.item2Charges:r.itemCharges;}
function setSlot(r,slot,item,charges=0){if(slot===1){r.item2=item;r.item2Charges=charges;}else{r.item=item;r.itemCharges=charges;}r.pickupOrder=(r.pickupOrder||[]).filter(q=>q!==slot);if(item)r.pickupOrder.unshift(slot);}
function clearSlot(r,slot){if(slot===1){r.item2=null;r.item2Charges=0;}else{r.item=null;r.itemCharges=0;}r.pickupOrder=(r.pickupOrder||[]).filter(q=>q!==slot);}
function hasCarriedItem(r){return!!(r&&(r.item||r.item2));}
function firstEmptySlot(r){if(!r.item)return 0;if(itemSlotCount(r)>1&&!r.item2)return 1;return-1;}
function hasInventorySpace(r){return firstEmptySlot(r)>=0;}
function latestItemSlot(r){r.pickupOrder=(r.pickupOrder||[]).filter(q=>q<itemSlotCount(r)&&slotItem(r,q));return r.pickupOrder.length?r.pickupOrder[0]:(r.item?0:r.item2?1:-1);}
function useItem(r,slot=null){
  if(r.stunT>0)return false;if(slot==null)slot=r.isPlayer?latestItemSlot(r):0;if(slot<0||slot>=itemSlotCount(r))return false;
  const it=slotItem(r,slot);if(!it)return false;if(it!=='tripulse')clearSlot(r,slot);
  const c=Math.cos(r.h),s=Math.sin(r.h);
  if(it==='boost'){r.boostT=Math.max(r.boostT,STANDARD_BOOST_SECONDS);if(r.isPlayer){SFX.boost();bannerAdd('POWER SURGE!','#f2c500',1);}}
  else if(it==='brownnose'){r.boostT=Math.max(r.boostT,BROWN_NOSE_SECONDS);r.invincibleT=Math.max(r.invincibleT,BROWN_NOSE_SECONDS);if(r.isPlayer){SFX.boost();bannerAdd('BROWN NOSE · INVINCIBLE-STATE!','#8b5a2b',1.5);}}
  else if(it==='tripulse'){const left=Math.max(0,(slotCharges(r,slot)||3)-1);setSlot(r,slot,left?'tripulse':null,left);r.boostT=Math.max(r.boostT,.85);if(left)r.aiItemT=.75;if(r.isPlayer){SFX.boost();bannerAdd('PHASE BOOST · '+left+' LEFT','#ff9f43',1);}}
  else if(it==='shield'){r.shieldT=10;if(r.isPlayer){SFX.shield();bannerAdd('ARC SHIELD ACTIVE','#4bd0ff',1);}}
  else if(it==='shift'){triggerShiftJump(r);}
  else if(it==='culture'){if(r.isPlayer){SV.wiz+=50;persist();SFX.pickup();bannerAdd('CULTURE TOKEN · +50 E-STARS','#2fb77d',1.5);}else r.boostT=Math.max(r.boostT,.6);}
  else if(it==='flash'){
    let hit=0;for(const o of G.racers){if(o===r||o.finished)continue;if(invincibleStateActive(o)){if(o.isPlayer)bannerAdd('INVINCIBLE-STATE BLOCKED ARK-FLASH','#8b5a2b',1.2);continue;}if(o.shieldT>0){o.shieldT=0;continue;}o.blindT=Math.max(o.blindT,2);o.blindWanderT=0;hit++;if(o.isPlayer){SFX.hit();bannerAdd('ARK-FLASH · VISOR WHITEOUT!','#fff4a3',2);}}
    if(r.isPlayer){SFX.missile();bannerAdd(hit?'ARK-FLASH DEPLOYED!':'ARK-FLASH · NO TARGETS','#fff4a3',1.2);}
  }
  else if(it==='mine'){G.mines.push({x:r.x-c*3.2,y:r.y-s*3.2,owner:r,t:0,life:30});if(r.isPlayer){SFX.pickup();bannerAdd('BREAKER SET','#d7e0e4',1);}}
  else if(it==='emp'){G.emps.push({x:r.x,y:r.y,owner:r,t:0,hit:new Set()});if(r.isPlayer){SFX.missile();bannerAdd('GROUND FAULT PULSE!','#6bffd0',1);}}
  else if(it==='missile'){
    let tgt=null,bd=1e9;
    for(const o of G.racers){if(o===r||o.finished)continue;const dx=o.x-r.x,dy=o.y-r.y,d=Math.hypot(dx,dy);if(d>75)continue;if(Math.abs(angDiff(r.h,Math.atan2(dy,dx)))>.9)continue;if(d<bd){bd=d;tgt=o;}}
    G.missiles.push({x:r.x+c*2.8,y:r.y+s*2.8,h:r.h,owner:r,target:tgt,life:5,t:0});
    if(r.isPlayer){SFX.missile();bannerAdd('ARC EVENT!','#ff8a4a',1);}
  }
  if(slotItem(r,slot)){r.pickupOrder=(r.pickupOrder||[]).filter(q=>q!==slot);r.pickupOrder.push(slot);}
  return true;
}
function dropCarriedPickup(v){if(!hasCarriedItem(v))return;const c=Math.cos(v.h),sn=Math.sin(v.h),dropped=[];for(let slot=0;slot<itemSlotCount(v);slot++){const item=slotItem(v,slot);if(!item)continue;const charges=slotCharges(v,slot)||0,side=slot?.9:-.9;G.dropBoxes.push({x:v.x-c*4-sn*side,y:v.y-sn*4+c*side,z:v.baseZ||0,item,charges,life:22,lock:.55,owner:v,s:Math.random()*100});dropped.push(ITEM_DEF[item].name.toUpperCase());clearSlot(v,slot);}v.roll=0;if(v.isPlayer)bannerAdd('PICKUP'+(dropped.length>1?'S':'')+' DROPPED · '+dropped.join(' + '),'#ffb84a',1.25);}
function hitRacer(v,by,kind){
  if(v.invT>0||v.finished&&false)return false;
  if(invincibleStateActive(v)&&by&&by!==v){if(v.isPlayer)bannerAdd('INVINCIBLE-STATE · ITEM BLOCKED','#8b5a2b',1);return false;}
  if(v.shieldT>0){v.shieldT=0;burst(v.x,v.y,2,14,'#8fe3ff',16,.6,3);if(v.isPlayer){SFX.shield();bannerAdd('ARC SHIELD BLOCKED!','#4bd0ff',1);}return false;}
  dropCarriedPickup(v);
  if(kind==='emp'){v.stunT=Math.max(v.stunT,.55);v.vx*=.45;v.vy*=.45;v.spin=0;}
  else{v.stunT=1.15;v.vx*=.3;v.vy*=.3;v.spin=0;}
  v.invT=1.1+v.stunT;v.drifting=false;v.driftT=0;v.driftDirT=0;
  burst(v.x,v.y,2,18,'#ffb84a',20,.7,3);
  if(v.isPlayer){SFX.hit();G.shake=Math.max(G.shake,10);bannerAdd(kind==='emp'?'GROUND FAULT HIT':kind==='missile'?'ARC EVENT HIT':'SPUN OUT!','#ff6a5a',1.1);}
  else if(by&&by.isPlayer){SFX.pickup();bannerAdd('HIT '+v.name+'!','#ffe14a',1);}
  return true;
}
function updateItems(dt){
  // pickups
  const activeBoxes=G.training?TRAIN.boxes:FEAT.boxes;
  for(const b of activeBoxes)if(b.t>0)b.t-=dt;
  for(const r of G.racers){
    if(r.roll>0){r.roll-=dt;if(r.isPlayer&&Math.random()<.35)SFX.roll();if(r.roll<=0){const item=rollItem(r);setSlot(r,r.rollSlot,item,item==='tripulse'?3:0);if(r.isPlayer)SFX.pickup();r.aiItemT=rnd(.6,2.8);}}
    else if(hasInventorySpace(r)&&!r.finished&&r.z<1.5){
      for(const b of activeBoxes){if(b.t>0)continue;if(Math.abs(r.x-b.x)<2.6&&Math.abs(r.y-b.y)<2.6&&Math.hypot(r.x-b.x,r.y-b.y)<2.7){b.t=4.5;r.rollSlot=firstEmptySlot(r);r.roll=1.0;burst(b.x,b.y,2,10,'#ffe14a',14,.6,2);if(r.isPlayer)SFX.pickup();break;}}
    }
  }
  // dropped inventory boxes: contain the exact item lost when a racer enters Wipeout.
  for(let i=G.dropBoxes.length-1;i>=0;i--){const b=G.dropBoxes[i];b.life-=dt;b.lock=Math.max(0,b.lock-dt);if(b.life<=0){G.dropBoxes.splice(i,1);continue;}for(const r of G.racers){if(r.finished||!hasInventorySpace(r)||r.roll>0||r.z>1.7||(b.lock>0&&r===b.owner))continue;if(Math.hypot(r.x-b.x,r.y-b.y)<2.9){setSlot(r,firstEmptySlot(r),b.item,b.charges||(b.item==='tripulse'?3:0));r.aiItemT=rnd(.6,2.4);burst(b.x,b.y,2,12,ITEM_DEF[b.item].col,15,.65,2);if(r.isPlayer){SFX.pickup();bannerAdd('RECOVERED · '+ITEM_DEF[b.item].name.toUpperCase(),ITEM_DEF[b.item].col,1.1);}G.dropBoxes.splice(i,1);break;}}}
  // mines
  for(let i=G.mines.length-1;i>=0;i--){
    const m=G.mines[i];m.t+=dt;if(m.t>m.life){G.mines.splice(i,1);continue;}
    if(m.t<.8)continue;
    for(const r of G.racers){
      if(r.z>1.5)continue;if(r===m.owner&&m.t<2.2)continue;
      if(Math.hypot(r.x-m.x,r.y-m.y)<2.3){hitRacer(r,m.owner,'mine');burst(m.x,m.y,1,26,'#c98bff',24,.8,3);G.mines.splice(i,1);break;}
    }
  }
  // missiles
  for(let i=G.missiles.length-1;i>=0;i--){
    const m=G.missiles[i];m.t+=dt;m.life-=dt;
    let want;
    if(m.target&&!m.target.finished&&m.life>0){want=Math.atan2(m.target.y-m.y,m.target.x-m.x);}
    else if(G.training)want=m.h;else{trkQuery(m.x,m.y,-1);trkAt(Q.s+14,0);want=Math.atan2(trkAt.y-m.y,trkAt.x-m.x);}
    const da=angDiff(m.h,want);m.h+=clamp(da,-3.2*dt,3.2*dt);
    const sp=64;m.x+=Math.cos(m.h)*sp*dt;m.y+=Math.sin(m.h)*sp*dt;
    if(Math.random()<.7)addPart(m.x,m.y,1.4,-Math.cos(m.h)*8+rnd(-2,2),-Math.sin(m.h)*8+rnd(-2,2),rnd(0,2),.35,2,'#ffb060',-2);
    let dead=m.life<=0;
    for(const r of G.racers){if(r===m.owner||r.z>2.5)continue;if(Math.hypot(r.x-m.x,r.y-m.y)<2.4){hitRacer(r,m.owner,'missile');burst(m.x,m.y,1.5,22,'#ff7a3a',26,.8,3);dead=true;break;}}
    if(!dead&&!G.training){trkQuery(m.x,m.y,-1);if(Math.abs(Q.lat)>Q.w/2+1.5){burst(m.x,m.y,1,10,'#ff7a3a',16,.5,2);dead=true;}}
    if(dead)G.missiles.splice(i,1);
  }
  // emps
  for(let i=G.emps.length-1;i>=0;i--){
    const e=G.emps[i];e.t+=dt;const rad=e.t*50;
    for(const r of G.racers){if(r===e.owner||e.hit.has(r))continue;if(Math.hypot(r.x-e.x,r.y-e.y)<rad&&Math.hypot(r.x-e.x,r.y-e.y)<30){e.hit.add(r);hitRacer(r,e.owner,'emp');}}
    if(e.t>.65)G.emps.splice(i,1);
  }
}

/* ===================== PHYSICS ===================== */
function updateRacer(r,dt){
  const inp=r.inp;updateRacerState(r,0);
  r.bob+=dt*6;
  if(r.rampCool>0)r.rampCool-=dt;
  if(r.invT>0)r.invT-=dt;
  if(r.shieldT>0)r.shieldT-=dt;
  if(r.invincibleT>0)r.invincibleT=Math.max(0,r.invincibleT-dt);
  if(r.blindT>0)r.blindT=Math.max(0,r.blindT-dt);
  if(r.lapFlash>0)r.lapFlash-=dt;if(r.setTouchT>0)r.setTouchT=Math.max(0,r.setTouchT-dt);
  const st=r.stats;
  const cd=G.state==='countdown';
  const locked=cd||r.stunT>0;
  if(r.stunT>0){r.stunT-=dt;r.spin+=dt*14;}else r.spin=0;
  if(r.boostT>0)r.boostT-=dt;
  if(r.driftBoostT>0)r.driftBoostT=Math.max(0,r.driftBoostT-dt);
  if(r.transitionT>0)r.transitionT=Math.max(0,r.transitionT-dt);
  if(r.bunnyBoostT>0)r.bunnyBoostT=Math.max(0,r.bunnyBoostT-dt);
  if(r.kartFlickCool>0)r.kartFlickCool=Math.max(0,r.kartFlickCool-dt);
  const handi=r.isPlayer?1:(DIFFS[SV.diff].m*r.skill*(1+(r.rb||0)));
  const trn=1.55+st.trn*.075;
  const c=Math.cos(r.h),s=Math.sin(r.h);
  let vf=r.vx*c+r.vy*s,vs=-r.vx*s+r.vy*c;
  const thr=locked?0:inp.thr,brk=locked?0:inp.brk;
  // steer smoothing
  const tgtSteer=locked?0:inp.steer;
  r.steer+=(tgtSteer-r.steer)*Math.min(1,dt*(r.drifting?9:11));
  // Drift Meter: charge while the drift remains active; every full meter fires an immediate pickup-strength boost.
  if(!locked&&inp.drift&&!r.drifting&&!r.air&&vf>13&&Math.abs(inp.steer)>.2){const newDir=Math.sign(inp.steer);if(r.isPlayer&&r.transitionT>0&&r.lastDriftDir&&newDir===-r.lastDriftDir){const bunnyT=bunnyHopSeconds();r.bunnyBoostT=bunnyT;r.transitionT=0;if(bunnyT>0)vf*=1.2;SFX.boost();bannerAdd('Bunny-Hop Drift · '+bunnyT.toFixed(2)+'s','#ffe14a',1.15);}r.drifting=true;r.driftDir=newDir;r.h+=r.driftDir*initialDriftAngleRad();r.driftT=0;r.driftDirT=0;r.driftBoostT=r.isPlayer&&!SV.classicDrift?0:DRIFT_FORWARD_BOOST_SECONDS;r.kartFlicks=0;r.kartLastSteer=r.driftDir;r.kartFlickCool=.16;r.vz=Math.max(r.vz,!SV.classicDrift&&r.isPlayer?7:5.5);r.air=true;r.hop=true;}
  if(r.drifting){
    if(!inp.drift||vf<11||locked)endDrift(r);
    else{if(r.isPlayer&&!SV.classicDrift&&Math.abs(inp.steer)>.72){const steerSign=Math.sign(inp.steer);if(steerSign!==r.kartLastSteer&&r.kartFlickCool<=0){r.kartLastSteer=steerSign;r.kartFlicks++;r.kartFlickCool=.13;if(r.kartFlicks===KART_DRIFT_BLUE_FLICKS)bannerAdd('BLUE SPARKS READY','#52c8ff',.8);if(r.kartFlicks===KART_DRIFT_ORANGE_FLICKS)bannerAdd('ORANGE SPARKS READY','#ff9f43',.8);}}r.driftT+=dt;r.driftDirT+=dt;r.driftMeter+=driftRate(r)*dt;if(r.driftMeter>=DRIFT_METER_MAX){r.driftMeter%=DRIFT_METER_MAX;r.boostT=Math.max(r.boostT,2.3);if(r.isPlayer){SFX.boost();bannerAdd('DRIFT METER BOOST!','#f2c500',1.1);}}}
  }
  const boosting=r.boostT>0,driftForwardBoost=r.driftBoostT>0,bunnyBoost=r.bunnyBoostT>0;
  const maxSp=(30+st.spd*.625)*handi*(boosting?1.38:1)*(bunnyBoost?1.2:1)*(driftForwardBoost?DRIFT_FORWARD_SPEED_MULT:1)*(r.wallT>0?.8:1);
  const acc=(boosting?58:(11+st.acc*1.0)*(r.isPlayer?1:1.02*handi))*(driftForwardBoost?DRIFT_FORWARD_ACCEL_MULT:1);
  // longitudinal
  if(thr>0){if(vf<maxSp)vf=Math.min(maxSp,vf+acc*thr*dt);else vf-=(vf-maxSp)*1.4*dt;}
  else vf-=vf*Math.min(1,.55*dt);
  if(brk>0){vf-=(vf>0?42:12)*dt;if(vf<-9)vf=-9;}
  if(r.stunT>0)vf-=vf*Math.min(1,2.2*dt);
  // lateral grip
  const grip=r.drifting?1.45:(r.air?3.5:8.5);
  vs*=Math.exp(-grip*dt);
  // steering
  const sf=clamp(Math.abs(vf)/9,0,1)*(1-.3*clamp(vf/maxSp,0,1));
  let om;
  if(r.drifting)om=r.isPlayer&&!SV.classicDrift?(r.driftDir*.8+r.steer*.58)*trn*1.13*sf:(r.driftDir*.72+r.steer*.82)*trn*1.02*sf*driftTightenAmount(r);
  else om=r.steer*trn*sf*(vf<0?-1:1)*(r.air?.4:1);
  if(r.wallT>0)r.wallT-=dt;
  r.h+=om*dt;
  if(r.stunT>0)om=0;
  const c2=Math.cos(r.h),s2=Math.sin(r.h);
  r.vx=c2*vf-s2*vs;r.vy=s2*vf+c2*vs;
  r.x+=r.vx*dt;r.y+=r.vy*dt;
  r.speed=Math.hypot(r.vx,r.vy);
  // vertical
  if(r.air){
    r.z+=r.vz*dt;r.vz-=34*dt;
    if(r.z<=0&&r.vz<0){r.z=0;r.vz=0;r.air=false;landed(r);}
  }
  // trail
  r.trailT+=dt;const trailStep=lowDetail()?(r.isPlayer?.032:.065):.022,trailMax=lowDetail()?(r.isPlayer?6:3):9;if(r.trailT>trailStep){r.trailT=0;r.trail.unshift({x:r.x,y:r.y,z:r.z,baseZ:r.baseZ||0});if(r.trail.length>trailMax)r.trail.length=trailMax;}
  // trick spin visual
  if(r.tricks){r.trickRot*=Math.exp(-3*dt);}else r.trickRot=0;
  // particles
  if(r.drifting&&Math.random()<.9*particleScale()){const lvl=driftLevel(r),kartCol=r.kartFlicks>=KART_DRIFT_ORANGE_FLICKS?'#ff9f43':r.kartFlicks>=KART_DRIFT_BLUE_FLICKS?'#52c8ff':null;const col=r.isPlayer&&!SV.classicDrift&&kartCol?kartCol:lvl>=3?'#c27aff':lvl===2?'#ffb02e':lvl===1?'#52c8ff':'#ffffff';
    const bx=r.x-c2*1.6,by=r.y-s2*1.6;addPart(bx+rnd(-.5,.5),by+rnd(-.5,.5),.3,-c2*rnd(4,10)+rnd(-3,3),-s2*rnd(4,10)+rnd(-3,3),rnd(2,5),.35,2,col);}
  if(boosting&&Math.random()<.9*particleScale()){const bx=r.x-c2*1.9,by=r.y-s2*1.9;addPart(bx,by,.5+r.z,-c2*rnd(12,20)+rnd(-2,2),-s2*rnd(12,20)+rnd(-2,2),rnd(0,3),.3,3,Math.random()<.5?'#ffd25a':'#ff7a3a',-1);}
  const goldPieces=(r.boardId==='gold'?1:0)+(r.hatId==='gold'?1:0);if(goldPieces&&Math.random()<(holySetActive(r)?.98:.72)*particleScale()){const bx=r.x-c2*rnd(holySetActive(r)?2.2:1.6,holySetActive(r)?4.2:2.8),by=r.y-s2*rnd(1.6,2.8);addPart(bx+rnd(-.65,.65),by+rnd(-.65,.65),.35+r.z+rnd(0,holySetActive(r)?1.2:.6),-c2*rnd(holySetActive(r)?4:2,holySetActive(r)?12:7)+rnd(-2,2),-s2*rnd(2,8)+rnd(-2,2),rnd(.5,holySetActive(r)?4.5:2.8),rnd(.45,holySetActive(r)?.9:.65),rnd(holySetActive(r)?2.2:1.2,holySetActive(r)?4.8:2.8),Math.random()<.6?'#ffd84d':'#fff3a6',5);}
  if(prideSetActive(r)&&Math.random()<.9*particleScale()){const bx=r.x-c2*rnd(1.8,3.4),by=r.y-s2*rnd(1.6,2.7);addPart(bx+rnd(-.6,.6),by+rnd(-.6,.6),.4+r.z+rnd(0,.8),-c2*rnd(3,10)+rnd(-2,2),-s2*rnd(3,10)+rnd(-2,2),rnd(.4,3.8),rnd(.35,.75),rnd(1.8,3.8),Math.random()<.55?'#1686ff':'#9bdcff',3);}
  if(r.invincibleT>0&&Math.random()<.98*particleScale()){const bx=r.x-c2*rnd(2,4),by=r.y-s2*rnd(1.5,3);addPart(bx+rnd(-.7,.7),by+rnd(-.7,.7),.4+r.z+rnd(0,1.1),-c2*rnd(5,13)+rnd(-2,2),-s2*rnd(3,9)+rnd(-2,2),rnd(.5,4.2),rnd(.4,.85),rnd(2,4.5),Math.random()<.55?'#8b5a2b':'#d0a06a',4);}
  if(!r.air&&r.speed>10&&Math.random()<.25*particleScale())addPart(r.x-c2*1.8+rnd(-.5,.5),r.y-s2*1.8+rnd(-.5,.5),.2,rnd(-1,1),rnd(-1,1),rnd(.5,2),.45,2,'rgba(190,230,255,.7)',-1);
  updateRacerState(r,dt);
}
function driftLevel(r){const q=r.driftMeter/DRIFT_METER_MAX;return q>=.75?3:q>=.5?2:q>=.25?1:0;}
function endDrift(r){if(!r.drifting)return;const endedDir=r.driftDir;if(r.isPlayer&&!SV.classicDrift&&r.driftT>.25&&r.kartFlicks>=KART_DRIFT_BLUE_FLICKS){const orange=r.kartFlicks>=KART_DRIFT_ORANGE_FLICKS,dur=orange?KART_DRIFT_ORANGE_BOOST:KART_DRIFT_BLUE_BOOST;r.boostT=Math.max(r.boostT,dur);SFX.boost();bannerAdd(orange?'ORANGE MINI-TURBO!':'BLUE MINI-TURBO!',orange?'#ff9f43':'#52c8ff',1.05);}r.drifting=false;r.lastDriftDir=endedDir;r.transitionT=TRANSITION_SECONDS;r.driftT=0;r.driftDirT=0;r.kartFlicks=0;r.kartLastSteer=0;}
function landed(r){
  if(r.hop){r.hop=false;return;}
  const c=Math.cos(r.h),s=Math.sin(r.h);
  burst(r.x,r.y,.2,10,'rgba(210,240,255,.9)',10,.5,3);
  if(r.isPlayer)SFX.land();
  if(r.tricks){
    const tk=r.tricks,n=tk.seq.length;
    if(tk.prog>=n){r.boostT=Math.max(r.boostT,.9+.5*n);if(r.isPlayer){SFX.perfect();G.perfects++;bannerAdd('PERFECT '+['','','DOUBLE','TRIPLE','QUAD'][n]+' TRICK!','#ffe14a',1.5);}}
    else if(tk.prog>0){r.boostT=Math.max(r.boostT,.4*tk.prog);if(r.isPlayer){SFX.boost();bannerAdd('Trick boost','#9be8ff',1);}}
    r.tricks=null;
  }else if(r.trickWill){const n=r.aiTrickN||2;r.boostT=Math.max(r.boostT,.9+.5*n);r.trickWill=false;}
}
function trickKey(code){
  const r=G.player;if(!r||!r.air||!r.tricks||r.hop)return;
  const k=({KeyA:'A',KeyS:'S',KeyD:'D',KeyF:'F'})[code];if(!k)return;
  const tk=r.tricks;if(tk.prog>=tk.seq.length)return;
  if(tk.seq[tk.prog]===k){tk.prog++;r.trickRot+=Math.PI*1.4;SFX.trick();burst(r.x,r.y,r.z+2,6,'#ffe14a',10,.4,2);}
  else{tk.err=.3;}
}

function trainingInteract(r,dt){
  const pr=1.6;
  if(r.x<TRAIN.xmin+pr){r.x=TRAIN.xmin+pr;if(r.vx<0)r.vx*=-.45;}
  if(r.x>TRAIN.xmax-pr){r.x=TRAIN.xmax-pr;if(r.vx>0)r.vx*=-.45;}
  if(r.y<TRAIN.ymin+pr){r.y=TRAIN.ymin+pr;if(r.vy<0)r.vy*=-.45;}
  if(r.y>TRAIN.ymax-pr){r.y=TRAIN.ymax-pr;if(r.vy>0)r.vy*=-.45;}
  if(!r.air)for(const o of TRAIN.obstacles){const dx=r.x-o.x,dy=r.y-o.y,d=Math.hypot(dx,dy),md=o.r+pr;if(d<md){const nx=d>.01?dx/d:1,ny=d>.01?dy/d:0,over=md-d;r.x+=nx*over;r.y+=ny*over;const vn=r.vx*nx+r.vy*ny;if(vn<0){r.vx-=1.35*vn*nx;r.vy-=1.35*vn*ny;r.vx*=.82;r.vy*=.82;if(-vn>5){SFX.wall();G.shake=Math.max(G.shake,4);burst(r.x,r.y,.8,8,'#ffe9a0',14,.4,2);}}}}
  if(!r.air&&r.rampCool<=0)for(const rp of TRAIN.ramps){const cs=Math.cos(rp.rot),sn=Math.sin(rp.rot),dx=r.x-rp.x,dy=r.y-rp.y,lx=dx*cs+dy*sn,ly=-dx*sn+dy*cs,forward=r.vx*cs+r.vy*sn;const entry=lx>-rp.len/2&&lx<-rp.len/2+3;if(entry&&Math.abs(ly)<rp.w/2&&forward>9){r.air=true;r.vz=rp.vz;r.hop=false;r.rampCool=1.2;r.drifting=false;r.driftT=0;r.driftDirT=0;const keysS=['A','S','D','F'],comboN=jumpComboKeys(),seq=[];for(let i=0;i<comboN;i++){let k;do{k=pick(keysS);}while(i&&k===seq[i-1]);seq.push(k);}r.tricks={seq,prog:0,err:0};r.trickRot=0;SFX.launch();break;}}
  if(!r.air)for(const p of TRAIN.pads){const cs=Math.cos(p.rot),sn=Math.sin(p.rot),dx=r.x-p.x,dy=r.y-p.y,lx=dx*cs+dy*sn,ly=-dx*sn+dy*cs;if(Math.abs(lx)<p.len/2&&Math.abs(ly)<p.w/2){if(r.boostT<.5)SFX.boost();r.boostT=Math.max(r.boostT,1.4);}}
}

/* track interaction: walls, ramps, pads, laps */
function trackInteract(r,dt){
  trkQuery(r.x,r.y,r.idx);
  const prevIdx=r.idx,N=T.N;
  r.idx=Q.i;r.s=Q.s;r.baseZ=T.z[Q.i]||0;
  if(prevIdx>N*.8&&r.idx<N*.2){r.crossed++;onCross(r,1);}
  else if(prevIdx<N*.2&&r.idx>N*.8){r.crossed--;}
  r.prog=(r.crossed-1)*T.L+r.s;
  const half=Q.w/2-1.2;
  if(!T.cross[Q.i]&&Math.abs(Q.lat)>half){
    const sg=Math.sign(Q.lat),nx=-sg*T.nx[Q.i],ny=-sg*T.ny[Q.i],over=Math.abs(Q.lat)-half;
    r.x+=nx*over;r.y+=ny*over;
    const vn=r.vx*nx+r.vy*ny;
    if(vn<0){
      r.vx-=1.25*vn*nx;r.vy-=1.25*vn*ny;
      if(-vn>5){r.vx*=.9;r.vy*=.9;burst(r.x-nx*1.2,r.y-ny*1.2,.8,8,'#ffe9a0',16,.4,2);if(r.isPlayer){SFX.wall();G.shake=Math.max(G.shake,Math.min(8,-vn*.4));}}
    }
    r.h+=angDiff(r.h,Math.atan2(T.ty[Q.i],T.tx[Q.i]))*Math.min(1,dt*2.5);r.wallT=.15;
    if(r.drifting&&-vn>8)endDrift(r);
  }
  // ramps
  if(!r.air&&r.rampCool<=0){
    for(const rp of FEAT.ramps){
      const d=wrapD(Q.s-rp.s,T.L);
      if(d>0&&d<rp.len&&Math.abs(Q.lat-rp.lat)<rp.w/2&&(r.vx*T.tx[Q.i]+r.vy*T.ty[Q.i])>10){
        r.air=true;r.vz=rp.vz*(.85+.15*Math.min(1,r.speed/38));r.hop=false;r.rampCool=1.2;r.drifting=false;r.driftT=0;r.driftDirT=0;
        const keysS=['A','S','D','F'],comboN=r.isPlayer?jumpComboKeys():BASE_COMBO_KEYS[SV.diff];const seq=[];for(let i=0;i<comboN;i++){let k;do{k=pick(keysS);}while(i>0&&k===seq[i-1]);seq.push(k);}
        if(r.isPlayer){r.tricks={seq,prog:0,err:0};r.trickRot=0;SFX.launch();}
        else{r.tricks=null;r.trickWill=Math.random()<.5+.4*(r.skill-.94)/.09;r.aiTrickN=comboN;}
        break;
      }
    }
  }
  // boost pads
  if(!r.air){
    for(const p of FEAT.pads){
      const d=wrapD(Q.s-p.s,T.L);
      if(d>0&&d<p.len&&Math.abs(Q.lat-p.lat)<p.w/2){if(r.boostT<.5&&r.isPlayer)SFX.boost();r.boostT=Math.max(r.boostT,1.4);}
    }
  }
}
function onCross(r,dir){
  if(r.crossed>=2&&r.crossed<=G.laps+1){
    const lt=G.raceTime-r.lapStart;r.lapTimes.push(lt);r.lapStart=G.raceTime;
    if(r.isPlayer&&r.crossed<=G.laps){SFX.lap();bannerAdd(r.crossed===G.laps?'FINAL LAP!':'LAP '+r.crossed+' / '+G.laps,'#ffffff',1.6);}
  }
  if(r.crossed===1){r.lapStart=G.raceTime;}
  r.lap=clamp(r.crossed,1,G.laps);
}

function invincibleTouchWipeout(v,by){if(!v||v.setTouchT>0||v.finished||invincibleStateActive(v))return;const brown=by&&by.invincibleT>0,col=brown?'#8b5a2b':'#ffd84d';dropCarriedPickup(v);v.shieldT=0;v.stunT=Math.max(v.stunT,1.35);v.invT=1.6;v.vx*=.22;v.vy*=.22;v.spin=0;v.setTouchT=.7;burst(v.x,v.y,2,26,col,24,.85,3);if(by?.isPlayer){SFX.hit();bannerAdd((brown?'BROWN NOSE':'HOLY GRAIL')+' WIPEOUT · '+v.name+'!',col,1.15);}}
function raceCollisions(){
  const R=G.racers;
  for(let i=0;i<R.length;i++)for(let j=i+1;j<R.length;j++){
    const a=R[i],b=R[j];if(Math.abs(a.z-b.z)>2)continue;
    const dx=b.x-a.x,dy=b.y-a.y,d=Math.hypot(dx,dy);
    if(d<2.7&&d>.001){if(a.isPlayer&&invincibleStateActive(a)&&!invincibleStateActive(b))invincibleTouchWipeout(b,a);else if(b.isPlayer&&invincibleStateActive(b)&&!invincibleStateActive(a))invincibleTouchWipeout(a,b);
      const nx=dx/d,ny=dy/d,ov=2.7-d;
      a.x-=nx*ov/2;a.y-=ny*ov/2;b.x+=nx*ov/2;b.y+=ny*ov/2;
      const rv=(b.vx-a.vx)*nx+(b.vy-a.vy)*ny;
      if(rv<0){const imp=-rv*.6;a.vx-=nx*imp;a.vy-=ny*imp;b.vx+=nx*imp;b.vy+=ny*imp;
        if(-rv>4&&(a.isPlayer||b.isPlayer)){SFX.wall();G.shake=Math.max(G.shake,3);}
        if(-rv>4)burst((a.x+b.x)/2,(a.y+b.y)/2,1.5,5,'#fff2b0',12,.3,2);}
    }
  }
}
function computeRanks(){
  const arr=G.racers.slice().sort((a,b)=>{
    if(a.finished&&b.finished)return a.finishTime-b.finishTime;
    if(a.finished)return-1;if(b.finished)return 1;return b.prog-a.prog;});
  arr.forEach((r,i)=>r.rank=i+1);
  return arr;
}

/* ===================== AI ===================== */
function aiControl(r,dt){
  const inp=r.inp,spd=r.speed;
  inp.drift=false;inp.brk=0;
  if(r.finished){trkAt(r.s+14,0);const want=Math.atan2(trkAt.y-r.y,trkAt.x-r.x);inp.steer=clamp(angDiff(r.h,want)*2.2,-1,1);inp.thr=spd<26?1:0;return;}
  if(r.blindT>0){r.blindWanderT-=dt;if(r.blindWanderT<=0){r.blindWanderT=rnd(.22,.48);r.blindSteer=rnd(-1,1);}inp.steer=r.blindSteer;inp.thr=.62;inp.brk=0;return;}
  r.aiT-=dt;
  if(r.aiT<=0){r.aiT=rnd(1.4,3.4);r.aiLat=rnd(-6,6);}
  // dodge mines
  for(const m of G.mines){if(m.owner===r&&m.t<3)continue;const dd=wrapD(0,1);const dx=m.x-r.x,dy=m.y-r.y,d=Math.hypot(dx,dy);if(d<20&&Math.abs(angDiff(r.h,Math.atan2(dy,dx)))<.5){trkQuery(m.x,m.y,r.idx);r.aiLat=Q.lat>0?Q.lat-6:Q.lat+6;r.aiT=1;}}
  const lim=T.w[r.idx]/2-3.2;r.aiLat=clamp(r.aiLat,-lim,lim);
  r.aiLatS+=(r.aiLat-r.aiLatS)*Math.min(1,dt*1.6);
  const look=8+spd*.5;
  trkAt(r.s+look,r.aiLatS);
  const want=Math.atan2(trkAt.y-r.y,trkAt.x-r.x),da=angDiff(r.h,want);
  inp.steer=clamp(da*2.6,-1,1);
  inp.thr=Math.abs(da)>1.1?.35:1;
  // corner boost
  const k=Math.abs(T.k[r.idx]);
  if(k>.012)r.cornerT+=dt;else{if(r.cornerT>1.1&&Math.random()<.35+.5*(r.skill-.94)/.09){r.boostT=Math.max(r.boostT,.55+Math.min(1,r.cornerT-1)*.6);}r.cornerT=0;}
  // rubber band
  if(G.player&&!G.player.finished){const gap=G.player.prog-r.prog;r.rb=clamp(gap/300,-.045,.075);}else r.rb=0;
  // items
  if(hasCarriedItem(r)&&!r.roll){
    r.aiItemT-=dt;
    if(r.aiItemT<=0){
      let use=false;
      if(r.item==='shield')use=true;
      else if(r.item==='boost'||r.item==='tripulse')use=k<.006;
      else if(r.item==='flash')use=true;
      else if(r.item==='shift')use=k>.006||r.speed<12;
      else if(r.item==='culture')use=true;
      else if(r.item==='missile'){for(const o of G.racers){if(o===r||o.finished)continue;const dx=o.x-r.x,dy=o.y-r.y,d=Math.hypot(dx,dy);if(d<55&&d>6&&Math.abs(angDiff(r.h,Math.atan2(dy,dx)))<.35){use=true;break;}}}
      else if(r.item==='mine'){for(const o of G.racers){if(o===r)continue;const dx=o.x-r.x,dy=o.y-r.y,d=Math.hypot(dx,dy);if(d<24&&Math.abs(angDiff(r.h+Math.PI,Math.atan2(dy,dx)))<.6){use=true;break;}}}
      else if(r.item==='emp'){let n=0;for(const o of G.racers){if(o===r)continue;if(Math.hypot(o.x-r.x,o.y-r.y)<24)n++;}use=n>=1;}
      if(use)useItem(r,0);else r.aiItemT=.4;
    }
  }
}

/* ===================== RENDERING HELPERS ===================== */
function rr(c,x,y,w,h,r){c.beginPath();c.moveTo(x+r,y);c.arcTo(x+w,y,x+w,y+h,r);c.arcTo(x+w,y+h,x,y+h,r);c.arcTo(x,y+h,x,y,r);c.arcTo(x,y,x+w,y,r);c.closePath();}
function poly(c,pts,fill,stroke,lw){c.beginPath();c.moveTo(pts[0],pts[1]);for(let i=2;i<pts.length;i+=2)c.lineTo(pts[i],pts[i+1]);c.closePath();if(fill){c.fillStyle=fill;c.fill();}if(stroke){c.lineWidth=lw||1;c.strokeStyle=stroke;c.stroke();}}
function ell(c,x,y,rx,ry,fill){c.beginPath();c.ellipse(x,y,rx,ry,0,0,TAU);c.fillStyle=fill;c.fill();}
const GZ=-.8;

/* ---------- anime rider (screen space, feet at origin) ---------- */
function drawDJAssembler(c,x,y,s,ch,o){
  o=o||{};const lean=o.lean||0,fx=o.fx||0,t=o.t||0;
  c.save();c.translate(x,y);c.scale(s*.96,s*1.035);if(o.rot)c.rotate(o.rot);c.lineCap='round';c.lineJoin='round';
  const skin=ch.skin||'#f0c8a8',ax=lean*3;
  c.fillStyle='#263746';rr(c,-8+ax,-15,7,15,3);c.fill();rr(c,1+ax,-15,7,15,3);c.fill();
  c.fillStyle='#1b1f24';ell(c,-5+ax,-1,6,3,c.fillStyle);ell(c,5+ax,-1,6,3,c.fillStyle);
  c.strokeStyle=shade(ch.outfit,.78);c.lineWidth=5;c.beginPath();c.moveTo(-9+ax,-29);c.lineTo(-15+ax,-16);c.moveTo(9+ax,-29);c.lineTo(15+ax,-16);c.stroke();
  c.fillStyle=skin;ell(c,-15+ax,-15,3,3,skin);ell(c,15+ax,-15,3,3,skin);
  c.fillStyle=ch.outfit;rr(c,-10+ax,-34,20,21,5);c.fill();
  c.fillStyle='#f2c500';c.fillRect(-8+ax,-25,16,3);c.fillStyle='#28323b';poly(c,[ax,-32,ax-2,-25,ax,-19,ax+2,-25],c.fillStyle);
  const hx=lean*4,hy=-47;c.fillStyle=skin;c.beginPath();c.ellipse(hx,hy+2,15.5,14,0,0,TAU);c.fill();
  // Exposed sparse, high-sided hair with a small M-shaped forelock.
  c.fillStyle=ch.hair2;c.beginPath();c.arc(hx,hy,15.4,Math.PI*.93,Math.PI*1.18);c.lineTo(hx-9,hy-7);c.closePath();c.fill();c.beginPath();c.arc(hx,hy,15.4,Math.PI*1.82,Math.PI*2.07);c.lineTo(hx+9,hy-7);c.closePath();c.fill();poly(c,[hx-5,hy-10,hx-1,hy-14,hx+1,hy-10,hx+5,hy-14,hx+7,hy-8],ch.hair2);
  for(const ex of[-1,1]){c.fillStyle='#fff';ell(c,hx+ex*5+fx*2,hy+2,3.5,4.2,'#fff');ell(c,hx+ex*5+fx*2,hy+2,1.5,2.2,ch.eye);}
  c.strokeStyle='#263746';c.lineWidth=2;c.strokeRect(hx-11,hy-3,9,9);c.strokeRect(hx+2,hy-3,9,9);c.beginPath();c.moveTo(hx-2,hy+1);c.lineTo(hx+2,hy+1);c.stroke();
  // Connected gray goatee: the mustache sits slightly lower and overlaps both jaw connectors.
   c.fillStyle='#74777b';
   c.beginPath();c.moveTo(hx-6.7,hy+7.4);c.quadraticCurveTo(hx-3.4,hy+5.5,hx,hy+7.6);c.quadraticCurveTo(hx+3.4,hy+5.5,hx+6.7,hy+7.4);c.lineTo(hx+5.2,hy+10.3);c.quadraticCurveTo(hx+2.6,hy+8.7,hx,hy+10);c.quadraticCurveTo(hx-2.6,hy+8.7,hx-5.2,hy+10.3);c.closePath();c.fill();
   c.beginPath();c.moveTo(hx-6.3,hy+9.3);c.quadraticCurveTo(hx-5.8,hy+14,hx-2.8,hy+15.5);c.quadraticCurveTo(hx,hy+18.2,hx+2.8,hy+15.5);c.quadraticCurveTo(hx+5.8,hy+14,hx+6.3,hy+9.3);c.lineTo(hx+4.2,hy+10.2);c.quadraticCurveTo(hx+3.6,hy+13,hx+2,hy+13.9);c.quadraticCurveTo(hx,hy+15.1,hx-2,hy+13.9);c.quadraticCurveTo(hx-3.6,hy+13,hx-4.2,hy+10.2);c.closePath();c.fill();
   c.strokeStyle='#9a493f';c.lineWidth=1.15;c.beginPath();c.moveTo(hx-2.7+fx,hy+11.5);c.quadraticCurveTo(hx+fx,hy+12.5,hx+2.7+fx,hy+11.5);c.stroke();
  // DJ carries a vinyl record.
  c.save();c.translate(18+ax,-18);c.rotate(-.18+lean*.08);ell(c,0,0,9.5,9.5,'#17191d');ell(c,0,0,4,4,'#e63b73');ell(c,0,0,1.3,1.3,'#f4e7b2');c.strokeStyle='rgba(255,255,255,.28)';c.lineWidth=.8;c.beginPath();c.arc(0,0,7,0,TAU);c.stroke();c.restore();
  c.restore();
}
function drawBrettKoolAid(c,x,y,s,ch,o){
  o=o||{};const lean=o.lean||0,fx=o.fx||0;c.save();c.translate(x,y);c.scale(s,s);if(o.rot)c.rotate(o.rot);c.lineCap='round';c.lineJoin='round';
  c.strokeStyle='#8f1024';c.lineWidth=5;c.beginPath();c.moveTo(-9,-17);c.lineTo(-14,-4);c.moveTo(9,-17);c.lineTo(14,-4);c.stroke();c.fillStyle='#6b1320';ell(c,-14,-2,6,3,c.fillStyle);ell(c,14,-2,6,3,c.fillStyle);
  c.strokeStyle='#c1152c';c.lineWidth=6;c.beginPath();c.moveTo(-14,-42);c.lineTo(-23-lean*4,-25);c.moveTo(14,-42);c.lineTo(24+lean*4,-25);c.stroke();ell(c,-24-lean*4,-24,4,4,'#d91b36');ell(c,25+lean*4,-24,4,4,'#d91b36');
  c.fillStyle='#d71936';c.beginPath();c.moveTo(-17,-55);c.quadraticCurveTo(-21,-28,-12,-14);c.quadraticCurveTo(0,-8,12,-14);c.quadraticCurveTo(21,-28,17,-55);c.closePath();c.fill();c.strokeStyle='#8e1022';c.lineWidth=2;c.stroke();
  // Solid red pitcher handle with a darker outside edge.
  c.strokeStyle='#8e1022';c.lineWidth=7;c.beginPath();c.arc(17,-40,12,-1.25,1.25);c.stroke();c.strokeStyle='#d71936';c.lineWidth=4;c.beginPath();c.arc(17,-40,12,-1.25,1.25);c.stroke();
  c.fillStyle='#e81e3c';c.beginPath();c.ellipse(0,-57,18,8,0,0,TAU);c.fill();c.strokeStyle='#8e1022';c.stroke();c.fillStyle='rgba(255,255,255,.35)';c.beginPath();c.ellipse(-4,-59,10,3,0,0,TAU);c.fill();
  // Original smiling red-pitcher mascot face; no employee portrait asset is used.
  c.save();c.beginPath();c.arc(fx*1.5,-40,14.5,0,TAU);c.clip();ell(c,-5+fx,-43,3.4,4.8,'#050505');ell(c,5+fx,-43,3.4,4.8,'#050505');c.fillStyle='#050505';c.beginPath();c.arc(fx,-37,8.5,.12,Math.PI-.12);c.quadraticCurveTo(fx,-29,fx-8.5,-37);c.closePath();c.fill();c.restore();
  // Small charcoal chin beard: the lower half of a goatee, below the mascot smile.
  c.fillStyle='#292929';c.beginPath();c.moveTo(fx-5,-27);c.quadraticCurveTo(fx-4,-22,fx,-20);c.quadraticCurveTo(fx+4,-22,fx+5,-27);c.quadraticCurveTo(fx,-24,fx-5,-27);c.closePath();c.fill();
  c.fillStyle='rgba(255,255,255,.28)';c.beginPath();c.ellipse(-10,-43,3,10,-.3,0,TAU);c.fill();
  // BC carries a cell phone.
  c.save();c.translate(25+lean*4,-24);c.rotate(.12);c.fillStyle='#111820';rr(c,-3.5,-6,7,12,1.4);c.fill();c.fillStyle='#69d7ff';rr(c,-2.4,-4.6,4.8,8.3,.7);c.fill();c.fillStyle='#fff';c.globalAlpha=.8;c.fillRect(-1.6,-3.5,3.2,.8);c.restore();
  c.restore();
}

function drawJenkinsManager(c,x,y,s,ch,o){
  o=o||{};const lean=o.lean||0,fx=o.fx||0;c.save();c.translate(x,y);c.scale(s,s);if(o.rot)c.rotate(o.rot);c.lineCap='round';c.lineJoin='round';
  const skin=ch.skin,ax=lean*3;
  c.fillStyle='#26313a';rr(c,-10+ax,-17,8,17,3);c.fill();rr(c,2+ax,-17,8,17,3);c.fill();ell(c,-6+ax,-1,7,3,'#111820');ell(c,7+ax,-1,7,3,'#111820');
  c.strokeStyle=shade(ch.outfit,.76);c.lineWidth=6;c.beginPath();c.moveTo(-12+ax,-31);c.lineTo(-19+ax,-16);c.moveTo(12+ax,-31);c.lineTo(19+ax,-16);c.stroke();ell(c,-19+ax,-15,3.4,3.4,skin);ell(c,19+ax,-15,3.4,3.4,skin);
  c.fillStyle=ch.outfit;rr(c,-14+ax,-38,28,25,8);c.fill();c.strokeStyle='#2f3942';c.lineWidth=1.2;c.beginPath();c.arc(ax,-35,7,0,Math.PI);c.stroke();
  c.strokeStyle='#e6bd38';c.lineWidth=1.6;c.beginPath();c.moveTo(-7+ax,-34);c.lineTo(ax,-27);c.lineTo(7+ax,-34);c.stroke();
  const hx=lean*4,hy=-51;c.fillStyle=skin;ell(c,hx,hy+2,14.5,13.5,skin);
   // Lined-up very short black hair: one clean semicircle with no side curls.
   c.fillStyle='#080706';c.beginPath();c.ellipse(hx,hy-3,12.8,8.5,0,Math.PI,TAU);c.lineTo(hx+12.8,hy-3);c.lineTo(hx-12.8,hy-3);c.closePath();c.fill();c.fillStyle='rgba(255,255,255,.12)';ell(c,hx-4,hy-7.5,3.5,1.1,c.fillStyle);
  for(const ex of[-1,1]){ell(c,hx+ex*5+fx*2,hy+2,3.1,3.6,'#fff');ell(c,hx+ex*5+fx*2,hy+2,1.5,2.1,ch.eye);}
  c.strokeStyle='#2b1710';c.lineWidth=1.4;c.beginPath();c.arc(hx+fx,hy+8,3,.15,Math.PI-.1);c.stroke();
  // Cigar stays in Jenkins's hand, not his mouth.
  c.save();c.translate(18+ax,-15);c.rotate(-.18);c.fillStyle='#8b4a22';rr(c,0,-1.6,14,3.2,1.3);c.fill();c.fillStyle='#d8b06b';c.fillRect(10,-1.6,2,3.2);c.fillStyle='#ef6a32';c.fillRect(13,-1.5,1.6,3);c.restore();
  c.restore();
}
function drawDallasGolf(c,x,y,s,ch,o){
  o=o||{};const lean=o.lean||0,fx=o.fx||0,skin=ch.skin;c.save();c.translate(x,y);c.scale(s,s);if(o.rot)c.rotate(o.rot);c.lineCap='round';c.lineJoin='round';
  // Golf bag behind the very tall, slightly broad silhouette.
  c.save();c.translate(13,-34);c.rotate(-.18);c.fillStyle='#133e68';rr(c,-6,-25,12,38,5);c.fill();c.strokeStyle='#8fd7ff';c.lineWidth=2;c.stroke();for(let i=-1;i<=1;i++){c.strokeStyle=['#ddd','#f2c500','#9ad7ff'][i+1];c.lineWidth=1.8;c.beginPath();c.moveTo(i*3,-24);c.lineTo(i*4,-37);c.stroke();ell(c,i*4,-38,3,1.5,'#3b4650');}c.restore();
  c.fillStyle='#18314b';rr(c,-10,-22,8,22,3);c.fill();rr(c,2,-22,8,22,3);c.fill();ell(c,-6,-1,7,3,'#fff');ell(c,7,-1,7,3,'#fff');
  c.strokeStyle='#1769aa';c.lineWidth=6;c.beginPath();c.moveTo(-13,-43);c.lineTo(-21,-23);c.moveTo(13,-43);c.lineTo(21,-23);c.stroke();ell(c,-21,-22,3.6,3.6,skin);ell(c,21,-22,3.6,3.6,'#eef4f7');
  c.fillStyle=ch.outfit;rr(c,-14+lean*2,-49,28,30,8);c.fill();c.fillStyle='#8fd7ff';c.fillRect(-14+lean*2,-31,28,4);c.fillStyle='#fff';c.font='bold 6px sans-serif';c.textAlign='center';c.fillText('dirdygolf',lean*2,-37);
  const hx=lean*3,hy=-63;ell(c,hx,hy+3,14,13,skin);
  // Hat removed: brown hair is combed into a slicked-back wave.
  c.fillStyle=ch.hair2;c.beginPath();c.arc(hx,hy-3,14,Math.PI*.96,TAU*1.01);c.lineTo(hx+11,hy-3);c.quadraticCurveTo(hx+4,hy-13,hx-10,hy-8);c.closePath();c.fill();c.fillStyle=ch.hair;c.beginPath();c.moveTo(hx-12,hy-5);c.quadraticCurveTo(hx-4,hy-14,hx+10,hy-8);c.quadraticCurveTo(hx+5,hy-4,hx-11,hy-1);c.closePath();c.fill();c.strokeStyle='rgba(255,255,255,.22)';c.lineWidth=1.2;c.beginPath();c.moveTo(hx-7,hy-7);c.quadraticCurveTo(hx,hy-11,hx+8,hy-8);c.stroke();
  c.fillStyle='rgba(35,55,80,.76)';rr(c,hx-11,hy-1,9,7,2);c.fill();rr(c,hx+2,hy-1,9,7,2);c.fill();c.strokeStyle='#9ad7ff';c.lineWidth=1.5;c.strokeRect(hx-11,hy-1,9,7);c.strokeRect(hx+2,hy-1,9,7);c.beginPath();c.moveTo(hx-2,hy+2);c.lineTo(hx+2,hy+2);c.stroke();
   // Small black beard follows the outside jaw; the mustache connects into both sides.
   c.fillStyle='#17120f';c.beginPath();c.moveTo(hx-13,hy+4);c.quadraticCurveTo(hx-12,hy+12,hx-7,hy+15);c.quadraticCurveTo(hx,hy+20,hx+7,hy+15);c.quadraticCurveTo(hx+12,hy+12,hx+13,hy+4);c.lineTo(hx+9,hy+8);c.quadraticCurveTo(hx+5,hy+14,hx,hy+15);c.quadraticCurveTo(hx-5,hy+14,hx-9,hy+8);c.closePath();c.fill();c.beginPath();c.moveTo(hx-10,hy+7);c.quadraticCurveTo(hx-5,hy+4,hx,hy+7);c.quadraticCurveTo(hx+5,hy+4,hx+10,hy+7);c.lineTo(hx+8,hy+9);c.quadraticCurveTo(hx+3,hy+7,hx,hy+8.5);c.quadraticCurveTo(hx-3,hy+7,hx-8,hy+9);c.closePath();c.fill();c.strokeStyle='#8f4e43';c.lineWidth=1.2;c.beginPath();c.moveTo(hx-3+fx,hy+10);c.quadraticCurveTo(hx+fx,hy+11.5,hx+3+fx,hy+10);c.stroke();
  // Golf club in gloved right hand; rings on left.
  c.strokeStyle='#bcc8cf';c.lineWidth=2;c.beginPath();c.moveTo(22,-23);c.lineTo(31,-2);c.stroke();c.fillStyle='#414d54';rr(c,27,-4,9,4,1);c.fill();c.fillStyle='#f2c500';for(let q=0;q<3;q++)ell(c,-22+q*1.8,-22,1.2,1.2,'#f2c500');c.restore();
}
function drawCassandraQuality(c,x,y,s,ch,o){
  o=o||{};const lean=o.lean||0,fx=o.fx||0,skin=ch.skin;c.save();c.translate(x,y);c.scale(s,s);if(o.rot)c.rotate(o.rot);c.lineCap='round';c.lineJoin='round';
  c.fillStyle='#24588f';rr(c,-12,-19,10,19,4);c.fill();rr(c,2,-19,10,19,4);c.fill();ell(c,-8,-1,7,3,'#222a31');ell(c,8,-1,7,3,'#222a31');
  // Slightly curvier blouse silhouette with a defined waist and soft hips.
  c.fillStyle=ch.outfit;c.beginPath();c.moveTo(-14,-42);c.quadraticCurveTo(-17,-38,-16,-34);c.quadraticCurveTo(-12,-30,-11,-27);c.quadraticCurveTo(-15,-23,-16,-18);c.lineTo(16,-18);c.quadraticCurveTo(15,-23,11,-27);c.quadraticCurveTo(12,-30,16,-34);c.quadraticCurveTo(17,-38,14,-42);c.quadraticCurveTo(0,-48,-14,-42);c.fill();c.strokeStyle='#a9bdcc';c.lineWidth=1.5;c.stroke();
  c.strokeStyle='#dbe5ed';c.lineWidth=5.5;c.beginPath();c.moveTo(-12,-39);c.lineTo(-20,-22);c.moveTo(12,-39);c.lineTo(20,-22);c.stroke();ell(c,-20,-21,3.5,3.5,skin);ell(c,20,-21,3.5,3.5,skin);
  // Hat-free blonde updo with a compact bun, lowered to follow the head contour.
  const hx=lean*3,hy=-54,hairY=hy+1.25;c.fillStyle=ch.hair2;ell(c,hx,hairY-12,9,8,ch.hair2);ell(c,hx,hy+4,12.5,12,skin);c.fillStyle=ch.hair;c.beginPath();c.ellipse(hx,hairY-4,12.8,8,0,Math.PI,TAU);c.lineTo(hx+12.8,hairY-4);c.lineTo(hx-12.8,hairY-4);c.closePath();c.fill();c.beginPath();c.arc(hx-8,hairY-1,5,Math.PI*.8,Math.PI*1.48);c.strokeStyle=ch.hair;c.lineWidth=2.4;c.stroke();
  for(const ex of[-1,1]){ell(c,hx+ex*5+fx*2,hy+4,3.1,3.8,'#fff');ell(c,hx+ex*5+fx*2,hy+4,1.4,2,ch.eye);}c.strokeStyle='#b04a5a';c.lineWidth=1.3;c.beginPath();c.arc(hx+fx,hy+10,3,.1,Math.PI-.1);c.stroke();
  // A cluttered clipboard occupies Cassandra's other hand.
  c.save();c.translate(-23,-24);c.rotate(.12);c.fillStyle='#8a6138';rr(c,-8,-12,16,24,2);c.fill();c.fillStyle='#f7f2df';rr(c,-6,-10,12,20,1);c.fill();c.fillStyle='#526a78';rr(c,-3,-13,6,5,1);c.fill();c.strokeStyle='#d84c3e';c.lineWidth=1;c.beginPath();c.moveTo(-4,-5);c.lineTo(4,-5);c.moveTo(-4,-1);c.lineTo(3,-1);c.moveTo(-4,3);c.lineTo(5,3);c.stroke();c.fillStyle='#f2c500';c.fillRect(1,5,5,4);c.fillStyle='#68a7d0';c.fillRect(-6,6,5,3);c.restore();
  // Paper shopping bag packed with fictional snacks.
  c.save();c.translate(22,-21);c.rotate(-.12);c.fillStyle='#b57a42';c.beginPath();c.moveTo(-9,-9);c.lineTo(9,-9);c.lineTo(7,12);c.lineTo(-7,12);c.closePath();c.fill();c.strokeStyle='#72471f';c.lineWidth=1.4;c.stroke();c.beginPath();c.arc(0,-9,6,Math.PI,TAU);c.stroke();c.fillStyle='#e64b3c';rr(c,-7,-16,6,10,1.5);c.fill();c.fillStyle='#ffe05d';c.font='bold 4px sans-serif';c.textAlign='center';c.fillText('CHIPS',-4,-10);c.fillStyle='#4fae62';rr(c,1,-15,6,9,1.5);c.fill();c.fillStyle='#fff';ell(c,4,-11,2,2,'#fff');c.fillStyle='#6b3b24';for(let i=0;i<3;i++)ell(c,-3+i*3,4+(i%2)*3,1.7,1.2,'#6b3b24');c.restore();c.restore();
}
function drawRyanRotator(c,x,y,s,ch,o){
  o=o||{};const lean=o.lean||0,fx=o.fx||0,skin=ch.skin;c.save();c.translate(x,y);c.scale(s,s*1.045);if(o.rot)c.rotate(o.rot);c.lineCap='round';c.lineJoin='round';
  // Camo pants.
  c.fillStyle='#677448';rr(c,-10,-18,8,18,3);c.fill();rr(c,2,-18,8,18,3);c.fill();c.fillStyle='#3f4b32';c.fillRect(-9,-14,4,5);c.fillRect(4,-8,5,5);ell(c,-6,-1,7,3,'#20252a');ell(c,7,-1,7,3,'#20252a');
  // Masters-green graphic tee with a gold pin-and-hole mark.
  c.fillStyle=ch.outfit;rr(c,-12,-39,24,24,7);c.fill();c.fillStyle='#f2c500';c.font='bold 5px sans-serif';c.textAlign='center';c.fillText('MASTERS',0,-29);c.strokeStyle='#f2c500';c.lineWidth=1.2;c.beginPath();c.moveTo(0,-27);c.lineTo(0,-20);c.stroke();c.fillStyle='#f2c500';c.beginPath();c.moveTo(0,-27);c.lineTo(6,-25);c.lineTo(0,-23);c.closePath();c.fill();ell(c,0,-20,4,1.5,'#e8f0d0');
  c.strokeStyle=ch.outfit;c.lineWidth=6;c.beginPath();c.moveTo(-10,-35);c.lineTo(-18,-20);c.moveTo(10,-35);c.lineTo(18,-20);c.stroke();ell(c,-18,-19,3.5,3.5,skin);ell(c,18,-19,3.5,3.5,skin);
   const hx=lean*3,hy=-51;ell(c,hx,hy+2,14,13,skin);c.fillStyle='#b74224';c.beginPath();c.moveTo(hx-13,hy+4);c.quadraticCurveTo(hx-12,hy+15,hx-7,hy+18);c.quadraticCurveTo(hx,hy+22,hx+7,hy+18);c.quadraticCurveTo(hx+12,hy+15,hx+13,hy+4);c.lineTo(hx+9,hy+9);c.quadraticCurveTo(hx+5,hy+15,hx,hy+16);c.quadraticCurveTo(hx-5,hy+15,hx-9,hy+9);c.closePath();c.fill();
   // Connected mustache bridges the beard at the jaw edges while leaving a readable smile.
   c.fillStyle='#b74224';c.beginPath();c.moveTo(hx-10,hy+7);c.quadraticCurveTo(hx-5,hy+4,hx,hy+7);c.quadraticCurveTo(hx+5,hy+4,hx+10,hy+7);c.lineTo(hx+8,hy+9);c.quadraticCurveTo(hx+3,hy+7,hx,hy+8.5);c.quadraticCurveTo(hx-3,hy+7,hx-8,hy+9);c.closePath();c.fill();
   for(const ex of[-1,1]){ell(c,hx+ex*5+fx*2,hy+1,3.1,3.6,'#fff');ell(c,hx+ex*5+fx*2,hy+1,1.4,2,ch.eye);}c.strokeStyle='#7d2b22';c.lineWidth=1.35;c.beginPath();c.arc(hx+fx,hy+10,3.2,.15,Math.PI-.15);c.stroke();c.fillStyle='rgba(255,255,255,.2)';ell(c,hx-3,hy-8,5,2,c.fillStyle);
  // Safely cradled fictional boy baby in a blue onesie.
  c.save();c.translate(18,-25);c.rotate(.22);c.fillStyle='#69aee8';rr(c,-7,-5,14,16,5);c.fill();c.fillStyle='#fff';c.font='bold 5px sans-serif';c.textAlign='center';c.fillText('BOY',0,5);ell(c,0,-9,7,7,'#f1c9ad');c.fillStyle='#c59a6e';c.beginPath();c.arc(0,-12,6,Math.PI,TAU);c.fill();ell(c,-2,-8,1,1,'#333');ell(c,2,-8,1,1,'#333');c.strokeStyle=ch.outfit;c.lineWidth=2.2;c.beginPath();c.moveTo(-5,2);c.lineTo(-12,8);c.moveTo(5,2);c.lineTo(12,8);c.stroke();c.restore();c.restore();
}

function drawJGWireQueen(c,x,y,s,ch,o){
  o=o||{};const lean=o.lean||0,fx=o.fx||0,skin=ch.skin;c.save();c.translate(x,y);c.scale(s*.92,s*.92);if(o.rot)c.rotate(o.rot);c.lineCap='round';c.lineJoin='round';
   c.fillStyle=ch.outfit;rr(c,-9,-19,7,19,3);c.fill();rr(c,2,-19,7,19,3);c.fill();ell(c,-5.5,-1,6.5,3,'#20252a');ell(c,5.5,-1,6.5,3,'#20252a');
   // Continuous skin-tight hourglass torso: narrower upper half, defined waist, and rounded wider hips that taper flush to the legs.
   c.fillStyle=ch.outfit;c.beginPath();c.moveTo(-11.5,-42);c.quadraticCurveTo(-13,-39,-12,-35);c.quadraticCurveTo(-10,-31,-7.5,-29);c.quadraticCurveTo(-11.5,-27,-13,-23);c.quadraticCurveTo(-12.5,-20,-9,-18);c.lineTo(9,-18);c.quadraticCurveTo(12.5,-20,13,-23);c.quadraticCurveTo(11.5,-27,7.5,-29);c.quadraticCurveTo(10,-31,12,-35);c.quadraticCurveTo(13,-39,11.5,-42);c.quadraticCurveTo(0,-46,-11.5,-42);c.fill();c.strokeStyle=shade(ch.outfit,.72);c.lineWidth=1.2;c.stroke();
  c.strokeStyle=shade(ch.outfit,.76);c.lineWidth=5.5;c.beginPath();c.moveTo(-12,-39);c.lineTo(-20,-22);c.moveTo(12,-39);c.lineTo(20,-22);c.stroke();ell(c,-20,-21,3.5,3.5,skin);ell(c,20,-21,3.5,3.5,skin);
   const hx=lean*3,hy=-54;
   // Curly bun sits behind the back-right of the head instead of on top.
   c.fillStyle=ch.hair2;for(const q of[[9,-10],[13,-7],[11,-3],[7,-5]])ell(c,hx+q[0],hy+q[1],5.5,5.2,ch.hair2);ell(c,hx+10,hy-7,7.2,6.5,ch.hair);
   ell(c,hx,hy+3,13.5,12.5,skin);c.fillStyle=ch.hair2;c.beginPath();c.arc(hx,hy-3,13.5,Math.PI,TAU);c.fill();for(const q of[[-9,-7],[-4,-11],[2,-12],[8,-8]])ell(c,hx+q[0],hy+q[1],4.6,4.2,ch.hair);
  for(const ex of[-1,1]){ell(c,hx+ex*4.8+fx*2,hy+3,3.1,3.8,'#fff');ell(c,hx+ex*4.8+fx*2,hy+3,1.4,2,ch.eye);}c.strokeStyle='#273a58';c.lineWidth=1.6;c.strokeRect(hx-10,hy-1,8,7);c.strokeRect(hx+2,hy-1,8,7);c.beginPath();c.moveTo(hx-2,hy+2);c.lineTo(hx+2,hy+2);c.stroke();c.strokeStyle='#a64058';c.beginPath();c.arc(hx+fx,hy+9,3,.15,Math.PI-.15);c.stroke();
  // Black pull-style rolling tote with Eaton-orange lining, held by its telescoping handle.
   c.save();c.translate(20,-21);c.rotate(-.07);c.strokeStyle='#47535c';c.lineWidth=1.7;c.beginPath();c.moveTo(0,0);c.lineTo(6,8);c.lineTo(6,11);c.stroke();c.strokeStyle='#14191d';c.lineWidth=3;c.beginPath();c.moveTo(-1,0);c.lineTo(2.5,3.5);c.stroke();c.fillStyle='#11161a';rr(c,1,8,17,20,3);c.fill();c.strokeStyle='#f58220';c.lineWidth=1.8;rr(c,1,8,17,20,3);c.stroke();c.fillStyle='#f58220';c.beginPath();c.moveTo(3,10);c.lineTo(16,10);c.lineTo(13.5,13);c.lineTo(5.5,13);c.closePath();c.fill();c.strokeStyle='#39434a';c.lineWidth=1;c.beginPath();c.moveTo(5,16);c.lineTo(14,16);c.moveTo(5,20);c.lineTo(14,20);c.stroke();ell(c,4,29,2.6,2.2,'#0a0d0f');ell(c,15,29,2.6,2.2,'#0a0d0f');ell(c,4,29,1,1,'#f58220');ell(c,15,29,1,1,'#f58220');c.restore();c.restore();
}

function drawJWHiker(c,x,y,s,ch,o){
  o=o||{};const lean=o.lean||0,fx=o.fx||0,skin=ch.skin;c.save();c.translate(x,y);c.scale(s*.9,s*1.12);if(o.rot)c.rotate(o.rot);c.lineCap='round';c.lineJoin='round';
  c.fillStyle='#a88450';rr(c,-8,-23,6,23,3);c.fill();rr(c,2,-23,6,23,3);c.fill();ell(c,-5,-1,7,3,'#392b21');ell(c,6,-1,7,3,'#392b21');
  c.fillStyle=ch.outfit;rr(c,-10,-45,20,25,6);c.fill();c.fillStyle='#8c6a3c';rr(c,-11,-42,5,20,2);c.fill();rr(c,6,-42,5,20,2);c.fill();c.strokeStyle='#d5a84c';c.lineWidth=1.3;c.beginPath();c.moveTo(-4,-41);c.lineTo(0,-33);c.lineTo(4,-41);c.stroke();
  c.strokeStyle=ch.outfit;c.lineWidth=5;c.beginPath();c.moveTo(-9,-41);c.lineTo(-17,-24);c.moveTo(9,-41);c.lineTo(18,-25);c.stroke();ell(c,-17,-23,3.2,3.2,skin);ell(c,18,-24,3.2,3.2,skin);
  const hx=lean*3,hy=-58;ell(c,hx,hy+2,13,12,skin);c.fillStyle=ch.hair2;c.beginPath();c.ellipse(hx,hy-3,12.5,7,0,Math.PI,TAU);c.lineTo(hx+12.5,hy-3);c.lineTo(hx-12.5,hy-3);c.closePath();c.fill();c.fillStyle=ch.hair;c.beginPath();c.moveTo(hx-11,hy-4);c.quadraticCurveTo(hx,hy-10.8,hx+11,hy-4);c.quadraticCurveTo(hx+4,hy-1.7,hx-10,hy-1.2);c.closePath();c.fill();
   for(const ex of[-1,1]){ell(c,hx+ex*4.7+fx*2,hy+2,3,3.5,'#fff');ell(c,hx+ex*4.7+fx*2,hy+2,1.4,2,ch.eye);}c.fillStyle='#241813';c.beginPath();c.moveTo(hx-9,hy+7);c.quadraticCurveTo(hx-8,hy+12,hx-4,hy+13);c.quadraticCurveTo(hx,hy+17,hx+4,hy+13);c.quadraticCurveTo(hx+8,hy+12,hx+9,hy+7);c.lineTo(hx+6,hy+10);c.quadraticCurveTo(hx,hy+14,hx-6,hy+10);c.closePath();c.fill();c.beginPath();c.moveTo(hx-10,hy+7);c.quadraticCurveTo(hx-5,hy+4,hx,hy+7);c.quadraticCurveTo(hx+5,hy+4,hx+10,hy+7);c.lineTo(hx+8,hy+9);c.quadraticCurveTo(hx+3,hy+7,hx,hy+8.5);c.quadraticCurveTo(hx-3,hy+7,hx-8,hy+9);c.closePath();c.fill();c.strokeStyle='#8c4d3f';c.lineWidth=1.25;c.beginPath();c.moveTo(hx-2.7+fx,hy+9.05);c.quadraticCurveTo(hx+fx,hy+9.8,hx+2.7+fx,hy+9.05);c.stroke();
  // Cigarette held away from the face.
  c.save();c.translate(18,-24);c.rotate(-.18);c.fillStyle='#f4f0e7';rr(c,0,-1,11,2,1);c.fill();c.fillStyle='#d8a244';c.fillRect(8,-1,3,2);c.fillStyle='#ef6a32';c.fillRect(11,-.9,1.4,1.8);c.restore();c.restore();
}

function drawRMCandyRanger(c,x,y,s,ch,o){
  o=o||{};const lean=o.lean||0,fx=o.fx||0,skin=ch.skin;c.save();c.translate(x,y);c.scale(s*1.12,s*1.125);if(o.rot)c.rotate(o.rot);c.lineCap='round';c.lineJoin='round';
  c.fillStyle='#235c91';rr(c,-13,-22,11,22,4);c.fill();rr(c,2,-22,11,22,4);c.fill();ell(c,-8,-1,8,3,'#17191d');ell(c,8,-1,8,3,'#17191d');
  c.fillStyle='#111820';rr(c,-16,-45,32,27,9);c.fill();c.fillStyle='#f2c500';c.font='bold 5px sans-serif';c.textAlign='center';c.fillText('LVA',0,-31);c.strokeStyle='#111820';c.lineWidth=6;c.beginPath();c.moveTo(-13,-40);c.lineTo(-22,-22);c.moveTo(13,-40);c.lineTo(22,-22);c.stroke();ell(c,-22,-21,3.6,3.6,skin);ell(c,22,-21,3.6,3.6,skin);
  const hx=lean*3,hy=-58;ell(c,hx,hy+3,14,13,skin);
   // Lined-up very short black hair: one clean semicircle with no side curls.
   c.fillStyle='#080706';c.beginPath();c.ellipse(hx,hy-3,13,7,0,Math.PI,TAU);c.lineTo(hx+13,hy-3);c.lineTo(hx-13,hy-3);c.closePath();c.fill();for(const ex of[-1,1]){ell(c,hx+ex*5+fx*2,hy+3,3.2,3.7,'#fff');ell(c,hx+ex*5+fx*2,hy+3,1.5,2.1,ch.eye);}c.strokeStyle='#2a1710';c.lineWidth=1.4;c.beginPath();c.arc(hx+fx,hy+9,3,.15,Math.PI-.15);c.stroke();
  // Bag of candy.
  c.save();c.translate(24,-20);c.rotate(.12);c.fillStyle='#df593f';rr(c,-9,-12,18,24,3);c.fill();c.fillStyle='#ffe66b';c.font='bold 5px sans-serif';c.textAlign='center';c.fillText('CANDY',0,1);for(const q of [[-5,-7],[4,-6],[-4,7],[5,7]])ell(c,q[0],q[1],2,1.5,['#77d6ff','#ffe66b','#8ee08e','#d69cff'][(q[0]+q[1]+20)%4]);c.restore();c.restore();
}

function drawCBPhotographer(c,x,y,s,ch,o){
  o=o||{};const lean=o.lean||0,fx=o.fx||0,skin=ch.skin;c.save();c.translate(x,y);c.scale(s*.84,s*.88);if(o.rot)c.rotate(o.rot);c.lineCap='round';c.lineJoin='round';
  c.fillStyle='#6f777d';rr(c,-9,-18,7,18,3);c.fill();rr(c,2,-18,7,18,3);c.fill();ell(c,-5,-1,6.5,3,'#161a1e');ell(c,6,-1,6.5,3,'#161a1e');
  c.fillStyle=ch.outfit;rr(c,-11,-39,22,23,6);c.fill();c.strokeStyle=ch.accent;c.lineWidth=1.5;for(let q=-7;q<=7;q+=7){c.beginPath();c.moveTo(q,-38);c.lineTo(q,-18);c.stroke();}for(let q=-34;q<=-20;q+=7){c.beginPath();c.moveTo(-10,q);c.lineTo(10,q);c.stroke();}
  c.strokeStyle=shade(ch.outfit,.76);c.lineWidth=5;c.beginPath();c.moveTo(-10,-35);c.lineTo(-18,-20);c.moveTo(10,-35);c.lineTo(18,-20);c.stroke();ell(c,-18,-19,3.3,3.3,skin);ell(c,18,-19,3.3,3.3,skin);
  const hx=lean*3,hy=-51;ell(c,hx,hy+2,13,12,skin);c.fillStyle=ch.hair2;c.beginPath();c.arc(hx,hy-3,13,Math.PI,TAU);c.lineTo(hx+12,hy-2);c.quadraticCurveTo(hx+2,hy-12,hx-12,hy-5);c.closePath();c.fill();
  for(const ex of[-1,1]){ell(c,hx+ex*4.6+fx*1.5,hy+2,3.2,1.7,'#fff');ell(c,hx+ex*4.6+fx*1.5,hy+2,1.5,1.05,ch.eye);}c.strokeStyle='#111820';c.lineWidth=1.7;rr(c,hx-10.5,hy-1,8.5,6,2);c.stroke();rr(c,hx+2,hy-1,8.5,6,2);c.stroke();c.beginPath();c.moveTo(hx-2,hy+1);c.lineTo(hx+2,hy+1);c.stroke();c.strokeStyle='#984c45';c.lineWidth=1.2;c.beginPath();c.arc(hx+fx,hy+8,2.8,.15,Math.PI-.15);c.stroke();
  c.save();c.translate(20,-21);c.rotate(-.1);c.fillStyle='#111820';rr(c,-8,-6,16,12,2);c.fill();c.fillStyle='#2f3b43';rr(c,-4,-9,8,4,1);c.fill();ell(c,0,0,5,5,'#1f2b33');ell(c,0,0,3,3,'#67c9ff');ell(c,-5,-3,1.3,1.3,'#f58220');c.strokeStyle='#111820';c.lineWidth=1.5;c.beginPath();c.moveTo(-6,-7);c.quadraticCurveTo(0,-14,7,-7);c.stroke();c.restore();c.restore();
}
function drawSBGolfer(c,x,y,s,ch,o){
  o=o||{};const lean=o.lean||0,fx=o.fx||0,skin=ch.skin;c.save();c.translate(x,y);c.scale(s*.86,s*.9);if(o.rot)c.rotate(o.rot);c.lineCap='round';c.lineJoin='round';
  c.fillStyle='#92cfea';rr(c,-9,-18,7,18,3);c.fill();rr(c,2,-18,7,18,3);c.fill();ell(c,-5,-1,6.5,3,'#f4f7f8');ell(c,6,-1,6.5,3,'#f4f7f8');
  c.fillStyle=ch.outfit;rr(c,-12,-40,24,24,7);c.fill();c.fillStyle='#d7f0ff';c.fillRect(-11,-35,22,2);c.strokeStyle=shade(ch.outfit,.76);c.lineWidth=5.5;c.beginPath();c.moveTo(-10,-36);c.lineTo(-18,-21);c.moveTo(10,-36);c.lineTo(18,-21);c.stroke();ell(c,-18,-20,3.3,3.3,skin);ell(c,18,-20,3.3,3.3,skin);
  const hx=lean*3,hy=-53;ell(c,hx,hy+2,13.5,12.5,skin);c.fillStyle=ch.hair2;c.beginPath();c.ellipse(hx,hy-3,13,7.5,0,Math.PI,TAU);c.lineTo(hx+13,hy-3);c.lineTo(hx-13,hy-3);c.closePath();c.fill();c.fillStyle=ch.hair;for(const q of[[-8,-6.8],[-3,-9],[3,-8.6],[8,-6.5]])ell(c,hx+q[0],hy+q[1],1.5,1,ch.hair);
  for(const ex of[-1,1]){ell(c,hx+ex*4.8+fx*1.5,hy+2,3.1,1.8,'#fff');ell(c,hx+ex*4.8+fx*1.5,hy+2,1.4,1.1,ch.eye);}c.fillStyle='#41464b';c.beginPath();c.moveTo(hx-9,hy+7);c.quadraticCurveTo(hx-7,hy+13,hx,hy+15);c.quadraticCurveTo(hx+7,hy+13,hx+9,hy+7);c.lineTo(hx+6,hy+9);c.quadraticCurveTo(hx,hy+12,hx-6,hy+9);c.closePath();c.fill();c.beginPath();c.moveTo(hx-8,hy+6);c.quadraticCurveTo(hx-4,hy+4,hx,hy+6);c.quadraticCurveTo(hx+4,hy+4,hx+8,hy+6);c.lineTo(hx+6,hy+8);c.quadraticCurveTo(hx,hy+6.8,hx-6,hy+8);c.closePath();c.fill();
  c.save();c.translate(20,-20);c.rotate(-.08);c.strokeStyle='#aab6bd';c.lineWidth=2;c.beginPath();c.moveTo(0,0);c.lineTo(9,25);c.stroke();c.fillStyle='#56646d';c.beginPath();c.moveTo(6,21);c.lineTo(16,22);c.lineTo(14,27);c.lineTo(8,27);c.closePath();c.fill();c.strokeStyle='#28343b';c.lineWidth=1.2;c.stroke();c.fillStyle='rgba(255,255,255,.28)';c.fillRect(9,22,5,1);c.restore();c.restore();
}
function drawGZSnowboarder(c,x,y,s,ch,o){
  o=o||{};const lean=o.lean||0,fx=o.fx||0,skin=ch.skin;c.save();c.translate(x,y);c.scale(s,s);if(o.rot)c.rotate(o.rot);c.lineCap='round';c.lineJoin='round';
  c.save();c.translate(18,-22);c.rotate(-.34);c.fillStyle='#dbeaf2';rr(c,-5,-24,10,48,5);c.fill();c.strokeStyle='#123d70';c.lineWidth=2;c.stroke();c.fillStyle='#f58220';c.fillRect(-4,-3,8,6);c.fillStyle='#0067c6';ell(c,0,-15,3,3,c.fillStyle);ell(c,0,15,3,3,c.fillStyle);c.restore();
  c.fillStyle='#285b8b';rr(c,-10,-20,8,20,3);c.fill();rr(c,2,-20,8,20,3);c.fill();ell(c,-6,-1,7,3,'#111820');ell(c,7,-1,7,3,'#111820');
  c.fillStyle=ch.outfit;rr(c,-13,-42,26,25,7);c.fill();c.fillStyle=ch.accent;c.fillRect(-12,-23,24,3);c.fillStyle='#ffffff';c.font='bold 6px sans-serif';c.textAlign='center';c.fillText('MVC',0,-30);c.strokeStyle=shade(ch.outfit,.76);c.lineWidth=5.5;c.beginPath();c.moveTo(-11,-38);c.lineTo(-20,-22);c.moveTo(11,-38);c.lineTo(20,-22);c.stroke();ell(c,-20,-21,3.4,3.4,skin);ell(c,20,-21,3.4,3.4,skin);
  const hx=lean*3,hy=-55;ell(c,hx,hy+3,13.5,12.5,skin);c.fillStyle=ch.hair;c.beginPath();c.moveTo(hx-12.5,hy-6);c.quadraticCurveTo(hx-17,hy-4,hx-16.5,hy+2);c.lineTo(hx-15.5,hy+16);c.quadraticCurveTo(hx-15,hy+21,hx-11.5,hy+20);c.quadraticCurveTo(hx-9.5,hy+18,hx-10,hy+12);c.lineTo(hx-10.5,hy-4);c.closePath();c.fill();c.beginPath();c.moveTo(hx+12.5,hy-6);c.quadraticCurveTo(hx+17,hy-4,hx+16.5,hy+2);c.lineTo(hx+15.5,hy+16);c.quadraticCurveTo(hx+15,hy+21,hx+11.5,hy+20);c.quadraticCurveTo(hx+9.5,hy+18,hx+10,hy+12);c.lineTo(hx+10.5,hy-4);c.closePath();c.fill();c.beginPath();c.moveTo(hx-15.5,hy-4);c.quadraticCurveTo(hx-10,hy-14.5,hx,hy-14.5);c.quadraticCurveTo(hx+10,hy-14.5,hx+15.5,hy-4);c.quadraticCurveTo(hx+8.5,hy-1,hx,hy-1.5);c.quadraticCurveTo(hx-8.5,hy-1,hx-15.5,hy-4);c.closePath();c.fill();c.strokeStyle='rgba(255,255,255,.14)';c.lineWidth=1;c.beginPath();c.moveTo(hx-13.2,hy);c.quadraticCurveTo(hx-13.5,hy+8,hx-12.8,hy+17);c.moveTo(hx+13.2,hy);c.quadraticCurveTo(hx+13.5,hy+8,hx+12.8,hy+17);c.stroke();
  for(const ex of[-1,1]){ell(c,hx+ex*4.8+fx*2,hy+3,3.1,3.5,'#fff');ell(c,hx+ex*4.8+fx*2,hy+3,1.4,2,ch.eye);}c.strokeStyle='#8f4e43';c.lineWidth=1.2;c.beginPath();c.arc(hx+fx,hy+9,3,.15,Math.PI-.15);c.stroke();c.restore();
}

function drawXEAnchor(c,x,y,s,ch,o){
  o=o||{};const lean=o.lean||0,fx=o.fx||0,skin=ch.skin;c.save();c.translate(x,y);c.scale(s*.94,s*1.07);if(o.rot)c.rotate(o.rot);c.lineCap='round';c.lineJoin='round';
  // Blue jeans and tall, curvy hourglass silhouette derived from JG's approved proportions.
  c.fillStyle='#245b91';rr(c,-10,-20,8,20,3);c.fill();rr(c,2,-20,8,20,3);c.fill();ell(c,-6,-1,7,3,'#111820');ell(c,7,-1,7,3,'#111820');
  c.fillStyle=ch.outfit;c.beginPath();c.moveTo(-12,-44);c.quadraticCurveTo(-15,-40,-13,-35);c.quadraticCurveTo(-10,-31,-8,-29);c.quadraticCurveTo(-13,-26,-14,-21);c.quadraticCurveTo(-12,-18,-9,-18);c.lineTo(9,-18);c.quadraticCurveTo(12,-18,14,-21);c.quadraticCurveTo(13,-26,8,-29);c.quadraticCurveTo(10,-31,13,-35);c.quadraticCurveTo(15,-40,12,-44);c.quadraticCurveTo(0,-48,-12,-44);c.fill();
  c.strokeStyle='#111820';c.lineWidth=5.5;c.beginPath();c.moveTo(-11,-40);c.lineTo(-20,-22);c.moveTo(11,-40);c.lineTo(20,-22);c.stroke();ell(c,-20,-21,3.5,3.5,skin);ell(c,20,-21,3.5,3.5,skin);
  const hx=lean*3,hy=-58;ell(c,hx,hy+3,14,13,skin);c.fillStyle=ch.hair2;for(const q of[[-11,-8],[-7,-13],[-1,-15],[5,-14],[10,-10],[13,-4],[-13,-3]])ell(c,hx+q[0],hy+q[1],5.3,5.2,ch.hair2);c.fillStyle=ch.hair;for(const q of[[-8,-10],[-2,-13],[5,-11],[10,-6],[-11,-4]])ell(c,hx+q[0],hy+q[1],4,3.8,ch.hair);
  for(const ex of[-1,1]){ell(c,hx+ex*4.8+fx*2,hy+3,3.1,3.6,'#fff');ell(c,hx+ex*4.8+fx*2,hy+3,1.4,2,ch.eye);}c.strokeStyle='#9b4f49';c.lineWidth=1.3;c.beginPath();c.arc(hx+fx,hy+9,3.1,.12,Math.PI-.12);c.stroke();
  // Steel anchor held at the right side.
  c.save();c.translate(23,-19);c.rotate(.12);c.strokeStyle='#606d77';c.lineWidth=2.5;c.beginPath();c.arc(0,-10,3.5,0,TAU);c.moveTo(0,-6.5);c.lineTo(0,16);c.moveTo(-8,3);c.lineTo(8,3);c.moveTo(-11,10);c.quadraticCurveTo(-8,18,0,17);c.quadraticCurveTo(8,18,11,10);c.stroke();poly(c,[-11,10,-12,16,-6,13],'#606d77');poly(c,[11,10,12,16,6,13],'#606d77');c.restore();c.restore();
}
function drawRBPatriot(c,x,y,s,ch,o){
  o=o||{};const lean=o.lean||0,fx=o.fx||0,skin=ch.skin;c.save();c.translate(x,y);c.scale(s*.92,s*1.05);if(o.rot)c.rotate(o.rot);c.lineCap='round';c.lineJoin='round';
  c.fillStyle='#245b91';rr(c,-10,-20,8,20,3);c.fill();rr(c,2,-20,8,20,3);c.fill();ell(c,-6,-1,7,3,'#111820');ell(c,7,-1,7,3,'#111820');
  c.fillStyle='#f4f5f7';rr(c,-13,-43,26,26,7);c.fill();c.save();rr(c,-13,-43,26,26,7);c.clip();c.fillStyle='#ba2334';for(let y=-39;y<=-19;y+=6)c.fillRect(-13,y,26,3);c.fillStyle='#21468b';c.fillRect(-13,-43,12,12);c.fillStyle='#fff';for(const q of[[-10,-40],[-6,-40],[-10,-36],[-6,-36]])ell(c,q[0],q[1],.8,.8,'#fff');c.restore();
  c.strokeStyle='#21468b';c.lineWidth=5.5;c.beginPath();c.moveTo(-11,-39);c.lineTo(-20,-22);c.moveTo(11,-39);c.lineTo(20,-22);c.stroke();ell(c,-20,-21,3.5,3.5,skin);ell(c,20,-21,3.5,3.5,skin);
  const hx=lean*3,hy=-56;ell(c,hx,hy+3,14,13,skin);c.fillStyle=ch.hair2;c.beginPath();c.ellipse(hx,hy-3,13,7,0,Math.PI,TAU);c.lineTo(hx+13,hy-3);c.lineTo(hx-13,hy-3);c.closePath();c.fill();
  for(const ex of[-1,1]){ell(c,hx+ex*4.8+fx*2,hy+3,3.1,3.6,'#fff');ell(c,hx+ex*4.8+fx*2,hy+3,1.4,2,ch.eye);}c.strokeStyle='#2a1710';c.lineWidth=1.3;c.beginPath();c.arc(hx+fx,hy+9,3.1,.12,Math.PI-.12);c.stroke();
  // Hand-held American flag.
  c.save();c.translate(21,-22);c.rotate(-.08);c.strokeStyle='#7b613e';c.lineWidth=2;c.beginPath();c.moveTo(0,6);c.lineTo(0,-29);c.stroke();c.fillStyle='#fff';c.fillRect(1,-29,21,14);c.fillStyle='#c52233';for(let q=0;q<4;q++)c.fillRect(1,-29+q*4,21,2);c.fillStyle='#21468b';c.fillRect(1,-29,9,7);c.fillStyle='#fff';for(const q of[[3,-27],[6,-27],[3,-24],[6,-24]])ell(c,q[0],q[1],.65,.65,'#fff');c.restore();c.restore();
}
function drawPBPride(c,x,y,s,ch,o){
  o=o||{};const lean=o.lean||0,fx=o.fx||0,skin=ch.skin;c.save();c.translate(x,y);c.scale(s*1.08,s*1.08);if(o.rot)c.rotate(o.rot);c.lineCap='round';c.lineJoin='round';
  c.fillStyle='#6f4c31';rr(c,-13,-21,10,21,4);c.fill();rr(c,3,-21,10,21,4);c.fill();ell(c,-8,-1,8,3,'#241a16');ell(c,8,-1,8,3,'#241a16');
  // Heavier light-purple open button-up shirt.
  c.fillStyle=ch.outfit;rr(c,-17,-44,34,28,10);c.fill();c.strokeStyle=shade(ch.outfit,.76);c.lineWidth=6;c.beginPath();c.moveTo(-14,-39);c.lineTo(-23,-21);c.moveTo(14,-39);c.lineTo(23,-21);c.stroke();ell(c,-23,-20,3.8,3.8,skin);ell(c,23,-20,3.8,3.8,skin);
  poly(c,[-5,-44,0,-29,5,-44],skin);c.fillStyle='#6f4a7b';for(const y of[-27,-22,-18])ell(c,0,y,1.1,1.1,c.fillStyle);c.strokeStyle='#111820';c.lineWidth=1.25;c.beginPath();c.moveTo(-4.2,-42);c.lineTo(0,-30);c.moveTo(4.2,-42);c.lineTo(0,-30);c.stroke();ell(c,0,-29,3.2,3.8,'#111820');
  const hx=lean*3,hy=-57;ell(c,hx,hy+3,15,14,skin);c.fillStyle=ch.hair;c.beginPath();c.moveTo(hx-13.5,hy-7);c.quadraticCurveTo(hx-18,hy-4,hx-17.5,hy+2);c.lineTo(hx-16.5,hy+15);c.quadraticCurveTo(hx-16,hy+20,hx-12.5,hy+19);c.quadraticCurveTo(hx-10.5,hy+17,hx-11,hy+11);c.lineTo(hx-11.5,hy-5);c.closePath();c.fill();c.beginPath();c.moveTo(hx+13.5,hy-7);c.quadraticCurveTo(hx+18,hy-4,hx+17.5,hy+2);c.lineTo(hx+16.5,hy+15);c.quadraticCurveTo(hx+16,hy+20,hx+12.5,hy+19);c.quadraticCurveTo(hx+10.5,hy+17,hx+11,hy+11);c.lineTo(hx+11.5,hy-5);c.closePath();c.fill();c.beginPath();c.moveTo(hx-16,hy-4);c.quadraticCurveTo(hx-10,hy-12.5,hx,hy-12.5);c.quadraticCurveTo(hx+10,hy-12.5,hx+16,hy-4);c.quadraticCurveTo(hx+8.5,hy-.5,hx,hy-1);c.quadraticCurveTo(hx-8.5,hy-.5,hx-16,hy-4);c.closePath();c.fill();c.strokeStyle='rgba(255,255,255,.18)';c.lineWidth=1;c.beginPath();c.moveTo(hx-14.2,hy);c.quadraticCurveTo(hx-14.5,hy+7,hx-13.8,hy+16);c.moveTo(hx+14.2,hy);c.quadraticCurveTo(hx+14.5,hy+7,hx+13.8,hy+16);c.stroke();
  for(const ex of[-1,1]){ell(c,hx+ex*5+fx*2,hy+3,3.2,3.7,'#fff');ell(c,hx+ex*5+fx*2,hy+3,1.5,2.1,ch.eye);}c.strokeStyle='#a34e58';c.lineWidth=1.3;c.beginPath();c.arc(hx+fx,hy+10,3.2,.12,Math.PI-.12);c.stroke();
  // Black-colored nails and hand-held rainbow flag.
  c.fillStyle='#111820';for(const q of[[-24,-19],[-21,-22],[22,-22],[25,-19]])ell(c,q[0],q[1],1.1,1.6,'#111820');c.save();c.translate(24,-22);c.rotate(-.06);c.strokeStyle='#6d5840';c.lineWidth=2;c.beginPath();c.moveTo(0,7);c.lineTo(0,-29);c.stroke();const cols=['#e53935','#fb8c00','#fdd835','#43a047','#1e88e5','#8e24aa'];cols.forEach((col,i)=>{c.fillStyle=col;c.fillRect(1,-29+i*2.5,22,2.6);});c.restore();c.restore();
}

function drawBumpCap(c,x,y,s,ch,o){
  const hat=hatOf(o&&o.hatId);if(!hat)return;const lean=o.lean||0;
  const hy=ch.dallas?-76:ch.koolaid?-70:ch.jenkins?-64:ch.cassandra?-69:ch.ryan?-66:ch.jg?-70:ch.jw?-75:ch.rm?-80:ch.cb?-56:ch.sb?-59:ch.gz?-69:ch.xe?-73:ch.rb?-70:ch.pb?-73:ch.mackey?-62:-58,hx=lean*3;
  c.save();c.translate(x,y);c.scale(s,s);if(o.rot)c.rotate(o.rot);if(hat.pride||hat.golden){c.shadowColor=hat.golden?'#ffd84d':'#1686ff';c.shadowBlur=hat.golden?9:6;}c.fillStyle=hat.color;c.beginPath();c.arc(hx,hy,13,Math.PI,TAU);c.fill();c.strokeStyle=shade(hat.color,.62);c.lineWidth=1.4;c.stroke();c.fillStyle=shade(hat.color,.8);rr(c,hx-15,hy-1,30,4,2);c.fill();c.shadowBlur=0;c.fillStyle='#fff';c.font='bold '+(hat.pride?'11':'5')+'px sans-serif';c.textAlign='center';c.fillText(hat.pride?'E':hat.golden?'E★':'LVA',hx,hy-3.5);if(hat.golden){c.strokeStyle='rgba(255,255,255,.85)';c.lineWidth=1;c.beginPath();c.moveTo(hx-7,hy-10);c.lineTo(hx+1,hy-13);c.stroke();}c.restore();
}
function drawRider(c,x,y,s,ch,o){
   o=o||{};const special=ch.koolaid?drawBrettKoolAid:ch.mackey?drawDJAssembler:ch.jenkins?drawJenkinsManager:ch.dallas?drawDallasGolf:ch.cassandra?drawCassandraQuality:ch.ryan?drawRyanRotator:ch.jg?drawJGWireQueen:ch.jw?drawJWHiker:ch.rm?drawRMCandyRanger:ch.cb?drawCBPhotographer:ch.sb?drawSBGolfer:ch.gz?drawGZSnowboarder:ch.xe?drawXEAnchor:ch.rb?drawRBPatriot:ch.pb?drawPBPride:null;if(special){special(c,x,y,s,ch,o);drawBumpCap(c,x,y,s,ch,o);return;}const lean=o.lean||0,fx=o.fx||0,front=o.front!==false,t=o.t||0,arm=o.arm||0;
  const skin=ch.skin||'#ffe3cc';
  c.save();c.translate(x,y);c.scale(s,s);if(o.rot)c.rotate(o.rot);
  c.lineCap='round';c.lineJoin='round';
  const ax=lean*4;
  // legs + shoes
  c.fillStyle='#2b3558';rr(c,-8+lean*3,-15,7,15,3);c.fill();rr(c,1+lean*3,-15,7,15,3);c.fill();
  c.fillStyle=ch.accent;c.beginPath();c.ellipse(-5+lean*3,-1,6,3,0,0,TAU);c.fill();c.beginPath();c.ellipse(5+lean*3,-1,6,3,0,0,TAU);c.fill();
  // arms
  c.strokeStyle=shade(ch.outfit,.8);c.lineWidth=5;
  c.beginPath();c.moveTo(-9+ax,-29);c.quadraticCurveTo(-16+ax-arm*4,-24,-15+ax-arm*6,-16-arm*5);c.stroke();
  c.beginPath();c.moveTo(9+ax,-29);c.quadraticCurveTo(16+ax+arm*4,-24,15+ax+arm*6,-16-arm*5);c.stroke();
  c.fillStyle=skin;c.beginPath();c.arc(-15+ax-arm*6,-15-arm*5,3,0,TAU);c.fill();c.beginPath();c.arc(15+ax+arm*6,-15-arm*5,3,0,TAU);c.fill();
  // torso
  c.fillStyle=ch.outfit;rr(c,-9+ax*.8,-33,18,20,6);c.fill();
  c.fillStyle=ch.accent;rr(c,-9+ax*.8,-22,18,3,1);c.fill();
  c.fillStyle=shade(ch.outfit,.75);rr(c,-2+ax*.8,-33,4,11,1);c.fill();
  // head
  const hx=lean*5,hy=-45;
  c.fillStyle=ch.hair2;
  if(ch.style==='twin'){c.beginPath();c.ellipse(hx-15,hy+8,4.5,11,.25,0,TAU);c.fill();c.beginPath();c.ellipse(hx+15,hy+8,4.5,11,-.25,0,TAU);c.fill();}
  else if(ch.style==='pony'){const sd=fx>=0?-1:1;c.beginPath();c.ellipse(hx+sd*13,hy+5,4.5,13,sd*.5,0,TAU);c.fill();}
  else if(ch.style==='bob'){c.beginPath();c.ellipse(hx,hy+4,14.5,14,0,0,TAU);c.fill();}
  c.beginPath();c.arc(hx,hy,13,0,TAU);c.fill();
  if(front){
    c.fillStyle=skin;c.beginPath();c.ellipse(hx,hy+2.5,11,10.5,0,0,TAU);c.fill();
    // eyes
    const blink=((t*1.1)%4)<.08;
    for(const ex of[-1,1]){
      const x0=hx+ex*4.8+fx*3.2,y0=hy+3;
      if(blink){c.strokeStyle='#40304a';c.lineWidth=1.5;c.beginPath();c.moveTo(x0-3,y0+1);c.lineTo(x0+3,y0+1);c.stroke();continue;}
      c.fillStyle='#fff';c.beginPath();c.ellipse(x0,y0,3.3,4.3,0,0,TAU);c.fill();
      c.fillStyle=ch.eye;c.beginPath();c.ellipse(x0+fx*.8,y0+.4,2.5,3.5,0,0,TAU);c.fill();
      c.fillStyle='#1c1230';c.beginPath();c.ellipse(x0+fx*.8,y0+.6,1.3,2,0,0,TAU);c.fill();
      c.fillStyle='#fff';c.beginPath();c.arc(x0+fx*.8-.9,y0-1.4,1.1,0,TAU);c.fill();
      c.strokeStyle='#3a2a50';c.lineWidth=1.2;c.beginPath();c.arc(x0,y0-.5,4,Math.PI*1.12,Math.PI*1.88);c.stroke();
    }
    c.fillStyle='rgba(255,120,150,.35)';c.beginPath();c.ellipse(hx-8+fx*2,hy+7,2.6,1.6,0,0,TAU);c.fill();c.beginPath();c.ellipse(hx+8+fx*2,hy+7,2.6,1.6,0,0,TAU);c.fill();
    if(o.cheer){c.fillStyle='#b0364c';c.beginPath();c.ellipse(hx+fx*2,hy+9,2.6,2.2,0,0,TAU);c.fill();}
    else{c.strokeStyle='#b04a5a';c.lineWidth=1.3;c.beginPath();c.arc(hx+fx*2,hy+7.8,2.2,.2,Math.PI-.2);c.stroke();}
    // front hair
    c.fillStyle=ch.hair;c.beginPath();c.moveTo(hx-12,hy+3);c.quadraticCurveTo(hx-13,hy-14,hx,hy-14);c.quadraticCurveTo(hx+13,hy-14,hx+12,hy+3);
    c.lineTo(hx+8,hy-3);c.lineTo(hx+4,hy+2);c.lineTo(hx,hy-5);c.lineTo(hx-4,hy+2);c.lineTo(hx-8,hy-3);c.closePath();c.fill();
  }else{
    c.fillStyle=ch.hair;c.beginPath();c.arc(hx,hy+1,12.6,0,TAU);c.fill();
    c.fillStyle='rgba(255,255,255,.28)';c.beginPath();c.ellipse(hx-3,hy-5,5,2.4,-.4,0,TAU);c.fill();
  }
  // style extras
  c.fillStyle=ch.hair;
  if(ch.style==='spiky'||ch.style==='goggles'){
    c.beginPath();c.moveTo(hx-12,hy-4);c.lineTo(hx-14,hy-17);c.lineTo(hx-6,hy-11);c.lineTo(hx-3,hy-21);c.lineTo(hx+2,hy-11);c.lineTo(hx+8,hy-20);c.lineTo(hx+9,hy-9);c.lineTo(hx+15,hy-13);c.lineTo(hx+12,hy-3);c.closePath();c.fill();
  }
  if(ch.style==='goggles'){
    c.strokeStyle='#394266';c.lineWidth=3.2;c.beginPath();c.arc(hx,hy-8,11.5,Math.PI*1.08,Math.PI*1.92);c.stroke();
    c.fillStyle='#7fe3ff';c.strokeStyle='#394266';c.lineWidth=1.6;c.beginPath();c.ellipse(hx-4.8,hy-10,4,3,0,0,TAU);c.fill();c.stroke();c.beginPath();c.ellipse(hx+4.8,hy-10,4,3,0,0,TAU);c.fill();c.stroke();
  }
  if(ch.style==='twin'){c.fillStyle=ch.accent;c.beginPath();c.arc(hx-14,hy-1,2.8,0,TAU);c.fill();c.beginPath();c.arc(hx+14,hy-1,2.8,0,TAU);c.fill();}
  if(ch.style==='pony'){const sd=fx>=0?-1:1;c.fillStyle=ch.accent;c.beginPath();c.arc(hx+sd*11,hy-3,2.6,0,TAU);c.fill();}
  if(ch.style==='bob'){c.fillStyle=ch.accent;rr(c,hx+3,hy-12,6,3,1.5);c.fill();}
  if(front&&ch.safetyGlasses){c.strokeStyle='#bcecff';c.lineWidth=1.8;c.strokeRect(hx-10,hy-1,8,7);c.strokeRect(hx+2,hy-1,8,7);c.beginPath();c.moveTo(hx-2,hy+2);c.lineTo(hx+2,hy+2);c.stroke();}
  if(ch.hardhat){c.fillStyle=ch.hardhat;c.beginPath();c.arc(hx,hy-9,13,Math.PI,TAU);c.fill();c.fillRect(hx-15,hy-10,30,3);}
  c.restore();drawBumpCap(c,x,y,s,ch,o);
}

/* ---------- generic iso box ---------- */
function drawBox(x,y,hw,rot,z0,z1,top,side1,side2){
  const cs=Math.cos(rot),sn=Math.sin(rot);
  const px=[],py=[];
  const off=[[-hw,-hw],[hw,-hw],[hw,hw],[-hw,hw]];
  for(const o of off){px.push(x+o[0]*cs-o[1]*sn);py.push(y+o[0]*sn+o[1]*cs);}
  const faces=[];
  for(let k=0;k<4;k++){
    const a=k,b=(k+1)%4,mx=(px[a]+px[b])/2-x,my=(py[a]+py[b])/2-y;
    if(mx+my>0)faces.push({a,b,d:mx+my});
  }
  faces.sort((p,q)=>p.d-q.d);
  for(const f of faces){
    proj(px[f.a],py[f.a],z1);const ax=PX,ay=PY;proj(px[f.b],py[f.b],z1);const bx=PX,by=PY;
    proj(px[f.b],py[f.b],z0);const cx=PX,cy=PY;proj(px[f.a],py[f.a],z0);const dx=PX,dy=PY;
    poly(ctx,[ax,ay,bx,by,cx,cy,dx,dy],(f.a%2===0)?side1:side2,'rgba(0,0,0,.18)',1);
  }
  const tp=[];for(let k=0;k<4;k++){proj(px[k],py[k],z1);tp.push(PX,PY);}
  poly(ctx,tp,top,'rgba(0,0,0,.15)',1);
}

/* ---------- sky / island ---------- */
function drawSky(){
  const th=trackTheme(),g=ctx.createLinearGradient(0,0,0,H);g.addColorStop(0,th.skyTop);g.addColorStop(.5,th.skyMid);g.addColorStop(1,th.skyBottom);ctx.fillStyle=g;ctx.fillRect(0,0,W,H);
  ctx.save();ctx.globalAlpha=T.def?.theme==='arc'?.48:.35;ctx.strokeStyle=th.grid;ctx.lineWidth=T.def?.theme==='arc'?4:8;for(let x=-W;x<W*2;x+=150){ctx.beginPath();ctx.moveTo(x,0);ctx.lineTo(x+W*.35,H*.48);ctx.stroke();}ctx.globalAlpha=T.def?.theme==='arc'?.48:.7;for(let x=70;x<W;x+=190){ctx.fillStyle=T.def?.theme==='arc'?'#39c9ff':'#f7fbff';ctx.fillRect(x,28,105,10);ctx.shadowColor=T.def?.theme==='arc'?'#00a8e8':'#fff';ctx.shadowBlur=lowDetail()?0:T.def?.theme==='arc'?22:16;ctx.fillRect(x,28,105,5);}ctx.restore();
}
function drawIsland(){
  const k=cam.K*cam.zoom,TS=10,vis=[];
  for(const t of FEAT.tiles){proj(t.x,t.y,GZ);if(PX<-k*TS*1.6||PX>W+k*TS*1.6||PY<-k*TS*.9||PY>H+k*TS*2.6)continue;vis.push(t);}
  const depth=12*k*.95;
  ctx.lineWidth=1;
  for(const t of vis){
    const x0=t.i*TS,y0=t.j*TS,x1=x0+TS,y1=y0+TS;
    if(t.nx){proj(x1,y0,GZ);const ax=PX,ay=PY;proj(x1,y1,GZ);const bx=PX,by=PY;
      const th=trackTheme(),g=ctx.createLinearGradient(0,ay,0,ay+depth);g.addColorStop(0,th.edgeA);g.addColorStop(1,th.edgeB);poly(ctx,[ax,ay,bx,by,bx,by+depth,ax,ay+depth],g,null);}
    if(t.ny){proj(x0,y1,GZ);const ax=PX,ay=PY;proj(x1,y1,GZ);const bx=PX,by=PY;
      const th=trackTheme(),g=ctx.createLinearGradient(0,ay,0,ay+depth);g.addColorStop(0,th.edgeC);g.addColorStop(1,th.edgeD);poly(ctx,[ax,ay,bx,by,bx,by+depth,ax,ay+depth],g,null);}
  }
  for(const t of vis){
    const x0=t.i*TS,y0=t.j*TS;
    proj(x0,y0,GZ);const ax=PX,ay=PY;proj(x0+TS,y0,GZ);const bx=PX,by=PY;proj(x0+TS,y0+TS,GZ);const cx=PX,cy=PY;proj(x0,y0+TS,GZ);const dx=PX,dy=PY;
    const v=.97+hash2(t.i,t.j,3)*.06;
    const th=trackTheme(),col=shade(t.c?th.tileB:th.tileA,v);
    poly(ctx,[ax,ay,bx,by,cx,cy,dx,dy],col,col,1);
  }
}

function drawArdenPlantMap(){
  if(!T.def.plantTour)return;const k=cam.K*cam.zoom;
  const boundary=[[-252,-138],[252,-138],[252,108],[-252,108]],pts=[];
  for(const q of boundary){proj(q[0],q[1],.025);pts.push(PX,PY);}poly(ctx,pts,'rgba(142,151,156,.72)','#48565d',Math.max(1,.12*k));
  for(let i=0;i<ARDEN_AREAS.length;i++){
    const a=ARDEN_AREAS[i],x0=a.x-a.w/2,x1=a.x+a.w/2,y0=a.y-a.h/2,y1=a.y+a.h/2,p=[];
    for(const q of[[x0,y0],[x1,y0],[x1,y1],[x0,y1]]){proj(q[0],q[1],.04);p.push(PX,PY);}poly(ctx,p,i%2?'rgba(188,196,199,.86)':'rgba(170,180,184,.9)','#59676d',Math.max(1,.075*k));
    proj(a.x,a.y,.07);ctx.fillStyle='#27343a';ctx.font='900 '+Math.max(7,Math.round(.48*k))+'px "Trebuchet MS",sans-serif';ctx.textAlign='center';ctx.textBaseline='middle';ctx.fillText(a.label,PX,PY);
  }
}

/* ---------- road ---------- */
const roadVis=new Uint8Array(4096);
function laneQuad(j,l0,l1,z,a,b){
  const n=T.N,j2=(j+1)%n;
  proj(T.x[j]+T.nx[j]*l0,T.y[j]+T.ny[j]*l0,T.z[j]+z);a[0]=PX;a[1]=PY;
  proj(T.x[j]+T.nx[j]*l1,T.y[j]+T.ny[j]*l1,T.z[j]+z);a[2]=PX;a[3]=PY;
  proj(T.x[j2]+T.nx[j2]*l1,T.y[j2]+T.ny[j2]*l1,T.z[j2]+z);a[4]=PX;a[5]=PY;
  proj(T.x[j2]+T.nx[j2]*l0,T.y[j2]+T.ny[j2]*l0,T.z[j2]+z);a[6]=PX;a[7]=PY;
}
const _q=[0,0,0,0,0,0,0,0];
function drawRoad(time){
  const th=trackTheme(),N=T.N,k=cam.K*cam.zoom,m=k*16;
  for(let j=0;j<N;j++){proj(T.x[j],T.y[j],T.z[j]);roadVis[j]=(PX>-m&&PX<W+m&&PY>-m&&PY<H+m)?1:0;}
  ctx.lineWidth=1;
    // True raised deck: project both top and underside at world height so the bridge reads as solid volume.
   ctx.fillStyle='#25333a';ctx.strokeStyle='#172229';
   const qb=[0,0,0,0,0,0,0,0];
   if(!lowDetail())for(let j=0;j<N;j++){if(!roadVis[j])continue;const w=T.w[j]/2;laneQuad(j,-w,w,0,_q);laneQuad(j,-w,w,-.9,qb);
     poly(ctx,qb.slice(),'#202d33','#172229',1);
     poly(ctx,[_q[0],_q[1],_q[6],_q[7],qb[6],qb[7],qb[0],qb[1]],'#374850','#172229',1);
     poly(ctx,[_q[2],_q[3],_q[4],_q[5],qb[4],qb[5],qb[2],qb[3]],'#2b3a41','#172229',1);
   }
  // surface
  for(let j=0;j<N;j++){
    if(!roadVis[j])continue;const w=T.w[j]/2;laneQuad(j,-w,w,0,_q);
    const col=((j>>2)&1)?th.roadB:th.roadA;
    ctx.fillStyle=col;ctx.strokeStyle=col;ctx.beginPath();ctx.moveTo(_q[0],_q[1]);ctx.lineTo(_q[2],_q[3]);ctx.lineTo(_q[4],_q[5]);ctx.lineTo(_q[6],_q[7]);ctx.closePath();ctx.fill();ctx.stroke();
    // lane marks
    if((j%(lowDetail()?12:8))<(lowDetail()?3:4)){laneQuad(j,-.25,.25,.01,_q);poly(ctx,_q.slice(),th.lane,null);}
    laneQuad(j,-w+1.4,-w+1.9,.01,_q);poly(ctx,_q.slice(),th.edge,null);
    laneQuad(j,w-1.9,w-1.4,.01,_q);poly(ctx,_q.slice(),th.edge,null);
  }
  // guard curbs: steel-only at intersections; the inside rail is omitted on tight hairpins to prevent overlap.
  for(let j=0;j<N;j++){
    if(!roadVis[j]||(lowDetail()&&(j&1)))continue;const w=T.w[j]/2,red=((j>>1)&1),atCross=!!T.cross[j],tightHairpin=T.ka[j]>.010,innerSign=Math.sign(T.k[j]);
    const colT=atCross?'#aebbc1':red?th.curbA:th.curbB,colS=atCross?'#667983':red?th.curbSideA:th.curbSideB;
    for(const sg of[-1,1]){
      if(tightHairpin&&innerSign&&sg===innerSign)continue;
      const l0=sg<0?-w-1.2:w,l1=sg<0?-w:w+1.2;
      // visible face: the one whose outward normal (in world) has positive dot with (1,1)
      const nxw=sg*(T.nx[j]+T.ny[j]);
      const faceLat=(sg>0?(nxw>0?l1:l0):(nxw>0?l0:l1));  // outer face if facing camera else inner face
      const j2=(j+1)%N;
      proj(T.x[j]+T.nx[j]*faceLat,T.y[j]+T.ny[j]*faceLat,T.z[j]);const a0=PX,b0=PY;
       proj(T.x[j2]+T.nx[j2]*faceLat,T.y[j2]+T.ny[j2]*faceLat,T.z[j2]);const a1=PX,b1=PY;
      const hh=.8*k*.95;
      poly(ctx,[a0,b0,a1,b1,a1,b1-hh,a0,b0-hh],colS,null);
      laneQuad(j,l0,l1,.8,_q);poly(ctx,_q.slice(),colT,colT,1);
    }
  }
  // start line
  for(let j=0;j<=1;j++){
    const w=T.w[j]/2,n=11;
    for(let c=0;c<n;c++){laneQuad(j,-w+c*(w*2/n),-w+(c+1)*(w*2/n),.02,_q);poly(ctx,_q.slice(),((c+j)&1)?'#111827':'#f5f7ff',null);}
  }
  // pads
  for(const p of FEAT.pads){
    const ph=(time*2.2)%1;
    const pts=(s0,s1,l0,l1,z)=>{const o=[];for(const [s,l] of[[s0,l0],[s0,l1],[s1,l1],[s1,l0]]){trkAt(s,l);proj(trkAt.x,trkAt.y,trkAt.z+z);o.push(PX,PY);}return o;};
    poly(ctx,pts(p.s,p.s+p.len,-p.w/2,p.w/2,.03),'rgba(40,220,255,.35)','rgba(140,250,255,.95)',2);
    for(let c=0;c<3;c++){
      const u=((c+ph)/3)*(p.len-1.6);
      const L1=[],pp=[[u,-p.w/2+1.2],[u+1.6,0],[u,p.w/2-1.2]];
      ctx.beginPath();pp.forEach((q,i)=>{trkAt(p.s+q[0],q[1]);proj(trkAt.x,trkAt.y,trkAt.z+.05);if(i)ctx.lineTo(PX,PY);else ctx.moveTo(PX,PY);});
      ctx.lineWidth=3;ctx.strokeStyle='rgba(255,255,255,.95)';ctx.stroke();
    }
  }
  // ramps
  for(const rp of FEAT.ramps){
    const hgt=1.7,P=(s,l,dz)=>{trkAt(rp.s+s,rp.lat+l);proj(trkAt.x,trkAt.y,trkAt.z+dz);return[PX,PY];};
    const a=P(0,-rp.w/2,0),b=P(0,rp.w/2,0),c=P(rp.len,rp.w/2,hgt),d=P(rp.len,-rp.w/2,hgt),e=P(rp.len,rp.w/2,0),f=P(rp.len,-rp.w/2,0);
    poly(ctx,[...a,...d,...f],'#b48200',null);poly(ctx,[...b,...c,...e],'#b48200',null);
    poly(ctx,[...a,...b,...c,...d],'#ffb62e','#fff1a8',2);
    // front lip
    poly(ctx,[...d,...c,...e,...f],'#e08a00','#fff1a8',1);
        for(let i=0;i<3;i++){const u=1.2+i*2.3;ctx.beginPath();const p1=P(u,-rp.w/2+1.2,hgt*u/rp.len+.03),p2=P(u+1.2,0,hgt*(u+1.2)/rp.len+.03),p3=P(u,rp.w/2-1.2,hgt*u/rp.len+.03);ctx.moveTo(p1[0],p1[1]);ctx.lineTo(p2[0],p2[1]);ctx.lineTo(p3[0],p3[1]);ctx.lineWidth=3;ctx.strokeStyle='#fff';ctx.stroke();}
   }
   // Steel safety rails continue through intersecting decks; no yellow/black hazard tape is used there.
   if(T.def.overpass&&!lowDetail()){ctx.strokeStyle='#d7e1e5';ctx.lineWidth=Math.max(2,.11*k);for(let j=0;j<N;j+=2){const j2=(j+2)%N;if(T.z[j]<1.5)continue;const tight=T.ka[j]>.010,inner=Math.sign(T.k[j]);for(const sg of[-1,1]){if(tight&&inner&&sg===inner)continue;const l0=sg*T.w[j]/2,l1=sg*T.w[j2]/2;proj(T.x[j]+T.nx[j]*l0,T.y[j]+T.ny[j]*l0,T.z[j]+1.25);const a=[PX,PY];proj(T.x[j2]+T.nx[j2]*l1,T.y[j2]+T.ny[j2]*l1,T.z[j2]+1.25);const b=[PX,PY];ctx.beginPath();ctx.moveTo(...a);ctx.lineTo(...b);ctx.stroke();if(j%8===0){proj(T.x[j]+T.nx[j]*l0,T.y[j]+T.ny[j]*l0,T.z[j]);const d=[PX,PY];ctx.beginPath();ctx.moveTo(...d);ctx.lineTo(...a);ctx.stroke();}}}}
 }


function drawBridgeSupports(){
   if(!T.def.overpass)return;
   for(let j=0;j<T.N;j+=lowDetail()?20:10){const z=T.z[j];if(z<2.2)continue;const w=T.w[j]*.28;
     for(const sg of[-1,1])drawBox(T.x[j]+T.nx[j]*w,T.y[j]+T.ny[j]*w,1.05,T.ang[j],GZ,z-.82,'#aeb9be','#6f7e85','#536169');
     drawBox(T.x[j],T.y[j],Math.max(1.5,T.w[j]*.31),T.ang[j],Math.max(GZ,z-1.25),z-.72,'#c3ccd0','#7c8b92','#5e6c72');
   }
 }
function drawTunnel(time){
  if(!FEAT.tunnel)return;const k=cam.K*cam.zoom,start=FEAT.tunnel.start,end=FEAT.tunnel.end;
  for(let ss=start;ss<end;ss+=15){trkAt(ss,0);const w=trkAt.w/2+1.3,z=trkAt.z,tx=trkAt.tx,ty=trkAt.ty,nx=-ty,ny=tx;
    const lx=trkAt.x+nx*w,ly=trkAt.y+ny*w,rx=trkAt.x-nx*w,ry=trkAt.y-ny*w;
    proj(lx,ly,z);const a=[PX,PY];proj(lx,ly,z+7);const b=[PX,PY];proj(rx,ry,z+7);const c=[PX,PY];proj(rx,ry,z);const d=[PX,PY];
    ctx.strokeStyle='#075aa8';ctx.lineWidth=Math.max(3,.42*k);ctx.beginPath();ctx.moveTo(...a);ctx.lineTo(...b);ctx.lineTo(...c);ctx.lineTo(...d);ctx.stroke();
    ctx.strokeStyle='rgba(242,197,0,.9)';ctx.lineWidth=Math.max(1,.12*k);ctx.beginPath();ctx.moveTo(...b);ctx.lineTo(...c);ctx.stroke();
  }
  trkAt(start,0);proj(trkAt.x,trkAt.y,trkAt.z+7.8);ctx.fillStyle='#075aa8';rr(ctx,PX-4.5*k,PY-1.05*k,9*k,2.1*k,.25*k);ctx.fill();ctx.strokeStyle='#f2c500';ctx.lineWidth=2;ctx.stroke();ctx.fillStyle='#fff';ctx.font='bold '+Math.max(9,Math.round(.72*k))+'px sans-serif';ctx.textAlign='center';ctx.fillText('EATON SERVICE TUNNEL',PX,PY+.25*k);
}

/* ---------- scenery / objects ---------- */
function drawScenery(o){
  const th=trackTheme(),k=cam.K*cam.zoom,sz=o.sz;proj(o.x,o.y,GZ);const bx=PX,by=PY;
  if(o.kind==='panel'||o.kind==='switchgear'){
    const tall=o.kind==='switchgear';ell(ctx,bx,by,(tall?3.8:3.2)*k*sz,1.2*k*sz,'rgba(0,0,0,.18)');drawBox(o.x,o.y,(tall?3.2:2.7)*sz,o.rot||0,GZ,(tall?7.5:6.2)*sz,th.cabinet,shade(th.cabinet,.78),shade(th.cabinet,.58));
    proj(o.x,o.y,(tall?6.6:5.5)*sz);ctx.fillStyle=th.accent;ctx.fillRect(PX-2.2*k*sz,PY-.62*k*sz,4.4*k*sz,1.24*k*sz);ctx.fillStyle='#fff';ctx.font='bold '+Math.max(8,Math.round(.6*k*sz))+'px sans-serif';ctx.textAlign='center';ctx.fillText(tall?'EATON LVA':'LVA PANEL',PX,PY+.22*k*sz);
  }else if(o.kind==='wire'){
    ell(ctx,bx,by,2.8*k*sz,1.1*k*sz,'rgba(0,0,0,.18)');ctx.strokeStyle='#7a4a22';ctx.lineWidth=1.2*k*sz;ctx.beginPath();ctx.arc(bx,by-2.1*k*sz,1.7*k*sz,0,TAU);ctx.stroke();ctx.strokeStyle=o.hue<.5?'#e04b37':'#1b1e22';ctx.lineWidth=.7*k*sz;for(let i=0;i<3;i++){ctx.beginPath();ctx.arc(bx,by-2.1*k*sz,(.7+i*.45)*k*sz,0,TAU);ctx.stroke();}
  }else if(o.kind==='cart'||o.kind==='busbar'){
    drawBox(o.x,o.y,(o.kind==='busbar'?3.1:2.4)*sz,o.rot||0,GZ,(o.kind==='busbar'?2.2:2.8)*sz,o.kind==='busbar'?'#c97932':th.accent,o.kind==='busbar'?'#8f4e20':shade(th.accent,.72),o.kind==='busbar'?'#603117':shade(th.accent,.48));proj(o.x,o.y,3*sz);ctx.fillStyle=T.def?.theme==='arc'?'#f58220':'#f2c500';ctx.fillRect(PX-1.5*k*sz,PY-.42*k*sz,3*k*sz,.84*k*sz);ctx.fillStyle='#fff';ctx.font='bold '+Math.max(7,.48*k*sz)+'px sans-serif';ctx.textAlign='center';ctx.fillText(o.kind==='busbar'?'BUS BAR':'EATON',PX,PY+.2*k*sz);
  }else if(o.kind==='breakerRack'){
    drawBox(o.x,o.y,3*sz,o.rot||0,GZ,4.8*sz,'#dfe5e8','#53616a','#303b40');proj(o.x,o.y,4.2*sz);ctx.fillStyle='#f2c500';ctx.font='bold '+Math.max(8,.62*k*sz)+'px sans-serif';ctx.textAlign='center';ctx.fillText('BREAKERS',PX,PY);for(let q=-1;q<=1;q++){proj(o.x,o.y,2.2*sz+q*.75*sz);ctx.fillStyle='#1d2a30';ctx.fillRect(PX-1.7*k*sz,PY-.2*k*sz,3.4*k*sz,.4*k*sz);}
  }else if(o.kind==='workbench'){
    drawBox(o.x,o.y,3.4*sz,o.rot||0,GZ,2.5*sz,'#8cb5c8','#39708c','#23536b');proj(o.x,o.y,3*sz);ctx.fillStyle='#fff';ctx.font='bold '+Math.max(7,.55*k*sz)+'px sans-serif';ctx.textAlign='center';ctx.fillText('TORQUE STATION',PX,PY);
  }else{
    drawBox(o.x,o.y,2.5*sz,o.rot||0,GZ,5.5*sz,'#eef3f5','#8ea1aa','#657780');proj(o.x,o.y,4.8*sz);ctx.fillStyle='#075aa8';ctx.fillRect(PX-2*k*sz,PY-.9*k*sz,4*k*sz,1.8*k*sz);ctx.fillStyle='#fff';ctx.font='bold '+Math.max(7,.5*k*sz)+'px sans-serif';ctx.textAlign='center';ctx.fillText('SAFETY · QUALITY',PX,PY-.1*k*sz);ctx.fillText('DELIVERY · COST',PX,PY+.5*k*sz);
  }
}
function drawGantry(){
  const w=T.w[0]/2+2.2;
  trkAt(0,-w);const lx=trkAt.x,ly=trkAt.y,lz=trkAt.z;trkAt(0,w);const rx=trkAt.x,ry=trkAt.y,rz=trkAt.z;
  const h=10;
  proj(lx,ly,lz);const l0x=PX,l0y=PY;proj(lx,ly,lz+h);const l1x=PX,l1y=PY;
  proj(rx,ry,rz);const r0x=PX,r0y=PY;proj(rx,ry,rz+h);const r1x=PX,r1y=PY;
  const k=cam.K*cam.zoom;
  ctx.lineCap='round';ctx.strokeStyle='#e9eefc';ctx.lineWidth=.9*k*.7;
  ctx.beginPath();ctx.moveTo(l0x,l0y);ctx.lineTo(l1x,l1y);ctx.moveTo(r0x,r0y);ctx.lineTo(r1x,r1y);ctx.stroke();
  proj(lx,ly,lz+h-3);const b0x=PX,b0y=PY;proj(rx,ry,rz+h-3);const b1x=PX,b1y=PY;
  const th=trackTheme(),circuit=circuitForTrack(T.def.id);poly(ctx,[l1x,l1y,r1x,r1y,b1x,b1y,b0x,b0y],th.accent,'#ffe14a',2);
  // checker strip
  for(let i=0;i<10;i++){const u0=i/10,u1=(i+1)/10;const f=(u,v)=>[lerp(l1x,r1x,u)+(lerp(b0x,b1x,u)-lerp(l1x,r1x,u))*v,lerp(l1y,r1y,u)+(lerp(b0y,b1y,u)-lerp(l1y,r1y,u))*v];
    const p1=f(u0,0),p2=f(u1,0),p3=f(u1,.3),p4=f(u0,.3);poly(ctx,[...p1,...p2,...p3,...p4],(i&1)?'#111':'#fff',null);}
  ctx.font='bold '+Math.round(1.5*k)+'px "Trebuchet MS",sans-serif';ctx.textAlign='center';ctx.fillStyle='#fff';
  ctx.fillText(circuit?'EATON · '+circuit.short:'EATON · LVA ASCENDERS',(l1x+r1x+b0x+b1x)/4,(l1y+r1y+b0y+b1y)/4+.7*k);
}
function drawBox3(b,time){
  const base=b.z||0,z=base+1.8+Math.sin(time*3+b.s)*.35,rot=time*1.6+b.s;
  const col=Math.sin(time*5+b.s)>0?'#1686c4':'#f2c500';
  proj(b.x,b.y,base);ell(ctx,PX,PY,1.4*cam.K*cam.zoom,.6*cam.K*cam.zoom,'rgba(0,0,0,.2)');
  drawBox(b.x,b.y,.85,rot,z,z+1.7,'#f5f8fa',col,shade('#075aa8',.8));
  proj(b.x,b.y,z+1.9);ctx.font='bold '+Math.round(1.7*cam.K*cam.zoom)+'px "Trebuchet MS",sans-serif';ctx.textAlign='center';ctx.fillStyle='#075aa8';ctx.fillText('LVA',PX,PY+.5*cam.K*cam.zoom);
}
function drawDropBox(b,time){const k=cam.K*cam.zoom,z=(b.z||0)+1.4+Math.sin(time*4+b.s)*.25,rot=time*1.2+b.s,col=ITEM_DEF[b.item]?.col||'#f2c500';proj(b.x,b.y,b.z||0);ell(ctx,PX,PY,1.7*k,.65*k,'rgba(0,0,0,.25)');drawBox(b.x,b.y,.95,rot,z,z+1.9,'#fff7cf',col,shade(col,.65));proj(b.x,b.y,z+2.2);ctx.fillStyle='#17313f';ctx.font='900 '+Math.max(7,Math.round(.62*k))+'px sans-serif';ctx.textAlign='center';ctx.fillText('DROP',PX,PY);}
function drawMine(m,time){
  proj(m.x,m.y,0);const k=cam.K*cam.zoom,x=PX,y=PY,blink=(m.t>.8&&Math.sin(time*10)>0);
  ell(ctx,x,y,1.6*k,.65*k,'rgba(0,0,0,.25)');ctx.save();ctx.translate(x,y-.9*k);ctx.rotate(-.18);
  ctx.fillStyle='#303b40';rr(ctx,-1.05*k,-1.25*k,2.1*k,2.5*k,.2*k);ctx.fill();ctx.strokeStyle='#aebbc1';ctx.lineWidth=Math.max(1,.09*k);ctx.stroke();
  ctx.fillStyle='#eef3f5';rr(ctx,-.55*k,-.7*k,1.1*k,1.35*k,.12*k);ctx.fill();ctx.fillStyle=blink?'#ff5538':'#075aa8';rr(ctx,-.22*k,-.5*k,.44*k,.75*k,.08*k);ctx.fill();
  ctx.fillStyle='#f2c500';ctx.font='bold '+Math.max(7,Math.round(.38*k))+'px sans-serif';ctx.textAlign='center';ctx.fillText('BRK',0,1.05*k);ctx.restore();
}
function drawMissile(m){
  const c=Math.cos(m.h),s=Math.sin(m.h);
  proj(m.x,m.y,1.4);const x=PX,y=PY;proj(m.x-c*2.2,m.y-s*2.2,1.4);const tx=PX,ty=PY;
  proj(m.x,m.y,0);ell(ctx,PX,PY,.9*cam.K*cam.zoom,.4*cam.K*cam.zoom,'rgba(0,0,0,.2)');
  ctx.lineCap='round';ctx.strokeStyle='#ff9a4a';ctx.lineWidth=.9*cam.K*cam.zoom;ctx.beginPath();ctx.moveTo(tx,ty);ctx.lineTo(tx-(x-tx)*.4,ty-(y-ty)*.4);ctx.stroke();
  ctx.strokeStyle='#f2f4ff';ctx.lineWidth=.85*cam.K*cam.zoom;ctx.beginPath();ctx.moveTo(tx,ty);ctx.lineTo(x,y);ctx.stroke();
  ctx.fillStyle='#ff4a4a';ctx.beginPath();ctx.arc(x,y,.55*cam.K*cam.zoom,0,TAU);ctx.fill();
}
function drawEMP(e){
  const rad=e.t*50,k=cam.K*cam.zoom;proj(e.x,e.y,.2);
  ctx.strokeStyle='rgba(110,255,220,'+(1-e.t/.65).toFixed(2)+')';ctx.lineWidth=5;
  ctx.beginPath();ctx.ellipse(PX,PY,rad*k*1.414,rad*k*.707,0,0,TAU);ctx.stroke();
  ctx.lineWidth=2;ctx.beginPath();ctx.ellipse(PX,PY,rad*.8*k*1.414,rad*.8*k*.707,0,0,TAU);ctx.stroke();
}

/* ---------- racer ---------- */
function drawForkTruckBase(r,ang,bz,time){
  const k=cam.K*cam.zoom,ca=Math.cos(ang),sa=Math.sin(ang),wp=(lx,ly,z)=>{proj(r.x+lx*ca-ly*sa,r.y+lx*sa+ly*ca,bz+z);return[PX,PY];};
  const face=(q,col,stroke='#381b1b')=>poly(ctx,q.flat(),col,stroke,1.5);
  const A=wp(-2.5,-1.25,.42),B=wp(1.4,-1.25,.42),C=wp(1.7,1.25,.42),D=wp(-2.5,1.25,.42),A0=wp(-2.5,-1.25,-.08),B0=wp(1.4,-1.25,-.08),C0=wp(1.7,1.25,-.08),D0=wp(-2.5,1.25,-.08);
  face([A,B,B0,A0],shade(r.boardColor,.72));face([B,C,C0,B0],shade(r.boardColor,.52));face([C,D,D0,C0],shade(r.boardColor,.88));face([A,B,C,D],r.boardColor);
  // Raised operator deck and three small compartment walls around the rider.
  const p1=wp(-1.68,-.86,.8),p2=wp(-.12,-.86,.8),p3=wp(-.12,.86,.8),p4=wp(-1.68,.86,.8);face([p1,p2,p3,p4],'#3e4d55');
  const wall=(a,b,top=.62)=>face([wp(...a,.82),wp(...b,.82),wp(...b,.82+top),wp(...a,.82+top)],shade(r.boardColor,.82),shade(r.boardColor,.42));
  wall([-1.68,-.86],[-.25,-.86]);wall([-.25,.86],[-1.68,.86]);wall([-1.68,.86],[-1.68,-.86],.78);
  // Rounded red counterweight without branding.
  face([wp(-2.45,-1.02,.5),wp(-1.35,-1.02,.5),wp(-1.35,-1.02,1.42),wp(-2.45,-1.02,1.42)],shade(r.boardColor,.9));
  ctx.strokeStyle='#26343b';ctx.lineWidth=Math.max(2,.17*k);for(const ly of[-.95,.95]){let a=wp(1.28,ly,.4),b=wp(1.28,ly,3.2);ctx.beginPath();ctx.moveTo(...a);ctx.lineTo(...b);ctx.stroke();}
  let g1=wp(-1.55,-.95,2.9),g2=wp(.75,-.95,2.9),g3=wp(.75,.95,2.9),g4=wp(-1.55,.95,2.9);face([g1,g2,g3,g4],'rgba(65,82,90,.42)');
  let st0=wp(-.25,0,.82),st1=wp(.18,0,1.7);ctx.beginPath();ctx.moveTo(...st0);ctx.lineTo(...st1);ctx.stroke();ell(ctx,st1[0],st1[1],.36*k,.18*k,'#20282c');
  const fc1=wp(1.22,-1.12,.45),fc2=wp(1.22,1.12,.45),fc3=wp(1.22,1.12,1.25),fc4=wp(1.22,-1.12,1.25);face([fc1,fc2,fc3,fc4],'#34444c');ctx.strokeStyle='#303b40';ctx.lineWidth=Math.max(2,.2*k);for(const ly of[-.82,.82]){let a=wp(1.25,ly,.32),b=wp(4.25,ly,.32);ctx.beginPath();ctx.moveTo(...a);ctx.lineTo(...b);ctx.stroke();}
  // Tall, upright tires with visible rims instead of flat floor ellipses.
  const wheel=(lx,ly)=>{const p=wp(lx,ly,.12);ctx.save();ctx.translate(p[0],p[1]);ctx.rotate((ly<0?-1:1)*.18);ell(ctx,0,0,.38*k,.66*k,'#14191c');ell(ctx,0,0,.18*k,.34*k,'#89969c');ell(ctx,0,0,.07*k,.14*k,'#303a3f');ctx.restore();};
  for(const q of[[-1.75,-1.32],[-1.75,1.32],[1.05,-1.32],[1.05,1.32]])wheel(q[0],q[1]);
  if(r.boostT>0){const p=wp(-2.8,0,.58);ell(ctx,p[0],p[1],.85*k,.4*k,'rgba(255,130,40,.9)');}
}
const GOLD_RIDER_CANVAS=document.createElement('canvas');GOLD_RIDER_CANVAS.width=300;GOLD_RIDER_CANVAS.height=320;const GOLD_RIDER_CTX=GOLD_RIDER_CANVAS.getContext('2d');
function drawGoldenRider(target,x,y,s,ch,o){const g=GOLD_RIDER_CTX;g.clearRect(0,0,300,320);drawRider(g,150,270,s,ch,o);g.save();g.globalCompositeOperation='source-atop';const shine=g.createLinearGradient(70,80,230,270);shine.addColorStop(0,'rgba(255,249,190,.9)');shine.addColorStop(.35,'rgba(255,205,40,.72)');shine.addColorStop(.58,'rgba(255,246,175,.95)');shine.addColorStop(1,'rgba(186,116,0,.78)');g.fillStyle=shine;g.fillRect(0,0,300,320);g.globalCompositeOperation='screen';g.globalAlpha=.65;g.fillStyle='#fff3a6';g.beginPath();g.moveTo(108,82);g.lineTo(126,82);g.lineTo(190,270);g.lineTo(170,270);g.closePath();g.fill();g.restore();target.drawImage(GOLD_RIDER_CANVAS,x-150,y-270);}
function drawRacer(r,time){
  const k=cam.K*cam.zoom,c=Math.cos(r.h),s=Math.sin(r.h),pride=prideSetActive(r),holy=holySetActive(r),brown=r.invincibleT>0;
  const hov=.35+Math.sin(r.bob)*.07;
  const flick=(r.invT>0&&r.stunT<=0&&Math.floor(time*16)%2===0)?.45:1;
  ctx.globalAlpha=flick;
  ctx.save();if(brown){ctx.filter='sepia(.95) saturate(1.45) hue-rotate(-12deg)';if(!lowDetail()){ctx.shadowColor='#8b5a2b';ctx.shadowBlur=42*cam.zoom;}}else if((pride||holy)&&!lowDetail()){ctx.shadowColor=holy?'#ffd84d':'#1686ff';ctx.shadowBlur=(holy?34:30)*cam.zoom;}
  // shadow
  proj(r.x,r.y,r.baseZ||0);const sx=PX,sy=PY;const sh=clamp(1-r.z/12,.35,1);
  ell(ctx,sx,sy,2.5*k*sh,1.2*k*sh,'rgba(10,20,50,.28)');
  ctx.globalAlpha=.22*flick;ell(ctx,sx,sy,1.8*k*sh,.85*k*sh,r.boardColor);ctx.globalAlpha=flick;
  const ang=r.h+r.trickRot+(r.stunT>0?r.spin*.6:0)+driftVisualAngle(r);
  const ca=Math.cos(ang),sa=Math.sin(ang);
  const bz=(r.baseZ||0)+r.z+hov;
  if(SV.fork)drawForkTruckBase(r,ang,bz,time);else{
    const loc=[[2.2,0],[1.3,.8],[-1.7,.8],[-2.2,.45],[-2.2,-.45],[-1.7,-.8],[1.3,-.8]],pts=[],pts2=[];
    for(const q of loc){proj(r.x+q[0]*ca-q[1]*sa,r.y+q[0]*sa+q[1]*ca,bz);pts.push(PX,PY);}
    for(const q of loc){proj(r.x+q[0]*.62*ca-q[1]*.55*sa,r.y+q[0]*.62*sa+q[1]*.55*ca,bz+.06);pts2.push(PX,PY);}
    const th=.28*k*.95,under=[];for(let i=0;i<pts.length;i+=2)under.push(pts[i],pts[i+1]+th);
    ctx.save();if((r.boardId==='gold'||r.boardId==='pride')&&!lowDetail()){ctx.shadowColor=r.boardId==='gold'?'#ffd84d':'#1686ff';ctx.shadowBlur=(holy||pride?30:12)*cam.zoom;}poly(ctx,under,shade(r.boardColor,.55),null);poly(ctx,pts,r.boardColor,'rgba(10,20,50,.7)',1.5);poly(ctx,pts2,shade(r.boardColor,1.25),'rgba(255,255,255,.5)',1);if(r.boardId==='gold'){ctx.globalAlpha=.38;ctx.strokeStyle='#fff3a6';ctx.lineWidth=Math.max(2,3*cam.zoom);poly(ctx,pts,null,ctx.strokeStyle,ctx.lineWidth);}if(r.boardId==='pride'){ctx.globalAlpha=.95;ctx.fillStyle='#fff';ctx.font='900 '+Math.max(8,Math.round(13*cam.zoom))+'px sans-serif';ctx.textAlign='center';ctx.fillText('E',pts2[2],pts2[3]+4*cam.zoom);}ctx.restore();
    const th2=(r.boostT>0||r.invincibleT>0);for(const side of[-.45,.45]){proj(r.x-2.3*ca-side*(-sa),r.y-2.3*sa+side*ca,bz);const fl=(th2?1.6:.75)*(.9+.1*Math.sin(time*25+r.bob));ell(ctx,PX,PY,.7*k*fl,.4*k*fl,th2?'rgba(255,170,60,.95)':'rgba(120,230,255,.85)');ell(ctx,PX,PY,.35*k*fl,.2*k*fl,'rgba(255,255,255,.95)');}
  }
  // scarf
  if(r.trail.length>2){
    ctx.lineCap='round';
    const n=Math.min(r.trail.length,lowDetail()?4:7);
    for(let i=0;i<n-1;i++){
      const a=r.trail[i],b=r.trail[i+1],za=3.2-i*.08+Math.sin(time*9+i*.9)*.3,zb=3.2-(i+1)*.08+Math.sin(time*9+(i+1)*.9)*.3;
      const wob=Math.sin(time*7+i)*.25;
      proj(a.x+wob*(-s),a.y+wob*c,(a.baseZ||0)+a.z+za);const x0=PX,y0=PY;proj(b.x+wob*(-s),b.y+wob*c,(b.baseZ||0)+b.z+zb);
      ctx.strokeStyle=i%2?r.ch.accent:r.ch.outfit;ctx.lineWidth=Math.max(1,(3.2-i*.28)*cam.zoom);ctx.beginPath();ctx.moveTo(x0,y0);ctx.lineTo(PX,PY);ctx.stroke();
    }
  }
  // rider
  proj(r.x,r.y,bz+(SV.fork?.84:.15));
  const fdx=(c-s),fdy=(c+s)*.5,front=fdy>-.1;
  const fx=clamp(fdx,-1,1);
  const lean=clamp(r.steer*(front?-1:1)*(r.drifting?.9:.5),-1,1);
  const rs=cam.zoom*(SV.fork?.92:1.08);
  let rot=0;if(r.stunT>0)rot=Math.sin(r.spin*.6)*.5;
  if(r.air&&!r.hop)rot=Math.sin(r.trickRot*.5)*.35;
  const riderOpts={fx,front,lean,t:time+r.bob,arm:(r.boostT>0||r.air)?1:r.drifting?.6:0,rot,cheer:r.finished||r.boostT>0,hatId:r.hatId};if(holy)drawGoldenRider(ctx,PX,PY,rs,r.ch,riderOpts);else drawRider(ctx,PX,PY,rs,r.ch,riderOpts);
  // stun stars
  if(r.stunT>0){for(let i=0;i<3;i++){const a=time*8+i*TAU/3;ctx.fillStyle='#ffe14a';ctx.beginPath();ctx.arc(PX+Math.cos(a)*14*rs,PY-62*rs+Math.sin(a)*5*rs,3.2*rs,0,TAU);ctx.fill();}}
  // shield
  if(r.shieldT>0){
    const rad=40*cam.zoom,cy=PY-24*rs;
    const g=ctx.createRadialGradient(PX,cy,rad*.2,PX,cy,rad);g.addColorStop(0,'rgba(120,220,255,.05)');g.addColorStop(1,'rgba(120,220,255,.45)');
    ctx.globalAlpha=(r.shieldT<2&&Math.floor(time*10)%2?.4:1)*flick;
    ctx.fillStyle=g;ctx.beginPath();ctx.arc(PX,cy,rad,0,TAU);ctx.fill();ctx.strokeStyle='rgba(200,245,255,.9)';ctx.lineWidth=2;ctx.stroke();
  }
  ctx.restore();ctx.globalAlpha=1;
  // name tag
  if(!r.isPlayer){ctx.font='bold '+Math.max(10,Math.round(11*cam.zoom*1.1))+'px "Trebuchet MS",sans-serif';ctx.textAlign='center';ctx.lineWidth=3;ctx.strokeStyle='rgba(20,30,70,.7)';ctx.fillStyle='#fff';const ty=PY-70*rs;ctx.strokeText(r.name,PX,ty);ctx.fillText(r.name,PX,ty);}
  else{ctx.fillStyle='#ffe14a';const ty=PY-70*rs;ctx.beginPath();ctx.moveTo(PX,ty);ctx.lineTo(PX-6*rs,ty-9*rs);ctx.lineTo(PX+6*rs,ty-9*rs);ctx.closePath();ctx.fill();}
}

function drawParticles(){
  for(const p of G.parts){
    proj(p.x,p.y,p.z);if(PX<-24||PX>W+24||PY<-24||PY>H+24)continue;const a=clamp(p.life/p.max,0,1);
    ctx.globalAlpha=a;ctx.fillStyle=p.col;ctx.beginPath();ctx.arc(PX,PY,Math.max(.6,p.r*cam.zoom*(.4+.6*a)),0,TAU);ctx.fill();
  }
  ctx.globalAlpha=1;
}

function drawSceneryCached(o){
  const sz=Math.round(o.sz*5)/5,hue=Math.min(2,Math.floor(o.hue*3)),key=o.kind+':'+sz+':'+hue;
  let entry=scenerySprites.get(key);
  if(!entry){
    const sprite=smoothCanvas(240,300),oldCtx=ctx,oldW=W,oldH=H,oldCam={...cam};
    try{ctx=sprite.getContext('2d');W=240;H=300;cam.x=o.x;cam.y=o.y;cam.zoom=1;cam.sy=110;
      drawScenery({...o,sz,hue:(hue+.5)/3});entry={canvas:sprite,x:120,y:260};scenerySprites.set(key,entry);
    }finally{ctx=oldCtx;W=oldW;H=oldH;Object.assign(cam,oldCam);}
  }
  proj(o.x,o.y,0);const z=cam.zoom;
  ctx.drawImage(entry.canvas,PX-entry.x*z,PY-entry.y*z,entry.canvas.width*z,entry.canvas.height*z);
}
function drawTrainingFloor(){
  drawSky();const step=10;for(let x=TRAIN.xmin;x<TRAIN.xmax;x+=step)for(let y=TRAIN.ymin;y<TRAIN.ymax;y+=step){const p=[];for(const q of[[x,y],[x+step,y],[x+step,y+step],[x,y+step]]){proj(q[0],q[1],GZ);p.push(PX,PY);}poly(ctx,p,(((x/step+y/step)&1)?'#c4d0d5':'#b7c5cb'),'rgba(70,95,105,.22)',1);}
  const k=cam.K*cam.zoom,path=[];for(const q of TRAIN.testTrack){proj(q[0],q[1],.02);path.push([PX,PY]);}ctx.save();ctx.lineJoin='round';ctx.lineCap='round';ctx.beginPath();path.forEach((p,i)=>i?ctx.lineTo(...p):ctx.moveTo(...p));ctx.closePath();ctx.strokeStyle='#4b626d';ctx.lineWidth=22*k;ctx.stroke();ctx.strokeStyle='#f2c500';ctx.lineWidth=1.1*k;ctx.setLineDash([3*k,3*k]);ctx.stroke();ctx.setLineDash([]);ctx.strokeStyle='rgba(255,255,255,.8)';ctx.lineWidth=.35*k;ctx.stroke();ctx.restore();
  for(const q of[[-185,-125],[170,118]]){proj(q[0],q[1],.06);ctx.fillStyle='#075aa8';rr(ctx,PX-4.5*k,PY-1.4*k,9*k,2.8*k,.3*k);ctx.fill();ctx.strokeStyle='#f2c500';ctx.lineWidth=2;ctx.stroke();ctx.fillStyle='#fff';ctx.font='bold '+Math.max(8,Math.round(.72*k))+'px sans-serif';ctx.textAlign='center';ctx.fillText('EATON LVA',PX,PY+.25*k);}
  const corners=[[TRAIN.xmin,TRAIN.ymin],[TRAIN.xmax,TRAIN.ymin],[TRAIN.xmax,TRAIN.ymax],[TRAIN.xmin,TRAIN.ymax]];ctx.strokeStyle='#f2c500';ctx.lineWidth=5;ctx.beginPath();corners.forEach((q,i)=>{proj(q[0],q[1],0);i?ctx.lineTo(PX,PY):ctx.moveTo(PX,PY);});ctx.closePath();ctx.stroke();
}
function drawAssetSilhouetteShadow(img,x,y,w,h){
  ctx.save();ctx.translate(x,y);ctx.transform(1,.18,-.42,.2,0,0);ctx.globalAlpha=.24;ctx.filter='brightness(0)';ctx.drawImage(img,-w/2,-h,w,h);ctx.restore();
}
function drawLVAAssetProp(o){
  const img=LVA_IMAGES.get(o.asset);if(!img)return;const k=cam.K*cam.zoom,m=LVAEnvironmentAssets.manifest[o.asset],ratio=m?m.native[1]/m.native[0]:1;
  proj(o.x,o.y,GZ);const w=o.w*ASSET_SCALE*k,h=o.w*ASSET_SCALE*ratio*k;if(!lowDetail())drawAssetSilhouetteShadow(img,PX,PY,w,h);ctx.drawImage(img,PX-w/2,PY-h,w,h);
}
function drawTrainingObject(o){
  if(o.kind==='lvaAsset'){drawLVAAssetProp(o);return;}if(['panel','wire','cart'].includes(o.kind)){drawScenery(o);return;}const k=cam.K*cam.zoom;
  if(o.kind==='switchgear'){drawBox(o.x,o.y,3.8*o.sz,o.rot,GZ,7.5*o.sz,'#e8edf0','#9eacb3','#74858d');proj(o.x,o.y,6.6*o.sz);ctx.fillStyle='#075aa8';ctx.fillRect(PX-2.5*k*o.sz,PY-.65*k*o.sz,5*k*o.sz,1.3*k*o.sz);ctx.fillStyle='#fff';ctx.font='bold '+Math.max(8,.65*k*o.sz)+'px sans-serif';ctx.textAlign='center';ctx.fillText('LVA SWITCHGEAR',PX,PY+.2*k*o.sz);}
  else if(o.kind==='breaker'){drawBox(o.x,o.y,2.6*o.sz,o.rot,GZ,3.7*o.sz,'#dfe5e8','#343f45','#1f292e');proj(o.x,o.y,3.2*o.sz);ctx.fillStyle='#f2c500';ctx.font='bold '+Math.max(8,.7*k*o.sz)+'px sans-serif';ctx.textAlign='center';ctx.fillText('BREAKER',PX,PY);}
  else if(o.kind==='tool'){drawBox(o.x,o.y,3.2*o.sz,o.rot,GZ,2.6*o.sz,'#d64532','#9d2e24','#742018');proj(o.x,o.y,2.9*o.sz);ctx.fillStyle='#fff';ctx.font='bold '+Math.max(8,.65*k*o.sz)+'px sans-serif';ctx.textAlign='center';ctx.fillText('TOOLS',PX,PY);}
  else if(o.kind==='line'){const cs=Math.cos(o.rot),sn=Math.sin(o.rot);for(let i=-2;i<=2;i++){const x=o.x+i*3*cs,y=o.y+i*3*sn;drawBox(x,y,2.1*o.sz,o.rot,GZ,2.1*o.sz,'#60a3c4','#246b8c','#164b66');}proj(o.x,o.y,2.6*o.sz);ctx.fillStyle='#fff';ctx.font='bold '+Math.max(8,.7*k*o.sz)+'px sans-serif';ctx.textAlign='center';ctx.fillText('ASSEMBLY LINE',PX,PY);}
  else if(o.kind==='quality'){drawBox(o.x,o.y,2.8*o.sz,o.rot,GZ,5.5*o.sz,'#eef3f5','#8ea1aa','#657780');proj(o.x,o.y,4.8*o.sz);ctx.fillStyle='#075aa8';ctx.fillRect(PX-2.1*k*o.sz,PY-.9*k*o.sz,4.2*k*o.sz,1.8*k*o.sz);ctx.fillStyle='#fff';ctx.font='bold '+Math.max(7,.5*k*o.sz)+'px sans-serif';ctx.textAlign='center';ctx.fillText('SAFETY · QUALITY',PX,PY-.15*k*o.sz);ctx.fillText('DELIVERY · COST',PX,PY+.5*k*o.sz);}
}
function drawTrainingRamp(rp){const cs=Math.cos(rp.rot),sn=Math.sin(rp.rot),P=(lx,ly,z)=>{proj(rp.x+lx*cs-ly*sn,rp.y+lx*sn+ly*cs,z);return[PX,PY];},a=P(-rp.len/2,-rp.w/2,0),b=P(-rp.len/2,rp.w/2,0),c=P(rp.len/2,rp.w/2,2),d=P(rp.len/2,-rp.w/2,2),e=P(rp.len/2,rp.w/2,0),f=P(rp.len/2,-rp.w/2,0);poly(ctx,[...a,...b,...c,...d],'#f2a82c','#fff3b0',2);poly(ctx,[...d,...c,...e,...f],'#b87800','#fff3b0',1);}
function drawTrainingPad(p,time){const cs=Math.cos(p.rot),sn=Math.sin(p.rot),pts=[];for(const q of[[-p.len/2,-p.w/2],[-p.len/2,p.w/2],[p.len/2,p.w/2],[p.len/2,-p.w/2]]){proj(p.x+q[0]*cs-q[1]*sn,p.y+q[0]*sn+q[1]*cs,.04);pts.push(PX,PY);}poly(ctx,pts,'rgba(40,220,255,.38)','rgba(180,255,255,.95)',2);}
function renderTrainingWorld(time){
  drawTrainingFloor();for(const p of TRAIN.pads)drawTrainingPad(p,time);for(const r of TRAIN.ramps)drawTrainingRamp(r);const objs=[];for(const a of TRAIN.assets)if(a.backdrop&&screenVisible(a,220))objs.push({k:a.x+a.y,t:-1,o:a});for(const o of TRAIN.obstacles)if(screenVisible(o,180))objs.push({k:o.x+o.y,t:0,o});for(const b of TRAIN.boxes)if(b.t<=0&&screenVisible(b))objs.push({k:b.x+b.y,t:1,o:b});for(const b of G.dropBoxes)if(screenVisible(b))objs.push({k:b.x+b.y,t:2,o:b});for(const m of G.mines)if(screenVisible(m))objs.push({k:m.x+m.y,t:3,o:m});for(const m of G.missiles)if(screenVisible(m))objs.push({k:m.x+m.y,t:4,o:m});for(const r of G.racers)if(r.isPlayer||screenVisible(r,180))objs.push({k:r.x+r.y,t:5,o:r});objs.sort((a,b)=>a.k-b.k);for(const e of objs){if(e.t===-1)drawLVAAssetProp(e.o);else if(e.t===0)drawTrainingObject(e.o);else if(e.t===1)drawBox3(e.o,time);else if(e.t===2)drawDropBox(e.o,time);else if(e.t===3)drawMine(e.o,time);else if(e.t===4)drawMissile(e.o);else drawRacer(e.o,time);}for(const e of G.emps)drawEMP(e);drawParticles();
}
function renderWorld(time){
  if(G.training){renderTrainingWorld(time);return;}drawSky();drawIsland();drawArdenPlantMap();drawBridgeSupports();drawRoad(time);drawTunnel(time);
  const objs=[];const k=cam.K*cam.zoom,mg=k*28;
  for(const sc of FEAT.scenery){proj(sc.x,sc.y,0);if(PX<-mg||PX>W+mg||PY<-mg*1.5||PY>H+mg)continue;objs.push({k:sc.x+sc.y,t:0,o:sc});}
  for(const a of FEAT.assetProps){proj(a.x,a.y,0);if(PX<-mg||PX>W+mg||PY<-mg*1.5||PY>H+mg)continue;objs.push({k:a.x+a.y,t:0,o:a});}
  objs.push({k:(trkAt(0,0),trkAt.x+trkAt.y),t:1});
  for(const b of FEAT.boxes)if(b.t<=0&&screenVisible(b))objs.push({k:b.x+b.y,t:2,o:b});
  for(const b of G.dropBoxes)if(screenVisible(b))objs.push({k:b.x+b.y,t:3,o:b});
  for(const m of G.mines)if(screenVisible(m))objs.push({k:m.x+m.y,t:4,o:m});
  for(const m of G.missiles)if(screenVisible(m))objs.push({k:m.x+m.y,t:5,o:m});
  for(const r of G.racers)if(r.isPlayer||screenVisible(r,180))objs.push({k:r.x+r.y+.01,t:6,o:r});
  objs.sort((a,b)=>a.k-b.k);
  for(const e of objs){
    if(e.t===0)(e.o.asset?drawLVAAssetProp(e.o):drawSceneryCached(e.o));else if(e.t===1)drawGantry();else if(e.t===2)drawBox3(e.o,time);else if(e.t===3)drawDropBox(e.o,time);else if(e.t===4)drawMine(e.o,time);else if(e.t===5)drawMissile(e.o);else drawRacer(e.o,time);
  }
  for(const e of G.emps)drawEMP(e);
  drawParticles();
}

/* ===================== HUD ===================== */
function drawItemIcon(c,type,x,y,s){
  c.save();c.translate(x,y);c.scale(s,s);c.lineCap='round';c.lineJoin='round';
  if(type==='missile'){
    c.fillStyle='#ff6a2a';poly(c,[-5,-24,12,-8,3,-5,17,8,2,5,7,24,-13,5,-4,2,-18,-10,-2,-7],c.fillStyle,'#fff',2.5);
  }else if(type==='flash'){
    c.fillStyle='#fff9c7';c.beginPath();for(let i=0;i<16;i++){const a=i*TAU/16,r=i%2?10:24;c.lineTo(Math.cos(a)*r,Math.sin(a)*r);}c.closePath();c.fill();c.strokeStyle='#f2c500';c.lineWidth=2;c.stroke();c.fillStyle='#17313f';c.font='bold 8px sans-serif';c.textAlign='center';c.fillText('ARK',0,3);
  }else if(type==='shield'){
    c.fillStyle='#4bd0ff';c.beginPath();c.moveTo(0,-20);c.quadraticCurveTo(18,-16,18,-4);c.quadraticCurveTo(16,14,0,22);c.quadraticCurveTo(-16,14,-18,-4);c.quadraticCurveTo(-18,-16,0,-20);c.fill();c.strokeStyle='#fff';c.lineWidth=3;c.stroke();c.fillStyle='#075aa8';c.font='bold 12px sans-serif';c.textAlign='center';c.fillText('AS',0,4);
  }else if(type==='boost'){
    c.fillStyle='#f2c500';rr(c,-12,-21,24,42,6);c.fill();c.strokeStyle='#fff';c.lineWidth=2.5;c.stroke();c.fillStyle='#075aa8';c.font='bold 12px sans-serif';c.textAlign='center';c.fillText('AQ',0,4);c.strokeStyle='#34444c';c.lineWidth=3;c.beginPath();c.moveTo(0,-21);c.lineTo(0,-28);c.lineTo(9,-28);c.stroke();
  }else if(type==='tripulse'){
    for(let i=0;i<3;i++){c.fillStyle=['#ffd166','#ff9f43','#f26b38'][i];rr(c,-15+i*10,-18+i*5,13,28,4);c.fill();c.strokeStyle='#fff';c.lineWidth=1.8;c.stroke();}c.fillStyle='#17313f';c.font='bold 12px sans-serif';c.textAlign='center';c.fillText('3×',0,5);
  }else if(type==='shift'){
    c.fillStyle='#ad7cff';poly(c,[-20,8,-5,-8,-5,1,14,-18,6,5,18,5,0,22,0,11],c.fillStyle,'#fff',2.5);c.fillStyle='#fff';c.font='bold 8px sans-serif';c.textAlign='center';c.fillText('SD',0,5);
  }else if(type==='mine'){
    c.fillStyle='#303b40';rr(c,-17,-22,34,44,5);c.fill();c.strokeStyle='#d7e0e4';c.lineWidth=2.5;c.stroke();c.fillStyle='#eef3f5';rr(c,-9,-11,18,20,3);c.fill();c.fillStyle='#075aa8';rr(c,-3,-7,6,12,2);c.fill();c.fillStyle='#f2c500';c.font='bold 9px sans-serif';c.textAlign='center';c.fillText('BRK',0,18);
  }else if(type==='emp'){
    c.strokeStyle='#6bffd0';c.lineWidth=4;for(let i=1;i<=3;i++){c.globalAlpha=1-i*.22;c.beginPath();c.arc(0,0,i*7,0,TAU);c.stroke();}c.globalAlpha=1;c.fillStyle='#fff';c.beginPath();c.arc(0,0,3,0,TAU);c.fill();c.fillStyle='#075aa8';c.font='bold 9px sans-serif';c.textAlign='center';c.fillText('GF',0,4);
  }else if(type==='culture'){
    c.fillStyle='#2fb77d';c.beginPath();c.arc(0,0,22,0,TAU);c.fill();c.strokeStyle='#fff3a6';c.lineWidth=3;c.stroke();c.fillStyle='#fff';c.font='bold 13px sans-serif';c.textAlign='center';c.fillText('E★',0,5);
  }
  c.restore();
}
function keyTile(c,x,y,sz,label,state){
  c.save();
  c.fillStyle=state==='done'?'#7ef0a0':state==='next'?'#ffe14a':'rgba(255,255,255,.85)';
  rr(c,x,y,sz,sz,sz*.2);c.fill();c.lineWidth=3;c.strokeStyle=state==='next'?'#ff9a1a':'rgba(30,40,100,.6)';c.stroke();
  c.fillStyle='#233';c.font='bold '+Math.round(sz*.58)+'px "Trebuchet MS",sans-serif';c.textAlign='center';c.textBaseline='middle';c.fillText(label,x+sz/2,y+sz/2+1);
  c.restore();
}
let mmB=null;
function drawMinimap(x,y,w,h){
  if(!mmB){let a=1e9,b=-1e9,c2=1e9,d=-1e9;for(let j=0;j<T.N;j+=3){const mx=T.x[j]-T.y[j],my=(T.x[j]+T.y[j])*.5;a=Math.min(a,mx);b=Math.max(b,mx);c2=Math.min(c2,my);d=Math.max(d,my);}mmB={a,b,c:c2,d};}
  const pad=12,sc=Math.min((w-pad*2)/(mmB.b-mmB.a),(h-pad*2)/(mmB.d-mmB.c));
  const ox=x+w/2-(mmB.a+mmB.b)/2*sc,oy=y+h/2-(mmB.c+mmB.d)/2*sc;
  const mp=(px,py)=>[ox+(px-py)*sc,oy+(px+py)*.5*sc];
  ctx.save();ctx.fillStyle='rgba(20,30,80,.5)';rr(ctx,x,y,w,h,12);ctx.fill();ctx.strokeStyle='rgba(255,255,255,.5)';ctx.lineWidth=2;ctx.stroke();
  ctx.lineJoin='round';ctx.lineCap='round';
  ctx.beginPath();for(let j=0;j<=T.N;j+=2){const p=mp(T.x[j%T.N],T.y[j%T.N]);if(j)ctx.lineTo(p[0],p[1]);else ctx.moveTo(p[0],p[1]);}ctx.closePath();
  ctx.strokeStyle='rgba(10,20,60,.8)';ctx.lineWidth=7;ctx.stroke();ctx.strokeStyle='#8fa6e8';ctx.lineWidth=4;ctx.stroke();
  const sp=mp(T.x[0],T.y[0]);ctx.fillStyle='#fff';ctx.fillRect(sp[0]-3,sp[1]-3,6,6);
  for(const r of G.racers){if(r.isPlayer)continue;const p=mp(r.x,r.y);ctx.fillStyle=r.ch.outfit;ctx.beginPath();ctx.arc(p[0],p[1],4,0,TAU);ctx.fill();ctx.strokeStyle='#fff';ctx.lineWidth=1.5;ctx.stroke();}
  const pl=G.player;if(pl){const p=mp(pl.x,pl.y);ctx.fillStyle='#ffe14a';ctx.beginPath();ctx.arc(p[0],p[1],6,0,TAU);ctx.fill();ctx.strokeStyle='#fff';ctx.lineWidth=2.5;ctx.stroke();}
  ctx.restore();
}
function txt(t,x,y,size,col,align,stroke){
  ctx.font='bold '+Math.round(size)+'px "Trebuchet MS","Segoe UI",sans-serif';ctx.textAlign=align||'left';ctx.textBaseline='alphabetic';
  if(stroke!==false){ctx.lineWidth=Math.max(3,size*.14);ctx.strokeStyle='rgba(25,35,95,.85)';ctx.lineJoin='round';ctx.strokeText(t,x,y);}
  ctx.fillStyle=col||'#fff';ctx.fillText(t,x,y);
}
function drawDriftMeter(x,y,w,hs,p){
  const h=50*hs,q=clamp(p.driftMeter/DRIFT_METER_MAX,0,1),lv=driftLevel(p),cols=['#dce9ef','#52c8ff','#ffb02e','#c27aff'],col=p.drifting?cols[lv]:'#f2c500';
  ctx.save();ctx.fillStyle='rgba(16,35,57,.78)';rr(ctx,x,y,w,h,12*hs);ctx.fill();ctx.strokeStyle=p.drifting?col:'rgba(255,255,255,.5)';ctx.lineWidth=2*hs;ctx.stroke();
  txt('DRIFT METER'+(p.driftBoostT>0?' · DRIVE '+p.driftBoostT.toFixed(1)+'S':''),x+10*hs,y+17*hs,p.driftBoostT>0?10*hs:12*hs,'#fff','left',false);txt(Math.floor(q*100)+'% · '+Math.floor(p.driftMeter)+' / '+DRIFT_METER_MAX,x+w-10*hs,y+17*hs,11*hs,col,'right',false);
  const bx=x+10*hs,by=y+25*hs,bw=w-20*hs,bh=14*hs;ctx.fillStyle='rgba(255,255,255,.15)';rr(ctx,bx,by,bw,bh,7*hs);ctx.fill();
  for(let i=0;i<10;i++){const sx=bx+i*bw/10+2*hs,sw=bw/10-4*hs;if(q>(i/10)){ctx.fillStyle=col;rr(ctx,sx,by+2*hs,sw,10*hs,4*hs);ctx.fill();}ctx.strokeStyle='rgba(255,255,255,.18)';ctx.lineWidth=1;rr(ctx,sx,by+2*hs,sw,10*hs,4*hs);ctx.stroke();}
  if(p.drifting){ctx.globalAlpha=.28+.18*Math.sin(G.t*12);ctx.fillStyle=col;rr(ctx,bx,by,bw*q,bh,7*hs);ctx.fill();}ctx.restore();
}

function drawStateBadge(x,y,hs,p){const st=p.pcState||resolveRacerState(p),cols={Base:'#dce9ef',Boost:'#f2c500',Drift:'#52c8ff',Transition:'#f58220',Jump:'#ad7cff',Wipeout:'#ff6a5a',Pickup:'#2fb77d'},w=170*hs,h=30*hs;ctx.save();ctx.fillStyle='rgba(16,35,57,.8)';rr(ctx,x,y,w,h,9*hs);ctx.fill();ctx.strokeStyle=cols[st]||'#fff';ctx.lineWidth=2*hs;ctx.stroke();txt('STATE · '+st.toUpperCase()+(st===PLAYER_STATES.JUMP?' · 75% SPEED':''),x+w/2,y+20*hs,st===PLAYER_STATES.JUMP?9.5*hs:11*hs,cols[st]||'#fff','center',false);ctx.restore();}
function drawInventorySlots(p,time,hs,centerX,bottomY){const count=itemSlotCount(p),ibs=74*hs,gap=10*hs,total=count*ibs+(count-1)*gap,x0=centerX-total/2,latest=latestItemSlot(p);for(let slot=0;slot<count;slot++){const x=x0+slot*(ibs+gap),y=bottomY-ibs,item=slotItem(p,slot),rolling=p.roll>0&&p.rollSlot===slot;ctx.fillStyle='rgba(20,30,80,.58)';rr(ctx,x,y,ibs,ibs,17*hs);ctx.fill();ctx.lineWidth=4*hs;ctx.strokeStyle=item?ITEM_DEF[item].col:rolling?'#f2c500':'rgba(255,255,255,.5)';ctx.stroke();if(rolling){const types=Object.keys(ITEM_DEF);drawItemIcon(ctx,types[Math.floor(time*14)%types.length],x+ibs/2,y+ibs/2,1.02*hs);}else if(item)drawItemIcon(ctx,item,x+ibs/2,y+ibs/2,1.07*hs);else txt('EMPTY',x+ibs/2,y+ibs/2+5*hs,11*hs,'rgba(255,255,255,.55)','center',false);txt(slot?'E':'Q',x+8*hs,y+16*hs,12*hs,slot===latest?'#ffe14a':'#fff','left',false);if(item==='tripulse')txt('×'+slotCharges(p,slot),x+ibs-7*hs,y+16*hs,11*hs,'#fff','right',false);}const name=latest>=0&&slotItem(p,latest)?ITEM_DEF[slotItem(p,latest)].name.toUpperCase():'NO PICKUP';txt('SPACE NEXT · '+name,centerX,bottomY-ibs-8*hs,12*hs,'#fff','center');}
function drawTrainingHUD(time){
  const p=G.player;if(!p)return;const hs=clamp(Math.min(W/1100,H/700),.62,1.35),m=14*hs;txt('TRAINING GROUND',m,m+32*hs,30*hs,'#f2c500','left');txt('LVA asset gallery · Drift loop · Directional ramps',m,m+56*hs,15*hs,'#fff','left');drawStateBadge(m,m+68*hs,hs,p);txt(Math.round(p.speed*4.2)+' km/h',m,H-m-22*hs,27*hs,p.boostT>0?'#ffb21a':'#fff','left');drawDriftMeter(m,H-m-92*hs,250*hs,hs,p);
  drawInventorySlots(p,time,hs,W-(itemSlotCount(p)===2?92:52)*hs-m,H-m);
  if(p.air&&p.tricks&&!p.hop){const tk=p.tricks,sz=58*hs,gap=10*hs,tw=tk.seq.length*(sz+gap)-gap,x0=W/2-tw/2,y0=H*.2;txt('TRAINING TRICK',W/2,y0-14*hs,20*hs,'#ffe14a','center');for(let i=0;i<tk.seq.length;i++)keyTile(ctx,x0+i*(sz+gap),y0,sz,tk.seq[i],i<tk.prog?'done':i===tk.prog?'next':'todo');}
  let by=H*.33;for(let i=G.banners.length-1;i>=0;i--){const b=G.banners[i],a=clamp(Math.min(b.t*6,(b.dur-b.t)*3),0,1);ctx.globalAlpha=a;txt(b.text,W/2,by,36*hs,b.col,'center');by+=42*hs;}ctx.globalAlpha=1;txt('P / ESC · pause and return to menu',W/2,H-18*hs,14*hs,'#fff','center');
}
function drawHUD(time){
  const p=G.player;if(!p)return;if(G.training){drawTrainingHUD(time);return;}
  const hs=clamp(Math.min(W/1100,H/700),.62,1.35);
  // speed lines when boosting
  if(p.boostT>0){
    ctx.save();ctx.strokeStyle='rgba(255,255,255,.22)';ctx.lineWidth=2;
    for(let i=0,n=lowDetail()?10:22;i<n;i++){const a=hash2(i,Math.floor(time*20),4)*TAU,r0=Math.min(W,H)*(.38+hash2(i,Math.floor(time*20),5)*.2),r1=r0+60+hash2(i,2,3)*120;
      ctx.beginPath();ctx.moveTo(W/2+Math.cos(a)*r0*1.5,H/2+Math.sin(a)*r0);ctx.lineTo(W/2+Math.cos(a)*r1*1.5,H/2+Math.sin(a)*r1);ctx.stroke();}
    ctx.restore();
  }
  // position
  const m=14*hs;
  txt(ord(p.rank),m,m+58*hs,64*hs,p.rank===1?'#ffe14a':'#fff','left');
  txt('/ '+G.racers.length,m+(String(ord(p.rank)).length*38+20)*hs,m+58*hs,26*hs,'#cfe2ff','left');drawStateBadge(m,m+72*hs,hs,p);
  // lap + time
  const lap=clamp(p.crossed,1,G.laps);
  txt('LAP '+(p.finished?G.laps:lap)+' / '+G.laps,W/2,m+30*hs,30*hs,'#fff','center');
  txt(fmtTime(G.raceTime),W/2,m+58*hs,22*hs,'#cfe2ff','center');txt(T.def.name,W/2,m+78*hs,13*hs,'#f2c500','center');if(T.def.plantTour)txt('AREA · '+nearestArdenArea(p).label,W/2,m+96*hs,12*hs,'#fff','center');
  // minimap
  const mw=190*hs,mh=150*hs;drawMinimap(W-mw-m,m,mw,mh);
  // standings mini list
  const arr=G.racers.slice().sort((a,b)=>a.rank-b.rank);
  ctx.save();let ly=m+mh+14*hs;
  for(const r of arr){
    ctx.fillStyle=r.isPlayer?'rgba(255,225,74,.92)':'rgba(20,30,80,.55)';rr(ctx,W-mw-m,ly,mw,20*hs,8);ctx.fill();
    ctx.fillStyle=r.ch.outfit;ctx.beginPath();ctx.arc(W-mw-m+12*hs,ly+10*hs,6*hs,0,TAU);ctx.fill();ctx.strokeStyle='#fff';ctx.lineWidth=1.5;ctx.stroke();
    ctx.font='bold '+Math.round(12*hs)+'px "Trebuchet MS",sans-serif';ctx.textAlign='left';ctx.fillStyle=r.isPlayer?'#3a2a00':'#fff';ctx.fillText(r.rank+'. '+r.name,W-mw-m+24*hs,ly+14.5*hs);
    if(r.finished){ctx.textAlign='right';ctx.fillText(fmtTime(r.finishTime),W-m-8*hs,ly+14.5*hs);}
    ly+=23*hs;
  }
  ctx.restore();
  // speedometer
  const kmh=Math.round(p.speed*4.2),mx=(30+p.stats.spd*.625)*1.38;
  const bx=m,by=H-m-70*hs,bw=250*hs;drawDriftMeter(bx,by-60*hs,bw,hs,p);
  ctx.fillStyle='rgba(20,30,80,.55)';rr(ctx,bx,by,bw,60*hs,14);ctx.fill();
  txt(String(kmh),bx+14*hs,by+44*hs,40*hs,p.boostT>0?'#ffb21a':'#fff','left');
  txt('km/h',bx+14*hs+(String(kmh).length*23+8)*hs,by+44*hs,15*hs,'#cfe2ff','left');
  ctx.fillStyle='rgba(255,255,255,.2)';rr(ctx,bx+130*hs,by+14*hs,bw-146*hs,12*hs,6);ctx.fill();
  ctx.fillStyle=p.boostT>0?'#ffb21a':'#4cd1ff';rr(ctx,bx+130*hs,by+14*hs,Math.max(6,(bw-146*hs)*clamp(p.speed/mx,0,1)),12*hs,6);ctx.fill();
    // pickup inventory · Q left, E right, Space consumes newest pickup first
  drawInventorySlots(p,time,hs,W/2,H-m);
  // trick prompt
  if(p.air&&p.tricks&&!p.hop){
    const tk=p.tricks,sz=58*hs,gap=10*hs,tw=tk.seq.length*(sz+gap)-gap,x0=W/2-tw/2,y0=H*.2;
    txt('TRICK!  press in order',W/2,y0-14*hs,20*hs,'#ffe14a','center');
    for(let i=0;i<tk.seq.length;i++)keyTile(ctx,x0+i*(sz+gap),y0+(tk.err>0&&i===tk.prog?Math.sin(time*60)*4:0),sz,tk.seq[i],i<tk.prog?'done':i===tk.prog?'next':'todo');
  }
  // banners
  let by2=H*.33;
  for(let i=G.banners.length-1;i>=0;i--){const b=G.banners[i],a=clamp(Math.min(b.t*6,(b.dur-b.t)*3),0,1);ctx.globalAlpha=a;const sc=1+Math.max(0,.4-b.t*3);txt(b.text,W/2,by2,38*hs*sc,b.col,'center');by2+=44*hs;}
  ctx.globalAlpha=1;
  // wrong way
  if(G.wrongT>1&&Math.floor(time*4)%2===0)txt('WRONG WAY!',W/2,H*.5,54*hs,'#ff5a5a','center');
  // countdown / go
  if(G.state==='countdown'){
    const n=Math.ceil(G.cd),fr=G.cd-Math.floor(G.cd);
    ctx.globalAlpha=clamp(fr*3,.2,1);txt(String(Math.min(3,n)),W/2,H*.45,150*hs*(1+fr*.35),['#fff','#ffe14a','#ff9a3a','#ff5a5a'][Math.min(3,n)]||'#fff','center');ctx.globalAlpha=1;
    if(G.cd<3)txt('Tap ↑ right before GO for a line launch',W/2,H*.66,18*hs,'#fff','center');
  }else if(G.goT>0){ctx.globalAlpha=clamp(G.goT*2,0,1);txt('GO!',W/2,H*.45,150*hs*(1+(1.2-G.goT)*.3),'#7ef0a0','center');ctx.globalAlpha=1;}
  if(p.finished&&G.state==='finishing'){txt('FINISH!',W/2,H*.4,110*hs,'#ffe14a','center');}
}

/* ===================== MENU / RESULTS (DOM) ===================== */
const elMenu=document.getElementById('menu'),elRes=document.getElementById('results'),elPause=document.getElementById('pause');
function statRow(k){
  const ch=charById(SV.char),bd=boardOf(SV.board),hat=hatOf(SV.hat),b=buildOf(),base=ch.base[k],al=b.alloc[k],gear=(bd.bonus[k]||0)+(hat?.bonus[k]||0);
  const tot=Math.min(STAT_MAX,base+al+gear),rate=k==='drf'?` <small>(${10+tot*2} pts/s)</small>`:'';
  return`<div class="stat"><div class="nm">${STAT_NAMES[k]}${rate}</div><div class="bar"><i style="width:${base*5}%"></i><u style="left:${base*5}%;width:${Math.min(al,STAT_MAX-base)*5}%"></u><em style="left:${(base+al)*5}%;width:${Math.max(0,Math.min(gear,STAT_MAX-base-al))*5}%"></em></div><div class="v">${tot}/${STAT_MAX}</div>
  <button class="b sm" data-act="dec" data-k="${k}" ${al<=0?'disabled':''}>−</button><button class="b sm" data-act="inc" data-k="${k}" ${((b.points+(SV.statBank||0))<=0||tot>=STAT_MAX)?'disabled':''}>+</button></div>`;
}
let MENU_PAGE='home';
let PROGRESS_CONFIRM_MODE='',RESET_JUST_COMPLETED=false,UNLOCK_JUST_COMPLETED=false,PROFILE_MESSAGE='',PROFILE_MESSAGE_ERROR=false,PROFILE_EXPORT_CODE='',CUSTOM_MESSAGE='';
function trackButton(t,circuit=false){const td=trackDifficulty(t),selected=SV.track===t.id;return`<button class="b circuit-track ${selected?'on':''}" data-act="track" data-id="${t.id}" aria-pressed="${selected}"><b>${t.name}</b><small><span class="track-difficulty ${DIFFS[td].n.toLowerCase()}">${DIFFS[td].n} Track</span> · ${t.desc}</small></button>`;}
function circuitPanel(c){const tracks=c.trackIds.map(id=>trackDef(id));return`<section class="circuit-card circuit-${c.theme}"><button class="b grand-prix-btn" data-act="grandPrix" data-id="${c.id}">🏆 Grand-Prix · 3-Track Championship</button><div class="circuit-head"><div><h3>${c.name}</h3><p>${c.feel}</p></div><span class="difficulty-badge">${DIFFS[c.difficulty].n} Tracks</span></div><div class="circuit-tracks">${tracks.map(t=>trackButton(t,true)).join('')}</div></section>`;}
const CUSTOM_OPEN={boards:false,caps:false};
function menuHeader(){const max=SV.level>=MAX_LEVEL,need=max?1:playerXpNeed(SV.level),subtitle=MENU_PAGE==='home'?'You could eliminate up 10 minutes of your break time by switching to Weekend Shift!':'Version: 4.6.7 Deferred Profile Gate & Drift Hotfix · Systems energized';return`<div class="console-kicker"><span class="eaton-wordmark" role="img" aria-label="Eaton"></span><span>LVA Control Console · Arden Circuit</span><span class="signal-led" aria-hidden="true"></span></div><div class="topbar"><div><h1 class="title">LOW VOLTAGE <span class="volt">ASCENDERS</span></h1><div class="sub">${subtitle}</div></div><div class="row"><span class="pill">PROFILE · ${ACTIVE_PROFILE_NAME||(GUEST_MODE?'GUEST / TESTER':'NOT LOADED')} · ${GUEST_MODE?'NO SAVE':STORAGE_MODE==='persistent'?'LOCAL SAVE':'SESSION'}</span><span class="pill"><span class="lva-badge">E★</span>${SV.wiz.toLocaleString()} E-Stars</span><span class="pill">Player Lv ${SV.level}<span class="xpbar"><div style="width:${max?100:clamp(SV.xp/need*100,0,100)}%"></div></span><small>${max?'MAX · XP→E★ 2:1':`${SV.xp}/${need} XP`}</small></span></div></div>`;}
function portraitMetrics(ch){return{sc:ch.jw?1.65:ch.rm?1.58:ch.jg?1.9:(ch.cb||ch.sb)?1.82:ch.gz?1.9:ch.xe?1.75:ch.rb?1.78:ch.pb?1.68:2.05,base:ch.jw||ch.rm?145:ch.mackey||ch.ryan?140:(ch.cb||ch.sb)?143:(ch.xe||ch.rb||ch.pb)?145:136,shadow:ch.jw||ch.rm?145:ch.mackey||ch.ryan?143:(ch.cb||ch.sb||ch.xe||ch.rb||ch.pb)?145:138};}
function menuNav(page){return`<div class="navrow"><button class="b" data-page="home">Main Menu</button>${['race','training','custom','profiles','settings','testing','credits'].map(p=>`<button class="b ${page===p?'on':''}" data-page="${p}">${p==='custom'?'Customization':p[0].toUpperCase()+p.slice(1)}</button>`).join('')}</div>`;}
function equipmentSetPanel(){const pride=prideSetActive(),holy=holySetActive();return`<div class="card set-panel"><h2>Equipment Sets</h2><div class="set-row"><div><b>Eaton Pride Set</b><small style="display:block;color:#51629a">2 pieces · item bonuses +0.1 each · full-set bonus +0.3 additive XP and E-Stars · blue PC glow + spark trail</small></div><span class="set-status ${pride?'active':'inactive'}">${pride?'ACTIVE · ×1.5 gear':'INACTIVE'}</span></div><div class="set-row"><div><b>The Holy Grail Set</b><small style="display:block;color:#51629a">2 pieces · grants Invincible-state · contact wipeouts + opponent-item immunity · golden employee, glow, and enlarged trail</small></div><span class="set-status ${holy?'active':'inactive'}">${holy?'ACTIVE · INVINCIBLE':'INACTIVE'}</span></div></div>`;}
function renderMenu(){
  const bd=boardOf(SV.board),selectedCircuit=circuitForTrack(SV.track);let h='<div class="wrap">'+menuHeader();
  if(MENU_PAGE==='home'){
    h+=`<div class="card factory-hero main-menu" style="margin:18px auto"><div class="hero-kicker">⚡ Eaton LVA · Factory Circuit Online</div><div class="hero-display"><div><div class="credit-mark">WELCOME TO THE LVA LINE</div><div class="version">Build 4.6.7 Deferred Profile Gate & Drift Hotfix · Dual-Level Controller Online</div><div class="safety-stripe"></div><p class="factory-note">Race 15 Eaton-themed LVA shop-floor tracks, develop fifteen fictional employees through individual levels, raise a separate Player Level, challenge three-race Grand Prix circuits, and carry portable PIN profiles between devices. The line is live. The state machine is watching.</p></div><div class="breaker-console" aria-hidden="true"><span class="breaker-cell"></span><span class="breaker-cell"></span><span class="breaker-cell"></span><span class="breaker-cell"></span></div></div><div class="value-strip" aria-label="LVA operating priorities"><span class="value-chip">SAFETY</span><span class="value-chip">QUALITY</span><span class="value-chip">DELIVERY</span><span class="value-chip">COST</span></div><div class="menu-grid"><button class="menu-tile" data-page="race"><span class="tile-icon">⚡</span>RACE<small>Choose a circuit, set difficulty and laps, then energize the grid</small></button><button class="menu-tile" data-page="custom"><span class="tile-icon">▦</span>CUSTOMIZATION<small>Configure fifteen fictional Eaton employees, dual progression, stats, nine boards, and ten Bump Caps</small></button><button class="menu-tile training-tile" data-page="training"><span class="tile-icon">▲</span>TRAINING<small>Free-roam the LVA asset gallery and tune the drift system</small></button><button class="menu-tile" data-page="profiles"><span class="tile-icon">▣</span>PROFILES<small>Local PIN profiles, Guest/Tester mode, and the Option C registry bridge</small></button><button class="menu-tile" data-page="settings"><span class="tile-icon">⚙</span>SETTINGS<small>Handling, graphics, audio, auto-acceleration, mobile controls, and Fork-Truck Mode</small></button><button class="menu-tile" data-page="testing"><span class="tile-icon">◈</span>TESTING<small>Open the dedicated LVA Test Bench and tune experimental handling controls</small></button><button class="menu-tile credits-tile" data-page="credits"><span class="tile-icon">E★</span>CREDITS<small>Release data, acknowledgements, and control-console status</small></button></div></div>`;
  }else if(MENU_PAGE==='race'){
    h+=menuNav('race')+`<div class="card"><div class="submenu-head"><button class="b" data-page="home">← Back</button><h2>Race</h2></div><div class="safety-stripe"></div><h2>Race Setup</h2><div class="gp-status">Game Difficulty: ${DIFFS[SV.diff].n} · Opponent skill and jump-combo length are controlled only in Settings. Track difficulty independently increases XP and E-Star rewards.</div><div class="row" style="margin-bottom:10px"><b style="width:90px">Laps</b><span class="seg row" style="gap:0">${[1,3,5].map(n=>`<button class="b ${SV.laps===n?'on':''}" data-act="laps" data-n="${n}">${n} lap${n===1?'':'s'} · ${Math.round(lapRewardMultiplier(n)*100)}%</button>`).join('')}</span></div><div class="circuit-stack">${CIRCUITS.map(circuitPanel).join('')}</div><div class="open-race"><h3>Open Race · Original Courses</h3><small>Each course now has a fixed track difficulty. Game Difficulty remains independent in Settings.</small><div class="menu-grid" style="grid-template-columns:repeat(auto-fit,minmax(150px,1fr));gap:8px;margin-top:7px">${TRACKS.filter(t=>!t.circuit).map(t=>trackButton(t)).join('')}</div></div><div class="jump-rule"><b>Lap payout:</b> 1 lap = 50% · 3 laps = 100% · 5 laps = 150%.</div><div class="jump-rule"><b>Jump boost combo:</b> ${DIFFS[SV.diff].n} requires <b>${jumpComboKeys()} key${jumpComboKeys()===1?'':'s'}</b> per ramp — Easy 2 · Medium 3 · Hard 4. Track difficulty does not change Game Difficulty.</div><div style="margin-top:10px;color:#516b78;font-size:13px">Record: ${SV.wins} win${SV.wins===1?'':'s'} in ${SV.races} race${SV.races===1?'':'s'} · Best lap ${fmtTime(SV.bestLap)} · Best race ${fmtTime(SV.bestRace)}</div><div class="cta"><button class="b go" data-act="start">START RACE</button></div></div>`;
   }else if(MENU_PAGE==='training'){
    h+=menuNav('training')+`<div class="card"><div class="submenu-head"><button class="b" data-page="home">← Back</button><h2>Training</h2></div><div class="safety-stripe"></div><p class="factory-note">Enter a double-size LVA training ground with a barrier-free test/drift loop and the complete doubled-scale v0.1 cartoon equipment set: switchgear lineups, breakers, control station, panel bank, hazard gate, and switchboard obstacle.</p><div class="training-list"><span>⚡ Random LVA pickups</span><span>▲ Practice ramps & jump combos</span><span>▣ Eight LVA equipment assets</span><span>↗ Ramps launch from low side only</span></div><div class="jump-rule"><b>No finish line.</b> Practice driving, drifting, item use, and ${jumpComboKeys()}-key ramp tricks. Pause at any time to return to the main menu.</div><div class="cta"><button class="b go" data-act="training">START TRAINING</button></div></div>`;
  }else if(MENU_PAGE==='custom'){
    h+=menuNav('custom')+`<div class="submenu-head"><button class="b" data-page="home">← Back</button><h2>Customization</h2></div><div class="grid"><div class="card"><h2>Choose your Eaton Employee</h2><div class="jump-rule"><b>Dual progression:</b> every XP reward advances both your Player Level and the selected Employee Level. Player requirements are doubled; Player level-ups add shared stat points. Employee level-ups add points for that employee.</div><div class="chars">`;
    for(const c of CUSTOM_CHARS){const ep=employeeProgressOf(c.id),emax=ep.level>=MAX_LEVEL,eneed=emax?0:employeeXpNeed(ep.level);h+=`<div class="ch ${c.id===SV.char?'sel':''}" data-act="char" data-id="${c.id}"><span class="employee-level-badge"><small>EMP</small>Lv ${ep.level}</span><canvas width="120" height="150" data-pid="${c.id}"></canvas><b>${c.name}</b><small class="role">${c.role}</small><small>Acc ${c.base.acc} · Spd ${c.base.spd} · Trn ${c.base.trn} · Drift ${c.base.drf}</small><small class="employee-xp-line">${emax?'MAX · XP converts 2:1 to E★':`${ep.xp}/${eneed} Employee XP`}</small></div>`;}
    const build=buildOf(),selectedEP=employeeProgressOf(),allocated=STAT_KEYS.reduce((n,k)=>n+build.alloc[k],0);h+=`</div></div><div style="display:flex;flex-direction:column;gap:12px"><div class="card"><h2>Stats <small style="text-transform:none;color:#51629a">· ${build.points} employee + ${SV.statBank||0} shared point${(build.points+(SV.statBank||0))===1?'':'s'} available</small></h2><div class="jump-rule"><b>${charById(SV.char).name} · Employee Level ${selectedEP.level}</b> · ${selectedEP.level>=MAX_LEVEL?'MAX LEVEL — future Employee XP converts to E-Stars at 2:1.':`${selectedEP.xp}/${employeeXpNeed(selectedEP.level)} XP to next employee point.`}<br><b>Player Level ${SV.level}</b> · ${SV.level>=MAX_LEVEL?'MAX LEVEL — future Player XP converts to E-Stars at 2:1.':`${SV.xp}/${playerXpNeed(SV.level)} XP to next shared point.`}</div>${CUSTOM_MESSAGE?`<div class="custom-status" role="status">${CUSTOM_MESSAGE}</div>`:''}${STAT_KEYS.map(k=>statRow(k)).join('')}<div class="jump-rule"><b>Drift skill:</b> determines Drift Meter points gained each second while drifting. At ${DRIFT_METER_MAX} points, the meter resets and fires an immediate Power Surge-strength boost.</div><div class="row" style="justify-content:space-between"><small style="color:#51629a">Blue = employee · gold = your points · green = board / Bump Cap bonus</small><div class="row"><button class="b go" data-act="purchaseStatPoint" ${SV.wiz<STAT_POINT_COST?'disabled':''}>Purchase Point · ${STAT_POINT_COST.toLocaleString()} E★</button><button class="b danger" data-act="resetEmployeeStats" ${allocated<=0||SV.wiz<EMPLOYEE_STAT_RESET_COST?'disabled':''}>Reset Employee Stats · ${EMPLOYEE_STAT_RESET_COST} E★</button></div></div><small style="display:block;margin-top:7px;color:#51629a">Purchased points enter the shared stat bank and can be allocated to any employee.</small><small style="display:block;margin-top:7px;color:#51629a">Refunds every allocated point for ${charById(SV.char).name} into the shared stat bank, usable on any employee. Cost is charged only when points are allocated.</small></div>${equipmentSetPanel()}<div class="card boards"><button class="b section-toggle" data-act="toggleBoards" aria-expanded="${CUSTOM_OPEN.boards}"><span>Boards</span><span>${CUSTOM_OPEN.boards?'▲':'▼'}</span></button>`;
    if(CUSTOM_OPEN.boards){h+=`<div class="gear-list"><small style="display:block;color:#51629a;margin-bottom:8px">Prices scale with stat packages. Game Difficulty alone controls jump-combo length.</small>`;for(const b of BOARDS){const own=SV.owned.includes(b.id),sel=SV.board===b.id,total=boardStatTotal(b);const bon=STAT_KEYS.filter(k=>b.bonus[k]).map(k=>'+'+b.bonus[k]+' '+STAT_NAMES[k]).join(', ')||'no stat bonus';const trait=b.reward?` · +${b.reward.toFixed(1)} additive rewards`:b.set==='holy'?' · Holy Grail piece':'';const glow=b.golden?'gear-glow-gold':b.pride?'gear-glow-blue':'';h+=`<div class="bd ${sel?'sel':''}"><div class="sw ${glow}" style="background:${b.color};color:${b.color}">${b.pride?'<span style="display:block;color:#fff;text-align:center;font-weight:900;line-height:18px">E</span>':''}</div><div class="info"><b>${b.name}</b> <small>· ${bon} · ${total} total stat point${total===1?'':'s'}${trait}<br>${b.note}</small></div>${own?(sel?'<b style="color:#075aa8">Equipped</b>':`<button class="b" data-act="equip" data-id="${b.id}">Equip</button>`):`<button class="b" data-act="buy" data-id="${b.id}" ${SV.wiz<b.cost?'disabled':''}><span class="lva-badge" style="width:18px;height:18px;font-size:8px">E★</span> ${b.cost}</button>`}</div>`;}h+=`</div>`;}
    h+=`</div><div class="card caps"><button class="b section-toggle" data-act="toggleCaps" aria-expanded="${CUSTOM_OPEN.caps}"><span>Bump Caps</span><span>${CUSTOM_OPEN.caps?'▲':'▼'}</span></button>`;
    if(CUSTOM_OPEN.caps){h+=`<div class="gear-list"><small style="display:block;color:#51629a;margin-bottom:8px">Purchase and equip one cap. +1/+2 bonuses count toward the 20-point maximum; special traits and set bonuses apply while equipped.</small>${SV.hat?'<button class="b" data-act="unequipHat" style="margin-bottom:8px">Remove equipped cap</button>':''}`;for(const cap of HATS){const own=SV.ownedHats.includes(cap.id),sel=SV.hat===cap.id;h+=`<div class="bd ${sel?'sel':''}"><div class="cap-swatch ${cap.golden?'gear-glow-gold':cap.pride?'gear-glow-blue':''}" style="background:${cap.color};color:#fff;text-align:center;font-weight:900">${cap.pride?'E':''}</div><div class="info" style="flex:1"><b>${cap.name}</b><small style="display:block;color:#51629a">${cap.note}</small></div>${own?(sel?'<b style="color:#8a6500">Equipped</b>':`<button class="b" data-act="equipHat" data-id="${cap.id}">Equip</button>`):`<button class="b" data-act="buyHat" data-id="${cap.id}" ${SV.wiz<cap.cost?'disabled':''}><span class="lva-badge" style="width:18px;height:18px;font-size:8px">E★</span> ${cap.cost}</button>`}</div>`;}h+=`</div>`;}
    h+=`</div></div></div>`;
  }else if(MENU_PAGE==='profiles'){
    const list=profileList(),opts=list.length?list.map(n=>`<option value="${n.replace(/&/g,'&amp;').replace(/"/g,'&quot;')}">${n.replace(/&/g,'&amp;').replace(/</g,'&lt;')}</option>`).join(''):'<option value="">No local profiles</option>';
    h+=menuNav('profiles')+`<div class="submenu-head"><button class="b" data-page="home">← Back</button><h2>Profiles</h2></div>${STORAGE_MODE==='session'&&!GUEST_MODE?'<div class="profile-status" role="status"><b>SESSION STORAGE MODE</b> · ArcadeLab blocks persistent browser storage inside its sandbox. Profiles work now, but you must generate a new portable save code after play and before closing or reloading.</div>':''}${PROFILE_MESSAGE?`<div class="profile-status ${PROFILE_MESSAGE_ERROR?'error':''}" role="status">${PROFILE_MESSAGE}</div>`:''}<div class="profile-grid"><div class="card"><h2>Active Profile</h2>${ACTIVE_PROFILE_NAME?`<div class="profile-name">${ACTIVE_PROFILE_NAME.replace(/&/g,'&amp;').replace(/</g,'&lt;')}</div><p class="factory-note">${STORAGE_MODE==='persistent'?'Progress auto-saves in this browser.':'Progress auto-saves for this session only. Generate a fresh code after every play session.'} The four-digit PIN is a casual lock, not cloud-grade authentication.</p><div class="row"><button class="b" data-act="exportProfile">Generate Current Save Code</button><button class="b" data-act="signOutProfile">Sign Out</button></div><textarea id="profileCodeOut" readonly placeholder="Generate a portable save code">${PROFILE_EXPORT_CODE}</textarea>`:GUEST_MODE?`<div class="profile-name">Guest / Tester</div><p class="factory-note">Fresh session-only progress is active. Nothing is written to a profile or portable save. Closing or reloading ends this run.</p><button class="b" data-act="endGuestProfile">End Guest Session</button>`:'<p class="factory-note">No profile is loaded. Create one, load an available browser profile, import a portable save code, or enter Guest/Tester mode for this play session.</p>'}</div><div class="card guest-card"><h2>Guest / Tester</h2><p class="factory-note">Start immediately with a fresh, temporary build. Ideal for a quick test drive; progress is intentionally not saved.</p><button class="b" data-act="guestProfile">${GUEST_MODE?'Restart Fresh Guest Session':'Play as Guest / Tester'}</button></div><div class="card"><h2>Create Profile</h2><label>Name<input id="profileCreateName" maxlength="20" autocomplete="off" placeholder="DB_Racer01"></label><label>4-digit PIN<input id="profileCreatePin" maxlength="4" inputmode="numeric" type="password" placeholder="••••"></label><button class="b" data-act="createProfile">Create & Load</button><small style="display:block;margin-top:8px;color:#516b78">The first profile inherits existing progress when persistent browser storage is available. In ArcadeLab session mode, export a save code before leaving.</small></div><div class="card"><h2>Load Available Profile</h2><label>Profile<select id="profileLoginName">${opts}</select></label><label>4-digit PIN<input id="profileLoginPin" maxlength="4" inputmode="numeric" type="password" placeholder="••••"></label><button class="b" data-act="loginProfile" ${list.length?'':'disabled'}>Load Profile</button></div><div class="card"><h2>Import Portable Profile</h2><textarea id="profileCodeIn" placeholder="Paste an LVA3 portable save code"></textarea><label>Profile PIN<input id="profileImportPin" maxlength="4" inputmode="numeric" type="password" placeholder="••••"></label><button class="b" data-act="importProfile">Import & Load</button><small style="display:block;margin-top:8px;color:#516b78">Cross-device transfer is manual and ArcadeLab-safe. No network call is made.</small></div><div class="card"><h2>Option C · Online Registry Bridge</h2><p class="factory-note">ArcadeLab blocks network calls, so the external LVA Profile Registry acts as the online checkpoint while this game remains offline-safe.</p><div class="jump-rule"><b>Push:</b> Generate the current code here, sign in to the registry webpage, and save it as a new text-database revision.<br><b>Pull:</b> Sign in to the registry on any device, copy the generated LVA3 code, then import it here with the same PIN.</div><small style="display:block;margin-top:8px;color:#516b78">Your registry administrator supplies the webpage URL after deployment. No URL or creator code is embedded in this release.</small></div></div>`;
  }else if(MENU_PAGE==='settings'){
    h+=menuNav('settings')+`<div class="submenu-head"><button class="b" data-page="home">← Back</button><h2>Settings</h2></div><div class="card game-difficulty-card"><h2>Game Difficulty</h2><div class="row"><div><b>Opponent skill + jump boost combo</b><p class="factory-note">Easy = 2 keys · Medium = 3 keys · Hard = 4 keys. This setting never changes a track's own difficulty.</p></div><span class="seg row" style="gap:0">${DIFFS.map((d,i)=>`<button class="b ${SV.diff===i?'on':''}" data-act="gameDiff" data-i="${i}">${d.n}</button>`).join('')}</span></div></div>`;
    h+=`<div class="settings-grid"><div class="card help"><h2>Controls</h2><p><kbd>←</kbd><kbd>→</kbd> steer · <kbd>↑</kbd> accelerate · <kbd>↓</kbd> brake</p><p><kbd>Shift</kbd> or <kbd>Z</kbd> hold while turning to drift. The new default uses hop-entry, locked drift direction, counter-steer sparks, and release mini-turbos. Enable Classic Drift to restore the former progressive steering and launch-window handling.</p><p>Exit a drift to enter Transition-state for ${TRANSITION_SECONDS} seconds. Start the opposite drift during that window to trigger <b>Bunny-Hop Drift!</b>. Its 20% boost lasts ${bunnyHopSeconds().toFixed(2)} seconds, controlled in Testing.</p><p><kbd>Q</kbd> left pickup · <kbd>E</kbd> right pickup · <kbd>Space</kbd> newest pickup first · <kbd>A</kbd><kbd>S</kbd><kbd>D</kbd><kbd>F</kbd> jump combo · <kbd>P</kbd>/<kbd>Esc</kbd> pause · <kbd>M</kbd> mute</p></div><div class="card"><h2>Handling, Graphics & Audio</h2><label class="setting-line"><b>Graphics</b><select data-setting="quality"><option value="performance" ${SMOOTH.quality==='performance'?'selected':''}>Performance Saver · 1×</option><option value="balanced" ${SMOOTH.quality==='balanced'?'selected':''}>Balanced · 1.25×</option><option value="high" ${SMOOTH.quality==='high'?'selected':''}>High · up to 2×</option></select></label><small style="display:block;color:#51629a;margin:-4px 0 8px">Balanced automatically enables detail saving after sustained frame pressure, especially at high speed. Gameplay physics remain at 60 Hz.</small><label class="setting-line"><b>Stable camera</b><span class="toggle-switch"><input type="checkbox" data-setting="camera" aria-label="Stable camera" ${SMOOTH.camera?'checked':''}><i></i></span></label><label class="setting-line"><b>Impact screen shake</b><span class="toggle-switch"><input type="checkbox" data-setting="shake" aria-label="Impact screen shake" ${SMOOTH.shake?'checked':''}><i></i></span></label><label class="setting-line"><b>Show frame rate</b><span class="toggle-switch"><input type="checkbox" data-setting="showFPS" aria-label="Show frame rate" ${SMOOTH.showFPS?'checked':''}><i></i></span></label><label class="setting-line"><b>Audio</b><span class="toggle-switch"><input type="checkbox" data-setting="audio" aria-label="Audio" ${audioOn?'checked':''}><i></i></span></label><label class="setting-line"><span><b>Auto-acceleration</b><small style="display:block;color:#51629a">Mobile default: ON. Hold ↓ to suspend acceleration and brake; release to resume. Desktop default: OFF.</small></span><span class="toggle-switch"><input type="checkbox" data-setting="auto" aria-label="Auto-acceleration" ${SV.auto?'checked':''}><i></i></span></label><label class="setting-line"><span><b>Classic Drift</b><small style="display:block;color:#51629a">Replace the new default drift with the former progressive steering, launch window, and no counter-steer spark requirement.</small></span><span class="toggle-switch"><input type="checkbox" data-setting="classicDrift" aria-label="Classic Drift" ${SV.classicDrift?'checked':''}><i></i></span></label><label class="setting-line"><span><b>Mobile Controls Test</b><small style="display:block;color:#51629a">Show the touch D-pad and Drift console on desktop.</small></span><span class="toggle-switch"><input type="checkbox" data-setting="mobileControlsTest" aria-label="Mobile Controls Test" ${SV.mobileControlsTest?'checked':''}><i></i></span></label><label class="setting-line"><span><b>Fork-Truck Mode</b><small style="display:block;color:#51629a">Replace hoverboards with fork-trucks</small></span><span class="toggle-switch"><input type="checkbox" data-setting="fork" aria-label="Fork-Truck Mode" ${SV.fork?'checked':''}><i></i></span></label></div><div class="card" style="grid-column:1/-1"><h2>Player State Controller</h2><p class="factory-note">Primary state priority: Invincible → Wipeout → Jump → Boost → Drift → Transition → Pickup → Base.</p><div class="state-key"><span>BASE · stats only</span><span>BOOST · any boost</span><span>DRIFT · drift held</span><span>TRANSITION · ${TRANSITION_SECONDS}-second chain window</span><span>JUMP · combo + 75% speed</span><span>WIPEOUT · spinout</span><span>PICKUP · item held</span><span>INVINCIBLE · contact wipeout + opponent-item immunity</span></div></div><div class="card" style="grid-column:1/-1"><h2>LVA Pickups</h2><div class="row" style="justify-content:space-around">${Object.keys(ITEM_DEF).map(k=>`<span class="pill" style="border:2px solid ${ITEM_DEF[k].col}">${ITEM_DEF[k].name}</span>`).join('')}</div></div><div class="card reset-zone unlock-zone" style="grid-column:1/-1"><h2>Progress Controls</h2><p><b>Unlock Everything</b> unlocks every board and Bump Cap, sets all fifteen employees and the Player Level to 30, maximizes every employee’s base-allocation stats, and fills the test bank to ${MAX_ESTAR_BANK.toLocaleString()} E-Stars.</p>${UNLOCK_JUST_COMPLETED?'<div class="lvl" role="status">Everything unlocked. Test profile maxed.</div>':''}<button class="b go" data-act="askUnlock">Unlock Everything</button><hr style="margin:14px 0;border:0;border-top:2px solid #b9c8ce"><h2>Reset Progress</h2><p>Restore the fresh-start profile, including Level 1, 0 XP, 0 E-Stars, and only the starter board.</p>${RESET_JUST_COMPLETED?'<div class="lvl" role="status">Progress reset. Fresh-start values restored.</div>':''}<button class="b danger" data-act="askReset">Reset Progress</button></div></div>`;
    h+=PROGRESS_CONFIRM_MODE?`<div class="reset-confirm" role="dialog" aria-modal="true" aria-labelledby="progressPrompt"><div class="card"><h2>${PROGRESS_CONFIRM_MODE==='unlock'?'Unlock Everything':'Reset Progress'}</h2><p id="progressPrompt">${PROGRESS_CONFIRM_MODE==='unlock'?'Are you sure you want to unlock every item and maximize the E-Star bank, Player Level, all Employee Levels, and all employee stats?':'Are you sure you want to reset all of your progress (Level, XP, E-Star points and items purchased)?'}</p><div class="row"><button class="b danger" data-act="${PROGRESS_CONFIRM_MODE==='unlock'?'confirmUnlock':'confirmReset'}">Yes, I am sure.</button><button class="b" data-act="cancelProgress">No, keep my progress.</button></div></div></div>`:'';
  }else if(MENU_PAGE==='testing'){
    h+=menuNav('testing')+`<div class="submenu-head"><button class="b" data-page="home">← Back</button><h2>Testing</h2></div><div class="card"><div class="hero-kicker">◈ LVA TEST BENCH · ADVANCED SETTINGS</div><h2>Experimental Handling Controls</h2><p class="factory-note">Tune prototype behavior here without crowding production settings. Changes save with the active profile.</p><div class="range-line"><div><b>Initial Drift Angle</b><small style="display:block;color:#516b78">Controls the immediate heading angle when Drift-state begins. New profiles default to 22°.</small></div><input type="range" min="1" max="90" step="1" value="${SV.initialDriftAngle}" data-setting="initialDriftAngle" aria-label="Initial Drift Angle"><span class="range-value">${initialDriftAngleDeg().toFixed(0)}°</span></div><div class="jump-rule">Range: 1°–90°. Twenty-two degrees is the tuned default. Higher values are intentionally aggressive. The handling boss will not negotiate.</div><hr style="margin:16px 0;border:0;border-top:2px solid #b9c8ce"><div class="range-line"><div><b>Bunny-hop Timer</b><small style="display:block;color:#516b78">Sets the duration of the 20% Bunny-Hop forward-speed boost. 100% = 1.00 second; 0% = 0.00 seconds.</small></div><input type="range" min="0" max="100" step="1" value="${bunnyHopPercent()}" data-setting="bunnyHopTimer" aria-label="Bunny-hop Timer"><span class="range-value">${bunnyHopPercent()}% · ${bunnyHopSeconds().toFixed(2)} s</span></div><div class="jump-rule">Range: 0%–100%. The default is 15% (0.15 seconds). The 0.3-second Transition-state window is fixed; this slider changes only the chained boost duration.</div></div>`;
  }else{
    h+=menuNav('credits')+`<div class="card" style="max-width:720px;margin:0 auto;text-align:center"><div class="submenu-head"><button class="b" data-page="home">← Back</button><h2>Credits</h2></div><div class="credit-mark">LOW VOLTAGE ASCENDERS</div><div class="version">Version: 4.6.7 Deferred Profile Gate & Drift Hotfix</div><div class="safety-stripe"></div><p class="factory-note">Developed and published by dirdygame Studios</p><p class="factory-note">All employee characters, appearances, roles, accessories, family props, and performance stats are fictional game art—not assessments or claims about real employees. Safety, quality, delivery, cost, and people remain the real priorities.</p></div><div class="card patch-notes" style="max-width:720px;margin:12px auto 0"><h2>Latest Patch Notes · 4.6.7</h2><ul><li>Set the default Initial Drift Angle to 22°.</li><li>Deferred the Guest / Profile checkpoint until a player selects Race, Grand Prix, or Training without an active session.</li><li>Play as Guest / Tester remains the default checkpoint action and immediately continues the selected activity.</li><li>Preserved all employees, roles, stats, equipment, tracks, progression, environmental scaling, Bunny-hop timing, and controls.</li></ul></div>`;
  }
  if(PROFILE_GATE_PROMPT)h+=`<div class="reset-confirm startup-profile-prompt" role="dialog" aria-modal="true" aria-labelledby="profileGateTitle" aria-describedby="profileGateText"><div class="card"><div class="hero-kicker">▣ PROFILE CHECKPOINT</div><h2 id="profileGateTitle">Profile Choice Required</h2><p id="profileGateText">This activity needs an active Profile or Guest / Tester session. Guest / Tester is selected by default and will continue directly to the activity you chose. Guest progress is temporary and disappears when the game is closed or reloaded.</p><div class="recommendation">Recommended: create, load, or import a profile to save progression and generate portable save codes.</div><div class="startup-choice"><button class="b go startup-default" data-act="continueGuest" aria-pressed="true" autofocus>Play as Guest / Tester<small>Default · continue without saved progress</small></button><button class="b" data-act="startupProfiles">Create / Load Profile<small>Recommended · saves progression</small></button></div></div></div>`;
  h+='</div>';elMenu.innerHTML=h;
  elMenu.querySelectorAll('canvas[data-pid]').forEach(cn=>{const c=cn.getContext('2d'),ch=charById(+cn.dataset.pid),pm=portraitMetrics(ch),sc=pm.sc,base=pm.base,shadow=pm.shadow;c.clearRect(0,0,120,150);c.fillStyle=boardOf(SV.board).color;c.globalAlpha=.35;c.beginPath();c.ellipse(60,shadow,40,8,0,0,TAU);c.fill();c.globalAlpha=1;c.save();if(prideSetActive()||holySetActive()){c.shadowColor=holySetActive()?'#ffd84d':'#1686ff';c.shadowBlur=18;}const opts={front:true,fx:0,t:1,hatId:SV.hat};if(holySetActive())drawGoldenRider(c,60,base,sc,ch,opts);else drawRider(c,60,base,sc,ch,opts);c.restore();});
  if(PROFILE_GATE_PROMPT)elMenu.querySelector('[data-act="continueGuest"]')?.focus();
}
function runProfileRequiredAction(action,id=''){if(action==='grandPrix'){startGrandPrix(id);return;}if(action==='race'){GRAND_PRIX=null;persist();startRace();return;}if(action==='training'){persist();startTraining();}}
function requestProfileRequiredAction(action,id=''){if(!ACTIVE_PROFILE_NAME&&!GUEST_MODE){PENDING_PROFILE_ACTION={action,id};PROFILE_GATE_PROMPT=true;PROFILE_MESSAGE='Choose Guest / Tester or create/load a profile to continue.';PROFILE_MESSAGE_ERROR=false;renderMenu();return false;}runProfileRequiredAction(action,id);return true;}
elMenu.addEventListener('click',e=>{
  const pg=e.target.closest('[data-page]');if(pg){MENU_PAGE=pg.dataset.page;renderMenu();return;}
  const t=e.target.closest('[data-act]');if(!t)return;const a=t.dataset.act;
  if(a==='continueGuest'){const pending=PENDING_PROFILE_ACTION;PROFILE_GATE_PROMPT=false;PENDING_PROFILE_ACTION=null;persist();ACTIVE_PROFILE_NAME=null;STORAGE.removeItem(PROFILE_ACTIVE_KEY);GUEST_MODE=true;SV=defSave();PROFILE_EXPORT_CODE='';PROFILE_MESSAGE='Guest / Tester session active. Progress will not be saved.';PROFILE_MESSAGE_ERROR=false;buildTrack(SV.track);buildFeatures();if(pending){runProfileRequiredAction(pending.action,pending.id);return;}MENU_PAGE='home';renderMenu();return;}
  if(a==='startupProfiles'){PROFILE_GATE_PROMPT=false;PENDING_PROFILE_ACTION=null;PROFILE_MESSAGE='Profiles are recommended so progression can be saved and exported.';PROFILE_MESSAGE_ERROR=false;MENU_PAGE='profiles';renderMenu();return;}
  if(a==='gameDiff'){SV.diff=clamp(+t.dataset.i,0,2);persist();renderMenu();return;}
  if(a==='grandPrix'){requestProfileRequiredAction('grandPrix',t.dataset.id);return;}
  if(a==='guestProfile'){persist();ACTIVE_PROFILE_NAME=null;STORAGE.removeItem(PROFILE_ACTIVE_KEY);GUEST_MODE=true;SV=defSave();PROFILE_EXPORT_CODE='';PROFILE_MESSAGE='Guest / Tester session started. Progress will not be saved.';PROFILE_MESSAGE_ERROR=false;MENU_PAGE='home';buildTrack(SV.track);buildFeatures();renderMenu();return;}
  if(a==='endGuestProfile'){GUEST_MODE=false;SV=defSave();PROFILE_MESSAGE='Guest session ended. Create, load, import, or start another temporary session.';PROFILE_MESSAGE_ERROR=false;MENU_PAGE='profiles';renderMenu();return;}
  if(a==='createProfile'){const r=createProfile(document.getElementById('profileCreateName')?.value||'',document.getElementById('profileCreatePin')?.value||'');PROFILE_MESSAGE=r.msg;PROFILE_MESSAGE_ERROR=!r.ok;if(r.ok)PROFILE_EXPORT_CODE=encodeProfileCode();renderMenu();return;}
  if(a==='loginProfile'){const r=activateProfile(document.getElementById('profileLoginName')?.value||'',document.getElementById('profileLoginPin')?.value||'');PROFILE_MESSAGE=r.msg;PROFILE_MESSAGE_ERROR=!r.ok;if(r.ok){PROFILE_EXPORT_CODE='';buildTrack(SV.track);buildFeatures();}renderMenu();return;}
  if(a==='signOutProfile'){signOutProfile();PROFILE_MESSAGE='Profile signed out. Load a profile to continue progression.';PROFILE_MESSAGE_ERROR=false;PROFILE_EXPORT_CODE='';MENU_PAGE='profiles';renderMenu();return;}
  if(a==='exportProfile'){PROFILE_EXPORT_CODE=encodeProfileCode();PROFILE_MESSAGE=PROFILE_EXPORT_CODE?'Portable save code generated. Copy it into the Option C registry or directly into the other device.':'Load a profile before exporting.';PROFILE_MESSAGE_ERROR=!PROFILE_EXPORT_CODE;renderMenu();document.getElementById('profileCodeOut')?.select();return;}
  if(a==='importProfile'){const r=importProfileCode(document.getElementById('profileCodeIn')?.value||'',document.getElementById('profileImportPin')?.value||'');PROFILE_MESSAGE=r.msg;PROFILE_MESSAGE_ERROR=!r.ok;if(r.ok){PROFILE_EXPORT_CODE=encodeProfileCode();buildTrack(SV.track);buildFeatures();}renderMenu();return;}
  if(a==='askUnlock'){RESET_JUST_COMPLETED=false;UNLOCK_JUST_COMPLETED=false;PROGRESS_CONFIRM_MODE='unlock';renderMenu();elMenu.querySelector('[data-act="confirmUnlock"]')?.focus();return;}
  if(a==='askReset'){RESET_JUST_COMPLETED=false;UNLOCK_JUST_COMPLETED=false;PROGRESS_CONFIRM_MODE='reset';renderMenu();elMenu.querySelector('[data-act="confirmReset"]')?.focus();return;}
  if(a==='cancelProgress'){PROGRESS_CONFIRM_MODE='';renderMenu();return;}
  if(a==='confirmUnlock'){unlockEverything();PROGRESS_CONFIRM_MODE='';UNLOCK_JUST_COMPLETED=true;RESET_JUST_COMPLETED=false;renderMenu();elMenu.querySelector('[data-act="askUnlock"]')?.focus();return;}
  if(a==='confirmReset'){SV=defSave();persist();PROGRESS_CONFIRM_MODE='';RESET_JUST_COMPLETED=true;UNLOCK_JUST_COMPLETED=false;CUSTOM_OPEN.boards=false;CUSTOM_OPEN.caps=false;CUSTOM_MESSAGE='';renderMenu();elMenu.querySelector('[data-act="askReset"]')?.focus();return;}
  if(a==='toggleBoards'){CUSTOM_OPEN.boards=!CUSTOM_OPEN.boards;renderMenu();return;}
  if(a==='toggleCaps'){CUSTOM_OPEN.caps=!CUSTOM_OPEN.caps;renderMenu();return;}
  if(a==='char'){SV.char=+t.dataset.id;buildOf();}
  else if(a==='inc'){const k=t.dataset.k,b=buildOf();if((b.points+(SV.statBank||0))>0){b.alloc[k]++;if((SV.statBank||0)>0){SV.statBank--;b.sharedAlloc[k]++;}else b.points--;}}
  else if(a==='dec'){const k=t.dataset.k,b=buildOf();if(b.alloc[k]>0){b.alloc[k]--;if((b.sharedAlloc[k]||0)>0){b.sharedAlloc[k]--;SV.statBank=(SV.statBank||0)+1;}else b.points++;}}
  else if(a==='purchaseStatPoint'){const r=purchaseStatPoint();CUSTOM_MESSAGE=r.msg;}
   else if(a==='resetEmployeeStats'){const b=buildOf(),spent=STAT_KEYS.reduce((n,k)=>n+b.alloc[k],0);if(spent>0&&SV.wiz>=EMPLOYEE_STAT_RESET_COST){SV.wiz-=EMPLOYEE_STAT_RESET_COST;SV.statBank=(SV.statBank||0)+spent;for(const k of STAT_KEYS){b.alloc[k]=0;b.sharedAlloc[k]=0;}CUSTOM_MESSAGE=`${charById(SV.char).name} moved ${spent} stat point${spent===1?'':'s'} into the shared bank for ${EMPLOYEE_STAT_RESET_COST} E-Stars.`;}else CUSTOM_MESSAGE=spent<=0?'No allocated stat points to refund.':'Insufficient E-Stars for the stat reset.';}
  else if(a==='equip'){SV.board=t.dataset.id;}
  else if(a==='buy'){const b=boardOf(t.dataset.id);if(SV.wiz>=b.cost&&!SV.owned.includes(b.id)){SV.wiz-=b.cost;SV.owned.push(b.id);SV.board=b.id;}}
  else if(a==='equipHat'){if(SV.ownedHats.includes(t.dataset.id))SV.hat=t.dataset.id;}
  else if(a==='unequipHat'){SV.hat=null;}
  else if(a==='buyHat'){const cap=hatOf(t.dataset.id);if(cap&&SV.wiz>=cap.cost&&!SV.ownedHats.includes(cap.id)){SV.wiz-=cap.cost;SV.ownedHats.push(cap.id);SV.hat=cap.id;}}
  else if(a==='laps')SV.laps=+t.dataset.n;
   else if(a==='track'){SV.track=t.dataset.id;}
  else if(a==='start'){requestProfileRequiredAction('race');return;}
   else if(a==='training'){requestProfileRequiredAction('training');return;}
  persist();renderMenu();
});
elMenu.addEventListener('change',e=>{
  const k=e.target.dataset.setting;if(!k)return;
  if(k==='auto'){SV.auto=e.target.checked;SV.autoMobileDefault461Applied=true;persist();renderMenu();}
   else if(k==='classicDrift'){SV.classicDrift=e.target.checked;persist();renderMenu();}
   else if(k==='initialDriftAngle'){SV.initialDriftAngle=clamp(+e.target.value,1,90);persist();renderMenu();}
    else if(k==='bunnyHopTimer'){SV.bunnyHopTimer=clamp(Math.round(+e.target.value),0,100);persist();renderMenu();}
   else if(k==='mobileControlsTest'){SV.mobileControlsTest=e.target.checked;persist();syncTouchControls();renderMenu();}
   else if(k==='fork'){SV.fork=e.target.checked;persist();}
   else if(k==='quality'){SMOOTH.quality=e.target.value;PERF.low=SMOOTH.quality==='performance';PERF.slowT=PERF.fastT=0;document.getElementById('smoothQuality').value=SMOOTH.quality;resize();}
  else if(k==='audio')audioOn=e.target.checked;
  else{SMOOTH[k]=e.target.checked;const ids={camera:'smoothCamera',shake:'smoothShake',showFPS:'smoothFPS'};if(ids[k])document.getElementById(ids[k]).checked=SMOOTH[k];SMOOTH.resetCamera=true;}
});
function showMenu(page='home'){G.training=false;G.state='menu';syncTouchControls();MENU_PAGE=page;PROGRESS_CONFIRM_MODE='';RESET_JUST_COMPLETED=false;UNLOCK_JUST_COMPLETED=false;stopEngine();elRes.classList.remove('show');elPause.classList.remove('show');renderMenu();elMenu.classList.add('show');if(PROFILE_GATE_PROMPT)requestAnimationFrame(()=>elMenu.querySelector('[data-act="continueGuest"]')?.focus());}

function rankReward(rank,perfects=0){
  const lapsK=lapRewardMultiplier(G.laps),m=raceRewardMultiplier();
  return{xp:Math.round([140,105,85,65,50,40][rank-1]*lapsK*m),wiz:Math.round(([320,240,190,150,120,90][rank-1]+perfects*15)*lapsK*m)};
}
function grantProgressTrack(level,currentXp,rewardXp,needFn){let remaining=Math.max(0,Math.round(rewardXp||0)),ups=0,converted=0;level=clamp(Math.floor(+level||1),1,MAX_LEVEL);currentXp=level>=MAX_LEVEL?0:Math.max(0,Math.floor(+currentXp||0));while(remaining>0&&level<MAX_LEVEL){const need=needFn(level),room=Math.max(1,need-currentXp);if(remaining<room){currentXp+=remaining;remaining=0;}else{remaining-=room;currentXp=0;level++;ups++;}}if(level>=MAX_LEVEL&&remaining>0)converted=Math.floor(remaining/2);return{level,xp:level>=MAX_LEVEL?0:currentXp,ups,converted};}
function addPlayerRewards(xp,wiz){const p=grantProgressTrack(SV.level,SV.xp,xp,playerXpNeed);SV.level=p.level;SV.xp=p.xp;SV.statBank=(SV.statBank||0)+p.ups;const ep=employeeProgressOf(),e=grantProgressTrack(ep.level,ep.xp,xp,employeeXpNeed);ep.level=e.level;ep.xp=e.xp;buildOf().points+=e.ups;const converted=p.converted+e.converted,totalWiz=wiz+converted;SV.wiz+=totalWiz;return{playerUps:p.ups,employeeUps:e.ups,playerConverted:p.converted,employeeConverted:e.converted,converted,baseWiz:wiz,totalWiz};}
function sortedGrandPrixStandings(){return GRAND_PRIX.racerIds.slice().sort((a,b)=>GRAND_PRIX.points[b]-GRAND_PRIX.points[a]||(GRAND_PRIX.lastRanks[a]||9)-(GRAND_PRIX.lastRanks[b]||9)||a-b);}
function drawPodiumEmployees(){elRes.querySelectorAll('canvas[data-podium-id]').forEach(cn=>{const c=cn.getContext('2d'),ch=charById(+cn.dataset.podiumId),pm=portraitMetrics(ch),sc=pm.sc,base=pm.base;c.clearRect(0,0,120,150);drawRider(c,60,base,sc,ch,{front:true,fx:0,t:1,hatId:null});});}
function showGrandPrixPodium(playerAward){
  const gp=GRAND_PRIX,stand=sortedGrandPrixStandings(),top=stand.slice(0,3),firstBase=gp.rewards[top[0]],firstBonus={xp:Math.round(firstBase.xp*.25),wiz:Math.round(firstBase.wiz*.25)},bonuses=[firstBonus,{xp:Math.round(firstBonus.xp*.5),wiz:Math.round(firstBonus.wiz*.5)},{xp:Math.round(firstBonus.xp*.25),wiz:Math.round(firstBonus.wiz*.25)}];
  const playerPlace=stand.indexOf(SV.char)+1,podiumIndex=top.indexOf(SV.char);let bonusAward={playerUps:0,employeeUps:0,converted:0,totalWiz:0};if(podiumIndex>=0)bonusAward=addPlayerRewards(bonuses[podiumIndex].xp,bonuses[podiumIndex].wiz);persist();
  const slot=(place)=>{const id=top[place-1],r=gp.rewards[id],b=bonuses[place-1],total={xp:r.xp+b.xp,wiz:r.wiz+b.wiz};return`<div class="podium-slot place-${place}"><div class="podium-reward">TOTAL · ${total.xp} XP<br>${total.wiz} E★</div><canvas width="120" height="150" data-podium-id="${id}"></canvas><div class="podium-name">${charById(id).name}<br><small>${gp.points[id]} points</small></div><div class="podium-block">${place}</div></div>`;};
  const profile=(ACTIVE_PROFILE_NAME||charById(SV.char).name).replace(/&/g,'&amp;').replace(/</g,'&lt;');
  elRes.innerHTML=`<div class="wrap podium-card"><div class="card" style="text-align:center"><div class="big podium-headline">Congratulations ${profile}, you placed ${ord(playerPlace)}!</div><div class="sub" style="color:#51629a;text-shadow:none">${circuitForTrack(gp.trackIds[0]).name} · Grand-Prix complete</div><div class="podium-stage">${slot(2)}${slot(1)}${slot(3)}</div><div class="podium-note">Podium bonuses · 1st: 25% of first-place base rewards · 2nd: 50% of first bonus · 3rd: 25% of first bonus</div>${podiumIndex>=0?`<div class="lvl">Your podium bonus: +${bonuses[podiumIndex].xp} XP to Player and ${charById(SV.char).name} · +${bonusAward.totalWiz} E★${bonusAward.converted?` (${bonusAward.converted} from max-level XP)`:''}</div>`:'<div class="gp-status">No podium bonus this run. The circuit remembers.</div>'}${playerAward.playerUps+bonusAward.playerUps?`<div class="lvl">PLAYER LEVEL UP! Player Level ${SV.level} · +${playerAward.playerUps+bonusAward.playerUps} shared stat point${playerAward.playerUps+bonusAward.playerUps===1?'':'s'}</div>`:''}${playerAward.employeeUps+bonusAward.employeeUps?`<div class="lvl">EMPLOYEE LEVEL UP! ${charById(SV.char).name} reached Employee Level ${employeeProgressOf().level} · +${playerAward.employeeUps+bonusAward.employeeUps} employee stat point${playerAward.employeeUps+bonusAward.employeeUps===1?'':'s'}</div>`:''}<button class="b go" style="font-size:18px;padding:9px 25px" data-act="gpDone">Continue</button></div></div>`;
  elRes.classList.add('show');G.state='results';syncTouchControls();stopEngine();drawPodiumEmployees();
}
function showResults(){
  const arr=computeRanks(),me=G.player,rank=me.rank,reward=rankReward(rank,G.perfects),xp=reward.xp,wiz=reward.wiz,award=addPlayerRewards(xp,wiz);
  SV.races++;if(rank===1)SV.wins++;const bl=me.lapTimes.length?Math.min(...me.lapTimes):null;if(bl!=null&&(SV.bestLap==null||bl<SV.bestLap))SV.bestLap=bl;if(me.finished&&G.laps===3&&(SV.bestRace==null||me.finishTime<SV.bestRace))SV.bestRace=me.finishTime;
  if(GRAND_PRIX){const n=G.racers.length;arr.forEach((r,i)=>{const id=r.ch.id,rr=rankReward(i+1,r.isPlayer?G.perfects:0);GRAND_PRIX.points[id]+=n-i;GRAND_PRIX.rewards[id].xp+=rr.xp;GRAND_PRIX.rewards[id].wiz+=rr.wiz+(id===SV.char?award.converted:0);GRAND_PRIX.lastRanks[id]=i+1;});GRAND_PRIX.raceIndex++;persist();if(GRAND_PRIX.raceIndex>=GRAND_PRIX.trackIds.length){showGrandPrixPodium(award);return;}}
  persist();let h=`<div class="wrap" style="max-width:700px"><div class="card" style="text-align:center"><div class="big">${ord(rank)} PLACE</div><div class="sub" style="color:#51629a;text-shadow:none">${rank===1?'Victory!':rank<=3?'On the podium!':'Keep assembling speed — try drifting and jump combos!'}</div><table class="res"><tr><th>#</th><th>Racer</th><th>Time</th></tr>`;arr.forEach((r,i)=>{h+=`<tr class="${r.isPlayer?'me':''}"><td>${i+1}</td><td>${r.isPlayer?'You ('+r.ch.name+')':r.name}</td><td>${r.finished?fmtTime(r.finishTime):'DNF'}</td></tr>`;});h+=`</table><div class="rew"><span class="pill"><span class="lva-badge">E★</span>+${award.totalWiz} E-Stars</span><span class="pill">+${xp} Player XP</span><span class="pill">+${xp} ${charById(SV.char).name} XP</span>${award.converted?`<span class="pill">Max-level conversion +${award.converted} E★</span>`:``}<span class="pill">Difficulty + gear ×${raceRewardMultiplier().toFixed(1)}</span><span class="pill">Laps ×${lapRewardMultiplier(G.laps).toFixed(1)}</span><span class="pill">Final payout ×${(raceRewardMultiplier()*lapRewardMultiplier(G.laps)).toFixed(2)}</span>${G.perfects?`<span class="pill">${G.perfects} perfect trick${G.perfects>1?'s':''}</span>`:''}${bl!=null?`<span class="pill">Best lap ${fmtTime(bl)}</span>`:''}</div>`;
  if(award.playerUps)h+=`<div class="lvl">PLAYER LEVEL UP! Player Level ${SV.level} · +${award.playerUps} shared stat point${award.playerUps===1?'':'s'}</div>`;if(award.employeeUps)h+=`<div class="lvl">EMPLOYEE LEVEL UP! ${charById(SV.char).name} reached Employee Level ${employeeProgressOf().level} · +${award.employeeUps} employee stat point${award.employeeUps===1?'':'s'}</div>`;
  if(GRAND_PRIX){const standings=sortedGrandPrixStandings();h+=`<div class="gp-status">Grand-Prix Race ${GRAND_PRIX.raceIndex} of 3 complete · points: 1st = ${G.racers.length}, then descending to 1</div><table class="res gp-standings"><tr><th>Standing</th><th>Employee</th><th>Points</th></tr>${standings.map((id,i)=>`<tr class="${id===SV.char?'me':''}"><td>${ord(i+1)}</td><td>${charById(id).name}</td><td>${GRAND_PRIX.points[id]}</td></tr>`).join('')}</table><button class="b go" style="font-size:18px;padding:8px 22px;margin-top:10px" data-act="gpContinue">Continue to ${trackDef(GRAND_PRIX.trackIds[GRAND_PRIX.raceIndex]).name}</button>`;}
  else h+=`<div class="row" style="justify-content:center;margin-top:6px"><button class="b go" style="font-size:18px;padding:8px 22px" data-act="again">Race again</button><button class="b" data-act="garage" style="padding:10px 16px">Main Menu</button></div>`;
  h+=`</div></div>`;elRes.innerHTML=h;elRes.classList.add('show');G.state='results';syncTouchControls();stopEngine();
}
elRes.addEventListener('click',e=>{const t=e.target.closest('[data-act]');if(!t)return;const a=t.dataset.act;if(a==='gpContinue'&&GRAND_PRIX){SV.track=GRAND_PRIX.trackIds[GRAND_PRIX.raceIndex];persist();elRes.classList.remove('show');startRace();}else if(a==='gpDone'){GRAND_PRIX=null;elRes.classList.remove('show');showMenu('race');}else if(a==='again'){GRAND_PRIX=null;elRes.classList.remove('show');startRace();}else if(a==='garage'){GRAND_PRIX=null;elRes.classList.remove('show');showMenu();}});
document.getElementById('bResume').onclick=()=>setPause(false);
document.getElementById('bRestart').onclick=()=>{const tr=G.training;setPause(false);tr?startTraining():startRace();};
document.getElementById('bQuit').onclick=()=>{GRAND_PRIX=null;setPause(false);showMenu('race');};
function setPause(v){acc=0;if(v&&!(G.state==='countdown'||G.state==='race'||G.state==='finishing'||G.state==='training'))return;G.paused=v;elPause.classList.toggle('show',v);syncTouchControls();}

/* ===================== INPUT ===================== */
window.addEventListener('keydown',e=>{
  const c=e.code;
  if(['ArrowUp','ArrowDown','ArrowLeft','ArrowRight','Space'].includes(c))e.preventDefault();
  if(e.repeat){keys[c]=true;return;}
  keys[c]=true;ensureAudio();
  if(c==='KeyM'){audioOn=!audioOn;}
  if(c==='KeyP'||c==='Escape')setPause(!G.paused);
  if(G.paused)return;
  if(c==='Space'&&(G.state==='race'||G.state==='finishing'||G.state==='training')&&G.player&&!G.player.finished)G.useReq=true;
  if(c==='KeyQ'&&(G.state==='race'||G.state==='finishing'||G.state==='training')&&G.player&&!G.player.finished)G.useSlotReq=0;
  if(c==='KeyE'&&(G.state==='race'||G.state==='finishing'||G.state==='training')&&G.player&&!G.player.finished)G.useSlotReq=1;
  if(c==='Enter'&&G.state==='menu'&&!PROFILE_GATE_PROMPT&&MENU_PAGE==='race'&&document.querySelector('[data-act="start"]'))requestProfileRequiredAction('race');
   if(c==='Enter'&&G.state==='menu'&&!PROFILE_GATE_PROMPT&&MENU_PAGE==='training'&&document.querySelector('[data-act="training"]'))requestProfileRequiredAction('training');
  trickKey(c);
});
window.addEventListener('keyup',e=>{keys[e.code]=false;});
window.addEventListener('blur',()=>{for(const k in keys)keys[k]=false;if(G.state==='race'||G.state==='countdown'||G.state==='training')setPause(true);});
window.addEventListener('resize',resize);
const touchControls=document.getElementById('touchControls');
const NATIVE_TOUCH=MOBILE_DEVICE;
function jumpTouchMode(){const p=G.player;return!!(p&&p.air&&p.tricks&&!p.hop&&!G.paused);}
for(const b of touchControls.querySelectorAll('[data-touch]')){
  const code=b.dataset.touch,on=e=>{e.preventDefault();ensureAudio();b.classList.add('on');if(jumpTouchMode()&&b.dataset.jumpCode){trickKey(b.dataset.jumpCode);return;}keys[code]=true;},off=e=>{e.preventDefault();keys[code]=false;b.classList.remove('on');};
  b.addEventListener('pointerdown',on);b.addEventListener('pointerup',off);b.addEventListener('pointercancel',off);b.addEventListener('pointerleave',off);
}
for(const b of touchControls.querySelectorAll('[data-touch-action="item-slot"]'))b.addEventListener('pointerdown',e=>{e.preventDefault();if(G.player&&!G.paused)G.useSlotReq=+b.dataset.slot;});
touchControls.querySelector('[data-touch-action="pause"]').addEventListener('pointerdown',e=>{e.preventDefault();setPause(!G.paused);});
function syncTouchControls(){const gameplay=['countdown','race','finishing','training'].includes(G.state)&&!G.paused,active=gameplay&&(NATIVE_TOUCH||SV.mobileControlsTest),jump=active&&jumpTouchMode();touchControls.classList.toggle('active',active);touchControls.classList.toggle('jump-mode',jump);for(const b of touchControls.querySelectorAll('[data-jump-code]'))b.textContent=jump?b.dataset.jumpLabel:b.dataset.driveLabel;const p=G.player;for(const b of touchControls.querySelectorAll('[data-touch-action="item-slot"]')){const slot=+b.dataset.slot,item=p&&slotItem(p,slot),allowed=p&&slot<itemSlotCount(p);b.classList.toggle('hidden',!allowed);b.classList.toggle('empty',!item);const sp=b.querySelector('span');if(sp)sp.textContent=item?ITEM_DEF[item].name.toUpperCase()+(item==='tripulse'?' ×'+slotCharges(p,slot):''):'EMPTY';}const st=document.getElementById('touchState');if(st){const state=p?.pcState||PLAYER_STATES.BASE;st.textContent='STATE · '+state.toUpperCase()+(state===PLAYER_STATES.JUMP?' · 75%':'');}}

function readPlayerInput(p){
  const i=p.inp;
  // Mobile auto-throttle pauses only while D-pad down is held; the Settings switch is the persistent override.
  i.steer=(keys.ArrowRight?1:0)-(keys.ArrowLeft?1:0);
  i.thr=SV.auto?(keys.ArrowDown?0:1):(keys.ArrowUp?1:0);
  i.brk=keys.ArrowDown?1:0;
  i.drift=!!(keys.ShiftLeft||keys.ShiftRight||keys.KeyZ);
}

/* ===================== MAIN STEP ===================== */
G.goT=0;G.useReq=false;G.useSlotReq=-1;
function stepGame(dt){
  if(G.player)updateRacerState(G.player,0);G.timeScale=G.player&&resolveRacerState(G.player)===PLAYER_STATES.JUMP?.75:1;dt*=G.timeScale;G.t+=dt;
  if(G.goT>0)G.goT-=dt;
  for(const b of G.banners)b.t+=dt;
  G.banners=G.banners.filter(b=>b.t<b.dur);
  if(G.state==='training'){
    G.raceTime+=dt;const r=G.player;readPlayerInput(r);if(G.useSlotReq>=0){const q=G.useSlotReq;G.useSlotReq=-1;useItem(r,q);}else if(G.useReq){G.useReq=false;useItem(r);}updateRacer(r,dt);trainingInteract(r,dt);updateItems(dt);for(let i=G.parts.length-1;i>=0;i--){const q=G.parts[i];q.life-=dt;if(q.life<=0){G.parts.splice(i,1);continue;}q.x+=q.vx*dt;q.y+=q.vy*dt;q.z+=q.vz*dt;q.vz-=q.g*dt;if(q.z<0){q.z=0;q.vz*=-.3;}}updateEngine(r.speed,r.boostT>0);G.shake*=Math.exp(-6*dt);return;
  }
  if(G.state==='countdown'){
    const prev=G.cd;G.cd-=dt;
    if(Math.floor(G.cd)!==Math.floor(prev)&&G.cd>0)SFX.beep();
    if((keys.ArrowUp)&&G.startPress<0)G.startPress=Math.max(G.cd,.0001);
    if(G.cd<=0){
      G.state='race';G.goT=1.2;SFX.go();
      const p=G.player;
      if(G.startPress>0&&G.startPress<=.6){p.boostT=1.7;bannerAdd('LINE LAUNCH!','#ffb21a',1.4);SFX.boost();}
      else if(G.startPress>.6&&!SV.auto){bannerAdd('Too early!','#ff8a7a',1);}
      for(const r of G.racers)if(!r.isPlayer&&Math.random()<.35)r.boostT=1.2;
    }
  }
  if(G.state==='race'||G.state==='finishing')G.raceTime+=dt;
  // inputs + physics
  for(const r of G.racers){
    if(r.isPlayer&&!r.finished)readPlayerInput(r);else aiControl(r,dt);
    if(r.isPlayer&&G.useSlotReq>=0){const q=G.useSlotReq;G.useSlotReq=-1;useItem(r,q);}
    else if(r.isPlayer&&G.useReq){G.useReq=false;useItem(r);}
    else if(!r.isPlayer&&r.item&&r.inp.use){r.inp.use=false;}
    updateRacer(r,dt);
    trackInteract(r,dt);
  }
  G.useReq=false;G.useSlotReq=-1;
  raceCollisions();
  updateItems(dt);
  // particles
  for(let i=G.parts.length-1;i>=0;i--){const q=G.parts[i];q.life-=dt;if(q.life<=0){G.parts.splice(i,1);continue;}q.x+=q.vx*dt;q.y+=q.vy*dt;q.z+=q.vz*dt;q.vz-=q.g*dt;if(q.z<0){q.z=0;q.vz*=-.3;}}
  computeRanks();
  // finish detection
  for(const r of G.racers){
    if(!r.finished&&r.crossed>=G.laps+1){
      r.finished=true;r.finishTime=G.raceTime;
      if(r.isPlayer&&G.state!=='finishing'){G.state='finishing';G.finishT=0;SFX.win();}
    }
  }
  if(G.state==='finishing'){G.finishT+=dt;if(G.finishT>4||G.racers.every(r=>r.finished)){if(G.finishT>1.5||G.racers.every(r=>r.finished))showResults();}}
  // wrong way
  const pl=G.player;
  if(pl&&G.state==='race'){const along=pl.vx*T.tx[pl.idx]+pl.vy*T.ty[pl.idx];if(along<-3)G.wrongT+=dt;else G.wrongT=0;}
  if(pl)updateEngine(pl.speed,pl.boostT>0);
  G.shake*=Math.exp(-6*dt);
}

function drawBlindOverlay(p){
  if(!p||p.blindT<=0)return;const pulse=.94+.05*Math.sin(G.t*28);ctx.save();ctx.globalAlpha=pulse;ctx.fillStyle='#fffdf2';ctx.fillRect(0,0,W,H);ctx.globalAlpha=1;ctx.fillStyle='#f2c500';ctx.font='900 '+Math.round(clamp(Math.min(W/18,H/8),32,82))+'px "Trebuchet MS",sans-serif';ctx.textAlign='center';ctx.textBaseline='middle';ctx.fillText('ARK-FLASH',W/2,H/2);ctx.restore();
}

/* ===================== CAMERA + LOOP ===================== */
/* Smooth Edition: fixed simulation with interpolated visual poses.
   Interpolation only mutates draw-time fields, restored before any physics step. */
const VIS_FIELDS=['x','y','z','h','vx','vy','bob','spin','trickRot'];
function captureVisualState(reset=false){
  for(const r of G.racers){
    if(!r._visualPrev)r._visualPrev={};
    for(const k of VIS_FIELDS)r._visualPrev[k]=r[k];
  }
  for(const group of [G.parts,G.missiles])for(const o of group){o._px=o.x;o._py=o.y;o._pz=o.z;o._ph=o.h;}
}
function interpolateWorld(alpha){
  const restore=[];
  for(const r of G.racers){const p=r._visualPrev;if(!p)continue;const saved={};
    const teleport=Math.hypot(r.x-p.x,r.y-p.y)>12;
    for(const k of VIS_FIELDS){saved[k]=r[k];if(teleport)continue;
      if(k==='h')r[k]=p[k]+angDiff(p[k],r[k])*alpha;
      else if(Number.isFinite(p[k])&&Number.isFinite(r[k]))r[k]=lerp(p[k],r[k],alpha);
    }restore.push([r,saved]);
  }
  for(const group of [G.parts,G.missiles])for(const o of group){const saved={x:o.x,y:o.y,z:o.z,h:o.h};
    if(Number.isFinite(o._px)&&Math.hypot(o.x-o._px,o.y-o._py)<12){o.x=lerp(o._px,o.x,alpha);o.y=lerp(o._py,o.y,alpha);if(Number.isFinite(o.z)&&Number.isFinite(o._pz))o.z=lerp(o._pz,o.z,alpha);if(Number.isFinite(o.h)&&Number.isFinite(o._ph))o.h=o._ph+angDiff(o._ph,o.h)*alpha;}
    restore.push([o,saved]);
  }
  return ()=>{for(const [o,saved] of restore)Object.assign(o,saved);};
}
function updateCamera(dt){
  const p=G.player;if(!p)return;
  const baseZoom=clamp(Math.min(W/1250,H/760),.6,1.5);
  const tz=baseZoom*(SMOOTH.camera?1:p.boostT>0?.93:1);
  cam.zoom+=(tz-cam.zoom)*(1-Math.exp(-dt*3));
  if(SMOOTH.camera){
    const f=1-Math.exp(-dt*3.5),maxLook=7;
    SMOOTH.lookX+=(clamp(p.vx*.16,-maxLook,maxLook)-SMOOTH.lookX)*f;
    SMOOTH.lookY+=(clamp(p.vy*.16,-maxLook,maxLook)-SMOOTH.lookY)*f;
    cam.x=p.x+SMOOTH.lookX;cam.y=p.y+SMOOTH.lookY;
  }else{
    const f=1-Math.exp(-dt*6);
    cam.x+=(p.x+p.vx*.28-cam.x)*f;cam.y+=(p.y+p.vy*.28-cam.y)*f;
  }
  if(SMOOTH.resetCamera){cam.x=p.x;cam.y=p.y;cam.zoom=baseZoom;SMOOTH.resetCamera=false;}
  cam.sy=SMOOTH.shake?Math.sin(G.t*77)*G.shake*.4:0;
}
let lastTs=0,acc=0,monitorT=0,touchSyncT=0;
const FIXED_DT=1/60,MAX_STEPS=6;
function frame(ts){
  if(ts-touchSyncT>100){touchSyncT=ts;syncTouchControls();}
  const raw=lastTs?Math.max(0,(ts-lastTs)/1000):0;lastTs=ts;
  const dt=Math.min(.1,raw);
  if(raw>0&&raw<.5){SMOOTH.frameMs+=(raw*1000-SMOOTH.frameMs)*.06;SMOOTH.fps=1000/SMOOTH.frameMs;updatePerformanceGovernor(raw);}
  if(G.state==='countdown'||G.state==='race'||G.state==='finishing'||G.state==='training'){
    if(!G.paused){acc+=dt;let n=0;
      while(acc>=FIXED_DT&&n<MAX_STEPS){captureVisualState();stepGame(FIXED_DT);acc-=FIXED_DT;n++;}
      if(acc>=FIXED_DT)acc%=FIXED_DT;
    }else acc=0;
    const restore=interpolateWorld(G.paused?1:clamp(acc/FIXED_DT,0,1));
    try{updateCamera(dt);const visualTime=G.paused?G.t:Math.max(0,G.t-FIXED_DT+acc);renderWorld(visualTime);drawHUD(visualTime);drawBlindOverlay(G.player);}finally{restore();}
  }else if(G.state==='results'){
    acc=0;renderWorld(G.t);
  }else acc=0;
  if(ts-monitorT>350){monitorT=ts;const el=document.getElementById('smoothMonitor');el.style.display=SMOOTH.showFPS?'block':'none';el.textContent='LVA 4.6.7 Deferred Profile Gate & Drift Hotfix · '+Math.round(SMOOTH.fps)+' FPS · '+SMOOTH.quality+(lowDetail()?' · DETAIL SAVER':'')+' · P pause';}
  requestAnimationFrame(frame);
}
for(const [id,key] of [['smoothCamera','camera'],['smoothShake','shake'],['smoothFPS','showFPS']])document.getElementById(id).addEventListener('change',e=>{SMOOTH[key]=e.target.checked;SMOOTH.resetCamera=true;});
document.getElementById('smoothQuality').addEventListener('change',e=>{SMOOTH.quality=e.target.value;PERF.low=SMOOTH.quality==='performance';PERF.slowT=PERF.fastT=0;resize();});
document.addEventListener('visibilitychange',()=>{if(document.hidden){for(const k in keys)keys[k]=false;if(['race','countdown','finishing','training'].includes(G.state))setPause(true);acc=0;}lastTs=0;});
async function boot(){
  resize();await initLVAAssets();buildTrack(SV.track);buildFeatures();
  for(const o of FEAT.scenery)drawSceneryCached(o);
  cam.zoom=1;
  // idle camera at the start line for menu background
  trkAt(0,0);cam.x=trkAt.x;cam.y=trkAt.y;
  showMenu('home');
  requestAnimationFrame(frame);
}
boot().catch(err=>{console.error(err);document.getElementById('menu').innerHTML='<div class="card"><h2>Asset Load Error</h2><p>Reload the game to restart the factory simulation.</p></div>';document.getElementById('menu').classList.add('show');});
</script>
</body>
</html>

Game Source: Low Voltage Ascenders 4.6.7

Creator: SuperPirate58

Libraries: none

Complexity: complex (2121 lines, 337.3 KB)

The full source code is displayed above on this page.

Remix Instructions

To remix this game, copy the source code above and modify it. Add a ARCADELAB header at the top with "remix_of: low-voltage-ascenders-4-6-6-superpirate58" to link back to the original. Then publish at arcadelab.ai/publish.