Universal Script – Delta remaster - Verified script for Universal Roblox
Key RequiredUniversal

Universal Script – Delta remaster

Universal ScriptIooooooIoooooo 861 views 865 executesUpdated Oct 21, 2026
Unrated
00
Lua Script•14073 lines (396756 chars)
--!nocheck
local __dcm_boot = {
	hostEnv = (getgenv and getgenv()) or _G or {},
}

__dcm_boot.getLoader = function()
	local hostLoader = type(__dcm_boot.hostEnv) == "table" and rawget(__dcm_boot.hostEnv, "loadstring") or nil
	if type(hostLoader) == "function" then
		return hostLoader
	end
	if type(loadstring) == "function" then
		return loadstring
	end
	return nil
end
local __dcm_isDelta = false
if type(identifyexecutor) == "function" then
	local ok, name = pcall(identifyexecutor)
	__dcm_isDelta = ok and type(name) == "string" and name:lower() == "delta"
end
if not __dcm_isDelta then
	pcall(function()
		local loader = __dcm_boot.getLoader()
		if type(loader) ~= "function" then
			return
		end
		local src = game:HttpGet("https://gitlab.com/ltseverydayyou/Nameless-Admin/-/raw/main/NamelessAdminNotifications.lua")
		local chunk = loader(src, "@NamelessAdminNotifications.lua")
		if type(chunk) ~= "function" then
			return
		end
		local mod = chunk()
		if type(mod) == "table" and type(mod.Notify) == "function" then
			mod.Notify({
				Title = "Delta Only",
				Description = "This script ONLY supports Delta's UI.\nTo that ScriptBlox reviewer: testing a Delta customizer on another executor and whining 'doesn't work' is a reading problem, not a script problem.",
				Duration = 9,
			})
		end
	end)
	return
end

__dcm_boot.hostGetfenv = type(__dcm_boot.hostEnv.getfenv) == "function" and __dcm_boot.hostEnv.getfenv or getfenv
__dcm_boot.hostSetfenv = type(__dcm_boot.hostEnv.setfenv) == "function" and __dcm_boot.hostEnv.setfenv or setfenv
__dcm_boot.debug = rawget(__dcm_boot.hostEnv, "debug") or debug
__dcm_boot.getPrivateRegistry = function()
	local registry
	if type(getreg) == "function" then
		pcall(function()
			registry = getreg()
		end)
	end
	if type(registry) ~= "table" and type(__dcm_boot.debug) == "table" and type(__dcm_boot.debug.getregistry) == "function" then
		pcall(function()
			registry = __dcm_boot.debug.getregistry()
		end)
	end
	if type(registry) ~= "table" then
		registry = {}
	end
	return registry
end
__dcm_boot.ensureTable = function(host, key)
	local value = type(host) == "table" and rawget(host, key) or nil
	if type(value) ~= "table" then
		value = {}
		if type(host) == "table" then
			pcall(rawset, host, key, value)
			if rawget(host, key) ~= value then
				host[key] = value
			end
		end
	end
	return value
end
__dcm_boot.clearHostKey = function(host, key)
	if type(host) == "table" then
		pcall(rawset, host, key, nil)
		pcall(function()
			host[key] = nil
		end)
	end
end
__dcm_boot.clearLegacyGlobals = function(host)
	local keys = {
		"__DeltaCustomizationModuleLoaded",
		"__DeltaVisualPatchLoaded",
		"__DeltaThemeMenuPatchLoaded",
		"__DeltaHubMusicPatch",
		"DeltaIcon",
	}
	for i = 1, #keys do
		__dcm_boot.clearHostKey(host, keys[i])
	end
	local sh = type(host) == "table" and rawget(host, "shared") or nil
	if type(sh) == "table" and sh ~= host then
		for i = 1, #keys do
			__dcm_boot.clearHostKey(sh, keys[i])
		end
	end
end
__dcm_boot.privateRegistry = __dcm_boot.getPrivateRegistry()
__dcm_boot.privateRoot = __dcm_boot.ensureTable(__dcm_boot.privateRegistry, "__nameless_admin_private")
local __dcm_env = __dcm_boot.ensureTable(__dcm_boot.privateRoot, "delta_customization")
local __dcm_shared = __dcm_boot.ensureTable(__dcm_env, "shared")
__dcm_boot.runtimeEnv = __dcm_boot.ensureTable(__dcm_env, "runtime")

__dcm_boot.runtimeEnv.shared = __dcm_shared
__dcm_boot.runtimeEnv._G = __dcm_boot.runtimeEnv
__dcm_boot.runtimeEnv.getgenv = function()
	return __dcm_boot.runtimeEnv
end
__dcm_boot.runtimeEnv.getfenv = function(target)
	if target == nil or target == 0 then
		return __dcm_boot.runtimeEnv
	end
	if type(__dcm_boot.hostGetfenv) == "function" then
		return __dcm_boot.hostGetfenv(target)
	end
	return __dcm_boot.runtimeEnv
end

setmetatable(__dcm_boot.runtimeEnv, {
	__index = function(_, key)
		if key == "_G" then
			return __dcm_boot.runtimeEnv
		elseif key == "shared" then
			return __dcm_shared
		elseif key == "getgenv" then
			return __dcm_boot.runtimeEnv.getgenv
		elseif key == "getfenv" then
			return __dcm_boot.runtimeEnv.getfenv
		end
		return __dcm_boot.hostEnv[key]
	end,
})

if type(__dcm_boot.hostSetfenv) == "function" then
	pcall(__dcm_boot.hostSetfenv, 1, __dcm_boot.runtimeEnv)
end

local __lt = (function()
	local cached = rawget(__dcm_boot.privateRoot, "serviceResolver")
	if type(cached) == "table" then
		return cached
	end
	local loader = __dcm_boot.getLoader()
	if type(loader) ~= "function" then
		error("Service resolver loader unavailable")
	end
	local okSrc, src = pcall(function()
		return game:HttpGet("https://gitlab.com/ltseverydayyou/ltseverydayyou.gitlab.io/-/raw/main/ServiceResolver.luau")
	end)
	if not (okSrc and type(src) == "string" and src ~= "") then
		error("Service resolver HTTP failed: " .. tostring(typeof and typeof(src) or type(src)))
	end
	local resolver = loader(src, "@ServiceResolver.luau")
	if type(resolver) ~= "function" then
		error("Service resolver failed to compile")
	end
	if type(__dcm_boot.hostSetfenv) == "function" then
		pcall(__dcm_boot.hostSetfenv, resolver, __dcm_boot.runtimeEnv)
	end
	local loaded = resolver()
	if type(loaded) ~= "table" then
		error("Service resolver failed to load")
	end
	__dcm_boot.privateRoot.serviceResolver = loaded
	return loaded
end)()
local __NAUIProtector = (function()
	local cacheHost = __dcm_env;
	if cacheHost then
		local cached = rawget(cacheHost, "__lt_ui_protector");
		if type(cached) == "table" then
			return cached;
		end;
	end;
	local loader = __dcm_boot.getLoader();
	if type(loader) ~= "function" then
		return nil;
	end;
	local okSource, source = pcall(function()
		return game:HttpGet("https://gitlab.com/ltseverydayyou/ltseverydayyou.gitlab.io/-/raw/main/UIprotector.luau");
	end);
	if not okSource or type(source) ~= "string" or source == "" then
		return nil;
	end;
	local chunk = loader(source, "@UIprotector.luau");
	if type(chunk) ~= "function" then
		return nil;
	end;
	if type(__dcm_boot.hostSetfenv) == "function" then
		pcall(__dcm_boot.hostSetfenv, chunk, __dcm_boot.runtimeEnv);
	end;
	local okLoaded, loaded = pcall(chunk);
	if okLoaded and type(loaded) == "table" then
		if cacheHost then
			cacheHost.__lt_ui_protector = loaded;
		end;
		return loaded;
	end;
	return nil;
end)();
local __NAOriginalGetHui = gethui;
local gethui = function()
	if __NAUIProtector and type(__NAUIProtector.huiGrabber) == "function" then
		local ok, ui = pcall(__NAUIProtector.huiGrabber);
		if ok and typeof(ui) == "Instance" then
			return ui;
		end;
	end;
	if type(__NAOriginalGetHui) == "function" then
		local ok, ui = pcall(__NAOriginalGetHui);
		if ok then
			return ui;
		end;
	end;
	return nil;
end;
local function __NAProtectUI(gui, options)
	if __NAUIProtector and type(__NAUIProtector.protectUI) == "function" then
		local ok, protected = pcall(__NAUIProtector.protectUI, gui, options);
		if ok and protected then
			return protected;
		end;
	end;
	return nil;
end;

local function dcmAlreadyLoaded()
	if __dcm_env and __dcm_env.__DeltaCustomizationModuleLoaded then
		return true
	end
	if __dcm_shared and __dcm_shared.__DeltaCustomizationModuleLoaded then
		return true
	end
	return false
end

local __dcm_previousMasterRuntime = rawget(__dcm_env, "__DeltaCustomizationMasterRuntime")
if type(__dcm_previousMasterRuntime) == "table" and type(__dcm_previousMasterRuntime.stop) == "function" then
	pcall(__dcm_previousMasterRuntime.stop)
else
	local __dcm_previousRuntime = rawget(__dcm_env, "__DeltaCustomizationV2Runtime")
	if type(__dcm_previousRuntime) == "table" and type(__dcm_previousRuntime.stop) == "function" then
		pcall(__dcm_previousRuntime.stop)
	end
end
__dcm_env.__DeltaCustomizationModuleLoaded = nil
__dcm_shared.__DeltaCustomizationModuleLoaded = nil
__dcm_env.__DeltaVisualPatchLoaded = nil
__dcm_env.__DeltaThemeMenuPatchLoaded = nil

local __dcm_flag = {
	version = "2.5.8",
	loadedAt = tick(),
}
__dcm_env.__DeltaCustomizationModuleLoaded = __dcm_flag
__dcm_shared.__DeltaCustomizationModuleLoaded = __dcm_flag
local httpTxt
local UIS
local root
local settingsPath
local notify
local _naConns
local NAlib
local writeJsonFile

do
local deltaEnv = __dcm_boot.runtimeEnv
local _ref = cloneref and type(cloneref) == "function" and cloneref or function(v)
	return v
end
local SRV = setmetatable({}, {
	__index = function(self, n)
		local ok, s = pcall(function()
			return __lt.cs(n, _ref)
		end)
		if ok and s then
			rawset(self, n, s)
			return s
		end
	end,
})
local function Svc(n)
	return SRV[n]
end

httpTxt = function(u, hdr)
	if type(u) ~= "string" or u == "" then
		return nil, "bad url"
	end
	local rq = (syn and syn.request) or request or http_request or (http and http.request)
	if type(rq) == "function" then
		local h = {
			["User-Agent"] = "Roblox/Http/1.1",
			["Accept"] = "*/*",
		}
		if type(hdr) == "table" then
			for k, v in hdr do
				h[k] = v
			end
		end
		local ok, res = pcall(rq, {
			Url = u,
			Method = "GET",
			Headers = h,
		})
		if ok and type(res) == "table" then
			local code = tonumber(res.StatusCode or res.Status or res.status_code) or 0
			local body = res.Body or res.body
			if (code == 0 or code >= 200 and code < 300) and type(body) == "string" and body ~= "" then
				return body
			end
		end
	end
	local ok, body = pcall(function()
		return game:HttpGet(u)
	end)
	if ok and type(body) == "string" and body ~= "" then
		return body
	end
	return nil, "HttpGet returned " .. tostring(typeof and typeof(body) or type(body))
end

local function runUrl(u, name, hdr)
	local ld = __dcm_boot.getLoader()
	if type(ld) ~= "function" then
		return false, "loadstring unavailable"
	end
	local src, er = httpTxt(u, hdr)
	if type(src) ~= "string" or src == "" then
		return false, er or "empty source"
	end
	local fn, er2 = ld(src, name or ("@" .. u))
	if type(fn) ~= "function" then
		return false, er2 or "compile failed"
	end
	if type(__dcm_boot.hostSetfenv) == "function" then
		pcall(__dcm_boot.hostSetfenv, fn, __dcm_boot.runtimeEnv)
	end
	return pcall(fn)
end
UIS = Svc("UserInputService")
local CG = Svc("CoreGui")
local HS = Svc("HttpService")
local RS = Svc("RunService")
local Stats = Svc("Stats")
local TS = Svc("TweenService")
local notifMod
local nt
local colorsPath = "DeltaCustom/Colors.json"
local colorConfig = {}
do
	if HS and type(isfile) == "function" and type(readfile) == "function" then
		if isfile(colorsPath) then
			local ok, data = pcall(readfile, colorsPath)
			if ok and data then
				local ok2, decoded = pcall(function()
					return __lt.cm("HttpService", "JSONDecode", data)
				end)
				if ok2 and type(decoded) == "table" then
					colorConfig = decoded
				end
			end
		end
	end
end
settingsPath = "DeltaCustom/Settings.json"
local settingsConfig = {}
do
	if HS and type(isfile) == "function" and type(readfile) == "function" then
		if isfile(settingsPath) then
			local ok, data = pcall(readfile, settingsPath)
			if ok and data then
				local ok2, decoded = pcall(function()
					return __lt.cm("HttpService", "JSONDecode", data)
				end)
				if ok2 and type(decoded) == "table" then
					settingsConfig = decoded
				end
			end
		end
	end
end
do
	local n = nil
	local tries = 0
	repeat
		tries += 1
		local s, r = runUrl(
			"https://gitlab.com/ltseverydayyou/Nameless-Admin/-/raw/main/NamelessAdminNotifications.lua",
			"@NamelessAdminNotifications.lua"
		)
		if s and type(r) == "table" and type(r.Notify) == "function" then
			n = r
			notifMod = r
			nt = r.Notify
		else
			task.wait(0.5)
		end
	until n ~= nil or tries >= 5
end
notify = function(info)
	if not nt or type(info) ~= "table" then
		return
	end
	pcall(function()
		nt(info)
	end)
end
_naConns = {}
NAlib = {}
function NAlib.disconnect(n)
	local t = _naConns[n]
	if t then
		for _, c in t do
			pcall(function()
				c:Disconnect()
			end)
		end
		_naConns[n] = nil
	end
end
function NAlib.connect(n, c)
	if not c then
		return
	end
	_naConns[n] = _naConns[n] or {}
	table.insert(_naConns[n], c)
	return c
end
function NAlib.isProperty(o, p)
	return pcall(function()
		return o[p]
	end)
end
function NAlib.setProperty(o, p, v)
	pcall(function()
		o[p] = v
	end)
end
local uiLib = {}
uiLib.draggerV2 = function(ui, dragui)
	dragui = dragui or ui
	local dragging, dragInput, dragStart, startPos
	local anchor = ui.AnchorPoint
	local sg = ui:FindFirstAncestorWhichIsA("ScreenGui") or ui.Parent
	local function sClamp(v, lo, hi)
		if hi < lo then
			hi = lo
		end
		return math.clamp(v, lo, hi)
	end
	local function upd(input)
		pcall(function()
			local p = sg.AbsoluteSize
			local s = ui.AbsoluteSize
			if p.X <= 0 or p.Y <= 0 then
				return
			end
			local sx = startPos.X.Scale * p.X + startPos.X.Offset
			local sy = startPos.Y.Scale * p.Y + startPos.Y.Offset
			local dx = input.Position.X - dragStart.X
			local dy = input.Position.Y - dragStart.Y
			local minX = anchor.X * s.X
			local maxX = p.X - (1 - anchor.X) * s.X
			local minY = anchor.Y * s.Y
			local maxY = p.Y - (1 - anchor.Y) * s.Y
			local nx = sClamp(sx + dx, minX, maxX)
			local ny = sClamp(sy + dy, minY, maxY)
			ui.Position = UDim2.new(nx / p.X, 0, ny / p.Y, 0)
		end)
	end
	local id = "DraggerV2_" .. ui:GetDebugId()
	NAlib.disconnect(id)
	NAlib.connect(
		id,
		dragui.InputBegan:Connect(function(input)
			pcall(function()
				if
					input.UserInputType == Enum.UserInputType.MouseButton1
					or input.UserInputType == Enum.UserInputType.Touch
				then
					dragging = true
					dragStart = input.Position
					startPos = ui.Position
					local c = input.Changed:Connect(function()
						pcall(function()
							if input.UserInputState == Enum.UserInputState.End then
								dragging = false
							end
						end)
					end)
					NAlib.connect(id, c)
				end
			end)
		end)
	)
	NAlib.connect(
		id,
		dragui.InputChanged:Connect(function(input)
			pcall(function()
				if
					input.UserInputType == Enum.UserInputType.MouseMovement
					or input.UserInputType == Enum.UserInputType.Touch
				then
					dragInput = input
				end
			end)
		end)
	)
	NAlib.connect(
		id,
		UIS.InputChanged:Connect(function(input)
			pcall(function()
				if input == dragInput and dragging then
					upd(input)
				end
			end)
		end)
	)
	local function clampToView()
		pcall(function()
			local p = sg.AbsoluteSize
			local s = ui.AbsoluteSize
			if p.X <= 0 or p.Y <= 0 then
				return
			end
			local pos = ui.Position
			local ax = pos.X.Scale * p.X + pos.X.Offset
			local ay = pos.Y.Scale * p.Y + pos.Y.Offset
			local minX = anchor.X * s.X
			local maxX = p.X - (1 - anchor.X) * s.X
			local minY = anchor.Y * s.Y
			local maxY = p.Y - (1 - anchor.Y) * s.Y
			local nx = sClamp(ax, minX, maxX)
			local ny = sClamp(ay, minY, maxY)
			ui.Position = UDim2.new(nx / p.X, 0, ny / p.Y, 0)
		end)
	end
	NAlib.connect(id, (sg:GetPropertyChangedSignal("AbsoluteSize")):Connect(clampToView))
	if ui and ui.GetPropertyChangedSignal then
		NAlib.connect(id, (ui:GetPropertyChangedSignal("AbsoluteSize")):Connect(clampToView))
	end
	clampToView()
	if ui and NAlib.isProperty(ui, "Active") then
		NAlib.setProperty(ui, "Active", true)
	end
	if dragui and NAlib.isProperty(dragui, "Active") then
		NAlib.setProperty(dragui, "Active", true)
	end
end
root = gethui and gethui() or CG
local function isGib(n)
	if typeof(n) ~= "string" or n == "" then
		return false
	end
	return not n:match("^[%w _%-]+$")
end
local function getMain()
	local best
	local bestScore = 0
	for _, g in root:GetChildren() do
		if g:IsA("ScreenGui") then
			local score = 0
			if g:FindFirstChild("Executor") then
				score += 5
			elseif g:FindFirstChild("Executor", true) then
				score += 2
			end
			if g:FindFirstChild("Sidebar") then
				score += 4
			elseif g:FindFirstChild("Sidebar", true) then
				score += 2
			end
			for _, name in { "Scripthub", "Settings", "Home", "Console" } do
				if g:FindFirstChild(name) then
					score += 2
				elseif g:FindFirstChild(name, true) then
					score += 1
				end
			end
			if g:FindFirstChild("MainScript") then
				score += 1
			end
			if isGib(g.Name) then
				score += 1
			end
			if score > bestScore then
				best = g
				bestScore = score
			end
		end
	end
	if bestScore >= 11 then
		return best
	end
end

local function fixNet(rootGui)
	if not rootGui then
		return
	end
	local side = rootGui:FindFirstChild("Sidemenu", true) or rootGui
	local net = side and side:FindFirstChild("Network", true)
	if not (net and net:IsA("GuiObject")) then
		return
	end
	local over = net:FindFirstChild("Overlay")
	if not (over and over:IsA("GuiObject")) then
		over = Instance.new("Frame")
		over.Name = "Overlay"
		over.BackgroundTransparency = 1
		over.BorderSizePixel = 0
		over.Position = UDim2.fromScale(0, 0)
		over.Size = UDim2.fromScale(1, 1)
		over.ClipsDescendants = false
		over.ZIndex = net.ZIndex + 1
		over.Parent = net
	end
	for _, name in { "Holder", "Information" } do
		local ch = net:FindFirstChild(name)
		if ch and ch ~= over and ch.Parent == net and not over:FindFirstChild(name) then
			ch.Parent = over
		end
	end
	return over
end
local function getIconGui()
	local bestGui
	local bestButton
	local bestScore = -math.huge
	for _, g in root:GetChildren() do
		if g:IsA("ScreenGui") and not g:FindFirstChild("Executor", true) then
			local buttons = {}
			local guiCount = 0
			for _, d in g:GetDescendants() do
				if d:IsA("GuiObject") then
					guiCount += 1
				end
				if d:IsA("ImageButton") then
					table.insert(buttons, d)
				end
			end
			if #buttons == 1 and guiCount <= 12 then
				local button = buttons[1]
				local score = 0
				if button.Parent == g then
					score += 4
				end
				if type(button.Image) == "string" and button.Image ~= "" then
					score += 3
				end
				local size = button.AbsoluteSize
				if size.X > 0 and size.Y > 0 then
					local ratio = size.X / size.Y
					if ratio >= 0.7 and ratio <= 1.3 then
						score += 3
					end
				end
				if isGib(g.Name) then
					score += 1
				end
				if score > bestScore then
					bestScore = score
					bestGui = g
					bestButton = button
				end
			end
		end
	end
	return bestGui, bestButton
end
local mainGui = getMain()
local _iconGui0, _iconBtn0 = getIconGui()
local __dcm_masterRuntime = {
	alive = true,
	stopping = false,
	objects = {},
	baseline = {},
	mutations = setmetatable({}, { __mode = "k" }),
	customObjects = {},
	roots = {},
}
__dcm_env.__DeltaCustomizationMasterRuntime = __dcm_masterRuntime
__dcm_shared.__DeltaCustomizationMasterRuntime = __dcm_masterRuntime

local __dcm_snapshotProperties = {
	"Name",
	"Archivable",
}
local __dcm_guiProperties = {
	"Visible",
	"Active",
	"Selectable",
	"Interactable",
	"Position",
	"Size",
	"AnchorPoint",
	"AutomaticSize",
	"BackgroundColor3",
	"BackgroundTransparency",
	"BorderColor3",
	"BorderSizePixel",
	"ClipsDescendants",
	"LayoutOrder",
	"Rotation",
	"ZIndex",
	"Draggable",
}
local __dcm_textProperties = {
	"Text",
	"TextColor3",
	"TextTransparency",
	"TextStrokeColor3",
	"TextStrokeTransparency",
	"TextSize",
	"TextScaled",
	"TextWrapped",
	"TextTruncate",
	"TextXAlignment",
	"TextYAlignment",
	"FontFace",
	"LineHeight",
}
local __dcm_imageProperties = {
	"Image",
	"ImageColor3",
	"ImageTransparency",
	"ScaleType",
	"SliceCenter",
	"SliceScale",
	"ResampleMode",
	"TileSize",
}
local __dcm_scrollingProperties = {
	"AutomaticCanvasSize",
	"CanvasPosition",
	"CanvasSize",
	"ElasticBehavior",
	"HorizontalScrollBarInset",
	"ScrollBarImageColor3",
	"ScrollBarImageTransparency",
	"ScrollBarThickness",
	"ScrollingDirection",
	"ScrollingEnabled",
	"VerticalScrollBarInset",
	"VerticalScrollBarPosition",
}

local function __dcm_captureProperty(object, values, property)
	local ok, value = pcall(function()
		return object[property]
	end)
	if ok then
		values[property] = value
	end
end

local function __dcm_captureObject(object)
	if not object or __dcm_masterRuntime.baseline[object] then
		return
	end
	local values = {}
	for _, property in __dcm_snapshotProperties do
		__dcm_captureProperty(object, values, property)
	end
	if object:IsA("LayerCollector") then
		for _, property in { "Enabled", "ResetOnSpawn", "ZIndexBehavior" } do
			__dcm_captureProperty(object, values, property)
		end
	end
	if object:IsA("ScreenGui") then
		for _, property in { "DisplayOrder", "IgnoreGuiInset", "ScreenInsets", "SafeAreaCompatibility", "ClipToDeviceSafeArea" } do
			__dcm_captureProperty(object, values, property)
		end
	end
	if object:IsA("CanvasGroup") then
		for _, property in { "GroupColor3", "GroupTransparency" } do
			__dcm_captureProperty(object, values, property)
		end
	end
	if object:IsA("GuiButton") then
		for _, property in { "AutoButtonColor", "Modal", "Selected" } do
			__dcm_captureProperty(object, values, property)
		end
	end
	if object:IsA("GuiObject") then
		for _, property in __dcm_guiProperties do
			__dcm_captureProperty(object, values, property)
		end
	end
	if object:IsA("TextLabel") or object:IsA("TextButton") or object:IsA("TextBox") then
		for _, property in __dcm_textProperties do
			__dcm_captureProperty(object, values, property)
		end
	end
	if object:IsA("ImageLabel") or object:IsA("ImageButton") then
		for _, property in __dcm_imageProperties do
			__dcm_captureProperty(object, values, property)
		end
	end
	if object:IsA("ScrollingFrame") then
		for _, property in __dcm_scrollingProperties do
			__dcm_captureProperty(object, values, property)
		end
	elseif object:IsA("UIListLayout") or object:IsA("UIGridLayout") then
		for _, property in { "Padding", "FillDirection", "HorizontalAlignment", "VerticalAlignment", "SortOrder", "Wraps", "HorizontalFlex", "VerticalFlex" } do
			__dcm_captureProperty(object, values, property)
		end
	elseif object:IsA("UIPadding") then
		for _, property in { "PaddingLeft", "PaddingRight", "PaddingTop", "PaddingBottom" } do
			__dcm_captureProperty(object, values, property)
		end
	elseif object:IsA("UIGradient") then
		for _, property in { "Color", "Transparency", "Rotation", "Offset", "Enabled" } do
			__dcm_captureProperty(object, values, property)
		end
	elseif object:IsA("UICorner") then
		__dcm_captureProperty(object, values, "CornerRadius")
	elseif object:IsA("UIStroke") then
		for _, property in { "Color", "Thickness", "Transparency", "Enabled", "ApplyStrokeMode", "LineJoinMode" } do
			__dcm_captureProperty(object, values, property)
		end
	elseif object:IsA("UIScale") then
		__dcm_captureProperty(object, values, "Scale")
	elseif object:IsA("ValueBase") then
		__dcm_captureProperty(object, values, "Value")
	end
	__dcm_masterRuntime.baseline[object] = true
	local attributes = {}
	pcall(function()
		attributes = object:GetAttributes()
	end)
	__dcm_masterRuntime.objects[object] = {
		Parent = object.Parent,
		Values = values,
		Attributes = attributes,
	}
end

local function __dcm_captureRoot(target)
	if not target then
		return
	end
	table.insert(__dcm_masterRuntime.roots, target)
	__dcm_captureObject(target)
	for _, object in target:GetDescendants() do
		__dcm_captureObject(object)
	end
end

local function __dcm_captureMutation(object, property)
	if not (object and type(property) == "string") then
		return
	end
	local state = __dcm_masterRuntime.mutations[object]
	if not state then
		state = {}
		__dcm_masterRuntime.mutations[object] = state
	end
	if state[property] ~= nil then
		return
	end
	local ok, value = pcall(function()
		return object[property]
	end)
	if ok then
		state[property] = { value = value }
	end
end

local function __dcm_setTracked(object, property, value)
	if not object then
		return false
	end
	__dcm_captureMutation(object, property)
	return pcall(function()
		object[property] = value
	end)
end

local function __dcm_registerCustom(object)
	if object then
		__dcm_masterRuntime.customObjects[object] = true
	end
	return object
end

__dcm_masterRuntime.captureMutation = __dcm_captureMutation
__dcm_masterRuntime.setTracked = __dcm_setTracked
__dcm_masterRuntime.registerCustom = __dcm_registerCustom

__dcm_captureRoot(mainGui)
if _iconGui0 and _iconGui0 ~= mainGui then
	__dcm_captureRoot(_iconGui0)
end

local function __dcm_isCustomObject(object)
	local name = object.Name
	if name:sub(1, 3) == "LT_" or name == "LTIcon" or name:sub(1, 11) == "DeltaCustom" then
		return true
	end
	return name == "Section_Customization"
		or name == "Section_Delta"
		or name == "SidebarGestureZone"
		or name == "SidebarGradientColor1"
		or name == "SidebarGradientColor2"
		or name == "IconColorValue"
		or name == "IconSizeValue"
		or name == "IconRgbSpeedValue"
		or name == "DeltaIconCorner"
end

local function __dcm_restoreSnapshot()
	for object in __dcm_masterRuntime.customObjects do
		if object and object.Parent then
			pcall(function()
				object:Destroy()
			end)
		end
	end
	for object, snapshot in __dcm_masterRuntime.objects do
		if object and snapshot.Parent then
			pcall(function()
				object.Parent = snapshot.Parent
			end)
		end
	end
	for _, target in __dcm_masterRuntime.roots do
		if target and target.Parent then
			local settings = target:FindFirstChild("Settings") or target:FindFirstChild("Settings", true)
			local holder = settings and settings:FindFirstChild("Holder")
			if holder then
				for _, child in holder:GetChildren() do
					if not __dcm_masterRuntime.baseline[child] and __dcm_isCustomObject(child) then
						pcall(function()
							child:Destroy()
						end)
					end
				end
			end
			for _, object in target:GetDescendants() do
				if not __dcm_masterRuntime.baseline[object] and __dcm_isCustomObject(object) then
					pcall(function()
						object:Destroy()
					end)
				end
			end
		end
	end
	for object, snapshot in __dcm_masterRuntime.objects do
		if object and object.Parent then
			for property, value in snapshot.Values do
				pcall(function()
					object[property] = value
				end)
			end
		end
	end
	for object, state in __dcm_masterRuntime.mutations do
		if object and object.Parent then
			local baselineSnapshot = __dcm_masterRuntime.objects[object]
			for property, wrapped in state do
				local ownedByBaseline = baselineSnapshot
					and (property == "Parent" or baselineSnapshot.Values[property] ~= nil)
				if not ownedByBaseline then
					pcall(function()
						object[property] = wrapped.value
					end)
				end
			end
		end
	end
	for object, snapshot in __dcm_masterRuntime.objects do
		if object and object.Parent then
			pcall(function()
				local original = snapshot.Attributes or {}
				for name in object:GetAttributes() do
					if original[name] == nil then
						object:SetAttribute(name, nil)
					end
				end
				for name, value in original do
					object:SetAttribute(name, value)
				end
			end)
		end
	end
end

__dcm_masterRuntime.stop = function()
	if not __dcm_masterRuntime.alive or __dcm_masterRuntime.stopping then
		return
	end
	__dcm_masterRuntime.stopping = true
	for _, key in { "__DeltaCustomizationV2Runtime", "__DeltaThemeRuntime", "__DeltaHubMusicPatch" } do
		local current = rawget(__dcm_env, key)
		if type(current) == "table" and current ~= __dcm_masterRuntime and type(current.stop) == "function" then
			pcall(current.stop)
		end
	end
	if type(_naConns) == "table" and type(NAlib) == "table" then
		for name in _naConns do
			NAlib.disconnect(name)
		end
	end
	__dcm_restoreSnapshot()
	__dcm_masterRuntime.alive = false
	__dcm_masterRuntime.stopping = false
	if rawget(__dcm_env, "__DeltaCustomizationMasterRuntime") == __dcm_masterRuntime then
		__dcm_env.__DeltaCustomizationMasterRuntime = nil
	end
	if rawget(__dcm_shared, "__DeltaCustomizationMasterRuntime") == __dcm_masterRuntime then
		__dcm_shared.__DeltaCustomizationMasterRuntime = nil
	end
	__dcm_env.__DeltaCustomizationModuleLoaded = nil
	__dcm_shared.__DeltaCustomizationModuleLoaded = nil
	__dcm_env.__DeltaVisualPatchLoaded = nil
	__dcm_env.__DeltaThemeMenuPatchLoaded = nil
	__dcm_env.DeltaIcon = nil
	__dcm_env.__NewDeltaUIToggle = nil

	local restoreToken = {}
	__dcm_env.__DeltaCustomizationRestoreToken = restoreToken
	__dcm_shared.__DeltaCustomizationRestoreToken = restoreToken
	local function stabilizeRestore()
		if rawget(__dcm_env, "__DeltaCustomizationRestoreToken") ~= restoreToken then
			return
		end
		if rawget(__dcm_env, "__DeltaCustomizationMasterRuntime") ~= nil then
			return
		end
		__dcm_restoreSnapshot()
	end
	task.defer(stabilizeRestore)
	task.delay(0.05, stabilizeRestore)
	task.delay(0.2, stabilizeRestore)
	task.delay(0.6, function()
		stabilizeRestore()
		if rawget(__dcm_env, "__DeltaCustomizationRestoreToken") == restoreToken then
			__dcm_env.__DeltaCustomizationRestoreToken = nil
		end
		if rawget(__dcm_shared, "__DeltaCustomizationRestoreToken") == restoreToken then
			__dcm_shared.__DeltaCustomizationRestoreToken = nil
		end
		table.clear(__dcm_masterRuntime.mutations)
	end)
end

local managedIcon = {
	deltaGui = _iconGui0,
	deltaBtn = _iconBtn0,
	customGui = nil,
	customBtn = nil,
}
managedIcon.deltaStroke = managedIcon.deltaBtn
	and (
		managedIcon.deltaBtn:FindFirstChildOfClass("UIStroke")
		or managedIcon.deltaBtn:FindFirstChildWhichIsA("UIStroke", true)
	)
managedIcon.deltaCorner = managedIcon.deltaBtn
	and (
		managedIcon.deltaBtn:FindFirstChildOfClass("UICorner")
		or managedIcon.deltaBtn:FindFirstChildWhichIsA("UICorner", true)
	)
managedIcon.customStroke = nil
managedIcon.customCorner = nil
local iconGui, iconBtn = managedIcon.deltaGui, managedIcon.deltaBtn
local iconStroke = managedIcon.deltaStroke
local iconCorner = managedIcon.deltaCorner
local iconBaseColor = iconStroke and iconStroke.Color
local iconBaseSize = iconBtn and iconBtn.Size
local iconBaseCorner = iconCorner and iconCorner.CornerRadius
local iconSzLock = false
local iconColorUseCustom = false
local iconApplyBusy = false
local updateIconStatusUI
local applyIconStrokeState
local applyIconShapeChoice
local applySavedManagedIconPosition
local bindManagedIconPositionSaver
local bindManagedIconToggle
local ensureManagedIcon
local function MouseButtonFix(button, clickCallback)
	if not button or type(clickCallback) ~= "function" then
		return { Disconnect = function() end }
	end
	local clickTimeThreshold = 0.45
	local moveThreshold = 10
	local mouseDownTime = 0
	local isPointerDown = false
	local startPosition = nil
	local maxMoveDistance = 0
	local connections = {}
	local function getSignal(obj, signalName)
		local ok, signal = pcall(function()
			return obj[signalName]
		end)
		if ok and signal then
			return signal
		end
		return nil
	end
	local function connectSignal(signal, fn)
		if not signal then
			return false
		end
		local ok, conn = pcall(function()
			return signal:Connect(fn)
		end)
		if ok and conn then
			connections[#connections + 1] = conn
			return true
		end
		return false
	end
	local function isPressInput(inputType)
		return inputType == Enum.UserInputType.MouseButton1 or inputType == Enum.UserInputType.Touch
	end
	local function resetState()
		mouseDownTime = 0
		isPointerDown = false
		startPosition = nil
		maxMoveDistance = 0
	end
	local function beginPointer(input)
		isPointerDown = true
		mouseDownTime = tick()
		maxMoveDistance = 0
		local pos = input and input.Position
		startPosition = pos and Vector2.new(pos.X, pos.Y) or nil
	end
	local function endPointer()
		if not isPointerDown or mouseDownTime == 0 then
			resetState()
			return
		end
		local holdDuration = tick() - mouseDownTime
		local isClick = holdDuration < clickTimeThreshold and maxMoveDistance <= moveThreshold
		resetState()
		if isClick then
			clickCallback()
		end
	end
	local boundPress = false
	local isGuiButton = type(button.IsA) == "function" and button:IsA("GuiButton")
	if isGuiButton then
		local downSignal = getSignal(button, "MouseButton1Down")
		local upSignal = getSignal(button, "MouseButton1Up")
		local downBound = connectSignal(downSignal, function()
			beginPointer(nil)
		end)
		local upBound = connectSignal(upSignal, function()
			endPointer()
		end)
		boundPress = downBound and upBound
	end
	if not boundPress then
		local beganSignal = getSignal(button, "InputBegan")
		local endedSignal = getSignal(button, "InputEnded")
		local beganBound = connectSignal(beganSignal, function(input)
			if input and isPressInput(input.UserInputType) then
				beginPointer(input)
			end
		end)
		local endedBound = connectSignal(endedSignal, function(input)
			if input and isPressInput(input.UserInputType) then
				endPointer()
			end
		end)
		boundPress = beganBound and endedBound
	end
	local changedSignal = getSignal(button, "InputChanged")
	connectSignal(changedSignal, function(input)
		if not isPointerDown then
			return
		end
		if input.UserInputType ~= Enum.UserInputType.MouseMovement and input.UserInputType ~= Enum.UserInputType.Touch then
			return
		end
		local pos = input.Position
		if not pos then
			return
		end
		if not startPosition then
			startPosition = Vector2.new(pos.X, pos.Y)
			return
		end
		local currentPos = Vector2.new(pos.X, pos.Y)
		local delta = (currentPos - startPosition).Magnitude
		if delta > maxMoveDistance then
			maxMoveDistance = delta
		end
	end)
	if not boundPress then
		return { Disconnect = function() end }
	end
	return {
		Disconnect = function()
			for _, conn in connections do
				if conn and conn.Disconnect then
					conn:Disconnect()
				end
			end
		end,
	}
end
local function hideOriginalDeltaIcon()
	if managedIcon.deltaGui then
		__dcm_setTracked(managedIcon.deltaGui, "Enabled", false)
	end
	if managedIcon.deltaBtn then
		__dcm_setTracked(managedIcon.deltaBtn, "Visible", false)
		__dcm_setTracked(managedIcon.deltaBtn, "Active", false)
		__dcm_setTracked(managedIcon.deltaBtn, "ImageTransparency", 1)
		__dcm_setTracked(managedIcon.deltaBtn, "BackgroundTransparency", 1)
	end
	if managedIcon.deltaStroke then
		__dcm_setTracked(managedIcon.deltaStroke, "Enabled", false)
	end
end
local function refreshIconRefs()
	local prevIconGui = iconGui
	local prevIconBtn = iconBtn
	local ig, ib = getIconGui()
	local deltaChanged = ig ~= managedIcon.deltaGui or ib ~= managedIcon.deltaBtn
	managedIcon.deltaGui = ig
	managedIcon.deltaBtn = ib
	managedIcon.deltaStroke = managedIcon.deltaBtn
		and (
			managedIcon.deltaBtn:FindFirstChildOfClass("UIStroke")
			or managedIcon.deltaBtn:FindFirstChildWhichIsA("UIStroke", true)
		)
	managedIcon.deltaCorner = managedIcon.deltaBtn
		and (
			managedIcon.deltaBtn:FindFirstChildOfClass("UICorner")
			or managedIcon.deltaBtn:FindFirstChildWhichIsA("UICorner", true)
		)
	if managedIcon.deltaGui or managedIcon.deltaBtn then
		hideOriginalDeltaIcon()
		NAlib.disconnect("DeltaIcon_OriginalHideGui")
		if managedIcon.deltaGui then
			NAlib.connect(
				"DeltaIcon_OriginalHideGui",
				managedIcon.deltaGui:GetPropertyChangedSignal("Enabled"):Connect(function()
					if managedIcon.deltaGui.Enabled then
						hideOriginalDeltaIcon()
					end
				end)
			)
		end
		NAlib.disconnect("DeltaIcon_OriginalHideBtn")
		if managedIcon.deltaBtn then
			NAlib.connect(
				"DeltaIcon_OriginalHideBtn",
				managedIcon.deltaBtn:GetPropertyChangedSignal("Visible"):Connect(function()
					if managedIcon.deltaBtn.Visible then
						hideOriginalDeltaIcon()
					end
				end)
			)
		end
	end
	if ensureManagedIcon then
		ensureManagedIcon()
	end
	if managedIcon.customBtn and managedIcon.customBtn.Parent then
		iconGui = managedIcon.customGui
		iconBtn = managedIcon.customBtn
		iconStroke = managedIcon.customStroke
		iconCorner = managedIcon.customCorner
	else
		iconGui = managedIcon.deltaGui
		iconBtn = managedIcon.deltaBtn
		iconStroke = managedIcon.deltaStroke
		iconCorner = managedIcon.deltaCorner
	end
	local changed = deltaChanged or iconGui ~= prevIconGui or iconBtn ~= prevIconBtn
	if iconBtn then
		if changed or not iconBaseSize then
			iconBaseSize = iconBtn.Size
		end
		if iconStroke and not iconColorUseCustom and (changed or not iconBaseColor) then
			iconBaseColor = iconStroke.Color
		end
		if iconCorner and (changed or not iconBaseCorner) then
			iconBaseCorner = iconCorner.CornerRadius
		end
		if changed and applyIconStrokeState then
			task.defer(applyIconStrokeState)
		end
		if changed and applyIconShapeChoice then
			task.defer(applyIconShapeChoice)
		end
		if changed and applySavedManagedIconPosition then
			task.defer(applySavedManagedIconPosition)
		end
		if changed and bindManagedIconPositionSaver then
			task.defer(bindManagedIconPositionSaver)
		end
		if changed and bindManagedIconToggle then
			task.defer(bindManagedIconToggle)
		end
	end
	return changed
end
local function fsOk()
	return type(isfile) == "function" and type(writefile) == "function"
end
local function gaOk()
	return type(getcustomasset) == "function"
end
local function iconFsOk()
	return fsOk() and gaOk()
end
local function trim(s)
	if type(s) ~= "string" then
		return ""
	end
	return s:match("^%s*(.-)%s*$") or ""
end
local function sName(name)
	if type(name) ~= "string" then
		return nil
	end
	local t = trim(name)
	t = t:gsub("[^%w%._%-]", "_")
	t = t:gsub("_+", "_")
	t = t:gsub("^_+", "")
	t = t:gsub("_+$", "")
	if t == "" then
		return nil
	end
	return t
end
local function getName(path)
	if type(path) ~= "string" then
		return nil
	end
	local n = path:gsub("\\", "/")
	return n:match("([^/]+)$")
end
local function fileFromUrl(u)
	if type(u) ~= "string" then
		return nil
	end
	return u:match("/([^/%?]+)$")
end
local function iconPreUrl(u)
	if type(u) ~= "string" then
		return nil
	end
	local t = trim(u)
	if t == "" then
		return nil
	end
	t = t:gsub(" ", "%%20")
	local q = t:find("%?")
	local base = q and t:sub(1, q - 1) or t
	return t, base
end
local function iconNormUrl(u)
	local t, base = iconPreUrl(u)
	if not t then
		return nil
	end
	local owner, repo, kind, rest = base:match("^https?://github.com/([^/]+)/([^/]+)/([^/]+)/(.+)$")
	if owner and repo and kind and rest then
		local s = rest
		if s:sub(1, 11) == "refs/heads/" then
			s = s:sub(12)
		elseif s:sub(1, 10) == "refs/tags/" then
			s = s:sub(11)
		end
		local branch, path = s:match("^([^/]+)/(.+)$")
		if branch and path and (kind == "blob" or kind == "raw") then
			branch = branch:gsub("%%2[Ff]", "/")
			path = path:gsub("%%2[Ff]", "/")
			return string.format("https://raw.githubusercontent.com/%s/%s/%s/%s", owner, repo, branch, path)
		end
	end
	local rawDir = base:match("^https?://raw%.githubusercontent%.com/.+")
	if rawDir then
		return t
	end
	return t
end
local function ensureDir(path)
	if not fsOk() then
		return false
	end
	if type(isfolder) == "function" then
		local ok, ex = pcall(isfolder, path)
		if ok and ex then
			return true
		end
		if type(makefolder) ~= "function" then
			return false
		end
		local okMk = pcall(makefolder, path)
		return okMk == true
	end
	return true
end
local function ensureParentDir(path)
	if type(path) ~= "string" or path == "" then
		return false
	end
	local dir = path:gsub("\\", "/"):match("^(.*)/[^/]+$")
	if not dir or dir == "" then
		return true
	end
	return ensureDir(dir)
end
writeJsonFile = function(path, payload)
	if not (HS and fsOk()) then
		return false
	end
	if not ensureParentDir(path) then
		return false
	end
	local okEnc, enc = pcall(function()
		return __lt.cm("HttpService", "JSONEncode", payload)
	end)
	if not (okEnc and type(enc) == "string") then
		return false
	end
	local okW = pcall(writefile, path, enc)
	if okW then
		return true
	end
	return pcall(writefile, path, enc)
end
local baseDir = "DeltaCustom"
local iconDir = baseDir .. "/DeltaIcons"
local cfgPath = baseDir .. "/delta_icon.json"
local dIcons = {
	entries = {},
	index = 0,
	enabled = false,
	localPath = "",
	assetId = "",
	defaultImage = "",
	pendingInput = "",
}
local function ensureIconDir()
	if not ensureDir(baseDir) then
		return false
	end
	return ensureDir(iconDir)
end
local function loadIconCfg()
	if not fsOk() or not HS then
		return
	end
	if type(isfolder) == "function" and type(makefolder) == "function" then
		local okB, exB = pcall(isfolder, baseDir)
		if not (okB and exB) then
			pcall(makefolder, baseDir)
		end
	end
	if type(isfile) == "function" and type(writefile) == "function" then
		if not isfile(cfgPath) then
			pcall(
				writefile,
				cfgPath,
				__lt.cm("HttpService", "JSONEncode", {
					enabled = false,
					assetId = "",
					localPath = "",
					index = 0,
				})
			)
		end
	end
	if type(isfile) ~= "function" or type(readfile) ~= "function" then
		return
	end
	if not isfile(cfgPath) then
		return
	end
	local ok, raw = pcall(readfile, cfgPath)
	if not (ok and type(raw) == "string") then
		return
	end
	local okD, dec = pcall(HS.JSONDecode, HS, raw)
	if not (okD and type(dec) == "table") then
		return
	end
	if type(dec.enabled) == "boolean" then
		dIcons.enabled = dec.enabled
	end
	if type(dec.assetId) == "string" then
		dIcons.assetId = dec.assetId
	end
	if type(dec.localPath) == "string" then
		dIcons.localPath = dec.localPath
	end
	if type(dec.index) == "number" then
		dIcons.index = dec.index
	end
end
local function saveIconCfg()
	if not fsOk() or not HS then
		return
	end
	local payload = {
		enabled = dIcons.enabled and true or false,
		assetId = type(dIcons.assetId) == "string" and dIcons.assetId or "",
		localPath = type(dIcons.localPath) == "string" and dIcons.localPath or "",
		index = tonumber(dIcons.index) or 0,
	}
	writeJsonFile(cfgPath, payload)
end
local function scanIcons()
	dIcons.entries = {}
	dIcons.index = 0
	if not (fsOk() and type(listfiles) == "function") then
		return
	end
	if not ensureIconDir() then
		return
	end
	local ok, items = pcall(listfiles, iconDir)
	if not (ok and type(items) == "table") then
		return
	end
	local list = {}
	for _, full in items do
		local n = getName(full)
		if n then
			list[#list + 1] = { file = n }
		end
	end
	dIcons.entries = list
	if type(dIcons.localPath) == "string" and dIcons.localPath ~= "" then
		local cur = getName(dIcons.localPath)
		if cur then
			for i, e in list do
				if e.file == cur then
					dIcons.index = i
					if updateIconStatusUI then
						updateIconStatusUI()
					end
					return
				end
			end
		end
	end
	if #list > 0 then
		dIcons.index = 1
	end
	if updateIconStatusUI then
		updateIconStatusUI()
	end
end
local function formatIconStatus()
	local list = dIcons.entries
	local n = #list
	if n == 0 then
		return "No custom icons installed"
	end
	if n == 1 then
		return "1 custom icon installed"
	end
	return tostring(n) .. " custom icons installed"
end
local function resolveIconAsset(full)
	if not gaOk() or type(full) ~= "string" or full == "" then
		return nil
	end
	local tried = {}
	local function tryPath(path)
		if type(path) ~= "string" or path == "" or tried[path] then
			return nil
		end
		tried[path] = true
		local okA, asset = pcall(getcustomasset, path)
		if okA and type(asset) == "string" and asset ~= "" then
			return asset
		end
		return nil
	end
	local asset = tryPath(full)
	if asset then
		return asset
	end
	local slash = full:gsub("\\", "/")
	if slash ~= full then
		asset = tryPath(slash)
		if asset then
			return asset
		end
	end
	local back = full:gsub("/", "\\")
	if back ~= full then
		asset = tryPath(back)
		if asset then
			return asset
		end
	end
	local name = getName(full)
	if name then
		asset = tryPath(iconDir .. "/" .. name) or tryPath(iconDir .. "\\" .. name) or tryPath(name)
		if asset then
			return asset
		end
	end
	return nil
end
local function iconHttpGetBinary(url, headers)
	if type(url) ~= "string" or url == "" then
		return nil
	end
	local function tryRequest(hdr)
		if type(rq) ~= "function" then
			return nil
		end
		local h = {}
		if type(hdr) == "table" then
			for k, v in hdr do
				h[k] = v
			end
		end
		h["User-Agent"] = h["User-Agent"] or "Roblox/Http/1.1"
		h["Accept"] = h["Accept"] or "*/*"
		local ok, res = pcall(rq, {
			Url = url,
			Method = "GET",
			Headers = h,
		})
		if ok and res then
			local code = res.StatusCode or res.Status or res.status_code or 0
			local body = res.Body or res.body
			if (code == 0 or (code >= 200 and code < 300)) and type(body) == "string" and body ~= "" then
				return body
			end
		end
		return nil
	end
	local data = tryRequest(headers)
	if type(data) == "string" and data ~= "" then
		return data
	end
	local ok2, body2 = pcall(function()
		return game:HttpGet(url)
	end)
	if ok2 and type(body2) == "string" and body2 ~= "" then
		return body2
	end
	return tryRequest(nil)
end
local function iconSaveFromUrl(url)
	if not iconFsOk() then
		return false, "Custom icons require file support and getcustomasset."
	end
	if not ensureIconDir() then
		return false, "Unable to prepare DeltaIcons folder."
	end
	local norm = iconNormUrl(url)
	if not norm then
		return false, "Enter a valid image URL or asset id."
	end
	local data = iconHttpGetBinary(norm)
	if not (type(data) == "string" and data ~= "") then
		return false, "Unable to download icon image."
	end
	local remote = fileFromUrl(norm) or "DeltaIcon.png"
	local safe = sName(remote) or "icon_" .. tostring(os.time()) .. ".png"
	local full = iconDir .. "/" .. safe
	local okW, errW = pcall(writefile, full, data)
	if not okW then
		return false, errW or "Unable to save icon image."
	end
	local asset = resolveIconAsset(full)
	if not asset then
		return false, "Unable to load icon image."
	end
	dIcons.localPath = full
	local list = dIcons.entries
	local idx
	for i, e in list do
		if e.file == safe then
			idx = i
			break
		end
	end
	if not idx then
		list[#list + 1] = { file = safe }
		idx = #list
	end
	dIcons.entries = list
	dIcons.index = idx
	if updateIconStatusUI then
		updateIconStatusUI()
	end
	return true, asset
end
local function applyIcon()
	refreshIconRefs()
	if not iconBtn or (not iconBtn:IsA("ImageButton")) then
		return false
	end
	local img
	if dIcons.enabled and type(dIcons.assetId) == "string" and dIcons.assetId ~= "" then
		img = dIcons.assetId
	elseif type(dIcons.defaultImage) == "string" and dIcons.defaultImage ~= "" then
		img = dIcons.defaultImage
	end
	iconApplyBusy = true
	if img and img ~= "" then
		iconBtn.Image = img
		iconApplyBusy = false
		return true
	else
		iconBtn.Image = ""
	end
	iconApplyBusy = false
	return false
end
local function setIconEnabled(flag)
	if not iconFsOk() then
		return false, "Custom icon requires file support and getcustomasset."
	end
	flag = flag and true or false
	if flag and (not dIcons.assetId or dIcons.assetId == "") then
		return false, "Add an asset id or image URL before enabling."
	end
	dIcons.enabled = flag
	applyIcon()
	saveIconCfg()
	return true
end
local function setIconAsset(input, opts)
	opts = opts or {}
	if not iconFsOk() then
		return false, "Custom icon requires file support and getcustomasset."
	end
	local raw = type(input) == "string" and input or tostring(input)
	if type(raw) ~= "string" then
		return false, "Enter a valid asset id or image URL."
	end
	raw = trim(raw)
	if raw == "" then
		return false, "Enter a valid asset id or image URL."
	end
	local digits = raw:match("^rbxassetid://(%d+)$") or raw:match("id=(%d+)") or raw:match("^(%d+)$")
	local newAsset
	dIcons.localPath = ""
	if digits then
		newAsset = "rbxassetid://" .. digits
	else
		local okIcon, res = iconSaveFromUrl(raw)
		if not okIcon then
			return false, res or "Unable to save custom icon."
		end
		newAsset = res
		scanIcons()
	end
	dIcons.assetId = newAsset
	if opts.autoEnable ~= false then
		dIcons.enabled = true
	end
	applyIcon()
	saveIconCfg()
	if digits then
		return true, digits
	end
	return true, raw
end
local function cycleIcon(delta)
	local list = dIcons.entries
	if #list == 0 then
		return
	end
	delta = delta or 1
	local idx = dIcons.index or 1
	if idx < 1 or idx > #list then
		idx = 1
	end
	idx = (idx - 1 + delta) % #list + 1
	local e = list[idx]
	if not e or not e.file then
		return
	end
	local full = iconDir .. "/" .. e.file
	if fsOk() and type(isfile) == "function" then
		local okEx, ex = pcall(isfile, full)
		if not (okEx and ex) then
			scanIcons()
			return
		end
	end
	local asset = resolveIconAsset(full)
	if not asset then
		return
	end
	dIcons.localPath = full
	dIcons.assetId = asset
	dIcons.index = idx
	dIcons.enabled = true
	applyIcon()
	saveIconCfg()
	if updateIconStatusUI then
		updateIconStatusUI()
	end
end
local function delIconFile(name)
	if type(name) ~= "string" or name == "" then
		return
	end
	if not (fsOk() and type(delfile) == "function" and type(isfile) == "function") then
		return
	end
	local full = iconDir .. "/" .. name
	local okEx, ex = pcall(isfile, full)
	if okEx and ex then
		pcall(delfile, full)
	end
end
local function clearIfCurrent(name)
	if type(name) ~= "string" or name == "" then
		return
	end
	local full = iconDir .. "/" .. name
	if dIcons.localPath == full then
		dIcons.localPath = ""
		dIcons.assetId = ""
		dIcons.index = 0
		dIcons.enabled = false
		applyIcon()
		saveIconCfg()
	end
end
local function removeIconEntry(entry)
	if not (entry and entry.file) then
		return
	end
	delIconFile(entry.file)
	clearIfCurrent(entry.file)
	scanIcons()
end
local function removeAllIcons()
	local list = dIcons.entries or {}
	for _, e in list do
		if e and e.file then
			delIconFile(e.file)
		end
	end
	dIcons.entries = {}
	dIcons.index = 0
	dIcons.localPath = ""
	dIcons.assetId = ""
	dIcons.enabled = false
	applyIcon()
	saveIconCfg()
	scanIcons()
end
ensureManagedIcon = function()
	if
		mainGui
		and managedIcon.customBtn
		and managedIcon.customBtn.Parent == mainGui
	then
		managedIcon.customGui = mainGui
		managedIcon.customStroke = managedIcon.customBtn
			and (
				managedIcon.customBtn:FindFirstChildOfClass("UIStroke")
				or managedIcon.customBtn:FindFirstChildWhichIsA("UIStroke", true)
			)
		managedIcon.customCorner = managedIcon.customBtn
			and (
				managedIcon.customBtn:FindFirstChildOfClass("UICorner")
				or managedIcon.customBtn:FindFirstChildWhichIsA("UICorner", true)
			)
		return true
	end
	if not (mainGui and managedIcon.deltaGui and managedIcon.deltaBtn) then
		return false
	end
	hideOriginalDeltaIcon()
	local btn = managedIcon.deltaBtn:Clone()
	btn.Name = "LTIcon"
	btn.Visible = true
	btn.Active = true
	btn.ImageTransparency = managedIcon.deltaBtn.ImageTransparency
	btn.BackgroundTransparency = managedIcon.deltaBtn.BackgroundTransparency
	btn.Parent = mainGui
	managedIcon.customGui = mainGui
	managedIcon.customBtn = btn
	managedIcon.customStroke = btn:FindFirstChildOfClass("UIStroke") or btn:FindFirstChildWhichIsA("UIStroke", true)
	managedIcon.customCorner = btn:FindFirstChildOfClass("UICorner") or btn:FindFirstChildWhichIsA("UICorner", true)
	iconGui = managedIcon.customGui
	iconBtn = managedIcon.customBtn
	iconStroke = managedIcon.customStroke
	iconCorner = managedIcon.customCorner
	return true
end
ensureManagedIcon()
refreshIconRefs()
if iconBtn and type(iconBtn.Image) == "string" and iconBtn.Image ~= "" then
	dIcons.defaultImage = iconBtn.Image
end
loadIconCfg()
scanIcons()
local function refreshIconFromPath()
	if not iconFsOk() then
		return
	end
	if type(dIcons.localPath) ~= "string" or dIcons.localPath == "" then
		return
	end
	local full = dIcons.localPath
	local okEx, ex = pcall(isfile, full)
	if not (okEx and ex) then
		dIcons.localPath = ""
		dIcons.assetId = ""
		dIcons.enabled = false
		saveIconCfg()
		return
	end
	local asset = resolveIconAsset(full)
	if not asset then
		dIcons.assetId = ""
		dIcons.enabled = false
		saveIconCfg()
		return
	end
	dIcons.assetId = asset
	saveIconCfg()
end
refreshIconFromPath()
if dIcons.enabled and type(dIcons.assetId) == "string" and dIcons.assetId ~= "" then
	applyIcon()
end
local function bindIconButtonWatcher()
	NAlib.disconnect("DeltaIcon_ImageWatcher")
	if not (iconBtn and iconBtn:IsA("ImageButton")) then
		return
	end
	NAlib.connect(
		"DeltaIcon_ImageWatcher",
		iconBtn:GetPropertyChangedSignal("Image"):Connect(function()
			if iconApplyBusy then
				return
			end
			if
				dIcons.enabled
				and type(dIcons.assetId) == "string"
				and dIcons.assetId ~= ""
				and iconBtn.Image ~= dIcons.assetId
			then
				task.defer(applyIcon)
			end
		end)
	)
end
local function refreshIconButtonState()
	local changed = refreshIconRefs()
	if iconBtn and type(iconBtn.Image) == "string" and iconBtn.Image ~= "" then
		if
			not (
				dIcons.enabled
				and type(dIcons.assetId) == "string"
				and dIcons.assetId ~= ""
				and iconBtn.Image == dIcons.assetId
			)
		then
			dIcons.defaultImage = iconBtn.Image
		end
	end
	bindIconButtonWatcher()
	if changed and dIcons.enabled and type(dIcons.assetId) == "string" and dIcons.assetId ~= "" then
		task.defer(applyIcon)
	end
end
refreshIconButtonState()
NAlib.disconnect("DeltaIcon_RootChildAdded")
NAlib.connect(
	"DeltaIcon_RootChildAdded",
	root.ChildAdded:Connect(function()
		task.defer(refreshIconButtonState)
	end)
)
local deltaIconApi = {
	status = formatIconStatus,
	setEnabled = setIconEnabled,
	setAsset = setIconAsset,
	cycle = cycleIcon,
	scan = scanIcons,
	removeEntry = removeIconEntry,
	removeAll = removeAllIcons,
	getButton = function()
		refreshIconButtonState()
		return iconBtn
	end,
	rebindToggle = function()
		if bindManagedIconToggle then
			bindManagedIconToggle()
		end
	end,
	data = dIcons,
}
deltaEnv.DeltaIcon = deltaIconApi
__dcm_env.DeltaIcon = deltaIconApi
__dcm_shared.DeltaIcon = deltaIconApi
task.defer(function()
	while not mainGui do
		mainGui = getMain()
		if mainGui then
			break
		end
		task.wait(0.1)
	end
	if not mainGui then
		notify({
			Title = "Delta Customization",
			Description = "Failed to find Delta UI.",
			Duration = 4,
		})
		return
	end
	__dcm_setTracked(mainGui, "IgnoreGuiInset", true)
	fixNet(mainGui)
	NAlib.disconnect("DeltaCustom_NetworkOverlayFix")
	NAlib.connect("DeltaCustom_NetworkOverlayFix", mainGui.DescendantAdded:Connect(function(d)
		if d and d.Name == "Network" then
			task.defer(function()
				fixNet(mainGui)
			end)
		end
	end))
	local execFrame = mainGui:FindFirstChild("Executor")
	if not (execFrame and execFrame:IsA("Frame")) then
		notify({
			Title = "Delta Customization",
			Description = "Executor frame not found.",
			Duration = 4,
		})
		return
	end
	local execImage = execFrame:FindFirstChild("Executor")
	if not (execImage and execImage:IsA("ImageLabel")) then
		notify({
			Title = "Delta Customization",
			Description = "Executor image not found.",
			Duration = 4,
		})
		return
	end
	local overlay = execImage:FindFirstChild("Overlay")
	if not overlay then
		notify({
			Title = "Delta Customization",
			Description = "Overlay frame not found.",
			Duration = 4,
		})
		return
	end
	local sidebar = mainGui:FindFirstChild("Sidebar", true)
	local toggleUIBtn = sidebar and sidebar:FindFirstChild("ToggleUI", true)
	local activeColorValue = sidebar and sidebar:FindFirstChild("ActiveColor")
	local inactiveColorValue = sidebar and sidebar:FindFirstChild("InactiveColor")
	local darkOverlay = mainGui:FindFirstChild("DarkOverlay")
	local sidebarGradient = nil
	local sidebarGrad1 = nil
	local sidebarGrad2 = nil
	local sidebarClosedPos = UDim2.new(1.08, 0, 0.5, 0)
	local sidebarOpenPos = UDim2.new(1, 0, 0.5, 0)
	local sidebarNormalizeBusy = false
	local function normalizeSidebarGeometry()
		if sidebarNormalizeBusy or not (sidebar and sidebar:IsA("GuiObject")) then
			return
		end
		sidebarNormalizeBusy = true
		pcall(function()
			if sidebar.Size.Y.Scale ~= 1 or sidebar.Size.Y.Offset ~= 0 then
				sidebar.Size = UDim2.new(sidebar.Size.X.Scale, sidebar.Size.X.Offset, 1, 0)
			end
			if sidebar.Position.Y.Scale ~= 0.5 or sidebar.Position.Y.Offset ~= 0 then
				sidebar.Position = UDim2.new(sidebar.Position.X.Scale, sidebar.Position.X.Offset, 0.5, 0)
			end
		end)
		sidebarNormalizeBusy = false
	end
	local function setSidebarPosition(targetPos)
		if not (sidebar and sidebar:IsA("GuiObject")) then
			return
		end
		sidebar.Position = UDim2.new(targetPos.X.Scale, targetPos.X.Offset, 0.5, 0)
	end
	if sidebar and sidebar:IsA("GuiObject") then
		normalizeSidebarGeometry()
		NAlib.disconnect("Sidebar_NormalizeGeometry")
		NAlib.connect(
			"Sidebar_NormalizeGeometry",
			sidebar:GetPropertyChangedSignal("Size"):Connect(function()
				task.defer(normalizeSidebarGeometry)
			end)
		)
		NAlib.connect(
			"Sidebar_NormalizeGeometry",
			sidebar:GetPropertyChangedSignal("Position"):Connect(function()
				task.defer(normalizeSidebarGeometry)
			end)
		)
	end
	if iconGui and iconGui:IsA("ScreenGui") then
		__dcm_setTracked(iconGui, "IgnoreGuiInset", true)
	end
	if iconBtn then
		__dcm_setTracked(iconBtn, "Draggable", false)
		uiLib.draggerV2(iconBtn, iconBtn)
	end
	if darkOverlay then
		__dcm_setTracked(darkOverlay, "Visible", false)
		__dcm_setTracked(darkOverlay, "Active", false)
		NAlib.connect(
			"DarkOverlay_Hide",
			darkOverlay:GetPropertyChangedSignal("Visible"):Connect(function()
				darkOverlay.Visible = false
			end)
		)
	end
	local settingsFrame
	do
		local cand = mainGui:FindFirstChild("Settings", true)
		if cand and cand:IsA("Frame") and cand:FindFirstChild("Holder") then
			settingsFrame = cand
		end
	end
	local settingsHolder = settingsFrame and settingsFrame:FindFirstChild("Holder")
	local settingTemplate
	local function saveSettingsEntry(key, payload)
		if not (HS and type(writefile) == "function") then
			return
		end
		settingsConfig[key] = payload
		writeJsonFile(settingsPath, settingsConfig)
	end
	local uiScaleState = {
		object = nil,
		value = nil,
		refreshers = setmetatable({}, { __mode = "k" }),
	}
	local function getInterfaceViewport()
		local cam = workspace.CurrentCamera
		if cam and cam.ViewportSize.X > 0 and cam.ViewportSize.Y > 0 then
			return cam.ViewportSize
		end
		return mainGui.AbsoluteSize
	end
	local function suggestInterfaceScale()
		local vp = getInterfaceViewport()
		if not vp then
			return 1
		end
		return 1
	end
	local function ensureInterfaceScale()
		if uiScaleState.object and uiScaleState.object.Parent == mainGui then
			return uiScaleState.object
		end
		local sc = mainGui:FindFirstChild("LT_InterfaceScale")
		if not (sc and sc:IsA("UIScale")) then
			sc = Instance.new("UIScale")
			sc.Name = "LT_InterfaceScale"
			sc.Parent = mainGui
		end
		uiScaleState.object = sc
		return sc
	end
	local function applyInterfaceScale(v)
		local sc = ensureInterfaceScale()
		if not sc then
			return
		end
		pcall(function()
			sc.Scale = math.clamp(tonumber(v) or 1, 0.5, 1.65)
		end)
		task.defer(function()
			for _, delayTime in { 0, 0.03, 0.1 } do
				if delayTime > 0 then
					task.wait(delayTime)
				end
				for sf, refresh in uiScaleState.refreshers do
					if sf and sf.Parent and type(refresh) == "function" then
						pcall(refresh)
					else
						uiScaleState.refreshers[sf] = nil
					end
				end
			end
		end)
	end
	uiScaleState.value = Instance.new("NumberValue")
	uiScaleState.value.Name = "InterfaceScaleValue"
	do
		local cfg = settingsConfig.InterfaceScale
		local def = suggestInterfaceScale()
		if type(cfg) == "table" and type(cfg.value) == "number" then
			def = math.clamp(cfg.value, 0.5, 1.65)
		end
		uiScaleState.value.Value = def
	end
	applyInterfaceScale(uiScaleState.value.Value)
	local function setupAutoScroll(sf, fixRows, verticalOnly)
		if not (sf and sf:IsA("ScrollingFrame")) then
			return
		end
		pcall(function()
			sf.AutomaticCanvasSize = Enum.AutomaticSize.None
			sf.CanvasSize = UDim2.new(0, 0, 0, 0)
			if verticalOnly then
				sf.ScrollingDirection = Enum.ScrollingDirection.Y
			end
		end)
		local lay = sf:FindFirstChildWhichIsA("UIListLayout") or sf:FindFirstChildWhichIsA("UIGridLayout")
		if not lay then
			return
		end
		local id = "CanvasAuto_" .. sf:GetDebugId()
		NAlib.disconnect(id)
		local boundVerticalGuis = setmetatable({}, { __mode = "k" })
		local function getUiScaleFactor()
			local sc = uiScaleState and uiScaleState.object
			local factor = sc and tonumber(sc.Scale) or 1
			if not factor or factor <= 0 then
				factor = 1
			end
			return factor
		end
		local function isVisibleInScroll(gui)
			local cur = gui
			while cur and cur ~= sf do
				if cur:IsA("GuiObject") and not cur.Visible then
					return false
				end
				cur = cur.Parent
			end
			return cur == sf
		end
		local function descendantBounds()
			local maxX = 0
			local maxY = 0
			local canvasPos = sf.CanvasPosition
			local uiScaleFactor = getUiScaleFactor()
			if verticalOnly then
				for _, child in sf:GetChildren() do
					if child:IsA("GuiObject") and isVisibleInScroll(child) then
						local relY = ((child.AbsolutePosition.Y - sf.AbsolutePosition.Y) / uiScaleFactor) + canvasPos.Y
						maxY = math.max(maxY, relY + (child.AbsoluteSize.Y / uiScaleFactor))
						for _, desc in child:QueryDescendants("GuiObject") do
							if desc.Name == "Dropdown" and isVisibleInScroll(desc) then								local dRelY = ((desc.AbsolutePosition.Y - sf.AbsolutePosition.Y) / uiScaleFactor) + canvasPos.Y
								maxY = math.max(maxY, dRelY + (desc.AbsoluteSize.Y / uiScaleFactor))
							end
						end
					end
				end
			else
				for _, desc in sf:QueryDescendants("GuiObject") do
					if isVisibleInScroll(desc) then						local relX = ((desc.AbsolutePosition.X - sf.AbsolutePosition.X) / uiScaleFactor) + canvasPos.X
						local relY = ((desc.AbsolutePosition.Y - sf.AbsolutePosition.Y) / uiScaleFactor) + canvasPos.Y
						maxX = math.max(maxX, relX + (desc.AbsoluteSize.X / uiScaleFactor))
						maxY = math.max(maxY, relY + (desc.AbsoluteSize.Y / uiScaleFactor))
					end
				end
			end
			return maxX, maxY
		end
		local function applyRows()
			if not fixRows then
				return
			end
			for _, ch in sf:GetChildren() do
				if
					ch:IsA("GuiObject")
					and ch.Visible
					and not ch:IsA("UIListLayout")
					and not ch:IsA("UIGridLayout")
					and not ch:IsA("UIPadding")
					and ch.Name ~= "LT_SettingDropdown"
				then
					local s = ch.Size
					if s.Y.Scale ~= 0 or s.Y.Offset ~= 50 then
						ch.Size = UDim2.new(s.X.Scale, s.X.Offset, 0, 50)
					end
				end
			end
		end
		local function upd()
			if not __dcm_masterRuntime.alive or __dcm_masterRuntime.stopping then
				return
			end
			applyRows()
			local uiScaleFactor = getUiScaleFactor()
			local size = lay.AbsoluteContentSize
			local sizeX = size.X / uiScaleFactor
			local sizeY = size.Y / uiScaleFactor
			local x
			local y
			if verticalOnly then
				local _, descY = descendantBounds()
				x = 0
				y = math.max(0, math.floor(math.max(sizeY + 12.5, descY + 12.5) + 0.5))
			else
				local descX, descY = descendantBounds()
				x = math.max(0, math.floor(math.max(sizeX, descX) + 0.5))
				y = math.max(0, math.floor(math.max(sizeY + 12.5, descY + 12.5) + 0.5))
			end
			pcall(function()
				if verticalOnly then
					sf.CanvasSize = UDim2.new(0, 0, 0, y)
				else
					sf.CanvasSize = UDim2.new(0, x, 0, y)
				end
			end)
		end
		uiScaleState.refreshers[sf] = upd
		if verticalOnly then
			local function bindVerticalGui(gui)
				if not (gui and gui:IsA("GuiObject")) or boundVerticalGuis[gui] then
					return
				end
				local isDirectChild = gui.Parent == sf
				local isDropdownGui = gui.Name == "Dropdown" or gui.Name == "LT_SettingDropdown"
				if not (isDirectChild or isDropdownGui) then
					return
				end
				boundVerticalGuis[gui] = true
				NAlib.connect(
					id,
					gui:GetPropertyChangedSignal("Visible"):Connect(function()
						task.defer(upd)
					end)
				)
				NAlib.connect(
					id,
					gui:GetPropertyChangedSignal("Size"):Connect(function()
						task.defer(upd)
					end)
				)
				NAlib.connect(
					id,
					gui:GetPropertyChangedSignal("Position"):Connect(function()
						task.defer(upd)
					end)
				)
				NAlib.connect(
					id,
					gui:GetPropertyChangedSignal("AbsoluteSize"):Connect(function()
						task.defer(upd)
					end)
				)
			end
			local function bindVerticalRow(row)
				if not (row and row:IsA("GuiObject")) then
					return
				end
				bindVerticalGui(row)
				for _, desc in row:QueryDescendants("GuiObject") do
					if desc.Name == "Dropdown" then						bindVerticalGui(desc)
					end
				end
				NAlib.connect(
					id,
					row.DescendantAdded:Connect(function(desc)
						if desc:IsA("GuiObject") and desc.Name == "Dropdown" then
							bindVerticalGui(desc)
							task.defer(upd)
						end
					end)
				)
				NAlib.connect(
					id,
					row.DescendantRemoving:Connect(function(desc)
						if desc:IsA("GuiObject") and desc.Name == "Dropdown" then
							task.defer(upd)
						end
					end)
				)
			end
			for _, child in sf:GetChildren() do
				bindVerticalRow(child)
			end
			upd()
			NAlib.connect(id, lay:GetPropertyChangedSignal("AbsoluteContentSize"):Connect(upd))
			NAlib.connect(
				id,
				sf.DescendantAdded:Connect(function(desc)
					if desc.Parent == sf then
						bindVerticalRow(desc)
						task.defer(upd)
					end
				end)
			)
			NAlib.connect(
				id,
				sf.DescendantRemoving:Connect(function()
					task.defer(upd)
				end)
			)
			NAlib.connect(
				id,
				sf:GetPropertyChangedSignal("AbsoluteSize"):Connect(function()
					task.defer(upd)
				end)
			)
			if uiScaleState and uiScaleState.object and uiScaleState.object.GetPropertyChangedSignal then
				NAlib.connect(
					id,
					uiScaleState.object:GetPropertyChangedSignal("Scale"):Connect(function()
						task.defer(upd)
					end)
				)
			end
			return
		end
		local function bindGui(gui)
			if not (gui and gui:IsA("GuiObject")) then
				return
			end
			NAlib.connect(
				id,
				gui:GetPropertyChangedSignal("Visible"):Connect(function()
					task.defer(upd)
				end)
			)
			NAlib.connect(
				id,
				gui:GetPropertyChangedSignal("Size"):Connect(function()
					task.defer(upd)
				end)
			)
			NAlib.connect(
				id,
				gui:GetPropertyChangedSignal("Position"):Connect(function()
					task.defer(upd)
				end)
			)
			NAlib.connect(
				id,
				gui:GetPropertyChangedSignal("AbsoluteSize"):Connect(function()
					task.defer(upd)
				end)
			)
		end
		for _, desc in sf:QueryDescendants("Instance") do
			bindGui(desc)
		end
		upd()
		NAlib.connect(id, lay:GetPropertyChangedSignal("AbsoluteContentSize"):Connect(upd))
		NAlib.connect(
			id,
			sf.DescendantAdded:Connect(function(desc)
				bindGui(desc)
				task.defer(upd)
			end)
		)
		NAlib.connect(
			id,
			sf.DescendantRemoving:Connect(function()
				task.defer(upd)
			end)
		)
		NAlib.connect(
			id,
			sf:GetPropertyChangedSignal("AbsoluteSize"):Connect(function()
				task.defer(upd)
			end)
		)
		if uiScaleState and uiScaleState.object and uiScaleState.object.GetPropertyChangedSignal then
			NAlib.connect(
				id,
				uiScaleState.object:GetPropertyChangedSignal("Scale"):Connect(function()
					task.defer(upd)
				end)
			)
		end
	end
	local function mkDock(fr)
		local d = Instance.new("Frame")
		d.Name = "Dock"
		d.BackgroundTransparency = 1
		d.AnchorPoint = Vector2.new(1, 0.5)
		d.Position = UDim2.new(1, -14, 0.5, 0)
		d.Size = UDim2.new(0, 320, 0, 18)
		d.Parent = fr
		local l = Instance.new("UIListLayout")
		l.FillDirection = Enum.FillDirection.Horizontal
		l.HorizontalAlignment = Enum.HorizontalAlignment.Right
		l.VerticalAlignment = Enum.VerticalAlignment.Center
		l.Padding = UDim.new(0, 8)
		l.Parent = d
		return d
	end
	local function mkTog(par)
		local t = Instance.new("TextButton")
		t.Name = "Toggle"
		t.Size = UDim2.new(0, 18, 0, 18)
		t.BackgroundColor3 = Color3.fromRGB(30, 30, 30)
		t.BorderSizePixel = 0
		t.Font = Enum.Font.GothamBold
		t.TextSize = 11
		t.TextColor3 = Color3.new(1, 1, 1)
		t.Text = "C"
		t.Parent = par
		local c = Instance.new("UICorner")
		c.CornerRadius = UDim.new(0, 4)
		c.Parent = t
		return t
	end
	local function mkBox(par)
		local b = Instance.new("TextBox")
		b.Name = "ValueBox"
		b.Size = UDim2.new(0, 70, 0, 18)
		b.BackgroundColor3 = Color3.fromRGB(20, 20, 20)
		b.BorderSizePixel = 0
		b.ClearTextOnFocus = false
		b.TextXAlignment = Enum.TextXAlignment.Center
		b.Font = Enum.Font.Gotham
		b.TextSize = 12
		b.TextColor3 = Color3.new(1, 1, 1)
		b.Parent = par
		return b
	end
	local function mkSl(par, w)
		local s = Instance.new("Frame")
		s.Name = "Slider"
		s.BackgroundTransparency = 1
		s.Size = UDim2.new(0, w or 150, 0, 18)
		s.Parent = par
		local bar = Instance.new("Frame")
		bar.Name = "Bar"
		bar.BackgroundColor3 = Color3.fromRGB(40, 40, 40)
		bar.BorderSizePixel = 0
		bar.AnchorPoint = Vector2.new(0.5, 0.5)
		bar.Position = UDim2.new(0.5, 0, 0.5, 0)
		bar.Size = UDim2.new(1, 0, 0, 6)
		bar.Parent = s
		local bc = Instance.new("UICorner")
		bc.CornerRadius = UDim.new(0, 3)
		bc.Parent = bar
		local fill = Instance.new("Frame")
		fill.Name = "Fill"
		fill.BorderSizePixel = 0
		fill.AnchorPoint = Vector2.new(0, 0.5)
		fill.Position = UDim2.new(0, 0, 0.5, 0)
		fill.Size = UDim2.new(0, 0, 1, 0)
		fill.Parent = bar
		local fc = Instance.new("UICorner")
		fc.CornerRadius = UDim.new(0, 3)
		fc.Parent = fill
		local kb = Instance.new("Frame")
		kb.Name = "Knob"
		kb.Size = UDim2.new(0, 12, 0, 12)
		kb.AnchorPoint = Vector2.new(0.5, 0.5)
		kb.BackgroundColor3 = Color3.new(1, 1, 1)
		kb.BorderSizePixel = 0
		kb.Parent = bar
		local kc = Instance.new("UICorner")
		kc.CornerRadius = UDim.new(1, 0)
		kc.Parent = kb
		return s, bar, fill, kb
	end
	local customDropdownMenus = {}
	local function closeCustomDropdowns(exceptMenu)
		for i = #customDropdownMenus, 1, -1 do
			local entry = customDropdownMenus[i]
			local menu = type(entry) == "table" and entry.menu or entry
			if not (menu and menu.Parent) then
				table.remove(customDropdownMenus, i)
			elseif menu ~= exceptMenu then
				if type(entry) == "table" then
					if type(entry.collapse) == "function" then
						pcall(entry.collapse)
					elseif entry.row and entry.row.Parent then
						pcall(function()
							menu.Visible = false
						end)
						local baseHeight = tonumber(entry.baseHeight) or 50
						local s = entry.row.Size
						entry.row.Size = UDim2.new(s.X.Scale, s.X.Offset, 0, baseHeight)
					end
				else
					pcall(function()
						menu.Visible = false
					end)
				end
			end
		end
	end
	if settingsHolder then
		for _, c in settingsHolder:GetChildren() do
			if c:IsA("Frame") and c.Name == "Button" then
				settingTemplate = c
				break
			end
		end
	end
	local hiddenStockDropdownTitles = {
		["fps cap"] = true,
		["icon size"] = true,
		["icon color"] = true,
		["icon shape"] = true,
	}
	local hiddenStockDropdownBound = setmetatable({}, { __mode = "k" })
	local function enforceHiddenStockDropdownRow(child)
		if not (child and child.Parent and child:IsA("Frame")) then
			return
		end
		local size = child.Size
		__dcm_setTracked(child, "Visible", false)
		__dcm_setTracked(child, "Size", UDim2.new(size.X.Scale, size.X.Offset, 0, 0))
	end
	local function bindHiddenStockDropdownRow(child)
		if not (child and child:IsA("Frame") and child.Name == "SettingDropdown") then
			return
		end
		local title = child:FindFirstChild("Title", true)
		local titleText = title and title:IsA("TextLabel") and string.lower(title.Text or "") or ""
		if not hiddenStockDropdownTitles[titleText] then
			return
		end
		enforceHiddenStockDropdownRow(child)
		if not hiddenStockDropdownBound[child] then
			hiddenStockDropdownBound[child] = true
			local guardId = "HideManagedStockDropdownRows_" .. child:GetDebugId()
			NAlib.disconnect(guardId)
			NAlib.connect(
				guardId,
				child:GetPropertyChangedSignal("Visible"):Connect(function()
					if child.Visible then
						enforceHiddenStockDropdownRow(child)
					end
				end)
			)
			NAlib.connect(
				guardId,
				child:GetPropertyChangedSignal("Size"):Connect(function()
					if child.Visible or child.Size.Y.Offset ~= 0 or child.Size.Y.Scale ~= 0 then
						enforceHiddenStockDropdownRow(child)
					end
				end)
			)
			child.Destroying:Connect(function()
				hiddenStockDropdownBound[child] = nil
				NAlib.disconnect(guardId)
			end)
		end
	end
	local function hideManagedStockDropdownRows()
		if not settingsHolder then
			return
		end
		for _, child in settingsHolder:GetChildren() do
			if child:IsA("Frame") then
				bindHiddenStockDropdownRow(child)
			end
		end
	end
	if settingsHolder then
		task.defer(hideManagedStockDropdownRows)
		NAlib.disconnect("HideManagedStockDropdownRows")
		NAlib.connect(
			"HideManagedStockDropdownRows",
			settingsHolder.ChildAdded:Connect(function(child)
				task.defer(function()
					bindHiddenStockDropdownRow(child)
				end)
			end)
		)
	end
	if settingsHolder and settingTemplate then
		local function makeSectionTitle(text, order, isCustom)
			local f = __dcm_registerCustom(settingTemplate:Clone())
			f.Name = isCustom and "Section_Customization" or "Section_Delta"
			f.Parent = settingsHolder
			f.LayoutOrder = order
			for _, d in f:QueryDescendants("LocalScript") do
				d:Destroy()
			end
			local btn = f:FindFirstChild("Button", true)
			if btn then
				btn:Destroy()
			end
			local tLabel = f:FindFirstChild("Title", true)
			local dLabel = f:FindFirstChild("Desc", true)
			local baseCol = isCustom and Color3.fromRGB(79, 164, 242) or Color3.fromRGB(112, 118, 132)
			local fillCol = Color3.fromRGB(25, 28, 35)
			local edgeCol = isCustom and Color3.fromRGB(88, 152, 223) or Color3.fromRGB(63, 68, 80)
			f.BackgroundColor3 = fillCol
			local outline = f:FindFirstChildWhichIsA("UIStroke", true)
			if outline then
				outline.Color = edgeCol
				outline.Transparency = 0.34
				outline.Thickness = 1
			end
			local panelGrad = f:FindFirstChildWhichIsA("UIGradient", true)
			if panelGrad then
				panelGrad.Color = ColorSequence.new({
					ColorSequenceKeypoint.new(0, Color3.fromRGB(28, 31, 38)),
					ColorSequenceKeypoint.new(1, Color3.fromRGB(23, 25, 31)),
				})
				panelGrad.Rotation = 0
			else
				panelGrad = Instance.new("UIGradient")
				panelGrad.Color = ColorSequence.new({
					ColorSequenceKeypoint.new(0, Color3.fromRGB(28, 31, 38)),
					ColorSequenceKeypoint.new(1, Color3.fromRGB(23, 25, 31)),
				})
				panelGrad.Rotation = 0
				panelGrad.Parent = f
			end
			if tLabel then
				tLabel.Text = isCustom and "Customization" or "Delta settings"
				tLabel.AnchorPoint = Vector2.new(0.5, 0.5)
				tLabel.Position = UDim2.new(0.5, 0, 0.5, 0)
				tLabel.Size = UDim2.new(1, -32, 0, 18)
				tLabel.TextColor3 = Color3.fromRGB(236, 240, 247)
				tLabel.TextXAlignment = Enum.TextXAlignment.Center
				tLabel.TextYAlignment = Enum.TextYAlignment.Center
				if isCustom then
					local textGrad = tLabel:FindFirstChildOfClass("UIGradient") or Instance.new("UIGradient")
					textGrad.Color = ColorSequence.new({
						ColorSequenceKeypoint.new(
							0,
							activeColorValue and activeColorValue.Value or Color3.fromRGB(79, 164, 242)
						),
						ColorSequenceKeypoint.new(0.5, Color3.fromRGB(235, 244, 255)),
						ColorSequenceKeypoint.new(
							1,
							inactiveColorValue and inactiveColorValue.Value or Color3.fromRGB(63, 72, 92)
						),
					})
					textGrad.Offset = Vector2.new(-0.8, 0)
					textGrad.Parent = tLabel
					local function refreshCustomSectionColors()
						local activeCol = activeColorValue and activeColorValue.Value or Color3.fromRGB(79, 164, 242)
						local inactiveCol = inactiveColorValue and inactiveColorValue.Value
							or Color3.fromRGB(63, 72, 92)
						textGrad.Color = ColorSequence.new({
							ColorSequenceKeypoint.new(0, activeCol),
							ColorSequenceKeypoint.new(0.5, Color3.fromRGB(235, 244, 255)),
							ColorSequenceKeypoint.new(1, inactiveCol),
						})
						if panelGrad then
							panelGrad.Color = ColorSequence.new({
								ColorSequenceKeypoint.new(0, activeCol:Lerp(Color3.fromRGB(14, 16, 22), 0.74)),
								ColorSequenceKeypoint.new(1, inactiveCol:Lerp(Color3.fromRGB(14, 16, 22), 0.8)),
							})
						end
					end
					refreshCustomSectionColors()
					if activeColorValue then
						activeColorValue:GetPropertyChangedSignal("Value"):Connect(refreshCustomSectionColors)
					end
					if inactiveColorValue then
						inactiveColorValue:GetPropertyChangedSignal("Value"):Connect(refreshCustomSectionColors)
					end
					if TS then
						local alive = true
						f.Destroying:Connect(function()
							alive = false
						end)
						local function animateTextGradient()
							if not alive or not textGrad.Parent then
								return
							end
							textGrad.Offset = Vector2.new(-0.8, 0)
							local tw = TS:Create(
								textGrad,
								TweenInfo.new(1.7, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut),
								{
									Offset = Vector2.new(0.8, 0),
								}
							)
							tw:Play()
							tw.Completed:Connect(function()
								if alive then
									task.delay(0.12, animateTextGradient)
								end
							end)
						end
						local function animateBackground()
							if not alive or not f.Parent then
								return
							end
							local activeCol = activeColorValue and activeColorValue.Value
								or Color3.fromRGB(79, 164, 242)
							local inactiveCol = inactiveColorValue and inactiveColorValue.Value
								or Color3.fromRGB(63, 72, 92)
							local a = activeCol:Lerp(Color3.fromRGB(12, 14, 18), 0.78)
							local b = inactiveCol:Lerp(Color3.fromRGB(12, 14, 18), 0.78)
							local tw1 =
								TS:Create(f, TweenInfo.new(1.25, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {
									BackgroundColor3 = a,
								})
							tw1:Play()
							tw1.Completed:Connect(function()
								if not alive or not f.Parent then
									return
								end
								local tw2 = TS:Create(
									f,
									TweenInfo.new(1.25, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut),
									{
										BackgroundColor3 = b,
									}
								)
								tw2:Play()
								tw2.Completed:Connect(function()
									if alive then
										animateBackground()
									end
								end)
							end)
						end
						animateTextGradient()
						animateBackground()
					end
				end
			end
			if dLabel then
				dLabel.Text = ""
				dLabel.Visible = false
			end
			return f
		end
		makeSectionTitle("Customization", -3, true)
		makeSectionTitle("Delta settings", -1, false)
	end
	if sidebar then
		local existingGrad = sidebar:FindFirstChildOfClass("UIGradient")
		local c1
		local c2
		if existingGrad then
			local kps = existingGrad.Color.Keypoints
			c1 = kps[1] and kps[1].Value or Color3.fromRGB(79, 164, 242)
			c2 = kps[#kps] and kps[#kps].Value or Color3.fromRGB(28, 34, 46)
			sidebarGradient = existingGrad
		else
			c1 = Color3.fromRGB(79, 164, 242)
			c2 = Color3.fromRGB(28, 34, 46)
			sidebarGradient = Instance.new("UIGradient")
			sidebarGradient.Name = "DeltaCustomGradient"
			sidebarGradient.Parent = sidebar
		end
		sidebarGradient.Rotation = 100
		sidebarGradient.Color = ColorSequence.new({
			ColorSequenceKeypoint.new(0, c1),
			ColorSequenceKeypoint.new(1, c2),
		})
		sidebarGrad1 = Instance.new("Color3Value")
		sidebarGrad1.Name = "SidebarGradientColor1"
		sidebarGrad1.Value = c1
		sidebarGrad2 = Instance.new("Color3Value")
		sidebarGrad2.Name = "SidebarGradientColor2"
		sidebarGrad2.Value = c2
		local sidebarSnapPending = false
		NAlib.disconnect("Sidebar_OvershootSnap")
		NAlib.connect(
			"Sidebar_OvershootSnap",
			(sidebar:GetPropertyChangedSignal("Position")):Connect(function()
			local p = sidebar.Position
			if p.X.Scale > sidebarOpenPos.X.Scale and not sidebarSnapPending then
				sidebarSnapPending = true
				task.spawn(function()
					local last = p
					local stable = 0
					local step = 0.05
					while stable < 0.1 do
						task.wait(step)
						local cur = sidebar.Position
						if cur ~= last then
							last = cur
							stable = 0
						else
							stable += step
						end
					end
					sidebarSnapPending = false
					if sidebar.Parent and sidebar.Position.X.Scale > sidebarOpenPos.X.Scale then
						setSidebarPosition(sidebarClosedPos)
						normalizeSidebarGeometry()
					end
				end)
			end
		end)
		)
	end
	local iconColorValue
	if iconStroke then
		iconColorValue = Instance.new("Color3Value")
		iconColorValue.Name = "IconColorValue"
		iconColorValue.Value = iconBaseColor or iconStroke.Color
		NAlib.connect(
			"IconColorValue_Changed",
			iconColorValue.Changed:Connect(function()
				if not iconColorUseCustom then
					return
				end
				pcall(function()
					iconStroke.Color = iconColorValue.Value
				end)
			end)
		)
	end
	local iconSizeValue
	if iconBtn and iconBaseSize then
		iconSizeValue = Instance.new("NumberValue")
		iconSizeValue.Name = "IconSizeValue"
		iconSizeValue.Value = 1
		local sizeCfg = settingsConfig.IconSize
		if type(sizeCfg) == "table" and type(sizeCfg.value) == "number" then
			iconSizeValue.Value = math.clamp(sizeCfg.value, 0.5, 5)
		end
		local function applyIconSize(v)
			v = math.clamp(v, 0.5, 5)
			if not iconBtn or not iconBaseSize then
				return
			end
			iconSzLock = true
			iconBtn.Size = UDim2.new(
				iconBaseSize.X.Scale * v,
				iconBaseSize.X.Offset * v,
				iconBaseSize.Y.Scale * v,
				iconBaseSize.Y.Offset * v
			)
			iconSzLock = false
		end
		if iconBtn and iconBtn.GetPropertyChangedSignal and mainGui and mainGui.GetPropertyChangedSignal then
			NAlib.connect(
				"IconSizeRebase",
				(mainGui:GetPropertyChangedSignal("AbsoluteSize")):Connect(function()
					task.defer(function()
						if iconBtn and iconSizeValue and not iconSzLock then
							local v = math.clamp(iconSizeValue.Value, 0.5, 5)
							local s = iconBtn.Size
							iconBaseSize = UDim2.new(s.X.Scale / v, s.X.Offset / v, s.Y.Scale / v, s.Y.Offset / v)
							applyIconSize(v)
						end
					end)
				end)
			)
		end
		NAlib.connect(
			"IconSizeValue_Changed",
			iconSizeValue.Changed:Connect(function()
				applyIconSize(iconSizeValue.Value)
				if HS and type(writefile) == "function" then
					settingsConfig.IconSize = { value = math.clamp(iconSizeValue.Value, 0.5, 5) }
						writeJsonFile(settingsPath, settingsConfig)
				end
			end)
		)
		applyIconSize(iconSizeValue.Value)
	end
	local function ensureIconCorner()
		refreshIconRefs()
		if not iconBtn then
			return nil
		end
		if not iconCorner then
			iconCorner = Instance.new("UICorner")
			iconCorner.Name = "DeltaIconCorner"
			iconCorner.Parent = iconBtn
		end
		if not iconBaseCorner then
			iconBaseCorner = iconCorner.CornerRadius
		end
		return iconCorner
	end
	local iconShapeName = "Squircle"
	do
		local cfg = settingsConfig.IconShape
		if type(cfg) == "table" and type(cfg.name) == "string" and cfg.name ~= "" then
			iconShapeName = cfg.name
		end
	end
	if iconShapeName == "Default" then
		iconShapeName = "Squircle"
	elseif iconShapeName == "Pill" then
		iconShapeName = "Circle"
	end
	local function getIconShapeCorner(shapeName)
		if shapeName == "Square" then
			return UDim.new(0, 0)
		elseif shapeName == "Rounded" then
			return UDim.new(0, 8)
		elseif shapeName == "Squircle" then
			return UDim.new(0, 12)
		elseif shapeName == "Circle" then
			return UDim.new(1, 0)
		end
		return UDim.new(0, 12)
	end
	applyIconShapeChoice = function()
		local corner = ensureIconCorner()
		if not corner then
			return
		end
		pcall(function()
			corner.CornerRadius = getIconShapeCorner(iconShapeName)
		end)
	end
	task.defer(applyIconShapeChoice)
	local iconRgbSpeedValue
	if iconStroke then
		iconRgbSpeedValue = Instance.new("NumberValue")
		iconRgbSpeedValue.Name = "IconRgbSpeedValue"
		local sp = 0.2
		local spCfg = settingsConfig.IconRgbSpeed
		if type(spCfg) == "table" and type(spCfg.value) == "number" then
			sp = math.clamp(spCfg.value, 0.05, 2)
		end
		iconRgbSpeedValue.Value = sp
	end
	local iconVisible = true
	do
		local cfg = settingsConfig.IconVisible
		if type(cfg) == "table" and cfg.enabled ~= nil then
			iconVisible = cfg.enabled and true or false
		end
	end
	local iconPositionSaveEnabled = false
	do
		local cfg = settingsConfig.IconPositionSave
		if type(cfg) == "table" and cfg.enabled ~= nil then
			iconPositionSaveEnabled = cfg.enabled and true or false
		end
	end
	local iconStrokeUserEnabled = true
	do
		local cfg = settingsConfig.IconStrokeEnabled
		if type(cfg) == "table" and cfg.enabled ~= nil then
			iconStrokeUserEnabled = cfg.enabled and true or false
		end
	end
	local iconForcedHidden = false
	local tabNotifEnabled = true
	do
		local cfg = settingsConfig.TabNotifications
		if type(cfg) == "table" and cfg.enabled ~= nil then
			tabNotifEnabled = cfg.enabled and true or false
		end
	end
	local function tweenIconVisual(imgT, bgT, instant)
		if not iconBtn then
			return
		end
		if imgT < 1 or bgT < 1 then
			pcall(function()
				iconBtn.Visible = true
			end)
		end
		if TS and not instant then
			pcall(function()
				(__lt.cm(
					"TweenService",
					"Create",
					iconBtn,
					TweenInfo.new(0.18, Enum.EasingStyle.Quad, Enum.EasingDirection.Out),
					{
						ImageTransparency = imgT,
						BackgroundTransparency = bgT,
					}
				)):Play()
			end)
		else
			pcall(function()
				iconBtn.ImageTransparency = imgT
				iconBtn.BackgroundTransparency = bgT
			end)
		end
	end
	local function updateManagedIconDisplay(instant)
		if not iconBtn then
			return
		end
		local shouldShow = iconVisible and not iconForcedHidden
		pcall(function()
			iconBtn.Active = true
		end)
		pcall(function()
			iconBtn.Interactable = true
		end)
		if shouldShow then
			pcall(function()
				iconBtn.Visible = true
			end)
			tweenIconVisual(0, 0, instant)
		else
			if not iconForcedHidden then
				pcall(function()
					iconBtn.Visible = true
				end)
			end
			tweenIconVisual(1, 1, instant)
			if iconForcedHidden then
				local stamp = tick()
				task.delay(instant and 0 or 0.2, function()
					if not iconBtn or not iconBtn.Parent then
						return
					end
					if stamp and not iconForcedHidden then
						return
					end
					pcall(function()
						iconBtn.Visible = false
					end)
				end)
			end
		end
		applyIconStrokeState()
	end
	applyIconStrokeState = function()
		if not iconStroke then
			return
		end
		pcall(function()
			iconStroke.Enabled = iconVisible and iconStrokeUserEnabled and not iconForcedHidden
		end)
	end
	local function saveManagedIconPosition()
		if not (iconPositionSaveEnabled and iconBtn and iconBtn.Parent) then
			return
		end
		saveSettingsEntry("IconPosition", {
			xScale = iconBtn.Position.X.Scale,
			xOffset = iconBtn.Position.X.Offset,
			yScale = iconBtn.Position.Y.Scale,
			yOffset = iconBtn.Position.Y.Offset,
		})
	end
	applySavedManagedIconPosition = function()
		if not (iconPositionSaveEnabled and iconBtn and iconBtn.Parent) then
			return
		end
		local cfg = settingsConfig.IconPosition
		if type(cfg) ~= "table" then
			return
		end
		local xs = tonumber(cfg.xScale)
		local xo = tonumber(cfg.xOffset)
		local ys = tonumber(cfg.yScale)
		local yo = tonumber(cfg.yOffset)
		if xs and xo and ys and yo then
			pcall(function()
				iconBtn.Position = UDim2.new(xs, xo, ys, yo)
			end)
		end
	end
	bindManagedIconPositionSaver = function()
		NAlib.disconnect("ManagedIcon_PositionSave")
		if not (iconBtn and iconBtn.Parent) then
			return
		end
		local stamp = 0
		NAlib.connect(
			"ManagedIcon_PositionSave",
			iconBtn:GetPropertyChangedSignal("Position"):Connect(function()
				if not iconPositionSaveEnabled then
					return
				end
				stamp += 1
				local cur = stamp
				task.delay(0.2, function()
					if cur == stamp then
						saveManagedIconPosition()
					end
				end)
			end)
		)
	end
	local function applyIconUserVisibility(instant)
		updateManagedIconDisplay(instant)
	end
	local function setIconForcedHidden(hidden)
		iconForcedHidden = hidden and true or false
		if not iconBtn then
			return
		end
		updateManagedIconDisplay(false)
	end
	task.defer(function()
		applySavedManagedIconPosition()
		bindManagedIconPositionSaver()
	end)
	applyIconUserVisibility(true)
	local scriptHubHolder
	local homeHolder
	do
		local sh = mainGui:FindFirstChild("Scripthub")
		if sh then
			scriptHubHolder = sh:FindFirstChild("Holder")
		end
		local ho = mainGui:FindFirstChild("Home")
		if ho then
			homeHolder = ho:FindFirstChild("Holder")
		end
	end
	setupAutoScroll(settingsHolder, true, true)
	setupAutoScroll(scriptHubHolder, false, false)
	setupAutoScroll(homeHolder, true, true)
	local function makeColorSlider(id, tt, dt, cVal)
		if not (settingsHolder and settingTemplate and cVal) then
			return
		end
		local key = id or tt or "Color_" .. tostring(math.random(1, 1000000000))
		local slId = "ColorSlider_" .. key
		local isIc = id == "IconColor" and iconStroke ~= nil
		local fr = __dcm_registerCustom(settingTemplate:Clone())
		fr.Parent = settingsHolder
		fr.Visible = true
		fr.LayoutOrder = -2
		for _, d in fr:QueryDescendants("LocalScript") do
			d:Destroy()
		end
		local tL = fr:FindFirstChild("Title", true)
		local dL = fr:FindFirstChild("Desc", true)
		if tL then
			tL.Text = tt
		end
		if dL then
			dL.Text = dt
		end
		local ob = fr:FindFirstChild("Button", true)
		local ord = 0
		if ob then
			ord = ob.LayoutOrder
			ob:Destroy()
		end
		local pad = 14
		local vbW = 74
		local tgW = 20
		local slW = 190
		local sl = Instance.new("Frame")
		sl.Name = "ColorSlider"
		sl.BackgroundTransparency = 1
		sl.Size = UDim2.new(0, slW, 1, 0)
		sl.AnchorPoint = Vector2.new(1, 0.5)
		sl.LayoutOrder = ord
		sl.Parent = fr
		local vb = Instance.new("TextBox")
		vb.Name = "ColorValue"
		vb.Size = UDim2.new(0, vbW, 0, 18)
		vb.AnchorPoint = Vector2.new(1, 0.5)
		vb.BackgroundColor3 = Color3.fromRGB(20, 20, 20)
		vb.BorderSizePixel = 0
		vb.ClearTextOnFocus = false
		vb.TextXAlignment = Enum.TextXAlignment.Center
		vb.Font = Enum.Font.Gotham
		vb.TextSize = 12
		vb.TextColor3 = Color3.new(1, 1, 1)
		vb.Parent = fr
		local tg = Instance.new("TextButton")
		tg.Name = "Toggle"
		tg.Size = UDim2.new(0, tgW, 0, 18)
		tg.AnchorPoint = Vector2.new(1, 0.5)
		tg.BackgroundColor3 = Color3.fromRGB(30, 30, 30)
		tg.BorderSizePixel = 0
		tg.Font = Enum.Font.GothamBold
		tg.TextSize = 11
		tg.TextColor3 = Color3.new(1, 1, 1)
		tg.Text = "C"
		tg.Parent = fr
		local tgc = Instance.new("UICorner")
		tgc.CornerRadius = UDim.new(0, 4)
		tgc.Parent = tg
		local function lay()
			local y = 0.5
			vb.Position = UDim2.new(1, -pad, y, 0)
			tg.Position = UDim2.new(1, -(pad + vbW + 8), y, 0)
			sl.Position = UDim2.new(1, -(pad + vbW + 8 + tgW + 8), y, 0)
		end
		lay();
		(fr:GetPropertyChangedSignal("AbsoluteSize")):Connect(lay)
		local function mkBar(nm, yy)
			local b = Instance.new("Frame")
			b.Name = nm
			b.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
			b.BorderSizePixel = 0
			b.AnchorPoint = Vector2.new(0.5, 0)
			b.Position = UDim2.new(0.5, 0, yy, 0)
			b.Size = UDim2.new(1, 0, 0, 5)
			b.Active = true
			b.Parent = sl
			local bc = Instance.new("UICorner")
			bc.CornerRadius = UDim.new(0, 3)
			bc.Parent = b
			local k = Instance.new("Frame")
			k.Name = "Knob"
			k.Size = UDim2.new(0, 9, 0, 9)
			k.AnchorPoint = Vector2.new(0.5, 0.5)
			k.Position = UDim2.new(0, 0, 0.5, 0)
			k.BackgroundColor3 = Color3.new(1, 1, 1)
			k.BorderSizePixel = 0
			k.Parent = b
			local kc = Instance.new("UICorner")
			kc.CornerRadius = UDim.new(1, 0)
			kc.Parent = k
			return b, k
		end
		local bH, kH = mkBar("Hue", 0.2)
		local bS, kS = mkBar("Sat", 0.5)
		local bV, kV = mkBar("Val", 0.8)
		local gH = Instance.new("UIGradient")
		gH.Rotation = 0
		gH.Color = ColorSequence.new({
			ColorSequenceKeypoint.new(0, Color3.fromRGB(255, 0, 0)),
			ColorSequenceKeypoint.new(0.17, Color3.fromRGB(255, 255, 0)),
			ColorSequenceKeypoint.new(0.33, Color3.fromRGB(0, 255, 0)),
			ColorSequenceKeypoint.new(0.5, Color3.fromRGB(0, 255, 255)),
			ColorSequenceKeypoint.new(0.67, Color3.fromRGB(0, 0, 255)),
			ColorSequenceKeypoint.new(0.83, Color3.fromRGB(255, 0, 255)),
			ColorSequenceKeypoint.new(1, Color3.fromRGB(255, 0, 0)),
		})
		gH.Parent = bH
		local gS = Instance.new("UIGradient")
		gS.Rotation = 0
		gS.Parent = bS
		local gV = Instance.new("UIGradient")
		gV.Rotation = 0
		gV.Parent = bV
		local defC = cVal.Value or Color3.new(1, 1, 1)
		local cOn = true
		local lastC = defC
		local sv = colorConfig[key]
		if type(sv) == "table" then
			if type(sv.customColor) == "table" and #sv.customColor == 3 then
				lastC = Color3.new(sv.customColor[1], sv.customColor[2], sv.customColor[3])
			end
			if sv.useCustom ~= nil then
				cOn = sv.useCustom and true or false
			end
		end
		local h, s, v = Color3.toHSV(lastC)
		local function boxC(c)
			vb.Text = string.format(
				"%d,%d,%d",
				math.floor(c.R * 255 + 0.5),
				math.floor(c.G * 255 + 0.5),
				math.floor(c.B * 255 + 0.5)
			)
		end
		local function save()
			if not (HS and type(writefile) == "function") then
				return
			end
			colorConfig[key] = {
				useCustom = cOn,
				customColor = { lastC.R, lastC.G, lastC.B },
			}
			writeJsonFile(colorsPath, colorConfig)
		end
		local function updGrad()
			gS.Color = ColorSequence.new({
				ColorSequenceKeypoint.new(0, Color3.fromHSV(h, 0, v)),
				ColorSequenceKeypoint.new(1, Color3.fromHSV(h, 1, v)),
			})
			gV.Color = ColorSequence.new({
				ColorSequenceKeypoint.new(0, Color3.fromHSV(h, s, 0)),
				ColorSequenceKeypoint.new(1, Color3.fromHSV(h, s, 1)),
			})
		end
		local function setVis()
			kH.Position = UDim2.new(h, 0, 0.5, 0)
			kS.Position = UDim2.new(s, 0, 0.5, 0)
			kV.Position = UDim2.new(v, 0, 0.5, 0)
			updGrad()
			boxC(Color3.fromHSV(h, s, v))
		end
		local function applyC(col, st)
			if cVal then
				cVal.Value = col
			end
			if st then
				lastC = col
			end
			save()
		end
		local function setHSV(nh, ns, nv, st)
			h = math.clamp(nh, 0, 1)
			s = math.clamp(ns, 0, 1)
			v = math.clamp(nv, 0, 1)
			setVis()
			applyC(Color3.fromHSV(h, s, v), st)
		end
		local function syncFromC(col)
			h, s, v = Color3.toHSV(col)
			setVis()
		end
		if cOn then
			if isIc then
				iconColorUseCustom = true
			end
			syncFromC(lastC)
			applyC(lastC, false)
			tg.Text = "C"
		else
			if isIc then
				iconColorUseCustom = false
				if iconStroke then
					pcall(function()
						iconStroke.Color = iconBaseColor or iconStroke.Color
					end)
				end
			end
			syncFromC(defC)
			applyC(defC, false)
			tg.Text = "D"
		end
		local drag = nil
		local function relX(bar, inp)
			local w = bar.AbsoluteSize.X
			if w <= 1 then
				return nil
			end
			local x = (inp.Position.X - bar.AbsolutePosition.X) / w
			if x ~= x then
				x = 0
			end
			return math.clamp(x, 0, 1)
		end
		local function useDrag(inp)
			if not drag then
				return
			end
			local a = relX(drag, inp)
			if not a then
				return
			end
			cOn = true
			tg.Text = "C"
			if isIc then
				iconColorUseCustom = true
			end
			if drag == bH then
				setHSV(a, s, v, true)
			elseif drag == bS then
				setHSV(h, a, v, true)
			elseif drag == bV then
				setHSV(h, s, a, true)
			end
		end
		local function beg(bar, inp)
			if
				inp.UserInputType ~= Enum.UserInputType.MouseButton1
				and inp.UserInputType ~= Enum.UserInputType.Touch
			then
				return
			end
			drag = bar
			useDrag(inp)
		end
		bH.InputBegan:Connect(function(i)
			beg(bH, i)
		end)
		bS.InputBegan:Connect(function(i)
			beg(bS, i)
		end)
		bV.InputBegan:Connect(function(i)
			beg(bV, i)
		end)
		NAlib.disconnect(slId)
		NAlib.connect(
			slId,
			UIS.InputChanged:Connect(function(i)
				if not drag then
					return
				end
				if
					i.UserInputType == Enum.UserInputType.MouseMovement
					or i.UserInputType == Enum.UserInputType.Touch
				then
					useDrag(i)
				end
			end)
		)
		NAlib.connect(
			slId,
			UIS.InputEnded:Connect(function(i)
				if
					i.UserInputType == Enum.UserInputType.MouseButton1
					or i.UserInputType == Enum.UserInputType.Touch
				then
					drag = nil
				end
			end)
		)
		fr.Destroying:Connect(function()
			NAlib.disconnect(slId)
		end)
		vb.FocusLost:Connect(function()
			local txt = vb.Text or ""
			local r, g, b = txt:match("(%d+)%s*,%s*(%d+)%s*,%s*(%d+)")
			r, g, b = tonumber(r), tonumber(g), tonumber(b)
			if r and g and b then
				local col =
					Color3.new(math.clamp(r, 0, 255) / 255, math.clamp(g, 0, 255) / 255, math.clamp(b, 0, 255) / 255)
				cOn = true
				tg.Text = "C"
				if isIc then
					iconColorUseCustom = true
				end
				syncFromC(col)
				applyC(col, true)
			else
				boxC(cVal.Value)
			end
		end)
		tg.MouseButton1Click:Connect(function()
			if cOn then
				cOn = false
				tg.Text = "D"
				if isIc then
					iconColorUseCustom = false
					if iconStroke then
						pcall(function()
							iconStroke.Color = iconBaseColor or iconStroke.Color
						end)
					end
				end
				syncFromC(defC)
				applyC(defC, false)
			else
				cOn = true
				tg.Text = "C"
				if isIc then
					iconColorUseCustom = true
				end
				syncFromC(lastC or defC)
				applyC(lastC or defC, true)
			end
			save()
		end)
	end
	local function makeSizeSlider(id, titleText, descText, numValue, minV, maxV, opts)
		if not (settingsHolder and settingTemplate and numValue) then
			return
		end
		opts = type(opts) == "table" and opts or {}
		local key = id or titleText or "Size_" .. tostring(math.random(1, 1000000000))
		local slId = "SizeSlider_" .. key
		minV = minV or 0.5
		maxV = maxV or 5
		local fr = __dcm_registerCustom(settingTemplate:Clone())
		fr.Parent = settingsHolder
		fr.Visible = true
		fr.LayoutOrder = -2
		local tl = fr:FindFirstChild("Title", true)
		local dl = fr:FindFirstChild("Desc", true)
		if tl then
			tl.Text = titleText
		end
		if dl then
			dl.Text = descText
		end
		local ob = fr:FindFirstChild("Button", true)
		if ob then
			ob:Destroy()
		end
		local dock = mkDock(fr)
		local vb = mkBox(dock)
		local sl, bar, fill, kb = mkSl(dock, 150)
		local sv = settingsConfig[key]
		if type(sv) == "table" and type(sv.value) == "number" then
			numValue.Value = math.clamp(sv.value, minV, maxV)
		end
		local function save(v)
			if opts.persist == false then
				return
			end
			if not (HS and type(writefile) == "function") then
				return
			end
			settingsConfig[key] = { value = v }
			writeJsonFile(settingsPath, settingsConfig)
		end
		local function setVis(v)
			if opts.integer then
				v = math.floor((tonumber(v) or minV) + 0.5)
			end
			v = math.clamp(v, minV, maxV)
			local denom = maxV - minV
			local a = denom ~= 0 and ((v - minV) / denom) or 0
			fill.Size = UDim2.new(a, 0, 1, 0)
			kb.Position = UDim2.new(a, 0, 0.5, 0)
			vb.Text = opts.integer and tostring(v) or string.format("%.2f", v)
		end
		local function commit(v)
			if opts.integer then
				v = math.floor((tonumber(v) or minV) + 0.5)
			end
			v = math.clamp(v, minV, maxV)
			numValue.Value = v
			setVis(v)
			save(v)
			if type(opts.apply) == "function" then
				pcall(opts.apply, v)
			end
		end
		setVis(numValue.Value)
		local drag = false
		local pendingValue = numValue.Value
		local function fromIn(input)
			local rel = 0
			pcall(function()
				rel = (input.Position.X - bar.AbsolutePosition.X) / bar.AbsoluteSize.X
			end)
			rel = math.clamp(rel, 0, 1)
			local nextV = minV + (maxV - minV) * rel
			if opts.integer then
				nextV = math.floor(nextV + 0.5)
			end
			if opts.applyOnRelease then
				pendingValue = nextV
				setVis(nextV)
			else
				commit(nextV)
			end
		end
		bar.InputBegan:Connect(function(input)
			if
				input.UserInputType == Enum.UserInputType.MouseButton1
				or input.UserInputType == Enum.UserInputType.Touch
			then
				drag = true
				fromIn(input)
			end
		end)
		NAlib.disconnect(slId)
		NAlib.connect(
			slId,
			UIS.InputChanged:Connect(function(input)
				if not drag then
					return
				end
				if
					input.UserInputType == Enum.UserInputType.MouseMovement
					or input.UserInputType == Enum.UserInputType.Touch
				then
					fromIn(input)
				end
			end)
		)
		NAlib.connect(
			slId,
			UIS.InputEnded:Connect(function(input)
				if
					input.UserInputType == Enum.UserInputType.MouseButton1
					or input.UserInputType == Enum.UserInputType.Touch
				then
					if drag and opts.applyOnRelease then
						commit(pendingValue)
					end
					drag = false
				end
			end)
		)
		fr.Destroying:Connect(function()
			NAlib.disconnect(slId)
		end)
		vb.FocusLost:Connect(function()
			local v = tonumber(vb.Text or "")
			if v then
				commit(v)
			else
				setVis(numValue.Value)
			end
		end)
		local function updDock()
			local w = math.clamp(math.floor(fr.AbsoluteSize.X * 0.46), 240, 380)
			dock.Size = UDim2.new(0, w, 0, 18)
			local sw = math.clamp(w - 78, 140, 280)
			sl.Size = UDim2.new(0, sw, 0, 18)
		end
		updDock()
		fr:GetPropertyChangedSignal("AbsoluteSize"):Connect(function()
			task.defer(updDock)
		end)
	end
	local function makeEnumDropdown(id, titleText, descText, enumItems, getCurrentName, setSelectedName, opts)
		if not (settingsHolder and settingTemplate and type(setSelectedName) == "function") then
			return
		end
		opts = type(opts) == "table" and opts or {}
		local names = {}
		for _, item in enumItems or {} do
			if typeof(item) == "EnumItem" then
				names[#names + 1] = item.Name
			elseif type(item) == "string" and item ~= "" then
				names[#names + 1] = item
			end
		end
		if #names == 0 then
			return
		end
		local baseHeight = 50
		local fr = Instance.new("Frame")
		fr.Name = "LT_SettingDropdown"
		fr.Parent = settingsHolder
		fr.Visible = true
		fr.LayoutOrder = -2
		fr.BackgroundTransparency = 1
		fr.BorderSizePixel = 0
		fr.ClipsDescendants = false
		fr.Size = UDim2.new(1, 0, 0, baseHeight)
		local card = __dcm_registerCustom(settingTemplate:Clone())
		card.Name = "Card"
		card.Parent = fr
		card.Visible = true
		card.Size = UDim2.new(1, 0, 0, baseHeight)
		card.Position = UDim2.new(0, 0, 0, 0)
		for _, d in card:QueryDescendants("LocalScript") do
			d:Destroy()
		end
		local tl = card:FindFirstChild("Title", true)
		local dl = card:FindFirstChild("Desc", true)
		if tl then
			tl.Text = titleText
			tl.TextScaled = false
			tl.TextWrapped = false
			tl.TextTruncate = Enum.TextTruncate.AtEnd
			tl.TextYAlignment = Enum.TextYAlignment.Center
		end
		if dl then
			dl.Text = descText
			dl.TextScaled = false
			dl.TextWrapped = false
			dl.TextTruncate = Enum.TextTruncate.AtEnd
			dl.TextYAlignment = Enum.TextYAlignment.Center
		end
		local ob = card:FindFirstChild("Button", true)
		if ob then
			ob:Destroy()
		end
		local dock = mkDock(card)
		local dockLayout = dock:FindFirstChildWhichIsA("UIListLayout")
		if dockLayout then
			dockLayout:Destroy()
		end
		dock.Size = UDim2.new(0, 168, 0, 30)
		local openBg = Instance.new("Frame")
		openBg.Name = "DropdownBackground"
		openBg.AnchorPoint = Vector2.new(1, 0.5)
		openBg.Position = UDim2.new(1, 0, 0.5, 0)
		openBg.Size = UDim2.new(1, 0, 1, 0)
		openBg.BackgroundColor3 = Color3.fromRGB(39, 42, 52)
		openBg.BorderSizePixel = 0
		openBg.ZIndex = 25
		openBg.Parent = dock
		local openBgCorner = Instance.new("UICorner")
		openBgCorner.CornerRadius = UDim.new(0, 12)
		openBgCorner.Parent = openBg
		local openBtn = Instance.new("TextButton")
		openBtn.Name = "DropdownButton"
		openBtn.Size = UDim2.new(1, 0, 1, 0)
		openBtn.BackgroundTransparency = 1
		openBtn.BorderSizePixel = 0
		openBtn.AutoButtonColor = false
		openBtn.Font = Enum.Font.GothamBold
		openBtn.TextSize = 12
		openBtn.TextColor3 = Color3.fromRGB(164, 169, 182)
		openBtn.TextXAlignment = Enum.TextXAlignment.Right
		openBtn.ZIndex = 27
		openBtn.Parent = dock
		local openPad = Instance.new("UIPadding")
		openPad.PaddingLeft = UDim.new(0, 8)
		openPad.PaddingRight = UDim.new(0, 30)
		openPad.Parent = openBtn
		local arrow = Instance.new("Frame")
		arrow.Name = "Arrow"
		arrow.BackgroundTransparency = 1
		arrow.AnchorPoint = Vector2.new(1, 0.5)
		arrow.Position = UDim2.new(1, -8, 0.5, 0)
		arrow.Size = UDim2.new(0, 12, 0, 18)
		arrow.ZIndex = 28
		arrow.Parent = dock
		local arrowLayout = Instance.new("UIListLayout")
		arrowLayout.FillDirection = Enum.FillDirection.Vertical
		arrowLayout.HorizontalAlignment = Enum.HorizontalAlignment.Center
		arrowLayout.VerticalAlignment = Enum.VerticalAlignment.Center
		arrowLayout.Padding = UDim.new(0, 0)
		arrowLayout.Parent = arrow
		local upArrow = Instance.new("TextLabel")
		upArrow.Name = "Up"
		upArrow.BackgroundTransparency = 1
		upArrow.Size = UDim2.new(1, 0, 0, 9)
		upArrow.Font = Enum.Font.GothamBold
		upArrow.TextSize = 9
		upArrow.TextColor3 = Color3.fromRGB(104, 110, 124)
		upArrow.Text = "^"
		upArrow.ZIndex = 28
		upArrow.Parent = arrow
		local downArrow = Instance.new("TextLabel")
		downArrow.Name = "Down"
		downArrow.BackgroundTransparency = 1
		downArrow.Size = UDim2.new(1, 0, 0, 9)
		downArrow.Font = Enum.Font.GothamBold
		downArrow.TextSize = 9
		downArrow.TextColor3 = Color3.fromRGB(160, 166, 180)
		downArrow.Text = "v"
		downArrow.ZIndex = 28
		downArrow.Parent = arrow
		local menu = Instance.new("ScrollingFrame")
		menu.Name = "Dropdown"
		menu.AnchorPoint = Vector2.new(1, 0)
		menu.Position = UDim2.new(1, -14, 0, baseHeight + 6)
		menu.Size = UDim2.new(0, 168, 0, math.min(132, #names * 30 + 8))
		menu.Visible = false
		menu.BackgroundColor3 = Color3.fromRGB(43, 47, 58)
		menu.BorderSizePixel = 0
		menu.ScrollBarThickness = 3
		menu.ScrollingDirection = Enum.ScrollingDirection.Y
		menu.CanvasSize = UDim2.new(0, 0, 0, 0)
		menu.AutomaticCanvasSize = Enum.AutomaticSize.Y
		menu.ZIndex = 26
		menu.Parent = fr
		local menuCorner = Instance.new("UICorner")
		menuCorner.CornerRadius = UDim.new(0, 10)
		menuCorner.Parent = menu
		local menuPad = Instance.new("UIPadding")
		menuPad.PaddingTop = UDim.new(0, 4)
		menuPad.PaddingBottom = UDim.new(0, 4)
		menuPad.PaddingLeft = UDim.new(0, 12)
		menuPad.PaddingRight = UDim.new(0, 12)
		menuPad.Parent = menu
		local menuLayout = Instance.new("UIListLayout")
		menuLayout.Padding = UDim.new(0, 0)
		menuLayout.SortOrder = Enum.SortOrder.LayoutOrder
		menuLayout.Parent = menu
		local dropdownEntry = {
			menu = menu,
			row = fr,
			baseHeight = baseHeight,
		}
		table.insert(customDropdownMenus, dropdownEntry)
		local selectedName
		local optionButtons = {}
		local hover = false
		local dropdownOpen = false
		local function getDropdownScale()
			local sc = uiScaleState and uiScaleState.object
			local factor = sc and tonumber(sc.Scale) or 1
			if not factor or factor <= 0 then
				factor = 1
			end
			return factor
		end
		local function syncExpandedHeight()
			local s = fr.Size
			local menuLogicalHeight = menu.Size.Y.Offset
			local uiScaleFactor = getDropdownScale()
			if menu.AbsoluteSize.Y > 0 then
				menuLogicalHeight = math.max(menuLogicalHeight, math.floor((menu.AbsoluteSize.Y / uiScaleFactor) + 0.5))
			end
			local expandedHeight = baseHeight + menuLogicalHeight + 6
			fr.Size = UDim2.new(s.X.Scale, s.X.Offset, 0, dropdownOpen and expandedHeight or baseHeight)
		end
		local function setExpanded(open)
			dropdownOpen = open and true or false
			menu.Visible = dropdownOpen
			upArrow.TextColor3 = open and Color3.fromRGB(160, 166, 180) or Color3.fromRGB(104, 110, 124)
			downArrow.TextColor3 = open and Color3.fromRGB(104, 110, 124) or Color3.fromRGB(160, 166, 180)
			syncExpandedHeight()
			openBg.BackgroundColor3 = open and Color3.fromRGB(48, 52, 64)
				or (hover and Color3.fromRGB(45, 49, 60) or Color3.fromRGB(39, 42, 52))
		end
		dropdownEntry.collapse = function()
			setExpanded(false)
		end
		local function refreshOptions()
			for name, btn in optionButtons do
				if btn and btn.Parent then
					btn.TextColor3 = name == selectedName and Color3.fromRGB(255, 255, 255)
						or Color3.fromRGB(245, 247, 252)
					local check = btn:FindFirstChild("Check")
					if check and check:IsA("TextLabel") then
						check.Visible = name == selectedName
					end
				end
			end
			openBtn.Text = selectedName or "Select"
		end
		local function applySelection(name)
			if not table.find(names, name) then
				return
			end
			selectedName = name
			pcall(function()
				setSelectedName(name)
			end)
			if opts.persist and id then
				saveSettingsEntry(id, { name = name })
			end
			refreshOptions()
		end
		for idx, name in names do
			local option = Instance.new("TextButton")
			option.Name = name
			option.Size = UDim2.new(1, 0, 0, 30)
			option.BackgroundTransparency = 1
			option.BorderSizePixel = 0
			option.AutoButtonColor = false
			option.Font = Enum.Font.GothamMedium
			option.TextSize = 12
			option.TextColor3 = Color3.new(1, 1, 1)
			option.TextXAlignment = Enum.TextXAlignment.Left
			option.Text = name
			option.LayoutOrder = idx
			option.ZIndex = 27
			option.Parent = menu
			local optionPad = Instance.new("UIPadding")
			optionPad.PaddingRight = UDim.new(0, 24)
			optionPad.Parent = option
			local divider = Instance.new("Frame")
			divider.Name = "Divider"
			divider.AnchorPoint = Vector2.new(0, 1)
			divider.Position = UDim2.new(0, 0, 1, 0)
			divider.Size = UDim2.new(1, 0, 0, idx < #names and 1 or 0)
			divider.BackgroundColor3 = Color3.fromRGB(66, 96, 128)
			divider.BorderSizePixel = 0
			divider.ZIndex = 27
			divider.Parent = option
			local check = Instance.new("TextLabel")
			check.Name = "Check"
			check.BackgroundTransparency = 1
			check.AnchorPoint = Vector2.new(1, 0.5)
			check.Position = UDim2.new(1, 0, 0.5, 0)
			check.Size = UDim2.new(0, 16, 0, 16)
			check.Font = Enum.Font.GothamBold
			check.TextSize = 15
			check.TextColor3 = Color3.fromRGB(79, 164, 242)
			check.Text = "✓"
			check.Visible = false
			check.ZIndex = 28
			check.Parent = option
			optionButtons[name] = option
			option.MouseButton1Click:Connect(function()
				closeCustomDropdowns(menu)
				setExpanded(false)
				applySelection(name)
			end)
		end
		openBtn.MouseEnter:Connect(function()
			hover = true
			if not menu.Visible then
				openBg.BackgroundColor3 = Color3.fromRGB(45, 49, 60)
			end
		end)
		openBtn.MouseLeave:Connect(function()
			hover = false
			if not menu.Visible then
				openBg.BackgroundColor3 = Color3.fromRGB(39, 42, 52)
			end
		end)
		openBtn.MouseButton1Click:Connect(function()
			local willOpen = not menu.Visible
			closeCustomDropdowns(menu)
			setExpanded(willOpen)
		end)
		menu:GetPropertyChangedSignal("AbsoluteSize"):Connect(function()
			task.defer(syncExpandedHeight)
		end)
		menu:GetPropertyChangedSignal("Size"):Connect(function()
			task.defer(syncExpandedHeight)
		end)
		if uiScaleState and uiScaleState.object and uiScaleState.object.GetPropertyChangedSignal then
			uiScaleState.object:GetPropertyChangedSignal("Scale"):Connect(function()
				task.defer(syncExpandedHeight)
			end)
		end
		local initialName
		if opts.persist and id then
			local saved = settingsConfig[id]
			if type(saved) == "table" and type(saved.name) == "string" then
				initialName = saved.name
			end
		end
		if type(getCurrentName) == "function" then
			initialName = initialName or getCurrentName()
		end
		if not table.find(names, initialName) then
			initialName = names[1]
		end
		setExpanded(false)
		applySelection(initialName)
	end
	local function makeIconRgbToggle()
		if not (settingsHolder and settingTemplate and iconBtn and iconStroke) then
			return
		end
		local key = "IconRGB"
		local frame = __dcm_registerCustom(settingTemplate:Clone())
		frame.Parent = settingsHolder
		frame.Visible = true
		frame.LayoutOrder = -2
		for _, d in frame:QueryDescendants("LocalScript") do
			d:Destroy()
		end
		local tLabel = frame:FindFirstChild("Title", true)
		local dLabel = frame:FindFirstChild("Desc", true)
		if tLabel then
			tLabel.Text = "RGB icon"
		end
		if dLabel then
			dLabel.Text = "Rainbow outline on the Delta icon."
		end
		local btnFrame = frame:FindFirstChild("Button", true)
		if not btnFrame then
			return
		end
		local btnLabel = btnFrame:FindFirstChildWhichIsA("TextLabel")
		if btnLabel then
			btnLabel.Text = "Toggle"
		end
		local clickable = btnFrame:FindFirstChildWhichIsA("GuiButton") or btnFrame
		local saved = settingsConfig[key]
		local enabled = false
		if type(saved) == "table" and saved.enabled ~= nil then
			enabled = saved.enabled and true or false
		end
		local hue = 0
		local function saveState()
			if not (HS and type(writefile) == "function") then
				return
			end
			settingsConfig[key] = { enabled = enabled }
			writeJsonFile(settingsPath, settingsConfig)
		end
		local function setVisualToggle()
			btnFrame.BackgroundColor3 = enabled and Color3.fromRGB(79, 164, 242) or Color3.fromRGB(30, 30, 30)
		end
		local function startLoop()
			NAlib.disconnect("IconRGB_Loop")
			NAlib.connect(
				"IconRGB_Loop",
				RS.Heartbeat:Connect(function(dt)
					local spd = iconRgbSpeedValue and math.clamp(iconRgbSpeedValue.Value, 0.05, 2) or 0.2
					hue = (hue + dt * spd) % 1
					pcall(function()
						iconStroke.Color = Color3.fromHSV(hue, 1, 1)
					end)
				end)
			)
		end
		local function stopLoop()
			NAlib.disconnect("IconRGB_Loop")
			pcall(function()
				if iconColorUseCustom and iconColorValue then
					iconStroke.Color = iconColorValue.Value
				else
					iconStroke.Color = iconBaseColor or iconStroke.Color
				end
			end)
		end
		local function applyState()
			setVisualToggle()
			if enabled then
				startLoop()
			else
				stopLoop()
			end
			saveState()
		end
		applyState()
		local function toggleClick()
			enabled = not enabled
			applyState()
		end
		if clickable:IsA("GuiButton") then
			clickable.MouseButton1Click:Connect(toggleClick)
		else
			clickable.InputBegan:Connect(function(input)
				if
					input.UserInputType == Enum.UserInputType.MouseButton1
					or input.UserInputType == Enum.UserInputType.Touch
				then
					toggleClick()
				end
			end)
		end
	end
	local function makeIconVisibilityToggle()
		if not (settingsHolder and settingTemplate and iconBtn) then
			return
		end
		local key = "IconVisible"
		local frame = __dcm_registerCustom(settingTemplate:Clone())
		frame.Parent = settingsHolder
		frame.Visible = true
		frame.LayoutOrder = -2
		for _, d in frame:QueryDescendants("LocalScript") do
			d:Destroy()
		end
		local tLabel = frame:FindFirstChild("Title", true)
		local dLabel = frame:FindFirstChild("Desc", true)
		if tLabel then
			tLabel.Text = "Icon visibility"
		end
		if dLabel then
			dLabel.Text = "Makes the Delta icon invisible"
		end
		local btnFrame = frame:FindFirstChild("Button", true)
		if not btnFrame then
			return
		end
		local btnLabel = btnFrame:FindFirstChildWhichIsA("TextLabel")
		if btnLabel then
			btnLabel.Text = "Toggle"
		end
		local clickable = btnFrame:FindFirstChildWhichIsA("GuiButton") or btnFrame
		local function saveState()
			if not (HS and type(writefile) == "function") then
				return
			end
			settingsConfig[key] = { enabled = iconVisible }
			writeJsonFile(settingsPath, settingsConfig)
		end
		local function setVisual()
			btnFrame.BackgroundColor3 = iconVisible and Color3.fromRGB(79, 164, 242) or Color3.fromRGB(30, 30, 30)
		end
		setVisual()
		local function toggleClick()
			iconVisible = not iconVisible
			applyIconUserVisibility(false)
			setVisual()
			saveState()
		end
		if clickable:IsA("GuiButton") then
			clickable.MouseButton1Click:Connect(toggleClick)
		else
			clickable.InputBegan:Connect(function(input)
				if
					input.UserInputType == Enum.UserInputType.MouseButton1
					or input.UserInputType == Enum.UserInputType.Touch
				then
					toggleClick()
				end
			end)
		end
	end
	local function makeIconStrokeToggle()
		if not (settingsHolder and settingTemplate and iconStroke) then
			return
		end
		local key = "IconStrokeEnabled"
		local frame = __dcm_registerCustom(settingTemplate:Clone())
		frame.Parent = settingsHolder
		frame.Visible = true
		frame.LayoutOrder = -2
		for _, d in frame:QueryDescendants("LocalScript") do
			d:Destroy()
		end
		local tLabel = frame:FindFirstChild("Title", true)
		local dLabel = frame:FindFirstChild("Desc", true)
		if tLabel then
			tLabel.Text = "Icon stroke"
		end
		if dLabel then
			dLabel.Text = "Toggle the Delta icon outline"
		end
		local btnFrame = frame:FindFirstChild("Button", true)
		if not btnFrame then
			return
		end
		local btnLabel = btnFrame:FindFirstChildWhichIsA("TextLabel")
		if btnLabel then
			btnLabel.Text = "Toggle"
		end
		local clickable = btnFrame:FindFirstChildWhichIsA("GuiButton") or btnFrame
		local function saveState()
			saveSettingsEntry(key, { enabled = iconStrokeUserEnabled })
		end
		local function setVisual()
			btnFrame.BackgroundColor3 = iconStrokeUserEnabled and Color3.fromRGB(79, 164, 242)
				or Color3.fromRGB(30, 30, 30)
		end
		setVisual()
		local function toggleClick()
			iconStrokeUserEnabled = not iconStrokeUserEnabled
			applyIconStrokeState()
			setVisual()
			saveState()
		end
		if clickable:IsA("GuiButton") then
			clickable.MouseButton1Click:Connect(toggleClick)
		else
			clickable.InputBegan:Connect(function(input)
				if
					input.UserInputType == Enum.UserInputType.MouseButton1
					or input.UserInputType == Enum.UserInputType.Touch
				then
					toggleClick()
				end
			end)
		end
	end
	local function makeIconPositionSaveToggle()
		if not (settingsHolder and settingTemplate and iconBtn) then
			return
		end
		local key = "IconPositionSave"
		local frame = __dcm_registerCustom(settingTemplate:Clone())
		frame.Parent = settingsHolder
		frame.Visible = true
		frame.LayoutOrder = -2
		for _, d in frame:QueryDescendants("LocalScript") do
			d:Destroy()
		end
		local tLabel = frame:FindFirstChild("Title", true)
		local dLabel = frame:FindFirstChild("Desc", true)
		if tLabel then
			tLabel.Text = "Save icon position"
		end
		if dLabel then
			dLabel.Text = "Load your dragged icon position on execute"
		end
		local btnFrame = frame:FindFirstChild("Button", true)
		if not btnFrame then
			return
		end
		local btnLabel = btnFrame:FindFirstChildWhichIsA("TextLabel")
		if btnLabel then
			btnLabel.Text = "Toggle"
		end
		local clickable = btnFrame:FindFirstChildWhichIsA("GuiButton") or btnFrame
		local function saveState()
			saveSettingsEntry(key, { enabled = iconPositionSaveEnabled })
			if iconPositionSaveEnabled then
				saveManagedIconPosition()
			end
		end
		local function setVisual()
			btnFrame.BackgroundColor3 = iconPositionSaveEnabled and Color3.fromRGB(79, 164, 242)
				or Color3.fromRGB(30, 30, 30)
		end
		setVisual()
		local function toggleClick()
			iconPositionSaveEnabled = not iconPositionSaveEnabled
			if iconPositionSaveEnabled then
				applySavedManagedIconPosition()
			end
			setVisual()
			saveState()
		end
		if clickable:IsA("GuiButton") then
			clickable.MouseButton1Click:Connect(toggleClick)
		else
			clickable.InputBegan:Connect(function(input)
				if
					input.UserInputType == Enum.UserInputType.MouseButton1
					or input.UserInputType == Enum.UserInputType.Touch
				then
					toggleClick()
				end
			end)
		end
	end
	local function makeTabNotifToggle()
		if not (settingsHolder and settingTemplate) then
			return
		end
		local key = "TabNotifications"
		local frame = __dcm_registerCustom(settingTemplate:Clone())
		frame.Parent = settingsHolder
		frame.Visible = true
		frame.LayoutOrder = -2
		for _, d in frame:QueryDescendants("LocalScript") do
			d:Destroy()
		end
		local tLabel = frame:FindFirstChild("Title", true)
		local dLabel = frame:FindFirstChild("Desc", true)
		if tLabel then
			tLabel.Text = "Tab notifications"
		end
		if dLabel then
			dLabel.Text = "Show info popups about saved tabs"
		end
		local btnFrame = frame:FindFirstChild("Button", true)
		if not btnFrame then
			return
		end
		local btnLabel = btnFrame:FindFirstChildWhichIsA("TextLabel")
		if btnLabel then
			btnLabel.Text = "Toggle"
		end
		local clickable = btnFrame:FindFirstChildWhichIsA("GuiButton") or btnFrame
		local function saveState()
			if not (HS and type(writefile) == "function") then
				return
			end
			settingsConfig[key] = { enabled = tabNotifEnabled }
			writeJsonFile(settingsPath, settingsConfig)
		end
		local function setVisual()
			btnFrame.BackgroundColor3 = tabNotifEnabled and Color3.fromRGB(79, 164, 242) or Color3.fromRGB(30, 30, 30)
		end
		setVisual()
		local function toggleClick()
			tabNotifEnabled = not tabNotifEnabled
			setVisual()
			saveState()
		end
		if clickable:IsA("GuiButton") then
			clickable.MouseButton1Click:Connect(toggleClick)
		else
			clickable.InputBegan:Connect(function(input)
				if
					input.UserInputType == Enum.UserInputType.MouseButton1
					or input.UserInputType == Enum.UserInputType.Touch
				then
					toggleClick()
				end
			end)
		end
	end
	local function makeDestroyUIButton()
		if not (settingsHolder and settingTemplate) then
			return
		end
		local frame = __dcm_registerCustom(settingTemplate:Clone())
		frame.Parent = settingsHolder
		frame.Visible = true
		frame.LayoutOrder = -2
		for _, d in frame:QueryDescendants("LocalScript") do
			d:Destroy()
		end
		local tLabel = frame:FindFirstChild("Title", true)
		local dLabel = frame:FindFirstChild("Desc", true)
		if tLabel then
			tLabel.Text = "Destroy Delta UI"
			tLabel.TextColor3 = Color3.fromRGB(255, 80, 80)
		end
		if dLabel then
			dLabel.Text = "Deletes Delta's UI and icon until you rejoin."
			dLabel.TextColor3 = Color3.fromRGB(255, 120, 120)
		end
		local btnFrame = frame:FindFirstChild("Button", true)
		if not btnFrame then
			return
		end
		local btnLabel = btnFrame:FindFirstChildWhichIsA("TextLabel")
		if btnLabel then
			btnLabel.Text = "KILL"
		end
		btnFrame.BackgroundColor3 = Color3.fromRGB(255, 80, 80)
		local clickable = btnFrame:FindFirstChildWhichIsA("GuiButton") or btnFrame
		local function click()
			if iconGui and iconGui ~= mainGui then
				pcall(function()
					iconGui:Destroy()
				end)
				iconGui = nil
			end
			if mainGui then
				pcall(function()
					mainGui:Destroy()
				end)
				mainGui = nil
			end
		end
		if clickable:IsA("GuiButton") then
			clickable.MouseButton1Click:Connect(click)
		else
			clickable.InputBegan:Connect(function(input)
				if
					input.UserInputType == Enum.UserInputType.MouseButton1
					or input.UserInputType == Enum.UserInputType.Touch
				then
					click()
				end
			end)
		end
	end
	local function makeIconEnableToggle()
		if not (settingsHolder and settingTemplate and iconBtn) then
			return
		end
		local key = "IconEnabled"
		local frame = __dcm_registerCustom(settingTemplate:Clone())
		frame.Parent = settingsHolder
		frame.Visible = true
		frame.LayoutOrder = -2
		for _, d in frame:QueryDescendants("LocalScript") do
			d:Destroy()
		end
		local tLabel = frame:FindFirstChild("Title", true)
		local dLabel = frame:FindFirstChild("Desc", true)
		if tLabel then
			tLabel.Text = "Use custom icon"
		end
		if dLabel then
			dLabel.Text = iconFsOk() and "Toggle between default and custom Delta icon"
				or "Requires file system + getcustomasset support"
		end
		local btnFrame = frame:FindFirstChild("Button", true)
		if not btnFrame then
			return
		end
		local btnLabel = btnFrame:FindFirstChildWhichIsA("TextLabel")
		if btnLabel then
			btnLabel.Text = "Toggle"
		end
		local clickable = btnFrame:FindFirstChildWhichIsA("GuiButton") or btnFrame
		local enabled = dIcons.enabled and true or false
		local function setVisual()
			btnFrame.BackgroundColor3 = enabled and Color3.fromRGB(79, 164, 242) or Color3.fromRGB(30, 30, 30)
		end
		setVisual()
		local function toggleClick()
			local target = not enabled
			local ok, err = setIconEnabled(target)
			if not ok then
				notify({
					Title = "Delta Icon",
					Description = err or "Failed to toggle custom icon.",
					Duration = 5,
				})
				return
			end
			enabled = target
			setVisual()
		end
		if clickable:IsA("GuiButton") then
			clickable.MouseButton1Click:Connect(toggleClick)
		else
			clickable.InputBegan:Connect(function(input)
				if
					input.UserInputType == Enum.UserInputType.MouseButton1
					or input.UserInputType == Enum.UserInputType.Touch
				then
					toggleClick()
				end
			end)
		end
	end
	local function makeIconInputRow()
		if not (settingsHolder and settingTemplate and iconBtn) then
			return
		end
		local frame = __dcm_registerCustom(settingTemplate:Clone())
		frame.Parent = settingsHolder
		frame.Visible = true
		frame.LayoutOrder = -2
		for _, d in frame:QueryDescendants("LocalScript") do
			d:Destroy()
		end
		local tLabel = frame:FindFirstChild("Title", true)
		local dLabel = frame:FindFirstChild("Desc", true)
		if tLabel then
			tLabel.Text = "Icon source"
		end
		if dLabel then
			dLabel.Text = "Asset id or image URL (GitHub/External supported)"
		end
		local oldBtn = frame:FindFirstChild("Button", true)
		local pos
		if oldBtn then
			pos = oldBtn.Position
			oldBtn:Destroy()
		end
		local basePos = pos or UDim2.new(1, -160, 0.5, 0)
		local bx, bo = basePos.X.Scale, basePos.X.Offset
		local by, byo = basePos.Y.Scale, basePos.Y.Offset
		local box = Instance.new("TextBox")
		box.Name = "IconInput"
		box.Size = UDim2.new(0, 160, 0, 18)
		box.AnchorPoint = Vector2.new(1, 0.5)
		box.Position = UDim2.new(bx, bo, by, byo)
		box.BackgroundColor3 = Color3.fromRGB(20, 20, 20)
		box.BorderSizePixel = 0
		box.ClearTextOnFocus = true
		box.TextXAlignment = Enum.TextXAlignment.Center
		box.Font = Enum.Font.Gotham
		box.TextSize = 12
		box.TextColor3 = Color3.new(1, 1, 1)
		box.Text = ""
		box.PlaceholderText = "ID or image URL"
		box.Parent = frame
		local setBtn = Instance.new("TextButton")
		setBtn.Name = "Apply"
		setBtn.Size = UDim2.new(0, 50, 0, 18)
		setBtn.AnchorPoint = Vector2.new(1, 0.5)
		setBtn.Position = UDim2.new(bx, bo - 170, by, byo)
		setBtn.BackgroundColor3 = Color3.fromRGB(79, 164, 242)
		setBtn.BorderSizePixel = 0
		setBtn.Font = Enum.Font.GothamBold
		setBtn.TextSize = 11
		setBtn.TextColor3 = Color3.new(1, 1, 1)
		setBtn.Text = "SET"
		setBtn.Parent = frame
		local setCorner = Instance.new("UICorner")
		setCorner.CornerRadius = UDim.new(0, 4)
		setCorner.Parent = setBtn
		local defBtn = Instance.new("TextButton")
		defBtn.Name = "Default"
		defBtn.Size = UDim2.new(0, 50, 0, 18)
		defBtn.AnchorPoint = Vector2.new(1, 0.5)
		defBtn.Position = UDim2.new(bx, bo - 230, by, byo)
		defBtn.BackgroundColor3 = Color3.fromRGB(30, 30, 30)
		defBtn.BorderSizePixel = 0
		defBtn.Font = Enum.Font.GothamBold
		defBtn.TextSize = 11
		defBtn.TextColor3 = Color3.new(1, 1, 1)
		defBtn.Text = "DEF"
		defBtn.Parent = frame
		local defCorner = Instance.new("UICorner")
		defCorner.CornerRadius = UDim.new(0, 4)
		defCorner.Parent = defBtn
		local function applyInput()
			if not iconFsOk() then
				notify({
					Title = "Delta Icon",
					Description = "Custom icons require file system + getcustomasset.",
					Duration = 5,
				})
				return
			end
			local txt = trim(box.Text or "")
			if txt == "" then
				notify({
					Title = "Delta Icon",
					Description = "Enter an asset id or image URL.",
					Duration = 4,
				})
				return
			end
			local ok, msg = setIconAsset(txt, { autoEnable = true })
			if not ok then
				notify({
					Title = "Delta Icon",
					Description = msg or "Failed to set custom icon.",
					Duration = 5,
				})
				return
			end
			if updateIconStatusUI then
				updateIconStatusUI()
			end
			box.Text = ""
			notify({
				Title = "Delta Icon",
				Description = "Custom icon updated.",
				Duration = 4,
			})
		end
		local function resetDefault()
			dIcons.enabled = false
			dIcons.assetId = ""
			dIcons.localPath = ""
			applyIcon()
			saveIconCfg()
			if updateIconStatusUI then
				updateIconStatusUI()
			end
			notify({
				Title = "Delta Icon",
				Description = "Reverted to default icon.",
				Duration = 4,
			})
		end
		setBtn.MouseButton1Click:Connect(applyInput)
		defBtn.MouseButton1Click:Connect(resetDefault)
		box.FocusLost:Connect(function(enter)
			if enter then
				applyInput()
			end
		end)
	end
	local function makeIconManagerRow()
		if not (settingsHolder and settingTemplate) then
			return
		end
		local frame = __dcm_registerCustom(settingTemplate:Clone())
		frame.Parent = settingsHolder
		frame.Visible = true
		frame.LayoutOrder = -2
		for _, d in frame:QueryDescendants("LocalScript") do
			d:Destroy()
		end
		local tLabel = frame:FindFirstChild("Title", true)
		local dLabel = frame:FindFirstChild("Desc", true)
		if tLabel then
			tLabel.Text = "Icon manager"
		end
		if dLabel then
			dLabel.Text = iconFsOk() and formatIconStatus() or "File system/getcustomasset not supported."
		end
		local oldBtn = frame:FindFirstChild("Button", true)
		local pos
		if oldBtn then
			pos = oldBtn.Position
			oldBtn:Destroy()
		end
		local basePos = pos or UDim2.new(1, -160, 0.5, 0)
		local bx, bo = basePos.X.Scale, basePos.X.Offset
		local by, byo = basePos.Y.Scale, basePos.Y.Offset
		local function mkMgrBtn(nm, w, xOff, bgColor, txt)
			local b = Instance.new("TextButton")
			b.Name = nm
			b.Size = UDim2.new(0, w, 0, 18)
			b.AnchorPoint = Vector2.new(1, 0.5)
			b.Position = UDim2.new(bx, bo + xOff, by, byo)
			b.BackgroundColor3 = bgColor
			b.BorderSizePixel = 0
			b.Font = Enum.Font.GothamBold
			b.TextSize = 11
			b.TextColor3 = Color3.new(1, 1, 1)
			b.Text = txt
			b.Parent = frame
			local c = Instance.new("UICorner")
			c.CornerRadius = UDim.new(0, 4)
			c.Parent = b
			return b
		end
		local gray = Color3.fromRGB(30, 30, 30)
		local prevBtn = mkMgrBtn("Prev", 24, -210, gray, "<")
		local nextBtn = mkMgrBtn("Next", 24, -180, gray, ">")
		local delBtn = mkMgrBtn("Del", 32, -140, Color3.fromRGB(80, 40, 40), "DEL")
		local clrBtn = mkMgrBtn("Clr", 36, -95, Color3.fromRGB(60, 30, 30), "CLR")
		local statusLabel = Instance.new("TextLabel")
		statusLabel.Name = "Status"
		statusLabel.Size = UDim2.new(0, 60, 0, 18)
		statusLabel.AnchorPoint = Vector2.new(1, 0.5)
		statusLabel.Position = UDim2.new(bx, bo, by, byo)
		statusLabel.BackgroundTransparency = 1
		statusLabel.Font = Enum.Font.Gotham
		statusLabel.TextSize = 11
		statusLabel.TextColor3 = Color3.fromRGB(200, 200, 200)
		statusLabel.TextXAlignment = Enum.TextXAlignment.Right
		statusLabel.Text = "-/-"
		statusLabel.Parent = frame
		function updateIconStatusUI()
			if not statusLabel then
				return
			end
			local n = #dIcons.entries
			local idx = dIcons.index
			if dLabel then
				dLabel.Text = iconFsOk() and formatIconStatus() or "File system/getcustomasset not supported."
			end
			if n <= 0 then
				statusLabel.Text = "-/-"
			else
				if idx < 1 or idx > n then
					idx = 1
				end
				statusLabel.Text = tostring(idx) .. "/" .. tostring(n)
			end
		end
		updateIconStatusUI()
		local function chkFs()
			if iconFsOk() then
				return true
			end
			notify({
				Title = "Delta Icon",
				Description = "Custom icon manager requires file system + getcustomasset.",
				Duration = 5,
			})
			return false
		end
		prevBtn.MouseButton1Click:Connect(function()
			if not chkFs() then
				return
			end
			if #dIcons.entries == 0 then
				notify({ Title = "Delta Icon", Description = "No custom icons to cycle.", Duration = 4 })
				return
			end
			cycleIcon(-1)
		end)
		nextBtn.MouseButton1Click:Connect(function()
			if not chkFs() then
				return
			end
			if #dIcons.entries == 0 then
				notify({ Title = "Delta Icon", Description = "No custom icons to cycle.", Duration = 4 })
				return
			end
			cycleIcon(1)
		end)
		delBtn.MouseButton1Click:Connect(function()
			if not chkFs() then
				return
			end
			local list = dIcons.entries
			local idx = dIcons.index
			if #list == 0 or idx < 1 or idx > #list then
				notify({ Title = "Delta Icon", Description = "No icon selected to delete.", Duration = 4 })
				return
			end
			local e = list[idx]
			if not e or not e.file then
				return
			end
			removeIconEntry(e)
			if updateIconStatusUI then
				updateIconStatusUI()
			end
		end)
		clrBtn.MouseButton1Click:Connect(function()
			if not chkFs() then
				return
			end
			if #dIcons.entries == 0 then
				notify({ Title = "Delta Icon", Description = "No custom icons to clear.", Duration = 4 })
				return
			end
			removeAllIcons()
			if updateIconStatusUI then
				updateIconStatusUI()
			end
			notify({ Title = "Delta Icon", Description = "Cleared all custom icons.", Duration = 4 })
		end)
	end
	local sidebarGestureEnabled = false
	local sidebarGestureVisible = true
	local sidebarGestureWidth = 18
	local sidebarGestureHeight = 120
	local sidebarGestureFrame
	local sidebarDragActive = false
	local sidebarDragStartX = 0
	local sidebarDragStartAlpha = 0
	local sidebarDragAlpha = 0
	local getCurrentSectionName
	local sidebarCurrentSection = nil
	local autoCloseOnLoad = true
	local sectionsList = { "Executor", "Home", "Scripthub", "Settings", "Console", "Music" }
	local gestureWidthValue = Instance.new("NumberValue")
	gestureWidthValue.Name = "GestureWidthValue"
	gestureWidthValue.Value = sidebarGestureWidth
	local gestureHeightValue = Instance.new("NumberValue")
	gestureHeightValue.Name = "GestureHeightValue"
	gestureHeightValue.Value = sidebarGestureHeight
	do
		local cfg = settingsConfig.GestureWidth
		if type(cfg) == "table" and type(cfg.value) == "number" then
			gestureWidthValue.Value = math.clamp(cfg.value, 6, 80)
		end
	end
	do
		local cfg = settingsConfig.GestureHeight
		if type(cfg) == "table" and type(cfg.value) == "number" then
			gestureHeightValue.Value = math.clamp(cfg.value, 60, 400)
		end
	end
	do
		local cfg = settingsConfig.SidebarGesture
		if type(cfg) == "table" and cfg.enabled ~= nil then
			sidebarGestureEnabled = cfg.enabled and true or false
		end
	end
	do
		local cfg = settingsConfig.SidebarGestureVisible
		if type(cfg) == "table" and cfg.enabled ~= nil then
			sidebarGestureVisible = cfg.enabled and true or false
		end
	end
	do
		local cfg = settingsConfig.AutoCloseOnLoad
		if type(cfg) == "table" and cfg.enabled ~= nil then
			autoCloseOnLoad = cfg.enabled and true or false
		end
	end
	local gestCol = Instance.new("Color3Value")
	gestCol.Name = "GestureColorValue"
	gestCol.Value = Color3.fromRGB(255, 255, 255)
	gestCol.Changed:Connect(function()
		if sidebarGestureFrame then
			sidebarGestureFrame.BackgroundColor3 = gestCol.Value
		end
	end)
	local function closeDeltaSidebar()
		if sidebar then
			setSidebarPosition(sidebarClosedPos)
			normalizeSidebarGeometry()
		end
		if mainGui then
			for _, n in sectionsList do
				local fr = mainGui:FindFirstChild(n)
				if fr and fr:IsA("GuiObject") then
					fr.Visible = false
				end
			end
		end
		setIconForcedHidden(sidebarGestureEnabled)
	end
	local function openDeltaFromIcon()
		if not sidebar then
			return
		end
		local curSec = getCurrentSectionName()
		if curSec then
			sidebarCurrentSection = curSec
		end
		if not sidebarCurrentSection then
			sidebarCurrentSection = sectionsList[1]
		end
		if TS and sidebar then
			local tw = __lt.cm(
				"TweenService",
				"Create",
				sidebar,
				TweenInfo.new(0.2, Enum.EasingStyle.Quad, Enum.EasingDirection.Out),
				{
					Position = UDim2.new(sidebarOpenPos.X.Scale, sidebarOpenPos.X.Offset, 0.5, 0),
				}
			)
			tw:Play()
		else
			setSidebarPosition(sidebarOpenPos)
		end
		normalizeSidebarGeometry()
		setIconForcedHidden(true)
		if mainGui and sidebarCurrentSection then
			for _, n in sectionsList do
				local fr = mainGui:FindFirstChild(n)
				if fr and fr:IsA("GuiObject") then
					fr.Visible = n == sidebarCurrentSection
				end
			end
		end
	end
	bindManagedIconToggle = function()
		NAlib.disconnect("ManagedIcon_Toggle")
		if not (iconBtn and iconBtn:IsA("GuiButton")) then
			return
		end
		NAlib.connect("ManagedIcon_Toggle", MouseButtonFix(iconBtn, function()
			local override = rawget(__dcm_env, "__NewDeltaUIToggle")
			if type(override) == "function" then
				local ok, handled = pcall(override)
				if ok and handled ~= false then
					return
				end
			end
			if not sidebar then
				return
			end
			local isOpen = math.abs(sidebar.Position.X.Scale - sidebarOpenPos.X.Scale) <= 0.001
			if isOpen then
				closeDeltaSidebar()
			else
				openDeltaFromIcon()
			end
		end))
	end
	bindManagedIconToggle()
	local function saveSidebarGesture()
		if not (HS and type(writefile) == "function") then
			return
		end
		settingsConfig.SidebarGesture = { enabled = sidebarGestureEnabled }
		writeJsonFile(settingsPath, settingsConfig)
	end
	local function saveSidebarGestureVisible()
		if not (HS and type(writefile) == "function") then
			return
		end
		settingsConfig.SidebarGestureVisible = { enabled = sidebarGestureVisible }
		writeJsonFile(settingsPath, settingsConfig)
	end
	local function applyGestureVisual()
		if sidebarGestureFrame then
			sidebarGestureFrame.BackgroundTransparency = sidebarGestureVisible and 0.4 or 1
		end
	end
	local function applyGestureSize()
		if not sidebarGestureFrame then
			return
		end
		local h = math.clamp(gestureHeightValue and gestureHeightValue.Value or sidebarGestureHeight, 60, 400)
		local w = math.clamp(gestureWidthValue and gestureWidthValue.Value or sidebarGestureWidth, 6, 80)
		if UIS and UIS.TouchEnabled then
			w = math.floor(w * 1.6)
		end
		sidebarGestureFrame.Size = UDim2.new(0, w, 0, h)
	end
	gestureWidthValue.Changed:Connect(function()
		if sidebarGestureFrame then
			applyGestureSize()
		end
	end)
	gestureHeightValue.Changed:Connect(function()
		if sidebarGestureFrame then
			applyGestureSize()
		end
	end)
	local function ensureSidebarGestureFrame()
		if sidebarGestureFrame or not (sidebar and mainGui) then
			return
		end
		local f = Instance.new("Frame")
		sidebarGestureFrame = f
		f.Name = "SidebarGestureZone"
		f.BackgroundColor3 = gestCol.Value
		f.BorderSizePixel = 0
		f.AnchorPoint = Vector2.new(1, 0.5)
		f.Position = UDim2.new(1, 0, 0.5, 0)
		f.Size = UDim2.new(0, sidebarGestureWidth, 0, sidebarGestureHeight)
		f.Active = false
		f.Visible = false
		f.Parent = mainGui
		local corner = Instance.new("UICorner")
		corner.CornerRadius = UDim.new(0, 6)
		corner.Parent = f
		applyGestureSize()
		applyGestureVisual()
	end
	local function makeSidebarGestureToggle()
		if not (settingsHolder and settingTemplate and sidebar) then
			return
		end
		local frame = __dcm_registerCustom(settingTemplate:Clone())
		frame.Parent = settingsHolder
		frame.Visible = true
		frame.LayoutOrder = -2
		for _, d in frame:QueryDescendants("LocalScript") do
			d:Destroy()
		end
		local tLabel = frame:FindFirstChild("Title", true)
		local dLabel = frame:FindFirstChild("Desc", true)
		if tLabel then
			tLabel.Text = "Sidebar gesture"
		end
		if dLabel then
			dLabel.Text = "Drag from the right edge to open/close the sidebar"
		end
		local btnFrame = frame:FindFirstChild("Button", true)
		if not btnFrame then
			return
		end
		local btnLabel = btnFrame:FindFirstChildWhichIsA("TextLabel")
		if btnLabel then
			btnLabel.Text = "Toggle"
		end
		local clickable = btnFrame:FindFirstChildWhichIsA("GuiButton") or btnFrame
		local function setVisual()
			btnFrame.BackgroundColor3 = sidebarGestureEnabled and Color3.fromRGB(79, 164, 242)
				or Color3.fromRGB(30, 30, 30)
		end
		setVisual()
		local function toggleClick()
			sidebarGestureEnabled = not sidebarGestureEnabled
			setVisual()
			saveSidebarGesture()
			setIconForcedHidden(sidebarGestureEnabled)
			task.defer(function()
				if applySidebarGestureState then
					applySidebarGestureState()
				end
			end)
		end
		if clickable:IsA("GuiButton") then
			clickable.MouseButton1Click:Connect(toggleClick)
		else
			clickable.InputBegan:Connect(function(input)
				if
					input.UserInputType == Enum.UserInputType.MouseButton1
					or input.UserInputType == Enum.UserInputType.Touch
				then
					toggleClick()
				end
			end)
		end
	end
	local function makeSidebarGestureBarVisibilityToggle()
		if not (settingsHolder and settingTemplate) then
			return
		end
		local frame = __dcm_registerCustom(settingTemplate:Clone())
		frame.Parent = settingsHolder
		frame.Visible = true
		frame.LayoutOrder = -2
		for _, d in frame:QueryDescendants("LocalScript") do
			d:Destroy()
		end
		local tLabel = frame:FindFirstChild("Title", true)
		local dLabel = frame:FindFirstChild("Desc", true)
		if tLabel then
			tLabel.Text = "Gesture bar visible"
		end
		if dLabel then
			dLabel.Text = "Hide the sidebar gesture bar but keep it usable"
		end
		local btnFrame = frame:FindFirstChild("Button", true)
		if not btnFrame then
			return
		end
		local btnLabel = btnFrame:FindFirstChildWhichIsA("TextLabel")
		if btnLabel then
			btnLabel.Text = "Toggle"
		end
		local clickable = btnFrame:FindFirstChildWhichIsA("GuiButton") or btnFrame
		local function setVisual()
			btnFrame.BackgroundColor3 = sidebarGestureVisible and Color3.fromRGB(79, 164, 242)
				or Color3.fromRGB(30, 30, 30)
		end
		setVisual()
		applyGestureVisual()
		local function toggleClick()
			sidebarGestureVisible = not sidebarGestureVisible
			setVisual()
			applyGestureVisual()
			saveSidebarGestureVisible()
		end
		if clickable:IsA("GuiButton") then
			clickable.MouseButton1Click:Connect(toggleClick)
		else
			clickable.InputBegan:Connect(function(input)
				if
					input.UserInputType == Enum.UserInputType.MouseButton1
					or input.UserInputType == Enum.UserInputType.Touch
				then
					toggleClick()
				end
			end)
		end
	end
	local function makeAutoCloseToggle()
		if not (settingsHolder and settingTemplate and sidebar) then
			return
		end
		local key = "AutoCloseOnLoad"
		local frame = __dcm_registerCustom(settingTemplate:Clone())
		frame.Parent = settingsHolder
		frame.Visible = true
		frame.LayoutOrder = -2
		for _, d in frame:QueryDescendants("LocalScript") do
			d:Destroy()
		end
		local tLabel = frame:FindFirstChild("Title", true)
		local dLabel = frame:FindFirstChild("Desc", true)
		if tLabel then
			tLabel.Text = "Auto-close on load"
		end
		if dLabel then
			dLabel.Text = "Close the Delta sidebar right after it loads"
		end
		local btnFrame = frame:FindFirstChild("Button", true)
		if not btnFrame then
			return
		end
		local btnLabel = btnFrame:FindFirstChildWhichIsA("TextLabel")
		if btnLabel then
			btnLabel.Text = "Toggle"
		end
		local clickable = btnFrame:FindFirstChildWhichIsA("GuiButton") or btnFrame
		local function saveState()
			if not (HS and type(writefile) == "function") then
				return
			end
			settingsConfig[key] = { enabled = autoCloseOnLoad }
			writeJsonFile(settingsPath, settingsConfig)
		end
		local function setVisual()
			btnFrame.BackgroundColor3 = autoCloseOnLoad and Color3.fromRGB(79, 164, 242) or Color3.fromRGB(30, 30, 30)
		end
		setVisual()
		local function toggleClick()
			autoCloseOnLoad = not autoCloseOnLoad
			setVisual()
			saveState()
		end
		if clickable:IsA("GuiButton") then
			clickable.MouseButton1Click:Connect(toggleClick)
		else
			clickable.InputBegan:Connect(function(input)
				if
					input.UserInputType == Enum.UserInputType.MouseButton1
					or input.UserInputType == Enum.UserInputType.Touch
				then
					toggleClick()
				end
			end)
		end
	end
	function getCurrentSectionName()
		if not mainGui then
			return nil
		end
		local cur
		for _, name in sectionsList do
			local fr = mainGui:FindFirstChild(name)
			if fr and fr:IsA("GuiObject") and fr.Visible then
				cur = name
			end
		end
		return cur
	end
	do
		local iconApi = rawget(__dcm_env, "DeltaIcon")
		if type(iconApi) == "table" then
			iconApi.getCurrentSectionName = getCurrentSectionName
			iconApi.setForcedHidden = setIconForcedHidden
			iconApi.openClassic = openDeltaFromIcon
			iconApi.closeClassic = closeDeltaSidebar
			iconApi.setCurrentSection = function(name)
				if table.find(sectionsList, name) then
					sidebarCurrentSection = name
				end
			end
		end
	end
	local function bindSidebarSectionMemory()
		NAlib.disconnect("SidebarSectionMemory")
		if not mainGui then
			return
		end
		local current = getCurrentSectionName()
		if current then
			sidebarCurrentSection = current
		end
		for _, name in sectionsList do
			local fr = mainGui:FindFirstChild(name)
			if fr and fr:IsA("GuiObject") then
				NAlib.connect(
					"SidebarSectionMemory",
					fr:GetPropertyChangedSignal("Visible"):Connect(function()
						if fr.Visible then
							sidebarCurrentSection = name
						end
					end)
				)
			end
		end
	end
	bindSidebarSectionMemory()
	function applySidebarGestureState()
		if not sidebar then
			sidebarGestureEnabled = false
			saveSidebarGesture()
			return
		end
		ensureSidebarGestureFrame()
		if not sidebarGestureFrame then
			sidebarGestureEnabled = false
			saveSidebarGesture()
			return
		end
		if toggleUIBtn and toggleUIBtn:IsA("ImageButton") then
			pcall(function()
				toggleUIBtn.Visible = not sidebarGestureEnabled
			end)
		end
		NAlib.disconnect("SidebarGesture")
		sidebarGestureFrame.Active = false
		sidebarGestureFrame.Visible = false
		if not sidebarGestureEnabled then
			setIconForcedHidden(false)
			saveSidebarGesture()
			return
		end
		setIconForcedHidden(true)
		sidebarGestureFrame.Active = true
		sidebarGestureFrame.Visible = true
		applyGestureVisual()
		applyGestureSize()
		local id = "SidebarGesture"
		local function recalcGesturePosition()
			if not (mainGui and sidebar and sidebarGestureFrame) then
				return
			end
			local sgSize = mainGui.AbsoluteSize
			if sgSize.X <= 0 or sgSize.Y <= 0 then
				return
			end
			local sbPos = sidebar.AbsolutePosition
			local sbSize = sidebar.AbsoluteSize
			local px = sbPos.X - 8
			sidebarGestureFrame.Position = UDim2.new(px / sgSize.X, 0, 0.5, 0)
		end
		local function getSidebarAlpha()
			if not sidebar then
				return 0
			end
			local sx = sidebar.Position.X.Scale
			local denom = sidebarClosedPos.X.Scale - sidebarOpenPos.X.Scale
			if denom == 0 then
				return 0
			end
			return math.clamp((sidebarClosedPos.X.Scale - sx) / denom, 0, 1)
		end
		recalcGesturePosition()
		NAlib.connect(id, (sidebar:GetPropertyChangedSignal("Position")):Connect(recalcGesturePosition))
		if sidebar.GetPropertyChangedSignal then
			NAlib.connect(id, (sidebar:GetPropertyChangedSignal("Size")):Connect(recalcGesturePosition))
		end
		if mainGui and mainGui.GetPropertyChangedSignal then
			NAlib.connect(id, (mainGui:GetPropertyChangedSignal("AbsoluteSize")):Connect(recalcGesturePosition))
		end
		local function updateSidebarFromInput(input)
			if not sidebar or not mainGui then
				return
			end
			local dx = input.Position.X - sidebarDragStartX
			local guiSize = mainGui.AbsoluteSize
			local dist = guiSize.X * math.abs(sidebarClosedPos.X.Scale - sidebarOpenPos.X.Scale)
			if dist <= 0 then
				dist = 100
			end
			local alpha = math.clamp(sidebarDragStartAlpha - dx / dist, 0, 1)
			sidebarDragAlpha = alpha
			setSidebarPosition(
				UDim2.new(
					sidebarClosedPos.X.Scale + (sidebarOpenPos.X.Scale - sidebarClosedPos.X.Scale) * alpha,
					0,
					0.5,
					0
				)
			)
		end
		NAlib.connect(
			id,
			sidebarGestureFrame.InputBegan:Connect(function(input)
				if not sidebarGestureEnabled then
					return
				end
				if
					input.UserInputType ~= Enum.UserInputType.MouseButton1
					and input.UserInputType ~= Enum.UserInputType.Touch
				then
					return
				end
				sidebarDragAlpha = getSidebarAlpha()
				sidebarDragStartAlpha = sidebarDragAlpha
				sidebarDragStartX = input.Position.X
				sidebarDragActive = true
			end)
		)
		NAlib.connect(
			id,
			UIS.InputChanged:Connect(function(input)
				if not sidebarDragActive or not sidebarGestureEnabled then
					return
				end
				if
					input.UserInputType == Enum.UserInputType.MouseMovement
					or input.UserInputType == Enum.UserInputType.Touch
				then
					updateSidebarFromInput(input)
				end
			end)
		)
		NAlib.connect(
			id,
			UIS.InputEnded:Connect(function(input)
				if not sidebarDragActive or not sidebarGestureEnabled then
					return
				end
				if
					input.UserInputType ~= Enum.UserInputType.MouseButton1
					and input.UserInputType ~= Enum.UserInputType.Touch
				then
					return
				end
				sidebarDragActive = false
				local curSec = getCurrentSectionName()
				if curSec then
					sidebarCurrentSection = curSec
				end
				local targetPos = sidebarDragAlpha > 0.5 and sidebarOpenPos or sidebarClosedPos
				if TS and sidebar then
					local tw = __lt.cm(
						"TweenService",
						"Create",
						sidebar,
						TweenInfo.new(0.2, Enum.EasingStyle.Quad, Enum.EasingDirection.Out),
						{
							Position = UDim2.new(targetPos.X.Scale, targetPos.X.Offset, 0.5, 0),
						}
					)
					tw:Play()
				elseif sidebar then
					setSidebarPosition(targetPos)
				end
				if targetPos == sidebarOpenPos then
					if not sidebarCurrentSection then
						sidebarCurrentSection = getCurrentSectionName()
					end
					setIconForcedHidden(true)
					if mainGui and sidebarCurrentSection then
						for _, n in sectionsList do
							local fr = mainGui:FindFirstChild(n)
							if fr and fr:IsA("GuiObject") then
								fr.Visible = n == sidebarCurrentSection
							end
						end
					end
				else
					if mainGui then
						if curSec then
							sidebarCurrentSection = curSec
						end
						for _, n in sectionsList do
							local fr = mainGui:FindFirstChild(n)
							if fr and fr:IsA("GuiObject") then
								fr.Visible = false
							end
						end
					end
					setIconForcedHidden(sidebarGestureEnabled)
				end
			end)
		)
		saveSidebarGesture()
	end
	if toggleUIBtn and toggleUIBtn:IsA("GuiButton") then
		NAlib.disconnect("ManagedToggleUI_ForcedHidden")
		NAlib.connect(
			"ManagedToggleUI_ForcedHidden",
			toggleUIBtn.MouseButton1Click:Connect(function()
				setIconForcedHidden(sidebarGestureEnabled)
			end)
		)
	end
	if activeColorValue then
		makeColorSlider("ActiveColor", "Active Color", "Sidebar active button color", activeColorValue)
	end
	if inactiveColorValue then
		makeColorSlider("InactiveColor", "Inactive Color", "Sidebar inactive button color", inactiveColorValue)
	end
	if iconColorValue then
		makeColorSlider("IconColor", "Icon Color", "Custom color for the Delta icon", iconColorValue)
	end
	if uiScaleState.value then
		makeSizeSlider(
			"InterfaceScale",
			"Interface size",
			"Adjust Delta's interface size",
			uiScaleState.value,
			0.5,
			1.65,
			{
				apply = applyInterfaceScale,
				applyOnRelease = true,
			}
		)
	end
	if iconSizeValue then
		makeSizeSlider("IconSize", "Icon Size", "Scale the Delta icon size", iconSizeValue, 0.5, 5)
	end
	makeEnumDropdown(
		"IconShape",
		"Icon Shape",
		"Choose the shape of the Delta icon",
		{ "Squircle", "Rounded", "Square", "Circle" },
		function()
			return iconShapeName
		end,
		function(name)
			iconShapeName = name
			applyIconShapeChoice()
		end,
		{ persist = true }
	)
	if iconRgbSpeedValue then
		makeSizeSlider("IconRgbSpeed", "RGB Speed", "Speed of the RGB icon effect", iconRgbSpeedValue, 0.05, 2)
	end
	do
		local lighting = game:GetService("Lighting")
		local techItems = Enum.Technology:GetEnumItems()
		makeEnumDropdown(
			"LightingTechnology",
			"Lighting Technology",
			"Set Lighting.Technology from Delta settings",
			techItems,
			function()
				return lighting and lighting.Technology and lighting.Technology.Name
					or techItems[1] and techItems[1].Name
			end,
			function(name)
				local enumItem = Enum.Technology[name]
				if lighting and enumItem then
					pcall(function()
						lighting.Technology = enumItem
					end)
				end
			end,
			{ persist = false }
		)
	end
	do
		local selectedCameraType
		local camItems = Enum.CameraType:GetEnumItems()
		local function applyCameraType(name)
			local enumItem = Enum.CameraType[name]
			if not enumItem then
				return
			end
			selectedCameraType = name
			local cam = workspace.CurrentCamera
			if cam then
				pcall(function()
					cam.CameraType = enumItem
				end)
			end
		end
		makeEnumDropdown(
			"CameraType",
			"Camera Type",
			"Set CurrentCamera.CameraType from Delta settings",
			camItems,
			function()
				local cam = workspace.CurrentCamera
				return cam and cam.CameraType and cam.CameraType.Name or camItems[1] and camItems[1].Name
			end,
			applyCameraType,
			{ persist = false }
		)
		NAlib.disconnect("CameraType_Reapply")
		NAlib.connect(
			"CameraType_Reapply",
			workspace:GetPropertyChangedSignal("CurrentCamera"):Connect(function()
				task.defer(function()
					if selectedCameraType then
						applyCameraType(selectedCameraType)
					end
				end)
			end)
		)
	end
	do
		local soundService = game:GetService("SoundService")
		local reverbItems = Enum.ReverbType:GetEnumItems()
		makeEnumDropdown(
			"SoundReverb",
			"Sound Reverb",
			"Set SoundService.AmbientReverb from Delta settings",
			reverbItems,
			function()
				return soundService and soundService.AmbientReverb and soundService.AmbientReverb.Name
					or reverbItems[1] and reverbItems[1].Name
			end,
			function(name)
				local enumItem = Enum.ReverbType[name]
				if soundService and enumItem then
					pcall(function()
						soundService.AmbientReverb = enumItem
					end)
				end
			end,
			{ persist = false }
		)
	end
	if type(setfpscap) == "function" then
		local fpsCapValue = Instance.new("NumberValue")
		fpsCapValue.Name = "FpsCapValue"
		local fpsSaved = settingsConfig.FpsCap
		local fpsHasSaved = type(fpsSaved) == "table" and type(fpsSaved.value) == "number"
		fpsCapValue.Value = fpsHasSaved and math.clamp(math.floor(fpsSaved.value + 0.5), 30, 999) or 60
		local fpsCapTarget = fpsCapValue.Value
		local function applyFpsCap(v)
			local n = math.clamp(math.floor((tonumber(v) or 60) + 0.5), 30, 999)
			if fpsCapValue.Value ~= n then
				fpsCapValue.Value = n
			end
			fpsCapTarget = n
			pcall(setfpscap, n)
		end
		NAlib.disconnect("FpsCap_Enforce")
		local function reapplyFpsCap()
			if fpsCapTarget then
				pcall(setfpscap, fpsCapTarget)
			end
		end
		if UIS and UIS.WindowFocused then
			NAlib.connect("FpsCap_Reapply", UIS.WindowFocused:Connect(reapplyFpsCap))
		end
		makeSizeSlider("FpsCap", "FPS cap", "set your FPS cap to anything you like", fpsCapValue, 1, 999, {
			integer = true,
			apply = applyFpsCap,
		})
		if fpsHasSaved then
			task.defer(function()
				applyFpsCap(fpsCapValue.Value)
			end)
		end
	end
	if sidebarGrad1 and sidebarGrad2 and sidebarGradient then
		makeColorSlider("SidebarGradient1", "Sidebar Gradient 1", "First sidebar gradient color", sidebarGrad1)
		makeColorSlider("SidebarGradient2", "Sidebar Gradient 2", "Second sidebar gradient color", sidebarGrad2)
		local function updateSidebarGradient()
			sidebarGradient.Color = ColorSequence.new({
				ColorSequenceKeypoint.new(0, sidebarGrad1.Value),
				ColorSequenceKeypoint.new(1, sidebarGrad2.Value),
			})
		end
		updateSidebarGradient();
		(sidebarGrad1:GetPropertyChangedSignal("Value")):Connect(updateSidebarGradient);
		(sidebarGrad2:GetPropertyChangedSignal("Value")):Connect(updateSidebarGradient)
	end
	makeIconVisibilityToggle()
	makeIconPositionSaveToggle()
	makeIconStrokeToggle()
	makeIconRgbToggle()
	makeTabNotifToggle()
	makeIconEnableToggle()
	makeIconInputRow()
	makeIconManagerRow()
	makeColorSlider("GestureColor", "Gesture Color", "Color of the sidebar gesture bar", gestCol)
	makeSidebarGestureToggle()
	makeSidebarGestureBarVisibilityToggle()
	if gestureWidthValue then
		makeSizeSlider("GestureWidth", "Gesture width", "Width of the sidebar gesture area", gestureWidthValue, 6, 80)
	end
	if gestureHeightValue then
		makeSizeSlider(
			"GestureHeight",
			"Gesture height",
			"Height of the sidebar gesture area",
			gestureHeightValue,
			60,
			400
		)
	end
	makeAutoCloseToggle()
	makeDestroyUIButton()
	task.defer(function()
		task.wait()
		pcall(function()
			capUi()
			apRad()
			apPan()
			apStk()
			fxSync()
		end)
	end)
	applySidebarGestureState()
	if autoCloseOnLoad and sidebar then
		task.defer(function()
			task.wait(1.5)
			closeDeltaSidebar()
		end)
	end
	local sidemenu = execFrame:FindFirstChild("Sidemenu", true)
	if sidemenu then
		local oldCard = sidemenu:FindFirstChild("Script", true)
		if oldCard and oldCard:IsA("ImageLabel") then
			local parent = oldCard.Parent
			local newCard = oldCard:Clone()
			__dcm_setTracked(oldCard, "Parent", nil)
			newCard.Name = "LT_FeaturedScriptCard"
			newCard.Parent = parent
			local labs = {}
			for _, d in newCard:QueryDescendants("TextLabel") do
				table.insert(labs, d)
			end
			if #labs >= 3 then
				table.sort(labs, function(a, b)
					return a.AbsolutePosition.Y < b.AbsolutePosition.Y
				end)
				local bigHeader = labs[1]
				local subTitle = labs[2]
				local desc = labs[3]
				if bigHeader then
					bigHeader.Text = "Featured"
				end
				if subTitle then
					subTitle.Text = "Nameless Admin"
				end
				if desc then
					desc.Text =
						"continuation of Nameless Admin with advanced features, fixed commands and lots of customization."
				end
			end
			local clickable = nil
			for _, d in newCard:QueryDescendants("Instance") do
				if d:IsA("LocalScript") then
					d:Destroy()
				elseif d:IsA("TextButton") then
					clickable = d
				end
			end
			if not clickable then
				clickable = newCard:FindFirstChildWhichIsA("GuiButton")
					or newCard:FindFirstChildWhichIsA("GuiButton", true)
					or newCard
			end
			local function runNA()
				fixNet(mainGui)
				local ok, er = runUrl(
					"https://gitlab.com/ltseverydayyou/Nameless-Admin/-/raw/main/Source.lua",
					"@NamelessAdminSource.lua"
				)
				if not ok then
					toast("ScriptHub", tostring(er))
				end
			end
			if clickable:IsA("GuiButton") then
				clickable.MouseButton1Click:Connect(runNA)
			else
				clickable.InputBegan:Connect(function(input)
					if
						input.UserInputType == Enum.UserInputType.MouseButton1
						or input.UserInputType == Enum.UserInputType.Touch
					then
						runNA()
					end
				end)
			end
		end
	end
	local pingLabel
	do
		local nFrame = sidemenu and sidemenu:FindFirstChild("Network", true)
		if nFrame then
			local overlayNet = nFrame:FindFirstChild("Overlay", true)
			local holderNet = overlayNet and overlayNet:FindFirstChild("Holder", true)
			local infoNet = holderNet and holderNet:FindFirstChild("Information", true)
			pingLabel = infoNet and infoNet:FindFirstChild("Ping")
		end
	end
	if pingLabel and Stats and RS then
		local net = Stats.Network
		local item = net and net.ServerStatsItem and net.ServerStatsItem["Data Ping"]
		if item then
			pingLabel.RichText = true
			local pingId = "DeltaCustom_Ping"
			NAlib.disconnect(pingId)
			local function updatePing()
				local v = 0
				pcall(function()
					if item.GetValue then
						v = item:GetValue()
					elseif item.Value ~= nil then
						v = item.Value
					end
				end)
				pingLabel.Text = string.format('<font color="#4FA4F2">%d</font> MS Ping', math.floor(tonumber(v) or 0))
			end
			updatePing()
			local pingAccum = 0
			NAlib.connect(
				pingId,
				RS.Heartbeat:Connect(function(dt)
					pingAccum += dt
					if pingAccum < 0.5 then
						return
					end
					pingAccum = 0
					updatePing()
				end)
			)
		end
	end
	local tabs = overlay:FindFirstChild("Tabs", true)
	local codeSf = overlay:FindFirstChild("Code", true)
	if not tabs then
		notify({ Title = "Delta Customization", Description = "Tabs frame not found.", Duration = 4 })
		return
	end
	if not codeSf then
		notify({ Title = "Delta Customization", Description = "Code frame not found.", Duration = 4 })
		return
	end
	local hasFS = type(isfolder) == "function"
		and type(makefolder) == "function"
		and type(isfile) == "function"
		and type(writefile) == "function"
		and type(readfile) == "function"
		and type(listfiles) == "function"
	if not hasFS then
		notify({
			Title = "Delta Customization",
			Description = "Your executor does not support saving tabs.",
			Duration = 5,
		})
		return
	end
	local rootDir = "DeltaCustom"
	local tabsDir = rootDir .. "/DeltaTabs"
	if not isfolder(rootDir) then
		pcall(makefolder, rootDir)
	end
	if not isfolder(tabsDir) then
		pcall(makefolder, tabsDir)
	end
	local function parseIndex(nm)
		return tonumber(nm:match("^script(%d+)%.lua$"))
	end
	local function isScriptName(nm)
		return parseIndex(nm) ~= nil
	end
	local function getCodeBoxes()
		local t = {}
		for _, c in codeSf:QueryDescendants("TextBox") do
			if isScriptName(c.Name) then				table.insert(t, c)
			end
		end
		table.sort(t, function(a, b)
			return (parseIndex(a.Name) or 0) < (parseIndex(b.Name) or 0)
		end)
		return t
	end
	local function getSavedNames()
		local list = {}
		for _, p in listfiles(tabsDir) do
			local nm = p:match("([^/\\]+)$")
			if nm and isScriptName(nm) then
				table.insert(list, nm)
			end
		end
		table.sort(list, function(a, b)
			return (parseIndex(a) or 0) < (parseIndex(b) or 0)
		end)
		return list
	end
	local saved = getSavedNames()
	local boxes = getCodeBoxes()
	if tabNotifEnabled then
		if #saved > 0 then
			local desc
			if #saved > #boxes then
				desc = "Saved tabs: "
					.. tostring(#saved)
					.. "\nCreate your tabs in Delta and the saved code will load automatically."
			else
				desc = "Saved tabs: "
					.. tostring(#saved)
					.. "\nYour saved code will load into matching tabs automatically."
			end
			notify({ Title = "Delta Customization", Description = desc, Duration = 8 })
		else
			notify({
				Title = "Delta Customization",
				Description = "No saved tabs yet. Anything you type will be saved automatically.",
				Duration = 6,
			})
		end
	end
	local hooked = {}
	local function hookBox(box)
		if not box or hooked[box] then
			return
		end
		hooked[box] = true
		local ready = false
		local function setupForName(nm)
			if ready then
				return
			end
			if not isScriptName(nm) then
				return
			end
			ready = true
			local path = tabsDir .. "/" .. nm
			if isfile(path) then
				local ok, data = pcall(readfile, path)
				if ok and type(data) == "string" then
					box.Text = data
				end
			else
				pcall(writefile, path, box.Text or "")
			end
			local last = 0
			(box:GetPropertyChangedSignal("Text")):Connect(function()
				last = tick()
				local id = last
				task.delay(0.4, function()
					if id ~= last then
						return
					end
					local txt = box.Text
					pcall(writefile, path, txt)
				end)
			end)
		end
		setupForName(box.Name);
		(box:GetPropertyChangedSignal("Name")):Connect(function()
			setupForName(box.Name)
		end)
	end
	for _, b in boxes do
		hookBox(b)
	end
	codeSf.DescendantAdded:Connect(function(obj)
		if obj:IsA("TextBox") then
			task.wait(0.05)
			hookBox(obj)
		end
	end)
	codeSf.DescendantRemoving:Connect(function(obj)
		if not (obj:IsA("TextBox") and isScriptName(obj.Name) and type(delfile) == "function") then
			return
		end
		local txt = ""
		pcall(function()
			txt = obj.Text
		end)
		if type(txt) ~= "string" or txt:match("^%s*$") then
			local path = tabsDir .. "/" .. obj.Name
			if isfile(path) then
				pcall(delfile, path)
			end
		end
	end)
end)


__lt.deltaPatchState = __lt.deltaPatchState or {}
__lt.deltaPatchState.visualEnv = __dcm_env
if type(__lt.deltaPatchState.visualEnv) == "table" and not __lt.deltaPatchState.visualEnv.__DeltaVisualPatchLoaded then
	__lt.deltaPatchState.visualEnv.__DeltaVisualPatchLoaded = true
	task.defer(function()
		if (identifyexecutor and identifyexecutor() or ""):lower() ~= "delta" then
			return
		end
		local function S(n)
			local ok, s = pcall(function()
				return __lt.cs(n, cloneref and cloneref or function(v)
					return v
				end)
			end)
			if ok then
				return s
			end
		end
		local HS = S("HttpService")
		local TS = S("TweenService")
		local CG = S("CoreGui")
		local root = gethui and gethui() or CG
		local function isGib(n)
			if typeof(n) ~= "string" or n == "" then
				return false
			end
			return not n:match("^[%w _%-]+$")
		end
		local function getMain()
			for _, g in root:GetChildren() do
				if g:IsA("ScreenGui") and isGib(g.Name) then
					if
						g:FindFirstChild("Executor", true)
						and g:FindFirstChild("Scripthub", true)
						and g:FindFirstChild("Sidebar", true)
					then
						return g
					end
				end
			end
		end
		local mainGui = getMain()
		if not mainGui then
			return
		end
		do
			local vp = workspace.CurrentCamera and workspace.CurrentCamera.ViewportSize or mainGui.AbsoluteSize
			if UIS and UIS.TouchEnabled and (vp.X <= 1100 or vp.Y <= 820) then
				local darkOverlay = mainGui:FindFirstChild("DarkOverlay")
				if darkOverlay then
					pcall(function()
						darkOverlay.Visible = false
						darkOverlay.Active = false
					end)
				end
				return
			end
		end
		local sectionsList = { "Executor", "Home", "Scripthub", "Settings", "Console", "Music" }
		local settingsPath = "DeltaCustom/Settings.json"
		local settingsConfig = {}
		if HS and type(isfile) == "function" and type(readfile) == "function" and isfile(settingsPath) then
			local ok, data = pcall(readfile, settingsPath)
			if ok and data then
				local ok2, dec = pcall(function()
					return __lt.cm("HttpService", "JSONDecode", data)
				end)
				if ok2 and type(dec) == "table" then
					settingsConfig = dec
				end
			end
		end
		local function saveCfg(k, t)
			if not (HS and type(writefile) == "function") then
				return
			end
			settingsConfig[k] = t
			writeJsonFile(settingsPath, settingsConfig)
		end
		local darkOverlay = mainGui:FindFirstChild("DarkOverlay")
		NAlib.disconnect("DarkOverlay_Hide")
		local dimFr = darkOverlay
		if not dimFr then
			dimFr = Instance.new("Frame")
			dimFr.Name = "DarkOverlay"
			dimFr.BackgroundColor3 = Color3.new(0, 0, 0)
			dimFr.BorderSizePixel = 0
			dimFr.Position = UDim2.fromScale(0, 0)
			dimFr.Size = UDim2.fromScale(1, 1)
			dimFr.ZIndex = 1
			dimFr.Visible = false
			dimFr.Active = false
			dimFr.Parent = mainGui
		end
		pcall(function()
			dimFr.BackgroundColor3 = Color3.new(0, 0, 0)
			dimFr.BorderSizePixel = 0
			dimFr.Position = UDim2.fromScale(0, 0)
			dimFr.Size = UDim2.fromScale(1, 1)
			dimFr.ZIndex = 1
			dimFr.Active = false
		end)
		local base = { cor = {}, pan = {}, str = {}, got = false }
		local okNm = {
			Sidebar = true,
			Overlay = true,
			Popup = true,
			Searchbar = true,
			Script = true,
			Network = true,
			Information = true,
			RobloxConsole = true,
			RConsole = true,
			Source = true,
			Title = true,
			Executor = true,
			Console = true,
			Home = true,
			Scripthub = true,
			Settings = true,
			Dropdown = true,
			SettingDropdown = true,
			SettingTextbox = true,
			SettingSwitch = true,
			SettingSwitchOn = true,
			Button = true,
			InputText = true,
			LT_ScriptHub = true,
			LT_Music = true,
			Top = true,
			Bottom = true,
			List = true,
			Card = true,
			Card1 = true,
		}
		local skip = {
			Knob = true,
			Hue = true,
			Sat = true,
			Val = true,
			Fill = true,
			DarkOverlay = true,
			SidebarGestureZone = true,
		}
		local function capUi()
			if not mainGui then
				return
			end
			for _, o in mainGui:QueryDescendants("Instance") do
				if o:IsA("UICorner") then
					local p = o.Parent
					if p and p:IsA("GuiObject") and not skip[p.Name] then
						local s = p.AbsoluteSize
						if okNm[p.Name] or (s.X >= 44 and s.Y >= 18) then
							if base.cor[o] == nil then
								base.cor[o] = o.CornerRadius
							end
						end
					end
				elseif o:IsA("UIStroke") then
					if base.str[o] == nil then
						base.str[o] = o.Thickness
					end
				elseif
					o:IsA("Frame")
					or o:IsA("ImageLabel")
					or o:IsA("TextBox")
					or o:IsA("TextButton")
					or o:IsA("ImageButton")
					or o:IsA("ScrollingFrame")
				then
					if not skip[o.Name] then
						local s = o.AbsoluteSize
						if okNm[o.Name] or s.X >= 120 or s.Y >= 28 then
							local pr = (o:IsA("ImageLabel") or o:IsA("ImageButton")) and "ImageTransparency"
								or "BackgroundTransparency"
							if base.pan[o] == nil then
								base.pan[o] = { pr, o[pr] }
							end
						end
					end
				end
			end
			base.got = true
		end
		local radVal = Instance.new("NumberValue")
		radVal.Value = type(settingsConfig.UiRound) == "table" and math.clamp(settingsConfig.UiRound.value or 0, 0, 18)
			or 0
		local panVal = Instance.new("NumberValue")
		panVal.Value = type(settingsConfig.UiAlpha) == "table"
				and math.clamp(settingsConfig.UiAlpha.value or 0, 0, 0.35)
			or 0
		local stkVal = Instance.new("NumberValue")
		stkVal.Value = type(settingsConfig.UiStroke) == "table"
				and math.clamp(settingsConfig.UiStroke.value or 1, 0, 2.5)
			or 1
		local dimVal = Instance.new("NumberValue")
		dimVal.Value = type(settingsConfig.UiDim) == "table" and math.clamp(settingsConfig.UiDim.value or 0.28, 0, 0.65)
			or 0.28
		local dimDesiredVisible = false
		local dimDesiredTransparency = 1
		local dimGuardBusy = false
		local function applyDimState(force)
			if dimGuardBusy then
				return
			end
			dimGuardBusy = true
			pcall(function()
				if force or dimFr.Visible ~= dimDesiredVisible then
					dimFr.Visible = dimDesiredVisible
				end
				if force or math.abs(dimFr.BackgroundTransparency - dimDesiredTransparency) > 0.001 then
					dimFr.BackgroundTransparency = dimDesiredTransparency
				end
				dimFr.Active = false
				if force or dimFr.BackgroundColor3 ~= Color3.new(0, 0, 0) then
					dimFr.BackgroundColor3 = Color3.new(0, 0, 0)
				end
			end)
			dimGuardBusy = false
		end
		local function syncDimLoop()
			NAlib.disconnect("DeltaCustom_DimGuard")
			NAlib.connect(
				"DeltaCustom_DimGuard",
				dimFr:GetPropertyChangedSignal("Visible"):Connect(function()
					if not dimGuardBusy and dimFr.Visible ~= dimDesiredVisible then
						task.defer(applyDimState, false)
					end
				end)
			)
			NAlib.connect(
				"DeltaCustom_DimGuard",
				dimFr:GetPropertyChangedSignal("BackgroundTransparency"):Connect(function()
					if
						not dimGuardBusy
						and math.abs(dimFr.BackgroundTransparency - dimDesiredTransparency) > 0.001
					then
						task.defer(applyDimState, false)
					end
				end)
			)
		end
		local function apRad()
			capUi()
			local v = math.floor(math.clamp(radVal.Value, 0, 18) + 0.5)
			for o, b in base.cor do
				if o and o.Parent then
					pcall(function()
						o.CornerRadius = UDim.new(b.Scale, math.max(b.Offset, v))
					end)
				end
			end
		end
		local function apPan()
			capUi()
			local a = math.clamp(panVal.Value, 0, 0.35)
			for o, b in base.pan do
				if o and o.Parent then
					pcall(function()
						o[b[1]] = math.clamp(b[2] + a, 0, 1)
					end)
				end
			end
		end
		local function apStk()
			capUi()
			local m = math.clamp(stkVal.Value, 0, 2.5)
			for o, b in base.str do
				if o and o.Parent then
					pcall(function()
						o.Thickness = b * m
					end)
				end
			end
		end
		local function uiOpen()
			for _, n in sectionsList do
				local fr = mainGui:FindFirstChild(n)
				if fr and fr:IsA("GuiObject") and fr.Visible then
					return true
				end
			end
			return false
		end
		local function fxSync()
			local on = uiOpen()
			dimDesiredVisible = on and dimVal.Value > 0.01
			dimDesiredTransparency = 1 - math.clamp(dimVal.Value, 0, 0.85)
			applyDimState(true)
			syncDimLoop()
		end
		capUi()
		apRad()
		apPan()
		apStk()
		fxSync()
		radVal.Changed:Connect(function()
			apRad()
			saveCfg("UiRound", { value = math.clamp(radVal.Value, 0, 18) })
		end)
		panVal.Changed:Connect(function()
			apPan()
			saveCfg("UiAlpha", { value = math.clamp(panVal.Value, 0, 0.35) })
		end)
		stkVal.Changed:Connect(function()
			apStk()
			saveCfg("UiStroke", { value = math.clamp(stkVal.Value, 0, 2.5) })
		end)
		dimVal.Changed:Connect(function()
			fxSync()
			saveCfg("UiDim", { value = math.clamp(dimVal.Value, 0, 0.65) })
		end)
		for _, n in sectionsList do
			local fr = mainGui:FindFirstChild(n)
			if fr and fr.GetPropertyChangedSignal then
				fr:GetPropertyChangedSignal("Visible"):Connect(function()
					task.defer(fxSync)
				end)
			end
		end
		local settings = mainGui:FindFirstChild("Settings", true)
		local holder = settings and settings:FindFirstChild("Holder")
		local template
		if holder then
			for _, c in holder:GetChildren() do
				if c:IsA("Frame") and c.Name == "Button" then
					template = c
					break
				end
			end
		end
		if holder and template then
			local function mkDock(fr)
				local d = Instance.new("Frame")
				d.Name = "Dock"
				d.BackgroundTransparency = 1
				d.AnchorPoint = Vector2.new(1, 0.5)
				d.Position = UDim2.new(1, -14, 0.5, 0)
				d.Size = UDim2.new(0, 320, 0, 18)
				d.Parent = fr
				local l = Instance.new("UIListLayout")
				l.FillDirection = Enum.FillDirection.Horizontal
				l.HorizontalAlignment = Enum.HorizontalAlignment.Right
				l.VerticalAlignment = Enum.VerticalAlignment.Center
				l.Padding = UDim.new(0, 8)
				l.Parent = d
				return d
			end
			local function mkBox(par)
				local b = Instance.new("TextBox")
				b.Name = "ValueBox"
				b.Size = UDim2.new(0, 70, 0, 18)
				b.BackgroundColor3 = Color3.fromRGB(20, 20, 20)
				b.BorderSizePixel = 0
				b.ClearTextOnFocus = false
				b.TextXAlignment = Enum.TextXAlignment.Center
				b.Font = Enum.Font.Gotham
				b.TextSize = 12
				b.TextColor3 = Color3.new(1, 1, 1)
				b.Parent = par
				return b
			end
			local function mkSl(par, w)
				local s = Instance.new("Frame")
				s.Name = "Slider"
				s.BackgroundTransparency = 1
				s.Size = UDim2.new(0, w or 150, 0, 18)
				s.Parent = par
				local bar = Instance.new("Frame")
				bar.Name = "Bar"
				bar.BackgroundColor3 = Color3.fromRGB(40, 40, 40)
				bar.BorderSizePixel = 0
				bar.AnchorPoint = Vector2.new(0.5, 0.5)
				bar.Position = UDim2.new(0.5, 0, 0.5, 0)
				bar.Size = UDim2.new(1, 0, 0, 6)
				bar.Parent = s
				local bc = Instance.new("UICorner")
				bc.CornerRadius = UDim.new(0, 3)
				bc.Parent = bar
				local fill = Instance.new("Frame")
				fill.Name = "Fill"
				fill.BorderSizePixel = 0
				fill.AnchorPoint = Vector2.new(0, 0.5)
				fill.Position = UDim2.new(0, 0, 0.5, 0)
				fill.Size = UDim2.new(0, 0, 1, 0)
				fill.Parent = bar
				local fc = Instance.new("UICorner")
				fc.CornerRadius = UDim.new(0, 3)
				fc.Parent = fill
				local kb = Instance.new("Frame")
				kb.Name = "Knob"
				kb.Size = UDim2.new(0, 12, 0, 12)
				kb.AnchorPoint = Vector2.new(0.5, 0.5)
				kb.BackgroundColor3 = Color3.new(1, 1, 1)
				kb.BorderSizePixel = 0
				kb.Parent = bar
				local kc = Instance.new("UICorner")
				kc.CornerRadius = UDim.new(1, 0)
				kc.Parent = kb
				return s, bar, fill, kb
			end
			local function makeSizeSlider(id, titleText, descText, numValue, minV, maxV)
				local fr = __dcm_registerCustom(template:Clone())
				fr.Parent = holder
				fr.Visible = true
				fr.LayoutOrder = -2
				local tl = fr:FindFirstChild("Title", true)
				local dl = fr:FindFirstChild("Desc", true)
				if tl then
					tl.Text = titleText
				end
				if dl then
					dl.Text = descText
				end
				local ob = fr:FindFirstChild("Button", true)
				if ob then
					ob:Destroy()
				end
				local dock = mkDock(fr)
				local vb = mkBox(dock)
				local sl, bar, fill, kb = mkSl(dock, 150)
				local function setVis(v)
					v = math.clamp(v, minV, maxV)
					local a = (v - minV) / (maxV - minV)
					fill.Size = UDim2.new(a, 0, 1, 0)
					kb.Position = UDim2.new(a, 0, 0.5, 0)
					vb.Text = string.format("%.2f", v)
				end
				local function apply(v)
					v = math.clamp(v, minV, maxV)
					numValue.Value = v
					setVis(v)
					saveCfg(id, { value = v })
				end
				setVis(numValue.Value)
				local drag = false
				local function fromIn(input)
					local rel = 0
					pcall(function()
						rel = (input.Position.X - bar.AbsolutePosition.X) / bar.AbsoluteSize.X
					end)
					rel = math.clamp(rel, 0, 1)
					apply(minV + (maxV - minV) * rel)
				end
				bar.InputBegan:Connect(function(input)
					if
						input.UserInputType == Enum.UserInputType.MouseButton1
						or input.UserInputType == Enum.UserInputType.Touch
					then
						drag = true
						fromIn(input)
					end
				end)
				local ui = S("UserInputService")
				if ui then
					ui.InputChanged:Connect(function(input)
						if
							drag
							and (
								input.UserInputType == Enum.UserInputType.MouseMovement
								or input.UserInputType == Enum.UserInputType.Touch
							)
						then
							fromIn(input)
						end
					end)
					ui.InputEnded:Connect(function(input)
						if
							input.UserInputType == Enum.UserInputType.MouseButton1
							or input.UserInputType == Enum.UserInputType.Touch
						then
							drag = false
						end
					end)
				end
				vb.FocusLost:Connect(function()
					local v = tonumber(vb.Text or "")
					if v then
						apply(v)
					else
						setVis(numValue.Value)
					end
				end)
				local function updDock()
					local w = math.clamp(math.floor(fr.AbsoluteSize.X * 0.46), 240, 380)
					dock.Size = UDim2.new(0, w, 0, 18)
					local sw = math.clamp(w - 78, 140, 280)
					sl.Size = UDim2.new(0, sw, 0, 18)
				end
				updDock()
				fr:GetPropertyChangedSignal("AbsoluteSize"):Connect(function()
					task.defer(updDock)
				end)
			end
			makeSizeSlider("UiRound", "UI roundness", "Adds extra roundness to panels and cards", radVal, 0, 18)
			makeSizeSlider(
				"UiAlpha",
				"Panel transparency",
				"Makes the heavy panels cleaner and less chunky",
				panVal,
				0,
				0.35
			)
			makeSizeSlider("UiStroke", "Stroke scale", "Scales borders and outlines across Delta", stkVal, 0, 2.5)
			makeSizeSlider("UiDim", "Open dim", "Darkens the game behind Delta while it is open", dimVal, 0, 0.65)
		end
	end)
end


end

do
local __lt = __lt

if (identifyexecutor and identifyexecutor() or ""):lower() ~= "delta" then
	return
end

local env = __dcm_env
if type(env) ~= "table" then
	return
end

if env.__DeltaHubMusicPatch and type(env.__DeltaHubMusicPatch.stop) == "function" then
	pcall(env.__DeltaHubMusicPatch.stop)
end

local ref = cloneref and type(cloneref) == "function" and cloneref or function(v)
	return v
end

local srv = setmetatable({}, {
	__index = function(t, k)
		local ok, v = pcall(function()
			return __lt.cs(k, ref)
		end)
		if ok and v then
			rawset(t, k, v)
			return v
		end
	end,
})

local function S(n)
	return srv[n]
end

local UIS = S("UserInputService")
local TS = S("TweenService")
local RS = S("RunService")
local SS = S("SoundService")
local HS = S("HttpService")
local CG = S("CoreGui")

local root = gethui and gethui() or CG
local rq = request or http_request or syn and syn.request

local st = {
	con = {},
	pg = {},
	snd = nil,
	muted = {},
	gui = nil,
	fn = {},
}

local function con(c)
	if c then
		st.con[#st.con + 1] = c
	end
	return c
end

local function disc()
	for _, c in st.con do
		pcall(function()
			c:Disconnect()
		end)
	end
	st.con = {}
end

local function stop()
	disc()
	if st.snd then
		pcall(function()
			st.snd:Destroy()
		end)
		st.snd = nil
	end
	if st.pg.music then
		pcall(function()
			st.pg.music:Destroy()
		end)
	end
	if st.pg.musicButton then
		pcall(function()
			st.pg.musicButton:Destroy()
		end)
		st.pg.musicButton = nil
	end
	if st.pg.sh and st.pg.sh:FindFirstChild("LT_ScriptHub") then
		pcall(function()
			st.pg.sh.LT_ScriptHub:Destroy()
		end)
	end
	for o, v in st.muted do
		if o and o.Parent then
			pcall(function()
				o.Visible = v
			end)
		end
	end
	st.muted = {}
	env.__DeltaHubMusicPatch = nil
end

env.__DeltaHubMusicPatch = {
	stop = stop,
}

local function trim(s)
	if type(s) ~= "string" then
		return ""
	end
	return (s:gsub("^%s+", ""):gsub("%s+$", ""))
end

local function isg(s)
	if typeof(s) ~= "string" or s == "" then
		return false
	end
	return not s:match("^[%w _%-]+$")
end

local function getMain()
	for _, g in root:GetChildren() do
		if g:IsA("ScreenGui") and isg(g.Name) then
			if
				g:FindFirstChild("Executor", true)
				and g:FindFirstChild("Scripthub", true)
				and g:FindFirstChild("Sidebar", true)
			then
				return g
			end
		end
	end
end

local gui = getMain()
if not gui then
	return
end
st.gui = gui

local sb = gui:FindFirstChild("Sidebar", true)
local sh = gui:FindFirstChild("Scripthub")
local ex = gui:FindFirstChild("Executor")
local hm = gui:FindFirstChild("Home")
local se = gui:FindFirstChild("Settings")
local co = gui:FindFirstChild("Console")

if not (sb and sh) then
	return
end

st.pg.sh = sh

local sec = {
	"Executor",
	"Home",
	"Scripthub",
	"Settings",
	"Console",
	"Music",
}

local musicState = {
	openPos = UDim2.new(0.476246715, 0, 0.508232415, 0),
	closedPos = UDim2.new(0.400000006, 0, 0.508232415, 0),
	frame = nil,
	button = nil,
	tween = nil,
	activeTab = nil,
	icon = {
		sheetUrl = "https://gitlab.com/ltseverydayyou/Nameless-Admin/-/raw/main/NAimages/sheet.png",
		sheetAsset = nil,
		rectOffset = Vector2.new(371, 806),
		rectSize = Vector2.new(23, 33),
	},
}
local syncTabColors
local function tweenMusic(toPos, show, hideAfter)
	if not musicState.frame then
		return
	end
	if musicState.tween then
		pcall(function()
			musicState.tween:Cancel()
		end)
		musicState.tween = nil
	end
	if show then
		musicState.frame.Visible = true
	end
	if TS then
		musicState.frame.Position = musicState.frame.Position
		musicState.tween =
			TS:Create(musicState.frame, TweenInfo.new(0.22, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {
				Position = toPos,
			})
		if hideAfter then
			con(musicState.tween.Completed:Connect(function()
				if musicState.frame then
					musicState.frame.Visible = false
				end
			end))
		end
		musicState.tween:Play()
	else
		musicState.frame.Position = toPos
		if hideAfter then
			musicState.frame.Visible = false
		end
	end
end

local function openMusic()
	if not musicState.frame then
		return
	end
	musicState.activeTab = "Music"
	for _, n in sec do
		local p = gui:FindFirstChild(n)
		if p and p:IsA("GuiObject") and p ~= musicState.frame then
			p.Visible = false
		end
	end
	musicState.frame.Position = musicState.closedPos
	tweenMusic(musicState.openPos, true, false)
	task.defer(function()
		syncTabColors("Music")
	end)
end

local function closeMusic(anim)
	if not musicState.frame then
		return
	end
	if not musicState.frame.Visible then
		musicState.frame.Position = musicState.closedPos
		return
	end
	if anim then
		tweenMusic(musicState.closedPos, false, true)
	else
		musicState.frame.Position = musicState.closedPos
		musicState.frame.Visible = false
	end
end

local function hideAll(exn)
	if exn == "Music" then
		musicState.activeTab = "Music"
		openMusic()
		return
	end
	musicState.activeTab = exn
	closeMusic(true)
	for _, n in sec do
		local p = gui:FindFirstChild(n)
		if p and p:IsA("GuiObject") and n ~= "Music" then
			p.Visible = n == exn
		end
	end
	task.defer(function()
		syncTabColors(exn)
	end)
end

local function txtOf(o)
	for _, d in o:QueryDescendants("Instance") do
		if d:IsA("TextLabel") or d:IsA("TextButton") then
			return d
		end
	end
end

local function gbtn(nm)
	for _, d in sb:QueryDescendants("GuiButton") do
		if d.Name == nm then			return d
		end
	end
end

local sidebarRefs = {
	home = gbtn("Home"),
	scripthub = gbtn("Scripthub"),
	settings = gbtn("Settings"),
	executor = gbtn("Executor"),
	console = gbtn("Console"),
	toggle = gbtn("ToggleUI"),
	activeColor = sb:FindFirstChild("ActiveColor"),
	inactiveColor = sb:FindFirstChild("InactiveColor"),
}

local function imgOf(btn)
	if not btn then
		return nil
	end
	return btn:FindFirstChildWhichIsA("ImageLabel")
end

local function improveSidebarTouch(btn)
	if not (btn and btn:IsA("GuiButton") and UIS and UIS.TouchEnabled) then
		return btn
	end
	if btn:GetAttribute("LT_TouchSized") then
		return btn
	end
	btn:SetAttribute("LT_TouchSized", true)
	pcall(function()
		btn.Size = UDim2.new(btn.Size.X.Scale, btn.Size.X.Offset + 8, btn.Size.Y.Scale, btn.Size.Y.Offset + 14)
	end)
	return btn
end

local offBg = sidebarRefs.scripthub and sidebarRefs.scripthub.BackgroundColor3 or Color3.fromRGB(41, 45, 58)
local offImg = imgOf(sidebarRefs.scripthub) and imgOf(sidebarRefs.scripthub).ImageColor3
	or Color3.fromRGB(138, 145, 164)
local onImg = Color3.new(1, 1, 1)

improveSidebarTouch(sidebarRefs.home)
improveSidebarTouch(sidebarRefs.scripthub)
improveSidebarTouch(sidebarRefs.settings)
improveSidebarTouch(sidebarRefs.executor)
improveSidebarTouch(sidebarRefs.console)
improveSidebarTouch(sidebarRefs.toggle)

local function bgOn()
	return sidebarRefs.activeColor and sidebarRefs.activeColor.Value or col.ac
end

local function bgOff()
	return sidebarRefs.inactiveColor and sidebarRefs.inactiveColor.Value or offBg
end

local function applyBtnState(btn, on)
	if not btn then
		return
	end
	local targetBg = on and bgOn() or bgOff()
	local targetImg = on and onImg or offImg
	local img = imgOf(btn)
	if TS then
		pcall(function()
			TS:Create(btn, TweenInfo.new(0.16, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {
				BackgroundColor3 = targetBg,
			}):Play()
		end)
		if img then
			pcall(function()
				TS:Create(img, TweenInfo.new(0.16, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {
					ImageColor3 = targetImg,
				}):Play()
			end)
		end
	else
		pcall(function()
			btn.BackgroundColor3 = targetBg
		end)
		if img then
			pcall(function()
				img.ImageColor3 = targetImg
			end)
		end
	end
end

local function visibleTab()
	for _, n in sec do
		local p = gui:FindFirstChild(n)
		if p and p:IsA("GuiObject") and p.Visible then
			return n
		end
	end
end

function syncTabColors(forceTab)
	local curTab = forceTab or visibleTab()
	local map = {
		Home = sidebarRefs.home,
		Executor = sidebarRefs.executor,
		Scripthub = sidebarRefs.scripthub,
		Settings = sidebarRefs.settings,
		Console = sidebarRefs.console,
		Music = musicState.button,
	}
	for n, b in map do
		applyBtnState(b, curTab == n)
	end
end

local function muteObj(d)
	if not (d and d:IsA("GuiObject")) then
		return
	end
	local keep = false
	if d == sh then
		keep = true
	elseif d:FindFirstAncestor("LT_ScriptHub") then
		keep = true
	end
	if keep then
		return
	end
	if st.muted[d] == nil then
		st.muted[d] = d.Visible
	end
	local master = rawget(__dcm_env, "__DeltaCustomizationMasterRuntime")
	if type(master) == "table" and type(master.setTracked) == "function" then
		master.setTracked(d, "Visible", false)
	else
		pcall(function()
			d.Visible = false
		end)
	end
	if d.GetPropertyChangedSignal then
		con(d:GetPropertyChangedSignal("Visible"):Connect(function()
			if d.Parent and not d:FindFirstAncestor("LT_ScriptHub") then
				pcall(function()
					d.Visible = false
				end)
			end
		end))
	end
end

local function muteSh()
	for _, d in sh:QueryDescendants("Instance") do
		muteObj(d)
	end
end

st.fn.setupHubMusic = function()

local col = {
	bg = Color3.fromRGB(20, 22, 26),
	bg2 = Color3.fromRGB(30, 33, 40),
	cd = Color3.fromRGB(26, 29, 36),
	st = Color3.fromRGB(70, 75, 85),
	ac = Color3.fromRGB(79, 164, 242),
	tx = Color3.fromRGB(255, 255, 255),
	td = Color3.fromRGB(186, 192, 205),
	su = Color3.fromRGB(52, 211, 153),
	wa = Color3.fromRGB(255, 179, 71),
	er = Color3.fromRGB(244, 63, 94),
}

local function mk(class, props, kids)
	local o = Instance.new(class)
	for k, v in props or {} do
		o[k] = v
	end
	for _, c in kids or {} do
		c.Parent = o
	end
	return o
end

local function req(u)
	local body
	local status = 0
	if type(rq) == "function" then
		local ok, r = pcall(rq, {
			Url = u,
			Method = "GET",
			Headers = {
				["User-Agent"] = "Roblox/Http/1.1",
				["Accept"] = "application/json",
			},
		})
		if ok and r then
			body = r.Body or r.body
			status = r.StatusCode or r.Status or r.status_code or 0
		end
	end
	if type(body) ~= "string" or body == "" then
		local ok2, r2 = pcall(function()
			return game:HttpGet(u)
		end)
		if ok2 and type(r2) == "string" and r2 ~= "" then
			body = r2
			status = 0
		end
	end
	if type(body) ~= "string" or body == "" then
		return nil, status
	end
	local ok3, dec = pcall(function()
		return __lt.cm("HttpService", "JSONDecode", body)
	end)
	if ok3 then
		return dec, status
	end
	return nil, status
end

local SCRIPTBLOX_BASE = "https://scriptblox.com"
local RSCRIPTS_BASE = "https://rscripts.net"
local ROSCRIPTS_BASE = "https://roscripts.io"
local HAXHELL_BASE = "https://haxhell.com"
local IMAGE_CACHE_DIR = "DeltaCustom/ScriptHubImages"
local MUSIC_CACHE_DIR = "DeltaCustom/DeltaMusic"
local MUSIC_CFG_PATH = MUSIC_CACHE_DIR .. "/_config.json"
local MUSIC_EXTS = {
	mp3 = true,
	ogg = true,
	flac = true,
	wav = true,
}
local musicCfg = {}

local function sanitizeFileName(str)
	return tostring(str or ""):gsub("[^%w%._%-]", "_")
end

local function hashString(str)
	local h = 0
	for i = 1, #str do
		h = (h * 31 + string.byte(str, i)) % 4294967296
	end
	return string.format("%08x", h)
end

local function clearImageCache()
	if
		type(isfolder) ~= "function"
		or type(listfiles) ~= "function"
		or type(isfile) ~= "function"
		or type(delfile) ~= "function"
	then
		return false
	end
	local okExists, exists = pcall(isfolder, IMAGE_CACHE_DIR)
	if not okExists or not exists then
		return false
	end
	local okList, files = pcall(listfiles, IMAGE_CACHE_DIR)
	if not okList or type(files) ~= "table" then
		return false
	end
	for _, path in files do
		if type(path) == "string" and path ~= "" then
			pcall(delfile, path)
		end
	end
	return true
end

local function ensureImageFolder()
	if type(isfolder) ~= "function" or type(makefolder) ~= "function" then
		return false
	end
	local ok, ex = pcall(isfolder, IMAGE_CACHE_DIR)
	if ok and ex then
		return true
	end
	return pcall(makefolder, IMAGE_CACHE_DIR) == true
end

local function ensureMusicFolder()
	if type(isfolder) ~= "function" or type(makefolder) ~= "function" then
		return false
	end
	local ok, ex = pcall(isfolder, MUSIC_CACHE_DIR)
	if ok and ex then
		return true
	end
	return pcall(makefolder, MUSIC_CACHE_DIR) == true
end

local function getAudioExt(path)
	if type(path) ~= "string" then
		return nil
	end
	local clean = path:match("([^?#]+)") or path
	local ext = clean:match("%.([%w]+)$")
	if not ext then
		return nil
	end
	ext = ext:lower()
	return MUSIC_EXTS[ext] and ext or nil
end

local function normalizeAudioUrl(url)
	if type(url) ~= "string" then
		return nil
	end
	local t = trim(url)
	if t == "" then
		return nil
	end
	t = t:gsub(" ", "%%20")
	t = t:gsub(
		"^https://github%.com/([^/]+)/([^/]+)/blob/([^/]+)/(.+)$",
		"https://raw.githubusercontent.com/%1/%2/%3/%4"
	)
	return t
end

local function deriveAudioFileName(url, ext)
	local name = url:match("/([^/%?#]+)") or "track"
	name = name:match("([^?#]+)") or name
	local base = sanitizeFileName(name:gsub("%.[^%.]+$", ""))
	base = base ~= "" and base or "track"
	return string.format("%s_%s.%s", base, hashString(url), ext)
end

local function resolveMusicAsset(full)
	if type(full) ~= "string" or full == "" or type(getcustomasset) ~= "function" or type(isfile) ~= "function" then
		return nil
	end
	local okEx, ex = pcall(isfile, full)
	if not (okEx and ex) then
		return nil
	end
	local okAsset, asset = pcall(getcustomasset, full)
	if okAsset and type(asset) == "string" and asset ~= "" then
		return asset
	end
	return nil
end

local function loadMusicCfg()
	if HS and type(isfile) == "function" and type(readfile) == "function" and isfile(MUSIC_CFG_PATH) then
		local ok, data = pcall(readfile, MUSIC_CFG_PATH)
		if ok and type(data) == "string" and data ~= "" then
			local okDec, dec = pcall(function()
				return __lt.cm("HttpService", "JSONDecode", data)
			end)
			if okDec and type(dec) == "table" then
				musicCfg = dec
				return
			end
		end
	end
	musicCfg = {}
end

local function saveMusicCfg()
	if not (HS and type(writefile) == "function" and ensureMusicFolder()) then
		return false
	end
	return writeJsonFile(MUSIC_CFG_PATH, musicCfg)
end

local function scanMusicFiles()
	local list = {}
	if type(listfiles) ~= "function" or not ensureMusicFolder() then
		return list
	end
	local okList, files = pcall(listfiles, MUSIC_CACHE_DIR)
	if not okList or type(files) ~= "table" then
		return list
	end
	for _, path in files do
		if type(path) == "string" then
			local ext = getAudioExt(path)
			if ext then
				local name = path:match("([^/\\]+)$") or path
				list[#list + 1] = {
					path = path,
					name = name,
					asset = resolveMusicAsset(path),
				}
			end
		end
	end
	table.sort(list, function(a, b)
		return (a.name or ""):lower() < (b.name or ""):lower()
	end)
	return list
end

local function makeMusicFolderDropdown(par, y, z, onPick, onToggle)
	local state = {
		open = false,
		menuHeight = 0,
	}

	local hoverBg = mk("Frame", {
		Name = "LocalTrackHover",
		BackgroundColor3 = Color3.fromRGB(41, 45, 56),
		BackgroundTransparency = 1,
		BorderSizePixel = 0,
		Position = UDim2.new(0, 16, 0, y),
		Size = UDim2.new(1, -32, 0, 32),
		Parent = par,
		ZIndex = z,
	}, {
		mk("UICorner", {
			CornerRadius = UDim.new(0, 10),
		}),
	})

	local btn = mk("TextButton", {
		Name = "LocalTrackButton",
		BackgroundColor3 = col.bg,
		BorderSizePixel = 0,
		Position = UDim2.new(0, 16, 0, y),
		Size = UDim2.new(1, -32, 0, 32),
		Text = "",
		AutoButtonColor = false,
		Parent = par,
		ZIndex = z + 1,
	}, {
		mk("UICorner", {
			CornerRadius = UDim.new(0, 10),
		}),
		mk("UIStroke", {
			Color = col.st,
			Transparency = 0.3,
		}),
	})

	local value = mk("TextLabel", {
		Name = "Value",
		BackgroundTransparency = 1,
		Position = UDim2.new(0, 12, 0, 0),
		Size = UDim2.new(1, -38, 1, 0),
		Text = "Pick local audio from DeltaMusic",
		TextColor3 = col.tx,
		Font = Enum.Font.GothamSemibold,
		TextSize = 13,
		TextTruncate = Enum.TextTruncate.AtEnd,
		TextXAlignment = Enum.TextXAlignment.Left,
		Parent = btn,
		ZIndex = z + 2,
	})

	local arrow = mk("TextLabel", {
		Name = "Arrow",
		BackgroundTransparency = 1,
		AnchorPoint = Vector2.new(1, 0.5),
		Position = UDim2.new(1, -12, 0.5, 0),
		Size = UDim2.new(0, 18, 0, 18),
		Text = "v",
		TextColor3 = col.td,
		Font = Enum.Font.GothamBold,
		TextSize = 12,
		Parent = btn,
		ZIndex = z + 2,
	})

	local menu = mk("Frame", {
		Name = "LocalTrackMenu",
		BackgroundColor3 = Color3.fromRGB(37, 41, 52),
		BorderSizePixel = 0,
		Position = UDim2.new(0, 16, 0, y + 38),
		Size = UDim2.new(1, -32, 0, 0),
		Visible = false,
		Parent = par,
		ZIndex = z + 3,
	}, {
		mk("UICorner", {
			CornerRadius = UDim.new(0, 12),
		}),
		mk("UIStroke", {
			Color = Color3.fromRGB(71, 79, 97),
			Transparency = 0.22,
		}),
	})

	local menuList = mk("ScrollingFrame", {
		Name = "List",
		BackgroundTransparency = 1,
		BorderSizePixel = 0,
		CanvasSize = UDim2.new(0, 0, 0, 0),
		ElasticBehavior = Enum.ElasticBehavior.Never,
		ScrollBarThickness = 3,
		ScrollBarImageColor3 = col.st,
		ScrollingDirection = Enum.ScrollingDirection.Y,
		TopImage = "",
		MidImage = "",
		BottomImage = "",
		Size = UDim2.new(1, 0, 1, 0),
		Parent = menu,
		ZIndex = z + 4,
	}, {
		mk("UIPadding", {
			PaddingTop = UDim.new(0, 8),
			PaddingBottom = UDim.new(0, 8),
			PaddingLeft = UDim.new(0, 10),
			PaddingRight = UDim.new(0, 10),
		}),
		mk("UIListLayout", {
			Padding = UDim.new(0, 6),
			SortOrder = Enum.SortOrder.LayoutOrder,
		}),
	})

	local function setHover(on)
		hoverBg.BackgroundTransparency = on and 0 or 1
	end

	local function setMenuOpen(open)
		if state.open == open then
			return
		end
		state.open = open
		menu.Visible = open
		arrow.Text = open and "^" or "v"
		if TS then
			pcall(function()
				TS:Create(btn, TweenInfo.new(0.14, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {
					BackgroundColor3 = open and Color3.fromRGB(34, 38, 49) or col.bg,
				}):Play()
			end)
		else
			btn.BackgroundColor3 = open and Color3.fromRGB(34, 38, 49) or col.bg
		end
		if onToggle then
			onToggle(open, state.menuHeight)
		end
	end

	local function setValueText(text)
		value.Text = trim(text or "") ~= "" and tostring(text) or "Pick local audio from DeltaMusic"
	end

	local function rebuild()
		for _, child in menuList:GetChildren() do
			if not child:IsA("UIListLayout") and not child:IsA("UIPadding") then
				child:Destroy()
			end
		end
		local items = scanMusicFiles()
		if #items == 0 then
			mk("TextLabel", {
				Name = "Empty",
				BackgroundTransparency = 1,
				Size = UDim2.new(1, 0, 0, 28),
				Text = "No local audio files found",
				TextColor3 = col.td,
				Font = Enum.Font.Gotham,
				TextSize = 12,
				TextXAlignment = Enum.TextXAlignment.Left,
				Parent = menuList,
				ZIndex = z + 5,
			})
		else
			for i, item in items do
				local row = mk("TextButton", {
					Name = "Track_" .. i,
					BackgroundColor3 = Color3.fromRGB(43, 47, 58),
					BorderSizePixel = 0,
					Size = UDim2.new(1, 0, 0, 30),
					Text = item.name or "",
					TextColor3 = col.tx,
					Font = Enum.Font.GothamSemibold,
					TextSize = 12,
					TextTruncate = Enum.TextTruncate.AtEnd,
					TextXAlignment = Enum.TextXAlignment.Left,
					AutoButtonColor = false,
					Parent = menuList,
					ZIndex = z + 5,
				}, {
					mk("UIPadding", {
						PaddingLeft = UDim.new(0, 10),
						PaddingRight = UDim.new(0, 10),
					}),
					mk("UICorner", {
						CornerRadius = UDim.new(0, 8),
					}),
				})
				con(row.MouseEnter:Connect(function()
					row.BackgroundColor3 = Color3.fromRGB(51, 56, 68)
				end))
				con(row.MouseLeave:Connect(function()
					row.BackgroundColor3 = Color3.fromRGB(43, 47, 58)
				end))
				con(row.MouseButton1Click:Connect(function()
					setValueText(item.name)
					setMenuOpen(false)
					if onPick then
						onPick(item)
					end
				end))
			end
		end
		local count = math.max(#items, 1)
		local fullHeight = count * 30 + math.max(count - 1, 0) * 6 + 16
		local visibleHeight = math.min(fullHeight, 172)
		state.menuHeight = visibleHeight
		menu.Size = UDim2.new(1, -32, 0, visibleHeight)
		menuList.CanvasSize = UDim2.new(0, 0, 0, fullHeight)
		if state.open and onToggle then
			onToggle(true, state.menuHeight)
		end
	end

	con(btn.MouseButton1Click:Connect(function()
		if not state.open then
			rebuild()
		end
		setMenuOpen(not state.open)
	end))

	con(btn.MouseEnter:Connect(function()
		setHover(true)
	end))

	con(btn.MouseLeave:Connect(function()
		setHover(false)
	end))

	return {
		button = btn,
		menu = menu,
		rebuild = rebuild,
		close = function()
			setMenuOpen(false)
		end,
		setText = setValueText,
	}
end

local function findLocalMusicEntry(query)
	query = trim(query)
	if query == "" then
		return nil
	end
	local lower = query:lower()
	for _, item in scanMusicFiles() do
		local nm = (item.name or ""):lower()
		local base = nm:gsub("%.[^%.]+$", "")
		if lower == nm or lower == base then
			return item
		end
	end
	return nil
end

local httpGetBinary
local function downloadMusicAsset(url)
	if
		type(getcustomasset) ~= "function"
		or type(writefile) ~= "function"
		or type(isfile) ~= "function"
		or not ensureMusicFolder()
	then
		return nil, "Custom music requires file support and getcustomasset."
	end
	local norm = normalizeAudioUrl(url)
	local ext = getAudioExt(norm)
	if not norm or not ext then
		return nil, "Unsupported audio format. Use mp3, ogg, flac, or wav."
	end
	local full = MUSIC_CACHE_DIR .. "/" .. deriveAudioFileName(norm, ext)
	local okEx, ex = pcall(isfile, full)
	if not (okEx and ex) then
		local data = httpGetBinary(norm)
		if not (type(data) == "string" and data ~= "") then
			return nil, "Failed to download audio."
		end
		local okW = pcall(writefile, full, data)
		if not okW then
			return nil, "Failed to save audio."
		end
	end
	local asset = resolveMusicAsset(full)
	if not asset then
		return nil, "Failed to load audio asset."
	end
	return {
		asset = asset,
		name = full:match("([^/\\]+)$") or full,
		path = full,
	}, nil
end

ensureMusicFolder()
loadMusicCfg()

local function deriveImageFileName(url)
	local name = url:match("/([^/%?#]+)") or "image"
	name = name:match("([^?#]+)") or name
	local base = sanitizeFileName(name:match("(.+)%.") or name)
	return string.format("%s_%s.bin", base ~= "" and base or "image", hashString(url))
end

clearImageCache()

local function normalizeImageUrl(url, base)
	if type(url) ~= "string" or url == "" then
		return nil
	end
	local t = trim(url)
	if t == "" then
		return nil
	end
	if t:match("^rbxassetid://") or t:match("^rbxthumb://") then
		return nil
	end
	if t:match("^https?://") then
		return t
	end
	if t:sub(1, 2) == "//" then
		return "https:" .. t
	end
	if t:sub(1, 1) == "/" then
		return (base or "") .. t
	end
	return base and (base .. "/" .. t) or t
end

local function isMeaningfulImageUrl(url)
	if type(url) ~= "string" or url == "" then
		return false
	end
	return not url:lower():find("no%-script")
end

function httpGetBinary(url, headers)
	if type(url) ~= "string" or url == "" then
		return nil
	end
	local function tryRequest(hdr)
		if type(rq) ~= "function" then
			return nil
		end
		local h = {}
		if type(hdr) == "table" then
			for k, v in hdr do
				h[k] = v
			end
		end
		h["User-Agent"] = h["User-Agent"] or "Roblox/Http/1.1"
		h["Accept"] = h["Accept"] or "*/*"
		local ok, res = pcall(rq, {
			Url = url,
			Method = "GET",
			Headers = h,
		})
		if ok and res then
			local code = res.StatusCode or res.Status or res.status_code or 0
			local body = res.Body or res.body
			if (code == 0 or code >= 200 and code < 300) and type(body) == "string" and body ~= "" then
				return body
			end
		end
		return nil
	end
	local data = tryRequest(headers)
	if type(data) == "string" and data ~= "" then
		return data
	end
	local ok2, body2 = pcall(function()
		return game:HttpGet(url)
	end)
	if ok2 and type(body2) == "string" and body2 ~= "" then
		return body2
	end
	return tryRequest(nil)
end

local function downloadImageAsset(url)
	if type(url) ~= "string" or url == "" then
		return nil
	end
	if type(getcustomasset) ~= "function" or type(writefile) ~= "function" or type(isfile) ~= "function" then
		return nil
	end
	if not ensureImageFolder() then
		return nil
	end
	local full = IMAGE_CACHE_DIR .. "/" .. deriveImageFileName(url)
	local okEx, ex = pcall(isfile, full)
	if not (okEx and ex) then
		local host = url:match("^https?://([^/]+)") or ""
		local hdr
		if host:find("rscripts%.net") then
			hdr = { Referer = RSCRIPTS_BASE }
		elseif host:find("robloxscripts%.com") then
			hdr = { Referer = "https://robloxscripts.com" }
		elseif host:find("haxhell%.com") then
			hdr = { Referer = HAXHELL_BASE }
		elseif host:find("rbxcdn%.com") then
			hdr = { Referer = "https://www.roblox.com/" }
		end
		local data = httpGetBinary(url, hdr)
		if not (type(data) == "string" and data ~= "") then
			return nil
		end
		local okW = pcall(writefile, full, data)
		if not okW then
			return nil
		end
	end
	local okA, asset = pcall(getcustomasset, full)
	if okA and type(asset) == "string" and asset ~= "" then
		return asset
	end
	return nil
end

local function resolveScriptBloxImage(d)
	if not d then
		return nil
	end
	local function pick(vals)
		for _, v in vals do
			local n = normalizeImageUrl(v, SCRIPTBLOX_BASE)
			if n and isMeaningfulImageUrl(n) then
				return n
			end
		end
	end
	return pick({
		d.image,
		d.imageUrl,
		d.thumbnail,
		d.coverImage,
		d.icon,
		d.game and d.game.imageUrl,
		d.game and d.game.thumbnail,
		d.game and d.game.image,
		d.game and d.game.coverImage,
		d.game and d.game.icon,
	})
end

local function resolveRScriptsImage(d)
	if not d then
		return nil
	end
	local function pick(vals)
		for _, v in vals do
			local n = normalizeImageUrl(v, RSCRIPTS_BASE)
			if n then
				return n
			end
		end
	end
	return pick({
		d.image,
		d.imageUrl,
		d.thumbnail,
		d.cover,
		d.banner,
		d.img,
		d.game and d.game.imgurl,
		d.game and d.game.imageUrl,
		d.game and d.game.image,
		d.game and d.game.thumbnail,
		d.game and d.game.cover,
		d.game and d.game.banner,
		d.game and d.game.gameLogo,
	})
end

local function resolveRoScriptsImage(d)
	if not d then
		return nil
	end
	local url = normalizeImageUrl(d.image, ROSCRIPTS_BASE)
	if url and isMeaningfulImageUrl(url) then
		return url
	end
	local gameData = type(d.game) == "table" and d.game or nil
	url = normalizeImageUrl(gameData and gameData.image, ROSCRIPTS_BASE)
	if url and isMeaningfulImageUrl(url) then
		return url
	end
	return nil
end

local function resolveHaxHellImage(d)
	if not d then
		return nil
	end
	local media = type(d.media) == "table" and d.media or {}
	local gameData = type(d.game) == "table" and d.game or {}
	local function pick(vals)
		for _, v in vals do
			local n = normalizeImageUrl(v, HAXHELL_BASE)
			if n and isMeaningfulImageUrl(n) then
				return n
			end
		end
	end
	return pick({
		media.thumbnailUrl,
		d.image,
		d.imageUrl,
		d.thumbnail,
		gameData.thumbnailUrl,
		gameData.iconUrl,
		gameData.imageUrl,
		gameData.image,
	})
end

local function buildRobloxThumbnail(placeId)
	local id = tostring(placeId or "")
	if id == "" or id == "0" then
		return nil
	end
	return "https://www.roblox.com/Thumbs/PlaceThumbnail.ashx?width=420&height=270&format=png&placeId=" .. id
end

local function toast(a, b)
	if type(env.Notify) == "function" then
		pcall(env.Notify, {
			Title = a,
			Description = b,
			Duration = 4,
		})
		return
	end
	if type(env.nt) == "function" then
		pcall(env.nt, {
			Title = a,
			Description = b,
			Duration = 4,
		})
	end
end

local hub = sh:FindFirstChild("LT_ScriptHub")
if hub then
	hub:Destroy()
end

muteSh()

hub = mk("Frame", {
	Name = "LT_ScriptHub",
	BackgroundTransparency = 1,
	Size = UDim2.new(1, 0, 1, 0),
	Visible = true,
	ZIndex = 50,
	Parent = sh,
}, {
	mk("UIPadding", {
		PaddingTop = UDim.new(0, 12),
		PaddingBottom = UDim.new(0, 12),
		PaddingLeft = UDim.new(0, 12),
		PaddingRight = UDim.new(0, 12),
	}),
})

local top = mk("Frame", {
	Name = "Top",
	BackgroundColor3 = col.bg2,
	BorderSizePixel = 0,
	Size = UDim2.new(1, 0, 0, 42),
	Parent = hub,
	ZIndex = 51,
}, {
	mk("UICorner", {
		CornerRadius = UDim.new(0, 10),
	}),
	mk("UIStroke", {
		Color = col.st,
		Transparency = 0.35,
	}),
})

local engb = mk("TextButton", {
	Name = "Engine",
	BackgroundColor3 = Color3.fromRGB(45, 49, 58),
	BorderSizePixel = 0,
	Size = UDim2.new(0, 168, 1, 0),
	Text = "Engine: RScripts",
	TextColor3 = col.tx,
	Font = Enum.Font.GothamSemibold,
	TextSize = 13,
	Parent = top,
	ZIndex = 52,
}, {
	mk("UICorner", {
		CornerRadius = UDim.new(0, 8),
	}),
	mk("UIStroke", {
		Color = col.st,
		Transparency = 0.3,
	}),
})

local fltb = mk("TextButton", {
	Name = "Filter",
	BackgroundColor3 = col.bg,
	BorderSizePixel = 0,
	Size = UDim2.new(0, 88, 1, 0),
	Position = UDim2.new(1, -176, 0, 0),
	Text = "All",
	TextColor3 = col.tx,
	Font = Enum.Font.GothamSemibold,
	TextSize = 13,
	Parent = top,
	ZIndex = 52,
}, {
	mk("UICorner", {
		CornerRadius = UDim.new(0, 8),
	}),
	mk("UIStroke", {
		Color = col.st,
		Transparency = 0.3,
	}),
})

local gob = mk("TextButton", {
	Name = "Go",
	BackgroundColor3 = col.ac,
	BorderSizePixel = 0,
	Size = UDim2.new(0, 80, 1, 0),
	Position = UDim2.new(1, -80, 0, 0),
	Text = "Search",
	TextColor3 = col.tx,
	Font = Enum.Font.GothamBold,
	TextSize = 13,
	Parent = top,
	ZIndex = 52,
}, {
	mk("UICorner", {
		CornerRadius = UDim.new(0, 8),
	}),
})

local sbox = mk("TextBox", {
	Name = "Search",
	BackgroundColor3 = col.bg,
	BorderSizePixel = 0,
	Size = UDim2.new(1, -352, 1, 0),
	Position = UDim2.new(0, 176, 0, 0),
	ClearTextOnFocus = false,
	Text = "",
	PlaceholderText = "Search for scripts (rscripts.net)",
	TextColor3 = col.tx,
	PlaceholderColor3 = col.td,
	TextXAlignment = Enum.TextXAlignment.Left,
	Font = Enum.Font.Gotham,
	TextSize = 13,
	Parent = top,
	ZIndex = 52,
}, {
	mk("UIPadding", {
		PaddingLeft = UDim.new(0, 10),
		PaddingRight = UDim.new(0, 10),
	}),
	mk("UICorner", {
		CornerRadius = UDim.new(0, 8),
	}),
	mk("UIStroke", {
		Color = col.st,
		Transparency = 0.3,
	}),
})

local list = mk("ScrollingFrame", {
	Name = "List",
	BackgroundTransparency = 1,
	BorderSizePixel = 0,
	Size = UDim2.new(1, 0, 1, -92),
	Position = UDim2.new(0, 0, 0, 50),
	CanvasSize = UDim2.new(0, 0, 0, 0),
	AutomaticCanvasSize = Enum.AutomaticSize.Y,
	ScrollBarThickness = 4,
	Parent = hub,
	ZIndex = 51,
}, {
	mk("UIListLayout", {
		Padding = UDim.new(0, 10),
		SortOrder = Enum.SortOrder.LayoutOrder,
	}),
})

local bot = mk("Frame", {
	Name = "Bottom",
	BackgroundTransparency = 1,
	Size = UDim2.new(1, 0, 0, 32),
	Position = UDim2.new(0, 0, 1, -32),
	Parent = hub,
	ZIndex = 51,
})

local prev = mk("TextButton", {
	BackgroundColor3 = col.bg,
	BorderSizePixel = 0,
	Size = UDim2.new(0, 72, 1, 0),
	Text = "Prev",
	TextColor3 = col.tx,
	Font = Enum.Font.GothamSemibold,
	TextSize = 12,
	Parent = bot,
	ZIndex = 52,
}, {
	mk("UICorner", {
		CornerRadius = UDim.new(0, 8),
	}),
	mk("UIStroke", {
		Color = col.st,
		Transparency = 0.35,
	}),
})

local nextb = mk("TextButton", {
	BackgroundColor3 = col.bg,
	BorderSizePixel = 0,
	Size = UDim2.new(0, 72, 1, 0),
	Position = UDim2.new(1, -72, 0, 0),
	Text = "Next",
	TextColor3 = col.tx,
	Font = Enum.Font.GothamSemibold,
	TextSize = 12,
	Parent = bot,
	ZIndex = 52,
}, {
	mk("UICorner", {
		CornerRadius = UDim.new(0, 8),
	}),
	mk("UIStroke", {
		Color = col.st,
		Transparency = 0.35,
	}),
})

local pgt = mk("TextLabel", {
	BackgroundTransparency = 1,
	Size = UDim2.new(1, -160, 1, 0),
	Position = UDim2.new(0, 80, 0, 0),
	Text = "Page 1 / 1",
	TextColor3 = col.td,
	Font = Enum.Font.Gotham,
	TextSize = 12,
	Parent = bot,
	ZIndex = 52,
})

local eng = "RScripts"
local flt = "all"
local cur = 1
local maxp = 1
local q = ""
local tr = false
local busy = false
local data = {}

local function pass(d)
	local v
	if eng == "RScripts" then
		v = d.keySystem
	elseif eng == "HaxHell" then
		local flags = type(d.flags) == "table" and d.flags or {}
		v = flags.keySystem
	else
		v = d.key
	end
	if v == nil and type(d.accessType) == "string" then
		v = d.accessType:lower() == "key"
	end
	local k = false
	if type(v) == "boolean" then
		k = v
	elseif type(v) == "number" then
		k = v ~= 0
	elseif type(v) == "string" then
		local s = v:lower()
		if
			s ~= ""
			and s ~= "false"
			and s ~= "0"
			and s ~= "none"
			and s ~= "n/a"
			and not s:find("no key", 1, true)
			and not s:find("keyless", 1, true)
		then
			k = true
		end
	elseif v ~= nil and v ~= false then
		k = true
	end
	if flt == "all" then
		return true
	elseif flt == "keyless" then
		return not k
	else
		return k
	end
end

local function shClr()
	for _, c in list:GetChildren() do
		if c:IsA("GuiObject") then
			c:Destroy()
		end
	end
end

local function shMsg(t, c3)
	local lb = mk("TextLabel", {
		BackgroundTransparency = 1,
		Size = UDim2.new(1, 0, 0, 40),
		Text = t,
		TextColor3 = c3 or col.td,
		Font = Enum.Font.GothamSemibold,
		TextSize = 14,
		Parent = list,
	})
	return lb
end

local function mkb(par, tx, c3)
	return mk("TextButton", {
		BackgroundColor3 = c3,
		BorderSizePixel = 0,
		Size = UDim2.new(0, 88, 0, 28),
		Text = tx,
		TextColor3 = col.tx,
		Font = Enum.Font.GothamSemibold,
		TextSize = 12,
		Parent = par,
	}, {
		mk("UICorner", {
			CornerRadius = UDim.new(0, 7),
		}),
	})
end

local function getRw(d)
	if eng == "RScripts" then
		return d.rawScript or d.scriptLink or d.raw or "", true
	elseif eng == "RoScripts" then
		local url = d.loadstring or d.rawUrl or ""
		return url, type(url) == "string" and url:match("^https?://") ~= nil
	elseif eng == "RobloxScripts" then
		local source = d.script or ""
		if source ~= "" then
			return source, false
		end
		local url = d.rawScriptUrl or d.scriptLink or d.raw or ""
		return url, url ~= ""
	elseif eng == "HaxHell" then
		local links = type(d.links) == "table" and d.links or {}
		local sourceData = type(d.source) == "table" and d.source or {}
		local source = links.raw or sourceData.rawUrl or sourceData.code or d.rawScriptUrl or d.script or ""
		return source, type(source) == "string" and source:match("^https?://") ~= nil
	end
	return d.script or d.rawScript or d.scriptLink or d.raw or "", false
end

local function getTi(d)
	return d.title or d.name or "Untitled Script"
end

local function getGa(d)
	if eng == "RScripts" then
		return d.game and d.game.title or "Unknown Game"
	end
	return d.game and d.game.name or "Unknown Game"
end

local function keyReq(d)
	local v
	if eng == "RScripts" then
		v = d.keySystem
	elseif eng == "HaxHell" then
		local flags = type(d.flags) == "table" and d.flags or {}
		v = flags.keySystem
	else
		v = d.key
	end
	if v == nil and type(d.accessType) == "string" then
		v = d.accessType:lower() == "key"
	end
	local k = false
	if type(v) == "boolean" then
		k = v
	elseif type(v) == "number" then
		k = v ~= 0
	elseif type(v) == "string" then
		local s = v:lower()
		if
			s ~= ""
			and s ~= "false"
			and s ~= "0"
			and s ~= "none"
			and s ~= "n/a"
			and not s:find("no key", 1, true)
			and not s:find("keyless", 1, true)
		then
			k = true
		end
	elseif v ~= nil and v ~= false then
		k = true
	end
	return k
end

local function getInfo(d)
	local stats = type(d.stats) == "table" and d.stats or {}
	local flags = type(d.flags) == "table" and d.flags or {}
	local v = tostring(d.views or d.viewCount or stats.views or 0)
	local l = tostring(d.likes or d.likeCount or stats.likes or 0)
	local k = keyReq(d) and "Key" or "Keyless"
	if eng == "RoScripts" then
		if d.scriptType == "paid" then
			k = "Paid"
		end
	elseif eng == "RobloxScripts" and type(d.accessType) == "string" then
		local access = d.accessType:lower()
		if access == "paid" then
			k = "Paid"
		elseif access == "free" then
			k = "Free"
		end
	elseif eng == "HaxHell" and flags.isPaid == true then
		k = "Paid"
	end
	local s = eng == "RobloxScripts" and "Published" or (d.isPatched == true or d.patched == true or flags.patched == true) and "Patched" or "Working"
	local info = string.format("%s | Views %s | Likes %s | %s", k, v, l, s)
	if eng == "RScripts" and d.discord and d.discord ~= "" then
		info = info .. " | Discord"
	elseif eng == "RobloxScripts" and d.author and d.author.verified == true then
		info = info .. " | Verified"
	elseif eng == "RoScripts" then
		if d.verified == true or type(d.owner) == "table" and d.owner.verified == true then
			info = info .. " | Verified"
		end
		if d.universal == true then
			info = info .. " | Universal"
		end
	elseif eng == "HaxHell" then
		local verified = flags.verified == true or type(d.author) == "table" and d.author.isScripterVerified == true
		if verified then
			info = info .. " | Verified"
		end
		if flags.mobileSupported == true then
			info = info .. " | Mobile"
		end
	end
	return info
end

local function mkRow()
	return mk("Frame", {
		Name = "Row",
		BackgroundTransparency = 1,
		Size = UDim2.new(1, 0, 0, 124),
		Parent = list,
		ZIndex = 51,
	}, {
		mk("UIListLayout", {
			FillDirection = Enum.FillDirection.Horizontal,
			Padding = UDim.new(0, 10),
			SortOrder = Enum.SortOrder.LayoutOrder,
		}),
	})
end

local function mkCard(par, i, d)
	local rw, rwIsUrl = getRw(d)
	local placeId
	if eng == "ScriptBlox" then
		placeId = d.game and d.game.gameId
	elseif eng == "RScripts" then
		placeId = d.game and (d.game.placeId or d.game.gameLink and d.game.gameLink:match("/games/(%d+)"))
	elseif eng == "HaxHell" or eng == "RoScripts" then
		placeId = d.game and d.game.placeId or d.placeId
	end
	placeId = tonumber(placeId)

	local bgUrl
	if eng == "ScriptBlox" then
		bgUrl = resolveScriptBloxImage(d)
	elseif eng == "RScripts" then
		bgUrl = resolveRScriptsImage(d)
	elseif eng == "RoScripts" then
		bgUrl = resolveRoScriptsImage(d)
	elseif eng == "HaxHell" then
		bgUrl = resolveHaxHellImage(d)
	else
		local candidates = {
			d.image,
			d.imageUrl,
			d.thumbnail,
			d.game and d.game.iconUrl,
			d.game and d.game.image,
		}
		for _, value in candidates do
			local normalized = normalizeImageUrl(value, "https://robloxscripts.com")
			if normalized and isMeaningfulImageUrl(normalized) then
				bgUrl = normalized
				break
			end
		end
	end
	if not bgUrl and placeId then
		bgUrl = buildRobloxThumbnail(placeId)
	end
	local bgAsset = bgUrl and downloadImageAsset(bgUrl) or nil
	local bgImg = bgAsset or bgUrl

	local cd = mk("Frame", {
		Name = "Card" .. tostring(i),
		BackgroundColor3 = col.cd,
		BorderSizePixel = 0,
		Size = UDim2.new(0.333333343, -7, 1, 0),
		LayoutOrder = i,
		ClipsDescendants = true,
		Parent = par,
	}, {
		mk("UICorner", {
			CornerRadius = UDim.new(0, 10),
		}),
		mk("UIStroke", {
			Color = col.st,
			Transparency = 0.35,
		}),
	})

	if bgImg then
		mk("ImageLabel", {
			Name = "Cover",
			BackgroundColor3 = Color3.fromRGB(12, 14, 22),
			BackgroundTransparency = 0,
			BorderSizePixel = 0,
			Size = UDim2.new(1, 0, 1, 0),
			Image = bgImg,
			ImageTransparency = 0.1,
			ScaleType = Enum.ScaleType.Crop,
			Parent = cd,
			ZIndex = 0,
		}, {
			mk("UICorner", {
				CornerRadius = UDim.new(0, 10),
			}),
		})
		mk("Frame", {
			BackgroundColor3 = Color3.new(0, 0, 0),
			BackgroundTransparency = 0.35,
			BorderSizePixel = 0,
			Size = UDim2.new(1, 0, 1, 0),
			Parent = cd,
			ZIndex = 1,
		}, {
			mk("UICorner", {
				CornerRadius = UDim.new(0, 10),
			}),
			mk("UIGradient", {
				Rotation = 90,
				Transparency = NumberSequence.new({
					NumberSequenceKeypoint.new(0, 0.08),
					NumberSequenceKeypoint.new(1, 0.45),
				}),
			}),
		})
	end

	mk("TextLabel", {
		BackgroundTransparency = 1,
		Size = UDim2.new(1, -16, 0, 20),
		Position = UDim2.new(0, 8, 0, 8),
		TextXAlignment = Enum.TextXAlignment.Left,
		TextTruncate = Enum.TextTruncate.AtEnd,
		Font = Enum.Font.GothamBold,
		TextSize = 14,
		TextColor3 = col.tx,
		Text = getTi(d),
		Parent = cd,
		ZIndex = 2,
	})

	mk("TextLabel", {
		BackgroundTransparency = 1,
		Size = UDim2.new(1, -16, 0, 18),
		Position = UDim2.new(0, 8, 0, 30),
		TextXAlignment = Enum.TextXAlignment.Left,
		TextTruncate = Enum.TextTruncate.AtEnd,
		Font = Enum.Font.GothamSemibold,
		TextSize = 12,
		TextColor3 = col.ac,
		Text = getGa(d),
		Parent = cd,
		ZIndex = 2,
	})

	mk("TextLabel", {
		BackgroundTransparency = 1,
		Size = UDim2.new(1, -16, 0, 30),
		Position = UDim2.new(0, 8, 0, 50),
		TextWrapped = true,
		TextXAlignment = Enum.TextXAlignment.Left,
		TextYAlignment = Enum.TextYAlignment.Top,
		Font = Enum.Font.Gotham,
		TextSize = 11,
		TextColor3 = col.td,
		Text = getInfo(d),
		Parent = cd,
		ZIndex = 2,
	})

	local row = mk("Frame", {
		BackgroundTransparency = 1,
		Size = UDim2.new(1, -16, 0, 28),
		Position = UDim2.new(0, 8, 1, -36),
		Parent = cd,
		ZIndex = 2,
	}, {
		mk("UIListLayout", {
			FillDirection = Enum.FillDirection.Horizontal,
			Padding = UDim.new(0, 8),
		}),
	})

	local run = mkb(row, "Run", col.su)
	run.ZIndex = 3
	local cp = setclipboard and mkb(row, "Copy", Color3.fromRGB(57, 63, 75)) or nil
	if cp then
		cp.ZIndex = 3
	end
	local extra = eng == "RScripts" and d.discord or eng == "RoScripts" and (d.marketplaceUrl or d.discordUrl)
	local extraLabel = eng == "RoScripts" and d.marketplaceUrl and "Store" or "Discord"
	local dc = type(extra) == "string" and extra ~= "" and setclipboard
		and mkb(row, extraLabel, Color3.fromRGB(28, 116, 224)) or nil
	if dc then
		dc.ZIndex = 3
	end

	con(run.MouseButton1Click:Connect(function()
		local ok, er = pcall(function()
			local ld = __dcm_boot.getLoader()
			if type(ld) ~= "function" then
				error("loadstring unavailable")
			end
			local src = rw
			if rwIsUrl then
				local headers
				if eng == "RScripts" then
					headers = { Referer = RSCRIPTS_BASE }
				elseif eng == "RobloxScripts" then
					headers = { Referer = "https://robloxscripts.com" }
				elseif eng == "HaxHell" then
					headers = { Referer = HAXHELL_BASE }
				end
				local got, gotEr = httpTxt(rw, headers)
				if type(got) ~= "string" or got == "" then
					error(gotEr or "empty script source")
				end
				src = got
			end
			if type(src) ~= "string" or src == "" then
				error("script source must be a string, got " .. tostring(typeof and typeof(src) or type(src)))
			end
			local fn, cer = ld(src, "@ScriptHubEntry")
			if type(fn) ~= "function" then
				error(cer or "compile failed")
			end
			if type(__dcm_boot.hostSetfenv) == "function" then
				pcall(__dcm_boot.hostSetfenv, fn, __dcm_boot.runtimeEnv)
			end
			fn()
		end)
		if ok then
			toast("ScriptHub", "Executed script.")
		else
			toast("ScriptHub", tostring(er))
		end
	end))

	if cp then
		con(cp.MouseButton1Click:Connect(function()
			pcall(function()
				local src = rw
				if eng == "RoScripts" and type(d.loadstring) == "string" and d.loadstring ~= "" then
					src = "loadstring(game:HttpGet(" .. string.format("%q", d.loadstring) .. "))()"
				elseif rwIsUrl then
					local headers
					if eng == "RScripts" then
						headers = { Referer = RSCRIPTS_BASE }
					elseif eng == "RobloxScripts" then
						headers = { Referer = "https://robloxscripts.com" }
					elseif eng == "HaxHell" then
						headers = { Referer = HAXHELL_BASE }
					end
					src = httpTxt(rw, headers)
				end
				if type(src) == "string" and src ~= "" then
					setclipboard(src)
				end
			end)
			cp.Text = "Copied"
			task.delay(0.8, function()
				if cp and cp.Parent then
					cp.Text = "Copy"
				end
			end)
		end))
	end

	if dc then
		con(dc.MouseButton1Click:Connect(function()
			pcall(function()
				setclipboard(extra)
			end)
			dc.Text = "Copied"
			task.delay(0.8, function()
				if dc and dc.Parent then
					dc.Text = extraLabel
				end
			end)
		end))
	end
end

local function ren()
	shClr()
	pgt.Text = string.format("Page %d / %d", cur, maxp)
	if not data or #data == 0 then
		shMsg("No scripts found", col.wa)
		return
	end
	local n = 0
	local row
	local coln = 0
	for _, d in data do
		if pass(d) then
			if not row or coln >= 3 then
				row = mkRow()
				coln = 0
			end
			n += 1
			coln += 1
			mkCard(row, n, d)
		end
	end
	if n == 0 then
		if flt == "keyless" then
			shMsg("No keyless scripts found on this page", col.wa)
		elseif flt == "key" then
			shMsg("No key-required scripts found on this page", col.wa)
		else
			shMsg("No scripts found", col.wa)
		end
	end
end

local function setBusy(v)
	busy = v and true or false
	gob.Active = not busy
	prev.Active = not busy
	nextb.Active = not busy
	gob.Text = busy and "Loading" or "Search"
end

local function fetch(q2, tr2, p2)
	if busy then
		return
	end
	clearImageCache()
	q2 = trim(q2 or "")
	tr2 = eng == "ScriptBlox" and tr2 == true or false
	p2 = math.max(tonumber(p2) or 1, 1)
	q = q2
	tr = tr2
	cur = p2
	maxp = 1
	data = {}
	setBusy(true)
	shClr()
	shMsg("Loading...", col.td)
	local requestQuery = q2
	if eng == "RobloxScripts" and #requestQuery > 100 then
		requestQuery = requestQuery:sub(1, 100)
	elseif eng == "HaxHell" and requestQuery ~= "" and #requestQuery < 2 then
		shClr()
		shMsg("HaxHell search requires at least 2 characters", col.wa)
		setBusy(false)
		return
	end
	local enc = __lt.cm("HttpService", "UrlEncode", requestQuery)
	local u
	if eng == "RScripts" then
		u = string.format("https://rscripts.net/api/v2/scripts?page=%d&orderBy=date&sort=desc", p2)
		if requestQuery ~= "" then
			u = u .. "&q=" .. enc
		end
	elseif eng == "RoScripts" then
		if requestQuery == "" then
			u = string.format("https://api.roscripts.io/v1/scripts?page=%d&max=20&sortBy=updatedAt&order=desc", p2)
		else
			u = string.format("https://api.roscripts.io/v1/scripts/search?q=%s&page=%d&max=20", enc, p2)
		end
	elseif eng == "RobloxScripts" then
		p2 = math.min(p2, 200)
		cur = p2
		u = string.format("https://robloxscripts.com/api/v1/scripts?page=%d&limit=24&sort=newest", p2)
		if requestQuery ~= "" then
			u = u .. "&q=" .. enc
		end
	elseif eng == "HaxHell" then
		if requestQuery == "" then
			u = string.format("https://haxhell.com/api/v1/scripts?page=%d&limit=24&sort=latest", p2)
		else
			u = string.format("https://haxhell.com/api/v1/search/scripts?q=%s&page=%d&limit=24&sort=latest", enc, p2)
		end
	elseif tr2 then
		u = string.format("https://scriptblox.com/api/script/fetch?page=%d", p2)
	else
		u = string.format("https://scriptblox.com/api/script/search?q=%s&page=%d", enc, p2)
	end
	local dec, status = req(u)
	shClr()
	if status == 429 then
		shMsg("Rate limit reached. Try again shortly", col.wa)
		setBusy(false)
		return
	elseif status == 503 then
		shMsg("API temporarily unavailable", col.wa)
		setBusy(false)
		return
	elseif status ~= 0 and (status < 200 or status >= 300) then
		shMsg("Request failed (" .. tostring(status) .. ")", col.er)
		setBusy(false)
		return
	elseif not dec then
		shMsg("Request failed", col.er)
		setBusy(false)
		return
	end
	local arr
	if eng == "RScripts" then
		arr = dec.scripts
		maxp = math.max(dec.info and dec.info.maxPages or 1, 1)
	elseif eng == "RoScripts" then
		local result = dec.result or {}
		local meta = dec.meta or {}
		arr = type(result.scripts) == "table" and result.scripts or {}
		local pages = tonumber(result.totalPages or meta.totalPages)
		maxp = math.max(math.floor(pages or 1), 1)
		cur = tonumber(result.page or meta.page) or p2
	elseif eng == "RobloxScripts" then
		arr = dec.data
		local pg = dec.pagination or {}
		local total = tonumber(pg.total or pg.totalItems)
		local limit = tonumber(pg.limit or pg.perPage) or 24
		local pages = tonumber(pg.totalPages or pg.pages or pg.lastPage)
		if not pages and total then
			pages = math.ceil(total / math.max(limit, 1))
		end
		maxp = math.min(math.max(pages or 1, 1), 200)
		cur = tonumber(pg.page or pg.currentPage) or p2
	elseif eng == "HaxHell" then
		arr = dec.data
		local pg = dec.pagination or {}
		local total = tonumber(pg.total or pg.totalItems)
		local limit = tonumber(pg.limit or pg.perPage) or 24
		local pages = tonumber(pg.totalPages or pg.pages or pg.lastPage)
		if not pages and total then
			pages = math.ceil(total / math.max(limit, 1))
		end
		cur = tonumber(pg.page or pg.currentPage) or p2
		if not pages then
			pages = pg.hasMore == true and (cur + 1) or cur
		end
		maxp = math.max(math.floor(pages or 1), 1)
	else
		local r = dec.result or {}
		arr = r.scripts
		maxp = math.max(r.totalPages or 1, 1)
	end
	data = arr or {}
	if #data == 0 then
		shMsg("No scripts found", col.wa)
		pgt.Text = string.format("Page %d / %d", cur, maxp)
		setBusy(false)
		return
	end
	ren()
	setBusy(false)
end

con(engb.MouseButton1Click:Connect(function()
	if eng == "ScriptBlox" then
		eng = "RScripts"
		engb.BackgroundColor3 = Color3.fromRGB(45, 49, 58)
		sbox.PlaceholderText = "Search for scripts (rscripts.net)"
	elseif eng == "RScripts" then
		eng = "RoScripts"
		engb.BackgroundColor3 = Color3.fromRGB(45, 68, 62)
		sbox.PlaceholderText = "Search for scripts (roscripts.io)"
	elseif eng == "RoScripts" then
		eng = "RobloxScripts"
		engb.BackgroundColor3 = Color3.fromRGB(38, 52, 68)
		sbox.PlaceholderText = "Search for scripts (robloxscripts.com)"
	elseif eng == "RobloxScripts" then
		eng = "HaxHell"
		engb.BackgroundColor3 = Color3.fromRGB(58, 42, 74)
		sbox.PlaceholderText = "Search for scripts (haxhell.com)"
	else
		eng = "ScriptBlox"
		engb.BackgroundColor3 = col.bg
		sbox.PlaceholderText = "Search for scripts (scriptblox.com)"
	end
	engb.Text = "Engine: " .. eng
	toast("ScriptHub", "Switched to " .. eng)
	data = {}
	cur = 1
	maxp = 1
	pgt.Text = "Page 1 / 1"
	shClr()
	shMsg("Press Search to load scripts", col.td)
end))

con(fltb.MouseButton1Click:Connect(function()
	if flt == "all" then
		flt = "keyless"
		fltb.Text = "Keyless"
	elseif flt == "keyless" then
		flt = "key"
		fltb.Text = "Key"
	else
		flt = "all"
		fltb.Text = "All"
	end
	ren()
end))

con(gob.MouseButton1Click:Connect(function()
	local t = trim(sbox.Text)
	if t ~= "" then
		fetch(t, false, 1)
	else
		if eng == "ScriptBlox" then
			fetch("", true, 1)
		else
			fetch("", false, 1)
		end
	end
end))

con(sbox.FocusLost:Connect(function(ent)
	if ent then
		local t = trim(sbox.Text)
		if t ~= "" then
			fetch(t, false, 1)
		else
			if eng == "ScriptBlox" then
				fetch("", true, 1)
			else
				fetch("", false, 1)
			end
		end
	end
end))

con(prev.MouseButton1Click:Connect(function()
	if busy then
		return
	end
	if cur > 1 then
		fetch(q, tr, cur - 1)
	end
end))

con(nextb.MouseButton1Click:Connect(function()
	if busy then
		return
	end
	if cur < maxp then
		fetch(q, tr, cur + 1)
	end
end))

shClr()
shMsg("Press Search to load scripts", col.td)
con(sh.DescendantAdded:Connect(function(d)
	muteObj(d)
end))

local function buildMusicTab()
	musicState.frame = gui:FindFirstChild("Music")
	if musicState.frame then
		pcall(function()
			musicState.frame:Destroy()
		end)
	end

	local tpl = sh or hm or se or ex or co
	if tpl and tpl:IsA("GuiObject") then
		musicState.frame = tpl:Clone()
		musicState.frame.Name = "Music"
		musicState.frame.Visible = false
		musicState.frame.Parent = gui
		pcall(function()
			musicState.frame.AnchorPoint = Vector2.new(0.5, 0.5)
			musicState.frame.Position = musicState.closedPos
			musicState.frame.Size = sh.Size
			musicState.frame.ZIndex = sh.ZIndex
		end)
		for _, d in musicState.frame:QueryDescendants("Instance") do
			if d:IsA("LocalScript") then
				d:Destroy()
			elseif d:IsA("GuiObject") and d ~= musicState.frame then
				pcall(function()
					d.Visible = false
				end)
			end
		end
	else
		musicState.frame = mk("Frame", {
			Name = "Music",
			BackgroundTransparency = 1,
			AnchorPoint = Vector2.new(0.5, 0.5),
			Position = musicState.closedPos,
			Size = sh and sh.Size or UDim2.new(0.848344803, 0, 0.892481446, 0),
			Visible = false,
			Parent = gui,
			ZIndex = sh and sh.ZIndex or 100,
		})
	end

	st.pg.music = musicState.frame

	local mr = mk("ScrollingFrame", {
		Name = "LT_Music",
		AutomaticCanvasSize = Enum.AutomaticSize.None,
		BackgroundTransparency = 1,
		BorderSizePixel = 0,
		CanvasSize = UDim2.new(0, 0, 0, 590),
		ElasticBehavior = Enum.ElasticBehavior.Never,
		HorizontalScrollBarInset = Enum.ScrollBarInset.ScrollBar,
		ScrollingDirection = Enum.ScrollingDirection.Y,
		ScrollBarImageColor3 = col.st,
		ScrollBarThickness = 4,
		TopImage = "",
		MidImage = "",
		BottomImage = "",
		VerticalScrollBarInset = Enum.ScrollBarInset.ScrollBar,
		AnchorPoint = Vector2.new(0.5, 0.5),
		Position = UDim2.new(0.5, 0, 0.5, 0),
		Size = UDim2.new(0.94, 0, 0.88, 0),
		Visible = true,
		ZIndex = 50,
		Parent = musicState.frame,
	})

	local function mkPanel(name, pos, size, fill, stroke, z)
		return mk("Frame", {
			Name = name,
			BackgroundColor3 = fill or col.bg2,
			BorderSizePixel = 0,
			Position = pos,
			Size = size,
			Parent = mr,
			ZIndex = z or 51,
		}, {
			mk("UICorner", {
				CornerRadius = UDim.new(0, 12),
			}),
			mk("UIStroke", {
				Color = stroke or col.st,
				Transparency = 0.28,
			}),
		})
	end

	local function mkCtl(par, name, text, width, bg, strokeCol)
		return mk("TextButton", {
			Name = name,
			BackgroundColor3 = bg,
			BorderSizePixel = 0,
			Size = UDim2.new(0, width, 0, 34),
			Text = text,
			TextColor3 = col.tx,
			Font = Enum.Font.GothamBold,
			TextSize = 13,
			Parent = par,
			ZIndex = 54,
		}, {
			mk("UICorner", {
				CornerRadius = UDim.new(0, 9),
			}),
			mk("UIStroke", {
				Color = strokeCol or bg:Lerp(Color3.new(1, 1, 1), 0.12),
				Transparency = 0.45,
			}),
		})
	end

	local function mkSlider(parent, y, titleText, accent, defaultScale)
		local title = mk("TextLabel", {
			BackgroundTransparency = 1,
			Position = UDim2.new(0, 16, 0, y),
			Size = UDim2.new(1, -32, 0, 16),
			Text = titleText,
			TextColor3 = col.td,
			Font = Enum.Font.GothamSemibold,
			TextSize = 12,
			TextXAlignment = Enum.TextXAlignment.Left,
			Parent = parent,
			ZIndex = 54,
		})
		local bar = mk("Frame", {
			BackgroundColor3 = Color3.fromRGB(43, 47, 58),
			BorderSizePixel = 0,
			Position = UDim2.new(0, 16, 0, y + 24),
			Size = UDim2.new(1, -32, 0, 10),
			Parent = parent,
			ZIndex = 54,
		}, {
			mk("UICorner", {
				CornerRadius = UDim.new(0, 999),
			}),
		})
		local fill = mk("Frame", {
			BackgroundColor3 = accent,
			BorderSizePixel = 0,
			Size = UDim2.new(defaultScale or 0, 0, 1, 0),
			Parent = bar,
			ZIndex = 55,
		}, {
			mk("UICorner", {
				CornerRadius = UDim.new(0, 999),
			}),
		})
		local knob = mk("Frame", {
			BackgroundColor3 = Color3.fromRGB(245, 247, 250),
			BorderSizePixel = 0,
			AnchorPoint = Vector2.new(0.5, 0.5),
			Position = UDim2.new(defaultScale or 0, 0, 0.5, 0),
			Size = UDim2.new(0, 14, 0, 14),
			Parent = bar,
			ZIndex = 56,
		}, {
			mk("UICorner", {
				CornerRadius = UDim.new(1, 0),
			}),
			mk("UIStroke", {
				Color = accent,
				Transparency = 0.35,
			}),
		})
		return title, bar, fill, knob
	end

	local hero = mkPanel(
		"Hero",
		UDim2.new(0, 0, 0, 0),
		UDim2.new(1, 0, 0, 118),
		Color3.fromRGB(18, 22, 31),
		Color3.fromRGB(62, 72, 92),
		51
	)
	hero.ClipsDescendants = true
	local heroGrad = Instance.new("UIGradient")
	heroGrad.Color = ColorSequence.new({
		ColorSequenceKeypoint.new(0, Color3.fromRGB(15, 21, 31)),
		ColorSequenceKeypoint.new(0.52, Color3.fromRGB(23, 29, 44)),
		ColorSequenceKeypoint.new(1, Color3.fromRGB(10, 14, 21)),
	})
	heroGrad.Rotation = 12
	heroGrad.Parent = hero

	mk("Frame", {
		Name = "OrbA",
		AnchorPoint = Vector2.new(1, 0),
		Position = UDim2.new(1, -16, 0, -18),
		Size = UDim2.new(0, 96, 0, 96),
		BackgroundColor3 = Color3.fromRGB(79, 164, 242),
		BackgroundTransparency = 0.8,
		BorderSizePixel = 0,
		Parent = hero,
		ZIndex = 51,
	}, {
		mk("UICorner", { CornerRadius = UDim.new(1, 0) }),
	})

	mk("Frame", {
		Name = "OrbB",
		AnchorPoint = Vector2.new(0, 1),
		Position = UDim2.new(0, -10, 1, 18),
		Size = UDim2.new(0, 72, 0, 72),
		BackgroundColor3 = Color3.fromRGB(52, 211, 153),
		BackgroundTransparency = 0.86,
		BorderSizePixel = 0,
		Parent = hero,
		ZIndex = 51,
	}, {
		mk("UICorner", { CornerRadius = UDim.new(1, 0) }),
	})

	local heroTag = mk("TextLabel", {
		BackgroundColor3 = Color3.fromRGB(32, 45, 71),
		BorderSizePixel = 0,
		Position = UDim2.new(0, 16, 0, 14),
		Size = UDim2.new(0, 118, 0, 20),
		Text = "CUSTOM PLAYER",
		TextColor3 = Color3.fromRGB(223, 238, 255),
		Font = Enum.Font.GothamBold,
		TextSize = 10,
		Parent = hero,
		ZIndex = 53,
	}, {
		mk("UICorner", { CornerRadius = UDim.new(0, 999) }),
	})

	local mt = mk("TextLabel", {
		BackgroundTransparency = 1,
		Position = UDim2.new(0, 16, 0, 47),
		Size = UDim2.new(1, -146, 0, 28),
		Text = "Music Studio",
		TextColor3 = col.tx,
		Font = Enum.Font.GothamBold,
		TextSize = 24,
		TextXAlignment = Enum.TextXAlignment.Left,
		Parent = hero,
		ZIndex = 53,
	})

	local heroStatus = mk("TextLabel", {
		Name = "HeroStatus",
		AnchorPoint = Vector2.new(1, 0),
		Position = UDim2.new(1, -16, 0, 14),
		Size = UDim2.new(0, 108, 0, 24),
		BackgroundColor3 = Color3.fromRGB(28, 32, 42),
		BorderSizePixel = 0,
		Text = "IDLE",
		TextColor3 = Color3.fromRGB(199, 208, 221),
		Font = Enum.Font.GothamBold,
		TextSize = 11,
		Parent = hero,
		ZIndex = 53,
	}, {
		mk("UICorner", { CornerRadius = UDim.new(0, 999) }),
		mk("UIStroke", {
			Color = Color3.fromRGB(70, 75, 85),
			Transparency = 0.35,
		}),
	})

	local assetChip = mk("TextLabel", {
		Name = "AssetChip",
		AnchorPoint = Vector2.new(1, 0),
		Position = UDim2.new(1, -16, 0, 46),
		Size = UDim2.new(0, 126, 0, 20),
		BackgroundColor3 = Color3.fromRGB(22, 26, 35),
		BorderSizePixel = 0,
		Text = "No asset",
		TextColor3 = Color3.fromRGB(151, 160, 176),
		Font = Enum.Font.GothamSemibold,
		TextSize = 10,
		TextTruncate = Enum.TextTruncate.AtEnd,
		Parent = hero,
		ZIndex = 53,
	}, {
		mk("UICorner", { CornerRadius = UDim.new(0, 999) }),
	})

	local inputBaseY = 132
	local inputBaseHeight = 118
	local controlBaseY = 264
	local mixBaseY = 436
	local canvasBaseHeight = 590

	local inputCard =
		mkPanel("InputCard", UDim2.new(0, 0, 0, inputBaseY), UDim2.new(1, 0, 0, inputBaseHeight), col.bg2, col.st, 51)
	local inputTitle = mk("TextLabel", {
		BackgroundTransparency = 1,
		Position = UDim2.new(0, 16, 0, 10),
		Size = UDim2.new(1, -32, 0, 14),
		Text = "Load audio",
		TextColor3 = col.tx,
		Font = Enum.Font.GothamSemibold,
		TextSize = 13,
		TextXAlignment = Enum.TextXAlignment.Left,
		Parent = inputCard,
		ZIndex = 53,
	})

	local mb = mk("TextBox", {
		Name = "IdBox",
		BackgroundColor3 = col.bg,
		BorderSizePixel = 0,
		Size = UDim2.new(1, -156, 0, 40),
		Position = UDim2.new(0, 16, 0, 28),
		ClearTextOnFocus = false,
		Text = "",
		PlaceholderText = "Asset id or direct audio URL",
		TextColor3 = col.tx,
		PlaceholderColor3 = col.td,
		TextXAlignment = Enum.TextXAlignment.Left,
		Font = Enum.Font.Gotham,
		TextSize = 14,
		Parent = inputCard,
		ZIndex = 53,
	}, {
		mk("UIPadding", {
			PaddingLeft = UDim.new(0, 12),
			PaddingRight = UDim.new(0, 12),
		}),
		mk("UICorner", {
			CornerRadius = UDim.new(0, 10),
		}),
		mk("UIStroke", {
			Color = col.st,
			Transparency = 0.28,
		}),
	})

	local loadb = mkCtl(inputCard, "Load", "Load Track", 124, col.ac, Color3.fromRGB(116, 192, 255))
	loadb.Position = UDim2.new(1, -140, 0, 28)
	loadb.ZIndex = 53

	local controlCard =
		mkPanel("ControlCard", UDim2.new(0, 0, 0, controlBaseY), UDim2.new(1, 0, 0, 158), col.bg2, col.st, 51)
	local controlLabel = mk("TextLabel", {
		BackgroundTransparency = 1,
		Position = UDim2.new(0, 16, 0, 12),
		Size = UDim2.new(1, -156, 0, 14),
		Text = "Playback",
		TextColor3 = col.tx,
		Font = Enum.Font.GothamSemibold,
		TextSize = 13,
		TextXAlignment = Enum.TextXAlignment.Left,
		Parent = controlCard,
		ZIndex = 53,
	})
	local cycleb = mkCtl(
		controlCard,
		"Cycle",
		"Cycle Off",
		112,
		Color3.fromRGB(45, 50, 61),
		Color3.fromRGB(94, 105, 121)
	)
	cycleb.AnchorPoint = Vector2.new(1, 0)
	cycleb.Position = UDim2.new(1, -16, 0, 10)
	cycleb.ZIndex = 53

	local now = mk("TextLabel", {
		BackgroundTransparency = 1,
		Position = UDim2.new(0, 16, 0, 32),
		Size = UDim2.new(1, -152, 0, 24),
		Text = "No track loaded",
		TextColor3 = col.tx,
		Font = Enum.Font.GothamBold,
		TextSize = 16,
		TextTruncate = Enum.TextTruncate.AtEnd,
		TextXAlignment = Enum.TextXAlignment.Left,
		Parent = controlCard,
		ZIndex = 53,
	})

	local stat = mk("TextLabel", {
		BackgroundTransparency = 1,
		Position = UDim2.new(0, 16, 0, 56),
		Size = UDim2.new(1, -32, 0, 18),
		Text = "Stopped",
		TextColor3 = col.td,
		Font = Enum.Font.Gotham,
		TextSize = 12,
		TextXAlignment = Enum.TextXAlignment.Left,
		Parent = controlCard,
		ZIndex = 53,
	})

	local row = mk("Frame", {
		BackgroundTransparency = 1,
		Position = UDim2.new(0, 16, 0, 82),
		Size = UDim2.new(1, -32, 0, 34),
		Parent = controlCard,
		ZIndex = 53,
	}, {
		mk("UIListLayout", {
			FillDirection = Enum.FillDirection.Horizontal,
			Padding = UDim.new(0, 8),
			VerticalAlignment = Enum.VerticalAlignment.Center,
		}),
	})

	local playb = mkCtl(row, "Play", "Play", 74, col.su, Color3.fromRGB(103, 233, 186))
	local pauseSlot = mk("Frame", {
		Name = "PauseSlot",
		BackgroundTransparency = 1,
		Size = UDim2.new(0, 82, 0, 34),
		Parent = row,
		ZIndex = 53,
	})
	local pauseb = mkCtl(
		pauseSlot,
		"Pause",
		"Pause",
		82,
		Color3.fromRGB(57, 63, 75),
		Color3.fromRGB(105, 115, 133)
	)
	pauseb.Position = UDim2.new(0, 0, 0, 0)
	local resumeb = mkCtl(
		pauseSlot,
		"Resume",
		"Resume",
		82,
		Color3.fromRGB(42, 68, 88),
		Color3.fromRGB(96, 164, 216)
	)
	resumeb.Position = UDim2.new(0, 0, 0, 0)
	local stopb = mkCtl(row, "Stop", "Stop", 74, Color3.fromRGB(80, 40, 40), Color3.fromRGB(132, 74, 74))
	local loopb = mkCtl(row, "Loop", "Loop Off", 96, Color3.fromRGB(45, 50, 61), Color3.fromRGB(94, 105, 121))
	resumeb.Visible = false

	local progressInfo = mk("TextLabel", {
		BackgroundTransparency = 1,
		Position = UDim2.new(0, 16, 0, 124),
		Size = UDim2.new(1, -32, 0, 14),
		Text = "00:00 / 00:00",
		TextColor3 = Color3.fromRGB(142, 151, 166),
		Font = Enum.Font.GothamSemibold,
		TextSize = 11,
		TextXAlignment = Enum.TextXAlignment.Left,
		Parent = controlCard,
		ZIndex = 53,
	})

	local pbar = mk("Frame", {
		BackgroundColor3 = Color3.fromRGB(41, 45, 56),
		BorderSizePixel = 0,
		Position = UDim2.new(0, 16, 0, 142),
		Size = UDim2.new(1, -32, 0, 8),
		Parent = controlCard,
		ZIndex = 54,
	}, {
		mk("UICorner", { CornerRadius = UDim.new(0, 999) }),
	})

	local pfill = mk("Frame", {
		BackgroundColor3 = Color3.fromRGB(79, 164, 242),
		BorderSizePixel = 0,
		Size = UDim2.new(0, 0, 1, 0),
		Parent = pbar,
		ZIndex = 55,
	}, {
		mk("UICorner", { CornerRadius = UDim.new(0, 999) }),
	})

	local pkn = mk("Frame", {
		BackgroundColor3 = Color3.fromRGB(255, 255, 255),
		BorderSizePixel = 0,
		AnchorPoint = Vector2.new(0.5, 0.5),
		Position = UDim2.new(0, 0, 0.5, 0),
		Size = UDim2.new(0, 12, 0, 12),
		Parent = pbar,
		ZIndex = 56,
	}, {
		mk("UICorner", { CornerRadius = UDim.new(1, 0) }),
		mk("UIStroke", {
			Color = Color3.fromRGB(79, 164, 242),
			Transparency = 0.35,
		}),
	})

	local mixCard = mkPanel("MixCard", UDim2.new(0, 0, 0, mixBaseY), UDim2.new(1, 0, 0, 138), col.bg2, col.st, 51)
	local mixTitle = mk("TextLabel", {
		BackgroundTransparency = 1,
		Position = UDim2.new(0, 16, 0, 12),
		Size = UDim2.new(1, -32, 0, 14),
		Text = "Mixer",
		TextColor3 = col.tx,
		Font = Enum.Font.GothamSemibold,
		TextSize = 13,
		TextXAlignment = Enum.TextXAlignment.Left,
		Parent = mixCard,
		ZIndex = 53,
	})

	local vt, vbar, vfill, vkn = mkSlider(mixCard, 34, "Volume", col.ac, 0.5)
	local spLabel, sbar, sfill, skn = mkSlider(mixCard, 84, "Playback speed", Color3.fromRGB(52, 211, 153), 0.333333)

	local helper = mk("TextLabel", {
		BackgroundTransparency = 1,
		Position = UDim2.new(0, 16, 1, -18),
		Size = UDim2.new(1, -32, 0, 14),
		Text = "Seek tracks with the progress bar. Volume and speed apply live.",
		TextColor3 = Color3.fromRGB(124, 132, 145),
		Font = Enum.Font.Gotham,
		TextSize = 11,
		TextXAlignment = Enum.TextXAlignment.Left,
		Parent = mixCard,
		ZIndex = 53,
	})

	local localPicker
	local function relayoutMusic(extra)
		extra = math.max(0, tonumber(extra) or 0)
		inputCard.Size = UDim2.new(1, 0, 0, inputBaseHeight + extra)
		controlCard.Position = UDim2.new(0, 0, 0, controlBaseY + extra)
		mixCard.Position = UDim2.new(0, 0, 0, mixBaseY + extra)
		mr.CanvasSize = UDim2.new(0, 0, 0, canvasBaseHeight + extra)
	end

	local function syncLocalPicker(raw)
		if not localPicker then
			return
		end
		local entry = raw and findLocalMusicEntry(raw) or nil
		if entry and entry.name then
			localPicker.setText(entry.name)
		else
			localPicker.setText("")
		end
	end

	local savedVol = tonumber(musicCfg.volume)
	if savedVol and savedVol >= 0 and savedVol <= 1 then
		savedVol *= 10
	end
	local vl = math.clamp(savedVol or 1, 0, 10)
	local spd = math.clamp(tonumber(musicCfg.playbackSpeed) or 1, 0.5, 2)
	local mixSaveStamp = 0
	local mixReady = false
	local function queueMixSave()
		if not mixReady then
			return
		end
		mixSaveStamp += 1
		local cur = mixSaveStamp
		task.delay(0.15, function()
			if cur ~= mixSaveStamp then
				return
			end
			musicCfg.volume = vl
			musicCfg.playbackSpeed = spd
			saveMusicCfg()
		end)
	end
	local function formatTime(sec)
		sec = tonumber(sec) or 0
		if sec < 0 or sec ~= sec or sec == math.huge then
			sec = 0
		end
		local total = math.floor(sec + 0.5)
		local m = math.floor(total / 60)
		local s = total % 60
		return string.format("%02d:%02d", m, s)
	end

	local function setStatusText(text, accent)
		stat.Text = text
		heroStatus.Text = string.upper(text)
		if accent then
			heroStatus.BackgroundColor3 = accent
			heroStatus.TextColor3 = Color3.fromRGB(245, 247, 250)
		else
			heroStatus.BackgroundColor3 = Color3.fromRGB(28, 32, 42)
			heroStatus.TextColor3 = Color3.fromRGB(199, 208, 221)
		end
	end

	local function setProgress(alpha, pos, len)
		alpha = math.clamp(alpha or 0, 0, 1)
		pfill.Size = UDim2.new(alpha, 0, 1, 0)
		pkn.Position = UDim2.new(alpha, 0, 0.5, 0)
		progressInfo.Text = string.format("%s / %s", formatTime(pos or 0), formatTime(len or 0))
	end

	local function syncLoopButton()
		local on = st.snd and st.snd.Looped
		loopb.Text = on and "Loop On" or "Loop Off"
		loopb.BackgroundColor3 = on and Color3.fromRGB(45, 93, 73) or Color3.fromRGB(45, 50, 61)
	end
	local function syncPauseButtons()
		local paused = st.musicPaused and st.snd ~= nil
		pauseb.Visible = not paused
		resumeb.Visible = paused
	end
	local function syncCycleButton()
		local mode = st.musicCycleMode
		if mode == "order" then
			cycleb.Text = "Cycle Order"
			cycleb.BackgroundColor3 = Color3.fromRGB(45, 93, 73)
		elseif mode == "random" then
			cycleb.Text = "Cycle Random"
			cycleb.BackgroundColor3 = Color3.fromRGB(52, 74, 112)
		else
			cycleb.Text = "Cycle Off"
			cycleb.BackgroundColor3 = Color3.fromRGB(45, 50, 61)
		end
	end
	local function getNextCycleTrack()
		local mode = st.musicCycleMode
		if mode ~= "order" and mode ~= "random" then
			return nil
		end
		local items = scanMusicFiles()
		if #items == 0 then
			return nil
		end
		local currentRaw = trim(st.musicRaw or "")
		if currentRaw == "" then
			return nil
		end
		local currentLower = currentRaw:lower()
		local currentIndex
		for i, item in items do
			local nm = (item.name or ""):lower()
			local base = nm:gsub("%.[^%.]+$", "")
			if currentLower == nm or currentLower == base then
				currentIndex = i
				break
			end
		end
		if not currentIndex then
			return nil
		end
		if mode == "random" then
			if #items == 1 then
				return items[1]
			end
			local idx = currentIndex
			for _ = 1, 8 do
				idx = math.random(1, #items)
				if idx ~= currentIndex then
					break
				end
			end
			if idx == currentIndex then
				idx = (currentIndex % #items) + 1
			end
			return items[idx]
		end
		return items[(currentIndex % #items) + 1]
	end

	local function apVol(v)
		vl = math.clamp(v, 0, 10)
		local alpha = vl / 10
		vfill.Size = UDim2.new(alpha, 0, 1, 0)
		vkn.Position = UDim2.new(alpha, 0, 0.5, 0)
		vt.Text = string.format("Volume  %.2f", vl)
		if st.snd then
			st.snd.Volume = vl
		end
		queueMixSave()
	end

	local function apSpeed(v)
		spd = math.clamp(v, 0.5, 2)
		local alpha = (spd - 0.5) / 1.5
		sfill.Size = UDim2.new(alpha, 0, 1, 0)
		skn.Position = UDim2.new(alpha, 0, 0.5, 0)
		spLabel.Text = string.format("Playback speed  %.2fx", spd)
		if st.snd then
			st.snd.PlaybackSpeed = spd
		end
		queueMixSave()
	end

	apVol(vl)
	apSpeed(spd)
	st.musicPaused = false
	st.musicCycleMode = st.musicCycleMode or "off"
	mixReady = true
	setStatusText("Stopped")
	setProgress(0, 0, 0)
	relayoutMusic(0)
	syncPauseButtons()
	syncCycleButton()

	local dragging = false
	local speedDragging = false
	local progressDragging = false

	local function setBar(inp)
		local x = (inp.Position.X - vbar.AbsolutePosition.X) / math.max(vbar.AbsoluteSize.X, 1)
		apVol(math.clamp(x, 0, 1) * 10)
	end

	local function setSpeedBar(inp)
		local x = (inp.Position.X - sbar.AbsolutePosition.X) / math.max(sbar.AbsoluteSize.X, 1)
		apSpeed(0.5 + math.clamp(x, 0, 1) * 1.5)
	end

	local function setProgressBar(inp)
		if not (st.snd and st.snd.TimeLength and st.snd.TimeLength > 0) then
			return
		end
		local x = (inp.Position.X - pbar.AbsolutePosition.X) / math.max(pbar.AbsoluteSize.X, 1)
		x = math.clamp(x, 0, 1)
		local len = st.snd.TimeLength
		local pos = len * x
		pcall(function()
			st.snd.TimePosition = pos
		end)
		setProgress(x, pos, len)
	end

	con(vbar.InputBegan:Connect(function(inp)
		if inp.UserInputType == Enum.UserInputType.MouseButton1 or inp.UserInputType == Enum.UserInputType.Touch then
			dragging = true
			setBar(inp)
		end
	end))

	con(sbar.InputBegan:Connect(function(inp)
		if inp.UserInputType == Enum.UserInputType.MouseButton1 or inp.UserInputType == Enum.UserInputType.Touch then
			speedDragging = true
			setSpeedBar(inp)
		end
	end))

	con(pbar.InputBegan:Connect(function(inp)
		if inp.UserInputType == Enum.UserInputType.MouseButton1 or inp.UserInputType == Enum.UserInputType.Touch then
			progressDragging = true
			setProgressBar(inp)
		end
	end))

	con(UIS.InputChanged:Connect(function(inp)
		if
			dragging
			and (inp.UserInputType == Enum.UserInputType.MouseMovement or inp.UserInputType == Enum.UserInputType.Touch)
		then
			setBar(inp)
		end
		if
			speedDragging
			and (inp.UserInputType == Enum.UserInputType.MouseMovement or inp.UserInputType == Enum.UserInputType.Touch)
		then
			setSpeedBar(inp)
		end
		if
			progressDragging
			and (inp.UserInputType == Enum.UserInputType.MouseMovement or inp.UserInputType == Enum.UserInputType.Touch)
		then
			setProgressBar(inp)
		end
	end))

	con(UIS.InputEnded:Connect(function(inp)
		if inp.UserInputType == Enum.UserInputType.MouseButton1 or inp.UserInputType == Enum.UserInputType.Touch then
			dragging = false
			speedDragging = false
			progressDragging = false
		end
	end))

	if RS then
		con(RS.Heartbeat:Connect(function()
			local snd = st.snd
			if not snd then
				return
			end
			local len = snd.TimeLength or 0
			local pos = snd.TimePosition or 0
			local alpha = 0
			if len > 0 then
				alpha = math.clamp(pos / len, 0, 1)
			end
			if not progressDragging then
				setProgress(alpha, pos, len)
			end
		end))
	end

	local function getId(t)
		t = trim(t)
		if t == "" then
			return nil
		end
		local n = t:match("^rbxassetid://(%d+)$") or t:match("id=(%d+)") or t:match("^(%d+)$")
		if n then
			return "rbxassetid://" .. n, n
		end
		return nil
	end

	local function mkSnd(id, raw)
		if st.snd then
			pcall(function()
				st.snd:Destroy()
			end)
		end
		local s = Instance.new("Sound")
		s.Name = "LT_MusicSound"
		s.SoundId = id
		s.Volume = vl
		s.Looped = false
		s.PlaybackSpeed = spd
		s.Parent = gui
		local function clearSoundGroup()
			if not (s and s.Parent) then
				return
			end
			pcall(function()
				if s.SoundGroup ~= nil then
					s.SoundGroup = nil
				end
			end)
		end
		clearSoundGroup()
		st.snd = s
		st.musicPaused = false
		st.musicRaw = tostring(raw)
		now.Text = tostring(raw)
		assetChip.Text = tostring(raw)
		setStatusText("Loaded", Color3.fromRGB(53, 83, 125))
		setProgress(0, 0, 0)
		syncLoopButton()
		syncPauseButtons()
		con(s.Loaded:Connect(function()
			if st.snd ~= s then
				return
			end
			st.musicPaused = false
			setStatusText("Loaded", Color3.fromRGB(53, 83, 125))
			setProgress(0, s.TimePosition or 0, s.TimeLength or 0)
			syncPauseButtons()
		end))
		con(s.Ended:Connect(function()
			if st.snd ~= s then
				return
			end
			st.musicPaused = false
			setStatusText("Ended", Color3.fromRGB(88, 64, 48))
			syncPauseButtons()
			local nextTrack = getNextCycleTrack()
			if nextTrack and nextTrack.asset then
				task.defer(function()
					if st.snd ~= s then
						return
					end
					mb.Text = nextTrack.name or ""
					mkSnd(nextTrack.asset, nextTrack.name)
					syncLocalPicker(nextTrack.name)
					if st.snd then
						pcall(function()
							st.snd:Play()
						end)
					end
				end)
			end
		end))
		con(s.Played:Connect(function()
			if st.snd ~= s then
				return
			end
			st.musicPaused = false
			setStatusText("Playing", Color3.fromRGB(52, 211, 153))
			syncPauseButtons()
		end))
		con(s.Paused:Connect(function()
			if st.snd ~= s then
				return
			end
			st.musicPaused = true
			setStatusText("Paused", Color3.fromRGB(92, 105, 123))
			syncPauseButtons()
		end))
		con(s.Stopped:Connect(function()
			if st.snd ~= s then
				return
			end
			st.musicPaused = false
			setStatusText("Stopped")
			setProgress(0, 0, s.TimeLength or 0)
			syncPauseButtons()
		end))
		con(s:GetPropertyChangedSignal("SoundGroup"):Connect(function()
			task.defer(clearSoundGroup)
		end))
	end

	local function resolveTrackInput(text)
		local q = trim(text)
		if q == "" then
			return nil, nil, "Enter a valid asset id, filename, or audio URL."
		end
		local localEntry = findLocalMusicEntry(q)
		if localEntry and localEntry.asset then
			return localEntry.asset, localEntry.name
		end
		local sid, raw = getId(q)
		if sid then
			return sid, raw
		end
		if q:match("^https?://") or q:match("^www%.") then
			local entry, err = downloadMusicAsset(q:match("^www%.") and ("https://" .. q) or q)
			if not entry then
				return nil, nil, err or "Failed to download audio."
			end
			return entry.asset, entry.name
		end
		if getAudioExt(q) then
			return nil, nil, "Local track not found in DeltaCustom/DeltaMusic."
		end
		return nil, nil, "Enter a valid asset id, filename, or audio URL."
	end

	local loadCurrentTrack
	localPicker = makeMusicFolderDropdown(inputCard, 74, 53, function(item)
		mb.Text = item.name or ""
		task.defer(function()
			if loadCurrentTrack then
				loadCurrentTrack()
			end
		end)
	end, function(open, menuHeight)
		relayoutMusic(open and (menuHeight + 10) or 0)
	end)

	function loadCurrentTrack()
		if localPicker then
			localPicker.close()
		end
		local sid, raw, err = resolveTrackInput(mb.Text)
		if not sid then
			toast("Music", err or "Enter a valid track.")
			return false
		end
		mkSnd(sid, raw)
		syncLocalPicker(raw)
		toast("Music", "Loaded audio.")
		return true
	end

	con(loadb.MouseButton1Click:Connect(loadCurrentTrack))

	con(mb.FocusLost:Connect(function(enter)
		if enter then
			loadCurrentTrack()
		end
	end))

	con(playb.MouseButton1Click:Connect(function()
		if st.snd then
			st.musicPaused = false
			syncPauseButtons()
			pcall(function()
				st.snd:Play()
			end)
		end
	end))

	con(pauseb.MouseButton1Click:Connect(function()
		if st.snd then
			st.musicPaused = true
			syncPauseButtons()
			pcall(function()
				st.snd:Pause()
			end)
		end
	end))

	con(resumeb.MouseButton1Click:Connect(function()
		if st.snd then
			st.musicPaused = false
			syncPauseButtons()
			local ok = pcall(function()
				st.snd:Resume()
			end)
			if not ok then
				pcall(function()
					st.snd:Play()
				end)
			end
		end
	end))

	con(stopb.MouseButton1Click:Connect(function()
		if st.snd then
			st.musicPaused = false
			syncPauseButtons()
			pcall(function()
				st.snd:Stop()
			end)
		end
	end))

	con(loopb.MouseButton1Click:Connect(function()
		if not st.snd then
			return
		end
		st.snd.Looped = not st.snd.Looped
		syncLoopButton()
	end))
	con(cycleb.MouseButton1Click:Connect(function()
		local mode = st.musicCycleMode
		if mode == "off" then
			st.musicCycleMode = "order"
		elseif mode == "order" then
			st.musicCycleMode = "random"
		else
			st.musicCycleMode = "off"
		end
		syncCycleButton()
	end))
end

buildMusicTab()

musicState.setupSidebar = function()
	musicState.icon.sheetAsset = downloadImageAsset(musicState.icon.sheetUrl)

	musicState.button = gbtn("Music")
	if musicState.button then
		pcall(function()
			musicState.button:Destroy()
		end)
	end

	musicState.sourceButton = sidebarRefs.console
		or sidebarRefs.scripthub
		or sidebarRefs.home
		or sidebarRefs.settings
		or sidebarRefs.executor
	if musicState.sourceButton then
		musicState.button = musicState.sourceButton:Clone()
		musicState.button.Name = "Music"
		musicState.button.Parent = musicState.sourceButton.Parent
		st.pg.musicButton = musicState.button
		musicState.textLabel = txtOf(musicState.button)
		if musicState.textLabel then
			musicState.textLabel.Text = "Music"
		end
		pcall(function()
			if sidebarRefs.toggle and sidebarRefs.toggle:IsA("GuiButton") then
				local to = sidebarRefs.toggle.LayoutOrder or 999
				for _, d in sb:GetChildren() do
					if d:IsA("GuiButton") and d ~= musicState.button and d.LayoutOrder and d.LayoutOrder >= to then
						d.LayoutOrder += 1
					end
				end
				musicState.button.LayoutOrder = to
			else
				local lo = 0
				for _, d in sb:GetChildren() do
					if d:IsA("GuiButton") and d ~= musicState.button then
						lo = math.max(lo, d.LayoutOrder or 0)
					end
				end
				musicState.button.LayoutOrder = lo + 1
			end
		end)
		musicState.imageLabel = imgOf(musicState.button)
		if musicState.imageLabel then
			pcall(function()
				if musicState.icon.sheetAsset then
					musicState.imageLabel.Image = musicState.icon.sheetAsset
					musicState.imageLabel.ImageRectOffset = musicState.icon.rectOffset
					musicState.imageLabel.ImageRectSize = musicState.icon.rectSize
					musicState.imageLabel.ScaleType = Enum.ScaleType.Fit
				end
				musicState.imageLabel.ImageColor3 = offImg
			end)
		end
		pcall(function()
			musicState.button.BackgroundColor3 = bgOff()
		end)
	end

	musicState.placeButton = function()
		if not (musicState.button and sidebarRefs.toggle and musicState.button.Parent == sidebarRefs.toggle.Parent) then
			return
		end
		pcall(function()
			if sidebarRefs.toggle:GetAttribute("LT_OrigPosXS") == nil then
				sidebarRefs.toggle:SetAttribute("LT_OrigPosXS", sidebarRefs.toggle.Position.X.Scale)
				sidebarRefs.toggle:SetAttribute("LT_OrigPosXO", sidebarRefs.toggle.Position.X.Offset)
				sidebarRefs.toggle:SetAttribute("LT_OrigPosYS", sidebarRefs.toggle.Position.Y.Scale)
				sidebarRefs.toggle:SetAttribute("LT_OrigPosYO", sidebarRefs.toggle.Position.Y.Offset)
				sidebarRefs.toggle:SetAttribute("LT_OrigLay", sidebarRefs.toggle.LayoutOrder or 0)
			end
			local op = UDim2.new(
				sidebarRefs.toggle:GetAttribute("LT_OrigPosXS") or sidebarRefs.toggle.Position.X.Scale,
				sidebarRefs.toggle:GetAttribute("LT_OrigPosXO") or sidebarRefs.toggle.Position.X.Offset,
				sidebarRefs.toggle:GetAttribute("LT_OrigPosYS") or sidebarRefs.toggle.Position.Y.Scale,
				sidebarRefs.toggle:GetAttribute("LT_OrigPosYO") or sidebarRefs.toggle.Position.Y.Offset
			)
			sidebarRefs.toggle.Position = op
			local togLo = sidebarRefs.toggle:GetAttribute("LT_OrigLay") or sidebarRefs.toggle.LayoutOrder or 0
			sidebarRefs.toggle.LayoutOrder = togLo
			local above
			local ay = -math.huge
			local ty = op.Y.Scale + op.Y.Offset / 100000
			for _, d in sidebarRefs.toggle.Parent:GetChildren() do
				if d:IsA("GuiButton") and d ~= sidebarRefs.toggle and d ~= musicState.button then
					local py = d.Position.Y.Scale + d.Position.Y.Offset / 100000
					if py < ty and py > ay then
						ay = py
						above = d
					end
				end
			end
			local gapS = 0.11
			local gapO = 0
			if above then
				gapS = op.Y.Scale - above.Position.Y.Scale
				gapO = op.Y.Offset - above.Position.Y.Offset
			end
			musicState.button.Position = op
			musicState.button.LayoutOrder = togLo - 1
			sidebarRefs.toggle.Position = UDim2.new(op.X.Scale, op.X.Offset, op.Y.Scale + gapS, op.Y.Offset + gapO)
			sidebarRefs.toggle.LayoutOrder = togLo + 1
		end)
	end

	musicState.placeButton()

	musicState.bindHide = function(b, nm)
		improveSidebarTouch(b)
		if b and b:IsA("GuiButton") then
			con(b.MouseButton1Click:Connect(function()
				closeMusic(true)
				task.defer(function()
					syncTabColors(nm or b.Name)
				end)
			end))
		end
	end

	musicState.bindHide(sidebarRefs.home, "Home")
	musicState.bindHide(sidebarRefs.scripthub, "Scripthub")
	musicState.bindHide(sidebarRefs.settings, "Settings")
	musicState.bindHide(sidebarRefs.executor, "Executor")
	musicState.bindHide(sidebarRefs.console, "Console")

	improveSidebarTouch(musicState.button)
	if musicState.button and musicState.button:IsA("GuiButton") then
		con(musicState.button.MouseButton1Click:Connect(function()
			openMusic()
			task.defer(function()
				syncTabColors("Music")
			end)
		end))
	end

	for _, n in sec do
		local p = gui:FindFirstChild(n)
		if p and p:IsA("GuiObject") and p.GetPropertyChangedSignal then
			con(p:GetPropertyChangedSignal("Visible"):Connect(function()
				task.defer(syncTabColors)
			end))
		end
	end

	if sidebarRefs.activeColor and sidebarRefs.activeColor.Changed then
		con(sidebarRefs.activeColor.Changed:Connect(function()
			task.defer(syncTabColors)
		end))
	end

	if sidebarRefs.inactiveColor and sidebarRefs.inactiveColor.Changed then
		con(sidebarRefs.inactiveColor.Changed:Connect(function()
			task.defer(syncTabColors)
		end))
	end

	task.defer(syncTabColors)
end

musicState.setupSidebar()
end

st.fn.setupHubMusic();
end

do
	local previousThemeRuntime = rawget(__dcm_env, "__DeltaThemeRuntime")
	if type(previousThemeRuntime) == "table" and type(previousThemeRuntime.stop) == "function" then
		pcall(previousThemeRuntime.stop)
	end
	if (identifyexecutor and identifyexecutor() or ""):lower() == "delta" then
		task.defer(function()
			local themeRuntime = {
				alive = true,
				connections = {},
				baseBackground = setmetatable({}, { __mode = "k" }),
				baseText = setmetatable({}, { __mode = "k" }),
				baseStroke = setmetatable({}, { __mode = "k" }),
				baseImage = setmetatable({}, { __mode = "k" }),
			}
			__dcm_env.__DeltaThemeRuntime = themeRuntime
			local function connectTheme(signal, callback)
				if not signal then
					return
				end
				local ok, connection = pcall(function()
					return signal:Connect(callback)
				end)
				if ok and connection then
					table.insert(themeRuntime.connections, connection)
				end
			end
			local function getThemeRoot()
				local service = cloneref and cloneref(game:GetService("CoreGui")) or game:GetService("CoreGui")
				return gethui and gethui() or service
			end
			local function findMainGui()
				local rootGui = getThemeRoot()
				for _, gui in rootGui:GetChildren() do
					if
						gui:IsA("ScreenGui")
						and gui:FindFirstChild("Executor")
						and gui:FindFirstChild("Settings")
						and gui:FindFirstChild("Sidebar")
					then
						return gui
					end
				end
			end
			local mainGui = findMainGui()
			local attempts = 0
			while themeRuntime.alive and not mainGui and attempts < 100 do
				attempts += 1
				task.wait(0.1)
				mainGui = findMainGui()
			end
			if not (themeRuntime.alive and mainGui) then
				return
			end
			local settingsPath = "DeltaCustom/Settings.json"
			local function readThemeConfig()
				if type(isfile) ~= "function" or type(readfile) ~= "function" or not isfile(settingsPath) then
					return {}
				end
				local ok, raw = pcall(readfile, settingsPath)
				if not ok or type(raw) ~= "string" or raw == "" then
					return {}
				end
				local decodedOk, decoded = pcall(function()
					return __lt.cm("HttpService", "JSONDecode", raw)
				end)
				return decodedOk and type(decoded) == "table" and decoded or {}
			end
			local function saveTheme(name)
				local config = readThemeConfig()
				config.DeltaTheme = { name = name }
				writeJsonFile(settingsPath, config)
			end
			local function capture(object)
				if not object then
					return
				end
				if
					object:IsA("Frame")
					or object:IsA("ImageLabel")
					or object:IsA("ImageButton")
					or object:IsA("TextButton")
					or object:IsA("TextBox")
					or object:IsA("ScrollingFrame")
				then
					if themeRuntime.baseBackground[object] == nil then
						themeRuntime.baseBackground[object] = object.BackgroundColor3
					end
				end
				if object:IsA("TextLabel") or object:IsA("TextButton") or object:IsA("TextBox") then
					if themeRuntime.baseText[object] == nil then
						themeRuntime.baseText[object] = object.TextColor3
					end
				end
				if object:IsA("UIStroke") and themeRuntime.baseStroke[object] == nil then
					themeRuntime.baseStroke[object] = object.Color
				end
				if (object:IsA("ImageLabel") or object:IsA("ImageButton")) and themeRuntime.baseImage[object] == nil then
					themeRuntime.baseImage[object] = object.ImageColor3
				end
			end
			capture(mainGui)
			for _, object in mainGui:GetDescendants() do
				capture(object)
			end
			local palettes = {
				Light = {
					root = Color3.fromRGB(242, 244, 248),
					panel = Color3.fromRGB(229, 232, 239),
					card = Color3.fromRGB(216, 221, 230),
					card2 = Color3.fromRGB(205, 211, 221),
					text = Color3.fromRGB(27, 33, 44),
					muted = Color3.fromRGB(91, 101, 118),
					stroke = Color3.fromRGB(178, 188, 204),
					icon = Color3.fromRGB(69, 79, 96),
					accent = Color3.fromRGB(79, 164, 242),
				},
				Amoled = {
					root = Color3.fromRGB(0, 0, 0),
					panel = Color3.fromRGB(5, 5, 7),
					card = Color3.fromRGB(10, 10, 13),
					card2 = Color3.fromRGB(15, 15, 19),
					text = Color3.fromRGB(244, 247, 250),
					muted = Color3.fromRGB(143, 150, 162),
					stroke = Color3.fromRGB(29, 30, 36),
					icon = Color3.fromRGB(224, 229, 236),
					accent = Color3.fromRGB(79, 164, 242),
				},
			}
			local function isAccent(color)
				local hue, saturation, value = Color3.toHSV(color)
				return saturation >= 0.34 and value >= 0.28 and hue >= 0.48 and hue <= 0.72
			end
			local function isControlColorPart(object)
				local current = object
				while current and current ~= mainGui do
					local name = current.Name
					if
						name == "Hue"
						or name == "Sat"
						or name == "Val"
						or name == "Knob"
						or name == "ColorSlider"
						or name == "ColorValue"
					then
						return true
					end
					current = current.Parent
				end
				return false
			end
			local function backgroundRole(object, palette)
				local name = string.lower(object.Name or "")
				if name == "darkoverlay" then
					return Color3.new(0, 0, 0)
				end
				if
					name:find("overlay")
					or name == "settings"
					or name == "executor"
					or name == "home"
					or name == "scripthub"
					or name == "console"
					or name == "music"
				then
					return palette.root
				end
				if
					name:find("button")
					or name:find("tab")
					or name:find("card")
					or name:find("script")
					or name:find("network")
					or name:find("search")
					or name:find("dropdown")
					or name:find("setting")
				then
					return palette.card
				end
				if object:IsA("TextBox") or object:IsA("TextButton") or object:IsA("ImageButton") then
					return palette.card2
				end
				return palette.panel
			end
			local function restoreObject(object)
				local background = themeRuntime.baseBackground[object]
				if background ~= nil and object.Parent then
					pcall(function()
						object.BackgroundColor3 = background
					end)
				end
				local textColor = themeRuntime.baseText[object]
				if textColor ~= nil and object.Parent then
					pcall(function()
						object.TextColor3 = textColor
					end)
				end
				local strokeColor = themeRuntime.baseStroke[object]
				if strokeColor ~= nil and object.Parent then
					pcall(function()
						object.Color = strokeColor
					end)
				end
				local imageColor = themeRuntime.baseImage[object]
				if imageColor ~= nil and object.Parent then
					pcall(function()
						object.ImageColor3 = imageColor
					end)
				end
			end
			local function applyObject(object, themeName)
				if object:GetAttribute("LT_SyntaxOverlay") then
					return
				end
				capture(object)
				if themeName == "Default" then
					restoreObject(object)
					return
				end
				local palette = palettes[themeName]
				if not palette or isControlColorPart(object) then
					return
				end
				local background = themeRuntime.baseBackground[object]
				if background ~= nil then
					pcall(function()
						object.BackgroundColor3 = isAccent(background) and background or backgroundRole(object, palette)
					end)
				end
				local textColor = themeRuntime.baseText[object]
				if textColor ~= nil then
					local name = string.lower(object.Name or "")
					pcall(function()
						object.TextColor3 = isAccent(textColor) and textColor
							or ((name == "desc" or name:find("description") or name:find("placeholder")) and palette.muted or palette.text)
					end)
				end
				local strokeColor = themeRuntime.baseStroke[object]
				if strokeColor ~= nil then
					pcall(function()
						object.Color = isAccent(strokeColor) and strokeColor or palette.stroke
					end)
				end
				local imageColor = themeRuntime.baseImage[object]
				if imageColor ~= nil then
					local _, saturation = Color3.toHSV(imageColor)
					local name = string.lower(object.Name or "")
					if saturation <= 0.28 or name == "checked" or name:find("icon") or name == "imagebutton" then
						pcall(function()
							object.ImageColor3 = isAccent(imageColor) and imageColor or (name == "checked" and palette.accent or palette.icon)
						end)
					end
				end
			end
			local function getThemeDropdown()
				local executor = mainGui:FindFirstChild("Executor")
				local image = executor and executor:FindFirstChild("Executor")
				local overlay = image and image:FindFirstChild("Overlay")
				local menu = overlay and overlay:FindFirstChild("Menu", true)
				return menu and menu:FindFirstChild("Dropdown")
			end
			local themeMap = { Option1 = "Default", Option2 = "Light", Option3 = "Amoled" }
			local function syncChecks(themeName)
				local dropdown = getThemeDropdown()
				for optionName, name in themeMap do
					local option = dropdown and dropdown:FindFirstChild(optionName)
					local checked = option and option:FindFirstChild("Checked", true)
					if checked and checked:IsA("GuiObject") then
						checked.Visible = name == themeName
					end
				end
			end
			local currentTheme = "Default"
			local applying = false
			local function applyTheme(themeName, persist)
				if applying or not themeRuntime.alive then
					return
				end
				themeName = themeName == "Light" and "Light" or themeName == "Amoled" and "Amoled" or "Default"
				applying = true
				currentTheme = themeName
				applyObject(mainGui, themeName)
				for _, object in mainGui:GetDescendants() do
					applyObject(object, themeName)
				end
				syncChecks(themeName)
				if persist then
					saveTheme(themeName)
				end
				applying = false
			end
			themeRuntime.applyTheme = applyTheme
			themeRuntime.stop = function()
				if not themeRuntime.alive then
					return
				end
				if currentTheme ~= "Default" then
					applyTheme("Default", false)
				end
				themeRuntime.alive = false
				for i = #themeRuntime.connections, 1, -1 do
					pcall(function()
						themeRuntime.connections[i]:Disconnect()
					end)
				end
				table.clear(themeRuntime.connections)
				if rawget(__dcm_env, "__DeltaThemeRuntime") == themeRuntime then
					__dcm_env.__DeltaThemeRuntime = nil
				end
			end
			local boundOptions = setmetatable({}, { __mode = "k" })
			local function bindOption(option, themeName)
				if not (option and option:IsA("GuiButton")) or boundOptions[option] then
					return
				end
				boundOptions[option] = true
				local locked = false
				local function choose()
					if locked then
						return
					end
					locked = true
					task.defer(applyTheme, themeName, true)
					task.delay(0.12, function()
						locked = false
					end)
				end
				connectTheme(option.MouseButton1Click, choose)
				connectTheme(option.Activated, choose)
				connectTheme(option.TouchTap, choose)
			end
			local function bindThemeOptions()
				local dropdown = getThemeDropdown()
				if not dropdown then
					return
				end
				for optionName, themeName in themeMap do
					bindOption(dropdown:FindFirstChild(optionName), themeName)
				end
			end
			bindThemeOptions()
			connectTheme(mainGui.DescendantAdded, function(object)
				task.defer(function()
					if not (themeRuntime.alive and object and object.Parent) then
						return
					end
					capture(object)
					if object:IsA("GuiObject") or object:IsA("UIStroke") then
						applyObject(object, currentTheme)
					end
					if object:IsA("GuiButton") and themeMap[object.Name] and object.Parent and object.Parent.Name == "Dropdown" then
						bindOption(object, themeMap[object.Name])
					end
				end)
			end)
			local config = readThemeConfig()
			local savedTheme = type(config.DeltaTheme) == "table" and config.DeltaTheme.name or nil
			applyTheme(savedTheme, false)
		end)
	end
end

do
	local previous = rawget(__dcm_env, "__DeltaCustomizationV2Runtime")
	if type(previous) == "table" and type(previous.stop) == "function" then
		pcall(previous.stop)
	end

	local runtime = {
		alive = true,
		version = "2.5.5",
		connections = {},
		instances = {},
		originalButtons = setmetatable({}, { __mode = "k" }),
		restorers = {},
	}
	__dcm_env.__DeltaCustomizationV2Runtime = runtime
	__dcm_shared.__DeltaCustomizationV2Runtime = runtime

	local function addConnection(connection)
		if connection then
			table.insert(runtime.connections, connection)
		end
		return connection
	end

	local function connect(signal, callback)
		if not signal then
			return nil
		end
		local ok, connection = pcall(function()
			return signal:Connect(callback)
		end)
		if ok then
			return addConnection(connection)
		end
		return nil
	end

	local function addRestorer(callback)
		if type(callback) == "function" then
			table.insert(runtime.restorers, callback)
		end
	end

	local function track(instance)
		if instance then
			table.insert(runtime.instances, instance)
		end
		return instance
	end

	local function restoreOriginalButtons()
		for button, wasVisible in runtime.originalButtons do
			if button and button.Parent then
				pcall(function()
					local nativeVisible = button:GetAttribute("LT_NativeVisible")
					button.Visible = typeof(nativeVisible) == "boolean" and nativeVisible or wasVisible
				end)
			end
		end
		table.clear(runtime.originalButtons)
	end

	runtime.stop = function()
		if not runtime.alive then
			return
		end
		runtime.alive = false
		restoreOriginalButtons()
		for i = #runtime.restorers, 1, -1 do
			pcall(runtime.restorers[i])
		end
		table.clear(runtime.restorers)
		for name in _naConns do
			NAlib.disconnect(name)
		end
		for i = #runtime.connections, 1, -1 do
			local connection = runtime.connections[i]
			pcall(function()
				connection:Disconnect()
			end)
		end
		table.clear(runtime.connections)
		for i = #runtime.instances, 1, -1 do
			local instance = runtime.instances[i]
			if instance and instance.Parent then
				pcall(function()
					instance:Destroy()
				end)
			end
		end
		table.clear(runtime.instances)
		if rawget(__dcm_env, "__DeltaCustomizationV2Runtime") == runtime then
			__dcm_env.__DeltaCustomizationV2Runtime = nil
		end
		if rawget(__dcm_shared, "__DeltaCustomizationV2Runtime") == runtime then
			__dcm_shared.__DeltaCustomizationV2Runtime = nil
		end
	end

	NAlib.disconnect("FpsCap_Enforce")

	local function findMainGui()
		local best
		local bestScore = 0
		for _, gui in root:GetChildren() do
			if gui:IsA("ScreenGui") then
				local score = 0
				for _, name in { "Executor", "Sidebar", "Scripthub", "Settings", "Home", "Console" } do
					if gui:FindFirstChild(name) then
						score += (name == "Executor" or name == "Sidebar") and 4 or 2
					elseif gui:FindFirstChild(name, true) then
						score += 1
					end
				end
				if score > bestScore then
					best = gui
					bestScore = score
				end
			end
		end
		if bestScore >= 10 then
			return best
		end
	end

	local v2Main = findMainGui()
	local attempts = 0
	while runtime.alive and not v2Main and attempts < 80 do
		attempts += 1
		task.wait(0.1)
		v2Main = findMainGui()
	end
	if not (runtime.alive and v2Main) then
		return
	end

	local executorRoot = v2Main:FindFirstChild("Executor") or v2Main:FindFirstChild("Executor", true)
	local executorImage = executorRoot and executorRoot:FindFirstChild("Executor")
	local executorOverlay = executorImage and executorImage:FindFirstChild("Overlay")
	local tabsFrame = executorOverlay and executorOverlay:FindFirstChild("Tabs", true)
	local codeFrame = executorOverlay and executorOverlay:FindFirstChild("Code", true)
	local buttonsFrame = executorOverlay and executorOverlay:FindFirstChild("Buttons", true)
	if not (executorOverlay and tabsFrame and codeFrame and buttonsFrame) then
		return
	end

	for _, object in codeFrame:GetChildren() do
		if object:GetAttribute("LT_SyntaxOverlay") or object.Name:match("^LT_Syntax_") then
			object:Destroy()
		elseif object:IsA("TextBox") and object.Name:match("^script%d+%.lua$") then
			local originalTransparency = object:GetAttribute("LT_SyntaxOriginalTransparency")
			local originalZ = object:GetAttribute("LT_SyntaxOriginalZIndex")
			object.TextTransparency = typeof(originalTransparency) == "number" and originalTransparency or 0
			object.ZIndex = typeof(originalZ) == "number" and originalZ or 1
			object:SetAttribute("LT_SyntaxOriginalTransparency", nil)
			object:SetAttribute("LT_SyntaxOriginalZIndex", nil)
		end
	end
	local staleToolbar = buttonsFrame:FindFirstChild("LT_EditorToolbar")
	if staleToolbar then
		staleToolbar:Destroy()
	end
	for _, name in { "Execute", "Clear", "ExecuteClipboard" } do
		local button = buttonsFrame:FindFirstChild(name)
		if button and button:IsA("GuiObject") then
			button:SetAttribute("LT_NativeVisible", true)
			button.Visible = true
		end
	end
	buttonsFrame.Visible = true

	local function readCurrentConfig()
		local config = {}
		if
			type(isfile) == "function"
			and type(readfile) == "function"
			and isfile(settingsPath)
		then
			local ok, raw = pcall(readfile, settingsPath)
			if ok and type(raw) == "string" and raw ~= "" then
				local decodedOk, decoded = pcall(function()
					return __lt.cm("HttpService", "JSONDecode", raw)
				end)
				if decodedOk and type(decoded) == "table" then
					config = decoded
				end
			end
		end
		return config
	end

	local function readBool(key, defaultValue)
		local config = readCurrentConfig()
		local value = config[key]
		if type(value) == "table" and value.enabled ~= nil then
			return value.enabled and true or false
		end
		return defaultValue
	end

	local function saveBool(key, enabled)
		local config = readCurrentConfig()
		config[key] = { enabled = enabled and true or false }
		writeJsonFile(settingsPath, config)
	end

	local function readNumber(key, defaultValue, minimum, maximum)
		local config = readCurrentConfig()
		local value = config[key]
		local number = type(value) == "table" and tonumber(value.value) or nil
		return math.clamp(number or defaultValue, minimum, maximum)
	end

	local function saveNumber(key, value)
		local config = readCurrentConfig()
		config[key] = { value = value }
		writeJsonFile(settingsPath, config)
	end

	do
		local config = readCurrentConfig()
		if config.UiBlur ~= nil or config.UiBlurSize ~= nil then
			config.UiBlur = nil
			config.UiBlurSize = nil
			writeJsonFile(settingsPath, config)
		end
	end

	local autoRestoreEnabled = readBool("AutoRestoreTabs", true)
	local editorToolbarEnabled = readBool("EditorToolbar", true)
	local editorStatusEnabled = readBool("EditorStatus", true)
	local wideEditorEnabled = readBool("WideEditor", false)
	local compactTabsEnabled = readBool("CompactTabs", false)
	local editorWordWrapEnabled = readBool("EditorWordWrap", false)
	local syntaxHighlightEnabled = readBool("EditorSyntaxHighlight", true)
	local exploitSyntaxEnabled = readBool("ExploitSyntaxHighlight", true)
	local editorFontSize = math.floor(readNumber("EditorFontSize", 14, 10, 24) + 0.5)
	local toolbarButtons = {}
	local toolbarLayout = buttonsFrame:FindFirstChildOfClass("UIListLayout")
	local originalToolbarPadding = toolbarLayout and toolbarLayout.Padding or nil
	local nativeButtonOriginals = setmetatable({}, { __mode = "k" })
	local statusFrame
	local statusLabel
	local editorCanvas
	local originalCodePosition = codeFrame.Position
	local originalCodeSize = codeFrame.Size
	local originalButtonsVisible = buttonsFrame.Visible
	local statusUpdateQueued = false
	local hookedBoxes = setmetatable({}, { __mode = "k" })
	local sidebar = v2Main:FindFirstChild("Sidebar") or v2Main:FindFirstChild("Sidebar", true)
	local sidebarLayout = sidebar and sidebar:FindFirstChildOfClass("UIListLayout")
	local originalSidebarSortOrder = sidebarLayout and sidebarLayout.SortOrder or nil
	local sidebarNames = { "Home", "Executor", "Scripthub", "Music", "Console", "Settings", "ToggleUI" }
	local sidebarNameSet = {}
	local sidebarOriginalOrders = setmetatable({}, { __mode = "k" })
	for _, name in sidebarNames do
		sidebarNameSet[name] = true
		local button = sidebar and sidebar:FindFirstChild(name)
		if button and button:IsA("GuiObject") then
			sidebarOriginalOrders[button] = button.LayoutOrder
		end
	end

	local function normalizeSidebarOrder(value)
		local result = {}
		local used = {}
		if type(value) == "table" then
			for _, name in value do
				if sidebarNameSet[name] and not used[name] then
					used[name] = true
					table.insert(result, name)
				end
			end
		end
		local musicWasMissing = not used.Music
		for _, name in sidebarNames do
			if not used[name] then
				used[name] = true
				table.insert(result, name)
			end
		end
		if musicWasMissing then
			local musicIndex = table.find(result, "Music")
			if musicIndex then
				table.remove(result, musicIndex)
				local hubIndex = table.find(result, "Scripthub") or math.min(3, #result)
				table.insert(result, hubIndex + 1, "Music")
			end
		end
		return result
	end

	local function readSidebarOrder()
		local config = readCurrentConfig()
		local saved = config.SidebarButtonOrder
		if type(saved) == "table" and type(saved.order) == "table" then
			saved = saved.order
		end
		return normalizeSidebarOrder(saved)
	end

	local sidebarOrder = readSidebarOrder()
	local sidebarApplyingOrder = false

	local function saveSidebarOrder()
		local config = readCurrentConfig()
		config.SidebarButtonOrder = { order = table.clone(sidebarOrder) }
		writeJsonFile(settingsPath, config)
	end

	local function applySidebarOrder()
		if sidebarApplyingOrder or not sidebar then
			return
		end
		sidebarApplyingOrder = true
		if sidebarLayout then
			sidebarLayout.SortOrder = Enum.SortOrder.LayoutOrder
		end
		for index, name in sidebarOrder do
			local button = sidebar:FindFirstChild(name)
			if button and button:IsA("GuiObject") then
				if sidebarOriginalOrders[button] == nil then
					sidebarOriginalOrders[button] = button.LayoutOrder
				end
				button.LayoutOrder = index
			end
		end
		sidebarApplyingOrder = false
	end

	local function moveSidebarButton(name, direction)
		local index = table.find(sidebarOrder, name)
		if not index then
			return
		end
		local target = math.clamp(index + direction, 1, #sidebarOrder)
		if target == index then
			return
		end
		sidebarOrder[index], sidebarOrder[target] = sidebarOrder[target], sidebarOrder[index]
		applySidebarOrder()
		saveSidebarOrder()
	end

	local function getCodeBoxes()
		local boxes = {}
		for _, object in codeFrame:GetDescendants() do
			if object:IsA("TextBox") and object.Name:match("^script%d+%.lua$") then
				table.insert(boxes, object)
			end
		end
		table.sort(boxes, function(a, b)
			local ai = tonumber(a.Name:match("%d+")) or math.huge
			local bi = tonumber(b.Name:match("%d+")) or math.huge
			return ai < bi
		end)
		return boxes
	end

	local function getActiveCodeBox()
		local focused = UIS and UIS:GetFocusedTextBox()
		if focused and focused:IsDescendantOf(codeFrame) then
			return focused
		end
		for _, box in getCodeBoxes() do
			if box.Visible then
				return box
			end
		end
		return getCodeBoxes()[1]
	end


	runtime.clipboardCache = tostring(runtime.clipboardCache or "")

	local function writeClipboard(value)
		value = tostring(value or "")
		runtime.clipboardCache = value
		local writer = type(setclipboard) == "function" and setclipboard
			or type(toclipboard) == "function" and toclipboard
			or type(setrbxclipboard) == "function" and setrbxclipboard
		if writer then
			pcall(writer, value)
		end
		return writer ~= nil
	end

	local function readClipboard()
		local reader = type(getclipboard) == "function" and getclipboard
			or type(readclipboard) == "function" and readclipboard
		if reader then
			local ok, value = pcall(reader)
			if ok and type(value) == "string" then
				runtime.clipboardCache = value
				return value, true
			end
		end
		if runtime.clipboardCache ~= "" then
			return runtime.clipboardCache, false
		end
		return nil, false
	end


	local function insertIntoActive(text)
		local box = getActiveCodeBox()
		if not box then
			return false
		end
		text = tostring(text or "")
		local current = box.Text or ""
		local cursor = tonumber(box.CursorPosition) or -1
		if cursor < 1 or cursor > #current + 1 then
			cursor = #current + 1
		end
		box.Text = current:sub(1, cursor - 1) .. text .. current:sub(cursor)
		local nextCursor = cursor + #text
		task.defer(function()
			if box and box.Parent then
				pcall(function()
					box:CaptureFocus()
					box.CursorPosition = nextCursor
					box.SelectionStart = nextCursor
				end)
			end
		end)
		return true
	end


	local function copyActiveCode()
		local box = getActiveCodeBox()
		if not box then
			return
		end
		writeClipboard(box.Text or "")
		notify({
			Title = "Delta Customization",
			Description = "Copied the active editor tab.",
			Duration = 3,
		})
	end

	local function pasteIntoActive()
		local value = readClipboard()
		if type(value) == "string" then
			insertIntoActive(value)
			return
		end
		notify({
			Title = "Delta Customization",
			Description = "Clipboard access is unavailable in this Delta build.",
			Duration = 5,
		})
	end

	local function executeSource(source, chunkName)
		source = tostring(source or "")
		if type(loadstring) ~= "function" then
			notify({
				Title = "Delta Customization",
				Description = "Script execution is unavailable in this Delta build.",
				Duration = 5,
			})
			return false
		end
		local compiled, compileError = loadstring(source, chunkName or "=Delta V2")
		if not compiled then
			notify({
				Title = "Delta V2 compile error",
				Description = tostring(compileError or "Unknown compile error"),
				Duration = 7,
			})
			return false
		end
		task.spawn(function()
			local ok, runtimeError = xpcall(compiled, function(message)
				return tostring(message)
			end)
			if not ok then
				notify({
					Title = "Delta V2 runtime error",
					Description = tostring(runtimeError or "Unknown runtime error"),
					Duration = 7,
				})
			end
		end)
		return true
	end

	local function executeActiveCode()
		local box = getActiveCodeBox()
		if not box then
			return false
		end
		return executeSource(box.Text or "", "=" .. tostring(box.Name))
	end

	local function clearActiveCode()
		local box = getActiveCodeBox()
		if not box then
			return false
		end
		box.Text = ""
		task.defer(function()
			if box and box.Parent then
				pcall(function()
					box.CursorPosition = 1
					box.SelectionStart = -1
				end)
			end
		end)
		return true
	end

	local function executeClipboardCode()
		local value = readClipboard()
		if type(value) ~= "string" then
			notify({
				Title = "Delta Customization",
				Description = "Clipboard access is unavailable in this Delta build.",
				Duration = 5,
			})
			return false
		end
		return executeSource(value, "=Delta V2 Clipboard")
	end

	local function activateOriginal(button)
		if not button then
			return false
		end
		if type(firesignal) == "function" then
			if type(getconnections) == "function" then
				for _, signalName in { "MouseButton1Click", "Activated" } do
					local signal = button[signalName]
					local ok, connections = pcall(getconnections, signal)
					if ok and type(connections) == "table" and #connections > 0 then
						local fired = pcall(firesignal, signal)
						if fired then
							return true
						end
					end
				end
			end
			local ok = pcall(firesignal, button.MouseButton1Click)
			if ok then
				return true
			end
		end
		return pcall(function()
			button:Activate()
		end)
	end

	local function removeScripts(instance)
		for _, object in instance:GetDescendants() do
			if object:IsA("LuaSourceContainer") then
				object:Destroy()
			end
		end
	end

	local function setButtonTitle(button, text)
		local title = button:FindFirstChild("Title", true) or button:FindFirstChildWhichIsA("TextLabel", true)
		if title and title:IsA("TextLabel") then
			title.Text = text
		end
	end

	local function captureNativeButton(button)
		if not (button and button:IsA("GuiObject")) or nativeButtonOriginals[button] then
			return
		end
		local title = button:FindFirstChild("Title", true) or button:FindFirstChildWhichIsA("TextLabel", true)
		nativeButtonOriginals[button] = {
			Size = button.Size,
			LayoutOrder = button.LayoutOrder,
			Title = title,
			Text = title and title.Text or nil,
			TextScaled = title and title.TextScaled or nil,
			TextSize = title and title.TextSize or nil,
			TextTruncate = title and title.TextTruncate or nil,
		}
	end

	local function restoreNativeButton(button)
		local original = nativeButtonOriginals[button]
		if not (original and button and button.Parent) then
			return
		end
		button.Size = original.Size
		button.LayoutOrder = original.LayoutOrder
		button.Visible = true
		local title = original.Title
		if title and title.Parent then
			title.Text = original.Text
			title.TextScaled = original.TextScaled
			title.TextSize = original.TextSize
			title.TextTruncate = original.TextTruncate
		end
	end

	local function styleNativeButton(button, text, width, order)
		if not (button and button:IsA("GuiObject")) then
			return
		end
		captureNativeButton(button)
		button.Visible = true
		button.Size = UDim2.new(width, 0, 0.7, 0)
		button.LayoutOrder = order
		setButtonTitle(button, text)
		local title = button:FindFirstChild("Title", true) or button:FindFirstChildWhichIsA("TextLabel", true)
		if title and title:IsA("TextLabel") then
			title.TextScaled = false
			title.TextSize = buttonsFrame.AbsoluteSize.X < 650 and 10 or 12
			title.TextTruncate = Enum.TextTruncate.AtEnd
		end
	end

	local function createToolbarButton(parent, template, name, text, order, callback)
		local button = template:Clone()
		button.Name = name
		removeScripts(button)
		button.Visible = true
		button.Active = true
		button.Interactable = true
		button.Selectable = true
		button.AnchorPoint = Vector2.new(0, 0.5)
		button.Position = UDim2.new(0, 0, 0.5, 0)
		button.Size = UDim2.new(1 / 6, -4, 1, -6)
		button.LayoutOrder = order
		button.ZIndex = parent.ZIndex + 1
		button.Parent = parent
		for _, object in button:GetDescendants() do
			if object:IsA("GuiObject") then
				object.ZIndex = button.ZIndex + 1
			end
		end
		setButtonTitle(button, text)
		local title = button:FindFirstChild("Title", true) or button:FindFirstChildWhichIsA("TextLabel", true)
		if title and title:IsA("TextLabel") then
			title.TextScaled = false
			title.TextSize = buttonsFrame.AbsoluteSize.X < 650 and 10 or 12
			title.TextTruncate = Enum.TextTruncate.AtEnd
		end
		track(button)
		local locked = false
		local function activate()
			if locked or not runtime.alive then
				return
			end
			locked = true
			callback()
			task.delay(0.1, function()
				locked = false
			end)
		end
		if button:IsA("GuiButton") then
			connect(button.MouseButton1Click, activate)
			connect(button.Activated, activate)
			connect(button.TouchTap, activate)
		else
			connect(button.InputEnded, function(input)
				if
					input.UserInputType == Enum.UserInputType.MouseButton1
					or input.UserInputType == Enum.UserInputType.Touch
				then
					activate()
				end
			end)
		end
		return button
	end

	local function clearToolbar()
		for i = #toolbarButtons, 1, -1 do
			local button = toolbarButtons[i]
			if button and button.Parent then
				button:Destroy()
			end
			toolbarButtons[i] = nil
		end
		for _, name in { "LT_Copy", "LT_Paste", "LT_NewLine" } do
			local stale = buttonsFrame:FindFirstChild(name)
			if stale then
				stale:Destroy()
			end
		end
		for _, name in { "Execute", "Clear", "ExecuteClipboard" } do
			restoreNativeButton(buttonsFrame:FindFirstChild(name))
		end
		if toolbarLayout and originalToolbarPadding then
			toolbarLayout.Padding = originalToolbarPadding
		end
	end

	local function addToolbarButton(template, name, text, order, width, callback)
		local button = createToolbarButton(buttonsFrame, template, name, text, order, callback)
		button.AnchorPoint = Vector2.new(0, 0)
		button.Size = UDim2.new(width, 0, 0.7, 0)
		table.insert(toolbarButtons, button)
		return button
	end

	local function buildToolbar()
		clearToolbar()
		for _, name in {
			"CopyCode",
			"LT_EditorToolbar",
			"LT_Execute",
			"LT_Clear",
			"LT_ExecuteClipboard",
			"LT_Copy",
			"LT_Paste",
			"LT_NewLine",
		} do
			local stale = buttonsFrame:FindFirstChild(name)
			if stale then
				stale:Destroy()
			end
		end
		local executeButton = buttonsFrame:FindFirstChild("Execute")
		local clearButton = buttonsFrame:FindFirstChild("Clear")
		local clipboardButton = buttonsFrame:FindFirstChild("ExecuteClipboard")
		for _, button in { executeButton, clearButton, clipboardButton } do
			if button and button:IsA("GuiObject") then
				button:SetAttribute("LT_NativeVisible", true)
				button.Visible = true
			end
		end
		if not editorToolbarEnabled then
			return
		end
		local template = clipboardButton or executeButton or clearButton
		if not (executeButton and clearButton and clipboardButton and template and template:IsA("GuiObject")) then
			return
		end
		if toolbarLayout then
			toolbarLayout.Padding = UDim.new(0, 4)
		end
		styleNativeButton(executeButton, "RUN", 0.14, 0)
		styleNativeButton(clearButton, "CLEAR", 0.13, 1)
		styleNativeButton(clipboardButton, "RUN CLIP", 0.20, 2)
		addToolbarButton(template, "LT_Copy", "COPY", 3, 0.13, copyActiveCode)
		addToolbarButton(template, "LT_Paste", "PASTE", 4, 0.13, pasteIntoActive)
		addToolbarButton(template, "LT_NewLine", "ADD LINE", 5, 0.16, function()
			insertIntoActive("\n")
		end)
	end

	local function updateStatusPosition()
		if not (statusFrame and statusFrame.Parent and codeFrame and codeFrame.Parent == executorOverlay) then
			return
		end
		statusFrame.Position = UDim2.new(
			codeFrame.Position.X.Scale + codeFrame.Size.X.Scale * (1 - codeFrame.AnchorPoint.X),
			codeFrame.Position.X.Offset + codeFrame.Size.X.Offset * (1 - codeFrame.AnchorPoint.X) - 6,
			codeFrame.Position.Y.Scale + codeFrame.Size.Y.Scale * (1 - codeFrame.AnchorPoint.Y),
			codeFrame.Position.Y.Offset + codeFrame.Size.Y.Offset * (1 - codeFrame.AnchorPoint.Y) - 5
		)
		statusFrame.Size = UDim2.new(0, math.clamp(math.floor(codeFrame.AbsoluteSize.X * 0.58), 210, 360), 0, 22)
	end

	local function updateStatus()
		statusUpdateQueued = false
		if not (statusFrame and statusLabel) then
			return
		end
		statusFrame.Visible = editorStatusEnabled
		if not editorStatusEnabled then
			return
		end
		local box = getActiveCodeBox()
		if not box then
			statusLabel.Text = "No active editor tab"
			return
		end
		local text = box.Text or ""
		local _, lineBreaks = text:gsub("\n", "\n")
		local lines = lineBreaks + 1
		statusLabel.Text = string.format("%s   •   %d lines   •   %d chars   •   autosave", box.Name, lines, #text)
	end

	local function queueStatusUpdate()
		if statusUpdateQueued then
			return
		end
		statusUpdateQueued = true
		task.defer(updateStatus)
	end

	local saveTokens = setmetatable({}, { __mode = "k" })
	local tabDirectory = "DeltaCustom/DeltaTabs"
	editorCanvas = (function()
		local TextService = game:GetService("TextService")
		local hooked = setmetatable({}, { __mode = "k" })
		local originals = setmetatable({}, { __mode = "k" })
		local resizeTokens = setmetatable({}, { __mode = "k" })
		local originalCanvasSize = codeFrame.CanvasSize
		local originalAutomaticCanvasSize = codeFrame.AutomaticCanvasSize
		local originalCanvasPosition = codeFrame.CanvasPosition

		local function effectiveScale(object)
			local scale = 1
			local current = object
			while current do
				for _, child in current:GetChildren() do
					if child:IsA("UIScale") then
						scale *= child.Scale
					end
				end
				current = current.Parent
			end
			return math.max(scale, 0.05)
		end

		local function remember(box)
			if originals[box] == nil then
				originals[box] = {
					AutomaticSize = box.AutomaticSize,
					Position = box.Position,
					Size = box.Size,
				}
			end
		end

		local function resize(box)
			if not (runtime.alive and box and box.Parent and box:IsA("TextBox")) then
				return
			end
			remember(box)
			local token = (resizeTokens[box] or 0) + 1
			resizeTokens[box] = token
			task.defer(function()
				if not (runtime.alive and box.Parent and resizeTokens[box] == token) then
					return
				end
				local scale = effectiveScale(codeFrame)
				local windowWidth = math.max(140, math.floor(codeFrame.AbsoluteWindowSize.X / scale))
				local windowHeight = math.max(100, math.floor(codeFrame.AbsoluteWindowSize.Y / scale))
				local availableTextWidth = math.max(120, windowWidth - 20)
				local text = box.Text ~= "" and box.Text or " "
				local params = Instance.new("GetTextBoundsParams")
				params.Text = text
				params.Width = box.TextWrapped and availableTextWidth or 1000000
				params.Font = box.FontFace
				params.Size = box.TextSize
				local ok, bounds = pcall(function()
					return TextService:GetTextBoundsAsync(params)
				end)
				params:Destroy()
				local _, lineBreaks = (box.Text or ""):gsub("\n", "\n")
				local lineHeight = math.max(1, box.LineHeight) * box.TextSize
				local minimumTextHeight = math.ceil((lineBreaks + 1) * lineHeight)
				if not ok then
					bounds = Vector2.new(availableTextWidth, minimumTextHeight)
				end
				if not (runtime.alive and box.Parent and resizeTokens[box] == token) then
					return
				end
				local measuredWidth = math.ceil(bounds.X)
				local measuredHeight = math.max(math.ceil(bounds.Y), minimumTextHeight)
				local contentWidth = box.TextWrapped
					and availableTextWidth
					or math.max(availableTextWidth, measuredWidth + 28)
				local contentHeight = math.max(windowHeight - 12, measuredHeight + math.ceil(lineHeight) + 28)
				local canvasWidth = box.TextWrapped
					and windowWidth
					or math.max(windowWidth, 8 + contentWidth + 32)
				local canvasHeight = math.max(windowHeight, 6 + contentHeight + 36)
				box.AutomaticSize = Enum.AutomaticSize.None
				box.Position = UDim2.fromOffset(8, 6)
				box.Size = UDim2.fromOffset(contentWidth, contentHeight)
				if box.Visible then
					codeFrame.AutomaticCanvasSize = Enum.AutomaticSize.None
					codeFrame.CanvasSize = UDim2.fromOffset(canvasWidth, canvasHeight)
					local maximumX = math.max(0, canvasWidth - windowWidth)
					local maximumY = math.max(0, canvasHeight - windowHeight)
					codeFrame.CanvasPosition = Vector2.new(
						math.clamp(codeFrame.CanvasPosition.X, 0, maximumX),
						math.clamp(codeFrame.CanvasPosition.Y, 0, maximumY)
					)
				end
			end)
		end

		local function hook(box)
			if hooked[box] or not box:IsA("TextBox") or not box.Name:match("^script%d+%.lua$") then
				return
			end
			hooked[box] = true
			remember(box)
			for _, property in { "Text", "Visible", "TextWrapped", "TextSize", "FontFace", "LineHeight" } do
				connect(box:GetPropertyChangedSignal(property), function()
					resize(box)
				end)
			end
			resize(box)
		end

		local function resizeAll()
			for _, box in getCodeBoxes() do
				hook(box)
				resize(box)
			end
		end

		local function restore()
			if codeFrame and codeFrame.Parent then
				codeFrame.AutomaticCanvasSize = originalAutomaticCanvasSize
				codeFrame.CanvasSize = originalCanvasSize
				codeFrame.CanvasPosition = originalCanvasPosition
			end
			for box, values in originals do
				if box and box.Parent then
					box.AutomaticSize = values.AutomaticSize
					box.Position = values.Position
					box.Size = values.Size
				end
			end
		end

		connect(codeFrame:GetPropertyChangedSignal("AbsoluteSize"), resizeAll)
		pcall(function()
			connect(codeFrame:GetPropertyChangedSignal("AbsoluteWindowSize"), resizeAll)
		end)
		return { hook = hook, resize = resize, resizeAll = resizeAll, restore = restore }
	end)()

	local function applyToolbarLayout()
		buttonsFrame.Visible = true
		codeFrame.Position = originalCodePosition
		codeFrame.Size = originalCodeSize
		task.defer(updateStatusPosition)
		task.delay(0.05, function()
			if runtime.alive then
				editorCanvas.resizeAll()
			end
		end)
	end

	addRestorer(function()
		for button, layoutOrder in sidebarOriginalOrders do
			if button and button.Parent then
				button.LayoutOrder = layoutOrder
			end
		end
		if sidebarLayout and originalSidebarSortOrder then
			sidebarLayout.SortOrder = originalSidebarSortOrder
		end
	end)

	if sidebar then
		applySidebarOrder()
		connect(sidebar.ChildAdded, function(object)
			if sidebarNameSet[object.Name] and object:IsA("GuiObject") then
				task.defer(applySidebarOrder)
			end
		end)
	end

	addRestorer(function()
		if codeFrame and codeFrame.Parent then
			codeFrame.Position = originalCodePosition
			codeFrame.Size = originalCodeSize
		end
		if buttonsFrame and buttonsFrame.Parent then
			for _, name in { "LT_Copy", "LT_Paste", "LT_NewLine" } do
				local button = buttonsFrame:FindFirstChild(name)
				if button then
					button:Destroy()
				end
			end
			for _, name in { "Execute", "Clear", "ExecuteClipboard" } do
				restoreNativeButton(buttonsFrame:FindFirstChild(name))
			end
			if toolbarLayout and originalToolbarPadding then
				toolbarLayout.Padding = originalToolbarPadding
			end
			buttonsFrame.Visible = originalButtonsVisible
		end
	end)

	local syntaxHighlighter = (function()
		local overlays = setmetatable({}, { __mode = "k" })
		local updateTokens = setmetatable({}, { __mode = "k" })
		local keywords = {
			["and"] = true, ["break"] = true, ["continue"] = true, ["do"] = true,
			["else"] = true, ["elseif"] = true, ["end"] = true, ["export"] = true,
			["false"] = true, ["for"] = true, ["function"] = true, ["if"] = true,
			["in"] = true, ["local"] = true, ["nil"] = true, ["not"] = true,
			["or"] = true, ["repeat"] = true, ["return"] = true, ["then"] = true,
			["true"] = true, ["type"] = true, ["until"] = true, ["while"] = true,
		}
		local builtins = {
			assert = true, collectgarbage = true, error = true, getfenv = true, getmetatable = true,
			ipairs = true, load = true, loadstring = true, next = true, pairs = true, pcall = true,
			print = true, rawequal = true, rawget = true, rawlen = true, rawset = true, require = true,
			select = true, setfenv = true, setmetatable = true, tonumber = true, tostring = true,
			typeof = true, unpack = true, warn = true, xpcall = true,
			bit32 = true, buffer = true, coroutine = true, debug = true, math = true, os = true,
			string = true, table = true, task = true, utf8 = true, vector = true,
			Axes = true, BrickColor = true, CFrame = true, Color3 = true, ColorSequence = true,
			ColorSequenceKeypoint = true, DateTime = true, DockWidgetPluginGuiInfo = true,
			Enum = true, Faces = true, Font = true, Instance = true, NumberRange = true,
			NumberSequence = true, NumberSequenceKeypoint = true, OverlapParams = true,
			PathWaypoint = true, PhysicalProperties = true, Random = true, Ray = true,
			RaycastParams = true, Rect = true, Region3 = true, Region3int16 = true,
			TweenInfo = true, UDim = true, UDim2 = true, Vector2 = true, Vector2int16 = true,
			Vector3 = true, Vector3int16 = true,
			any = true, boolean = true, never = true, number = true, string = true,
			table = true, thread = true, unknown = true,
		}
		local globals = {
			_G = true, game = true, plugin = true, script = true, shared = true, workspace = true,
		}
		local executorApis = {
			appendfile = true, base64_decode = true, base64_encode = true, base64decode = true,
			base64encode = true, checkcaller = true, checkclosure = true, cloneref = true,
			clonefunction = true, compareinstances = true, crypt = true, decompile = true,
			delfile = true, delfolder = true, dofile = true, Drawing = true, dumpstring = true,
			fireclickdetector = true, fireproximityprompt = true, firesignal = true,
			firetouchinterest = true, fluxus = true, getcallbackvalue = true, getcallingscript = true,
			getclipboard = true, getconnections = true, getconstant = true, getconstants = true,
			getcustomasset = true, getexecutorname = true, getfflag = true, getfflags = true,
			getfpscap = true, getgc = true, getgenv = true, gethiddenproperties = true,
			gethiddenproperty = true, gethui = true, getidentity = true, getinstances = true,
			getloadedmodules = true, getnamecallmethod = true, getnilinstances = true,
			getproto = true, getprotos = true, getrawmetatable = true, getreg = true,
			getrenv = true, getrunningscripts = true, getscriptbytecode = true,
			getscriptclosure = true, getscriptfromthread = true, getscriptfunction = true,
			getscripts = true, getstack = true, getsynasset = true, getthreadidentity = true,
			getupvalue = true, getupvalues = true, hookfunction = true, hookmetamethod = true,
			http_request = true, identifyexecutor = true, is_c_closure = true, iscclosure = true,
			isexecutorclosure = true, isfile = true, isfolder = true, iskrnlclosure = true,
			islclosure = true, isourclosure = true, isreadonly = true, isscriptable = true,
			listfiles = true, loadfile = true, lz4compress = true, lz4decompress = true,
			make_readonly = true, make_writeable = true, makefolder = true, newcclosure = true,
			protect_gui = true, queue_on_teleport = true, queueonteleport = true, readclipboard = true,
			readfile = true, replaceclosure = true, request = true, saveinstance = true,
			setclipboard = true, setconstant = true, setfflag = true, setfpscap = true,
			sethiddenproperty = true, setidentity = true, setnamecallmethod = true,
			setproto = true, setreadonly = true, setrbxclipboard = true, setscriptable = true,
			setstack = true, setthreadidentity = true, setupvalue = true, syn = true,
			toclipboard = true, unprotect_gui = true, WebSocket = true, websocket = true,
			writeclipboard = true, writefile = true,
		}

		local function escape(value)
			return tostring(value or ""):gsub("&", "&amp;"):gsub("<", "&lt;"):gsub(">", "&gt;")
		end

		local function palette()
			local background = codeFrame.BackgroundColor3
			local light = background.R * 0.299 + background.G * 0.587 + background.B * 0.114 > 0.58
			if light then
				return {
					text = Color3.fromRGB(25, 30, 42), keyword = "#AF00DB", builtin = "#267F99",
					global = "#001080", func = "#795E26", string = "#A31515",
					number = "#098658", comment = "#008000", executor = "#B44700",
				}
			end
			return {
				text = Color3.fromRGB(218, 222, 232), keyword = "#C586C0", builtin = "#4EC9B0",
				global = "#9CDCFE", func = "#DCDCAA", string = "#CE9178",
				number = "#B5CEA8", comment = "#6A9955", executor = "#FF9E64",
			}
		end

		local function paint(value, color)
			return '<font color="' .. color .. '">' .. escape(value) .. "</font>"
		end

		local function longBracketAt(source, index)
			local equals = source:sub(index):match("^%[(=*)%[")
			if equals == nil then
				return nil
			end
			local closing = "]" .. equals .. "]"
			local finish = source:find(closing, index + #equals + 2, true)
			return finish and finish + #closing - 1 or #source
		end

		local function tokenize(source)
			local colors = palette()
			local output = table.create(math.max(32, math.floor(#source / 6)))
			local index = 1
			local expectFunctionName = false
			while index <= #source do
				local char = source:sub(index, index)
				local pair = source:sub(index, index + 1)
				if pair == "--" then
					local longFinish = longBracketAt(source, index + 2)
					local finish = longFinish or ((source:find("\n", index + 2, true) or (#source + 1)) - 1)
					output[#output + 1] = paint(source:sub(index, finish), colors.comment)
					index = finish + 1
				elseif char == "\"" or char == "'" then
					local quote = char
					local finish = index + 1
					while finish <= #source do
						local current = source:sub(finish, finish)
						if current == "\\" then
							finish += 2
						elseif current == quote then
							break
						else
							finish += 1
						end
					end
					finish = math.min(finish, #source)
					output[#output + 1] = paint(source:sub(index, finish), colors.string)
					index = finish + 1
				elseif char == "[" then
					local finish = longBracketAt(source, index)
					if finish then
						output[#output + 1] = paint(source:sub(index, finish), colors.string)
						index = finish + 1
					else
						output[#output + 1] = escape(char)
						index += 1
					end
				elseif char:match("[%a_]") then
					local finish = index
					while finish < #source and source:sub(finish + 1, finish + 1):match("[%w_]") do
						finish += 1
					end
					local word = source:sub(index, finish)
					local color
					if keywords[word] then
						color = colors.keyword
						expectFunctionName = word == "function"
					elseif exploitSyntaxEnabled and executorApis[word] then
						color = colors.executor
					elseif builtins[word] then
						color = colors.builtin
					elseif globals[word] then
						color = colors.global
					else
						local nextIndex = finish + 1
						while nextIndex <= #source and source:sub(nextIndex, nextIndex):match("%s") do
							nextIndex += 1
						end
						if expectFunctionName or source:sub(nextIndex, nextIndex) == "(" then
							color = colors.func
						end
						expectFunctionName = false
					end
					output[#output + 1] = color and paint(word, color) or escape(word)
					index = finish + 1
				elseif char:match("%d") or (char == "." and source:sub(index + 1, index + 1):match("%d")) then
					local rest = source:sub(index)
					local number = rest:match("^0[xX][%da-fA-F_]+")
						or rest:match("^0[bB][01_]+")
						or rest:match("^%d[%d_]*%.?[%d_]*[eE][+-]?[%d_]+")
						or rest:match("^%.%d[%d_]*[eE][+-]?[%d_]+")
						or rest:match("^%d[%d_]*%.?[%d_]*")
						or rest:match("^%.%d[%d_]*")
					number = number ~= "" and number or char
					output[#output + 1] = paint(number, colors.number)
					index += #number
				else
					output[#output + 1] = escape(char)
					index += 1
				end
			end
			return table.concat(output), colors.text
		end

		local function sync(box)
			local state = overlays[box]
			if not state then
				return
			end
			local label = state.label
			if not (box.Parent and label.Parent) then
				return
			end
			label.AnchorPoint = box.AnchorPoint
			label.Position = box.Position
			label.Size = box.Size
			label.Rotation = box.Rotation
			label.TextXAlignment = box.TextXAlignment
			label.TextYAlignment = box.TextYAlignment
			label.TextWrapped = box.TextWrapped
			label.FontFace = box.FontFace
			label.TextSize = box.TextSize
			label.LineHeight = box.LineHeight
			local showOverlay = syntaxHighlightEnabled and box.Visible and box.Text ~= ""
			label.Visible = showOverlay
			if showOverlay then
				box.TextTransparency = 1
				box.ZIndex = state.originalZ + 1
				label.ZIndex = state.originalZ
			else
				box.TextTransparency = state.originalTransparency
				box.ZIndex = state.originalZ
			end
		end

		local function update(box)
			local state = overlays[box]
			if not state then
				return
			end
			sync(box)
			if not syntaxHighlightEnabled then
				return
			end
			local richText, textColor = tokenize(box.Text or "")
			state.label.TextColor3 = textColor
			state.label.Text = richText
		end

		local function queue(box)
			local token = (updateTokens[box] or 0) + 1
			updateTokens[box] = token
			task.delay(#(box.Text or "") > 60000 and 0.08 or 0.025, function()
				if runtime.alive and box.Parent and updateTokens[box] == token then
					update(box)
				end
			end)
		end

		local function hook(box)
			if overlays[box] or not box:IsA("TextBox") or not box.Name:match("^script%d+%.lua$") then
				return
			end
			local label = Instance.new("TextLabel")
			label.Name = "LT_Syntax_" .. box.Name
			label:SetAttribute("LT_SyntaxOverlay", true)
			label.BackgroundTransparency = 1
			label.BorderSizePixel = 0
			label.RichText = true
			label.TextScaled = false
			label.TextTruncate = Enum.TextTruncate.None
			label.Active = false
			label.Interactable = false
			label.Selectable = false
			label.Parent = box.Parent
			track(label)
			local originalTransparency = box:GetAttribute("LT_SyntaxOriginalTransparency")
			if typeof(originalTransparency) ~= "number" then
				originalTransparency = box.TextTransparency < 1 and box.TextTransparency or 0
			end
			local originalZ = box:GetAttribute("LT_SyntaxOriginalZIndex")
			if typeof(originalZ) ~= "number" then
				originalZ = math.max(1, box.ZIndex)
			end
			box:SetAttribute("LT_SyntaxOriginalTransparency", originalTransparency)
			box:SetAttribute("LT_SyntaxOriginalZIndex", originalZ)
			overlays[box] = {
				label = label,
				originalTransparency = originalTransparency,
				originalZ = originalZ,
			}
			for _, property in {
				"Text", "Visible", "Position", "Size", "AnchorPoint", "Rotation", "TextWrapped",
				"TextSize", "FontFace", "LineHeight", "TextXAlignment", "TextYAlignment",
			} do
				connect(box:GetPropertyChangedSignal(property), function()
					queue(box)
				end)
			end
			connect(box.Destroying, function()
				local state = overlays[box]
				if state and state.label and state.label.Parent then
					state.label:Destroy()
				end
				overlays[box] = nil
			end)
			queue(box)
		end

		local function applyAll()
			for _, box in getCodeBoxes() do
				hook(box)
				update(box)
			end
		end

		local function restore()
			for box, state in overlays do
				if box and box.Parent then
					box.TextTransparency = state.originalTransparency
					box.ZIndex = state.originalZ
					box:SetAttribute("LT_SyntaxOriginalTransparency", nil)
					box:SetAttribute("LT_SyntaxOriginalZIndex", nil)
				end
				if state.label and state.label.Parent then
					state.label:Destroy()
				end
			end
			table.clear(overlays)
		end

		connect(codeFrame:GetPropertyChangedSignal("BackgroundColor3"), applyAll)
		return { hook = hook, sync = queue, applyAll = applyAll, restore = restore }
	end)()

	local function hookCodeBox(box)
		if
			not (box and box:IsA("TextBox") and not hookedBoxes[box])
			or not box.Name:match("^script%d+%.lua$")
		then
			return
		end
		hookedBoxes[box] = true
		editorCanvas.hook(box)
		syntaxHighlighter.hook(box)
		local path = tabDirectory .. "/" .. box.Name
		if type(isfile) == "function" and type(readfile) == "function" and isfile(path) then
			local ok, data = pcall(readfile, path)
			if ok and type(data) == "string" then
				box.Text = data
			end
		elseif type(writefile) == "function" then
			pcall(writefile, path, box.Text or "")
		end
		connect(box:GetPropertyChangedSignal("Text"), function()
			queueStatusUpdate()
			local token = (saveTokens[box] or 0) + 1
			saveTokens[box] = token
			task.delay(0.3, function()
				if
					runtime.alive
					and box.Parent
					and saveTokens[box] == token
					and type(writefile) == "function"
				then
					pcall(writefile, tabDirectory .. "/" .. box.Name, box.Text or "")
				end
			end)
		end)
		connect(box:GetPropertyChangedSignal("Visible"), queueStatusUpdate)
		connect(box:GetPropertyChangedSignal("Name"), queueStatusUpdate)
		connect(box.Focused, queueStatusUpdate)
	end

	local function buildStatus()
		if statusFrame and statusFrame.Parent then
			statusFrame:Destroy()
		end
		statusFrame = Instance.new("Frame")
		statusFrame.Name = "LT_EditorStatus"
		statusFrame.AnchorPoint = Vector2.new(1, 1)
		statusFrame.BackgroundColor3 = Color3.fromRGB(15, 17, 22)
		statusFrame.BackgroundTransparency = 0.18
		statusFrame.BorderSizePixel = 0
		statusFrame.ZIndex = math.max(codeFrame.ZIndex + 50, 800)
		statusFrame.Visible = editorStatusEnabled
		statusFrame.Parent = executorOverlay
		track(statusFrame)
		local corner = Instance.new("UICorner")
		corner.CornerRadius = UDim.new(0, 7)
		corner.Parent = statusFrame
		track(corner)
		local stroke = Instance.new("UIStroke")
		stroke.Thickness = 1
		stroke.Transparency = 0.45
		stroke.Color = Color3.fromRGB(79, 164, 242)
		stroke.Parent = statusFrame
		track(stroke)
		statusLabel = Instance.new("TextLabel")
		statusLabel.Name = "Text"
		statusLabel.BackgroundTransparency = 1
		statusLabel.Size = UDim2.new(1, -12, 1, 0)
		statusLabel.Position = UDim2.new(0, 6, 0, 0)
		statusLabel.Font = Enum.Font.Gotham
		statusLabel.TextSize = 11
		statusLabel.TextColor3 = Color3.fromRGB(222, 228, 238)
		statusLabel.TextXAlignment = Enum.TextXAlignment.Right
		statusLabel.TextTruncate = Enum.TextTruncate.AtEnd
		statusLabel.ZIndex = statusFrame.ZIndex + 1
		statusLabel.Parent = statusFrame
		track(statusLabel)
		updateStatusPosition()
		for _, box in getCodeBoxes() do
			hookCodeBox(box)
		end
		queueStatusUpdate()
	end

	local normalizingTabs = false
	local managedCloseBound = setmetatable({}, { __mode = "k" })
	local managedCloseBusy = setmetatable({}, { __mode = "k" })
	local normalizeTabSequence

	local function getOrderedTabButtons()
		local entries = {}
		for ordinal, tab in tabsFrame:GetChildren() do
			if tab:IsA("GuiButton") and tab.Name:match("^script%d+%.lua$") then
				table.insert(entries, { tab = tab, ordinal = ordinal })
			end
		end
		table.sort(entries, function(a, b)
			local ao = a.tab.LayoutOrder
			local bo = b.tab.LayoutOrder
			if ao ~= bo then
				return ao < bo
			end
			local ai = tonumber(a.tab.Name:match("%d+")) or math.huge
			local bi = tonumber(b.tab.Name:match("%d+")) or math.huge
			if ai ~= bi then
				return ai < bi
			end
			return a.ordinal < b.ordinal
		end)
		local result = {}
		for _, entry in entries do
			table.insert(result, entry.tab)
		end
		return result
	end

	local function closeManagedTab(tab)
		if not (runtime.alive and tab and tab.Parent) then
			return
		end
		local tabs = getOrderedTabButtons()
		if #tabs <= 1 then
			return
		end
		local index = table.find(tabs, tab)
		if not index then
			return
		end
		local boxes = getCodeBoxes()
		local box = boxes[index]
		local wasVisible = box and box.Visible or false
		if tab.Parent then
			tab:Destroy()
		end
		if box and box.Parent then
			box:Destroy()
		end
		task.defer(function()
			if not runtime.alive then
				return
			end
			normalizeTabSequence()
			if wasVisible then
				local remaining = getCodeBoxes()
				local nextBox = remaining[math.min(index, #remaining)] or remaining[#remaining]
				if nextBox then
					for _, current in remaining do
						current.Visible = current == nextBox
					end
					for _, currentTab in getOrderedTabButtons() do
						currentTab.BackgroundTransparency = currentTab.Name == nextBox.Name and 0 or 1
					end
				end
			end
			queueStatusUpdate()
		end)
	end

	local function bindManagedClose(tab)
		if not (tab and tab:IsA("GuiButton")) or managedCloseBound[tab] then
			return
		end
		local closeButton = tab:FindFirstChild("ImageButton")
		if not (closeButton and closeButton:IsA("GuiButton")) then
			return
		end
		managedCloseBound[tab] = true
		local function activateClose()
			if managedCloseBusy[tab] then
				return
			end
			managedCloseBusy[tab] = true
			closeManagedTab(tab)
			task.delay(0.1, function()
				managedCloseBusy[tab] = nil
			end)
		end
		connect(closeButton.MouseButton1Click, activateClose)
		connect(closeButton.Activated, activateClose)
	end

	local function normalizeSavedTabFiles()
		local directory = tabDirectory
		if
			type(isfolder) ~= "function"
			or type(listfiles) ~= "function"
			or type(readfile) ~= "function"
			or type(writefile) ~= "function"
			or not isfolder(directory)
		then
			return
		end
		local ok, files = pcall(listfiles, directory)
		if not ok or type(files) ~= "table" then
			return
		end
		local saved = {}
		for _, path in files do
			local name = tostring(path):match("([^/\\]+)$")
			local index = name and tonumber(name:match("^script(%d+)%.lua$"))
			if index then
				local readOk, text = pcall(readfile, path)
				if readOk and type(text) == "string" then
					table.insert(saved, { index = index, name = name, text = text })
				end
			end
		end
		table.sort(saved, function(a, b)
			return a.index < b.index
		end)
		local keep = {}
		for index, item in saved do
			local name = "script" .. tostring(index) .. ".lua"
			keep[name] = true
			pcall(writefile, directory .. "/" .. name, item.text)
		end
		if type(delfile) == "function" and type(isfile) == "function" then
			for _, item in saved do
				if not keep[item.name] then
					local path = directory .. "/" .. item.name
					if isfile(path) then
						pcall(delfile, path)
					end
				end
			end
		end
	end

	normalizeTabSequence = function()
		if normalizingTabs or not runtime.alive then
			return
		end
		normalizingTabs = true
		local boxes = getCodeBoxes()
		local tabs = getOrderedTabButtons()
		local usedTabs = setmetatable({}, { __mode = "k" })
		local entries = {}
		local keep = {}
		for index, box in boxes do
			local oldName = box.Name
			local newName = "script" .. tostring(index) .. ".lua"
			keep[newName] = true
			local tab
			for _, candidate in tabs do
				if not usedTabs[candidate] and candidate.Name == oldName then
					tab = candidate
					break
				end
			end
			if not tab then
				for _, candidate in tabs do
					if not usedTabs[candidate] then
						tab = candidate
						break
					end
				end
			end
			if tab then
				usedTabs[tab] = true
			end
			table.insert(entries, {
				box = box,
				tab = tab,
				oldName = oldName,
				newName = newName,
				text = box.Text or "",
			})
		end
		for _, tab in tabs do
			if not usedTabs[tab] and tab.Parent then
				tab:Destroy()
			end
		end
		for index, entry in entries do
			if entry.box.Parent then
				entry.box.Name = entry.newName
			end
			local tab = entry.tab
			if tab and tab.Parent then
				tab.Name = entry.newName
				tab.LayoutOrder = index
				local title = tab:FindFirstChild("Title", true)
				if title and title:IsA("TextLabel") then
					title.Text = entry.newName
				end
				bindManagedClose(tab)
			end
		end
		if type(writefile) == "function" then
			for _, entry in entries do
				pcall(writefile, tabDirectory .. "/" .. entry.newName, entry.text)
			end
		end
		if type(delfile) == "function" and type(isfile) == "function" then
			for _, entry in entries do
				if entry.oldName ~= entry.newName and not keep[entry.oldName] then
					local path = tabDirectory .. "/" .. entry.oldName
					if isfile(path) then
						pcall(delfile, path)
					end
				end
			end
		end
		queueStatusUpdate()
		normalizingTabs = false
	end

	local function savedTabNames()
		normalizeSavedTabFiles()
		local names = {}
		local directory = "DeltaCustom/DeltaTabs"
		if type(isfolder) ~= "function" or type(listfiles) ~= "function" or not isfolder(directory) then
			return names
		end
		local ok, files = pcall(listfiles, directory)
		if not ok or type(files) ~= "table" then
			return names
		end
		for _, path in files do
			local name = tostring(path):match("([^/\\]+)$")
			if name and name:match("^script%d+%.lua$") then
				table.insert(names, name)
			end
		end
		table.sort(names, function(a, b)
			return (tonumber(a:match("%d+")) or math.huge) < (tonumber(b:match("%d+")) or math.huge)
		end)
		return names
	end

	local function fireAddTab(addButton)
		local before = #getCodeBoxes()
		local fired = activateOriginal(addButton)
		if not fired then
			return false
		end
		local deadline = os.clock() + 0.5
		repeat
			task.wait()
		until #getCodeBoxes() > before or os.clock() >= deadline
		return #getCodeBoxes() > before
	end

	local function selectTabByName(name)
		for _, box in getCodeBoxes() do
			box.Visible = box.Name == name
		end
		for _, tab in tabsFrame:GetChildren() do
			if tab:IsA("GuiButton") and tab.Name:match("^script%d+%.lua$") then
				tab.BackgroundTransparency = tab.Name == name and 0 or 1
			end
		end
		queueStatusUpdate()
	end

	local function nextAvailableTabName()
		local used = {}
		for _, box in getCodeBoxes() do
			used[tonumber(box.Name:match("%d+"))] = true
		end
		local index = 1
		while used[index] do
			index += 1
		end
		return "script" .. tostring(index) .. ".lua"
	end

	local function createFallbackTab(name)
		if tabsFrame:FindFirstChild(name) and codeFrame:FindFirstChild(name, true) then
			return true
		end
		local sourceTab
		for _, object in tabsFrame:GetChildren() do
			if object:IsA("GuiButton") and object.Name:match("^script%d+%.lua$") then
				sourceTab = object
				break
			end
		end
		local sourceBox = getCodeBoxes()[1]
		if not (sourceTab and sourceBox) then
			return false
		end
		local index = tonumber(name:match("%d+")) or (#getCodeBoxes() + 1)
		local tab = sourceTab:Clone()
		tab.Name = name
		tab.LayoutOrder = index
		tab.BackgroundTransparency = 1
		removeScripts(tab)
		local title = tab:FindFirstChild("Title", true)
		if title and title:IsA("TextLabel") then
			title.Text = name
		end
		tab.Parent = tabsFrame
		track(tab)
		local box = sourceBox:Clone()
		box.Name = name
		box.Text = ""
		box.Visible = false
		box.Parent = sourceBox.Parent
		track(box)
		connect(tab.MouseButton1Click, function()
			selectTabByName(name)
		end)
		local closeButton = tab:FindFirstChild("ImageButton")
		if closeButton and closeButton:IsA("GuiButton") then
			connect(closeButton.MouseButton1Click, function()
				if #getCodeBoxes() <= 1 then
					return
				end
				local wasVisible = box.Visible
				if type(delfile) == "function" and type(isfile) == "function" then
					local path = tabDirectory .. "/" .. name
					if isfile(path) then
						pcall(delfile, path)
					end
				end
				if tab.Parent then
					tab:Destroy()
				end
				if box.Parent then
					box:Destroy()
				end
				if wasVisible then
					local remaining = getCodeBoxes()[1]
					if remaining then
						selectTabByName(remaining.Name)
					end
				end
				queueStatusUpdate()
			end)
		end
		return true
	end

	local restoringTabs = false
	local function restoreSavedTabs(showResult)
		if restoringTabs or not runtime.alive then
			return
		end
		restoringTabs = true
		normalizeTabSequence()
		local saved = savedTabNames()
		local addButton = tabsFrame:FindFirstChild("AddTab")
		local before = #getCodeBoxes()
		local target = 0
		for _, name in saved do
			target = math.max(target, tonumber(name:match("%d+")) or 0)
		end
		local attemptsMade = 0
		while runtime.alive and #getCodeBoxes() < target and attemptsMade < math.max(target * 3, 8) do
			attemptsMade += 1
			local nextIndex = #getCodeBoxes() + 1
			local created = addButton and fireAddTab(addButton) or false
			if not created then
				created = createFallbackTab("script" .. tostring(nextIndex) .. ".lua")
			end
			if not created then
				break
			end
			task.wait(0.08)
		end
		local boxes = getCodeBoxes()
		if type(isfile) == "function" and type(readfile) == "function" then
			for _, box in boxes do
				local path = "DeltaCustom/DeltaTabs/" .. box.Name
				if isfile(path) then
					local ok, text = pcall(readfile, path)
					if ok and type(text) == "string" then
						box.Text = text
					end
				end
				hookCodeBox(box)
			end
		end
		queueStatusUpdate()
		if showResult then
			local after = #boxes
			local description
			if #saved == 0 then
				description = "No saved tabs were found."
			elseif after >= target then
				description = string.format("Restored %d saved tab%s.", #saved, #saved == 1 and "" or "s")
			else
				description = string.format("Restored %d of %d saved tabs.", math.max(after - before, 0), #saved)
			end
			notify({
				Title = "Delta Customization",
				Description = description,
				Duration = 4,
			})
		end
		restoringTabs = false
	end

	local function findSettingsTemplate()
		local settings = v2Main:FindFirstChild("Settings") or v2Main:FindFirstChild("Settings", true)
		local holder = settings and settings:FindFirstChild("Holder")
		if not holder then
			return nil, nil
		end
		local template
		for _, child in holder:GetChildren() do
			if child:IsA("Frame") and child.Name == "Button" then
				template = child
				break
			end
		end
		return holder, template
	end

	local function createSettingRow(name, titleText, descText, buttonText, callback)
		local holder, template = findSettingsTemplate()
		if not (holder and template) then
			return nil, nil
		end
		local existing = holder:FindFirstChild(name)
		if existing then
			existing:Destroy()
		end
		local row = template:Clone()
		row.Name = name
		row.Visible = true
		row.LayoutOrder = -2
		removeScripts(row)
		local title = row:FindFirstChild("Title", true)
		local desc = row:FindFirstChild("Desc", true)
		if title and title:IsA("TextLabel") then
			title.Text = titleText
		end
		if desc and desc:IsA("TextLabel") then
			desc.Text = descText
		end
		local button = row:FindFirstChild("Button", true)
		if button and button:IsA("GuiObject") then
			setButtonTitle(button, buttonText)
			if button:IsA("GuiButton") then
				button.Active = true
				button.Interactable = true
				local locked = false
				local function activate()
					if locked or not runtime.alive then
						return
					end
					locked = true
					callback()
					task.delay(0.1, function()
						locked = false
					end)
				end
				connect(button.MouseButton1Click, activate)
				connect(button.Activated, activate)
				connect(button.TouchTap, activate)
			else
				connect(button.InputEnded, function(input)
					if
						input.UserInputType == Enum.UserInputType.MouseButton1
						or input.UserInputType == Enum.UserInputType.Touch
					then
						callback()
					end
				end)
			end
		end
		row.Parent = holder
		track(row)
		return row, button
	end

	local sidebarSortMenu
	local sidebarSortList
	local refreshSidebarSortMenu

	local function makeSortButton(parent, text, position, size, callback)
		local button = Instance.new("TextButton")
		button.BackgroundColor3 = Color3.fromRGB(31, 31, 36)
		button.BorderSizePixel = 0
		button.Position = position
		button.Size = size
		button.Font = Enum.Font.GothamMedium
		button.Text = text
		button.TextColor3 = Color3.new(1, 1, 1)
		button.TextSize = 12
		button.AutoButtonColor = true
		button.ZIndex = 10003
		button.Parent = parent
		local corner = Instance.new("UICorner")
		corner.CornerRadius = UDim.new(0, 6)
		corner.Parent = button
		connect(button.Activated, callback)
		return button
	end

	local function ensureSidebarSortMenu()
		if sidebarSortMenu and sidebarSortMenu.Parent then
			return sidebarSortMenu
		end
		local menu = Instance.new("Frame")
		menu.Name = "LT_SidebarSortMenu"
		menu.AnchorPoint = Vector2.new(0.5, 0.5)
		menu.Position = UDim2.fromScale(0.5, 0.5)
		menu.Size = UDim2.fromOffset(390, 520)
		menu.BackgroundColor3 = Color3.fromRGB(18, 18, 22)
		menu.BorderSizePixel = 0
		menu.Visible = false
		menu.ZIndex = 10000
		menu.Parent = v2Main
		track(menu)
		local corner = Instance.new("UICorner")
		corner.CornerRadius = UDim.new(0, 12)
		corner.Parent = menu
		local stroke = Instance.new("UIStroke")
		stroke.Color = Color3.fromRGB(72, 72, 82)
		stroke.Thickness = 1
		stroke.Parent = menu
		local title = Instance.new("TextLabel")
		title.BackgroundTransparency = 1
		title.Position = UDim2.fromOffset(18, 12)
		title.Size = UDim2.new(1, -76, 0, 30)
		title.Font = Enum.Font.GothamBold
		title.Text = "Sidebar button order"
		title.TextColor3 = Color3.new(1, 1, 1)
		title.TextSize = 17
		title.TextXAlignment = Enum.TextXAlignment.Left
		title.ZIndex = 10001
		title.Parent = menu
		local description = Instance.new("TextLabel")
		description.BackgroundTransparency = 1
		description.Position = UDim2.fromOffset(18, 44)
		description.Size = UDim2.new(1, -36, 0, 34)
		description.Font = Enum.Font.Gotham
		description.Text = "Reorders Home, Executor, Scripthub, Music, Console, Settings, and the classic ToggleUI button."
		description.TextColor3 = Color3.fromRGB(178, 178, 188)
		description.TextSize = 12
		description.TextWrapped = true
		description.TextXAlignment = Enum.TextXAlignment.Left
		description.TextYAlignment = Enum.TextYAlignment.Top
		description.ZIndex = 10001
		description.Parent = menu
		makeSortButton(menu, "X", UDim2.new(1, -48, 0, 12), UDim2.fromOffset(34, 30), function()
			menu.Visible = false
		end)
		local list = Instance.new("Frame")
		list.Name = "List"
		list.BackgroundTransparency = 1
		list.Position = UDim2.fromOffset(16, 86)
		list.Size = UDim2.new(1, -32, 1, -142)
		list.ZIndex = 10001
		list.Parent = menu
		local layout = Instance.new("UIListLayout")
		layout.Padding = UDim.new(0, 6)
		layout.SortOrder = Enum.SortOrder.LayoutOrder
		layout.Parent = list
		makeSortButton(menu, "RESET", UDim2.new(0, 16, 1, -44), UDim2.new(1, -32, 0, 32), function()
			sidebarOrder = table.clone(sidebarNames)
			applySidebarOrder()
			saveSidebarOrder()
			if refreshSidebarSortMenu then
				refreshSidebarSortMenu()
			end
		end)
		sidebarSortMenu = menu
		sidebarSortList = list
		return menu
	end

	refreshSidebarSortMenu = function()
		ensureSidebarSortMenu()
		for _, child in sidebarSortList:GetChildren() do
			if child:IsA("Frame") and child.Name:sub(1, 12) == "LT_OrderRow_" then
				child:Destroy()
			end
		end
		for index, name in sidebarOrder do
			local row = Instance.new("Frame")
			row.Name = "LT_OrderRow_" .. name
			row.BackgroundColor3 = Color3.fromRGB(25, 25, 30)
			row.BorderSizePixel = 0
			row.Size = UDim2.new(1, 0, 0, 42)
			row.LayoutOrder = index
			row.ZIndex = 10002
			row.Parent = sidebarSortList
			local corner = Instance.new("UICorner")
			corner.CornerRadius = UDim.new(0, 8)
			corner.Parent = row
			local label = Instance.new("TextLabel")
			label.BackgroundTransparency = 1
			label.Position = UDim2.fromOffset(12, 0)
			label.Size = UDim2.new(1, -126, 1, 0)
			label.Font = Enum.Font.GothamMedium
			label.Text = string.format("%d. %s", index, name)
			label.TextColor3 = Color3.new(1, 1, 1)
			label.TextSize = 13
			label.TextXAlignment = Enum.TextXAlignment.Left
			label.ZIndex = 10003
			label.Parent = row
			makeSortButton(row, "UP", UDim2.new(1, -108, 0.5, -14), UDim2.fromOffset(48, 28), function()
				moveSidebarButton(name, -1)
				refreshSidebarSortMenu()
			end)
			makeSortButton(row, "DOWN", UDim2.new(1, -56, 0.5, -14), UDim2.fromOffset(52, 28), function()
				moveSidebarButton(name, 1)
				refreshSidebarSortMenu()
			end)
		end
	end

	local function createToggleSetting(name, titleText, descText, initial, onChanged)
		local enabled = initial
		local row
		local button
		local function refresh()
			if button and button.Parent then
				local activeColor = Color3.fromRGB(79, 164, 242)
				local sidebar = v2Main:FindFirstChild("Sidebar") or v2Main:FindFirstChild("Sidebar", true)
				local activeValue = sidebar and sidebar:FindFirstChild("ActiveColor")
				if activeValue and activeValue:IsA("Color3Value") then
					activeColor = activeValue.Value
				end
				button.BackgroundColor3 = enabled and activeColor or Color3.fromRGB(30, 30, 30)
				setButtonTitle(button, enabled and "ON" or "OFF")
			end
		end
		row, button = createSettingRow(name, titleText, descText, "", function()
			enabled = not enabled
			refresh()
			onChanged(enabled)
		end)
		refresh()
		return row
	end

	local staleBlur = game:GetService("Lighting"):FindFirstChild("LT_DeltaBlur")
	if staleBlur then
		staleBlur:Destroy()
	end
	local oldSettings = v2Main:FindFirstChild("Settings") or v2Main:FindFirstChild("Settings", true)
	local oldHolder = oldSettings and oldSettings:FindFirstChild("Holder")
	if oldHolder then
		for _, name in { "LT_BackgroundBlur", "LT_BlurStrength" } do
			local row = oldHolder:FindFirstChild(name)
			if row then
				row:Destroy()
			end
		end
	end
	local editorSideMenu = executorRoot:FindFirstChild("Sidemenu")
	local originalEditorSize = executorImage.Size
	local originalEditorPosition = executorImage.Position
	local originalEditorAnchor = executorImage.AnchorPoint
	local originalSideVisible = editorSideMenu and editorSideMenu.Visible
	local originalTabSizes = setmetatable({}, { __mode = "k" })
	local originalEditorText = setmetatable({}, { __mode = "k" })
	local function applyWideEditor()
		if not (executorImage and executorImage.Parent) then
			return
		end
		if wideEditorEnabled then
			if editorSideMenu then
				editorSideMenu.Visible = false
			end
			executorImage.AnchorPoint = Vector2.new(1, originalEditorAnchor.Y)
			executorImage.Position = UDim2.new(1, 0, originalEditorPosition.Y.Scale, originalEditorPosition.Y.Offset)
			executorImage.Size = UDim2.new(0.995, 0, originalEditorSize.Y.Scale, originalEditorSize.Y.Offset)
		else
			if editorSideMenu then
				editorSideMenu.Visible = originalSideVisible
			end
			executorImage.AnchorPoint = originalEditorAnchor
			executorImage.Position = originalEditorPosition
			executorImage.Size = originalEditorSize
		end
		task.defer(updateStatusPosition)
		task.defer(editorCanvas.resizeAll)
	end
	local function applyTabStyle(tab)
		if not (tab and tab:IsA("ImageButton") and tab.Name:match("^script%d+%.lua$")) then
			return
		end
		if originalTabSizes[tab] == nil then
			originalTabSizes[tab] = tab.Size
		end
		if compactTabsEnabled then
			tab.Size = UDim2.new(0, 126, originalTabSizes[tab].Y.Scale, originalTabSizes[tab].Y.Offset)
		else
			tab.Size = originalTabSizes[tab]
		end
		local title = tab:FindFirstChild("Title", true)
		if title and title:IsA("TextLabel") then
			title.TextSize = compactTabsEnabled and 11 or 14
		end
	end
	local function applyCompactTabs()
		for _, tab in tabsFrame:GetChildren() do
			applyTabStyle(tab)
		end
	end
	local function applyEditorStyle(box)
		if not (box and box:IsA("TextBox") and box.Name:match("^script%d+%.lua$")) then
			return
		end
		if originalEditorText[box] == nil then
			originalEditorText[box] = { TextSize = box.TextSize, TextWrapped = box.TextWrapped }
		end
		box.TextSize = editorFontSize
		box.TextWrapped = editorWordWrapEnabled
		editorCanvas.resize(box)
		syntaxHighlighter.sync(box)
	end
	local function applyEditorPreferences()
		for _, box in getCodeBoxes() do
			applyEditorStyle(box)
		end
	end
	addRestorer(function()
		if executorImage and executorImage.Parent then
			executorImage.AnchorPoint = originalEditorAnchor
			executorImage.Position = originalEditorPosition
			executorImage.Size = originalEditorSize
		end
		if editorSideMenu and editorSideMenu.Parent then
			editorSideMenu.Visible = originalSideVisible
		end
		for tab, size in originalTabSizes do
			if tab and tab.Parent then
				tab.Size = size
			end
		end
		for box, values in originalEditorText do
			if box and box.Parent then
				box.TextSize = values.TextSize
				box.TextWrapped = values.TextWrapped
			end
		end
		syntaxHighlighter.restore()
		editorCanvas.restore()
	end)
	connect(tabsFrame.ChildAdded, function(tab)
		task.defer(applyTabStyle, tab)
	end)
	local function createCycleSetting(name, titleText, descText, values, getValue, setValue, formatValue)
		local row
		local button
		local function refresh()
			if button and button.Parent then
				setButtonTitle(button, formatValue(getValue()))
			end
		end
		row, button = createSettingRow(name, titleText, descText, "", function()
			local current = getValue()
			local index = table.find(values, current) or 0
			local nextValue = values[(index % #values) + 1]
			setValue(nextValue)
			refresh()
		end)
		refresh()
		return row
	end


	local newUi = {
		enabled = readBool("NewDeltaUI", false),
		open = true,
		activePage = "Executor",
		applying = false,
		railCollapsed = false,
		originals = setmetatable({}, { __mode = "k" }),
		created = {},
		connections = {},
		tabConnections = {},
		locks = {},
		detached = {},
		pageNames = { "Home", "Executor", "Scripthub", "Music", "Console", "Settings" },
		pageButtons = {},
		codeBound = setmetatable({}, { __mode = "k" }),
	}

	newUi.colors = {
		panelTop = Color3.fromRGB(32, 48, 59),
		panelMiddle = Color3.fromRGB(27, 38, 45),
		panelBottom = Color3.fromRGB(22, 32, 38),
		railTop = Color3.fromRGB(31, 46, 57),
		railBottom = Color3.fromRGB(22, 33, 40),
		stroke = Color3.fromRGB(67, 91, 108),
		button = Color3.fromRGB(34, 48, 61),
		buttonStroke = Color3.fromRGB(67, 91, 108),
		active = Color3.fromRGB(0, 120, 255),
		text = Color3.fromRGB(247, 249, 252),
		muted = Color3.fromRGB(218, 225, 232),
	}

	newUi.pageSet = {}
	for _, pageName in newUi.pageNames do
		newUi.pageSet[pageName] = true
	end

	newUi.getIconApi = function()
		local iconApi = rawget(__dcm_env, "DeltaIcon")
		if type(iconApi) == "table" then
			return iconApi
		end
		return nil
	end

	newUi.getCurrentSectionName = function()
		local iconApi = newUi.getIconApi()
		if iconApi and type(iconApi.getCurrentSectionName) == "function" then
			local ok, pageName = pcall(iconApi.getCurrentSectionName)
			if ok and type(pageName) == "string" and newUi.pageSet[pageName] then
				return pageName
			end
		end
		for _, pageName in newUi.pageNames do
			local page = newUi.getPage and newUi.getPage(pageName)
			if page and page.Visible then
				return pageName
			end
		end
		return nil
	end

	newUi.setIconHidden = function(hidden)
		local iconApi = newUi.getIconApi()
		if iconApi and type(iconApi.setForcedHidden) == "function" then
			local ok = pcall(iconApi.setForcedHidden, hidden and true or false)
			if ok then
				return
			end
		end
		if iconApi and type(iconApi.getButton) == "function" then
			local ok, button = pcall(iconApi.getButton)
			if ok and button and button:IsA("GuiObject") then
				button.Visible = not hidden
			end
		end
	end

	newUi.setClassicOpen = function(open)
		local iconApi = newUi.getIconApi()
		local callback = iconApi and (open and iconApi.openClassic or iconApi.closeClassic)
		if type(callback) == "function" then
			local ok = pcall(callback)
			if ok then
				return
			end
		end
		for _, pageName in newUi.pageNames do
			local page = newUi.getPage and newUi.getPage(pageName)
			if page then
				page.Visible = open and pageName == newUi.activePage
			end
		end
		newUi.setIconHidden(open)
	end

	newUi.capture = function(object, properties)
		if not object then
			return
		end
		local state = newUi.originals[object]
		if not state then
			state = {}
			newUi.originals[object] = state
		end
		for _, property in properties do
			if state[property] == nil then
				local ok, value = pcall(function()
					return object[property]
				end)
				if ok then
					state[property] = { value = value }
				end
			end
		end
	end

	newUi.connect = function(signal, callback)
		local ok, connection = pcall(function()
			return signal:Connect(callback)
		end)
		if ok and connection then
			table.insert(newUi.connections, connection)
		end
		return connection
	end

	newUi.connectTab = function(signal, callback)
		local ok, connection = pcall(function()
			return signal:Connect(callback)
		end)
		if ok and connection then
			table.insert(newUi.tabConnections, connection)
		end
		return connection
	end

	newUi.bindClick = function(button, callback)
		if not (button and button:IsA("GuiButton") and type(callback) == "function") then
			return nil
		end
		local locked = false
		return newUi.connect(button.Activated, function()
			if locked or not (newUi.enabled and newUi.applied) then
				return
			end
			locked = true
			callback()
			task.delay(0.08, function()
				locked = false
			end)
		end)
	end

	newUi.bindTabClick = function(button, callback)
		if not (button and button:IsA("GuiButton") and type(callback) == "function") then
			return nil
		end
		local locked = false
		return newUi.connectTab(button.Activated, function()
			if locked or not (newUi.enabled and newUi.applied) then
				return
			end
			locked = true
			callback()
			task.delay(0.08, function()
				locked = false
			end)
		end)
	end

	newUi.make = function(className, name, parent)
		local object = Instance.new(className)
		object.Name = name
		object.Parent = parent
		table.insert(newUi.created, object)
		track(object)
		return object
	end

	newUi.makeTransient = function(className, name, parent)
		local object = Instance.new(className)
		object.Name = name
		object.Parent = parent
		return object
	end

	newUi.ensureCorner = function(object, radius)
		local corner = object:FindFirstChildOfClass("UICorner")
		if corner then
			newUi.capture(corner, { "CornerRadius" })
		else
			corner = newUi.make("UICorner", "LT_NewUICorner", object)
		end
		corner.CornerRadius = UDim.new(0, radius)
		return corner
	end

	newUi.ensureStroke = function(object, color, transparency, thickness)
		local stroke = object:FindFirstChildOfClass("UIStroke")
		if stroke then
			newUi.capture(stroke, { "Color", "Transparency", "Thickness", "Enabled" })
		else
			stroke = newUi.make("UIStroke", "LT_NewUIStroke", object)
		end
		stroke.Color = color
		stroke.Transparency = transparency
		stroke.Thickness = thickness
		stroke.Enabled = true
		return stroke
	end

	newUi.makeCorner = function(object, radius, transient)
		local corner = transient and newUi.makeTransient("UICorner", "Corner", object)
			or newUi.make("UICorner", "Corner", object)
		corner.CornerRadius = UDim.new(0, radius)
		return corner
	end

	newUi.makeStroke = function(object, color, transparency, thickness, transient)
		local stroke = transient and newUi.makeTransient("UIStroke", "Stroke", object)
			or newUi.make("UIStroke", "Stroke", object)
		stroke.Color = color
		stroke.Transparency = transparency
		stroke.Thickness = thickness
		return stroke
	end

	newUi.lock = function(object, property, resolver)
		if not object then
			return nil
		end
		newUi.capture(object, { property })
		local state = {
			object = object,
			property = property,
			resolver = resolver,
			busy = false,
		}
		state.apply = function()
			if state.busy or not (newUi.enabled and newUi.applied and object.Parent) then
				return
			end
			local value = type(resolver) == "function" and resolver() or resolver
			local ok, current = pcall(function()
				return object[property]
			end)
			if ok and current ~= value then
				state.busy = true
				pcall(function()
					object[property] = value
				end)
				state.busy = false
			end
		end
		table.insert(newUi.locks, state)
		newUi.connect(object:GetPropertyChangedSignal(property), function()
			if not state.busy then
				task.defer(state.apply)
			end
		end)
		state.apply()
		return state
	end

	newUi.applyLocks = function()
		for _, state in newUi.locks do
			state.apply()
		end
	end

	newUi.getPage = function(pageName)
		local page = v2Main:FindFirstChild(pageName)
		if page and page:IsA("GuiObject") then
			return page
		end
		return nil
	end

	newUi.getOrderedPages = function()
		local result = {}
		local used = {}
		for _, pageName in sidebarOrder do
			if newUi.pageSet[pageName] and newUi.getPage(pageName) and not used[pageName] then
				used[pageName] = true
				table.insert(result, pageName)
			end
		end
		for _, pageName in newUi.pageNames do
			if newUi.getPage(pageName) and not used[pageName] then
				used[pageName] = true
				table.insert(result, pageName)
			end
		end
		return result
	end

	newUi.findImage = function(object)
		if not object then
			return nil
		end
		for _, descendant in object:GetDescendants() do
			if
				(descendant:IsA("ImageLabel") or descendant:IsA("ImageButton"))
				and type(descendant.Image) == "string"
				and descendant.Image ~= ""
			then
				return descendant
			end
		end
		return nil
	end

	newUi.findSourceIcon = function(pageName)
		local sourceButton = sidebar and sidebar:FindFirstChild(pageName)
		return newUi.findImage(sourceButton)
	end

	newUi.copyIcon = function(source, parent, size, zIndex, transient)
		local icon = transient and newUi.makeTransient("ImageLabel", "Icon", parent)
			or newUi.make("ImageLabel", "Icon", parent)
		icon.AnchorPoint = Vector2.new(0.5, 0.5)
		icon.Position = UDim2.fromScale(0.5, 0.5)
		icon.Size = UDim2.fromOffset(size, size)
		icon.BackgroundTransparency = 1
		icon.BorderSizePixel = 0
		icon.ScaleType = Enum.ScaleType.Fit
		icon.ImageColor3 = Color3.new(1, 1, 1)
		icon.ImageTransparency = 0
		icon.ZIndex = zIndex
		if source then
			pcall(function()
				icon.Image = source.Image
			end)
			pcall(function()
				icon.ImageRectOffset = source.ImageRectOffset
				icon.ImageRectSize = source.ImageRectSize
			end)
			pcall(function()
				icon.ResampleMode = source.ResampleMode
			end)
		end
		local constraint = transient and newUi.makeTransient("UIAspectRatioConstraint", "Aspect", icon)
			or newUi.make("UIAspectRatioConstraint", "Aspect", icon)
		constraint.AspectRatio = 1
		constraint.DominantAxis = Enum.DominantAxis.Height
		return icon
	end

	newUi.makeXIcon = function(parent, size, color, zIndex, transient)
		local holder = transient and newUi.makeTransient("Frame", "Icon", parent)
			or newUi.make("Frame", "Icon", parent)
		holder.AnchorPoint = Vector2.new(0.5, 0.5)
		holder.Position = UDim2.fromScale(0.5, 0.5)
		holder.Size = UDim2.fromOffset(size, size)
		holder.BackgroundTransparency = 1
		holder.ZIndex = zIndex
		for index, rotation in { 45, -45 } do
			local line = transient and newUi.makeTransient("Frame", "Line" .. index, holder)
				or newUi.make("Frame", "Line" .. index, holder)
			line.AnchorPoint = Vector2.new(0.5, 0.5)
			line.Position = UDim2.fromScale(0.5, 0.5)
			line.Size = UDim2.fromOffset(2, math.floor(size * 0.72))
			line.BackgroundColor3 = color
			line.BorderSizePixel = 0
			line.Rotation = rotation
			line.ZIndex = zIndex
			if transient then
				newUi.makeCorner(line, 1, true)
			else
				newUi.makeCorner(line, 1, false)
			end
		end
		return holder
	end

	newUi.makeDocumentIcon = function(parent, size, color, zIndex, withPlus, transient)
		local holder = transient and newUi.makeTransient("Frame", "DocumentIcon", parent)
			or newUi.make("Frame", "DocumentIcon", parent)
		holder.AnchorPoint = Vector2.new(0.5, 0.5)
		holder.Position = UDim2.fromScale(0.5, 0.5)
		holder.Size = UDim2.fromOffset(size, size)
		holder.BackgroundTransparency = 1
		holder.ZIndex = zIndex
		local body = transient and newUi.makeTransient("Frame", "Document", holder)
			or newUi.make("Frame", "Document", holder)
		body.AnchorPoint = Vector2.new(0.5, 0.5)
		body.Position = UDim2.fromScale(0.5, 0.48)
		body.Size = UDim2.fromScale(0.58, 0.72)
		body.BackgroundTransparency = 1
		body.ZIndex = zIndex
		newUi.makeCorner(body, math.max(2, math.floor(size * 0.08)), transient)
		newUi.makeStroke(body, color, 0, math.max(1.5, size * 0.075), transient)
		local fold = transient and newUi.makeTransient("Frame", "Fold", holder)
			or newUi.make("Frame", "Fold", holder)
		fold.AnchorPoint = Vector2.new(1, 0)
		fold.Position = UDim2.fromScale(0.79, 0.18)
		fold.Size = UDim2.fromScale(0.22, 0.22)
		fold.BackgroundColor3 = newUi.colors.panelTop
		fold.BorderSizePixel = 0
		fold.Rotation = 45
		fold.ZIndex = zIndex + 1
		if withPlus then
			local plusHolder = transient and newUi.makeTransient("Frame", "Plus", holder)
				or newUi.make("Frame", "Plus", holder)
			plusHolder.AnchorPoint = Vector2.new(0.5, 0.5)
			plusHolder.Position = UDim2.fromScale(0.27, 0.75)
			plusHolder.Size = UDim2.fromScale(0.42, 0.42)
			plusHolder.BackgroundColor3 = newUi.colors.active
			plusHolder.BorderSizePixel = 0
			plusHolder.ZIndex = zIndex + 2
			newUi.makeCorner(plusHolder, math.floor(size * 0.2), transient)
			for index, value in { Vector2.new(0.58, 0.12), Vector2.new(0.12, 0.58) } do
				local line = transient and newUi.makeTransient("Frame", "PlusLine" .. index, plusHolder)
					or newUi.make("Frame", "PlusLine" .. index, plusHolder)
				line.AnchorPoint = Vector2.new(0.5, 0.5)
				line.Position = UDim2.fromScale(0.5, 0.5)
				line.Size = UDim2.fromScale(value.X, value.Y)
				line.BackgroundColor3 = Color3.new(1, 1, 1)
				line.BorderSizePixel = 0
				line.ZIndex = zIndex + 3
				newUi.makeCorner(line, 1, transient)
			end
		end
		return holder
	end

	newUi.makePlayIcon = function(parent, size, color, zIndex, transient, withRing)
		local holder = transient and newUi.makeTransient("Frame", "PlayIcon", parent)
			or newUi.make("Frame", "PlayIcon", parent)
		holder.AnchorPoint = Vector2.new(0.5, 0.5)
		holder.Position = UDim2.fromScale(0.5, 0.5)
		holder.Size = UDim2.fromOffset(size, size)
		holder.BackgroundTransparency = 1
		holder.ZIndex = zIndex
		if withRing then
			local ring = transient and newUi.makeTransient("Frame", "Ring", holder)
				or newUi.make("Frame", "Ring", holder)
			ring.AnchorPoint = Vector2.new(0.5, 0.5)
			ring.Position = UDim2.fromScale(0.5, 0.5)
			ring.Size = UDim2.fromScale(0.9, 0.9)
			ring.BackgroundTransparency = 1
			ring.ZIndex = zIndex
			newUi.makeCorner(ring, size, transient)
			newUi.makeStroke(ring, color, 0, math.max(1.4, size * 0.075), transient)
		end
		local arrow = transient and newUi.makeTransient("TextLabel", "Arrow", holder)
			or newUi.make("TextLabel", "Arrow", holder)
		arrow.AnchorPoint = Vector2.new(0.5, 0.5)
		arrow.Position = UDim2.fromScale(withRing and 0.53 or 0.5, 0.48)
		arrow.Size = UDim2.fromScale(0.7, 0.8)
		arrow.BackgroundTransparency = 1
		arrow.Font = Enum.Font.GothamBold
		arrow.Text = ">"
		arrow.TextColor3 = color
		arrow.TextSize = math.floor(size * (withRing and 0.58 or 0.72))
		arrow.ZIndex = zIndex + 1
		return holder
	end

	newUi.makeTrashIcon = function(parent, size, color, zIndex, transient)
		local holder = transient and newUi.makeTransient("Frame", "TrashIcon", parent)
			or newUi.make("Frame", "TrashIcon", parent)
		holder.AnchorPoint = Vector2.new(0.5, 0.5)
		holder.Position = UDim2.fromScale(0.5, 0.5)
		holder.Size = UDim2.fromOffset(size, size)
		holder.BackgroundTransparency = 1
		holder.ZIndex = zIndex
		local body = transient and newUi.makeTransient("Frame", "Body", holder)
			or newUi.make("Frame", "Body", holder)
		body.AnchorPoint = Vector2.new(0.5, 1)
		body.Position = UDim2.fromScale(0.5, 0.92)
		body.Size = UDim2.fromScale(0.58, 0.58)
		body.BackgroundTransparency = 1
		body.ZIndex = zIndex
		newUi.makeCorner(body, math.max(2, math.floor(size * 0.08)), transient)
		newUi.makeStroke(body, color, 0, math.max(1.4, size * 0.07), transient)
		local lid = transient and newUi.makeTransient("Frame", "Lid", holder)
			or newUi.make("Frame", "Lid", holder)
		lid.AnchorPoint = Vector2.new(0.5, 0.5)
		lid.Position = UDim2.fromScale(0.5, 0.27)
		lid.Size = UDim2.fromScale(0.72, 0.08)
		lid.BackgroundColor3 = color
		lid.BorderSizePixel = 0
		lid.ZIndex = zIndex + 1
		newUi.makeCorner(lid, 2, transient)
		local handle = transient and newUi.makeTransient("Frame", "Handle", holder)
			or newUi.make("Frame", "Handle", holder)
		handle.AnchorPoint = Vector2.new(0.5, 1)
		handle.Position = UDim2.fromScale(0.5, 0.23)
		handle.Size = UDim2.fromScale(0.28, 0.14)
		handle.BackgroundTransparency = 1
		handle.ZIndex = zIndex + 1
		newUi.makeCorner(handle, 2, transient)
		newUi.makeStroke(handle, color, 0, math.max(1.2, size * 0.06), transient)
		for index, x in { 0.4, 0.6 } do
			local line = transient and newUi.makeTransient("Frame", "Slot" .. index, body)
				or newUi.make("Frame", "Slot" .. index, body)
			line.AnchorPoint = Vector2.new(0.5, 0.5)
			line.Position = UDim2.fromScale(x, 0.53)
			line.Size = UDim2.fromScale(0.08, 0.55)
			line.BackgroundColor3 = color
			line.BorderSizePixel = 0
			line.ZIndex = zIndex + 1
			newUi.makeCorner(line, 1, transient)
		end
		return holder
	end

	newUi.makeClipboardIcon = function(parent, size, color, zIndex, transient, withPlay)
		local holder = transient and newUi.makeTransient("Frame", "ClipboardIcon", parent)
			or newUi.make("Frame", "ClipboardIcon", parent)
		holder.AnchorPoint = Vector2.new(0.5, 0.5)
		holder.Position = UDim2.fromScale(0.5, 0.5)
		holder.Size = UDim2.fromOffset(size, size)
		holder.BackgroundTransparency = 1
		holder.ZIndex = zIndex
		local body = transient and newUi.makeTransient("Frame", "Body", holder)
			or newUi.make("Frame", "Body", holder)
		body.AnchorPoint = Vector2.new(0.5, 0.5)
		body.Position = UDim2.fromScale(withPlay and 0.46 or 0.5, 0.54)
		body.Size = UDim2.fromScale(0.62, 0.72)
		body.BackgroundTransparency = 1
		body.ZIndex = zIndex
		newUi.makeCorner(body, math.max(2, math.floor(size * 0.08)), transient)
		newUi.makeStroke(body, color, 0, math.max(1.4, size * 0.07), transient)
		local clip = transient and newUi.makeTransient("Frame", "Clip", holder)
			or newUi.make("Frame", "Clip", holder)
		clip.AnchorPoint = Vector2.new(0.5, 0.5)
		clip.Position = UDim2.fromScale(withPlay and 0.46 or 0.5, 0.2)
		clip.Size = UDim2.fromScale(0.34, 0.17)
		clip.BackgroundColor3 = newUi.colors.button
		clip.BorderSizePixel = 0
		clip.ZIndex = zIndex + 1
		newUi.makeCorner(clip, math.max(2, math.floor(size * 0.07)), transient)
		newUi.makeStroke(clip, color, 0, math.max(1.2, size * 0.06), transient)
		if withPlay then
			local badge = transient and newUi.makeTransient("Frame", "PlayBadge", holder)
				or newUi.make("Frame", "PlayBadge", holder)
			badge.AnchorPoint = Vector2.new(0.5, 0.5)
			badge.Position = UDim2.fromScale(0.76, 0.73)
			badge.Size = UDim2.fromScale(0.48, 0.48)
			badge.BackgroundColor3 = newUi.colors.active
			badge.BorderSizePixel = 0
			badge.ZIndex = zIndex + 2
			newUi.makeCorner(badge, size, transient)
			newUi.makePlayIcon(badge, math.floor(size * 0.34), Color3.new(1, 1, 1), zIndex + 3, transient, false)
		end
		return holder
	end

	newUi.makeMusicIcon = function(parent, size, color, zIndex, transient)
		local holder = transient and newUi.makeTransient("Frame", "MusicIcon", parent)
			or newUi.make("Frame", "MusicIcon", parent)
		holder.AnchorPoint = Vector2.new(0.5, 0.5)
		holder.Position = UDim2.fromScale(0.5, 0.5)
		holder.Size = UDim2.fromOffset(size, size)
		holder.BackgroundTransparency = 1
		holder.ZIndex = zIndex
		local stem = transient and newUi.makeTransient("Frame", "Stem", holder)
			or newUi.make("Frame", "Stem", holder)
		stem.AnchorPoint = Vector2.new(0.5, 0)
		stem.Position = UDim2.fromScale(0.62, 0.13)
		stem.Size = UDim2.fromScale(0.11, 0.58)
		stem.BackgroundColor3 = color
		stem.BorderSizePixel = 0
		stem.ZIndex = zIndex
		newUi.makeCorner(stem, 2, transient)
		local beam = transient and newUi.makeTransient("Frame", "Beam", holder)
			or newUi.make("Frame", "Beam", holder)
		beam.AnchorPoint = Vector2.new(1, 0)
		beam.Position = UDim2.fromScale(0.68, 0.13)
		beam.Size = UDim2.fromScale(0.43, 0.1)
		beam.BackgroundColor3 = color
		beam.BorderSizePixel = 0
		beam.Rotation = -8
		beam.ZIndex = zIndex
		newUi.makeCorner(beam, 2, transient)
		local note = transient and newUi.makeTransient("Frame", "Note", holder)
			or newUi.make("Frame", "Note", holder)
		note.AnchorPoint = Vector2.new(0.5, 0.5)
		note.Position = UDim2.fromScale(0.45, 0.75)
		note.Size = UDim2.fromScale(0.36, 0.28)
		note.BackgroundColor3 = color
		note.BorderSizePixel = 0
		note.Rotation = -12
		note.ZIndex = zIndex
		newUi.makeCorner(note, size, transient)
		return holder
	end

	newUi.makeChevronIcon = function(parent, size, color, zIndex, transient)
		local holder = transient and newUi.makeTransient("Frame", "ChevronIcon", parent)
			or newUi.make("Frame", "ChevronIcon", parent)
		holder.AnchorPoint = Vector2.new(0.5, 0.5)
		holder.Position = UDim2.fromScale(0.5, 0.5)
		holder.Size = UDim2.fromOffset(size, size)
		holder.BackgroundTransparency = 1
		holder.ZIndex = zIndex
		for index = 1, 2 do
			local line = transient and newUi.makeTransient("Frame", "Line" .. index, holder)
				or newUi.make("Frame", "Line" .. index, holder)
			line.AnchorPoint = Vector2.new(0.5, 0.5)
			line.Size = UDim2.fromOffset(2, math.floor(size * 0.55))
			line.BackgroundColor3 = color
			line.BorderSizePixel = 0
			line.ZIndex = zIndex
			newUi.makeCorner(line, 1, transient)
		end
		return holder
	end

	newUi.setChevronDirection = function(holder, pointsRight)
		if not holder then
			return
		end
		local first = holder:FindFirstChild("Line1")
		local second = holder:FindFirstChild("Line2")
		if first then
			first.Position = UDim2.fromScale(0.5, 0.37)
			first.Rotation = pointsRight and -42 or 42
		end
		if second then
			second.Position = UDim2.fromScale(0.5, 0.63)
			second.Rotation = pointsRight and 42 or -42
		end
	end

	newUi.makeCopyIcon = function(parent, size, color, zIndex, transient)
		local holder = transient and newUi.makeTransient("Frame", "CopyIcon", parent)
			or newUi.make("Frame", "CopyIcon", parent)
		holder.AnchorPoint = Vector2.new(0.5, 0.5)
		holder.Position = UDim2.fromScale(0.5, 0.5)
		holder.Size = UDim2.fromOffset(size, size)
		holder.BackgroundTransparency = 1
		holder.ZIndex = zIndex
		local back = transient and newUi.makeTransient("Frame", "Back", holder)
			or newUi.make("Frame", "Back", holder)
		back.AnchorPoint = Vector2.new(0.5, 0.5)
		back.Position = UDim2.fromScale(0.62, 0.38)
		back.Size = UDim2.fromScale(0.58, 0.64)
		back.BackgroundColor3 = newUi.colors.button
		back.BorderSizePixel = 0
		back.ZIndex = zIndex
		newUi.makeCorner(back, math.max(2, math.floor(size * 0.08)), transient)
		newUi.makeStroke(back, color, 0, math.max(1.3, size * 0.065), transient)
		local front = transient and newUi.makeTransient("Frame", "Front", holder)
			or newUi.make("Frame", "Front", holder)
		front.AnchorPoint = Vector2.new(0.5, 0.5)
		front.Position = UDim2.fromScale(0.4, 0.62)
		front.Size = UDim2.fromScale(0.58, 0.64)
		front.BackgroundColor3 = newUi.colors.button
		front.BorderSizePixel = 0
		front.ZIndex = zIndex + 1
		newUi.makeCorner(front, math.max(2, math.floor(size * 0.08)), transient)
		newUi.makeStroke(front, color, 0, math.max(1.3, size * 0.065), transient)
		return holder
	end

	newUi.makeActionIcon = function(kind, parent, size, color, zIndex, transient)
		if kind == "Execute" then
			return newUi.makePlayIcon(parent, size, color, zIndex, transient, true)
		elseif kind == "Clear" then
			return newUi.makeTrashIcon(parent, size, color, zIndex, transient)
		elseif kind == "ExecuteClipboard" then
			return newUi.makeClipboardIcon(parent, size, color, zIndex, transient, true)
		elseif kind == "Copy" then
			return newUi.makeCopyIcon(parent, size, color, zIndex, transient)
		end
		return newUi.makeClipboardIcon(parent, size, color, zIndex, transient, false)
	end

	newUi.createNavButton = function(pageName)
		local button = newUi.make("ImageButton", "LT_NewUINav_" .. pageName, newUi.navBar)
		button.Size = UDim2.fromOffset(64, 64)
		button.BackgroundColor3 = newUi.colors.active
		button.BackgroundTransparency = 1
		button.BorderSizePixel = 0
		button.AutoButtonColor = false
		button.Image = ""
		button.ZIndex = 12002
		newUi.makeCorner(button, 32, false)
		local source = newUi.findSourceIcon(pageName)
		local icon
		if source then
			icon = newUi.copyIcon(source, button, 25, 12003, false)
		else
			if pageName == "Music" then
				icon = newUi.makeMusicIcon(button, 27, Color3.new(1, 1, 1), 12003, false)
			else
				icon = newUi.make("TextLabel", "Icon", button)
				icon.AnchorPoint = Vector2.new(0.5, 0.5)
				icon.Position = UDim2.fromScale(0.5, 0.5)
				icon.Size = UDim2.fromOffset(32, 32)
				icon.BackgroundTransparency = 1
				icon.Font = pageName == "Executor" and Enum.Font.Code or Enum.Font.GothamBold
				icon.Text = pageName == "Executor" and ">_" or pageName:sub(1, 1)
				icon.TextColor3 = Color3.new(1, 1, 1)
				icon.TextSize = pageName == "Executor" and 18 or 20
				icon.ZIndex = 12003
			end
		end
		newUi.pageButtons[pageName] = {
			button = button,
			icon = icon,
		}
		newUi.bindClick(button, function()
			newUi.showPage(pageName)
		end)
		return button
	end

	newUi.refreshOrder = function()
		if not (newUi.navBar and newUi.navBar.Parent) then
			return
		end
		local ordered = newUi.getOrderedPages()
		for index, pageName in ordered do
			local entry = newUi.pageButtons[pageName]
			if entry and entry.button then
				entry.button.LayoutOrder = index
			end
		end
		local width = (#ordered * 64) + (math.max(#ordered - 1, 0) * 4) + 24
		newUi.navBar.Size = UDim2.fromOffset(width, 80)
		if newUi.closeButton then
			newUi.closeButton.Position = UDim2.new(0.53, -(math.floor(width / 2) + 49), 0.015, 0)
		end
	end

	newUi.refreshNav = function()
		local visible = newUi.enabled and newUi.applied and newUi.open
		if newUi.navBar then
			newUi.navBar.Visible = visible
		end
		if newUi.closeButton then
			newUi.closeButton.Visible = visible
		end
		if newUi.rail then
			newUi.rail.Visible = visible and newUi.activePage == "Executor"
		end
		for pageName, entry in newUi.pageButtons do
			local active = visible and newUi.activePage == pageName
			entry.button.BackgroundTransparency = active and 0 or 1
			if entry.icon:IsA("ImageLabel") then
				entry.icon.ImageColor3 = Color3.new(1, 1, 1)
				entry.icon.ImageTransparency = active and 0 or 0.1
			elseif entry.icon:IsA("TextLabel") then
				entry.icon.TextColor3 = Color3.new(1, 1, 1)
				entry.icon.TextTransparency = active and 0 or 0.1
			end
		end
	end

	newUi.syncPages = function()
		if not (newUi.enabled and newUi.applied) then
			return
		end
		newUi.applying = true
		for _, pageName in newUi.pageNames do
			local page = newUi.getPage(pageName)
			if page then
				page.Visible = newUi.open and pageName == newUi.activePage
			end
		end
		if sidebar and sidebar.Parent then
			sidebar.Visible = false
		end
		newUi.applying = false
		newUi.refreshNav()
		newUi.setIconHidden(newUi.open)
	end

	newUi.showPage = function(pageName)
		if not (newUi.enabled and newUi.applied and newUi.pageSet[pageName]) then
			return
		end
		newUi.activePage = pageName
		newUi.open = true
		newUi.syncPages()
		newUi.applyLocks()
		if pageName == "Executor" then
			newUi.rebuildTabs()
			task.defer(editorCanvas.resizeAll)
			task.defer(updateStatusPosition)
		end
	end

	newUi.setOpen = function(open)
		if not (newUi.enabled and newUi.applied) then
			return
		end
		newUi.open = open and true or false
		newUi.syncPages()
		newUi.applyLocks()
	end

	newUi.updateLineNumbers = function()
		if not (newUi.lineGutter and newUi.lineNumbers and newUi.enabled and newUi.applied) then
			return
		end
		local box = getActiveCodeBox()
		if not box then
			newUi.lineNumbers.Text = ""
			return
		end
		local text = box.Text or ""
		local _, breaks = text:gsub("\n", "\n")
		local count = math.min(breaks + 1, 5000)
		local numbers = table.create(count)
		for index = 1, count do
			numbers[index] = tostring(index)
		end
		local lineHeight = math.max(1, box.LineHeight)
		newUi.lineNumbers.Text = table.concat(numbers, "\n")
		newUi.lineNumbers.TextSize = box.TextSize
		newUi.lineNumbers.LineHeight = lineHeight
		newUi.lineNumbers.Position = UDim2.fromOffset(0, 6 - codeFrame.CanvasPosition.Y)
		newUi.lineNumbers.Size = UDim2.new(1, -4, 0, math.max(newUi.lineGutter.AbsoluteSize.Y, math.ceil(count * box.TextSize * lineHeight) + 20))
	end

	newUi.clearTabConnections = function()
		for i = #newUi.tabConnections, 1, -1 do
			pcall(function()
				newUi.tabConnections[i]:Disconnect()
			end)
		end
		table.clear(newUi.tabConnections)
	end

	newUi.updateTabCanvas = function()
		if not (newUi.tabBar and newUi.tabLayout) then
			return
		end
		newUi.tabBar.CanvasSize = UDim2.fromOffset(newUi.tabLayout.AbsoluteContentSize.X + 4, 0)
	end

	newUi.getNativeTabTitle = function(tab)
		local title = tab and (tab:FindFirstChild("Title", true) or tab:FindFirstChildWhichIsA("TextLabel", true))
		local value = title and title:IsA("TextLabel") and title.Text ~= "" and title.Text or tab and tab.Name or "New tab"
		local index = tostring(value):match("^script(%d+)%.lua$")
		if index then
			return tonumber(index) == 1 and "New tab" or "New tab " .. index
		end
		return value
	end

	newUi.getNativeClose = function(tab)
		if not tab then
			return nil
		end
		for _, descendant in tab:GetDescendants() do
			if descendant:IsA("GuiButton") then
				return descendant
			end
		end
		return nil
	end

	newUi.rebuildTabs = function()
		if not (newUi.enabled and newUi.applied and newUi.tabBar and newUi.tabBar.Parent) then
			return
		end
		newUi.clearTabConnections()
		for _, child in newUi.tabBar:GetChildren() do
			if child:GetAttribute("LT_CustomTab") then
				child:Destroy()
			end
		end
		local nativeTabs = {}
		for _, tab in tabsFrame:GetChildren() do
			if tab:IsA("GuiButton") and tab.Name:match("^script%d+%.lua$") then
				table.insert(nativeTabs, tab)
			end
		end
		table.sort(nativeTabs, function(a, b)
			return (a.LayoutOrder ~= b.LayoutOrder and a.LayoutOrder < b.LayoutOrder)
				or (a.LayoutOrder == b.LayoutOrder and a.Name < b.Name)
		end)
		for index, nativeTab in nativeTabs do
			local box = codeFrame:FindFirstChild(nativeTab.Name, true)
			local active = box and box:IsA("TextBox") and box.Visible
			local button = newUi.makeTransient("ImageButton", nativeTab.Name, newUi.tabBar)
			button:SetAttribute("LT_CustomTab", true)
			button.Size = UDim2.fromOffset(184, 54)
			button.LayoutOrder = index
			button.BackgroundColor3 = active and newUi.colors.active or newUi.colors.button
			button.BackgroundTransparency = active and 0 or 0.12
			button.BorderSizePixel = 0
			button.AutoButtonColor = false
			button.Image = ""
			button.ZIndex = 12010
			newUi.makeCorner(button, 16, true)
			if not active then
				newUi.makeStroke(button, newUi.colors.buttonStroke, 0.5, 1, true)
			end
			local documentHolder = newUi.makeTransient("Frame", "DocumentHolder", button)
			documentHolder.AnchorPoint = Vector2.new(0, 0.5)
			documentHolder.Position = UDim2.new(0, 14, 0.5, 0)
			documentHolder.Size = UDim2.fromOffset(24, 24)
			documentHolder.BackgroundTransparency = 1
			documentHolder.ZIndex = 12011
			newUi.makeDocumentIcon(documentHolder, 22, Color3.new(1, 1, 1), 12012, true, true)
			local title = newUi.makeTransient("TextLabel", "Title", button)
			title.AnchorPoint = Vector2.new(0, 0.5)
			title.Position = UDim2.new(0, 45, 0.5, 0)
			title.Size = UDim2.new(1, -78, 1, 0)
			title.BackgroundTransparency = 1
			title.Font = Enum.Font.GothamMedium
			title.Text = newUi.getNativeTabTitle(nativeTab)
			title.TextColor3 = newUi.colors.text
			title.TextSize = 15
			title.TextXAlignment = Enum.TextXAlignment.Left
			title.TextTruncate = Enum.TextTruncate.AtEnd
			title.ZIndex = 12011
			local close = newUi.makeTransient("ImageButton", "Close", button)
			close.AnchorPoint = Vector2.new(1, 0.5)
			close.Position = UDim2.new(1, -10, 0.5, 0)
			close.Size = UDim2.fromOffset(30, 30)
			close.BackgroundTransparency = 1
			close.BorderSizePixel = 0
			close.AutoButtonColor = false
			close.Image = ""
			close.ZIndex = 12012
			newUi.makeXIcon(close, 15, Color3.fromRGB(214, 223, 231), 12013, true)
			newUi.bindTabClick(button, function()
				selectTabByName(nativeTab.Name)
				task.defer(newUi.rebuildTabs)
				task.defer(editorCanvas.resizeAll)
			end)
			newUi.bindTabClick(close, function()
				local nativeClose = newUi.getNativeClose(nativeTab)
				if nativeClose then
					activateOriginal(nativeClose)
				else
					local nativeBox = codeFrame:FindFirstChild(nativeTab.Name, true)
					if nativeBox then
						nativeBox:Destroy()
					end
					nativeTab:Destroy()
				end
				task.delay(0.08, function()
					local activeBox = getActiveCodeBox()
					if not activeBox then
						local first = tabsFrame:FindFirstChildWhichIsA("GuiButton")
						if first and first.Name:match("^script%d+%.lua$") then
							selectTabByName(first.Name)
						end
					end
					newUi.rebuildTabs()
				end)
			end)
		end
		newUi.updateTabCanvas()
		newUi.updateLineNumbers()
	end

	newUi.refreshTabs = newUi.rebuildTabs

	newUi.bindCodeBox = function(box)
		if not (box and box:IsA("TextBox") and box.Name:match("^script%d+%.lua$") and not newUi.codeBound[box]) then
			return
		end
		newUi.codeBound[box] = true
		newUi.connect(box:GetPropertyChangedSignal("Visible"), function()
			task.defer(newUi.rebuildTabs)
		end)
		newUi.connect(box:GetPropertyChangedSignal("Name"), function()
			task.defer(newUi.rebuildTabs)
		end)
		for _, property in { "Text", "TextSize", "LineHeight" } do
			newUi.connect(box:GetPropertyChangedSignal(property), function()
				task.defer(newUi.updateLineNumbers)
			end)
		end
	end

	newUi.createActionButton = function(name, text, position, size, iconKind, callback)
		local button = newUi.make("ImageButton", name, newUi.toolbar)
		button.AnchorPoint = Vector2.new(position.X.Scale == 1 and 1 or 0, 0)
		button.Position = position
		button.Size = size
		button.BackgroundColor3 = newUi.colors.button
		button.BackgroundTransparency = 0.08
		button.BorderSizePixel = 0
		button.AutoButtonColor = false
		button.Image = ""
		button.ZIndex = 12010
		newUi.makeCorner(button, 14, false)
		newUi.makeStroke(button, newUi.colors.buttonStroke, 0.2, 1.5, false)
		local holder = newUi.make("Frame", "IconHolder", button)
		holder.AnchorPoint = Vector2.new(0, 0.5)
		holder.Position = UDim2.new(0, 14, 0.5, 0)
		holder.Size = UDim2.fromOffset(24, 24)
		holder.BackgroundTransparency = 1
		holder.ZIndex = 12012
		newUi.makeActionIcon(iconKind, holder, 22, newUi.colors.text, 12013, false)
		local label = newUi.make("TextLabel", "Text", button)
		label.Position = UDim2.new(0, 48, 0, 0)
		label.Size = UDim2.new(1, -58, 1, 0)
		label.BackgroundTransparency = 1
		label.Font = Enum.Font.GothamMedium
		label.Text = text
		label.TextColor3 = newUi.colors.text
		label.TextSize = 14
		label.TextXAlignment = Enum.TextXAlignment.Left
		label.TextTruncate = Enum.TextTruncate.None
		label.ZIndex = 12012
		newUi.bindClick(button, callback)
		return button
	end

	newUi.applyRailState = function()
		newUi.applyLocks()
		if newUi.addButton then
			newUi.addButton.Visible = not newUi.railCollapsed
		end
		if newUi.railTop then
			newUi.railTop.Visible = not newUi.railCollapsed
		end
		newUi.setChevronDirection(newUi.railToggleIcon, newUi.railCollapsed)
	end

	newUi.buildShell = function()
		newUi.capture(sidebar, { "Visible" })
		if sidebar then
			sidebar.Visible = false
			newUi.lock(sidebar, "Visible", false)
		end
		newUi.navBar = newUi.make("Frame", "LT_NewUINavBar", v2Main)
		newUi.navBar.AnchorPoint = Vector2.new(0.5, 0)
		newUi.navBar.Position = UDim2.new(0.53, 0, 0.015, 0)
		newUi.navBar.BackgroundColor3 = Color3.fromRGB(20, 34, 47)
		newUi.navBar.BackgroundTransparency = 0.01
		newUi.navBar.BorderSizePixel = 0
		newUi.navBar.ZIndex = 12000
		newUi.makeCorner(newUi.navBar, 40, false)
		newUi.makeStroke(newUi.navBar, Color3.fromRGB(58, 79, 95), 0.15, 1.5, false)
		local layout = newUi.make("UIListLayout", "Layout", newUi.navBar)
		layout.FillDirection = Enum.FillDirection.Horizontal
		layout.HorizontalAlignment = Enum.HorizontalAlignment.Center
		layout.VerticalAlignment = Enum.VerticalAlignment.Center
		layout.Padding = UDim.new(0, 4)
		layout.SortOrder = Enum.SortOrder.LayoutOrder
		for _, pageName in newUi.pageNames do
			if newUi.getPage(pageName) then
				newUi.createNavButton(pageName)
			end
		end
		newUi.closeButton = newUi.make("ImageButton", "LT_NewUIClose", v2Main)
		newUi.closeButton.AnchorPoint = Vector2.new(0.5, 0)
		newUi.closeButton.Size = UDim2.fromOffset(80, 80)
		newUi.closeButton.BackgroundColor3 = Color3.fromRGB(24, 40, 51)
		newUi.closeButton.BackgroundTransparency = 0.01
		newUi.closeButton.BorderSizePixel = 0
		newUi.closeButton.AutoButtonColor = false
		newUi.closeButton.Image = ""
		newUi.closeButton.ZIndex = 12000
		newUi.makeCorner(newUi.closeButton, 40, false)
		newUi.makeStroke(newUi.closeButton, Color3.fromRGB(58, 79, 95), 0.15, 1.5, false)
		newUi.makeXIcon(newUi.closeButton, 30, newUi.colors.text, 12002, false)
		newUi.bindClick(newUi.closeButton, function()
			newUi.setOpen(false)
		end)
		newUi.refreshOrder()
	end

	newUi.buildPages = function()
		for _, pageName in newUi.pageNames do
			local page = newUi.getPage(pageName)
			if page then
				newUi.capture(page, { "Visible", "Position", "Size", "AnchorPoint", "ClipsDescendants" })
				newUi.lock(page, "AnchorPoint", Vector2.zero)
				newUi.lock(page, "Position", UDim2.new(0.012, 0, 0.16, 0))
				newUi.lock(page, "Size", UDim2.new(0.976, 0, 0.828, 0))
				newUi.lock(page, "ClipsDescendants", false)
				newUi.connect(page:GetPropertyChangedSignal("Visible"), function()
					if not newUi.applying then
						task.defer(newUi.syncPages)
					end
				end)
			end
		end
	end

	newUi.buildExecutor = function()
		newUi.capture(editorSideMenu, { "Visible" })
		if editorSideMenu then
			newUi.lock(editorSideMenu, "Visible", false)
		end
		newUi.capture(executorImage, {
			"Position",
			"Size",
			"AnchorPoint",
			"BackgroundColor3",
			"BackgroundTransparency",
			"ImageTransparency",
			"ClipsDescendants",
		})
		newUi.lock(executorImage, "AnchorPoint", Vector2.zero)
		newUi.lock(executorImage, "Position", UDim2.fromScale(0, 0))
		newUi.lock(executorImage, "Size", function()
			return newUi.railCollapsed and UDim2.new(0.974, 0, 1, 0) or UDim2.new(0.948, 0, 1, 0)
		end)
		newUi.lock(executorImage, "BackgroundColor3", newUi.colors.panelTop)
		newUi.lock(executorImage, "BackgroundTransparency", 0)
		newUi.lock(executorImage, "ImageTransparency", 1)
		newUi.lock(executorImage, "ClipsDescendants", true)
		newUi.ensureCorner(executorImage, 20)
		newUi.ensureStroke(executorImage, newUi.colors.stroke, 0.22, 1.5)
		for _, child in executorImage:GetChildren() do
			if child:IsA("UIGradient") then
				newUi.capture(child, { "Enabled" })
				child.Enabled = false
			end
		end
		local panelGradient = newUi.make("UIGradient", "LT_NewUIPanelGradient", executorImage)
		panelGradient.Color = ColorSequence.new({
			ColorSequenceKeypoint.new(0, newUi.colors.panelTop),
			ColorSequenceKeypoint.new(0.5, newUi.colors.panelMiddle),
			ColorSequenceKeypoint.new(1, newUi.colors.panelBottom),
		})
		panelGradient.Rotation = 90
		newUi.capture(executorOverlay, { "BackgroundTransparency", "ImageTransparency" })
		newUi.lock(executorOverlay, "BackgroundTransparency", 1)
		newUi.lock(executorOverlay, "ImageTransparency", 1)
		newUi.capture(tabsFrame, { "Visible" })
		newUi.lock(tabsFrame, "Visible", false)
		newUi.capture(buttonsFrame, { "Visible" })
		buttonsFrame.Visible = false
		if statusFrame then
			newUi.capture(statusFrame, { "Visible" })
			newUi.lock(statusFrame, "Visible", false)
		end
		local menu = executorOverlay:FindFirstChild("Menu")
		if menu and menu:IsA("GuiObject") then
			newUi.capture(menu, { "Visible" })
			newUi.lock(menu, "Visible", false)
		end
		newUi.capture(codeFrame, {
			"Position",
			"Size",
			"AnchorPoint",
			"BackgroundColor3",
			"BackgroundTransparency",
			"BorderSizePixel",
			"ScrollBarThickness",
			"ScrollBarImageColor3",
			"ScrollBarImageTransparency",
		})
		newUi.lock(codeFrame, "AnchorPoint", Vector2.zero)
		newUi.lock(codeFrame, "Position", UDim2.new(0.035, 0, 0, 76))
		newUi.lock(codeFrame, "Size", UDim2.new(0.945, 0, 1, -150))
		newUi.lock(codeFrame, "BackgroundColor3", newUi.colors.panelMiddle)
		newUi.lock(codeFrame, "BackgroundTransparency", 1)
		newUi.lock(codeFrame, "BorderSizePixel", 0)
		newUi.lock(codeFrame, "ScrollBarThickness", 3)
		newUi.lock(codeFrame, "ScrollBarImageColor3", Color3.fromRGB(81, 101, 114))
		newUi.lock(codeFrame, "ScrollBarImageTransparency", 0.35)
		newUi.lineGutter = newUi.make("Frame", "LT_NewUILineGutter", executorOverlay)
		newUi.lineGutter.Position = UDim2.new(0.008, 0, 0, 76)
		newUi.lineGutter.Size = UDim2.new(0.025, 0, 1, -150)
		newUi.lineGutter.BackgroundTransparency = 1
		newUi.lineGutter.BorderSizePixel = 0
		newUi.lineGutter.ClipsDescendants = true
		newUi.lineGutter.ZIndex = 12008
		newUi.lineNumbers = newUi.make("TextLabel", "Numbers", newUi.lineGutter)
		newUi.lineNumbers.Position = UDim2.fromOffset(0, 6)
		newUi.lineNumbers.Size = UDim2.new(1, -4, 1, 0)
		newUi.lineNumbers.BackgroundTransparency = 1
		newUi.lineNumbers.Font = Enum.Font.Code
		newUi.lineNumbers.Text = ""
		newUi.lineNumbers.TextColor3 = Color3.fromRGB(190, 201, 210)
		newUi.lineNumbers.TextSize = editorFontSize
		newUi.lineNumbers.TextXAlignment = Enum.TextXAlignment.Right
		newUi.lineNumbers.TextYAlignment = Enum.TextYAlignment.Top
		newUi.lineNumbers.ZIndex = 12009
		newUi.connect(codeFrame:GetPropertyChangedSignal("CanvasPosition"), function()
			newUi.updateLineNumbers()
		end)
		newUi.tabBar = newUi.make("ScrollingFrame", "LT_NewUITabs", executorOverlay)
		newUi.tabBar.Position = UDim2.new(0.01, 0, 0, 14)
		newUi.tabBar.Size = UDim2.new(1, -92, 0, 54)
		newUi.tabBar.BackgroundTransparency = 1
		newUi.tabBar.BorderSizePixel = 0
		newUi.tabBar.ScrollBarThickness = 0
		newUi.tabBar.ScrollingDirection = Enum.ScrollingDirection.X
		newUi.tabBar.CanvasSize = UDim2.fromOffset(0, 0)
		newUi.tabBar.ZIndex = 12009
		newUi.tabLayout = newUi.make("UIListLayout", "Layout", newUi.tabBar)
		newUi.tabLayout.FillDirection = Enum.FillDirection.Horizontal
		newUi.tabLayout.HorizontalAlignment = Enum.HorizontalAlignment.Left
		newUi.tabLayout.VerticalAlignment = Enum.VerticalAlignment.Center
		newUi.tabLayout.Padding = UDim.new(0, 8)
		newUi.tabLayout.SortOrder = Enum.SortOrder.LayoutOrder
		newUi.connect(newUi.tabLayout:GetPropertyChangedSignal("AbsoluteContentSize"), newUi.updateTabCanvas)
		newUi.addButton = newUi.make("ImageButton", "LT_NewUIAddTab", executorOverlay)
		newUi.addButton.AnchorPoint = Vector2.new(1, 0)
		newUi.addButton.Position = UDim2.new(1, -14, 0, 14)
		newUi.addButton.Size = UDim2.fromOffset(54, 54)
		newUi.addButton.BackgroundColor3 = newUi.colors.button
		newUi.addButton.BackgroundTransparency = 0.04
		newUi.addButton.BorderSizePixel = 0
		newUi.addButton.AutoButtonColor = false
		newUi.addButton.Image = ""
		newUi.addButton.ZIndex = 12010
		newUi.makeCorner(newUi.addButton, 18, false)
		newUi.makeStroke(newUi.addButton, newUi.colors.buttonStroke, 0.35, 1, false)
		newUi.makeDocumentIcon(newUi.addButton, 26, newUi.colors.text, 12012, true, false)
		local nativeAdd = tabsFrame:FindFirstChild("AddTab")
		newUi.bindClick(newUi.addButton, function()
			task.spawn(function()
				local created = nativeAdd and fireAddTab(nativeAdd)
				if not created then
					createFallbackTab(nextAvailableTabName())
				end
				task.delay(0.05, function()
					for _, box in getCodeBoxes() do
						newUi.bindCodeBox(box)
					end
					newUi.rebuildTabs()
					editorCanvas.resizeAll()
				end)
			end)
		end)
		local divider = newUi.make("Frame", "LT_NewUIHeaderDivider", executorOverlay)
		divider.Position = UDim2.new(0, 0, 0, 72)
		divider.Size = UDim2.new(1, 0, 0, 2)
		divider.BackgroundColor3 = Color3.fromRGB(42, 59, 70)
		divider.BackgroundTransparency = 0.55
		divider.BorderSizePixel = 0
		divider.ZIndex = 12007
		newUi.toolbar = newUi.make("Frame", "LT_NewUIToolbar", executorOverlay)
		newUi.toolbar.AnchorPoint = Vector2.new(0, 1)
		newUi.toolbar.Position = UDim2.new(0.01, 0, 1, -14)
		newUi.toolbar.Size = UDim2.new(0.97, 0, 0, 54)
		newUi.toolbar.BackgroundTransparency = 1
		newUi.toolbar.BorderSizePixel = 0
		newUi.toolbar.ZIndex = 12009
		newUi.createActionButton(
			"LT_NewUIExecute",
			"Execute",
			UDim2.fromOffset(0, 0),
			UDim2.fromOffset(142, 54),
			"Execute",
			executeActiveCode
		)
		newUi.createActionButton(
			"LT_NewUIClear",
			"Clear",
			UDim2.fromOffset(150, 0),
			UDim2.fromOffset(124, 54),
			"Clear",
			function()
				clearActiveCode()
				task.defer(newUi.rebuildTabs)
				task.defer(newUi.updateLineNumbers)
			end
		)
		newUi.createActionButton(
			"LT_NewUICopy",
			"Copy",
			UDim2.fromOffset(282, 0),
			UDim2.fromOffset(124, 54),
			"Copy",
			copyActiveCode
		)
		newUi.createActionButton(
			"LT_NewUIPaste",
			"Paste",
			UDim2.fromOffset(414, 0),
			UDim2.fromOffset(124, 54),
			"Paste",
			pasteIntoActive
		)
		local nativeExecuteButton = buttonsFrame:FindFirstChild("Execute")
		local nativeClearButton = buttonsFrame:FindFirstChild("Clear")
		local nativeClipboardButton = buttonsFrame:FindFirstChild("ExecuteClipboard")
		local nativeButtonsLayout = buttonsFrame:FindFirstChildOfClass("UIListLayout")
		newUi.capture(buttonsFrame, {
			"AnchorPoint",
			"Position",
			"Size",
			"BackgroundTransparency",
			"BorderSizePixel",
			"ZIndex",
			"Active",
		})
		newUi.lock(buttonsFrame, "Visible", true)
		newUi.lock(buttonsFrame, "AnchorPoint", Vector2.new(1, 1))
		newUi.lock(buttonsFrame, "Position", UDim2.new(0.98, 0, 1, -14))
		newUi.lock(buttonsFrame, "Size", UDim2.fromOffset(210, 54))
		newUi.lock(buttonsFrame, "BackgroundTransparency", 1)
		newUi.lock(buttonsFrame, "BorderSizePixel", 0)
		newUi.lock(buttonsFrame, "ZIndex", 12020)
		newUi.lock(buttonsFrame, "Active", false)
		if nativeButtonsLayout then
			newUi.capture(nativeButtonsLayout, { "Parent" })
			table.insert(newUi.detached, nativeButtonsLayout)
			nativeButtonsLayout.Parent = nil
		end
		for _, nativeButton in { nativeExecuteButton, nativeClearButton } do
			if nativeButton and nativeButton:IsA("GuiObject") then
				newUi.lock(nativeButton, "Visible", false)
			end
		end
		if nativeClipboardButton and nativeClipboardButton:IsA("GuiButton") then
			newUi.capture(nativeClipboardButton, {
				"AnchorPoint",
				"Position",
				"Size",
				"Visible",
				"Active",
				"Interactable",
				"AutoButtonColor",
				"BackgroundColor3",
				"BackgroundTransparency",
				"BorderSizePixel",
				"Image",
				"ImageTransparency",
				"ZIndex",
			})
			newUi.lock(nativeClipboardButton, "AnchorPoint", Vector2.zero)
			newUi.lock(nativeClipboardButton, "Position", UDim2.fromScale(0, 0))
			newUi.lock(nativeClipboardButton, "Size", UDim2.fromScale(1, 1))
			newUi.lock(nativeClipboardButton, "Visible", true)
			newUi.lock(nativeClipboardButton, "Active", true)
			newUi.lock(nativeClipboardButton, "Interactable", true)
			newUi.lock(nativeClipboardButton, "AutoButtonColor", false)
			newUi.lock(nativeClipboardButton, "BackgroundColor3", newUi.colors.button)
			newUi.lock(nativeClipboardButton, "BackgroundTransparency", 0.08)
			newUi.lock(nativeClipboardButton, "BorderSizePixel", 0)
			newUi.lock(nativeClipboardButton, "Image", "")
			newUi.lock(nativeClipboardButton, "ImageTransparency", 1)
			newUi.lock(nativeClipboardButton, "ZIndex", 12021)
			for _, descendant in nativeClipboardButton:GetDescendants() do
				if descendant:IsA("GuiObject") then
					newUi.lock(descendant, "Visible", false)
				elseif descendant:IsA("UIStroke") or descendant:IsA("UIGradient") then
					newUi.capture(descendant, { "Enabled" })
					descendant.Enabled = false
				end
			end
			newUi.ensureCorner(nativeClipboardButton, 14)
			newUi.makeStroke(nativeClipboardButton, newUi.colors.buttonStroke, 0.2, 1.5, false)
			local nativeIconHolder = newUi.make("Frame", "LT_NewUIClipboardIconHolder", nativeClipboardButton)
			nativeIconHolder.AnchorPoint = Vector2.new(0, 0.5)
			nativeIconHolder.Position = UDim2.new(0, 14, 0.5, 0)
			nativeIconHolder.Size = UDim2.fromOffset(24, 24)
			nativeIconHolder.BackgroundTransparency = 1
			nativeIconHolder.ZIndex = 12023
			newUi.makeActionIcon(
				"ExecuteClipboard",
				nativeIconHolder,
				22,
				newUi.colors.text,
				12024,
				false
			)
			local nativeLabel = newUi.make("TextLabel", "LT_NewUIClipboardText", nativeClipboardButton)
			nativeLabel.Position = UDim2.new(0, 48, 0, 0)
			nativeLabel.Size = UDim2.new(1, -58, 1, 0)
			nativeLabel.BackgroundTransparency = 1
			nativeLabel.Font = Enum.Font.GothamMedium
			nativeLabel.Text = "Execute clipboard"
			nativeLabel.TextColor3 = newUi.colors.text
			nativeLabel.TextSize = 14
			nativeLabel.TextXAlignment = Enum.TextXAlignment.Left
			nativeLabel.TextTruncate = Enum.TextTruncate.None
			nativeLabel.ZIndex = 12023
		else
			newUi.createActionButton(
				"LT_NewUIExecuteClipboard",
				"Execute clipboard",
				UDim2.new(1, 0, 0, 0),
				UDim2.fromOffset(210, 54),
				"ExecuteClipboard",
				executeClipboardCode
			)
		end
		newUi.rail = newUi.make("Frame", "LT_NewUIRail", executorRoot)
		newUi.rail.BackgroundColor3 = newUi.colors.railTop
		newUi.rail.BackgroundTransparency = 0
		newUi.rail.BorderSizePixel = 0
		newUi.rail.ZIndex = 11900
		newUi.makeCorner(newUi.rail, 20, false)
		newUi.makeStroke(newUi.rail, newUi.colors.stroke, 0.22, 1.5, false)
		local railGradient = newUi.make("UIGradient", "Gradient", newUi.rail)
		railGradient.Color = ColorSequence.new(newUi.colors.railTop, newUi.colors.railBottom)
		railGradient.Rotation = 90
		newUi.lock(newUi.rail, "Position", function()
			return newUi.railCollapsed and UDim2.new(0.982, 0, 0, 0) or UDim2.new(0.956, 0, 0, 0)
		end)
		newUi.lock(newUi.rail, "Size", function()
			return newUi.railCollapsed and UDim2.new(0.018, 0, 1, 0) or UDim2.new(0.044, 0, 1, 0)
		end)
		newUi.railTop = newUi.make("TextLabel", "LT_NewUIRailTerminal", newUi.rail)
		newUi.railTop.AnchorPoint = Vector2.new(0.5, 0)
		newUi.railTop.Position = UDim2.new(0.5, 0, 0, 15)
		newUi.railTop.Size = UDim2.new(1, -12, 0, 48)
		newUi.railTop.BackgroundTransparency = 1
		newUi.railTop.Font = Enum.Font.Code
		newUi.railTop.Text = ">_"
		newUi.railTop.TextColor3 = newUi.colors.text
		newUi.railTop.TextSize = 22
		newUi.railTop.ZIndex = 11902
		newUi.railToggle = newUi.make("TextButton", "LT_NewUIRailToggle", newUi.rail)
		newUi.railToggle.AnchorPoint = Vector2.new(0.5, 0.5)
		newUi.railToggle.Position = UDim2.fromScale(0.5, 0.5)
		newUi.railToggle.Size = UDim2.new(1, 0, 0, 56)
		newUi.railToggle.BackgroundTransparency = 1
		newUi.railToggle.Text = ""
		newUi.railToggle.ZIndex = 11902
		newUi.railToggleIcon = newUi.makeChevronIcon(
			newUi.railToggle,
			20,
			newUi.colors.muted,
			11903,
			false
		)
		newUi.bindClick(newUi.railToggle, function()
			newUi.railCollapsed = not newUi.railCollapsed
			newUi.applyRailState()
			task.defer(editorCanvas.resizeAll)
		end)
		newUi.connect(tabsFrame.ChildAdded, function(object)
			if object:IsA("GuiButton") then
				task.delay(0.05, newUi.rebuildTabs)
			end
		end)
		newUi.connect(tabsFrame.ChildRemoved, function()
			task.defer(newUi.rebuildTabs)
		end)
		newUi.connect(codeFrame.DescendantAdded, function(object)
			if object:IsA("TextBox") then
				task.defer(newUi.bindCodeBox, object)
			end
		end)
		for _, box in getCodeBoxes() do
			newUi.bindCodeBox(box)
		end
		newUi.applyRailState()
		newUi.rebuildTabs()
	end

	newUi.bindIcon = function()
		__dcm_env.__NewDeltaUIToggle = function()
			if newUi.enabled and newUi.applied then
				newUi.setOpen(not newUi.open)
				return true
			end
			return false
		end
		local iconApi = rawget(__dcm_env, "DeltaIcon")
		if type(iconApi) == "table" and type(iconApi.rebindToggle) == "function" then
			pcall(iconApi.rebindToggle)
		end
	end

	newUi.enable = function()
		if newUi.applied then
			newUi.enabled = true
			newUi.setOpen(newUi.open)
			return
		end
		local visiblePage = newUi.getCurrentSectionName()
		newUi.enabled = true
		newUi.applied = true
		newUi.open = visiblePage ~= nil
		if visiblePage and newUi.pageSet[visiblePage] then
			newUi.activePage = visiblePage
		else
			for _, pageName in newUi.pageNames do
				local page = newUi.getPage(pageName)
				if page and page.Visible then
					newUi.activePage = pageName
					newUi.open = true
					break
				end
			end
		end
		NAlib.disconnect("Sidebar_NormalizeGeometry")
		NAlib.disconnect("SidebarGesture")
		NAlib.disconnect("ManagedIcon_Toggle")
		local gesture = v2Main:FindFirstChild("SidebarGestureZone", true)
		if gesture and gesture:IsA("GuiObject") then
			newUi.capture(gesture, { "Visible", "Active" })
			gesture.Visible = false
			gesture.Active = false
		end
		newUi.buildShell()
		newUi.buildPages()
		newUi.buildExecutor()
		newUi.bindIcon()
		newUi.syncPages()
		newUi.applyLocks()
		newUi.refreshOrder()
		newUi.refreshNav()
		task.defer(editorCanvas.resizeAll)
		task.defer(updateStatusPosition)
	end

	newUi.disable = function(fullUnload)
		if not newUi.applied then
			newUi.enabled = false
			return
		end
		local wasOpen = newUi.open
		local lastPage = newUi.activePage
		newUi.enabled = false
		newUi.applied = false
		newUi.clearTabConnections()
		for i = #newUi.connections, 1, -1 do
			pcall(function()
				newUi.connections[i]:Disconnect()
			end)
		end
		table.clear(newUi.connections)
		for i = #newUi.created, 1, -1 do
			local object = newUi.created[i]
			if object and object.Parent then
				pcall(function()
					object:Destroy()
				end)
			end
		end
		table.clear(newUi.created)
		for object, state in newUi.originals do
			if object then
				local parentState = state.Parent
				if parentState then
					pcall(function()
						object.Parent = parentState.value
					end)
				end
				for property, wrapped in state do
					if property ~= "Parent" then
						pcall(function()
							object[property] = wrapped.value
						end)
					end
				end
			end
		end
		table.clear(newUi.detached)
		newUi.originals = setmetatable({}, { __mode = "k" })
		newUi.pageButtons = {}
		newUi.codeBound = setmetatable({}, { __mode = "k" })
		newUi.locks = {}
		newUi.navBar = nil
		newUi.closeButton = nil
		newUi.tabBar = nil
		newUi.tabLayout = nil
		newUi.lineGutter = nil
		newUi.lineNumbers = nil
		newUi.addButton = nil
		newUi.toolbar = nil
		newUi.rail = nil
		newUi.railTop = nil
		newUi.railToggle = nil
		newUi.railToggleIcon = nil
		__dcm_env.__NewDeltaUIToggle = nil
		if not fullUnload then
			if lastPage and newUi.pageSet[lastPage] then
				local iconApi = newUi.getIconApi()
				if iconApi and type(iconApi.setCurrentSection) == "function" then
					pcall(iconApi.setCurrentSection, lastPage)
				end
			end
			newUi.setClassicOpen(wasOpen)
			local iconApi = rawget(__dcm_env, "DeltaIcon")
			if type(iconApi) == "table" and type(iconApi.rebindToggle) == "function" then
				task.defer(iconApi.rebindToggle)
			end
			task.defer(applySidebarOrder)
			task.defer(applyWideEditor)
			task.defer(applyCompactTabs)
			task.defer(applyToolbarLayout)
			task.defer(editorCanvas.resizeAll)
			task.defer(updateStatusPosition)
		end
	end

	local baseApplySidebarOrder = applySidebarOrder
	applySidebarOrder = function()
		baseApplySidebarOrder()
		if newUi.enabled and newUi.applied then
			newUi.refreshOrder()
		end
	end

	addRestorer(function()
		newUi.disable(true)
	end)
	local newUiSettingRow = createToggleSetting(
		"LT_NewDeltaUI",
		"Recreated new Delta UI (BETA)",
		"BETA: Rebuilds Delta around the unreleased full-screen layout while retaining its native page and executor handlers",
		newUi.enabled,
		function(enabled)
			saveBool("NewDeltaUI", enabled)
			if enabled then
				newUi.enable()
			else
				newUi.disable()
			end
		end
	)
	if newUiSettingRow then
		local betaStroke = Instance.new("UIStroke")
		betaStroke.Name = "LT_NewUIBetaStroke"
		betaStroke.Color = Color3.fromRGB(0, 145, 255)
		betaStroke.Transparency = 0.25
		betaStroke.Thickness = 1.5
		betaStroke.Parent = newUiSettingRow
		local newBadge = Instance.new("TextLabel")
		newBadge.Name = "LT_NewUIBadge"
		newBadge.AnchorPoint = Vector2.new(1, 0)
		newBadge.Position = UDim2.new(1, -92, 0, 8)
		newBadge.Size = UDim2.fromOffset(54, 21)
		newBadge.BackgroundColor3 = Color3.fromRGB(0, 120, 255)
		newBadge.BorderSizePixel = 0
		newBadge.Font = Enum.Font.GothamBold
		newBadge.Text = "NEW!"
		newBadge.TextColor3 = Color3.new(1, 1, 1)
		newBadge.TextSize = 11
		newBadge.ZIndex = newUiSettingRow.ZIndex + 4
		newBadge.Parent = newUiSettingRow
		local badgeCorner = Instance.new("UICorner")
		badgeCorner.CornerRadius = UDim.new(0, 7)
		badgeCorner.Parent = newBadge
	end

	createToggleSetting(
		"LT_AutoRestoreTabs",
		"Auto restore saved tabs",
		"Creates missing Delta tabs and loads their saved code automatically",
		autoRestoreEnabled,
		function(enabled)
			autoRestoreEnabled = enabled
			saveBool("AutoRestoreTabs", enabled)
			if enabled then
				task.spawn(restoreSavedTabs, true)
			end
		end
	)

	createToggleSetting(
		"LT_EditorToolbarSetting",
		"Extended editor toolbar",
		"Resizes Delta's native controls and adds Copy, Paste, and Add Line",
		editorToolbarEnabled,
		function(enabled)
			editorToolbarEnabled = enabled
			saveBool("EditorToolbar", enabled)
			buildToolbar()
			applyToolbarLayout()
		end
	)

	createSettingRow(
		"LT_SidebarButtonOrder",
		"Sidebar button order",
		"Reorders the classic sidebar and the recreated top navigation, including Music",
		"SORT",
		function()
			local menu = ensureSidebarSortMenu()
			refreshSidebarSortMenu()
			menu.Visible = not menu.Visible
		end
	)

	createToggleSetting(
		"LT_EditorStatusSetting",
		"Editor statistics",
		"Shows the active tab, line count, character count and autosave state",
		editorStatusEnabled,
		function(enabled)
			editorStatusEnabled = enabled
			saveBool("EditorStatus", enabled)
			queueStatusUpdate()
		end
	)

	createSettingRow(
		"LT_RestoreTabsNow",
		"Restore saved tabs now",
		"Rebuilds any missing tabs from DeltaCustom/DeltaTabs",
		"RESTORE",
		function()
			task.spawn(restoreSavedTabs, true)
		end
	)

	createToggleSetting(
		"LT_WideEditor",
		"Wide editor",
		"Hides the executor side cards and gives the code editor more room",
		wideEditorEnabled,
		function(enabled)
			wideEditorEnabled = enabled
			saveBool("WideEditor", enabled)
			applyWideEditor()
		end
	)

	createToggleSetting(
		"LT_CompactTabs",
		"Compact editor tabs",
		"Fits more script tabs across the executor tab bar",
		compactTabsEnabled,
		function(enabled)
			compactTabsEnabled = enabled
			saveBool("CompactTabs", enabled)
			applyCompactTabs()
		end
	)


	createToggleSetting(
		"LT_SyntaxHighlight",
		"Lua/Luau syntax highlighting",
		"Highlights Luau keywords, strings, numbers, comments, globals and built-in APIs",
		syntaxHighlightEnabled,
		function(enabled)
			syntaxHighlightEnabled = enabled
			saveBool("EditorSyntaxHighlight", enabled)
			syntaxHighlighter.applyAll()
		end
	)

	createToggleSetting(
		"LT_ExploitSyntaxHighlight",
		"Executor API highlighting",
		"Highlights common executor globals, filesystem, hook, debug and clipboard functions",
		exploitSyntaxEnabled,
		function(enabled)
			exploitSyntaxEnabled = enabled
			saveBool("ExploitSyntaxHighlight", enabled)
			syntaxHighlighter.applyAll()
		end
	)

	createToggleSetting(
		"LT_EditorWordWrap",
		"Editor word wrap",
		"Wraps long code lines inside the editor viewport",
		editorWordWrapEnabled,
		function(enabled)
			editorWordWrapEnabled = enabled
			saveBool("EditorWordWrap", enabled)
			applyEditorPreferences()
		end
	)

	createSettingRow(
		"LT_UnloadCustomization",
		"Unload customization",
		"Restores Delta's original interface and removes the active customization",
		"UNLOAD",
		function()
			local master = rawget(__dcm_env, "__DeltaCustomizationMasterRuntime")
			if type(master) == "table" and type(master.stop) == "function" then
				task.defer(master.stop)
			else
				task.defer(runtime.stop)
			end
		end
	)

	createCycleSetting(
		"LT_EditorFontSize",
		"Editor font size",
		"Cycles the code editor font size",
		{ 10, 12, 14, 16, 18, 20, 22, 24 },
		function()
			return editorFontSize
		end,
		function(value)
			editorFontSize = value
			saveNumber("EditorFontSize", value)
			applyEditorPreferences()
		end,
		function(value)
			return tostring(value) .. " PX"
		end
	)

	connect(codeFrame.DescendantAdded, function(object)
		if object:IsA("TextBox") then
			task.defer(function()
				hookCodeBox(object)
				applyEditorStyle(object)
				queueStatusUpdate()
			end)
			task.delay(0.12, normalizeTabSequence)
		end
	end)
	local addTabButton = tabsFrame:FindFirstChild("AddTab")
	if addTabButton and addTabButton:IsA("GuiButton") then
		connect(addTabButton.MouseButton1Click, function()
			local before = #getCodeBoxes()
			task.delay(0.18, function()
				if runtime.alive and #getCodeBoxes() == before then
					createFallbackTab(nextAvailableTabName())
				end
			end)
		end)
	end
	connect(codeFrame.DescendantRemoving, function(object)
		queueStatusUpdate()
		task.delay(0.12, normalizeTabSequence)
		if not object:IsA("TextBox") or not object.Name:match("^script%d+%.lua$") then
			return
		end
		local name = object.Name
		task.delay(0.3, function()
			if
				not runtime.alive
				or not v2Main.Parent
				or not tabsFrame.Parent
				or not codeFrame.Parent
			then
				return
			end
			for _, box in getCodeBoxes() do
				if box.Name == name then
					return
				end
			end
			if type(delfile) == "function" and type(isfile) == "function" then
				local path = tabDirectory .. "/" .. name
				if isfile(path) then
					pcall(delfile, path)
				end
			end
		end)
	end)
	connect(codeFrame:GetPropertyChangedSignal("Position"), updateStatusPosition)
	connect(codeFrame:GetPropertyChangedSignal("Size"), updateStatusPosition)
	connect(codeFrame:GetPropertyChangedSignal("AbsoluteSize"), updateStatusPosition)
	connect(buttonsFrame.ChildAdded, function(object)
		if not object:IsA("GuiButton") then
			return
		end
		if object.Name == "Execute" or object.Name == "Clear" or object.Name == "ExecuteClipboard" then
			object:SetAttribute("LT_NativeVisible", true)
			runtime.originalButtons[object] = true
			object.Visible = true
			task.defer(function()
				if runtime.alive and object.Parent == buttonsFrame then
					buildToolbar()
				end
			end)
		end
	end)

	task.wait(0.7)
	if not runtime.alive then
		return
	end
	normalizeTabSequence()
	buildToolbar()
	applyToolbarLayout()
	buildStatus()
	applyWideEditor()
	applyCompactTabs()
	applyEditorPreferences()
	syntaxHighlighter.applyAll()
	if newUi.enabled then
		newUi.enable()
	end
	if autoRestoreEnabled then
		task.spawn(restoreSavedTabs, false)
	end
end

How to Execute Universal Script – Delta remaster

Step 1: Copy Code: Click the Copy Code button in the viewer above to grab the clean Lua loadstring.

Step 2: Launch Executor: Open a compatible, unpatched executor. If you need one, check our Roblox Executors Directory.

Step 3: Join Experience: Launch Roblox and join Universal Script.

Step 4: Attach & Run: Attach/inject your executor into the Roblox process, paste the code into the script tab, and press Execute.

Created By

Ioooooo
Ioooooo
Script Creator
View Author Profile

Features & Information

Execute Universal Script – Delta remaster. Key system required, created by Ioooooo, updated Oct 21, 2026. Tested and working on supported executors.

Script Changelog (2)

@QueueSpeedDemonOct 22, 2026

Edited during review before approval

@IooooooOct 21, 2026

Create script

Community Comments (3)

Xcw7xXcw7xOct 22, 2026

Cool

Replying to @Xcw7x
IooooooIooooooOct 23, 2026

@Xcw7x thx user Xcw7x

Replying to @Ioooooo
Xcw7xXcw7xOct 23, 2026

@Ioooooo You can make it smaller because it's a long script.

Frequently Asked Questions

How do I execute Universal Script – Delta remaster in Roblox?

To run Universal Script – Delta remaster, copy the Lua loadstring from the code viewer above, launch Roblox and join Universal Script, attach a working executor (such as Potassium, Solara, or Delta from our Executors directory), paste the code into your executor console, and click Execute.

Is Universal Script – Delta remaster keyless or does it require an access key?

Universal Script – Delta remaster requires an access key. You can retrieve the official key directly using the Get Script Key link provided above.

Is Universal Script – Delta remaster currently safe and working?

This script is active and operational. Always test scripts using a secondary (alt) Roblox account to safeguard your main profile against anti-cheat bans.