/* MacSur Docs - GitHub 风格优化 */

:root {
    /* GitHub 风格主题色 */
    --theme-color: #0969da;
    --theme-hover: #0550ae;
    --theme-light: #ddf4ff;
    --border-color: #d0d7de;
    --bg-canvas: #ffffff;
    --bg-subtle: #f6f8fa;
    --text-primary: #24292f;
    --text-secondary: #57606a;
    --code-bg: #f6f8fa;
    --sidebar-width: 300px;
}

/* 暗黑模式适配 */
@media (prefers-color-scheme: dark) {
    :root {
        --theme-color: #58a6ff;
        --theme-hover: #79c0ff;
        --theme-light: rgba(88, 166, 255, 0.15);
        --border-color: #30363d;
        --bg-canvas: #0d1117;
        --bg-subtle: #161b22;
        --text-primary: #c9d1d9;
        --text-secondary: #8b949e;
        --code-bg: #161b22;
        /* 侧边栏在 GitHub 暗黑模式下也是浅灰，不是纯黑 */
        --sidebar-bg: #0d1117;
    }

    /* 侧边栏在暗黑模式下保持清晰 */
    .sidebar {
        background: var(--sidebar-bg);
        border-right-color: var(--border-color);
    }

    .sidebar a:hover {
        background: var(--bg-subtle);
    }

    .sidebar a.active {
        background: var(--theme-light);
        color: var(--theme-color);
    }
}

/* 全局字体 - 等宽风格 */
html {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji";
    font-size: 16px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* 代码和等宽元素 */
code, pre, kbd, samp, .code-block {
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
    font-size: 0.9em;
}

/* 侧边栏优化 */
.sidebar {
    background: var(--bg-canvas);
    border-right: 1px solid var(--border-color);
    color: var(--text-primary);
    width: var(--sidebar-width);
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 2rem 0;
    z-index: 100;
    transition: transform 0.3s ease;
    /* 确保文字清晰 */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.sidebar::-webkit-scrollbar {
    width: 8px;
}

.sidebar::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* 侧边栏链接 */
.sidebar a {
    color: var(--text-secondary);
    display: block;
    padding: 0.4em 1.5em;
    margin: 0.2em 0;
    text-decoration: none;
    border-left: 3px solid transparent;
    transition: all 0.15s ease;
    font-size: 0.95rem;
    font-weight: 500;
}

.sidebar a:hover {
    background: var(--bg-subtle);
    border-left-color: var(--theme-color);
    color: var(--text-primary);
}

.sidebar a.active {
    background: var(--theme-light);
    border-left-color: var(--theme-color);
    color: var(--theme-color);
    font-weight: 600;
}

/* 侧边栏标题 */
.sidebar > h1,
.sidebar > h2,
.sidebar > h3 {
    padding: 0.8em 1.5em 0.3em;
    margin: 1em 0 0.2em;
    color: var(--text-primary);
    font-weight: 600;
    border-bottom: 1px solid var(--border-color);
}

/* 移动端侧边栏 */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        width: 80%;
        max-width: 280px;
        box-shadow: 2px 0 8px rgba(0,0,0,0.15);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    /* 折叠屏竖屏模式（外屏） */
    @media (max-width: 768px) {
        .sidebar {
            width: 75%;
            max-width: 240px;
        }

        .page {
            padding: 0.8rem !important;
        }

        .markdown-section h1 {
            font-size: 1.6em !important;
        }

        .markdown-section h2 {
            font-size: 1.3em !important;
        }
    }

    /* 遮罩层 */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: 99;
    }

    .sidebar-overlay.active {
        display: block;
    }

    /* 移动端内容区域 */
    .page {
        padding: 1rem !important;
        margin-top: 3rem !important;
        margin-left: 0 !important; /* 移除左边距，侧边栏为抽屉式 */
    }

    /* 表格横向滚动优化 */
    .markdown-section table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .markdown-section th,
    .markdown-section td {
        padding: 0.8em 1em;
        font-size: 0.9em;
    }

    .markdown-section th:first-child,
    .markdown-section td:first-child {
        min-width: 250px;
        width: auto;
    }

    .markdown-section th:nth-child(2),
    .markdown-section td:nth-child(2),
    .markdown-section th:nth-child(3),
    .markdown-section td:nth-child(3),
    .markdown-section th:nth-child(4),
    .markdown-section td:nth-child(4) {
        width: 80px;
        min-width: 70px;
        font-size: 0.85em;
        padding: 0.7em 0.5em;
    }
}

