/* ===================================
   2026 现代化算法教程网站样式
   =================================== */

/* CSS 变量定义 */
:root {
    /* 主色调 - 现代科技蓝紫渐变 */
    --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --primary-color: #667eea;
    --primary-dark: #5a67d8;
    --secondary-color: #764ba2;
    --accent-color: #f093fb;
    
    /* 功能色 */
    --success-color: #48bb78;
    --warning-color: #ed8936;
    --error-color: #f56565;
    --info-color: #4299e1;
    
    /* 中性色 */
    --bg-primary: #ffffff;
    --bg-secondary: #f7fafc;
    --bg-tertiary: #edf2f7;
    --text-primary: #1a202c;
    --text-secondary: #4a5568;
    --text-muted: #718096;
    --border-color: #e2e8f0;
    
    /* 代码主题色 */
    --code-bg: #1a202c;
    --code-text: #e2e8f0;
    
    /* 尺寸 */
    --sidebar-width: 280px;
    --header-height: 70px;
    --border-radius: 12px;
    --border-radius-lg: 20px;
    
    /* 阴影 */
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.15);
    --shadow-xl: 0 20px 40px rgba(0,0,0,0.2);
    
    /* 过渡 */
    --transition-fast: 0.15s ease;
    --transition-base: 0.3s ease;
    --transition-slow: 0.5s ease;
}

/* 暗色主题 */
[data-theme="dark"] {
    --bg-primary: #1a202c;
    --bg-secondary: #2d3748;
    --bg-tertiary: #4a5568;
    --text-primary: #f7fafc;
    --text-secondary: #e2e8f0;
    --text-muted: #a0aec0;
    --border-color: #4a5568;
}

/* 基础重置 */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    font-size: 16px;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    line-height: 1.7;
    color: var(--text-primary);
    background-color: var(--bg-secondary);
    overflow-x: hidden;
}

/* 容器 */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 24px;
}

.container-narrow {
    max-width: 900px;
}

/* ===================================
   导航栏
   =================================== */
.navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    box-shadow: var(--shadow-sm);
    z-index: 1000;
    transition: all var(--transition-base);
}

[data-theme="dark"] .navbar {
    background: rgba(26, 32, 44, 0.95);
}

.navbar.scrolled {
    box-shadow: var(--shadow-md);
}

.navbar .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 100%;
}

.logo {
    font-size: 1.5rem;
    font-weight: 800;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-decoration: none;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 32px;
    list-style: none;
}

.nav-links a {
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 500;
    transition: color var(--transition-fast);
    position: relative;
}

.nav-links a::after {
    content: '';
    position: absolute;
    bottom: -5px;
    left: 0;
    width: 0;
    height: 2px;
    background: var(--primary-gradient);
    transition: width var(--transition-base);
}

.nav-links a:hover {
    color: var(--primary-color);
}

.nav-links a:hover::after {
    width: 100%;
}

/* 主题切换按钮 */
.theme-toggle {
    background: var(--bg-tertiary);
    border: none;
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.2rem;
    transition: all var(--transition-fast);
}

.theme-toggle:hover {
    transform: scale(1.1);
}

/* ===================================
   Hero 区域
   =================================== */
.hero {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-gradient);
    position: relative;
    overflow: hidden;
    padding: var(--header-height) 0 80px;
}

.hero::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.05'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

.hero-content {
    text-align: center;
    color: white;
    position: relative;
    z-index: 1;
    max-width: 900px;
    padding: 0 24px;
}

.hero h1 {
    font-size: clamp(2.5rem, 6vw, 4.5rem);
    font-weight: 800;
    margin-bottom: 24px;
    line-height: 1.1;
    animation: fadeInUp 0.8s ease;
}

.hero p {
    font-size: clamp(1.1rem, 2vw, 1.3rem);
    opacity: 0.95;
    margin-bottom: 40px;
    animation: fadeInUp 0.8s ease 0.2s backwards;
}

.hero-buttons {
    display: flex;
    gap: 16px;
    justify-content: center;
    flex-wrap: wrap;
    animation: fadeInUp 0.8s ease 0.4s backwards;
}

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

