/* 筆記閱讀介面整體佈局 */
.reader-container {
    display: flex;
    align-items: stretch;
    height: calc(100vh - 80px); /* 鎖定整體高度 */
    background: transparent;
    margin-top: 80px;
    padding: 0;
    color: inherit;
    box-sizing: border-box;
    gap: 0;
    overflow: hidden; /* 防止整體頁面滾動 */
}

/* 可調式分隔線 (Resizer) */
.reader-resizer {
    width: 12px; /* 加大拖曳熱區 */
    background: transparent;
    cursor: col-resize;
    position: relative;
    z-index: 10;
    transition: background 0.2s;
    flex-shrink: 0;
    display: none; /* 預設隱藏 */
}
.reader-sidebar.show + #readerResizer {
    display: block; /* 左側欄顯示時，左邊分隔線才顯示 */
}
.reader-container:has(#tocContainer.show) #tocResizer {
    display: block; /* 右側欄顯示時，右邊分隔線才顯示 */
}
.reader-resizer::after {
    content: '';
    position: absolute;
    left: 4px; /* 置中 (12-4)/2 = 4 */
    top: 50%;
    transform: translateY(-50%);
    width: 4px; /* 加粗 */
    height: 60px; /* 加高 */
    background: rgba(0, 217, 255, 0.5); /* 加深預設顏色 */
    border-radius: 4px;
    transition: all 0.2s;
}
.reader-resizer:hover::after,
.reader-resizer.resizing::after {
    background: rgba(0, 217, 255, 1);
    box-shadow: 0 0 12px rgba(0, 217, 255, 0.8);
    width: 6px;
    left: 3px;
}
body.reader-resizing {
    user-select: none;
    cursor: col-resize !important;
}

/* 左側欄：章節目錄 */
.reader-sidebar {
    width: 0;
    flex-shrink: 0;
    overflow-y: auto;
    overflow-x: hidden;
    height: 100%;
    /* 科技感毛玻璃 */
    background: rgba(10, 15, 30, 0.5);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    display: flex;
    flex-direction: column;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-sizing: border-box;
    border-right: 0px solid rgba(0, 217, 255, 0.15);
}

.reader-sidebar.show {
    width: 350px;
    border-right-width: 1px;
}

.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: 10px 8px;
}

/* 樹狀結構清單 */
.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 6px;
    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;
    text-align: left;
}


/* 中間欄：主要內容 */
.reader-main {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    flex: 1; /* 占滿剩餘寬度 */
    height: 100%;
    overflow: hidden; /* 中間欄本身不滾動，由 wrapper 負責 */
    min-width: 0;
    box-sizing: border-box;
}

/* 亮色模式外觀 (科技毛玻璃) */
.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 50px 40px;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    position: relative;
    flex: 1;
    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::-webkit-scrollbar {
    width: 4px;
}
.reader-content-wrapper::-webkit-scrollbar-track {
    background: transparent;
}
.reader-content-wrapper::-webkit-scrollbar-thumb {
    background: rgba(0, 217, 255, 0.3);
    border-radius: 4px;
}
.reader-content-wrapper::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 217, 255, 0.6);
}

/* 深色模式外觀 (科技毛玻璃) */
.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);
    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 {
    width: 0;
    flex-shrink: 0;
    overflow-y: auto;
    overflow-x: hidden;
    height: 100%;
    background: rgba(10, 15, 30, 0.5);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-sizing: border-box;
    border-left: 0px solid rgba(0, 217, 255, 0.15);
}

.reader-toc-container.show {
    width: 350px;
    border-left-width: 1px;
}

.reader-toc {
    padding: 20px;
    width: 100%;
    box-sizing: border-box;
}

.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 {
        position: fixed;
        top: 80px;
        left: -100%; /* 預設收合在左側外 */
        width: 100%;
        max-width: 100%;
        height: calc(100vh - 80px);
        margin: 0;
        border-radius: 0;
        z-index: 999;
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: 5px 0 15px rgba(0, 0, 0, 0.5);
        background: rgba(10, 15, 30, 0.98); /* 滿版時背景更為不透明以遮住後方內容 */
    }
    .reader-sidebar.show {
        left: 0;
        width: 100%;
        border-right: 1px solid rgba(0, 217, 255, 0.3);
    }
    
    /* 右側欄頁內目錄：改為懸浮滿版 */
    .reader-toc-container {
        position: fixed;
        top: 80px;
        right: -100%; /* 預設收合在右側外 */
        width: 100%;
        max-width: 100%;
        height: calc(100vh - 80px);
        z-index: 999;
        transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: -5px 0 15px rgba(0, 0, 0, 0.5);
        background: rgba(10, 15, 30, 0.98);
    }
    .reader-toc-container.show {
        right: 0;
        width: 100%;
        border-left: 1px solid rgba(0, 217, 255, 0.3);
    }
    .reader-toc {
        width: 100%;
    }

    .reader-main {
        padding: 15px; /* 縮小邊距 */
        width: 100%;
    }
    .reader-content-wrapper {
        padding: 20px 25px; /* 進一步縮小內層 padding */
        border-radius: 12px;
    }
    .fab-container {
        z-index: 1001; /* 確保高於懸浮側邊欄的 z-index 999 */
    }
}

