<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Sushi Chef - Rosy's Arcade</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
            min-height: 100vh;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            color: white;
            padding: 20px;
            user-select: none;
        }
        h1 {
            font-size: 2.5rem;
            margin-bottom: 10px;
            text-shadow: 0 0 20px #ff6b6b;
        }
        .game-container {
            background: #0f0f23;
            border-radius: 12px;
            padding: 20px;
            box-shadow: 0 0 40px rgba(255, 107, 107, 0.2);
            max-width: 600px;
            width: 100%;
        }
        .stats {
            display: flex;
            justify-content: space-between;
            margin-bottom: 15px;
            font-size: 1.1rem;
        }
        .score { color: #ffd93d; }
        .timer { color: #ff6b6b; }
        .streak { color: #6bcb77; }

        .order-section {
            background: #1a1a3a;
            border-radius: 8px;
            padding: 15px;
            margin-bottom: 15px;
            border: 2px solid #ff6b6b;
        }
        .order-label {
            font-size: 0.9rem;
            color: #888;
            margin-bottom: 8px;
        }
        .order-display {
            display: flex;
            gap: 8px;
            justify-content: center;
            flex-wrap: wrap;
            min-height: 50px;
            align-items: center;
        }

        .plate-section {
            background: #1a1a3a;
            border-radius: 8px;
            padding: 15px;
            margin-bottom: 15px;
            border: 2px solid #6bcb77;
        }
        .plate-label {
            font-size: 0.9rem;
            color: #888;
            margin-bottom: 8px;
        }
        .plate-display {
            display: flex;
            gap: 8px;
            justify-content: center;
            flex-wrap: wrap;
            min-height: 50px;
            align-items: center;
        }

        .ingredient {
            font-size: 2rem;
            padding: 5px 10px;
            background: #2a2a4a;
            border-radius: 8px;
            transition: transform 0.1s;
        }
        .ingredient.bounce {
            animation: bounce 0.3s ease;
        }
        @keyframes bounce {
            0%, 100% { transform: scale(1); }
            50% { transform: scale(1.2); }
        }

        .ingredients-grid {
            display: grid;
            grid-template-columns: repeat(4, 1fr);
            gap: 10px;
            margin-bottom: 15px;
        }
        .ingredient-btn {
            font-size: 2.5rem;
            padding: 15px;
            background: #2a2a4a;
            border: 2px solid #444;
            border-radius: 12px;
            cursor: pointer;
            transition: all 0.2s;
        }
        .ingredient-btn:hover {
            background: #3a3a5a;
            transform: scale(1.05);
            border-color: #ffd93d;
        }
        .ingredient-btn:active {
            transform: scale(0.95);
        }

        .action-buttons {
            display: flex;
            gap: 10px;
        }
        .action-btn {
            flex: 1;
            padding: 15px;
            font-size: 1.1rem;
            font-weight: bold;
            border: none;
            border-radius: 8px;
            cursor: pointer;
            transition: all 0.2s;
        }
        .serve-btn {
            background: #6bcb77;
            color: #1a1a2e;
        }
        .serve-btn:hover {
            background: #5ab966;
        }
        .clear-btn {
            background: #ff6b6b;
            color: white;
        }
        .clear-btn:hover {
            background: #e85555;
        }

        .message {
            text-align: center;
            font-size: 1.5rem;
            padding: 20px;
            margin-top: 10px;
            border-radius: 8px;
            opacity: 0;
            transition: opacity 0.3s;
        }
        .message.show {
            opacity: 1;
        }
        .message.success {
            background: rgba(107, 203, 119, 0.2);
            color: #6bcb77;
        }
        .message.error {
            background: rgba(255, 107, 107, 0.2);
            color: #ff6b6b;
        }

        .game-over {
            display: none;
            text-align: center;
            padding: 30px;
        }
        .game-over h2 {
            font-size: 2rem;
            color: #ff6b6b;
            margin-bottom: 15px;
        }
        .game-over .final-score {
            font-size: 3rem;
            color: #ffd93d;
            margin-bottom: 10px;
        }
        .game-over .high-score {
            font-size: 1.2rem;
            color: #6bcb77;
            margin-bottom: 20px;
        }
        .restart-btn {
            padding: 15px 40px;
            font-size: 1.2rem;
            background: #ff6b6b;
            color: white;
            border: none;
            border-radius: 8px;
            cursor: pointer;
            transition: background 0.2s;
        }
        .restart-btn:hover {
            background: #e85555;
        }

        .controls {
            margin-top: 20px;
            text-align: center;
            color: #888;
            font-size: 0.9rem;
        }

        .sushi-types {
            font-size: 0.8rem;
            color: #666;
            margin-top: 10px;
            text-align: center;
        }
    </style>
</head>
<body>
    <h1>🍣 Sushi Chef</h1>

    <div class="game-container">
        <div class="stats">
            <span class="score">Score: <span id="score">0</span></span>
            <span class="timer">Time: <span id="timer">60</span>s</span>
            <span class="streak">Streak: <span id="streak">0</span>🔥</span>
        </div>

        <div id="gameArea">
            <div class="order-section">
                <div class="order-label">📋 Customer Order:</div>
                <div class="order-display" id="orderDisplay"></div>
            </div>

            <div class="plate-section">
                <div class="plate-label">🍽️ Your Plate:</div>
                <div class="plate-display" id="plateDisplay"></div>
            </div>

            <div class="ingredients-grid" id="ingredientsGrid"></div>

            <div class="action-buttons">
                <button class="action-btn clear-btn" id="clearBtn">🗑️ Clear</button>
                <button class="action-btn serve-btn" id="serveBtn">✨ Serve!</button>
            </div>

            <div class="message" id="message"></div>
        </div>

        <div class="game-over" id="gameOver">
            <h2>⏰ Time's Up!</h2>
            <div class="final-score" id="finalScore">0</div>
            <div class="high-score">Best: <span id="highScore">0</span></div>
            <button class="restart-btn" id="restartBtn">🍣 Play Again</button>
        </div>
    </div>

    <div class="controls">
        <p>Click ingredients to add them to your plate, then serve!</p>
        <p>Match the order exactly to score points. Build a streak for bonus points!</p>
    </div>

    <script>
        // Ingredients available
        const ingredients = ['🍚', '🐟', '🍣', '🥒', '🥑', '🦐', '🐙', '🥚', '🌊', '🔥', '🥢', '🍋'];

        // Sushi recipes (what ingredients make what)
        const recipes = [
            { name: 'Salmon Roll', items: ['🍚', '🐟', '🌊'] },
            { name: 'Tuna Nigiri', items: ['🍚', '🐟'] },
            { name: 'Shrimp Tempura', items: ['🦐', '🔥', '🍚'] },
            { name: 'California Roll', items: ['🍚', '🥒', '🥑', '🦐'] },
            { name: 'Octopus Sushi', items: ['🍚', '🐙'] },
            { name: 'Tamago', items: ['🍚', '🥚'] },
            { name: 'Cucumber Roll', items: ['🍚', '🥒', '🌊'] },
            { name: 'Avocado Roll', items: ['🍚', '🥑', '🌊'] },
            { name: 'Spicy Tuna', items: ['🍚', '🐟', '🔥'] },
            { name: 'Dragon Roll', items: ['🍚', '🦐', '🥑', '🔥'] },
            { name: 'Simple Nigiri', items: ['🍚', '🐟'] },
            { name: 'Veggie Roll', items: ['🍚', '🥒', '🥑'] },
        ];

        // Game state
        let score = 0;
        let timeLeft = 60;
        let streak = 0;
        let currentOrder = [];
        let plate = [];
        let gameRunning = false;
        let timerInterval = null;
        let highScore = parseInt(localStorage.getItem('sushiHighScore') || 0);

        // DOM elements
        const scoreEl = document.getElementById('score');
        const timerEl = document.getElementById('timer');
        const streakEl = document.getElementById('streak');
        const orderDisplay = document.getElementById('orderDisplay');
        const plateDisplay = document.getElementById('plateDisplay');
        const ingredientsGrid = document.getElementById('ingredientsGrid');
        const messageEl = document.getElementById('message');
        const gameArea = document.getElementById('gameArea');
        const gameOver = document.getElementById('gameOver');
        const finalScoreEl = document.getElementById('finalScore');
        const highScoreEl = document.getElementById('highScore');
        const clearBtn = document.getElementById('clearBtn');
        const serveBtn = document.getElementById('serveBtn');
        const restartBtn = document.getElementById('restartBtn');

        // Initialize ingredient buttons
        function initIngredients() {
            ingredientsGrid.innerHTML = '';
            ingredients.forEach(ing => {
                const btn = document.createElement('button');
                btn.className = 'ingredient-btn';
                btn.textContent = ing;
                btn.addEventListener('click', () => addToPlate(ing));
                ingredientsGrid.appendChild(btn);
            });
        }

        // Generate a new order
        function generateOrder() {
            const recipe = recipes[Math.floor(Math.random() * recipes.length)];
            currentOrder = [...recipe.items];
            renderOrder();
        }

        // Render the order display
        function renderOrder() {
            orderDisplay.innerHTML = currentOrder.map(item =>
                `<span class="ingredient">${item}</span>`
            ).join('');
        }

        // Render the plate display
        function renderPlate() {
            plateDisplay.innerHTML = plate.length > 0
                ? plate.map(item => `<span class="ingredient">${item}</span>`).join('')
                : '<span style="color: #666;">Empty - add ingredients!</span>';
        }

        // Add ingredient to plate
        function addToPlate(ingredient) {
            if (!gameRunning) return;
            plate.push(ingredient);
            renderPlate();

            // Add bounce animation
            const lastIngredient = plateDisplay.lastElementChild;
            if (lastIngredient) {
                lastIngredient.classList.add('bounce');
                setTimeout(() => lastIngredient.classList.remove('bounce'), 300);
            }
        }

        // Clear the plate
        function clearPlate() {
            plate = [];
            renderPlate();
        }

        // Check if plate matches order
        function checkOrder() {
            if (plate.length !== currentOrder.length) return false;

            const sortedPlate = [...plate].sort();
            const sortedOrder = [...currentOrder].sort();

            return sortedPlate.every((item, i) => item === sortedOrder[i]);
        }

        // Serve the dish
        function serveDish() {
            if (!gameRunning) return;

            if (checkOrder()) {
                // Correct order!
                streak++;
                const bonus = streak > 1 ? streak * 5 : 0;
                const points = 10 + bonus;
                score += points;

                showMessage(`Perfect! +${points} points${bonus > 0 ? ` (${streak}x streak!)` : ''}`, 'success');

                // Update displays
                scoreEl.textContent = score;
                streakEl.textContent = streak;

                // New order
                plate = [];
                renderPlate();
                generateOrder();
            } else {
                // Wrong order
                streak = 0;
                streakEl.textContent = streak;
                showMessage('Wrong order! Try again.', 'error');
            }
        }

        // Show message
        function showMessage(text, type) {
            messageEl.textContent = text;
            messageEl.className = `message show ${type}`;
            setTimeout(() => {
                messageEl.classList.remove('show');
            }, 1500);
        }

        // Start the game
        function startGame() {
            score = 0;
            timeLeft = 60;
            streak = 0;
            plate = [];
            gameRunning = true;

            scoreEl.textContent = score;
            timerEl.textContent = timeLeft;
            streakEl.textContent = streak;
            highScoreEl.textContent = highScore;

            gameArea.style.display = 'block';
            gameOver.style.display = 'none';

            generateOrder();
            renderPlate();

            // Start timer
            timerInterval = setInterval(() => {
                timeLeft--;
                timerEl.textContent = timeLeft;

                if (timeLeft <= 0) {
                    endGame();
                }
            }, 1000);
        }

        // End the game
        function endGame() {
            gameRunning = false;
            clearInterval(timerInterval);

            if (score > highScore) {
                highScore = score;
                localStorage.setItem('sushiHighScore', highScore);
            }

            finalScoreEl.textContent = score;
            highScoreEl.textContent = highScore;

            gameArea.style.display = 'none';
            gameOver.style.display = 'block';
        }

        // Event listeners
        clearBtn.addEventListener('click', clearPlate);
        serveBtn.addEventListener('click', serveDish);
        restartBtn.addEventListener('click', startGame);

        // Keyboard shortcuts
        document.addEventListener('keydown', (e) => {
            if (e.key === 'Enter') {
                if (gameRunning) {
                    serveDish();
                } else {
                    startGame();
                }
            }
            if (e.key === 'Escape' || e.key === 'Backspace') {
                e.preventDefault();
                clearPlate();
            }
        });

        // Initialize and start
        initIngredients();
        startGame();
    </script>
</body>
</html>
