/* Base Styles */
:root {
    --primary-color: #ffd700;
    --secondary-color: #ffc400;
    --accent-color: #ff6b6b;
    --dark-color: #333;
    --light-color: #fff8e1;
    --shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Comic Neue', cursive;
    background-color: var(--light-color);
    color: var(--dark-color);
    line-height: 1.6;
}

/* Typography */
h1, h2, h3, h4 {
    font-family: 'Fredoka One', cursive;
    letter-spacing: 1px;
}

/* Import shared styles */
@import url('../shared/shared.css');

/* Container */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
}

/* Search Container */
.search-container {
    max-width: 600px;
    margin: 1rem auto;
    position: relative;
    z-index: 1001; /* Create a new stacking context */
    padding: 3px; /* Space for the glow */
    border-radius: 50px;
    background: linear-gradient(90deg, #ffd700, #ff8c00, #ffd700);
    background-size: 200% auto;
    animation: gradient 3s linear infinite, pulse 2s infinite;
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.5);
    transition: all 0.3s ease;
}

@keyframes gradient {
    0% {
        background-position: 0% 50%;
    }
    50% {
        background-position: 100% 50%;
    }
    100% {
        background-position: 0% 50%;
    }
}

.search-box {
    position: relative;
    width: 100%;
    border-radius: 50px;
    overflow: hidden;
    background: white;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

.search-box input[type="text"] {
    width: 100%;
    padding: 18px 65px 18px 25px;
    border: none;
    outline: none;
    font-size: 1.1rem;
    font-family: 'Comic Neue', cursive;
    background: transparent;
    color: #333;
}

.search-btn, .help-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    border: none;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.search-btn {
    right: 5px;
    background: linear-gradient(45deg, #ffd700, #ff8c00);
    color: white;
    font-size: 1.3rem;
    box-shadow: 0 4px 15px rgba(255, 140, 0, 0.4);
}

.search-btn:hover {
    transform: translateY(-50%) scale(1.1);
    box-shadow: 0 6px 20px rgba(255, 140, 0, 0.6);
}

.help-btn {
    right: 60px;
    background: transparent;
    color: #666;
    font-size: 1.2rem;
}

/* Filter toggle sits between search and help buttons */
.filter-toggle {
    /*right: 110px;*/
}

.help-btn.active,
.filter-toggle.active {
    color: #ff8c00;
}

.help-btn:hover {
    color: #ff8c00;
}

.help-popup {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 10px;
    background: white;
    border-radius: 10px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
    z-index: 1002; /* Higher than the container */
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.3s ease;
    pointer-events: auto;
    /* Ensure the popup stays above other content */
    will-change: transform, opacity;
    transform-style: preserve-3d;
}

.help-popup.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.help-content {
    padding: 20px;
    position: relative;
}

.help-content h3 {
    margin-bottom: 10px;
    color: #333;
}

.help-content ul {
    margin-left: 20px;
    margin-bottom: 15px;
}

.help-content li {
    margin-bottom: 5px;
    color: #555;
}

.close-help {
    background: #ffd700;
    border: none;
    padding: 8px 20px;
    border-radius: 20px;
    cursor: pointer;
    font-family: 'Comic Neue', cursive;
    font-weight: bold;
    transition: all 0.3s ease;
}

.close-help:hover {
    background: #ffc400;
    transform: translateY(-2px);
}

.search-btn:hover {
    transform: translateY(-50%) scale(1.1);
    box-shadow: 0 6px 20px rgba(255, 140, 0, 0.6);
}

.search-btn i {
    color: white;
    text-shadow: 0 2px 3px rgba(0, 0, 0, 0.2);
}

/* Pulsing animation */
@keyframes pulse {
    0% {
        box-shadow: 0 0 5px 0 rgba(255, 215, 0, 0.8),
                    0 0 20px 0 rgba(255, 215, 0, 0.6);
    }
    70% {
        box-shadow: 0 0 20px 10px rgba(255, 215, 0, 0.3),
                   0 0 40px 20px rgba(255, 215, 0, 0.1);
    }
    100% {
        box-shadow: 0 0 5px 0 rgba(255, 215, 0, 0.8),
                   0 0 20px 0 rgba(255, 215, 0, 0.6);
    }
}

/* Focus effect */
.search-container:focus-within {
    animation: pulse 1.5s infinite, gradient 3s linear infinite;
    transform: scale(1.02);
}

.search-container:hover {
    animation: pulse 1.5s infinite, gradient 3s linear infinite;
    transform: scale(1.01);
}

/* Add a subtle shine effect to the search container */
.search-container::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    z-index: -1;
    border-radius: 50px;
    background: linear-gradient(45deg, #ffd700, #ff8c00, #ffd700, #ff8c00);
    background-size: 400% 400%;
    animation: gradient 3s ease infinite;
    filter: blur(5px);
    opacity: 0.7;
    transition: 0.3s;
}

.search-container:hover::before {
    opacity: 0.9;
    filter: blur(8px);
}

/* Buttons */
.btn {
    padding: 0.8rem 1.5rem;
    border: none;
    border-radius: 30px;
    font-family: 'Fredoka One', cursive;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    background-color: var(--primary-color);
    color: var(--dark-color);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.btn:active {
    transform: translateY(0);
}

.btn-secondary {
    background-color: white;
    border: 2px solid var(--primary-color);
}

/* Meme Grid */
.meme-grid {
    display: grid;
    gap: 1.5rem;
    padding: 1rem 0;
    grid-template-columns: repeat(2, 1fr);
}

.meme-card {
    position: relative;
    background: white;
    border-radius: 15px;
    overflow: hidden;
    box-shadow: var(--shadow);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    aspect-ratio: 1;
    z-index: 1; /* Base z-index for cards */
    /* Ensure cards don't create a new stacking context that could interfere */
    transform: translateZ(0);
    will-change: transform;
}

.meme-card:hover {
    transform: translateY(-5px) translateZ(0);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.15);
}
.meme-image-container {
    position: relative;
    width: 100%;
    height: 100%;
}

.meme-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.meme-actions {
    padding: 1rem;
    display: flex;
    justify-content: center;
}

.download-btn {
    position: absolute;
    bottom: 10px;
    right: 10px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: white;
    backdrop-filter: blur(10px);
    border: solid 1px black;
    color: var(--dark-color);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    opacity: 0.8;
    background: rgba(255, 255, 255, 0.6);   
}

.download-btn:hover {
    opacity: 1;
    transform: scale(1.1);
}

.download-btn i {
    font-size: 1.1rem;
}

/* Recommend (find similar) button */
.recommend-btn {
    position: absolute;
    bottom: 10px;
    left: 10px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.6);
    backdrop-filter: blur(10px);
    border: solid 1px black;
    color: var(--dark-color);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    opacity: 0.8;
}

.recommend-btn:hover {
    opacity: 1;
    transform: scale(1.1);
}

.recommend-btn i {
    font-size: 1.1rem;
}

/* Image icon inside recommend button */
.recommend-btn img {
    width: 22px;
    height: 22px;
    display: block;
}

/* Fancy quick tooltips for recommend (search) button */
.recommend-btn[data-tooltip] {
    position: absolute; /* already absolute; ensure positioning context for tooltip */
}

.recommend-btn[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    left: 0; /* align to button's left to avoid clipping on card edge */
    bottom: 60px; /* above the button */
    transform: translateY(4px) scale(0.96);
    background: linear-gradient(135deg, #222, #333);
    color: #fff;
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 0.8rem;
    white-space: nowrap;
    box-shadow: 0 8px 16px rgba(0,0,0,0.25), 0 0 0 1px rgba(255,255,255,0.06) inset;
    opacity: 0;
    pointer-events: none;
    transition: opacity 120ms ease, transform 120ms ease;
    z-index: 10;
}

.recommend-btn[data-tooltip]::before {
    content: '';
    position: absolute;
    left: 18px; /* arrow roughly under bubble near left */
    bottom: 54px; /* small gap to bubble */
    transform: translateX(0);
    border: 6px solid transparent;
    border-top-color: #333; /* matches bubble background end color */
    opacity: 0;
    transition: opacity 120ms ease;
    z-index: 10;
}

.recommend-btn:hover[data-tooltip]::after,
.recommend-btn:focus-visible[data-tooltip]::after,
.recommend-btn:hover[data-tooltip]::before,
.recommend-btn:focus-visible[data-tooltip]::before {
    opacity: 1;
    transform: translateY(0) scale(1);
}

@media (prefers-reduced-motion: reduce) {
    .recommend-btn[data-tooltip]::after,
    .recommend-btn[data-tooltip]::before {
        transition: none;
    }
}

/* Desktop styles */
@media (min-width: 768px) {
    .meme-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 2rem;
    }
}

/* Mobile styles */
@media (max-width: 767px) {
    .meme-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1rem;
        padding: 0.5rem;
    }
    
    .meme-card {
        border-radius: 10px;
    }
}

