body {
    font-family: Arial, sans-serif;
    line-height: 1.6;
    margin: 0;
    padding: 0;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.main-container {
    display: flex;
    max-width: 1600px; /* 增加最大宽度 */
    width: 95%; /* 添加这行，使容器占据屏幕宽度的95% */
    margin: 0 auto;
    padding: 20px;
}

header {
    display: flex;
    flex-direction: column;
    align-items: center;
    background-color: #f4f4f4;
    padding: 1rem;
    text-align: center;
    position: relative;
}

#category-nav {
    width: 200px;
    position: sticky;
    top: 20px;
    align-self: flex-start;
    margin-right: 20px;
}

#category-nav ul {
    list-style-type: none;
    padding: 0;
}

#category-nav li {
    margin-bottom: 10px;
}

#category-nav a {
    text-decoration: none;
    color: #333;
}

main {
    flex: 1;
}

.links-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    grid-area: links-grid;
    gap: 40px 15px; /* 统一卡片之间的间距 */
    padding-bottom: 40px; /* 增加网格底部的间距 */
    
}

.link-card {
    background-color: #f4f4f4;
    border-radius: 5px;
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    height: 100%;
    transition: background-color 0.3s ease, transform 0.1s ease, box-shadow 0.3s ease;
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.link-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.link-card-content {
    display: flex;
    align-items: center;
    margin-bottom: 0.5rem;
}

.link-logo {
    width: 16px;
    height: 16px;
    margin-right: 10px;
}

.link-title {
    font-weight: bold;
}

.link-url {
    font-size: 0.8em;
    color: #666;
    margin: 0.25rem 0;
    word-break: break-all;
}

.link-description {
    font-size: 0.9em;
    color: #666;
    margin: 0.5rem 0;
    flex-grow: 1;
}

#dark-mode-toggle {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
}

/* Dark mode styles */
body.dark-mode {
    background-color: #1a1a1a;
    color: #f0f0f0;
}

body.dark-mode header {
    background-color: #2a2a2a;
}

body.dark-mode #category-nav a {
    color: #f0f0f0;
}

body.dark-mode .link-card {
    background-color: #2a2a2a;
}

body.dark-mode .link-card:hover {
    background-color: #3a3a3a;
}

body.dark-mode .link-url,
body.dark-mode .link-description {
    color: #aaa;
}

body.dark-mode .link-title {
    color: #f0f0f0;
}

/* Responsive design */
@media (max-width: 1600px) {
    .links-grid {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
        gap: 35px 20px; /* 保持一致的间距 */
    }
}

@media (max-width: 1200px) {
    .links-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
        gap: 35px 20px; /* 保持一致的间距 */
    }
}

@media (max-width: 900px) {
    .links-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 35px 20px; /* 保持一致的间距 */
    }
}

@media (max-width: 768px) {
    body {
        overflow-x: hidden; /* 防止水平滚动 */
    }

    .main-container {
        flex-direction: column;
        width: 100%; /* 使用全宽 */
        padding: 0; /* 移除容器的内边距 */
        box-sizing: border-box; /* 确保padding不会增加总宽度 */
    }

    #category-nav {
        width: 100vw; /* 使用视口宽度 */
        position: sticky; /* 改为 sticky */
        top: 0; /* 设置顶部距离为 0 */
        left: 0; /* 确保从左边开始 */
        margin-right: 0;
        margin-bottom: 20px;
        background-color: #f4f4f4; /* 添加背景色 */
        padding: 10px 0; /* 添加一些内边距 */
        z-index: 1000; /* 确保菜单栏在其他元素之上 */
        transition: background-color 0.3s ease; /* 平滑过渡效果 */
    }

    body.dark-mode #category-nav {
        background-color: #2a2a2a; /* 暗模式下的背景色 */
    }

    #category-nav ul {
        display: flex;
        flex-wrap: wrap;
        gap: 10px;
        justify-content: center; /* 居中显示菜单项 */
        padding: 0 15px; /* 为菜单项添加左右内边距 */
    }

    #category-nav li {
        margin-bottom: 0;
    }

    main {
        width: 100%; /* 确保主内容区域不会超出容器 */
        padding: 0 15px; /* 为主内容添加左右内边距 */
        box-sizing: border-box;
    }

    .links-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 15px; /* 增加卡片之间的间距 */
    }

    .link-card {
        padding: 0.75rem; /* 增加卡片内边距 */
        width: 100%; /* 确保卡片不会超出网格单元格 */
        box-sizing: border-box;
    }

    .link-title {
        font-size: 0.9em;
    }

    .link-url, .link-description {
        font-size: 0.8em;
    }
}

@media (max-width: 480px) {
    main {
        padding: 0 10px; /* 在更小的屏幕上稍微减少内边距 */
    }

    .links-grid {
        gap: 10px; /* 在更小的屏幕上稍微减小间距 */
    }
}

.main-nav {
    margin-bottom: 1rem;
}

.main-nav ul {
    list-style-type: none;
    padding: 0;
    display: flex;
    justify-content: center;
}

.main-nav li {
    margin: 0 10px;
}

.main-nav a {
    text-decoration: none;
    color: #333;
    font-weight: bold;
    padding: 5px 10px;
    border-radius: 5px;
    transition: background-color 0.3s ease;
}

.main-nav a:hover,
.main-nav a.active {
    background-color: #007bff;
    color: white;
}

body.dark-mode .main-nav a {
    color: #f0f0f0;
}

body.dark-mode .main-nav a:hover,
body.dark-mode .main-nav a.active {
    background-color: #0056b3;
}

/* 响应式设计 */
@media (max-width: 768px) {
    .main-nav ul {
        flex-direction: column;
        align-items: center;
    }

    .main-nav li {
        margin: 5px 0;
    }
}

.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-content {
    display: none;
    position: absolute;
    background-color: #f9f9f9;
    min-width: 200px;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
    z-index: 1;
    white-space: nowrap;
}

.dropdown:hover .dropdown-content {
    display: block;
}

.dropdown-content a {
    color: black;
    padding: 12px 16px;
    text-decoration: none;
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dropdown-content a:hover {
    background-color: #f1f1f1;
}

/* 夜间模式样式 */
body.dark-mode .dropdown-content {
    background-color: #333;
    box-shadow: 0px 8px 16px 0px rgba(255,255,255,0.1);
}

body.dark-mode .dropdown-content a {
    color: #f0f0f0;
}

body.dark-mode .dropdown-content a:hover {
    background-color: #444;
}

/* 下拉按钮的箭头样式 */
.dropbtn::after {
    content: ' ▼';
    font-size: 0.7em;
    vertical-align: middle;
}

/* 确保夜间模式下下拉按钮的颜色正确 */
body.dark-mode .dropbtn {
    color: #f0f0f0;
}

/* 确保下拉菜单在移动设备上也能正常工作 */
@media (max-width: 768px) {
    .dropdown {
        position: static;
    }
    
    .dropdown-content {
        width: 100%;
        position: static;
        box-shadow: none;
        display: none;
    }
    
    .dropdown:hover .dropdown-content,
    .dropdown:focus-within .dropdown-content {
        display: block;
    }
}