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

:root {
    --primary-color: #2c3e50;
    --secondary-color: #3498db;
    --accent-color: #e74c3c;
    --light-bg: #ecf0f1;
    --dark-text: #2c3e50;
    --light-text: #7f8c8d;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: var(--dark-text);
    background-color: #fff;
}

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

/* 导航栏样式 */
.navbar {
    background-color: var(--primary-color);
    color: white;
    position: fixed;
    width: 100%;
    top: 0;
    z-index: 1000;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.navbar .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
}

.logo {
    font-size: 1.5rem;
    font-weight: bold;
    color: white;
}

.nav-links {
    display: flex;
    list-style: none;
    gap: 30px;
}

.nav-links a {
    color: white;
    text-decoration: none;
    transition: color 0.3s ease;
}

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

/* Hero区域样式 */
.hero {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    padding: 150px 0 100px;
    text-align: center;
}

.hero h1 {
    font-size: 3rem;
    margin-bottom: 20px;
    animation: fadeInDown 0.8s ease;
}

.hero p {
    font-size: 1.2rem;
    margin-bottom: 30px;
    opacity: 0.9;
    animation: fadeInUp 0.8s ease;
}

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

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

/* 按钮样式 */
.btn {
    display: inline-block;
    padding: 12px 30px;
    border-radius: 5px;
    text-decoration: none;
    font-weight: bold;
    transition: all 0.3s ease;
    cursor: pointer;
    border: none;
}

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

.btn-primary:hover {
    background-color: #c0392b;
    transform: translateY(-2px);
}

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

.btn-secondary:hover {
    background-color: #2980b9;
    transform: translateY(-2px);
}

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

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

/* 算法分类区域 */
.algorithms-section,
.practice-section,
.resources-section {
    padding: 80px 0;
}

.algorithms-section {
    background-color: var(--light-bg);
}

.algorithms-section h2,
.practice-section h2,
.resources-section h2 {
    text-align: center;
    font-size: 2.5rem;
    margin-bottom: 50px;
    color: var(--primary-color);
}

.algorithm-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 30px;
}

.algorithm-card {
    background: white;
    padding: 30px;
    border-radius: 10px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.1);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.algorithm-card:hover {
    transform: translateY(-10px);
    box-shadow: 0 10px 30px rgba(0,0,0,0.15);
}

.algorithm-card h3 {
    color: var(--primary-color);
    margin-bottom: 15px;
    font-size: 1.5rem;
}

.algorithm-card p {
    color: var(--light-text);
    margin-bottom: 20px;
}

/* 练习平台区域 */
.practice-platforms {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 30px;
}

.platform-card {
    text-align: center;
    padding: 40px 30px;
    border: 2px solid #eee;
    border-radius: 10px;
    transition: border-color 0.3s ease;
}

.platform-card:hover {
    border-color: var(--secondary-color);
}

.platform-card h3 {
    color: var(--primary-color);
    margin-bottom: 15px;
}

.platform-card p {
    color: var(--light-text);
    margin-bottom: 20px;
}

/* 资源区域 */
.resources-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 30px;
}

.resource-item {
    background: var(--light-bg);
    padding: 30px;
    border-radius: 10px;
}

.resource-item h3 {
    color: var(--primary-color);
    margin-bottom: 20px;
}

.resource-item ul {
    list-style: none;
}

.resource-item li {
    padding: 10px 0;
    border-bottom: 1px solid #ddd;
    color: var(--dark-text);
}

.resource-item li:last-child {
    border-bottom: none;
}

/* 页脚 */
.footer {
    background-color: var(--primary-color);
    color: white;
    text-align: center;
    padding: 30px 0;
}

/* 响应式设计 */
@media (max-width: 768px) {
    .navbar .container {
        flex-direction: column;
        gap: 15px;
    }

    .nav-links {
        gap: 15px;
    }

    .hero h1 {
        font-size: 2rem;
    }

    .algorithm-grid,
    .practice-platforms,
    .resources-grid {
        grid-template-columns: 1fr;
    }
}

