/* Global Resets and Base Styles */
body {
    background-color: var(--bg-color, #000); /* Default fallback */
    color: var(--text-color, #FFF); /* Default fallback */
    font-family: 'Microsoft YaHei', 'SimSun', sans-serif; /* Common CJK fonts */
    margin: 0;
    padding: 0;
    line-height: 1.7; /* Default line height */
    transition: background-color 0.3s ease, color 0.3s ease; /* Smooth theme transitions */
}

/* Style Variables - defined in :root in reader.php/JS */
:root {
    --bg-color: #000000;
    --text-color: #FFFFFF;
    --font-size: 18px;
    --link-color: #add8e6; /* Light blue for links */
    --link-hover-color: #ffffff;
    --border-color: #555;
    --panel-bg: #333;
    --button-bg: #3a3a3a;
    --button-hover-bg: #555;
    --button-disabled-bg: #2a2a2a;
    --button-disabled-color: #777;
    --progress-bar-color: #4CAF50; /* Green */
    --highlight-color: rgba(76, 175, 80, 0.5);    /* 陰影顏色 */
    --highlight-bg: rgba(76, 175, 80, 0.15);      /* 背景色 */
    --highlight-border: #4CAF50;                  /* 邊框顏色 */
    --highlight-bg-fade: rgba(76, 175, 80, 0.1);  /* 動畫淡色 */
    --highlight-bg-strong: rgba(76, 175, 80, 0.3); /* 動畫深色 */
    --accent-color: #00b4d8;
}

/* Settings Panel */
.settings-panel {
    position: fixed;
    top: 10px;
    right: 10px;
    width: 200px; /* 減小寬度 */
    background: var(--panel-bg);
    border-radius: 8px;
    padding: 10px;
    z-index: 1000;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    display: none; /* 初始隱藏 */
}

.settings-panel.active {
    display: block; /* 當有 active 類時顯示 */
}

.control-container {
    margin-bottom: 6px;
}

.color-controls {
    display: flex;
    justify-content: flex-start; /* 改為靠左對齊 */
    gap: 10px; /* 添加間距 */
    margin-bottom: 6px;
    flex-wrap: wrap; /* 允許換行 */
}

.color-control {
    display: flex;
    align-items: center;
    gap: 4px;
    min-width: 80px; /* 確保有足夠的空間 */
}

.color-control label {
    color: #fff;
    font-size: 13px;
    white-space: nowrap; /* 防止文字換行 */
}

.color-control input[type="color"] {
    width: 35px;
    height: 22px;
    padding: 0;
    border: 1px solid var(--border-color);
    border-radius: 3px;
}

.slider-group {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 4px 0;
}

.slider-group label {
    color: #fff;
    font-size: 13px;
    min-width: 35px;
}

.slider-group input[type="range"] {
    flex: 1;
    height: 4px;
}

.slider-value {
    color: #fff;
    font-size: 13px;
    min-width: 35px;
    text-align: right;
}

.control-divider {
    height: 1px;
    background: var(--border-color);
    margin: 6px 0;
}

.control-button {
    width: 100%;
    padding: 4px 8px;
    background: var(--button-bg);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: #fff;
    cursor: pointer;
    font-size: 13px;
    margin: 3px 0;
}

.control-select {
    width: 100%;
    padding: 4px;
    background: var(--button-bg);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: #fff;
    font-size: 13px;
    margin: 3px 0;
}

.control-label {
    display: flex;
    align-items: center;
    gap: 6px;
    color: #fff;
    font-size: 14px;
    margin: 4px 0;
}

/* Reader Container */
.reader-container {
    max-width: 800px; /* Optimal reading width */
    margin: 30px auto; /* Center container with top/bottom margin */
    padding: 25px 30px; /* Inner padding */
    /* Optional: Slight background contrast if body bg is very dark/light */
    /* background-color: rgba(255, 255, 255, 0.03); */
    /* border-radius: 5px; */
}

.reader-container h1 {
    color: var(--text-color);
    text-align: center;
    margin-bottom: 10px;
    font-size: 1.8em; /* Larger title */
    font-weight: 600;
}

.reader-container h2 {
    color: var(--text-color);
    text-align: center;
    margin-top: 0;
    margin-bottom: 25px;
    font-size: 1.3em; /* Slightly smaller chapter title */
    font-weight: normal;
}

.reader-container h2 .author-tag {
    font-size: 0.8em;
    color: #ccc;
    margin-left: 5px;
}


hr {
    border: 0;
    border-top: 1px solid var(--border-color);
    margin: 30px 0; /* Space around horizontal rules */
}

/* Novel Content Area */
#novel-content {
    font-size: var(--font-size);
    line-height: 1.8;
    color: var(--text-color);
    white-space: pre-line;
    text-align: justify;
    word-wrap: break-word;
    transition: font-size 0.2s ease, color 0.3s ease;
    margin: 0 auto;
    max-width: 800px;
    width: 100%;
    padding: 0;
    position: relative;
    margin-top: 20px;
}

#novel-content h1:first-child,
#novel-content h2:first-child {
    display: none; /* 隱藏內容區域重複的標題 */
}

