/* ===================================================
   concengine.net — Concurrent Event Simulation Engine
   Chrome-metallic HUD with depth-stack navigation
   =================================================== */

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

:root {
    --void-bg: #06080f;
    --panel-bg: #0c1220;
    --panel-bg-alpha: rgba(12, 18, 32, 0.85);
    --phosphor: #3dffc0;
    --amber: #ff9e3d;
    --conflict: #ff4d6a;
    --chrome: #c8d0dc;
    --muted: #5a6a7a;
    --highlight: #a0f0ff;
    --body-text: #b8c4d0;
    --annotation: #7a8a9a;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--void-bg);
    color: var(--body-text);
    font-family: 'IBM Plex Sans', sans-serif;
    font-weight: 400;
    font-size: clamp(0.875rem, 1.2vw, 1.1rem);
    line-height: 1.7;
}

/* --- Grain Overlay --- */
#grain-overlay {
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    z-index: 9999;
    pointer-events: none;
    opacity: 0.03;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
    background-size: 256px 256px;
    animation: grainShift 0.1s steps(1) infinite;
}

@keyframes grainShift {
    0% { transform: translate(0, 0); }
    25% { transform: translate(-2px, 3px); }
    50% { transform: translate(3px, -1px); }
    75% { transform: translate(-1px, -3px); }
    100% { transform: translate(2px, 1px); }
}

/* --- Scan Line Drift --- */
#scan-line {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 1px;
    background: var(--phosphor);
    opacity: 0.08;
    z-index: 9998;
    pointer-events: none;
    animation: scanDrift 12s linear infinite;
}

#scan-line.flash {
    opacity: 0.2;
    transition: opacity 0.1s;
}

@keyframes scanDrift {
    0% { top: 0; }
    100% { top: 100%; }
}

/* --- Coordinate Ghost --- */
#coord-ghost {
    position: fixed;
    pointer-events: none;
    z-index: 9997;
    font-family: 'IBM Plex Mono', monospace;
    font-size: clamp(0.75rem, 1vw, 0.95rem);
    letter-spacing: 0.04em;
    color: var(--muted);
    opacity: 0;
    transition: opacity 0.3s ease;
    white-space: nowrap;
}

#coord-ghost.visible {
    opacity: 0.5;
}

/* --- Waypoint Navigation --- */
#waypoints {
    position: fixed;
    left: 24px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 28px;
}

.waypoint {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    opacity: 0.4;
    transition: opacity 0.4s ease;
}

.waypoint.active {
    opacity: 1;
}

.waypoint-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--phosphor);
    box-shadow: 0 0 6px var(--phosphor);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.waypoint.active .waypoint-dot {
    animation: waypointPulse 2s ease-in-out infinite;
    box-shadow: 0 0 12px var(--phosphor);
}

@keyframes waypointPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.4); }
}

.waypoint-label {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.65rem;
    letter-spacing: 0.1em;
    color: var(--muted);
    transition: color 0.3s ease;
}

.waypoint.active .waypoint-label {
    color: var(--phosphor);
}

/* --- Layer Container --- */
#layer-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    perspective: 1200px;
}

/* --- Layers --- */
.layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transform: scale(1.08);
    transition: opacity 0.6s ease, transform 0.6s ease;
    pointer-events: none;
}

.layer-active {
    opacity: 1;
    transform: scale(1);
    pointer-events: auto;
}

.layer-behind {
    opacity: 0.3;
    transform: scale(0.92);
    pointer-events: none;
}

.layer-inner {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: 40px 80px;
}

/* --- Layer Titles --- */
.layer-title {
    font-family: 'Chakra Petch', sans-serif;
    font-weight: 700;
    font-size: clamp(1.8rem, 4vw, 3.5rem);
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--chrome);
    text-shadow: 0 0 8px var(--phosphor);
    margin-bottom: 20px;
}

