* {
  box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    margin: 0;
    background-color: #1a1a1a;
    color: #f0f0f0;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    padding-top: 130px; /* 进一步增加空间以避免内容被固定头部和导航栏遮挡 */
}

header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    background-color: #222; /* 确保背景色，防止内容透过 */
    z-index: 1000; /* 确保在其他内容之上 */
    box-shadow: 0 2px 5px rgba(0,0,0,0.1); /* 可选：添加阴影增加视觉效果 */
    padding: 15px 20px;
    display: flex;
    flex-direction: row; /* 改为横向排列 */
    justify-content: space-between; /* 标题靠左，搜索栏靠右 */
    align-items: center;
    gap: 15px;
}

.logo h1 {
    margin: 0;
    font-size: 28px;
    font-weight: bold;
    display: flex; /* 确保内部元素横向排列 */
    flex-direction: row; /* 明确设置为横向 */
    align-items: center;
    white-space: nowrap; /* 防止标题换行 */
}

.logo .highlight {
    background-color: #ff8c00;
    color: #000000;
    padding: 5px;
    border-radius: 8px;
    margin-left: 6px;
    font-size: 28px;
}

.search-container {
    width: 100%;
    max-width: 500px;
}

.search-container form {
    display: flex;
    border-radius: 25px;
    overflow: hidden;
    background-color: #333;
}

.search-input {
    flex-grow: 1;
    border: none;
    padding: 12px 20px;
    font-size: 16px;
    background-color: transparent;
    color: #f0f0f0;
    outline: none;
}

.search-input::placeholder {
    color: #bbb;
}

.search-button {
    background-color: #ff8c00;
    color: #fff;
    border: none;
    padding: 10px 25px;
    font-size: 22px;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.search-button:hover {
    background-color: #e67e00;
}

.categories {
    position: fixed;
    top: 58px; /* 紧随header固定，header高度约为58px (15px padding-top + 28px font-size + 15px padding-bottom) */
    left: 0;
    width: 100%;
    background-color: #222; /* 确保背景色 */
    z-index: 999; /* 略低于header，但仍高于页面内容 */
    box-shadow: 0 2px 5px rgba(0,0,0,0.05); /* 可选：添加阴影 */
    display: flex;
    justify-content: center;
    padding: 10px 0;
    /* border-top: 1px solid #444; */
    border-bottom: 1px solid #444;
    overflow-x: auto; /* Enable horizontal scrolling for small screens */
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    white-space: nowrap; /* Prevent wrapping of buttons */
    }
    
    .categories::-webkit-scrollbar {
        display: none;
    }

.category-button {
    background-color: transparent;
    color: #f0f0f0;
    border: none;
    padding: 10px 20px;
    font-size: 16px;
    cursor: pointer;
    transition: color 0.2s ease, border-bottom 0.2s ease;
    position: relative;
    flex-shrink: 0; /* Prevent buttons from shrinking */
    outline: none; /* 移除焦点轮廓 */
    -webkit-tap-highlight-color: transparent; /* 移除移动端点击高亮 */
}

.category-button.active {
    color: #ff8c00;
}

.category-button.active::after {
    content: '';
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    bottom: 0;
    width: 60%;
    height: 3px;
    background-color: #ff8c00;
    border-radius: 2px;
}

.category-button:hover:not(.active) {
    color: #ffaa44;
}

main {
    padding: 20px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); /* Adjusted for 4 columns */
    gap: 20px;
    max-width: 1200px;
    margin: 0 auto; /* Center the main content area */
}

.card {
    background-color: #2a2a2a;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    transition: transform 0.2s ease;
}

.card:hover {
    transform: translateY(-5px);
}

.card-image-container {
    width: 100%;
    height: 200px; /* Fixed height for images */
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #333; /* Placeholder background */
}

.card-image {
    width: 100%;
    height: 100%;
    object-fit: cover; /* Cover the container while maintaining aspect ratio */
    object-position: top; /* 从上方开始显示 */
    display: block;
}

img, video {
  max-width: 100%;
  height: auto; /* 保持图片的原始宽高比 */
}

.card-content {
    padding: 15px;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}

