/* ========================================
   ConcEngine.net - Styles
   Palette: Dopamine Neon
   ======================================== */

/* --- CSS Custom Properties --- */
:root {
    --void-black: #0a0a0f;
    --deep-circuit: #12121f;
    --terminal-green: #00ff41;
    --deadlock-red: #ff003c;
    --thread-cyan: #00e5ff;
    --mutex-magenta: #ff00ff;
    --phosphor-white: #e0ffe0;
    --dim-register: #7a8a7a;
    --overload-yellow: #ffff00;
    --grid-gap: 3px;
}

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

html {
    scroll-behavior: smooth;
    overflow-x: hidden;
}

body {
    background-color: var(--void-black);
    color: var(--phosphor-white);
    font-family: 'Exo 2', sans-serif;
    font-weight: 300;
    font-size: clamp(0.95rem, 1.2vw, 1.15rem);
    line-height: 1.65;
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
}

/* --- Noise Texture (CSS-generated) --- */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000;
    opacity: 0.04;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='1'/%3E%3C/svg%3E");
    background-repeat: repeat;
    background-size: 128px 128px;
}

/* --- Scanline Overlay --- */
#scanlines {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 999;
    background: repeating-linear-gradient(
        transparent 0px,
        transparent 2px,
        rgba(0, 0, 0, 0.08) 2px,
        rgba(0, 0, 0, 0.08) 4px
    );
}

/* --- Boot Overlay --- */
#boot-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--void-black);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    transition: opacity 0.3s ease;
}

#boot-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

#power-rail {
    width: 0;
    height: 1px;
    background: var(--terminal-green);
    box-shadow: 0 0 10px var(--terminal-green), 0 0 30px var(--terminal-green);
    transition: width 0.8s ease-out;
    position: absolute;
    top: 50%;
    left: 0;
}

#power-rail.active {
    width: 100%;
}

#bios-text {
    position: absolute;
    top: 40px;
    left: 40px;
    font-family: 'Share Tech Mono', monospace;
    font-size: 14px;
    color: var(--terminal-green);
    white-space: pre-line;
    line-height: 1.8;
    text-shadow: 0 0 6px var(--terminal-green);
}

#bios-text .bios-line {
    display: block;
    opacity: 0;
    transform: translateY(2px);
    transition: opacity 0.1s, transform 0.1s;
}

#bios-text .bios-line.visible {
    opacity: 1;
    transform: translateY(0);
}

/* --- PID Label --- */
#pid-label {
    position: fixed;
    top: 12px;
    left: 12px;
    font-family: 'Share Tech Mono', monospace;
    font-size: 12px;
    color: var(--terminal-green);
    text-decoration: none;
    z-index: 900;
    letter-spacing: 0.1em;
    text-shadow: 0 0 8px var(--terminal-green);
    opacity: 0;
    transition: opacity 0.5s;
}

#pid-label.visible {
    opacity: 1;
}

#pid-label:hover {
    color: var(--mutex-magenta);
    text-shadow: 0 0 8px var(--mutex-magenta);
}

/* --- Scroll Timeline --- */
#scroll-timeline {
    position: fixed;
    bottom: 0;
    left: 0;
    height: 2px;
    width: 0%;
    background: var(--deadlock-red);
    box-shadow: 0 0 6px var(--deadlock-red);
    z-index: 900;
    transition: width 0.1s linear;
}

/* --- Circuit Traces SVG --- */
#circuit-traces {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
    opacity: 0;
    transition: opacity 0.8s ease;
}

#circuit-traces.visible {
    opacity: 1;
}

.trace {
    fill: none;
    stroke: var(--terminal-green);
    stroke-width: 1;
    opacity: 0.2;
    stroke-dasharray: 8 4;
    transition: opacity 0.3s;
}

.trace.active {
    opacity: 0.8;
    animation: traceFlow 1.5s linear infinite;
}

.trace-node {
    fill: var(--terminal-green);
    opacity: 0.3;
    transition: opacity 0.3s;
}

