/* ============================================================
   completengine.com — deep-burgundy engine
   flat, schematic, zero gradients
   Fonts originally specified as Space Grotesk" (Google Fonts), IBM Plex Mono" (Google Fonts loaded via `<link>`); external fetching disabled here.
   Interactions:** Interactions* Interaction* Interaction:* Interactions:* Interaction: Interactions: Intersection Observer with `threshold: 0.2`
   ============================================================ */

:root {
    --c-void:       #0d0509;
    --c-surface:    #1a0a12;
    --c-surface-2:  #120710;
    --c-accent:     #8b2252;
    --c-hot:        #ff2d55;
    --c-text:       #f2e6d9;
    --c-text-dim:   #c9b8a8;
    --c-border:     #3d1a2e;
    --c-plum:       #5a3a48;
    --c-glow:       #d4507a;

    --ff-display: "Space Grotesk", "Inter", system-ui, sans-serif;
    --ff-body:    "Instrument Sans", "Inter", system-ui, sans-serif;
    --ff-mono:    "IBM Plex Mono", ui-monospace, monospace;
}

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

html, body {
    background: var(--c-void);
    color: var(--c-text);
    font-family: var(--ff-body);
    font-size: 16px;
    line-height: 1.65;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
}

body {
    position: relative;
    min-height: 100vh;
}

/* Grain / noise overlay */
body::after {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 9999;
    opacity: 0.035;
    mix-blend-mode: overlay;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.95  0 0 0 0 0.9  0 0 0 0 0.85  0 0 0 1 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

h1, h2, h3, h4 {
    font-family: var(--ff-display);
    font-weight: 700;
    color: var(--c-text);
    letter-spacing: -0.02em;
    line-height: 1.05;
}

p { color: var(--c-text-dim); }

/* ============================================================
   DISPATCH HEADER (hero)
   ============================================================ */
.dispatch-header {
    position: relative;
    height: 100vh;
    min-height: 720px;
    background: var(--c-void);
    overflow: hidden;
    border-bottom: 1px solid var(--c-border);
}

.particle-field {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 1;
}

.particle {
    position: absolute;
    width: 12px;
    height: 16px;
    background: var(--c-accent);
    border-radius: 1px;
    opacity: 0;
    transform: translateY(0);
    will-change: opacity, transform;
}

.particle.on {
    animation: particle-breathe var(--dur, 5s) ease-in-out infinite;
    animation-delay: var(--delay, 0s);
}

@keyframes particle-breathe {
    0%   { opacity: 0; transform: translateY(0); background: var(--c-accent); }
    20%  { opacity: 0.9; }
    48%  { opacity: 1; background: var(--c-text); }
    52%  { background: var(--c-accent); }
    80%  { opacity: 0.6; transform: translateY(calc(var(--drift, 28px) * -1)); }
    100% { opacity: 0; transform: translateY(calc(var(--drift, 28px) * -1)); }
}

.particle.connected::after {
    content: "";
    position: absolute;
    top: 8px;
    left: 12px;
    width: var(--link, 60px);
    height: 1px;
    background: var(--c-accent);
    opacity: 0.35;
    transform-origin: left center;
    transform: rotate(var(--link-angle, 20deg));
}

.hero-circuit {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0.75;
    z-index: 0;
}

.hero-circuit .node {
    animation: node-pulse 4s ease-in-out infinite;
}
.hero-circuit .node-a { animation-duration: 2.3s; }
.hero-circuit .node-b { animation-duration: 3.7s; }
.hero-circuit .node-c { animation-duration: 4.9s; }
.hero-circuit .node-d { animation-duration: 2.8s; }
.hero-circuit .node-e { animation-duration: 4.2s; }
.hero-circuit .node-f { animation-duration: 3.1s; }
.hero-circuit .node-g { animation-duration: 5.0s; }
.hero-circuit .node-h { animation-duration: 2.6s; }

@keyframes node-pulse {
    0%, 100% { fill: var(--c-border); r: 3; }
    50%      { fill: var(--c-accent); r: 4; }
}

/* Corner readouts */
.readout {
    position: absolute;
    z-index: 3;
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-family: var(--ff-mono);
    font-size: 0.72rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--c-plum);
}

.readout .readout-label { color: var(--c-plum); font-weight: 500; }
.readout .readout-val   { color: var(--c-accent); }

.readout-tl { top: 2.2vh; left: 2.2vw; }
.readout-tr { top: 2.2vh; right: 2.2vw; align-items: flex-end; }
.readout-br { bottom: 2.2vh; right: 2.2vw; align-items: flex-end; }

.hero-label {
    position: absolute;
    top: 2.2vh;
    left: 50%;
    transform: translateX(-50%);
    z-index: 3;
    display: flex;
    align-items: center;
    gap: 12px;
    font-family: var(--ff-mono);
    font-size: 0.72rem;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    color: var(--c-text-dim);
}
.hero-label .dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--c-accent);
    box-shadow: 0 0 10px var(--c-accent);
    animation: node-pulse 1.6s ease-in-out infinite;
}
.hero-label .sep { color: var(--c-plum); }

