/* ==========================================================================
   Scrollytelling Styles - Media Bias Visualization
   ========================================================================== */

/* ==========================================================================
   Scrollytelling Container
   ========================================================================== */

.scrollytelling {
    position: relative;
    min-height: 100vh;
    display: flex;
}

/* ==========================================================================
   Chapter Theme System - Visual Story Navigation
   ========================================================================== */

/* Chapter Theme Variables */
:root {
    /* Chapter 1: Global Overview - Deep Navy (World perspective) */
    --chapter-global-primary: #1e3a5f;
    --chapter-global-secondary: #3a6ea5;
    --chapter-global-accent: #60a5fa;
    --chapter-global-bg: linear-gradient(135deg, #0f172a 0%, #1e3a5f 50%, #1e40af 100%);
    --chapter-global-card-border: rgba(96, 165, 250, 0.3);

    /* Chapter 2: Regional Baselines - Slate Gray (Neutral overview) */
    --chapter-regional-primary: #475569;
    --chapter-regional-secondary: #64748b;
    --chapter-regional-accent: #94a3b8;
    --chapter-regional-bg: linear-gradient(135deg, #1e293b 0%, #334155 50%, #475569 100%);
    --chapter-regional-card-border: rgba(148, 163, 184, 0.3);

    /* Chapter 3: Africa Deep Dive - Warm Earth (African soil) */
    --chapter-africa-primary: #92400e;
    --chapter-africa-secondary: #b45309;
    --chapter-africa-accent: #f59e0b;
    --chapter-africa-bg: linear-gradient(135deg, #451a03 0%, #78350f 50%, #92400e 100%);
    --chapter-africa-card-border: rgba(245, 158, 11, 0.3);

    /* Chapter 4: Modern Contrast - Violet (Contemporary crisis) */
    --chapter-modern-primary: #6d28d9;
    --chapter-modern-secondary: #7c3aed;
    --chapter-modern-accent: #a78bfa;
    --chapter-modern-bg: linear-gradient(135deg, #2e1065 0%, #4c1d95 50%, #6d28d9 100%);
    --chapter-modern-card-border: rgba(167, 139, 250, 0.3);

    /* Chapter 5: Historical Parallel - Teal (Historical perspective) */
    --chapter-historical-primary: #0f766e;
    --chapter-historical-secondary: #0d9488;
    --chapter-historical-accent: #2dd4bf;
    --chapter-historical-bg: linear-gradient(135deg, #042f2e 0%, #115e59 50%, #0f766e 100%);
    --chapter-historical-card-border: rgba(45, 212, 191, 0.3);
}

/* Chapter Indicator Icons */
.chapter-indicator {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin-bottom: var(--space-md);
    padding: var(--space-xs) var(--space-md);
    background: rgba(255, 255, 255, 0.1);
    border-radius: var(--border-radius-xl);
    width: fit-content;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    transition: all var(--transition-base);
}

.chapter-indicator-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chapter-indicator-icon svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

/* Chapter-specific step content styling */
.scroll-step[data-chapter="global"] .step-content {
    border-left: 4px solid var(--chapter-global-accent);
}

.scroll-step[data-chapter="global"] .chapter-indicator {
    color: var(--chapter-global-accent);
    background: rgba(96, 165, 250, 0.15);
}

.scroll-step[data-chapter="global"] h3 {
    color: var(--chapter-global-secondary);
}

.scroll-step[data-chapter="regional"] .step-content {
    border-left: 4px solid var(--chapter-regional-accent);
}

.scroll-step[data-chapter="regional"] .chapter-indicator {
    color: var(--chapter-regional-accent);
    background: rgba(148, 163, 184, 0.15);
}

.scroll-step[data-chapter="regional"] h3 {
    color: var(--chapter-regional-secondary);
}

.scroll-step[data-chapter="africa"] .step-content {
    border-left: 4px solid var(--chapter-africa-accent);
}

.scroll-step[data-chapter="africa"] .chapter-indicator {
    color: var(--chapter-africa-accent);
    background: rgba(245, 158, 11, 0.15);
}

.scroll-step[data-chapter="africa"] h3 {
    color: var(--chapter-africa-secondary);
}

.scroll-step[data-chapter="modern"] .step-content {
    border-left: 4px solid var(--chapter-modern-accent);
}

.scroll-step[data-chapter="modern"] .chapter-indicator {
    color: var(--chapter-modern-accent);
    background: rgba(167, 139, 250, 0.15);
}

.scroll-step[data-chapter="modern"] h3 {
    color: var(--chapter-modern-secondary);
}

.scroll-step[data-chapter="historical"] .step-content {
    border-left: 4px solid var(--chapter-historical-accent);
}

.scroll-step[data-chapter="historical"] .chapter-indicator {
    color: var(--chapter-historical-accent);
    background: rgba(45, 212, 191, 0.15);
}

.scroll-step[data-chapter="historical"] h3 {
    color: var(--chapter-historical-secondary);
}

/* Sticky Visual Background Themes */
.sticky-visual {
    transition: background var(--transition-slow), box-shadow var(--transition-slow);
}

.sticky-visual[data-theme="global"] {
    background: var(--chapter-global-bg);
    box-shadow: inset 0 0 100px rgba(96, 165, 250, 0.1);
}

.sticky-visual[data-theme="regional"] {
    background: var(--chapter-regional-bg);
    box-shadow: inset 0 0 100px rgba(148, 163, 184, 0.1);
}

.sticky-visual[data-theme="africa"] {
    background: var(--chapter-africa-bg);
    box-shadow: inset 0 0 100px rgba(245, 158, 11, 0.1);
}

.sticky-visual[data-theme="modern"] {
    background: var(--chapter-modern-bg);
    box-shadow: inset 0 0 100px rgba(167, 139, 250, 0.1);
}

.sticky-visual[data-theme="historical"] {
    background: var(--chapter-historical-bg);
    box-shadow: inset 0 0 100px rgba(45, 212, 191, 0.1);
}

/* Active step glow effect matching chapter theme */
.scroll-step[data-chapter="global"].is-active .step-content {
    box-shadow: var(--shadow-lg), 0 0 30px rgba(96, 165, 250, 0.15);
}

.scroll-step[data-chapter="regional"].is-active .step-content {
    box-shadow: var(--shadow-lg), 0 0 30px rgba(148, 163, 184, 0.15);
}

.scroll-step[data-chapter="africa"].is-active .step-content {
    box-shadow: var(--shadow-lg), 0 0 30px rgba(245, 158, 11, 0.15);
}

.scroll-step[data-chapter="modern"].is-active .step-content {
    box-shadow: var(--shadow-lg), 0 0 30px rgba(167, 139, 250, 0.15);
}

.scroll-step[data-chapter="historical"].is-active .step-content {
    box-shadow: var(--shadow-lg), 0 0 30px rgba(45, 212, 191, 0.15);
}

/* ==========================================================================
   Sticky Visual Container
   ========================================================================== */

.sticky-container {
    flex: 1;
    position: relative;
    transition: background var(--transition-slow);
}

/* Dynamic background themes for sticky-container - fills entire left side */
.sticky-container[data-theme="global"] {
    background: var(--chapter-global-bg);
}

.sticky-container[data-theme="regional"] {
    background: var(--chapter-regional-bg);
}

.sticky-container[data-theme="africa"] {
    background: var(--chapter-africa-bg);
}

.sticky-container[data-theme="modern"] {
    background: var(--chapter-modern-bg);
}

.sticky-container[data-theme="historical"] {
    background: var(--chapter-historical-bg);
}

.sticky-visual {
    position: sticky;
    top: var(--header-height);
    height: calc(100vh - var(--header-height));
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-xl);
    background: var(--bg-secondary);
    overflow: hidden;
}

.sticky-visual .chart-wrapper {
    width: 100%;
    max-width: 900px;
    height: 90%;
    max-height: 600px;
    background: var(--bg-primary);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-lg);
    padding: var(--space-lg);
    position: relative;
}

.sticky-visual .chart-container {
    width: 100%;
    height: 100%;
}

/* ==========================================================================
   Scroll Steps (Text Content)
   ========================================================================== */

.scroll-sections {
    position: relative;
    z-index: 10;
    pointer-events: none;
    flex: 0 0 450px;
    max-width: 450px;
    transition: background var(--transition-slow);
}

/* Dynamic background themes for scroll-sections - matches sticky-visual */
.scroll-sections[data-theme="global"] {
    background: var(--chapter-global-bg);
}

.scroll-sections[data-theme="regional"] {
    background: var(--chapter-regional-bg);
}

.scroll-sections[data-theme="africa"] {
    background: var(--chapter-africa-bg);
}

.scroll-sections[data-theme="modern"] {
    background: var(--chapter-modern-bg);
}

.scroll-sections[data-theme="historical"] {
    background: var(--chapter-historical-bg);
}

.scroll-step {
    min-height: 100vh;
    display: flex;
    align-items: center;
    padding: var(--space-xxl) var(--container-padding);
}

.scroll-step:first-child {
    padding-top: calc(50vh + var(--header-height));
}

.scroll-step:last-child {
    padding-bottom: 50vh;
}

.step-content {
    width: 100%;
    max-width: 400px;
    margin: 0 auto;
    background: var(--bg-primary);
    padding: var(--space-xl);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-lg);
    pointer-events: auto;
    opacity: 0.3;
    transform: translateY(20px);
    transition: opacity var(--transition-base), transform var(--transition-base);
}

.scroll-step.is-active .step-content {
    opacity: 1;
    transform: translateY(0);
}

.step-number {
    display: inline-block;
    font-family: 'Roboto Slab', Georgia, serif;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--color-primary);
    letter-spacing: 0.1em;
    margin-bottom: var(--space-sm);
    padding: var(--space-xxs) var(--space-sm);
    background: rgba(207, 0, 99, 0.1);
    border-radius: var(--border-radius-sm);
}

.step-content h3 {
    font-family: 'Roboto Slab', Georgia, serif;
    font-size: 1.375rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--space-md);
    line-height: 1.3;
}