/* 中等屏幕（折叠屏展开、小平板）768px - 1024px */
@media (min-width: 769px) and (max-width: 1024px) {
    /* 侧边栏调整 */
    .sidebar {
        width: 260px;
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
    }

    .page {
        margin-left: 260px;
        padding: 2rem 1.5rem;
        max-width: none;
    }

    /* 表格优化 - 中等屏幕给更多宽度给标题列 */
    .markdown-section table {
        table-layout: auto;
    }

    .markdown-section th:first-child,
    .markdown-section td:first-child {
        min-width: 320px; /* 比手机宽，比桌面窄 */
        width: auto;
        padding: 1em 1.5em;
    }

    .markdown-section th:nth-child(2),
    .markdown-section td:nth-child(2),
    .markdown-section th:nth-child(3),
    .markdown-section td:nth-child(3),
    .markdown-section th:nth-child(4),
    .markdown-section td:nth-child(4) {
        width: 90px; /* 稍宽一点 */
        min-width: 80px;
        padding: 0.8em 0.6em;
        font-size: 0.95em;
    }

    /* 字体微调 */
    html {
        font-size: 16px;
    }

    .markdown-section {
        font-size: 0.95rem;
        line-height: 1.7;
    }

    /* 轮播图调整 */
    .carousel-container {
        max-width: 100%;
    }

    /* 按钮大小优化 */
    .carousel-control {
        width: 40px;
        height: 40px;
        font-size: 1.3em;
    }

    .menu-button {
        top: 1rem;
        left: 1rem;
        padding: 0.6rem;
    }
}

/* 主内容区域 */
.page {
    background: var(--bg-canvas);
    color: var(--text-primary);
    max-width: 1100px;
    margin: 0 auto 0 var(--sidebar-width); /* 左边距等于侧边栏宽度 */
    padding: 2rem 3rem;
    min-height: 100vh;
}

@media (max-width: 768px) {
    .page {
        padding: 1rem;
        margin-left: 0 !important;
    }
}

/* 标题优化 */
.markdown-section h1,
.markdown-section h2,
.markdown-section h3,
.markdown-section h4,
.markdown-section h5,
.markdown-section h6 {
    font-weight: 600;
    line-height: 1.25;
    margin-top: 2em;
    margin-bottom: 1em;
    color: var(--text-primary);
}

.markdown-section h1 {
    font-size: 2em;
    padding-bottom: 0.3em;
    border-bottom: 1px solid var(--border-color);
    margin-top: 0;
}

.markdown-section h2 {
    font-size: 1.5em;
    padding-bottom: 0.3em;
    border-bottom: 1px solid var(--border-color);
}

.markdown-section h3 {
    font-size: 1.25em;
}

/* 段落和文本 */
.markdown-section p {
    margin: 1.2em 0;
    line-height: 1.7;
}

.markdown-section a {
    color: var(--theme-color);
    text-decoration: none;
}

.markdown-section a:hover {
    text-decoration: underline;
    color: var(--theme-hover);
}

/* 列表 */
.markdown-section ul,
.markdown-section ol {
    padding-left: 2em;
    margin: 1.2em 0;
}

.markdown-section li {
    margin: 0.5em 0;
    line-height: 1.6;
}

/* 引用块 - GitHub 风格 */
.markdown-section blockquote {
    margin: 1.5em 0;
    padding: 0 1em;
    color: var(--text-secondary);
    border-left: 0.25em solid var(--border-color);
    background: var(--bg-subtle);
    border-radius: 0 6px 6px 0;
}

.markdown-section blockquote p:last-child {
    margin-bottom: 0;
}

/* 代码块 - GitHub 风格 */
.markdown-section pre {
    background: var(--code-bg);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 1em;
    overflow-x: auto;
    margin: 1.5em 0;
    font-size: 0.9em;
    line-height: 1.6;
}

.markdown-section pre code {
    background: transparent;
    padding: 0;
    border: none;
    font-size: inherit;
    color: inherit;
}

/* 行内代码 */
.markdown-section code {
    background: var(--code-bg);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 0.2em 0.4em;
    font-size: 0.9em;
    color: var(--text-primary);
}

/* 表格 - GitHub 风格 */
.markdown-section table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.5em 0;
    display: table;
    table-layout: auto; /* 自动布局，让 min-width 生效 */
}

.markdown-section th,
.markdown-section td {
    padding: 0.8em 1.2em;
    border: 1px solid var(--border-color);
    text-align: left;
    word-break: break-word; /* 强制换行 */
    white-space: normal; /* 不强制单行 */
    overflow-wrap: break-word;
}

