/* conc.quest - Interactive Concurrency Experience */
/* Palette: #0a0a1a, #00e5ff, #ff4081, #76ff03, #ffd740, #ff1744, #e0e0e0 */
/* Fonts: Chakra Petch (display), IBM Plex Sans (body), IBM Plex Mono (labels) */

:root {
    --void: #0a0a1a;
    --void-light: #12122a;
    --thread-a: #00e5ff;
    --thread-b: #ff4081;
    --thread-c: #76ff03;
    --sync: #ffd740;
    --deadlock: #ff1744;
    --text: #e0e0e0;
    --text-dim: rgba(224, 224, 224, 0.5);
    --text-faint: rgba(224, 224, 224, 0.25);
    --glow-a: rgba(0, 229, 255, 0.5);
    --glow-b: rgba(255, 64, 129, 0.5);
    --glow-c: rgba(118, 255, 3, 0.5);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html {
    scroll-behavior: smooth;
}

body {
    background: var(--void);
    color: var(--text);
    font-family: 'IBM Plex Sans', sans-serif;
    font-weight: 400;
    line-height: 1.65;
    overflow-x: hidden;
}

/* ================================
   PARTICLE CANVAS
   ================================ */
#particle-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
}

/* ================================
   HERO SECTION
   ================================ */
.hero {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    z-index: 1;
}

.trail-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

