/* Ecosystem Hub Section */
.ecosystem-section {
    position: relative;
    padding: 150px 0;
    background-color: var(--bg-color);
    overflow: hidden;
    min-height: 800px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.ecosystem-container {
    position: relative;
    width: 1200px;
    /* Strict fixed width to ensure PC is EXACT expanded version of Mobile */
    max-width: none;
    /* Remove fluid constraint */
    height: 800px;
    margin: 0 auto;
}

/* SVG Connector Layer */
.ecosystem-connectors {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
}

.connector-path {
    fill: none;
    stroke: url(#connectorGradient);
    stroke-width: 1.5;
    stroke-linecap: round;
    opacity: 0.3;
    filter: drop-shadow(0 0 3px rgba(123, 63, 242, 0.3));
}

.pulse-path {
    fill: none;
    stroke: url(#connectorGradient);
    stroke-width: 3;
    stroke-linecap: round;
    opacity: 0;
    filter: drop-shadow(0 0 8px rgba(123, 63, 242, 0.8));
    pointer-events: none;
}

/* Trigger line drawing on scroll - transition handled in JS to avoid resets */
.animate-in .connector-path {
    stroke-dashoffset: 0 !important;
}

.animate-in .pulse-path {
    animation: energyPulse 4s ease-in-out infinite;
}

@keyframes energyPulse {
    0% {
        stroke-dashoffset: 100%;
        opacity: 0;
    }

    10% {
        opacity: 1;
    }

    40% {
        opacity: 1;
    }

    50% {
        stroke-dashoffset: 0%;
        opacity: 0;
    }

    100% {
        stroke-dashoffset: 0%;
        opacity: 0;
    }
}

/* Central Character Node */
.ecosystem-center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 300px;
    height: 300px;
    z-index: 10;
    display: flex;
    justify-content: center;
    align-items: center;
}

.center-image {
    width: 100%;
    height: auto;
    filter: drop-shadow(0 0 30px rgba(123, 63, 242, 0.4));
    /* Initial state: Hidden until scroll */
    opacity: 0;
    transform: scale(0.5);
}

/* Trigger center reveal on scroll */
.animate-in .center-image {
    animation: revealCenter 0.8s cubic-bezier(0.34, 1.56, 0.64, 1) forwards,
        floatCenter 6s ease-in-out 0.8s infinite;
}

@keyframes revealCenter {
    0% {
        opacity: 0;
        transform: scale(0.5);
    }

    100% {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes floatCenter {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-15px);
    }
}

/* Satellite Nodes (Floating Cards) */
.ecosystem-node {
    position: absolute;
    width: 220px;
    padding: 15px;
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    z-index: 5;
    display: flex;
    align-items: center;
    gap: 12px;
    color: #fff;
    cursor: pointer;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    overflow: hidden;
    z-index: 1;

    /* Initial state: Hidden until scroll */
    opacity: 0;
}

/* Specific Node Positions */
.node-top {
    top: 3%;
    left: 50%;
    transform: translateX(-50%);
}

.node-top-right {
    top: 18%;
    right: 8%;
}

.node-right {
    top: 50%;
    right: 3%;
    transform: translateY(-50%);
}

.node-bottom-right {
    bottom: 18%;
    right: 8%;
}

.node-bottom-left {
    bottom: 18%;
    left: 8%;
}

.node-left {
    top: 50%;
    left: 3%;
    transform: translateY(-50%);
}

.node-top-left {
    top: 18%;
    left: 8%;
}

/* Delays (if needed as classes) */
.delay-0 {
    --delay: 0s;
}

.delay-0-5 {
    --delay: 0.5s;
}

.delay-1 {
    --delay: 1s;
}

.delay-1-5 {
    --delay: 1.5s;
}

.delay-2 {
    --delay: 2s;
}

.delay-2-5 {
    --delay: 2.5s;
}

.delay-3 {
    --delay: 3s;
}

/* Trigger node fade-in on scroll (Accelerated Cohesive Entrance) */
.animate-in .ecosystem-node {
    animation: fadeInNode 0.5s ease-out forwards, floatNode 8s ease-in-out 0.5s infinite;
}

/* Staggered slightly but very fast (0.05s increments) */
.animate-in .ecosystem-node:nth-child(3) {
    animation-delay: 0.1s;
}

.animate-in .ecosystem-node:nth-child(4) {
    animation-delay: 0.15s;
}

.animate-in .ecosystem-node:nth-child(5) {
    animation-delay: 0.2s;
}

.animate-in .ecosystem-node:nth-child(6) {
    animation-delay: 0.25s;
}

.animate-in .ecosystem-node:nth-child(7) {
    animation-delay: 0.3s;
}

.animate-in .ecosystem-node:nth-child(8) {
    animation-delay: 0.35s;
}

.animate-in .ecosystem-node:nth-child(9) {
    animation-delay: 0.4s;
}

@keyframes fadeInNode {
    0% {
        opacity: 0;
        transform: translateY(20px);
    }

    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

/* 1. The Spinning Gradient (The Border) */
.ecosystem-node::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 200%;
    height: 200%;
    transform: translate(-50%, -50%);
    background: conic-gradient(from 0deg,
            transparent 0%,
            #7B3FF2 10%,
            transparent 20%,
            transparent 50%,
            #4285F4 60%,
            transparent 70%,
            transparent 100%);
    animation: rotateBorder 4s linear infinite;
    z-index: -2;
}

@keyframes rotateBorder {
    from {
        transform: translate(-50%, -50%) rotate(0deg);
    }

    to {
        transform: translate(-50%, -50%) rotate(360deg);
    }
}

/* 2. The Inner Background (The Card Body) */
.ecosystem-node::after {
    content: "";
    position: absolute;
    inset: 1.5px;
    background: rgba(20, 20, 30, 0.85);
    border-radius: 15px;
    z-index: -1;
    backdrop-filter: blur(12px);
}

.ecosystem-node:hover {
    transform: translateY(-5px) scale(1.05);
    box-shadow: 0 15px 40px rgba(123, 63, 242, 0.3);
}

/* Intensify glow on hover */
.ecosystem-node:hover::before {
    background: conic-gradient(from 0deg,
            transparent 0%,
            #a855f7 10%,
            transparent 20%,
            transparent 50%,
            #60a5fa 60%,
            transparent 70%,
            transparent 100%);
    filter: brightness(1.5);
}

.node-icon-img {
    width: 48px;
    height: 48px;
    object-fit: contain;
    border-radius: 8px;
    filter: drop-shadow(0 2px 5px rgba(0, 0, 0, 0.3));
    transition: transform 0.3s ease;
}

.ecosystem-node:hover .node-icon-img {
    transform: rotate(5deg) scale(1.1);
}

.node-content {
    display: flex;
    flex-direction: column;
}

.node-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: #fff;
    margin-bottom: 2px;
}

.node-subtitle {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.6);
}

