File size: 248,012 Bytes
e8e4be6
 
 
 
 
 
0c5e7b7
 
 
 
 
e8e4be6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0c5e7b7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e8e4be6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9b13459
e8e4be6
 
 
9b13459
 
e8e4be6
 
 
 
 
 
 
 
 
 
 
9b13459
e8e4be6
 
 
 
 
 
 
 
9b13459
e8e4be6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9b13459
e8e4be6
 
 
9b13459
 
e8e4be6
1c22380
e8e4be6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1c22380
e8e4be6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9b13459
 
 
 
 
 
 
 
 
 
 
 
 
 
e8e4be6
9b13459
 
e8e4be6
 
 
 
 
 
 
 
 
9b13459
 
 
 
 
 
 
 
 
 
 
 
 
 
e8e4be6
9b13459
 
e8e4be6
 
 
 
 
 
 
 
 
9b13459
 
 
 
 
 
 
 
 
 
 
 
 
 
e8e4be6
9b13459
 
e8e4be6
 
 
 
 
 
 
 
 
9b13459
 
 
 
 
 
 
 
 
 
 
 
 
 
e8e4be6
9b13459
 
e8e4be6
 
 
 
 
 
 
 
 
9b13459
 
 
 
 
 
 
 
 
 
 
 
 
 
e8e4be6
9b13459
 
e8e4be6
 
 
 
 
 
 
 
 
9b13459
 
 
 
 
 
 
 
 
 
 
 
 
 
e8e4be6
9b13459
 
e8e4be6
 
 
 
 
 
 
 
 
9b13459
 
 
 
 
 
 
 
 
 
 
 
 
 
e8e4be6
9b13459
 
e8e4be6
 
 
 
 
 
 
 
 
9b13459
 
 
 
 
 
 
 
 
 
 
 
 
 
e8e4be6
9b13459
 
e8e4be6
 
 
 
 
 
 
 
 
9b13459
 
 
 
 
 
 
 
 
 
 
 
 
 
e8e4be6
9b13459
 
e8e4be6
 
 
 
 
 
 
 
 
9b13459
 
 
 
 
 
 
 
 
 
 
 
 
 
e8e4be6
9b13459
 
e8e4be6
 
 
 
 
 
 
 
 
9b13459
 
 
 
 
 
 
 
 
 
 
 
 
 
e8e4be6
9b13459
 
e8e4be6
 
 
 
 
 
 
 
 
9b13459
 
 
 
 
 
 
 
 
 
 
 
 
 
e8e4be6
9b13459
 
e8e4be6
 
 
 
 
 
 
 
 
9b13459
 
 
 
 
 
 
 
 
 
 
 
 
 
e8e4be6
9b13459
 
e8e4be6
 
 
 
 
 
 
 
 
9b13459
 
 
 
 
 
 
 
 
 
 
 
 
 
e8e4be6
9b13459
 
e8e4be6
 
 
 
 
 
 
 
 
9b13459
 
 
 
 
 
 
 
 
 
 
 
 
 
e8e4be6
9b13459
 
e8e4be6
 
 
 
 
 
 
 
 
9b13459
 
 
 
 
 
 
 
 
 
 
 
 
 
e8e4be6
9b13459
 
e8e4be6
 
 
 
 
 
 
 
 
9b13459
 
 
 
 
 
 
 
 
 
 
 
 
 
e8e4be6
9b13459
 
e8e4be6
 
 
 
 
 
 
 
 
9b13459
 
 
 
 
 
 
 
 
 
 
 
 
 
e8e4be6
9b13459
 
e8e4be6
 
 
 
 
 
 
 
 
9b13459
 
 
 
 
 
 
 
 
 
 
 
 
 
e8e4be6
9b13459
 
e8e4be6
 
 
 
 
 
 
 
 
9b13459
 
 
 
 
 
 
 
 
 
 
 
 
 
e8e4be6
9b13459
 
e8e4be6
 
 
 
 
 
 
 
 
9b13459
 
 
 
 
 
 
 
 
 
 
 
 
 
e8e4be6
9b13459
 
e8e4be6
 
 
 
 
 
 
 
 
9b13459
 
 
 
 
 
 
 
 
 
 
 
 
 
e8e4be6
9b13459
 
e8e4be6
 
 
 
 
 
 
 
 
9b13459
 
 
 
 
 
 
 
 
 
 
 
 
 
e8e4be6
9b13459
 
e8e4be6
 
 
 
 
 
 
 
 
9b13459
 
 
 
 
 
 
 
 
 
 
 
 
 
e8e4be6
9b13459
 
e8e4be6
 
 
1c22380
 
 
0c5e7b7
1c22380
9b13459
 
1c22380
 
 
 
 
 
 
 
 
0c5e7b7
9b13459
1c22380
 
 
 
 
 
e8e4be6
 
 
 
9b13459
e8e4be6
 
 
9b13459
 
e8e4be6
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>hf_kernels_rotary</title>

    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:ital,wght@0,100..800;1,100..800&display=swap" rel="stylesheet">

    <script>
// Iframe-friendly navigation router
        (function() {
            const isIframe = window.self !== window.top;
            if (!isIframe) return; // Only activate in iframe context

            // On load: if hash points to a different page, navigate there
            const hash = window.location.hash;
            if (hash && hash.startsWith('#/')) {
                const targetPath = hash.slice(2); // Remove '#/'
                const currentPath = window.location.pathname.split('/').pop();

                // Only navigate if we're not already on the target page
                if (targetPath !== currentPath) {
                    window.location.href = targetPath;
                    return; // Stop execution, we're navigating away
                }
            }

            // Intercept all link clicks for hash-based navigation
            document.addEventListener('click', function(e) {
                const link = e.target.closest('a');
                if (!link) return;

                const href = link.getAttribute('href');

                // Skip external links, anchors, and javascript: links
                if (!href || href.startsWith('#') || href.startsWith('http') || href.startsWith('javascript:')) {
                    return;
                }

                e.preventDefault();

                // Convert relative/absolute path to hash-based navigation
                const url = new URL(href, window.location.href);
                let fullPath = url.pathname;

                // Remove leading slash if present for cleaner paths
                if (fullPath.startsWith('/')) {
                    fullPath = fullPath.slice(1);
                }

                // Update parent URL hash
                window.location.hash = '#/' + fullPath;

                // For HTML files, navigate within iframe
                if (fullPath.endsWith('.html') || fullPath.endsWith('/')) {
                    const pathParts = fullPath.split('/').filter(p => p);
                    const targetFile = pathParts[pathParts.length - 1] || 'index.html';
                    window.location.href = targetFile;
                } else {
                    // For non-HTML files (raw .py, etc), open directly
                    window.open(href, '_blank');
                }
            });
        })();

        // Apply theme and widget visibility immediately to prevent flicker
        (function() {
            const configTheme = 'dark';
            const hasConfigUi = false;
            const configUi = hasConfigUi ? 'None' : null;
            const hasWidgetsConfig = false;
            const widgetsOn = hasWidgetsConfig ? false : true;
            let theme;
            if (configTheme === 'auto') {
                theme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
            } else {
                theme = localStorage.getItem('uvnote-theme') || configTheme;
            }
            document.documentElement.setAttribute('data-theme', theme);

            // Initialize UI theme (css theme)
            let ui = hasConfigUi ? configUi : (localStorage.getItem('uvnote-ui') || 'default');
            if (ui !== 'default' && ui !== 'none' && ui !== 'monocolor') { ui = 'default'; }
            document.documentElement.setAttribute('data-ui', ui);

            // Apply widgets visibility
            document.documentElement.setAttribute('data-widgets', widgetsOn ? 'on' : 'off');
        })();
    </script>
    <style>
:root[data-theme="light"] {
    --bg-primary: #ffffff;
    --bg-secondary: #f6f8fa;
    --bg-tertiary: #f8f9fa;
    --bg-code: #f8f9fa;
    --bg-error: #fdf2f2;
    --bg-artifact: #e6f3ff;
    --bg-artifact-hover: #d0e7ff;

    --text-primary: #333;
    --text-secondary: #656d76;
    --text-error: #c53030;
    --text-link: #0969da;

    --border-primary: #e1e5e9;
    --border-error: #e53e3e;
    --border-cell-failed: #d73a49;

    --shadow: rgba(0, 0, 0, 0.1);
}

:root[data-theme="dark"] {
    --bg-primary: #0a0a0a;
    --bg-secondary: #121212;
    --bg-tertiary: #181818;
    --bg-code: #0d0d0d;
    --bg-error: #1a0f0f;
    --bg-artifact: #151515;
    --bg-artifact-hover: #1a1a1a;

    --text-primary: #e0e0e0;
    --text-secondary: #888888;
    --text-error: #ff6b6b;
    --text-link: #64b5f6;

    --border-primary: #2a2a2a;
    --border-error: #ff6b6b;
    --border-cell-failed: #ff6b6b;

    --shadow: rgba(255, 255, 255, 0.05);
}

/* Monocolor UI theme: black/white background, all text/borders single blue */
:root[data-ui="monocolor"] {
    --mono-color: #0a66ff;
}

:root[data-ui="monocolor"][data-theme="light"] {
    --bg-primary: #ffffff;
}

:root[data-ui="monocolor"][data-theme="dark"] {
    --bg-primary: #000000;
}

:root[data-ui="monocolor"] {
    --bg-secondary: var(--bg-primary);
    --bg-tertiary: var(--bg-primary);
    --bg-code: var(--bg-primary);
    --bg-error: var(--bg-primary);
    --bg-artifact: var(--bg-primary);
    --bg-artifact-hover: var(--bg-primary);

    --text-primary: var(--mono-color);
    --text-secondary: var(--mono-color);
    --text-error: var(--mono-color);
    --text-link: var(--mono-color);

    --border-primary: var(--mono-color);
    --border-error: var(--mono-color);
    --border-cell-failed: var(--mono-color);

    --shadow: none;
}

:root[data-ui="monocolor"] a {
    color: var(--mono-color);
}

:root[data-ui="monocolor"] .menu-button,
:root[data-ui="monocolor"] .theme-toggle,
:root[data-ui="monocolor"] .reset-toggle,
:root[data-ui="monocolor"] .back-button {
    background: var(--bg-primary);
    color: var(--mono-color);
    border-color: var(--mono-color);
}

:root[data-ui="monocolor"] .menu-button:hover,
:root[data-ui="monocolor"] .theme-toggle:hover,
:root[data-ui="monocolor"] .reset-toggle:hover,
:root[data-ui="monocolor"] .back-button:hover {
    background: var(--bg-primary);
    color: var(--mono-color);
    border-color: var(--mono-color);
}

:root[data-ui="monocolor"] .menu-dropdown {
    background: var(--bg-primary);
    border-color: var(--mono-color);
    box-shadow: none;
}

:root[data-ui="monocolor"] .menu-item {
    color: var(--mono-color);
    border-bottom-color: var(--mono-color);
}

:root[data-ui="monocolor"] .system-info {
    background: var(--bg-primary);
    border-color: var(--mono-color);
}

:root[data-ui="monocolor"] .cell {
    border-color: var(--mono-color);
    background: var(--bg-primary);
}

:root[data-ui="monocolor"] .cell-header {
    background: var(--bg-primary);
    border-bottom-color: var(--mono-color);
}

:root[data-ui="monocolor"] .artifact {
    background: var(--bg-primary);
    border-color: var(--mono-color);
    color: var(--mono-color);
}

:root[data-ui="monocolor"] .artifact:hover {
    background: var(--bg-primary);
}

:root[data-ui="monocolor"] .artifact-preview img,
:root[data-ui="monocolor"] .artifact-preview svg {
    border-color: var(--mono-color);
}

:root[data-ui="monocolor"] .status-widget {
    background: var(--bg-primary);
    border-color: var(--mono-color);
    color: var(--mono-color);
}

:root[data-ui="monocolor"] .minimap,
:root[data-ui="monocolor"] .file-explorer,
:root[data-ui="monocolor"] .tools-widget {
    background: var(--bg-primary);
    border-color: var(--mono-color);
    color: var(--mono-color);
}

:root[data-ui="monocolor"] .cell-code {
    background: var(--bg-primary);
    border-bottom-color: var(--mono-color);
}

:root[data-ui="monocolor"] .tools-title,
:root[data-ui="monocolor"] .file-explorer-section-title,
:root[data-ui="monocolor"] .minimap-title {
    color: var(--mono-color);
    border-bottom-color: var(--mono-color);
}

:root[data-ui="monocolor"] .tool-button {
    background: var(--bg-primary);
    border-color: var(--mono-color);
    color: var(--mono-color);
}

:root[data-ui="monocolor"] .tool-button.active {
    border-color: var(--mono-color);
}

:root[data-ui="monocolor"] .file-explorer-item,
:root[data-ui="monocolor"] .minimap-item {
    color: var(--mono-color);
}

/* Force Pygments code to mono blue on mono bg */
:root[data-ui="monocolor"] .highlight {
    background: var(--bg-primary) !important;
    color: var(--mono-color) !important;
}

:root[data-ui="monocolor"] .highlight *,
:root[data-ui="monocolor"] .highlight .hll {
    color: var(--mono-color) !important;
    background: transparent !important;
    border-color: var(--mono-color) !important;
}

/* Default code font + metrics (overridable via frontmatter) */
:root {
    --code-font-size: 0.95rem;
    --code-line-height: 1.5;
    --code-pad-y: 0.75rem;
}

/* Minimal UI theme overrides base variables for a flatter, 90s look */
:root[data-ui="none"] {
    --bg-primary: #ffffff;
    --bg-secondary: transparent;
    --bg-tertiary: transparent;
    --bg-code: #f9f9f9;
    --bg-error: #fff0f0;
    --bg-artifact: #f0f7ff;
    --bg-artifact-hover: #e5f1ff;

    --text-primary: #000000;
    --text-secondary: #222222;
    --text-error: #a00000;
    --text-link: #0000ee;

    --border-primary: #cccccc;
    --border-error: #cc0000;
    --border-cell-failed: #cc0000;

    --shadow: none;
}

html {
    overscroll-behavior: none;
}

body {
    font-family: 'Cascadia Mono', 'Cascadia Code', 'JetBrains Mono', 'SF Mono', Monaco, 'Consolas', monospace;
    line-height: 1.4;
    max-width: 1000px;
    margin: 0 auto;
    padding: 15px;
    color: var(--text-primary);
    background: var(--bg-primary);
    transition: background-color 0.2s ease, color 0.2s ease;
    overscroll-behavior: none;
}

/* Minimal "none" UI theme overrides */
:root[data-ui="none"] body {
    font-family: 'Times New Roman', Times, serif;
    line-height: 1.5;
    max-width: 860px;
    padding: 12px;
    background: #ffffff;
    color: #000000;
    transition: none;
}

/* Two panel layout removed */

.controls {
    position: fixed;
    top: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.25rem;
    z-index: 1000;
}

.controls-buttons {
    display: flex;
    gap: 0.5rem;
}

.menu-button {
    position: relative;
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    padding: 8px 12px;
    border-radius: 2px;
    color: var(--text-secondary);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.9rem;
    user-select: none;
}

/* Keep default control styling when widgets are enabled, even in minimal UI */
:root[data-ui="none"][data-widgets="on"] .menu-button,
:root[data-ui="none"][data-widgets="on"] .theme-toggle,
:root[data-ui="none"][data-widgets="on"] .reset-toggle,
:root[data-ui="none"][data-widgets="on"] .back-button {
    background: #f6f6f6;
    border: 1px solid #cccccc;
    color: #222222;
}

.menu-button:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

/* Controls state indicator (top-right) */
/* Status widget (bottom-right) */
.status-widget {
    position: fixed;
    right: 20px;
    bottom: 20px;
    width: auto;
    max-width: 260px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: 2px;
    padding: 6px 8px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    z-index: 100;
}

.status-widget strong {
    color: var(--text-primary);
}

:root[data-ui="none"][data-widgets="on"] .status-widget {
    background: #f6f6f6;
    border-color: #ccc;
    color: #222;
}

:root[data-ui="none"][data-widgets="on"] .menu-button:hover,
:root[data-ui="none"][data-widgets="on"] .theme-toggle:hover,
:root[data-ui="none"][data-widgets="on"] .reset-toggle:hover,
:root[data-ui="none"][data-widgets="on"] .back-button:hover {
    background: #ededed;
    border-color: #bbbbbb;
    color: #000000;
}

.menu-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: 4px;
    box-shadow: 0 4px 12px var(--shadow);
    min-width: 160px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: all 0.2s ease;
    z-index: 1001;
    margin-top: 4px;
}

:root[data-ui="none"][data-widgets="on"] .menu-dropdown {
    background: #ffffff;
    border: 1px solid #cccccc;
    box-shadow: none;
}

