/**
 * Frontend Diagram Styles
 * Arkylink Neural Diagrams
 */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

.and-diagram-wrapper {
    position: relative;
    width: 100%;
    min-height: 600px;
    background: #000;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ========== DESKTOP VIEW ========== */
.and-desktop-view {
    position: relative;
    width: 100%;
    height: 100%;
    min-height: 600px;
}

.and-diagram-canvas {
    position: relative;
    width: 100%;
    height: 100%;
    cursor: grab;
    touch-action: none;
    transition: transform 0.3s ease-out;
}

.and-diagram-canvas.and-grabbing {
    cursor: grabbing;
}

.and-diagram-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

.and-nodes-container {
    position: relative;
    width: 100%;
    height: 100%;
    z-index: 2;
}

/* Node Styles */
.and-node {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    background: white;
    color: #000;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid #fff;
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.7);
    font-weight: bold;
    text-transform: uppercase;
    word-wrap: break-word;
    line-height: 1.2;
    user-select: none;
    overflow: hidden;
    padding: 10px;
    transition: all 0.4s ease;
    animation: and-float 6s ease-in-out infinite;
    opacity: 0;
    transform: scale(0.8);
}

.and-node.and-visible {
    opacity: 1;
    transform: scale(1);
}

.and-node.and-active {
    animation: and-glow 2s infinite ease-in-out;
}

.and-node:hover {
    transform: scale(1.05);
    box-shadow: 0 0 25px rgba(255, 255, 255, 0.9);
}

/* Decorative nodes */
.and-decorative-node {
    position: absolute;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    box-shadow: 0 0 4px rgba(255, 255, 255, 0.2);
    width: 25px;
    height: 25px;
    animation: and-float 6s ease-in-out infinite;
    pointer-events: none;
}

/* Info button */
.and-info-btn {
    position: absolute;
    background: white;
    border-radius: 50%;
    font-weight: bold;
    color: #000;
    text-align: center;
    cursor: pointer;
    box-shadow: 0 0 8px rgba(255, 255, 255, 0.5);
    z-index: 3;
    user-select: none;
    width: 20px;
    height: 20px;
    font-size: 11px;
    line-height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    opacity: 0;
}

.and-info-btn.and-visible {
    opacity: 1;
}

.and-info-btn:hover {
    transform: scale(1.2);
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.8);
}

/* Font sizes for different node sizes */
.and-node-xs { font-size: 9px; }
.and-node-sm { font-size: 10px; }
.and-node-md { font-size: 11px; }
.and-node-lg { font-size: 12px; }
.and-node-xl { font-size: 13px; }

/* Animations */
@keyframes and-float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

@keyframes and-glow {
    0% { box-shadow: 0 0 8px 2px rgba(255, 0, 255, 0.4), 0 0 16px 4px rgba(0, 255, 255, 0.4); }
    50% { box-shadow: 0 0 8px 2px rgba(0, 255, 127, 0.5), 0 0 16px 4px rgba(0, 0, 255, 0.4); }
    100% { box-shadow: 0 0 8px 2px rgba(255, 0, 255, 0.4), 0 0 16px 4px rgba(0, 255, 255, 0.4); }
}

/* SVG Lines */
.and-connection-line {
    stroke: rgba(255, 255, 255, 0.3);
    stroke-width: 1.5;
    fill: none;
    opacity: 0;
    transition: opacity 0.4s ease;
}

.and-connection-line.and-visible {
    opacity: 1;
}

/* ========== MOBILE VIEW ========== */
.and-mobile-view {
    display: none;
    width: 100%;
    min-height: 100vh;
    background: #000;
    padding: 20px 0;
    overflow-x: hidden;
}

.and-mobile-container {
    max-width: 100%;
    padding: 0 20px;
}

/* Mobile root node */
.and-mobile-root {
    margin: 20px auto 40px;
    width: 250px;
    min-height: 100px;
    background: white;
    border-radius: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    font-weight: bold;
    text-transform: uppercase;
    color: #000;
    font-size: 16px;
    padding: 20px;
    box-shadow: 0 0 30px rgba(255, 255, 255, 0.8);
    animation: and-float 6s ease-in-out infinite;
    line-height: 1.3;
}

/* Mobile node group */
.and-mobile-node-group {
    margin-bottom: 40px;
}

/* Mobile node */
.and-mobile-node {
    position: relative;
    margin: 0 auto 20px;
    width: 200px;
    min-height: 80px;
    background: white;
    border-radius: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    font-weight: bold;
    text-transform: uppercase;
    cursor: pointer;
    color: #000;
    font-size: 12px;
    padding: 15px 25px;
    animation: and-float 6s ease-in-out infinite;
    transition: all 0.4s ease;
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.5);
    line-height: 1.3;
}

