/* ========================================================================
   CSS Reset and Normalization - Phase 1.1 分頁模式修改計畫
   目標：消除瀏覽器之間的預設樣式差異，為分頁系統建立穩固基礎
   ======================================================================== */

/* Webfont: Sarasa Mono TC/SC (local-first). If available on system,
   browser will prefer it; otherwise fallback to LXGW WenKai Mono TC. */
@font-face {
    font-family: 'Sarasa Mono TC';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: local('Sarasa Mono TC'), local('SarasaMonoTC-Regular'),
         url('/static/fonts/SarasaMonoTC-Regular.ttf') format('truetype');
}

@font-face {
    font-family: 'Sarasa Mono SC';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: local('Sarasa Mono SC'), local('SarasaMonoSC-Regular'),
         url('/static/fonts/SarasaMonoSC-Regular.ttf') format('truetype');
}

/* Universal box-sizing reset */
*, *::before, *::after {
    box-sizing: border-box;
}

/* Basic CSS Reset for core elements */
html, body, div, span, h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code, del, dfn, em, img, ins,
kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i,
center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td, article, aside,
canvas, details, embed, figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary, time, mark, audio, video {
    margin: 0;
    padding: 0;
    border: 0;
    font-size: 100%;
    font: inherit;
    vertical-align: baseline;
}

/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
    display: block;
}

/* Reset list styles */
ol, ul {
    list-style: none;
}

/* Reset blockquotes */
blockquote, q {
    quotes: none;
}

blockquote:before, blockquote:after,
q:before, q:after {
    content: '';
    content: none;
}

/* Reset table styles */
table {
    border-collapse: collapse;
    border-spacing: 0;
}

/* Reset form elements */
button, input, optgroup, select, textarea {
    font-family: inherit;
    font-size: 100%;
    line-height: 1.15;
    margin: 0;
}

/* Reset button styles */
button {
    background: none;
    border: none;
    cursor: pointer;
}

/* Reset focus styles */
button:focus, input:focus, textarea:focus, select:focus {
    outline: none;
}

/* Reset anchor styles */
a {
    color: inherit;
    text-decoration: none;
}

/* Modern normalize additions */
html {
    line-height: 1.15;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
    height: 100%;
}

body {
    margin: 0;
    min-height: 100vh;
    height: 100%;
    overflow: hidden; /* 禁止整頁捲動，改由內層容器控制 */
    overflow-x: hidden;
}

/* Improve media defaults */
img, video, canvas, audio, iframe, embed, object {
    display: block;
    max-width: 100%;
}

img, video {
    height: auto;
}

/* Remove built-in form typography styles */
input, button, textarea, select {
    font: inherit;
}

/* Avoid text overflows */
p, h1, h2, h3, h4, h5, h6 {
    overflow-wrap: break-word;
}

/* Improve line wrapping */
p {
    text-wrap: pretty;
}
h1, h2, h3, h4, h5, h6 {
    text-wrap: balance;
}

/* Create a root stacking context */
#root, #__next {
    isolation: isolate;
}

/* ========================================================================
   End of CSS Reset - Phase 1.1 Complete
   ======================================================================== */

/* ========================================================================
   核心閱讀排版樣式 - Phase 1.2 分頁模式修改計畫
   目標：建立舒適、美觀的閱讀基底，提供優雅的書本感體驗
   ======================================================================== */

/* 主要內容容器的排版樣式 */
.content-wrapper {
    /* 分頁模式改回使用 LXGW WenKai Mono TC（等寬、視覺風格一致） */
    font-family: 'LXGW WenKai Mono TC', ui-monospace, SFMono-Regular, Menlo,
                 Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;
    line-height: 1.7; /* 稍微緊密的行距 */
    font-size: 17px; /* 舒適的閱讀字型大小 */
    letter-spacing: 0.03em; /* 稍微緊密的字距 */
    
    /* 實現左右對齊的書本效果，並處理斷詞 */
    text-align: justify;
    -webkit-hyphens: auto; /* for Safari */
    -ms-hyphens: auto;     /* for IE/Edge */
    hyphens: auto;         /* 標準語法 */
    
    /* 語言必須被指定，斷詞才能生效 */
    lang: zh-TW;
    
    /* 改善中文排版的細節 */
    word-wrap: break-word;
    overflow-wrap: break-word;
    text-rendering: optimizeLegibility;
    
    /* 平滑字體渲染 */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* 處理段落，解決黏滯感 */
.content-wrapper p {
    margin-top: 0;
    margin-bottom: 0.75em; /* 調整：段落間距 0.75em */
    text-indent: 2em; /* 中文傳統首行縮排 */
}

/* 提高特定容器選擇器權重，確保分頁模式套用 */
#content-wrapper p {
    margin-bottom: 0.75em;
}

/* 標題樣式 */
.content-wrapper h1,
.content-wrapper h2,
.content-wrapper h3,
.content-wrapper h4,
.content-wrapper h5,
.content-wrapper h6 {
    margin-top: 2em;
    margin-bottom: 1em;
    line-height: 1.3;
    text-align: center; /* 章節標題置中 */
    text-indent: 0; /* 標題不縮排 */
    font-weight: 600;
}

.content-wrapper h1 {
    font-size: 1.8em;
    margin-top: 1em;
    margin-bottom: 1.5em;
}

.content-wrapper h2 {
    font-size: 1.5em;
}

.content-wrapper h3 {
    font-size: 1.3em;
}

