/* =============================================
   DIAGRAMS MODULE
   Isometric 3D layer diagrams for blog content
   Animated SVG with hover interactions
   ============================================= */

/* --- Container --- */
.diagram-wrap {
    position: relative;
    width: 100%;
    max-width: 480px;
    margin: 32px auto;
    padding: 24px 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-lg);
    background:
        radial-gradient(ellipse at 50% 40%, rgba(180, 205, 255, 0.06), transparent 70%),
        rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.06);
    overflow: visible;
    user-select: none;
}

.diagram-wrap::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: radial-gradient(circle at 50% 0%, rgba(180, 205, 255, 0.04), transparent 60%);
    pointer-events: none;
}

/* --- Caption --- */
.diagram-caption {
    text-align: center;
    font-size: 12px;
    color: var(--font-mono);
    margin-top: 8px;
    letter-spacing: 0.3px;
    opacity: 0.7;
    transition: opacity 0.4s ease;
}

.diagram-wrap:hover + .diagram-caption,
.diagram-wrap:hover ~ .diagram-caption {
    opacity: 1;
}

/* --- SVG Layers --- */
.layers-svg {
    width: 100%;
    max-width: 420px;
    overflow: visible;
    cursor: default;
}

.layers-svg g.layer {
    transform:
        translateX(var(--offset-x, 0px))
        translateY(var(--offset-y, 0px));
    transition: transform 0.45s cubic-bezier(0.16, 1, 0.3, 1),
                filter 0.45s cubic-bezier(0.16, 1, 0.3, 1);
    animation: layerFloat 3s ease-in-out infinite;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.15));
}

.layers-svg g.layer:nth-of-type(2) { animation-delay: 0.25s; }
.layers-svg g.layer:nth-of-type(3) { animation-delay: 0.5s; }
.layers-svg g.layer:nth-of-type(4) { animation-delay: 0.75s; }
.layers-svg g.layer:nth-of-type(5) { animation-delay: 1.0s; }
.layers-svg g.layer:nth-of-type(6) { animation-delay: 1.25s; }
.layers-svg g.layer:nth-of-type(7) { animation-delay: 1.5s; }

@keyframes layerFloat {
    0%, 100% {
        transform:
            translateX(var(--offset-x, 0px))
            translateY(var(--offset-y, 0px));
    }
    50% {
        transform:
            translateX(var(--offset-x, 0px))
            translateY(calc(var(--offset-y, 0px) + 2.5px));
    }
}

/* Hover: lift the hovered layer */
.layers-svg g.layer:hover {
    transform:
        translateX(var(--offset-x, 0px))
        translateY(calc(var(--offset-y, 0px) - 4px));
    filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.3))
            brightness(1.15);
    animation-play-state: paused;
}

/* Layer label text */
.layers-svg text {
    font-family: var(--font-system);
    font-weight: bold;
    fill: rgba(255, 255, 255, 0.85);
    pointer-events: none;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
    transform: skew(-68deg, 22deg)
               translate(calc(49px * var(--size, 100) / 100), calc(7px * var(--size, 100) / 100))
               scaleY(0.5);
}

/* Side faces */
.layers-svg .face-left {
    fill: rgba(0, 0, 0, 0.25);
}

.layers-svg .face-right {
    fill: rgba(255, 255, 255, 0.15);
}

/* --- Connection lines between layers --- */
.diagram-connection {
    stroke: rgba(180, 205, 255, 0.25);
    stroke-width: 0.5;
    stroke-dasharray: 3 3;
    fill: none;
    animation: connectionPulse 2s ease-in-out infinite;
}

@keyframes connectionPulse {
    0%, 100% { stroke-opacity: 0.2; }
    50% { stroke-opacity: 0.6; }
}

/* --- Data flow particles --- */
.flow-particle {
    fill: var(--accent-blue);
    opacity: 0;
    animation: flowMove 2.5s ease-in-out infinite;
}

.flow-particle:nth-child(2) { animation-delay: 0.8s; }
.flow-particle:nth-child(3) { animation-delay: 1.6s; }

@keyframes flowMove {
    0% {
        opacity: 0;
        offset-distance: 0%;
    }
    10% { opacity: 0.8; }
    90% { opacity: 0.8; }
    100% {
        opacity: 0;
        offset-distance: 100%;
    }
}

/* --- Tooltip on hover --- */
.layer-tooltip {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%) translateY(4px);
    background: rgba(10, 10, 20, 0.92);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    padding: 8px 14px;
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    backdrop-filter: blur(12px);
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 10;
}

.diagram-wrap:hover .layer-tooltip {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* --- Diagram variations --- */

/* Mother Core diagram - larger, centered emphasis */
.diagram-wrap--mother-core .layers-svg {
    max-width: 460px;
}

/* Signal arrows */
.signal-arrow {
    stroke: rgba(180, 205, 255, 0.4);
    stroke-width: 0.8;
    fill: none;
    marker-end: url(#arrowhead);
    opacity: 0;
    animation: signalPulse 3s ease-in-out infinite;
}

.signal-arrow:nth-child(odd) { animation-delay: 0.5s; }
.signal-arrow:nth-child(even) { animation-delay: 1.5s; }

@keyframes signalPulse {
    0%, 100% { opacity: 0; stroke-dashoffset: 20; }
    30% { opacity: 0.7; }
    70% { opacity: 0.7; }
    100% { opacity: 0; stroke-dashoffset: 0; }
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .diagram-wrap {
        max-width: 100%;
        padding: 16px 0;
    }

    .layers-svg {
        max-width: 320px;
    }
}

/* --- Interactive highlight when blog content references diagram --- */
.diagram-wrap[data-active="true"] {
    border-color: rgba(180, 205, 255, 0.15);
    background: rgba(180, 205, 255, 0.04);
}

.diagram-wrap[data-active="true"] .layers-svg g.layer {
    filter: drop-shadow(0 4px 8px rgba(49, 83, 171, 0.2));
}