.trace-node.active {
    opacity: 1;
}

@keyframes traceFlow {
    from { stroke-dashoffset: 0; }
    to { stroke-dashoffset: -24; }
}

/* --- Bento Grid --- */
#bento-grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    grid-template-rows: repeat(8, 1fr);
    gap: var(--grid-gap);
    padding: var(--grid-gap);
    min-height: 100vh;
    width: 100%;
    position: relative;
    z-index: 10;
    opacity: 0;
    transition: opacity 0.5s ease;
}

#bento-grid.visible {
    opacity: 1;
}

/* --- Panel Base --- */
.panel {
    background: var(--void-black);
    border: 1px solid var(--terminal-green);
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    opacity: 0;
    transform: scale(0.98);
    transition: opacity 0.4s ease, transform 0.4s ease, border-color 0.15s;
}

.panel.visible {
    opacity: 1;
    transform: scale(1);
}

.panel:hover {
    background: var(--deep-circuit);
    border-color: var(--mutex-magenta);
}

/* Panel border pulse - using prime number durations */
#panel-hero { animation: borderPulse 2.3s ease-in-out infinite; }
#panel-queue { animation: borderPulse 3.7s ease-in-out infinite; }
#panel-mutex { animation: borderPulse 5.1s ease-in-out infinite; }
#panel-architecture { animation: borderPulse 7.3s ease-in-out infinite; }
#panel-metrics { animation: borderPulse 11.1s ease-in-out infinite; }
#panel-info { animation: borderPulse 2.9s ease-in-out infinite; }
#panel-threadcount { animation: borderPulse 4.3s ease-in-out infinite; }

@keyframes borderPulse {
    0%, 100% { border-color: var(--terminal-green); }
    50% { border-color: rgba(0, 255, 65, 0.3); }
}

/* --- Panel Grid Positions --- */
#panel-hero {
    grid-column: 1 / 9;
    grid-row: 1 / 5;
}

#panel-queue {
    grid-column: 9 / 13;
    grid-row: 1 / 4;
}

#panel-mutex {
    grid-column: 9 / 13;
    grid-row: 4 / 5;
}

#panel-architecture {
    grid-column: 1 / 5;
    grid-row: 5 / 9;
}

#panel-metrics {
    grid-column: 5 / 9;
    grid-row: 5 / 9;
}

#panel-info {
    grid-column: 9 / 13;
    grid-row: 5 / 7;
}

#panel-threadcount {
    grid-column: 9 / 13;
    grid-row: 7 / 9;
}

/* --- Panel Header --- */
.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    border-bottom: 1px solid rgba(0, 255, 65, 0.15);
    flex-shrink: 0;
}

.panel-pid {
    font-family: 'Share Tech Mono', monospace;
    font-size: 10px;
    color: var(--dim-register);
    letter-spacing: 0.08em;
}

.panel-status {
    font-family: 'Share Tech Mono', monospace;
    font-size: 9px;
    padding: 2px 6px;
    letter-spacing: 0.1em;
}

.status-active {
    color: var(--terminal-green);
    border: 1px solid rgba(0, 255, 65, 0.3);
}

.status-locked {
    color: var(--deadlock-red);
    border: 1px solid rgba(255, 0, 60, 0.3);
    animation: statusBlink 1.5s step-end infinite;
}

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

/* --- Panel Content --- */
.panel-content {
    padding: 16px;
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* --- Panel Title --- */
.panel-title {
    font-family: 'Orbitron', sans-serif;
    font-weight: 700;
    font-size: clamp(1rem, 2vw, 1.4rem);
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--phosphor-white);
    margin-bottom: 12px;
    position: relative;
}

/* --- Glitch Effect for Titles --- */
.panel-title::before,
.panel-title::after {
    content: attr(data-text);
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    opacity: 0;
}

.panel-title::before {
    color: var(--deadlock-red);
    z-index: -1;
}

