:root {
    color-scheme: light dark;
    /* Light Mode */
    --background: #fbf9f4;
    --surface: #ffffff;
    --surface-soft: #f2ece0;
    --text: #2c2824;
    --muted: #82786d;
    --line: #e6ded1;
    --accent: #8b3a26;
    --accent-soft: #f2dfda;
    --shadow: 0 12px 40px rgba(0, 0, 0, 0.05);
    
    --bg-gradient: linear-gradient(90deg, rgba(139, 58, 38, 0.03), transparent 32%, transparent 68%, rgba(51, 83, 91, 0.03));
    --surface-translucent: rgba(255, 255, 255, 0.75);
    --toolbar-translucent: rgba(251, 249, 244, 0.85);
    --note-bg: rgba(255, 255, 255, 0.85);

    /* Typography */
    --font-ui: "Inter", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --font-body: "Charter", "Iowan Old Style", "Georgia", "Times New Roman", serif;
    --font-body-zh: "Noto Serif SC", "Songti SC", "Source Han Serif SC", STSong, SimSun, serif;
    
    /* Layout */
    --max-reading-width: 820px;
    --max-parallel-width: 1280px;
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    
    --base-font-size: 18px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --background: #18181a;
        --surface: #222224;
        --surface-soft: #2e2e30;
        --text: #e0e0e0;
        --muted: #9e9e9e;
        --line: #3a3a3c;
        --accent: #d27963;
        --accent-soft: #422c27;
        --shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
        
        --bg-gradient: linear-gradient(90deg, rgba(210, 121, 99, 0.05), transparent 32%, transparent 68%, rgba(80, 130, 142, 0.05));
        --surface-translucent: rgba(34, 34, 36, 0.75);
        --toolbar-translucent: rgba(24, 24, 26, 0.85);
        --note-bg: rgba(46, 46, 48, 0.85);
    }
}

* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    background: var(--bg-gradient), var(--background);
    color: var(--text);
    font-family: var(--font-body);
    transition: background-color 0.3s ease, color 0.3s ease;
}

body:lang(zh-CN) {
    font-family: var(--font-body-zh);
}

button,
input {
    font: inherit;
}

a {
    color: inherit;
    transition: var(--transition);
}

.reader-shell {
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
    min-height: 100vh;
}

.reader-sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    padding: 32px 20px;
    overflow-y: auto;
    border-right: 1px solid var(--line);
    background: var(--surface-translucent);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

/* Custom scrollbar for sidebar */
.reader-sidebar::-webkit-scrollbar {
    width: 6px;
}
.reader-sidebar::-webkit-scrollbar-track {
    background: transparent;
}
.reader-sidebar::-webkit-scrollbar-thumb {
    background: var(--line);
    border-radius: 4px;
}

.reader-brand {
    display: block;
    margin-bottom: 32px;
    padding: 0 10px 24px;
    border-bottom: 1px solid var(--line);
    text-decoration: none;
}

.reader-brand:hover .reader-brand-title {
    color: var(--accent);
}

.reader-brand-title,
.reader-brand-subtitle {
    display: block;
}

.reader-brand-title {
    font-size: 24px;
    font-weight: 700;
    transition: var(--transition);
}

.reader-brand-subtitle {
    margin-top: 6px;
    color: var(--muted);
    font-size: 13px;
    font-family: var(--font-ui);
}

.toc {
    display: grid;
    gap: 4px;
}

.toc a {
    display: block;
    padding: 10px 12px;
    border-radius: 8px;
    color: var(--muted);
    text-decoration: none;
    font-family: var(--font-ui);
    font-size: 14px;
    line-height: 1.4;
    transition: var(--transition);
}

.toc a:hover {
    background: var(--surface-soft);
    color: var(--text);
    transform: translateX(4px);
}

.toc a.active {
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 500;
}

.reader-main {
    min-width: 0;
}

