Drift Car Page Transition
Motion and entrances @bhaskar Stars:0 Views:1
<!--
MIT License
Copyright (c) 2026 Suraj Maurya
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
-->
<div class="cs-stage">
<div class="cs-page" data-p="0">
<div class="cs-pv on">
<span class="cs-tag">Garage · Page 1</span>
<h2>Ready to launch?</h2>
<p>Tap the button to drift into the next page.</p>
<button type="button" class="cs-go" data-dir="ltr"><span>Launch Transition</span><span class="cs-ar">→</span></button>
</div>
<div class="cs-pv" hidden>
<span class="cs-tag">Track · Page 2</span>
<h2>You made it.</h2>
<p>Smoke clears, the new page is in. Drive back when you're ready.</p>
<button type="button" class="cs-go" data-dir="rtl"><span class="cs-ar">←</span><span>Drive Back</span></button>
</div>
</div>
<div class="cs-ov" aria-hidden="true" hidden>
<canvas></canvas>
<div class="cs-car"><svg class="cs-svg" viewBox="0 0 360 120"><defs><linearGradient id="cs-carPaint" x1="0%" y1="8%" x2="100%" y2="100%"><stop offset="0%" stop-color="#ff4b5f" /><stop offset="16%" stop-color="#ed1c32" /><stop offset="42%" stop-color="#c80f28" /><stop offset="68%" stop-color="#a9071d" /><stop offset="88%" stop-color="#760414" /><stop offset="100%" stop-color="#41020a" /></linearGradient><linearGradient id="cs-carPaintShadow" x1="0%" y1="0%" x2="0%" y2="100%"><stop offset="0%" stop-color="rgba(255,255,255,0.22)" /><stop offset="38%" stop-color="rgba(255,255,255,0.04)" /><stop offset="100%" stop-color="rgba(0,0,0,0.42)" /></linearGradient><linearGradient id="cs-carReflection" x1="0%" y1="0%" x2="100%" y2="0%"><stop offset="0%" stop-color="rgba(255,255,255,0)" /><stop offset="28%" stop-color="rgba(255,255,255,0.15)" /><stop offset="46%" stop-color="rgba(255,255,255,0.72)" /><stop offset="54%" stop-color="rgba(255,255,255,0.20)" /><stop offset="78%" stop-color="rgba(255,255,255,0.05)" /><stop offset="100%" stop-color="rgba(255,255,255,0)" /></linearGradient><linearGradient id="cs-glass" x1="0%" y1="0%" x2="100%" y2="100%"><stop offset="0%" stop-color="#6f8ea5" /><stop offset="22%" stop-color="#182632" /><stop offset="54%" stop-color="#071018" /><stop offset="100%" stop-color="#020507" /></linearGradient><linearGradient id="cs-glassReflection" x1="0%" y1="0%" x2="1" y2="1"><stop offset="0%" stop-color="rgba(255,255,255,0.48)" /><stop offset="22%" stop-color="rgba(255,255,255,0.10)" /><stop offset="52%" stop-color="rgba(255,255,255,0)" /><stop offset="84%" stop-color="rgba(255,255,255,0.16)" /><stop offset="1" stop-color="rgba(255,255,255,0)" /></linearGradient><linearGradient id="cs-carbon" x1="0%" y1="0%" x2="0%" y2="100%"><stop offset="0%" stop-color="#34383d" /><stop offset="45%" stop-color="#14171a" /><stop offset="100%" stop-color="#050607" /></linearGradient><radialGradient id="cs-tire" cx="42%" cy="34%" r="68%"><stop offset="0%" stop-color="#272b30" /><stop offset="62%" stop-color="#090a0c" /><stop offset="100%" stop-color="#020203" /></radialGradient><radialGradient id="cs-rim" cx="36%" cy="30%" r="80%"><stop offset="0%" stop-color="#e9edf0" /><stop offset="38%" stop-color="#9da4aa" /><stop offset="70%" stop-color="#5b6268" /><stop offset="100%" stop-color="#262a2e" /></radialGradient><radialGradient id="cs-hubGlow" cx="45%" cy="42%" r="55%"><stop offset="0%" stop-color="#fff4c4" /><stop offset="18%" stop-color="#ffc82e" /><stop offset="100%" stop-color="#9a3e00" /></radialGradient><linearGradient id="cs-headlight" x1="0%" y1="0%" x2="100%" y2="0%"><stop offset="0%" stop-color="#ffffff" stop-opacity="0.98" /><stop offset="35%" stop-color="#dff5ff" stop-opacity="0.9" /><stop offset="78%" stop-color="#7ec8ff" stop-opacity="0.22" /><stop offset="100%" stop-color="#7ec8ff" stop-opacity="0" /></linearGradient><radialGradient id="cs-tailLight"><stop offset="0%" stop-color="#fff1f2" /><stop offset="18%" stop-color="#ff425a" /><stop offset="62%" stop-color="#d10c2c" /><stop offset="100%" stop-color="#6a0011" stop-opacity="0" /></radialGradient><linearGradient id="cs-roadReflection" x1="0%" y1="0%" x2="0%" y2="100%"><stop offset="0%" stop-color="rgba(255,255,255,0.16)" /><stop offset="100%" stop-color="rgba(255,255,255,0)" /></linearGradient><filter id="cs-softBlur"><feGaussianBlur stdDeviation="3.5" /></filter><filter id="cs-lightGlow"><feGaussianBlur stdDeviation="2.5" /></filter></defs><ellipse cx="180" cy="103" rx="158" ry="9" fill="rgba(0,0,0,0.78)" filter="url(#cs-softBlur)" /><ellipse cx="183" cy="96" rx="122" ry="5" fill="url(#cs-roadReflection)" opacity="0.45" /><path d="M 20 80 C 16 75, 16 67, 20 60 L 31 51 C 43 48, 60 47, 82 45 C 100 41, 121 29, 145 23 C 166 18, 206 17, 228 23 C 248 28, 264 37, 281 45 L 314 51 C 330 54, 340 62, 338 70 L 330 81 L 298 81 C 294 70, 283 63, 269 63 C 254 63, 241 70, 237 81 L 111 81 C 107 69, 95 63, 81 63 C 66 63, 54 70, 49 81 L 22 81 Z" fill="url(#cs-carPaint)" stroke="#5b0612" stroke-width="1.4" /><path d="M 22 68 C 65 58, 92 57, 125 51 C 163 44, 212 40, 280 48 C 301 51, 319 59, 337 67 L 330 79 L 299 79 C 293 69, 283 64, 269 64 C 253 64, 243 70, 238 80 L 111 80 C 105 69, 95 64, 81 64 C 66 64, 56 70, 50 80 L 22 80 Z" fill="url(#cs-carPaintShadow)" opacity="0.78" /><path d="M 36 50 C 84 46, 118 39, 145 31 C 185 20, 226 25, 256 38 C 278 47, 301 50, 322 56" fill="none" stroke="url(#cs-carReflection)" stroke-width="4.2" stroke-linecap="round" opacity="0.86" /><path d="M 44 66 C 98 60, 142 61, 194 57 C 234 54, 280 56, 316 66" fill="none" stroke="rgba(255,255,255,0.12)" stroke-width="1.2" stroke-linecap="round" /><path d="M 91 45 C 108 37, 128 28, 146 24 C 170 19, 205 19, 227 25 C 244 30, 259 38, 271 46 L 253 50 L 105 50 Z" fill="url(#cs-glass)" stroke="rgba(255,255,255,0.22)" stroke-width="1" /><path d="M 170 23 L 164 49" stroke="rgba(0,0,0,0.58)" stroke-width="2.2" /><path d="M 95 45 C 122 35, 142 27, 159 24 L 151 48 Z" fill="url(#cs-glassReflection)" opacity="0.7" /><path d="M 179 24 C 196 23, 219 27, 238 36 L 248 46 L 178 46 Z" fill="rgba(255,255,255,0.05)" /><path d="M 206 42 C 215 39, 224 40, 230 44 L 224 48 L 208 47 Z" fill="url(#cs-carPaint)" stroke="#45030b" stroke-width="0.8" /><path d="M 211 43 L 222 43.5" stroke="rgba(255,255,255,0.42)" stroke-width="0.8" stroke-linecap="round" /><path d="M 130 52 C 117 56, 108 64, 102 75 L 111 75 C 116 65, 124 59, 137 55 Z" fill="#030405" stroke="#1e2226" stroke-width="1" /><path d="M 116 63 C 128 58, 139 56, 153 55" fill="none" stroke="#4d0a12" stroke-width="1.4" /><path d="M 167 48 L 160 75" stroke="rgba(0,0,0,0.34)" stroke-width="1.05" /><path d="M 171 48 C 186 47, 198 47, 208 48" fill="none" stroke="rgba(255,255,255,0.18)" stroke-width="0.8" /><path d="M 292 49 C 310 51, 323 56, 329 62 C 323 64, 309 63, 298 59 Z" fill="#11161b" stroke="#2e3941" stroke-width="0.7" /><path d="M 296 52 C 307 53, 317 56, 324 60" fill="none" stroke="url(#cs-headlight)" stroke-width="2.3" stroke-linecap="round" /><ellipse cx="319" cy="58" rx="16" ry="8" fill="url(#cs-tailLight)" opacity="0.12" filter="url(#cs-lightGlow)" /><path d="M 25 56 C 34 54, 42 57, 47 63" fill="none" stroke="#ff314d" stroke-width="3" stroke-linecap="round" /><circle cx="31" cy="60" r="7" fill="url(#cs-tailLight)" opacity="0.48" /><circle cx="31" cy="60" r="2.2" fill="#fff2f3" opacity="0.9" /><path d="M 18 81 L 51 81 M 111 81 L 238 81 M 298 81 L 333 81" stroke="url(#cs-carbon)" stroke-width="5" stroke-linecap="round" /><path d="M 20 84 L 58 84 M 305 84 L 331 84" stroke="#07090b" stroke-width="2.2" stroke-linecap="round" /><path d="M 280 78 L 289 84 L 298 78 M 303 79 L 311 84 L 319 79" fill="none" stroke="#25292e" stroke-width="1.1" /><g class="cs-rw"><circle cx="81" cy="82" r="19" fill="#020203" opacity="0.55" /><circle cx="81" cy="82" r="17" fill="url(#cs-tire)" /><circle cx="81" cy="82" r="15.7" fill="none" stroke="#353a40" stroke-width="1" /><circle cx="81" cy="82" r="11.3" fill="url(#cs-rim)" /><circle cx="81" cy="82" r="8.7" fill="#242a2f" /><circle cx="81" cy="82" r="8" fill="none" stroke="#cbd0d5" stroke-width="0.6" opacity="0.7" /><circle cx="81" cy="82" r="8.1" fill="none" stroke="#777f86" stroke-width="1" stroke-dasharray="1.8 1.8" /><path d="M 74 76 A 8 8 0 0 1 80 74 L 81 78 A 4 4 0 0 0 77 79 Z" fill="#ffc62c" stroke="#8d4b00" stroke-width="0.5" /><g stroke="#e3e7ea" stroke-width="1.15" stroke-linecap="round"><path d="M 81 82 L 81 73" /><path d="M 81 82 L 86.5 74.8" /><path d="M 81 82 L 90 78" /><path d="M 81 82 L 90 86" /><path d="M 81 82 L 86.5 89.2" /><path d="M 81 82 L 81 91" /><path d="M 81 82 L 75.5 89.2" /><path d="M 81 82 L 72 86" /><path d="M 81 82 L 72 78" /><path d="M 81 82 L 75.5 74.8" /></g><circle cx="81" cy="82" r="2.8" fill="url(#cs-hubGlow)" stroke="#5a4a16" stroke-width="0.6" /></g><g class="cs-fs"><g class="cs-fw"><circle cx="269" cy="82" r="19" fill="#020203" opacity="0.55" /><circle cx="269" cy="82" r="17" fill="url(#cs-tire)" /><circle cx="269" cy="82" r="15.7" fill="none" stroke="#353a40" stroke-width="1" /><circle cx="269" cy="82" r="11.3" fill="url(#cs-rim)" /><circle cx="269" cy="82" r="8.7" fill="#242a2f" /><circle cx="269" cy="82" r="8" fill="none" stroke="#cbd0d5" stroke-width="0.6" opacity="0.7" /><circle cx="269" cy="82" r="8.1" fill="none" stroke="#777f86" stroke-width="1" stroke-dasharray="1.8 1.8" /><path d="M 262 76 A 8 8 0 0 1 268 74 L 269 78 A 4 4 0 0 0 265 79 Z" fill="#ffc62c" stroke="#8d4b00" stroke-width="0.5" /><g stroke="#e3e7ea" stroke-width="1.15" stroke-linecap="round"><path d="M 269 82 L 269 73" /><path d="M 269 82 L 274.5 74.8" /><path d="M 269 82 L 278 78" /><path d="M 269 82 L 278 86" /><path d="M 269 82 L 274.5 89.2" /><path d="M 269 82 L 269 91" /><path d="M 269 82 L 263.5 89.2" /><path d="M 269 82 L 260 86" /><path d="M 269 82 L 260 78" /><path d="M 269 82 L 263.5 74.8" /></g><circle cx="269" cy="82" r="2.8" fill="url(#cs-hubGlow)" stroke="#5a4a16" stroke-width="0.6" /></g></g><path d="M 58 77 C 63 65, 71 61, 81 61 C 92 61, 101 66, 106 77" fill="none" stroke="rgba(255,255,255,0.16)" stroke-width="1.2" /><path d="M 246 77 C 251 65, 259 61, 269 61 C 280 61, 289 66, 294 77" fill="none" stroke="rgba(255,255,255,0.16)" stroke-width="1.2" /><g opacity="0.82"><ellipse cx="16" cy="79" rx="8" ry="2.8" fill="#ff7a18" opacity="0.25" filter="url(#cs-lightGlow)" /><circle cx="16" cy="79" r="1.6" fill="#ffd166" /><circle cx="13" cy="79" r="0.8" fill="#fff4c4" /></g> </svg></div>
<div class="cs-fade"></div>
</div>
<p class="cs-sr" role="status" aria-live="polite"></p>
</div>
<style>
.cs-stage{position:relative;width:100%;height:calc(100vh - 40px);min-height:280px;overflow:hidden;border-radius:16px;background:radial-gradient(120% 90% at 50% 100%,#1a1a1f 0%,#0a0a0b 60%);font-family:Inter,system-ui,-apple-system,"Segoe UI",sans-serif;color:#fafafa}
.cs-stage [hidden]{display:none!important}
.cs-stage::before{content:"";position:absolute;left:0;right:0;top:50%;height:1px;background:linear-gradient(90deg,transparent,rgba(255,255,255,.06),transparent);transform:translateY(60px)}
.cs-page{position:relative;display:grid;place-items:center;height:100%;padding:24px;text-align:center}
.cs-pv{display:flex;flex-direction:column;align-items:center;animation:cs-in .5s cubic-bezier(.16,1,.3,1)}
@keyframes cs-in{from{opacity:0;transform:translateY(8px)}}
.cs-tag{padding:4px 12px;border:1px solid rgba(255,255,255,.12);border-radius:999px;color:#a1a1aa;font:11px ui-monospace,SFMono-Regular,Menlo,monospace;letter-spacing:.08em;text-transform:uppercase}
.cs-pv h2{margin:16px 0 8px;font-size:clamp(26px,5vw,40px);font-weight:700;letter-spacing:-.035em}
.cs-pv p{max-width:340px;margin:0 0 24px;color:#a1a1aa;font-size:14px;line-height:1.6}
.cs-go{display:flex;align-items:center;gap:8px;padding:12px 24px;border:0;border-radius:12px;background:#fafafa;color:#09090b;font:inherit;font-size:14px;font-weight:500;letter-spacing:-.01em;cursor:pointer;box-shadow:0 4px 6px -1px rgba(0,0,0,.3);transition:opacity .15s,transform .15s}
.cs-go:hover{opacity:.9}.cs-go:active{transform:scale(.95)}
.cs-go:focus-visible{outline:2px solid #fafafa;outline-offset:3px}
.cs-ar{font:12px ui-monospace,SFMono-Regular,Menlo,monospace;opacity:.6}
.cs-ov{position:absolute;inset:0;z-index:50;overflow:hidden;pointer-events:none}
.cs-ov canvas{position:absolute;inset:0;width:100%;height:100%}
.cs-car{position:absolute;left:0;top:0;will-change:transform}
.cs-svg{display:block;overflow:visible;filter:drop-shadow(0 24px 22px rgba(0,0,0,.68))}
.cs-car.rtl .cs-svg{transform:scaleX(-1)}
.cs-rw{transform-origin:81px 82px}.cs-fs,.cs-fw{transform-origin:269px 82px}
.cs-rw,.cs-fs,.cs-fw{transform-box:view-box}
.cs-fade{position:absolute;inset:0;background:#050505;opacity:0}
.cs-sr{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0)}
</style>
<script>
(function(){
function bez(x1,y1,x2,y2){function A(a,b){return 1-3*b+3*a;}function B(a,b){return 3*b-6*a;}function C(a){return 3*a;}function f(t,a,b){return((A(a,b)*t+B(a,b))*t+C(a))*t;}function d(t,a,b){return 3*A(a,b)*t*t+2*B(a,b)*t+C(a);}return function(x){if(x<=0)return 0;if(x>=1)return 1;var t=x;for(var i=0;i<8;i++){var e=f(t,x1,x2)-x,s=d(t,x1,x2);if(Math.abs(e)<1e-5||Math.abs(s)<1e-6)break;t-=e/s;}return f(t,y1,y2);};}
var DRIFT=bez(.22,1,.36,1),EIO=bez(.42,0,.58,1),FADE=bez(.16,1,.3,1);
function kf(p,vals,times){if(p<=0)return vals[0];if(p>=1)return vals[vals.length-1];for(var i=1;i<times.length;i++){if(p<=times[i]){var k=(p-times[i-1])/(times[i]-times[i-1]);return vals[i-1]+(vals[i]-vals[i-1])*EIO(k);}}return vals[vals.length-1];}
var reduce=matchMedia('(prefers-reduced-motion: reduce)').matches,DUR=1350,PT_DELAY=900,PT_DUR=400,RESET=350,LIFE=1400,DENS=4,MAXP=160;
document.querySelectorAll('.cs-stage').forEach(function(stage){
var ov=stage.querySelector('.cs-ov'),cv=ov.querySelector('canvas'),ctx=cv.getContext('2d'),car=ov.querySelector('.cs-car'),svg=car.querySelector('svg'),rw=svg.querySelector('.cs-rw'),fs=svg.querySelector('.cs-fs'),fw=svg.querySelector('.cs-fw'),fade=ov.querySelector('.cs-fade'),views=stage.querySelectorAll('.cs-pv'),sr=stage.querySelector('.cs-sr'),
running=false,raf=null,smoke=[],skids=[],lines=[],lastW=null,W=0,H=0,dpr=1,st=null,timers=[];
function dims(){var w=stage.offsetWidth,s=w<640?.55:w<1024?.8:1,cw=310*s;return{w:cw,h:cw*100/300*1.12,s:s};}
function size(){W=stage.offsetWidth;H=stage.offsetHeight;dpr=Math.min(devicePixelRatio||1,2);cv.width=W*dpr;cv.height=H*dpr;}
function swap(){var cur=[].findIndex.call(views,function(v){return !v.hidden;}),nx=1-cur;views[cur].hidden=true;views[nx].hidden=false;sr.textContent=nx?'Page 2: Track':'Page 1: Garage';}
function later(fn,ms){timers.push(setTimeout(fn,ms));}
function frame(now){var D=st.d,ltr=st.ltr,p=Math.min(1,(now-st.t0)/DUR),dir=ltr?1:-1;
var x=st.sx+(st.ex-st.sx)*DRIFT(p),ang=kf(p,[0,0,st.maxA,st.maxA*.7,1.5*dir,0],[0,.22,.48,.7,.88,1]),steer=kf(p,[0,14*dir,18*dir,6*dir,0],[0,.26,.52,.74,1]),yo=kf(p,[0,-4*D.s,3*D.s,5*D.s,-2*D.s,0],[0,.2,.45,.68,.85,1]),wr=st.wr*DRIFT(p),carRun=p<1;
var top=H/2-D.h/2+yo;car.style.transform='translate('+x+'px,'+top+'px) rotate('+ang+'deg)';
rw.style.transform='rotate('+(ltr?wr:-wr)+'deg)';fw.style.transform='rotate('+(ltr?wr:-wr)+'deg)';fs.style.transform='rotate('+(ltr?steer:-steer)+'deg)';
var sx=D.w/360,sy=D.h/120,lx=(ltr?81:279)*sx,ly=82*sy,cx=D.w/2,cy=D.h/2,rad=ang*Math.PI/180,rx=lx-cx,ry=ly-cy,wx=x+cx+rx*Math.cos(rad)-ry*Math.sin(rad),wy=top+cy+rx*Math.sin(rad)+ry*Math.cos(rad),drifting=Math.abs(ang)>1.2;
ctx.setTransform(dpr,0,0,dpr,0,0);ctx.clearRect(0,0,W,H);
if(carRun&&drifting){if(lastW)skids.push({x1:lastW.x,y1:lastW.y,x2:wx,y2:wy,o:.55,w:5*D.s});lastW={x:wx,y:wy};}else lastW=null;
for(var i=skids.length-1;i>=0;i--){var s=skids[i];s.o-=.006;if(s.o<=0){skids.splice(i,1);continue;}ctx.beginPath();ctx.strokeStyle='rgba(10,10,15,'+s.o*.9+')';ctx.lineWidth=s.w;ctx.lineCap='round';ctx.moveTo(s.x1,s.y1);ctx.lineTo(s.x2,s.y2);ctx.stroke();}
if(carRun){var n=Math.min(Math.round(DENS*(drifting?1.8:1)),MAXP-smoke.length);for(var k=0;k<n;k++){var ps=(10+Math.random()*18)*D.s,pl=LIFE*(.8+Math.random()*.5);smoke.push({x:wx+(Math.random()*14-7)*D.s,y:wy+(Math.random()*10-5)*D.s,vx:-dir*(3.5+Math.random()*5.5)*D.s,vy:(-1.2+(Math.random()*2.4-1.2))*D.s,s:ps,ms:ps*(3.2+Math.random()*2),o:.75+Math.random()*.25,r:Math.random()*6.283,vr:Math.random()*.05-.025,l:pl,ml:pl});}
if(lines.length<14){var lsx=ltr?x-50*D.s:x+D.w+50*D.s;for(var j=0;j<2;j++)lines.push({x:lsx,y:top+D.h/2+(Math.random()*70-35)*D.s,len:(40+Math.random()*80)*D.s,vx:-dir*(14+Math.random()*10)*D.s,o:.65+Math.random()*.35,w:(1.2+Math.random()*1.8)*D.s});}}
for(i=lines.length-1;i>=0;i--){var l=lines[i];l.x+=l.vx;l.o-=.022;if(l.o<=0){lines.splice(i,1);continue;}var ex2=l.x+(ltr?-l.len:l.len),g=ctx.createLinearGradient(l.x,l.y,ex2,l.y);g.addColorStop(0,'rgba(255,255,255,'+l.o+')');g.addColorStop(1,'rgba(255,255,255,0)');ctx.beginPath();ctx.strokeStyle=g;ctx.lineWidth=l.w;ctx.lineCap='round';ctx.moveTo(l.x,l.y);ctx.lineTo(ex2,l.y);ctx.stroke();}
for(i=smoke.length-1;i>=0;i--){var q=smoke[i];q.x+=q.vx;q.y+=q.vy;q.r+=q.vr;q.l-=16.67;var pr=1-Math.max(0,q.l/q.ml),cs=q.s+(q.ms-q.s)*pr,co=q.o*(1-Math.pow(pr,1.8));if(q.l<=0||co<=.01){smoke.splice(i,1);continue;}
ctx.save();ctx.translate(q.x,q.y);ctx.rotate(q.r);var rg=ctx.createRadialGradient(0,0,cs*.08,0,0,cs);rg.addColorStop(0,'rgba(245,245,255,'+co*.85+')');rg.addColorStop(.35,'rgba(200,205,220,'+co*.5+')');rg.addColorStop(.7,'rgba(140,145,165,'+co*.2+')');rg.addColorStop(1,'rgba(100,105,125,0)');ctx.fillStyle=rg;ctx.beginPath();ctx.arc(0,0,cs,0,6.2832);ctx.fill();ctx.restore();}
if(st.fadeT0){var fp=Math.min(1,(now-st.fadeT0)/st.fadeDur);fade.style.opacity=st.fadeTo?FADE(fp):1-fp*fp;}
raf=requestAnimationFrame(frame);}
function go(ltr){if(running)return;running=true;timers.forEach(clearTimeout);timers=[];size();ov.hidden=false;
if(reduce){fade.style.opacity=1;later(function(){swap();later(function(){fade.style.opacity=0;ov.hidden=true;running=false;},RESET);},PT_DUR);return;}
var D=dims(),sx=ltr?-D.w-100:W+100,ex=ltr?W+160:-D.w-160,travel=Math.abs(ex-sx),circ=2*Math.PI*14*D.s;
car.classList.toggle('rtl',!ltr);svg.setAttribute('width',D.w);svg.setAttribute('height',D.h);smoke=[];skids=[];lines=[];lastW=null;fade.style.opacity=0;
st={t0:performance.now(),ltr:ltr,d:D,sx:sx,ex:ex,maxA:ltr?-6.5:6.5,wr:travel/circ*360*1.35,fadeT0:0};raf=requestAnimationFrame(frame);
later(function(){st.fadeT0=performance.now();st.fadeDur=PT_DUR;st.fadeTo=1;},DUR*.65);
var done=PT_DELAY+100;later(swap,done);
later(function(){st.fadeT0=performance.now();st.fadeDur=350;st.fadeTo=0;later(function(){cancelAnimationFrame(raf);raf=null;ctx.setTransform(1,0,0,1,0,0);ctx.clearRect(0,0,cv.width,cv.height);ov.hidden=true;running=false;var b=stage.querySelector('.cs-pv:not([hidden]) .cs-go');if(b&&document.activeElement&&stage.contains(document.activeElement))b.focus({preventScroll:true});},350);},done+RESET+PT_DUR);}
stage.querySelectorAll('.cs-go').forEach(function(b){b.addEventListener('click',function(e){e.preventDefault();var keep=document.activeElement===b;go(b.dataset.dir==='ltr');if(keep)setTimeout(function(){},0);});});
if(window.ResizeObserver)new ResizeObserver(function(){if(running)size();}).observe(stage);
});
})();
</script>