.trail {
    stroke-dasharray: 1200;
    stroke-dashoffset: 1200;
    animation: drawTrail 2.5s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.trail-a { animation-delay: 0.1s; }
.trail-b { animation-delay: 0.4s; }
.trail-c { animation-delay: 0.7s; }

.trail-a-echo, .trail-b-echo, .trail-c-echo {
    stroke-dasharray: 1200;
    stroke-dashoffset: 1200;
    animation: drawTrail 3s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.trail-a-echo { animation-delay: 0.5s; }
.trail-b-echo { animation-delay: 0.8s; }
.trail-c-echo { animation-delay: 1.1s; }

@keyframes drawTrail {
    to { stroke-dashoffset: 0; }
}

.origin-pulse {
    animation: originPulse 2s ease-in-out infinite;
}

@keyframes originPulse {
    0%, 100% { r: 5; opacity: 1; }
    50% { r: 12; opacity: 0.3; }
}

.hero-content {
    position: relative;
    z-index: 2;
    text-align: center;
}

.hero-pid {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.65rem;
    color: var(--text-faint);
    letter-spacing: 0.15em;
    margin-bottom: 1rem;
}

.brand {
    font-family: 'Chakra Petch', sans-serif;
    font-weight: 700;
    font-size: clamp(3.5rem, 10vw, 6rem);
    color: #fff;
    text-shadow:
        0 0 40px rgba(0, 229, 255, 0.25),
        0 0 80px rgba(255, 64, 129, 0.15),
        0 0 120px rgba(118, 255, 3, 0.1);
    letter-spacing: -0.02em;
}

.brand-dot {
    color: var(--thread-a);
    text-shadow: 0 0 20px var(--glow-a);
}

.brand-sub {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.85rem;
    color: var(--text-dim);
    margin-top: 0.5rem;
    letter-spacing: 0.12em;
}

.hero-status {
    display: flex;
    gap: 1.5rem;
    justify-content: center;
    margin-top: 2rem;
}

.status-item {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.65rem;
    color: var(--text-dim);
    letter-spacing: 0.08em;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    opacity: 0;
    animation: fadeIn 0.5s ease forwards;
}

.status-item:nth-child(1) { animation-delay: 1.5s; }
.status-item:nth-child(2) { animation-delay: 1.8s; }
.status-item:nth-child(3) { animation-delay: 2.1s; }

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    animation: statusBlink 1.5s ease infinite;
}

.dot-color-a { background: var(--thread-a); box-shadow: 0 0 6px var(--glow-a); }
.dot-color-b { background: var(--thread-b); box-shadow: 0 0 6px var(--glow-b); }
.dot-color-c { background: var(--thread-c); box-shadow: 0 0 6px var(--glow-c); }

@keyframes statusBlink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* Fork SVG */
.fork-svg {
    position: relative;
    z-index: 2;
    margin-top: 2.5rem;
    opacity: 0;
    animation: fadeIn 1s ease forwards 2s;
}

.fork-line {
    stroke-dasharray: 200;
    stroke-dashoffset: 200;
    animation: drawTrail 1s ease forwards 2.2s;
}

.fork-endpoint {
    opacity: 0;
    animation: fadeIn 0.5s ease forwards 2.8s;
}

@keyframes fadeIn {
    to { opacity: 1; }
}

/* Scroll Hint */
.scroll-hint {
    position: absolute;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    opacity: 0;
    animation: fadeIn 1s ease forwards 3s, scrollBounce 2s ease-in-out infinite 3.5s;
    z-index: 2;
}

.scroll-hint-text {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.6rem;
    letter-spacing: 0.2em;
    color: var(--text-faint);
}

@keyframes scrollBounce {
    0%, 100% { transform: translateX(-50%) translateY(0); }
    50% { transform: translateX(-50%) translateY(6px); }
}

/* ================================
   PARALLEL SECTION
   ================================ */
.parallel-section {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem 1.5rem 4rem;
    position: relative;
    z-index: 1;
}

/* Sync Barriers */
.sync-barrier {
    border-top: 2px dashed var(--sync);
    padding: 0.75rem 0;
    margin: 3rem 0;
    text-align: center;
    position: relative;
}

.sync-barrier::before,
.sync-barrier::after {
    content: '';
    position: absolute;
    top: -2px;
    width: 8px;
    height: 8px;
    background: var(--sync);
    border-radius: 50%;
}

.sync-barrier::before { left: 0; }
.sync-barrier::after { right: 0; }

.sync-barrier.sync-danger {
    border-color: var(--deadlock);
}
.sync-barrier.sync-danger::before,
.sync-barrier.sync-danger::after {
    background: var(--deadlock);
}

.sync-barrier.sync-final {
    border-color: #fff;
    border-style: solid;
}
.sync-barrier.sync-final::before,
.sync-barrier.sync-final::after {
    background: #fff;
}

.sync-label {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.7rem;
    letter-spacing: 0.15em;
    color: var(--sync);
    background: var(--void);
    padding: 0 1rem;
    position: relative;
    z-index: 1;
}

.sync-danger .sync-label { color: var(--deadlock); }
.sync-final .sync-label { color: #fff; }

.sync-timestamp {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.6rem;
    color: var(--text-faint);
    display: block;
    margin-top: 0.25rem;
}

/* Thread Grid */
.thread-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 2px;
    margin: 1rem 0;
}

.thread {
    padding: 1.5rem;
    border-left: 3px solid;
    background: rgba(255, 255, 255, 0.015);
    position: relative;
    transition: background 0.3s ease;
}

.thread::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.05), transparent);
}

.thread:hover {
    background: rgba(255, 255, 255, 0.04);
}

.thread-a { border-left-color: var(--thread-a); }
.thread-b { border-left-color: var(--thread-b); }
.thread-c { border-left-color: var(--thread-c); }

.thread-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.thread-badge {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.65rem;
    font-weight: 400;
    padding: 0.15rem 0.55rem;
    border-radius: 9999px;
    color: var(--void);
    letter-spacing: 0.05em;
}

.badge-a { background: var(--thread-a); box-shadow: 0 0 8px var(--glow-a); }
.badge-b { background: var(--thread-b); box-shadow: 0 0 8px var(--glow-b); }
.badge-c { background: var(--thread-c); box-shadow: 0 0 8px var(--glow-c); }

.thread-state {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.55rem;
    letter-spacing: 0.1em;
    padding: 0.1rem 0.4rem;
    border-radius: 3px;
    border: 1px solid;
}

.state-running {
    color: var(--thread-c);
    border-color: rgba(118, 255, 3, 0.3);
    background: rgba(118, 255, 3, 0.05);
}