.layer-subtitle {
    font-family: 'Overpass', sans-serif;
    font-weight: 300;
    font-style: italic;
    font-size: 0.8rem;
    color: var(--annotation);
    opacity: 0;
    transition: opacity 0.8s ease 1.8s;
}

.layer-active .layer-subtitle {
    opacity: 0.7;
}

/* ===================================================
   LAYER 1: EVENT INGESTION
   =================================================== */

/* Radial Lines */
.radial-lines {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    opacity: 0.12;
}

.radial-lines line {
    stroke: var(--phosphor);
    stroke-width: 0.5;
    opacity: 0.4;
}

/* Pulsing Ring */
.pulse-ring {
    width: 180px;
    height: 180px;
    border: 2px solid var(--phosphor);
    border-radius: 50%;
    box-shadow: 0 0 20px rgba(61, 255, 192, 0.2), inset 0 0 20px rgba(61, 255, 192, 0.05);
    animation: pulseRing 2s ease-in-out infinite;
    margin-bottom: 30px;
    opacity: 0;
    transition: opacity 1s ease;
}

.layer-active .pulse-ring {
    opacity: 1;
    transition-delay: 1.2s;
}

@keyframes pulseRing {
    0%, 100% { transform: scale(0.95); }
    50% { transform: scale(1.05); }
}

#title-ingestion {
    overflow: hidden;
    white-space: nowrap;
    border-right: 2px solid var(--phosphor);
    width: 0;
    animation: none;
}

#title-ingestion.typing {
    animation: typewriter 1.2s steps(16) forwards, blinkCursor 0.6s step-end 4;
}

@keyframes typewriter {
    from { width: 0; }
    to { width: 16ch; }
}

@keyframes blinkCursor {
    50% { border-color: transparent; }
}

#title-ingestion.typed {
    width: 16ch;
    border-right-color: transparent;
}

/* ===================================================
   LAYER 2: SCHEDULER
   =================================================== */
.scheduler-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    width: 90%;
    max-width: 1000px;
    margin-top: 20px;
}

.sched-block {
    background: var(--panel-bg-alpha);
    border: 1px solid rgba(61, 255, 192, 0.4);
    padding: 12px;
    position: relative;
    transition: border-color 0.3s ease, transform 0.3s ease, box-shadow 0.3s ease;
    opacity: 0;
    transform: translateY(20px);
}

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

.sched-block:hover {
    border-color: var(--phosphor);
    transform: translateY(-4px);
    box-shadow: 0 0 20px rgba(61, 255, 192, 0.15);
}

.span-2x1 {
    grid-column: span 2;
}

.block-label {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.65rem;
    letter-spacing: 0.08em;
    color: var(--muted);
    margin-bottom: 8px;
    text-transform: uppercase;
}

.block-viz {
    height: 60px;
    display: flex;
    align-items: flex-end;
    gap: 3px;
    overflow: hidden;
    position: relative;
}

/* Priority Queue visualization */
.priority-queue {
    justify-content: center;
}

.pq-bar {
    width: 14%;
    background: var(--phosphor);
    opacity: 0.7;
    height: var(--h);
    animation: pqPulse 2s ease-in-out infinite;
    animation-delay: var(--delay);
}

@keyframes pqPulse {
    0%, 100% { opacity: 0.7; }
    50% { opacity: 0.3; }
}

/* Round Robin */
.round-robin {
    justify-content: center;
    gap: 6px;
    align-items: center;
}

.rr-slot {
    width: 20px;
    height: 20px;
    border: 1px solid var(--phosphor);
    opacity: 0.3;
    transition: opacity 0.3s, background 0.3s;
}

.rr-slot.active {
    background: var(--phosphor);
    opacity: 0.8;
    box-shadow: 0 0 8px var(--phosphor);
}

/* FIFO */
.fifo {
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    justify-content: flex-end;
}

.fifo-item {
    height: 10px;
    background: var(--phosphor);
    opacity: 0.5;
    animation: fifoSlide 2s ease-in-out infinite;
    animation-delay: var(--delay);
}