.panel-title::after {
    color: var(--thread-cyan);
    z-index: -1;
}

.panel-title.glitching::before {
    opacity: 0.8;
    animation: glitchLeft 150ms steps(2) forwards;
}

.panel-title.glitching::after {
    opacity: 0.8;
    animation: glitchRight 150ms steps(2) forwards;
}

@keyframes glitchLeft {
    0% { transform: translateX(-2px); clip-path: inset(0 0 60% 0); }
    50% { transform: translateX(3px); clip-path: inset(40% 0 0 0); }
    100% { transform: translateX(0); clip-path: inset(0); opacity: 0; }
}

@keyframes glitchRight {
    0% { transform: translateX(2px); clip-path: inset(60% 0 0 0); }
    50% { transform: translateX(-3px); clip-path: inset(0 0 40% 0); }
    100% { transform: translateX(0); clip-path: inset(0); opacity: 0; }
}

/* --- Hero Panel --- */
.hero-content {
    justify-content: center;
    align-items: center;
    text-align: center;
    position: relative;
}

.hero-title {
    font-family: 'Orbitron', sans-serif;
    font-weight: 900;
    font-size: clamp(2rem, 5vw, 5rem);
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--phosphor-white);
    line-height: 1.15;
    text-shadow: 0 0 20px rgba(0, 255, 65, 0.3);
    position: relative;
    z-index: 2;
}

/* Subtle continuous RGB split on hero */
.hero-title::before,
.hero-title::after {
    content: attr(data-text);
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.hero-title::before {
    color: var(--deadlock-red);
    z-index: -1;
    opacity: 0.5;
    animation: heroGlitchR 8s ease-in-out infinite;
}

.hero-title::after {
    color: var(--thread-cyan);
    z-index: -1;
    opacity: 0.5;
    animation: heroGlitchB 8s ease-in-out infinite;
}

@keyframes heroGlitchR {
    0%, 90%, 100% { transform: translate(0, 0); }
    92% { transform: translate(-1px, 0); }
    94% { transform: translate(1px, 1px); }
    96% { transform: translate(-1px, -1px); }
    98% { transform: translate(1px, 0); }
}

@keyframes heroGlitchB {
    0%, 90%, 100% { transform: translate(0, 0); }
    91% { transform: translate(1px, 0); }
    93% { transform: translate(-1px, -1px); }
    95% { transform: translate(1px, 1px); }
    97% { transform: translate(-1px, 0); }
}

/* --- Thread Visualizer --- */
.thread-visualizer {
    position: absolute;
    bottom: 16px;
    left: 16px;
    right: 16px;
    height: 80px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    overflow: hidden;
}

.thread-line {
    height: 2px;
    width: 0;
    border-radius: 1px;
    animation: threadRun var(--speed) linear infinite;
    animation-delay: var(--delay);
    position: relative;
}

.thread-green {
    background: var(--terminal-green);
    box-shadow: 0 0 4px var(--terminal-green);
}

.thread-cyan {
    background: var(--thread-cyan);
    box-shadow: 0 0 4px var(--thread-cyan);
}

.thread-magenta {
    background: var(--mutex-magenta);
    box-shadow: 0 0 4px var(--mutex-magenta);
}

@keyframes threadRun {
    0% { width: 0; margin-left: 0; opacity: 0; }
    5% { opacity: 1; }
    40% { width: 60%; }
    60% { width: 60%; }
    70% { width: 30%; }
    95% { opacity: 1; }
    100% { width: 100%; margin-left: 0; opacity: 0; }
}

/* --- Thread Queue Panel --- */
.queue-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
    overflow: hidden;
}

.queue-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 0;
    border-bottom: 1px solid rgba(0, 255, 65, 0.07);
    font-family: 'Share Tech Mono', monospace;
    font-size: 12px;
}

.queue-id {
    color: var(--dim-register);
    min-width: 55px;
}

