/* CSS Variables */
:root {
    --primary: #8B2323;
    --primary-dark: #6B1A1A;
    --primary-light: #A63D3D;
    --accent: #C4A35A;
    --accent-light: #E8D5A3;
    --accent-dark: #9A7B3A;
    --bg-main: #F8F5F0;
    --bg-white: #FFFDF8;
    --bg-cream: #FFF9F0;
    --bg-card: #FFF5E8;
    --bg-paper: #FEFCF7;
    --text-dark: #2C2416;
    --text-medium: #5C4D3C;
    --text-light: #8B7355;
    --border: #E0D5C5;
    --border-light: #EDE6DA;
    --border-accent: #D4C4A8;
    --success: #4A7C59;
    --warning: #B8860B;
    --shadow: rgba(44, 36, 22, 0.1);
    --shadow-warm: rgba(139, 35, 35, 0.08);
    --header-height: 60px;
    --sidebar-width: 280px;
    --ai-panel-width: 380px;
}

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

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: 'Noto Serif SC', serif;
    background: var(--bg-main);
    background-image: 
        radial-gradient(ellipse at 20% 30%, rgba(196, 163, 90, 0.06) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 70%, rgba(139, 35, 35, 0.04) 0%, transparent 50%),
        linear-gradient(180deg, rgba(255, 253, 248, 0.8) 0%, rgba(248, 245, 240, 1) 100%);
    color: var(--text-dark);
    line-height: 1.8;
    min-height: 100vh; /* Fallback */
    min-height: 100dvh; /* Dynamic viewport height */
    overflow-x: hidden;
}

/* Header - Fixed at top */
.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    z-index: 1000;
    box-shadow: 0 2px 10px var(--shadow);
}

.header-btn {
    min-width: 44px;
    height: 44px;
    background: linear-gradient(180deg, rgba(255,255,255,0.2) 0%, rgba(255,255,255,0.08) 100%);
    border: 1px solid rgba(255,255,255,0.15);
    border-top-color: rgba(255,255,255,0.25);
    border-bottom-color: rgba(0,0,0,0.1);
    border-radius: 10px;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
    box-shadow: 
        0 2px 4px rgba(0,0,0,0.2),
        0 1px 2px rgba(0,0,0,0.1),
        inset 0 1px 0 rgba(255,255,255,0.15);
}

.header-btn.with-label {
    width: auto;
    min-width: 80px;
    padding: 10px 18px;
    gap: 8px;
    white-space: nowrap;
}

