/* ============================================
   xanadu.quest - Luminescent Neon Knowledge Graph
   ============================================ */

/* --- Reset & Base --- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --teal: #00D9D9;
    --purple: #7B5AFF;
    --gold: #FFB84D;
    --rose: #FF6B9D;
    --text-primary: #E8F4F8;
    --text-secondary: #A0BCC5;
    --bg-deep: #0F1B2E;
    --bg-light: #1A3A52;
    --bg-mid: #1A2B47;
    --gradient-mid: #2D1B4E;

    --font-headline: 'Space Grotesk', sans-serif;
    --font-body: 'Inter', sans-serif;
    --font-mono: 'IBM Plex Mono', monospace;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-body);
    color: var(--text-primary);
    background: var(--bg-deep);
    overflow-x: hidden;
    line-height: 1.7;
    letter-spacing: 0.01em;
    min-height: 500vh;
}

/* --- Animated Background Gradient --- */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, var(--bg-deep) 0%, var(--bg-mid) 50%, var(--bg-deep) 100%);
    background-size: 400% 400%;
    animation: bgShift 20s ease infinite;
    z-index: -2;
}

@keyframes bgShift {
    0% { background-position: 0% 0%; }
    50% { background-position: 100% 100%; }
    100% { background-position: 0% 0%; }
}

/* --- SVG Thread Canvas --- */
#thread-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
}

#thread-canvas path {
    fill: none;
    stroke-width: 2.5;
    stroke-linecap: round;
    opacity: 0.5;
    transition: opacity 0.4s ease, filter 0.4s ease;
}

#thread-canvas path.thread-active {
    opacity: 1;
    filter: url(#thread-glow);
    stroke-width: 3;
}

#thread-canvas path.thread-pulse {
    animation: threadPulse 3.5s ease-in-out infinite;
}

@keyframes threadPulse {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 0.8; }
}

/* --- Scroll Sections --- */
.scroll-section {
    position: relative;
    z-index: 2;
    pointer-events: none;
}

#hero-section {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

#wave-section {
    min-height: 150vh;
    padding: 10vh 5vw;
    position: relative;
}

#nested-section {
    min-height: 150vh;
    padding: 10vh 5vw;
    position: relative;
}

#constellation-section {
    min-height: 100vh;
    padding: 10vh 5vw;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* --- Nodes --- */
.node {
    position: relative;
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    pointer-events: auto;
    cursor: pointer;
    transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.4s ease;
    opacity: 0;
    transform: scale(0.95);
}

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

/* --- Node Sizes --- */
.node-hero {
    width: clamp(280px, 40vw, 400px);
    height: clamp(280px, 40vw, 400px);
    background: rgba(26, 58, 82, 0.2);
    border: 1px solid rgba(0, 217, 217, 0.4);
    box-shadow: 0 0 20px 4px rgba(0, 217, 217, 0.3), inset 0 0 30px rgba(0, 217, 217, 0.05);
    z-index: 10;
}

.node-primary {
    width: clamp(200px, 30vw, 300px);
    height: clamp(200px, 30vw, 300px);
    background: rgba(26, 58, 82, 0.18);
    border: 1px solid rgba(123, 90, 255, 0.35);
    box-shadow: 0 0 18px 3px rgba(123, 90, 255, 0.25), inset 0 0 20px rgba(123, 90, 255, 0.04);
    z-index: 8;
}

.node-secondary {
    width: clamp(130px, 18vw, 180px);
    height: clamp(130px, 18vw, 180px);
    background: rgba(26, 58, 82, 0.15);
    border: 1px solid rgba(255, 184, 77, 0.3);
    box-shadow: 0 0 15px 3px rgba(255, 184, 77, 0.2), inset 0 0 15px rgba(255, 184, 77, 0.03);
    z-index: 6;
}

.node-tertiary {
    width: clamp(70px, 10vw, 120px);
    height: clamp(70px, 10vw, 120px);
    background: rgba(26, 58, 82, 0.12);
    border: 1px solid rgba(255, 107, 157, 0.25);
    box-shadow: 0 0 12px 2px rgba(255, 107, 157, 0.15);
    z-index: 4;
}

