/* ============================================
 * Modern Card-Based Category Layout
 * Optimized Light/Dark Adaptive System
 * ============================================ */

/* ============================================
 * Grid Container
 * ============================================ */
.category-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
    padding: 20px 0;
    width: 100%;
    box-sizing: border-box;
}

/* ============================================
 * Card Base Style - Light Background (Default)
 * ============================================ */
.category-card {
    border-radius: 12px;
    padding: 20px;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.3s ease;
    border-left: 5px solid var(--category-color, #999);
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: visible; /* 改为 visible 防止图标被裁剪 */
}

/* Light Background - Category Card */
body.light-background .category-card,
body:not(.dark-background) .category-card {
    background: rgba(255, 255, 255, 0.95) !important;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(0, 0, 0, 0.08) !important;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08);
}

body.light-background .category-card:hover,
body:not(.dark-background) .category-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    background: rgba(255, 255, 255, 1) !important;
}

/* Dark Background - Category Card */
body.dark-background .category-card {
    background: rgba(255, 255, 255, 0.12) !important;
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border: 1px solid rgba(255, 255, 255, 0.15) !important;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

body.dark-background .category-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
    background: rgba(255, 255, 255, 0.18) !important;
}

/* ============================================
 * Card Header Section
 * ============================================ */
.card-header {
    display: flex;
    align-items: center;
    margin-bottom: 15px;
    padding-bottom: 12px;
    transition: border-color 0.3s ease;
}

/* Light Background - Header */
body.light-background .card-header,
body:not(.dark-background) .card-header {
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

/* Dark Background - Header */
body.dark-background .card-header {
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

/* ============================================
 * Card Icon (Emoji)
 * ============================================ */
.card-icon {
    font-size: 28px;
    margin-right: 12px;
    filter: grayscale(0.2);
    transition: all 0.3s ease;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px; /* 防止图标压缩 */
    flex-shrink: 0; /* 防止图标缩小 */
}

.category-card:hover .card-icon {
    filter: grayscale(0);
    transform: scale(1.1);
}

/* ============================================
 * Card Title
 * ============================================ */
.card-title {
    font-size: 18px;
    font-weight: bold;
    text-decoration: none;
    flex-grow: 1;
    letter-spacing: 0.5px;
    transition: color 0.3s ease;
}

/* Light Background - Title */
body.light-background .card-title,
body:not(.dark-background) .card-title {
    color: #2a2a2a !important;
}

body.light-background .card-title:hover,
body:not(.dark-background) .card-title:hover {
    color: var(--category-color, #667eea) !important;
}

/* Dark Background - Title */
body.dark-background .card-title {
    color: #ffffff !important;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

body.dark-background .card-title:hover {
    color: var(--category-color, #667eea) !important;
}

/* ============================================
 * Card Count Badge
 * ============================================ */
.card-count {
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
    transition: all 0.3s ease;
}

/* Light Background - Count */
body.light-background .card-count,
body:not(.dark-background) .card-count {
    background: rgba(0, 0, 0, 0.05);
    color: #666;
}

/* Dark Background - Count */
body.dark-background .card-count {
    background: rgba(255, 255, 255, 0.15);
    color: rgba(255, 255, 255, 0.85);
}

/* ============================================
 * Sub-categories Tag Cloud
 * ============================================ */
.subcategory-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    list-style: none;
    padding: 0;
    margin: 0;
    margin-top: auto; /* Push to bottom */
}

.subcategory-item {
    display: block;
}

.subcategory-link {
    display: inline-block;
    padding: 5px 10px;
    border-radius: 6px;
    font-size: 13px;
    text-decoration: none;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

/* Light Background - Subcategory Links */
body.light-background .subcategory-link,
body:not(.dark-background) .subcategory-link {
    background: rgba(0, 0, 0, 0.05);
    color: #2a2a2a !important;
}

body.light-background .subcategory-link:hover,
body:not(.dark-background) .subcategory-link:hover {
    background: #ffffff;
    color: var(--category-color, #667eea) !important;
    border-color: var(--category-color, #667eea);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.08);
}

/* Dark Background - Subcategory Links */
body.dark-background .subcategory-link {
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.9) !important;
}

body.dark-background .subcategory-link:hover {
    background: rgba(255, 255, 255, 0.2);
    color: #ffffff !important;
    border-color: var(--category-color, #667eea);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}

/* ============================================
 * Mobile Responsiveness
 * ============================================ */
@media screen and (max-width: 768px) {
    .category-container {
        grid-template-columns: 1fr; /* Single column on mobile */
        padding: 15px 0;
    }

    .category-card {
        padding: 16px;
    }

    .card-icon {
        font-size: 24px;
        min-width: 28px;
    }

    .card-title {
        font-size: 16px;
    }

    .subcategory-link {
        font-size: 12px;
        padding: 4px 8px;
    }
}

/* ============================================
 * Print Styles
 * ============================================ */
@media print {
    .category-card {
        break-inside: avoid;
        box-shadow: none;
        border: 1px solid #ddd;
    }
}