.and-mobile-node.and-active {
    box-shadow: 0 0 30px rgba(255, 255, 255, 0.8),
                0 0 60px rgba(255, 255, 255, 0.4);
    transform: scale(1.05);
}

/* Mobile children container */
.and-mobile-children {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.5s ease;
    padding: 0 20px;
    position: relative;
}

.and-mobile-node-group.and-expanded .and-mobile-children {
    max-height: 3000px;
    padding: 20px 20px;
}

/* Connection line for mobile */
.and-mobile-connection-line {
    position: absolute;
    width: 2px;
    background: rgba(255, 255, 255, 0.3);
    left: 50%;
    transform: translateX(-50%);
    top: -20px;
    bottom: 20px;
    z-index: 0;
}

/* Mobile child nodes */
.and-mobile-child {
    position: relative;
    margin: 0 auto 20px;
    width: 160px;
    min-height: 60px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    font-weight: bold;
    text-transform: uppercase;
    color: #000;
    font-size: 11px;
    padding: 12px 20px;
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.3);
    line-height: 1.3;
    opacity: 0;
    transform: translateY(-20px);
    transition: all 0.4s ease;
}

.and-mobile-node-group.and-expanded .and-mobile-child {
    opacity: 1;
    transform: translateY(0);
}

.and-mobile-node-group.and-expanded .and-mobile-child:nth-child(2) { transition-delay: 0.1s; }
.and-mobile-node-group.and-expanded .and-mobile-child:nth-child(3) { transition-delay: 0.2s; }
.and-mobile-node-group.and-expanded .and-mobile-child:nth-child(4) { transition-delay: 0.3s; }

/* Mobile info button */
.and-mobile-info-btn {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    background: #000;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: bold;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    z-index: 2;
}

/* Mobile grandchildren */
.and-mobile-grandchildren {
    margin: 15px 0 0 0;
    padding-left: 20px;
    border-left: 2px solid rgba(255, 255, 255, 0.2);
}

.and-mobile-grandchild {
    margin: 10px 0;
    padding: 8px 15px;
    background: rgba(255, 255, 255, 0.7);
    border-radius: 20px;
    font-size: 10px;
    font-weight: bold;
    text-transform: uppercase;
    color: #000;
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.2);
    display: inline-block;
    cursor: pointer;
}

/* ========== POPUP MODAL ========== */
.and-popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 9998;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: and-fade-in 0.3s ease;
}

.and-popup-overlay.and-closing {
    animation: and-fade-out 0.3s ease forwards;
}

.and-popup-modal {
    position: relative;
    background: #fff;
    color: #000;
    border-radius: 15px;
    box-shadow: 0 0 20px 5px rgba(255, 255, 255, 0.4);
    max-width: 90%;
    width: 500px;
    max-height: 80vh;
    overflow: auto;
    padding: 30px;
    animation: and-scale-in 0.3s ease;
    background-image: radial-gradient(circle at 50% 50%, rgba(255,255,255,0.95), rgba(255,255,255,0.8)),
                      repeating-conic-gradient(from 0deg, #ff00ff 0deg 30deg, #00ffff 30deg 60deg, #ffff00 60deg 90deg);
    background-blend-mode: lighten;
}

.and-popup-overlay.and-closing .and-popup-modal {
    animation: and-scale-out 0.3s ease forwards;
}

.and-popup-close {
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    color: #000;
    background: none;
    border: none;
    width: 30px;
    height: 30px;
    line-height: 30px;
    text-align: center;
    transition: transform 0.2s;
}

.and-popup-close:hover {
    transform: rotate(90deg);
}

.and-popup-content {
    font-size: 14px;
    line-height: 1.6;
}

@keyframes and-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes and-fade-out {
    from { opacity: 1; }
    to { opacity: 0; }
}

@keyframes and-scale-in {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes and-scale-out {
    from {
        opacity: 1;
        transform: scale(1);
    }
    to {
        opacity: 0;
        transform: scale(0.9);
    }
}

/* ========== RESPONSIVE ========== */
@media screen and (max-width: 768px) {
    .and-desktop-view {
        display: none;
    }

    .and-mobile-view {
        display: block;
    }

    .and-popup-modal {
        width: 95%;
        max-width: none;
        padding: 20px;
        font-size: 13px;
    }
}

@media screen and (min-width: 769px) {
    .and-mobile-view {
        display: none;
    }

    .and-desktop-view {
        display: block;
    }
}

/* Smooth scroll behavior */
html {
    scroll-behavior: smooth;
}

/* Loading state */
.and-diagram-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 400px;
    color: #fff;
}

.and-diagram-loading::after {
    content: '';
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: and-spin 0.8s linear infinite;
}

@keyframes and-spin {
    to { transform: rotate(360deg); }
}