.step-content p {
    font-size: 0.9375rem;
    color: var(--text-secondary);
    margin-bottom: var(--space-md);
    line-height: 1.65;
}

.step-content p:last-child {
    margin-bottom: 0;
}

/* Interactive controls within steps */
.interactive-control {
    margin-top: var(--space-md);
    padding-top: var(--space-md);
    border-top: 1px solid var(--border-color);
}

.interactive-control label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: var(--space-xs);
}

.interactive-control select {
    padding: var(--space-xs) var(--space-sm);
    font-size: 0.875rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    background: var(--bg-primary);
}

.outlet-select {
    min-width: 140px;
}

/* ==========================================================================
   Chart Annotations (positioned over sticky visual)
   ========================================================================== */

.chart-annotations {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 5;
}

.annotation {
    position: absolute;
    max-width: 200px;
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-primary);
    border-radius: var(--border-radius-md);
    box-shadow: var(--shadow-md);
    font-size: 0.8125rem;
    color: var(--text-secondary);
    opacity: 0;
    transform: scale(0.9);
    transition: opacity var(--transition-base), transform var(--transition-base);
}

.annotation.is-visible {
    opacity: 1;
    transform: scale(1);
}

.annotation::before {
    content: '';
    position: absolute;
    width: 8px;
    height: 8px;
    background: var(--bg-primary);
    transform: rotate(45deg);
}

