/* =============================================================
   concurrent.quest v2 — Living Systems Observatory
   ============================================================= */

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

:root {
    --deep-observatory: #060B18;
    --biolume-cyan: #00E5CC;
    --synapse-magenta: #D946EF;
    --axon-gold: #F5C842;
    --membrane-white: #E8ECF4;
    --fog-layer: rgba(8, 12, 24, 0.72);
    --thread-gray: #3A4260;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--deep-observatory);
    color: var(--membrane-white);
    font-family: 'Source Serif 4', Georgia, serif;
    font-weight: 400;
    font-size: clamp(16px, 1.2vw, 20px);
    line-height: 1.65;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* --- WebGL Canvas --- */
#particle-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
}

/* --- Title Overlay (Opening Sequence) --- */
#title-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 10;
    pointer-events: none;
    transition: opacity 1s ease;
}

#title-overlay.hidden {
    opacity: 0;
}

#title-text {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: clamp(36px, 6vw, 80px);
    letter-spacing: -0.02em;
    color: var(--membrane-white);
    white-space: nowrap;
}

#title-text .dot-accent {
    color: var(--biolume-cyan);
}

#scroll-hint {
    position: absolute;
    bottom: 60px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    opacity: 0;
    transition: opacity 0.8s ease;
}

#scroll-hint.visible {
    opacity: 0.6;
}

#scroll-hint svg {
    animation: hintBounce 2s ease-in-out infinite;
    transform: rotate(90deg);
}

#scroll-hint span {
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    letter-spacing: 0.05em;
    color: var(--thread-gray);
    text-transform: uppercase;
}

@keyframes hintBounce {
    0%, 100% { transform: rotate(90deg) translateY(0); }
    50% { transform: rotate(90deg) translateY(8px); }
}

/* --- Horizontal Panel Rail --- */
#panel-rail {
    position: fixed;
    top: 0;
    left: 0;
    display: flex;
    align-items: center;
    height: 100vh;
    z-index: 5;
    will-change: transform;
    transition: transform 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.panel {
    flex-shrink: 0;
    width: 100vw;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10vh 7.5vw;
}

.panel-glass {
    position: relative;
    width: 85vw;
    max-width: 1200px;
    max-height: 80vh;
    padding: clamp(32px, 4vw, 64px);
    background: var(--fog-layer);
    backdrop-filter: blur(20px) saturate(1.4);
    -webkit-backdrop-filter: blur(20px) saturate(1.4);
    border: 1px solid rgba(58, 66, 96, 0.3);
    border-radius: 16px;
    overflow-y: auto;
    overflow-x: hidden;
}

.panel-glass::-webkit-scrollbar {
    width: 4px;
}

.panel-glass::-webkit-scrollbar-track {
    background: transparent;
}

.panel-glass::-webkit-scrollbar-thumb {
    background: var(--thread-gray);
    border-radius: 2px;
}

/* --- Typography --- */
.panel-title {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: clamp(32px, 5.5vw, 72px);
    letter-spacing: -0.02em;
    color: var(--membrane-white);
    margin-bottom: 20px;
    line-height: 1.1;
}

.observatory-title {
    font-size: clamp(40px, 7vw, 96px);
}

.dot-accent {
    color: var(--biolume-cyan);
}

.panel-subtitle {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 500;
    font-size: clamp(16px, 2vw, 24px);
    color: var(--thread-gray);
    margin-bottom: 24px;
    letter-spacing: -0.01em;
}

.body-text {
    font-family: 'Source Serif 4', Georgia, serif;
    font-weight: 400;
    font-size: clamp(16px, 1.2vw, 20px);
    line-height: 1.65;
    color: var(--membrane-white);
    max-width: 640px;
    margin-bottom: 20px;
}

.panel-intro {
    color: var(--thread-gray);
    font-size: clamp(14px, 1vw, 16px);
    margin-bottom: 16px;
}

code {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 400;
    font-size: 14px;
    letter-spacing: 0.01em;
}

/* --- Haeckel Ornaments --- */
.haeckel-frame {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
}

.haeckel-ornament {
    position: absolute;
    width: 80px;
    height: 80px;
    opacity: 0.4;
    animation: ornamentBreathe 8s ease-in-out infinite;
}

.haeckel-ornament.top-left { top: 16px; left: 16px; }
.haeckel-ornament.top-right { top: 16px; right: 16px; }
.haeckel-ornament.bottom-left { bottom: 16px; left: 16px; }
.haeckel-ornament.bottom-right { bottom: 16px; right: 16px; }

@keyframes ornamentBreathe {
    0%, 100% { transform: scale(1); opacity: 0.4; }
    50% { transform: scale(1.003); opacity: 0.55; }
}

/* Panel transition illumination */
.panel.active .haeckel-ornament {
    animation: ornamentIlluminate 1.5s ease forwards, ornamentBreathe 8s ease-in-out infinite 1.5s;
}