/* Optional: Add paragraph spacing if using <p> tags or double line breaks */
#novel-content p,
#novel-content br + br { /* Target double line breaks */
     margin-bottom: 1.2em; /* Space between paragraphs */
}
/* Optional: First line indent for paragraphs */
#novel-content p {
    text-indent: 2em;
}
/* Hacky indent for <br> separated paragraphs (less reliable) */
/*
#novel-content::first-line { text-indent: 2em; }
#novel-content br + br::before { content: ''; display: inline-block; width: 2em; }
*/

/* Remove the floating highlight container */
.speech-highlight-container {
    display: none !important;
}

/* Remove default browser styling for <mark> */
mark,
.sentence-mark {
    color: inherit;
    background: none;
    padding: 0;
    margin: 0;
    display: inline;
    position: relative;
    text-align: inherit;
    white-space: pre-line;
    vertical-align: baseline;
}

/* Style for the currently spoken sentence */
.sentence-mark.current-sentence {
    background-color: var(--highlight-bg, rgba(147, 112, 219, 0.25)) !important;
    border: 1px solid var(--highlight-border, rgba(221, 160, 221, 0.7)) !important;
    padding: 2px 4px !important;
    margin: -2px -4px !important;
    border-radius: 3px !important;
    box-shadow: 0 0 8px var(--highlight-color, rgba(221, 160, 221, 0.4)) !important;
    color: var(--text-color) !important;
    display: inline !important;
    position: relative !important;
    text-align: inherit !important;
    white-space: pre-line !important;
    vertical-align: baseline !important;
    scroll-margin-top: calc(50vh - 100px) !important;
    scroll-margin-bottom: calc(50vh - 100px) !important;
}

/* Style for fallback highlight (if direct text search is used) */
.fallback-highlight {
    background-color: rgba(255, 165, 0, 0.3) !important; /* Different color for fallback */
    border: 1px dashed orange !important;
}

/* 語音進度指示器 - 改為固定在頂部 */
.speech-progress {
    height: 4px;
    background-color: var(--progress-bar-color);
    position: fixed;
    top: 0;
    left: 0;
    width: 0%;
    transition: width 0.2s linear;
    z-index: 300; /* 確保顯示在設定面板上方 */
    box-shadow: 0 0 8px rgba(76, 175, 80, 0.7);
}

/* Voice selection dropdown styling */
#voiceSelect {
    padding: 5px 8px;
    background-color: var(--button-bg);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    max-width: 170px;
    width: 170px;
    height: 30px;
    appearance: menulist;
    font-size: 0.95em;
    transition: all 0.2s ease;
}

#voiceSelect:hover {
    background-color: var(--button-hover-bg);
    border-color: #777;
}

#voiceSelect optgroup {
    background-color: #222;
    color: #ddd;
    font-weight: bold;
}

#voiceSelect option {
    background-color: #333;
    color: #fff;
    padding: 5px;
}

/* 朗讀按鈕激活狀態 */
#speechButton.speaking {
    background-color: #4CAF50;
    border-color: #2E8B57;
    box-shadow: 0 0 5px rgba(76, 175, 80, 0.5);
}

/* Navigation Buttons */
.nav-buttons {
    display: flex;
    flex-wrap: nowrap;
    justify-content: center;
    gap: 5px;
    margin: 10px 0;
    width: 100%;
}

.nav-button {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px 8px;
    font-size: 14px !important;
    background: var(--button-bg);
    color: var(--text-color);
    border: 1px solid var(--accent-color);
    border-radius: 4px;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    min-width: auto;
    flex-shrink: 0;
}

/* Mobile specific styles */
@media (max-width: 768px) {
    .nav-buttons {
        gap: 4px;
        padding: 5px 3px;
    }

    .nav-button {
        padding: 3px 6px;
        font-size: 13px !important;
        min-height: 28px;
        min-width: auto;
    }

    /* 上一頁/下一頁按鈕特別樣式 */
    .nav-button[title*="上一頁"],
    .nav-button[title*="下一頁"],
    .nav-button[title*="上1頁"],
    .nav-button[title*="下1頁"] {
        min-width: auto;
        font-weight: normal;
    }

    /* 返回目錄按鈕特別樣式 */
    .nav-button[title*="目錄"] {
        background: var(--accent-color);
        border-color: var(--accent-color);
        font-weight: normal;
        padding: 3px 6px;
    }
}

