/* 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 {
    background-color: var(--panel-bg);
    padding: 10px 20px;
    border-bottom: 1px solid var(--border-color);
    position: sticky; /* Keep panel at the top */
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 15px; /* Spacing between controls */
    flex-wrap: wrap; /* Allow controls to wrap on smaller screens */
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}

.settings-panel label {
    color: #ccc;
    font-size: 0.9em;
    margin-right: 5px;
}

.settings-panel input[type="color"] {
    border: 1px solid var(--border-color);
    padding: 0;
    height: 25px;
    width: 40px;
    cursor: pointer;
    vertical-align: middle;
    background-color: transparent; /* Ensure swatch color is visible */
    border-radius: 3px;
}

.settings-panel input[type="range"] {
    cursor: pointer;
    vertical-align: middle;
    max-width: 100px; /* Limit width */
}

#fontSizeValue {
    color: #fff;
    min-width: 40px; /* Prevent jumping */
    display: inline-block;
    text-align: right;
    font-size: 0.9em;
    font-family: monospace;
}

.settings-panel button {
    padding: 5px 12px;
    background-color: var(--button-bg);
    color: #fff;
    border: 1px solid var(--border-color);
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.9em;
    transition: background-color 0.2s ease;
}

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

/* 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;
}

/* 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 */
.navigation {
    text-align: center;
    margin-bottom: 20px;
    margin-top: 20px;
    display: flex; /* Use flexbox for alignment */
    justify-content: center; /* Center buttons */
    gap: 15px; /* Space between buttons */
    flex-wrap: wrap; /* Allow wrapping on small screens */
}

.nav-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5em;
    padding: 0.8em 1.2em;
    font-size: 18px !important;
    line-height: 1.2;
    text-decoration: none;
    border-radius: 8px;
    transition: all 0.2s ease;
    white-space: nowrap;
    cursor: pointer;
}

.nav-button .icon {
    font-size: 20px !important; /* Force icon size */
    line-height: 1;
}

.nav-button .text {
    font-size: 18px !important; /* Force text size */
}

.nav-button:hover:not(.disabled) { /* Hover effect only if not disabled */
    background-color: var(--accent-color);
    color: #fff;
    border-color: #777;
}

.nav-button.disabled {
    background-color: var(--button-disabled-bg);
    color: var(--button-disabled-color);
    cursor: not-allowed;
    pointer-events: none; /* Disable clicks */
    border-color: #444;
}

/* 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;
    margin-left: 10px;
    white-space: nowrap;
}

.auto-next-page input[type="checkbox"] {
    margin-right: 4px;
    cursor: pointer;
}

.auto-next-page label {
    font-size: 0.85em;
    cursor: pointer;
}

@media (max-width: 480px) {
    .auto-next-page {
        margin-left: 5px;
    }
    
    .auto-next-page label {
        font-size: 0.8em;
    }
}

/* 語音控制按鈕區域 */
.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;
    max-width: 1200px;
    margin: 0 auto;
}

.novel-card {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    overflow: hidden;
    transition: transform 0.3s ease;
    position: relative;
    margin: 0 auto;
    width: 100%;
    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) {
    .novel-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 15px;
        padding: 15px;
        width: calc(100% - 30px);
        margin: 0 auto;
    }

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

@media (max-width: 480px) {
    .novel-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
        padding: 12px;
        width: calc(100% - 24px);
    }

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

    .novel-info {
        padding: 10px;
    }

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

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

@media (max-width: 320px) {
    .novel-grid {
        grid-template-columns: 1fr;
        gap: 15px;
        padding: 15px;
        width: calc(100% - 30px);
    }

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

/* Container styles */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 10px;
}

/* 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 {
    margin-bottom: 20px;
    width: 100%;
    max-width: 600px;
    margin: 0 auto 20px;
}

.search-box {
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 10px 15px;
    margin: 0 auto;
    width: 100%;
    box-sizing: border-box;
}

.search-input {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-color);
    font-size: 1em;
    padding: 5px 10px;
    outline: none;
}

.search-icon {
    opacity: 0.7;
    margin-right: 10px;
}

/* Categories navigation */
.categories-nav {
    margin: 15px 0;
    padding: 10px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

.category-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.category-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 12px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 15px;
    color: #fff;
    text-decoration: none;
    transition: all 0.3s ease;
    border: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 0.9em;
}

.category-link:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.category-link.active {
    background: #4CAF50;
    border-color: #45a049;
}

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

@media (max-width: 480px) {
    .search-box {
        padding: 8px 12px;
    }

    .category-link {
        padding: 6px 12px;
        font-size: 0.9em;
    }

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

/* Footer styles */
.footer {
    background: rgba(30, 30, 30, 0.95);
    padding: 20px 0 10px;
    margin-top: 30px;
    color: #fff;
}

.footer-content {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    padding: 0 20px;
}

.footer-section {
    padding: 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;
    }
}