/* 主內容區域的頂部間距 */
body {
    padding-top: 60px;
    margin: 0;
    font-family: Arial, sans-serif;
    background-color: var(--background-primary);
    color: var(--text-primary);
    transition: background-color 0.3s, color 0.3s;  /* 為 body 添加主題切換過渡效果 */
}
/* 強制暗色模式類 */
body.dark-theme {
    color-scheme: dark;
    background-color: var(--background-primary);
    color: var(--text-primary);
}
/* 強制亮色模式類 */
body.light-theme {
    color-scheme: light;
    background-color: var(--background-primary);
    color: var(--text-primary);
}
p {
    font-weight: 400;
}
.paragraph {
    text-indent: 2em;
}
.indent {
    margin-left: 1em;
}
a {
    text-decoration: none;
    color: var(--primary);
    font-weight: 500;
}
a:hover, a:active {
    color: var(--primary-hover);
}
/* 平滑捲動效果 */
html {
    scroll-behavior: smooth;
}		
/* 標題上方增加間距，防止導航時標題被頂部遮擋 */
h2[id], h3[id], h4[id] {
    scroll-margin-top: 70px;
}
table {
    border-collapse: collapse;
    margin-top: 1rem;
    width: 100%;
}
table th, table td {
    border: 1px solid var(--border-light);
    padding: 8px;
    text-align: left;
}
table caption {
    font-weight: bold;
    margin-bottom: 0.5rem;
}
pre {
    background-color: var(--background-code);
    padding: 12px;
    margin: 0 auto;
    border-radius: 4px;
    overflow-x: auto;
}
code {
    background-color: var(--background-code);
    padding: 2px 4px;
    border-radius: 4px;
    font-family: monospace;
}

/* 固定導航欄樣式 */
#fixed-nav {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    background-color: var(--background-light);
    box-shadow: 0 2px 4px var(--shadow-light);
    z-index: 1000;
    padding: 10px 0;
    display: flex;
    justify-content: center;
    align-items: center;
    box-sizing: border-box;
}
#nav-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: 1500px; /* 設定最大寬度 */
    padding: 0 20px;
    box-sizing: border-box;
}
#fixed-nav .nav-title {
    font-size: 18px;
    font-weight: bold;
}
#fixed-nav .nav-links {
    display: flex;
    gap: 1rem;
}
#fixed-nav a {
    text-decoration: none;
    color: var(--text-dark-light);
    font-weight: 500;
}
#fixed-nav a:hover, #fixed-nav a.active {
    color: var(--primary);
}

/* 響應式佈局 - 小螢幕設備 */
@media screen and (max-width: 950px) {
    .sidebar-col {
        display: none; /* 隱藏側邊欄 */
    }
    .main-col {
        flex: 1 !important;
        max-width: 100% !important; /* 主內容區域佔據全部寬度 */
    }
    
    /* 移動端導航 */
    #fixed-nav .nav-links {
        display: none; /* 隱藏一般導航連結 */
    }
    .mobile-menu-toggle {
        display: block !important; /* 顯示移動端選單按鈕 */
        font-size: 24px;
        font-weight: bold;
        cursor: pointer;
        padding: 5px 10px;
        color: var(--text-dark-light);
    }
    .mobile-menu-panel {
        display: none;
        position: fixed;
        top: 60px;
        left: 0;
        width: 100%;
        background-color: var(--background-primary);
        box-shadow: 0 4px 6px var(--shadow-light);
        z-index: 999;
        max-height: 80vh;
        overflow-y: auto;
    }
    .mobile-menu-panel.active {
        display: block;
    }
    .mobile-menu-section {
        padding: 10px 20px;
    }
    .mobile-menu-section a {
        display: block;
        padding: 8px 0;
        color: var(--text-dark-light);
        text-decoration: none;
        border-bottom: 1px solid var(--border-lighter);
    }
    .mobile-menu-section a:hover {
        color: var(--primary);
    }
    .mobile-menu-section h4 {
        margin-top: 15px;
        margin-bottom: 5px;
        font-weight: bold;
        color: var(--text-gray);
    }
    .mobile-nav-divider {
        height: 1px;
        background-color: var(--divider);
        margin: 10px 0;
    }
    .mobile-sub-menu {
        padding-left: 20px;
    }
}