/* 引言區塊樣式 */
.content-wrapper blockquote {
    margin: 2em 0;
    padding: 1em 2em;
    border-left: 3px solid var(--bs-primary, #007bff);
    background-color: rgba(0, 0, 0, 0.02);
    font-style: italic;
    position: relative;
}

.content-wrapper blockquote p {
    text-indent: 0; /* 引言不縮排 */
    margin-bottom: 0;
}

/* 列表樣式重設（因為我們重設了所有樣式） */
.content-wrapper ul,
.content-wrapper ol {
    margin: 1em 0;
    padding-left: 2em;
}

.content-wrapper ul {
    list-style-type: disc;
}

.content-wrapper ol {
    list-style-type: decimal;
}

.content-wrapper li {
    margin-bottom: 0.5em;
    text-indent: 0; /* 列表項目不縮排 */
}

/* 強調文字樣式 */
.content-wrapper strong,
.content-wrapper b {
    font-weight: 700;
}

.content-wrapper em,
.content-wrapper i {
    font-style: italic;
}

/* 代碼區塊樣式 */
.content-wrapper code {
    font-family: 'Courier New', 'Consolas', monospace;
    background-color: rgba(0, 0, 0, 0.05);
    padding: 0.2em 0.4em;
    border-radius: 3px;
    font-size: 0.9em;
}

.content-wrapper pre {
    background-color: rgba(0, 0, 0, 0.05);
    padding: 1em;
    border-radius: 5px;
    overflow-x: auto;
    margin: 1em 0;
}

.content-wrapper pre code {
    background: none;
    padding: 0;
    font-size: 0.85em;
}

/* 分隔線樣式 */
.content-wrapper hr {
    border: none;
    height: 1px;
    background: linear-gradient(to right, transparent, rgba(0, 0, 0, 0.2), transparent);
    margin: 3em 0;
}

/* 暗色主題適配 */
[data-bs-theme="dark"] .content-wrapper blockquote {
    background-color: rgba(255, 255, 255, 0.05);
    border-left-color: var(--bs-primary, #0d6efd);
}

[data-bs-theme="dark"] .content-wrapper code {
    background-color: rgba(255, 255, 255, 0.1);
}

[data-bs-theme="dark"] .content-wrapper pre {
    background-color: rgba(255, 255, 255, 0.05);
}

[data-bs-theme="dark"] .content-wrapper hr {
    background: linear-gradient(to right, transparent, rgba(255, 255, 255, 0.3), transparent);
}

/* ========================================================================
   End of 核心閱讀排版樣式 - Phase 1.2 Complete
   ======================================================================== */

/* ========================================================================
   CSS 多欄式分頁核心實現 - Phase 2.2 分頁模式修改計畫
   目標：利用CSS Column實現自動、無誤的分頁，解決內容溢出和空白頁問題
   ======================================================================== */

/* 故事展示容器 - 支援雙模式切換 */
.story-display-container {
    position: relative;
    display: flex;
    flex-direction: column;
    /* 使用彈性高度避免壓出父容器，使右側滾動能拉到底 */
    flex: 1 1 auto;
    height: auto;
    min-height: 0; /* 重要：讓flex子元素能夠縮小 */
}

/* 外層容器：定義閱讀器的可視範圍 */
.reader-container {
    /* 尺寸必須固定！這是讓內容自動分頁的前提 */
    width: 100%;
    height: 100%;
    min-height: 500px; /* 設定最小高度防止計算錯誤 */
    
    overflow: hidden; /* 關鍵：隱藏垂直滾動條，水平滾動由內容容器控制 */
    box-sizing: border-box;
    padding: 0 2rem; /* 在螢幕左右留出安全邊距 */
    
    /* 建立相對定位上下文 */
    position: relative;
    display: flex;
    flex-direction: column;
}

/* 內容包裝器：真正實現分頁的地方 */
#content-wrapper, #sharedContentWrapper {
    /* 為底部分頁控制及與下緣保持距離預留空間 */
    height: calc(100% - 72px); /* 52px 控制列 + 20px 底部間距 */
    display: flex;
    flex-direction: row;
    align-items: stretch;
    gap: 0;

    /* 水平滾動 + 對齊每頁 */
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    scroll-behavior: smooth;

    /* 隱藏滾動條但保持滾動功能 */
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE and Edge */
    contain: layout style;
}

/* 隱藏 WebKit 瀏覽器的滾動條 */
#content-wrapper::-webkit-scrollbar, #sharedContentWrapper::-webkit-scrollbar { display: none; }

/* 單頁樣式 */
#content-wrapper .page, #sharedContentWrapper .page {
    flex: 0 0 100%;
    height: 100%;
    scroll-snap-align: start;
    scroll-snap-stop: always;
    overflow: hidden; /* 內層處理垂直滾動 */
    padding: 0 14px; /* 加大內側距離，避免右側吃字 */
    box-sizing: border-box;
}

#content-wrapper .page-inner, #sharedContentWrapper .page-inner {
    height: 100%;
    overflow-y: auto; /* 單頁超出時獨立垂直滾動（保底） */
    padding-right: 10px; /* 增加安全邊界，避免右側遮擋 */
    white-space: pre-wrap;
    box-sizing: border-box;
}

/* --- Shared stories: prevent right-edge clipping more aggressively --- */
#sharedContentWrapper { 
    /* 為水平捲動分頁保留邊界，避免右側吃字 */
    scroll-padding-left: 24px;
    scroll-padding-right: calc(24px + var(--shared-sb-width, 0px));
    /* 在支援的瀏覽器中穩定保留捲軸空間，避免版面跳動/遮擋 */
    scrollbar-gutter: stable both-edges;
}
#sharedContentWrapper .page { padding: 0 24px; }
#sharedContentWrapper .page-inner {
    padding-right: calc(24px + var(--shared-sb-width, 0px));
}

/* 分頁控制按鈕容器 */
.pagination-controls {
    position: absolute;
    bottom: 20px; /* 再上調，與下緣保持更大距離 */
    left: 0;
    right: 0;
    height: 52px; /* 再縮小控制列高度 */
    
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    
    background: var(--bs-body-bg);
    border-top: 1px solid var(--bs-border-color);
    padding: 0 2rem;
    
    /* 確保控制條在最上層 */
    z-index: 10;
}

