diff --git a/script.js b/script.js
index a8f0d36..c43be71 100644
--- a/script.js
+++ b/script.js
@@ -1,10 +1,50 @@
-"use strict";(()=>{function Z(c){if(c<3)return[];if(c===3)return[3];if(c===4)return[4];if(c===5)return[5];if(c===6)return[3,3];if(c===7)return[4,3];if(c===8)return[4,4];if(c===9)return[3,3,3];if(c===10)return[5,5];let e=Math.floor(c/4),t=c%4;return t===0?Array(e).fill(4):t===1?e>=2?[...Array(e-2).fill(4),5,4]:[3,3,3,2]:t===2?e>=1?[...Array(e-1).fill(4),3,3]:[3,3,3,3]:t===3?[...Array(e).fill(4),3]:[]}function ye(c){if(c<3)return[];if(c<9)return Z(c);if(c===9)return[3,3,3];if(c===10)return[4,3,3];if(c===11)return[4,4,3];if(c===12)return[4,4,4];if(c===13)return[4,3,3,3];if(c===14)return[4,4,3,3];if(c===15)return[4,4,4,3];let e=[],t=c;for(;t>=7;)e.push(4),t-=4;if(t===6)e.push(3,3);else if(t===5)if(e.length>0)e.pop(),t+=4,e.push(3,3,3);else return Z(c);else t===4?e.push(4):t===3&&e.push(3);return e.sort((r,n)=>n-r)}function fe(){let c=document.getElementById("avoid-five-pods-radio");return c&&c.checked?"avoid-five":"balanced"}function ve(){let c=document.getElementById("bracket-radio");if(c&&c.checked)return{allowLeniency:!1,allowSuperLeniency:!1,maxTolerance:0};let e=document.getElementById("no-leniency-radio"),t=document.getElementById("leniency-radio");return document.getElementById("super-leniency-radio").checked?{allowLeniency:!0,allowSuperLeniency:!0,maxTolerance:1}:t.checked?{allowLeniency:!0,allowSuperLeniency:!1,maxTolerance:.5}:{allowLeniency:!1,allowSuperLeniency:!1,maxTolerance:0}}function be(c){let e=[];if(c.forEach(n=>{if(n.checked){let o=parseFloat(n.value);isNaN(o)||e.push(o)}}),e.length===0)return{availablePowers:[],powerRange:"",averagePower:0};e.sort((n,o)=>n-o);let t;e.length===1?t=e[0].toString():t=e.join(", ");let r=e.reduce((n,o)=>n+o,0)/e.length;return{availablePowers:e,powerRange:t,averagePower:Math.round(r*2)/2}}function Me(){let c=document.querySelector("#leniency-radio");return document.querySelector("#super-leniency-radio")?.checked?1:c?.checked?.5:0}function J(c){let e=c.players.flatMap(o=>"players"in o?o.players:[o]);if(e.length===0)return c.power.toString();let t=Me(),r=[],n=new Set;e.forEach(o=>{o.availablePowers.forEach(s=>n.add(s))});for(let o of n)e.every(a=>a.availablePowers.some(i=>Math.abs(o-i)<=t))&&r.push(o);return r.sort((o,s)=>o-s),r.length===0?c.power.toString():r.length===1?r[0].toString():r.every((s,a)=>a===0||s-r[a-1]<=.5)&&r.length>2?`${r[0]}-${r[r.length-1]}`:r.join(", ")}function j(c,e){let t=[];if(Array.isArray(c.availablePowers))t=c.availablePowers;else if(typeof c.powerRange=="string")if(c.powerRange.includes("-")){let[n,o]=c.powerRange.split("-").map(s=>parseFloat(s.trim()));for(let s=n;s<=o;s+=.5)t.push(s)}else t=c.powerRange.split(",").map(n=>parseFloat(n.trim()));return t.map(n=>e.includes(n)?`${n}`:n.toString()).join(", ")}function Ee(c,e){let t=[];if(Array.isArray(c.availableBrackets))t=c.availableBrackets;else if(typeof c.bracketRange=="string")if(c.bracketRange.includes("-")){let[n,o]=c.bracketRange.split("-").map(i=>i.trim()),s=parseInt(n),a=parseInt(o);if(!isNaN(s)&&!isNaN(a))for(let i=s;i<=a;i++)t.push(i.toString());else t=[n,o]}else t=c.bracketRange.split(",").map(n=>n.trim());return t.map(n=>e.includes(n)?`${n}`:n.toString()).join(", ")}function Y(c){let e=c.players.flatMap(s=>"players"in s?s.players:[s]);if(e.length===0)return[];let t=new Map,r=new Set;if(e.forEach(s=>{s.availablePowers.length===1&&r.add(s.availablePowers[0]),s.availablePowers.forEach(a=>{t.set(a,(t.get(a)||0)+1)})}),t.size===0)return[];let n=Math.max(...t.values()),o=[];for(let[s,a]of t.entries())(a===n||r.has(s))&&o.push(s);return o.sort((s,a)=>s-a),o}var X=class{constructor(){this.groups=new Map;this.nextPlayerId=0;this.nextGroupId=1;this.availableColors=[];this.groupColorAssignments=new Map;this.initializeAvailableColors()}initializeAvailableColors(){this.availableColors=Array.from({length:50},(e,t)=>t+1),this.shuffleArray(this.availableColors)}shuffleArray(e){for(let t=e.length-1;t>0;t--){let r=Math.floor(Math.random()*(t+1));[e[t],e[r]]=[e[r],e[t]]}}assignRandomColor(e){if(this.groupColorAssignments.has(e))return this.groupColorAssignments.get(e);this.availableColors.length===0&&this.initializeAvailableColors();let t=this.availableColors.pop();return this.groupColorAssignments.set(e,t),t}releaseColor(e){let t=this.groupColorAssignments.get(e);t&&(this.availableColors.push(t),this.groupColorAssignments.delete(e))}getNextPlayerId(){return this.nextPlayerId++}resetPlayerIds(){this.nextPlayerId=0}getNextGroupId(){let e=new Set;document.querySelectorAll(".group-select").forEach(r=>{if(r.value.startsWith("group-")){let n=parseInt(r.value.split("-")[1]);isNaN(n)||e.add(n)}if(r.value==="new-group"&&r.dataset.createdGroupId&&r.dataset.createdGroupId.startsWith("group-")){let n=parseInt(r.dataset.createdGroupId.split("-")[1]);isNaN(n)||e.add(n)}});for(let r=1;r<=50;r++)if(!e.has(r))return r;return this.nextGroupId++}resetGroupIds(){this.nextGroupId=1}getGroups(){return this.groups}clearGroups(){this.groups.clear()}getPlayerFromRow(e){let t=e.querySelector(".player-name");t.classList.remove("input-error");let r=t.value.trim();if(!r)return t.classList.add("input-error"),null;if(document.getElementById("bracket-radio").checked){let s=e.querySelectorAll('.bracket-checkbox input[type="checkbox"]'),a=[];if(s.forEach(p=>{p.checked&&a.push(p.value)}),a.length===0)return e.querySelector(".bracket-selector-btn").classList.add("error"),null;e.querySelector(".bracket-selector-btn").classList.remove("error");let i={1:1,2:2,3:3,4:4,cedh:10},l=a.map(p=>i[p]),d=l.reduce((p,u)=>p+u,0)/l.length;return{id:parseInt(e.dataset.playerId),name:r,power:Math.round(d*2)/2,availablePowers:l,powerRange:a.join(", "),brackets:a,bracketRange:a.join(", "),rowElement:e}}else{let s=e.querySelectorAll('.power-checkbox input[type="checkbox"]'),a=be(s);return a.availablePowers.length===0?(e.querySelector(".power-selector-btn").classList.add("error"),null):(e.querySelector(".power-selector-btn").classList.remove("error"),{id:parseInt(e.dataset.playerId),name:r,power:a.averagePower,availablePowers:a.availablePowers,powerRange:a.powerRange,rowElement:e})}}handleGroupChange(e){this.groups.clear();let t=Array.from(e.querySelectorAll(".player-row"));t.forEach(n=>{for(let o=1;o<=50;o++)n.querySelector(".group-select").classList.remove(`group-${o}`)});let r=new Set;t.forEach(n=>{let o=n.querySelector(".group-select");o.dataset.createdGroupId?r.add(o.dataset.createdGroupId):o.value.startsWith("group-")&&r.add(o.value)}),t.forEach(n=>{let o=n.querySelector(".group-select"),s="";if(o.value==="new-group"){o.dataset.createdGroupId?s=o.dataset.createdGroupId:(s=`group-${this.getNextGroupId()}`,r.add(s),o.dataset.createdGroupId=s);let a=this.getPlayerFromRow(n);a&&(this.groups.has(s)||this.groups.set(s,[]),this.groups.get(s).push(a))}else if(o.value.startsWith("group-")){s=o.value;let a=this.getPlayerFromRow(n);a&&(this.groups.has(o.value)||this.groups.set(o.value,[]),this.groups.get(o.value).push(a))}else o.dataset.createdGroupId&&delete o.dataset.createdGroupId;if(s){let a=parseInt(s.split("-")[1]);a>=1&&a<=50&&o.classList.add(`group-${a}`)}}),this.cleanupUnusedGroups(r),this.updateAllGroupDropdowns(e)}updateAllGroupDropdowns(e){let t=new Set,r=Array.from(e.querySelectorAll(".player-row"));r.forEach(n=>{let o=n.querySelector(".group-select");o.value==="new-group"&&o.dataset.createdGroupId?t.add(o.dataset.createdGroupId):o.value.startsWith("group-")&&t.add(o.value)}),r.forEach(n=>{let o=n.querySelector(".group-select"),s=o.value,a=o.dataset.createdGroupId;if(Array.from(o.options).forEach(l=>{l.value.startsWith("group-")&&o.remove(l.index)}),t.forEach(l=>{let d=l.split("-")[1],p=new Option(`Group ${d}`,l);o.add(p)}),a&&t.has(a)&&(s==="new-group"||s==="no-group")){o.value=a;let l=parseInt(a.split("-")[1]);l>=1&&l<=50&&o.classList.add(`group-${l}`)}else if(s.startsWith("group-")&&t.has(s)){o.value=s;let l=parseInt(s.split("-")[1]);l>=1&&l<=50&&o.classList.add(`group-${l}`)}else{o.value="no-group";for(let l=1;l<=50;l++)o.classList.remove(`group-${l}`)}})}arePlayersCompatible(e,t,r){return e.availablePowers.some(o=>t.availablePowers.some(s=>Math.abs(o-s)<.01))?!0:r.allowLeniency?e.availablePowers.some(o=>t.availablePowers.some(s=>Math.abs(o-s)<=r.maxTolerance)):!1}findAllCommonPowers(e,t){return e.length===0?[]:[...new Set(e.flatMap(n=>n.availablePowers))].sort((n,o)=>n-o).filter(n=>e.every(o=>o.availablePowers.some(s=>{let a=Math.abs(s-n);return a<.01||t.allowLeniency&&a<=t.maxTolerance})))}findBestCommonPowerLevel(e){if(e.length===0)return null;let t=new Map;for(let o of e)for(let s of o.availablePowers)t.set(s,(t.get(s)||0)+1);if(t.size===0)return null;let r=e[0].availablePowers[0],n=0;for(let[o,s]of t.entries())s>n&&(n=s,r=o);return r}calculatePodPower(e){if(e.length===0)return 0;let t=e.reduce((r,n)=>{if("players"in n)return r+n.averagePower;{let o=n.powerRange.split(",").map(a=>parseFloat(a.trim())),s=o.reduce((a,i)=>a+i,0)/o.length;return r+s}},0);return Math.round(t/e.length*10)/10}cleanupUnusedGroups(e){Array.from(this.groupColorAssignments.keys()).forEach(o=>{e.has(o)||this.releaseColor(o)}),Array.from(this.groups.keys()).forEach(o=>{e.has(o)||this.groups.delete(o)}),document.querySelectorAll(".group-select").forEach(o=>{let s=o.dataset.createdGroupId;s&&!e.has(s)&&delete o.dataset.createdGroupId})}};var ee=class{constructor(){this.shuffleSeed=null;this.sizeCache=new Map}setShuffleSeed(e){this.shuffleSeed=e,this.sizeCache.clear()}seededRandom(e){let t=e;return()=>(t=t*1103515245+12345&2147483647,t/2147483647)}shuffleArray(e){let t=[...e],r;this.shuffleSeed!==null?r=this.seededRandom(this.shuffleSeed):r=Math.random;for(let n=t.length-1;n>0;n--){let o=Math.floor(r()*(n+1));[t[n],t[o]]=[t[o],t[n]]}return t}getItemSize(e){let t="players"in e?`group-${e.id}`:`player-${e.id}`;if(!this.sizeCache.has(t)){let r="players"in e?e.size:1;this.sizeCache.set(t,r)}return this.sizeCache.get(t)}getItemId(e){return"players"in e?e.id:e.id.toString()}generatePodsWithBacktracking(e,t,r){let n=this.shuffleArray(e),o=n.reduce((l,d)=>l+("size"in d?d.size:1),0);if(o>=3&&o<=5){let l=n.flatMap(p=>"players"in p?p.players:[p]),d=this.findBestCommonPowerLevel(l);return d!==null?{pods:[{players:n,power:d}],unassigned:[]}:{pods:[],unassigned:n}}let s=this.findOptimalPodAssignment(n,t,r),a=new Set;for(let l of s)for(let d of l.players)"players"in d?a.add(d.id):a.add(d.id.toString());let i=n.filter(l=>"players"in l?!a.has(l.id):!a.has(l.id.toString()));return{pods:s,unassigned:i}}findOptimalPodAssignment(e,t,r){return this.optimizeVirtualPlayerAssignmentUnified(e,t,r)}optimizeVirtualPlayerAssignmentUnified(e,t,r){if(e.length===0)return[];let n=this.createVirtualPlayersUnified(e),o=new Map;for(let a of n)o.has(a.powerLevel)||o.set(a.powerLevel,[]),o.get(a.powerLevel).push(a);let s={pods:[],totalPods:0};return r.allowLeniency?this.backtrackVirtualPlayersWithLeniencyUnified(n,t,r.maxTolerance,[],new Set,t,s):this.backtrackVirtualPlayersUnified(Array.from(o.entries()),[],new Set,t,s),s.pods}createVirtualPlayersUnified(e){let t=[];for(let r of e)if("players"in r){let n=r.players.flatMap(d=>d.availablePowers),o=Math.min(...n),s=Math.max(...n),i=[r.averagePower,o,s],l=[...new Set(i)];for(let d of l)t.push({item:r,powerLevel:d})}else for(let n of r.availablePowers)t.push({item:r,powerLevel:n});return t}backtrackVirtualPlayersUnified(e,t,r,n,o){if(n.length===0){t.length>o.totalPods&&(o.pods=[...t],o.totalPods=t.length);return}if(t.length+n.length<=o.totalPods)return;let s=n[0],a=n.slice(1);for(let[i,l]of e){let d=l.filter(E=>{let f=this.getItemId(E.item);return!r.has(f)}),p=0;for(let E=0;E=u){let E=d.sort((v,m)=>{let h=this.getItemSize(v.item);return this.getItemSize(m.item)-h}),f=[],P=new Set,g=0;for(let v of E){let m=this.getItemId(v.item),h=this.getItemSize(v.item);if(!P.has(m)&&g+h<=s&&(f.push(v),P.add(m),g+=h,g===s))break}if(g>=3){let v=f.map(y=>y.item),m={players:v,power:i},h=new Set(r);for(let y of v){let w="players"in y?y.id:y.id.toString();h.add(w)}this.backtrackVirtualPlayersUnified(e,[...t,m],h,a,o)}}}this.backtrackVirtualPlayersUnified(e,t,r,a,o)}backtrackVirtualPlayersWithLeniencyUnified(e,t,r,n,o,s,a){if(s.length===0){n.length>a.totalPods&&(a.pods=[...n],a.totalPods=n.length);return}if(n.length+s.length<=a.totalPods)return;let i=s[0],l=s.slice(1),d=e.filter(u=>{let E="players"in u.item?u.item.id:u.item.id.toString();return!o.has(E)}),p=[...new Set(d.map(u=>u.powerLevel))].sort((u,E)=>u-E);for(let u of p){let E=d.filter(h=>("players"in h.item,Math.abs(h.powerLevel-u)<=r)),f=new Map;for(let h of E){let y="players"in h.item?h.item.id:h.item.id.toString();if(!f.has(y))f.set(y,h);else{let w=f.get(y),k=Math.abs(w.powerLevel-u);Math.abs(h.powerLevel-u){if("players"in h.item&&"players"in y.item){let w=Math.abs(h.powerLevel-h.item.averagePower)<.01,k=Math.abs(y.powerLevel-y.item.averagePower)<.01;return w&&!k?-1:!w&&k?1:Math.abs(h.powerLevel-u)-Math.abs(y.powerLevel-u)}return"players"in h.item&&!("players"in y.item)?1:!("players"in h.item)&&"players"in y.item?-1:Math.abs(h.powerLevel-u)-Math.abs(y.powerLevel-u)}),v=0;for(let h=0;h=m){let h=g.sort((b,L)=>{let T=this.getItemSize(b.item);return this.getItemSize(L.item)-T}),y=[],w=new Set,k=0;for(let b of h){let L=this.getItemId(b.item),T=this.getItemSize(b.item);if(!w.has(L)&&k+T<=i&&(y.push(b),w.add(L),k+=T,k===i))break}if(k>=3){let b=y.map(I=>I.item);if(!this.isPodPowerSpreadValid(y,r))continue;let L=y.reduce((I,$)=>I+$.powerLevel,0)/y.length,T={players:b,power:Math.round(L*2)/2},S=new Set(o);for(let I of b){let $="players"in I?I.id:I.id.toString();S.add($),e.forEach(G=>{let ae="players"in G.item?G.item.id:G.item.id.toString();ae===$&&S.add(ae)})}this.backtrackVirtualPlayersWithLeniencyUnified(e,t,r,[...n,T],S,l,a)}}}this.backtrackVirtualPlayersWithLeniencyUnified(e,t,r,n,o,l,a)}isPodPowerSpreadValid(e,t){if(e.length===0)return!0;let r=e.map(a=>a.powerLevel),n=Math.min(...r);return Math.max(...r)-n<=t}findBestCommonPowerLevel(e){if(e.length===0)return null;let t=new Map;for(let o of e)for(let s of o.availablePowers)t.set(s,(t.get(s)||0)+1);if(t.size===0)return null;let r=e[0].availablePowers[0],n=0;for(let[o,s]of t.entries())s>n&&(n=s,r=o);return r}};var te=class{constructor(e,t){this.draggedElement=null;this.draggedItemData=null;this.currentPods=[];this.currentUnassigned=[];this.handleDragStart=e=>{let t=e.target;this.draggedElement=t,t.classList.add("dragging"),this.draggedItemData={type:t.dataset.itemType,id:t.dataset.itemId,podIndex:t.dataset.podIndex,itemIndex:t.dataset.itemIndex},e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/html",t.outerHTML)};this.handleDragEnd=e=>{e.target.classList.remove("dragging"),this.draggedElement=null,this.draggedItemData=null};this.handleDragOver=e=>{e.preventDefault(),e.dataTransfer.dropEffect="move",e.currentTarget.classList.add("drag-over")};this.handleDragLeave=e=>{e.currentTarget.classList.remove("drag-over")};this.handleDrop=e=>{e.preventDefault();let t=e.currentTarget;if(t.classList.remove("drag-over"),!this.draggedItemData)return;let r=t.dataset.podIndex,n=this.draggedItemData.podIndex;r!==n&&this.moveItemBetweenPods(this.draggedItemData,r)};this.playerManager=e,this.onPodsChanged=t}setCurrentPods(e,t=[]){this.currentPods=[...e],this.currentUnassigned=[...t]}moveItemBetweenPods(e,t){let r=e.podIndex,n=parseInt(e.itemIndex),o=null;if(r==="unassigned")o=this.currentUnassigned[n],this.currentUnassigned.splice(n,1);else{let s=this.currentPods[parseInt(r)];o=s.players[n],s.players.splice(n,1),s.power=this.playerManager.calculatePodPower(s.players)}if(o){if(t==="unassigned")this.currentUnassigned.push(o);else if(t==="new-pod"){let s={players:[o],power:this.playerManager.calculatePodPower([o])};this.currentPods.push(s)}else{let s=this.currentPods[parseInt(t)];s.players.push(o),s.power=this.playerManager.calculatePodPower(s.players)}this.cleanupEmptyPods(),this.onPodsChanged(this.currentPods,this.currentUnassigned)}}cleanupEmptyPods(){this.currentPods=this.currentPods.filter(e=>e.players.length>0)}};var ie=class{constructor(){this.pools=new Map;this.POOL_SIZE=15}get(e){let t=this.pools.get(e.toLowerCase())||[];if(t.length>0){let r=t.pop();return this.resetElement(r),r}return document.createElement(e)}release(e){let t=e.tagName.toLowerCase(),r=this.pools.get(t);r||(r=[],this.pools.set(t,r)),r.length{delete e.dataset[t]})}clear(){this.pools.clear()}getStats(){let e={};return this.pools.forEach((t,r)=>{e[r]=t.length}),e}preWarm(){[{tag:"div",count:8},{tag:"li",count:6},{tag:"ul",count:4},{tag:"h3",count:3},{tag:"p",count:3},{tag:"strong",count:3},{tag:"button",count:2}].forEach(({tag:t,count:r})=>{let n=[];for(let o=0;o0;r--){let n=Math.floor(Math.random()*(r+1));[t[r],t[n]]=[t[n],t[r]]}if(e>t.length){let r=[];for(let n=0;n"players"in s?s.players:[s]);if(t.length===0)return"Unknown";let r=[],n=new Set;t.forEach(s=>{s.brackets&&s.brackets.forEach(a=>n.add(a))});for(let s of n)t.every(i=>i.brackets&&i.brackets.includes(s))&&r.push(s);let o=["1","2","3","4","cedh"];if(r.sort((s,a)=>o.indexOf(s)-o.indexOf(a)),r.length===0)return"Unknown";if(r.length===1)return r[0];{let s=r.filter(i=>i!=="cedh");return s.length>1&&s.every((i,l)=>{if(l===0)return!0;let d=parseInt(i),p=parseInt(s[l-1]);return d===p+1})&&s.length===r.length&&r.length>1?`${r[0]}-${r[r.length-1]}`:r.join(", ")}}getValidBracketsArrayForPod(e){let t=e.players.flatMap(a=>"players"in a?a.players:[a]);if(t.length===0)return[];let r=new Map;if(t.forEach(a=>{a.brackets&&a.brackets.forEach(i=>{r.set(i,(r.get(i)||0)+1)})}),r.size===0)return[];let n=Math.ceil(t.length/2),o=[];for(let[a,i]of r.entries())i>=n&&o.push(a);let s=["1","2","3","4","cedh"];return o.sort((a,i)=>s.indexOf(a)-s.indexOf(i)),o}enterDisplayMode(e){if(e.length===0)return;this.isDisplayMode=!0,document.body.classList.add("display-mode");let t=Math.ceil(Math.sqrt(e.length)),r=A.get("div");r.className="display-mode-container",r.style.position="fixed",r.style.top="0",r.style.left="0",r.style.width="100vw",r.style.height="100vh",r.style.background="#1a1a1a",r.style.zIndex="1000",r.style.padding="20px",r.style.boxSizing="border-box",r.style.overflow="hidden",r.innerHTML=`
+"use strict";(()=>{function Z(c){if(c<3)return[];if(c===3)return[3];if(c===4)return[4];if(c===5)return[5];if(c===6)return[3,3];if(c===7)return[4,3];if(c===8)return[4,4];if(c===9)return[3,3,3];if(c===10)return[5,5];let e=Math.floor(c/4),t=c%4;return t===0?Array(e).fill(4):t===1?e>=2?[...Array(e-2).fill(4),5,4]:[3,3,3,2]:t===2?e>=1?[...Array(e-1).fill(4),3,3]:[3,3,3,3]:t===3?[...Array(e).fill(4),3]:[]}function fe(c){if(c<3)return[];if(c<9)return Z(c);if(c===9)return[3,3,3];if(c===10)return[4,3,3];if(c===11)return[4,4,3];if(c===12)return[4,4,4];if(c===13)return[4,3,3,3];if(c===14)return[4,4,3,3];if(c===15)return[4,4,4,3];let e=[],t=c;for(;t>=7;)e.push(4),t-=4;if(t===6)e.push(3,3);else if(t===5)if(e.length>0)e.pop(),t+=4,e.push(3,3,3);else return Z(c);else t===4?e.push(4):t===3&&e.push(3);return e.sort((r,n)=>n-r)}function ve(){let c=document.getElementById("avoid-five-pods-radio");return c&&c.checked?"avoid-five":"balanced"}function be(){let c=document.getElementById("bracket-radio");if(c&&c.checked)return{allowLeniency:!1,allowSuperLeniency:!1,maxTolerance:0};let e=document.getElementById("no-leniency-radio"),t=document.getElementById("leniency-radio");return document.getElementById("super-leniency-radio").checked?{allowLeniency:!0,allowSuperLeniency:!0,maxTolerance:1}:t.checked?{allowLeniency:!0,allowSuperLeniency:!1,maxTolerance:.5}:{allowLeniency:!1,allowSuperLeniency:!1,maxTolerance:0}}function Ee(c){let e=[];if(c.forEach(n=>{if(n.checked){let o=parseFloat(n.value);isNaN(o)||e.push(o)}}),e.length===0)return{availablePowers:[],powerRange:"",averagePower:0};e.sort((n,o)=>n-o);let t;e.length===1?t=e[0].toString():t=e.join(", ");let r=e.reduce((n,o)=>n+o,0)/e.length;return{availablePowers:e,powerRange:t,averagePower:Math.round(r*2)/2}}function Pe(){let c=document.querySelector("#leniency-radio");return document.querySelector("#super-leniency-radio")?.checked?1:c?.checked?.5:0}function J(c){let e=c.players.flatMap(o=>"players"in o?o.players:[o]);if(e.length===0)return c.power.toString();let t=Pe(),r=[],n=new Set;e.forEach(o=>{o.availablePowers.forEach(s=>n.add(s))});for(let o of n)e.every(a=>a.availablePowers.some(i=>Math.abs(o-i)<=t))&&r.push(o);return r.sort((o,s)=>o-s),r.length===0?c.power.toString():r.length===1?r[0].toString():r.every((s,a)=>a===0||s-r[a-1]<=.5)&&r.length>2?`${r[0]}-${r[r.length-1]}`:r.join(", ")}function j(c,e){let t=[];if(Array.isArray(c.availablePowers))t=c.availablePowers;else if(typeof c.powerRange=="string")if(c.powerRange.includes("-")){let[n,o]=c.powerRange.split("-").map(s=>parseFloat(s.trim()));for(let s=n;s<=o;s+=.5)t.push(s)}else t=c.powerRange.split(",").map(n=>parseFloat(n.trim()));return t.map(n=>e.includes(n)?`${n}`:n.toString()).join(", ")}function we(c,e){let t=[];if(Array.isArray(c.availableBrackets))t=c.availableBrackets;else if(typeof c.bracketRange=="string")if(c.bracketRange.includes("-")){let[n,o]=c.bracketRange.split("-").map(i=>i.trim()),s=parseInt(n),a=parseInt(o);if(!isNaN(s)&&!isNaN(a))for(let i=s;i<=a;i++)t.push(i.toString());else t=[n,o]}else t=c.bracketRange.split(",").map(n=>n.trim());return t.map(n=>e.includes(n)?`${n}`:n.toString()).join(", ")}function Y(c){let e=c.players.flatMap(s=>"players"in s?s.players:[s]);if(e.length===0)return[];let t=new Map,r=new Set;if(e.forEach(s=>{s.availablePowers.length===1&&r.add(s.availablePowers[0]),s.availablePowers.forEach(a=>{t.set(a,(t.get(a)||0)+1)})}),t.size===0)return[];let n=Math.max(...t.values()),o=[];for(let[s,a]of t.entries())(a===n||r.has(s))&&o.push(s);return o.sort((s,a)=>s-a),o}var X=class{constructor(){this.groups=new Map;this.nextPlayerId=0;this.nextGroupId=1;this.availableColors=[];this.groupColorAssignments=new Map;this.initializeAvailableColors()}initializeAvailableColors(){this.availableColors=Array.from({length:50},(e,t)=>t+1),this.shuffleArray(this.availableColors)}shuffleArray(e){for(let t=e.length-1;t>0;t--){let r=Math.floor(Math.random()*(t+1));[e[t],e[r]]=[e[r],e[t]]}}assignRandomColor(e){if(this.groupColorAssignments.has(e))return this.groupColorAssignments.get(e);this.availableColors.length===0&&this.initializeAvailableColors();let t=this.availableColors.pop();return this.groupColorAssignments.set(e,t),t}releaseColor(e){let t=this.groupColorAssignments.get(e);t&&(this.availableColors.push(t),this.groupColorAssignments.delete(e))}getNextPlayerId(){return this.nextPlayerId++}resetPlayerIds(){this.nextPlayerId=0}getNextGroupId(){let e=new Set;document.querySelectorAll(".group-select").forEach(r=>{if(r.value.startsWith("group-")){let n=parseInt(r.value.split("-")[1]);isNaN(n)||e.add(n)}if(r.value==="new-group"&&r.dataset.createdGroupId&&r.dataset.createdGroupId.startsWith("group-")){let n=parseInt(r.dataset.createdGroupId.split("-")[1]);isNaN(n)||e.add(n)}});for(let r=1;r<=50;r++)if(!e.has(r))return r;return this.nextGroupId++}resetGroupIds(){this.nextGroupId=1}getGroups(){return this.groups}clearGroups(){this.groups.clear()}getPlayerFromRow(e){let t=e.querySelector(".player-name");t.classList.remove("input-error");let r=t.value.trim();if(!r)return t.classList.add("input-error"),null;if(document.getElementById("bracket-radio").checked){let s=e.querySelectorAll('.bracket-checkbox input[type="checkbox"]'),a=[];if(s.forEach(p=>{p.checked&&a.push(p.value)}),a.length===0)return e.querySelector(".bracket-selector-btn").classList.add("error"),null;e.querySelector(".bracket-selector-btn").classList.remove("error");let i={1:1,2:2,3:3,4:4,cedh:10},l=a.map(p=>i[p]),d=l.reduce((p,u)=>p+u,0)/l.length;return{id:parseInt(e.dataset.playerId),name:r,power:Math.round(d*2)/2,availablePowers:l,powerRange:a.join(", "),brackets:a,bracketRange:a.join(", "),rowElement:e}}else{let s=e.querySelectorAll('.power-checkbox input[type="checkbox"]'),a=Ee(s);return a.availablePowers.length===0?(e.querySelector(".power-selector-btn").classList.add("error"),null):(e.querySelector(".power-selector-btn").classList.remove("error"),{id:parseInt(e.dataset.playerId),name:r,power:a.averagePower,availablePowers:a.availablePowers,powerRange:a.powerRange,rowElement:e})}}handleGroupChange(e){this.groups.clear();let t=Array.from(e.querySelectorAll(".player-row"));t.forEach(n=>{for(let o=1;o<=50;o++)n.querySelector(".group-select").classList.remove(`group-${o}`)});let r=new Set;t.forEach(n=>{let o=n.querySelector(".group-select");o.dataset.createdGroupId?r.add(o.dataset.createdGroupId):o.value.startsWith("group-")&&r.add(o.value)}),t.forEach(n=>{let o=n.querySelector(".group-select"),s="";if(o.value==="new-group"){o.dataset.createdGroupId?s=o.dataset.createdGroupId:(s=`group-${this.getNextGroupId()}`,r.add(s),o.dataset.createdGroupId=s);let a=this.getPlayerFromRow(n);a&&(this.groups.has(s)||this.groups.set(s,[]),this.groups.get(s).push(a))}else if(o.value.startsWith("group-")){s=o.value;let a=this.getPlayerFromRow(n);a&&(this.groups.has(o.value)||this.groups.set(o.value,[]),this.groups.get(o.value).push(a))}else o.dataset.createdGroupId&&delete o.dataset.createdGroupId;if(s){let a=parseInt(s.split("-")[1]);a>=1&&a<=50&&o.classList.add(`group-${a}`)}}),this.cleanupUnusedGroups(r),this.updateAllGroupDropdowns(e)}updateAllGroupDropdowns(e){let t=new Set,r=Array.from(e.querySelectorAll(".player-row"));r.forEach(n=>{let o=n.querySelector(".group-select");o.value==="new-group"&&o.dataset.createdGroupId?t.add(o.dataset.createdGroupId):o.value.startsWith("group-")&&t.add(o.value)}),r.forEach(n=>{let o=n.querySelector(".group-select"),s=o.value,a=o.dataset.createdGroupId;if(Array.from(o.options).forEach(l=>{l.value.startsWith("group-")&&o.remove(l.index)}),t.forEach(l=>{let d=l.split("-")[1],p=new Option(`Group ${d}`,l);o.add(p)}),a&&t.has(a)&&(s==="new-group"||s==="no-group")){o.value=a;let l=parseInt(a.split("-")[1]);l>=1&&l<=50&&o.classList.add(`group-${l}`)}else if(s.startsWith("group-")&&t.has(s)){o.value=s;let l=parseInt(s.split("-")[1]);l>=1&&l<=50&&o.classList.add(`group-${l}`)}else{o.value="no-group";for(let l=1;l<=50;l++)o.classList.remove(`group-${l}`)}})}arePlayersCompatible(e,t,r){return e.availablePowers.some(o=>t.availablePowers.some(s=>Math.abs(o-s)<.01))?!0:r.allowLeniency?e.availablePowers.some(o=>t.availablePowers.some(s=>Math.abs(o-s)<=r.maxTolerance)):!1}findAllCommonPowers(e,t){return e.length===0?[]:[...new Set(e.flatMap(n=>n.availablePowers))].sort((n,o)=>n-o).filter(n=>e.every(o=>o.availablePowers.some(s=>{let a=Math.abs(s-n);return a<.01||t.allowLeniency&&a<=t.maxTolerance})))}findBestCommonPowerLevel(e){if(e.length===0)return null;let t=new Map;for(let o of e)for(let s of o.availablePowers)t.set(s,(t.get(s)||0)+1);if(t.size===0)return null;let r=e[0].availablePowers[0],n=0;for(let[o,s]of t.entries())s>n&&(n=s,r=o);return r}calculatePodPower(e){if(e.length===0)return 0;let t=e.reduce((r,n)=>{if("players"in n)return r+n.averagePower;{let o=n.powerRange.split(",").map(a=>parseFloat(a.trim())),s=o.reduce((a,i)=>a+i,0)/o.length;return r+s}},0);return Math.round(t/e.length*10)/10}cleanupUnusedGroups(e){Array.from(this.groupColorAssignments.keys()).forEach(o=>{e.has(o)||this.releaseColor(o)}),Array.from(this.groups.keys()).forEach(o=>{e.has(o)||this.groups.delete(o)}),document.querySelectorAll(".group-select").forEach(o=>{let s=o.dataset.createdGroupId;s&&!e.has(s)&&delete o.dataset.createdGroupId})}};var ee=class{constructor(){this.shuffleSeed=null;this.sizeCache=new Map}setShuffleSeed(e){this.shuffleSeed=e,this.sizeCache.clear()}seededRandom(e){let t=e;return()=>(t=t*1103515245+12345&2147483647,t/2147483647)}shuffleArray(e){let t=[...e],r;this.shuffleSeed!==null?r=this.seededRandom(this.shuffleSeed):r=Math.random;for(let n=t.length-1;n>0;n--){let o=Math.floor(r()*(n+1));[t[n],t[o]]=[t[o],t[n]]}return t}getItemSize(e){let t="players"in e?`group-${e.id}`:`player-${e.id}`;if(!this.sizeCache.has(t)){let r="players"in e?e.size:1;this.sizeCache.set(t,r)}return this.sizeCache.get(t)}getItemId(e){return"players"in e?e.id:e.id.toString()}generatePodsWithBacktracking(e,t,r){let n=this.shuffleArray(e),o=n.reduce((l,d)=>l+("size"in d?d.size:1),0);if(o>=3&&o<=5){let l=n.flatMap(p=>"players"in p?p.players:[p]),d=this.findBestCommonPowerLevel(l);return d!==null?{pods:[{players:n,power:d}],unassigned:[]}:{pods:[],unassigned:n}}let s=this.findOptimalPodAssignment(n,t,r),a=new Set;for(let l of s)for(let d of l.players)"players"in d?a.add(d.id):a.add(d.id.toString());let i=n.filter(l=>"players"in l?!a.has(l.id):!a.has(l.id.toString()));return{pods:s,unassigned:i}}findOptimalPodAssignment(e,t,r){return this.optimizeVirtualPlayerAssignmentUnified(e,t,r)}optimizeVirtualPlayerAssignmentUnified(e,t,r){if(e.length===0)return[];let n=this.createVirtualPlayersUnified(e),o=new Map;for(let a of n)o.has(a.powerLevel)||o.set(a.powerLevel,[]),o.get(a.powerLevel).push(a);let s={pods:[],totalPods:0};return r.allowLeniency?this.backtrackVirtualPlayersWithLeniencyUnified(n,t,r.maxTolerance,[],new Set,t,s):this.backtrackVirtualPlayersUnified(Array.from(o.entries()),[],new Set,t,s),s.pods}createVirtualPlayersUnified(e){let t=[];for(let r of e)if("players"in r){let n=r.players.flatMap(d=>d.availablePowers),o=Math.min(...n),s=Math.max(...n),i=[r.averagePower,o,s],l=[...new Set(i)];for(let d of l)t.push({item:r,powerLevel:d})}else for(let n of r.availablePowers)t.push({item:r,powerLevel:n});return t}backtrackVirtualPlayersUnified(e,t,r,n,o){if(n.length===0){t.length>o.totalPods&&(o.pods=[...t],o.totalPods=t.length);return}if(t.length+n.length<=o.totalPods)return;let s=n[0],a=n.slice(1);for(let[i,l]of e){let d=l.filter(E=>{let f=this.getItemId(E.item);return!r.has(f)}),p=0;for(let E=0;E=u){let E=d.sort((v,m)=>{let h=this.getItemSize(v.item);return this.getItemSize(m.item)-h}),f=[],P=new Set,g=0;for(let v of E){let m=this.getItemId(v.item),h=this.getItemSize(v.item);if(!P.has(m)&&g+h<=s&&(f.push(v),P.add(m),g+=h,g===s))break}if(g>=3){let v=f.map(y=>y.item),m={players:v,power:i},h=new Set(r);for(let y of v){let w="players"in y?y.id:y.id.toString();h.add(w)}this.backtrackVirtualPlayersUnified(e,[...t,m],h,a,o)}}}this.backtrackVirtualPlayersUnified(e,t,r,a,o)}backtrackVirtualPlayersWithLeniencyUnified(e,t,r,n,o,s,a){if(s.length===0){n.length>a.totalPods&&(a.pods=[...n],a.totalPods=n.length);return}if(n.length+s.length<=a.totalPods)return;let i=s[0],l=s.slice(1),d=e.filter(u=>{let E="players"in u.item?u.item.id:u.item.id.toString();return!o.has(E)}),p=[...new Set(d.map(u=>u.powerLevel))].sort((u,E)=>u-E);for(let u of p){let E=d.filter(h=>("players"in h.item,Math.abs(h.powerLevel-u)<=r)),f=new Map;for(let h of E){let y="players"in h.item?h.item.id:h.item.id.toString();if(!f.has(y))f.set(y,h);else{let w=f.get(y),M=Math.abs(w.powerLevel-u);Math.abs(h.powerLevel-u){if("players"in h.item&&"players"in y.item){let w=Math.abs(h.powerLevel-h.item.averagePower)<.01,M=Math.abs(y.powerLevel-y.item.averagePower)<.01;return w&&!M?-1:!w&&M?1:Math.abs(h.powerLevel-u)-Math.abs(y.powerLevel-u)}return"players"in h.item&&!("players"in y.item)?1:!("players"in h.item)&&"players"in y.item?-1:Math.abs(h.powerLevel-u)-Math.abs(y.powerLevel-u)}),v=0;for(let h=0;h=m){let h=g.sort((b,L)=>{let T=this.getItemSize(b.item);return this.getItemSize(L.item)-T}),y=[],w=new Set,M=0;for(let b of h){let L=this.getItemId(b.item),T=this.getItemSize(b.item);if(!w.has(L)&&M+T<=i&&(y.push(b),w.add(L),M+=T,M===i))break}if(M>=3){let b=y.map(I=>I.item);if(!this.isPodPowerSpreadValid(y,r))continue;let L=y.reduce((I,$)=>I+$.powerLevel,0)/y.length,T={players:b,power:Math.round(L*2)/2},S=new Set(o);for(let I of b){let $="players"in I?I.id:I.id.toString();S.add($),e.forEach(G=>{let ie="players"in G.item?G.item.id:G.item.id.toString();ie===$&&S.add(ie)})}this.backtrackVirtualPlayersWithLeniencyUnified(e,t,r,[...n,T],S,l,a)}}}this.backtrackVirtualPlayersWithLeniencyUnified(e,t,r,n,o,l,a)}isPodPowerSpreadValid(e,t){if(e.length===0)return!0;let r=e.map(a=>a.powerLevel),n=Math.min(...r);return Math.max(...r)-n<=t}findBestCommonPowerLevel(e){if(e.length===0)return null;let t=new Map;for(let o of e)for(let s of o.availablePowers)t.set(s,(t.get(s)||0)+1);if(t.size===0)return null;let r=e[0].availablePowers[0],n=0;for(let[o,s]of t.entries())s>n&&(n=s,r=o);return r}};var le=class{constructor(){this.pools=new Map;this.POOL_SIZE=15}get(e){let t=this.pools.get(e.toLowerCase())||[];if(t.length>0){let r=t.pop();return this.resetElement(r),r}return document.createElement(e)}release(e){let t=e.tagName.toLowerCase(),r=this.pools.get(t);r||(r=[],this.pools.set(t,r)),r.length{delete e.dataset[t]})}clear(){this.pools.clear()}getStats(){let e={};return this.pools.forEach((t,r)=>{e[r]=t.length}),e}preWarm(){[{tag:"div",count:8},{tag:"li",count:6},{tag:"ul",count:4},{tag:"h3",count:3},{tag:"p",count:3},{tag:"strong",count:3},{tag:"button",count:2}].forEach(({tag:t,count:r})=>{let n=[];for(let o=0;o