--[[
	zxclinux — Black Flash chain macro
	tg: https://t.me/zxclinux
]]

if _G.zxclinux_bf then
	pcall(function()
		local core = game:GetService("CoreGui"):FindFirstChild("zxclinuxBF")
		if core then core:Destroy() end
	end)
	pcall(function()
		local plrs = game:GetService("Players")
		local lp = plrs.LocalPlayer
		local pg = lp and lp:FindFirstChild("PlayerGui")
		if pg then
			local old = pg:FindFirstChild("zxclinuxBF")
			if old then old:Destroy() end
		end
	end)
end
_G.zxclinux_bf = true

local okRun, runErr = pcall(function()

local UIS         = game:GetService("UserInputService")
local VIM
pcall(function() VIM = game:GetService("VirtualInputManager") end)
local Players     = game:GetService("Players")
local RunService  = game:GetService("RunService")
local HttpService = game:GetService("HttpService")
local TweenService = game:GetService("TweenService")

local LP     = Players.LocalPlayer
if not LP then
	LP = Players.PlayerAdded:Wait()
end
local Camera = workspace.CurrentCamera

if _G.zxclinux_bf then
	pcall(function()
		local pg = LP.PlayerGui:FindFirstChild("zxclinuxBF")
		if pg then pg:Destroy() end
	end)
end

local ThemeName = "Dark"
local Themes = {
	Dark = {
		BG = Color3.fromRGB(10, 10, 10),
		PANEL = Color3.fromRGB(16, 12, 12),
		ROW = Color3.fromRGB(20, 12, 14),
		ACCENT = Color3.fromRGB(200, 35, 45),
		ACCENT_H = Color3.fromRGB(255, 90, 90),
		MUTED = Color3.fromRGB(120, 80, 80),
		TEXT = Color3.fromRGB(255, 255, 255),
		STROKE = Color3.fromRGB(160, 25, 35),
		VEIL = 0.55,
		WIN_TRANS = 0.25,
		HINT_BG = Color3.fromRGB(12, 12, 12),
		VEIL_TINT = Color3.fromRGB(0, 0, 0),
		GRAD_A = Color3.fromRGB(48, 14, 18),
		GRAD_B = Color3.fromRGB(14, 10, 10),
		GLOW = 0.5,
		PHOTO_TRANS = 0.67,
		SHINE = 0.92,
	},
	Light = {
		BG = Color3.fromRGB(255, 252, 253),
		PANEL = Color3.fromRGB(255, 255, 255),
		ROW = Color3.fromRGB(255, 246, 248),
		ACCENT = Color3.fromRGB(225, 29, 72),
		ACCENT_H = Color3.fromRGB(244, 63, 94),
		MUTED = Color3.fromRGB(130, 110, 118),
		TEXT = Color3.fromRGB(30, 18, 24),
		STROKE = Color3.fromRGB(251, 113, 133),
		-- same bg/photo opacity as Dark so wallpaper reads equally
		VEIL = 0.55,
		WIN_TRANS = 0.25,
		HINT_BG = Color3.fromRGB(255, 250, 252),
		VEIL_TINT = Color3.fromRGB(0, 0, 0),
		GRAD_A = Color3.fromRGB(255, 228, 235),
		GRAD_B = Color3.fromRGB(255, 255, 255),
		GLOW = 0.25,
		PHOTO_TRANS = 0.67,
		SHINE = 0.92,
	},
}

local ACCENT, PANEL, BG, MUTED, TEXT_PRIMARY, ACCENT_H, STROKE_C
local UI = { rows = {} }

local function themeColors()
	return Themes[ThemeName] or Themes.Dark
end

local function pullTheme()
	local t = themeColors()
	ACCENT, PANEL, BG, MUTED = t.ACCENT, t.PANEL, t.BG, t.MUTED
	TEXT_PRIMARY, ACCENT_H, STROKE_C = t.TEXT, t.ACCENT_H, t.STROKE
	return t
end

pullTheme()

local function setGradient(frame, a, b, rot)
	if not frame then return end
	local g = frame:FindFirstChildOfClass("UIGradient") or Instance.new("UIGradient")
	g.Color = ColorSequence.new({
		ColorSequenceKeypoint.new(0, a),
		ColorSequenceKeypoint.new(1, b),
	})
	g.Rotation = rot or 90
	g.Parent = frame
end

local function setShine(frame, peak)
	if not frame then return end
	local ok = pcall(function()
		local g = frame:FindFirstChildOfClass("UIGradient") or Instance.new("UIGradient")
		g.Color = ColorSequence.new(Color3.new(1, 1, 1))
		g.Transparency = NumberSequence.new({
			NumberSequenceKeypoint.new(0, 1 - peak),
			NumberSequenceKeypoint.new(0.55, 1),
		})
		g.Rotation = 90
		g.Parent = frame
	end)
	if not ok then
		frame.BackgroundTransparency = 1
	end
end

local function pulseStroke(stroke, minT, maxT)
	if not stroke then return end
	task.spawn(function()
		local dir = 1
		while stroke.Parent do
			local goal = dir > 0 and maxT or minT
			TweenService:Create(stroke, TweenInfo.new(1.1, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {
				Transparency = goal,
			}):Play()
			task.wait(1.15)
			dir = -dir
		end
	end)
end

local function popIn(frame, scaleObj)
	if not frame or not scaleObj then return end
	scaleObj.Scale = 0.94
	task.defer(function()
		pcall(function()
			TweenService:Create(scaleObj, TweenInfo.new(0.4, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {
				Scale = 1,
			}):Play()
		end)
	end)
end

local function setPlaceholder(box, text, color)
	pcall(function() box.PlaceholderText = text end)
	pcall(function() box.PlaceholderColor3 = color end)
end

-- full URLs injected by build (catbox / luarmor / raw host)
local CDN_URLS = {
	bg = "https://hloridata.github.io/zxclinux-loader/zxclinux_bg.png",
	snd = "https://hloridata.github.io/zxclinux-loader/tuturu_1.mp3",
}

local function httpFetch(url, binary)
	local wantBin = binary == true
	local ok, body = pcall(function()
		local okG, res = pcall(function() return game:HttpGet(url, wantBin) end)
		if okG and type(res) == "string" and res ~= "" then return res end
		if syn and syn.request then
			return syn.request({ Url = url, Method = "GET" }).Body
		end
		if http and http.request then
			return http.request({ Url = url, Method = "GET" }).Body
		end
		if http_request then
			return http_request({ Url = url, Method = "GET" }).Body
		end
		if request then
			return request({ Url = url, Method = "GET" }).Body
		end
	end)
	if ok and type(body) == "string" and body ~= "" and not body:find("<!DOCTYPE", 1, true) then
		return body
	end
	return nil
end

local function ensureCdnAsset(fileName)
	if typeof(writefile) ~= "function" or typeof(getcustomasset) ~= "function" then
		return nil
	end
	local url
	if fileName == "zxclinux_bg.png" then
		url = CDN_URLS.bg
	elseif fileName == "tuturu_1.mp3" then
		url = CDN_URLS.snd
	end
	if not url or url == "" or url:find("__ZXC_", 1, true) then
		return nil
	end
	local rel = "zxclinux_cache/" .. fileName
	if isfile and isfile(rel) then
		local ok, asset = pcall(getcustomasset, rel)
		if ok and asset and asset ~= "" then return asset end
	end
	local body = httpFetch(url, true)
	if not body then return nil end
	pcall(function()
		if makefolder then makefolder("zxclinux_cache") end
	end)
	local okW = pcall(writefile, rel, body)
	if not okW then return nil end
	local ok, asset = pcall(getcustomasset, rel)
	if ok and asset and asset ~= "" then return asset end
	return nil
end

local ACCESS_CODE = "footjob"
local Authenticated = false

local ChainAnims = {
	["rbxassetid://100962226150441"] = 0.19,
	["rbxassetid://95852624447551"]  = 0.19,
	["rbxassetid://74145636023952"]  = 0.19,
	["rbxassetid://72475960800126"]  = 0.20,
	["rbxassetid://123171106092050"] = 0.19,
}

local StraightAnims = {
	["rbxassetid://123171106092050"] = true,
}

local Defaults = {
	Chance        = 70,
	Duration      = 0.18, -- pro: quick but readable
	Radius        = 2.75,
	Range         = 25,
	CurveStrength = 9,
	CamOffset     = 2.1,
	DashMode      = 1, -- default Q/pro style
}

local Settings = {}
for k, v in pairs(Defaults) do Settings[k] = v end

local CONFIG = "zxclinux_bf.json"
local Enabled = false
local sliderHooks = {}
local activeGlide = nil
local camPrevType = nil

local function save()
	if not writefile then return end
	pcall(function()
		writefile(CONFIG, HttpService:JSONEncode(Settings))
	end)
end

local function load()
	if not (isfile and readfile) then return end
	local ok, raw = pcall(function()
		if isfile(CONFIG) then return readfile(CONFIG) end
	end)
	if not ok or not raw then return end
	local ok2, data = pcall(function() return HttpService:JSONDecode(raw) end)
	if ok2 and type(data) == "table" then
		for k in pairs(Defaults) do
			if type(data[k]) == "number" then Settings[k] = data[k] end
		end
	end
end
pcall(load)

local function getHRP(char)
	if not char then return end
	return char:FindFirstChild("HumanoidRootPart")
		or char:FindFirstChild("Torso")
		or char:FindFirstChild("UpperTorso")
end

local function press(key)
	if not Enabled or not VIM then return end
	VIM:SendKeyEvent(true, key, false, game)
	VIM:SendKeyEvent(false, key, false, game)
end

local function rollChance()
	return math.random(1, 100) <= math.clamp(Settings.Chance, 0, 100)
end

local function isPlayerCharacter(char)
	if not char then return false end
	for _, pl in ipairs(Players:GetPlayers()) do
		if pl.Character == char then return true end
	end
	return false
end

-- nearest player OR npc/dummy (models with Humanoid + HP on custom maps)
local function nearest(maxRange)
	local my = getHRP(LP.Character)
	if not my then return end
	local best, bestD = nil, maxRange

	for _, pl in ipairs(Players:GetPlayers()) do
		if pl ~= LP and pl.Character then
			local hrp = getHRP(pl.Character)
			local hum = pl.Character:FindFirstChildOfClass("Humanoid")
			if hum and hrp and hum.Health > 0 then
				local d = (my.Position - hrp.Position).Magnitude
				if d < bestD then bestD, best = d, pl.Character end
			end
		end
	end

	for _, inst in ipairs(workspace:GetDescendants()) do
		if inst:IsA("Model") and inst ~= LP.Character and not isPlayerCharacter(inst) then
			local hum = inst:FindFirstChildOfClass("Humanoid")
			local hrp = getHRP(inst)
			if hum and hrp and hum.Health > 0 then
				local d = (my.Position - hrp.Position).Magnitude
				if d < bestD then bestD, best = d, inst end
			end
		end
	end

	return best
end

local function ragdolled(char)
	if not char then return false end
	local hum = char:FindFirstChildOfClass("Humanoid")
	local hrp = getHRP(char)
	if not (hum and hrp) then return false end
	return hum:GetState() == Enum.HumanoidStateType.Physics
		or math.abs(hrp.CFrame.UpVector.Y) < 0.7
end

local function playingAnimId()
	local char = LP.Character
	local hum = char and char:FindFirstChildOfClass("Humanoid")
	local animator = hum and hum:FindFirstChildOfClass("Animator")
	if not animator then return end
	for _, track in ipairs(animator:GetPlayingAnimationTracks()) do
		local id = track.Animation.AnimationId
		if ChainAnims[id] then return id end
	end
end

local function stopGlide()
	if activeGlide then
		activeGlide:Disconnect()
		activeGlide = nil
	end
	local char = LP.Character
	local hum = char and char:FindFirstChildOfClass("Humanoid")
	if hum then hum.AutoRotate = true end
	if camPrevType ~= nil and Camera then
		Camera.CameraType = camPrevType
		camPrevType = nil
	end
end

-- Pro camera: over-shoulder follow (not noob overhead lock staring at enemy)
local function syncCamPro(hrp, tHRP, dt)
	if not hrp or not Camera then return end
	dt = dt or 0.016
	local flatLook = Vector3.new(hrp.CFrame.LookVector.X, 0, hrp.CFrame.LookVector.Z)
	if flatLook.Magnitude < 0.05 then
		flatLook = Vector3.new(0, 0, -1)
	else
		flatLook = flatLook.Unit
	end
	local right = Vector3.new(flatLook.Z, 0, -flatLook.X)
	local height = Settings.CamOffset or 2.1
	local camPos = hrp.Position - flatLook * 5.8 + right * 1.55 + Vector3.new(0, height, 0)

	local lookPoint = hrp.Position + flatLook * 6 + Vector3.new(0, 1.15, 0)
	if tHRP and tHRP.Parent then
		local toEnemy = tHRP.Position + Vector3.new(0, 1.1, 0)
		lookPoint = lookPoint:Lerp(toEnemy, 0.38)
	end

	local goal = CFrame.new(camPos, lookPoint)
	local alpha = math.clamp((dt or 0.016) * 16, 0.2, 1)
	Camera.CFrame = Camera.CFrame:Lerp(goal, alpha)
end

local function startChain()
	if not Enabled then return end
	local animId = playingAnimId()
	if not animId then return end

	local target = nearest(Settings.Range)
	local myHRP = getHRP(LP.Character)
	local hum = LP.Character and LP.Character:FindFirstChildOfClass("Humanoid")
	if not (target and myHRP and hum) then return end
	if ragdolled(target) then return end

	local tHRP = getHRP(target)
	if not tHRP or not tHRP.Parent then return end

	local mode = math.floor((Settings.DashMode or 1) + 0.5)
	local goStraight = StraightAnims and StraightAnims[animId] == true
	local startTime = tick()
	local startPos = Vector3.new(myHRP.Position.X, 0, myHRP.Position.Z)

	stopGlide()
	hum.AutoRotate = false
	camPrevType = Camera.CameraType
	Camera.CameraType = Enum.CameraType.Custom

	if mode >= 1 then
		-- Pro: face back + Q dash, then short curved settle (like clean BF chain)
		local targetPos = Vector3.new(tHRP.Position.X, 0, tHRP.Position.Z)
		local behindDir = Vector3.new(tHRP.CFrame.LookVector.X, 0, tHRP.CFrame.LookVector.Z)
		behindDir = behindDir.Magnitude > 0.05 and behindDir.Unit or Vector3.new(0, 0, -1)
		local endPos = targetPos - behindDir * Settings.Radius
		myHRP.CFrame = CFrame.new(myHRP.Position, Vector3.new(endPos.X, myHRP.Position.Y, endPos.Z))
		syncCamPro(myHRP, tHRP, 0.05)
		press(Enum.KeyCode.Q)
	end

	-- Curve path like original black flash chain (pro-tuned)
	local targetPos0 = Vector3.new(tHRP.Position.X, 0, tHRP.Position.Z)
	local behindDir0 = Vector3.new(tHRP.CFrame.LookVector.X, 0, tHRP.CFrame.LookVector.Z)
	behindDir0 = behindDir0.Magnitude > 0.05 and behindDir0.Unit or Vector3.new(0, 0, -1)
	local endPos0 = targetPos0 - behindDir0 * Settings.Radius

	local controlPt
	if not goStraight then
		local mid = (startPos + endPos0) * 0.5
		local toTarget = targetPos0 - startPos
		local flatDist = toTarget.Magnitude
		local dirNorm = flatDist > 0.1 and (toTarget / flatDist) or Vector3.new(1, 0, 0)
		local perp = Vector3.new(-dirNorm.Z, 0, dirNorm.X)
		-- tighter arc than noob wide swing
		local width = math.clamp((Settings.CurveStrength or 9) * 0.85, 4, 14)
		controlPt = mid + perp * math.min(width, math.max(flatDist * 0.45, 5))
	end

	activeGlide = RunService.RenderStepped:Connect(function(dt)
		if not Enabled or not myHRP.Parent or not tHRP.Parent then
			stopGlide()
			return
		end

		-- live update end point (they turn / move)
		local targetPos = Vector3.new(tHRP.Position.X, 0, tHRP.Position.Z)
		local behindDir = Vector3.new(tHRP.CFrame.LookVector.X, 0, tHRP.CFrame.LookVector.Z)
		behindDir = behindDir.Magnitude > 0.05 and behindDir.Unit or Vector3.new(0, 0, -1)
		local endPos = targetPos - behindDir * Settings.Radius

		local dur = math.max(Settings.Duration, 0.08)
		if mode >= 1 then dur = math.max(dur, 0.12) end
		local alpha = math.clamp((tick() - startTime) / dur, 0, 1)
		local t = 1 - (1 - alpha) ^ 2 -- same ease as original
		local t1 = 1 - t

		local moveFlat
		if goStraight or not controlPt then
			moveFlat = startPos:Lerp(endPos, t)
		else
			-- live bend end control toward current endPos
			local ctrl = controlPt:Lerp(endPos, 0.15)
			moveFlat = Vector3.new(
				(t1 * t1) * startPos.X + (2 * t1 * t) * ctrl.X + (t * t) * endPos.X,
				0,
				(t1 * t1) * startPos.Z + (2 * t1 * t) * ctrl.Z + (t * t) * endPos.Z
			)
		end

		local movePos = Vector3.new(moveFlat.X, myHRP.Position.Y, moveFlat.Z)
		local lookAt = Vector3.new(tHRP.Position.X, movePos.Y, tHRP.Position.Z)
		myHRP.CFrame = CFrame.new(movePos, lookAt)
		syncCamPro(myHRP, tHRP, dt)

		if alpha >= 1 then
			local finish = Vector3.new(endPos.X, myHRP.Position.Y, endPos.Z)
			myHRP.CFrame = CFrame.new(finish, lookAt)
			syncCamPro(myHRP, tHRP, 0.05)
			stopGlide()
		end
	end)
end
local function onCharacter(char)
	local hum = char:WaitForChild("Humanoid", 5)
	local animator = hum and hum:WaitForChild("Animator", 5)
	if not animator then return end

	animator.AnimationPlayed:Connect(function(track)
		if not Authenticated or not Enabled then return end
		local base = ChainAnims[track.Animation.AnimationId]
		if not base then return end
		if not rollChance() then return end
		task.delay(base, function()
			if hum.Health > 0 and Enabled then
				press(Enum.KeyCode.Three)
			end
		end)
	end)
end

if LP.Character then onCharacter(LP.Character) end
LP.CharacterAdded:Connect(onCharacter)

local gui = Instance.new("ScreenGui")
gui.Name = "zxclinuxBF"
gui.ResetOnSpawn = false
gui.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
gui.DisplayOrder = 120
pcall(function() gui.Parent = game:GetService("CoreGui") end)
if not gui.Parent then gui.Parent = LP:WaitForChild("PlayerGui") end

local hint = Instance.new("TextLabel")
hint.Size = UDim2.fromOffset(250, 28)
hint.Position = UDim2.fromOffset(20, 20)
hint.BackgroundColor3 = Color3.fromRGB(12, 12, 12)
hint.TextColor3 = Color3.fromRGB(180, 80, 80)
hint.Text = "RightShift - zxclinux menu"
hint.Font = Enum.Font.Gotham
hint.TextSize = 13
hint.BorderSizePixel = 0
hint.Visible = false
hint.Parent = gui
Instance.new("UICorner", hint).CornerRadius = UDim.new(0, 8)
UI.hint = hint

local function resolveBgAsset()
	local fromCdn = ensureCdnAsset("zxclinux_bg.png")
	if fromCdn then return fromCdn end
	local paths = {
		"zxclinux_bg.png",
		"scripts/zxclinux_bg.png",
		"zxclinux_cache/zxclinux_bg.png",
		"i.webp",
		"C:/Users/socia/Desktop/scripts/zxclinux_bg.png",
		"C:/Users/socia/Desktop/i.webp",
	}
	if typeof(getcustomasset) == "function" then
		for _, path in ipairs(paths) do
			local ok, asset = pcall(getcustomasset, path)
			if ok and asset and asset ~= "" then return asset end
		end
	end
	return nil
end

local function resolveSoundAsset()
	local fromCdn = ensureCdnAsset("tuturu_1.mp3")
	if fromCdn then return fromCdn end
	local paths = {
		"tuturu_1.mp3",
		"scripts/tuturu_1.mp3",
		"zxclinux_cache/tuturu_1.mp3",
		"C:/Users/socia/Downloads/tuturu_1.mp3",
		"C:/Users/socia/Desktop/scripts/tuturu_1.mp3",
	}
	if typeof(getcustomasset) == "function" then
		for _, path in ipairs(paths) do
			local ok, asset = pcall(getcustomasset, path)
			if ok and asset and asset ~= "" then return asset end
		end
	end
	return nil
end

local function playUnlockSound()
	local asset = resolveSoundAsset()
	if not asset then return end
	local snd = Instance.new("Sound")
	snd.SoundId = asset
	snd.Volume = 1
	snd.Parent = gui
	snd:Play()
	snd.Ended:Connect(function() snd:Destroy() end)
end

local win = Instance.new("Frame")
win.Name = "MainWin"
win.Size = UDim2.fromOffset(320, 420)
win.Position = UDim2.new(0, 20, 0.5, -180)
win.BackgroundColor3 = BG
win.BackgroundTransparency = themeColors().WIN_TRANS
win.BorderSizePixel = 0
win.Active = true
win.Draggable = true
win.ClipsDescendants = true
win.Visible = false
win.Parent = gui
Instance.new("UICorner", win).CornerRadius = UDim.new(0, 12)
local winStroke = Instance.new("UIStroke", win)
winStroke.Color = STROKE_C
winStroke.Thickness = 1.5
winStroke.Transparency = themeColors().GLOW
UI.win = win
UI.winStroke = winStroke
pulseStroke(winStroke, themeColors().GLOW, themeColors().GLOW + 0.25)

local bgPhoto = Instance.new("ImageLabel")
bgPhoto.Name = "BackgroundPhoto"
bgPhoto.Size = UDim2.fromScale(1, 1)
bgPhoto.Position = UDim2.fromScale(0, 0)
bgPhoto.BackgroundTransparency = 1
bgPhoto.BorderSizePixel = 0
bgPhoto.ImageTransparency = themeColors().PHOTO_TRANS
bgPhoto.ScaleType = Enum.ScaleType.Crop
bgPhoto.ZIndex = 0
bgPhoto.Parent = win
Instance.new("UICorner", bgPhoto).CornerRadius = UDim.new(0, 12)
do
	task.defer(function()
		local asset = resolveBgAsset()
		if asset and bgPhoto and bgPhoto.Parent then
			bgPhoto.Image = asset
		end
	end)
end

UI.bgPhoto = bgPhoto

-- soft dark veil so text stays readable over the photo
local veil = Instance.new("Frame")
veil.Size = UDim2.fromScale(1, 1)
veil.BackgroundColor3 = themeColors().VEIL_TINT
veil.BackgroundTransparency = themeColors().VEIL
veil.BorderSizePixel = 0
veil.ZIndex = 1
veil.Parent = win
Instance.new("UICorner", veil).CornerRadius = UDim.new(0, 12)
UI.veil = veil

local head = Instance.new("Frame")
head.Size = UDim2.new(1, 0, 0, 56)
head.BackgroundColor3 = PANEL
head.BackgroundTransparency = 0.45
head.BorderSizePixel = 0
head.ZIndex = 2
head.Parent = win
Instance.new("UICorner", head).CornerRadius = UDim.new(0, 12)
local headFix = Instance.new("Frame")
headFix.Size = UDim2.new(1, 0, 0.5, 0)
headFix.Position = UDim2.new(0, 0, 0.5, 0)
headFix.BackgroundColor3 = PANEL
headFix.BackgroundTransparency = 0.45
headFix.BorderSizePixel = 0
headFix.ZIndex = 2
headFix.Parent = head
UI.head, UI.headFix = head, headFix

local headGrad = Instance.new("Frame")
headGrad.Size = UDim2.fromScale(1, 1)
headGrad.BackgroundColor3 = Color3.new(1, 1, 1)
headGrad.BackgroundTransparency = 0.35
headGrad.BorderSizePixel = 0
headGrad.ZIndex = 2
headGrad.Parent = head
Instance.new("UICorner", headGrad).CornerRadius = UDim.new(0, 12)
UI.headGrad = headGrad
setGradient(headGrad, themeColors().GRAD_A, themeColors().GRAD_B, 100)

local winAccent = Instance.new("Frame")
winAccent.Size = UDim2.new(1, -28, 0, 2)
winAccent.Position = UDim2.new(0, 14, 0, 54)
winAccent.BorderSizePixel = 0
winAccent.ZIndex = 4
winAccent.Parent = win
UI.winAccent = winAccent
setGradient(winAccent, ACCENT, ACCENT_H, 0)

local winShine = Instance.new("Frame")
winShine.Size = UDim2.new(1, 0, 0, 72)
winShine.BackgroundColor3 = Color3.new(1, 1, 1)
winShine.BackgroundTransparency = 0
winShine.BorderSizePixel = 0
winShine.ZIndex = 2
winShine.Parent = win
UI.winShine = winShine
setShine(winShine, themeColors().SHINE)

local title = Instance.new("TextLabel")
title.Size = UDim2.new(1, -190, 0, 22)
title.Position = UDim2.fromOffset(16, 8)
title.BackgroundTransparency = 1
title.Text = "zxclinux"
title.TextColor3 = TEXT_PRIMARY
title.Font = Enum.Font.GothamBold
title.TextSize = 17
title.TextXAlignment = Enum.TextXAlignment.Left
title.ZIndex = 3
title.Parent = head
UI.title = title

local sub = Instance.new("TextButton")
sub.Size = UDim2.new(1, -190, 0, 16)
sub.Position = UDim2.fromOffset(16, 32)
sub.BackgroundTransparency = 1
sub.Text = "tg: zxclinux.t.me  (copy)"
sub.TextColor3 = ACCENT
sub.Font = Enum.Font.Gotham
sub.TextSize = 11
sub.TextXAlignment = Enum.TextXAlignment.Left
sub.AutoButtonColor = false
sub.ZIndex = 3
sub.Parent = head
UI.sub = sub
sub.MouseButton1Click:Connect(function()
	if setclipboard then
		setclipboard("https://t.me/zxclinux")
		sub.Text = "copied"
		task.delay(1.1, function()
			if sub.Parent then sub.Text = "tg: zxclinux.t.me  (copy)" end
		end)
	end
end)

local themeBtn = Instance.new("TextButton")
themeBtn.Size = UDim2.fromOffset(56, 30)
themeBtn.Position = UDim2.new(1, -144, 0.5, -15)
themeBtn.BackgroundColor3 = PANEL
themeBtn.BackgroundTransparency = 0.35
themeBtn.Text = "DARK"
themeBtn.TextColor3 = ACCENT
themeBtn.Font = Enum.Font.GothamBold
themeBtn.TextSize = 10
themeBtn.BorderSizePixel = 0
themeBtn.ZIndex = 3
themeBtn.AutoButtonColor = false
themeBtn.Parent = head
Instance.new("UICorner", themeBtn).CornerRadius = UDim.new(0, 8)
UI.themeBtn = themeBtn

local onBtn = Instance.new("TextButton")
onBtn.Size = UDim2.fromOffset(72, 30)
onBtn.Position = UDim2.new(1, -82, 0.5, -15)
onBtn.BackgroundColor3 = ACCENT
onBtn.Text = "ON"
onBtn.TextColor3 = Color3.new(1, 1, 1)
onBtn.Font = Enum.Font.GothamBold
onBtn.TextSize = 12
onBtn.BorderSizePixel = 0
onBtn.ZIndex = 3
onBtn.Parent = head
Instance.new("UICorner", onBtn).CornerRadius = UDim.new(0, 8)
UI.onBtn = onBtn

local scroll = Instance.new("ScrollingFrame")
scroll.Size = UDim2.new(1, -24, 1, -116)
scroll.Position = UDim2.fromOffset(12, 64)
scroll.BackgroundTransparency = 1
scroll.BorderSizePixel = 0
scroll.ScrollBarThickness = 3
scroll.ScrollBarImageColor3 = ACCENT
scroll.AutomaticCanvasSize = Enum.AutomaticSize.Y
scroll.CanvasSize = UDim2.new()
scroll.ZIndex = 2
scroll.Parent = win
UI.scroll = scroll
local list = Instance.new("UIListLayout", scroll)
list.Padding = UDim.new(0, 8)
Instance.new("UIPadding", scroll).PaddingBottom = UDim.new(0, 8)

local function fmt(v, step)
	if step >= 1 then return tostring(math.floor(v + 0.5)) end
	return string.format("%.2f", v)
end

local function slider(name, desc, min, max, key, step)
	step = step or 0.01
	local row = Instance.new("Frame")
	row.Size = UDim2.new(1, -4, 0, 72)
	row.BackgroundColor3 = PANEL
	row.BackgroundTransparency = 0.42
	row.BorderSizePixel = 0
	row.ZIndex = 3
	row.Parent = scroll
	table.insert(UI.rows, row)
	Instance.new("UICorner", row).CornerRadius = UDim.new(0, 10)
	local rowStroke = Instance.new("UIStroke", row)
	rowStroke.Color = Color3.fromRGB(160, 40, 50)
	rowStroke.Transparency = 0.55
	rowStroke.Thickness = 1

	local nl = Instance.new("TextLabel")
	nl.Size = UDim2.new(1, -80, 0, 20)
	nl.Position = UDim2.fromOffset(12, 8)
	nl.BackgroundTransparency = 1
	nl.Text = name
	nl.TextColor3 = TEXT_PRIMARY
	nl.Font = Enum.Font.GothamBold
	nl.TextSize = 14
	nl.TextXAlignment = Enum.TextXAlignment.Left
	nl.ZIndex = 4
	nl.Parent = row

	local dl = Instance.new("TextLabel")
	dl.Size = UDim2.new(1, -16, 0, 14)
	dl.Position = UDim2.fromOffset(12, 28)
	dl.BackgroundTransparency = 1
	dl.Text = desc
	dl.TextColor3 = MUTED
	dl.Font = Enum.Font.Gotham
	dl.TextSize = 11
	dl.TextXAlignment = Enum.TextXAlignment.Left
	dl.ZIndex = 4
	dl.Parent = row

	local vl = Instance.new("TextLabel")
	vl.Size = UDim2.fromOffset(60, 20)
	vl.Position = UDim2.new(1, -70, 0, 8)
	vl.BackgroundTransparency = 1
	vl.Text = fmt(Settings[key], step)
	vl.TextColor3 = ACCENT_H
	vl.Font = Enum.Font.GothamBold
	vl.TextSize = 14
	vl.TextXAlignment = Enum.TextXAlignment.Right
	vl.ZIndex = 4
	vl.Parent = row

	local track = Instance.new("Frame")
	track.Size = UDim2.new(1, -24, 0, 6)
	track.Position = UDim2.fromOffset(12, 52)
	track.BackgroundColor3 = Color3.fromRGB(40, 20, 22)
	track.BorderSizePixel = 0
	track.BackgroundTransparency = 0.25
	track.ZIndex = 4
	track.Parent = row
	Instance.new("UICorner", track).CornerRadius = UDim.new(1, 0)

	local fill = Instance.new("Frame")
	fill.Size = UDim2.new((Settings[key] - min) / (max - min), 0, 1, 0)
	fill.BackgroundColor3 = ACCENT
	fill.BorderSizePixel = 0
	fill.ZIndex = 4
	fill.Parent = track
	Instance.new("UICorner", fill).CornerRadius = UDim.new(1, 0)

	local knob = Instance.new("TextButton")
	knob.Size = UDim2.fromOffset(16, 16)
	knob.Position = UDim2.new((Settings[key] - min) / (max - min), -8, 0.5, -8)
	knob.BackgroundColor3 = Color3.fromRGB(255, 90, 90)
	knob.Text = ""
	knob.BorderSizePixel = 0
	knob.ZIndex = 5
	knob.Parent = track
	Instance.new("UICorner", knob).CornerRadius = UDim.new(1, 0)

	local function apply(alpha)
		alpha = math.clamp(alpha, 0, 1)
		local v = math.clamp(math.round((min + (max - min) * alpha) / step) * step, min, max)
		local r = (v - min) / (max - min)
		fill.Size = UDim2.new(r, 0, 1, 0)
		knob.Position = UDim2.new(r, -8, 0.5, -8)
		vl.Text = fmt(v, step)
		Settings[key] = v
		save()
	end

	local drag = false
	local function fromX(x)
		if track.AbsoluteSize.X <= 0 then return end
		apply((x - track.AbsolutePosition.X) / track.AbsoluteSize.X)
	end

	knob.MouseButton1Down:Connect(function() drag = true end)
	track.InputBegan:Connect(function(i)
		if i.UserInputType == Enum.UserInputType.MouseButton1 or i.UserInputType == Enum.UserInputType.Touch then
			drag = true
			fromX(i.Position.X)
		end
	end)
	UIS.InputEnded:Connect(function(i)
		if i.UserInputType == Enum.UserInputType.MouseButton1 or i.UserInputType == Enum.UserInputType.Touch then
			drag = false
		end
	end)
	UIS.InputChanged:Connect(function(i)
		if drag and (i.UserInputType == Enum.UserInputType.MouseMovement or i.UserInputType == Enum.UserInputType.Touch) then
			fromX(i.Position.X)
		end
	end)

	table.insert(sliderHooks, function()
		Settings[key] = Defaults[key]
		local r = (Defaults[key] - min) / (max - min)
		fill.Size = UDim2.new(r, 0, 1, 0)
		knob.Position = UDim2.new(r, -8, 0.5, -8)
		vl.Text = fmt(Defaults[key], step)
	end)
end


local modeRow = Instance.new("Frame")
modeRow.Size = UDim2.new(1, -4, 0, 54)
modeRow.BackgroundColor3 = PANEL
modeRow.BackgroundTransparency = 0.42
modeRow.BorderSizePixel = 0
modeRow.ZIndex = 3
modeRow.Parent = scroll
UI.modeRow = modeRow
Instance.new("UICorner", modeRow).CornerRadius = UDim.new(0, 10)

local modeTitle = Instance.new("TextLabel")
modeTitle.Size = UDim2.new(1, -100, 0, 18)
modeTitle.Position = UDim2.fromOffset(12, 8)
modeTitle.BackgroundTransparency = 1
modeTitle.Text = "Dash Mode"
modeTitle.TextColor3 = TEXT_PRIMARY
modeTitle.Font = Enum.Font.GothamBold
modeTitle.TextSize = 14
modeTitle.TextXAlignment = Enum.TextXAlignment.Left
modeTitle.ZIndex = 4
modeTitle.Parent = modeRow

local modeDesc = Instance.new("TextLabel")
modeDesc.Size = UDim2.new(1, -16, 0, 14)
modeDesc.Position = UDim2.fromOffset(12, 30)
modeDesc.BackgroundTransparency = 1
modeDesc.Text = "TELEPORT = snap  |  Q DASH = pro curve"
modeDesc.TextColor3 = MUTED
modeDesc.Font = Enum.Font.Gotham
modeDesc.TextSize = 11
modeDesc.TextXAlignment = Enum.TextXAlignment.Left
modeDesc.ZIndex = 4
modeDesc.Parent = modeRow

local modeBtn = Instance.new("TextButton")
modeBtn.Size = UDim2.fromOffset(88, 28)
modeBtn.Position = UDim2.new(1, -98, 0.5, -14)
modeBtn.BackgroundColor3 = ACCENT
modeBtn.Text = (math.floor((Settings.DashMode or 1) + 0.5) >= 1) and "Q DASH" or "TELEPORT"
modeBtn.TextColor3 = Color3.new(1, 1, 1)
modeBtn.Font = Enum.Font.GothamBold
modeBtn.TextSize = 11
modeBtn.BorderSizePixel = 0
modeBtn.ZIndex = 4
modeBtn.Parent = modeRow
Instance.new("UICorner", modeBtn).CornerRadius = UDim.new(0, 8)
modeBtn.MouseButton1Click:Connect(function()
	Settings.DashMode = (math.floor(Settings.DashMode + 0.5) >= 1) and 0 or 1
	modeBtn.Text = (Settings.DashMode >= 1) and "Q DASH" or "TELEPORT"
	save()
end)
slider("Chain Chance", "Chance of black flash chain %", 0, 100, "Chance", 1)
slider("Dash Speed", "Lower = faster (pro default 0.18)", 0.08, 0.4, "Duration", 0.01)
slider("Behind Distance", "Straight behind back, studs", 1.5, 6, "Radius", 0.25)
slider("Range", "Target range", 10, 45, "Range", 1)

local footer = Instance.new("Frame")
footer.Size = UDim2.new(1, -24, 0, 40)
footer.Position = UDim2.new(0, 12, 1, -48)
footer.BackgroundTransparency = 1
footer.ZIndex = 2
footer.Parent = win

local reset = Instance.new("TextButton")
reset.Size = UDim2.new(0.48, 0, 1, 0)
reset.BackgroundColor3 = Color3.fromRGB(50, 25, 28)
reset.Text = "Reset"
reset.TextColor3 = Color3.fromRGB(220, 180, 180)
reset.Font = Enum.Font.GothamBold
reset.TextSize = 12
reset.BorderSizePixel = 0
reset.BackgroundTransparency = 0.25
reset.ZIndex = 3
reset.Parent = footer
Instance.new("UICorner", reset).CornerRadius = UDim.new(0, 8)

local tip = Instance.new("TextLabel")
tip.Size = UDim2.new(0.48, 0, 1, 0)
tip.Position = UDim2.new(0.52, 0, 0, 0)
tip.BackgroundColor3 = PANEL
tip.Text = "Hotkey: E"
tip.TextColor3 = MUTED
tip.Font = Enum.Font.Gotham
tip.TextSize = 12
tip.BorderSizePixel = 0
tip.BackgroundTransparency = 0.42
tip.ZIndex = 3
tip.Parent = footer
Instance.new("UICorner", tip).CornerRadius = UDim.new(0, 8)

reset.MouseButton1Click:Connect(function()
	for _, fn in ipairs(sliderHooks) do fn() end
	save()
end)

onBtn.MouseButton1Click:Connect(function()
	Enabled = not Enabled
	onBtn.Text = Enabled and "ON" or "OFF"
	onBtn.BackgroundColor3 = Enabled and ACCENT or Color3.fromRGB(70, 20, 25)
	if not Enabled then stopGlide() end
end)

local function applyTheme(nextName)
	ThemeName = nextName or ThemeName
	local t = pullTheme()

	if UI.win then
		UI.win.BackgroundColor3 = t.BG
		UI.win.BackgroundTransparency = t.WIN_TRANS
	end
	if UI.winStroke then
		UI.winStroke.Color = t.STROKE
		UI.winStroke.Transparency = t.GLOW
	end
	if UI.veil then
		UI.veil.BackgroundColor3 = t.VEIL_TINT
		UI.veil.BackgroundTransparency = t.VEIL
	end
	if UI.bgPhoto then UI.bgPhoto.ImageTransparency = t.PHOTO_TRANS end
	if UI.hint then
		UI.hint.BackgroundColor3 = t.HINT_BG
		UI.hint.TextColor3 = t.ACCENT
	end
	if UI.head then
		UI.head.BackgroundColor3 = t.PANEL
		UI.headFix.BackgroundColor3 = t.PANEL
	end
	setGradient(UI.headGrad, t.GRAD_A, t.GRAD_B, 100)
	setGradient(UI.winAccent, t.ACCENT, t.ACCENT_H, 0)
	setShine(UI.winShine, t.SHINE)
	if UI.title then UI.title.TextColor3 = t.TEXT end
	if UI.sub then UI.sub.TextColor3 = t.ACCENT end
	if UI.themeBtn then
		UI.themeBtn.Text = ThemeName == "Light" and "WHITE" or "DARK"
		UI.themeBtn.TextColor3 = t.ACCENT
		UI.themeBtn.BackgroundColor3 = t.PANEL
	end
	if UI.onBtn and Enabled then UI.onBtn.BackgroundColor3 = t.ACCENT end
	if UI.scroll then UI.scroll.ScrollBarImageColor3 = t.ACCENT end
	if UI.modeRow then UI.modeRow.BackgroundColor3 = t.ROW end
	for _, row in ipairs(UI.rows) do
		if row.Parent then row.BackgroundColor3 = t.ROW end
	end
	if UI.authFrame then
		UI.authFrame.BackgroundColor3 = t.BG
		UI.authFrame.BackgroundTransparency = t.WIN_TRANS
	end
	if UI.authStroke then
		UI.authStroke.Color = t.STROKE
		UI.authStroke.Transparency = t.GLOW
	end
	if UI.authVeil then
		UI.authVeil.BackgroundColor3 = t.VEIL_TINT
		UI.authVeil.BackgroundTransparency = t.VEIL
	end
	if UI.authBg then UI.authBg.ImageTransparency = t.PHOTO_TRANS end
	if UI.authHead then UI.authHead.BackgroundColor3 = t.PANEL end
	if UI.authHeadFix then UI.authHeadFix.BackgroundColor3 = t.PANEL end
	setGradient(UI.authHeadGrad, t.GRAD_A, t.GRAD_B, 100)
	setGradient(UI.authAccent, t.ACCENT, t.ACCENT_H, 0)
	setShine(UI.authShine, t.SHINE)
	if UI.authTitle then UI.authTitle.TextColor3 = t.TEXT end
	if UI.authHint then UI.authHint.TextColor3 = t.ACCENT end
	if UI.authKeyMsg then UI.authKeyMsg.TextColor3 = t.TEXT end
	if UI.codeBox then
		UI.codeBox.BackgroundColor3 = t.ROW
		UI.codeBox.TextColor3 = t.TEXT
		setPlaceholder(UI.codeBox, "введите ключ...", t.MUTED)
		if UI.codeStroke then UI.codeStroke.Color = t.STROKE end
	end
	if UI.authBtn then UI.authBtn.BackgroundColor3 = t.ACCENT end
	if UI.authThemeBtn then
		UI.authThemeBtn.Text = ThemeName == "Light" and "WHITE" or "DARK"
		UI.authThemeBtn.TextColor3 = t.ACCENT
		UI.authThemeBtn.BackgroundColor3 = t.PANEL
	end
end

local function toggleTheme()
	applyTheme(ThemeName == "Dark" and "Light" or "Dark")
end

themeBtn.MouseButton1Click:Connect(toggleTheme)

-- styled login (same look as main menu)
local auth = Instance.new("Frame")
auth.Name = "AuthGate"
auth.Size = UDim2.fromOffset(340, 332)
auth.Position = UDim2.new(0.5, -170, 0.5, -166)
auth.BackgroundColor3 = BG
auth.BackgroundTransparency = themeColors().WIN_TRANS
auth.BorderSizePixel = 0
auth.Active = true
auth.Draggable = true
auth.ClipsDescendants = true
auth.ZIndex = 50
auth.Parent = gui
Instance.new("UICorner", auth).CornerRadius = UDim.new(0, 14)
local authStroke = Instance.new("UIStroke", auth)
authStroke.Color = STROKE_C
authStroke.Thickness = 1.5
authStroke.Transparency = themeColors().GLOW
UI.authFrame, UI.authStroke = auth, authStroke
pulseStroke(authStroke, themeColors().GLOW, themeColors().GLOW + 0.22)

local authScale = Instance.new("UIScale")
authScale.Parent = auth
UI.authScale = authScale

local authBg = Instance.new("ImageLabel")
authBg.Size = UDim2.fromScale(1, 1)
authBg.BackgroundTransparency = 1
authBg.ImageTransparency = themeColors().PHOTO_TRANS
authBg.ScaleType = Enum.ScaleType.Crop
authBg.ZIndex = 0
authBg.Parent = auth
Instance.new("UICorner", authBg).CornerRadius = UDim.new(0, 14)
do
	task.defer(function()
		local asset = resolveBgAsset()
		if asset and authBg and authBg.Parent then
			authBg.Image = asset
		end
	end)
end
UI.authBg = authBg

local authVeil = Instance.new("Frame")
authVeil.Size = UDim2.fromScale(1, 1)
authVeil.BackgroundColor3 = themeColors().VEIL_TINT
authVeil.BackgroundTransparency = themeColors().VEIL
authVeil.BorderSizePixel = 0
authVeil.ZIndex = 1
authVeil.Parent = auth
Instance.new("UICorner", authVeil).CornerRadius = UDim.new(0, 14)
UI.authVeil = authVeil

local authShine = Instance.new("Frame")
authShine.Size = UDim2.new(1, 0, 0, 88)
authShine.BackgroundColor3 = Color3.new(1, 1, 1)
authShine.BackgroundTransparency = 0
authShine.BorderSizePixel = 0
authShine.ZIndex = 2
authShine.Parent = auth
UI.authShine = authShine
setShine(authShine, themeColors().SHINE)

local authHead = Instance.new("Frame")
authHead.Size = UDim2.new(1, 0, 0, 58)
authHead.BackgroundColor3 = PANEL
authHead.BackgroundTransparency = 0.45
authHead.BorderSizePixel = 0
authHead.ZIndex = 3
authHead.Parent = auth
Instance.new("UICorner", authHead).CornerRadius = UDim.new(0, 14)
local authHeadFix = Instance.new("Frame")
authHeadFix.Size = UDim2.new(1, 0, 0.5, 0)
authHeadFix.Position = UDim2.new(0, 0, 0.5, 0)
authHeadFix.BackgroundColor3 = PANEL
authHeadFix.BackgroundTransparency = 0.45
authHeadFix.BorderSizePixel = 0
authHeadFix.ZIndex = 3
authHeadFix.Parent = authHead
UI.authHead, UI.authHeadFix = authHead, authHeadFix

local authHeadGrad = Instance.new("Frame")
authHeadGrad.Size = UDim2.fromScale(1, 1)
authHeadGrad.BackgroundColor3 = Color3.new(1, 1, 1)
authHeadGrad.BackgroundTransparency = 0.35
authHeadGrad.BorderSizePixel = 0
authHeadGrad.ZIndex = 3
authHeadGrad.Parent = authHead
Instance.new("UICorner", authHeadGrad).CornerRadius = UDim.new(0, 14)
UI.authHeadGrad = authHeadGrad
setGradient(authHeadGrad, themeColors().GRAD_A, themeColors().GRAD_B, 100)

local authAccent = Instance.new("Frame")
authAccent.Size = UDim2.new(1, -28, 0, 2)
authAccent.Position = UDim2.new(0, 14, 0, 56)
authAccent.BorderSizePixel = 0
authAccent.ZIndex = 4
authAccent.Parent = auth
UI.authAccent = authAccent
setGradient(authAccent, ACCENT, ACCENT_H, 0)

local authTitle = Instance.new("TextLabel")
authTitle.Size = UDim2.new(1, -120, 0, 22)
authTitle.Position = UDim2.fromOffset(16, 8)
authTitle.BackgroundTransparency = 1
authTitle.Text = "zxclinux"
authTitle.Font = Enum.Font.GothamBold
authTitle.TextSize = 18
authTitle.TextColor3 = TEXT_PRIMARY
authTitle.TextXAlignment = Enum.TextXAlignment.Left
authTitle.ZIndex = 5
authTitle.Parent = authHead
UI.authTitle = authTitle

local authSub = Instance.new("TextLabel")
authSub.Size = UDim2.new(1, -120, 0, 16)
authSub.Position = UDim2.fromOffset(16, 34)
authSub.BackgroundTransparency = 1
authSub.Text = "tg: zxclinux.t.me"
authSub.Font = Enum.Font.Gotham
authSub.TextSize = 11
authSub.TextColor3 = ACCENT
authSub.TextXAlignment = Enum.TextXAlignment.Left
authSub.ZIndex = 5
authSub.Parent = authHead
UI.authHint = authSub

local authThemeBtn = Instance.new("TextButton")
authThemeBtn.Size = UDim2.fromOffset(56, 30)
authThemeBtn.Position = UDim2.new(1, -72, 0.5, -15)
authThemeBtn.BackgroundColor3 = PANEL
authThemeBtn.BackgroundTransparency = 0.35
authThemeBtn.Text = ThemeName == "Light" and "WHITE" or "DARK"
authThemeBtn.TextColor3 = ACCENT
authThemeBtn.Font = Enum.Font.GothamBold
authThemeBtn.TextSize = 10
authThemeBtn.BorderSizePixel = 0
authThemeBtn.ZIndex = 5
authThemeBtn.AutoButtonColor = false
authThemeBtn.Parent = authHead
Instance.new("UICorner", authThemeBtn).CornerRadius = UDim.new(0, 8)
UI.authThemeBtn = authThemeBtn
authThemeBtn.MouseButton1Click:Connect(toggleTheme)

local authBody = Instance.new("Frame")
authBody.Size = UDim2.new(1, -28, 1, -78)
authBody.Position = UDim2.fromOffset(14, 68)
authBody.BackgroundTransparency = 1
authBody.ZIndex = 4
authBody.Parent = auth

local authKeyMsg = Instance.new("TextLabel")
authKeyMsg.Size = UDim2.new(1, 0, 0, 44)
authKeyMsg.BackgroundTransparency = 1
authKeyMsg.Text = "Возьмите свой ключ для скрипта\nу автора zxclinux"
authKeyMsg.Font = Enum.Font.Gotham
authKeyMsg.TextSize = 13
authKeyMsg.TextColor3 = TEXT_PRIMARY
authKeyMsg.TextWrapped = true
authKeyMsg.TextXAlignment = Enum.TextXAlignment.Center
authKeyMsg.TextYAlignment = Enum.TextYAlignment.Center
authKeyMsg.ZIndex = 4
authKeyMsg.Parent = authBody
UI.authKeyMsg = authKeyMsg

local codeBox = Instance.new("TextBox")
codeBox.Size = UDim2.new(1, 0, 0, 40)
codeBox.Position = UDim2.fromOffset(0, 52)
codeBox.BackgroundColor3 = themeColors().ROW
codeBox.BackgroundTransparency = 0.12
codeBox.Text = ""
codeBox.TextColor3 = TEXT_PRIMARY
setPlaceholder(codeBox, "введите ключ...", MUTED)
codeBox.Font = Enum.Font.Gotham
codeBox.TextSize = 15
codeBox.ClearTextOnFocus = false
codeBox.BorderSizePixel = 0
codeBox.ZIndex = 4
codeBox.Parent = authBody
Instance.new("UICorner", codeBox).CornerRadius = UDim.new(0, 10)
local codeStroke = Instance.new("UIStroke", codeBox)
codeStroke.Color = STROKE_C
codeStroke.Thickness = 1.2
UI.codeBox = codeBox
UI.codeStroke = codeStroke

local authErr = Instance.new("TextLabel")
authErr.Size = UDim2.new(1, 0, 0, 16)
authErr.Position = UDim2.fromOffset(0, 98)
authErr.BackgroundTransparency = 1
authErr.Text = ""
authErr.Font = Enum.Font.Gotham
authErr.TextSize = 11
authErr.TextColor3 = ACCENT_H
authErr.TextXAlignment = Enum.TextXAlignment.Center
authErr.ZIndex = 4
authErr.Parent = authBody
UI.authErr = authErr

local authBtn = Instance.new("TextButton")
authBtn.Size = UDim2.new(1, 0, 0, 38)
authBtn.Position = UDim2.fromOffset(0, 124)
authBtn.BackgroundColor3 = ACCENT
authBtn.Text = ""
authBtn.BorderSizePixel = 0
authBtn.AutoButtonColor = false
authBtn.ZIndex = 5
authBtn.Parent = authBody
Instance.new("UICorner", authBtn).CornerRadius = UDim.new(0, 10)
local authBtnGrad = Instance.new("Frame")
authBtnGrad.Size = UDim2.fromScale(1, 1)
authBtnGrad.BackgroundColor3 = Color3.new(1, 1, 1)
authBtnGrad.BackgroundTransparency = 0.55
authBtnGrad.BorderSizePixel = 0
authBtnGrad.Active = false
authBtnGrad.ZIndex = 5
authBtnGrad.Parent = authBtn
Instance.new("UICorner", authBtnGrad).CornerRadius = UDim.new(0, 10)
setGradient(authBtnGrad, ACCENT_H, ACCENT, 45)

local authBtnLabel = Instance.new("TextLabel")
authBtnLabel.Size = UDim2.fromScale(1, 1)
authBtnLabel.BackgroundTransparency = 1
authBtnLabel.Text = "Войти"
authBtnLabel.TextColor3 = Color3.new(1, 1, 1)
authBtnLabel.Font = Enum.Font.GothamBold
authBtnLabel.TextSize = 14
authBtnLabel.ZIndex = 6
authBtnLabel.Parent = authBtn
UI.authBtn = authBtn

popIn(auth, authScale)

local function unlockMain()
	local raw = codeBox.Text or ""
	local entered = string.lower(string.gsub(raw, "%s+", ""))
	if entered == "" then
		authErr.Text = "введите ключ"
		return
	end
	if entered ~= ACCESS_CODE then
		authErr.Text = "неверный ключ"
		return
	end
	Authenticated = true
	Enabled = true
	authErr.Text = ""
	win.Visible = true
	hint.Visible = false
	playUnlockSound()
	task.defer(function()
		if auth and auth.Parent then auth:Destroy() end
	end)
end

authBtn.MouseButton1Click:Connect(unlockMain)
codeBox.FocusLost:Connect(function(enter)
	if enter then unlockMain() end
end)
task.defer(function()
	pcall(function() codeBox:CaptureFocus() end)
end)

auth.Visible = true
gui.Enabled = true

applyTheme(ThemeName)

UIS.InputBegan:Connect(function(input, processed)
	if not Authenticated then return end
	if input.KeyCode == Enum.KeyCode.RightShift then
		local open = not win.Visible
		win.Visible = open
		hint.Visible = not open
		return
	end
	if processed or not Enabled then return end
	if input.KeyCode == Enum.KeyCode.E then
		if not rollChance() then return end
		press(Enum.KeyCode.Three)
		task.wait(0.12)
		startChain()
	end
end)

end)
if not okRun then
	warn("[zxclinux] error:", runErr)
end