.pagination-controls .page-anim-toggle {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
}
.pagination-controls .page-anim-toggle .form-check-input {
    transform: scale(0.85);
    transform-origin: center right;
}
.pagination-controls .page-anim-toggle .form-check-label {
    font-size: 0.8rem;
}

/* 分頁按鈕樣式 */
.pagination-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    
    transition: all 0.2s ease;
    border-width: 2px;
}

.pagination-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.pagination-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

.pagination-btn i {
    font-size: 0.95rem;
}

/* 頁碼指示器 */
.page-indicator {
    font-size: 0.8rem;
    color: var(--bs-secondary);
    font-weight: 500;
    white-space: nowrap;
    
    /* 數字使用等寬字體，避免跳動 */
    font-variant-numeric: tabular-nums;
}

#currentPageNum, #totalPagesNum {
    font-weight: 600;
    color: var(--bs-primary);
}

/* 響應式調整 */
@media (max-width: 768px) {
    .reader-container {
        padding: 0 1rem;
    }
    
    #content-wrapper {
        column-gap: 2rem;
    }
    
    .pagination-controls {
        padding: 0 1rem;
        height: 48px; /* 行動裝置更小高度 */
        bottom: 12px;  /* 與下緣保持距離 */
    }
    
    #content-wrapper {
        height: calc(100% - 60px); /* 48px + 12px */
    }
    
    .pagination-btn {
        width: 40px;
        height: 40px;
    }
    
    .pagination-btn i {
        font-size: 1rem;
    }
    
    .page-indicator { font-size: 0.78rem; }
}

/* 超小螢幕調整 */
@media (max-width: 480px) {
    .reader-container {
        padding: 0 0.5rem;
    }
    
    #content-wrapper {
        column-gap: 1.5rem;
    }
    
    .pagination-controls {
        gap: 0.5rem;
        padding: 0 0.5rem;
    }
}

/* 暗色主題適配 */
[data-bs-theme="dark"] .pagination-controls {
    background: var(--bs-dark);
    border-top-color: var(--bs-border-color);
}

[data-bs-theme="dark"] .pagination-btn:hover:not(:disabled) {
    box-shadow: 0 4px 12px rgba(255, 255, 255, 0.1);
}

/* 內容載入狀態 */
.content-wrapper.loading {
    opacity: 0.6;
    pointer-events: none;
}

.content-wrapper.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 2rem;
    height: 2rem;
    border: 2px solid var(--bs-border-color);
    border-top: 2px solid var(--bs-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: translate(-50%, -50%) rotate(0deg); }
    100% { transform: translate(-50%, -50%) rotate(360deg); }
}

/* ========================================================================
   End of CSS 多欄式分頁核心實現 - Phase 2.2 Complete
   ======================================================================== */

/* 章節結尾繼續提示（浮動小窗） */
.continue-prompt {
    position: fixed;
    left: 50%;
    bottom: calc(96px + env(safe-area-inset-bottom, 0px));
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: rgba(33, 37, 41, 0.95); /* bootstrap dark */
    color: #fff;
    border-radius: 10px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
    z-index: 2000;
}

.continue-prompt p {
    margin: 0;
}

.continue-prompt .btn-close {
    filter: invert(1);
}

[data-bs-theme="dark"] .continue-prompt {
    background: rgba(52, 58, 64, 0.95);
}

/* 手機與小視窗時再往上移，避免遮到下方內容或控制列 */
@media (max-width: 768px) {
  .continue-prompt {
    bottom: calc(112px + env(safe-area-inset-bottom, 0px));
  }
}

/* Chapter Navigation Tabs */
.chapter-tabs-container {
    max-width: 100%;
    overflow: hidden;
    border-top: 1px solid #dee2e6;
    padding-top: 0.5rem;
}

.chapter-tabs-wrapper {
    position: relative;
    overflow: hidden;
}

.chapter-tabs {
    display: flex;
    gap: 0.5rem;
    padding: 0.25rem 0;
    overflow-x: auto;
    scroll-behavior: smooth;
    /* 隱藏滾動條但保持滑動功能 */
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE and Edge */
}

/* 隱藏 WebKit 瀏覽器的滾動條 */
.chapter-tabs::-webkit-scrollbar {
    display: none;
}

.chapter-tab {
    flex: 0 0 auto;
    padding: 0.375rem 0.75rem;
    background-color: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 0.375rem;
    color: #6c757d;
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    white-space: nowrap;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
}

.chapter-tab:hover {
    background-color: #e9ecef;
    border-color: #adb5bd;
    color: #495057;
    transform: translateY(-1px);
}

.chapter-tab.active {
    background-color: #007bff;
    border-color: #007bff;
    color: white;
    box-shadow: 0 2px 4px rgba(0, 123, 255, 0.25);
}

.chapter-tab.active:hover {
    background-color: #0056b3;
    border-color: #0056b3;
    transform: translateY(-1px);
}

/* Dark theme adjustments */
[data-bs-theme="dark"] .chapter-tabs-container {
    border-top-color: #495057;
}

[data-bs-theme="dark"] .chapter-tab {
    background-color: #343a40;
    border-color: #495057;
    color: #adb5bd;
}

[data-bs-theme="dark"] .chapter-tab:hover {
    background-color: #495057;
    border-color: #6c757d;
    color: #f8f9fa;
}

[data-bs-theme="dark"] .chapter-tab.active {
    background-color: #0d6efd;
    border-color: #0d6efd;
    color: white;
    box-shadow: 0 2px 4px rgba(13, 110, 253, 0.25);
}

[data-bs-theme="dark"] .chapter-tab.active:hover {
    background-color: #0b5ed7;
    border-color: #0b5ed7;
}

/* Mobile responsive adjustments */
@media (max-width: 768px) {
    .chapter-tabs {
        gap: 0.25rem;
        padding: 0.125rem 0;
    }
    
    .chapter-tab {
        padding: 0.25rem 0.5rem;
        font-size: 0.75rem;
    }
}

