/* concurrengine.com - Concurrent Engine HUD */

:root {
    --void-black: #0a0a0f;
    --panel-dark: #12131a;
    --thread-cyan: #00e5ff;
    --mutex-gold: #ffd740;
    --deadlock-red: #ff1744;
    --resolve-green: #69f0ae;
    --signal-white: #e0e0e0;
    --muted-steel: #b0bec5;
    --deep-grid: #1a1c25;
}

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

html {
    scroll-behavior: smooth;
}

body {
    background-color: var(--void-black);
    color: var(--signal-white);
    font-family: 'IBM Plex Sans', sans-serif;
    font-weight: 400;
    font-size: clamp(0.85rem, 1vw, 1rem);
    line-height: 1.7;
    overflow-x: hidden;
    min-height: 100vh;
}

/* Scanlines overlay */
.scanlines {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000;
    opacity: 0;
    transition: opacity 500ms ease;
    background: repeating-linear-gradient(
        to bottom,
        transparent 0px,
        transparent 1px,
        rgba(0, 0, 0, 0.08) 1px,
        rgba(0, 0, 0, 0.08) 2px
    );
}

.scanlines.active {
    opacity: 1;
}

/* Navigation */
.nav-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 36px;
    background: var(--void-black);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    z-index: 100;
}

.nav-line {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 1px;
    width: 0;
    background: rgba(0, 229, 255, 0.15);
    transition: width 400ms ease;
}

.nav-line.active {
    width: 100%;
}

.wordmark {
    font-family: 'Share Tech Mono', monospace;
    font-size: clamp(1.2rem, 2.5vw, 1.8rem);
    font-weight: 400;
    letter-spacing: 0.3em;
    text-transform: uppercase;
}

.wm-char {
    opacity: 0;
    transition: opacity 100ms ease;
    color: var(--signal-white);
}

.wm-char.visible {
    opacity: 1;
}

.wm-cyan {
    color: var(--thread-cyan);
}

.nav-links {
    display: flex;
    gap: 24px;
}

.nav-links a {
    font-family: 'Share Tech Mono', monospace;
    font-size: 11px;
    color: var(--muted-steel);
    text-decoration: none;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    transition: color 300ms ease;
}

.nav-links a:hover {
    color: var(--signal-white);
}

/* HUD Viewport */
.hud-viewport {
    position: relative;
    width: 100vw;
    height: 100vh;
    padding-top: 36px;
    display: grid;
    grid-template-columns: 1fr 1fr 30%;
    grid-template-rows: 55% 1fr;
    grid-template-areas:
        "grid grid eventlog"
        "timeline timeline state";
    gap: 0;
    overflow: hidden;
}

.hud-viewport::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(to bottom, transparent 60%, rgba(10, 10, 15, 0.4));
    pointer-events: none;
    z-index: 1;
}

/* Panels */
.panel {
    background: var(--panel-dark);
    border: 1px solid rgba(0, 229, 255, 0.3);
    position: relative;
    overflow: hidden;
    opacity: 0;
    transition: opacity 300ms ease;
}

.panel.visible {
    opacity: 1;
}

.panel-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-bottom: 1px solid rgba(0, 229, 255, 0.1);
}

.panel-title {
    font-family: 'Chakra Petch', sans-serif;
    font-weight: 600;
    font-size: clamp(0.7rem, 1.2vw, 1rem);
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--muted-steel);
}

/* Status LEDs */
.status-led {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 1px;
    animation: ledPulse 2s ease-in-out infinite alternate;
}

.led-cyan { background: var(--thread-cyan); }
.led-gold { background: var(--mutex-gold); }
.led-green { background: var(--resolve-green); }
.led-red { background: var(--deadlock-red); }

@keyframes ledPulse {
    0% { opacity: 0.6; }
    100% { opacity: 1; }
}

/* Process Grid Panel */
.process-grid-panel {
    grid-area: grid;
}

.process-grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    grid-template-rows: repeat(8, 1fr);
    gap: 2px;
    padding: 12px;
    height: calc(100% - 40px);
}

.grid-cell {
    background: transparent;
    border: 1px dashed rgba(0, 229, 255, 0.15);
    border-radius: 1px;
    transition: background-color 400ms ease-in-out, border-color 400ms ease-in-out;
    will-change: background-color;
}

.grid-cell.running {
    background: var(--thread-cyan);
    border-color: var(--thread-cyan);
}

.grid-cell.waiting {
    background: var(--mutex-gold);
    border-color: var(--mutex-gold);
}

.grid-cell.blocked {
    background: var(--deadlock-red);
    border-color: var(--deadlock-red);
}

.grid-cell.complete {
    background: var(--resolve-green);
    border-color: var(--resolve-green);
}

.grid-cell.idle {
    background: transparent;
    border: 1px dashed rgba(0, 229, 255, 0.15);
}

/* Event Log Panel */
.event-log-panel {
    grid-area: eventlog;
}

.event-log {
    padding: 8px 12px;
    height: calc(100% - 40px);
    overflow-y: auto;
    font-family: 'IBM Plex Mono', monospace;
    font-size: clamp(0.7rem, 0.9vw, 0.85rem);
    line-height: 1.5;
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 229, 255, 0.3) transparent;
}

.event-log::-webkit-scrollbar {
    width: 4px;
}

.event-log::-webkit-scrollbar-track {
    background: transparent;
}

.event-log::-webkit-scrollbar-thumb {
    background: rgba(0, 229, 255, 0.3);
}

.log-entry {
    opacity: 0;
    animation: logFadeIn 300ms ease forwards;
    margin-bottom: 2px;
    white-space: nowrap;
}

.log-entry.dimmed {
    opacity: 0.2;
}