@keyframes floatNode {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-8px);
    }
}

/* =========================================
   Light Mode Optimizations
   ========================================= */
[data-theme="light"] .ecosystem-section {
    background-color: #f8f9fa;
}

[data-theme="light"] .ecosystem-node {
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.05);
    color: #1a1a1a;
}

/* Light Mode Card Body Color */
[data-theme="light"] .ecosystem-node::after {
    background: rgba(255, 255, 255, 0.9);
}

[data-theme="light"] .ecosystem-node:hover {
    box-shadow: 0 15px 40px rgba(123, 63, 242, 0.15);
}

[data-theme="light"] .node-title {
    color: #000;
}

[data-theme="light"] .node-subtitle {
    color: #555;
}

[data-theme="light"] .node-icon-img {
    background: rgba(0, 0, 0, 0.03);
    padding: 2px;
}

[data-theme="light"] .connector-path {
    opacity: 1;
    filter: none;
    stroke: url(#connectorGradientLight) !important;
    stroke-width: 2.5px;
}

/* =========================================
   Accessibility: Reduced Motion
   ========================================= */
@media (prefers-reduced-motion: reduce) {

    .center-image,
    .connector-path,
    .ecosystem-node {
        animation: none !important;
        transition: none !important;
        opacity: 1 !important;
        transform: none !important;
    }

    .animate-in .center-image,
    .animate-in .ecosystem-node {
        opacity: 1 !important;
    }
}

/* Connection Points (Invisible anchors for JS) */
.connection-point-center {
    position: absolute;
    top: 20%;
    left: 50%;
    width: 1px;
    height: 1px;
    visibility: hidden;
}

/* Mobile Responsiveness - Exact Mini-PC Experience */
/* Mobile Miniature Logic for Satellite Nodes */
@media (max-width: 991px) {
    .ecosystem-section {
        min-height: 400px;
        /* Matches the scaled height */
        padding: 50px 0;
        overflow: hidden;
        display: block;
        /* Remove flex layout to stop interference */
    }

    /* Wrapper handles the width of the screen and centering */
    .desktop-scaler {
        width: 100vw;
        height: 320px;
        /* 800px * 0.31 + padding */
        overflow: hidden;
        display: flex;
        justify-content: center;
        /* Center the 1200px element horizontally */
    }

    /* 
       THE MAGIC: Force the container to BE wide (desktop size), 
       then scale it down relative to its own top center.
    */
    .ecosystem-container {
        width: 1200px !important;
        /* Strict Desktop Width */
        max-width: 1200px !important;
        height: 800px !important;
        /* Strict Desktop Height */

        transform: scale(0.31);
        /* Scale to fit ~375px screens */
        transform-origin: top center;
        /* Scale from the top-center point */

        margin: 0;
        /* Remove auto margins, let flex parent center it */
        flex-shrink: 0;
    }

    /* Persist desktop styles */
    .node-subtitle {
        display: block !important;
    }

    .ecosystem-node {
        position: absolute !important;
    }
}