/* 教程名称列（第一列） - 自适应全宽，占据所有剩余空间 */
.markdown-section th:first-child,
.markdown-section td:first-child {
    width: auto; /* 自动填充剩余宽度 */
    min-width: 0; /* 不设最小宽度限制 */
    max-width: none;
    padding: 1.2em 1.8em;
    font-weight: 500;
}

/* 后三列并排窄列（分类、难度、热度） */
.markdown-section th:nth-child(2),
.markdown-section td:nth-child(2),
.markdown-section th:nth-child(3),
.markdown-section td:nth-child(3),
.markdown-section th:nth-child(4),
.markdown-section td:nth-child(4) {
    width: 80px; /* 固定窄列 */
    min-width: 70px;
    max-width: 100px;
    text-align: center;
    padding: 0.8em 0.6em;
    font-size: 0.95em;
}

.markdown-section th {
    background: var(--bg-subtle);
    font-weight: 600;
    color: var(--text-primary);
    position: sticky;
    top: 0; /* 固定表头 */
}

.markdown-section tr:nth-child(2n) {
    background: var(--bg-subtle);
}

.markdown-section tr:hover {
    background: var(--theme-light);
}

/* 移动端表格优化 */
@media (max-width: 768px) {
    .markdown-section table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        /* 移动端使用自动布局，让内容决定宽度 */
        table-layout: auto !important;
    }

    .markdown-section th,
    .markdown-section td {
        /* 确保文字换行 */
        white-space: normal !important;
        word-break: break-word !important;
        overflow-wrap: break-word !important;
        /* 增加内边距提高可读性 */
        padding: 0.8em 1em;
    }

    .markdown-section th:first-child,
    .markdown-section td:first-child {
        /* 第一列宽度自适应（可换行） */
        width: auto !important;
        min-width: 0; /* 移除最小宽度限制 */
        max-width: none !important;
        padding: 1em 1.2em;
        font-weight: 500;
    }

    .markdown-section th:nth-child(2),
    .markdown-section td:nth-child(2),
    .markdown-section th:nth-child(3),
    .markdown-section td:nth-child(3),
    .markdown-section th:nth-child(4),
    .markdown-section td:nth-child(4) {
        /* 右侧三列紧凑但可读 */
        width: 80px !important; /* 固定窄列 */
        min-width: 70px;
        text-align: center;
        padding: 0.7em 0.5em;
        font-size: 0.9em;
    }
}

/* 水平分割线 */
.markdown-section hr {
    height: 1px;
    background: var(--border-color);
    border: 0;
    margin: 3em 0;
}

/* 图片 */
.markdown-section img {
    max-width: 100%;
    height: auto;
    border-radius: 6px;
    border: 1px solid var(--border-color);
}

/* 徽章 - 科幻霓虹风格 */
.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.25em 0.7em;
    font-size: 0.75rem;
    font-weight: 700;
    border-radius: 4px;
    margin: 0.2em;
    vertical-align: middle;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    transition: all 0.2s ease;
    border: 2px solid transparent;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.badge-new {
    background: linear-gradient(135deg, #00ff88 0%, #00ccff 100%);
    color: #000;
    border-color: #00ff88;
    box-shadow: 0 0 10px rgba(0, 255, 136, 0.4);
}

.badge-new:hover {
    box-shadow: 0 0 15px rgba(0, 255, 136, 0.6);
    transform: translateY(-1px);
}

.badge-hot {
    background: linear-gradient(135deg, #ff3366 0%, #ff6633 100%);
    color: #fff;
    border-color: #ff3366;
    box-shadow: 0 0 10px rgba(255, 51, 102, 0.4);
}

.badge-hot:hover {
    box-shadow: 0 0 15px rgba(255, 51, 102, 0.6);
    transform: translateY(-1px);
}

.badge-update {
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    color: #fff;
    border-color: #6366f1;
    box-shadow: 0 0 10px rgba(99, 102, 241, 0.4);
}

.badge-update:hover {
    box-shadow: 0 0 15px rgba(99, 102, 241, 0.6);
    transform: translateY(-1px);
}

/* 科幻风格边框发光 */
.badge-cyber {
    background: transparent;
    color: #00ffcc;
    border: 2px solid #00ffcc;
    box-shadow: 0 0 8px rgba(0, 255, 204, 0.3), inset 0 0 8px rgba(0, 255, 204, 0.1);
    text-shadow: 0 0 5px rgba(0, 255, 204, 0.5);
}

.badge-cyber:hover {
    background: rgba(0, 255, 204, 0.1);
    box-shadow: 0 0 12px rgba(0, 255, 204, 0.6), inset 0 0 12px rgba(0, 255, 204, 0.2);
}

/* 提示框 */
.tip,
.warning,
.danger {
    padding: 1em 1.2em;
    border-radius: 6px;
    margin: 1.5em 0;
    border-left: 4px solid;
}

.tip {
    background: #dafbe1;
    border-color: #1f883d;
    color: #0a5c36;
}

.warning {
    background: #fff8c5;
    border-color: #9a6700;
    color: #664d03;
}

.danger {
    background: #ffebe9;
    border-color: #cf222e;
    color: #a21212;
}

/* Giscus 评论区美化 */
#giscus-container {
    max-width: 800px;
    margin: 3em auto 0;
    padding: 2em;
    background: var(--bg-subtle);
    border: 1px solid var(--border-color);
    border-radius: 12px;
}

#giscus-container h3 {
    margin-top: 0;
    color: var(--text-primary);
}