/* 算法详情页样式 */
.algorithm-detail {
    padding: 100px 0 50px;
}

.algorithm-detail h2 {
    color: var(--primary-color);
    margin-bottom: 30px;
}

.algorithm-detail h3 {
    color: var(--secondary-color);
    margin: 30px 0 15px;
}

.algorithm-content {
    background: var(--light-bg);
    padding: 30px;
    border-radius: 10px;
    margin: 20px 0;
}

.code-block {
    background: #0d1117;
    color: #c9d1d9;
    padding: 20px;
    border-radius: 6px;
    overflow-x: auto;
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
    font-size: 14px;
    line-height: 1.6;
    margin: 15px 0;
    border: 1px solid #30363d;
}

.code-block pre {
    margin: 0;
}

.code-block pre code {
    background: transparent;
    padding: 0;
    font-family: inherit;
    font-size: inherit;
}

/* 行号样式 */
.line-numbers .code-block pre {
    position: relative;
    padding-left: 3.5em;
    counter-reset: linenumber;
}

.line-numbers .code-block pre code {
    position: relative;
    white-space: inherit;
}

.line-numbers .code-block pre code::before {
    content: counter(linenumber);
    color: #484f58;
    display: inline-block;
    padding-right: 0.5em;
    padding-left: 0;
    width: 2.5em;
    text-align: right;
    position: absolute;
    left: 0;
    top: 0;
}

.line-numbers .code-block pre code::before,
.line-numbers .code-block pre code::after {
    content: normal;
}

/* 多语言代码标签页样式 */
.code-tabs {
    margin: 20px 0;
}

.code-tab-header {
    display: flex;
    gap: 0;
    margin-bottom: 0;
    border-bottom: 1px solid #30363d;
    align-items: center;
}

.code-tab-btn {
    padding: 10px 20px;
    border: none;
    background: #21262d;
    color: #8b949e;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    border: 1px solid #30363d;
    border-bottom: none;
    margin-left: -1px;
    transition: all 0.2s ease;
}

.code-tab-btn:first-child {
    margin-left: 0;
    border-radius: 6px 0 0 0;
}

.code-tab-btn:last-child {
    border-radius: 0 6px 0 0;
}

.code-tab-btn:hover {
    background: #30363d;
    color: #c9d1d9;
}

.code-tab-btn.active {
    background: #0d1117;
    color: #58a6ff;
    border-bottom: 2px solid #0d1117;
}

/* 代码块折叠按钮 */
.code-fold-btn {
    margin-left: auto;
    padding: 6px 12px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: #8b949e;
    cursor: pointer;
    font-size: 12px;
    border-radius: 4px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 4px;
}

.code-fold-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: #c9d1d9;
}

.code-fold-btn .fold-icon {
    transition: transform 0.2s ease;
}

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

.code-tab-content {
    display: none;
    background: #0d1117;
    border: 1px solid #30363d;
    border-top: none;
    border-radius: 0 6px 6px 6px;
    padding: 20px;
}

.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, #0d1117);
}

.code-tab-content .code-block {
    margin: 0;
    background: transparent;
    border: none;
    border-radius: 0;
    padding: 0;
}

/* 独立代码块包装器 */
.code-block-wrapper {
    position: relative;
    margin: 20px 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, #0d1117);
    pointer-events: none;
}

.code-tab-content .line-numbers .code-block pre {
    padding-left: 3.5em;
}

.complexity {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin: 20px 0;
}

.complexity-item {
    background: white;
    padding: 20px;
    border-radius: 5px;
    text-align: center;
}

.complexity-item h4 {
    color: var(--primary-color);
    margin-bottom: 10px;
}

.back-link {
    display: inline-block;
    margin-bottom: 30px;
    color: var(--secondary-color);
    text-decoration: none;
}

.back-link:hover {
    text-decoration: underline;
}