.queue-state {
    font-size: 9px;
    padding: 1px 5px;
    letter-spacing: 0.08em;
    min-width: 45px;
    text-align: center;
}

.state-run {
    color: var(--terminal-green);
    border: 1px solid rgba(0, 255, 65, 0.3);
}

.state-wait {
    color: var(--overload-yellow);
    border: 1px solid rgba(255, 255, 0, 0.3);
}

.state-block {
    color: var(--deadlock-red);
    border: 1px solid rgba(255, 0, 60, 0.3);
}

.queue-time {
    color: var(--thread-cyan);
    margin-left: auto;
}

/* --- Mutex Panel --- */
.panel-locked:hover {
    animation: microShake 150ms ease;
    border-color: var(--deadlock-red) !important;
}

@keyframes microShake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-2px); }
    75% { transform: translateX(2px); }
}

.mutex-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.mutex-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 8px;
    border: 1px solid rgba(0, 255, 65, 0.1);
}

.mutex-name {
    font-family: 'Share Tech Mono', monospace;
    font-size: 10px;
    color: var(--dim-register);
    letter-spacing: 0.05em;
}

.mutex-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.mutex-item.locked .mutex-indicator {
    background: var(--deadlock-red);
    box-shadow: 0 0 6px var(--deadlock-red);
    animation: indicatorPulse 1.3s ease-in-out infinite;
}

.mutex-item.unlocked .mutex-indicator {
    background: var(--terminal-green);
    box-shadow: 0 0 6px var(--terminal-green);
}

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

/* --- Architecture Panel --- */
.architecture-diagram {
    width: 100%;
    flex: 1;
    max-height: 280px;
}

.event-loop-ring {
    animation: ringRotate 12s linear infinite;
    transform-origin: 180px 140px;
}

@keyframes ringRotate {
    from { stroke-dashoffset: 0; }
    to { stroke-dashoffset: -56.5; }
}

.arch-node {
    animation: nodePulse 2.7s ease-in-out infinite;
}

.arch-node:nth-child(2) { animation-delay: 0.7s; }
.arch-node:nth-child(4) { animation-delay: 1.4s; }
.arch-node:nth-child(6) { animation-delay: 2.1s; }

@keyframes nodePulse {
    0%, 100% { r: 6; opacity: 1; }
    50% { r: 4; opacity: 0.6; }
}

.data-flow {
    animation: dataFlowAnim 3s linear infinite;
}

.data-flow:nth-child(2) { animation-delay: 0.75s; }
.data-flow:nth-child(3) { animation-delay: 1.5s; }
.data-flow:nth-child(4) { animation-delay: 2.25s; }

@keyframes dataFlowAnim {
    from { stroke-dashoffset: 0; }
    to { stroke-dashoffset: -18; }
}

/* --- Metrics Panel --- */
.metrics-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    flex: 1;
    align-content: center;
}

.metric-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.metric-label {
    font-family: 'Orbitron', sans-serif;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.15em;
    color: var(--dim-register);
    text-transform: uppercase;
}

.metric-value {
    font-family: 'Share Tech Mono', monospace;
    font-size: clamp(1.1rem, 2vw, 1.6rem);
    color: var(--thread-cyan);
    text-shadow: 0 0 8px rgba(0, 229, 255, 0.4);
}

/* --- Info Panel --- */
.panel-body {
    font-family: 'Exo 2', sans-serif;
    font-weight: 300;
    color: var(--phosphor-white);
    margin-bottom: 10px;
    font-size: clamp(0.85rem, 1.1vw, 1rem);
}

.panel-body.dim {
    color: var(--dim-register);
    font-size: clamp(0.8rem, 1vw, 0.9rem);
}

/* --- Thread Count Panel --- */
.thread-count-content {
    align-items: center;
    justify-content: center;
    text-align: center;
}

.thread-count-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 12px 0;
}

.thread-count-number {
    font-family: 'Share Tech Mono', monospace;
    font-size: clamp(2.5rem, 5vw, 4rem);
    color: var(--terminal-green);
    text-shadow: 0 0 15px var(--terminal-green), 0 0 30px rgba(0, 255, 65, 0.3);
    line-height: 1;
}

