[Question]
  [
[MarioLANG](http://esolangs.org/wiki/MarioLANG) is a two-dimensional programming language where the source code resembles a Super Mario Bros. level. Furthermore, its instruction set is very similar to [Brainfuck](http://esolangs.org/wiki/Brainfuck)'s. This means that MarioLANG is essentially a 2-D Brainfuck where the instruction pointer moves like Mario. So [when I wrote my MarioLANG submission](https://codegolf.stackexchange.com/a/54928/8478) for the Programming Language Quiz, I started by converting a Brainfuck "Hello, World!" program to MarioLANG. I noticed that this is possible with a very systematic process, so let's write a Brainfuck-to-MarioLANG compiler!
*Note:* The MarioLANG spec isn't entirely unambiguous, so I'm assuming the interpretation of the [Ruby implementation](https://github.com/mynery/mariolang.rb/blob/master/mariolang.rb).
I'll explain the process with the following Brainfuck program:
```
++[>+++++[>+++++++>++++++++++>+++>+<<<<-]<-]>>++.>+.+++++++..+++.>+++.>.
```
It prints `Hello!` and a trailing newline.
1. Convert `<` and `>` to `(` and `)`, respectively:
```
++[)+++++[)+++++++)++++++++++)+++)+((((-](-]))++.)+.+++++++..+++.)+++.).
```
2. Add a floor for Mario to walk on:
```
++[)+++++[)+++++++)++++++++++)+++)+((((-](-]))++.)+.+++++++..+++.)+++.).
========================================================================
```
3. Now the issue is that MarioLANG doesn't have loops like `[` and `]`. Instead, we have to use elevators and directional instructions to make Mario actually walk in a loop. First, we replace `[` with `>` and change the floor to `"`. And we also replace `]` with `[!` and change the floor to `=#`:
```
++>)+++++>)+++++++)++++++++++)+++)+((((-[!(-[!))++.)+.+++++++..+++.)+++.).
=="======"===============================#===#============================
```
4. The `"` and `#` can form elevators (starting from `#`, ending at `"`), so now all we need are auxiliary floors for Mario to walk back on. The start with `!` and end with `<`:
```
++>)+++++>)+++++++)++++++++++)+++)+((((-[!(-[!))++.)+.+++++++..+++.)+++.).
=="======"===============================#===#============================
         !                               <    
         #==============================="    
  !                                          <
  #=========================================="
```
Note that all lines must be at least as long as the largest enclosing loop, because the interpreter isn't able to connect elevator ends across shorter lines. Therefore, we pad the middle lines with spaces.
And that's it. We've got a fully functional, equivalent MarioLANG program.
## The Challenge
Given a valid Brainfuck program, implement the above procedure to compile it into a MarioLANG program.
You may assume that there are only command characters in the input, i.e. no characters except `,.+-<>[]`.
All auxiliary floor must be as close as possible to the main program floor. You may choose to pad the lines of intermediate floors either as little as possible (up to the width of the largest enclosing loop) or to the end of the main program.
You may write a program or function, taking input via STDIN (or closest alternative), command-line argument or function argument and outputting the result via STDOUT (or closest alternative), function return value or function (out) parameter. If you don't print the result to STDOUT, it should still be a single newline-separated string.
This is code golf, so the shortest answer (in bytes) wins.
## Test Cases
The test cases are formatted as follows: the first line is the Brainfuck program (your input), then there's an empty line, and everything until the next empty line is the expected output in MarioLANG. These examples use the minimal amount of padded spaces. Alternatively, you may pad each line with spaces to the width of the first line of the output.
```
>,++-.<
),++-.(
=======
,[.,]
,>.,[!
="===#
 !   <
 #==="
>>[-]<<[->>+<<]
))>-[!((>-))+(([!
=="==#=="=======#
  !  <  !       <
  #=="  #======="
++[>+++++[>+++++++>++++++++++>+++>+<<<<-]<-]>>++.>+.+++++++..+++.>+++.>.
++>)+++++>)+++++++)++++++++++)+++)+((((-[!(-[!))++.)+.+++++++..+++.)+++.).
=="======"===============================#===#============================
         !                               <    
         #==============================="    
  !                                          <
  #=========================================="
[][[[][[]]][]][[]]
>[!>>>[!>>[![![!>[![!>>[![!
"=#"""=#""=#=#=#"=#=#""=#=#
! <  ! < ! <    ! <   ! <  
#="  #=" #="    #="   #="  
        !    <       !    <
        #===="       #===="
    !          <     
    #=========="     
   !                <
   #================"
>>+++++++>>++>>++++>>+++++++>>+>>++++>>+>>+++>>+>>+++++>>+>>++>>+>>++++++>>++>>++++>>+++++++>>+>>+++++>>++>>+>>+>>++++>>+++++++>>+>>+++++>>+>>+>>+>>++++>>+++++++>>+>>+++++>>++++++++++++++>>+>>+>>++++>>+++++++>>+>>+++++>>++>>+>>+>>++++>>+++++++>>+>>+++++>>+++++++++++++++++++++++++++++>>+>>+>>++++>>+++++++>>+>>+++++>>++>>+>>+>>+++++>>+>>++++++>>+>>++>>+>>++++++>>+>>++>>+>>++++++>>+>>++>>+>>++++++>>+>>++>>+>>++++++>>+>>++>>+>>++++++>>+>>++>>+>>++++++>>++>>++++>>+++++++>>+>>+++++>>+++++++>>+>>+++++>>+>>+>>+>>++++>>+>>++>>+>>++++++>>+>>+++++>>+++++++>>+>>++++>>+>>+>>++>>+++++>>+>>+++>>+>>++++>>+>>++>>+>>++++++>>+>>+++++>>+++++++++++++++++++>>++>>++>>+++>>++>>+>>++>>++++>>+++++++>>++>>+++++>>++++++++++>>+>>++>>++++>>+>>++>>+>>++++++>>++++++>>+>>+>>+++++>>+>>++++++>>++>>+++++>>+++++++>>++>>++++>>+>>++++++[<<]>>[>++++++[-<<++++++++++>>]<<++..------------------->[-<.>>+<]>[-<+>]>]<<[-[-[-[-[-[-[>++>]<+++++++++++++++++++++++++++++>]<++>]<++++++++++++++>]<+>]<++>]<<[->.<]<<]
))+++++++))++))++++))+++++++))+))++++))+))+++))+))+++++))+))++))+))++++++))++))++++))+++++++))+))+++++))++))+))+))++++))+++++++))+))+++++))+))+))+))++++))+++++++))+))+++++))++++++++++++++))+))+))++++))+++++++))+))+++++))++))+))+))++++))+++++++))+))+++++))+++++++++++++++++++++++++++++))+))+))++++))+++++++))+))+++++))++))+))+))+++++))+))++++++))+))++))+))++++++))+))++))+))++++++))+))++))+))++++++))+))++))+))++++++))+))++))+))++++++))+))++))+))++++++))++))++++))+++++++))+))+++++))+++++++))+))+++++))+))+))+))++++))+))++))+))++++++))+))+++++))+++++++))+))++++))+))+))++))+++++))+))+++))+))++++))+))++))+))++++++))+))+++++))+++++++++++++++++++))++))++))+++))++))+))++))++++))+++++++))++))+++++))++++++++++))+))++))++++))+))++))+))++++++))++++++))+))+))+++++))+))++++++))++))+++++))+++++++))++))++++))+))++++++>(([!))>)++++++>-((++++++++++))[!((++..-------------------)>-(.))+([!)>-(+)[!)[!((>->->->->->->)++)[!(+++++++++++++++++++++++++++++)[!(++)[!(++++++++++++++)[!(+)[!(++)[!((>-).([!(([!
========================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================="===#=="======="================#=========================="========#="=====#==#=="="="="="="="=====#================================#=====#=================#====#=====#=="=====#===#
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         !   <          !                <                          !        < !     <                 !     <                                                                      !     <    
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         #==="          #================"                          #========" #====="                 #====="                                                                      #====="    
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                !                                                                       <            !                                        <                                                
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                #======================================================================="            #========================================"                                                
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   !                                                <                                          
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   #================================================"                                          
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 !                                                                    <                        
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 #===================================================================="                        
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               !                                                                           <                   
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               #==========================================================================="                   
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             !                                                                                   <             
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             #==================================================================================="             
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           !                                                                                                  <
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           #=================================================================================================="
```
  
[Answer]
# CJam, ~~148~~ 144 bytes
```
q"<>[""()>"er']/"[!"*_">!"1$|"\"#=":Cer:FF,[{SF,*L{'=t}/FI>(C#"['=-{_'##}{_CW</s}w],2*(:M'#tM('!tLM+ ;LW=34ctLW=('<tLW< ;L"S/=~:L;}fI]z~]{S-},N*
```
Try it online in the [CJam interpreter](http://cjam.aditsu.net/#code=q%22%3C%3E%5B%22%22()%3E%22er'%5D%2F%22%5B!%22*_%22%3E!%221%24%7C%22%5C%22%23%3D%22%3ACer%3AFF%2C%5B%7BSF%2C*L%7B'%3Dt%7D%2FFI%3E(C%23%22%5B'%3D-%7B_'%23%23%7D%7B_CW%3C%2Fs%7Dw%5D%2C2*(%3AM'%23tM('!tLM%2B%20%3BLW%3D34ctLW%3D('%3CtLW%3C%20%3BL%22S%2F%3D~%3AL%3B%7DfI%5Dz~%5D%7BS-%7D%2CN*&input=%5B%5D%5B%5B%5B%5D%5B%5B%5D%5D%5D%5B%5D%5D%5B%5B%5D%5D).
[Answer]
# Python, 707 chars
```
def b(c):
 c,l,o,x,j,m=list(c.replace(">",")").replace("<","(")),[list("="*len(c))],[],[],0,0
 for i,z in enumerate(c):
  i+=j
  if"["==z:
   c[i],l[0][i]=">",'"'
   x.append(i)
  if"]"==z:
   c[i],l[0][i]="[!","=#"
   c,l[0],m,d,b=list("".join(c)),list("".join(l[0])),max(m,len(x)),0,x.pop()
   for a in o:d+=b<a[0]and-~i>a[0]or b<a[1]and-~i>a[1]
   o.append((b,i+1,d))
   j+=1
 for q in o:
  d=q[2]*2+1
  while len(l)<=d+1:l.append(list(" "*len(c)))
  l[d][q[0]],l[d+1][q[0]],l[d][q[1]],l[d+1][q[1]]="!","#","<",'"'
  for i in range(q[0]+1,q[1]):l[d+1][i]="="
 g="\n".join(l.rstrip()for l in("".join(c)+"\n"+"\n".join("".join(f)for f in l)).split("\n"))
 while"\n\n"in g:g=g.replace("\n\n","\n")
 return g
```
There's probably a lot of space to be golfed. Doesn't work for the last test case.
Example usage:
```
>>> print b("++[>+++<-]>[<+++>-]<.")
=="=======#="=======#==
  !       < !       <
  #=======" #======="
```
No lines in the output contains trailing spaces.
]