/* ============================================================
   THE IMPERIAL CODEX - Design System
   A luxurious editorial aesthetic inspired by Renaissance
   manuscripts and classical antiquarian book design.
   ============================================================ */

/* --- Design Tokens --- */
:root {
    /* Primary Palette */
    --oxblood: #6B1D2A;
    --oxblood-light: #8A2E3B;
    --oxblood-dark: #4A1018;
    --gold: #C5A55A;
    --gold-muted: #B89B4A;
    --gold-light: #D9C88E;
    --gold-glow: rgba(197, 165, 90, 0.15);

    /* Neutral Palette */
    --ink: #1A1A2E;
    --ink-soft: #2D2D44;
    --stone: #8C7B6B;
    --stone-light: #A89888;
    --bronze: #9E7C5A;

    /* Background Palette */
    --ivory: #F8F4EC;
    --vellum: #EDE8DC;
    --parchment: #F3EEE4;
    --cream: #FDFAF3;
    --panel-bg: #FEFDFB;
    --panel-border: #E6DFD3;

    /* Accent */
    --navy: #2C3E50;
    --navy-light: #34495E;

    /* Typography */
    --font-display: 'Cormorant Garamond', 'Garamond', 'Georgia', serif;
    --font-body: 'Lora', 'Georgia', serif;
    --font-ui: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-chinese: 'Noto Serif SC', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', serif;

    /* Spacing */
    --panel-padding: 28px;
    --radius: 10px;
    --radius-sm: 6px;
    --radius-lg: 16px;

    /* Shadows */
    --shadow-subtle: 0 1px 8px rgba(26, 26, 46, 0.06);
    --shadow-elevated: 0 4px 20px rgba(26, 26, 46, 0.10);
    --shadow-deep: 0 8px 40px rgba(26, 26, 46, 0.12);
    --shadow-inner: inset 0 1px 3px rgba(26, 26, 46, 0.04);

    /* Transitions */
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    --duration: 0.3s;
    --duration-slow: 0.5s;
}

/* --- Reset & Base --- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-ui);
    background: var(--ivory);
    color: var(--ink);
    line-height: 1.6;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Subtle noise texture overlay on body */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
    opacity: 0.025;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
    background-repeat: repeat;
    background-size: 256px 256px;
}

/* --- Main Layout --- */
.reader-container {
    display: grid;
    grid-template-columns: 320px 1fr 360px;
    height: 100vh;
    gap: 0;
    padding: 0;
    transition: grid-template-columns var(--duration) var(--ease-out);
}

/* --- Panel Base --- */
.left-panel, .center-panel, .right-panel {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--panel-bg);
}

/* --- Left Panel: Table of Contents --- */
.left-panel {
    background: var(--cream);
    border-right: 1px solid var(--panel-border);
}

.panel-header {
    padding: 24px 24px 20px;
    border-bottom: 1px solid var(--panel-border);
    background: var(--cream);
    position: relative;
}

.panel-header h2 {
    font-family: var(--font-display);
    color: var(--ink);
    font-weight: 600;
    font-size: 1.5em;
    letter-spacing: 0.02em;
    margin-bottom: 16px;
    text-align: center;
    padding-right: 0;
}

.mobile-panel-close {
    display: none;
    position: absolute;
    top: 14px;
    right: 14px;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 1px solid var(--panel-border);
    background: white;
    color: var(--stone);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    transition: all 0.2s var(--ease-out);
}

.mobile-panel-close:hover {
    color: var(--oxblood);
    border-color: var(--gold);
    box-shadow: var(--shadow-subtle);
}

.search-box input {
    width: 100%;
    padding: 11px 16px;
    border: 1px solid var(--panel-border);
    border-radius: var(--radius-sm);
    font-family: var(--font-ui);
    font-size: 14px;
    background: white;
    color: var(--ink);
    transition: all var(--duration) var(--ease-out);
}

.search-box input::placeholder {
    color: var(--stone-light);
    font-style: italic;
}

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

/* TOC Content */
.toc-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px 14px;
    min-height: 0;
}

.volume-section {
    margin-bottom: 6px;
}

.volume-header {
    background: var(--vellum);
    color: var(--ink);
    padding: 14px 18px;
    border-radius: var(--radius-sm);
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 15px;
    letter-spacing: 0.02em;
    margin-bottom: 4px;
    cursor: pointer;
    user-select: none;
    transition: all var(--duration) var(--ease-out);
    position: relative;
    line-height: 1.5;
    border-left: 3px solid var(--gold);
}

.volume-header:hover {
    background: var(--parchment);
    border-left-color: var(--bronze);
    transform: translateX(2px);
    box-shadow: var(--shadow-subtle);
}

.volume-header::after {
    content: '+';
    position: absolute;
    right: 16px;
    top: 14px;
    font-size: 16px;
    font-family: var(--font-ui);
    font-weight: 400;
    color: var(--stone);
    transition: transform var(--duration) var(--ease-out);
}

.volume-header.expanded {
    background: white;
    border-left-color: var(--bronze);
    box-shadow: var(--shadow-subtle);
}

.volume-header.expanded::after {
    content: '\2212';
    transform: none;
}

.chapter-list {
    margin-left: 0;
    display: none;
    padding: 4px 0;
}

.chapter-list.expanded {
    display: block;
}

.chapter-item {
    padding: 10px 14px;
    margin: 2px 4px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 14px;
    line-height: 1.55;
    border-left: 2px solid transparent;
    transition: all 0.2s var(--ease-out);
    color: var(--ink-soft);
}

.chapter-item:hover {
    background: var(--vellum);
    border-left-color: var(--gold);
    transform: translateX(3px);
    color: var(--ink);
}

.chapter-item.active,
.chapter-item.current-reading {
    background: var(--vellum);
    color: var(--ink);
    border-left-color: var(--bronze);
    font-weight: 600;
    box-shadow: var(--shadow-subtle);
}

.chapter-item.current-reading {
    background: linear-gradient(135deg, rgba(197, 165, 90, 0.15), rgba(197, 165, 90, 0.25));
    color: var(--ink);
    border-left-color: var(--gold);
}

.part-label {
    font-family: var(--font-ui);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--gold-muted);
    display: block;
    margin-bottom: 2px;
}

.part-name {
    font-family: var(--font-display);
    font-size: 13px;
    font-weight: 500;
    color: var(--ink-soft);
    display: block;
    line-height: 1.4;
}

.chinese-subtitle {
    font-family: var(--font-chinese);
    color: var(--ink-soft);
    font-size: 0.9em;
    font-style: normal;
    display: block;
    margin-top: 3px;
    font-weight: 400;
    line-height: 1.5;
}