@keyframes fifoSlide {
    0% { transform: translateX(-100%); opacity: 0; }
    30% { transform: translateX(0); opacity: 0.5; }
    70% { transform: translateX(0); opacity: 0.5; }
    100% { transform: translateX(100%); opacity: 0; }
}

/* Bubble Sort */
.bubble-sort {
    justify-content: center;
    align-items: flex-end;
}

.bs-bar {
    width: 12%;
    background: var(--amber);
    opacity: 0.6;
    height: var(--h);
    animation: bsSwap 3s ease-in-out infinite;
    animation-delay: calc(var(--i) * 0.3s);
}

@keyframes bsSwap {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(100%); }
    50% { transform: translateX(0); }
    75% { transform: translateX(-100%); }
}

/* Weighted Queue */
.weighted-q {
    align-items: center;
    justify-content: center;
}

.wq-ring {
    position: absolute;
    width: 40px;
    height: 40px;
    border: 1px solid var(--phosphor);
    border-radius: 50%;
    opacity: 0.5;
    animation: wqExpand 3s ease-in-out infinite;
}

.wq-ring.r2 {
    animation-delay: 1s;
}

.wq-ring.r3 {
    animation-delay: 2s;
}

@keyframes wqExpand {
    0% { transform: scale(0.5); opacity: 0.8; }
    100% { transform: scale(2); opacity: 0; }
}

/* Dependency Graph */
.dep-graph {
    align-items: center;
    justify-content: center;
}

.dep-graph svg {
    width: 100%;
    height: 100%;
}

.dep-node {
    fill: var(--phosphor);
    opacity: 0.7;
    animation: depPulse 2s ease-in-out infinite;
}

.dep-node.n2 { animation-delay: 0.5s; }
.dep-node.n3 { animation-delay: 1s; }
.dep-node.n4 { animation-delay: 1.5s; }

.dep-edge {
    stroke: var(--phosphor);
    stroke-width: 1;
    opacity: 0.4;
    stroke-dasharray: 60;
    stroke-dashoffset: 60;
    animation: drawEdge 2s ease-out forwards;
}

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

@keyframes depPulse {
    0%, 100% { opacity: 0.7; r: 6; }
    50% { opacity: 1; r: 8; }
}

/* Timer Wheel */
.timer-wheel {
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(61, 255, 192, 0.3);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    margin: 5px auto;
    position: relative;
}

.tw-hand {
    position: absolute;
    width: 1px;
    height: 20px;
    background: var(--phosphor);
    bottom: 50%;
    left: 50%;
    transform-origin: bottom center;
    animation: twSpin 4s linear infinite;
}

@keyframes twSpin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* SJF Queue */
.sjf {
    justify-content: center;
    align-items: flex-end;
}

.sjf-bar {
    width: 14%;
    background: var(--phosphor);
    opacity: 0.5;
    height: var(--h);
}

/* ===================================================
   LAYER 3: EXECUTION ARENA
   =================================================== */
.execution-area {
    width: 100%;
    height: 70%;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.timeline-svg {
    width: 80%;
    max-width: 1000px;
    height: auto;
}

.timeline-path {
    fill: none;
    stroke: var(--phosphor);
    stroke-width: 2;
    opacity: 0.6;
    stroke-dasharray: 1000;
    stroke-dashoffset: 1000;
    transition: stroke-dashoffset 0.8s ease-out;
}

.timeline-path.drawn {
    stroke-dashoffset: 0;
}

.timeline-path.fork-1b,
.timeline-path.fork-1b-cont,
.timeline-path.merge-3,
.timeline-path.final-merge-2 {
    stroke: var(--amber);
}

.timeline-path.fork-2a,
.timeline-path.merge-1 {
    stroke: var(--conflict);
}

.fork-node {
    fill: var(--phosphor);
    opacity: 0;
    transition: opacity 0.4s ease;
}

.fork-node.visible {
    opacity: 1;
    animation: forkPulse 1s ease-out;
}

@keyframes forkPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.5); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}