/* ===================================
   按钮样式
   =================================== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 14px 28px;
    border-radius: var(--border-radius);
    font-weight: 600;
    font-size: 1rem;
    text-decoration: none;
    border: none;
    cursor: pointer;
    transition: all var(--transition-base);
}

.btn-primary {
    background: white;
    color: var(--primary-color);
}

.btn-primary:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.5);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-3px);
}

.btn-gradient {
    background: var(--primary-gradient);
    color: white;
}

.btn-gradient:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
}

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

.btn-outline:hover {
    background: var(--primary-color);
    color: white;
}

/* ===================================
   算法分类区域
   =================================== */
.algorithms-section {
    padding: 100px 0;
    background: var(--bg-primary);
}

.section-header {
    text-align: center;
    margin-bottom: 60px;
}

.section-header h2 {
    font-size: clamp(2rem, 4vw, 3rem);
    font-weight: 800;
    color: var(--text-primary);
    margin-bottom: 16px;
}

.section-header p {
    font-size: 1.1rem;
    color: var(--text-muted);
    max-width: 600px;
    margin: 0 auto;
}

/* 算法卡片网格 */
.algorithm-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 32px;
}

.algorithm-card {
    background: var(--bg-primary);
    border-radius: var(--border-radius-lg);
    padding: 32px;
    box-shadow: var(--shadow-md);
    transition: all var(--transition-base);
    border: 1px solid var(--border-color);
    position: relative;
    overflow: hidden;
}

.algorithm-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: var(--primary-gradient);
    transform: scaleX(0);
    transition: transform var(--transition-base);
}

.algorithm-card:hover {
    transform: translateY(-8px);
    box-shadow: var(--shadow-xl);
}

.algorithm-card:hover::before {
    transform: scaleX(1);
}

