Character controller flying into space when pressing jump key while not moving on X and Z axes

I am a beginner and am creating my first ever slightly big game( have made some small ones). it is an fps game. I have attached a character controller to it. It works literally fine. It jumps fine while moving but, when the character is not moving, and I press the jump key , it flies indefinitely into the sky. Not getting what to do, Please help me. The script is provided below.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour
{
[SerializeField]
Animator animator;
[SerializeField]
float original_speed;
CharacterController controller;
[SerializeField]
float jumpSpeed;
Vector3 movement;
[SerializeField]
float gravity;
float temp_speed;

// Start is called before the first frame update
void Start()
{
    controller = GetComponent<CharacterController>();
    temp_speed= original_speed;
}

// Update is called once per frame
void Update()
{
    if (controller.isGrounded)
    {
        float moveHorizontal = Input.GetAxis("Horizontal");
        float moveVertical = Input.GetAxis("Vertical");
        if (moveHorizontal != 0)
        {
            temp_speed = original_speed / 4;
        }
       

        if (moveVertical > 0)
        {
            temp_speed = original_speed;
        }
        else if (moveVertical < 0)
        {
            temp_speed = original_speed / 4;
        }

        movement = transform.right * moveHorizontal + transform.forward * moveVertical;

        if (moveHorizontal!=0 || moveVertical != 0)
        {
            animator.SetBool("IsIdle", false);
            if (temp_speed == original_speed)
            {
                animator.SetFloat("Speed_Multiplier", 1.0f);
            }
            else if(temp_speed < original_speed)
            {
                animator.SetFloat("Speed_Multiplier", 0.25f);
            }
        }
        else
        {
            animator.SetBool("IsIdle", true);
        }
       
        if (Input.GetKeyDown(KeyCode.Space))
        {
            movement.y = jumpSpeed;
        }
       
    }
    movement.y -= gravity * Time.deltaTime;
    movement.Normalize();
    controller.Move(movement * temp_speed * Time.deltaTime);

}

}

if (controller.isGrounded)
{
if(Input.GetKeyDown(KeyCode.Space))
{
movement.y=jumpSpeed;
}
}
Hi mate could you pls change whole if statement with this and try one more time in place (“While you are not moving”). If it is stills works bugly then there is a problem about your jumping method else if works fine there is problem about in your if statements. In addition as I see you are checking ground control in if method but I dont see any changer which changes .isGrounded value in you if which controls jumping (Space Input).Could you check that pls =) In addition I could recommend Brackeys fps video I made my self improved fps controller with that video it is a really good source =)
Have a great day