/* Globally hide the default system cursor */
html, body, .game-container, .item, .drop-zone, button, select {
    cursor: none !important;
}

body {
    font-family: 'Mali', cursive;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    background-color: #f0f8f0;
    color: #333;
    overflow: hidden; /* Prevents scrollbars when the background scales up */
}

body::before {
    content: "";
    position: fixed;
    top: -2%;
    left: -2%;
    width: 104%;
    height: 104%;
    background-image: url('images/farm-bg.jpg');
    background-size: cover;
    background-position: center;
    z-index: -1;
    /* margin handles the drag shift while transform handles the idle animation */
    margin-left: var(--bg-shift-x, 0);
    margin-top: var(--bg-shift-y, 0);
    transition: margin 0.4s ease-out;
    animation: farm-float 40s infinite alternate ease-in-out;
}

@keyframes farm-float {
    0% { transform: scale(1) translate(0, 0); }
    100% { transform: scale(1.1) translate(-1%, -1%); }
}

.game-container {
    background-color: rgba(255, 255, 255, 0.9);
    border-radius: 15px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    padding: 20px; /* Reduced padding */
    text-align: center;
    max-width: 900px;
    width: 100%;
    position: relative; /* Needed for absolutely positioned confetti particles */
    display: flex; /* Make it a flex container */
    flex-direction: column; /* Stack children vertically */
    height: 90vh; /* Aim for 90% of viewport height */
    max-height: 700px; /* Prevent it from getting too tall on very large screens */
    overflow: hidden; /* Hide overflow to enforce "one screen" */
    border: 5px solid #8bc34a;
}

h1 {
    font-family: 'Carter One', cursive;
    color: #2e8b57;
    letter-spacing: 2px;
    margin-bottom: 5px; /* Reduced margin */
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
}

h2 {
    font-family: 'Carter One', cursive;
    color: #555;
    font-size: 1.5em;
    text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.15);
}

p {
    margin-bottom: 10px; /* Reduced margin */
    color: #555;
}

.score-area {
    font-size: 1.2em;
    font-weight: bold;
    margin-bottom: 10px; /* Reduced margin */
    color: #4682b4; /* Steel blue */
}

.message {
    min-height: 20px;
    margin-bottom: 10px; /* Reduced margin */
    font-weight: bold;
    color: #d9534f; /* Red for errors/feedback */
}

.game-board {
    display: flex;
    flex-wrap: nowrap; /* Prevent wrapping */
    justify-content: space-between; /* Distribute space */
    gap: 15px; /* Reduced gap */
    margin-bottom: 15px; /* Reduced margin */
    flex-grow: 1; /* Allow it to take available vertical space */
    overflow: hidden; /* Hide overflow from its children if they exceed */
}

/* Specific styles for items-to-sort */
.items-to-sort {
    flex: 0 0 200px; /* Fixed width for items to sort */
    min-width: 200px; /* Ensure it doesn't shrink below this */
    background-color: rgba(230, 255, 230, 0.7); /* Added transparency */
    border: 2px dashed #a0d9b4;
    border-radius: 10px;
    padding: 10px; /* Reduced padding */
    min-height: 0; /* Allow flex item to shrink */
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    align-content: flex-start;
    align-items: center;
    gap: 10px;
    overflow-y: auto; /* Allow scrolling for items */
}

.drop-zones {
    display: flex;
    flex-wrap: nowrap; /* Prevent wrapping of individual drop zones */
    flex: 1; /* Take remaining space */
    gap: 15px; /* Reduced gap */
    min-height: 0; /* Allow flex item to shrink */
}

#animals-zone {
    background-color: rgba(255, 205, 210, 0.7); /* Soft Red */
    border: 3px solid #ef5350;
}

#produce-zone {
    background-color: rgba(255, 243, 224, 0.7); /* Soft Orange */
    border: 3px solid #ffb74d;
}

