   processStyleText: ->
     styletext = @styletext
     lines = styletext.split('\n')
+    lastSelectorLine = null
     for line, i in lines
       lineBeginsWithAttribute = @doesLineBeginsWithAttribute(line)
       line = @renameHyphenFunctionName(line)
-      lineBefore = lines[i-1]
+      lineBefore = lines[lastSelectorLine]
       # media queries have an exception rule
       if @pattern.isCSSQuery.test(line)
         # @media

throw 'CoffeeScript is needed' unless CoffeeScript?

class DocumentStyle


        line = line.replace /^(\s*)([a-zA-Z\.\#\&\>\:\*]+((?!\:\s).)*)$/, "\n@add '$2', '$1', "
        # one selector, like `body.imprint`
        line = line.replace /\n(\s*)([a-zA-Z\.\#\&\>\:\*]+((?!\:\s).)*)(\s*)$/, "\n@add '$2', '$1', $4"
        lastSelectorLine = null
      # check line before called a function/css query like @page
      if lineBefore and lineBeginsWithAttribute and /^\s*(@[a-z\_\-]+)([^\,]\s*)*\s*$/i.test(lineBefore)
        matches = lineBefore.match /^(\s*)(@[a-z\_\-]+)([^a-z\_\,].*)*\s*$/i
        changedLine  = matches[1]+matches[2]
        # TODO: what if @rule :pseudo, :pseudo ?
        lines[lastSelectorLine] = changedLine += ( if matches[3] then matches[3]+',' else '' ) + ' __$cssAttributes__ ='
      lastSelectorLine = i if /^@[a-zA-Z\_\-]+/.test(line)
      lines[i] = line

    @styletext = lines.join('\n').replace(/\n+/g, "\n")