.annotation.arrow-left::before {
    left: -4px;
    top: 50%;
    margin-top: -4px;
    box-shadow: -2px 2px 3px rgba(0, 0, 0, 0.05);
}

.annotation.arrow-right::before {
    right: -4px;
    top: 50%;
    margin-top: -4px;
    box-shadow: 2px -2px 3px rgba(0, 0, 0, 0.05);
}

.annotation.arrow-top::before {
    top: -4px;
    left: 50%;
    margin-left: -4px;
    box-shadow: -2px -2px 3px rgba(0, 0, 0, 0.05);
}

.annotation.arrow-bottom::before {
    bottom: -4px;
    left: 50%;
    margin-left: -4px;
    box-shadow: 2px 2px 3px rgba(0, 0, 0, 0.05);
}

/* ==========================================================================
   Progress Indicator
   ========================================================================== */

.scroll-progress {
    position: fixed;
    top: var(--header-height);
    left: 0;
    width: 100%;
    height: 3px;
    background: var(--color-gray-200);
    z-index: var(--z-sticky);
}

.scroll-progress-bar {
    height: 100%;
    background: var(--color-primary);
    width: 0;
    transition: width 100ms linear;
}

/* Step indicators (dots) */
.step-indicators {
    position: fixed;
    right: var(--space-lg);
    top: 50%;
    transform: translateY(-50%);
    z-index: var(--z-sticky);
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.step-indicator {
    width: 20px;
    height: 4px;
    border-radius: 2px;
    background: var(--color-gray-300);
    border: none;
    box-shadow: none;
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
    opacity: 0.6;
}

/* Tooltip styles */
.step-tooltip {
    position: absolute;
    right: 32px;
    top: 50%;
    transform: translateY(-50%) translateX(10px);
    background: var(--bg-dark);
    color: var(--color-white);
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: all var(--transition-base);
    box-shadow: var(--shadow-md);
}

.step-tooltip::after {
    content: '';
    position: absolute;
    right: -4px;
    top: 50%;
    margin-top: -4px;
    border-width: 4px;
    border-style: solid;
    border-color: transparent transparent transparent var(--bg-dark);
}

.step-indicator:hover .step-tooltip {
    opacity: 1;
    visibility: visible;
    transform: translateY(-50%) translateX(0);
}

.step-indicator:hover {
    opacity: 1;
    background: var(--color-gray-500);
    width: 24px;
}

.step-indicator.is-active {
    background: var(--color-primary);
    width: 32px;
    opacity: 1;
    transform: none;
    /* Reset the scale transform from previous dot style */
}

.step-indicator.is-passed {
    background: var(--color-primary-light);
    opacity: 0.8;
}

/* ==========================================================================
   Chart Transitions
   ========================================================================== */

/* Fade transition */
.chart-transition-fade {
    opacity: 0;
    transition: opacity var(--transition-slow);
}

.chart-transition-fade.is-visible {
    opacity: 1;
}

/* Slide transitions */
.chart-transition-slide-left {
    opacity: 0;
    transform: translateX(-30px);
    transition: opacity var(--transition-base), transform var(--transition-base);
}

.chart-transition-slide-right {
    opacity: 0;
    transform: translateX(30px);
    transition: opacity var(--transition-base), transform var(--transition-base);
}

.chart-transition-slide-up {
    opacity: 0;
    transform: translateY(30px);
    transition: opacity var(--transition-base), transform var(--transition-base);
}

.chart-transition-slide-left.is-visible,
.chart-transition-slide-right.is-visible,
.chart-transition-slide-up.is-visible {
    opacity: 1;
    transform: translate(0, 0);
}

/* ==========================================================================
   Scroll-triggered Highlights
   ========================================================================== */

.highlight-pulse {
    animation: highlightPulse 1.5s ease-in-out;
}

@keyframes highlightPulse {

    0%,
    100% {
        filter: none;
    }

    50% {
        filter: drop-shadow(0 0 8px var(--color-primary));
    }
}

.highlight-glow {
    filter: drop-shadow(0 0 6px var(--color-primary));
}

/* ==========================================================================
   Narrative Elements
   ========================================================================== */

/* Quote/Callout in story */
.story-callout {
    position: relative;
    padding: var(--space-md) var(--space-lg);
    margin: var(--space-lg) 0;
    background: linear-gradient(135deg, rgba(207, 0, 99, 0.05) 0%, rgba(0, 51, 102, 0.05) 100%);
    border-radius: var(--border-radius-md);
    border-left: 3px solid var(--color-primary);
}

.story-callout p {
    font-style: italic;
    color: var(--text-primary);
    margin: 0;
}

/* Reveal animation for key numbers */
.reveal-number {
    display: inline-block;
    font-family: 'Roboto Slab', Georgia, serif;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-primary);
    opacity: 0;
    transform: translateY(10px);
    transition: opacity var(--transition-base), transform var(--transition-base);
}