.drop-zone {
    min-height: 0; /* Allow flex item to shrink */
    flex: 1; /* Each drop zone takes half the space */
    position: relative; /* Anchor for the success-mark */
    border-radius: 10px; /* Added for consistency */
    padding: 10px; /* Reduced padding */
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    align-content: flex-start;
    align-items: center;
    gap: 10px;
    overflow-y: auto; /* Allow scrolling for dropped items */
}

.drop-zone.hover {
    background-color: #d4edda; /* Lighter green on hover */
    border-color: #28a745; /* Darker green on hover */
}

.items-to-sort h2, .drop-zone h2 {
    width: 100%;
    margin-bottom: 5px;
}

.item {
    touch-action: none; /* Prevents scrolling while dragging on mobile */
    border: 2px solid #ccc;
    border-radius: 8px;
    padding: 10px;
    width: 100px;
    text-align: center;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

.item[data-category="animal"] {
    background-color: #e3f2fd; /* Light Blue */
    border-color: #90caf9;
}

.item[data-category="produce"] {
    background-color: #fff9c4; /* Light Yellow */
    border-color: #fff176;
}

.item:nth-child(odd) {
    animation-delay: 0.2s;
}

.item:nth-child(even) {
    animation-delay: 0.5s;
}

.item:hover {
    animation-play-state: paused;
    box-shadow: 0 0 20px 2px rgba(255, 255, 255, 1) !important;
}

.item:active {
    transform: scale(1.05);
}

.item.dragging {
    /* Vibrant white and gold glow that overrides the wiggle shadow */
    box-shadow: 0 0 15px 5px rgba(255, 255, 255, 0.8), 0 0 25px 8px rgba(255, 215, 0, 0.6) !important;
    opacity: 0.9;
    transform: scale(1.08); /* Slightly larger than :active for emphasis */
    font-weight: bold;
}

#custom-cursor {
    position: fixed;
    top: 0;
    left: 0;
    width: 48px;
    height: 48px;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='48' height='48' style='font-size: 36px;'><text y='38' x='5'>🧤</text></svg>");
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    pointer-events: none; /* Crucial: clicks pass through to game elements */
    z-index: 9999;
    will-change: transform; /* Optimizes performance for high-frequency updates */
}

/* Styles for the cursor trail particles */
.cursor-trail-particle {
    position: fixed;
    width: 10px; /* Small size for particles */
    height: 10px;
    border-radius: 50%; /* Make them circular */
    opacity: 0; /* Start invisible, animation will make them appear and fade */
    pointer-events: none; /* Don't block clicks */
    z-index: 9998; /* Below the main cursor */
    background-color: var(--trail-color); /* Color set by JS */
    transform: translate(-50%, -50%); /* Center the particle on its coordinates */
    animation: fade-out-trail 0.8s forwards ease-out; /* Fade out animation */
}
@keyframes fade-out-trail {
    0% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
}

.item-success {
    animation: item-pop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes item-pop {
    0% { transform: scale(1); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

@keyframes wiggle {
    0% { 
        transform: rotate(0deg); 
        box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    }
    25% { 
        transform: rotate(var(--wiggle-intensity, 2deg)); 
        box-shadow: 0 8px 15px rgba(0, 0, 0, 0.15);
    }
    50% { 
        transform: rotate(0deg); 
        box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    }
    75% { 
        transform: rotate(calc(-1 * var(--wiggle-intensity, 2deg))); 
        box-shadow: 0 8px 15px rgba(0, 0, 0, 0.15);
    }
    100% { 
        transform: rotate(0deg); 
        box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    }
}

button {
    font-family: 'Mali', cursive;
    font-weight: 700;
    padding: 10px 20px;
    font-size: 1em;
    background-color: #007bff; /* Blue */
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s ease;
}

button:hover {
    background-color: #0056b3;
}

#settings-button {
    position: absolute;
    top: 15px;
    right: 15px;
    background: none;
    border: none;
    font-size: 1.8em;
    padding: 5px;
    z-index: 100;
    cursor: pointer;
    transition: transform 0.3s ease;
}

#settings-button:hover {
    transform: rotate(90deg);
    background: none;
}

.volume-settings-content {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin: 20px 0;
    align-items: center;
}

.volume-group {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: bold;
    color: #555;
}

.volume-group input {
    cursor: pointer;
}

.settings-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

#mute-all-button {
    background-color: #dc3545; /* Danger Red */
    padding: 5px 12px;
    font-size: 0.85em;
    margin: 0;
}