.state-waiting {
    color: var(--sync);
    border-color: rgba(255, 215, 64, 0.3);
    background: rgba(255, 215, 64, 0.05);
}

.state-blocked {
    color: var(--deadlock);
    border-color: rgba(255, 23, 68, 0.3);
    background: rgba(255, 23, 68, 0.05);
}

/* Spinners */
.spinner {
    width: 10px;
    height: 10px;
    border: 1.5px solid rgba(224, 224, 224, 0.15);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-left: auto;
}

.spinner-a { border-top-color: var(--thread-a); }
.spinner-b { border-top-color: var(--thread-b); }
.spinner-c { border-top-color: var(--thread-c); }

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

/* Thread Progress */
.thread-progress {
    height: 3px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 2px;
    margin-bottom: 1rem;
    overflow: hidden;
}

.thread-bar {
    height: 100%;
    border-radius: 2px;
    width: 0;
    transition: width 1.8s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.bar-a { background: var(--thread-a); box-shadow: 0 0 6px var(--glow-a); }
.bar-b { background: var(--thread-b); box-shadow: 0 0 6px var(--glow-b); }
.bar-c { background: var(--thread-c); box-shadow: 0 0 6px var(--glow-c); }

.thread-title {
    font-family: 'Chakra Petch', sans-serif;
    font-weight: 600;
    font-size: 1.05rem;
    margin-bottom: 0.5rem;
    color: var(--text);
}

.thread-desc {
    font-size: 0.82rem;
    color: var(--text-dim);
    line-height: 1.6;
    margin-bottom: 0.75rem;
}

.thread-meta-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.thread-meta {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.65rem;
    color: var(--text-faint);
}

/* Call Stack */
.thread-callstack {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.callstack-label {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.55rem;
    color: var(--text-faint);
    letter-spacing: 0.1em;
    display: block;
    margin-bottom: 0.35rem;
}

.callstack-frame {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.7rem;
    color: var(--text-dim);
    display: block;
    padding: 0.15rem 0;
    padding-left: 0.75rem;
    border-left: 1px solid rgba(255, 255, 255, 0.08);
}

.callstack-frame::before {
    content: '\25B8 ';
    color: var(--text-faint);
}

/* Context Switch Animation */
.context-switch-grid.switching .thread {
    animation: contextSwitch 0.8s ease;
}

@keyframes contextSwitch {
    0% { filter: blur(0); opacity: 1; }
    30% { filter: blur(4px); opacity: 0.5; }
    60% { filter: blur(4px); opacity: 0.5; }
    100% { filter: blur(0); opacity: 1; }
}

/* ================================
   CONTENTION SECTION
   ================================ */
.contention-section {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem 1.5rem 4rem;
    position: relative;
    z-index: 1;
}

.contention-zone {
    padding: 2rem;
    border: 1px solid rgba(255, 23, 68, 0.15);
    border-radius: 6px;
    background: linear-gradient(180deg, rgba(255, 23, 68, 0.03) 0%, transparent 100%);
    position: relative;
}

.contention-header {
    margin-bottom: 1.5rem;
}

.contention-header-text {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.65rem;
    color: var(--deadlock);
    letter-spacing: 0.12em;
    opacity: 0.7;
}

.contention-overlap {
    position: relative;
}

.contention-thread {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    border: 1px solid;
    border-radius: 4px;
    margin-bottom: 0.5rem;
    transition: transform 0.5s ease, opacity 0.5s ease;
}

.ct-a {
    border-color: rgba(0, 229, 255, 0.4);
    background: rgba(0, 229, 255, 0.04);
    position: relative;
    z-index: 3;
}

.ct-b {
    border-color: rgba(255, 64, 129, 0.4);
    background: rgba(255, 64, 129, 0.04);
    position: relative;
    z-index: 2;
    margin-top: -6px;
    margin-left: 24px;
}

.ct-c {
    border-color: rgba(118, 255, 3, 0.4);
    background: rgba(118, 255, 3, 0.04);
    position: relative;
    z-index: 1;
    margin-top: -6px;
    margin-left: 48px;
}

.lock-icon {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.lock-icon.locked svg {
    animation: lockPulse 1.2s ease infinite;
}

.lock-icon.waiting svg {
    opacity: 0.4;
    animation: lockWait 2s ease infinite;
}

@keyframes lockPulse {
    0%, 100% { opacity: 1; filter: drop-shadow(0 0 4px var(--thread-a)); }
    50% { opacity: 0.4; filter: none; }
}

@keyframes lockWait {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 0.2; }
}

.contention-info {
    flex: 1;
    min-width: 0;
}

.contention-text {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.78rem;
    color: var(--text-dim);
}

.contention-detail {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.6rem;
    color: var(--text-faint);
    margin-top: 0.2rem;
}

/* Deadlock Warning */
.deadlock-warning {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    margin-top: 2rem;
    padding: 1.25rem;
    border: 1px solid rgba(255, 23, 68, 0.5);
    border-radius: 4px;
    background: rgba(255, 23, 68, 0.06);
    animation: deadlockGlow 2s ease infinite;
}

@keyframes deadlockGlow {
    0%, 100% { box-shadow: 0 0 0 transparent; }
    50% { box-shadow: 0 0 20px rgba(255, 23, 68, 0.1); }
}

.deadlock-pulse {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--deadlock);
    flex-shrink: 0;
    margin-top: 2px;
    animation: deadlockBlink 0.8s ease infinite;
}

@keyframes deadlockBlink {
    0%, 100% { opacity: 1; box-shadow: 0 0 8px var(--deadlock); }
    50% { opacity: 0.2; box-shadow: none; }
}

.deadlock-info {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.deadlock-text {
    font-family: 'Chakra Petch', sans-serif;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--deadlock);
    letter-spacing: 0.1em;
}

.deadlock-detail {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.65rem;
    color: rgba(255, 23, 68, 0.6);
}

/* Resolution Zone */
.resolution-zone {
    margin-top: 2rem;
    padding: 1.5rem;
    border: 1px solid rgba(118, 255, 3, 0.2);
    border-radius: 4px;
    background: rgba(118, 255, 3, 0.02);
}

.resolution-header {
    margin-bottom: 1rem;
}

.resolution-label {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.65rem;
    color: var(--thread-c);
    letter-spacing: 0.12em;
}

.resolution-steps {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.resolution-step {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    opacity: 0.3;
    transition: opacity 0.5s ease;
}

.resolution-step.step-active {
    opacity: 1;
}

.step-num {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.6rem;
    color: var(--thread-c);
    background: rgba(118, 255, 3, 0.1);
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
}

.step-text {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.75rem;
    color: var(--text-dim);
}

/* ================================
   JOIN SECTION
   ================================ */
.join-section {
    max-width: 900px;
    margin: 0 auto;
    padding: 4rem 2rem 6rem;
    text-align: center;
    position: relative;
    z-index: 1;
}

.join-svg {
    opacity: 0;
    animation: fadeIn 1s ease forwards;
    margin-bottom: 1.5rem;
}

.join-line {
    stroke-dasharray: 200;
    stroke-dashoffset: 200;
}

.join-endpoint {
    opacity: 0;
}

.join-merge-point {
    opacity: 0;
    animation: mergeGlow 2s ease infinite;
}

@keyframes mergeGlow {
    0%, 100% { filter: drop-shadow(0 0 4px rgba(255,255,255,0.3)); }
    50% { filter: drop-shadow(0 0 12px rgba(255,255,255,0.7)); }
}

.join-content {
    padding: 2rem 0;
}

.join-title {
    font-family: 'Chakra Petch', sans-serif;
    font-weight: 700;
    font-size: clamp(1.8rem, 4vw, 2.5rem);
    color: #fff;
    margin-bottom: 1rem;
    text-shadow: 0 0 30px rgba(255, 255, 255, 0.15);
}

.join-desc {
    font-size: 0.9rem;
    color: var(--text-dim);
    max-width: 550px;
    margin: 0 auto 2.5rem;
    line-height: 1.7;
}

/* Join Trails */
.join-trails {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 2.5rem;
}

.join-trail-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.35rem;
}

.join-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    transition: transform 0.3s ease;
}

