local API = rawget(_G, "LIDCOUNCIL_API")
local INTERNAL_API = type(API) == "table" and type(API.__internal) == "table" and API.__internal or nil
if type(INTERNAL_API) ~= "table" then
  error("LidCouncil missing internal API registry.")
end

local function CreateAboutUtilitySections(editor, aboutContent, deps)
  deps = deps or {}
  local MakeAboutTitle = deps.MakeAboutTitle
  local MakeYellowSubHeader = deps.MakeYellowSubHeader
  local RootDB = deps.RootDB
  local GetRuntimeDiagnostics = type(deps.GetRuntimeDiagnostics) == "function" and deps.GetRuntimeDiagnostics or nil
  local Print = type(deps.Print) == "function" and deps.Print or rawget(_G, "LIDCOUNCIL_Print")
  local CreateLootProfileApi = type(deps.CreateLootProfile) == "function" and deps.CreateLootProfile or rawget(_G, "LIDCOUNCIL_CreateLootProfile")
  local DeleteLootProfileApi = type(deps.DeleteLootProfile) == "function" and deps.DeleteLootProfile or rawget(_G, "LIDCOUNCIL_DeleteLootProfile")
  local GetLootProfileAccessInfoApi = type(deps.GetLootProfileAccessInfo) == "function" and deps.GetLootProfileAccessInfo or rawget(_G, "LIDCOUNCIL_GetLootProfileAccessInfo")
  local RepairSimulationProfileOwnershipApi = type(deps.RepairSimulationProfileOwnership) == "function" and deps.RepairSimulationProfileOwnership or rawget(_G, "LIDCOUNCIL_RepairSimulationProfileOwnership")
  local SetLootProfileEnabledApi = type(deps.SetLootProfileEnabled) == "function" and deps.SetLootProfileEnabled or rawget(_G, "LIDCOUNCIL_SetLootProfileEnabled")
  local GetActiveLootSession = type(deps.GetActiveLootSession) == "function" and deps.GetActiveLootSession or rawget(_G, "LIDCOUNCIL_GetActiveLootSession")
  local SafeHookScript = deps.SafeHookScript or function(frame, scriptName, handler)
    if frame and type(frame.HookScript) == "function" and type(handler) == "function" then
      pcall(frame.HookScript, frame, scriptName, handler)
    end
  end
  local GetTitleColor = type(deps.GetTitleColor) == "function" and deps.GetTitleColor or function()
    return 0.6588, 0.4784, 0.9098, 1.0
  end
  local function ApplyTitleColor(fontString)
    if not fontString then
      return
    end
    local r, g, b, a = GetTitleColor()
    fontString:SetTextColor(r, g, b, a)
  end

  local function GetSimulationProfileState(root)
    root = root or RootDB()
    local repaired = false
    local masterKey = ""
    if type(RepairSimulationProfileOwnershipApi) == "function" then
      local didRepair, resolvedMaster = RepairSimulationProfileOwnershipApi(root)
      repaired = didRepair == true
      masterKey = tostring(resolvedMaster or "")
    end

    local profile = type(root.profiles) == "table" and root.profiles.Simulation or nil
    if type(profile) ~= "table" then
      return {
        exists = false,
        repaired = repaired,
        masterKey = "",
        access = nil,
        canDelete = false,
      }
    end

    local access = type(GetLootProfileAccessInfoApi) == "function" and GetLootProfileAccessInfoApi("Simulation") or nil
    if type(access) == "table" and tostring(access.masterKey or "") ~= "" then
      masterKey = tostring(access.masterKey)
    elseif masterKey == "" and type(profile.meta) == "table" and type(profile.meta.permissions) == "table" then
      masterKey = tostring(profile.meta.permissions.master or "")
    end

    return {
      exists = true,
      repaired = repaired,
      masterKey = masterKey,
      access = access,
      canDelete = type(access) == "table" and access.canDeleteProfile == true or false,
    }
  end

  local function HasSimulationProfile(root)
    return GetSimulationProfileState(root).exists
  end

  local function HasActiveSimulationSession()
    if type(GetActiveLootSession) ~= "function" then
      return false
    end
    local activeSession, activeProfileName = GetActiveLootSession()
    return activeSession ~= nil and tostring(activeProfileName or "") == "Simulation"
  end

  local function ResolveNonSimulationFallbackProfile(root)
    root = root or RootDB()
    root.ui = type(root.ui) == "table" and root.ui or {}

    local preferredName = tostring(root.ui.lastNonSimulationProfile or "")
    if preferredName ~= "" and preferredName ~= "Simulation" and type(root.profiles) == "table" and type(root.profiles[preferredName]) == "table" then
      return preferredName
    end
    if type(root.profiles) == "table" and type(root.profiles.Default) == "table" then
      return "Default"
    end

    local candidates = {}
    for profileName in pairs(root.profiles or {}) do
      local resolvedName = tostring(profileName or "")
      if resolvedName ~= "" and resolvedName ~= "Simulation" then
        candidates[#candidates + 1] = resolvedName
      end
    end
    table.sort(candidates, function(a, b)
      return string.lower(tostring(a or "")) < string.lower(tostring(b or ""))
    end)
    return candidates[1]
  end

  local function MoveAwayFromSimulationSelection()
    local root = RootDB()
    root.ui = type(root.ui) == "table" and root.ui or {}

    local fallbackProfile = ResolveNonSimulationFallbackProfile(root)
    if fallbackProfile and fallbackProfile ~= "Simulation" and type(root.profiles) == "table" then
      local simulationProfile = root.profiles.Simulation
      if type(simulationProfile) == "table" and type(simulationProfile.settings) == "table" and simulationProfile.settings.enabled == true and type(SetLootProfileEnabledApi) == "function" then
        SetLootProfileEnabledApi(fallbackProfile, true)
      end
    end
    if tostring(root.currentProfile or "") == "Simulation" and fallbackProfile and type(root.profiles) == "table" and type(root.profiles[fallbackProfile]) == "table" then
      root.currentProfile = fallbackProfile
    end

    local fallbackSelection = fallbackProfile ~= "Simulation" and fallbackProfile or nil
    if editor then
      if editor.selectedProfileName == "Simulation" then
        editor.selectedProfileName = fallbackSelection
      end
      if editor.selectedLootProfileName == "Simulation" then
        editor.selectedLootProfileName = fallbackSelection
      end
    end
  end

  local aboutCreditsFrame = CreateFrame("Frame", nil, aboutContent)
  aboutCreditsFrame:SetAllPoints(aboutContent)
  aboutCreditsFrame:Hide()
  editor.aboutCreditsFrame = aboutCreditsFrame

  local creditsTitle = MakeAboutTitle(aboutCreditsFrame, "Credits", 0, 0)
  editor.aboutCreditsTitle = creditsTitle

  local function CreateCreditsSection(parent, titleText, bodyText)
    local header = parent:CreateFontString(nil, "OVERLAY", "GameFontNormal")
    header:SetJustifyH("LEFT")
    header:SetText(titleText)
    ApplyTitleColor(header)

    local body = parent:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
    body:SetJustifyH("LEFT")
    body:SetText(bodyText)
    if body.SetSpacing then body:SetSpacing(3) end

    local divider = parent:CreateTexture(nil, "ARTWORK")
    divider:SetColorTexture(1, 1, 1, 0.14)
    divider:SetHeight(1)

    return {
      header = header,
      body = body,
      divider = divider,
    }
  end

  local creditsSections = {
    CreateCreditsSection(
      aboutCreditsFrame,
      "Disclaimer",
      "This addon is an independent fan project and is not affiliated with or endorsed by Blizzard Entertainment, Inc.\n" ..
      "World of Warcraft and all related artwork are trademarks or registered trademarks of Blizzard Entertainment."
    ),
    CreateCreditsSection(
      aboutCreditsFrame,
      "Acknowledgements",
      "Special thanks to the creator of LargerMacroIconSelection - their icon list was incredibly helpful while building the icon selection features.\n\n" ..
      "Although LidCouncil does not use any code from RCLootCouncil, it has been a long-standing loot distribution tool and surely provided many ideas and workflow inspiration for LidCouncil."
    ),
    CreateCreditsSection(
      aboutCreditsFrame,
      "Testing & Feedback",
      "Special thanks to the following people for their time, feedback, and testing support:\n\n" ..
      "- Rikku\n" ..
      "- wuuusaa\n" ..
      "- Chepter\n" ..
      "- Elfeba"
    ),
    CreateCreditsSection(
      aboutCreditsFrame,
      "Development Tools",
      "This addon was developed with assistance from AI tools, including ChatGPT and Codex, which supported code generation, problem solving, and technical exploration."
    ),
    CreateCreditsSection(
      aboutCreditsFrame,
      "Graphics & Visuals",
      "Certain UI graphics and visual assets were created with the assistance of ChatGPT."
    ),
    CreateCreditsSection(
      aboutCreditsFrame,
      "Additional Support",
      "Thanks to everyone who shared suggestions, bug reports, and ideas during development <3"
    ),
  }
  editor.aboutCreditsSections = creditsSections

  local function UpdateAboutCreditsLayout()
    if not aboutContent or not creditsSections then return end
    if editor and editor.aboutSection and editor.aboutSection ~= "Credits" then return end
    local w = (aboutContent:GetWidth() or 0) - 24
    if w < 220 then w = 220 end
    if w > 620 then w = 620 end

    local y = -26
    for index, section in ipairs(creditsSections) do
      section.header:ClearAllPoints()
      section.header:SetPoint("TOPLEFT", creditsTitle, "TOPLEFT", 0, y)
      section.header:SetWidth(w)
      local hf, _, hflags = section.header:GetFont()
      if hf then section.header:SetFont(hf, 15, hflags) end
      ApplyTitleColor(section.header)

      local headerHeight = (section.header.GetStringHeight and section.header:GetStringHeight()) or 22
      y = y - headerHeight - 10

      section.body:ClearAllPoints()
      section.body:SetPoint("TOPLEFT", creditsTitle, "TOPLEFT", 0, y)
      section.body:SetWidth(w)
      local bf, _, bflags = section.body:GetFont()
      if bf then section.body:SetFont(bf, 13, bflags) end
      local bodyHeight = (section.body.GetStringHeight and section.body:GetStringHeight()) or 70
      y = y - bodyHeight

      if section.divider then
        if index < #creditsSections then
          section.divider:Show()
          section.divider:ClearAllPoints()
          section.divider:SetPoint("TOPLEFT", creditsTitle, "TOPLEFT", 0, y - 14)
          section.divider:SetWidth(w)
          y = y - 28
        else
          section.divider:Hide()
        end
      end
    end

    local h = math.max(520, math.floor((-y) + 120))
    if editor and editor.SetAboutContentHeight then
      editor:SetAboutContentHeight(h)
    end
  end
  editor.UpdateAboutCreditsLayout = UpdateAboutCreditsLayout
  SafeHookScript(aboutCreditsFrame, "OnShow", UpdateAboutCreditsLayout)
  SafeHookScript(aboutContent, "OnSizeChanged", UpdateAboutCreditsLayout)

  local aboutStressFrame = CreateFrame("Frame", nil, aboutContent)
  aboutStressFrame:SetAllPoints(aboutContent)
  aboutStressFrame:Hide()
  editor.aboutStressFrame = aboutStressFrame

  local stressTitle = MakeAboutTitle(aboutStressFrame, "Stresstest", 0, 0)
  editor.aboutStressTitle = stressTitle

  local stressContainer = CreateFrame("Frame", nil, aboutStressFrame)
  stressContainer:SetPoint("TOPLEFT", stressTitle, "BOTTOMLEFT", 0, -8)
  stressContainer:SetPoint("TOPRIGHT", aboutStressFrame, "TOPRIGHT", -10, -8)
  stressContainer:SetHeight(10)
  editor.aboutStressContainer = stressContainer

  local STRESS_ENTRIES = {
    {
      version = "Version 0.9.2 [ALPHA]",
      sections = {
        { title = "CPU", bullets = {
            "Base AddOn: ~0.0%",
        } },
        { title = "FPS", bullets = {
            "tbv",
        } },
        { title = "tbv", bullets = {
            "tbv",
        } },
        { title = "tbv", bullets = {
            "tbv",
        } },
        { title = "tbv", bullets = {
            "tbv",
        } },
        { title = "General Notes", bullets = {
            "tbv",
        } },
      },
    },
  }

  local stressLines = {}
  local stressDividers = {}

  local function GetStressLine(index)
    local fs = stressLines[index]
    if not fs then
      fs = stressContainer:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
      fs:SetJustifyH("LEFT")
      stressLines[index] = fs
    end
    return fs
  end

  local function GetStressDivider(index)
    local tx = stressDividers[index]
    if not tx then
      tx = stressContainer:CreateTexture(nil, "ARTWORK")
      tx:SetColorTexture(1, 1, 1, 0.14)
      tx:SetHeight(1)
      stressDividers[index] = tx
    end
    return tx
  end

  local function HideUnusedStress(fromLine, fromDivider)
    for i = fromLine, #stressLines do stressLines[i]:Hide() end
    for i = fromDivider, #stressDividers do stressDividers[i]:Hide() end
  end

  local function UpdateStressText()
    local width = (aboutContent:GetWidth() or 560) - 14
    if width < 220 then width = 220 end
    local lineIndex, dividerIndex, y = 1, 1, 0

    for _, entry in ipairs(STRESS_ENTRIES) do
      local divider = GetStressDivider(dividerIndex); dividerIndex = dividerIndex + 1
      divider:ClearAllPoints()
      divider:SetPoint("TOPLEFT", stressContainer, "TOPLEFT", 0, y)
      divider:SetWidth(width)
      divider:Show()
      y = y - 12

      local versionLine = GetStressLine(lineIndex); lineIndex = lineIndex + 1
      versionLine:ClearAllPoints()
      versionLine:SetPoint("TOPLEFT", stressContainer, "TOPLEFT", 0, y)
      versionLine:SetWidth(width)
      versionLine:SetText(entry.version or "")
      local vf, _, vflags = versionLine:GetFont()
      versionLine:SetFont(vf, 16, vflags)
      ApplyTitleColor(versionLine)
      versionLine:Show()
      y = y - ((versionLine:GetStringHeight() or 0) + 8)

      for _, note in ipairs(entry.notes or {}) do
        local noteLine = GetStressLine(lineIndex); lineIndex = lineIndex + 1
        noteLine:ClearAllPoints()
        noteLine:SetPoint("TOPLEFT", stressContainer, "TOPLEFT", 0, y)
        noteLine:SetWidth(width)
        noteLine:SetText(note)
        local nf, _, nflags = noteLine:GetFont()
        noteLine:SetFont(nf, 13, nflags)
        noteLine:SetTextColor(0.9, 0.9, 0.9, 1)
        noteLine:Show()
        y = y - ((noteLine:GetStringHeight() or 0) + 6)
      end

      for _, section in ipairs(entry.sections or {}) do
        local sectionLine = GetStressLine(lineIndex); lineIndex = lineIndex + 1
        sectionLine:ClearAllPoints()
        sectionLine:SetPoint("TOPLEFT", stressContainer, "TOPLEFT", 0, y)
        sectionLine:SetWidth(width)
        sectionLine:SetText(section.title or "")
        local sf, _, sflags = sectionLine:GetFont()
        sectionLine:SetFont(sf, 14, sflags)
        ApplyTitleColor(sectionLine)
        sectionLine:Show()
        y = y - ((sectionLine:GetStringHeight() or 0) + 4)

        for _, bulletText in ipairs(section.bullets or {}) do
          local bulletLine = GetStressLine(lineIndex); lineIndex = lineIndex + 1
          bulletLine:ClearAllPoints()
          bulletLine:SetPoint("TOPLEFT", stressContainer, "TOPLEFT", 8, y)
          bulletLine:SetWidth(width - 8)
          bulletLine:SetText(string.char(226, 128, 162) .. " " .. tostring(bulletText))
          local bf, _, bflags = bulletLine:GetFont()
          bulletLine:SetFont(bf, 13, bflags)
          bulletLine:SetTextColor(0.9, 0.9, 0.9, 1)
          bulletLine:Show()
          y = y - ((bulletLine:GetStringHeight() or 0) + 2)
        end
        y = y - 6
      end
      y = y - 8
    end

    HideUnusedStress(lineIndex, dividerIndex)
    stressContainer:SetHeight(math.max(40, -y + 6))
  end

  local function UpdateAboutStressLayout()
    if not aboutContent or not stressContainer then return end
    if editor and editor.aboutSection and editor.aboutSection ~= "Stresstest" then return end
    UpdateStressText()
    local h = stressContainer:GetHeight() or 400
    if editor and editor.SetAboutContentHeight then
      editor:SetAboutContentHeight(math.max(520, math.floor(h + 140)))
    end
  end
  editor.UpdateAboutStressLayout = UpdateAboutStressLayout
  SafeHookScript(aboutStressFrame, "OnShow", UpdateAboutStressLayout)
  SafeHookScript(aboutContent, "OnSizeChanged", UpdateAboutStressLayout)

  local aboutTutorialImagesFrame = CreateFrame("Frame", nil, aboutContent)
  aboutTutorialImagesFrame:SetAllPoints(aboutContent)
  aboutTutorialImagesFrame:Hide()
  editor.aboutTutorialImagesFrame = aboutTutorialImagesFrame

  local aboutTutorialImagesTitle = MakeAboutTitle(aboutTutorialImagesFrame, "Disable Tutorial Images", 0, 0)
  editor.aboutTutorialImagesTitle = aboutTutorialImagesTitle

  local aboutTutorialImagesText = aboutTutorialImagesFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  aboutTutorialImagesText:SetPoint("TOPLEFT", aboutTutorialImagesTitle, "BOTTOMLEFT", 0, -8)
  aboutTutorialImagesText:SetWidth(560)
  aboutTutorialImagesText:SetJustifyH("LEFT")
  aboutTutorialImagesText:SetText(
    "Use this option if you want to save disk space by deleting tutorial images.\n\n" ..
    "Folder: Interface\\AddOns\\LidCouncil\\Media\\LidCouncil\\Tutorials\n\n" ..
    "If that folder or files are missing, WoW may show green placeholder boxes.\n" ..
    "Set mode to Disabled to stop loading tutorial images and keep cards transparent."
  )
  editor.aboutTutorialImagesText = aboutTutorialImagesText

  local aboutTutorialImagesModeHeader = MakeYellowSubHeader(aboutTutorialImagesFrame, "Mode", 0, -164)
  editor.aboutTutorialImagesModeHeader = aboutTutorialImagesModeHeader

  local aboutTutorialImagesToggleBtn = CreateFrame("Button", nil, aboutTutorialImagesFrame, "UIPanelButtonTemplate")
  aboutTutorialImagesToggleBtn:SetSize(110, 20)
  aboutTutorialImagesToggleBtn:SetPoint("TOPLEFT", aboutTutorialImagesModeHeader, "BOTTOMLEFT", 0, -8)
  editor.aboutTutorialImagesToggleBtn = aboutTutorialImagesToggleBtn

  local aboutTutorialImagesState = aboutTutorialImagesFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  aboutTutorialImagesState:SetPoint("TOPLEFT", aboutTutorialImagesToggleBtn, "BOTTOMLEFT", 0, -8)
  aboutTutorialImagesState:SetWidth(560)
  aboutTutorialImagesState:SetJustifyH("LEFT")
  editor.aboutTutorialImagesState = aboutTutorialImagesState

  local function RefreshTutorialImagesSection()
    local root = RootDB()
    root.ui = root.ui or {}
    local disabled = root.ui.disableTutorialImages == true
    if aboutTutorialImagesToggleBtn then
      aboutTutorialImagesToggleBtn:SetText(disabled and "Disabled" or "Enabled")
    end
    if aboutTutorialImagesState then
      if disabled then
        aboutTutorialImagesState:SetText("Tutorial images are not loaded")
        aboutTutorialImagesState:SetTextColor(1.0, 0.78, 0.78, 1.0)
      else
        aboutTutorialImagesState:SetText("Tutorial images are currently shown")
        aboutTutorialImagesState:SetTextColor(0.82, 0.92, 0.82, 1.0)
      end
    end
  end
  editor.RefreshTutorialImagesSection = RefreshTutorialImagesSection

  aboutTutorialImagesToggleBtn:SetScript("OnClick", function()
    local root = RootDB()
    root.ui = root.ui or {}
    root.ui.disableTutorialImages = not (root.ui.disableTutorialImages == true)
    RefreshTutorialImagesSection()
    if editor and editor.ApplyTutorialTextureMode then editor:ApplyTutorialTextureMode() end
    if editor and editor.LayoutTutorial then editor:LayoutTutorial() end
    if editor and editor.LayoutNoPanel then editor:LayoutNoPanel() end
    if editor and editor.LayoutProfileWelcome then editor:LayoutProfileWelcome() end
  end)

  local function UpdateAboutTutorialImagesLayout()
    if not aboutContent or not aboutTutorialImagesText then return end
    if editor and editor.aboutSection and editor.aboutSection ~= "TutorialImages" then return end
    local w = (aboutContent:GetWidth() or 0) - 10
    if w < 200 then w = 200 end
    aboutTutorialImagesText:SetWidth(w)
    if aboutTutorialImagesState then
      aboutTutorialImagesState:SetWidth(math.max(220, w - 40))
    end
    local t1 = (aboutTutorialImagesText.GetStringHeight and aboutTutorialImagesText:GetStringHeight()) or 120
    local t2 = (aboutTutorialImagesState and aboutTutorialImagesState.GetStringHeight and aboutTutorialImagesState:GetStringHeight()) or 20
    if editor and editor.SetAboutContentHeight then
      editor:SetAboutContentHeight(math.max(520, math.floor(t1 + t2 + 230)))
    end
  end
  editor.UpdateAboutTutorialImagesLayout = UpdateAboutTutorialImagesLayout
  SafeHookScript(aboutTutorialImagesFrame, "OnShow", function()
    if editor and editor.RefreshTutorialImagesSection then editor:RefreshTutorialImagesSection() end
    UpdateAboutTutorialImagesLayout()
  end)
  SafeHookScript(aboutContent, "OnSizeChanged", UpdateAboutTutorialImagesLayout)

  local aboutDeveloperFrame = CreateFrame("Frame", nil, aboutContent)
  aboutDeveloperFrame:SetAllPoints(aboutContent)
  aboutDeveloperFrame:Hide()
  editor.aboutDeveloperFrame = aboutDeveloperFrame

  local DEV_SECTION_TITLE_R, DEV_SECTION_TITLE_G, DEV_SECTION_TITLE_B, DEV_SECTION_TITLE_A = 0.643, 0.804, 0.345, 1.0
  local DEV_EXPERIMENTAL_TITLE_R, DEV_EXPERIMENTAL_TITLE_G, DEV_EXPERIMENTAL_TITLE_B, DEV_EXPERIMENTAL_TITLE_A = 1.00, 0.50, 0.50, 1.0

  local function ApplyDeveloperSectionTitle(fontString, isExperimental)
    if not fontString then
      return
    end
    if isExperimental then
      fontString:SetTextColor(DEV_EXPERIMENTAL_TITLE_R, DEV_EXPERIMENTAL_TITLE_G, DEV_EXPERIMENTAL_TITLE_B, DEV_EXPERIMENTAL_TITLE_A)
    else
      fontString:SetTextColor(DEV_SECTION_TITLE_R, DEV_SECTION_TITLE_G, DEV_SECTION_TITLE_B, DEV_SECTION_TITLE_A)
    end
  end

  local function SetElementShown(element, shown)
    if not element then
      return
    end
    if element.SetShown then
      element:SetShown(shown)
    elseif shown and element.Show then
      element:Show()
    elseif not shown and element.Hide then
      element:Hide()
    end
  end

  local function ParseDeveloperNumber(value)
    local text = tostring(value or "")
    text = text:gsub(",", ".")
    return tonumber(text)
  end

  local function ResolveApiFunction(name)
    local api = rawget(_G, "LIDCOUNCIL_API")
    if type(api) == "table" and type(api[name]) == "function" then
      return api[name]
    end
    local globalValue = rawget(_G, name)
    if type(globalValue) == "function" then
      return globalValue
    end
    return nil
  end

  local function GetProfileSyncTuning()
    local getter = ResolveApiFunction("LIDCOUNCIL_GetProfileSyncTuning")
    if type(getter) == "function" then
      local ok, tuning = pcall(getter)
      if ok and type(tuning) == "table" then
        return tuning
      end
    end
    local root = RootDB()
    root.ui = root.ui or {}
    return {
      developerMode = root.ui.developerMode == true,
      chunkSize = tonumber(root.ui.profileSyncChunkSize) or 120,
      intervalSeconds = tonumber(root.ui.profileSyncDelaySeconds) or 0.12,
      defaultChunkSize = 120,
      minChunkSize = 80,
      maxChunkSize = 190,
      defaultIntervalSeconds = 0.12,
      minIntervalSeconds = 0.08,
      maxIntervalSeconds = 0.25,
      safePayloadLimit = 240,
    }
  end

  local function SetProfileSyncTuning(chunkSize, intervalSeconds)
    local setter = ResolveApiFunction("LIDCOUNCIL_SetProfileSyncTuning")
    if type(setter) == "function" then
      local ok, tuning = pcall(setter, chunkSize, intervalSeconds)
      if ok and type(tuning) == "table" then
        return tuning
      end
    end
    local root = RootDB()
    root.ui = root.ui or {}
    root.ui.profileSyncChunkSize = tonumber(chunkSize) or 120
    root.ui.profileSyncDelaySeconds = tonumber(intervalSeconds) or 0.12
    return GetProfileSyncTuning()
  end

  local function ResetProfileSyncTuning()
    local resetter = ResolveApiFunction("LIDCOUNCIL_ResetProfileSyncTuning")
    if type(resetter) == "function" then
      local ok, tuning = pcall(resetter)
      if ok and type(tuning) == "table" then
        return tuning
      end
    end
    return SetProfileSyncTuning(120, 0.12)
  end

  local function CreateDeveloperEditBox(name, parent, width)
    local editBox = CreateFrame("EditBox", name, parent, "InputBoxTemplate")
    editBox:SetSize(width or 72, 22)
    editBox:SetAutoFocus(false)
    editBox:SetJustifyH("CENTER")
    editBox:SetMaxLetters(8)
    return editBox
  end

  local aboutDeveloperTitle = MakeAboutTitle(aboutDeveloperFrame, "Developer Mode", 0, 0)
  editor.aboutDeveloperTitle = aboutDeveloperTitle

  local aboutDeveloperText = aboutDeveloperFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  aboutDeveloperText:SetPoint("TOPLEFT", aboutDeveloperTitle, "BOTTOMLEFT", 0, -8)
  aboutDeveloperText:SetWidth(560)
  aboutDeveloperText:SetJustifyH("LEFT")
  aboutDeveloperText:SetText(
    "Developer Mode exposes internal testing helpers for LidCouncil.\n\n" ..
    "Activate it only when you need profile IDs, tutorial overlays, the Simulation profile, or runtime diagnostics while testing."
  )
  editor.aboutDeveloperText = aboutDeveloperText

  local aboutDeveloperModeCheck = CreateFrame("CheckButton", "LIDCOUNCIL_AboutDeveloperModeCheck", aboutDeveloperFrame, "UICheckButtonTemplate")
  aboutDeveloperModeCheck:SetPoint("TOPLEFT", aboutDeveloperText, "BOTTOMLEFT", 0, -10)
  _G[aboutDeveloperModeCheck:GetName() .. "Text"]:SetText("Activate Developer Mode")
  editor.aboutDeveloperModeCheck = aboutDeveloperModeCheck

  local aboutDeveloperModeDesc = aboutDeveloperFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  aboutDeveloperModeDesc:SetPoint("TOPLEFT", aboutDeveloperModeCheck, "BOTTOMLEFT", 24, -2)
  aboutDeveloperModeDesc:SetWidth(536)
  aboutDeveloperModeDesc:SetJustifyH("LEFT")
  aboutDeveloperModeDesc:SetTextColor(0.80, 0.80, 0.80, 1.00)
  aboutDeveloperModeDesc:SetText("Master switch. Turning this off disables every developer helper below.")
  editor.aboutDeveloperModeDesc = aboutDeveloperModeDesc

  local aboutDeveloperOptionsDivider = aboutDeveloperFrame:CreateTexture(nil, "ARTWORK")
  aboutDeveloperOptionsDivider:SetTexture("Interface/Buttons/WHITE8x8")
  aboutDeveloperOptionsDivider:SetVertexColor(0.25, 0.25, 0.30, 0.85)
  aboutDeveloperOptionsDivider:SetHeight(1)
  aboutDeveloperOptionsDivider:SetPoint("TOPLEFT", aboutDeveloperModeDesc, "BOTTOMLEFT", -24, -14)
  aboutDeveloperOptionsDivider:SetPoint("RIGHT", aboutDeveloperFrame, "RIGHT", -10, 0)
  editor.aboutDeveloperOptionsDivider = aboutDeveloperOptionsDivider

  local aboutDeveloperOptionsHeader = aboutDeveloperFrame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  aboutDeveloperOptionsHeader:SetPoint("TOPLEFT", aboutDeveloperOptionsDivider, "BOTTOMLEFT", 0, -12)
  aboutDeveloperOptionsHeader:SetText("Developer Options")
  ApplyDeveloperSectionTitle(aboutDeveloperOptionsHeader, false)
  editor.aboutDeveloperOptionsHeader = aboutDeveloperOptionsHeader

  local aboutDeveloperOptionsDesc = aboutDeveloperFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  aboutDeveloperOptionsDesc:SetPoint("TOPLEFT", aboutDeveloperOptionsHeader, "BOTTOMLEFT", 0, -6)
  aboutDeveloperOptionsDesc:SetWidth(560)
  aboutDeveloperOptionsDesc:SetJustifyH("LEFT")
  aboutDeveloperOptionsDesc:SetText("Enable only the helpers you need while testing.")
  editor.aboutDeveloperOptionsDesc = aboutDeveloperOptionsDesc

  local aboutShowProfileIdCheck = CreateFrame("CheckButton", "LIDCOUNCIL_AboutShowProfileIdCheck", aboutDeveloperFrame, "UICheckButtonTemplate")
  aboutShowProfileIdCheck:SetPoint("TOPLEFT", aboutDeveloperOptionsDesc, "BOTTOMLEFT", 0, -10)
  _G[aboutShowProfileIdCheck:GetName() .. "Text"]:SetText("Show internal Profile ID")
  editor.aboutShowProfileIdCheck = aboutShowProfileIdCheck

  local profileIdInfo = CreateFrame("Frame", nil, aboutDeveloperFrame)
  profileIdInfo:SetSize(18, 18)
  profileIdInfo:SetPoint("LEFT", _G[aboutShowProfileIdCheck:GetName() .. "Text"], "RIGHT", 8, 0)
  profileIdInfo:EnableMouse(true)
  local profileIdInfoText = profileIdInfo:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
  profileIdInfoText:SetPoint("CENTER", 0, 0)
  profileIdInfoText:SetText("(i)")
  profileIdInfo:SetScript("OnEnter", function(self)
    if not GameTooltip then return end
    GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
    GameTooltip:SetText("Show internal Profile ID", 1, 0.82, 0.28, 1, true)
    GameTooltip:AddLine("Activating this will show the Internal Profile ID on the Profile Page. The Internal ID is unique and allows profiles with the exact same name to not get into conflict with each other.", 0.92, 0.92, 0.96, true)
    GameTooltip:Show()
  end)
  profileIdInfo:SetScript("OnLeave", function()
    if GameTooltip then GameTooltip:Hide() end
  end)
  editor.aboutShowProfileIdInfo = profileIdInfo

  local aboutShowProfileSizeCheck = CreateFrame("CheckButton", "LIDCOUNCIL_AboutShowProfileSizeCheck", aboutDeveloperFrame, "UICheckButtonTemplate")
  aboutShowProfileSizeCheck:SetPoint("TOPLEFT", aboutShowProfileIdCheck, "BOTTOMLEFT", 0, -6)
  _G[aboutShowProfileSizeCheck:GetName() .. "Text"]:SetText("Show Profile Size")
  editor.aboutShowProfileSizeCheck = aboutShowProfileSizeCheck

  local profileSizeInfo = CreateFrame("Frame", nil, aboutDeveloperFrame)
  profileSizeInfo:SetSize(18, 18)
  profileSizeInfo:SetPoint("LEFT", _G[aboutShowProfileSizeCheck:GetName() .. "Text"], "RIGHT", 8, 0)
  profileSizeInfo:EnableMouse(true)
  local profileSizeInfoText = profileSizeInfo:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
  profileSizeInfoText:SetPoint("CENTER", 0, 0)
  profileSizeInfoText:SetText("(i)")
  profileSizeInfo:SetScript("OnEnter", function(self)
    if not GameTooltip then return end
    GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
    GameTooltip:SetText("Show Profile Size", 1, 0.82, 0.28, 1, true)
    GameTooltip:AddLine("Shows the serialized profile snapshot size in Profile Settings. This is the payload used for full profile sync.", 0.92, 0.92, 0.96, true)
    GameTooltip:AddLine("The estimate uses the current LidCouncil chunk size and queue delay. Real raid conditions can still add overhead.", 0.72, 0.82, 0.95, true)
    GameTooltip:Show()
  end)
  profileSizeInfo:SetScript("OnLeave", function()
    if GameTooltip then GameTooltip:Hide() end
  end)
  editor.aboutShowProfileSizeInfo = profileSizeInfo

  local aboutTutorialModeCheck = CreateFrame("CheckButton", "LIDCOUNCIL_AboutTutorialModeCheck", aboutDeveloperFrame, "UICheckButtonTemplate")
  aboutTutorialModeCheck:SetPoint("TOPLEFT", aboutShowProfileSizeCheck, "BOTTOMLEFT", 0, -6)
  _G[aboutTutorialModeCheck:GetName() .. "Text"]:SetText("Tutorial Mode")
  editor.aboutTutorialModeCheck = aboutTutorialModeCheck

  local aboutShowSimulationCheck = CreateFrame("CheckButton", "LIDCOUNCIL_AboutShowSimulationCheck", aboutDeveloperFrame, "UICheckButtonTemplate")
  aboutShowSimulationCheck:SetPoint("TOPLEFT", aboutTutorialModeCheck, "BOTTOMLEFT", 0, -6)
  _G[aboutShowSimulationCheck:GetName() .. "Text"]:SetText("Show Simulation Profile")
  editor.aboutShowSimulationCheck = aboutShowSimulationCheck

  local aboutCreateSimulationBtn = CreateFrame("Button", nil, aboutDeveloperFrame, "UIPanelButtonTemplate")
  aboutCreateSimulationBtn:SetSize(180, 22)
  aboutCreateSimulationBtn:SetPoint("TOPLEFT", aboutShowSimulationCheck, "BOTTOMLEFT", 4, -10)
  aboutCreateSimulationBtn:SetText("Create Simulation Profile")
  editor.aboutCreateSimulationBtn = aboutCreateSimulationBtn

  local aboutDeleteSimulationBtn = CreateFrame("Button", nil, aboutDeveloperFrame, "UIPanelButtonTemplate")
  aboutDeleteSimulationBtn:SetSize(180, 22)
  aboutDeleteSimulationBtn:SetPoint("LEFT", aboutCreateSimulationBtn, "RIGHT", 10, 0)
  aboutDeleteSimulationBtn:SetText("Delete Simulation Profile")
  editor.aboutDeleteSimulationBtn = aboutDeleteSimulationBtn

  local aboutRuntimeDivider = aboutDeveloperFrame:CreateTexture(nil, "ARTWORK")
  aboutRuntimeDivider:SetTexture("Interface/Buttons/WHITE8x8")
  aboutRuntimeDivider:SetVertexColor(0.25, 0.25, 0.30, 0.85)
  aboutRuntimeDivider:SetHeight(1)
  aboutRuntimeDivider:SetPoint("TOPLEFT", aboutCreateSimulationBtn, "BOTTOMLEFT", -4, -18)
  aboutRuntimeDivider:SetPoint("RIGHT", aboutDeveloperFrame, "RIGHT", -10, 0)
  editor.aboutRuntimeDivider = aboutRuntimeDivider

  local aboutRuntimeHeader = aboutDeveloperFrame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  aboutRuntimeHeader:SetPoint("TOPLEFT", aboutRuntimeDivider, "BOTTOMLEFT", 0, -12)
  aboutRuntimeHeader:SetText("Runtime Health")
  ApplyDeveloperSectionTitle(aboutRuntimeHeader, false)
  editor.aboutRuntimeHeader = aboutRuntimeHeader

  local aboutRuntimeDesc = aboutDeveloperFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  aboutRuntimeDesc:SetPoint("TOPLEFT", aboutRuntimeHeader, "BOTTOMLEFT", 0, -6)
  aboutRuntimeDesc:SetWidth(560)
  aboutRuntimeDesc:SetJustifyH("LEFT")
  aboutRuntimeDesc:SetText("Current Simulation visibility, developer flags, and live runtime state.")
  editor.aboutRuntimeDesc = aboutRuntimeDesc

  local aboutSimulationState = aboutDeveloperFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  aboutSimulationState:SetPoint("TOPLEFT", aboutRuntimeDesc, "BOTTOMLEFT", 0, -8)
  aboutSimulationState:SetWidth(560)
  aboutSimulationState:SetJustifyH("LEFT")
  editor.aboutSimulationState = aboutSimulationState

  local aboutDeveloperState = aboutDeveloperFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  aboutDeveloperState:SetPoint("TOPLEFT", aboutSimulationState, "BOTTOMLEFT", 0, -8)
  aboutDeveloperState:SetWidth(560)
  aboutDeveloperState:SetJustifyH("LEFT")
  editor.aboutDeveloperState = aboutDeveloperState

  local aboutDeveloperHealthHeader = MakeYellowSubHeader(aboutDeveloperFrame, "Detailed Diagnostics", 0, -152)
  aboutDeveloperHealthHeader:SetPoint("TOPLEFT", aboutDeveloperState, "BOTTOMLEFT", 0, -16)
  editor.aboutDeveloperHealthHeader = aboutDeveloperHealthHeader

  local aboutDeveloperHealth = aboutDeveloperFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  aboutDeveloperHealth:SetPoint("TOPLEFT", aboutDeveloperHealthHeader, "BOTTOMLEFT", 0, -8)
  aboutDeveloperHealth:SetWidth(560)
  aboutDeveloperHealth:SetJustifyH("LEFT")
  editor.aboutDeveloperHealth = aboutDeveloperHealth

  local aboutDeveloperExperimentalDivider = aboutDeveloperFrame:CreateTexture(nil, "ARTWORK")
  aboutDeveloperExperimentalDivider:SetTexture("Interface/Buttons/WHITE8x8")
  aboutDeveloperExperimentalDivider:SetVertexColor(0.25, 0.25, 0.30, 0.85)
  aboutDeveloperExperimentalDivider:SetHeight(1)
  aboutDeveloperExperimentalDivider:SetPoint("TOPLEFT", aboutDeveloperHealth, "BOTTOMLEFT", 0, -18)
  aboutDeveloperExperimentalDivider:SetPoint("RIGHT", aboutDeveloperFrame, "RIGHT", -10, 0)
  editor.aboutDeveloperExperimentalDivider = aboutDeveloperExperimentalDivider

  local aboutDeveloperExperimentalHeader = aboutDeveloperFrame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  aboutDeveloperExperimentalHeader:SetPoint("TOPLEFT", aboutDeveloperExperimentalDivider, "BOTTOMLEFT", 0, -12)
  aboutDeveloperExperimentalHeader:SetText("New Feature in Development")
  ApplyDeveloperSectionTitle(aboutDeveloperExperimentalHeader, true)
  editor.aboutDeveloperExperimentalHeader = aboutDeveloperExperimentalHeader

  local aboutDeveloperExperimentalInfo = CreateFrame("Frame", nil, aboutDeveloperFrame)
  aboutDeveloperExperimentalInfo:SetSize(18, 18)
  aboutDeveloperExperimentalInfo:SetPoint("LEFT", aboutDeveloperExperimentalHeader, "RIGHT", 8, 0)
  aboutDeveloperExperimentalInfo:EnableMouse(true)
  local aboutDeveloperExperimentalInfoText = aboutDeveloperExperimentalInfo:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
  aboutDeveloperExperimentalInfoText:SetPoint("CENTER", 0, 0)
  aboutDeveloperExperimentalInfoText:SetText("(i)")
  aboutDeveloperExperimentalInfo:SetScript("OnEnter", function(self)
    if not GameTooltip then return end
    local tuning = GetProfileSyncTuning()
    GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
    GameTooltip:SetText("Experimental Profile Sync Tuning", 1, 0.50, 0.50, 1, true)
    GameTooltip:AddLine("Default: 120 byte chunks and 0.12 second queue delay.", 0.92, 0.92, 0.96, true)
    GameTooltip:AddLine("First safe test: 160 byte chunks with the default 0.12 second delay.", 0.92, 0.92, 0.96, true)
    GameTooltip:AddLine("Still plausible for testing: up to 180 byte chunks, and 0.10-0.12 second delay.", 0.92, 0.92, 0.96, true)
    GameTooltip:AddLine("Most likely to break: very large chunks, or delays below 0.08 seconds. That can create oversized addon messages or Blizzard spam protection disconnects.", 1.00, 0.62, 0.52, true)
    GameTooltip:AddLine("Throttle handling: if WoW reports AddonMessageThrottle, LidCouncil keeps the message in the queue and retries it after at least 1 second. The message is not counted as sent until WoW accepts it.", 0.92, 0.92, 0.96, true)
    GameTooltip:AddLine("Testing signal: if the throttle counter in Sync Management rises, your current chunk size or queue delay is too aggressive for sustained syncing. Lower chunk size, increase delay, or both.", 1.00, 0.82, 0.42, true)
    GameTooltip:AddLine("Important: local send success only means WoW accepted the message for sending. Final profile sync still depends on the receiver applying the snapshot and sending its ACK.", 0.72, 0.82, 0.95, true)
    GameTooltip:AddLine(string.format("Recommended range: %d-%d bytes, %.2f-%.2f seconds. Developer overrides are no longer clamped; current effective values: %d bytes / %.2fs.", tonumber(tuning.minChunkSize) or 80, tonumber(tuning.maxChunkSize) or 190, tonumber(tuning.minIntervalSeconds) or 0.08, tonumber(tuning.maxIntervalSeconds) or 0.25, tonumber(tuning.chunkSize) or 120, tonumber(tuning.intervalSeconds) or 0.12), 0.72, 0.82, 0.95, true)
    GameTooltip:AddLine("These settings are only honored while Developer Mode is enabled.", 0.72, 0.82, 0.95, true)
    GameTooltip:Show()
  end)
  aboutDeveloperExperimentalInfo:SetScript("OnLeave", function()
    if GameTooltip then GameTooltip:Hide() end
  end)
  editor.aboutDeveloperExperimentalInfo = aboutDeveloperExperimentalInfo

  local aboutDeveloperExperimentalDesc = aboutDeveloperFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  aboutDeveloperExperimentalDesc:SetPoint("TOPLEFT", aboutDeveloperExperimentalHeader, "BOTTOMLEFT", 0, -6)
  aboutDeveloperExperimentalDesc:SetWidth(560)
  aboutDeveloperExperimentalDesc:SetJustifyH("LEFT")
  aboutDeveloperExperimentalDesc:SetText("Experimental profile sync tuning for raid tests. LidCouncil tracks send speed and throttle events in Sync Management; throttled messages are requeued and retried instead of being dropped.")
  editor.aboutDeveloperExperimentalDesc = aboutDeveloperExperimentalDesc

  local aboutSyncChunkLabel = aboutDeveloperFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  aboutSyncChunkLabel:SetPoint("TOPLEFT", aboutDeveloperExperimentalDesc, "BOTTOMLEFT", 0, -12)
  aboutSyncChunkLabel:SetText("Profile chunk size")
  editor.aboutSyncChunkLabel = aboutSyncChunkLabel

  local aboutSyncChunkEdit = CreateDeveloperEditBox("LIDCOUNCIL_ProfileSyncChunkEdit", aboutDeveloperFrame, 72)
  aboutSyncChunkEdit:SetPoint("LEFT", aboutSyncChunkLabel, "RIGHT", 12, 0)
  editor.aboutSyncChunkEdit = aboutSyncChunkEdit

  local aboutSyncChunkUnit = aboutDeveloperFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  aboutSyncChunkUnit:SetPoint("LEFT", aboutSyncChunkEdit, "RIGHT", 8, 0)
  aboutSyncChunkUnit:SetText("bytes")
  editor.aboutSyncChunkUnit = aboutSyncChunkUnit

  local aboutSyncDelayLabel = aboutDeveloperFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  aboutSyncDelayLabel:SetPoint("LEFT", aboutSyncChunkUnit, "RIGHT", 24, 0)
  aboutSyncDelayLabel:SetText("Queue delay")
  editor.aboutSyncDelayLabel = aboutSyncDelayLabel

  local aboutSyncDelayEdit = CreateDeveloperEditBox("LIDCOUNCIL_ProfileSyncDelayEdit", aboutDeveloperFrame, 72)
  aboutSyncDelayEdit:SetPoint("LEFT", aboutSyncDelayLabel, "RIGHT", 12, 0)
  editor.aboutSyncDelayEdit = aboutSyncDelayEdit

  local aboutSyncDelayUnit = aboutDeveloperFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  aboutSyncDelayUnit:SetPoint("LEFT", aboutSyncDelayEdit, "RIGHT", 8, 0)
  aboutSyncDelayUnit:SetText("sec")
  editor.aboutSyncDelayUnit = aboutSyncDelayUnit

  local aboutSyncTuningApplyBtn = CreateFrame("Button", nil, aboutDeveloperFrame, "UIPanelButtonTemplate")
  aboutSyncTuningApplyBtn:SetSize(100, 22)
  aboutSyncTuningApplyBtn:SetPoint("TOPLEFT", aboutSyncChunkLabel, "BOTTOMLEFT", 0, -10)
  aboutSyncTuningApplyBtn:SetText("Apply")
  editor.aboutSyncTuningApplyBtn = aboutSyncTuningApplyBtn

  local aboutSyncTuningResetBtn = CreateFrame("Button", nil, aboutDeveloperFrame, "UIPanelButtonTemplate")
  aboutSyncTuningResetBtn:SetSize(100, 22)
  aboutSyncTuningResetBtn:SetPoint("LEFT", aboutSyncTuningApplyBtn, "RIGHT", 10, 0)
  aboutSyncTuningResetBtn:SetText("Reset")
  editor.aboutSyncTuningResetBtn = aboutSyncTuningResetBtn

  local aboutSyncTuningState = aboutDeveloperFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  aboutSyncTuningState:SetPoint("LEFT", aboutSyncTuningResetBtn, "RIGHT", 12, 0)
  aboutSyncTuningState:SetWidth(320)
  aboutSyncTuningState:SetJustifyH("LEFT")
  aboutSyncTuningState:SetText("")
  editor.aboutSyncTuningState = aboutSyncTuningState

  local function RefreshDeveloperHealth()
    if not aboutDeveloperHealth then
      return
    end
    local diagnostics = GetRuntimeDiagnostics and GetRuntimeDiagnostics() or nil
    if type(diagnostics) ~= "table" then
      aboutDeveloperHealth:SetText("Runtime diagnostics unavailable.")
      return
    end

    local lines = {
      "Schema Version: " .. tostring(diagnostics.schemaVersion or 0),
      "Current Profile: " .. tostring(diagnostics.currentProfile or ""),
      "Enabled Profile: " .. tostring(diagnostics.enabledProfile or ""),
      "Active Profile ID: " .. tostring(diagnostics.activeProfileId or ""),
      "Profile Revisions: settings=" .. tostring(diagnostics.settingsRevision or 0)
        .. " | permissions=" .. tostring(diagnostics.permissionsRevision or 0)
        .. " | operational=" .. tostring(diagnostics.operationalRevision or 0),
      "Active Session ID: " .. tostring(diagnostics.activeSessionId or ""),
      "Session Host: " .. tostring(diagnostics.sessionHost or ""),
      "Local Role: " .. tostring(diagnostics.localRole or ""),
      "Local Access Summary: " .. tostring((diagnostics.localAccessSummary and diagnostics.localAccessSummary ~= "") and diagnostics.localAccessSummary or "none"),
      "Board Mode: " .. tostring(diagnostics.boardMode or ""),
      "Board ID: " .. tostring(diagnostics.boardId or ""),
      "Selected Item Key: " .. tostring(diagnostics.selectedItemKey or ""),
      "Joined Members: " .. tostring(diagnostics.joinedMemberCount or 0),
      "Tracked Items: " .. tostring(diagnostics.itemCount or 0),
      "Pending Choices: " .. tostring(diagnostics.pendingChoices or 0),
      "Unassigned Items: " .. tostring(diagnostics.unassignedItems or 0),
      "Shared Profile Sync: " .. tostring(diagnostics.sharedProfileSyncMode or "")
        .. " | " .. tostring(diagnostics.sharedProfileSyncSeverity or "")
        .. " | " .. tostring(diagnostics.sharedProfileSyncMessage or ""),
      "Shared Sync Sender: " .. tostring(diagnostics.sharedProfileSyncSender or ""),
      "Shared Sync UpdatedAt: " .. tostring(diagnostics.sharedProfileSyncUpdatedAt or 0),
      "Shared Sync Domains: remote=" .. tostring(diagnostics.sharedProfileSyncRemoteDomains or "none")
        .. " | local=" .. tostring(diagnostics.sharedProfileSyncLocalDomains or "none"),
      "Shared Sync Host Counts: newer=" .. tostring(diagnostics.sharedProfileSyncRemoteNewerCount or 0)
        .. " | conflicts=" .. tostring(diagnostics.sharedProfileSyncDivergedCount or 0)
        .. " | local-newer=" .. tostring(diagnostics.sharedProfileSyncLocalNewerCount or 0)
        .. " | same=" .. tostring(diagnostics.sharedProfileSyncSameCount or 0),
      "Permission Policy: v" .. tostring(diagnostics.permissionPolicyVersion or 0)
        .. " | overrides=" .. tostring(diagnostics.permissionPolicyHasOverrides == true and "YES" or "NO"),
      "Council Overrides: " .. tostring(diagnostics.permissionPolicyCouncilOverrideCount or 0)
        .. " | " .. tostring((diagnostics.permissionPolicyCouncilOverrides and diagnostics.permissionPolicyCouncilOverrides ~= "") and diagnostics.permissionPolicyCouncilOverrides or "none"),
      "Session Host Overrides: " .. tostring(diagnostics.permissionPolicySessionHostOverrideCount or 0)
        .. " | " .. tostring((diagnostics.permissionPolicySessionHostOverrides and diagnostics.permissionPolicySessionHostOverrides ~= "") and diagnostics.permissionPolicySessionHostOverrides or "none"),
      "Raider Overrides: " .. tostring(diagnostics.permissionPolicyRaiderOverrideCount or 0)
        .. " | " .. tostring((diagnostics.permissionPolicyRaiderOverrides and diagnostics.permissionPolicyRaiderOverrides ~= "") and diagnostics.permissionPolicyRaiderOverrides or "none"),
      "Last Board Sync Sender: " .. tostring(diagnostics.lastBoardSyncSender or ""),
      "Last Runtime Opcode: " .. tostring(diagnostics.lastOpcode or ""),
      "Last Runtime Sender: " .. tostring(diagnostics.lastSender or ""),
      "Developer Mode Flag: " .. tostring(diagnostics.developerMode == true and "ON" or "OFF"),
    }
    aboutDeveloperHealth:SetText(table.concat(lines, "\n"))
  end
  editor.RefreshDeveloperHealth = RefreshDeveloperHealth

  local function RefreshProfileSyncTuningControls()
    local tuning = GetProfileSyncTuning()
    if aboutSyncChunkEdit and not aboutSyncChunkEdit:HasFocus() then
      aboutSyncChunkEdit:SetText(tostring(tonumber(tuning.chunkSize) or 120))
    end
    if aboutSyncDelayEdit and not aboutSyncDelayEdit:HasFocus() then
      aboutSyncDelayEdit:SetText(string.format("%.2f", tonumber(tuning.intervalSeconds) or 0.12))
    end
    if aboutSyncTuningState then
      aboutSyncTuningState:SetText(string.format(
        "Default %d / %.2fs | Recommended %d-%d bytes, %.2f-%.2fs | Override active",
        tonumber(tuning.defaultChunkSize) or 120,
        tonumber(tuning.defaultIntervalSeconds) or 0.12,
        tonumber(tuning.minChunkSize) or 80,
        tonumber(tuning.maxChunkSize) or 190,
        tonumber(tuning.minIntervalSeconds) or 0.08,
        tonumber(tuning.maxIntervalSeconds) or 0.25
      ))
    end
  end

  local function RefreshDeveloperSection()
    local root = RootDB()
    root.ui = root.ui or {}
    local enabled = root.ui.developerMode == true
    local simulationState = GetSimulationProfileState(root)
    local simulationExists = simulationState.exists
    local activeSession = type(GetActiveLootSession) == "function" and GetActiveLootSession() or nil
    local hasRunningSession = activeSession and true or false
    local hasSimulationSession = HasActiveSimulationSession()

    if aboutDeveloperModeCheck then
      aboutDeveloperModeCheck:SetChecked(enabled)
    end
    if aboutShowProfileIdCheck then
      aboutShowProfileIdCheck:SetChecked(enabled and root.ui.showInternalProfileId == true or false)
    end
    if aboutShowProfileSizeCheck then
      aboutShowProfileSizeCheck:SetChecked(enabled and root.ui.showProfileSize == true or false)
    end
    if aboutTutorialModeCheck then
      aboutTutorialModeCheck:SetChecked(enabled and root.ui.tutorialMode == true or false)
    end
    if aboutShowSimulationCheck then
      aboutShowSimulationCheck:SetChecked(enabled and root.ui.showSimulationProfile == true or false)
    end

    local showAdvanced = enabled
    SetElementShown(aboutDeveloperOptionsDivider, showAdvanced)
    SetElementShown(aboutDeveloperOptionsHeader, showAdvanced)
    SetElementShown(aboutDeveloperOptionsDesc, showAdvanced)
    SetElementShown(aboutShowProfileIdCheck, showAdvanced)
    SetElementShown(profileIdInfo, showAdvanced)
    SetElementShown(aboutShowProfileSizeCheck, showAdvanced)
    SetElementShown(profileSizeInfo, showAdvanced)
    SetElementShown(aboutTutorialModeCheck, showAdvanced)
    SetElementShown(aboutShowSimulationCheck, showAdvanced)
    SetElementShown(aboutCreateSimulationBtn, showAdvanced)
    SetElementShown(aboutDeleteSimulationBtn, showAdvanced)
    SetElementShown(aboutRuntimeDivider, showAdvanced)
    SetElementShown(aboutRuntimeHeader, showAdvanced)
    SetElementShown(aboutRuntimeDesc, showAdvanced)
    SetElementShown(aboutSimulationState, showAdvanced)
    SetElementShown(aboutDeveloperState, showAdvanced)
    SetElementShown(aboutDeveloperHealthHeader, showAdvanced)
    SetElementShown(aboutDeveloperHealth, showAdvanced)
    SetElementShown(aboutDeveloperExperimentalDivider, showAdvanced)
    SetElementShown(aboutDeveloperExperimentalHeader, showAdvanced)
    SetElementShown(aboutDeveloperExperimentalInfo, showAdvanced)
    SetElementShown(aboutDeveloperExperimentalDesc, showAdvanced)
    SetElementShown(aboutSyncChunkLabel, showAdvanced)
    SetElementShown(aboutSyncChunkEdit, showAdvanced)
    SetElementShown(aboutSyncChunkUnit, showAdvanced)
    SetElementShown(aboutSyncDelayLabel, showAdvanced)
    SetElementShown(aboutSyncDelayEdit, showAdvanced)
    SetElementShown(aboutSyncDelayUnit, showAdvanced)
    SetElementShown(aboutSyncTuningApplyBtn, showAdvanced)
    SetElementShown(aboutSyncTuningResetBtn, showAdvanced)
    SetElementShown(aboutSyncTuningState, showAdvanced)

    if aboutShowSimulationCheck and aboutShowSimulationCheck.Enable then
      if enabled then
        aboutShowSimulationCheck:Enable()
      else
        aboutShowSimulationCheck:Disable()
      end
    end
    if aboutCreateSimulationBtn and aboutCreateSimulationBtn.Enable then
      if enabled and not simulationExists then
        aboutCreateSimulationBtn:Enable()
      else
        aboutCreateSimulationBtn:Disable()
      end
    end
    if aboutDeleteSimulationBtn and aboutDeleteSimulationBtn.Enable then
      if enabled and simulationExists and simulationState.canDelete and not hasRunningSession then
        aboutDeleteSimulationBtn:Enable()
      else
        aboutDeleteSimulationBtn:Disable()
      end
    end

    if aboutSimulationState then
      aboutSimulationState:SetText(
        "Simulation Profile: " .. tostring(simulationExists and "Present" or "Missing")
        .. (simulationExists and (" | Master: " .. tostring(simulationState.masterKey ~= "" and simulationState.masterKey or "Unassigned")) or "")
        .. " | Visible in Profile list: " .. tostring(root.ui.showSimulationProfile == true and "ON" or "OFF")
        .. (simulationExists and not simulationState.canDelete and simulationState.masterKey ~= "" and " | Delete locked for non-owner." or "")
        .. (hasSimulationSession and " | Stop the active Simulation session before hiding it." or "")
        .. (hasRunningSession and not hasSimulationSession and " | Stop the active session before deleting it." or "")
      )
    end
    if aboutDeveloperState then
      if enabled then
        aboutDeveloperState:SetText(
          "Developer Mode: ON\n"
          .. "Profile ID display: " .. tostring(root.ui.showInternalProfileId == true and "ON" or "OFF")
          .. " | Profile Size display: " .. tostring(root.ui.showProfileSize == true and "ON" or "OFF") .. "\n"
          .. "Tutorial Mode: " .. tostring(root.ui.tutorialMode == true and "ON" or "OFF") .. "\n"
          .. "Silent-error tracing is active while Developer Mode is enabled."
        )
      else
        aboutDeveloperState:SetText(
          "Developer Mode: OFF\n"
          .. "Profile ID display: OFF | Profile Size display: OFF | Tutorial Mode: OFF\n"
          .. "Silent-error tracing is currently disabled."
        )
      end
    end

    RefreshDeveloperHealth()
    RefreshProfileSyncTuningControls()
    if editor and editor.UpdateAboutDeveloperLayout then
      editor:UpdateAboutDeveloperLayout()
    end
  end
  editor.RefreshDeveloperSection = RefreshDeveloperSection

  aboutDeveloperModeCheck:SetScript("OnClick", function(self)
    local root = RootDB()
    root.ui = root.ui or {}
    local enabled = self:GetChecked() and true or false
    if not enabled and root.ui.showSimulationProfile == true and HasActiveSimulationSession() then
      root.ui.developerMode = true
      self:SetChecked(true)
      if type(Print) == "function" then
        Print("Stop the active Simulation session before hiding the Simulation profile.")
      end
      RefreshDeveloperSection()
      if editor and editor.RefreshAbout then editor:RefreshAbout() end
      if editor and editor.Refresh then editor:Refresh() end
      return
    end

    root.ui.developerMode = enabled
    if not enabled then
      root.ui.showInternalProfileId = false
      root.ui.showProfileSize = false
      root.ui.tutorialMode = false
      root.ui.showSimulationProfile = false
      MoveAwayFromSimulationSelection()
    end

    local debugStore = _G.LIDCOUNCIL_Debug
    if not enabled and debugStore then
      debugStore.silent = {}
    end
    RefreshDeveloperSection()
    if editor and editor.RefreshAbout then editor:RefreshAbout() end
    if editor and editor.Refresh then editor:Refresh() end
  end)

  aboutShowProfileIdCheck:SetScript("OnClick", function(self)
    local root = RootDB()
    root.ui = root.ui or {}
    if root.ui.developerMode ~= true then
      root.ui.showInternalProfileId = false
      self:SetChecked(false)
      RefreshDeveloperSection()
      return
    end
    root.ui.showInternalProfileId = self:GetChecked() and true or false
    RefreshDeveloperSection()
    if editor and editor.Refresh then editor:Refresh() end
  end)

  aboutShowProfileSizeCheck:SetScript("OnClick", function(self)
    local root = RootDB()
    root.ui = root.ui or {}
    if root.ui.developerMode ~= true then
      root.ui.showProfileSize = false
      self:SetChecked(false)
      RefreshDeveloperSection()
      return
    end
    root.ui.showProfileSize = self:GetChecked() and true or false
    RefreshDeveloperSection()
    if editor and editor.Refresh then editor:Refresh() end
  end)

  local function ApplyProfileSyncTuningFromInputs()
    local root = RootDB()
    root.ui = root.ui or {}
    if root.ui.developerMode ~= true then
      if type(Print) == "function" then
        Print("Activate Developer Mode before changing experimental sync tuning.")
      end
      RefreshDeveloperSection()
      return
    end

    local chunkSize = ParseDeveloperNumber(aboutSyncChunkEdit and aboutSyncChunkEdit:GetText() or "")
    local delaySeconds = ParseDeveloperNumber(aboutSyncDelayEdit and aboutSyncDelayEdit:GetText() or "")
    local tuning = SetProfileSyncTuning(chunkSize, delaySeconds)
    if type(Print) == "function" then
      Print(string.format(
        "Profile sync tuning applied: %d byte chunks, %.2fs queue delay.",
        tonumber(tuning.chunkSize) or 120,
        tonumber(tuning.intervalSeconds) or 0.12
      ))
    end
    RefreshDeveloperSection()
    if editor and editor.Refresh then editor:Refresh() end
  end

  if aboutSyncTuningApplyBtn then
    aboutSyncTuningApplyBtn:SetScript("OnClick", ApplyProfileSyncTuningFromInputs)
  end
  if aboutSyncTuningResetBtn then
    aboutSyncTuningResetBtn:SetScript("OnClick", function()
      local tuning = ResetProfileSyncTuning()
      if type(Print) == "function" then
        Print(string.format(
          "Profile sync tuning reset: %d byte chunks, %.2fs queue delay.",
          tonumber(tuning.chunkSize) or 120,
          tonumber(tuning.intervalSeconds) or 0.12
        ))
      end
      RefreshDeveloperSection()
      if editor and editor.Refresh then editor:Refresh() end
    end)
  end
  for _, editBox in ipairs({ aboutSyncChunkEdit, aboutSyncDelayEdit }) do
    if editBox then
      editBox:SetScript("OnEnterPressed", function(self)
        ApplyProfileSyncTuningFromInputs()
        self:ClearFocus()
      end)
      editBox:SetScript("OnEscapePressed", function(self)
        self:ClearFocus()
        RefreshProfileSyncTuningControls()
      end)
    end
  end

  aboutTutorialModeCheck:SetScript("OnClick", function(self)
    local root = RootDB()
    root.ui = root.ui or {}
    if root.ui.developerMode ~= true then
      root.ui.tutorialMode = false
      self:SetChecked(false)
      RefreshDeveloperSection()
      return
    end
    root.ui.tutorialMode = self:GetChecked() and true or false
    RefreshDeveloperSection()
    if editor and editor.Refresh then editor:Refresh() end
  end)

  aboutShowSimulationCheck:SetScript("OnClick", function(self)
    local root = RootDB()
    root.ui = root.ui or {}
    if root.ui.developerMode ~= true then
      root.ui.showSimulationProfile = false
      self:SetChecked(false)
      RefreshDeveloperSection()
      return
    end
    if not self:GetChecked() and HasActiveSimulationSession() then
      root.ui.showSimulationProfile = true
      self:SetChecked(true)
      if type(Print) == "function" then
        Print("Stop the active Simulation session before hiding the Simulation profile.")
      end
      RefreshDeveloperSection()
      if editor and editor.Refresh then editor:Refresh() end
      return
    end
    root.ui.showSimulationProfile = self:GetChecked() and true or false
    if not root.ui.showSimulationProfile then
      MoveAwayFromSimulationSelection()
    end
    RefreshDeveloperSection()
    if editor and editor.Refresh then editor:Refresh() end
  end)

  aboutCreateSimulationBtn:SetScript("OnClick", function()
    local root = RootDB()
    root.ui = root.ui or {}
    if root.ui.developerMode ~= true then
      if type(Print) == "function" then
        Print("Activate Developer Mode first.")
      end
      return
    end
    local simulationState = GetSimulationProfileState(root)
    if simulationState.exists then
      root.ui.showSimulationProfile = true
      RefreshDeveloperSection()
      if editor and editor.Refresh then editor:Refresh() end
      if type(Print) == "function" then
        if simulationState.repaired then
          Print("Recovered the existing Simulation profile for this character.")
        else
          Print("Simulation profile already exists.")
        end
      end
      return
    end
    if type(CreateLootProfileApi) ~= "function" then
      if type(Print) == "function" then
        Print("Simulation profile API unavailable.")
      end
      return
    end
    local ok, result = CreateLootProfileApi("Simulation")
    if not ok then
      if type(Print) == "function" then
        Print(tostring(result or "Could not create the Simulation profile."))
      end
      return
    end
    local profileManagement = INTERNAL_API and INTERNAL_API.LIDCOUNCIL_EditorProfileManagement_Impl or nil
    if type(profileManagement) == "table" and type(profileManagement.InvalidateSortedProfileNames) == "function" then
      profileManagement.InvalidateSortedProfileNames(root)
    end
    root.ui.showSimulationProfile = true
    RefreshDeveloperSection()
    if editor and editor.Refresh then editor:Refresh() end
    if type(StaticPopup_Show) == "function" then
      StaticPopup_Show("LIDCOUNCIL_SIMULATION_PROFILE_CREATED")
    elseif type(Print) == "function" then
      Print("Simulation Profile created - go to Profile to start using it for Simulations.")
    end
  end)

  aboutDeleteSimulationBtn:SetScript("OnClick", function()
    local root = RootDB()
    root.ui = root.ui or {}
    if root.ui.developerMode ~= true then
      if type(Print) == "function" then
        Print("Activate Developer Mode first.")
      end
      return
    end
    local simulationState = GetSimulationProfileState(root)
    if not simulationState.exists then
      if type(Print) == "function" then
        Print("Simulation profile not found.")
      end
      return
    end
    if type(simulationState.access) == "table" and not simulationState.canDelete then
      if type(Print) == "function" then
        Print("Only the Simulation profile owner can delete it.")
      end
      RefreshDeveloperSection()
      return
    end
    if type(DeleteLootProfileApi) ~= "function" then
      if type(Print) == "function" then
        Print("Simulation delete API unavailable.")
      end
      return
    end
    if type(StaticPopup_Show) == "function" then
      StaticPopup_Show("LIDCOUNCIL_DELETE_SIMULATION_PROFILE")
    end
  end)

  local function UpdateAboutDeveloperLayout()
    if not aboutContent or not aboutDeveloperText then return end
    if editor and editor.aboutSection and editor.aboutSection ~= "Developer" then return end
    local root = RootDB()
    root.ui = root.ui or {}
    local enabled = root.ui.developerMode == true
    local w = (aboutContent:GetWidth() or 0) - 10
    if w < 200 then w = 200 end

    aboutDeveloperText:SetWidth(w)
    if aboutDeveloperModeDesc then aboutDeveloperModeDesc:SetWidth(math.max(220, w - 24)) end
    if aboutDeveloperOptionsDesc then aboutDeveloperOptionsDesc:SetWidth(w) end
    if aboutRuntimeDesc then aboutRuntimeDesc:SetWidth(w) end
    if aboutSimulationState then aboutSimulationState:SetWidth(w) end
    if aboutDeveloperState then aboutDeveloperState:SetWidth(w) end
    if aboutDeveloperHealth then aboutDeveloperHealth:SetWidth(w) end
    if aboutDeveloperExperimentalDesc then aboutDeveloperExperimentalDesc:SetWidth(w) end
    if aboutSyncTuningState then aboutSyncTuningState:SetWidth(w) end

    if aboutDeveloperExperimentalDivider then
      aboutDeveloperExperimentalDivider:ClearAllPoints()
      aboutDeveloperExperimentalDivider:SetPoint("TOPLEFT", aboutDeveloperHealth, "BOTTOMLEFT", 0, -18)
      aboutDeveloperExperimentalDivider:SetPoint("RIGHT", aboutDeveloperFrame, "RIGHT", -10, 0)
    end
    if aboutDeveloperExperimentalHeader then
      aboutDeveloperExperimentalHeader:ClearAllPoints()
      aboutDeveloperExperimentalHeader:SetPoint("TOPLEFT", aboutDeveloperExperimentalDivider, "BOTTOMLEFT", 0, -12)
    end
    if aboutDeveloperExperimentalInfo then
      aboutDeveloperExperimentalInfo:ClearAllPoints()
      aboutDeveloperExperimentalInfo:SetPoint("LEFT", aboutDeveloperExperimentalHeader, "RIGHT", 8, 0)
    end
    if aboutDeveloperExperimentalDesc then
      aboutDeveloperExperimentalDesc:ClearAllPoints()
      aboutDeveloperExperimentalDesc:SetPoint("TOPLEFT", aboutDeveloperExperimentalHeader, "BOTTOMLEFT", 0, -6)
    end
    if aboutSyncChunkLabel then
      aboutSyncChunkLabel:ClearAllPoints()
      aboutSyncChunkLabel:SetPoint("TOPLEFT", aboutDeveloperExperimentalDesc, "BOTTOMLEFT", 0, -12)
    end
    if aboutSyncChunkEdit then
      aboutSyncChunkEdit:ClearAllPoints()
      aboutSyncChunkEdit:SetPoint("LEFT", aboutSyncChunkLabel, "RIGHT", 12, 0)
    end
    if aboutSyncChunkUnit then
      aboutSyncChunkUnit:ClearAllPoints()
      aboutSyncChunkUnit:SetPoint("LEFT", aboutSyncChunkEdit, "RIGHT", 8, 0)
    end
    local singleLineTuning = w >= 540
    if aboutSyncDelayLabel then
      aboutSyncDelayLabel:ClearAllPoints()
      if singleLineTuning then
        aboutSyncDelayLabel:SetPoint("LEFT", aboutSyncChunkUnit, "RIGHT", 24, 0)
      else
        aboutSyncDelayLabel:SetPoint("TOPLEFT", aboutSyncChunkLabel, "BOTTOMLEFT", 0, -10)
      end
    end
    if aboutSyncDelayEdit then
      aboutSyncDelayEdit:ClearAllPoints()
      aboutSyncDelayEdit:SetPoint("LEFT", aboutSyncDelayLabel, "RIGHT", 12, 0)
    end
    if aboutSyncDelayUnit then
      aboutSyncDelayUnit:ClearAllPoints()
      aboutSyncDelayUnit:SetPoint("LEFT", aboutSyncDelayEdit, "RIGHT", 8, 0)
    end
    if aboutSyncTuningApplyBtn then
      aboutSyncTuningApplyBtn:ClearAllPoints()
      if singleLineTuning then
        aboutSyncTuningApplyBtn:SetPoint("TOPLEFT", aboutSyncChunkLabel, "BOTTOMLEFT", 0, -12)
      else
        aboutSyncTuningApplyBtn:SetPoint("TOPLEFT", aboutSyncDelayLabel, "BOTTOMLEFT", 0, -12)
      end
    end
    if aboutSyncTuningResetBtn then
      aboutSyncTuningResetBtn:ClearAllPoints()
      aboutSyncTuningResetBtn:SetPoint("LEFT", aboutSyncTuningApplyBtn, "RIGHT", 10, 0)
    end
    if aboutSyncTuningState then
      aboutSyncTuningState:ClearAllPoints()
      aboutSyncTuningState:SetPoint("TOPLEFT", aboutSyncTuningApplyBtn, "BOTTOMLEFT", 0, -8)
    end

    local t1 = (aboutDeveloperText.GetStringHeight and aboutDeveloperText:GetStringHeight()) or 60
    local tMode = (aboutDeveloperModeDesc and aboutDeveloperModeDesc.GetStringHeight and aboutDeveloperModeDesc:GetStringHeight()) or 20
    local tOptions = enabled and ((aboutDeveloperOptionsDesc and aboutDeveloperOptionsDesc.GetStringHeight and aboutDeveloperOptionsDesc:GetStringHeight()) or 18) or 0
    local tState = enabled and (
      ((aboutSimulationState and aboutSimulationState.GetStringHeight and aboutSimulationState:GetStringHeight()) or 20)
      + ((aboutDeveloperState and aboutDeveloperState.GetStringHeight and aboutDeveloperState:GetStringHeight()) or 20)
    ) or 0
    local tHealth = enabled and ((aboutDeveloperHealth and aboutDeveloperHealth.GetStringHeight and aboutDeveloperHealth:GetStringHeight()) or 120) or 0
    local tExperimental = enabled and ((aboutDeveloperExperimentalDesc and aboutDeveloperExperimentalDesc.GetStringHeight and aboutDeveloperExperimentalDesc:GetStringHeight()) or 20) or 0
    local tExperimentalControls = enabled and (singleLineTuning and 78 or 110) or 0

    if editor and editor.SetAboutContentHeight then
      if enabled then
        editor:SetAboutContentHeight(math.max(560, math.floor(t1 + tMode + tOptions + tState + tHealth + tExperimental + tExperimentalControls + 520)))
      else
        editor:SetAboutContentHeight(math.max(520, math.floor(t1 + tMode + 180)))
      end
    end
  end
  editor.UpdateAboutDeveloperLayout = UpdateAboutDeveloperLayout
  SafeHookScript(aboutDeveloperFrame, "OnShow", function()
    if editor and editor.RefreshDeveloperSection then editor:RefreshDeveloperSection() end
    UpdateAboutDeveloperLayout()
  end)
  SafeHookScript(aboutContent, "OnSizeChanged", UpdateAboutDeveloperLayout)
end

INTERNAL_API.LIDCOUNCIL_CreateAboutUtilitySections_Impl = CreateAboutUtilitySections
