surface.CreateFont("ASCII_Font", {
    font = "Courier New",  
    size = 18,
    weight = 500,
    antialias = true
})

local function CreateVGUI()
    -- Valeurs de base définies par l'utilisateur
    local baseMenuWidth, baseMenuHeight = 750, 350
    local baseAsciiWidth, baseAsciiHeight = 600, 150
    local baseSpacing = 10
    local screenCenterX = ScrW() / 2
    local screenCenterY = ScrH() / 2

    -- Calcul du facteur de mise à l'échelle basé sur la résolution de l'écran
    local scaleX = ScrW() / 1920  -- Considère 1920x1080 comme résolution de base
    local scaleY = ScrH() / 1080  -- Considère 1920x1080 comme résolution de base

    -- Application de l'échelle
    local menuWidth = baseMenuWidth * scaleX
    local menuHeight = baseMenuHeight * scaleY
    local asciiWidth = baseAsciiWidth * scaleX
    local asciiHeight = baseAsciiHeight * scaleY
    local spacing = baseSpacing * scaleY

    -- Première DFrame (ASCII en haut)
    local asciiFrame = vgui.Create("DFrame")
    asciiFrame:SetSize(asciiWidth, asciiHeight)
    asciiFrame:SetPos(screenCenterX - (asciiWidth / 2), screenCenterY - (menuHeight / 2) - asciiHeight - spacing)
    asciiFrame:SetTitle("")
    asciiFrame:SetDraggable(false)
    asciiFrame:ShowCloseButton(false)
    asciiFrame:MakePopup()

    asciiFrame.Paint = function(self, w, h)
        draw.RoundedBox(0, 0, 0, w, h, Color(0, 0, 0))  
        draw.RoundedBox(0, 1.5, 1.5, w - 3, h - 3, Color(0, 255, 0))  
        draw.RoundedBox(0, 3.4, 3.4, w - 6.8, h - 6.8, Color(0, 0, 0))  
        draw.RoundedBox(0, 5, 5, w - 10, h - 10, Color(30, 30, 30))  
    end

    local asciiText = [[
  _____  _____  ______  _   __ _____ 
 |  __ \|  __ \|  ____|| | / /|  __ \
 | |__) | |__) | |__   | |/ / | |  | |
 |  _  /|  ___/|  __|  |    \ | |  | |
 | | \ \| |    | |____ | |\  \| |__| |
 |_|  \_\_|    |______||_| \_/|_____/ 
    ]]

    local asciiLabel = vgui.Create("DLabel", asciiFrame)
    asciiLabel:SetFont("ASCII_Font")
    asciiLabel:SetText(asciiText)
    asciiLabel:SetTextColor(Color(0, 255, 0))
    asciiLabel:SetContentAlignment(5)
    asciiLabel:SetSize(asciiWidth - 40, asciiHeight - 40)
    asciiLabel:SetPos(20, 40)

    -- Deuxième DFrame (Boutons en haut)
    local buttonFrame = vgui.Create("DFrame")
    buttonFrame:SetSize(ScrW(), ScrH() * 0.05)  -- Hauteur des boutons fixée à 5% de la hauteur de l'écran
    buttonFrame:SetPos(0, 0)
    buttonFrame:SetTitle("")
    buttonFrame:ShowCloseButton(false)
    buttonFrame:SetDraggable(false)
    buttonFrame.Paint = function(self, w, h)
        draw.RoundedBox(0, 0, 0, w, h, Color(30, 30, 30, 255))  
    end

    local menuFrame = vgui.Create("DFrame")
    menuFrame:SetSize(menuWidth + 100, menuHeight + 100)
    menuFrame:SetPos(screenCenterX - (menuWidth / 1.8), screenCenterY - (menuHeight / 2))
    menuFrame:SetTitle("")
    menuFrame:SetDraggable(false)
    menuFrame:ShowCloseButton(false)
    menuFrame:MakePopup()
    menuFrame.Paint = function(self, w, h)
        draw.RoundedBox(0, 0, 0, w, h, Color(0, 0, 0))  
        local gradient = Material("vgui/gradient-u")
        surface.SetDrawColor(148, 0, 211, 255) -- Violet
        surface.SetMaterial(gradient)
        surface.DrawTexturedRect(1.5, 1.5, w - 3, h - 3)
        surface.SetDrawColor(70, 130, 180, 255) -- Bleu clair
        surface.SetMaterial(gradient)
        surface.DrawTexturedRect(1.5, (2 * h) / 3, w - 3, h / 3)
        draw.RoundedBox(0, 3.4, 3.4, w - 6.8, h - 6.8, Color(0, 0, 0))  
        draw.RoundedBox(0, 5, 5, w - 10, h - 10, Color(20, 20, 20))  
    end

    local dsheet = vgui.Create("DPropertySheet", menuFrame)
    dsheet:SetSize(menuWidth + 80, menuHeight + 80 )
    dsheet:SetPos(10, 10)
    dsheet.Paint = function(self, w, h)
        draw.RoundedBox(0, 0, 0, w, h, Color(0, 0, 0))  
        local gradient = Material("vgui/gradient-u")
        surface.SetDrawColor(56, 55, 55) -- Violet
        surface.SetMaterial(gradient)
        surface.DrawTexturedRect(1.5, 1.5, w - 3, h - 3)
        surface.SetDrawColor(56, 55, 55) -- Bleu clair
        surface.SetMaterial(gradient)
        surface.DrawTexturedRect(1.5, (2 * h) / 3, w - 3, h / 3)
        draw.RoundedBox(0, 3.4, 3.4, w - 6.8, h - 6.8, Color(0, 0, 0))  
        draw.RoundedBox(0, 5, 5, w - 10, h - 10, Color(20, 20, 20))  
    end

    local tabs = {}
    local buttons = {"Visuals", "Aiming", "Misc", "Skins", "Config"}
    local buttonWidth = ScrW() / #buttons 
    local activeButton = "Aiming"

    -- Création des onglets
    for _, name in ipairs(buttons) do
        local panel = vgui.Create("DPanel", dsheet)
        panel:SetSize(menuWidth + 85, menuHeight + 80) -- Taille des panneaux ajustée
        panel:SetPaintBackground(false)

        panel.OnSizeChanged = function(self, w, h)
            self:SetSize(w, h) -- S'assurer que les panneaux se redimensionnent correctement
        end

        panel.Paint = function(self, w, h)
            draw.RoundedBox(5, 0, 0, w, h, Color(50, 50, 50))
            surface.SetDrawColor(0, 0, 0, 255)
            surface.DrawOutlinedRect(0, 0, w, h, 2)
        end

        tabs[name] = dsheet:AddSheet(name, panel).Tab
    end

    -- Création des boutons
    for i, name in ipairs(buttons) do
        local btn = vgui.Create("DButton", buttonFrame)
        btn:SetSize(buttonWidth, ScrH() * 0.05)  -- Hauteur des boutons fixée à 5% de la hauteur de l'écran
        btn:SetPos((i - 1) * buttonWidth, 0)
        btn:SetText(name)
        btn:SetFont("Trebuchet24")
        
        btn.Paint = function(self, w, h)
            local isActive = (name == activeButton)
            draw.RoundedBox(0, 0, 0, w, h, Color(40, 40, 40))
            surface.SetDrawColor(255, 255, 255, 255)
            surface.DrawOutlinedRect(0, 0, w, h, 2)
            draw.SimpleText(name, "Trebuchet24", w / 2, h / 2, isActive and Color(0, 255, 0) or Color(255, 255, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
        end
        
        btn.DoClick = function()
            activeButton = name
            dsheet:SetActiveTab(tabs[name])
        end
    end

    for _, sheet in ipairs(dsheet:GetItems()) do
        sheet.Tab:SetVisible(false)
    end
    dsheet:SetActiveTab(tabs["Aiming"])
end

concommand.Add("open_vgui", CreateVGUI)