/* Extra Small Devices */
@media (max-width: 480px) {
    .nav-button {
        padding: 3px 5px;
        font-size: 12px !important;
        min-height: 26px;
    }

    .nav-button[title*="上一頁"],
    .nav-button[title*="下一頁"],
    .nav-button[title*="上1頁"],
    .nav-button[title*="下1頁"] {
        min-width: auto;
    }
}

/* Reading Progress Indicator */
#progress-indicator {
    position: fixed;
    bottom: 0;
    left: 0;
    height: 3px; /* Bar height */
    background-color: var(--progress-bar-color);
    width: 0%; /* Initial width */
    z-index: 200; /* Above most content */
    transition: width 0.1s linear; /* Smooth width change */
    box-shadow: 0 0 5px rgba(76, 175, 80, 0.5); /* Optional glow */
}


/* Responsive Design */
@media (max-width: 850px) {
    .reader-container {
        max-width: 95%; /* Use more screen width */
        padding: 20px 15px;
        margin: 20px auto;
    }
}

@media (max-width: 600px) {
    .settings-panel {
        padding: 10px;
        gap: 10px; /* Reduce gap */
        justify-content: center; /* Center items when wrapped */
    }
    .settings-panel label {
        margin-right: 2px;
        font-size: 0.85em; /* Smaller font for labels on mobile */
    }
    .settings-panel input[type="range"] {
        max-width: 80px;
    }
    #fontSizeValue, #scrollSpeedValue, #speechRateValue { 
        min-width: 35px; 
        font-size: 0.85em;
    }
    
    .settings-panel button {
        padding: 4px 8px;
        font-size: 0.85em;
    }
    
    #voiceSelect {
        max-width: 130px;
        width: 130px;
        font-size: 0.9em;
    }
    
    /* 手機版設置分組橫向排列 */
    .settings-group {
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        width: 100%;
        margin-bottom: 5px;
        padding: 3px;
    }
    
    /* 改為單行顯示 */
    .settings-panel {
        flex-direction: row;
        overflow-x: auto;
        white-space: nowrap;
        padding: 10px 5px;
    }
    
    /* 允許左右滑動操作 */
    .settings-panel::-webkit-scrollbar {
        height: 3px;
    }
    
    .settings-panel::-webkit-scrollbar-track {
        background: #333;
    }
    
    .settings-panel::-webkit-scrollbar-thumb {
        background: #555;
    }
    
    /* 在手機上顯示分隔線 */
    .settings-divider {
        display: block;
        height: 20px;
        margin: 0 8px;
    }

    .reader-container {
        padding: 15px 10px;
        margin: 15px auto;
    }

    .reader-container h1 { font-size: 1.6em; }
    .reader-container h2 { font-size: 1.2em; }

    #novel-content {
        line-height: 1.7; /* Slightly tighter line height on mobile */
        text-align: left; /* Left align might be better on small screens */
    }

    .navigation {
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        gap: 5px;
        margin: 15px 0;
    }
    
    .nav-button {
        padding: 5px 10px;
        font-size: 0.85em;
        flex-grow: 0;
        min-width: 0;
    }
    
    /* 控制按鈕寬度，使其適合手機屏幕 */
    .nav-button.index-button {
        width: auto;
    }
    
    .nav-button.jump-button {
        padding: 5px 6px;
        font-size: 0.8em;
    }
    
    .speech-highlight-container {
        max-width: 95%;
        padding: 15px;
        background-color: rgba(20, 20, 20, 0.9);
    }
    
    .speech-highlight {
        font-size: calc(var(--font-size) * 1.1);
        padding: 10px;
    }

    /* 在手機上增強高亮效果 */
    .highlighted-text {
        padding: 2px 4px;
        margin: 0 1px;
        border-bottom-width: 3px;
        font-weight: bold;
        box-shadow: 0 0 12px var(--highlight-color);
    }
    
    @keyframes text-highlight-pulse {
        0% { background-color: var(--highlight-bg-fade, rgba(76, 175, 80, 0.1)); }
        50% { background-color: var(--highlight-bg-strong, rgba(76, 175, 80, 0.25)); }
        100% { background-color: var(--highlight-bg-fade, rgba(76, 175, 80, 0.1)); }
    }
}