.english-subtitle {
    font-family: var(--font-display);
    color: var(--stone);
    font-size: 0.8em;
    font-style: italic;
    display: block;
    margin-top: 2px;
    font-weight: 400;
    line-height: 1.4;
}

.part-summary {
    font-family: var(--font-chinese);
    font-size: 12px;
    color: var(--stone);
    display: block;
    line-height: 1.4;
    margin-top: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.volume-header .chinese-subtitle {
    color: var(--stone);
}

.volume-header .english-subtitle {
    color: var(--stone-light);
    font-size: 0.78em;
}

.volume-header.expanded .chinese-subtitle {
    color: var(--stone);
}

/* --- Center Panel: Reading Area --- */
.center-panel {
    background: white;
    box-shadow: var(--shadow-deep);
    z-index: 1;
    position: relative;
}

.content-header {
    padding: 16px var(--panel-padding);
    border-bottom: 1px solid var(--panel-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(to bottom, white, var(--cream));
    flex-shrink: 0;
    gap: 12px;
}

.breadcrumb {
    flex: 1;
    min-width: 0;
}

.volume-title {
    font-family: var(--font-display);
    font-size: 15px;
    color: var(--oxblood);
    font-weight: 600;
    letter-spacing: 0.02em;
}

.chapter-title {
    font-family: var(--font-ui);
    font-size: 12px;
    color: var(--stone);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Control Buttons */
.reading-controls {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.control-btn {
    padding: 7px 12px;
    border: 1px solid var(--panel-border);
    background: white;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
    font-family: var(--font-ui);
    color: var(--ink-soft);
    transition: all 0.2s var(--ease-out);
}

.control-btn:hover {
    background: var(--vellum);
    border-color: var(--gold);
    color: var(--ink);
    transform: translateY(-1px);
    box-shadow: var(--shadow-subtle);
}

.control-btn:active {
    transform: scale(0.96);
}

/* Prominent Home Button */
.home-btn-prominent {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 8px 16px;
    background: linear-gradient(135deg, var(--oxblood), var(--oxblood-light));
    color: var(--gold-light);
    border: 1px solid var(--oxblood);
    border-radius: 999px;
    cursor: pointer;
    font-family: var(--font-chinese);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.08em;
    transition: all 0.25s var(--ease-out);
    box-shadow: 0 2px 8px rgba(107, 29, 42, 0.25);
    white-space: nowrap;
}

.home-btn-prominent svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

.home-btn-prominent:hover {
    background: linear-gradient(135deg, var(--oxblood-light), var(--oxblood));
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(107, 29, 42, 0.35);
}

.home-btn-prominent:active {
    transform: scale(0.96);
    box-shadow: 0 1px 4px rgba(107, 29, 42, 0.2);
}

/* --- Reading Area --- */
.reading-area {
    flex: 1;
    overflow-y: auto;
    padding: 40px 48px;
    font-family: var(--font-body);
    font-size: 17px;
    line-height: 1.85;
    color: var(--ink);
}

/* Chapter content base */
.chapter-content {
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    width: auto !important;
    font-family: var(--font-body);
    font-size: 17px;
    line-height: 1.85;
    color: var(--ink);
}

/* --- Chinese Font Support --- */
.chinese-text, .chinese-paragraph {
    font-family: var(--font-chinese);
    font-weight: 400;
}

/* --- Bilingual Content Styles --- */
.bilingual-content {
    max-width: 100%;
}

.paragraph-pair {
    margin-bottom: 40px;
    padding-bottom: 36px;
    border-bottom: 1px solid rgba(197, 165, 90, 0.15);
    position: relative;
}

.paragraph-pair:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

/* Drop cap for first English paragraph */
.paragraph-pair:first-child .english-paragraph::first-letter {
    font-family: var(--font-display);
    float: left;
    font-size: 3.6em;
    line-height: 0.8;
    padding-right: 10px;
    padding-top: 6px;
    color: var(--oxblood);
    font-weight: 700;
}

.english-paragraph, .chinese-paragraph {
    margin-bottom: 16px;
    padding: 20px 24px;
    border-radius: var(--radius);
    transition: all var(--duration) var(--ease-out);
}

.english-paragraph {
    font-family: var(--font-body);
    background: linear-gradient(135deg, rgba(248, 244, 236, 0.5), rgba(237, 232, 220, 0.3));
    border-left: 3px solid var(--gold);
    font-size: 17px;
    line-height: 1.85;
    color: var(--ink);
}

.english-paragraph:hover {
    background: linear-gradient(135deg, rgba(248, 244, 236, 0.7), rgba(237, 232, 220, 0.5));
    box-shadow: var(--shadow-subtle);
}

.chinese-paragraph {
    font-family: var(--font-chinese);
    background: linear-gradient(135deg, rgba(107, 29, 42, 0.03), rgba(107, 29, 42, 0.06));
    border-left: 3px solid var(--oxblood);
    font-size: 16px;
    line-height: 1.95;
    color: var(--ink-soft);
}

.chinese-paragraph:hover {
    background: linear-gradient(135deg, rgba(107, 29, 42, 0.05), rgba(107, 29, 42, 0.08));
    box-shadow: var(--shadow-subtle);
}

.english-paragraph.hidden, .chinese-paragraph.hidden {
    display: none;
}

/* Language Mode Styles */
.reading-area.bilingual-mode .paragraph-pair {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}

.reading-area.bilingual-mode .english-paragraph,
.reading-area.bilingual-mode .chinese-paragraph {
    margin-bottom: 0;
}

.reading-area.english-mode .chinese-paragraph {
    display: none;
}

.reading-area.chinese-mode .english-paragraph {
    display: none;
}

.reading-area.chinese-mode .chinese-paragraph {
    border-left-color: var(--gold);
    background: linear-gradient(135deg, rgba(197, 165, 90, 0.06), rgba(197, 165, 90, 0.12));
}

/* Chapter content overrides for loaded HTML */
.chapter-content * {
    max-width: 100% !important;
    box-sizing: border-box !important;
}

.chapter-content body {
    margin: 0 !important;
    padding: 0 !important;
    width: auto !important;
}

.chapter-content p,
.chapter-content div,
.chapter-content h1,
.chapter-content h2,
.chapter-content h3,
.chapter-content h4,
.chapter-content h5,
.chapter-content h6 {
    margin-left: 0 !important;
    margin-right: 0 !important;
    width: auto !important;
    max-width: 100% !important;
}

/* --- Welcome Message --- */
.welcome-message {
    text-align: center;
    max-width: 640px;
    margin: 0 auto;
    padding: 48px 24px 60px;
    animation: fadeInUp 0.8s var(--ease-out) both;
}

/* Hero Section */
.welcome-hero {
    position: relative;
    padding: 44px 20px 36px;
    margin: 0 -24px 32px;
    background:
        radial-gradient(ellipse at 30% 20%, rgba(107, 29, 42, 0.06), transparent 60%),
        radial-gradient(ellipse at 70% 80%, rgba(197, 165, 90, 0.08), transparent 50%),
        linear-gradient(180deg, var(--cream) 0%, white 100%);
    border-bottom: 1px solid rgba(197, 165, 90, 0.2);
    overflow: hidden;
}

.welcome-hero::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 200px;
    height: 200px;
    background: radial-gradient(circle, rgba(197, 165, 90, 0.12), transparent 70%);
    border-radius: 50%;
    pointer-events: none;
}

.welcome-overline {
    font-family: var(--font-ui);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.28em;
    text-transform: uppercase;
    color: var(--gold-muted);
    margin-bottom: 16px;
    animation: fadeInUp 0.6s var(--ease-out) 0.1s both;
}

.welcome-message h1 {
    font-family: var(--font-display);
    color: var(--oxblood);
    font-size: 2.6em;
    font-weight: 700;
    margin-bottom: 8px;
    letter-spacing: 0.02em;
    line-height: 1.2;
    animation: fadeInUp 0.7s var(--ease-out) 0.15s both;
}

.welcome-title-cn {
    font-family: var(--font-chinese);
    color: var(--ink);
    font-size: 1.5em;
    font-weight: 600;
    margin-bottom: 8px;
    letter-spacing: 0.12em;
    animation: fadeInUp 0.7s var(--ease-out) 0.2s both;
}

.welcome-message h2 {
    font-family: var(--font-display);
    color: var(--stone);
    font-size: 1.15em;
    font-weight: 400;
    font-style: italic;
    margin-bottom: 0;
    letter-spacing: 0.04em;
    animation: fadeInUp 0.7s var(--ease-out) 0.25s both;
}

/* Decorative Divider */
.welcome-divider {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin: 0 0 28px;
    animation: fadeIn 0.8s var(--ease-out) 0.4s both;
}

.welcome-divider::before,
.welcome-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--gold-muted), transparent);
    max-width: 80px;
}

