/* General Body Styling */
body {
    margin: 0;
    font-family: 'Open Sans', sans-serif;
    overflow: hidden; /* Prevent scrolling */
    background: linear-gradient(to bottom right, #C8E6C9, #FFDDC1); /* Soft Mint Green to Peach */
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh; /* Full viewport height */
    color: #333;
}

/* --- Back to Homepage Icon Button Styling --- */
.back-to-home-icon {
    position: absolute;
    top: 20px;
    left: 20px;
    color: #6A5ACD; /* Medium Purple */
    padding: 10px; /* Padding around the icon */
    border-radius: 50%; /* Make it circular */
    text-decoration: none;
    display: flex; /* Use flex to center the SVG inside */
    justify-content: center;
    align-items: center;
    transition: all 0.2s ease-in-out;
    z-index: 101; /* Ensure it's above the game container and overlay */
    box-shadow: 0 2px 5px rgba(0,0,0,0.1); /* Very subtle shadow */
    background-color: rgba(255, 255, 255, 0.7); /* Slightly transparent white background */
}

.back-to-home-icon:hover {
    color: #483D8B; /* Darker Purple on hover */
    transform: translateY(-2px); /* Slight lift */
    box-shadow: 0 4px 8px rgba(0,0,0,0.15); /* Slightly more prominent shadow on hover */
}

.back-to-home-icon:active {
    transform: translateY(1px); /* Press down effect */
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.back-to-home-icon svg {
    width: 28px; /* Size of the SVG icon */
    height: 28px;
    fill: currentColor; /* Make SVG fill color inherit from parent 'color' property */
}
/* --- End Back to Homepage Icon Button Styling --- */

/* Main Game Container */
.game-container {
    display: flex;
    flex-direction: column; /* Stack elements vertically on small screens */
    background-color: #ffffff;
    border-radius: 30px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15); /* Softer shadow */
    padding: 25px; /* Slightly more padding */
    max-width: 95vw; /* Max width relative to viewport */
    max-height: 95vh; /* Max height relative to viewport */
    box-sizing: border-box;
    border: 6px solid #FFD700; /* Bright Gold Border */
    gap: 25px; /* More space between board and controls */
    align-items: center; /* Center items horizontally */
}

/* Responsive layout for larger screens */
@media (min-width: 768px) {
    .game-container {
        flex-direction: row; /* Side-by-side on larger screens */
        justify-content: space-around;
        padding: 40px; /* More padding for larger screens */
    }
}

/* Game Board Styling */
.game-board {
    display: grid;
    border: 4px solid #A2D9CE; /* Soft Teal Green Border */
    border-radius: 18px; /* Slightly more rounded */
    background-color: #F8FFFF; /* Very light, almost white background for board */
    box-shadow: inset 0 0 8px rgba(0,0,0,0.05); /* Softer inner shadow */
    position: relative; /* For critter/star positioning */
    width: clamp(200px, 60vh, 500px); /* Responsive square board */
    height: clamp(200px, 60vh, 500px);
    aspect-ratio: 1 / 1; /* Keep it square */
}

.grid-cell {
    border: 1px dashed rgba(0,0,0,0.35); /* Darker, clearer cell borders */
    display: flex;
    justify-content: center;
    align-items: center;
    box-sizing: border-box;
    font-size: clamp(25px, 6vw, 40px); /* Responsive emoji size for obstacles */
}

/* --- NEW: Obstacle Styling --- */
.grid-cell.obstacle {
    background-color: #E0E0E0; /* Light grey background for obstacle cells */
}


/* Critter and Star */
.critter, .star {
    position: absolute;
    width: calc(100% / var(--grid-size) * 0.75); /* Slightly larger critter/star */
    height: calc(100% / var(--grid-size) * 0.75);
    transition: left 0.3s ease-in-out, top 0.3s ease-in-out, transform 0.2s ease-in-out;
    display: flex;
    justify-content: center;
    align-items: center;
}

.critter svg {
    width: 100%;
    height: 100%;
    fill: #FF6347; /* Tomato Red Critter */
    stroke: #CD5C5C; /* Darker Red Stroke */
    stroke-width: 2;
}

.star {
    color: #FFD700; /* Gold star, kept as is as a good contrast */
    font-size: clamp(25px, 6vw, 70px); /* Responsive emoji size */
    text-shadow: 0 0 12px rgba(255,215,0,0.8); /* Slightly stronger glow */
}

/* Control Panel */
.control-panel {
    display: flex;
    flex-direction: column;
    gap: 20px; /* More space between sections */
    align-items: center;
    width: clamp(200px, 35vw, 400px); /* Responsive width */
    min-width: 200px;
}

.command-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr; /* Two columns for buttons */
    gap: 12px; /* Slightly more gap */
    width: 100%;
}

.game-button {
    background-color: #9370DB; /* Medium Purple */
    color: white;
    padding: 18px 12px; /* More padding */
    border-radius: 18px; /* More rounded */
    font-size: clamp(1.1em, 2.8vw, 1.5em);
    font-weight: bold;
    cursor: pointer;
    border: none;
    box-shadow: 0 6px 0 #6A5ACD; /* Slate Blue for 3D effect */
    transition: all 0.1s ease-in-out;
    font-family: 'Fredoka One', cursive;
    flex-grow: 1; /* Allow buttons to grow */
    text-shadow: 1px 1px 2px rgba(0,0,0,0.2); /* Subtle text shadow */
}

.game-button:active {
    box-shadow: 0 2px 0 #6A5ACD;
    transform: translateY(4px); /* Softer press */
}

.game-button:hover {
    background-color: #6A5ACD;
}

/* Specific button styling for arrows - larger font for emojis */
.game-button.arrow-button {
    font-size: clamp(1.8em, 4.5vw, 3em); /* Larger font for arrow emojis */
    padding: 15px; /* Adjust padding for larger emoji */
}