@media (max-width: 450px) {
    /* 小螢幕也使用橫向滾動方式 */
    .settings-panel { 
        flex-direction: row;
        overflow-x: auto;
        white-space: nowrap;
        padding: 10px 5px;
        align-items: center;
    }
    
    .settings-panel > * { 
        margin-bottom: 0;
        margin-right: 8px;
    }
    
    /* 優化滑塊寬度，使其在手機上更容易操作 */
    .settings-panel input[type="range"] { 
        max-width: 80px;
        width: 80px;
    }
    
    /* 確保每個分組都有足夠的寬度 */
    .settings-group {
        min-width: 220px;
        flex-shrink: 0;
        margin-right: 10px;
        padding: 5px;
        border-radius: 4px;
        background-color: rgba(80, 80, 80, 0.2);
    }
    
    /* 語音選擇下拉框 */
    #voiceSelect {
        max-width: 120px;
        width: 120px;
        font-size: 0.85em;
        padding: 4px 6px;
    }

    /* 導航按鈕水平排列 */
    .navigation { 
        flex-direction: row;
        justify-content: center;
        flex-wrap: wrap;
        gap: 5px;
        padding: 5px 0;
    } 
    
    .nav-button { 
        display: inline-block; 
        width: auto;
        min-width: 32px;
        margin: 2px;
        padding: 5px 8px;
        font-size: 0.8em;
        text-align: center;
    }
    
    /* 更小的跳轉按鈕 */
    .nav-button.jump-button {
        padding: 5px 6px;
        font-size: 0.75em;
    }
    
    /* 調整回列表按鈕 */
    .nav-button.index-button {
        flex-basis: auto;
    }
    
    /* 上下頁導航組 */
    .bottom-nav {
        margin-bottom: 30px;
    }
    
    /* 優化圖標顯示 */
    .nav-button .icon {
        font-size: 1.2em;
    }
    
    /* 當顯示圖標時，確保按鈕足夠寬 */
    @media (max-width: 480px) {
        .nav-button {
            min-width: 36px;
            padding: 6px;
        }
        
        /* 在非常小的螢幕上減小導航距離 */
        .navigation {
            gap: 3px;
            margin: 10px 0;
        }
        
        /* 優化下方導航，減少頁面佔用 */
        .bottom-nav {
            position: fixed;
            bottom: 0;
            left: 0;
            right: 0;
            background-color: rgba(30, 30, 30, 0.9);
            margin: 0;
            padding: 5px;
            z-index: 90;
            box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.3);
        }
    }
}

/* 白底黑字 - 藍色調高亮 */
@media (prefers-color-scheme: light), (light) {
    .highlighted-text {
        --highlight-color: rgba(25, 118, 210, 0.5);    /* 藍色陰影 */
        --highlight-bg: rgba(25, 118, 210, 0.12);      /* 淡藍背景 */
        --highlight-border: #1976d2;                   /* 藍色邊框 */
        --highlight-bg-fade: rgba(25, 118, 210, 0.08); /* 動畫淡色 */
        --highlight-bg-strong: rgba(25, 118, 210, 0.2); /* 動畫深色 */
    }
}

/* 黑底綠字 - 紫色調高亮 */
@media (light-level: dim) {
    body[style*="color: rgb(0, 255, 0)"], 
    body[style*="color: #00ff00"], 
    body[style*="color: lime"] {
        --highlight-color: rgba(186, 104, 200, 0.5);   /* 紫色陰影 */
        --highlight-bg: rgba(186, 104, 200, 0.15);     /* 淡紫背景 */
        --highlight-border: #ba68c8;                   /* 紫色邊框 */
        --highlight-bg-fade: rgba(186, 104, 200, 0.1); /* 動畫淡色 */
        --highlight-bg-strong: rgba(186, 104, 200, 0.3); /* 動畫深色 */
    }
}

/* 動態高亮背景顏色 - 通過JS實現 */
/* 當檢測到藍色背景時 - 黃色調高亮 */
.bg-blue .highlighted-text,
body[style*="background-color: rgb(0, 0, 255)"] .highlighted-text,
body[style*="background-color: #0000ff"] .highlighted-text {
    --highlight-color: rgba(255, 215, 0, 0.7);    /* 金色陰影 */
    --highlight-bg: rgba(255, 215, 0, 0.18);      /* 淡金背景 */
    --highlight-border: #ffd700;                  /* 金色邊框 */
    --highlight-bg-fade: rgba(255, 215, 0, 0.12); /* 動畫淡色 */
    --highlight-bg-strong: rgba(255, 215, 0, 0.25); /* 動畫深色 */
}

/* 高對比模式 - 更明顯的高亮效果 */
.high-contrast .highlighted-text {
    color: #000000;
    background-color: #ffff00 !important;
    box-shadow: 0 0 8px rgba(0, 0, 0, 0.5);
    border: 2px solid #000000;
    animation: high-contrast-pulse 2s infinite ease-in-out;
}

