Trying to make a menu that makes use of an LCD

Please don't judge, but I'm kinda new to coding in Arduino and to this forum :slight_smile:

pretty much, I've been trying to create a menu which uses a 16x2 LCD with an analog joystick and a buzzer.
everything works except, whenever i move the joystick, nothing happens, it does make the scrolling click sound but the menu variable (M) doesn't change.

here's my code (don't mind the huge setup part, it's a little startup animation that i created)

#include <LiquidCrystal.h>

//integer setup
const int BL = 9; //backlight pin
const int C = 6; //contrast pin
const int Sw = 13; //joystick switch pin
int S = 0; //joystick switch state
const int Ml = 1023; //joystick max limit
const int B = 10; //buzzer pin
int M = 0; //menu choice

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  lcd.begin(16, 2);

  //pin setup
  pinMode(BL, OUTPUT);
  pinMode(S, INPUT);
  pinMode(C, OUTPUT);

  //startup animation
  analogWrite(C, 120);
  analogWrite(BL, 0);
  lcd.clear();
  lcd.print("-                                                      -");
  delay(25);
  analogWrite(BL, 20);
  lcd.clear();
  lcd.print("--                                                    --");
  delay(25);
  analogWrite(BL, 40);
  lcd.clear();
  lcd.print("---                                                  ---");
  delay(25);
  analogWrite(BL, 60);
  lcd.clear();
  lcd.print("----                                                ----");
  delay(25);
  analogWrite(BL, 80);
  lcd.clear();
  lcd.print("-----                                              -----");
  delay(25);
  analogWrite(BL, 100);
  lcd.clear();
  lcd.print("------                                            ------");
  delay(25);
  analogWrite(BL, 120);
  lcd.clear();
  lcd.print("-------                                          -------");
  delay(25);
  analogWrite(BL, 140);
  lcd.clear();
  lcd.print("--------                                        --------");
  delay(25);
  analogWrite(BL, 160);
  lcd.clear();
  lcd.print("---------                                      ---------");
  delay(25);
  analogWrite(BL, 180);
  lcd.clear();
  lcd.print("----------                                    ----------");
  delay(25);
  analogWrite(BL, 200);
  lcd.clear();
  lcd.print("-----------                                  -----------");
  delay(25);
  lcd.clear();
  lcd.print("------------                                ------------");
  delay(25);
  lcd.clear();
  lcd.print("-------------                              -------------");
  delay(25);
  lcd.clear();
  lcd.print("--------------                            --------------");
  delay(25);
  lcd.clear();
  lcd.print("---------------                          ---------------");
  delay(25);
  lcd.clear();
  lcd.print("----------------                        ----------------");
  delay(250);
  analogWrite(BL, 200);
  analogWrite(C, 120);
  tone(B, 1000);
  delay(100);
  tone(B, 900);
  delay(100);
  tone(B, 1000);
  delay(100);
  tone(B, 1100);
  delay(100);
  tone(B, 1500, 100);
  lcd.clear();
}

void loop() {
  S = digitalRead(Sw); //switch state setup

  //refresh
  delay(50);
  lcd.clear();
  
  
  //display menu
  if (M == 0) {
    lcd.print(">Brightness                             -Contrast");
  }
  if (M == 1) {
    lcd.print(">Contrast");
  }

  
  if (M == 2) int M = 1; //maximum menu choice
  if (M == -1) int M = 0; //minimum menu choice

  //if joystick goes up
  if (analogRead(A0) == Ml){
    M = (M-1);
    tone(B, 2000, 2);
    delay(100);
  }
  
  //if joystick goes down
  if (analogRead(A0) == 0){
    M = (M+1);
    tone(B, 1500, 2);
    delay(100);
  }

  //if button is clicked
  if (S == LOW){
    tone(B, 2000);
    delay(10);
    tone(B, 1500, 10);
    delay(100);
  }
}

help would be appreciated