@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;
    }
}

/* =========================================================
   筆記封面導覽/章節目錄首頁樣式
   ========================================================= */
.note-cover-page {
    max-width: 100%;
    margin: 0 auto;
    padding: 20px 0 50px 0;
}

.cover-header {
    text-align: center;
    margin-bottom: 40px;
    position: relative;
    padding-bottom: 25px;
    border-bottom: 1px solid rgba(0, 217, 255, 0.2);
}

.cover-title {
    font-size: 2.8rem;
    font-weight: 800;
    line-height: 1.3;
    margin-bottom: 15px;
    text-shadow: 0 0 20px rgba(0, 217, 255, 0.15);
}

.cover-meta {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    font-size: 0.9rem;
    opacity: 0.7;
    flex-wrap: wrap;
}

.cover-meta span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.cover-tags {
    display: flex;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 6px;
}

/* 分類/標籤分組容器 */
.cover-meta-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    margin-top: 12px;
}
.cover-meta-label {
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    opacity: 0.5;
    display: flex;
    align-items: center;
    gap: 5px;
}

.cover-intro-card {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 40px;
    line-height: 1.6;
    font-size: 1.05rem;
}
.reader-content-wrapper.dark-mode .cover-intro-card {
    background: rgba(0, 217, 255, 0.02);
    border-color: rgba(0, 217, 255, 0.08);
}

.cover-intro-card h4 {
    font-weight: 700;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--primary-color, #00d9ff);
}

/* 備註卡（橘黃色調區分） */
.cover-remark-card {
    border-color: rgba(251, 191, 36, 0.2);
    background: rgba(251, 191, 36, 0.04);
}
.cover-remark-card h4 {
    color: #fbbf24;
}

/* Logo 圖片 */
.cover-logo-wrap {
    display: flex;
    justify-content: center;
    margin-bottom: 20px;
}
.cover-logo-img {
    width: 140px;
    height: 140px;
    object-fit: contain;
    border-radius: 20px;
    border: 1px solid rgba(0, 217, 255, 0.25);
    padding: 10px;
    background: rgba(255, 255, 255, 0.06);
    box-shadow: 0 4px 20px rgba(0, 217, 255, 0.12);
}

/* 狀態徽章 */
.cover-status-badges {
    display: flex;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 15px;
}
.cover-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    border: 1px solid;
}
.badge-pinned {
    color: #f59e0b;
    border-color: rgba(245, 158, 11, 0.3);
    background: rgba(245, 158, 11, 0.08);
}
.badge-public {
    color: #10b981;
    border-color: rgba(16, 185, 129, 0.3);
    background: rgba(16, 185, 129, 0.08);
}
.badge-project {
    color: #00d9ff;
    border-color: rgba(0, 217, 255, 0.3);
    background: rgba(0, 217, 255, 0.08);
}