.menu-button.active .menu-dropdown {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.menu-item {
    display: block;
    padding: 8px 12px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.85rem;
    border-bottom: 1px solid var(--border-primary);
    cursor: pointer;
}

:root[data-ui="none"] .menu-item {
    color: #000;
    border-bottom: 1px solid #eee;
}

.menu-item:last-child {
    border-bottom: none;
}

.menu-item:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.menu-checkbox {
    display: inline-block;
    width: 16px;
    font-family: monospace;
    color: var(--text-link);
}

.theme-toggle,
.reset-toggle,
.back-button {
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    padding: 8px 12px;
    border-radius: 4px;
    color: var(--text-secondary);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.9rem;
    user-select: none;
}

.back-button {
    text-decoration: none;
    display: inline-block;
}

.theme-toggle:hover,
.reset-toggle:hover,
.back-button:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

.system-info {
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: 4px;
    padding: 8px 12px;
    margin-bottom: 16px;
    font-size: 0.85em;
    color: var(--text-secondary);
}

.system-info-header {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.system-info-content {
    font-family: monospace;
}

.theme-toggle,
.reset-toggle {
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: 2px;
    /* padding: 0.4rem 0.6rem; */
    cursor: pointer;
    font-family: inherit;
    font-size: 0.8rem;
    color: var(--text-secondary);
    user-select: none;
    transition: all 0.2s ease;
    text-transform: lowercase;
    letter-spacing: 0;
}

.theme-toggle:hover,
.reset-toggle:hover {
    background: var(--bg-tertiary);
    border-color: var(--text-secondary);
    color: var(--text-primary);
}

.minimap {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 220px;
    max-height: 400px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: 2px;
    padding: 0.5rem;
    font-size: 0.7rem;
    overflow-y: auto;
    z-index: 100;
    opacity: 0.9;
    transition: opacity 0.2s ease;
}

/* Hide widgets and controls when disabled via frontmatter */
:root[data-widgets="off"] .controls,
:root[data-widgets="off"] .minimap,
:root[data-widgets="off"] .file-explorer,
:root[data-widgets="off"] .tools-widget,
:root[data-widgets="off"] .status-widget {
    display: none !important;
}

.file-explorer {
    position: fixed;
    bottom: 20px;
    /* default; JS will stack */
    right: 20px;
    left: auto;
    top: auto;
    width: 220px;
    max-height: 400px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: 2px;
    padding: 0.5rem;
    font-size: 0.7rem;
    overflow-y: auto;
    z-index: 100;
    opacity: 0.9;
    transition: opacity 0.2s ease;
}

/* Drawing overlay */
.draw-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 80;
    /* under widgets (100) and controls (1000) */
    display: block;
    pointer-events: none;
    /* enabled only when a tool is active */
}

/* Tools widget */
.tools-widget {
    position: fixed;
    bottom: 20px;
    /* default; JS will stack */
    right: 20px;
    left: auto;
    top: auto;
    width: 220px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: 2px;
    padding: 0.5rem;
    font-size: 0.7rem;
    z-index: 100;
    opacity: 0.95;
}

.tools-title {
    font-weight: bold;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    padding-bottom: 0.25rem;
    border-bottom: 1px solid var(--border-primary);
    cursor: grab;
    user-select: none;
}

.tools-row {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
}

.tool-button {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: 2px;
    padding: 0.25rem 0.4rem;
    cursor: pointer;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.75rem;
    user-select: none;
}

.tool-button:hover {
    color: var(--text-primary);
}

.tool-button.active {
    color: var(--text-primary);
    border-color: var(--text-secondary);
    background: var(--bg-secondary);
}

.minimap:hover,
.file-explorer:hover {
    opacity: 1;
}

.minimap-title {
    font-weight: bold;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    padding-bottom: 0.25rem;
    border-bottom: 1px solid var(--border-primary);
    cursor: grab;
    /* drag handle */
    user-select: none;
}

.minimap-item {
    display: block;
    color: var(--text-secondary);
    text-decoration: none;
    padding: 0.15rem 0;
    border-left: 2px solid transparent;
    padding-left: 0.5rem;
    transition: all 0.2s ease;
    cursor: pointer;
}

.minimap-item:hover {
    color: var(--text-primary);
    border-left-color: var(--text-secondary);
}

.minimap-item.active {
    color: var(--text-primary);
    border-left-color: var(--text-link);
}

.minimap-heading {
    font-weight: normal;
}

.minimap-heading.h1 {
    padding-left: 0.5rem;
}

.minimap-heading.h2 {
    padding-left: 1rem;
}

.minimap-heading.h3 {
    padding-left: 1.5rem;
}

.minimap-heading.h4 {
    padding-left: 2rem;
}

.minimap-heading.h5 {
    padding-left: 2.5rem;
}

.minimap-heading.h6 {
    padding-left: 3rem;
}

.minimap-cell {
    color: var(--text-link);
    opacity: 0.8;
    font-style: italic;
}

.minimap-cell:hover {
    opacity: 1;
}

.file-explorer-title {
    font-weight: bold;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    padding-bottom: 0.25rem;
    border-bottom: 1px solid var(--border-primary);
    cursor: grab;
    /* drag handle */
    user-select: none;
}

.file-explorer-section {
    margin-bottom: 0.75rem;
}

.file-explorer-section-title {
    font-weight: bold;
    color: var(--text-secondary);
    font-size: 0.65rem;
    margin-bottom: 0.25rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.file-explorer-item {
    display: block;
    color: var(--text-secondary);
    text-decoration: none;
    padding: 0.1rem 0;
    margin-left: 0.5rem;
    transition: color 0.2s ease;
    cursor: pointer;
    font-family: monospace;
}

.file-explorer-item:hover {
    color: var(--text-primary);
}

.file-explorer-item.script {
    color: var(--text-link);
}

.file-explorer-item.artifact {
    color: var(--text-secondary);
    opacity: 0.8;
}


/* Hide widgets on smaller screens */
@media (max-width: 768px) {

    .minimap,
    .file-explorer,
    .tools-widget {
        display: none;
    }
}

.cell {
    margin: 1rem 0;
    border: 1px solid var(--border-primary);
    border-radius: 2px;
    overflow: hidden;
    background: var(--bg-secondary);
}

:root[data-ui="none"] .cell {
    margin: 1em 0;
    border: none;
    background: transparent;
}

.cell-header {
    background: var(--bg-secondary);
    padding: 0.5rem 1rem;
    border-bottom: 1px solid var(--border-primary);
    font-family: inherit;
    font-size: 0.85rem;
}

:root[data-ui="none"] .cell-header {
    background: transparent;
    border: none;
    padding: 0;
    font-weight: bold;
}

:root[data-ui="none"] .cell-content {
    padding: 0;
}

:root[data-ui="none"] .copy-button,
:root[data-ui="none"] .collapse-indicators,
:root[data-ui="none"] .cell-meta,
:root[data-ui="none"] .cell-outputs-header {
    display: none !important;
}

:root[data-ui="none"] pre,
:root[data-ui="none"] code {
    font-family: Menlo, Monaco, 'Courier New', monospace;
}

:root[data-ui="none"] .code-content pre {
    background: #f9f9f9;
    border: 1px solid #ddd;
    padding: 8px;
}

:root[data-ui="none"] .output {
    background: transparent;
    border: none;
    padding: 0.25em 0;
}

color: var(--text-secondary);
cursor: pointer;
user-select: none;
transition: background-color 0.2s ease;
}

.cell-header:hover {
    background: var(--bg-tertiary);
}

.collapse-indicators {
    color: var(--text-secondary);
    font-size: 0.8rem;
    opacity: 0.7;
}

.collapse-indicators span:hover {
    color: var(--text-primary);
    opacity: 1;
}

.cell-code {
    display: block;
    background: var(--bg-code);
}

.cell-code.collapsed {
    display: none;
}

.cell-code pre {
    margin: 0;
    padding: 0.75rem;
    background: var(--bg-code);
    overflow-x: auto;
    color: var(--text-primary);
}

.cell-output {
    padding: 0.75rem;
    /* background: var(--bg-primary); */
    background: var(--bg-secondary);
}

.cell-output.collapsed {
    display: none;
}

.cell-stdout {
    background: var(--bg-tertiary);
    padding: 0.75rem;
    border-radius: 1px;
    /* margin: 0.25rem 0; */
    font-family: inherit;
    font-size: 0.9rem;
    white-space: pre-wrap;
    color: var(--text-primary);
}

.cell-stdout {
    background: var(--bg-tertiary);
    padding: 0.75rem;
    border-radius: 1px;
    font-family: inherit;
    font-size: 0.9rem;
    color: var(--text-primary);

    /* key bits */
    overflow: auto;
    /* show scrollbars when needed */
    max-width: 100%;
    /* respects whatever layout width you give it */
}

.cell-stdout .stdout-text {
    margin: 0;
    /* reset pre default margin */
    white-space: pre;
    /* keep line breaks, NO wrapping */
    display: inline-block;
    /* shrink-to-content */
    min-width: max-content;
    /* allow very long lines to define intrinsic width */
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    tab-size: 2;
}

.cell-stderr {
    background: var(--bg-error);
    border-left: 2px solid var(--border-error);
    padding: 1rem;
    margin: 0.5rem 0;
    font-family: inherit;
    font-size: 0.9rem;
    color: var(--text-error);
    white-space: pre-wrap;
}

.uv-install-logs {
    margin: 0.5rem 0;
}

.uv-logs-header {
    cursor: pointer;
    padding: 0.75rem;
    border-left: 3px solid var(--border-color);
    font-family: inherit;
    font-size: 0.85rem;
    color: var(--text-secondary);
    user-select: none;
}

.uv-logs-content {
    background: var(--bg-secondary);
    padding: 1rem;
    border-left: 3px solid var(--border-color);
    white-space: pre-wrap;
    font-family: monospace;
    font-size: 0.85rem;
    color: var(--text-secondary);
    overflow-x: auto;
}

.cell-artifacts {
    margin: 1rem 0;
}

.cell-artifacts h4 {
    margin: 0 0 0.5rem 0;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.artifact {
    display: inline-block;
    background: var(--bg-artifact);
    padding: 0.25rem 0.5rem;
    border-radius: 1px;
    margin: 0.25rem 0.5rem 0.25rem 0;
    font-family: inherit;
    font-size: 0.8rem;
    color: var(--text-link);
    text-decoration: none;
    transition: background-color 0.2s ease;
    border: 1px solid var(--border-primary);
}

.artifact:hover {
    background: var(--bg-artifact-hover);
}

.artifact-preview {
    margin-top: 1rem;
}

.artifact-preview img {
    max-width: 100%;
    height: auto;
    border: 1px solid var(--border-primary);
    border-radius: 1px;
}

.artifact-preview svg {
    max-width: 100%;
    height: auto;
    border: 1px solid var(--border-primary);
    border-radius: 1px;
    display: block;
}

/* Style SVG text elements */
.artifact-preview svg g {
    fill: var(--text-primary) !important;
}

/* Auto-theme SVG elements */
.artifact-preview svg {
    background: transparent;
}

/* Invert SVG images in dark mode */
:root[data-theme="dark"] .artifact-preview img[src$=".svg"] {
    filter: invert(0.9) hue-rotate(180deg);
}

/* Keep SVG images readable in monocolor mode */
:root[data-ui="monocolor"] .artifact-preview img[src$=".svg"] {
    filter: none;
}

/* CSV table styling */
.artifact-csv {
    margin-top: 1rem;
    overflow-x: auto;
}

.csv-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: 1px;
}

.csv-table th,
.csv-table td {
    padding: 0.5rem 0.75rem;
    text-align: left;
    border: 1px solid var(--border-primary);
}

.csv-table th {
    background: var(--bg-tertiary);
    font-weight: 600;
    color: var(--text-primary);
}

.csv-table tbody tr:hover {
    background: var(--bg-artifact-hover);
}

.artifact-csv-error {
    margin-top: 1rem;
    padding: 1rem;
    background: var(--bg-error);
    color: var(--text-error);
    border: 1px solid var(--border-error);
    border-radius: 1px;
}

.cell-failed {
    border-color: var(--border-cell-failed);
}

.cell-failed .cell-header {
    background: var(--bg-error);
    color: var(--text-error);
}

.cell-commented {
    opacity: 0.6;
    border-style: dashed;
}

.cell-commented .cell-header {
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-style: italic;
}

.run-btn {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    padding: 2px 6px;
    border-radius: 2px;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.75em;
    font-family: inherit;
    margin-left: 4px;
}

.run-btn:hover {
    color: var(--text-primary);
    background: var(--bg-primary);
}

.run-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.copy-btn {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    padding: 2px 6px;
    border-radius: 2px;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.75em;
    font-family: inherit;
    margin-left: 4px;
}

.copy-btn:hover {
    color: var(--text-primary);
    background: var(--bg-primary);
}

.copy-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.copy-btn.copied {
    color: #4caf50;
    background: var(--bg-primary);
    border-color: #4caf50;
    transition: all 0.2s ease;
}

.raw-btn {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    padding: 2px 6px;
    border-radius: 2px;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.75em;
    font-family: inherit;
    margin-left: 4px;
    text-decoration: none;
    display: inline-block;
}

.raw-btn:hover {
    color: var(--text-primary);
    background: var(--bg-primary);
    text-decoration: none;
}

.github-btn {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    padding: 2px 6px;
    border-radius: 2px;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.75em;
    font-family: inherit;
    margin-left: 4px;
    text-decoration: none;
    display: inline-block;
}

.github-btn:hover {
    color: var(--text-primary);
    background: var(--bg-primary);
    text-decoration: none;
}

.hf-btn {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    padding: 2px 6px;
    border-radius: 2px;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.75em;
    font-family: inherit;
    margin-left: 4px;
    text-decoration: none;
    display: inline-block;
}

.hf-btn:hover {
    color: var(--text-primary);
    background: var(--bg-primary);
    text-decoration: none;
}

.output-stale {
    opacity: 0.5;
    position: relative;
}

.output-stale::after {
    content: '⏳ updating...';
    position: absolute;
    top: 8px;
    right: 8px;
    background: var(--bg-secondary);
    padding: 4px 8px;
    border-radius: 2px;
    font-size: 0.75em;
    color: var(--text-secondary);
    border: 1px solid var(--border-primary);
}

h1,
h2,
h3,
h4,
h5,
h6 {
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
}

h1 {
    margin-top: 0;
    margin-bottom: 1rem;
}

p {
    margin: 0.75rem 0;
    color: var(--text-primary);
}

a {
    color: var(--text-link);
}

img {
    max-width: 100%;
    height: auto;
    border-radius: 1px;
    box-shadow: none;
}

pre,
code {
    font-family: 'Cascadia Mono', 'Cascadia Code', 'JetBrains Mono', 'SF Mono', Monaco, 'Consolas', monospace;
    font-size: var(--code-font-size);
}

.code-wrap {
    position: relative;
}

.code-line-highlight {
    display: none;
    position: absolute;
    left: 0;
    right: 0;
    height: 1.5em;
    background: rgba(255, 235, 170, 0.35);
    pointer-events: none;
    border-left: 3px solid #f4c542;
}

.line-number {
    cursor: pointer;
    text-decoration: none;
    color: var(--text-secondary);
    padding: 0 0.25rem;
}

.line-number.selected {
    background: rgba(255, 235, 170, 0.4);
    color: var(--text-primary);
}

/* Line numbers */
.highlight-with-lines {
    display: flex;
}

.line-numbers {
    background: var(--bg-tertiary);
    padding: var(--code-pad-y) 0.5rem;
    font-family: 'Cascadia Mono', 'Cascadia Code', 'JetBrains Mono', 'SF Mono', Monaco, 'Consolas', monospace;
    font-size: var(--code-font-size);
    line-height: var(--code-line-height);
    color: var(--text-secondary);
    user-select: none;
    text-align: right;
    border-right: 1px solid var(--border-primary);
}

.line-numbers .line-number {
    display: block;
    line-height: var(--code-line-height);
}

.highlight-with-lines .highlight {
    flex: 1;
}

.highlight .hll {
    background-color: transparent;
}

/* don't conflict with our highlight */
.highlight pre {
    white-space: pre;
    margin: 0;
    padding: var(--code-pad-y) 0.75rem;
    line-height: var(--code-line-height);
}

/* Collapsed code styling */
.cell-code.collapsed {
    display: none;
}

.cell-code.expanded {
    display: block;
}

    {
    % if config.collapse_code %
}

.cell-code {
    display: none;
}

    {
    % else %
}

.cell-code {
    display: block;
    border-bottom: 1px solid var(--border-primary);
}

    {
    % endif %
}

    {
        {
        pygments_css
    }
}

/* Ensure our code metrics override Pygments defaults */
.highlight pre {
    white-space: pre;
    margin: 0;
    padding: var(--code-pad-y) 0.75rem !important;
    line-height: var(--code-line-height) !important;
    font-size: var(--code-font-size) !important;
    font-family: 'Cascadia Mono', 'Cascadia Code', 'JetBrains Mono', 'SF Mono', Monaco, 'Consolas', monospace !important;
    border: none;
}

.line-numbers {
    line-height: var(--code-line-height) !important;
}

.line-numbers .line-number {
    line-height: var(--code-line-height) !important;
}

/* Custom CSS from frontmatter */
    {
        {
        config.custom_css
    }
}

    {
    # Override code font size from frontmatter (accept number as px) #
}

    {
    % if config.code_font_size is not none %
}

    {
    % if config.code_font_size is string %
}

:root {
    --code-font-size: {
            {
            config.code_font_size
        }
    }

    ;
}

    {
    % else %
}

:root {
    --code-font-size: {
            {
            config.code_font_size
        }
    }

    px;
}

    {
    % endif %
}

    {
    % endif %
}

/* Cursor for tools */
body[data-tool="arrow"] .main-content {
    cursor: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="%23e53935" stroke-width="2"><path d="M12 19l7-7 3 3-7 7-3-3z"/><path d="M18 13l-1.5-7.5L2 2l3.5 14.5L13 18l5-5z"/><path d="M2 2l7.586 7.586"/><circle cx="11" cy="11" r="2"/></svg>') 12 12, crosshair;
}

body[data-tool="pen"] .main-content {
    cursor: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="%23e53935" stroke-width="2"><path d="M12 19l7-7 3 3-7 7-3-3z"/><path d="M18 13l-1.5-7.5L2 2l3.5 14.5L13 18l5-5z"/><circle cx="4" cy="20" r="2" fill="%23e53935"/></svg>') 4 20, pointer;
}

body[data-tool="eraser"] .main-content {
    cursor: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="%23e53935" stroke-width="2"><path d="M20 20H7l-7-7 7-7h13v14z"/><path d="M13 13l7-7"/><path d="M13 13L9 9"/></svg>') 12 12, auto;
}

/* Color picker styles */
.tools-section-title {
    font-weight: bold;
    color: var(--text-secondary);
    font-size: 0.65rem;
    margin: 0.75rem 0 0.5rem 0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.color-row {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 0.25rem;
    margin-bottom: 0.5rem;
}

.color-swatch {
    width: 18px;
    height: 18px;
    border: 2px solid var(--border-primary);
    border-radius: 3px;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.color-swatch:hover {
    transform: scale(1.1);
    border-color: var(--text-secondary);
}

.color-swatch.selected {
    border-color: var(--text-primary);
    box-shadow: 0 0 0 2px var(--text-link);
}

.color-swatch.selected::after {
    content: '✓';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 10px;
    font-weight: bold;
    text-shadow: 1px 1px 1px black;
}

.color-input {
    width: 24px;
    height: 24px;
    border: 2px solid var(--border-primary);
    border-radius: 3px;
    cursor: pointer;
    background: none;
    padding: 0;
    grid-column: span 2;
    justify-self: center;
}

.color-input:hover {
    border-color: var(--text-secondary);
}

/* Thickness slider styles */
.thickness-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.thickness-slider {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 4px;
    background: var(--border-primary);
    border-radius: 2px;
    outline: none;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.thickness-slider:hover {
    opacity: 1;
}

.thickness-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 12px;
    height: 12px;
    background: var(--text-link);
    border-radius: 50%;
    cursor: pointer;
}

.thickness-slider::-moz-range-thumb {
    width: 12px;
    height: 12px;
    background: var(--text-link);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

.thickness-value {
    font-size: 0.7rem;
    color: var(--text-secondary);
    min-width: 20px;
    text-align: right;
}

.highlight {
    background: none !important;
}

/* Loading animations */
.loading-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--border-primary);
    border-radius: 50%;
    border-top-color: var(--text-link);
    animation: spin 1s linear infinite;
    margin-right: 8px;
    vertical-align: middle;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loading-skeleton {
    display: inline-block;
    background: var(--bg-tertiary);
    background: linear-gradient(90deg,
            var(--bg-tertiary) 25%,
            var(--bg-secondary) 50%,
            var(--bg-tertiary) 75%);
    background-size: 200% 100%;
    animation: loading-shimmer 2s ease-in-out infinite;
    border-radius: 2px;
    height: 1em;
    width: 80px;
    vertical-align: middle;
}

@keyframes loading-shimmer {
    0% {
        background-position: -200% 0;
    }

    100% {
        background-position: 200% 0;
    }
}

/* Loading state for cell output */
.cell-output:has(.loading-spinner) {
    opacity: 0.7;
    background: var(--bg-secondary);
    /* border-left: 3px solid var(--text-link); */
}
    </style>
    <script>
// --- Drag utilities ---
        function clamp(val, min, max) { return Math.max(min, Math.min(max, val)); }

        function restorePosition(el, storageKey) {
            try {
                const raw = localStorage.getItem(storageKey);
                if (!raw) return;
                const pos = JSON.parse(raw);
                if (typeof pos.left === 'number' && typeof pos.top === 'number') {
                    el.style.left = pos.left + 'px';
                    el.style.top = pos.top + 'px';
                    el.style.right = 'auto';
                    el.style.bottom = 'auto';
                }
            } catch (_) {}
        }

        function savePosition(el, storageKey) {
            try {
                const left = parseFloat(el.style.left || 'NaN');
                const top = parseFloat(el.style.top || 'NaN');
                if (!Number.isNaN(left) && !Number.isNaN(top)) {
                    localStorage.setItem(storageKey, JSON.stringify({ left, top }));
                }
            } catch (_) {}
        }


        function makeDraggable(el, storageKey, handleEl) {
            let dragging = false;
            let startX = 0, startY = 0; // cursor
            let origLeft = 0, origTop = 0; // element

            const onMove = (e) => {
                if (!dragging) return;
                const clientX = e.touches ? e.touches[0].clientX : e.clientX;
                const clientY = e.touches ? e.touches[0].clientY : e.clientY;
                const dx = clientX - startX;
                const dy = clientY - startY;
                const w = el.offsetWidth;
                const h = el.offsetHeight;
                const maxX = window.innerWidth - w;
                const maxY = window.innerHeight - h;
                const newLeft = clamp(origLeft + dx, 0, maxX);
                const newTop = clamp(origTop + dy, 0, maxY);
                el.style.left = newLeft + 'px';
                el.style.top = newTop + 'px';
                el.style.right = 'auto';
                el.style.bottom = 'auto';
            };

            const endDrag = () => {
                if (!dragging) return;
                dragging = false;
                document.removeEventListener('mousemove', onMove);
                document.removeEventListener('mouseup', endDrag);
                document.removeEventListener('touchmove', onMove);
                document.removeEventListener('touchend', endDrag);
                handleEl && (handleEl.style.cursor = 'grab');
                savePosition(el, storageKey);
                // ensure no-overlap constraint after a drag
                try { layoutWidgetsStackedBottomRight(); } catch (_) {}
            };

            const startDrag = (e) => {
                // Start from element's current on-screen rect
                const elRect = el.getBoundingClientRect();
                el.style.left = elRect.left + 'px';
                el.style.top = elRect.top + 'px';
                el.style.right = 'auto';
                el.style.bottom = 'auto';

                dragging = true;
                startX = e.touches ? e.touches[0].clientX : e.clientX;
                startY = e.touches ? e.touches[0].clientY : e.clientY;
                origLeft = elRect.left;
                origTop = elRect.top;

                document.addEventListener('mousemove', onMove);
                document.addEventListener('mouseup', endDrag);
                document.addEventListener('touchmove', onMove, { passive: false });
                document.addEventListener('touchend', endDrag);
                handleEl && (handleEl.style.cursor = 'grabbing');
                e.preventDefault();
            };

            (handleEl || el).addEventListener('mousedown', startDrag);
            (handleEl || el).addEventListener('touchstart', startDrag, { passive: false });

            // Apply any saved position on init
            restorePosition(el, storageKey);
        }
        function toggleCell(cellId) {
            const codeElement = document.getElementById('code-' + cellId);
            const outputElement = document.getElementById('output-' + cellId);
            
            if (codeElement) {
                codeElement.classList.toggle('collapsed');
            }
            if (outputElement) {
                outputElement.classList.toggle('collapsed');
            }
            
            updateIndicators(cellId);
            encodeToolStateToUrl();
        }
        
        function toggleCode(cellId) {
            const codeElement = document.getElementById('code-' + cellId);
            if (codeElement) {
                codeElement.classList.toggle('collapsed');
                updateIndicators(cellId);
                encodeToolStateToUrl();
            }
        }
        
        function toggleOutput(cellId) {
            const outputElement = document.getElementById('output-' + cellId);
            if (outputElement) {
                outputElement.classList.toggle('collapsed');
                updateIndicators(cellId);
                encodeToolStateToUrl();
            }
        }

        function toggleUvLogs(headerElement) {
            const contentElement = headerElement.nextElementSibling;
            if (contentElement) {
                const isCollapsed = contentElement.style.display === 'none';
                contentElement.style.display = isCollapsed ? 'block' : 'none';
                headerElement.textContent = isCollapsed ? '▼ UV Install Logs' : '▶ UV Install Logs';

                // Update the header indicator if it exists
                const uvLogsDiv = headerElement.parentElement;
                if (uvLogsDiv && uvLogsDiv.id && uvLogsDiv.id.startsWith('uv-logs-')) {
                    const cellId = uvLogsDiv.id.replace('uv-logs-', '');
                    const indicatorElement = document.getElementById('uv-indicator-' + cellId);
                    if (indicatorElement) {
                        indicatorElement.textContent = isCollapsed ? '▼ uv-logs' : '▶ uv-logs';
                    }
                }
            }
        }

        function toggleUvLogsFromHeader(cellId) {
            const uvLogsElement = document.getElementById('uv-logs-' + cellId);
            const indicatorElement = document.getElementById('uv-indicator-' + cellId);
            if (uvLogsElement) {
                const headerElement = uvLogsElement.querySelector('.uv-logs-header');
                const contentElement = uvLogsElement.querySelector('.uv-logs-content');
                if (contentElement && headerElement) {
                    const isCollapsed = contentElement.style.display === 'none';
                    contentElement.style.display = isCollapsed ? 'block' : 'none';
                    headerElement.textContent = isCollapsed ? '▼ UV Install Logs' : '▶ UV Install Logs';
                    if (indicatorElement) {
                        indicatorElement.textContent = isCollapsed ? '▼ uv-logs' : '▶ uv-logs';
                    }
                }
            }
        }
        
        function updateIndicators(cellId) {
            const codeElement = document.getElementById('code-' + cellId);
            const outputElement = document.getElementById('output-' + cellId);
            const indicators = document.querySelector(`[onclick*="${cellId}"]`)?.closest('.cell-header')?.querySelector('.collapse-indicators');
            
            if (indicators) {
                const codeCollapsed = codeElement && codeElement.classList.contains('collapsed');
                const outputCollapsed = outputElement && outputElement.classList.contains('collapsed');
                
                const codeIcon = codeCollapsed ? '▶' : '▼';
                const outputIcon = outputCollapsed ? '▶' : '▼';
                
                const codeSpan = indicators.querySelector('[onclick*="toggleCode"]');
                const outputSpan = indicators.querySelector('[onclick*="toggleOutput"]');
                
                if (codeSpan) codeSpan.innerHTML = `${codeIcon} code`;
                if (outputSpan) outputSpan.innerHTML = `${outputIcon} output`;
            }
        }
        
        function toggleTheme() {
            const html = document.documentElement;
            const currentTheme = html.getAttribute('data-theme');
            const newTheme = currentTheme === 'dark' ? 'light' : 'dark';
            html.setAttribute('data-theme', newTheme);
            localStorage.setItem('uvnote-theme', newTheme);
            updateThemeIcon();
            updateUiDebug();
        }
        
        // Two panel code removed
        
        function updateThemeIcon() {
            const theme = document.documentElement.getAttribute('data-theme');
            const toggle = document.querySelector('.theme-toggle');
            if (toggle) {
                toggle.textContent = theme === 'dark' ? 'light' : 'dark';
            }
        }
        function setUiTheme(newUi) {
            if (newUi !== 'default' && newUi !== 'none' && newUi !== 'monocolor') return;
            const html = document.documentElement;
            html.setAttribute('data-ui', newUi);
            try { localStorage.setItem('uvnote-ui', newUi); } catch (_) {}
            updateUiMenu();
            updateUiDebug();
        }
        function updateUiMenu() {
            const ui = document.documentElement.getAttribute('data-ui') || 'default';
            const checks = {
                default: document.getElementById('checkbox-ui-default'),
                none: document.getElementById('checkbox-ui-none'),
                monocolor: document.getElementById('checkbox-ui-monocolor')
            };
            if (checks.default) checks.default.textContent = ui === 'default' ? '☑' : '☐';
            if (checks.none) checks.none.textContent = ui === 'none' ? '☑' : '☐';
            if (checks.monocolor) checks.monocolor.textContent = ui === 'monocolor' ? '☑' : '☐';
        }

        function updateUiDebug() {
            const ui = document.documentElement.getAttribute('data-ui') || 'default';
            const color = document.documentElement.getAttribute('data-theme') || 'light';
            const el = document.getElementById('ui-debug');
            if (el) {
                el.textContent = `UI: ${ui} | Color: ${color}`;
            }
        }

        // Line selection and deep-linking
        function clearLineSelections() {
            try {
                document.querySelectorAll('.code-line-highlight').forEach(el => { el.style.display = 'none'; });
                document.querySelectorAll('.line-number.selected').forEach(el => el.classList.remove('selected'));
            } catch (_) {}
        }

        let _selection = null; // { cellId, a, b }

        function clearSelection(updateUrl) {
            clearLineSelections();
            _selection = null;
            if (updateUrl) {
                try {
                    const url = new URL(window.location.href);
                    url.searchParams.delete('cell');
                    url.searchParams.delete('line');
                    history.replaceState(null, '', url.toString());
                } catch (_) {}
            }
            updateStateIndicator();
        }

        function selectCellLine(cellId, line, updateUrl) {
            try {
                // Ensure only one selection across the whole document
                clearLineSelections();
                const codeBox = document.getElementById(`code-${cellId}`);
                if (!codeBox) return;
                const pre = codeBox.querySelector('.highlight pre');
                const overlay = document.getElementById(`line-highlight-${cellId}`);
                const numbers = document.getElementById(`lines-${cellId}`);
                if (!pre || !overlay) return;

                // Measure line height directly from computed style
                const preStyle = getComputedStyle(pre);
                const padTop = parseFloat(preStyle.paddingTop || '0');
                const lh = parseFloat(preStyle.lineHeight || '20');

                // Position overlay
                overlay.style.display = 'block';
                overlay.style.height = `${lh}px`;
                overlay.style.top = `${pre.offsetTop + padTop + (line - 1) * lh}px`;

                // Update selected class in line numbers
                if (numbers) {
                    numbers.querySelectorAll('.line-number').forEach(a => a.classList.remove('selected'));
                    const sel = numbers.querySelector(`.line-number[data-line="${line}"]`);
                    if (sel) sel.classList.add('selected');
                }

                if (updateUrl) {
                    const url = new URL(window.location.href);
                    url.searchParams.set('cell', cellId);
                    url.searchParams.set('line', String(line));
                    history.replaceState(null, '', url.toString());
                }
                _selection = { cellId, a: line, b: line };
                updateStateIndicator();
            } catch (e) { console.warn('selectCellLine error', e); }
        }

        function selectCellLines(cellId, startLine, endLine, updateUrl) {
            try {
                // normalize order
                const a = Math.min(startLine, endLine);
                const b = Math.max(startLine, endLine);
                clearLineSelections();
                const codeBox = document.getElementById(`code-${cellId}`);
                if (!codeBox) return;
                const pre = codeBox.querySelector('.highlight pre');
                const overlay = document.getElementById(`line-highlight-${cellId}`);
                const numbers = document.getElementById(`lines-${cellId}`);
                if (!pre || !overlay) return;

                const preStyle = getComputedStyle(pre);
                const padTop = parseFloat(preStyle.paddingTop || '0');
                const lh = parseFloat(preStyle.lineHeight || '20');

                overlay.style.display = 'block';
                overlay.style.top = `${pre.offsetTop + padTop + (a - 1) * lh}px`;
                overlay.style.height = `${(b - a + 1) * lh}px`;

                if (numbers) {
                    numbers.querySelectorAll('.line-number').forEach(a => a.classList.remove('selected'));
                    for (let i = a; i <= b; i++) {
                        const el = numbers.querySelector(`.line-number[data-line="${i}"]`);
                        if (el) el.classList.add('selected');
                    }
                }

                if (updateUrl) {
                    const url = new URL(window.location.href);
                    url.searchParams.set('cell', cellId);
                    if (a === b) url.searchParams.set('line', String(a));
                    else url.searchParams.set('line', `${a}-${b}`);
                    history.replaceState(null, '', url.toString());
                }
                _selection = { cellId, a, b };
                updateStateIndicator();
            } catch (e) { console.warn('selectCellLines error', e); }
        }

        // Drag-to-select support on line numbers
        let _lineDrag = { active: false, cellId: null, start: 0 };
        function onLineNumberMouseDown(e) {
            const a = e.target.closest('.line-number');
            if (!a) return;
            e.preventDefault();
            const cellId = a.dataset.cell;
            const line = parseInt(a.dataset.line || '1', 10) || 1;
            // Toggle off if this exact single line is already the only selection
            const numbers = document.getElementById(`lines-${cellId}`);
            if (numbers) {
                const selected = Array.from(numbers.querySelectorAll('.line-number.selected')).map(n => parseInt(n.dataset.line||'0',10)).filter(Boolean);
                if (selected.length === 1 && selected[0] === line) {
                    clearSelection(true);
                    return;
                }
            }
            _lineDrag.active = true;
            _lineDrag.cellId = cellId;
            _lineDrag.start = line;
            selectCellLines(_lineDrag.cellId, _lineDrag.start, _lineDrag.start, false);
        }
        function onDocMouseMove(e) {
            if (!_lineDrag.active) return;
            const el = document.elementFromPoint(e.clientX, e.clientY);
            if (!el) return;
            const a = el.closest && el.closest('.line-number');
            if (!a) return;
            if (a.dataset.cell !== _lineDrag.cellId) return;
            const cur = parseInt(a.dataset.line || '1', 10) || 1;
            selectCellLines(_lineDrag.cellId, _lineDrag.start, cur, false);
        }
        function onDocMouseUp(e) {
            if (!_lineDrag.active) return;
            const last = document.querySelector('.line-number.selected:last-of-type');
            // finalize URL using the current selected range
            const numbers = document.getElementById(`lines-${_lineDrag.cellId}`);
            if (numbers) {
                const selected = Array.from(numbers.querySelectorAll('.line-number.selected')).map(n => parseInt(n.dataset.line||'0',10)).filter(Boolean);
                if (selected.length) {
                    const a = Math.min(...selected); const b = Math.max(...selected);
                    selectCellLines(_lineDrag.cellId, a, b, true);
                }
            }
            _lineDrag.active = false; _lineDrag.cellId = null; _lineDrag.start = 0;
        }

        function applyLocationFromUrl() {
            try {
                const url = new URL(window.location.href);
                const cell = url.searchParams.get('cell');
                const lineParam = url.searchParams.get('line');
                if (cell && lineParam) {
                    if (lineParam.includes('-')) {
                        const [a, b] = lineParam.split('-').map(x => parseInt(x, 10));
                        if (!Number.isNaN(a) && !Number.isNaN(b)) selectCellLines(cell, a, b, false);
                    } else {
                        const l = parseInt(lineParam, 10);
                        if (!Number.isNaN(l)) selectCellLine(cell, l, false);
                    }
                }
                
                // Apply tool parameters from URL
                applyToolsFromUrl(url.searchParams);
                
                // Cell states will be applied later in DOMContentLoaded with proper timing
                const encodedCellStates = url.searchParams.get('cells');
                console.log('Encoded cell states from URL:', encodedCellStates);
            } catch (_) {}
        }
        
        function applyToolsFromUrl(params) {
            try {
                // Check if tools widget should be shown
                const showTools = params.get('tools');
                if (showTools === '1') {
                    // Mark that tool was loaded from URL
                    _urlLoadedTool = true;
                    
                    // Apply color
                    const color = params.get('color');
                    if (color && /^[0-9a-fA-F]{6}$/.test(color)) {
                        setStoredArrowColor('#' + color);
                    }
                    
                    // Apply thickness
                    const thickness = params.get('thickness');
                    if (thickness) {
                        const value = parseInt(thickness, 10);
                        if (value >= 1 && value <= 10) {
                            setStoredLineThickness(value);
                        }
                    }
                    
                    // Don't override fadeout time for URL-loaded tools - let individual shapes decide
                    
                    // Load shapes from URL
                    const encodedShapes = params.get('shapes');
                    if (encodedShapes) {
                        const decodedShapes = decodeShapesFromUrl(encodedShapes);
                        if (decodedShapes.length > 0) {
                            _shapes = decodedShapes;
                            saveShapes();
                            // Trigger render after overlay is initialized
                            setTimeout(() => {
                                renderOverlay();
                            }, 300);
                        }
                    }
                    
                    // Wait for widgets to be initialized before showing tools
                    setTimeout(() => {
                        const toolsWidget = document.querySelector('.tools-widget');
                        const checkbox = document.getElementById('checkbox-tools');
                        if (toolsWidget && checkbox) {
                            toolsWidget.style.display = 'block';
                            checkbox.textContent = '☑';
                            localStorage.setItem('uvnote-widget-tools', 'visible');
                        }
                        
                        // Apply active tool
                        const activeTool = params.get('tool');
                        if (activeTool && ['arrow', 'pen', 'eraser', 'spotlight'].includes(activeTool)) {
                            const toolBtn = Array.from(document.querySelectorAll('.tool-button')).find(btn => btn.textContent === activeTool);
                            if (toolBtn) {
                                toolBtn.click();
                            }
                        }
                        
                        // Re-layout widgets after showing tools
                        layoutWidgetsStackedBottomRight();
                    }, 200);
                }
            } catch (_) {}
        }
        
        function captureInitialCellStates() {
            const cells = document.querySelectorAll('.cell');
            cells.forEach(cell => {
                const cellId = cell.id.replace('cell-', '');
                const codeEl = document.getElementById('code-' + cellId);
                const outputEl = document.getElementById('output-' + cellId);
                
                if (codeEl || outputEl) {
                    const state = {};
                    if (codeEl) {
                        state.c = codeEl.classList.contains('collapsed') ? 0 : 1;
                    }
                    if (outputEl) {
                        state.o = outputEl.classList.contains('collapsed') ? 0 : 1;
                    }
                    _initialCellStates[cellId] = state;
                }
            });
            console.log('Captured initial cell states:', _initialCellStates);
        }

        function encodeCellStatesToUrl() {
            // Get all cells and their collapse states
            const cells = document.querySelectorAll('.cell');
            const cellStates = {};
            
            console.log('Found cells:', cells.length);
            
            cells.forEach(cell => {
                const cellId = cell.id.replace('cell-', '');
                const codeEl = document.getElementById('code-' + cellId);
                const outputEl = document.getElementById('output-' + cellId);
                const initialState = _initialCellStates[cellId] || {};
                
                console.log(`Encoding cell ${cellId}:`, {
                    codeEl: !!codeEl,
                    outputEl: !!outputEl,
                    codeCollapsed: codeEl ? codeEl.classList.contains('collapsed') : 'N/A',
                    outputCollapsed: outputEl ? outputEl.classList.contains('collapsed') : 'N/A',
                    initialState: initialState
                });
                
                if (codeEl || outputEl) {
                    const state = {};
                    let hasChanges = false;
                    
                    if (codeEl) {
                        const currentCodeState = codeEl.classList.contains('collapsed') ? 0 : 1;
                        const initialCodeState = initialState.c;
                        // Only encode if different from initial state
                        if (initialCodeState !== undefined && currentCodeState !== initialCodeState) {
                            state.c = currentCodeState;
                            hasChanges = true;
                        }
                    }
                    
                    if (outputEl) {
                        const currentOutputState = outputEl.classList.contains('collapsed') ? 0 : 1;
                        const initialOutputState = initialState.o;
                        // Only encode if different from initial state
                        if (initialOutputState !== undefined && currentOutputState !== initialOutputState) {
                            state.o = currentOutputState;
                            hasChanges = true;
                        }
                    }
                    
                    // Only include cell if it has changes from initial state
                    if (hasChanges) {
                        cellStates[cellId] = state;
                        console.log(`Added cell ${cellId}:`, state);
                    }
                }
            });
            
            console.log('Final cell states to encode:', cellStates);
            
            // Return empty string if no changed cells
            if (Object.keys(cellStates).length === 0) return '';
            
            // Encode as compact base64 string
            const encoded = btoa(JSON.stringify(cellStates));
            console.log('Encoded cell states:', encoded);
            return encoded;
        }
        
        function decodeCellStatesFromUrl(encodedStates) {
            if (!encodedStates) return {};
            
            try {
                return JSON.parse(atob(encodedStates));
            } catch (e) {
                console.error('Failed to decode cell states:', e);
                return {};
            }
        }
        
        function applyCellStatesFromUrl(cellStates) {
            console.log('Applying cell states from URL:', cellStates);
            Object.entries(cellStates).forEach(([cellId, state]) => {
                const codeEl = document.getElementById('code-' + cellId);
                const outputEl = document.getElementById('output-' + cellId);
                
                console.log(`Cell ${cellId}:`, {
                    codeEl: !!codeEl,
                    outputEl: !!outputEl,
                    state: state
                });
                
                if (codeEl && state.c !== undefined) {
                    if (state.c === 0) {
                        codeEl.classList.add('collapsed');
                        console.log(`Collapsed code for cell ${cellId}`, {
                            hasCollapsedClass: codeEl.classList.contains('collapsed'),
                            computedDisplay: getComputedStyle(codeEl).display,
                            classList: Array.from(codeEl.classList),
                            elementId: codeEl.id
                        });
                    } else {
                        codeEl.classList.remove('collapsed');
                        codeEl.classList.add('expanded'); // Explicitly add expanded class
                        console.log(`Expanded code for cell ${cellId}`, {
                            hasCollapsedClass: codeEl.classList.contains('collapsed'),
                            hasExpandedClass: codeEl.classList.contains('expanded'),
                            computedDisplay: getComputedStyle(codeEl).display,
                            classList: Array.from(codeEl.classList),
                            elementId: codeEl.id
                        });
                    }
                }
                
                if (outputEl && state.o !== undefined) {
                    if (state.o === 0) {
                        outputEl.classList.add('collapsed');
                        console.log(`Collapsed output for cell ${cellId}`);
                    } else {
                        outputEl.classList.remove('collapsed');
                        console.log(`Expanded output for cell ${cellId}`);
                    }
                }
                
                // Update visual indicators and force style recalculation
                try {
                    updateIndicators(cellId);
                    // Force browser to recalculate styles
                    if (codeEl) {
                        codeEl.offsetHeight; // Force reflow
                        console.log(`After indicators update - code visible: ${getComputedStyle(codeEl).display !== 'none'}`);
                    }
                    if (outputEl) {
                        outputEl.offsetHeight; // Force reflow
                        console.log(`After indicators update - output visible: ${getComputedStyle(outputEl).display !== 'none'}`);
                    }
                } catch (e) {
                    console.error(`Error updating indicators for cell ${cellId}:`, e);
                }
            });
        }

        function encodeShapesToUrl() {
            // Encode shapes as compact base64 string
            if (_shapes.length === 0) return '';
            
            const shapeData = _shapes.map(shape => {
                const baseData = {
                    ct: shape.createdAt, // creation timestamp
                    fo: shape.fadeoutTime || getFadeoutTime() // fadeout time for this shape
                };
                
                if (shape.type === 'arrow') {
                    return {
                        ...baseData,
                        t: 'a',
                        x1: Math.round(shape.x1),
                        y1: Math.round(shape.y1),
                        x2: Math.round(shape.x2),
                        y2: Math.round(shape.y2),
                        c: shape.color.substring(1), // remove #
                        w: shape.width
                    };
                } else if (shape.type === 'pen') {
                    return {
                        ...baseData,
                        t: 'p',
                        pts: shape.points.map(p => [Math.round(p.x), Math.round(p.y)]),
                        c: shape.color.substring(1),
                        w: shape.width
                    };
                } else if (shape.type === 'spotlight') {
                    return {
                        ...baseData,
                        t: 's',
                        x: Math.round(shape.x),
                        y: Math.round(shape.y),
                        r: Math.round(shape.radius)
                    };
                }
            }).filter(Boolean);
            
            return btoa(JSON.stringify(shapeData));
        }
        
        function decodeShapesFromUrl(encodedShapes) {
            if (!encodedShapes) return [];
            
            try {
                const shapeData = JSON.parse(atob(encodedShapes));
                return shapeData.map(data => {
                    const base = {
                        createdAt: data.ct || Date.now(), // use encoded timestamp or current time
                        fadeoutTime: data.fo || 0, // use encoded fadeout time or 0 (never fade)
                        opacity: 1.0
                    };
                    
                    if (data.t === 'a') {
                        return {
                            ...base,
                            type: 'arrow',
                            x1: data.x1,
                            y1: data.y1,
                            x2: data.x2,
                            y2: data.y2,
                            color: '#' + data.c,
                            width: data.w
                        };
                    } else if (data.t === 'p') {
                        return {
                            ...base,
                            type: 'pen',
                            points: data.pts.map(([x, y]) => ({ x, y })),
                            color: '#' + data.c,
                            width: data.w
                        };
                    } else if (data.t === 's') {
                        return {
                            ...base,
                            type: 'spotlight',
                            x: data.x,
                            y: data.y,
                            radius: data.r,
                            color: '#000000'
                        };
                    }
                }).filter(Boolean);
            } catch (e) {
                console.error('Failed to decode shapes:', e);
                return [];
            }
        }
        
        function encodeToolStateToUrl() {
            // Don't update URL during initialization
            if (_isInitializing) {
                return window.location.href;
            }
            
            const params = new URLSearchParams(window.location.search);
            
            // Check if tools widget is visible and has an active tool
            const toolsWidget = document.querySelector('.tools-widget');
            const activeTool = document.body.dataset.tool;
            const hasActiveTool = activeTool && activeTool !== 'none';
            const toolsWidgetVisible = toolsWidget && getComputedStyle(toolsWidget).display !== 'none';
            
            // Always handle shapes regardless of tool state
            const encodedShapes = encodeShapesToUrl();
            if (encodedShapes) {
                params.set('shapes', encodedShapes);
            } else {
                params.delete('shapes');
            }
            
            // Always preserve existing cell states from URL if present
            const existingCellStates = params.get('cells');
            if (existingCellStates) {
                // Keep existing cell states - don't re-encode from DOM
                params.set('cells', existingCellStates);
            } else {
                // Only encode new cell states if none exist in URL
                const encodedCellStates = encodeCellStatesToUrl();
                if (encodedCellStates) {
                    params.set('cells', encodedCellStates);
                }
            }
            
            if (toolsWidgetVisible && hasActiveTool) {
                // Include tool params when widget is visible AND tool is active
                params.set('tools', '1');
                params.set('tool', activeTool);
                
                // Get color (without # prefix)
                const color = getArrowColor();
                if (color && color.startsWith('#')) {
                    params.set('color', color.substring(1));
                }
                
                // Get thickness
                const thickness = getLineThickness();
                params.set('thickness', thickness.toString());
            } else {
                // Remove tool state params but keep shapes
                params.delete('tools');
                params.delete('tool');
                params.delete('color');
                params.delete('thickness');
                params.delete('fadeout');
            }
            
            // Update URL without reloading
            const newUrl = window.location.pathname + (params.toString() ? '?' + params.toString() : '') + window.location.hash;
            window.history.replaceState(null, '', newUrl);
            
            return window.location.href;
        }

        function resetLayout() {
            try {
                // Clear all uvnote-* keys
                const allKeys = Object.keys(localStorage);
                const uvnoteKeys = allKeys.filter(key => key.startsWith('uvnote-'));
                uvnoteKeys.forEach(k => localStorage.removeItem(k));
            } catch (_) {}
            
            // Clear any active selection and remove URL params
            try { clearSelection(true); } catch(_) {}
            // Reset active tool if any
            try { window.setActiveTool('none'); } catch(_) {}
            // Clear shapes
            try { _shapes = []; saveShapes(); } catch(_) {}
            // Reset URL-loaded tool flag
            try { _urlLoadedTool = false; } catch(_) {}
            // Reset all cells to expanded state
            try {
                const cells = document.querySelectorAll('.cell');
                cells.forEach(cell => {
                    const cellId = cell.id.replace('cell-', '');
                    const codeEl = document.getElementById('code-' + cellId);
                    const outputEl = document.getElementById('output-' + cellId);
                    if (codeEl) codeEl.classList.remove('collapsed');
                    if (outputEl) outputEl.classList.remove('collapsed');
                    updateIndicators(cellId);
                });
            } catch(_) {}
            
            // Clear ALL URL parameters and reload with clean URL
            try {
                const cleanUrl = window.location.pathname + window.location.hash;
                window.location.href = cleanUrl; // Use window.location.href instead of history.replaceState + reload
            } catch (_) {
                // Fallback - reload current page
                location.reload();
            }
        }

        function toggleMenu() {
            const menuButton = document.querySelector('.menu-button');
            if (menuButton) {
                menuButton.classList.toggle('active');
            }
        }

        function toggleWidget(widgetName) {
            let widget;
            let checkbox;
            
            // Close the menu first
            const menuButton = document.querySelector('.menu-button');
            if (menuButton) {
                menuButton.classList.remove('active');
            }
            
            switch(widgetName) {
                case 'tools':
                    widget = document.querySelector('.tools-widget');
                    checkbox = document.getElementById('checkbox-tools');
                    break;
                case 'file-explorer':
                    widget = document.querySelector('.file-explorer');
                    checkbox = document.getElementById('checkbox-file-explorer');
                    break;
                case 'minimap':
                    widget = document.querySelector('.minimap');
                    checkbox = document.getElementById('checkbox-minimap');
                    break;
                case 'status':
                    widget = document.querySelector('.status-widget');
                    checkbox = document.getElementById('checkbox-status');
                    break;
                default:
                    return;
            }
            
            if (widget && checkbox) {
                const isVisible = getComputedStyle(widget).display !== 'none';
                widget.style.display = isVisible ? 'none' : 'block';
                checkbox.textContent = isVisible ? '☐' : '☑';
                
                // Save state to localStorage
                try {
                    localStorage.setItem(`uvnote-widget-${widgetName}`, isVisible ? 'hidden' : 'visible');
                } catch (_) {}
                
                // Re-layout widgets after visibility change
                try { 
                    layoutWidgetsStackedBottomRight(); 
                } catch (_) {}
                
                // Update URL when tools widget visibility changes
                if (widgetName === 'tools') {
                    encodeToolStateToUrl();
                }
            }
        }
        
        function initializeWidgetVisibility() {
            const widgets = [
                { name: 'tools', selector: '.tools-widget' },
                { name: 'file-explorer', selector: '.file-explorer' },
                { name: 'minimap', selector: '.minimap' },
                { name: 'status', selector: '.status-widget' }
            ];
            
            widgets.forEach(({ name, selector }) => {
                const defaultState = name === 'status' ? 'visible' : 'hidden';
                const savedState = localStorage.getItem(`uvnote-widget-${name}`) || defaultState;
                const widget = document.querySelector(selector);
                const checkbox = document.getElementById(`checkbox-${name}`);
                
                if (widget && checkbox) {
                    const isVisible = savedState === 'visible';
                    widget.style.display = isVisible ? 'block' : 'none';
                    checkbox.textContent = isVisible ? '☑' : '☐';
                }
            });
        }

        // Close menu when clicking outside
        document.addEventListener('click', function(event) {
            const menuButton = document.querySelector('.menu-button');
            // Don't close if clicking on a menu item (let the item handler close it)
            if (menuButton && !menuButton.contains(event.target)) {
                menuButton.classList.remove('active');
            }
        });

        // Layout: stack widgets bottom-right and equalize widths
        function hasCustomWidgetPositions() {
            try {
                return (
                    localStorage.getItem('uvnote-minimap-pos') ||
                    localStorage.getItem('uvnote-file-explorer-pos') ||
                    localStorage.getItem('uvnote-tools-pos')
                );
            } catch (_) { return false; }
        }

        function rectsOverlap(r1, r2) {
            return !(r1.right <= r2.left || r2.right <= r1.left || r1.bottom <= r2.top || r2.bottom <= r1.top);
        }

        function widgetsOverlap(widgets) {
            for (let i = 0; i < widgets.length; i++) {
                const a = widgets[i];
                const ra = a.getBoundingClientRect();
                for (let j = i + 1; j < widgets.length; j++) {
                    const b = widgets[j];
                    const rb = b.getBoundingClientRect();
                    if (rectsOverlap(ra, rb)) return true;
                }
            }
            return false;
        }

        function applyStackLayout(widgets, order) {
            if (!widgets.length) return;
            // Fixed equal width
            const fixedWidth = 220;
            widgets.forEach(el => { el.style.width = fixedWidth + 'px'; });

            // Fit heights if needed to avoid overflow
            const gap = 12;
            const available = Math.max(0, window.innerHeight - 40 - gap * (order.length - 1));
            const eachMax = Math.floor(available / order.length);
            order.forEach(el => {
                el.style.maxHeight = eachMax + 'px';
                el.style.overflowY = 'auto';
            });

            // Stack bottom-up in the requested order
            let bottomOffset = 20; // base gutter
            order.forEach(el => {
                el.style.left = 'auto';
                el.style.top = 'auto';
                el.style.right = '20px';
                el.style.bottom = bottomOffset + 'px';
                bottomOffset += el.offsetHeight + gap;
            });
        }

        function layoutWidgetsStackedBottomRight() {
            const minimap = document.querySelector('.minimap');
            const fileExplorer = document.querySelector('.file-explorer');
            const tools = document.querySelector('.tools-widget');
            const status = document.querySelector('.status-widget');
            const widgets = [minimap, fileExplorer, tools, status].filter(el => el && getComputedStyle(el).display !== 'none');
            if (!widgets.length) return;

            const order = [minimap, fileExplorer, tools, status].filter(Boolean).filter(el => getComputedStyle(el).display !== 'none');

            // If user placed custom positions and there is no overlap, respect them.
            if (hasCustomWidgetPositions() && !widgetsOverlap(widgets)) return;

            applyStackLayout(widgets, order);
        }
        
        // Panel icon removed
        
        let _minimapScrollContainer = null;
        let _minimapScrollHandler = null;
        function initMinimap() {
            // Generate minimap content
            const minimap = createMinimap();
            document.body.appendChild(minimap);
            // Make draggable (use title as handle)
            const mTitle = minimap.querySelector('.minimap-title');
            makeDraggable(minimap, 'uvnote-minimap-pos', mTitle);

            // Attach scroll listener to window (two-panel removed)
            _minimapScrollContainer = window;

            if (_minimapScrollContainer) {
                _minimapScrollHandler = () => updateMinimapActive();
                if (_minimapScrollContainer === window) {
                    window.addEventListener('scroll', _minimapScrollHandler);
                } else {
                    _minimapScrollContainer.addEventListener('scroll', _minimapScrollHandler);
                }
            }
            updateMinimapActive();
        }

        function teardownMinimap() {
            const minimap = document.querySelector('.minimap');
            if (minimap && minimap.parentNode) minimap.parentNode.removeChild(minimap);
            if (_minimapScrollContainer && _minimapScrollHandler) {
                if (_minimapScrollContainer === window) {
                    window.removeEventListener('scroll', _minimapScrollHandler);
                } else {
                    _minimapScrollContainer.removeEventListener('scroll', _minimapScrollHandler);
                }
            }
            _minimapScrollContainer = null;
            _minimapScrollHandler = null;
        }
        
        function initFileExplorer() {
            // Generate file explorer content
            const fileExplorer = createFileExplorer();
            document.body.appendChild(fileExplorer);
        }
        
        function createMinimap() {
            const minimap = document.createElement('div');
            minimap.className = 'minimap';
            
            const title = document.createElement('div');
            title.className = 'minimap-title';
            title.textContent = 'navigation';
            minimap.appendChild(title);
            
            // Find all headings and cells
            const root = document.querySelector('.main-content') || document;
            const headings = root.querySelectorAll('h1, h2, h3, h4, h5, h6');
            const cells = root.querySelectorAll('.cell');
            
            // Combine and sort by position
            const items = [];
            
            headings.forEach(heading => {
                const id = heading.id || generateId(heading.textContent);
                if (!heading.id) heading.id = id;
                
                items.push({
                    element: heading,
                    type: 'heading',
                    level: parseInt(heading.tagName.charAt(1)),
                    text: heading.textContent.trim(),
                    id: id,
                    position: heading.getBoundingClientRect().top + window.scrollY
                });
            });
            
            cells.forEach(cell => {
                const header = cell.querySelector('.cell-header');
                if (header) {
                    const id = cell.id || `cell-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
                    if (!cell.id) cell.id = id;
                    
                    items.push({
                        element: cell,
                        type: 'cell',
                        text: header.textContent.trim(),
                        id: id,
                        position: cell.getBoundingClientRect().top + window.scrollY
                    });
                }
            });
            
            // Sort by position
            items.sort((a, b) => a.position - b.position);
            
            // Create minimap items
            items.forEach(item => {
                const link = document.createElement('a');
                link.className = `minimap-item ${item.type === 'heading' ? 'minimap-heading' : 'minimap-cell'}`;
                if (item.type === 'heading') {
                    link.classList.add(`h${item.level}`);
                }
                link.textContent = item.text.length > 25 ? item.text.substring(0, 22) + '...' : item.text;
                link.href = `#${item.id}`;
                link.onclick = function(e) {
                    e.preventDefault();
                    item.element.scrollIntoView({ behavior: 'smooth', block: 'start' });
                };
                minimap.appendChild(link);
            });
            
            return minimap;
        }
        
        function generateId(text) {
            return text.toLowerCase()
                .replace(/[^a-z0-9]+/g, '-')
                .replace(/^-+|-+$/g, '')
                .substring(0, 20);
        }
        
        function updateMinimapActive() {
            const minimapItems = document.querySelectorAll('.minimap-item');
            const container = _minimapScrollContainer || window;
            const containerRect = container === window ? null : container.getBoundingClientRect();
            const scrollPos = (container === window ? window.scrollY : container.scrollTop) + 100; // Offset for better detection
            
            let activeItem = null;
            minimapItems.forEach(item => {
                const targetId = item.getAttribute('href').substring(1);
                const target = document.getElementById(targetId);
                
                if (target) {
                    const rectTop = target.getBoundingClientRect().top;
                    const targetPos = (container === window)
                        ? rectTop + window.scrollY
                        : rectTop - containerRect.top + container.scrollTop;
                    if (targetPos <= scrollPos) {
                        activeItem = item;
                    }
                }
                
                item.classList.remove('active');
            });
            
            if (activeItem) {
                activeItem.classList.add('active');
            }
        }
        
        function createFileExplorer() {
            const fileExplorer = document.createElement('div');
            fileExplorer.className = 'file-explorer';
            
            const title = document.createElement('div');
            title.className = 'file-explorer-title';
            title.textContent = 'files';
            fileExplorer.appendChild(title);
            // Make draggable (use title as handle)
            makeDraggable(fileExplorer, 'uvnote-file-explorer-pos', title);
            
            // Scripts section
            const scriptsSection = document.createElement('div');
            scriptsSection.className = 'file-explorer-section';
            
            const scriptsTitle = document.createElement('div');
            scriptsTitle.className = 'file-explorer-section-title';
            scriptsTitle.textContent = 'scripts';
            scriptsSection.appendChild(scriptsTitle);
            
            // Find all cells and list their script files (single panel)
            const root = document.querySelector('.main-content') || document;
            const cells = root.querySelectorAll('.cell');
            cells.forEach(cell => {
                const header = cell.querySelector('.cell-header');
                if (header) {
                    const cellText = header.textContent.trim();
                    const cellMatch = cellText.match(/Cell: ([a-zA-Z_][a-zA-Z0-9_]*)/);
                    if (cellMatch) {
                        const cellId = cellMatch[1];
                        const scriptItem = document.createElement('div');
                        scriptItem.className = 'file-explorer-item script';
                        scriptItem.textContent = `${cellId}.py`;
                        scriptItem.onclick = function() {
                            cell.scrollIntoView({ behavior: 'smooth', block: 'start' });
                        };
                        scriptsSection.appendChild(scriptItem);
                    }
                }
            });
            
            fileExplorer.appendChild(scriptsSection);
            
            // Artifacts section
            const artifactsSection = document.createElement('div');
            artifactsSection.className = 'file-explorer-section';
            
            const artifactsTitle = document.createElement('div');
            artifactsTitle.className = 'file-explorer-section-title';
            artifactsTitle.textContent = 'artifacts';
            artifactsSection.appendChild(artifactsTitle);
            
            // Find all artifact links (single panel)
            const artifactsRoot = document.querySelector('.main-content') || document;
            const artifacts = artifactsRoot.querySelectorAll('.artifact');
            if (artifacts.length === 0) {
                const noArtifacts = document.createElement('div');
                noArtifacts.className = 'file-explorer-item artifact';
                noArtifacts.textContent = '(none)';
                noArtifacts.style.opacity = '0.5';
                artifactsSection.appendChild(noArtifacts);
            } else {
                artifacts.forEach(artifact => {
                    const artifactItem = document.createElement('div');
                    artifactItem.className = 'file-explorer-item artifact';
                    artifactItem.textContent = artifact.textContent;
                    artifactItem.onclick = function() {
                        artifact.click();
                    };
                    artifactsSection.appendChild(artifactItem);
                });
            }
            
            fileExplorer.appendChild(artifactsSection);
            
            return fileExplorer;
        }

        function initStatusWidget() {
            let el = document.querySelector('.status-widget');
            if (!el) {
                el = document.createElement('div');
                el.className = 'status-widget';
                el.id = 'status-widget';
                el.textContent = 'ready — Esc';
                document.body.appendChild(el);
            }
        }

        // Tools widget
        let _cursorX = 0;
        let _cursorY = 0;
        let _cursorVisible = false;
        
        function setActiveTool(tool) {
            if (!tool || tool === 'none') {
                document.body.dataset.tool = 'none';
                localStorage.setItem('uvnote-active-tool', 'none');
                setOverlayActive(false);
                _cursorVisible = false;
                // Remove active class from all tool buttons when deactivating
                const toolButtons = document.querySelectorAll('.tools-widget .tool-button');
                toolButtons.forEach(btn => btn.classList.remove('active'));
                updateStateIndicator();
                encodeToolStateToUrl();
                return;
            }
            document.body.dataset.tool = tool;
            localStorage.setItem('uvnote-active-tool', tool);
            setOverlayActive(true);
            _cursorVisible = true;
            updateStateIndicator();
            encodeToolStateToUrl();
        }

        // Make setActiveTool globally accessible for ESC key handler
        window.setActiveTool = setActiveTool;
        

        function getArrowColor() {
            const saved = localStorage.getItem('uvnote-arrow-color');
            if (saved) return saved;
            return '#e53935'; // Default red color
        }

        function setStoredArrowColor(color) {
            try { localStorage.setItem('uvnote-arrow-color', color); } catch (_) {}
        }

        function getLineThickness() {
            const saved = localStorage.getItem('uvnote-line-thickness');
            if (saved) return parseInt(saved, 10);
            return 6; // default thickness
        }

        function setStoredLineThickness(thickness) {
            try { localStorage.setItem('uvnote-line-thickness', thickness); } catch (_) {}
        }

        function getFadeoutTime() {
            const saved = localStorage.getItem('uvnote-fadeout-time');
            if (saved) return parseInt(saved, 10);
            return 5; // default 5 seconds
        }

        function setStoredFadeoutTime(seconds) {
            try { localStorage.setItem('uvnote-fadeout-time', seconds); } catch (_) {}
        }

        function createToolsWidget() {
            const tools = document.createElement('div');
            tools.className = 'tools-widget';

            const title = document.createElement('div');
            title.className = 'tools-title';
            title.textContent = 'tools';
            tools.appendChild(title);

            const row = document.createElement('div');
            row.className = 'tools-row';
            tools.appendChild(row);

            // Arrow tool
            const arrowBtn = document.createElement('div');
            arrowBtn.className = 'tool-button';
            arrowBtn.textContent = 'arrow';
            arrowBtn.onclick = function() {
                const isActive = arrowBtn.classList.contains('active');
                if (isActive) {
                    arrowBtn.classList.remove('active');
                    setActiveTool('none');
                } else {
                    tools.querySelectorAll('.tool-button').forEach(b => b.classList.remove('active'));
                    arrowBtn.classList.add('active');
                    setActiveTool('arrow');
                }
            };
            row.appendChild(arrowBtn);

            // Pen tool
            const penBtn = document.createElement('div');
            penBtn.className = 'tool-button';
            penBtn.textContent = 'pen';
            penBtn.onclick = function() {
                const isActive = penBtn.classList.contains('active');
                if (isActive) {
                    penBtn.classList.remove('active');
                    setActiveTool('none');
                } else {
                    tools.querySelectorAll('.tool-button').forEach(b => b.classList.remove('active'));
                    penBtn.classList.add('active');
                    setActiveTool('pen');
                }
            };
            row.appendChild(penBtn);

            // Eraser tool
            const eraseBtn = document.createElement('div');
            eraseBtn.className = 'tool-button';
            eraseBtn.textContent = 'eraser';
            eraseBtn.onclick = function() {
                const isActive = eraseBtn.classList.contains('active');
                if (isActive) {
                    eraseBtn.classList.remove('active');
                    setActiveTool('none');
                } else {
                    tools.querySelectorAll('.tool-button').forEach(b => b.classList.remove('active'));
                    eraseBtn.classList.add('active');
                    setActiveTool('eraser');
                }
            };
            row.appendChild(eraseBtn);

            // Spotlight tool
            const spotlightBtn = document.createElement('div');
            spotlightBtn.className = 'tool-button';
            spotlightBtn.textContent = 'spotlight';
            spotlightBtn.onclick = function() {
                const isActive = spotlightBtn.classList.contains('active');
                if (isActive) {
                    spotlightBtn.classList.remove('active');
                    setActiveTool('none');
                } else {
                    tools.querySelectorAll('.tool-button').forEach(b => b.classList.remove('active'));
                    spotlightBtn.classList.add('active');
                    setActiveTool('spotlight');
                }
            };
            row.appendChild(spotlightBtn);

            // Clear all
            const clearBtn = document.createElement('div');
            clearBtn.className = 'tool-button';
            clearBtn.textContent = 'clear';
            clearBtn.onclick = function() {
                _shapes = [];
                saveShapes();
                renderOverlay();
            };
            row.appendChild(clearBtn);
            
            // We'll add the copy button at the end of the widget

            // Restore active state from storage
            const saved = localStorage.getItem('uvnote-active-tool') || 'none';
            if (saved === 'arrow') {
                arrowBtn.classList.add('active');
                setActiveTool('arrow');
            } else if (saved === 'pen') {
                penBtn.classList.add('active');
                setActiveTool('pen');
            } else if (saved === 'eraser') {
                eraseBtn.classList.add('active');
                setActiveTool('eraser');
            } else if (saved === 'spotlight') {
                spotlightBtn.classList.add('active');
                setActiveTool('spotlight');
            }

            // Color selector
            const colorTitle = document.createElement('div');
            colorTitle.className = 'tools-section-title';
            colorTitle.textContent = 'color';
            tools.appendChild(colorTitle);

            const colorRow = document.createElement('div');
            colorRow.className = 'tools-row color-row';
            tools.appendChild(colorRow);

            const swatchColors = [
                // Primary colors
                '#e53935', '#fb8c00', '#fdd835', '#43a047', '#1e88e5', '#8e24aa',
                // Additional useful colors  
                '#ff5722', '#795548', '#607d8b', '#9c27b0',
                // Grayscale
                '#000000', '#424242', '#9e9e9e', '#ffffff'
            ];
            const swatches = [];
            swatchColors.forEach(c => {
                const s = document.createElement('div');
                s.className = 'color-swatch';
                s.style.backgroundColor = c;
                s.title = c;
                s.onclick = () => {
                    setStoredArrowColor(c);
                    refreshColorUI(c);
                    if (_cursorVisible) renderOverlay();
                    encodeToolStateToUrl();
                };
                colorRow.appendChild(s);
                swatches.push(s);
            });

            const colorInput = document.createElement('input');
            colorInput.type = 'color';
            colorInput.className = 'color-input';
            colorInput.oninput = () => {
                setStoredArrowColor(colorInput.value);
                refreshColorUI(colorInput.value);
                if (_cursorVisible) renderOverlay();
                encodeToolStateToUrl();
            };
            colorRow.appendChild(colorInput);

            function refreshColorUI(selected) {
                const selectedHex = selected.startsWith('#') ? selected.toLowerCase() : rgbToHex(selected);
                
                swatches.forEach((s, i) => {
                    const swatchHex = swatchColors[i].toLowerCase();
                    if (swatchHex === selectedHex) {
                        s.classList.add('selected');
                    } else {
                        s.classList.remove('selected');
                    }
                });
                
                try { 
                    colorInput.value = selectedHex; 
                } catch (_) {}
            }

            function rgbToHex(rgb) {
                const m = rgb.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)\)/i);
                if (!m) return '#000000';
                const r = parseInt(m[1]).toString(16).padStart(2, '0');
                const g = parseInt(m[2]).toString(16).padStart(2, '0');
                const b = parseInt(m[3]).toString(16).padStart(2, '0');
                return `#${r}${g}${b}`;
            }

            // Restore color selection
            refreshColorUI(getArrowColor());

            // Thickness slider
            const thicknessTitle = document.createElement('div');
            thicknessTitle.className = 'tools-section-title';
            thicknessTitle.textContent = 'thickness';
            tools.appendChild(thicknessTitle);

            const thicknessRow = document.createElement('div');
            thicknessRow.className = 'thickness-row';
            tools.appendChild(thicknessRow);

            const thicknessSlider = document.createElement('input');
            thicknessSlider.type = 'range';
            thicknessSlider.className = 'thickness-slider';
            thicknessSlider.min = '1';
            thicknessSlider.max = '10';
            thicknessSlider.value = getLineThickness();
            
            const thicknessValue = document.createElement('span');
            thicknessValue.className = 'thickness-value';
            thicknessValue.textContent = thicknessSlider.value + 'px';

            thicknessSlider.oninput = function() {
                const value = parseInt(thicknessSlider.value, 10);
                setStoredLineThickness(value);
                thicknessValue.textContent = value + 'px';
                if (_cursorVisible) renderOverlay();
                encodeToolStateToUrl();
            };

            thicknessRow.appendChild(thicknessSlider);
            thicknessRow.appendChild(thicknessValue);

            // Fadeout time slider
            const fadeoutTitle = document.createElement('div');
            fadeoutTitle.className = 'tools-section-title';
            fadeoutTitle.textContent = 'fadeout time';
            tools.appendChild(fadeoutTitle);

            const fadeoutRow = document.createElement('div');
            fadeoutRow.className = 'thickness-row';
            tools.appendChild(fadeoutRow);

            const fadeoutSlider = document.createElement('input');
            fadeoutSlider.type = 'range';
            fadeoutSlider.className = 'thickness-slider';
            fadeoutSlider.min = '0';
            fadeoutSlider.max = '30';
            fadeoutSlider.value = getFadeoutTime();
            
            const fadeoutValue = document.createElement('span');
            fadeoutValue.className = 'thickness-value';
            fadeoutValue.textContent = fadeoutSlider.value === '0' ? 'never' : fadeoutSlider.value + 's';

            fadeoutSlider.oninput = function() {
                const value = parseInt(fadeoutSlider.value, 10);
                setStoredFadeoutTime(value);
                fadeoutValue.textContent = value === 0 ? 'never' : value + 's';
                encodeToolStateToUrl();
            };

            fadeoutRow.appendChild(fadeoutSlider);
            fadeoutRow.appendChild(fadeoutValue);

            // Draggable behavior
            makeDraggable(tools, 'uvnote-tools-pos', title);

            return tools;
        }

        function initTools() {
            const widget = createToolsWidget();
            document.body.appendChild(widget);
        }

        function teardownTools() {
            const w = document.querySelector('.tools-widget');
            if (w && w.parentNode) w.parentNode.removeChild(w);
        }

        // --- Canvas overlay for tools ---
        let _overlay = null;
        let _overlayCtx = null;
        let _overlayContainer = null; // window
        let _overlayMode = 'single';
        let _overlayResizeHandler = null;
        let _overlayScrollHandler = null;
        let _drawing = null; // current in-progress arrow {x1,y1,x2,y2}
        let _shapes = []; // committed shapes for current mode
        let _fadeTimer = null; // timer for fade animation
        let _urlLoadedTool = false; // track if tool was loaded from URL
        let _isInitializing = true; // prevent URL updates during initialization
        let _initialCellStates = {}; // track initial cell states from page load

        function getOverlayStorageKey() { return 'uvnote-shapes'; }

        function loadShapes() {
            try {
                const raw = localStorage.getItem(getOverlayStorageKey());
                _shapes = raw ? JSON.parse(raw) : [];
            } catch (_) { _shapes = []; }
        }

        function saveShapes() {
            try { 
                localStorage.setItem(getOverlayStorageKey(), JSON.stringify(_shapes));
                // Always update URL when shapes change
                encodeToolStateToUrl();
            } catch (_) {}
        }

        function updateShapesFade() {
            const now = Date.now();
            let needsUpdate = false;

            for (let i = _shapes.length - 1; i >= 0; i--) {
                const shape = _shapes[i];
                if (!shape.createdAt) continue; // Skip old shapes without timestamps
                
                // Use individual shape's fadeout time, or global if not set
                const shapesFadeoutSeconds = shape.fadeoutTime !== undefined ? shape.fadeoutTime : getFadeoutTime();
                
                // Skip fading if fadeout is disabled for this shape
                if (shapesFadeoutSeconds === 0) continue;
                
                const fadeStartTime = Math.max(0, (shapesFadeoutSeconds - 2) * 1000); // Start fading 2s before end
                const fadeEndTime = shapesFadeoutSeconds * 1000; // Fully gone after specified time
                const age = now - shape.createdAt;
                
                if (age >= fadeEndTime) {
                    // Remove completely faded shapes
                    _shapes.splice(i, 1);
                    needsUpdate = true;
                } else if (age >= fadeStartTime) {
                    // Update opacity for fading shapes
                    const fadeProgress = (age - fadeStartTime) / (fadeEndTime - fadeStartTime);
                    const newOpacity = 1 - fadeProgress;
                    if (Math.abs(shape.opacity - newOpacity) > 0.01) {
                        shape.opacity = newOpacity;
                        needsUpdate = true;
                    }
                }
            }

            if (needsUpdate) {
                saveShapes();
                renderOverlay();
                // Update URL to remove faded shapes  
                encodeToolStateToUrl();
            }
        }

        function getContentContainer() { return window; }

        function updateOverlayModeAndContainer() {
            _overlayContainer = window;
            _overlayMode = 'single';
        }

        function updateOverlayBounds() {
            if (!_overlay) return;
            if (_overlayContainer === window) {
                _overlay.style.position = 'fixed';
                _overlay.style.left = '0px';
                _overlay.style.top = '0px';
                _overlay.width = window.innerWidth;
                _overlay.height = window.innerHeight;
            } else {
                const rect = _overlayContainer.getBoundingClientRect();
                _overlay.style.position = 'fixed';
                _overlay.style.left = rect.left + 'px';
                _overlay.style.top = rect.top + 'px';
                _overlay.width = Math.max(0, Math.floor(rect.width));
                _overlay.height = Math.max(0, Math.floor(rect.height));
            }
            renderOverlay();
        }

        function containerScrollLeft() {
            return (_overlayContainer === window) ? (window.scrollX || 0) : (_overlayContainer.scrollLeft || 0);
        }
        function containerScrollTop() {
            return (_overlayContainer === window) ? (window.scrollY || 0) : (_overlayContainer.scrollTop || 0);
        }

        function toCanvasCoords(clientX, clientY) {
            const rect = _overlay.getBoundingClientRect();
            return { x: clientX - rect.left, y: clientY - rect.top };
        }

        function onPointerDown(e) {
            const tool = document.body.dataset.tool;
            if (tool === 'arrow') {
                startDrawArrow(e);
            } else if (tool === 'pen') {
                startDrawPen(e);
            } else if (tool === 'eraser') {
                eraseAt(e);
            } else if (tool === 'spotlight') {
                startDrawSpotlight(e);
            }
        }

        function onPointerMove(e) {
            // Update cursor position
            const pt = toCanvasCoords(e.touches ? e.touches[0].clientX : e.clientX, e.touches ? e.touches[0].clientY : e.clientY);
            _cursorX = pt.x;
            _cursorY = pt.y;
            
            if (!_drawing) {
                // Just update cursor position and re-render
                if (_cursorVisible) {
                    renderOverlay();
                }
                return;
            }
            
            if (_drawing.type === 'pen') {
                moveDrawPen(e);
            } else if (_drawing.type === 'spotlight') {
                moveDrawSpotlight(e);
            } else {
                moveDrawArrow(e);
            }
        }
        
        function onPointerEnter(e) {
            _cursorVisible = document.body.dataset.tool !== 'none';
            if (_cursorVisible) {
                renderOverlay();
            }
        }
        
        function onPointerLeave(e) {
            _cursorVisible = false;
            renderOverlay();
        }

        function onPointerUp(e) {
            if (!_drawing) return;
            if (_drawing.type === 'pen') {
                endDrawPen();
            } else if (_drawing.type === 'spotlight') {
                endDrawSpotlight();
            } else {
                endDrawArrow();
            }
        }

        function startDrawArrow(e) {
            if (document.body.dataset.tool !== 'arrow') return;
            const pt = toCanvasCoords(e.touches ? e.touches[0].clientX : e.clientX, e.touches ? e.touches[0].clientY : e.clientY);
            _drawing = {
                x1: pt.x + containerScrollLeft(),
                y1: pt.y + containerScrollTop(),
                x2: pt.x + containerScrollLeft(),
                y2: pt.y + containerScrollTop(),
                color: getArrowColor(),
                width: getLineThickness()
            };
            renderOverlay();
            e.preventDefault();
        }

        function moveDrawArrow(e) {
            if (!_drawing) return;
            const pt = toCanvasCoords(e.touches ? e.touches[0].clientX : e.clientX, e.touches ? e.touches[0].clientY : e.clientY);
            _drawing.x2 = pt.x + containerScrollLeft();
            _drawing.y2 = pt.y + containerScrollTop();
            renderOverlay();
            e.preventDefault();
        }

        function endDrawArrow() {
            if (!_drawing) return;
            _shapes.push({ 
                type: 'arrow', 
                ..._drawing,
                createdAt: Date.now(),
                fadeoutTime: getFadeoutTime(),
                opacity: 1.0
            });
            _drawing = null;
            saveShapes();
            renderOverlay();
        }

        function startDrawPen(e) {
            if (document.body.dataset.tool !== 'pen') return;
            const pt = toCanvasCoords(e.touches ? e.touches[0].clientX : e.clientX, e.touches ? e.touches[0].clientY : e.clientY);
            _drawing = {
                type: 'pen',
                points: [{
                    x: pt.x + containerScrollLeft(),
                    y: pt.y + containerScrollTop()
                }],
                color: getArrowColor(),
                width: getLineThickness()
            };
            renderOverlay();
            e.preventDefault();
        }

        function moveDrawPen(e) {
            if (!_drawing || _drawing.type !== 'pen') return;
            const pt = toCanvasCoords(e.touches ? e.touches[0].clientX : e.clientX, e.touches ? e.touches[0].clientY : e.clientY);
            _drawing.points.push({
                x: pt.x + containerScrollLeft(),
                y: pt.y + containerScrollTop()
            });
            renderOverlay();
            e.preventDefault();
        }

        function endDrawPen() {
            if (!_drawing || _drawing.type !== 'pen') return;
            if (_drawing.points.length > 1) {
                _shapes.push({ 
                    ..._drawing,
                    createdAt: Date.now(),
                    fadeoutTime: getFadeoutTime(),
                    opacity: 1.0
                });
            }
            _drawing = null;
            saveShapes();
            renderOverlay();
        }

        function startDrawSpotlight(e) {
            if (document.body.dataset.tool !== 'spotlight') return;
            const pt = toCanvasCoords(e.touches ? e.touches[0].clientX : e.clientX, e.touches ? e.touches[0].clientY : e.clientY);
            _drawing = {
                type: 'spotlight',
                x: pt.x + containerScrollLeft(),
                y: pt.y + containerScrollTop(),
                radius: getLineThickness() * 20, // Use thickness to control spotlight size (bigger default)
                color: getArrowColor()
            };
            renderOverlay();
            e.preventDefault();
        }

        function moveDrawSpotlight(e) {
            if (!_drawing || _drawing.type !== 'spotlight') return;
            const pt = toCanvasCoords(e.touches ? e.touches[0].clientX : e.clientX, e.touches ? e.touches[0].clientY : e.clientY);
            const dx = pt.x + containerScrollLeft() - _drawing.x;
            const dy = pt.y + containerScrollTop() - _drawing.y;
            _drawing.radius = Math.max(20, Math.sqrt(dx * dx + dy * dy)); // Minimum radius of 20
            renderOverlay();
            e.preventDefault();
        }

        function endDrawSpotlight() {
            if (!_drawing || _drawing.type !== 'spotlight') return;
            _shapes.push({ 
                ..._drawing,
                createdAt: Date.now(),
                fadeoutTime: getFadeoutTime(),
                opacity: 1.0
            });
            _drawing = null;
            saveShapes();
            renderOverlay();
        }

        function distPointToSegment(px, py, x1, y1, x2, y2) {
            const dx = x2 - x1, dy = y2 - y1;
            if (dx === 0 && dy === 0) return Math.hypot(px - x1, py - y1);
            const t = Math.max(0, Math.min(1, ((px - x1) * dx + (py - y1) * dy) / (dx*dx + dy*dy)));
            const cx = x1 + t * dx, cy = y1 + t * dy;
            return Math.hypot(px - cx, py - cy);
        }

        function eraseAt(e) {
            const pt = toCanvasCoords(e.touches ? e.touches[0].clientX : e.clientX, e.touches ? e.touches[0].clientY : e.clientY);
            const x = pt.x + containerScrollLeft();
            const y = pt.y + containerScrollTop();
            const threshold = 10; // pixels
            for (let i = _shapes.length - 1; i >= 0; i--) {
                const s = _shapes[i];
                if (s.type === 'arrow') {
                    const d = distPointToSegment(x, y, s.x1, s.y1, s.x2, s.y2);
                    if (d <= threshold) {
                        _shapes.splice(i, 1);
                        saveShapes();
                        renderOverlay();
                        break;
                    }
                } else if (s.type === 'pen' && s.points) {
                    // Check if click is near any line segment in the pen stroke
                    let minDist = Infinity;
                    for (let j = 1; j < s.points.length; j++) {
                        const d = distPointToSegment(x, y, s.points[j-1].x, s.points[j-1].y, s.points[j].x, s.points[j].y);
                        minDist = Math.min(minDist, d);
                    }
                    if (minDist <= threshold) {
                        _shapes.splice(i, 1);
                        saveShapes();
                        renderOverlay();
                        break;
                    }
                }
            }
            e.preventDefault();
        }

        function drawArrow(ctx, x1, y1, x2, y2, color, width, opacity = 1.0) {
            // Set opacity
            const oldAlpha = ctx.globalAlpha;
            ctx.globalAlpha = opacity;
            
            ctx.strokeStyle = color;
            ctx.fillStyle = color;
            ctx.lineWidth = width;
            ctx.lineCap = 'round';
            ctx.lineJoin = 'round';
            
            // Check if points are too close (initial state)
            const dx = x2 - x1;
            const dy = y2 - y1;
            const distance = Math.sqrt(dx * dx + dy * dy);
            
            if (distance < 5) {
                // Draw just a small arrowhead pointing down-right when first clicked
                const defaultAngle = Math.PI / 4; // 45 degrees (down-right)
                const headLength = Math.min(15 + width * 1.5, 25);
                const headAngle = Math.PI / 6;
                
                // Calculate arrowhead points
                const hx1 = x1 + headLength * Math.cos(defaultAngle - headAngle);
                const hy1 = y1 + headLength * Math.sin(defaultAngle - headAngle);
                const hx2 = x1 + headLength * Math.cos(defaultAngle + headAngle);
                const hy2 = y1 + headLength * Math.sin(defaultAngle + headAngle);
                
                // Draw arrowhead only
                ctx.beginPath();
                ctx.moveTo(x1, y1);
                ctx.lineTo(hx1, hy1);
                ctx.lineTo(hx2, hy2);
                ctx.closePath();
                ctx.fill();
            } else {
                // Normal arrow drawing - head at x1,y1, tail at x2,y2
                const angle = Math.atan2(y1 - y2, x1 - x2);
                const headLength = Math.min(15 + width * 1.5, 25);
                const headAngle = Math.PI / 6;
                
                // Calculate where the line should end (before the arrowhead)
                const lineEndX = x1 - headLength * 0.8 * Math.cos(angle);
                const lineEndY = y1 - headLength * 0.8 * Math.sin(angle);
                
                // Draw the line from tail to near the head
                ctx.beginPath();
                ctx.moveTo(x2, y2);
                ctx.lineTo(lineEndX, lineEndY);
                ctx.stroke();
                
                // Calculate arrowhead points
                const hx1 = x1 - headLength * Math.cos(angle - headAngle);
                const hy1 = y1 - headLength * Math.sin(angle - headAngle);
                const hx2 = x1 - headLength * Math.cos(angle + headAngle);
                const hy2 = y1 - headLength * Math.sin(angle + headAngle);
                
                // Draw arrowhead
                ctx.beginPath();
                ctx.moveTo(x1, y1);
                ctx.lineTo(hx1, hy1);
                ctx.lineTo(hx2, hy2);
                ctx.closePath();
                ctx.fill();
            }
            
            // Restore opacity
            ctx.globalAlpha = oldAlpha;
        }

        function drawPen(ctx, points, color, width, offX, offY, opacity = 1.0) {
            if (!points || points.length < 2) return;
            
            // Set opacity
            const oldAlpha = ctx.globalAlpha;
            ctx.globalAlpha = opacity;
            
            ctx.strokeStyle = color;
            ctx.lineWidth = width;
            ctx.lineCap = 'round';
            ctx.lineJoin = 'round';
            ctx.beginPath();
            ctx.moveTo(points[0].x - offX, points[0].y - offY);
            for (let i = 1; i < points.length; i++) {
                ctx.lineTo(points[i].x - offX, points[i].y - offY);
            }
            ctx.stroke();
            
            // Restore opacity
            ctx.globalAlpha = oldAlpha;
        }

        function drawAllSpotlights(ctx, spotlights, offX, offY) {
            if (!spotlights || spotlights.length === 0) return;
            
            ctx.save();
            
            // Calculate the overall opacity based on all spotlights
            const maxOpacity = Math.max(...spotlights.map(s => s.opacity || 1.0));
            
            // Fill entire canvas with dark overlay
            ctx.fillStyle = `rgba(0, 0, 0, ${0.7 * maxOpacity})`;
            ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);
            
            // Cut out completely transparent holes for all spotlights
            ctx.globalCompositeOperation = 'destination-out';
            ctx.fillStyle = 'rgba(0, 0, 0, 1)'; // Solid black to ensure complete removal
            for (const spotlight of spotlights) {
                ctx.beginPath();
                ctx.arc(spotlight.x - offX, spotlight.y - offY, spotlight.radius, 0, 2 * Math.PI);
                ctx.fill();
            }
            
            ctx.restore();
        }

        function renderOverlay() {
            if (!_overlay || !_overlayCtx) return;
            _overlayCtx.clearRect(0, 0, _overlay.width, _overlay.height);
            const offX = containerScrollLeft();
            const offY = containerScrollTop();
            // Draw non-spotlight shapes first
            for (const s of _shapes) {
                const opacity = s.opacity !== undefined ? s.opacity : 1.0;
                if (s.type === 'arrow') {
                    drawArrow(_overlayCtx, s.x1 - offX, s.y1 - offY, s.x2 - offX, s.y2 - offY, s.color || '#f00', s.width || 2, opacity);
                } else if (s.type === 'pen') {
                    drawPen(_overlayCtx, s.points, s.color || '#f00', s.width || 2, offX, offY, opacity);
                }
            }
            // Draw current drawing (non-spotlight)
            if (_drawing) {
                if (_drawing.type === 'pen') {
                    drawPen(_overlayCtx, _drawing.points, _drawing.color, _drawing.width, offX, offY);
                } else if (_drawing.type !== 'spotlight') {
                    drawArrow(_overlayCtx, _drawing.x1 - offX, _drawing.y1 - offY, _drawing.x2 - offX, _drawing.y2 - offY, _drawing.color, _drawing.width);
                }
            }
            
            // Collect all spotlights (existing + current drawing + cursor preview)
            const spotlights = [];
            
            // Add existing spotlight shapes
            for (const s of _shapes) {
                if (s.type === 'spotlight') {
                    spotlights.push({
                        x: s.x,
                        y: s.y, 
                        radius: s.radius,
                        opacity: s.opacity !== undefined ? s.opacity : 1.0
                    });
                }
            }
            
            // Add current spotlight being drawn
            if (_drawing && _drawing.type === 'spotlight') {
                spotlights.push({
                    x: _drawing.x,
                    y: _drawing.y,
                    radius: _drawing.radius,
                    opacity: 1.0
                });
            }
            
            // Add cursor preview spotlight if tool is active
            if (_cursorVisible && !_drawing) {
                const tool = document.body.dataset.tool;
                if (tool === 'spotlight') {
                    const thickness = getLineThickness();
                    const radius = thickness * 20;
                    const cursorWorldX = _cursorX + containerScrollLeft();
                    const cursorWorldY = _cursorY + containerScrollTop();
                    spotlights.push({
                        x: cursorWorldX,
                        y: cursorWorldY,
                        radius: radius,
                        opacity: 0.8
                    });
                }
            }
            
            // Draw all spotlights as a single overlay with multiple holes
            drawAllSpotlights(_overlayCtx, spotlights, offX, offY);
            
            // Draw cursor indicators for non-spotlight tools
            if (_cursorVisible && !_drawing) {
                const tool = document.body.dataset.tool;
                const color = getArrowColor();
                const thickness = getLineThickness();
                
                if (tool !== 'spotlight') {
                    _overlayCtx.save();
                    _overlayCtx.fillStyle = color;
                    _overlayCtx.globalAlpha = 0.7;
                    
                    if (tool === 'eraser') {
                        // Draw eraser indicator
                        _overlayCtx.strokeStyle = color;
                        _overlayCtx.lineWidth = 2;
                        _overlayCtx.beginPath();
                        _overlayCtx.arc(_cursorX, _cursorY, 10, 0, 2 * Math.PI);
                        _overlayCtx.stroke();
                    } else {
                        // Draw dot for pen/arrow
                        _overlayCtx.beginPath();
                        _overlayCtx.arc(_cursorX, _cursorY, thickness / 2, 0, 2 * Math.PI);
                        _overlayCtx.fill();
                    }
                    
                    _overlayCtx.restore();
                }
            }
        }

        function setOverlayActive(active) {
            if (!_overlay) initOverlay();
            _overlay.style.pointerEvents = active ? 'auto' : 'none';
            _overlay.style.cursor = active ? 'none' : 'auto';
            // Re-render to ensure visibility aligns with content
            renderOverlay();
        }

        function initOverlay() {
            if (_overlay) return;
            updateOverlayModeAndContainer();
            _overlay = document.createElement('canvas');
            _overlay.className = 'draw-overlay';
            _overlayCtx = _overlay.getContext('2d');
            document.body.appendChild(_overlay);
            updateOverlayBounds();
            loadShapes();
            renderOverlay();

            // Events
            _overlay.addEventListener('mousedown', onPointerDown);
            _overlay.addEventListener('mousemove', onPointerMove);
            _overlay.addEventListener('mouseenter', onPointerEnter);
            _overlay.addEventListener('mouseleave', onPointerLeave);
            document.addEventListener('mouseup', onPointerUp);
            _overlay.addEventListener('touchstart', onPointerDown, { passive: false });
            _overlay.addEventListener('touchmove', onPointerMove, { passive: false });
            document.addEventListener('touchend', onPointerUp);

            _overlayResizeHandler = () => updateOverlayBounds();
            window.addEventListener('resize', _overlayResizeHandler);

            _overlayScrollHandler = () => renderOverlay();
            window.addEventListener('scroll', _overlayScrollHandler);
            
            // Start fade animation timer
            _fadeTimer = setInterval(updateShapesFade, 100); // Update every 100ms for smooth fade
        }

        function rebindOverlayContainer() {
            if (!_overlay) return;
            // Remove old scroll handler
            if (_overlayScrollHandler) { window.removeEventListener('scroll', _overlayScrollHandler); }
            updateOverlayModeAndContainer();
            updateOverlayBounds();
            loadShapes();
            renderOverlay();
            _overlayScrollHandler = () => renderOverlay();
            window.addEventListener('scroll', _overlayScrollHandler);
        }

        function teardownOverlay() {
            if (!_overlay) return;
            _overlay.removeEventListener('mousedown', onPointerDown);
            _overlay.removeEventListener('mousemove', onPointerMove);
            _overlay.removeEventListener('mouseenter', onPointerEnter);
            _overlay.removeEventListener('mouseleave', onPointerLeave);
            document.removeEventListener('mouseup', onPointerUp);
            _overlay.removeEventListener('touchstart', onPointerDown);
            _overlay.removeEventListener('touchmove', onPointerMove);
            document.removeEventListener('touchend', onPointerUp);
            if (_overlayResizeHandler) window.removeEventListener('resize', _overlayResizeHandler);
            if (_overlayScrollHandler) {
                if (_overlayContainer === window) {
                    window.removeEventListener('scroll', _overlayScrollHandler);
                } else if (_overlayContainer) {
                    _overlayContainer.removeEventListener('scroll', _overlayScrollHandler);
                }
            }
            if (_fadeTimer) {
                clearInterval(_fadeTimer);
                _fadeTimer = null;
            }
            if (_overlay.parentNode) _overlay.parentNode.removeChild(_overlay);
            _overlay = null; _overlayCtx = null; _overlayContainer = null; _overlayResizeHandler = null; _overlayScrollHandler = null; _drawing = null;
        }
        
        function teardownFileExplorer() {
            const fe = document.querySelector('.file-explorer');
            if (fe && fe.parentNode) fe.parentNode.removeChild(fe);
        }

        function escapeHtml(text) {
            const div = document.createElement('div');
            div.textContent = text;
            return div.innerHTML;
        }

        function runCell(cellId){
            const btn=document.querySelector('.run-btn[onclick*="'+cellId+'"]');
            const output=document.getElementById('output-'+cellId);
            if(btn){btn.textContent='⏳ running...';btn.disabled=true;}
            if(output){output.classList.add('output-stale');}
            fetch('/run/'+cellId,{method:'POST'}).then(r=>r.json()).then(data=>{
                if(output){
                    output.classList.remove('output-stale');
                    let html='';
                    if (data.stdout) {
                    html += '<div class="cell-stdout"><pre class="stdout-text">'
                        + escapeHtml(data.stdout)
                        + '</pre></div>';
                    }

                    console.log('UV Logs:', data);
                    if(data.stderr) {
                        // Split UV logs from regular stderr
                        const lines = data.stderr.split('\\n');
                        let uvLogs = [];
                        let regularLogs = [];
                        let inUvSection = true;

                        for (const line of lines) {
                            if (inUvSection) {
                                uvLogs.push(line);
                                if (line.startsWith('Installed ')) {
                                    inUvSection = false;
                                }
                            } else {
                                regularLogs.push(line);
                            }
                        }
                        

                        // If we never found "Installed", treat it all as regular stderr
                        if (inUvSection) {
                            html+='<div class="cell-stderr">'+escapeHtml(data.stderr)+'</div>';
                        } else {
                            const uvLogsStr = uvLogs.join('\\n');
                            const regularLogsStr = regularLogs.join('\\n').trim();

                            if (uvLogsStr) {
                                html+='<div class="uv-install-logs">';
                                html+='<div class="uv-logs-header" onclick="toggleUvLogs(this)">▶ UV Install Logs</div>';
                                html+='<div class="uv-logs-content" style="display: none;">'+escapeHtml(uvLogsStr)+'</div>';
                                html+='</div>';
                            }
                            if (regularLogsStr) {
                                html+='<div class="cell-stderr">'+escapeHtml(regularLogsStr)+'</div>';
                            }
                        }
                    }
                    output.innerHTML=html;
                }
                if(btn){btn.textContent='▶ run';btn.disabled=false;}
            }).catch(e=>{
                console.error('Run failed:',e);
                if(output){output.classList.remove('output-stale');}
                if(btn){btn.textContent='▶ run';btn.disabled=false;}
            });
        }

        function copyCell(cellId){
            // Try multiple selectors to find the code element
            // Pygments generates .highlight > pre with spans, not wrapped in <code>
            let codeElement = document.querySelector('#code-'+cellId+' .highlight pre');
            if (!codeElement) {
                codeElement = document.querySelector('#code-'+cellId+' pre');
            }
            if (!codeElement) {
                codeElement = document.querySelector('#code-'+cellId+' code');
            }
            if (!codeElement) {
                // Fallback to the code div itself
                codeElement = document.getElementById('code-'+cellId);
            }

            const btn = document.querySelector('.copy-btn[onclick*="'+cellId+'"]');

            if (!codeElement) {
                console.error('Code element not found for cell:', cellId);
                return;
            }
            if (!btn) {
                console.error('Copy button not found for cell:', cellId);
                return;
            }

            const codeText = codeElement.textContent;
            
            if (navigator.clipboard && navigator.clipboard.writeText) {
                navigator.clipboard.writeText(codeText).then(function() {
                    console.log('Clipboard copy successful');
                    btn.textContent = '✓ Copied!';
                    btn.classList.add('copied');
                    setTimeout(function() {
                        btn.textContent = 'Copy';
                        btn.classList.remove('copied');
                    }, 2000);
                }).catch(function(err) {
                    console.warn('Clipboard copy failed:', err);
                    fallbackCopy();
                });
            } else {
                console.log('Using fallback copy method');
                fallbackCopy();
            }
            
            function fallbackCopy() {
                const textarea = document.createElement('textarea');
                textarea.value = codeText;
                textarea.style.position = 'absolute';
                textarea.style.left = '-9999px';
                document.body.appendChild(textarea);
                textarea.select();
                try {
                    const success = document.execCommand('copy');
                    console.log('Fallback copy success:', success);
                    btn.textContent = '✓ Copied!';
                    btn.classList.add('copied');
                    setTimeout(function() {
                        btn.textContent = 'Copy';
                        btn.classList.remove('copied');
                    }, 2000);
                } catch (err) {
                    console.error('Fallback copy failed:', err);
                    btn.textContent = 'Copy failed';
                    setTimeout(function() {
                        btn.textContent = 'Copy';
                    }, 2000);
                }
                document.body.removeChild(textarea);
            }
        }

        // // Live reload functionality (robust SSE handling)
        // (function(){
        //     if (!('EventSource' in window)) {
        //         console.warn('SSE not supported in this browser');
        //         return;
        //     }
        //     let source = new EventSource('/events');
        //     let isOpen = false;
        //     source.onopen = function(){ isOpen = true; console.log('SSE connected'); };
        //     source.onmessage = function(e){
        //         const msg=(e.data||'').trim(); if(!msg) return;
        //         console.log('SSE message:', msg);
        //         if (msg==='reload' || msg==='incremental') { location.reload(); }
        //         // Ignore 'loading' to avoid premature reload loops
        //     };
        //     source.onerror = function(e){
        //         // Let EventSource auto-reconnect instead of forcing a reload
        //         if (isOpen) console.warn('SSE error after open, retrying...', e);
        //     };
        //     window.addEventListener('beforeunload', function(){ try{source.close();}catch(_){} });
        // })();


        document.addEventListener('DOMContentLoaded', function() {
            // Capture initial cell states before any modifications
            captureInitialCellStates();
            
            updateThemeIcon();
            updateUiMenu();
            updateUiDebug();
            const widgetsEnabled = (document.documentElement.getAttribute('data-widgets') || 'on') === 'on';
            if (widgetsEnabled) {
            initMinimap();
            initFileExplorer();
            initTools();
            initOverlay();
            initStatusWidget();
            initializeWidgetVisibility();
            layoutWidgetsStackedBottomRight();
            window.addEventListener('resize', layoutWidgetsStackedBottomRight);
            }

            // Apply deep-link selection if present
            applyLocationFromUrl();
            updateStateIndicator();
            
            // Apply cell states from URL immediately
            const url = new URL(window.location.href);
            const encodedCellStates = url.searchParams.get('cells');
            if (encodedCellStates) {
                console.log('Applying cell states from URL...');
                const cellStates = decodeCellStatesFromUrl(encodedCellStates);
                
                // Use requestAnimationFrame to ensure DOM is ready
                requestAnimationFrame(() => {
                    applyCellStatesFromUrl(cellStates);
                    
                    // Clear initialization flag after cell states are applied
                    if (typeof _isInitializing !== 'undefined') {
                        _isInitializing = false;
                    }
                });
            } else {
                // Clear initialization flag even if no cell states
                if (typeof _isInitializing !== 'undefined') {
                    requestAnimationFrame(() => {
                        _isInitializing = false;
                    });
                }
            }

            // Bind drag selection on line numbers
            document.addEventListener('mousedown', onLineNumberMouseDown);
            document.addEventListener('mousemove', onDocMouseMove);
            document.addEventListener('mouseup', onDocMouseUp);

            // Add ESC key handler to exit tools
            document.addEventListener('keydown', function(e) {
                if (e.key === 'Escape' || e.keyCode === 27) {
                    const currentTool = document.body.dataset.tool;
                    if (currentTool && currentTool !== 'none') {
                        // Deactivate the current tool
                        window.setActiveTool('none');
                    }
                    // Also clear any active line selection
                    clearSelection(true);
                }
            });
        });

        function updateStateIndicator() {
            try {
                const el = document.getElementById('status-widget');
                if (!el) return;
                const tool = document.body.dataset.tool || 'none';
                if (tool && tool !== 'none') {
                    el.textContent = `tool: ${tool} — Esc`;
                    return;
                }
                if (_selection) {
                    const t = _selection.a === _selection.b ? `L${_selection.a}` : `L${_selection.a}-${_selection.b}`;
                    el.textContent = `selected: ${t} — Esc`;
                    return;
                }
                el.textContent = 'ready — Esc';
            } catch (_) {}
        }
    </script>