/* Chapter Planning Modal Styles */
.chapter-planning-list {
    max-height: 400px;
    overflow-y: auto;
    border: 1px solid var(--bs-border-color);
    border-radius: 0.375rem;
    padding: 1rem;
}

.chapter-planning-item {
    border: 1px solid var(--bs-border-color);
    border-radius: 0.375rem;
    padding: 1rem;
    margin-bottom: 1rem;
    background-color: var(--bs-body-bg);
    transition: all 0.2s ease;
}

.chapter-planning-item:hover {
    border-color: var(--bs-primary);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.chapter-planning-item:last-child {
    margin-bottom: 0;
}

.chapter-planning-item .chapter-number {
    font-weight: 600;
    color: var(--bs-primary);
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
}

.chapter-planning-item .chapter-title {
    font-weight: 500;
    margin-bottom: 0.75rem;
    color: var(--bs-body-color);
}

.chapter-planning-item .chapter-description {
    color: var(--bs-secondary);
    font-size: 0.875rem;
    line-height: 1.5;
    margin-bottom: 0.75rem;
}

.chapter-planning-item .chapter-opinion {
    border-top: 1px solid var(--bs-border-color-translucent);
    padding-top: 0.75rem;
    margin-top: 0.75rem;
}

.chapter-planning-item .chapter-opinion label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--bs-secondary);
    margin-bottom: 0.25rem;
}

.chapter-planning-item .chapter-opinion textarea {
    font-size: 0.875rem;
    border: 1px solid var(--bs-border-color-translucent);
    border-radius: 0.25rem;
    padding: 0.5rem;
    resize: vertical;
    min-height: 60px;
}

.chapter-planning-item .chapter-opinion textarea:focus {
    border-color: var(--bs-primary);
    box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.15);
}

/* Mobile responsive styles for chapter planning modal */
@media (max-width: 767.98px) {
    /* Make modal full screen on mobile */
    .modal-xl {
        max-width: 100%;
        margin: 0;
    }
    
    .modal-xl .modal-content {
        height: 100vh;
        border-radius: 0;
        border: none;
    }
    
    .modal-xl .modal-body {
        padding: 1rem 0.75rem;
        overflow-y: auto;
        flex: 1;
    }
    
    .modal-xl .modal-header {
        padding: 0.75rem;
        border-bottom: 1px solid var(--bs-border-color);
        flex-shrink: 0;
    }
    
    .modal-xl .modal-footer {
        padding: 0.75rem;
        border-top: 1px solid var(--bs-border-color);
        flex-shrink: 0;
    }
    
    /* Adjust chapter planning list for mobile */
    .chapter-planning-list {
        max-height: none;
        border: none;
        padding: 0.5rem;
        border-radius: 0;
    }
    
    .chapter-planning-item {
        padding: 0.75rem;
        margin-bottom: 0.75rem;
        border-radius: 0.5rem;
    }
    
    .chapter-planning-item .chapter-number {
        font-size: 1rem;
        margin-bottom: 0.75rem;
        text-align: center;
        background-color: var(--bs-primary);
        color: white;
        padding: 0.25rem 0.5rem;
        border-radius: 0.25rem;
        display: inline-block;
    }
    
    /* Mobile form adjustments */
    .chapter-planning-item .form-label {
        font-size: 0.875rem;
        font-weight: 600;
        margin-bottom: 0.5rem;
    }
    
    .chapter-planning-item .form-control {
        font-size: 16px; /* Prevent zoom on iOS */
        padding: 0.75rem;
        border-radius: 0.5rem;
    }
    
    .chapter-planning-item textarea.form-control {
        min-height: 80px;
        resize: vertical;
    }
    
    .chapter-planning-item .form-text {
        font-size: 0.75rem;
        margin-top: 0.25rem;
    }
    
    /* Chapter count input section mobile styles */
    .row.mb-4 {
        margin-bottom: 1.5rem !important;
    }
    
    .row.mb-4 .col-md-6 {
        padding: 0 0.75rem;
    }
    
    #chapterCountInput {
        font-size: 16px; /* Prevent zoom on iOS */
        padding: 0.75rem;
        border-radius: 0.5rem;
    }
    
    #generateChapterPlanBtn {
        padding: 0.75rem 1rem;
        border-radius: 0.5rem;
        font-weight: 600;
    }
    
    /* Save button mobile styles */
    #saveChapterPlanBtn {
        padding: 0.75rem 1.5rem;
        border-radius: 0.5rem;
        font-weight: 600;
    }
    
    /* Empty state mobile styles */
    #chapterPlanningEmptyState {
        padding: 2rem 1rem !important;
    }
    
    #chapterPlanningEmptyState i {
        font-size: 2.5rem !important;
    }
    
    #chapterPlanningEmptyState h6 {
        font-size: 1.1rem;
        margin-top: 1rem !important;
    }
    
    #chapterPlanningEmptyState p {
        font-size: 0.9rem;
        line-height: 1.4;
    }
}

/* Tablet responsive styles for chapter planning */
@media (min-width: 768px) and (max-width: 991.98px) {
    .modal-xl {
        max-width: 95%;
    }
    
    .chapter-planning-list {
        max-height: 500px;
        padding: 1.25rem;
    }
    
    .chapter-planning-item {
        padding: 1.25rem;
    }
    
    .chapter-planning-item .form-control {
        font-size: 0.9rem;
    }
}

/* Touch-friendly improvements for mobile */
@media (max-width: 767.98px) {
    /* Larger touch targets */
    .chapter-planning-item .form-control:focus {
        border-width: 2px;
        border-color: var(--bs-primary);
        box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.15);
    }
    
    /* Better spacing for touch interaction */
    .chapter-planning-item .mb-3 {
        margin-bottom: 1.5rem !important;
    }
    
    /* Improved button styling for mobile */
    .btn {
        min-height: 44px; /* iOS recommended minimum touch target */
        border-radius: 0.5rem;
    }
    
    .btn-sm {
        min-height: 38px;
        padding: 0.5rem 1rem;
    }
    
    /* Modal close button mobile optimization */
    .modal-header .btn-close {
        padding: 1rem;
        margin: -1rem -1rem -1rem auto;
    }
}

