Ideas of how to fit a door here?
I presume you’re going to get a Building Permit to do the work. If so, I can see several Code violations that you’ll need to correct:

Incorrect height of handrail.

Handrail does not extend far enough at top of stair.

Height of ceiling on top landing is too low.

Incorrect bedroom window size. Window needs to be changed to egress window regardless if the door is added or not. (Egress window has a minimum opening width and height for emergency exiting...and emergency rescue.)

Smoke detector is required for sleeping rooms...


If you add the door, make sure the top landing remains the width of the stairway and has a depth of 36” in the direction of the stair, if the door swings out over the landing. (See ICC R311.5.4) No required size of landing is required if the door does not swing out over the landing.
Maybe the new door could swing into the bedroom.