/* ============================================
   conc.quest - Cyberpunk Process Theater
   ============================================ */

/* --- CSS Custom Properties --- */
:root {
    --void-black: #0a0a0f;
    --goroutine-green: #00ff9f;
    --channel-cyan: #00d4ff;
    --mutex-magenta: #ff0080;
    --deadlock-red: #ff2d2d;
    --stack-gray: #8b8fa3;
    --register-white: #e8eaf0;
    --heap-amber: #ffb830;

    --font-display: 'Share Tech Mono', monospace;
    --font-body: 'Exo 2', sans-serif;
    --font-accent: 'Orbitron', sans-serif;
    --font-code: 'Fira Code', monospace;

    --scroll-speed: 30s;
}

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

html {
    scroll-behavior: smooth;
    background: var(--void-black);
}

body {
    font-family: var(--font-body);
    font-weight: 300;
    font-size: clamp(0.95rem, 1.8vw, 1.15rem);
    line-height: 1.75;
    color: var(--stack-gray);
    background: var(--void-black);
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* --- Binary Rain Backdrop --- */
#binary-rain {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    opacity: 0.03;
    overflow: hidden;
}

#binary-rain::before {
    content: "01001101 10110010 01110100 00101010 11010011 01001001 10100110 01110001 00101101 11001010 01010111 10011100 01101010 11100001 00110101 10101010 01011001 10010110 01110010 00100101 11010010 01001110 10101001 01110100 00101100 11001011 01010110 10011101 01101001 11100010 00110100 10101011 01011000 10010111 01110011 00100100 11010011 01001101 10101010 01110101 00101011 11001100 01010101 10011110 01101000 11100011 00110011 10101100 01011011 10010100";
    position: absolute;
    top: -100%;
    left: 0;
    width: 100%;
    height: 300%;
    font-family: var(--font-code);
    font-size: 14px;
    line-height: 1.8;
    color: var(--goroutine-green);
    word-wrap: break-word;
    letter-spacing: 0.5em;
    animation: binaryScroll 60s linear infinite;
}

@keyframes binaryScroll {
    0% { transform: translateY(0); }
    100% { transform: translateY(33.33%); }
}

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

#thread-traces path {
    fill: none;
    stroke-width: 1.5;
    stroke-linecap: round;
}

/* --- HUD Frame --- */
#hud-frame {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 100;
}

#hud-top {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 36px;
    background: rgba(10, 10, 15, 0.85);
    border-bottom: 1px solid rgba(139, 143, 163, 0.2);
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 12px;
    backdrop-filter: blur(8px);
}

.hud-label {
    font-family: var(--font-accent);
    font-weight: 500;
    font-size: 0.7rem;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--stack-gray);
}

.hud-value {
    font-family: var(--font-display);
    font-size: 0.85rem;
    color: var(--goroutine-green);
    letter-spacing: 0.1em;
}

.hud-separator {
    color: rgba(139, 143, 163, 0.3);
    font-size: 0.8rem;
}

.status-active {
    color: var(--goroutine-green);
    animation: statusPulse 2s ease-in-out infinite;
}

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

#hud-left {
    position: absolute;
    top: 36px;
    left: 0;
    width: 140px;
    bottom: 36px;
    background: rgba(10, 10, 15, 0.7);
    border-right: 1px solid rgba(139, 143, 163, 0.15);
    padding: 12px 8px;
    backdrop-filter: blur(8px);
    overflow: hidden;
}

.hud-rail-title {
    font-family: var(--font-accent);
    font-weight: 500;
    font-size: 0.6rem;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--stack-gray);
    margin-bottom: 12px;
    text-align: center;
    border-bottom: 1px solid rgba(139, 143, 163, 0.15);
    padding-bottom: 8px;
}

.process-entry {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 6px;
    margin-bottom: 4px;
    border-left: 2px solid transparent;
    font-family: var(--font-code);
    font-size: 0.65rem;
    transition: border-color 0.3s ease;
}