.hero-heading {
    position: absolute;
    left: 8vw;
    bottom: 12vh;
    z-index: 2;
    max-width: min(1000px, 84vw);
}

.hero-heading h1 {
    font-size: clamp(2.5rem, 6vw + 1rem, 7rem);
    letter-spacing: -0.03em;
    line-height: 1.0;
    color: var(--c-text);
    display: block;
}

.hero-heading h1.secondary {
    color: var(--c-accent);
}

.hero-sub {
    margin-top: 1.4rem;
    max-width: 520px;
    font-size: clamp(1rem, 1.2vw + 0.4rem, 1.2rem);
    line-height: 1.55;
    color: var(--c-text-dim);
    border-left: 1px solid var(--c-border);
    padding-left: 1rem;
}

.glitch-target {
    font-variant-ligatures: none;
}
.glitch-target .ch {
    display: inline-block;
    white-space: pre;
}

/* ============================================================
   ENGINE GRID
   ============================================================ */
.engine-grid-section {
    padding: 6rem 2vw 4rem;
    background: var(--c-void);
    position: relative;
}

.section-marker {
    display: flex;
    align-items: baseline;
    gap: 1.6rem;
    padding: 0 0 1.8rem 0;
    margin: 0 0.4rem 1.2rem;
    border-bottom: 1px solid var(--c-border);
    font-family: var(--ff-mono);
    font-size: 0.78rem;
    letter-spacing: 0.2em;
    text-transform: uppercase;
}
.section-marker .mk-index { color: var(--c-plum); }
.section-marker .mk-title { color: var(--c-text); font-weight: 500; }
.section-marker .mk-meta  { color: var(--c-accent); margin-left: auto; }

.engine-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    grid-auto-rows: 220px;
    gap: 2px;
    background: var(--c-border);
    padding: 2px;
    border: 1px solid var(--c-border);
}

.cell {
    position: relative;
    overflow: hidden;
    background: var(--c-surface);
    padding: 1.6rem 1.4rem 1.4rem;
    display: flex;
    flex-direction: column;
    transition: background 200ms ease-out, outline-color 300ms ease-out;
    outline: 1px solid transparent;
    outline-offset: -1px;
}

.cell-tall { grid-row: span 2; }
.cell-grand { grid-row: span 3; }
.cell-wide { grid-column: span 2; }

@media (max-width: 700px) {
    .cell-wide { grid-column: span 1; }
    .cell-tall,
    .cell-grand { grid-row: span 1; }
    .engine-grid { grid-auto-rows: auto; }
    .cell { min-height: 220px; }
}

.cell-bg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0.18;
    pointer-events: none;
    z-index: 0;
}

.cell-head {
    position: relative;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-family: var(--ff-mono);
    font-size: 0.7rem;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    color: var(--c-plum);
    margin-bottom: 1.2rem;
}
.cell-id { color: var(--c-accent); }
.cell-pulse {
    width: 6px; height: 6px;
    background: var(--c-accent);
    border-radius: 50%;
    box-shadow: 0 0 8px var(--c-accent);
    animation: node-pulse 2.4s ease-in-out infinite;
}

.cell-title {
    position: relative;
    z-index: 2;
    font-size: clamp(1.3rem, 2vw + 0.2rem, 2.2rem);
    line-height: 1.08;
    letter-spacing: -0.02em;
    color: var(--c-text);
    margin-bottom: 0.9rem;
    max-width: 95%;
}

.cell-body {
    position: relative;
    z-index: 2;
    font-size: 0.94rem;
    color: var(--c-text-dim);
    line-height: 1.55;
    max-width: 52ch;
}

.cell-stat {
    position: relative;
    z-index: 2;
    margin-top: auto;
    padding-top: 1.2rem;
    border-top: 1px dashed var(--c-border);
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-family: var(--ff-mono);
    font-size: 0.78rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--c-plum);
}
.cell-stat b {
    font-weight: 500;
    color: var(--c-accent);
    font-size: 0.92rem;
}
.cell-stat sup {
    font-size: 0.7em;
    color: var(--c-plum);
    margin-left: 2px;
}

/* Glitch scan line */
.glitch-scan {
    position: absolute;
    left: 0;
    top: -4px;
    width: 100%;
    height: 1px;
    background: var(--c-hot);
    box-shadow: 0 0 8px var(--c-hot);
    opacity: 0;
    pointer-events: none;
    z-index: 3;
}

.cell:hover {
    background: var(--c-surface-2);
    outline-color: var(--c-accent);
}
.cell:hover .cell-id { color: var(--c-glow); }
.cell:hover .glitch-scan {
    animation: glitch-scan 400ms linear forwards;
}
@keyframes glitch-scan {
    0%   { top: 0;    opacity: 1; }
    95%  {            opacity: 1; }
    100% { top: 100%; opacity: 0; }
}

/* ============================================================
   THREAD POOL
   ============================================================ */
