.posts-wrapper {
    width: 100%;
    max-width: 1400px; /* Or whatever your site's max width is */
    margin: 0 auto;
    padding: 0 2rem;   /* Side breathing room */
}

.archive-header {
    width: 100%;       /* Force full width of the wrapper */
    display: flex;
    flex-direction: column;
    align-items: center; /* Centers the text and search bar */
    text-align: center;
    padding: 4rem 0;   /* Vertical spacing */
    margin: 0 auto;
}

.premium-title {
    font-size: clamp(3rem, 7vw, 4.5rem);
    font-weight: 800;
    color: var(--text-black);
    letter-spacing: -2px;
    margin-top: 10rem;
}

.premium-title span {
    font-family: 'Dancing Script', cursive;
    color: var(--accent-color);
    margin-left: 5px;
    font-weight: 400;
}

.subtitle {
    color: var(--text-muted);
    font-size: 1.1rem;
    margin-top: 1rem;
    font-weight: 500;
}

/* --- 2. Advanced Search Section --- */
.search-container {
    max-width: 600px;
    margin: 3rem auto;
    perspective: 1000px;
}

.search-box {
    position: relative;
    display: flex;
    align-items: center;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 6px 25px;
    border-radius: 100px;
    transition: all 0.5s cubic-bezier(0.165, 0.84, 0.44, 1);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.03);
}

.search-box:focus-within {
    transform: scale(1.02) translateY(-4px);
    border-color: var(--accent-color);
    box-shadow: 0 20px 40px rgba(99, 102, 241, 0.1);
    background: #fff;
}

#postSearch {
    width: 100%;
    border: none;
    background: transparent;
    padding: 16px 0;
    font-size: 1rem;
    font-weight: 600;
    outline: none;
    color: var(--text-black);
}

/* --- 4. Category Filter Pills --- */
.category-filter {
    width: 100%;
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.cat-pill {
    padding: 0.8rem 1.8rem;
    border-radius: 100px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    text-decoration: none;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 600;
    transition: all 0.5s cubic-bezier(0.165, 0.84, 0.44, 1);
}

.cat-pill:hover, .cat-pill.active {
    background: var(--text-black);
    color: white;
    transform: translateY(-3px);
}

.cat-pill.active {
    background: var(--accent-color);
    border-color: var(--accent-color);
}

/* --- 5. The Premium Post Grid & Hover Logic --- */

.posts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
    gap: 4rem 2.5rem;
    margin-top: 4rem;
}

.grid-card {
    background: var(--bg-light);
    border: 1px solid rgba(0, 0, 0, 0.05);
    overflow: hidden;
    transition: all 0.4s cubic-bezier(0.165, 0.84, 0.44, 1);
    display: flex;
    flex-direction: column;
}

/* --- Image Container: The Focus Point --- */

.img-container {
    position: relative;
    height: 280px;
    border-radius: 20px; /* Slightly smaller than card radius for nested look */
    overflow: hidden;
    margin-bottom: 1.5rem;
    background: var(--text-black);
    transition: box-shadow 0.4s ease;
}

/* Subtle Accent Tint Overlay */
.img-container::after {
    content: '';
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: var(--accent-color);
    mix-blend-mode: multiply;
    opacity: 0.15;
    z-index: 1;
    pointer-events: none;
    transition: opacity 0.6s ease;
}

.img-container img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    filter: grayscale(100%) brightness(0.9);
    transition: transform 1s cubic-bezier(0.19, 1, 0.22, 1), 
                filter 0.6s ease;
}

/* --- Hover State Interactions --- */

.grid-card:hover {
    transform: translateY(-12px);
    box-shadow: 0 30px 60px -12px rgba(0, 0, 0, 0.15);
    border-color: rgba(99, 102, 241, 0.2); /* Soft indigo border reveal */
}

.grid-card:hover .img-container img {
    transform: scale(1.08);
    filter: grayscale(0%) brightness(1);
}

.grid-card:hover .img-container::after {
    opacity: 0;
}

.grid-card:hover h3 a {
    color: var(--accent-color);
}

/* --- Content Typography & Elements --- */

