/* ============================================
   BIBLIA CONTEXT - Timeline + AI Sidebar
   ============================================ */

.ctx-panel {
    margin-top: 32px;
    padding: 20px;
    border-radius: 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 24px var(--shadow-sm);
}

/* ============ HEADER ============ */
.ctx-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border-color);
}

.ctx-book-badge {
    display: flex;
    align-items: center;
    gap: 12px;
}

.ctx-book-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1em;
    font-weight: 800;
    color: white;
    flex-shrink: 0;
}
.ctx-book-icon.bc { background: linear-gradient(135deg, #7c3aed, #5b21b6); }
.ctx-book-icon.ad { background: linear-gradient(135deg, #059669, #047857); }

.ctx-book-name {
    font-size: 1.15em;
    font-weight: 700;
    color: var(--text-heading);
}

.ctx-book-detail {
    font-size: 0.78em;
    color: var(--text-secondary);
    margin-top: 2px;
}

.ctx-era-badge {
    font-size: 0.78em;
    font-weight: 700;
    padding: 6px 14px;
    border-radius: 20px;
    white-space: nowrap;
}
.ctx-era-badge.bc {
    background: rgba(124, 58, 237, 0.12);
    color: #7c3aed;
    border: 1px solid rgba(124, 58, 237, 0.2);
}
[data-theme="dark"] .ctx-era-badge.bc {
    background: rgba(147, 130, 210, 0.12);
    color: #c4b5fd;
    border-color: rgba(147, 130, 210, 0.25);
}
.ctx-era-badge.ad {
    background: rgba(5, 150, 105, 0.1);
    color: #059669;
    border: 1px solid rgba(5, 150, 105, 0.2);
}
[data-theme="dark"] .ctx-era-badge.ad {
    background: rgba(52, 211, 153, 0.1);
    color: #6ee7b7;
    border-color: rgba(52, 211, 153, 0.2);
}

/* ============ TIMELINE ============ */
.ctx-timeline-section {
    margin-bottom: 16px;
}

.ctx-timeline-bar {
    position: relative;
    height: 72px;
    border-radius: 14px;
    overflow: visible;
    cursor: pointer;
    user-select: none;
}

.ctx-tl-bg {
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 48px;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.ctx-tl-bc {
    position: absolute;
    top: 0; left: 0;
    height: 100%;
    background: linear-gradient(135deg, #1e1b4b 0%, #312e81 40%, #3730a3 100%);
}
[data-theme="light"] .ctx-tl-bc {
    background: linear-gradient(135deg, #ddd6fe 0%, #c4b5fd 40%, #a78bfa 100%);
}

.ctx-tl-ad {
    position: absolute;
    top: 0;
    height: 100%;
    background: linear-gradient(135deg, #064e3b 0%, #065f46 40%, #047857 100%);
}
[data-theme="light"] .ctx-tl-ad {
    background: linear-gradient(135deg, #d1fae5 0%, #a7f3d0 40%, #6ee7b7 100%);
}

.ctx-tl-era-label {
    position: absolute;
    top: 4px;
    font-size: 0.6em;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 2px;
    opacity: 0.45;
    pointer-events: none;
    z-index: 1;
}
.ctx-tl-era-label.bc-label { left: 8px; color: rgba(255,255,255,0.7); }
.ctx-tl-era-label.ad-label { right: 8px; color: rgba(255,255,255,0.7); }
[data-theme="light"] .ctx-tl-era-label.bc-label { color: rgba(91, 33, 182, 0.4); }
[data-theme="light"] .ctx-tl-era-label.ad-label { color: rgba(4, 120, 87, 0.4); }

/* Periods */
.ctx-tl-periods {
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 48px;
    z-index: 4;
}

.ctx-tl-period {
    position: absolute;
    top: 14px;
    height: 20px;
    border-radius: 4px;
    opacity: 0.3;
    transition: all 0.3s;
    cursor: pointer;
}
.ctx-tl-period:hover { opacity: 0.6; }
.ctx-tl-period.active-period { opacity: 0.65; }

/* Book Range */
.ctx-tl-range {
    position: absolute;
    top: 0;
    height: 48px;
    border-radius: 8px;
    transition: all 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 2;
    pointer-events: none;
    overflow: hidden;
}

.ctx-tl-range-fill {
    width: 100%;
    height: 100%;
    background: var(--accent-primary);
    opacity: 0.5;
    animation: ctxPulse 2.5s ease-in-out infinite;
}

.ctx-tl-range-border {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    border: 2px solid var(--accent-primary);
    border-radius: 8px;
    opacity: 0.8;
}

.ctx-tl-range-label {
    position: absolute;
    top: 14px;
    transform: translateX(-50%);
    font-size: 0.65em;
    font-weight: 800;
    color: white;
    text-shadow: 0 1px 4px rgba(0,0,0,0.7);
    white-space: nowrap;
    z-index: 3;
    pointer-events: none;
}
[data-theme="light"] .ctx-tl-range-label {
    color: #1e1b4b;
    text-shadow: 0 1px 2px rgba(255,255,255,0.8);
}

@keyframes ctxPulse {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 0.6; }
}

/* Event dots */
.ctx-tl-events {
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 48px;
    z-index: 5;
    pointer-events: none;
}

.ctx-tl-dot {
    position: absolute;
    top: 18px;
    width: 10px;
    height: 10px;
    background: #fbbf24;
    border: 2px solid rgba(0,0,0,0.4);
    border-radius: 50%;
    transform: translateX(-50%);
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 0 4px rgba(251, 191, 36, 0.5);
    z-index: 5;
    pointer-events: auto;
}
.ctx-tl-dot:hover {
    transform: translateX(-50%) scale(1.8);
    box-shadow: 0 0 14px rgba(251, 191, 36, 0.9);
    z-index: 10;
}

.ctx-tl-dot-tip {
    position: absolute;
    bottom: calc(100% + 10px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 0.72em;
    color: var(--text-primary);
    white-space: nowrap;
    box-shadow: 0 4px 16px var(--shadow-md);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    z-index: 20;
    line-height: 1.5;
}
.ctx-tl-dot:hover .ctx-tl-dot-tip { opacity: 1; }

/* Christ marker */
.ctx-tl-christ {
    position: absolute;
    top: -2px;
    z-index: 6;
    transform: translateX(-50%);
    pointer-events: none;
}

.ctx-tl-christ-line {
    width: 3px;
    height: 52px;
    background: linear-gradient(180deg, #fbbf24, #f59e0b, #d97706);
    margin: 0 auto;
    box-shadow: 0 0 8px rgba(251, 191, 36, 0.6);
    border-radius: 2px;
}

.ctx-tl-christ-label {
    font-size: 0.62em;
    font-weight: 800;
    color: #fbbf24;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    margin-top: 2px;
    text-shadow: 0 1px 4px rgba(0,0,0,0.6);
}
[data-theme="light"] .ctx-tl-christ-label {
    color: #b45309;
    text-shadow: none;
}

/* Year labels */
.ctx-tl-labels {
    position: absolute;
    top: 52px;
    left: 0; right: 0;
    height: 18px;
}

.ctx-tl-label {
    position: absolute;
    font-size: 0.62em;
    font-weight: 600;
    color: var(--text-tertiary);
    transform: translateX(-50%);
    white-space: nowrap;
}

/* ============ CONTEXT ACTION BUTTONS ============ */
.ctx-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 14px;
}

.ctx-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 8px 14px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    font-size: 0.82em;
    color: var(--text-primary);
}
.ctx-action-btn:hover {
    border-color: var(--accent-primary);
    background: var(--accent-light, rgba(102, 126, 234, 0.08));
    color: var(--accent-primary);
    transform: translateY(-1px);
    box-shadow: 0 3px 12px var(--shadow-sm);
}

.ctx-action-icon {
    font-size: 1.1em;
}

.ctx-action-label {
    font-weight: 600;
    white-space: nowrap;
}

/* ============ KEY EVENTS CHIPS ============ */
.ctx-events-section {
    margin-bottom: 8px;
}

.ctx-events-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.ctx-event-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 8px 14px;
    transition: all 0.2s;
    cursor: pointer;
}
.ctx-event-chip:hover {
    border-color: var(--accent-primary);
    box-shadow: 0 2px 12px var(--shadow-sm);
    transform: translateY(-1px);
}

.ctx-event-year {
    font-size: 0.72em;
    font-weight: 800;
    padding: 3px 10px;
    border-radius: 6px;
    white-space: nowrap;
}

.ctx-year-bc {
    background: rgba(124, 58, 237, 0.1);
    color: #7c3aed;
}
[data-theme="dark"] .ctx-year-bc {
    background: rgba(147, 130, 210, 0.12);
    color: #c4b5fd;
}

.ctx-year-ad {
    background: rgba(5, 150, 105, 0.08);
    color: #059669;
}
[data-theme="dark"] .ctx-year-ad {
    background: rgba(52, 211, 153, 0.1);
    color: #6ee7b7;
}

.ctx-event-text {
    font-size: 0.82em;
    color: var(--text-primary);
    font-weight: 500;
}

.ctx-event-arrow {
    font-size: 0.75em;
    color: var(--text-tertiary);
    transition: color 0.2s;
}
.ctx-event-chip:hover .ctx-event-arrow {
    color: var(--accent-primary);
}

/* ============ SIDEBAR AI THINKING ============ */
.ctx-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    padding: 50px 24px;
    min-height: 220px;
}

/* Brain icon with pulse ring */
.ctx-thinking-brain {
    position: relative;
    width: 64px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ctx-thinking-icon {
    font-size: 2em;
    z-index: 2;
    animation: ctxBrainBounce 2s ease-in-out infinite;
}

.ctx-thinking-pulse {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    border-radius: 50%;
    background: var(--accent-primary, #667eea);
    opacity: 0.15;
    animation: ctxPulseRing 2s ease-in-out infinite;
}

@keyframes ctxBrainBounce {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

@keyframes ctxPulseRing {
    0% { transform: scale(0.8); opacity: 0.2; }
    50% { transform: scale(1.3); opacity: 0.05; }
    100% { transform: scale(0.8); opacity: 0.2; }
}

/* Status text */
.ctx-thinking-status {
    text-align: center;
}

.ctx-thinking-label {
    font-size: 1em;
    font-weight: 700;
    color: var(--text-heading, #1a202c);
    margin-bottom: 6px;
}

.ctx-thinking-dots::after {
    content: '';
    animation: ctxDots 1.5s steps(4, end) infinite;
}

@keyframes ctxDots {
    0% { content: ''; }
    25% { content: '.'; }
    50% { content: '..'; }
    75% { content: '...'; }
}

.ctx-thinking-detail {
    font-size: 0.82em;
    color: var(--text-secondary, #718096);
    margin-top: 4px;
    transition: opacity 0.3s;
    min-height: 1.2em;
}

/* Progress bar */
.ctx-thinking-bar {
    width: 180px;
    height: 4px;
    border-radius: 4px;
    background: var(--border-color, #e2e8f0);
    overflow: hidden;
}

.ctx-thinking-bar-fill {
    height: 100%;
    width: 40%;
    border-radius: 4px;
    background: linear-gradient(90deg, var(--accent-primary, #667eea), #764ba2);
    animation: ctxBarSlide 1.8s ease-in-out infinite;
}

@keyframes ctxBarSlide {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(350%); }
}

.ctx-error {
    padding: 20px;
    text-align: center;
    color: #e74c3c;
    font-size: 0.88em;
}

.ctx-ai-response {
    font-size: 0.88em;
    line-height: 1.7;
    color: var(--text-primary);
    word-wrap: break-word;
}

.ctx-ai-response strong {
    color: var(--text-heading);
    font-weight: 700;
}

.ctx-resp-heading {
    font-size: 1em;
    font-weight: 700;
    color: var(--accent-primary);
    margin: 16px 0 8px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--border-color);
}

.ctx-resp-bullet {
    padding-left: 8px;
    margin: 4px 0;
    line-height: 1.6;
}

/* ============ VERSE ACTION MENU EXTRAS ============ */
.verse-action-divider {
    height: 1px;
    background: var(--border-color);
    margin: 4px 8px;
}
.ctx-verse-btn {
    color: var(--accent-primary, #667eea) !important;
    font-weight: 600 !important;
}

/* ============ SIDEBAR SECTIONS (Expandable) ============ */
.ctx-sidebar-section {
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 0;
}
.ctx-sidebar-section:last-child { border-bottom: none; }

/* Narrate context button (injected at top of AI content) */
.ctx-narrate-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 10px 16px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    margin-bottom: 14px;
    letter-spacing: 0.3px;
    transition: transform 0.15s, box-shadow 0.15s;
}
.ctx-narrate-btn:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 16px rgba(102,126,234,0.4);
}

.ctx-section-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 14px 16px;
    border: none;
    background: none;
    color: var(--text-heading);
    font-size: 0.92em;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.2s;
}
.ctx-section-toggle:hover {
    background: var(--bg-hover, rgba(0,0,0,0.03));
}
.ctx-section-toggle .ctx-section-icon {
    font-size: 1.1em;
    margin-right: 8px;
}
.ctx-section-toggle .ctx-section-arrow {
    font-size: 0.7em;
    color: var(--text-tertiary);
    transition: transform 0.3s;
}
.ctx-section-toggle[aria-expanded="true"] .ctx-section-arrow {
    transform: rotate(180deg);
}

.ctx-section-body {
    overflow: hidden;
    max-height: 0;
    transition: max-height 0.4s ease;
}
.ctx-section-body.open {
    max-height: 5000px;
}
.ctx-section-content {
    padding: 0 16px 16px;
}

/* Map viewer */
.ctx-map-container {
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
}
.ctx-map-img {
    width: 100%;
    height: auto;
    display: block;
    cursor: zoom-in;
    transition: transform 0.3s;
}
.ctx-map-img.zoomed {
    cursor: zoom-out;
    transform: scale(1.8);
    transform-origin: var(--zoom-x, center) var(--zoom-y, center);
}
.ctx-map-title {
    padding: 10px 14px;
    font-size: 0.82em;
    font-weight: 600;
    color: var(--text-secondary);
    text-align: center;
    background: var(--bg-tertiary);
}
.ctx-map-credit {
    font-size: 0.7em;
    color: var(--text-tertiary);
    text-align: center;
    padding: 4px 14px 10px;
}
.ctx-map-fullscreen {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: rgba(0,0,0,0.5);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9em;
    z-index: 2;
    transition: background 0.2s;
}
.ctx-map-fullscreen:hover { background: rgba(0,0,0,0.7); }

/* Map gallery (multiple maps per book) */
.ctx-map-gallery {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 10px;
}
.ctx-map-thumb {
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border-color);
    cursor: pointer;
    background: var(--bg-tertiary);
}
.ctx-map-thumb:hover {
    border-color: var(--accent-primary);
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.ctx-map-thumb img {
    width: 100%;
    height: 80px;
    object-fit: cover;
}
.ctx-map-thumb-title {
    padding: 4px 6px;
    font-size: 0.7em;
    color: var(--text-secondary);
    text-align: center;
    line-height: 1.2;
}

/* Image gallery */
.ctx-gallery {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}
.ctx-gallery-item {
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}
.ctx-gallery-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px var(--shadow-md);
}
.ctx-gallery-item img {
    width: 100%;
    height: 120px;
    object-fit: cover;
    display: block;
}
.ctx-gallery-caption {
    padding: 8px 10px;
    font-size: 0.75em;
    color: var(--text-secondary);
    line-height: 1.3;
}
.ctx-gallery-artist {
    font-size: 0.68em;
    color: var(--text-tertiary);
    font-style: italic;
}

/* Image lightbox */
.ctx-lightbox {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.92);
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}
.ctx-lightbox.active {
    opacity: 1;
    pointer-events: auto;
}
.ctx-lightbox img {
    max-width: 95%;
    max-height: 90vh;
    border-radius: 8px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.5);
}
.ctx-lightbox-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    color: white;
    border: none;
    cursor: pointer;
    font-size: 1.3em;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}
.ctx-lightbox-caption {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    color: white;
    font-size: 0.9em;
    text-align: center;
    text-shadow: 0 1px 4px rgba(0,0,0,0.8);
    max-width: 80%;
}

/* Infographics Grid */
.ctx-infog-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 10px;
    padding: 8px 0;
}
.ctx-infog-card {
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    background: var(--bg-tertiary, #2a2a3e);
    border: 1px solid rgba(102, 126, 234, 0.15);
    transition: transform 0.2s, box-shadow 0.2s;
}
.ctx-infog-card:hover {
    transform: scale(1.03);
    box-shadow: 0 4px 16px rgba(102, 126, 234, 0.2);
}
.ctx-infog-card img {
    width: 100%;
    aspect-ratio: 3/4;
    object-fit: cover;
    display: block;
}
.ctx-infog-title {
    padding: 6px 8px;
    font-size: 10px;
    font-weight: 500;
    line-height: 1.3;
    color: var(--text-secondary, #a0a0b8);
}
.ctx-empty {
    padding: 16px;
    text-align: center;
    font-size: 12px;
    color: var(--text-tertiary, #777);
    opacity: 0.7;
}

/* No data placeholder */
.ctx-no-data {
    text-align: center;
    padding: 24px 16px;
    color: var(--text-tertiary);
    font-size: 0.85em;
}
.ctx-no-data-icon {
    font-size: 2em;
    margin-bottom: 8px;
    opacity: 0.5;
}

/* ============ ACTIVE/TOUCH FEEDBACK ============ */
.ctx-action-btn:active {
    transform: scale(0.95);
    background: var(--accent-light, rgba(102, 126, 234, 0.15));
    border-color: var(--accent-primary);
    transition: transform 0.1s;
}
.ctx-event-chip:active {
    transform: scale(0.97);
    background: var(--accent-light, rgba(102, 126, 234, 0.08));
    transition: transform 0.1s;
}
.ctx-tl-period:active { opacity: 0.8; }

/* ============ COLLAPSIBLE CONTEXT (mobile) ============ */
.ctx-collapse-toggle {
    display: none;
}

/* ============ BACK TO TOP BUTTON ============ */
.btt-btn {
    position: fixed;
    bottom: 80px;
    right: 20px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--accent-primary, #667eea);
    color: white;
    border: none;
    font-size: 1.2em;
    cursor: pointer;
    box-shadow: 0 4px 14px var(--shadow-md, rgba(0,0,0,0.15));
    z-index: 89;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s, transform 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
}
.btt-btn.visible {
    opacity: 1;
    pointer-events: auto;
}
.btt-btn:active {
    transform: scale(0.9);
}

/* ============ VOTD DISMISS ============ */
.votd-close {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 0.8em;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}
.votd-close:hover { background: rgba(255,255,255,0.35); }

/* ============ MOBILE ============ */
@media (max-width: 768px) {
    .ctx-panel { margin-top: 20px; padding: 14px; }
    .ctx-header { flex-direction: column; gap: 10px; align-items: flex-start; }
    .ctx-book-icon { width: 36px; height: 36px; font-size: 0.9em; }
    .ctx-book-name { font-size: 1em; }
    .ctx-timeline-bar { height: 66px; }
    .ctx-tl-bg { height: 42px; }
    .ctx-tl-range { height: 42px; }
    .ctx-tl-christ-line { height: 46px; }
    .ctx-tl-events { height: 42px; }

    /* Fix #3: Dots — visible 10px, touch area 44px via padding */
    .ctx-tl-dot {
        top: 11px;
        width: 10px;
        height: 10px;
        padding: 17px;
        margin: -17px;
        background-clip: content-box;
        border: none;
        box-shadow: none;
        position: absolute;
    }
    .ctx-tl-dot::after {
        content: '';
        position: absolute;
        top: 50%;
        left: 50%;
        width: 10px;
        height: 10px;
        transform: translate(-50%, -50%);
        background: #fbbf24;
        border: 2px solid rgba(0,0,0,0.4);
        border-radius: 50%;
        box-shadow: 0 0 4px rgba(251, 191, 36, 0.5);
    }

    /* Fix #4: Year labels legible */
    .ctx-tl-labels { top: 46px; }
    .ctx-tl-label { font-size: 0.72em; }
    .ctx-tl-range-label { font-size: 0.6em; }

    /* Fix #2: Context buttons scroll with fade hint */
    .ctx-actions {
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
        position: relative;
        mask-image: linear-gradient(to right, black 85%, transparent 100%);
        -webkit-mask-image: linear-gradient(to right, black 85%, transparent 100%);
        padding-bottom: 4px;
    }
    .ctx-action-btn { flex-shrink: 0; }

    /* Fix #9: Collapsible context panel */
    .ctx-collapse-toggle {
        display: flex;
        align-items: center;
        justify-content: space-between;
        width: 100%;
        padding: 10px 0;
        border: none;
        background: none;
        color: var(--text-heading);
        font-size: 0.95em;
        font-weight: 700;
        cursor: pointer;
        font-family: inherit;
    }
    .ctx-collapse-toggle .ctx-collapse-arrow {
        transition: transform 0.3s;
        font-size: 0.8em;
        color: var(--text-tertiary);
    }
    .ctx-collapse-toggle[aria-expanded="true"] .ctx-collapse-arrow {
        transform: rotate(180deg);
    }
    .ctx-collapse-body {
        overflow: hidden;
        transition: max-height 0.4s ease, opacity 0.3s;
    }
    .ctx-collapse-body.collapsed {
        max-height: 0 !important;
        opacity: 0;
        overflow: hidden;
    }

    .ctx-events-list { flex-direction: column; }
    .ctx-event-chip { width: 100%; }

    /* Fix #15: Prevent floating buttons overlapping content */
    .ctx-panel { margin-bottom: 80px; }

    /* Back to top button position for mobile */
    .btt-btn { bottom: calc(76px + env(safe-area-inset-bottom, 0px)); right: 14px; }

    /* Sidebar full-screen on mobile */
    .ctx-sidebar,
    .sidebar.sidebar-right,
    .sidebar.sidebar-left {
        width: 100% !important;
    }

    /* Map & infographic images fill container */
    .ctx-map-container { border-radius: 10px; }
    .ctx-map-img { border-radius: 10px; }
    .ctx-infog-grid {
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)) !important;
        gap: 8px !important;
    }

    /* Lightbox touch-friendly */
    .ctx-lightbox img {
        max-width: 98%;
        max-height: 85vh;
        border-radius: 4px;
    }
    .ctx-lightbox-close {
        top: calc(10px + env(safe-area-inset-top, 0px));
        right: 10px;
        width: 48px;
        height: 48px;
        font-size: 1.4em;
        background: rgba(0,0,0,0.5);
    }
    .ctx-lightbox-caption {
        bottom: calc(12px + env(safe-area-inset-bottom, 0px));
        font-size: 0.8em;
        max-width: 90%;
    }

    /* Narrate button compact */
    .ctx-narrate-btn { padding: 8px 12px; font-size: 12px; min-height: 44px; }

    /* AI content readable */
    .ctx-ai-content { font-size: 0.9em; }

    /* Timeline labels smaller on mobile */
    .ctx-tl-range-label { font-size: 0.55em; }
    .ctx-tl-label { font-size: 0.65em; white-space: nowrap; }
}

/* Extra small phones */
@media (max-width: 400px) {
    .ctx-panel { padding: 10px; }
    .ctx-header { gap: 8px; }
    .ctx-book-name { font-size: 0.9em; }
    .ctx-action-btn { font-size: 0.72em; padding: 5px 8px; }
    .ctx-infog-grid {
        grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)) !important;
    }
}

/* ============================================
   INLINE CHAPTER ILLUSTRATIONS
   ============================================ */
.ctx-inline-illustration {
    margin: 20px -8px;
    border-radius: 14px;
    overflow: hidden;
    background: var(--card-bg, #fff);
    box-shadow: 0 4px 20px rgba(0,0,0,0.10), 0 1px 4px rgba(0,0,0,0.06);
    cursor: pointer;
    opacity: 0;
    transform: translateY(30px) scale(0.97);
    transition: opacity 0.7s ease, transform 0.7s cubic-bezier(0.22, 1, 0.36, 1);
    position: relative;
}
.ctx-inline-illustration.visible {
    opacity: 1;
    transform: translateY(0) scale(1);
}
.ctx-inline-illustration:active {
    transform: scale(0.98);
    transition: transform 0.1s;
}
.ctx-inline-img-wrap {
    position: relative;
    width: 100%;
    max-height: 320px;
    overflow: hidden;
}
.ctx-inline-img-wrap img {
    width: 100%;
    height: auto;
    display: block;
    object-fit: cover;
    max-height: 320px;
    transition: transform 0.5s ease;
}
.ctx-inline-illustration:hover .ctx-inline-img-wrap img {
    transform: scale(1.03);
}
.ctx-inline-gradient {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 70px;
    background: linear-gradient(to top, rgba(0,0,0,0.55), transparent);
    pointer-events: none;
}
.ctx-inline-caption {
    padding: 10px 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.ctx-inline-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary, #1a1a2e);
}
.ctx-inline-artist {
    font-size: 0.78rem;
    color: var(--text-muted, #888);
    font-style: italic;
}

/* Dark theme */
[data-theme="dark"] .ctx-inline-illustration {
    background: var(--card-bg, #1e1e2e);
    box-shadow: 0 4px 20px rgba(0,0,0,0.3), 0 1px 4px rgba(0,0,0,0.2);
}
[data-theme="dark"] .ctx-inline-title {
    color: var(--text-primary, #e0e0e0);
}
[data-theme="dark"] .ctx-inline-artist {
    color: var(--text-muted, #999);
}

/* Mobile adjustments */
@media (max-width: 768px) {
    .ctx-inline-illustration {
        margin: 16px -4px;
        border-radius: 12px;
    }
    .ctx-inline-img-wrap {
        max-height: 240px;
    }
    .ctx-inline-img-wrap img {
        max-height: 240px;
    }
    .ctx-inline-caption {
        flex-direction: column;
        align-items: flex-start;
        gap: 2px;
        padding: 8px 12px;
    }
}

/* ============ PRINT ============ */
@media print {
    .ctx-panel { display: none !important; }
    .btt-btn { display: none !important; }
    .ctx-inline-illustration { display: none !important; }
}