/* Dark mode adjustments for chapter planning */
[data-bs-theme="dark"] .chapter-planning-list {
    border-color: var(--bs-border-color);
    background-color: var(--bs-dark);
}

[data-bs-theme="dark"] .chapter-planning-item {
    background-color: var(--bs-dark);
    border-color: var(--bs-border-color);
}

[data-bs-theme="dark"] .chapter-planning-item:hover {
    border-color: var(--bs-primary);
    box-shadow: 0 2px 4px rgba(255,255,255,0.1);
}

[data-bs-theme="dark"] .chapter-planning-item .chapter-opinion {
    border-top-color: var(--bs-border-color);
}

[data-bs-theme="dark"] .chapter-planning-item .chapter-opinion textarea {
    background-color: var(--bs-dark);
    border-color: var(--bs-border-color);
    color: var(--bs-body-color);
}

[data-bs-theme="dark"] .chapter-planning-item .chapter-opinion textarea:focus {
    border-color: var(--bs-primary);
    box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.15);
}

/* Loading state for chapter planning button */
#chapterPlanningBtn.has-planning {
    background-color: var(--bs-success);
    border-color: var(--bs-success);
    color: white;
}

#chapterPlanningBtn.has-planning:hover {
    background-color: var(--bs-success);
    border-color: var(--bs-success);
    opacity: 0.9;
}

/* Loading states and progress indicators */
.loading-state {
    position: relative;
    overflow: hidden;
}

.loading-state::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
    animation: loading-shimmer 1.5s infinite;
}

@keyframes loading-shimmer {
    0% { left: -100%; }
    100% { left: 100%; }
}

.progress-indicator {
    position: relative;
    background-color: var(--bs-light);
    border-radius: 0.25rem;
    overflow: hidden;
    height: 4px;
    margin: 0.5rem 0;
}

.progress-indicator .progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--bs-primary), var(--bs-info));
    border-radius: 0.25rem;
    transition: width 0.3s ease;
    animation: progress-pulse 2s infinite;
}

@keyframes progress-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.status-indicator {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--bs-secondary);
    margin-top: 0.5rem;
}

.status-indicator .spinner-border {
    width: 1rem;
    height: 1rem;
    border-width: 0.125rem;
}

.status-indicator.success {
    color: var(--bs-success);
}

.status-indicator.error {
    color: var(--bs-danger);
}

.status-indicator.warning {
    color: var(--bs-warning);
}

/* Enhanced button loading states */
.btn.loading {
    position: relative;
    pointer-events: none;
}

.btn.loading .btn-text {
    opacity: 0.7;
}

.btn.loading .spinner-border {
    margin-left: 0.5rem;
}

/* Chapter planning specific loading states */
.chapter-planning-generating {
    opacity: 0.7;
    pointer-events: none;
}

.chapter-planning-generating .chapter-planning-item {
    background: linear-gradient(90deg, #f8f9fa 25%, #e9ecef 50%, #f8f9fa 75%);
    background-size: 200% 100%;
    animation: loading-skeleton 1.5s infinite;
}

@keyframes loading-skeleton {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.save-status {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.75rem;
    font-weight: 500;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.save-status.show {
    opacity: 1;
}

.save-status.saving {
    background-color: var(--bs-warning);
    color: var(--bs-dark);
}

.save-status.saved {
    background-color: var(--bs-success);
    color: white;
}

.save-status.error {
    background-color: var(--bs-danger);
    color: white;
}

/* Dark mode adjustments for loading states */
[data-bs-theme="dark"] .loading-state::after {
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.1), transparent);
}

[data-bs-theme="dark"] .progress-indicator {
    background-color: var(--bs-dark);
}

[data-bs-theme="dark"] .chapter-planning-generating .chapter-planning-item {
    background: linear-gradient(90deg, #343a40 25%, #495057 50%, #343a40 75%);
    background-size: 200% 100%;
}

/* Chapter count input validation styles */
#chapterCountInput.is-invalid {
    border-color: var(--bs-danger);
}

#chapterCountInput.is-invalid:focus {
    border-color: var(--bs-danger);
    box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.25);
}

/* General Body Styling */
body {
    font-family: 'LXGW WenKai Mono TC', sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

[data-bs-theme="light"] body {
    background-color: #f8f9fa;
}

[data-bs-theme="dark"] body {
    background-color: #212529;
}

/* Main container adjustments */
.main-container {
    padding-top: 1rem;
    padding-bottom: 1rem;
    /* 使用新視窗單位避免瀏覽器網址列/系統列造成 100vh 計算誤差 */
    height: 100vh;
    height: 100dvh; /* 支援的瀏覽器以 100dvh 為準 */
    max-height: 100vh;
    max-height: 100dvh;
}

/* New resizable row container */
.resizable-row {
    display: flex;
    /* 高度 = 視窗高度 - 上下內距 */
    height: calc(100vh - 2rem);
    height: calc(100dvh - 2rem);
    flex-direction: row !important;
}

.panel-col {
    height: 100%;
    min-width: 200px; /* Minimum width for panels */
    padding: 0 !important; /* Override Bootstrap padding */
    display: flex; /* Ensure proper flex layout */
    flex-direction: column; /* Stack content vertically */
}

#left-panel {
    flex: 0 0 40%; /* Initial width of left panel */
}

#right-panel {
    flex: 1 1 auto; /* Right panel takes remaining space */
    min-height: 0; /* 允許子元素縮小，避免撐出外層捲動 */
}