.reveal-number.is-revealed {
    opacity: 1;
    transform: translateY(0);
}

/* Key insight marker */
.key-insight {
    position: relative;
    padding-left: var(--space-lg);
}

.key-insight::before {
    content: '💡';
    position: absolute;
    left: 0;
    top: 0;
}

/* ==========================================================================
   Mini Charts in Step Content
   ========================================================================== */

.step-mini-chart {
    width: 100%;
    height: 120px;
    margin: var(--space-md) 0;
    background: var(--bg-secondary);
    border-radius: var(--border-radius-md);
    overflow: hidden;
}

.step-mini-chart svg {
    width: 100%;
    height: 100%;
}

/* ==========================================================================
   Responsive Scrollytelling
   ========================================================================== */

@media (max-width: 1024px) {
    .scrollytelling {
        flex-direction: column;
    }

    .sticky-container {
        flex: none;
        position: sticky;
        top: var(--header-height);
        z-index: 1;
        /* Ensure click events pass through the container's empty areas if any */
        pointer-events: none;
    }

    .scroll-sections {
        flex: none;
        max-width: 100%;
        position: relative;
        z-index: 10;
        pointer-events: none;
        /* Allow clicks to pass through to chart */
        background: transparent !important;
        /* Ensure gaps are transparent */
    }

    .step-content {
        pointer-events: auto;
        /* Re-enable events on text cards */
    }

    .sticky-visual {
        pointer-events: auto;
        /* Re-enable events on the visual itself */
        height: 40vh;
        min-height: 250px;
        padding: var(--space-sm);
        /* Reduce padding to maximize chart space */
    }

    .scroll-step {
        min-height: 80vh;
        /* Ensure steps are tall enough to space out text */
        padding: 45vh var(--container-padding) var(--space-xl);
        /* Top padding clears the chart area */
        display: flex;
        align-items: flex-start;
        /* Align text to top of content area (just below chart space) */
    }

    .scroll-step:first-child {
        padding-top: 45vh;
    }

    .step-content {
        max-width: 100%;
        margin: 0 auto;
    }
}