.thread-count-unit {
    font-family: 'Orbitron', sans-serif;
    font-size: 10px;
    letter-spacing: 0.3em;
    color: var(--dim-register);
    margin-top: 4px;
}

.thread-count-bar {
    width: 80%;
    height: 3px;
    background: rgba(0, 255, 65, 0.1);
    margin-top: 10px;
    position: relative;
    overflow: hidden;
}

.thread-count-fill {
    height: 100%;
    width: 80%;
    background: var(--terminal-green);
    box-shadow: 0 0 6px var(--terminal-green);
    transition: width 0.5s ease;
}

/* --- Glitch Band (per-panel buffer corruption) --- */
.panel-glitch-band {
    position: absolute;
    left: 0;
    width: 100%;
    height: 0;
    background: linear-gradient(
        90deg,
        transparent 0%,
        var(--terminal-green) 15%,
        var(--mutex-magenta) 30%,
        var(--thread-cyan) 50%,
        var(--deadlock-red) 70%,
        var(--terminal-green) 85%,
        transparent 100%
    );
    opacity: 0;
    pointer-events: none;
    z-index: 50;
}

.panel-glitch-band.active {
    height: 6px;
    opacity: 0.7;
    animation: glitchBandSweep 200ms linear forwards;
}

@keyframes glitchBandSweep {
    from { top: 0; }
    to { top: 100%; }
}

/* --- Shake Animations --- */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-6px); }
    75% { transform: translateX(6px); }
}

.shake {
    animation: shake 300ms ease !important;
}

.shake-border {
    border-color: var(--overload-yellow) !important;
    box-shadow: 0 0 10px rgba(255, 255, 0, 0.3);
}

/* Viewport shake */
@keyframes viewportShake {
    0%, 100% { transform: translate(0, 0); }
    25% { transform: translate(-1px, 0); }
    50% { transform: translate(1px, -1px); }
    75% { transform: translate(-1px, 1px); }
}

body.viewport-shake {
    animation: viewportShake 200ms ease;
}

body.viewport-shake .panel {
    border-color: var(--deadlock-red) !important;
}

/* --- Mobile Adaptation --- */
@media (max-width: 768px) {
    #bento-grid {
        display: flex;
        flex-direction: column;
        gap: var(--grid-gap);
        padding: var(--grid-gap);
        min-height: auto;
    }

    .panel {
        min-height: 250px;
    }

    #panel-hero {
        min-height: 400px;
    }

    #panel-mutex {
        min-height: 180px;
    }

    .hero-title {
        font-size: clamp(1.6rem, 6vw, 2.8rem);
    }

    .thread-visualizer {
        height: 50px;
    }

    #circuit-traces {
        display: none;
    }

    .metrics-grid {
        grid-template-columns: 1fr;
    }

    .mutex-grid {
        grid-template-columns: 1fr;
    }
}

@media (min-width: 769px) and (max-width: 1023px) {
    #bento-grid {
        grid-template-columns: repeat(6, 1fr);
        grid-template-rows: auto;
    }

    #panel-hero { grid-column: 1 / 7; grid-row: auto; min-height: 350px; }
    #panel-queue { grid-column: 1 / 4; grid-row: auto; min-height: 250px; }
    #panel-mutex { grid-column: 4 / 7; grid-row: auto; min-height: 180px; }
    #panel-architecture { grid-column: 1 / 4; grid-row: auto; min-height: 300px; }
    #panel-metrics { grid-column: 4 / 7; grid-row: auto; min-height: 300px; }
    #panel-info { grid-column: 1 / 4; grid-row: auto; }
    #panel-threadcount { grid-column: 4 / 7; grid-row: auto; }
}

/* --- Selection styling --- */
::selection {
    background: var(--mutex-magenta);
    color: var(--void-black);
}
