/**
 * HERITAGE SECTION - REFACTORED RESPONSIVE SCROLLYTELLING
 *
 * Behavior:
 * ≥ 1280px: Sticky scrollytelling with fade transitions (Desktop/Ultrawide)
 * < 1280px: Linear stacked sections (Mobile/Tablet/Small Laptops)
 *
 * This file provides complete responsive overrides for the heritage section
 */

/* ===== MOBILE & TABLET: LINEAR STACKED LAYOUT (< 1280px) ===== */

@media (max-width: 1279px) {
    /* RESET: Remove all sticky scroll behavior */
    .heritage {
        height: auto !important;
        min-height: 0 !important;
        padding: 0 !important;
        position: relative !important;
        overflow: visible !important;
        background: linear-gradient(135deg, #1a0a0a 0%, #0f172a 50%, #1a0a0a 100%) !important;
    }

    /* Remove sticky container */
    .heritage-scroll-container {
        position: static !important;
        height: auto !important;
        overflow: visible !important;
        display: block !important;
        padding: 0 !important;
    }

    .heritage-sticky-area {
        position: static !important;
        height: auto !important;
        display: block !important;
    }

    /* Hide all desktop-only UI elements */
    .heritage-progress,
    .heritage-scroll-progress,
    .heritage-scroll-mouse,
    .parallax-layer,
    .heritage-bg-layer,
    .gradient-overlay {
        display: none !important;
    }

    /* Content wrapper becomes simple block container */
    .heritage-content-wrapper {
        position: static !important;
        height: auto !important;
        display: block !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: visible !important;
    }

    /* STAGES: Convert from absolute overlay to linear stacked sections */
    .heritage-stage {
        /* Reset all absolute positioning */
        position: relative !important;
        top: auto !important;
        left: auto !important;
        right: auto !important;
        bottom: auto !important;

        /* Make fully visible */
        opacity: 1 !important;
        visibility: visible !important;
        transform: none !important;

        /* Block-level stacking */
        display: block !important;
        width: 100% !important;
        height: auto !important;
        min-height: 0 !important;
        max-height: none !important;

        /* Each stage is a distinct section */
        padding: clamp(3rem, 8vw, 5rem) clamp(1rem, 4vw, 2rem) !important;
        margin-bottom: clamp(3rem, 6vw, 4rem) !important;

        /* Ensure no overlap */
        overflow: visible !important;
        pointer-events: auto !important;
        z-index: auto !important;

        /* Visual styling for each stage as separate section */
        background: rgba(0, 0, 0, 0.4) !important;
        border-bottom: 1px solid rgba(251, 191, 36, 0.2) !important;
        border-radius: 0 !important;
    }

    /* Remove active class effects on mobile */
    .heritage-stage.active,
    .heritage-stage:not(.active) {
        position: relative !important;
        opacity: 1 !important;
        transform: none !important;
    }

    /* Stage content layout - vertical stacking */
    .stage-content-grid {
        display: flex !important;
        flex-direction: column !important;
        gap: clamp(1.5rem, 4vw, 2.5rem) !important;
        padding: 0 !important;
        max-width: 900px !important;
        margin: 0 auto !important;
        width: 100% !important;
    }

    .stage-content-body {
        display: flex !important;
        flex-direction: column !important;
        gap: clamp(1.5rem, 4vw, 2.5rem) !important;
        width: 100% !important;
        max-height: none !important;
        overflow: visible !important;
        grid-template-columns: 1fr !important;
    }

    /* FLUID TYPOGRAPHY using clamp() */
    .stage-title {
        font-size: clamp(1.75rem, 5vw, 2.5rem) !important;
        line-height: 1.2 !important;
        text-align: center !important;
        margin: 0 0 clamp(1rem, 3vw, 1.5rem) 0 !important;
        padding: 0 !important;
        color: #ffffff !important;
        opacity: 1 !important;
        transform: none !important;
    }

    .section-label {
        display: inline-block !important;
        padding: clamp(0.5rem, 2vw, 0.75rem) clamp(1rem, 3vw, 1.5rem) !important;
        font-size: clamp(0.75rem, 2vw, 0.875rem) !important;
        font-weight: 600 !important;
        text-transform: uppercase !important;
        letter-spacing: 0.1em !important;
        color: #fb923c !important;
        background: rgba(251, 146, 60, 0.2) !important;
        border-radius: 50px !important;
        margin-bottom: clamp(0.75rem, 2vw, 1rem) !important;
        opacity: 1 !important;
        transform: none !important;
    }

    .stage-description {
        font-size: clamp(0.9375rem, 2.5vw, 1.125rem) !important;
        line-height: clamp(1.6, 1.5 + 0.5vw, 1.75) !important;
        color: rgba(255, 255, 255, 0.9) !important;
        opacity: 1 !important;
        transform: none !important;
    }

    .stage-description p {
        margin-bottom: clamp(1rem, 3vw, 1.5rem) !important;
        opacity: 1 !important;
        transform: none !important;
    }

    /* Text content - always visible on mobile */
    .stage-text {
        order: 2 !important;
        width: 100% !important;
        padding: 0 !important;
        opacity: 1 !important;
        transform: none !important;
    }

    /* Visual content - images above text */
    .stage-visual {
        order: 1 !important;
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 auto clamp(1.5rem, 4vw, 2rem) auto !important;
    }

    /* Heritage images */
    .heritage-images,
    .heritage-image-container {
        width: 100% !important;
        max-width: 600px !important;
        margin: 0 auto !important;
    }

    .heritage-image-wrapper {
        width: 100% !important;
        aspect-ratio: 16 / 10 !important;
        border-radius: clamp(0.5rem, 2vw, 1rem) !important;
        overflow: hidden !important;
    }

    .heritage-image,
    .heritage-image-old {
        width: 100% !important;
        height: 100% !important;
        object-fit: cover !important;
    }

    /* Founder portrait */
    .founder-visual {
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
    }

    .portrait-card {
        width: 100% !important;
        max-width: 400px !important;
        padding: 0 !important;
        margin: 0 auto !important;
    }

    .founder-img {
        width: 100% !important;
        height: auto !important;
        border-radius: clamp(0.5rem, 2vw, 1rem) !important;
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5) !important;
    }

    /* Founder text */
    .founder-name {
        font-size: clamp(1.25rem, 4vw, 1.75rem) !important;
        font-weight: 700 !important;
        color: #ffffff !important;
        margin-bottom: clamp(0.5rem, 2vw, 0.75rem) !important;
    }

    .founder-subtitle {
        font-size: clamp(1rem, 3vw, 1.25rem) !important;
        font-weight: 500 !important;
        color: #fb923c !important;
        margin-bottom: clamp(1.5rem, 4vw, 2rem) !important;
    }

    .founder-quote {
        border-left: 4px solid #fb923c !important;
        padding-left: clamp(1rem, 3vw, 1.5rem) !important;
        margin: clamp(1.5rem, 4vw, 2rem) 0 !important;
        font-style: italic !important;
        font-size: clamp(1rem, 3vw, 1.25rem) !important;
        color: rgba(255, 255, 255, 0.9) !important;
    }

    /* Poem section */
    .poem-image-container {
        width: 100% !important;
        max-width: 500px !important;
        margin: 0 auto !important;
    }

    .poem-img {
        width: 100% !important;
        height: auto !important;
        border-radius: clamp(0.5rem, 2vw, 1rem) !important;
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5) !important;
    }
}