.reader-toolbar {
    position: sticky;
    top: 0;
    z-index: 5;
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: center;
    justify-content: space-between;
    padding: 16px clamp(20px, 5vw, 64px);
    border-bottom: 1px solid var(--line);
    background: var(--toolbar-translucent);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.toolbar-button {
    display: none;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    padding: 8px 14px;
    text-decoration: none;
    cursor: pointer;
    font-family: var(--font-ui);
    font-size: 14px;
    transition: var(--transition);
    box-shadow: 0 2px 4px rgba(0,0,0,0.02);
    align-items: center;
    justify-content: center;
}

.toolbar-button:hover {
    border-color: var(--muted);
    background: var(--surface-soft);
}

.language-controls {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-wrap: wrap; /* allow wrapping on small screens */
}

.toolbar-divider {
    width: 1px;
    height: 18px;
    background: var(--line);
    margin: 0 4px;
}

.language-button {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--muted);
    padding: 8px 12px;
    cursor: pointer;
    font-family: var(--font-ui);
    font-size: 13px;
    font-weight: 500;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.language-button:hover {
    border-color: var(--muted);
    color: var(--text);
    background: var(--surface-soft);
}

.language-button.active {
    border-color: var(--accent);
    background: var(--accent-soft);
    color: var(--accent);
}

.search-label {
    display: block;
    flex: 1;
    max-width: 320px;
    position: relative;
}

.search-label span {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

.search-label input {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    padding: 8px 14px;
    color: var(--text);
    transition: var(--transition);
    font-family: var(--font-ui);
    font-size: 13px;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.01);
}

.search-label input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.search-label input::placeholder {
    color: var(--muted);
    opacity: 0.6;
}

.search-results {
    margin: 24px clamp(20px, 5vw, 64px) 0;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface);
    box-shadow: var(--shadow);
    font-family: var(--font-ui);
}

.search-result {
    display: block;
    padding: 14px;
    border-radius: 8px;
    text-decoration: none;
    transition: var(--transition);
}

.search-result:hover {
    background: var(--surface-soft);
    transform: translateX(4px);
}

.search-result strong {
    display: block;
    color: var(--accent);
    font-size: 15px;
    margin-bottom: 6px;
}

.search-result span {
    display: block;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.5;
}

.reader-article {
    width: 100%;
    max-width: var(--max-reading-width);
    margin: 0 auto;
    padding: 72px 32px 64px;
    transition: max-width 0.3s ease;
}

body.is-parallel .reader-article {
    max-width: var(--max-parallel-width);
}

.eyebrow {
    margin: 0 0 16px;
    color: var(--accent);
    font-family: var(--font-ui);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.15em;
}

#page-title {
    margin: 0;
    font-size: clamp(40px, 6vw, 64px);
    line-height: 1.1;
    letter-spacing: -0.02em;
    font-weight: 700;
}

.page-meta {
    margin-top: 20px;
    color: var(--muted);
    font-family: var(--font-ui);
    font-size: 14px;
}

.translation-notice {
    margin: 32px 0 0;
    border-left: 4px solid var(--accent);
    background: var(--accent-soft);
    padding: 16px 20px;
    border-radius: 0 8px 8px 0;
    color: var(--text);
    font-family: var(--font-ui);
    font-size: 14px;
    line-height: 1.6;
}

.content {
    margin-top: 56px;
}

.content h1,
.content h2,
.content h3,
.content h4 {
    margin: 56px 0 24px;
    line-height: 1.2;
    letter-spacing: -0.01em;
    font-weight: 700;
    color: var(--text);
}

.content h1 {
    font-size: calc(var(--base-font-size) * 2);
}

.content h2 {
    font-size: calc(var(--base-font-size) * 1.55);
    border-bottom: 1px solid var(--line);
    padding-bottom: 8px;
}

.content h3,
.content h4 {
    font-size: calc(var(--base-font-size) * 1.25);
}

.content p {
    margin: 0 0 24px;
    font-size: var(--base-font-size);
    line-height: 1.8;
}

.content .parallel-block {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 32px;
    max-width: 100%;
    margin: 0 0 32px;
    padding-bottom: 32px;
    border-bottom: 1px solid var(--line);
}