@media (prefers-contrast: more) {
    .highlighted-text {
        color: #000000;
        background-color: #ffff00 !important;
        box-shadow: 0 0 8px rgba(0, 0, 0, 0.5);
        border: 2px solid #000000;
        animation: high-contrast-pulse 2s infinite ease-in-out;
    }
}

@keyframes high-contrast-pulse {
    0% { background-color: #ffff00; }
    50% { background-color: #ffcc00; }
    100% { background-color: #ffff00; }
}

/* 支持深色/淺色主題自動切換高亮顏色 */
@media (prefers-color-scheme: dark) {
    .speech-highlight-container {
        background-color: rgba(30, 30, 30, 0.9);
        border-left-color: var(--highlight-border, #4CAF50);
    }
}

@media (prefers-color-scheme: light) {
    .speech-highlight-container {
        background-color: rgba(240, 240, 240, 0.95);
        border-left-color: #1976d2;
        color: #222;
    }
    
    .speech-highlight {
        color: #222;
        text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    }
}

/* 語音控制按鈕樣式 */
#speechPlayButton, #speechPauseButton, #speechRestartButton {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 5px 10px;
    margin-right: 5px;
    border-radius: 4px;
    transition: all 0.2s ease;
}

#speechPlayButton .speech-icon,
#speechPauseButton .speech-icon,
#speechRestartButton .speech-icon {
    margin-right: 5px;
    font-size: 1.1em;
}

#speechPlayButton {
    background-color: var(--button-bg);
}

#speechPlayButton.speaking {
    background-color: #4CAF50;
    border-color: #2e7d32;
}

#speechPauseButton {
    background-color: #f44336;
    border-color: #d32f2f;
}

#speechRestartButton {
    background-color: #2196F3;
    border-color: #1976D2;
}

#speechPlayButton:hover {
    background-color: #66BB6A;
}

#speechPauseButton:hover {
    background-color: #e57373;
}

#speechRestartButton:hover {
    background-color: #64B5F6;
}

/* 在小屏幕上只顯示圖標 */
@media (max-width: 480px) {
    #speechPlayButton .speech-text,
    #speechPauseButton .speech-text,
    #speechRestartButton .speech-text {
        display: none;
    }
    
    #speechPlayButton .speech-icon,
    #speechPauseButton .speech-icon,
    #speechRestartButton .speech-icon {
        margin-right: 0;
        font-size: 1.2em;
    }
    
    #speechPlayButton, 
    #speechPauseButton, 
    #speechRestartButton {
        min-width: 36px;
        padding: 5px 8px;
    }
}

/* 自動翻頁選項樣式 */
.auto-next-page {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    margin: 10px 0;
}

.auto-next-page input[type="checkbox"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
    accent-color: var(--accent-color);
}

.auto-next-page label {
    font-size: 16px;
    color: var(--text-color);
    cursor: pointer;
    user-select: none;
    margin: 0;
}

/* 移動端樣式優化 */
@media (max-width: 768px) {
    .auto-next-page {
        width: 100%;
        justify-content: center;
        padding: 12px;
        margin: 15px 0;
    }

    .auto-next-page input[type="checkbox"] {
        width: 24px;
        height: 24px;
    }

    .auto-next-page label {
        font-size: 16px;
    }
}

@media (max-width: 480px) {
    .auto-next-page {
        padding: 10px;
        margin: 10px 0;
    }

    .auto-next-page label {
        font-size: 14px;
    }
}

/* 確保自動翻頁選項在設置面板中正確顯示 */
.settings-panel .auto-next-page {
    margin: 0;
    padding: 0;
    background: none;
    flex-shrink: 0;
}

/* 設置組中的自動翻頁選項 */
.settings-group .auto-next-page {
    width: 100%;
    justify-content: flex-start;
    padding: 8px;
    margin: 5px 0;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
}

/* 確保自動翻頁選項在導航欄中正確顯示 */
.navigation .auto-next-page {
    margin: 0;
    padding: 0 10px;
    background: none;
}

/* 自動翻頁開關的動畫效果 */
.auto-next-page input[type="checkbox"] {
    transition: all 0.2s ease;
}

.auto-next-page input[type="checkbox"]:checked {
    background-color: var(--accent-color);
    border-color: var(--accent-color);
}

/* 懸停效果 */
.auto-next-page:hover {
    background: rgba(255, 255, 255, 0.08);
}

.auto-next-page label:hover {
    color: var(--accent-color);
}

/* 語音控制按鈕區域 */
.speech-controls {
    text-align: center;
    margin: 10px auto;
    display: flex;
    justify-content: center;
    gap: 10px;
}

.speech-control-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 5px 12px;
    background-color: var(--button-bg);
    color: #d0d0d0;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    transition: background-color 0.2s ease, color 0.2s ease;
    cursor: pointer;
    font-size: 18px !important;
}

