```// ==UserScript==
// @name         codecurber with true full expand & preserve formatting - tweaked for current chat HTML
// @version      1.23
// @description  Fold long code blocks in .bubble-wrap.svelte-gjtrl6, skip micro blocks, fullscreen overlay expand with preserved formatting
// @match        *://yuntian-deng-chatgpt.hf.space/*
// @match        *://yuntian-deng-o1mini.hf.space/*
// @match        *://yuntian-deng-chatgpt4.hf.space/*
// @match        *://yuntian-deng-o1.hf.space/*
// @grant        none
// ==/UserScript==

(function() {
  'use strict';

  const MAX_LINES = 10;
  const MIN_LINES = 6; 
  const LINE_HEIGHT_PX = 19.2;

  // Add styles
  const style = document.createElement('style');
  style.textContent = `
    .textarea-container {
      position: relative;
      margin: 1em 0 2.5em;
      width: 100%;
      display: flex;
      flex-direction: column;
      align-items: flex-start;
      z-index: 1;
    }
    .code-textarea {
      width: 100% !important;
      background: #1e1e1e !important;
      color: #39ff14 !important;
      border-radius: 6px !important;
      border: 1px solid #39ff14 !important;
      padding: 10px !important;
      resize: vertical !important;
      white-space: pre !important;
      overflow-y: auto !important;
      user-select: text !important;
      box-sizing: border-box !important;
      max-height: calc(${MAX_LINES} * ${LINE_HEIGHT_PX}px) !important;
      height: calc(${MAX_LINES} * ${LINE_HEIGHT_PX}px) !important;
      transition: box-shadow 0.3s ease;
      position: relative;
      z-index: 1;
      font-family: 'Press Start 2P', monospace !important;
      caret-color: #6eff44 !important;
    }

    .fold-toggle-button {
      background: #f00;
      border: 3px solid #39ff14;
      color: #39ff14;
      padding: 6px 20px;
      font-family: 'Press Start 2P', monospace;
      text-shadow:
        1px 1px 0 #000,
        -1px -1px 0 #000,
        1px -1px 0 #000,
        -1px 1px 0 #000;
      border-radius: 4px;
      box-shadow:
        inset 0 0 2px #39ff14,
        0 0 12px #39ff1444;
      cursor: pointer;
      transition: background-color 0.15s ease, color 0.15s ease;
      margin-top: 0.5em;
      align-self: flex-start;
    }
    .fold-toggle-button:hover {
      background: #39ff14;
      color: #0f0;
      box-shadow:
        inset 0 0 6px #fff,
        0 0 16px #39ff14;
    }

    .folded-overlay {
      background: linear-gradient(135deg, #000000cc, #003300cc);
      box-shadow:
        0 0 30px #39ff14aa inset,
        0 0 50px #0f0f0f;
      border: 5px solid #39ff14;
      border-radius: 8px;

      position: fixed !important;
      top: 1.5vh !important;
      left: 1.5vw !important;
      width: 97vw !important;
      height: 97vh !important;
      display: flex;
      justify-content: center;
      align-items: center;
      z-index: 1000000;
    }

    .folded-overlay textarea {
      font-family: 'Press Start 2P', monospace !important;
      width: 100% !important;
      height: 100% !important;
      color: #39ff14;
      background: #001100;
      border: none;
      box-shadow:
        0 0 20px #39ff1499 inset;
      padding: 1em;
      border-radius: 8px;
      caret-color: #6eff44 !important;
      resize: none !important;
      box-sizing: border-box !important;
      outline: none !important;
      overflow: auto !important;
      user-select: text !important;
      white-space: pre !important;
    }

    .folded-overlay .close-button {
      user-select: none;
      box-shadow:
        0 0 10px #39ff14cc,
        inset 0 0 6px #6eff44cc;
      border-radius: 50%;
      border: 3px solid #39ff14;
      background: #002200;
      color: #39ff14;
      transition: color 0.3s ease, background 0.3s ease;
      position: fixed !important;
      top: 10px !important;
      right: 10px !important;
      width: 40px !important;
      height: 40px !important;
      font-size: 28px !important;
      line-height: 40px !important;
      text-align: center;
      cursor: pointer;
      z-index: 1000001;
    }
    .folded-overlay .close-button:hover {
      background: #39ff14;
      color: #f00;
      box-shadow:
        0 0 20px #39ff44ff,
        inset 0 0 12px #39ff66ff;
    }
  `;
  document.head.appendChild(style);

  function transformCodeBlock(codeEl) {
    if (codeEl.dataset.transformed === 'true') return;

    const text = codeEl.textContent || '';
    const lines = text.split('\n').length;
    if (lines < MIN_LINES) return;

    codeEl.dataset.transformed = 'true';

    const container = document.createElement('div');
    container.className = 'textarea-container';

    // Try to hide .code_wrap parent if present (for cleaner layout)
    const codeWrap = codeEl.closest('.code_wrap');
    if (codeWrap) {
      codeWrap.style.display = 'none';
      codeWrap.parentNode.insertBefore(container, codeWrap);
    } else {
      const parent = codeEl.parentNode;
      if (!parent) return;
      parent.insertBefore(container, codeEl);
    }

    container.appendChild(codeEl);

    const ta = document.createElement('textarea');
    ta.readOnly = true;
    ta.className = 'code-textarea';
    ta.value = text;
    ta.style.maxHeight = `${MAX_LINES * LINE_HEIGHT_PX}px`;
    ta.style.height = ta.style.maxHeight;

    container.appendChild(ta);

    const btn = document.createElement('button');
    btn.type = 'button';
    btn.className = 'fold-toggle-button';
    btn.textContent = 'Show full code';

    btn.addEventListener('click', () => openOverlay(ta, btn));

    container.appendChild(btn);
  }

  function openOverlay(originalTA) {
    const overlay = document.createElement('div');
    overlay.className = 'folded-overlay';

    const fullTA = document.createElement('textarea');
    fullTA.readOnly = true;
    fullTA.value = originalTA.value;

    const closeBtn = document.createElement('button');
    closeBtn.className = 'close-button';
    closeBtn.title = 'Close full code view';
    closeBtn.textContent = '×';

    overlay.appendChild(fullTA);
    document.body.appendChild(overlay);
    document.body.appendChild(closeBtn);

    fullTA.focus();
    fullTA.scrollTop = 0;

    function cleanup() {
      overlay.remove();
      closeBtn.remove();
      document.removeEventListener('keydown', onKey);
      originalTA.focus();
    }

    closeBtn.addEventListener('click', cleanup);

    function onKey(e) {
      if (e.key === 'Escape') {
        cleanup();
      }
    }
    document.addEventListener('keydown', onKey);
  }

  function foldAllCodeBlocks() {
    const chat = document.querySelector('.bubble-wrap.svelte-gjtrl6');
    if (!chat) return;
    chat.querySelectorAll('code').forEach(transformCodeBlock);
  }

  function observeChat() {
    const chat = document.querySelector('.bubble-wrap.svelte-gjtrl6');
    if (!chat) return;

    const observer = new MutationObserver(() => {
      foldAllCodeBlocks();
    });
    observer.observe(chat, { childList: true, subtree: true });
  }

  const initInt = setInterval(() => {
    if (document.querySelector('.bubble-wrap.svelte-gjtrl6')) {
      clearInterval(initInt);
      foldAllCodeBlocks();
      observeChat();
    }
  }, 300);
})();
```