/* style.css - 最終完美版 */
@import url('https://fonts.googleapis.com/css2?family=LXGW+WenKai+TC&display=swap');

/* --- 全局設定 --- */
html {
    scroll-behavior: smooth;      /* 點擊目錄時平滑滾動 */
    scroll-padding-top: 20px;     /* 避免跳轉後標題貼著視窗頂部太近 */
}

body {
    font-family: "Helvetica Neue", Helvetica, Arial, "PingFang TC", "Microsoft JhengHei", sans-serif;
    line-height: 1.8;
    color: #333;
    background-color: #fdfdfd;
    margin: 0 auto;
    padding: 20px;
    max-width: 1200px; /* 限制最大寬度，避免在大螢幕上太寬 */
    
    /* 啟用 Grid 佈局 (預設手機版：單欄) */
    display: grid;
    grid-template-columns: 1fr;
    gap: 0;
}

/* 連結基本樣式 */
a { color: #0066cc; text-decoration: none; transition: color 0.2s; }
a:hover { color: #004499; text-decoration: underline; }

/* --- 標題與日期區域 --- */
h1.title { 
    text-align: center; 
    margin-bottom: 10px;
    font-family: "Songti TC", "SimSun", "LXGW WenKai TC", serif;
    color: #222;
    line-height: 1.3; /* 增加一點行高，避免換行時擠在一起 */
}

/* 響應式標題：英文標題控制 */
.en-title {
    /* [手機版預設] */
    display: block;       /* 強制換行 */
    font-size: 0.85em;    /* 英文稍微縮小一點，視覺更有層次 */
    font-family: "Songti TC", "SimSun", "LXGW WenKai TC", serif;
    color: #555;          /* 顏色稍微淡一點 */
    margin-top: 5px;      /* 增加與中文標題的間距 */
}

/* Pandoc 自動生成的日期樣式 */
p.date {
    text-align: center;
    color: #888;
    font-size: 0.9em;
    margin-top: 0;
    margin-bottom: 30px; /* 日期與正文的距離 */
    font-family: monospace; /* 用等寬字體顯示時間更有科技感 */
}

/* --- PDF 按鈕區域 (新位置) --- */
.pdf-btn-wrapper {
    text-align: right; /* 關鍵：讓按鈕靠右對齊 */
    margin-bottom: 20px; /* 與下方正文保持距離 */
    padding-top: 5px;
}

.pdf-btn-wrapper a {
    background-color: #0066cc;
    color: white;
    padding: 8px 16px;
    border-radius: 4px;
    text-decoration: none;
    font-size: 14px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    transition: background-color 0.2s;
}

.pdf-btn-wrapper a:hover {
    background-color: #0055aa;
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

/* --- 桌面版佈局 (當螢幕寬度 > 1000px) --- */
@media (min-width: 1000px) {
    body {
        /* 定義兩欄：左 300px，右 自動 */
        grid-template-columns: 300px 1fr;
        
        /* [關鍵修正] 定義列高：
           第一列 (min-content) 給標題與日期，高度由內容決定
           第二列 (1fr) 給正文與目錄，佔滿剩餘空間 */
        grid-template-rows: min-content 1fr;
        
        gap: 40px;
        align-items: start;
    }

    /* 1. 標題與日期區 -> 強制放在「第二欄、第一列」 */
    #title-block-header {
        grid-column: 2;
        grid-row: 1;
        margin-bottom: 20px;
    }

    /* 2. 左側目錄 -> 強制去第一欄 (左邊)，並跨越行數以保持懸浮 */
    #TOC {
        grid-column: 1;      /* 指定第一欄 */
        grid-row: 1 / -1;   /* 讓它垂直跨越所有內容，確保一直黏在左邊 */
        position: sticky;      /* 懸浮效果 */
        top: 20px;
        height: 90vh;          /* 限制高度 */
        overflow-y: auto;      /* 超過高度時出現捲軸 */
        border-right: 1px solid #eee;
        padding-right: 20px;
        margin-top: 0;
    }

    /* 3. 右側內容區 -> 強制去第二欄 (右邊) */
    .main-content {
        grid-column: 2;      /* 指定第二欄 */
        min-width: 0;
    }

    /* 電腦版標題設定：中英並排 */
    .en-title {
        display: inline;       /* 恢復同一行 */
        font-size: 1em;
        margin-top: 0;
        margin-left: 15px;     /* 左邊留白隔開中文 */
        padding-left: 15px;
        border-left: 1px solid #ccc; /* 加一條細分隔線 */
    }
}

/* --- 目錄 (TOC) 美化 --- */
#TOC ul { list-style-type: none; padding-left: 0; }
#TOC li { margin-bottom: 6px; }
#TOC ul ul { padding-left: 15px; } /* 子目錄縮排 */

#TOC a {
    display: block;
    padding: 6px 10px;
    border-radius: 4px;
    color: #555;
    font-size: 0.9em;
    border-left: 3px solid transparent;
    word-break: break-all;
}

#TOC a:hover {
    background-color: #f0f7ff;
    color: #0066cc;
    border-left: 3px solid #0066cc;
}

/* --- 內文標題樣式 --- */
/* 中文標題 */
h2.自訂中文標題樣式 {
    margin-top: 60px;
    margin-bottom: 10px;
    font-family: "Songti TC", "SimSun", "LXGW WenKai TC", serif;
    font-size: 1.5em;
    color: #2c3e50;
    border-bottom: none;
    line-height: 1.4;
}

/* 英文標題 */
h2.自訂英文標題樣式 {
    margin-top: 0;
    font-size: 1.1em;
    font-weight: normal;
    color: #666;
    font-style: italic;
    border-bottom: 1px solid #eee;
    padding-bottom: 15px;
    margin-bottom: 25px;
    line-height: 1.5;
}

/* --- 回到頂部按鈕 --- */
#backToTopBtn {
    display: none;        /* 預設隱藏，由 JS 控制 */
    position: fixed;
    bottom: 30px;
    right: 30px;
    z-index: 99;
    font-size: 20px;
    border: none;
    outline: none;
    background-color: #0066cc;
    color: white;
    cursor: pointer;
    padding: 10px 15px;
    border-radius: 50%;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
    transition: transform 0.2s;
}

#backToTopBtn:hover {
    transform: translateY(-3px);
    background-color: #0055aa;
}