.content .parallel-column > * {
    margin-top: 0;
}

.content .source-column {
    color: var(--muted);
    font-size: 0.95em;
}

.content .note {
    margin: 24px 0;
    padding: 18px 24px;
    border-left: 4px solid var(--accent);
    background: var(--note-bg);
    border-radius: 0 12px 12px 0;
    color: var(--text);
    font-size: calc(var(--base-font-size) * 0.85);
    line-height: 1.7;
    box-shadow: 0 2px 12px rgba(0,0,0,0.02);
}

.content .note-label {
    margin-right: 8px;
    color: var(--accent);
    font-family: var(--font-ui);
    font-weight: 600;
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.content .separator {
    width: 120px;
    margin: 56px auto;
    border: 0;
    border-top: 1px solid var(--line);
    position: relative;
}
.content .separator::after {
    content: "✦";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--background);
    padding: 0 16px;
    color: var(--muted);
    font-size: 14px;
}

.table-wrap {
    max-width: 100%;
    margin: 32px 0;
    overflow-x: auto;
    border-radius: 12px;
    border: 1px solid var(--line);
}

.content table {
    border-collapse: collapse;
    width: 100%;
    min-width: 600px;
    background: var(--surface);
    font-size: calc(var(--base-font-size) * 0.9);
}

.content th {
    background: var(--surface-soft);
    font-weight: 600;
    text-align: left;
    padding: 14px 16px;
    border-bottom: 2px solid var(--line);
    font-family: var(--font-ui);
}

.content td {
    border-bottom: 1px solid var(--line);
    padding: 14px 16px;
    vertical-align: top;
    line-height: 1.6;
}

.page-nav {
    display: flex;
    justify-content: space-between;
    gap: 24px;
    margin-top: 80px;
    padding-top: 32px;
    border-top: 1px solid var(--line);
}

.page-nav-link {
    flex: 1;
    max-width: 240px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface);
    padding: 16px 20px;
    text-align: center;
    text-decoration: none;
    font-family: var(--font-ui);
    font-weight: 500;
    color: var(--text);
    transition: var(--transition);
    box-shadow: 0 2px 8px rgba(0,0,0,0.02);
}

.page-nav-link:hover {
    border-color: var(--accent);
    color: var(--accent);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0,0,0,0.06);
}

.page-nav-link[aria-disabled="true"] {
    pointer-events: none;
    opacity: 0.4;
    background: transparent;
    box-shadow: none;
}

.reader-footer {
    max-width: var(--max-reading-width);
    margin: 0 auto;
    padding: 0 32px 64px;
    color: var(--muted);
    font-family: var(--font-ui);
    font-size: 14px;
    line-height: 1.6;
    text-align: center;
}

@media (max-width: 860px) {
    .reader-shell {
        display: block;
    }

    .reader-sidebar {
        position: fixed;
        inset: 68px 0 auto 0;
        z-index: 10;
        display: none;
        height: calc(100vh - 68px);
        border-right: 0;
        border-bottom: 1px solid var(--line);
        background: var(--surface);
    }

    .reader-sidebar.open {
        display: block;
        animation: slideDown 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    }

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

    .reader-toolbar {
        padding: 12px 20px;
    }

    .language-controls {
        flex: 1;
        justify-content: flex-end;
    }

    .search-label {
        flex: 1 1 100%;
        max-width: 100%;
        margin-top: 4px;
    }

    .content .parallel-block {
        grid-template-columns: minmax(0, 1fr);
        gap: 16px;
    }

    .toolbar-button {
        display: inline-flex;
    }

    .reader-article {
        padding: 48px 24px 40px;
    }

    .content p {
        /* let the var(--base-font-size) control it */
        line-height: 1.7;
    }
}

@media (max-width: 560px) {
    /* removed unneeded grid overrides */
    #page-title {
        font-size: 36px;
    }

    .page-nav {
        flex-direction: column;
    }
    .page-nav-link {
        max-width: 100%;
    }
}