.process-entry[data-color="green"] { border-left-color: var(--goroutine-green); }
.process-entry[data-color="cyan"] { border-left-color: var(--channel-cyan); }
.process-entry[data-color="magenta"] { border-left-color: var(--mutex-magenta); }
.process-entry[data-color="amber"] { border-left-color: var(--heap-amber); }

.pid {
    color: var(--stack-gray);
}

.pstate {
    font-family: var(--font-accent);
    font-size: 0.55rem;
    letter-spacing: 0.1em;
    padding: 1px 4px;
}

.state-running { color: var(--goroutine-green); }
.state-ready { color: var(--channel-cyan); }
.state-blocked { color: var(--mutex-magenta); }
.state-yield { color: var(--heap-amber); }

#hud-bottom {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 36px;
    background: rgba(10, 10, 15, 0.85);
    border-top: 1px solid rgba(139, 143, 163, 0.2);
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 12px;
    backdrop-filter: blur(8px);
}

#hud-bottom .hud-label {
    flex-shrink: 0;
}

#event-log-container {
    flex: 1;
    overflow: hidden;
    height: 20px;
}

#event-log {
    list-style: none;
    font-family: var(--font-code);
    font-size: 0.75rem;
    color: var(--stack-gray);
    animation: logScroll 0.5s ease;
}

#event-log li {
    height: 20px;
    line-height: 20px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#event-log li .log-time {
    color: var(--heap-amber);
}

#event-log li .log-msg {
    color: var(--stack-gray);
}

@keyframes logScroll {
    from { transform: translateY(-20px); }
    to { transform: translateY(0); }
}

/* --- Main Content --- */
#content {
    position: relative;
    z-index: 10;
    padding-left: 140px;
    padding-top: 36px;
    padding-bottom: 36px;
}

/* --- Narrative Sections --- */
.narrative-section {
    position: relative;
    min-height: 100vh;
    padding: 80px 60px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

/* --- Mutex Lock Icons --- */
.mutex-lock {
    position: absolute;
    top: 40px;
    right: 40px;
    width: 28px;
    height: 36px;
    z-index: 20;
}

.lock-body {
    position: absolute;
    bottom: 0;
    left: 2px;
    width: 24px;
    height: 18px;
    background: var(--mutex-magenta);
    border-radius: 3px;
    transition: background 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.lock-shackle {
    position: absolute;
    top: 0;
    left: 6px;
    width: 16px;
    height: 18px;
    border: 3px solid var(--mutex-magenta);
    border-bottom: none;
    border-radius: 8px 8px 0 0;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.mutex-lock.unlocked .lock-body {
    background: var(--goroutine-green);
}

.mutex-lock.unlocked .lock-shackle {
    border-color: var(--goroutine-green);
    transform: translateX(6px) translateY(-4px);
}

/* --- Diagonal Dividers --- */
.diagonal-divider {
    position: absolute;
    bottom: -30px;
    left: -5%;
    right: -5%;
    height: 60px;
    background: linear-gradient(
        90deg,
        transparent 0%,
        var(--goroutine-green) 20%,
        var(--channel-cyan) 50%,
        var(--mutex-magenta) 80%,
        transparent 100%
    );
    opacity: 0.12;
    transform: skewY(-3deg);
    background-size: 200% 100%;
    animation: dataBurst 4s linear infinite;
    z-index: 5;
}

@keyframes dataBurst {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

/* --- Hero Zone (SPAWN) --- */
.hero-zone {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    min-height: 80vh;
}

#hero-title {
    font-family: var(--font-display);
    font-size: clamp(2rem, 5vw, 4.5rem);
    font-weight: 400;
    letter-spacing: 0.35em;
    text-transform: uppercase;
    color: var(--register-white);
    margin-bottom: 24px;
    display: flex;
    gap: 0;
}

.hero-letter {
    display: inline-block;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.4s ease, transform 0.4s ease;
}

.hero-letter.visible {
    opacity: 1;
    transform: translateY(0);
}

.hero-letter.flash {
    color: var(--goroutine-green);
    text-shadow: 0 0 20px var(--goroutine-green), 0 0 40px var(--goroutine-green);
}

.hero-letter.settled {
    color: var(--register-white);
    text-shadow: 0 0 10px rgba(232, 234, 240, 0.3);
}

#hero-subtitle {
    font-family: var(--font-body);
    font-weight: 300;
    font-size: clamp(1rem, 2vw, 1.3rem);
    color: var(--stack-gray);
    letter-spacing: 0.1em;
    min-height: 1.75em;
    overflow: hidden;
    border-right: 2px solid var(--goroutine-green);
    white-space: nowrap;
    animation: cursorBlink 0.8s step-end infinite;
}

@keyframes cursorBlink {
    0%, 100% { border-right-color: var(--goroutine-green); }
    50% { border-right-color: transparent; }
}

.spawn-indicator {
    margin-top: 40px;
    font-family: var(--font-display);
    font-size: 1rem;
    color: var(--goroutine-green);
}

.spawn-cmd {
    opacity: 0.7;
}

.spawn-blink {
    animation: cursorBlink 0.8s step-end infinite;
}

/* --- Section Titles --- */
.section-title {
    font-family: var(--font-display);
    font-size: clamp(1.8rem, 4vw, 3.5rem);
    font-weight: 400;
    letter-spacing: 0.35em;
    text-transform: uppercase;
    color: var(--register-white);
    margin-bottom: 24px;
    text-shadow: 0 0 10px rgba(232, 234, 240, 0.2);
}

.section-narrative {
    font-family: var(--font-body);
    font-weight: 300;
    font-size: clamp(0.95rem, 1.8vw, 1.15rem);
    line-height: 1.75;
    color: var(--stack-gray);
    max-width: 700px;
    margin-bottom: 40px;
}

/* --- Process Cards --- */
.process-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 4px;
    margin-top: 20px;
}

.process-card {
    background: rgba(10, 10, 15, 0.8);
    border: 1px solid var(--stack-gray);
    border-radius: 2px;
    overflow: hidden;
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 0.5s ease, transform 0.5s ease, border-color 0.3s ease, box-shadow 0.3s ease;
    position: relative;
}

.process-card::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: repeating-linear-gradient(
        0deg,
        transparent 0px,
        transparent 1px,
        rgba(255, 255, 255, 0.02) 1px,
        rgba(255, 255, 255, 0.02) 2px
    );
    pointer-events: none;
}

