0}}const we={green:{border:"#34d399",bg:"rgba(52,211,153,0.18)",text:"#6ee7b7"},red:{border:"#f87171",bg:"rgba(248,113,113,0.18)",text:"#fca5a5"},yellow:{border:"#fbbf24",bg:"rgba(251,191,36,0.18)",text:"#fde68a"},blue:{border:"#60a5fa",bg:"rgba(96,165,250,0.18)",text:"#93c5fd"},purple:{border:"#c084fc",bg:"rgba(192,132,252,0.18)",text:"#d8b4fe"}},je={border:"#475569",bg:"rgba(30,41,59,0.7)",text:"#cbd5e1"},Le={green:"#34d399",red:"#f87171",yellow:"#fbbf24",blue:"#60a5fa",purple:"#c084fc"},C=60,N=48,W=40,F=C+W,B=6,G=N+78;function ke({step:g}){return g?g.lru?i.jsx(Se,{step:g}):i.jsx(Ne,{step:g}):null}function Ne({step:g}){const{nodes:t,pointers:c,highlights:x,cycleTo:e}=g,r=new Map(x.map(h=>[h.index,h.color])),n=new Map;for(const h of c){const m=n.get(h.index)??[];m.push(h),n.set(h.index,m)}if(t.length===0)return i.jsx("div",{className:"flex h-full min-h-[260px] w-full items-center justify-center",children:i.jsx("div",{className:"flex h-16 w-48 items-center justify-center rounded-lg border-2 border-dashed border-slate-700 text-xs text-slate-600",children:"Empty list — null"})});const l=Math.ceil(t.length/B),s=Math.min(t.length,B)*F+W,p=l*G+20,o=28,a=h=>{const m=Math.floor(h/B);return{x:h%B*F+W,y:m*G+o}};return i.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center gap-4 overflow-auto px-2",children:[i.jsxs("svg",{viewBox:`0 0 ${s+20} ${p}`,width:"100%",style:{maxWidth:`${s+20}px`,overflow:"visible"},children:[t.map((h,m)=>{const v=m===t.length-1,{x:y,y:$}=a(m),f=m%B!==B-1;if(v)return null;if(f)return i.jsxs("g",{children:[i.jsx("line",{x1:y+C,y1:$+N/2,x2:y+F,y2:$+N/2,stroke:"#475569",strokeWidth:1.6}),i.jsx("polygon",{points:`${y+F},${$+N/2} ${y+F-7},${$+N/2-4} ${y+F-7},${$+N/2+4}`,fill:"#475569"})]},`edge-${h.id}`);const b=a(m+1);return i.jsx("path",{d:`M ${y+C} ${$+N/2} L ${y+C+14} ${$+N/2} L ${y+C+14} ${$+N+28} L ${b.x-14} ${b.y+N/2} L ${b.x} ${b.y+N/2}`,fill:"none",stroke:"#475569",strokeWidth:1.6,markerEnd:""},`wrap-${h.id}`)}),e==null&&t.length>0&&(()=>{const h=t.length-1,{x:m,y:v}=a(h);return i.jsx("text",{x:m+C+22,y:v+N/2+4,textAnchor:"middle",fontSize:"10",fill:"#64748b",fontFamily:"monospace",children:"null"},"null")})(),e!=null&&t.length>0&&(()=>{const h=a(t.length-1),m=a(e),v=h.x+C/2,y=h.y+N,$=m.x+C/2,f=m.y+N,b=Math.max(y,f)+46;return i.jsxs("g",{children:[i.jsx("path",{d:`M ${v} ${y} C ${v} ${b}, ${$} ${b}, ${$} ${f}`,fill:"none",stroke:"#f59e0b",strokeWidth:1.8,strokeDasharray:"5 4"}),i.jsx("polygon",{points:`${$},${f} ${$-4},${f+8} ${$+4},${f+8}`,fill:"#f59e0b"}),i.jsxs("text",{x:(v+$)/2,y:b+12,textAnchor:"middle",fontSize:"9",fill:"#fbbf24",fontFamily:"monospace",children:["cycle → index ",e]})]})})(),t.map((h,m)=>{const{x:v,y}=a(m),$=r.get(m),f=$?we[$]:je,b=n.get(m)??[];return i.jsxs("g",{children:[m===0&&i.jsx("text",{x:v+C/2,y:y-16,textAnchor:"middle",fontSize:"9",fill:"#818cf8",fontFamily:"monospace",children:"head"}),b.map((R,L)=>i.jsx("g",{children:i.jsxs("text",{x:v+C/2,y:y-6-L*11,textAnchor:"middle",fontSize:"9",fontWeight:"bold",fill:Le[R.color??"blue"],fontFamily:"monospace",children:[R.name,"↓"]})},R.name)),i.jsx("rect",{x:v,y,width:C,height:N,rx:8,fill:f.bg,stroke:f.border,strokeWidth:$?2.2:1.5}),i.jsx("text",{x:v+C/2,y:y+N/2+5,textAnchor:"middle",fontSize:"15",fontWeight:"bold",fill:f.text,fontFamily:"sans-serif",children:h.value}),i.jsxs("text",{x:v+C/2,y:y+N+12,textAnchor:"middle",fontSize:"8",fill:"#475569",fontFamily:"monospace",children:["[",m,"]"]})]},h.id)})]}),g.description&&i.jsx("div",{className:"w-full max-w-xl rounded-lg bg-slate-800/60 px-4 py-2 text-center text-xs leading-relaxed text-indigo-300",children:g.description}),g.meta&&g.meta.length>0&&i.jsx("div",{className:"flex flex-wrap justify-center gap-1.5",children:g.meta.map(h=>i.jsx("span",{className:"rounded-full bg-slate-800/80 px-2.5 py-0.5 text-[10px] font-mono text-slate-300 ring-1 ring-slate-700/50",children:h},h))})]})}function Se({step:g}){const t=g.lru,c=Array.from({length:t.capacity});return i.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center gap-5 overflow-auto px-2",children:[i.jsxs("div",{className:"flex w-full max-w-2xl items-center justify-between text-[10px] uppercase tracking-wider text-slate-500",children:[i.jsx("span",{className:"text-emerald-400",children:"← Most recently used"}),i.jsx("span",{className:"text-rose-400",children:"Least recently used →"})]}),i.jsx("div",{className:"flex flex-wrap items-center justify-center gap-3",children:c.map((x,e)=>{const r=t.entries[e];if(!r)return i.jsx("div",{className:"flex h-20 w-24 flex-col items-center justify-center rounded-xl border-2 border-dashed border-slate-700 text-[10px] text-slate-600",children:"empty"},`empty-${e}`);const n=t.hitKey===r.key,d=t.evictKey===r.key?"border-rose-400 bg-rose-500/15":n?"border-emerald-400 bg-emerald-500/15":"border-slate-600 bg-slate-800/70";return i.jsxs("div",{className:`flex h-20 w-24 flex-col items-center justify-center rounded-xl border-2 ${d} transition-all`,children:[i.jsxs("span",{className:"text-[9px] font-mono uppercase tracking-wide text-slate-400",children:["key ",r.key]}),i.jsx("span",{className:"mt-0.5 text-xl font-bold text-white",children:r.value}),e===0&&i.jsx("span",{className:"mt-0.5 text-[8px] font-mono text-emerald-400",children:"MRU"}),e===t.entries.length-1&&t.entries.length===t.capacity&&e!==0&&i.jsx("span",{className:"mt-0.5 text-[8px] font-mono text-rose-400",children:"LRU"})]},r.key)})}),t.missKey!=null&&i.jsxs("div",{className:"rounded-lg bg-rose-500/10 px-3 py-1 text-xs font-mono text-rose-300 ring-1 ring-rose-500/30",children:["MISS · key ",t.missKey," not present"]}),g.description&&i.jsx("div",{className:"w-full max-w-xl rounded-lg bg-slate-800/60 px-4 py-2 text-center text-xs leading-relaxed text-indigo-300",children:g.description}),g.meta&&g.meta.length>0&&i.jsx("div",{className:"flex flex-wrap justify-center gap-1.5",children:g.meta.map(x=>i.jsx("span",{className:"rounded-full bg-slate-800/80 px-2.5 py-0.5 text-[10px] font-mono text-slate-300 ring-1 ring-slate-700/50",children:x},x))})]})}const P=(g,t)=>Math.floor(Math.random()*(t-g+1))+g;function T(g,t=1,c=99){return Array.from({length:g},()=>P(t,c))}function Re(g){switch(g){case"find-middle":return T(P(5,9)).join(",");case"palindrome":{const t=T(P(2,3));if(Math.random()<.6){const c=Math.random()<.5?[P(1,9)]:[];return[...t,...c,...[...t].reverse()].join(",")}return T(P(4,7)).join(",")}case"lru-cache":{const t=P(2,3),c=[1,2,3,4,5],x=[];for(let e=0;e{const w=Re(t);e(w),m(w)};return i.jsxs("aside",{className:"w-full space-y-4 xl:w-80 xl:shrink-0",children:[i.jsxs("section",{className:"rounded-2xl border border-slate-700/50 bg-slate-900/60 p-4 backdrop-blur-sm",children:[i.jsx("h3",{className:"mb-2 text-xs font-semibold uppercase tracking-wider text-slate-400",children:"Input"}),i.jsx("label",{className:"text-[11px] text-slate-500",children:c.inputLabel}),i.jsx("textarea",{value:x,onChange:w=>e(w.target.value),rows:3,className:"mt-1 w-full resize-none rounded-xl bg-slate-950/70 px-3 py-2 text-xs font-mono text-slate-200 outline-none ring-1 ring-slate-700/50 focus:ring-indigo-500/50"}),i.jsx("p",{className:"mt-2 text-[10px] leading-relaxed text-slate-500",children:c.helper}),i.jsxs("div",{className:"mt-3 grid grid-cols-2 gap-2",children:[i.jsx("button",{onClick:()=>m(),className:"rounded-xl bg-indigo-500/20 px-3 py-2 text-xs font-semibold text-indigo-300 ring-1 ring-indigo-500/40 hover:bg-indigo-500/30",children:"Build Steps"}),i.jsxs("button",{onClick:L,className:"inline-flex items-center justify-center gap-1 rounded-xl bg-slate-800/70 px-3 py-2 text-xs font-semibold text-slate-300 ring-1 ring-slate-700/50 hover:bg-slate-700/70",children:[i.jsx(ne,{size:13})," Random"]})]})]}),i.jsxs("section",{className:"rounded-2xl border border-slate-700/50 bg-slate-900/60 p-4 backdrop-blur-sm",children:[i.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[i.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wider text-slate-400",children:"Playback"}),i.jsxs("span",{className:"font-mono text-xs text-indigo-300",children:[Math.min(n+1,r.length)," / ",r.length]})]}),i.jsx("div",{className:"h-2 overflow-hidden rounded-full bg-slate-800",children:i.jsx("div",{className:"h-full rounded-full bg-indigo-400 transition-all",style:{width:`${d}%`}})}),i.jsxs("div",{className:"mt-3 rounded-xl border border-slate-700/40 bg-slate-950/40 p-3",children:[i.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[i.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-wider text-slate-500",children:"Animation Speed"}),i.jsxs("span",{className:"font-mono text-[10px] text-indigo-300",children:[(p/1e3).toFixed(2),"s"]})]}),i.jsx("input",{type:"range",min:120,max:3e3,step:20,value:3120-p,onChange:w=>o(3120-Number(w.target.value)),className:"w-full accent-indigo-400","aria-label":"Animation speed"}),i.jsxs("div",{className:"mt-1 flex justify-between text-[9px] uppercase tracking-wide text-slate-600",children:[i.jsx("span",{children:"Slow"}),i.jsx("span",{children:"Fast"})]})]}),i.jsxs("div",{className:"mt-3 grid grid-cols-3 gap-2",children:[i.jsxs("button",{onClick:$,disabled:!R,className:"inline-flex items-center justify-center gap-1 rounded-xl bg-slate-800/70 px-2 py-2 text-xs text-slate-300 ring-1 ring-slate-700/50 disabled:opacity-30",children:[i.jsx(se,{size:13})," Back"]}),i.jsx("button",{onClick:v,className:`inline-flex items-center justify-center gap-1 rounded-xl px-2 py-2 text-xs font-semibold ring-1 ${s?"bg-amber-500/15 text-amber-300 ring-amber-500/30":"bg-emerald-500/15 text-emerald-300 ring-emerald-500/30"}`,children:s?i.jsxs(i.Fragment,{children:[i.jsx(ie,{size:13})," Pause"]}):i.jsxs(i.Fragment,{children:[i.jsx(re,{size:13})," Play"]})}),i.jsxs("button",{onClick:y,disabled:!b,className:"inline-flex items-center justify-center gap-1 rounded-xl bg-slate-800/70 px-2 py-2 text-xs text-slate-300 ring-1 ring-slate-700/50 disabled:opacity-30",children:["Next ",i.jsx(oe,{size:13})]})]}),i.jsxs("button",{onClick:f,className:"mt-2 inline-flex w-full items-center justify-center gap-1 rounded-xl bg-slate-800/70 px-3 py-2 text-xs text-slate-300 ring-1 ring-slate-700/50 hover:bg-slate-700/70",children:[i.jsx(le,{size:13})," Reset"]}),i.jsx("p",{className:"mt-3 min-h-10 text-xs leading-relaxed text-slate-300",children:l?.description})]}),i.jsxs("section",{className:"rounded-2xl border border-slate-700/50 bg-slate-900/60 p-4 backdrop-blur-sm",children:[i.jsxs("button",{onClick:()=>h(!a),className:`inline-flex w-full items-center justify-center gap-2 rounded-xl px-3 py-2 text-xs font-semibold ring-1 ${a?"bg-indigo-500/15 text-indigo-300 ring-indigo-500/30":"bg-slate-800/70 text-slate-400 ring-slate-700/40"}`,children:[a?i.jsx(ae,{size:14}):i.jsx(de,{size:14}),a?"Sound On":"Sound Off"]}),i.jsx("div",{className:"mt-3 flex flex-wrap gap-1.5",children:c.tags.map(w=>i.jsx("span",{className:"rounded-full bg-violet-500/10 px-2 py-0.5 text-[10px] font-medium text-violet-300 ring-1 ring-violet-500/20",children:w},w))}),i.jsx("p",{className:"mt-2 text-[10px] font-mono text-slate-500",children:c.complexity})]})]})}function Ke({problem:g}){const t=be(g),{info:c}=t;return i.jsxs("div",{className:"flex flex-1 flex-col gap-4 overflow-auto p-4 md:p-6 xl:flex-row",children:[i.jsxs("main",{className:"order-last flex min-h-[520px] flex-1 flex-col gap-4 xl:order-first",children:[i.jsxs("section",{className:"rounded-2xl border border-slate-700/50 bg-slate-900/60 p-5 backdrop-blur-sm",children:[i.jsxs(Q,{to:"/algorithms/linked-list",className:"mb-3 inline-flex items-center gap-1.5 text-xs font-medium text-slate-400 transition-colors hover:text-indigo-300",children:[i.jsx(ce,{size:13})," Linked List Algorithms"]}),i.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-[0.24em] text-indigo-300",children:"Linked List Algorithms"}),i.jsx("h2",{className:"mt-1 text-xl font-bold text-white",children:c.title}),i.jsx("p",{className:"mt-1 text-sm text-slate-400",children:c.subtitle})]}),i.jsx("section",{className:"flex flex-1 items-center justify-center rounded-2xl border border-slate-700/50 bg-slate-900/40 p-4 backdrop-blur-sm",children:i.jsx(ke,{step:t.currentStep})}),i.jsx(te,{pseudocode:c.pseudocode,activeLine:t.currentStep?.codeLine??null})]}),i.jsx(Ae,{hook:t,problem:g})]})}export{Ke as default};
diff --git a/docs/assets/LinkedListAlgorithmsPage-bVyDUoFQ.js b/docs/assets/LinkedListAlgorithmsPage-CUxv2ABR.js
similarity index 95%
rename from docs/assets/LinkedListAlgorithmsPage-bVyDUoFQ.js
rename to docs/assets/LinkedListAlgorithmsPage-CUxv2ABR.js
index feed259..723e38d 100644
--- a/docs/assets/LinkedListAlgorithmsPage-bVyDUoFQ.js
+++ b/docs/assets/LinkedListAlgorithmsPage-CUxv2ABR.js
@@ -1 +1 @@
-import{c as a,j as e,L as r,N as c,G as d,a as x,S as m,b as h,A as p}from"./index-eCXyAnHs.js";import{P as g}from"./linkedListAlgo-0_WYfSZm.js";import{A as f}from"./arrow-left-DiyrXoev.js";import{R as u}from"./rotate-ccw-B8GZP3d7.js";const k=[["path",{d:"m17 2 4 4-4 4",key:"nntrym"}],["path",{d:"M3 11v-1a4 4 0 0 1 4-4h14",key:"84bu3i"}],["path",{d:"m7 22-4-4 4-4",key:"1wqhfi"}],["path",{d:"M21 13v1a4 4 0 0 1-4 4H3",key:"1rx37r"}]],w=a("repeat",k);const y=[["circle",{cx:"6",cy:"6",r:"3",key:"1lh9wr"}],["path",{d:"M8.12 8.12 12 12",key:"1alkpv"}],["path",{d:"M20 4 8.12 15.88",key:"xgtan2"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}],["path",{d:"M14.8 14.8 20 20",key:"ptml3r"}]],b=a("scissors",y);const j=[["path",{d:"M17.971 4.285A2 2 0 0 1 21 6v12a2 2 0 0 1-3.029 1.715l-9.997-5.998a2 2 0 0 1-.003-3.432z",key:"15892j"}],["path",{d:"M3 20V4",key:"1ptbpl"}]],N=a("skip-back",j);const v=[["circle",{cx:"19",cy:"5",r:"2",key:"mhkx31"}],["circle",{cx:"5",cy:"19",r:"2",key:"v8kfzx"}],["path",{d:"M5 17A12 12 0 0 1 17 5",key:"1okkup"}]],L=a("spline",v),C={"find-middle":{gradient:"from-sky-500 to-cyan-500",shadowColor:"shadow-sky-500/20",icon:h},"reverse-list":{gradient:"from-rose-500 to-pink-500",shadowColor:"shadow-rose-500/20",icon:u},"add-two-numbers":{gradient:"from-blue-500 to-indigo-500",shadowColor:"shadow-blue-500/20",icon:m},"reverse-k-group":{gradient:"from-purple-500 to-fuchsia-500",shadowColor:"shadow-purple-500/20",icon:N},palindrome:{gradient:"from-fuchsia-500 to-pink-500",shadowColor:"shadow-fuchsia-500/20",icon:L},"lru-cache":{gradient:"from-emerald-500 to-teal-500",shadowColor:"shadow-emerald-500/20",icon:x},segregate:{gradient:"from-lime-500 to-green-500",shadowColor:"shadow-lime-500/20",icon:b},"detect-cycle":{gradient:"from-amber-500 to-orange-500",shadowColor:"shadow-amber-500/20",icon:w},"sort-list":{gradient:"from-indigo-500 to-violet-500",shadowColor:"shadow-indigo-500/20",icon:d}},R=["find-middle","reverse-list","add-two-numbers","reverse-k-group","palindrome","lru-cache","segregate","detect-cycle","sort-list"];function z(){return e.jsxs("div",{className:"flex-1 overflow-y-auto",children:[e.jsxs("section",{className:"flex flex-col items-center justify-center px-6 pt-12 pb-8 text-center",children:[e.jsxs(r,{to:"/algorithms",className:"mb-4 inline-flex items-center gap-1.5 rounded-full bg-slate-800/60 px-3 py-1.5 text-xs font-medium text-slate-400 ring-1 ring-slate-700/50 transition-colors hover:text-indigo-300",children:[e.jsx(f,{size:13})," Back to Algorithms"]}),e.jsxs("div",{className:"mb-4 inline-flex items-center gap-2 rounded-full bg-indigo-500/10 px-4 py-1.5 ring-1 ring-indigo-500/20",children:[e.jsx(c,{size:14,className:"text-indigo-400"}),e.jsx("span",{className:"text-xs font-medium text-indigo-300",children:"Linked List Algorithms"})]}),e.jsxs("h2",{className:"text-3xl font-extrabold tracking-tight text-white",children:["Linked ",e.jsx("span",{className:"bg-gradient-to-r from-indigo-400 to-fuchsia-400 bg-clip-text text-transparent",children:"List"})]}),e.jsx("p",{className:"mt-3 max-w-2xl mx-auto text-sm text-slate-400 leading-relaxed",children:"Two-pointer tricks, Floyd's cycle detection, merge sort, and an LRU cache — each with step playback, a speed slider, and audio feedback."})]}),e.jsx("section",{className:"px-6 pb-12",children:e.jsx("div",{className:"mx-auto grid max-w-6xl grid-cols-1 gap-5 sm:grid-cols-2 lg:grid-cols-3",children:R.map(t=>{const s=g[t],{gradient:l,shadowColor:o,icon:n}=C[t];return e.jsxs(r,{to:`/algorithms/linked-list/${t}`,className:`group relative flex flex-col rounded-2xl border border-slate-700/40 bg-slate-900/50 p-6 shadow-lg backdrop-blur-sm transition-all duration-300 hover:scale-[1.01] hover:border-slate-600/60 hover:bg-slate-900/70 ${o}`,children:[e.jsx("div",{className:`mb-3 flex h-11 w-11 items-center justify-center rounded-xl bg-gradient-to-br ${l} shadow-lg ${o}`,children:e.jsx(n,{size:20,className:"text-white"})}),e.jsx("h4",{className:"text-base font-bold text-white",children:s.title}),e.jsx("p",{className:"text-[10px] text-slate-500 italic",children:s.subtitle}),e.jsx("p",{className:"mt-2 flex-1 text-xs leading-relaxed text-slate-400",children:s.helper}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-1.5",children:s.tags.map(i=>e.jsx("span",{className:"rounded-full bg-slate-800/60 px-2 py-0.5 text-[10px] font-medium text-slate-400",children:i},i))}),e.jsxs("div",{className:"mt-3 flex items-center gap-1 text-xs font-medium text-indigo-400 opacity-0 transition-opacity group-hover:opacity-100",children:["Explore ",e.jsx(p,{size:12})]})]},t)})})})]})}export{z as default};
+import{c as a,j as e,L as r,N as c,G as d,a as x,S as m,b as h,A as p}from"./index-DBkLeWDs.js";import{P as g}from"./linkedListAlgo-0_WYfSZm.js";import{A as f}from"./arrow-left-CTMPG6pL.js";import{R as u}from"./rotate-ccw-7GTUOPy4.js";const k=[["path",{d:"m17 2 4 4-4 4",key:"nntrym"}],["path",{d:"M3 11v-1a4 4 0 0 1 4-4h14",key:"84bu3i"}],["path",{d:"m7 22-4-4 4-4",key:"1wqhfi"}],["path",{d:"M21 13v1a4 4 0 0 1-4 4H3",key:"1rx37r"}]],w=a("repeat",k);const y=[["circle",{cx:"6",cy:"6",r:"3",key:"1lh9wr"}],["path",{d:"M8.12 8.12 12 12",key:"1alkpv"}],["path",{d:"M20 4 8.12 15.88",key:"xgtan2"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}],["path",{d:"M14.8 14.8 20 20",key:"ptml3r"}]],b=a("scissors",y);const j=[["path",{d:"M17.971 4.285A2 2 0 0 1 21 6v12a2 2 0 0 1-3.029 1.715l-9.997-5.998a2 2 0 0 1-.003-3.432z",key:"15892j"}],["path",{d:"M3 20V4",key:"1ptbpl"}]],N=a("skip-back",j);const v=[["circle",{cx:"19",cy:"5",r:"2",key:"mhkx31"}],["circle",{cx:"5",cy:"19",r:"2",key:"v8kfzx"}],["path",{d:"M5 17A12 12 0 0 1 17 5",key:"1okkup"}]],L=a("spline",v),C={"find-middle":{gradient:"from-sky-500 to-cyan-500",shadowColor:"shadow-sky-500/20",icon:h},"reverse-list":{gradient:"from-rose-500 to-pink-500",shadowColor:"shadow-rose-500/20",icon:u},"add-two-numbers":{gradient:"from-blue-500 to-indigo-500",shadowColor:"shadow-blue-500/20",icon:m},"reverse-k-group":{gradient:"from-purple-500 to-fuchsia-500",shadowColor:"shadow-purple-500/20",icon:N},palindrome:{gradient:"from-fuchsia-500 to-pink-500",shadowColor:"shadow-fuchsia-500/20",icon:L},"lru-cache":{gradient:"from-emerald-500 to-teal-500",shadowColor:"shadow-emerald-500/20",icon:x},segregate:{gradient:"from-lime-500 to-green-500",shadowColor:"shadow-lime-500/20",icon:b},"detect-cycle":{gradient:"from-amber-500 to-orange-500",shadowColor:"shadow-amber-500/20",icon:w},"sort-list":{gradient:"from-indigo-500 to-violet-500",shadowColor:"shadow-indigo-500/20",icon:d}},R=["find-middle","reverse-list","add-two-numbers","reverse-k-group","palindrome","lru-cache","segregate","detect-cycle","sort-list"];function z(){return e.jsxs("div",{className:"flex-1 overflow-y-auto",children:[e.jsxs("section",{className:"flex flex-col items-center justify-center px-6 pt-12 pb-8 text-center",children:[e.jsxs(r,{to:"/algorithms",className:"mb-4 inline-flex items-center gap-1.5 rounded-full bg-slate-800/60 px-3 py-1.5 text-xs font-medium text-slate-400 ring-1 ring-slate-700/50 transition-colors hover:text-indigo-300",children:[e.jsx(f,{size:13})," Back to Algorithms"]}),e.jsxs("div",{className:"mb-4 inline-flex items-center gap-2 rounded-full bg-indigo-500/10 px-4 py-1.5 ring-1 ring-indigo-500/20",children:[e.jsx(c,{size:14,className:"text-indigo-400"}),e.jsx("span",{className:"text-xs font-medium text-indigo-300",children:"Linked List Algorithms"})]}),e.jsxs("h2",{className:"text-3xl font-extrabold tracking-tight text-white",children:["Linked ",e.jsx("span",{className:"bg-gradient-to-r from-indigo-400 to-fuchsia-400 bg-clip-text text-transparent",children:"List"})]}),e.jsx("p",{className:"mt-3 max-w-2xl mx-auto text-sm text-slate-400 leading-relaxed",children:"Two-pointer tricks, Floyd's cycle detection, merge sort, and an LRU cache — each with step playback, a speed slider, and audio feedback."})]}),e.jsx("section",{className:"px-6 pb-12",children:e.jsx("div",{className:"mx-auto grid max-w-6xl grid-cols-1 gap-5 sm:grid-cols-2 lg:grid-cols-3",children:R.map(t=>{const s=g[t],{gradient:l,shadowColor:o,icon:n}=C[t];return e.jsxs(r,{to:`/algorithms/linked-list/${t}`,className:`group relative flex flex-col rounded-2xl border border-slate-700/40 bg-slate-900/50 p-6 shadow-lg backdrop-blur-sm transition-all duration-300 hover:scale-[1.01] hover:border-slate-600/60 hover:bg-slate-900/70 ${o}`,children:[e.jsx("div",{className:`mb-3 flex h-11 w-11 items-center justify-center rounded-xl bg-gradient-to-br ${l} shadow-lg ${o}`,children:e.jsx(n,{size:20,className:"text-white"})}),e.jsx("h4",{className:"text-base font-bold text-white",children:s.title}),e.jsx("p",{className:"text-[10px] text-slate-500 italic",children:s.subtitle}),e.jsx("p",{className:"mt-2 flex-1 text-xs leading-relaxed text-slate-400",children:s.helper}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-1.5",children:s.tags.map(i=>e.jsx("span",{className:"rounded-full bg-slate-800/60 px-2 py-0.5 text-[10px] font-medium text-slate-400",children:i},i))}),e.jsxs("div",{className:"mt-3 flex items-center gap-1 text-xs font-medium text-indigo-400 opacity-0 transition-opacity group-hover:opacity-100",children:["Explore ",e.jsx(p,{size:12})]})]},t)})})})]})}export{z as default};
diff --git a/docs/assets/LinkedListPage-DDic5oaj.js b/docs/assets/LinkedListPage-CPh-u55R.js
similarity index 97%
rename from docs/assets/LinkedListPage-DDic5oaj.js
rename to docs/assets/LinkedListPage-CPh-u55R.js
index 6b9cb0f..261e517 100644
--- a/docs/assets/LinkedListPage-DDic5oaj.js
+++ b/docs/assets/LinkedListPage-CPh-u55R.js
@@ -1 +1 @@
-import{r as a,j as e,e as de}from"./index-eCXyAnHs.js";import{u as ce}from"./useDSSound-CIDAFkgj.js";import{P as K}from"./plus-CffLiizr.js";import{T as xe}from"./trash-2-DQ8BZrIf.js";import{R as ue}from"./rotate-ccw-B8GZP3d7.js";import{S as he}from"./shuffle-CdKU4ZYx.js";import{V as ge,a as pe}from"./volume-x-CTbtCvt-.js";import{C as me,a as fe}from"./chevron-right-BZqZw4c2.js";import"./audioContext-NbgqvQGz.js";let U=1;const be=[3,7,1,9].map(p=>({id:U++,value:p}));function je(){const[p,m]=a.useState(be),[c,H]=a.useState("singly"),[h,y]=a.useState([]),[x,r]=a.useState(-1),[S,M]=a.useState(""),[V,X]=a.useState(""),[G,P]=a.useState([]),[j,A]=a.useState(400),[n,C]=a.useState(!1),$=a.useRef(null),R=a.useRef(j),v=a.useRef(!1),{soundEnabled:o,toggleSound:F,playInsert:N,playDelete:I,playTraverse:k,playFound:T,playNotFound:D}=ce(),B=a.useRef(N),Y=a.useRef(I),q=a.useRef(k);a.useEffect(()=>{B.current=N},[N]),a.useEffect(()=>{Y.current=I},[I]),a.useEffect(()=>{q.current=k},[k]),a.useEffect(()=>{R.current=j},[j]),a.useEffect(()=>{if(!v.current||h.length===0)return;v.current=!1,$.current&&clearTimeout($.current),C(!0);let t=0;const s=()=>{if(t>=h.length-1){C(!1);return}t++,r(t);const i=h[t];i&&(i.highlightColor==="green"?B.current():i.highlightColor==="red"?Y.current():i.highlightColor==="yellow"&&q.current(t,h.length)),$.current=setTimeout(s,R.current)};$.current=setTimeout(s,R.current)},[h]);const J=x>=0&&h[x]?h[x].nodes:p,l=x>=0?h[x]:null,E=c==="singly"?"singly linked list":c==="doubly"?"doubly linked list":"circular linked list",O=t=>P(s=>[t,...s].slice(0,20)),Q=a.useCallback(t=>{H(t),y([]),r(-1),C(!1),P(s=>[`Switch to ${t}`,...s].slice(0,20))},[]),w=(t,s,i=[],d=null,u=null)=>({description:t,nodes:s,highlightIds:new Set(i),highlightColor:d,newNodeId:u}),Z=a.useCallback(t=>{const s={id:U++,value:t};m(i=>{const d=[s,...i],u=[w(`Prepend ${t}: creating new node at head in the ${E}...`,i,[],null,s.id),w(`${t} inserted at position 0. Updating ${c==="doubly"?"prev/next pointers":c==="circular"?"tail.next back to head":"head pointer"}.`,d,[s.id],"green",s.id)];return y(u),r(0),v.current=!0,N(),O(`Prepend ${t}`),d})},[N,c,E]),ee=a.useCallback(t=>{const s={id:U++,value:t};m(i=>{const d=[...i,s],u=[];for(let f=0;f{const i={id:U++,value:t};m(d=>{if(s<0||s>d.length)return d;const u=[...d.slice(0,s),i,...d.slice(s)],f=[];for(let W=0;W{m(s=>{if(t<0||t>=s.length)return s;const i=s[t],d=[];for(let f=0;f<=t;f++)d.push(w(`Traversing to index ${t}: at node ${s[f].value}...`,s,[s[f].id],"yellow"));d.push(w(`Deleting node ${i.value} at index ${t}: re-linking ${c==="doubly"?"prev and next pointers":c==="circular"?"cycle pointers":"next pointer"}.`,s,[i.id],"red"));const u=s.filter((f,W)=>W!==t);return d.push(w(`Node ${i.value} removed. List size: ${u.length}`,u,[],null)),y(d),r(0),v.current=!0,I(),O(`Delete [${t}] → ${i.value}`),u})},[I,c]),le=a.useCallback(t=>{m(s=>{const i=[];let d=-1;for(let u=0;u{m([]),y([]),r(-1),O("Clear list")},[]),ae=a.useCallback(()=>{const t=Math.floor(Math.random()*4)+4,s=Array.from({length:t},()=>({id:U++,value:Math.floor(Math.random()*90)+1}));m(s),y([]),r(-1),O("Random list")},[]),ie=a.useCallback(()=>{r(t=>Math.min(t+1,h.length-1))},[h.length]),re=a.useCallback(()=>{r(t=>Math.max(t-1,0))},[]),oe=a.useCallback(()=>{if(n){C(!1),$.current&&clearTimeout($.current);return}if(x>=h.length-1)return;C(!0);let t=x;const s=()=>{if(t>=h.length-1){C(!1);return}t++,r(t),$.current=setTimeout(s,j)};$.current=setTimeout(s,j)},[n,x,h.length,j]);return{nodes:p,variant:c,changeVariant:Q,displayNodes:J,steps:h,stepIndex:x,currentStep:l,inputValue:S,setInputValue:M,indexValue:V,setIndexValue:X,history:G,speed:j,setSpeed:A,isPlaying:n,prepend:Z,append:ee,insertAt:te,deleteAt:se,search:le,clear:ne,generateRandom:ae,nextStep:ie,prevStep:re,autoPlay:oe,canGoNext:x0,soundEnabled:o,toggleSound:F}}const ye={green:{border:"#34d399",bg:"rgba(52,211,153,0.15)",text:"#6ee7b7"},red:{border:"#f87171",bg:"rgba(248,113,113,0.15)",text:"#fca5a5"},yellow:{border:"#fbbf24",bg:"rgba(251,191,36,0.15)",text:"#fde68a"},blue:{border:"#60a5fa",bg:"rgba(96,165,250,0.15)",text:"#93c5fd"}},Ne={border:"#475569",bg:"rgba(30,41,59,0.7)",text:"#cbd5e1"},b=64,g=48,L=36,z=b+L,_=5;function ve({nodes:p,currentStep:m,variant:c}){const H=m?.highlightIds??new Set,h=m?.highlightColor??null,y=[];for(let j=0;j{const n=A*r+20,C=A===y.length-1,$=A*_;return e.jsx("g",{children:j.map((R,v)=>{const o=v*z+L/2,F=H.has(R.id),N=F&&h?ye[h]:Ne,I=$+v,k=I===0,T=I===p.length-1,D=v===j.length-1;return e.jsxs("g",{children:[k&&e.jsx("text",{x:o+b/2,y:n-8,textAnchor:"middle",fontSize:"10",fill:"#818cf8",fontFamily:"monospace",children:"head"}),e.jsx("rect",{x:o,y:n,width:b,height:g,rx:8,fill:N.bg,stroke:N.border,strokeWidth:F?2:1.5}),e.jsx("text",{x:o+b*.38,y:n+g/2+5,textAnchor:"middle",fontSize:"15",fontWeight:"bold",fill:N.text,fontFamily:"sans-serif",children:R.value}),e.jsx("line",{x1:o+b*.62,y1:n+4,x2:o+b*.62,y2:n+g-4,stroke:N.border,strokeWidth:1,opacity:.5}),e.jsx("text",{x:o+b*.82,y:n+g/2+4,textAnchor:"middle",fontSize:"9",fill:"#64748b",fontFamily:"monospace",children:T?c==="circular"?"↺":"null":"→"}),c==="doubly"&&e.jsx("text",{x:o+b*.2,y:n+g-7,textAnchor:"middle",fontSize:"8",fill:"#93c5fd",fontFamily:"monospace",children:k?"null":"←"}),!T&&!D&&e.jsxs("g",{children:[e.jsx("line",{x1:o+b,y1:n+g/2,x2:o+z,y2:n+g/2,stroke:"#475569",strokeWidth:1.5}),e.jsx("polygon",{points:`${o+z},${n+g/2} ${o+z-6},${n+g/2-4} ${o+z-6},${n+g/2+4}`,fill:"#475569"})]}),c==="doubly"&&!T&&!D&&e.jsxs("g",{opacity:.75,children:[e.jsx("line",{x1:o+z,y1:n+g/2+12,x2:o+b,y2:n+g/2+12,stroke:"#60a5fa",strokeWidth:1.2}),e.jsx("polygon",{points:`${o+b},${n+g/2+12} ${o+b+6},${n+g/2+8} ${o+b+6},${n+g/2+16}`,fill:"#60a5fa"})]}),D&&!C&&e.jsxs("g",{children:[e.jsx("path",{d:`M ${o+b} ${n+g/2} L ${o+b+14} ${n+g/2} L ${o+b+14} ${n+g+20} L ${L/2} ${n+g+20} L ${L/2} ${n+r}`,fill:"none",stroke:"#475569",strokeWidth:1.5}),e.jsx("polygon",{points:`${L/2},${n+r} ${L/2-4},${n+r-6} ${L/2+4},${n+r-6}`,fill:"#475569"})]})]},R.id)})},A)}),c==="circular"&&y.length>0&&p.length>1&&e.jsxs("g",{children:[e.jsx("path",{d:`M ${G+b} ${P+g/2} C ${x+40} ${S+16}, -20 ${S+16}, ${L/2+b/2} 78`,fill:"none",stroke:"#f59e0b",strokeDasharray:"5 5",strokeWidth:1.5}),e.jsx("text",{x:x/2,y:S-4,textAnchor:"middle",fontSize:"10",fill:"#fbbf24",fontFamily:"monospace",children:"tail.next → head"})]})]}),m?.description&&e.jsx("div",{className:"w-full max-w-sm rounded-lg bg-slate-800/60 px-4 py-2 text-center text-xs text-indigo-300 leading-relaxed",children:m.description}),e.jsxs("div",{className:"text-xs text-slate-500 font-mono",children:[c," list · length = ",p.length]})]})}const $e=[{label:"Slow",value:700},{label:"Med",value:350},{label:"Fast",value:120}];function ke({hook:p}){const{nodes:m,variant:c,changeVariant:H,steps:h,stepIndex:y,inputValue:x,setInputValue:r,indexValue:S,setIndexValue:M,history:V,speed:X,setSpeed:G,isPlaying:P,prepend:j,append:A,insertAt:n,deleteAt:C,search:$,clear:R,generateRandom:v,nextStep:o,prevStep:F,canGoNext:N,canGoPrev:I,soundEnabled:k,toggleSound:T}=p,D=()=>{const l=parseInt(x);isNaN(l)||(j(l),r(""))},B=()=>{const l=parseInt(x);isNaN(l)||(A(l),r(""))},Y=()=>{const l=parseInt(x),E=parseInt(S);!isNaN(l)&&!isNaN(E)&&(n(l,E),r(""))},q=()=>{const l=parseInt(S);isNaN(l)||C(l)},J=()=>{const l=parseInt(x);isNaN(l)||$(l)};return e.jsxs("div",{className:"flex flex-col gap-4 w-full md:w-72 shrink-0 overflow-y-auto max-h-full pr-1",children:[e.jsxs("div",{className:"rounded-xl border border-slate-700/50 bg-slate-900/60 p-4 backdrop-blur-sm",children:[e.jsx("h3",{className:"text-sm font-bold text-indigo-300 mb-1",children:"Linked List"}),e.jsxs("p",{className:"text-xs text-slate-400 leading-relaxed",children:["A chain of ",e.jsx("strong",{className:"text-slate-300",children:"nodes"}),". Switch between singly, doubly, and circular pointer layouts while keeping the same operations."]}),e.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:["Prepend O(1)","Append O(n)","Insert O(n)","Delete O(n)","Search O(n)"].map(l=>e.jsx("span",{className:"rounded-full bg-violet-500/10 px-2 py-0.5 text-[10px] font-medium text-violet-400 ring-1 ring-violet-500/20",children:l},l))})]}),e.jsxs("div",{className:"rounded-xl border border-slate-700/50 bg-slate-900/60 p-4 backdrop-blur-sm",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wider text-slate-400 mb-3",children:"List Type"}),e.jsx("div",{className:"grid grid-cols-3 gap-1",children:["singly","doubly","circular"].map(l=>e.jsx("button",{onClick:()=>H(l),className:`rounded-lg px-2 py-2 text-[10px] font-semibold capitalize transition-all ${c===l?"bg-indigo-500/20 text-indigo-300 ring-1 ring-indigo-500/40":"bg-slate-800/60 text-slate-400 hover:bg-slate-700/60"}`,children:l},l))}),e.jsx("p",{className:"mt-2 text-[10px] leading-relaxed text-slate-500",children:"Doubly lists show backward pointers; circular lists connect the tail back to the head."})]}),e.jsxs("div",{className:"rounded-xl border border-slate-700/50 bg-slate-900/60 p-4 backdrop-blur-sm",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wider text-slate-400 mb-3",children:"Operations"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 mb-3",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("label",{className:"text-[10px] text-slate-500 uppercase tracking-wider",children:"Value"}),e.jsx("input",{type:"number",value:x,onChange:l=>r(l.target.value),placeholder:"e.g. 42",className:"w-full rounded-lg bg-slate-800/60 px-3 py-2 text-sm text-slate-200 placeholder-slate-600 outline-none ring-1 ring-slate-700/50 focus:ring-indigo-500/50 transition-all"})]}),e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("label",{className:"text-[10px] text-slate-500 uppercase tracking-wider",children:"Index"}),e.jsx("input",{type:"number",value:S,onChange:l=>M(l.target.value),placeholder:"e.g. 0",min:"0",className:"w-full rounded-lg bg-slate-800/60 px-3 py-2 text-sm text-slate-200 placeholder-slate-600 outline-none ring-1 ring-slate-700/50 focus:ring-indigo-500/50 transition-all"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("button",{onClick:D,disabled:m.length>=12,className:"flex items-center justify-center gap-1.5 rounded-lg bg-gradient-to-r from-emerald-500/80 to-green-500/80 px-3 py-2 text-xs font-semibold text-white shadow-lg shadow-emerald-500/15 transition-all hover:brightness-110 active:scale-[0.98] disabled:opacity-40 disabled:cursor-not-allowed",children:[e.jsx(K,{size:13})," Prepend"]}),e.jsxs("button",{onClick:B,disabled:m.length>=12,className:"flex items-center justify-center gap-1.5 rounded-lg bg-indigo-500/20 px-3 py-2 text-xs font-semibold text-indigo-300 ring-1 ring-indigo-500/30 transition-all hover:bg-indigo-500/30 active:scale-[0.98] disabled:opacity-40 disabled:cursor-not-allowed",children:[e.jsx(K,{size:13})," Append"]}),e.jsxs("button",{onClick:Y,disabled:m.length>=12,className:"flex items-center justify-center gap-1.5 rounded-lg bg-violet-500/20 px-3 py-2 text-xs font-semibold text-violet-300 ring-1 ring-violet-500/30 transition-all hover:bg-violet-500/30 active:scale-[0.98] disabled:opacity-40 disabled:cursor-not-allowed",children:[e.jsx(K,{size:13})," Insert at"]}),e.jsxs("button",{onClick:q,disabled:m.length===0,className:"flex items-center justify-center gap-1.5 rounded-lg bg-gradient-to-r from-rose-500/80 to-pink-500/80 px-3 py-2 text-xs font-semibold text-white shadow-lg shadow-rose-500/15 transition-all hover:brightness-110 active:scale-[0.98] disabled:opacity-40 disabled:cursor-not-allowed",children:[e.jsx(xe,{size:13})," Delete at"]}),e.jsxs("button",{onClick:J,disabled:m.length===0,className:"flex items-center justify-center gap-1.5 rounded-lg bg-amber-500/20 px-3 py-2 text-xs font-semibold text-amber-300 ring-1 ring-amber-500/30 transition-all hover:bg-amber-500/30 active:scale-[0.98] disabled:opacity-40 disabled:cursor-not-allowed",children:[e.jsx(de,{size:13})," Search"]}),e.jsxs("button",{onClick:R,disabled:m.length===0,className:"flex items-center justify-center gap-1.5 rounded-lg bg-slate-800/60 px-3 py-2 text-xs font-medium text-slate-400 transition-all hover:bg-slate-700/60 disabled:opacity-40 disabled:cursor-not-allowed",children:[e.jsx(ue,{size:13})," Clear"]})]}),e.jsxs("button",{onClick:v,className:"mt-2 w-full flex items-center justify-center gap-1.5 rounded-lg bg-slate-800/60 px-3 py-2 text-xs font-medium text-slate-400 transition-all hover:bg-slate-700/60 hover:text-slate-300",children:[e.jsx(he,{size:12})," Random List"]}),e.jsxs("button",{onClick:()=>T(!k),className:`mt-2 w-full flex items-center justify-center gap-1.5 rounded-lg px-3 py-2 text-xs font-medium transition-all ${k?"bg-indigo-500/15 text-indigo-300 ring-1 ring-indigo-500/30":"bg-slate-800/60 text-slate-400 hover:bg-slate-700/60"}`,children:[k?e.jsx(ge,{size:12}):e.jsx(pe,{size:12}),k?"Sound On":"Sound Off"]})]}),e.jsxs("div",{className:"rounded-xl border border-slate-700/50 bg-slate-900/60 p-4 backdrop-blur-sm",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wider text-slate-400 mb-3",children:"Animation Speed"}),e.jsx("div",{className:"flex gap-1",children:$e.map(l=>e.jsx("button",{onClick:()=>G(l.value),className:`flex-1 rounded-lg px-2 py-1.5 text-xs font-medium transition-all duration-200 ${X===l.value?"bg-violet-500/20 text-violet-300 ring-1 ring-violet-500/40":"bg-slate-800/50 text-slate-400 hover:bg-slate-700/50 hover:text-slate-300"}`,children:l.label},l.value))})]}),h.length>0&&e.jsxs("div",{className:"rounded-xl border border-slate-700/50 bg-slate-900/60 p-4 backdrop-blur-sm",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wider text-slate-400 mb-3",children:"Step Through"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{onClick:F,disabled:!I||P,className:"flex-1 flex items-center justify-center gap-1 rounded-lg bg-slate-800/60 px-3 py-2.5 text-sm font-medium text-slate-400 transition-all hover:bg-slate-700/60 hover:text-slate-300 disabled:opacity-30 disabled:cursor-not-allowed",children:[e.jsx(me,{size:16})," Prev"]}),e.jsxs("button",{onClick:o,disabled:!N||P,className:"flex-1 flex items-center justify-center gap-1 rounded-lg bg-slate-800/60 px-3 py-2.5 text-sm font-medium text-slate-400 transition-all hover:bg-slate-700/60 hover:text-slate-300 disabled:opacity-30 disabled:cursor-not-allowed",children:["Next ",e.jsx(fe,{size:16})]})]}),e.jsxs("div",{className:"mt-2 flex items-center justify-between",children:[e.jsx("span",{className:"text-xs text-slate-500",children:"Step"}),e.jsxs("span",{className:"text-sm font-mono font-semibold text-indigo-400",children:[Math.max(0,y+1)," / ",h.length]})]})]}),V.length>0&&e.jsxs("div",{className:"rounded-xl border border-slate-700/50 bg-slate-900/60 p-4 backdrop-blur-sm",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wider text-slate-400 mb-3",children:"History"}),e.jsx("div",{className:"max-h-36 overflow-y-auto space-y-1",children:V.map((l,E)=>e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("span",{className:"font-mono text-slate-600 w-4 text-right",children:E+1}),e.jsx("span",{className:l.startsWith("Prepend")||l.startsWith("Append")||l.startsWith("Insert")?"text-emerald-400":l.startsWith("Delete")?"text-rose-400":l.startsWith("Search")?"text-amber-400":"text-slate-400",children:l})]},E))})]}),e.jsxs("div",{className:"rounded-xl border border-slate-700/50 bg-slate-900/60 p-4 backdrop-blur-sm",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wider text-slate-400 mb-3",children:"Legend"}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"h-3 w-5 rounded-sm bg-emerald-500"}),e.jsx("span",{className:"text-xs text-slate-400",children:"Insert / found"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"h-3 w-5 rounded-sm bg-rose-500"}),e.jsx("span",{className:"text-xs text-slate-400",children:"Delete"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"h-3 w-5 rounded-sm bg-amber-400"}),e.jsx("span",{className:"text-xs text-slate-400",children:"Traversal / search"})]})]})]})]})}function Ee(){const p=je();return e.jsxs("div",{className:"flex flex-1 flex-col md:flex-row gap-4 md:gap-6 overflow-auto p-4 md:p-6",children:[e.jsx("div",{className:"order-last md:order-first flex md:flex-1 flex-col items-center justify-center gap-3 min-h-[40vh] md:min-h-0 max-h-[55vh] md:max-h-none overflow-auto",children:e.jsx(ve,{nodes:p.displayNodes,currentStep:p.currentStep,variant:p.variant})}),e.jsx(ke,{hook:p})]})}export{Ee as default};
+import{r as a,j as e,d as de}from"./index-DBkLeWDs.js";import{u as ce}from"./useDSSound-KKipmh13.js";import{P as K}from"./plus-DVazsZHX.js";import{T as xe}from"./trash-2-C6_cMdiI.js";import{R as ue}from"./rotate-ccw-7GTUOPy4.js";import{S as he}from"./shuffle-Dlr-c52A.js";import{V as ge,a as pe}from"./volume-x-BSx9gxSg.js";import{C as me,a as fe}from"./chevron-right-CFBAUJsk.js";import"./audioContext-NbgqvQGz.js";let U=1;const be=[3,7,1,9].map(p=>({id:U++,value:p}));function je(){const[p,m]=a.useState(be),[c,H]=a.useState("singly"),[h,y]=a.useState([]),[x,r]=a.useState(-1),[S,M]=a.useState(""),[V,X]=a.useState(""),[G,P]=a.useState([]),[j,A]=a.useState(400),[n,C]=a.useState(!1),$=a.useRef(null),R=a.useRef(j),v=a.useRef(!1),{soundEnabled:o,toggleSound:F,playInsert:N,playDelete:I,playTraverse:k,playFound:T,playNotFound:D}=ce(),B=a.useRef(N),Y=a.useRef(I),q=a.useRef(k);a.useEffect(()=>{B.current=N},[N]),a.useEffect(()=>{Y.current=I},[I]),a.useEffect(()=>{q.current=k},[k]),a.useEffect(()=>{R.current=j},[j]),a.useEffect(()=>{if(!v.current||h.length===0)return;v.current=!1,$.current&&clearTimeout($.current),C(!0);let t=0;const s=()=>{if(t>=h.length-1){C(!1);return}t++,r(t);const i=h[t];i&&(i.highlightColor==="green"?B.current():i.highlightColor==="red"?Y.current():i.highlightColor==="yellow"&&q.current(t,h.length)),$.current=setTimeout(s,R.current)};$.current=setTimeout(s,R.current)},[h]);const J=x>=0&&h[x]?h[x].nodes:p,l=x>=0?h[x]:null,E=c==="singly"?"singly linked list":c==="doubly"?"doubly linked list":"circular linked list",O=t=>P(s=>[t,...s].slice(0,20)),Q=a.useCallback(t=>{H(t),y([]),r(-1),C(!1),P(s=>[`Switch to ${t}`,...s].slice(0,20))},[]),w=(t,s,i=[],d=null,u=null)=>({description:t,nodes:s,highlightIds:new Set(i),highlightColor:d,newNodeId:u}),Z=a.useCallback(t=>{const s={id:U++,value:t};m(i=>{const d=[s,...i],u=[w(`Prepend ${t}: creating new node at head in the ${E}...`,i,[],null,s.id),w(`${t} inserted at position 0. Updating ${c==="doubly"?"prev/next pointers":c==="circular"?"tail.next back to head":"head pointer"}.`,d,[s.id],"green",s.id)];return y(u),r(0),v.current=!0,N(),O(`Prepend ${t}`),d})},[N,c,E]),ee=a.useCallback(t=>{const s={id:U++,value:t};m(i=>{const d=[...i,s],u=[];for(let f=0;f{const i={id:U++,value:t};m(d=>{if(s<0||s>d.length)return d;const u=[...d.slice(0,s),i,...d.slice(s)],f=[];for(let W=0;W{m(s=>{if(t<0||t>=s.length)return s;const i=s[t],d=[];for(let f=0;f<=t;f++)d.push(w(`Traversing to index ${t}: at node ${s[f].value}...`,s,[s[f].id],"yellow"));d.push(w(`Deleting node ${i.value} at index ${t}: re-linking ${c==="doubly"?"prev and next pointers":c==="circular"?"cycle pointers":"next pointer"}.`,s,[i.id],"red"));const u=s.filter((f,W)=>W!==t);return d.push(w(`Node ${i.value} removed. List size: ${u.length}`,u,[],null)),y(d),r(0),v.current=!0,I(),O(`Delete [${t}] → ${i.value}`),u})},[I,c]),le=a.useCallback(t=>{m(s=>{const i=[];let d=-1;for(let u=0;u{m([]),y([]),r(-1),O("Clear list")},[]),ae=a.useCallback(()=>{const t=Math.floor(Math.random()*4)+4,s=Array.from({length:t},()=>({id:U++,value:Math.floor(Math.random()*90)+1}));m(s),y([]),r(-1),O("Random list")},[]),ie=a.useCallback(()=>{r(t=>Math.min(t+1,h.length-1))},[h.length]),re=a.useCallback(()=>{r(t=>Math.max(t-1,0))},[]),oe=a.useCallback(()=>{if(n){C(!1),$.current&&clearTimeout($.current);return}if(x>=h.length-1)return;C(!0);let t=x;const s=()=>{if(t>=h.length-1){C(!1);return}t++,r(t),$.current=setTimeout(s,j)};$.current=setTimeout(s,j)},[n,x,h.length,j]);return{nodes:p,variant:c,changeVariant:Q,displayNodes:J,steps:h,stepIndex:x,currentStep:l,inputValue:S,setInputValue:M,indexValue:V,setIndexValue:X,history:G,speed:j,setSpeed:A,isPlaying:n,prepend:Z,append:ee,insertAt:te,deleteAt:se,search:le,clear:ne,generateRandom:ae,nextStep:ie,prevStep:re,autoPlay:oe,canGoNext:x0,soundEnabled:o,toggleSound:F}}const ye={green:{border:"#34d399",bg:"rgba(52,211,153,0.15)",text:"#6ee7b7"},red:{border:"#f87171",bg:"rgba(248,113,113,0.15)",text:"#fca5a5"},yellow:{border:"#fbbf24",bg:"rgba(251,191,36,0.15)",text:"#fde68a"},blue:{border:"#60a5fa",bg:"rgba(96,165,250,0.15)",text:"#93c5fd"}},Ne={border:"#475569",bg:"rgba(30,41,59,0.7)",text:"#cbd5e1"},b=64,g=48,L=36,z=b+L,_=5;function ve({nodes:p,currentStep:m,variant:c}){const H=m?.highlightIds??new Set,h=m?.highlightColor??null,y=[];for(let j=0;j{const n=A*r+20,C=A===y.length-1,$=A*_;return e.jsx("g",{children:j.map((R,v)=>{const o=v*z+L/2,F=H.has(R.id),N=F&&h?ye[h]:Ne,I=$+v,k=I===0,T=I===p.length-1,D=v===j.length-1;return e.jsxs("g",{children:[k&&e.jsx("text",{x:o+b/2,y:n-8,textAnchor:"middle",fontSize:"10",fill:"#818cf8",fontFamily:"monospace",children:"head"}),e.jsx("rect",{x:o,y:n,width:b,height:g,rx:8,fill:N.bg,stroke:N.border,strokeWidth:F?2:1.5}),e.jsx("text",{x:o+b*.38,y:n+g/2+5,textAnchor:"middle",fontSize:"15",fontWeight:"bold",fill:N.text,fontFamily:"sans-serif",children:R.value}),e.jsx("line",{x1:o+b*.62,y1:n+4,x2:o+b*.62,y2:n+g-4,stroke:N.border,strokeWidth:1,opacity:.5}),e.jsx("text",{x:o+b*.82,y:n+g/2+4,textAnchor:"middle",fontSize:"9",fill:"#64748b",fontFamily:"monospace",children:T?c==="circular"?"↺":"null":"→"}),c==="doubly"&&e.jsx("text",{x:o+b*.2,y:n+g-7,textAnchor:"middle",fontSize:"8",fill:"#93c5fd",fontFamily:"monospace",children:k?"null":"←"}),!T&&!D&&e.jsxs("g",{children:[e.jsx("line",{x1:o+b,y1:n+g/2,x2:o+z,y2:n+g/2,stroke:"#475569",strokeWidth:1.5}),e.jsx("polygon",{points:`${o+z},${n+g/2} ${o+z-6},${n+g/2-4} ${o+z-6},${n+g/2+4}`,fill:"#475569"})]}),c==="doubly"&&!T&&!D&&e.jsxs("g",{opacity:.75,children:[e.jsx("line",{x1:o+z,y1:n+g/2+12,x2:o+b,y2:n+g/2+12,stroke:"#60a5fa",strokeWidth:1.2}),e.jsx("polygon",{points:`${o+b},${n+g/2+12} ${o+b+6},${n+g/2+8} ${o+b+6},${n+g/2+16}`,fill:"#60a5fa"})]}),D&&!C&&e.jsxs("g",{children:[e.jsx("path",{d:`M ${o+b} ${n+g/2} L ${o+b+14} ${n+g/2} L ${o+b+14} ${n+g+20} L ${L/2} ${n+g+20} L ${L/2} ${n+r}`,fill:"none",stroke:"#475569",strokeWidth:1.5}),e.jsx("polygon",{points:`${L/2},${n+r} ${L/2-4},${n+r-6} ${L/2+4},${n+r-6}`,fill:"#475569"})]})]},R.id)})},A)}),c==="circular"&&y.length>0&&p.length>1&&e.jsxs("g",{children:[e.jsx("path",{d:`M ${G+b} ${P+g/2} C ${x+40} ${S+16}, -20 ${S+16}, ${L/2+b/2} 78`,fill:"none",stroke:"#f59e0b",strokeDasharray:"5 5",strokeWidth:1.5}),e.jsx("text",{x:x/2,y:S-4,textAnchor:"middle",fontSize:"10",fill:"#fbbf24",fontFamily:"monospace",children:"tail.next → head"})]})]}),m?.description&&e.jsx("div",{className:"w-full max-w-sm rounded-lg bg-slate-800/60 px-4 py-2 text-center text-xs text-indigo-300 leading-relaxed",children:m.description}),e.jsxs("div",{className:"text-xs text-slate-500 font-mono",children:[c," list · length = ",p.length]})]})}const $e=[{label:"Slow",value:700},{label:"Med",value:350},{label:"Fast",value:120}];function ke({hook:p}){const{nodes:m,variant:c,changeVariant:H,steps:h,stepIndex:y,inputValue:x,setInputValue:r,indexValue:S,setIndexValue:M,history:V,speed:X,setSpeed:G,isPlaying:P,prepend:j,append:A,insertAt:n,deleteAt:C,search:$,clear:R,generateRandom:v,nextStep:o,prevStep:F,canGoNext:N,canGoPrev:I,soundEnabled:k,toggleSound:T}=p,D=()=>{const l=parseInt(x);isNaN(l)||(j(l),r(""))},B=()=>{const l=parseInt(x);isNaN(l)||(A(l),r(""))},Y=()=>{const l=parseInt(x),E=parseInt(S);!isNaN(l)&&!isNaN(E)&&(n(l,E),r(""))},q=()=>{const l=parseInt(S);isNaN(l)||C(l)},J=()=>{const l=parseInt(x);isNaN(l)||$(l)};return e.jsxs("div",{className:"flex flex-col gap-4 w-full md:w-72 shrink-0 overflow-y-auto max-h-full pr-1",children:[e.jsxs("div",{className:"rounded-xl border border-slate-700/50 bg-slate-900/60 p-4 backdrop-blur-sm",children:[e.jsx("h3",{className:"text-sm font-bold text-indigo-300 mb-1",children:"Linked List"}),e.jsxs("p",{className:"text-xs text-slate-400 leading-relaxed",children:["A chain of ",e.jsx("strong",{className:"text-slate-300",children:"nodes"}),". Switch between singly, doubly, and circular pointer layouts while keeping the same operations."]}),e.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:["Prepend O(1)","Append O(n)","Insert O(n)","Delete O(n)","Search O(n)"].map(l=>e.jsx("span",{className:"rounded-full bg-violet-500/10 px-2 py-0.5 text-[10px] font-medium text-violet-400 ring-1 ring-violet-500/20",children:l},l))})]}),e.jsxs("div",{className:"rounded-xl border border-slate-700/50 bg-slate-900/60 p-4 backdrop-blur-sm",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wider text-slate-400 mb-3",children:"List Type"}),e.jsx("div",{className:"grid grid-cols-3 gap-1",children:["singly","doubly","circular"].map(l=>e.jsx("button",{onClick:()=>H(l),className:`rounded-lg px-2 py-2 text-[10px] font-semibold capitalize transition-all ${c===l?"bg-indigo-500/20 text-indigo-300 ring-1 ring-indigo-500/40":"bg-slate-800/60 text-slate-400 hover:bg-slate-700/60"}`,children:l},l))}),e.jsx("p",{className:"mt-2 text-[10px] leading-relaxed text-slate-500",children:"Doubly lists show backward pointers; circular lists connect the tail back to the head."})]}),e.jsxs("div",{className:"rounded-xl border border-slate-700/50 bg-slate-900/60 p-4 backdrop-blur-sm",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wider text-slate-400 mb-3",children:"Operations"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 mb-3",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("label",{className:"text-[10px] text-slate-500 uppercase tracking-wider",children:"Value"}),e.jsx("input",{type:"number",value:x,onChange:l=>r(l.target.value),placeholder:"e.g. 42",className:"w-full rounded-lg bg-slate-800/60 px-3 py-2 text-sm text-slate-200 placeholder-slate-600 outline-none ring-1 ring-slate-700/50 focus:ring-indigo-500/50 transition-all"})]}),e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("label",{className:"text-[10px] text-slate-500 uppercase tracking-wider",children:"Index"}),e.jsx("input",{type:"number",value:S,onChange:l=>M(l.target.value),placeholder:"e.g. 0",min:"0",className:"w-full rounded-lg bg-slate-800/60 px-3 py-2 text-sm text-slate-200 placeholder-slate-600 outline-none ring-1 ring-slate-700/50 focus:ring-indigo-500/50 transition-all"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("button",{onClick:D,disabled:m.length>=12,className:"flex items-center justify-center gap-1.5 rounded-lg bg-gradient-to-r from-emerald-500/80 to-green-500/80 px-3 py-2 text-xs font-semibold text-white shadow-lg shadow-emerald-500/15 transition-all hover:brightness-110 active:scale-[0.98] disabled:opacity-40 disabled:cursor-not-allowed",children:[e.jsx(K,{size:13})," Prepend"]}),e.jsxs("button",{onClick:B,disabled:m.length>=12,className:"flex items-center justify-center gap-1.5 rounded-lg bg-indigo-500/20 px-3 py-2 text-xs font-semibold text-indigo-300 ring-1 ring-indigo-500/30 transition-all hover:bg-indigo-500/30 active:scale-[0.98] disabled:opacity-40 disabled:cursor-not-allowed",children:[e.jsx(K,{size:13})," Append"]}),e.jsxs("button",{onClick:Y,disabled:m.length>=12,className:"flex items-center justify-center gap-1.5 rounded-lg bg-violet-500/20 px-3 py-2 text-xs font-semibold text-violet-300 ring-1 ring-violet-500/30 transition-all hover:bg-violet-500/30 active:scale-[0.98] disabled:opacity-40 disabled:cursor-not-allowed",children:[e.jsx(K,{size:13})," Insert at"]}),e.jsxs("button",{onClick:q,disabled:m.length===0,className:"flex items-center justify-center gap-1.5 rounded-lg bg-gradient-to-r from-rose-500/80 to-pink-500/80 px-3 py-2 text-xs font-semibold text-white shadow-lg shadow-rose-500/15 transition-all hover:brightness-110 active:scale-[0.98] disabled:opacity-40 disabled:cursor-not-allowed",children:[e.jsx(xe,{size:13})," Delete at"]}),e.jsxs("button",{onClick:J,disabled:m.length===0,className:"flex items-center justify-center gap-1.5 rounded-lg bg-amber-500/20 px-3 py-2 text-xs font-semibold text-amber-300 ring-1 ring-amber-500/30 transition-all hover:bg-amber-500/30 active:scale-[0.98] disabled:opacity-40 disabled:cursor-not-allowed",children:[e.jsx(de,{size:13})," Search"]}),e.jsxs("button",{onClick:R,disabled:m.length===0,className:"flex items-center justify-center gap-1.5 rounded-lg bg-slate-800/60 px-3 py-2 text-xs font-medium text-slate-400 transition-all hover:bg-slate-700/60 disabled:opacity-40 disabled:cursor-not-allowed",children:[e.jsx(ue,{size:13})," Clear"]})]}),e.jsxs("button",{onClick:v,className:"mt-2 w-full flex items-center justify-center gap-1.5 rounded-lg bg-slate-800/60 px-3 py-2 text-xs font-medium text-slate-400 transition-all hover:bg-slate-700/60 hover:text-slate-300",children:[e.jsx(he,{size:12})," Random List"]}),e.jsxs("button",{onClick:()=>T(!k),className:`mt-2 w-full flex items-center justify-center gap-1.5 rounded-lg px-3 py-2 text-xs font-medium transition-all ${k?"bg-indigo-500/15 text-indigo-300 ring-1 ring-indigo-500/30":"bg-slate-800/60 text-slate-400 hover:bg-slate-700/60"}`,children:[k?e.jsx(ge,{size:12}):e.jsx(pe,{size:12}),k?"Sound On":"Sound Off"]})]}),e.jsxs("div",{className:"rounded-xl border border-slate-700/50 bg-slate-900/60 p-4 backdrop-blur-sm",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wider text-slate-400 mb-3",children:"Animation Speed"}),e.jsx("div",{className:"flex gap-1",children:$e.map(l=>e.jsx("button",{onClick:()=>G(l.value),className:`flex-1 rounded-lg px-2 py-1.5 text-xs font-medium transition-all duration-200 ${X===l.value?"bg-violet-500/20 text-violet-300 ring-1 ring-violet-500/40":"bg-slate-800/50 text-slate-400 hover:bg-slate-700/50 hover:text-slate-300"}`,children:l.label},l.value))})]}),h.length>0&&e.jsxs("div",{className:"rounded-xl border border-slate-700/50 bg-slate-900/60 p-4 backdrop-blur-sm",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wider text-slate-400 mb-3",children:"Step Through"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{onClick:F,disabled:!I||P,className:"flex-1 flex items-center justify-center gap-1 rounded-lg bg-slate-800/60 px-3 py-2.5 text-sm font-medium text-slate-400 transition-all hover:bg-slate-700/60 hover:text-slate-300 disabled:opacity-30 disabled:cursor-not-allowed",children:[e.jsx(me,{size:16})," Prev"]}),e.jsxs("button",{onClick:o,disabled:!N||P,className:"flex-1 flex items-center justify-center gap-1 rounded-lg bg-slate-800/60 px-3 py-2.5 text-sm font-medium text-slate-400 transition-all hover:bg-slate-700/60 hover:text-slate-300 disabled:opacity-30 disabled:cursor-not-allowed",children:["Next ",e.jsx(fe,{size:16})]})]}),e.jsxs("div",{className:"mt-2 flex items-center justify-between",children:[e.jsx("span",{className:"text-xs text-slate-500",children:"Step"}),e.jsxs("span",{className:"text-sm font-mono font-semibold text-indigo-400",children:[Math.max(0,y+1)," / ",h.length]})]})]}),V.length>0&&e.jsxs("div",{className:"rounded-xl border border-slate-700/50 bg-slate-900/60 p-4 backdrop-blur-sm",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wider text-slate-400 mb-3",children:"History"}),e.jsx("div",{className:"max-h-36 overflow-y-auto space-y-1",children:V.map((l,E)=>e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("span",{className:"font-mono text-slate-600 w-4 text-right",children:E+1}),e.jsx("span",{className:l.startsWith("Prepend")||l.startsWith("Append")||l.startsWith("Insert")?"text-emerald-400":l.startsWith("Delete")?"text-rose-400":l.startsWith("Search")?"text-amber-400":"text-slate-400",children:l})]},E))})]}),e.jsxs("div",{className:"rounded-xl border border-slate-700/50 bg-slate-900/60 p-4 backdrop-blur-sm",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wider text-slate-400 mb-3",children:"Legend"}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"h-3 w-5 rounded-sm bg-emerald-500"}),e.jsx("span",{className:"text-xs text-slate-400",children:"Insert / found"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"h-3 w-5 rounded-sm bg-rose-500"}),e.jsx("span",{className:"text-xs text-slate-400",children:"Delete"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"h-3 w-5 rounded-sm bg-amber-400"}),e.jsx("span",{className:"text-xs text-slate-400",children:"Traversal / search"})]})]})]})]})}function Ee(){const p=je();return e.jsxs("div",{className:"flex flex-1 flex-col md:flex-row gap-4 md:gap-6 overflow-auto p-4 md:p-6",children:[e.jsx("div",{className:"order-last md:order-first flex md:flex-1 flex-col items-center justify-center gap-3 min-h-[40vh] md:min-h-0 max-h-[55vh] md:max-h-none overflow-auto",children:e.jsx(ve,{nodes:p.displayNodes,currentStep:p.currentStep,variant:p.variant})}),e.jsx(ke,{hook:p})]})}export{Ee as default};
diff --git a/docs/assets/MahjongGamePage-D5Ek5nyq.js b/docs/assets/MahjongGamePage-CBqcyOb2.js
similarity index 91%
rename from docs/assets/MahjongGamePage-D5Ek5nyq.js
rename to docs/assets/MahjongGamePage-CBqcyOb2.js
index 8d3aa5e..2a1c5f9 100644
--- a/docs/assets/MahjongGamePage-D5Ek5nyq.js
+++ b/docs/assets/MahjongGamePage-CBqcyOb2.js
@@ -1,8 +1,8 @@
-import{c as U,j as e,d as ve,e as ke,E as we,r as c,A as de}from"./index-eCXyAnHs.js";import{S as Te}from"./shuffle-CdKU4ZYx.js";import{R as K}from"./rotate-ccw-B8GZP3d7.js";import{V as Q,a as ee}from"./volume-x-CTbtCvt-.js";import{E as Ce}from"./eye-off-EsCpy5pU.js";import{C as Se,a as $e}from"./chevron-right-BZqZw4c2.js";import{P as We}from"./pause-nC-0zhw8.js";import{P as Pe}from"./play-BqZilH6N.js";import{T as Y}from"./trophy-DkUzH7jB.js";import{g as _e}from"./audioContext-NbgqvQGz.js";import{L as Me,F as Ae}from"./lightbulb-B7pRWk3f.js";import{S as Re,B as ze}from"./skip-forward-BOek2ZcD.js";import{T as He}from"./timer-DSbfy6P3.js";import{Z as Ee}from"./zap-DNziIfcU.js";const Be=[["path",{d:"M8 3 4 7l4 4",key:"9rb6wj"}],["path",{d:"M4 7h16",key:"6tx8e3"}],["path",{d:"m16 21 4-4-4-4",key:"siv7j2"}],["path",{d:"M20 17H4",key:"h6l3hr"}]],Ie=U("arrow-left-right",Be);const Oe=[["path",{d:"M21.801 10A10 10 0 1 1 17 3.335",key:"yps3ct"}],["path",{d:"m9 11 3 3L22 4",key:"1pflzl"}]],V=U("circle-check-big",Oe);const Fe=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m15 9-6 6",key:"1uzhvr"}],["path",{d:"m9 9 6 6",key:"z0biqf"}]],re=U("circle-x",Fe);const Ge=[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["path",{d:"M16 3.128a4 4 0 0 1 0 7.744",key:"16gr8j"}],["path",{d:"M22 21v-2a4 4 0 0 0-3-3.87",key:"kshegd"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}]],pe=U("users",Ge);const Ve=[["path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.106-3.105c.32-.322.863-.22.983.218a6 6 0 0 1-8.259 7.057l-7.91 7.91a1 1 0 0 1-2.999-3l7.91-7.91a6 6 0 0 1 7.057-8.259c.438.12.54.662.219.984z",key:"1ngwbx"}]],Le=U("wrench",Ve),he={B:"Bamboo",C:"Characters",D:"Dots"},Z={B:"#4ade80",C:"#f87171",D:"#60a5fa"},De={sandbox:{label:"Sandbox",description:"Build any hand and check it freely"},guided:{label:"Guided",description:"Learn to spot pairs & melds step-by-step"},challenge:{label:"Challenge",description:"Speed rounds — Win or Not Win?"},"two-player":{label:"2 Player",description:"Take turns building hands"}},P=14,E=4,O=[1,2,3,4,5,6,7,8,9],B=["B","C","D"],J={title:"Mahjong Hand Solver",subtitle:"Backtracking-based winning hand validator",what:"Build a 14-tile Mahjong hand and check if it forms a valid winning combination — 4 melds (pongs or chows) plus 1 pair. Watch the backtracking solver try every possibility step-by-step.",skills:["Backtracking","Constraint Validation","Combinatorics","Pattern Matching"]},xe={sm:"w-9 h-12 sm:w-10 sm:h-14",md:"w-11 h-14 sm:w-12 sm:h-16 md:w-14 md:h-[4.35rem]",lg:"w-12 h-16 sm:w-14 sm:h-[4.6rem] md:w-16 md:h-20"};function I({code:t,index:s,count:n,size:a="md",selected:l=!1,disabled:r=!1,faded:m=!1,interactive:k=!1,removable:p=!1,placeholder:T=!1,onClick:i}){if(T||!t)return e.jsx("div",{className:`${xe[a]} relative rounded-xl border border-dashed border-emerald-900/30 bg-emerald-950/20 shadow-inner`,children:e.jsx("div",{className:"absolute inset-1 rounded-lg border border-emerald-900/20"})});const o=t[0],x=Number(t[1]),u=Z[o],g=e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"absolute inset-0 rounded-xl bg-gradient-to-br from-stone-50 via-amber-50 to-stone-200"}),e.jsx("div",{className:"absolute inset-x-1 top-1 h-1 rounded-full bg-white/80"}),e.jsx("div",{className:"absolute inset-1 rounded-lg border border-amber-950/10 bg-[radial-gradient(circle_at_30%_15%,rgba(255,255,255,0.8),transparent_38%),linear-gradient(135deg,rgba(255,255,255,0.35),transparent)]"}),e.jsx("div",{className:"absolute inset-y-1 right-0.5 w-1 rounded-r-lg bg-emerald-900/25"}),e.jsx("div",{className:"relative z-10 flex h-full flex-col items-center justify-center px-1 text-center",children:e.jsx(Ue,{suit:o,value:x,color:u,size:a})}),e.jsx("div",{className:"absolute left-1 top-1 text-[8px] font-black leading-none text-slate-900/35",children:x}),e.jsx("div",{className:"absolute bottom-1 right-1 rotate-180 text-[8px] font-black leading-none text-slate-900/35",children:x}),typeof s=="number"&&s>=0&&e.jsx("span",{className:"absolute -bottom-1 left-1/2 z-20 -translate-x-1/2 rounded-full bg-slate-950/80 px-1 text-[7px] font-mono text-slate-400 ring-1 ring-slate-700/50",children:s+1}),typeof n=="number"&&n>0&&e.jsx("span",{className:"absolute -right-1.5 -top-1.5 z-20 flex h-5 w-5 items-center justify-center rounded-full bg-emerald-950 text-[10px] font-bold text-emerald-200 ring-1 ring-emerald-500/50",children:n}),p&&e.jsx("span",{className:"absolute inset-0 z-30 flex items-center justify-center rounded-xl bg-red-950/70 text-sm font-black text-white opacity-0 transition-opacity group-hover:opacity-100",children:"x"})]}),b=`
+import{c as U,j as e,d as ve,E as ke,r as c,A as de,B as we}from"./index-DBkLeWDs.js";import{S as Te}from"./shuffle-Dlr-c52A.js";import{S as Ce}from"./sparkles-3Zw4K66N.js";import{R as K}from"./rotate-ccw-7GTUOPy4.js";import{V as Q,a as ee}from"./volume-x-BSx9gxSg.js";import{E as Se}from"./eye-off-BfEKGZbc.js";import{C as $e,a as We}from"./chevron-right-CFBAUJsk.js";import{P as Pe}from"./pause-CG1snUW9.js";import{P as _e}from"./play-mcIZClKO.js";import{T as Y}from"./trophy-C1QWh03u.js";import{g as Me}from"./audioContext-NbgqvQGz.js";import{L as Ae,F as Re}from"./lightbulb-xA5HFx8I.js";import{S as ze}from"./skip-forward-C79KMIOU.js";import{T as He}from"./timer-e0gb0oZa.js";import{Z as Ee}from"./zap-CUITaKA-.js";const Be=[["path",{d:"M8 3 4 7l4 4",key:"9rb6wj"}],["path",{d:"M4 7h16",key:"6tx8e3"}],["path",{d:"m16 21 4-4-4-4",key:"siv7j2"}],["path",{d:"M20 17H4",key:"h6l3hr"}]],Ie=U("arrow-left-right",Be);const Oe=[["path",{d:"M21.801 10A10 10 0 1 1 17 3.335",key:"yps3ct"}],["path",{d:"m9 11 3 3L22 4",key:"1pflzl"}]],V=U("circle-check-big",Oe);const Fe=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m15 9-6 6",key:"1uzhvr"}],["path",{d:"m9 9 6 6",key:"z0biqf"}]],re=U("circle-x",Fe);const Ge=[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["path",{d:"M16 3.128a4 4 0 0 1 0 7.744",key:"16gr8j"}],["path",{d:"M22 21v-2a4 4 0 0 0-3-3.87",key:"kshegd"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}]],pe=U("users",Ge);const Ve=[["path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.106-3.105c.32-.322.863-.22.983.218a6 6 0 0 1-8.259 7.057l-7.91 7.91a1 1 0 0 1-2.999-3l7.91-7.91a6 6 0 0 1 7.057-8.259c.438.12.54.662.219.984z",key:"1ngwbx"}]],Le=U("wrench",Ve),he={B:"Bamboo",C:"Characters",D:"Dots"},Z={B:"#4ade80",C:"#f87171",D:"#60a5fa"},De={sandbox:{label:"Sandbox",description:"Build any hand and check it freely"},guided:{label:"Guided",description:"Learn to spot pairs & melds step-by-step"},challenge:{label:"Challenge",description:"Speed rounds — Win or Not Win?"},"two-player":{label:"2 Player",description:"Take turns building hands"}},P=14,E=4,O=[1,2,3,4,5,6,7,8,9],B=["B","C","D"],J={title:"Mahjong Hand Solver",subtitle:"Backtracking-based winning hand validator",what:"Build a 14-tile Mahjong hand and check if it forms a valid winning combination — 4 melds (pongs or chows) plus 1 pair. Watch the backtracking solver try every possibility step-by-step.",skills:["Backtracking","Constraint Validation","Combinatorics","Pattern Matching"]},xe={sm:"w-9 h-12 sm:w-10 sm:h-14",md:"w-11 h-14 sm:w-12 sm:h-16 md:w-14 md:h-[4.35rem]",lg:"w-12 h-16 sm:w-14 sm:h-[4.6rem] md:w-16 md:h-20"};function I({code:t,index:s,count:n,size:a="md",selected:l=!1,disabled:r=!1,faded:m=!1,interactive:k=!1,removable:p=!1,placeholder:T=!1,onClick:i}){if(T||!t)return e.jsx("div",{className:`${xe[a]} relative rounded-xl border border-dashed border-emerald-900/30 bg-emerald-950/20 shadow-inner`,children:e.jsx("div",{className:"absolute inset-1 rounded-lg border border-emerald-900/20"})});const o=t[0],x=Number(t[1]),u=Z[o],g=e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"absolute inset-0 rounded-xl bg-gradient-to-br from-stone-50 via-amber-50 to-stone-200"}),e.jsx("div",{className:"absolute inset-x-1 top-1 h-1 rounded-full bg-white/80"}),e.jsx("div",{className:"absolute inset-1 rounded-lg border border-amber-950/10 bg-[radial-gradient(circle_at_30%_15%,rgba(255,255,255,0.8),transparent_38%),linear-gradient(135deg,rgba(255,255,255,0.35),transparent)]"}),e.jsx("div",{className:"absolute inset-y-1 right-0.5 w-1 rounded-r-lg bg-emerald-900/25"}),e.jsx("div",{className:"relative z-10 flex h-full flex-col items-center justify-center px-1 text-center",children:e.jsx(Ue,{suit:o,value:x,color:u,size:a})}),e.jsx("div",{className:"absolute left-1 top-1 text-[8px] font-black leading-none text-slate-900/35",children:x}),e.jsx("div",{className:"absolute bottom-1 right-1 rotate-180 text-[8px] font-black leading-none text-slate-900/35",children:x}),typeof s=="number"&&s>=0&&e.jsx("span",{className:"absolute -bottom-1 left-1/2 z-20 -translate-x-1/2 rounded-full bg-slate-950/80 px-1 text-[7px] font-mono text-slate-400 ring-1 ring-slate-700/50",children:s+1}),typeof n=="number"&&n>0&&e.jsx("span",{className:"absolute -right-1.5 -top-1.5 z-20 flex h-5 w-5 items-center justify-center rounded-full bg-emerald-950 text-[10px] font-bold text-emerald-200 ring-1 ring-emerald-500/50",children:n}),p&&e.jsx("span",{className:"absolute inset-0 z-30 flex items-center justify-center rounded-xl bg-red-950/70 text-sm font-black text-white opacity-0 transition-opacity group-hover:opacity-100",children:"x"})]}),b=`
group relative ${xe[a]} shrink-0 overflow-visible rounded-xl border transition-all duration-200
shadow-[0_10px_18px_rgba(0,0,0,0.35),inset_0_-3px_0_rgba(0,0,0,0.18)]
${l?"z-10 -translate-y-2 rotate-[-1deg] border-amber-300 ring-2 ring-amber-300/50":"border-amber-950/25"}
${r?"cursor-not-allowed opacity-45 grayscale":""}
${m?"opacity-35":""}
${k&&!r?"cursor-pointer hover:-translate-y-2 hover:rotate-1 hover:shadow-[0_18px_28px_rgba(0,0,0,0.45)] active:translate-y-0":""}
- `;return k||i?e.jsx("button",{onClick:i,disabled:r,title:t,className:b,children:g}):e.jsx("div",{className:b,children:g})}function Ue({suit:t,value:s,color:n,size:a}){return t==="C"?e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("span",{style:{color:n},className:`${a==="sm"?"text-xl":a==="lg"?"text-3xl":"text-2xl"} font-black leading-none drop-shadow-sm`,children:s}),e.jsx("span",{style:{color:n},className:`${a==="sm"?"text-base":"text-lg"} font-black leading-none`,children:"萬"})]}):t==="B"?e.jsx("div",{className:"grid grid-cols-3 gap-0.5",children:Array.from({length:s}).map((l,r)=>e.jsx("span",{className:"h-3 w-1 rounded-full border border-emerald-950/20 bg-gradient-to-b from-emerald-300 to-emerald-700 shadow-sm"},r))}):e.jsx("div",{className:"grid grid-cols-3 gap-0.5",children:Array.from({length:s}).map((l,r)=>e.jsx("span",{className:"h-2.5 w-2.5 rounded-full border border-blue-950/30 bg-white shadow-sm",style:{boxShadow:`inset 0 0 0 2px ${n}`}},r))})}function Je(t,s){return t.filter(n=>n===s).length}function qe({suit:t,value:s,count:n,disabled:a,onClick:l}){const r=n>=4,m=`${t}${s}`;return e.jsx(I,{code:m,count:n,size:"md",disabled:a||r,interactive:!0,onClick:l})}function Ye({hand:t,handIsFull:s,onAddTile:n}){return e.jsxs("div",{className:"rounded-2xl border border-slate-700/50 bg-slate-900/70 p-4 shadow-xl shadow-black/20 backdrop-blur-sm md:p-5",children:[e.jsxs("div",{className:"mb-3 md:mb-4",children:[e.jsx("h3",{className:"text-xs md:text-sm font-semibold uppercase tracking-wider text-slate-300",children:"Tile Wall"}),e.jsx("p",{className:"mt-0.5 text-[10px] text-slate-500",children:"Choose up to four copies of each realistic Mahjong tile"})]}),e.jsx("div",{className:"space-y-4 md:space-y-5",children:B.map(a=>e.jsxs("div",{className:"rounded-xl border border-slate-800/70 bg-slate-950/35 p-3",children:[e.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[e.jsx("span",{className:"h-2 w-2 rounded-full",style:{backgroundColor:Z[a]}}),e.jsx("p",{className:"text-[10px] md:text-xs font-semibold uppercase tracking-wider",style:{color:Z[a]},children:he[a]})]}),e.jsx("div",{className:"flex flex-wrap items-end gap-1.5 md:gap-2",children:O.map(l=>{const r=`${a}${l}`;return e.jsx(qe,{suit:a,value:l,count:Je(t,r),disabled:s,onClick:()=>n(r)},r)})})]},a))})]})}function Ze({hand:t,onRemoveTile:s}){const n=P-t.length;return e.jsxs("div",{className:"relative overflow-hidden rounded-2xl border border-emerald-900/40 bg-[radial-gradient(circle_at_top_left,rgba(16,185,129,0.14),transparent_34%),linear-gradient(135deg,rgba(15,23,42,0.96),rgba(6,78,59,0.36))] p-4 shadow-2xl shadow-black/30 md:p-5",children:[e.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 h-16 bg-gradient-to-t from-black/25 to-transparent"}),e.jsxs("div",{className:"flex items-center justify-between mb-3 md:mb-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-xs md:text-sm font-semibold uppercase tracking-wider text-emerald-200",children:"Your Hand"}),e.jsx("p",{className:"mt-0.5 text-[10px] text-emerald-100/50",children:"Click a tile to discard it from the rack"})]}),e.jsxs("span",{className:`text-xs md:text-sm font-mono font-bold ${t.length===P?"text-emerald-400":"text-slate-500"}`,children:[t.length," / ",P]})]}),e.jsxs("div",{className:"relative flex min-h-[5.5rem] flex-wrap items-end gap-1.5 rounded-xl border border-emerald-950/40 bg-emerald-950/20 p-3 shadow-inner md:gap-2",children:[t.map((a,l)=>e.jsx(I,{code:a,index:l,size:"lg",interactive:!0,removable:!0,onClick:()=>s(l)},`${a}-${l}`)),n>0&&Array.from({length:n}).map((a,l)=>e.jsx(I,{size:"lg",placeholder:!0},`empty-${l}`))]})]})}function ie({code:t}){return e.jsx(I,{code:t,size:"sm"})}function Xe({meld:t,index:s}){return e.jsxs("div",{className:"flex items-center gap-2 rounded-xl bg-slate-950/35 p-2 ring-1 ring-slate-800/70 md:gap-3",children:[e.jsxs("span",{className:"w-14 shrink-0 text-[10px] font-semibold uppercase tracking-wider text-slate-500 md:w-16 md:text-xs",children:[t.type==="pong"?"Pong":"Chow"," ",s+1]}),e.jsx("div",{className:"flex gap-1 md:gap-1.5",children:t.tiles.map((n,a)=>e.jsx(ie,{code:n},`${n}-${a}`))})]})}function Ke({result:t}){return t?t.isWin?e.jsxs("div",{className:"rounded-2xl border border-emerald-500/30 bg-[radial-gradient(circle_at_top_left,rgba(16,185,129,0.18),transparent_36%),rgba(16,185,129,0.05)] p-4 shadow-xl shadow-emerald-950/20 backdrop-blur-sm md:p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3 md:mb-4",children:[e.jsx("span",{className:"text-lg md:text-2xl",children:"🀄"}),e.jsx("h3",{className:"text-sm md:text-base font-bold text-emerald-300",children:"Winning Hand!"})]}),e.jsxs("div",{className:"mb-3 flex items-center gap-2 rounded-xl bg-slate-950/35 p-2 ring-1 ring-slate-800/70 md:mb-4 md:gap-3",children:[e.jsx("span",{className:"w-14 shrink-0 text-[10px] font-semibold uppercase tracking-wider text-slate-500 md:w-16 md:text-xs",children:"Pair"}),e.jsxs("div",{className:"flex gap-1 md:gap-1.5",children:[e.jsx(ie,{code:t.pair[0]}),e.jsx(ie,{code:t.pair[1]})]})]}),e.jsx("div",{className:"space-y-2 md:space-y-3",children:t.melds.map((s,n)=>e.jsx(Xe,{meld:s,index:n},n))})]}):e.jsxs("div",{className:"rounded-xl border border-red-500/30 bg-red-500/5 p-4 md:p-5 backdrop-blur-sm",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-lg md:text-2xl",children:"❌"}),e.jsx("h3",{className:"text-sm md:text-base font-bold text-red-300",children:"Not a Winning Hand"})]}),e.jsx("p",{className:"mt-2 text-xs md:text-sm text-slate-400",children:"Hand is not a valid winning combination. A winning hand needs 4 melds (pongs or chows) and 1 pair."})]}):null}const Qe=[{label:"Slow",value:800},{label:"Med",value:400},{label:"Fast",value:150}];function et({handIsFull:t,result:s,showAnimation:n,steps:a,stepIndex:l,stepsTotal:r,isAnimating:m,animSpeed:k,currentStep:p,lastError:T,onCheckHand:i,onResetHand:o,onRandomHand:x,onWinningHand:u,onToggleAnimation:g,onStepForward:b,onStepBack:w,onAutoPlay:$,onSetAnimSpeed:N,soundEnabled:f,onToggleSound:C}){return e.jsxs("div",{className:"flex flex-col gap-4 w-full md:w-80 shrink-0 overflow-y-auto max-h-full pr-1",children:[e.jsxs("div",{className:"rounded-xl border border-slate-700/50 bg-slate-900/60 p-4 md:p-5 backdrop-blur-sm",children:[e.jsx("h3",{className:"text-sm md:text-base font-bold text-indigo-300 mb-1",children:J.title}),e.jsx("p",{className:"text-[10px] md:text-xs text-slate-500 italic mb-2",children:J.subtitle}),e.jsx("p",{className:"text-xs md:text-sm text-slate-400 leading-relaxed",children:J.what}),e.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:J.skills.map(h=>e.jsx("span",{className:"inline-flex items-center rounded-full bg-violet-500/10 px-2 py-0.5 text-[10px] md:text-xs font-medium text-violet-400 ring-1 ring-violet-500/20",children:h},h))})]}),e.jsxs("div",{className:"rounded-xl border border-slate-700/50 bg-slate-900/60 p-4 md:p-5 backdrop-blur-sm",children:[e.jsx("h3",{className:"text-xs md:text-sm font-semibold uppercase tracking-wider text-slate-400 mb-3",children:"Actions"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 md:gap-2.5 mb-3",children:[e.jsxs("button",{onClick:x,className:"flex items-center justify-center gap-1.5 rounded-lg bg-slate-800/60 px-3 py-2.5 text-xs md:text-sm font-medium text-slate-400 transition-all hover:bg-slate-700/60 hover:text-slate-300",children:[e.jsx(Te,{size:14})," Random"]}),e.jsxs("button",{onClick:u,className:"flex items-center justify-center gap-1.5 rounded-lg bg-slate-800/60 px-3 py-2.5 text-xs md:text-sm font-medium text-slate-400 transition-all hover:bg-slate-700/60 hover:text-slate-300",children:[e.jsx(ve,{size:14})," Winning"]}),e.jsxs("button",{onClick:o,className:"flex items-center justify-center gap-1.5 rounded-lg bg-slate-800/60 px-3 py-2.5 text-xs md:text-sm font-medium text-slate-400 transition-all hover:bg-slate-700/60 hover:text-slate-300",children:[e.jsx(K,{size:14})," Reset"]}),e.jsxs("button",{onClick:i,disabled:!t,className:`flex items-center justify-center gap-1.5 rounded-lg px-3 py-2.5 text-xs md:text-sm font-medium transition-all ${t?"bg-indigo-500/20 text-indigo-300 ring-1 ring-indigo-500/40 hover:bg-indigo-500/30":"bg-slate-800/40 text-slate-600 cursor-not-allowed"}`,children:[e.jsx(ke,{size:14})," Check"]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 md:gap-2.5",children:[e.jsxs("button",{onClick:()=>C(!f),className:`flex items-center justify-center gap-1.5 rounded-lg px-3 py-2.5 text-xs md:text-sm font-medium transition-all ${f?"bg-indigo-500/15 text-indigo-300 ring-1 ring-indigo-500/30":"bg-slate-800/60 text-slate-400 hover:bg-slate-700/60 hover:text-slate-300"}`,children:[f?e.jsx(Q,{size:14}):e.jsx(ee,{size:14})," Sound"]}),e.jsxs("button",{onClick:g,className:`flex items-center justify-center gap-1.5 rounded-lg px-3 py-2.5 text-xs md:text-sm font-medium transition-all ${n?"bg-amber-500/15 text-amber-300 ring-1 ring-amber-500/30":"bg-slate-800/60 text-slate-400 hover:bg-slate-700/60 hover:text-slate-300"}`,children:[n?e.jsx(we,{size:14}):e.jsx(Ce,{size:14}),n?"Anim On":"Anim Off"]})]})]}),n&&a.length>0&&e.jsxs("div",{className:"rounded-xl border border-slate-700/50 bg-slate-900/60 p-4 md:p-5 backdrop-blur-sm",children:[e.jsx("h3",{className:"text-xs md:text-sm font-semibold uppercase tracking-wider text-slate-400 mb-3",children:"Solver Steps"}),e.jsxs("div",{className:"flex gap-2 mb-3",children:[e.jsxs("button",{onClick:w,disabled:l<=-1,className:"flex-1 flex items-center justify-center gap-1 rounded-lg bg-slate-800/60 px-2 py-2.5 text-xs md:text-sm font-medium text-slate-400 hover:bg-slate-700/60 hover:text-slate-300 disabled:opacity-30 disabled:cursor-not-allowed",children:[e.jsx(Se,{size:14})," Prev"]}),e.jsx("button",{onClick:$,className:`flex-1 flex items-center justify-center gap-1 rounded-lg px-2 py-2.5 text-xs md:text-sm font-medium transition-all ${m?"bg-amber-500/20 text-amber-300 ring-1 ring-amber-500/30":"bg-indigo-500/20 text-indigo-300 ring-1 ring-indigo-500/30 hover:bg-indigo-500/30"}`,children:m?e.jsxs(e.Fragment,{children:[e.jsx(We,{size:14})," Pause"]}):e.jsxs(e.Fragment,{children:[e.jsx(Pe,{size:14})," Play"]})}),e.jsxs("button",{onClick:b,disabled:l>=r-1,className:"flex-1 flex items-center justify-center gap-1 rounded-lg bg-slate-800/60 px-2 py-2.5 text-xs md:text-sm font-medium text-slate-400 hover:bg-slate-700/60 hover:text-slate-300 disabled:opacity-30 disabled:cursor-not-allowed",children:["Next ",e.jsx($e,{size:14})]})]}),e.jsx("div",{className:"flex gap-1 mb-2",children:Qe.map(h=>e.jsx("button",{onClick:()=>N(h.value),className:`flex-1 rounded-md px-2 py-1.5 text-[10px] md:text-xs font-medium transition-all ${k===h.value?"bg-indigo-500/20 text-indigo-300 ring-1 ring-indigo-500/30":"bg-slate-800/50 text-slate-500 hover:text-slate-400"}`,children:h.label},h.value))}),r>0&&e.jsxs("div",{className:"flex items-center justify-between text-[10px] md:text-xs text-slate-500",children:[e.jsx("span",{children:"Step"}),e.jsxs("span",{className:"font-mono font-semibold text-indigo-300",children:[Math.max(0,l+1)," / ",r]})]})]}),n&&p&&e.jsxs("div",{className:`rounded-xl border p-4 md:p-5 backdrop-blur-sm ${p.action.type==="found_win"?"border-emerald-500/30 bg-emerald-500/5":p.action.type==="backtrack"||p.action.type==="pair_failed"?"border-amber-500/30 bg-amber-500/5":p.action.type==="no_win"?"border-red-500/30 bg-red-500/5":"border-slate-700/50 bg-slate-900/60"}`,children:[e.jsx("h3",{className:"text-xs md:text-sm font-semibold uppercase tracking-wider text-slate-400 mb-2",children:"Current Step"}),e.jsx("p",{className:"text-xs md:text-sm text-slate-300 leading-relaxed",children:p.description})]}),s&&!n&&e.jsx("div",{className:`rounded-xl border p-4 md:p-5 backdrop-blur-sm ${s.isWin?"border-emerald-500/30 bg-emerald-500/5":"border-red-500/30 bg-red-500/5"}`,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Y,{size:16,className:s.isWin?"text-emerald-400":"text-red-400"}),e.jsx("span",{className:`text-sm md:text-base font-bold ${s.isWin?"text-emerald-300":"text-red-300"}`,children:s.isWin?"Winning Hand!":"Not a Winner"})]})}),T&&e.jsx("div",{className:"rounded-lg border border-red-500/30 bg-red-500/5 px-3 py-2.5 text-center text-xs md:text-sm font-medium text-red-400 animate-pulse",children:T})]})}const oe=B.flatMap(t=>O.map(s=>`${t}${s}`));function fe(t){return{suit:t[0],value:Number(t[1])}}function tt(t){const s={};for(const n of t)s[n]=(s[n]??0)+1;return s}const me={B:0,C:1,D:2};function L(t){return[...t].sort((s,n)=>{const a=me[s[0]],l=me[n[0]];return a!==l?a-l:Number(s[1])-Number(n[1])})}function st(t){if(t.length===0)return"Hand is empty. Add 14 tiles.";if(t.lengthP)return`Hand has ${t.length} tiles. Maximum is ${P}.`;const s=tt(t);for(const[n,a]of Object.entries(s))if(a>E)return`Too many copies of ${n} (${a}). Maximum is ${E}.`;return null}function be(t,s){return t.length>=P?`Hand is full (${P} tiles).`:t.filter(a=>a===s).length>=E?`Already have ${E} copies of ${s}.`:null}function D(){const t={},s=[];for(;s.length
(s[r]??0)>=E?!1:(t.push(r),s[r]=(s[r]??0)+1,!0);for(let r=0;r<4;r++){const m=B[Math.floor(Math.random()*B.length)];if(Math.random()<.4){const i=O[Math.floor(Math.random()*O.length)],o=`${m}${i}`;if((s[o]??0)+3<=E){n(o),n(o),n(o);continue}}let p=!1;const T=[...O.filter(i=>i<=7)].sort(()=>Math.random()-.5);for(const i of T){const o=`${m}${i}`,x=`${m}${i+1}`,u=`${m}${i+2}`;if((s[o]??0)Math.random()-.5);for(const r of l)if((s[r]??0)+2<=E){n(r),n(r),a=!0;break}return!a||t.length!==P?L(["B1","B2","B3","C4","C5","C6","D7","D7","D7","B8","B8","B8","C1","C1"]):L(t)}function je(t){const s={B:{},C:{},D:{}};for(const n of t){const{suit:a,value:l}=fe(n);s[a][l]=(s[a][l]??0)+1}return s}function ye(t){const s={B:{},C:{},D:{}};for(const n of B)for(const[a,l]of Object.entries(t[n]))s[n][Number(a)]=l;return s}function F(t){const s={};for(const n of B)for(const[a,l]of Object.entries(t[n]))l>0&&(s[`${n}${a}`]=l);return s}function nt(t){let s=0;for(const n of B)for(const a of Object.values(t[n]))s+=a;return s}function X(t,s,n,a){if(s===0)return nt(t)===0;for(const l of B)for(let r=1;r<=9;r++)if(!((t[l][r]??0)<=0)){if(t[l][r]>=3){const m=[`${l}${r}`,`${l}${r}`,`${l}${r}`];if(t[l][r]-=3,a&&a.push({action:{type:"try_meld",meldType:"pong",tiles:m,success:!0},description:`Try Pong: ${m.join(" ")}`,remaining:F(t)}),n.push({type:"pong",tiles:m}),X(t,s-1,n,a))return!0;n.pop(),t[l][r]+=3,a&&a.push({action:{type:"backtrack",tiles:m},description:`Backtrack: undo Pong ${m.join(" ")}`,remaining:F(t)})}if(r<=7&&(t[l][r]??0)>=1&&(t[l][r+1]??0)>=1&&(t[l][r+2]??0)>=1){const m=[`${l}${r}`,`${l}${r+1}`,`${l}${r+2}`];if(t[l][r]-=1,t[l][r+1]-=1,t[l][r+2]-=1,a&&a.push({action:{type:"try_meld",meldType:"chow",tiles:m,success:!0},description:`Try Chow: ${m.join(" ")}`,remaining:F(t)}),n.push({type:"chow",tiles:m}),X(t,s-1,n,a))return!0;n.pop(),t[l][r]+=1,t[l][r+1]+=1,t[l][r+2]+=1,a&&a.push({action:{type:"backtrack",tiles:m},description:`Backtrack: undo Chow ${m.join(" ")}`,remaining:F(t)})}return!1}return s===0}function G(t){const s=je(t),n=[];for(const a of B)for(let l=1;l<=9;l++)(s[a][l]??0)>=2&&n.push({suit:a,value:l});for(const{suit:a,value:l}of n){const r=ye(s);r[a][l]-=2;const m=[];if(X(r,4,m,null)){const k=`${a}${l}`;return{isWin:!0,pair:[k,k],melds:m}}}return{isWin:!1}}function at(t){const s=je(t),n=[],a=[];for(const l of B)for(let r=1;r<=9;r++)(s[l][r]??0)>=2&&a.push({suit:l,value:r});for(const{suit:l,value:r}of a){const m=`${l}${r}`;n.push({action:{type:"select_pair",pair:m},description:`Try pair: ${m} ${m}`,remaining:F(s)});const k=ye(s);k[l][r]-=2;const p=[];if(X(k,4,p,n)){const T={type:"found_win",pair:[m,m],melds:p.map(i=>({...i,tiles:[...i.tiles]}))};return n.push({action:T,description:`WIN! Pair: ${m} ${m} | Melds: ${p.map(i=>i.tiles.join(" ")).join(" | ")}`,remaining:{}}),{result:{isWin:!0,pair:[m,m],melds:p},steps:n}}n.push({action:{type:"pair_failed",pair:m},description:`Pair ${m} ${m} failed — no valid 4 melds found`,remaining:F(s)})}return n.push({action:{type:"no_win"},description:"No valid winning combination found.",remaining:F(s)}),{result:{isWin:!1},steps:n}}const lt=[261.63,293.66,329.63,392,440,493.88,523.25,587.33,659.25];function te(){const t=c.useRef(!0),s=c.useCallback(()=>_e(),[]),n=c.useCallback(i=>{t.current=i},[]),a=c.useCallback(i=>{if(!t.current)return;const o=s();if(!o)return;const x=lt[Math.max(0,Math.min(i-1,8))],u=o.createOscillator(),g=o.createGain();u.type="sine",u.frequency.setValueAtTime(x,o.currentTime),g.gain.setValueAtTime(.1,o.currentTime),g.gain.exponentialRampToValueAtTime(.001,o.currentTime+.2),u.connect(g),g.connect(o.destination),u.start(),u.stop(o.currentTime+.2);const b=o.createOscillator(),w=o.createGain();b.type="triangle",b.frequency.setValueAtTime(x*2,o.currentTime),w.gain.setValueAtTime(.03,o.currentTime),w.gain.exponentialRampToValueAtTime(.001,o.currentTime+.15),b.connect(w),w.connect(o.destination),b.start(o.currentTime+.02),b.stop(o.currentTime+.17)},[s]),l=c.useCallback(()=>{if(!t.current)return;const i=s();if(!i)return;const o=i.createOscillator(),x=i.createGain();o.type="sine",o.frequency.setValueAtTime(480,i.currentTime),o.frequency.setValueAtTime(320,i.currentTime+.08),x.gain.setValueAtTime(.07,i.currentTime),x.gain.exponentialRampToValueAtTime(.001,i.currentTime+.12),o.connect(x),x.connect(i.destination),o.start(),o.stop(i.currentTime+.12)},[s]),r=c.useCallback(()=>{if(!t.current)return;const i=s();if(!i)return;[523.25,587.33,659.25,783.99,880,1046.5].forEach((x,u)=>{const g=i.createOscillator(),b=i.createGain();g.type="sine",g.frequency.value=x,b.gain.setValueAtTime(.08,i.currentTime+u*.09),b.gain.exponentialRampToValueAtTime(.001,i.currentTime+u*.09+.2),g.connect(b),b.connect(i.destination),g.start(i.currentTime+u*.09),g.stop(i.currentTime+u*.09+.2)})},[s]),m=c.useCallback(()=>{if(!t.current)return;const i=s();if(!i)return;[400,340,280].forEach((x,u)=>{const g=i.createOscillator(),b=i.createGain();g.type="sine",g.frequency.value=x,b.gain.setValueAtTime(.07,i.currentTime+u*.1),b.gain.exponentialRampToValueAtTime(.001,i.currentTime+u*.1+.2),g.connect(b),b.connect(i.destination),g.start(i.currentTime+u*.1),g.stop(i.currentTime+u*.1+.2)})},[s]),k=c.useCallback(()=>{if(!t.current)return;const i=s();if(!i)return;const o=i.createOscillator(),x=i.createGain();o.type="sawtooth",o.frequency.setValueAtTime(190,i.currentTime),o.frequency.setValueAtTime(130,i.currentTime+.12),x.gain.setValueAtTime(.07,i.currentTime),x.gain.exponentialRampToValueAtTime(.001,i.currentTime+.25),o.connect(x),x.connect(i.destination),o.start(),o.stop(i.currentTime+.25)},[s]),p=c.useCallback(i=>{if(!t.current)return;const o=s();if(!o)return;const x=400+i%8*50,u=o.createOscillator(),g=o.createGain();u.type="sine",u.frequency.setValueAtTime(x,o.currentTime),g.gain.setValueAtTime(.05,o.currentTime),g.gain.exponentialRampToValueAtTime(.001,o.currentTime+.08),u.connect(g),g.connect(o.destination),u.start(),u.stop(o.currentTime+.08)},[s]),T=c.useCallback(()=>{if(!t.current)return;const i=s();if(!i)return;const o=i.createOscillator(),x=i.createGain();o.type="triangle",o.frequency.setValueAtTime(550,i.currentTime),o.frequency.setValueAtTime(350,i.currentTime+.06),x.gain.setValueAtTime(.05,i.currentTime),x.gain.exponentialRampToValueAtTime(.001,i.currentTime+.1),o.connect(x),x.connect(i.destination),o.start(),o.stop(i.currentTime+.1)},[s]);return{playTilePlaced:a,playTileRemoved:l,playWinSound:r,playLoseSound:m,playErrorSound:k,playStepTick:p,playBacktrackSound:T,setEnabled:n}}function rt(){if(Math.random()<.6){const s=ce(),n=G(s);return{hand:s,isWinning:n.isWin,solution:n.isWin?n:null}}for(let s=0;s<50;s++){const n=D();if(!G(n).isWin)return{hand:n,isWinning:!1,solution:null}}return{hand:D(),isWinning:!1,solution:null}}const ne={hand:[],isWinning:!1,solution:null,phase:"judging",playerSaidWin:null,selectedTiles:[],foundPair:null,foundMelds:[],hintsUsed:0,showHint:!1,feedback:null,roundComplete:!1};function it(){const[t,s]=c.useState(ne),[n,a]=c.useState(0),[l,r]=c.useState(0),[m,k]=c.useState(0),[p,T]=c.useState(!1),[i,o]=c.useState(!0),x=te(),u=c.useCallback(()=>{const d=rt();s({...ne,hand:d.hand,isWinning:d.isWinning,solution:d.solution}),T(!0)},[]),g=c.useCallback(d=>{const v=d===t.isWinning;v&&t.isWinning&&t.solution?(x.playTilePlaced(5),s(j=>({...j,playerSaidWin:d,phase:"grouping",feedback:"Correct! Now identify the pair and melds."}))):v&&!t.isWinning?(x.playWinSound(),a(j=>j+100-t.hintsUsed*20),r(j=>j+1),k(j=>j+1),s(j=>({...j,playerSaidWin:d,phase:"feedback",feedback:"Correct! This hand is not a winner.",roundComplete:!0}))):(x.playLoseSound(),r(j=>j+1),s(j=>({...j,playerSaidWin:d,phase:"feedback",feedback:t.isWinning?"Wrong — this hand IS a winner! Check the solution below.":"Wrong — this hand is NOT a winner.",roundComplete:!0})))},[t,x]),b=c.useCallback(d=>{s(v=>{const j=v.selectedTiles.includes(d)?v.selectedTiles.filter(y=>y!==d):[...v.selectedTiles,d];return{...v,selectedTiles:j}}),x.playTilePlaced(3)},[x]),w=c.useCallback(()=>{if(t.selectedTiles.length!==2||!t.solution)return;const d=t.selectedTiles.map(y=>t.hand[y]),v=t.solution.pair;d[0]===d[1]&&d[0]===v[0]?(x.playTilePlaced(7),s(y=>({...y,foundPair:[d[0],d[1]],selectedTiles:[],feedback:"Pair found! Now identify the 4 melds."}))):(x.playErrorSound(),s(y=>({...y,selectedTiles:[],feedback:"That's not the correct pair. Try again!"})))},[t,x]),$=c.useCallback(()=>{if(t.selectedTiles.length!==3||!t.solution)return;const d=t.selectedTiles.map(y=>t.hand[y]).sort(),v=t.solution.melds.filter((y,W)=>!t.foundMelds.some(S=>JSON.stringify(S.tiles.sort())===JSON.stringify(t.solution.melds[W].tiles.sort()))),j=v.findIndex(y=>JSON.stringify([...y.tiles].sort())===JSON.stringify(d));if(j>=0){const y=v[j];x.playTilePlaced(8);const W=[...t.foundMelds,y];W.length===4?(x.playWinSound(),a(S=>S+200-t.hintsUsed*30),r(S=>S+1),k(S=>S+1),s(S=>({...S,foundMelds:W,selectedTiles:[],phase:"feedback",feedback:"Excellent! You identified all groups correctly!",roundComplete:!0}))):s(S=>({...S,foundMelds:W,selectedTiles:[],feedback:`Meld ${W.length}/4 found! Keep going.`}))}else x.playErrorSound(),s(y=>({...y,selectedTiles:[],feedback:"Those 3 tiles don't form a valid meld in the solution. Try again!"}))},[t,x]),N=c.useCallback(()=>{t.solution&&(x.playBacktrackSound(),s(d=>({...d,hintsUsed:d.hintsUsed+1,showHint:!0})),setTimeout(()=>{s(d=>({...d,showHint:!1}))},3e3))},[t.solution,x]),f=c.useCallback(()=>{r(d=>d+1),s(d=>({...d,phase:"feedback",feedback:"Skipped grouping. Here's the solution:",roundComplete:!0}))},[]),C=c.useCallback(()=>{s(ne),a(0),r(0),k(0),T(!1)},[]),h=c.useCallback(d=>{o(d),x.setEnabled(d)},[x]);return{round:t,score:n,totalRounds:l,correctRounds:m,started:p,soundEnabled:i,startNewRound:u,judgeHand:g,toggleTileSelection:b,submitPair:w,submitMeld:$,useHint:N,skipGrouping:f,resetGame:C,toggleSound:h}}function q({code:t,index:s,selected:n,onClick:a}){return e.jsx(I,{code:t,index:s,size:"lg",selected:n,interactive:!!a,disabled:!a,onClick:a})}function ot(){const{round:t,score:s,totalRounds:n,correctRounds:a,started:l,soundEnabled:r,startNewRound:m,judgeHand:k,toggleTileSelection:p,submitPair:T,submitMeld:i,useHint:o,skipGrouping:x,resetGame:u,toggleSound:g}=it();if(!l)return e.jsx("div",{className:"flex flex-1 items-center justify-center p-6",children:e.jsxs("div",{className:"max-w-md text-center",children:[e.jsx("div",{className:"text-4xl mb-4",children:"📖"}),e.jsx("h2",{className:"text-xl md:text-2xl font-bold text-white mb-2",children:"Guided Mode"}),e.jsxs("p",{className:"text-sm md:text-base text-slate-400 mb-6 leading-relaxed",children:["Practice identifying winning Mahjong hands step-by-step. First judge if the hand is a winner, then identify the ",e.jsx("span",{className:"text-indigo-300 font-semibold",children:"pair"})," and ",e.jsx("span",{className:"text-violet-300 font-semibold",children:"4 melds"})," by selecting tiles. Use hints if you get stuck!"]}),e.jsx("button",{onClick:m,className:"rounded-xl bg-gradient-to-r from-indigo-500 to-violet-500 px-8 py-3 text-sm md:text-base font-bold text-white shadow-lg shadow-indigo-500/25 transition-all hover:shadow-indigo-500/40 hover:scale-105 active:scale-95",children:"Start Learning"})]})});const{hand:b,phase:w,selectedTiles:$,foundPair:N,foundMelds:f,feedback:C,showHint:h,solution:d,roundComplete:v,hintsUsed:j}=t,y=d&&h?N?`Hint: Next meld is ${d.melds[f.length]?.tiles.join(" ")??"done!"}`:`Hint: The pair is ${d.pair[0]} ${d.pair[1]}`:null,W=new Set;if(N){let S=0;for(let M=0;M=0&&(W.add(z),M.splice(H,1))}}return e.jsxs("div",{className:"flex flex-1 flex-col md:flex-row gap-4 md:gap-6 overflow-auto p-4 md:p-6",children:[e.jsxs("div",{className:"flex flex-col gap-4 w-full md:w-80 shrink-0 overflow-y-auto max-h-full pr-1",children:[e.jsxs("div",{className:"rounded-xl border border-slate-700/50 bg-slate-900/60 p-4 md:p-5 backdrop-blur-sm",children:[e.jsx("h3",{className:"text-xs md:text-sm font-semibold uppercase tracking-wider text-slate-400 mb-3",children:"Progress"}),e.jsxs("div",{className:"grid grid-cols-3 gap-3 text-center",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-lg md:text-xl font-bold text-indigo-300",children:s}),e.jsx("p",{className:"text-[10px] md:text-xs text-slate-500",children:"Score"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-lg md:text-xl font-bold text-emerald-300",children:a}),e.jsx("p",{className:"text-[10px] md:text-xs text-slate-500",children:"Correct"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-lg md:text-xl font-bold text-slate-300",children:n}),e.jsx("p",{className:"text-[10px] md:text-xs text-slate-500",children:"Rounds"})]})]})]}),w==="judging"&&e.jsxs("div",{className:"rounded-xl border border-slate-700/50 bg-slate-900/60 p-4 md:p-5 backdrop-blur-sm",children:[e.jsx("h3",{className:"text-xs md:text-sm font-semibold uppercase tracking-wider text-slate-400 mb-2",children:"Step 1: Judge"}),e.jsx("p",{className:"text-xs md:text-sm text-slate-400 mb-4",children:"Is this a valid winning hand?"}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("button",{onClick:()=>k(!0),className:"flex items-center justify-center gap-2 rounded-xl bg-emerald-500/15 px-4 py-3 text-sm md:text-base font-bold text-emerald-300 ring-1 ring-emerald-500/30 transition-all hover:bg-emerald-500/25 hover:scale-105 active:scale-95",children:[e.jsx(V,{size:16})," Win"]}),e.jsxs("button",{onClick:()=>k(!1),className:"flex items-center justify-center gap-2 rounded-xl bg-red-500/15 px-4 py-3 text-sm md:text-base font-bold text-red-300 ring-1 ring-red-500/30 transition-all hover:bg-red-500/25 hover:scale-105 active:scale-95",children:[e.jsx(re,{size:16})," Not Win"]})]})]}),w==="grouping"&&e.jsxs("div",{className:"rounded-xl border border-indigo-500/30 bg-indigo-500/5 p-4 md:p-5 backdrop-blur-sm",children:[e.jsxs("h3",{className:"text-xs md:text-sm font-semibold uppercase tracking-wider text-indigo-300 mb-2",children:["Step 2: ",N?`Find Meld ${f.length+1}/4`:"Find the Pair"]}),e.jsx("p",{className:"text-xs md:text-sm text-slate-400 mb-3",children:N?"Select 3 tiles that form a pong (AAA) or chow (ABC).":"Select 2 identical tiles that form the pair."}),e.jsxs("p",{className:"text-xs md:text-sm text-indigo-300 font-mono mb-3",children:["Selected: ",$.length," / ",N?3:2]}),e.jsx("div",{className:"flex gap-2 mb-3",children:N?e.jsxs("button",{onClick:i,disabled:$.length!==3,className:"flex-1 flex items-center justify-center gap-1.5 rounded-lg bg-indigo-500/20 px-3 py-2.5 text-xs md:text-sm font-medium text-indigo-300 ring-1 ring-indigo-500/30 transition-all hover:bg-indigo-500/30 disabled:opacity-30 disabled:cursor-not-allowed",children:[e.jsx(V,{size:14})," Submit Meld"]}):e.jsxs("button",{onClick:T,disabled:$.length!==2,className:"flex-1 flex items-center justify-center gap-1.5 rounded-lg bg-indigo-500/20 px-3 py-2.5 text-xs md:text-sm font-medium text-indigo-300 ring-1 ring-indigo-500/30 transition-all hover:bg-indigo-500/30 disabled:opacity-30 disabled:cursor-not-allowed",children:[e.jsx(V,{size:14})," Submit Pair"]})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{onClick:o,className:"flex-1 flex items-center justify-center gap-1.5 rounded-lg bg-amber-500/15 px-3 py-2 text-xs md:text-sm font-medium text-amber-300 ring-1 ring-amber-500/30 transition-all hover:bg-amber-500/25",children:[e.jsx(Me,{size:14})," Hint (",j,")"]}),e.jsxs("button",{onClick:x,className:"flex-1 flex items-center justify-center gap-1.5 rounded-lg bg-slate-800/60 px-3 py-2 text-xs md:text-sm font-medium text-slate-400 transition-all hover:bg-slate-700/60",children:[e.jsx(Re,{size:14})," Skip"]})]})]}),C&&e.jsxs("div",{className:`rounded-xl border p-4 md:p-5 backdrop-blur-sm ${w==="feedback"&&v?t.playerSaidWin===t.isWinning?"border-emerald-500/30 bg-emerald-500/5":"border-red-500/30 bg-red-500/5":"border-indigo-500/30 bg-indigo-500/5"}`,children:[e.jsx("p",{className:"text-xs md:text-sm text-slate-300 leading-relaxed",children:C}),y&&e.jsx("p",{className:"mt-2 text-xs md:text-sm text-amber-300 font-mono animate-pulse",children:y}),v&&d&&e.jsxs("div",{className:"mt-3 text-[10px] md:text-xs text-slate-500",children:[e.jsxs("p",{children:["Solution: Pair ",d.pair.join(" ")]}),d.melds.map((S,M)=>e.jsxs("p",{children:[S.type==="pong"?"Pong":"Chow",": ",S.tiles.join(" ")]},M))]}),v&&e.jsxs("button",{onClick:m,className:"mt-3 w-full flex items-center justify-center gap-2 rounded-lg bg-indigo-500/20 px-4 py-2.5 text-xs md:text-sm font-medium text-indigo-300 ring-1 ring-indigo-500/30 transition-all hover:bg-indigo-500/30",children:["Next Round ",e.jsx(de,{size:14})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{onClick:u,className:"flex-1 flex items-center justify-center gap-1.5 rounded-lg bg-slate-800/60 px-3 py-2.5 text-xs md:text-sm font-medium text-slate-400 transition-all hover:bg-slate-700/60 hover:text-slate-300",children:[e.jsx(K,{size:14})," Reset"]}),e.jsx("button",{onClick:()=>g(!r),className:`flex items-center justify-center gap-1.5 rounded-lg px-3 py-2.5 text-xs md:text-sm font-medium transition-all ${r?"bg-indigo-500/15 text-indigo-300 ring-1 ring-indigo-500/30":"bg-slate-800/60 text-slate-400"}`,children:r?e.jsx(Q,{size:14}):e.jsx(ee,{size:14})})]})]}),e.jsxs("div",{className:"order-last md:order-first flex md:flex-1 flex-col gap-4 min-h-0 md:overflow-auto",children:[e.jsxs("div",{className:"rounded-2xl border border-emerald-900/40 bg-[radial-gradient(circle_at_top_left,rgba(16,185,129,0.14),transparent_34%),linear-gradient(135deg,rgba(15,23,42,0.96),rgba(6,78,59,0.32))] p-4 shadow-2xl shadow-black/30 md:p-5",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3 md:mb-4",children:[e.jsx("h3",{className:"text-xs md:text-sm font-semibold uppercase tracking-wider text-emerald-200",children:"Hand"}),N&&e.jsxs("span",{className:"text-xs md:text-sm font-mono text-emerald-300",children:["Pair ✓ | Melds ",f.length,"/4"]})]}),e.jsx("div",{className:"flex flex-wrap items-end gap-1.5 rounded-xl border border-emerald-950/40 bg-emerald-950/20 p-3 shadow-inner md:gap-2",children:b.map((S,M)=>{const z=W.has(M),H=$.includes(M),se=w==="grouping"&&!z;return e.jsx("div",{className:z?"opacity-30":"",children:e.jsx(q,{code:S,index:M,selected:H,onClick:se?()=>p(M):void 0})},`${S}-${M}`)})})]}),(N||f.length>0)&&e.jsxs("div",{className:"rounded-2xl border border-emerald-500/20 bg-emerald-500/5 p-4 shadow-xl shadow-emerald-950/20 backdrop-blur-sm md:p-5",children:[e.jsx("h3",{className:"text-xs md:text-sm font-semibold uppercase tracking-wider text-emerald-400 mb-3",children:"Found Groups"}),N&&e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("span",{className:"text-[10px] md:text-xs font-medium text-slate-600 w-14 shrink-0",children:"Pair"}),e.jsxs("div",{className:"flex gap-1",children:[e.jsx(q,{code:N[0],index:-1,selected:!1}),e.jsx(q,{code:N[1],index:-1,selected:!1})]})]}),f.map((S,M)=>e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsxs("span",{className:"text-[10px] md:text-xs font-medium text-slate-600 w-14 shrink-0",children:[S.type==="pong"?"Pong":"Chow"," ",M+1]}),e.jsx("div",{className:"flex gap-1",children:S.tiles.map((z,H)=>e.jsx(q,{code:z,index:-1,selected:!1},`${z}-${H}`))})]},M))]})]})]})}function ue(){if(Math.random()<.5){const s=ce(),n=G(s);return{hand:s,isWinning:n.isWin,solution:n.isWin?n:null}}for(let s=0;s<50;s++){const n=D();if(!G(n).isWin)return{hand:n,isWinning:!1,solution:null}}return{hand:D(),isWinning:!1,solution:null}}const ae={hand:[],isWinning:!1,solution:null,round:0,score:0,streak:0,bestStreak:0,timer:0,answered:!1,lastCorrect:null,totalCorrect:0,totalAnswered:0};function dt(){const[t,s]=c.useState(ae),[n,a]=c.useState(!1),l=c.useRef(null),r=te(),[m,k]=c.useState(!0);c.useEffect(()=>(n&&!t.answered&&(l.current=setInterval(()=>{s(u=>({...u,timer:u.timer+1}))},1e3)),()=>{l.current&&clearInterval(l.current)}),[n,t.answered]);const p=c.useCallback(()=>{const{hand:u,isWinning:g,solution:b}=ue();s({...ae,hand:u,isWinning:g,solution:b,round:1}),a(!0)},[]),T=c.useCallback(()=>{const{hand:u,isWinning:g,solution:b}=ue();s(w=>({...w,hand:u,isWinning:g,solution:b,round:w.round+1,timer:0,answered:!1,lastCorrect:null}))},[]),i=c.useCallback(u=>{if(t.answered)return;const g=u===t.isWinning,b=Math.max(0,10-t.timer),w=g?100+b*10+t.streak*25:0;g?r.playWinSound():r.playLoseSound(),s($=>({...$,answered:!0,lastCorrect:g,score:$.score+w,streak:g?$.streak+1:0,bestStreak:g?Math.max($.bestStreak,$.streak+1):$.bestStreak,totalCorrect:$.totalCorrect+(g?1:0),totalAnswered:$.totalAnswered+1}))},[t.answered,t.isWinning,t.timer,t.streak,r]),o=c.useCallback(()=>{s(ae),a(!1),l.current&&clearInterval(l.current)},[]),x=c.useCallback(u=>{k(u),r.setEnabled(u)},[r]);return{...t,isRunning:n,soundEnabled:m,startGame:p,nextRound:T,answer:i,resetGame:o,toggleSound:x}}function ct({code:t}){return e.jsx(I,{code:t,size:"lg"})}function xt(){const{hand:t,isWinning:s,solution:n,round:a,score:l,streak:r,bestStreak:m,timer:k,answered:p,lastCorrect:T,totalCorrect:i,totalAnswered:o,isRunning:x,soundEnabled:u,startGame:g,nextRound:b,answer:w,resetGame:$,toggleSound:N}=dt();return x?e.jsxs("div",{className:"flex flex-1 flex-col md:flex-row gap-4 md:gap-6 overflow-auto p-4 md:p-6",children:[e.jsxs("div",{className:"flex flex-col gap-4 w-full md:w-80 shrink-0 overflow-y-auto max-h-full pr-1",children:[e.jsxs("div",{className:"rounded-xl border border-slate-700/50 bg-slate-900/60 p-4 md:p-5 backdrop-blur-sm",children:[e.jsx("h3",{className:"text-xs md:text-sm font-semibold uppercase tracking-wider text-slate-400 mb-3",children:"Stats"}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Y,{size:14,className:"text-amber-400"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-lg md:text-xl font-bold text-white",children:l}),e.jsx("p",{className:"text-[10px] md:text-xs text-slate-500",children:"Score"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ae,{size:14,className:"text-orange-400"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-lg md:text-xl font-bold text-orange-300",children:r}),e.jsx("p",{className:"text-[10px] md:text-xs text-slate-500",children:"Streak"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(He,{size:14,className:"text-cyan-400"}),e.jsxs("div",{children:[e.jsxs("p",{className:"text-lg md:text-xl font-bold text-cyan-300",children:[k,"s"]}),e.jsx("p",{className:"text-[10px] md:text-xs text-slate-500",children:"Time"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(V,{size:14,className:"text-emerald-400"}),e.jsxs("div",{children:[e.jsxs("p",{className:"text-lg md:text-xl font-bold text-emerald-300",children:[i,"/",o]}),e.jsx("p",{className:"text-[10px] md:text-xs text-slate-500",children:"Correct"})]})]})]}),e.jsxs("div",{className:"mt-3 flex items-center justify-between text-[10px] md:text-xs text-slate-500",children:[e.jsxs("span",{children:["Round ",a]}),e.jsxs("span",{children:["Best streak: ",m]})]})]}),!p&&e.jsxs("div",{className:"rounded-xl border border-slate-700/50 bg-slate-900/60 p-4 md:p-5 backdrop-blur-sm",children:[e.jsx("h3",{className:"text-xs md:text-sm font-semibold uppercase tracking-wider text-slate-400 mb-3",children:"Your Judgment"}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("button",{onClick:()=>w(!0),className:"flex items-center justify-center gap-2 rounded-xl bg-emerald-500/15 px-4 py-4 text-sm md:text-base font-bold text-emerald-300 ring-1 ring-emerald-500/30 transition-all hover:bg-emerald-500/25 hover:scale-105 active:scale-95",children:[e.jsx(V,{size:18})," Win"]}),e.jsxs("button",{onClick:()=>w(!1),className:"flex items-center justify-center gap-2 rounded-xl bg-red-500/15 px-4 py-4 text-sm md:text-base font-bold text-red-300 ring-1 ring-red-500/30 transition-all hover:bg-red-500/25 hover:scale-105 active:scale-95",children:[e.jsx(re,{size:18})," Not Win"]})]})]}),p&&e.jsxs("div",{className:`rounded-xl border p-4 md:p-5 backdrop-blur-sm ${T?"border-emerald-500/30 bg-emerald-500/5":"border-red-500/30 bg-red-500/5"}`,children:[e.jsx("div",{className:"flex items-center gap-2 mb-2",children:T?e.jsxs(e.Fragment,{children:[e.jsx(V,{size:18,className:"text-emerald-400"}),e.jsx("span",{className:"text-sm md:text-base font-bold text-emerald-300",children:"Correct!"})]}):e.jsxs(e.Fragment,{children:[e.jsx(re,{size:18,className:"text-red-400"}),e.jsx("span",{className:"text-sm md:text-base font-bold text-red-300",children:"Wrong!"})]})}),e.jsxs("p",{className:"text-xs md:text-sm text-slate-400 mb-3",children:["The hand was ",e.jsx("span",{className:`font-bold ${s?"text-emerald-300":"text-red-300"}`,children:s?"a Winner":"Not a Winner"}),"."]}),s&&n&&e.jsxs("div",{className:"text-[10px] md:text-xs text-slate-500 mb-3",children:["Pair: ",n.pair.join(" ")," | Melds: ",n.melds.map(f=>f.tiles.join(" ")).join(" | ")]}),e.jsxs("button",{onClick:b,className:"w-full flex items-center justify-center gap-2 rounded-lg bg-indigo-500/20 px-4 py-2.5 text-xs md:text-sm font-medium text-indigo-300 ring-1 ring-indigo-500/30 transition-all hover:bg-indigo-500/30",children:["Next Round ",e.jsx(de,{size:14})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{onClick:$,className:"flex-1 flex items-center justify-center gap-1.5 rounded-lg bg-slate-800/60 px-3 py-2.5 text-xs md:text-sm font-medium text-slate-400 transition-all hover:bg-slate-700/60 hover:text-slate-300",children:[e.jsx(K,{size:14})," Reset"]}),e.jsx("button",{onClick:()=>N(!u),className:`flex items-center justify-center gap-1.5 rounded-lg px-3 py-2.5 text-xs md:text-sm font-medium transition-all ${u?"bg-indigo-500/15 text-indigo-300 ring-1 ring-indigo-500/30":"bg-slate-800/60 text-slate-400"}`,children:u?e.jsx(Q,{size:14}):e.jsx(ee,{size:14})})]})]}),e.jsx("div",{className:"order-last md:order-first flex md:flex-1 flex-col gap-4 min-h-0 md:overflow-auto",children:e.jsxs("div",{className:"rounded-2xl border border-emerald-900/40 bg-[radial-gradient(circle_at_top_left,rgba(16,185,129,0.14),transparent_34%),linear-gradient(135deg,rgba(15,23,42,0.96),rgba(6,78,59,0.32))] p-4 shadow-2xl shadow-black/30 md:p-5",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3 md:mb-4",children:[e.jsx("h3",{className:"text-xs md:text-sm font-semibold uppercase tracking-wider text-emerald-200",children:"Hand to Judge"}),e.jsxs("span",{className:"text-xs md:text-sm font-mono font-bold text-indigo-300",children:["Round ",a]})]}),e.jsx("div",{className:"flex flex-wrap items-end gap-1.5 rounded-xl border border-emerald-950/40 bg-emerald-950/20 p-3 shadow-inner md:gap-2",children:t.map((f,C)=>e.jsx(ct,{code:f},`${f}-${C}`))})]})})]}):e.jsx("div",{className:"flex flex-1 items-center justify-center p-6",children:e.jsxs("div",{className:"max-w-md text-center",children:[e.jsx("div",{className:"text-4xl mb-4",children:"⚡"}),e.jsx("h2",{className:"text-xl md:text-2xl font-bold text-white mb-2",children:"Challenge Mode"}),e.jsxs("p",{className:"text-sm md:text-base text-slate-400 mb-6 leading-relaxed",children:["You'll see a 14-tile hand. Decide as fast as you can: is it a ",e.jsx("span",{className:"text-emerald-400 font-semibold",children:"Winning Hand"})," or ",e.jsx("span",{className:"text-red-400 font-semibold",children:"Not a Winner"}),"? Score points for correct answers. Faster = more bonus points. Build streaks for multipliers!"]}),e.jsx("button",{onClick:g,className:"rounded-xl bg-gradient-to-r from-indigo-500 to-violet-500 px-8 py-3 text-sm md:text-base font-bold text-white shadow-lg shadow-indigo-500/25 transition-all hover:shadow-indigo-500/40 hover:scale-105 active:scale-95",children:"Start Challenge"})]})})}function ge(t){return{name:t,hand:[],result:null,score:0}}const le={phase:"building",players:[ge("Player 1"),ge("Player 2")],currentPlayer:0,round:1,roundComplete:!1};function mt(){const[t,s]=c.useState(le),[n,a]=c.useState(null),[l,r]=c.useState(!1),[m,k]=c.useState(!0),p=te(),T=t.players[t.currentPlayer].hand,i=T.length>=P,o=t.players[0].hand.length>=P&&t.players[1].hand.length>=P,x=c.useCallback(()=>{s({...le}),r(!0),a(null)},[]),u=c.useCallback(h=>{if(t.phase!=="building")return;const d=t.players[t.currentPlayer].hand,v=be(d,h);if(v){a(v),p.playErrorSound();return}a(null);const{value:j}={value:Number(h[1])};p.playTilePlaced(j),s(y=>{const W=[...y.players],S={...W[y.currentPlayer]};S.hand=L([...S.hand,h]),W[y.currentPlayer]=S;const M=S.hand.length>=P,z=W[1-y.currentPlayer].hand.length>=P;let H=y.currentPlayer;return M&&!z?H=1-y.currentPlayer:M||(H=1-y.currentPlayer,W[H].hand.length>=P&&(H=y.currentPlayer)),{...y,players:W,currentPlayer:H}})},[t.phase,t.currentPlayer,t.players,p]),g=c.useCallback(h=>{t.phase==="building"&&(p.playTileRemoved(),a(null),s(d=>{const v=[...d.players],j={...v[d.currentPlayer]},y=[...j.hand];return y.splice(h,1),j.hand=y,v[d.currentPlayer]=j,{...d,players:v}}))},[t.phase,p]),b=c.useCallback(()=>{if(!o)return;const h=G(t.players[0].hand),d=G(t.players[1].hand),v=h.isWin?1:0,j=d.isWin?1:0;v>j||j>v?p.playWinSound():p.playLoseSound(),s(y=>{const W=[...y.players];return W[0]={...W[0],result:h,score:W[0].score+v},W[1]={...W[1],result:d,score:W[1].score+j},{...y,players:W,phase:"results",roundComplete:!0}})},[o,t.players,p]),w=c.useCallback(()=>{s(h=>({...h,phase:"building",players:[{...h.players[0],hand:[],result:null},{...h.players[1],hand:[],result:null}],currentPlayer:0,round:h.round+1,roundComplete:!1})),a(null)},[]),$=c.useCallback(()=>{s(le),r(!1),a(null)},[]),N=c.useCallback(()=>{if(t.phase!=="building")return;const h=1-t.currentPlayer;t.players[h].hand.length>=P||s(d=>({...d,currentPlayer:h}))},[t.phase,t.currentPlayer,t.players]),f=()=>{if(t.phase!=="results")return null;const h=t.players[0].result,d=t.players[1].result;return!h||!d?null:h.isWin&&!d.isWin?t.players[0].name:!h.isWin&&d.isWin?t.players[1].name:h.isWin&&d.isWin?"Both Win!":"Neither Wins"},C=c.useCallback(h=>{k(h),p.setEnabled(h)},[p]);return{state:t,lastError:n,started:l,soundEnabled:m,currentHand:T,currentHandIsFull:i,bothFull:o,winner:f(),startGame:x,addTile:u,removeTile:g,checkBothHands:b,nextRound:w,resetGame:$,switchPlayer:N,toggleSound:C}}function ut({code:t,onRemove:s}){return e.jsx(I,{code:t,size:"md",interactive:!!s,removable:!!s,onClick:s})}function gt(t,s){return t.filter(n=>n===s).length}function pt({suit:t,value:s,count:n,disabled:a,onClick:l}){const r=n>=4,m=`${t}${s}`;return e.jsx(I,{code:m,count:n,size:"sm",disabled:a||r,interactive:!0,onClick:l})}function ht(){const{state:t,lastError:s,started:n,soundEnabled:a,currentHand:l,currentHandIsFull:r,bothFull:m,winner:k,startGame:p,addTile:T,removeTile:i,checkBothHands:o,nextRound:x,resetGame:u,switchPlayer:g,toggleSound:b}=mt();if(!n)return e.jsx("div",{className:"flex flex-1 items-center justify-center p-6",children:e.jsxs("div",{className:"max-w-md text-center",children:[e.jsx("div",{className:"text-4xl mb-4",children:"👥"}),e.jsx("h2",{className:"text-xl md:text-2xl font-bold text-white mb-2",children:"2 Player Mode"}),e.jsxs("p",{className:"text-sm md:text-base text-slate-400 mb-6 leading-relaxed",children:["Take turns placing tiles to build your 14-tile hands. Players alternate picks. Once both hands are complete, the solver checks both — whoever has a valid ",e.jsx("span",{className:"text-emerald-400 font-semibold",children:"winning hand"})," scores a point!"]}),e.jsx("button",{onClick:p,className:"rounded-xl bg-gradient-to-r from-indigo-500 to-violet-500 px-8 py-3 text-sm md:text-base font-bold text-white shadow-lg shadow-indigo-500/25 transition-all hover:shadow-indigo-500/40 hover:scale-105 active:scale-95",children:"Start Game"})]})});const{phase:w,players:$,currentPlayer:N,round:f}=t,C=$[0],h=$[1];return e.jsxs("div",{className:"flex flex-1 flex-col md:flex-row gap-4 md:gap-6 overflow-auto p-4 md:p-6",children:[e.jsxs("div",{className:"flex flex-col gap-4 w-full md:w-80 shrink-0 overflow-y-auto max-h-full pr-1",children:[e.jsxs("div",{className:"rounded-xl border border-slate-700/50 bg-slate-900/60 p-4 md:p-5 backdrop-blur-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(pe,{size:14,className:"text-indigo-400"}),e.jsxs("h3",{className:"text-xs md:text-sm font-semibold uppercase tracking-wider text-slate-400",children:["Round ",f]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:`rounded-lg p-3 text-center transition-all ${w==="building"&&N===0?"bg-indigo-500/15 ring-2 ring-indigo-400/40":"bg-slate-800/40"}`,children:[e.jsx("p",{className:"text-sm md:text-base font-bold text-indigo-300",children:C.name}),e.jsx("p",{className:"text-lg md:text-xl font-extrabold text-white",children:C.score}),e.jsxs("p",{className:"text-[10px] md:text-xs text-slate-500",children:[C.hand.length,"/",P," tiles"]}),w==="results"&&C.result&&e.jsx("p",{className:`mt-1 text-[10px] md:text-xs font-bold ${C.result.isWin?"text-emerald-400":"text-red-400"}`,children:C.result.isWin?"✓ Winner":"✗ No Win"})]}),e.jsxs("div",{className:`rounded-lg p-3 text-center transition-all ${w==="building"&&N===1?"bg-violet-500/15 ring-2 ring-violet-400/40":"bg-slate-800/40"}`,children:[e.jsx("p",{className:"text-sm md:text-base font-bold text-violet-300",children:h.name}),e.jsx("p",{className:"text-lg md:text-xl font-extrabold text-white",children:h.score}),e.jsxs("p",{className:"text-[10px] md:text-xs text-slate-500",children:[h.hand.length,"/",P," tiles"]}),w==="results"&&h.result&&e.jsx("p",{className:`mt-1 text-[10px] md:text-xs font-bold ${h.result.isWin?"text-emerald-400":"text-red-400"}`,children:h.result.isWin?"✓ Winner":"✗ No Win"})]})]})]}),w==="building"&&e.jsxs("div",{className:`rounded-xl border p-4 md:p-5 backdrop-blur-sm ${N===0?"border-indigo-500/30 bg-indigo-500/5":"border-violet-500/30 bg-violet-500/5"}`,children:[e.jsxs("p",{className:`text-sm md:text-base font-bold ${N===0?"text-indigo-300":"text-violet-300"}`,children:[$[N].name,"'s Turn"]}),e.jsx("p",{className:"text-xs md:text-sm text-slate-400 mt-1",children:"Pick a tile to add to your hand."}),!r&&e.jsxs("button",{onClick:g,className:"mt-3 w-full flex items-center justify-center gap-1.5 rounded-lg bg-slate-800/60 px-3 py-2 text-xs md:text-sm font-medium text-slate-400 transition-all hover:bg-slate-700/60 hover:text-slate-300",children:[e.jsx(Ie,{size:14})," Switch Player"]})]}),w==="building"&&m&&e.jsxs("button",{onClick:o,className:"w-full flex items-center justify-center gap-2 rounded-xl bg-gradient-to-r from-indigo-500/20 to-violet-500/20 px-4 py-3 text-sm md:text-base font-bold text-indigo-200 ring-1 ring-indigo-500/30 transition-all hover:from-indigo-500/30 hover:to-violet-500/30 active:scale-95",children:[e.jsx(Y,{size:16})," Check Both Hands"]}),w==="results"&&k&&e.jsxs("div",{className:`rounded-xl border p-4 md:p-5 backdrop-blur-sm ${k.includes("Neither")?"border-slate-700/50 bg-slate-900/60":"border-emerald-500/30 bg-emerald-500/5"}`,children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(Y,{size:18,className:"text-amber-400"}),e.jsx("span",{className:"text-base md:text-lg font-bold text-white",children:k})]}),$.map((d,v)=>d.result&&d.result.isWin&&e.jsxs("div",{className:"mt-2 text-[10px] md:text-xs text-slate-500",children:[e.jsxs("p",{className:"font-semibold text-slate-400",children:[d.name,":"]}),e.jsxs("p",{children:["Pair: ",d.result.pair.join(" ")]}),d.result.melds.map((j,y)=>e.jsxs("p",{children:[j.type==="pong"?"Pong":"Chow",": ",j.tiles.join(" ")]},y))]},v)),e.jsxs("button",{onClick:x,className:"mt-3 w-full flex items-center justify-center gap-2 rounded-lg bg-indigo-500/20 px-4 py-2.5 text-xs md:text-sm font-medium text-indigo-300 ring-1 ring-indigo-500/30 transition-all hover:bg-indigo-500/30",children:["Next Round ",e.jsx(de,{size:14})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{onClick:u,className:"flex-1 flex items-center justify-center gap-1.5 rounded-lg bg-slate-800/60 px-3 py-2.5 text-xs md:text-sm font-medium text-slate-400 transition-all hover:bg-slate-700/60 hover:text-slate-300",children:[e.jsx(K,{size:14})," Reset"]}),e.jsx("button",{onClick:()=>b(!a),className:`flex items-center justify-center gap-1.5 rounded-lg px-3 py-2.5 text-xs md:text-sm font-medium transition-all ${a?"bg-indigo-500/15 text-indigo-300 ring-1 ring-indigo-500/30":"bg-slate-800/60 text-slate-400"}`,children:a?e.jsx(Q,{size:14}):e.jsx(ee,{size:14})})]}),s&&e.jsx("div",{className:"rounded-lg border border-red-500/30 bg-red-500/5 px-3 py-2.5 text-center text-xs md:text-sm font-medium text-red-400 animate-pulse",children:s})]}),e.jsxs("div",{className:"order-last md:order-first flex md:flex-1 flex-col gap-4 min-h-0 md:overflow-auto",children:[$.map((d,v)=>e.jsxs("div",{className:`rounded-2xl border p-4 shadow-xl backdrop-blur-sm md:p-5 ${w==="building"&&N===v?v===0?"border-indigo-500/30 bg-indigo-500/5":"border-violet-500/30 bg-violet-500/5":"border-emerald-900/40 bg-[radial-gradient(circle_at_top_left,rgba(16,185,129,0.12),transparent_34%),linear-gradient(135deg,rgba(15,23,42,0.96),rgba(6,78,59,0.28))]"}`,children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("h3",{className:`text-xs md:text-sm font-semibold uppercase tracking-wider ${v===0?"text-indigo-400":"text-violet-400"}`,children:d.name}),e.jsxs("span",{className:`text-xs md:text-sm font-mono font-bold ${d.hand.length===P?"text-emerald-400":"text-slate-500"}`,children:[d.hand.length,"/",P]})]}),e.jsxs("div",{className:"flex min-h-[5rem] flex-wrap items-end gap-1.5 rounded-xl border border-emerald-950/40 bg-emerald-950/20 p-3 shadow-inner md:gap-2",children:[d.hand.map((j,y)=>e.jsx(ut,{code:j,onRemove:w==="building"&&N===v?()=>i(y):void 0},`${j}-${y}`)),d.hand.lengthe.jsx(I,{size:"md",placeholder:!0},`e-${y}`))]})]},v)),w==="building"&&!r&&e.jsxs("div",{className:"rounded-2xl border border-slate-700/50 bg-slate-900/70 p-4 shadow-xl shadow-black/20 backdrop-blur-sm md:p-5",children:[e.jsx("h3",{className:"text-xs md:text-sm font-semibold uppercase tracking-wider text-slate-300 mb-3",children:"Tile Wall"}),e.jsx("div",{className:"space-y-3 md:space-y-4",children:B.map(d=>e.jsxs("div",{className:"rounded-xl border border-slate-800/70 bg-slate-950/35 p-3",children:[e.jsx("p",{className:"text-[10px] md:text-xs font-medium mb-1.5",style:{color:Z[d]},children:he[d]}),e.jsx("div",{className:"flex flex-wrap items-end gap-1 md:gap-1.5",children:O.map(v=>{const j=`${d}${v}`;return e.jsx(pt,{suit:d,value:v,count:gt(l,j),disabled:r,onClick:()=>T(j)},j)})})]},d))})]})]})]})}function ft(){const[t,s]=c.useState([]),[n,a]=c.useState(null),[l,r]=c.useState([]),[m,k]=c.useState(-1),[p,T]=c.useState(!1),[i,o]=c.useState(400),[x,u]=c.useState(null),[g,b]=c.useState(!1),[w,$]=c.useState(!0),N=c.useRef(null),f=te();c.useEffect(()=>()=>{N.current&&clearInterval(N.current)},[]);const C=c.useCallback(()=>{a(null),r([]),k(-1),T(!1),N.current&&(clearInterval(N.current),N.current=null)},[]),h=c.useCallback(_=>{s(A=>{const R=be(A,_);return R?(u(R),f.playErrorSound(),A):(u(null),C(),f.playTilePlaced(fe(_).value),L([...A,_]))})},[C,f]),d=c.useCallback(_=>{s(A=>{const R=[...A];return R.splice(_,1),C(),f.playTileRemoved(),R}),u(null)},[C,f]),v=c.useCallback(()=>{s([]),u(null),C()},[C]),j=c.useCallback(()=>{s(D()),u(null),C()},[C]),y=c.useCallback(()=>{s(ce()),u(null),C()},[C]),W=c.useCallback(()=>{const _=st(t);if(_){u(_),f.playErrorSound();return}if(u(null),g){const{result:A,steps:R}=at(t);a(A),r(R),k(-1)}else{const A=G(t);a(A),r([]),k(-1),A.isWin?f.playWinSound():f.playLoseSound()}},[t,g,f]),S=c.useCallback(()=>{k(_=>{const A=Math.min(_+1,l.length-1);if(A>=0&&A{k(_=>Math.max(_-1,-1))},[]),z=c.useCallback(()=>{if(p){N.current&&(clearInterval(N.current),N.current=null),T(!1);return}T(!0),k(_=>_>=l.length-1?-1:_),N.current=setInterval(()=>{k(_=>{if(_>=l.length-1)return N.current&&clearInterval(N.current),N.current=null,T(!1),_;const A=_+1;if(A{b(_=>!_),C()},[C]),se=c.useCallback(_=>{$(_),f.setEnabled(_)},[f]),Ne=m>=0&&m=P,soundEnabled:w,addTile:h,removeTile:d,resetHand:v,randomHand:j,winningHand:y,checkHand:W,stepForward:S,stepBack:M,autoPlay:z,setAnimSpeed:o,toggleAnimation:H,toggleSound:se}}const bt={sandbox:e.jsx(Le,{size:14}),guided:e.jsx(ze,{size:14}),challenge:e.jsx(Ee,{size:14}),"two-player":e.jsx(pe,{size:14})},jt=["sandbox","guided","challenge","two-player"];function yt(){const{hand:t,result:s,steps:n,stepIndex:a,stepsTotal:l,currentStep:r,isAnimating:m,animSpeed:k,showAnimation:p,lastError:T,handIsFull:i,addTile:o,removeTile:x,resetHand:u,randomHand:g,winningHand:b,checkHand:w,stepForward:$,stepBack:N,autoPlay:f,setAnimSpeed:C,toggleAnimation:h,soundEnabled:d,toggleSound:v}=ft();return e.jsxs("div",{className:"flex flex-1 flex-col md:flex-row gap-4 md:gap-6 overflow-auto bg-[radial-gradient(circle_at_top,rgba(16,185,129,0.08),transparent_34%),linear-gradient(180deg,rgba(15,23,42,0),rgba(6,78,59,0.16))] p-4 md:p-6",children:[e.jsx(et,{handIsFull:i,result:s,showAnimation:p,steps:n,stepIndex:a,stepsTotal:l,isAnimating:m,animSpeed:k,currentStep:r,lastError:T,onCheckHand:w,onResetHand:u,onRandomHand:g,onWinningHand:b,onToggleAnimation:h,onStepForward:$,onStepBack:N,onAutoPlay:f,onSetAnimSpeed:C,soundEnabled:d,onToggleSound:v}),e.jsxs("div",{className:"order-last md:order-first flex md:flex-1 flex-col gap-4 min-h-0 md:min-h-0 md:overflow-auto",children:[e.jsx(Ze,{hand:t,onRemoveTile:x}),s&&e.jsx(Ke,{result:s}),e.jsx(Ye,{hand:t,handIsFull:i,onAddTile:o})]})]})}function zt(){const[t,s]=c.useState("sandbox");return e.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[e.jsx("div",{className:"shrink-0 border-b border-emerald-900/40 bg-[linear-gradient(135deg,rgba(15,23,42,0.9),rgba(6,78,59,0.34))] backdrop-blur-sm px-4 md:px-6 pt-3 pb-0",children:e.jsx("div",{className:"flex gap-1 overflow-x-auto",children:jt.map(n=>e.jsxs("button",{onClick:()=>s(n),className:`flex items-center gap-1.5 rounded-t-lg px-4 py-2.5 text-xs md:text-sm font-medium transition-all whitespace-nowrap ${t===n?"bg-slate-800/80 text-indigo-300 border border-b-0 border-slate-700/50 -mb-px":"text-slate-500 hover:text-slate-300 hover:bg-slate-800/30"}`,children:[bt[n],e.jsx("span",{children:De[n].label})]},n))})}),e.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[t==="sandbox"&&e.jsx(yt,{}),t==="guided"&&e.jsx(ot,{}),t==="challenge"&&e.jsx(xt,{}),t==="two-player"&&e.jsx(ht,{})]})]})}export{zt as default};
+ `;return k||i?e.jsx("button",{onClick:i,disabled:r,title:t,className:b,children:g}):e.jsx("div",{className:b,children:g})}function Ue({suit:t,value:s,color:n,size:a}){return t==="C"?e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("span",{style:{color:n},className:`${a==="sm"?"text-xl":a==="lg"?"text-3xl":"text-2xl"} font-black leading-none drop-shadow-sm`,children:s}),e.jsx("span",{style:{color:n},className:`${a==="sm"?"text-base":"text-lg"} font-black leading-none`,children:"萬"})]}):t==="B"?e.jsx("div",{className:"grid grid-cols-3 gap-0.5",children:Array.from({length:s}).map((l,r)=>e.jsx("span",{className:"h-3 w-1 rounded-full border border-emerald-950/20 bg-gradient-to-b from-emerald-300 to-emerald-700 shadow-sm"},r))}):e.jsx("div",{className:"grid grid-cols-3 gap-0.5",children:Array.from({length:s}).map((l,r)=>e.jsx("span",{className:"h-2.5 w-2.5 rounded-full border border-blue-950/30 bg-white shadow-sm",style:{boxShadow:`inset 0 0 0 2px ${n}`}},r))})}function Je(t,s){return t.filter(n=>n===s).length}function qe({suit:t,value:s,count:n,disabled:a,onClick:l}){const r=n>=4,m=`${t}${s}`;return e.jsx(I,{code:m,count:n,size:"md",disabled:a||r,interactive:!0,onClick:l})}function Ye({hand:t,handIsFull:s,onAddTile:n}){return e.jsxs("div",{className:"rounded-2xl border border-slate-700/50 bg-slate-900/70 p-4 shadow-xl shadow-black/20 backdrop-blur-sm md:p-5",children:[e.jsxs("div",{className:"mb-3 md:mb-4",children:[e.jsx("h3",{className:"text-xs md:text-sm font-semibold uppercase tracking-wider text-slate-300",children:"Tile Wall"}),e.jsx("p",{className:"mt-0.5 text-[10px] text-slate-500",children:"Choose up to four copies of each realistic Mahjong tile"})]}),e.jsx("div",{className:"space-y-4 md:space-y-5",children:B.map(a=>e.jsxs("div",{className:"rounded-xl border border-slate-800/70 bg-slate-950/35 p-3",children:[e.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[e.jsx("span",{className:"h-2 w-2 rounded-full",style:{backgroundColor:Z[a]}}),e.jsx("p",{className:"text-[10px] md:text-xs font-semibold uppercase tracking-wider",style:{color:Z[a]},children:he[a]})]}),e.jsx("div",{className:"flex flex-wrap items-end gap-1.5 md:gap-2",children:O.map(l=>{const r=`${a}${l}`;return e.jsx(qe,{suit:a,value:l,count:Je(t,r),disabled:s,onClick:()=>n(r)},r)})})]},a))})]})}function Ze({hand:t,onRemoveTile:s}){const n=P-t.length;return e.jsxs("div",{className:"relative overflow-hidden rounded-2xl border border-emerald-900/40 bg-[radial-gradient(circle_at_top_left,rgba(16,185,129,0.14),transparent_34%),linear-gradient(135deg,rgba(15,23,42,0.96),rgba(6,78,59,0.36))] p-4 shadow-2xl shadow-black/30 md:p-5",children:[e.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 h-16 bg-gradient-to-t from-black/25 to-transparent"}),e.jsxs("div",{className:"flex items-center justify-between mb-3 md:mb-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-xs md:text-sm font-semibold uppercase tracking-wider text-emerald-200",children:"Your Hand"}),e.jsx("p",{className:"mt-0.5 text-[10px] text-emerald-100/50",children:"Click a tile to discard it from the rack"})]}),e.jsxs("span",{className:`text-xs md:text-sm font-mono font-bold ${t.length===P?"text-emerald-400":"text-slate-500"}`,children:[t.length," / ",P]})]}),e.jsxs("div",{className:"relative flex min-h-[5.5rem] flex-wrap items-end gap-1.5 rounded-xl border border-emerald-950/40 bg-emerald-950/20 p-3 shadow-inner md:gap-2",children:[t.map((a,l)=>e.jsx(I,{code:a,index:l,size:"lg",interactive:!0,removable:!0,onClick:()=>s(l)},`${a}-${l}`)),n>0&&Array.from({length:n}).map((a,l)=>e.jsx(I,{size:"lg",placeholder:!0},`empty-${l}`))]})]})}function ie({code:t}){return e.jsx(I,{code:t,size:"sm"})}function Xe({meld:t,index:s}){return e.jsxs("div",{className:"flex items-center gap-2 rounded-xl bg-slate-950/35 p-2 ring-1 ring-slate-800/70 md:gap-3",children:[e.jsxs("span",{className:"w-14 shrink-0 text-[10px] font-semibold uppercase tracking-wider text-slate-500 md:w-16 md:text-xs",children:[t.type==="pong"?"Pong":"Chow"," ",s+1]}),e.jsx("div",{className:"flex gap-1 md:gap-1.5",children:t.tiles.map((n,a)=>e.jsx(ie,{code:n},`${n}-${a}`))})]})}function Ke({result:t}){return t?t.isWin?e.jsxs("div",{className:"rounded-2xl border border-emerald-500/30 bg-[radial-gradient(circle_at_top_left,rgba(16,185,129,0.18),transparent_36%),rgba(16,185,129,0.05)] p-4 shadow-xl shadow-emerald-950/20 backdrop-blur-sm md:p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3 md:mb-4",children:[e.jsx("span",{className:"text-lg md:text-2xl",children:"🀄"}),e.jsx("h3",{className:"text-sm md:text-base font-bold text-emerald-300",children:"Winning Hand!"})]}),e.jsxs("div",{className:"mb-3 flex items-center gap-2 rounded-xl bg-slate-950/35 p-2 ring-1 ring-slate-800/70 md:mb-4 md:gap-3",children:[e.jsx("span",{className:"w-14 shrink-0 text-[10px] font-semibold uppercase tracking-wider text-slate-500 md:w-16 md:text-xs",children:"Pair"}),e.jsxs("div",{className:"flex gap-1 md:gap-1.5",children:[e.jsx(ie,{code:t.pair[0]}),e.jsx(ie,{code:t.pair[1]})]})]}),e.jsx("div",{className:"space-y-2 md:space-y-3",children:t.melds.map((s,n)=>e.jsx(Xe,{meld:s,index:n},n))})]}):e.jsxs("div",{className:"rounded-xl border border-red-500/30 bg-red-500/5 p-4 md:p-5 backdrop-blur-sm",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-lg md:text-2xl",children:"❌"}),e.jsx("h3",{className:"text-sm md:text-base font-bold text-red-300",children:"Not a Winning Hand"})]}),e.jsx("p",{className:"mt-2 text-xs md:text-sm text-slate-400",children:"Hand is not a valid winning combination. A winning hand needs 4 melds (pongs or chows) and 1 pair."})]}):null}const Qe=[{label:"Slow",value:800},{label:"Med",value:400},{label:"Fast",value:150}];function et({handIsFull:t,result:s,showAnimation:n,steps:a,stepIndex:l,stepsTotal:r,isAnimating:m,animSpeed:k,currentStep:p,lastError:T,onCheckHand:i,onResetHand:o,onRandomHand:x,onWinningHand:u,onToggleAnimation:g,onStepForward:b,onStepBack:w,onAutoPlay:$,onSetAnimSpeed:N,soundEnabled:f,onToggleSound:C}){return e.jsxs("div",{className:"flex flex-col gap-4 w-full md:w-80 shrink-0 overflow-y-auto max-h-full pr-1",children:[e.jsxs("div",{className:"rounded-xl border border-slate-700/50 bg-slate-900/60 p-4 md:p-5 backdrop-blur-sm",children:[e.jsx("h3",{className:"text-sm md:text-base font-bold text-indigo-300 mb-1",children:J.title}),e.jsx("p",{className:"text-[10px] md:text-xs text-slate-500 italic mb-2",children:J.subtitle}),e.jsx("p",{className:"text-xs md:text-sm text-slate-400 leading-relaxed",children:J.what}),e.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:J.skills.map(h=>e.jsx("span",{className:"inline-flex items-center rounded-full bg-violet-500/10 px-2 py-0.5 text-[10px] md:text-xs font-medium text-violet-400 ring-1 ring-violet-500/20",children:h},h))})]}),e.jsxs("div",{className:"rounded-xl border border-slate-700/50 bg-slate-900/60 p-4 md:p-5 backdrop-blur-sm",children:[e.jsx("h3",{className:"text-xs md:text-sm font-semibold uppercase tracking-wider text-slate-400 mb-3",children:"Actions"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 md:gap-2.5 mb-3",children:[e.jsxs("button",{onClick:x,className:"flex items-center justify-center gap-1.5 rounded-lg bg-slate-800/60 px-3 py-2.5 text-xs md:text-sm font-medium text-slate-400 transition-all hover:bg-slate-700/60 hover:text-slate-300",children:[e.jsx(Te,{size:14})," Random"]}),e.jsxs("button",{onClick:u,className:"flex items-center justify-center gap-1.5 rounded-lg bg-slate-800/60 px-3 py-2.5 text-xs md:text-sm font-medium text-slate-400 transition-all hover:bg-slate-700/60 hover:text-slate-300",children:[e.jsx(Ce,{size:14})," Winning"]}),e.jsxs("button",{onClick:o,className:"flex items-center justify-center gap-1.5 rounded-lg bg-slate-800/60 px-3 py-2.5 text-xs md:text-sm font-medium text-slate-400 transition-all hover:bg-slate-700/60 hover:text-slate-300",children:[e.jsx(K,{size:14})," Reset"]}),e.jsxs("button",{onClick:i,disabled:!t,className:`flex items-center justify-center gap-1.5 rounded-lg px-3 py-2.5 text-xs md:text-sm font-medium transition-all ${t?"bg-indigo-500/20 text-indigo-300 ring-1 ring-indigo-500/40 hover:bg-indigo-500/30":"bg-slate-800/40 text-slate-600 cursor-not-allowed"}`,children:[e.jsx(ve,{size:14})," Check"]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 md:gap-2.5",children:[e.jsxs("button",{onClick:()=>C(!f),className:`flex items-center justify-center gap-1.5 rounded-lg px-3 py-2.5 text-xs md:text-sm font-medium transition-all ${f?"bg-indigo-500/15 text-indigo-300 ring-1 ring-indigo-500/30":"bg-slate-800/60 text-slate-400 hover:bg-slate-700/60 hover:text-slate-300"}`,children:[f?e.jsx(Q,{size:14}):e.jsx(ee,{size:14})," Sound"]}),e.jsxs("button",{onClick:g,className:`flex items-center justify-center gap-1.5 rounded-lg px-3 py-2.5 text-xs md:text-sm font-medium transition-all ${n?"bg-amber-500/15 text-amber-300 ring-1 ring-amber-500/30":"bg-slate-800/60 text-slate-400 hover:bg-slate-700/60 hover:text-slate-300"}`,children:[n?e.jsx(ke,{size:14}):e.jsx(Se,{size:14}),n?"Anim On":"Anim Off"]})]})]}),n&&a.length>0&&e.jsxs("div",{className:"rounded-xl border border-slate-700/50 bg-slate-900/60 p-4 md:p-5 backdrop-blur-sm",children:[e.jsx("h3",{className:"text-xs md:text-sm font-semibold uppercase tracking-wider text-slate-400 mb-3",children:"Solver Steps"}),e.jsxs("div",{className:"flex gap-2 mb-3",children:[e.jsxs("button",{onClick:w,disabled:l<=-1,className:"flex-1 flex items-center justify-center gap-1 rounded-lg bg-slate-800/60 px-2 py-2.5 text-xs md:text-sm font-medium text-slate-400 hover:bg-slate-700/60 hover:text-slate-300 disabled:opacity-30 disabled:cursor-not-allowed",children:[e.jsx($e,{size:14})," Prev"]}),e.jsx("button",{onClick:$,className:`flex-1 flex items-center justify-center gap-1 rounded-lg px-2 py-2.5 text-xs md:text-sm font-medium transition-all ${m?"bg-amber-500/20 text-amber-300 ring-1 ring-amber-500/30":"bg-indigo-500/20 text-indigo-300 ring-1 ring-indigo-500/30 hover:bg-indigo-500/30"}`,children:m?e.jsxs(e.Fragment,{children:[e.jsx(Pe,{size:14})," Pause"]}):e.jsxs(e.Fragment,{children:[e.jsx(_e,{size:14})," Play"]})}),e.jsxs("button",{onClick:b,disabled:l>=r-1,className:"flex-1 flex items-center justify-center gap-1 rounded-lg bg-slate-800/60 px-2 py-2.5 text-xs md:text-sm font-medium text-slate-400 hover:bg-slate-700/60 hover:text-slate-300 disabled:opacity-30 disabled:cursor-not-allowed",children:["Next ",e.jsx(We,{size:14})]})]}),e.jsx("div",{className:"flex gap-1 mb-2",children:Qe.map(h=>e.jsx("button",{onClick:()=>N(h.value),className:`flex-1 rounded-md px-2 py-1.5 text-[10px] md:text-xs font-medium transition-all ${k===h.value?"bg-indigo-500/20 text-indigo-300 ring-1 ring-indigo-500/30":"bg-slate-800/50 text-slate-500 hover:text-slate-400"}`,children:h.label},h.value))}),r>0&&e.jsxs("div",{className:"flex items-center justify-between text-[10px] md:text-xs text-slate-500",children:[e.jsx("span",{children:"Step"}),e.jsxs("span",{className:"font-mono font-semibold text-indigo-300",children:[Math.max(0,l+1)," / ",r]})]})]}),n&&p&&e.jsxs("div",{className:`rounded-xl border p-4 md:p-5 backdrop-blur-sm ${p.action.type==="found_win"?"border-emerald-500/30 bg-emerald-500/5":p.action.type==="backtrack"||p.action.type==="pair_failed"?"border-amber-500/30 bg-amber-500/5":p.action.type==="no_win"?"border-red-500/30 bg-red-500/5":"border-slate-700/50 bg-slate-900/60"}`,children:[e.jsx("h3",{className:"text-xs md:text-sm font-semibold uppercase tracking-wider text-slate-400 mb-2",children:"Current Step"}),e.jsx("p",{className:"text-xs md:text-sm text-slate-300 leading-relaxed",children:p.description})]}),s&&!n&&e.jsx("div",{className:`rounded-xl border p-4 md:p-5 backdrop-blur-sm ${s.isWin?"border-emerald-500/30 bg-emerald-500/5":"border-red-500/30 bg-red-500/5"}`,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Y,{size:16,className:s.isWin?"text-emerald-400":"text-red-400"}),e.jsx("span",{className:`text-sm md:text-base font-bold ${s.isWin?"text-emerald-300":"text-red-300"}`,children:s.isWin?"Winning Hand!":"Not a Winner"})]})}),T&&e.jsx("div",{className:"rounded-lg border border-red-500/30 bg-red-500/5 px-3 py-2.5 text-center text-xs md:text-sm font-medium text-red-400 animate-pulse",children:T})]})}const oe=B.flatMap(t=>O.map(s=>`${t}${s}`));function fe(t){return{suit:t[0],value:Number(t[1])}}function tt(t){const s={};for(const n of t)s[n]=(s[n]??0)+1;return s}const me={B:0,C:1,D:2};function L(t){return[...t].sort((s,n)=>{const a=me[s[0]],l=me[n[0]];return a!==l?a-l:Number(s[1])-Number(n[1])})}function st(t){if(t.length===0)return"Hand is empty. Add 14 tiles.";if(t.lengthP)return`Hand has ${t.length} tiles. Maximum is ${P}.`;const s=tt(t);for(const[n,a]of Object.entries(s))if(a>E)return`Too many copies of ${n} (${a}). Maximum is ${E}.`;return null}function be(t,s){return t.length>=P?`Hand is full (${P} tiles).`:t.filter(a=>a===s).length>=E?`Already have ${E} copies of ${s}.`:null}function D(){const t={},s=[];for(;s.length
(s[r]??0)>=E?!1:(t.push(r),s[r]=(s[r]??0)+1,!0);for(let r=0;r<4;r++){const m=B[Math.floor(Math.random()*B.length)];if(Math.random()<.4){const i=O[Math.floor(Math.random()*O.length)],o=`${m}${i}`;if((s[o]??0)+3<=E){n(o),n(o),n(o);continue}}let p=!1;const T=[...O.filter(i=>i<=7)].sort(()=>Math.random()-.5);for(const i of T){const o=`${m}${i}`,x=`${m}${i+1}`,u=`${m}${i+2}`;if((s[o]??0)Math.random()-.5);for(const r of l)if((s[r]??0)+2<=E){n(r),n(r),a=!0;break}return!a||t.length!==P?L(["B1","B2","B3","C4","C5","C6","D7","D7","D7","B8","B8","B8","C1","C1"]):L(t)}function je(t){const s={B:{},C:{},D:{}};for(const n of t){const{suit:a,value:l}=fe(n);s[a][l]=(s[a][l]??0)+1}return s}function ye(t){const s={B:{},C:{},D:{}};for(const n of B)for(const[a,l]of Object.entries(t[n]))s[n][Number(a)]=l;return s}function F(t){const s={};for(const n of B)for(const[a,l]of Object.entries(t[n]))l>0&&(s[`${n}${a}`]=l);return s}function nt(t){let s=0;for(const n of B)for(const a of Object.values(t[n]))s+=a;return s}function X(t,s,n,a){if(s===0)return nt(t)===0;for(const l of B)for(let r=1;r<=9;r++)if(!((t[l][r]??0)<=0)){if(t[l][r]>=3){const m=[`${l}${r}`,`${l}${r}`,`${l}${r}`];if(t[l][r]-=3,a&&a.push({action:{type:"try_meld",meldType:"pong",tiles:m,success:!0},description:`Try Pong: ${m.join(" ")}`,remaining:F(t)}),n.push({type:"pong",tiles:m}),X(t,s-1,n,a))return!0;n.pop(),t[l][r]+=3,a&&a.push({action:{type:"backtrack",tiles:m},description:`Backtrack: undo Pong ${m.join(" ")}`,remaining:F(t)})}if(r<=7&&(t[l][r]??0)>=1&&(t[l][r+1]??0)>=1&&(t[l][r+2]??0)>=1){const m=[`${l}${r}`,`${l}${r+1}`,`${l}${r+2}`];if(t[l][r]-=1,t[l][r+1]-=1,t[l][r+2]-=1,a&&a.push({action:{type:"try_meld",meldType:"chow",tiles:m,success:!0},description:`Try Chow: ${m.join(" ")}`,remaining:F(t)}),n.push({type:"chow",tiles:m}),X(t,s-1,n,a))return!0;n.pop(),t[l][r]+=1,t[l][r+1]+=1,t[l][r+2]+=1,a&&a.push({action:{type:"backtrack",tiles:m},description:`Backtrack: undo Chow ${m.join(" ")}`,remaining:F(t)})}return!1}return s===0}function G(t){const s=je(t),n=[];for(const a of B)for(let l=1;l<=9;l++)(s[a][l]??0)>=2&&n.push({suit:a,value:l});for(const{suit:a,value:l}of n){const r=ye(s);r[a][l]-=2;const m=[];if(X(r,4,m,null)){const k=`${a}${l}`;return{isWin:!0,pair:[k,k],melds:m}}}return{isWin:!1}}function at(t){const s=je(t),n=[],a=[];for(const l of B)for(let r=1;r<=9;r++)(s[l][r]??0)>=2&&a.push({suit:l,value:r});for(const{suit:l,value:r}of a){const m=`${l}${r}`;n.push({action:{type:"select_pair",pair:m},description:`Try pair: ${m} ${m}`,remaining:F(s)});const k=ye(s);k[l][r]-=2;const p=[];if(X(k,4,p,n)){const T={type:"found_win",pair:[m,m],melds:p.map(i=>({...i,tiles:[...i.tiles]}))};return n.push({action:T,description:`WIN! Pair: ${m} ${m} | Melds: ${p.map(i=>i.tiles.join(" ")).join(" | ")}`,remaining:{}}),{result:{isWin:!0,pair:[m,m],melds:p},steps:n}}n.push({action:{type:"pair_failed",pair:m},description:`Pair ${m} ${m} failed — no valid 4 melds found`,remaining:F(s)})}return n.push({action:{type:"no_win"},description:"No valid winning combination found.",remaining:F(s)}),{result:{isWin:!1},steps:n}}const lt=[261.63,293.66,329.63,392,440,493.88,523.25,587.33,659.25];function te(){const t=c.useRef(!0),s=c.useCallback(()=>Me(),[]),n=c.useCallback(i=>{t.current=i},[]),a=c.useCallback(i=>{if(!t.current)return;const o=s();if(!o)return;const x=lt[Math.max(0,Math.min(i-1,8))],u=o.createOscillator(),g=o.createGain();u.type="sine",u.frequency.setValueAtTime(x,o.currentTime),g.gain.setValueAtTime(.1,o.currentTime),g.gain.exponentialRampToValueAtTime(.001,o.currentTime+.2),u.connect(g),g.connect(o.destination),u.start(),u.stop(o.currentTime+.2);const b=o.createOscillator(),w=o.createGain();b.type="triangle",b.frequency.setValueAtTime(x*2,o.currentTime),w.gain.setValueAtTime(.03,o.currentTime),w.gain.exponentialRampToValueAtTime(.001,o.currentTime+.15),b.connect(w),w.connect(o.destination),b.start(o.currentTime+.02),b.stop(o.currentTime+.17)},[s]),l=c.useCallback(()=>{if(!t.current)return;const i=s();if(!i)return;const o=i.createOscillator(),x=i.createGain();o.type="sine",o.frequency.setValueAtTime(480,i.currentTime),o.frequency.setValueAtTime(320,i.currentTime+.08),x.gain.setValueAtTime(.07,i.currentTime),x.gain.exponentialRampToValueAtTime(.001,i.currentTime+.12),o.connect(x),x.connect(i.destination),o.start(),o.stop(i.currentTime+.12)},[s]),r=c.useCallback(()=>{if(!t.current)return;const i=s();if(!i)return;[523.25,587.33,659.25,783.99,880,1046.5].forEach((x,u)=>{const g=i.createOscillator(),b=i.createGain();g.type="sine",g.frequency.value=x,b.gain.setValueAtTime(.08,i.currentTime+u*.09),b.gain.exponentialRampToValueAtTime(.001,i.currentTime+u*.09+.2),g.connect(b),b.connect(i.destination),g.start(i.currentTime+u*.09),g.stop(i.currentTime+u*.09+.2)})},[s]),m=c.useCallback(()=>{if(!t.current)return;const i=s();if(!i)return;[400,340,280].forEach((x,u)=>{const g=i.createOscillator(),b=i.createGain();g.type="sine",g.frequency.value=x,b.gain.setValueAtTime(.07,i.currentTime+u*.1),b.gain.exponentialRampToValueAtTime(.001,i.currentTime+u*.1+.2),g.connect(b),b.connect(i.destination),g.start(i.currentTime+u*.1),g.stop(i.currentTime+u*.1+.2)})},[s]),k=c.useCallback(()=>{if(!t.current)return;const i=s();if(!i)return;const o=i.createOscillator(),x=i.createGain();o.type="sawtooth",o.frequency.setValueAtTime(190,i.currentTime),o.frequency.setValueAtTime(130,i.currentTime+.12),x.gain.setValueAtTime(.07,i.currentTime),x.gain.exponentialRampToValueAtTime(.001,i.currentTime+.25),o.connect(x),x.connect(i.destination),o.start(),o.stop(i.currentTime+.25)},[s]),p=c.useCallback(i=>{if(!t.current)return;const o=s();if(!o)return;const x=400+i%8*50,u=o.createOscillator(),g=o.createGain();u.type="sine",u.frequency.setValueAtTime(x,o.currentTime),g.gain.setValueAtTime(.05,o.currentTime),g.gain.exponentialRampToValueAtTime(.001,o.currentTime+.08),u.connect(g),g.connect(o.destination),u.start(),u.stop(o.currentTime+.08)},[s]),T=c.useCallback(()=>{if(!t.current)return;const i=s();if(!i)return;const o=i.createOscillator(),x=i.createGain();o.type="triangle",o.frequency.setValueAtTime(550,i.currentTime),o.frequency.setValueAtTime(350,i.currentTime+.06),x.gain.setValueAtTime(.05,i.currentTime),x.gain.exponentialRampToValueAtTime(.001,i.currentTime+.1),o.connect(x),x.connect(i.destination),o.start(),o.stop(i.currentTime+.1)},[s]);return{playTilePlaced:a,playTileRemoved:l,playWinSound:r,playLoseSound:m,playErrorSound:k,playStepTick:p,playBacktrackSound:T,setEnabled:n}}function rt(){if(Math.random()<.6){const s=ce(),n=G(s);return{hand:s,isWinning:n.isWin,solution:n.isWin?n:null}}for(let s=0;s<50;s++){const n=D();if(!G(n).isWin)return{hand:n,isWinning:!1,solution:null}}return{hand:D(),isWinning:!1,solution:null}}const ne={hand:[],isWinning:!1,solution:null,phase:"judging",playerSaidWin:null,selectedTiles:[],foundPair:null,foundMelds:[],hintsUsed:0,showHint:!1,feedback:null,roundComplete:!1};function it(){const[t,s]=c.useState(ne),[n,a]=c.useState(0),[l,r]=c.useState(0),[m,k]=c.useState(0),[p,T]=c.useState(!1),[i,o]=c.useState(!0),x=te(),u=c.useCallback(()=>{const d=rt();s({...ne,hand:d.hand,isWinning:d.isWinning,solution:d.solution}),T(!0)},[]),g=c.useCallback(d=>{const v=d===t.isWinning;v&&t.isWinning&&t.solution?(x.playTilePlaced(5),s(j=>({...j,playerSaidWin:d,phase:"grouping",feedback:"Correct! Now identify the pair and melds."}))):v&&!t.isWinning?(x.playWinSound(),a(j=>j+100-t.hintsUsed*20),r(j=>j+1),k(j=>j+1),s(j=>({...j,playerSaidWin:d,phase:"feedback",feedback:"Correct! This hand is not a winner.",roundComplete:!0}))):(x.playLoseSound(),r(j=>j+1),s(j=>({...j,playerSaidWin:d,phase:"feedback",feedback:t.isWinning?"Wrong — this hand IS a winner! Check the solution below.":"Wrong — this hand is NOT a winner.",roundComplete:!0})))},[t,x]),b=c.useCallback(d=>{s(v=>{const j=v.selectedTiles.includes(d)?v.selectedTiles.filter(y=>y!==d):[...v.selectedTiles,d];return{...v,selectedTiles:j}}),x.playTilePlaced(3)},[x]),w=c.useCallback(()=>{if(t.selectedTiles.length!==2||!t.solution)return;const d=t.selectedTiles.map(y=>t.hand[y]),v=t.solution.pair;d[0]===d[1]&&d[0]===v[0]?(x.playTilePlaced(7),s(y=>({...y,foundPair:[d[0],d[1]],selectedTiles:[],feedback:"Pair found! Now identify the 4 melds."}))):(x.playErrorSound(),s(y=>({...y,selectedTiles:[],feedback:"That's not the correct pair. Try again!"})))},[t,x]),$=c.useCallback(()=>{if(t.selectedTiles.length!==3||!t.solution)return;const d=t.selectedTiles.map(y=>t.hand[y]).sort(),v=t.solution.melds.filter((y,W)=>!t.foundMelds.some(S=>JSON.stringify(S.tiles.sort())===JSON.stringify(t.solution.melds[W].tiles.sort()))),j=v.findIndex(y=>JSON.stringify([...y.tiles].sort())===JSON.stringify(d));if(j>=0){const y=v[j];x.playTilePlaced(8);const W=[...t.foundMelds,y];W.length===4?(x.playWinSound(),a(S=>S+200-t.hintsUsed*30),r(S=>S+1),k(S=>S+1),s(S=>({...S,foundMelds:W,selectedTiles:[],phase:"feedback",feedback:"Excellent! You identified all groups correctly!",roundComplete:!0}))):s(S=>({...S,foundMelds:W,selectedTiles:[],feedback:`Meld ${W.length}/4 found! Keep going.`}))}else x.playErrorSound(),s(y=>({...y,selectedTiles:[],feedback:"Those 3 tiles don't form a valid meld in the solution. Try again!"}))},[t,x]),N=c.useCallback(()=>{t.solution&&(x.playBacktrackSound(),s(d=>({...d,hintsUsed:d.hintsUsed+1,showHint:!0})),setTimeout(()=>{s(d=>({...d,showHint:!1}))},3e3))},[t.solution,x]),f=c.useCallback(()=>{r(d=>d+1),s(d=>({...d,phase:"feedback",feedback:"Skipped grouping. Here's the solution:",roundComplete:!0}))},[]),C=c.useCallback(()=>{s(ne),a(0),r(0),k(0),T(!1)},[]),h=c.useCallback(d=>{o(d),x.setEnabled(d)},[x]);return{round:t,score:n,totalRounds:l,correctRounds:m,started:p,soundEnabled:i,startNewRound:u,judgeHand:g,toggleTileSelection:b,submitPair:w,submitMeld:$,useHint:N,skipGrouping:f,resetGame:C,toggleSound:h}}function q({code:t,index:s,selected:n,onClick:a}){return e.jsx(I,{code:t,index:s,size:"lg",selected:n,interactive:!!a,disabled:!a,onClick:a})}function ot(){const{round:t,score:s,totalRounds:n,correctRounds:a,started:l,soundEnabled:r,startNewRound:m,judgeHand:k,toggleTileSelection:p,submitPair:T,submitMeld:i,useHint:o,skipGrouping:x,resetGame:u,toggleSound:g}=it();if(!l)return e.jsx("div",{className:"flex flex-1 items-center justify-center p-6",children:e.jsxs("div",{className:"max-w-md text-center",children:[e.jsx("div",{className:"text-4xl mb-4",children:"📖"}),e.jsx("h2",{className:"text-xl md:text-2xl font-bold text-white mb-2",children:"Guided Mode"}),e.jsxs("p",{className:"text-sm md:text-base text-slate-400 mb-6 leading-relaxed",children:["Practice identifying winning Mahjong hands step-by-step. First judge if the hand is a winner, then identify the ",e.jsx("span",{className:"text-indigo-300 font-semibold",children:"pair"})," and ",e.jsx("span",{className:"text-violet-300 font-semibold",children:"4 melds"})," by selecting tiles. Use hints if you get stuck!"]}),e.jsx("button",{onClick:m,className:"rounded-xl bg-gradient-to-r from-indigo-500 to-violet-500 px-8 py-3 text-sm md:text-base font-bold text-white shadow-lg shadow-indigo-500/25 transition-all hover:shadow-indigo-500/40 hover:scale-105 active:scale-95",children:"Start Learning"})]})});const{hand:b,phase:w,selectedTiles:$,foundPair:N,foundMelds:f,feedback:C,showHint:h,solution:d,roundComplete:v,hintsUsed:j}=t,y=d&&h?N?`Hint: Next meld is ${d.melds[f.length]?.tiles.join(" ")??"done!"}`:`Hint: The pair is ${d.pair[0]} ${d.pair[1]}`:null,W=new Set;if(N){let S=0;for(let M=0;M=0&&(W.add(z),M.splice(H,1))}}return e.jsxs("div",{className:"flex flex-1 flex-col md:flex-row gap-4 md:gap-6 overflow-auto p-4 md:p-6",children:[e.jsxs("div",{className:"flex flex-col gap-4 w-full md:w-80 shrink-0 overflow-y-auto max-h-full pr-1",children:[e.jsxs("div",{className:"rounded-xl border border-slate-700/50 bg-slate-900/60 p-4 md:p-5 backdrop-blur-sm",children:[e.jsx("h3",{className:"text-xs md:text-sm font-semibold uppercase tracking-wider text-slate-400 mb-3",children:"Progress"}),e.jsxs("div",{className:"grid grid-cols-3 gap-3 text-center",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-lg md:text-xl font-bold text-indigo-300",children:s}),e.jsx("p",{className:"text-[10px] md:text-xs text-slate-500",children:"Score"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-lg md:text-xl font-bold text-emerald-300",children:a}),e.jsx("p",{className:"text-[10px] md:text-xs text-slate-500",children:"Correct"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-lg md:text-xl font-bold text-slate-300",children:n}),e.jsx("p",{className:"text-[10px] md:text-xs text-slate-500",children:"Rounds"})]})]})]}),w==="judging"&&e.jsxs("div",{className:"rounded-xl border border-slate-700/50 bg-slate-900/60 p-4 md:p-5 backdrop-blur-sm",children:[e.jsx("h3",{className:"text-xs md:text-sm font-semibold uppercase tracking-wider text-slate-400 mb-2",children:"Step 1: Judge"}),e.jsx("p",{className:"text-xs md:text-sm text-slate-400 mb-4",children:"Is this a valid winning hand?"}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("button",{onClick:()=>k(!0),className:"flex items-center justify-center gap-2 rounded-xl bg-emerald-500/15 px-4 py-3 text-sm md:text-base font-bold text-emerald-300 ring-1 ring-emerald-500/30 transition-all hover:bg-emerald-500/25 hover:scale-105 active:scale-95",children:[e.jsx(V,{size:16})," Win"]}),e.jsxs("button",{onClick:()=>k(!1),className:"flex items-center justify-center gap-2 rounded-xl bg-red-500/15 px-4 py-3 text-sm md:text-base font-bold text-red-300 ring-1 ring-red-500/30 transition-all hover:bg-red-500/25 hover:scale-105 active:scale-95",children:[e.jsx(re,{size:16})," Not Win"]})]})]}),w==="grouping"&&e.jsxs("div",{className:"rounded-xl border border-indigo-500/30 bg-indigo-500/5 p-4 md:p-5 backdrop-blur-sm",children:[e.jsxs("h3",{className:"text-xs md:text-sm font-semibold uppercase tracking-wider text-indigo-300 mb-2",children:["Step 2: ",N?`Find Meld ${f.length+1}/4`:"Find the Pair"]}),e.jsx("p",{className:"text-xs md:text-sm text-slate-400 mb-3",children:N?"Select 3 tiles that form a pong (AAA) or chow (ABC).":"Select 2 identical tiles that form the pair."}),e.jsxs("p",{className:"text-xs md:text-sm text-indigo-300 font-mono mb-3",children:["Selected: ",$.length," / ",N?3:2]}),e.jsx("div",{className:"flex gap-2 mb-3",children:N?e.jsxs("button",{onClick:i,disabled:$.length!==3,className:"flex-1 flex items-center justify-center gap-1.5 rounded-lg bg-indigo-500/20 px-3 py-2.5 text-xs md:text-sm font-medium text-indigo-300 ring-1 ring-indigo-500/30 transition-all hover:bg-indigo-500/30 disabled:opacity-30 disabled:cursor-not-allowed",children:[e.jsx(V,{size:14})," Submit Meld"]}):e.jsxs("button",{onClick:T,disabled:$.length!==2,className:"flex-1 flex items-center justify-center gap-1.5 rounded-lg bg-indigo-500/20 px-3 py-2.5 text-xs md:text-sm font-medium text-indigo-300 ring-1 ring-indigo-500/30 transition-all hover:bg-indigo-500/30 disabled:opacity-30 disabled:cursor-not-allowed",children:[e.jsx(V,{size:14})," Submit Pair"]})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{onClick:o,className:"flex-1 flex items-center justify-center gap-1.5 rounded-lg bg-amber-500/15 px-3 py-2 text-xs md:text-sm font-medium text-amber-300 ring-1 ring-amber-500/30 transition-all hover:bg-amber-500/25",children:[e.jsx(Ae,{size:14})," Hint (",j,")"]}),e.jsxs("button",{onClick:x,className:"flex-1 flex items-center justify-center gap-1.5 rounded-lg bg-slate-800/60 px-3 py-2 text-xs md:text-sm font-medium text-slate-400 transition-all hover:bg-slate-700/60",children:[e.jsx(ze,{size:14})," Skip"]})]})]}),C&&e.jsxs("div",{className:`rounded-xl border p-4 md:p-5 backdrop-blur-sm ${w==="feedback"&&v?t.playerSaidWin===t.isWinning?"border-emerald-500/30 bg-emerald-500/5":"border-red-500/30 bg-red-500/5":"border-indigo-500/30 bg-indigo-500/5"}`,children:[e.jsx("p",{className:"text-xs md:text-sm text-slate-300 leading-relaxed",children:C}),y&&e.jsx("p",{className:"mt-2 text-xs md:text-sm text-amber-300 font-mono animate-pulse",children:y}),v&&d&&e.jsxs("div",{className:"mt-3 text-[10px] md:text-xs text-slate-500",children:[e.jsxs("p",{children:["Solution: Pair ",d.pair.join(" ")]}),d.melds.map((S,M)=>e.jsxs("p",{children:[S.type==="pong"?"Pong":"Chow",": ",S.tiles.join(" ")]},M))]}),v&&e.jsxs("button",{onClick:m,className:"mt-3 w-full flex items-center justify-center gap-2 rounded-lg bg-indigo-500/20 px-4 py-2.5 text-xs md:text-sm font-medium text-indigo-300 ring-1 ring-indigo-500/30 transition-all hover:bg-indigo-500/30",children:["Next Round ",e.jsx(de,{size:14})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{onClick:u,className:"flex-1 flex items-center justify-center gap-1.5 rounded-lg bg-slate-800/60 px-3 py-2.5 text-xs md:text-sm font-medium text-slate-400 transition-all hover:bg-slate-700/60 hover:text-slate-300",children:[e.jsx(K,{size:14})," Reset"]}),e.jsx("button",{onClick:()=>g(!r),className:`flex items-center justify-center gap-1.5 rounded-lg px-3 py-2.5 text-xs md:text-sm font-medium transition-all ${r?"bg-indigo-500/15 text-indigo-300 ring-1 ring-indigo-500/30":"bg-slate-800/60 text-slate-400"}`,children:r?e.jsx(Q,{size:14}):e.jsx(ee,{size:14})})]})]}),e.jsxs("div",{className:"order-last md:order-first flex md:flex-1 flex-col gap-4 min-h-0 md:overflow-auto",children:[e.jsxs("div",{className:"rounded-2xl border border-emerald-900/40 bg-[radial-gradient(circle_at_top_left,rgba(16,185,129,0.14),transparent_34%),linear-gradient(135deg,rgba(15,23,42,0.96),rgba(6,78,59,0.32))] p-4 shadow-2xl shadow-black/30 md:p-5",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3 md:mb-4",children:[e.jsx("h3",{className:"text-xs md:text-sm font-semibold uppercase tracking-wider text-emerald-200",children:"Hand"}),N&&e.jsxs("span",{className:"text-xs md:text-sm font-mono text-emerald-300",children:["Pair ✓ | Melds ",f.length,"/4"]})]}),e.jsx("div",{className:"flex flex-wrap items-end gap-1.5 rounded-xl border border-emerald-950/40 bg-emerald-950/20 p-3 shadow-inner md:gap-2",children:b.map((S,M)=>{const z=W.has(M),H=$.includes(M),se=w==="grouping"&&!z;return e.jsx("div",{className:z?"opacity-30":"",children:e.jsx(q,{code:S,index:M,selected:H,onClick:se?()=>p(M):void 0})},`${S}-${M}`)})})]}),(N||f.length>0)&&e.jsxs("div",{className:"rounded-2xl border border-emerald-500/20 bg-emerald-500/5 p-4 shadow-xl shadow-emerald-950/20 backdrop-blur-sm md:p-5",children:[e.jsx("h3",{className:"text-xs md:text-sm font-semibold uppercase tracking-wider text-emerald-400 mb-3",children:"Found Groups"}),N&&e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("span",{className:"text-[10px] md:text-xs font-medium text-slate-600 w-14 shrink-0",children:"Pair"}),e.jsxs("div",{className:"flex gap-1",children:[e.jsx(q,{code:N[0],index:-1,selected:!1}),e.jsx(q,{code:N[1],index:-1,selected:!1})]})]}),f.map((S,M)=>e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsxs("span",{className:"text-[10px] md:text-xs font-medium text-slate-600 w-14 shrink-0",children:[S.type==="pong"?"Pong":"Chow"," ",M+1]}),e.jsx("div",{className:"flex gap-1",children:S.tiles.map((z,H)=>e.jsx(q,{code:z,index:-1,selected:!1},`${z}-${H}`))})]},M))]})]})]})}function ue(){if(Math.random()<.5){const s=ce(),n=G(s);return{hand:s,isWinning:n.isWin,solution:n.isWin?n:null}}for(let s=0;s<50;s++){const n=D();if(!G(n).isWin)return{hand:n,isWinning:!1,solution:null}}return{hand:D(),isWinning:!1,solution:null}}const ae={hand:[],isWinning:!1,solution:null,round:0,score:0,streak:0,bestStreak:0,timer:0,answered:!1,lastCorrect:null,totalCorrect:0,totalAnswered:0};function dt(){const[t,s]=c.useState(ae),[n,a]=c.useState(!1),l=c.useRef(null),r=te(),[m,k]=c.useState(!0);c.useEffect(()=>(n&&!t.answered&&(l.current=setInterval(()=>{s(u=>({...u,timer:u.timer+1}))},1e3)),()=>{l.current&&clearInterval(l.current)}),[n,t.answered]);const p=c.useCallback(()=>{const{hand:u,isWinning:g,solution:b}=ue();s({...ae,hand:u,isWinning:g,solution:b,round:1}),a(!0)},[]),T=c.useCallback(()=>{const{hand:u,isWinning:g,solution:b}=ue();s(w=>({...w,hand:u,isWinning:g,solution:b,round:w.round+1,timer:0,answered:!1,lastCorrect:null}))},[]),i=c.useCallback(u=>{if(t.answered)return;const g=u===t.isWinning,b=Math.max(0,10-t.timer),w=g?100+b*10+t.streak*25:0;g?r.playWinSound():r.playLoseSound(),s($=>({...$,answered:!0,lastCorrect:g,score:$.score+w,streak:g?$.streak+1:0,bestStreak:g?Math.max($.bestStreak,$.streak+1):$.bestStreak,totalCorrect:$.totalCorrect+(g?1:0),totalAnswered:$.totalAnswered+1}))},[t.answered,t.isWinning,t.timer,t.streak,r]),o=c.useCallback(()=>{s(ae),a(!1),l.current&&clearInterval(l.current)},[]),x=c.useCallback(u=>{k(u),r.setEnabled(u)},[r]);return{...t,isRunning:n,soundEnabled:m,startGame:p,nextRound:T,answer:i,resetGame:o,toggleSound:x}}function ct({code:t}){return e.jsx(I,{code:t,size:"lg"})}function xt(){const{hand:t,isWinning:s,solution:n,round:a,score:l,streak:r,bestStreak:m,timer:k,answered:p,lastCorrect:T,totalCorrect:i,totalAnswered:o,isRunning:x,soundEnabled:u,startGame:g,nextRound:b,answer:w,resetGame:$,toggleSound:N}=dt();return x?e.jsxs("div",{className:"flex flex-1 flex-col md:flex-row gap-4 md:gap-6 overflow-auto p-4 md:p-6",children:[e.jsxs("div",{className:"flex flex-col gap-4 w-full md:w-80 shrink-0 overflow-y-auto max-h-full pr-1",children:[e.jsxs("div",{className:"rounded-xl border border-slate-700/50 bg-slate-900/60 p-4 md:p-5 backdrop-blur-sm",children:[e.jsx("h3",{className:"text-xs md:text-sm font-semibold uppercase tracking-wider text-slate-400 mb-3",children:"Stats"}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Y,{size:14,className:"text-amber-400"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-lg md:text-xl font-bold text-white",children:l}),e.jsx("p",{className:"text-[10px] md:text-xs text-slate-500",children:"Score"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Re,{size:14,className:"text-orange-400"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-lg md:text-xl font-bold text-orange-300",children:r}),e.jsx("p",{className:"text-[10px] md:text-xs text-slate-500",children:"Streak"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(He,{size:14,className:"text-cyan-400"}),e.jsxs("div",{children:[e.jsxs("p",{className:"text-lg md:text-xl font-bold text-cyan-300",children:[k,"s"]}),e.jsx("p",{className:"text-[10px] md:text-xs text-slate-500",children:"Time"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(V,{size:14,className:"text-emerald-400"}),e.jsxs("div",{children:[e.jsxs("p",{className:"text-lg md:text-xl font-bold text-emerald-300",children:[i,"/",o]}),e.jsx("p",{className:"text-[10px] md:text-xs text-slate-500",children:"Correct"})]})]})]}),e.jsxs("div",{className:"mt-3 flex items-center justify-between text-[10px] md:text-xs text-slate-500",children:[e.jsxs("span",{children:["Round ",a]}),e.jsxs("span",{children:["Best streak: ",m]})]})]}),!p&&e.jsxs("div",{className:"rounded-xl border border-slate-700/50 bg-slate-900/60 p-4 md:p-5 backdrop-blur-sm",children:[e.jsx("h3",{className:"text-xs md:text-sm font-semibold uppercase tracking-wider text-slate-400 mb-3",children:"Your Judgment"}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("button",{onClick:()=>w(!0),className:"flex items-center justify-center gap-2 rounded-xl bg-emerald-500/15 px-4 py-4 text-sm md:text-base font-bold text-emerald-300 ring-1 ring-emerald-500/30 transition-all hover:bg-emerald-500/25 hover:scale-105 active:scale-95",children:[e.jsx(V,{size:18})," Win"]}),e.jsxs("button",{onClick:()=>w(!1),className:"flex items-center justify-center gap-2 rounded-xl bg-red-500/15 px-4 py-4 text-sm md:text-base font-bold text-red-300 ring-1 ring-red-500/30 transition-all hover:bg-red-500/25 hover:scale-105 active:scale-95",children:[e.jsx(re,{size:18})," Not Win"]})]})]}),p&&e.jsxs("div",{className:`rounded-xl border p-4 md:p-5 backdrop-blur-sm ${T?"border-emerald-500/30 bg-emerald-500/5":"border-red-500/30 bg-red-500/5"}`,children:[e.jsx("div",{className:"flex items-center gap-2 mb-2",children:T?e.jsxs(e.Fragment,{children:[e.jsx(V,{size:18,className:"text-emerald-400"}),e.jsx("span",{className:"text-sm md:text-base font-bold text-emerald-300",children:"Correct!"})]}):e.jsxs(e.Fragment,{children:[e.jsx(re,{size:18,className:"text-red-400"}),e.jsx("span",{className:"text-sm md:text-base font-bold text-red-300",children:"Wrong!"})]})}),e.jsxs("p",{className:"text-xs md:text-sm text-slate-400 mb-3",children:["The hand was ",e.jsx("span",{className:`font-bold ${s?"text-emerald-300":"text-red-300"}`,children:s?"a Winner":"Not a Winner"}),"."]}),s&&n&&e.jsxs("div",{className:"text-[10px] md:text-xs text-slate-500 mb-3",children:["Pair: ",n.pair.join(" ")," | Melds: ",n.melds.map(f=>f.tiles.join(" ")).join(" | ")]}),e.jsxs("button",{onClick:b,className:"w-full flex items-center justify-center gap-2 rounded-lg bg-indigo-500/20 px-4 py-2.5 text-xs md:text-sm font-medium text-indigo-300 ring-1 ring-indigo-500/30 transition-all hover:bg-indigo-500/30",children:["Next Round ",e.jsx(de,{size:14})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{onClick:$,className:"flex-1 flex items-center justify-center gap-1.5 rounded-lg bg-slate-800/60 px-3 py-2.5 text-xs md:text-sm font-medium text-slate-400 transition-all hover:bg-slate-700/60 hover:text-slate-300",children:[e.jsx(K,{size:14})," Reset"]}),e.jsx("button",{onClick:()=>N(!u),className:`flex items-center justify-center gap-1.5 rounded-lg px-3 py-2.5 text-xs md:text-sm font-medium transition-all ${u?"bg-indigo-500/15 text-indigo-300 ring-1 ring-indigo-500/30":"bg-slate-800/60 text-slate-400"}`,children:u?e.jsx(Q,{size:14}):e.jsx(ee,{size:14})})]})]}),e.jsx("div",{className:"order-last md:order-first flex md:flex-1 flex-col gap-4 min-h-0 md:overflow-auto",children:e.jsxs("div",{className:"rounded-2xl border border-emerald-900/40 bg-[radial-gradient(circle_at_top_left,rgba(16,185,129,0.14),transparent_34%),linear-gradient(135deg,rgba(15,23,42,0.96),rgba(6,78,59,0.32))] p-4 shadow-2xl shadow-black/30 md:p-5",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3 md:mb-4",children:[e.jsx("h3",{className:"text-xs md:text-sm font-semibold uppercase tracking-wider text-emerald-200",children:"Hand to Judge"}),e.jsxs("span",{className:"text-xs md:text-sm font-mono font-bold text-indigo-300",children:["Round ",a]})]}),e.jsx("div",{className:"flex flex-wrap items-end gap-1.5 rounded-xl border border-emerald-950/40 bg-emerald-950/20 p-3 shadow-inner md:gap-2",children:t.map((f,C)=>e.jsx(ct,{code:f},`${f}-${C}`))})]})})]}):e.jsx("div",{className:"flex flex-1 items-center justify-center p-6",children:e.jsxs("div",{className:"max-w-md text-center",children:[e.jsx("div",{className:"text-4xl mb-4",children:"⚡"}),e.jsx("h2",{className:"text-xl md:text-2xl font-bold text-white mb-2",children:"Challenge Mode"}),e.jsxs("p",{className:"text-sm md:text-base text-slate-400 mb-6 leading-relaxed",children:["You'll see a 14-tile hand. Decide as fast as you can: is it a ",e.jsx("span",{className:"text-emerald-400 font-semibold",children:"Winning Hand"})," or ",e.jsx("span",{className:"text-red-400 font-semibold",children:"Not a Winner"}),"? Score points for correct answers. Faster = more bonus points. Build streaks for multipliers!"]}),e.jsx("button",{onClick:g,className:"rounded-xl bg-gradient-to-r from-indigo-500 to-violet-500 px-8 py-3 text-sm md:text-base font-bold text-white shadow-lg shadow-indigo-500/25 transition-all hover:shadow-indigo-500/40 hover:scale-105 active:scale-95",children:"Start Challenge"})]})})}function ge(t){return{name:t,hand:[],result:null,score:0}}const le={phase:"building",players:[ge("Player 1"),ge("Player 2")],currentPlayer:0,round:1,roundComplete:!1};function mt(){const[t,s]=c.useState(le),[n,a]=c.useState(null),[l,r]=c.useState(!1),[m,k]=c.useState(!0),p=te(),T=t.players[t.currentPlayer].hand,i=T.length>=P,o=t.players[0].hand.length>=P&&t.players[1].hand.length>=P,x=c.useCallback(()=>{s({...le}),r(!0),a(null)},[]),u=c.useCallback(h=>{if(t.phase!=="building")return;const d=t.players[t.currentPlayer].hand,v=be(d,h);if(v){a(v),p.playErrorSound();return}a(null);const{value:j}={value:Number(h[1])};p.playTilePlaced(j),s(y=>{const W=[...y.players],S={...W[y.currentPlayer]};S.hand=L([...S.hand,h]),W[y.currentPlayer]=S;const M=S.hand.length>=P,z=W[1-y.currentPlayer].hand.length>=P;let H=y.currentPlayer;return M&&!z?H=1-y.currentPlayer:M||(H=1-y.currentPlayer,W[H].hand.length>=P&&(H=y.currentPlayer)),{...y,players:W,currentPlayer:H}})},[t.phase,t.currentPlayer,t.players,p]),g=c.useCallback(h=>{t.phase==="building"&&(p.playTileRemoved(),a(null),s(d=>{const v=[...d.players],j={...v[d.currentPlayer]},y=[...j.hand];return y.splice(h,1),j.hand=y,v[d.currentPlayer]=j,{...d,players:v}}))},[t.phase,p]),b=c.useCallback(()=>{if(!o)return;const h=G(t.players[0].hand),d=G(t.players[1].hand),v=h.isWin?1:0,j=d.isWin?1:0;v>j||j>v?p.playWinSound():p.playLoseSound(),s(y=>{const W=[...y.players];return W[0]={...W[0],result:h,score:W[0].score+v},W[1]={...W[1],result:d,score:W[1].score+j},{...y,players:W,phase:"results",roundComplete:!0}})},[o,t.players,p]),w=c.useCallback(()=>{s(h=>({...h,phase:"building",players:[{...h.players[0],hand:[],result:null},{...h.players[1],hand:[],result:null}],currentPlayer:0,round:h.round+1,roundComplete:!1})),a(null)},[]),$=c.useCallback(()=>{s(le),r(!1),a(null)},[]),N=c.useCallback(()=>{if(t.phase!=="building")return;const h=1-t.currentPlayer;t.players[h].hand.length>=P||s(d=>({...d,currentPlayer:h}))},[t.phase,t.currentPlayer,t.players]),f=()=>{if(t.phase!=="results")return null;const h=t.players[0].result,d=t.players[1].result;return!h||!d?null:h.isWin&&!d.isWin?t.players[0].name:!h.isWin&&d.isWin?t.players[1].name:h.isWin&&d.isWin?"Both Win!":"Neither Wins"},C=c.useCallback(h=>{k(h),p.setEnabled(h)},[p]);return{state:t,lastError:n,started:l,soundEnabled:m,currentHand:T,currentHandIsFull:i,bothFull:o,winner:f(),startGame:x,addTile:u,removeTile:g,checkBothHands:b,nextRound:w,resetGame:$,switchPlayer:N,toggleSound:C}}function ut({code:t,onRemove:s}){return e.jsx(I,{code:t,size:"md",interactive:!!s,removable:!!s,onClick:s})}function gt(t,s){return t.filter(n=>n===s).length}function pt({suit:t,value:s,count:n,disabled:a,onClick:l}){const r=n>=4,m=`${t}${s}`;return e.jsx(I,{code:m,count:n,size:"sm",disabled:a||r,interactive:!0,onClick:l})}function ht(){const{state:t,lastError:s,started:n,soundEnabled:a,currentHand:l,currentHandIsFull:r,bothFull:m,winner:k,startGame:p,addTile:T,removeTile:i,checkBothHands:o,nextRound:x,resetGame:u,switchPlayer:g,toggleSound:b}=mt();if(!n)return e.jsx("div",{className:"flex flex-1 items-center justify-center p-6",children:e.jsxs("div",{className:"max-w-md text-center",children:[e.jsx("div",{className:"text-4xl mb-4",children:"👥"}),e.jsx("h2",{className:"text-xl md:text-2xl font-bold text-white mb-2",children:"2 Player Mode"}),e.jsxs("p",{className:"text-sm md:text-base text-slate-400 mb-6 leading-relaxed",children:["Take turns placing tiles to build your 14-tile hands. Players alternate picks. Once both hands are complete, the solver checks both — whoever has a valid ",e.jsx("span",{className:"text-emerald-400 font-semibold",children:"winning hand"})," scores a point!"]}),e.jsx("button",{onClick:p,className:"rounded-xl bg-gradient-to-r from-indigo-500 to-violet-500 px-8 py-3 text-sm md:text-base font-bold text-white shadow-lg shadow-indigo-500/25 transition-all hover:shadow-indigo-500/40 hover:scale-105 active:scale-95",children:"Start Game"})]})});const{phase:w,players:$,currentPlayer:N,round:f}=t,C=$[0],h=$[1];return e.jsxs("div",{className:"flex flex-1 flex-col md:flex-row gap-4 md:gap-6 overflow-auto p-4 md:p-6",children:[e.jsxs("div",{className:"flex flex-col gap-4 w-full md:w-80 shrink-0 overflow-y-auto max-h-full pr-1",children:[e.jsxs("div",{className:"rounded-xl border border-slate-700/50 bg-slate-900/60 p-4 md:p-5 backdrop-blur-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(pe,{size:14,className:"text-indigo-400"}),e.jsxs("h3",{className:"text-xs md:text-sm font-semibold uppercase tracking-wider text-slate-400",children:["Round ",f]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:`rounded-lg p-3 text-center transition-all ${w==="building"&&N===0?"bg-indigo-500/15 ring-2 ring-indigo-400/40":"bg-slate-800/40"}`,children:[e.jsx("p",{className:"text-sm md:text-base font-bold text-indigo-300",children:C.name}),e.jsx("p",{className:"text-lg md:text-xl font-extrabold text-white",children:C.score}),e.jsxs("p",{className:"text-[10px] md:text-xs text-slate-500",children:[C.hand.length,"/",P," tiles"]}),w==="results"&&C.result&&e.jsx("p",{className:`mt-1 text-[10px] md:text-xs font-bold ${C.result.isWin?"text-emerald-400":"text-red-400"}`,children:C.result.isWin?"✓ Winner":"✗ No Win"})]}),e.jsxs("div",{className:`rounded-lg p-3 text-center transition-all ${w==="building"&&N===1?"bg-violet-500/15 ring-2 ring-violet-400/40":"bg-slate-800/40"}`,children:[e.jsx("p",{className:"text-sm md:text-base font-bold text-violet-300",children:h.name}),e.jsx("p",{className:"text-lg md:text-xl font-extrabold text-white",children:h.score}),e.jsxs("p",{className:"text-[10px] md:text-xs text-slate-500",children:[h.hand.length,"/",P," tiles"]}),w==="results"&&h.result&&e.jsx("p",{className:`mt-1 text-[10px] md:text-xs font-bold ${h.result.isWin?"text-emerald-400":"text-red-400"}`,children:h.result.isWin?"✓ Winner":"✗ No Win"})]})]})]}),w==="building"&&e.jsxs("div",{className:`rounded-xl border p-4 md:p-5 backdrop-blur-sm ${N===0?"border-indigo-500/30 bg-indigo-500/5":"border-violet-500/30 bg-violet-500/5"}`,children:[e.jsxs("p",{className:`text-sm md:text-base font-bold ${N===0?"text-indigo-300":"text-violet-300"}`,children:[$[N].name,"'s Turn"]}),e.jsx("p",{className:"text-xs md:text-sm text-slate-400 mt-1",children:"Pick a tile to add to your hand."}),!r&&e.jsxs("button",{onClick:g,className:"mt-3 w-full flex items-center justify-center gap-1.5 rounded-lg bg-slate-800/60 px-3 py-2 text-xs md:text-sm font-medium text-slate-400 transition-all hover:bg-slate-700/60 hover:text-slate-300",children:[e.jsx(Ie,{size:14})," Switch Player"]})]}),w==="building"&&m&&e.jsxs("button",{onClick:o,className:"w-full flex items-center justify-center gap-2 rounded-xl bg-gradient-to-r from-indigo-500/20 to-violet-500/20 px-4 py-3 text-sm md:text-base font-bold text-indigo-200 ring-1 ring-indigo-500/30 transition-all hover:from-indigo-500/30 hover:to-violet-500/30 active:scale-95",children:[e.jsx(Y,{size:16})," Check Both Hands"]}),w==="results"&&k&&e.jsxs("div",{className:`rounded-xl border p-4 md:p-5 backdrop-blur-sm ${k.includes("Neither")?"border-slate-700/50 bg-slate-900/60":"border-emerald-500/30 bg-emerald-500/5"}`,children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(Y,{size:18,className:"text-amber-400"}),e.jsx("span",{className:"text-base md:text-lg font-bold text-white",children:k})]}),$.map((d,v)=>d.result&&d.result.isWin&&e.jsxs("div",{className:"mt-2 text-[10px] md:text-xs text-slate-500",children:[e.jsxs("p",{className:"font-semibold text-slate-400",children:[d.name,":"]}),e.jsxs("p",{children:["Pair: ",d.result.pair.join(" ")]}),d.result.melds.map((j,y)=>e.jsxs("p",{children:[j.type==="pong"?"Pong":"Chow",": ",j.tiles.join(" ")]},y))]},v)),e.jsxs("button",{onClick:x,className:"mt-3 w-full flex items-center justify-center gap-2 rounded-lg bg-indigo-500/20 px-4 py-2.5 text-xs md:text-sm font-medium text-indigo-300 ring-1 ring-indigo-500/30 transition-all hover:bg-indigo-500/30",children:["Next Round ",e.jsx(de,{size:14})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{onClick:u,className:"flex-1 flex items-center justify-center gap-1.5 rounded-lg bg-slate-800/60 px-3 py-2.5 text-xs md:text-sm font-medium text-slate-400 transition-all hover:bg-slate-700/60 hover:text-slate-300",children:[e.jsx(K,{size:14})," Reset"]}),e.jsx("button",{onClick:()=>b(!a),className:`flex items-center justify-center gap-1.5 rounded-lg px-3 py-2.5 text-xs md:text-sm font-medium transition-all ${a?"bg-indigo-500/15 text-indigo-300 ring-1 ring-indigo-500/30":"bg-slate-800/60 text-slate-400"}`,children:a?e.jsx(Q,{size:14}):e.jsx(ee,{size:14})})]}),s&&e.jsx("div",{className:"rounded-lg border border-red-500/30 bg-red-500/5 px-3 py-2.5 text-center text-xs md:text-sm font-medium text-red-400 animate-pulse",children:s})]}),e.jsxs("div",{className:"order-last md:order-first flex md:flex-1 flex-col gap-4 min-h-0 md:overflow-auto",children:[$.map((d,v)=>e.jsxs("div",{className:`rounded-2xl border p-4 shadow-xl backdrop-blur-sm md:p-5 ${w==="building"&&N===v?v===0?"border-indigo-500/30 bg-indigo-500/5":"border-violet-500/30 bg-violet-500/5":"border-emerald-900/40 bg-[radial-gradient(circle_at_top_left,rgba(16,185,129,0.12),transparent_34%),linear-gradient(135deg,rgba(15,23,42,0.96),rgba(6,78,59,0.28))]"}`,children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("h3",{className:`text-xs md:text-sm font-semibold uppercase tracking-wider ${v===0?"text-indigo-400":"text-violet-400"}`,children:d.name}),e.jsxs("span",{className:`text-xs md:text-sm font-mono font-bold ${d.hand.length===P?"text-emerald-400":"text-slate-500"}`,children:[d.hand.length,"/",P]})]}),e.jsxs("div",{className:"flex min-h-[5rem] flex-wrap items-end gap-1.5 rounded-xl border border-emerald-950/40 bg-emerald-950/20 p-3 shadow-inner md:gap-2",children:[d.hand.map((j,y)=>e.jsx(ut,{code:j,onRemove:w==="building"&&N===v?()=>i(y):void 0},`${j}-${y}`)),d.hand.lengthe.jsx(I,{size:"md",placeholder:!0},`e-${y}`))]})]},v)),w==="building"&&!r&&e.jsxs("div",{className:"rounded-2xl border border-slate-700/50 bg-slate-900/70 p-4 shadow-xl shadow-black/20 backdrop-blur-sm md:p-5",children:[e.jsx("h3",{className:"text-xs md:text-sm font-semibold uppercase tracking-wider text-slate-300 mb-3",children:"Tile Wall"}),e.jsx("div",{className:"space-y-3 md:space-y-4",children:B.map(d=>e.jsxs("div",{className:"rounded-xl border border-slate-800/70 bg-slate-950/35 p-3",children:[e.jsx("p",{className:"text-[10px] md:text-xs font-medium mb-1.5",style:{color:Z[d]},children:he[d]}),e.jsx("div",{className:"flex flex-wrap items-end gap-1 md:gap-1.5",children:O.map(v=>{const j=`${d}${v}`;return e.jsx(pt,{suit:d,value:v,count:gt(l,j),disabled:r,onClick:()=>T(j)},j)})})]},d))})]})]})]})}function ft(){const[t,s]=c.useState([]),[n,a]=c.useState(null),[l,r]=c.useState([]),[m,k]=c.useState(-1),[p,T]=c.useState(!1),[i,o]=c.useState(400),[x,u]=c.useState(null),[g,b]=c.useState(!1),[w,$]=c.useState(!0),N=c.useRef(null),f=te();c.useEffect(()=>()=>{N.current&&clearInterval(N.current)},[]);const C=c.useCallback(()=>{a(null),r([]),k(-1),T(!1),N.current&&(clearInterval(N.current),N.current=null)},[]),h=c.useCallback(_=>{s(A=>{const R=be(A,_);return R?(u(R),f.playErrorSound(),A):(u(null),C(),f.playTilePlaced(fe(_).value),L([...A,_]))})},[C,f]),d=c.useCallback(_=>{s(A=>{const R=[...A];return R.splice(_,1),C(),f.playTileRemoved(),R}),u(null)},[C,f]),v=c.useCallback(()=>{s([]),u(null),C()},[C]),j=c.useCallback(()=>{s(D()),u(null),C()},[C]),y=c.useCallback(()=>{s(ce()),u(null),C()},[C]),W=c.useCallback(()=>{const _=st(t);if(_){u(_),f.playErrorSound();return}if(u(null),g){const{result:A,steps:R}=at(t);a(A),r(R),k(-1)}else{const A=G(t);a(A),r([]),k(-1),A.isWin?f.playWinSound():f.playLoseSound()}},[t,g,f]),S=c.useCallback(()=>{k(_=>{const A=Math.min(_+1,l.length-1);if(A>=0&&A