.welcome-divider-icon {
    width: 28px;
    height: 28px;
    border: 1px solid var(--gold-muted);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-display);
    font-size: 12px;
    color: var(--gold-muted);
    font-weight: 700;
    background: white;
}

.intro {
    font-family: var(--font-body);
    font-size: 1.05em;
    color: var(--ink-soft);
    margin-bottom: 32px;
    text-align: justify;
    line-height: 1.8;
}

.personal-story {
    background: linear-gradient(135deg, var(--cream), var(--vellum));
    padding: 24px 24px;
    border-radius: var(--radius-lg);
    border-left: 4px solid var(--gold);
    margin-bottom: 28px;
    font-family: var(--font-chinese);
    font-size: 14.5px;
    line-height: 1.85;
    color: var(--ink-soft);
    box-shadow: var(--shadow-subtle);
    text-align: left;
    animation: fadeInUp 0.6s var(--ease-out) 0.35s both;
}

.personal-story p {
    margin-bottom: 14px;
    line-height: 1.85;
    color: var(--ink-soft);
}

.personal-story p:last-child {
    margin-bottom: 0;
}

.personal-story strong {
    color: var(--oxblood);
    font-weight: 600;
}

.personal-story a {
    color: var(--oxblood);
    text-decoration: none;
    font-weight: 500;
    border-bottom: 1px solid rgba(107, 29, 42, 0.3);
    transition: all 0.2s var(--ease-out);
}

.personal-story a:hover {
    color: var(--oxblood-light);
    border-bottom-color: var(--oxblood);
}

/* Volume Section Header */
.welcome-section-label {
    font-family: var(--font-ui);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--stone-light);
    margin-bottom: 14px;
    text-align: left;
    animation: fadeInUp 0.5s var(--ease-out) 0.4s both;
}

/* Volume Cards on Welcome Page */
.welcome-volumes {
    margin-top: 0;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    text-align: left;
}

.volume-card {
    background: white;
    padding: 14px 16px;
    border-radius: var(--radius);
    border: 1px solid var(--panel-border);
    cursor: pointer;
    transition: all var(--duration) var(--ease-out);
    position: relative;
    overflow: hidden;
}

.volume-card::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--gold);
    transition: width var(--duration) var(--ease-out);
}

.volume-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-elevated);
    border-color: var(--gold);
}

.volume-card:hover::before {
    width: 5px;
    background: var(--oxblood);
}

.volume-card .vol-number {
    font-family: var(--font-display);
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--gold-muted);
    margin-bottom: 3px;
}

.volume-card .vol-title {
    font-family: var(--font-display);
    font-size: 13px;
    font-weight: 600;
    color: var(--ink);
    line-height: 1.4;
}

.volume-card .vol-title-cn {
    font-family: var(--font-chinese);
    font-size: 12px;
    color: var(--stone);
    margin-top: 2px;
    line-height: 1.5;
}

.volume-card .vol-chapters {
    font-family: var(--font-ui);
    font-size: 10px;
    color: var(--stone-light);
    margin-top: 5px;
}

.clickable-volume {
    cursor: pointer;
    transition: all 0.2s var(--ease-out);
}

.clickable-volume:hover {
    background: var(--vellum);
    border-left-color: var(--oxblood);
    transform: translateX(4px);
    box-shadow: var(--shadow-subtle);
}

.chapter-count {
    color: var(--stone);
    font-size: 12px;
    float: right;
}

/* Sponsor Button */
.sponsor-section {
    margin-top: 18px;
    text-align: center;
}

.sponsor-button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 28px;
    background: linear-gradient(135deg, var(--gold-muted), var(--gold));
    color: var(--oxblood-dark);
    text-decoration: none;
    border-radius: 999px;
    font-family: var(--font-chinese);
    font-weight: 700;
    font-size: 13px;
    letter-spacing: 0.06em;
    border: 1px solid var(--gold);
    box-shadow: 0 2px 12px rgba(197, 165, 90, 0.3);
    transition: all var(--duration) var(--ease-out);
}

.sponsor-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 24px rgba(197, 165, 90, 0.4);
    background: linear-gradient(135deg, var(--gold), var(--gold-light));
    color: var(--oxblood-dark);
    border-color: var(--gold-light);
}

/* --- Right Panel: Interactive Elements --- */
.right-panel {
    background: var(--cream);
    border-left: 1px solid var(--panel-border);
}

.panel-tabs {
    display: flex;
    border-bottom: 1px solid var(--panel-border);
    background: white;
    padding: 0;
    position: relative;
}

