:root {
    --primary: #4361ee;
    --primary-light: #4895ef;
    --secondary: #3f37c9;
    --dark: #1d3557;
    --light: #f8f9fa;
    --gray: #6c757d;
    --gray-light: #e9ecef;
    --success: #4cc9f0;
    --danger: #e63946;
    --border-radius: 12px;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    --transition: all 0.3s ease;
    
    /* 浅色主题变量 */
    --bg-color: #f8f9fa;
    --card-bg: #ffffff;
    --text-color: #1d3557;
    --text-secondary: #6c757d;
    --border-color: #e9ecef;
    --header-bg: #ffffff;
}

.dark-mode {
    /* 深色主题变量 */
    --bg-color: #121212;
    --card-bg: #1e1e1e;
    --text-color: #e9ecef;
    --text-secondary: #a0a0a0;
    --border-color: #2d2d2d;
    --header-bg: #1e1e1e;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    line-height: 1.6;
    color: var(--text-color);
    background: var(--bg-color);
    min-height: 100vh;
    transition: var(--transition);
    padding: 0 20px;
}

.container {
    max-width: 1000px;
    margin: 0 auto;
}

.eb-header {
    text-align: center;
    margin-bottom: 40px;
    padding: 40px 20px;
    background: var(--header-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
    transition: var(--transition);
}

.eb-header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 4px;
    background: linear-gradient(to right, var(--primary), var(--success));
}

.eb-header h1 {
    font-size: 2.2rem;
    margin-bottom: 10px;
    color: var(--text-color);
    font-weight: 700;
    transition: var(--transition);
}

.eb-header p {
    font-size: 1.1rem;
    color: var(--text-secondary);
    max-width: 600px;
    margin: 0 auto;
    transition: var(--transition);
}

.theme-toggle {
    background: var(--card-bg);
    border: none;

    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;

    cursor: pointer;
    transition: var(--transition);
    box-shadow: var(--shadow);
}

.theme-toggle:hover {
    transform: rotate(15deg);
}

.theme-toggle i {
    font-size: 1.3rem;
    color: var(--text-color);
    transition: var(--transition);
}

.top-controls {
    position: fixed;
    top: 30px;
    right: 30px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 22;
}

.reading-controls {
    position: fixed;
    bottom: 30px;
    right: 30px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 20;
}

.reading-controls .control-btn, .top-controls .control-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: var(--shadow);
    border: none;
    flex-direction: column;
}

.reading-controls .control-btn:hover, .top-controls .control-btn:hover {
    background: var(--secondary);
    transform: scale(1.1);
}

.css-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 15px;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    border: none;
    font-size: 0.9rem;
    text-align: center;
    white-space: nowrap;
    margin-bottom: 4px;
}

.css-btn.primary {
    background: var(--primary);
    color: white;
}

.css-btn.primary:hover {
    background: var(--secondary);
    transform: translateY(-2px);
}

/* 通知样式 */
.custom-css-notification {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);        
    padding: 12px 20px;
    border-radius: 6px;
    color: white;
    font-weight: 600;
    z-index: 10003;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transition: all 0.3s ease;
}

.custom-css-notification.success {
    background: #4CAF50;
}

.custom-css-notification.info {
    background: var(--primary);
}

.custom-css-notification.warning {
    background: #f8961e;
}

.custom-css-notification.fade-out {
    opacity: 0;
    transform: translateY(-10px);
}