/* 側邊導航區域樣式 */
.nav-sidebar {
    transition: all 0.3s ease;
    padding: 0 20px;
    position: sticky;
    top: 60px; /* 與固定導航欄底部對齊 */
    max-height: calc(100vh - 70px);
    overflow-y: auto; /* 內容過多時可滾動 */
}
#nav-sidebar a {
    text-decoration: none;
    color: var(--text-primary);
    font-weight: 500;
}
#nav-sidebar a:hover, #nav-sidebar a.active {
    color: var(--primary);
}

/* 回到頂部按鈕 */
#back-to-top {
    position: fixed;
    bottom: 90px;
    right: 20px;
    background-color: var(--primary);
    color: var(--text-dark);
    border: none;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    font-size: 24px;
    cursor: pointer;
    display: none; /* 初始隱藏 */
    z-index: 1000;
    box-shadow: 0 2px 5px var(--shadow-medium);
}
#back-to-top:hover {
    background-color: var(--primary-hover);
}

/* 主題切換按鈕 */
#theme-toggle {
    position: fixed;
    bottom: 20px;
    right: 20px; /* 位於回到頂部按鈕旁邊 */
    background-color: var(--primary);
    color: var(--text-dark);
    border: none;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    font-size: 20px;
    cursor: pointer;
    display: block;
    z-index: 1000;
    box-shadow: 0 2px 5px var(--shadow-medium);
    transition: background-color 0.3s;
}
#theme-toggle:hover {
    background-color: var(--primary-hover);
}

/* 移動端選單按鈕預設隱藏 */
.mobile-menu-toggle {
    display: none;
}
/* 移動端導航面板 */
.mobile-menu-panel {
    display: none;
}

/* 共用容器 */
.container {
    width: 100%;
    max-width: 1500px; /* 設定最大寬度 */
    padding: 0 20px;
    box-sizing: border-box; /* 確保 padding 被計算在寬度內 */
    margin: 0 auto; /* 居中顯示 */
}
/* 佈局容器 */
.flex-container {
    display: flex;
    gap: 1rem;
    max-width: 1500px; /* 設定最大寬度 */
    margin: 0 auto; /* 居中顯示 */
}
/* 導航區域約佔 20% */
.sidebar-col {
    flex: 1;
    max-width: 20%;
    min-width: 250px; /* 確保導航欄不會太窄 */
}
/* 主內容區域約佔 80% */
.main-col {
    flex: 4;
    max-width: 80%;
}

/* 頁腳樣式 */
.footer {
    background-color: var(--background-footer);
    color: var(--text-dark);
    padding: 30px 0 10px;
    margin-top: 40px;
    width: 100%;
    box-sizing: border-box;
}
.footer-content {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}
.footer-section {
    flex: 1;
    min-width: 250px;
    margin-bottom: 20px;
    padding: 0 15px;
}
.footer-section h4 {
    color: var(--primary-dark);
    margin-bottom: 15px;
    font-size: 18px;
    position: relative;
    padding-bottom: 8px;
}
.footer-section h4:after {
    content: "";
    position: absolute;
    left: 0;
    bottom: 0;
    width: 50px;
    height: 2px;
    background-color: var(--primary-dark);
}
.footer-section p {
    margin: 8px 0;
    font-size: 14px;
    text-indent: 0; /* 移除段落縮排 */
}
.footer-section a {
    color: var(--primary-light);
    text-decoration: none;
    transition: color 0.3s;
}
.footer-section a:hover {
    color: var(--text-dark);
    text-decoration: underline;
}
.footer-bottom {
    text-align: center;
    padding-top: 15px;
    margin-top: 20px;
    border-top: 1px solid var(--footer-divider);
    font-size: 12px;
    color: var(--text-footer-light);
}