.tab-btn {
    flex: 1;
    padding: 14px 12px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-family: var(--font-ui);
    font-weight: 500;
    font-size: 13px;
    color: var(--stone);
    border-bottom: 2px solid transparent;
    transition: all 0.2s var(--ease-out);
    letter-spacing: 0.02em;
}

.tab-btn:hover {
    background: var(--vellum);
    color: var(--oxblood);
}

.tab-btn.active {
    color: var(--oxblood);
    border-bottom-color: var(--gold);
    background: linear-gradient(to bottom, white, var(--cream));
    font-weight: 600;
}

.mobile-panel-close-right {
    right: 10px;
    top: 9px;
    z-index: 2;
}

.tab-content {
    flex: 1;
    padding: var(--panel-padding);
    display: none;
    overflow-y: auto;
    min-height: 0;
}

.tab-content.active {
    display: flex;
    flex-direction: column;
}

.tab-header h3 {
    font-family: var(--font-display);
    color: var(--oxblood);
    font-size: 1.15em;
    font-weight: 600;
    margin-bottom: 16px;
    text-align: center;
    letter-spacing: 0.03em;
}

/* --- Map Styles --- */
#map-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

#interactive-map {
    height: 300px;
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-subtle);
    border: 1px solid var(--panel-border);
}

.map-legend {
    background: white;
    padding: 12px 14px;
    border-radius: var(--radius);
    border: 1px solid var(--panel-border);
    font-size: 12px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 5px 0;
    font-size: 12px;
    font-family: var(--font-ui);
    color: var(--ink-soft);
}

.legend-color {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

.legend-color.capital { background: var(--oxblood); }
.legend-color.province { background: var(--gold); }
.legend-color.frontier { background: var(--bronze); }

#map-legend {
    background: white;
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    padding: 12px 14px;
    margin: 8px 0;
    box-shadow: var(--shadow-subtle);
    max-height: 240px;
    overflow-y: auto;
}

.legend-location-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 8px;
    margin: 2px 0;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s var(--ease-out);
}

.legend-location-item:hover {
    background: var(--vellum);
    transform: translateX(2px);
}

.legend-location-item:active {
    transform: scale(0.98);
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 2px solid white;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
    flex-shrink: 0;
}

.legend-location-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.legend-location-name {
    font-family: var(--font-ui);
    font-size: 12px;
    font-weight: 600;
    color: var(--ink-soft);
    line-height: 1.3;
}

.legend-location-type {
    font-family: var(--font-ui);
    font-size: 10px;
    color: var(--stone);
    letter-spacing: 0.02em;
}

/* --- Characters Styles --- */
.characters-list {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.character-card {
    background: white;
    padding: 18px 20px;
    border-radius: var(--radius);
    border: 1px solid var(--panel-border);
    box-shadow: var(--shadow-subtle);
    transition: all var(--duration) var(--ease-out);
    position: relative;
    overflow: hidden;
}

.character-card::after {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--gold);
}

.character-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-elevated);
}

.character-name {
    font-family: var(--font-display);
    color: var(--oxblood);
    font-weight: 700;
    font-size: 16px;
    margin-bottom: 3px;
    letter-spacing: 0.02em;
}

.character-title {
    font-family: var(--font-display);
    color: var(--bronze);
    font-size: 13px;
    font-style: italic;
    margin-bottom: 6px;
}

.character-years {
    font-family: var(--font-ui);
    color: var(--stone);
    font-size: 11px;
    margin-bottom: 10px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.character-description {
    font-family: var(--font-ui);
    font-size: 12.5px;
    line-height: 1.6;
    color: var(--ink-soft);
}

.wiki-link {
    color: var(--navy);
    text-decoration: none;
    font-family: var(--font-ui);
    font-size: 12px;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-top: 10px;
    padding: 5px 10px;
    border-radius: var(--radius-sm);
    background: rgba(44, 62, 80, 0.06);
    transition: all 0.2s var(--ease-out);
    letter-spacing: 0.02em;
}

.wiki-link:hover {
    background: var(--navy);
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(44, 62, 80, 0.2);
}

/* --- Location Popup (Map) --- */
.location-popup {
    font-family: var(--font-ui) !important;
    max-width: 260px;
    color: var(--ink) !important;
}

.location-popup strong {
    color: var(--oxblood);
    font-size: 1.05em;
}

.location-popup em {
    color: var(--bronze);
    font-style: italic;
    text-transform: capitalize;
}

.location-popup p {
    margin: 8px 0;
    font-size: 0.88em;
    line-height: 1.5;
}

.location-popup a {
    color: var(--navy);
    text-decoration: none;
    font-weight: 500;
}

.location-popup a:hover {
    text-decoration: underline;
}

/* Custom Map Popup */
.leaflet-popup .custom-popup .leaflet-popup-content-wrapper {
    background: var(--panel-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow-elevated);
    border: 1px solid var(--gold);
    padding: 0;
}

.leaflet-popup .custom-popup .leaflet-popup-content {
    margin: 0;
    border-radius: var(--radius);
    font-family: var(--font-ui);
}

.leaflet-popup .custom-popup .leaflet-popup-tip {
    background: var(--gold);
    border: none;
    box-shadow: var(--shadow-subtle);
}

/* --- No Content State --- */
.no-content {
    text-align: center;
    color: var(--stone);
    font-family: var(--font-display);
    font-style: italic;
    padding: 48px 24px;
    font-size: 14px;
}

/* --- Loading Overlay --- */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(253, 250, 243, 0.92);
    backdrop-filter: blur(4px);
    display: none;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    z-index: 1100;
}

.loading-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--panel-border);
    border-top: 3px solid var(--gold);
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}

.loading-text {
    margin-top: 16px;
    font-family: var(--font-display);
    color: var(--stone);
    font-weight: 500;
    font-size: 14px;
    letter-spacing: 0.04em;
    font-style: italic;
}

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

