I don't know much about javascript, but chatgpt suggested this solution and it works great for me (put it on end of main.js file - you will find it in the template subdirectory called js).
There are also changes here to make everything look nice and smooth.
Unfortunately, I don't remember if any other part of the file was edited before. If this doesn't work, I can send you the full code of the main.js file.
jQuery(document).ready(function($) {
// Scroll and close offcanvas immediately
$('a[href^="#"]').on('click', function(event) {
var target = $(this.getAttribute('href'));
if (target.length) {
event.preventDefault();
// Close offcanvas immediately
$('.offcanvas-init').removeClass('offcanvas-active');
// Scroll after closing offcanvas
setTimeout(function() {
$('html, body').animate({
scrollTop: target.offset().top
}, 500);
}, 200); // Short delay for smooth closing of the menu
}
});