#resize-handle {
    flex: 0 0 10px; /* Width of the handle */
    cursor: col-resize;
    background-color: #dee2e6;
    border-left: 1px solid #adb5bd;
    border-right: 1px solid #adb5bd;
}

[data-bs-theme="dark"] #resize-handle {
    background-color: #343a40;
    border-color: #495057;
}

.card {
    height: 100%;
    border: none; /* Remove card border */
    border-radius: 0; /* Remove card radius */
    display: flex; /* Ensure card is flexbox */
    flex-direction: column; /* Stack content vertically */
}

.panel-col .card-body {
    overflow-y: auto;
    padding: 1rem; /* Add padding back inside */
    height: 100%; /* Fill available height of card */
    min-height: 0; /* 防止子元素撐高 */
}

/* 右側卡片避免外層與內層雙重滾動，交給內層內容控滾動 */
#right-panel .card-body {
    overflow: hidden;
}

.card-body textarea {
    resize: vertical;
}

#storyDisplay {
    white-space: pre-wrap;
    resize: none;
    height: 100%; /* 確保textarea填滿容器 */
    flex: 1; /* 讓textarea在flex容器中佔據剩餘空間 */
    /* font-size controlled by JavaScript */
}

/* 分頁模式：隱藏滾動條 */
#storyDisplay.paginated-mode {
    overflow-y: hidden;
}

/* 連續模式：允許滾動 */
#storyDisplay.continuous-mode {
    overflow-y: auto;
    /* 避免最後一兩行被底部遮擋：預留兩行的安全距離 */
    padding-bottom: 3em;
    scroll-padding-bottom: 3em;
}

/* Enhanced Loading Spinner Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1050;
    backdrop-filter: blur(2px);
}

.loading-content {
    text-align: center;
    max-width: 300px;
    padding: 2rem;
    background: rgba(0, 0, 0, 0.8);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.loading-text h5 {
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.loading-text p {
    font-size: 0.9rem;
    opacity: 0.8;
    margin-bottom: 1rem;
}

.loading-progress {
    margin-top: 1rem;
}

.progress-dots {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
}

.progress-dots span {
    width: 8px;
    height: 8px;
    background-color: #ffffff;
    border-radius: 50%;
    animation: pulse-dots 1.5s infinite ease-in-out;
}

.progress-dots span:nth-child(1) {
    animation-delay: 0s;
}

.progress-dots span:nth-child(2) {
    animation-delay: 0.3s;
}

.progress-dots span:nth-child(3) {
    animation-delay: 0.6s;
}

@keyframes pulse-dots {
    0%, 60%, 100% {
        opacity: 0.3;
        transform: scale(1);
    }
    30% {
        opacity: 1;
        transform: scale(1.2);
    }
}

/* Custom button styling for better aesthetics */
.btn-outline-secondary, .btn-outline-success, .btn-outline-info, .btn-outline-warning, .btn-outline-primary, .btn-outline-dark {
    border-width: 1.5px;
    font-weight: 500;
    transition: all 0.2s ease-in-out;
}

/* Button loading state */
.btn-loading {
    position: relative;
    pointer-events: none;
}

.btn-loading:disabled {
    opacity: 0.8;
}

.btn-loading .spinner-border-sm {
    width: 1rem;
    height: 1rem;
    border-width: 0.125em;
}

.btn-outline-secondary:hover, .btn-outline-success:hover, .btn-outline-info:hover, .btn-outline-warning:hover, .btn-outline-primary:hover, .btn-outline-dark:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

/* Fix dark mode button colors */
[data-bs-theme="dark"] .btn-outline-dark {
    border-color: #adb5bd;
    color: #adb5bd;
}

[data-bs-theme="dark"] .btn-outline-dark:hover {
    background-color: #adb5bd;
    border-color: #adb5bd;
    color: #212529;
}

/* Theme switcher button enhancement */
#theme-switcher {
    border-radius: 6px;
    padding: 6px 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

#theme-switcher:hover {
    transform: scale(1.1);
    transition: all 0.2s ease-in-out;
}

#theme-switcher i {
    transition: all 0.3s ease-in-out;
}

/* Bottom Reader Opinion Input (ChatGPT Style) */
.reader-opinion-bottom {
    margin-top: 1rem;
    padding: 1rem;
    border-top: 1px solid var(--bs-border-color);
    background: var(--bs-body-bg);
}

.opinion-input-container {
    max-width: 100%;
}

.opinion-textarea {
    resize: none;
    border-radius: 12px !important;
    border: 1px solid var(--bs-border-color);
    padding: 12px 16px;
    font-size: 14px;
    line-height: 1.4;
    transition: all 0.2s ease;
    min-height: 44px;
    max-height: 120px;
    overflow-y: hidden;
}

.opinion-textarea:focus {
    border-color: var(--bs-primary);
    box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.15);
}

.opinion-send-btn {
    border-radius: 12px !important;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: 8px;
    transition: all 0.2s ease;
}

.opinion-send-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(13, 110, 253, 0.3);
}

.opinion-send-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.opinion-suggestions {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--bs-border-color-translucent);
}

.suggestion-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.suggestion-btn {
    border-radius: 20px;
    padding: 4px 12px;
    font-size: 12px;
    transition: all 0.2s ease;
}

.suggestion-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* Dark mode adjustments */
[data-bs-theme="dark"] .reader-opinion-bottom {
    border-top-color: var(--bs-border-color);
}

[data-bs-theme="dark"] .opinion-textarea {
    background-color: var(--bs-dark);
    border-color: var(--bs-border-color);
    color: var(--bs-body-color);
}

[data-bs-theme="dark"] .opinion-textarea:focus {
    border-color: var(--bs-primary);
    box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.25);
}

/* Reading Progress Bar */
.reading-progress-container {
    padding: 0 1rem;
    margin-bottom: 0.5rem;
}

.reading-progress-bar {
    height: 3px;
    background-color: var(--bs-border-color-translucent);
    border-radius: 2px;
    overflow: hidden;
}