.merge-node {
    fill: none;
    stroke: var(--phosphor);
    stroke-width: 2;
    opacity: 0;
    transition: opacity 0.4s ease;
}

.merge-node.visible {
    opacity: 0.8;
    animation: mergePulse 1s ease-out;
}

@keyframes mergePulse {
    0% { r: 6; }
    50% { r: 12; }
    100% { r: 6; }
}

.event-dot {
    fill: var(--phosphor);
    opacity: 0;
}

.event-dot.ed-2 {
    fill: var(--amber);
}

.event-dot.ed-3 {
    fill: var(--conflict);
}

/* Execution Cards */
.exec-card {
    position: absolute;
    background: var(--panel-bg-alpha);
    border: 1px solid rgba(61, 255, 192, 0.4);
    padding: 12px 16px;
    min-width: 160px;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.4s ease, transform 0.4s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

.exec-card.visible {
    opacity: 1;
    transform: translateY(0);
}

.exec-card:hover {
    border-color: var(--phosphor);
    box-shadow: 0 0 16px rgba(61, 255, 192, 0.15);
    transform: translateY(-4px);
}

.card-1 { top: 8%; left: 8%; }
.card-2 { top: 12%; right: 8%; }
.card-3 { bottom: 12%; right: 15%; }

.card-top-edge {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
}

.card-top-edge.green { background: var(--phosphor); }
.card-top-edge.amber { background: var(--amber); }
.card-top-edge.red { background: var(--conflict); }

.card-label {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.7rem;
    letter-spacing: 0.06em;
    color: var(--chrome);
    margin-bottom: 8px;
}

.card-data {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.7rem;
    line-height: 1.8;
}

.data-key {
    color: var(--muted);
}

.data-val {
    color: var(--phosphor);
}

.green-text { color: var(--phosphor); }
.amber-text { color: var(--amber); }
.red-text { color: var(--conflict); }

/* ===================================================
   LAYER 4: CONFLICT RESOLUTION
   =================================================== */
.conflict-area {
    width: 100%;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.conflict-split {
    display: flex;
    flex: 1;
    gap: 2px;
}

.conflict-left, .conflict-right {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
}

.conflict-svg {
    width: 100%;
    max-width: 500px;
    height: auto;
}

.conflict-path {
    fill: none;
    stroke: var(--phosphor);
    stroke-width: 2;
    opacity: 0.6;
    stroke-dasharray: 600;
    stroke-dashoffset: 600;
}

.conflict-path.drawn {
    stroke-dashoffset: 0;
    transition: stroke-dashoffset 1.5s ease-out;
}

.conflict-path.path-b {
    stroke: var(--amber);
}

.resource-diamond {
    fill: var(--conflict);
    opacity: 0;
    transition: opacity 0.5s ease;
}

.resource-diamond.pulse-conflict {
    opacity: 1;
    animation: conflictPulse 0.4s ease-in-out 3;
}

@keyframes conflictPulse {
    0%, 100% { fill: var(--conflict); opacity: 1; }
    50% { fill: #ff1a3a; opacity: 0.6; }
}

.resource-diamond.resolved {
    fill: var(--phosphor);
    opacity: 0.8;
}

.resolution-path {
    fill: none;
    stroke: var(--phosphor);
    stroke-width: 2;
    opacity: 0.6;
    stroke-dasharray: 400;
    stroke-dashoffset: 400;
}

.resolution-path.drawn {
    stroke-dashoffset: 0;
    transition: stroke-dashoffset 1s ease-out;
}

.loser-path {
    stroke: var(--muted);
    opacity: 0.3;
}

.conflict-dot {
    fill: var(--phosphor);
    opacity: 0;
}

.conflict-dot.dot-b {
    fill: var(--amber);
}

.resolution-dot {
    opacity: 0;
}

.winner-dot {
    fill: var(--phosphor);
}

.loser-dot {
    fill: var(--muted);
    opacity: 0.3;
}

.pause-icon {
    fill: var(--muted);
    opacity: 0.5;
}

.conflict-label {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.7rem;
    letter-spacing: 0.1em;
    color: var(--muted);
    margin-top: 12px;
    text-transform: uppercase;
}

/* Ticker Stream */
.ticker-container {
    width: 100%;
    height: 36px;
    overflow: hidden;
    background: rgba(12, 18, 32, 0.6);
    border-top: 1px solid rgba(61, 255, 192, 0.2);
    border-bottom: 1px solid rgba(61, 255, 192, 0.2);
    position: relative;
}

.ticker-stream {
    display: flex;
    gap: 40px;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    white-space: nowrap;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.7rem;
    letter-spacing: 0.04em;
    animation: tickerScroll 30s linear infinite;
}

@keyframes tickerScroll {
    from { transform: translateY(-50%) translateX(0); }
    to { transform: translateY(-50%) translateX(-50%); }
}

.ticker-entry {
    display: inline-flex;
    gap: 8px;
}

.ticker-ts { color: var(--muted); }
.ticker-id { color: var(--chrome); }
.ticker-status-ok { color: var(--phosphor); }
.ticker-status-queue { color: var(--amber); }
.ticker-status-conflict { color: var(--conflict); }

/* ===================================================
   LAYER 5: OUTPUT MANIFOLD
   =================================================== */
.output-area {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
}

.sphere-container {
    width: 300px;
    height: 300px;
    perspective: 800px;
    margin-bottom: 30px;
}

.wireframe-sphere {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    animation: sphereRotate 60s linear infinite;
}

@keyframes sphereRotate {
    from { transform: rotateY(0deg) rotateX(15deg); }
    to { transform: rotateY(360deg) rotateX(15deg); }
}

.sphere-ring {
    position: absolute;
    top: 50%;
    left: 50%;
    border: 1px solid var(--phosphor);
    border-radius: 50%;
    opacity: 0.3;
    transform-style: preserve-3d;
}

.sphere-dot {
    position: absolute;
    width: 3px;
    height: 3px;
    background: var(--phosphor);
    border-radius: 50%;
    box-shadow: 0 0 4px var(--phosphor);
    transform-style: preserve-3d;
}

#particle-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.output-stats {
    display: flex;
    gap: 40px;
    flex-wrap: wrap;
    justify-content: center;
    z-index: 10;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.stat-label {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.65rem;
    letter-spacing: 0.08em;
    color: var(--muted);
}

.stat-value {
    font-family: 'Chakra Petch', sans-serif;
    font-weight: 700;
    font-size: clamp(1.2rem, 2.5vw, 2rem);
    color: var(--chrome);
    text-shadow: 0 0 8px var(--phosphor);
}

.final-label {
    font-family: 'Chakra Petch', sans-serif;
    font-weight: 700;
    font-size: clamp(1rem, 2vw, 1.5rem);
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--phosphor);
    text-shadow: 0 0 8px var(--phosphor);
    margin-top: 40px;
    opacity: 0;
    animation: none;
    z-index: 10;
}

.final-label.breathing {
    opacity: 1;
    animation: breathe 4s ease-in-out infinite;
}

@keyframes breathe {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

/* ===================================================
   RESPONSIVE
   =================================================== */
@media (max-width: 768px) {
    #waypoints {
        left: 10px;
        gap: 20px;
    }

    .waypoint-label {
        display: none;
    }

    .layer-inner {
        padding: 20px 30px;
    }

    .scheduler-grid {
        grid-template-columns: repeat(2, 1fr);
        width: 95%;
    }

    .span-2x1 {
        grid-column: span 2;
    }

    .conflict-split {
        flex-direction: column;
    }

    .output-stats {
        gap: 20px;
    }

    .exec-card {
        display: none;
    }
}
