01 dev Menu Kour.io

Speed Hack, Invisibility, And many more. "Insert" to open menu.

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램을 설치해야 합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

Advertisement:

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

Advertisement:

// ==UserScript==
// @name         01 dev Menu Kour.io
// @namespace   https://discord.gg/YTeRSG8kER
// @match        *://kour.io/*
// @version      2.0
// @author       01 dev
// @icon         https://cdn.pfps.gg/pfps/30968-pomni-pfp.png
// @description  Speed Hack, Invisibility, And many more. "Insert" to open menu.
// @run-at       document-start
// @grant        unsafeWindow
// @license      MIT
// ==/UserScript==

(function () {
    ("use strict");

    /***************************************
   * Performance.now Speed Hack
   ***************************************/
    const originalPerfNow = performance.now.bind(performance);

    function updatePerformanceNow(multiplier) {
        if (multiplier === 1) {
            performance.now = originalPerfNow;
            return;
        }

        performance.now = new Proxy(originalPerfNow, {
            apply(target, thisArg, argArray) {
                try {
                    throw new Error();
                } catch (e) {
                    if (!e.stack.includes("invoke_")) {
                        return target.apply(thisArg, argArray) * multiplier;
                    }
                }
                return target.apply(thisArg, argArray);
            },
        });
    }

    updatePerformanceNow(1);

    /***************************************
     * Invisibility + Instakill
     ***************************************/
    const Signatures = {
        damageTaken: "f3 04 c8 02 f5 15 04",
        updateState: "f3 02 fd 02 f4 03 c8",
    };

    function hexOf(buf) {
        return Array.from(new Uint8Array(buf))
            .map((b) => b.toString(16).padStart(2, "0"))
            .join(" ");
    }

    function shouldBlockDamage(ev) {
        return (
            ev.data instanceof ArrayBuffer &&
            hexOf(ev.data).startsWith(Signatures.damageTaken) &&
            kourInstance.config.Invisible
        );
    }

    /***************************************
     * AntiAim
     ***************************************/
    const HEADER_SIG = [0xf3, 0x02, 0xfd, 0x02, 0xf4, 0x03];
    const SAFE_MIN_LENGTH = 70;

    function arrayStartsWith(arr, prefix) {
        if (arr.length < prefix.length) return false;
        for (let i = 0; i < prefix.length; i++) {
            if (arr[i] !== prefix[i]) return false;
        }
        return true;
    }

    function isSafeToModify(packet) {
        return packet.byteLength >= SAFE_MIN_LENGTH && !kourInstance.config.Invisible && kourInstance.config.AntiAim;
    }

    function modifyPacket(packet) {
        const view = new DataView(packet.buffer, packet.byteOffset, packet.byteLength);

        let x = view.getFloat32(28, true);
        const xDelta = Math.random() < 0.5 ? -0.2 : 0.2;
        x += xDelta;
        view.setFloat32(28, x, true);

        let z = view.getFloat32(36, true);
        const zDelta = Math.random() < 0.5 ? -0.2 : 0.2;
        z += zDelta;
        view.setFloat32(36, z, true);

        //console.log(`[Packet Modified] X: ${x.toFixed(2)}, Z: ${z.toFixed(2)}`);

        return packet;
    }

    /***************************************
 * Spinbot Angle Modifier
 ***************************************/
    const crazyNumbers = [
        3822588238527201280.00, -1857736430059520.00, 0.00, -0.00, -1.4284511533486216e+24,
        -0.00, 0.00, 0.12, -1.8763868419170566e+22, 0.00, 556457979374085341184.00, 0.00,
        -228963383699832832.00, -0.00, 478289722746077184.00, 0.00, -1707527.88, 0.00,
        2.0849836473005435e+26, -0.00, 343366451878428672.00, -0.00, 0.00, -0.00, -398.99,
        -7.327271464138011e+37, -0.00, 7.479676797675635e+34, 6077727.50, -112678365030856523776.00,
        64406255347955662848.00, -0.00, 3.9367609144474995e+28, -0.68, -4.1272324222675643e+34,
        0.00, -34401746419712.00, 256284.98, -0.00, -992099.94, -46124.25, -0.00, -0.23,
        3573135.75, -0.00, 3.4937574108676156e+24, 31446140.00, -0.00, 0.00,
        -2.633920784508417e+22, 1.5002101046880594e+23, -662611.81, 0.00, -7.82,
        2.1554711763577515e+33, -4781238408011841536.00, -8.267893275317273e+33, -0.00, 0.00,
        -4.7050078084659084e+24, 63447551577279168512.00, 0.00, 5.614778816753592e+36, 5183327.50,
    ];

    let currentIndex = 0;
    const ANGLE_OFFSET = 0x38;

    /***************************************
     * WebSocket Hooking
     ***************************************/
    (function hookWS() {
        const OrigWS = unsafeWindow.WebSocket;
        unsafeWindow.WebSocket = function (...args) {
            const ws = new OrigWS(...args);

            const { addEventListener } = ws;
            ws.addEventListener = (type, fn, opts) =>
                addEventListener.call(
                    ws,
                    type,
                    type === "message" ? (ev) => shouldBlockDamage(ev) || fn(ev) : fn,
                    opts
                );

            const protoDesc = Object.getOwnPropertyDescriptor(OrigWS.prototype, "onmessage");
            Object.defineProperty(ws, "onmessage", {
                set(fn) {
                    protoDesc.set.call(this, (ev) => shouldBlockDamage(ev) || fn(ev));
                },
                get() {
                    return protoDesc.get.call(this);
                },
            });

            const originalSend = ws.send;
            ws.send = function (data) {
                if (data instanceof ArrayBuffer || data instanceof Uint8Array) {
                    let packet = data instanceof Uint8Array ? data : new Uint8Array(data);

                    const hex = hexOf(packet);

                    if (hex.startsWith(Signatures.updateState) && kourInstance.config.Instakill) {
                        for (let i = 0; i < 41; i++) originalSend.call(ws, data);
                        return;
                    }

                    if (arrayStartsWith(packet, HEADER_SIG)) {
                        if (isSafeToModify(packet)) {
                            packet = modifyPacket(packet);
                            data = packet.buffer;
                        }

                        if (kourInstance.config.SpinBot && packet.byteLength >= ANGLE_OFFSET + 4 && !kourInstance.config.Invisible) {
                            const view = new DataView(data);
                            const num = crazyNumbers[currentIndex];

                            view.setFloat32(ANGLE_OFFSET, num, true);

                            currentIndex++;
                            if (currentIndex >= crazyNumbers.length) currentIndex = 0;
                        }
                    }
                }

                return originalSend.call(this, data);
            };

            return ws;
        };

        unsafeWindow.WebSocket.prototype = OrigWS.prototype;
    })();

    /***************************************
     * Config Object
     ***************************************/
    class Kour {
        constructor() {
            this.config = {
                Invisible: true,
                Instakill: false,
                AntiAim: false,
                SpinBot: false,
                airStrafing: true,
            };
        }
    }

    const kourInstance = new Kour();
    unsafeWindow.kourInstance = kourInstance;

    /***************************************
   * Weapon Changer (Lobby Only!)
   ***************************************/
    const weapons = [
        { name: "AK-47", id: "0" },
        { name: "Deagle", id: "1" },
        { name: "AWP", id: "2" },
        { name: "Bayonet", id: "3" },
        { name: "Uzi", id: "4" },
        { name: "PKM", id: "5" },
        { name: "Revolver", id: "6" },
        { name: "RPG", id: "7" },
        { name: "USPS", id: "8" },
        { name: "MP5", id: "9" },
        { name: "Shotgun", id: "10" },
        { name: "Glock", id: "11" },
        { name: "Karambit", id: "12" },
        { name: "Knife", id: "13" },
        { name: "Scar", id: "14" },
        { name: "Minigun", id: "15" },
        { name: "Famas", id: "16" },
        { name: "Vector", id: "17" },
        { name: "Flamethrower", id: "18" },
        { name: "Kar98k", id: "19" },
        { name: "M4A4", id: "20" },
        { name: "Tec-9", id: "21" },
        { name: "CZ", id: "22" },
        { name: "Berretta92fs", id: "23" },
        { name: "AK-109", id: "24" },
        { name: "P90", id: "25" },
        { name: "Thompson", id: "26" },
        { name: "UMP45", id: "27" },
        { name: "XM1014", id: "28" },
        { name: "Butterfly", id: "29" },
        { name: "Laser Gun", id: "30" },
        { name: "Bomb", id: "31" },
        { name: "Smoke Grenade", id: "32" },
        { name: "Molotov", id: "33" },
        { name: "Grenade", id: "34" },
        { name: "Flashbang", id: "35" },
        { name: "Glizzy", id: "36" },
        { name: "Axe", id: "37" },
        { name: "Bare Fists", id: "38" },
    ];

    function setSecondaryWeapon(weaponID) {
        firebase
            .database()
            .ref("users/" + firebase.auth().currentUser.uid)
            .child("overrideWeaponIndexes1")
            .set(weaponID);
        showUserDetails(
            firebase.auth().currentUser.email,
            firebase.auth().currentUser
        );
    }

    function setMeleeWeapon(weaponID) {
        firebase
            .database()
            .ref("users/" + firebase.auth().currentUser.uid)
            .child("overrideWeaponIndexes2")
            .set(weaponID);
        showUserDetails(
            firebase.auth().currentUser.email,
            firebase.auth().currentUser
        );
    }

    /***************************************
   * Skin Changer (Lobby Only!)
   ***************************************/

    const skins = [
        { name: "KBI Agent", id: "12" },
        { name: "James Kour", id: "13" },
        { name: "President", id: "14" },
        { name: "Doctor", id: "15" },
        { name: "Trickster", id: "16" },
        { name: "Royal Guard", id: "17" },
        { name: "Xmas", id: "18" },
        { name: "Kelvis", id: "19" },
        { name: "Princess Pink", id: "20" },
        { name: "Princess White", id: "21" },
        { name: "Princess Bee", id: "22" },
        { name: "Princess Leaf", id: "23" },
        { name: "Koura Kraft", id: "24" },
        { name: "Green Hologram", id: "25" },
        { name: "Hologrape", id: "26" },
        { name: "Peter", id: "27" },
        { name: "Chicken", id: "28" },
        { name: "Chickoletta", id: "29" },
        { name: "Kyle", id: "30" },
        { name: "Shadowgram", id: "32" },
        { name: "IceBunny", id: "33" },
        { name: "CocoBunny", id: "34" },
        { name: "Kourean", id: "35" },
        { name: "KourG", id: "36" },
        { name: "Hackour", id: "37" },
        { name: "Golden Hackour", id: "38" },
        { name: "Gas Man", id: "39" },
        { name: "Terrorist", id: "40" },
        { name: "Counter Terrorist", id: "41" },
        { name: "Ambush", id: "42" },
        { name: "Baby Kour", id: "43" },
        { name: "Poacher", id: "44" },
        { name: "Astronaut", id: "45" },
        { name: "Kour Parrot", id: "46" },
        { name: "Kour Pirate", id: "47" },
        { name: "Legionaut", id: "48" },
        { name: "Blue Hologram", id: "49" },
        { name: "Mr Wireframe", id: "50" },
        { name: "Mythian", id: "51" },
        { name: "Kour Trooper", id: "52" },
        { name: "Kour Craft", id: "53" },
        { name: "Kour Green Soldier", id: "54" },
        { name: "Yellow Astronaut", id: "55" },
        { name: "Orange Astronaut", id: "56" },
        { name: "Red Astronaut", id: "57" },
        { name: "Blue Astronaut", id: "58" },
        { name: "Kour Banana", id: "59" },
        { name: "Mrs Kour", id: "60" },
        { name: "Investor Inverted", id: "61" },
        { name: "Kour Jungler", id: "62" },
        { name: "Skinny Baby", id: "63" },
        { name: "KourTuber", id: "64" },
        { name: "Red Hologram", id: "65" },
        { name: "White Hologram", id: "66" },
        { name: "Orange Hologram", id: "67" },
        { name: "Dark Blue Hologram", id: "68" },
        { name: "Brown Hologram", id: "69" },
        { name: "Yellow Hologram", id: "70" },
        { name: "Dark Red Hologram", id: "71" },
        { name: "Kourist", id: "72" },
        { name: "Firefighter", id: "73" },
        { name: "FireKour", id: "74" },
        { name: "Kour Thief", id: "75" },
        { name: "Kour Burger", id: "76" },
        { name: "Kour Fan", id: "77" },
        { name: "Kour Brady", id: "78" },
        { name: "LeKour James", id: "79" },
        { name: "Uncle Kour", id: "80" },
        { name: "Chef", id: "81" },
        { name: "KourObby", id: "82" },
        { name: "Legionary", id: "83" },
        { name: "Kitty Kour One", id: "84" },
        { name: "Kitty Kour Two", id: "85" },
        { name: "Kitty Kour Three", id: "86" },
        { name: "Kour Crafter", id: "87" },
        { name: "RTX", id: "88" },
        { name: "Loony Kour", id: "89" },
        { name: "Kour Shocker", id: "90" },
        { name: "Kourkin", id: "91" },
        { name: "Forest Kour", id: "92" },
        { name: "Slender Kour", id: "93" },
        { name: "Drakour", id: "94" },
        { name: "Christmas2024", id: "95" },
        { name: "Deer2024", id: "96" }
    ];

    function setSkin(skinID) {
        firebase
            .database()
            .ref("users/" + firebase.auth().currentUser.uid)
            .child("skin")
            .set(skinID);
        showUserDetails(
            firebase.auth().currentUser.email,
            firebase.auth().currentUser
        );
    }

    /***************************************
   * Profile Stats
   ***************************************/
    function setStat(stat, value) {
        const parsedValue = parseInt(value, 10);
        const finalValue = isNaN(parsedValue) ? value : parsedValue;
        firebase
            .database()
            .ref("users/" + firebase.auth().currentUser.uid + "/public")
            .child(stat)
            .set(finalValue);
        showUserDetails(
            firebase.auth().currentUser.email,
            firebase.auth().currentUser
        );
    }

    /***************************************
   * Clan Editing
   ***************************************/

    function overrideCreateClan() {
        if (typeof createClan === 'function') {
            createClan = function (clanName, leaderUserId, clanColor, reqID) {
                unityInstanceWrapper.sendMessage(firebaseObjName, 'OnSetDataNew', clanName + "&" + reqID);
            };
            //console.log("override done.");
        } else {
            setTimeout(overrideCreateClan, 500);
        }
    }

    overrideCreateClan();

    /***************************************
   * Class Kills
   ***************************************/
    const classMap = {
        Soldier: "class0kills",
        Hitman: "class1kills",
        Gunner: "class2kills",
        Heavy: "class3kills",
        Rocketeer: "class4kills",
        Agent: "class5kills",
        Brawler: "class6kills",
        Investor: "class7kills",
        Assassin: "class8kills",
        Juggernaut: "class9kills",
        Recon: "class10kills",
        Pyro: "class11kills",
        Rayblader: "class15kills",
    };

    function setClassKills() {
        const existingDialog = document.getElementById("classSelectionDialog");
        if (existingDialog) existingDialog.remove();

        const classSelectionDialog = document.createElement("div");
        classSelectionDialog.id = "classSelectionDialog";
        Object.assign(classSelectionDialog.style, {
            position: "fixed",
            top: "50%",
            left: "50%",
            transform: "translate(-50%, -50%)",
            backgroundColor: "#5a2d72",
            color: "#fff",
            padding: "20px",
            zIndex: "10002",
            fontFamily: "Arial, sans-serif",
            fontSize: "14px",
            borderRadius: "8px",
            boxShadow: "0 4px 8px rgba(0,0,0,0.2)",
            width: "300px",
            maxHeight: "400px",
            overflowY: "auto",
            cursor: "move",
            userSelect: "none",
        });

        const closeBtn = document.createElement("button");
        closeBtn.textContent = "×";
        closeBtn.style.position = "absolute";
        closeBtn.style.top = "5px";
        closeBtn.style.right = "5px";
        closeBtn.style.background = "none";
        closeBtn.style.border = "none";
        closeBtn.style.color = "#fff";
        closeBtn.style.fontSize = "16px";
        closeBtn.style.cursor = "pointer";
        closeBtn.addEventListener("click", () => classSelectionDialog.remove());
        classSelectionDialog.appendChild(closeBtn);

        const dialogTitle = document.createElement("div");
        dialogTitle.textContent = "Select Class";
        dialogTitle.style.fontWeight = "bold";
        dialogTitle.style.fontSize = "18px";
        dialogTitle.style.marginBottom = "15px";
        dialogTitle.style.textAlign = "center";
        classSelectionDialog.appendChild(dialogTitle);

        const classButtonContainer = document.createElement("div");
        classButtonContainer.style.display = "grid";
        classButtonContainer.style.gridTemplateColumns = "repeat(2, 1fr)";
        classButtonContainer.style.gap = "8px";

        Object.keys(classMap).forEach((className) => {
            const classBtn = document.createElement("button");
            classBtn.textContent = className;
            Object.assign(classBtn.style, {
                padding: "8px",
                cursor: "pointer",
                backgroundColor: "#9b3e9f",
                border: "none",
                borderRadius: "5px",
                fontSize: "13px",
                color: "#fff",
                transition: "background-color 0.3s",
            });

            classBtn.addEventListener(
                "mouseover",
                () => (classBtn.style.backgroundColor = "#a74cbf")
            );
            classBtn.addEventListener(
                "mouseout",
                () => (classBtn.style.backgroundColor = "#9b3e9f")
            );

            classBtn.addEventListener("click", () => {
                const killsValue = prompt(
                    `Enter kill count for ${className}:`,
                    "10000"
                );
                if (killsValue === null) return;

                const numKills = Number(killsValue);
                if (isNaN(numKills)) {
                    alert("Please enter a valid number!");
                    return;
                }

                const dbField = classMap[className];
                updateClassKills(dbField, numKills);
                classSelectionDialog.remove();
            });

            classButtonContainer.appendChild(classBtn);
        });

        classSelectionDialog.appendChild(classButtonContainer);

        const cancelBtn = document.createElement("button");
        cancelBtn.textContent = "Cancel";
        Object.assign(cancelBtn.style, {
            width: "100%",
            marginTop: "15px",
            padding: "8px",
            cursor: "pointer",
            backgroundColor: "#444",
            border: "none",
            borderRadius: "5px",
            color: "#fff",
        });
        cancelBtn.addEventListener("click", () => classSelectionDialog.remove());
        classSelectionDialog.appendChild(cancelBtn);

        let pos1 = 0,
            pos2 = 0,
            pos3 = 0,
            pos4 = 0;
        classSelectionDialog.onmousedown = dragMouseDown;

        function dragMouseDown(e) {
            if (e.target.tagName === "BUTTON" || e.target.tagName === "INPUT") {
                return;
            }

            e = e || window.event;
            e.preventDefault();
            pos3 = e.clientX;
            pos4 = e.clientY;
            document.onmouseup = closeDragElement;
            document.onmousemove = elementDrag;
        }

        function elementDrag(e) {
            e = e || window.event;
            e.preventDefault();
            pos1 = pos3 - e.clientX;
            pos2 = pos4 - e.clientY;
            pos3 = e.clientX;
            pos4 = e.clientY;
            classSelectionDialog.style.top =
                classSelectionDialog.offsetTop - pos2 + "px";
            classSelectionDialog.style.left =
                classSelectionDialog.offsetLeft - pos1 + "px";
            classSelectionDialog.style.transform = "none";
        }

        function closeDragElement() {
            document.onmouseup = null;
            document.onmousemove = null;
        }

        document.body.appendChild(classSelectionDialog);
    }

    function updateClassKills(classField, killCount) {
        if (!firebase.auth().currentUser) {
            console.log("[01 dev Menu] User is not logged in");
            return;
        }

        const updateData = {};
        updateData[classField] = killCount;

        firebase
            .database()
            .ref(`users/${firebase.auth().currentUser.uid}`)
            .update(updateData)
            .then(() => {
                showUserDetails(
                    firebase.auth().currentUser.email,
                    firebase.auth().currentUser
                );
                console.log(
                    `[01 dev Menu] ${classField} successfully updated to ${killCount}`
                );
                showUserDetails(
                    firebase.auth().currentUser.email,
                    firebase.auth().currentUser
                );
            })
            .catch((err) => {
                console.error(`[01 dev Menu] Failed to update ${classField}:`, err);
            });
    }

    /***************************************
   * Stats Changer
   ***************************************/
    function updateKDStats(kills) {
        if (!firebase.auth().currentUser) {
            console.log("[01 dev Menu] User is not logged in");
            alert("login first!");
            return;
        }

        const updateData = {
            totalKills: kills,
        };

        firebase
            .database()
            .ref(`users/${firebase.auth().currentUser.uid}`)
            .update(updateData)
            .then(() => {
                showUserDetails(
                    firebase.auth().currentUser.email,
                    firebase.auth().currentUser
                );
                console.log(
                    `[01 dev Menu] Stats updated to Kills:${kills}`
                );
            })
            .catch((err) => {
                console.error("[01 dev Menu] Failed to update stats:", err);
            });
    }

    function setKDStats() {
        const kills = prompt("Enter new Total Kills:", "1337");
        if (kills === null) return;
        const parsedKills = Number(kills);

        if (isNaN(parsedKills)) {
            alert("Please enter valid numbers for kills.");
            return;
        }

        updateKDStats(parsedKills);
    }


    /***************************************
   * Air strafing
   ***************************************/

    let spaceHeld = false;
    let turningLeft = false;
    let turningRight = false;

    let lastMoveTime = 0;
    const activeTimeout = 150;

    document.addEventListener('mousemove', e => {
        if (e.movementX < 0) {
            turningLeft = true;
            turningRight = false;
        } else if (e.movementX > 0) {
            turningRight = true;
            turningLeft = false;
        }
        lastMoveTime = Date.now();
    });

    document.addEventListener('keydown', e => {
        if (e.code === 'Space') spaceHeld = true;
    });

    document.addEventListener('keyup', e => {
        if (e.code === 'Space') spaceHeld = false;
    });

    function simulateKey(code, down = true) {
        const event = new KeyboardEvent(down ? 'keydown' : 'keyup', {
            code: code,
            key: code.replace('Key', ''),
            keyCode: code === 'KeyA' ? 65 : 68,
            which: code === 'KeyA' ? 65 : 68,
            bubbles: true,
            cancelable: true,
        });
        document.dispatchEvent(event);
    }

    let aHeld = false;
    let dHeld = false;

    function loop() {
        const now = Date.now();
        const mouseActive = (now - lastMoveTime) < activeTimeout;
        if (kourInstance.config.airStrafing) {
            if (spaceHeld && mouseActive) {
                if (turningLeft && !aHeld) {
                    simulateKey('KeyA', true);
                    aHeld = true;
                } else if (!turningLeft && aHeld) {
                    simulateKey('KeyA', false);
                    aHeld = false;
                }

                if (turningRight && !dHeld) {
                    simulateKey('KeyD', true);
                    dHeld = true;
                } else if (!turningRight && dHeld) {
                    simulateKey('KeyD', false);
                    dHeld = false;
                }
            } else {
                if (aHeld) {
                    simulateKey('KeyA', false);
                    aHeld = false;
                }
                if (dHeld) {
                    simulateKey('KeyD', false);
                    dHeld = false;
                }
            }

            requestAnimationFrame(loop);
        }
    }

    loop();

    /***************************************
   * ESP
   ***************************************/

    let gl = null;
    const filters = [
        { min: 1481, max: 1483 }, // normal
        { min: 1553, max: 1555 }, // princess
        { min: 5615, max: 5617 }, // RTX
        { min: 3875, max: 3877 }, // Egg
        //{ min: 239, max: 240},      // Map Secret
    ];

    window.espEnabled = true;

    window.addEventListener("keydown", (e) => {
        if (e.key.toLowerCase() === "p") {
            window.espEnabled = !window.espEnabled;
            const espCheckbox = document.getElementById("espToggle");
            if (espCheckbox) espCheckbox.checked = window.espEnabled;
            console.log(`[01 dev Menu] Toggled ${window.espEnabled ? "ON" : "OFF"}`);
        }
    });

    const WebGL = WebGL2RenderingContext.prototype;

    HTMLCanvasElement.prototype.getContext = new Proxy(
        HTMLCanvasElement.prototype.getContext,
        {
            apply(target, thisArgs, args) {
                if (args[1]) {
                    args[1].preserveDrawingBuffer = true;
                }
                return Reflect.apply(...arguments);
            },
        }
    );

    try {
        window.espColor = JSON.parse(localStorage.getItem("espColorRGB")) || { r: 0, g: 0, b: 0 };
    } catch {
        window.espColor = { r: 0, g: 0, b: 0 };
    }

    const drawHandler = {
        apply(target, thisArgs, args) {
            const count = args[1];
            const blockarms = document.getElementById("blockarms");
            if (count === 300 && settings.crosshairEnabled) {
                return;
            }
            if (count === 24 && settings.damagenumbersoff) {
                return;
            }
            if (blockarms && blockarms.checked && count === 1098) {
                return;
            }
            const program = thisArgs.getParameter(thisArgs.CURRENT_PROGRAM);
            if (!program.uniforms) {
                program.uniforms = {
                    vertexCount: thisArgs.getUniformLocation(program, "vertexCount"),
                    espToggle: thisArgs.getUniformLocation(program, "espToggle"),
                    gnilgnim: thisArgs.getUniformLocation(program, "gnilgnim"),
                    espColor: thisArgs.getUniformLocation(program, "espColor"),
                };
            }

            if (program.uniforms.vertexCount) {
                thisArgs.uniform1f(program.uniforms.vertexCount, count);
            }
            if (program.uniforms.espToggle) {
                thisArgs.uniform1f(program.uniforms.espToggle, window.espEnabled ? 1.0 : 0.0);
            }
            if (program.uniforms.gnilgnim) {
                thisArgs.uniform1f(program.uniforms.gnilgnim, 13371337.0);
            }
            if (program.uniforms.espColor && window.espColor) {
                const { r, g, b } = window.espColor;
                thisArgs.uniform3f(program.uniforms.espColor, r / 255, g / 255, b / 255);
            }

            gl = thisArgs;
            return Reflect.apply(...arguments);
        },
    };

    WebGL.drawElements = new Proxy(WebGL.drawElements, drawHandler);
    WebGL.drawElementsInstanced = new Proxy(WebGL.drawElementsInstanced, drawHandler);

    function generateRangeConditions(varName) {
        return filters
            .map(({ min, max }) => `(${varName} >= ${min}.0 && ${varName} <= ${max}.0)`)
            .join(" || ");
    }

    WebGL.shaderSource = new Proxy(WebGL.shaderSource, {
        apply(target, thisArgs, args) {
            let [shader, src] = args;

            if (src.includes("gl_Position")) {
                const conditions = generateRangeConditions("vertexCount");
                src = src.replace(
                    /void\s+main\s*\(\s*\)\s*\{/,
                    `uniform float vertexCount;\nuniform float espToggle;\nuniform float gnilgnim;\nout float vVertexCount;\nuniform vec3 espColor;\nvoid main() {\nvVertexCount = vertexCount;\n`
                );
                src = src.replace(
                    /(gl_Position\s*=.+;)/,
                    `$1\nif (espToggle > 0.5 && (${conditions})) {\n  gl_Position.z = 0.01 + gl_Position.z * 0.1;\n}\nif (espToggle > 0.5 && gnilgnim == 13371337.0) {\n  gl_Position.z *= 1.0;\n}`
                );
            }

            if (src.includes("SV_Target0")) {
                const conditions = generateRangeConditions("vVertexCount");
                src = src
                    .replace(
                        /void\s+main\s*\(\s*\)\s*\{/,
                        `uniform float espToggle;\nuniform float gnilgnim;\nin float vVertexCount;\nuniform vec3 espColor;\nvoid main() {`
                    )
                    .replace(
                        /return;/,
                        `if (espToggle > 0.5 && (${conditions}) && SV_Target0.a > 0.5) {\n  SV_Target0 = vec4(espColor, 1.0);\n}\nif (gnilgnim == 13371337.0) {\n  SV_Target0.rgb *= 1.0;\n}\nreturn;`
                    );
            }

            args[1] = src;
            return Reflect.apply(...arguments);
        },
    });

    /***************************************
   * Color Aimbot
   ***************************************/

    let fovCircleEnabled = true;
    window.fovColor = 'rgba(168, 85, 247, 0.6)';

    const fovCanvas = document.createElement('canvas');
    fovCanvas.style.position = 'fixed';
    fovCanvas.style.top = '0';
    fovCanvas.style.left = '0';
    fovCanvas.style.pointerEvents = 'none';
    fovCanvas.style.zIndex = '9999';
    document.body.appendChild(fovCanvas);

    const fovCtx = fovCanvas.getContext('2d');

    function resizeCanvas() {
        fovCanvas.width = window.innerWidth;
        fovCanvas.height = window.innerHeight;
    }
    resizeCanvas();
    window.addEventListener('resize', resizeCanvas);

    let fovRadius = 80;

    function drawFOVCircle() {
        fovCtx.clearRect(0, 0, fovCanvas.width, fovCanvas.height);
        if (!fovCircleEnabled) return;
        const centerX = fovCanvas.width / 2;
        const centerY = fovCanvas.height / 2;

        fovCtx.beginPath();
        fovCtx.arc(centerX, centerY, fovRadius, 0, Math.PI * 2);
        fovCtx.strokeStyle = window.fovColor || 'rgba(168, 85, 247, 0.6)';
        fovCtx.lineWidth = 2;
        fovCtx.stroke();
    }

    const settings = {
        aimbotEnabled: true,
        aimbotSpeed: 1.2,
        aimbotTriggerButton: ['left', 'right'],
        crosshairEnabled: false,
        triggerbotEnabled: true,
        damagenumbersoff: false,
        aimbotMode: "hold",
    };

    let mouseButtons = { left: false, right: false };

    document.addEventListener("mousedown", (e) => {
        if (e.button === 0) mouseButtons.left = true;
        if (e.button === 2) mouseButtons.right = true;
    });
    document.addEventListener("mouseup", (e) => {
        if (e.button === 0) mouseButtons.left = false;
        if (e.button === 2) mouseButtons.right = false;
    });

    function isTriggerPressed() {
        if (settings.aimbotMode === "always") return true;
        return settings.aimbotTriggerButton.some(btn => mouseButtons[btn]);
    }

    function isTargetPixel(r, g, b, a, t, c) {
        if (a === 0) return false;

        const dr = r - c.r;
        const dg = g - c.g;
        const db = b - c.b;

        return (dr * dr + dg * dg + db * db) <= (t * t);
    }

    function updateAimbot() {
        drawFOVCircle();
        if (!settings.aimbotEnabled || !gl || !gl.canvas || !gl.readPixels || !isTriggerPressed()) return;

        const width = Math.min(150, gl.canvas?.width || 0);
        const height = Math.min(150, gl.canvas?.height || 0);
        if (width < 10 || height < 10) {
            return;
        }
        const t = 20;
        const c = window.espColor;

        const centerX = gl.canvas.width / 2;
        const centerY = gl.canvas.height / 2;
        const startX = Math.floor(centerX - width / 2);
        const startY = Math.floor(centerY - height / 2);
        const pixels = new Uint8Array(width * height * 4);

        gl.readPixels(startX, startY, width, height, gl.RGBA, gl.UNSIGNED_BYTE, pixels);

        let closestDist = Infinity;
        let bestDX = 0;
        let bestDY = 0;
        let targetCount = 0;
        //console.log(window.espColor);
        for (let i = 0; i < pixels.length; i += 4) {
            const r = pixels[i], g = pixels[i + 1], b = pixels[i + 2], a = pixels[i + 3];
            if (isTargetPixel(r, g, b, a, t, c)) {
                targetCount++;
                const index = i / 4;
                const x = index % width;
                const y = Math.floor(index / width);
                const dx = startX + x - centerX;
                const dy = -(startY + y - centerY);
                const dist = Math.hypot(dx, dy);
                if (fovCircleEnabled) {
                    if (dist > fovRadius) continue;
                }
                const gnilgnim = "signature Start X - Y";
                if (dist < closestDist) {
                    closestDist = dist;
                    bestDX = dx;
                    bestDY = dy;
                }
            }
        }

        if (closestDist < Infinity) {
            //console.log("moving");
            const factor = settings.aimbotSpeed;
            gl.canvas.dispatchEvent(new MouseEvent("mousemove", {
                movementX: bestDX * factor,
                movementY: bestDY * factor,
                bubbles: true,
                cancelable: true,
                composed: true,
            }));
        }
    }

    setInterval(updateAimbot, 0);

    function createUI() {
        // Load font
        const fontLink = document.createElement("link");
        fontLink.rel = "stylesheet";
        fontLink.href = "https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&display=swap";
        document.head.appendChild(fontLink);

        // Load custom styles
        const style = document.createElement("style");
        style.textContent = `
        @import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&display=swap');

        .zeph-dashboard {
            --bg-main: rgba(18, 12, 28, 0.82);
            --bg-panel: rgba(255, 255, 255, 0.03);
            --border-color: rgba(255, 255, 255, 0.08);
            --border-hover: rgba(255, 255, 255, 0.16);
            --accent-purple: #a855f7;
            --accent-pink: #ec4899;
            --accent-gradient: linear-gradient(135deg, var(--accent-purple), var(--accent-pink));
            --accent-gradient-hover: linear-gradient(135deg, #b55fe6, #f43f5e);
            --text-primary: #ffffff;
            --text-secondary: rgba(255, 255, 255, 0.7);
            --text-muted: rgba(255, 255, 255, 0.45);
            
            position: fixed;
            width: 660px;
            height: 490px;
            display: flex;
            flex-direction: column;
            background: var(--bg-main);
            backdrop-filter: blur(20px) saturate(140%);
            -webkit-backdrop-filter: blur(20px) saturate(140%);
            border-radius: 12px;
            border: 1px solid var(--border-color);
            box-shadow: 0 24px 60px rgba(0, 0, 0, 0.65), inset 0 1px 0 rgba(255, 255, 255, 0.1);
            color: var(--text-primary);
            font-family: 'Outfit', sans-serif;
            font-size: 13.5px;
            user-select: none;
            -webkit-user-select: none;
            z-index: 100000;
            overflow: hidden;
            transition: opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1), transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
        }

        /* Color Themes */
        .zeph-dashboard.theme-cyan {
            --accent-purple: #06b6d4;
            --accent-pink: #3b82f6;
            --accent-gradient: linear-gradient(135deg, #06b6d4, #3b82f6);
            --accent-gradient-hover: linear-gradient(135deg, #0891b2, #2563eb);
        }
        .zeph-dashboard.theme-green {
            --accent-purple: #10b981;
            --accent-pink: #14b8a6;
            --accent-gradient: linear-gradient(135deg, #10b981, #14b8a6);
            --accent-gradient-hover: linear-gradient(135deg, #059669, #0d9488);
        }
        .zeph-dashboard.theme-red {
            --accent-purple: #ef4444;
            --accent-pink: #f43f5e;
            --accent-gradient: linear-gradient(135deg, #ef4444, #f43f5e);
            --accent-gradient-hover: linear-gradient(135deg, #dc2626, #e11d48);
        }
        .zeph-dashboard.theme-gold {
            --accent-purple: #eab308;
            --accent-pink: #f97316;
            --accent-gradient: linear-gradient(135deg, #eab308, #f97316);
            --accent-gradient-hover: linear-gradient(135deg, #ca8a04, #ea580c);
        }

        .zeph-dashboard.hidden {
            opacity: 0;
            transform: scale(0.96);
            pointer-events: none;
        }

        .zeph-titlebar {
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 14px 20px;
            background: rgba(0, 0, 0, 0.2);
            border-bottom: 1px solid var(--border-color);
            cursor: move;
        }

        .zeph-logo-container {
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .zeph-logo-img {
            width: 24px;
            height: 24px;
            border-radius: 4px;
        }

        .zeph-title-text {
            background: var(--accent-gradient);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            font-weight: 700;
            font-size: 18px;
            letter-spacing: 0.5px;
        }

        .zeph-titlebar-right {
            display: flex;
            align-items: center;
            gap: 12px;
        }

        .zeph-discord-icon {
            width: 20px;
            height: 20px;
            cursor: pointer;
            opacity: 0.8;
            transition: all 0.2s ease;
        }

        .zeph-discord-icon:hover {
            opacity: 1;
            transform: scale(1.1);
        }

        .zeph-body {
            display: flex;
            flex: 1;
            overflow: hidden;
            height: calc(100% - 49px);
        }

        .zeph-sidebar {
            width: 170px;
            background: rgba(0, 0, 0, 0.12);
            border-right: 1px solid var(--border-color);
            display: flex;
            flex-direction: column;
            padding: 12px 8px;
            gap: 4px;
            overflow-y: auto;
        }

        .zeph-tab-btn {
            display: flex;
            align-items: center;
            gap: 10px;
            padding: 10px 14px;
            border-radius: 8px;
            border: none;
            background: transparent;
            color: var(--text-secondary);
            cursor: pointer;
            text-align: left;
            font-size: 13.5px;
            font-weight: 500;
            font-family: inherit;
            transition: all 0.2s ease;
            border-left: 3px solid transparent;
        }

        .zeph-tab-btn:hover {
            color: var(--text-primary);
            background: rgba(255, 255, 255, 0.04);
        }

        .zeph-tab-btn.active {
            color: var(--text-primary);
            background: rgba(255, 255, 255, 0.07);
            font-weight: 600;
            border-left-color: var(--accent-purple);
        }

        .zeph-content {
            flex: 1;
            padding: 20px 24px;
            overflow-y: auto;
            display: flex;
            flex-direction: column;
            background: rgba(255, 255, 255, 0.01);
        }

        .zeph-panel {
            display: none;
            flex-direction: column;
            gap: 14px;
            animation: zephFadeIn 0.2s ease;
        }

        .zeph-panel.active {
            display: flex;
        }

        @keyframes zephFadeIn {
            from { opacity: 0; transform: translateY(4px); }
            to { opacity: 1; transform: translateY(0); }
        }

        .zeph-section-header {
            font-size: 11px;
            text-transform: uppercase;
            letter-spacing: 1.5px;
            color: var(--accent-purple);
            font-weight: 700;
            margin-bottom: 6px;
            opacity: 0.95;
        }

        .zeph-row {
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 10px 14px;
            border-radius: 8px;
            background: var(--bg-panel);
            border: 1px solid rgba(255, 255, 255, 0.02);
            transition: border-color 0.2s ease, background 0.2s ease;
        }

        .zeph-row:hover {
            border-color: var(--border-hover);
            background: rgba(255, 255, 255, 0.05);
        }

        .zeph-label-group {
            display: flex;
            flex-direction: column;
            gap: 2px;
        }

        .zeph-label-title {
            font-weight: 500;
            color: var(--text-primary);
        }

        .zeph-label-desc {
            font-size: 11px;
            color: var(--text-muted);
        }

        .zeph-switch {
            position: relative;
            display: inline-block;
            width: 40px;
            height: 20px;
        }

        .zeph-switch input {
            opacity: 0;
            width: 0;
            height: 0;
        }

        .zeph-slider {
            position: absolute;
            cursor: pointer;
            top: 0; left: 0; right: 0; bottom: 0;
            background-color: rgba(255, 255, 255, 0.1);
            transition: .25s ease;
            border-radius: 20px;
            border: 1px solid rgba(255, 255, 255, 0.05);
        }

        .zeph-slider:before {
            position: absolute;
            content: "";
            height: 14px;
            width: 14px;
            left: 2px;
            bottom: 2px;
            background-color: #fff;
            transition: .25s ease;
            border-radius: 50%;
        }

        .zeph-switch input:checked + .zeph-slider {
            background: var(--accent-gradient);
            border-color: transparent;
            box-shadow: 0 0 10px rgba(168, 85, 247, 0.45);
        }

        .zeph-switch input:checked + .zeph-slider:before {
            transform: translateX(20px);
        }

        .zeph-slider-container {
            display: flex;
            flex-direction: column;
            gap: 8px;
            width: 100%;
        }

        .zeph-slider-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            width: 100%;
        }

        .zeph-slider-val {
            font-weight: 600;
            color: var(--accent-pink);
            font-size: 13px;
        }

        .zeph-slider-input {
            -webkit-appearance: none;
            appearance: none;
            width: 100%;
            height: 5px;
            border-radius: 3px;
            background: rgba(255, 255, 255, 0.1);
            outline: none;
            transition: background 0.2s;
        }

        .zeph-slider-input::-webkit-slider-thumb {
            -webkit-appearance: none;
            appearance: none;
            width: 14px;
            height: 14px;
            border-radius: 50%;
            background: #fff;
            cursor: pointer;
            box-shadow: 0 0 10px rgba(168, 85, 247, 0.8);
            transition: transform 0.1s ease;
        }

        .zeph-slider-input::-webkit-slider-thumb:hover {
            transform: scale(1.25);
        }

        .zeph-btn {
            background: var(--accent-gradient);
            border: none;
            border-radius: 8px;
            color: #fff;
            padding: 8px 14px;
            font-weight: 600;
            cursor: pointer;
            font-family: inherit;
            font-size: 13px;
            transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
            box-shadow: 0 4px 10px rgba(168, 85, 247, 0.25);
            display: inline-flex;
            align-items: center;
            justify-content: center;
        }

        .zeph-btn:hover {
            background: var(--accent-gradient-hover);
            transform: translateY(-1.5px);
            box-shadow: 0 6px 14px rgba(168, 85, 247, 0.4);
        }

        .zeph-btn:active {
            transform: translateY(0);
            box-shadow: 0 2px 6px rgba(168, 85, 247, 0.25);
        }

        .zeph-btn-secondary {
            background: rgba(255, 255, 255, 0.06);
            border: 1px solid var(--border-color);
            box-shadow: none;
        }

        .zeph-btn-secondary:hover {
            background: rgba(255, 255, 255, 0.12);
            border-color: rgba(255, 255, 255, 0.2);
            transform: translateY(-1px);
            box-shadow: none;
        }

        .zeph-select-container {
            position: relative;
            width: 170px;
        }

        .zeph-select-input {
            width: 100%;
            background: rgba(0, 0, 0, 0.25);
            border: 1px solid var(--border-color);
            border-radius: 6px;
            color: var(--text-primary);
            padding: 6px 10px;
            font-size: 12.5px;
            outline: none;
            font-family: inherit;
            transition: border-color 0.2s ease;
            box-sizing: border-box;
        }

        .zeph-select-input:focus {
            border-color: var(--accent-purple);
            box-shadow: 0 0 6px rgba(168, 85, 247, 0.25);
        }

        .zeph-select-options {
            position: absolute;
            top: 100%;
            left: 0;
            right: 0;
            margin-top: 4px;
            max-height: 180px;
            overflow-y: auto;
            background: rgba(20, 16, 28, 0.96);
            border: 1px solid var(--border-color);
            border-radius: 6px;
            box-shadow: 0 10px 25px rgba(0,0,0,0.5);
            z-index: 100002;
            display: none;
        }

        .zeph-select-options.open {
            display: block;
        }

        .zeph-select-option {
            padding: 6px 10px;
            font-size: 12.5px;
            cursor: pointer;
            color: var(--text-secondary);
            transition: background 0.15s ease, color 0.15s ease;
        }

        .zeph-select-option:hover {
            background: rgba(255, 255, 255, 0.08);
            color: var(--text-primary);
        }

        .zeph-select-option.selected {
            background: var(--accent-gradient);
            color: #fff;
        }

        .zeph-dashboard *::-webkit-scrollbar {
            width: 5px;
        }
        .zeph-dashboard *::-webkit-scrollbar-track {
            background: transparent;
        }
        .zeph-dashboard *::-webkit-scrollbar-thumb {
            background: rgba(255, 255, 255, 0.15);
            border-radius: 4px;
        }
        .zeph-dashboard *::-webkit-scrollbar-thumb:hover {
            background: rgba(255, 255, 255, 0.3);
        }

        .zeph-modal-overlay {
            position: absolute;
            top: 0; left: 0; right: 0; bottom: 0;
            background: rgba(10, 8, 15, 0.75);
            backdrop-filter: blur(6px);
            -webkit-backdrop-filter: blur(6px);
            display: flex;
            align-items: center;
            justify-content: center;
            z-index: 100005;
            opacity: 0;
            pointer-events: none;
            transition: opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1);
        }

        .zeph-modal-overlay.open {
            opacity: 1;
            pointer-events: auto;
        }

        .zeph-modal {
            background: rgba(25, 18, 38, 0.95);
            border: 1px solid rgba(255, 255, 255, 0.1);
            border-radius: 12px;
            padding: 20px;
            width: 320px;
            display: flex;
            flex-direction: column;
            gap: 16px;
            box-shadow: 0 24px 60px rgba(0, 0, 0, 0.65);
            transform: scale(0.9);
            transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
        }

        .zeph-modal-overlay.open .zeph-modal {
            transform: scale(1);
        }

        .zeph-modal-title {
            font-weight: 700;
            font-size: 15px;
            color: var(--text-primary);
            margin-bottom: -4px;
        }

        .zeph-modal-input {
            width: 100%;
            background: rgba(0, 0, 0, 0.3);
            border: 1px solid var(--border-color);
            border-radius: 6px;
            color: var(--text-primary);
            padding: 8px 12px;
            font-size: 13px;
            outline: none;
            font-family: inherit;
            transition: border-color 0.2s ease;
            box-sizing: border-box;
        }

        .zeph-modal-input:focus {
            border-color: var(--accent-purple);
        }

        .zeph-modal-actions {
            display: flex;
            justify-content: flex-end;
            gap: 10px;
        }

        .zeph-madeby {
            font-size: 11px;
            text-align: center;
            margin-bottom: 5px;
            font-weight: bold;
            letter-spacing: 0.5px;
        }

        .zeph-grid-2 {
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            gap: 10px;
        }

        .zeph-watermark {
            position: fixed;
            top: 15px;
            left: 15px;
            padding: 8px 14px;
            background: rgba(18, 12, 28, 0.75);
            backdrop-filter: blur(12px) saturate(120%);
            -webkit-backdrop-filter: blur(12px) saturate(120%);
            border: 1px solid rgba(255, 255, 255, 0.08);
            border-radius: 8px;
            box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
            color: #fff;
            font-family: 'Outfit', sans-serif;
            font-size: 12.5px;
            font-weight: 600;
            letter-spacing: 0.5px;
            z-index: 99998;
            pointer-events: none;
            display: flex;
            align-items: center;
            gap: 8px;
            transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        }
        .zeph-watermark.hidden {
            opacity: 0;
        }
        .zeph-watermark-dot {
            width: 7px;
            height: 7px;
            background: var(--accent-purple, #a855f7);
            border-radius: 50%;
            box-shadow: 0 0 10px var(--accent-purple, #a855f7);
        }
        `;
        document.head.appendChild(style);

        // Main Dashboard
        const menu = document.createElement("div");
        menu.id = "zephMenu";
        menu.className = "zeph-dashboard hidden"; // Start hidden

        // Apply saved theme
        let savedTheme = localStorage.getItem("zephMenuTheme") || "purple";
        const themeColors = {
            purple: "rgba(168, 85, 247, 0.6)",
            cyan: "rgba(6, 182, 212, 0.6)",
            green: "rgba(16, 185, 129, 0.6)",
            red: "rgba(239, 68, 68, 0.6)",
            gold: "rgba(234, 179, 8, 0.6)"
        };
        window.fovColor = themeColors[savedTheme] || themeColors.purple;

        if (savedTheme !== "purple") {
            menu.classList.add("theme-" + savedTheme);
        }

        // Menu position from LocalStorage
        let posX = localStorage.getItem("zephMenuX") || "100";
        let posY = localStorage.getItem("zephMenuY") || "100";
        menu.style.left = posX + "px";
        menu.style.top = posY + "px";

        // Title Bar
        const titlebar = document.createElement("div");
        titlebar.className = "zeph-titlebar";

        const logoContainer = document.createElement("div");
        logoContainer.className = "zeph-logo-container";

        const logo = document.createElement("img");
        logo.src = "https://cdn.pfps.gg/pfps/30968-pomni-pfp.png";
        logo.className = "zeph-logo-img";
        logoContainer.appendChild(logo);

        const titleText = document.createElement("div");
        titleText.className = "zeph-title-text";
        titleText.textContent = "01 dev Menu";
        logoContainer.appendChild(titleText);
        titlebar.appendChild(logoContainer);

        const titlebarRight = document.createElement("div");
        titlebarRight.className = "zeph-titlebar-right";

        const discordLogo = document.createElement("img");
        discordLogo.src = "https://i.ibb.co/sJV6y56H/Zeph-Menu-Discordlogo.png";
        discordLogo.className = "zeph-discord-icon";
        discordLogo.alt = "Discord";
        discordLogo.addEventListener("click", () => window.open("https://discord.gg/YTeRSG8kER", "_blank"));
        titlebarRight.appendChild(discordLogo);
        titlebar.appendChild(titlebarRight);

        menu.appendChild(titlebar);

        // Main Body Layout
        const body = document.createElement("div");
        body.className = "zeph-body";

        const sidebar = document.createElement("div");
        sidebar.className = "zeph-sidebar";

        const content = document.createElement("div");
        content.className = "zeph-content";

        body.appendChild(sidebar);
        body.appendChild(content);
        menu.appendChild(body);

        // Custom Modal Overlay inside dashboard
        const modalOverlay = document.createElement("div");
        modalOverlay.id = "zephModalOverlay";
        modalOverlay.className = "zeph-modal-overlay";
        menu.appendChild(modalOverlay);

        // Helper: dynamic modal rendering
        function showModalCustom(title, contentHTML, onConfirm, onRender = null) {
            modalOverlay.innerHTML = "";

            const modal = document.createElement("div");
            modal.className = "zeph-modal";

            const titleDiv = document.createElement("div");
            titleDiv.className = "zeph-modal-title";
            titleDiv.textContent = title;
            modal.appendChild(titleDiv);

            const bodyDiv = document.createElement("div");
            bodyDiv.style.display = "flex";
            bodyDiv.style.flexDirection = "column";
            bodyDiv.style.gap = "12px";
            bodyDiv.innerHTML = contentHTML;
            modal.appendChild(bodyDiv);

            const actions = document.createElement("div");
            actions.className = "zeph-modal-actions";

            const cancelBtn = document.createElement("button");
            cancelBtn.className = "zeph-btn zeph-btn-secondary";
            cancelBtn.textContent = "Cancel";
            cancelBtn.addEventListener("click", () => {
                modalOverlay.classList.remove("open");
            });

            const confirmBtn = document.createElement("button");
            confirmBtn.className = "zeph-btn";
            confirmBtn.textContent = "Confirm";
            confirmBtn.addEventListener("click", () => {
                if (onConfirm(bodyDiv)) {
                    modalOverlay.classList.remove("open");
                }
            });

            actions.appendChild(cancelBtn);
            actions.appendChild(confirmBtn);
            modal.appendChild(actions);
            overlayCloseClickRegister(modal);
            modalOverlay.appendChild(modal);

            modalOverlay.classList.add("open");
            if (onRender) onRender(bodyDiv);
        }

        function overlayCloseClickRegister(modal) {
            modal.addEventListener("click", (e) => e.stopPropagation());
        }
        modalOverlay.addEventListener("click", () => modalOverlay.classList.remove("open"));

        // Helper: search dropdown
        function createSearchDropdown(labelText, itemsArray, currentValue, onSelect) {
            const container = document.createElement("div");
            container.className = "zeph-row";

            const labelGroup = document.createElement("div");
            labelGroup.className = "zeph-label-group";
            const labelTitle = document.createElement("div");
            labelTitle.className = "zeph-label-title";
            labelTitle.textContent = labelText;
            labelGroup.appendChild(labelTitle);
            container.appendChild(labelGroup);

            const selectContainer = document.createElement("div");
            selectContainer.className = "zeph-select-container";

            const input = document.createElement("input");
            input.type = "text";
            input.className = "zeph-select-input";

            const initialItem = itemsArray.find(item => item.id === String(currentValue));
            input.placeholder = initialItem ? initialItem.name : "Select...";

            const optionsList = document.createElement("div");
            optionsList.className = "zeph-select-options";

            function renderOptions(filterText = "") {
                optionsList.innerHTML = "";
                const filtered = itemsArray.filter(item =>
                    item.name.toLowerCase().includes(filterText.toLowerCase())
                );

                filtered.forEach(item => {
                    const opt = document.createElement("div");
                    opt.className = "zeph-select-option";
                    if (String(currentValue) === item.id) opt.classList.add("selected");
                    opt.textContent = `${item.name} (${item.id})`;
                    opt.addEventListener("mousedown", (e) => {
                        e.preventDefault();
                        currentValue = item.id;
                        input.value = "";
                        input.placeholder = item.name;
                        onSelect(item.id);
                        optionsList.classList.remove("open");
                        input.blur();
                    });
                    optionsList.appendChild(opt);
                });

                if (filtered.length === 0) {
                    const noOpt = document.createElement("div");
                    noOpt.className = "zeph-select-option";
                    noOpt.style.color = "var(--text-muted)";
                    noOpt.style.cursor = "default";
                    noOpt.textContent = "No results found";
                    optionsList.appendChild(noOpt);
                }
            }

            input.addEventListener("focus", () => {
                renderOptions(input.value);
                optionsList.classList.add("open");
            });

            input.addEventListener("blur", () => {
                setTimeout(() => {
                    optionsList.classList.remove("open");
                }, 150);
            });

            input.addEventListener("input", () => {
                renderOptions(input.value);
            });

            selectContainer.appendChild(input);
            selectContainer.appendChild(optionsList);
            container.appendChild(selectContainer);

            return container;
        }

        // Helper: Toggle Switch
        function createSwitchToggle(labelText, labelDesc, checked, onChange, customId = null) {
            const row = document.createElement("div");
            row.className = "zeph-row";

            const labelGroup = document.createElement("div");
            labelGroup.className = "zeph-label-group";

            const title = document.createElement("div");
            title.className = "zeph-label-title";
            title.textContent = labelText;
            labelGroup.appendChild(title);

            if (labelDesc) {
                const desc = document.createElement("div");
                desc.className = "zeph-label-desc";
                desc.textContent = labelDesc;
                labelGroup.appendChild(desc);
            }

            row.appendChild(labelGroup);

            const label = document.createElement("label");
            label.className = "zeph-switch";

            const input = document.createElement("input");
            input.type = "checkbox";
            input.checked = checked;
            if (customId) input.id = customId;
            input.addEventListener("change", (e) => onChange(e.target.checked));

            const slider = document.createElement("span");
            slider.className = "zeph-slider";

            label.appendChild(input);
            label.appendChild(slider);
            row.appendChild(label);

            return row;
        }

        // Helper: Slider
        function createSlider(labelText, min, max, step, currentValue, unit, onChange) {
            const row = document.createElement("div");
            row.className = "zeph-row";

            const container = document.createElement("div");
            container.className = "zeph-slider-container";

            const header = document.createElement("div");
            header.className = "zeph-slider-header";

            const label = document.createElement("span");
            label.className = "zeph-label-title";
            label.textContent = labelText;
            header.appendChild(label);

            const valSpan = document.createElement("span");
            valSpan.className = "zeph-slider-val";
            valSpan.textContent = currentValue + unit;
            header.appendChild(valSpan);

            container.appendChild(header);

            const slider = document.createElement("input");
            slider.type = "range";
            slider.className = "zeph-slider-input";
            slider.min = min;
            slider.max = max;
            slider.step = step;
            slider.value = currentValue;

            slider.addEventListener("input", (e) => {
                const val = parseFloat(e.target.value);
                valSpan.textContent = val + unit;
                onChange(val);
            });

            container.appendChild(slider);
            row.appendChild(container);

            return row;
        }

        // Setup Tabs and Panels
        const tabs = [];
        const panels = [];

        function registerTab(id, label, iconText, panelContentElement) {
            const btn = document.createElement("button");
            btn.className = "zeph-tab-btn";
            btn.innerHTML = `<span style="font-size:16px;">${iconText}</span> ${label}`;

            const panel = document.createElement("div");
            panel.id = `panel-${id}`;
            panel.className = "zeph-panel";
            panel.appendChild(panelContentElement);

            btn.addEventListener("click", () => {
                tabs.forEach(t => t.classList.remove("active"));
                panels.forEach(p => p.classList.remove("active"));

                btn.classList.add("active");
                panel.classList.add("active");
            });

            sidebar.appendChild(btn);
            content.appendChild(panel);
            tabs.push(btn);
            panels.push(panel);
        }

        // Helper: Hex to RGB
        function hexToRgb(hex) {
            const bigint = parseInt(hex.slice(1), 16);
            return {
                r: (bigint >> 16) & 255,
                g: (bigint >> 8) & 255,
                b: bigint & 255
            };
        }

        // ==========================================
        // 🎯 Combat Panel Content
        // ==========================================
        const combatWrapper = document.createElement("div");
        combatWrapper.style.display = "flex";
        combatWrapper.style.flexDirection = "column";
        combatWrapper.style.gap = "12px";

        combatWrapper.appendChild(createSwitchToggle("Aimbot", "Locks aim on matching color targets", settings.aimbotEnabled, (val) => {
            settings.aimbotEnabled = val;
        }, "aimbotToggle"));

        combatWrapper.appendChild(createSlider("Aimbot Speed", 0.1, 5.0, 0.1, settings.aimbotSpeed, "", (val) => {
            settings.aimbotSpeed = val;
        }));

        combatWrapper.appendChild(createSwitchToggle("FOV Circle", "Show target FOV perimeter", fovCircleEnabled, (val) => {
            fovCircleEnabled = val;
            const toggle = document.getElementById("fovToggle");
            if (toggle) toggle.checked = val;
        }, "fovToggle"));

        combatWrapper.appendChild(createSlider("FOV Radius", 20, 300, 5, fovRadius, "px", (val) => {
            fovRadius = val;
        }));

        combatWrapper.appendChild(createSwitchToggle("AntiPlayer (Anti-Aim)", "Tamper movement packets (requires invis OFF in lobby)", kourInstance.config.AntiAim, (val) => {
            kourInstance.config.AntiAim = val;
            const toggle = document.getElementById("aimToggle");
            if (toggle) toggle.checked = val;
        }, "aimToggle"));

        combatWrapper.appendChild(createSwitchToggle("SpinBot", "Spin model rapidly via packets", kourInstance.config.SpinBot, (val) => {
            kourInstance.config.SpinBot = val;
        }));

        combatWrapper.appendChild(createSwitchToggle("Instakill", "Multiplies weapon packet updates", kourInstance.config.Instakill, (val) => {
            kourInstance.config.Instakill = val;
        }));

        // Aimbot Activation Mode Select Dropdown
        const modeOptions = [
            { name: "Hold Trigger Key", id: "hold" },
            { name: "Always Active", id: "always" }
        ];
        combatWrapper.appendChild(createSearchDropdown(
            "Aimbot Activation Mode",
            modeOptions,
            settings.aimbotMode,
            (modeId) => {
                settings.aimbotMode = modeId;
            }
        ));

        // Aimbot Trigger Button Select Dropdown
        const triggerOptions = [
            { name: "Left + Right Click", id: "both" },
            { name: "Right Click Only", id: "right" },
            { name: "Left Click Only", id: "left" }
        ];

        let initialTriggerId = "both";
        if (settings.aimbotTriggerButton.length === 1) {
            initialTriggerId = settings.aimbotTriggerButton[0];
        }

        combatWrapper.appendChild(createSearchDropdown(
            "Aimbot Trigger Key",
            triggerOptions,
            initialTriggerId,
            (triggerId) => {
                if (triggerId === "both") {
                    settings.aimbotTriggerButton = ['left', 'right'];
                } else {
                    settings.aimbotTriggerButton = [triggerId];
                }
            }
        ));


        // ==========================================
        // 👁️ Visuals Panel Content
        // ==========================================
        const visualsWrapper = document.createElement("div");
        visualsWrapper.style.display = "flex";
        visualsWrapper.style.flexDirection = "column";
        visualsWrapper.style.gap = "12px";

        visualsWrapper.appendChild(createSwitchToggle("ESP", "Highlight player locations through walls", window.espEnabled, (val) => {
            window.espEnabled = val;
            const toggle = document.getElementById("espToggle");
            if (toggle) toggle.checked = val;
        }, "espToggle"));

        // ESP Color Row
        const colorRow = document.createElement("div");
        colorRow.className = "zeph-row";
        const colorLabelGroup = document.createElement("div");
        colorLabelGroup.className = "zeph-label-group";
        const colorTitle = document.createElement("div");
        colorTitle.className = "zeph-label-title";
        colorTitle.textContent = "ESP Color";
        colorLabelGroup.appendChild(colorTitle);
        const colorDesc = document.createElement("div");
        colorDesc.className = "zeph-label-desc";
        colorDesc.textContent = "Set primary highlight tone";
        colorLabelGroup.appendChild(colorDesc);
        colorRow.appendChild(colorLabelGroup);

        const colorPicker = document.createElement("input");
        colorPicker.type = "color";
        colorPicker.id = "espColorPicker";
        colorPicker.style.border = "none";
        colorPicker.style.background = "none";
        colorPicker.style.cursor = "pointer";
        colorPicker.style.width = "40px";
        colorPicker.style.height = "26px";
        colorPicker.value = `#${((1 << 24) + (window.espColor.r << 16) + (window.espColor.g << 8) + window.espColor.b).toString(16).slice(1)}`;
        colorPicker.addEventListener("input", (e) => {
            const rgb = hexToRgb(e.target.value);
            window.espColor = rgb;
            localStorage.setItem("espColorRGB", JSON.stringify(rgb));
        });
        colorRow.appendChild(colorPicker);
        visualsWrapper.appendChild(colorRow);

        visualsWrapper.appendChild(createSwitchToggle("Hide Crosshair", "Disable browser overlay crosshair", settings.crosshairEnabled, (val) => {
            settings.crosshairEnabled = val;
            const toggle = document.getElementById("crosshairToggle");
            if (toggle) toggle.checked = val;
        }, "crosshairToggle"));

        visualsWrapper.appendChild(createSwitchToggle("Hide Arms", "Remove weapon model arms in-game", true, (val) => {
            // Checked directly by WebGL interceptor via DOM element
        }, "blockarms"));

        visualsWrapper.appendChild(createSwitchToggle("Hide Damage Numbers", "Block game damage counter popups", settings.damagenumbersoff, (val) => {
            settings.damagenumbersoff = val;
        }));


        // ==========================================
        // ⚡ Movement Panel Content
        // ==========================================
        const movementWrapper = document.createElement("div");
        movementWrapper.style.display = "flex";
        movementWrapper.style.flexDirection = "column";
        movementWrapper.style.gap = "12px";

        // Performance.now slider
        let initialSpeedVal = 1.0;
        movementWrapper.appendChild(createSlider("Speed Hack Multiplier", 1, 6, 0.5, initialSpeedVal, "x", (val) => {
            updatePerformanceNow(val);
        }));

        movementWrapper.appendChild(createSwitchToggle("Air Strafing", "Increase lateral movement freedom in mid-air", kourInstance.config.airStrafing, (val) => {
            kourInstance.config.airStrafing = val;
            const toggle = document.getElementById("airToggle");
            if (toggle) toggle.checked = val;
        }, "airToggle"));


        // ==========================================
        // 🎒 Customization Panel Content
        // ==========================================
        const customWrapper = document.createElement("div");
        customWrapper.style.display = "flex";
        customWrapper.style.flexDirection = "column";
        customWrapper.style.gap = "12px";

        // Nickname changer row
        const nickRow = document.createElement("div");
        nickRow.className = "zeph-row";
        nickRow.innerHTML = `
            <div class="zeph-label-group">
                <div class="zeph-label-title">Player Nickname</div>
                <div class="zeph-label-desc">Sets custom lobby display name</div>
            </div>
            <div style="display:flex; gap:8px; align-items:center;">
                <input type="text" class="zeph-select-input" id="zephNicknameInput" style="width:130px;">
                <button class="zeph-btn" id="zephNicknameBtn" style="padding: 6px 12px;">Set</button>
            </div>
        `;
        const nickInput = nickRow.querySelector("#zephNicknameInput");
        nickInput.value = localStorage.getItem("playerNickname") || "";
        nickRow.querySelector("#zephNicknameBtn").addEventListener("click", () => {
            const name = nickInput.value.trim();
            if (name !== "") {
                localStorage.setItem("playerNickname", name);
                if (window.location.href.includes("#")) {
                    unityInstance.SendMessage("MapScripts", "SetNickname", name);
                }
            }
        });
        customWrapper.appendChild(nickRow);

        // Class Id Map (replaces local classMap shadowing)
        const classIdMap = {
            "Soldier": 0,
            "Hitman": 1,
            "Gunner": 2,
            "Heavy": 3,
            "Rocketeer": 4,
            "Agent": 5,
            "Brawler": 6,
            "Investor": 7,
            "Assassin": 8,
            "Juggernaut": 9,
            "Recon": 10,
            "Pyro": 11,
            "Rayblader": 12
        };

        // Class select dropdown
        customWrapper.appendChild(createSearchDropdown(
            "Select Class",
            Object.keys(classIdMap).map(cls => ({ name: cls, id: String(classIdMap[cls]) })),
            localStorage.getItem("selectedClass") || "0",
            (classID) => {
                localStorage.setItem("selectedClass", classID);
                unityInstance.SendMessage("MapScripts", "ChangeClassTo", parseInt(classID));
            }
        ));

        customWrapper.appendChild(createSearchDropdown("Secondary Weapon", weapons, "1", (id) => {
            setSecondaryWeapon(id);
        }));

        customWrapper.appendChild(createSearchDropdown("Melee Weapon", weapons, "13", (id) => {
            setMeleeWeapon(id);
        }));

        customWrapper.appendChild(createSearchDropdown("Set Skin", skins, "12", (id) => {
            setSkin(id);
        }));


        // ==========================================
        // 📊 Profile Panel Content
        // ==========================================
        const profileWrapper = document.createElement("div");
        profileWrapper.style.display = "flex";
        profileWrapper.style.flexDirection = "column";
        profileWrapper.style.gap = "12px";

        const statsHeader = document.createElement("div");
        statsHeader.className = "zeph-section-header";
        statsHeader.textContent = "Stats Editor";
        profileWrapper.appendChild(statsHeader);

        const stats = [
            { label: "ELO Points", key: "elo" },
            { label: "Chickalettas", key: "chickalettasKilled" },
            { label: "Games Played", key: "gamesPlayed" },
            { label: "Games Won", key: "gamesWon" },
            { label: "Knife Kills", key: "knifeKills" },
            { label: "Assists", key: "assists" },
            { label: "Max Kill Streak", key: "maxKillStreak" },
            { label: "Barrels Shot", key: "barrels" },
            { label: "Kyles Killed", key: "kylesKilled" },
            { label: "Total Kills", key: "totalKills" },
        ];

        const statsGrid = document.createElement("div");
        statsGrid.className = "zeph-grid-2";

        stats.forEach(({ label, key }) => {
            const statCard = document.createElement("div");
            statCard.className = "zeph-row";
            statCard.style.padding = "8px 12px";

            const cardLabel = document.createElement("div");
            cardLabel.className = "zeph-label-title";
            cardLabel.style.fontSize = "12px";
            cardLabel.textContent = label;
            statCard.appendChild(cardLabel);

            const editBtn = document.createElement("button");
            editBtn.className = "zeph-btn zeph-btn-secondary";
            editBtn.style.padding = "4px 8px";
            editBtn.style.fontSize = "11px";
            editBtn.textContent = "Edit";
            editBtn.addEventListener("click", () => {
                showModalCustom(
                    `Modify ${label}`,
                    `<input type="text" class="zeph-modal-input" placeholder="Enter new value..." id="statVal">`,
                    (body) => {
                        const val = body.querySelector("#statVal").value;
                        if (val.trim() !== "") {
                            if (key === "totalKills") {
                                updateKDStats(val);
                            } else {
                                setStat(key, val);
                            }
                            return true;
                        }
                        return false;
                    },
                    (body) => {
                        body.querySelector("#statVal").focus();
                    }
                );
            });
            statCard.appendChild(editBtn);
            statsGrid.appendChild(statCard);
        });
        profileWrapper.appendChild(statsGrid);

        const actionsHeader = document.createElement("div");
        actionsHeader.className = "zeph-section-header";
        actionsHeader.style.marginTop = "8px";
        actionsHeader.textContent = "Global Actions";
        profileWrapper.appendChild(actionsHeader);

        // Class kills button
        const classKillsBtn = document.createElement("button");
        classKillsBtn.className = "zeph-btn";
        classKillsBtn.style.width = "100%";
        classKillsBtn.textContent = "Class Kills Modifier";
        classKillsBtn.addEventListener("click", () => {
            // Using the IIFE scope classMap for database names mapping
            showModalCustom(
                "Class Kills Editor",
                `
                <div style="display:flex; flex-direction:column; gap:4px;">
                    <label style="font-size:11px; color:var(--text-secondary)">Select Class</label>
                    <select class="zeph-modal-input" id="classSelectField" style="background:#130e20; color:#fff; border:1px solid var(--border-color)">
                        ${Object.keys(classMap).map(cls => `<option value="${classMap[cls]}">${cls}</option>`).join("")}
                    </select>
                </div>
                <div style="display:flex; flex-direction:column; gap:4px;">
                    <label style="font-size:11px; color:var(--text-secondary)">Kill Count</label>
                    <input type="number" class="zeph-modal-input" id="classKillsCount" value="10000" min="0">
                </div>
                `,
                (body) => {
                    const classField = body.querySelector("#classSelectField").value;
                    const killCount = body.querySelector("#classKillsCount").value;
                    if (killCount !== "" && !isNaN(Number(killCount))) {
                        updateClassKills(classField, Number(killCount));
                        return true;
                    }
                    return false;
                }
            );
        });
        profileWrapper.appendChild(classKillsBtn);


        // ==========================================
        // ⚙️ Settings Panel Content
        // ==========================================
        const settingsWrapper = document.createElement("div");
        settingsWrapper.style.display = "flex";
        settingsWrapper.style.flexDirection = "column";
        settingsWrapper.style.gap = "12px";

        const keybindRow = document.createElement("div");
        keybindRow.className = "zeph-row";
        keybindRow.innerHTML = `
            <div class="zeph-label-group">
                <div class="zeph-label-title">Menu Toggle Bind</div>
                <div class="zeph-label-desc">Press any key in box to register bind</div>
            </div>
            <input type="text" class="zeph-select-input" id="zephKeybindInput" style="width:80px; text-align:center; cursor:pointer;" readonly>
        `;
        const keyInput = keybindRow.querySelector("#zephKeybindInput");
        keyInput.value = keybinds.toggleMenu;
        keyInput.addEventListener("keydown", (e) => {
            e.preventDefault();
            keyInput.value = e.key;
            keybinds.toggleMenu = e.key;
            localStorage.setItem("zephKeybinds", JSON.stringify(keybinds));
        });
        settingsWrapper.appendChild(keybindRow);

        // Menu Theme Dropdown
        const themeOptions = [
            { name: "Amethyst Purple", id: "purple" },
            { name: "Cyber Cyan", id: "cyan" },
            { name: "Acid Green", id: "green" },
            { name: "Crimson Red", id: "red" },
            { name: "Royal Gold", id: "gold" }
        ];

        settingsWrapper.appendChild(createSearchDropdown(
            "Menu Color Theme",
            themeOptions,
            savedTheme,
            (themeId) => {
                menu.classList.remove("theme-cyan", "theme-green", "theme-red", "theme-gold");
                const wm = document.getElementById("zephWatermark");
                if (wm) {
                    wm.classList.remove("theme-cyan", "theme-green", "theme-red", "theme-gold");
                }
                if (themeId !== "purple") {
                    menu.classList.add("theme-" + themeId);
                    if (wm) wm.classList.add("theme-" + themeId);
                }
                window.fovColor = themeColors[themeId] || themeColors.purple;
                localStorage.setItem("zephMenuTheme", themeId);
            }
        ));

        // Reset position row
        const resetRow = document.createElement("div");
        resetRow.className = "zeph-row";
        resetRow.innerHTML = `
            <div class="zeph-label-group">
                <div class="zeph-label-title">Reset Menu Position</div>
                <div class="zeph-label-desc">Centers the dashboard back to default</div>
            </div>
            <button class="zeph-btn zeph-btn-secondary" id="zephResetPosBtn" style="padding: 6px 12px;">Reset</button>
        `;
        resetRow.querySelector("#zephResetPosBtn").addEventListener("click", () => {
            menu.style.left = "100px";
            menu.style.top = "100px";
            localStorage.setItem("zephMenuX", "100");
            localStorage.setItem("zephMenuY", "100");
        });
        settingsWrapper.appendChild(resetRow);

        // Watermark toggle
        let initialWM = localStorage.getItem("zephWatermarkEnabled") !== "false";
        settingsWrapper.appendChild(createSwitchToggle(
            "Screen Watermark",
            "Show version indicator overlay on screen",
            initialWM,
            (val) => {
                localStorage.setItem("zephWatermarkEnabled", val);
                const wm = document.getElementById("zephWatermark");
                if (wm) {
                    if (val) wm.classList.remove("hidden");
                    else wm.classList.add("hidden");
                }
            }
        ));

        // Panic Button Row
        const panicRow = document.createElement("div");
        panicRow.className = "zeph-row";
        panicRow.innerHTML = `
            <div class="zeph-label-group">
                <div class="zeph-label-title" style="color: #ef4444; font-weight: 600;">Self-Destruct (Panic)</div>
                <div class="zeph-label-desc">Instantly wipe all overlays from game window</div>
            </div>
            <button class="zeph-btn" id="zephPanicBtn" style="background: linear-gradient(135deg, #ef4444, #b91c1c); box-shadow: 0 4px 10px rgba(239, 68, 68, 0.25); padding: 6px 12px;">Panic</button>
        `;
        panicRow.querySelector("#zephPanicBtn").addEventListener("click", () => {
            menu.remove();
            const wm = document.getElementById("zephWatermark");
            if (wm) wm.remove();
            if (fovCanvas) fovCanvas.remove();
            performance.now = originalPerfNow;
            console.log("[01 dev Menu] Panic Mode Activated. UI cleaned up.");
        });
        settingsWrapper.appendChild(panicRow);


        // Register tabs to navigation sidebar
        registerTab("combat", "Combat", "🎯", combatWrapper);
        registerTab("visuals", "Visuals", "👁️", visualsWrapper);
        registerTab("movement", "Movement", "⚡", movementWrapper);
        registerTab("custom", "Customization", "🎒", customWrapper);
        registerTab("profile", "Profile Modder", "📊", profileWrapper);
        registerTab("settings", "Settings", "⚙️", settingsWrapper);

        // Default open the first tab
        tabs[0].click();

        // Rainbow Authors text at bottom left
        const authorDiv = document.createElement("div");
        authorDiv.className = "zeph-madeby";
        authorDiv.textContent = "by 01 dev";
        authorDiv.style.marginTop = "auto";
        authorDiv.style.paddingTop = "15px";
        sidebar.appendChild(authorDiv);

        let hue = 0;
        function updateRGB() {
            hue = (hue + 1) % 360;
            authorDiv.style.color = `hsl(${hue}, 100%, 75%)`;
            if (document.getElementById("zephMenu")) {
                requestAnimationFrame(updateRGB);
            }
        }
        updateRGB();

        // Dragging handler
        let isDragging = false;
        let startXDrag, startYDrag;

        titlebar.addEventListener("mousedown", (e) => {
            if (e.target.closest(".zeph-discord-icon") || e.target.closest("button") || e.target.closest("input")) return;
            isDragging = true;
            startXDrag = e.clientX - menu.offsetLeft;
            startYDrag = e.clientY - menu.offsetTop;
            document.addEventListener("mousemove", drag);
            document.addEventListener("mouseup", stopDrag);
        });

        function drag(e) {
            if (!isDragging) return;
            let newX = e.clientX - startXDrag;
            let newY = e.clientY - startYDrag;

            newX = Math.max(0, Math.min(window.innerWidth - menu.offsetWidth, newX));
            newY = Math.max(0, Math.min(window.innerHeight - menu.offsetHeight, newY));

            menu.style.left = newX + "px";
            menu.style.top = newY + "px";
            menu.style.transform = "none";
        }

        function stopDrag() {
            isDragging = false;
            localStorage.setItem("zephMenuX", parseInt(menu.style.left));
            localStorage.setItem("zephMenuY", parseInt(menu.style.top));
            document.removeEventListener("mousemove", drag);
            document.removeEventListener("mouseup", stopDrag);
        }

        document.body.appendChild(menu);

        // Watermark initialization
        let watermark = document.createElement("div");
        watermark.id = "zephWatermark";
        watermark.className = "zeph-watermark";
        let savedWM = localStorage.getItem("zephWatermarkEnabled") !== "false";
        if (!savedWM) watermark.classList.add("hidden");

        watermark.innerHTML = `
            <div class="zeph-watermark-dot"></div>
            <div>01 dev Menu v2</div>
        `;

        // Match initial theme
        if (savedTheme !== "purple") {
            watermark.classList.add("theme-" + savedTheme);
        }

        document.body.appendChild(watermark);
    }

    window.addEventListener("keydown", (e) => {
        if (e.key.toLowerCase() === "v") {
            const savedClassID = localStorage.getItem("selectedClass");
            if (
                savedClassID !== null &&
                window.location.href.includes("#")
            ) {
                unityInstance.SendMessage("MapScripts", "ChangeClassTo", parseInt(savedClassID));
            }
        }
    });

    /***************************************
   * Keybinds
   ***************************************/

    let lastHash = window.location.hash;

    setInterval(() => {
        const currentHash = window.location.hash;

        if (currentHash !== lastHash && currentHash.includes("#")) {
            lastHash = currentHash;

            const storedName = localStorage.getItem("playerNickname");
            if (storedName) {
                unityInstance.SendMessage("MapScripts", "SetNickname", storedName);
            }
        }
    }, 500);

    let keybinds = {
        toggleMenu: "Insert",
    }

    const savedKeybinds = localStorage.getItem("zephKeybinds");
    if (savedKeybinds) {
        try {
            keybinds = JSON.parse(savedKeybinds);
        } catch (e) { }
    }

    document.addEventListener("keydown", function (e) {
        if ((e.key === keybinds.toggleMenu || e.key === "Insert") && !e.target.matches("input, textarea, select")) {
            const menu = document.getElementById("zephMenu");
            if (menu) {
                const isClosed = menu.classList.contains("hidden");
                if (isClosed) {
                    menu.classList.remove("hidden");
                } else {
                    menu.classList.add("hidden");
                    const overlay = document.getElementById("zephModalOverlay");
                    if (overlay) overlay.classList.remove("open");
                }
            }
        }
    });

    window.addEventListener("load", createUI);
})();