.breadcrumb {
    display: flex;
    align-items: center;
    margin: 20px 0;
    padding: 15px 20px;
    background: var(--card-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    transition: var(--transition);
}

.breadcrumb a {
    text-decoration: none;
    color: var(--text-secondary);
    transition: var(--transition);
    display: flex;
    align-items: center;
}

.breadcrumb a:hover {
    color: var(--primary);
}

.breadcrumb-separator {
    margin: 0 10px;
    color: var(--text-secondary);
}

.breadcrumb-current {
    color: var(--text-color);
    font-weight: 600;
}

.book-info {
    display: flex;
    gap: 25px;
    margin-bottom: 30px;
    flex-wrap: wrap;
}

.book-cover {
    flex: 0 0 200px;
    height: 280px;
    border-radius: var(--border-radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.book-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.book-details {
    flex: 1;
    min-width: 300px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.book-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 20px;
}

.book-tag {
    background: var(--border-color);
    color: var(--text-color);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 500;
    transition: var(--transition);
}

.book-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.action-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--primary);
    color: white;
    padding: 10px 20px;
    border-radius: 50px;
    font-weight: 600;
    text-decoration: none;
    transition: var(--transition);
    border: none;
    cursor: pointer;
}

.action-btn:hover {
    background: var(--secondary);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(67, 97, 238, 0.4);
}

.action-btn.secondary {
    background: var(--card-bg);
    color: var(--text-color);
    border: 2px solid var(--border-color);
}

.action-btn.secondary:hover {
    background: var(--border-color);
    transform: translateY(-2px);
}

.toc-container {
    margin: 20px 0;
    background: var(--card-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    transition: var(--transition);
}

.toc-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.toc-header h2 {
    color: var(--text-color);
    font-size: 1.5rem;
    transition: var(--transition);
}

.chapter-count {
    background: var(--primary);
    color: white;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 600;
}

.chapter-list {
    list-style-type: none;
    padding: 0;
    max-height: 500px;
    overflow-y: auto;
}

.chapter-list li {
    border-bottom: 1px solid var(--border-color);
    transition: var(--transition);
}

.chapter-list li:last-child {
    border-bottom: none;
}

.chapter-list a {
    text-decoration: none;
    color: var(--text-color);
    display: flex;
    align-items: center;
    padding: 15px 20px;
    transition: var(--transition);
}

.chapter-list a:hover {
    background: var(--border-color);
}

/* 除了 hashtag 锚点，还支持 active class */
.chapter-list a:target, .chapter-list a.active  {
    background: linear-gradient(to right, var(--primary), var(--success));
    color: #e9ecef;
}

.chapter-list a:target .chapter-page, .chapter-list a.active .chapter-page {
    color: #e9ecef;
}

.chapter-icon {
    margin-right: 12px;
    color: var(--text-secondary);
    font-size: 1.1rem;
    width: 24px;
    text-align: center;
}

.chapter-title {
    flex: 1;
}

.chapter-page {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.toc-level-0 { margin-left: 0px; }
.toc-level-1 { margin-left: 25px; font-size: 0.95em; }
.toc-level-2 { margin-left: 50px; font-size: 0.9em; }
.toc-level-3 { margin-left: 75px; font-size: 0.85em; }

.toc-level-1 .chapter-icon { color: var(--success); }
.toc-level-2 .chapter-icon { color: var(--warning); }
.toc-level-3 .chapter-icon { color: var(--danger); }

.eb-footer {
    text-align: center;
    padding: 10px 0;
    color: var(--text-secondary);
    font-size: 0.9rem;
    border-top: 1px solid var(--border-color);
    transition: var(--transition);
}

.book-info-card {
    display: flex;
    background: var(--card-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    padding: 25px;
    margin-bottom: 30px;
    margin-top: 30px;
    gap: 25px;
    transition: var(--transition);
}

.book-info-cover {
    flex: 0 0 150px;
    height: 200px;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.book-info-cover img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.book-info-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.book-info-title {
    font-size: 1.5rem;
    color: var(--text-color);
    margin-bottom: 10px;
    font-weight: 700;
    line-height: 1.3;
}

.book-info-author {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: 15px;
}

.book-info-desc {
    font-size: 1rem;
    color: var(--text-color);
    margin-bottom: 15px;
}

.book-info-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 15px;
}

.book-tag {
    background: var(--primary-light);
    color: white;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 500;
    transition: var(--transition);
}

.book-tag:hover {
    background: var(--primary);
    transform: translateY(-2px);
    cursor: pointer;
}

.control-name {
    font-size: 0.5rem;
}

.kindle-mode .eb-header, .kindle-mode .toc-container, 
.kindle-mode .content-container, .kindle-mode .navigation,
.kindle-mode .theme-toggle, .kindle-mode .control-btn {
    box-shadow: none;
    border-radius: inherit;
}

.kindle-mode .book-info-card, .kindle-mode .eb-footer{
    display: none;
}

.kindle-mode .chapter-list {
    max-height: none;
}

.kindle-mode .breadcrumb, .kindle-mode .toc-container {
    margin: 0;
}

.kindle-mode .container {
    padding: 0;
}

.kindle-mode .theme-toggle {
    border: 1px solid;
}

@media (max-width: 768px) {
    .eb-header h1 {
        font-size: 1.8rem;
    }
    
    .book-info {
        flex-direction: column;
    }
    
    .book-cover {
        align-self: center;
    }
    
    .book-actions {
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .eb-header {
        padding: 30px 15px;
    }
    
    .breadcrumb {
        flex-wrap: wrap;
    }
    
    .breadcrumb-separator {
        margin: 0 5px;
    }
    
    .toc-header {
        flex-direction: column;
        gap: 10px;
        align-items: flex-start;
    }

    #clearReadingProgressBtn {
        font-size: 0.5rem;
    }
    
    #toggleShelfBtn {
        font-size: 0.5rem;
    }
}

/* 书架按钮样式 */
#toggleShelfBtn {
    margin-right: 10px;
}

#toggleShelfBtn.in-shelf {
    background: var(--danger);
}

#toggleShelfBtn.in-shelf:hover {
    background: #c0392b;
}