.grid-content {
    padding: 0 1rem 1rem 1rem;
}

.card-meta-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.date {
    font-size: 0.75rem;
    font-weight: 800;
    color: var(--accent-color);
    text-transform: uppercase;
    letter-spacing: 1.5px;
}

.card-views {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 600;
}

.grid-content h3 {
    margin-bottom: 1rem;
    line-height: 1.4;
}

.grid-content h3 a {
    text-decoration: none;
    color: var(--text-black);
    font-size: 1.4rem;
    transition: color 0.3s ease;
}

.grid-content p {
    color: var(--text-muted);
    font-size: 0.95rem;
    line-height: 1.6;
    margin-bottom: 1.5rem;
}

/* --- Premium Badge (Glassmorphism) --- */

.badge {
    position: absolute;
    top: 15px;
    left: 15px;
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    padding: 6px 14px;
    border-radius: 10px;
    font-size: 0.65rem;
    font-weight: 900;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--text-black);
    z-index: 2;
    box-shadow: var(--shadow-sm);
}

/* --- Arrow Link --- */

.arrow-link {
    text-decoration: none;
    color: var(--text-black);
    font-weight: 800;
    font-size: 0.85rem;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: color 0.3s ease;
}

.arrow-link span {
    transition: transform 0.3s ease;
}

.grid-card:hover .arrow-link {
    color: var(--accent-color);
}

.grid-card:hover .arrow-link span {
    transform: translateX(6px);
}
/* --- 6. Pagination Styling (Responsive Fix) --- */
/* --- Pagination Main Container --- */
.pagination-container {
    margin-top: 8rem;
    display: flex;
    justify-content: center;
    padding: 0 15px; /* Safety margin for mobile */
}

/* --- The Pill Wrapper --- */
.pagination-wrapper {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding: 0.8rem 2rem;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-radius: 100px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.03);
    transition: var(--transition-premium);
}

/* --- Nav Links (Prev/Next) --- */
.page-nav {
    text-decoration: none;
    color: var(--text-black);
    font-weight: 700;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: var(--transition-fast);
}

.page-nav:hover {
    color: var(--accent-color);
}

/* --- Number Grouping --- */
.page-numbers {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* --- Individual Circular Page Numbers --- */
.page-num {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.9rem;
    border-radius: 50%;
    transition: all 0.4s cubic-bezier(0.165, 0.84, 0.44, 1);
}

.page-num:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--text-black);
    transform: translateY(-2px);
}

.page-num.active {
    background: var(--accent-color);
    color: #ffffff;
    box-shadow: 0 8px 20px rgba(99, 102, 241, 0.2);
}

/* --- Ellipsis Styling --- */
.page-dots {
    color: var(--text-muted);
    font-weight: 800;
    padding: 0 4px;
    user-select: none;
}

/* --- Responsive Fixes --- */
@media (max-width: 768px) {
    .pagination-wrapper {
        gap: 1rem;
        padding: 0.6rem 1.2rem;
    }

    /* Hide "Previous/Next" text to save horizontal space */
    .nav-text {
        display: none;
    }

    .page-nav {
        font-size: 1.2rem; /* Make arrows larger for easy tapping */
    }

    .page-num {
        width: 36px;
        height: 36px;
    }
}

@media (max-width: 480px) {
    .pagination-wrapper {
        gap: 0.5rem;
    }

    .page-num {
        width: 32px;
        height: 32px;
        font-size: 0.8rem;
    }

    .page-numbers {
        gap: 4px;
    }
}

