@import url('https://fonts.googleapis.com/css2?family=Ma+Shan+Zheng&family=Noto+Serif+SC:wght@400;700&family=ZCOOL+XiaoWei&display=swap');

:root {
    --imperial-yellow: #ffeb3b;
    --imperial-gold: #c5a006;
    --qing-blue: #1a237e;
    --cinnabar-red: #b71c1c;
    --jade-green: #2e7d32;
    --paper-bg: #fdfbf7;
    --scroll-border: #5d4037;
    
    --font-title: "Georgia", "Times New Roman", "Ma Shan Zheng", cursive;
    --font-body: "Segoe UI", "Helvetica Neue", "Arial", "Noto Serif SC", sans-serif;
}

body {
    background-color: #3e2723;
    background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%235d4037' fill-opacity='0.4'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
    font-family: var(--font-body);
    margin: 0;
    padding: 20px;
    color: #333;
}

/* =========================================
   Legacy Support (Chapters 1-5) & Base Container
   ========================================= */
.imperial-scroll, .scroll-content {
    max-width: 900px;
    margin: 0 auto;
    background-color: var(--paper-bg);
    border: 8px solid var(--imperial-gold);
    border-radius: 4px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    position: relative;
    padding: 40px;
}

/* Dragon Pattern Borders */
.imperial-scroll::before, .scroll-content::before {
    content: "";
    position: absolute;
    top: 10px; left: 10px; right: 10px; bottom: 10px;
    border: 2px solid var(--qing-blue);
    pointer-events: none;
    z-index: 1;
}

/* =========================================
   New Structure (Chapter 6+)
   ========================================= */

/* Fixed Border Decoration */
.imperial-border {
    position: fixed;
    top: 0; left: 0; right: 0; height: 10px;
    background: var(--imperial-gold);
    z-index: 100;
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
}

/* Header */
.main-header {
    text-align: center;
    margin-bottom: 30px;
    color: var(--imperial-gold);
    text-shadow: 2px 2px 4px #000;
}

.logo-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
}

.dragon-symbol {
    font-size: 3rem;
    filter: drop-shadow(0 0 5px var(--imperial-gold));
}

.main-header h1 {
    font-family: var(--font-title);
    font-size: 3rem;
    margin: 0;
    color: var(--imperial-yellow);
    text-shadow: 2px 2px 0 var(--cinnabar-red);
    border: none;
    padding: 0;
}

.subtitle {
    font-family: var(--font-title);
    font-size: 1.5rem;
    color: #ffd700;
    margin-top: 10px;
}

/* Navigation Bar */
.chapter-nav {
    display: flex;
    justify-content: space-between;
    max-width: 900px;
    margin: 0 auto 20px auto;
    padding: 0 10px;
}

.nav-btn {
    background: var(--cinnabar-red);
    color: var(--imperial-yellow);
    padding: 10px 20px;
    text-decoration: none;
    border-radius: 5px;
    font-family: var(--font-title);
    border: 2px solid var(--imperial-gold);
    transition: all 0.3s;
    box-shadow: 3px 3px 0 rgba(0,0,0,0.5);
}

.nav-btn:hover {
    transform: translateY(-2px);
    box-shadow: 5px 5px 0 rgba(0,0,0,0.5);
    background: #d32f2f;
}

/* =========================================
   Typography & Content
   ========================================= */

h1, h2, h3 {
    font-family: var(--font-title);
    color: var(--cinnabar-red);
    text-align: center;
}

/* Legacy h1 support */
.imperial-scroll h1 {
    font-size: 2.5rem;
    text-shadow: 2px 2px 0 var(--imperial-yellow);
    margin-bottom: 2rem;
    border-bottom: 3px double var(--cinnabar-red);
    padding-bottom: 10px;
}

h2 {
    font-size: 2rem;
    margin-top: 3rem;
    color: var(--qing-blue);
    display: flex;
    align-items: center;
    justify-content: center;
}

h2::before, h2::after {
    content: "☁️";
    font-size: 1.5rem;
    margin: 0 10px;
    opacity: 0.6;
}

/* =========================================
   Comic Components
   ========================================= */