.action-buttons {
    display: flex;
    gap: 12px; /* More gap */
    width: 100%;
    justify-content: center;
}

/* Modernized Run Code Button - Cool Blue */
.action-buttons .game-button.run-button {
    background-color: #6495ED; /* Cornflower Blue */
    box-shadow: 0 6px 0 #4169E1; /* Royal Blue for depth */
    color: white; /* White text for better contrast */
    font-size: clamp(1.3em, 3vw, 1.8em); /* Slightly larger font for prominence */
    padding: 18px 25px; /* More padding */
    border-radius: 25px; /* More rounded */
    text-shadow: 1px 1px 2px rgba(0,0,0,0.3); /* Stronger text shadow */
}
.action-buttons .game-button.run-button:hover { background-color: #4169E1; }
.action-buttons .game-button.run-button:active { box-shadow: 0 2px 0 #4169E1; }

/* Modernized Reset Level Button - Cool Green */
.action-buttons .game-button.reset-button {
    background-color: #7FFF00; /* Chartreuse Green */
    box-shadow: 0 6px 0 #6B8E23; /* Olive Drab for depth */
    color: white; /* White text for better contrast */
    font-size: clamp(1.3em, 3vw, 1.8em); /* Slightly larger font for prominence */
    padding: 18px 25px; /* More padding */
    border-radius: 25px; /* More rounded */
    text-shadow: 1px 1px 2px rgba(0,0,0,0.3); /* Stronger text shadow */
}
.action-buttons .game-button.reset-button:hover { background-color: #6B8E23; }
.action-buttons .game-button.reset-button:active { box-shadow: 0 2px 0 #6B8E23; }


.program-display {
    background-color: #F0F8FF; /* Alice Blue (light, soft) */
    border: 2px dashed #B0E0E6; /* Softer blue border */
    border-radius: 12px; /* Slightly more rounded */
    padding: 10px; /* Adjusted padding for horizontal layout */
    min-height: 80px; /* Reduced min-height for horizontal flow */
    width: 100%;
    text-align: left;
    box-sizing: border-box;
    overflow-x: auto; /* Allow horizontal scrolling if commands overflow */
    overflow-y: hidden; /* Hide vertical scrollbar */
    white-space: nowrap; /* Keep items on one line initially */
    display: flex; /* Use flexbox for horizontal layout */
    align-items: center; /* Vertically center items */
    gap: 8px; /* Gap between command icons */
    box-shadow: inset 0 2px 5px rgba(0,0,0,0.05); /* Subtle inner shadow */
}

.program-display .program-command-icon {
    display: inline-flex; /* Use inline-flex to keep them in line */
    justify-content: center;
    align-items: center;
    width: 40px; /* Fixed width for each icon */
    height: 40px; /* Fixed height for each icon */
    background-color: rgba(176, 224, 230, 0.4); /* Softer background for command lines */
    border-radius: 8px; /* More rounded */
    font-size: 1.8em; /* Size of the emoji */
    flex-shrink: 0; /* Prevent shrinking */
}

.program-display p {
    margin: 0; /* Remove default paragraph margin */
    padding: 0; /* Remove default paragraph padding */
    font-size: 1.2em; /* Keep "Your Code:" visible */
    flex-shrink: 0;
    margin-right: 10px; /* Space after "Your Code:" */
}

.program-display .placeholder-text {
    color: #888;
    font-size: 0.9em;
}

/* Floating Feedback Message */
.floating-feedback {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: rgba(255, 255, 255, 0.95); /* Semi-transparent white */
    padding: 30px 50px;
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    font-family: 'Fredoka One', cursive;
    font-size: clamp(1.8em, 5vw, 3em);
    font-weight: bold;
    text-align: center;
    z-index: 1000; /* On top of everything */
    opacity: 0; /* Start hidden */
    visibility: hidden; /* Start hidden */
    transition: opacity 0.5s ease-out, visibility 0.5s ease-out;
    pointer-events: none; /* Allow clicks to pass through when hidden */
}

.floating-feedback.show {
    opacity: 1;
    visibility: visible;
}

.floating-feedback.success {
    color: #28A745; /* Dark green */
    border: 3px solid #28A745;
}

.floating-feedback.error {
    color: #DC3545; /* Dark red */
    border: 3px solid #DC3545;
}

.level-info {
    font-family: 'Fredoka One', cursive;
    font-size: clamp(1.4em, 2.8vw, 2em); /* Larger level info */
    color: #9370DB; /* Matching command button color */
    margin-bottom: 15px; /* More margin */
    text-align: center;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.1); /* Subtle text shadow */
}

/* Small screen adjustments */
@media (max-width: 480px) {
    .game-container {
        padding: 15px;
        gap: 15px;
    }
    .game-button {
        padding: 12px 8px;
        font-size: 1em;
    }
    .game-button.arrow-button {
        font-size: clamp(1.5em, 3.5vw, 2.5em); /* Adjust arrow size for smaller screens */
    }
    .action-buttons .game-button {
        font-size: clamp(1.1em, 2.5vw, 1.5em); /* Adjusted font size for action buttons on small screens */
        padding: 15px 18px; /* Adjusted padding */
    }
    .program-display {
        min-height: 60px; /* Further reduced min-height for small screens */
        font-size: 1em;
        gap: 5px; /* Smaller gap on small screens */
    }
    .program-display .program-command-icon {
        width: 35px;
        height: 35px;
        font-size: 1.5em;
    }
    .floating-feedback {
        font-size: clamp(1.5em, 4vw, 2.5em);
        padding: 20px 30px;
    }
    .level-info {
        font-size: 1.2em;
    }
}