/* ===== LANDSCAPE MOBILE OPTIMIZATION ===== */
@media (max-width: 1279px) and (max-height: 768px) and (orientation: landscape) {
    .heritage-stage {
        padding: clamp(2rem, 5vw, 3rem) clamp(1rem, 3vw, 1.5rem) !important;
        margin-bottom: clamp(2rem, 4vw, 3rem) !important;
    }

    .stage-content-body {
        gap: clamp(1rem, 3vw, 1.5rem) !important;
    }

    .stage-title {
        font-size: clamp(1.5rem, 4vw, 2rem) !important;
    }
}

/* ===== DESKTOP & ULTRAWIDE: STICKY SCROLLYTELLING (≥ 1280px) ===== */

@media (min-width: 1280px) {
    /* Enable sticky scroll behavior */
    .heritage {
        height: 300vh;
        position: relative;
        overflow: visible;
        background: linear-gradient(135deg, #1a0a0a 0%, #0f172a 50%, #1a0a0a 100%);
        padding: 0;
        margin: 0;
    }

    .heritage-scroll-container {
        position: sticky;
        top: 10px;
        height: calc(100vh - 10px);
        overflow: hidden;
        display: flex;
        align-items: center;
        justify-content: center;
        width: 100%;
        z-index: 1;
    }

    /* Content wrapper with max-width for ultrawide */
    .heritage-content-wrapper {
        position: relative;
        width: 100%;
        height: 100%;
        max-width: clamp(1200px, 90vw, 2000px);
        margin: 0 auto;
        padding: 0 clamp(2rem, 4vw, 4rem);
        z-index: 2;
    }

    /* Stages overlaid with absolute positioning */
    .heritage-stage {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        display: flex;
        align-items: flex-start;
        justify-content: center;
        padding-top: clamp(4.625rem, 8vh + 10px, 6.625rem);
        opacity: 0;
        pointer-events: none;
        transition: opacity 1.2s ease-in-out;
    }

    .heritage-stage.active {
        opacity: 1;
        pointer-events: auto;
    }

    /* Stage content layout - side by side */
    .stage-content-grid {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: flex-start;
        max-width: 100%;
        width: 100%;
        padding: 0 clamp(1.5rem, 3vw, 3rem);
        gap: clamp(0.5rem, 1vw, 1rem);
    }

    .stage-content-body {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: clamp(2rem, 5vw, 6rem);
        align-items: center;
        width: 100%;
        max-height: calc(100vh - 60px - 8rem);
        overflow: visible;
    }

    /* FLUID TYPOGRAPHY for desktop */
    .stage-title {
        font-size: clamp(2rem, 3vw, 3.5rem);
        line-height: 1.1;
        text-align: center;
        margin: 0 0 clamp(1rem, 2vw, 2rem) 0;
        color: #ffffff;
        width: 100%;
    }

    .section-label {
        display: inline-block;
        padding: clamp(0.5rem, 1vw, 0.75rem) clamp(1rem, 2vw, 1.5rem);
        font-size: clamp(0.75rem, 1vw, 0.875rem);
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.15em;
        color: #fb923c;
        background: rgba(251, 146, 60, 0.2);
        border-radius: 50px;
        margin-bottom: clamp(0.75rem, 1.5vw, 1.25rem);
    }

    .stage-description {
        font-size: clamp(1rem, 1.25vw, 1.25rem);
        line-height: clamp(1.6, 1.5 + 0.5vw, 1.8);
        color: rgba(255, 255, 255, 0.9);
    }

    .stage-description p {
        margin-bottom: clamp(1rem, 2vw, 1.5rem);
    }

    /* Founder text on desktop */
    .founder-name {
        font-size: clamp(1.5rem, 2vw, 2rem);
        font-weight: 700;
        color: #ffffff;
        margin-bottom: clamp(0.5rem, 1vw, 0.75rem);
    }

    .founder-subtitle {
        font-size: clamp(1.125rem, 1.5vw, 1.5rem);
        font-weight: 500;
        color: #fb923c;
        margin-bottom: clamp(1.5rem, 2vw, 2rem);
    }

    .founder-quote {
        border-left: 4px solid #fb923c;
        padding-left: clamp(1rem, 2vw, 2rem);
        margin: clamp(1.5rem, 2vw, 2rem) 0;
        font-style: italic;
        font-size: clamp(1.125rem, 1.5vw, 1.5rem);
        color: rgba(255, 255, 255, 0.95);
    }

    /* Progress indicators visible on desktop */
    .heritage-progress {
        position: fixed;
        right: 3%;
        top: 50%;
        transform: translateY(-50%);
        display: flex;
        flex-direction: column;
        gap: clamp(1rem, 2vw, 1.5rem);
        z-index: 1000;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
    }

    .progress-dot {
        width: clamp(10px, 1vw, 12px);
        height: clamp(10px, 1vw, 12px);
        border-radius: 50%;
        background: rgba(255, 255, 255, 0.3);
        transition: all 0.3s ease;
        cursor: pointer;
    }

    .progress-dot.active {
        background: #fb923c;
        transform: scale(1.5);
        box-shadow: 0 0 20px rgba(251, 146, 60, 0.8);
    }

    .progress-dot:hover {
        background: rgba(251, 146, 60, 0.6);
        transform: scale(1.2);
    }

    /* Progress bar visible on desktop */
    .heritage-scroll-progress {
        position: fixed;
        top: 60px;
        left: 0;
        width: 100%;
        height: 8px;
        background: rgba(0, 0, 0, 0.6);
        z-index: 1000;
        opacity: 0;
        transition: opacity 0.3s ease;
    }

    .heritage-scroll-progress-bar {
        height: 100%;
        background: linear-gradient(90deg, #fbbf24 0%, #f59e0b 50%, #fbbf24 100%);
        width: 0%;
        transition: width 0.1s linear;
    }
}

/* ===== ULTRAWIDE OPTIMIZATION (≥ 1920px & 21:9) ===== */

@media (min-width: 1920px) and (min-aspect-ratio: 21/9) {
    .heritage-content-wrapper {
        max-width: 2000px;
        padding: 0 clamp(3rem, 5vw, 6rem);
    }

    .stage-content-body {
        gap: clamp(4rem, 6vw, 8rem);
    }

    .stage-title {
        font-size: clamp(2.5rem, 3.5vw, 4rem);
        letter-spacing: 0.02em;
    }

    .stage-description {
        font-size: clamp(1.125rem, 1.5vw, 1.5rem);
        line-height: 1.8;
    }

    .heritage-stage {
        padding: clamp(2rem, 4vw, 4rem);
    }
}

/* ===== 4K MONITORS (≥ 2560px) ===== */

@media (min-width: 2560px) {
    .heritage-content-wrapper {
        max-width: 2400px;
    }

    .stage-title {
        font-size: clamp(3rem, 4vw, 5rem);
    }

    .stage-description {
        font-size: clamp(1.25rem, 1.75vw, 1.75rem);
    }

    .progress-dot {
        width: 16px;
        height: 16px;
    }

    .progress-dot.active {
        transform: scale(1.75);
    }
}

/* ===== ACCESSIBILITY ===== */

@media (prefers-reduced-motion: reduce) {
    .heritage-stage,
    .progress-dot,
    * {
        transition: none !important;
        animation: none !important;
    }
}

@media (prefers-contrast: high) {
    .heritage-stage {
        border: 2px solid #ffffff;
    }

    .stage-title {
        text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.9);
    }
}