/* 色彩主題 */
@media (prefers-color-scheme:light){
    :root{
        /* 基本色彩 */
        --background-primary: #fff;
        --text-primary: #000;
        --background-dark: #1b1b1b;
        --text-dark: #fff;

        /* 主題色彩 */
        --primary: #007bff;
        --primary-hover: #0056b3;
        --primary-light: #5dade2;
        --primary-dark: #3498db;

        /* 背景色彩 */
        --background-light: #f8f9fa;
        --background-footer: #2c3e50;
        --background-code: #ddd;

        /* 文字與邊框色彩 */
        --text-dark-light: #333;
        --text-gray: #555;
        --text-footer-light: #bdc3c7;
        --border-light: #ccc;
        --border-lighter: #eee;
        --divider: #ddd;
        --footer-divider: rgba(255, 255, 255, 0.1);

        /* 特殊顏色 */
        --accent-yellow: #f3b918;
        --accent-red: #ec3b53;

        /* 陰影色彩 */
        --shadow-light: rgba(0, 0, 0, 0.1);
        --shadow-medium: rgba(0, 0, 0, 0.2);
    }
}
@media (prefers-color-scheme:dark){
    :root{
        /* 基本色彩 - 暗色模式 */
        --background-primary: #1b1b1b;
        --text-primary: #f0f0f0;
        --background-dark: #121212;
        --text-dark: #fff;

        /* 主題色彩 - 暗色模式 */
        --primary: #2196f3;
        --primary-hover: #64b5f6;
        --primary-light: #90caf9;
        --primary-dark: #1976d2;

        /* 背景色彩 - 暗色模式 */
        --background-light: #2d2d2d;
        --background-footer: #121212;
        --background-code: #3d3d3d;

        /* 文字與邊框色彩 - 暗色模式 */
        --text-dark-light: #e0e0e0;
        --text-gray: #aaa;
        --text-footer-light: #757575;
        --border-light: #444;
        --border-lighter: #333;
        --divider: #444;
        --footer-divider: rgba(255, 255, 255, 0.1);

        /* 特殊顏色 - 暗色模式 */
        --accent-yellow: #ffb300;
        --accent-red: #f44336;

        /* 陰影色彩 - 暗色模式 */
        --shadow-light: rgba(0, 0, 0, 0.5);
        --shadow-medium: rgba(0, 0, 0, 0.7);
    }
}

/* 手動主題切換類別 - 需要高優先級來覆蓋媒體查詢 */
/* 亮色主題 */
html.light-theme body,
body.light-theme {
    /* 基本色彩 */
    --background-primary: #fff !important;
    --text-primary: #000 !important;
    --background-dark: #1b1b1b !important;
    --text-dark: #fff !important;

    /* 主題色彩 */
    --primary: #007bff !important;
    --primary-hover: #0056b3 !important;
    --primary-light: #5dade2 !important;
    --primary-dark: #3498db !important;

    /* 背景色彩 */
    --background-light: #f8f9fa !important;
    --background-footer: #2c3e50 !important;
    --background-code: #ddd !important;

    /* 文字與邊框色彩 */
    --text-dark-light: #333 !important;
    --text-gray: #555 !important;
    --text-footer-light: #bdc3c7 !important;
    --border-light: #ccc !important;
    --border-lighter: #eee !important;
    --divider: #ddd !important;
    --footer-divider: rgba(255, 255, 255, 0.1) !important;

    /* 特殊顏色 */
    --accent-yellow: #f3b918 !important;
    --accent-red: #ec3b53 !important;

    /* 陰影色彩 */
    --shadow-light: rgba(0, 0, 0, 0.1) !important;
    --shadow-medium: rgba(0, 0, 0, 0.2) !important;
}

/* 暗色主題 */
html.dark-theme body,
body.dark-theme {
    /* 基本色彩 - 暗色模式 */
    --background-primary: #1b1b1b !important;
    --text-primary: #f0f0f0 !important;
    --background-dark: #121212 !important;
    --text-dark: #fff !important;

    /* 主題色彩 - 暗色模式 */
    --primary: #2196f3 !important;
    --primary-hover: #64b5f6 !important;
    --primary-light: #90caf9 !important;
    --primary-dark: #1976d2 !important;

    /* 背景色彩 - 暗色模式 */
    --background-light: #2d2d2d !important;
    --background-footer: #121212 !important;
    --background-code: #3d3d3d !important;

    /* 文字與邊框色彩 - 暗色模式 */
    --text-dark-light: #e0e0e0 !important;
    --text-gray: #aaa !important;
    --text-footer-light: #757575 !important;
    --border-light: #444 !important;
    --border-lighter: #333 !important;
    --divider: #444 !important;
    --footer-divider: rgba(255, 255, 255, 0.1) !important;

    /* 特殊顏色 - 暗色模式 */
    --accent-yellow: #ffb300 !important;
    --accent-red: #f44336 !important;

    /* 陰影色彩 - 暗色模式 */
    --shadow-light: rgba(0, 0, 0, 0.5) !important;
    --shadow-medium: rgba(0, 0, 0, 0.7) !important;
}