/* --- Node Hover --- */
.node:hover {
    transform: scale(1.03);
}

.node-hero:hover {
    box-shadow: 0 0 35px 8px rgba(0, 217, 217, 0.5), inset 0 0 40px rgba(0, 217, 217, 0.08);
    background: rgba(26, 58, 82, 0.3);
}

.node-primary:hover {
    box-shadow: 0 0 30px 6px rgba(123, 90, 255, 0.4), inset 0 0 30px rgba(123, 90, 255, 0.06);
    background: rgba(26, 58, 82, 0.28);
}

.node-secondary:hover {
    box-shadow: 0 0 25px 5px rgba(255, 184, 77, 0.35), inset 0 0 25px rgba(255, 184, 77, 0.05);
    background: rgba(26, 58, 82, 0.25);
}

.node-tertiary:hover {
    box-shadow: 0 0 20px 4px rgba(255, 107, 157, 0.3);
    background: rgba(26, 58, 82, 0.2);
}

/* --- Node Content --- */
.node-label {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 400;
    letter-spacing: 0.04em;
    text-transform: lowercase;
    color: rgba(160, 188, 197, 0.7);
    margin-bottom: 8px;
}

.hero-title {
    font-family: var(--font-headline);
    font-size: clamp(2.5rem, 9vw, 5rem);
    font-weight: 700;
    letter-spacing: 0.03em;
    color: var(--text-primary);
    line-height: 1.1;
    text-shadow: 0 0 30px rgba(0, 217, 217, 0.4);
}

.hero-tagline {
    font-family: var(--font-body);
    font-size: clamp(0.85rem, 2vw, 1.1rem);
    font-weight: 400;
    color: var(--text-secondary);
    margin-top: 12px;
    max-width: 80%;
    line-height: 1.5;
}

.node h2 {
    font-family: var(--font-headline);
    font-size: clamp(1.4rem, 4vw, 2.2rem);
    font-weight: 700;
    letter-spacing: 0.03em;
    color: var(--text-primary);
    line-height: 1.2;
    margin-bottom: 8px;
}

.node h3 {
    font-family: var(--font-headline);
    font-size: clamp(1rem, 2.5vw, 1.4rem);
    font-weight: 700;
    letter-spacing: 0.03em;
    color: var(--text-primary);
    line-height: 1.2;
    margin-bottom: 6px;
}

.node p {
    font-family: var(--font-body);
    font-size: clamp(0.75rem, 1.5vw, 0.95rem);
    font-weight: 400;
    color: var(--text-secondary);
    line-height: 1.6;
    max-width: 85%;
}

/* --- Hero Accent Nodes --- */
#node-accent-1 {
    position: absolute;
    top: 18%;
    right: 12%;
}

#node-accent-2 {
    position: absolute;
    bottom: 22%;
    left: 10%;
}

/* --- Wave Section Positioning (Asymmetric) --- */
#wave-section {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
    align-items: flex-start;
    gap: 4vh;
}

#node-concepts {
    margin-left: 5%;
    margin-top: 5vh;
}

#node-explore {
    margin-right: 3%;
    margin-top: 18vh;
}

#node-history {
    margin-left: 20%;
    margin-top: 8vh;
}

/* --- Nested Section Positioning --- */
#nested-section {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
    align-items: flex-start;
    gap: 3vh;
}

#node-parallel {
    margin-left: 8%;
    margin-top: 3vh;
}

#node-transclusion {
    margin-right: 15%;
    margin-top: 10vh;
}

#node-versioning {
    margin-left: 25%;
    margin-top: 2vh;
}

#node-deep-links {
    margin-right: 8%;
    margin-top: 15vh;
}

#node-side-by-side {
    margin-left: 12%;
    margin-top: 5vh;
}

/* --- Constellation --- */
.constellation-container {
    position: relative;
    width: clamp(300px, 80vw, 900px);
    height: clamp(300px, 60vh, 600px);
    pointer-events: auto;
}