.btn-label {
    font-size: 0.9rem;
    font-weight: 500;
    letter-spacing: 0.08em;
    white-space: nowrap;
    text-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.header-btn:hover {
    background: linear-gradient(180deg, rgba(255,255,255,0.28) 0%, rgba(255,255,255,0.12) 100%);
    box-shadow: 
        0 3px 6px rgba(0,0,0,0.25),
        0 2px 4px rgba(0,0,0,0.15),
        inset 0 1px 0 rgba(255,255,255,0.2);
    transform: translateY(-1px);
}

.header-btn:active {
    background: linear-gradient(180deg, rgba(255,255,255,0.1) 0%, rgba(255,255,255,0.15) 100%);
    box-shadow: 
        0 1px 2px rgba(0,0,0,0.2),
        inset 0 2px 4px rgba(0,0,0,0.1);
    transform: translateY(1px);
}

.header-btn.ai-btn {
    background: linear-gradient(180deg, #D4B36A 0%, var(--accent) 50%, #9A7B3A 100%);
    color: #fff;
    border: 1px solid rgba(154, 123, 58, 0.6);
    border-top-color: rgba(232, 213, 163, 0.5);
    border-bottom-color: rgba(100, 80, 40, 0.4);
    position: relative;
    box-shadow: 
        0 3px 6px rgba(100, 80, 40, 0.35),
        0 2px 4px rgba(0,0,0,0.2),
        inset 0 1px 0 rgba(255,255,255,0.3),
        inset 0 -1px 0 rgba(0,0,0,0.1);
    text-shadow: 0 1px 2px rgba(100, 80, 40, 0.4);
}

.header-btn.ai-btn:hover {
    background: linear-gradient(180deg, #E8D5A3 0%, #D4B36A 50%, var(--accent) 100%);
    box-shadow: 
        0 4px 8px rgba(100, 80, 40, 0.4),
        0 2px 4px rgba(0,0,0,0.2),
        inset 0 1px 0 rgba(255,255,255,0.4),
        inset 0 -1px 0 rgba(0,0,0,0.1);
    transform: translateY(-1px);
    border-color: rgba(232, 213, 163, 0.6);
}

.header-btn.ai-btn:active {
    background: linear-gradient(180deg, var(--accent) 0%, #9A7B3A 50%, #7A6030 100%);
    box-shadow: 
        0 1px 2px rgba(100, 80, 40, 0.3),
        inset 0 2px 4px rgba(0,0,0,0.15);
    transform: translateY(1px);
}

.header-title {
    display: flex;
    align-items: center;
    gap: 8px;
}

.logo-icon {
    width: 38px;
    height: 38px;
    background: linear-gradient(135deg, var(--accent-light) 0%, var(--accent) 100%);
    color: var(--primary-dark);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    font-weight: bold;
    box-shadow: 0 2px 8px rgba(196, 163, 90, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.logo-text {
    font-size: 1.15rem;
    letter-spacing: 0.15em;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* Main Content */
.main-content {
    padding-top: var(--header-height);
    min-height: 100vh;
}

/* Sidebar Base Styles */
.sidebar {
    position: fixed;
    top: 0;
    bottom: 0; /* Use top+bottom instead of height for better mobile support */
    background: var(--bg-white);
    z-index: 1001;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    box-shadow: 0 0 20px var(--shadow);
}

.sidebar-left {
    left: 0;
    width: var(--sidebar-width);
    transform: translateX(-100%);
}

.sidebar-left.open {
    transform: translateX(0);
}

.sidebar-right {
    right: 0;
    width: 100%;
    max-width: var(--ai-panel-width);
    transform: translateX(100%);
}

.sidebar-right.open {
    transform: translateX(0);
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 16px;
    border-bottom: 1px solid var(--border-accent);
    min-height: var(--header-height);
    background: linear-gradient(180deg, rgba(255, 253, 248, 1) 0%, rgba(248, 245, 240, 0.5) 100%);
}

.sidebar-header h2 {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--primary);
    letter-spacing: 0.15em;
}

.close-btn {
    width: 36px;
    height: 36px;
    background: transparent;
    border: none;
    color: var(--text-medium);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: background 0.2s;
}

.close-btn:hover {
    background: var(--border-light);
}

/* AI Header specific */
.ai-header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: #fff;
    border-bottom: none;
    position: relative;
}

.ai-header::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--accent), transparent);
}

.ai-header h2 {
    color: #fff;
    letter-spacing: 0.12em;
}

.ai-header .close-btn {
    color: #fff;
}

.ai-header .close-btn:hover {
    background: rgba(255,255,255,0.2);
}

.ai-title {
    display: flex;
    align-items: center;
    gap: 10px;
}

.ai-icon {
    font-size: 1.2rem;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* Chapter List */
.chapter-list {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: linear-gradient(180deg, rgba(255, 253, 248, 0.5) 0%, rgba(248, 245, 240, 0.3) 100%);
}

/* Navigation Sections */
.nav-section {
    margin-bottom: 28px;
}

.nav-section-header {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--primary);
    margin-bottom: 14px;
    padding: 8px 12px;
    background: linear-gradient(90deg, rgba(196, 163, 90, 0.12) 0%, transparent 100%);
    border-left: 3px solid var(--accent);
    border-radius: 0 4px 4px 0;
    letter-spacing: 0.1em;
}

.nav-section-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.nav-item {
    padding: 12px 10px;
    cursor: pointer;
    transition: all 0.25s ease;
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    border-radius: 6px;
    margin-bottom: 4px;
    position: relative;
}

.nav-item:hover {
    color: var(--primary);
    background: rgba(196, 163, 90, 0.08);
}

.nav-item.active {
    color: var(--primary);
    background: linear-gradient(90deg, rgba(139, 35, 35, 0.08) 0%, rgba(196, 163, 90, 0.05) 100%);
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 60%;
    background: var(--primary);
    border-radius: 0 2px 2px 0;
}

.nav-item.active .nav-item-name {
    font-weight: 600;
}

.nav-item.sub-entry {
    padding-left: 28px;
    position: relative;
}

.nav-item.sub-entry::after {
    content: '└';
    position: absolute;
    left: 10px;
    color: var(--border-accent);
    font-size: 0.85rem;
}

.nav-item-name {
    font-size: 1.05rem;
    color: inherit;
    margin-right: 6px;
    letter-spacing: 0.05em;
}

.nav-item-desc {
    font-size: 0.92rem;
    color: var(--text-light);
    letter-spacing: 0.02em;
}

/* Content Area */
.content-area {
    padding: 24px 16px;
    max-width: 800px;
    margin: 0 auto;
}

/* Chapter content wrapper */
.chapter-content {
    animation: chapterFadeIn 0.4s ease-out;
}

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

.chapter-header {
    text-align: center;
    padding: 28px 20px 24px;
    margin-bottom: 24px;
    position: relative;
    background: linear-gradient(180deg, rgba(196, 163, 90, 0.08) 0%, transparent 100%);
    border-radius: 8px;
}

.chapter-header::before {
    content: '◆';
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    color: var(--accent);
    font-size: 0.6rem;
    letter-spacing: 1em;
}

.chapter-header::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 120px;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--accent), var(--primary), var(--accent), transparent);
}