@keyframes ornamentIlluminate {
    0% { opacity: 0.4; }
    30% { opacity: 0.9; }
    30.1% {
        filter: drop-shadow(0 0 6px var(--biolume-cyan));
    }
    100% {
        opacity: 0.4;
        filter: none;
    }
}

/* --- Thread Diagram (Panel 2) --- */
.thread-diagram {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin: 32px 0;
    padding: 24px;
    border: 1px solid rgba(58, 66, 96, 0.3);
    border-radius: 12px;
    background: rgba(6, 11, 24, 0.5);
}

.thread-lane {
    display: flex;
    align-items: center;
    gap: 12px;
}

.thread-label {
    min-width: 100px;
    color: var(--thread-gray);
}

.thread-blocks {
    display: flex;
    gap: 3px;
    flex-wrap: nowrap;
}

.thread-block {
    height: 28px;
    border-radius: 4px;
    transition: opacity 0.3s ease;
}

.thread-block.active {
    background: var(--biolume-cyan);
    opacity: 0.85;
}

.thread-block.idle {
    background: var(--thread-gray);
    opacity: 0.4;
}

.thread-block.blocked {
    background: var(--axon-gold);
    opacity: 0.75;
}

.thread-block.sync {
    background: var(--synapse-magenta);
    opacity: 0.8;
}

/* Thread animation when panel is active */
.panel.active .thread-block {
    animation: threadPulse 3s ease-in-out infinite;
}

.panel.active .thread-lane:nth-child(2) .thread-block {
    animation-delay: 0.4s;
}

.panel.active .thread-lane:nth-child(3) .thread-block {
    animation-delay: 0.8s;
}

@keyframes threadPulse {
    0%, 100% { opacity: 0.7; }
    50% { opacity: 1; }
}

.legend {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    margin-top: 8px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    color: var(--thread-gray);
}

.legend-swatch {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 3px;
}

.legend-swatch.active { background: var(--biolume-cyan); }
.legend-swatch.idle { background: var(--thread-gray); }
.legend-swatch.blocked { background: var(--axon-gold); }
.legend-swatch.sync { background: var(--synapse-magenta); }

/* --- Node Graph (Panel 3) --- */
.node-graph-container {
    position: relative;
    width: 100%;
    height: 420px;
    border: 1px solid rgba(58, 66, 96, 0.3);
    border-radius: 12px;
    background: rgba(6, 11, 24, 0.5);
    overflow: hidden;
}

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

.process-node {
    position: absolute;
    padding: 12px 20px;
    background: rgba(6, 11, 24, 0.9);
    border: 1px solid var(--thread-gray);
    border-radius: 12px;
    cursor: pointer;
    z-index: 2;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
    user-select: none;
}

.process-node:hover {
    border-color: var(--biolume-cyan);
    box-shadow: 0 0 20px rgba(0, 229, 204, 0.15);
}

.process-node.dragging {
    border-color: var(--synapse-magenta);
    box-shadow: 0 0 25px rgba(217, 70, 239, 0.25);
}

.process-node.deadlocked {
    border-color: var(--axon-gold);
    box-shadow: 0 0 25px rgba(245, 200, 66, 0.3);
    animation: deadlockPulse 1s ease-in-out infinite;
}

.process-node.flowing {
    border-color: var(--biolume-cyan);
    box-shadow: 0 0 20px rgba(0, 229, 204, 0.25);
}

@keyframes deadlockPulse {
    0%, 100% { box-shadow: 0 0 25px rgba(245, 200, 66, 0.3); }
    50% { box-shadow: 0 0 40px rgba(245, 200, 66, 0.5); }
}

.node-label {
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    color: var(--membrane-white);
    white-space: nowrap;
}

.deadlock-label {
    position: absolute;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    font-family: 'JetBrains Mono', monospace;
    font-size: 14px;
    color: var(--axon-gold);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    opacity: 1;
    transition: opacity 0.5s ease;
}

.flow-label {
    position: absolute;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    font-family: 'JetBrains Mono', monospace;
    font-size: 14px;
    color: var(--biolume-cyan);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    opacity: 1;
    transition: opacity 0.5s ease;
}

.hidden {
    opacity: 0 !important;
    pointer-events: none;
}

/* SVG connection lines */
.node-connection {
    fill: none;
    stroke: var(--thread-gray);
    stroke-width: 1.5;
    transition: stroke 0.3s ease;
}

.node-connection.active-flow {
    stroke: var(--biolume-cyan);
    stroke-dasharray: 8 4;
    animation: flowDash 1s linear infinite;
}

.node-connection.deadlock-flow {
    stroke: var(--axon-gold);
    stroke-width: 2;
}

.node-connection-temp {
    fill: none;
    stroke: var(--synapse-magenta);
    stroke-width: 1.5;
    stroke-dasharray: 4 4;
    opacity: 0.6;
}

@keyframes flowDash {
    to { stroke-dashoffset: -24; }
}

/* --- Patterns Catalog (Panel 4) --- */
.patterns-catalog {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 24px;
    margin-top: 24px;
}