.comic-panel {
    background: #fff;
    border: 3px solid #000;
    padding: 20px;
    margin: 30px 0;
    box-shadow: 5px 5px 0 rgba(0,0,0,0.2);
    position: relative;
    z-index: 2;
}

/* New Character Structure (Ch 6+) */
.character {
    display: flex;
    align-items: flex-start;
    margin-bottom: 20px;
    gap: 15px;
}

.character:nth-child(even) {
    flex-direction: row-reverse;
}

.character .avatar {
    font-size: 3rem;
    width: 80px;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f0f0f0;
    border: 3px solid #333;
    border-radius: 50%;
    box-shadow: 3px 3px 0 rgba(0,0,0,0.2);
}

/* Legacy Avatar Support (Ch 1-5) */
.dialogue {
    display: flex;
    align-items: flex-start;
    margin-bottom: 20px;
}
.dialogue.right { flex-direction: row-reverse; }
.dialogue .avatar { /* Inherits base styles, specific backgrounds below */
    width: 80px; height: 80px; border-radius: 50%; border: 4px solid #000; flex-shrink: 0; background-size: cover; background-position: center; background-color: #ddd;
}
.avatar.xiaobao { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Ccircle cx='50' cy='50' r='50' fill='%23ffcc80'/%3E%3Cpath d='M20,30 Q50,60 80,30' fill='none' stroke='%23000' stroke-width='3'/%3E%3Ccircle cx='35' cy='45' r='5' fill='%23000'/%3E%3Ccircle cx='65' cy='45' r='5' fill='%23000'/%3E%3Crect x='10' y='20' width='80' height='10' fill='%23000'/%3E%3Ctext x='50' y='90' font-size='20' text-anchor='middle' font-family='serif'%3E韦小宝%3C/text%3E%3C/svg%3E"); border-color: var(--imperial-gold); }
.avatar.jinnan { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Ccircle cx='50' cy='50' r='50' fill='%23eeeeee'/%3E%3Crect x='20' y='10' width='60' height='30' fill='%23000'/%3E%3Ccircle cx='35' cy='55' r='5' fill='%23000'/%3E%3Ccircle cx='65' cy='55' r='5' fill='%23000'/%3E%3Cpath d='M40,70 Q50,80 60,70' fill='none' stroke='%23000' stroke-width='3'/%3E%3Ctext x='50' y='90' font-size='20' text-anchor='middle' font-family='serif'%3E陈近南%3C/text%3E%3C/svg%3E"); border-color: var(--cinnabar-red); }
.avatar.kangxi { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Ccircle cx='50' cy='50' r='50' fill='%23fff176'/%3E%3Cpolygon points='20,20 50,0 80,20' fill='%23fbc02d'/%3E%3Ccircle cx='35' cy='50' r='5' fill='%23000'/%3E%3Ccircle cx='65' cy='50' r='5' fill='%23000'/%3E%3Cpath d='M30,70 Q50,80 70,70' fill='none' stroke='%23000' stroke-width='3'/%3E%3Ctext x='50' y='90' font-size='20' text-anchor='middle' font-family='serif'%3E康熙%3C/text%3E%3C/svg%3E"); border-color: var(--imperial-yellow); }

/* Speech Bubbles */
.speech-bubble, .bubble {
    background: #fff;
    border: 2px solid #000;
    border-radius: 15px;
    padding: 15px;
    margin: 10px 0; /* Adjusted for flex layout */
    position: relative;
    font-family: var(--font-body);
    font-size: 1.1rem;
    line-height: 1.6;
    flex: 1;
}

.speech-bubble::before {
    content: '';
    position: absolute;
    width: 0; height: 0;
    border: 10px solid transparent;
}

/* Left Arrow */
.character:nth-child(odd) .speech-bubble::before, .dialogue.left .bubble::before {
    border-right-color: #000;
    left: -20px; top: 20px;
}
.character:nth-child(odd) .speech-bubble::after, .dialogue.left .bubble::after {
    content: ''; position: absolute;
    border: 10px solid transparent;
    border-right-color: #fff;
    left: -16px; top: 20px;
}

/* Right Arrow */
.character:nth-child(even) .speech-bubble::before, .dialogue.right .bubble::before {
    border-left-color: #000;
    right: -20px; top: 20px;
}
.character:nth-child(even) .speech-bubble::after, .dialogue.right .bubble::after {
    content: ''; position: absolute;
    border: 10px solid transparent;
    border-left-color: #fff;
    right: -16px; top: 20px;
}

/* =========================================
   Educational Components
   ========================================= */

/* Imperial Edict (Commands) */
.imperial-edict {
    background-color: var(--imperial-yellow);
    border: 4px double var(--cinnabar-red);
    padding: 20px;
    margin: 20px 0;
    position: relative;
    box-shadow: 5px 5px 15px rgba(0,0,0,0.2);
    z-index: 2;
}

.imperial-edict::before {
    content: "奉天承运";
    position: absolute;
    top: -15px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--cinnabar-red);
    color: var(--imperial-yellow);
    padding: 5px 20px;
    font-family: var(--font-title);
    border-radius: 20px;
    font-size: 1.2rem;
}

.imperial-edict h3 {
    margin-top: 10px;
    font-size: 1.5rem;
    color: #333;
    text-shadow: none;
    border: none;
}

/* Story Segment (Ch 6+) */
.story-segment {
    margin-bottom: 40px;
    position: relative;
    z-index: 2;
}

.story-segment p {
    font-size: 1.1rem;
    line-height: 1.8;
}

/* Step Card (Ch 6+) */
.step-card {
    background: #fff;
    border-left: 5px solid var(--qing-blue);
    padding: 15px;
    margin: 20px 0;
    box-shadow: 2px 2px 5px rgba(0,0,0,0.1);
}

.step-card h3 {
    text-align: left;
    color: var(--qing-blue);
    font-size: 1.3rem;
    margin-top: 0;
}

/* Practice Moment (Hands-on) */
.practice-moment {
    background: #e8f5e9;
    border: 2px dashed var(--jade-green);
    padding: 20px;
    margin-top: 40px;
    border-radius: 10px;
    position: relative;
    z-index: 2;
}

.practice-moment h3 {
    color: var(--jade-green);
    text-align: center;
}

.warning-box {
    background: #ffebee;
    border: 1px solid var(--cinnabar-red);
    padding: 10px;
    margin: 10px 0;
    color: var(--cinnabar-red);
    border-radius: 5px;
}

/* Code Blocks */
pre, code {
    font-family: 'Consolas', 'Monaco', monospace;
}

code {
    background: #eee;
    padding: 2px 5px;
    border-radius: 3px;
    color: #d32f2f;
}

pre {
    background: #212121;
    color: #00e676;
    padding: 15px;
    border-radius: 4px;
    overflow-x: auto;
    border: 2px solid #000;
}

.imperial-edict code, .imperial-edict pre {
    /* Code inside edict */
}

.cmd-preview {
    background: #000;
    color: #0f0;
    padding: 15px;
    border-radius: 5px;
    font-family: monospace;
    margin-top: 15px;
    border: 2px solid #555;
    white-space: pre-wrap;
}

/* Nav Hint */
.nav-hint {
    margin-top: 30px;
    padding: 15px;
    background: #fff3e0;
    border-left: 5px solid #ff9800;
    font-style: italic;
}

/* Footer */
footer {
    text-align: center;
    margin-top: 50px;
    padding: 20px;
    color: var(--imperial-gold);
    font-family: var(--font-title);
    font-size: 1.2rem;
    text-shadow: 1px 1px 2px #000;
}

/* =========================================
   Responsive
   ========================================= */
@media (max-width: 768px) {
    .imperial-scroll, .scroll-content {
        padding: 20px;
        margin-top: 60px; /* Space for fixed header/border */
    }
    .main-header h1 { font-size: 2rem; }
    .dragon-symbol { display: none; }
    .chapter-nav { flex-direction: column; gap: 10px; text-align: center; }
    .nav-btn { display: block; }
    .avatar { width: 50px; height: 50px; font-size: 2rem; }
}
