```// ==UserScript==
// @name         codecurber fullscreen-style mini-preview with toggle fullscreen fit
// @version      1.28
// @description  Use fullscreen-style code block as default mini-preview, with toggle button to expand to real fullscreen fitting viewport
// @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 MIN_LINES_TO_FOLD = 6;

  const style = document.createElement('style');
  style.textContent = `
    .codecurber-container {
      position: relative;
      margin: 1em 0 2em;
      font-family: 'Press Start 2P', monospace;
      color: #39ff14;
      user-select: text;
      border: 5px solid #39ff14;
      border-radius: 8px;
      background: linear-gradient(135deg, #000000cc, #003300cc);
      box-shadow:
        0 0 30px #39ff14aa inset,
        0 0 50px #0f0f0f;
      max-width: 100%;
      min-height: 10em;
      display: flex;
      flex-direction: column;
      transition: all 0.3s ease;
      overflow: hidden;
      position: relative;
    }

    .codecurber-textarea {
      width: 100% !important;
      height: 10em;
      background: #001100 !important;
      border: none !important;
      box-shadow: inset 0 0 20px #39ff1499 !important;
      color: #39ff14 !important;
      caret-color: #6eff44 !important;
      resize: vertical !important;
      outline: none !important;
      overflow: auto !important;
      white-space: pre !important;
      font-family: 'Press Start 2P', monospace !important;
      box-sizing: border-box !important;
      user-select: text !important;
      flex-grow: 1;
      min-height: 6em;
      max-height: 40vh;
      transition: height 0.3s ease;
    }

    .codecurber-btns {
      padding: 0.5em 0;
      display: flex;
      justify-content: flex-end;
      gap: 8px;
    }

    .codecurber-btn {
      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;
      width: 36px;
      height: 36px;
      font-size: 28px;
      line-height: 36px;
      text-align: center;
      cursor: pointer;
    }
    .codecurber-btn:hover {
      background: #39ff14;
      color: #f00;
      box-shadow:
        0 0 20px #39ff44ff,
        inset 0 0 12px #39ff66ff;
    }

    .codecurber-fullscreen {
      position: fixed !important;
      top: 50% !important;
      left: 50% !important;
      max-width: 97vw !important;
      max-height: 97vh !important;
      width: auto !important;
      height: auto !important;
      padding: 1em;
      border-radius: 8px;
      background: linear-gradient(135deg, #000000cc, #003300cc);
      box-shadow:
        0 0 30px #39ff14aa inset,
        0 0 50px #0f0f0f;
      border: 5px solid #39ff14;
      overflow: hidden;
      display: flex;
      flex-direction: column;
      z-index: 1000000;
      transform-origin: center center;
      transform: translate(-50%, -50%) scale(1);
      transition: all 0.3s ease;
    }

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

  `;

  document.head.appendChild(style);

  function createCodeCurberBlock(codeEl) {
    if (codeEl.dataset.codecurberProcessed) return;
    const text = codeEl.textContent || '';
    const lines = text.split('\n').length;
    if (lines < MIN_LINES_TO_FOLD) return; // Leave small code blocks as is

    codeEl.dataset.codecurberProcessed = 'true';

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

    // Textarea (mini-preview default)
    const ta = document.createElement('textarea');
    ta.className = 'codecurber-textarea';
    ta.readOnly = true;
    ta.value = text;
    container.appendChild(ta);

    // Buttons container
    const btns = document.createElement('div');
    btns.className = 'codecurber-btns';

    // Fullscreen toggle button
    const expandBtn = document.createElement('button');
    expandBtn.className = 'codecurber-btn';
    expandBtn.title = 'Toggle fullscreen fit mode';
    expandBtn.textContent = '⬜'; // Unicode square symbol
    btns.appendChild(expandBtn);

    // Close button
    const closeBtn = document.createElement('button');
    closeBtn.className = 'codecurber-btn';
    closeBtn.title = 'Close code block';
    closeBtn.textContent = '×';
    btns.appendChild(closeBtn);

    container.appendChild(btns);

    // Replace original code block with container
    const parent = codeEl.parentNode;
    if (!parent) return;
    parent.replaceChild(container, codeEl);

    let fullscreen = false;

    function scaleToFit() {
      const vw = window.innerWidth * 0.97;
      const vh = window.innerHeight * 0.97;

      ta.style.width = 'auto';
      ta.style.height = 'auto';

      // measured natural size
      const scrollW = ta.scrollWidth;
      const scrollH = ta.scrollHeight;

      const paddingAllowance = 40;
      const maxW = vw - paddingAllowance;
      const maxH = vh - paddingAllowance;

      const scaleX = maxW / scrollW;
      const scaleY = maxH / scrollH;
      const scale = Math.min(1, scaleX, scaleY);

      container.style.width = scrollW + 'px';
      container.style.height = scrollH + 'px';
      container.style.position = 'fixed';
      container.style.top = '50%';
      container.style.left = '50%';
      container.style.transformOrigin = 'center center';
      container.style.transform = `translate(-50%, -50%) scale(${scale})`;
      container.style.zIndex = '1000000';
      container.style.maxWidth = '';
      container.style.maxHeight = '';
      container.style.borderRadius = '8px';
      container.style.background = 'linear-gradient(135deg, #000000cc, #003300cc)';
      container.style.boxShadow =
        '0 0 30px #39ff14aa inset, 0 0 50px #0f0f0f';
      container.style.flexDirection = 'column';
      container.style.overflow = 'hidden';
      container.style.display = 'flex';

      ta.style.width = scrollW + 'px';
      ta.style.height = scrollH + 'px';
      ta.style.resize = 'none';
      ta.style.overflow = 'auto';
    }

    function resetToMini() {
      container.style.position = '';
      container.style.top = '';
      container.style.left = '';
      container.style.transform = '';
      container.style.zIndex = '';
      container.style.width = '';
      container.style.height = '';
      container.style.maxWidth = '100%';
      container.style.maxHeight = '40vh';
      container.style.borderRadius = '8px';
      container.style.background = 'linear-gradient(135deg, #000000cc, #003300cc)';
      container.style.boxShadow =
        '0 0 30px #39ff14aa inset, 0 0 50px #0f0f0f';
      container.style.flexDirection = 'column';
      container.style.overflow = 'hidden';
      container.style.display = 'flex';

      ta.style.width = '100%';
      ta.style.height = '10em';
      ta.style.resize = 'vertical';
      ta.style.overflow = 'auto';
    }

    expandBtn.addEventListener('click', () => {
      fullscreen = !fullscreen;
      if (fullscreen) {
        scaleToFit();
        expandBtn.textContent = '🗗'; // Unicode maximize symbol
      } else {
        resetToMini();
        expandBtn.textContent = '⬜'; // Unicode square
      }
    });

    closeBtn.addEventListener('click', () => {
      container.remove();
    });

    window.addEventListener('resize', () => {
      if (fullscreen) {
        scaleToFit();
      }
    });
  }

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

  function observeChat() {
    const chat = document.querySelector('.bubble-wrap.svelte-gjtrl6');
    if (!chat) return;
    const observer = new MutationObserver(() => {
      processAllCodeBlocks();
    });
    observer.observe(chat, { childList: true, subtree: true });
  }

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

  // alias for clarity
  const createCodeCurberBlock = createCodeCurberBlock || createCodeCurberBlock;
  // assign createCodeCurberBlock function inside processAllCodeBlocks
  function createCodeCurberBlock(codeEl) {
    // same as above
    if (codeEl.dataset.codecurberProcessed) return;
    const text = codeEl.textContent || '';
    const lines = text.split('\n').length;
    if (lines < MIN_LINES_TO_FOLD) return; // Leave small code blocks as is

    codeEl.dataset.codecurberProcessed = 'true';

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

    // Textarea (mini-preview default)
    const ta = document.createElement('textarea');
    ta.className = 'codecurber-textarea';
    ta.readOnly = true;
    ta.value = text;
    container.appendChild(ta);

    // Buttons container
    const btns = document.createElement('div');
    btns.className = 'codecurber-btns';

    // Fullscreen toggle button
    const expandBtn = document.createElement('button');
    expandBtn.className = 'codecurber-btn';
    expandBtn.title = 'Toggle fullscreen fit mode';
    expandBtn.textContent = '⬜';
    btns.appendChild(expandBtn);

    // Close button
    const closeBtn = document.createElement('button');
    closeBtn.className = 'codecurber-btn';
    closeBtn.title = 'Close code block';
    closeBtn.textContent = '×';
    btns.appendChild(closeBtn);

    container.appendChild(btns);

    // Replace original code block with container
    const parent = codeEl.parentNode;
    if (!parent) return;
    parent.replaceChild(container, codeEl);

    let fullscreen = false;

    function scaleToFit() {
      const vw = window.innerWidth * 0.97;
      const vh = window.innerHeight * 0.97;

      ta.style.width = 'auto';
      ta.style.height = 'auto';

      const scrollW = ta.scrollWidth;
      const scrollH = ta.scrollHeight;

      const paddingAllowance = 40;
      const maxW = vw - paddingAllowance;
      const maxH = vh - paddingAllowance;

      const scaleX = maxW / scrollW;
      const scaleY = maxH / scrollH;
      const scale = Math.min(1, scaleX, scaleY);

      container.style.width = scrollW + 'px';
      container.style.height = scrollH + 'px';
      container.style.position = 'fixed';
      container.style.top = '50%';
      container.style.left = '50%';
      container.style.transformOrigin = 'center center';
      container.style.transform = `translate(-50%, -50%) scale(${scale})`;
      container.style.zIndex = '1000000';
      container.style.maxWidth = '';
      container.style.maxHeight = '';
      container.style.borderRadius = '8px';
      container.style.background = 'linear-gradient(135deg, #000000cc, #003300cc)';
      container.style.boxShadow =
        '0 0 30px #39ff14aa inset, 0 0 50px #0f0f0f';
      container.style.flexDirection = 'column';
      container.style.overflow = 'hidden';
      container.style.display = 'flex';

      ta.style.width = scrollW + 'px';
      ta.style.height = scrollH + 'px';
      ta.style.resize = 'none';
      ta.style.overflow = 'auto';
    }

    function resetToMini() {
      container.style.position = '';
      container.style.top = '';
      container.style.left = '';
      container.style.transform = '';
      container.style.zIndex = '';
      container.style.width = '';
      container.style.height = '';
      container.style.maxWidth = '100%';
      container.style.maxHeight = '40vh';
      container.style.borderRadius = '8px';
      container.style.background = 'linear-gradient(135deg, #000000cc, #003300cc)';
      container.style.boxShadow =
        '0 0 30px #39ff14aa inset, 0 0 50px #0f0f0f';
      container.style.flexDirection = 'column';
      container.style.overflow = 'hidden';
      container.style.display = 'flex';

      ta.style.width = '100%';
      ta.style.height = '10em';
      ta.style.resize = 'vertical';
      ta.style.overflow = 'auto';
    }

    expandBtn.addEventListener('click', () => {
      fullscreen = !fullscreen;
      if (fullscreen) {
        scaleToFit();
        expandBtn.textContent = '🗗';
      } else {
        resetToMini();
        expandBtn.textContent = '⬜';
      }
    });

    closeBtn.addEventListener('click', () => {
      container.remove();
    });

    window.addEventListener('resize', () => {
      if (fullscreen) scaleToFit();
    });
  }
})();
```