</head>


<body>
    <div class="controls">
        <div class="controls-buttons">
            
            <a href="index.html" class="back-button">← back</a>
            
            <div class="theme-toggle" onclick="toggleTheme()">light</div>
            <div class="reset-toggle" onclick="resetLayout()">reset</div>
            <div class="menu-button" onclick="toggleMenu()">
                menu ▼
                <div class="menu-dropdown">
                    <div class="menu-item" onclick="setUiTheme('default')">
                        <span class="menu-checkbox" id="checkbox-ui-default"></span> Theme: default
                    </div>
                    <div class="menu-item" onclick="setUiTheme('none')">
                        <span class="menu-checkbox" id="checkbox-ui-none"></span> Theme: none
                    </div>
                    <div class="menu-item" onclick="setUiTheme('monocolor')">
                        <span class="menu-checkbox" id="checkbox-ui-monocolor"></span> Theme: monocolor
                    </div>
                    <div class="menu-item" onclick="toggleWidget('tools')">
                        <span class="menu-checkbox" id="checkbox-tools"></span> Tools
                    </div>
                    <div class="menu-item" onclick="toggleWidget('file-explorer')">
                        <span class="menu-checkbox" id="checkbox-file-explorer"></span> File Explorer
                    </div>
                    <div class="menu-item" onclick="toggleWidget('minimap')">
                        <span class="menu-checkbox" id="checkbox-minimap"></span> Table of Contents
                    </div>
                    <div class="menu-item" onclick="toggleWidget('status')">
                        <span class="menu-checkbox" id="checkbox-status"></span> Status Indicator
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <div class="system-info">
        <div class="system-info-header">Generated on:</div>
        <div class="system-info-content">
            Linux x86_64 | Linux-5.10.244-240.970.amzn2.x86_64-x86_64-with-glibc2.35
        </div>
    </div>
    
    <div class="main-content">
        <h1>HF Kernels - Rotary Position Embeddings</h1>