.algorithm-card-icon {
    width: 60px;
    height: 60px;
    border-radius: var(--border-radius);
    background: var(--primary-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    margin-bottom: 20px;
}

.algorithm-card h3 {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 12px;
}

.algorithm-card p {
    color: var(--text-secondary);
    margin-bottom: 24px;
    line-height: 1.6;
}

.algorithm-card-tags {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.tag {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.tag-beginner { background: #c6f6d5; color: #276749; }
.tag-intermediate { background: #feebc8; color: #c05621; }
.tag-advanced { background: #fed7d7; color: #c53030; }

.algorithm-card-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 600;
    transition: gap var(--transition-fast);
}

.algorithm-card-link:hover {
    gap: 12px;
}

/* ===================================
   知识图谱区域
   =================================== */
.knowledge-map {
    padding: 100px 0;
    background: var(--bg-secondary);
}

.knowledge-map-container {
    background: var(--bg-primary);
    border-radius: var(--border-radius-lg);
    padding: 40px;
    box-shadow: var(--shadow-lg);
    overflow-x: auto;
}

/* ===================================
   算法详情页
   =================================== */
.algorithm-detail {
    padding: calc(var(--header-height) + 60px) 0 80px;
    min-height: 100vh;
}

.breadcrumb {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 32px;
    font-size: 0.9rem;
}

.breadcrumb a {
    color: var(--text-muted);
    text-decoration: none;
    transition: color var(--transition-fast);
}

.breadcrumb a:hover {
    color: var(--primary-color);
}

.breadcrumb-separator {
    color: var(--text-muted);
}

.page-title {
    font-size: clamp(2rem, 4vw, 3rem);
    font-weight: 800;
    color: var(--text-primary);
    margin-bottom: 16px;
}

.page-description {
    font-size: 1.2rem;
    color: var(--text-muted);
    margin-bottom: 40px;
}

/* 内容区域布局 */
.detail-layout {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    gap: 40px;
}

/* 侧边目录 */
.toc-sidebar {
    position: sticky;
    top: calc(var(--header-height) + 32px);
    height: fit-content;
    background: var(--bg-primary);
    border-radius: var(--border-radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
}

.toc-sidebar h3 {
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 16px;
}

.toc-list {
    list-style: none;
}

.toc-list li {
    margin-bottom: 8px;
}

.toc-list a {
    display: block;
    padding: 10px 14px;
    border-radius: 8px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    transition: all var(--transition-fast);
}

.toc-list a:hover {
    background: var(--bg-tertiary);
    color: var(--primary-color);
}

.toc-list a.active {
    background: var(--primary-gradient);
    color: white;
}

/* 主内容区 */
.main-content {
    background: var(--bg-primary);
    border-radius: var(--border-radius-lg);
    padding: 48px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
}

.main-content h2 {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 48px 0 24px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--border-color);
}

.main-content h3 {
    font-size: 1.4rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 36px 0 20px;
}

.main-content h4 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin: 28px 0 16px;
}

.main-content p {
    color: var(--text-secondary);
    margin-bottom: 20px;
    line-height: 1.8;
}

.main-content ul,
.main-content ol {
    color: var(--text-secondary);
    margin-bottom: 20px;
    padding-left: 24px;
    line-height: 1.8;
}

.main-content li {
    margin-bottom: 8px;
}

/* ===================================
   图表容器
   =================================== */
.diagram-container {
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    padding: 32px;
    margin: 32px 0;
    overflow-x: auto;
}

.mermaid {
    display: flex;
    justify-content: center;
    padding: 20px;
}

/* 交互图表容器 */
.interactive-diagram {
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    padding: 32px;
    margin: 32px 0;
    border: 1px solid var(--border-color);
}

.interactive-controls {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 24px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--border-color);
}

.diagram-canvas {
    background: var(--bg-primary);
    border-radius: var(--border-radius);
    padding: 24px;
    min-height: 400px;
    position: relative;
}

/* ===================================
   表格样式
   =================================== */
.comparison-table {
    width: 100%;
    border-collapse: collapse;
    margin: 32px 0;
    background: var(--bg-primary);
    border-radius: var(--border-radius);
    overflow: hidden;
    box-shadow: var(--shadow-md);
}

.comparison-table th,
.comparison-table td {
    padding: 16px 20px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.comparison-table th {
    background: var(--primary-gradient);
    color: white;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.8rem;
    letter-spacing: 0.05em;
}

.comparison-table tr:hover {
    background: var(--bg-secondary);
}

.comparison-table tr:last-child td {
    border-bottom: none;
}

/* 复杂度表格 */
.complexity-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 20px;
    margin: 32px 0;
}

.complexity-item {
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    padding: 24px;
    text-align: center;
    border: 1px solid var(--border-color);
    transition: all var(--transition-base);
}

.complexity-item:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary-color);
}

.complexity-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 8px;
}

.complexity-value {
    font-size: 1.5rem;
    font-weight: 700;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* ===================================
   代码块样式
   =================================== */
.code-tabs {
    margin: 32px 0;
    border-radius: var(--border-radius);
    overflow: hidden;
    box-shadow: var(--shadow-lg);
}

.code-tab-header {
    display: flex;
    background: var(--code-bg);
    border-bottom: 1px solid #4a5568;
    align-items: center;
}

.code-tab-btn {
    padding: 12px 24px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    font-weight: 500;
    font-size: 0.9rem;
    transition: all var(--transition-fast);
    border-bottom: 2px solid transparent;
}

.code-tab-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.code-tab-btn.active {
    color: var(--accent-color);
    border-bottom-color: var(--accent-color);
}

/* 代码块折叠按钮 */
.code-fold-btn {
    margin-left: auto;
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.85rem;
    border-radius: 6px;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    gap: 6px;
}

.code-fold-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: var(--text-primary);
}

.code-fold-btn .fold-icon {
    transition: transform var(--transition-fast);
}

.code-fold-btn.collapsed .fold-icon {
    transform: rotate(-90deg);
}

.code-tab-content {
    display: none;
    background: var(--code-bg);
}

.code-tab-content.active {
    display: block;
}

.code-tab-content.collapsed .code-block {
    max-height: 50px;
    overflow: hidden;
    position: relative;
}

.code-tab-content.collapsed .code-block::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 30px;
    background: linear-gradient(to bottom, transparent, var(--code-bg));
}

