/* ============================================
   concurrent.quest - Crystal Lattice Experience
   ============================================ */

/* CSS Custom Properties */
:root {
    --bg: #08080e;
    --lattice-chrome: #c0c0c8;
    --text-primary: #b8b8c8;
    --accent-spawn: #7070ff;
    --accent-diverge: #ff70b8;
    --accent-contend: #70ffc8;
    --accent-sync: #ffd070;
    --highlight: #ffffff;
    --chrome-light: #e8e8f0;
    --chrome-dark: #8888a0;
    --phase-color: #7070ff;
    --lattice-angle: 0deg;
    --scroll: 0;
    --ease-decel: cubic-bezier(0.23, 1, 0.32, 1);
}

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

html {
    scroll-behavior: smooth;
}

body {
    background: var(--bg);
    color: var(--text-primary);
    font-family: 'Nunito Sans', sans-serif;
    font-weight: 300;
    font-size: clamp(1rem, 1.8vw, 1.25rem);
    line-height: 1.9;
    overflow-x: hidden;
    min-height: 500vh;
}

/* ============================================
   Chrome Reflections
   ============================================ */
#chrome-reflections {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
    overflow: hidden;
}

#chrome-reflections::before {
    content: '';
    position: absolute;
    top: -200%;
    left: 0;
    width: 100%;
    height: 400%;
    background: repeating-linear-gradient(
        0deg,
        transparent 0px,
        transparent 120px,
        rgba(255, 255, 255, 0.04) 120px,
        rgba(255, 255, 255, 0.06) 140px,
        transparent 140px,
        transparent 300px,
        rgba(255, 255, 255, 0.03) 300px,
        rgba(255, 255, 255, 0.05) 315px,
        transparent 315px
    );
    animation: chrome-drift 25s linear infinite;
    will-change: transform;
}

@keyframes chrome-drift {
    0% { transform: translateY(0); }
    100% { transform: translateY(50%); }
}

/* ============================================
   Crystal Lattice SVG
   ============================================ */
#crystal-lattice {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 1;
    pointer-events: none;
}

#lattice-group {
    transform-origin: center;
    will-change: transform;
}

#lattice-edges line {
    stroke: var(--lattice-chrome);
    stroke-width: 0.5;
    opacity: 0.3;
    transition: stroke-width 0.3s ease, opacity 0.5s ease;
}

#lattice-edges line.pulse {
    stroke-width: 1.5;
    opacity: 0.6;
}

#lattice-vertices circle {
    fill: var(--phase-color);
    opacity: 0.6;
    transition: opacity 0.5s ease, r 0.3s ease;
}

#lattice-vertices circle.glow {
    opacity: 1;
}

#lattice-vertices .vertex-halo {
    opacity: 0.3;
    transition: opacity 0.5s ease;
}

/* Thread Traces */
.thread-trace {
    fill: none;
    stroke-width: 1;
    stroke-linecap: round;
    opacity: 0.7;
}

.thread-trace-a {
    stroke: var(--accent-spawn);
    stroke-dasharray: 20 80;
    animation: trace-move-a 8s linear infinite;
}

.thread-trace-b {
    stroke: var(--accent-diverge);
    stroke-dasharray: 15 85;
    animation: trace-move-b 6s linear infinite;
}

.thread-trace-c {
    stroke: var(--accent-contend);
    stroke-dasharray: 25 75;
    animation: trace-move-c 10s linear infinite;
}

@keyframes trace-move-a {
    0% { stroke-dashoffset: 0; }
    100% { stroke-dashoffset: -200; }
}

@keyframes trace-move-b {
    0% { stroke-dashoffset: 0; }
    100% { stroke-dashoffset: -200; }
}

@keyframes trace-move-c {
    0% { stroke-dashoffset: 0; }
    100% { stroke-dashoffset: -200; }
}

/* Sync Burst Effect */
.sync-burst {
    fill: none;
    stroke: var(--phase-color);
    stroke-width: 2;
    opacity: 0;
    animation: burst 0.8s var(--ease-decel) forwards;
}

