:root {
    --primary: #2C3E50;
    --secondary: #34495E;
    --accent: #E74C3C;
    --background: #F5F5F5;
    --card: #FFFFFF;
    --text: #2C3E50;
    --text-light: #7F8C8D;
    --border: #E1E8ED;
    --toolbar-height: 56px;
    --page-indicator-height: 60px;
    --font-size: 18px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
    overflow: hidden;
    font-family: 'Noto Sans SC', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--background);
    color: var(--text);
    font-size: var(--font-size);
    line-height: 1.8;
}

body {
    touch-action: manipulation;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-width: 100vw;
    overflow: hidden;
}

.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--toolbar-height);
    padding: 0 12px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.toolbar-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    color: white;
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.15s;
}

.toolbar-btn:active {
    background: rgba(255, 255, 255, 0.15);
}

.chapter-title {
    font-family: 'Noto Serif SC', serif;
    font-size: 17px;
    font-weight: 600;
    max-width: 50%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.toolbar-actions {
    display: flex;
    gap: 4px;
}

.reader-content {
    flex: 1;
    overflow: hidden;
    position: relative;
}

.page-container {
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

.page {
    background: var(--card);
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 16px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    animation: fadeIn 0.4s ease-out;
    min-height: calc(100vh - var(--toolbar-height) - var(--page-indicator-height) - 60px);
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.page-header {
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.page-title {
    font-family: 'Noto Serif SC', serif;
    font-size: 22px;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 8px;
}

.page-subtitle {
    font-size: 14px;
    color: var(--text-light);
}

.page-content {
    color: var(--text);
}

.page-content p {
    margin-bottom: 20px;
    text-align: justify;
    text-indent: 2em;
}

.reference-section {
    margin-top: 32px;
    padding-top: 20px;
    border-top: 2px dashed var(--border);
}

.reference-header {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 15px;
    font-weight: 600;
    color: var(--primary);
    margin-bottom: 12px;
}

.reference-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.reference-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px;
    background: #F8FAFC;
    border-radius: 8px;
    text-decoration: none;
    color: var(--text);
    transition: all 0.2s;
}

.reference-item:active {
    background: #EDF2F7;
}

.reference-icon {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #E3F2FD;
    color: #1976D2;
    border-radius: 6px;
}

.reference-info {
    flex: 1;
    min-width: 0;
}

.reference-title {
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.reference-reason {
    font-size: 12px;
    color: var(--text-light);
}

.no-reference {
    text-align: center;
    padding: 20px;
    color: var(--text-light);
    font-size: 14px;
}

.page-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 24px;
    height: var(--page-indicator-height);
    background: var(--card);
    border-top: 1px solid var(--border);
    padding: 0 16px;
}

.page-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border: none;
    background: var(--secondary);
    color: white;
    cursor: pointer;
    border-radius: 50%;
    transition: all 0.15s;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.page-btn:active {
    transform: scale(0.95);
    background: var(--primary);
}

.page-btn:disabled {
    background: #BDC3C7;
    cursor: not-allowed;
    box-shadow: none;
}

.page-info {
    font-size: 15px;
    font-weight: 500;
    color: var(--text-light);
    min-width: 60px;
    text-align: center;
}

.toc-panel {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 500;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.toc-panel.show {
    opacity: 1;
    visibility: visible;
}

.toc-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.toc-content {
    position: absolute;
    right: 0;
    top: 0;
    width: 280px;
    height: 100%;
    background: var(--card);
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.1);
    transform: translateX(100%);
    transition: transform 0.3s ease;
    overflow-y: auto;
    padding-top: var(--toolbar-height);
}

.toc-panel.show .toc-content {
    transform: translateX(0);
}

.toc-content h2 {
    font-family: 'Noto Serif SC', serif;
    font-size: 18px;
    padding: 20px;
    border-bottom: 1px solid var(--border);
    color: var(--primary);
}

.toc-list {
    list-style: none;
    padding: 12px;
}

.toc-list li {
    padding: 14px 16px;
    margin-bottom: 4px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 15px;
    transition: all 0.15s;
}

.toc-list li:active {
    background: rgba(0, 0, 0, 0.05);
}

.toc-list li.active {
    background: var(--primary);
    color: white;
}

.toc-list li .page-num {
    float: right;
    font-size: 12px;
    opacity: 0.7;
}

.tts-panel {
    position: fixed;
    bottom: calc(var(--page-indicator-height) + 10px);
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--card);
    border-radius: 12px;
    padding: 16px 24px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    z-index: 300;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    display: flex;
    gap: 16px;
    align-items: center;
}

.tts-panel.show {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

.tts-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

.tts-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border: none;
    background: var(--secondary);
    color: white;
    cursor: pointer;
    border-radius: 50%;
    transition: all 0.15s;
}

.tts-btn:active {
    transform: scale(0.95);
}

.tts-speed {
    display: flex;
    gap: 6px;
}

.speed-btn {
    padding: 6px 12px;
    border: 1px solid var(--border);
    background: white;
    color: var(--text);
    cursor: pointer;
    border-radius: 15px;
    font-size: 12px;
    transition: all 0.15s;
}

.speed-btn.active {
    background: var(--secondary);
    color: white;
    border-color: var(--secondary);
}

.ref-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 600;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.ref-modal.show {
    display: flex;
}

.ref-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
}

.ref-content {
    position: relative;
    background: var(--card);
    border-radius: 12px;
    padding: 24px;
    width: 100%;
    max-width: 400px;
    max-height: 70vh;
    overflow-y: auto;
    animation: modalIn 0.3s ease;
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}

.ref-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--text-light);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.15s;
}

.ref-close:active {
    background: rgba(0, 0, 0, 0.05);
}

.ref-title {
    font-family: 'Noto Serif SC', serif;
    font-size: 18px;
    margin-bottom: 16px;
    color: var(--primary);
    padding-right: 32px;
}

.ref-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ref-item {
    display: block;
    padding: 14px;
    background: #F8FAFC;
    border-radius: 8px;
    text-decoration: none;
    color: var(--text);
    transition: all 0.2s;
}

.ref-item:active {
    background: #EDF2F7;
}

.ref-item-title {
    font-size: 15px;
    font-weight: 500;
    margin-bottom: 6px;
}

.ref-item-reason {
    font-size: 13px;
    color: var(--text-light);
}

.slide-left {
    animation: slideInLeft 0.3s ease-out;
}

.slide-right {
    animation: slideInRight 0.3s ease-out;
}

@keyframes slideInLeft {
    from { transform: translateX(-30px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes slideInRight {
    from { transform: translateX(30px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@media (max-width: 480px) {
    :root {
        --toolbar-height: 50px;
        --font-size: 16px;
    }

    .chapter-title {
        font-size: 15px;
    }

    .page {
        padding: 20px;
    }

    .page-title {
        font-size: 20px;
    }

    .toc-content {
        width: 85%;
    }
}

@media (orientation: landscape) and (max-height: 500px) {
    .toolbar {
        height: 44px;
    }

    .page-indicator {
        height: 48px;
    }

    .page {
        min-height: calc(100vh - 44px - 48px - 30px);
    }
}
