Salesforce flattens data and uses aria-expanded, aria-level for styling. I would suggest the same. Here is the script to flatten data. I also updated playgroundplayground with simple styling for Id
UPDATE: Created separate playgroundplayground to not override changes.