#mute-all-button.muted {
    background-color: #6c757d; /* Grey when muted */
}

#music-toggle-button {
    background-color: #6c757d; /* Grey */
    color: white;
}

#music-toggle-button:hover {
    background-color: #5a6268;
}

#view-high-scores-button {
    background-color: #17a2b8; /* Teal */
    color: white;
}

#view-high-scores-button:hover {
    background-color: #138496;
}

#pause-button {
    position: absolute;
    top: 75px;
    right: 15px;
    background: #4682b4; /* Steel Blue */
    border: none;
    border-radius: 50%;
    width: 45px;
    height: 45px;
    font-size: 1.2em;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    cursor: pointer;
    color: white;
    transition: transform 0.2s ease;
}

#hint-button {
    position: absolute;
    top: 135px;
    right: 15px;
    z-index: 100;
    background-color: #ffc107; /* Amber/Yellow */
    color: #333;
    font-size: 1.5em;
    padding: 0;
    width: 45px;
    height: 45px;
    border-radius: 50%;
    display: none; /* Hidden by default, shown after inactivity */
    align-items: center;
    justify-content: center;
}

#hint-button:hover {
    background-color: #e0a800;
}

.hint-pulse {
    animation: hint-pulse-glow 2s infinite;
}

@keyframes hint-pulse-glow {
    0% { box-shadow: 0 0 0 0 rgba(255, 193, 7, 0.7); }
    70% { box-shadow: 0 0 0 15px rgba(255, 193, 7, 0); }
    100% { box-shadow: 0 0 0 0 rgba(255, 193, 7, 0); }
}

#next-level-button {
    background-color: #28a745; /* Vibrant Success Green */
    font-weight: bold;
    margin-right: 10px;
    animation: pulse 1.5s infinite ease-in-out; /* Add pulse animation */
}

#next-level-button:hover {
    background-color: #218838;
}

.difficulty-area {
    margin-bottom: 10px; /* Reduced margin */
    font-weight: bold;
}

#difficulty-select {
    padding: 5px 10px;
    border-radius: 5px;
    border: 1px solid #ccc;
    font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif;
    cursor: pointer;
}

.penalty-flash {
    color: #d9534f !important;
    display: inline-block;
    animation: timer-warning 0.5s ease-in-out;
    text-shadow: 0 0 8px rgba(217, 83, 79, 0.6);
}

@keyframes timer-warning {
    0%, 100% { transform: scale(1) translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: scale(1.3) translateX(-4px); }
    20%, 40%, 60%, 80% { transform: scale(1.3) translateX(4px); }
}

.hint-highlight {
    border: 4px solid #ffc107 !important;
    box-shadow: 0 0 15px #ffc107;
    transition: all 0.3s ease;
}

/* Modal Styles */
.modal {
    display: flex;
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(4px);
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.modal.show {
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    position: relative;
    background-color: white;
    padding: 30px;
    border-radius: 15px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    max-width: 400px;
    width: 85%;
    border: 4px solid #2e8b57;
}

.close-icon {
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 1.5em;
    background: none !important;
    border: none;
    color: #888;
    cursor: pointer;
    padding: 5px;
    line-height: 1;
    transition: color 0.2s, transform 0.2s;
}

.close-icon:hover {
    color: #d9534f;
    transform: scale(1.1);
}

/* Settings Modal Specific Slide-in from Right */
#settings-modal .modal-content {
    transform: translateX(100vw);
    transition: transform 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

#settings-modal.show .modal-content {
    transform: translateX(0);
}

/* Semi-transparent Pause Modal Content with Slide-down Animation */
#pause-modal .modal-content {
    background-color: rgba(255, 255, 255, 0.85);
    transform: translateY(-100vh);
    transition: transform 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