/* --- 7. Responsive --- */
@media (max-width: 992px) {
    .posts-grid { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
}

@media (max-width: 768px) {
    .posts-grid { grid-template-columns: 1fr; }
    .premium-title { font-size: 2.5rem; }
}

/* Ensure the container allows absolute positioning */
.posts-grid .img-container {
    position: relative;
    overflow: visible !important; /* Changed from hidden to visible */
}

/* Specific styling for the Explore page badge */
.posts-grid .trending-badge-mini {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 100; /* Ensure it's above the image and category badge */
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(5px);
    padding: 4px 10px;
    border-radius: 50px;
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.7rem;
    font-weight: 800;
    color: #ea580c; /* Trending orange */
    border: 1px solid rgba(234, 88, 12, 0.2);
    box-shadow: 0 4px 10px rgba(0,0,0,0.15);
    pointer-events: none; /* Prevents badge from blocking clicks to the post */
}

/* Pulsing effect for the fire icon to prove it's live */
.posts-grid .fire-icon {
    animation: trendPulse 1.5s infinite alternate;
}

@keyframes trendPulse {
    from { transform: scale(1); opacity: 1; }
    to { transform: scale(1.2); opacity: 0.8; }
}



.archive-header {
    text-align: center;
    max-width: 900px;
    margin: 0 auto 60px;
    padding: 0 20px;
}

/* Search Section Styling */
.search-section {
    width: 100%;
    max-width: 800px; /* Optional: keeps the search bar from getting too wide on huge screens */
    margin: 2.5rem auto;
}

.search-box {
    display: flex;
    align-items: center;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    padding: 6px;
    border-radius: 100px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.03);
}

.search-box:focus-within {
    border-color: var(--accent-color);
    box-shadow: 0 10px 25px rgba(99, 102, 241, 0.1);
    transform: translateY(-2px);
}

.search-icon-wrapper {
    padding-left: 18px;
    color: #94a3b8;
    display: flex;
    align-items: center;
}

.search-box input {
    flex: 1;
    border: none;
    outline: none;
    padding: 10px 15px;
    font-size: 1rem;
    font-weight: 500;
}

.btn-search-trigger {
    background: #111827;
    color: white;
    border: none;
    padding: 10px 24px;
    border-radius: 100px;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-search-trigger:hover {
    background: var(--accent-color);
}

/* --- Advanced Discovery Cloud --- */

.tag-cloud {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin: 2rem auto;
    padding: 0 1rem;
}

/* Elegant Label */
.tag-label {
    font-size: 0.7rem;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--text-muted);
    margin-right: 10px;
    user-select: none;
}

/* The Advanced Pill */
.tag-pill {
    display: inline-flex;
    align-items: center;
    padding: 6px 16px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-dark);
    background: transparent;
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 100px;
    text-decoration: none;
    transition: all 0.4s cubic-bezier(0.23, 1, 0.32, 1);
    position: relative;
    overflow: hidden;
}

/* Micro-Interaction: Hover */
.tag-pill:hover {
    color: var(--accent-color);
    border-color: var(--accent-color);
    transform: translateY(-2px);
    background: rgba(99, 102, 241, 0.03);
    box-shadow: 0 10px 20px rgba(99, 102, 241, 0.08);
}

/* High-Contrast Active State */
.tag-pill.active {
    background: var(--text-black);
    border-color: var(--text-black);
    color: #ffffff;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
}

/* Subtle Hash Color */
.tag-pill #hash-symbol, 
.tag-pill::before {
    content: '#'; /* If you want to handle it via CSS */
    color: var(--accent-color);
    margin-right: 3px;
    font-weight: 800;
    opacity: 0.8;
}

.tag-pill.active #hash-symbol {
    color: var(--accent-color); /* Keeps the indigo hash even on black background */
}

.archive-header {
    width: 100% !important;
    max-width: 100% !important;
    padding-left: 0;
    padding-right: 0;
}

.tag-cloud {
    max-width: 1200px; /* Limits the inner content width for readability */
    margin-left: auto;
    margin-right: auto;
}

.search-box { position: relative; z-index: 1000; }

/* The Dropdown Panel */
.search-suggestions-dropdown {
    position: absolute;
    top: calc(100% + 12px);
    left: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.1);
    border: 1px solid rgba(0,0,0,0.05);
    overflow: hidden;
    display: none;
    transform-origin: top;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Individual Suggestion Item */
.suggestion-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 25px;
    text-decoration: none;
    transition: all 0.2s;
    border-bottom: 1px solid rgba(0,0,0,0.03);
}

.suggestion-item:last-child { border-bottom: none; }
.suggestion-item:hover { background: rgba(99, 102, 241, 0.05); }