.card-title {
    font-size: 20px;
    margin-top: 0;
    margin-bottom: 0px;
    color: #ff8c00;
    word-break: break-word; /* 强制换行 */
    overflow-wrap: break-word; /* 兼容性写法 */
}

.card-description {
    font-size: 13px;
    color: #bbb;
    line-height: 1.5;
    margin-top:3px;
    margin-bottom: 10px;
    flex-grow: 1;
    word-break: break-word; /* 强制换行 */
    overflow-wrap: break-word; /* 兼容性写法 */
}

.card-button {
    display: block;
    width: 100%;
    padding: 12px;
    background-color: #ff8c00;
    color: #fff;
    text-align: center;
    text-decoration: none;
    border-radius: 5px;
    font-size: 16px;
    transition: background-color 0.2s ease;
    box-sizing: border-box; /* Include padding in width */
}

.card-button:hover {
    background-color: #e67e00;
}

/* 移动端适配 */
@media (max-width: 768px) {
    body {
        padding-left: 25px; /* 示例值，可根据需求调整 */
        padding-right: 25px; /* 示例值，可根据需求调整 */
        padding-top: 100px; /* 移动端再次增加空间以避免内容被固定头部和导航栏遮挡 */
    }

    header {
        padding: 10px 15px;
        flex-direction: row; /* 移动端改为横向排列 */
        justify-content: space-between; /* 标题靠左，搜索栏靠右 */
        align-items: center;
        gap: 10px; /* 增加间距 */
    }

    .search-container {
        flex-grow: 1; /* 搜索框自适应宽度 */
        box-sizing: border-box; /* 确保 padding 不会增加总宽度 */
        max-width: 60%; /* 调整搜索框最大宽度，给按钮留出空间 */
    }

    .search-container form {
        justify-content: flex-end; /* 确保搜索框和按钮靠右对齐 */
    }

    .logo h1 {
        font-size: 22px; /* 保持原字体大小 */
        white-space: nowrap; /* 防止标题换行 */
        flex-grow: 1; /* 确保标题占据剩余空间 */
        overflow: hidden; /* 隐藏溢出内容 */
        text-overflow: ellipsis; /* 显示省略号 */
    }

    .logo .highlight {
        font-size: 22px;
        padding: 2px;
        border-radius: 4px;
    }

    .search-input {
        padding: 18px 13px;
        font-size: 16px;
        width: 100%; /* 搜索框自适应宽度 */
        max-width: 300px; /* 限制最大宽度 */
    }
    .search-button {
        padding: 18px 13px; /* 保持与输入框相同的垂直填充 */
        font-size: 16px;
        flex-shrink: 0; /* 防止按钮缩小 */
    }

    .categories {
        position: fixed; /* 确保在移动端也固定 */
        top: 42px; /* 移动端紧随header固定，header高度约为42px */
        justify-content: flex-start; /* 确保在移动端从左侧开始显示 */
        padding: 8px 10px;
        border-top: 6px solid #444;
        border-bottom: 1px solid #444;
        scrollbar-width: none; /* Firefox */
        -ms-overflow-style: none;  /* IE and Edge */
    }

    .category-button {
        padding: 8px 9px;
        font-size: 14px;
    }

    main {
        padding: 10px; /* 减少左右边距 */
        grid-template-columns: 1fr; /* Single column for mobile */
        gap: 15px;
    }

    .card-title {
        font-size: 18px;
    }

    .card-description {
        font-size: 13px;
    }

    .card-button {
        padding: 10px;
        font-size: 14px;
    }
}

@media (max-width: 480px) {
    .search-container form {
        border-radius: 20px;
    }
    .search-input {
        padding: 8px 15px;
    }
    .search-button {
        padding: 8px 15px;
    }
}

.footer {
    text-align: center;
    margin-top: 50px;
    margin-bottom: 50px;
    color: #888888; /* 灰色页脚文字 */
    font-size: 0.8em;
}

#show-log-alert {
    color: #006bde; /* 蓝色 */
}

.card-favicon {
    height: 1em; /* 调整图标大小 */
    vertical-align: middle; /* 垂直居中对齐 */
    margin-right: 5px; /* 与标题文字的间距 */
}