/* 搜索框优化 */
.search input {
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 0.5em 1em;
    font-size: 0.9em;
    background: var(--bg-canvas);
    color: var(--text-primary);
    transition: border-color 0.2s;
}

.search input:focus {
    outline: none;
    border-color: var(--theme-color);
    box-shadow: 0 0 0 3px var(--theme-light);
}

/* 分页按钮 */
.pagination {
    display: flex;
    justify-content: center;
    gap: 0.5em;
    margin: 2em 0;
}

.pagination .pagination-item {
    padding: 0.5em 1em;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-canvas);
    color: var(--text-primary);
    text-decoration: none;
    transition: all 0.15s;
}

.pagination .pagination-item:hover,
.pagination .pagination-item.active {
    background: var(--theme-light);
    border-color: var(--theme-color);
    color: var(--theme-color);
}

/* 移动端菜单按钮 */
.menu-button {
    display: none;
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 1000;
    padding: 0.5rem;
    background: var(--bg-canvas);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
}

@media (max-width: 768px) {
    .menu-button {
        display: block;
    }
}

/* 视频容器 */
.video-container {
    position: relative;
    padding-bottom: 56.25%; /* 16:9 */
    height: 0;
    overflow: hidden;
    border-radius: 12px;
    margin: 1.5em 0;
    border: 1px solid var(--border-color);
}

.video-container iframe,
.video-container video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 0;
}

/* 轮播图样式 - 科幻风格 */
.carousel-container {
    position: relative;
    width: 100%;
    max-width: 900px;
    margin: 1.5em auto;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    border: 2px solid var(--theme-color);
    background: var(--bg-subtle);
}

.carousel-slide {
    display: none;
    position: relative;
    width: 100%;
    padding-bottom: 56.25%; /* 16:9 */
}

.carousel-slide.active {
    display: block;
}

.carousel-slide img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.carousel-caption {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 1.5em;
    background: linear-gradient(transparent, rgba(0,0,0,0.8));
    color: #fff;
    text-shadow: 0 1px 3px rgba(0,0,0,0.5);
}

.carousel-caption h4 {
    margin: 0 0 0.5em 0;
    font-size: 1.2em;
    color: var(--theme-color);
}

.carousel-caption p {
    margin: 0;
    font-size: 0.9em;
    opacity: 0.9;
}

/* 轮播控制按钮 */
.carousel-control {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 48px;
    height: 48px;
    background: rgba(0,0,0,0.5);
    border: 2px solid var(--theme-color);
    border-radius: 50%;
    color: var(--theme-color);
    font-size: 1.5em;
    cursor: pointer;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    backdrop-filter: blur(4px);
}

.carousel-control:hover {
    background: var(--theme-color);
    color: #fff;
    transform: translateY(-50%) scale(1.1);
}

.carousel-prev { left: 1em; }
.carousel-next { right: 1em; }

/* 轮播指示器 */
.carousel-indicators {
    position: absolute;
    bottom: 1em;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 0.5em;
    z-index: 10;
}

.carousel-indicator {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: rgba(255,255,255,0.4);
    border: 2px solid var(--theme-color);
    cursor: pointer;
    transition: all 0.2s;
}

.carousel-indicator.active {
    background: var(--theme-color);
    transform: scale(1.2);
}

@media (max-width: 768px) {
    .carousel-control {
        width: 36px;
        height: 36px;
        font-size: 1.2em;
    }

    .carousel-caption h4 {
        font-size: 1em;
    }

    .carousel-caption p {
        font-size: 0.8em;
    }
}

/* 响应式表格 */
@media (max-width: 768px) {
    .markdown-section table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* 打印优化 */
@media print {
    .sidebar,
    .pagination,
    #giscus-container {
        display: none;
    }

    .page {
        padding: 0;
        max-width: 100%;
    }
}
