User prompt
bazı görünüm şeyleri silinmiş iki bir beş tane görünüm ekle
User prompt
Please fix the bug: 'Timeout.tick error: tween is not a function' in or related to this line: 'tween(playAgainBg, {' Line Number: 2470 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Please fix the bug: 'Timeout.tick error: tween is not a function' in or related to this line: 'tween(redTurnText, {' Line Number: 1913 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Eklenti kullanmadan basit animasyonlarla
User prompt
plugin yani eklenti olan kısımları basit animasyonlarla gider yani plugin kullanma eklenti kullanma
User prompt
Please fix the bug: 'Timeout.tick error: tween is not a function' in or related to this line: 'tween(redTurnText, {' Line Number: 1913 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Please fix the bug: 'Uncaught TypeError: tween is not a function' in or related to this line: 'tween(confirmationBg, {' Line Number: 1124 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Please fix the bug: 'Uncaught TypeError: tween is not a function' in or related to this line: 'tween(confirmationBg, {' Line Number: 1124 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Please fix the bug: 'Uncaught TypeError: tween is not a function' in or related to this line: 'tween(confirmationBg, {' Line Number: 1124 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Please fix the bug: 'Uncaught TypeError: tween is not a function' in or related to this line: 'tween(confirmationBg, {' Line Number: 1124 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Please fix the bug: 'Uncaught TypeError: tween is not a function' in or related to this line: 'tween(noBtn, {' Line Number: 1071 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Please fix the bug: 'Uncaught TypeError: tween is not a function' in or related to this line: 'tween(yesBtn, {' Line Number: 1066 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Please fix the bug: 'Uncaught TypeError: tween is not a function' in or related to this line: 'tween(confirmationText, {' Line Number: 1061 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Please fix the bug: 'Uncaught TypeError: tween is not a function' in or related to this line: 'tween(confirmationBg, {' Line Number: 1056
User prompt
X ve O'nun yer orantısını düzelt.
User prompt
Please fix the bug: 'Timeout.tick error: tween is not a function' in or related to this line: 'tween(playAgainBg, {' Line Number: 2403
User prompt
Please fix the bug: 'Timeout.tick error: tween is not a function' in or related to this line: 'tween(self.line, {' Line Number: 257
User prompt
Please fix the bug: 'Uncaught TypeError: tween is not a function' in or related to this line: 'tween(self.marker, {' Line Number: 155
User prompt
Oyunda eklenti olduğu için başka cihazlar giremiyor. Eklentileri kaldır.
User prompt
yüklenmesi daha kolay olsun ve hatalardan uzak olsun
User prompt
İçeriki yüklenirken hata veriyor.
User prompt
Zorluk seçim düğme yazısını biraz yukarı taşı
User prompt
ayarlar düğmesini de biraz yukarı taşı ve büyüt
User prompt
butonlara tıklanması için düğmeleri büyüt ve birbirlerinden birazcık ayır
User prompt
evet şu an oyunun olması gerektiği gibi tüm resimler yerinde tüm paketlerdeki görünümler doğru şimdi bu kodu iyice bir kontrol et böyle olması gerektiğine ildair herşeyi kontrol et
/**** 
* Classes
****/ 
var Cell = Container.expand(function (row, col) {
	var self = Container.call(this);
	self.row = row;
	self.col = col;
	self.value = 0; // 0 = empty, 1 = X (blue), 2 = O (red)
	var cellBg = self.attachAsset('cell', {
		anchorX: 0.5,
		anchorY: 0.5,
		alpha: 0.01 // Make almost invisible but still interactive
	});
	// Make the entire cell area interactive
	self.interactive = true;
	self.hitArea = new Rectangle(-290, -290, 580, 580);
	self.marker = null;
	// Add hover effect to show clickable area
	self.move = function (x, y, obj) {
		if (!gameReady || gameOver || self.value !== 0 || gameMode === 'menu') return;
		if (isAIMode && (currentPlayer !== 1 || aiProcessing)) return;
		if (gameBoard.alpha > 0 && !aiProcessing) {
			// Only show hover when board is visible and AI is not processing
			cellBg.alpha = 0.2; // Show cell is hoverable
		}
	};
	// Reset hover effect when mouse leaves
	self.up = function (x, y, obj) {
		if (self.value === 0 && !gameOver && gameReady && gameMode !== 'menu') {
			cellBg.alpha = 0.01; // Reset to almost invisible
		}
	};
	self.placeMarker = function (type, callback) {
		if (self.value !== 0) return false;
		// Prevent placing marker if already has one or is animating
		if (self.marker || self.value !== 0) return false;
		// In AI mode, extra validation
		if (isAIMode && type === 1 && aiProcessing) return false;
		if (isAIMode && type === 2 && !aiProcessing) return false;
		self.value = type;
		// Simplified asset mapping with fallback protection
		var styleMap = {
			0: {
				x: 'xMarker',
				o: 'oMarker'
			},
			1: {
				x: 'xMarkerStyle1',
				o: 'oMarkerStyle1'
			},
			2: {
				x: 'xMarkerStyle3',
				o: 'oMarkerStyle3'
			},
			3: {
				x: 'xMarkerStyle3',
				o: 'oMarkerStyle3'
			},
			4: {
				x: 'xMarkerStyle6',
				o: 'oMarkerStyle6'
			},
			5: {
				x: 'xMarkerStyle3',
				o: 'oMarkerStyle3'
			},
			6: {
				x: 'xMarkerStyle6',
				o: 'oMarkerStyle6'
			},
			7: {
				x: 'xMarkerStyle8',
				o: 'oMarkerStyle8'
			},
			8: {
				x: 'xMarkerStyle8',
				o: 'oMarkerStyle8'
			},
			9: {
				x: 'xMarkerStyle8',
				o: 'oMarkerStyle8'
			},
			10: {
				x: 'xMarkerStyle8',
				o: 'oMarkerStyle8'
			}
		};
		var selectedStyle = styleMap[currentAppearanceStyle] || styleMap[0];
		var xAssetName = selectedStyle.x;
		var oAssetName = selectedStyle.o;
		// Unified marker creation with error handling
		try {
			var assetName = type === 1 ? xAssetName : oAssetName;
			self.marker = self.attachAsset(assetName, {
				anchorX: 0.5,
				anchorY: 0.5,
				alpha: 0,
				scaleX: 0.1,
				scaleY: 0.1
			});
			// Position marker at center of cell
			self.marker.x = 0;
			self.marker.y = 0;
			// Calculate appropriate scale based on cell size and marker asset size
			var cellSize = 580; // Cell size from asset definition
			var markerOriginalSize = 400; // Original marker size from asset definitions
			var targetScale = cellSize * 0.7 / markerOriginalSize; // Use 70% of cell size for proper proportion
			// Adjust scale for different appearance styles to maintain consistency
			if (currentAppearanceStyle === 1 || currentAppearanceStyle === 6 || currentAppearanceStyle === 4) {
				// Cartoon styles use 320px assets, so adjust scaling
				markerOriginalSize = 320;
				targetScale = cellSize * 0.7 / markerOriginalSize;
			}
			// Consistent animation for all styles
			animateObject(self.marker, {
				alpha: 0.9,
				scaleX: targetScale,
				scaleY: targetScale
			}, {
				duration: 300,
				easing: 'easeOut',
				onFinish: callback
			});
		} catch (e) {
			console.log("Error creating marker, using fallback");
			// Fallback to basic marker
			self.marker = self.attachAsset('xMarker', {
				anchorX: 0.5,
				anchorY: 0.5,
				alpha: 0,
				scaleX: 0.1,
				scaleY: 0.1
			});
			// Position fallback marker at center of cell
			self.marker.x = 0;
			self.marker.y = 0;
			// Calculate scale for fallback marker
			var cellSize = 580;
			var markerOriginalSize = 400;
			var targetScale = cellSize * 0.7 / markerOriginalSize;
			animateObject(self.marker, {
				alpha: 0.9,
				scaleX: targetScale,
				scaleY: targetScale
			}, {
				duration: 300,
				easing: 'easeOut',
				onFinish: callback
			});
		}
		LK.getSound('place').play();
		return true;
	};
	self.down = function (x, y, obj) {
		// Basic validation checks
		if (!gameReady || gameOver || gameMode === 'menu') return;
		if (self.value !== 0) return; // Cell already occupied
		// Prevent placing markers when game board is not visible
		if (gameBoard.alpha === 0) return;
		// In AI mode, prevent ALL player input during AI processing or when it's not player's turn
		if (isAIMode && (currentPlayer !== 1 || aiProcessing)) return;
		// Additional safety check to prevent race conditions
		if (isAIMode && currentPlayer === 2) return;
		// Extra validation: ensure no other animations are running
		if (isAIMode && aiProcessing) {
			console.log("Player input blocked - AI is processing");
			return;
		}
		// Check if any cell is currently animating to prevent interference
		for (var r = 0; r < 3; r++) {
			for (var c = 0; c < 3; c++) {
				var checkCell = grid[r][c];
				if (checkCell && checkCell.marker && checkCell.marker.alpha < 0.9 && checkCell.marker.alpha > 0) {
					return; // Animation in progress, prevent input
				}
			}
		}
		// Place the marker with animation and wait for completion
		if (self.placeMarker(currentPlayer, function () {
			// This callback runs after the marker animation completes
			checkWin();
			if (!gameOver) {
				if (isAIMode && currentPlayer === 1) {
					// AI mode - player played, now AI plays
					currentPlayer = 2;
					updateTurnDisplay();
					// Only start AI processing if not already processing
					if (!aiProcessing) {
						aiProcessing = true;
						LK.setTimeout(function () {
							if (!gameOver && currentPlayer === 2 && isAIMode) {
								aiProcessing = false;
								makeAIMove();
							} else {
								aiProcessing = false;
							}
						}, 100); // Small delay to ensure UI updates
					}
				} else if (isAIMode && currentPlayer === 2) {
					// This shouldn't happen in AI mode since AI doesn't click
					currentPlayer = 1;
					updateTurnDisplay();
				} else {
					// Two player mode - switch players normally
					currentPlayer = currentPlayer === 1 ? 2 : 1;
					updateTurnDisplay();
				}
			}
		})) {
			// Marker placement started successfully - disable further input until animation completes
		}
	};
	return self;
});
var WinLine = Container.expand(function () {
	var self = Container.call(this);
	self.line = self.attachAsset('winLine', {
		anchorX: 0.5,
		anchorY: 0.5,
		alpha: 0,
		scaleX: 0
	});
	self.showWinLine = function (startX, startY, endX, endY, color) {
		var deltaX = endX - startX;
		var deltaY = endY - startY;
		var angle = Math.atan2(deltaY, deltaX);
		var distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
		self.x = startX + deltaX / 2;
		self.y = startY + deltaY / 2;
		self.line.rotation = angle;
		self.line.tint = color;
		self.line.width = distance;
		animateObject(self.line, {
			alpha: 1,
			scaleX: 1
		}, {
			duration: 500,
			easing: 'easeOut'
		});
	};
	return self;
});
/**** 
* Initialize Game
****/ 
var game = new LK.Game({
	backgroundColor: 0x1a1a1a
});
/**** 
* Game Code
****/ 
// Basic tween replacement - simple property animation
// Asset lazy loading function
// Initialize only essential marker assets - others loaded dynamically when needed
var tween = {
	stop: function stop(obj) {
		if (obj && obj._tweenActive) {
			obj._tweenActive = false;
		}
	},
	easeOut: 'easeOut',
	easeInOut: 'easeInOut'
};
function animateObject(obj, props, options) {
	if (!obj || !props) return;
	obj._tweenActive = true;
	var duration = options.duration || 300;
	var startTime = Date.now();
	var startProps = {};
	// Store starting values
	for (var key in props) {
		startProps[key] = obj[key] || 0;
	}
	function animate() {
		if (!obj._tweenActive) return;
		var elapsed = Date.now() - startTime;
		var progress = Math.min(elapsed / duration, 1);
		// Simple easing
		if (options.easing === 'easeOut') {
			progress = 1 - Math.pow(1 - progress, 2);
		} else if (options.easing === 'easeInOut') {
			progress = progress < 0.5 ? 2 * progress * progress : 1 - Math.pow(-2 * progress + 2, 2) / 2;
		}
		// Update properties
		for (var key in props) {
			var start = startProps[key];
			var end = props[key];
			obj[key] = start + (end - start) * progress;
		}
		if (progress >= 1) {
			obj._tweenActive = false;
			if (options.onFinish) options.onFinish();
			if (options.repeat === -1 && options.yoyo) {
				// Simple repeat logic for pulsing effects
				var newProps = {};
				for (var key in props) {
					newProps[key] = startProps[key];
				}
				animateObject(obj, newProps, options);
			}
		} else {
			LK.setTimeout(animate, 16); // ~60fps
		}
	}
	animate();
}
// Replace tween function calls
window.tween = animateObject;
tween.stop = function (obj) {
	if (obj && obj._tweenActive) {
		obj._tweenActive = false;
	}
};
tween.easeOut = 'easeOut';
tween.easeInOut = 'easeInOut';
// Basic storage replacement - use browser localStorage
var storage = {
	get language() {
		try {
			return localStorage.getItem('language') || 'tr';
		} catch (e) {
			return 'tr';
		}
	},
	set language(val) {
		try {
			localStorage.setItem('language', val);
		} catch (e) {}
	},
	get appearanceStyle() {
		try {
			var val = localStorage.getItem('appearanceStyle');
			return val !== null ? parseInt(val) : 0;
		} catch (e) {
			return 0;
		}
	},
	set appearanceStyle(val) {
		try {
			localStorage.setItem('appearanceStyle', val.toString());
		} catch (e) {}
	},
	get blueWins() {
		try {
			var val = localStorage.getItem('blueWins');
			return val !== null ? parseInt(val) : 0;
		} catch (e) {
			return 0;
		}
	},
	set blueWins(val) {
		try {
			localStorage.setItem('blueWins', val.toString());
		} catch (e) {}
	},
	get redWins() {
		try {
			var val = localStorage.getItem('redWins');
			return val !== null ? parseInt(val) : 0;
		} catch (e) {
			return 0;
		}
	},
	set redWins(val) {
		try {
			localStorage.setItem('redWins', val.toString());
		} catch (e) {}
	},
	get draws() {
		try {
			var val = localStorage.getItem('draws');
			return val !== null ? parseInt(val) : 0;
		} catch (e) {
			return 0;
		}
	},
	set draws(val) {
		try {
			localStorage.setItem('draws', val.toString());
		} catch (e) {}
	}
};
function loadMarkerAsset(assetName, styleConfig) {
	try {
		return LK.getAsset(assetName, {});
	} catch (e) {
		console.log("Failed to load asset: " + assetName + ", using fallback");
		// Fallback to basic marker
		return LK.getAsset(styleConfig.fallback || 'xMarker', {});
	}
}
// Alternative appearance styles
var grid = [];
var currentPlayer = 1; // 1 = Blue X, 2 = Red O
var gameOver = false;
var winLine = null;
var gameMode = 'menu'; // 'menu', 'ai', 'twoPlayer', 'difficulty'
var isAIMode = false;
var aiDifficulty = 'normal'; // 'easy', 'normal', 'hard'
var aiProcessing = false; // Flag to prevent AI from interfering with player moves
var currentLanguage;
var currentAppearanceStyle;
// Safe storage access with error handling
try {
	currentLanguage = storage.language || 'tr';
	currentAppearanceStyle = storage.appearanceStyle !== undefined ? storage.appearanceStyle : 0;
} catch (e) {
	console.log("Storage access error, using defaults");
	currentLanguage = 'tr';
	currentAppearanceStyle = 0;
}
// Initialize statistics from storage with defaults
var gameStats = {
	blueWins: storage.blueWins || 0,
	redWins: storage.redWins || 0,
	draws: storage.draws || 0
};
var winnerTextBg = null; // Global reference for winner text background
var drawTextBg = null; // Global reference for draw text background
var selectedDifficulty = ''; // Store selected difficulty for confirmation
var isResetConfirmation = false; // Track if we're in reset confirmation mode
var cartoonMenuVisible = false; // Track if cartoon submenu is visible
var superheroMenuVisible = false; // Track if superhero submenu is visible
var footballMenuVisible = false; // Track if football submenu is visible
// Cartoon submenu UI elements
var cartoonTitle = new Text2('', {
	size: 100,
	fill: 0xFFFFFF
});
cartoonTitle.anchor.set(0.5, 0.5);
LK.gui.center.addChild(cartoonTitle);
cartoonTitle.y = -200;
cartoonTitle.alpha = 0;
var tomJerryBtn = new Text2('', {
	size: 100,
	fill: 0xFF8800
});
tomJerryBtn.anchor.set(0.5, 0.5);
tomJerryBtn.interactive = false;
tomJerryBtn.hitArea = new Rectangle(-250, -60, 500, 120);
LK.gui.center.addChild(tomJerryBtn);
tomJerryBtn.y = -120;
tomJerryBtn.alpha = 0;
var phineasFerbBtn = new Text2('', {
	size: 100,
	fill: 0x00FF00
});
phineasFerbBtn.anchor.set(0.5, 0.5);
phineasFerbBtn.interactive = false;
phineasFerbBtn.hitArea = new Rectangle(-250, -60, 500, 120);
LK.gui.center.addChild(phineasFerbBtn);
phineasFerbBtn.y = 20;
phineasFerbBtn.alpha = 0;
var dipperMabelBtn = new Text2('', {
	size: 100,
	fill: 0xFF6600
});
dipperMabelBtn.anchor.set(0.5, 0.5);
dipperMabelBtn.interactive = false;
dipperMabelBtn.hitArea = new Rectangle(-250, -60, 500, 120);
LK.gui.center.addChild(dipperMabelBtn);
dipperMabelBtn.y = 160;
dipperMabelBtn.alpha = 0;
// Cartoon submenu backgrounds
var tomJerryBg = LK.getAsset('cell', {
	anchorX: 0.5,
	anchorY: 0.5,
	width: 550,
	height: 120,
	tint: 0xFF8800,
	alpha: 0.2
});
LK.gui.center.addChild(tomJerryBg);
tomJerryBg.y = -120;
tomJerryBg.alpha = 0;
var phineasFerbBg = LK.getAsset('cell', {
	anchorX: 0.5,
	anchorY: 0.5,
	width: 550,
	height: 120,
	tint: 0x00FF00,
	alpha: 0.2
});
LK.gui.center.addChild(phineasFerbBg);
phineasFerbBg.y = 20;
phineasFerbBg.alpha = 0;
var dipperMabelBg = LK.getAsset('cell', {
	anchorX: 0.5,
	anchorY: 0.5,
	width: 550,
	height: 120,
	tint: 0xFF6600,
	alpha: 0.2
});
LK.gui.center.addChild(dipperMabelBg);
dipperMabelBg.y = 160;
dipperMabelBg.alpha = 0;
// Superhero submenu UI elements
var superheroTitle = new Text2('', {
	size: 100,
	fill: 0xFFFFFF
});
superheroTitle.anchor.set(0.5, 0.5);
LK.gui.center.addChild(superheroTitle);
superheroTitle.y = -200;
superheroTitle.alpha = 0;
var batmanJokerBtn = new Text2('', {
	size: 100,
	fill: 0xFFD700
});
batmanJokerBtn.anchor.set(0.5, 0.5);
batmanJokerBtn.interactive = false;
batmanJokerBtn.hitArea = new Rectangle(-250, -60, 500, 120);
LK.gui.center.addChild(batmanJokerBtn);
batmanJokerBtn.y = -80;
batmanJokerBtn.alpha = 0;
var spidermanVenomBtn = new Text2('', {
	size: 100,
	fill: 0xFF0000
});
spidermanVenomBtn.anchor.set(0.5, 0.5);
spidermanVenomBtn.interactive = true;
spidermanVenomBtn.hitArea = new Rectangle(-250, -60, 500, 120);
LK.gui.center.addChild(spidermanVenomBtn);
spidermanVenomBtn.y = 80;
spidermanVenomBtn.alpha = 0;
// Superhero submenu backgrounds
var batmanJokerBg = LK.getAsset('cell', {
	anchorX: 0.5,
	anchorY: 0.5,
	width: 550,
	height: 120,
	tint: 0x000000,
	alpha: 0.2
});
LK.gui.center.addChild(batmanJokerBg);
batmanJokerBg.y = -80;
batmanJokerBg.alpha = 0;
var spidermanVenomBg = LK.getAsset('cell', {
	anchorX: 0.5,
	anchorY: 0.5,
	width: 550,
	height: 120,
	tint: 0xFF0000,
	alpha: 0.2
});
LK.gui.center.addChild(spidermanVenomBg);
spidermanVenomBg.y = 80;
spidermanVenomBg.alpha = 0;
// Football submenu UI elements
var footballTitle = new Text2('', {
	size: 100,
	fill: 0xFFFFFF
});
footballTitle.anchor.set(0.5, 0.5);
LK.gui.center.addChild(footballTitle);
footballTitle.y = -200;
footballTitle.alpha = 0;
var ronaldoMessiBtn = new Text2('', {
	size: 100,
	fill: 0xFF4444
});
ronaldoMessiBtn.anchor.set(0.5, 0.5);
ronaldoMessiBtn.interactive = false;
ronaldoMessiBtn.hitArea = new Rectangle(-250, -60, 500, 120);
LK.gui.center.addChild(ronaldoMessiBtn);
ronaldoMessiBtn.y = -120;
ronaldoMessiBtn.alpha = 0;
var galatasarayFenerbahceBtn = new Text2('', {
	size: 100,
	fill: 0x00FFFF
});
galatasarayFenerbahceBtn.anchor.set(0.5, 0.5);
galatasarayFenerbahceBtn.interactive = false;
galatasarayFenerbahceBtn.hitArea = new Rectangle(-250, -60, 500, 120);
LK.gui.center.addChild(galatasarayFenerbahceBtn);
galatasarayFenerbahceBtn.y = 20;
galatasarayFenerbahceBtn.alpha = 0;
var realMadridBarcaBtn = new Text2('', {
	size: 100,
	fill: 0xFFD700
});
realMadridBarcaBtn.anchor.set(0.5, 0.5);
realMadridBarcaBtn.interactive = false;
realMadridBarcaBtn.hitArea = new Rectangle(-250, -60, 500, 120);
LK.gui.center.addChild(realMadridBarcaBtn);
realMadridBarcaBtn.y = 160;
realMadridBarcaBtn.alpha = 0;
// Football submenu backgrounds
var ronaldoMessiBg = LK.getAsset('cell', {
	anchorX: 0.5,
	anchorY: 0.5,
	width: 550,
	height: 120,
	tint: 0xFF4444,
	alpha: 0.2
});
LK.gui.center.addChild(ronaldoMessiBg);
ronaldoMessiBg.y = -120;
ronaldoMessiBg.alpha = 0;
var galatasarayFenerbahceBg = LK.getAsset('cell', {
	anchorX: 0.5,
	anchorY: 0.5,
	width: 550,
	height: 120,
	tint: 0x00FFFF,
	alpha: 0.2
});
LK.gui.center.addChild(galatasarayFenerbahceBg);
galatasarayFenerbahceBg.y = 20;
galatasarayFenerbahceBg.alpha = 0;
var realMadridBarcaBg = LK.getAsset('cell', {
	anchorX: 0.5,
	anchorY: 0.5,
	width: 550,
	height: 120,
	tint: 0xFFD700,
	alpha: 0.2
});
LK.gui.center.addChild(realMadridBarcaBg);
realMadridBarcaBg.y = 160;
realMadridBarcaBg.alpha = 0;
var languageTexts = {
	tr: {
		blueTurn: 'Sıra: Mavinin',
		redTurn: 'Sıra: Kırmızının',
		blueWin: 'MAVİ TAKIM KAZANDI!',
		redWin: 'KIRMIZI TAKIM KAZANDI!',
		draw: 'BERABERE!',
		playAgain: 'Tekrar Oyna',
		language: 'Türkçe',
		vsAI: 'Yapay Zeka ile Oyna',
		twoPlayer: 'İki Kişilik Oyna',
		selectMode: 'Oyun Modunu Seçin',
		back: '← Geri',
		exit: 'Çıkış',
		selectDifficulty: 'Zorluk Seçin',
		easy: 'Kolay',
		normal: 'Normal',
		hard: 'Zor',
		confirmEasy: 'Kolay modu seçmek istiyor musunuz?',
		confirmNormal: 'Normal modu seçmek istiyor musunuz?',
		confirmHard: 'Zor modu seçmek istiyor musunuz?',
		yes: 'Evet',
		no: 'Hayır',
		blueWins: 'Mavi Galibiyetler: ',
		redWins: 'Kırmızı Galibiyetler: ',
		draws: 'Beraberlikler: ',
		resetStats: 'İstatistikleri Sıfırla',
		confirmReset: 'İstatistikleri sıfırlamaktan emin misiniz?',
		settings: 'Ayarlar',
		changeAppearance: 'Görünümü Değiştir',
		selectPackage: 'Paket Seçın',
		package1: 'Klasik X-O',
		package2: 'Çizgi Film',
		package3: 'Süper Kahramanlar',
		package4: 'Futbol',
		package5: 'Minecraft',
		package6: 'Belirsiz',
		selected: 'Seçili: ',
		selectSuperhero: 'Süper Kahraman Seçin',
		batmanJoker: 'Batman vs Joker',
		spidermanVenom: 'Spiderman vs Venom',
		batmanWin: 'BATMAN KAZANDI!',
		jokerWin: 'JOKER KAZANDI!',
		spidermanWin: 'SPIDERMAN KAZANDI!',
		venomWin: 'VENOM KAZANDI!'
	},
	en: {
		blueTurn: 'Turn: Blue',
		redTurn: 'Turn: Red',
		blueWin: 'BLUE TEAM WON!',
		redWin: 'RED TEAM WON!',
		draw: 'DRAW!',
		playAgain: 'Play Again',
		language: 'English',
		vsAI: 'Play vs AI',
		twoPlayer: 'Two Player',
		selectMode: 'Select Game Mode',
		back: '← Back',
		exit: 'Exit',
		selectDifficulty: 'Select Difficulty',
		easy: 'Easy',
		normal: 'Normal',
		hard: 'Hard',
		confirmEasy: 'Do you want to select Easy mode?',
		confirmNormal: 'Do you want to select Normal mode?',
		confirmHard: 'Do you want to select Hard mode?',
		yes: 'Yes',
		no: 'No',
		blueWins: 'Blue Wins: ',
		redWins: 'Red Wins: ',
		draws: 'Draws: ',
		resetStats: 'Reset Statistics',
		confirmReset: 'Are you sure you want to reset statistics?',
		settings: 'Settings',
		changeAppearance: 'Change Appearance',
		selectPackage: 'Select Package',
		package1: 'Classic X-O',
		package2: 'Cartoon',
		package3: 'Superheroes',
		package4: 'Football',
		package5: 'Minecraft',
		package6: 'Undefined',
		selected: 'Selected: ',
		selectSuperhero: 'Select Superhero',
		batmanJoker: 'Batman vs Joker',
		spidermanVenom: 'Spiderman vs Venom',
		batmanWin: 'BATMAN WON!',
		jokerWin: 'JOKER WON!',
		spidermanWin: 'SPIDERMAN WON!',
		venomWin: 'VENOM WON!'
	}
};
// Game setup
var gameBoard = game.addChild(new Container());
gameBoard.x = 2048 / 2;
gameBoard.y = 2732 / 2;
gameBoard.scaleX = 1.2;
gameBoard.scaleY = 1.2;
gameBoard.alpha = 0; // Hidden initially
// Create background
var background = gameBoard.attachAsset('gridBackground', {
	anchorX: 0.5,
	anchorY: 0.5
});
// Create grid lines
var verticalLine1 = gameBoard.attachAsset('gridLine', {
	anchorX: 0.5,
	anchorY: 0.5,
	x: -300,
	height: 1800
});
var verticalLine2 = gameBoard.attachAsset('gridLine', {
	anchorX: 0.5,
	anchorY: 0.5,
	x: 300,
	height: 1800
});
var horizontalLine1 = gameBoard.attachAsset('gridLine', {
	anchorX: 0.5,
	anchorY: 0.5,
	y: -300,
	width: 1800,
	height: 8
});
var horizontalLine2 = gameBoard.attachAsset('gridLine', {
	anchorX: 0.5,
	anchorY: 0.5,
	y: 300,
	width: 1800,
	height: 8
});
// Create cells
for (var row = 0; row < 3; row++) {
	grid[row] = [];
	for (var col = 0; col < 3; col++) {
		var cell = gameBoard.addChild(new Cell(row, col));
		cell.x = (col - 1) * 600;
		cell.y = (row - 1) * 600;
		grid[row][col] = cell;
	}
}
// UI Elements
var blueTurnText = new Text2(languageTexts[currentLanguage].blueTurn, {
	size: 100,
	fill: 0x00AAFF
});
blueTurnText.anchor.set(0.5, 0);
LK.gui.top.addChild(blueTurnText);
blueTurnText.y = 220;
var redTurnText = new Text2(languageTexts[currentLanguage].redTurn, {
	size: 100,
	fill: 0xff0000
});
redTurnText.anchor.set(0.5, 0);
LK.gui.top.addChild(redTurnText);
redTurnText.y = 220;
var languageBtn = new Text2(languageTexts[currentLanguage === 'tr' ? 'en' : 'tr'].language, {
	size: 60,
	fill: 0xFFFFFF
});
languageBtn.anchor.set(0.5, 0);
LK.gui.top.addChild(languageBtn);
languageBtn.y = 120;
var statusText = new Text2('', {
	size: 100,
	fill: 0xFFFFFF
});
statusText.anchor.set(0.5, 0.5);
LK.gui.center.addChild(statusText);
statusText.y = 400;
// Create background for play again button
var playAgainBg = LK.getAsset('cell', {
	anchorX: 0.5,
	anchorY: 0.5,
	width: 500,
	height: 120,
	tint: 0x4CAF50,
	alpha: 0
});
LK.gui.center.addChild(playAgainBg);
playAgainBg.y = 550;
var playAgainBtn = new Text2(languageTexts[currentLanguage].playAgain, {
	size: 90,
	fill: 0xFFFFFF
});
playAgainBtn.anchor.set(0.5, 0.5);
playAgainBtn.interactive = false;
playAgainBtn.hitArea = new Rectangle(-250, -60, 500, 120);
LK.gui.center.addChild(playAgainBtn);
playAgainBtn.y = 550;
playAgainBtn.alpha = 0;
// Settings button
var settingsBtn = new Text2(languageTexts[currentLanguage].settings, {
	size: 100,
	fill: 0xFFAA00
});
settingsBtn.anchor.set(0.5, 0.5);
settingsBtn.interactive = false;
settingsBtn.hitArea = new Rectangle(-150, -60, 300, 120);
LK.gui.center.addChild(settingsBtn);
settingsBtn.y = -400;
// Menu UI elements
var menuTitle = new Text2(languageTexts[currentLanguage].selectMode, {
	size: 120,
	fill: 0xFFFFFF
});
menuTitle.anchor.set(0.5, 0.5);
LK.gui.center.addChild(menuTitle);
menuTitle.y = -200;
// AI Difficulty selection elements
var difficultyTitle = new Text2(languageTexts[currentLanguage].selectDifficulty, {
	size: 100,
	fill: 0xFFFFFF
});
difficultyTitle.anchor.set(0.5, 0.5);
LK.gui.center.addChild(difficultyTitle);
difficultyTitle.y = -250;
difficultyTitle.alpha = 0;
// Create background blocks for difficulty buttons
var easyBlock = LK.getAsset('cell', {
	anchorX: 0.5,
	anchorY: 0.5,
	width: 500,
	height: 150,
	tint: 0x44FF44,
	alpha: 0.3
});
LK.gui.center.addChild(easyBlock);
easyBlock.y = -120;
easyBlock.alpha = 0;
var normalBlock = LK.getAsset('cell', {
	anchorX: 0.5,
	anchorY: 0.5,
	width: 500,
	height: 150,
	tint: 0xFFAA00,
	alpha: 0.3
});
LK.gui.center.addChild(normalBlock);
normalBlock.y = 70;
normalBlock.alpha = 0;
var hardBlock = LK.getAsset('cell', {
	anchorX: 0.5,
	anchorY: 0.5,
	width: 500,
	height: 150,
	tint: 0xFF4444,
	alpha: 0.3
});
LK.gui.center.addChild(hardBlock);
hardBlock.y = 260;
hardBlock.alpha = 0;
var easyBtn = new Text2(languageTexts[currentLanguage].easy, {
	size: 110,
	fill: 0x44FF44
});
easyBtn.anchor.set(0.5, 0.5);
easyBtn.interactive = false;
easyBtn.hitArea = new Rectangle(-250, -75, 500, 150);
LK.gui.center.addChild(easyBtn);
easyBtn.y = -120;
easyBtn.alpha = 0;
var normalBtn = new Text2(languageTexts[currentLanguage].normal, {
	size: 110,
	fill: 0xFFAA00
});
normalBtn.anchor.set(0.5, 0.5);
normalBtn.interactive = false;
normalBtn.hitArea = new Rectangle(-250, -75, 500, 150);
LK.gui.center.addChild(normalBtn);
normalBtn.y = 70;
normalBtn.alpha = 0;
var hardBtn = new Text2(languageTexts[currentLanguage].hard, {
	size: 110,
	fill: 0xFF4444
});
hardBtn.anchor.set(0.5, 0.5);
hardBtn.interactive = false;
hardBtn.hitArea = new Rectangle(-250, -75, 500, 150);
LK.gui.center.addChild(hardBtn);
hardBtn.y = 260;
hardBtn.alpha = 0;
// Confirmation dialog elements
var confirmationBg = LK.getAsset('gridBackground', {
	anchorX: 0.5,
	anchorY: 0.5,
	width: 1200,
	height: 600,
	tint: 0x000000,
	alpha: 0.8
});
LK.gui.center.addChild(confirmationBg);
confirmationBg.alpha = 0;
var confirmationText = new Text2('', {
	size: 80,
	fill: 0xFFFFFF
});
confirmationText.anchor.set(0.5, 0.5);
LK.gui.center.addChild(confirmationText);
confirmationText.y = -50;
confirmationText.alpha = 0;
var yesBtn = new Text2(languageTexts[currentLanguage].yes, {
	size: 80,
	fill: 0x44FF44
});
yesBtn.anchor.set(0.5, 0.5);
yesBtn.interactive = true;
LK.gui.center.addChild(yesBtn);
yesBtn.x = -150;
yesBtn.y = 100;
yesBtn.alpha = 0;
var noBtn = new Text2(languageTexts[currentLanguage].no, {
	size: 80,
	fill: 0xFF4444
});
noBtn.anchor.set(0.5, 0.5);
noBtn.interactive = true;
LK.gui.center.addChild(noBtn);
noBtn.x = 150;
noBtn.y = 100;
noBtn.alpha = 0;
// Add hit areas to confirmation dialog buttons
yesBtn.hitArea = new Rectangle(-100, -40, 200, 80);
noBtn.hitArea = new Rectangle(-100, -40, 200, 80);
// Confirmation dialog button handlers
yesBtn.down = function (x, y, obj) {
	if (isResetConfirmation) {
		// Reset all statistics to zero
		gameStats.blueWins = 0;
		gameStats.redWins = 0;
		gameStats.draws = 0;
		// Update storage
		storage.blueWins = 0;
		storage.redWins = 0;
		storage.draws = 0;
		// Update display
		blueStatsText.setText(languageTexts[currentLanguage].blueWins + gameStats.blueWins);
		redStatsText.setText(languageTexts[currentLanguage].redWins + gameStats.redWins);
		drawStatsText.setText(languageTexts[currentLanguage].draws + gameStats.draws);
		hideConfirmationDialog();
	} else if (selectedDifficulty) {
		aiDifficulty = selectedDifficulty;
		hideConfirmationDialog();
		startGame('ai');
	}
};
noBtn.down = function (x, y, obj) {
	hideConfirmationDialog();
};
// Add glowing animation to blocks
function animateDifficultyBlocks() {
	// Stop any existing animations on difficulty blocks first
	tween.stop(easyBlock);
	tween.stop(normalBlock);
	tween.stop(hardBlock);
	// Reset block properties to prevent visual artifacts
	easyBlock.alpha = 0.3;
	normalBlock.alpha = 0.3;
	hardBlock.alpha = 0.3;
	easyBlock.scaleX = 1;
	easyBlock.scaleY = 1;
	normalBlock.scaleX = 1;
	normalBlock.scaleY = 1;
	hardBlock.scaleX = 1;
	hardBlock.scaleY = 1;
}
function showConfirmationDialog(difficulty) {
	selectedDifficulty = difficulty;
	gameMode = 'confirmation';
	isResetConfirmation = false;
	var confirmText = '';
	if (difficulty === 'easy') {
		confirmText = languageTexts[currentLanguage].confirmEasy;
	} else if (difficulty === 'normal') {
		confirmText = languageTexts[currentLanguage].confirmNormal;
	} else if (difficulty === 'hard') {
		confirmText = languageTexts[currentLanguage].confirmHard;
	}
	confirmationText.setText(confirmText);
	// Enable confirmation button interactions
	yesBtn.interactive = true;
	noBtn.interactive = true;
	// Show confirmation elements
	animateObject(confirmationBg, {
		alpha: 0.8
	}, {
		duration: 200
	});
	tween(confirmationText, {
		alpha: 1
	}, {
		duration: 200
	});
	tween(yesBtn, {
		alpha: 1
	}, {
		duration: 200
	});
	tween(noBtn, {
		alpha: 1
	}, {
		duration: 200
	});
}
function showResetConfirmationDialog() {
	isResetConfirmation = true;
	gameMode = 'confirmation';
	selectedDifficulty = '';
	confirmationText.setText(languageTexts[currentLanguage].confirmReset);
	// Enable confirmation button interactions
	yesBtn.interactive = true;
	noBtn.interactive = true;
	// Show confirmation elements
	tween(confirmationBg, {
		alpha: 0.8
	}, {
		duration: 200
	});
	tween(confirmationText, {
		alpha: 1
	}, {
		duration: 200
	});
	tween(yesBtn, {
		alpha: 1
	}, {
		duration: 200
	});
	tween(noBtn, {
		alpha: 1
	}, {
		duration: 200
	});
}
function hideConfirmationDialog() {
	if (isResetConfirmation) {
		// Return to appropriate game mode when hiding reset confirmation
		if (gameBoard.alpha > 0) {
			gameMode = isAIMode ? 'ai' : 'twoPlayer';
		} else {
			gameMode = 'menu';
		}
	} else {
		gameMode = 'difficulty';
	}
	selectedDifficulty = '';
	isResetConfirmation = false;
	// Disable confirmation button interactions
	yesBtn.interactive = false;
	noBtn.interactive = false;
	// Hide confirmation elements
	tween(confirmationBg, {
		alpha: 0
	}, {
		duration: 200
	});
	tween(confirmationText, {
		alpha: 0
	}, {
		duration: 200
	});
	tween(yesBtn, {
		alpha: 0
	}, {
		duration: 200
	});
	tween(noBtn, {
		alpha: 0
	}, {
		duration: 200
	});
}
var vsAIBtn = new Text2(languageTexts[currentLanguage].vsAI, {
	size: 120,
	fill: 0x00AAFF
});
vsAIBtn.anchor.set(0.5, 0.5);
vsAIBtn.interactive = false;
vsAIBtn.hitArea = new Rectangle(-300, -75, 600, 150);
LK.gui.center.addChild(vsAIBtn);
vsAIBtn.y = -50;
var twoPlayerBtn = new Text2(languageTexts[currentLanguage].twoPlayer, {
	size: 120,
	fill: 0xFF4444
});
twoPlayerBtn.anchor.set(0.5, 0.5);
twoPlayerBtn.interactive = false;
twoPlayerBtn.hitArea = new Rectangle(-300, -75, 600, 150);
LK.gui.center.addChild(twoPlayerBtn);
twoPlayerBtn.y = 150;
var backBtn = new Text2(languageTexts[currentLanguage].back, {
	size: 70,
	fill: 0xFFFFFF
});
backBtn.anchor.set(0.5, 0.5);
backBtn.interactive = false;
backBtn.hitArea = new Rectangle(-150, -40, 300, 80);
LK.gui.top.addChild(backBtn);
backBtn.x = 200;
backBtn.y = 220;
backBtn.alpha = 0;
var exitBtn = new Text2(languageTexts[currentLanguage].exit, {
	size: 60,
	fill: 0xFF0000
});
exitBtn.anchor.set(0.5, 0);
exitBtn.interactive = false;
exitBtn.hitArea = new Rectangle(-80, -30, 160, 60);
LK.gui.top.addChild(exitBtn);
exitBtn.y = 120;
exitBtn.x = 400;
exitBtn.alpha = 0;
// Statistics display elements
var statsContainer = new Container();
LK.gui.bottom.addChild(statsContainer);
statsContainer.y = -180;
statsContainer.alpha = 0;
var blueStatsText = new Text2(languageTexts[currentLanguage].blueWins + gameStats.blueWins, {
	size: 45,
	fill: 0x00AAFF
});
blueStatsText.anchor.set(0.5, 0);
statsContainer.addChild(blueStatsText);
blueStatsText.y = 0;
blueStatsText.x = -600;
var redStatsText = new Text2(languageTexts[currentLanguage].redWins + gameStats.redWins, {
	size: 45,
	fill: 0xFF4444
});
redStatsText.anchor.set(0.5, 0);
statsContainer.addChild(redStatsText);
redStatsText.y = 0;
redStatsText.x = 0;
var drawStatsText = new Text2(languageTexts[currentLanguage].draws + gameStats.draws, {
	size: 45,
	fill: 0xFFFFFF
});
drawStatsText.anchor.set(0.5, 0);
statsContainer.addChild(drawStatsText);
drawStatsText.y = 0;
drawStatsText.x = 600;
var resetStatsBtn = new Text2(languageTexts[currentLanguage].resetStats, {
	size: 40,
	fill: 0xFF4444
});
resetStatsBtn.anchor.set(0.5, 0);
resetStatsBtn.interactive = true;
resetStatsBtn.hitArea = new Rectangle(-70, -20, 140, 40);
statsContainer.addChild(resetStatsBtn);
resetStatsBtn.y = 70;
resetStatsBtn.x = 0;
// Change Appearance button
var changeAppearanceBtn = new Text2(languageTexts[currentLanguage].changeAppearance, {
	size: 60,
	fill: 0x00AAFF
});
changeAppearanceBtn.anchor.set(0.5, 0.5);
changeAppearanceBtn.interactive = true;
changeAppearanceBtn.hitArea = new Rectangle(-120, -30, 240, 60);
LK.gui.center.addChild(changeAppearanceBtn);
changeAppearanceBtn.y = -100;
changeAppearanceBtn.alpha = 0;
// Current appearance style display
var currentStyleText = new Text2('', {
	size: 50,
	fill: 0xFFFFFF
});
currentStyleText.anchor.set(0.5, 0.5);
LK.gui.center.addChild(currentStyleText);
currentStyleText.y = -20;
currentStyleText.alpha = 0;
// Package selection UI elements
var packageTitle = new Text2(languageTexts[currentLanguage].selectPackage, {
	size: 100,
	fill: 0xFFFFFF
});
packageTitle.anchor.set(0.5, 0.5);
LK.gui.center.addChild(packageTitle);
packageTitle.y = -250;
packageTitle.alpha = 0;
// Package selection buttons
var package1Btn = new Text2(languageTexts[currentLanguage].package1, {
	size: 100,
	fill: 0x00AAFF
});
package1Btn.anchor.set(0.5, 0.5);
package1Btn.interactive = false;
package1Btn.hitArea = new Rectangle(-200, -60, 400, 120);
LK.gui.center.addChild(package1Btn);
package1Btn.y = -140;
package1Btn.alpha = 0;
var package2Btn = new Text2(languageTexts[currentLanguage].package2, {
	size: 100,
	fill: 0xFF8800
});
package2Btn.anchor.set(0.5, 0.5);
package2Btn.interactive = false;
package2Btn.hitArea = new Rectangle(-200, -60, 400, 120);
LK.gui.center.addChild(package2Btn);
package2Btn.y = -20;
package2Btn.alpha = 0;
var package3Btn = new Text2(languageTexts[currentLanguage].package3, {
	size: 100,
	fill: 0x44FF44
});
package3Btn.anchor.set(0.5, 0.5);
package3Btn.interactive = false;
package3Btn.hitArea = new Rectangle(-200, -60, 400, 120);
LK.gui.center.addChild(package3Btn);
package3Btn.y = 100;
package3Btn.alpha = 0;
var package4Btn = new Text2(languageTexts[currentLanguage].package4, {
	size: 100,
	fill: 0xFFBBBB
});
package4Btn.anchor.set(0.5, 0.5);
package4Btn.interactive = false;
package4Btn.hitArea = new Rectangle(-200, -60, 400, 120);
LK.gui.center.addChild(package4Btn);
package4Btn.y = 220;
package4Btn.alpha = 0;
// Package selection backgrounds
var package1Bg = LK.getAsset('cell', {
	anchorX: 0.5,
	anchorY: 0.5,
	width: 450,
	height: 120,
	tint: 0x00AAFF,
	alpha: 0.2
});
LK.gui.center.addChild(package1Bg);
package1Bg.y = -140;
package1Bg.alpha = 0;
var package2Bg = LK.getAsset('cell', {
	anchorX: 0.5,
	anchorY: 0.5,
	width: 450,
	height: 120,
	tint: 0xFF8800,
	alpha: 0.2
});
LK.gui.center.addChild(package2Bg);
package2Bg.y = -20;
package2Bg.alpha = 0;
var package3Bg = LK.getAsset('cell', {
	anchorX: 0.5,
	anchorY: 0.5,
	width: 450,
	height: 120,
	tint: 0x44FF44,
	alpha: 0.2
});
LK.gui.center.addChild(package3Bg);
package3Bg.y = 100;
package3Bg.alpha = 0;
var package4Bg = LK.getAsset('cell', {
	anchorX: 0.5,
	anchorY: 0.5,
	width: 450,
	height: 120,
	tint: 0xFF4444,
	alpha: 0.2
});
LK.gui.center.addChild(package4Bg);
package4Bg.y = 220;
package4Bg.alpha = 0;
// Language toggle functionality
languageBtn.interactive = true; // Always interactive
languageBtn.hitArea = new Rectangle(-100, -40, 200, 80);
languageBtn.down = function (x, y, obj) {
	// Always allow language switching regardless of game state
	currentLanguage = currentLanguage === 'tr' ? 'en' : 'tr';
	storage.language = currentLanguage;
	updateLanguageTexts();
};
// Menu button handlers
vsAIBtn.down = function (x, y, obj) {
	if (gameMode === 'menu') {
		showDifficultySelection();
	}
};
twoPlayerBtn.down = function (x, y, obj) {
	if (gameMode === 'menu') {
		startGame('twoPlayer');
	}
};
// Difficulty button handlers
easyBtn.down = function (x, y, obj) {
	if (gameMode === 'difficulty') {
		showConfirmationDialog('easy');
	}
};
normalBtn.down = function (x, y, obj) {
	if (gameMode === 'difficulty') {
		showConfirmationDialog('normal');
	}
};
hardBtn.down = function (x, y, obj) {
	if (gameMode === 'difficulty') {
		showConfirmationDialog('hard');
	}
};
backBtn.down = function (x, y, obj) {
	if (gameMode === 'confirmation') {
		hideConfirmationDialog();
	} else if (gameMode === 'cartoonMenu') {
		hideCartoonSubmenu();
	} else if (gameMode === 'superheroMenu') {
		hideSuperheroSubmenu();
	} else if (gameMode === 'footballMenu') {
		hideFootballSubmenu();
	} else if (gameMode === 'difficulty') {
		showMenu();
	} else if (gameMode === 'settings') {
		showMenu();
	} else if (gameMode === 'packages') {
		showSettingsMenu();
	} else if (gameMode !== 'menu') {
		resetGame();
		showMenu();
	}
};
exitBtn.down = function (x, y, obj) {
	if (gameMode !== 'menu') {
		resetGame();
		showMenu();
	}
};
resetStatsBtn.down = function (x, y, obj) {
	if (statsContainer.alpha > 0) {
		// Show reset confirmation dialog
		showResetConfirmationDialog();
	}
};
changeAppearanceBtn.down = function (x, y, obj) {
	if (gameMode === 'settings') {
		showPackageSelection();
	}
};
// Package selection button handlers
package1Btn.down = function (x, y, obj) {
	if (gameMode === 'packages') {
		selectPackage(0);
	}
};
package2Btn.down = function (x, y, obj) {
	if (gameMode === 'packages') {
		showCartoonSubmenu();
	}
};
package3Btn.down = function (x, y, obj) {
	if (gameMode === 'packages') {
		showSuperheroSubmenu();
	}
};
package4Btn.down = function (x, y, obj) {
	if (gameMode === 'packages') {
		showFootballSubmenu();
	}
};
tomJerryBtn.down = function (x, y, obj) {
	if (gameMode === 'cartoonMenu') {
		selectPackage(1);
		hideCartoonSubmenu();
	}
};
phineasFerbBtn.down = function (x, y, obj) {
	if (gameMode === 'cartoonMenu') {
		selectPackage(6);
		hideCartoonSubmenu();
	}
};
dipperMabelBtn.down = function (x, y, obj) {
	if (gameMode === 'cartoonMenu') {
		selectPackage(4);
		hideCartoonSubmenu();
	}
};
batmanJokerBtn.down = function (x, y, obj) {
	if (gameMode === 'superheroMenu') {
		selectPackage(3);
		hideSuperheroSubmenu();
	}
};
spidermanVenomBtn.down = function (x, y, obj) {
	if (gameMode === 'superheroMenu') {
		selectPackage(8);
		hideSuperheroSubmenu();
	}
};
ronaldoMessiBtn.down = function (x, y, obj) {
	if (gameMode === 'footballMenu') {
		selectPackage(2);
		hideFootballSubmenu();
	}
};
galatasarayFenerbahceBtn.down = function (x, y, obj) {
	if (gameMode === 'footballMenu') {
		selectPackage(10);
		hideFootballSubmenu();
	}
};
realMadridBarcaBtn.down = function (x, y, obj) {
	if (gameMode === 'footballMenu') {
		selectPackage(9);
		hideFootballSubmenu();
	}
};
settingsBtn.down = function (x, y, obj) {
	if (gameMode === 'menu') {
		showSettingsMenu();
	}
};
function showSuperheroSubmenu() {
	gameMode = 'superheroMenu';
	superheroMenuVisible = true;
	// Update texts based on current language
	superheroTitle.setText(languageTexts[currentLanguage].selectSuperhero);
	batmanJokerBtn.setText(languageTexts[currentLanguage].batmanJoker);
	spidermanVenomBtn.setText(languageTexts[currentLanguage].spidermanVenom);
	// Hide package selection elements
	packageTitle.alpha = 0;
	package1Btn.alpha = 0;
	package2Btn.alpha = 0;
	package3Btn.alpha = 0;
	package4Btn.alpha = 0;
	package1Bg.alpha = 0;
	package2Bg.alpha = 0;
	package3Bg.alpha = 0;
	package4Bg.alpha = 0;
	// Disable package interactions
	package1Btn.interactive = false;
	package2Btn.interactive = false;
	package3Btn.interactive = false;
	package4Btn.interactive = false;
	// Show superhero submenu
	superheroTitle.alpha = 1;
	batmanJokerBtn.alpha = 1;
	spidermanVenomBtn.alpha = 1;
	batmanJokerBg.alpha = 0.2;
	spidermanVenomBg.alpha = 0.2;
	// Enable superhero submenu interactions
	batmanJokerBtn.interactive = true;
	spidermanVenomBtn.interactive = true;
}
function hideSuperheroSubmenu() {
	superheroMenuVisible = false;
	gameMode = 'packages';
	// Hide superhero submenu
	superheroTitle.alpha = 0;
	batmanJokerBtn.alpha = 0;
	spidermanVenomBtn.alpha = 0;
	batmanJokerBg.alpha = 0;
	spidermanVenomBg.alpha = 0;
	// Disable superhero submenu interactions
	batmanJokerBtn.interactive = false;
	spidermanVenomBtn.interactive = false;
	// Show package selection again
	showPackageSelection();
}
function showFootballSubmenu() {
	gameMode = 'footballMenu';
	footballMenuVisible = true;
	// Update texts based on current language
	if (currentLanguage === 'tr') {
		footballTitle.setText('Futbol Seçin');
		ronaldoMessiBtn.setText('Ronaldo vs Messi');
		galatasarayFenerbahceBtn.setText('Galatasaray vs Fenerbahçe');
		realMadridBarcaBtn.setText('Real Madrid vs Barcelona');
	} else {
		footballTitle.setText('Select Football');
		ronaldoMessiBtn.setText('Ronaldo vs Messi');
		galatasarayFenerbahceBtn.setText('Galatasaray vs Fenerbahçe');
		realMadridBarcaBtn.setText('Real Madrid vs Barcelona');
	}
	// Hide package selection elements
	packageTitle.alpha = 0;
	package1Btn.alpha = 0;
	package2Btn.alpha = 0;
	package3Btn.alpha = 0;
	package4Btn.alpha = 0;
	package1Bg.alpha = 0;
	package2Bg.alpha = 0;
	package3Bg.alpha = 0;
	package4Bg.alpha = 0;
	// Disable package interactions
	package1Btn.interactive = false;
	package2Btn.interactive = false;
	package3Btn.interactive = false;
	package4Btn.interactive = false;
	// Show football submenu
	footballTitle.alpha = 1;
	ronaldoMessiBtn.alpha = 1;
	galatasarayFenerbahceBtn.alpha = 1;
	realMadridBarcaBtn.alpha = 1;
	ronaldoMessiBg.alpha = 0.2;
	galatasarayFenerbahceBg.alpha = 0.2;
	realMadridBarcaBg.alpha = 0.2;
	// Enable football submenu interactions
	ronaldoMessiBtn.interactive = true;
	galatasarayFenerbahceBtn.interactive = true;
	realMadridBarcaBtn.interactive = true;
}
function hideFootballSubmenu() {
	footballMenuVisible = false;
	gameMode = 'packages';
	// Hide football submenu
	footballTitle.alpha = 0;
	ronaldoMessiBtn.alpha = 0;
	galatasarayFenerbahceBtn.alpha = 0;
	realMadridBarcaBtn.alpha = 0;
	ronaldoMessiBg.alpha = 0;
	galatasarayFenerbahceBg.alpha = 0;
	realMadridBarcaBg.alpha = 0;
	// Disable football submenu interactions
	ronaldoMessiBtn.interactive = false;
	galatasarayFenerbahceBtn.interactive = false;
	realMadridBarcaBtn.interactive = false;
	// Show package selection again
	showPackageSelection();
}
function showCartoonSubmenu() {
	gameMode = 'cartoonMenu';
	cartoonMenuVisible = true;
	// Update texts based on current language
	if (currentLanguage === 'tr') {
		cartoonTitle.setText('Çizgi Film Seçin');
		tomJerryBtn.setText('Tom ve Jerry');
		phineasFerbBtn.setText('Phineas ve Ferb');
		dipperMabelBtn.setText('Dipper ve Mabel');
	} else {
		cartoonTitle.setText('Select Cartoon');
		tomJerryBtn.setText('Tom vs Jerry');
		phineasFerbBtn.setText('Phineas vs Ferb');
		dipperMabelBtn.setText('Dipper vs Mabel');
	}
	// Hide package selection elements
	packageTitle.alpha = 0;
	package1Btn.alpha = 0;
	package2Btn.alpha = 0;
	package3Btn.alpha = 0;
	package4Btn.alpha = 0;
	package1Bg.alpha = 0;
	package2Bg.alpha = 0;
	package3Bg.alpha = 0;
	package4Bg.alpha = 0;
	// Disable package interactions
	package1Btn.interactive = false;
	package2Btn.interactive = false;
	package3Btn.interactive = false;
	package4Btn.interactive = false;
	// Show cartoon submenu
	cartoonTitle.alpha = 1;
	tomJerryBtn.alpha = 1;
	phineasFerbBtn.alpha = 1;
	dipperMabelBtn.alpha = 1;
	tomJerryBg.alpha = 0.2;
	phineasFerbBg.alpha = 0.2;
	dipperMabelBg.alpha = 0.2;
	// Enable cartoon submenu interactions
	tomJerryBtn.interactive = true;
	phineasFerbBtn.interactive = true;
	dipperMabelBtn.interactive = true;
}
function hideCartoonSubmenu() {
	cartoonMenuVisible = false;
	gameMode = 'packages';
	// Hide cartoon submenu
	cartoonTitle.alpha = 0;
	tomJerryBtn.alpha = 0;
	phineasFerbBtn.alpha = 0;
	dipperMabelBtn.alpha = 0;
	tomJerryBg.alpha = 0;
	phineasFerbBg.alpha = 0;
	dipperMabelBg.alpha = 0;
	// Disable cartoon submenu interactions
	tomJerryBtn.interactive = false;
	phineasFerbBtn.interactive = false;
	dipperMabelBtn.interactive = false;
	// Show package selection again
	showPackageSelection();
}
function showPackageSelection() {
	gameMode = 'packages';
	// Hide settings menu
	changeAppearanceBtn.alpha = 0;
	changeAppearanceBtn.interactive = false;
	// Hide current style text
	currentStyleText.alpha = 0;
	// Show package selection elements
	packageTitle.alpha = 1;
	package1Btn.alpha = 1;
	package2Btn.alpha = 1;
	package3Btn.alpha = 1;
	package4Btn.alpha = 1;
	package1Bg.alpha = 0.2;
	package2Bg.alpha = 0.2;
	package3Bg.alpha = 0.2;
	package4Bg.alpha = 0.2;
	// Enable package button interactions
	package1Btn.interactive = true;
	package2Btn.interactive = true;
	package3Btn.interactive = true;
	package4Btn.interactive = true;
	// Highlight current package
	highlightCurrentPackage();
}
function selectPackage(packageIndex) {
	currentAppearanceStyle = packageIndex;
	storage.appearanceStyle = currentAppearanceStyle;
	// If there's an active game, reset it to apply new styles
	if (gameBoard.alpha > 0) {
		resetGame();
	}
	// Update package highlight
	highlightCurrentPackage();
	// Go back to settings menu after selection
	showSettingsMenu();
}
function highlightCurrentPackage() {
	// Reset all backgrounds
	package1Bg.alpha = 0.2;
	package2Bg.alpha = 0.2;
	package3Bg.alpha = 0.2;
	package4Bg.alpha = 0.2;
	// Highlight current selection
	if (currentAppearanceStyle === 0) {
		package1Bg.alpha = 0.6;
	} else if (currentAppearanceStyle === 1) {
		package2Bg.alpha = 0.6; // Tom vs Jerry is in cartoon submenu
	} else if (currentAppearanceStyle === 2 || currentAppearanceStyle === 9 || currentAppearanceStyle === 10) {
		package4Bg.alpha = 0.6; // Football package (Ronaldo vs Messi, Real Madrid vs Barcelona, Galatasaray vs Fenerbahçe)
	} else if (currentAppearanceStyle === 3) {
		package3Bg.alpha = 0.6; // Batman vs Joker is in superhero submenu
	} else if (currentAppearanceStyle === 4) {
		package2Bg.alpha = 0.6; // Dipper vs Mabel is in cartoon submenu
	} else if (currentAppearanceStyle === 6) {
		package2Bg.alpha = 0.6; // Phineas vs Ferb is in cartoon submenu
	} else if (currentAppearanceStyle === 8) {
		package3Bg.alpha = 0.6; // Spider-Man vs Venom is in superhero submenu
	}
}
function updateLanguageTexts() {
	blueTurnText.setText(languageTexts[currentLanguage].blueTurn);
	redTurnText.setText(languageTexts[currentLanguage].redTurn);
	playAgainBtn.setText(languageTexts[currentLanguage].playAgain);
	languageBtn.setText(languageTexts[currentLanguage === 'tr' ? 'en' : 'tr'].language);
	menuTitle.setText(languageTexts[currentLanguage].selectMode);
	vsAIBtn.setText(languageTexts[currentLanguage].vsAI);
	twoPlayerBtn.setText(languageTexts[currentLanguage].twoPlayer);
	backBtn.setText(languageTexts[currentLanguage].back);
	exitBtn.setText(languageTexts[currentLanguage].exit);
	difficultyTitle.setText(languageTexts[currentLanguage].selectDifficulty);
	easyBtn.setText(languageTexts[currentLanguage].easy);
	normalBtn.setText(languageTexts[currentLanguage].normal);
	hardBtn.setText(languageTexts[currentLanguage].hard);
	yesBtn.setText(languageTexts[currentLanguage].yes);
	noBtn.setText(languageTexts[currentLanguage].no);
	settingsBtn.setText(languageTexts[currentLanguage].settings);
	changeAppearanceBtn.setText(languageTexts[currentLanguage].changeAppearance);
	packageTitle.setText(languageTexts[currentLanguage].selectPackage);
	package1Btn.setText(languageTexts[currentLanguage].package1);
	package2Btn.setText(languageTexts[currentLanguage].package2);
	package3Btn.setText(languageTexts[currentLanguage].package3);
	package4Btn.setText(languageTexts[currentLanguage].package4);
	// package5Btn and package6Btn don't exist, removing references
	// Update winner/draw text if game is over
	if (gameOver && statusText.alpha > 0) {
		var currentText = statusText.text;
		// Check for all possible winner texts based on styles
		var isBlueWin = false;
		var isRedWin = false;
		var isDraw = false;
		var isXWin = false;
		var isOWin = false;
		// Check classic wins
		if (currentText === languageTexts.tr.blueWin || currentText === languageTexts.en.blueWin) isBlueWin = true;
		if (currentText === languageTexts.tr.redWin || currentText === languageTexts.en.redWin) isRedWin = true;
		if (currentText === languageTexts.tr.draw || currentText === languageTexts.en.draw) isDraw = true;
		// Check Tom ve Jerry wins
		if (currentText === 'TOM KAZANDI!' || currentText === 'TOM WON!') isXWin = true;
		if (currentText === 'JERRY KAZANDI!' || currentText === 'JERRY WON!') isOWin = true;
		// Check Batman vs Joker wins
		if (currentText === 'BATMAN KAZANDI!' || currentText === 'BATMAN WON!') isXWin = true;
		if (currentText === 'JOKER KAZANDI!' || currentText === 'JOKER WON!') isOWin = true;
		// Check Ronaldo vs. Messi wins
		if (currentText === 'RONALDO KAZANDI!' || currentText === 'RONALDO WON!') isXWin = true;
		if (currentText === 'MESSI KAZANDI!' || currentText === 'MESSI WON!') isOWin = true;
		// Check Spiderman vs Venom wins
		if (currentText === languageTexts.tr.spidermanWin || currentText === languageTexts.en.spidermanWin) isXWin = true;
		if (currentText === languageTexts.tr.venomWin || currentText === languageTexts.en.venomWin) isOWin = true;
		// Check Galatasaray vs Fenerbahçe wins
		if (currentText === 'GALATASARAY KAZANDI!' || currentText === 'GALATASARAY WON!') isXWin = true;
		if (currentText === 'FENERBAHÇE KAZANDI!' || currentText === 'FENERBAHÇE WON!') isOWin = true;
		// Check Phineas vs Ferb wins
		if (currentText === 'PHINEAS KAZANDI!' || currentText === 'PHINEAS WON!') isXWin = true;
		if (currentText === 'FERB KAZANDI!' || currentText === 'FERB WON!') isOWin = true;
		// Check Deeper vs. Mabel wins
		if (currentText === 'DEEPER KAZANDI!' || currentText === 'DEEPER WON!') isXWin = true;
		if (currentText === 'MABEL KAZANDI!' || currentText === 'MABEL WON!') isOWin = true;
		// Update text based on current style and language
		if (isBlueWin || isXWin) {
			if (currentAppearanceStyle === 0) {
				statusText.setText(languageTexts[currentLanguage].blueWin);
			} else if (currentAppearanceStyle === 1) {
				statusText.setText(currentLanguage === 'tr' ? 'TOM KAZANDI!' : 'TOM WON!');
			} else if (currentAppearanceStyle === 2) {
				statusText.setText(currentLanguage === 'tr' ? 'RONALDO KAZANDI!' : 'RONALDO WON!');
			} else if (currentAppearanceStyle === 3) {
				statusText.setText(currentLanguage === 'tr' ? 'RONALDO KAZANDI!' : 'RONALDO WON!');
			} else if (currentAppearanceStyle === 4) {
				statusText.setText(currentLanguage === 'tr' ? 'DIPPER KAZANDI!' : 'DIPPER WON!');
			} else if (currentAppearanceStyle === 5) {
				statusText.setText(languageTexts[currentLanguage].batmanWin);
			} else if (currentAppearanceStyle === 6) {
				statusText.setText(currentLanguage === 'tr' ? 'PHINEAS KAZANDI!' : 'PHINEAS WON!');
			} else if (currentAppearanceStyle === 8) {
				statusText.setText(languageTexts[currentLanguage].spidermanWin);
			} else if (currentAppearanceStyle === 9) {
				statusText.setText(currentLanguage === 'tr' ? 'REAL MADRID KAZANDI!' : 'REAL MADRID WON!');
			} else if (currentAppearanceStyle === 10) {
				statusText.setText(currentLanguage === 'tr' ? 'GALATASARAY KAZANDI!' : 'GALATASARAY WON!');
			}
		} else if (isRedWin || isOWin) {
			if (currentAppearanceStyle === 0) {
				statusText.setText(languageTexts[currentLanguage].redWin);
			} else if (currentAppearanceStyle === 1) {
				statusText.setText(currentLanguage === 'tr' ? 'JERRY KAZANDI!' : 'JERRY WON!');
			} else if (currentAppearanceStyle === 2) {
				statusText.setText(currentLanguage === 'tr' ? 'MESSI KAZANDI!' : 'MESSI WON!');
			} else if (currentAppearanceStyle === 3) {
				statusText.setText(languageTexts[currentLanguage].batmanWin);
			} else if (currentAppearanceStyle === 4) {
				statusText.setText(currentLanguage === 'tr' ? 'MABEL KAZANDI!' : 'MABEL WON!');
			} else if (currentAppearanceStyle === 5) {
				statusText.setText(languageTexts[currentLanguage].jokerWin);
			} else if (currentAppearanceStyle === 6) {
				statusText.setText(currentLanguage === 'tr' ? 'FERB KAZANDI!' : 'FERB WON!');
			} else if (currentAppearanceStyle === 8) {
				statusText.setText(languageTexts[currentLanguage].venomWin);
			} else if (currentAppearanceStyle === 9) {
				statusText.setText(currentLanguage === 'tr' ? 'BARÇA KAZANDI!' : 'BARÇA WON!');
			} else if (currentAppearanceStyle === 10) {
				statusText.setText(currentLanguage === 'tr' ? 'FENERBAHÇE KAZANDI!' : 'FENERBAHÇE WON!');
			}
		} else if (isDraw) {
			statusText.setText(languageTexts[currentLanguage].draw);
		}
	}
	// Update statistics display
	blueStatsText.setText(languageTexts[currentLanguage].blueWins + gameStats.blueWins);
	redStatsText.setText(languageTexts[currentLanguage].redWins + gameStats.redWins);
	drawStatsText.setText(languageTexts[currentLanguage].draws + gameStats.draws);
	resetStatsBtn.setText(languageTexts[currentLanguage].resetStats);
	// Update current style text if visible
	if (currentStyleText.alpha > 0) {
		var currentStyleName = '';
		if (currentAppearanceStyle === 0) {
			currentStyleName = languageTexts[currentLanguage].package1;
		} else if (currentAppearanceStyle === 1) {
			currentStyleName = currentLanguage === 'tr' ? 'Çizgi Film - Tom ve Jerry' : 'Cartoon - Tom vs Jerry';
		} else if (currentAppearanceStyle === 2) {
			currentStyleName = currentLanguage === 'tr' ? 'Futbol - Ronaldo vs Messi' : 'Football - Ronaldo vs Messi';
		} else if (currentAppearanceStyle === 3) {
			currentStyleName = currentLanguage === 'tr' ? 'Süper Kahramanlar - Batman vs Joker' : 'Superheroes - Batman vs Joker';
		} else if (currentAppearanceStyle === 4) {
			currentStyleName = currentLanguage === 'tr' ? 'Çizgi Film - Dipper ve Mabel' : 'Cartoon - Dipper vs Mabel';
		} else if (currentAppearanceStyle === 5) {
			currentStyleName = currentLanguage === 'tr' ? 'Süper Kahramanlar - Batman vs Joker' : 'Superheroes - Batman vs Joker';
		} else if (currentAppearanceStyle === 6) {
			currentStyleName = currentLanguage === 'tr' ? 'Çizgi Film - Phineas vs Ferb' : 'Cartoon - Phineas vs Ferb';
		} else if (currentAppearanceStyle === 7 || currentAppearanceStyle === 11) {
			currentStyleName = 'Real Madrid ve Barça';
		} else if (currentAppearanceStyle === 8) {
			currentStyleName = currentLanguage === 'tr' ? 'Süper Kahramanlar - Spiderman vs Venom' : 'Superheroes - Spiderman vs Venom';
		} else if (currentAppearanceStyle === 9) {
			currentStyleName = currentLanguage === 'tr' ? 'Futbol - Real Madrid vs Barcelona' : 'Football - Real Madrid vs Barcelona';
		} else if (currentAppearanceStyle === 10) {
			currentStyleName = currentLanguage === 'tr' ? 'Futbol - Galatasaray vs Fenerbahçe' : 'Football - Galatasaray vs Fenerbahçe';
		}
		currentStyleText.setText(languageTexts[currentLanguage].selected + currentStyleName);
	}
	// Reposition statistics horizontally to display side by side with better spacing
	blueStatsText.y = 0;
	blueStatsText.x = -500;
	redStatsText.y = 0;
	redStatsText.x = 0;
	drawStatsText.y = 0;
	drawStatsText.x = 500;
}
// Start in menu mode
showMenu();
function updateTurnDisplay() {
	if (gameMode === 'menu' || gameOver) {
		blueTurnText.alpha = 0;
		redTurnText.alpha = 0;
	} else if (currentPlayer === 1) {
		blueTurnText.alpha = 1;
		redTurnText.alpha = 0;
		// Stop any AI thinking animation
		tween.stop(redTurnText);
	} else {
		blueTurnText.alpha = 0;
		redTurnText.alpha = 1;
		// Add thinking animation for AI in AI mode
		if (isAIMode && aiProcessing) {
			tween(redTurnText, {
				alpha: 0.3
			}, {
				duration: 800,
				easing: tween.easeInOut,
				repeat: -1,
				yoyo: true
			});
		} else {
			// Stop thinking animation
			tween.stop(redTurnText);
			redTurnText.alpha = 1;
		}
	}
}
function showMenu() {
	gameMode = 'menu';
	gameBoard.alpha = 0;
	settingsBtn.alpha = 1;
	settingsBtn.interactive = true;
	menuTitle.alpha = 1;
	vsAIBtn.alpha = 1;
	twoPlayerBtn.alpha = 1;
	// Enable main menu interactions
	vsAIBtn.interactive = true;
	twoPlayerBtn.interactive = true;
	blueTurnText.alpha = 0;
	redTurnText.alpha = 0;
	statusText.alpha = 0;
	playAgainBtn.alpha = 0;
	playAgainBtn.interactive = false;
	playAgainBg.alpha = 0;
	backBtn.alpha = 0;
	backBtn.interactive = false;
	exitBtn.alpha = 0;
	exitBtn.interactive = false;
	// Hide difficulty selection
	difficultyTitle.alpha = 0;
	easyBtn.alpha = 0;
	normalBtn.alpha = 0;
	hardBtn.alpha = 0;
	// Disable difficulty button interactions
	easyBtn.interactive = false;
	normalBtn.interactive = false;
	hardBtn.interactive = false;
	// Hide blocks
	// Stop any active animations on difficulty blocks
	tween.stop(easyBlock);
	tween.stop(normalBlock);
	tween.stop(hardBlock);
	// Reset block properties to prevent visual artifacts
	easyBlock.alpha = 0;
	normalBlock.alpha = 0;
	hardBlock.alpha = 0;
	easyBlock.scaleX = 1;
	easyBlock.scaleY = 1;
	normalBlock.scaleX = 1;
	normalBlock.scaleY = 1;
	hardBlock.scaleX = 1;
	hardBlock.scaleY = 1;
	// Hide confirmation dialog
	confirmationBg.alpha = 0;
	confirmationText.alpha = 0;
	yesBtn.alpha = 0;
	noBtn.alpha = 0;
	// Disable confirmation dialog interactions
	yesBtn.interactive = false;
	noBtn.interactive = false;
	// Hide statistics in menu
	statsContainer.alpha = 0;
	// Hide appearance button
	changeAppearanceBtn.alpha = 0;
	changeAppearanceBtn.interactive = false;
	// Hide current style text
	currentStyleText.alpha = 0;
	// Hide package selection elements
	packageTitle.alpha = 0;
	package1Btn.alpha = 0;
	package2Btn.alpha = 0;
	package3Btn.alpha = 0;
	package4Btn.alpha = 0;
	package1Bg.alpha = 0;
	package2Bg.alpha = 0;
	package3Bg.alpha = 0;
	package4Bg.alpha = 0;
	// Disable package button interactions
	package1Btn.interactive = false;
	package2Btn.interactive = false;
	package3Btn.interactive = false;
	package4Btn.interactive = false;
	// Hide cartoon submenu elements
	cartoonTitle.alpha = 0;
	tomJerryBtn.alpha = 0;
	phineasFerbBtn.alpha = 0;
	dipperMabelBtn.alpha = 0;
	tomJerryBg.alpha = 0;
	phineasFerbBg.alpha = 0;
	dipperMabelBg.alpha = 0;
	tomJerryBtn.interactive = false;
	phineasFerbBtn.interactive = false;
	dipperMabelBtn.interactive = false;
	cartoonMenuVisible = false;
	// Hide superhero submenu elements
	superheroTitle.alpha = 0;
	batmanJokerBtn.alpha = 0;
	spidermanVenomBtn.alpha = 0;
	batmanJokerBg.alpha = 0;
	spidermanVenomBg.alpha = 0;
	batmanJokerBtn.interactive = false;
	spidermanVenomBtn.interactive = false;
	superheroMenuVisible = false;
	// Hide football submenu elements
	footballTitle.alpha = 0;
	ronaldoMessiBtn.alpha = 0;
	galatasarayFenerbahceBtn.alpha = 0;
	realMadridBarcaBtn.alpha = 0;
	ronaldoMessiBg.alpha = 0;
	galatasarayFenerbahceBg.alpha = 0;
	realMadridBarcaBg.alpha = 0;
	ronaldoMessiBtn.interactive = false;
	galatasarayFenerbahceBtn.interactive = false;
	realMadridBarcaBtn.interactive = false;
	footballMenuVisible = false;
}
function showSettingsMenu() {
	gameMode = 'settings';
	// Hide main menu
	settingsBtn.alpha = 0;
	settingsBtn.interactive = false;
	menuTitle.alpha = 0;
	vsAIBtn.alpha = 0;
	twoPlayerBtn.alpha = 0;
	vsAIBtn.interactive = false;
	twoPlayerBtn.interactive = false;
	// Show back button and language button more prominently
	backBtn.alpha = 1;
	backBtn.interactive = true;
	// Show appearance change button
	changeAppearanceBtn.alpha = 1;
	changeAppearanceBtn.interactive = true;
	// Show current appearance style
	var currentStyleName = '';
	if (currentAppearanceStyle === 0) {
		currentStyleName = languageTexts[currentLanguage].package1;
	} else if (currentAppearanceStyle === 1) {
		currentStyleName = currentLanguage === 'tr' ? 'Çizgi Film - Tom ve Jerry' : 'Cartoon - Tom vs Jerry';
	} else if (currentAppearanceStyle === 2) {
		currentStyleName = currentLanguage === 'tr' ? 'Futbol - Ronaldo vs Messi' : 'Football - Ronaldo vs Messi';
	} else if (currentAppearanceStyle === 3) {
		currentStyleName = currentLanguage === 'tr' ? 'Süper Kahramanlar - Batman vs Joker' : 'Superheroes - Batman vs Joker';
	} else if (currentAppearanceStyle === 4) {
		currentStyleName = currentLanguage === 'tr' ? 'Çizgi Film - Dipper ve Mabel' : 'Cartoon - Dipper vs Mabel';
	} else if (currentAppearanceStyle === 5) {
		currentStyleName = currentLanguage === 'tr' ? 'Süper Kahramanlar - Batman vs Joker' : 'Superheroes - Batman vs Joker';
	} else if (currentAppearanceStyle === 6) {
		currentStyleName = currentLanguage === 'tr' ? 'Çizgi Film - Phineas vs Ferb' : 'Cartoon - Phineas vs Ferb';
	} else if (currentAppearanceStyle === 7 || currentAppearanceStyle === 11) {
		currentStyleName = 'Real Madrid ve Barça';
	} else if (currentAppearanceStyle === 8) {
		currentStyleName = currentLanguage === 'tr' ? 'Süper Kahramanlar - Spiderman vs Venom' : 'Superheroes - Spiderman vs Venom';
	} else if (currentAppearanceStyle === 9) {
		currentStyleName = currentLanguage === 'tr' ? 'Futbol - Real Madrid vs Barcelona' : 'Football - Real Madrid vs Barcelona';
	} else if (currentAppearanceStyle === 10) {
		currentStyleName = currentLanguage === 'tr' ? 'Futbol - Galatasaray vs Fenerbahçe' : 'Football - Galatasaray vs Fenerbahçe';
	}
	currentStyleText.setText(languageTexts[currentLanguage].selected + currentStyleName);
	currentStyleText.alpha = 1;
	// Hide package selection elements
	packageTitle.alpha = 0;
	package1Btn.alpha = 0;
	package2Btn.alpha = 0;
	package3Btn.alpha = 0;
	package4Btn.alpha = 0;
	package1Bg.alpha = 0;
	package2Bg.alpha = 0;
	package3Bg.alpha = 0;
	package4Bg.alpha = 0;
	// Disable package button interactions
	package1Btn.interactive = false;
	package2Btn.interactive = false;
	package3Btn.interactive = false;
	package4Btn.interactive = false;
	// Hide cartoon submenu elements
	cartoonTitle.alpha = 0;
	tomJerryBtn.alpha = 0;
	phineasFerbBtn.alpha = 0;
	dipperMabelBtn.alpha = 0;
	tomJerryBg.alpha = 0;
	phineasFerbBg.alpha = 0;
	dipperMabelBg.alpha = 0;
	tomJerryBtn.interactive = false;
	phineasFerbBtn.interactive = false;
	dipperMabelBtn.interactive = false;
	cartoonMenuVisible = false;
}
function showDifficultySelection() {
	gameMode = 'difficulty';
	// Hide main menu
	menuTitle.alpha = 0;
	vsAIBtn.alpha = 0;
	twoPlayerBtn.alpha = 0;
	// Disable main menu interactions
	vsAIBtn.interactive = false;
	twoPlayerBtn.interactive = false;
	// Hide settings button in difficulty selection
	settingsBtn.alpha = 0;
	settingsBtn.interactive = false;
	// Show difficulty selection
	difficultyTitle.alpha = 1;
	easyBtn.alpha = 1;
	normalBtn.alpha = 1;
	hardBtn.alpha = 1;
	backBtn.alpha = 1;
	// Enable difficulty button interactions
	easyBtn.interactive = true;
	normalBtn.interactive = true;
	hardBtn.interactive = true;
	backBtn.interactive = true;
	// Show and animate blocks
	easyBlock.alpha = 0.3;
	normalBlock.alpha = 0.3;
	hardBlock.alpha = 0.3;
	animateDifficultyBlocks();
}
function startGame(mode) {
	gameMode = mode;
	isAIMode = mode === 'ai';
	gameBoard.alpha = 1;
	settingsBtn.alpha = 0;
	settingsBtn.interactive = false;
	menuTitle.alpha = 0;
	vsAIBtn.alpha = 0;
	twoPlayerBtn.alpha = 0;
	// Disable menu interactions
	vsAIBtn.interactive = false;
	twoPlayerBtn.interactive = false;
	// Hide difficulty selection
	difficultyTitle.alpha = 0;
	easyBtn.alpha = 0;
	normalBtn.alpha = 0;
	hardBtn.alpha = 0;
	// Disable difficulty button interactions
	easyBtn.interactive = false;
	normalBtn.interactive = false;
	hardBtn.interactive = false;
	// Hide blocks
	// Stop any active animations on difficulty blocks first
	tween.stop(easyBlock);
	tween.stop(normalBlock);
	tween.stop(hardBlock);
	// Reset block properties to prevent visual artifacts
	easyBlock.alpha = 0;
	normalBlock.alpha = 0;
	hardBlock.alpha = 0;
	easyBlock.scaleX = 1;
	easyBlock.scaleY = 1;
	normalBlock.scaleX = 1;
	normalBlock.scaleY = 1;
	hardBlock.scaleX = 1;
	hardBlock.scaleY = 1;
	// Hide confirmation dialog
	confirmationBg.alpha = 0;
	confirmationText.alpha = 0;
	yesBtn.alpha = 0;
	noBtn.alpha = 0;
	// Disable confirmation dialog interactions
	yesBtn.interactive = false;
	noBtn.interactive = false;
	// Hide back button in all game modes once game starts
	backBtn.alpha = 0;
	backBtn.interactive = false;
	exitBtn.alpha = 1;
	// Enable exit button interaction
	exitBtn.interactive = true;
	// In AI mode, player (1) always starts first
	if (isAIMode) {
		currentPlayer = 1;
	} else {
		// In two player mode, X (player 1) always starts
		currentPlayer = 1;
	}
	updateTurnDisplay();
	// Hide settings and package elements
	changeAppearanceBtn.alpha = 0;
	changeAppearanceBtn.interactive = false;
	// Hide current style text
	currentStyleText.alpha = 0;
	packageTitle.alpha = 0;
	package1Btn.alpha = 0;
	package2Btn.alpha = 0;
	package3Btn.alpha = 0;
	package4Btn.alpha = 0;
	package1Bg.alpha = 0;
	package2Bg.alpha = 0;
	package3Bg.alpha = 0;
	package4Bg.alpha = 0;
	// Disable package button interactions
	package1Btn.interactive = false;
	package2Btn.interactive = false;
	package3Btn.interactive = false;
	package4Btn.interactive = false;
	// Hide cartoon submenu elements
	cartoonTitle.alpha = 0;
	tomJerryBtn.alpha = 0;
	phineasFerbBtn.alpha = 0;
	dipperMabelBtn.alpha = 0;
	tomJerryBg.alpha = 0;
	phineasFerbBg.alpha = 0;
	dipperMabelBg.alpha = 0;
	tomJerryBtn.interactive = false;
	phineasFerbBtn.interactive = false;
	dipperMabelBtn.interactive = false;
	cartoonMenuVisible = false;
	// Show statistics during gameplay
	statsContainer.alpha = 1;
}
function checkWin() {
	var winner = 0;
	var winPositions = [];
	// Check rows
	for (var row = 0; row < 3; row++) {
		if (grid[row][0].value !== 0 && grid[row][0].value === grid[row][1].value && grid[row][1].value === grid[row][2].value) {
			winner = grid[row][0].value;
			winPositions = [{
				row: row,
				col: 0
			}, {
				row: row,
				col: 1
			}, {
				row: row,
				col: 2
			}];
			break;
		}
	}
	// Check columns
	if (winner === 0) {
		for (var col = 0; col < 3; col++) {
			if (grid[0][col].value !== 0 && grid[0][col].value === grid[1][col].value && grid[1][col].value === grid[2][col].value) {
				winner = grid[0][col].value;
				winPositions = [{
					row: 0,
					col: col
				}, {
					row: 1,
					col: col
				}, {
					row: 2,
					col: col
				}];
				break;
			}
		}
	}
	// Check diagonals
	if (winner === 0) {
		if (grid[0][0].value !== 0 && grid[0][0].value === grid[1][1].value && grid[1][1].value === grid[2][2].value) {
			winner = grid[0][0].value;
			winPositions = [{
				row: 0,
				col: 0
			}, {
				row: 1,
				col: 1
			}, {
				row: 2,
				col: 2
			}];
		} else if (grid[0][2].value !== 0 && grid[0][2].value === grid[1][1].value && grid[1][1].value === grid[2][0].value) {
			winner = grid[0][2].value;
			winPositions = [{
				row: 0,
				col: 2
			}, {
				row: 1,
				col: 1
			}, {
				row: 2,
				col: 0
			}];
		}
	}
	if (winner !== 0) {
		gameOver = true;
		showWinner(winner, winPositions);
		return;
	}
	// Check for draw
	var isDraw = true;
	for (var r = 0; r < 3; r++) {
		for (var c = 0; c < 3; c++) {
			if (grid[r][c].value === 0) {
				isDraw = false;
				break;
			}
		}
		if (!isDraw) break;
	}
	if (isDraw) {
		gameOver = true;
		showDraw();
	}
}
function showWinner(winner, positions) {
	LK.getSound('win').play();
	// Update statistics
	if (winner === 1) {
		gameStats.blueWins++;
		storage.blueWins = gameStats.blueWins;
	} else {
		gameStats.redWins++;
		storage.redWins = gameStats.redWins;
	}
	// Update statistics display
	blueStatsText.setText(languageTexts[currentLanguage].blueWins + gameStats.blueWins);
	redStatsText.setText(languageTexts[currentLanguage].redWins + gameStats.redWins);
	// Custom winner messages based on appearance style
	var winnerText = '';
	if (currentAppearanceStyle === 0) {
		// Klasik X-O
		winnerText = winner === 1 ? languageTexts[currentLanguage].blueWin : languageTexts[currentLanguage].redWin;
	} else if (currentAppearanceStyle === 1) {
		// Tom ve Jerry
		if (currentLanguage === 'tr') {
			winnerText = winner === 1 ? 'TOM KAZANDI!' : 'JERRY KAZANDI!';
		} else {
			winnerText = winner === 1 ? 'TOM WON!' : 'JERRY WON!';
		}
	} else if (currentAppearanceStyle === 2) {
		// Ronaldo vs. Messi
		if (currentLanguage === 'tr') {
			winnerText = winner === 1 ? 'RONALDO KAZANDI!' : 'MESSI KAZANDI!';
		} else {
			winnerText = winner === 1 ? 'RONALDO WON!' : 'MESSI WON!';
		}
	} else if (currentAppearanceStyle === 3) {
		// Batman vs Joker
		winnerText = winner === 1 ? languageTexts[currentLanguage].batmanWin : languageTexts[currentLanguage].jokerWin;
	} else if (currentAppearanceStyle === 4) {
		// Dipper vs. Mabel
		if (currentLanguage === 'tr') {
			winnerText = winner === 1 ? 'DIPPER KAZANDI!' : 'MABEL KAZANDI!';
		} else {
			winnerText = winner === 1 ? 'DIPPER WON!' : 'MABEL WON!';
		}
	} else if (currentAppearanceStyle === 5) {
		// Batman vs Joker
		winnerText = winner === 1 ? languageTexts[currentLanguage].batmanWin : languageTexts[currentLanguage].jokerWin;
	} else if (currentAppearanceStyle === 6) {
		// Phineas vs Ferb
		if (currentLanguage === 'tr') {
			winnerText = winner === 1 ? 'PHINEAS KAZANDI!' : 'FERB KAZANDI!';
		} else {
			winnerText = winner === 1 ? 'PHINEAS WON!' : 'FERB WON!';
		}
	} else if (currentAppearanceStyle === 7) {
		// Style 7 is now undefined - use default
		winnerText = winner === 1 ? languageTexts[currentLanguage].blueWin : languageTexts[currentLanguage].redWin;
	} else if (currentAppearanceStyle === 8) {
		// Spider-Man vs Venom
		winnerText = winner === 1 ? languageTexts[currentLanguage].spidermanWin : languageTexts[currentLanguage].venomWin;
	} else if (currentAppearanceStyle === 9) {
		// Real Madrid ve Barça
		if (currentLanguage === 'tr') {
			winnerText = winner === 1 ? 'REAL MADRID KAZANDI!' : 'BARÇA KAZANDI!';
		} else {
			winnerText = winner === 1 ? 'REAL MADRID WON!' : 'BARÇA WON!';
		}
	} else if (currentAppearanceStyle === 10) {
		// Galatasaray vs Fenerbahçe
		if (currentLanguage === 'tr') {
			winnerText = winner === 1 ? 'GALATASARAY KAZANDI!' : 'FENERBAHÇE KAZANDI!';
		} else {
			winnerText = winner === 1 ? 'GALATASARAY WON!' : 'FENERBAHÇE WON!';
		}
	}
	var winnerColor = 0x000000; // Black color
	statusText.setText(winnerText);
	statusText.fill = 0xFFFFFF; // White color
	// Create grey background for winner text
	winnerTextBg = LK.getAsset('cell', {
		anchorX: 0.5,
		anchorY: 0.5,
		width: statusText.width + 100,
		height: statusText.height + 40,
		tint: 0x808080,
		alpha: 0.8
	});
	LK.gui.center.addChild(winnerTextBg);
	winnerTextBg.y = 400; // Same position as statusText
	// Ensure background is behind text
	if (LK.gui.center.getChildIndex(statusText) > 0) {
		LK.gui.center.setChildIndex(winnerTextBg, LK.gui.center.getChildIndex(statusText) - 1);
	}
	statusText.alpha = 1;
	blueTurnText.alpha = 0;
	redTurnText.alpha = 0;
	// Show win line
	winLine = gameBoard.addChild(new WinLine());
	var startPos = grid[positions[0].row][positions[0].col];
	var endPos = grid[positions[2].row][positions[2].col];
	var lineColor = winner === 1 ? 0x00aaff : 0xff4444;
	winLine.showWinLine(startPos.x, startPos.y, endPos.x, endPos.y, lineColor);
	// Show play again button with background
	playAgainBtn.interactive = true;
	animateObject(playAgainBg, {
		alpha: 0.9
	}, {
		duration: 500
	});
	animateObject(playAgainBtn, {
		alpha: 1
	}, {
		duration: 500
	});
	// Add pulsing animation to make it more prominent
	animateObject(playAgainBg, {
		scaleX: 1.1,
		scaleY: 1.1
	}, {
		duration: 800,
		easing: 'easeInOut',
		repeat: -1,
		yoyo: true
	});
}
function showDraw() {
	// Update statistics
	gameStats.draws++;
	storage.draws = gameStats.draws;
	// Update statistics display
	drawStatsText.setText(languageTexts[currentLanguage].draws + gameStats.draws);
	statusText.setText(languageTexts[currentLanguage].draw);
	statusText.fill = 0xFFFFFF; // White color
	// Create grey background for draw text
	drawTextBg = LK.getAsset('cell', {
		anchorX: 0.5,
		anchorY: 0.5,
		width: statusText.width + 100,
		height: statusText.height + 40,
		tint: 0x808080,
		alpha: 0.8
	});
	LK.gui.center.addChild(drawTextBg);
	drawTextBg.y = 400; // Same position as statusText
	// Ensure background is behind text
	if (LK.gui.center.getChildIndex(statusText) > 0) {
		LK.gui.center.setChildIndex(drawTextBg, LK.gui.center.getChildIndex(statusText) - 1);
	}
	statusText.alpha = 1;
	blueTurnText.alpha = 0;
	redTurnText.alpha = 0;
	// Show play again button with background
	playAgainBtn.interactive = true;
	tween(playAgainBg, {
		alpha: 0.9
	}, {
		duration: 500
	});
	tween(playAgainBtn, {
		alpha: 1
	}, {
		duration: 500
	});
	// Add pulsing animation to make it more prominent
	tween(playAgainBg, {
		scaleX: 1.1,
		scaleY: 1.1
	}, {
		duration: 800,
		easing: tween.easeInOut,
		repeat: -1,
		yoyo: true
	});
}
function makeAIMove() {
	if (gameOver || currentPlayer !== 2) return;
	// Extra validation for game state
	if (!isAIMode || gameMode !== 'ai') return;
	// Don't proceed if AI is already processing
	if (aiProcessing) return;
	// Set AI processing flag to prevent consecutive moves
	aiProcessing = true;
	// Force turn display update to show AI is thinking
	updateTurnDisplay();
	// Add safety timeout to clear flag in case of errors
	var safetyTimeout = LK.setTimeout(function () {
		if (aiProcessing) {
			console.log("AI safety timeout triggered - clearing processing flag");
			aiProcessing = false; // Safety clear after 5 seconds
		}
	}, 5000);
	// Variable thinking time based on difficulty
	var minTime, maxTime;
	if (aiDifficulty === 'easy') {
		minTime = 300;
		maxTime = 800;
	} else if (aiDifficulty === 'normal') {
		minTime = 500;
		maxTime = 1200;
	} else {
		// hard
		minTime = 800;
		maxTime = 2000;
	}
	var thinkingTime = minTime + Math.floor(Math.random() * (maxTime - minTime));
	// Use setTimeout to yield frame and prevent blocking
	LK.setTimeout(function () {
		// Clear the safety timeout since we're now processing
		if (safetyTimeout) {
			LK.clearTimeout(safetyTimeout);
			safetyTimeout = null;
		}
		// Recheck game state after timeout - ensure AI flag is always cleared
		if (gameOver || currentPlayer !== 2 || !isAIMode || gameMode !== 'ai') {
			aiProcessing = false;
			return;
		}
		// Additional validation to prevent AI moves during player turn
		if (isAIMode && currentPlayer === 1) {
			aiProcessing = false;
			return;
		}
		// Extra safety check - if game state is invalid, clear flag
		if (!isAIMode || gameMode !== 'ai') {
			aiProcessing = false;
			return;
		}
		// Find best move using difficulty-specific strategy
		var bestMove = findBestMove();
		var moveSuccess = false;
		// Validate that we have a valid move and it's still empty
		if (bestMove && bestMove.value === 0) {
			// Validate coordinates are within bounds
			if (bestMove.row >= 0 && bestMove.row < 3 && bestMove.col >= 0 && bestMove.col < 3) {
				// Double check the cell is still valid before AI places marker
				var targetCell = grid[bestMove.row][bestMove.col];
				if (targetCell && targetCell.value === 0 && !gameOver && currentPlayer === 2 && !targetCell.marker) {
					if (targetCell.placeMarker(2, function () {
						// This callback runs after the AI marker animation completes
						checkWin();
						if (!gameOver) {
							currentPlayer = 1;
							updateTurnDisplay();
						}
						// Clear AI processing flag after move is complete
						aiProcessing = false;
						// Force refresh of all cell hover states and clear any visual artifacts
						for (var r = 0; r < 3; r++) {
							for (var c = 0; c < 3; c++) {
								var cell = grid[r][c];
								if (cell && cell.value === 0) {
									var cellBgElement = cell.children[0];
									if (cellBgElement) {
										cellBgElement.alpha = 0.01;
										cellBgElement.tint = 0xffffff; // Reset tint to white
										cellBgElement.scaleX = 1; // Reset scale
										cellBgElement.scaleY = 1; // Reset scale
										cellBgElement.rotation = 0; // Reset rotation
									}
								}
							}
						}
					})) {
						moveSuccess = true;
					}
				}
			}
		}
		// If the best move failed for any reason, find any empty cell as fallback
		if (!moveSuccess && !gameOver && currentPlayer === 2) {
			var emptyCells = [];
			for (var row = 0; row < 3; row++) {
				for (var col = 0; col < 3; col++) {
					if (grid[row][col].value === 0 && !grid[row][col].marker) {
						emptyCells.push(grid[row][col]);
					}
				}
			}
			// Try to place marker on any empty cell
			if (emptyCells.length > 0) {
				var fallbackCell = emptyCells[Math.floor(Math.random() * emptyCells.length)];
				if (fallbackCell.placeMarker(2, function () {
					// This callback runs after the fallback AI marker animation completes
					checkWin();
					if (!gameOver) {
						currentPlayer = 1;
						updateTurnDisplay();
					}
					// Clear AI processing flag after move is complete
					aiProcessing = false;
					// Force refresh of all cell hover states and clear any visual artifacts
					for (var r = 0; r < 3; r++) {
						for (var c = 0; c < 3; c++) {
							var cell = grid[r][c];
							if (cell && cell.value === 0) {
								var cellBgElement = cell.children[0];
								if (cellBgElement) {
									cellBgElement.alpha = 0.01;
									cellBgElement.tint = 0xffffff; // Reset tint to white
									cellBgElement.scaleX = 1; // Reset scale
									cellBgElement.scaleY = 1; // Reset scale
									cellBgElement.rotation = 0; // Reset rotation
								}
							}
						}
					}
				})) {
					moveSuccess = true;
				}
			}
		}
		// If no move was made, clear the processing flag
		if (!moveSuccess) {
			aiProcessing = false;
		}
	}, thinkingTime);
}
function findBestMove() {
	var emptyCells = [];
	var winningMoves = [];
	var blockingMoves = [];
	var forkMoves = [];
	var blockForkMoves = [];
	var cornerCells = [];
	var edgeCells = [];
	var validCells = [];
	// Collect all valid empty cells
	for (var row = 0; row < 3; row++) {
		for (var col = 0; col < 3; col++) {
			var cell = grid[row][col];
			if (cell && cell.value === 0) {
				emptyCells.push(cell);
				validCells.push(cell);
				// Categorize cell positions
				if ((row === 0 || row === 2) && (col === 0 || col === 2)) {
					cornerCells.push(cell);
				} else if (row === 1 && col === 1) {
					// Center cell - handled separately
				} else {
					edgeCells.push(cell);
				}
			}
		}
	}
	// Early exit if no valid moves
	if (validCells.length === 0) {
		return null;
	}
	// Ensure we always have at least one valid cell to return
	if (emptyCells.length === 0) {
		return null;
	}
	// Easy mode: Simplified random play with occasional smart moves
	if (aiDifficulty === 'easy') {
		// 80% chance for completely random move
		if (Math.random() < 0.8) {
			return validCells[Math.floor(Math.random() * validCells.length)];
		}
		// 20% chance for basic strategy (win if possible, otherwise random)
		for (var i = 0; i < emptyCells.length; i++) {
			var cell = emptyCells[i];
			cell.value = 2;
			if (checkWinCondition(2)) {
				cell.value = 0;
				return cell;
			}
			cell.value = 0;
		}
		return validCells[Math.floor(Math.random() * validCells.length)];
	}
	// Normal mode: Balanced play with occasional mistakes
	if (aiDifficulty === 'normal') {
		// Priority 1: Check if AI can win immediately
		for (var i = 0; i < emptyCells.length; i++) {
			var cell = emptyCells[i];
			cell.value = 2;
			if (checkWinCondition(2)) {
				cell.value = 0;
				return cell;
			}
			cell.value = 0;
		}
		// Priority 2: Block player from winning
		for (var i = 0; i < emptyCells.length; i++) {
			var cell = emptyCells[i];
			cell.value = 1;
			if (checkWinCondition(1)) {
				cell.value = 0;
				if (Math.random() > 0.02) {
					return cell;
				}
			}
			cell.value = 0;
		}
		// Priority 3: Create forks
		if (Math.random() < 0.85) {
			forkMoves = checkForFork(2);
			if (forkMoves.length > 0) {
				return forkMoves[0];
			}
		}
		// Priority 4: Block player forks
		if (Math.random() < 0.8) {
			var playerForkMoves = checkForFork(1);
			if (playerForkMoves.length > 0) {
				if (playerForkMoves.length === 1) {
					return playerForkMoves[0];
				} else {
					for (var i = 0; i < emptyCells.length; i++) {
						var cell = emptyCells[i];
						cell.value = 2;
						var createsThreats = false;
						for (var j = 0; j < emptyCells.length; j++) {
							if (i !== j) {
								var testCell = emptyCells[j];
								testCell.value = 2;
								if (checkWinCondition(2)) {
									createsThreats = true;
								}
								testCell.value = 0;
							}
						}
						cell.value = 0;
						if (createsThreats) {
							return cell;
						}
					}
					return playerForkMoves[0];
				}
			}
		}
		// Priority 5: Basic strategy
		if (Math.random() < 0.7) {
			var strategicMoves = [];
			if (grid[1][1].value === 0) {
				strategicMoves.push(grid[1][1]);
				strategicMoves.push(grid[1][1]);
			}
			for (var i = 0; i < cornerCells.length; i++) {
				strategicMoves.push(cornerCells[i]);
			}
			if (strategicMoves.length > 0) {
				return strategicMoves[Math.floor(Math.random() * strategicMoves.length)];
			}
		}
		if (emptyCells.length > 0) {
			return emptyCells[Math.floor(Math.random() * emptyCells.length)];
		}
	}
	// Advanced position evaluation for hard mode AI
	function evaluateHardModePosition(cell) {
		var score = 0;
		var row = cell.row;
		var col = cell.col;
		// Base positional values with strategic weighting
		if (row === 1 && col === 1) {
			score += 15; // Center dominance
		} else if ((row === 0 || row === 2) && (col === 0 || col === 2)) {
			score += 12; // Corner control
		} else {
			score += 8; // Edge positions
		}
		// Evaluate line potential (how many lines this position affects)
		var linesControlled = 0;
		var lineValues = 0;
		// Check row control
		var rowEmpty = 0,
			rowAI = 0,
			rowPlayer = 0;
		for (var c = 0; c < 3; c++) {
			if (grid[row][c].value === 0) rowEmpty++;else if (grid[row][c].value === 2) rowAI++;else rowPlayer++;
		}
		if (rowPlayer === 0) {
			linesControlled++;
			lineValues += rowAI * 3 + rowEmpty;
		}
		// Check column control
		var colEmpty = 0,
			colAI = 0,
			colPlayer = 0;
		for (var r = 0; r < 3; r++) {
			if (grid[r][col].value === 0) colEmpty++;else if (grid[r][col].value === 2) colAI++;else colPlayer++;
		}
		if (colPlayer === 0) {
			linesControlled++;
			lineValues += colAI * 3 + colEmpty;
		}
		// Check main diagonal
		if (row === col) {
			var diagEmpty = 0,
				diagAI = 0,
				diagPlayer = 0;
			for (var i = 0; i < 3; i++) {
				if (grid[i][i].value === 0) diagEmpty++;else if (grid[i][i].value === 2) diagAI++;else diagPlayer++;
			}
			if (diagPlayer === 0) {
				linesControlled++;
				lineValues += diagAI * 3 + diagEmpty;
			}
		}
		// Check anti-diagonal
		if (row + col === 2) {
			var antiDiagEmpty = 0,
				antiDiagAI = 0,
				antiDiagPlayer = 0;
			for (var i = 0; i < 3; i++) {
				if (grid[i][2 - i].value === 0) antiDiagEmpty++;else if (grid[i][2 - i].value === 2) antiDiagAI++;else antiDiagPlayer++;
			}
			if (antiDiagPlayer === 0) {
				linesControlled++;
				lineValues += antiDiagAI * 3 + antiDiagEmpty;
			}
		}
		score += linesControlled * 6 + lineValues * 2;
		// Strategic pattern bonuses
		// Opposite corner control
		if (row === 0 && col === 0 && grid[2][2].value === 2 || row === 2 && col === 2 && grid[0][0].value === 2 || row === 0 && col === 2 && grid[2][0].value === 2 || row === 2 && col === 0 && grid[0][2].value === 2) {
			score += 8; // Diagonal dominance
		}
		// Adjacent to AI pieces (connection bonus)
		var adjacentAI = 0;
		var checkAdj = [{
			r: row - 1,
			c: col
		}, {
			r: row + 1,
			c: col
		}, {
			r: row,
			c: col - 1
		}, {
			r: row,
			c: col + 1
		}];
		for (var i = 0; i < checkAdj.length; i++) {
			var adj = checkAdj[i];
			if (adj.r >= 0 && adj.r < 3 && adj.c >= 0 && adj.c < 3) {
				if (grid[adj.r][adj.c].value === 2) adjacentAI++;
			}
		}
		score += adjacentAI * 4;
		return score;
	}
	// Check for forks (moves that create two winning threats)
	function checkForFork(player) {
		var forkCells = [];
		for (var i = 0; i < emptyCells.length; i++) {
			var cell = emptyCells[i];
			cell.value = player;
			var winningLineCount = 0;
			// Count how many winning moves this creates
			for (var j = 0; j < emptyCells.length; j++) {
				if (i !== j) {
					var testCell = emptyCells[j];
					testCell.value = player;
					if (checkWinCondition(player)) {
						winningLineCount++;
					}
					testCell.value = 0;
				}
			}
			cell.value = 0;
			if (winningLineCount >= 2) {
				forkCells.push(cell);
			}
		}
		return forkCells;
	}
	// Hard mode AI - Perfect play with advanced strategy evaluation
	if (aiDifficulty === 'hard') {
		// Priority 1: ALWAYS win if possible (0% miss rate)
		for (var i = 0; i < emptyCells.length; i++) {
			var cell = emptyCells[i];
			cell.value = 2;
			if (checkWinCondition(2)) {
				cell.value = 0;
				return cell; // IMMEDIATELY take winning move - no randomness
			}
			cell.value = 0;
		}
		// Priority 2: ALWAYS block player wins (0% miss rate)
		for (var i = 0; i < emptyCells.length; i++) {
			var cell = emptyCells[i];
			cell.value = 1;
			if (checkWinCondition(1)) {
				cell.value = 0;
				return cell; // IMMEDIATELY block - no randomness
			}
			cell.value = 0;
		}
		// Priority 3: Create forks (multiple winning threats)
		forkMoves = checkForFork(2);
		if (forkMoves.length > 0) {
			return forkMoves[0]; // Take any fork opportunity
		}
		// Priority 4: Block player forks with counter-strategy
		var playerForkMoves = checkForFork(1);
		if (playerForkMoves.length > 0) {
			// If player can create multiple forks, create a counter-threat
			if (playerForkMoves.length > 1) {
				// Look for moves that force player to defend while blocking fork
				for (var i = 0; i < emptyCells.length; i++) {
					var cell = emptyCells[i];
					cell.value = 2;
					var threatsCreated = 0;
					for (var j = 0; j < emptyCells.length; j++) {
						if (i !== j) {
							var testCell = emptyCells[j];
							testCell.value = 2;
							if (checkWinCondition(2)) {
								threatsCreated++;
							}
							testCell.value = 0;
						}
					}
					cell.value = 0;
					if (threatsCreated > 0) {
						return cell; // Counter-threat to force defense
					}
				}
			}
			// Otherwise block the fork
			return playerForkMoves[0];
		}
		// Priority 5: Optimal opening strategy
		if (emptyCells.length === 9) {
			// First move: always take center or corner
			if (grid[1][1].value === 0) {
				return grid[1][1]; // Center is strongest opening
			} else {
				return cornerCells[0]; // Fallback to corner
			}
		}
		if (emptyCells.length === 8) {
			// Second move response
			if (grid[1][1].value === 1) {
				// Player took center, take any corner
				return cornerCells[0];
			} else {
				// Player took corner or edge, take center
				if (grid[1][1].value === 0) {
					return grid[1][1];
				}
			}
		}
		// Priority 6: Advanced positional strategy with minimax evaluation
		var bestMove = null;
		var bestScore = -1000;
		for (var i = 0; i < emptyCells.length; i++) {
			var cell = emptyCells[i];
			var score = evaluateHardModePosition(cell);
			// Add advanced tactical bonuses
			if (cell.row === 1 && cell.col === 1) score += 15; // Center control
			if ((cell.row === 0 || cell.row === 2) && (cell.col === 0 || cell.col === 2)) score += 12; // Corner control
			// Evaluate future position strength
			cell.value = 2;
			var futureThreats = 0;
			for (var j = 0; j < emptyCells.length; j++) {
				if (i !== j) {
					var testCell = emptyCells[j];
					testCell.value = 2;
					if (checkWinCondition(2)) futureThreats++;
					testCell.value = 0;
				}
			}
			score += futureThreats * 8; // Bonus for creating future threats
			cell.value = 0;
			if (score > bestScore) {
				bestScore = score;
				bestMove = cell;
			}
		}
		if (bestMove) {
			return bestMove;
		}
	}
	// Easy mode already handled above with helpful logic
	// Final fallback: intelligent selection
	var fallbackChoices = [];
	// Prioritize based on position value (less strategic in easy mode)
	if (aiDifficulty !== 'easy' || Math.random() < 0.5) {
		if (grid[1][1].value === 0) {
			fallbackChoices.push(grid[1][1]);
		}
	}
	if (cornerCells.length > 0 && (aiDifficulty !== 'easy' || Math.random() < 0.6)) {
		fallbackChoices = fallbackChoices.concat(cornerCells);
	}
	if (edgeCells.length > 0 && (aiDifficulty === 'easy' || Math.random() < 0.3)) {
		fallbackChoices.push(edgeCells[Math.floor(Math.random() * edgeCells.length)]);
	}
	if (fallbackChoices.length === 0) {
		fallbackChoices = validCells;
	}
	if (fallbackChoices.length > 0) {
		return fallbackChoices[Math.floor(Math.random() * fallbackChoices.length)];
	}
	// Ultimate fallback: return first empty cell found
	for (var row = 0; row < 3; row++) {
		for (var col = 0; col < 3; col++) {
			if (grid[row][col].value === 0 && !grid[row][col].marker) {
				return grid[row][col];
			}
		}
	}
	// If still no valid move found, return any empty cell regardless of marker status
	for (var row = 0; row < 3; row++) {
		for (var col = 0; col < 3; col++) {
			if (grid[row][col].value === 0) {
				return grid[row][col];
			}
		}
	}
	return null;
}
function checkWinCondition(player) {
	// Check rows
	for (var row = 0; row < 3; row++) {
		if (grid[row][0].value === player && grid[row][1].value === player && grid[row][2].value === player) {
			return true;
		}
	}
	// Check columns
	for (var col = 0; col < 3; col++) {
		if (grid[0][col].value === player && grid[1][col].value === player && grid[2][col].value === player) {
			return true;
		}
	}
	// Check diagonals
	if (grid[0][0].value === player && grid[1][1].value === player && grid[2][2].value === player) {
		return true;
	}
	if (grid[0][2].value === player && grid[1][1].value === player && grid[2][0].value === player) {
		return true;
	}
	return false;
}
function resetGame() {
	gameOver = false;
	// Immediately clear AI processing to prevent stuck states
	aiProcessing = false;
	// Clear any pending AI timeouts
	LK.clearTimeout(); // Clear any pending timeouts
	// Stop all active tweens to prevent conflicts
	// Stop tweens on UI elements
	tween.stop(playAgainBg);
	tween.stop(playAgainBtn);
	tween.stop(statusText);
	// Stop tweens on difficulty blocks
	tween.stop(easyBlock);
	tween.stop(normalBlock);
	tween.stop(hardBlock);
	// Stop tweens on confirmation dialog elements
	tween.stop(confirmationBg);
	tween.stop(confirmationText);
	tween.stop(yesBtn);
	tween.stop(noBtn);
	// Stop tweens on all cell markers
	for (var row = 0; row < 3; row++) {
		for (var col = 0; col < 3; col++) {
			var cell = grid[row][col];
			if (cell.marker) {
				tween.stop(cell.marker);
			}
		}
	}
	// Force clear any stuck AI state
	if (isAIMode && currentPlayer === 2) {
		currentPlayer = 1; // Reset to player's turn
	}
	// Start according to game mode
	if (gameMode === 'ai') {
		currentPlayer = 1; // Player always starts in AI mode
		isAIMode = true;
	} else if (gameMode === 'twoPlayer') {
		currentPlayer = 1; // X player always starts in two-player mode
		isAIMode = false;
	} else {
		// Menu mode
		currentPlayer = 1;
		isAIMode = false;
	}
	// Clear grid
	for (var row = 0; row < 3; row++) {
		for (var col = 0; col < 3; col++) {
			var cell = grid[row][col];
			cell.value = 0;
			if (cell.marker) {
				// Stop any active tweens on marker before destroying
				tween.stop(cell.marker);
				// Reset marker properties to prevent visual glitches
				cell.marker.alpha = 0;
				cell.marker.scaleX = 1;
				cell.marker.scaleY = 1;
				cell.marker.tint = 0xffffff;
				cell.marker.rotation = 0;
				// Remove from parent before destroying
				if (cell.marker.parent) {
					cell.marker.parent.removeChild(cell.marker);
				}
				cell.marker.destroy();
				cell.marker = null;
			}
			// Clean up second marker for Tom ve Jerry style
			if (cell.marker2) {
				// Stop any active tweens on second marker before destroying
				tween.stop(cell.marker2);
				// Reset marker properties to prevent visual glitches
				cell.marker2.alpha = 0;
				cell.marker2.scaleX = 1;
				cell.marker2.scaleY = 1;
				cell.marker2.tint = 0xffffff;
				cell.marker2.rotation = 0;
				// Remove from parent before destroying
				if (cell.marker2.parent) {
					cell.marker2.parent.removeChild(cell.marker2);
				}
				cell.marker2.destroy();
				cell.marker2 = null;
			}
			// Reset cell background properties to clear any visual artifacts
			var cellBgElement = cell.children[0];
			if (cellBgElement) {
				cellBgElement.alpha = 0.01;
				cellBgElement.tint = 0xffffff;
				cellBgElement.scaleX = 1;
				cellBgElement.scaleY = 1;
				cellBgElement.rotation = 0;
			}
		}
	}
	// Clear UI
	statusText.setText('');
	statusText.alpha = 0;
	// Remove winner text background if it exists
	if (winnerTextBg && winnerTextBg.parent) {
		winnerTextBg.parent.removeChild(winnerTextBg);
		winnerTextBg.destroy();
		winnerTextBg = null;
	}
	// Remove draw text background if it exists
	if (drawTextBg && drawTextBg.parent) {
		drawTextBg.parent.removeChild(drawTextBg);
		drawTextBg.destroy();
		drawTextBg = null;
	}
	playAgainBtn.alpha = 0;
	playAgainBg.alpha = 0;
	// Stop any pulsing animation on play again button
	tween.stop(playAgainBg);
	tween.stop(playAgainBtn);
	playAgainBg.scaleX = 1;
	playAgainBg.scaleY = 1;
	playAgainBtn.interactive = false;
	// Hide all settings and package UI elements
	changeAppearanceBtn.alpha = 0;
	changeAppearanceBtn.interactive = false;
	// Hide current style text
	currentStyleText.alpha = 0;
	packageTitle.alpha = 0;
	package1Btn.alpha = 0;
	package2Btn.alpha = 0;
	package3Btn.alpha = 0;
	package4Btn.alpha = 0;
	package1Bg.alpha = 0;
	package2Bg.alpha = 0;
	package3Bg.alpha = 0;
	package4Bg.alpha = 0;
	// Disable package button interactions
	package1Btn.interactive = false;
	package2Btn.interactive = false;
	package3Btn.interactive = false;
	package4Btn.interactive = false;
	// Hide cartoon submenu elements
	cartoonTitle.alpha = 0;
	tomJerryBtn.alpha = 0;
	phineasFerbBtn.alpha = 0;
	dipperMabelBtn.alpha = 0;
	tomJerryBg.alpha = 0;
	phineasFerbBg.alpha = 0;
	dipperMabelBg.alpha = 0;
	tomJerryBtn.interactive = false;
	phineasFerbBtn.interactive = false;
	dipperMabelBtn.interactive = false;
	cartoonMenuVisible = false;
	// Remove win line
	if (winLine) {
		// Stop any active tweens on win line to prevent memory leaks
		tween.stop(winLine.line);
		tween.stop(winLine); // Stop any tweens on the container too
		// Reset line properties before destroying
		winLine.line.alpha = 0;
		winLine.line.scaleX = 0;
		winLine.line.tint = 0xffffff; // Reset tint
		// Remove from parent before destroying
		if (winLine.parent) {
			winLine.parent.removeChild(winLine);
		}
		winLine.destroy();
		winLine = null;
	}
	updateTurnDisplay();
}
// Play again button handler
playAgainBtn.down = function (x, y, obj) {
	if (gameOver) {
		resetGame();
	}
};
// Add small delay to prevent initial freeze when entering game
var gameReady = false;
LK.setTimeout(function () {
	gameReady = true;
}, 50); // Reduced delay for better responsiveness ===================================================================
--- original.js
+++ change.js
@@ -1004,9 +1004,9 @@
 	// Enable confirmation button interactions
 	yesBtn.interactive = true;
 	noBtn.interactive = true;
 	// Show confirmation elements
-	tween(confirmationBg, {
+	animateObject(confirmationBg, {
 		alpha: 0.8
 	}, {
 		duration: 200
 	});