.reading-progress-bar .progress-bar {
    background: linear-gradient(90deg, var(--bs-primary), var(--bs-success));
    transition: width 0.3s ease;
    height: 100%;
}

/* Dark mode progress bar */
[data-bs-theme="dark"] .reading-progress-bar {
    background-color: var(--bs-border-color);
}

/* Mobile sidebar styles */
.mobile-menu-btn {
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 1060;
    background: var(--bs-primary);
    color: white;
    border: none;
    border-radius: 8px;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    transition: all 0.3s ease;
}

.mobile-menu-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.mobile-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1040;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.mobile-overlay.show {
    opacity: 1;
    visibility: visible;
}

.mobile-sidebar {
    position: fixed;
    top: 0;
    left: -100%;
    width: 85%;
    max-width: 350px;
    height: 100vh;
    z-index: 1045;
    transition: left 0.3s ease;
    background: var(--bs-body-bg);
    box-shadow: 2px 0 10px rgba(0,0,0,0.1);
}

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

.mobile-sidebar .card {
    border: none;
    border-radius: 0;
    height: 100vh;
}

.mobile-close-btn {
    position: absolute;
    top: 1rem;
    right: 1rem;
    z-index: 1046;
    background: transparent;
    border: none;
    color: var(--bs-secondary);
    font-size: 18px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
}

.mobile-close-btn:hover {
    background: var(--bs-light);
    color: var(--bs-dark);
}

/* Responsive adjustments - Mobile first approach */
@media (max-width: 767.98px) {
    .resizable-row {
        flex-direction: row;
        height: 100vh;
        max-height: 100vh;
    }
    
    #right-panel {
        flex: 1;
        width: 100%;
        height: 100vh;
    }
    
    #right-panel .card-body {
        padding: 0.5rem;
        display: flex;
        flex-direction: column;
        height: 100vh;
        min-height: 100vh;
    }
    
    #right-panel .d-flex.justify-content-between {
        padding: 0.5rem;
        margin-bottom: 0.5rem !important;
        flex-shrink: 0;
    }
    
    .reading-progress-container {
        flex-shrink: 0;
    }
    
    #storyDisplay {
        border: none !important;
        border-radius: 0 !important;
        /* 移除固定行高，讓系統根據字型大小自動調整 */
        line-height: normal !important;
        padding: 1rem !important;
        flex: 1;
        min-height: 0;
        resize: none;
        /* 為大字型預留更多空間 */
        word-wrap: break-word;
        overflow-wrap: break-word;
    }
    
    /* 響應式模式下的滾動控制 */
    #storyDisplay.paginated-mode {
        overflow-y: hidden !important;
    }
    
    #storyDisplay.continuous-mode {
        overflow-y: auto !important;
    }
    
    .reader-opinion-bottom {
        flex-shrink: 0;
    }
    
    #resize-handle {
        display: none;
    }
    
    .main-container {
        padding: 0;
        height: 100vh;
        max-height: 100vh;
        /* 為手機版底部提供安全邊距 */
        padding-bottom: env(safe-area-inset-bottom);
    }
    
    /* Mobile styles for bottom opinion input */
    .reader-opinion-bottom {
        padding: 0.75rem !important;
        margin-top: 0 !important;
        /* 確保底部有足夠空間顯示建議按鈕 */
        padding-bottom: 1rem !important;
        min-height: auto;
    }
    
    .opinion-textarea {
        font-size: 16px !important;
        border-radius: 8px !important;
        padding: 10px 14px !important;
    }
    
    .opinion-send-btn {
        width: 40px !important;
        height: 40px !important;
        border-radius: 8px !important;
    }
    
    .suggestion-buttons {
        gap: 0.25rem !important;
    }
    
    .suggestion-btn {
        font-size: 11px !important;
        padding: 3px 8px !important;
    }
    
    /* 確保建議區域有足夠空間顯示 */
    .opinion-suggestions {
        margin-top: 0.75rem !important;
        padding-top: 0.75rem !important;
        padding-bottom: 0.5rem !important;
        /* 確保建議按鈕不會被裁切 */
        overflow: visible !important;
    }
    
    .suggestion-buttons {
        flex-wrap: wrap !important;
        gap: 0.25rem !important;
        /* 確保按鈕有足夠的垂直空間 */
        margin-bottom: 0.25rem !important;
    }
    
    /* 為極大字型提供額外的行間距調整 */
    #storyDisplay[style*="font-size: 2"][style*="px"],
    #storyDisplay[style*="font-size: 3"][style*="px"] {
        line-height: 1.4 !important;
    }
}

/* Force horizontal layout for desktop and tablet */
@media (min-width: 768px) {
    .resizable-row {
        flex-direction: row !important;
        height: calc(100vh - 2rem) !important;
        max-height: calc(100vh - 2rem) !important;
    }
    
    .panel-col {
        min-width: 200px !important;
        height: 100% !important;
        margin-bottom: 0 !important;
    }
    
    #resize-handle {
        display: block !important;
    }
    
    .mobile-sidebar {
        position: static !important;
        width: auto !important;
        max-width: none !important;  
        left: auto !important;
        box-shadow: none !important;
        display: block !important; /* Force show on desktop */
    }
    
    #left-panel {
        display: block !important; /* Force show left panel on desktop */
    }
    
    .mobile-menu-btn {
        display: none !important;
    }
    
    .mobile-overlay {
        display: none !important;
    }
}

/* ========================================================================
   Shared Stories Page Styles
   ======================================================================== */

/* Shared story list item spacing fix */
.shared-story-item {
    margin-bottom: 0.25rem !important; /* Maximum density for better viewing */
}

.shared-story-item:last-child {
    margin-bottom: 0 !important;
}

/* Shared stories list container */
.shared-stories-list {
    overflow-y: auto;
    max-height: calc(100vh - 200px);
}