#pause-modal.show .modal-content {
    transform: translateY(0);
}

/* Winning Modal Specific Scale-up with Bounce */
#win-modal .modal-content {
    transform: scale(0);
    transition: transform 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#win-modal.show .modal-content {
    transform: scale(1);
}

.transition-content {
    background: none !important;
    border: none !important;
    box-shadow: none !important;
}

#transition-level-text {
    font-size: 4em;
    color: #ffc107;
    margin-bottom: 20px;
}

#countdown-text {
    font-size: 6em;
    color: white;
    font-family: 'Titan One', cursive;
    text-shadow: 4px 4px 15px rgba(0,0,0,0.5);
}

.stats {
    margin: 20px 0;
    font-size: 1.2em;
    font-weight: bold;
    color: #4682b4;
}

#bonus-display {
    color: #ffc107;
    font-weight: bold;
    margin: 5px 0;
}

.high-scores-list {
    margin: 20px 0;
    text-align: left;
    max-height: 250px;
    overflow-y: auto;
    padding: 10px;
    background: #f9f9f9;
    border-radius: 8px;
    border: 1px solid #ddd;
}

.high-score-item {
    display: flex;
    justify-content: space-between;
    padding: 10px 5px;
    border-bottom: 1px solid #eee;
    font-size: 1.1em;
}

.high-score-item:last-child {
    border-bottom: none;
}

#clear-high-scores-button {
    background-color: #d9534f; /* Red for destructive action */
    margin-right: 10px;
}

#clear-high-scores-button:hover {
    background-color: #c9302c;
}

.final-stars {
    font-size: 2.5em;
    color: #ffc107; /* Gold color */
    margin-top: 10px;
}

.success-mark {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 5rem;
    pointer-events: none;
    z-index: 10;
    animation: mark-fade 1s ease-out forwards;
}

@keyframes mark-fade {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
    30% { opacity: 0.8; transform: translate(-50%, -50%) scale(1.2); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(1); }
}

/* Confetti Particle Styles */
.confetti-particle {
    position: absolute;
    width: 10px;
    height: 10px;
    background-color: #f00; /* Default, will be randomized by JS */
    border-radius: 50%; /* Make them circular */
    opacity: 0;
    pointer-events: none; /* Ensure they don't interfere with clicks/drags */
    animation: confetti-burst 1.5s forwards ease-out;
}

@keyframes confetti-burst {
    0% {
        transform: translate(0, 0) scale(1) rotate(0deg);
        opacity: 1;
    }
    20% {
        transform: translate(var(--x-start), var(--y-start)) scale(1.2) rotate(var(--rotate-start));
        opacity: 1;
    }
    100% {
        transform: translate(var(--x-end), var(--y-end)) scale(0.5) rotate(var(--rotate-end));
        opacity: 0;
    }
}

/* Fallback for browsers that don't support CSS variables in keyframes (less common now) */
/* If you need wider browser support for older browsers, you might need to generate more keyframes or use JS for animation */
/* For modern browsers, CSS variables in keyframes are widely supported. */

/* Mobile Responsiveness */
@media (max-width: 600px) {
    #custom-cursor {
        display: none; /* Hide virtual cursor on touch devices */
    }

    .game-container {
        height: 100vh;
        max-height: none;
        border-radius: 0;
        padding: 10px;
    }

    .game-board {
        flex-direction: column;
    }

    .items-to-sort {
        flex: 0 0 110px;
        width: 100%;
        min-width: 0;
        flex-direction: row;
        overflow-x: auto;
        overflow-y: hidden;
        justify-content: flex-start;
    }

    .item {
        flex: 0 0 75px; /* Reduced width for better fit */
        padding: 8px 4px; /* Tighter padding */
        font-size: 0.85em; /* Slightly smaller text */
    }
}

/* Pulse Animation for Next Level Button */
@keyframes pulse {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
    100% {
        transform: scale(1);
    }
}