:root {
    --primary-color: #1a5490;
    --secondary-color: #2c7bb6;
    --text-color: #2c2c2c;
    --bg-color: #f8f9fa;
    --card-bg: #ffffff;
    --border-color: #dee2e6;
    --highlight-color: #e3f2fd;
    --divider-color: #adb5bd;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

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

body {
    font-family: 'Georgia', 'Songti SC', 'SimSun', serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
}

header {
    background: linear-gradient(135deg, var(--primary-color) 0%, #6d3610 100%);
    color: white;
    padding: 3rem 2rem;
    text-align: center;
    box-shadow: var(--shadow);
}

header h1 {
    font-size: 3rem;
    margin-bottom: 0.5rem;
    font-weight: normal;
    letter-spacing: 0.3rem;
}

header h2 {
    font-size: 1.5rem;
    font-weight: normal;
    opacity: 0.95;
    margin-bottom: 0.5rem;
}

.subtitle {
    font-size: 1rem;
    opacity: 0.85;
    font-style: italic;
}

main {
    max-width: 1400px;
    margin: 0 auto;
    padding: 3rem 2rem;
}

main:has(.reader-container) {
    max-width: 100%;
    padding: 0;
    margin: 0;
}

#loading {
    text-align: center;
    font-size: 1.2rem;
    color: var(--primary-color);
    padding: 4rem;
}

#histories-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 2rem;
}

.history-card {
    background: var(--card-bg);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    padding: 2rem;
    transition: all 0.3s ease;
    cursor: pointer;
    text-decoration: none;
    color: var(--text-color);
    display: block;
}

.history-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 16px rgba(139, 69, 19, 0.15);
    border-color: var(--secondary-color);
}

.history-card h3 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    color: var(--primary-color);
}

.history-card .pinyin {
    font-size: 1rem;
    color: #666;
    margin-bottom: 0.5rem;
    font-style: italic;
}

.history-card .english-name {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 1rem;
}

.history-card .dynasty {
    font-size: 0.9rem;
    color: #888;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.history-card .chapter-count {
    font-size: 0.85rem;
    color: var(--primary-color);
    margin-top: 0.5rem;
    font-weight: 500;
}

footer {
    text-align: center;
    padding: 2rem;
    color: #666;
    border-top: 1px solid var(--border-color);
    margin-top: 4rem;
}

footer a {
    color: var(--primary-color);
    text-decoration: none;
}

footer a:hover {
    text-decoration: underline;
}

/* Chapter listing page */
.chapter-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
    margin-top: 2rem;
}

.chapter-link {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 1.5rem;
    text-align: center;
    text-decoration: none;
    color: var(--text-color);
    transition: all 0.2s ease;
}

.chapter-link:hover {
    background: var(--highlight-color);
    border-color: var(--secondary-color);
}

/* Reader page */
.reader-wrapper {
    background: var(--card-bg);
    min-height: calc(100vh - 140px);
}

.reader-header {
    display: grid;
    grid-template-columns: 1fr 1px 1fr;
    position: sticky;
    top: 0;
    background: var(--card-bg);
    z-index: 100;
    border-bottom: 2px solid var(--primary-color);
}

.column-header {
    padding: 1rem 3rem;
    margin: 0;
    color: var(--primary-color);
    font-size: 1.1rem;
    font-weight: 600;
}

.reader-header::after {
    content: '';
    grid-column: 2;
    background: var(--divider-color);
}

.reader-content {
    display: grid;
    grid-template-columns: 1fr 1px 1fr;
    min-height: calc(100vh - 180px);
}

.reader-content::before {
    content: '';
    grid-column: 2;
    background: var(--divider-color);
    grid-row: 1 / -1;
}

.paragraph-row {
    display: contents;
}

.paragraph {
    padding: 1rem 3rem;
    margin: 0;
    border-radius: 0;
}

.paragraph.chinese {
    grid-column: 1;
}

.paragraph.english {
    grid-column: 3;
}

/* Mobile responsive styles */
@media (max-width: 768px) {
    .reader-header {
        grid-template-columns: 1fr;
    }
    
    .reader-header::after {
        display: none;
    }
    
    .english-header {
        border-top: 1px solid var(--divider-color);
    }
    
    .reader-content {
        grid-template-columns: 1fr;
    }
    
    .reader-content::before {
        display: none;
    }
    
    .column-header {
        padding: 0.75rem 1.25rem;
        font-size: 1rem;
    }
    
    .paragraph {
        padding: 0.75rem 1.25rem;
    }
    
    .paragraph.chinese {
        grid-column: 1;
        border-bottom: 1px solid var(--border-color);
    }
    
    .paragraph.english {
        grid-column: 1;
        border-bottom: 1px solid var(--divider-color);
        padding-bottom: 1.5rem;
    }
    
    .chinese-pane .paragraph {
        font-size: 1.1rem;
        line-height: 2;
    }
    
    .english-pane .paragraph {
        font-size: 1rem;
        line-height: 1.6;
    }
    
    main {
        padding: 1.5rem 1rem;
    }
    
    header {
        padding: 2rem 1rem;
    }
    
    header h1 {
        font-size: 2rem;
        letter-spacing: 0.2rem;
    }
    
    header h2 {
        font-size: 1.2rem;
    }
}