/* Shared stories specific textarea styling */
#sharedStoryDisplay {
    white-space: pre-wrap;
    resize: none;
    height: 100%;
    flex: 1;
}

/* Shared stories paginated mode */
#sharedStoryDisplay.paginated-mode {
    overflow-y: hidden;
}

/* Shared stories continuous mode */
#sharedStoryDisplay.continuous-mode {
    overflow-y: auto;
    /* 與創作區一致，預留底部安全距離，避免最後一兩行被遮擋 */
    padding-bottom: 3em;
    scroll-padding-bottom: 3em;
}

/* Ensure left-right layout for shared stories page on desktop */
.resizable-row {
    display: flex !important;
    flex-direction: row !important;
    width: 100% !important;
    height: calc(100vh - 2rem) !important;
}

#left-panel {
    flex: 0 0 40% !important;
    display: block !important;
    min-width: 300px !important;
    max-width: 50% !important;
}

#right-panel {
    flex: 1 1 auto !important;
    display: block !important;
    min-width: 0 !important;
}

/* Prevent layout issues in shared stories */
body .main-container .resizable-row {
    flex-wrap: nowrap !important;
}

/* Ensure panels have proper height */
.panel-col {
    height: 100% !important;
    display: flex !important;
    flex-direction: column !important;
}

.panel-col .card {
    flex: 1 !important;
    display: flex !important;
    flex-direction: column !important;
}

.panel-col .card-body {
    flex: 1 !important;
    display: flex !important;
    flex-direction: column !important;
}

/* 左側面板需要滾動條 */
#left-panel .card-body {
    overflow-y: auto !important;
    /* 增加底部安全內距，避免最後一行被捲軸或視窗邊緣遮住（加大） */
    padding-bottom: calc(1rem + 28px + env(safe-area-inset-bottom, 0px)) !important;
}

/* 右側面板不需要滾動條（由內部組件控制） */
#right-panel .card-body {
    overflow: hidden !important;
    min-height: 0; /* 與 flex 容器搭配，允許內容縮小 */
}

/* Mobile responsive styles for shared stories page */
@media (max-width: 767.98px) {
    /* Mobile adjustments for shared stories page */
    #sharedStoryDisplay {
        border: none !important;
        border-radius: 0 !important;
        line-height: normal !important;
        padding: 1rem !important;
        flex: 1;
        min-height: 0;
        resize: none;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }
    
    #sharedStoryDisplay.paginated-mode {
        overflow-y: hidden !important;
    }
    
    #sharedStoryDisplay.continuous-mode {
        overflow-y: auto !important;
    }
    
    /* Shared stories mobile sidebar */
    .mobile-sidebar {
        position: fixed;
        top: 0;
        left: -100%;
        width: 80%;
        max-width: 300px;
        height: 100vh;
        background: white;
        z-index: 1040;
        transition: left 0.3s ease;
        overflow-y: auto;
    }
    
    .mobile-sidebar.show {
        left: 0;
    }
    
    .mobile-sidebar .card {
        height: 100vh;
        border: none;
        border-radius: 0;
    }
    
    /* Mobile specific panel adjustments */
    
    #right-panel {
        flex: 1;
        width: 100%;
        height: 100vh;
    }
    
    /* Mobile menu button for shared stories */
    .mobile-menu-btn {
        position: fixed;
        top: 1rem;
        left: 1rem;
        z-index: 1041;
        width: 44px;
        height: 44px;
        border-radius: 50%;
        background: var(--bs-primary);
        color: white;
        border: none;
        display: flex;
        align-items: center;
        justify-content: center;
        box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    }
    
    .mobile-close-btn {
        position: absolute;
        top: 1rem;
        right: 1rem;
        width: 32px;
        height: 32px;
        border-radius: 50%;
        background: transparent;
        border: 1px solid #dee2e6;
        display: flex;
        align-items: center;
        justify-content: center;
        color: #6c757d;
    }
    
    .mobile-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0,0,0,0.5);
        z-index: 1039;
        display: none;
    }
    
    .mobile-overlay.show {
        display: block;
    }
}

/* Ensure chapter planning modal always appears on top */
#chapterPlanningModal.modal {
    z-index: 1060 !important;
}

#chapterPlanningModal .modal-backdrop {
    z-index: 1059 !important;
}

/* Chapter Title Display Input */
.chapter-title-display-input {
    border: none;
    background: transparent;
    font-size: 1.1rem; /* Adjust as needed */
    font-weight: 600; /* Adjust as needed */
    color: var(--bs-body-color); /* Inherit text color */
    padding: 0;
    margin: 0;
    display: inline; /* Keep it inline with chapter number */
    width: auto; /* Allow content to dictate width */
    box-shadow: none; /* Remove any focus box-shadow */
    outline: none; /* Remove outline on focus */
    text-overflow: ellipsis; /* Add ellipsis for long titles */
    white-space: nowrap; /* Prevent wrapping */
    overflow: hidden; /* Hide overflow */
}

.chapter-title-display-input:focus {
    border: 1px solid var(--bs-primary); /* Add a subtle border on focus for editing */
    background-color: var(--bs-body-bg); /* Add a background on focus */
    padding: 0.25rem 0.5rem; /* Add some padding on focus */
    border-radius: 0.25rem;
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}

/* Adjust chapter number to align with title input */
.chapter-planning-item .chapter-number {
    font-weight: 600;
    color: var(--bs-primary);
    font-size: 1.1rem; /* Match title font size */
    margin-bottom: 0; /* Remove bottom margin */
    flex-shrink: 0; /* Prevent shrinking */
}

/* Ensure the flex container works as expected */
.chapter-planning-item .d-flex.align-items-center {
    margin-bottom: 0.5rem; /* Add some space below the title line */
}

/* Points Update Animation */
#user-points-display {
    transition: all 0.5s ease;
}

#user-points-display.points-updated {
    color: #FFD700; /* Gold color */
    transform: scale(1.2);
}