/* --- Entrance Animations --- */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(16px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

/* Staggered volume cards animation */
.volume-card:nth-child(1) { animation: fadeInUp 0.5s var(--ease-out) 0.1s both; }
.volume-card:nth-child(2) { animation: fadeInUp 0.5s var(--ease-out) 0.18s both; }
.volume-card:nth-child(3) { animation: fadeInUp 0.5s var(--ease-out) 0.26s both; }
.volume-card:nth-child(4) { animation: fadeInUp 0.5s var(--ease-out) 0.34s both; }
.volume-card:nth-child(5) { animation: fadeInUp 0.5s var(--ease-out) 0.42s both; }
.volume-card:nth-child(6) { animation: fadeInUp 0.5s var(--ease-out) 0.50s both; }

/* Content entrance */
.paragraph-pair {
    animation: fadeInUp 0.4s var(--ease-out) both;
}

.paragraph-pair:nth-child(1) { animation-delay: 0.05s; }
.paragraph-pair:nth-child(2) { animation-delay: 0.1s; }
.paragraph-pair:nth-child(3) { animation-delay: 0.15s; }
.paragraph-pair:nth-child(4) { animation-delay: 0.2s; }
.paragraph-pair:nth-child(5) { animation-delay: 0.25s; }

/* --- Scrollbar Styling --- */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--stone-light);
    border-radius: 4px;
    border: 2px solid transparent;
    background-clip: content-box;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--stone);
    background-clip: content-box;
}

.toc-content,
.reading-area,
.tab-content {
    scrollbar-width: thin;
    scrollbar-color: var(--stone-light) transparent;
}

/* --- Annotation Popup System --- */
.annotation-link {
    display: inline-block;
    background: var(--gold);
    color: white;
    text-decoration: none;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    line-height: 17px;
    text-align: center;
    font-size: 10px;
    font-weight: 700;
    margin: 0 2px;
    cursor: pointer;
    transition: all 0.2s var(--ease-out);
    position: relative;
    vertical-align: super;
    font-family: var(--font-ui);
}

.annotation-link:hover {
    background: var(--oxblood);
    transform: scale(1.15);
    box-shadow: 0 2px 8px rgba(107, 29, 42, 0.3);
}

.annotation-popup {
    display: none;
    position: fixed;
    background: white;
    border: 1px solid var(--gold);
    border-radius: var(--radius);
    box-shadow: var(--shadow-deep);
    padding: 18px 20px;
    max-width: 380px;
    z-index: 1000;
    font-family: var(--font-body);
    font-size: 14px;
    line-height: 1.6;
}

.annotation-popup.show {
    display: block;
    animation: popupFade 0.25s var(--ease-out);
}

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

.annotation-popup::before {
    content: '';
    position: absolute;
    top: -7px;
    left: 20px;
    width: 0;
    height: 0;
    border-left: 7px solid transparent;
    border-right: 7px solid transparent;
    border-bottom: 7px solid var(--gold);
}

.annotation-popup .popup-header {
    font-family: var(--font-display);
    font-weight: 700;
    color: var(--oxblood);
    margin-bottom: 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--panel-border);
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.annotation-popup .popup-content {
    color: var(--ink-soft);
}

.annotation-popup .close-btn {
    position: absolute;
    top: 8px;
    right: 12px;
    background: none;
    border: none;
    font-size: 16px;
    color: var(--stone);
    cursor: pointer;
    padding: 0;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s var(--ease-out);
}

.annotation-popup .close-btn:hover {
    background: var(--oxblood);
    color: white;
}

/* Hide original footnote elements */
.chapter-content p.foot {
    display: none !important;
}

.chapter-content a[id^="linknote"] {
    display: none !important;
}

.annotation-link {
    display: inline-block !important;
}

/* --- Paragraph Images --- */
.paragraph-images {
    margin: 28px 0;
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    justify-content: center;
}

.image-container {
    flex: 0 0 auto;
    max-width: 100%;
    background: white;
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-subtle);
    border: 1px solid var(--panel-border);
    transition: all var(--duration) var(--ease-out);
}

.image-container:hover {
    box-shadow: var(--shadow-elevated);
    transform: translateY(-3px);
}

.paragraph-image {
    width: 100%;
    height: auto;
    max-width: 420px;
    display: block;
    cursor: zoom-in;
}

.paragraph-images .image-container:only-child .paragraph-image {
    max-width: 520px;
}

.paragraph-images:has(:nth-child(2)) .image-container .paragraph-image {
    max-width: 300px;
}

/* Mobile Quick Action Bar — inline below header */
.mobile-action-bar {
    display: none;
    width: 100%;
    padding: 6px 14px;
    background: var(--cream);
    border-bottom: 1px solid var(--panel-border);
    gap: 8px;
    flex-shrink: 0;
}

.mobile-action-btn {
    flex: 1;
    border: 1px solid var(--panel-border);
    background: white;
    color: var(--ink-soft);
    border-radius: 999px;
    padding: 8px 10px;
    font-family: var(--font-ui);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.02em;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    cursor: pointer;
    transition: all 0.2s var(--ease-out);
}

.mobile-action-btn:hover {
    border-color: var(--gold);
    color: var(--ink);
}

.mobile-action-btn.active {
    background: linear-gradient(135deg, rgba(197, 165, 90, 0.16), rgba(197, 165, 90, 0.3));
    border-color: var(--gold);
    color: var(--oxblood);
}

.mobile-action-icon {
    font-size: 14px;
    line-height: 1;
}

.mobile-action-label {
    line-height: 1;
}

/* Mobile Overlay */
.mobile-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(26, 26, 46, 0.4);
    backdrop-filter: blur(2px);
    z-index: 998;
    transition: opacity var(--duration) var(--ease-out);
}

.mobile-overlay.active {
    display: block;
    opacity: 1;
}

/* ============================================================
   RESPONSIVE DESIGN
   ============================================================ */

@media (max-width: 1200px) {
    .reader-container {
        grid-template-columns: 260px 1fr 320px;
    }

    .reading-area {
        padding: 32px 36px;
    }
}