.paragraph.highlighted {
    background-color: var(--highlight-color);
}

.sentence {
    display: inline;
    padding: 2px 0;
    cursor: pointer;
    transition: background-color 0.2s ease;
    border-radius: 2px;
}

.sentence.highlighted {
    background-color: var(--highlight-color);
    box-shadow: 0 -2px 0 0 var(--secondary-color), 0 2px 0 0 var(--secondary-color);
}

.chinese-pane .paragraph {
    font-size: 1.3rem;
    line-height: 2.2;
}

.english-pane .paragraph {
    font-size: 1.1rem;
    line-height: 1.8;
}

.word {
    cursor: help;
    position: relative;
    border-bottom: 1px dotted transparent;
    transition: border-color 0.2s ease;
}

.word:hover {
    border-bottom-color: var(--primary-color);
}

.tooltip {
    position: absolute;
    background: white;
    border: 2px solid var(--primary-color);
    border-radius: 4px;
    padding: 1rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    z-index: 1000;
    max-width: 300px;
    font-size: 0.9rem;
}

.tooltip .pinyin {
    color: var(--primary-color);
    font-weight: bold;
    margin-bottom: 0.5rem;
}

.tooltip .definitions {
    margin-top: 0.5rem;
}

.tooltip .definitions li {
    margin: 0.25rem 0;
}

.back-link {
    display: inline-block;
    color: var(--primary-color);
    text-decoration: none;
    margin-bottom: 1rem;
    font-weight: 600;
}

.back-link:hover {
    text-decoration: underline;
}

.view-controls {
    display: flex;
    gap: 0.5rem;
}

.view-btn {
    background: rgba(255, 255, 255, 0.15);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

.view-btn:hover {
    background: rgba(255, 255, 255, 0.25);
}

.view-btn.active {
    background: rgba(255, 255, 255, 0.9);
    color: var(--primary-color);
    border-color: white;
}

.cite-btn {
    background: rgba(255, 255, 255, 0.15);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

.cite-btn:hover {
    background: rgba(255, 255, 255, 0.25);
}

.cite-paragraph-btn {
    background: var(--bg-color);
    color: var(--primary-color);
    border: 1px solid var(--border-color);
    padding: 0.25rem 0.5rem;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.75rem;
    margin-left: 0.5rem;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.paragraph:hover .cite-paragraph-btn {
    opacity: 1;
}

.cite-paragraph-btn:hover {
    background: var(--highlight-color);
    border-color: var(--primary-color);
}

/* Modal styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: var(--card-bg);
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    max-width: 700px;
    width: 90%;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 2px solid var(--border-color);
}

.modal-header h3 {
    margin: 0;
    color: var(--primary-color);
    font-size: 1.3rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 2rem;
    color: #999;
    cursor: pointer;
    line-height: 1;
    padding: 0;
    width: 2rem;
    height: 2rem;
}

.modal-close:hover {
    color: var(--text-color);
}

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
}

.citation-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.citation-tab {
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    padding: 0.75rem 1rem;
    cursor: pointer;
    color: #666;
    font-weight: 500;
    transition: all 0.2s ease;
}

.citation-tab:hover {
    color: var(--primary-color);
}

.citation-tab.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

.citation-content {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

#citation-text {
    width: 100%;
    min-height: 150px;
    padding: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-family: 'Georgia', serif;
    font-size: 0.95rem;
    line-height: 1.6;
    resize: vertical;
}

#citation-text:focus {
    outline: 2px solid var(--secondary-color);
    border-color: var(--secondary-color);
}

.btn-primary {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.95rem;
    transition: all 0.2s ease;
    align-self: flex-start;
}

.btn-primary:hover {
    background: var(--secondary-color);
}

.chapter-title {
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--border-color);
}

.chapter-title h2 {
    color: var(--primary-color);
    font-size: 1.8rem;
    margin-bottom: 0.5rem;
}

.chapter-title .subtitle {
    color: #666;
    font-style: italic;
}