#chapterTitle {
    font-size: 1.6rem;
    font-weight: 500;
    letter-spacing: 0.35em;
    margin-bottom: 12px;
    color: var(--text-dark);
    text-shadow: 0 1px 2px rgba(44, 36, 22, 0.05);
}

.chapter-subtitle {
    font-size: 0.9rem;
    color: var(--accent-dark);
    letter-spacing: 0.15em;
    position: relative;
    display: inline-block;
    padding: 0 16px;
}

.chapter-subtitle::before,
.chapter-subtitle::after {
    content: '〔';
    color: var(--accent);
    opacity: 0.6;
}

.chapter-subtitle::after {
    content: '〕';
}

/* Text Content - Classical Book Style */
.text-area {
    background: var(--bg-paper);
    border-radius: 4px;
    border: 1px solid var(--border-accent);
    padding: 32px 28px;
    font-size: 1.08rem;
    line-height: 2.4;
    text-align: justify;
    position: relative;
    box-shadow: 
        0 2px 12px var(--shadow-warm),
        inset 0 0 60px rgba(196, 163, 90, 0.03);
}

/* Classical corner decorations */
.text-area::before,
.text-area::after {
    content: '';
    position: absolute;
    width: 24px;
    height: 24px;
    border-color: var(--accent);
    border-style: solid;
    opacity: 0.5;
}

.text-area::before {
    top: 8px;
    left: 8px;
    border-width: 2px 0 0 2px;
}

.text-area::after {
    bottom: 8px;
    right: 8px;
    border-width: 0 2px 2px 0;
}

.text-segment {
    cursor: pointer;
    transition: all 0.25s ease;
    border-radius: 3px;
    padding: 3px 6px;
    margin: 0 -6px;
    position: relative;
}

.text-segment:hover {
    background: linear-gradient(135deg, rgba(196, 163, 90, 0.12) 0%, rgba(196, 163, 90, 0.18) 100%);
    color: var(--text-dark);
}

.text-segment.selected {
    background: linear-gradient(135deg, rgba(139, 35, 35, 0.08) 0%, rgba(139, 35, 35, 0.12) 100%);
    color: var(--primary);
    box-shadow: 0 0 0 1px rgba(139, 35, 35, 0.15);
}

.content-hint {
    text-align: center;
    padding: 28px 0 20px;
    color: var(--text-light);
    font-size: 0.88rem;
}

.content-hint span {
    background: linear-gradient(135deg, var(--bg-cream) 0%, var(--bg-card) 100%);
    padding: 10px 20px;
    border-radius: 24px;
    border: 1px dashed var(--border-accent);
    letter-spacing: 0.1em;
}

/* ============== Book Introduction Page ============== */
.intro-page {
    animation: fadeIn 0.5s ease-out;
}

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

.intro-header {
    text-align: center;
    padding: 48px 20px 40px;
    background: linear-gradient(180deg, rgba(196, 163, 90, 0.1) 0%, rgba(196, 163, 90, 0.02) 100%);
    border-radius: 8px;
    margin-bottom: 28px;
    position: relative;
    border: 1px solid var(--border-accent);
}

/* Classical corner decorations for intro header */
.intro-header::before,
.intro-header::after {
    content: '';
    position: absolute;
    width: 28px;
    height: 28px;
    border-color: var(--accent);
    border-style: solid;
    opacity: 0.4;
}

.intro-header::before {
    top: 12px;
    left: 12px;
    border-width: 2px 0 0 2px;
}

.intro-header::after {
    bottom: 12px;
    right: 12px;
    border-width: 0 2px 2px 0;
}