.speech-control-btn:hover {
    background-color: var(--button-hover-bg);
    color: #fff;
}

#speechPauseButton {
    background-color: #e74c3c;
}

#speechPauseButton:hover {
    background-color: #c0392b;
}

#speechRestartButton {
    background-color: #3498db;
}

#speechRestartButton:hover {
    background-color: #2980b9;
}

/* Button styles */
.nav-buttons {
    display: flex;
    flex-wrap: nowrap;
    justify-content: center;
    gap: 5px;
    margin: 10px 0;
}

.nav-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    font-size: 8px;
    border: 1px solid var(--border-color);
    background-color: var(--button-bg-color);
    color: var(--button-text-color);
    border-radius: 3px;
    cursor: pointer;
    text-decoration: none;
    margin: 2px;
    padding: 2px;
    text-align: center;
}

.nav-button:hover {
    background-color: var(--button-hover-bg-color);
}

.nav-button.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Mobile specific styles */
@media (max-width: 768px) {
    .nav-buttons {
        display: flex;
        justify-content: center;
        gap: 10px;
        padding: 15px 10px;
        flex-wrap: wrap;
    }

    .nav-button {
        min-height: 44px;
        min-width: 44px;
        padding: 10px 20px;
        font-size: 17px !important;
        background: var(--button-bg);
        color: var(--text-color);
        border: 1px solid var(--accent-color);
        border-radius: 8px;
        display: flex;
        align-items: center;
        justify-content: center;
        margin: 0;
        touch-action: manipulation;
    }

    .nav-button:active {
        background: var(--accent-color);
        transform: scale(0.98);
    }

    .nav-button.disabled {
        opacity: 0.5;
        background: var(--button-disabled-bg);
        border-color: var(--border-color);
    }

    /* 上一頁/下一頁按鈕特別樣式 */
    .nav-button[title*="上一頁"],
    .nav-button[title*="下一頁"] {
        min-width: 100px;
        font-weight: bold;
    }

    /* 返回目錄按鈕特別樣式 */
    .nav-button[title*="目錄"] {
        background: var(--accent-color);
        border-color: var(--accent-color);
        font-weight: bold;
    }

    /* 語音控制按鈕組 */
    .speech-controls {
        position: fixed;
        bottom: 20px;
        left: 0;
        right: 0;
        padding: 15px;
        background: rgba(0, 0, 0, 0.8);
        backdrop-filter: blur(10px);
        z-index: 1000;
        display: flex;
        justify-content: center;
        gap: 15px;
    }

    .speech-control-btn {
        min-height: 44px;
        min-width: 44px;
        padding: 10px 20px;
        font-size: 17px !important;
        border-radius: 8px;
        background: var(--accent-color);
        color: #ffffff;
        border: none;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        touch-action: manipulation;
    }

    /* 設置面板按鈕 */
    .settings-panel button,
    .settings-panel select,
    #voiceSelect {
        min-height: 44px;
        min-width: 44px;
        padding: 10px 15px;
        font-size: 17px !important;
        border-radius: 8px;
        margin: 5px;
    }
}

/* Extra Small Devices */
@media (max-width: 480px) {
    .nav-button {
        padding: 8px 15px;
        font-size: 16px !important;
    }

    .nav-button[title*="上一頁"],
    .nav-button[title*="下一頁"] {
        min-width: 80px;
    }

    .speech-controls {
        padding: 10px;
    }

    .speech-control-btn {
        padding: 8px 15px;
    }
}

/* Ensure smooth scrolling */
html {
    scroll-behavior: smooth;
}

/* Desktop specific adjustments */
@media (min-width: 769px) {
    .reader-container {
        max-width: 800px;
        margin: 30px auto;
        padding: 25px 30px;
        position: relative;
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    #novel-content {
        width: 100%;
        max-width: 800px;
        margin: 0 auto;
        padding: 0;
        position: relative;
    }

    .sentence-mark.current-sentence {
        scroll-margin-top: calc(50vh - 100px) !important;
        scroll-margin-bottom: calc(50vh - 100px) !important;
    }
}

/* Mobile adjustments */
@media (max-width: 768px) {
    .reader-container {
        padding: 15px 20px;
        width: calc(100% - 40px);
        margin: 15px auto;
    }

    #novel-content {
        padding: 0;
        text-align: justify;
    }

    .sentence-mark.current-sentence {
        scroll-margin-top: 25vh !important;
        scroll-margin-bottom: 25vh !important;
    }
}