.join-dot:hover {
    transform: scale(1.3);
}

.dot-a { background: var(--thread-a); box-shadow: 0 0 10px var(--glow-a); }
.dot-b { background: var(--thread-b); box-shadow: 0 0 10px var(--glow-b); }
.dot-c { background: var(--thread-c); box-shadow: 0 0 10px var(--glow-c); }
.dot-merged {
    background: #fff;
    box-shadow: 0 0 16px rgba(255, 255, 255, 0.6);
    width: 18px;
    height: 18px;
    animation: mergePulse 2s ease infinite;
}

@keyframes mergePulse {
    0%, 100% { box-shadow: 0 0 16px rgba(255, 255, 255, 0.6); }
    50% { box-shadow: 0 0 24px rgba(255, 255, 255, 0.9); }
}

.join-dot-label {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.55rem;
    color: var(--text-faint);
    letter-spacing: 0.08em;
}

.join-connector {
    width: 20px;
    height: 1px;
    background: rgba(255, 255, 255, 0.15);
    margin-bottom: 1rem;
}

.join-arrow {
    font-size: 1rem;
    color: var(--text-faint);
    margin: 0 0.25rem;
    margin-bottom: 1rem;
}

/* Join Stats */
.join-stats {
    display: flex;
    justify-content: center;
    gap: 3rem;
    margin-bottom: 2.5rem;
}