@keyframes burst {
    0% { r: 0; opacity: 0.8; stroke-width: 2; }
    100% { r: 20; opacity: 0; stroke-width: 0.5; }
}

/* ============================================
   Navigation Diamond
   ============================================ */
#nav-diamond {
    position: fixed;
    top: 24px;
    left: 24px;
    z-index: 100;
    cursor: pointer;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: diamond-pulse 3s ease-in-out infinite;
}

#nav-diamond svg polygon {
    transition: stroke 0.3s ease, fill 0.3s ease;
}

#nav-diamond:hover svg polygon {
    stroke: var(--highlight);
    fill: rgba(192, 192, 200, 0.1);
}

@keyframes diamond-pulse {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

#radial-menu {
    position: fixed;
    top: 24px;
    left: 24px;
    z-index: 99;
    width: 0;
    height: 0;
    transition: opacity 0.4s var(--ease-decel);
}

#radial-menu.hidden {
    opacity: 0;
    pointer-events: none;
}

#radial-menu.visible {
    opacity: 1;
    pointer-events: auto;
}

.radial-item {
    position: absolute;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.7rem;
    font-weight: 400;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    text-decoration: none;
    color: var(--color);
    padding: 6px 12px;
    border: 1px solid currentColor;
    border-radius: 2px;
    background: rgba(8, 8, 14, 0.85);
    white-space: nowrap;
    transform: translate(-50%, -50%) rotate(0deg);
    transition: transform 0.5s var(--ease-decel), opacity 0.4s ease, background 0.3s ease;
    opacity: 0;
}

#radial-menu.visible .radial-item {
    opacity: 1;
}

.radial-item:hover {
    background: rgba(192, 192, 200, 0.15);
}

/* Radial positions */
#radial-menu.visible .radial-item:nth-child(1) { transform: translate(60px, 10px); }
#radial-menu.visible .radial-item:nth-child(2) { transform: translate(90px, 50px); }
#radial-menu.visible .radial-item:nth-child(3) { transform: translate(60px, 90px); }
#radial-menu.visible .radial-item:nth-child(4) { transform: translate(0px, 110px); }
#radial-menu.visible .radial-item:nth-child(5) { transform: translate(-30px, 60px); }

/* ============================================
   Crystallographic Labels
   ============================================ */
#crystal-labels {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
    pointer-events: none;
}

.crystal-label {
    position: absolute;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.6rem;
    font-weight: 400;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: #7070ff;
    opacity: 0;
    animation: label-breathe 8s ease-in-out infinite;
}

.crystal-label:nth-child(2) { animation-delay: -1s; }
.crystal-label:nth-child(3) { animation-delay: -2s; }
.crystal-label:nth-child(4) { animation-delay: -3s; }
.crystal-label:nth-child(5) { animation-delay: -4s; }
.crystal-label:nth-child(6) { animation-delay: -5s; }
.crystal-label:nth-child(7) { animation-delay: -6s; }
.crystal-label:nth-child(8) { animation-delay: -7s; }

@keyframes label-breathe {
    0%, 100% { opacity: 0; }
    30%, 70% { opacity: 0.2; }
}

/* ============================================
   Phase Indicators
   ============================================ */
.phase-indicator {
    position: sticky;
    top: 24px;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 16px;
    padding-left: 80px;
    pointer-events: none;
}

.phase-label {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.75rem;
    font-weight: 400;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--phase-color);
    opacity: 0.6;
}

.phase-name {
    font-family: 'Orbitron', sans-serif;
    font-size: clamp(0.9rem, 2vw, 1.2rem);
    font-weight: 700;
    letter-spacing: 0.4em;
    text-transform: uppercase;
    background: linear-gradient(180deg, var(--chrome-light), var(--chrome-dark));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* ============================================
   Content Main
   ============================================ */
#content {
    position: relative;
    z-index: 3;
}

.phase {
    min-height: 100vh;
    position: relative;
    display: flex;
    flex-direction: column;
}

/* SPAWN Phase */
#spawn {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.spawn-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 0 24px;
    min-height: 80vh;
}

