/* ===== RESET & BASE ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

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

body {
    background: #0b0e14;
    color: #e0e6ed;
    font-family: "IBM Plex Sans", system-ui, sans-serif;
    font-weight: 400;
    line-height: 1.7;
    overflow-x: hidden;
    font-feature-settings: "tnum";
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ===== HUD OVERLAY ===== */
.hud {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 100;
    transition: opacity 300ms ease;
    font-family: "JetBrains Mono", monospace;
    font-weight: 400;
}

.hud.hud-fade {
    opacity: 0;
}

.hud-cell {
    position: absolute;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 18px 24px;
    background: rgba(11, 14, 20, 0.55);
    border: 1px solid rgba(46, 196, 182, 0.15);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

.hud-tl { top: 18px; left: 18px; border-left: 2px solid #2ec4b6; }
.hud-tr { top: 18px; right: 18px; border-right: 2px solid #2ec4b6; text-align: right; align-items: flex-end; }
.hud-bl { bottom: 18px; left: 18px; border-left: 2px solid #f4a261; }
.hud-br { bottom: 18px; right: 18px; border-right: 2px solid #e63946; text-align: right; align-items: flex-end; }

.hud-label {
    font-size: 0.7rem;
    letter-spacing: 0.18em;
    color: #a8b2c1;
    text-transform: uppercase;
}

.hud-value {
    font-size: clamp(1rem, 2vw, 1.4rem);
    color: #e0e6ed;
    letter-spacing: 0.05em;
    font-weight: 700;
}

.hud-unit {
    font-size: 0.75em;
    color: #a8b2c1;
    margin-left: 2px;
    font-weight: 400;
}

/* ===== SECTIONS ===== */
.section {
    position: relative;
    width: 100%;
    min-height: 100vh;
    padding: 96px 48px 64px;
    overflow: hidden;
}

.section-meta {
    position: absolute;
    top: 32px;
    left: 48px;
    display: flex;
    gap: 12px;
    align-items: center;
    font-family: "JetBrains Mono", monospace;
    font-size: 0.75rem;
    letter-spacing: 0.18em;
    color: #a8b2c1;
    z-index: 10;
}

.meta-tag {
    color: #2ec4b6;
    font-weight: 700;
}

.meta-text {
    text-transform: uppercase;
}

.section-footer {
    position: absolute;
    bottom: 24px;
    left: 48px;
    right: 48px;
    display: flex;
    gap: 12px;
    align-items: center;
    font-family: "JetBrains Mono", monospace;
    font-size: 0.7rem;
    letter-spacing: 0.16em;
    color: #a8b2c1;
    text-transform: uppercase;
    z-index: 5;
}

.footer-tag { color: #e0e6ed; }
.footer-sep { color: #2ec4b6; }

/* ===== SECTION 1: THREAD POOL ===== */
.section-pool {
    background: #0b0e14;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pool-container {
    width: 100%;
    height: 70vh;
    display: flex;
    flex-direction: column;
    gap: 0;
    position: relative;
}

.thread-lane {
    flex: 1;
    position: relative;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    overflow: hidden;
}

.thread-lane:first-child {
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.thread-lane::before {
    content: attr(data-thread);
    position: absolute;
    top: 50%;
    left: 12px;
    transform: translateY(-50%);
    font-family: "JetBrains Mono", monospace;
    font-size: 0.65rem;
    color: rgba(168, 178, 193, 0.5);
    letter-spacing: 0.15em;
    z-index: 2;
    pointer-events: none;
}

.task-block {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    height: 60%;
    border-radius: 2px;
    will-change: transform;
    animation: lane-slide linear infinite;
}

.task-block.task-compute {
    background: #e63946;
    box-shadow: 0 0 12px rgba(230, 57, 70, 0.4);
}

.task-block.task-io {
    background: #457b9d;
    box-shadow: 0 0 12px rgba(69, 123, 157, 0.4);
}

.task-block.task-channel {
    background: #2ec4b6;
    box-shadow: 0 0 12px rgba(46, 196, 182, 0.4);
}

.task-block.task-mutex {
    background: #f4a261;
    box-shadow: 0 0 12px rgba(244, 162, 97, 0.4);
}

@keyframes lane-slide {
    0% {
        transform: translateY(-50%) translateX(-220px);
    }
    100% {
        transform: translateY(-50%) translateX(calc(100vw + 220px));
    }
}

/* ===== SECTION 2: FORK ===== */
.section-fork {
    position: relative;
    padding: 0;
    background: #0b0e14;
    min-height: 100vh;
}

.fork-upper {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #0d1b2a;
    clip-path: polygon(0 0, 100% 0, 100% 0, 0 calc(100% - 12vw));
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding: 96px 48px;
}

.fork-lower {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #1b2838;
    clip-path: polygon(0 100%, 100% 0, 100% 100%, 0 100%);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 96px 48px;
}

.fork-divider {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    background: linear-gradient(
        to bottom right,
        transparent calc(50% - 1px),
        #2ec4b6 calc(50% - 1px),
        #2ec4b6 calc(50% + 1px),
        transparent calc(50% + 1px)
    );
    animation: divider-pulse 2s ease-in-out infinite;
    z-index: 5;
}

@keyframes divider-pulse {
    0%, 100% { opacity: 0.45; }
    50% { opacity: 1; }
}

.flame-wrapper {
    width: 50%;
    max-width: 540px;
    margin-left: 4%;
    position: relative;
}

.flame-title {
    display: block;
    font-family: "JetBrains Mono", monospace;
    font-size: 0.8rem;
    color: #2ec4b6;
    letter-spacing: 0.12em;
    margin-bottom: 16px;
    text-transform: lowercase;
}

.flame-graph {
    width: 100%;
    height: auto;
    aspect-ratio: 800 / 320;
    display: block;
}

.flame-rect {
    stroke: #0d1b2a;
    stroke-width: 1;
    cursor: pointer;
    transition: stroke 0.15s ease, filter 0.15s ease;
    opacity: 0;
    animation: flame-fade 0.4s forwards;
}

.flame-rect:hover {
    stroke: #ffffff;
    stroke-width: 1;
    filter: brightness(1.3);
}

@keyframes flame-fade {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.flame-tooltip {
    position: absolute;
    pointer-events: none;
    background: #0b0e14;
    border: 1px solid #2ec4b6;
    color: #e0e6ed;
    padding: 6px 10px;
    font-family: "JetBrains Mono", monospace;
    font-size: 0.7rem;
    letter-spacing: 0.05em;
    opacity: 0;
    transition: opacity 0.12s ease;
    z-index: 20;
    white-space: nowrap;
}

.flame-tooltip.visible {
    opacity: 1;
}

.fork-text {
    width: 50%;
    max-width: 540px;
    margin-right: 4%;
}

.fork-tag {
    display: inline-block;
    font-family: "JetBrains Mono", monospace;
    font-size: 0.75rem;
    letter-spacing: 0.18em;
    color: #2ec4b6;
    margin-bottom: 12px;
}

.fork-heading {
    font-family: "Space Grotesk", sans-serif;
    font-weight: 700;
    font-size: clamp(1.5rem, 3vw, 2.5rem);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #e0e6ed;
    margin-bottom: 24px;
    line-height: 1.15;
}

.fork-code {
    background: #0b0e14;
    border-left: 2px solid #2ec4b6;
    padding: 18px 22px;
    font-family: "JetBrains Mono", monospace;
    font-size: clamp(0.78rem, 1vw, 0.9rem);
    color: #e0e6ed;
    margin-bottom: 24px;
    overflow-x: auto;
    line-height: 1.6;
    letter-spacing: 0.02em;
}

.fork-code .kw { color: #f4a261; }
.fork-code .fn { color: #2ec4b6; }
.fork-code .var { color: #e0e6ed; }
.fork-code .ty { color: #06d6a0; }

.fork-prose {
    font-size: clamp(0.95rem, 1.5vw, 1.05rem);
    color: #a8b2c1;
    line-height: 1.7;
    max-width: 52ch;
}

/* ===== SECTION 3: CONTENTION ===== */
.section-contention {
    background: #0b0e14;
}

.contention-wrap {
    width: 100%;
    height: 70vh;
    position: relative;
    margin-top: 20px;
}

.contention-graph {
    width: 100%;
    height: 100%;
    display: block;
}

.cn-edge {
    stroke: #2ec4b6;
    stroke-width: 1;
    opacity: 0.2;
    fill: none;
    transition: opacity 0.25s ease, stroke-width 0.25s ease;
}

.cn-edge.active {
    opacity: 0.85;
    stroke-width: 1.5;
}

.cn-edge-pulse {
    stroke: #2ec4b6;
    stroke-width: 2;
    fill: none;
    stroke-dasharray: 4 200;
    animation: edge-flow 3s linear infinite;
    opacity: 0.55;
}

@keyframes edge-flow {
    from { stroke-dashoffset: 0; }
    to { stroke-dashoffset: -200; }
}

.cn-node {
    fill: #1b2838;
    stroke: #2ec4b6;
    stroke-width: 1.5;
    transition: stroke 0.2s ease, filter 0.2s ease;
    cursor: pointer;
}

.cn-node.contended {
    fill: #1b2838;
    stroke: #e63946;
    animation: node-pulse 1.4s ease-in-out infinite;
}

.cn-node.healthy {
    stroke: #2ec4b6;
}

.cn-node:hover {
    filter: drop-shadow(0 0 8px #2ec4b6);
}

@keyframes node-pulse {
    0%, 100% {
        filter: drop-shadow(0 0 0 rgba(230, 57, 70, 0));
    }
    50% {
        filter: drop-shadow(0 0 12px rgba(230, 57, 70, 0.6));
    }
}

.cn-label {
    font-family: "JetBrains Mono", monospace;
    font-size: 9px;
    fill: #a8b2c1;
    letter-spacing: 0.05em;
    pointer-events: none;
}

.contention-labels {
    position: absolute;
    inset: 0;
    pointer-events: none;
    font-family: "JetBrains Mono", monospace;
}

.contention-label {
    position: absolute;
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 0.7rem;
    letter-spacing: 0.05em;
    border-left: 2px solid #e63946;
    padding-left: 8px;
}

.contention-label-1 { top: 18%; left: 14%; }
.contention-label-2 { top: 60%; right: 18%; border-left-color: #2ec4b6; }
.contention-label-3 { bottom: 22%; left: 22%; border-left-color: #f4a261; }

.cl-tag { color: #e0e6ed; font-weight: 700; }
.cl-detail { color: #a8b2c1; }

/* ===== SECTION 4: BENTO ===== */
.section-bento {
    background: #0b0e14;
}

.bento-grid {
    display: grid;
    grid-template-columns: 2fr 1fr 2fr;
    grid-template-rows: 1fr 1fr;
    gap: 56px;
    width: 100%;
    height: 70vh;
    margin-top: 24px;
    grid-template-areas:
        "spark gauge histo"
        "perc perc total";
}

.bento-cell {
    position: relative;
    padding: 20px;
    border: 1px solid transparent;
    transition: border-color 0.3s ease;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 12px;
}

.bento-cell:hover {
    border-color: #2ec4b6;
    animation: border-cycle 1.2s linear;
}

@keyframes border-cycle {
    0% { border-color: rgba(46, 196, 182, 0); }
    50% { border-color: rgba(46, 196, 182, 1); }
    100% { border-color: rgba(46, 196, 182, 1); }
}

.bento-sparkline { grid-area: spark; }
.bento-gauge { grid-area: gauge; }
.bento-histogram { grid-area: histo; }
.bento-percentile { grid-area: perc; }
.bento-throughput { grid-area: total; }

.bento-label {
    font-family: "JetBrains Mono", monospace;
    font-size: 0.7rem;
    letter-spacing: 0.18em;
    color: #a8b2c1;
    text-transform: uppercase;
}

.bento-value {
    font-family: "JetBrains Mono", monospace;
    font-size: clamp(1.4rem, 2.4vw, 2rem);
    font-weight: 700;
    color: #e0e6ed;
    letter-spacing: 0.05em;
}

.bento-large {
    font-size: clamp(2rem, 4.5vw, 3.6rem);
    color: #2ec4b6;
}

.bento-sub {
    font-family: "JetBrains Mono", monospace;
    font-size: 0.7rem;
    color: #a8b2c1;
    letter-spacing: 0.08em;
}

.sparkline {
    width: 100%;
    height: 60px;
    flex: 0 0 60px;
}

.spark-line {
    stroke: #2ec4b6;
    stroke-width: 1.5;
    fill: none;
    stroke-dasharray: 600;
    stroke-dashoffset: 600;
    transition: stroke-dashoffset 1.6s ease-out;
}

.spark-line.drawn {
    stroke-dashoffset: 0;
}

.spark-fill {
    fill: rgba(46, 196, 182, 0.15);
    stroke: none;
    opacity: 0;
    transition: opacity 0.6s ease 1.2s;
}

.spark-fill.drawn {
    opacity: 1;
}

.gauge {
    width: 100px;
    height: 100px;
    transform: rotate(-90deg);
    align-self: center;
}

.gauge-track {
    fill: none;
    stroke: #1b2838;
    stroke-width: 8;
}

.gauge-arc {
    fill: none;
    stroke: #2ec4b6;
    stroke-width: 8;
    stroke-linecap: round;
    stroke-dasharray: 314;
    stroke-dashoffset: 314;
    transition: stroke-dashoffset 1.4s cubic-bezier(0.22, 1, 0.36, 1);
}

.gauge-value {
    align-self: center;
    font-size: 1rem;
}

.histogram {
    display: flex;
    align-items: flex-end;
    gap: 3px;
    height: 80px;
    padding: 8px 0;
}

.histo-bar {
    flex: 1;
    background: #2ec4b6;
    box-shadow: 0 0 8px rgba(46, 196, 182, 0.3);
    height: 0;
    transform-origin: bottom;
    transition: height 0.8s cubic-bezier(0.22, 1, 0.36, 1);
}

.percentile-rows {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin-top: 8px;
}

.prow {
    display: grid;
    grid-template-columns: 36px 1fr 64px;
    align-items: center;
    gap: 12px;
    font-family: "JetBrains Mono", monospace;
    font-size: 0.85rem;
}

.ptag {
    color: #a8b2c1;
    letter-spacing: 0.08em;
}

.pbar {
    height: 6px;
    background: #1b2838;
    overflow: hidden;
    position: relative;
}

.pfill {
    height: 100%;
    background: #2ec4b6;
    width: 0;
    transition: width 1s cubic-bezier(0.22, 1, 0.36, 1);
    box-shadow: 0 0 6px rgba(46, 196, 182, 0.5);
}

.prow:nth-child(4) .pfill {
    background: #f4a261;
    box-shadow: 0 0 6px rgba(244, 162, 97, 0.5);
}

.pval {
    color: #e0e6ed;
    text-align: right;
    letter-spacing: 0.05em;
}

/* ===== SECTION 5: RESOLUTION ===== */
.section-resolution {
    background: #0b0e14;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    min-height: 100vh;
}

.resolution-container {
    width: 100%;
    height: 60vh;
    position: relative;
    display: flex;
    flex-direction: column;
    margin-top: 24px;
    overflow: hidden;
}

.resolution-lane {
    flex: 1;
    position: relative;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    overflow: hidden;
}

.resolution-lane:first-child {
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.res-block {
    position: absolute;
    top: 50%;
    left: -200px;
    height: 60%;
    width: 80px;
    background: #2ec4b6;
    border-radius: 2px;
    box-shadow: 0 0 14px rgba(46, 196, 182, 0.45);
    transform: translateY(-50%);
    will-change: transform, left;
}

.res-block.converging {
    animation: converge 4s cubic-bezier(0.55, 0, 0.45, 1) forwards;
}

@keyframes converge {
    0% {
        left: -200px;
        top: var(--start-top, 50%);
    }
    60% {
        left: 60%;
        top: var(--start-top, 50%);
    }
    100% {
        left: calc(100% + 200px);
        top: 50%;
    }
}

.output-stream {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 6px;
    background: linear-gradient(
        to bottom,
        transparent 0%,
        #2ec4b6 50%,
        transparent 100%
    );
    box-shadow: 0 0 24px rgba(46, 196, 182, 0.5);
    opacity: 0;
    animation: stream-fade 6s ease-in 1s forwards;
}

@keyframes stream-fade {
    0% { opacity: 0; transform: scaleY(0.4); }
    50% { opacity: 1; transform: scaleY(1); }
    100% { opacity: 1; transform: scaleY(1); }
}

.resolution-line {
    margin-top: 32px;
    font-family: "JetBrains Mono", monospace;
    font-size: clamp(1.1rem, 2.4vw, 1.6rem);
    color: #e0e6ed;
    letter-spacing: 0.12em;
    opacity: 0;
    transition: opacity 1.2s ease 1.5s;
}

.resolution-line.revealed {
    opacity: 1;
}

/* ===== INTERSECTION REVEAL ===== */
.section {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.9s ease, transform 0.9s ease;
}

.section.in-view {
    opacity: 1;
    transform: translateY(0);
}

.section-pool.in-view {
    opacity: 1;
}

.section-pool {
    opacity: 1;
    transform: none;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .section {
        padding: 80px 20px 56px;
    }

    .section-meta {
        left: 20px;
        top: 22px;
    }

    .section-footer {
        left: 20px;
        right: 20px;
        flex-wrap: wrap;
    }

    .hud {
        position: fixed;
        top: auto;
        bottom: 0;
        height: auto;
        background: rgba(11, 14, 20, 0.85);
        padding: 8px;
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 4px;
        backdrop-filter: blur(10px);
    }

    .hud-cell {
        position: static;
        padding: 8px 12px;
        background: transparent;
        border: 1px solid rgba(46, 196, 182, 0.18);
    }

    .hud-tl, .hud-tr, .hud-bl, .hud-br {
        text-align: left;
        align-items: flex-start;
        border-left: 2px solid #2ec4b6;
        border-right: none;
    }

    .hud-label { font-size: 0.6rem; }
    .hud-value { font-size: 0.95rem; }

    .pool-container,
    .resolution-container {
        height: 60vh;
    }

    /* Lanes 7-12 hidden on mobile via JS-injected class */
    .thread-lane.hide-mobile,
    .resolution-lane.hide-mobile {
        display: none;
    }

    .task-block {
        animation-duration: calc(var(--lane-duration, 5s) * 1.3) !important;
    }

    .section-fork {
        min-height: auto;
    }

    .fork-upper, .fork-lower {
        position: relative;
        clip-path: none;
        width: 100%;
        padding: 80px 20px;
        min-height: 50vh;
    }

    .fork-upper {
        background: #0d1b2a;
    }

    .fork-lower {
        background: #1b2838;
    }

    .fork-divider {
        background: linear-gradient(to bottom, transparent 49%, #2ec4b6 49%, #2ec4b6 51%, transparent 51%);
    }

    .flame-wrapper, .fork-text {
        width: 100%;
        margin: 0;
        max-width: 100%;
    }

    .bento-grid {
        grid-template-columns: 1fr;
        grid-template-rows: auto;
        grid-template-areas:
            "spark"
            "gauge"
            "histo"
            "perc"
            "total";
        gap: 32px;
        height: auto;
    }

    .contention-wrap {
        height: 60vh;
    }

    .contention-label-1 { top: 8%; left: 4%; }
    .contention-label-2 { top: 50%; right: 4%; }
    .contention-label-3 { bottom: 8%; left: 4%; }
}

@media (prefers-reduced-motion: reduce) {
    .task-block,
    .fork-divider,
    .cn-edge-pulse,
    .cn-node.contended,
    .res-block.converging,
    .output-stream {
        animation: none !important;
    }
}
