/* 筆記閱讀介面整體佈局 */
.reader-container {
    display: flex;
    justify-content: center; /* 讓內容置中 */
    height: calc(100vh - 80px); /* 鎖定高度 */
    overflow: hidden; /* 防止全域滾動 */
    background: transparent;
    margin-top: 80px;
    color: inherit;
}


/* 左側欄：章節目錄 (改為浮出式) */
.reader-sidebar {
    position: fixed;
    left: -320px; /* 預設隱藏於畫面外 */
    top: 80px;
    width: 280px;
    height: calc(100vh - 120px); /* 扣除 header 與 margin */
    z-index: 100;
    /* 更高透明度的科技感毛玻璃 */
    background: rgba(10, 15, 30, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(0, 217, 255, 0.2);
    border-radius: 16px;
    box-shadow: 5px 0 25px rgba(0, 0, 0, 0.5), inset 0 0 15px rgba(0, 217, 255, 0.05);
    display: flex;
    flex-direction: column;
    margin: 20px;
    overflow-y: auto;
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.reader-sidebar.show {
    left: 0;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid rgba(0, 217, 255, 0.2);
}

.sidebar-header h3 {
    font-size: 1.2rem;
    font-weight: 700;
    color: inherit;
    line-height: 1.4;
    text-shadow: 0 0 10px rgba(0, 217, 255, 0.3);
}

.sidebar-content {
    padding: 15px;
}

/* 樹狀結構清單 */
.section-tree {
    list-style: none;
    padding: 0;
    margin: 0;
}
.section-tree ul {
    list-style: none;
    padding-left: 20px;
    margin: 0;
    display: none; /* 預設摺疊 */
}
.section-tree ul.expanded {
    display: block;
}

.tree-node {
    display: flex;
    align-items: center;
    padding: 8px 10px;
    border-radius: 8px;
    cursor: pointer;
    color: inherit;
    opacity: 0.8;
    font-size: 0.95rem;
    transition: all 0.3s ease;
    user-select: none;
    margin-bottom: 4px;
    border: 1px solid transparent;
}
.tree-node:hover {
    background: rgba(0, 217, 255, 0.1);
    opacity: 1;
}
.tree-node.active {
    background: rgba(0, 217, 255, 0.15);
    color: #00d9ff;
    font-weight: 600;
    opacity: 1;
    border: 1px solid rgba(0, 217, 255, 0.3);
    box-shadow: 0 0 15px rgba(0, 217, 255, 0.1);
}
.node-toggle {
    width: 20px;
    text-align: center;
    opacity: 0.6;
    margin-right: 5px;
}
.node-title {
    flex-grow: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}


/* 中間欄：主要內容 */
.reader-main {
    padding: 20px; /* 從 40px 縮小為 20px，讓內容空間變大 */
    display: flex;
    justify-content: center;
    width: 90%;
    height: 100%;
    /* 移除外層滾動，交由內層卡片滾動 */
}

/* 亮色模式外觀 (科技毛玻璃) */
.reader-content-wrapper {
    width: 100%;
    box-sizing: border-box;
    background: rgba(255, 255, 255, 0.4);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    color: #333;
    padding: 30px 40px; /* 從 40px 60px 縮小，增加內容可見度 */
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    position: relative;
    /* 固定高度，與左側欄對齊，並開啟內部滾動 */
    height: 100%;
    overflow-y: auto;
    border: 1px solid rgba(255, 255, 255, 0.5);
    transition: background-color 0.3s, color 0.3s, border 0.3s, padding 0.3s;
}

/* 深色模式外觀 (科技毛玻璃) */
.reader-content-wrapper.dark-mode {
    background: rgba(10, 15, 30, 0.3);
    color: #f1f5f9;
    border: 1px solid rgba(0, 217, 255, 0.2);
    box-shadow: 0 0 30px rgba(0, 217, 255, 0.05), inset 0 0 20px rgba(0, 217, 255, 0.02);
}

.content-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid rgba(0, 217, 255, 0.3);
    margin-bottom: 30px;
    padding-bottom: 15px;
}

.header-back-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 0.95rem;
    color: var(--primary-color, #00d9ff);
    text-decoration: none;
    padding: 8px 16px;
    border-radius: 8px;
    background: rgba(0, 217, 255, 0.1);
    border: 1px solid rgba(0, 217, 255, 0.2);
    transition: all 0.3s ease;
    white-space: nowrap;
}

.header-back-link:hover {
    color: #fff;
    background: rgba(0, 217, 255, 0.2);
    box-shadow: 0 0 10px rgba(0, 217, 255, 0.3);
    text-decoration: none;
}

.content-title {
    font-size: 2.5rem;
    font-weight: 700;
    color: inherit;
    margin: 0;
}

.loading-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    color: var(--primary-color, #3b82f6);
    border-radius: 16px;
    z-index: 10;
}
.reader-content-wrapper.dark-mode .loading-overlay {
    background: rgba(26, 31, 44, 0.8);
    color: #f1f5f9;
}


/* 右側欄：頁內目錄 (TOC) - 改為滑動面板 (固定為暗色系配色) */
.reader-toc-container {
    position: fixed;
    right: -300px; /* 隱藏於畫面外 (寬度 280px + 緩衝) */
    top: 80px;
    width: 280px; /* 與左側欄 (280px) 保持一致 */
    height: calc(100vh - 80px);
    overflow-y: auto;
    background: #0f172a; /* 強制使用暗色背景 */
    color: #f1f5f9; /* 強制使用亮色文字 */
    border-left: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: -5px 0 25px rgba(0, 0, 0, 0.5);
    transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 100;
    padding: 30px 20px;
}

.reader-toc-container.show {
    right: 0; /* 顯示 */
}

.reader-toc h4 {
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: inherit;
    opacity: 0.7;
    margin-bottom: 20px;
    font-weight: 700;
    border-bottom: 1px solid rgba(148, 163, 184, 0.3);
    padding-bottom: 10px;
}


.reader-toc ul {
    list-style: none;
    padding: 0;
    margin: 0;
}
.reader-toc ul ul {
    padding-left: 15px;
}
.reader-toc li {
    margin-bottom: 10px;
}

.reader-toc a {
    display: block;
    color: rgba(255, 255, 255, 0.6);
    text-decoration: none;
    font-size: 0.9rem;
    line-height: 1.4;
    padding-left: 12px;
    border-left: 2px solid transparent;
    transition: all 0.3s ease;
}
/* 科技按鈕相關樣式移至 button.css 作為全域使用 */
.reader-toc a:hover {
    color: var(--white);
}

.reader-toc a.active {
    color: var(--cyan);
    font-weight: 600;
    border-left-color: var(--cyan);
}

/* =========================================
   響應式設計 (RWD)
   ========================================= */

@media (max-width: 992px) {
    /* 平板與小螢幕：左側欄改為滿版高度，無圓角 */
    .reader-sidebar {
        height: calc(100vh - 80px); /* 滿版高度 */
        margin: 0;
        border-radius: 0;
    }
    .reader-sidebar.show {
        left: 0;
    }
    .reader-main {
        padding: 15px; /* 縮小邊距 */
    }
    .reader-content-wrapper {
        padding: 20px 25px; /* 進一步縮小內層 padding */
        border-radius: 12px;
    }
    /* 在手機版，我們可能需要左下的漢堡按鈕來打開左側列，但為了不破壞現有 HTML，我們可以透過縮小邊距即可，使用者可使用原生上一頁返回。 */
}

@media (max-width: 576px) {
    /* 手機版極限尺寸 */
    .reader-main {
        padding: 10px;
    }
    .reader-content-wrapper {
        padding: 15px 20px;
        border-radius: 8px; /* 較小圓角 */
    }
    .content-title {
        font-size: 1.8rem;
    }
    /* 縮小右下角的浮動按鈕區 */
    .fab-container {
        right: 15px;
        bottom: 20px;
        gap: 10px;
    }
    .tech-fab-btn {
        width: 45px;
        height: 45px;
        font-size: 1.1rem;
    }
}
