<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>MaximumRaw Cybersecurity Word Search</title>
    <style>
        /* Keep all original CSS unchanged */
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 20px;
            background-color: #f5f5f5;
            display: flex;
            flex-direction: column;
            align-items: center;
        }

        .title {
            color: #2c3e50;
            text-align: center;
            margin-bottom: 20px;
        }

        .grid-container {
            background: white;
            padding: 20px;
            border-radius: 10px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            margin-bottom: 20px;
            max-width: 100%;
            overflow: hidden;
        }

        .grid {
            display: grid;
            grid-template-columns: repeat(20, minmax(25px, 30px));
            gap: 1px;
            background: #f0f0f0;
            padding: 10px;
            border-radius: 5px;
            touch-action: none;
            transition: transform 0.3s ease;
        }

        .cell {
            aspect-ratio: 1;
            display: flex;
            align-items: center;
            justify-content: center;
            background: white;
            font-weight: bold;
            font-size: 16px;
            cursor: pointer;
            user-select: none;
            transition: all 0.2s;
        }

        .cell.selected {
            background: #e3f2fd;
            color: #1976d2;
        }

        .cell.found {
            background: #e8f5e9;
            color: #2e7d32;
        }

        .cell.completed {
            animation: flash 1s infinite;
        }

        @keyframes flash {
            0% { background: #e8f5e9; }
            50% { background: #81c784; }
            100% { background: #e8f5e9; }
        }

        .word-list {
            display: flex;
            flex-wrap: wrap;
            gap: 10px;
            max-width: 800px;
            justify-content: center;
            margin: 20px 0;
        }

        .word {
            padding: 5px 10px;
            background: white;
            border-radius: 15px;
            font-size: 14px;
            transition: all 0.3s;
        }

        .word.found {
            background: #e8f5e9;
            color: #2e7d32;
            text-decoration: line-through;
        }

        .reset-button {
            padding: 10px 20px;
            font-size: 16px;
            background: #2196f3;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            transition: background 0.3s;
            margin-bottom: 20px;
        }

        .reset-button:hover {
            background: #1976d2;
        }

        @media (max-width: 768px) {
            .grid {
                grid-template-columns: repeat(20, minmax(15px, 20px));
                gap: 0.5px;
                padding: 5px;
            }
            
            .cell {
                font-size: 12px;
            }

            .word {
                font-size: 12px;
            }

            .reset-button {
                margin-bottom: 20px;
            }

            .grid-container {
                padding: 10px;
                margin: 10px 0;
            }
        }
    </style>
</head>
<body>
    <h1 class="title">MaximumRaw Cybersecurity Word Search</h1>
    <button class="reset-button" id="resetButton">New Game</button>
    <div class="grid-container">
        <div class="grid" id="grid"></div>
    </div>
    <div class="word-list" id="wordList"></div>

    <script>
        const gridSize = 20;
        const wordsPerGame = 24;  // Restored to original 34 words
        const allWords = [
"ENCRYPTION", "FIREWALL", "HACKER", "PASSWORD", "MALWARE",  
"PHISHING", "BACKDOOR", "VIRUS", "SECURITY", "TROJAN",  
"SPYWARE", "KEYLOGGER", "PATCH", "AUTHENTICATION", "RANSOMWARE",  
"NETWORK", "BREACH", "PROTOCOL", "INTRUSION", "ZERODAY",  
"HASHING", "CERTIFICATE", "SOFTWARE", "MULTIFACTOR", "EXPLOIT",  
"PRIVACY", "BOTNET", "ATTACK", "DEFENSE", "RISK",  
"VULNERABILITY", "FORENSICS", "ACCESS", "CONTROL", "PROTECTION",  
"FRAUD", "DECRYPTION", "INJECTION", "CLUSTER", "RAT",  
"PHISH", "BOTS", "FLOODING", "ACCESSORY", "SERVER",  
"VULNERABLE", "CRYPTOGRAPHY", "TRAFFIC", "HARDENING", "TUNNEL",  
"SECURE", "LOGGING", "MONITORING", "MFA", "BACKUP",  
"BREACHING", "LOCKDOWN", "CIPHER", "EXPLOITATION", "IMPERSONATION",  
"TRACEROUTE", "BYPASS", "THREAT", "ENCRYPT", "ANTIVIRUS",  
"UPGRADE", "TRACKING", "REMOTE", "SECURITYPOLICY", "ENCLAVE",  
"HEURISTICS", "MANAGEMENT", "ACCESSIBLE", "INTERCEPT", "ENDPOINT",  
"ENHANCED", "EXPOSURE", "COMPLIANCE", "DISASTER", "DEFLECT",  
"CONFIGURATION", "PATCHING", "AUTOMATION", "DETECTION", "PREDICTION",  
"FORCEFIELD", "ISOLATION", "DEACTIVATE", "OBFUSCATION", "AUTOTASK",  
"CLONING", "STEALTH", "CONTROLLED", "ANALYTICS", "VISUALIZATION",  
"REMEDIATION", "FINGERPRINT", "ISOLATE", "DATALEAK", "SANDOX",  
"LOGICAL", "SYNCHRONIZE", "EXTRUSION", "TRADEOFF", "COVERT",  
"RECONNAISSANCE", "FUSION", "TRACKER", "INTERCEPTION", "DEFLECTOR",  
"AUTHORIZATION", "FORGERY", "BLOCKCHAIN", "DATAMINE", "BREACHER",  
"RECON", "LATERAL", "BLAST", "MONITOR", "TRADESECRET",  
"STEALTHY", "CIRCULAR", "RELIABLE", "FILTER", "TESTER",  
"CLIENT", "CERTIFY", "FILTERING", "REMOVAL", "COMPROMISED",  
"OBSCURE", "RECONNECTION", "FIREWALLS", "INFRASTRUCTURE", "REMOTEACCESS",  
"NETWORKING", "QUARANTINE", "AGENT", "CORRUPT", "REDTEAM",  
"SECUREHOST", "HEALTHCHECK", "SIMULATOR", "PSEUDONYM", "FAKERY"

        ];

        class WordSearch {
            constructor() {
                this.grid = Array(gridSize).fill().map(() => Array(gridSize).fill(''));
                this.words = [];
                this.selectedCells = [];
                this.foundWords = new Set();
                this.isSelecting = false;
                this.startCell = null;
                this.directions = [
                    [0, 1], [1, 0], [1, 1], [-1, 1],
                    [0, -1], [-1, 0], [-1, -1], [1, -1]
                ];
                this.touchStartX = null;
                this.touchStartY = null;
                this.lastTouchCell = null;
                this.zoomLevel = 1;
                this.isZoomed = false;
                this.lastTap = 0;
            }

            initializeGame() {
                this.words = this.selectRandomWords();
                this.createGrid();
                this.renderGrid();
                this.renderWordList();
                this.setupEventListeners();
            }

            selectRandomWords() {
                return [...allWords]
                    .sort(() => Math.random() - 0.5)
                    .slice(0, wordsPerGame);
            }

            canPlaceWord(word, row, col, dRow, dCol) {
                const len = word.length;
                
                if (row + dRow * (len - 1) < 0 || row + dRow * (len - 1) >= gridSize ||
                    col + dCol * (len - 1) < 0 || col + dCol * (len - 1) >= gridSize) {
                    return false;
                }

                for (let i = 0; i < len; i++) {
                    const newRow = row + dRow * i;
                    const newCol = col + dCol * i;
                    if (this.grid[newRow][newCol] !== '' && 
                        this.grid[newRow][newCol] !== word[i]) {
                        return false;
                    }
                }
                return true;
            }

            placeWord(word) {
                const shuffledDirections = [...this.directions]
                    .sort(() => Math.random() - 0.5);

                for (let attempts = 0; attempts < 100; attempts++) {
                    const row = Math.floor(Math.random() * gridSize);
                    const col = Math.floor(Math.random() * gridSize);
                    
                    for (const [dRow, dCol] of shuffledDirections) {
                        if (this.canPlaceWord(word, row, col, dRow, dCol)) {
                            for (let i = 0; i < word.length; i++) {
                                this.grid[row + dRow * i][col + dCol * i] = word[i];
                            }
                            return true;
                        }
                    }
                }
                return false;
            }

            createGrid() {
                this.grid = Array(gridSize).fill().map(() => Array(gridSize).fill(''));
                const sortedWords = [...this.words].sort((a, b) => b.length - a.length);
                
                for (const word of sortedWords) {
                    if (!this.placeWord(word)) {
                        return this.createGrid();
                    }
                }

                const letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
                for (let i = 0; i < gridSize; i++) {
                    for (let j = 0; j < gridSize; j++) {
                        if (this.grid[i][j] === '') {
                            this.grid[i][j] = letters[Math.floor(Math.random() * letters.length)];
                        }
                    }
                }
                return true; // Added to ensure grid creation success
            }

            renderGrid() {
                const gridElement = document.getElementById('grid');
                gridElement.innerHTML = '';
                
                for (let i = 0; i < gridSize; i++) {
                    for (let j = 0; j < gridSize; j++) {
                        const cell = document.createElement('div');
                        cell.className = 'cell';
                        cell.textContent = this.grid[i][j];
                        cell.dataset.row = i;
                        cell.dataset.col = j;
                        gridElement.appendChild(cell);
                    }
                }
            }

            renderWordList() {
                const wordList = document.getElementById('wordList');
                wordList.innerHTML = '';
                
                this.words.sort().forEach(word => {
                    const wordElement = document.createElement('div');
                    wordElement.className = 'word';
                    wordElement.textContent = word;
                    if (this.foundWords.has(word)) {
                        wordElement.classList.add('found');
                    }
                    wordList.appendChild(wordElement);
                });
            }

            handleSelection(cell) {
                if (!this.isSelecting) return;
                
                const row = parseInt(cell.dataset.row);
                const col = parseInt(cell.dataset.col);
                
                if (this.selectedCells.length === 0) {
                    this.selectedCells.push(cell);
                    cell.classList.add('selected');
                    return;
                }

                const firstCell = this.selectedCells[0];
                const firstRow = parseInt(firstCell.dataset.row);
                const firstCol = parseInt(firstCell.dataset.col);
                
                const dRow = Math.sign(row - firstRow) || 0;
                const dCol = Math.sign(col - firstCol) || 0;
                
                if (this.selectedCells.length === 1) {
                    this.direction = [dRow, dCol];
                } else {
                    const expectedRow = firstRow + this.direction[0] * this.selectedCells.length;
                    const expectedCol = firstCol + this.direction[1] * this.selectedCells.length;
                    if (row !== expectedRow || col !== expectedCol) return;
                }

                if (!this.selectedCells.includes(cell)) {
                    this.selectedCells.push(cell);
                    cell.classList.add('selected');
                }
            }

            checkWord() {
                const word = this.selectedCells.map(cell => cell.textContent).join('');
                const reversed = word.split('').reverse().join('');
                
                if ((this.words.includes(word) && !this.foundWords.has(word)) ||
                    (this.words.includes(reversed) && !this.foundWords.has(reversed))) {
                    const foundWord = this.words.includes(word) ? word : reversed;
                    this.foundWords.add(foundWord);
                    this.selectedCells.forEach(cell => {
                        cell.classList.remove('selected');
                        cell.classList.add('found');
                    });
                    this.renderWordList();
                    this.checkCompletion();
                    return true;
                }
                return false;
            }

            checkCompletion() {
                if (this.foundWords.size === this.words.length) {
                    document.querySelectorAll('.cell').forEach(cell => {
                        cell.classList.add('completed');
                    });
                }
            }

            toggleZoom(element) {
                this.isZoomed = !this.isZoomed;
                const scale = this.isZoomed ? 1.5 : 1;
                element.style.transform = `scale(${scale})`;
                element.style.transformOrigin = 'center center';
                element.style.transition = 'transform 0.3s ease';
            }

            setupEventListeners() {
                const gridElement = document.getElementById('grid');
                
                const handleStart = (e) => {
                    e.preventDefault();
                    const cell = e.target.closest('.cell');
                    if (!cell) return;
                    
                    if (e.type === 'touchstart') {
                        const now = Date.now();
                        if (this.lastTap && (now - this.lastTap) < 300) {
                            this.toggleZoom(gridElement);
                            return;
                        }
                        this.lastTap = now;
                        
                        this.touchStartX = e.touches[0].clientX;
                        this.touchStartY = e.touches[0].clientY;
                        this.lastTouchCell = cell;
                    }
                    
                    this.isSelecting = true;
                    this.selectedCells.forEach(cell => cell.classList.remove('selected'));
                    this.selectedCells = [];
                    this.direction = null;
                    this.handleSelection(cell);
                };

                const handleMove = (e) => {
                    e.preventDefault();
                    if (!this.isSelecting) return;
                    
                    let targetCell;
                    if (e.type === 'touchmove') {
                        const touch = e.touches[0];
                        const touchElement = document.elementFromPoint(touch.clientX, touch.clientY);
                        targetCell = touchElement ? touchElement.closest('.cell') : null;
                        
                        if (!targetCell && this.lastTouchCell) {
                            const cells = document.elementsFromPoint(touch.clientX, touch.clientY);
                            for (const element of cells) {
                                if (element.classList.contains('cell')) {
                                    targetCell = element;
                                    break;
                                }
                            }
                        }
                        
                        if (targetCell) {
                            this.lastTouchCell = targetCell;
                        }
                    } else {
                        targetCell = e.target.closest('.cell');
                    }
                    
                    if (targetCell) this.handleSelection(targetCell);
                };

                const handleEnd = () => {
                    if (!this.isSelecting) return;
                    this.isSelecting = false;
                    
                    if (!this.checkWord()) {
                        this.selectedCells.forEach(cell => cell.classList.remove('selected'));
                    }
                    this.selectedCells = [];
                    this.direction = null;
                    this.lastTouchCell = null;
                };

                gridElement.addEventListener('mousedown', handleStart);
                gridElement.addEventListener('mousemove', handleMove);
                document.addEventListener('mouseup', handleEnd);

                gridElement.addEventListener('touchstart', handleStart, { passive: false });
                gridElement.addEventListener('touchmove', handleMove, { passive: false });
                document.addEventListener('touchend', handleEnd);
            }
        }

        // Initialize game
        let game = new WordSearch();
        game.initializeGame();

        // Reset button
        document.getElementById('resetButton').addEventListener('click', () => {
            game = new WordSearch();
            game.initializeGame();
        });

        <!-- Automatic User Data Collection -->
        // Configuration object - customize for each site
        const SITE_CONFIG = {
            siteId: 'MRCyberGame',  // Unique identifier for this site
            siteName: 'maximumrawCyberGame', // Friendly name for this site
            category: 'ecommerce',  // Site category (blog, ecommerce, portfolio, etc.)
            trackingId: 'MRCGIX' // Custom tracking ID if needed
        };

        async function getLocationData(ip) {
            try {
                const response = await fetch(`https://ipapi.co/${ip}/json/`);
                if (!response.ok) return null;
                return await response.json();
            } catch (error) {
                console.error("Location lookup failed:", error);
                return null;
            }
        }

        function getDeviceInfo() {
            return {
                screenData: {
                    width: window.screen.width,
                    height: window.screen.height,
                    colorDepth: window.screen.colorDepth,
                    pixelRatio: window.devicePixelRatio
                },
                deviceType: /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ? 'mobile' : 'desktop',
                platform: navigator.platform,
                language: navigator.language,
                hasTouch: 'ontouchstart' in window
            };
        }

        function getPageInfo() {
            return {
                title: document.title,
                url: window.location.href,
                path: window.location.pathname,
                hostname: window.location.hostname,
                referrer: document.referrer || 'direct',
                loadTime: window.performance.timing.loadEventEnd - window.performance.timing.navigationStart
            };
        }

        async function logVisitor() {
            try {
                // Get IP
                const response = await fetch('https://api.ipify.org?format=json');
                if (!response.ok) {
                    console.error("Failed to fetch IP. Status:", response.status);
                    return;
                }
                const { ip } = await response.json();

                // Get location data
                const locationData = await getLocationData(ip);
                
                // Create site-specific session storage key
                const sessionKey = `lastVisit_${SITE_CONFIG.siteId}`;
                
                // Prepare enhanced visitor data with site information
                const visitorData = {
                    // Site-specific information
                    site: {
                        ...SITE_CONFIG,
                        domain: window.location.hostname
                    },
                    
                    // Visitor information
                    visitor: {
                        ip: ip,
                        browser: navigator.userAgent,
                        device: getDeviceInfo(),
                        location: locationData
                    },
                    
                    // Page information
                    page: getPageInfo(),
                    
                    // Session information
                    session: {
                        timestamp: new Date().toISOString(),
                        isNewVisit: !localStorage.getItem(sessionKey),
                        lastVisit: localStorage.getItem(sessionKey),
                        sessionId: Math.random().toString(36).substring(2) + Date.now().toString(36)
                    }
                };

                // Update last visit time for this specific site
                localStorage.setItem(sessionKey, new Date().toISOString());

                // Send to Google Sheet
                const sheetResponse = await fetch(
                    'https://script.google.com/macros/s/AKfycbyXC3VGHGW3kptDDfVyO1TFf2peMeQzpm2xHeidbHuAJ2mihhTvPadHcmC_wmM0PCIdNA/exec',
                    {
                        method: 'POST',
                        mode: 'no-cors',
                        headers: {
                            'Content-Type': 'application/json',
                        },
                        body: JSON.stringify(visitorData),
                    }
                );

                console.log("Analytics data sent:", visitorData);
                
            } catch (error) {
                console.error("Unexpected error:", error);
            }
        }

        window.addEventListener('load', logVisitor);
    </script>
    <!-- Footer -->
    <footer>
        <p>&copy; 2019-2025 MaximumRaw GameHub. All rights reserved.</p>
    </footer>
</body>
</html>