.code-block {
    background: var(--code-bg);
    color: var(--code-text);
    overflow-x: auto;
    font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 0.9rem;
    line-height: 1.6;
    transition: max-height 0.3s ease;
}

.code-block pre {
    margin: 0;
    padding: 24px;
}

.code-block code {
    background: transparent;
    padding: 0;
}

/* 独立代码块包装器 */
.code-block-wrapper {
    position: relative;
    margin: 32px 0;
}

.code-block-wrapper.collapsed .code-block {
    max-height: 50px;
    overflow: hidden;
    position: relative;
}

.code-block-wrapper.collapsed .code-block::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 30px;
    background: linear-gradient(to bottom, transparent, var(--code-bg));
    pointer-events: none;
}

/* ===================================
   信息卡片
   =================================== */
.info-card {
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    padding: 24px;
    margin: 32px 0;
    border-left: 4px solid var(--info-color);
}

.info-card.warning {
    border-left-color: var(--warning-color);
    background: rgba(237, 137, 54, 0.1);
}

.info-card.success {
    border-left-color: var(--success-color);
    background: rgba(72, 187, 120, 0.1);
}

.info-card.error {
    border-left-color: var(--error-color);
    background: rgba(245, 101, 101, 0.1);
}

.info-card-title {
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.info-card-content {
    color: var(--text-secondary);
    line-height: 1.7;
}

/* ===================================
   公式样式
   =================================== */
.formula {
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    padding: 24px 32px;
    margin: 32px 0;
    text-align: center;
    font-family: 'Times New Roman', serif;
    font-size: 1.2rem;
    border: 1px solid var(--border-color);
    overflow-x: auto;
}

/* ===================================
   动画演示区域
   =================================== */
.animation-container {
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    padding: 32px;
    margin: 32px 0;
    text-align: center;
}

.animation-canvas {
    background: var(--bg-primary);
    border-radius: var(--border-radius);
    padding: 24px;
    min-height: 300px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 20px;
}

/* ===================================
   时间线样式
   =================================== */
.timeline {
    position: relative;
    padding: 20px 0;
    margin: 32px 0;
}

.timeline::before {
    content: '';
    position: absolute;
    left: 30px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--border-color);
}

.timeline-item {
    position: relative;
    padding-left: 80px;
    margin-bottom: 32px;
}

.timeline-marker {
    position: absolute;
    left: 0;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--primary-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    box-shadow: var(--shadow-md);
}

.timeline-content {
    background: var(--bg-primary);
    border-radius: var(--border-radius);
    padding: 24px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

.timeline-title {
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.timeline-description {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

/* ===================================
   页脚
   =================================== */
.footer {
    background: var(--text-primary);
    color: var(--text-muted);
    padding: 60px 0 30px;
    margin-top: 100px;
}

.footer-content {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 40px;
    margin-bottom: 40px;
}

.footer-section h4 {
    color: white;
    font-weight: 600;
    margin-bottom: 16px;
}

.footer-section ul {
    list-style: none;
}

.footer-section a {
    color: var(--text-muted);
    text-decoration: none;
    transition: color var(--transition-fast);
}

.footer-section a:hover {
    color: white;
}

.footer-bottom {
    text-align: center;
    padding-top: 30px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

/* ===================================
   响应式设计
   =================================== */
@media (max-width: 1024px) {
    .detail-layout {
        grid-template-columns: 1fr;
    }
    
    .toc-sidebar {
        position: relative;
        top: 0;
        margin-bottom: 32px;
    }
}

@media (max-width: 768px) {
    .nav-links {
        gap: 16px;
    }
    
    .algorithm-grid {
        grid-template-columns: 1fr;
    }
    
    .main-content {
        padding: 32px 24px;
    }
    
    .timeline-item {
        padding-left: 70px;
    }
    
    .timeline-marker {
        width: 50px;
        height: 50px;
        font-size: 0.9rem;
    }
}

/* ===================================
   工具类
   =================================== */
.text-center { text-align: center; }
.text-gradient { 
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mt-4 { margin-top: 32px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.mb-4 { margin-bottom: 32px; }