/* Loading, Error, and No Results */
.loading, .error-message, .no-results {
    text-align: center;
    padding: 2rem;
    margin: 2rem 0;
    border-radius: 10px;
    background-color: white;
    box-shadow: var(--shadow);
}

.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid var(--primary-color);
    border-top: 5px solid var(--accent-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Animated yellow glow for pagination buttons */
@keyframes goldPulse {
    0% {
        box-shadow: 0 2px 8px rgba(255, 215, 0, 0.25), 0 0 0 0 rgba(255, 196, 0, 0.15);
    }
    50% {
        box-shadow: 0 6px 18px rgba(255, 140, 0, 0.45), 0 0 0 6px rgba(255, 215, 0, 0.18);
    }
    100% {
        box-shadow: 0 2px 8px rgba(255, 215, 0, 0.25), 0 0 0 0 rgba(255, 196, 0, 0.15);
    }
}

.error-message {
    background-color: #ffebee;
    color: #c62828;
}

.no-results {
    background-color: #e8f5e9;
    color: #2e7d32;
}

/* Load More (mobile) */
.load-more-container {
    display: flex;
    justify-content: center;
    margin: 0.5rem 0 1.5rem;
}

/* Make the button a bit wider than header pagination */
#loadMoreBtn.pagination-link {
    padding: 1rem 2rem;
}