.process-card.revealed {
    opacity: 1;
    transform: translateY(0);
}

.process-card[data-thread="green"]:hover {
    border-color: var(--goroutine-green);
    box-shadow: 0 0 20px rgba(0, 255, 159, 0.15);
}

.process-card[data-thread="cyan"]:hover {
    border-color: var(--channel-cyan);
    box-shadow: 0 0 20px rgba(0, 212, 255, 0.15);
}

.process-card[data-thread="magenta"]:hover {
    border-color: var(--mutex-magenta);
    box-shadow: 0 0 20px rgba(255, 0, 128, 0.15);
}

.process-card[data-thread="amber"]:hover {
    border-color: var(--heap-amber);
    box-shadow: 0 0 20px rgba(255, 184, 48, 0.15);
}

.card-titlebar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: rgba(139, 143, 163, 0.08);
    border-bottom: 1px solid rgba(139, 143, 163, 0.1);
}

.titlebar-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
}

.dot-red { background: var(--deadlock-red); }
.dot-amber { background: var(--heap-amber); }
.dot-green { background: var(--goroutine-green); }

.card-title {
    font-family: var(--font-accent);
    font-weight: 500;
    font-size: 0.7rem;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--stack-gray);
    margin-left: 8px;
}

.card-body {
    padding: 16px;
}

.card-code {
    font-family: var(--font-code);
    font-size: 0.8rem;
    color: var(--channel-cyan);
    margin-bottom: 12px;
    padding: 8px;
    background: rgba(0, 212, 255, 0.05);
    border-left: 2px solid var(--channel-cyan);
}

.card-text {
    font-family: var(--font-body);
    font-weight: 300;
    font-size: 0.9rem;
    line-height: 1.6;
    color: var(--stack-gray);
    margin-bottom: 12px;
}

