Untitled

Text Views: 464 • Nov 08, 2026 • Never expires
--= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
-- WHIZ HUB — RUN FOR EGGS EDITION (GUI + AUTO REBIRTH + AUTO BUY TRAILS)
--= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local LP = Players.LocalPlayer
local PG = LP:WaitForChild("PlayerGui")

local DISCORD_USER   = "wexsttt"
local DISCORD_INVITE = "https://discord.gg/QaeqZyaqZH"

local Themes = {
    Black = {
        Bg = Color3.fromRGB(12, 12, 12), Card = Color3.fromRGB(22, 22, 22),
        CardAlt = Color3.fromRGB(32, 32, 32), Sidebar = Color3.fromRGB(8, 8, 8),
        Accent = Color3.fromRGB(240, 240, 240), Accent2 = Color3.fromRGB(255, 255, 255),
        Text = Color3.fromRGB(245, 245, 245), SubText = Color3.fromRGB(140, 140, 140),
        ToggleOff = Color3.fromRGB(50, 50, 50), Stroke = Color3.fromRGB(45, 45, 45),
    },
    Midnight = {
        Bg = Color3.fromRGB(18,16,28), Card = Color3.fromRGB(28,25,44),
        CardAlt = Color3.fromRGB(38,34,58), Sidebar = Color3.fromRGB(14,12,22),
        Accent = Color3.fromRGB(140,90,255), Accent2 = Color3.fromRGB(180,130,255),
        Text = Color3.fromRGB(235,232,255), SubText = Color3.fromRGB(150,145,175),
        ToggleOff = Color3.fromRGB(60,55,85), Stroke = Color3.fromRGB(52,46,78),
    },
    Bloodmoon = {
        Bg = Color3.fromRGB(22,10,12), Card = Color3.fromRGB(36,16,18),
        CardAlt = Color3.fromRGB(50,20,24), Sidebar = Color3.fromRGB(16,6,8),
        Accent = Color3.fromRGB(230,40,60), Accent2 = Color3.fromRGB(255,90,90),
        Text = Color3.fromRGB(255,235,235), SubText = Color3.fromRGB(180,130,130),
        ToggleOff = Color3.fromRGB(80,40,45), Stroke = Color3.fromRGB(72,28,32),
    },
    Emerald = {
        Bg = Color3.fromRGB(10,22,18), Card = Color3.fromRGB(16,36,28),
        CardAlt = Color3.fromRGB(22,48,38), Sidebar = Color3.fromRGB(7,16,13),
        Accent = Color3.fromRGB(30,220,140), Accent2 = Color3.fromRGB(80,255,180),
        Text = Color3.fromRGB(230,255,245), SubText = Color3.fromRGB(130,180,160),
        ToggleOff = Color3.fromRGB(40,70,60), Stroke = Color3.fromRGB(26,62,48),
    },
    Ocean = {
        Bg = Color3.fromRGB(8,16,28), Card = Color3.fromRGB(16,28,46),
        CardAlt = Color3.fromRGB(22,38,60), Sidebar = Color3.fromRGB(5,10,18),
        Accent = Color3.fromRGB(60,160,255), Accent2 = Color3.fromRGB(120,200,255),
        Text = Color3.fromRGB(230,242,255), SubText = Color3.fromRGB(130,160,190),
        ToggleOff = Color3.fromRGB(40,60,90), Stroke = Color3.fromRGB(28,48,76),
    },
    Sunset = {
        Bg = Color3.fromRGB(24,14,10), Card = Color3.fromRGB(40,24,16),
        CardAlt = Color3.fromRGB(54,32,20), Sidebar = Color3.fromRGB(16,9,6),
        Accent = Color3.fromRGB(255,120,40), Accent2 = Color3.fromRGB(255,170,90),
        Text = Color3.fromRGB(255,242,230), SubText = Color3.fromRGB(190,150,120),
        ToggleOff = Color3.fromRGB(80,50,30), Stroke = Color3.fromRGB(76,44,26),
    },
}

local CurrentTheme = "Black"
local CurrentScale = 1.0
local CurrentTab = "Main"
local State = {}