.book-icon {
    width: 88px;
    height: 88px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: var(--accent-light);
    font-size: 2rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 24px;
    box-shadow: 
        0 8px 24px rgba(139, 35, 35, 0.25),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(196, 163, 90, 0.3);
}

.book-title {
    font-size: 2.2rem;
    font-weight: 500;
    color: var(--text-dark);
    letter-spacing: 0.25em;
    margin-bottom: 16px;
    text-shadow: 0 1px 2px rgba(44, 36, 22, 0.05);
}

.book-meta {
    font-size: 0.95rem;
    color: var(--accent-dark);
    letter-spacing: 0.25em;
    position: relative;
    display: inline-block;
}

.book-meta::before {
    content: '〔';
    color: var(--accent);
    opacity: 0.5;
    margin-right: 4px;
}

.book-meta::after {
    content: '〕';
    color: var(--accent);
    opacity: 0.5;
    margin-left: 4px;
}

.intro-content {
    background: var(--bg-paper);
    border-radius: 6px;
    border: 1px solid var(--border-accent);
    overflow: hidden;
    position: relative;
    box-shadow: 
        0 2px 12px var(--shadow-warm),
        inset 0 0 80px rgba(196, 163, 90, 0.02);
}

/* Classical corner decorations for intro content */
.intro-content::before,
.intro-content::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    border-color: var(--accent);
    border-style: solid;
    opacity: 0.35;
    z-index: 1;
    pointer-events: none;
}

.intro-content::before {
    top: 10px;
    left: 10px;
    border-width: 2px 0 0 2px;
}

.intro-content::after {
    bottom: 10px;
    right: 10px;
    border-width: 0 2px 2px 0;
}

.intro-section {
    padding: 32px 28px;
    border-bottom: 1px solid var(--border-light);
    position: relative;
}

.intro-section:last-child {
    border-bottom: none;
}

.section-title {
    display: flex;
    align-items: center;
    gap: 14px;
    font-size: 1.15rem;
    font-weight: 500;
    color: var(--primary);
    margin-bottom: 20px;
    letter-spacing: 0.08em;
}

.title-icon {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--accent-light) 0%, var(--accent) 100%);
    color: var(--primary-dark);
    font-size: 0.95rem;
    font-weight: 600;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(196, 163, 90, 0.3);
}

.section-body {
    color: var(--text-medium);
    line-height: 2.2;
}

.section-body p {
    margin-bottom: 18px;
    text-indent: 2em;
    text-align: justify;
}

.section-body p:last-child {
    margin-bottom: 0;
}

.intro-footer {
    text-align: center;
    padding: 36px 20px;
    position: relative;
}

.intro-footer::before {
    content: '◇  ◇  ◇';
    display: block;
    color: var(--accent);
    opacity: 0.5;
    font-size: 0.7rem;
    letter-spacing: 0.5em;
    margin-bottom: 16px;
}

.footer-decoration {
    width: 80px;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--accent), var(--primary), var(--accent), transparent);
    margin: 0 auto 20px;
}

.footer-text {
    color: var(--text-light);
    font-size: 0.92rem;
    letter-spacing: 0.15em;
}

/* Clickable Book Title in Sidebar */
.sidebar-left .sidebar-header h2 {
    cursor: pointer;
    transition: all 0.2s;
}

.sidebar-left .sidebar-header h2:hover {
    color: var(--accent-dark);
    transform: translateX(2px);
}

/* ============== End Book Introduction Page ============== */

/* AI Content */
.ai-content {
    flex: 1;
    overflow-y: auto;
    padding: 18px;
    background: linear-gradient(180deg, rgba(255, 253, 248, 0.8) 0%, var(--bg-main) 100%);
}

/* Ensure last card has extra bottom margin */
.ai-response .response-card:last-child {
    margin-bottom: 12px;
}

/* AI Response container */
.ai-response {
    animation: fadeIn 0.4s ease-out;
}

/* AI Welcome */
.ai-welcome {
    text-align: center;
    padding: 12px 0;
}

.welcome-icon {
    font-size: 3rem;
    margin-bottom: 16px;
}

.ai-welcome h3 {
    font-size: 1.15rem;
    color: var(--primary);
    margin-bottom: 8px;
    letter-spacing: 0.1em;
}

.ai-welcome p {
    font-size: 0.9rem;
    color: var(--text-medium);
    margin-bottom: 16px;
}

.welcome-desc {
    font-size: 0.95rem;
    line-height: 2;
    color: var(--text-medium);
    text-align: center;
    padding: 0 12px;
}

