text paste
--[[ IMPRA v1.2 | Key: jointodiscord | Discord: https://discord.gg/MrXgJC4GK ]]

if not game:IsLoaded() then game.Loaded:Wait() end
local Players      = game:GetService("Players")
local UIS          = game:GetService("UserInputService")
local RunService   = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
local Lighting     = game:GetService("Lighting")
local LP = Players.LocalPlayer
local PG = LP:WaitForChild("PlayerGui")
if PG:FindFirstChild("IMPRA") then PG.IMPRA:Destroy() end

print("[IMPRA] v1.2 loading...")

local CONFIG = {KEY="jointodiscord", DISCORD="https://discord.gg/MrXgJC4GK", VERSION="1.2", DEF_THEME="Dark"}

-- THEMES
local Themes = {
    Dark     = {BG=Color3.fromRGB(15,15,18),BG2=Color3.fromRGB(22,22,27),BG3=Color3.fromRGB(30,30,36),
                ACCENT=Color3.fromRGB(255,255,255),TEXT=Color3.fromRGB(240,240,240),SUB=Color3.fromRGB(150,150,155),
                BORDER=Color3.fromRGB(45,45,52),DANGER=Color3.fromRGB(255,80,80),SUCCESS=Color3.fromRGB(80,220,120)},
    Light    = {BG=Color3.fromRGB(248,248,250),BG2=Color3.fromRGB(235,235,240),BG3=Color3.fromRGB(220,220,225),
                ACCENT=Color3.fromRGB(30,30,30),TEXT=Color3.fromRGB(20,20,22),SUB=Color3.fromRGB(100,100,105),
                BORDER=Color3.fromRGB(200,200,205),DANGER=Color3.fromRGB(200,50,50),SUCCESS=Color3.fromRGB(30,160,80)},
    Midnight = {BG=Color3.fromRGB(8,10,22),BG2=Color3.fromRGB(16,20,38),BG3=Color3.fromRGB(24,30,52),
                ACCENT=Color3.fromRGB(120,160,255),TEXT=Color3.fromRGB(220,228,255),SUB=Color3.fromRGB(140,155,195),
                BORDER=Color3.fromRGB(38,46,72),DANGER=Color3.fromRGB(255,100,100),SUCCESS=Color3.fromRGB(100,220,160)},
    Contrast = {BG=Color3.fromRGB(0,0,0),BG2=Color3.fromRGB(20,20,20),BG3=Color3.fromRGB(35,35,35),
                ACCENT=Color3.fromRGB(255,210,0),TEXT=Color3.fromRGB(255,255,255),SUB=Color3.fromRGB(180,180,180),
                BORDER=Color3.fromRGB(255,255,255),DANGER=Color3.fromRGB(255,80,80),SUCCESS=Color3.fromRGB(80,255,130)},
}
local CurrentTheme = CONFIG.DEF_THEME
local function T() return Themes[CurrentTheme] end
local themeFns = {}
local function onTheme(fn) pcall(fn, Themes[CurrentTheme]); table.insert(themeFns, fn) end
local function applyTheme(n)
    if not Themes[n] then return end
    CurrentTheme = n
    for _, fn in ipairs(themeFns) do pcall(fn, Themes[n]) end
end

-- HELPERS
local function new(class, props)
    local o = Instance.new(class)
    for k, v in pairs(props) do if k ~= "Parent" then pcall(function() o[k]=v end) end end
    if props.Parent then o.Parent = props.Parent end
    return o
end
local function corner(p, r) return new("UICorner", {CornerRadius=UDim.new(0, r or 8), Parent=p}) end
local function stroke(p, c, t) return new("UIStroke", {Color=c or T().BORDER, Thickness=t or 1, Parent=p}) end
local connections = {}
local function track(c) table.insert(connections, c); return c end

local function getScale(f)
    local s = f:FindFirstChild("IMPRA_Scale")
    if not s then s = Instance.new("UIScale"); s.Name="IMPRA_Scale"; s.Scale=1; s.Parent=f end
    return s
end
local function popIn(f, d)
    local s = getScale(f); s.Scale = 0.7
    TweenService:Create(s, TweenInfo.new(d or 0.4, Enum.EasingStyle.Back, Enum.EasingDirection.Out), {Scale=1}):Play()
end
local function popOut(f, d, cb)
    local t = TweenService:Create(getScale(f), TweenInfo.new(d or 0.25, Enum.EasingStyle.Quad, Enum.EasingDirection.In), {Scale=0.7})
    t:Play(); if cb then t.Completed:Connect(cb) end
end
local function addHover(b, gN, gH)
    local s = getScale(b); local h = false
    b.MouseEnter:Connect(function()
        h=true
        TweenService:Create(s, TweenInfo.new(0.15), {Scale=1.03}):Play()
        TweenService:Create(b, TweenInfo.new(0.15), {BackgroundColor3=gH()}):Play()
    end)
    b.MouseLeave:Connect(function()
        h=false
        TweenService:Create(s, TweenInfo.new(0.15), {Scale=1}):Play()
        TweenService:Create(b, TweenInfo.new(0.15), {BackgroundColor3=gN()}):Play()
    end)
    onTheme(function() b.BackgroundColor3 = h and gH() or gN() end)
end
local function addRipple(b)
    b.ClipsDescendants = true
    b.MouseButton1Click:Connect(function()
        pcall(function()
            local r = Instance.new("Frame")
            r.AnchorPoint = Vector2.new(0.5,0.5)
            r.Position = UDim2.fromScale(0.5,0.5)
            r.Size = UDim2.fromOffset(0,0)
            r.BackgroundColor3 = Color3.new(1,1,1)
            r.BackgroundTransparency = 0.65
            r.BorderSizePixel = 0
            r.ZIndex = b.ZIndex + 1
            r.Parent = b
            local c = Instance.new("UICorner"); c.CornerRadius = UDim.new(1,0); c.Parent = r
            local tgt = math.max(b.AbsoluteSize.X, b.AbsoluteSize.Y) * 2
            TweenService:Create(r, TweenInfo.new(0.5), {Size=UDim2.fromOffset(tgt,tgt), BackgroundTransparency=1}):Play()
            task.delay(0.55, function() pcall(function() r:Destroy() end) end)
        end)
    end)
end
local function polishBtn(b, gN, gH)
    if gN and gH then addHover(b, gN, gH) end
    addRipple(b)
end
local function makeDraggable(frame, handle, excludes)
    local dragging, ds, sp = false, nil, nil
    local s = getScale(frame)
    excludes = excludes or {}
    local function isExcluded(t)
        for _, ex in ipairs(excludes) do
            if t == ex then return true end
            local ok, r = pcall(function() return t:IsDescendantOf(ex) end)
            if ok and r then return true end
        end
        return false
    end
    handle.InputBegan:Connect(function(i)
        if i.UserInputType ~= Enum.UserInputType.MouseButton1 then return end
        if isExcluded(i.Target) then return end
        dragging = true; ds = i.Position; sp = frame.Position
        TweenService:Create(s, TweenInfo.new(0.15), {Scale=1.02}):Play()
    end)
    UIS.InputChanged:Connect(function(i)
        if dragging and i.UserInputType == Enum.UserInputType.MouseMovement then
            local d = i.Position - ds
            frame.Position = UDim2.new(sp.X.Scale, sp.X.Offset+d.X, sp.Y.Scale, sp.Y.Offset+d.Y)
        end
    end)
    UIS.InputEnded:Connect(function(i)
        if i.UserInputType == Enum.UserInputType.MouseButton1 and dragging then
            dragging = false
            TweenService:Create(s, TweenInfo.new(0.15, Enum.EasingStyle.Back, Enum.EasingDirection.Out), {Scale=1}):Play()
        end
    end)
end

-- STATE
local state = {fly=false, flySpeed=50, noclip=false, esp=false, clickTp=false, fullbright=false}
local flyBV, noclipConn = nil, nil
local espObjects = {}
local origLight = {B=Lighting.Brightness, A=Lighting.Ambient, OA=Lighting.OutdoorAmbient, CT=Lighting.ClockTime, FE=Lighting.FogEnd}
local buildMainUI, setFly, setNoclip, setESP, setFullbright, unloadScript

-- GUI ROOT
local gui = new("ScreenGui", {Name="IMPRA", ResetOnSpawn=false, IgnoreGuiInset=true,
    ZIndexBehavior=Enum.ZIndexBehavior.Sibling, DisplayOrder=999, Parent=PG})

-- ═══ KEY SYSTEM ═══
local keyFrame = new("Frame", {Name="KeySystem", Size=UDim2.fromOffset(420,300),
    Position=UDim2.new(0.5,0,0.5,0), AnchorPoint=Vector2.new(0.5,0.5),
    BackgroundColor3=T().BG, BorderSizePixel=0, Parent=gui})
corner(keyFrame, 12)
local kStroke = stroke(keyFrame, T().BORDER, 1)
onTheme(function(t) keyFrame.BackgroundColor3=t.BG; kStroke.Color=t.BORDER end)

local kTitle = new("TextLabel", {Size=UDim2.new(1,0,0,44), BackgroundTransparency=1,
    Text="IMPRA v"..CONFIG.VERSION, TextColor3=T().TEXT, Font=Enum.Font.GothamBold, TextSize=24, Parent=keyFrame})
onTheme(function(t) kTitle.TextColor3=t.TEXT end)
new("TextLabel", {Size=UDim2.new(1,0,0,20), Position=UDim2.new(0,0,0,46), BackgroundTransparency=1,
    Text="Key System • Enter your access key", TextColor3=T().SUB, Font=Enum.Font.Gotham, TextSize=13, Parent=keyFrame})
onTheme(function(t) for _,c in ipairs(keyFrame:GetChildren()) do
    if c:IsA("TextLabel") and c.Text:find("Key System") then c.TextColor3=t.SUB end end end)

local kBox = new("Frame", {Size=UDim2.new(1,-60,0,44), Position=UDim2.new(0,30,0,90),
    BackgroundColor3=T().BG2, BorderSizePixel=0, Parent=keyFrame})
corner(kBox, 8)
local kBoxStroke = stroke(kBox, T().BORDER, 1)
onTheme(function(t) kBox.BackgroundColor3=t.BG2; kBoxStroke.Color=t.BORDER end)
local kInput = new("TextBox", {Size=UDim2.new(1,-20,1,0), Position=UDim2.new(0,12,0,0), BackgroundTransparency=1,
    Text="", PlaceholderText="Enter key...", PlaceholderColor3=T().SUB, TextColor3=T().TEXT,
    Font=Enum.Font.Gotham, TextSize=15, TextXAlignment=Enum.TextXAlignment.Left, ClearTextOnFocus=false, Parent=kBox})
onTheme(function(t) kInput.TextColor3=t.TEXT; kInput.PlaceholderColor3=t.SUB end)

local kStatus = new("TextLabel", {Size=UDim2.new(1,-60,0,18), Position=UDim2.new(0,30,0,140),
    BackgroundTransparency=1, Text="", TextColor3=T().DANGER, Font=Enum.Font.GothamMedium, TextSize=12,
    TextXAlignment=Enum.TextXAlignment.Left, Parent=keyFrame})
onTheme(function(t) kStatus.TextColor3=t.DANGER end)

local unlockBtn = new("TextButton", {Size=UDim2.new(1,-60,0,44), Position=UDim2.new(0,30,0,168),
    BackgroundColor3=T().ACCENT, Text="UNLOCK", TextColor3=T().BG, Font=Enum.Font.GothamBold, TextSize=15,
    BorderSizePixel=0, AutoButtonColor=false, Parent=keyFrame})
corner(unlockBtn, 8)
onTheme(function(t) unlockBtn.BackgroundColor3=t.ACCENT; unlockBtn.TextColor3=t.BG end)
polishBtn(unlockBtn,
    function() return T().ACCENT end,
    function() return Color3.new(math.min(1,T().ACCENT.R+0.15), math.min(1,T().ACCENT.G+0.15), math.min(1,T().ACCENT.B+0.15)) end)

local discBtn = new("TextButton", {Size=UDim2.new(1,-60,0,32), Position=UDim2.new(0,30,0,226),
    BackgroundColor3=T().BG2, Text="Join our Discord • "..CONFIG.DISCORD, TextColor3=T().SUB,
    Font=Enum.Font.Gotham, TextSize=12, BorderSizePixel=0, AutoButtonColor=false, Parent=keyFrame})
corner(discBtn, 6)
onTheme(function(t) discBtn.BackgroundColor3=t.BG2; discBtn.TextColor3=t.SUB end)
polishBtn(discBtn, function() return T().BG2 end, function() return T().BG3 end)

discBtn.MouseButton1Click:Connect(function()
    pcall(function() setclipboard(CONFIG.DISCORD) end)
    kStatus.Text = "Discord link copied!"; kStatus.TextColor3 = T().SUCCESS
    task.delay(2, function()
        if kStatus.Text == "Discord link copied!" then kStatus.Text=""; kStatus.TextColor3=T().DANGER end
    end)
end)

task.defer(function() popIn(keyFrame, 0.45) end)
makeDraggable(keyFrame, keyFrame, {unlockBtn, discBtn, kInput, kBox})

local function flashStroke(c, th)
    kStroke.Color = c; kStroke.Thickness = th
    TweenService:Create(kStroke, TweenInfo.new(0.4), {Thickness=1, Color=T().BORDER}):Play()
end
local function showKeyErr(msg)
    kStatus.Text = msg; kStatus.TextColor3 = T().DANGER
    flashStroke(T().DANGER, 3)
    local o = kBox.Position
    for i=1,6 do kBox.Position = o + UDim2.fromOffset((i%2==0) and 6 or -6, 0); task.wait(0.03) end
    kBox.Position = o
end
local function tryUnlock()
    local k = (kInput.Text or ""):gsub("%s+", "")
    if k == "" then showKeyErr("Please enter a key.") return end
    if k == CONFIG.KEY then
        kStatus.Text = "Key accepted! Loading..."; kStatus.TextColor3 = T().SUCCESS
        flashStroke(T().SUCCESS, 3)
        task.wait(0.6)
        popOut(keyFrame, 0.35, function()
            keyFrame:Destroy()
            print("[IMPRA] Building main GUI...")
            if buildMainUI then
                local ok, err = pcall(buildMainUI)
                if not ok then warn("[IMPRA] buildMainUI error:", err) end
            else warn("[IMPRA] buildMainUI nil!") end
        end)
    else showKeyErr("Invalid key. Try again.") end
end
unlockBtn.MouseButton1Click:Connect(tryUnlock)
kInput.FocusLost:Connect(function(e) if e then tryUnlock() end end)
print("[IMPRA] Key system ready")

-- ═══ MAIN UI ═══
buildMainUI = function()
    print("[IMPRA] buildMainUI...")
    local pages, tabs, activePage, allItems = {}, {}, "Main", {}

    local mainFrame = new("Frame", {Name="Main", Size=UDim2.fromOffset(720,480),
        Position=UDim2.new(0.5,0,0.5,0), AnchorPoint=Vector2.new(0.5,0.5),
        BackgroundColor3=T().BG, BorderSizePixel=0, Parent=gui})
    corner(mainFrame, 12)
    local mStroke = stroke(mainFrame, T().BORDER, 1)
    onTheme(function(t) mainFrame.BackgroundColor3=t.BG; mStroke.Color=t.BORDER end)

    -- TOP BAR
    local topBar = new("Frame", {Size=UDim2.new(1,0,0,44), BackgroundColor3=T().BG2, BorderSizePixel=0, Parent=mainFrame})
    corner(topBar, 12)
    local topCover = new("Frame", {Size=UDim2.new(1,0,0,22), Position=UDim2.new(0,0,1,-22),
        BackgroundColor3=T().BG2, BorderSizePixel=0, Parent=topBar})
    onTheme(function(t) topBar.BackgroundColor3=t.BG2; topCover.BackgroundColor3=t.BG2 end)

    local title = new("TextLabel", {Size=UDim2.fromOffset(220,44), Position=UDim2.fromOffset(20,0), BackgroundTransparency=1,
        Text="IMPRA v"..CONFIG.VERSION, TextColor3=T().TEXT, Font=Enum.Font.GothamBold, TextSize=16,
        TextXAlignment=Enum.TextXAlignment.Left, Parent=topBar})
    onTheme(function(t) title.TextColor3=t.TEXT end)

    -- SEARCH
    local searchFrame = new("Frame", {Size=UDim2.fromOffset(280,30), Position=UDim2.new(0.5,-140,0.5,-15),
        BackgroundColor3=T().BG3, BorderSizePixel=0, Parent=topBar})
    corner(searchFrame, 6)
    local sS = stroke(searchFrame, T().BORDER, 1)
    onTheme(function(t) searchFrame.BackgroundColor3=t.BG3; sS.Color=t.BORDER end)
    new("TextLabel", {Size=UDim2.fromOffset(24,30), Position=UDim2.fromOffset(4,0), BackgroundTransparency=1,
        Text="🔍", TextColor3=T().SUB, Font=Enum.Font.Gotham, TextSize=13, Parent=searchFrame})
    local searchBox = new("TextBox", {Size=UDim2.new(1,-24,1,0), Position=UDim2.fromOffset(24,0), BackgroundTransparency=1,
        PlaceholderText="Search features...", PlaceholderColor3=T().SUB, Text="", TextColor3=T().TEXT,
        Font=Enum.Font.Gotham, TextSize=13, TextXAlignment=Enum.TextXAlignment.Left, ClearTextOnFocus=false, Parent=searchFrame})
    onTheme(function(t) searchBox.TextColor3=t.TEXT; searchBox.PlaceholderColor3=t.SUB end)

    -- MIN/CLOSE
    local minBtn = new("TextButton", {Size=UDim2.fromOffset(28,28), Position=UDim2.new(1,-72,0.5,-14),
        BackgroundColor3=T().BG3, Text="—", TextColor3=T().TEXT, Font=Enum.Font.GothamBold, TextSize=14,
        BorderSizePixel=0, AutoButtonColor=false, Parent=topBar})
    corner(minBtn, 6)
    onTheme(function(t) minBtn.BackgroundColor3=t.BG3; minBtn.TextColor3=t.TEXT end)
    polishBtn(minBtn, function() return T().BG3 end, function() return T().BORDER end)

    local closeBtn = new("TextButton", {Size=UDim2.fromOffset(28,28), Position=UDim2.new(1,-38,0.5,-14),
        BackgroundColor3=T().BG3, Text="✕", TextColor3=T().DANGER, Font=Enum.Font.GothamBold, TextSize=14,
        BorderSizePixel=0, AutoButtonColor=false, Parent=topBar})
    corner(closeBtn, 6)
    onTheme(function(t) closeBtn.BackgroundColor3=t.BG3; closeBtn.TextColor3=t.DANGER end)
    polishBtn(closeBtn, function() return T().BG3 end,
        function() return Color3.new(math.min(1,T().BG3.R+0.15), T().BG3.G, T().BG3.B) end)

    makeDraggable(mainFrame, topBar, {searchBox, searchFrame, minBtn, closeBtn})

    -- SIDEBAR
    local sidebar = new("Frame", {Size=UDim2.new(0,130,1,-68), Position=UDim2.new(0,0,0,44),
        BackgroundColor3=T().BG2, BorderSizePixel=0, Parent=mainFrame})
    local sbS = stroke(sidebar, T().BORDER, 1)
    onTheme(function(t) sidebar.BackgroundColor3=t.BG2; sbS.Color=t.BORDER end)

    -- STATUS BAR
    local statusBar = new("Frame", {Size=UDim2.new(1,0,0,24), Position=UDim2.new(0,0,1,-24),
        BackgroundColor3=T().BG2, BorderSizePixel=0, Parent=mainFrame})
    onTheme(function(t) statusBar.BackgroundColor3=t.BG2 end)
    local statusLabel = new("TextLabel", {Size=UDim2.new(1,-20,1,0), Position=UDim2.fromOffset(12,0),
        BackgroundTransparency=1, Text="Ready • IMPRA v"..CONFIG.VERSION, TextColor3=T().SUB,
        Font=Enum.Font.Gotham, TextSize=11, TextXAlignment=Enum.TextXAlignment.Left, Parent=statusBar})
    onTheme(function(t) statusLabel.TextColor3=t.SUB end)

    -- CONTENT
    local content = new("Frame", {Size=UDim2.new(1,-140,1,-68), Position=UDim2.new(0,135,0,44),
        BackgroundTransparency=1, ClipsDescendants=true, Parent=mainFrame})

    local function makePage(name)
        local p = new("ScrollingFrame", {Name=name.."Page", Size=UDim2.new(1,0,1,0),
            BackgroundTransparency=1, BorderSizePixel=0, ScrollBarThickness=4, ScrollBarImageColor3=T().SUB,
            CanvasSize=UDim2.new(0,0,0,0), AutomaticCanvasSize=Enum.AutomaticSize.Y, Visible=false, Parent=content})
        new("UIPadding", {PaddingLeft=UDim.new(0,10), PaddingRight=UDim.new(0,10),
            PaddingTop=UDim.new(0,10), PaddingBottom=UDim.new(0,10), Parent=p})
        new("UIListLayout", {Padding=UDim.new(0,8), SortOrder=Enum.SortOrder.LayoutOrder, Parent=p})
        pages[name] = p
        return p
    end

    local function section(parent, text, order)
        local f = new("Frame", {Size=UDim2.new(1,0,0,24), BackgroundTransparency=1, LayoutOrder=order or 0, Parent=parent})
        new("TextLabel", {Size=UDim2.new(1,0,1,0), BackgroundTransparency=1, Text=text:upper(),
            TextColor3=T().SUB, Font=Enum.Font.GothamBold, TextSize=10, TextXAlignment=Enum.TextXAlignment.Left, Parent=f})
        onTheme(function(t) for _,c in ipairs(f:GetChildren()) do
            if c:IsA("TextLabel") then c.TextColor3=t.SUB end end end)
        return f
    end

    local function toggle(parent, name, order, initial, cb)
        local f = new("Frame", {Size=UDim2.new(1,0,0,40), BackgroundColor3=T().BG2, BorderSizePixel=0, LayoutOrder=order, Parent=parent})
        f:SetAttribute("FeatureName", name)
        corner(f, 8)
        local fS = stroke(f, T().BORDER, 1)
        onTheme(function(t) f.BackgroundColor3=t.BG2; fS.Color=t.BORDER end)
        new("TextLabel", {Size=UDim2.new(1,-70,1,0), Position=UDim2.fromOffset(14,0), BackgroundTransparency=1,
            Text=name, TextColor3=T().TEXT, Font=Enum.Font.GothamMedium, TextSize=13,
            TextXAlignment=Enum.TextXAlignment.Left, Parent=f})
        onTheme(function(t) for _,c in ipairs(f:GetChildren()) do
            if c:IsA("TextLabel") then c.TextColor3=t.TEXT end end end)
        local pill = new("Frame", {Size=UDim2.fromOffset(38,20), Position=UDim2.new(1,-52,0.5,-10),
            BackgroundColor3=T().BORDER, BorderSizePixel=0, Parent=f})
        corner(pill, 10)
        local pS = stroke(pill, T().BORDER, 1)
        local dot = new("Frame", {Size=UDim2.fromOffset(16,16), Position=UDim2.fromOffset(2,2),
            BackgroundColor3=Color3.new(1,1,1), BorderSizePixel=0, Parent=pill})
        corner(dot, 8)
        local cur = initial or false
        local function set(v)
            cur = v; local t = T()
            TweenService:Create(pill, TweenInfo.new(0.25, Enum.EasingStyle.Back, Enum.EasingDirection.Out),
                {BackgroundColor3 = v and t.ACCENT or t.BORDER}):Play()
            TweenService:Create(dot, TweenInfo.new(0.3, Enum.EasingStyle.Back, Enum.EasingDirection.Out),
                {Position = v and UDim2.new(1,-18,0,2) or UDim2.fromOffset(2,2)}):Play()
            TweenService:Create(dot, TweenInfo.new(0.2),
                {BackgroundColor3 = v and t.BG or Color3.new(1,1,1)}):Play()
            cb(v)
        end
        set(cur)
        f.InputBegan:Connect(function(i)
            if i.UserInputType == Enum.UserInputType.MouseButton1 then set(not cur) end
        end)
        f.MouseEnter:Connect(function() TweenService:Create(f, TweenInfo.new(0.15), {BackgroundColor3=T().BG3}):Play() end)
        f.MouseLeave:Connect(function() TweenService:Create(f, TweenInfo.new(0.15), {BackgroundColor3=T().BG2}):Play() end)
        onTheme(function(t)
            pill.BackgroundColor3 = cur and t.ACCENT or t.BORDER
            pS.Color = t.BORDER
            dot.BackgroundColor3 = cur and t.BG or Color3.new(1,1,1)
        end)
        table.insert(allItems, f)
    end

    local function slider(parent, name, order, minV, maxV, initV, cb)
        local f = new("Frame", {Size=UDim2.new(1,0,0,56), BackgroundColor3=T().BG2, BorderSizePixel=0, LayoutOrder=order, Parent=parent})
        f:SetAttribute("FeatureName", name)
        corner(f, 8)
        local fS = stroke(f, T().BORDER, 1)
        onTheme(function(t) f.BackgroundColor3=t.BG2; fS.Color=t.BORDER end)
        new("TextLabel", {Size=UDim2.new(0.6,0,0,22), Position=UDim2.fromOffset(14,6), BackgroundTransparency=1,
            Text=name, TextColor3=T().TEXT, Font=Enum.Font.GothamMedium, TextSize=13,
            TextXAlignment=Enum.TextXAlignment.Left, Parent=f})
        onTheme(function(t) for _,c in ipairs(f:GetChildren()) do
            if c:IsA("TextLabel") then c.TextColor3=t.TEXT end end end)
        local valLbl = new("TextLabel", {Size=UDim2.new(0.4,-14,0,22), Position=UDim2.new(0.6,0,0,6),
            BackgroundTransparency=1, Text=tostring(initV), TextColor3=T().ACCENT, Font=Enum.Font.GothamBold,
            TextSize=13, TextXAlignment=Enum.TextXAlignment.Right, Parent=f})
        onTheme(function(t) valLbl.TextColor3=t.ACCENT end)
        local barBg = new("Frame", {Size=UDim2.new(1,-28,0,6), Position=UDim2.new(0,14,0,34),
            BackgroundColor3=T().BG3, BorderSizePixel=0, Parent=f})
        corner(barBg, 3)
        onTheme(function(t) barBg.BackgroundColor3=t.BG3 end)
        local pct = math.clamp((initV-minV)/(maxV-minV), 0, 1)
        local fill = new("Frame", {Size=UDim2.new(pct,0,1,0), BackgroundColor3=T().ACCENT, BorderSizePixel=0, Parent=barBg})
        corner(fill, 3)
        onTheme(function(t) fill.BackgroundColor3=t.ACCENT end)
        local knob = new("Frame", {Size=UDim2.fromOffset(14,14), Position=UDim2.new(pct,-7,0.5,-7),
            BackgroundColor3=T().ACCENT, BorderSizePixel=0, Parent=barBg})
        corner(knob, 7)
        onTheme(function(t) knob.BackgroundColor3=t.ACCENT end)
        local dragging = false
        local function setFromX(x)
            local rel = math.clamp((x - barBg.AbsolutePosition.X) / barBg.AbsoluteSize.X, 0, 1)
            local v = math.floor(minV + (maxV-minV)*rel + 0.5)
            fill.Size = UDim2.new(rel,0,1,0)
            knob.Position = UDim2.new(rel,-7,0.5,-7)
            valLbl.Text = tostring(v)
            cb(v)
        end
        barBg.InputBegan:Connect(function(i)
            if i.UserInputType == Enum.UserInputType.MouseButton1 then dragging = true; setFromX(i.Position.X) end
        end)
        UIS.InputChanged:Connect(function(i)
            if dragging and i.UserInputType == Enum.UserInputType.MouseMovement then setFromX(i.Position.X) end
        end)
        UIS.InputEnded:Connect(function(i)
            if i.UserInputType == Enum.UserInputType.MouseButton1 then dragging = false end
        end)
        table.insert(allItems, f)
    end

    local function actionBtn(parent, name, order, label, cb)
        local f = new("TextButton", {Size=UDim2.new(1,0,0,40), BackgroundColor3=T().BG2, Text="",
            BorderSizePixel=0, AutoButtonColor=false, LayoutOrder=order, Parent=parent})
        f:SetAttribute("FeatureName", name)
        corner(f, 8)
        local fS = stroke(f, T().BORDER, 1)
        onTheme(function(t) f.BackgroundColor3=t.BG2; fS.Color=t.BORDER end)
        new("TextLabel", {Size=UDim2.new(1,-28,1,0), Position=UDim2.fromOffset(14,0), BackgroundTransparency=1,
            Text=label, TextColor3=T().TEXT, Font=Enum.Font.GothamMedium, TextSize=13,
            TextXAlignment=Enum.TextXAlignment.Left, Parent=f})
        onTheme(function(t) for _,c in ipairs(f:GetChildren()) do
            if c:IsA("TextLabel") then c.TextColor3=t.TEXT end end end)
        polishBtn(f, function() return T().BG2 end, function() return T().BG3 end)
        f.MouseButton1Click:Connect(cb)
        table.insert(allItems, f)
    end

    -- MAIN PAGE
    local mp = makePage("Main")
    section(mp, "Movement", 1)
    toggle(mp, "Fly", 2, false, function(v) setFly(v) end)
    slider(mp, "Fly Speed", 3, 10, 300, 50, function(v) state.flySpeed = v end)
    toggle(mp, "Noclip", 4, false, function(v) setNoclip(v) end)
    toggle(mp, "Click Teleport (Ctrl + Click)", 5, false, function(v) state.clickTp = v end)
    section(mp, "Teleport", 6)
    actionBtn(mp, "Teleport to Cursor", 7, "Teleport to Cursor", function()
        local m = LP:GetMouse()
        if m.Hit then
            local c = LP.Character
            if c and c:FindFirstChild("HumanoidRootPart") then
                c.HumanoidRootPart.CFrame = CFrame.new(m.Hit.Position + Vector3.new(0,3,0))
            end
        end
    end)

    -- VISUALS
    local vp = makePage("Visuals")
    section(vp, "ESP", 1)
    toggle(vp, "ESP (Player Highlights)", 2, false, function(v) setESP(v) end)
    section(vp, "Lighting", 3)
    toggle(vp, "Fullbright", 4, false, function(v) setFullbright(v) end)
    slider(vp, "Brightness", 5, 0, 5, Lighting.Brightness, function(v) Lighting.Brightness = v end)
    slider(vp, "Clock Time", 6, 0, 24, Lighting.ClockTime, function(v) Lighting.ClockTime = v end)
    actionBtn(vp, "Reset Lighting", 7, "Reset Lighting", function()
        Lighting.Brightness = origLight.B; Lighting.Ambient = origLight.A
        Lighting.OutdoorAmbient = origLight.OA; Lighting.ClockTime = origLight.CT; Lighting.FogEnd = origLight.FE
    end)

    -- PLAYER
    local pp = makePage("Player")
    local playerScroll = new("ScrollingFrame", {Size=UDim2.new(1,0,0,340), BackgroundTransparency=1,
        ScrollBarThickness=4, ScrollBarImageColor3=T().SUB, CanvasSize=UDim2.new(0,0,0,0),
        AutomaticCanvasSize=Enum.AutomaticSize.Y, LayoutOrder=2, Parent=pp})
    playerScroll:SetAttribute("FeatureName", "Player List")
    new("UIListLayout", {Padding=UDim.new(0,6), SortOrder=Enum.SortOrder.LayoutOrder, Parent=playerScroll})

    local function refresh()
        for _,c in ipairs(playerScroll:GetChildren()) do
            if c:IsA("Frame") then c:Destroy() end
        end
        for _,p in ipairs(Players:GetPlayers()) do
            local row = new("Frame", {Size=UDim2.new(1,-4,0,40), BackgroundColor3=T().BG2, BorderSizePixel=0, Parent=playerScroll})
            corner(row, 8); stroke(row, T().BORDER, 1)
            new("TextLabel", {Size=UDim2.new(1,-110,1,0), Position=UDim2.fromOffset(12,0), BackgroundTransparency=1,
                Text=p.Name..(p==LP and " (You)" or ""), TextColor3=T().TEXT, Font=Enum.Font.GothamMedium,
                TextSize=13, TextXAlignment=Enum.TextXAlignment.Left, Parent=row})
            if p ~= LP then
                local tp = new("TextButton", {Size=UDim2.fromOffset(80,28), Position=UDim2.new(1,-90,0.5,-14),
                    BackgroundColor3=T().BG3, Text="Teleport", TextColor3=T().TEXT, Font=Enum.Font.GothamMedium,
                    TextSize=12, BorderSizePixel=0, AutoButtonColor=false, Parent=row})
                corner(tp, 6)
                polishBtn(tp, function() return T().BG3 end, function() return T().BORDER end)
                tp.MouseButton1Click:Connect(function()
                    if p.Character and p.Character:FindFirstChild("HumanoidRootPart")
                       and LP.Character and LP.Character:FindFirstChild("HumanoidRootPart") then
                        LP.Character.HumanoidRootPart.CFrame = p.Character.HumanoidRootPart.CFrame * CFrame.new(0,0,3)
                    end
                end)
            end
        end
    end
    refresh()
    track(Players.PlayerAdded:Connect(function() task.wait(0.5); refresh() end))
    track(Players.PlayerRemoving:Connect(function() task.wait(0.1); refresh() end))
    track(LP.CharacterAdded:Connect(function() task.wait(1); refresh() end))

    -- SETTINGS
    local sp = makePage("Settings")
    section(sp, "Theme", 1)
    for i, tn in ipairs({"Dark","Light","Midnight","Contrast"}) do
        local f = new("TextButton", {Size=UDim2.new(1,0,0,40), BackgroundColor3=T().BG2, Text="",
            BorderSizePixel=0, AutoButtonColor=false, LayoutOrder=1+i, Parent=sp})
        f:SetAttribute("FeatureName", "Theme "..tn)
        corner(f, 8)
        local fS = stroke(f, T().BORDER, 1)
        new("TextLabel", {Size=UDim2.new(0.6,0,1,0), Position=UDim2.fromOffset(14,0), BackgroundTransparency=1,
            Text=tn, TextColor3=T().TEXT, Font=Enum.Font.GothamMedium, TextSize=13,
            TextXAlignment=Enum.TextXAlignment.Left, Parent=f})
        local pv = new("Frame", {Size=UDim2.fromOffset(24,24), Position=UDim2.new(1,-38,0.5,-12),
            BackgroundColor3=Themes[tn].ACCENT, BorderSizePixel=0, Parent=f})
        corner(pv, 6)
        onTheme(function(t)
            f.BackgroundColor3=t.BG2; fS.Color=t.BORDER
            for _,c in ipairs(f:GetChildren()) do
                if c:IsA("TextLabel") then c.TextColor3=t.TEXT end
            end
        end)
        polishBtn(f, function() return T().BG2 end, function() return T().BG3 end)
        f.MouseButton1Click:Connect(function()
            applyTheme(tn); statusLabel.Text = "Theme: "..tn
        end)
        table.insert(allItems, f)
    end
    section(sp, "Info", 10)
    actionBtn(sp, "Discord Link", 11, "Copy Discord Link", function()
        pcall(function() setclipboard(CONFIG.DISCORD) end)
        statusLabel.Text = "Discord link copied!"
    end)
    actionBtn(sp, "Unload Script", 12, "Unload IMPRA", function()
        if unloadScript then popOut(mainFrame, 0.25, function() unloadScript() end) end
    end)

    -- TABS
    local tabNames = {"Main","Visuals","Player","Settings"}
    local function setPage(name)
        local np = pages[name]
        if not np then return end
        for n, p in pairs(pages) do if n ~= name then p.Visible = false end end
        np.Position = UDim2.fromOffset(30, 0)
        np.Visible = true
        TweenService:Create(np, TweenInfo.new(0.25, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {Position=UDim2.new(0,0,0,0)}):Play()
        activePage = name
        for n, t in pairs(tabs) do
            if n == name then
                TweenService:Create(t.bg, TweenInfo.new(0.2), {BackgroundColor3=T().BG3}):Play()
                TweenService:Create(t.lbl, TweenInfo.new(0.2), {TextColor3=T().TEXT}):Play()
            else
                TweenService:Create(t.bg, TweenInfo.new(0.2), {BackgroundColor3=T().BG2}):Play()
                TweenService:Create(t.lbl, TweenInfo.new(0.2), {TextColor3=T().SUB}):Play()
            end
        end
    end
    for i, tn in ipairs(tabNames) do
        local tab = new("TextButton", {Size=UDim2.new(1,-16,0,34), Position=UDim2.fromOffset(8, 8 + (i-1)*40),
            BackgroundColor3=T().BG2, Text="", BorderSizePixel=0, AutoButtonColor=false, Parent=sidebar})
        corner(tab, 6)
        local lbl = new("TextLabel", {Size=UDim2.new(1,-20,1,0), Position=UDim2.fromOffset(12,0),
            BackgroundTransparency=1, Text=tn, TextColor3=T().SUB, Font=Enum.Font.GothamMedium,
            TextSize=13, TextXAlignment=Enum.TextXAlignment.Left, Parent=tab})
        onTheme(function(t) lbl.TextColor3 = (activePage == tn) and t.TEXT or t.SUB end)
        polishBtn(tab, function() return (activePage==tn) and T().BG3 or T().BG2 end, function() return T().BG3 end)
        tab.MouseButton1Click:Connect(function() setPage(tn) end)
        tabs[tn] = {bg=tab, lbl=lbl}
    end
    setPage("Main")

    searchBox:GetPropertyChangedSignal("Text"):Connect(function()
        local q = (searchBox.Text or ""):lower():gsub("%s+", "")
        for _, item in ipairs(allItems) do
            local n = (item:GetAttribute("FeatureName") or ""):lower():gsub("%s+", "")
            item.Visible = (q == "" or n:find(q, 1, true)) and true or false
        end
    end)

    -- RESTORE
    local restoreBtn = new("TextButton", {Name="Restore", Size=UDim2.fromOffset(56,56),
        Position=UDim2.new(0.5,0,0.5,0), AnchorPoint=Vector2.new(0.5,0.5),
        BackgroundColor3=T().BG, Text="I", TextColor3=T().ACCENT, Font=Enum.Font.GothamBold,
        TextSize=22, BorderSizePixel=0, AutoButtonColor=false, Visible=false, Parent=gui})
    corner(restoreBtn, 12)
    stroke(restoreBtn, T().BORDER, 1)
    onTheme(function(t) restoreBtn.BackgroundColor3=t.BG; restoreBtn.TextColor3=t.ACCENT end)
    polishBtn(restoreBtn, function() return T().BG end, function() return T().BG2 end)

    minBtn.MouseButton1Click:Connect(function()
        popOut(mainFrame, 0.2, function()
            mainFrame.Visible = false
            restoreBtn.Visible = true
            popIn(restoreBtn, 0.3)
        end)
    end)
    restoreBtn.MouseButton1Click:Connect(function()
        popOut(restoreBtn, 0.15, function()
            restoreBtn.Visible = false
            mainFrame.Visible = true
            popIn(mainFrame, 0.3)
        end)
    end)
    closeBtn.MouseButton1Click:Connect(function()
        popOut(mainFrame, 0.25, function() if unloadScript then unloadScript() end end)
    end)

    -- FPS
    task.spawn(function()
        local frames, st = 0, tick()
        while mainFrame.Parent do
            frames = frames + 1
            if tick() - st >= 0.5 then
                local fps = math.floor(frames / (tick() - st))
                statusLabel.Text = ("%d FPS • Theme: %s • v%s"):format(fps, CurrentTheme, CONFIG.VERSION)
                frames, st = 0, tick()
            end
            task.wait()
        end
    end)

    popIn(mainFrame, 0.4)
    print("[IMPRA] Main GUI ready")
end

-- ═══ FEATURES ═══
local function createFlyBV()
    local c = LP.Character; if not c then return end
    local hrp = c:FindFirstChild("HumanoidRootPart"); if not hrp then return end
    if flyBV then flyBV:Destroy() end
    flyBV = Instance.new("BodyVelocity")
    flyBV.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
    flyBV.Velocity = Vector3.zero; flyBV.Parent = hrp
end
setFly = function(v)
    state.fly = v
    if v then createFlyBV() else if flyBV then flyBV:Destroy(); flyBV=nil end end
end
task.spawn(function()
    RunService.RenderStepped:Connect(function()
        if not state.fly then return end
        local c = LP.Character; if not c then return end
        local hrp = c:FindFirstChild("HumanoidRootPart"); if not hrp then return end
        if not flyBV or flyBV.Parent ~= hrp then createFlyBV() end
        local cam = workspace.CurrentCamera
        local d = Vector3.zero
        if UIS:IsKeyDown(Enum.KeyCode.W) then d = d + cam.CFrame.LookVector end
        if UIS:IsKeyDown(Enum.KeyCode.S) then d = d - cam.CFrame.LookVector end
        if UIS:IsKeyDown(Enum.KeyCode.A) then d = d - cam.CFrame.RightVector end
        if UIS:IsKeyDown(Enum.KeyCode.D) then d = d + cam.CFrame.RightVector end
        if UIS:IsKeyDown(Enum.KeyCode.Space) then d = d + Vector3.new(0,1,0) end
        if UIS:IsKeyDown(Enum.KeyCode.LeftShift) then d = d - Vector3.new(0,1,0) end
        if flyBV then flyBV.Velocity = (d.Magnitude > 0) and (d.Unit * state.flySpeed) or Vector3.zero end
    end)
end)
LP.CharacterAdded:Connect(function() task.wait(0.5); if state.fly then createFlyBV() end end)

setNoclip = function(v)
    state.noclip = v
    if v then
        if noclipConn then noclipConn:Disconnect() end
        noclipConn = RunService.Stepped:Connect(function()
            local c = LP.Character
            if c then for _, p in ipairs(c:GetDescendants()) do
                if p:IsA("BasePart") then p.CanCollide = false end end end
        end)
        track(noclipConn)
    else
        if noclipConn then noclipConn:Disconnect(); noclipConn = nil end
        local c = LP.Character
        if c then for _, p in ipairs(c:GetDescendants()) do
            if p:IsA("BasePart") and p.Name ~= "HumanoidRootPart" then p.CanCollide = true end end end
    end
end

local function createESP(player)
    if player == LP then return end
    local c = player.Character; if not c then return end
    local hrp = c:FindFirstChild("HumanoidRootPart"); if not hrp then return end
    if espObjects[player] then
        pcall(function() espObjects[player].billboard:Destroy() end)
        pcall(function() espObjects[player].highlight:Destroy() end)
    end
    local bb = new("BillboardGui", {Name="IMPRA_ESP", Adornee=hrp, Size=UDim2.fromOffset(120,40),
        StudsOffset=Vector3.new(0,3.2,0), AlwaysOnTop=true, Parent=hrp})
    new("TextLabel", {Size=UDim2.new(1,0,0.5,0), BackgroundTransparency=1, Text=player.Name,
        TextColor3=Color3.new(1,1,1), TextStrokeTransparency=0, TextScaled=true, Font=Enum.Font.GothamBold, Parent=bb})
    local dl = new("TextLabel", {Size=UDim2.new(1,0,0.5,0), Position=UDim2.new(0,0,0.5,0),
        BackgroundTransparency=1, Text="0m", TextColor3=Color3.fromRGB(200,200,200), TextStrokeTransparency=0,
        TextScaled=true, Font=Enum.Font.Gotham, Parent=bb})
    local hl = new("Highlight", {Adornee=c, FillColor=Color3.new(1,1,1), FillTransparency=0.7,
        OutlineColor=Color3.new(1,1,1), OutlineTransparency=0, Parent=c})
    espObjects[player] = {billboard=bb, highlight=hl, distLbl=dl, hrp=hrp}
end
local function removeESP(player)
    if espObjects[player] then
        pcall(function() espObjects[player].billboard:Destroy() end)
        pcall(function() espObjects[player].highlight:Destroy() end)
        espObjects[player] = nil
    end
end
setESP = function(v)
    state.esp = v
    if v then
        for _, p in ipairs(Players:GetPlayers()) do createESP(p) end
    else
        local keys = {}
        for p in pairs(espObjects) do table.insert(keys, p) end
        for _, p in ipairs(keys) do removeESP(p) end
    end
end
RunService.RenderStepped:Connect(function()
    if not state.esp then return end
    local c = LP.Character; if not c then return end
    local hrp = c:FindFirstChild("HumanoidRootPart"); if not hrp then return end
    for player, data in pairs(espObjects) do
        if data.hrp and data.hrp.Parent then
            data.distLbl.Text = math.floor((data.hrp.Position - hrp.Position).Magnitude).."m"
        else createESP(player) end
    end
end)
Players.PlayerAdded:Connect(function(p)
    track(p.CharacterAdded:Connect(function() task.wait(1); if state.esp then createESP(p) end end))
end)
Players.PlayerRemoving:Connect(function(p) removeESP(p) end)

track(UIS.InputBegan:Connect(function(input, gp)
    if gp then return end
    if state.clickTp and input.UserInputType == Enum.UserInputType.MouseButton1
       and UIS:IsKeyDown(Enum.KeyCode.LeftControl) then
        local m = LP:GetMouse()
        if m.Hit then
            local c = LP.Character
            if c and c:FindFirstChild("HumanoidRootPart") then
                c.HumanoidRootPart.CFrame = CFrame.new(m.Hit.Position + Vector3.new(0,3,0))
            end
        end
    end
end))

setFullbright = function(v)
    state.fullbright = v
    if v then
        Lighting.Brightness = 3
        Lighting.Ambient = Color3.fromRGB(180,180,180)
        Lighting.OutdoorAmbient = Color3.fromRGB(180,180,180)
        Lighting.ClockTime = 14
        Lighting.FogEnd = 100000
    else
        Lighting.Brightness = origLight.B; Lighting.Ambient = origLight.A
        Lighting.OutdoorAmbient = origLight.OA; Lighting.ClockTime = origLight.CT; Lighting.FogEnd = origLight.FE
    end
end

unloadScript = function()
    if flyBV then flyBV:Destroy(); flyBV = nil end
    if noclipConn then noclipConn:Disconnect(); noclipConn = nil end
    if setESP then setESP(false) end
    if setFullbright then setFullbright(false) end
    if setNoclip then setNoclip(false) end
    state.fly = false
    for _, c in ipairs(connections) do pcall(function() c:Disconnect() end) end
    connections = {}
    if gui then pcall(function() gui:Destroy() end) end
    Lighting.Brightness = origLight.B; Lighting.Ambient = origLight.A
    Lighting.OutdoorAmbient = origLight.OA; Lighting.ClockTime = origLight.CT; Lighting.FogEnd = origLight.FE
    warn("[IMPRA] Unloaded.")
end

print("[IMPRA] v"..CONFIG.VERSION.." loaded. Key: "..CONFIG.KEY)