:root {
    --bg-color: #0f172a;
    --card-bg: #1e293b;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --accent: #38bdf8;
    --border: #334155;
    --font-stack: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans SC", sans-serif;
    /* Added Chinese font support */
}

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

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: var(--font-stack);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 16px;
}

/* Header */
.site-header {
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(10px);
    position: sticky;
    top: 0;
    z-index: 100;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

.header-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--accent);
    white-space: nowrap;
}

/* Search Box */
.search-box {
    display: flex;
    background: var(--card-bg);
    border-radius: 99px;
    padding: 4px 12px;
    border: 1px solid var(--border);
    flex-grow: 1;
    /* max-width removed to take available space on mobile, controlled by parent flex */
}

.search-box input {
    background: transparent;
    border: none;
    color: white;
    padding: 6px;
    width: 100%;
    outline: none;
    font-size: 0.95rem;
}

.search-box button {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
}

/* Filter Dropdown UI */
.filter-wrapper {
    position: static;
    /* Change to static so menu can position relative to container or body if needed, BUT actually relative is better for anchoring.
                         However, to float ABOVE the header border, z-index needs to be handled carefully. */
    position: relative;
}

.btn-filter {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 0.9rem;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
    /* Ensure button is above overlay if overlay is full screen?
       Actually if overlay is 101, button is inside header (100).
       We should probably set .filter-wrapper to z-index 102 when active?
       Simplest is just making overlay very high */
}

.btn-filter:hover,
.btn-filter[aria-expanded="true"] {
    border-color: var(--accent);
    color: var(--accent);
}

.filter-menu {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 8px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
    min-width: 200px;
    max-width: 90vw;
    display: grid;
    grid-template-columns: 1fr;
    gap: 4px;
    padding: 8px;
    z-index: 102;
    /* Above overlay */
    max-height: 60vh;
    /* Limit height to trigger scroll sooner on mobile */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* Tablet: 2 cols */
@media (min-width: 500px) {
    .filter-menu {
        grid-template-columns: repeat(2, 1fr);
        min-width: 300px;
    }
}

/* Desktop: 3 cols */
@media (min-width: 800px) {
    .filter-menu {
        grid-template-columns: repeat(3, 1fr);
        min-width: 450px;
    }
}

.filter-item {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    text-align: left;
    padding: 10px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.95rem;
    transition: background 0.1s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-decoration: none;
    /* For <a> tags */
    display: block;
    /* Ensure full width click area */
}

.filter-item:hover,
.filter-item.active {
    background: rgba(56, 189, 248, 0.1);
    color: var(--accent);
}

/* Overlay for mobile click-out */
.filter-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 99;
    /* Below header (100) but above content */
    display: none;
    background: transparent;
}

.filter-overlay.active {
    display: block;
}


/* Resource Grid */
.resource-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    padding: 20px 0;
}

/* Back Button in Single View */
.btn-back-home {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background-color: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.9rem;
    cursor: pointer;
    margin-bottom: 1rem;
    transition: all 0.2s;
    grid-column: 1 / -1;
    width: fit-content;
}

.btn-back-home:hover {
    background-color: var(--accent);
    border-color: var(--accent);
}

@media (min-width: 640px) {
    .resource-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 20px;
    }
}

@media (min-width: 1024px) {
    .resource-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* Resource Card */
.card {
    background: var(--card-bg);
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--border);
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    flex-direction: column;
}

.card:hover {
    transform: translateY(-4px);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
}

.card-image {
    width: 100%;
    height: 180px;
    object-fit: cover;
    background: #000;
}

.card-content {
    padding: 16px;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}

.card-tag {
    font-size: 0.75rem;
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.05);
    padding: 2px 6px;
    border-radius: 4px;
    display: inline-block;
    align-self: flex-start;

    letter-spacing: 0.05em;
    font-weight: 500;
    margin-bottom: 8px;

    /* Interactive */
    cursor: pointer;
    text-decoration: none;
    /* No underline */
    transition: all 0.2s;
}

.card-tag:hover {
    color: var(--accent);
    background: rgba(56, 189, 248, 0.1);
}

.card-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-primary);
    line-height: 1.4;
}

.card-footer {
    margin-top: auto;
    padding-top: 12px;
}

.btn-download {
    display: block;
    width: 100%;
    text-align: center;
    background: #334155;
    color: white;
    text-decoration: none;
    padding: 10px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    transition: background 0.2s;
}

.btn-download:hover {
    background: var(--accent);
    color: #0f172a;
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    padding: 30px 0 50px;
}

.pagination button,
.pagination .page-number {
    background: var(--card-bg);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
}

.pagination .page-number.active {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--bg-color);
    font-weight: 600;
}

.pagination .page-number:hover:not(.active) {
    border-color: var(--accent);
    color: var(--accent);
}

.pagination .dots {
    color: var(--text-secondary);
    padding: 0 4px;
}

.pagination .page-jump {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: 12px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.pagination .page-input {
    width: 60px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    color: white;
    padding: 6px 8px;
    border-radius: 6px;
    text-align: center;
    font-size: 0.9rem;
    outline: none;
}

.pagination .page-input:focus {
    border-color: var(--accent);
}

.pagination .page-input::-webkit-inner-spin-button,
.pagination .page-input::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* Mobile adjustments for pagination */
@media (max-width: 640px) {
    .pagination {
        flex-wrap: wrap;
        gap: 8px;
    }

    .pagination .page-jump {
        width: 100%;
        justify-content: center;
        margin-left: 0;
        margin-top: 8px;
    }
}

/* --- Enhanced UI: Loading & Empty State --- */

/* Loading Spinner */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 0;
    color: var(--text-secondary);
    gap: 16px;
    animation: fadeIn 0.3s ease;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(56, 189, 248, 0.1);
    border-top: 3px solid var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

    100% {
        transform: rotate(360deg);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Empty State (Not Found) */
.empty-state {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 80px 20px;
    background: rgba(30, 41, 59, 0.4);
    border: 1px dashed var(--border);
    border-radius: 20px;
    margin: 20px 0;
    animation: fadeIn 0.5s ease;
}

.empty-icon {
    font-size: 3rem;
    margin-bottom: 20px;
    opacity: 0.5;
}

.empty-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.empty-text {
    color: var(--text-secondary);
    max-width: 300px;
    font-size: 0.95rem;
}

.btn-reset-search {
    margin-top: 24px;
    padding: 10px 20px;
    background: var(--card-bg);
    border: 1px solid var(--accent);
    color: var(--accent);
    border-radius: 99px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s;
}

.btn-reset-search:hover {
    background: var(--accent);
    color: var(--bg-color);
}

/* Error State */
.error {
    text-align: center;
    padding: 40px;
    color: #f87171;
    background: rgba(248, 113, 113, 0.1);
    border-radius: 12px;
    margin: 20px 0;
}

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