.offsetHeight - 50;

                prepare_for_ai_turn();
                if (is_thinking) {
                    is_thinking = false;
                    toggleButton.textContent = 'Thought for ' + ((performance.now() - g_thought_start_time) / 1000).toFixed(2) + ' s';
                }
                g_md_src += chunk;
                render_main();

                if (isAtBottom) {
                    window.scrollTo(0, document.body.scrollHeight);
                }
            }

            function 