code: def _nest_rules(self, rule, p_selectors, p_parents, p_children, scope, media, c_lineno, c_property, c_codestr):
          
          if c_property == self.construct and rule[MEDIA] == media:
              rule[CODESTR] = c_codestr
              self.manage_children(
                  rule, p_selectors, p_parents, p_children, scope, media)
          else:
              c_property = self.apply_vars(
                  c_property, rule[CONTEXT], rule[OPTIONS], rule, True)
  
              c_selectors = self.normalize_selectors(c_property)
              c_selectors, _, c_parents = c_selectors.partition(' extends ')
  
              better_selectors = set()
              c_selectors = c_selectors.split(',')
              for c_selector in c_selectors:
                  for p_selector in p_selectors:
                      if c_selector == self.construct:
                          better_selectors.add(p_selector)
                      elif '&' in c_selector:  # Parent References
                          better_selectors.add(
                              c_selector.replace('&', p_selector))
                      elif p_selector:
                          better_selectors.add(p_selector + ' ' + c_selector)
                      else:
                          better_selectors.add(c_selector)
              better_selectors = ','.join(sorted(better_selectors))
  
              if c_parents:
                  parents = set(p.strip() for p in c_parents.split('&'))
                  parents.discard('')
                  if parents:
                      better_selectors += ' extends ' + '&'.join(sorted(parents))
  
              _rule = spawn_rule(rule, codestr=c_codestr, deps=set(), context=rule[CONTEXT].copy(), options=rule[OPTIONS].copy(), selectors=better_selectors, properties=[], final=False, media=media, lineno=c_lineno)
  
              p_children.appendleft(_rule)
docs: Implements Nested CSS rules