/* 模板卡片样式 */
.templates-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: var(--spacing-xl);
    margin-top: var(--spacing-2xl);
    padding: 0 var(--spacing-sm);
}

@media (min-width: 768px) {
    .templates-grid {
        grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
        gap: var(--spacing-2xl);
        padding: 0;
    }
}

@media (min-width: 1200px) {
    .templates-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 2rem;
    }
}

.template-card {
    background: var(--background);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06), 0 1px 3px rgba(0, 0, 0, 0.1);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid rgba(0, 0, 0, 0.06);
    position: relative;
    cursor: pointer;
    transform: translateZ(0); /* 启用硬件加速 */
}

.template-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.02) 0%, rgba(118, 75, 162, 0.02) 100%);
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 1;
    pointer-events: none;
}

.template-card:hover {
    transform: translateY(-6px) scale(1.02);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.12), 0 8px 16px rgba(0, 0, 0, 0.08);
    border-color: rgba(102, 126, 234, 0.2);
}

.template-card:hover::before {
    opacity: 1;
}

.template-card:active {
    transform: translateY(-2px) scale(1.01);
}

/* 预览区域增强 */
.template-preview {
    height: 220px;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.template-preview::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: url('data:image/svg+xml;charset=UTF-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><defs><pattern id="grid" width="20" height="20" patternUnits="userSpaceOnUse"><path d="M 20 0 L 0 0 0 20" fill="none" stroke="%23dee2e6" stroke-width="0.5"/></pattern></defs><rect width="100" height="100" fill="url(%23grid)"/></svg>') repeat;
    opacity: 0.4;
}

.template-preview::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(45deg, transparent 48%, rgba(255, 255, 255, 0.1) 49%, rgba(255, 255, 255, 0.1) 51%, transparent 52%);
    transform: translateX(-100%);
    transition: transform 0.6s ease;
}

.template-card:hover .template-preview::after {
    transform: translateX(100%);
}

.preview-content {
    position: relative;
    z-index: 2;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    padding: var(--spacing-lg);
}

.preview-cell {
    width: 48px;
    height: 48px;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--background);
    position: relative;
    font-size: 20px;
    font-weight: 600;
    color: var(--primary-color);
    transition: all 0.2s ease;
}

.preview-cell.sample {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-color: #667eea;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.preview-cell.trace {
    color: #95a5a6;
    background: #fafbfc;
    border-color: #e9ecef;
}

.preview-cell.empty {
    background: #fafbfc;
    border-color: #e9ecef;
    border-style: dashed;
}

.preview-cell .pinyin {
    position: absolute;
    top: 3px;
    left: 4px;
    font-size: 9px;
    color: rgba(255, 255, 255, 0.8);
    font-weight: 500;
}

.template-card:hover .preview-cell {
    transform: scale(1.05);
}

.template-card:hover .preview-cell.sample {
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

/* 模板徽章优化 */
.template-badge {
    position: absolute;
    top: 12px;
    right: 12px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
    z-index: 3;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

/* 内容区域优化 */
.template-content {
    padding: 24px;
    position: relative;
    z-index: 2;
}

.template-header {
    margin-bottom: 16px;
}

.template-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.template-type {
    display: inline-block;
    background: rgba(102, 126, 234, 0.1);
    color: #667eea;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 12px;
    border: 1px solid rgba(102, 126, 234, 0.2);
}

.template-description {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.5;
    margin-bottom: 20px;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* 特性标签 */
.template-features {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 20px;
}

.feature-tag {
    background: rgba(39, 174, 96, 0.1);
    color: #27ae60;
    padding: 4px 8px;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 500;
    border: 1px solid rgba(39, 174, 96, 0.2);
}

.feature-tag.pinyin {
    background: rgba(52, 152, 219, 0.1);
    color: #3498db;
    border-color: rgba(52, 152, 219, 0.2);
}

.feature-tag.stroke {
    background: rgba(230, 126, 34, 0.1);
    color: #e67e22;
    border-color: rgba(230, 126, 34, 0.2);
}

/* 操作按钮区域 */
.template-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.btn-template {
    flex: 1;
    padding: 12px 16px;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
    text-decoration: none;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

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

.btn-secondary {
    background: white;
    color: var(--text-secondary);
    border: 1px solid #dee2e6;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.btn-secondary:hover {
    background: #f8f9fa;
    border-color: #adb5bd;
    color: var(--text-primary);
}

/* 筛选按钮优化 */
.template-filters {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-top: 20px;
    flex-wrap: wrap;
}

.filter-btn {
    padding: 10px 20px;
    border: 2px solid #dee2e6;
    background: white;
    color: var(--text-secondary);
    border-radius: 25px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
}

.filter-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    transition: left 0.3s ease;
    z-index: -1;
}

.filter-btn:hover::before,
.filter-btn.active::before {
    left: 0;
}

.filter-btn:hover,
.filter-btn.active {
    color: white;
    border-color: #667eea;
    transform: translateY(-1px);
}

/* 动画效果 */
.filtered-in {
    animation: fadeInUp 0.4s ease forwards;
}

.filtered-out {
    animation: fadeOutDown 0.3s ease forwards;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeOutDown {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(-10px);
    }
}

/* 加载状态 */
.template-card.loading {
    pointer-events: none;
}

.template-card.loading .template-content {
    opacity: 0.6;
}

.template-card.loading .template-actions::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid #667eea;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* 移动端优化 */
@media (max-width: 767px) {
    .templates-grid {
        grid-template-columns: 1fr;
        gap: var(--spacing-lg);
        padding: 0 var(--spacing-sm);
    }
    
    .template-card {
        margin: 0 auto;
        max-width: 400px;
    }
    
    .template-preview {
        height: 180px;
    }
    
    .preview-content {
        gap: 6px;
        padding: var(--spacing-md);
    }
    
    .preview-cell {
        width: 40px;
        height: 40px;
        font-size: 16px;
    }
    
    .template-content {
        padding: 20px;
    }
    
    .template-title {
        font-size: 16px;
    }
    
    .template-description {
        font-size: 13px;
    }
    
    .btn-template {
        padding: 10px 14px;
        font-size: 13px;
    }
    
    .template-filters {
        gap: 6px;
        padding: 0 var(--spacing-sm);
    }
    
    .filter-btn {
        padding: 8px 16px;
        font-size: 13px;
    }
}

/* 高对比度模式支持 */
@media (prefers-contrast: high) {
    .template-card {
        border-width: 2px;
        border-color: var(--text-primary);
    }
    
    .template-badge,
    .btn-primary {
        background: var(--text-primary);
    }
    
    .template-type,
    .feature-tag {
        border-width: 2px;
    }
}

/* 减少动画模式支持 */
@media (prefers-reduced-motion: reduce) {
    .template-card,
    .preview-cell,
    .btn-template,
    .filter-btn {
        transition: none;
    }
    
    .template-card:hover {
        transform: none;
    }
    
    .filtered-in,
    .filtered-out {
        animation: none;
    }
    
    .template-preview::after {
        display: none;
    }
} 