.card-status {
    font-family: var(--font-accent);
    font-weight: 500;
    font-size: 0.65rem;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    display: flex;
    align-items: center;
    gap: 8px;
}

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

.status-dot.running { background: var(--goroutine-green); color: var(--goroutine-green); }
.status-dot.communicating { background: var(--channel-cyan); color: var(--channel-cyan); }
.status-dot.blocked { background: var(--mutex-magenta); color: var(--mutex-magenta); }
.status-dot.yielding { background: var(--heap-amber); color: var(--heap-amber); }

.card-status { color: var(--stack-gray); }

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

/* --- Sync Visual (SYNCHRONIZE section) --- */
.sync-visual {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    margin: 40px 0;
    position: relative;
    height: 120px;
}

.sync-line {
    flex: 1;
    height: 2px;
    max-width: 150px;
    opacity: 0;
    transition: opacity 0.6s ease;
}

.sync-line[data-from="green"] { background: var(--goroutine-green); }
.sync-line[data-from="cyan"] { background: var(--channel-cyan); }
.sync-line[data-from="magenta"] { background: var(--mutex-magenta); }
.sync-line[data-from="amber"] { background: var(--heap-amber); }

.sync-visual.active .sync-line {
    opacity: 0.8;
    animation: syncPulse 1.5s ease-in-out infinite;
}

@keyframes syncPulse {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 0.8; }
}

.sync-point {
    width: 120px;
    height: 120px;
    border: 2px solid var(--goroutine-green);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    position: relative;
    background: rgba(0, 255, 159, 0.05);
}

.sync-label {
    font-family: var(--font-code);
    font-size: 0.7rem;
    color: var(--goroutine-green);
    text-align: center;
}

.sync-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 4px;
    margin-top: 30px;
}

.sync-card {
    opacity: 0;
    transform: translateY(30px);
}

.sync-card.revealed {
    opacity: 1;
    transform: translateY(0);
}

/* --- Contention Zone (CONTEND section) --- */
.contention-zone {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    margin: 40px 0;
    padding: 30px;
}

.contention-thread {
    display: flex;
    align-items: center;
    gap: 12px;
}

.thread-label {
    font-family: var(--font-code);
    font-size: 0.8rem;
    color: var(--goroutine-green);
}

.thread-arrow {
    font-family: var(--font-code);
    font-size: 1.2rem;
    color: var(--deadlock-red);
    animation: arrowPulse 1s ease-in-out infinite;
}

@keyframes arrowPulse {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 1; }
}

.contention-resource {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.resource-lock {
    width: 50px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.lock-icon.contested {
    position: relative;
    width: 30px;
    height: 36px;
}

.lock-body-icon {
    position: absolute;
    bottom: 0;
    left: 1px;
    width: 28px;
    height: 20px;
    background: var(--deadlock-red);
    border-radius: 3px;
    animation: lockContested 0.5s ease-in-out infinite;
}

.lock-shackle-icon {
    position: absolute;
    top: 0;
    left: 5px;
    width: 18px;
    height: 18px;
    border: 3px solid var(--deadlock-red);
    border-bottom: none;
    border-radius: 9px 9px 0 0;
}

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

.resource-label {
    font-family: var(--font-accent);
    font-weight: 500;
    font-size: 0.65rem;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--deadlock-red);
}

.deadlock-warning {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 24px;
    background: rgba(255, 45, 45, 0.08);
    border: 1px solid rgba(255, 45, 45, 0.3);
    border-radius: 2px;
    margin: 30px 0;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.5s ease, transform 0.5s ease;
}

.deadlock-warning.visible {
    opacity: 1;
    transform: translateY(0);
}

.warning-icon {
    width: 24px;
    height: 24px;
    background: var(--deadlock-red);
    color: var(--void-black);
    font-family: var(--font-display);
    font-size: 0.9rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 2px;
    flex-shrink: 0;
}

.warning-text {
    font-family: var(--font-code);
    font-size: 0.8rem;
    color: var(--deadlock-red);
}

.contend-resolution {
    margin-top: 20px;
    color: var(--goroutine-green);
    font-weight: 600;
    font-style: italic;
}

/* --- Resolve Visual (RESOLVE section) --- */
.resolve-visual {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    margin: 40px 0;
    position: relative;
    min-height: 160px;
}

.resolve-trace {
    flex: 1;
    max-width: 120px;
    height: 2px;
    opacity: 0;
    transition: opacity 1s ease;
}

.resolve-trace[data-color="green"] { background: var(--goroutine-green); }
.resolve-trace[data-color="cyan"] { background: var(--channel-cyan); }
.resolve-trace[data-color="magenta"] { background: var(--mutex-magenta); }
.resolve-trace[data-color="amber"] { background: var(--heap-amber); }

.resolve-visual.active .resolve-trace {
    opacity: 0.6;
}

.resolve-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 30px;
    border: 1px solid var(--goroutine-green);
    border-radius: 4px;
    background: rgba(0, 255, 159, 0.03);
    flex-shrink: 0;
}