/* Tablet / Mobile */
@media (max-width: 768px) {
    .reader-container,
    .center-panel {
        height: 100dvh;
    }

    .reader-container {
        grid-template-columns: 1fr;
        gap: 0;
        padding: 0;
    }

    .mobile-action-bar {
        display: flex;
    }

    /* Left Panel - Drawer */
    .left-panel {
        position: fixed;
        top: 0;
        left: -88vw;
        width: 88vw;
        max-width: 380px;
        height: 100vh;
        z-index: 1000;
        transition: left var(--duration) var(--ease-out);
        box-shadow: 12px 0 36px rgba(26, 26, 46, 0.18);
        background: var(--cream);
        border-right: 1px solid var(--panel-border);
        border-radius: 0 14px 14px 0;
    }

    .left-panel.open {
        left: 0;
    }

    /* Mobile TOC: keep fonts readable */
    .panel-header {
        padding-top: 18px;
    }

    .panel-header h2 {
        font-size: 1.4em;
        padding-right: 34px;
    }

    .mobile-panel-close {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .volume-header {
        font-size: 15px;
        padding: 14px 16px;
    }

    .chapter-item {
        font-size: 14px;
        padding: 10px 12px;
    }

    .chinese-subtitle {
        font-size: 0.88em;
    }

    .search-box input {
        font-size: 14px;
        padding: 10px 14px;
    }

    /* Right Panel - Drawer */
    .right-panel {
        position: fixed;
        top: 0;
        right: -92vw;
        width: 92vw;
        max-width: 420px;
        height: 100vh;
        z-index: 1000;
        transition: right var(--duration) var(--ease-out);
        box-shadow: -12px 0 36px rgba(26, 26, 46, 0.18);
        border-radius: 14px 0 0 14px;
        overflow: hidden;
    }

    .panel-tabs {
        padding-right: 44px;
    }

    .right-panel.open {
        right: 0;
    }

    .center-panel {
        width: 100%;
        margin: 0;
    }

    .content-header {
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 10px 14px;
        flex-wrap: nowrap;
        border-bottom: 1px solid var(--panel-border);
        box-shadow: 0 1px 0 rgba(230, 223, 211, 0.6);
    }

    .breadcrumb {
        flex: 1;
        min-width: 0;
    }

    .volume-title {
        font-size: 14px;
    }

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

    .reading-controls {
        display: flex;
        gap: 0;
        flex-shrink: 0;
    }

    .control-btn {
        padding: 7px 9px;
        font-size: 13px;
        min-width: unset;
    }

    /* Reading area - comfortable mobile reading */
    .reading-area {
        padding: 20px 18px 24px;
        font-size: 16.5px;
        line-height: 1.9;
    }

    .english-paragraph {
        padding: 16px 18px;
        font-size: 16px;
        line-height: 1.8;
    }

    .chinese-paragraph {
        padding: 16px 18px;
        font-size: 15.5px;
        line-height: 1.9;
    }

    .paragraph-pair {
        margin-bottom: 28px;
        padding-bottom: 24px;
    }

    /* Drop cap smaller on mobile */
    .paragraph-pair:first-child .english-paragraph::first-letter {
        font-size: 2.8em;
        padding-right: 8px;
        padding-top: 4px;
    }

    .toc-content {
        padding: 12px;
    }

    .tab-content {
        padding: 16px 14px 24px;
    }

    .tab-btn {
        font-size: 14px;
        padding: 14px 10px;
    }

    .toc-content,
    .reading-area,
    .tab-content {
        -webkit-overflow-scrolling: touch;
    }

    #interactive-map {
        height: 220px;
    }

    .welcome-volumes {
        grid-template-columns: 1fr;
    }

    .welcome-message {
        padding: 32px 18px;
    }

    .welcome-hero {
        padding: 32px 16px 28px;
        margin: 0 -18px 24px;
    }

    .welcome-message h1 {
        font-size: 2em;
    }

    .welcome-title-cn {
        font-size: 1.25em;
    }

    .welcome-message h2 {
        font-size: 1em;
    }

    .personal-story {
        padding: 20px 18px;
        font-size: 14px;
    }

    .volume-card {
        padding: 13px 14px;
    }

    .volume-card .vol-title {
        font-size: 13px;
    }

    .volume-card .vol-title-cn {
        font-size: 12px;
    }

    .volume-card .vol-chapters {
        font-size: 11px;
    }

    /* Character cards */
    .character-name {
        font-size: 16px;
    }

    .character-title {
        font-size: 14px;
    }

    .character-description {
        font-size: 13px;
    }

    .paragraph-images {
        margin: 16px 0;
        gap: 12px;
    }

    .paragraph-image,
    .paragraph-images .image-container:only-child .paragraph-image,
    .paragraph-images:has(:nth-child(2)) .image-container .paragraph-image {
        max-width: 100%;
    }

    /* Sponsor button */
    .sponsor-button {
        font-size: 13px;
        padding: 10px 22px;
    }

    /* Home button mobile */
    .home-btn-prominent {
        padding: 7px 12px;
        font-size: 11px;
    }

    .home-btn-prominent svg {
        width: 13px;
        height: 13px;
    }
}

/* Small mobile (< 480px) */
@media (max-width: 480px) {
    .left-panel {
        width: 88vw;
        left: -88vw;
        max-width: none;
    }

    .right-panel {
        width: 92vw;
        right: -92vw;
        max-width: none;
    }

    .content-header {
        padding: 9px 10px;
    }

    .volume-title {
        font-size: 13px;
    }

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

    #interactive-map {
        height: 180px;
    }

    .reading-area {
        padding: 18px 14px 20px;
        font-size: 16px;
    }

    .english-paragraph {
        padding: 14px 16px;
        font-size: 15.5px;
    }

    .chinese-paragraph {
        padding: 14px 16px;
        font-size: 15px;
    }

    .welcome-message {
        padding: 24px 12px;
    }

    .welcome-hero {
        padding: 28px 12px 24px;
        margin: 0 -12px 20px;
    }

    .welcome-message h1 {
        font-size: 1.7em;
    }

    .welcome-title-cn {
        font-size: 1.15em;
    }

    .welcome-message h2 {
        font-size: 0.95em;
    }

    .personal-story {
        padding: 16px 14px;
        font-size: 13.5px;
    }

    .volume-card .vol-title {
        font-size: 12px;
    }

    .mobile-action-bar {
        width: calc(100% - 16px);
        padding: 6px;
        gap: 6px;
    }

    .mobile-action-btn {
        padding: 8px 8px;
        font-size: 11.5px;
        gap: 5px;
    }

    .mobile-action-icon {
        font-size: 13px;
    }
}

/* ============================================================
   UNIVERSAL MOBILE SHELL
   Force the same mobile-first UI on all screen sizes.
   ============================================================ */
body.mobile-first-reader {
    display: flex;
    justify-content: center;
    align-items: stretch;
    padding: 0;
    background:
        radial-gradient(circle at 20% 10%, rgba(197, 165, 90, 0.10), transparent 42%),
        radial-gradient(circle at 85% 85%, rgba(107, 29, 42, 0.08), transparent 44%),
        var(--ivory);
}

body.mobile-first-reader .reader-container {
    width: min(100vw, 430px);
    height: 100dvh;
    grid-template-columns: 1fr;
    position: relative;
    overflow: hidden;
    background: white;
}

body.mobile-first-reader .center-panel {
    width: 100%;
    height: 100%;
    margin: 0;
    box-shadow: none;
    z-index: 1;
}

body.mobile-first-reader .content-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--panel-border);
    box-shadow: 0 1px 0 rgba(230, 223, 211, 0.6);
}

body.mobile-first-reader .reading-controls {
    gap: 0;
}

body.mobile-first-reader .control-btn {
    padding: 7px 9px;
    font-size: 13px;
}

body.mobile-first-reader .home-btn-prominent {
    padding: 7px 14px;
    font-size: 11px;
}