/* Welcome Example Section */
.welcome-example {
    margin-top: 32px;
    padding: 0 4px;
}

.example-header {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
}

.example-badge {
    background: transparent;
    color: var(--text-light);
    font-size: 0.82rem;
    padding: 0;
    border-radius: 0;
    font-weight: 400;
    letter-spacing: 0.2em;
    border-bottom: 1px dashed var(--border-accent);
    padding-bottom: 4px;
}

/* Step Guide Styles */
.guide-step {
    display: flex;
    gap: 12px;
    margin-bottom: 4px;
}

.step-indicator {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 24px;
    flex-shrink: 0;
}

.step-number {
    width: 24px;
    height: 24px;
    background: var(--primary);
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 600;
}

.step-line {
    flex: 1;
    width: 2px;
    background: var(--border);
    margin: 4px 0;
    min-height: 20px;
}

.step-content {
    flex: 1;
    padding-bottom: 12px;
}

.step-title {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-dark);
    margin-bottom: 8px;
}

.step-demo {
    background: var(--bg-paper);
    border-radius: 6px;
    padding: 12px 14px;
    border: 1px dashed var(--border-accent);
}

.step-demo-menu {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
}

.demo-icon {
    color: var(--text-medium);
}

.demo-text {
    color: var(--text-medium);
}

.demo-arrow {
    color: var(--accent);
    margin: 0 4px;
}

.demo-chapter {
    background: var(--primary);
    color: #fff;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
}

.step-demo-text {
    font-size: 0.85rem;
    color: var(--text-medium);
    line-height: 1.6;
}

.step-demo-text p {
    margin: 0;
}

.highlight-text {
    background: rgba(139, 35, 35, 0.12);
    color: var(--primary);
    padding: 2px 4px;
    border-radius: 4px;
}

.step-result-preview {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.preview-card {
    background: var(--bg-paper);
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid var(--border-accent);
}

.preview-card-header {
    padding: 8px 12px;
    background: linear-gradient(90deg, rgba(196, 163, 90, 0.08) 0%, transparent 100%);
    border-bottom: 1px solid var(--border-light);
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--primary);
    letter-spacing: 0.05em;
    border-left: 2px solid var(--accent);
}

.preview-card-body {
    padding: 10px 12px;
    font-size: 0.78rem;
    line-height: 1.7;
    color: var(--text-light);
}

.preview-card-warning .preview-card-header {
    border-left-color: var(--primary);
    background: linear-gradient(90deg, rgba(139, 35, 35, 0.08) 0%, transparent 100%);
}

.preview-card-warning .preview-card-body {
    border-left: none;
}

.preview-card-success .preview-card-header {
    border-left-color: var(--success);
    background: linear-gradient(90deg, rgba(74, 124, 89, 0.08) 0%, transparent 100%);
}

.preview-card-success .preview-card-body {
    border-left: none;
}

/* AI Loading */
.ai-loading {
    text-align: center;
    padding: 40px 0;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    margin: 0 auto 16px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.ai-loading p {
    color: var(--text-light);
}

/* AI Response */
.selected-text {
    background: var(--bg-paper);
    border: 1px solid var(--border-accent);
    border-radius: 6px;
    padding: 16px 18px;
    margin-bottom: 18px;
    position: relative;
    box-shadow: 0 2px 8px var(--shadow-warm);
}

/* Classical corner decorations for selected text */
.selected-text::before,
.selected-text::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    border-color: var(--accent);
    border-style: solid;
    opacity: 0.4;
}

.selected-text::before {
    top: 6px;
    left: 6px;
    border-width: 2px 0 0 2px;
}

.selected-text::after {
    bottom: 6px;
    right: 6px;
    border-width: 0 2px 2px 0;
}

.selected-text .label {
    display: block;
    font-size: 0.72rem;
    color: var(--accent-dark);
    letter-spacing: 0.15em;
    margin-bottom: 8px;
    padding-bottom: 6px;
    border-bottom: 1px dashed var(--border-accent);
}

.selected-text p {
    font-size: 0.95rem;
    line-height: 1.9;
    color: var(--text-dark);
}

.response-card {
    background: var(--bg-paper);
    border-radius: 6px;
    margin-bottom: 14px;
    overflow: hidden;
    border: 1px solid var(--border-accent);
    box-shadow: 0 2px 8px var(--shadow-warm);
}

