/**** 
* Plugins
****/ 
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/**** 
* Classes
****/ 
// CookArea: Cooks raw corn, can be tapped to cook, then send to order area
var CookArea = Container.expand(function () {
	var self = Container.call(this);
	self.rawCorn = 0;
	self.cookedCorn = 0;
	// Cooked corn icon
	var cookedAsset = self.attachAsset('cooked', {
		anchorX: 0.5,
		anchorY: 0.5,
		alpha: 0
	});
	cookedAsset.width = 120;
	cookedAsset.height = 120;
	// Texts
	var rawTxt = new Text2('0', {
		size: 60,
		fill: "#fff"
	});
	rawTxt.anchor.set(0.5, 0.2);
	self.addChild(rawTxt);
	// cookedTxt removed: cooked corn count text is not shown on 2nd screen
	self.addRawCorn = function (n) {
		self.rawCorn += n;
		rawTxt.setText(self.rawCorn);
	};
	self.removeRawCorn = function (n) {
		if (self.rawCorn >= n) {
			self.rawCorn -= n;
			rawTxt.setText(self.rawCorn);
			return true;
		}
		return false;
	};
	self.addCookedCorn = function (n) {
		self.cookedCorn += n;
		// cookedTxt.setText(self.cookedCorn); // removed
		cookedAsset.alpha = 1;
		LK.effects.flashObject(cookedAsset, 0xffb347, 200);
	};
	self.removeCookedCorn = function (n) {
		if (self.cookedCorn >= n) {
			self.cookedCorn -= n;
			// cookedTxt.setText(self.cookedCorn); // removed
			if (self.cookedCorn === 0) cookedAsset.alpha = 0;
			return true;
		}
		return false;
	};
	self.down = function (x, y, obj) {
		if (self.rawCorn > 0) {
			// Cook one corn (takes time)
			self.removeRawCorn(1);
			LK.setTimeout(function () {
				self.addCookedCorn(1);
			}, game.cookTime);
		} else if (self.cookedCorn > 0) {
			// Send cooked corn to order area
			var globalCook = self.toGlobal({
				x: 0,
				y: 0
			});
			var orderPos = game.cookArea.getGlobalCenter();
			var flyingCorn = LK.getAsset('cooked', {
				anchorX: 0.5,
				anchorY: 0.5,
				x: globalCook.x,
				y: globalCook.y,
				width: 100,
				height: 100
			});
			game.addChild(flyingCorn);
			tween(flyingCorn, {
				x: orderPos.x,
				y: orderPos.y,
				alpha: 0.2
			}, {
				duration: 500,
				easing: tween.cubicOut,
				onFinish: function onFinish() {
					flyingCorn.destroy();
					if (self.removeCookedCorn(1)) {
						game.orderArea.addCorn(1);
					}
				}
			});
		}
	};
	self.getGlobalCenter = function () {
		var pos = self.toGlobal({
			x: 0,
			y: 0
		});
		return {
			x: pos.x,
			y: pos.y
		};
	};
	self.reset = function () {
		self.rawCorn = 0;
		self.cookedCorn = 0;
		rawTxt.setText('0');
		// cookedTxt.setText('0'); // removed
		cookedAsset.alpha = 0;
	};
	// Add containsPoint method to CookArea
	self.containsPoint = function (point) {
		// Convert global point to local coordinates of the CookArea
		var localX = point.x - self.x;
		var localY = point.y - self.y;
		// cookAsset is removed, so use cookedAsset for bounds
		var w = cookedAsset.width;
		var h = cookedAsset.height;
		// Check if localX, localY is inside cookedAsset bounds
		return localX >= -w / 2 && localX <= w / 2 && localY >= -h / 2 && localY <= h / 2;
	};
	return self;
});
// CornBox: Stores harvested corn, can be tapped to send to cook area
var CornBox = Container.expand(function () {
	var self = Container.call(this);
	var boxAsset = self.attachAsset('box', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	boxAsset.width = 220;
	boxAsset.height = 220;
	self.cornCount = 0;
	// Corn count text
	var cornTxt = new Text2('0', {
		size: 80,
		fill: 0xFFF700
	});
	cornTxt.anchor.set(0.5, 0.5);
	self.addChild(cornTxt);
	self.addCorn = function (n) {
		self.cornCount += n;
		cornTxt.setText(self.cornCount);
		LK.effects.flashObject(boxAsset, 0xffff00, 200);
	};
	self.removeCorn = function (n) {
		if (self.cornCount >= n) {
			self.cornCount -= n;
			cornTxt.setText(self.cornCount);
			return true;
		}
		return false;
	};
	self.down = function (x, y, obj) {
		if (self.cornCount > 0) {
			// Animate corn to cook area
			var globalBox = self.toGlobal({
				x: 0,
				y: 0
			});
			var cookPos = game.cookArea.getGlobalCenter();
			var flyingCorn = LK.getAsset('corn', {
				anchorX: 0.5,
				anchorY: 0.5,
				x: globalBox.x,
				y: globalBox.y,
				width: 100,
				height: 100
			});
			game.addChild(flyingCorn);
			tween(flyingCorn, {
				x: cookPos.x,
				y: cookPos.y,
				alpha: 0.2
			}, {
				duration: 500,
				easing: tween.cubicOut,
				onFinish: function onFinish() {
					flyingCorn.destroy();
					if (self.removeCorn(1)) {
						game.cookArea.addRawCorn(1);
					}
				}
			});
		}
	};
	self.getGlobalCenter = function () {
		var pos = self.toGlobal({
			x: 0,
			y: 0
		});
		return {
			x: pos.x,
			y: pos.y
		};
	};
	self.reset = function () {
		self.cornCount = 0;
		cornTxt.setText('0');
	};
	// Add containsPoint method to CornBox
	self.containsPoint = function (point) {
		// Convert global point to local coordinates of the CornBox
		var localX = point.x - self.x;
		var localY = point.y - self.y;
		// boxAsset is centered at (0,0) with anchor 0.5,0.5
		var w = boxAsset.width;
		var h = boxAsset.height;
		// Check if localX, localY is inside boxAsset bounds
		return localX >= -w / 2 && localX <= w / 2 && localY >= -h / 2 && localY <= h / 2;
	};
	return self;
});
// CornField: Represents a single field where corn can be planted, grown, and harvested
var CornField = Container.expand(function () {
	var self = Container.call(this);
	// States: 'empty', 'growing', 'ready'
	self.state = 'empty';
	self.index = 0; // set by game
	self.cornType = null; // for future upgrades
	// Field asset
	var fieldAsset = self.attachAsset('field', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	fieldAsset.width = 320;
	fieldAsset.height = 320;
	// Corn asset (hidden unless growing/ready)
	var cornAsset = self.attachAsset('corn', {
		anchorX: 0.5,
		anchorY: 0.5,
		alpha: 0
	});
	cornAsset.width = 180;
	cornAsset.height = 180;
	// Grow time/ready text above corn
	var growTxt = new Text2('', {
		size: 60,
		fill: "#fff"
	});
	growTxt.anchor.set(0.5, 1);
	growTxt.x = 0;
	growTxt.y = -120;
	self.addChild(growTxt);
	// Cooldown text above field (for replant cooldown)
	var cooldownTxt = new Text2('', {
		size: 60,
		fill: 0xFF4444
	});
	cooldownTxt.anchor.set(0.5, 1);
	cooldownTxt.x = 0;
	cooldownTxt.y = -180;
	self.addChild(cooldownTxt);
	// Track grow start time for countdown
	self._growStart = null;
	self._growEnd = null;
	// Show field as locked if not unlocked
	var lockAsset = self.attachAsset('lock', {
		anchorX: 0.5,
		anchorY: 0.5,
		alpha: 0
	});
	lockAsset.width = 120;
	lockAsset.height = 120;
	// Track how many times this field has been planted
	self.plantCount = 0;
	// Plant corn if field is empty
	self.down = function (x, y, obj) {
		if (self.state === 'empty' && !self.locked) {
			if (self._replantCooldown) {
				// Show cooldown visually
				LK.effects.flashObject(fieldAsset, 0xff0000, 200);
				return;
			}
			// Only allow planting if there are seeds left
			if (typeof game.seeds === "undefined" || game.seeds <= 0) {
				LK.effects.flashObject(fieldAsset, 0xff0000, 300);
				return;
			}
			// Decrement seed count and update display
			game.seeds--;
			if (typeof game.updateSeeds === "function") game.updateSeeds();
			self.plant();
		} else if (self.locked) {
			// Try to unlock if enough coins
			if (game.coins >= game.unlockCost) {
				game.coins -= game.unlockCost;
				self.unlock();
				game.updateCoins();
			} else {
				LK.effects.flashObject(lockAsset, 0xff0000, 500);
			}
		} else if (self.state === 'ready') {
			self.harvest();
		}
	};
	self.plant = function () {
		self.state = 'growing';
		cornAsset.alpha = 1;
		cornAsset.scaleX = 0.5;
		cornAsset.scaleY = 0.5;
		tween(cornAsset, {
			scaleX: 1,
			scaleY: 1
		}, {
			duration: 400,
			easing: tween.easeOut
		});
		// Calculate grow time: 5s for first, +1s for each subsequent plant, but reset to 5s after 10s
		if (typeof self.plantCount !== "number") self.plantCount = 0;
		var growTime = 5000 + self.plantCount * 1000;
		if (growTime > 10000) growTime = 5000;
		self.plantCount++;
		// Start grow timer
		self._growStart = Date.now();
		self._growEnd = self._growStart + growTime;
		growTxt.setText(Math.ceil(growTime / 1000));
		self.growTimeout = LK.setTimeout(function () {
			self.state = 'ready';
			self._growStart = null;
			self._growEnd = null;
			growTxt.setText('ready');
			LK.effects.flashObject(cornAsset, 0xffff00, 400);
		}, growTime);
	};
	self.harvest = function () {
		if (self.state !== 'ready') return;
		self.state = 'empty';
		cornAsset.alpha = 0;
		growTxt.setText('');
		self._growStart = null;
		self._growEnd = null;
		// Animate corn flying to box
		var globalCorn = self.toGlobal({
			x: 0,
			y: 0
		});
		var boxPos = game.cornBox.getGlobalCenter();
		var flyingCorn = LK.getAsset('corn', {
			anchorX: 0.5,
			anchorY: 0.5,
			x: globalCorn.x,
			y: globalCorn.y,
			width: 120,
			height: 120
		});
		game.addChild(flyingCorn);
		tween(flyingCorn, {
			x: boxPos.x,
			y: boxPos.y,
			alpha: 0.2
		}, {
			duration: 600,
			easing: tween.cubicOut,
			onFinish: function onFinish() {
				flyingCorn.destroy();
				game.cornBox.addCorn(1);
				// Increase seeds by 2 for each harvested corn
				if (typeof game.seeds === "number") {
					game.seeds += 2;
					if (typeof game.updateSeeds === "function") game.updateSeeds();
				}
			}
		});
		// Start replant cooldown: prevent planting for 5 seconds
		self._replantCooldown = true;
		cooldownTxt.setText('5');
		var cooldownLeft = 5;
		self._replantCooldownTimer = LK.setInterval(function () {
			cooldownLeft--;
			if (cooldownLeft > 0) {
				cooldownTxt.setText('' + cooldownLeft);
			} else {
				LK.clearInterval(self._replantCooldownTimer);
				self._replantCooldown = false;
				cooldownTxt.setText('');
			}
		}, 1000);
	};
	self.locked = false;
	self.lock = function () {
		self.locked = true;
		lockAsset.alpha = 1;
		fieldAsset.alpha = 0.4;
		cornAsset.alpha = 0;
		self.state = 'empty';
	};
	self.unlock = function () {
		self.locked = false;
		lockAsset.alpha = 0;
		fieldAsset.alpha = 1;
	};
	self.setLocked = function (locked) {
		if (locked) {
			self.lock();
			fieldAsset.alpha = 0.4;
		} else {
			self.unlock();
			fieldAsset.alpha = 1;
		}
	};
	self.reset = function () {
		self.state = 'empty';
		cornAsset.alpha = 0;
		if (self.growTimeout) LK.clearTimeout(self.growTimeout);
		growTxt.setText('');
		self._growStart = null;
		self._growEnd = null;
		self.plantCount = 0;
		if (self._replantCooldownTimer) LK.clearInterval(self._replantCooldownTimer);
		self._replantCooldown = false;
		cooldownTxt.setText('');
	};
	// Update method for grow/ready text
	self.update = function () {
		if (self.state === 'growing' && self._growStart && self._growEnd) {
			var now = Date.now();
			var remain = Math.max(0, Math.ceil((self._growEnd - now) / 1000));
			if (remain > 0) {
				growTxt.setText(remain);
			} else {
				growTxt.setText('ready');
			}
		} else if (self.state === 'ready') {
			growTxt.setText('ready');
		} else {
			growTxt.setText('');
		}
		// Show/hide cooldown text depending on replant cooldown
		if (self._replantCooldown) {
			// cooldownTxt is already updated in the interval
			cooldownTxt.visible = true;
		} else {
			cooldownTxt.visible = false;
		}
	};
	// Add containsPoint method to CornField
	self.containsPoint = function (point) {
		// Convert global point to local coordinates of the field
		var localX = point.x - self.x;
		var localY = point.y - self.y;
		// fieldAsset is centered at (0,0) with anchor 0.5,0.5
		var w = fieldAsset.width;
		var h = fieldAsset.height;
		// Check if localX, localY is inside fieldAsset bounds
		return localX >= -w / 2 && localX <= w / 2 && localY >= -h / 2 && localY <= h / 2;
	};
	return self;
});
// Customer: Represents a customer standing in front of the tezgah (counter)
var Customer = Container.expand(function () {
	var self = Container.call(this);
	// Body (ellipse, new asset)
	var body = self.attachAsset('humanBody', {
		anchorX: 0.5,
		anchorY: 1,
		y: 0,
		width: 220,
		height: 320,
		alpha: 1
	});
	// Head (unique customer head)
	var head = self.attachAsset('customerHead', {
		anchorX: 0.5,
		anchorY: 1,
		y: -260,
		width: 180,
		height: 180,
		alpha: 1
	});
	// Left hand (ellipse, new asset)
	var leftHand = self.attachAsset('humanHand', {
		anchorX: 0.5,
		anchorY: 1,
		x: -90,
		y: -100,
		width: 80,
		height: 80,
		alpha: 1
	});
	// Right hand (ellipse, new asset)
	var rightHand = self.attachAsset('humanHand', {
		anchorX: 0.5,
		anchorY: 1,
		x: 90,
		y: -100,
		width: 80,
		height: 80,
		alpha: 1
	});
	// Speech bubble to the right of the customer (use new decorative asset instead of old box)
	// Make the bubble much larger
	self.speechBubble = self.attachAsset('speechBubbleDeco', {
		anchorX: 0,
		anchorY: 0.5,
		x: 120,
		y: -320,
		// move up to fit larger bubble
		width: 520,
		// much wider
		height: 260,
		// much taller
		alpha: 0.92
	});
	// Order text centered on top of the speech bubble
	self.orderText = new Text2('', {
		size: 38,
		// much smaller text to fit inside bubble
		fill: "#222"
	});
	self.orderText.anchor.set(0.5, 0);
	// Center horizontally, place at the top edge of the bubble
	self.orderText.x = self.speechBubble.x + self.speechBubble.width / 2;
	self.orderText.y = self.speechBubble.y - self.speechBubble.height / 2 + 24; // 24px margin from top
	self.addChild(self.speechBubble);
	self.addChild(self.orderText);
	// --- Leave timer label above head ---
	self.leaveTime = 10; // seconds left before leaving
	self._leaveStart = null;
	self._leaveEnd = null;
	self.leaveTimerLabel = new Text2('', {
		size: 60,
		fill: 0xFF4444
	});
	self.leaveTimerLabel.anchor.set(0.5, 0.5);
	// Place directly in the center of the head
	self.leaveTimerLabel.x = head.x;
	self.leaveTimerLabel.y = head.y - head.height / 2;
	self.addChild(self.leaveTimerLabel);
	// Set order and update label
	self.setOrder = function (orderObj) {
		self.order = orderObj;
		if (orderObj && orderObj.sauces && orderObj.sauces.length > 0) {
			// Show corn count and sauces
			var txt = '';
			if (orderObj.cornCount && orderObj.cornCount > 1) {
				txt += orderObj.cornCount + 'x ';
			} else {
				txt += '1x ';
			}
			for (var i = 0; i < orderObj.sauces.length; i++) {
				txt += orderObj.sauces[i];
				if (i < orderObj.sauces.length - 1) txt += ', ';
			}
			self.orderText.setText(txt);
			self.speechBubble.visible = true;
			self.orderText.visible = true;
		} else {
			self.orderText.setText('');
			self.speechBubble.visible = false;
			self.orderText.visible = false;
		}
		// Reset leave timer when new order is set
		self.leaveTime = 10;
		self._leaveStart = Date.now();
		self._leaveEnd = self._leaveStart + 10000;
		self.leaveTimerLabel.visible = true;
		self.leaveTimerLabel.setText('10');
	};
	// Update method for leave timer
	self.update = function () {
		// Only show timer if visible and on order screen
		if (!self.visible || game.currentScreen !== 2) {
			self.leaveTimerLabel.visible = false;
			return;
		}
		// If leave timer is running
		if (self._leaveStart && self._leaveEnd) {
			var now = Date.now();
			var remain = Math.max(0, Math.ceil((self._leaveEnd - now) / 1000));
			if (remain > 0) {
				self.leaveTimerLabel.setText(remain + '');
				self.leaveTimerLabel.visible = true;
			} else {
				self.leaveTimerLabel.setText('0');
				self.leaveTimerLabel.visible = true;
				// Customer leaves: destroy self, clear from game.customers
				if (!self.destroyed) {
					// Fame penalty for missed order
					if (typeof game.fame === "number") {
						game.fame -= 5;
						if (typeof game.updateFame === "function") game.updateFame();
					}
					self.destroy();
					// Remove from game.customers array
					for (var i = 0; i < game.customers.length; i++) {
						if (game.customers[i] === self) {
							game.customers[i] = null;
							break;
						}
					}
					// Update customer spawn interval based on fame
					if (typeof game.updateCustomerSpawnRate === "function") {
						game.updateCustomerSpawnRate();
					}
				}
			}
		} else {
			self.leaveTimerLabel.visible = false;
		}
	};
	return self;
});
// OrderArea: Handles customer orders, sauces, and delivery
var OrderArea = Container.expand(function () {
	var self = Container.call(this);
	var orderAsset = self.attachAsset('order', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	orderAsset.width = 260;
	orderAsset.height = 260;
	self.cornCount = 0;
	self.currentOrder = null;
	self.sauces = ['ketchup', 'mayonnaise'];
	self.selectedSauces = [];
	// Corn icon
	var cornAsset = self.attachAsset('cooked', {
		anchorX: 0.5,
		anchorY: 0.5,
		alpha: 0
	});
	cornAsset.width = 120;
	cornAsset.height = 120;
	// Order text
	var orderTxt = new Text2('', {
		size: 50,
		fill: "#fff"
	});
	orderTxt.anchor.set(0.5, 0.1);
	self.addChild(orderTxt);
	// Sauce icons
	self.sauceIcons = [];
	for (var i = 0; i < self.sauces.length; i++) {
		var s = self.sauces[i];
		var icon = self.attachAsset(s, {
			anchorX: 0.5,
			anchorY: 0.5,
			x: -60 + i * 60,
			y: 80,
			alpha: 0.5
		});
		icon.width = 60;
		icon.height = 60;
		icon.sauce = s;
		// Add containsPoint method to each sauce icon
		icon.containsPoint = function (point) {
			// point is relative to OrderArea, icon.x/y is relative to OrderArea
			var localX = point.x - icon.x;
			var localY = point.y - icon.y;
			var w = icon.width,
				h = icon.height;
			return localX >= -w / 2 && localX <= w / 2 && localY >= -h / 2 && localY <= h / 2;
		};
		self.sauceIcons.push(icon);
	}
	// Delivery button
	var deliverBtn = self.attachAsset('deliver', {
		anchorX: 0.5,
		anchorY: 0.5,
		x: 0,
		y: 120,
		alpha: 0.7
	});
	deliverBtn.width = 100;
	deliverBtn.height = 60;
	// Add containsPoint method to deliverBtn for hit testing
	deliverBtn.containsPoint = function (point) {
		var localX = point.x - deliverBtn.x;
		var localY = point.y - deliverBtn.y;
		var w = deliverBtn.width;
		var h = deliverBtn.height;
		return localX >= -w / 2 && localX <= w / 2 && localY >= -h / 2 && localY <= h / 2;
	};
	// Add corn to order area
	self.addCorn = function (n) {
		self.cornCount += n;
		cornAsset.alpha = 1;
		LK.effects.flashObject(cornAsset, 0xffb347, 200);
		self.updateOrderText();
	};
	self.removeCorn = function (n) {
		if (self.cornCount >= n) {
			self.cornCount -= n;
			if (self.cornCount === 0) cornAsset.alpha = 0;
			self.updateOrderText();
			return true;
		}
		return false;
	};
	self.updateOrderText = function () {
		if (!self.currentOrder) {
			orderTxt.setText('');
			return;
		}
		var txt = 'Order: ';
		for (var i = 0; i < self.currentOrder.sauces.length; i++) {
			txt += self.currentOrder.sauces[i];
			if (i < self.currentOrder.sauces.length - 1) txt += ', ';
		}
		orderTxt.setText(txt);
	};
	self.newOrder = function () {
		// Random sauces (1-3)
		var n = 1 + Math.floor(Math.random() * self.sauces.length);
		var sauces = [];
		var used = {};
		while (sauces.length < n) {
			var idx = Math.floor(Math.random() * self.sauces.length);
			var s = self.sauces[idx];
			if (!used[s]) {
				sauces.push(s);
				used[s] = true;
			}
		}
		self.currentOrder = {
			sauces: sauces
		};
		self.selectedSauces = [];
		self.updateOrderText();
		for (var i = 0; i < self.sauceIcons.length; i++) {
			self.sauceIcons[i].alpha = 0.5;
		}
	};
	// Sauce selection
	self.sauceDown = function (sauce) {
		if (!self.currentOrder) return;
		if (self.selectedSauces.length >= self.currentOrder.sauces.length) return;
		if (self.selectedSauces.indexOf(sauce) !== -1) return;
		self.selectedSauces.push(sauce);
		for (var i = 0; i < self.sauceIcons.length; i++) {
			if (self.sauceIcons[i].sauce === sauce) {
				self.sauceIcons[i].alpha = 1;
			}
		}
	};
	// Deliver order
	self.deliver = function () {
		if (!self.currentOrder) return;
		if (self.cornCount < 1) return;
		// Check sauces
		var ok = true;
		for (var i = 0; i < self.currentOrder.sauces.length; i++) {
			if (self.selectedSauces.indexOf(self.currentOrder.sauces[i]) === -1) {
				ok = false;
				break;
			}
		}
		if (ok && self.selectedSauces.length === self.currentOrder.sauces.length) {
			// Success
			self.removeCorn(1);
			LK.effects.flashObject(orderAsset, 0x00ff00, 400);
			game.coins += game.orderReward;
			game.updateCoins();
			self.currentOrder = null;
			self.selectedSauces = [];
			LK.setTimeout(function () {
				self.newOrder();
			}, 800);
		} else {
			// Wrong sauces
			LK.effects.flashObject(orderAsset, 0xff0000, 400);
			self.selectedSauces = [];
			for (var i = 0; i < self.sauceIcons.length; i++) {
				self.sauceIcons[i].alpha = 0.5;
			}
		}
	};
	// Event handling
	self.down = function (x, y, obj) {
		// Check if sauce icon tapped
		for (var i = 0; i < self.sauceIcons.length; i++) {
			var icon = self.sauceIcons[i];
			if (icon.containsPoint({
				x: x - self.x,
				y: y - self.y
			})) {
				self.sauceDown(icon.sauce);
				return;
			}
		}
		// Check if deliver button tapped
		if (deliverBtn.containsPoint({
			x: x - self.x,
			y: y - self.y
		})) {
			self.deliver();
			return;
		}
	};
	self.getGlobalCenter = function () {
		var pos = self.toGlobal({
			x: 0,
			y: 0
		});
		return {
			x: pos.x,
			y: pos.y
		};
	};
	self.reset = function () {
		self.cornCount = 0;
		self.currentOrder = null;
		self.selectedSauces = [];
		cornAsset.alpha = 0;
		self.updateOrderText();
		for (var i = 0; i < self.sauceIcons.length; i++) {
			self.sauceIcons[i].alpha = 0.5;
		}
	};
	// Add containsPoint method to OrderArea
	self.containsPoint = function (point) {
		// Convert global point to local coordinates of the OrderArea
		var localX = point.x - self.x;
		var localY = point.y - self.y;
		// orderAsset is centered at (0,0) with anchor 0.5,0.5
		var w = orderAsset.width;
		var h = orderAsset.height;
		// Check if localX, localY is inside orderAsset bounds
		return localX >= -w / 2 && localX <= w / 2 && localY >= -h / 2 && localY <= h / 2;
	};
	return self;
});
// unique plate asset for tezgah
// Plate: Represents a plate to be shown on tezgah when cooked corn box is tapped
var Plate = Container.expand(function () {
	var self = Container.call(this);
	var plateAsset = self.attachAsset('plate', {
		anchorX: 0.5,
		anchorY: 0.5,
		width: 700,
		height: 280,
		x: 0,
		y: 0,
		alpha: 1
	});
	// Optionally add more visuals or logic here
	return self;
});
/**** 
* Initialize Game
****/ 
var game = new LK.Game({
	backgroundColor: 0x2e7d32
});
/**** 
* Game Code
****/ 
// New assets for human body and hands
// New tezgah (counter) asset for 3rd screen
// --- Game constants ---
// Unique assets for stove and pot
// cook asset re-added
// Background for 3rd (order) screen
function _typeof(o) {
	"@babel/helpers - typeof";
	return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
		return typeof o;
	} : function (o) {
		return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
	}, _typeof(o);
}
game.cornGrowTime = 5000; // ms
game.cookTime = 2000; // ms
game.orderReward = 5;
game.unlockCost = 20;
game.maxFields = 8;
// --- Game state ---
game.coins = 0;
game.unlockedFields = 4;
game.seeds = 4; // Başlangıçta 4 tohumumuz var
// --- UI: Seeds display (always visible, top center, not in top left 100x100) ---
var seedsTxt = new Text2('Seeds: ' + game.seeds, {
	size: 80,
	fill: 0xFFF700
});
seedsTxt.anchor.set(0.5, 0);
// Move seedsTxt down to avoid the top menu (at least 100px from top), and center horizontally
seedsTxt.x = 2048 / 2;
seedsTxt.y = 140;
LK.gui.top.addChild(seedsTxt);
// Always show seeds count on all screens
seedsTxt.visible = true;
// --- Seed Box for 1st screen (shows number of plantable seeds) ---
game.seedBox = new Container();
var seedBoxAsset = LK.getAsset('box', {
	anchorX: 0.5,
	anchorY: 0.5,
	width: 220,
	height: 220,
	x: 0,
	y: 0,
	alpha: 1
});
game.seedBox.addChild(seedBoxAsset);
// Add English label above the seed box
game.seedBoxLabel = new Text2('Seeds left', {
	size: 40,
	fill: "#fff"
});
game.seedBoxLabel.anchor.set(0.5, 1);
game.seedBoxLabel.x = 0;
game.seedBoxLabel.y = -130;
game.seedBox.addChild(game.seedBoxLabel);
game.seedBoxTxt = new Text2(game.seeds + '', {
	size: 80,
	fill: 0xFFF700
});
game.seedBoxTxt.anchor.set(0.5, 0.5);
game.seedBoxTxt.x = 0;
game.seedBoxTxt.y = 0;
game.seedBox.addChild(game.seedBoxTxt);
// Place seed box at right side, below the seedsTxt, not in top right 100x100
game.seedBox.x = 2048 - 300;
game.seedBox.y = 320;
game.addChild(game.seedBox);
game.seedBox.visible = true; // Only show on field screen
// --- UI: Coins display ---
var coinsTxt = new Text2(game.coins + '$', {
	size: 90,
	fill: 0xFFFDE7
});
coinsTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(coinsTxt);
// --- UI: Clock display (left of coins) ---
game.clockHour = 8;
game.clockMinute = 0;
game.clockTime = 8 * 60; // minutes since 00:00
game.clockRunning = false;
game.day = 1; // Track day count, starts at 1
var clockTxt = new Text2('08:00', {
	size: 90,
	fill: 0xFFFDE7
});
clockTxt.anchor.set(0.5, 0);
// Place clock to the left of coins, with a small gap (e.g. 40px)
// Move it slightly more to the left (e.g. 40px more)
clockTxt.x = coinsTxt.x - 240;
clockTxt.y = coinsTxt.y;
LK.gui.top.addChild(clockTxt);
// --- Fame (Şöhret) ---
// Add dayTxt to the right of fameTxt
game.fame = 0; // Fame starts at 0, max 100
var fameTxt = new Text2('Fame: 0', {
	size: 90,
	fill: 0xFFD700
});
fameTxt.anchor.set(0, 0.0);
// Place fame to the right of coins, with a small gap (e.g. 40px)
fameTxt.x = coinsTxt.x + coinsTxt.width / 2 + 40;
fameTxt.y = coinsTxt.y;
LK.gui.top.addChild(fameTxt);
// Day text, placed to the right of fameTxt
var dayTxt = new Text2('Day: 1', {
	size: 60,
	fill: 0xFFD700
});
dayTxt.anchor.set(0, 0.0);
dayTxt.x = fameTxt.x + fameTxt.width + 100;
dayTxt.y = fameTxt.y;
LK.gui.top.addChild(dayTxt);
// Fame update function
game.updateFame = function () {
	// Fame can go negative, but clamp max to 100
	if (game.fame > 100) game.fame = 100;
	fameTxt.setText('Fame: ' + game.fame);
	if (typeof dayTxt !== "undefined") dayTxt.setText('Day: ' + game.day);
	// Lose the game if fame reaches -50 or less
	if (game.fame <= -50) {
		LK.showGameOver();
	}
};
game.updateFame();
// Bring seedsTxt, coinsTxt, fameTxt to the very front in the GUI overlay
if (typeof LK.gui.top.setChildIndex === "function") {
	LK.gui.top.setChildIndex(seedsTxt, LK.gui.top.children.length - 1);
	LK.gui.top.setChildIndex(coinsTxt, LK.gui.top.children.length - 1);
	LK.gui.top.setChildIndex(fameTxt, LK.gui.top.children.length - 1);
}
// Update seeds display
game.updateSeeds = function () {
	if (typeof seedsTxt !== "undefined") {
		seedsTxt.setText('Seeds: ' + game.seeds);
	}
	if (typeof game.seedBoxTxt !== "undefined") {
		game.seedBoxTxt.setText(game.seeds + '');
	}
};
game.updateCoins = function () {
	coinsTxt.setText(game.coins + '$');
	storage.coins = game.coins;
	storage.unlockedFields = game.unlockedFields;
};
// --- Screen management ---
// Add 5th screen: instructions/help screen
game.screens = ['field', 'boxcook', 'order', 'screen4', 'help'];
game.currentScreen = 4; // 0: field, 1: box/cook, 2: order, 3: screen4, 4: help (instructions)
// --- 5th Screen: Help/Instructions ---
game.helpScreenContainer = new Container();
game.helpScreenBg = LK.getAsset('5screen', {
	anchorX: 0.5,
	anchorY: 0.5,
	width: 2048,
	height: 2732,
	x: 2048 / 2,
	y: 2732 / 2,
	alpha: 1
});
game.helpScreenContainer.addChild(game.helpScreenBg);
// Title
var helpTitle = new Text2('How to Play?', {
	size: 140,
	fill: "#fff"
});
helpTitle.anchor.set(0.5, 0);
helpTitle.x = 2048 / 2;
helpTitle.y = 180;
game.helpScreenContainer.addChild(helpTitle);
// --- Blinking warning note for 5th screen ---
game.helpWarningNote = new Text2("WARNING: No customers will appear until you visit the customer screen. Please keep this in mind.", {
	size: 70,
	fill: 0xFF4444,
	maxWidth: 1800,
	align: "center"
});
game.helpWarningNote.anchor.set(0.5, 0);
game.helpWarningNote.x = 2048 / 2;
game.helpWarningNote.y = 320;
game.helpScreenContainer.addChild(game.helpWarningNote);
// --- New: Blinking auto-start warning note for 5th screen ---
game.autoCustomerWarningNote = new Text2("If you do not press the customer start button by 13:00, the game will start automatically.", {
	size: 70,
	fill: 0xFF4444,
	maxWidth: 1800,
	align: "center"
});
game.autoCustomerWarningNote.anchor.set(0.5, 0);
game.autoCustomerWarningNote.x = 2048 / 2;
// Place below the Start Game button (helpStartBtn), with a margin
if (typeof game.helpStartBtn !== "undefined" && typeof game.helpStartBtn.y === "number" && typeof game.helpStartBtn.height === "number") {
	game.autoCustomerWarningNote.y = game.helpStartBtn.y + game.helpStartBtn.height / 2 + 40;
} else {
	// Fallback: place at a default y if helpStartBtn is not yet defined
	game.autoCustomerWarningNote.y = 2100 + 180 / 2 + 40;
}
game.helpScreenContainer.addChild(game.autoCustomerWarningNote);
// Blinking effect: toggle alpha every 500ms for both warning notes
game._helpWarningBlinkState = true;
game._helpWarningBlinkTimer = LK.setInterval(function () {
	if (game.helpWarningNote) {
		game._helpWarningBlinkState = !game._helpWarningBlinkState;
		game.helpWarningNote.alpha = game._helpWarningBlinkState ? 1 : 0.2;
	}
	if (typeof game.autoCustomerWarningNote !== "undefined" && game.autoCustomerWarningNote !== null && typeof game.autoCustomerWarningNote.alpha !== "undefined") {
		game.autoCustomerWarningNote.alpha = game._helpWarningBlinkState ? 1 : 0.2;
	}
}, 500);
// Instructions (multi-line)
var helpText = new Text2("1. Plant, grow, and harvest corn in the field.\n" + "2. Put the harvested corn into the box.\n" + "3. Take corn from the box and cook it in the pot.\n" + "4. Serve the cooked corn to customers.\n" + "5. Customers want corn with sauces, add the correct sauces.\n" + "6. Unlock new fields and buy automations as you earn more.\n\n" + "Use the left/right arrows to switch between screens.\n\n" + "If your Fame drops to -50, you lose the game!\n" + "If you find any bugs, please write them in the comments below.", {
	size: 80,
	fill: "#fff",
	maxWidth: 1800,
	align: "center"
});
helpText.anchor.set(0.5, 0);
helpText.x = 2048 / 2;
helpText.y = 400;
game.helpScreenContainer.addChild(helpText);
// Add French toggle button above English button (using 'frboxu' asset)
game.frenchBtn = LK.getAsset('frboxu', {
	anchorX: 0.5,
	anchorY: 0.5,
	width: 500,
	height: 120,
	x: 2048 / 2,
	y: 1570,
	// 140px above English button
	alpha: 0.98
});
game.helpScreenContainer.addChild(game.frenchBtn);
game.frenchBtnTxt = new Text2('FRANÇAIS', {
	size: 90,
	fill: "#000"
});
game.frenchBtnTxt.anchor.set(0.5, 0.5);
game.frenchBtnTxt.x = game.frenchBtn.x;
game.frenchBtnTxt.y = game.frenchBtn.y;
game.helpScreenContainer.addChild(game.frenchBtnTxt);
// Add English toggle button above Turkish button (using 'engboxu' asset)
game.englishBtn = LK.getAsset('engboxu', {
	anchorX: 0.5,
	anchorY: 0.5,
	width: 500,
	height: 120,
	x: 2048 / 2,
	y: 1710,
	// 140px above Turkish button
	alpha: 0.98
});
game.helpScreenContainer.addChild(game.englishBtn);
game.englishBtnTxt = new Text2('ENGLISH', {
	size: 90,
	fill: "#000"
});
game.englishBtnTxt.anchor.set(0.5, 0.5);
game.englishBtnTxt.x = game.englishBtn.x;
game.englishBtnTxt.y = game.englishBtn.y;
game.helpScreenContainer.addChild(game.englishBtnTxt);
// Add Turkish toggle button to help screen (now using 'turkboxu' asset)
game.turkceBtn = LK.getAsset('turkboxu', {
	anchorX: 0.5,
	anchorY: 0.5,
	width: 500,
	height: 120,
	x: 2048 / 2,
	y: 1850,
	alpha: 0.98
});
game.helpScreenContainer.addChild(game.turkceBtn);
game.turkceBtnTxt = new Text2('TÜRKÇE', {
	size: 90,
	fill: "#000"
});
game.turkceBtnTxt.anchor.set(0.5, 0.5);
game.turkceBtnTxt.x = game.turkceBtn.x;
game.turkceBtnTxt.y = game.turkceBtn.y;
game.helpScreenContainer.addChild(game.turkceBtnTxt);
// Start button
game.helpStartBtn = LK.getAsset('unlock', {
	anchorX: 0.5,
	anchorY: 0.5,
	width: 600,
	height: 180,
	x: 2048 / 2,
	y: 2100,
	alpha: 0.98
});
game.helpScreenContainer.addChild(game.helpStartBtn);
game.helpStartBtnTxt = new Text2('Start Game', {
	size: 110,
	fill: "#fff"
});
game.helpStartBtnTxt.anchor.set(0.5, 0.5);
game.helpStartBtnTxt.x = game.helpStartBtn.x;
game.helpStartBtnTxt.y = game.helpStartBtn.y;
game.helpScreenContainer.addChild(game.helpStartBtnTxt);
game.addChild(game.helpScreenContainer);
// Turkish text values for all UI
game._turkishTexts = {
	helpTitle: "Nasıl Oynanır?",
	helpText: "1. Tarlada mısır ek, büyüt ve hasat et.\n2. Hasat edilen mısırı kutuya koy.\n3. Kutudan mısırı alıp tencerede pişir.\n4. Pişmiş mısırı müşterilere servis et.\n5. Müşteriler soslu mısır ister, doğru sosları ekle.\n6. Kazandıkça yeni tarlalar aç ve otomasyonlar satın al.\n\nEkranlar arasında geçiş için sol/sağ oklarını kullan.\n\nŞöhretin -50 olursa oyunu kaybedersin!\nBir hata bulursan lütfen aşağıya yoruma yaz.",
	helpStartBtn: "Oyuna Başla",
	turkceBtn: "TÜRKÇE",
	seedsTxt: "Tohum: ",
	seedBoxLabel: "Kalan Tohum",
	cornBoxLabel: "Kutudaki Mısır",
	coinsTxt: "₺",
	fameTxt: "Şöhret: ",
	dayTxt: "Gün: ",
	unlock4Txt: "4 Tarla Aç (20₺)",
	leftTxt: "<",
	rightTxt: ">",
	autoCompleteBtnTxt: "Siparişleri Otomatik Doldur (100₺)",
	autoGrowBtnTxt: "Mısırı Otomatik Büyüt (50₺)",
	autoCollectBtnTxt: "Otomatik Topla (50₺)",
	potReduceBoxTxt: "Pişirme Süresini 10sn Kısalt (50₺)"
};
// Function to switch all texts to Turkish
game.setTurkishTexts = function () {
	// Help screen
	if (typeof helpTitle !== "undefined") helpTitle.setText(game._turkishTexts.helpTitle);
	if (typeof helpText !== "undefined") helpText.setText(game._turkishTexts.helpText);
	if (typeof game.helpStartBtnTxt !== "undefined") game.helpStartBtnTxt.setText(game._turkishTexts.helpStartBtn);
	if (typeof game.turkceBtnTxt !== "undefined") game.turkceBtnTxt.setText(game._turkishTexts.turkceBtn);
	// Top bar
	if (typeof seedsTxt !== "undefined") seedsTxt.setText(game._turkishTexts.seedsTxt + game.seeds);
	if (typeof coinsTxt !== "undefined") coinsTxt.setText(game.coins + game._turkishTexts.coinsTxt);
	if (typeof fameTxt !== "undefined") fameTxt.setText(game._turkishTexts.fameTxt + game.fame);
	if (typeof dayTxt !== "undefined") dayTxt.setText(game._turkishTexts.dayTxt + game.day);
	// Seed box
	if (typeof game.seedBoxLabel !== "undefined") game.seedBoxLabel.setText(game._turkishTexts.seedBoxLabel);
	if (typeof game.seedBoxTxt !== "undefined") game.seedBoxTxt.setText(game.seeds + '');
	// Corn box
	if (typeof game.cornBoxLabel !== "undefined") game.cornBoxLabel.setText(game._turkishTexts.cornBoxLabel);
	// Unlock 4 fields
	if (typeof unlock4Txt !== "undefined") unlock4Txt.setText(game._turkishTexts.unlock4Txt);
	// Nav
	if (typeof leftTxt !== "undefined") leftTxt.setText(game._turkishTexts.leftTxt);
	if (typeof rightTxt !== "undefined") rightTxt.setText(game._turkishTexts.rightTxt);
	// 4th screen buttons
	if (typeof game.autoCompleteBtnTxt !== "undefined") game.autoCompleteBtnTxt.setText(game._turkishTexts.autoCompleteBtnTxt);
	if (typeof game.autoGrowBtnTxt !== "undefined") game.autoGrowBtnTxt.setText(game._turkishTexts.autoGrowBtnTxt);
	if (typeof game.autoCollectBtnTxt !== "undefined") game.autoCollectBtnTxt.setText(game._turkishTexts.autoCollectBtnTxt);
	// Pot reduce box
	if (typeof game.potReduceBoxTxt !== "undefined") game.potReduceBoxTxt.setText(game._turkishTexts.potReduceBoxTxt);
};
// (Removed old Turkish button tap logic here, now handled in main game.down)
// --- 4th Screen: Unique, empty, not copy-paste, not interacting with others ---
game.screen4Container = new Container();
game.screen4Bg = LK.getAsset('box', {
	anchorX: 0.5,
	anchorY: 0.5,
	width: 2048,
	height: 2732,
	x: 2048 / 2,
	y: 2732 / 2,
	alpha: 0.15
});
game.screen4Container.addChild(game.screen4Bg);
// No label for 4th screen (removed as requested)
// --- 4th Screen: Auto-complete Button and Logic ---
game.autoCompleteEnabled = false;
game.autoCompleteBtn = LK.getAsset('unlock', {
	anchorX: 0.0,
	// Anchor left for left extension
	anchorY: 0.5,
	width: 700,
	// Increased width for a bigger button
	height: 180,
	// Increased height for a bigger button
	x: 2048 / 2 - 350,
	// Shift left by half the new width
	y: 2732 / 2 + 200,
	alpha: 0.9
});
game.screen4Container.addChild(game.autoCompleteBtn);
game.autoCompleteBtnTxt = new Text2('Auto-complete Orders (100$)', {
	size: 110,
	// Increased font size for better visibility
	fill: "#fff",
	maxWidth: 660 // Ensure text fits inside 700px button with padding
});
game.autoCompleteBtnTxt.anchor.set(0.5, 0.5);
game.autoCompleteBtnTxt.x = game.autoCompleteBtn.x + game.autoCompleteBtn.width / 2; // Center text in button
game.autoCompleteBtnTxt.y = game.autoCompleteBtn.y;
game.screen4Container.addChild(game.autoCompleteBtnTxt);
// --- 4th Screen: Auto-grow Box and Logic ---
game.autoGrowEnabled = false;
game.autoGrowBtn = LK.getAsset('unlock', {
	anchorX: 0.0,
	anchorY: 0.5,
	width: 700,
	height: 180,
	x: 2048 / 2 - 350,
	y: 2732 / 2 + 420,
	// Place below auto-complete button
	alpha: 0.9
});
game.screen4Container.addChild(game.autoGrowBtn);
game.autoGrowBtnTxt = new Text2('Auto-grow Corn (50$)', {
	size: 110,
	fill: "#fff",
	maxWidth: 660
});
game.autoGrowBtnTxt.anchor.set(0.5, 0.5);
game.autoGrowBtnTxt.x = game.autoGrowBtn.x + game.autoGrowBtn.width / 2;
game.autoGrowBtnTxt.y = game.autoGrowBtn.y;
game.screen4Container.addChild(game.autoGrowBtnTxt);
// --- 4th Screen: Auto-collect Box and Logic ---
game.autoCollectEnabled = false;
game.autoCollectBtn = LK.getAsset('unlock', {
	anchorX: 0.0,
	anchorY: 0.5,
	width: 700,
	height: 180,
	x: 2048 / 2 - 350,
	y: 2732 / 2 + 640,
	// Place below auto-grow button
	alpha: 0.9
});
game.screen4Container.addChild(game.autoCollectBtn);
game.autoCollectBtnTxt = new Text2('Auto-collect (50$)', {
	size: 110,
	fill: "#fff",
	maxWidth: 660
});
game.autoCollectBtnTxt.anchor.set(0.5, 0.5);
game.autoCollectBtnTxt.x = game.autoCollectBtn.x + game.autoCollectBtn.width / 2;
game.autoCollectBtnTxt.y = game.autoCollectBtn.y;
game.screen4Container.addChild(game.autoCollectBtnTxt);
// Helper: auto-collect logic, harvest all ready unlocked fields
game.autoCollectTick = function () {
	if (!game.autoCollectEnabled) return;
	// Only collect if on field screen
	if (game.currentScreen !== 0) return;
	for (var i = 0; i < game.unlockedFields; i++) {
		var field = game.fields[i];
		if (field && field.state === 'ready' && !field.locked) {
			field.harvest();
		}
	}
};
// Set up interval for auto-collect (every 1s)
game._autoCollectInterval = null;
function startAutoCollectInterval() {
	if (game._autoCollectInterval) LK.clearInterval(game._autoCollectInterval);
	game._autoCollectInterval = LK.setInterval(function () {
		if (game.autoCollectEnabled) game.autoCollectTick();
	}, 1000);
}
function stopAutoCollectInterval() {
	if (game._autoCollectInterval) {
		LK.clearInterval(game._autoCollectInterval);
		game._autoCollectInterval = null;
	}
}
startAutoCollectInterval();
// Helper: auto-grow logic, plant in all empty unlocked fields if seeds available
game.autoGrowTick = function () {
	if (!game.autoGrowEnabled) return;
	// Only plant if on field screen and have seeds
	if (game.currentScreen !== 0) return;
	if (typeof game.seeds !== "number" || game.seeds <= 0) return;
	for (var i = 0; i < game.unlockedFields; i++) {
		var field = game.fields[i];
		if (field && field.state === 'empty' && !field.locked && !field._replantCooldown && game.seeds > 0) {
			// Plant in this field
			game.seeds--;
			if (typeof game.updateSeeds === "function") game.updateSeeds();
			field.plant();
		}
	}
};
// Set up interval for auto-grow (every 1s)
game._autoGrowInterval = null;
function startAutoGrowInterval() {
	if (game._autoGrowInterval) LK.clearInterval(game._autoGrowInterval);
	game._autoGrowInterval = LK.setInterval(function () {
		if (game.autoGrowEnabled) game.autoGrowTick();
	}, 1000);
}
function stopAutoGrowInterval() {
	if (game._autoGrowInterval) {
		LK.clearInterval(game._autoGrowInterval);
		game._autoGrowInterval = null;
	}
}
startAutoGrowInterval();
// Helper: check if we can auto-complete a customer order
game.canAutoCompleteOrder = function (cust) {
	if (!cust || !cust.order) return false;
	// Check if enough cooked corn
	if (!game.cookArea || typeof game.cookArea.cookedCorn !== "number") return false;
	if (game.cookArea.cookedCorn < cust.order.cornCount) return false;
	// Check if all sauces are available (ketchup/mayonnaise)
	// In this game, sauces are always available (no inventory), so always true
	return true;
};
// Helper: auto-complete a customer order (simulate delivery visually, step by step)
game.autoCompleteOrder = function (cust) {
	if (!cust || !cust.order) return false;
	if (!game.canAutoCompleteOrder(cust)) return false;
	// If not on order screen, do nothing
	if (game.currentScreen !== 2) return false;
	// Step 1: Ensure plate exists and is empty
	if (!game.tezgahPlate || game.tezgahPlate.destroyed) {
		game.tezgahPlate = new Plate();
		game.tezgahPlate.x = game.counterAsset.x;
		game.tezgahPlate.y = game.counterAsset.y - game.counterAsset.height / 2;
		game.addChild(game.tezgahPlate);
		game.tezgahPlate.cornIcons = [];
	}
	// Remove any existing corn/sauce icons from plate
	if (game.tezgahPlate.cornIcons) {
		for (var i = 0; i < game.tezgahPlate.cornIcons.length; i++) {
			var c = game.tezgahPlate.cornIcons[i];
			if (c._ketchupIcon && !c._ketchupIcon.destroyed) c._ketchupIcon.destroy();
			if (c._mayonnaiseIcon && !c._mayonnaiseIcon.destroyed) c._mayonnaiseIcon.destroy();
			if (!c.destroyed) c.destroy();
		}
	}
	game.tezgahPlate.cornIcons = [];
	// Step 2: Animate adding corn(s) to plate, then sauces, then deliver
	var cornCount = cust.order.cornCount || 1;
	var sauces = cust.order.sauces || [];
	var addDelay = 350; // ms between each corn/sauce step
	var totalDelay = 0;
	// Remove cooked corn from cookArea (all at once, but animate one by one)
	if (!game.cookArea.removeCookedCorn(cornCount)) return false;
	// Helper to add a corn icon to plate
	function addCornToPlate(idx) {
		var iconW = 80,
			iconH = 80;
		var xOnPlate = game.tezgahPlate.x - 120 + idx * (iconW + 10);
		var yOnPlate = game.tezgahPlate.y - 10;
		var cornIcon = LK.getAsset('corn', {
			anchorX: 0.5,
			anchorY: 0.5,
			width: iconW,
			height: iconH,
			x: xOnPlate,
			y: yOnPlate,
			alpha: 0
		});
		game.addChild(cornIcon);
		// Animate fade in
		tween(cornIcon, {
			alpha: 1
		}, {
			duration: 200
		});
		if (!game.tezgahPlate.cornIcons) game.tezgahPlate.cornIcons = [];
		game.tezgahPlate.cornIcons.push(cornIcon);
	}
	// Helper to add sauce to a corn icon
	function addSauceToCorn(cornIcon, sauce) {
		var icon = null;
		if (sauce === "ketchup") {
			icon = LK.getAsset('ketchup', {
				anchorX: 0.5,
				anchorY: 0.5,
				width: 40,
				height: 40,
				x: cornIcon.x,
				y: cornIcon.y - 20,
				alpha: 0
			});
			game.addChild(icon);
			tween(icon, {
				alpha: 1
			}, {
				duration: 150
			});
			cornIcon._hasKetchup = true;
			cornIcon._ketchupIcon = icon;
		} else if (sauce === "mayonnaise") {
			icon = LK.getAsset('mayonnaise', {
				anchorX: 0.5,
				anchorY: 0.5,
				width: 40,
				height: 40,
				x: cornIcon.x,
				y: cornIcon.y - 10,
				alpha: 0
			});
			game.addChild(icon);
			tween(icon, {
				alpha: 1
			}, {
				duration: 150
			});
			cornIcon._hasMayonnaise = true;
			cornIcon._mayonnaiseIcon = icon;
		}
	}
	// Step 2a: Animate adding corns one by one
	for (var i = 0; i < cornCount; i++) {
		LK.setTimeout(function (idx) {
			return function () {
				addCornToPlate(idx);
			};
		}(i), totalDelay);
		totalDelay += addDelay;
	}
	// Step 2b: Animate adding sauces to each corn, one by one
	// Distribute sauces as in order (if more corns than sauces, repeat sauces)
	for (var i = 0; i < cornCount; i++) {
		for (var s = 0; s < sauces.length; s++) {
			LK.setTimeout(function (idx, sauceName) {
				return function () {
					if (game.tezgahPlate.cornIcons && game.tezgahPlate.cornIcons[idx]) {
						addSauceToCorn(game.tezgahPlate.cornIcons[idx], sauceName);
					}
				};
			}(i, sauces[s]), totalDelay);
			totalDelay += addDelay;
		}
	}
	// Step 3: After all corns and sauces are added, animate plate to customer and deliver
	LK.setTimeout(function () {
		// Animate plate to customer
		var origX = game.tezgahPlate.x;
		var origY = game.tezgahPlate.y;
		var destX = cust.x;
		var destY = cust.y - 200; // move plate up to customer
		tween(game.tezgahPlate, {
			x: destX,
			y: destY
		}, {
			duration: 400,
			easing: tween.cubicOut,
			onFinish: function onFinish() {
				// Flash customer for feedback
				LK.effects.flashObject(cust, 0x00ff00, 400);
				// Give coins based on cornCount
				var deliveredCoins = 0;
				if (cust.order && cust.order.cornCount === 1) deliveredCoins = 5;else if (cust.order && cust.order.cornCount === 2) deliveredCoins = 10;else if (cust.order && cust.order.cornCount === 3) deliveredCoins = 15;else if (cust.order && cust.order.cornCount === 4) deliveredCoins = 20;else deliveredCoins = 5; // fallback
				game.coins += deliveredCoins;
				if (typeof game.updateCoins === "function") game.updateCoins();
				// Remove customer
				if (!cust.destroyed) cust.destroy();
				for (var i = 0; i < game.customers.length; i++) {
					if (game.customers[i] === cust) {
						game.customers[i] = null;
						break;
					}
				}
				// Remove corn/sauce icons from plate
				if (game.tezgahPlate.cornIcons) {
					for (var i = 0; i < game.tezgahPlate.cornIcons.length; i++) {
						var c = game.tezgahPlate.cornIcons[i];
						if (c._ketchupIcon && !c._ketchupIcon.destroyed) c._ketchupIcon.destroy();
						if (c._mayonnaiseIcon && !c._mayonnaiseIcon.destroyed) c._mayonnaiseIcon.destroy();
						if (!c.destroyed) c.destroy();
					}
				}
				game.tezgahPlate.cornIcons = [];
				// Animate plate back to original position
				tween(game.tezgahPlate, {
					x: origX,
					y: origY
				}, {
					duration: 400,
					easing: tween.cubicOut
				});
				// Flash effect for feedback
				LK.effects.flashObject(game.cookedCornBox, 0x00ff00, 400);
			}
		});
	}, totalDelay + 200);
	return true;
};
game.addChild(game.screen4Container);
game.screen4Container.visible = false;
// --- Field grid ---
game.fields = [];
var fieldRows = 2;
var fieldCols = 2;
var fieldSpacing = 340;
var fieldStartX = 400;
var fieldStartY = 600;
function updateFieldGrid() {
	// Determine grid size based on unlocked fields
	var n = game.unlockedFields;
	if (n <= 4) {
		fieldRows = 2;
		fieldCols = 2;
	} else if (n <= 9) {
		fieldRows = 3;
		fieldCols = 3;
	} else {
		fieldRows = 4;
		fieldCols = 4;
	}
}
function layoutFields() {
	updateFieldGrid();
	// Calculate how many fields are visible per "page" vertically
	var maxVisibleRows = Math.floor((2048 - fieldStartY) / fieldSpacing); // fit as many as possible
	var maxVisibleCols = Math.floor((2048 - fieldStartX) / fieldSpacing);
	// For our game, let's allow 2 rows before scrolling horizontally
	var fieldsPerCol = 2;
	var fieldsPerRow = 4; // up to 4 columns before scrolling horizontally
	// Calculate how many "pages" horizontally
	var pageSize = fieldsPerCol * fieldsPerRow;
	var pageCount = Math.ceil(game.unlockedFields / pageSize);
	// Find which page is currently active (always show the last unlocked page)
	var currentPage = Math.floor((game.unlockedFields - 1) / pageSize);
	// Calculate horizontal offset for scrolling
	var scrollX = currentPage * (fieldsPerRow * fieldSpacing + 100); // 100px gap between pages
	for (var i = 0; i < game.maxFields; i++) {
		// Which page does this field belong to?
		var page = Math.floor(i / pageSize);
		var pageIndex = i % pageSize;
		var row = Math.floor(pageIndex / fieldsPerRow);
		var col = pageIndex % fieldsPerRow;
		// If not unlocked, keep offscreen
		if (i >= game.unlockedFields) {
			game.fields[i].x = -1000;
			game.fields[i].y = -1000;
			continue;
		}
		// Place fields in a grid, scrolling horizontally after 2 rows
		var x = fieldStartX + col * fieldSpacing - scrollX;
		var y = fieldStartY + row * fieldSpacing;
		game.fields[i].x = x;
		game.fields[i].y = y;
	}
}
// Create fields
for (var i = 0; i < game.maxFields; i++) {
	var field = new CornField();
	field.index = i;
	game.addChild(field);
	game.fields.push(field);
}
function updateFieldLocks() {
	for (var i = 0; i < game.maxFields; i++) {
		if (i < game.unlockedFields) {
			game.fields[i].setLocked(false);
			if (game.fields[i].fieldAsset) game.fields[i].fieldAsset.alpha = 1;
		} else {
			game.fields[i].setLocked(true);
			if (game.fields[i].fieldAsset) game.fields[i].fieldAsset.alpha = 0.4;
		}
	}
}
updateFieldLocks();
layoutFields();
// --- Corn Box ---
// Place corn box just above the pot on 2nd screen
game.cornBox = new CornBox();
// Pot is at y = 2732 (bottom), potAsset.y = -120, potAsset.height = 800, so top of pot = 2732 - 120 - 800 = 1812
// Place corn box about 120px above the pot
game.cornBox.x = 2048 / 2;
game.cornBox.y = 1812 - 120;
// Add English label above the corn box, and a count label below it
game.cornBoxLabel = new Text2('Corn in Box', {
	size: 48,
	fill: "#fff"
});
game.cornBoxLabel.anchor.set(0.5, 1);
game.cornBoxLabel.x = game.cornBox.x;
game.cornBoxLabel.y = game.cornBox.y - 140;
game.cornBoxLabel.visible = false; // Only show on boxcook screen
game.addChild(game.cornBoxLabel);
// Add a corn count label above the box (just below the "Corn in Box" label)
game.cornBoxCountLabel = new Text2('0', {
	size: 60,
	fill: 0xFFF700
});
game.cornBoxCountLabel.anchor.set(0.5, 1);
game.cornBoxCountLabel.x = game.cornBox.x;
game.cornBoxCountLabel.y = game.cornBox.y - 80;
game.cornBoxCountLabel.visible = false; // Only show on boxcook screen
game.addChild(game.cornBoxCountLabel);
game.addChild(game.cornBox);
// --- Cooked Corn Count Box for 2nd Screen (BoxCook) ---
// This duplicates the cooked corn count box from the 3rd screen, but for the 2nd screen.
game.cookedCornBox2 = new Container();
var cookedCornBox2Asset = LK.getAsset('cooked', {
	anchorX: 0.5,
	anchorY: 0.5,
	width: 220,
	height: 220,
	x: 0,
	y: 0,
	alpha: 1
});
game.cookedCornBox2.addChild(cookedCornBox2Asset);
// Add a small black box behind the cooked corn count text for a shadow effect
var cookedCornBox2Shadow = LK.getAsset('box', {
	anchorX: 0.5,
	anchorY: 0.5,
	width: 120,
	height: 80,
	x: 0,
	y: 0,
	alpha: 0.7,
	tint: 0x000000
});
game.cookedCornBox2.addChild(cookedCornBox2Shadow);
game.cookedCornBox2Txt = new Text2('0', {
	size: 80,
	fill: "#fff"
});
game.cookedCornBox2Txt.anchor.set(0.5, 0.5);
game.cookedCornBox2Txt.x = 0;
game.cookedCornBox2Txt.y = 0;
game.cookedCornBox2.addChild(game.cookedCornBox2Txt);
// Place cooked corn count box at the very left edge, centered vertically above the pot (on 2nd screen)
game.cookedCornBox2.x = 220 / 2 + 10; // 10px margin from left
if (game.stove && typeof game.stove.y === "number" && typeof game.stove.height === "number") {
	game.cookedCornBox2.y = game.stove.y - game.stove.height / 2 - 220 / 2 - 20; // above the stove, adjust as needed
} else {
	// Fallback: place at a reasonable default if stove is not yet defined
	game.cookedCornBox2.y = 2732 - 1600;
}
game.addChild(game.cookedCornBox2);
game.cookedCornBox2.visible = false; // Only show on boxcook screen
// --- Stove & Pot for Cooking Screen ---
game.stove = new Container();
// Place stove at the very bottom of the screen, centered horizontally
game.stove.x = 2048 / 2;
game.stove.y = 2732; // y=2732 is the very bottom edge
game.addChild(game.stove);
// Stove asset (image) - use a new visual asset for the stove
var stoveAsset = LK.getAsset('stoveImage', {
	anchorX: 0.5,
	anchorY: 1,
	width: 2048,
	height: 420,
	y: 0
});
game.stove.addChild(stoveAsset);
// Pot asset (ellipse, centered on stove) - as large as possible but fits inside stove and is fully visible
var potAsset = LK.getAsset('pot', {
	anchorX: 0.5,
	anchorY: 1,
	width: 1400,
	// very wide, fills most of stove
	height: 800,
	// very tall, fills most of stove
	y: -120 // move pot lower so it sits further down on the stove
});
game.stove.addChild(potAsset);
// Place pot lower on the stove
potAsset.x = 0;
potAsset.y = -120;
// Pot "lid" (for visual effect) - now smaller than pot and sits directly on top of pot
var potLid = LK.getAsset('potLid', {
	anchorX: 0.5,
	anchorY: 1,
	width: 1000,
	// reduced width
	height: 220,
	// reduced height
	y: potAsset.y - potAsset.height + 300,
	// moved lid slightly up (less down)
	// adjust to match new height
	alpha: 1
});
game.stove.addChild(potLid);
// Place lid to visually close the pot
potLid.x = potAsset.x;
potLid.y = potAsset.y - potAsset.height + 300; // moved lid slightly up (less down)
// Corns in pot (array of {asset, startTime})
game.potCorns = [];
// Pot timer text
game.potTimerTxt = new Text2('', {
	size: 70,
	fill: "#fff"
});
game.potTimerTxt.anchor.set(0.5, 0.5);
// Center the timer in the middle of the pot, and move it lower to match new pot position
game.potTimerTxt.x = potAsset.x;
game.potTimerTxt.y = potAsset.y - 320 + 300; // Move timer lower to match new pot position
game.stove.addChild(game.potTimerTxt);
// --- 2nd Screen: Pot Cook Time Reduce Box ---
// Only visible on 2nd screen (boxcook)
game.potReduceBox = LK.getAsset('unlock', {
	anchorX: 0.5,
	anchorY: 0.5,
	width: 600,
	height: 260,
	x: 2048 / 2,
	y: 400,
	// much higher on the screen
	alpha: 0.98
});
game.addChild(game.potReduceBox);
game.potReduceBox.visible = false; // Only show on 2nd screen
game.potReduceBoxTxt = new Text2('Reduce Cook Time by 10s (50$)', {
	size: 90,
	fill: "#fff",
	maxWidth: 560
});
game.potReduceBoxTxt.anchor.set(0.5, 0.5);
game.potReduceBoxTxt.x = game.potReduceBox.x;
game.potReduceBoxTxt.y = game.potReduceBox.y;
game.addChild(game.potReduceBoxTxt);
game.potReduceBoxTxt.visible = false; // Only show on 2nd screen
// --- Permanent pot cook time reduction: each use reduces all future corns' cook time by 10s ---
game.potCookTimeReduce = 0; // in ms, permanent reduction for all new corns in pot
// --- Cook Area (for legacy, still used for quick cook) ---
game.cookArea = new CookArea();
game.cookArea.x = 2048 - 300;
game.cookArea.y = 1100;
game.addChild(game.cookArea);
// --- Order Area ---
// Order area removed as per request
// Minimal OrderArea to prevent undefined error for addCorn
game.orderArea = {
	addCorn: function addCorn(n) {
		// No-op: order area is removed, but prevent error
	}
};
// --- Order Screen Background ---
game.orderBg = LK.getAsset('orderBg', {
	anchorX: 0.5,
	anchorY: 0.5,
	width: 2048,
	height: 2732,
	x: 2048 / 2,
	y: 2732 / 2,
	alpha: 1
});
game.addChild(game.orderBg);
game.orderBg.visible = false;
// --- Tezgah (Counter) for Customer Screen ---
// Make the tezgah (counter) very large and at the very bottom of the screen, spanning almost the full width
game.counterAsset = LK.getAsset('tezgah', {
	anchorX: 0.5,
	anchorY: 1,
	width: 2048 - 20,
	// leave only 10px margin on each side for a bigger counter
	height: 420,
	// make it even taller
	alpha: 0.95
});
game.counterAsset.x = 2048 / 2;
game.counterAsset.y = 2732; // Place tezgah at the very bottom of the screen (old/original position)
game.addChild(game.counterAsset);
// --- Cooked Corn Count Box for 3rd Screen (Order Screen) ---
game.cookedCornBox = new Container();
var cookedCornBoxAsset = LK.getAsset('cooked', {
	anchorX: 0.5,
	anchorY: 0.5,
	width: 220,
	height: 220,
	x: 0,
	y: 0,
	alpha: 1
});
game.cookedCornBox.addChild(cookedCornBoxAsset);
// Add a small black box behind the cooked corn count text for a shadow effect
var cookedCornBoxShadow = LK.getAsset('box', {
	anchorX: 0.5,
	anchorY: 0.5,
	width: 120,
	height: 80,
	x: 0,
	y: 0,
	alpha: 0.7,
	tint: 0x000000
});
game.cookedCornBox.addChild(cookedCornBoxShadow);
game.cookedCornBoxTxt = new Text2('0', {
	size: 80,
	fill: "#fff"
	// removed shadow property, now using box behind
});
game.cookedCornBoxTxt.anchor.set(0.5, 0.5);
game.cookedCornBoxTxt.x = 0;
game.cookedCornBoxTxt.y = 0;
game.cookedCornBox.addChild(game.cookedCornBoxTxt);
// Place cooked corn count box at the very left edge, centered vertically on top of the tezgah (counter) in 3rd screen
// Center the box horizontally at the left edge of the tezgah
game.cookedCornBox.x = game.counterAsset.x - game.counterAsset.width / 2 + game.cookedCornBox.width / 2 + 10; // 10px margin from left
game.cookedCornBox.y = game.counterAsset.y - game.counterAsset.height / 2; // center vertically on tezgah
game.addChild(game.cookedCornBox);
game.cookedCornBox.visible = false; // Only show on order screen
// --- New: Two unique boxes on the tezgah (counter) ---
game.tezgahBox1 = new Container();
var tezgahBox1Asset = LK.getAsset('tezgahBox1', {
	anchorX: 0.5,
	anchorY: 0.5,
	width: 180,
	height: 180,
	x: 0,
	y: 0,
	alpha: 1
});
game.tezgahBox1.addChild(tezgahBox1Asset);
// Create tezgahBox2 container and asset
game.tezgahBox2 = new Container();
var tezgahBox2Asset = LK.getAsset('tezgahBox2', {
	anchorX: 0.5,
	anchorY: 0.5,
	width: 180,
	height: 180,
	x: 0,
	y: 0,
	alpha: 1
});
game.tezgahBox2.addChild(tezgahBox2Asset);
// Place tezgahBox2 at the far right and at the very top of the tezgah (counter)
game.tezgahBox2.x = game.counterAsset.x + game.counterAsset.width / 2 - game.tezgahBox2.width / 2 - 10; // 10px margin from right
game.tezgahBox2.y = game.counterAsset.y - game.counterAsset.height + game.tezgahBox2.height / 2 + 10; // 10px margin from top
game.addChild(game.tezgahBox2);
game.tezgahBox2.visible = false; // Only show on order screen
// Place tezgahBox1 to the left of tezgahBox2 with a small gap (e.g. 20px)
var tezgahBoxGap = 20;
game.tezgahBox1.x = game.tezgahBox2.x - game.tezgahBox2.width / 2 - tezgahBoxGap - game.tezgahBox1.width / 2;
game.tezgahBox1.y = game.tezgahBox2.y;
game.addChild(game.tezgahBox1);
game.tezgahBox1.visible = false; // Only show on order screen
// --- Customers in front of tezgah (only on customer screen) ---
game.customers = [];
game.customerSpawnPositions = [2048 / 2 - 420,
// left
2048 / 2,
// center
2048 / 2 + 420 // right
];
game.customerY = 2732 - 420; // Stand just above the tezgah
// --- Customer Spawn Control for 3rd Screen ---
// Add a button to the 3rd screen to start customer spawning
game.customerStartBtn = LK.getAsset('unlock', {
	anchorX: 0.5,
	anchorY: 0.5,
	width: 600,
	height: 180,
	x: 2048 / 2,
	y: 600,
	alpha: 0.98
});
game.customerStartBtnTxt = new Text2('Müşteri Başlat', {
	size: 90,
	fill: "#fff"
});
game.customerStartBtnTxt.anchor.set(0.5, 0.5);
game.customerStartBtnTxt.x = game.customerStartBtn.x;
game.customerStartBtnTxt.y = game.customerStartBtn.y;
// Add translations for customer start button
game._customerStartBtnTexts = {
	en: "Start Customers",
	tr: "Müşteri Başlat",
	fr: "Démarrer les clients"
};
// Track if customer spawning has started
game._customerSpawningStarted = false;
// Helper to spawn a customer at a random position
game.spawnCustomer = function () {
	// Find a free customer slot (max 3 customers at a time)
	var freeIndex = -1;
	for (var i = 0; i < 3; i++) {
		if (!game.customers[i] || game.customers[i].destroyed || !game.customers[i].visible) {
			freeIndex = i;
			break;
		}
	}
	if (freeIndex === -1) return; // All slots full
	// Pick a random position index (0, 1, 2)
	var posIdx = Math.floor(Math.random() * 3);
	// Make sure no other customer is at this position
	var taken = false;
	for (var i = 0; i < game.customers.length; i++) {
		if (game.customers[i] && game.customers[i].visible && game.customers[i].x === game.customerSpawnPositions[posIdx]) {
			taken = true;
			break;
		}
	}
	if (taken) {
		// Try other positions
		for (var j = 0; j < 3; j++) {
			if (j !== posIdx) {
				var found = false;
				for (var k = 0; k < game.customers.length; k++) {
					if (game.customers[k] && game.customers[k].visible && game.customers[k].x === game.customerSpawnPositions[j]) {
						found = true;
						break;
					}
				}
				if (!found) {
					posIdx = j;
					break;
				}
			}
		}
	}
	// Create or reuse customer
	var cust;
	if (game.customers[freeIndex] && !game.customers[freeIndex].destroyed) {
		cust = game.customers[freeIndex];
	} else {
		cust = new Customer();
		game.customers[freeIndex] = cust;
		game.addChild(cust);
	}
	// Set customer position and keep them stationary
	cust.x = game.customerSpawnPositions[posIdx];
	cust.y = game.customerY;
	// Always keep customer visible, but only show on order screen
	cust.visible = game.currentScreen === 2;
	// Assign a random order to the customer and show it above their head
	var sauces = ['ketchup', 'mayonnaise'];
	var n = 1 + Math.floor(Math.random() * Math.min(2, sauces.length));
	var orderSauces = [];
	var used = {};
	while (orderSauces.length < n) {
		var idx = Math.floor(Math.random() * sauces.length);
		var s = sauces[idx];
		if (!used[s]) {
			orderSauces.push(s);
			used[s] = true;
		}
	}
	// Assign random cornCount (1-4)
	var cornCount = 1 + Math.floor(Math.random() * 4);
	cust.setOrder({
		sauces: orderSauces,
		cornCount: cornCount
	});
	// Remove any movement or animation logic for customers here to keep them stationary
};
// Remove all pre-created customers
game.customers = [];
// --- Customer spawn timer logic controlled by button ---
game.customerSpawnTimer = null;
game._customerSpawnInterval = 20000; // 20s after first
game._customerFirstDelay = 40000; // 40s for first customer (not used anymore)
game._customerSpawningStarted = false;
// --- Auto-start customer spawning at 13:00 if not started by button ---
game._autoCustomerStartTimer = LK.setInterval(function () {
	// Only check if not already started and on or after 13:00
	if (!game._customerSpawningStarted && game.clockTime >= 13 * 60) {
		game._customerSpawningStarted = true;
		// Set customer start button text to English if auto-started
		if (game.customerStartBtnTxt && game._customerStartBtnTexts) {
			game.customerStartBtnTxt.setText(game._customerStartBtnTexts.en);
		}
		// Hide customer start button if visible
		if (game.customerStartBtn) game.customerStartBtn.visible = false;
		if (game.customerStartBtnTxt) game.customerStartBtnTxt.visible = false;
		// Spawn first customer immediately
		if (typeof spawnCustomerOnOrderScreen === "function") spawnCustomerOnOrderScreen();
		// Start interval for next customers (every 22s)
		if (game.customerSpawnTimer) LK.clearInterval(game.customerSpawnTimer);
		game._customerSpawnIntervalStarted = true;
		game.customerSpawnTimer = LK.setInterval(spawnCustomerOnOrderScreen, 22000);
		// Stop this interval, no need to check again
		LK.clearInterval(game._autoCustomerStartTimer);
		game._autoCustomerStartTimer = null;
	}
}, 500);
// Fame-based customer spawn rate
game.updateCustomerSpawnRate = function () {
	// Fame 0-10: 1 customer per 35s, 10-50: 1 per 18s, 50-100: 1 per 7s
	var fame = typeof game.fame === "number" ? game.fame : 0;
	var interval = 35000;
	if (fame >= 50) {
		interval = 7000;
	} else if (fame >= 10) {
		interval = 18000;
	} else {
		interval = 35000;
	}
	// Fame 0-10: 1 customer per 35s, 10-50: 1 per 18s, 50-100: 1 per 7s
	var fame = typeof game.fame === "number" ? game.fame : 0;
	var interval = 35000;
	if (fame >= 50) {
		interval = 7000;
	} else if (fame >= 10) {
		interval = 18000;
	} else {
		interval = 35000;
	}
	game._customerSpawnInterval = interval;
	// Restart interval if already running and spawning has started
	if (game.customerSpawnTimer && game._customerSpawningStarted) {
		LK.clearInterval(game.customerSpawnTimer);
		game.customerSpawnTimer = LK.setInterval(spawnCustomerOnOrderScreen, game._customerSpawnInterval);
	}
};
// --- Only spawn customers if started by button ---
function spawnCustomerOnOrderScreen() {
	if (!game._customerSpawningStarted) return;
	// Allow customer start button to work before 11:00 (removed 11:00 check)
	// (No time check here)
	// Always spawn customers in the background, not just on order screen
	// Find a free customer slot (max 3 customers at a time)
	var freeIndex = -1;
	for (var i = 0; i < 3; i++) {
		if (!game.customers[i] || game.customers[i].destroyed || !game.customers[i].visible) {
			freeIndex = i;
			break;
		}
	}
	if (freeIndex === -1) return; // All slots full
	// Pick a random position index (0, 1, 2)
	var posIdx = Math.floor(Math.random() * 3);
	// Make sure no other customer is at this position
	var taken = false;
	for (var i = 0; i < game.customers.length; i++) {
		if (game.customers[i] && game.customers[i].visible && game.customers[i].x === game.customerSpawnPositions[posIdx]) {
			taken = true;
			break;
		}
	}
	if (taken) {
		// Try other positions
		for (var j = 0; j < 3; j++) {
			if (j !== posIdx) {
				var found = false;
				for (var k = 0; k < game.customers.length; k++) {
					if (game.customers[k] && game.customers[k].visible && game.customers[k].x === game.customerSpawnPositions[j]) {
						found = true;
						break;
					}
				}
				if (!found) {
					posIdx = j;
					break;
				}
			}
		}
	}
	// Create or reuse customer
	var cust;
	if (game.customers[freeIndex] && !game.customers[freeIndex].destroyed) {
		cust = game.customers[freeIndex];
	} else {
		cust = new Customer();
		game.customers[freeIndex] = cust;
		game.addChild(cust);
	}
	// Set customer position and keep them stationary
	cust.x = game.customerSpawnPositions[posIdx];
	cust.y = game.customerY;
	// Always keep customer visible, but only show on order screen
	cust.visible = game.currentScreen === 2;
	// Assign a random order to the customer and show it above their head
	var sauces = ['ketchup', 'mayonnaise'];
	var n = 1 + Math.floor(Math.random() * Math.min(2, sauces.length));
	var orderSauces = [];
	var used = {};
	while (orderSauces.length < n) {
		var idx = Math.floor(Math.random() * sauces.length);
		var s = sauces[idx];
		if (!used[s]) {
			orderSauces.push(s);
			used[s] = true;
		}
	}
	// Assign random cornCount (1-4)
	var cornCount = 1 + Math.floor(Math.random() * 4);
	cust.setOrder({
		sauces: orderSauces,
		cornCount: cornCount
	});
	// After first call, switch to interval if not already set and spawning has started
	if (!game._customerSpawnIntervalStarted && game._customerSpawningStarted) {
		// Allow customer start button to work before 11:00 (removed 11:00 check)
		// (No time check here)
		// Always spawn customers in the background, not just on order screen
		// Find a free customer slot (max 3 customers at a time)
		var freeIndex = -1;
		for (var i = 0; i < 3; i++) {
			if (!game.customers[i] || game.customers[i].destroyed || !game.customers[i].visible) {
				freeIndex = i;
				break;
			}
		}
		if (freeIndex === -1) return; // All slots full
		// Pick a random position index (0, 1, 2)
		var posIdx = Math.floor(Math.random() * 3);
		// Make sure no other customer is at this position
		var taken = false;
		for (var i = 0; i < game.customers.length; i++) {
			if (game.customers[i] && game.customers[i].visible && game.customers[i].x === game.customerSpawnPositions[posIdx]) {
				taken = true;
				break;
			}
		}
		if (taken) {
			// Try other positions
			for (var j = 0; j < 3; j++) {
				if (j !== posIdx) {
					var found = false;
					for (var k = 0; k < game.customers.length; k++) {
						if (game.customers[k] && game.customers[k].visible && game.customers[k].x === game.customerSpawnPositions[j]) {
							found = true;
							break;
						}
					}
					if (!found) {
						posIdx = j;
						break;
					}
				}
			}
		}
		// Create or reuse customer
		var cust;
		if (game.customers[freeIndex] && !game.customers[freeIndex].destroyed) {
			cust = game.customers[freeIndex];
		} else {
			cust = new Customer();
			game.customers[freeIndex] = cust;
			game.addChild(cust);
		}
		// Set customer position and keep them stationary
		cust.x = game.customerSpawnPositions[posIdx];
		cust.y = game.customerY;
		// Always keep customer visible, but only show on order screen
		cust.visible = game.currentScreen === 2;
		// Assign a random order to the customer and show it above their head
		var sauces = ['ketchup', 'mayonnaise'];
		var n = 1 + Math.floor(Math.random() * Math.min(2, sauces.length));
		var orderSauces = [];
		var used = {};
		while (orderSauces.length < n) {
			var idx = Math.floor(Math.random() * sauces.length);
			var s = sauces[idx];
			if (!used[s]) {
				orderSauces.push(s);
				used[s] = true;
			}
		}
		// Assign random cornCount (1-4)
		var cornCount = 1 + Math.floor(Math.random() * 4);
		cust.setOrder({
			sauces: orderSauces,
			cornCount: cornCount
		});
		// No destroy, just reuse and set visible
		// After first call, switch to interval if not already set
		game._customerSpawnIntervalStarted = true;
		game.customerSpawnTimer = LK.setInterval(spawnCustomerOnOrderScreen, game._customerSpawnInterval);
	}
}
// --- Clock update interval ---
game._clockInterval = LK.setInterval(function () {
	if (!game.clockRunning) return;
	// Advance time by 1 minute every 0.2 real seconds (5x faster)
	game.clockTime += 1;
	// If time passes 23:59, reset to 08:00 and increment day
	if (game.clockTime > 23 * 60 + 59) {
		game.clockTime = 8 * 60;
		game.clockHour = 8;
		game.clockMinute = 0;
		if (typeof game.day === "undefined") game.day = 1;
		game.day += 1;
		if (typeof dayTxt !== "undefined") dayTxt.setText('Day: ' + game.day);
		if (typeof game.updateFame === "function") game.updateFame();
	} else {
		game.clockHour = Math.floor(game.clockTime / 60);
		game.clockMinute = game.clockTime % 60;
	}
	// Format as HH:MM
	var h = game.clockHour < 10 ? '0' + game.clockHour : '' + game.clockHour;
	var m = game.clockMinute < 10 ? '0' + game.clockMinute : '' + game.clockMinute;
	if (typeof clockTxt !== "undefined") clockTxt.setText(h + ':' + m);
}, 200);
// --- Helper: is it after 11:00? ---
game.isAfterEleven = function () {
	return game.clockTime >= 11 * 60;
};
// Do not start customer spawn timer automatically; will be started by button on 3rd screen
if (game.customerSpawnTimer) {
	LK.clearInterval(game.customerSpawnTimer);
}
if (game._customerSpawnTimeout) {
	LK.clearTimeout(game._customerSpawnTimeout);
}
game._customerSpawnIntervalStarted = false;
game._customerSpawningStarted = false;
// --- Unlock 4 Fields Button ---
// Place a new button below the 4 fields to unlock 4 more fields at once for 20 coins
var unlock4BtnContainer = new Container();
var unlock4Btn = LK.getAsset('unlock', {
	anchorX: 0.0,
	anchorY: 0.5,
	width: 420,
	// Reduced width for a smaller button
	height: 120,
	// Reduced height for a smaller button
	alpha: 0.9
});
unlock4BtnContainer.addChild(unlock4Btn);
game.addChild(unlock4BtnContainer);
var unlock4Txt = new Text2('Unlock 4 Fields (20$)', {
	size: 70,
	// Reduced font size for better fit
	fill: "#fff",
	maxWidth: 380 // Ensure text fits inside 420px button with padding
});
unlock4Txt.anchor.set(0.5, 0.5);
game.addChild(unlock4Txt);
// Add containsPoint method to unlock4BtnContainer
unlock4BtnContainer.containsPoint = function (point) {
	var localX = point.x - unlock4BtnContainer.x;
	var localY = point.y - unlock4BtnContainer.y;
	var w = unlock4Btn.width;
	var h = unlock4Btn.height;
	return localX >= -w / 2 && localX <= w / 2 && localY >= -h / 2 && localY <= h / 2;
};
// Update unlock4 button position and text
function updateUnlockBtn() {
	// Only show if exactly 4 fields are unlocked and maxFields not reached and seeds > 0
	if (game.unlockedFields !== 4 || game.unlockedFields >= game.maxFields || game.seeds <= 0) {
		unlock4Btn.alpha = 0.3;
		unlock4BtnContainer.visible = false;
		unlock4Txt.visible = false;
		return;
	}
	// Place below the last unlocked field (index game.unlockedFields-1)
	// Since unlock4Btn is now left-anchored and wider, align its left edge with the field's left edge
	var lastField = game.fields[game.unlockedFields - 1];
	unlock4BtnContainer.x = lastField.x - 260; // Shift left by half the new width (520/2)
	unlock4BtnContainer.y = lastField.y + 260;
	unlock4Txt.x = unlock4BtnContainer.x + unlock4Btn.width / 2; // Center text in button
	unlock4Txt.y = unlock4BtnContainer.y;
	unlock4BtnContainer.visible = true;
	unlock4Txt.visible = true;
	unlock4Btn.alpha = 0.9;
	unlock4Txt.setText('Unlock 4 Fields (20$)');
}
updateUnlockBtn();
// --- Screen navigation buttons ---
var leftBtn = LK.getAsset('unlock', {
	anchorX: 0.5,
	anchorY: 0.5,
	width: 120,
	height: 120,
	x: 120,
	y: 2732 / 2,
	alpha: 0.7
});
var rightBtn = LK.getAsset('unlock', {
	anchorX: 0.5,
	anchorY: 0.5,
	width: 120,
	height: 120,
	x: 2048 - 120,
	y: 2732 / 2,
	alpha: 0.7
});
game.addChild(leftBtn);
game.addChild(rightBtn);
// Add containsPoint for nav buttons
leftBtn.containsPoint = function (point) {
	var localX = point.x - leftBtn.x;
	var localY = point.y - leftBtn.y;
	var w = leftBtn.width,
		h = leftBtn.height;
	return localX >= -w / 2 && localX <= w / 2 && localY >= -h / 2 && localY <= h / 2;
};
rightBtn.containsPoint = function (point) {
	var localX = point.x - rightBtn.x;
	var localY = point.y - rightBtn.y;
	var w = rightBtn.width,
		h = rightBtn.height;
	return localX >= -w / 2 && localX <= w / 2 && localY >= -h / 2 && localY <= h / 2;
};
// Nav button text
var leftTxt = new Text2('<', {
	size: 90,
	fill: "#fff"
});
leftTxt.anchor.set(0.5, 0.5);
leftTxt.x = leftBtn.x;
leftTxt.y = leftBtn.y;
game.addChild(leftTxt);
var rightTxt = new Text2('>', {
	size: 90,
	fill: "#fff"
});
rightTxt.anchor.set(0.5, 0.5);
rightTxt.x = rightBtn.x;
rightTxt.y = rightBtn.y;
game.addChild(rightTxt);
// --- Screen show/hide logic ---
function updateScreenVisibility() {
	// 0: field, 1: boxcook, 2: order, 3: screen4, 4: help
	var showField = game.currentScreen === 0;
	var showBoxCook = game.currentScreen === 1;
	var showOrder = game.currentScreen === 2;
	var showScreen4 = game.currentScreen === 3;
	var showHelp = game.currentScreen === 4;
	// Fields
	for (var i = 0; i < game.fields.length; i++) {
		game.fields[i].visible = showField;
	}
	// Show seedBox only on field screen
	if (game.seedBox) {
		game.seedBox.visible = showField;
	}
	// Only show unlock4BtnContainer and unlock4Txt if unlock4Btn should be available (unlockedFields==4, not maxed, seeds>0)
	// If fields are already unlocked (>4), always hide the button and label
	if (showField && game.unlockedFields === 4 && game.unlockedFields < game.maxFields && game.seeds > 0) {
		unlock4BtnContainer.visible = true;
		unlock4Txt.visible = true;
		unlock4Btn.alpha = 0.9;
	} else {
		unlock4BtnContainer.visible = false;
		unlock4Txt.visible = false;
		unlock4Btn.alpha = 0.3;
	}
	// Always hide and destroy unlock4BtnContainer and label if more than 4 fields are unlocked
	if (game.unlockedFields > 4) {
		if (unlock4BtnContainer && !unlock4BtnContainer.destroyed) {
			unlock4BtnContainer.destroy();
		}
		if (unlock4Txt && !unlock4Txt.destroyed) {
			unlock4Txt.destroy();
		}
		unlock4Btn.alpha = 0.3;
	}
	// Show/hide corn box label and count only on 2nd screen (boxcook)
	if (typeof game.cornBoxLabel !== "undefined") {
		game.cornBoxLabel.visible = showBoxCook;
		if (showBoxCook) {
			game.cornBoxLabel.setText('Corn in Box');
			// Make sure label is above the box and added to the display list
			if (game.cornBox && game.children.indexOf(game.cornBoxLabel) === -1) {
				game.addChild(game.cornBoxLabel);
			}
			// Position label above the box
			game.cornBoxLabel.x = game.cornBox.x;
			game.cornBoxLabel.y = game.cornBox.y - 140;
		}
	}
	// Show/hide potReduceBox and label only on 2nd screen
	if (typeof game.potReduceBox !== "undefined") {
		game.potReduceBox.visible = showBoxCook;
	}
	if (typeof game.potReduceBoxTxt !== "undefined") {
		game.potReduceBoxTxt.visible = showBoxCook;
	}
	if (typeof game.cornBoxCountLabel !== "undefined") {
		game.cornBoxCountLabel.visible = showBoxCook;
		if (showBoxCook) {
			// Update count to match box
			if (game.cornBox && typeof game.cornBox.cornCount === "number") {
				game.cornBoxCountLabel.setText(game.cornBox.cornCount + '');
			} else {
				game.cornBoxCountLabel.setText('0');
			}
			// Position count label just below the main label
			game.cornBoxCountLabel.x = game.cornBox.x;
			game.cornBoxCountLabel.y = game.cornBox.y - 80;
			// Make sure label is added to display list
			if (game.cornBox && game.children.indexOf(game.cornBoxCountLabel) === -1) {
				game.addChild(game.cornBoxCountLabel);
			}
		}
	}
	// Hide all other elements except fields, unlock4Btn, and seedBox on 1st screen
	for (var i = 0; i < game.children.length; i++) {
		var ch = game.children[i];
		if (showHelp) {
			// Only show the help screen container, hide everything else
			if (ch === game.helpScreenContainer) {
				ch.visible = true;
			} else {
				ch.visible = false;
			}
		} else if (showScreen4) {
			// Only show the 4th screen container, hide everything else
			if (ch === game.screen4Container) {
				ch.visible = true;
			} else {
				ch.visible = false;
			}
		} else if (showField) {
			// Only show fields, unlock4BtnContainer, unlock4Txt, and seedBox
			if (game.fields.indexOf(ch) !== -1 || ch === unlock4BtnContainer || ch === unlock4Txt || ch === game.seedBox) {
				ch.visible = true;
			} else {
				ch.visible = false;
			}
		} else if (showBoxCook) {
			// Only show stove, cornBox, and potReduceBox on 2nd screen
			if (ch === game.stove || ch === game.cornBox || ch === game.potReduceBox || ch === game.potReduceBoxTxt) {
				ch.visible = true;
			} else {
				ch.visible = false;
			}
		} else {
			// On 3rd screen (order), only show tezgah, customers, cooked corn count box, and plate
			if (game.currentScreen === 2) {
				// Show tezgah plate if not present, but do NOT recreate if it already exists (preserve corn icons)
				// Only create the plate if it never existed (not if just hidden)
				if (!game.tezgahPlate) {
					game.tezgahPlate = new Plate();
					// Center the plate horizontally on the tezgah
					game.tezgahPlate.x = game.counterAsset.x;
					// Place the plate vertically so it sits visually on the tezgah
					game.tezgahPlate.y = game.counterAsset.y - game.counterAsset.height / 2;
					game.addChild(game.tezgahPlate);
					game.tezgahPlate.cornIcons = [];
				} else if (game.tezgahPlate.destroyed) {
					// If destroyed, recreate and clear contents
					game.tezgahPlate = new Plate();
					game.tezgahPlate.x = game.counterAsset.x;
					game.tezgahPlate.y = game.counterAsset.y - game.counterAsset.height / 2;
					game.addChild(game.tezgahPlate);
					game.tezgahPlate.cornIcons = [];
				} else if (game.children.indexOf(game.tezgahPlate) === -1) {
					// If plate exists but is not in display list, re-add it (preserve its cornIcons)
					game.addChild(game.tezgahPlate);
				}
				if (ch === game.counterAsset || ch === game.cookedCornBox || ch === game.tezgahPlate) {
					ch.visible = true;
				} else if (game.customers && game.customers.indexOf(ch) !== -1) {
					ch.visible = true;
				} else {
					ch.visible = false;
				}
			} else {
				// On other screens, hide stove and cornBox, show others (handled by their own logic)
				if (ch === game.stove || ch === game.cornBox) {
					ch.visible = false;
				} else if (typeof ch.visible === "boolean") {
					ch.visible = true;
				}
			}
		}
	}
	// Order
	// game.orderArea.visible = showOrder; // Removed order area
	if (game.counterAsset) game.counterAsset.visible = showOrder;
	// Customers visible only on customer screen
	if (game.customers) {
		for (var i = 0; i < game.customers.length; i++) {
			if (showOrder && game.customers[i] && !game.customers[i].destroyed) {
				game.customers[i].visible = true;
			} else if (game.customers[i]) {
				game.customers[i].visible = false;
			}
		}
	}
	// Show cooked corn count box only on order screen (3rd) and boxcook screen (2nd)
	if (game.cookedCornBox) {
		// Only show on order screen (screen 2)
		game.cookedCornBox.visible = showOrder;
		// Show tezgah plate if on order screen
		if (showOrder && game.tezgahPlate) {
			game.tezgahPlate.visible = true;
		}
		// Update value from cookArea only if visible
		if (showOrder && game.cookArea && typeof game.cookArea.cookedCorn === "number") {
			game.cookedCornBoxTxt.setText(game.cookArea.cookedCorn);
		} else {
			game.cookedCornBoxTxt.setText('');
			game.cookedCornBox.visible = false;
		}
	}
	// Show/hide cooked corn count box for 2nd screen (boxcook)
	if (game.cookedCornBox2) {
		game.cookedCornBox2.visible = showBoxCook;
		if (showBoxCook && game.cookArea && typeof game.cookArea.cookedCorn === "number") {
			game.cookedCornBox2Txt.setText(game.cookArea.cookedCorn);
		} else {
			game.cookedCornBox2Txt.setText('');
			game.cookedCornBox2.visible = false;
		}
	}
	// Show tezgahBox1 and tezgahBox2 only on order screen
	if (game.tezgahBox1) game.tezgahBox1.visible = showOrder;
	if (game.tezgahBox2) game.tezgahBox2.visible = showOrder;
	// Show orderBg only on 3rd (order) screen
	if (game.orderBg) {
		game.orderBg.visible = showOrder;
	}
	// Show customer start button only on 3rd screen (order)
	if (game.customerStartBtn && game.customerStartBtnTxt) {
		if (showOrder && !game._customerSpawningStarted) {
			if (game.children.indexOf(game.customerStartBtn) === -1) game.addChild(game.customerStartBtn);
			if (game.children.indexOf(game.customerStartBtnTxt) === -1) game.addChild(game.customerStartBtnTxt);
			game.customerStartBtn.visible = true;
			game.customerStartBtnTxt.visible = true;
		} else {
			game.customerStartBtn.visible = false;
			game.customerStartBtnTxt.visible = false;
		}
	}
	// Nav buttons visible except on help screen (5th screen)
	if (game.currentScreen === 4) {
		leftBtn.visible = false;
		rightBtn.visible = false;
		leftTxt.visible = false;
		rightTxt.visible = false;
	} else {
		leftBtn.visible = true;
		rightBtn.visible = true;
		leftTxt.visible = true;
		rightTxt.visible = true;
	}
	// Hide tezgah plate if not on order screen
	if (game.tezgahPlate && game.currentScreen !== 2) {
		game.tezgahPlate.visible = false;
		// Do NOT destroy the plate or its cornIcons here; preserve them for when returning to the order screen
	}
	// Show seeds count always
	if (typeof seedsTxt !== "undefined") {
		seedsTxt.visible = true;
		if (typeof game.updateSeeds === "function") {
			game.updateSeeds();
		}
		if (typeof game.seedBoxTxt !== "undefined") {
			game.seedBoxTxt.setText(game.seeds + '');
		}
	}
}
updateScreenVisibility();
// --- Touch handling ---
game._draggingPlate = false;
game._dragPlateOffset = {
	x: 0,
	y: 0
};
game._dragPlateStart = {
	x: 0,
	y: 0
};
game._dragPlateCornIcons = null;
game._dragPlateKetchup = null;
game.down = function (x, y, obj) {
	// --- 5th Screen: English button tap ---
	if (game.currentScreen === 4 && game.englishBtn && typeof game.englishBtn.x === "number" && typeof game.englishBtn.y === "number") {
		var localXe = x - game.englishBtn.x;
		var localYe = y - game.englishBtn.y;
		var we = game.englishBtn.width || 420;
		var he = game.englishBtn.height || 140;
		if (localXe >= -we / 2 && localXe <= we / 2 && localYe >= -he / 2 && localYe <= he / 2) {
			// Switch all texts to English (default)
			if (typeof helpTitle !== "undefined") helpTitle.setText('How to Play?');
			if (typeof helpText !== "undefined") helpText.setText("1. Plant, grow, and harvest corn in the field.\n" + "2. Put the harvested corn into the box.\n" + "3. Take corn from the box and cook it in the pot.\n" + "4. Serve the cooked corn to customers.\n" + "5. Customers want corn with sauces, add the correct sauces.\n" + "6. Unlock new fields and buy automations as you earn more.\n\n" + "Use the left/right arrows to switch between screens.\n\n" + "If your Fame drops to -50, you lose the game!\n" + "If you find any bugs, please write them in the comments below.");
			if (typeof game.helpWarningNote !== "undefined") game.helpWarningNote.setText("WARNING: No customers will appear until you visit the customer screen. Please keep this in mind.");
			if (typeof game.autoCustomerWarningNote !== "undefined") game.autoCustomerWarningNote.setText("If you do not press the customer start button by 13:00, the game will start automatically.");
			if (typeof game.helpStartBtnTxt !== "undefined") game.helpStartBtnTxt.setText('Start Game');
			if (typeof game.customerStartBtnTxt !== "undefined" && game._customerStartBtnTexts) game.customerStartBtnTxt.setText(game._customerStartBtnTexts.en);
			if (typeof game.helpStartBtn !== "undefined") {
				game.helpStartBtn.width = 600;
				game.helpStartBtn.height = 180;
			}
			if (typeof game.helpStartBtnTxt !== "undefined") {
				game.helpStartBtnTxt.x = game.helpStartBtn.x;
				game.helpStartBtnTxt.y = game.helpStartBtn.y;
			}
			if (typeof game.turkceBtnTxt !== "undefined") game.turkceBtnTxt.setText('TÜRKÇE');
			if (typeof game.englishBtnTxt !== "undefined") game.englishBtnTxt.setText('ENGLISH');
			// Top bar
			if (typeof seedsTxt !== "undefined") seedsTxt.setText('Seeds: ' + game.seeds);
			if (typeof coinsTxt !== "undefined") coinsTxt.setText(game.coins + '$');
			if (typeof fameTxt !== "undefined") {
				fameTxt.setText('Fame: ' + game.fame);
				fameTxt.size = 90; // Restore fame text size in English
			}
			if (typeof dayTxt !== "undefined") dayTxt.setText('Day: ' + game.day);
			// Seed box
			if (typeof game.seedBoxLabel !== "undefined") game.seedBoxLabel.setText('Seeds left');
			if (typeof game.seedBoxTxt !== "undefined") game.seedBoxTxt.setText(game.seeds + '');
			// Corn box
			if (typeof game.cornBoxLabel !== "undefined") game.cornBoxLabel.setText('Corn in Box');
			// Unlock 4 fields
			if (typeof unlock4Txt !== "undefined") unlock4Txt.setText('Unlock 4 Fields (20$)');
			// Nav
			if (typeof leftTxt !== "undefined") leftTxt.setText('<');
			if (typeof rightTxt !== "undefined") rightTxt.setText('>');
			// 4th screen buttons
			if (typeof game.autoCompleteBtnTxt !== "undefined") game.autoCompleteBtnTxt.setText('Auto-complete Orders (100$)');
			if (typeof game.autoGrowBtnTxt !== "undefined") game.autoGrowBtnTxt.setText('Auto-grow Corn (50$)');
			if (typeof game.autoCollectBtnTxt !== "undefined") game.autoCollectBtnTxt.setText('Auto-collect (50$)');
			// Pot reduce box
			if (typeof game.potReduceBoxTxt !== "undefined") game.potReduceBoxTxt.setText('Reduce Cook Time by 10s (50$)');
			LK.effects.flashObject(game.englishBtn, 0x00ff00, 300);
			return;
		}
	}
	// --- 5th Screen: French button tap ---
	if (game.currentScreen === 4 && game.frenchBtn && typeof game.frenchBtn.x === "number" && typeof game.frenchBtn.y === "number") {
		var localXf = x - game.frenchBtn.x;
		var localYf = y - game.frenchBtn.y;
		var wf = game.frenchBtn.width || 420;
		var hf = game.frenchBtn.height || 140;
		if (localXf >= -wf / 2 && localXf <= wf / 2 && localYf >= -hf / 2 && localYf <= hf / 2) {
			// Switch all texts to French, but do NOT change font size (keep size as in English/Turkish)
			if (typeof helpTitle !== "undefined") helpTitle.setText('Comment jouer ?');
			if (typeof helpText !== "undefined") helpText.setText("1. Plante, fais pousser et récolte du maïs dans le champ.\n" + "2. Mets le maïs récolté dans la boîte.\n" + "3. Prends le maïs de la boîte et fais-le cuire dans la marmite.\n" + "4. Sers le maïs cuit aux clients.\n" + "5. Les clients veulent du maïs avec des sauces, ajoute les bonnes sauces.\n" + "6. Débloque de nouveaux champs et achète des automatisations au fur et à mesure que tu gagnes plus.\n\n" + "Utilise les flèches gauche/droite pour changer d’écran.\n\n" + "Si ta renommée tombe à -50, tu perds la partie !\n" + "Si tu trouves un bug, écris-le dans les commentaires ci-dessous.");
			if (typeof game.helpWarningNote !== "undefined") game.helpWarningNote.setText("ATTENTION : Aucun client n’apparaîtra tant que vous n’êtes pas allé à l’écran client. Faites-y attention.");
			if (typeof game.autoCustomerWarningNote !== "undefined") game.autoCustomerWarningNote.setText("Si vous n’appuyez pas sur le bouton de démarrage client avant 13h00, le jeu commencera automatiquement.");
			if (typeof game.helpStartBtnTxt !== "undefined") game.helpStartBtnTxt.setText('Commencer le jeu');
			if (typeof game.customerStartBtnTxt !== "undefined" && game._customerStartBtnTexts) game.customerStartBtnTxt.setText(game._customerStartBtnTexts.fr);
			if (typeof game.turkceBtnTxt !== "undefined") game.turkceBtnTxt.setText('TÜRKÇE');
			if (typeof game.englishBtnTxt !== "undefined") game.englishBtnTxt.setText('ENGLISH');
			if (typeof game.frenchBtnTxt !== "undefined") game.frenchBtnTxt.setText('FRANÇAIS');
			// Top bar
			if (typeof seedsTxt !== "undefined") seedsTxt.setText('Graines : ' + game.seeds);
			if (typeof coinsTxt !== "undefined") coinsTxt.setText(game.coins + '€');
			if (typeof fameTxt !== "undefined") {
				fameTxt.setText('Fame: ' + game.fame);
				fameTxt.size = 60; // Reduce fame text size in French
			}
			if (typeof dayTxt !== "undefined") dayTxt.setText('Jour : ' + game.day);
			// Seed box
			if (typeof game.seedBoxLabel !== "undefined") game.seedBoxLabel.setText('Graines restantes');
			if (typeof game.seedBoxTxt !== "undefined") game.seedBoxTxt.setText(game.seeds + '');
			// Corn box
			if (typeof game.cornBoxLabel !== "undefined") game.cornBoxLabel.setText('Maïs dans la boîte');
			// Unlock 4 fields
			if (typeof unlock4Txt !== "undefined") unlock4Txt.setText('Débloquer 4 champs (20€)');
			// Nav
			if (typeof leftTxt !== "undefined") leftTxt.setText('<');
			if (typeof rightTxt !== "undefined") rightTxt.setText('>');
			// 4th screen buttons
			if (typeof game.autoCompleteBtnTxt !== "undefined") game.autoCompleteBtnTxt.setText('Remplir les commandes (100€)');
			if (typeof game.autoGrowBtnTxt !== "undefined") game.autoGrowBtnTxt.setText('Faire pousser automatiquement (50€)');
			if (typeof game.autoCollectBtnTxt !== "undefined") game.autoCollectBtnTxt.setText('Récolte automatique (50€)');
			// Pot reduce box
			if (typeof game.potReduceBoxTxt !== "undefined") game.potReduceBoxTxt.setText('Réduire le temps de cuisson de 10s (50€)');
			// Do NOT change any .size property of any Text2 object here, so text size remains the same as in other languages
			// --- Grow help start button horizontally in French ---
			if (typeof game.helpStartBtn !== "undefined") {
				game.helpStartBtn.width = 800;
				game.helpStartBtn.height = 180;
			}
			if (typeof game.helpStartBtnTxt !== "undefined") {
				game.helpStartBtnTxt.x = game.helpStartBtn.x;
				game.helpStartBtnTxt.y = game.helpStartBtn.y;
			}
			LK.effects.flashObject(game.frenchBtn, 0x00ff00, 300);
			return;
		}
	}
	// --- 5th Screen: Türkçe button tap ---
	if (game.currentScreen === 4 && game.turkceBtn && typeof game.turkceBtn.x === "number" && typeof game.turkceBtn.y === "number") {
		var localXt = x - game.turkceBtn.x;
		var localYt = y - game.turkceBtn.y;
		var wt = game.turkceBtn.width || 420;
		var ht = game.turkceBtn.height || 140;
		if (localXt >= -wt / 2 && localXt <= wt / 2 && localYt >= -ht / 2 && localYt <= ht / 2) {
			// Switch all texts to Turkish
			if (typeof game.setTurkishTexts === "function") game.setTurkishTexts();
			if (typeof game.customerStartBtnTxt !== "undefined" && game._customerStartBtnTexts) game.customerStartBtnTxt.setText(game._customerStartBtnTexts.tr);
			if (typeof game.helpWarningNote !== "undefined") game.helpWarningNote.setText("Müşteri kısmına gelmediğiniz sürece müşteri doğmaz ona dikkat edin.");
			if (typeof game.autoCustomerWarningNote !== "undefined") game.autoCustomerWarningNote.setText("Eğer saat 13.00 kadar müşteri başlat tuşuna basılmazsa otomatik oyun başlicak.");
			if (typeof game.helpStartBtn !== "undefined") {
				game.helpStartBtn.width = 600;
				game.helpStartBtn.height = 180;
			}
			if (typeof game.helpStartBtnTxt !== "undefined") {
				game.helpStartBtnTxt.x = game.helpStartBtn.x;
				game.helpStartBtnTxt.y = game.helpStartBtn.y;
			}
			if (typeof fameTxt !== "undefined") fameTxt.size = 90; // Restore fame text size in Turkish
			LK.effects.flashObject(game.turkceBtn, 0x00ff00, 300);
			return;
		}
	}
	// --- 5th Screen: Oyuna Başla button tap ---
	if (game.currentScreen === 4 && game.helpStartBtn && typeof game.helpStartBtn.x === "number" && typeof game.helpStartBtn.y === "number") {
		var localXh = x - game.helpStartBtn.x;
		var localYh = y - game.helpStartBtn.y;
		var wh = game.helpStartBtn.width || 420;
		var hh = game.helpStartBtn.height || 140;
		if (localXh >= -wh / 2 && localXh <= wh / 2 && localYh >= -hh / 2 && localYh <= hh / 2) {
			// Start the game: go to field screen, start clock
			game.currentScreen = 0;
			game.clockRunning = true;
			LK.playMusic('Music'); // Start background music when game starts
			updateScreenVisibility();
			return;
		}
	}
	// Navigation buttons
	if (leftBtn.containsPoint({
		x: x,
		y: y
	})) {
		game.currentScreen = (game.currentScreen + 3) % 4;
		updateScreenVisibility();
		return;
	}
	if (rightBtn.containsPoint({
		x: x,
		y: y
	})) {
		game.currentScreen = (game.currentScreen + 1) % 4;
		updateScreenVisibility();
		return;
	}
	// --- 4th Screen: Auto-complete Button Tap ---
	if (game.currentScreen === 3 && game.autoCompleteBtn && typeof game.autoCompleteBtn.x === "number" && typeof game.autoCompleteBtn.y === "number") {
		var localX = x - game.autoCompleteBtn.x;
		var localY = y - game.autoCompleteBtn.y;
		var w = game.autoCompleteBtn.width || 420;
		var h = game.autoCompleteBtn.height || 140;
		if (localX >= -w / 2 && localX <= w / 2 && localY >= -h / 2 && localY <= h / 2) {
			// Only if not already enabled
			if (!game.autoCompleteEnabled) {
				if (game.coins >= 100) {
					game.coins -= 100;
					if (typeof game.updateCoins === "function") game.updateCoins();
					game.autoCompleteEnabled = true;
					game.autoCompleteBtn.alpha = 0.3;
					game.autoCompleteBtnTxt.setText('Auto-complete Active!');
					LK.effects.flashObject(game.autoCompleteBtn, 0x00ff00, 400);
				} else {
					LK.effects.flashObject(game.autoCompleteBtn, 0xff0000, 400);
				}
			}
			return;
		}
	}
	// --- 4th Screen: Auto-grow Button Tap ---
	if (game.currentScreen === 3 && game.autoGrowBtn && typeof game.autoGrowBtn.x === "number" && typeof game.autoGrowBtn.y === "number") {
		var localXg = x - game.autoGrowBtn.x;
		var localYg = y - game.autoGrowBtn.y;
		var wg = game.autoGrowBtn.width || 420;
		var hg = game.autoGrowBtn.height || 140;
		if (localXg >= -wg / 2 && localXg <= wg / 2 && localYg >= -hg / 2 && localYg <= hg / 2) {
			// Only if not already enabled
			if (!game.autoGrowEnabled) {
				if (game.coins >= 50) {
					game.coins -= 50;
					if (typeof game.updateCoins === "function") game.updateCoins();
					game.autoGrowEnabled = true;
					game.autoGrowBtn.alpha = 0.3;
					game.autoGrowBtnTxt.setText('Auto-grow Active!');
					LK.effects.flashObject(game.autoGrowBtn, 0x00ff00, 400);
					startAutoGrowInterval();
				} else {
					LK.effects.flashObject(game.autoGrowBtn, 0xff0000, 400);
				}
			}
			return;
		}
	}
	// --- 4th Screen: Auto-collect Button Tap ---
	if (game.currentScreen === 3 && game.autoCollectBtn && typeof game.autoCollectBtn.x === "number" && typeof game.autoCollectBtn.y === "number") {
		var localXc = x - game.autoCollectBtn.x;
		var localYc = y - game.autoCollectBtn.y;
		var wc = game.autoCollectBtn.width || 420;
		var hc = game.autoCollectBtn.height || 140;
		if (localXc >= -wc / 2 && localXc <= wc / 2 && localYc >= -hc / 2 && localYc <= hc / 2) {
			// Only if not already enabled
			if (!game.autoCollectEnabled) {
				if (game.coins >= 50) {
					game.coins -= 50;
					if (typeof game.updateCoins === "function") game.updateCoins();
					game.autoCollectEnabled = true;
					game.autoCollectBtn.alpha = 0.3;
					game.autoCollectBtnTxt.setText('Auto-collect Active!');
					LK.effects.flashObject(game.autoCollectBtn, 0x00ff00, 400);
					startAutoCollectInterval();
				} else {
					LK.effects.flashObject(game.autoCollectBtn, 0xff0000, 400);
				}
			}
			return;
		}
	}
	// --- Plate drag start logic (order screen only) ---
	if (game.currentScreen === 2 && game.tezgahPlate && !game._draggingPlate && !game.tezgahPlate.destroyed) {
		// Allow drag if touch is on the plate, regardless of corn
		var localPlateX = x - game.tezgahPlate.x;
		var localPlateY = y - game.tezgahPlate.y;
		var plateW = 700,
			plateH = 280;
		if (localPlateX >= -plateW / 2 && localPlateX <= plateW / 2 && localPlateY >= -plateH / 2 && localPlateY <= plateH / 2) {
			game._draggingPlate = true;
			game._dragPlateOffset = {
				x: game.tezgahPlate.x - x,
				y: game.tezgahPlate.y - y
			};
			game._dragPlateStart = {
				x: game.tezgahPlate.x,
				y: game.tezgahPlate.y
			};
			// Store corn icons and ketchup icons for drag-follow
			game._dragPlateCornIcons = [];
			if (game.tezgahPlate.cornIcons) {
				for (var i = 0; i < game.tezgahPlate.cornIcons.length; i++) {
					var c = game.tezgahPlate.cornIcons[i];
					game._dragPlateCornIcons.push({
						icon: c,
						dx: c.x - game.tezgahPlate.x,
						dy: c.y - game.tezgahPlate.y,
						ketchup: c._ketchupIcon
					});
				}
			}
			return;
		}
	}
	// Per-screen input
	if (game.currentScreen === 0) {
		if (game._draggingPlate) return; // Don't allow field actions while dragging plate
		// Field screen
		if (unlock4BtnContainer.visible && unlock4BtnContainer.containsPoint({
			x: x,
			y: y
		})) {
			if (game.seeds <= 0) {
				LK.effects.flashObject(unlock4Btn, 0xff0000, 400);
				return;
			}
			if (game.coins >= 20 && game.unlockedFields === 4 && game.unlockedFields < game.maxFields) {
				game.coins -= 20;
				// Unlock 4 more fields, but do not exceed maxFields
				var toUnlock = Math.min(4, game.maxFields - game.unlockedFields);
				game.unlockedFields += toUnlock;
				game.updateCoins();
				updateFieldLocks();
				layoutFields();
				updateUnlockBtn();
				// Hide and destroy unlock4BtnContainer and its label after unlocking the second set of fields
				if (unlock4BtnContainer && !unlock4BtnContainer.destroyed) {
					unlock4BtnContainer.destroy();
				}
				if (unlock4Txt && !unlock4Txt.destroyed) {
					unlock4Txt.destroy();
				}
				unlock4Btn.alpha = 0.3;
			} else {
				LK.effects.flashObject(unlock4Btn, 0xff0000, 400);
			}
			return;
		}
		for (var i = 0; i < game.fields.length; i++) {
			var f = game.fields[i];
			if (f.visible && f.containsPoint({
				x: x,
				y: y
			})) {
				f.down(x - f.x, y - f.y, obj);
				return;
			}
		}
	} else if (game.currentScreen === 1) {
		if (game._draggingPlate) return; // Don't allow box/cook actions while dragging plate
		// --- PotReduceBox tap: reduce all pot corns' cook time by 10s for 50 coins ---
		if (game.potReduceBox && typeof game.potReduceBox.x === "number" && typeof game.potReduceBox.y === "number") {
			var localXr = x - game.potReduceBox.x;
			var localYr = y - game.potReduceBox.y;
			var wr = game.potReduceBox.width || 320;
			var hr = game.potReduceBox.height || 160;
			if (localXr >= -wr / 2 && localXr <= wr / 2 && localYr >= -hr / 2 && localYr <= hr / 2) {
				// Only if player has enough coins
				if (game.coins >= 50) {
					// Permanent: reduce all future pot corns' cook time by 10s
					game.potCookTimeReduce += 10000; // 10s in ms
					game.coins -= 50;
					if (typeof game.updateCoins === "function") game.updateCoins();
					LK.effects.flashObject(game.potReduceBox, 0x00ff00, 400);
					game.potReduceBoxTxt.setText('All future cooks 10s faster!');
					LK.setTimeout(function () {
						game.potReduceBoxTxt.setText('Reduce Cook Time by 10s (50$)');
					}, 1200);
				} else {
					LK.effects.flashObject(game.potReduceBox, 0xff0000, 400);
					game.potReduceBoxTxt.setText('Not enough money!');
					LK.setTimeout(function () {
						game.potReduceBoxTxt.setText('Reduce Cook Time by 10s (50$)');
					}, 1200);
				}
				return;
			}
		}
		// Box & Cook screen
		// Prevent interaction with cook asset
		if (game.cornBox.visible && game.cornBox.containsPoint({
			x: x,
			y: y
		})) {
			// Prevent adding corn to pot if there is already corn in the pot
			if (game.potCorns && game.potCorns.length > 0) {
				LK.effects.flashObject(potAsset, 0xff0000, 300);
				return;
			}
			// When box is tapped, drop all corn into pot one by one, each at a different position
			var cornToMove = game.cornBox.cornCount;
			if (cornToMove > 0) {
				// Arrange corns in a circle or grid inside the pot
				var potRadius = 120;
				// Center corns visually in the pot asset (fix: use potAsset center, not offset)
				var centerX = potAsset.x;
				var centerY = potAsset.y - potAsset.height / 2 + 60; // center vertically in pot, adjust as needed
				var angleStep = Math.PI * 2 / Math.max(1, cornToMove);
				for (var i = 0; i < cornToMove; i++) {
					if (game.cornBox.removeCorn(1)) {
						// Calculate position for this corn
						var angle = i * angleStep;
						// For up to 8 corns, use a circle, for more, use a spiral
						var r = potRadius * (cornToMove > 8 ? 0.7 + 0.3 * (i / cornToMove) : 1);
						var px = centerX + Math.cos(angle) * r * 0.7;
						var py = centerY + Math.sin(angle) * r * 0.5;
						// Add a corn asset to pot at calculated position
						var cornInPot = LK.getAsset('corn', {
							anchorX: 0.5,
							anchorY: 0.5,
							width: 80,
							height: 80,
							x: px,
							y: py
						});
						game.stove.addChild(cornInPot);
						// Start cook timer (30s - permanent reduction)
						var cookStart = Date.now();
						var cookTimeReduce = typeof game.potCookTimeReduce === "number" ? game.potCookTimeReduce : 0;
						game.potCorns.push({
							asset: cornInPot,
							startTime: cookStart,
							done: false,
							cookTimeReduce: cookTimeReduce // store reduction for this corn
						});
						// Flash pot for each corn
						LK.effects.flashObject(potAsset, 0xffff00, 100);
					}
				}
			}
			return;
		}
		// Prevent interaction with cook asset and cooked corn count box
		if (game.cookArea && game.cookArea.containsPoint && game.cookArea.containsPoint({
			x: x - game.cookArea.x,
			y: y - game.cookArea.y
		})) {
			// Do nothing, prevent interaction
			return;
		}
		// Collect all cooked corn from pot with a single tap on the pot
		var localPotX = x - game.stove.x;
		var localPotY = y - game.stove.y;
		var potW = potAsset.width,
			potH = potAsset.height;
		// Check if tap is inside the pot area
		if (localPotX >= -potW / 2 && localPotX <= potW / 2 && localPotY >= -potH / 2 && localPotY <= potH / 2) {
			var collected = 0;
			// Collect all cooked corns
			for (var i = game.potCorns.length - 1; i >= 0; i--) {
				var c = game.potCorns[i];
				if (c.done) {
					c.asset.destroy();
					game.potCorns.splice(i, 1);
					game.cookArea.addCookedCorn(1);
					collected++;
				}
			}
			if (collected > 0) {
				LK.effects.flashObject(potAsset, 0x05c49c, 200);
			}
			return;
		}
	} else if (game.currentScreen === 2) {
		if (game._draggingPlate) return; // Don't allow other order actions while dragging plate
		// --- 3rd Screen: Customer Start Button tap ---
		if (game.currentScreen === 2 && game.customerStartBtn && typeof game.customerStartBtn.x === "number" && typeof game.customerStartBtn.y === "number" && !game._customerSpawningStarted) {
			var localXcs = x - game.customerStartBtn.x;
			var localYcs = y - game.customerStartBtn.y;
			var wcs = game.customerStartBtn.width || 420;
			var hcs = game.customerStartBtn.height || 140;
			if (localXcs >= -wcs / 2 && localXcs <= wcs / 2 && localYcs >= -hcs / 2 && localYcs <= hcs / 2) {
				// Start customer spawning: spawn first customer immediately, then every 20s
				game._customerSpawningStarted = true;
				if (game.customerStartBtn) game.customerStartBtn.visible = false;
				if (game.customerStartBtnTxt) game.customerStartBtnTxt.visible = false;
				// Spawn first customer immediately
				spawnCustomerOnOrderScreen();
				// Start interval for next customers (every 22s)
				if (game.customerSpawnTimer) LK.clearInterval(game.customerSpawnTimer);
				game._customerSpawnIntervalStarted = true;
				game.customerSpawnTimer = LK.setInterval(spawnCustomerOnOrderScreen, 22000); // always 22s after first
				return;
			}
		}
		// Order screen
		// Prevent interaction with cooked corn count box
		if (game.cookedCornBox && typeof game.cookedCornBox.x === "number" && typeof game.cookedCornBox.y === "number") {
			var localX = x - game.cookedCornBox.x;
			var localY = y - game.cookedCornBox.y;
			var w = 220,
				h = 220;
			if (localX >= -w / 2 && localX <= w / 2 && localY >= -h / 2 && localY <= h / 2) {
				// When cooked corn box is tapped, show a plate on tezgah (if not already present)
				if (!game.tezgahPlate || game.tezgahPlate.destroyed) {
					game.tezgahPlate = new Plate();
					// Center the plate horizontally on the tezgah
					game.tezgahPlate.x = game.counterAsset.x;
					// Place the plate vertically so it sits visually on the tezgah
					game.tezgahPlate.y = game.counterAsset.y - game.counterAsset.height / 2;
					game.addChild(game.tezgahPlate);
					game.tezgahPlate.cornIcons = [];
				}
				// Only move one cooked corn per tap, and use 'corn' asset for the plate
				var cookedCount = game.cookArea && typeof game.cookArea.cookedCorn === "number" ? game.cookArea.cookedCorn : 0;
				// Only add corn to plate if there is a plate present and it is not destroyed
				if (game.tezgahPlate && !game.tezgahPlate.destroyed && cookedCount > 0) {
					// Limit to 4 corns on the plate
					var plateCornCount = 0;
					if (game.tezgahPlate.cornIcons) plateCornCount = game.tezgahPlate.cornIcons.length;
					if (plateCornCount >= 4) {
						LK.effects.flashObject(game.tezgahPlate, 0xff0000, 300);
						return;
					}
					// Remove one cooked corn from cookArea
					if (game.cookArea.removeCookedCorn(1)) {
						// Place a single corn icon (asset: 'corn') on the plate
						var iconW = 80,
							iconH = 80;
						// Place new corn icon at next position in row, centered on plate
						var xOnPlate = game.tezgahPlate.x - 120 + plateCornCount * (iconW + 10);
						var yOnPlate = game.tezgahPlate.y - 10;
						var cornIcon = LK.getAsset('corn', {
							anchorX: 0.5,
							anchorY: 0.5,
							width: iconW,
							height: iconH,
							x: xOnPlate,
							y: yOnPlate
						});
						game.addChild(cornIcon);
						if (!game.tezgahPlate.cornIcons) game.tezgahPlate.cornIcons = [];
						game.tezgahPlate.cornIcons.push(cornIcon);
						// Update cooked corn box text to match new cooked corn count
						if (game.cookedCornBoxTxt) {
							game.cookedCornBoxTxt.setText(game.cookArea.cookedCorn);
						}
					}
				}
				return;
			}
			// --- TezgahBox1: Add ketchup to all corns on plate if tapped ---
			if (game.tezgahBox1 && typeof game.tezgahBox1.x === "number" && typeof game.tezgahBox1.y === "number") {
				var localX1 = x - game.tezgahBox1.x;
				var localY1 = y - game.tezgahBox1.y;
				var w1 = game.tezgahBox1.width || 180;
				var h1 = game.tezgahBox1.height || 180;
				if (localX1 >= -w1 / 2 && localX1 <= w1 / 2 && localY1 >= -h1 / 2 && localY1 <= h1 / 2) {
					// Only if there is at least one corn on the plate
					if (game.tezgahPlate && game.tezgahPlate.cornIcons && game.tezgahPlate.cornIcons.length > 0) {
						// Add ketchup icon on top of every corn on the plate
						for (var i = 0; i < game.tezgahPlate.cornIcons.length; i++) {
							var corn = game.tezgahPlate.cornIcons[i];
							// Prevent double ketchup
							if (!corn._hasKetchup) {
								var ketchupIcon = LK.getAsset('ketchup', {
									anchorX: 0.5,
									anchorY: 0.5,
									width: 40,
									height: 40,
									x: corn.x,
									y: corn.y - 20
								});
								game.addChild(ketchupIcon);
								corn._hasKetchup = true;
								corn._ketchupIcon = ketchupIcon;
							}
						}
					}
					return;
				}
			}
			// --- TezgahBox2: Add mayonnaise to all corns on plate if tapped, under ketchup if present ---
			if (game.tezgahBox2 && typeof game.tezgahBox2.x === "number" && typeof game.tezgahBox2.y === "number") {
				var localX2 = x - game.tezgahBox2.x;
				var localY2 = y - game.tezgahBox2.y;
				var w2 = game.tezgahBox2.width || 180;
				var h2 = game.tezgahBox2.height || 180;
				if (localX2 >= -w2 / 2 && localX2 <= w2 / 2 && localY2 >= -h2 / 2 && localY2 <= h2 / 2) {
					// Only if there is at least one corn on the plate
					if (game.tezgahPlate && game.tezgahPlate.cornIcons && game.tezgahPlate.cornIcons.length > 0) {
						for (var i = 0; i < game.tezgahPlate.cornIcons.length; i++) {
							var corn = game.tezgahPlate.cornIcons[i];
							// Prevent double mayonnaise
							if (!corn._hasMayonnaise) {
								// If ketchup exists, mayonnaise should be under it
								var mayoY = corn.y - 10; // slightly above corn
								var mayoZ = 0;
								if (corn._hasKetchup && corn._ketchupIcon) {
									// Place mayonnaise under ketchup
									mayoY = corn.y - 10; // mayonnaise closer to corn, ketchup above
									mayoZ = 0; // zIndex not supported, so add order: add mayonnaise first, then ketchup
									// Remove and re-add ketchup to ensure it's above mayonnaise
									if (!corn._ketchupIcon.destroyed) {
										corn._ketchupIcon.destroy();
									}
									// Add mayonnaise first
									var mayoIcon = LK.getAsset('mayonnaise', {
										anchorX: 0.5,
										anchorY: 0.5,
										width: 40,
										height: 40,
										x: corn.x,
										y: mayoY
									});
									game.addChild(mayoIcon);
									corn._hasMayonnaise = true;
									corn._mayonnaiseIcon = mayoIcon;
									// Add ketchup again above mayonnaise
									var ketchupIcon = LK.getAsset('ketchup', {
										anchorX: 0.5,
										anchorY: 0.5,
										width: 40,
										height: 40,
										x: corn.x,
										y: corn.y - 20
									});
									game.addChild(ketchupIcon);
									corn._ketchupIcon = ketchupIcon;
									corn._hasKetchup = true;
								} else {
									// No ketchup, just add mayonnaise
									var mayoIcon = LK.getAsset('mayonnaise', {
										anchorX: 0.5,
										anchorY: 0.5,
										width: 40,
										height: 40,
										x: corn.x,
										y: mayoY
									});
									game.addChild(mayoIcon);
									corn._hasMayonnaise = true;
									corn._mayonnaiseIcon = mayoIcon;
								}
							}
						}
					}
					return;
				}
			}
		}
		// Order area removed
	}
};
// --- Plate drag move/up logic ---
game.move = function (x, y, obj) {
	if (game._draggingPlate && game.tezgahPlate && !game.tezgahPlate.destroyed) {
		// Move plate
		game.tezgahPlate.x = x + game._dragPlateOffset.x;
		game.tezgahPlate.y = y + game._dragPlateOffset.y;
		// Move corn icons and ketchup icons with plate
		if (game._dragPlateCornIcons) {
			for (var i = 0; i < game._dragPlateCornIcons.length; i++) {
				var c = game._dragPlateCornIcons[i];
				if (c.icon && !c.icon.destroyed) {
					c.icon.x = game.tezgahPlate.x + c.dx;
					c.icon.y = game.tezgahPlate.y + c.dy;
				}
				if (c.ketchup && !c.ketchup.destroyed) {
					c.ketchup.x = game.tezgahPlate.x + c.dx;
					c.ketchup.y = game.tezgahPlate.y + c.dy - 20;
				}
				if (c.icon && c.icon._mayonnaiseIcon && !c.icon._mayonnaiseIcon.destroyed) {
					c.icon._mayonnaiseIcon.x = game.tezgahPlate.x + c.dx;
					c.icon._mayonnaiseIcon.y = game.tezgahPlate.y + c.dy - 10;
				}
			}
		}
		// Check for intersection with any customer
		if (game.customers) {
			for (var i = 0; i < game.customers.length; i++) {
				var cust = game.customers[i];
				if (cust && cust.visible && !cust.destroyed) {
					// Use bounding box for customer (body/head)
					var custX = cust.x,
						custY = cust.y;
					var custW = 220,
						custH = 320 + 180; // body+head
					var plateX = game.tezgahPlate.x,
						plateY = game.tezgahPlate.y;
					var plateW = 700,
						plateH = 280;
					// Simple AABB collision
					if (plateX + plateW / 2 > custX - custW / 2 && plateX - plateW / 2 < custX + custW / 2 && plateY + plateH / 2 > custY - custH && plateY - plateH / 2 < custY) {
						// Deliver plate to this customer!
						// Check if order matches
						var order = cust.order;
						var deliveredCount = game.tezgahPlate.cornIcons ? game.tezgahPlate.cornIcons.length : 0;
						var deliveredKetchup = 0;
						var deliveredMayonnaise = 0;
						for (var j = 0; j < deliveredCount; j++) {
							if (game.tezgahPlate.cornIcons[j]._hasKetchup) deliveredKetchup++;
							if (game.tezgahPlate.cornIcons[j]._hasMayonnaise) deliveredMayonnaise++;
						}
						var wantKetchup = 0;
						var wantMayonnaise = 0;
						if (order && order.sauces) {
							for (var j = 0; j < order.sauces.length; j++) {
								if (order.sauces[j] === "ketchup") wantKetchup++;
								if (order.sauces[j] === "mayonnaise") wantMayonnaise++;
							}
						}
						var ok = true;
						// Check corn count
						if (!order || deliveredCount !== order.cornCount) ok = false;
						// Check ketchup count (if ketchup is in order, must have at least that many with ketchup)
						if (wantKetchup > deliveredKetchup) ok = false;
						// Check mayonnaise: if customer wants only mayonnaise, all delivered corns must have mayonnaise and none must have ketchup
						if (order && order.sauces.length === 1 && order.sauces[0] === "mayonnaise") {
							// All delivered corns must have mayonnaise and must NOT have ketchup
							for (var j = 0; j < deliveredCount; j++) {
								if (!game.tezgahPlate.cornIcons[j]._hasMayonnaise || game.tezgahPlate.cornIcons[j]._hasKetchup) {
									ok = false;
									break;
								}
							}
						}
						// (If order has no ketchup, allow extra ketchup)
						if (ok) {
							// Success!
							LK.effects.flashObject(cust, 0x00ff00, 400);
							// Calculate coins based on corn count delivered
							var deliveredCoins = 0;
							if (order && order.cornCount === 1) deliveredCoins = 5;else if (order && order.cornCount === 2) deliveredCoins = 10;else if (order && order.cornCount === 3) deliveredCoins = 15;else if (order && order.cornCount === 4) deliveredCoins = 20;else deliveredCoins = 5; // fallback
							game.coins += deliveredCoins;
							game.updateCoins();
							// Fame reward for correct and on-time delivery
							if (typeof game.fame === "number") {
								game.fame += 10;
								if (game.fame > 100) game.fame = 100;
								if (typeof game.updateFame === "function") game.updateFame();
							}
							// Remove corn icons and their sauce icons, but do not destroy the plate itself
							for (var j = 0; j < game.tezgahPlate.cornIcons.length; j++) {
								if (game.tezgahPlate.cornIcons[j]._ketchupIcon && !game.tezgahPlate.cornIcons[j]._ketchupIcon.destroyed) {
									game.tezgahPlate.cornIcons[j]._ketchupIcon.destroy();
								}
								if (game.tezgahPlate.cornIcons[j]._mayonnaiseIcon && !game.tezgahPlate.cornIcons[j]._mayonnaiseIcon.destroyed) {
									game.tezgahPlate.cornIcons[j]._mayonnaiseIcon.destroy();
								}
								if (!game.tezgahPlate.cornIcons[j].destroyed) game.tezgahPlate.cornIcons[j].destroy();
							}
							game.tezgahPlate.cornIcons = [];
							// Remove customer
							if (!cust.destroyed) cust.destroy();
							game.customers[i] = null;
							// Animate plate back to its original position after delivery
							if (_typeof(game._dragPlateStart) === "object" && game.tezgahPlate && !game.tezgahPlate.destroyed) {
								var origX = game._dragPlateStart.x;
								var origY = game._dragPlateStart.y;
								tween(game.tezgahPlate, {
									x: origX,
									y: origY
								}, {
									duration: 400,
									easing: tween.cubicOut
								});
							}
						} else {
							// Wrong order
							LK.effects.flashObject(cust, 0xff0000, 400);
						}
						// End drag
						game._draggingPlate = false;
						game._dragPlateCornIcons = null;
						return;
					}
				}
			}
		}
	}
};
game.up = function (x, y, obj) {
	if (game._draggingPlate) {
		// Snap plate back to original position if not delivered
		if (game.tezgahPlate && !game.tezgahPlate.destroyed) {
			game.tezgahPlate.x = game._dragPlateStart.x;
			game.tezgahPlate.y = game._dragPlateStart.y;
			// Move corn icons and ketchup icons back
			if (game._dragPlateCornIcons) {
				for (var i = 0; i < game._dragPlateCornIcons.length; i++) {
					var c = game._dragPlateCornIcons[i];
					if (c.icon && !c.icon.destroyed) {
						c.icon.x = game.tezgahPlate.x + c.dx;
						c.icon.y = game.tezgahPlate.y + c.dy;
					}
					if (c.ketchup && !c.ketchup.destroyed) {
						c.ketchup.x = game.tezgahPlate.x + c.dx;
						c.ketchup.y = game.tezgahPlate.y + c.dy - 20;
					}
					if (c.icon && c.icon._mayonnaiseIcon && !c.icon._mayonnaiseIcon.destroyed) {
						c.icon._mayonnaiseIcon.x = game.tezgahPlate.x + c.dx;
						c.icon._mayonnaiseIcon.y = game.tezgahPlate.y + c.dy - 10;
					}
				}
			}
		}
		game._draggingPlate = false;
		game._dragPlateCornIcons = null;
	}
};
// --- Game update ---
game.update = function () {
	// Update all fields for grow/ready text
	for (var i = 0; i < game.fields.length; i++) {
		if (game.fields[i].visible) {
			if (typeof game.fields[i].update === "function") {
				game.fields[i].update();
			}
		}
	}
	// Update all customers for leave timers
	if (game.customers) {
		for (var i = 0; i < game.customers.length; i++) {
			if (game.customers[i] && !game.customers[i].destroyed && typeof game.customers[i].update === "function") {
				game.customers[i].update();
			}
		}
	}
	// --- Auto-complete logic: if enabled, auto-complete all possible orders ---
	if (game.autoCompleteEnabled && game.customers && game.currentScreen === 2) {
		for (var i = 0; i < game.customers.length; i++) {
			var cust = game.customers[i];
			if (cust && !cust.destroyed && game.canAutoCompleteOrder && game.autoCompleteOrder) {
				// Try to auto-complete if possible
				if (game.canAutoCompleteOrder(cust)) {
					game.autoCompleteOrder(cust);
				}
			}
		}
	}
	// --- Auto-grow logic: if enabled, plant in all empty unlocked fields ---
	if (game.autoGrowEnabled && typeof game.autoGrowTick === "function" && game.currentScreen === 0) {
		game.autoGrowTick();
	}
	// --- Auto-collect logic: if enabled, harvest all ready unlocked fields ---
	if (game.autoCollectEnabled && typeof game.autoCollectTick === "function" && game.currentScreen === 0) {
		game.autoCollectTick();
	}
	// Update corn box count label live on 2nd screen
	if (game.currentScreen === 1 && typeof game.cornBoxCountLabel !== "undefined" && game.cornBox && typeof game.cornBox.cornCount === "number") {
		game.cornBoxCountLabel.setText(game.cornBox.cornCount + '');
	}
	// Update cooked corn count box on 2nd screen (BoxCook) live
	if (game.currentScreen === 1 && game.cookedCornBox2 && game.cookArea && typeof game.cookArea.cookedCorn === "number") {
		game.cookedCornBox2Txt.setText(game.cookArea.cookedCorn);
		game.cookedCornBox2.visible = true;
	} else if (game.cookedCornBox2) {
		game.cookedCornBox2Txt.setText('');
		game.cookedCornBox2.visible = false;
	}
	// No automatic planting: Corn only grows when planted by the player
	// --- Pot cooking logic ---
	if (game.stove && game.potCorns) {
		var minTimeLeft = null;
		for (var i = 0; i < game.potCorns.length; i++) {
			var c = game.potCorns[i];
			// --- Add timer label above each corn in the pot ---
			if (!c.timerLabel) {
				c.timerLabel = new Text2('', {
					size: 40,
					fill: "#fff"
				});
				c.timerLabel.anchor.set(0.5, 1);
				c.timerLabel.x = c.asset.x;
				c.timerLabel.y = c.asset.y - 50;
				game.stove.addChild(c.timerLabel);
			}
			// Always update label position to follow corn
			c.timerLabel.x = c.asset.x;
			c.timerLabel.y = c.asset.y - 50;
			if (!c.done) {
				// Use permanent reduction for this corn (if present), fallback to 0
				var cookTimeReduce = typeof c.cookTimeReduce === "number" ? c.cookTimeReduce : typeof game.potCookTimeReduce === "number" ? game.potCookTimeReduce : 0;
				var elapsed = Date.now() - c.startTime;
				var left = 30000 - cookTimeReduce - elapsed;
				if (left <= 0) {
					// Done cooking
					c.done = true;
					c.asset.alpha = 1;
					c.asset.tint = 0x05c49c; // cooked color
					LK.effects.flashObject(c.asset, 0x05c49c, 300);
					left = 0;
				} else {
					c.asset.alpha = 0.7;
					c.asset.tint = 0xb8b031; // raw color
				}
				// Show remaining time above corn
				var secLeft = Math.ceil(left / 1000);
				c.timerLabel.setText(secLeft + "s");
				c.timerLabel.visible = true;
				if (minTimeLeft === null || left < minTimeLeft) minTimeLeft = left;
			} else {
				// Hide label above cooked corn (no 'Done' text)
				c.timerLabel.setText('');
				c.timerLabel.visible = false;
			}
			// If the corn asset is destroyed (collected), also destroy the label
			if (c.asset.destroyed && c.timerLabel) {
				c.timerLabel.destroy();
				c.timerLabel = null;
			}
			// Hide "Done" label if corn is not in potCorns anymore (collected)
			if ((!c.asset || c.asset.destroyed) && c.timerLabel) {
				c.timerLabel.visible = false;
			}
			// Remove global pot timer text (game.potTimerTxt) so only per-corn timers are shown
			game.potTimerTxt.setText('');
			game.potTimerTxt.visible = false;
		}
		// Remove all other pot timer text except per-corn timers on 2nd screen
		// (No global pot timer text on 2nd screen)
		// Remove timer labels for any corns that have been removed from potCorns
		for (var i = game.potCorns.length - 1; i >= 0; i--) {
			var c = game.potCorns[i];
			if (c.asset.destroyed && c.timerLabel) {
				c.timerLabel.destroy();
				c.timerLabel = null;
			}
		}
	}
	// Show pot lid only if there are corns in the pot
	if (typeof potLid !== "undefined" && typeof game.potCorns !== "undefined") {
		if (game.potCorns.length > 0) {
			potLid.visible = true;
		} else {
			potLid.visible = false;
		}
	}
	// Hide corn box above pot while pot is cooking, show it again when pot is empty
	if (typeof game.cornBox !== "undefined") {
		if (game.potCorns && game.potCorns.length > 0) {
			game.cornBox.visible = false;
			if (typeof game.cornBoxLabel !== "undefined") game.cornBoxLabel.visible = false;
			if (typeof game.cornBoxCountLabel !== "undefined") game.cornBoxCountLabel.visible = false;
		} else {
			// Only show on boxcook screen
			if (game.currentScreen === 1) {
				game.cornBox.visible = true;
				if (typeof game.cornBoxLabel !== "undefined") game.cornBoxLabel.visible = true;
				if (typeof game.cornBoxCountLabel !== "undefined") game.cornBoxCountLabel.visible = true;
			}
		}
	}
	// Update cooked corn count box value live on order screen
	if (game.currentScreen === 2 && game.cookedCornBox && game.cookArea && typeof game.cookArea.cookedCorn === "number") {
		game.cookedCornBoxTxt.setText(game.cookArea.cookedCorn);
		game.cookedCornBox.visible = true;
	} else if (game.cookedCornBox) {
		// Hide or clear cooked corn count on other screens
		game.cookedCornBoxTxt.setText('');
		game.cookedCornBox.visible = false;
	}
};
// --- Reset function for new game ---
game.resetGame = function () {
	// Destroy tezgah plate and its corn icons if present
	if (game.tezgahPlate) {
		if (game.tezgahPlate.cornIcons) {
			for (var i = 0; i < game.tezgahPlate.cornIcons.length; i++) {
				var c = game.tezgahPlate.cornIcons[i];
				if (c._ketchupIcon && !c._ketchupIcon.destroyed) c._ketchupIcon.destroy();
				if (c._mayonnaiseIcon && !c._mayonnaiseIcon.destroyed) c._mayonnaiseIcon.destroy();
				if (!c.destroyed) c.destroy();
			}
		}
		if (!game.tezgahPlate.destroyed) game.tezgahPlate.destroy();
		game.tezgahPlate = null;
	}
	// Reset clock to 08:00
	game.clockHour = 8;
	game.clockMinute = 0;
	game.clockTime = 8 * 60;
	game.clockRunning = true;
	game.day = 1;
	if (typeof clockTxt !== "undefined") clockTxt.setText('08:00');
	if (typeof dayTxt !== "undefined") dayTxt.setText('Day: ' + game.day);
	game.coins = 20;
	game.unlockedFields = 4;
	game.seeds = 4;
	game.fame = 0;
	if (typeof game.updateFame === "function") game.updateFame();
	if (typeof game.updateSeeds === "function") game.updateSeeds();
	game.updateCoins();
	updateFieldLocks();
	layoutFields();
	updateUnlockBtn();
	for (var i = 0; i < game.fields.length; i++) {
		game.fields[i].reset();
	}
	game.cornBox.reset();
	game.cookArea.reset();
	// Reset permanent pot cook time reduction
	game.potCookTimeReduce = 0;
	// Reset stove/pot
	if (game.potCorns) {
		for (var i = 0; i < game.potCorns.length; i++) {
			if (game.potCorns[i].asset) game.potCorns[i].asset.destroy();
		}
		game.potCorns = [];
	}
	if (game.potTimerTxt) game.potTimerTxt.setText('');
	// game.orderArea.reset();
	// game.orderArea.newOrder();
	// Reset to help screen and update visibility
	game.currentScreen = 4;
	game.clockRunning = false;
	// Remove all customers on reset (they will be spawned by timer on 3rd screen)
	if (game.customers) {
		for (var i = 0; i < game.customers.length; i++) {
			if (game.customers[i] && !game.customers[i].destroyed) {
				game.customers[i].destroy();
			}
		}
		game.customers = [];
	}
	// Hide and destroy unlock4BtnContainer and label if more than 4 fields are unlocked after reset
	if (game.unlockedFields > 4) {
		if (unlock4BtnContainer && !unlock4BtnContainer.destroyed) {
			unlock4BtnContainer.destroy();
		}
		if (unlock4Txt && !unlock4Txt.destroyed) {
			unlock4Txt.destroy();
		}
		unlock4Btn.alpha = 0.3;
	}
	updateScreenVisibility();
};
// --- Asset definitions (for static analysis) ---
// These are not real code, but LK will auto-create these assets as used above:
// field: green box, corn: yellow ellipse, lock: gray lock, box: brown box, cook: pot, cooked: orange ellipse, order: tray, ketchup/mayonnaise/cheese: colored circles, deliver: blue button, unlock: green button
// --- End of code --- /**** 
* Plugins
****/ 
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/**** 
* Classes
****/ 
// CookArea: Cooks raw corn, can be tapped to cook, then send to order area
var CookArea = Container.expand(function () {
	var self = Container.call(this);
	self.rawCorn = 0;
	self.cookedCorn = 0;
	// Cooked corn icon
	var cookedAsset = self.attachAsset('cooked', {
		anchorX: 0.5,
		anchorY: 0.5,
		alpha: 0
	});
	cookedAsset.width = 120;
	cookedAsset.height = 120;
	// Texts
	var rawTxt = new Text2('0', {
		size: 60,
		fill: "#fff"
	});
	rawTxt.anchor.set(0.5, 0.2);
	self.addChild(rawTxt);
	// cookedTxt removed: cooked corn count text is not shown on 2nd screen
	self.addRawCorn = function (n) {
		self.rawCorn += n;
		rawTxt.setText(self.rawCorn);
	};
	self.removeRawCorn = function (n) {
		if (self.rawCorn >= n) {
			self.rawCorn -= n;
			rawTxt.setText(self.rawCorn);
			return true;
		}
		return false;
	};
	self.addCookedCorn = function (n) {
		self.cookedCorn += n;
		// cookedTxt.setText(self.cookedCorn); // removed
		cookedAsset.alpha = 1;
		LK.effects.flashObject(cookedAsset, 0xffb347, 200);
	};
	self.removeCookedCorn = function (n) {
		if (self.cookedCorn >= n) {
			self.cookedCorn -= n;
			// cookedTxt.setText(self.cookedCorn); // removed
			if (self.cookedCorn === 0) cookedAsset.alpha = 0;
			return true;
		}
		return false;
	};
	self.down = function (x, y, obj) {
		if (self.rawCorn > 0) {
			// Cook one corn (takes time)
			self.removeRawCorn(1);
			LK.setTimeout(function () {
				self.addCookedCorn(1);
			}, game.cookTime);
		} else if (self.cookedCorn > 0) {
			// Send cooked corn to order area
			var globalCook = self.toGlobal({
				x: 0,
				y: 0
			});
			var orderPos = game.cookArea.getGlobalCenter();
			var flyingCorn = LK.getAsset('cooked', {
				anchorX: 0.5,
				anchorY: 0.5,
				x: globalCook.x,
				y: globalCook.y,
				width: 100,
				height: 100
			});
			game.addChild(flyingCorn);
			tween(flyingCorn, {
				x: orderPos.x,
				y: orderPos.y,
				alpha: 0.2
			}, {
				duration: 500,
				easing: tween.cubicOut,
				onFinish: function onFinish() {
					flyingCorn.destroy();
					if (self.removeCookedCorn(1)) {
						game.orderArea.addCorn(1);
					}
				}
			});
		}
	};
	self.getGlobalCenter = function () {
		var pos = self.toGlobal({
			x: 0,
			y: 0
		});
		return {
			x: pos.x,
			y: pos.y
		};
	};
	self.reset = function () {
		self.rawCorn = 0;
		self.cookedCorn = 0;
		rawTxt.setText('0');
		// cookedTxt.setText('0'); // removed
		cookedAsset.alpha = 0;
	};
	// Add containsPoint method to CookArea
	self.containsPoint = function (point) {
		// Convert global point to local coordinates of the CookArea
		var localX = point.x - self.x;
		var localY = point.y - self.y;
		// cookAsset is removed, so use cookedAsset for bounds
		var w = cookedAsset.width;
		var h = cookedAsset.height;
		// Check if localX, localY is inside cookedAsset bounds
		return localX >= -w / 2 && localX <= w / 2 && localY >= -h / 2 && localY <= h / 2;
	};
	return self;
});
// CornBox: Stores harvested corn, can be tapped to send to cook area
var CornBox = Container.expand(function () {
	var self = Container.call(this);
	var boxAsset = self.attachAsset('box', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	boxAsset.width = 220;
	boxAsset.height = 220;
	self.cornCount = 0;
	// Corn count text
	var cornTxt = new Text2('0', {
		size: 80,
		fill: 0xFFF700
	});
	cornTxt.anchor.set(0.5, 0.5);
	self.addChild(cornTxt);
	self.addCorn = function (n) {
		self.cornCount += n;
		cornTxt.setText(self.cornCount);
		LK.effects.flashObject(boxAsset, 0xffff00, 200);
	};
	self.removeCorn = function (n) {
		if (self.cornCount >= n) {
			self.cornCount -= n;
			cornTxt.setText(self.cornCount);
			return true;
		}
		return false;
	};
	self.down = function (x, y, obj) {
		if (self.cornCount > 0) {
			// Animate corn to cook area
			var globalBox = self.toGlobal({
				x: 0,
				y: 0
			});
			var cookPos = game.cookArea.getGlobalCenter();
			var flyingCorn = LK.getAsset('corn', {
				anchorX: 0.5,
				anchorY: 0.5,
				x: globalBox.x,
				y: globalBox.y,
				width: 100,
				height: 100
			});
			game.addChild(flyingCorn);
			tween(flyingCorn, {
				x: cookPos.x,
				y: cookPos.y,
				alpha: 0.2
			}, {
				duration: 500,
				easing: tween.cubicOut,
				onFinish: function onFinish() {
					flyingCorn.destroy();
					if (self.removeCorn(1)) {
						game.cookArea.addRawCorn(1);
					}
				}
			});
		}
	};
	self.getGlobalCenter = function () {
		var pos = self.toGlobal({
			x: 0,
			y: 0
		});
		return {
			x: pos.x,
			y: pos.y
		};
	};
	self.reset = function () {
		self.cornCount = 0;
		cornTxt.setText('0');
	};
	// Add containsPoint method to CornBox
	self.containsPoint = function (point) {
		// Convert global point to local coordinates of the CornBox
		var localX = point.x - self.x;
		var localY = point.y - self.y;
		// boxAsset is centered at (0,0) with anchor 0.5,0.5
		var w = boxAsset.width;
		var h = boxAsset.height;
		// Check if localX, localY is inside boxAsset bounds
		return localX >= -w / 2 && localX <= w / 2 && localY >= -h / 2 && localY <= h / 2;
	};
	return self;
});
// CornField: Represents a single field where corn can be planted, grown, and harvested
var CornField = Container.expand(function () {
	var self = Container.call(this);
	// States: 'empty', 'growing', 'ready'
	self.state = 'empty';
	self.index = 0; // set by game
	self.cornType = null; // for future upgrades
	// Field asset
	var fieldAsset = self.attachAsset('field', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	fieldAsset.width = 320;
	fieldAsset.height = 320;
	// Corn asset (hidden unless growing/ready)
	var cornAsset = self.attachAsset('corn', {
		anchorX: 0.5,
		anchorY: 0.5,
		alpha: 0
	});
	cornAsset.width = 180;
	cornAsset.height = 180;
	// Grow time/ready text above corn
	var growTxt = new Text2('', {
		size: 60,
		fill: "#fff"
	});
	growTxt.anchor.set(0.5, 1);
	growTxt.x = 0;
	growTxt.y = -120;
	self.addChild(growTxt);
	// Cooldown text above field (for replant cooldown)
	var cooldownTxt = new Text2('', {
		size: 60,
		fill: 0xFF4444
	});
	cooldownTxt.anchor.set(0.5, 1);
	cooldownTxt.x = 0;
	cooldownTxt.y = -180;
	self.addChild(cooldownTxt);
	// Track grow start time for countdown
	self._growStart = null;
	self._growEnd = null;
	// Show field as locked if not unlocked
	var lockAsset = self.attachAsset('lock', {
		anchorX: 0.5,
		anchorY: 0.5,
		alpha: 0
	});
	lockAsset.width = 120;
	lockAsset.height = 120;
	// Track how many times this field has been planted
	self.plantCount = 0;
	// Plant corn if field is empty
	self.down = function (x, y, obj) {
		if (self.state === 'empty' && !self.locked) {
			if (self._replantCooldown) {
				// Show cooldown visually
				LK.effects.flashObject(fieldAsset, 0xff0000, 200);
				return;
			}
			// Only allow planting if there are seeds left
			if (typeof game.seeds === "undefined" || game.seeds <= 0) {
				LK.effects.flashObject(fieldAsset, 0xff0000, 300);
				return;
			}
			// Decrement seed count and update display
			game.seeds--;
			if (typeof game.updateSeeds === "function") game.updateSeeds();
			self.plant();
		} else if (self.locked) {
			// Try to unlock if enough coins
			if (game.coins >= game.unlockCost) {
				game.coins -= game.unlockCost;
				self.unlock();
				game.updateCoins();
			} else {
				LK.effects.flashObject(lockAsset, 0xff0000, 500);
			}
		} else if (self.state === 'ready') {
			self.harvest();
		}
	};
	self.plant = function () {
		self.state = 'growing';
		cornAsset.alpha = 1;
		cornAsset.scaleX = 0.5;
		cornAsset.scaleY = 0.5;
		tween(cornAsset, {
			scaleX: 1,
			scaleY: 1
		}, {
			duration: 400,
			easing: tween.easeOut
		});
		// Calculate grow time: 5s for first, +1s for each subsequent plant, but reset to 5s after 10s
		if (typeof self.plantCount !== "number") self.plantCount = 0;
		var growTime = 5000 + self.plantCount * 1000;
		if (growTime > 10000) growTime = 5000;
		self.plantCount++;
		// Start grow timer
		self._growStart = Date.now();
		self._growEnd = self._growStart + growTime;
		growTxt.setText(Math.ceil(growTime / 1000));
		self.growTimeout = LK.setTimeout(function () {
			self.state = 'ready';
			self._growStart = null;
			self._growEnd = null;
			growTxt.setText('ready');
			LK.effects.flashObject(cornAsset, 0xffff00, 400);
		}, growTime);
	};
	self.harvest = function () {
		if (self.state !== 'ready') return;
		self.state = 'empty';
		cornAsset.alpha = 0;
		growTxt.setText('');
		self._growStart = null;
		self._growEnd = null;
		// Animate corn flying to box
		var globalCorn = self.toGlobal({
			x: 0,
			y: 0
		});
		var boxPos = game.cornBox.getGlobalCenter();
		var flyingCorn = LK.getAsset('corn', {
			anchorX: 0.5,
			anchorY: 0.5,
			x: globalCorn.x,
			y: globalCorn.y,
			width: 120,
			height: 120
		});
		game.addChild(flyingCorn);
		tween(flyingCorn, {
			x: boxPos.x,
			y: boxPos.y,
			alpha: 0.2
		}, {
			duration: 600,
			easing: tween.cubicOut,
			onFinish: function onFinish() {
				flyingCorn.destroy();
				game.cornBox.addCorn(1);
				// Increase seeds by 2 for each harvested corn
				if (typeof game.seeds === "number") {
					game.seeds += 2;
					if (typeof game.updateSeeds === "function") game.updateSeeds();
				}
			}
		});
		// Start replant cooldown: prevent planting for 5 seconds
		self._replantCooldown = true;
		cooldownTxt.setText('5');
		var cooldownLeft = 5;
		self._replantCooldownTimer = LK.setInterval(function () {
			cooldownLeft--;
			if (cooldownLeft > 0) {
				cooldownTxt.setText('' + cooldownLeft);
			} else {
				LK.clearInterval(self._replantCooldownTimer);
				self._replantCooldown = false;
				cooldownTxt.setText('');
			}
		}, 1000);
	};
	self.locked = false;
	self.lock = function () {
		self.locked = true;
		lockAsset.alpha = 1;
		fieldAsset.alpha = 0.4;
		cornAsset.alpha = 0;
		self.state = 'empty';
	};
	self.unlock = function () {
		self.locked = false;
		lockAsset.alpha = 0;
		fieldAsset.alpha = 1;
	};
	self.setLocked = function (locked) {
		if (locked) {
			self.lock();
			fieldAsset.alpha = 0.4;
		} else {
			self.unlock();
			fieldAsset.alpha = 1;
		}
	};
	self.reset = function () {
		self.state = 'empty';
		cornAsset.alpha = 0;
		if (self.growTimeout) LK.clearTimeout(self.growTimeout);
		growTxt.setText('');
		self._growStart = null;
		self._growEnd = null;
		self.plantCount = 0;
		if (self._replantCooldownTimer) LK.clearInterval(self._replantCooldownTimer);
		self._replantCooldown = false;
		cooldownTxt.setText('');
	};
	// Update method for grow/ready text
	self.update = function () {
		if (self.state === 'growing' && self._growStart && self._growEnd) {
			var now = Date.now();
			var remain = Math.max(0, Math.ceil((self._growEnd - now) / 1000));
			if (remain > 0) {
				growTxt.setText(remain);
			} else {
				growTxt.setText('ready');
			}
		} else if (self.state === 'ready') {
			growTxt.setText('ready');
		} else {
			growTxt.setText('');
		}
		// Show/hide cooldown text depending on replant cooldown
		if (self._replantCooldown) {
			// cooldownTxt is already updated in the interval
			cooldownTxt.visible = true;
		} else {
			cooldownTxt.visible = false;
		}
	};
	// Add containsPoint method to CornField
	self.containsPoint = function (point) {
		// Convert global point to local coordinates of the field
		var localX = point.x - self.x;
		var localY = point.y - self.y;
		// fieldAsset is centered at (0,0) with anchor 0.5,0.5
		var w = fieldAsset.width;
		var h = fieldAsset.height;
		// Check if localX, localY is inside fieldAsset bounds
		return localX >= -w / 2 && localX <= w / 2 && localY >= -h / 2 && localY <= h / 2;
	};
	return self;
});
// Customer: Represents a customer standing in front of the tezgah (counter)
var Customer = Container.expand(function () {
	var self = Container.call(this);
	// Body (ellipse, new asset)
	var body = self.attachAsset('humanBody', {
		anchorX: 0.5,
		anchorY: 1,
		y: 0,
		width: 220,
		height: 320,
		alpha: 1
	});
	// Head (unique customer head)
	var head = self.attachAsset('customerHead', {
		anchorX: 0.5,
		anchorY: 1,
		y: -260,
		width: 180,
		height: 180,
		alpha: 1
	});
	// Left hand (ellipse, new asset)
	var leftHand = self.attachAsset('humanHand', {
		anchorX: 0.5,
		anchorY: 1,
		x: -90,
		y: -100,
		width: 80,
		height: 80,
		alpha: 1
	});
	// Right hand (ellipse, new asset)
	var rightHand = self.attachAsset('humanHand', {
		anchorX: 0.5,
		anchorY: 1,
		x: 90,
		y: -100,
		width: 80,
		height: 80,
		alpha: 1
	});
	// Speech bubble to the right of the customer (use new decorative asset instead of old box)
	// Make the bubble much larger
	self.speechBubble = self.attachAsset('speechBubbleDeco', {
		anchorX: 0,
		anchorY: 0.5,
		x: 120,
		y: -320,
		// move up to fit larger bubble
		width: 520,
		// much wider
		height: 260,
		// much taller
		alpha: 0.92
	});
	// Order text centered on top of the speech bubble
	self.orderText = new Text2('', {
		size: 38,
		// much smaller text to fit inside bubble
		fill: "#222"
	});
	self.orderText.anchor.set(0.5, 0);
	// Center horizontally, place at the top edge of the bubble
	self.orderText.x = self.speechBubble.x + self.speechBubble.width / 2;
	self.orderText.y = self.speechBubble.y - self.speechBubble.height / 2 + 24; // 24px margin from top
	self.addChild(self.speechBubble);
	self.addChild(self.orderText);
	// --- Leave timer label above head ---
	self.leaveTime = 10; // seconds left before leaving
	self._leaveStart = null;
	self._leaveEnd = null;
	self.leaveTimerLabel = new Text2('', {
		size: 60,
		fill: 0xFF4444
	});
	self.leaveTimerLabel.anchor.set(0.5, 0.5);
	// Place directly in the center of the head
	self.leaveTimerLabel.x = head.x;
	self.leaveTimerLabel.y = head.y - head.height / 2;
	self.addChild(self.leaveTimerLabel);
	// Set order and update label
	self.setOrder = function (orderObj) {
		self.order = orderObj;
		if (orderObj && orderObj.sauces && orderObj.sauces.length > 0) {
			// Show corn count and sauces
			var txt = '';
			if (orderObj.cornCount && orderObj.cornCount > 1) {
				txt += orderObj.cornCount + 'x ';
			} else {
				txt += '1x ';
			}
			for (var i = 0; i < orderObj.sauces.length; i++) {
				txt += orderObj.sauces[i];
				if (i < orderObj.sauces.length - 1) txt += ', ';
			}
			self.orderText.setText(txt);
			self.speechBubble.visible = true;
			self.orderText.visible = true;
		} else {
			self.orderText.setText('');
			self.speechBubble.visible = false;
			self.orderText.visible = false;
		}
		// Reset leave timer when new order is set
		self.leaveTime = 10;
		self._leaveStart = Date.now();
		self._leaveEnd = self._leaveStart + 10000;
		self.leaveTimerLabel.visible = true;
		self.leaveTimerLabel.setText('10');
	};
	// Update method for leave timer
	self.update = function () {
		// Only show timer if visible and on order screen
		if (!self.visible || game.currentScreen !== 2) {
			self.leaveTimerLabel.visible = false;
			return;
		}
		// If leave timer is running
		if (self._leaveStart && self._leaveEnd) {
			var now = Date.now();
			var remain = Math.max(0, Math.ceil((self._leaveEnd - now) / 1000));
			if (remain > 0) {
				self.leaveTimerLabel.setText(remain + '');
				self.leaveTimerLabel.visible = true;
			} else {
				self.leaveTimerLabel.setText('0');
				self.leaveTimerLabel.visible = true;
				// Customer leaves: destroy self, clear from game.customers
				if (!self.destroyed) {
					// Fame penalty for missed order
					if (typeof game.fame === "number") {
						game.fame -= 5;
						if (typeof game.updateFame === "function") game.updateFame();
					}
					self.destroy();
					// Remove from game.customers array
					for (var i = 0; i < game.customers.length; i++) {
						if (game.customers[i] === self) {
							game.customers[i] = null;
							break;
						}
					}
					// Update customer spawn interval based on fame
					if (typeof game.updateCustomerSpawnRate === "function") {
						game.updateCustomerSpawnRate();
					}
				}
			}
		} else {
			self.leaveTimerLabel.visible = false;
		}
	};
	return self;
});
// OrderArea: Handles customer orders, sauces, and delivery
var OrderArea = Container.expand(function () {
	var self = Container.call(this);
	var orderAsset = self.attachAsset('order', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	orderAsset.width = 260;
	orderAsset.height = 260;
	self.cornCount = 0;
	self.currentOrder = null;
	self.sauces = ['ketchup', 'mayonnaise'];
	self.selectedSauces = [];
	// Corn icon
	var cornAsset = self.attachAsset('cooked', {
		anchorX: 0.5,
		anchorY: 0.5,
		alpha: 0
	});
	cornAsset.width = 120;
	cornAsset.height = 120;
	// Order text
	var orderTxt = new Text2('', {
		size: 50,
		fill: "#fff"
	});
	orderTxt.anchor.set(0.5, 0.1);
	self.addChild(orderTxt);
	// Sauce icons
	self.sauceIcons = [];
	for (var i = 0; i < self.sauces.length; i++) {
		var s = self.sauces[i];
		var icon = self.attachAsset(s, {
			anchorX: 0.5,
			anchorY: 0.5,
			x: -60 + i * 60,
			y: 80,
			alpha: 0.5
		});
		icon.width = 60;
		icon.height = 60;
		icon.sauce = s;
		// Add containsPoint method to each sauce icon
		icon.containsPoint = function (point) {
			// point is relative to OrderArea, icon.x/y is relative to OrderArea
			var localX = point.x - icon.x;
			var localY = point.y - icon.y;
			var w = icon.width,
				h = icon.height;
			return localX >= -w / 2 && localX <= w / 2 && localY >= -h / 2 && localY <= h / 2;
		};
		self.sauceIcons.push(icon);
	}
	// Delivery button
	var deliverBtn = self.attachAsset('deliver', {
		anchorX: 0.5,
		anchorY: 0.5,
		x: 0,
		y: 120,
		alpha: 0.7
	});
	deliverBtn.width = 100;
	deliverBtn.height = 60;
	// Add containsPoint method to deliverBtn for hit testing
	deliverBtn.containsPoint = function (point) {
		var localX = point.x - deliverBtn.x;
		var localY = point.y - deliverBtn.y;
		var w = deliverBtn.width;
		var h = deliverBtn.height;
		return localX >= -w / 2 && localX <= w / 2 && localY >= -h / 2 && localY <= h / 2;
	};
	// Add corn to order area
	self.addCorn = function (n) {
		self.cornCount += n;
		cornAsset.alpha = 1;
		LK.effects.flashObject(cornAsset, 0xffb347, 200);
		self.updateOrderText();
	};
	self.removeCorn = function (n) {
		if (self.cornCount >= n) {
			self.cornCount -= n;
			if (self.cornCount === 0) cornAsset.alpha = 0;
			self.updateOrderText();
			return true;
		}
		return false;
	};
	self.updateOrderText = function () {
		if (!self.currentOrder) {
			orderTxt.setText('');
			return;
		}
		var txt = 'Order: ';
		for (var i = 0; i < self.currentOrder.sauces.length; i++) {
			txt += self.currentOrder.sauces[i];
			if (i < self.currentOrder.sauces.length - 1) txt += ', ';
		}
		orderTxt.setText(txt);
	};
	self.newOrder = function () {
		// Random sauces (1-3)
		var n = 1 + Math.floor(Math.random() * self.sauces.length);
		var sauces = [];
		var used = {};
		while (sauces.length < n) {
			var idx = Math.floor(Math.random() * self.sauces.length);
			var s = self.sauces[idx];
			if (!used[s]) {
				sauces.push(s);
				used[s] = true;
			}
		}
		self.currentOrder = {
			sauces: sauces
		};
		self.selectedSauces = [];
		self.updateOrderText();
		for (var i = 0; i < self.sauceIcons.length; i++) {
			self.sauceIcons[i].alpha = 0.5;
		}
	};
	// Sauce selection
	self.sauceDown = function (sauce) {
		if (!self.currentOrder) return;
		if (self.selectedSauces.length >= self.currentOrder.sauces.length) return;
		if (self.selectedSauces.indexOf(sauce) !== -1) return;
		self.selectedSauces.push(sauce);
		for (var i = 0; i < self.sauceIcons.length; i++) {
			if (self.sauceIcons[i].sauce === sauce) {
				self.sauceIcons[i].alpha = 1;
			}
		}
	};
	// Deliver order
	self.deliver = function () {
		if (!self.currentOrder) return;
		if (self.cornCount < 1) return;
		// Check sauces
		var ok = true;
		for (var i = 0; i < self.currentOrder.sauces.length; i++) {
			if (self.selectedSauces.indexOf(self.currentOrder.sauces[i]) === -1) {
				ok = false;
				break;
			}
		}
		if (ok && self.selectedSauces.length === self.currentOrder.sauces.length) {
			// Success
			self.removeCorn(1);
			LK.effects.flashObject(orderAsset, 0x00ff00, 400);
			game.coins += game.orderReward;
			game.updateCoins();
			self.currentOrder = null;
			self.selectedSauces = [];
			LK.setTimeout(function () {
				self.newOrder();
			}, 800);
		} else {
			// Wrong sauces
			LK.effects.flashObject(orderAsset, 0xff0000, 400);
			self.selectedSauces = [];
			for (var i = 0; i < self.sauceIcons.length; i++) {
				self.sauceIcons[i].alpha = 0.5;
			}
		}
	};
	// Event handling
	self.down = function (x, y, obj) {
		// Check if sauce icon tapped
		for (var i = 0; i < self.sauceIcons.length; i++) {
			var icon = self.sauceIcons[i];
			if (icon.containsPoint({
				x: x - self.x,
				y: y - self.y
			})) {
				self.sauceDown(icon.sauce);
				return;
			}
		}
		// Check if deliver button tapped
		if (deliverBtn.containsPoint({
			x: x - self.x,
			y: y - self.y
		})) {
			self.deliver();
			return;
		}
	};
	self.getGlobalCenter = function () {
		var pos = self.toGlobal({
			x: 0,
			y: 0
		});
		return {
			x: pos.x,
			y: pos.y
		};
	};
	self.reset = function () {
		self.cornCount = 0;
		self.currentOrder = null;
		self.selectedSauces = [];
		cornAsset.alpha = 0;
		self.updateOrderText();
		for (var i = 0; i < self.sauceIcons.length; i++) {
			self.sauceIcons[i].alpha = 0.5;
		}
	};
	// Add containsPoint method to OrderArea
	self.containsPoint = function (point) {
		// Convert global point to local coordinates of the OrderArea
		var localX = point.x - self.x;
		var localY = point.y - self.y;
		// orderAsset is centered at (0,0) with anchor 0.5,0.5
		var w = orderAsset.width;
		var h = orderAsset.height;
		// Check if localX, localY is inside orderAsset bounds
		return localX >= -w / 2 && localX <= w / 2 && localY >= -h / 2 && localY <= h / 2;
	};
	return self;
});
// unique plate asset for tezgah
// Plate: Represents a plate to be shown on tezgah when cooked corn box is tapped
var Plate = Container.expand(function () {
	var self = Container.call(this);
	var plateAsset = self.attachAsset('plate', {
		anchorX: 0.5,
		anchorY: 0.5,
		width: 700,
		height: 280,
		x: 0,
		y: 0,
		alpha: 1
	});
	// Optionally add more visuals or logic here
	return self;
});
/**** 
* Initialize Game
****/ 
var game = new LK.Game({
	backgroundColor: 0x2e7d32
});
/**** 
* Game Code
****/ 
// New assets for human body and hands
// New tezgah (counter) asset for 3rd screen
// --- Game constants ---
// Unique assets for stove and pot
// cook asset re-added
// Background for 3rd (order) screen
function _typeof(o) {
	"@babel/helpers - typeof";
	return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
		return typeof o;
	} : function (o) {
		return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
	}, _typeof(o);
}
game.cornGrowTime = 5000; // ms
game.cookTime = 2000; // ms
game.orderReward = 5;
game.unlockCost = 20;
game.maxFields = 8;
// --- Game state ---
game.coins = 0;
game.unlockedFields = 4;
game.seeds = 4; // Başlangıçta 4 tohumumuz var
// --- UI: Seeds display (always visible, top center, not in top left 100x100) ---
var seedsTxt = new Text2('Seeds: ' + game.seeds, {
	size: 80,
	fill: 0xFFF700
});
seedsTxt.anchor.set(0.5, 0);
// Move seedsTxt down to avoid the top menu (at least 100px from top), and center horizontally
seedsTxt.x = 2048 / 2;
seedsTxt.y = 140;
LK.gui.top.addChild(seedsTxt);
// Always show seeds count on all screens
seedsTxt.visible = true;
// --- Seed Box for 1st screen (shows number of plantable seeds) ---
game.seedBox = new Container();
var seedBoxAsset = LK.getAsset('box', {
	anchorX: 0.5,
	anchorY: 0.5,
	width: 220,
	height: 220,
	x: 0,
	y: 0,
	alpha: 1
});
game.seedBox.addChild(seedBoxAsset);
// Add English label above the seed box
game.seedBoxLabel = new Text2('Seeds left', {
	size: 40,
	fill: "#fff"
});
game.seedBoxLabel.anchor.set(0.5, 1);
game.seedBoxLabel.x = 0;
game.seedBoxLabel.y = -130;
game.seedBox.addChild(game.seedBoxLabel);
game.seedBoxTxt = new Text2(game.seeds + '', {
	size: 80,
	fill: 0xFFF700
});
game.seedBoxTxt.anchor.set(0.5, 0.5);
game.seedBoxTxt.x = 0;
game.seedBoxTxt.y = 0;
game.seedBox.addChild(game.seedBoxTxt);
// Place seed box at right side, below the seedsTxt, not in top right 100x100
game.seedBox.x = 2048 - 300;
game.seedBox.y = 320;
game.addChild(game.seedBox);
game.seedBox.visible = true; // Only show on field screen
// --- UI: Coins display ---
var coinsTxt = new Text2(game.coins + '$', {
	size: 90,
	fill: 0xFFFDE7
});
coinsTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(coinsTxt);
// --- UI: Clock display (left of coins) ---
game.clockHour = 8;
game.clockMinute = 0;
game.clockTime = 8 * 60; // minutes since 00:00
game.clockRunning = false;
game.day = 1; // Track day count, starts at 1
var clockTxt = new Text2('08:00', {
	size: 90,
	fill: 0xFFFDE7
});
clockTxt.anchor.set(0.5, 0);
// Place clock to the left of coins, with a small gap (e.g. 40px)
// Move it slightly more to the left (e.g. 40px more)
clockTxt.x = coinsTxt.x - 240;
clockTxt.y = coinsTxt.y;
LK.gui.top.addChild(clockTxt);
// --- Fame (Şöhret) ---
// Add dayTxt to the right of fameTxt
game.fame = 0; // Fame starts at 0, max 100
var fameTxt = new Text2('Fame: 0', {
	size: 90,
	fill: 0xFFD700
});
fameTxt.anchor.set(0, 0.0);
// Place fame to the right of coins, with a small gap (e.g. 40px)
fameTxt.x = coinsTxt.x + coinsTxt.width / 2 + 40;
fameTxt.y = coinsTxt.y;
LK.gui.top.addChild(fameTxt);
// Day text, placed to the right of fameTxt
var dayTxt = new Text2('Day: 1', {
	size: 60,
	fill: 0xFFD700
});
dayTxt.anchor.set(0, 0.0);
dayTxt.x = fameTxt.x + fameTxt.width + 100;
dayTxt.y = fameTxt.y;
LK.gui.top.addChild(dayTxt);
// Fame update function
game.updateFame = function () {
	// Fame can go negative, but clamp max to 100
	if (game.fame > 100) game.fame = 100;
	fameTxt.setText('Fame: ' + game.fame);
	if (typeof dayTxt !== "undefined") dayTxt.setText('Day: ' + game.day);
	// Lose the game if fame reaches -50 or less
	if (game.fame <= -50) {
		LK.showGameOver();
	}
};
game.updateFame();
// Bring seedsTxt, coinsTxt, fameTxt to the very front in the GUI overlay
if (typeof LK.gui.top.setChildIndex === "function") {
	LK.gui.top.setChildIndex(seedsTxt, LK.gui.top.children.length - 1);
	LK.gui.top.setChildIndex(coinsTxt, LK.gui.top.children.length - 1);
	LK.gui.top.setChildIndex(fameTxt, LK.gui.top.children.length - 1);
}
// Update seeds display
game.updateSeeds = function () {
	if (typeof seedsTxt !== "undefined") {
		seedsTxt.setText('Seeds: ' + game.seeds);
	}
	if (typeof game.seedBoxTxt !== "undefined") {
		game.seedBoxTxt.setText(game.seeds + '');
	}
};
game.updateCoins = function () {
	coinsTxt.setText(game.coins + '$');
	storage.coins = game.coins;
	storage.unlockedFields = game.unlockedFields;
};
// --- Screen management ---
// Add 5th screen: instructions/help screen
game.screens = ['field', 'boxcook', 'order', 'screen4', 'help'];
game.currentScreen = 4; // 0: field, 1: box/cook, 2: order, 3: screen4, 4: help (instructions)
// --- 5th Screen: Help/Instructions ---
game.helpScreenContainer = new Container();
game.helpScreenBg = LK.getAsset('5screen', {
	anchorX: 0.5,
	anchorY: 0.5,
	width: 2048,
	height: 2732,
	x: 2048 / 2,
	y: 2732 / 2,
	alpha: 1
});
game.helpScreenContainer.addChild(game.helpScreenBg);
// Title
var helpTitle = new Text2('How to Play?', {
	size: 140,
	fill: "#fff"
});
helpTitle.anchor.set(0.5, 0);
helpTitle.x = 2048 / 2;
helpTitle.y = 180;
game.helpScreenContainer.addChild(helpTitle);
// --- Blinking warning note for 5th screen ---
game.helpWarningNote = new Text2("WARNING: No customers will appear until you visit the customer screen. Please keep this in mind.", {
	size: 70,
	fill: 0xFF4444,
	maxWidth: 1800,
	align: "center"
});
game.helpWarningNote.anchor.set(0.5, 0);
game.helpWarningNote.x = 2048 / 2;
game.helpWarningNote.y = 320;
game.helpScreenContainer.addChild(game.helpWarningNote);
// --- New: Blinking auto-start warning note for 5th screen ---
game.autoCustomerWarningNote = new Text2("If you do not press the customer start button by 13:00, the game will start automatically.", {
	size: 70,
	fill: 0xFF4444,
	maxWidth: 1800,
	align: "center"
});
game.autoCustomerWarningNote.anchor.set(0.5, 0);
game.autoCustomerWarningNote.x = 2048 / 2;
// Place below the Start Game button (helpStartBtn), with a margin
if (typeof game.helpStartBtn !== "undefined" && typeof game.helpStartBtn.y === "number" && typeof game.helpStartBtn.height === "number") {
	game.autoCustomerWarningNote.y = game.helpStartBtn.y + game.helpStartBtn.height / 2 + 40;
} else {
	// Fallback: place at a default y if helpStartBtn is not yet defined
	game.autoCustomerWarningNote.y = 2100 + 180 / 2 + 40;
}
game.helpScreenContainer.addChild(game.autoCustomerWarningNote);
// Blinking effect: toggle alpha every 500ms for both warning notes
game._helpWarningBlinkState = true;
game._helpWarningBlinkTimer = LK.setInterval(function () {
	if (game.helpWarningNote) {
		game._helpWarningBlinkState = !game._helpWarningBlinkState;
		game.helpWarningNote.alpha = game._helpWarningBlinkState ? 1 : 0.2;
	}
	if (typeof game.autoCustomerWarningNote !== "undefined" && game.autoCustomerWarningNote !== null && typeof game.autoCustomerWarningNote.alpha !== "undefined") {
		game.autoCustomerWarningNote.alpha = game._helpWarningBlinkState ? 1 : 0.2;
	}
}, 500);
// Instructions (multi-line)
var helpText = new Text2("1. Plant, grow, and harvest corn in the field.\n" + "2. Put the harvested corn into the box.\n" + "3. Take corn from the box and cook it in the pot.\n" + "4. Serve the cooked corn to customers.\n" + "5. Customers want corn with sauces, add the correct sauces.\n" + "6. Unlock new fields and buy automations as you earn more.\n\n" + "Use the left/right arrows to switch between screens.\n\n" + "If your Fame drops to -50, you lose the game!\n" + "If you find any bugs, please write them in the comments below.", {
	size: 80,
	fill: "#fff",
	maxWidth: 1800,
	align: "center"
});
helpText.anchor.set(0.5, 0);
helpText.x = 2048 / 2;
helpText.y = 400;
game.helpScreenContainer.addChild(helpText);
// Add French toggle button above English button (using 'frboxu' asset)
game.frenchBtn = LK.getAsset('frboxu', {
	anchorX: 0.5,
	anchorY: 0.5,
	width: 500,
	height: 120,
	x: 2048 / 2,
	y: 1570,
	// 140px above English button
	alpha: 0.98
});
game.helpScreenContainer.addChild(game.frenchBtn);
game.frenchBtnTxt = new Text2('FRANÇAIS', {
	size: 90,
	fill: "#000"
});
game.frenchBtnTxt.anchor.set(0.5, 0.5);
game.frenchBtnTxt.x = game.frenchBtn.x;
game.frenchBtnTxt.y = game.frenchBtn.y;
game.helpScreenContainer.addChild(game.frenchBtnTxt);
// Add English toggle button above Turkish button (using 'engboxu' asset)
game.englishBtn = LK.getAsset('engboxu', {
	anchorX: 0.5,
	anchorY: 0.5,
	width: 500,
	height: 120,
	x: 2048 / 2,
	y: 1710,
	// 140px above Turkish button
	alpha: 0.98
});
game.helpScreenContainer.addChild(game.englishBtn);
game.englishBtnTxt = new Text2('ENGLISH', {
	size: 90,
	fill: "#000"
});
game.englishBtnTxt.anchor.set(0.5, 0.5);
game.englishBtnTxt.x = game.englishBtn.x;
game.englishBtnTxt.y = game.englishBtn.y;
game.helpScreenContainer.addChild(game.englishBtnTxt);
// Add Turkish toggle button to help screen (now using 'turkboxu' asset)
game.turkceBtn = LK.getAsset('turkboxu', {
	anchorX: 0.5,
	anchorY: 0.5,
	width: 500,
	height: 120,
	x: 2048 / 2,
	y: 1850,
	alpha: 0.98
});
game.helpScreenContainer.addChild(game.turkceBtn);
game.turkceBtnTxt = new Text2('TÜRKÇE', {
	size: 90,
	fill: "#000"
});
game.turkceBtnTxt.anchor.set(0.5, 0.5);
game.turkceBtnTxt.x = game.turkceBtn.x;
game.turkceBtnTxt.y = game.turkceBtn.y;
game.helpScreenContainer.addChild(game.turkceBtnTxt);
// Start button
game.helpStartBtn = LK.getAsset('unlock', {
	anchorX: 0.5,
	anchorY: 0.5,
	width: 600,
	height: 180,
	x: 2048 / 2,
	y: 2100,
	alpha: 0.98
});
game.helpScreenContainer.addChild(game.helpStartBtn);
game.helpStartBtnTxt = new Text2('Start Game', {
	size: 110,
	fill: "#fff"
});
game.helpStartBtnTxt.anchor.set(0.5, 0.5);
game.helpStartBtnTxt.x = game.helpStartBtn.x;
game.helpStartBtnTxt.y = game.helpStartBtn.y;
game.helpScreenContainer.addChild(game.helpStartBtnTxt);
game.addChild(game.helpScreenContainer);
// Turkish text values for all UI
game._turkishTexts = {
	helpTitle: "Nasıl Oynanır?",
	helpText: "1. Tarlada mısır ek, büyüt ve hasat et.\n2. Hasat edilen mısırı kutuya koy.\n3. Kutudan mısırı alıp tencerede pişir.\n4. Pişmiş mısırı müşterilere servis et.\n5. Müşteriler soslu mısır ister, doğru sosları ekle.\n6. Kazandıkça yeni tarlalar aç ve otomasyonlar satın al.\n\nEkranlar arasında geçiş için sol/sağ oklarını kullan.\n\nŞöhretin -50 olursa oyunu kaybedersin!\nBir hata bulursan lütfen aşağıya yoruma yaz.",
	helpStartBtn: "Oyuna Başla",
	turkceBtn: "TÜRKÇE",
	seedsTxt: "Tohum: ",
	seedBoxLabel: "Kalan Tohum",
	cornBoxLabel: "Kutudaki Mısır",
	coinsTxt: "₺",
	fameTxt: "Şöhret: ",
	dayTxt: "Gün: ",
	unlock4Txt: "4 Tarla Aç (20₺)",
	leftTxt: "<",
	rightTxt: ">",
	autoCompleteBtnTxt: "Siparişleri Otomatik Doldur (100₺)",
	autoGrowBtnTxt: "Mısırı Otomatik Büyüt (50₺)",
	autoCollectBtnTxt: "Otomatik Topla (50₺)",
	potReduceBoxTxt: "Pişirme Süresini 10sn Kısalt (50₺)"
};
// Function to switch all texts to Turkish
game.setTurkishTexts = function () {
	// Help screen
	if (typeof helpTitle !== "undefined") helpTitle.setText(game._turkishTexts.helpTitle);
	if (typeof helpText !== "undefined") helpText.setText(game._turkishTexts.helpText);
	if (typeof game.helpStartBtnTxt !== "undefined") game.helpStartBtnTxt.setText(game._turkishTexts.helpStartBtn);
	if (typeof game.turkceBtnTxt !== "undefined") game.turkceBtnTxt.setText(game._turkishTexts.turkceBtn);
	// Top bar
	if (typeof seedsTxt !== "undefined") seedsTxt.setText(game._turkishTexts.seedsTxt + game.seeds);
	if (typeof coinsTxt !== "undefined") coinsTxt.setText(game.coins + game._turkishTexts.coinsTxt);
	if (typeof fameTxt !== "undefined") fameTxt.setText(game._turkishTexts.fameTxt + game.fame);
	if (typeof dayTxt !== "undefined") dayTxt.setText(game._turkishTexts.dayTxt + game.day);
	// Seed box
	if (typeof game.seedBoxLabel !== "undefined") game.seedBoxLabel.setText(game._turkishTexts.seedBoxLabel);
	if (typeof game.seedBoxTxt !== "undefined") game.seedBoxTxt.setText(game.seeds + '');
	// Corn box
	if (typeof game.cornBoxLabel !== "undefined") game.cornBoxLabel.setText(game._turkishTexts.cornBoxLabel);
	// Unlock 4 fields
	if (typeof unlock4Txt !== "undefined") unlock4Txt.setText(game._turkishTexts.unlock4Txt);
	// Nav
	if (typeof leftTxt !== "undefined") leftTxt.setText(game._turkishTexts.leftTxt);
	if (typeof rightTxt !== "undefined") rightTxt.setText(game._turkishTexts.rightTxt);
	// 4th screen buttons
	if (typeof game.autoCompleteBtnTxt !== "undefined") game.autoCompleteBtnTxt.setText(game._turkishTexts.autoCompleteBtnTxt);
	if (typeof game.autoGrowBtnTxt !== "undefined") game.autoGrowBtnTxt.setText(game._turkishTexts.autoGrowBtnTxt);
	if (typeof game.autoCollectBtnTxt !== "undefined") game.autoCollectBtnTxt.setText(game._turkishTexts.autoCollectBtnTxt);
	// Pot reduce box
	if (typeof game.potReduceBoxTxt !== "undefined") game.potReduceBoxTxt.setText(game._turkishTexts.potReduceBoxTxt);
};
// (Removed old Turkish button tap logic here, now handled in main game.down)
// --- 4th Screen: Unique, empty, not copy-paste, not interacting with others ---
game.screen4Container = new Container();
game.screen4Bg = LK.getAsset('box', {
	anchorX: 0.5,
	anchorY: 0.5,
	width: 2048,
	height: 2732,
	x: 2048 / 2,
	y: 2732 / 2,
	alpha: 0.15
});
game.screen4Container.addChild(game.screen4Bg);
// No label for 4th screen (removed as requested)
// --- 4th Screen: Auto-complete Button and Logic ---
game.autoCompleteEnabled = false;
game.autoCompleteBtn = LK.getAsset('unlock', {
	anchorX: 0.0,
	// Anchor left for left extension
	anchorY: 0.5,
	width: 700,
	// Increased width for a bigger button
	height: 180,
	// Increased height for a bigger button
	x: 2048 / 2 - 350,
	// Shift left by half the new width
	y: 2732 / 2 + 200,
	alpha: 0.9
});
game.screen4Container.addChild(game.autoCompleteBtn);
game.autoCompleteBtnTxt = new Text2('Auto-complete Orders (100$)', {
	size: 110,
	// Increased font size for better visibility
	fill: "#fff",
	maxWidth: 660 // Ensure text fits inside 700px button with padding
});
game.autoCompleteBtnTxt.anchor.set(0.5, 0.5);
game.autoCompleteBtnTxt.x = game.autoCompleteBtn.x + game.autoCompleteBtn.width / 2; // Center text in button
game.autoCompleteBtnTxt.y = game.autoCompleteBtn.y;
game.screen4Container.addChild(game.autoCompleteBtnTxt);
// --- 4th Screen: Auto-grow Box and Logic ---
game.autoGrowEnabled = false;
game.autoGrowBtn = LK.getAsset('unlock', {
	anchorX: 0.0,
	anchorY: 0.5,
	width: 700,
	height: 180,
	x: 2048 / 2 - 350,
	y: 2732 / 2 + 420,
	// Place below auto-complete button
	alpha: 0.9
});
game.screen4Container.addChild(game.autoGrowBtn);
game.autoGrowBtnTxt = new Text2('Auto-grow Corn (50$)', {
	size: 110,
	fill: "#fff",
	maxWidth: 660
});
game.autoGrowBtnTxt.anchor.set(0.5, 0.5);
game.autoGrowBtnTxt.x = game.autoGrowBtn.x + game.autoGrowBtn.width / 2;
game.autoGrowBtnTxt.y = game.autoGrowBtn.y;
game.screen4Container.addChild(game.autoGrowBtnTxt);
// --- 4th Screen: Auto-collect Box and Logic ---
game.autoCollectEnabled = false;
game.autoCollectBtn = LK.getAsset('unlock', {
	anchorX: 0.0,
	anchorY: 0.5,
	width: 700,
	height: 180,
	x: 2048 / 2 - 350,
	y: 2732 / 2 + 640,
	// Place below auto-grow button
	alpha: 0.9
});
game.screen4Container.addChild(game.autoCollectBtn);
game.autoCollectBtnTxt = new Text2('Auto-collect (50$)', {
	size: 110,
	fill: "#fff",
	maxWidth: 660
});
game.autoCollectBtnTxt.anchor.set(0.5, 0.5);
game.autoCollectBtnTxt.x = game.autoCollectBtn.x + game.autoCollectBtn.width / 2;
game.autoCollectBtnTxt.y = game.autoCollectBtn.y;
game.screen4Container.addChild(game.autoCollectBtnTxt);
// Helper: auto-collect logic, harvest all ready unlocked fields
game.autoCollectTick = function () {
	if (!game.autoCollectEnabled) return;
	// Only collect if on field screen
	if (game.currentScreen !== 0) return;
	for (var i = 0; i < game.unlockedFields; i++) {
		var field = game.fields[i];
		if (field && field.state === 'ready' && !field.locked) {
			field.harvest();
		}
	}
};
// Set up interval for auto-collect (every 1s)
game._autoCollectInterval = null;
function startAutoCollectInterval() {
	if (game._autoCollectInterval) LK.clearInterval(game._autoCollectInterval);
	game._autoCollectInterval = LK.setInterval(function () {
		if (game.autoCollectEnabled) game.autoCollectTick();
	}, 1000);
}
function stopAutoCollectInterval() {
	if (game._autoCollectInterval) {
		LK.clearInterval(game._autoCollectInterval);
		game._autoCollectInterval = null;
	}
}
startAutoCollectInterval();
// Helper: auto-grow logic, plant in all empty unlocked fields if seeds available
game.autoGrowTick = function () {
	if (!game.autoGrowEnabled) return;
	// Only plant if on field screen and have seeds
	if (game.currentScreen !== 0) return;
	if (typeof game.seeds !== "number" || game.seeds <= 0) return;
	for (var i = 0; i < game.unlockedFields; i++) {
		var field = game.fields[i];
		if (field && field.state === 'empty' && !field.locked && !field._replantCooldown && game.seeds > 0) {
			// Plant in this field
			game.seeds--;
			if (typeof game.updateSeeds === "function") game.updateSeeds();
			field.plant();
		}
	}
};
// Set up interval for auto-grow (every 1s)
game._autoGrowInterval = null;
function startAutoGrowInterval() {
	if (game._autoGrowInterval) LK.clearInterval(game._autoGrowInterval);
	game._autoGrowInterval = LK.setInterval(function () {
		if (game.autoGrowEnabled) game.autoGrowTick();
	}, 1000);
}
function stopAutoGrowInterval() {
	if (game._autoGrowInterval) {
		LK.clearInterval(game._autoGrowInterval);
		game._autoGrowInterval = null;
	}
}
startAutoGrowInterval();
// Helper: check if we can auto-complete a customer order
game.canAutoCompleteOrder = function (cust) {
	if (!cust || !cust.order) return false;
	// Check if enough cooked corn
	if (!game.cookArea || typeof game.cookArea.cookedCorn !== "number") return false;
	if (game.cookArea.cookedCorn < cust.order.cornCount) return false;
	// Check if all sauces are available (ketchup/mayonnaise)
	// In this game, sauces are always available (no inventory), so always true
	return true;
};
// Helper: auto-complete a customer order (simulate delivery visually, step by step)
game.autoCompleteOrder = function (cust) {
	if (!cust || !cust.order) return false;
	if (!game.canAutoCompleteOrder(cust)) return false;
	// If not on order screen, do nothing
	if (game.currentScreen !== 2) return false;
	// Step 1: Ensure plate exists and is empty
	if (!game.tezgahPlate || game.tezgahPlate.destroyed) {
		game.tezgahPlate = new Plate();
		game.tezgahPlate.x = game.counterAsset.x;
		game.tezgahPlate.y = game.counterAsset.y - game.counterAsset.height / 2;
		game.addChild(game.tezgahPlate);
		game.tezgahPlate.cornIcons = [];
	}
	// Remove any existing corn/sauce icons from plate
	if (game.tezgahPlate.cornIcons) {
		for (var i = 0; i < game.tezgahPlate.cornIcons.length; i++) {
			var c = game.tezgahPlate.cornIcons[i];
			if (c._ketchupIcon && !c._ketchupIcon.destroyed) c._ketchupIcon.destroy();
			if (c._mayonnaiseIcon && !c._mayonnaiseIcon.destroyed) c._mayonnaiseIcon.destroy();
			if (!c.destroyed) c.destroy();
		}
	}
	game.tezgahPlate.cornIcons = [];
	// Step 2: Animate adding corn(s) to plate, then sauces, then deliver
	var cornCount = cust.order.cornCount || 1;
	var sauces = cust.order.sauces || [];
	var addDelay = 350; // ms between each corn/sauce step
	var totalDelay = 0;
	// Remove cooked corn from cookArea (all at once, but animate one by one)
	if (!game.cookArea.removeCookedCorn(cornCount)) return false;
	// Helper to add a corn icon to plate
	function addCornToPlate(idx) {
		var iconW = 80,
			iconH = 80;
		var xOnPlate = game.tezgahPlate.x - 120 + idx * (iconW + 10);
		var yOnPlate = game.tezgahPlate.y - 10;
		var cornIcon = LK.getAsset('corn', {
			anchorX: 0.5,
			anchorY: 0.5,
			width: iconW,
			height: iconH,
			x: xOnPlate,
			y: yOnPlate,
			alpha: 0
		});
		game.addChild(cornIcon);
		// Animate fade in
		tween(cornIcon, {
			alpha: 1
		}, {
			duration: 200
		});
		if (!game.tezgahPlate.cornIcons) game.tezgahPlate.cornIcons = [];
		game.tezgahPlate.cornIcons.push(cornIcon);
	}
	// Helper to add sauce to a corn icon
	function addSauceToCorn(cornIcon, sauce) {
		var icon = null;
		if (sauce === "ketchup") {
			icon = LK.getAsset('ketchup', {
				anchorX: 0.5,
				anchorY: 0.5,
				width: 40,
				height: 40,
				x: cornIcon.x,
				y: cornIcon.y - 20,
				alpha: 0
			});
			game.addChild(icon);
			tween(icon, {
				alpha: 1
			}, {
				duration: 150
			});
			cornIcon._hasKetchup = true;
			cornIcon._ketchupIcon = icon;
		} else if (sauce === "mayonnaise") {
			icon = LK.getAsset('mayonnaise', {
				anchorX: 0.5,
				anchorY: 0.5,
				width: 40,
				height: 40,
				x: cornIcon.x,
				y: cornIcon.y - 10,
				alpha: 0
			});
			game.addChild(icon);
			tween(icon, {
				alpha: 1
			}, {
				duration: 150
			});
			cornIcon._hasMayonnaise = true;
			cornIcon._mayonnaiseIcon = icon;
		}
	}
	// Step 2a: Animate adding corns one by one
	for (var i = 0; i < cornCount; i++) {
		LK.setTimeout(function (idx) {
			return function () {
				addCornToPlate(idx);
			};
		}(i), totalDelay);
		totalDelay += addDelay;
	}
	// Step 2b: Animate adding sauces to each corn, one by one
	// Distribute sauces as in order (if more corns than sauces, repeat sauces)
	for (var i = 0; i < cornCount; i++) {
		for (var s = 0; s < sauces.length; s++) {
			LK.setTimeout(function (idx, sauceName) {
				return function () {
					if (game.tezgahPlate.cornIcons && game.tezgahPlate.cornIcons[idx]) {
						addSauceToCorn(game.tezgahPlate.cornIcons[idx], sauceName);
					}
				};
			}(i, sauces[s]), totalDelay);
			totalDelay += addDelay;
		}
	}
	// Step 3: After all corns and sauces are added, animate plate to customer and deliver
	LK.setTimeout(function () {
		// Animate plate to customer
		var origX = game.tezgahPlate.x;
		var origY = game.tezgahPlate.y;
		var destX = cust.x;
		var destY = cust.y - 200; // move plate up to customer
		tween(game.tezgahPlate, {
			x: destX,
			y: destY
		}, {
			duration: 400,
			easing: tween.cubicOut,
			onFinish: function onFinish() {
				// Flash customer for feedback
				LK.effects.flashObject(cust, 0x00ff00, 400);
				// Give coins based on cornCount
				var deliveredCoins = 0;
				if (cust.order && cust.order.cornCount === 1) deliveredCoins = 5;else if (cust.order && cust.order.cornCount === 2) deliveredCoins = 10;else if (cust.order && cust.order.cornCount === 3) deliveredCoins = 15;else if (cust.order && cust.order.cornCount === 4) deliveredCoins = 20;else deliveredCoins = 5; // fallback
				game.coins += deliveredCoins;
				if (typeof game.updateCoins === "function") game.updateCoins();
				// Remove customer
				if (!cust.destroyed) cust.destroy();
				for (var i = 0; i < game.customers.length; i++) {
					if (game.customers[i] === cust) {
						game.customers[i] = null;
						break;
					}
				}
				// Remove corn/sauce icons from plate
				if (game.tezgahPlate.cornIcons) {
					for (var i = 0; i < game.tezgahPlate.cornIcons.length; i++) {
						var c = game.tezgahPlate.cornIcons[i];
						if (c._ketchupIcon && !c._ketchupIcon.destroyed) c._ketchupIcon.destroy();
						if (c._mayonnaiseIcon && !c._mayonnaiseIcon.destroyed) c._mayonnaiseIcon.destroy();
						if (!c.destroyed) c.destroy();
					}
				}
				game.tezgahPlate.cornIcons = [];
				// Animate plate back to original position
				tween(game.tezgahPlate, {
					x: origX,
					y: origY
				}, {
					duration: 400,
					easing: tween.cubicOut
				});
				// Flash effect for feedback
				LK.effects.flashObject(game.cookedCornBox, 0x00ff00, 400);
			}
		});
	}, totalDelay + 200);
	return true;
};
game.addChild(game.screen4Container);
game.screen4Container.visible = false;
// --- Field grid ---
game.fields = [];
var fieldRows = 2;
var fieldCols = 2;
var fieldSpacing = 340;
var fieldStartX = 400;
var fieldStartY = 600;
function updateFieldGrid() {
	// Determine grid size based on unlocked fields
	var n = game.unlockedFields;
	if (n <= 4) {
		fieldRows = 2;
		fieldCols = 2;
	} else if (n <= 9) {
		fieldRows = 3;
		fieldCols = 3;
	} else {
		fieldRows = 4;
		fieldCols = 4;
	}
}
function layoutFields() {
	updateFieldGrid();
	// Calculate how many fields are visible per "page" vertically
	var maxVisibleRows = Math.floor((2048 - fieldStartY) / fieldSpacing); // fit as many as possible
	var maxVisibleCols = Math.floor((2048 - fieldStartX) / fieldSpacing);
	// For our game, let's allow 2 rows before scrolling horizontally
	var fieldsPerCol = 2;
	var fieldsPerRow = 4; // up to 4 columns before scrolling horizontally
	// Calculate how many "pages" horizontally
	var pageSize = fieldsPerCol * fieldsPerRow;
	var pageCount = Math.ceil(game.unlockedFields / pageSize);
	// Find which page is currently active (always show the last unlocked page)
	var currentPage = Math.floor((game.unlockedFields - 1) / pageSize);
	// Calculate horizontal offset for scrolling
	var scrollX = currentPage * (fieldsPerRow * fieldSpacing + 100); // 100px gap between pages
	for (var i = 0; i < game.maxFields; i++) {
		// Which page does this field belong to?
		var page = Math.floor(i / pageSize);
		var pageIndex = i % pageSize;
		var row = Math.floor(pageIndex / fieldsPerRow);
		var col = pageIndex % fieldsPerRow;
		// If not unlocked, keep offscreen
		if (i >= game.unlockedFields) {
			game.fields[i].x = -1000;
			game.fields[i].y = -1000;
			continue;
		}
		// Place fields in a grid, scrolling horizontally after 2 rows
		var x = fieldStartX + col * fieldSpacing - scrollX;
		var y = fieldStartY + row * fieldSpacing;
		game.fields[i].x = x;
		game.fields[i].y = y;
	}
}
// Create fields
for (var i = 0; i < game.maxFields; i++) {
	var field = new CornField();
	field.index = i;
	game.addChild(field);
	game.fields.push(field);
}
function updateFieldLocks() {
	for (var i = 0; i < game.maxFields; i++) {
		if (i < game.unlockedFields) {
			game.fields[i].setLocked(false);
			if (game.fields[i].fieldAsset) game.fields[i].fieldAsset.alpha = 1;
		} else {
			game.fields[i].setLocked(true);
			if (game.fields[i].fieldAsset) game.fields[i].fieldAsset.alpha = 0.4;
		}
	}
}
updateFieldLocks();
layoutFields();
// --- Corn Box ---
// Place corn box just above the pot on 2nd screen
game.cornBox = new CornBox();
// Pot is at y = 2732 (bottom), potAsset.y = -120, potAsset.height = 800, so top of pot = 2732 - 120 - 800 = 1812
// Place corn box about 120px above the pot
game.cornBox.x = 2048 / 2;
game.cornBox.y = 1812 - 120;
// Add English label above the corn box, and a count label below it
game.cornBoxLabel = new Text2('Corn in Box', {
	size: 48,
	fill: "#fff"
});
game.cornBoxLabel.anchor.set(0.5, 1);
game.cornBoxLabel.x = game.cornBox.x;
game.cornBoxLabel.y = game.cornBox.y - 140;
game.cornBoxLabel.visible = false; // Only show on boxcook screen
game.addChild(game.cornBoxLabel);
// Add a corn count label above the box (just below the "Corn in Box" label)
game.cornBoxCountLabel = new Text2('0', {
	size: 60,
	fill: 0xFFF700
});
game.cornBoxCountLabel.anchor.set(0.5, 1);
game.cornBoxCountLabel.x = game.cornBox.x;
game.cornBoxCountLabel.y = game.cornBox.y - 80;
game.cornBoxCountLabel.visible = false; // Only show on boxcook screen
game.addChild(game.cornBoxCountLabel);
game.addChild(game.cornBox);
// --- Cooked Corn Count Box for 2nd Screen (BoxCook) ---
// This duplicates the cooked corn count box from the 3rd screen, but for the 2nd screen.
game.cookedCornBox2 = new Container();
var cookedCornBox2Asset = LK.getAsset('cooked', {
	anchorX: 0.5,
	anchorY: 0.5,
	width: 220,
	height: 220,
	x: 0,
	y: 0,
	alpha: 1
});
game.cookedCornBox2.addChild(cookedCornBox2Asset);
// Add a small black box behind the cooked corn count text for a shadow effect
var cookedCornBox2Shadow = LK.getAsset('box', {
	anchorX: 0.5,
	anchorY: 0.5,
	width: 120,
	height: 80,
	x: 0,
	y: 0,
	alpha: 0.7,
	tint: 0x000000
});
game.cookedCornBox2.addChild(cookedCornBox2Shadow);
game.cookedCornBox2Txt = new Text2('0', {
	size: 80,
	fill: "#fff"
});
game.cookedCornBox2Txt.anchor.set(0.5, 0.5);
game.cookedCornBox2Txt.x = 0;
game.cookedCornBox2Txt.y = 0;
game.cookedCornBox2.addChild(game.cookedCornBox2Txt);
// Place cooked corn count box at the very left edge, centered vertically above the pot (on 2nd screen)
game.cookedCornBox2.x = 220 / 2 + 10; // 10px margin from left
if (game.stove && typeof game.stove.y === "number" && typeof game.stove.height === "number") {
	game.cookedCornBox2.y = game.stove.y - game.stove.height / 2 - 220 / 2 - 20; // above the stove, adjust as needed
} else {
	// Fallback: place at a reasonable default if stove is not yet defined
	game.cookedCornBox2.y = 2732 - 1600;
}
game.addChild(game.cookedCornBox2);
game.cookedCornBox2.visible = false; // Only show on boxcook screen
// --- Stove & Pot for Cooking Screen ---
game.stove = new Container();
// Place stove at the very bottom of the screen, centered horizontally
game.stove.x = 2048 / 2;
game.stove.y = 2732; // y=2732 is the very bottom edge
game.addChild(game.stove);
// Stove asset (image) - use a new visual asset for the stove
var stoveAsset = LK.getAsset('stoveImage', {
	anchorX: 0.5,
	anchorY: 1,
	width: 2048,
	height: 420,
	y: 0
});
game.stove.addChild(stoveAsset);
// Pot asset (ellipse, centered on stove) - as large as possible but fits inside stove and is fully visible
var potAsset = LK.getAsset('pot', {
	anchorX: 0.5,
	anchorY: 1,
	width: 1400,
	// very wide, fills most of stove
	height: 800,
	// very tall, fills most of stove
	y: -120 // move pot lower so it sits further down on the stove
});
game.stove.addChild(potAsset);
// Place pot lower on the stove
potAsset.x = 0;
potAsset.y = -120;
// Pot "lid" (for visual effect) - now smaller than pot and sits directly on top of pot
var potLid = LK.getAsset('potLid', {
	anchorX: 0.5,
	anchorY: 1,
	width: 1000,
	// reduced width
	height: 220,
	// reduced height
	y: potAsset.y - potAsset.height + 300,
	// moved lid slightly up (less down)
	// adjust to match new height
	alpha: 1
});
game.stove.addChild(potLid);
// Place lid to visually close the pot
potLid.x = potAsset.x;
potLid.y = potAsset.y - potAsset.height + 300; // moved lid slightly up (less down)
// Corns in pot (array of {asset, startTime})
game.potCorns = [];
// Pot timer text
game.potTimerTxt = new Text2('', {
	size: 70,
	fill: "#fff"
});
game.potTimerTxt.anchor.set(0.5, 0.5);
// Center the timer in the middle of the pot, and move it lower to match new pot position
game.potTimerTxt.x = potAsset.x;
game.potTimerTxt.y = potAsset.y - 320 + 300; // Move timer lower to match new pot position
game.stove.addChild(game.potTimerTxt);
// --- 2nd Screen: Pot Cook Time Reduce Box ---
// Only visible on 2nd screen (boxcook)
game.potReduceBox = LK.getAsset('unlock', {
	anchorX: 0.5,
	anchorY: 0.5,
	width: 600,
	height: 260,
	x: 2048 / 2,
	y: 400,
	// much higher on the screen
	alpha: 0.98
});
game.addChild(game.potReduceBox);
game.potReduceBox.visible = false; // Only show on 2nd screen
game.potReduceBoxTxt = new Text2('Reduce Cook Time by 10s (50$)', {
	size: 90,
	fill: "#fff",
	maxWidth: 560
});
game.potReduceBoxTxt.anchor.set(0.5, 0.5);
game.potReduceBoxTxt.x = game.potReduceBox.x;
game.potReduceBoxTxt.y = game.potReduceBox.y;
game.addChild(game.potReduceBoxTxt);
game.potReduceBoxTxt.visible = false; // Only show on 2nd screen
// --- Permanent pot cook time reduction: each use reduces all future corns' cook time by 10s ---
game.potCookTimeReduce = 0; // in ms, permanent reduction for all new corns in pot
// --- Cook Area (for legacy, still used for quick cook) ---
game.cookArea = new CookArea();
game.cookArea.x = 2048 - 300;
game.cookArea.y = 1100;
game.addChild(game.cookArea);
// --- Order Area ---
// Order area removed as per request
// Minimal OrderArea to prevent undefined error for addCorn
game.orderArea = {
	addCorn: function addCorn(n) {
		// No-op: order area is removed, but prevent error
	}
};
// --- Order Screen Background ---
game.orderBg = LK.getAsset('orderBg', {
	anchorX: 0.5,
	anchorY: 0.5,
	width: 2048,
	height: 2732,
	x: 2048 / 2,
	y: 2732 / 2,
	alpha: 1
});
game.addChild(game.orderBg);
game.orderBg.visible = false;
// --- Tezgah (Counter) for Customer Screen ---
// Make the tezgah (counter) very large and at the very bottom of the screen, spanning almost the full width
game.counterAsset = LK.getAsset('tezgah', {
	anchorX: 0.5,
	anchorY: 1,
	width: 2048 - 20,
	// leave only 10px margin on each side for a bigger counter
	height: 420,
	// make it even taller
	alpha: 0.95
});
game.counterAsset.x = 2048 / 2;
game.counterAsset.y = 2732; // Place tezgah at the very bottom of the screen (old/original position)
game.addChild(game.counterAsset);
// --- Cooked Corn Count Box for 3rd Screen (Order Screen) ---
game.cookedCornBox = new Container();
var cookedCornBoxAsset = LK.getAsset('cooked', {
	anchorX: 0.5,
	anchorY: 0.5,
	width: 220,
	height: 220,
	x: 0,
	y: 0,
	alpha: 1
});
game.cookedCornBox.addChild(cookedCornBoxAsset);
// Add a small black box behind the cooked corn count text for a shadow effect
var cookedCornBoxShadow = LK.getAsset('box', {
	anchorX: 0.5,
	anchorY: 0.5,
	width: 120,
	height: 80,
	x: 0,
	y: 0,
	alpha: 0.7,
	tint: 0x000000
});
game.cookedCornBox.addChild(cookedCornBoxShadow);
game.cookedCornBoxTxt = new Text2('0', {
	size: 80,
	fill: "#fff"
	// removed shadow property, now using box behind
});
game.cookedCornBoxTxt.anchor.set(0.5, 0.5);
game.cookedCornBoxTxt.x = 0;
game.cookedCornBoxTxt.y = 0;
game.cookedCornBox.addChild(game.cookedCornBoxTxt);
// Place cooked corn count box at the very left edge, centered vertically on top of the tezgah (counter) in 3rd screen
// Center the box horizontally at the left edge of the tezgah
game.cookedCornBox.x = game.counterAsset.x - game.counterAsset.width / 2 + game.cookedCornBox.width / 2 + 10; // 10px margin from left
game.cookedCornBox.y = game.counterAsset.y - game.counterAsset.height / 2; // center vertically on tezgah
game.addChild(game.cookedCornBox);
game.cookedCornBox.visible = false; // Only show on order screen
// --- New: Two unique boxes on the tezgah (counter) ---
game.tezgahBox1 = new Container();
var tezgahBox1Asset = LK.getAsset('tezgahBox1', {
	anchorX: 0.5,
	anchorY: 0.5,
	width: 180,
	height: 180,
	x: 0,
	y: 0,
	alpha: 1
});
game.tezgahBox1.addChild(tezgahBox1Asset);
// Create tezgahBox2 container and asset
game.tezgahBox2 = new Container();
var tezgahBox2Asset = LK.getAsset('tezgahBox2', {
	anchorX: 0.5,
	anchorY: 0.5,
	width: 180,
	height: 180,
	x: 0,
	y: 0,
	alpha: 1
});
game.tezgahBox2.addChild(tezgahBox2Asset);
// Place tezgahBox2 at the far right and at the very top of the tezgah (counter)
game.tezgahBox2.x = game.counterAsset.x + game.counterAsset.width / 2 - game.tezgahBox2.width / 2 - 10; // 10px margin from right
game.tezgahBox2.y = game.counterAsset.y - game.counterAsset.height + game.tezgahBox2.height / 2 + 10; // 10px margin from top
game.addChild(game.tezgahBox2);
game.tezgahBox2.visible = false; // Only show on order screen
// Place tezgahBox1 to the left of tezgahBox2 with a small gap (e.g. 20px)
var tezgahBoxGap = 20;
game.tezgahBox1.x = game.tezgahBox2.x - game.tezgahBox2.width / 2 - tezgahBoxGap - game.tezgahBox1.width / 2;
game.tezgahBox1.y = game.tezgahBox2.y;
game.addChild(game.tezgahBox1);
game.tezgahBox1.visible = false; // Only show on order screen
// --- Customers in front of tezgah (only on customer screen) ---
game.customers = [];
game.customerSpawnPositions = [2048 / 2 - 420,
// left
2048 / 2,
// center
2048 / 2 + 420 // right
];
game.customerY = 2732 - 420; // Stand just above the tezgah
// --- Customer Spawn Control for 3rd Screen ---
// Add a button to the 3rd screen to start customer spawning
game.customerStartBtn = LK.getAsset('unlock', {
	anchorX: 0.5,
	anchorY: 0.5,
	width: 600,
	height: 180,
	x: 2048 / 2,
	y: 600,
	alpha: 0.98
});
game.customerStartBtnTxt = new Text2('Müşteri Başlat', {
	size: 90,
	fill: "#fff"
});
game.customerStartBtnTxt.anchor.set(0.5, 0.5);
game.customerStartBtnTxt.x = game.customerStartBtn.x;
game.customerStartBtnTxt.y = game.customerStartBtn.y;
// Add translations for customer start button
game._customerStartBtnTexts = {
	en: "Start Customers",
	tr: "Müşteri Başlat",
	fr: "Démarrer les clients"
};
// Track if customer spawning has started
game._customerSpawningStarted = false;
// Helper to spawn a customer at a random position
game.spawnCustomer = function () {
	// Find a free customer slot (max 3 customers at a time)
	var freeIndex = -1;
	for (var i = 0; i < 3; i++) {
		if (!game.customers[i] || game.customers[i].destroyed || !game.customers[i].visible) {
			freeIndex = i;
			break;
		}
	}
	if (freeIndex === -1) return; // All slots full
	// Pick a random position index (0, 1, 2)
	var posIdx = Math.floor(Math.random() * 3);
	// Make sure no other customer is at this position
	var taken = false;
	for (var i = 0; i < game.customers.length; i++) {
		if (game.customers[i] && game.customers[i].visible && game.customers[i].x === game.customerSpawnPositions[posIdx]) {
			taken = true;
			break;
		}
	}
	if (taken) {
		// Try other positions
		for (var j = 0; j < 3; j++) {
			if (j !== posIdx) {
				var found = false;
				for (var k = 0; k < game.customers.length; k++) {
					if (game.customers[k] && game.customers[k].visible && game.customers[k].x === game.customerSpawnPositions[j]) {
						found = true;
						break;
					}
				}
				if (!found) {
					posIdx = j;
					break;
				}
			}
		}
	}
	// Create or reuse customer
	var cust;
	if (game.customers[freeIndex] && !game.customers[freeIndex].destroyed) {
		cust = game.customers[freeIndex];
	} else {
		cust = new Customer();
		game.customers[freeIndex] = cust;
		game.addChild(cust);
	}
	// Set customer position and keep them stationary
	cust.x = game.customerSpawnPositions[posIdx];
	cust.y = game.customerY;
	// Always keep customer visible, but only show on order screen
	cust.visible = game.currentScreen === 2;
	// Assign a random order to the customer and show it above their head
	var sauces = ['ketchup', 'mayonnaise'];
	var n = 1 + Math.floor(Math.random() * Math.min(2, sauces.length));
	var orderSauces = [];
	var used = {};
	while (orderSauces.length < n) {
		var idx = Math.floor(Math.random() * sauces.length);
		var s = sauces[idx];
		if (!used[s]) {
			orderSauces.push(s);
			used[s] = true;
		}
	}
	// Assign random cornCount (1-4)
	var cornCount = 1 + Math.floor(Math.random() * 4);
	cust.setOrder({
		sauces: orderSauces,
		cornCount: cornCount
	});
	// Remove any movement or animation logic for customers here to keep them stationary
};
// Remove all pre-created customers
game.customers = [];
// --- Customer spawn timer logic controlled by button ---
game.customerSpawnTimer = null;
game._customerSpawnInterval = 20000; // 20s after first
game._customerFirstDelay = 40000; // 40s for first customer (not used anymore)
game._customerSpawningStarted = false;
// --- Auto-start customer spawning at 13:00 if not started by button ---
game._autoCustomerStartTimer = LK.setInterval(function () {
	// Only check if not already started and on or after 13:00
	if (!game._customerSpawningStarted && game.clockTime >= 13 * 60) {
		game._customerSpawningStarted = true;
		// Set customer start button text to English if auto-started
		if (game.customerStartBtnTxt && game._customerStartBtnTexts) {
			game.customerStartBtnTxt.setText(game._customerStartBtnTexts.en);
		}
		// Hide customer start button if visible
		if (game.customerStartBtn) game.customerStartBtn.visible = false;
		if (game.customerStartBtnTxt) game.customerStartBtnTxt.visible = false;
		// Spawn first customer immediately
		if (typeof spawnCustomerOnOrderScreen === "function") spawnCustomerOnOrderScreen();
		// Start interval for next customers (every 22s)
		if (game.customerSpawnTimer) LK.clearInterval(game.customerSpawnTimer);
		game._customerSpawnIntervalStarted = true;
		game.customerSpawnTimer = LK.setInterval(spawnCustomerOnOrderScreen, 22000);
		// Stop this interval, no need to check again
		LK.clearInterval(game._autoCustomerStartTimer);
		game._autoCustomerStartTimer = null;
	}
}, 500);
// Fame-based customer spawn rate
game.updateCustomerSpawnRate = function () {
	// Fame 0-10: 1 customer per 35s, 10-50: 1 per 18s, 50-100: 1 per 7s
	var fame = typeof game.fame === "number" ? game.fame : 0;
	var interval = 35000;
	if (fame >= 50) {
		interval = 7000;
	} else if (fame >= 10) {
		interval = 18000;
	} else {
		interval = 35000;
	}
	// Fame 0-10: 1 customer per 35s, 10-50: 1 per 18s, 50-100: 1 per 7s
	var fame = typeof game.fame === "number" ? game.fame : 0;
	var interval = 35000;
	if (fame >= 50) {
		interval = 7000;
	} else if (fame >= 10) {
		interval = 18000;
	} else {
		interval = 35000;
	}
	game._customerSpawnInterval = interval;
	// Restart interval if already running and spawning has started
	if (game.customerSpawnTimer && game._customerSpawningStarted) {
		LK.clearInterval(game.customerSpawnTimer);
		game.customerSpawnTimer = LK.setInterval(spawnCustomerOnOrderScreen, game._customerSpawnInterval);
	}
};
// --- Only spawn customers if started by button ---
function spawnCustomerOnOrderScreen() {
	if (!game._customerSpawningStarted) return;
	// Allow customer start button to work before 11:00 (removed 11:00 check)
	// (No time check here)
	// Always spawn customers in the background, not just on order screen
	// Find a free customer slot (max 3 customers at a time)
	var freeIndex = -1;
	for (var i = 0; i < 3; i++) {
		if (!game.customers[i] || game.customers[i].destroyed || !game.customers[i].visible) {
			freeIndex = i;
			break;
		}
	}
	if (freeIndex === -1) return; // All slots full
	// Pick a random position index (0, 1, 2)
	var posIdx = Math.floor(Math.random() * 3);
	// Make sure no other customer is at this position
	var taken = false;
	for (var i = 0; i < game.customers.length; i++) {
		if (game.customers[i] && game.customers[i].visible && game.customers[i].x === game.customerSpawnPositions[posIdx]) {
			taken = true;
			break;
		}
	}
	if (taken) {
		// Try other positions
		for (var j = 0; j < 3; j++) {
			if (j !== posIdx) {
				var found = false;
				for (var k = 0; k < game.customers.length; k++) {
					if (game.customers[k] && game.customers[k].visible && game.customers[k].x === game.customerSpawnPositions[j]) {
						found = true;
						break;
					}
				}
				if (!found) {
					posIdx = j;
					break;
				}
			}
		}
	}
	// Create or reuse customer
	var cust;
	if (game.customers[freeIndex] && !game.customers[freeIndex].destroyed) {
		cust = game.customers[freeIndex];
	} else {
		cust = new Customer();
		game.customers[freeIndex] = cust;
		game.addChild(cust);
	}
	// Set customer position and keep them stationary
	cust.x = game.customerSpawnPositions[posIdx];
	cust.y = game.customerY;
	// Always keep customer visible, but only show on order screen
	cust.visible = game.currentScreen === 2;
	// Assign a random order to the customer and show it above their head
	var sauces = ['ketchup', 'mayonnaise'];
	var n = 1 + Math.floor(Math.random() * Math.min(2, sauces.length));
	var orderSauces = [];
	var used = {};
	while (orderSauces.length < n) {
		var idx = Math.floor(Math.random() * sauces.length);
		var s = sauces[idx];
		if (!used[s]) {
			orderSauces.push(s);
			used[s] = true;
		}
	}
	// Assign random cornCount (1-4)
	var cornCount = 1 + Math.floor(Math.random() * 4);
	cust.setOrder({
		sauces: orderSauces,
		cornCount: cornCount
	});
	// After first call, switch to interval if not already set and spawning has started
	if (!game._customerSpawnIntervalStarted && game._customerSpawningStarted) {
		// Allow customer start button to work before 11:00 (removed 11:00 check)
		// (No time check here)
		// Always spawn customers in the background, not just on order screen
		// Find a free customer slot (max 3 customers at a time)
		var freeIndex = -1;
		for (var i = 0; i < 3; i++) {
			if (!game.customers[i] || game.customers[i].destroyed || !game.customers[i].visible) {
				freeIndex = i;
				break;
			}
		}
		if (freeIndex === -1) return; // All slots full
		// Pick a random position index (0, 1, 2)
		var posIdx = Math.floor(Math.random() * 3);
		// Make sure no other customer is at this position
		var taken = false;
		for (var i = 0; i < game.customers.length; i++) {
			if (game.customers[i] && game.customers[i].visible && game.customers[i].x === game.customerSpawnPositions[posIdx]) {
				taken = true;
				break;
			}
		}
		if (taken) {
			// Try other positions
			for (var j = 0; j < 3; j++) {
				if (j !== posIdx) {
					var found = false;
					for (var k = 0; k < game.customers.length; k++) {
						if (game.customers[k] && game.customers[k].visible && game.customers[k].x === game.customerSpawnPositions[j]) {
							found = true;
							break;
						}
					}
					if (!found) {
						posIdx = j;
						break;
					}
				}
			}
		}
		// Create or reuse customer
		var cust;
		if (game.customers[freeIndex] && !game.customers[freeIndex].destroyed) {
			cust = game.customers[freeIndex];
		} else {
			cust = new Customer();
			game.customers[freeIndex] = cust;
			game.addChild(cust);
		}
		// Set customer position and keep them stationary
		cust.x = game.customerSpawnPositions[posIdx];
		cust.y = game.customerY;
		// Always keep customer visible, but only show on order screen
		cust.visible = game.currentScreen === 2;
		// Assign a random order to the customer and show it above their head
		var sauces = ['ketchup', 'mayonnaise'];
		var n = 1 + Math.floor(Math.random() * Math.min(2, sauces.length));
		var orderSauces = [];
		var used = {};
		while (orderSauces.length < n) {
			var idx = Math.floor(Math.random() * sauces.length);
			var s = sauces[idx];
			if (!used[s]) {
				orderSauces.push(s);
				used[s] = true;
			}
		}
		// Assign random cornCount (1-4)
		var cornCount = 1 + Math.floor(Math.random() * 4);
		cust.setOrder({
			sauces: orderSauces,
			cornCount: cornCount
		});
		// No destroy, just reuse and set visible
		// After first call, switch to interval if not already set
		game._customerSpawnIntervalStarted = true;
		game.customerSpawnTimer = LK.setInterval(spawnCustomerOnOrderScreen, game._customerSpawnInterval);
	}
}
// --- Clock update interval ---
game._clockInterval = LK.setInterval(function () {
	if (!game.clockRunning) return;
	// Advance time by 1 minute every 0.2 real seconds (5x faster)
	game.clockTime += 1;
	// If time passes 23:59, reset to 08:00 and increment day
	if (game.clockTime > 23 * 60 + 59) {
		game.clockTime = 8 * 60;
		game.clockHour = 8;
		game.clockMinute = 0;
		if (typeof game.day === "undefined") game.day = 1;
		game.day += 1;
		if (typeof dayTxt !== "undefined") dayTxt.setText('Day: ' + game.day);
		if (typeof game.updateFame === "function") game.updateFame();
	} else {
		game.clockHour = Math.floor(game.clockTime / 60);
		game.clockMinute = game.clockTime % 60;
	}
	// Format as HH:MM
	var h = game.clockHour < 10 ? '0' + game.clockHour : '' + game.clockHour;
	var m = game.clockMinute < 10 ? '0' + game.clockMinute : '' + game.clockMinute;
	if (typeof clockTxt !== "undefined") clockTxt.setText(h + ':' + m);
}, 200);
// --- Helper: is it after 11:00? ---
game.isAfterEleven = function () {
	return game.clockTime >= 11 * 60;
};
// Do not start customer spawn timer automatically; will be started by button on 3rd screen
if (game.customerSpawnTimer) {
	LK.clearInterval(game.customerSpawnTimer);
}
if (game._customerSpawnTimeout) {
	LK.clearTimeout(game._customerSpawnTimeout);
}
game._customerSpawnIntervalStarted = false;
game._customerSpawningStarted = false;
// --- Unlock 4 Fields Button ---
// Place a new button below the 4 fields to unlock 4 more fields at once for 20 coins
var unlock4BtnContainer = new Container();
var unlock4Btn = LK.getAsset('unlock', {
	anchorX: 0.0,
	anchorY: 0.5,
	width: 420,
	// Reduced width for a smaller button
	height: 120,
	// Reduced height for a smaller button
	alpha: 0.9
});
unlock4BtnContainer.addChild(unlock4Btn);
game.addChild(unlock4BtnContainer);
var unlock4Txt = new Text2('Unlock 4 Fields (20$)', {
	size: 70,
	// Reduced font size for better fit
	fill: "#fff",
	maxWidth: 380 // Ensure text fits inside 420px button with padding
});
unlock4Txt.anchor.set(0.5, 0.5);
game.addChild(unlock4Txt);
// Add containsPoint method to unlock4BtnContainer
unlock4BtnContainer.containsPoint = function (point) {
	var localX = point.x - unlock4BtnContainer.x;
	var localY = point.y - unlock4BtnContainer.y;
	var w = unlock4Btn.width;
	var h = unlock4Btn.height;
	return localX >= -w / 2 && localX <= w / 2 && localY >= -h / 2 && localY <= h / 2;
};
// Update unlock4 button position and text
function updateUnlockBtn() {
	// Only show if exactly 4 fields are unlocked and maxFields not reached and seeds > 0
	if (game.unlockedFields !== 4 || game.unlockedFields >= game.maxFields || game.seeds <= 0) {
		unlock4Btn.alpha = 0.3;
		unlock4BtnContainer.visible = false;
		unlock4Txt.visible = false;
		return;
	}
	// Place below the last unlocked field (index game.unlockedFields-1)
	// Since unlock4Btn is now left-anchored and wider, align its left edge with the field's left edge
	var lastField = game.fields[game.unlockedFields - 1];
	unlock4BtnContainer.x = lastField.x - 260; // Shift left by half the new width (520/2)
	unlock4BtnContainer.y = lastField.y + 260;
	unlock4Txt.x = unlock4BtnContainer.x + unlock4Btn.width / 2; // Center text in button
	unlock4Txt.y = unlock4BtnContainer.y;
	unlock4BtnContainer.visible = true;
	unlock4Txt.visible = true;
	unlock4Btn.alpha = 0.9;
	unlock4Txt.setText('Unlock 4 Fields (20$)');
}
updateUnlockBtn();
// --- Screen navigation buttons ---
var leftBtn = LK.getAsset('unlock', {
	anchorX: 0.5,
	anchorY: 0.5,
	width: 120,
	height: 120,
	x: 120,
	y: 2732 / 2,
	alpha: 0.7
});
var rightBtn = LK.getAsset('unlock', {
	anchorX: 0.5,
	anchorY: 0.5,
	width: 120,
	height: 120,
	x: 2048 - 120,
	y: 2732 / 2,
	alpha: 0.7
});
game.addChild(leftBtn);
game.addChild(rightBtn);
// Add containsPoint for nav buttons
leftBtn.containsPoint = function (point) {
	var localX = point.x - leftBtn.x;
	var localY = point.y - leftBtn.y;
	var w = leftBtn.width,
		h = leftBtn.height;
	return localX >= -w / 2 && localX <= w / 2 && localY >= -h / 2 && localY <= h / 2;
};
rightBtn.containsPoint = function (point) {
	var localX = point.x - rightBtn.x;
	var localY = point.y - rightBtn.y;
	var w = rightBtn.width,
		h = rightBtn.height;
	return localX >= -w / 2 && localX <= w / 2 && localY >= -h / 2 && localY <= h / 2;
};
// Nav button text
var leftTxt = new Text2('<', {
	size: 90,
	fill: "#fff"
});
leftTxt.anchor.set(0.5, 0.5);
leftTxt.x = leftBtn.x;
leftTxt.y = leftBtn.y;
game.addChild(leftTxt);
var rightTxt = new Text2('>', {
	size: 90,
	fill: "#fff"
});
rightTxt.anchor.set(0.5, 0.5);
rightTxt.x = rightBtn.x;
rightTxt.y = rightBtn.y;
game.addChild(rightTxt);
// --- Screen show/hide logic ---
function updateScreenVisibility() {
	// 0: field, 1: boxcook, 2: order, 3: screen4, 4: help
	var showField = game.currentScreen === 0;
	var showBoxCook = game.currentScreen === 1;
	var showOrder = game.currentScreen === 2;
	var showScreen4 = game.currentScreen === 3;
	var showHelp = game.currentScreen === 4;
	// Fields
	for (var i = 0; i < game.fields.length; i++) {
		game.fields[i].visible = showField;
	}
	// Show seedBox only on field screen
	if (game.seedBox) {
		game.seedBox.visible = showField;
	}
	// Only show unlock4BtnContainer and unlock4Txt if unlock4Btn should be available (unlockedFields==4, not maxed, seeds>0)
	// If fields are already unlocked (>4), always hide the button and label
	if (showField && game.unlockedFields === 4 && game.unlockedFields < game.maxFields && game.seeds > 0) {
		unlock4BtnContainer.visible = true;
		unlock4Txt.visible = true;
		unlock4Btn.alpha = 0.9;
	} else {
		unlock4BtnContainer.visible = false;
		unlock4Txt.visible = false;
		unlock4Btn.alpha = 0.3;
	}
	// Always hide and destroy unlock4BtnContainer and label if more than 4 fields are unlocked
	if (game.unlockedFields > 4) {
		if (unlock4BtnContainer && !unlock4BtnContainer.destroyed) {
			unlock4BtnContainer.destroy();
		}
		if (unlock4Txt && !unlock4Txt.destroyed) {
			unlock4Txt.destroy();
		}
		unlock4Btn.alpha = 0.3;
	}
	// Show/hide corn box label and count only on 2nd screen (boxcook)
	if (typeof game.cornBoxLabel !== "undefined") {
		game.cornBoxLabel.visible = showBoxCook;
		if (showBoxCook) {
			game.cornBoxLabel.setText('Corn in Box');
			// Make sure label is above the box and added to the display list
			if (game.cornBox && game.children.indexOf(game.cornBoxLabel) === -1) {
				game.addChild(game.cornBoxLabel);
			}
			// Position label above the box
			game.cornBoxLabel.x = game.cornBox.x;
			game.cornBoxLabel.y = game.cornBox.y - 140;
		}
	}
	// Show/hide potReduceBox and label only on 2nd screen
	if (typeof game.potReduceBox !== "undefined") {
		game.potReduceBox.visible = showBoxCook;
	}
	if (typeof game.potReduceBoxTxt !== "undefined") {
		game.potReduceBoxTxt.visible = showBoxCook;
	}
	if (typeof game.cornBoxCountLabel !== "undefined") {
		game.cornBoxCountLabel.visible = showBoxCook;
		if (showBoxCook) {
			// Update count to match box
			if (game.cornBox && typeof game.cornBox.cornCount === "number") {
				game.cornBoxCountLabel.setText(game.cornBox.cornCount + '');
			} else {
				game.cornBoxCountLabel.setText('0');
			}
			// Position count label just below the main label
			game.cornBoxCountLabel.x = game.cornBox.x;
			game.cornBoxCountLabel.y = game.cornBox.y - 80;
			// Make sure label is added to display list
			if (game.cornBox && game.children.indexOf(game.cornBoxCountLabel) === -1) {
				game.addChild(game.cornBoxCountLabel);
			}
		}
	}
	// Hide all other elements except fields, unlock4Btn, and seedBox on 1st screen
	for (var i = 0; i < game.children.length; i++) {
		var ch = game.children[i];
		if (showHelp) {
			// Only show the help screen container, hide everything else
			if (ch === game.helpScreenContainer) {
				ch.visible = true;
			} else {
				ch.visible = false;
			}
		} else if (showScreen4) {
			// Only show the 4th screen container, hide everything else
			if (ch === game.screen4Container) {
				ch.visible = true;
			} else {
				ch.visible = false;
			}
		} else if (showField) {
			// Only show fields, unlock4BtnContainer, unlock4Txt, and seedBox
			if (game.fields.indexOf(ch) !== -1 || ch === unlock4BtnContainer || ch === unlock4Txt || ch === game.seedBox) {
				ch.visible = true;
			} else {
				ch.visible = false;
			}
		} else if (showBoxCook) {
			// Only show stove, cornBox, and potReduceBox on 2nd screen
			if (ch === game.stove || ch === game.cornBox || ch === game.potReduceBox || ch === game.potReduceBoxTxt) {
				ch.visible = true;
			} else {
				ch.visible = false;
			}
		} else {
			// On 3rd screen (order), only show tezgah, customers, cooked corn count box, and plate
			if (game.currentScreen === 2) {
				// Show tezgah plate if not present, but do NOT recreate if it already exists (preserve corn icons)
				// Only create the plate if it never existed (not if just hidden)
				if (!game.tezgahPlate) {
					game.tezgahPlate = new Plate();
					// Center the plate horizontally on the tezgah
					game.tezgahPlate.x = game.counterAsset.x;
					// Place the plate vertically so it sits visually on the tezgah
					game.tezgahPlate.y = game.counterAsset.y - game.counterAsset.height / 2;
					game.addChild(game.tezgahPlate);
					game.tezgahPlate.cornIcons = [];
				} else if (game.tezgahPlate.destroyed) {
					// If destroyed, recreate and clear contents
					game.tezgahPlate = new Plate();
					game.tezgahPlate.x = game.counterAsset.x;
					game.tezgahPlate.y = game.counterAsset.y - game.counterAsset.height / 2;
					game.addChild(game.tezgahPlate);
					game.tezgahPlate.cornIcons = [];
				} else if (game.children.indexOf(game.tezgahPlate) === -1) {
					// If plate exists but is not in display list, re-add it (preserve its cornIcons)
					game.addChild(game.tezgahPlate);
				}
				if (ch === game.counterAsset || ch === game.cookedCornBox || ch === game.tezgahPlate) {
					ch.visible = true;
				} else if (game.customers && game.customers.indexOf(ch) !== -1) {
					ch.visible = true;
				} else {
					ch.visible = false;
				}
			} else {
				// On other screens, hide stove and cornBox, show others (handled by their own logic)
				if (ch === game.stove || ch === game.cornBox) {
					ch.visible = false;
				} else if (typeof ch.visible === "boolean") {
					ch.visible = true;
				}
			}
		}
	}
	// Order
	// game.orderArea.visible = showOrder; // Removed order area
	if (game.counterAsset) game.counterAsset.visible = showOrder;
	// Customers visible only on customer screen
	if (game.customers) {
		for (var i = 0; i < game.customers.length; i++) {
			if (showOrder && game.customers[i] && !game.customers[i].destroyed) {
				game.customers[i].visible = true;
			} else if (game.customers[i]) {
				game.customers[i].visible = false;
			}
		}
	}
	// Show cooked corn count box only on order screen (3rd) and boxcook screen (2nd)
	if (game.cookedCornBox) {
		// Only show on order screen (screen 2)
		game.cookedCornBox.visible = showOrder;
		// Show tezgah plate if on order screen
		if (showOrder && game.tezgahPlate) {
			game.tezgahPlate.visible = true;
		}
		// Update value from cookArea only if visible
		if (showOrder && game.cookArea && typeof game.cookArea.cookedCorn === "number") {
			game.cookedCornBoxTxt.setText(game.cookArea.cookedCorn);
		} else {
			game.cookedCornBoxTxt.setText('');
			game.cookedCornBox.visible = false;
		}
	}
	// Show/hide cooked corn count box for 2nd screen (boxcook)
	if (game.cookedCornBox2) {
		game.cookedCornBox2.visible = showBoxCook;
		if (showBoxCook && game.cookArea && typeof game.cookArea.cookedCorn === "number") {
			game.cookedCornBox2Txt.setText(game.cookArea.cookedCorn);
		} else {
			game.cookedCornBox2Txt.setText('');
			game.cookedCornBox2.visible = false;
		}
	}
	// Show tezgahBox1 and tezgahBox2 only on order screen
	if (game.tezgahBox1) game.tezgahBox1.visible = showOrder;
	if (game.tezgahBox2) game.tezgahBox2.visible = showOrder;
	// Show orderBg only on 3rd (order) screen
	if (game.orderBg) {
		game.orderBg.visible = showOrder;
	}
	// Show customer start button only on 3rd screen (order)
	if (game.customerStartBtn && game.customerStartBtnTxt) {
		if (showOrder && !game._customerSpawningStarted) {
			if (game.children.indexOf(game.customerStartBtn) === -1) game.addChild(game.customerStartBtn);
			if (game.children.indexOf(game.customerStartBtnTxt) === -1) game.addChild(game.customerStartBtnTxt);
			game.customerStartBtn.visible = true;
			game.customerStartBtnTxt.visible = true;
		} else {
			game.customerStartBtn.visible = false;
			game.customerStartBtnTxt.visible = false;
		}
	}
	// Nav buttons visible except on help screen (5th screen)
	if (game.currentScreen === 4) {
		leftBtn.visible = false;
		rightBtn.visible = false;
		leftTxt.visible = false;
		rightTxt.visible = false;
	} else {
		leftBtn.visible = true;
		rightBtn.visible = true;
		leftTxt.visible = true;
		rightTxt.visible = true;
	}
	// Hide tezgah plate if not on order screen
	if (game.tezgahPlate && game.currentScreen !== 2) {
		game.tezgahPlate.visible = false;
		// Do NOT destroy the plate or its cornIcons here; preserve them for when returning to the order screen
	}
	// Show seeds count always
	if (typeof seedsTxt !== "undefined") {
		seedsTxt.visible = true;
		if (typeof game.updateSeeds === "function") {
			game.updateSeeds();
		}
		if (typeof game.seedBoxTxt !== "undefined") {
			game.seedBoxTxt.setText(game.seeds + '');
		}
	}
}
updateScreenVisibility();
// --- Touch handling ---
game._draggingPlate = false;
game._dragPlateOffset = {
	x: 0,
	y: 0
};
game._dragPlateStart = {
	x: 0,
	y: 0
};
game._dragPlateCornIcons = null;
game._dragPlateKetchup = null;
game.down = function (x, y, obj) {
	// --- 5th Screen: English button tap ---
	if (game.currentScreen === 4 && game.englishBtn && typeof game.englishBtn.x === "number" && typeof game.englishBtn.y === "number") {
		var localXe = x - game.englishBtn.x;
		var localYe = y - game.englishBtn.y;
		var we = game.englishBtn.width || 420;
		var he = game.englishBtn.height || 140;
		if (localXe >= -we / 2 && localXe <= we / 2 && localYe >= -he / 2 && localYe <= he / 2) {
			// Switch all texts to English (default)
			if (typeof helpTitle !== "undefined") helpTitle.setText('How to Play?');
			if (typeof helpText !== "undefined") helpText.setText("1. Plant, grow, and harvest corn in the field.\n" + "2. Put the harvested corn into the box.\n" + "3. Take corn from the box and cook it in the pot.\n" + "4. Serve the cooked corn to customers.\n" + "5. Customers want corn with sauces, add the correct sauces.\n" + "6. Unlock new fields and buy automations as you earn more.\n\n" + "Use the left/right arrows to switch between screens.\n\n" + "If your Fame drops to -50, you lose the game!\n" + "If you find any bugs, please write them in the comments below.");
			if (typeof game.helpWarningNote !== "undefined") game.helpWarningNote.setText("WARNING: No customers will appear until you visit the customer screen. Please keep this in mind.");
			if (typeof game.autoCustomerWarningNote !== "undefined") game.autoCustomerWarningNote.setText("If you do not press the customer start button by 13:00, the game will start automatically.");
			if (typeof game.helpStartBtnTxt !== "undefined") game.helpStartBtnTxt.setText('Start Game');
			if (typeof game.customerStartBtnTxt !== "undefined" && game._customerStartBtnTexts) game.customerStartBtnTxt.setText(game._customerStartBtnTexts.en);
			if (typeof game.helpStartBtn !== "undefined") {
				game.helpStartBtn.width = 600;
				game.helpStartBtn.height = 180;
			}
			if (typeof game.helpStartBtnTxt !== "undefined") {
				game.helpStartBtnTxt.x = game.helpStartBtn.x;
				game.helpStartBtnTxt.y = game.helpStartBtn.y;
			}
			if (typeof game.turkceBtnTxt !== "undefined") game.turkceBtnTxt.setText('TÜRKÇE');
			if (typeof game.englishBtnTxt !== "undefined") game.englishBtnTxt.setText('ENGLISH');
			// Top bar
			if (typeof seedsTxt !== "undefined") seedsTxt.setText('Seeds: ' + game.seeds);
			if (typeof coinsTxt !== "undefined") coinsTxt.setText(game.coins + '$');
			if (typeof fameTxt !== "undefined") {
				fameTxt.setText('Fame: ' + game.fame);
				fameTxt.size = 90; // Restore fame text size in English
			}
			if (typeof dayTxt !== "undefined") dayTxt.setText('Day: ' + game.day);
			// Seed box
			if (typeof game.seedBoxLabel !== "undefined") game.seedBoxLabel.setText('Seeds left');
			if (typeof game.seedBoxTxt !== "undefined") game.seedBoxTxt.setText(game.seeds + '');
			// Corn box
			if (typeof game.cornBoxLabel !== "undefined") game.cornBoxLabel.setText('Corn in Box');
			// Unlock 4 fields
			if (typeof unlock4Txt !== "undefined") unlock4Txt.setText('Unlock 4 Fields (20$)');
			// Nav
			if (typeof leftTxt !== "undefined") leftTxt.setText('<');
			if (typeof rightTxt !== "undefined") rightTxt.setText('>');
			// 4th screen buttons
			if (typeof game.autoCompleteBtnTxt !== "undefined") game.autoCompleteBtnTxt.setText('Auto-complete Orders (100$)');
			if (typeof game.autoGrowBtnTxt !== "undefined") game.autoGrowBtnTxt.setText('Auto-grow Corn (50$)');
			if (typeof game.autoCollectBtnTxt !== "undefined") game.autoCollectBtnTxt.setText('Auto-collect (50$)');
			// Pot reduce box
			if (typeof game.potReduceBoxTxt !== "undefined") game.potReduceBoxTxt.setText('Reduce Cook Time by 10s (50$)');
			LK.effects.flashObject(game.englishBtn, 0x00ff00, 300);
			return;
		}
	}
	// --- 5th Screen: French button tap ---
	if (game.currentScreen === 4 && game.frenchBtn && typeof game.frenchBtn.x === "number" && typeof game.frenchBtn.y === "number") {
		var localXf = x - game.frenchBtn.x;
		var localYf = y - game.frenchBtn.y;
		var wf = game.frenchBtn.width || 420;
		var hf = game.frenchBtn.height || 140;
		if (localXf >= -wf / 2 && localXf <= wf / 2 && localYf >= -hf / 2 && localYf <= hf / 2) {
			// Switch all texts to French, but do NOT change font size (keep size as in English/Turkish)
			if (typeof helpTitle !== "undefined") helpTitle.setText('Comment jouer ?');
			if (typeof helpText !== "undefined") helpText.setText("1. Plante, fais pousser et récolte du maïs dans le champ.\n" + "2. Mets le maïs récolté dans la boîte.\n" + "3. Prends le maïs de la boîte et fais-le cuire dans la marmite.\n" + "4. Sers le maïs cuit aux clients.\n" + "5. Les clients veulent du maïs avec des sauces, ajoute les bonnes sauces.\n" + "6. Débloque de nouveaux champs et achète des automatisations au fur et à mesure que tu gagnes plus.\n\n" + "Utilise les flèches gauche/droite pour changer d’écran.\n\n" + "Si ta renommée tombe à -50, tu perds la partie !\n" + "Si tu trouves un bug, écris-le dans les commentaires ci-dessous.");
			if (typeof game.helpWarningNote !== "undefined") game.helpWarningNote.setText("ATTENTION : Aucun client n’apparaîtra tant que vous n’êtes pas allé à l’écran client. Faites-y attention.");
			if (typeof game.autoCustomerWarningNote !== "undefined") game.autoCustomerWarningNote.setText("Si vous n’appuyez pas sur le bouton de démarrage client avant 13h00, le jeu commencera automatiquement.");
			if (typeof game.helpStartBtnTxt !== "undefined") game.helpStartBtnTxt.setText('Commencer le jeu');
			if (typeof game.customerStartBtnTxt !== "undefined" && game._customerStartBtnTexts) game.customerStartBtnTxt.setText(game._customerStartBtnTexts.fr);
			if (typeof game.turkceBtnTxt !== "undefined") game.turkceBtnTxt.setText('TÜRKÇE');
			if (typeof game.englishBtnTxt !== "undefined") game.englishBtnTxt.setText('ENGLISH');
			if (typeof game.frenchBtnTxt !== "undefined") game.frenchBtnTxt.setText('FRANÇAIS');
			// Top bar
			if (typeof seedsTxt !== "undefined") seedsTxt.setText('Graines : ' + game.seeds);
			if (typeof coinsTxt !== "undefined") coinsTxt.setText(game.coins + '€');
			if (typeof fameTxt !== "undefined") {
				fameTxt.setText('Fame: ' + game.fame);
				fameTxt.size = 60; // Reduce fame text size in French
			}
			if (typeof dayTxt !== "undefined") dayTxt.setText('Jour : ' + game.day);
			// Seed box
			if (typeof game.seedBoxLabel !== "undefined") game.seedBoxLabel.setText('Graines restantes');
			if (typeof game.seedBoxTxt !== "undefined") game.seedBoxTxt.setText(game.seeds + '');
			// Corn box
			if (typeof game.cornBoxLabel !== "undefined") game.cornBoxLabel.setText('Maïs dans la boîte');
			// Unlock 4 fields
			if (typeof unlock4Txt !== "undefined") unlock4Txt.setText('Débloquer 4 champs (20€)');
			// Nav
			if (typeof leftTxt !== "undefined") leftTxt.setText('<');
			if (typeof rightTxt !== "undefined") rightTxt.setText('>');
			// 4th screen buttons
			if (typeof game.autoCompleteBtnTxt !== "undefined") game.autoCompleteBtnTxt.setText('Remplir les commandes (100€)');
			if (typeof game.autoGrowBtnTxt !== "undefined") game.autoGrowBtnTxt.setText('Faire pousser automatiquement (50€)');
			if (typeof game.autoCollectBtnTxt !== "undefined") game.autoCollectBtnTxt.setText('Récolte automatique (50€)');
			// Pot reduce box
			if (typeof game.potReduceBoxTxt !== "undefined") game.potReduceBoxTxt.setText('Réduire le temps de cuisson de 10s (50€)');
			// Do NOT change any .size property of any Text2 object here, so text size remains the same as in other languages
			// --- Grow help start button horizontally in French ---
			if (typeof game.helpStartBtn !== "undefined") {
				game.helpStartBtn.width = 800;
				game.helpStartBtn.height = 180;
			}
			if (typeof game.helpStartBtnTxt !== "undefined") {
				game.helpStartBtnTxt.x = game.helpStartBtn.x;
				game.helpStartBtnTxt.y = game.helpStartBtn.y;
			}
			LK.effects.flashObject(game.frenchBtn, 0x00ff00, 300);
			return;
		}
	}
	// --- 5th Screen: Türkçe button tap ---
	if (game.currentScreen === 4 && game.turkceBtn && typeof game.turkceBtn.x === "number" && typeof game.turkceBtn.y === "number") {
		var localXt = x - game.turkceBtn.x;
		var localYt = y - game.turkceBtn.y;
		var wt = game.turkceBtn.width || 420;
		var ht = game.turkceBtn.height || 140;
		if (localXt >= -wt / 2 && localXt <= wt / 2 && localYt >= -ht / 2 && localYt <= ht / 2) {
			// Switch all texts to Turkish
			if (typeof game.setTurkishTexts === "function") game.setTurkishTexts();
			if (typeof game.customerStartBtnTxt !== "undefined" && game._customerStartBtnTexts) game.customerStartBtnTxt.setText(game._customerStartBtnTexts.tr);
			if (typeof game.helpWarningNote !== "undefined") game.helpWarningNote.setText("Müşteri kısmına gelmediğiniz sürece müşteri doğmaz ona dikkat edin.");
			if (typeof game.autoCustomerWarningNote !== "undefined") game.autoCustomerWarningNote.setText("Eğer saat 13.00 kadar müşteri başlat tuşuna basılmazsa otomatik oyun başlicak.");
			if (typeof game.helpStartBtn !== "undefined") {
				game.helpStartBtn.width = 600;
				game.helpStartBtn.height = 180;
			}
			if (typeof game.helpStartBtnTxt !== "undefined") {
				game.helpStartBtnTxt.x = game.helpStartBtn.x;
				game.helpStartBtnTxt.y = game.helpStartBtn.y;
			}
			if (typeof fameTxt !== "undefined") fameTxt.size = 90; // Restore fame text size in Turkish
			LK.effects.flashObject(game.turkceBtn, 0x00ff00, 300);
			return;
		}
	}
	// --- 5th Screen: Oyuna Başla button tap ---
	if (game.currentScreen === 4 && game.helpStartBtn && typeof game.helpStartBtn.x === "number" && typeof game.helpStartBtn.y === "number") {
		var localXh = x - game.helpStartBtn.x;
		var localYh = y - game.helpStartBtn.y;
		var wh = game.helpStartBtn.width || 420;
		var hh = game.helpStartBtn.height || 140;
		if (localXh >= -wh / 2 && localXh <= wh / 2 && localYh >= -hh / 2 && localYh <= hh / 2) {
			// Start the game: go to field screen, start clock
			game.currentScreen = 0;
			game.clockRunning = true;
			LK.playMusic('Music'); // Start background music when game starts
			updateScreenVisibility();
			return;
		}
	}
	// Navigation buttons
	if (leftBtn.containsPoint({
		x: x,
		y: y
	})) {
		game.currentScreen = (game.currentScreen + 3) % 4;
		updateScreenVisibility();
		return;
	}
	if (rightBtn.containsPoint({
		x: x,
		y: y
	})) {
		game.currentScreen = (game.currentScreen + 1) % 4;
		updateScreenVisibility();
		return;
	}
	// --- 4th Screen: Auto-complete Button Tap ---
	if (game.currentScreen === 3 && game.autoCompleteBtn && typeof game.autoCompleteBtn.x === "number" && typeof game.autoCompleteBtn.y === "number") {
		var localX = x - game.autoCompleteBtn.x;
		var localY = y - game.autoCompleteBtn.y;
		var w = game.autoCompleteBtn.width || 420;
		var h = game.autoCompleteBtn.height || 140;
		if (localX >= -w / 2 && localX <= w / 2 && localY >= -h / 2 && localY <= h / 2) {
			// Only if not already enabled
			if (!game.autoCompleteEnabled) {
				if (game.coins >= 100) {
					game.coins -= 100;
					if (typeof game.updateCoins === "function") game.updateCoins();
					game.autoCompleteEnabled = true;
					game.autoCompleteBtn.alpha = 0.3;
					game.autoCompleteBtnTxt.setText('Auto-complete Active!');
					LK.effects.flashObject(game.autoCompleteBtn, 0x00ff00, 400);
				} else {
					LK.effects.flashObject(game.autoCompleteBtn, 0xff0000, 400);
				}
			}
			return;
		}
	}
	// --- 4th Screen: Auto-grow Button Tap ---
	if (game.currentScreen === 3 && game.autoGrowBtn && typeof game.autoGrowBtn.x === "number" && typeof game.autoGrowBtn.y === "number") {
		var localXg = x - game.autoGrowBtn.x;
		var localYg = y - game.autoGrowBtn.y;
		var wg = game.autoGrowBtn.width || 420;
		var hg = game.autoGrowBtn.height || 140;
		if (localXg >= -wg / 2 && localXg <= wg / 2 && localYg >= -hg / 2 && localYg <= hg / 2) {
			// Only if not already enabled
			if (!game.autoGrowEnabled) {
				if (game.coins >= 50) {
					game.coins -= 50;
					if (typeof game.updateCoins === "function") game.updateCoins();
					game.autoGrowEnabled = true;
					game.autoGrowBtn.alpha = 0.3;
					game.autoGrowBtnTxt.setText('Auto-grow Active!');
					LK.effects.flashObject(game.autoGrowBtn, 0x00ff00, 400);
					startAutoGrowInterval();
				} else {
					LK.effects.flashObject(game.autoGrowBtn, 0xff0000, 400);
				}
			}
			return;
		}
	}
	// --- 4th Screen: Auto-collect Button Tap ---
	if (game.currentScreen === 3 && game.autoCollectBtn && typeof game.autoCollectBtn.x === "number" && typeof game.autoCollectBtn.y === "number") {
		var localXc = x - game.autoCollectBtn.x;
		var localYc = y - game.autoCollectBtn.y;
		var wc = game.autoCollectBtn.width || 420;
		var hc = game.autoCollectBtn.height || 140;
		if (localXc >= -wc / 2 && localXc <= wc / 2 && localYc >= -hc / 2 && localYc <= hc / 2) {
			// Only if not already enabled
			if (!game.autoCollectEnabled) {
				if (game.coins >= 50) {
					game.coins -= 50;
					if (typeof game.updateCoins === "function") game.updateCoins();
					game.autoCollectEnabled = true;
					game.autoCollectBtn.alpha = 0.3;
					game.autoCollectBtnTxt.setText('Auto-collect Active!');
					LK.effects.flashObject(game.autoCollectBtn, 0x00ff00, 400);
					startAutoCollectInterval();
				} else {
					LK.effects.flashObject(game.autoCollectBtn, 0xff0000, 400);
				}
			}
			return;
		}
	}
	// --- Plate drag start logic (order screen only) ---
	if (game.currentScreen === 2 && game.tezgahPlate && !game._draggingPlate && !game.tezgahPlate.destroyed) {
		// Allow drag if touch is on the plate, regardless of corn
		var localPlateX = x - game.tezgahPlate.x;
		var localPlateY = y - game.tezgahPlate.y;
		var plateW = 700,
			plateH = 280;
		if (localPlateX >= -plateW / 2 && localPlateX <= plateW / 2 && localPlateY >= -plateH / 2 && localPlateY <= plateH / 2) {
			game._draggingPlate = true;
			game._dragPlateOffset = {
				x: game.tezgahPlate.x - x,
				y: game.tezgahPlate.y - y
			};
			game._dragPlateStart = {
				x: game.tezgahPlate.x,
				y: game.tezgahPlate.y
			};
			// Store corn icons and ketchup icons for drag-follow
			game._dragPlateCornIcons = [];
			if (game.tezgahPlate.cornIcons) {
				for (var i = 0; i < game.tezgahPlate.cornIcons.length; i++) {
					var c = game.tezgahPlate.cornIcons[i];
					game._dragPlateCornIcons.push({
						icon: c,
						dx: c.x - game.tezgahPlate.x,
						dy: c.y - game.tezgahPlate.y,
						ketchup: c._ketchupIcon
					});
				}
			}
			return;
		}
	}
	// Per-screen input
	if (game.currentScreen === 0) {
		if (game._draggingPlate) return; // Don't allow field actions while dragging plate
		// Field screen
		if (unlock4BtnContainer.visible && unlock4BtnContainer.containsPoint({
			x: x,
			y: y
		})) {
			if (game.seeds <= 0) {
				LK.effects.flashObject(unlock4Btn, 0xff0000, 400);
				return;
			}
			if (game.coins >= 20 && game.unlockedFields === 4 && game.unlockedFields < game.maxFields) {
				game.coins -= 20;
				// Unlock 4 more fields, but do not exceed maxFields
				var toUnlock = Math.min(4, game.maxFields - game.unlockedFields);
				game.unlockedFields += toUnlock;
				game.updateCoins();
				updateFieldLocks();
				layoutFields();
				updateUnlockBtn();
				// Hide and destroy unlock4BtnContainer and its label after unlocking the second set of fields
				if (unlock4BtnContainer && !unlock4BtnContainer.destroyed) {
					unlock4BtnContainer.destroy();
				}
				if (unlock4Txt && !unlock4Txt.destroyed) {
					unlock4Txt.destroy();
				}
				unlock4Btn.alpha = 0.3;
			} else {
				LK.effects.flashObject(unlock4Btn, 0xff0000, 400);
			}
			return;
		}
		for (var i = 0; i < game.fields.length; i++) {
			var f = game.fields[i];
			if (f.visible && f.containsPoint({
				x: x,
				y: y
			})) {
				f.down(x - f.x, y - f.y, obj);
				return;
			}
		}
	} else if (game.currentScreen === 1) {
		if (game._draggingPlate) return; // Don't allow box/cook actions while dragging plate
		// --- PotReduceBox tap: reduce all pot corns' cook time by 10s for 50 coins ---
		if (game.potReduceBox && typeof game.potReduceBox.x === "number" && typeof game.potReduceBox.y === "number") {
			var localXr = x - game.potReduceBox.x;
			var localYr = y - game.potReduceBox.y;
			var wr = game.potReduceBox.width || 320;
			var hr = game.potReduceBox.height || 160;
			if (localXr >= -wr / 2 && localXr <= wr / 2 && localYr >= -hr / 2 && localYr <= hr / 2) {
				// Only if player has enough coins
				if (game.coins >= 50) {
					// Permanent: reduce all future pot corns' cook time by 10s
					game.potCookTimeReduce += 10000; // 10s in ms
					game.coins -= 50;
					if (typeof game.updateCoins === "function") game.updateCoins();
					LK.effects.flashObject(game.potReduceBox, 0x00ff00, 400);
					game.potReduceBoxTxt.setText('All future cooks 10s faster!');
					LK.setTimeout(function () {
						game.potReduceBoxTxt.setText('Reduce Cook Time by 10s (50$)');
					}, 1200);
				} else {
					LK.effects.flashObject(game.potReduceBox, 0xff0000, 400);
					game.potReduceBoxTxt.setText('Not enough money!');
					LK.setTimeout(function () {
						game.potReduceBoxTxt.setText('Reduce Cook Time by 10s (50$)');
					}, 1200);
				}
				return;
			}
		}
		// Box & Cook screen
		// Prevent interaction with cook asset
		if (game.cornBox.visible && game.cornBox.containsPoint({
			x: x,
			y: y
		})) {
			// Prevent adding corn to pot if there is already corn in the pot
			if (game.potCorns && game.potCorns.length > 0) {
				LK.effects.flashObject(potAsset, 0xff0000, 300);
				return;
			}
			// When box is tapped, drop all corn into pot one by one, each at a different position
			var cornToMove = game.cornBox.cornCount;
			if (cornToMove > 0) {
				// Arrange corns in a circle or grid inside the pot
				var potRadius = 120;
				// Center corns visually in the pot asset (fix: use potAsset center, not offset)
				var centerX = potAsset.x;
				var centerY = potAsset.y - potAsset.height / 2 + 60; // center vertically in pot, adjust as needed
				var angleStep = Math.PI * 2 / Math.max(1, cornToMove);
				for (var i = 0; i < cornToMove; i++) {
					if (game.cornBox.removeCorn(1)) {
						// Calculate position for this corn
						var angle = i * angleStep;
						// For up to 8 corns, use a circle, for more, use a spiral
						var r = potRadius * (cornToMove > 8 ? 0.7 + 0.3 * (i / cornToMove) : 1);
						var px = centerX + Math.cos(angle) * r * 0.7;
						var py = centerY + Math.sin(angle) * r * 0.5;
						// Add a corn asset to pot at calculated position
						var cornInPot = LK.getAsset('corn', {
							anchorX: 0.5,
							anchorY: 0.5,
							width: 80,
							height: 80,
							x: px,
							y: py
						});
						game.stove.addChild(cornInPot);
						// Start cook timer (30s - permanent reduction)
						var cookStart = Date.now();
						var cookTimeReduce = typeof game.potCookTimeReduce === "number" ? game.potCookTimeReduce : 0;
						game.potCorns.push({
							asset: cornInPot,
							startTime: cookStart,
							done: false,
							cookTimeReduce: cookTimeReduce // store reduction for this corn
						});
						// Flash pot for each corn
						LK.effects.flashObject(potAsset, 0xffff00, 100);
					}
				}
			}
			return;
		}
		// Prevent interaction with cook asset and cooked corn count box
		if (game.cookArea && game.cookArea.containsPoint && game.cookArea.containsPoint({
			x: x - game.cookArea.x,
			y: y - game.cookArea.y
		})) {
			// Do nothing, prevent interaction
			return;
		}
		// Collect all cooked corn from pot with a single tap on the pot
		var localPotX = x - game.stove.x;
		var localPotY = y - game.stove.y;
		var potW = potAsset.width,
			potH = potAsset.height;
		// Check if tap is inside the pot area
		if (localPotX >= -potW / 2 && localPotX <= potW / 2 && localPotY >= -potH / 2 && localPotY <= potH / 2) {
			var collected = 0;
			// Collect all cooked corns
			for (var i = game.potCorns.length - 1; i >= 0; i--) {
				var c = game.potCorns[i];
				if (c.done) {
					c.asset.destroy();
					game.potCorns.splice(i, 1);
					game.cookArea.addCookedCorn(1);
					collected++;
				}
			}
			if (collected > 0) {
				LK.effects.flashObject(potAsset, 0x05c49c, 200);
			}
			return;
		}
	} else if (game.currentScreen === 2) {
		if (game._draggingPlate) return; // Don't allow other order actions while dragging plate
		// --- 3rd Screen: Customer Start Button tap ---
		if (game.currentScreen === 2 && game.customerStartBtn && typeof game.customerStartBtn.x === "number" && typeof game.customerStartBtn.y === "number" && !game._customerSpawningStarted) {
			var localXcs = x - game.customerStartBtn.x;
			var localYcs = y - game.customerStartBtn.y;
			var wcs = game.customerStartBtn.width || 420;
			var hcs = game.customerStartBtn.height || 140;
			if (localXcs >= -wcs / 2 && localXcs <= wcs / 2 && localYcs >= -hcs / 2 && localYcs <= hcs / 2) {
				// Start customer spawning: spawn first customer immediately, then every 20s
				game._customerSpawningStarted = true;
				if (game.customerStartBtn) game.customerStartBtn.visible = false;
				if (game.customerStartBtnTxt) game.customerStartBtnTxt.visible = false;
				// Spawn first customer immediately
				spawnCustomerOnOrderScreen();
				// Start interval for next customers (every 22s)
				if (game.customerSpawnTimer) LK.clearInterval(game.customerSpawnTimer);
				game._customerSpawnIntervalStarted = true;
				game.customerSpawnTimer = LK.setInterval(spawnCustomerOnOrderScreen, 22000); // always 22s after first
				return;
			}
		}
		// Order screen
		// Prevent interaction with cooked corn count box
		if (game.cookedCornBox && typeof game.cookedCornBox.x === "number" && typeof game.cookedCornBox.y === "number") {
			var localX = x - game.cookedCornBox.x;
			var localY = y - game.cookedCornBox.y;
			var w = 220,
				h = 220;
			if (localX >= -w / 2 && localX <= w / 2 && localY >= -h / 2 && localY <= h / 2) {
				// When cooked corn box is tapped, show a plate on tezgah (if not already present)
				if (!game.tezgahPlate || game.tezgahPlate.destroyed) {
					game.tezgahPlate = new Plate();
					// Center the plate horizontally on the tezgah
					game.tezgahPlate.x = game.counterAsset.x;
					// Place the plate vertically so it sits visually on the tezgah
					game.tezgahPlate.y = game.counterAsset.y - game.counterAsset.height / 2;
					game.addChild(game.tezgahPlate);
					game.tezgahPlate.cornIcons = [];
				}
				// Only move one cooked corn per tap, and use 'corn' asset for the plate
				var cookedCount = game.cookArea && typeof game.cookArea.cookedCorn === "number" ? game.cookArea.cookedCorn : 0;
				// Only add corn to plate if there is a plate present and it is not destroyed
				if (game.tezgahPlate && !game.tezgahPlate.destroyed && cookedCount > 0) {
					// Limit to 4 corns on the plate
					var plateCornCount = 0;
					if (game.tezgahPlate.cornIcons) plateCornCount = game.tezgahPlate.cornIcons.length;
					if (plateCornCount >= 4) {
						LK.effects.flashObject(game.tezgahPlate, 0xff0000, 300);
						return;
					}
					// Remove one cooked corn from cookArea
					if (game.cookArea.removeCookedCorn(1)) {
						// Place a single corn icon (asset: 'corn') on the plate
						var iconW = 80,
							iconH = 80;
						// Place new corn icon at next position in row, centered on plate
						var xOnPlate = game.tezgahPlate.x - 120 + plateCornCount * (iconW + 10);
						var yOnPlate = game.tezgahPlate.y - 10;
						var cornIcon = LK.getAsset('corn', {
							anchorX: 0.5,
							anchorY: 0.5,
							width: iconW,
							height: iconH,
							x: xOnPlate,
							y: yOnPlate
						});
						game.addChild(cornIcon);
						if (!game.tezgahPlate.cornIcons) game.tezgahPlate.cornIcons = [];
						game.tezgahPlate.cornIcons.push(cornIcon);
						// Update cooked corn box text to match new cooked corn count
						if (game.cookedCornBoxTxt) {
							game.cookedCornBoxTxt.setText(game.cookArea.cookedCorn);
						}
					}
				}
				return;
			}
			// --- TezgahBox1: Add ketchup to all corns on plate if tapped ---
			if (game.tezgahBox1 && typeof game.tezgahBox1.x === "number" && typeof game.tezgahBox1.y === "number") {
				var localX1 = x - game.tezgahBox1.x;
				var localY1 = y - game.tezgahBox1.y;
				var w1 = game.tezgahBox1.width || 180;
				var h1 = game.tezgahBox1.height || 180;
				if (localX1 >= -w1 / 2 && localX1 <= w1 / 2 && localY1 >= -h1 / 2 && localY1 <= h1 / 2) {
					// Only if there is at least one corn on the plate
					if (game.tezgahPlate && game.tezgahPlate.cornIcons && game.tezgahPlate.cornIcons.length > 0) {
						// Add ketchup icon on top of every corn on the plate
						for (var i = 0; i < game.tezgahPlate.cornIcons.length; i++) {
							var corn = game.tezgahPlate.cornIcons[i];
							// Prevent double ketchup
							if (!corn._hasKetchup) {
								var ketchupIcon = LK.getAsset('ketchup', {
									anchorX: 0.5,
									anchorY: 0.5,
									width: 40,
									height: 40,
									x: corn.x,
									y: corn.y - 20
								});
								game.addChild(ketchupIcon);
								corn._hasKetchup = true;
								corn._ketchupIcon = ketchupIcon;
							}
						}
					}
					return;
				}
			}
			// --- TezgahBox2: Add mayonnaise to all corns on plate if tapped, under ketchup if present ---
			if (game.tezgahBox2 && typeof game.tezgahBox2.x === "number" && typeof game.tezgahBox2.y === "number") {
				var localX2 = x - game.tezgahBox2.x;
				var localY2 = y - game.tezgahBox2.y;
				var w2 = game.tezgahBox2.width || 180;
				var h2 = game.tezgahBox2.height || 180;
				if (localX2 >= -w2 / 2 && localX2 <= w2 / 2 && localY2 >= -h2 / 2 && localY2 <= h2 / 2) {
					// Only if there is at least one corn on the plate
					if (game.tezgahPlate && game.tezgahPlate.cornIcons && game.tezgahPlate.cornIcons.length > 0) {
						for (var i = 0; i < game.tezgahPlate.cornIcons.length; i++) {
							var corn = game.tezgahPlate.cornIcons[i];
							// Prevent double mayonnaise
							if (!corn._hasMayonnaise) {
								// If ketchup exists, mayonnaise should be under it
								var mayoY = corn.y - 10; // slightly above corn
								var mayoZ = 0;
								if (corn._hasKetchup && corn._ketchupIcon) {
									// Place mayonnaise under ketchup
									mayoY = corn.y - 10; // mayonnaise closer to corn, ketchup above
									mayoZ = 0; // zIndex not supported, so add order: add mayonnaise first, then ketchup
									// Remove and re-add ketchup to ensure it's above mayonnaise
									if (!corn._ketchupIcon.destroyed) {
										corn._ketchupIcon.destroy();
									}
									// Add mayonnaise first
									var mayoIcon = LK.getAsset('mayonnaise', {
										anchorX: 0.5,
										anchorY: 0.5,
										width: 40,
										height: 40,
										x: corn.x,
										y: mayoY
									});
									game.addChild(mayoIcon);
									corn._hasMayonnaise = true;
									corn._mayonnaiseIcon = mayoIcon;
									// Add ketchup again above mayonnaise
									var ketchupIcon = LK.getAsset('ketchup', {
										anchorX: 0.5,
										anchorY: 0.5,
										width: 40,
										height: 40,
										x: corn.x,
										y: corn.y - 20
									});
									game.addChild(ketchupIcon);
									corn._ketchupIcon = ketchupIcon;
									corn._hasKetchup = true;
								} else {
									// No ketchup, just add mayonnaise
									var mayoIcon = LK.getAsset('mayonnaise', {
										anchorX: 0.5,
										anchorY: 0.5,
										width: 40,
										height: 40,
										x: corn.x,
										y: mayoY
									});
									game.addChild(mayoIcon);
									corn._hasMayonnaise = true;
									corn._mayonnaiseIcon = mayoIcon;
								}
							}
						}
					}
					return;
				}
			}
		}
		// Order area removed
	}
};
// --- Plate drag move/up logic ---
game.move = function (x, y, obj) {
	if (game._draggingPlate && game.tezgahPlate && !game.tezgahPlate.destroyed) {
		// Move plate
		game.tezgahPlate.x = x + game._dragPlateOffset.x;
		game.tezgahPlate.y = y + game._dragPlateOffset.y;
		// Move corn icons and ketchup icons with plate
		if (game._dragPlateCornIcons) {
			for (var i = 0; i < game._dragPlateCornIcons.length; i++) {
				var c = game._dragPlateCornIcons[i];
				if (c.icon && !c.icon.destroyed) {
					c.icon.x = game.tezgahPlate.x + c.dx;
					c.icon.y = game.tezgahPlate.y + c.dy;
				}
				if (c.ketchup && !c.ketchup.destroyed) {
					c.ketchup.x = game.tezgahPlate.x + c.dx;
					c.ketchup.y = game.tezgahPlate.y + c.dy - 20;
				}
				if (c.icon && c.icon._mayonnaiseIcon && !c.icon._mayonnaiseIcon.destroyed) {
					c.icon._mayonnaiseIcon.x = game.tezgahPlate.x + c.dx;
					c.icon._mayonnaiseIcon.y = game.tezgahPlate.y + c.dy - 10;
				}
			}
		}
		// Check for intersection with any customer
		if (game.customers) {
			for (var i = 0; i < game.customers.length; i++) {
				var cust = game.customers[i];
				if (cust && cust.visible && !cust.destroyed) {
					// Use bounding box for customer (body/head)
					var custX = cust.x,
						custY = cust.y;
					var custW = 220,
						custH = 320 + 180; // body+head
					var plateX = game.tezgahPlate.x,
						plateY = game.tezgahPlate.y;
					var plateW = 700,
						plateH = 280;
					// Simple AABB collision
					if (plateX + plateW / 2 > custX - custW / 2 && plateX - plateW / 2 < custX + custW / 2 && plateY + plateH / 2 > custY - custH && plateY - plateH / 2 < custY) {
						// Deliver plate to this customer!
						// Check if order matches
						var order = cust.order;
						var deliveredCount = game.tezgahPlate.cornIcons ? game.tezgahPlate.cornIcons.length : 0;
						var deliveredKetchup = 0;
						var deliveredMayonnaise = 0;
						for (var j = 0; j < deliveredCount; j++) {
							if (game.tezgahPlate.cornIcons[j]._hasKetchup) deliveredKetchup++;
							if (game.tezgahPlate.cornIcons[j]._hasMayonnaise) deliveredMayonnaise++;
						}
						var wantKetchup = 0;
						var wantMayonnaise = 0;
						if (order && order.sauces) {
							for (var j = 0; j < order.sauces.length; j++) {
								if (order.sauces[j] === "ketchup") wantKetchup++;
								if (order.sauces[j] === "mayonnaise") wantMayonnaise++;
							}
						}
						var ok = true;
						// Check corn count
						if (!order || deliveredCount !== order.cornCount) ok = false;
						// Check ketchup count (if ketchup is in order, must have at least that many with ketchup)
						if (wantKetchup > deliveredKetchup) ok = false;
						// Check mayonnaise: if customer wants only mayonnaise, all delivered corns must have mayonnaise and none must have ketchup
						if (order && order.sauces.length === 1 && order.sauces[0] === "mayonnaise") {
							// All delivered corns must have mayonnaise and must NOT have ketchup
							for (var j = 0; j < deliveredCount; j++) {
								if (!game.tezgahPlate.cornIcons[j]._hasMayonnaise || game.tezgahPlate.cornIcons[j]._hasKetchup) {
									ok = false;
									break;
								}
							}
						}
						// (If order has no ketchup, allow extra ketchup)
						if (ok) {
							// Success!
							LK.effects.flashObject(cust, 0x00ff00, 400);
							// Calculate coins based on corn count delivered
							var deliveredCoins = 0;
							if (order && order.cornCount === 1) deliveredCoins = 5;else if (order && order.cornCount === 2) deliveredCoins = 10;else if (order && order.cornCount === 3) deliveredCoins = 15;else if (order && order.cornCount === 4) deliveredCoins = 20;else deliveredCoins = 5; // fallback
							game.coins += deliveredCoins;
							game.updateCoins();
							// Fame reward for correct and on-time delivery
							if (typeof game.fame === "number") {
								game.fame += 10;
								if (game.fame > 100) game.fame = 100;
								if (typeof game.updateFame === "function") game.updateFame();
							}
							// Remove corn icons and their sauce icons, but do not destroy the plate itself
							for (var j = 0; j < game.tezgahPlate.cornIcons.length; j++) {
								if (game.tezgahPlate.cornIcons[j]._ketchupIcon && !game.tezgahPlate.cornIcons[j]._ketchupIcon.destroyed) {
									game.tezgahPlate.cornIcons[j]._ketchupIcon.destroy();
								}
								if (game.tezgahPlate.cornIcons[j]._mayonnaiseIcon && !game.tezgahPlate.cornIcons[j]._mayonnaiseIcon.destroyed) {
									game.tezgahPlate.cornIcons[j]._mayonnaiseIcon.destroy();
								}
								if (!game.tezgahPlate.cornIcons[j].destroyed) game.tezgahPlate.cornIcons[j].destroy();
							}
							game.tezgahPlate.cornIcons = [];
							// Remove customer
							if (!cust.destroyed) cust.destroy();
							game.customers[i] = null;
							// Animate plate back to its original position after delivery
							if (_typeof(game._dragPlateStart) === "object" && game.tezgahPlate && !game.tezgahPlate.destroyed) {
								var origX = game._dragPlateStart.x;
								var origY = game._dragPlateStart.y;
								tween(game.tezgahPlate, {
									x: origX,
									y: origY
								}, {
									duration: 400,
									easing: tween.cubicOut
								});
							}
						} else {
							// Wrong order
							LK.effects.flashObject(cust, 0xff0000, 400);
						}
						// End drag
						game._draggingPlate = false;
						game._dragPlateCornIcons = null;
						return;
					}
				}
			}
		}
	}
};
game.up = function (x, y, obj) {
	if (game._draggingPlate) {
		// Snap plate back to original position if not delivered
		if (game.tezgahPlate && !game.tezgahPlate.destroyed) {
			game.tezgahPlate.x = game._dragPlateStart.x;
			game.tezgahPlate.y = game._dragPlateStart.y;
			// Move corn icons and ketchup icons back
			if (game._dragPlateCornIcons) {
				for (var i = 0; i < game._dragPlateCornIcons.length; i++) {
					var c = game._dragPlateCornIcons[i];
					if (c.icon && !c.icon.destroyed) {
						c.icon.x = game.tezgahPlate.x + c.dx;
						c.icon.y = game.tezgahPlate.y + c.dy;
					}
					if (c.ketchup && !c.ketchup.destroyed) {
						c.ketchup.x = game.tezgahPlate.x + c.dx;
						c.ketchup.y = game.tezgahPlate.y + c.dy - 20;
					}
					if (c.icon && c.icon._mayonnaiseIcon && !c.icon._mayonnaiseIcon.destroyed) {
						c.icon._mayonnaiseIcon.x = game.tezgahPlate.x + c.dx;
						c.icon._mayonnaiseIcon.y = game.tezgahPlate.y + c.dy - 10;
					}
				}
			}
		}
		game._draggingPlate = false;
		game._dragPlateCornIcons = null;
	}
};
// --- Game update ---
game.update = function () {
	// Update all fields for grow/ready text
	for (var i = 0; i < game.fields.length; i++) {
		if (game.fields[i].visible) {
			if (typeof game.fields[i].update === "function") {
				game.fields[i].update();
			}
		}
	}
	// Update all customers for leave timers
	if (game.customers) {
		for (var i = 0; i < game.customers.length; i++) {
			if (game.customers[i] && !game.customers[i].destroyed && typeof game.customers[i].update === "function") {
				game.customers[i].update();
			}
		}
	}
	// --- Auto-complete logic: if enabled, auto-complete all possible orders ---
	if (game.autoCompleteEnabled && game.customers && game.currentScreen === 2) {
		for (var i = 0; i < game.customers.length; i++) {
			var cust = game.customers[i];
			if (cust && !cust.destroyed && game.canAutoCompleteOrder && game.autoCompleteOrder) {
				// Try to auto-complete if possible
				if (game.canAutoCompleteOrder(cust)) {
					game.autoCompleteOrder(cust);
				}
			}
		}
	}
	// --- Auto-grow logic: if enabled, plant in all empty unlocked fields ---
	if (game.autoGrowEnabled && typeof game.autoGrowTick === "function" && game.currentScreen === 0) {
		game.autoGrowTick();
	}
	// --- Auto-collect logic: if enabled, harvest all ready unlocked fields ---
	if (game.autoCollectEnabled && typeof game.autoCollectTick === "function" && game.currentScreen === 0) {
		game.autoCollectTick();
	}
	// Update corn box count label live on 2nd screen
	if (game.currentScreen === 1 && typeof game.cornBoxCountLabel !== "undefined" && game.cornBox && typeof game.cornBox.cornCount === "number") {
		game.cornBoxCountLabel.setText(game.cornBox.cornCount + '');
	}
	// Update cooked corn count box on 2nd screen (BoxCook) live
	if (game.currentScreen === 1 && game.cookedCornBox2 && game.cookArea && typeof game.cookArea.cookedCorn === "number") {
		game.cookedCornBox2Txt.setText(game.cookArea.cookedCorn);
		game.cookedCornBox2.visible = true;
	} else if (game.cookedCornBox2) {
		game.cookedCornBox2Txt.setText('');
		game.cookedCornBox2.visible = false;
	}
	// No automatic planting: Corn only grows when planted by the player
	// --- Pot cooking logic ---
	if (game.stove && game.potCorns) {
		var minTimeLeft = null;
		for (var i = 0; i < game.potCorns.length; i++) {
			var c = game.potCorns[i];
			// --- Add timer label above each corn in the pot ---
			if (!c.timerLabel) {
				c.timerLabel = new Text2('', {
					size: 40,
					fill: "#fff"
				});
				c.timerLabel.anchor.set(0.5, 1);
				c.timerLabel.x = c.asset.x;
				c.timerLabel.y = c.asset.y - 50;
				game.stove.addChild(c.timerLabel);
			}
			// Always update label position to follow corn
			c.timerLabel.x = c.asset.x;
			c.timerLabel.y = c.asset.y - 50;
			if (!c.done) {
				// Use permanent reduction for this corn (if present), fallback to 0
				var cookTimeReduce = typeof c.cookTimeReduce === "number" ? c.cookTimeReduce : typeof game.potCookTimeReduce === "number" ? game.potCookTimeReduce : 0;
				var elapsed = Date.now() - c.startTime;
				var left = 30000 - cookTimeReduce - elapsed;
				if (left <= 0) {
					// Done cooking
					c.done = true;
					c.asset.alpha = 1;
					c.asset.tint = 0x05c49c; // cooked color
					LK.effects.flashObject(c.asset, 0x05c49c, 300);
					left = 0;
				} else {
					c.asset.alpha = 0.7;
					c.asset.tint = 0xb8b031; // raw color
				}
				// Show remaining time above corn
				var secLeft = Math.ceil(left / 1000);
				c.timerLabel.setText(secLeft + "s");
				c.timerLabel.visible = true;
				if (minTimeLeft === null || left < minTimeLeft) minTimeLeft = left;
			} else {
				// Hide label above cooked corn (no 'Done' text)
				c.timerLabel.setText('');
				c.timerLabel.visible = false;
			}
			// If the corn asset is destroyed (collected), also destroy the label
			if (c.asset.destroyed && c.timerLabel) {
				c.timerLabel.destroy();
				c.timerLabel = null;
			}
			// Hide "Done" label if corn is not in potCorns anymore (collected)
			if ((!c.asset || c.asset.destroyed) && c.timerLabel) {
				c.timerLabel.visible = false;
			}
			// Remove global pot timer text (game.potTimerTxt) so only per-corn timers are shown
			game.potTimerTxt.setText('');
			game.potTimerTxt.visible = false;
		}
		// Remove all other pot timer text except per-corn timers on 2nd screen
		// (No global pot timer text on 2nd screen)
		// Remove timer labels for any corns that have been removed from potCorns
		for (var i = game.potCorns.length - 1; i >= 0; i--) {
			var c = game.potCorns[i];
			if (c.asset.destroyed && c.timerLabel) {
				c.timerLabel.destroy();
				c.timerLabel = null;
			}
		}
	}
	// Show pot lid only if there are corns in the pot
	if (typeof potLid !== "undefined" && typeof game.potCorns !== "undefined") {
		if (game.potCorns.length > 0) {
			potLid.visible = true;
		} else {
			potLid.visible = false;
		}
	}
	// Hide corn box above pot while pot is cooking, show it again when pot is empty
	if (typeof game.cornBox !== "undefined") {
		if (game.potCorns && game.potCorns.length > 0) {
			game.cornBox.visible = false;
			if (typeof game.cornBoxLabel !== "undefined") game.cornBoxLabel.visible = false;
			if (typeof game.cornBoxCountLabel !== "undefined") game.cornBoxCountLabel.visible = false;
		} else {
			// Only show on boxcook screen
			if (game.currentScreen === 1) {
				game.cornBox.visible = true;
				if (typeof game.cornBoxLabel !== "undefined") game.cornBoxLabel.visible = true;
				if (typeof game.cornBoxCountLabel !== "undefined") game.cornBoxCountLabel.visible = true;
			}
		}
	}
	// Update cooked corn count box value live on order screen
	if (game.currentScreen === 2 && game.cookedCornBox && game.cookArea && typeof game.cookArea.cookedCorn === "number") {
		game.cookedCornBoxTxt.setText(game.cookArea.cookedCorn);
		game.cookedCornBox.visible = true;
	} else if (game.cookedCornBox) {
		// Hide or clear cooked corn count on other screens
		game.cookedCornBoxTxt.setText('');
		game.cookedCornBox.visible = false;
	}
};
// --- Reset function for new game ---
game.resetGame = function () {
	// Destroy tezgah plate and its corn icons if present
	if (game.tezgahPlate) {
		if (game.tezgahPlate.cornIcons) {
			for (var i = 0; i < game.tezgahPlate.cornIcons.length; i++) {
				var c = game.tezgahPlate.cornIcons[i];
				if (c._ketchupIcon && !c._ketchupIcon.destroyed) c._ketchupIcon.destroy();
				if (c._mayonnaiseIcon && !c._mayonnaiseIcon.destroyed) c._mayonnaiseIcon.destroy();
				if (!c.destroyed) c.destroy();
			}
		}
		if (!game.tezgahPlate.destroyed) game.tezgahPlate.destroy();
		game.tezgahPlate = null;
	}
	// Reset clock to 08:00
	game.clockHour = 8;
	game.clockMinute = 0;
	game.clockTime = 8 * 60;
	game.clockRunning = true;
	game.day = 1;
	if (typeof clockTxt !== "undefined") clockTxt.setText('08:00');
	if (typeof dayTxt !== "undefined") dayTxt.setText('Day: ' + game.day);
	game.coins = 20;
	game.unlockedFields = 4;
	game.seeds = 4;
	game.fame = 0;
	if (typeof game.updateFame === "function") game.updateFame();
	if (typeof game.updateSeeds === "function") game.updateSeeds();
	game.updateCoins();
	updateFieldLocks();
	layoutFields();
	updateUnlockBtn();
	for (var i = 0; i < game.fields.length; i++) {
		game.fields[i].reset();
	}
	game.cornBox.reset();
	game.cookArea.reset();
	// Reset permanent pot cook time reduction
	game.potCookTimeReduce = 0;
	// Reset stove/pot
	if (game.potCorns) {
		for (var i = 0; i < game.potCorns.length; i++) {
			if (game.potCorns[i].asset) game.potCorns[i].asset.destroy();
		}
		game.potCorns = [];
	}
	if (game.potTimerTxt) game.potTimerTxt.setText('');
	// game.orderArea.reset();
	// game.orderArea.newOrder();
	// Reset to help screen and update visibility
	game.currentScreen = 4;
	game.clockRunning = false;
	// Remove all customers on reset (they will be spawned by timer on 3rd screen)
	if (game.customers) {
		for (var i = 0; i < game.customers.length; i++) {
			if (game.customers[i] && !game.customers[i].destroyed) {
				game.customers[i].destroy();
			}
		}
		game.customers = [];
	}
	// Hide and destroy unlock4BtnContainer and label if more than 4 fields are unlocked after reset
	if (game.unlockedFields > 4) {
		if (unlock4BtnContainer && !unlock4BtnContainer.destroyed) {
			unlock4BtnContainer.destroy();
		}
		if (unlock4Txt && !unlock4Txt.destroyed) {
			unlock4Txt.destroy();
		}
		unlock4Btn.alpha = 0.3;
	}
	updateScreenVisibility();
};
// --- Asset definitions (for static analysis) ---
// These are not real code, but LK will auto-create these assets as used above:
// field: green box, corn: yellow ellipse, lock: gray lock, box: brown box, cook: pot, cooked: orange ellipse, order: tray, ketchup/mayonnaise/cheese: colored circles, deliver: blue button, unlock: green button
// --- End of code ---
:quality(85)/https://cdn.frvr.ai/683ca03b7c5dda627b25c83b.png%3F3) 
 Mısır. In-Game asset. 2d. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/683ca0627c5dda627b25c844.png%3F3) 
 Arkaplanı sil
:quality(85)/https://cdn.frvr.ai/683caa577c5dda627b25c8b8.png%3F3) 
 Arkaplanı sil
:quality(85)/https://cdn.frvr.ai/683cab097c5dda627b25c8e6.png%3F3) 
 Arkaplanı olmasın.
:quality(85)/https://cdn.frvr.ai/683df170e40eba45996582fa.png%3F3) 
 Arkaplanı sil
:quality(85)/https://cdn.frvr.ai/683df48be40eba459965838e.png%3F3) 
 Tahta arkaplan. In-Game asset. 2d. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/683df748e40eba45996583f4.png%3F3) 
 Arkaplanı sil
:quality(85)/https://cdn.frvr.ai/683f3d6622dd03b6861c6df6.png%3F3) 
 Cadde arka planı. In-Game asset. 2d. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/683f405222dd03b6861c6e0e.png%3F3) 
 Konuşma balonu. In-Game asset. 2d. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/683f42b022dd03b6861c6e47.png%3F3) 
 Ketçap kutusu. In-Game asset. 2d. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/683f42ea22dd03b6861c6e5b.png%3F3) 
 Mayonez kutusu. In-Game asset. 2d. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/683f444f22dd03b6861c6e7c.png%3F3) 
 Dökülmüş ketçap. In-Game asset. 2d. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/683f57ef22dd03b6861c7039.png%3F3) 
 Dökülmüş mayonez. In-Game asset. 2d. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/68440c2070480cb20f63291d.png%3F3) 
 Delete hand
:quality(85)/https://cdn.frvr.ai/68440efb70480cb20f63293a.png%3F3) 
 Türkiye bayrağı. In-Game asset. 2d. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/68440fa570480cb20f632947.png%3F3) 
 İngiliz bayrağı. In-Game asset. 2d. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/6844104370480cb20f632953.png%3F3) 
 Fransa bayrağı. In-Game asset. 2d. High contrast. No shadows