.projects-grid {
    display: grid;
    /* Corrected the minmax() function with a realistic minimum width */
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 2rem;
    margin-top: 1rem;
    width: 100%;
    /* Use 100% width to fill its container */
    max-width: 55rem;
    /* Set a max-width for very large screens */
    margin-left: auto;
    /* Center the grid container */
    margin-right: auto;
    /* Center the grid container */
}

.project-item {
    background-color: rgba(0, 0, 0, 0.6);
    padding: 1.5rem;
    border-radius: 10px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    transition: transform 0.3s ease, filter 0.3s ease;
    /* Added transition for hover effects */
}

.project-item:hover {

    transform: scale(1.025);
    /* Changed to 7% bigger on hover */
    filter: brightness(1.25);
    /* Slight tint change */
}

.project-item img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin-bottom: 15px;
    /* border: 2px solid var(--color-primary);  <-- Moved to .gif-container */
}

.project-item p {
    font-size: 1rem;
    line-height: 1.5;
    text-shadow: 0px 0px 5px var(--shadow-color);
    /* Subtle text shadow for gradient effect */
    text-align: left;
}

.project-button {
    display: inline-block;
    padding: 12px 20px;
    /* --- THIS IS THE MAGIC LINE --- */
    margin-top: auto;
    /* This replaces the fixed margin-top: 15px */
    font-size: 0.85rem;
    border: 0.125rem solid var(--color-primary);
    color: var(--color-primary);
    background-color: transparent;
    text-decoration: none;
    font-family: var(--font-navigation);
    border-radius: 1rem;
    transition: background-color 0.3s ease, color 0.3s ease;
    text-align: center;
    width: 90%;
}

/* General style for any icon using this technique */
.project-button .icon {
    display: inline-flex;
    justify-content: center;
    /* Center items horizontally */
    align-items: center;
    /* Center items vertically */
    margin-left: 5px;
    height: 1.5em;
    width: 1.5em;
    vertical-align: text-bottom;
    /* Align with text */
    white-space: nowrap;
    /* Prevent line breaks */
    background-color: var(--color-primary);
    transition: background-color 0.3s ease;
    /* Animate the color change */
}

/* Specific style for the redirect icon's shape */
.project-button .redirect-icon {
    /* Use the SVG file as a stencil */
    -webkit-mask-image: url('../../SocialMediaIcons/redirect.svg');
    mask-image: url('../../SocialMediaIcons/redirect.svg');
    mask-size: contain;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
}

/* Hover State for the icon's color */
.project-button:hover .icon {
    background-color: var(--primary-bg-end);
    /* Change the color on hover */
}

/* --- END: New Mask Icon Styles --- */


.project-button:hover {
    border-color: var(--color-hover);
    background-color: var(--color-hover);
    color: var(--primary-bg-end);
}

/* --- Styles for Tablets (e.g., iPads) --- */
@media (min-width: 768px) and (max-width: 1368px) {
    .projects-grid {
        gap: 1.5rem;
        max-width: 93%;
    }

    .project-item p {
        font-size: 1.1rem;
    }
}

/* --- GIF Control Styles --- */

.gif-container {
    position: relative;
    width: 100%;
    margin-bottom: 15px;
    border-radius: 12px;
    overflow: hidden;
    /* Ensures the button doesn't spill out */
    border: 2px solid rgba(255, 255, 255, 0.1);
    transition: border-color 0.3s ease;
    display: flex;
    /* Fixes potential inline-block gaps */
}

/* Inherit hover effect from parent */
.project-item:hover .gif-container {
    border-color: var(--color-header);
}

.gif-container img {
    margin-bottom: 0 !important;
    /* Remove margin from img as container handles it */
    width: 100%;
    height: auto;
    display: block;
    border: none !important;
    /* Remove img border, container has it */
}

.gif-toggle-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    background-color: rgba(0, 0, 0, 0.6);
    color: var(--color-primary);
    font-size: 1.2rem;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: opacity 0.3s ease, background-color 0.3s ease, transform 0.2s ease;
    z-index: 10;
    backdrop-filter: blur(4px);
}

/* Show button when hovering content OR when paused */
.gif-container:hover .gif-toggle-btn,
.gif-toggle-btn.paused {
    opacity: 1;
}

.gif-toggle-btn:hover {
    background-color: rgba(0, 0, 0, 0.8);
}

/* State: PLAYING (shows Pause icon) */
.gif-toggle-btn.playing {
    color: var(--color-hover);
    /* Replaces high contrast #ff00ff */
}

/* State: PAUSED (shows Play icon) */
.gif-toggle-btn.paused {
    color: var(--color-primary);
    /* Replaces high contrast #00ffff */
    background-color: rgba(0, 0, 0, 0.7);
    /* Slightly darker bg when paused */
}