/* Highlight animation */
@keyframes highlight-pulse {
    0% { background-color: var(--highlight-bg, rgba(147, 112, 219, 0.2)); }
    50% { background-color: var(--highlight-bg, rgba(147, 112, 219, 0.3)); }
    100% { background-color: var(--highlight-bg, rgba(147, 112, 219, 0.2)); }
}

.sentence-mark.current-sentence {
    animation: highlight-pulse 2s infinite;
}

/* Novel Grid Layout */
.novel-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 20px;
    padding: 20px;
    margin: 0 auto;
    max-width: 1200px;
}

.novel-card {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    overflow: hidden;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 300px;
}

.novel-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

.novel-cover {
    width: 100%;
    height: 280px;
    object-fit: cover;
    display: block;
}

.novel-info {
    padding: 15px;
    flex-grow: 1;
}

.novel-title {
    font-size: 1.1em;
    margin: 0 0 8px 0;
    font-weight: bold;
    color: var(--text-color);
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.novel-author {
    font-size: 0.9em;
    color: rgba(255, 255, 255, 0.7);
    margin: 0;
}

/* 平板設備 */
@media (max-width: 768px) {
    .novel-grid {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
        gap: 15px;
        padding: 15px;
    }
}

/* 手機設備 */
@media (max-width: 480px) {
    .novel-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 12px;
        padding: 12px;
    }

    .novel-card {
        min-height: 250px;
    }

    .novel-cover {
        height: 200px;
    }

    .novel-info {
        padding: 10px;
    }

    .novel-title {
        font-size: 1em;
        -webkit-line-clamp: 2;
    }

    .novel-author {
        font-size: 0.85em;
    }
}

/* 小型手機設備 */
@media (max-width: 320px) {
    .novel-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
        padding: 10px;
    }

    .novel-card {
        min-height: 220px;
    }

    .novel-cover {
        height: 180px;
    }
}

/* Container styles */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    width: 100%;
    box-sizing: border-box;
}

/* Novel Grid Layout */
.novel-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 20px;
    width: 100%;
    box-sizing: border-box;
    margin: 0 auto;
    padding: 0;
}

.novel-card {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    overflow: hidden;
    transition: transform 0.3s ease;
    position: relative;
    width: 100%;
    box-sizing: border-box;
    margin: 0 auto;
    max-width: 300px;
}

.novel-card:hover {
    transform: translateY(-5px);
}

.novel-cover {
    width: 100%;
    aspect-ratio: 2/3;
    object-fit: cover;
    display: block;
}

.novel-info {
    padding: 15px;
}

.novel-title {
    margin: 0;
    font-size: 1.1em;
    color: var(--text-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.novel-author {
    margin: 5px 0 0;
    font-size: 0.9em;
    color: #888;
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 15px;
    }

    .novel-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 15px;
    }

    .novel-card {
        max-width: 200px;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 10px;
    }

    .novel-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
        width: calc(100% - 20px);
        margin: 0 auto;
    }

    .novel-card {
        max-width: none;
        width: 100%;
    }

    .novel-info {
        padding: 10px;
    }

    .novel-title {
        font-size: 1em;
    }

    .novel-author {
        font-size: 0.8em;
    }
}

@media (max-width: 320px) {
    .container {
        padding: 8px;
    }

    .novel-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
        width: calc(100% - 16px);
    }
}

/* Search container styles */
.search-container {
    width: 100%;
    max-width: 800px;
    margin: 20px auto;
    padding: 0 20px;
    box-sizing: border-box;
}