@keyframes logFadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

.log-thread {
    color: var(--thread-cyan);
}

.log-resource {
    color: var(--mutex-gold);
}

.log-error {
    color: var(--deadlock-red);
}

.log-success {
    color: var(--resolve-green);
}

.log-text {
    color: var(--muted-steel);
}

/* Timeline Panel */
.timeline-panel {
    grid-area: timeline;
}

.timeline-container {
    position: relative;
    height: calc(100% - 40px);
    overflow: hidden;
}

.timeline-track {
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 8px 12px;
    position: relative;
    height: 100%;
}

.timeline-bar-row {
    position: relative;
    height: 12px;
    flex-shrink: 0;
}

.timeline-bar {
    position: absolute;
    height: 100%;
    border-radius: 1px;
    opacity: 0.7;
    will-change: transform;
    animation: slideLeft 20s linear infinite;
}

@keyframes slideLeft {
    from { transform: translateX(100vw); }
    to { transform: translateX(-200px); }
}

.timeline-bar.bar-cyan { background: var(--thread-cyan); }
.timeline-bar.bar-gold { background: var(--mutex-gold); }
.timeline-bar.bar-red { background: var(--deadlock-red); }
.timeline-bar.bar-green { background: var(--resolve-green); }

/* State Diagram Panel */
.state-diagram-panel {
    grid-area: state;
}

.state-diagram {
    width: 100%;
    height: calc(100% - 40px);
    padding: 10px;
}

.state-node {
    fill: var(--panel-dark);
    stroke-width: 1.5;
    transition: transform 300ms ease, stroke-width 300ms ease;
}

.state-node-active {
    stroke-width: 2.5;
}

.state-label {
    font-family: 'Chakra Petch', sans-serif;
    font-size: 8px;
    fill: var(--muted-steel);
    text-anchor: middle;
    dominant-baseline: central;
    letter-spacing: 0.05em;
}

.state-arrow {
    fill: none;
    stroke-width: 1;
    stroke-dasharray: 4 3;
    animation: dashFlow 1.5s linear infinite;
}

@keyframes dashFlow {
    to { stroke-dashoffset: -20px; }
}

/* Thread Traces SVG */
.thread-traces {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 2;
}

.thread-trace {
    fill: none;
    stroke: rgba(0, 229, 255, 0.4);
    stroke-width: 1;
    stroke-dasharray: 6 4;
    animation: traceFlow 3s linear infinite;
}

@keyframes traceFlow {
    to { stroke-dashoffset: -200px; }
}

/* Deep Dive Section */
.deep-dive {
    position: relative;
    padding: 60px 40px;
    max-width: 1000px;
    margin: 0 auto;
}

/* Bus Lines */
.bus-line {
    width: 100%;
    height: 1px;
    margin: 40px 0;
    position: relative;
    overflow: hidden;
}

.bus-line::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 200%;
    height: 1px;
    background: repeating-linear-gradient(
        to right,
        rgba(0, 229, 255, 0.2) 0px,
        rgba(0, 229, 255, 0.2) 8px,
        transparent 8px,
        transparent 12px
    );
    animation: busScroll 2s linear infinite;
}

@keyframes busScroll {
    to { transform: translateX(-12px); }
}

/* Chapters */
.chapter {
    padding: 40px 0;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 600ms ease, transform 600ms ease;
}

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

.chapter-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
}

.chapter-title {
    font-family: 'Chakra Petch', sans-serif;
    font-weight: 600;
    font-size: clamp(0.9rem, 1.5vw, 1.2rem);
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--signal-white);
}

.chapter-body {
    color: var(--muted-steel);
    font-size: clamp(0.85rem, 1vw, 1rem);
    line-height: 1.7;
    margin-bottom: 24px;
    max-width: 700px;
}

.chapter-illustration {
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
}

.chapter-svg {
    width: 100%;
    height: auto;
}

/* Chapter SVG animations */
.thread-line {
    stroke-dasharray: 200;
    stroke-dashoffset: 200;
    transition: stroke-dashoffset 1s ease;
}

.chapter.visible .thread-line {
    stroke-dashoffset: 0;
}

.mutex-line {
    stroke-dasharray: 200;
    stroke-dashoffset: 200;
    transition: stroke-dashoffset 1s ease;
}

.chapter.visible .mutex-line {
    stroke-dashoffset: 0;
}

.converge-line {
    stroke-dasharray: 200;
    stroke-dashoffset: 200;
    transition: stroke-dashoffset 1.2s ease;
}

.chapter.visible .converge-line {
    stroke-dashoffset: 0;
}

.deadlock-node {
    stroke-dasharray: 130;
    stroke-dashoffset: 130;
    transition: stroke-dashoffset 1s ease;
}

.chapter.visible .deadlock-node {
    stroke-dashoffset: 0;
}

.deadlock-arrow {
    stroke-dasharray: 100;
    stroke-dashoffset: 100;
    transition: stroke-dashoffset 0.8s ease 0.5s;
}

.chapter.visible .deadlock-arrow {
    stroke-dashoffset: 0;
}

.event-loop-ring {
    animation: dashFlow 2s linear infinite;
}

.event-task {
    opacity: 0;
    transition: opacity 600ms ease;
}

.chapter.visible .event-task {
    opacity: 0.8;
}

/* Responsive */
@media (max-width: 768px) {
    .hud-viewport {
        grid-template-columns: 1fr;
        grid-template-rows: 50vh 30vh 30vh 30vh;
        grid-template-areas:
            "grid"
            "eventlog"
            "timeline"
            "state";
        height: auto;
        min-height: 100vh;
    }

    .nav-links {
        display: none;
    }

    .deep-dive {
        padding: 40px 20px;
    }
}