local function T(obj, time, props, style)
    local info = TweenInfo.new(time or 0.25, style or Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
    local t = TweenService:Create(obj, info, props)
    t:Play()
    return t
end

local function Corner(parent, r)
    local c = Instance.new("UICorner")
    c.CornerRadius = UDim.new(0, r or 10)
    c.Parent = parent
    return c
end

local function Stroke(parent, color, thick, trans)
    local s = Instance.new("UIStroke")
    s.Color = color
    s.Thickness = thick or 1
    s.Transparency = trans or 0.4
    s.ApplyStrokeMode = Enum.ApplyStrokeMode.Border
    s.Parent = parent
    return s
end

local function CopyToClipboard(text)
    local text = tostring(text)
    local env = getfenv and getfenv() or _G
    local funcNames = {"setclipboard", "toclipboard", "writeclipboard", "set_clipboard", "CopyToClipboard"}
    for _, fname in ipairs(funcNames) do
        local fn = env[fname]
        if type(fn) == "function" then
            local ok = pcall(fn, text)
            if ok then return true, fname end
        end
    end
    return false, nil
end

local function vlog(m)
    print(("[VEIL] %s | %s"):format(os.date("%H:%M:%S"), m))
end

--= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
-- REMOTES (ByteNet)
--= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

local Remotes = nil
do
    local ok, res = pcall(function()
        return require(ReplicatedStorage.Framework.Shared.Remotes)
    end)
    if ok and res then
        Remotes = res
        vlog("ByteNet remotes yuklendi")
    else
        warn("[VEIL] Remotes yuklenemedi")
    end
end

--= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
-- SHARED HELPERS
--= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

local function getWins()
    local ls = LP:FindFirstChild("leaderstats")
    local w = ls and ls:FindFirstChild("Wins")
    if not w then return 0 end
    return tonumber(w.Value) or 0
end

local function clickButton(btn)
    if not btn then return false end
    local fired = false
    if getconnections then
        local ok, conns = pcall(getconnections, btn.MouseButton1Click)
        if ok and conns then
            for _, conn in ipairs(conns) do
                pcall(function() conn:Fire() end)
                fired = true
            end
        end
    end
    if not fired and firesignal then
        pcall(firesignal, btn.MouseButton1Click)
        fired = true
    end
    if not fired then
        pcall(function() btn:Activate() end)
        fired = true
    end
    return fired
end

local function extractNumber(s)
    s = tostring(s or "")
    s = s:gsub(",", "")
    local num = s:match("[%d%.]+")
    return num and tonumber(num) or nil
end

--= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
-- AUTO REBIRTH
--= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

local rebirthCfg = { interval = 0.75, jitter = 0.5 }
local rebirthRunning = false
local rebirthCounter = 0

local function canRebirthNow()
    local okS, store = pcall(function()
        return require(ReplicatedStorage.Framework.Client.Stores.MainStore)
    end)
    if not okS or not store then return true end
    local okSt, state = pcall(function() return store:getState() end)
    if not okSt or not state or not state.Client then return true end
    local c = state.Client
    if c.Level and c.MaxLevel then
        return c.Level >= c.MaxLevel
    end
    return true
end

local function fireRebirth()
    if not Remotes or not Remotes.Rebirth then return end
    local okF, err = pcall(function()
        Remotes.Rebirth.send()
    end)
    if okF then
        rebirthCounter = rebirthCounter + 1
        if rebirthCounter % 20 == 0 then
            vlog(("rebirth istegi: %d"):format(rebirthCounter))
        end
    else
        vlog("rebirth hata: " .. tostring(err))
    end
end

local function rebirthLoop()
    while rebirthRunning do
        if canRebirthNow() then
            fireRebirth()
        end
        task.wait(rebirthCfg.interval + math.random() * rebirthCfg.jitter)
    end
    vlog("auto rebirth durdu")
end

--= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
-- AUTO BUY TRAILS
--= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

local TrailOrder = {
    "White", "Red", "Blue", "Green", "Purple", "Golden",
    "Fire", "Frost", "Lightning", "Magic", "Dragon",
}
local TrailPrices = {
    White = 250, Red = 2500, Blue = 15000, Green = 75000,
    Purple = 800000, Golden = 5000000, Fire = 1e8, Frost = 2.5e9,
    Lightning = 9e10, Magic = 2.5e14, Dragon = 7.5e16,
}

local trailsCfg = { interval = 0.6, jitter = 0.4, idle = 2.5 }
local trailsRunning = false
local trailsCounter = 0
local trailsMenuOpened = false
local trailsStuck = {}
local trailsFail = {}

local function getOwnedSet()
    local ok, store = pcall(function()
        return require(ReplicatedStorage.Framework.Client.Stores.MainStore)
    end)
    if not ok or not store then return nil end
    local ok2, state = pcall(function() return store:getState() end)
    if not ok2 or not state or not state.Client then return nil end
    local c = state.Client
    local trails = c.Trails or c.OwnedTrails or c.TrailData or c.Trail or c.ActiveTrail
    if not trails then return nil end
    local set = {}
    if type(trails) == "table" then
        for k, v in pairs(trails) do
            if type(k) == "string" then set[k] = true end
            if type(v) == "string" then set[v] = true end
            if type(v) == "table" then
                for kk, vv in pairs(v) do
                    if type(kk) == "string" and vv then set[kk] = true end
                    if type(vv) == "string" then set[vv] = true end
                end
            end
        end
    elseif type(trails) == "string" then
        set[trails] = true
    end
    return set
end

local function openTrailsMenu()
    local hud = PG:FindFirstChild("HudScreen")
    if not hud then
        vlog("HudScreen yok")
        return false
    end
    local center = hud:FindFirstChild("CenterLeft")
    local main = center and center:FindFirstChild("Main")
    local menuBtns = main and main:FindFirstChild("Menu Buttons")
    local trailBtn = menuBtns and menuBtns:FindFirstChild("Trails")
    if trailBtn and trailBtn:IsA("GuiButton") then
        clickButton(trailBtn)
        vlog("trails menusu acildi (path)")
        return true
    end
    for _, d in ipairs(hud:GetDescendants()) do
        if d:IsA("GuiButton") and d.Name:lower():find("trail", 1, true) then
            clickButton(d)
            vlog("trails menusu acildi (scan)")
            return true
        end
    end
    vlog("trails butonu bulunamadi")
    return false
end

local function findTrailCard(trailId)
    -- exact name match on Frame or GuiButton (case-insensitive)
    for _, d in ipairs(PG:GetDescendants()) do
        if (d:IsA("Frame") or d:IsA("GuiButton")) and d.Name:lower() == trailId:lower() then
            return d
        end
    end
    -- contains match, excluding "menu" hits
    for _, d in ipairs(PG:GetDescendants()) do
        if (d:IsA("Frame") or d:IsA("GuiButton")) then
            local n = d.Name:lower()
            if n:find(trailId:lower(), 1, true) and not n:find("menu", 1, true) then
                return d
            end
        end
    end
    return nil
end

local function findBuyButtonIn(card)
    local candidates = {}
    for _, d in ipairs(card:GetDescendants()) do
        if d:IsA("TextButton") then
            local t = (d.Text or ""):lower()
            if t:find("equip", 1, true) or t:find("owned", 1, true) then
                return nil, "already_owned"
            end
            table.insert(candidates, d)
        end
    end
    -- prefer numeric-text button (price display = buy button)
    for _, b in ipairs(candidates) do
        if extractNumber(b.Text) then
            return b, nil
        end
    end
    if #candidates > 0 then
        return candidates[1], nil
    end
    return nil, "no_btn"
end

local function tryBuy(trailId, price)
    local card = findTrailCard(trailId)
    if not card then return false, "no_card" end
    local buyBtn, why = findBuyButtonIn(card)
    if not buyBtn then return false, why or "no_btn" end

    local before = getWins()
    clickButton(buyBtn)
    task.wait(0.5)
    local after = getWins()
    if after < before then
        return true, "bought"
    elseif after == before then
        return false, "no_change"
    else
        return true, "gain?"
    end
end

local function trailsLoop()
    trailsMenuOpened = false
    trailsStuck = {}
    trailsFail = {}

    while trailsRunning do
        if not trailsMenuOpened then
            trailsMenuOpened = openTrailsMenu()
            task.wait(0.9)
        end

        local owned = getOwnedSet()
        local wins = getWins()
        local didSomething = false

        for _, trailId in ipairs(TrailOrder) do
            if not trailsRunning then break end

            if not trailsStuck[trailId] then
                local isOwned = owned and owned[trailId]
                if not isOwned then
                    local price = TrailPrices[trailId] or 0
                    if wins >= price then
                        local ok, reason = tryBuy(trailId, price)
                        if ok then
                            trailsCounter = trailsCounter + 1
                            vlog(("trail satin alindi: %s (#%d) [%s]"):format(trailId, trailsCounter, reason))
                            didSomething = true
                            break
                        else
                            if reason == "already_owned" then
                                trailsStuck[trailId] = true
                                vlog(("trail zaten sahip: %s"):format(trailId))
                            elseif reason == "no_card" or reason == "no_btn" then
                                trailsStuck[trailId] = true
                                vlog(("trail kart/buton yok: %s (%s)"):format(trailId, tostring(reason)))
                                trailsMenuOpened = false
                                break
                            elseif reason == "no_change" then
                                trailsFail[trailId] = (trailsFail[trailId] or 0) + 1
                                if trailsFail[trailId] >= 3 then
                                    trailsStuck[trailId] = true
                                    vlog(("trail satin alinamadi (3 deneme): %s"):format(trailId))
                                end
                            end
                        end
                    else
                        break
                    end
                end
            end
        end

        if not didSomething then
            task.wait(trailsCfg.idle)
        end
    end
    vlog("auto trails durdu")
end

--= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
-- TOGGLE DISPATCHER
--= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

_G.OnToggle = function(key, value)
    if key == "AutoRebirth" then
        if value and not rebirthRunning then
            rebirthRunning = true
            rebirthCounter = 0
            vlog("auto rebirth basladi")
            task.spawn(rebirthLoop)
        elseif not value and rebirthRunning then
            rebirthRunning = false
        end
    elseif key == "AutoBuyTrails" then
        if value and not trailsRunning then
            trailsRunning = true
            trailsCounter = 0
            vlog("auto trails basladi")
            task.spawn(trailsLoop)
        elseif not value and trailsRunning then
            trailsRunning = false
        end
    end
end

_G.autoRebirth = {
    on  = function() _G.OnToggle("AutoRebirth", true)  end,
    off = function() _G.OnToggle("AutoRebirth", false) end,
    fire = function() fireRebirth() end,
}
_G.autoTrails = {
    on    = function() _G.OnToggle("AutoBuyTrails", true)  end,
    off   = function() _G.OnToggle("AutoBuyTrails", false) end,
    open  = function() openTrailsMenu() end,
    state = function()
        for _, id in ipairs(TrailOrder) do
            local card = findTrailCard(id)
            local status = card and "found" or "missing"
            local btn = card and findBuyButtonIn(card)
            local btnTxt = (type(btn) == "Instance" and btn.Text) or "-"
            vlog(("%s: card=%s btn=%s"):format(id, status, tostring(btnTxt)))
        end
    end,
}

--= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
-- ROOT GUI
--= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

local BASE_W, BASE_H = 900, 580
local SIDEBAR_W = 160
local TOPBAR_H = 76

local ScreenGui = Instance.new("ScreenGui")
ScreenGui.Name = "WhizHub"
ScreenGui.ResetOnSpawn = false
ScreenGui.IgnoreGuiInset = true
ScreenGui.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
ScreenGui.Parent = PG

local NotifContainer = Instance.new("Frame")
NotifContainer.Name = "NotifContainer"
NotifContainer.Size = UDim2.fromOffset(320, 500)
NotifContainer.Position = UDim2.new(1, -20, 0, 20)
NotifContainer.AnchorPoint = Vector2.new(1, 0)
NotifContainer.BackgroundTransparency = 1
NotifContainer.ZIndex = 100
NotifContainer.Parent = ScreenGui

local NotifLayout = Instance.new("UIListLayout")
NotifLayout.Padding = UDim.new(0, 8)
NotifLayout.SortOrder = Enum.SortOrder.LayoutOrder
NotifLayout.VerticalAlignment = Enum.VerticalAlignment.Top
NotifLayout.Parent = NotifContainer

local notifId = 0

local function Notify(title, message, kind)
    notifId = notifId + 1
    local id = notifId
    local accent
    if kind == "success" then accent = Color3.fromRGB(60, 220, 130)
    elseif kind == "warn" then accent = Color3.fromRGB(255, 180, 60)
    elseif kind == "error" then accent = Color3.fromRGB(230, 60, 60)
    else accent = Themes[CurrentTheme].Accent end

    local card = Instance.new("Frame")
    card.Name = "Notif" .. id
    card.Size = UDim2.new(1, 0, 0, 64)
    card.Position = UDim2.new(1, 40, 0, 0)
    card.BackgroundColor3 = Themes[CurrentTheme].Card
    card.BackgroundTransparency = 0.05
    card.BorderSizePixel = 0
    card.LayoutOrder = id
    card.ZIndex = 101
    card.Parent = NotifContainer
    Corner(card, 12)
    Stroke(card, accent, 1, 0.3)

    local strip = Instance.new("Frame")
    strip.Size = UDim2.new(0, 3, 0.7, 0)
    strip.Position = UDim2.new(0, 10, 0.5, 0)
    strip.AnchorPoint = Vector2.new(0, 0.5)
    strip.BackgroundColor3 = accent
    strip.BorderSizePixel = 0
    strip.ZIndex = 102
    strip.Parent = card
    Corner(strip, 2)

    local t = Instance.new("TextLabel")
    t.Size = UDim2.new(1, -32, 0, 20)
    t.Position = UDim2.new(0, 22, 0, 12)
    t.BackgroundTransparency = 1
    t.Text = title
    t.TextColor3 = Themes[CurrentTheme].Text
    t.TextXAlignment = Enum.TextXAlignment.Left
    t.Font = Enum.Font.GothamBold
    t.TextSize = 14
    t.ZIndex = 102
    t.Parent = card

    local m = Instance.new("TextLabel")
    m.Size = UDim2.new(1, -32, 0, 22)
    m.Position = UDim2.new(0, 22, 0, 32)
    m.BackgroundTransparency = 1
    m.Text = message
    m.TextColor3 = Themes[CurrentTheme].SubText
    m.TextXAlignment = Enum.TextXAlignment.Left
    m.TextYAlignment = Enum.TextYAlignment.Top
    m.TextWrapped = true
    m.Font = Enum.Font.Gotham
    m.TextSize = 12
    m.ZIndex = 102
    m.Parent = card

    T(card, 0.3, { Position = UDim2.new(0, 0, 0, 0) })
    task.delay(3, function()
        if not card.Parent then return end
        T(card, 0.3, { Position = UDim2.new(1, 40, 0, 0) })
        task.wait(0.35)
        if card.Parent then card:Destroy() end
    end)
end

local Main = Instance.new("Frame")
Main.Name = "Main"
Main.Size = UDim2.fromOffset(BASE_W, BASE_H)
Main.Position = UDim2.new(0.5, 0, 0.5, 0)
Main.AnchorPoint = Vector2.new(0.5, 0.5)
Main.BackgroundColor3 = Themes[CurrentTheme].Bg
Main.BackgroundTransparency = 0.12
Main.BorderSizePixel = 0
Main.Active = true
Main.Draggable = true
Main.ClipsDescendants = true
Main.Parent = ScreenGui
Corner(Main, 18)
local MainStroke = Stroke(Main, Themes[CurrentTheme].Stroke, 1, 0.35)

local Shadow = Instance.new("ImageLabel")
Shadow.AnchorPoint = Vector2.new(0.5, 0.5)
Shadow.Position = UDim2.fromScale(0.5, 0.5)
Shadow.Size = UDim2.new(1, 60, 1, 60)
Shadow.BackgroundTransparency = 1
Shadow.Image = "rbxassetid://5028857472"
Shadow.ImageColor3 = Color3.fromRGB(0, 0, 0)
Shadow.ImageTransparency = 0.5
Shadow.ZIndex = 0
Shadow.Parent = Main

local MinimizedBar = Instance.new("Frame")
MinimizedBar.Name = "MinimizedBar"
MinimizedBar.Size = UDim2.fromOffset(190, 46)
MinimizedBar.Position = UDim2.new(0.5, 0, 0.5, 0)
MinimizedBar.AnchorPoint = Vector2.new(0.5, 0.5)
MinimizedBar.BackgroundColor3 = Themes[CurrentTheme].Bg
MinimizedBar.BackgroundTransparency = 0.08
MinimizedBar.BorderSizePixel = 0
MinimizedBar.Active = true
MinimizedBar.Draggable = true
MinimizedBar.Visible = false
MinimizedBar.ZIndex = 50
MinimizedBar.Parent = ScreenGui
Corner(MinimizedBar, 12)
local MinStroke = Stroke(MinimizedBar, Themes[CurrentTheme].Stroke, 1, 0.3)

local MinText = Instance.new("TextLabel")
MinText.Size = UDim2.new(1, -80, 1, 0)
MinText.Position = UDim2.new(0, 18, 0, 0)
MinText.BackgroundTransparency = 1
MinText.Text = "Whiz Hub"
MinText.TextColor3 = Themes[CurrentTheme].Text
MinText.TextXAlignment = Enum.TextXAlignment.Left
MinText.Font = Enum.Font.GothamBold
MinText.TextSize = 15
MinText.ZIndex = 51
MinText.Parent = MinimizedBar

local MinRestore = Instance.new("TextButton")
MinRestore.Name = "RestoreBtn"
MinRestore.Size = UDim2.fromOffset(28, 28)
MinRestore.Position = UDim2.new(1, -62, 0.5, 0)
MinRestore.AnchorPoint = Vector2.new(0, 0.5)
MinRestore.BackgroundColor3 = Themes[CurrentTheme].CardAlt
MinRestore.BackgroundTransparency = 0.2
MinRestore.BorderSizePixel = 0
MinRestore.Text = "−"
MinRestore.TextColor3 = Themes[CurrentTheme].SubText
MinRestore.Font = Enum.Font.GothamBold
MinRestore.TextSize = 18
MinRestore.AutoButtonColor = false
MinRestore.ZIndex = 52
MinRestore.Parent = MinimizedBar
Corner(MinRestore, 8)

local MinClose = Instance.new("TextButton")
MinClose.Name = "CloseBtn"
MinClose.Size = UDim2.fromOffset(28, 28)
MinClose.Position = UDim2.new(1, -30, 0.5, 0)
MinClose.AnchorPoint = Vector2.new(0, 0.5)
MinClose.BackgroundColor3 = Themes[CurrentTheme].CardAlt
MinClose.BackgroundTransparency = 0.2
MinClose.BorderSizePixel = 0
MinClose.Text = ""
MinClose.AutoButtonColor = false
MinClose.ZIndex = 52
MinClose.Parent = MinimizedBar
Corner(MinClose, 8)

do
    local l1 = Instance.new("Frame")
    l1.Name = "XLine1"
    l1.Size = UDim2.fromOffset(11, 2)
    l1.Position = UDim2.fromScale(0.5, 0.5)
    l1.AnchorPoint = Vector2.new(0.5, 0.5)
    l1.Rotation = 45
    l1.BackgroundColor3 = Themes[CurrentTheme].SubText
    l1.BorderSizePixel = 0
    l1.ZIndex = 53
    l1.Parent = MinClose
    Corner(l1, 1)
    local l2 = Instance.new("Frame")
    l2.Name = "XLine2"
    l2.Size = UDim2.fromOffset(11, 2)
    l2.Position = UDim2.fromScale(0.5, 0.5)
    l2.AnchorPoint = Vector2.new(0.5, 0.5)
    l2.Rotation = -45
    l2.BackgroundColor3 = Themes[CurrentTheme].SubText
    l2.BorderSizePixel = 0
    l2.ZIndex = 53
    l2.Parent = MinClose
    Corner(l2, 1)
end

MinRestore.MouseEnter:Connect(function()
    T(MinRestore, 0.15, { BackgroundColor3 = Themes[CurrentTheme].Accent, BackgroundTransparency = 0, TextColor3 = Color3.fromRGB(0,0,0) })
end)
MinRestore.MouseLeave:Connect(function()
    T(MinRestore, 0.15, { BackgroundColor3 = Themes[CurrentTheme].CardAlt, BackgroundTransparency = 0.2, TextColor3 = Themes[CurrentTheme].SubText })
end)
MinClose.MouseEnter:Connect(function()
    T(MinClose, 0.15, { BackgroundColor3 = Themes[CurrentTheme].Accent, BackgroundTransparency = 0 })
    for _, c in ipairs(MinClose:GetChildren()) do
        if c.Name == "XLine1" or c.Name == "XLine2" then
            T(c, 0.15, { BackgroundColor3 = Color3.fromRGB(0,0,0) })
        end
    end
end)
MinClose.MouseLeave:Connect(function()
    T(MinClose, 0.15, { BackgroundColor3 = Themes[CurrentTheme].CardAlt, BackgroundTransparency = 0.2 })
    for _, c in ipairs(MinClose:GetChildren()) do
        if c.Name == "XLine1" or c.Name == "XLine2" then
            T(c, 0.15, { BackgroundColor3 = Themes[CurrentTheme].SubText })
        end
    end
end)

local Sidebar = Instance.new("Frame")
Sidebar.Size = UDim2.new(0, SIDEBAR_W, 1, 0)
Sidebar.BackgroundColor3 = Themes[CurrentTheme].Sidebar
Sidebar.BackgroundTransparency = 0.05
Sidebar.BorderSizePixel = 0
Sidebar.ZIndex = 2
Sidebar.Parent = Main
Corner(Sidebar, 18)

local BrandLabel = Instance.new("TextLabel")
BrandLabel.Size = UDim2.new(1, -44, 0, 26)
BrandLabel.Position = UDim2.new(0, 22, 0, 28)
BrandLabel.BackgroundTransparency = 1
BrandLabel.Text = "Whiz Hub"
BrandLabel.TextColor3 = Themes[CurrentTheme].Text
BrandLabel.TextXAlignment = Enum.TextXAlignment.Left
BrandLabel.Font = Enum.Font.GothamBold
BrandLabel.TextSize = 20
BrandLabel.ZIndex = 3
BrandLabel.Parent = Sidebar

local BrandLine = Instance.new("Frame")
BrandLine.Size = UDim2.new(0, 30, 0, 3)
BrandLine.Position = UDim2.new(0, 22, 0, 60)
BrandLine.BackgroundColor3 = Themes[CurrentTheme].Accent
BrandLine.BorderSizePixel = 0
BrandLine.ZIndex = 3
BrandLine.Parent = Sidebar
Corner(BrandLine, 2)

local Nav = Instance.new("Frame")
Nav.Size = UDim2.new(1, -24, 0, 280)
Nav.Position = UDim2.new(0, 12, 0, 90)
Nav.BackgroundTransparency = 1
Nav.ZIndex = 3
Nav.Parent = Sidebar

local NavLayout = Instance.new("UIListLayout")
NavLayout.Padding = UDim.new(0, 6)
NavLayout.SortOrder = Enum.SortOrder.LayoutOrder
NavLayout.Parent = Nav

local NavButtons = { active = "" }
local Pages = {}

local function CreateNavButton(name, label, symbol, order)
    local btn = Instance.new("TextButton")
    btn.Name = name
    btn.Size = UDim2.new(1, 0, 0, 46)
    btn.BackgroundColor3 = Themes[CurrentTheme].Card
    btn.BackgroundTransparency = 1
    btn.BorderSizePixel = 0
    btn.Text = ""
    btn.AutoButtonColor = false
    btn.Active = true
    btn.LayoutOrder = order
    btn.ZIndex = 5
    btn.Parent = Nav
    Corner(btn, 10)

    local indicator = Instance.new("Frame")
    indicator.Name = "Indicator"
    indicator.Size = UDim2.new(0, 3, 0.55, 0)
    indicator.Position = UDim2.new(0, -12, 0.5, 0)
    indicator.AnchorPoint = Vector2.new(0, 0.5)
    indicator.BackgroundColor3 = Themes[CurrentTheme].Accent
    indicator.BorderSizePixel = 0
    indicator.BackgroundTransparency = 1
    indicator.ZIndex = 6
    indicator.Parent = btn
    Corner(indicator, 2)

    local iconBg = Instance.new("Frame")
    iconBg.Name = "IconBg"
    iconBg.Size = UDim2.fromOffset(30, 30)
    iconBg.Position = UDim2.new(0, 10, 0.5, 0)
    iconBg.AnchorPoint = Vector2.new(0, 0.5)
    iconBg.BackgroundColor3 = Themes[CurrentTheme].CardAlt
    iconBg.BorderSizePixel = 0
    iconBg.ZIndex = 6
    iconBg.Parent = btn
    Corner(iconBg, 15)

    local icon = Instance.new("TextLabel")
    icon.Name = "Icon"
    icon.Size = UDim2.fromScale(1, 1)
    icon.BackgroundTransparency = 1
    icon.Text = symbol
    icon.TextColor3 = Themes[CurrentTheme].SubText
    icon.Font = Enum.Font.GothamBlack
    icon.TextSize = 18
    icon.ZIndex = 7
    icon.Parent = iconBg

    local txt = Instance.new("TextLabel")
    txt.Name = "Label"
    txt.Size = UDim2.new(1, -52, 1, 0)
    txt.Position = UDim2.new(0, 48, 0, 0)
    txt.BackgroundTransparency = 1
    txt.Text = label
    txt.TextColor3 = Themes[CurrentTheme].SubText
    txt.TextXAlignment = Enum.TextXAlignment.Left
    txt.Font = Enum.Font.GothamMedium
    txt.TextSize = 14
    txt.ZIndex = 6
    txt.Parent = btn

    btn.MouseEnter:Connect(function()
        if NavButtons.active ~= name then
            T(btn, 0.15, { BackgroundTransparency = 0.4 })
            T(txt, 0.15, { TextColor3 = Themes[CurrentTheme].Text })
        end
    end)
    btn.MouseLeave:Connect(function()
        if NavButtons.active ~= name then
            T(btn, 0.15, { BackgroundTransparency = 1 })
            T(txt, 0.15, { TextColor3 = Themes[CurrentTheme].SubText })
        end
    end)

    NavButtons[name] = btn
    return btn
end

CreateNavButton("Main",     "Main",        "⌂", 1)
CreateNavButton("AutoBuy",  "Auto Buy",    "$", 2)
CreateNavButton("Reward",   "Reward",      "★", 3)
CreateNavButton("Settings", "Settings",    "⚙", 4)

local ProfileCard = Instance.new("Frame")
ProfileCard.Size = UDim2.new(1, -24, 0, 54)
ProfileCard.Position = UDim2.new(0, 12, 1, -66)
ProfileCard.AnchorPoint = Vector2.new(0, 1)
ProfileCard.BackgroundColor3 = Themes[CurrentTheme].Card
ProfileCard.BackgroundTransparency = 0.2
ProfileCard.BorderSizePixel = 0
ProfileCard.ZIndex = 3
ProfileCard.Parent = Sidebar
Corner(ProfileCard, 12)
local ProfileStroke = Stroke(ProfileCard, Themes[CurrentTheme].Stroke, 1, 0.5)

local Avatar = Instance.new("ImageLabel")
Avatar.Size = UDim2.fromOffset(38, 38)
Avatar.Position = UDim2.new(0, 8, 0.5, 0)
Avatar.AnchorPoint = Vector2.new(0, 0.5)
Avatar.BackgroundColor3 = Themes[CurrentTheme].CardAlt
Avatar.BorderSizePixel = 0
Avatar.Image = ""
Avatar.ZIndex = 4
Avatar.Parent = ProfileCard
Corner(Avatar, 19)

task.spawn(function()
    local ok, url = pcall(function()
        return Players:GetUserThumbnailAsync(LP.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size100x100)
    end)
    if ok and url then Avatar.Image = url end
end)

local ProfileName = Instance.new("TextLabel")
ProfileName.Size = UDim2.new(1, -58, 0, 16)
ProfileName.Position = UDim2.new(0, 52, 0, 9)
ProfileName.BackgroundTransparency = 1
ProfileName.Text = LP.DisplayName or LP.Name
ProfileName.TextColor3 = Themes[CurrentTheme].Text
ProfileName.TextXAlignment = Enum.TextXAlignment.Left
ProfileName.Font = Enum.Font.GothamBold
ProfileName.TextSize = 13
ProfileName.TextTruncate = Enum.TextTruncate.AtEnd
ProfileName.ZIndex = 4
ProfileName.Parent = ProfileCard

local ProfileSub = Instance.new("TextLabel")
ProfileSub.Size = UDim2.new(1, -58, 0, 14)
ProfileSub.Position = UDim2.new(0, 52, 0, 27)
ProfileSub.BackgroundTransparency = 1
ProfileSub.Text = "Whiz User"
ProfileSub.TextColor3 = Themes[CurrentTheme].SubText
ProfileSub.TextXAlignment = Enum.TextXAlignment.Left
ProfileSub.Font = Enum.Font.Gotham
ProfileSub.TextSize = 11
ProfileSub.TextTruncate = Enum.TextTruncate.AtEnd
ProfileSub.ZIndex = 4
ProfileSub.Parent = ProfileCard

local TopBar = Instance.new("Frame")
TopBar.Size = UDim2.new(1, -SIDEBAR_W, 0, TOPBAR_H)
TopBar.Position = UDim2.new(0, SIDEBAR_W, 0, 0)
TopBar.BackgroundTransparency = 1
TopBar.ZIndex = 3
TopBar.Parent = Main

local Title = Instance.new("TextLabel")
Title.Size = UDim2.new(1, -220, 1, 0)
Title.Position = UDim2.new(0, 30, 0, 0)
Title.BackgroundTransparency = 1
Title.Text = "Main"
Title.TextColor3 = Themes[CurrentTheme].Text
Title.TextXAlignment = Enum.TextXAlignment.Left
Title.TextYAlignment = Enum.TextYAlignment.Center
Title.Font = Enum.Font.GothamBold
Title.TextSize = 22
Title.ZIndex = 4
Title.Parent = TopBar

local function CreateTopButton(name, symbol, xOffset)
    local btn = Instance.new("TextButton")
    btn.Name = name
    btn.Size = UDim2.fromOffset(36, 36)
    btn.Position = UDim2.new(1, xOffset, 0.5, 0)
    btn.AnchorPoint = Vector2.new(0, 0.5)
    btn.BackgroundColor3 = Themes[CurrentTheme].CardAlt
    btn.BackgroundTransparency = 0.2
    btn.BorderSizePixel = 0
    btn.Text = symbol or ""
    btn.TextColor3 = Themes[CurrentTheme].SubText
    btn.Font = Enum.Font.GothamBold
    btn.TextSize = 18
    btn.AutoButtonColor = false
    btn.ZIndex = 4
    btn.Parent = TopBar
    Corner(btn, 10)
    btn.MouseEnter:Connect(function()
        T(btn, 0.15, { BackgroundColor3 = Themes[CurrentTheme].Accent, BackgroundTransparency = 0, TextColor3 = Color3.fromRGB(0,0,0) })
        for _, c in ipairs(btn:GetChildren()) do
            if c.Name == "XLine1" or c.Name == "XLine2" then
                T(c, 0.15, { BackgroundColor3 = Color3.fromRGB(0,0,0) })
            end
        end
    end)
    btn.MouseLeave:Connect(function()
        T(btn, 0.15, { BackgroundColor3 = Themes[CurrentTheme].CardAlt, BackgroundTransparency = 0.2, TextColor3 = Themes[CurrentTheme].SubText })
        for _, c in ipairs(btn:GetChildren()) do
            if c.Name == "XLine1" or c.Name == "XLine2" then
                T(c, 0.15, { BackgroundColor3 = Themes[CurrentTheme].SubText })
            end
        end
    end)
    return btn
end

local MinimizeBtn = CreateTopButton("Minimize", "−", -100)
local CloseBtn    = CreateTopButton("Close",    nil, -54)

do
    local line1 = Instance.new("Frame")
    line1.Name = "XLine1"
    line1.Size = UDim2.fromOffset(15, 2)
    line1.Position = UDim2.fromScale(0.5, 0.5)
    line1.AnchorPoint = Vector2.new(0.5, 0.5)
    line1.Rotation = 45
    line1.BackgroundColor3 = Themes[CurrentTheme].SubText
    line1.BorderSizePixel = 0
    line1.ZIndex = 5
    line1.Parent = CloseBtn
    Corner(line1, 1)
    local line2 = Instance.new("Frame")
    line2.Name = "XLine2"
    line2.Size = UDim2.fromOffset(15, 2)
    line2.Position = UDim2.fromScale(0.5, 0.5)
    line2.AnchorPoint = Vector2.new(0.5, 0.5)
    line2.Rotation = -45
    line2.BackgroundColor3 = Themes[CurrentTheme].SubText
    line2.BorderSizePixel = 0
    line2.ZIndex = 5
    line2.Parent = CloseBtn
    Corner(line2, 1)
end

local PageContainer = Instance.new("Frame")
PageContainer.Size = UDim2.new(1, -SIDEBAR_W, 1, -TOPBAR_H)
PageContainer.Position = UDim2.new(0, SIDEBAR_W, 0, TOPBAR_H)
PageContainer.BackgroundTransparency = 1
PageContainer.ZIndex = 3
PageContainer.ClipsDescendants = true
PageContainer.Parent = Main

local function CreatePage(name)
    local page = Instance.new("Frame")
    page.Name = name
    page.Size = UDim2.fromScale(1, 1)
    page.BackgroundTransparency = 1
    page.Visible = false
    page.ZIndex = 3
    page.Parent = PageContainer

    local pad = Instance.new("UIPadding")
    pad.PaddingTop = UDim.new(0, 8)
    pad.PaddingBottom = UDim.new(0, 24)
    pad.PaddingLeft = UDim.new(0, 30)
    pad.PaddingRight = UDim.new(0, 30)
    pad.Parent = page

    local scroll = Instance.new("ScrollingFrame")
    scroll.Name = "Scroll"
    scroll.Size = UDim2.fromScale(1, 1)
    scroll.BackgroundTransparency = 1
    scroll.BorderSizePixel = 0
    scroll.ScrollBarThickness = 3
    scroll.ScrollBarImageColor3 = Themes[CurrentTheme].Accent
    scroll.ScrollBarImageTransparency = 0.4
    scroll.CanvasSize = UDim2.new(0, 0, 0, 0)
    scroll.AutomaticCanvasSize = Enum.AutomaticSize.Y
    scroll.ZIndex = 4
    scroll.Parent = page

    local layout = Instance.new("UIListLayout")
    layout.Padding = UDim.new(0, 8)
    layout.SortOrder = Enum.SortOrder.LayoutOrder
    layout.Parent = scroll

    Pages[name] = { Frame = page, Scroll = scroll, Layout = layout }
    return page
end

CreatePage("Main")
CreatePage("AutoBuy")
CreatePage("Reward")
CreatePage("Settings")

local AllToggleCards = {}

local function CreateCard(parent, order)
    local card = Instance.new("Frame")
    card.Name = "Card"
    card.Size = UDim2.new(1, 0, 0, 52)
    card.BackgroundColor3 = Themes[CurrentTheme].Card
    card.BackgroundTransparency = 0.08
    card.BorderSizePixel = 0
    card.LayoutOrder = order or 0
    card.ZIndex = 4
    card.Parent = parent
    Corner(card, 12)
    Stroke(card, Themes[CurrentTheme].Stroke, 1, 0.55)
    return card
end

local function CreateToggle(parent, label, key, default)
    local card = CreateCard(parent)
    local name = Instance.new("TextLabel")
    name.Size = UDim2.new(0.7, 0, 1, 0)
    name.Position = UDim2.new(0, 20, 0, 0)
    name.BackgroundTransparency = 1
    name.Text = label
    name.TextColor3 = Themes[CurrentTheme].Text
    name.TextXAlignment = Enum.TextXAlignment.Left
    name.Font = Enum.Font.GothamMedium
    name.TextSize = 14
    name.ZIndex = 5
    name.Parent = card

    local status = Instance.new("TextLabel")
    status.Name = "Status"
    status.Size = UDim2.new(0, 60, 0, 24)
    status.Position = UDim2.new(1, -20, 0.5, 0)
    status.AnchorPoint = Vector2.new(1, 0.5)
    status.BackgroundTransparency = 1
    status.Text = "OFF"
    status.TextColor3 = Themes[CurrentTheme].SubText
    status.TextXAlignment = Enum.TextXAlignment.Right
    status.Font = Enum.Font.GothamBold
    status.TextSize = 13
    status.ZIndex = 6
    status.Parent = card

    local btn = Instance.new("TextButton")
    btn.Size = UDim2.fromScale(1, 1)
    btn.BackgroundTransparency = 1
    btn.Text = ""
    btn.ZIndex = 7
    btn.Parent = card

    local state = default or false
    State[key] = state

    local function render()
        if state then
            T(card, 0.2, { BackgroundColor3 = Themes[CurrentTheme].CardAlt })
            status.Text = "ON"
            status.TextColor3 = Themes[CurrentTheme].Accent2
        else
            T(card, 0.2, { BackgroundColor3 = Themes[CurrentTheme].Card })
            status.Text = "OFF"
            status.TextColor3 = Themes[CurrentTheme].SubText
        end
    end
    render()

    btn.MouseButton1Click:Connect(function()
        state = not state
        State[key] = state
        render()
        if _G.OnToggle then _G.OnToggle(key, state) end
    end)

    card:SetAttribute("ToggleKey", key)
    table.insert(AllToggleCards, { Card = card, Status = status, Key = key })
    return card, btn
end

local function CreateButton(parent, label, onClick)
    local card = CreateCard(parent)
    local name = Instance.new("TextLabel")
    name.Size = UDim2.new(0.7, 0, 1, 0)
    name.Position = UDim2.new(0, 20, 0, 0)
    name.BackgroundTransparency = 1
    name.Text = label
    name.TextColor3 = Themes[CurrentTheme].Text
    name.TextXAlignment = Enum.TextXAlignment.Left
    name.Font = Enum.Font.GothamMedium
    name.TextSize = 14
    name.ZIndex = 5
    name.Parent = card

    local arrow = Instance.new("TextLabel")
    arrow.Name = "Arrow"
    arrow.Size = UDim2.new(0, 100, 0, 24)
    arrow.Position = UDim2.new(1, -20, 0.5, 0)
    arrow.AnchorPoint = Vector2.new(1, 0.5)
    arrow.BackgroundTransparency = 1
    arrow.Text = "RUN →"
    arrow.TextColor3 = Themes[CurrentTheme].Accent2
    arrow.TextXAlignment = Enum.TextXAlignment.Right
    arrow.Font = Enum.Font.GothamBold
    arrow.TextSize = 12
    arrow.ZIndex = 6
    arrow.Parent = card

    local btn = Instance.new("TextButton")
    btn.Size = UDim2.fromScale(1, 1)
    btn.BackgroundTransparency = 1
    btn.Text = ""
    btn.ZIndex = 7
    btn.Parent = card

    btn.MouseButton1Click:Connect(function()
        T(card, 0.1, { BackgroundColor3 = Themes[CurrentTheme].Accent })
        task.delay(0.2, function()
            T(card, 0.2, { BackgroundColor3 = Themes[CurrentTheme].Card })
        end)
        if onClick then onClick() end
    end)
    return card, btn
end

local function CreateSlider(parent, label, minV, maxV, default, suffix, onChange)
    local card = CreateCard(parent)
    card.Size = UDim2.new(1, 0, 0, 66)
    local name = Instance.new("TextLabel")
    name.Size = UDim2.new(0.7, 0, 0, 22)
    name.Position = UDim2.new(0, 20, 0, 10)
    name.BackgroundTransparency = 1
    name.Text = label
    name.TextColor3 = Themes[CurrentTheme].Text
    name.TextXAlignment = Enum.TextXAlignment.Left
    name.Font = Enum.Font.GothamMedium
    name.TextSize = 14
    name.ZIndex = 5
    name.Parent = card

    local valueLbl = Instance.new("TextLabel")
    valueLbl.Size = UDim2.new(0, 80, 0, 22)
    valueLbl.Position = UDim2.new(1, -20, 0, 10)
    valueLbl.AnchorPoint = Vector2.new(1, 0)
    valueLbl.BackgroundTransparency = 1
    valueLbl.Text = tostring(default) .. (suffix or "")
    valueLbl.TextColor3 = Themes[CurrentTheme].Accent2
    valueLbl.TextXAlignment = Enum.TextXAlignment.Right
    valueLbl.Font = Enum.Font.GothamBold
    valueLbl.TextSize = 13
    valueLbl.ZIndex = 5
    valueLbl.Parent = card

    local bar = Instance.new("Frame")
    bar.Size = UDim2.new(1, -40, 0, 6)
    bar.Position = UDim2.new(0, 20, 1, -16)
    bar.AnchorPoint = Vector2.new(0, 0.5)
    bar.BackgroundColor3 = Themes[CurrentTheme].ToggleOff
    bar.BorderSizePixel = 0
    bar.ZIndex = 5
    bar.Parent = card
    Corner(bar, 3)

    local fill = Instance.new("Frame")
    fill.Size = UDim2.new((default - minV) / (maxV - minV), 0, 1, 0)
    fill.BackgroundColor3 = Themes[CurrentTheme].Accent
    fill.BorderSizePixel = 0
    fill.ZIndex = 6
    fill.Parent = bar
    Corner(fill, 3)

    local knob = Instance.new("Frame")
    knob.Size = UDim2.fromOffset(14, 14)
    knob.AnchorPoint = Vector2.new(0.5, 0.5)
    knob.Position = UDim2.new(fill.Size.X.Scale, 0, 0.5, 0)
    knob.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
    knob.BorderSizePixel = 0
    knob.ZIndex = 7
    knob.Parent = bar
    Corner(knob, 7)

    local dragging = false
    local function setFromX(x)
        local rel = math.clamp((x - bar.AbsolutePosition.X) / bar.AbsoluteSize.X, 0, 1)
        local val = minV + (maxV - minV) * rel
        val = math.floor(val * 100 + 0.5) / 100
        fill.Size = UDim2.new(rel, 0, 1, 0)
        knob.Position = UDim2.new(rel, 0, 0.5, 0)
        valueLbl.Text = tostring(val) .. (suffix or "")
        if onChange then onChange(val) end
    end

    local hit = Instance.new("TextButton")
    hit.Size = UDim2.new(1, 30, 0, 26)
    hit.Position = UDim2.new(0, -15, 1, -30)
    hit.BackgroundTransparency = 1
    hit.Text = ""
    hit.ZIndex = 8
    hit.Parent = card

    hit.InputBegan:Connect(function(input)
        if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
            dragging = true
            setFromX(input.Position.X)
        end
    end)
    UserInputService.InputChanged:Connect(function(input)
        if dragging and (input.UserInputType == Enum.UserInputType.MouseMovement or input.UserInputType == Enum.UserInputType.Touch) then
            setFromX(input.Position.X)
        end
    end)
    UserInputService.InputEnded:Connect(function(input)
        if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
            dragging = false
        end
    end)
    return card
end

-- ==========================================
-- MAIN PAGE
-- ==========================================
CreateToggle(Pages.Main.Scroll, "Auto Rebirth", "AutoRebirth", false)
CreateToggle(Pages.Main.Scroll, "Auto Buy Trails", "AutoBuyTrails", false)
CreateButton(Pages.Main.Scroll, "Open Trails Menu", function()
    openTrailsMenu()
    Notify("Trails", "Menu aciliyor...", "success")
end)
CreateButton(Pages.Main.Scroll, "Debug Trail State", function()
    _G.autoTrails.state()
    Notify("Debug", "Output'a bak.", "success")
end)

-- ==========================================
-- SETTINGS PAGE
-- ==========================================
CreateSlider(Pages.Settings.Scroll, "UI Scale", 0.7, 1.4, 1.0, "x", function(v)
    CurrentScale = v
    if Main.Visible then
        T(Main, 0.15, { Size = UDim2.fromOffset(BASE_W * v, BASE_H * v) })
    end
end)

local DiscordCard = CreateCard(Pages.Settings.Scroll)
DiscordCard.Size = UDim2.new(1, 0, 0, 32 + 44 + 44 + 12)

local DiscordTitle = Instance.new("TextLabel")
DiscordTitle.Size = UDim2.new(1, -40, 0, 22)
DiscordTitle.Position = UDim2.new(0, 20, 0, 10)
DiscordTitle.BackgroundTransparency = 1
DiscordTitle.Text = "Discord"
DiscordTitle.TextColor3 = Themes[CurrentTheme].Text
DiscordTitle.TextXAlignment = Enum.TextXAlignment.Left
DiscordTitle.Font = Enum.Font.GothamBold
DiscordTitle.TextSize = 14
DiscordTitle.ZIndex = 5
DiscordTitle.Parent = DiscordCard

local function MakeDiscordRow(parent, yPos, label, value, getName)
    local row = Instance.new("Frame")
    row.Size = UDim2.new(1, -40, 0, 44)
    row.Position = UDim2.new(0, 20, 0, yPos)
    row.BackgroundColor3 = Themes[CurrentTheme].CardAlt
    row.BackgroundTransparency = 0.2
    row.BorderSizePixel = 0
    row.ZIndex = 5
    row.Parent = parent
    Corner(row, 8)

    local lbl = Instance.new("TextLabel")
    lbl.Size = UDim2.new(0.35, 0, 1, 0)
    lbl.Position = UDim2.new(0, 14, 0, 0)
    lbl.BackgroundTransparency = 1
    lbl.Text = label
    lbl.TextColor3 = Themes[CurrentTheme].SubText
    lbl.TextXAlignment = Enum.TextXAlignment.Left
    lbl.Font = Enum.Font.Gotham
    lbl.TextSize = 12
    lbl.ZIndex = 6
    lbl.Parent = row

    local val = Instance.new("TextLabel")
    val.Size = UDim2.new(0.4, 0, 1, 0)
    val.Position = UDim2.new(0.35, 0, 0, 0)
    val.BackgroundTransparency = 1
    val.Text = value
    val.TextColor3 = Themes[CurrentTheme].Text
    val.TextXAlignment = Enum.TextXAlignment.Left
    val.Font = Enum.Font.GothamMedium
    val.TextSize = 13
    val.ZIndex = 6
    val.Parent = row

    local copy = Instance.new("TextLabel")
    copy.Size = UDim2.new(0, 100, 0, 20)
    copy.Position = UDim2.new(1, -14, 0.5, 0)
    copy.AnchorPoint = Vector2.new(1, 0.5)
    copy.BackgroundTransparency = 1
    copy.Text = "Click to copy"
    copy.TextColor3 = Themes[CurrentTheme].Accent2
    copy.TextXAlignment = Enum.TextXAlignment.Right
    copy.Font = Enum.Font.GothamBold
    copy.TextSize = 11
    copy.ZIndex = 6
    copy.Parent = row

    local btn = Instance.new("TextButton")
    btn.Size = UDim2.fromScale(1, 1)
    btn.BackgroundTransparency = 1
    btn.Text = ""
    btn.ZIndex = 7
    btn.Parent = row

    btn.MouseButton1Click:Connect(function()
        local ok = CopyToClipboard(value)
        T(row, 0.1, { BackgroundColor3 = Themes[CurrentTheme].Accent, BackgroundTransparency = 0 })
        task.delay(0.2, function()
            T(row, 0.2, { BackgroundColor3 = Themes[CurrentTheme].CardAlt, BackgroundTransparency = 0.2 })
        end)
        if ok then
            Notify("Copied", getName .. " copied.", "success")
        else
            Notify("Copy Failed", "Executor clipboard desteklemiyor.", "error")
        end
    end)
    return row
end

MakeDiscordRow(DiscordCard, 36, "Username", DISCORD_USER, "Discord username")
MakeDiscordRow(DiscordCard, 88, "Server", DISCORD_INVITE, "Discord invite")

local ThemeCard = CreateCard(Pages.Settings.Scroll)
ThemeCard.Size = UDim2.new(1, 0, 0, 108)

local ThemeTitle = Instance.new("TextLabel")
ThemeTitle.Size = UDim2.new(1, -40, 0, 22)
ThemeTitle.Position = UDim2.new(0, 20, 0, 12)
ThemeTitle.BackgroundTransparency = 1
ThemeTitle.Text = "Theme"
ThemeTitle.TextColor3 = Themes[CurrentTheme].Text
ThemeTitle.TextXAlignment = Enum.TextXAlignment.Left
ThemeTitle.Font = Enum.Font.GothamMedium
ThemeTitle.TextSize = 14
ThemeTitle.ZIndex = 5
ThemeTitle.Parent = ThemeCard

local ThemeRow = Instance.new("Frame")
ThemeRow.Size = UDim2.new(1, -40, 0, 38)
ThemeRow.Position = UDim2.new(0, 20, 0, 42)
ThemeRow.BackgroundTransparency = 1
ThemeRow.ZIndex = 5
ThemeRow.Parent = ThemeCard

local ThemeLayout = Instance.new("UIListLayout")
ThemeLayout.FillDirection = Enum.FillDirection.Horizontal
ThemeLayout.Padding = UDim.new(0, 8)
ThemeLayout.SortOrder = Enum.SortOrder.LayoutOrder
ThemeLayout.Parent = ThemeRow

local ThemeButtons = {}

local function ApplyTheme(themeName)
    local T2 = Themes[themeName]
    CurrentTheme = themeName

    T(Main, 0.3, { BackgroundColor3 = T2.Bg })
    T(Sidebar, 0.3, { BackgroundColor3 = T2.Sidebar })
    T(BrandLabel, 0.3, { TextColor3 = T2.Text })
    T(BrandLine, 0.3, { BackgroundColor3 = T2.Accent })
    T(MainStroke, 0.3, { Color = T2.Stroke })
    T(Title, 0.3, { TextColor3 = T2.Text })
    T(MinimizedBar, 0.3, { BackgroundColor3 = T2.Bg })
    T(MinStroke, 0.3, { Color = T2.Stroke })
    T(MinText, 0.3, { TextColor3 = T2.Text })
    T(MinRestore, 0.3, { BackgroundColor3 = T2.CardAlt, TextColor3 = T2.SubText })
    T(MinClose, 0.3, { BackgroundColor3 = T2.CardAlt })
    for _, c in ipairs(MinClose:GetChildren()) do
        if c.Name == "XLine1" or c.Name == "XLine2" then
            c.BackgroundColor3 = T2.SubText
        end
    end

    T(ProfileCard, 0.3, { BackgroundColor3 = T2.Card })
    T(ProfileStroke, 0.3, { Color = T2.Stroke })
    T(Avatar, 0.3, { BackgroundColor3 = T2.CardAlt })
    T(ProfileName, 0.3, { TextColor3 = T2.Text })
    T(ProfileSub, 0.3, { TextColor3 = T2.SubText })

    for _, page in pairs(Pages) do
        for _, desc in ipairs(page.Frame:GetDescendants()) do
            if desc:IsA("Frame") and desc.Name == "Card" then
                desc.BackgroundColor3 = T2.Card
                for _, s in ipairs(desc:GetChildren()) do
                    if s:IsA("UIStroke") then s.Color = T2.Stroke end
                end
            elseif desc:IsA("TextLabel") then
                if desc.Name == "Title" then
                    desc.TextColor3 = T2.Text
                elseif desc.Parent and desc.Parent.Name == "Card" and desc.Name ~= "Label" and desc.Name ~= "Status" and desc.Name ~= "Arrow" then
                    desc.TextColor3 = T2.Text
                end
            end
        end
    end

    for _, t in ipairs(AllToggleCards) do
        if State[t.Key] then
            t.Card.BackgroundColor3 = T2.CardAlt
            t.Status.TextColor3 = T2.Accent2
        else
            t.Card.BackgroundColor3 = T2.Card
            t.Status.TextColor3 = T2.SubText
        end
    end

    for n, btn in pairs(NavButtons) do
        if typeof(btn) == "Instance" and btn:IsA("TextButton") then
            local indicator = btn:FindFirstChild("Indicator")
            local iconBg = btn:FindFirstChild("IconBg")
            local lbl = btn:FindFirstChild("Label")
            local icon = iconBg and iconBg:FindFirstChild("Icon")
            if n == CurrentTab then
                if icon then icon.TextColor3 = Color3.fromRGB(0,0,0) end
                if iconBg then iconBg.BackgroundColor3 = T2.Accent end
                if lbl then lbl.TextColor3 = T2.Text end
                if indicator then indicator.BackgroundColor3 = T2.Accent end
            else
                if icon then icon.TextColor3 = T2.SubText end
                if iconBg then iconBg.BackgroundColor3 = T2.CardAlt end
                if lbl then lbl.TextColor3 = T2.SubText end
                if indicator then indicator.BackgroundColor3 = T2.Accent end
            end
        end
    end

    for _, tb in ipairs({ MinimizeBtn, CloseBtn }) do
        if tb then
            tb.BackgroundColor3 = T2.CardAlt
            tb.TextColor3 = T2.SubText
            for _, c in ipairs(tb:GetChildren()) do
                if c.Name == "XLine1" or c.Name == "XLine2" then
                    c.BackgroundColor3 = T2.SubText
                end
            end
        end
    end

    for _, tb in ipairs(ThemeButtons) do
        if tb:GetAttribute("ThemeName") == themeName then
            T(tb, 0.2, { BackgroundColor3 = T2.Accent })
            tb.TextColor3 = Color3.fromRGB(0, 0, 0)
        else
            T(tb, 0.2, { BackgroundColor3 = T2.CardAlt })
            tb.TextColor3 = T2.SubText
        end
    end
end

for i, themeName in ipairs({ "Black", "Midnight", "Bloodmoon", "Emerald", "Ocean", "Sunset" }) do
    local btn = Instance.new("TextButton")
    btn.Size = UDim2.fromOffset(90, 36)
    btn.BackgroundColor3 = Themes[CurrentTheme].CardAlt
    btn.BorderSizePixel = 0
    btn.Text = themeName
    btn.TextColor3 = Themes[CurrentTheme].SubText
    btn.Font = Enum.Font.GothamMedium
    btn.TextSize = 12
    btn.AutoButtonColor = false
    btn.LayoutOrder = i
    btn.ZIndex = 6
    btn.Parent = ThemeRow
    btn:SetAttribute("ThemeName", themeName)
    Corner(btn, 10)
    btn.MouseButton1Click:Connect(function() ApplyTheme(themeName) end)
    table.insert(ThemeButtons, btn)
end

local function SwitchPage(name)
    CurrentTab = name
    for n, page in pairs(Pages) do
        page.Frame.Visible = (n == name)
    end
    for n, btn in pairs(NavButtons) do
        if typeof(btn) == "Instance" and btn:IsA("TextButton") then
            local indicator = btn:FindFirstChild("Indicator")
            local iconBg = btn:FindFirstChild("IconBg")
            local lbl = btn:FindFirstChild("Label")
            local icon = iconBg and iconBg:FindFirstChild("Icon")
            if n == name then
                NavButtons.active = n
                T(btn, 0.2, { BackgroundColor3 = Themes[CurrentTheme].CardAlt, BackgroundTransparency = 0 })
                if icon then T(icon, 0.2, { TextColor3 = Color3.fromRGB(0,0,0) }) end
                if iconBg then T(iconBg, 0.2, { BackgroundColor3 = Themes[CurrentTheme].Accent }) end
                if lbl then T(lbl, 0.2, { TextColor3 = Themes[CurrentTheme].Text }) end
                if indicator then T(indicator, 0.2, { BackgroundTransparency = 0 }) end
            else
                T(btn, 0.2, { BackgroundColor3 = Themes[CurrentTheme].Card, BackgroundTransparency = 1 })
                if icon then T(icon, 0.2, { TextColor3 = Themes[CurrentTheme].SubText }) end
                if iconBg then T(iconBg, 0.2, { BackgroundColor3 = Themes[CurrentTheme].CardAlt }) end
                if lbl then T(lbl, 0.2, { TextColor3 = Themes[CurrentTheme].SubText }) end
                if indicator then T(indicator, 0.2, { BackgroundTransparency = 1 }) end
            end
        end
    end
    Title.Text = name == "Main" and "Main" or name == "AutoBuy" and "Auto Buy" or name == "Reward" and "Reward" or "Settings"
end

for name, btn in pairs(NavButtons) do
    if typeof(btn) == "Instance" and btn:IsA("TextButton") then
        btn.Activated:Connect(function() SwitchPage(name) end)
    end
end

SwitchPage("Main")

local function StopAllFeatures()
    for _, t in ipairs(AllToggleCards) do
        State[t.Key] = false
        t.Card.BackgroundColor3 = Themes[CurrentTheme].Card
        t.Status.Text = "OFF"
        t.Status.TextColor3 = Themes[CurrentTheme].SubText
        if _G.OnToggle then
            pcall(_G.OnToggle, t.Key, false)
        end
    end
end

local function minimize()
    MinimizedBar.Position = Main.Position
    MinimizedBar.AnchorPoint = Main.AnchorPoint
    Main.Visible = false
    MinimizedBar.Visible = true
end
local function restore()
    MinimizedBar.Visible = false
    Main.Position = UDim2.new(0.5, 0, 0.5, 0)
    Main.AnchorPoint = Vector2.new(0.5, 0.5)
    Main.Visible = true
end

MinimizeBtn.MouseButton1Click:Connect(minimize)
MinRestore.MouseButton1Click:Connect(restore)

MinClose.MouseButton1Click:Connect(function()
    StopAllFeatures()
    ScreenGui:Destroy()
end)
CloseBtn.MouseButton1Click:Connect(function()
    StopAllFeatures()
    ScreenGui:Destroy()
end)

UserInputService.InputBegan:Connect(function(input, gp)
    if gp then return end
    if input.KeyCode == Enum.KeyCode.RightShift then
        if ScreenGui and ScreenGui.Parent then
            if Main.Visible then minimize() else restore() end
        end
    end
end)

ApplyTheme("Black")
Notify("Whiz Hub", "Loaded. RightShift toggle.", "success")
vlog("Whiz Hub hazir. Main > Auto Rebirth / Auto Buy Trails")