Загрузка данных


--[[
    ===================================================
    Project: NEL UI Hub (v5.4 Key System Edition)
    Creators: Neliks & AI
    Supported Executor: Delta / Synapse / Mobile & PC
    ===================================================
]]--

local NelHub = {}

function NelHub:CreateWindow(customTitle, defaultBg, keyConfig, keyPasswordParam)
    -- Проверка названия: если не указано или пустое, ставится "NELIKS MENU"
    local WindowTitle = (type(customTitle) == "string" and customTitle:gsub("%s+", "") ~= "") and customTitle or "NELIKS MENU"

    -- Обработка кастомного дефолтного фона
    local function parseBgId(idInput)
        if not idInput then return nil end
        local cleanId = tostring(idInput):match("%d+")
        return cleanId and ("rbxassetid://" .. cleanId) or nil
    end

    -- Настройка системы ключей (Key System)
    local KeySystemEnabled = false
    local CorrectKey = ""

    if type(keyConfig) == "table" then
        KeySystemEnabled = keyConfig.KeySystem or keyConfig.Enabled or false
        CorrectKey = tostring(keyConfig.Key or keyConfig.Password or keyConfig.PasswordKey or "")
    elseif type(keyConfig) == "boolean" then
        KeySystemEnabled = keyConfig
        CorrectKey = tostring(keyPasswordParam or "")
    end

    local CoreGui = game:GetService("CoreGui")
    local Players = game:GetService("Players")
    local UserInputService = game:GetService("UserInputService")
    local SoundService = game:GetService("SoundService")
    local TweenService = game:GetService("TweenService")
    local Lighting = game:GetService("Lighting")

    -- Очистка старых объектов
    if CoreGui:FindFirstChild("NelCustomHub") then
        CoreGui.NelCustomHub:Destroy()
    end
    if Lighting:FindFirstChild("NelUIBlur") then
        Lighting.NelUIBlur:Destroy()
    end

    -- Эффект размытия заднего плана (Blur)
    local Blur = Instance.new("BlurEffect")
    Blur.Name = "NelUIBlur"
    Blur.Size = 0
    Blur.Parent = Lighting

    -- Звуки и глобальные переменные
    local GlobalVolume = 1
    local CurrentLanguage = "RU"
    local MaxChannelLink = "https://max.ru/join/TeZHb32gsp_Pq9ca7PMurqmHaE27rFL6CNJPdGWDP2k"
    local CurrentBorderColor = Color3.fromRGB(60, 60, 90)

    local function setupSound(id, name)
        local sound = Instance.new("Sound")
        sound.Name = name
        sound.SoundId = "rbxassetid://" .. tostring(id)
        sound.Volume = GlobalVolume
        sound.Parent = SoundService
        return sound
    end

    local soundOpen  = setupSound(4724430129, "NelOpenSound")
    local soundClose = setupSound(255476332,  "NelCloseSound")
    local soundClick = setupSound(4307186075, "NelClickSound")
    local soundDrag  = setupSound(6895079853, "NelDragSound")

    local function playSound(soundObj)
        if soundObj then
            soundObj.Volume = GlobalVolume
            soundObj:Play()
        end
    end

    local function copyToClipboard(text)
        if setclipboard then
            setclipboard(text)
        elseif toclipboard then
            toclipboard(text)
        end
    end

    -- Список фонов
    local BackgroundList = {
        {Name = "Кастом Фон 1 (13113352572)", Id = "rbxassetid://13113352572"},
        {Name = "Кастом Фон 2 (12257572143)", Id = "rbxassetid://12257572143"},
        {Name = "Кастом Фон 3 (102148219916335)", Id = "rbxassetid://102148219916335"},
        {Name = "Кастом Фон 4 (11486610383)", Id = "rbxassetid://11486610383"},
        {Name = "Кастом Фон 5 (16696506032)", Id = "rbxassetid://16696506032"},
        {Name = "Кастом Фон 6 (15251265686)", Id = "rbxassetid://15251265686"},
        {Name = "Кастом Фон 7 (18224297158)", Id = "rbxassetid://18224297158"},
        {Name = "Windows Облака (Clouds)", Id = "rbxassetid://282490520"},
        {Name = "Киберпанк (Cyberpunk)", Id = "rbxassetid://6071582231"},
        {Name = "Аниме Девушка (Cyber Girl)", Id = "rbxassetid://6071579407"},
        {Name = "Аниме Ночь (Night City)", Id = "rbxassetid://6071578393"},
        {Name = "Аниме Небо (Skyline)", Id = "rbxassetid://6071574673"},
        {Name = "Неоновый Город (Neon Vibe)", Id = "rbxassetid://6071576921"},
        {Name = "Аниме Закат (Sunset Art)", Id = "rbxassetid://6071580124"},
        {Name = "Ночной Дождь (Rain Night)", Id = "rbxassetid://6071575925"},
        {Name = "Капли на стекле (Window Drops)", Id = "rbxassetid://1417494402"},
        {Name = "Тёмный Дождь (Dark Rain)", Id = "rbxassetid://2155480411"},
        {Name = "Грустное Настроение (Sad Mood)", Id = "rbxassetid://6561088734"},
        {Name = "Одинокая Ночь (Lonely Night)", Id = "rbxassetid://6071581023"},
        {Name = "Мем Гигачад (Gigachad)", Id = "rbxassetid://9115712534"},
        {Name = "Мем Доге (Doge)", Id = "rbxassetid://6031280882"},
        {Name = "Мем Кот (Cat Vibes)", Id = "rbxassetid://9115713214"},
        {Name = "Мем Троллфейс (Trollface)", Id = "rbxassetid://5625470724"},
        {Name = "Мем Спандж Боб (SpongeBob)", Id = "rbxassetid://7074708290"},
        {Name = "Дефолт Сетка (Grid)", Id = "rbxassetid://122219671"},
        {Name = "Галактика (Space Galaxy)", Id = "rbxassetid://6071583342"},
        {Name = "Фиолетовый Закат (Purple Sunset)", Id = "rbxassetid://6071585564"}
    }

    local StartingBg = parseBgId(defaultBg) or BackgroundList[1].Id

    -- ScreenGui
    local ScreenGui = Instance.new("ScreenGui")
    ScreenGui.Name = "NelCustomHub"
    ScreenGui.ResetOnSpawn = false
    ScreenGui.Parent = CoreGui

    -- PULL BAR (Нижняя шторка)
    local BottomBar = Instance.new("Frame")
    BottomBar.Name = "NelPullBar"
    BottomBar.Size = UDim2.new(0, 130, 0, 7)
    BottomBar.Position = UDim2.new(0.5, -65, 1, -18)
    BottomBar.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
    BottomBar.BackgroundTransparency = 0.2
    BottomBar.BorderSizePixel = 0
    BottomBar.Parent = ScreenGui

    local BarCorner = Instance.new("UICorner")
    BarCorner.CornerRadius = UDim.new(1, 0)
    BarCorner.Parent = BottomBar

    -- ГЛАВНОЕ ОКНО
    local OpenPosition = UDim2.new(0.5, -260, 0.5, -170)
    local ClosedPosition = UDim2.new(0.5, -260, 1, 50)

    local MainFrame = Instance.new("Frame")
    MainFrame.Name = "MainFrame"
    MainFrame.Size = UDim2.new(0, 520, 0, 340)
    MainFrame.Position = ClosedPosition
    MainFrame.BackgroundColor3 = Color3.fromRGB(18, 18, 24)
    MainFrame.BorderSizePixel = 0
    MainFrame.ClipsDescendants = true
    MainFrame.Visible = false
    MainFrame.Parent = ScreenGui

    local MainCorner = Instance.new("UICorner")
    MainCorner.CornerRadius = UDim.new(0, 14)
    MainCorner.Parent = MainFrame

    local MainStroke = Instance.new("UIStroke")
    MainStroke.Thickness = 2
    MainStroke.Color = CurrentBorderColor
    MainStroke.Transparency = 0.2
    MainStroke.Parent = MainFrame

    -- Фон
    local BackgroundImage = Instance.new("ImageLabel")
    BackgroundImage.Name = "BackgroundImage"
    BackgroundImage.Size = UDim2.new(1, 0, 1, 0)
    BackgroundImage.Image = StartingBg
    BackgroundImage.ImageTransparency = 0.45
    BackgroundImage.ScaleType = Enum.ScaleType.Crop
    BackgroundImage.BackgroundTransparency = 1
    BackgroundImage.Parent = MainFrame

    -- Шапка
    local Header = Instance.new("Frame")
    Header.Name = "Header"
    Header.Size = UDim2.new(1, 0, 0, 45)
    Header.BackgroundColor3 = Color3.fromRGB(12, 12, 18)
    Header.BackgroundTransparency = 0.25
    Header.BorderSizePixel = 0
    Header.Parent = MainFrame

    local HeaderCorner = Instance.new("UICorner")
    HeaderCorner.CornerRadius = UDim.new(0, 14)
    HeaderCorner.Parent = Header

    local SettingsBtn = Instance.new("ImageButton")
    SettingsBtn.Name = "SettingsButton"
    SettingsBtn.Size = UDim2.new(0, 26, 0, 26)
    SettingsBtn.Position = UDim2.new(0, 12, 0.5, -13)
    SettingsBtn.BackgroundTransparency = 1
    SettingsBtn.Image = "rbxassetid://6031280882"
    SettingsBtn.ImageColor3 = Color3.fromRGB(220, 220, 255)
    SettingsBtn.Parent = Header

    -- ЗАГОЛОВОК
    local Title = Instance.new("TextLabel")
    Title.Name = "Title"
    Title.Size = UDim2.new(1, -95, 1, 0)
    Title.Position = UDim2.new(0, 46, 0, 0)
    Title.Text = WindowTitle
    Title.TextColor3 = Color3.fromRGB(255, 255, 255)
    Title.TextSize = 15
    Title.Font = Enum.Font.GothamBold
    Title.TextXAlignment = Enum.TextXAlignment.Left
    Title.BackgroundTransparency = 1
    Title.Parent = Header

    local CloseBtn = Instance.new("TextButton")
    CloseBtn.Name = "CloseButton"
    CloseBtn.Size = UDim2.new(0, 28, 0, 28)
    CloseBtn.Position = UDim2.new(1, -38, 0.5, -14)
    CloseBtn.BackgroundColor3 = Color3.fromRGB(220, 50, 65)
    CloseBtn.Text = "X"
    CloseBtn.TextColor3 = Color3.fromRGB(255, 255, 255)
    CloseBtn.Font = Enum.Font.GothamBold
    CloseBtn.TextSize = 13
    CloseBtn.Parent = Header

    local CloseCorner = Instance.new("UICorner")
    CloseCorner.CornerRadius = UDim.new(0, 8)
    CloseCorner.Parent = CloseBtn

    -- ЛЕВАЯ ПАНЕЛЬ ДЛЯ ВКЛАДОК
    local Sidebar = Instance.new("Frame")
    Sidebar.Name = "Sidebar"
    Sidebar.Size = UDim2.new(0, 130, 1, -55)
    Sidebar.Position = UDim2.new(0, 10, 0, 50)
    Sidebar.BackgroundColor3 = Color3.fromRGB(12, 12, 18)
    Sidebar.BackgroundTransparency = 0.4
    Sidebar.BorderSizePixel = 0
    Sidebar.Parent = MainFrame

    local SidebarCorner = Instance.new("UICorner")
    SidebarCorner.CornerRadius = UDim.new(0, 10)
    SidebarCorner.Parent = Sidebar

    local TabScroll = Instance.new("ScrollingFrame")
    TabScroll.Name = "TabScroll"
    TabScroll.Size = UDim2.new(1, -8, 1, -12)
    TabScroll.Position = UDim2.new(0, 4, 0, 6)
    TabScroll.BackgroundTransparency = 1
    TabScroll.BorderSizePixel = 0
    TabScroll.ScrollBarThickness = 2
    TabScroll.CanvasSize = UDim2.new(0, 0, 0, 0)
    TabScroll.AutomaticCanvasSize = Enum.AutomaticSize.Y
    TabScroll.Parent = Sidebar

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

    -- ПРАВАЯ ОБЛАСТЬ СТРАНИЦ
    local PageContainer = Instance.new("Frame")
    PageContainer.Name = "PageContainer"
    PageContainer.Size = UDim2.new(1, -156, 1, -55)
    PageContainer.Position = UDim2.new(0, 146, 0, 50)
    PageContainer.BackgroundTransparency = 1
    PageContainer.Parent = MainFrame

    -- ПАНЕЛЬ НАСТРОЕК
    local SettingsFrame = Instance.new("Frame")
    SettingsFrame.Name = "SettingsFrame"
    SettingsFrame.Size = UDim2.new(1, -20, 1, -55)
    SettingsFrame.Position = UDim2.new(1, 0, 0, 50)
    SettingsFrame.BackgroundColor3 = Color3.fromRGB(22, 22, 32)
    SettingsFrame.BackgroundTransparency = 0.05
    SettingsFrame.Visible = false
    SettingsFrame.Parent = MainFrame

    local SettingsCorner = Instance.new("UICorner")
    SettingsCorner.CornerRadius = UDim.new(0, 10)
    SettingsCorner.Parent = SettingsFrame

    local SettingsScroll = Instance.new("ScrollingFrame")
    SettingsScroll.Size = UDim2.new(1, -16, 1, -16)
    SettingsScroll.Position = UDim2.new(0, 8, 0, 8)
    SettingsScroll.BackgroundTransparency = 1
    SettingsScroll.BorderSizePixel = 0
    SettingsScroll.CanvasSize = UDim2.new(0, 0, 0, 0)
    SettingsScroll.AutomaticCanvasSize = Enum.AutomaticSize.Y
    SettingsScroll.ScrollBarThickness = 3
    SettingsScroll.Parent = SettingsFrame

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

    -- Кнопка копирования ссылки
    local CopyLinkBtn = Instance.new("TextButton")
    CopyLinkBtn.Size = UDim2.new(1, -6, 0, 36)
    CopyLinkBtn.BackgroundColor3 = Color3.fromRGB(45, 90, 180)
    CopyLinkBtn.Text = "Copy max link channel"
    CopyLinkBtn.TextColor3 = Color3.fromRGB(255, 255, 255)
    CopyLinkBtn.Font = Enum.Font.GothamBold
    CopyLinkBtn.TextSize = 13
    CopyLinkBtn.Parent = SettingsScroll

    local CopyCorner = Instance.new("UICorner")
    CopyCorner.CornerRadius = UDim.new(0, 8)
    CopyCorner.Parent = CopyLinkBtn

    CopyLinkBtn.MouseButton1Click:Connect(function()
        playSound(soundClick)
        copyToClipboard(MaxChannelLink)
        CopyLinkBtn.Text = "Copied!"
        task.wait(1.5)
        CopyLinkBtn.Text = "Copy max link channel"
    end)

    -- Переключатель языка
    local LangFrame = Instance.new("Frame")
    LangFrame.Size = UDim2.new(1, -6, 0, 40)
    LangFrame.BackgroundColor3 = Color3.fromRGB(32, 32, 46)
    LangFrame.Parent = SettingsScroll

    local LangCorner = Instance.new("UICorner")
    LangCorner.CornerRadius = UDim.new(0, 8)
    LangCorner.Parent = LangFrame

    local LangTitle = Instance.new("TextLabel")
    LangTitle.Size = UDim2.new(0.6, 0, 1, 0)
    LangTitle.Position = UDim2.new(0, 12, 0, 0)
    LangTitle.Text = "Язык / Language:"
    LangTitle.TextColor3 = Color3.fromRGB(255, 255, 255)
    LangTitle.Font = Enum.Font.GothamMedium
    LangTitle.TextSize = 13
    LangTitle.TextXAlignment = Enum.TextXAlignment.Left
    LangTitle.BackgroundTransparency = 1
    LangTitle.Parent = LangFrame

    local LangBtn = Instance.new("TextButton")
    LangBtn.Size = UDim2.new(0, 70, 0, 26)
    LangBtn.Position = UDim2.new(1, -80, 0.5, -13)
    LangBtn.BackgroundColor3 = Color3.fromRGB(55, 55, 85)
    LangBtn.Text = "RU"
    LangBtn.TextColor3 = Color3.fromRGB(255, 255, 255)
    LangBtn.Font = Enum.Font.GothamBold
    LangBtn.TextSize = 12
    LangBtn.Parent = LangFrame

    local LangBtnCorner = Instance.new("UICorner")
    LangBtnCorner.CornerRadius = UDim.new(0, 6)
    LangBtnCorner.Parent = LangBtn

    LangBtn.MouseButton1Click:Connect(function()
        playSound(soundClick)
        if CurrentLanguage == "RU" then
            CurrentLanguage = "EN"
            LangBtn.Text = "EN"
        else
            CurrentLanguage = "RU"
            LangBtn.Text = "RU"
        end
    end)

    -- Ползунок громкости
    local SoundFrame = Instance.new("Frame")
    SoundFrame.Size = UDim2.new(1, -6, 0, 50)
    SoundFrame.BackgroundColor3 = Color3.fromRGB(32, 32, 46)
    SoundFrame.Parent = SettingsScroll

    local SoundCorner = Instance.new("UICorner")
    SoundCorner.CornerRadius = UDim.new(0, 8)
    SoundCorner.Parent = SoundFrame

    local SoundLabel = Instance.new("TextLabel")
    SoundLabel.Size = UDim2.new(1, -20, 0, 20)
    SoundLabel.Position = UDim2.new(0, 12, 0, 5)
    SoundLabel.Text = "Громкость / Volume: 100%"
    SoundLabel.TextColor3 = Color3.fromRGB(255, 255, 255)
    SoundLabel.Font = Enum.Font.GothamMedium
    SoundLabel.TextSize = 13
    SoundLabel.TextXAlignment = Enum.TextXAlignment.Left
    SoundLabel.BackgroundTransparency = 1
    SoundLabel.Parent = SoundFrame

    local SliderBack = Instance.new("Frame")
    SliderBack.Size = UDim2.new(1, -24, 0, 8)
    SliderBack.Position = UDim2.new(0, 12, 0, 32)
    SliderBack.BackgroundColor3 = Color3.fromRGB(18, 18, 28)
    SliderBack.Parent = SoundFrame

    local SliderBackCorner = Instance.new("UICorner")
    SliderBackCorner.CornerRadius = UDim.new(1, 0)
    SliderBackCorner.Parent = SliderBack

    local SliderFill = Instance.new("Frame")
    SliderFill.Size = UDim2.new(1, 0, 1, 0)
    SliderFill.BackgroundColor3 = Color3.fromRGB(90, 150, 255)
    SliderFill.Parent = SliderBack

    local SliderFillCorner = Instance.new("UICorner")
    SliderFillCorner.CornerRadius = UDim.new(1, 0)
    SliderFillCorner.Parent = SliderFill

    local draggingSlider = false
    local function updateVolume(input)
        local pos = math.clamp((input.Position.X - SliderBack.AbsolutePosition.X) / SliderBack.AbsoluteSize.X, 0, 1)
        TweenService:Create(SliderFill, TweenInfo.new(0.05), {Size = UDim2.new(pos, 0, 1, 0)}):Play()
        GlobalVolume = pos
        SoundLabel.Text = "Громкость / Volume: " .. math.floor(pos * 100) .. "%"
    end

    SliderBack.InputBegan:Connect(function(input)
        if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
            draggingSlider = true
            updateVolume(input)
        end
    end)

    UserInputService.InputEnded:Connect(function(input)
        if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
            draggingSlider = false
        end
    end)

    UserInputService.InputChanged:Connect(function(input)
        if draggingSlider and (input.UserInputType == Enum.UserInputType.MouseMovement or input.UserInputType == Enum.UserInputType.Touch) then
            updateVolume(input)
        end
    end)

    -- Выбор цвета обводки
    local BorderHeader = Instance.new("TextLabel")
    BorderHeader.Size = UDim2.new(1, 0, 0, 25)
    BorderHeader.Text = "Цвет обводки / Border Color:"
    BorderHeader.TextColor3 = Color3.fromRGB(200, 200, 255)
    BorderHeader.Font = Enum.Font.GothamBold
    BorderHeader.TextSize = 13
    BorderHeader.TextXAlignment = Enum.TextXAlignment.Left
    BorderHeader.BackgroundTransparency = 1
    BorderHeader.Parent = SettingsScroll

    local BorderColors = {
        {Name = "Синий (Blue)", Color = Color3.fromRGB(60, 60, 120)},
        {Name = "Красный (Red)", Color = Color3.fromRGB(255, 60, 60)},
        {Name = "Зелёный (Green)", Color = Color3.fromRGB(60, 255, 120)},
        {Name = "Фиолетовый (Purple)", Color = Color3.fromRGB(160, 60, 255)},
        {Name = "Голубой (Cyan)", Color = Color3.fromRGB(60, 220, 255)},
        {Name = "Жёлтый (Gold)", Color = Color3.fromRGB(255, 215, 0)},
        {Name = "Розовый (Pink)", Color = Color3.fromRGB(255, 105, 180)},
        {Name = "Белый (White)", Color = Color3.fromRGB(255, 255, 255)}
    }

    for _, colorData in ipairs(BorderColors) do
        local ColorBtn = Instance.new("TextButton")
        ColorBtn.Size = UDim2.new(1, -6, 0, 30)
        ColorBtn.BackgroundColor3 = Color3.fromRGB(32, 32, 46)
        ColorBtn.Text = "   " .. colorData.Name
        ColorBtn.TextColor3 = colorData.Color
        ColorBtn.Font = Enum.Font.GothamMedium
        ColorBtn.TextSize = 12
        ColorBtn.TextXAlignment = Enum.TextXAlignment.Left
        ColorBtn.Parent = SettingsScroll

        local ColorBtnCorner = Instance.new("UICorner")
        ColorBtnCorner.CornerRadius = UDim.new(0, 6)
        ColorBtnCorner.Parent = ColorBtn

        ColorBtn.MouseButton1Click:Connect(function()
            playSound(soundClick)
            CurrentBorderColor = colorData.Color
            TweenService:Create(MainStroke, TweenInfo.new(0.3), {Color = colorData.Color}):Play()
        end)
    end

    -- Выбор фона в настройках
    local BgHeader = Instance.new("TextLabel")
    BgHeader.Size = UDim2.new(1, 0, 0, 25)
    BgHeader.Text = "Выбор фона / Choose Background (" .. #BackgroundList .. "):"
    BgHeader.TextColor3 = Color3.fromRGB(200, 200, 255)
    BgHeader.Font = Enum.Font.GothamBold
    BgHeader.TextSize = 13
    BgHeader.TextXAlignment = Enum.TextXAlignment.Left
    BgHeader.BackgroundTransparency = 1
    BgHeader.Parent = SettingsScroll

    for idx, bgData in ipairs(BackgroundList) do
        local BgBtn = Instance.new("TextButton")
        BgBtn.Size = UDim2.new(1, -6, 0, 32)
        BgBtn.BackgroundColor3 = Color3.fromRGB(32, 32, 46)
        BgBtn.Text = "   " .. idx .. ". " .. bgData.Name
        BgBtn.TextColor3 = Color3.fromRGB(220, 220, 240)
        BgBtn.Font = Enum.Font.GothamMedium
        BgBtn.TextSize = 12
        BgBtn.TextXAlignment = Enum.TextXAlignment.Left
        BgBtn.Parent = SettingsScroll

        local BgBtnCorner = Instance.new("UICorner")
        BgBtnCorner.CornerRadius = UDim.new(0, 6)
        BgBtnCorner.Parent = BgBtn

        BgBtn.MouseButton1Click:Connect(function()
            playSound(soundClick)
            BackgroundImage.Image = bgData.Id
        end)
    end

    -- Анимация Настроек
    local isSettingsOpen = false
    SettingsBtn.MouseButton1Click:Connect(function()
        playSound(soundClick)
        isSettingsOpen = not isSettingsOpen
        if isSettingsOpen then
            SettingsFrame.Visible = true
            SettingsFrame.Position = UDim2.new(1, 0, 0, 50)
            TweenService:Create(SettingsFrame, TweenInfo.new(0.3, Enum.EasingStyle.Quart, Enum.EasingDirection.Out), {Position = UDim2.new(0, 10, 0, 50)}):Play()
        else
            local tween = TweenService:Create(SettingsFrame, TweenInfo.new(0.3, Enum.EasingStyle.Quart, Enum.EasingDirection.In), {Position = UDim2.new(1, 0, 0, 50)})
            tween:Play()
            tween.Completed:Connect(function()
                if not isSettingsOpen then SettingsFrame.Visible = false end
            end)
        end
    end)

    -- АНИМАЦИИ И ЛОГИКА OТКРЫТИЯ/ЗАКРЫТИЯ ГЛАВНОГО МЕНЮ
    local isMenuOpen = false

    local function toggleMenu(open)
        if open == isMenuOpen then return end
        isMenuOpen = open

        local tweenInfo = TweenInfo.new(0.4, Enum.EasingStyle.Quart, Enum.EasingDirection.Out)

        if isMenuOpen then
            playSound(soundOpen)
            MainFrame.Visible = true
            MainFrame.Position = ClosedPosition
            
            TweenService:Create(MainFrame, tweenInfo, {Position = OpenPosition}):Play()
            TweenService:Create(Blur, tweenInfo, {Size = 18}):Play()
            TweenService:Create(BottomBar, tweenInfo, {BackgroundTransparency = 0.7, Size = UDim2.new(0, 90, 0, 5)}):Play()
        else
            playSound(soundClose)
            
            local mainTween = TweenService:Create(MainFrame, tweenInfo, {Position = ClosedPosition})
            TweenService:Create(Blur, tweenInfo, {Size = 0}):Play()
            TweenService:Create(BottomBar, tweenInfo, {BackgroundTransparency = 0.2, Size = UDim2.new(0, 130, 0, 7)}):Play()
            
            mainTween:Play()
            mainTween.Completed:Connect(function()
                if not isMenuOpen then
                    MainFrame.Visible = false
                end
            end)
        end
    end

    local pullStartPosY = 0
    local isPulling = false

    BottomBar.InputBegan:Connect(function(input)
        if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
            isPulling = true
            pullStartPosY = input.Position.Y
        end
    end)

    UserInputService.InputEnded:Connect(function(input)
        if (input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch) and isPulling then
            isPulling = false
            local deltaY = pullStartPosY - input.Position.Y
            if deltaY > 15 or not isMenuOpen then
                toggleMenu(true)
            end
        end
    end)

    CloseBtn.MouseButton1Click:Connect(function()
        toggleMenu(false)
    end)

    -- Перетаскивание шапки
    local dragging, dragInput, dragStart, startPos

    local function startHoldEffects()
        playSound(soundDrag)
        TweenService:Create(MainStroke, TweenInfo.new(0.2), {
            Color = Color3.fromRGB(255, 255, 255),
            Thickness = 3.5,
            Transparency = 0
        }):Play()

        local shrinkTween = TweenService:Create(MainFrame, TweenInfo.new(0.12, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {
            Size = UDim2.new(0, 504, 0, 328)
        })
        shrinkTween:Play()
        shrinkTween.Completed:Connect(function()
            TweenService:Create(MainFrame, TweenInfo.new(0.15, Enum.EasingStyle.Back, Enum.EasingDirection.Out), {
                Size = UDim2.new(0, 520, 0, 340)
            }):Play()
        end)
    end

    local function stopHoldEffects()
        TweenService:Create(MainStroke, TweenInfo.new(0.3), {
            Color = CurrentBorderColor,
            Thickness = 2,
            Transparency = 0.2
        }):Play()
    end

    Header.InputBegan:Connect(function(input)
        if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
            dragging = true
            dragStart = input.Position
            startPos = MainFrame.Position
            startHoldEffects()

            input.Changed:Connect(function()
                if input.UserInputState == Enum.UserInputState.End then
                    dragging = false
                    stopHoldEffects()
                end
            end)
        end
    end)

    Header.InputChanged:Connect(function(input)
        if input.UserInputType == Enum.UserInputType.MouseMovement or input.UserInputType == Enum.UserInputType.Touch then
            dragInput = input
        end
    end)

    UserInputService.InputChanged:Connect(function(input)
        if input == dragInput and dragging then
            local delta = input.Position - dragStart
            MainFrame.Position = UDim2.new(startPos.X.Scale, startPos.X.Offset + delta.X, startPos.Y.Scale, startPos.Y.Offset + delta.Y)
        end
    end)

    -- ===================================================
    -- ОФОРМЛЕНИЕ ОКНА КЛЮЧА (KEY SYSTEM WINDOW)
    -- ===================================================
    if KeySystemEnabled and CorrectKey ~= "" then
        playSound(soundOpen)
        TweenService:Create(Blur, TweenInfo.new(0.4), {Size = 18}):Play()

        local KeyFrame = Instance.new("Frame")
        KeyFrame.Name = "KeyFrame"
        KeyFrame.Size = UDim2.new(0, 340, 0, 195)
        KeyFrame.Position = UDim2.new(0.5, -170, 0.5, -97)
        KeyFrame.BackgroundColor3 = Color3.fromRGB(18, 18, 24)
        KeyFrame.BorderSizePixel = 0
        KeyFrame.ClipsDescendants = true
        KeyFrame.Parent = ScreenGui

        local KeyCorner = Instance.new("UICorner")
        KeyCorner.CornerRadius = UDim.new(0, 14)
        KeyCorner.Parent = KeyFrame

        local KeyStroke = Instance.new("UIStroke")
        KeyStroke.Thickness = 2
        KeyStroke.Color = CurrentBorderColor
        KeyStroke.Transparency = 0.2
        KeyStroke.Parent = KeyFrame

        -- Шапка окна ключа
        local KeyHeader = Instance.new("Frame")
        KeyHeader.Name = "KeyHeader"
        KeyHeader.Size = UDim2.new(1, 0, 0, 42)
        KeyHeader.BackgroundColor3 = Color3.fromRGB(12, 12, 18)
        KeyHeader.BackgroundTransparency = 0.25
        KeyHeader.BorderSizePixel = 0
        KeyHeader.Parent = KeyFrame

        local KeyHeaderCorner = Instance.new("UICorner")
        KeyHeaderCorner.CornerRadius = UDim.new(0, 14)
        KeyHeaderCorner.Parent = KeyHeader

        local KeyTitle = Instance.new("TextLabel")
        KeyTitle.Size = UDim2.new(1, -50, 1, 0)
        KeyTitle.Position = UDim2.new(0, 14, 0, 0)
        KeyTitle.Text = "KEY SYSTEM | ВВЕДИТЕ КЛЮЧ"
        KeyTitle.TextColor3 = Color3.fromRGB(255, 255, 255)
        KeyTitle.Font = Enum.Font.GothamBold
        KeyTitle.TextSize = 13
        KeyTitle.TextXAlignment = Enum.TextXAlignment.Left
        KeyTitle.BackgroundTransparency = 1
        KeyTitle.Parent = KeyHeader

        local KeyCloseBtn = Instance.new("TextButton")
        KeyCloseBtn.Size = UDim2.new(0, 26, 0, 26)
        KeyCloseBtn.Position = UDim2.new(1, -34, 0.5, -13)
        KeyCloseBtn.BackgroundColor3 = Color3.fromRGB(220, 50, 65)
        KeyCloseBtn.Text = "X"
        KeyCloseBtn.TextColor3 = Color3.fromRGB(255, 255, 255)
        KeyCloseBtn.Font = Enum.Font.GothamBold
        KeyCloseBtn.TextSize = 12
        KeyCloseBtn.Parent = KeyHeader

        local KeyCloseCorner = Instance.new("UICorner")
        KeyCloseCorner.CornerRadius = UDim.new(0, 6)
        KeyCloseCorner.Parent = KeyCloseBtn

        -- Текстовое поле для ввода
        local KeyTextBox = Instance.new("TextBox")
        KeyTextBox.Size = UDim2.new(1, -28, 0, 38)
        KeyTextBox.Position = UDim2.new(0, 14, 0, 54)
        KeyTextBox.BackgroundColor3 = Color3.fromRGB(28, 28, 38)
        KeyTextBox.PlaceholderText = "Введите ваш ключ..."
        KeyTextBox.PlaceholderColor3 = Color3.fromRGB(130, 130, 160)
        KeyTextBox.Text = ""
        KeyTextBox.TextColor3 = Color3.fromRGB(255, 255, 255)
        KeyTextBox.Font = Enum.Font.GothamMedium
        KeyTextBox.TextSize = 13
        KeyTextBox.ClearTextOnFocus = false
        KeyTextBox.Parent = KeyFrame

        local BoxCorner = Instance.new("UICorner")
        BoxCorner.CornerRadius = UDim.new(0, 8)
        BoxCorner.Parent = KeyTextBox

        local BoxStroke = Instance.new("UIStroke")
        BoxStroke.Thickness = 1
        BoxStroke.Color = Color3.fromRGB(50, 50, 80)
        BoxStroke.Parent = KeyTextBox

        -- Статус
        local StatusLabel = Instance.new("TextLabel")
        StatusLabel.Size = UDim2.new(1, -28, 0, 18)
        StatusLabel.Position = UDim2.new(0, 14, 0, 98)
        StatusLabel.Text = ""
        StatusLabel.TextColor3 = Color3.fromRGB(255, 80, 80)
        StatusLabel.Font = Enum.Font.GothamMedium
        StatusLabel.TextSize = 11
        StatusLabel.BackgroundTransparency = 1
        StatusLabel.Parent = KeyFrame

        -- Кнопка отправки ключа
        local SubmitBtn = Instance.new("TextButton")
        SubmitBtn.Size = UDim2.new(1, -28, 0, 36)
        SubmitBtn.Position = UDim2.new(0, 14, 0, 142)
        SubmitBtn.BackgroundColor3 = Color3.fromRGB(50, 90, 200)
        SubmitBtn.Text = "Проверить ключ / Verify"
        SubmitBtn.TextColor3 = Color3.fromRGB(255, 255, 255)
        SubmitBtn.Font = Enum.Font.GothamBold
        SubmitBtn.TextSize = 13
        SubmitBtn.Parent = KeyFrame

        local SubmitCorner = Instance.new("UICorner")
        SubmitCorner.CornerRadius = UDim.new(0, 8)
        SubmitCorner.Parent = SubmitBtn

        -- Закрытие окна ключа
        KeyCloseBtn.MouseButton1Click:Connect(function()
            playSound(soundClose)
            TweenService:Create(Blur, TweenInfo.new(0.3), {Size = 0}):Play()
            KeyFrame:Destroy()
        end)

        -- Логика проверки ключа
        local function verifyKey()
            playSound(soundClick)
            if KeyTextBox.Text == CorrectKey then
                StatusLabel.TextColor3 = Color3.fromRGB(80, 255, 120)
                StatusLabel.Text = "Ключ верный! Открытие..."
                task.wait(0.5)
                KeyFrame:Destroy()
                toggleMenu(true)
            else
                StatusLabel.TextColor3 = Color3.fromRGB(255, 80, 80)
                StatusLabel.Text = "Неверный ключ! Попробуйте снова."
                TweenService:Create(BoxStroke, TweenInfo.new(0.2), {Color = Color3.fromRGB(255, 60, 60)}):Play()
                task.wait(1)
                TweenService:Create(BoxStroke, TweenInfo.new(0.2), {Color = Color3.fromRGB(50, 50, 80)}):Play()
            end
        end

        SubmitBtn.MouseButton1Click:Connect(verifyKey)
        KeyTextBox.FocusLost:Connect(function(enterPressed)
            if enterPressed then
                verifyKey()
            end
        end)
    else
        -- Если KeySystem выключена или ключ не задан — запускаем меню сразу
        toggleMenu(true)
    end

    -- ОБЪЕКТ ОКНА С ВКЛАДКАМИ
    local Window = {}
    local Tabs = {}

    function Window:AddTab(tabName)
        local Tab = {}
        
        local TabBtn = Instance.new("TextButton")
        TabBtn.Name = tabName .. "TabButton"
        TabBtn.Size = UDim2.new(1, -4, 0, 34)
        TabBtn.BackgroundColor3 = Color3.fromRGB(24, 24, 36)
        TabBtn.BackgroundTransparency = 0.3
        TabBtn.Text = tabName
        TabBtn.TextColor3 = Color3.fromRGB(170, 170, 200)
        TabBtn.Font = Enum.Font.GothamMedium
        TabBtn.TextSize = 12
        TabBtn.Parent = TabScroll

        local TabBtnCorner = Instance.new("UICorner")
        TabBtnCorner.CornerRadius = UDim.new(0, 8)
        TabBtnCorner.Parent = TabBtn

        local Page = Instance.new("ScrollingFrame")
        Page.Name = tabName .. "Page"
        Page.Size = UDim2.new(1, 0, 1, 0)
        Page.BackgroundTransparency = 1
        Page.BorderSizePixel = 0
        Page.CanvasSize = UDim2.new(0, 0, 0, 0)
        Page.AutomaticCanvasSize = Enum.AutomaticSize.Y
        Page.ScrollBarThickness = 3
        Page.ScrollBarImageColor3 = Color3.fromRGB(120, 120, 170)
        Page.Visible = false
        Page.Parent = PageContainer

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

        local function selectTab()
            for _, tabData in ipairs(Tabs) do
                tabData.Page.Visible = false
                TweenService:Create(tabData.Button, TweenInfo.new(0.2), {
                    BackgroundColor3 = Color3.fromRGB(24, 24, 36),
                    BackgroundTransparency = 0.3,
                    TextColor3 = Color3.fromRGB(170, 170, 200)
                }):Play()
            end
            Page.Visible = true
            TweenService:Create(TabBtn, TweenInfo.new(0.2), {
                BackgroundColor3 = Color3.fromRGB(55, 55, 90),
                BackgroundTransparency = 0,
                TextColor3 = Color3.fromRGB(255, 255, 255)
            }):Play()
        end

        TabBtn.MouseButton1Click:Connect(function()
            playSound(soundClick)
            selectTab()
        end)

        if #Tabs == 0 then
            selectTab()
        end

        table.insert(Tabs, {Button = TabBtn, Page = Page})

        function Tab:AddButton(buttonName, callback)
            local Btn = Instance.new("TextButton")
            Btn.Size = UDim2.new(1, -6, 0, 36)
            Btn.BackgroundColor3 = Color3.fromRGB(32, 32, 48)
            Btn.BackgroundTransparency = 0.2
            Btn.Text = "   " .. buttonName
            Btn.TextColor3 = Color3.fromRGB(240, 240, 255)
            Btn.Font = Enum.Font.GothamMedium
            Btn.TextSize = 13
            Btn.TextXAlignment = Enum.TextXAlignment.Left
            Btn.Parent = Page

            local BtnCorner = Instance.new("UICorner")
            BtnCorner.CornerRadius = UDim.new(0, 8)
            BtnCorner.Parent = Btn

            Btn.MouseButton1Click:Connect(function()
                playSound(soundClick)
                TweenService:Create(Btn, TweenInfo.new(0.1), {Size = UDim2.new(1, -12, 0, 34)}):Play()
                task.wait(0.1)
                TweenService:Create(Btn, TweenInfo.new(0.1), {Size = UDim2.new(1, -6, 0, 36)}):Play()
                pcall(callback)
            end)
        end

        function Tab:AddToggle(toggleName, defaultState, callback)
            local state = defaultState or false

            local ToggleFrame = Instance.new("Frame")
            ToggleFrame.Size = UDim2.new(1, -6, 0, 36)
            ToggleFrame.BackgroundColor3 = Color3.fromRGB(32, 32, 48)
            ToggleFrame.BackgroundTransparency = 0.2
            ToggleFrame.Parent = Page

            local ToggleCorner = Instance.new("UICorner")
            ToggleCorner.CornerRadius = UDim.new(0, 8)
            ToggleCorner.Parent = ToggleFrame

            local Label = Instance.new("TextLabel")
            Label.Size = UDim2.new(1, -60, 1, 0)
            Label.Position = UDim2.new(0, 12, 0, 0)
            Label.Text = toggleName
            Label.TextColor3 = Color3.fromRGB(240, 240, 255)
            Label.Font = Enum.Font.GothamMedium
            Label.TextSize = 13
            Label.TextXAlignment = Enum.TextXAlignment.Left
            Label.BackgroundTransparency = 1
            Label.Parent = ToggleFrame

            local Switch = Instance.new("TextButton")
            Switch.Size = UDim2.new(0, 42, 0, 22)
            Switch.Position = UDim2.new(1, -50, 0.5, -11)
            Switch.BackgroundColor3 = state and Color3.fromRGB(60, 200, 110) or Color3.fromRGB(75, 75, 95)
            Switch.Text = state and "ON" or "OFF"
            Switch.TextColor3 = Color3.fromRGB(255, 255, 255)
            Switch.Font = Enum.Font.GothamBold
            Switch.TextSize = 11
            Switch.Parent = ToggleFrame

            local SwitchCorner = Instance.new("UICorner")
            SwitchCorner.CornerRadius = UDim.new(0, 6)
            SwitchCorner.Parent = Switch

            Switch.MouseButton1Click:Connect(function()
                state = not state
                playSound(soundClick)
                TweenService:Create(Switch, TweenInfo.new(0.2), {BackgroundColor3 = state and Color3.fromRGB(60, 200, 110) or Color3.fromRGB(75, 75, 95)}):Play()
                Switch.Text = state and "ON" or "OFF"
                pcall(callback, state)
            end)
        end

        function Tab:AddDropdown(dropdownName, optionsTable, callback)
            local DropdownFrame = Instance.new("Frame")
            DropdownFrame.Size = UDim2.new(1, -6, 0, 36)
            DropdownFrame.BackgroundColor3 = Color3.fromRGB(32, 32, 48)
            DropdownFrame.BackgroundTransparency = 0.2
            DropdownFrame.ClipsDescendants = true
            DropdownFrame.Parent = Page

            local DropCorner = Instance.new("UICorner")
            DropCorner.CornerRadius = UDim.new(0, 8)
            DropCorner.Parent = DropdownFrame

            local DropBtn = Instance.new("TextButton")
            DropBtn.Size = UDim2.new(1, 0, 0, 36)
            DropBtn.BackgroundTransparency = 1
            DropBtn.Text = "   " .. dropdownName .. "  [Выбрать]"
            DropBtn.TextColor3 = Color3.fromRGB(240, 240, 255)
            DropBtn.Font = Enum.Font.GothamMedium
            DropBtn.TextSize = 13
            DropBtn.TextXAlignment = Enum.TextXAlignment.Left
            DropBtn.Parent = DropdownFrame

            local isExpanded = false
            DropBtn.MouseButton1Click:Connect(function()
                playSound(soundClick)
                isExpanded = not isExpanded
                local targetSize = isExpanded and UDim2.new(1, -6, 0, 36 + (#optionsTable * 32)) or UDim2.new(1, -6, 0, 36)
                TweenService:Create(DropdownFrame, TweenInfo.new(0.25, Enum.EasingStyle.Quart, Enum.EasingDirection.Out), {Size = targetSize}):Play()
            end)

            for i, option in ipairs(optionsTable) do
                local OptBtn = Instance.new("TextButton")
                OptBtn.Size = UDim2.new(1, -16, 0, 28)
                OptBtn.Position = UDim2.new(0, 8, 0, 36 + (i - 1) * 32)
                OptBtn.BackgroundColor3 = Color3.fromRGB(42, 42, 62)
                OptBtn.Text = tostring(option)
                OptBtn.TextColor3 = Color3.fromRGB(220, 220, 255)
                OptBtn.Font = Enum.Font.Gotham
                OptBtn.TextSize = 12
                OptBtn.Parent = DropdownFrame

                local OptCorner = Instance.new("UICorner")
                OptCorner.CornerRadius = UDim.new(0, 6)
                OptCorner.Parent = OptBtn

                OptBtn.MouseButton1Click:Connect(function()
                    playSound(soundClick)
                    DropBtn.Text = "   " .. dropdownName .. ": " .. tostring(option)
                    isExpanded = false
                    TweenService:Create(DropdownFrame, TweenInfo.new(0.2, Enum.EasingStyle.Quart, Enum.EasingDirection.Out), {Size = UDim2.new(1, -6, 0, 36)}):Play()
                    pcall(callback, option)
                end)
            end
        end

        return Tab
    end

    return Window
end

return NelHub