/* 左侧导航栏样式 */
.sidebar {
    position: fixed;
    left: 0;
    top: 60px;
    width: 260px;
    height: calc(100vh - 60px);
    background: #f8f9fa;
    padding: 20px;
    overflow-y: auto;
    border-right: 1px solid #e0e0e0;
    z-index: 100;
}

.sidebar h2 {
    font-size: 1.2rem;
    color: var(--primary-color);
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--secondary-color);
}

.sidebar ul {
    list-style: none;
    padding: 0;
}

.sidebar li {
    margin: 5px 0;
}

.sidebar > ul > li > a {
    display: block;
    padding: 10px 15px;
    color: var(--dark-text);
    text-decoration: none;
    border-radius: 5px;
    transition: all 0.2s ease;
    font-weight: 500;
}

.sidebar > ul > li > a:hover {
    background: var(--secondary-color);
    color: white;
}

.sidebar > ul > li > ul {
    margin-left: 15px;
    margin-top: 5px;
}

.sidebar > ul > li > ul > li > a {
    display: block;
    padding: 8px 15px;
    color: var(--light-text);
    text-decoration: none;
    border-radius: 5px;
    font-size: 0.9rem;
    transition: all 0.2s ease;
}

.sidebar > ul > li > ul > li > a:hover {
    background: #e8f4fc;
    color: var(--secondary-color);
}

/* 主内容区右侧偏移 */
.content {
    margin-left: 260px;
    padding: 100px 40px 40px;
    max-width: calc(100% - 260px);
}

.content h1 {
    color: var(--primary-color);
    font-size: 2rem;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 2px solid var(--secondary-color);
}

.content section {
    margin-bottom: 50px;
    padding-bottom: 30px;
    border-bottom: 1px solid #eee;
}

.content section:last-child {
    border-bottom: none;
}

.content h2 {
    color: var(--primary-color);
    font-size: 1.5rem;
    margin: 30px 0 20px;
}

.content h3 {
    color: var(--secondary-color);
    font-size: 1.2rem;
    margin: 25px 0 15px;
}

.content h4 {
    color: var(--dark-text);
    font-size: 1.1rem;
    margin: 20px 0 10px;
}

/* 公式样式 */
.formula {
    background: #f5f5f5;
    padding: 20px;
    border-radius: 8px;
    margin: 15px 0;
    font-family: 'Times New Roman', serif;
    font-size: 1.1rem;
    text-align: center;
    border-left: 4px solid var(--secondary-color);
}

/* 表格样式 */
.comparison-table {
    width: 100%;
    border-collapse: collapse;
    margin: 20px 0;
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.comparison-table th,
.comparison-table td {
    padding: 15px;
    text-align: left;
    border-bottom: 1px solid #eee;
}

.comparison-table th {
    background: var(--primary-color);
    color: white;
    font-weight: 600;
}

.comparison-table tr:hover {
    background: #f8f9fa;
}

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

/* 代码块样式 */
.code-header {
    background: #21262d;
    color: #8b949e;
    padding: 8px 15px;
    font-size: 12px;
    font-weight: 500;
    border-bottom: 1px solid #30363d;
    border-radius: 6px 6px 0 0;
}

.code-block {
    background: #0d1117;
    color: #c9d1d9;
    padding: 0;
    border-radius: 6px;
    overflow-x: auto;
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
    font-size: 13px;
    line-height: 1.6;
    margin: 15px 0;
    border: 1px solid #30363d;
}

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

.code-block pre code {
    background: transparent;
    padding: 0;
    font-family: inherit;
    font-size: inherit;
}

/* 响应式设计 */
@media (max-width: 1024px) {
    .sidebar {
        width: 220px;
    }
    
    .content {
        margin-left: 220px;
        max-width: calc(100% - 220px);
    }
}

@media (max-width: 768px) {
    .sidebar {
        display: none;
    }
    
    .content {
        margin-left: 0;
        max-width: 100%;
        padding: 80px 20px 20px;
    }
}