@media (max-width: 768px) {
    .scrollytelling {
        display: block;
    }

    .sticky-visual {
        position: relative;
        top: 0;
        height: 60vh;
        min-height: 350px;
    }

    .sticky-visual .chart-wrapper {
        padding: var(--space-md);
    }

    .scroll-sections {
        position: relative;
    }

    .scroll-step {
        min-height: 80vh;
        padding: 50vh var(--container-padding) var(--space-lg);
    }

    .scroll-step:first-child {
        padding-top: 50vh;
    }

    .scroll-step:last-child {
        padding-bottom: var(--space-lg);
    }

    .step-content {
        opacity: 1;
        transform: none;
        box-shadow: none;
        border: 1px solid var(--border-color);
    }

    .step-indicators {
        display: none;
    }
}

/* ==========================================================================
   Alternative Layout: Side-by-side
   ========================================================================== */

.scrollytelling.layout-sidebyside .sticky-visual {
    width: 55%;
    margin-left: auto;
}

.scrollytelling.layout-sidebyside .scroll-sections {
    position: absolute;
    top: 0;
    left: 0;
    width: 40%;
}

.scrollytelling.layout-sidebyside .step-content {
    margin-left: 0;
    margin-right: auto;
    max-width: 100%;
}

@media (max-width: 1024px) {

    .scrollytelling.layout-sidebyside .sticky-visual,
    .scrollytelling.layout-sidebyside .scroll-sections {
        position: relative;
        width: 100%;
    }
}

/* ==========================================================================
   Debug Mode (development only)
   ========================================================================== */

.scrollytelling.debug .scroll-step {
    border: 2px dashed var(--color-warning);
}

.scrollytelling.debug .scroll-step.is-active {
    border-color: var(--color-positive);
}

.scrollytelling.debug .sticky-visual {
    border: 2px solid var(--color-info);
}