/* 統計資訊列 */
.cover-stats-row {
    display: flex;
    justify-content: center;
    gap: 30px;
    margin: 20px 0 30px;
    flex-wrap: wrap;
}
.cover-stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 15px 25px;
    border-radius: 12px;
    background: rgba(0, 217, 255, 0.04);
    border: 1px solid rgba(0, 217, 255, 0.12);
    min-width: 90px;
    transition: all 0.3s ease;
}
.cover-stat-item:hover {
    background: rgba(0, 217, 255, 0.08);
    border-color: rgba(0, 217, 255, 0.25);
}
.cover-stat-item i {
    font-size: 1.1rem;
    color: #00d9ff;
    opacity: 0.8;
}
.cover-stat-num {
    font-size: 1.6rem;
    font-weight: 800;
    line-height: 1;
    color: inherit;
}
.cover-stat-label {
    font-size: 0.75rem;
    opacity: 0.6;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.cover-directory-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-left: 4px solid var(--primary-color, #00d9ff);
    padding-left: 12px;
}

.cover-chapter-tree {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}

.cover-chapter-node {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    padding: 15px 20px;
    transition: all 0.3s ease;
}

.reader-content-wrapper.dark-mode .cover-chapter-node {
    background: rgba(10, 15, 30, 0.4);
    border-color: rgba(0, 217, 255, 0.05);
}

.cover-chapter-node:hover {
    transform: translateY(-2px);
    background: rgba(0, 217, 255, 0.05);
    border-color: rgba(0, 217, 255, 0.2);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.cover-node-main {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    font-weight: 600;
    font-size: 1.1rem;
}

.cover-node-main .node-title-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.cover-node-main i.chapter-icon {
    color: var(--primary-color, #00d9ff);
    font-size: 1.1rem;
}

.cover-node-main .go-read-btn {
    font-size: 0.85rem;
    opacity: 0;
    color: var(--primary-color, #00d9ff);
    transition: all 0.3s ease;
}

.cover-chapter-node:hover .go-read-btn {
    opacity: 1;
    transform: translateX(-5px);
}

/* 子章節目錄縮排與樣式 */
.cover-chapter-children {
    list-style: none;
    padding: 10px 0 0 24px;
    margin: 0;
    border-left: 1px dashed rgba(255, 255, 255, 0.1);
    margin-left: 7px;
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
}

.cover-child-node {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.95rem;
    transition: all 0.2s ease;
    opacity: 0.8;
}

.cover-child-node:hover {
    background: rgba(0, 217, 255, 0.08);
    opacity: 1;
    color: #00d9ff;
    padding-left: 16px;
}

.cover-child-node .go-read-btn {
    font-size: 0.8;
    opacity: 0;
    transition: all 0.2s ease;
}

.cover-child-node:hover .go-read-btn {
    opacity: 1;
}

@media (max-width: 576px) {
    .cover-title {
        font-size: 2rem;
    }
    .cover-meta {
        flex-direction: column;
        align-items: center;
        gap: 8px;
    }
}

/* =========================================================
   底部章節導航樣式
   ========================================================= */
.chapter-navigation {
    margin-top: 50px;
    padding-top: 30px;
    border-top: 1px solid rgba(0, 217, 255, 0.2);
    display: flex;
    justify-content: space-between;
    gap: 20px;
    flex-wrap: wrap;
}
.chapter-navigation.nav-top {
    margin-top: 0;
    margin-bottom: 40px;
    padding-top: 0;
    padding-bottom: 20px;
    border-top: none;
    border-bottom: 1px solid rgba(0, 217, 255, 0.2);
}
.reader-content-wrapper.dark-mode .chapter-navigation {
    border-top-color: rgba(0, 217, 255, 0.15);
}
.reader-content-wrapper.dark-mode .chapter-navigation.nav-top {
    border-bottom-color: rgba(0, 217, 255, 0.15);
}

.nav-btn {
    flex: 1;
    min-width: 150px;
    padding: 15px 20px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    color: inherit;
    text-decoration: none;
    display: flex;
    flex-direction: column;
    transition: all 0.3s ease;
    cursor: pointer;
}
.reader-content-wrapper.dark-mode .nav-btn {
    background: rgba(10, 15, 30, 0.4);
    border-color: rgba(0, 217, 255, 0.1);
}

.nav-btn:hover {
    background: rgba(0, 217, 255, 0.05);
    border-color: rgba(0, 217, 255, 0.3);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    text-decoration: none;
    color: #00d9ff;
}

.nav-btn.prev-btn {
    align-items: flex-start;
}
.nav-btn.middle-btn {
    align-items: center;
    text-align: center;
    background: rgba(0, 217, 255, 0.03);
    border-color: rgba(0, 217, 255, 0.15);
}
.nav-btn.middle-btn:hover {
    background: rgba(0, 217, 255, 0.08);
    border-color: rgba(0, 217, 255, 0.4);
}
.nav-btn.next-btn {
    align-items: flex-end;
    text-align: right;
}

.nav-btn-spacer {
    flex: 1;
    min-width: 150px;
}

.nav-label {
    font-size: 0.8rem;
    opacity: 0.6;
    text-transform: uppercase;
    margin-bottom: 5px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.nav-title {
    font-size: 1.05rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

/* =========================================================
   行內樣式提取至外部樣式表
   ========================================================= */

/* 鎖定全域滾動，僅在容器各欄內滾動 */
body {
    overflow: hidden !important;
}

/* 側邊欄封面大綱按鈕 */
.sidebar-home-link {
    padding: 10px;
    margin-bottom: 15px;
    cursor: pointer;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 10px;
    border: 1px solid rgba(0, 217, 255, 0.15);
    background: rgba(0, 217, 255, 0.05);
    transition: all 0.3s ease;
}
.sidebar-home-link:hover {
    background: rgba(0, 217, 255, 0.12);
    border-color: rgba(0, 217, 255, 0.3);
}
.sidebar-home-icon {
    color: #00d9ff;
}
.sidebar-home-text {
    font-weight: 600;
}

/* 封面返回按鈕 */
.cover-back-wrapper {
    margin-bottom: 20px;
    text-align: left;
}
.cover-back-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: inherit;
}
.cover-back-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #00d9ff;
}

/* 頂底導航欄隱藏與寬度設定 */
#chapterNavigationTop,
#chapterNavigation {
    display: none;
    width: 100%;
}