/* Search box */
.search-box {
    position: relative;
    width: 100%;
    margin-bottom: 30px;
    background: #2a2a2a;
    border-radius: 8px;
    padding: 10px 15px;
    display: flex;
    align-items: center;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.search-input {
    flex: 1;
    background: transparent;
    border: none;
    color: #fff;
    font-size: 16px;
    padding: 8px 10px;
    margin-left: 10px;
    outline: none;
}

.search-icon {
    color: #888;
    font-size: 18px;
}

/* Categories navigation */
.categories-nav {
    margin: 30px 0;
    padding: 20px;
    background: #1a1a1a;
    border-radius: 10px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.categories-nav h2 {
    margin: 0 0 20px 0;
    color: #fff;
    font-size: 1.5em;
    font-weight: normal;
}

.category-list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 0;
}

.category-link {
    display: inline-flex;
    align-items: center;
    padding: 8px 15px;
    background: #2a2a2a;
    border-radius: 20px;
    color: #fff;
    text-decoration: none;
    transition: all 0.3s ease;
}

.category-link:hover,
.category-link.active {
    background: #4CAF50;
    transform: translateY(-2px);
}

.category-icon {
    margin-right: 8px;
}

/* Responsive Design */
@media (max-width: 768px) {
    .search-container {
        padding: 0 15px;
    }
    
    .categories-nav {
        margin: 20px 0;
        padding: 15px;
    }
    
    .category-list {
        gap: 8px;
    }
}

@media (max-width: 480px) {
    .search-box {
        padding: 8px 12px;
    }
    
    .search-input {
        font-size: 14px;
    }
    
    .category-link {
        padding: 6px 12px;
        font-size: 14px;
    }
    
    .categories-nav h2 {
        font-size: 1.3em;
    }
}

/* Footer styles */
.footer {
    padding: 20px;
    background: rgba(0, 0, 0, 0.2);
    margin-top: 30px;
}

.footer-content {
    max-width: 1200px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
}

.footer-section {
    padding: 0 10px;
}

.footer-section h3 {
    color: var(--text-color);
    font-size: 1.1em;
    margin-bottom: 10px;
}

.footer-section ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.footer-section li {
    margin-bottom: 8px;
}

.footer-section a {
    color: var(--text-color);
    text-decoration: none;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.footer-section a:hover {
    opacity: 1;
}

.copyright {
    text-align: center;
    padding: 10px;
    opacity: 0.7;
    font-size: 0.9em;
}

/* Responsive footer */
@media (max-width: 768px) {
    .footer-content {
        grid-template-columns: repeat(3, 1fr);
        gap: 15px;
        padding: 0 15px;
    }
}

@media (max-width: 480px) {
    .footer {
        padding: 15px 10px;
    }

    .footer-content {
        grid-template-columns: 1fr;
        gap: 10px;
        text-align: center;
    }

    .footer-section {
        padding: 0;
        margin-bottom: 15px;
    }

    .footer-section h3 {
        font-size: 1em;
        margin-bottom: 8px;
    }

    .footer-section li {
        margin-bottom: 6px;
        font-size: 0.9em;
    }

    .copyright {
        font-size: 0.8em;
        padding: 8px;
    }
}

/* 設置面板的移動端優化 */
@media (max-width: 768px) {
    .settings-panel {
        width: 180px;
        padding: 8px;
    }

    .slider-group label {
        min-width: 30px;
        font-size: 12px;
    }
    
    .slider-value {
        min-width: 30px;
        font-size: 12px;
    }
}

/* 標題和作者顯示優化 */
@media (max-width: 768px) {
    .reader-container {
        padding: 20px 15px;
    }

    .reader-container h1 {
        font-size: 24px;
        line-height: 1.3;
        margin-bottom: 15px;
        padding: 0 10px;
    }

    .reader-container h2 {
        font-size: 18px;
        line-height: 1.4;
        margin: 0 0 20px 0;
        padding: 0 10px;
    }

    .reader-container h2 .author-tag {
        display: block;
        font-size: 16px;
        color: rgba(255, 255, 255, 0.8);
        margin-top: 8px;
    }

    #novel-content {
        font-size: var(--font-size, 18px);
        line-height: 1.8;
        padding: 0 10px;
    }
}

/* 更小螢幕的額外優化 */
@media (max-width: 480px) {
    .settings-panel {
        padding: 10px;
    }

    .reader-container h1 {
        font-size: 22px;
    }

    .reader-container h2 {
        font-size: 16px;
    }

    .reader-container h2 .author-tag {
        font-size: 14px;
    }

    #novel-content {
        padding: 0 8px;
    }

    .settings-panel button,
    .settings-panel select,
    #voiceSelect {
        height: 40px;
        font-size: 14px !important;
    }

    .settings-panel label {
        font-size: 14px;
    }
}

/* 確保文字不會被截斷 */
.novel-title,
.novel-author {
    white-space: normal;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.novel-title {
    line-height: 1.4;
    margin-bottom: 8px;
}

.novel-author {
    line-height: 1.3;
}

/* 移動端適配 */
@media (max-width: 768px) {
    .settings-panel {
        width: 220px;
        padding: 10px;
    }
    
    .slider-group label {
        min-width: 35px;
        font-size: 13px;
    }
    
    .slider-value {
        min-width: 40px;
        font-size: 13px;
    }
}

/* 隱藏底部多餘的語音選擇器 */
.page-content + .speech-controls + div .speech-controls,
.page-content ~ .speech-controls:not(:first-of-type),
body > .speech-controls:last-of-type,
body > select[id^="speechLang"]:not(.control-select) {
    display: none !important;
}

/* 確保只顯示設置面板內的語音選擇器 */
.settings-panel .control-select#speechLang {
    display: block;
}

/* 隱藏頁面底部的語音相關元素 */
body > div:not(.settings-panel):not(.reader-container) > .speech-controls,
body > div:not(.settings-panel):not(.reader-container) > select[id^="speechLang"] {
    display: none !important;
}