millis() command has a weird behaviour

Hi,
I have a program that "automates" a variant of basketball. Team 1 has to score up to 6 points in 30 seconds, and so does Team 2. The sketch I made uses millis() to calculate if 30 seconds have passed, but after around 60000 milliseconds the Arduino Mega sort of "jams up" and millis() goes into negative (going still towards positive). What is the cause of the problem? How can I solve it?

Code: (it's a bit messy and has some Italian-named variables)

const int echoPin = 8;
const int trigPin = 7;

long duration;
int distance;

int millitime;
int team = 0;

int count = 1;

void setup() {
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(24, OUTPUT);
  pinMode(25, OUTPUT);
  pinMode(26, OUTPUT);
  pinMode(27, OUTPUT);
  pinMode(28, OUTPUT);
  pinMode(29, OUTPUT);
  pinMode(30, OUTPUT);
  pinMode(31, OUTPUT);
  pinMode(32, OUTPUT);
  pinMode(33, OUTPUT);
  pinMode(34, OUTPUT);
  pinMode(35, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  Serial.println(millitime);
  Serial.println(millis());
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = duration*0.034/2;
  if((distance < 6) && (distance > 1) && (count < 13)) {
    digitalWrite(count + 23, HIGH);
    count = count + 1;
    delay(1000);
  }
  if((millis() - millitime) > 30000 && team == 1 && count < 13) {
      team = 0;
      millitime = millis();
      for(int i = 7; i < count; i++) {
        digitalWrite(i + 23, LOW);
      delay(500);
      }
      for(int i = 7; i < count; i++) {
        digitalWrite(i + 23, HIGH);
      }
      delay(500);
      for(int i = 7; i < count; i++) {
        digitalWrite(i + 23, LOW);
      }
      delay(500);
      for(int i = 7; i < count; i++) {
        digitalWrite(i + 23, HIGH);
      }
      delay(500);
      for(int i = 7; i < count; i++) {
       digitalWrite(i + 23, LOW);
      }
      delay(500);
      for(int i = 7; i < count; i++) {
        digitalWrite(i + 23, HIGH);
      }
      delay(4000);
      count = 13;
    } else if((millis() - millitime) > 30000 && team == 0 && count < 7) {
      team = 1;
      millitime = millis();
      
      for(int i = 0; i < count; i++) {
        digitalWrite(i + 23, LOW);
      delay(500);
      }
      for(int i = 0; i < count; i++) {
        digitalWrite(i + 23, HIGH);
      }
      delay(500);
      for(int i = 0; i < count; i++) {
        digitalWrite(i + 23, LOW);
      }
      delay(500);
      for(int i = 0; i < count; i++) {
        digitalWrite(i + 23, HIGH);
      }
      delay(500);
      for(int i = 0; i < count; i++) {
       digitalWrite(i + 23, LOW);
      }
      delay(500);
      for(int i = 0; i < count; i++) {
        digitalWrite(i + 23, HIGH);
      }
      count = 7;
      
    }
  if(count > 12) {
    count = 1;
    for(int i = 1; i < 13; i++) {
      digitalWrite(i + 23, LOW);
    }
  }
  delay(1);
}

thank you to anyone helping

Change this
int millitime;

to this

unsigned long millitime;

On the Arduino Uno (and other ATmega based boards) an int stores a 16-bit (2-byte) value. This yields a range of -32,768 to 32,767 (minimum value of -2^15 and a maximum value of (2^15) - 1).

Oh! thank you, I thought int would have saved values bigger than that. Guess I was wrong. Thank you

millis() returns unsigned long values.

Using an (signed) int provides 32768, or 32 seconds
unsigned int provides 65 seconds.

unsigned long provides (2^32)/1000 seconds, or 4.2 million (49+ days).

Always best to use unsigned long for time variables.