body.mobile-first-reader .home-btn-prominent svg {
    width: 13px;
    height: 13px;
}

body.mobile-first-reader .reading-area {
    padding: 20px 12px 24px;
    font-size: 16.5px;
    line-height: 1.9;
}

body.mobile-first-reader .english-paragraph {
    padding: 14px 12px;
    font-size: 16px;
    line-height: 1.8;
}

body.mobile-first-reader .chinese-paragraph {
    padding: 14px 12px;
    font-size: 15.5px;
    line-height: 1.9;
}

body.mobile-first-reader .paragraph-pair {
    margin-bottom: 24px;
    padding-bottom: 20px;
}

body.mobile-first-reader .paragraph-pair:first-child .english-paragraph::first-letter {
    font-size: 2.8em;
    padding-right: 8px;
    padding-top: 4px;
}

body.mobile-first-reader .left-panel {
    position: absolute;
    top: 0;
    left: -88%;
    width: 88%;
    max-width: none;
    height: 100%;
    z-index: 1000;
    transition: left var(--duration) var(--ease-out);
    box-shadow: 12px 0 36px rgba(26, 26, 46, 0.18);
    border-right: 1px solid var(--panel-border);
    border-radius: 0 14px 14px 0;
}

body.mobile-first-reader .left-panel.open {
    left: 0;
}

body.mobile-first-reader .right-panel {
    position: absolute;
    top: 0;
    right: -92%;
    width: 92%;
    max-width: none;
    height: 100%;
    z-index: 1000;
    transition: right var(--duration) var(--ease-out);
    box-shadow: -12px 0 36px rgba(26, 26, 46, 0.18);
    border-radius: 14px 0 0 14px;
    overflow: hidden;
}

body.mobile-first-reader .right-panel.open {
    right: 0;
}

body.mobile-first-reader .panel-tabs {
    padding-right: 44px;
}

body.mobile-first-reader .mobile-panel-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

body.mobile-first-reader .panel-header {
    padding-top: 18px;
}

body.mobile-first-reader .panel-header h2 {
    font-size: 1.5em;
    padding-right: 34px;
}

body.mobile-first-reader .search-box input {
    font-size: 14px;
    padding: 10px 14px;
}

body.mobile-first-reader .volume-header {
    font-size: 16px;
    padding: 14px 16px;
}

body.mobile-first-reader .chapter-item {
    font-size: 15px;
    padding: 10px 12px;
}

body.mobile-first-reader .chinese-subtitle {
    font-size: 0.92em;
}

body.mobile-first-reader .part-summary {
    font-size: 13px;
}

body.mobile-first-reader .part-label {
    font-size: 11px;
}

body.mobile-first-reader .part-name {
    font-size: 14px;
}

body.mobile-first-reader .english-subtitle {
    font-size: 0.85em;
}

body.mobile-first-reader .welcome-message h1 {
    font-size: 2.2em;
}

body.mobile-first-reader .welcome-title-cn {
    font-size: 1.4em;
}

body.mobile-first-reader .welcome-message h2 {
    font-size: 1.05em;
}

body.mobile-first-reader .welcome-overline {
    font-size: 11px;
}

body.mobile-first-reader .personal-story {
    font-size: 15px;
}

body.mobile-first-reader .personal-story p {
    line-height: 1.9;
}

body.mobile-first-reader .welcome-hero {
    padding: 36px 16px 28px;
}

body.mobile-first-reader .welcome-message {
    padding: 36px 16px 48px;
}

body.mobile-first-reader .volume-card .vol-title-cn {
    font-size: 13px;
}

body.mobile-first-reader .volume-card .vol-title {
    font-size: 14px;
}

body.mobile-first-reader .volume-card .vol-number {
    font-size: 11px;
}

body.mobile-first-reader .volume-card .vol-chapters {
    font-size: 11px;
}

body.mobile-first-reader .sponsor-button {
    font-size: 14px;
}

body.mobile-first-reader .tab-content {
    padding: 16px 14px 24px;
}

body.mobile-first-reader .tab-btn {
    font-size: 14px;
    padding: 14px 10px;
}

body.mobile-first-reader .mobile-action-bar {
    display: flex;
}

body.mobile-first-reader .mobile-overlay {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: min(100vw, 430px);
    height: 100dvh;
    z-index: 998;
}

body.mobile-first-reader .loading-overlay {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: min(100vw, 430px);
    height: 100dvh;
    z-index: 1100;
}

@media (min-width: 900px) {
    body.mobile-first-reader {
        padding: 12px 0;
    }

    body.mobile-first-reader .reader-container {
        height: calc(100dvh - 24px);
        border: 1px solid var(--panel-border);
        border-radius: 24px;
        box-shadow: 0 18px 48px rgba(26, 26, 46, 0.2);
    }

    body.mobile-first-reader .mobile-overlay,
    body.mobile-first-reader .loading-overlay {
        top: 12px;
        height: calc(100dvh - 24px);
        border-radius: 24px;
    }

    body.mobile-first-reader .left-panel {
        height: 100%;
    }

    body.mobile-first-reader .right-panel {
        height: 100%;
    }
}

@media (max-width: 420px) {
    body.mobile-first-reader .content-header {
        padding: 9px 10px;
    }

    body.mobile-first-reader .volume-title {
        font-size: 13px;
    }

    body.mobile-first-reader .chapter-title {
        font-size: 11px;
    }

    body.mobile-first-reader .reading-area {
        padding: 18px 10px calc(90px + env(safe-area-inset-bottom, 0px));
        font-size: 16px;
    }

    body.mobile-first-reader .english-paragraph {
        padding: 12px 10px;
        font-size: 15.5px;
    }

    body.mobile-first-reader .chinese-paragraph {
        padding: 12px 10px;
        font-size: 15px;
    }

    body.mobile-first-reader .welcome-message {
        padding: 28px 10px 40px;
    }

    body.mobile-first-reader .welcome-hero {
        margin: 0 -10px 20px;
    }

    body.mobile-first-reader .welcome-message h1 {
        font-size: 1.9em;
    }

    body.mobile-first-reader .welcome-title-cn {
        font-size: 1.25em;
    }

    body.mobile-first-reader .mobile-action-bar {
        width: calc(100% - 16px);
        padding: 6px;
        gap: 6px;
    }

    body.mobile-first-reader .mobile-action-btn {
        padding: 8px 8px;
        font-size: 11.5px;
        gap: 5px;
    }

    body.mobile-first-reader .mobile-action-icon {
        font-size: 13px;
    }
}

/* --- Selection Color --- */
::selection {
    background: rgba(197, 165, 90, 0.25);
    color: var(--ink);
}