/* 选择分组弹窗样式 */
.select-group-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 10002;
}

.select-group-modal.active {
    display: flex;
}

.select-group-content {
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    background: var(--card-bg);
    border-radius: var(--border-radius);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
}

.select-group-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.select-group-header h3 {
    margin: 0;
    color: var(--text-color);
}

.select-group-close-btn {
    width: 32px;
    height: 32px;
    background: var(--border-color);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    color: var(--text-color);
}

.select-group-close-btn:hover {
    background: var(--danger);
    color: white;
}

.select-group-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.select-group-tree {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.select-group-item {
    display: flex;
    align-items: center;
    padding: 10px 15px;
    background: var(--bg-color);
    border-radius: 6px;
    cursor: pointer;
    transition: var(--transition);
    border: 2px solid transparent;
    color: var(--text-color);
}

.select-group-item:hover {
    background: var(--primary-light);
    color: white;
}

.select-group-item.selected {
    border-color: var(--primary);
    background: var(--primary-light);
    color: white;
}

.select-group-item-icon {
    margin-right: 10px;
    font-size: 1rem;
}

.select-group-item-name {
    font-size: 0.95rem;
    font-weight: 500;
}

.select-group-footer {
    padding: 15px 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    flex-shrink: 0;
}

.select-group-confirm-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.95rem;
    transition: var(--transition);
}

.select-group-confirm-btn:hover {
    background: var(--primary-light);
}

/* 加载动画样式 */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(255, 255, 255, 1);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 5px solid #f3f3f3;
    border-top: 5px solid var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.dark-mode .loading-overlay {
    background-color: rgba(0, 0, 0, 1);
}

.dark-mode .loading-spinner {
    border: 5px solid #333;
    border-top: 5px solid var(--primary);
}

.kindle-mode .loading-spinner {
    width: auto;
    height: auto;
    border: none;
    border-radius: 0;
    animation: none;
    font-size: 18px;
    color: var(--text);
    font-family: var(--font-family);
}

.kindle-mode .loading-spinner::after {
    content: "Loading...";
}