.title {
    font-family: 'Orbitron', sans-serif;
    font-size: clamp(2.5rem, 6vw, 5rem);
    font-weight: 700;
    letter-spacing: 0.4em;
    text-transform: uppercase;
    margin-bottom: 2rem;
    line-height: 1.2;
}

.chrome-text {
    background: linear-gradient(180deg, #e8e8f0, #8888a0);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.haiku {
    max-width: 500px;
    margin-bottom: 3rem;
}

.haiku p {
    font-family: 'Nunito Sans', sans-serif;
    font-weight: 300;
    font-size: clamp(1.1rem, 2vw, 1.4rem);
    line-height: 2.2;
    color: #b8b8c8;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 1s var(--ease-decel), transform 1s var(--ease-decel);
}

.haiku p.visible {
    opacity: 1;
    transform: translateY(0);
}

.haiku p:nth-child(1) { transition-delay: 0.2s; }
.haiku p:nth-child(2) { transition-delay: 0.6s; }
.haiku p:nth-child(3) { transition-delay: 1.0s; }

.origin-node {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--accent-spawn);
    box-shadow: 0 0 30px var(--accent-spawn), 0 0 60px rgba(112, 112, 255, 0.3);
    animation: origin-pulse 2s ease-in-out infinite;
}

@keyframes origin-pulse {
    0%, 100% { transform: scale(1); box-shadow: 0 0 30px var(--accent-spawn), 0 0 60px rgba(112, 112, 255, 0.3); }
    50% { transform: scale(1.5); box-shadow: 0 0 50px var(--accent-spawn), 0 0 100px rgba(112, 112, 255, 0.5); }
}

/* DIVERGE Phase */
#diverge {
    min-height: 120vh;
    padding: 10vh 0;
}

.diverge-content {
    padding: 5vh 24px;
    flex: 1;
}

.parallel-columns {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 40px;
    max-width: 1200px;
    margin: 0 auto;
    padding: 4rem 0;
}

.timeline-column {
    padding: 2rem;
    border-left: 1px solid rgba(192, 192, 200, 0.15);
    will-change: transform;
}

.column-title {
    font-family: 'Orbitron', sans-serif;
    font-size: clamp(1rem, 2vw, 1.5rem);
    font-weight: 700;
    letter-spacing: 0.3em;
    text-transform: uppercase;
    margin-bottom: 1.5rem;
}

.timeline-column p {
    margin-bottom: 1.5rem;
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 0.8s var(--ease-decel), transform 0.8s var(--ease-decel);
}

.timeline-column p.visible {
    opacity: 1;
    transform: translateY(0);
}

/* CONTEND Phase */
#contend {
    min-height: 120vh;
    padding: 10vh 0;
}

.contend-content {
    padding: 5vh 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 80vh;
}

.collision-zone {
    position: relative;
    width: 100%;
    max-width: 900px;
    min-height: 400px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 4rem;
}

.collision-block {
    position: absolute;
    width: 45%;
    padding: 3rem;
    background: rgba(8, 8, 14, 0.6);
    border: 1px solid rgba(192, 192, 200, 0.2);
    transition: transform 1.5s var(--ease-decel);
}

.collision-block h2 {
    font-family: 'Orbitron', sans-serif;
    font-size: clamp(0.9rem, 1.8vw, 1.3rem);
    font-weight: 700;
    letter-spacing: 0.3em;
    text-transform: uppercase;
    margin-bottom: 1rem;
}

.block-a {
    transform: translateX(-30vw);
    mix-blend-mode: difference;
}

.block-a h2 {
    color: #7070ff;
}

.block-b {
    transform: translateX(30vw);
    mix-blend-mode: difference;
}

.block-b h2 {
    color: #ff70b8;
}

.collision-block.colliding {
    transform: translateX(0);
}

.interference-pattern {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    opacity: 0;
    transition: opacity 1s ease;
    background:
        radial-gradient(ellipse at 30% 40%, rgba(112, 112, 255, 0.3) 0%, transparent 70%),
        radial-gradient(ellipse at 70% 60%, rgba(255, 112, 184, 0.3) 0%, transparent 70%);
    mix-blend-mode: difference;
}