::-moz-selection {
    background: rgba(197, 165, 90, 0.25);
    color: var(--ink);
}

/* ============================================================
   ENTITY LINK & POPUP SYSTEM
   Interactive popups for historical persons and places
   ============================================================ */

/* --- Entity Links in Text --- */
.entity-link {
    color: var(--oxblood);
    text-decoration: none;
    border-bottom: 1px dotted var(--gold-muted);
    cursor: pointer;
    transition: color var(--duration) var(--ease-out),
                border-color var(--duration) var(--ease-out),
                background var(--duration) var(--ease-out);
}

.entity-link:hover {
    color: var(--oxblood-light);
    border-bottom-color: var(--gold);
    background: var(--gold-glow);
    border-radius: 2px;
}

.entity-link.place-link {
    color: var(--navy);
    border-bottom-color: var(--navy-light);
}

.entity-link.place-link:hover {
    color: var(--navy-light);
    border-bottom-color: var(--navy);
    background: rgba(44, 62, 80, 0.08);
}

.entity-link.entity-highlight {
    background: var(--gold-glow);
    box-shadow: 0 0 0 3px var(--gold-glow);
    border-radius: 2px;
    transition: background 0.3s ease, box-shadow 0.3s ease;
}

/* --- Entity Popup Card --- */
.entity-popup {
    position: fixed;
    z-index: 2000;
    width: 360px;
    max-height: 400px;
    overflow-y: auto;
    background: var(--cream);
    border: 1px solid var(--gold-muted);
    border-radius: var(--radius);
    box-shadow: var(--shadow-deep);
    opacity: 0;
    visibility: hidden;
    transform: translateY(8px);
    transition: opacity 0.25s var(--ease-out),
                visibility 0.25s var(--ease-out),
                transform 0.25s var(--ease-out);
    font-family: var(--font-body);
}

.entity-popup.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.entity-popup-close {
    position: absolute;
    top: 8px;
    right: 10px;
    background: none;
    border: none;
    font-size: 20px;
    color: rgba(255, 255, 255, 0.8);
    cursor: pointer;
    z-index: 2;
    line-height: 1;
    padding: 4px;
}

.entity-popup-close:hover {
    color: #fff;
}

/* --- Popup Header --- */
.entity-popup-header {
    background: linear-gradient(135deg, var(--oxblood-dark), var(--oxblood));
    color: #fff;
    padding: 16px 18px;
    border-radius: var(--radius) var(--radius) 0 0;
    border-bottom: 2px solid var(--gold);
}

.entity-popup-header-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.entity-popup-portrait {
    width: 48px;
    height: 48px;
    border-radius: 6px;
    border: 2px solid var(--gold-muted);
    flex-shrink: 0;
    object-fit: cover;
}

.entity-popup-name-zh {
    font-family: var(--font-chinese);
    font-size: 18px;
    font-weight: 600;
    line-height: 1.3;
}

.entity-popup-name-en {
    font-family: var(--font-display);
    font-size: 13px;
    opacity: 0.85;
    font-style: italic;
    margin-top: 2px;
}

/* --- Popup Body --- */
.entity-popup-body {
    padding: 14px 18px 16px;
}

.entity-popup-title {
    font-family: var(--font-display);
    font-size: 13px;
    color: var(--oxblood);
    font-weight: 600;
    margin-bottom: 4px;
}

.entity-popup-years {
    font-family: var(--font-ui);
    font-size: 12px;
    color: var(--stone);
    margin-bottom: 8px;
}

.entity-popup-type {
    display: inline-block;
    font-family: var(--font-ui);
    font-size: 11px;
    color: var(--navy);
    background: rgba(44, 62, 80, 0.08);
    padding: 2px 8px;
    border-radius: 10px;
    margin-bottom: 8px;
    text-transform: capitalize;
}

.entity-popup-bio {
    font-family: var(--font-chinese);
    font-size: 13px;
    line-height: 1.7;
    color: var(--ink-soft);
    margin-bottom: 10px;
}

.entity-popup-links {
    display: flex;
    gap: 12px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--panel-border);
}

.entity-popup-links a {
    font-family: var(--font-ui);
    font-size: 12px;
    color: var(--navy);
    text-decoration: none;
    font-weight: 500;
    transition: color var(--duration) var(--ease-out);
}

.entity-popup-links a:hover {
    color: var(--oxblood);
}

/* --- Character Card Enhancements --- */
.character-card-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 6px;
}

.character-portrait {
    width: 40px;
    height: 40px;
    border-radius: 6px;
    border: 1px solid var(--panel-border);
    object-fit: cover;
    flex-shrink: 0;
}

.character-card-names {
    flex: 1;
    min-width: 0;
}

.character-english-name {
    font-family: var(--font-display);
    font-size: 12px;
    color: var(--stone);
    font-style: italic;
}

/* --- Mobile Bottom Sheet --- */
@media (max-width: 768px) {
    .entity-popup.mobile-sheet {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        top: auto;
        width: 100%;
        max-height: 60vh;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        transform: translateY(100%);
        transition: transform 0.35s var(--ease-out),
                    opacity 0.25s var(--ease-out),
                    visibility 0.25s var(--ease-out);
    }

    .entity-popup.mobile-sheet.show {
        transform: translateY(0);
    }

    .entity-popup.mobile-sheet .entity-popup-close {
        color: rgba(255, 255, 255, 0.9);
        font-size: 24px;
        top: 12px;
        right: 14px;
    }

    .entity-popup.mobile-sheet .entity-popup-header {
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        padding: 20px 18px;
    }

    .entity-popup.mobile-sheet .entity-popup-body {
        padding: 16px 18px 24px;
        overflow-y: auto;
    }
}

/* ============================================================
   IMAGE LIGHTBOX
   ============================================================ */
.lightbox-overlay {
    position: fixed;
    inset: 0;
    z-index: 3000;
    background: rgba(10, 10, 18, 0.92);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s var(--ease-out), visibility 0.3s var(--ease-out);
    cursor: zoom-out;
}

.lightbox-overlay.active {
    opacity: 1;
    visibility: visible;
}

.lightbox-img {
    max-width: 92vw;
    max-height: 90vh;
    object-fit: contain;
    border-radius: var(--radius);
    box-shadow: 0 12px 60px rgba(0, 0, 0, 0.5);
    transform: scale(0.92);
    transition: transform 0.35s var(--ease-spring);
}

.lightbox-overlay.active .lightbox-img {
    transform: scale(1);
}

.lightbox-close {
    position: absolute;
    top: 16px;
    right: 20px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.1);
    color: white;
    font-size: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s var(--ease-out);
}

.lightbox-close:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.4);
    transform: scale(1.1);
}
