;
      };
    }

    function sendMessage() {
      const input = document.getElementById("input");
      const message = input.value.trim();
      if (message === "") return;

      input.value = "";
      buffer = "";

      const userDiv = document.createElement("div");
      userDiv.className = "user";
      userDiv.innerText = message;
      document.getElementById("chat").appendChild(userDiv);

      socket.send(message);
      scrollToBottom();
    }

    function scrollToBottom() {
      const chat