<h2>GPU Info</h2>
<div class="cell" id="cell-nv">
<div class="cell-header">
<span class="collapse-indicators">
<span onclick="toggleCode('nv')" style="cursor: pointer;">▼ code</span> 
<span onclick="toggleOutput('nv')" style="cursor: pointer;">▼ output</span>
 <span id="uv-indicator-nv" style="cursor: default; opacity: 0.3;">▶ uv-logs</span>
</span> | 
Cell: nv | 0.23s
 | <button class="run-btn" onclick="runCell('nv')">▶ run</button>
<button class="copy-btn" onclick="copyCell('nv')">Copy</button>
<a href="cells/nv.py" target="_blank" class="raw-btn">Raw</a>
<a href="https://github.com/huggingface/kernels-benchmarks/blob/main/rotary/impls/hf_kernels_rotary.md" target="_blank" class="github-btn">GitHub</a>
<a href="https://huggingface.co/kernels-community/rotary" target="_blank" class="hf-btn">🤗 HF</a>
</div>
<div id="code-nv" class="cell-code" data-lines="2">
<div class="code-wrap">
<div class="highlight"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">subprocess</span>
<span class="nb">print</span><span class="p">(</span><span class="n">subprocess</span><span class="o">.</span><span class="n">run</span><span class="p">([</span><span class="s2">&quot;nvidia-smi&quot;</span><span class="p">],</span> <span class="n">capture_output</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">text</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span><span class="o">.</span><span class="n">stdout</span><span class="p">)</span>
</pre></div>

<div class="code-line-highlight" id="line-highlight-nv"></div>
</div>
</div>
<div id="output-nv" class="cell-output">
<div class="cell-stdout"><pre class="stdout-text">Fri Oct 31 20:00:00 2025       
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 570.195.03             Driver Version: 570.195.03     CUDA Version: 12.8     |
|-----------------------------------------+------------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id          Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |           Memory-Usage | GPU-Util  Compute M. |
|                                         |                        |               MIG M. |
|=========================================+========================+======================|
|   0  NVIDIA L40S                    On  |   00000000:4D:00.0 Off |                    0 |
| N/A   32C    P0            101W /  350W |       0MiB /  46068MiB |    100%      Default |
|                                         |                        |                  N/A |
+-----------------------------------------+------------------------+----------------------+

+-----------------------------------------------------------------------------------------+
| Processes:                                                                              |
|  GPU   GI   CI              PID   Type   Process name                        GPU Memory |
|        ID   ID                                                               Usage      |
|=========================================================================================|
|  No running processes found                                                             |
+-----------------------------------------------------------------------------------------+

</pre></div>
</div>
</div>

<h2>Rotary Embeddings Benchmark</h2>
<div class="cell" id="cell-benchmark">
<div class="cell-header">
<span class="collapse-indicators">
<span onclick="toggleCode('benchmark')" style="cursor: pointer;">▼ code</span> 
<span onclick="toggleOutput('benchmark')" style="cursor: pointer;">▼ output</span>
 <span id="uv-indicator-benchmark" onclick="toggleUvLogsFromHeader('benchmark')" style="cursor: pointer;">▶ uv-logs</span>
</span> | 
Cell: benchmark | 4.67s
 | <button class="run-btn" onclick="runCell('benchmark')">▶ run</button>
<button class="copy-btn" onclick="copyCell('benchmark')">Copy</button>
<a href="cells/benchmark.py" target="_blank" class="raw-btn">Raw</a>
<a href="https://github.com/huggingface/kernels-benchmarks/blob/main/rotary/impls/hf_kernels_rotary.md" target="_blank" class="github-btn">GitHub</a>
<a href="https://huggingface.co/kernels-community/rotary" target="_blank" class="hf-btn">🤗 HF</a>
</div>
<div id="code-benchmark" class="cell-code" data-lines="48">
<div class="code-wrap">
<div class="highlight"><pre><span></span><span class="c1"># /// script</span>
<span class="c1"># requires-python = &quot;&gt;=3.10&quot;</span>
<span class="c1"># dependencies = [</span>
<span class="c1">#     &quot;numpy&quot;,</span>
<span class="c1">#     &quot;torch==2.8.0&quot;,</span>
<span class="c1">#     &quot;kernels-benchmark-tools&quot;,</span>
<span class="c1">#     &quot;kernels&quot;,</span>
<span class="c1"># ]</span>
<span class="c1">#</span>
<span class="c1"># [tool.uv.sources]</span>
<span class="c1"># kernels-benchmark-tools = { path = &quot;../../../../../tools&quot;, editable = true }</span>
<span class="c1"># ///</span>
<span class="kn">import</span><span class="w"> </span><span class="nn">torch</span>
<span class="kn">import</span><span class="w"> </span><span class="nn">sys</span>
<span class="kn">from</span><span class="w"> </span><span class="nn">kernels_benchmark_tools</span><span class="w"> </span><span class="kn">import</span> <span class="n">KernelTypeEnum</span><span class="p">,</span> <span class="n">run_benchmark</span>
<span class="kn">from</span><span class="w"> </span><span class="nn">kernels</span><span class="w"> </span><span class="kn">import</span> <span class="n">get_kernel</span>

<span class="c1"># Load the rotary kernel</span>
<span class="n">rotary</span> <span class="o">=</span> <span class="n">get_kernel</span><span class="p">(</span><span class="s2">&quot;kernels-community/rotary&quot;</span><span class="p">)</span>


<span class="k">def</span><span class="w"> </span><span class="nf">hf_kernels_rotary</span><span class="p">(</span><span class="n">query</span><span class="p">,</span> <span class="n">key</span><span class="p">,</span> <span class="n">cos</span><span class="p">,</span> <span class="n">sin</span><span class="p">,</span> <span class="n">conj</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
    <span class="n">rotary_dim</span> <span class="o">=</span> <span class="n">cos</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>

    <span class="c1"># Clone to avoid modifying inputs</span>
    <span class="n">q_out</span> <span class="o">=</span> <span class="n">query</span><span class="o">.</span><span class="n">clone</span><span class="p">()</span>
    <span class="n">k_out</span> <span class="o">=</span> <span class="n">key</span><span class="o">.</span><span class="n">clone</span><span class="p">()</span>

    <span class="c1"># Apply rotation to query</span>
    <span class="n">q1</span> <span class="o">=</span> <span class="n">q_out</span><span class="p">[</span><span class="o">...</span><span class="p">,</span> <span class="p">:</span><span class="n">rotary_dim</span><span class="p">]</span>
    <span class="n">q2</span> <span class="o">=</span> <span class="n">q_out</span><span class="p">[</span><span class="o">...</span><span class="p">,</span> <span class="n">rotary_dim</span> <span class="p">:</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">rotary_dim</span><span class="p">]</span>
    <span class="n">rotary</span><span class="o">.</span><span class="n">apply_rotary</span><span class="p">(</span><span class="n">q1</span><span class="p">,</span> <span class="n">q2</span><span class="p">,</span> <span class="n">cos</span><span class="p">,</span> <span class="n">sin</span><span class="p">,</span> <span class="n">q1</span><span class="p">,</span> <span class="n">q2</span><span class="p">,</span> <span class="n">conj</span><span class="p">)</span>

    <span class="c1"># Apply rotation to key</span>
    <span class="n">k1</span> <span class="o">=</span> <span class="n">k_out</span><span class="p">[</span><span class="o">...</span><span class="p">,</span> <span class="p">:</span><span class="n">rotary_dim</span><span class="p">]</span>
    <span class="n">k2</span> <span class="o">=</span> <span class="n">k_out</span><span class="p">[</span><span class="o">...</span><span class="p">,</span> <span class="n">rotary_dim</span> <span class="p">:</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">rotary_dim</span><span class="p">]</span>
    <span class="n">rotary</span><span class="o">.</span><span class="n">apply_rotary</span><span class="p">(</span><span class="n">k1</span><span class="p">,</span> <span class="n">k2</span><span class="p">,</span> <span class="n">cos</span><span class="p">,</span> <span class="n">sin</span><span class="p">,</span> <span class="n">k1</span><span class="p">,</span> <span class="n">k2</span><span class="p">,</span> <span class="n">conj</span><span class="p">)</span>

    <span class="k">return</span> <span class="n">q_out</span><span class="p">,</span> <span class="n">k_out</span>


<span class="n">run_benchmark</span><span class="p">(</span>
    <span class="n">kernel_type</span><span class="o">=</span><span class="n">KernelTypeEnum</span><span class="o">.</span><span class="n">ROTARY</span><span class="p">,</span>
    <span class="n">impl_name</span><span class="o">=</span><span class="s2">&quot;hf_kernels_rotary&quot;</span><span class="p">,</span>
    <span class="n">impl_tags</span><span class="o">=</span><span class="p">{</span><span class="s2">&quot;family&quot;</span><span class="p">:</span> <span class="s2">&quot;hf-kernels&quot;</span><span class="p">,</span> <span class="s2">&quot;backend&quot;</span><span class="p">:</span> <span class="s2">&quot;cuda&quot;</span><span class="p">},</span>
    <span class="n">impl_func</span><span class="o">=</span><span class="n">hf_kernels_rotary</span><span class="p">,</span>
    <span class="n">dtype</span><span class="o">=</span><span class="s2">&quot;float32&quot;</span><span class="p">,</span>
<span class="p">)</span>
</pre></div>

<div class="code-line-highlight" id="line-highlight-benchmark"></div>
</div>
</div>
<div id="output-benchmark" class="cell-output">
<div class="cell-stdout"><pre class="stdout-text">Running rotary benchmark on cuda with 24 workloads.

======================================================================
PROFILE TRACE: hf_kernels_rotary | cuda_B1_S128_H8_D64_R32
======================================================================
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
                                                   Name    Self CPU %      Self CPU   CPU total %     CPU total  CPU time avg     Self CUDA   Self CUDA %    CUDA total  CUDA time avg    # of Calls  
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
                                      hf_kernels_rotary         0.00%       0.000us         0.00%       0.000us       0.000us     426.303us      1837.51%     426.303us     426.303us             1  
                                      hf_kernels_rotary        12.40%     260.056us        99.66%       2.090ms       2.090ms       0.000us         0.00%      24.480us      24.480us             1  
                          _rotary_dba7d1e::apply_rotary         2.75%      57.674us         5.07%     106.315us      17.719us      16.128us        69.52%      16.128us       2.688us             6  
void at::native::(anonymous namespace)::unrolled_ele...         0.00%       0.000us         0.00%       0.000us       0.000us      16.128us        69.52%      16.128us       2.688us             6  
                                            aten::clone         2.13%      44.582us        79.34%       1.664ms     277.309us       0.000us         0.00%       8.352us       1.392us             6  
                                            aten::copy_         1.84%      38.562us        74.44%       1.561ms     260.165us       7.072us        30.48%       8.352us       1.392us             6  
                         Memcpy DtoD (Device -&gt; Device)         0.00%       0.000us         0.00%       0.000us       0.000us       7.072us        30.48%       7.072us       1.179us             6  
                                Activity Buffer Request        69.01%       1.447ms        69.01%       1.447ms       1.447ms       1.280us         5.52%       1.280us       1.280us             1  
                                    aten::empty_strided         2.78%      58.281us         2.78%      58.281us       9.713us       0.000us         0.00%       0.000us       0.000us             6  
                                        cudaMemcpyAsync         3.58%      75.121us         3.58%      75.121us      12.520us       0.000us         0.00%       0.000us       0.000us             6  
                                            aten::slice         2.14%      44.780us         2.85%      59.790us       4.983us       0.000us         0.00%       0.000us       0.000us            12  
                                       aten::as_strided         0.72%      15.010us         0.72%      15.010us       1.251us       0.000us         0.00%       0.000us       0.000us            12  
                                       cudaLaunchKernel         2.32%      48.641us         2.32%      48.641us       8.107us       0.000us         0.00%       0.000us       0.000us             6  
                                  cudaDeviceSynchronize         0.34%       7.100us         0.34%       7.100us       7.100us       0.000us         0.00%       0.000us       0.000us             1  
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
Self CPU time total: 2.097ms
Self CUDA time total: 23.200us



======================================================================
PROFILE TRACE: hf_kernels_rotary | cuda_B1_S128_H8_D128_R64
======================================================================
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
                                                   Name    Self CPU %      Self CPU   CPU total %     CPU total  CPU time avg     Self CUDA   Self CUDA %    CUDA total  CUDA time avg    # of Calls  
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
                                      hf_kernels_rotary         0.00%       0.000us         0.00%       0.000us       0.000us     340.796us      1422.00%     340.796us     340.796us             1  
                                      hf_kernels_rotary         9.48%     182.026us        99.73%       1.916ms       1.916ms       0.000us         0.00%      25.278us      25.278us             1  
                          _rotary_dba7d1e::apply_rotary         2.22%      42.701us         4.40%      84.531us      14.088us      16.159us        67.42%      16.159us       2.693us             6  
void at::native::(anonymous namespace)::unrolled_ele...         0.00%       0.000us         0.00%       0.000us       0.000us      16.159us        67.42%      16.159us       2.693us             6  
                                            aten::clone         1.41%      27.120us        83.58%       1.605ms     267.570us       0.000us         0.00%       9.119us       1.520us             6  
                                            aten::copy_         2.02%      38.773us        80.45%       1.545ms     257.555us       7.807us        32.58%       9.119us       1.520us             6  
                         Memcpy DtoD (Device -&gt; Device)         0.00%       0.000us         0.00%       0.000us       0.000us       7.807us        32.58%       7.807us       1.301us             6  
                                Activity Buffer Request        75.56%       1.451ms        75.56%       1.451ms       1.451ms       1.312us         5.47%       1.312us       1.312us             1  
                                    aten::empty_strided         1.72%      32.970us         1.72%      32.970us       5.495us       0.000us         0.00%       0.000us       0.000us             6  
                                        cudaMemcpyAsync         2.88%      55.291us         2.88%      55.291us       9.215us       0.000us         0.00%       0.000us       0.000us             6  
                                            aten::slice         1.76%      33.749us         2.27%      43.642us       3.637us       0.000us         0.00%       0.000us       0.000us            12  
                                       aten::as_strided         0.52%       9.893us         0.52%       9.893us       0.824us       0.000us         0.00%       0.000us       0.000us            12  
                                       cudaLaunchKernel         2.18%      41.830us         2.18%      41.830us       6.972us       0.000us         0.00%       0.000us       0.000us             6  
                                  cudaDeviceSynchronize         0.27%       5.161us         0.27%       5.161us       5.161us       0.000us         0.00%       0.000us       0.000us             1  
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
Self CPU time total: 1.921ms
Self CUDA time total: 23.966us



======================================================================
PROFILE TRACE: hf_kernels_rotary | cuda_B1_S128_H32_D64_R32
======================================================================
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
                                                   Name    Self CPU %      Self CPU   CPU total %     CPU total  CPU time avg     Self CUDA   Self CUDA %    CUDA total  CUDA time avg    # of Calls  
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
                                      hf_kernels_rotary         0.00%       0.000us         0.00%       0.000us       0.000us     339.421us      1391.81%     339.421us     339.421us             1  
                                      hf_kernels_rotary         9.18%     172.926us        99.76%       1.879ms       1.879ms       0.000us         0.00%      25.699us      25.699us             1  
                          _rotary_dba7d1e::apply_rotary         2.20%      41.409us         4.51%      85.000us      14.167us      16.481us        67.58%      16.481us       2.747us             6  
void at::native::(anonymous namespace)::unrolled_ele...         0.00%       0.000us         0.00%       0.000us       0.000us      16.481us        67.58%      16.481us       2.747us             6  
                                            aten::clone         1.46%      27.581us        83.73%       1.577ms     262.862us       0.000us         0.00%       9.218us       1.536us             6  
                                            aten::copy_         1.97%      37.091us        80.45%       1.515ms     252.563us       7.906us        32.42%       9.218us       1.536us             6  
                         Memcpy DtoD (Device -&gt; Device)         0.00%       0.000us         0.00%       0.000us       0.000us       7.906us        32.42%       7.906us       1.318us             6  
                                Activity Buffer Request        75.71%       1.426ms        75.71%       1.426ms       1.426ms       1.312us         5.38%       1.312us       1.312us             1  
                                    aten::empty_strided         1.82%      34.210us         1.82%      34.210us       5.702us       0.000us         0.00%       0.000us       0.000us             6  
                                        cudaMemcpyAsync         2.77%      52.231us         2.77%      52.231us       8.705us       0.000us         0.00%       0.000us       0.000us             6  
                                            aten::slice         1.80%      33.892us         2.33%      43.952us       3.663us       0.000us         0.00%       0.000us       0.000us            12  
                                       aten::as_strided         0.53%      10.060us         0.53%      10.060us       0.838us       0.000us         0.00%       0.000us       0.000us            12  
                                       cudaLaunchKernel         2.31%      43.591us         2.31%      43.591us       7.265us       0.000us         0.00%       0.000us       0.000us             6  
                                  cudaDeviceSynchronize         0.24%       4.550us         0.24%       4.550us       4.550us       0.000us         0.00%       0.000us       0.000us             1  
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
Self CPU time total: 1.884ms
Self CUDA time total: 24.387us



======================================================================
PROFILE TRACE: hf_kernels_rotary | cuda_B1_S128_H32_D128_R64
======================================================================
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
                                                   Name    Self CPU %      Self CPU   CPU total %     CPU total  CPU time avg     Self CUDA   Self CUDA %    CUDA total  CUDA time avg    # of Calls  
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
                                      hf_kernels_rotary         0.00%       0.000us         0.00%       0.000us       0.000us     353.466us      1252.36%     353.466us     353.466us             1  
                                      hf_kernels_rotary         8.35%     176.747us        99.76%       2.111ms       2.111ms       0.000us         0.00%      30.048us      30.048us             1  
                          _rotary_dba7d1e::apply_rotary         2.17%      45.850us         4.21%      89.000us      14.833us      17.664us        62.59%      17.664us       2.944us             6  
void at::native::(anonymous namespace)::unrolled_ele...         0.00%       0.000us         0.00%       0.000us       0.000us      17.664us        62.59%      17.664us       2.944us             6  
                                            aten::clone         1.36%      28.714us        85.13%       1.802ms     300.274us       0.000us         0.00%      12.384us       2.064us             6  
                                            aten::copy_         1.83%      38.751us        82.20%       1.740ms     289.944us      10.560us        37.41%      12.384us       2.064us             6  
                         Memcpy DtoD (Device -&gt; Device)         0.00%       0.000us         0.00%       0.000us       0.000us      10.560us        37.41%      10.560us       1.760us             6  
                                Activity Buffer Request        67.60%       1.431ms        67.60%       1.431ms       1.431ms       1.824us         6.46%       1.824us       1.824us             1  
                                    aten::empty_strided         1.57%      33.269us         1.57%      33.269us       5.545us       0.000us         0.00%       0.000us       0.000us             6  
                                        cudaMemcpyAsync        12.77%     270.306us        12.77%     270.306us      45.051us       0.000us         0.00%       0.000us       0.000us             6  
                                            aten::slice         1.59%      33.568us         2.07%      43.911us       3.659us       0.000us         0.00%       0.000us       0.000us            12  
                                       aten::as_strided         0.49%      10.343us         0.49%      10.343us       0.862us       0.000us         0.00%       0.000us       0.000us            12  
                                       cudaLaunchKernel         2.04%      43.150us         2.04%      43.150us       7.192us       0.000us         0.00%       0.000us       0.000us             6  
                                  cudaDeviceSynchronize         0.24%       5.130us         0.24%       5.130us       5.130us       0.000us         0.00%       0.000us       0.000us             1  
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
Self CPU time total: 2.116ms
Self CUDA time total: 28.224us



======================================================================
PROFILE TRACE: hf_kernels_rotary | cuda_B1_S512_H8_D64_R32
======================================================================
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
                                                   Name    Self CPU %      Self CPU   CPU total %     CPU total  CPU time avg     Self CUDA   Self CUDA %    CUDA total  CUDA time avg    # of Calls  
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
                                      hf_kernels_rotary         0.00%       0.000us         0.00%       0.000us       0.000us     351.740us      1444.46%     351.740us     351.740us             1  
                                      hf_kernels_rotary         8.68%     176.155us        99.77%       2.024ms       2.024ms       0.000us         0.00%      25.663us      25.663us             1  
                          _rotary_dba7d1e::apply_rotary         2.27%      46.099us         4.32%      87.680us      14.613us      16.479us        67.67%      16.479us       2.747us             6  
void at::native::(anonymous namespace)::unrolled_ele...         0.00%       0.000us         0.00%       0.000us       0.000us      16.479us        67.67%      16.479us       2.747us             6  
                                            aten::clone         1.42%      28.832us        84.62%       1.717ms     286.091us       0.000us         0.00%       9.184us       1.531us             6  
                                            aten::copy_         1.86%      37.831us        81.49%       1.653ms     275.519us       7.872us        32.33%       9.184us       1.531us             6  
                         Memcpy DtoD (Device -&gt; Device)         0.00%       0.000us         0.00%       0.000us       0.000us       7.872us        32.33%       7.872us       1.312us             6  
                                Activity Buffer Request        70.03%       1.420ms        70.03%       1.420ms       1.420ms       1.312us         5.39%       1.312us       1.312us             1  
                                    aten::empty_strided         1.71%      34.601us         1.71%      34.601us       5.767us       0.000us         0.00%       0.000us       0.000us             6  
                                        cudaMemcpyAsync         9.60%     194.784us         9.60%     194.784us      32.464us       0.000us         0.00%       0.000us       0.000us             6  
                                            aten::slice         1.63%      33.102us         2.14%      43.512us       3.626us       0.000us         0.00%       0.000us       0.000us            12  
                                       aten::as_strided         0.51%      10.410us         0.51%      10.410us       0.867us       0.000us         0.00%       0.000us       0.000us            12  
                                       cudaLaunchKernel         2.05%      41.581us         2.05%      41.581us       6.930us       0.000us         0.00%       0.000us       0.000us             6  
                                  cudaDeviceSynchronize         0.23%       4.660us         0.23%       4.660us       4.660us       0.000us         0.00%       0.000us       0.000us             1  
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
Self CPU time total: 2.029ms
Self CUDA time total: 24.351us



======================================================================
PROFILE TRACE: hf_kernels_rotary | cuda_B1_S512_H8_D128_R64
======================================================================
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
                                                   Name    Self CPU %      Self CPU   CPU total %     CPU total  CPU time avg     Self CUDA   Self CUDA %    CUDA total  CUDA time avg    # of Calls  
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
                                      hf_kernels_rotary         0.00%       0.000us         0.00%       0.000us       0.000us     349.111us      1238.38%     349.111us     349.111us             1  
                                      hf_kernels_rotary        23.24%     192.013us        99.32%     820.571us     820.571us       0.000us         0.00%      30.015us      30.015us             1  
                          _rotary_dba7d1e::apply_rotary         5.42%      44.795us        10.63%      87.866us      14.644us      17.632us        62.54%      17.632us       2.939us             6  
void at::native::(anonymous namespace)::unrolled_ele...         0.00%       0.000us         0.00%       0.000us       0.000us      17.632us        62.54%      17.632us       2.939us             6  
                                            aten::clone         2.69%      22.223us        60.09%     496.442us      82.740us       0.000us         0.00%      12.383us       2.064us             6  
                                            aten::copy_         4.60%      38.000us        53.48%     441.890us      73.648us      10.559us        37.46%      12.383us       2.064us             6  
                         Memcpy DtoD (Device -&gt; Device)         0.00%       0.000us         0.00%       0.000us       0.000us      10.559us        37.46%      10.559us       1.760us             6  
                                Activity Buffer Request        26.48%     218.816us        26.48%     218.816us     218.816us       1.824us         6.47%       1.824us       1.824us             1  
                                    aten::empty_strided         3.91%      32.329us         3.91%      32.329us       5.388us       0.000us         0.00%       0.000us       0.000us             6  
                                        cudaMemcpyAsync        22.40%     185.074us        22.40%     185.074us      30.846us       0.000us         0.00%       0.000us       0.000us             6  
                                            aten::slice         4.04%      33.410us         5.36%      44.250us       3.688us       0.000us         0.00%       0.000us       0.000us            12  
                                       aten::as_strided         1.31%      10.840us         1.31%      10.840us       0.903us       0.000us         0.00%       0.000us       0.000us            12  
                                       cudaLaunchKernel         5.21%      43.071us         5.21%      43.071us       7.178us       0.000us         0.00%       0.000us       0.000us             6  
                                  cudaDeviceSynchronize         0.68%       5.641us         0.68%       5.641us       5.641us       0.000us         0.00%       0.000us       0.000us             1  
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
Self CPU time total: 826.212us
Self CUDA time total: 28.191us



======================================================================
PROFILE TRACE: hf_kernels_rotary | cuda_B1_S512_H32_D64_R32
======================================================================
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
                                                   Name    Self CPU %      Self CPU   CPU total %     CPU total  CPU time avg     Self CUDA   Self CUDA %    CUDA total  CUDA time avg    # of Calls  
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
                                      hf_kernels_rotary         0.00%       0.000us         0.00%       0.000us       0.000us     344.984us       852.93%     344.984us     344.984us             1  
                                      hf_kernels_rotary        22.02%     168.975us        99.39%     762.759us     762.759us       0.000us         0.00%      43.263us      43.263us             1  
                          _rotary_dba7d1e::apply_rotary         5.75%      44.162us        11.18%      85.802us      14.300us      23.456us        57.99%      23.456us       3.909us             6  
void at::native::(anonymous namespace)::unrolled_ele...         0.00%       0.000us         0.00%       0.000us       0.000us      23.456us        57.99%      23.456us       3.909us             6  
                                            aten::clone         2.91%      22.350us        60.45%     463.932us      77.322us       0.000us         0.00%      19.807us       3.301us             6  
                                            aten::copy_         4.98%      38.249us        53.45%     410.170us      68.362us      16.991us        42.01%      19.807us       3.301us             6  
                         Memcpy DtoD (Device -&gt; Device)         0.00%       0.000us         0.00%       0.000us       0.000us      16.991us        42.01%      16.991us       2.832us             6  
                                Activity Buffer Request        24.55%     188.395us        24.55%     188.395us     188.395us       2.816us         6.96%       2.816us       2.816us             1  
                                    aten::empty_strided         4.09%      31.412us         4.09%      31.412us       5.235us       0.000us         0.00%       0.000us       0.000us             6  
                                        cudaMemcpyAsync        23.91%     183.526us        23.91%     183.526us      30.588us       0.000us         0.00%       0.000us       0.000us             6  
                                            aten::slice         4.40%      33.790us         5.74%      44.050us       3.671us       0.000us         0.00%       0.000us       0.000us            12  
                                       aten::as_strided         1.34%      10.260us         1.34%      10.260us       0.855us       0.000us         0.00%       0.000us       0.000us            12  
                                       cudaLaunchKernel         5.43%      41.640us         5.43%      41.640us       6.940us       0.000us         0.00%       0.000us       0.000us             6  
                                  cudaDeviceSynchronize         0.61%       4.661us         0.61%       4.661us       4.661us       0.000us         0.00%       0.000us       0.000us             1  
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
Self CPU time total: 767.420us
Self CUDA time total: 40.447us



======================================================================
PROFILE TRACE: hf_kernels_rotary | cuda_B1_S512_H32_D128_R64
======================================================================
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
                                                   Name    Self CPU %      Self CPU   CPU total %     CPU total  CPU time avg     Self CUDA   Self CUDA %    CUDA total  CUDA time avg    # of Calls  
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
                                      hf_kernels_rotary         0.00%       0.000us         0.00%       0.000us       0.000us     347.453us       442.64%     347.453us     347.453us             1  
                                      hf_kernels_rotary        20.37%     160.826us        99.39%     784.751us     784.751us       0.000us         0.00%      91.040us      91.040us             1  
                                            aten::clone         2.83%      22.340us        62.44%     492.983us      82.164us       0.000us         0.00%      52.865us       8.811us             6  
                                            aten::copy_         4.65%      36.740us        55.30%     436.663us      72.777us      40.321us        51.37%      52.865us       8.811us             6  
                         Memcpy DtoD (Device -&gt; Device)         0.00%       0.000us         0.00%       0.000us       0.000us      40.321us        51.37%      40.321us       6.720us             6  
                          _rotary_dba7d1e::apply_rotary         5.74%      45.350us        11.00%      86.891us      14.482us      38.175us        48.63%      38.175us       6.362us             6  
void at::native::(anonymous namespace)::unrolled_ele...         0.00%       0.000us         0.00%       0.000us       0.000us      38.175us        48.63%      38.175us       6.362us             6  
                                Activity Buffer Request        27.86%     219.946us        27.86%     219.946us     219.946us      12.544us        15.98%      12.544us      12.544us             1  
                                    aten::empty_strided         4.30%      33.980us         4.30%      33.980us       5.663us       0.000us         0.00%       0.000us       0.000us             6  
                                        cudaMemcpyAsync        22.79%     179.977us        22.79%     179.977us      29.996us       0.000us         0.00%       0.000us       0.000us             6  
                                            aten::slice         4.35%      34.361us         5.58%      44.051us       3.671us       0.000us         0.00%       0.000us       0.000us            12  
                                       aten::as_strided         1.23%       9.690us         1.23%       9.690us       0.808us       0.000us         0.00%       0.000us       0.000us            12  
                                       cudaLaunchKernel         5.26%      41.541us         5.26%      41.541us       6.924us       0.000us         0.00%       0.000us       0.000us             6  
                                  cudaDeviceSynchronize         0.61%       4.830us         0.61%       4.830us       4.830us       0.000us         0.00%       0.000us       0.000us             1  
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
Self CPU time total: 789.581us
Self CUDA time total: 78.496us



======================================================================
PROFILE TRACE: hf_kernels_rotary | cuda_B1_S2048_H8_D64_R32
======================================================================
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
                                                   Name    Self CPU %      Self CPU   CPU total %     CPU total  CPU time avg     Self CUDA   Self CUDA %    CUDA total  CUDA time avg    # of Calls  
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
                                      hf_kernels_rotary         0.00%       0.000us         0.00%       0.000us       0.000us     347.324us       858.06%     347.324us     347.324us             1  
                                      hf_kernels_rotary         8.65%     173.958us        99.77%       2.007ms       2.007ms       0.000us         0.00%      43.325us      43.325us             1  
                          _rotary_dba7d1e::apply_rotary         2.18%      43.910us         4.21%      84.770us      14.128us      23.423us        57.87%      23.423us       3.904us             6  
void at::native::(anonymous namespace)::unrolled_ele...         0.00%       0.000us         0.00%       0.000us       0.000us      23.423us        57.87%      23.423us       3.904us             6  
                                            aten::clone         1.35%      27.211us        84.83%       1.706ms     284.405us       0.000us         0.00%      19.902us       3.317us             6  
                                            aten::copy_         1.92%      38.681us        81.76%       1.645ms     274.138us      17.055us        42.13%      19.902us       3.317us             6  
                         Memcpy DtoD (Device -&gt; Device)         0.00%       0.000us         0.00%       0.000us       0.000us      17.055us        42.13%      17.055us       2.842us             6  
                                Activity Buffer Request        70.68%       1.422ms        70.68%       1.422ms       1.422ms       2.847us         7.03%       2.847us       2.847us             1  
                                    aten::empty_strided         1.71%      34.392us         1.71%      34.392us       5.732us       0.000us         0.00%       0.000us       0.000us             6  
                                        cudaMemcpyAsync         9.16%     184.363us         9.16%     184.363us      30.727us       0.000us         0.00%       0.000us       0.000us             6  
                                            aten::slice         1.62%      32.593us         2.08%      41.861us       3.488us       0.000us         0.00%       0.000us       0.000us            12  
                                       aten::as_strided         0.46%       9.268us         0.46%       9.268us       0.772us       0.000us         0.00%       0.000us       0.000us            12  
                                       cudaLaunchKernel         2.03%      40.860us         2.03%      40.860us       6.810us       0.000us         0.00%       0.000us       0.000us             6  
                                  cudaDeviceSynchronize         0.23%       4.670us         0.23%       4.670us       4.670us       0.000us         0.00%       0.000us       0.000us             1  
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
Self CPU time total: 2.012ms
Self CUDA time total: 40.478us



======================================================================
PROFILE TRACE: hf_kernels_rotary | cuda_B1_S2048_H8_D128_R64
======================================================================
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
                                                   Name    Self CPU %      Self CPU   CPU total %     CPU total  CPU time avg     Self CUDA   Self CUDA %    CUDA total  CUDA time avg    # of Calls  
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
                                      hf_kernels_rotary         0.00%       0.000us         0.00%       0.000us       0.000us     361.785us       476.45%     361.785us     361.785us             1  
                                      hf_kernels_rotary         8.64%     176.662us        99.77%       2.040ms       2.040ms       0.000us         0.00%      86.685us      86.685us             1  
                                            aten::clone         1.40%      28.682us        84.64%       1.731ms     288.486us       0.000us         0.00%      47.871us       7.979us             6  
                                            aten::copy_         1.80%      36.737us        81.55%       1.668ms     277.962us      37.119us        48.88%      47.871us       7.979us             6  
                          _rotary_dba7d1e::apply_rotary         2.24%      45.910us         4.34%      88.820us      14.803us      38.814us        51.12%      38.814us       6.469us             6  
void at::native::(anonymous namespace)::unrolled_ele...         0.00%       0.000us         0.00%       0.000us       0.000us      38.814us        51.12%      38.814us       6.469us             6  
                         Memcpy DtoD (Device -&gt; Device)         0.00%       0.000us         0.00%       0.000us       0.000us      37.119us        48.88%      37.119us       6.187us             6  
                                Activity Buffer Request        70.82%       1.448ms        70.82%       1.448ms       1.448ms      10.752us        14.16%      10.752us      10.752us             1  
                                    aten::empty_strided         1.69%      34.462us         1.69%      34.462us       5.744us       0.000us         0.00%       0.000us       0.000us             6  
                                        cudaMemcpyAsync         8.93%     182.677us         8.93%     182.677us      30.446us       0.000us         0.00%       0.000us       0.000us             6  
                                            aten::slice         1.66%      33.994us         2.15%      43.925us       3.660us       0.000us         0.00%       0.000us       0.000us            12  
                                       aten::as_strided         0.49%       9.931us         0.49%       9.931us       0.828us       0.000us         0.00%       0.000us       0.000us            12  
                                       cudaLaunchKernel         2.10%      42.910us         2.10%      42.910us       7.152us       0.000us         0.00%       0.000us       0.000us             6  
                                  cudaDeviceSynchronize         0.23%       4.670us         0.23%       4.670us       4.670us       0.000us         0.00%       0.000us       0.000us             1  
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
Self CPU time total: 2.045ms
Self CUDA time total: 75.933us



======================================================================
PROFILE TRACE: hf_kernels_rotary | cuda_B1_S2048_H32_D64_R32
======================================================================
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
                                                   Name    Self CPU %      Self CPU   CPU total %     CPU total  CPU time avg     Self CUDA   Self CUDA %    CUDA total  CUDA time avg    # of Calls  
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
                                      hf_kernels_rotary         0.00%       0.000us         0.00%       0.000us       0.000us     373.629us       268.97%     373.629us     373.629us             1  
                                      hf_kernels_rotary         8.95%     179.578us        99.78%       2.002ms       2.002ms       0.000us         0.00%     162.750us     162.750us             1  
                                            aten::clone         1.48%      29.597us        83.94%       1.684ms     280.680us       0.000us         0.00%     102.944us      17.157us             6  
                                            aten::copy_         1.82%      36.553us        80.73%       1.620ms     269.962us      79.104us        56.95%     102.944us      17.157us             6  
                         Memcpy DtoD (Device -&gt; Device)         0.00%       0.000us         0.00%       0.000us       0.000us      79.104us        56.95%      79.104us      13.184us             6  
                          _rotary_dba7d1e::apply_rotary         2.30%      46.131us         4.57%      91.713us      15.285us      59.806us        43.05%      59.806us       9.968us             6  
void at::native::(anonymous namespace)::unrolled_ele...         0.00%       0.000us         0.00%       0.000us       0.000us      59.806us        43.05%      59.806us       9.968us             6  
                                Activity Buffer Request        69.91%       1.403ms        69.91%       1.403ms       1.403ms      23.840us        17.16%      23.840us      23.840us             1  
                                    aten::empty_strided         1.73%      34.712us         1.73%      34.712us       5.785us       0.000us         0.00%       0.000us       0.000us             6  
                                        cudaMemcpyAsync         9.00%     180.563us         9.00%     180.563us      30.094us       0.000us         0.00%       0.000us       0.000us             6  
                                            aten::slice         1.75%      35.198us         2.31%      46.409us       3.867us       0.000us         0.00%       0.000us       0.000us            12  
                                       aten::as_strided         0.56%      11.211us         0.56%      11.211us       0.934us       0.000us         0.00%       0.000us       0.000us            12  
                                       cudaLaunchKernel         2.27%      45.582us         2.27%      45.582us       7.597us       0.000us         0.00%       0.000us       0.000us             6  
                                  cudaDeviceSynchronize         0.22%       4.510us         0.22%       4.510us       4.510us       0.000us         0.00%       0.000us       0.000us             1  
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
Self CPU time total: 2.006ms
Self CUDA time total: 138.910us



======================================================================
PROFILE TRACE: hf_kernels_rotary | cuda_B1_S2048_H32_D128_R64
======================================================================
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
                                                   Name    Self CPU %      Self CPU   CPU total %     CPU total  CPU time avg     Self CUDA   Self CUDA %    CUDA total  CUDA time avg    # of Calls  
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
                                      hf_kernels_rotary         7.56%     177.196us        86.68%       2.032ms       2.032ms       0.000us         0.00%     778.402us     778.402us             1  
                                      hf_kernels_rotary         0.00%       0.000us         0.00%       0.000us       0.000us     717.248us       101.07%     717.248us     717.248us             1  
                                            aten::clone         1.23%      28.772us        72.98%       1.711ms     285.141us       0.000us         0.00%     578.626us      96.438us             6  
                                            aten::copy_         1.64%      38.341us        70.23%       1.646ms     274.415us     509.889us        71.85%     578.626us      96.438us             6  
                         Memcpy DtoD (Device -&gt; Device)         0.00%       0.000us         0.00%       0.000us       0.000us     509.889us        71.85%     509.889us      84.982us             6  
                          _rotary_dba7d1e::apply_rotary         2.34%      54.801us         4.25%      99.591us      16.598us     199.776us        28.15%     199.776us      33.296us             6  
void at::native::(anonymous namespace)::unrolled_ele...         0.00%       0.000us         0.00%       0.000us       0.000us     199.776us        28.15%     199.776us      33.296us             6  
                                Activity Buffer Request        60.86%       1.427ms        60.86%       1.427ms       1.427ms      68.737us         9.69%      68.737us      68.737us             1  
                                    aten::empty_strided         1.52%      35.581us         1.52%      35.581us       5.930us       0.000us         0.00%       0.000us       0.000us             6  
                                        cudaMemcpyAsync         7.74%     181.435us         7.74%     181.435us      30.239us       0.000us         0.00%       0.000us       0.000us             6  
                                            aten::slice         1.41%      33.151us         1.89%      44.330us       3.694us       0.000us         0.00%       0.000us       0.000us            12  
                                       aten::as_strided         0.48%      11.179us         0.48%      11.179us       0.932us       0.000us         0.00%       0.000us       0.000us            12  
                                       cudaLaunchKernel         1.91%      44.790us         1.91%      44.790us       7.465us       0.000us         0.00%       0.000us       0.000us             6  
                                  cudaDeviceSynchronize        13.32%     312.348us        13.32%     312.348us     312.348us       0.000us         0.00%       0.000us       0.000us             1  
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
Self CPU time total: 2.344ms
Self CUDA time total: 709.665us



======================================================================
PROFILE TRACE: hf_kernels_rotary | cuda_B2_S128_H8_D64_R32
======================================================================
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
                                                   Name    Self CPU %      Self CPU   CPU total %     CPU total  CPU time avg     Self CUDA   Self CUDA %    CUDA total  CUDA time avg    # of Calls  
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
                                      hf_kernels_rotary         0.00%       0.000us         0.00%       0.000us       0.000us     349.629us      1313.11%     349.629us     349.629us             1  
                                      hf_kernels_rotary         8.75%     174.875us        99.76%       1.994ms       1.994ms       0.000us         0.00%      27.938us      27.938us             1  
                          _rotary_dba7d1e::apply_rotary         2.16%      43.200us         4.40%      87.900us      14.650us      18.754us        70.43%      18.754us       3.126us             6  
void at::native::(anonymous namespace)::unrolled_ele...         0.00%       0.000us         0.00%       0.000us       0.000us      18.754us        70.43%      18.754us       3.126us             6  
                                            aten::clone         1.44%      28.720us        84.48%       1.688ms     281.365us       0.000us         0.00%       9.184us       1.531us             6  
                                            aten::copy_         1.82%      36.432us        81.36%       1.626ms     271.003us       7.872us        29.57%       9.184us       1.531us             6  
                         Memcpy DtoD (Device -&gt; Device)         0.00%       0.000us         0.00%       0.000us       0.000us       7.872us        29.57%       7.872us       1.312us             6  
                                Activity Buffer Request        70.53%       1.410ms        70.53%       1.410ms       1.410ms       1.312us         4.93%       1.312us       1.312us             1  
                                    aten::empty_strided         1.67%      33.452us         1.67%      33.452us       5.575us       0.000us         0.00%       0.000us       0.000us             6  
                                        cudaMemcpyAsync         9.01%     180.083us         9.01%     180.083us      30.014us       0.000us         0.00%       0.000us       0.000us             6  
                                            aten::slice         1.63%      32.560us         2.14%      42.684us       3.557us       0.000us         0.00%       0.000us       0.000us            12  
                                       aten::as_strided         0.51%      10.124us         0.51%      10.124us       0.844us       0.000us         0.00%       0.000us       0.000us            12  
                                       cudaLaunchKernel         2.24%      44.700us         2.24%      44.700us       7.450us       0.000us         0.00%       0.000us       0.000us             6  
                                  cudaDeviceSynchronize         0.24%       4.780us         0.24%       4.780us       4.780us       0.000us         0.00%       0.000us       0.000us             1  
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
Self CPU time total: 1.998ms
Self CUDA time total: 26.626us



======================================================================
PROFILE TRACE: hf_kernels_rotary | cuda_B2_S128_H8_D128_R64
======================================================================
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
                                                   Name    Self CPU %      Self CPU   CPU total %     CPU total  CPU time avg     Self CUDA   Self CUDA %    CUDA total  CUDA time avg    # of Calls  
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
                                      hf_kernels_rotary         0.00%       0.000us         0.00%       0.000us       0.000us     344.698us      1282.22%     344.698us     344.698us             1  
                                      hf_kernels_rotary        22.61%     152.757us        99.23%     670.538us     670.538us       0.000us         0.00%      28.195us      28.195us             1  
                          _rotary_dba7d1e::apply_rotary         6.64%      44.870us        12.97%      87.630us      14.605us      19.009us        70.71%      19.009us       3.168us             6  
void at::native::(anonymous namespace)::unrolled_ele...         0.00%       0.000us         0.00%       0.000us       0.000us      19.009us        70.71%      19.009us       3.168us             6  
                                            aten::clone         3.38%      22.839us        57.25%     386.869us      64.478us       0.000us         0.00%       9.186us       1.531us             6  
                                            aten::copy_         5.63%      38.041us        49.11%     331.829us      55.305us       7.874us        29.29%       9.186us       1.531us             6  
                         Memcpy DtoD (Device -&gt; Device)         0.00%       0.000us         0.00%       0.000us       0.000us       7.874us        29.29%       7.874us       1.312us             6  
                                Activity Buffer Request        16.48%     111.363us        16.48%     111.363us     111.363us       1.312us         4.88%       1.312us       1.312us             1  
                                    aten::empty_strided         4.77%      32.201us         4.77%      32.201us       5.367us       0.000us         0.00%       0.000us       0.000us             6  
                                        cudaMemcpyAsync        27.00%     182.425us        27.00%     182.425us      30.404us       0.000us         0.00%       0.000us       0.000us             6  
                                            aten::slice         4.90%      33.085us         6.41%      43.282us       3.607us       0.000us         0.00%       0.000us       0.000us            12  
                                       aten::as_strided         1.51%      10.197us         1.51%      10.197us       0.850us       0.000us         0.00%       0.000us       0.000us            12  
                                       cudaLaunchKernel         6.33%      42.760us         6.33%      42.760us       7.127us       0.000us         0.00%       0.000us       0.000us             6  
                                  cudaDeviceSynchronize         0.77%       5.200us         0.77%       5.200us       5.200us       0.000us         0.00%       0.000us       0.000us             1  
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
Self CPU time total: 675.738us
Self CUDA time total: 26.883us



======================================================================
PROFILE TRACE: hf_kernels_rotary | cuda_B2_S128_H32_D64_R32
======================================================================
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
                                                   Name    Self CPU %      Self CPU   CPU total %     CPU total  CPU time avg     Self CUDA   Self CUDA %    CUDA total  CUDA time avg    # of Calls  
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
                                      hf_kernels_rotary         0.00%       0.000us         0.00%       0.000us       0.000us     350.004us      1141.75%     350.004us     350.004us             1  
                                      hf_kernels_rotary        19.05%     154.214us        99.36%     804.261us     804.261us       0.000us         0.00%      32.414us      32.414us             1  
                          _rotary_dba7d1e::apply_rotary         5.47%      44.240us        10.98%      88.910us      14.818us      20.064us        65.45%      20.064us       3.344us             6  
void at::native::(anonymous namespace)::unrolled_ele...         0.00%       0.000us         0.00%       0.000us       0.000us      20.064us        65.45%      20.064us       3.344us             6  
                                            aten::clone         3.02%      24.421us        63.80%     516.433us      86.072us       0.000us         0.00%      12.350us       2.058us             6  
                                            aten::copy_         4.66%      37.732us        56.69%     458.901us      76.483us      10.591us        34.55%      12.350us       2.058us             6  
                         Memcpy DtoD (Device -&gt; Device)         0.00%       0.000us         0.00%       0.000us       0.000us      10.591us        34.55%      10.591us       1.765us             6  
                                Activity Buffer Request        29.69%     240.306us        29.69%     240.306us     240.306us       1.759us         5.74%       1.759us       1.759us             1  
                                    aten::empty_strided         4.09%      33.111us         4.09%      33.111us       5.518us       0.000us         0.00%       0.000us       0.000us             6  
                                        cudaMemcpyAsync        22.34%     180.863us        22.34%     180.863us      30.144us       0.000us         0.00%       0.000us       0.000us             6  
                                            aten::slice         4.15%      33.594us         5.52%      44.704us       3.725us       0.000us         0.00%       0.000us       0.000us            12  
                                       aten::as_strided         1.37%      11.110us         1.37%      11.110us       0.926us       0.000us         0.00%       0.000us       0.000us            12  
                                       cudaLaunchKernel         5.52%      44.670us         5.52%      44.670us       7.445us       0.000us         0.00%       0.000us       0.000us             6  
                                  cudaDeviceSynchronize         0.64%       5.201us         0.64%       5.201us       5.201us       0.000us         0.00%       0.000us       0.000us             1  
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
Self CPU time total: 809.462us
Self CUDA time total: 30.655us



======================================================================
PROFILE TRACE: hf_kernels_rotary | cuda_B2_S128_H32_D128_R64
======================================================================
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
                                                   Name    Self CPU %      Self CPU   CPU total %     CPU total  CPU time avg     Self CUDA   Self CUDA %    CUDA total  CUDA time avg    # of Calls  
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
                                      hf_kernels_rotary         0.00%       0.000us         0.00%       0.000us       0.000us     350.355us       822.64%     350.355us     350.355us             1  
                                      hf_kernels_rotary        19.55%     155.605us        99.35%     790.981us     790.981us       0.000us         0.00%      45.469us      45.469us             1  
                          _rotary_dba7d1e::apply_rotary         5.55%      44.191us        11.02%      87.731us      14.622us      25.565us        60.03%      25.565us       4.261us             6  
void at::native::(anonymous namespace)::unrolled_ele...         0.00%       0.000us         0.00%       0.000us       0.000us      25.565us        60.03%      25.565us       4.261us             6  
                                            aten::clone         2.81%      22.389us        63.13%     502.593us      83.766us       0.000us         0.00%      19.904us       3.317us             6  
                                            aten::copy_         4.90%      39.043us        56.13%     446.833us      74.472us      17.024us        39.97%      19.904us       3.317us             6  
                         Memcpy DtoD (Device -&gt; Device)         0.00%       0.000us         0.00%       0.000us       0.000us      17.024us        39.97%      17.024us       2.837us             6  
                                Activity Buffer Request        28.37%     225.886us        28.37%     225.886us     225.886us       2.880us         6.76%       2.880us       2.880us             1  
                                    aten::empty_strided         4.19%      33.371us         4.19%      33.371us       5.562us       0.000us         0.00%       0.000us       0.000us             6  
                                        cudaMemcpyAsync        22.85%     181.904us        22.85%     181.904us      30.317us       0.000us         0.00%       0.000us       0.000us             6  
                                            aten::slice         4.29%      34.142us         5.66%      45.052us       3.754us       0.000us         0.00%       0.000us       0.000us            12  
                                       aten::as_strided         1.37%      10.910us         1.37%      10.910us       0.909us       0.000us         0.00%       0.000us       0.000us            12  
                                       cudaLaunchKernel         5.47%      43.540us         5.47%      43.540us       7.257us       0.000us         0.00%       0.000us       0.000us             6  
                                  cudaDeviceSynchronize         0.65%       5.140us         0.65%       5.140us       5.140us       0.000us         0.00%       0.000us       0.000us             1  
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
Self CPU time total: 796.121us
Self CUDA time total: 42.589us



======================================================================
PROFILE TRACE: hf_kernels_rotary | cuda_B2_S512_H8_D64_R32
======================================================================
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
                                                   Name    Self CPU %      Self CPU   CPU total %     CPU total  CPU time avg     Self CUDA   Self CUDA %    CUDA total  CUDA time avg    # of Calls  
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
                                      hf_kernels_rotary         0.00%       0.000us         0.00%       0.000us       0.000us     344.951us      1133.59%     344.951us     344.951us             1  
                                      hf_kernels_rotary        19.05%     153.418us        99.42%     800.680us     800.680us       0.000us         0.00%      32.125us      32.125us             1  
                          _rotary_dba7d1e::apply_rotary         5.43%      43.718us        10.83%      87.180us      14.530us      20.095us        66.04%      20.095us       3.349us             6  
void at::native::(anonymous namespace)::unrolled_ele...         0.00%       0.000us         0.00%       0.000us       0.000us      20.095us        66.04%      20.095us       3.349us             6  
                                            aten::clone         2.75%      22.180us        64.20%     517.012us      86.169us       0.000us         0.00%      12.030us       2.005us             6  
                                            aten::copy_         4.82%      38.813us        57.22%     460.802us      76.800us      10.335us        33.96%      12.030us       2.005us             6  
                         Memcpy DtoD (Device -&gt; Device)         0.00%       0.000us         0.00%       0.000us       0.000us      10.335us        33.96%      10.335us       1.722us             6  
                                Activity Buffer Request        30.13%     242.666us        30.13%     242.666us     242.666us       1.695us         5.57%       1.695us       1.695us             1  
                                    aten::empty_strided         4.23%      34.030us         4.23%      34.030us       5.672us       0.000us         0.00%       0.000us       0.000us             6  
                                        cudaMemcpyAsync        22.27%     179.323us        22.27%     179.323us      29.887us       0.000us         0.00%       0.000us       0.000us             6  
                                            aten::slice         4.11%      33.131us         5.35%      43.070us       3.589us       0.000us         0.00%       0.000us       0.000us            12  
                                       aten::as_strided         1.23%       9.939us         1.23%       9.939us       0.828us       0.000us         0.00%       0.000us       0.000us            12  
                                       cudaLaunchKernel         5.40%      43.462us         5.40%      43.462us       7.244us       0.000us         0.00%       0.000us       0.000us             6  
                                  cudaDeviceSynchronize         0.58%       4.660us         0.58%       4.660us       4.660us       0.000us         0.00%       0.000us       0.000us             1  
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
Self CPU time total: 805.340us
Self CUDA time total: 30.430us



======================================================================
PROFILE TRACE: hf_kernels_rotary | cuda_B2_S512_H8_D128_R64
======================================================================
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
                                                   Name    Self CPU %      Self CPU   CPU total %     CPU total  CPU time avg     Self CUDA   Self CUDA %    CUDA total  CUDA time avg    # of Calls  
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
                                      hf_kernels_rotary         0.00%       0.000us         0.00%       0.000us       0.000us     358.905us       840.15%     358.905us     358.905us             1  
                                      hf_kernels_rotary        15.26%     159.123us        99.55%       1.038ms       1.038ms       0.000us         0.00%      45.598us      45.598us             1  
                          _rotary_dba7d1e::apply_rotary         4.27%      44.490us         8.42%      87.790us      14.632us      25.600us        59.93%      25.600us       4.267us             6  
void at::native::(anonymous namespace)::unrolled_ele...         0.00%       0.000us         0.00%       0.000us       0.000us      25.600us        59.93%      25.600us       4.267us             6  
                                            aten::clone         2.23%      23.211us        71.54%     746.059us     124.343us       0.000us         0.00%      19.998us       3.333us             6  
                                            aten::copy_         3.70%      38.572us        65.96%     687.817us     114.636us      17.119us        40.07%      19.998us       3.333us             6  
                         Memcpy DtoD (Device -&gt; Device)         0.00%       0.000us         0.00%       0.000us       0.000us      17.119us        40.07%      17.119us       2.853us             6  
                                Activity Buffer Request        44.90%     468.242us        44.90%     468.242us     468.242us       2.879us         6.74%       2.879us       2.879us             1  
                                    aten::empty_strided         3.36%      35.031us         3.36%      35.031us       5.838us       0.000us         0.00%       0.000us       0.000us             6  
                                        cudaMemcpyAsync        17.36%     181.003us        17.36%     181.003us      30.167us       0.000us         0.00%       0.000us       0.000us             6  
                                            aten::slice         3.32%      34.604us         4.33%      45.135us       3.761us       0.000us         0.00%       0.000us       0.000us            12  
                                       aten::as_strided         1.01%      10.531us         1.01%      10.531us       0.878us       0.000us         0.00%       0.000us       0.000us            12  
                                       cudaLaunchKernel         4.15%      43.300us         4.15%      43.300us       7.217us       0.000us         0.00%       0.000us       0.000us             6  
                                  cudaDeviceSynchronize         0.45%       4.700us         0.45%       4.700us       4.700us       0.000us         0.00%       0.000us       0.000us             1  
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
Self CPU time total: 1.043ms
Self CUDA time total: 42.719us



======================================================================
PROFILE TRACE: hf_kernels_rotary | cuda_B2_S512_H32_D64_R32
======================================================================
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
                                                   Name    Self CPU %      Self CPU   CPU total %     CPU total  CPU time avg     Self CUDA   Self CUDA %    CUDA total  CUDA time avg    # of Calls  
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
                                      hf_kernels_rotary         0.00%       0.000us         0.00%       0.000us       0.000us     383.638us       432.19%     383.638us     383.638us             1  
                                      hf_kernels_rotary        19.20%     158.364us        99.38%     819.611us     819.611us       0.000us         0.00%     103.870us     103.870us             1  
                                            aten::clone         2.74%      22.581us        61.51%     507.313us      84.552us       0.000us         0.00%      63.135us      10.522us             6  
                                            aten::copy_         4.83%      39.811us        54.76%     451.622us      75.270us      48.031us        54.11%      63.135us      10.522us             6  
                         Memcpy DtoD (Device -&gt; Device)         0.00%       0.000us         0.00%       0.000us       0.000us      48.031us        54.11%      48.031us       8.005us             6  
                          _rotary_dba7d1e::apply_rotary         5.49%      45.243us        13.16%     108.504us      18.084us      40.735us        45.89%      40.735us       6.789us             6  
void at::native::(anonymous namespace)::unrolled_ele...         0.00%       0.000us         0.00%       0.000us       0.000us      40.735us        45.89%      40.735us       6.789us             6  
                                Activity Buffer Request        27.50%     226.825us        27.50%     226.825us     226.825us      15.104us        17.02%      15.104us      15.104us             1  
                                    aten::empty_strided         4.01%      33.110us         4.01%      33.110us       5.518us       0.000us         0.00%       0.000us       0.000us             6  
                                        cudaMemcpyAsync        22.43%     184.986us        22.43%     184.986us      30.831us       0.000us         0.00%       0.000us       0.000us             6  
                                            aten::slice         4.25%      35.021us         5.51%      45.430us       3.786us       0.000us         0.00%       0.000us       0.000us            12  
                                       aten::as_strided         1.26%      10.409us         1.26%      10.409us       0.867us       0.000us         0.00%       0.000us       0.000us            12  
                                       cudaLaunchKernel         7.67%      63.261us         7.67%      63.261us      10.543us       0.000us         0.00%       0.000us       0.000us             6  
                                  cudaDeviceSynchronize         0.62%       5.141us         0.62%       5.141us       5.141us       0.000us         0.00%       0.000us       0.000us             1  
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
Self CPU time total: 824.752us
Self CUDA time total: 88.766us



======================================================================
PROFILE TRACE: hf_kernels_rotary | cuda_B2_S512_H32_D128_R64
======================================================================
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
                                                   Name    Self CPU %      Self CPU   CPU total %     CPU total  CPU time avg     Self CUDA   Self CUDA %    CUDA total  CUDA time avg    # of Calls  
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
                                      hf_kernels_rotary         0.00%       0.000us         0.00%       0.000us       0.000us     359.259us       247.18%     359.259us     359.259us             1  
                                      hf_kernels_rotary        19.06%     158.337us        99.39%     825.781us     825.781us       0.000us         0.00%     168.829us     168.829us             1  
                                            aten::clone         2.83%      23.549us        64.09%     532.493us      88.749us       0.000us         0.00%     105.470us      17.578us             6  
                                            aten::copy_         4.58%      38.013us        57.29%     475.972us      79.329us      81.982us        56.41%     105.470us      17.578us             6  
                         Memcpy DtoD (Device -&gt; Device)         0.00%       0.000us         0.00%       0.000us       0.000us      81.982us        56.41%      81.982us      13.664us             6  
                          _rotary_dba7d1e::apply_rotary         5.47%      45.451us        10.86%      90.251us      15.042us      63.359us        43.59%      63.359us      10.560us             6  
void at::native::(anonymous namespace)::unrolled_ele...         0.00%       0.000us         0.00%       0.000us       0.000us      63.359us        43.59%      63.359us      10.560us             6  
                                Activity Buffer Request        31.29%     259.966us        31.29%     259.966us     259.966us      23.488us        16.16%      23.488us      23.488us             1  
                                    aten::empty_strided         3.97%      32.972us         3.97%      32.972us       5.495us       0.000us         0.00%       0.000us       0.000us             6  
                                        cudaMemcpyAsync        21.42%     177.993us        21.42%     177.993us      29.665us       0.000us         0.00%       0.000us       0.000us             6  
                                            aten::slice         4.19%      34.839us         5.38%      44.700us       3.725us       0.000us         0.00%       0.000us       0.000us            12  
                                       aten::as_strided         1.19%       9.861us         1.19%       9.861us       0.822us       0.000us         0.00%       0.000us       0.000us            12  
                                       cudaLaunchKernel         5.39%      44.800us         5.39%      44.800us       7.467us       0.000us         0.00%       0.000us       0.000us             6  
                                  cudaDeviceSynchronize         0.61%       5.100us         0.61%       5.100us       5.100us       0.000us         0.00%       0.000us       0.000us             1  
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
Self CPU time total: 830.881us
Self CUDA time total: 145.341us



======================================================================
PROFILE TRACE: hf_kernels_rotary | cuda_B2_S2048_H8_D64_R32
======================================================================
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
                                                   Name    Self CPU %      Self CPU   CPU total %     CPU total  CPU time avg     Self CUDA   Self CUDA %    CUDA total  CUDA time avg    # of Calls  
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
                                      hf_kernels_rotary         0.00%       0.000us         0.00%       0.000us       0.000us     385.725us       509.05%     385.725us     385.725us             1  
                                      hf_kernels_rotary         8.62%     176.456us        99.78%       2.043ms       2.043ms       0.000us         0.00%      82.558us      82.558us             1  
                          _rotary_dba7d1e::apply_rotary         2.32%      47.603us         4.41%      90.273us      15.045us      41.694us        55.02%      41.694us       6.949us             6  
void at::native::(anonymous namespace)::unrolled_ele...         0.00%       0.000us         0.00%       0.000us       0.000us      41.694us        55.02%      41.694us       6.949us             6  
                                            aten::clone         1.42%      29.000us        84.54%       1.731ms     288.534us       0.000us         0.00%      40.864us       6.811us             6  
                                            aten::copy_         1.93%      39.552us        80.14%       1.641ms     273.497us      34.080us        44.98%      40.864us       6.811us             6  
                         Memcpy DtoD (Device -&gt; Device)         0.00%       0.000us         0.00%       0.000us       0.000us      34.080us        44.98%      34.080us       5.680us             6  
                                Activity Buffer Request        69.16%       1.416ms        69.16%       1.416ms       1.416ms       6.784us         8.95%       6.784us       6.784us             1  
                                    aten::empty_strided         2.99%      61.221us         2.99%      61.221us      10.204us       0.000us         0.00%       0.000us       0.000us             6  
                                        cudaMemcpyAsync         9.05%     185.224us         9.05%     185.224us      30.871us       0.000us         0.00%       0.000us       0.000us             6  
                                            aten::slice         1.69%      34.591us         2.21%      45.260us       3.772us       0.000us         0.00%       0.000us       0.000us            12  
                                       aten::as_strided         0.52%      10.669us         0.52%      10.669us       0.889us       0.000us         0.00%       0.000us       0.000us            12  
                                       cudaLaunchKernel         2.08%      42.670us         2.08%      42.670us       7.112us       0.000us         0.00%       0.000us       0.000us             6  
                                  cudaDeviceSynchronize         0.22%       4.530us         0.22%       4.530us       4.530us       0.000us         0.00%       0.000us       0.000us             1  
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
Self CPU time total: 2.048ms
Self CUDA time total: 75.774us



======================================================================
PROFILE TRACE: hf_kernels_rotary | cuda_B2_S2048_H8_D128_R64
======================================================================
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
                                                   Name    Self CPU %      Self CPU   CPU total %     CPU total  CPU time avg     Self CUDA   Self CUDA %    CUDA total  CUDA time avg    # of Calls  
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
                                      hf_kernels_rotary         0.00%       0.000us         0.00%       0.000us       0.000us     368.925us       253.94%     368.925us     368.925us             1  
                                      hf_kernels_rotary         8.62%     177.641us        99.74%       2.055ms       2.055ms       0.000us         0.00%     169.118us     169.118us             1  
                                            aten::clone         1.42%      29.322us        84.62%       1.743ms     290.539us       0.000us         0.00%     105.470us      17.578us             6  
                                            aten::copy_         1.92%      39.462us        81.52%       1.679ms     279.897us      81.631us        56.19%     105.470us      17.578us             6  
                         Memcpy DtoD (Device -&gt; Device)         0.00%       0.000us         0.00%       0.000us       0.000us      81.631us        56.19%      81.631us      13.605us             6  
                          _rotary_dba7d1e::apply_rotary         2.27%      46.683us         4.40%      90.665us      15.111us      63.648us        43.81%      63.648us      10.608us             6  
void at::native::(anonymous namespace)::unrolled_ele...         0.00%       0.000us         0.00%       0.000us       0.000us      63.648us        43.81%      63.648us      10.608us             6  
                                Activity Buffer Request        70.79%       1.458ms        70.79%       1.458ms       1.458ms      23.839us        16.41%      23.839us      23.839us             1  
                                    aten::empty_strided         1.68%      34.530us         1.68%      34.530us       5.755us       0.000us         0.00%       0.000us       0.000us             6  
                                        cudaMemcpyAsync         8.81%     181.504us         8.81%     181.504us      30.251us       0.000us         0.00%       0.000us       0.000us             6  
                                            aten::slice         1.62%      33.289us         2.09%      43.080us       3.590us       0.000us         0.00%       0.000us       0.000us            12  
                                       aten::as_strided         0.48%       9.791us         0.48%       9.791us       0.816us       0.000us         0.00%       0.000us       0.000us            12  
                                       cudaLaunchKernel         2.13%      43.982us         2.13%      43.982us       7.330us       0.000us         0.00%       0.000us       0.000us             6  
                                  cudaDeviceSynchronize         0.26%       5.450us         0.26%       5.450us       5.450us       0.000us         0.00%       0.000us       0.000us             1  
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
Self CPU time total: 2.060ms
Self CUDA time total: 145.279us



======================================================================
PROFILE TRACE: hf_kernels_rotary | cuda_B2_S2048_H32_D64_R32
======================================================================
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
                                                   Name    Self CPU %      Self CPU   CPU total %     CPU total  CPU time avg     Self CUDA   Self CUDA %    CUDA total  CUDA time avg    # of Calls  
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
                                      hf_kernels_rotary        20.72%     223.838us        78.32%     845.992us     845.992us       0.000us         0.00%     747.476us     747.476us             1  
                                      hf_kernels_rotary         0.00%       0.000us         0.00%       0.000us       0.000us     688.117us       101.15%     688.117us     688.117us             1  
                                            aten::clone         2.05%      22.091us        45.23%     488.522us      81.420us       0.000us         0.00%     558.423us      93.070us             6  
                                            aten::copy_         3.67%      39.650us        40.20%     434.190us      72.365us     491.256us        72.21%     558.423us      93.070us             6  
                         Memcpy DtoD (Device -&gt; Device)         0.00%       0.000us         0.00%       0.000us       0.000us     491.256us        72.21%     491.256us      81.876us             6  
                          _rotary_dba7d1e::apply_rotary         4.18%      45.161us         8.45%      91.252us      15.209us     189.053us        27.79%     189.053us      31.509us             6  
void at::native::(anonymous namespace)::unrolled_ele...         0.00%       0.000us         0.00%       0.000us       0.000us     189.053us        27.79%     189.053us      31.509us             6  
                                Activity Buffer Request        19.62%     211.896us        19.62%     211.896us     211.896us      67.167us         9.87%      67.167us      67.167us             1  
                                    aten::empty_strided         2.98%      32.241us         2.98%      32.241us       5.374us       0.000us         0.00%       0.000us       0.000us             6  
                                        cudaMemcpyAsync        16.91%     182.644us        16.91%     182.644us      30.441us       0.000us         0.00%       0.000us       0.000us             6  
                                            aten::slice         3.05%      32.939us         3.92%      42.380us       3.532us       0.000us         0.00%       0.000us       0.000us            12  
                                       aten::as_strided         0.87%       9.441us         0.87%       9.441us       0.787us       0.000us         0.00%       0.000us       0.000us            12  
                                       cudaLaunchKernel         4.27%      46.091us         4.27%      46.091us       7.682us       0.000us         0.00%       0.000us       0.000us             6  
                                  cudaDeviceSynchronize        21.68%     234.186us        21.68%     234.186us     234.186us       0.000us         0.00%       0.000us       0.000us             1  
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
Self CPU time total: 1.080ms
Self CUDA time total: 680.309us



======================================================================
PROFILE TRACE: hf_kernels_rotary | cuda_B2_S2048_H32_D128_R64
======================================================================
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
                                                   Name    Self CPU %      Self CPU   CPU total %     CPU total  CPU time avg     Self CUDA   Self CUDA %    CUDA total  CUDA time avg    # of Calls  
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
                                      hf_kernels_rotary         5.41%     154.946us        27.83%     797.061us     797.061us       0.000us         0.00%       2.625ms       2.625ms             1  
                                      hf_kernels_rotary         0.00%       0.000us         0.00%       0.000us       0.000us       2.453ms       100.31%       2.453ms       2.453ms             1  
                                            aten::clone         0.79%      22.601us        17.83%     510.683us      85.114us       0.000us         0.00%       1.396ms     232.586us             6  
                                            aten::copy_         1.43%      40.940us        15.89%     455.120us      75.853us       1.216ms        49.74%       1.396ms     232.586us             6  
                          _rotary_dba7d1e::apply_rotary         1.59%      45.590us         3.06%      87.640us      14.607us       1.229ms        50.26%       1.229ms     204.885us             6  
void at::native::(anonymous namespace)::unrolled_ele...         0.00%       0.000us         0.00%       0.000us       0.000us       1.229ms        50.26%       1.229ms     204.885us             6  
                         Memcpy DtoD (Device -&gt; Device)         0.00%       0.000us         0.00%       0.000us       0.000us       1.216ms        49.74%       1.216ms     202.730us             6  
                                Activity Buffer Request         7.23%     207.076us         7.23%     207.076us     207.076us     179.136us         7.32%     179.136us     179.136us             1  
                                    aten::empty_strided         1.15%      32.962us         1.15%      32.962us       5.494us       0.000us         0.00%       0.000us       0.000us             6  
                                        cudaMemcpyAsync         7.23%     207.104us         7.23%     207.104us      34.517us       0.000us         0.00%       0.000us       0.000us             6  
                                            aten::slice         1.15%      33.011us         1.53%      43.792us       3.649us       0.000us         0.00%       0.000us       0.000us            12  
                                       aten::as_strided         0.38%      10.781us         0.38%      10.781us       0.898us       0.000us         0.00%       0.000us       0.000us            12  
                                       cudaLaunchKernel         1.47%      42.050us         1.47%      42.050us       7.008us       0.000us         0.00%       0.000us       0.000us             6  
                                  cudaDeviceSynchronize        72.17%       2.067ms        72.17%       2.067ms       2.067ms       0.000us         0.00%       0.000us       0.000us             1  
-------------------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  
Self CPU time total: 2.864ms
Self CUDA time total: 2.446ms


impl                     wl                  p50(ms)  ok
hf_kernels_rotary        cuda_B1_S128_H32_D128_R64     0.09  True
hf_kernels_rotary        cuda_B1_S128_H32_D64_R32     0.09  True
hf_kernels_rotary        cuda_B1_S128_H8_D128_R64     0.09  True
hf_kernels_rotary        cuda_B1_S128_H8_D64_R32     0.08  True
hf_kernels_rotary        cuda_B1_S2048_H32_D128_R64     0.26  True
hf_kernels_rotary        cuda_B1_S2048_H32_D64_R32     0.10  True
hf_kernels_rotary        cuda_B1_S2048_H8_D128_R64     0.10  True
hf_kernels_rotary        cuda_B1_S2048_H8_D64_R32     0.09  True
hf_kernels_rotary        cuda_B1_S512_H32_D128_R64     0.09  True
hf_kernels_rotary        cuda_B1_S512_H32_D64_R32     0.09  True
hf_kernels_rotary        cuda_B1_S512_H8_D128_R64     0.09  True
hf_kernels_rotary        cuda_B1_S512_H8_D64_R32     0.09  True
hf_kernels_rotary        cuda_B2_S128_H32_D128_R64     0.09  True
hf_kernels_rotary        cuda_B2_S128_H32_D64_R32     0.09  True
hf_kernels_rotary        cuda_B2_S128_H8_D128_R64     0.09  True
hf_kernels_rotary        cuda_B2_S128_H8_D64_R32     0.09  True
hf_kernels_rotary        cuda_B2_S2048_H32_D128_R64     0.85  True
hf_kernels_rotary        cuda_B2_S2048_H32_D64_R32     0.27  True
hf_kernels_rotary        cuda_B2_S2048_H8_D128_R64     0.09  True
hf_kernels_rotary        cuda_B2_S2048_H8_D64_R32     0.09  True
hf_kernels_rotary        cuda_B2_S512_H32_D128_R64     0.09  True
hf_kernels_rotary        cuda_B2_S512_H32_D64_R32     0.09  True
hf_kernels_rotary        cuda_B2_S512_H8_D128_R64     0.09  True
hf_kernels_rotary        cuda_B2_S512_H8_D64_R32     0.09  True
</pre></div>
<div class="uv-install-logs" id="uv-logs-benchmark">
<div class="uv-logs-header" onclick="toggleUvLogs(this)">▶ UV Install Logs</div>
<div class="uv-logs-content" style="display: none;">
Installed 15 packages in 14ms
</div>
</div>
<div class="cell-stderr">Fetching 5 files:   0%|          | 0/5 [00:00&lt;?, ?it/s]
Fetching 5 files:  60%|██████    | 3/5 [00:00&lt;00:00, 28.46it/s]
Fetching 5 files: 100%|██████████| 5/5 [00:00&lt;00:00,  9.80it/s]</div>
<div class="cell-artifacts">
<h4>Artifacts:</h4>
<a href="artifacts/benchmark/rotary.jsonl" class="artifact" target="_blank">rotary.jsonl</a>
</div>
</div>
</div>
    </div>
    
</body>
</html>