/* Utility Classes */
.hidden {
    display: none !important;
}

/* Results Header */
.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 1rem 0;
    padding: 5px;
    /* background: white;
    border-radius: 10px;
    box-shadow: var(--shadow); */
}

.total-count {
    font-family: 'Fredoka One', cursive;
    font-size: 1rem;
    color: var(--dark-color);
    letter-spacing: 1px;
}

/* Always hide total count section */
#totalCount {
    display: none !important;
}

/* Pagination Styles */
.pagination-container {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.pagination-link {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.45rem 2.1rem; /* wider */
    text-decoration: none;
    font-family: 'Comic Neue', cursive;
    font-size: 1rem;
    font-weight: bold;
    border-radius: 12px;
    transition: all 0.2s ease;
    border: 1px solid transparent;
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: var(--dark-color);
    will-change: box-shadow, transform;
    animation: goldPulse 2.2s ease-in-out infinite;
}

.pagination-link:hover:not(.disabled) {
    color: var(--accent-color);
    background: var(--primary-color);
    border-color: var(--primary-color);
    transform: translateY(-1px);
    box-shadow: 0 8px 20px rgba(255, 140, 0, 0.5), 0 0 0 8px rgba(255, 215, 0, 0.2);
}

.pagination-link.disabled {
    color: #919191;
    cursor: not-allowed;
    pointer-events: none;
    background:none;
    animation: none;
    box-shadow: none;
}

.page-info {
    color: var(--dark-color);
    padding: 0.3rem 0.6rem;
    background: var(--light-color);
    border-radius: 12px;
    border: 1px solid var(--primary-color);
    font-weight: 500;
    font-family: 'Fredoka One', cursive;
    font-size: 1rem;
    letter-spacing: 1px;
}

/* Mobile adjustments */
@media (max-width: 767px) {
    .results-header {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }
    
    .pagination-container {
        gap: 0.5rem;
    }
    
    .pagination-link {
        padding: 0.4rem 0.9rem;
        font-size: 1rem;
    }
    
    .page-info {
        padding: 0.3rem 0.6rem;
        font-size: 0.8rem;
    }
}

/* Responsive Design */
@media (max-width: 768px) {
    .search-box {
        flex-direction: column;
    }
    
    .meme-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 2fr));
    }
}

/* Media Filter Styles */
.media-filter {
    margin: 15px 0;
    margin-bottom: 5px;
    padding: 10px 0;
    border-bottom: 1px solid #ffd70033;
}

.radio-group {
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-wrap: wrap;
    align-items: center;
}

.radio-divider {
    width: 2px;
    height: 30px;
    background-color: var(--accent-color);
    opacity: 0.3;
    margin: 0 5px;
}

.radio-group input[type="radio"] {
    display: none;
}

.radio-group label {
    padding: 5px 15px;
    border-radius: 20px;
    background-color: #fff8e1;
    color: var(--accent-color);
    cursor: pointer;
    font-family: 'Comic Neue', cursive;
    font-weight: 700;
    font-size: 14px;
    transition: all 0.3s ease;
    border: 2px solid var(--accent-color);
}

.radio-group input[type="radio"]:checked + label {
    background-color: var(--primary-color);
    color: var(--dark-color);
    border-color: var(--secondary-color);
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
}

.radio-group label:hover {
    background-color: var(--primary-color);
}

/* Only show recommend icon for static images (jpg/jpeg/png). Hide for GIFs. */
.meme-image-container .recommend-btn { display: none; }
/* Show when the card contains an <img> with allowed extensions (case-insensitive, handle optional query strings) */
.meme-image-container:has(img[src$=".jpg" i]) .recommend-btn,
.meme-image-container:has(img[src*=".jpg?" i]) .recommend-btn,
.meme-image-container:has(img[src$=".jpeg" i]) .recommend-btn,
.meme-image-container:has(img[src*=".jpeg?" i]) .recommend-btn,
.meme-image-container:has(img[src$=".png" i]) .recommend-btn,
.meme-image-container:has(img[src*=".png?" i]) .recommend-btn { display: flex; }
/* Explicitly hide when there is a GIF image (case-insensitive, handle optional query strings) */
.meme-image-container:has(img[src$=".gif" i]) .recommend-btn,
.meme-image-container:has(img[src*=".gif?" i]) .recommend-btn { display: none !important; }
/* Ensure hidden when there is a <video> */
.meme-image-container:has(video) .recommend-btn { display: none !important; }