.constellation-node {
    position: absolute;
}

/* Constellation node positions - scattered */
#cnode-1  { top: 5%;   left: 10%; }
#cnode-2  { top: 15%;  left: 40%; }
#cnode-3  { top: 8%;   left: 72%; }
#cnode-4  { top: 30%;  left: 85%; }
#cnode-5  { top: 38%;  left: 5%;  }
#cnode-6  { top: 50%;  left: 35%; }
#cnode-7  { top: 42%;  left: 60%; }
#cnode-8  { top: 60%;  left: 80%; }
#cnode-9  { top: 70%;  left: 50%; }
#cnode-10 { top: 75%;  left: 20%; }
#cnode-11 { top: 85%;  left: 65%; }
#cnode-12 { top: 88%;  left: 8%;  }

.constellation-text {
    margin-top: 5vh;
    text-align: center;
    pointer-events: auto;
}

.constellation-caption {
    font-family: var(--font-headline);
    font-size: clamp(1rem, 2.5vw, 1.5rem);
    font-weight: 400;
    letter-spacing: 0.03em;
    color: var(--text-secondary);
    max-width: 600px;
    line-height: 1.6;
}

/* --- Thread Tooltip --- */
.thread-tooltip {
    position: fixed;
    z-index: 100;
    background: rgba(26, 58, 82, 0.9);
    border: 1px solid rgba(0, 217, 217, 0.4);
    border-radius: 6px;
    padding: 6px 12px;
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.04em;
    text-transform: lowercase;
    color: var(--text-secondary);
    pointer-events: none;
    transition: opacity 0.2s ease;
    box-shadow: 0 0 12px rgba(0, 217, 217, 0.2);
}

.thread-tooltip[hidden] {
    opacity: 0;
    display: block;
    visibility: hidden;
}

/* --- Connection Points (dots at thread ends) --- */
.connection-dot {
    position: absolute;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    z-index: 5;
    pointer-events: none;
    box-shadow: 0 0 8px 2px currentColor;
}

/* --- Scroll Reveal Animation --- */
@keyframes nodePopIn {
    0% {
        opacity: 0;
        transform: scale(0.92);
    }
    60% {
        transform: scale(1.02);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

.node.animate-in {
    animation: nodePopIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* --- Thread Drawing Animation --- */
@keyframes threadDraw {
    from { stroke-dashoffset: 1000; }
    to   { stroke-dashoffset: 0; }
}

#thread-canvas path.thread-drawing {
    stroke-dasharray: 1000;
    animation: threadDraw 0.8s ease-out forwards;
}

/* --- Responsive: Mobile --- */
@media (max-width: 768px) {
    body {
        font-size: 15px;
        line-height: 1.6;
    }

    .scroll-section {
        display: flex;
        flex-direction: column;
        align-items: center;
        min-height: auto;
        padding: 5vh 4vw;
    }

    #hero-section {
        height: 100vh;
    }

    .node {
        border-radius: 24px;
        width: 85vw !important;
        height: auto !important;
        min-height: 120px;
        padding: 24px 20px;
        margin: 12px 0 !important;
        position: relative !important;
        top: auto !important;
        left: auto !important;
        right: auto !important;
        bottom: auto !important;
    }

    .node-hero {
        width: 90vw !important;
        min-height: 200px;
        border-radius: 32px;
    }

    .constellation-container {
        display: flex;
        flex-wrap: wrap;
        gap: 10px;
        justify-content: center;
        height: auto;
    }

    .constellation-node {
        position: relative !important;
        top: auto !important;
        left: auto !important;
        width: 80px !important;
        height: 80px !important;
    }

    /* Threads become thin vertical separators on mobile */
    #thread-canvas {
        display: none;
    }

    .scroll-section + .scroll-section::before {
        content: '';
        display: block;
        width: 1px;
        height: 40px;
        background: linear-gradient(to bottom, var(--teal), var(--purple));
        margin: 0 auto 20px;
        opacity: 0.5;
    }
}