.pattern-card {
    padding: 24px;
    border: 1px solid rgba(58, 66, 96, 0.3);
    border-radius: 12px;
    background: rgba(6, 11, 24, 0.5);
    transition: border-color 0.4s ease, box-shadow 0.4s ease;
}

.pattern-card:hover {
    border-color: var(--biolume-cyan);
    box-shadow: 0 0 20px rgba(0, 229, 204, 0.1);
}

.pattern-organism {
    width: 100px;
    height: 100px;
    margin: 0 auto 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pattern-svg {
    width: 100%;
    height: 100%;
    animation: ornamentBreathe 8s ease-in-out infinite;
}

.pattern-name {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: 20px;
    color: var(--membrane-white);
    margin-bottom: 8px;
}

.pattern-desc {
    font-family: 'Source Serif 4', Georgia, serif;
    font-size: 14px;
    line-height: 1.6;
    color: var(--thread-gray);
}

/* Channel particle animation */
.channel-particle {
    animation: channelFlow 2s linear infinite;
}

.cp1 { animation-delay: 0s; }
.cp2 { animation-delay: 0.6s; }
.cp3 { animation-delay: 1.2s; }

@keyframes channelFlow {
    0% { transform: translateX(-20px); opacity: 0; }
    20% { opacity: 1; }
    80% { opacity: 1; }
    100% { transform: translateX(20px); opacity: 0; }
}

/* --- Join Panel (Panel 5) --- */
.panel-join {
    display: flex;
    align-items: center;
    justify-content: center;
}

.join-content {
    text-align: center;
    max-width: 500px;
}

.join-title {
    font-size: clamp(28px, 4vw, 56px);
    margin-bottom: 12px;
}

.join-subtitle {
    color: var(--thread-gray);
    margin-bottom: 32px;
}

.join-input-wrapper {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
}

.join-input {
    font-family: 'JetBrains Mono', monospace;
    font-size: 14px;
    padding: 12px 20px;
    width: 280px;
    background: rgba(6, 11, 24, 0.8);
    border: 1px solid var(--thread-gray);
    border-radius: 8px;
    color: var(--membrane-white);
    outline: none;
    transition: border-color 0.3s ease;
}

.join-input::placeholder {
    color: var(--thread-gray);
}

.join-input:focus {
    border-color: var(--biolume-cyan);
}

.join-button {
    font-family: 'JetBrains Mono', monospace;
    font-size: 14px;
    padding: 12px 24px;
    background: transparent;
    border: 1px solid var(--biolume-cyan);
    border-radius: 8px;
    color: var(--biolume-cyan);
    cursor: pointer;
    transition: background 0.3s ease, color 0.3s ease;
}

.join-button:hover {
    background: var(--biolume-cyan);
    color: var(--deep-observatory);
}

.join-confirmation {
    margin-top: 24px;
    transition: opacity 0.8s ease;
}

.confirmation-text {
    font-family: 'JetBrains Mono', monospace;
    font-size: 16px;
    color: var(--synapse-magenta);
    letter-spacing: 0.1em;
}

/* --- Progress Bar --- */
#progress-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 4px;
    background: rgba(58, 66, 96, 0.3);
    z-index: 20;
}

#progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--biolume-cyan), var(--synapse-magenta));
    transition: width 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

#progress-indicators {
    position: absolute;
    top: -14px;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: space-evenly;
    padding: 0 10%;
}

.progress-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--thread-gray);
    border: none;
    cursor: pointer;
    transition: background 0.3s ease, transform 0.3s ease;
    padding: 0;
}

.progress-dot.active {
    background: var(--biolume-cyan);
    transform: scale(1.3);
}

.progress-dot:hover {
    background: var(--membrane-white);
}

/* --- Synchronization Rings (spawned dynamically) --- */
.sync-ring {
    position: fixed;
    border: 1px solid var(--synapse-magenta);
    border-radius: 50%;
    pointer-events: none;
    z-index: 1;
    animation: syncExpand 1.5s ease-out forwards;
}

@keyframes syncExpand {
    0% {
        width: 0;
        height: 0;
        opacity: 0.4;
    }
    100% {
        width: 400px;
        height: 400px;
        opacity: 0;
        margin-top: -200px;
        margin-left: -200px;
    }
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .panel-glass {
        width: 92vw;
        max-height: 85vh;
        padding: clamp(20px, 3vw, 32px);
    }

    .thread-diagram {
        padding: 16px;
        overflow-x: auto;
    }

    .thread-label {
        min-width: 70px;
    }

    .thread-label code {
        font-size: 11px;
    }

    .node-graph-container {
        height: 350px;
    }

    .process-node {
        padding: 8px 12px;
    }

    .node-label code {
        font-size: 11px;
    }

    .patterns-catalog {
        grid-template-columns: 1fr 1fr;
        gap: 16px;
    }

    .join-input-wrapper {
        flex-direction: column;
        align-items: center;
    }

    .join-input {
        width: 100%;
        max-width: 280px;
    }

    #progress-indicators {
        padding: 0 5%;
    }
}

@media (max-width: 480px) {
    .patterns-catalog {
        grid-template-columns: 1fr;
    }
}