.card-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: linear-gradient(90deg, rgba(196, 163, 90, 0.1) 0%, transparent 100%);
    border-bottom: 1px solid var(--border-light);
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--primary);
    letter-spacing: 0.08em;
    border-left: 3px solid var(--accent);
}

.card-body {
    padding: 16px 18px;
    font-size: 0.92rem;
    line-height: 2;
    color: var(--text-medium);
    background: var(--bg-paper);
}

.card-body p {
    margin-bottom: 10px;
    text-align: justify;
}

.card-body p:last-child {
    margin-bottom: 0;
}

.response-card.positive .card-header {
    border-left-color: var(--success);
    background: linear-gradient(90deg, rgba(74, 124, 89, 0.08) 0%, transparent 100%);
}

.response-card.positive .card-body {
    border-left: none;
    background: linear-gradient(90deg, rgba(74, 124, 89, 0.03) 0%, transparent 50%);
}

.response-card.negative .card-header {
    border-left-color: var(--primary);
    background: linear-gradient(90deg, rgba(139, 35, 35, 0.08) 0%, transparent 100%);
}

.response-card.negative .card-body {
    border-left: none;
    background: linear-gradient(90deg, rgba(139, 35, 35, 0.03) 0%, transparent 50%);
}

/* AI Error */
.ai-error {
    text-align: center;
    padding: 40px 20px;
}

.error-icon {
    font-size: 3rem;
    margin-bottom: 16px;
}

.ai-error p {
    color: var(--text-medium);
    margin-bottom: 16px;
}

.retry-btn {
    background: var(--primary);
    color: #fff;
    border: none;
    padding: 10px 24px;
    border-radius: 8px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: background 0.2s;
}

.retry-btn:hover {
    background: var(--primary-dark);
}

/* Overlay */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
}

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

/* Desktop Styles */
@media (min-width: 1024px) {
    .header-btn {
        display: none;
    }
    
    .header {
        padding: 0 24px;
    }
    
    .logo-text {
        font-size: 1.3rem;
    }
    
    .main-content {
        display: grid;
        grid-template-columns: var(--sidebar-width) 1fr var(--ai-panel-width);
    }
    
    .sidebar {
        position: sticky;
        top: var(--header-height);
        bottom: auto; /* Override mobile bottom: 0 */
        height: calc(100vh - var(--header-height));
        transform: none !important;
        box-shadow: none;
        z-index: 1;
    }
    
    .sidebar-left {
        border-right: 1px solid var(--border);
    }
    
    .sidebar-right {
        border-left: 1px solid var(--border);
        max-width: none;
        width: auto;
    }
    
    .close-btn {
        display: none;
    }
    
    .sidebar-header {
        justify-content: center;
    }
    
    .ai-header {
        justify-content: flex-start;
    }
    
    .content-area {
        padding: 40px 48px;
    }
    
    #chapterTitle {
        font-size: 2.2rem;
        letter-spacing: 0.4em;
    }
    
    .chapter-header::after {
        width: 160px;
    }
    
    .text-area {
        padding: 40px 36px;
        font-size: 1.18rem;
        line-height: 2.5;
    }
    
    .text-area::before,
    .text-area::after {
        width: 32px;
        height: 32px;
    }
    
    .text-area::before {
        top: 12px;
        left: 12px;
    }
    
    .text-area::after {
        bottom: 12px;
        right: 12px;
    }
    
    .overlay {
        display: none !important;
    }
}

/* Tablet Styles */
@media (min-width: 768px) and (max-width: 1023px) {
    .sidebar-right {
        max-width: 400px;
    }
    
    .content-area {
        padding: 24px;
    }
}

/* Mobile - Extra bottom padding for sidebars */
@media (max-width: 1023px) {
    .ai-content {
        padding-bottom: 60px;
    }
    
    .ai-response .response-card:last-child {
        margin-bottom: 30px;
    }
    
    .chapter-list {
        padding-bottom: 60px;
    }
}

/* Small Mobile */
@media (max-width: 380px) {
    .logo-text {
        font-size: 0.95rem;
    }
    
    .logo-icon {
        width: 30px;
        height: 30px;
        font-size: 0.9rem;
    }
    
    .header-btn.with-label {
        padding: 6px 10px;
        gap: 4px;
    }
    
    .btn-label {
        font-size: 0.75rem;
    }
    
    .sidebar-left {
        width: 260px;
    }
    
    .content-area {
        padding: 16px 12px;
    }
    
    .text-area {
        padding: 16px;
        font-size: 0.95rem;
    }
}