.thread-pool {
    position: relative;
    padding: 7rem 2vw 6rem;
    background: var(--c-void);
    border-top: 1px solid var(--c-border);
}

.thread-columns {
    display: grid;
    grid-template-columns: 35% 25% 40%;
    gap: 2vw;
    margin-top: 2rem;
    padding: 0 0.4rem;
}

@media (max-width: 900px) {
    .thread-columns {
        grid-template-columns: 1fr;
        gap: 3rem;
    }
}

.thread {
    position: relative;
    padding-top: 1rem;
    border-top: 1px solid var(--c-border);
}

.thread-left   { margin-top: 0; }
.thread-center { margin-top: 5rem; }
.thread-right  { margin-top: 2.5rem; }

@media (max-width: 900px) {
    .thread-left, .thread-center, .thread-right { margin-top: 0; }
}

.thread-tag {
    font-family: var(--ff-mono);
    font-size: 0.72rem;
    letter-spacing: 0.22em;
    color: var(--c-accent);
    margin-bottom: 1rem;
    text-transform: uppercase;
}

.thread-title {
    font-size: clamp(1.5rem, 3vw + 0.5rem, 3rem);
    letter-spacing: -0.03em;
    line-height: 1.05;
    color: var(--c-text);
    margin-bottom: 1.2rem;
}

.thread-body {
    font-size: clamp(1rem, 1.1vw + 0.3rem, 1.15rem);
    line-height: 1.65;
    color: var(--c-text-dim);
    margin-bottom: 1rem;
}

.glitch-reveal {
    visibility: hidden;
}
.glitch-reveal.revealing,
.glitch-reveal.revealed {
    visibility: visible;
}

/* ============================================================
   TOPOLOGY DIAGRAM
   ============================================================ */
.topology {
    margin: 5rem auto 0;
    max-width: 960px;
    padding: 1.5rem;
    border: 1px solid var(--c-border);
    background: var(--c-surface-2);
    position: relative;
}
.topology-cap {
    font-family: var(--ff-mono);
    font-size: 0.72rem;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    color: var(--c-plum);
    margin-bottom: 1rem;
}
.topology svg { display: block; width: 100%; height: auto; }

.topo-active .flow {
    stroke-dasharray: 8 6;
    animation: flow-dash 3s linear infinite;
}
.topo-active .flow:nth-child(2) { animation-duration: 4.2s; }
.topo-active .flow:nth-child(3) { animation-duration: 5.0s; }
.topo-active .flow:nth-child(4) { animation-duration: 3.6s; }

@keyframes flow-dash {
    from { stroke-dashoffset: 0; }
    to   { stroke-dashoffset: -140; }
}

.topo-node circle {
    animation: topo-node-pulse 3s ease-in-out infinite;
    transform-origin: center;
    transform-box: fill-box;
}
.topo-node circle:nth-child(2) { animation-duration: 2.2s; }
.topo-node circle:nth-child(3) { animation-duration: 3.8s; }
.topo-node circle:nth-child(4) { animation-duration: 4.6s; }
.topo-node circle:nth-child(5) { animation-duration: 2.8s; }

@keyframes topo-node-pulse {
    0%, 100% { opacity: 0.7; }
    50%      { opacity: 1; }
}

/* ============================================================
   RESOLUTION FOOTER
   ============================================================ */
.resolution-footer {
    position: relative;
    padding: 3.5rem 2vw 2.5rem;
    background: var(--c-void);
    border-top: 1px solid var(--c-border);
    overflow: hidden;
}

.footer-field {
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(transparent 0, transparent 23px, rgba(61,26,46,0.35) 23px, rgba(61,26,46,0.35) 24px),
        linear-gradient(90deg, transparent 0, transparent 23px, rgba(61,26,46,0.35) 23px, rgba(61,26,46,0.35) 24px);
    background-size: 24px 24px;
    opacity: 0.4;
    pointer-events: none;
}

.footer-inner {
    position: relative;
    z-index: 2;
}

.footer-line {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.6rem 1.4rem;
    font-family: var(--ff-mono);
    font-size: clamp(0.8rem, 1vw + 0.2rem, 1rem);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--c-plum);
    padding-bottom: 1.4rem;
    border-bottom: 1px solid var(--c-border);
}

.footer-line .kv {
    display: inline-flex;
    align-items: baseline;
    gap: 0.6rem;
}
.footer-line .k { color: var(--c-plum); }
.footer-line .v {
    color: var(--c-accent);
    text-shadow: 0 0 4px rgba(139, 34, 82, 0.25);
    font-weight: 500;
}
.footer-line .pipe { color: var(--c-border); }

.footer-sub {
    margin-top: 1.2rem;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.8rem;
    font-family: var(--ff-mono);
    font-size: 0.72rem;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--c-plum);
}
.footer-sub .sep { color: var(--c-border); }

/* ============================================================
   UTIL
   ============================================================ */
::selection {
    background: var(--c-accent);
    color: var(--c-text);
}
