1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/optimizers-DEYifpeE.js","assets/index-CThNTRDP.js","assets/vendor-i18n-5wc_S7sb.js","assets/vendor-react-H8Xurm4u.js","assets/index-CJ2Do0LR.css","assets/useGPUDetect-gRyDdTgZ.js","assets/useAmbientMusic-CIhVcw9g.js","assets/index-DH_eo_Y2.js","assets/Environment-XaCWnzYV.js","assets/OrbitControls-BEt5BJ6u.js"])))=>i.map(i=>d[i]); 2import{j as n,a as w,H as pe,m as Kt,_ as Jt}from"./index-CThNTRDP.js";import{c as p,u as re}from"./vendor-i18n-5wc_S7sb.js";import{g as Qt,u as Zt}from"./useGPUDetect-gRyDdTgZ.js";import{u as en}from"./useAmbientMusic-CIhVcw9g.js";import{B as Ce,M as tn,V as k,a as X,S as nn,b as ze,C as U,U as sn,R as an,u as qe,O as rn,c as te,d as on,P as ln,D as ye,A as ce,F as cn,e as pn,f as yt,w as vt,q as un}from"./index-DH_eo_Y2.js";import{E as dn}from"./Environment-XaCWnzYV.js";import{O as mn}from"./OrbitControls-BEt5BJ6u.js";const Ue=(t,e,s=1)=>-Math.log(Math.exp(-s*t)+Math.exp(-s*e))/s,P=[{id:"simple-bowl",title:"The Simple Bowl",subtitle:"Every journey begins with a single step",icon:"ð¯",fn:(t,e)=>.5*(t*t+e*e),gradient:(t,e)=>[t,e],globalMin:[0,0],bounds:[-4,4],victoryRadius:.5,starThresholds:[60,30,12],defaultLR:.1,defaultMomentum:0,availableOptimizers:["sgd"],demoLR:.12,demoStart:[3,2.5],cameraPosition:[4,8,9],hint:"Click anywhere to drop the optimizer ball. It follows the gradient downhill. This bowl is gentle and forgiving - try cranking the learning rate to the max to see the ball overshoot and wobble.",explanationSuccess:"This is a convex function, meaning every path leads to the same minimum. Gradient descent works perfectly here because there are no traps. The learning rate controls how big each step is.",explanationFail:"The learning rate was too high and the optimizer overshot the minimum, causing it to diverge. Try a smaller learning rate!",explanationStuck:"The optimizer converged but not quite to the minimum. Try a slightly higher learning rate for faster convergence.",teachConcept:"Learning Rate",learningSummary:"Learning rate controls step size. Too small = slow convergence, too large = overshooting and divergence. For simple convex functions like this bowl, any starting point reaches the minimum.",relatedModule:{id:"learningRate",title:"Learning Rate"}},{id:"two-valleys",title:"Two Valleys",subtitle:"Not all valleys are created equal",icon:"â°ï¸",fn:(t,e)=>Ue(2*((t+2)*(t+2)+(e+2)*(e+2)),2*((t-2)*(t-2)+(e-2)*(e-2))+3,.8),gradient:null,globalMin:[-2,-2],localMin:[2,2],bounds:[-5,5],victoryRadius:.5,starThresholds:[80,40,18],defaultLR:.55,defaultMomentum:.85,availableOptimizers:["sgd","momentum"],demoLR:.06,demoStart:[-4,-4],cameraPosition:[5,8,10],hint:"Two valleys - the deeper one glows gold. The learning rate starts HIGH, so the ball overshoots and flies off even if you drop it on the target. Lower it until the ball settles, and use Momentum to roll out of the shallow valley into the deep one.",explanationSuccess:'You found the global minimum! Momentum helps the ball "roll through" shallow valleys to find deeper ones. Without momentum, SGD gets trapped in the first valley it enters.',explanationFail:"Too much speed! The optimizer flew off the landscape. Lower the learning rate.",explanationStuck:"You found a local minimum, not the global one! The local minimum has a higher loss. Try starting from a different position, or use momentum to escape.",teachConcept:"Local vs Global Minima",learningSummary:"Loss landscapes often have multiple valleys. SGD gets trapped in the first valley it enters. Momentum gives the optimizer inertia to roll through shallow local minima and find the deeper global minimum.",relatedModule:{id:"momentum",title:"Momentum"}},{id:"saddle-point",title:"The Saddle Point",subtitle:"Flat does not mean finished",icon:"ð",fn:(t,e)=>2.6*t*t+.05*t*t*t*t-1*e*e+.15*e*e*e*e-.2*e+3,gradient:null,globalMin:[0,1.88],bounds:[-4,4],victoryRadius:.45,starThresholds:[100,50,22],defaultLR:.6,defaultMomentum:.9,availableOptimizers:["sgd","momentum"],demoLR:.05,demoStart:[.6,3.6],cameraPosition:[4,8,10],hint:"A saddle: the surface curves up one way and down another, so the centre is NOT a minimum. The real minimum is down the +z trough. The high default learning rate overshoots and flies off - lower it, and add Momentum, to settle into the trough.",explanationSuccess:"The optimizer escaped the saddle point! Saddle points have zero gradient but are not minima. The loss is at a minimum along one axis but a maximum along another.",explanationFail:"The optimizer diverged along the unstable direction of the saddle. Try a smaller learning rate.",explanationStuck:"The optimizer got stuck at the saddle point where the gradient is almost zero. Try adding momentum or starting from a different position slightly off-center.",teachConcept:"Saddle Points",learningSummary:"Saddle points have near-zero gradients but are NOT minima. The loss goes down in one direction but up in another. In high-dimensional neural networks, saddle points are far more common than local minima. Momentum helps escape them.",relatedModule:{id:"convexity",title:"Convexity"}},{id:"noisy-terrain",title:"Noisy Terrain",subtitle:"Learning to see through the noise",icon:"ð",fn:(t,e)=>{const s=2.2*(t*t+e*e),i=.5*Math.sin(3*t)*Math.cos(3*e),a=.3*Math.sin(5*e)*Math.cos(2*t);return s+i+a+1},gradient:null,globalMin:[-.2,-.16],bounds:[-4,4],victoryRadius:.5,starThresholds:[120,60,25],defaultLR:.5,defaultMomentum:.85,availableOptimizer
2s:["sgd","momentum","adam"],demoLR:.05,demoStart:[2.4,2.4],cameraPosition:[4,8,10],hint:"The surface is steep and bumpy. The high default learning rate overshoots and flies off - lower it. Then switch to Adam, which adapts its step size to power through the noise.",explanationSuccess:"Adam combines momentum with adaptive per-parameter learning rates, making it naturally resistant to noisy gradients. This is why Adam is the default optimizer for most deep learning training!",explanationFail:"The noise caused the optimizer to diverge. A smaller learning rate helps, or try Adam which adapts automatically.",explanationStuck:"The optimizer got stuck in one of the bumps. Momentum or Adam can help power through small local minima caused by noise.",teachConcept:"Adaptive Learning Rates",learningSummary:"Real training data creates noisy gradients that confuse fixed-rate optimizers. Adam adapts its step size per parameter using running averages of past gradients. This is why Adam is the default optimizer for most deep learning.",relatedModule:{id:"adam",title:"Adam Optimizer"}},{id:"the-abyss",title:"The Abyss",subtitle:"Master the landscape",icon:"ð",fn:(t,e)=>Ue(Ue(2*((t+2.5)*(t+2.5)+(e-1)*(e-1)),2*((t-2)*(t-2)+(e+2.5)*(e+2.5))+3.5,.7),2*((t-.5)*(t-.5)+(e-3)*(e-3))+1.6,.7),gradient:null,globalMin:[-2.5,1],localMin:[.5,3],bounds:[-5,5],victoryRadius:.5,starThresholds:[150,75,30],defaultLR:.5,defaultMomentum:.9,availableOptimizers:["sgd","momentum","adam"],demoLR:.06,demoStart:[-4.2,1],cameraPosition:[5,8,11],hint:"The final exam: three valleys. Find the deepest (golden) one. The learning rate starts high, so the ball flies off - lower it so you do not overshoot, and pick a robust optimizer (Adam) to survive the ridges.",explanationSuccess:"Congratulations! You navigated a complex loss landscape with multiple traps. Real neural network landscapes are even more complex, with millions of dimensions!",explanationFail:"The landscape is treacherous. Try a more conservative learning rate, or use Adam for stability.",explanationStuck:"You found a local minimum, but not the deepest one. The global minimum is marked by the golden glow. Try a different starting point or a different optimizer.",teachConcept:"Putting It All Together",learningSummary:"Real neural network loss landscapes combine ALL of these challenges in millions of dimensions. The choice of optimizer, learning rate, and momentum can mean the difference between a model that learns and one that fails. You now understand the core intuition behind training neural networks!",relatedModule:{id:"gradientDescent",title:"Gradient Descent"}}];var hn=Object.defineProperty,gn=(t,e,s)=>e in t?hn(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s,F=(t,e,s)=>(gn(t,typeof e!="symbol"?e+"":e,s),s);function Ne(t,e,s,i,a){let r;if(t=t.subarray||t.slice?t:t.buffer,s=s.subarray||s.slice?s:s.buffer,t=e?t.subarray?t.subarray(e,a&&e+a):t.slice(e,a&&e+a):t,s.set)s.set(t,i);else for(r=0;r<t.length;r++)s[r+i]=t[r];return s}function xn(t){return t instanceof Float32Array?t:t instanceof Ce?t.getAttribute("position").array:t.map(e=>{const s=Array.isArray(e);return e instanceof k?[e.x,e.y,e.z]:e instanceof ze?[e.x,e.y,0]:s&&e.length===3?[e[0],e[1],e[2]]:s&&e.length===2?[e[0],e[1],0]:e}).flat()}class fn extends Ce{constructor(){super(),F(this,"type","MeshLine"),F(this,"isMeshLine",!0),F(this,"positions",[]),F(this,"previous",[]),F(this,"next",[]),F(this,"side",[]),F(this,"width",[]),F(this,"indices_array",[]),F(this,"uvs",[]),F(this,"counters",[]),F(this,"widthCallback",null),F(this,"_attributes"),F(this,"_points",[]),F(this,"points"),F(this,"matrixWorld",new tn),Object.defineProperties(this,{points:{enumerable:!0,get(){return this._points},set(e){this.setPoints(e,this.widthCallback)}}})}setMatrixWorld(e){this.matrixWorld=e}setPoints(e,s){if(e=xn(e),this._points=e,this.widthCallback=s??null,this.positions=[],this.counters=[],e.length&&e[0]instanceof k)for(let i=0;i<e.length;i++){const a=e[i],r=i/(e.length-1);this.positions.push(a.x,a.y,a.z),this.positions.push(a.x,a.y,a.z),this.counters.push(r),this.counters.push(r)}else for(let i=0;i<e.length;i+=3){const a=i/(e.length-1);this.positions.push(e[i],e[i+1],e[i+2]),this.positions.push(e[i],e[i+1],e[i+2]),this.counters.push(a),this.counters.push(a)}this.process()}compareV3(e,s){const i=e*6,a=s*6;return this.positions[i]===this.positions[a]&&this.positions[i+1]===this.positions[a+1]&&this.positions[i+2]===this.positions[a+2]}copyV3(e){const s=e*6;return[this.positions[s],this.positions[s+1],this.positions[s+2]]}process(){const e=this.positions.length/6;this.previous=[],this.next=[],this.side=[],this.width=[],this.indices_array=[],this.uvs=[];let s,i;this.compareV3(0,e-1)?i=this.copyV3(e-2):i=this.copyV3(0),this.previous.push(i[0],i[1],i[2]),this.previous.push(i[0],i[1],i[2]);for(let a=0;a<e;a++){if(this.side.push(1),this.side.push(-1),this.widthCallback?s=this.widthCallback(a/(e-1)):s=1,this.width.push(s),this.width.push(s),this.uvs.push(a/(e-1),0),this.uvs.push(a/(e-1),1),a<e-1){i=this.copyV3(a),this.previous.push(i[0],i[1],i[2]),this.previous.push(i[0],i[1],i[2]);const r=a*2;this.indices_array.push(r,r+1,r+2),this.indices_array.push(r+2,r+1,r+3)}a>0&&(i=this.copyV3(a),this.next.push(i[0],i[1],i[2]),this.next.push(i[0],i[1],i[2]))}this.compareV3(e-1,0)?i=this.copyV3(1):i=this.copyV3(e-1),this.next.push(i[0],i[1],i[2]),this.next.push(i[0],i[1],i[2]),!this._attributes||this._attributes.position.count!==this.counters.length?this._attributes={position:new X(new Float32Array(this.positions),3),previous:new X(new Float32Array(this.previous),3),next:new X(new Float32Array(this.next),3),side:new X(new Float32Array(this.side),1),width:new X(new Float32Array(this.width),1),uv:new X(new Float32Array(this.uvs),2),index:new X(new Uint16Array(this.indices_array),1),counters:new X(new Float32Array(this.counters),1)}:(this._attributes.position.copyArray(new Float32Array(this.positions)),this._attributes.position.needsUpdate=!0,this._attributes.previous.copyArray(new Float32Array(this.previous)),this._attributes.previous.needsUpdate=!0,this._attributes.next.copyArray(new Float32Array(this.next)),this._attributes.next.needsUpdate=!0,this._attributes.side.copyArray(new Float32Array(this.side)),this._attributes.side.needsUpdate=!0,this._attributes.width.copyArray(new Float32Array(this.width)),this._attributes.width.needsUpdate=!0,this._attributes.uv.copyArray(new Float32Array(this.uvs)),this._attributes.uv.needsUpdate=!0,this._attributes.index.copyArray(new Uint16Array(this.indices_array)),this._attributes.index.needsUpdate=!0),this.setAttribute("position",this._attributes.position),this.setAttribute("previous",this._attributes.previous),this.setAttribute("next",this._attributes.next),this.setAttribute("side",this._attributes.side),this.setAttribute("width",this._attributes.width),this.setAttribute("uv",this._attributes.uv),this.setAttribute("counters",this._attributes.counters),this.setAttribute("position",this._attributes.position),this.setAttribute("previous",this._attributes.previous),this.setAttribute("next",this._attributes.next),this.setAttribute("side",this._attributes.side),this.setAttribute("width",this._attributes.width),this.setAttribute("uv",this._attributes.uv),this.setAttribute("counters",this._attributes.counters),this.setIndex(this._attributes.index),this.computeBoundingSphere(),this.computeBoundingBox()}advance({x:e,y:s,z:i}){const a=this._attributes.position.array,r=this._attributes.previous.array,o=this._attributes.next.array,l=a.length;Ne(a,0,r,0,l),Ne(a,6,a,0,l-6),a[l-6]=e,a[l-5]=s,a[l-4]=i,a[l-3]=e,a[l-2]=s,a[l-1]=i,Ne(a,6,o,0,l-6),o[l-6]=e,o[l-5]=s,o[l-4]=i,o[l-3]=e,o[l-2]=s,o[l-1]=i,this._attributes.position.needsUpdate=!0,this._attributes.previous.needsUpdate=!0,this._attributes.next.needsUpdate=!0}}const yn=` 3 #include <common> 4 #include <logdepthbuf_pars_vertex> 5 #include <fog_pars_vertex> 6 #include <clipping_planes_pars_vertex> 7 8 attribute vec3 previous; 9 attribute vec3 next; 10 attribute float side; 11 attribute float width; 12 attribute float counters; 13 14 uniform vec2 resolution; 15 uniform float lineWidth; 16 uniform vec3 color; 17 uniform float opacity; 18 uniform float sizeAttenuation; 19 20 varying vec2 vUV; 21 varying vec4 vColor; 22 varying float vCounters; 23 24 vec2 fix(vec4 i, float aspect) { 25 vec2 res = i.xy / i.w; 26 res.x *= aspect; 27 return res; 28 } 29 30 void main() { 31 float aspect = resolution.x / resolution.y; 32 vColor = vec4(color, opacity); 33 vUV = uv; 34 vCounters = counters; 35 36 mat4 m = projectionMatrix * modelViewMatrix;
37 vec4 finalPosition = m * vec4(position, 1.0) * aspect; 38 vec4 prevPos = m * vec4(previous, 1.0); 39 vec4 nextPos = m * vec4(next, 1.0); 40 41 vec2 currentP = fix(finalPosition, aspect); 42 vec2 prevP = fix(prevPos, aspect); 43 vec2 nextP = fix(nextPos, aspect); 44 45 float w = lineWidth * width; 46 47 vec2 dir; 48 if (nextP == currentP) dir = normalize(currentP - prevP); 49 else if (prevP == currentP) dir = normalize(nextP - currentP); 50 else { 51 vec2 dir1 = normalize(currentP - prevP); 52 vec2 dir2 = normalize(nextP - currentP); 53 dir = normalize(dir1 + dir2); 54 55 vec2 perp = vec2(-dir1.y, dir1.x); 56 vec2 miter = vec2(-dir.y, dir.x); 57 //w = clamp(w / dot(miter, perp), 0., 4. * lineWidth * width); 58 } 59 60 //vec2 normal = (cross(vec3(dir, 0.), vec3(0., 0., 1.))).xy; 61 vec4 normal = vec4(-dir.y, dir.x, 0., 1.); 62 normal.xy *= .5 * w; 63 //normal *= projectionMatrix; 64 if (sizeAttenuation == 0.) { 65 normal.xy *= finalPosition.w; 66 normal.xy /= (vec4(resolution, 0., 1.) * projectionMatrix).xy * aspect; 67 } 68 69 finalPosition.xy += normal.xy * side; 70 gl_Position = finalPosition; 71 #include <logdepthbuf_vertex> 72 #include <fog_vertex> 73 vec4 mvPosition = modelViewMatrix * vec4(position, 1.0); 74 #include <clipping_planes_vertex> 75 #include <fog_vertex> 76 } 77`,vn=parseInt(an.replace(/\D+/g,"")),bn=vn>=154?"colorspace_fragment":"encodings_fragment",wn=` 78 #include <fog_pars_fragment> 79 #include <logdepthbuf_pars_fragment> 80 #include <clipping_planes_pars_fragment> 81 82 uniform sampler2D map; 83 uniform sampler2D alphaMap; 84 uniform float useGradient; 85 uniform float useMap; 86 uniform float useAlphaMap; 87 uniform float useDash; 88 uniform float dashArray; 89 uniform float dashOffset; 90 uniform float dashRatio; 91 uniform float visibility; 92 uniform float alphaTest; 93 uniform vec2 repeat; 94 uniform vec3 gradient[2]; 95 96 varying vec2 vUV; 97 varying vec4 vColor; 98 varying float vCounters; 99 100 void main() { 101 #include <logdepthbuf_fragment> 102 vec4 diffuseColor = vColor; 103 if (useGradient == 1.) diffuseColor = vec4(mix(gradient[0], gradient[1], vCounters), 1.0); 104 if (useMap == 1.) diffuseColor *= texture2D(map, vUV * repeat); 105 if (useAlphaMap == 1.) diffuseColor.a *= texture2D(alphaMap, vUV * repeat).a; 106 if (diffuseColor.a < alphaTest) discard; 107 if (useDash == 1.) diffuseColor.a *= ceil(mod(vCounters + dashOffset, dashArray) - (dashArray * dashRatio)); 108 diffuseColor.a *= step(vCounters, visibility); 109 #include <clipping_planes_fragment> 110 gl_FragColor = diffuseColor; 111 #include <fog_fragment> 112 #include <tonemapping_fragment> 113 #include <${bn}> 114 } 115`;class Sn extends nn{constructor(e){super({uniforms:{...sn.fog,lineWidth:{value:1},map:{value:null},useMap:{value:0},alphaMap:{value:null},useAlphaMap:{value:0},color:{value:new U(16777215)},gradient:{value:[new U(16711680),new U(65280)]},opacity:{value:1},resolution:{value:new ze(1,1)},sizeAttenuation:{value:1},dashArray:{value:0},dashOffset:{value:0},dashRatio:{value:.5},useDash:{value:0},useGradient:{value:0},visibility:{value:1},alphaTest:{value:0},repeat:{value:new ze(1,1)}},vertexShader:yn,fragmentShader:wn}),F(this,"lineWidth"),F(this,"map"),F(this,"useMap"),F(this,"alphaMap"),F(this,"useAlphaMap"),F(this,"color"),F(this,"gradient"),F(this,"resolution"),F(this,"sizeAttenuation"),F(this,"dashArray"),F(this,"dashOffset"),F(this,"dashRatio"),F(this,"useDash"),F(this,"useGradient"),F(this,"visibility"),F(this,"repeat"),this.type="MeshLineMaterial",Object.defineProperties(this,{lineWidth:{enumerable:!0,get(){return this.uniforms.lineWidth.value},set(s){this.uniforms.lineWidth.value=s}},map:{enumerable:!0,get(){return this.uniforms.map.value},set(s){this.uniforms.map.value=s}},useMap:{enumerable:!0,get(){return this.uniforms.useMap.value},set(s){this.uniforms.useMap.value=s}},alphaMap:{enumerable:!0,get(){return this.uniforms.alphaMap.value},set(s){this.uniforms.alphaMap.value=s}},useAlphaMap:{enumerable:!0,get(){return this.uniforms.useAlphaMap.value},set(s){this.uniforms.useAlphaMap.value=s}},color:{enumerable:!0,get(){return this.uniforms.color.value},set(s){this.uniforms.color.value=s}},gradient:{enumerable:!0,get(){return this.uniforms.gradient.value},set(s){this.uniforms.gradient.value=s}},opacity:{enumerable:!0,get(){return this.uniforms.opacity.value},set(s){this.uniforms.opacity.value=s}},resolution:{enumerable:!0,get(){return this.uniforms.resolution.value},set(s){this.uniforms.resolution.value.copy(s)}},sizeAttenuation:{enumerable:!0,get(){return this.uniforms.sizeAttenuation.value},set(s){this.uniforms.sizeAttenuation.value=s}},dashArray:{enumerable:!0,get(){return this.uniforms.dashArray.value},set(s){this.uniforms.dashArray.value=s,this.useDash=s!==0?1:0}},dashOffset:{enumerable:!0,get(){return this.uniforms.dashOffset.value},set(s){this.uniforms.dashOffset.value=s}},dashRatio:{enumerable:!0,get(){return this.uniforms.dashRatio.value},set(s){this.uniforms.dashRatio.value=s}},useDash:{enumerable:!0,get(){return this.uniforms.useDash.value},set(s){this.uniforms.useDash.value=s}},useGradient:{enumerable:!0,get(){return this.uniforms.useGradient.value},set(s){this.uniforms.useGradient.value=s}},visibility:{enumerable:!0,get(){return this.uniforms.visibility.value},set(s){this.uniforms.visibility.value=s}}
115,alphaTest:{enumerable:!0,get(){return this.uniforms.alphaTest.value},set(s){this.uniforms.alphaTest.value=s}},repeat:{enumerable:!0,get(){return this.uniforms.repeat.value},set(s){this.uniforms.repeat.value.copy(s)}}}),this.setValues(e)}copy(e){return super.copy(e),this.lineWidth=e.lineWidth,this.map=e.map,this.useMap=e.useMap,this.alphaMap=e.alphaMap,this.useAlphaMap=e.useAlphaMap,this.color.copy(e.color),this.gradient=e.gradient,this.opacity=e.opacity,this.resolution.copy(e.resolution),this.sizeAttenuation=e.sizeAttenuation,this.dashArray=e.dashArray,this.dashOffset=e.dashOffset,this.dashRatio=e.dashRatio,this.useDash=e.useDash,this.useGradient=e.useGradient,this.visibility=e.visibility,this.alphaTest=e.alphaTest,this.repeat.copy(e.repeat),this}}const Bt={width:.2,length:1,decay:1,local:!1,stride:0,interval:1},jn=(t,e=1)=>(t.set(t.subarray(e)),t.fill(-1/0,-e),t);function Mn(t,e){const{length:s,local:i,decay:a,interval:r,stride:o}={...Bt,...e},l=p.useRef(null),[c]=p.useState(()=>new k);p.useLayoutEffect(()=>{t&&(l.current=Float32Array.from({length:s*10*3},(h,d)=>t.position.getComponent(d%3)))},[s,t]);const u=p.useRef(new k),m=p.useRef(0);return te(()=>{if(t&&l.current){if(m.current===0){let h;i?h=t.position:(t.getWorldPosition(c),h=c);const d=1*a;for(let x=0;x<d;x++)h.distanceTo(u.current)<o||(jn(l.current,3),l.current.set(h.toArray(),l.current.length-3));u.current.copy(h)}m.current++,m.current=m.current%r}}),l}const _n=p.forwardRef((t,e)=>{const{children:s}=t,{width:i,length:a,decay:r,local:o,stride:l,interval:c}={...Bt,...t},{color:u="hotpink",attenuation:m,target:h}=t,d=qe(I=>I.size),x=qe(I=>I.scene),v=p.useRef(null),[R,M]=p.useState(null),y=Mn(R,{length:a,decay:r,local:o,stride:l,interval:c});p.useEffect(()=>{const I=(h==null?void 0:h.current)||v.current.children.find(f=>f instanceof rn);I&&M(I)},[y,h]);const b=p.useMemo(()=>new fn,[]),A=p.useMemo(()=>{var I,f;const G=new Sn({lineWidth:.1*i,color:u,sizeAttenuation:1,resolution:new ze(d.width,d.height)});let j;if(s)if(Array.isArray(s))j=s.find(_=>{const T=_;return typeof T.type=="string"&&T.type==="meshLineMaterial"});else{const _=s;typeof _.type=="string"&&_.type==="meshLineMaterial"&&(j=_)}return typeof((I=j)==null?void 0:I.props)=="object"&&((f=j)==null?void 0:f.props)!==null&&G.setValues(j.props),G},[i,u,d,s]);return p.useEffect(()=>{A.uniforms.resolution.value.set(d.width,d.height)},[d]),te(()=>{y.current&&b.setPoints(y.current,m)}),p.createElement("group",null,on(p.createElement("mesh",{ref:e,geometry:b,material:A}),x),p.createElement("group",{ref:v},s))}),ge=.12,Tn=.15,bt=80,An=.5,wt=6;function q(t){const e=t*An;return wt*Math.tanh(e/wt)}const S={targetGold:"#fbbf24",targetGlow:"#f59e0b",victoryGold:"#fcd34d",glassBgLight:"rgba(255, 255, 255, 0.82)",glassBgDark:"rgba(var(--bg-card-rgb), 0.82)",glassBorderLight:"rgba(255, 255, 255, 0.3)",glassBorderDark:"rgba(148, 163, 184, 0.2)"},Rn="#f0f4ff",zn="#0a0a0a",ds=.9,ms=.999,hs=1e-8,St=200,jt=80,Ye=2500;function Cn(t,e,s,i){const a=Math.max(0,Math.min(1,(t-e)/(s-e+1e-6)));let r,o,l;if(a<.15){const c=a/.15;r=.04+.02*c,o=.08+.55*c,l=.35+.55*c}else if(a<.35){const c=(a-.15)/.2;r=.06+.34*c,o=.63+.22*c,l=.9-.65*c}else if(a<.55){const c=(a-.35)/.2;r=.4+.5*c,o=.85-.05*c,l=.25-.15*c}else if(a<.75){const c=(a-.55)/.2;r=.9+.1*c,o=.8-.5*c,l=.1-.05*c}else{const c=(a-.75)/.25;r=1-.15*c,o=.3-.2*c,l=.05+.02*c}return i&&(r=Math.min(1,r*1.25),o=Math.min(1,o*1.25),l=Math.min(1,l*1.25)),[r,o,l]}function In({level:t,isDark:e,quality:s,onPointerMove:i,onClick:a}){const r=p.useRef(),o=Qt(s),{geometry:l}=p.useMemo(()=>{if(!t)return{geometry:null};const[c,u]=t.bounds,m=u-c,h=o,d=new ln(m,m,h,h),x=d.attributes.position.array,v=new Float32Array(x.length),R=x.length/3;let M=1/0,y=-1/0;const b=[];for(let A=0;A<R;A++){const I=x[A*3],f=x[A*3+1],G=c+(I/m+.5)*m,j=c+(f/m+.5)*m,_=t.fn(G,j),T=q(_);b.push({wx:G,wz:j,h:T,loss:_}),_<M&&(M=_),_>y&&(y=_)}for(let A=0;A<R;A++){const{wx:I,wz:f,h:G,loss:j}=b[A];x[A*3]=I,x[A*3+1]=G,x[A*3+2]=f;const[_,T,z]=Cn(j,M,y,e);v[A*3]=_,v[A*3+1]=T,v[A*3+2]=z}return d.setAttribute("color",new X(v,3)),d.attributes.position.needsUpdate=!0,d.computeVertexNormals(),{geometry:d}},[t,o,e]);return l?n.jsx("mesh",{ref:r,geometry:l,receiveShadow:!0,onPointerMove:i,onClick:a,children:n.jsx("meshPhysicalMaterial",{vertexColors:!0,roughness:.25,metalness:.15,clearcoat:s==="high"?.6:.1,clearcoatRoughness:.2,side:ye,transparent:!0,opacity:.95,envMapIntensity:e?1.5:.8})}):null}function Lt(t){if(t<.25)return[1,.15+.45*(t/.25),.05];if(t<.5){const e=(t-.25)/.25;return[1-.1*e,.6+.25*e,.05]}else if(t<.75){const e=(t-.5)/.25;return[.9-.5*e,.85+.05*e,.05+.2*e]}else{const e=(t-.75)/.25;return[.4-.3*e,.9+.1*e,.25+.15*e]}}const Mt=new U;function _t({path:t,color:e,quality:s,isDark:i}){const a=p.useRef(),r=p.useRef(),o=p.useRef(),l=p.useRef(new k(0,0,0)),c=p.useRef(new k(0,0,0)),u=p.useRef(0),m=p.useRef(0);te(({clock:x})=>{if(!t||t.length===0||!a.current)return;c.current.copy(a.current.position);const v=Math.min(u.current,t.length-1),R=t[v];l.current.set(R.x,R.y+ge+.02,R.z),a.current.position.lerp(l.current,Tn);const M=a.current.position.x-c.current.x,y=a.current.position.z-c.current.z,b=Math.sqrt(M*M+y*y);m.current=b,b>
115.001&&(a.current.rotation.z-=M*8,a.current.rotation.x+=y*8);const A=t.length>1?v/(t.length-1):0,[I,f,G]=Lt(A),j=a.current.material;if(j&&(Mt.setRGB(I,f,G),j.emissive.copy(Mt),j.emissiveIntensity=(i?.8:.3)+b*5),r.current){r.current.position.copy(a.current.position);const _=x.getElapsedTime(),T=1+.2*Math.sin(_*4)+b*4;r.current.scale.setScalar(T),r.current.material.opacity=Math.min(.25,.06+b*2+.03*Math.sin(_*3)),r.current.material.color.setRGB(I,f,G)}if(o.current){o.current.position.copy(a.current.position);const _=x.getElapsedTime(),T=i?2.5:1;o.current.intensity=T+.8*Math.sin(_*3)+b*18,o.current.color.setRGB(I,f,G)}u.current<t.length-1&&(u.current+=1)});const h=t==null?void 0:t.length;p.useMemo(()=>{h===1&&(u.current=0)},[h]);const d=t&&t.length>0?[t[0].x,t[0].y+ge+.02,t[0].z]:[0,1,0];return n.jsxs("group",{children:[s!=="low"&&n.jsx(_n,{width:s==="high"?.8:.4,length:s==="high"?bt:bt/2,color:e,attenuation:x=>x*x,target:a,children:n.jsxs("mesh",{ref:a,position:d,castShadow:!0,children:[n.jsx("sphereGeometry",{args:[ge,s==="high"?32:16,s==="high"?32:16]}),n.jsx("meshPhysicalMaterial",{color:e,emissive:e,emissiveIntensity:i?1.2:.4,roughness:.08,metalness:.85,clearcoat:1,clearcoatRoughness:.03,envMapIntensity:2.5})]})}),s==="low"&&n.jsxs("mesh",{ref:a,position:d,children:[n.jsx("sphereGeometry",{args:[ge,16,16]}),n.jsx("meshStandardMaterial",{color:e,emissive:e,emissiveIntensity:.5,roughness:.2,metalness:.5})]}),s!=="low"&&n.jsxs("mesh",{ref:r,position:d,children:[n.jsx("sphereGeometry",{args:[ge*4,16,16]}),n.jsx("meshBasicMaterial",{color:e,transparent:!0,opacity:.08,blending:ce,depthWrite:!1})]}),s!=="low"&&n.jsx("pointLight",{ref:o,color:e,intensity:i?2.5:1,distance:5,decay:2}),t&&t.length>2&&n.jsx(Fn,{path:t,isDark:i})]})}function Fn({path:t,isDark:e}){const{geometry:s}=p.useMemo(()=>{if(t.length<2)return{geometry:null};const i=[],a=[];for(let o=0;o<t.length;o++){const l=t[o];i.push(new k(l.x,l.y+.03,l.z));const c=o/(t.length-1),[u,m,h]=Lt(c);a.push(u,m,h)}const r=new Ce().setFromPoints(i);return r.setAttribute("color",new cn(a,3)),{geometry:r}},[t]);return s?n.jsx("line",{geometry:s,children:n.jsx("lineBasicMaterial",{vertexColors:!0,transparent:!0,opacity:e?.9:.65,linewidth:1})}):null}function Gn({position:t,surfaceY:e}){const s=p.useRef(),i=p.useRef(),a=p.useRef(),r=p.useRef(),o=p.useRef();te(({clock:c})=>{const u=c.getElapsedTime();if(s.current){const m=1+.25*Math.sin(u*2.5);s.current.scale.set(m,m,m),s.current.rotation.y=u*.4}if(i.current){const m=1+.15*Math.sin(u*3.5+1);i.current.scale.set(m,m,m),i.current.rotation.y=-u*.6}a.current&&(a.current.material.emissiveIntensity=.8+.5*Math.sin(u*3),a.current.material.opacity=.35+.2*Math.sin(u*2)),r.current&&(r.current.intensity=2.5+1.5*Math.sin(u*2.5)),o.current&&(o.current.material.opacity=.35+.15*Math.sin(u*1.5))});const l=(e||0)+.05;return n.jsxs("group",{position:[t[0],l,t[1]],children:[n.jsxs("mesh",{ref:s,rotation:[-Math.PI/2,0,0],children:[n.jsx("torusGeometry",{args:[.55,.045,16,48]}),n.jsx("meshStandardMaterial",{color:S.targetGold,emissive:S.targetGold,emissiveIntensity:1.2,roughness:.15,metalness:.9})]}),n.jsxs("mesh",{ref:i,rotation:[-Math.PI/2,0,0],position:[0,.02,0],children:[n.jsx("torusGeometry",{args:[.32,.025,12,36]}),n.jsx("meshStandardMaterial",{color:S.targetGlow,emissive:S.targetGlow,emissiveIntensity:1,roughness:.2,metalness:.8,transparent:!0,opacity:.85})]}),n.jsxs("mesh",{ref:a,rotation:[-Math.PI/2,0,0],position:[0,-.01,0],children:[n.jsx("circleGeometry",{args:[.7,32]}),n.jsx("meshStandardMaterial",{color:S.targetGold,emissive:S.targetGlow,emissiveIntensity:.8,transparent:!0,opacity:.35,side:ye})]}),n.jsxs("mesh",{ref:o,position:[0,2,0],children:[n.jsx("cylinderGeometry",{args:[.01,.12,4,8]}),n.jsx("meshStandardMaterial",{color:S.targetGold,emissive:S.targetGold,emissiveIntensity:1.2,transparent:!0,opacity:.35})]}),n.jsx("pointLight",{ref:r,color:S.targetGold,intensity:2.5,distance:8,decay:2,position:[0,.5,0]})]})}function Bn({level:t,isDark:e,quality:s}){const i=p.useRef(),a=s==="low"||!t,[r,o]=a?[0,0]:t.bounds,l=s==="high"?1:2,c=a?0:Math.floor((o-r)/l)+1;return te(({clock:u})=>
115{if(!i.current||a)return;const m=u.getElapsedTime();i.current.children.forEach((h,d)=>{if(h.material){const x=Math.sin(m*1.8+d*.25);h.material.opacity=e?.14+.08*x:.1+.06*x}})}),a?null:n.jsxs("group",{ref:i,children:[Array.from({length:c},(u,m)=>{const h=r+m*l;return n.jsx(Tt,{level:t,start:[r,h],end:[o,h],isDark:e,segments:s==="high"?64:32},`x-${m}`)}),Array.from({length:c},(u,m)=>{const h=r+m*l;return n.jsx(Tt,{level:t,start:[h,r],end:[h,o],isDark:e,isZDir:!0,segments:s==="high"?64:32},`z-${m}`)})]})}function Tt({level:t,start:e,end:s,isDark:i,isZDir:a,segments:r}){const o=p.useMemo(()=>{const l=[];for(let c=0;c<=r;c++){const u=c/r;let m,h;a?(m=e[0],h=e[1]+(s[1]-e[1])*u):(m=e[0]+(s[0]-e[0])*u,h=e[1]);const d=q(t.fn(m,h))+.015;l.push(new k(m,d,h))}return new Ce().setFromPoints(l)},[t,e,s,a,r]);return n.jsx("line",{geometry:o,children:n.jsx("lineBasicMaterial",{color:i?"#60a5fa":"#3b82f6",transparent:!0,opacity:i?.14:.1,linewidth:1})})}function Ln({position:t,color:e,surfaceY:s}){const i=p.useRef(),a=p.useRef(),r=p.useRef(),o=p.useRef(),l=p.useRef();return te(({clock:c})=>{const u=c.getElapsedTime();if(a.current&&(a.current.rotation.z=u*2),r.current&&(r.current.rotation.z=-u*1.5,r.current.scale.setScalar(1+.12*Math.sin(u*3))),o.current&&(o.current.rotation.z=u*3,o.current.scale.setScalar(1+.08*Math.sin(u*4+1))),i.current){i.current.position.y=(s||0)+.2+.1*Math.sin(u*3.5);const m=1+.05*Math.sin(u*2);i.current.scale.set(m,m,m)}l.current&&(l.current.intensity=1.5+.5*Math.sin(u*3))}),t?n.jsxs("group",{ref:i,position:[t[0],(s||0)+.2,t[1]],children:[n.jsxs("mesh",{ref:a,rotation:[-Math.PI/2,0,0],children:[n.jsx("torusGeometry",{args:[.38,.022,8,32]}),n.jsx("meshStandardMaterial",{color:e,emissive:e,emissiveIntensity:.8,transparent:!0,opacity:.8})]}),n.jsxs("mesh",{ref:r,rotation:[-Math.PI/2,0,0],children:[n.jsx("torusGeometry",{args:[.2,.018,8,24]}),n.jsx("meshStandardMaterial",{color:e,emissive:e,emissiveIntensity:1,transparent:!0,opacity:.85})]}),n.jsxs("mesh",{ref:o,rotation:[-Math.PI/2,0,0],children:[n.jsx("torusGeometry",{args:[.1,.012,8,20]}),n.jsx("meshStandardMaterial",{color:e,emissive:e,emissiveIntensity:1.2,transparent:!0,opacity:.9})]}),n.jsxs("mesh",{rotation:[-Math.PI/2,0,0],children:[n.jsx("circleGeometry",{args:[.04,16]}),n.jsx("meshStandardMaterial",{color:e,emissive:e,emissiveIntensity:1.5,side:ye})]}),n.jsxs("mesh",{position:[0,1.2,0],children:[n.jsx("cylinderGeometry",{args:[.003,.008,2.4,4]}),n.jsx("meshStandardMaterial",{color:e,emissive:e,emissiveIntensity:1.2,transparent:!0,opacity:.55})]}),n.jsx("pointLight",{ref:l,color:e,intensity:1.5,distance:3,decay:2})]}):null}function At(t,e,s,i,a){const r=new Float32Array(t*3),o=new Float32Array(t*3),l=new Float32Array(t*3);for(let c=0;c<t;c++){r[c*3]=0,r[c*3+1]=0,r[c*3+2]=0;const u=Math.random()*Math.PI*2,m=Math.random()*Math.PI*.55,h=e+Math.random()*(s-e);o[c*3]=h*Math.sin(m)*Math.cos(u),o[c*3+1]=h*Math.cos(m)+i,o[c*3+2]=h*Math.sin(m)*Math.sin(u);const d=a[Math.floor(Math.random()*a.length)];l[c*3]=d.r,l[c*3+1]=d.g,l[c*3+2]=d.b}return{positions:r,velocities:o,colors:l}}function kn({position:t,quality:e,color:s}){const i=p.useRef(),a=p.useRef(),r=p.useRef(),o=p.useRef(),l=p.useRef(),c=p.useRef(),u=p.useRef(null),[m,h]=p.useState(!0),d=e==="high"?St:e==="medium"?jt:0,x=e==="high"?Math.floor(St*.6):e==="medium"?Math.floor(jt*.5):0,v=e==="high"?40:e==="medium"?20:0,R=p.useMemo(()=>[new U(S.victoryGold),new U("#ffe066"),new U(s||S.targetGold),new U("#ffffff"),new U("#ffa500")],[s]),M=p.useMemo(()=>At(d,3,8,2.5,R),[d,R]),y=p.useMemo(()=>At(x,2,5,4,R),[x,R]),b=p.useMemo(()=>{const I=new Float32Array(v*3),f=new Float32Array(v*3),G=new Float32Array(v*3);for(let j=0;j<v;j++){I[j*3]=(Math.random()-.5)*2,I[j*3+1]=0,I[j*3+2]=(Math.random()-.5)*2,f[j*3]=(Math.random()-.5)*.5,f[j*3+1]=1.5+Math.random()*2,f[j*3+2]=(Math.random()-.5)*.5;const _=Math.random()<.6?new U(S.targetGold):new U("#ffe066");G[j*3]=_.r,G[j*3+1]=_.g,G[j*3+2]=_.b}return{positions:I,velocities:f,colors:G}},[v]);if(te(({clock:I})=>{if(!m)return;u.current===null&&(u.current=I.getElapsedTime());const f=(I.getElapsedTime()-u.current)*1e3,G=f/(Ye*1.2);if(G>1){h(!1);return}const j=f/1e3,_=-7;if(d>0&&i.current){const T=i.current.geometry.attributes.position;for(let z=0;z<d;z++)T.array[z*3]=M.velocities[z*3]*j,T.array[z*3+1]=M.velocities[z*3+1]*j+.5*_*j*j,T.array[z*3+2]=M.velocities[z*3+2]*j;T.needsUpdate=!0,i.current.material.opacity=Math.max(0,1-G*G),i.current.material.size=.12+.06*Math.sin(f*.012)}if(x>0&&a.current&&f>350){const T=(f-350)/1e3,z=a.current.geometry.attributes.position;for(let W=0;W<x;W++)z.array[W*3]=y.velocities[W*3]*T,z.array[W*3+1]=y.velocities[W*3+1]*T+.5*(_*.7)*T*T,z.array[W*3+2]=y.velocities[W*3+2]*T;z.needsUpdate=!0;const $=Math.max(0,(f-350)/(Ye*.8));
115a.current.material.opacity=Math.max(0,.9-$*$),a.current.material.size=.08+.04*Math.sin(f*.015)}if(v>0&&r.current&&f>200){const T=(f-200)/1e3,z=r.current.geometry.attributes.position;for(let C=0;C<v;C++){const ue=Math.sin(T*2+C*.7)*.3,de=Math.cos(T*1.5+C*1.1)*.3;z.array[C*3]=b.positions[C*3]+b.velocities[C*3]*T+ue,z.array[C*3+1]=b.velocities[C*3+1]*T,z.array[C*3+2]=b.positions[C*3+2]+b.velocities[C*3+2]*T+de}z.needsUpdate=!0;const $=Math.max(0,(f-200)/(Ye*1.1)),W=.7+.3*Math.sin(f*.02);r.current.material.opacity=Math.max(0,W*(1-$)),r.current.material.size=.06+.04*Math.sin(f*.008)}if(o.current){const T=Math.min(1,f/600),z=.1+T*5;o.current.scale.set(z,z,1),o.current.material.opacity=Math.max(0,.8*(1-T))}if(l.current){const T=Math.max(0,f-150),z=Math.min(1,T/900),$=.1+z*8;l.current.scale.set($,$,1),l.current.material.opacity=Math.max(0,.5*(1-z))}if(c.current){const T=Math.max(0,1-f/350);c.current.intensity=20*T*T}}),!m)return e==="low"?n.jsx("pointLight",{position:[t[0],(t[2]||0)+2,t[1]],color:S.targetGold,intensity:12,distance:15,decay:2}):null;const A=t[2]!=null?t[2]:0;return n.jsxs("group",{position:[t[0],A+.3,t[1]],children:[d>0&&n.jsxs("points",{ref:i,children:[n.jsxs("bufferGeometry",{children:[n.jsx("bufferAttribute",{attach:"attributes-position",count:d,array:M.positions,itemSize:3}),n.jsx("bufferAttribute",{attach:"attributes-color",count:d,array:M.colors,itemSize:3})]}),n.jsx("pointsMaterial",{vertexColors:!0,size:.12,transparent:!0,opacity:1,sizeAttenuation:!0,depthWrite:!1,blending:ce})]}),x>0&&n.jsxs("points",{ref:a,children:[n.jsxs("bufferGeometry",{children:[n.jsx("bufferAttribute",{attach:"attributes-position",count:x,array:y.positions,itemSize:3}),n.jsx("bufferAttribute",{attach:"attributes-color",count:x,array:y.colors,itemSize:3})]}),n.jsx("pointsMaterial",{vertexColors:!0,size:.08,transparent:!0,opacity:0,sizeAttenuation:!0,depthWrite:!1,blending:ce})]}),v>0&&n.jsxs("points",{ref:r,children:[n.jsxs("bufferGeometry",{children:[n.jsx("bufferAttribute",{attach:"attributes-position",count:v,array:b.positions,itemSize:3}),n.jsx("bufferAttribute",{attach:"attributes-color",count:v,array:b.colors,itemSize:3})]}),n.jsx("pointsMaterial",{vertexColors:!0,size:.06,transparent:!0,opacity:0,sizeAttenuation:!0,depthWrite:!1,blending:ce})]}),n.jsxs("mesh",{ref:o,rotation:[-Math.PI/2,0,0],children:[n.jsx("torusGeometry",{args:[1,.05,8,64]}),n.jsx("meshBasicMaterial",{color:S.targetGold,transparent:!0,opacity:.8,side:ye,blending:ce})]}),n.jsxs("mesh",{ref:l,rotation:[-Math.PI/2,0,0],children:[n.jsx("torusGeometry",{args:[1,.03,8,64]}),n.jsx("meshBasicMaterial",{color:"#ffffff",transparent:!0,opacity:.5,side:ye,blending:ce})]}),n.jsx("pointLight",{ref:c,color:"#fff8e0",intensity:20,distance:25,decay:2}),n.jsx("pointLight",{color:S.targetGold,intensity:5,distance:12,decay:2})]})}const Ae=typeof window<"u"?window.matchMedia("(prefers-reduced-motion: reduce)").matches:!1;function Pn(t){return t<.5?4*t*t*t:1-Math.pow(-2*t+2,3)/2}function Wn(t){return 1-Math.pow(1-t,4)}function Vn({controlsRef:t,gamePhase:e,level:s,levelIndex:i,ballPath:a,cameraMode:r,onCinematicDone:o}){const{camera:l}=qe(),c=p.useRef({mode:null,startTime:0,duration:0,startAngle:0,endAngle:0,orbitRadius:0,orbitHeight:0,startPos:new k,endPos:new k,startTarget:new k,endTarget:new k,startFov:45,endFov:45});p.useRef(i);const u=p.useRef(o);return u.current=o,p.useEffect(()=>{var b;if(r!=="intro"||Ae){if(r==="intro"&&Ae){const A=(s==null?void 0:s.cameraPosition)||[8,12,8];l.position.set(A[0],A[1],A[2]),l.fov=50,l.updateProjectionMatrix(),t.current&&(t.current.target.set(0,-2.5,0),t.current.update()),(b=u.current)==null||b.call(u)}return}const m=(s==null?void 0:s.cameraPosition)||[8,12,8],h=0,d=0,x=m[0]-h,v=m[2]-d,R=Math.sqrt(x*x+v*v),M=Math.atan2(v,x),y=M+Math.PI*.88;c.current={mode:"intro",startTime:-1,duration:2.4,startAngle:y,endAngle:M,orbitRadius:R,orbitHeight:m[1]+3,endHeight:m[1],startPos:new k,endPos:new k(m[0],m[1],m[2]),startTarget:new k(0,-2.5,0),endTarget:new k(0,-2.5,0),startFov:60,endFov:50},t.current&&(t.current.enabled=!1)},[r,s,l,t,i]),p.useEffect(()=>{var R,M,y;if(r!=="victory"||Ae){r==="victory"&&Ae&&((R=u.current)==null||R.call(u));return}const m=((M=s==null?void 0:s.globalMin)==null?void 0:M[0])||0,h=((y=s==null?void 0:s.globalMin)==null?void 0:y[1])||0,d=l.position.clone(),x=new k(m,0,h).sub(new k(d.x,0,d.z)).normalize(),v=new k(m-x.x*4,d.y*.6+2,h-x.z*4);c.current={mode:"victory",startTime:-1,duration:1.6,startAngle:0,endAngle:0,orbitRadius:0,orbitHeight:0,startPos:d.clone(),endPos:v,startTarget:t.current?t.current.target.clone():new k(0,-2.5,0),endTarget:new k(m,-2,h),startFov:l.fov,endFov:42},t.current&&(t.current.enabled=!1)},[r,s,l,t]),te((m,h)=>{var R,M;const d=c.current;if(!d.mode)return;d.startTime<0&&(d.startTime=m.clock.getElapsedTime());const x=m.clock.getElapsedTime()-d.startTime,v=Math.min(1,x/d.duration);if(d.mode==="intro"){const y=Pn(v),b=d.startAngle+(d.endAngle-d.startAngle)*y,A=d.orbitHeight+(d.endHeight-d.orbitHeight)*y,I=Math.cos(b)*d.orbitRadius,f=Math.sin(b)*d.orbitRadius;l.position.set(I,A,f),l.lookAt(d.endTarget.x,d.endTarget.y,d.endTarget.z),l.fov=d.startFov+(d.endFov-d.startFov)*y,l.updateProjectionMatrix(),v>=1&&(l.position.copy(d.endPos),l.fov=d.endFov,l.updateProjectionMatrix(),t.current&&(t.current.target.copy(d.endTarget),t.current.enabled=!0,t.current.update(
115)),d.mode=null,(R=u.current)==null||R.call(u))}if(d.mode==="victory"){const y=Wn(v);l.position.lerpVectors(d.startPos,d.endPos,y);const b=new k().lerpVectors(d.startTarget,d.endTarget,y);l.lookAt(b.x,b.y,b.z),l.fov=d.startFov+(d.endFov-d.startFov)*y,l.updateProjectionMatrix(),t.current&&(t.current.target.copy(b),t.current.update()),v>=1&&(t.current&&(t.current.enabled=!0),d.mode=null,(M=u.current)==null||M.call(u))}}),null}function En({level:t,levelIndex:e,gamePhase:s,dropPoint:i,ballPath:a,quality:r,isDark:o,trackColor:l,onSurfaceClick:c,onSurfaceHover:u,hoverPoint:m,prefersReducedMotion:h,demoPath:d,cameraMode:x,onCinematicDone:v}){const R=p.useRef(),M=p.useCallback(j=>{if(s!=="placing")return;j.stopPropagation();const _=j.point;u({x:_.x,z:_.z})},[s,u]),y=p.useCallback(j=>{if(s!=="placing")return;j.stopPropagation();const _=j.point;c({x:_.x,z:_.z})},[s,c]),b=p.useMemo(()=>t?q(t.fn(t.globalMin[0],t.globalMin[1])):0,[t]),A=p.useMemo(()=>!t||!m?0:q(t.fn(m.x,m.z)),[t,m]),{t:I}=re("pages"),f=o?zn:Rn,G=(t==null?void 0:t.cameraPosition)||[8,12,8];return n.jsxs(pn,{camera:{position:G,fov:50,near:.1,far:100},dpr:r==="low"?1:r==="medium"?[1,1.5]:[1,2],gl:{antialias:r!=="low",alpha:!1,powerPreference:"high-performance"},shadows:r==="high",style:{width:"100%",height:"100%",borderRadius:16,cursor:s==="placing"?"crosshair":"grab"},role:"application","aria-label":I("games_gd.scene_aria"),children:[n.jsx("color",{attach:"background",args:[f]}),n.jsx("fog",{attach:"fog",args:[f,25,50]}),n.jsx("ambientLight",{intensity:o?.35:.5}),n.jsx("directionalLight",{position:[10,15,5],intensity:o?1:1.2,castShadow:r==="high","shadow-mapSize-width":1024,"shadow-mapSize-height":1024,"shadow-camera-far":30,"shadow-camera-left":-10,"shadow-camera-right":10,"shadow-camera-top":10,"shadow-camera-bottom":-10}),n.jsx("directionalLight",{position:[-5,8,-5],intensity:o?.3:.2,color:o?"#4060ff":"#aaccff"}),r!=="low"&&n.jsx(dn,{preset:o?"night":"apartment"}),n.jsxs("group",{position:[0,-2,0],children:[n.jsx(In,{level:t,isDark:o,quality:r,onPointerMove:M,onClick:y}),!h&&n.jsx(Bn,{level:t,isDark:o,quality:r}),n.jsx(Gn,{position:t.globalMin,surfaceY:b}),s==="placing"&&m&&n.jsx(Ln,{position:{0:m.x,1:m.z},color:l,surfaceY:A}),(s==="running"||s==="victory"||s==="failed")&&a.length>0&&n.jsx(_t,{path:a,color:l,quality:r,isDark:o}),s==="victory"&&n.jsx(kn,{position:t.globalMin,quality:r,color:l}),d&&d.length>1&&n.jsx(_t,{path:d,color:l,quality:r,isDark:o})]}),n.jsx(mn,{ref:R,enablePan:!1,minPolarAngle:Math.PI/8,maxPolarAngle:Math.PI/2.1,minDistance:4,maxDistance:20,target:[0,-2.5,0],enableDamping:!0,dampingFactor:.05}),n.jsx(Vn,{controlsRef:R,gamePhase:s,level:t,levelIndex:e,ballPath:a,cameraMode:x,onCinematicDone:v}),r==="high"&&!h&&n.jsxs(yt,{children:[n.jsx(vt,{luminanceThreshold:.5,luminanceSmoothing:.4,intensity:o?1.2:.6,radius:.6}),n.jsx(un,{darkness:o?.45:.2,offset:.3})]}),r==="medium"&&!h&&n.jsx(yt,{children:n.jsx(vt,{luminanceThreshold:.6,luminanceSmoothing:.3,intensity:o?.8:.4,radius:.4})})]})}const ee=typeof window<"u"?window.matchMedia("(prefers-reduced-motion: reduce)").matches:!1;function Rt({level:t,levelIndex:e,totalLevels:s,gamePhase:i,metrics:a,learningRate:r,setLearningRate:o,momentumVal:l,setMomentumVal:c,optimizerType:u,setOptimizerType:m,stars:h,bestScore:d,onReset:x,onNextLevel:v,isDark:R,trackColor:M,isMobile:y}){const{t:b}=re("pages"),A=C=>b(`games_gd.levels.${t.id}.${C}`,{defaultValue:t[C]}),[I,f]=p.useState(!1),G=p.useRef(null);p.useEffect(()=>(i==="running"&&a.steps>30&&a.gradMag<.1?G.current=setTimeout(()=>f(!0),2e3):f(!1),()=>{G.current&&clearTimeout(G.current)}),[i,a.steps,a.gradMag]);const j=R?S.glassBgDark:S.glassBgLight,_=R?S.glassBorderDark:S.glassBorderLight,T={background:j,backdropFilter:"blur(16px)",WebkitBackdropFilter:"blur(16px)",border:`1px solid ${_}`,borderRadius:12,padding:"clamp(8px, 2vw, 12px)",boxShadow:R?"0 4px 16px rgba(0,0,0,0.3)":"0 4px 16px rgba(0,0,0,0.06)"},z=t.availableOptimizers.includes("momentum")||t.availableOptimizers.includes("adam"),$=a.loss!=null?a.loss<.5?"var(--color-success)":a.loss<2?S.targetGold:a.loss<5?"#f97316":"var(--color-error)":w.text,W=a.gradMag!=null?a.gradMag>1?"var(--color-success)":a.gradMag>.1?S.targetGold:"var(--color-error)":w.text;return n.jsxs("div",{style:{position:y?"relative":"absolute",top:y?"auto":"clamp(8px, 2vw, 14px)",right:y?"auto":"clamp(8px, 2vw, 14px)",width:y?"100%":"clamp(240px, 20vw, 280px)",maxHeight:y?"none":"calc(100vh - 100px)",overflowY:"auto",zIndex:10,display:"flex",flexDirection:"column",gap:"clamp(4px, 1vw, 6px)"},children:[n.jsx("div",{style:T,children:n.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[n.jsxs("div",{style:{minWidth:0},children:[n.jsx("div",{style:{fontSize:"clamp(9px, 2vw, 10px)",fontWeight:600,color:M,textTransform:"uppercase",letterSpacing:"0.05em"},children:b("games_gd.hud.level",{n:e+1,total:s})}),n.jsxs("div",{style:{fontSize:"clamp(13px, 3vw, 16px)",fontWeight:700,color:w.text,lineHeight:1.2,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:[t.icon," ",A("title")]})]}),n.jsx("div",{style:{display:"flex",gap:1,flexShrink:0},children:[1,2,3].map(C=>n.jsx("span",{style:{fontSize:"clamp(12px, 2.8vw, 14px)",opacity:h[e]>=C?1:.2,filter:h[e]>=C?"none":"grayscale(1)"},children:"â"},C))})]})}),(i==="running"||i==="victory"||i==="failed")&&n.jsxs("div",{style:T,children:[n.jsxs("div",{style:{display:"flex",gap:"clamp(4px, 1vw, 6px)",justifyContent:"space-between"},children:[n.jsx(De,{label:b("games_gd.hud.loss"),isLoss:!0,value:a.loss!=null?a.loss.toFixed(3):"-",color:$,highlight:a.loss!=null&&a.loss<.5}),n.jsx(De,{label:b("games_gd.hud.grad"),value:a.gradMag!=null?a.gradMag.toFixed(3):"-",color:W}),n.jsx(De,{label:b("games_gd.hud.steps"),value:a.steps||0,color:w.text,subValue:d?b("games_gd.hud.best",{steps:d.steps}):null})]}),a.loss!=null&&n.jsx("div",{style:{marginTop:"clamp(4px, 1vw, 6px)",height:3,borderRadius:2,background:R?"rgba(255,255,255,0.06)":"rgba(0,0,0,0.05)",overflow:"hidden"},children:n.jsx("div",{style:{height:"100%",borderRadius:2,width:`${Math.max(2,Math.min(100,(1-Math.min(1,a.loss/5))*100))}%`,background:"linear-gradient(90deg, #ef4444, #f59e0b, #22c55e)",transition:ee?"none":"width 0.15s ease-out"}})})]}),n.jsxs("div",{style:T,children:[n.jsxs("div",{style:{marginBottom:"clamp(4px, 1vw, 6px)"},children:[n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:2},children:[n.jsx("label",{style:{fontSize:"clamp(10px, 2.2vw, 11px)",fontWeight:600,color:w.text},children:b("games_gd.hud.learning_rate")}),n.jsx("span",{style:{fontSize:"clamp(10px, 2.2vw, 12px)",fontWeight:700,color:M,fontFamily:"var(--font-code)"},children:r.toFixed(3)})]}),n.jsx("input",{type:"range",min:"0.001",max:"1",step:"0.001",value:r,onChange:C=>o(parseFloat(C.target.value)),disabled:i==="running",style:{width:"100%",accentColor:M,minHeight:44,touchAction:"manipulation"},"aria-label":b("games_gd.hud.learning_rate_aria")})]}),n.jsxs("div",{style:{marginBottom:"clamp(4px, 1vw, 6px)",opacity:z?1:.35},children:[n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:2},children:[n.jsxs("label",{style:{fontSize:"clamp(10px, 2.2vw, 11px)",fontWeight:600,color:w.text},children:[b("games_gd.hud.momentum")," ",!z&&"ð"]}),n.jsx("span",{style:{fontSize:"clamp(10px, 2.2vw, 12px)",fontWeight:700,color:z?M:w.textMuted,fontFamily:"var(--font-code)"},children:z?l.toFixed(2):"-"})]}),n.jsx("input",{type:"range",min:"0",max:"0.99",step:"0.01",value:z?l:0,onChange:C=>c(parseFloat(C.target.value)),disabled:i==="running"||!z,style:{width:"100%",accentColor:z?M:w.textMuted,minHeight:44,touchAction:"manipulation",cursor:z?void 0:"not-allowed"},"aria-label":b("games_gd.hud.momentum_aria")}),!z&&n.jsx("div",{style:{fontSize:"clamp(8px, 1.8vw, 9px)",color:w.textMuted,fontStyle:"italic"},children:b("games_gd.hud.unlocked")})]}),n.jsxs("div",{style:{borderTop:`1px solid ${_}`,paddingTop:"clamp(4px, 1vw, 6px)",marginTop:"clamp(2px, 0.5vw, 4px)"},children:[n.jsx("div",{style:{fontSize:"clamp(10px, 2.2vw, 11px)",fontWeight:600,color:w.text,marginBottom:"clamp(4px, 1vw, 6px)"},children:b("games_gd.hud.optimizer")}),n.jsx("div",{style:{display:"flex",gap:"clamp(3px, 0.8vw, 4px)",flexWrap:"wrap"}
115,children:t.availableOptimizers.map(C=>n.jsx("button",{onClick:()=>m(C),disabled:i==="running",style:{padding:"clamp(4px, 1vw, 6px) clamp(8px, 2vw, 10px)",borderRadius:6,border:`2px solid ${u===C?M:w.border}`,background:u===C?pe(M):"transparent",color:u===C?"white":w.text,boxShadow:u===C?`0 0 12px ${M}50`:"none",fontWeight:600,fontSize:"clamp(9px, 2vw, 11px)",cursor:i==="running"?"not-allowed":"pointer",minHeight:32,transition:ee?"none":"all 0.2s ease-out",opacity:i==="running"?.5:1,fontFamily:"var(--font-code)"},"aria-pressed":u===C,children:C==="sgd"?"SGD":C==="momentum"?b("games_gd.hud.momentum"):"Adam"},C))})]}),n.jsxs("div",{style:{borderTop:`1px solid ${_}`,paddingTop:"clamp(4px, 1vw, 6px)",marginTop:"clamp(4px, 1vw, 6px)"},children:[i==="placing"&&n.jsx("div",{style:{fontSize:"clamp(10px, 2.2vw, 11px)",color:w.textSecondary,textAlign:"center",padding:"clamp(4px, 1vw, 6px)",lineHeight:1.4},children:A("hint")}),(i==="victory"||i==="failed")&&n.jsxs("div",{style:{display:"flex",gap:"clamp(4px, 1vw, 6px)"},children:[n.jsx("button",{onClick:x,style:{flex:1,padding:"clamp(6px, 1.5vw, 8px)",borderRadius:6,border:`2px solid ${w.border}`,background:"transparent",color:w.text,fontWeight:600,fontSize:"clamp(10px, 2.2vw, 11px)",cursor:"pointer",minHeight:36,transition:ee?"none":"all 0.2s ease-out"},children:b("games_gd.hud.try_again")}),i==="victory"&&e<s-1&&n.jsxs("button",{onClick:v,style:{flex:1,padding:"clamp(6px, 1.5vw, 8px)",borderRadius:6,border:`2px solid ${M}`,background:pe(M),color:"white",fontWeight:600,fontSize:"clamp(10px, 2.2vw, 11px)",cursor:"pointer",minHeight:36,transition:ee?"none":"all 0.2s ease-out"},children:[b("games_gd.hud.next")," ","â"]})]}),i==="running"&&n.jsx("button",{onClick:x,style:{width:"100%",padding:"clamp(6px, 1.5vw, 8px)",borderRadius:6,border:`2px solid ${w.border}`,background:"transparent",color:w.textSecondary,fontWeight:600,fontSize:"clamp(10px, 2.2vw, 11px)",cursor:"pointer",minHeight:36},children:b("games_gd.hud.stop_reset")})]})]}),I&&n.jsxs("div",{style:{...T,animation:ee?"none":"fadeSlideIn 0.3s ease-out"},children:[n.jsx("div",{style:{fontSize:"clamp(9px, 2vw, 10px)",fontWeight:600,color:S.targetGold,marginBottom:2,textTransform:"uppercase",letterSpacing:"0.05em"},children:b("games_gd.hud.tip")}),n.jsx("div",{style:{fontSize:"clamp(10px, 2.2vw, 11px)",color:w.textSecondary,lineHeight:1.4},children:a.gradMag<.01?b("games_gd.hud.tip_zero"):b("games_gd.hud.tip_slow")})]}),!ee&&n.jsx("style",{children:` 116 @keyframes fadeSlideIn { 117 from { opacity: 0; transform: translateY(6px); } 118 to { opacity: 1; transform: translateY(0); } 119 } 120 `})]})}function De({label:t,value:e,color:s,highlight:i,subValue:a,isLoss:r}){const o=p.useRef(e),[l,c]=p.useState(!1),[u,m]=p.useState(null);return p.useEffect(()=>{if(o.current!==e){const h=parseFloat(o.current),d=parseFloat(e);if(!isNaN(h)&&!isNaN(d)&&r){m(d<h?"down":"up");const x=setTimeout(()=>m(null),300);return o.current=e,()=>clearTimeout(x)}if(i){c(!0);const x=setTimeout(()=>c(!1),400);return o.current=e,()=>clearTimeout(x)}o.current=e}},[e,i,r]),n.jsxs("div",{style:{flex:1,textAlign:"center",padding:"clamp(3px, 0.8vw, 4px)",transition:ee?"none":"transform 0.15s ease-out",transform:l?"scale(1.08)":"scale(1)",borderRadius:6,background:u==="down"?"rgba(34,197,94,0.08)":u==="up"?"rgba(239,68,68,0.08)":"transparent"},children:[n.jsx("div",{style:{fontSize:"clamp(8px, 1.8vw, 9px)",fontWeight:500,color:w.textMuted,textTransform:"uppercase",letterSpacing:"0.04em"},children:t}),n.jsx("div",{style:{fontSize:"clamp(11px, 2.5vw, 13px)",fontWeight:700,color:s,fontFamily:"var(--font-code)",transition:ee?"none":"color 0.2s ease-out"},children:e}),a&&n.jsx("div",{style:{fontSize:"clamp(7px, 1.5vw, 8px)",fontWeight:500,color:w.textMuted,fontFamily:"var(--font-code)",marginTop:1},children:a})]})}const On=typeof window<"u"?window.matchMedia("(prefers-reduced-motion: reduce)").matches:!1;function $n({currentLevel:t,unlockedLevel:e,stars:s,onSelect:i,isDark:a,trackColor:r}){const{t:o}=re("pages");p.useEffect(()=>{const u=m=>{if(m.target.tagName==="INPUT"||m.target.tagName==="TEXTAREA")return;const h=parseInt(m.key,10);h>=1&&h<=P.length&&h-1<=e&&i(h-1)};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[e,i]);const l=a?S.glassBgDark:S.glassBgLight,c=a?S.glassBorderDark:S.glassBorderLight;return n.jsx("div",{style:{display:"flex",gap:"clamp(4px, 1vw, 8px)",padding:"clamp(6px, 1.5vw, 10px)",background:l,backdropFilter:"blur(12px)",WebkitBackdropFilter:"blur(12px)",border:`1px solid ${c}`,borderRadius:12,overflowX:"auto",WebkitOverflowScrolling:"touch"},children:P.map((u,m)=>{const h=m>e,d=m===t,x=s[m]||0;return n.jsxs("button",{onClick:()=>!h&&i(m),disabled:h,style:{flex:"0 0 auto",display:"flex",flexDirection:"column",alignItems:"center",gap:"clamp(2px, 0.5vw, 4px)",padding:"clamp(6px, 1.5vw, 10px) clamp(8px, 2vw, 14px)",borderRadius:10,border:`2px solid ${d?r:"transparent"}`,background:d?a?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.04)":"transparent",curs
120or:h?"not-allowed":"pointer",opacity:h?.4:1,minWidth:"clamp(52px, 13vw, 68px)",minHeight:44,transition:On?"none":"border-color 0.2s ease-out, background 0.2s ease-out, box-shadow 0.2s ease-out, transform 0.15s ease-out",fontFamily:"inherit",color:"inherit"},onMouseEnter:v=>{!h&&!d&&(v.currentTarget.style.transform="scale(1.08)",v.currentTarget.style.boxShadow=`0 0 14px ${r}30`)},onMouseLeave:v=>{v.currentTarget.style.transform="scale(1)",v.currentTarget.style.boxShadow="none"},"aria-label":o(h?"games_gd.level_select.aria_locked":"games_gd.level_select.aria",{n:m+1,title:o(`games_gd.levels.${u.id}.title`,{defaultValue:u.title})}),"aria-pressed":d,children:[n.jsx("span",{style:{fontSize:"clamp(16px, 3.5vw, 20px)",filter:h?"grayscale(1)":"none"},children:h?"ð":u.icon}),n.jsx("span",{style:{fontSize:"clamp(9px, 2vw, 10px)",fontWeight:600,color:d?r:w.textMuted,whiteSpace:"nowrap"},children:m+1}),!h&&n.jsx("div",{style:{display:"flex",gap:1},children:[1,2,3].map(v=>n.jsx("span",{style:{fontSize:"clamp(8px, 1.8vw, 10px)",opacity:x>=v?1:.2,filter:x>=v?"none":"grayscale(1)"},children:"â"},v))})]},u.id)})})}const xe=typeof window<"u"?window.matchMedia("(prefers-reduced-motion: reduce)").matches:!1;function Hn({level:t,gamePhase:e,failReason:s,steps:i,starsEarned:a,isDark:r,trackColor:o,onDismiss:l,isLastLevel:c,onShowGameSummary:u,onLearnMore:m}){const{t:h}=re("pages");if(e!=="victory"&&e!=="failed")return null;const d=y=>h(`games_gd.levels.${t.id}.${y}`,{defaultValue:t[y]}),x=e==="victory",v=d(x?"explanationSuccess":s==="stuck"?"explanationStuck":"explanationFail"),R=r?S.glassBgDark:S.glassBgLight,M=r?S.glassBorderDark:S.glassBorderLight;return n.jsxs("div",{style:{position:"absolute",bottom:"clamp(12px, 3vw, 20px)",left:"50%",transform:"translateX(-50%)",width:"clamp(280px, 60vw, 500px)",zIndex:20,background:R,backdropFilter:"blur(16px)",WebkitBackdropFilter:"blur(16px)",border:`1px solid ${M}`,borderRadius:16,padding:"clamp(16px, 4vw, 24px)",boxShadow:r?"0 12px 40px rgba(0,0,0,0.5)":"0 12px 40px rgba(0,0,0,0.12)",animation:xe?"none":"explainerSlideUp 0.4s ease-out"},children:[n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"clamp(8px, 2vw, 12px)",marginBottom:"clamp(10px, 2.5vw, 16px)"},children:[n.jsx("span",{style:{fontSize:"clamp(24px, 5vw, 32px)"},children:x?"ð":s==="stuck"?"ð¤":"ð¥"}),n.jsxs("div",{children:[n.jsx("div",{style:{fontSize:"clamp(16px, 3.5vw, 20px)",fontWeight:700,color:x?"var(--color-success)":"var(--color-error)"},children:h(x?"games_gd.explainer.found":s==="stuck"?"games_gd.explainer.stuck":s==="diverged"?"games_gd.explainer.diverged":"games_gd.explainer.timeout")}),x&&n.jsxs("div",{style:{fontSize:"clamp(11px, 2.5vw, 13px)",color:w.textSecondary},children:[h("games_gd.explainer.reached",{steps:i})," "," ",[1,2,3].map(y=>n.jsx("span",{style:{opacity:a>=y?1:.2},children:"â"},y))]})]})]}),n.jsx("div",{style:{fontSize:"clamp(12px, 2.8vw, 14px)",color:w.textSecondary,lineHeight:1.6,marginBottom:"clamp(12px, 3vw, 16px)"},children:v}),n.jsxs("div",{style:{padding:"clamp(8px, 2vw, 12px)",borderRadius:8,background:r?"rgba(255,255,255,0.04)":"rgba(0,0,0,0.03)",border:`1px solid ${M}`,marginBottom:"clamp(10px, 2.5vw, 14px)"},children:[n.jsx("div",{style:{fontSize:"clamp(10px, 2.2vw, 11px)",fontWeight:600,color:o,textTransform:"uppercase",letterSpacing:"0.05em",marginBottom:4},children:h("games_gd.explainer.key_concept")}),n.jsx("div",{style:{fontSize:"clamp(13px, 3vw, 15px)",fontWeight:600,color:w.text},children:d("teachConcept")})]}),x&&t.learningSummary&&n.jsxs("div",{style:{padding:"clamp(8px, 2vw, 12px)",borderRadius:8,background:r?"rgba(59,130,246,0.08)":"rgba(59,130,246,0.06)",border:`1px solid ${r?"rgba(59,130,246,0.2)":"rgba(59,130,246,0.15)"}`,marginBottom:"clamp(10px, 2.5vw, 14px)"},children:[n.jsxs("div",{style:{fontSize:"clamp(10px, 2.2vw, 11px)",fontWeight:600,color:r?"#93c5fd":"#2563eb",textTransform:"uppercase",letterSpacing:"0.05em",marginBottom:"clamp(4px, 1vw, 6px)"},children:["ð"," ",h("games_gd.explainer.learned")]}),n.jsx("div",{style:{fontSize:"clamp(11px, 2.5vw, 13px)",color:w.textSecondary,lineHeight:1.55},children:d("learningSummary")}
120)]}),t.relatedModule&&m&&n.jsxs("button",{onClick:()=>m(t.relatedModule),style:{width:"100%",padding:"clamp(6px, 1.5vw, 8px)",marginBottom:"clamp(8px, 2vw, 10px)",borderRadius:6,border:"none",background:"transparent",color:o,fontWeight:600,fontSize:"clamp(11px, 2.5vw, 12px)",cursor:"pointer",textAlign:"center",transition:xe?"none":"opacity 0.2s ease-out"},children:["ð"," ",h("games_gd.explainer.learn_more",{title:t.relatedModule.title})," ","â"]}),n.jsxs("div",{style:{display:"flex",gap:"clamp(6px, 1.5vw, 8px)"},children:[n.jsx("button",{onClick:l,style:{flex:1,padding:"clamp(8px, 2vw, 10px)",borderRadius:8,border:"none",background:pe(o),color:"white",fontWeight:600,fontSize:"clamp(12px, 2.8vw, 14px)",cursor:"pointer",minHeight:44,transition:xe?"none":"all 0.2s ease-out"},children:h("games_gd.explainer.got_it")}),x&&c&&u&&n.jsxs("button",{onClick:u,style:{flex:1,padding:"clamp(8px, 2vw, 10px)",borderRadius:8,border:`2px solid ${S.targetGold}`,background:r?"rgba(251,191,36,0.15)":"rgba(251,191,36,0.1)",color:S.targetGold,fontWeight:700,fontSize:"clamp(12px, 2.8vw, 14px)",cursor:"pointer",minHeight:44,transition:xe?"none":"all 0.2s ease-out"},children:["ð"," ",h("games_gd.explainer.summary")]})]}),!xe&&n.jsx("style",{children:` 121 @keyframes explainerSlideUp { 122 from { opacity: 0; transform: translateX(-50%) translateY(20px); } 123 to { opacity: 1; transform: translateX(-50%) translateY(0); } 124 } 125 `})]})}const fe=typeof window<"u"?window.matchMedia("(prefers-reduced-motion: reduce)").matches:!1;function Un({onStart:t,isDark:e,trackColor:s}){const{t:i}=re("pages"),a=P.length,r=e?"rgba(var(--bg-card-rgb), 0.94)":"rgba(255, 255, 255, 0.96)",o=e?"rgba(148, 163, 184, 0.25)":"rgba(0, 0, 0, 0.1)",l=e?"rgba(255,255,255,0.05)":"rgba(0,0,0,0.03)",c=e?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.06)";return n.jsxs("div",{style:{position:"absolute",inset:0,zIndex:50,display:"flex",alignItems:"center",justifyContent:"center",background:e?"rgba(0, 0, 0, 0.3)":"rgba(0, 0, 0, 0.15)",animation:fe?"none":"welcomeFadeIn 0.4s ease-out"},children:[n.jsxs("div",{style:{position:"relative",maxWidth:440,width:"94%",maxHeight:"calc(100vh - 160px)",overflowY:"auto",padding:"clamp(14px, 3.5vw, 20px)",textAlign:"center",background:r,backdropFilter:"blur(20px)",WebkitBackdropFilter:"blur(20px)",border:`1px solid ${o}`,borderRadius:18,boxShadow:e?"0 16px 48px rgba(0, 0, 0, 0.5)":"0 16px 48px rgba(0, 0, 0, 0.15)",animation:fe?"none":"welcomeCardSlideUp 0.5s ease-out"},children:[n.jsx("button",{onClick:t,style:{position:"absolute",top:6,right:6,zIndex:52,width:32,height:32,borderRadius:"50%",border:"none",background:e?"rgba(255,255,255,0.1)":"rgba(0,0,0,0.06)",color:w.textMuted,fontSize:14,fontWeight:700,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",minHeight:44,minWidth:44,padding:0},"aria-label":i("games_gd.welcome.close"),children:"â"}),n.jsx("h1",{style:{fontSize:"clamp(18px, 4.5vw, 24px)",fontWeight:800,margin:"0 0 clamp(2px, 0.5vw, 4px)",lineHeight:1.2,color:w.text,letterSpacing:"-0.01em"},children:"Gradient Descent Explorer"}),n.jsx("p",{style:{fontSize:"clamp(11px, 2.5vw, 13px)",color:w.textSecondary,lineHeight:1.4,margin:"0 0 clamp(10px, 2.5vw, 14px)",fontWeight:500},children:i("games_gd.welcome.tagline")}),n.jsx("div",{style:{padding:"clamp(8px, 2vw, 10px)",borderRadius:10,background:l,border:`1px solid ${c}`,marginBottom:"clamp(8px, 2vw, 10px)",textAlign:"left"},children:n.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"clamp(4px, 1vw, 6px) clamp(10px, 2.5vw, 14px)",fontSize:"clamp(10px, 2.2vw, 11px)",lineHeight:1.5},children:[n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4},children:[n.jsx("span",{style:{fontSize:"clamp(12px, 2.8vw, 14px)"},children:"ðºï¸"}),n.jsxs("span",{children:[n.jsx("strong",{style:{color:w.text},children:i("games_gd.welcome.surface")})," ",n.jsx("span",{style:{color:w.textMuted},children:i("games_gd.welcome.surface_def")})]})]}),n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4},children:[n.jsx("span",{style:{fontSize:"clamp(12px, 2.8vw, 14px)"},children:"ð¡"}),n.jsxs("span",{children:[n.jsx("strong",{style:{color:w.text},children:i("games_gd.welcome.gold_ring")})," ",n.jsx("span",{style:{color:w.textMuted},children:i("games_gd.welcome.gold_ring_def")})]})]}),n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4},children:[n.jsx("span",{style:{width:14,height:14,borderRadius:"50%",background:"linear-gradient(135deg, #ef4444, #22c55e)",display:"inline-block",flexShrink:0}}),n.jsxs("span",{children:[n.jsx("strong",{style:{color:w.text},children:i("games_gd.welcome.ball")})," ",n.jsx("span",{style:{color:w.textMuted},children:i("games_gd.welcome.ball_def")})]})]}),n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4},children:[n.jsx("span",{style:{fontSize:"clamp(12px, 2.8vw, 14px)"},children:"âï¸"}),n.jsxs("span",{children:[n.jsx("strong",{style:{color:w.text},children:i("games_gd.welcome.panel")})," ",n.jsx("span",{style:{color:w.textMuted},children:i("games_gd.welcome.panel_def")})]})]})]})}),n.jsxs("div",{style:{padding:"clamp(8px, 2vw, 10px)",borderRadius:10,background:l,border:`1px solid ${c}`,marginBottom:"clamp(10px, 2.5vw, 12px)",textAlign:"left",fontSize:"clamp(10px, 2.2vw, 11px)",color:w.textSecondary,lineHeight:1.6},children:[n.jsx("div",{style:{display:"flex",gap:"clamp(6px, 1.5vw, 8px)",alignItems:"flex-start"},children:[{n:"1",text:i("games_gd.welcome.step1")},{n:"2",text:i("games_gd.welcome.step2")},{n:"3",text:i("games_gd.welcome.step3")},{n:"4",text:i("games_gd.welcome.step4",{levels:a})}].map(u=>n.jsxs("div",{style:{flex:1,textAlign:"center"},children:[n.jsx("div",{style:{width:20,height:20,borderRadius:"50%",background:`${s}20`,border:`1.5px solid ${s}50`,display:"flex",alignItems:"center",justifyContent:"center",margin:"0 auto clamp(2px, 0.5vw, 3px)",fontSize:"clamp(9px, 2vw, 10px)",fontWeight:700,color:s},children:u.n}),n.jsx("div",{style:{fontSize:"clamp(8px, 1.8vw, 9px)"},children:u.text})]},u.n))}),n.jsxs("div",{style:{marginTop:"clamp(4px, 1vw, 6px)",color:w.textMuted,fontSize:"clamp(8px, 1.8vw, 9px)",textAlign:"center"},children:["ð±ï¸"," ",i("games_gd.welcome.controls")]})]}
125),n.jsxs("div",{style:{padding:"clamp(5px, 1.2vw, 7px) clamp(10px, 2.5vw, 12px)",borderRadius:8,background:`${S.targetGold}10`,border:`1px solid ${S.targetGold}20`,marginBottom:"clamp(10px, 2.5vw, 12px)",fontSize:"clamp(9px, 2vw, 10px)",color:S.targetGold,fontWeight:600},children:["ð"," ",i("games_gd.welcome.demo")]}),n.jsxs("button",{onClick:t,style:{padding:"clamp(10px, 2.5vw, 14px) clamp(32px, 8vw, 48px)",borderRadius:12,border:"none",background:`linear-gradient(135deg, ${pe(s)}, ${pe(s)}dd)`,color:"white",fontWeight:700,fontSize:"clamp(14px, 3.2vw, 16px)",cursor:"pointer",minHeight:48,boxShadow:`0 4px 20px ${s}40`,transition:fe?"none":"transform 0.2s ease-out, box-shadow 0.2s ease-out",letterSpacing:"0.02em"},onMouseEnter:u=>{fe||(u.target.style.transform="scale(1.04)",u.target.style.boxShadow=`0 6px 28px ${s}50`)},onMouseLeave:u=>{u.target.style.transform="",u.target.style.boxShadow=""},"aria-label":i("games_gd.welcome.start_aria"),children:[i("games_gd.welcome.start")," ","â"]}),n.jsx("div",{style:{fontSize:"clamp(8px, 1.8vw, 9px)",color:w.textMuted,marginTop:"clamp(6px, 1.5vw, 8px)",letterSpacing:"0.03em"},children:i("games_gd.welcome.footer",{levels:a})})]}),!fe&&n.jsx("style",{children:` 126 @keyframes welcomeFadeIn { 127 from { opacity: 0; } 128 to { opacity: 1; } 129 } 130 @keyframes welcomeCardSlideUp { 131 from { opacity: 0; transform: translateY(20px) scale(0.97); } 132 to { opacity: 1; transform: translateY(0) scale(1); } 133 } 134 `})]})}const zt=typeof window<"u"?window.AudioContext||window.webkitAudioContext:null;let Xe=null;function Nn(){return!Xe&&zt&&(Xe=new zt),Xe}function ne(){const t=Nn();return t&&t.state==="suspended"&&t.resume(),t}function Yn(t=.3){const e=ne();if(!e)return;const s=e.currentTime,i=.25,a=e.sampleRate*i,r=e.createBuffer(1,a,e.sampleRate),o=r.getChannelData(0);for(let d=0;d<a;d++)o[d]=(Math.random()*2-1)*(1-d/a);const l=e.createBufferSource();l.buffer=r;const c=e.createBiquadFilter();c.type="bandpass",c.frequency.setValueAtTime(2e3,s),c.frequency.exponentialRampToValueAtTime(400,s+i),c.Q.value=2;const u=e.createGain();u.gain.setValueAtTime(t,s),u.gain.exponentialRampToValueAtTime(.001,s+i),l.connect(c).connect(u).connect(e.destination),l.start(s),l.stop(s+i);const m=e.createOscillator();m.type="sine",m.frequency.setValueAtTime(220,s),m.frequency.exponentialRampToValueAtTime(80,s+.15);const h=e.createGain();h.gain.setValueAtTime(t*.6,s),h.gain.exponentialRampToValueAtTime(.001,s+.15),m.connect(h).connect(e.destination),m.start(s),m.stop(s+.15)}function Dn(t=.35){const e=ne();if(!e)return;const s=e.currentTime;[523.25,659.25,783.99,1046.5,1318.5].forEach((x,v)=>{const R=e.createOscillator();R.type=v<3?"sine":"triangle",R.frequency.value=x;const M=e.createGain(),y=s+v*.09;M.gain.setValueAtTime(0,y),M.gain.linearRampToValueAtTime(t*(v<3?1:.7),y+.03),M.gain.exponentialRampToValueAtTime(.001,y+.8),R.connect(M).connect(e.destination),R.start(y),R.stop(y+.8)});const a=.6,r=e.sampleRate*a,o=e.createBuffer(1,r,e.sampleRate),l=o.getChannelData(0);for(let x=0;x<r;x++)l[x]=(Math.random()*2-1)*(1-x/r)*.3;const c=e.createBufferSource();c.buffer=o;const u=e.createBiquadFilter();u.type="highpass",u.frequency.value=3500;const m=e.createGain();m.gain.setValueAtTime(t*.5,s+.05),m.gain.exponentialRampToValueAtTime(.001,s+.05+a),c.connect(u).connect(m).connect(e.destination),c.start(s+.05),c.stop(s+.05+a);const h=e.createOscillator();h.type="sine",h.frequency.setValueAtTime(80,s),h.frequency.exponentialRampToValueAtTime(40,s+.3);const d=e.createGain();d.gain.setValueAtTime(t*.4,s),d.gain.exponentialRampToValueAtTime(.001,s+.3),h.connect(d).connect(e.destination),h.start(s),h.stop(s+.3)}function Xn(t=.25){const e=ne();if(!e)return;const s=e.currentTime,i=e.createOscillator();i.type="sawtooth",i.frequency.setValueAtTime(400,s),i.frequency.exponentialRampToValueAtTime(150,s+.4);const a=e.createBiquadFilter();a.type="lowpass",a.frequency.setValueAtTime(1200,s),a.frequency.exponentialRampToValueAtTime(300,s+.4);const r=e.createGain();r.gain.setValueAtTime(t,s),r.gain.exponentialRampToValueAtTime(.001,s+.4),i.connect(a).connect(r).connect(e.destination),i.start(s),i.stop(s+.4);const o=e.createOscillator();o.type="sawtooth",o.frequency.setValueAtTime(330,s+.1),o.frequency.exponentialRampToValueAtTime(120,s+.5);const l=e.createGain();l.gain.setValueAtTime(t*.7,s+.1),l.gain.exponentialRampToValueAtTime(.001,s+.5);const c=e.createBiquadFilter();c.type="lowpass",c.frequency.value=800,o.connect(c).connect(l).connect(e.destination),o.start(s+.1),o.stop(s+.5)}function qn(t=.3){const e=ne();if(!e)return;const s=e.currentTime;
134[440,554.37,659.25,880].forEach((a,r)=>{const o=e.createOscillator();o.type="triangle",o.frequency.value=a;const l=e.createGain(),c=s+r*.06;l.gain.setValueAtTime(0,c),l.gain.linearRampToValueAtTime(t,c+.02),l.gain.exponentialRampToValueAtTime(.001,c+.35),o.connect(l).connect(e.destination),o.start(c),o.stop(c+.35)})}function Kn(t=.2){const e=ne();if(!e)return;const s=e.currentTime,i=e.createOscillator();i.type="sine",i.frequency.value=1200;const a=e.createGain();a.gain.setValueAtTime(t,s),a.gain.exponentialRampToValueAtTime(.001,s+.3),i.connect(a).connect(e.destination),i.start(s),i.stop(s+.3);const r=e.createOscillator();r.type="sine",r.frequency.value=1800;const o=e.createGain();o.gain.setValueAtTime(t*.5,s),o.gain.exponentialRampToValueAtTime(.001,s+.2),r.connect(o).connect(e.destination),r.start(s),r.stop(s+.2)}function Jn(t=.08){const e=ne();if(!e)return;const s=e.currentTime,i=e.createOscillator();i.type="sine",i.frequency.value=800;const a=e.createGain();a.gain.setValueAtTime(t,s),a.gain.exponentialRampToValueAtTime(.001,s+.05),i.connect(a).connect(e.destination),i.start(s),i.stop(s+.05)}function Qn(t=.12){const e=ne();if(!e)return;const s=e.currentTime,i=e.createOscillator();i.type="sine",i.frequency.setValueAtTime(600,s),i.frequency.linearRampToValueAtTime(900,s+.15);const a=e.createGain();a.gain.setValueAtTime(t,s),a.gain.exponentialRampToValueAtTime(.001,s+.2),i.connect(a).connect(e.destination),i.start(s),i.stop(s+.2);const r=e.createOscillator();r.type="sine",r.frequency.value=1400;const o=e.createGain();o.gain.setValueAtTime(t*.3,s+.05),o.gain.exponentialRampToValueAtTime(.001,s+.15),r.connect(o).connect(e.destination),r.start(s+.05),r.stop(s+.15)}function Zn(t=.25){const e=ne();if(!e)return;const s=e.currentTime;[2093,1760,1568,1318.5,1046.5].forEach((a,r)=>{const o=e.createOscillator();o.type="sine",o.frequency.value=a;const l=e.createGain(),c=s+.5+r*.08;l.gain.setValueAtTime(0,c),l.gain.linearRampToValueAtTime(t*.6,c+.01),l.gain.exponentialRampToValueAtTime(.001,c+.25),o.connect(l).connect(e.destination),o.start(c),o.stop(c+.25)})}function es(){return{drop:Yn,victory:Dn,fail:Xn,levelUp:qn,star:Kn,stepTick:Jn,proximityChime:Qn,newRecord:Zn}}const Ct="mlm_game_stars",It="mlm_game_unlocked",Ft="mlm_game_best",Gt="mlm_game_welcomed",E=typeof window<"u"?window.matchMedia("(prefers-reduced-motion: reduce)").matches:!1;function Re(t,e){try{const s=localStorage.getItem(t);return s?JSON.parse(s):e}catch{return e}}function ts({stars:t,isDark:e,trackColor:s,onDismiss:i,onReplay:a,onLearnMore:r}){const{t:o}=re("pages"),l=t.reduce((u,m)=>u+m,0),c=[{icon:"ð¯",title:"Learning Rate",summary:"Controls step size. Too small = slow, too large = divergence. The most fundamental hyperparameter.",moduleId:"learningRate",moduleTitle:"Learning Rate"},{icon:"â°ï¸",title:"Local vs Global Minima",summary:"Loss landscapes have multiple valleys. SGD gets trapped, but momentum helps roll through shallow traps to find deeper solutions.",moduleId:"momentum",moduleTitle:"Momentum"},{icon:"ð",title:"Saddle Points",summary:"Zero gradient does not mean minimum. In high dimensions, saddle points are more common than local minima. Momentum helps escape.",moduleId:"convexity",moduleTitle:"Convexity"},{icon:"ð",title:"Adaptive Learning Rates",summary:"Noisy gradients confuse fixed-rate optimizers. Adam adapts per-parameter, making it the go-to optimizer for deep learning.",moduleId:"adam",moduleTitle:"Adam Optimizer"},{icon:"ð",title:"Real Landscapes",summary:"Neural networks combine all these challenges in millions of dimensions. Optimizer choice, learning rate, and momentum determine success.",moduleId:"gradientDescent",moduleTitle:"Gradient Descent"}];return n.jsxs("div",{style:{position:"absolute",inset:0,zIndex:100,display:"flex",alignItems:"center",justifyContent:"center",background:e?"rgba(0,0,0,0.7)":"rgba(0,0,0,0.4)",backdropFilter:"blur(8px)",WebkitBackdropFilter:"blur(8px)",animation:E?"none":"gameSummaryFadeIn 0.4s ease-out"},children:[n.jsxs("div",{style:{width:"clamp(300px, 80vw, 540px)",maxHeight:"85vh",overflowY:"auto",background:e?"rgba(var(--bg-card-rgb),0.95)":"rgba(255,255,255,0.97)",borderRadius:20,padding:"clamp(20px, 5vw, 32px)",border:`2px solid ${S.targetGold}40`,boxShadow:`0 0 60px ${S.targetGold}20, 0 20px 60px rgba(0,0,0,0.3)`},children:[n.jsxs("div",{style:{textAlign:"center",marginBottom:"clamp(16px, 4vw, 24px)"},children:[n.jsx("div",{style:{fontSize:"clamp(40px, 10vw, 56px)",marginBottom:"clamp(4px, 1vw, 8px)"},children:"ð"}),n.jsx("div",{style:{fontSize:"clamp(20px, 5vw, 28px)",fontWeight:800,color:S.targetGold,marginBottom:"clamp(4px, 1vw, 6px)"},children:o("games_gd.summary.complete")}
134),n.jsx("div",{style:{fontSize:"clamp(12px, 2.8vw, 14px)",color:w.textSecondary},children:o("games_gd.summary.stars",{total:l,max:P.length*3,levels:P.length})}),n.jsx("div",{style:{marginTop:"clamp(4px, 1vw, 6px)"},children:[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15].map(u=>n.jsx("span",{style:{opacity:l>=u?1:.15,fontSize:"clamp(12px, 2.8vw, 14px)"},children:"â"},u))})]}),n.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"clamp(8px, 2vw, 12px)",marginBottom:"clamp(16px, 4vw, 24px)"},children:c.map((u,m)=>n.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"clamp(8px, 2vw, 12px)",padding:"clamp(8px, 2vw, 12px)",borderRadius:10,background:e?"rgba(255,255,255,0.04)":"rgba(0,0,0,0.02)",border:`1px solid ${e?"rgba(255,255,255,0.06)":"rgba(0,0,0,0.06)"}`},children:[n.jsx("div",{style:{fontSize:"clamp(16px, 3.5vw, 20px)",flexShrink:0,width:"clamp(24px, 5vw, 28px)",textAlign:"center"},children:u.icon}),n.jsxs("div",{children:[n.jsxs("div",{style:{fontSize:"clamp(12px, 2.8vw, 14px)",fontWeight:700,color:w.text,marginBottom:2},children:[o("games_gd.summary.level_title",{n:m+1,title:o(`games_gd.summary.c${m+1}.title`,{defaultValue:u.title})})," ",[1,2,3].map(h=>n.jsx("span",{style:{opacity:t[m]>=h?1:.2,fontSize:"clamp(10px, 2.2vw, 11px)"},children:"â"},h))]}),n.jsx("div",{style:{fontSize:"clamp(11px, 2.5vw, 12px)",color:w.textSecondary,lineHeight:1.5},children:o(`games_gd.summary.c${m+1}.summary`,{defaultValue:u.summary})}),r&&n.jsxs("button",{onClick:()=>r({id:u.moduleId,title:u.moduleTitle}),style:{marginTop:"clamp(3px, 0.8vw, 4px)",padding:0,border:"none",background:"none",color:s,fontWeight:600,fontSize:"clamp(10px, 2.2vw, 11px)",cursor:"pointer",textAlign:"left"},children:["ð"," ",o("games_gd.summary.module_link",{title:u.moduleTitle})," ","â"]})]})]},m))}),n.jsxs("div",{style:{padding:"clamp(10px, 2.5vw, 14px)",borderRadius:10,background:e?"rgba(59,130,246,0.08)":"rgba(59,130,246,0.05)",border:`1px solid ${e?"rgba(59,130,246,0.2)":"rgba(59,130,246,0.12)"}`,marginBottom:"clamp(14px, 3.5vw, 20px)"},children:[n.jsxs("div",{style:{fontSize:"clamp(10px, 2.2vw, 11px)",fontWeight:700,color:e?"#93c5fd":"#2563eb",textTransform:"uppercase",letterSpacing:"0.05em",marginBottom:"clamp(4px, 1vw, 6px)"},children:["ð§ "," ",o("games_gd.summary.big_picture")]}),n.jsx("div",{style:{fontSize:"clamp(11px, 2.5vw, 13px)",color:w.textSecondary,lineHeight:1.6},children:o("games_gd.summary.big_picture_body")})]}),n.jsxs("div",{style:{display:"flex",gap:"clamp(8px, 2vw, 12px)"},children:[n.jsxs("button",{onClick:a,style:{flex:1,padding:"clamp(10px, 2.5vw, 12px)",borderRadius:10,border:`2px solid ${w.border}`,background:"transparent",color:w.text,fontWeight:600,fontSize:"clamp(12px, 2.8vw, 14px)",cursor:"pointer",minHeight:44,transition:E?"none":"all 0.2s ease-out"},children:["ð"," ",o("games_gd.summary.replay")]}),n.jsxs("button",{onClick:i,style:{flex:1,padding:"clamp(10px, 2.5vw, 12px)",borderRadius:10,border:"none",background:S.targetGold,color:"#1a1a2e",fontWeight:700,fontSize:"clamp(12px, 2.8vw, 14px)",cursor:"pointer",minHeight:44,transition:E?"none":"all 0.2s ease-out"},children:["ð"," ",o("games_gd.summary.done")]})]})]}),!E&&n.jsx("style",{children:` 135 @keyframes gameSummaryFadeIn { 136 from { opacity: 0; } 137 to { opacity: 1; } 138 } 139 `})]})}function ns({isDark:t,nav:e,onBackToGames:s}){var at;const{t:i}=re("pages"),a=(g,L)=>i(`games_gd.levels.${g.id}.${L}`,{defaultValue:g[L]}),r=Zt(),o=en(),l=es(),c=Kt("optimization"),[u,m]=p.useState(null),[h,d]=p.useState("intro"),[x,v]=p.useState(!1),[R,M]=p.useState(!1),[y,b]=p.useState(()=>!Re(Gt,!1)),[A,I]=p.useState(!1),[f,G]=p.useState(0),[j,_]=p.useState("placing"),[T,z]=p.useState(null),[$,W]=p.useState(null),[C,ue]=p.useState([]),[de,Ie]=p.useState({loss:null,gradMag:null,steps:0}),[kt,ve]=p.useState(null),[Ke,se]=p.useState(!1),[Pt,Je]=p.useState(0),[Wt,Fe]=p.useState(!1),[oe,Vt]=p.useState(()=>Re(Ct,[0,0,0,0,0])),[Ge,Et]=p.useState(()=>Re(It,0)),[le,Ot]=p.useState(()=>Re(Ft,{})),V=P[f],[be,Be]=p.useState(V.defaultLR),[we,Le]=p.useState(V.defaultMomentum),[Se,ke]=p.useState(V.availableOptimizer
139s[0]),K=p.useRef(!1),Pe=p.useRef(null),ie=p.useRef(null),We=p.useRef(0),Y=p.useRef(l);Y.current=l;const Qe=p.useRef(le);Qe.current=le,p.useEffect(()=>{try{localStorage.setItem(Ct,JSON.stringify(oe)),localStorage.setItem(It,JSON.stringify(Ge)),localStorage.setItem(Ft,JSON.stringify(le))}catch{}},[oe,Ge,le]),p.useEffect(()=>{const g=P[f];Be(g.defaultLR),Le(g.defaultMomentum),ke(g.availableOptimizers[0])},[f]);const J=p.useMemo(()=>typeof window<"u"&&window.innerWidth<768,[]),me=p.useMemo(()=>{const g=P[f];let B=[...g.demoStart||g.globalMin||[3,2.5]];const O=g.demoLR||g.defaultLR,H=1e-4,Me=[{x:B[0],y:q(g.fn(B[0],B[1])),z:B[1]}];for(let Z=0;Z<120;Z++){const _e=(g.fn(B[0]+H,B[1])-g.fn(B[0]-H,B[1]))/(2*H),D=(g.fn(B[0],B[1]+H)-g.fn(B[0],B[1]-H))/(2*H);B=[B[0]-O*_e,B[1]-O*D],Me.push({x:B[0],y:q(g.fn(B[0],B[1])),z:B[1]});const ae=B[0]-g.globalMin[0],he=B[1]-g.globalMin[1];if(Math.sqrt(ae*ae+he*he)<(g.victoryRadius||1)*.4)break}return Me},[f]),[Ve,Ze]=p.useState(0),Ee=p.useRef(null);p.useEffect(()=>{if(!y){Ze(0);return}const g=me.length+25;let L=0;const B=setTimeout(()=>{Ee.current=setInterval(()=>{L=(L+1)%g,Ze(Math.min(L,me.length-1))},80)},600);return()=>{clearTimeout(B),Ee.current&&clearInterval(Ee.current)}},[y,me]);const $t=p.useMemo(()=>!y||Ve<=0?null:me.slice(0,Ve+1),[y,me,Ve]),Ht=p.useCallback(()=>{A?(o.stop(),I(!1)):(o.start(),I(!0))},[A,o]),Ut=p.useCallback(()=>{d(null)},[]),Nt=p.useCallback(()=>{b(!1),d("intro");try{localStorage.setItem(Gt,JSON.stringify(!0))}catch{}},[]),Yt=p.useCallback(()=>{b(!0)},[]),je=p.useCallback(()=>{var ut,dt,mt,ht,gt,xt;if(!K.current||!Pe.current)return;const g=Pe.current,L=P[g.levelIdx],B=1e3/20,O=performance.now();if(O-We.current<B){ie.current=requestAnimationFrame(je);return}We.current=O;const{numericalGradient:H,optimizerStep:Me}=g.optimizerFns,Z=L.gradient?L.gradient(g.pos[0],g.pos[1]):H(L.fn,g.pos[0],g.pos[1]),_e=Math.sqrt(Z[0]
139*Z[0]+Z[1]*Z[1]),D=Me(g.optimizerType,g.pos,Z,g.learningRate,g.momentum,{velocity:g.velocity,m:g.m,v:g.v,t:g.t});g.pos=D.pos,D.velocity&&(g.velocity=D.velocity),D.m&&(g.m=D.m),D.v&&(g.v=D.v),g.t+=1,g.steps+=1;const ae=L.fn(g.pos[0],g.pos[1]);g.path.push({x:g.pos[0],y:q(ae),z:g.pos[1]}),ue([...g.path]),Ie({loss:ae,gradMag:_e,steps:g.steps}),g.steps%10===0&&((dt=(ut=Y.current).stepTick)==null||dt.call(ut));const he=g.pos[0]-L.globalMin[0],rt=g.pos[1]-L.globalMin[1],ot=Math.sqrt(he*he+rt*rt),lt=L.victoryRadius||1;if(ot<lt*2&&!g.proximityChimed&&(g.proximityChimed=!0,(ht=(mt=Y.current).proximityChime)==null||ht.call(mt)),ot<lt){K.current=!1;const $e=ss(g.steps,L.starThresholds);Je($e),_("victory"),v(!0),setTimeout(()=>v(!1),500),d("victory"),Y.current.victory();for(let N=0;N<$e;N++)setTimeout(()=>Y.current.star(),500+N*200);setTimeout(()=>se(!0),1200);const ft=L.id,Te=Qe.current[ft];(!Te||g.steps<Te.steps)&&(M(!0),(xt=(gt=Y.current).newRecord)==null||xt.call(gt)),Vt(N=>{const He=[...N];return He[g.levelIdx]=Math.max(He[g.levelIdx],$e),He}),Et(N=>Math.max(N,g.levelIdx+1)),Ot(N=>!Te||g.steps<Te.steps?{...N,[ft]:{steps:g.steps}}:N);return}const[ct,pt]=L.bounds;if(ae>50||g.pos[0]<ct-2||g.pos[0]>pt+2||g.pos[1]<ct-2||g.pos[1]>pt+2||!isFinite(ae)){K.current=!1,_("failed"),ve("diverged"),se(!0),Y.current.fail();return}if(_e<1e-5){if(g.stuckCount=(g.stuckCount||0)+1,g.stuckCount>=40){K.current=!1,_("failed"),ve("stuck"),se(!0),Y.current.fail();return}}else g.stuckCount=0;if(g.steps>=500){K.current=!1,_("failed"),ve("max_steps"),se(!0),Y.current.fail();return}ie.current=requestAnimationFrame(je)},[]),et=p.useCallback(async(g,L)=>{const B=await Jt(()=>import("./optimizers-DEYifpeE.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9])),O=V.fn(g,L);Pe.current={levelIdx:f,pos:[g,L],velocity:[0,0],m:[0,0],v:[0,0],t:0,steps:0,stuckCount:0,proximityChimed:!1,path:[{x:g,y:q(O),z:L}],learningRate:be,momentum:we,optimizerType:Se,optimizerFns:B},ue([{x:g,y:q(O),z:L}]),Ie({loss:O,gradMag:null,steps:0}),We.current=0,K.current=!0,ie.current=requestAnimationFrame(je)},[V,f,be,we,Se,je]);p.useEffect(()=>()=>{K.current=!1,ie.current&&cancelAnimationFrame(ie.current)},[]);const tt=p.useRef(o.stop);tt.current=o.stop,p.useEffect(()=>()=>{tt.current()},[]);const Dt=p.useCallback(g=>{if(j!=="placing")return;const[L,B]=V.bounds,O=Math.max(L+.5,Math.min(B-.5,g.x)),H=Math.max(L+.5,Math.min(B-.5,g.z));z({x:O,z:H}),_("running"),l.drop(),et(O,H)},[j,V,et,l]),Xt=p.useCallback(g=>{y||W(g)},[y]),Q=p.useCallback(()=>{K.current=!1,ie.current&&cancelAnimationFrame(ie.current),_("placing"),z(null),W(null),ue([]),Ie({loss:null,gradMag:null,steps:0}),ve(null),se(!1),Je(0),d(null),v(!1),M(!1)},[]),Oe=p.useCallback(()=>{if(f<P.length-1){if(l.levelUp(),E){G(f+1),Q(),d("intro");return}m("fadeOut"),setTimeout(()=>{G(f+1),Q(),m("title"),setTimeout(()=>{m("fadeIn"),d("intro"),setTimeout(()=>m(null),500)},800)},400)}},[f,Q,l]),nt=p.useCallback(g=>{G(g),Q(),d("intro")},[Q]),qt=p.useCallback(()=>{se(!1)},[]),st=p.useCallback(g=>{e("module",{id:"optimization"},{id:g.id,title:g.title})},[e]),it=t?S.glassBorderDark:S.glassBorderLight;return n.jsxs("div",{style:{width:"100%",height:J?"auto":"calc(100vh - 120px)",minHeight:J?"calc(100vh - 120px)":"auto",display:"flex",flexDirection:J?"column":"row",position:"relative",overflow:"hidden"},children:[y&&n.jsx(Un,{onStart:Nt,isDark:t,trackColor:c}),u&&n.jsx("div",{style:{position:"absolute",inset:0,zIndex:200,display:"flex",alignItems:"center",justifyContent:"center",background:"#0a0a0a",opacity:u==="fadeOut"||u==="title"?1:0,transition:"opacity 0.4s ease-out",pointerEvents:"none"},children:(u==="title"||u==="fadeIn")&&n.jsxs("div",{style:{textAlign:"center"},children:[n.jsx("div",{style:{fontSize:"clamp(36px, 9vw, 52px)",marginBottom:"clamp(8px, 2vw, 12px)"},children:(at=P[f])==null?void 0:at.icon}),n.jsx("div",{style:{fontSize:"clamp(20px, 5vw, 30px)",fontWeight:800,color:"#fff",letterSpacing:"0.02em"},children:i("games_gd.game.level",{n:f+1})}),n.jsx("div",{style:{fontSize:"clamp(13px, 3vw, 16px)",fontWeight:500,color:"rgba(255,255,255,0.6)",marginTop:"clamp(4px, 1vw, 6px)"},children:P[f]&&a(P[f],"title")})]})}),Wt&&n.jsx(ts,{stars:oe,isDark:t,trackColor:c,onDismiss:()=>Fe(!1),onReplay:()=>{Fe(!1),nt(0)},onLearnMore:st}),n.jsxs("div",{style:{flex:J?"none":1,height:J?"55vh":"100%",minHeight:J?300:"auto",position:"relative",animation:x&&!E?"victoryShake 0.5s ease-out":"none"},children:[n.jsx(En,{level:V,levelIndex:f,gamePhase:j,dropPoint:T,ballPath:C,qual
139ity:r,isDark:t,trackColor:c,onSurfaceClick:Dt,onSurfaceHover:Xt,hoverPoint:$,prefersReducedMotion:E,demoPath:$t,cameraMode:h,onCinematicDone:Ut}),n.jsx("div",{style:{position:"absolute",top:"clamp(8px, 2vw, 16px)",left:"50%",transform:"translateX(-50%)",zIndex:15},children:n.jsx($n,{currentLevel:f,unlockedLevel:Ge,stars:oe,onSelect:nt,isDark:t,trackColor:c})}),!J&&n.jsx(Rt,{level:V,levelIndex:f,totalLevels:P.length,gamePhase:j,metrics:de,learningRate:be,setLearningRate:Be,momentumVal:we,setMomentumVal:Le,optimizerType:Se,setOptimizerType:ke,stars:oe,bestScore:le[V.id],onReset:Q,onNextLevel:Oe,isDark:t,trackColor:c,isMobile:!1}),Ke&&n.jsx(Hn,{level:V,gamePhase:j,failReason:kt,steps:de.steps,starsEarned:Pt,isDark:t,trackColor:c,onDismiss:qt,isLastLevel:f===P.length-1,onShowGameSummary:()=>{se(!1),Fe(!0)},onLearnMore:st}),R&&j==="victory"&&n.jsxs("div",{style:{position:"absolute",top:"clamp(56px, 14vw, 72px)",left:"50%",transform:"translateX(-50%)",zIndex:25,padding:"clamp(6px, 1.5vw, 8px) clamp(16px, 4vw, 24px)",background:`linear-gradient(135deg, ${S.targetGold}, #f59e0b)`,color:"#1a1a2e",fontWeight:800,fontSize:"clamp(12px, 2.8vw, 14px)",borderRadius:20,boxShadow:`0 4px 20px ${S.targetGold}50`,letterSpacing:"0.04em",animation:E?"none":"newRecordPop 0.5s ease-out"},children:["ð"," ",i("games_gd.game.new_record")]}),!Ke&&(j==="victory"||j==="failed")&&n.jsxs("div",{style:{position:"absolute",bottom:"clamp(16px, 4vw, 24px)",left:"50%",transform:"translateX(-50%)",zIndex:25,display:"flex",gap:"clamp(8px, 2vw, 12px)",padding:"clamp(8px, 2vw, 12px)",background:t?S.glassBgDark:S.glassBgLight,backdropFilter:"blur(16px)",WebkitBackdropFilter:"blur(16px)",border:`1px solid ${it}`,borderRadius:14,boxShadow:t?"0 8px 32px rgba(0,0,0,0.5)":"0 8px 32px rgba(0,0,0,0.12)",animation:E?"none":"floatBarSlideUp 0.3s ease-out"},children:[n.jsxs("button",{onClick:Q,style:{padding:"clamp(8px, 2vw, 12px) clamp(16px, 4vw, 24px)",borderRadius:10,border:`2px solid ${w.border}`,background:"transparent",color:w.text,fontWeight:600,fontSize:"clamp(12px, 2.8vw, 14px)",cursor:"pointer",minHeight:44,whiteSpace:"nowrap",transition:E?"none":"all 0.2s ease-out"},children:["ð"," ",i("games_gd.game.try_again")]}),j==="victory"&&f<P.length-1&&n.jsxs("button",{onClick:Oe,style:{padding:"clamp(8px, 2vw, 12px) clamp(16px, 4vw, 24px)",borderRadius:10,border:`2px solid ${c}`,background:pe(c),color:"white",fontWeight:600,fontSize:"clamp(12px, 2.8vw, 14px)",cursor:"pointer",minHeight:44,whiteSpace:"nowrap",transition:E?"none":"all 0.2s ease-out"},children:[i("games_gd.game.next_level")," ","â"]})]})]}),J&&n.jsx("div",{style:{flex:1,padding:"clamp(8px, 2vw, 12px)",overflowY:"auto"},children:n.jsx(Rt,{level:V,levelIndex:f,totalLevels:P.length,gamePhase:j,metrics:de,learningRate:be,setLearningRate:Be,momentumVal:we,setMomentumVal:Le,optimizerType:Se,setOptimizerType:ke,stars:oe,bestScore:le[V.id],onReset:Q,onNextLevel:Oe,isDark:t,trackColor:c,isMobile:!0})}),!y&&j==="placing"&&n.jsxs("div",{style:{position:"absolute",bottom:"clamp(16px, 4vw, 24px)",left:"50%",transform:"translateX(-50%)",zIndex:15,display:"flex",alignItems:"center",gap:"clamp(12px, 3vw, 18px)",padding:"clamp(8px, 2vw, 10px) clamp(14px, 3.5vw, 20px)",background:t?S.glassBgDark:S.glassBgLight,backdropFilter:"blur(12px)",WebkitBackdropFilter:"blur(12px)",border:`1px solid ${t?S.glassBorderDark:S.glassBorderLight}`,borderRadius:12,boxShadow:t?"0 4px 16px rgba(0,0,0,0.4)":"0 4px 16px rgba(0,0,0,0.08)",maxWidth:"clamp(280px, 70vw, 520px)",whiteSpace:"nowrap"},children:[n.jsxs("span",{style:{fontSize:"clamp(10px, 2.2vw, 12px)",color:w.textSecondary,display:"flex",alignItems:"center",gap:"clamp(3px, 0.8vw, 5px)"},children:[n.jsx("span",{style:{color:S.targetGold,fontSize:"clamp(12px, 2.8vw, 14px)"},children:"ð¡"}),i("games_gd.game.gold_ring_target")]}),n.jsx("span",{style:{width:1,height:"clamp(12px, 3vw, 16px)",background:t?"rgba(255,255,255,0.15)":"rgba(0,0,0,0.1)",flexShrink:0}}),n.jsxs("span",{style:{fontSize:"clamp(10px, 2.2vw, 12px)",color:w.text,fontWeight:600},children:["ð"," ",i("games_gd.game.click_drop")]})]}),n.jsxs("button",{onClick:()=>s?s():e("game"),style:{position:"absolute",top:"clamp(8px, 2vw, 14px)",left:"clamp(8px, 2vw, 14px)",zIndex:20,padding:"clamp(6px, 1.5vw, 8px) clamp(10px, 2.5vw, 14px)",borderRadius:8,border:`1px solid ${t?"rgba(148,163,184,0.2)":"rgba(255,255,255,0.3)"}`,background:t?"rgba(var(--bg-card-rgb),0.8)":"rgba(255,255,255,0.8)",backdropFilter:"blur(8px)",WebkitBackdropFilter:"blur(8px)",color:w.text,fontWeight:600,fontSize:"clamp(11px, 2.5vw, 13px)",cursor:"pointer",minHeight:36,display:"flex",alignItems:"center",gap:"clamp(4px, 1vw, 6px)"},"aria-label":i("games_gd.game.back_aria"),children:["â"," ",i("games_gd.game.games")]}),n.jsxs("button",{onClick:Ht,style:{position:"absolute",bottom:"clamp(8px, 2vw, 14px)",left:"clamp(8px, 2vw, 14px)",zIndex:20,padding:"clamp(6px, 1.5vw, 8px) clamp(10px, 2.5vw, 14px)",borderRadius:8,border:`1px solid ${t?"rgba(148,163,184,0.2)":"rgba(255,255,255,0.3)"}`,background:t?"rgba(var(--bg-card-rgb),0.8)":"rgba(255,255,255,0.8)",backdropFilter:"blur(8px)",WebkitBackdropFilter:"blur(8px)",color:A?
139c:w.textMuted,fontWeight:600,fontSize:"clamp(14px, 3vw, 16px)",cursor:"pointer",minHeight:36,display:"flex",alignItems:"center",gap:"clamp(4px, 1vw, 6px)",transition:E?"none":"all 0.2s ease-out"},"aria-label":i(A?"games_gd.game.music_mute":"games_gd.game.music_play"),title:i(A?"games_gd.game.music_mute_title":"games_gd.game.music_play_title"),children:[A?"ð":"ð",n.jsx("span",{style:{fontSize:"clamp(10px, 2.2vw, 11px)"},children:i(A?"games_gd.game.on":"games_gd.game.off")})]}),n.jsxs("button",{onClick:Yt,style:{position:"absolute",bottom:"clamp(96px, 22vw, 106px)",left:"clamp(8px, 2vw, 14px)",zIndex:20,padding:"clamp(6px, 1.5vw, 8px) clamp(10px, 2.5vw, 14px)",borderRadius:8,border:`1px solid ${t?"rgba(148,163,184,0.2)":"rgba(255,255,255,0.3)"}`,background:t?"rgba(var(--bg-card-rgb),0.8)":"rgba(255,255,255,0.8)",backdropFilter:"blur(8px)",WebkitBackdropFilter:"blur(8px)",color:w.textMuted,fontWeight:600,fontSize:"clamp(14px, 3vw, 16px)",cursor:"pointer",minHeight:36,display:"flex",alignItems:"center",gap:"clamp(4px, 1vw, 6px)"},"aria-label":i("games_gd.game.how_to_play"),title:i("games_gd.game.how_to_play"),children:["â¹ï¸",n.jsx("span",{style:{fontSize:"clamp(10px, 2.2vw, 11px)"},children:i("games_gd.game.info")})]}),n.jsxs("button",{onClick:()=>{const g=document.getElementById("game-hint-toast");g&&(g.style.display=g.style.display==="none"?"block":"none")},style:{position:"absolute",bottom:"clamp(52px, 12vw, 60px)",left:"clamp(8px, 2vw, 14px)",zIndex:20,padding:"clamp(6px, 1.5vw, 8px) clamp(10px, 2.5vw, 14px)",borderRadius:8,border:`1px solid ${t?"rgba(148,163,184,0.2)":"rgba(255,255,255,0.3)"}`,background:t?"rgba(var(--bg-card-rgb),0.8)":"rgba(255,255,255,0.8)",backdropFilter:"blur(8px)",WebkitBackdropFilter:"blur(8px)",color:w.textMuted,fontWeight:600,fontSize:"clamp(14px, 3vw, 16px)",cursor:"pointer",minHeight:36,display:"flex",alignItems:"center",gap:"clamp(4px, 1vw, 6px)"},"aria-label":i("games_gd.game.show_hint"),title:i("games_gd.game.hint_title"),children:["ð¡",n.jsx("span",{style:{fontSize:"clamp(10px, 2.2vw, 11px)"},children:i("games_gd.game.hint")})]}),n.jsxs("div",{id:"game-hint-toast",style:{display:"none",position:"absolute",bottom:"clamp(140px, 32vw, 156px)",left:"clamp(8px, 2vw, 14px)",zIndex:20,maxWidth:"clamp(220px, 40vw, 300px)",padding:"clamp(10px, 2.5vw, 14px)",borderRadius:10,background:t?S.glassBgDark:S.glassBgLight,backdropFilter:"blur(12px)",WebkitBackdropFilter:"blur(12px)",border:`1px solid ${it}`,boxShadow:t?"0 4px 20px rgba(0,0,0,0.4)":"0 4px 20px rgba(0,0,0,0.1)"},children:[n.jsxs("div",{style:{fontSize:"clamp(10px, 2.2vw, 11px)",fontWeight:600,color:S.targetGold,textTransform:"uppercase",letterSpacing:"0.05em",marginBottom:4},children:["ð¡"," ",i("games_gd.game.hint_heading",{title:a(V,"title")})]}),n.jsx("div",{style:{fontSize:"clamp(11px, 2.5vw, 13px)",color:w.textSecondary,lineHeight:1.5},children:a(V,"hint")})]}),!E&&n.jsx("style",{children:` 140 @keyframes floatBarSlideUp { 141 from { opacity: 0; transform: translateX(-50%) translateY(12px); } 142 to { opacity: 1; transform: translateX(-50%) translateY(0); } 143 } 144 @keyframes victoryShake { 145 0%, 100% { transform: translate(0, 0); } 146 10% { transform: translate(-3px, 2px); } 147 20% { transform: translate(2px, -3px); } 148 30% { transform: translate(-2px, 1px); } 149 40% { transform: translate(3px, -1px); } 150 50% { transform: translate(-1px, 3px); } 151 60% { transform: translate(2px, -2px); } 152 70% { transform: translate(-3px, 1px); } 153 80% { transform: translate(1px, -2px); } 154 90% { transform: translate(-2px, 2px); } 155 } 156 @keyframes newRecordPop { 157 0% { opacity: 0; transform: translateX(-50%) scale(0.5); } 158 60% { transform: translateX(-50%) scale(1.15); } 159 100% { opacity: 1; transform: translateX(-50%) scale(1); } 160 } 161 `})]})}function ss(t,e){return t<=e[2]?3:t<=e[1]?2:(t<=e[0],1)}const gs=Object.freeze(Object.defineProperty({__proto__:null,default:ns},Symbol.toStringTag,{value:"Module"}));
161export{ds as A,gs as G,ms as a,hs as b};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.