.interference-pattern.active {
    opacity: 1;
}

.mutex-block {
    text-align: center;
    max-width: 600px;
    opacity: 0;
    transform: translateY(60px);
    transition: opacity 1.2s var(--ease-decel), transform 1.2s var(--ease-decel);
}

.mutex-block.visible {
    opacity: 1;
    transform: translateY(0);
}

.mutex-line {
    height: 1px;
    background: linear-gradient(90deg, transparent, #70ffc8, transparent);
    margin: 1.5rem 0;
}

.mutex-text {
    font-family: 'Nunito Sans', sans-serif;
    font-weight: 600;
    color: #70ffc8;
    font-size: clamp(0.95rem, 1.6vw, 1.15rem);
    line-height: 1.9;
}

/* SYNCHRONIZE Phase */
#synchronize {
    min-height: 80vh;
    padding: 10vh 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.sync-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 5vh 24px;
    min-height: 60vh;
}

.convergence-block {
    max-width: 700px;
    text-align: center;
    opacity: 0;
    transform: scale(0.9);
    transition: opacity 1.5s var(--ease-decel), transform 1.5s var(--ease-decel);
}

.convergence-block.visible {
    opacity: 1;
    transform: scale(1);
}

.sync-title {
    font-family: 'Orbitron', sans-serif;
    font-size: clamp(1.8rem, 4vw, 3rem);
    font-weight: 700;
    letter-spacing: 0.4em;
    text-transform: uppercase;
    margin-bottom: 2rem;
}

.convergence-block p {
    margin-bottom: 1.5rem;
    color: #b8b8c8;
    line-height: 1.9;
}

/* RESOLVE Phase */
#resolve {
    min-height: 80vh;
    padding: 10vh 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.resolve-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 5vh 24px;
    text-align: center;
    min-height: 60vh;
}

.resolution-text {
    max-width: 650px;
    opacity: 0;
    transition: opacity 2s var(--ease-decel);
}

.resolution-text.visible {
    opacity: 1;
}

.final-statement {
    font-family: 'Nunito Sans', sans-serif;
    font-weight: 300;
    font-size: clamp(1.1rem, 2vw, 1.4rem);
    line-height: 2;
    color: #ffffff;
    opacity: 0;
    animation: none;
}

.final-statement.pulse {
    animation: final-pulse 2s var(--ease-decel) forwards;
}

@keyframes final-pulse {
    0% { opacity: 0; }
    50% { opacity: 1; text-shadow: 0 0 30px rgba(255,255,255,0.5); }
    100% { opacity: 1; text-shadow: none; }
}

.singularity {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #ffffff;
    margin-top: 3rem;
    box-shadow: 0 0 20px #ffffff, 0 0 40px rgba(255,255,255,0.3);
    opacity: 0;
    transition: opacity 2s ease;
}

.singularity.visible {
    opacity: 1;
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 768px) {
    .parallel-columns {
        grid-template-columns: 1fr;
        gap: 20px;
    }

    .timeline-column {
        padding: 1.5rem;
    }

    .collision-block {
        width: 80%;
        position: relative;
    }

    .block-a {
        transform: translateY(-20px);
    }

    .block-b {
        transform: translateY(20px);
    }

    .collision-block.colliding {
        transform: translateY(0);
    }

    .collision-zone {
        flex-direction: column;
        gap: 0;
    }

    .phase-indicator {
        padding-left: 24px;
    }

    .title {
        letter-spacing: 0.2em;
    }

    .radial-item {
        font-size: 0.6rem;
    }
}

/* ============================================
   Phase Transition Background
   ============================================ */
body.phase-resolve {
    background: #000000;
    transition: background 2s ease;
}

/* Lattice opacity transitions per phase */
body.phase-synchronize #lattice-edges line {
    opacity: 0.7;
    stroke-width: 1;
}

body.phase-resolve #crystal-lattice {
    opacity: 0;
    transition: opacity 3s ease;
}
