/* Base typography */
html {
    color: #1a1a1a;
    background-color: #f9fafb;
    /* gray-50 */
    text-size-adjust: 100%;
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100vh;
    overflow: hidden;
    text-rendering: optimizeLegibility;
    font-kerning: normal;
}

/* Admin dashboard needs page-level scrolling; keep reader behavior unchanged */
.admin-body {
    height: auto;
    min-height: 100vh;
    overflow-y: auto;
}

#print-container {
    display: none;
}

/* Custom Scrollbar for Sidebar and Content */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #e5e7eb;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #d1d5db;
}

/* Navigation Active State */
.active-nav-item {
    background-color: #eff6ff;
    /* blue-50 */
    color: #2563eb;
    /* blue-600 */
}

.active-nav-item svg {
    color: #3b82f6;
    /* blue-500 */
}

/* Reader Content Styling */
#content {
    /* Restore MinerU/A4 typography but adapt to container */
    font-family: "Noto Serif SC", "Times New Roman", serif;
    font-size: 18px;
    /* Slightly larger for screen reading */
    line-height: 1.8;
    color: #1a1a1a;
    width: 100%;
    max-width: 100%;
}

/* Typography Improvements */
#content h1 {
    font-size: 2.25em;
    font-weight: 700;
    margin-top: 1.5em;
    margin-bottom: 0.8em;
    letter-spacing: -0.025em;
    border-bottom: 1px solid #e5e7eb;
    padding-bottom: 0.3em;
    line-height: 1.3;
}

#content h2 {
    font-size: 1.8em;
    font-weight: 600;
    margin-top: 1.4em;
    margin-bottom: 0.6em;
    letter-spacing: -0.025em;
    border-bottom: 1px solid #f3f4f6;
    padding-bottom: 0.3em;
    line-height: 1.35;
}

#content h3 {
    font-size: 1.5em;
    font-weight: 600;
    margin-top: 1.2em;
    margin-bottom: 0.5em;
    letter-spacing: -0.02em;
    line-height: 1.4;
}

#content h4 {
    font-size: 1.25em;
    font-weight: 600;
    margin-top: 1.1em;
    margin-bottom: 0.5em;
    letter-spacing: -0.015em;
}

#content h5 {
    font-size: 1.1em;
    font-weight: 600;
    margin-top: 1em;
    margin-bottom: 0.5em;
}

#content h6 {
    font-size: 1em;
    font-weight: 600;
    margin-top: 1em;
    margin-bottom: 0.5em;
    text-transform: uppercase;
    color: #6b7280;
    letter-spacing: 0.05em;
}

#content p {
    margin-bottom: 1.2em;
    text-align: justify;
    letter-spacing: -0.01em;
}

/* Table Styling */
#content table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.5em 0;
    font-size: 0.95em;
    display: block;
    overflow-x: auto;
}

#content th,
#content td {
    border: 1px solid #e5e7eb;
    padding: 0.75em;
    text-align: left;
}

#content th {
    background-color: #f9fafb;
    font-weight: 600;
    color: #374151;
}

#content tr:nth-child(even) {
    background-color: #f9fafb;
}

/* Math Formula Styling */
math {
    font-family: "Latin Modern Math", "Cambria Math", serif;
}

.formula,
.math-display {
    display: block;
    overflow-x: auto;
    margin: 1.5em 0;
    text-align: center;
    padding: 1em 0;
}

/* Interactive Reading Elements */
.word-container {
    display: inline-flex;
    flex-direction: column;
    text-align: center;
    vertical-align: bottom;
    margin: 0;
    padding-bottom: 4px;
    position: relative;
    /* Ensure positioning context */
}

.word {
    cursor: pointer;
    padding: 0 1px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.word:hover {
    background-color: #e0e7ff;
}

/* Translation Styling - Compact & Beautified */
.translation {
    font-size: 0.75em;
    color: #4b5563;
    background-color: #f3f4f6;
    padding: 0 4px;
    margin: 0 2px;
    white-space: nowrap;
    user-select: none;
    display: inline-block;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
    font-family: system-ui, -apple-system, sans-serif;
    font-weight: 500;
    vertical-align: 1px;
    border: 1px solid transparent;
}

.translation:hover {
    background-color: #e0e7ff;
    color: #2563eb;
    border-color: #bfdbfe;
}

.translation.ai-enhanced {
    color: #7c3aed;
    background-color: #f5f3ff;
}

.translation.ai-enhanced:hover {
    background-color: #ede9fe;
    color: #6d28d9;
    border-color: #ddd6fe;
}

/* Summarize Button */
.summarize-btn-container {
    display: none;
    text-align: right;
    margin-top: -0.5em;
    margin-bottom: 1em;
}

.summarize-btn {
    cursor: pointer;
    font-size: 0.8em;
    color: #4f46e5;
    background-color: #eef2ff;
    padding: 4px 12px;
    border-radius: 9999px;
    transition: all 0.2s ease-in-out;
    border: 1px solid transparent;
    font-family: system-ui, sans-serif;
}

.summarize-btn:hover {
    background-color: #e0e7ff;
    border-color: #c7d2fe;
}

/* Animations */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translate3d(0, 20px, 0);
    }

    to {
        opacity: 1;
        transform: translate3d(0, 0, 0);
    }
}

.animate-fade-in-up {
    animation: fadeInUp 0.3s ease-out forwards;
}

/* Markdown Content Styling (for AI response) */
#ai-response h1,
#ai-response h2,
#ai-response h3 {
    margin-top: 1em;
    margin-bottom: 0.5em;
    font-weight: bold;
}

#ai-response p {
    margin-bottom: 0.8em;
}

#ai-response ul,
#ai-response ol {
    margin-left: 1.5em;
    margin-bottom: 0.8em;
}

#ai-response li {
    margin-bottom: 0.3em;
}

#ai-response code {
    background-color: #f3f4f6;
    padding: 2px 4px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.9em;
}

/* Print Styles */
@media print {
    @page {
        size: A4;
        margin: 12mm;
    }

    #sidebar,
    header,
    #pagination-controls,
    #reading-settings,
    #content-area,
    #view-reader,
    #view-library {
        display: none !important;
    }

    body {
        background-color: white;
        height: auto;
        overflow: visible;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    #print-container {
        display: block !important;
        width: 100%;
    }

    #print-container #page-container {
        box-shadow: none !important;
        max-width: 210mm;
        margin: 0 auto;
        padding: 0;
    }

    #print-container img {
        max-width: 100%;
        height: auto;
        display: block;
        margin: 0 auto;
        page-break-inside: avoid;
    }

    #print-container .print-page-break {
        page-break-after: always;
    }

    #print-container table {
        page-break-inside: avoid;
    }

    /* 统一打印字号，避免屏幕字号/行内样式过大 */
    #print-container,
    #print-container #content,
    #print-container .print-page-container {
        font-size: 12px;
        line-height: 1.6;
    }

    #print-container p,
    #print-container h1,
    #print-container h2,
    #print-container h3,
    #print-container h4,
    #print-container h5,
    #print-container h6 {
        break-inside: avoid;
        page-break-inside: avoid;
    }

    #print-container .summarize-btn-container {
        display: none !important;
    }
}