.join-stat {
    text-align: center;
}

.join-stat-value {
    font-family: 'Chakra Petch', sans-serif;
    font-weight: 700;
    font-size: 2rem;
    color: #fff;
    display: block;
}

.join-stat-label {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.55rem;
    color: var(--text-faint);
    letter-spacing: 0.1em;
    display: block;
    margin-top: 0.25rem;
}

.join-status {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.72rem;
    color: var(--thread-c);
    letter-spacing: 0.1em;
    opacity: 0.8;
}

/* ================================
   FADE IN ANIMATIONS
   ================================ */
.fade-in {
    opacity: 0;
    transform: translateY(16px);
    transition: opacity 0.7s ease, transform 0.7s ease;
}

.fade-in.visible {
    opacity: 1;
    transform: translateY(0);
}

/* Sync barrier flash animation */
.sync-barrier.flash {
    animation: barrierFlash 0.6s ease;
}

@keyframes barrierFlash {
    0% { background: transparent; }
    30% { background: rgba(255, 215, 64, 0.12); }
    100% { background: transparent; }
}

.sync-danger.flash {
    animation: dangerFlash 0.6s ease;
}

@keyframes dangerFlash {
    0% { background: transparent; }
    30% { background: rgba(255, 23, 68, 0.12); }
    100% { background: transparent; }
}

.sync-final.flash {
    animation: finalFlash 0.8s ease;
}

@keyframes finalFlash {
    0% { background: transparent; }
    30% { background: rgba(255, 255, 255, 0.08); }
    100% { background: transparent; }
}

/* ================================
   RESPONSIVE
   ================================ */
@media (max-width: 900px) {
    .thread-grid {
        grid-template-columns: 1fr;
        gap: 1px;
    }

    .ct-b, .ct-c {
        margin-left: 0;
    }

    .hero-status {
        flex-direction: column;
        align-items: center;
        gap: 0.5rem;
    }

    .join-stats {
        flex-wrap: wrap;
        gap: 1.5rem;
    }

    .join-trails {
        flex-wrap: wrap;
    }
}

@media (max-width: 480px) {
    .brand {
        font-size: clamp(2.5rem, 12vw, 3.5rem);
    }

    .thread {
        padding: 1rem;
    }

    .contention-zone {
        padding: 1rem;
    }

    .join-section {
        padding: 3rem 1rem 4rem;
    }
}