.resolve-code {
    font-family: var(--font-code);
    font-size: 1rem;
    color: var(--channel-cyan);
}

.resolve-status {
    font-family: var(--font-display);
    font-size: 1.2rem;
    letter-spacing: 0.3em;
    color: var(--goroutine-green);
    animation: statusPulse 2s ease-in-out infinite;
}

.resolve-message {
    margin-top: 60px;
    text-align: center;
    padding: 40px;
    border-top: 1px solid rgba(139, 143, 163, 0.15);
    border-bottom: 1px solid rgba(139, 143, 163, 0.15);
}

.resolve-text {
    font-family: var(--font-body);
    font-weight: 300;
    font-size: clamp(1.1rem, 2.5vw, 1.5rem);
    line-height: 1.8;
    color: var(--register-white);
    font-style: italic;
}

.resolve-attribution {
    font-family: var(--font-accent);
    font-weight: 500;
    font-size: 0.75rem;
    letter-spacing: 0.15em;
    color: var(--stack-gray);
    margin-top: 16px;
}

/* --- Scheduler Wheel --- */
#scheduler-wheel {
    position: fixed;
    bottom: 50px;
    right: 20px;
    width: 120px;
    height: 120px;
    opacity: 0.4;
    z-index: 90;
    pointer-events: none;
    animation: wheelRotate var(--scroll-speed) linear infinite;
}

#scheduler-wheel svg {
    width: 100%;
    height: 100%;
}

.wheel-segment {
    transition: opacity 0.3s ease;
}

.wheel-label {
    font-family: 'Orbitron', sans-serif;
    font-size: 8px;
    fill: var(--stack-gray);
    letter-spacing: 0.15em;
    text-anchor: middle;
}

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

/* --- Responsive --- */
@media (max-width: 768px) {
    #hud-left {
        display: none;
    }

    #content {
        padding-left: 0;
    }

    .narrative-section {
        padding: 60px 24px;
    }

    .process-card-grid,
    .sync-cards {
        grid-template-columns: 1fr;
    }

    .contention-zone {
        flex-direction: column;
    }

    .thread-arrow {
        transform: rotate(90deg);
    }

    #scheduler-wheel {
        width: 80px;
        height: 80px;
        bottom: 44px;
        right: 10px;
        opacity: 0.25;
    }

    .sync-visual {
        flex-direction: column;
        height: auto;
    }

    .sync-line {
        width: 2px;
        height: 30px;
        max-width: none;
    }

    .mutex-lock {
        top: 20px;
        right: 20px;
    }
}

@media (max-width: 480px) {
    #hud-top {
        font-size: 0.6rem;
        gap: 6px;
        padding: 0 10px;
    }

    #hud-top .hud-separator:nth-child(n+6) {
        display: none;
    }

    #hud-top .hud-label:nth-child(n+7) {
        display: none;
    }

    #hud-top .hud-value:nth-child(n+8) {
        display: none;
    }

    .hero-letter {
        font-size: clamp(1.5rem, 8vw, 3rem);
    }
}