.suggestion-info { display: flex; flex-direction: column; gap: 4px; }
.suggestion-title { font-weight: 700; color: #1e293b; font-size: 0.95rem; }
.suggestion-tag { font-size: 0.7rem; color: var(--accent-color); font-weight: 800; text-transform: uppercase; letter-spacing: 1px; }

/* The Loading Spinner */
.search-spinner {
    width: 18px;
    height: 18px;
    border: 2.5px solid rgba(99, 102, 241, 0.2);
    border-top: 2.5px solid var(--accent-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { 100% { transform: rotate(360deg); } }

/* Highlight state for keyboard navigation */
.suggestion-item.is-selected {
    background: rgba(99, 102, 241, 0.08); /* Light Indigo tint */
    border-left: 4px solid var(--accent-color, #6366f1);
    outline: none;
}

.suggestion-item.is-selected .suggestion-title {
    color: var(--accent-color, #6366f1);
}

/* Ensure the dropdown list is scrollable if it gets too long */
.search-suggestions-dropdown {
    max-height: 400px;
    overflow-y: auto;
}

.suggestion-item {
    background: #ffffff !important;
    border-bottom: 1px solid #eeeeee;
    display: block;
    padding: 15px;
    z-index: 9999;
}
.suggestion-title {
    color: #1a1a1a !important; /* Force dark text */
    font-weight: bold;
}


.card-meta-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.card-views {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted, #64748b);
    background: #f8fafc;
    padding: 2px 8px;
    border-radius: 6px;
    transition: all 0.3s ease;
}

.grid-card:hover .card-views {
    color: var(--accent-color, #6366f1);
    background: #f5f3ff;
}

.card-views svg {
    opacity: 0.7;
}


/* --- Advanced Zero-State (Empty Message) --- */

.empty-msg {
    grid-column: 1 / -1; /* Spans the full width of your post grid */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 6rem 2rem;
    background: rgba(255, 255, 255, 0.6);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    border-radius: 32px;
    margin: 4rem auto;
    max-width: 700px;
    animation: fadeInScale 0.8s cubic-bezier(0.22, 1, 0.36, 1);
}

.empty-icon-wrapper {
    position: relative;
    width: 80px;
    height: 80px;
    background: var(--bg-light);
    border-radius: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 2rem;
    box-shadow: 0 20px 40px rgba(0,0,0,0.05);
    animation: floating 3s ease-in-out infinite;
}

.empty-icon-wrapper svg {
    color: var(--accent-color);
}

.empty-msg h3 {
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--text-black);
    margin-bottom: 1rem;
    letter-spacing: -0.02em;
}

.empty-msg p {
    color: var(--text-muted);
    font-size: 1.05rem;
    line-height: 1.6;
    max-width: 400px;
    margin-bottom: 2.5rem;
}

.empty-msg b {
    display: block;
    margin-top: 1rem;
    font-size: 0.85rem;
    color: var(--accent-color);
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* --- Animated CTA Button --- */
.btn-reset-discovery {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    padding: 14px 28px;
    background: var(--text-black);
    color: #fff;
    text-decoration: none;
    border-radius: 100px;
    font-weight: 700;
    font-size: 0.9rem;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.btn-reset-discovery:hover {
    transform: scale(1.05);
    background: var(--accent-color);
    box-shadow: 0 15px 30px rgba(99, 102, 241, 0.3);
}

/* --- Keyframe Animations --- */

@keyframes fadeInScale {
    0% { opacity: 0; transform: translateY(20px) scale(0.95); }
    100% { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes floating {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

@media screen and (max-width: 768px) {
    /* 1. Container Fix */
    .search-section {
        width: 100%;
        padding: 0 15px; /* Side padding to prevent edge-touching */
        box-sizing: border-box;
    }

    .premium-search-form {
        width: 100%;
    }

    /* 2. The Search Box Engine */
    .search-box {
        display: flex;
        align-items: center;
        background: var(--bg-light);
        border: 1.5px solid var(--glass-border);
        border-radius: 16px;
        padding: 6px 8px; /* Compact padding */
        gap: 8px;
        width: 100%;
        box-sizing: border-box;
        box-shadow: var(--shadow-sm);
        position: relative;
    }

    /* 3. Input Scaling */
    #searchInput {
        flex: 1; /* Takes all available space */
        min-width: 0; /* Prevents input from pushing the button out */
        border: none;
        outline: none;
        background: transparent;
        font-size: 0.9rem;
        font-weight: 500;
        color: var(--text-dark);
        padding: 8px 0;
    }

    /* Shorten placeholder for small screens */
    #searchInput::placeholder {
        font-size: 0.8rem;
        color: var(--text-muted);
    }

    /* 4. Search Icon Wrapper */
    .search-icon-wrapper {
        flex-shrink: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        padding-left: 4px;
        color: var(--accent-color);
    }

    /* 5. Mobile Button Optimization */
    .btn-search-trigger {
        background: var(--accent-color);
        color: #ffffff;
        border: none;
        padding: 10px 16px;
        border-radius: 12px;
        font-size: 0.85rem;
        font-weight: 600;
        cursor: pointer;
        flex-shrink: 0; /* Prevents button from squashing */
        transition: transform 0.2s ease;
    }

    .btn-search-trigger:active {
        transform: scale(0.95);
    }

    /* 6. Suggestion Dropdown Fix */
    #searchSuggestions {
        position: absolute;
        top: calc(100% + 8px);
        left: 0;
        right: 0;
        width: 100%;
        max-height: 250px;
        overflow-y: auto;
        z-index: 1000;
        border-radius: 12px;
        background: var(--bg-light);
        border: 1px solid var(--glass-border);
        box-shadow: 0 10px 25px rgba(0,0,0,0.1);
    }
}




/* --- Desktop Premium --- */
@media screen and (min-width: 769px) {
    .mobile-filter-trigger, .filter-overlay-advanced { display: none; }
    
    .filter-header-inline { display: flex; align-items: center; gap: 15px; margin-bottom: 20px; }
    .filter-label { font-size: 0.7rem; font-weight: 800; letter-spacing: 2px; color: var(--text-muted); text-transform: uppercase; }
    .label-line-glow { height: 1px; flex-grow: 1; background: linear-gradient(90deg, var(--accent-color), transparent); opacity: 0.3; }

    .category-grid-inline { display: flex; flex-wrap: wrap; gap: 10px; }
    
    .glass-pill {
        background: rgba(255, 255, 255, 0.05);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        border: 1px solid rgba(255, 255, 255, 0.1);
        padding: 10px 20px; border-radius: 12px;
        color: var(--text-dark); font-weight: 600; font-size: 0.85rem;
        transition: all 0.4s cubic-bezier(0.23, 1, 0.32, 1);
        text-decoration: none;
    }

    .glass-pill:hover { background: rgba(255, 255, 255, 0.1); transform: translateY(-3px); border-color: var(--accent-color); }
    .glass-pill.active { background: var(--accent-color); color: #fff; border-color: var(--accent-color); box-shadow: 0 8px 20px rgba(99, 102, 241, 0.3); }
}

/* --- Mobile Advanced Glassmorphism --- */
@media screen and (max-width: 768px) {
    .desktop-filter-nav { display: none; }

    .btn-glass-trigger {
        width: 100%; display: flex; align-items: center; justify-content: center; gap: 12px;
        padding: 14px; background: rgba(30, 41, 59, 0.9); /* Deep slate glass */
        backdrop-filter: blur(12px); border: 1px solid rgba(255, 255, 255, 0.1);
        border-radius: 20px; color: #fff; font-weight: 700; font-size: 0.95rem;
        box-shadow: 0 15px 35px rgba(0,0,0,0.2);
    }

    .icon-orbit { color: var(--accent-color); animation: rotate 4s linear infinite; }
    @keyframes rotate { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

    .filter-overlay-advanced {
        position: fixed; inset: 0; background: rgba(15, 23, 42, 0.4);
        backdrop-filter: blur(8px); z-index: 99999; display: none; opacity: 0; transition: 0.4s;
    }

    .filter-overlay-advanced.active { display: block; opacity: 1; }

    .filter-sheet-glass {
        position: absolute; bottom: -100%; left: 0; width: 100%;
        max-height: 75vh; background: rgba(255, 255, 255, 0.85);
        backdrop-filter: blur(25px) saturate(180%);
        -webkit-backdrop-filter: blur(25px) saturate(180%);
        border-radius: 35px 35px 0 0; border: 1px solid rgba(255, 255, 255, 0.4);
        padding: 15px 20px 40px; transition: 0.6s cubic-bezier(0.19, 1, 0.22, 1);
        padding-bottom: calc(40px + env(safe-area-inset-bottom));
    }

    .filter-overlay-advanced.active .filter-sheet-glass { bottom: 0; }

    .sheet-indicator { width: 40px; height: 5px; background: rgba(0,0,0,0.1); border-radius: 10px; margin: 0 auto 20px; }

    .sheet-header-premium h4 { font-size: 1.3rem; font-weight: 900; color: #0f172a; margin: 0; }
    .btn-close-circle { background: #0f172a; color: #fff; border: none; width: 30px; height: 30px; border-radius: 50%; cursor: pointer; }

    .sheet-scroll-container { overflow-y: auto; margin-top: 20px; padding-bottom: 20px; }

    .category-grid-premium { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

    .pill-premium {
        background: rgba(255, 255, 255, 0.4); border: 1px solid rgba(255, 255, 255, 0.6);
        padding: 16px; border-radius: 20px; text-decoration: none;
        display: flex; flex-direction: column; gap: 4px; transition: 0.3s;
    }

    .p-title { font-weight: 800; font-size: 0.9rem; color: #1e293b; }
    .p-sub { font-size: 0.65rem; color: #64748b; font-weight: 600; text-transform: uppercase; }

    .pill-premium.active { background: var(--accent-color); border-color: var(--accent-color); }
    .pill-premium.active .p-title, .pill-premium.active .p-sub { color: #fff; }
}

@media screen and (max-width: 768px) {
    /* ... (keep other styles) ... */

    .sheet-scroll-container { 
        overflow-y: auto; 
        margin-top: 20px; 
        /* The "Safety Buffer" - prevents items from being cut off */
        padding-bottom: 80px; 
        max-height: calc(75vh - 100px); /* Adjusts height based on header */
        
        /* Smooth scrolling for mobile */
        -webkit-overflow-scrolling: touch;
    }

    .category-grid-premium { 
        display: grid; 
        grid-template-columns: 1fr 1fr; 
        gap: 12px;
        /* Ensure the last items have space below them */
        margin-bottom: 20px; 
    }

    /* Enhanced Pill Touch Target */
    .pill-premium {
        min-height: 85px; /* Ensures consistent size */
        display: flex;
        flex-direction: column;
        justify-content: center;
        background: rgba(255, 255, 255, 0.5);
        border: 1px solid rgba(255, 255, 255, 0.8);
        border-radius: 20px;
        padding: 16px;
        transition: transform 0.2s ease;
    }

    .pill-premium:active {
        transform: scale(0.96);
    }
}

@media screen and (max-width: 768px) {
    .p-sub {
        font-size: 0.65rem;
        color: var(--text-muted);
        font-weight: 700;
        letter-spacing: 0.05em;
        /* Ensures the text stays on one line */
        white-space: nowrap; 
    }
    
    .sheet-scroll-container {
        /* Extra padding so the database-driven list doesn't touch the bottom edge */
        padding-bottom: 100px !important; 
    }
}

@media screen and (min-width: 769px) {
    .category-grid-inline {
        display: flex;
        flex-wrap: wrap;
        gap: 15px;
    }

    .glass-pill {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 8px 12px 8px 20px;
        /* Subtle dark glass base to make white text readable */
        background: rgba(30, 41, 59, 0.05); 
        backdrop-filter: blur(15px);
        -webkit-backdrop-filter: blur(15px);
        border: 1px solid rgba(15, 23, 42, 0.1);
        border-radius: 100px;
        color: var(--text-dark); /* Default text color */
        font-weight: 700;
        text-decoration: none;
        transition: all 0.4s cubic-bezier(0.23, 1, 0.32, 1);
    }

    /* 1. HOVER STATE: Fix for Readability */
    .glass-pill:hover {
        transform: translateY(-4px);
        background: rgba(255, 255, 255, 1); /* Pure white background on hover */
        border-color: var(--accent-color);
        /* Change text color to Indigo so it's readable against white */
        color: var(--accent-color) !important; 
        box-shadow: 0 10px 20px rgba(99, 102, 241, 0.15);
    }

    /* 2. CIRCLE STATE: Transitions with the pill */
    .count-circle {
        display: flex;
        align-items: center;
        justify-content: center;
        min-width: 30px;
        height: 30px;
        border-radius: 50%;
        background: var(--text-dark); /* Dark circle by default */
        color: #ffffff; /* White number by default */
        font-size: 0.75rem;
        font-weight: 800;
        transition: all 0.3s ease;
    }

    /* When hovering the pill, make the circle Indigo */
    .glass-pill:hover .count-circle {
        background: var(--accent-color);
        color: #ffffff;
    }

    /* 3. ACTIVE STATE: High Contrast Premium */
    .glass-pill.active {
        background: var(--accent-color);
        color: #ffffff !important; /* Pure white text on Indigo bg */
        border-color: var(--accent-color);
        box-shadow: 0 12px 24px rgba(99, 102, 241, 0.3);
    }

    .glass-pill.active .count-circle {
        background: rgba(255, 255, 255, 0.2);
        color: #ffffff;
    }
}


@media screen and (max-width: 768px) {
    /* 1. The Container: Forced 2-Row Engine */
    .tag-cloud {
        display: flex !important;
        flex-direction: column; /* Stack rows vertically */
        flex-wrap: wrap !important; /* Allow wrapping to create the 2nd row */
        
        /* Fixed height ensures exactly 2 rows (approx 45px per row + gap) */
        height: 110px; 
        overflow-x: auto !important;
        overflow-y: hidden !important;
        
        padding: 10px 15px;
        gap: 12px;
        
        /* Smooth scrolling physics */
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x proximity;
        
        /* Hide Scrollbars */
        scrollbar-width: none;
    }

    .tag-cloud::-webkit-scrollbar {
        display: none;
    }

    /* 2. The Label: Positioned at the start of the first row */
    .tag-label {
        flex: 0 0 auto;
        display: flex;
        align-items: center;
        height: 38px; /* Match tag height */
        font-size: 0.7rem;
        font-weight: 800;
        text-transform: uppercase;
        letter-spacing: 0.1em;
        color: var(--accent-color);
        background: rgba(99, 102, 241, 0.1);
        padding: 0 15px;
        border-radius: 12px;
        margin-right: 8px;
        white-space: nowrap;
    }

    /* 3. The Premium Tag Pill */
    .tag-pill {
        flex: 0 0 auto; /* Crucial: prevents pills from shrinking */
        display: flex;
        align-items: center;
        height: 38px; /* Fixed height for row alignment */
        padding: 0 18px;
        
        background: rgba(255, 255, 255, 0.05);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        border: 1px solid var(--glass-border);
        border-radius: 12px;
        
        color: var(--text-dark);
        font-weight: 600;
        font-size: 0.85rem;
        text-decoration: none;
        white-space: nowrap;
        
        scroll-snap-align: start;
        transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    /* 4. Interactive & Active States */
    .tag-pill.active {
        background: var(--accent-color);
        color: #ffffff;
        border-color: var(--accent-color);
        box-shadow: 0 8px 16px rgba(99, 102, 241, 0.25);
    }

    .tag-hash::before {
        content: '#';
        margin-right: 4px;
        font-weight: 800;
        color: var(--accent-color);
    }

    .tag-pill.active .tag-hash::before {
        color: rgba(255, 255, 255, 0.8);
    }

    /* Fade Effect on the right to signal more tags */
    .tag-cloud::after {
        content: '';
        position: absolute;
        right: 0;
        top: 0;
        width: 40px;
        height: 100%;
        background: linear-gradient(to right, transparent, var(--bg-light));
        pointer-events: none;
    }
}