/* =============================================================
   infra.day — watercolor infrastructure
   Palette:
     Kiln Fire          #c2551a  (primary, burnt orange)
     Conduit Brown      #a0522d  (secondary, deep sienna)
     Infrastructure Gold#d4922a  (tertiary, amber highlights)
     Drafting Paper     #faf5ee  (background light)
     Carbon             #1c1917  (background dark)
     Obsidian           #0f0e0c  (substrate layer)
     Core               #0a0908  (terminal black)
     Blueprint Teal     #2a6b6b  (cool accent)
   Fonts: Bebas Neue · Source Sans 3 · Share Tech Mono
   ============================================================= */

:root {
    --kiln: #c2551a;
    --conduit: #a0522d;
    --gold: #d4922a;
    --paper: #faf5ee;
    --carbon: #1c1917;
    --obsidian: #0f0e0c;
    --core: #0a0908;
    --teal: #2a6b6b;

    --font-display: "Bebas Neue", Impact, sans-serif;
    --font-body: "Source Sans 3", "Source Sans Pro", system-ui, sans-serif;
    --font-mono: "Share Tech Mono", ui-monospace, monospace;

    --pad-x: clamp(1.5rem, 6vw, 8rem);
    --conduit-left: clamp(28px, 4vw, 64px);
}

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

html { scroll-behavior: smooth; }

body {
    font-family: var(--font-body);
    font-weight: 300;
    background: var(--paper);
    color: var(--carbon);
    line-height: 1.7;
    letter-spacing: 0.01em;
    overflow-x: hidden;
}

.svg-defs { position: absolute; width: 0; height: 0; }

/* Paper grain overlay — fixed over all content at ~3% */
.paper-grain {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 100;
    opacity: 0.055;
    mix-blend-mode: multiply;
    background-image:
        radial-gradient(circle at 20% 30%, rgba(31,25,23,0.9) 0.6px, transparent 0.8px),
        radial-gradient(circle at 80% 70%, rgba(31,25,23,0.8) 0.5px, transparent 0.8px),
        radial-gradient(circle at 60% 20%, rgba(31,25,23,0.7) 0.4px, transparent 0.7px),
        radial-gradient(circle at 10% 80%, rgba(31,25,23,0.6) 0.6px, transparent 0.9px);
    background-size: 7px 7px, 11px 11px, 13px 13px, 17px 17px;
    background-position: 0 0, 3px 2px, 5px 4px, 7px 6px;
}
.paper-grain::after {
    content: "";
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(
        27deg,
        transparent 0 3px,
        rgba(31,25,23,0.04) 3px 4px
    );
}

/* Vertical conduit line — always visible, runs full page height */
.conduit-line {
    position: fixed;
    left: var(--conduit-left);
    top: 0;
    bottom: 0;
    width: 2px;
    background: linear-gradient(
        to bottom,
        rgba(194,85,26,0.0) 0%,
        rgba(194,85,26,0.55) 6%,
        rgba(194,85,26,0.8) 50%,
        rgba(194,85,26,0.55) 94%,
        rgba(194,85,26,0.0) 100%
    );
    z-index: 5;
    pointer-events: none;
    filter: url(#watercolor-edge);
}

/* =============================================================
   Layer base
   ============================================================= */

.layer {
    position: relative;
    width: 100%;
    padding: clamp(4rem, 10vh, 9rem) var(--pad-x) clamp(4rem, 10vh, 9rem) calc(var(--conduit-left) + clamp(1.5rem, 4vw, 4rem));
}

/* =============================================================
   Stencil / technical labels
   ============================================================= */

.stencil {
    font-family: var(--font-mono);
    font-size: clamp(0.68rem, 1vw, 0.82rem);
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--conduit);
    line-height: 1.4;
    display: inline-flex;
    gap: 1.5rem;
    flex-wrap: wrap;
}

.stencil span { display: inline-block; }

.stencil-arrow { animation: arrowDrift 2.4s ease-in-out infinite; }

@keyframes arrowDrift {
    0%, 100% { transform: translateY(0); opacity: 0.6; }
    50% { transform: translateY(6px); opacity: 1; }
}

/* =============================================================
   Watercolor wash layers
   ============================================================= */

.wash {
    position: absolute;
    pointer-events: none;
    z-index: 0;
    filter: url(#watercolor-edge) blur(2px);
}

.wash-top {
    top: -6%;
    left: -10%;
    width: 120%;
    height: 70vh;
    background:
        radial-gradient(ellipse 60% 70% at 28% 0%, rgba(194,85,26,0.78), rgba(212,146,42,0.55) 38%, rgba(250,245,238,0) 68%),
        radial-gradient(ellipse 45% 55% at 70% 10%, rgba(160,82,45,0.55), rgba(250,245,238,0) 70%);
    animation: washDrift 40s ease-in-out infinite alternate;
}

.wash-left {
    top: 0;
    left: -8%;
    width: 55%;
    height: 140%;
    background:
        radial-gradient(ellipse 70% 40% at 10% 30%, rgba(160,82,45,0.65), rgba(28,25,23,0) 60%),
        radial-gradient(ellipse 40% 60% at 0% 70%, rgba(194,85,26,0.5), rgba(28,25,23,0) 65%),
        radial-gradient(ellipse 50% 40% at 20% 90%, rgba(212,146,42,0.35), rgba(28,25,23,0) 70%);
    animation: washDrift 55s ease-in-out infinite alternate-reverse;
}

@keyframes washDrift {
    0%   { transform: translate(0,0) scale(1); }
    50%  { transform: translate(2%, 1%) scale(1.04); }
    100% { transform: translate(-1%, 2%) scale(0.98); }
}

/* Wash edge between sections — SVG with turbulence displacement */
.wash-edge {
    position: absolute;
    left: 0;
    width: 100%;
    height: 80px;
    pointer-events: none;
    z-index: 3;
}

.wash-edge-bottom {
    bottom: -1px;
}

/* =============================================================
   Heartbeat marker
   ============================================================= */

.heartbeat-marker {
    position: absolute;
    bottom: clamp(1.2rem, 3vh, 2.4rem);
    left: var(--conduit-left);
    transform: translateX(-50%);
    z-index: 4;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.heartbeat {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--kiln);
    box-shadow:
        0 0 0 rgba(194,85,26,0.6),
        0 0 20px rgba(194,85,26,0.35);
    animation: heartbeat 4s ease-in-out infinite;
    filter: url(#watercolor-edge);
}

.heartbeat-marker-light .heartbeat {
    background: var(--gold);
    box-shadow: 0 0 30px rgba(212,146,42,0.6);
}

@keyframes heartbeat {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(194,85,26,0.5), 0 0 18px rgba(194,85,26,0.4);
    }
    40% {
        transform: scale(1.3);
        box-shadow: 0 0 0 22px rgba(194,85,26,0), 0 0 28px rgba(194,85,26,0.55);
    }
    70% {
        transform: scale(1.05);
    }
}

/* =============================================================
   LAYER 0 · Atmospheric
   ============================================================= */

.layer-0 {
    min-height: 100vh;
    background: var(--paper);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding-top: clamp(2.5rem, 5vh, 4rem);
    padding-bottom: clamp(5rem, 10vh, 8rem);
}

.layer-0-inner {
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    gap: clamp(1.5rem, 4vh, 3rem);
    flex: 1;
    justify-content: space-between;
}

.stencil-top {
    display: flex;
    flex-wrap: wrap;
    gap: clamp(1rem, 3vw, 2.5rem);
    opacity: 0;
    animation: fadeIn 1.2s ease-out 0.2s forwards;
}

.infra-title {
    width: 100%;
    margin: clamp(1rem, 4vh, 3rem) 0;
    opacity: 0;
    animation: infraReveal 1.8s cubic-bezier(0.25, 0.8, 0.25, 1) 0.5s forwards;
}

.infra-title svg {
    width: 100%;
    height: auto;
    display: block;
    filter: url(#watercolor-edge);
}

@keyframes infraReveal {
    0%   { opacity: 0; transform: scale(0.94); clip-path: inset(0 100% 0 0); }
    30%  { opacity: 1; }
    100% { opacity: 1; transform: scale(1); clip-path: inset(0 0 0 0); }
}

/* Mesh blob animation inside INFRA clip */
.mesh-blob { transform-origin: center; }
.mb1 { animation: blobDrift1 32s ease-in-out infinite alternate; }
.mb2 { animation: blobDrift2 44s ease-in-out infinite alternate; }
.mb3 { animation: blobDrift3 38s ease-in-out infinite alternate; }
.mb4 { animation: blobDrift4 50s ease-in-out infinite alternate; }

@keyframes blobDrift1 { 0% { transform: translate(0,0) scale(1); } 100% { transform: translate(60px,-30px) scale(1.15); } }
@keyframes blobDrift2 { 0% { transform: translate(0,0) scale(1); } 100% { transform: translate(-80px,40px) scale(0.85); } }
@keyframes blobDrift3 { 0% { transform: translate(0,0) scale(1); } 100% { transform: translate(-40px,50px) scale(1.1); } }
@keyframes blobDrift4 { 0% { transform: translate(0,0) scale(0.9); } 100% { transform: translate(70px,-40px) scale(1.2); } }

.subtitle {
    font-family: var(--font-body);
    font-weight: 300;
    font-size: clamp(1.1rem, 2.4vw, 1.9rem);
    color: var(--carbon);
    line-height: 1.35;
    max-width: 46ch;
    letter-spacing: 0.015em;
    min-height: 1.4em;
}

.subtitle .char {
    display: inline-block;
    opacity: 0;
    position: relative;
    transform: translateY(6px);
}

.subtitle .char.is-visible {
    animation: charBloom 900ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.subtitle .char.space { width: 0.35em; }

.subtitle .char::before {
    content: "";
    position: absolute;
    inset: -20px;
    background: radial-gradient(circle, rgba(194,85,26,0.45) 0%, rgba(194,85,26,0) 65%);
    opacity: 0;
    pointer-events: none;
    border-radius: 50%;
}

.subtitle .char.is-visible::before {
    animation: charBloomBg 700ms ease-out forwards;
}

@keyframes charBloom {
    0%   { opacity: 0; transform: translateY(6px); }
    60%  { opacity: 1; transform: translateY(-1px); }
    100% { opacity: 1; transform: translateY(0); }
}

@keyframes charBloomBg {
    0%   { opacity: 0; transform: scale(0.2); }
    60%  { opacity: 1; transform: scale(1); }
    100% { opacity: 0; transform: scale(1.4); }
}

.stencil-bottom {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    opacity: 0;
    animation: fadeIn 1.4s ease-out 2.2s forwards;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 0.85; transform: translateY(0); }
}

/* =============================================================
   LAYER 1 · Network Stratum
   ============================================================= */

.layer-1 {
    background: var(--carbon);
    color: var(--paper);
    padding-top: clamp(6rem, 12vh, 10rem);
    padding-bottom: clamp(7rem, 14vh, 12rem);
}

.layer-heading {
    max-width: 68ch;
    margin-bottom: clamp(3rem, 8vh, 6rem);
    position: relative;
    z-index: 2;
}

.layer-heading .stencil {
    color: var(--gold);
    margin-bottom: 1rem;
    display: block;
}

.section-title {
    font-family: var(--font-display);
    font-weight: 400;
    font-size: clamp(3rem, 8vw, 6rem);
    line-height: 0.88;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--paper);
    margin-bottom: 1.5rem;
    filter: url(#watercolor-edge);
}

.section-title::first-letter { color: var(--kiln); }

.lede {
    font-family: var(--font-body);
    font-weight: 300;
    font-size: clamp(1.05rem, 1.5vw, 1.35rem);
    line-height: 1.65;
    color: rgba(250,245,238,0.85);
    max-width: 55ch;
}

.lede-light { color: rgba(250,245,238,0.9); }

.conduit-block {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: clamp(2rem, 6vw, 5rem);
    align-items: center;
    padding: clamp(2rem, 6vh, 5rem) 0;
    min-height: 40vh;
    position: relative;
    z-index: 2;
    border-top: 1px solid rgba(160,82,45,0.25);
}

.conduit-block:first-of-type { border-top: none; }

.cb-dark { color: var(--paper); }

.cb-light {
    background: var(--paper);
    color: var(--carbon);
    margin: 0 calc(-1 * var(--pad-x));
    padding-left: calc(var(--pad-x) + var(--conduit-left) + clamp(1.5rem, 4vw, 4rem));
    padding-right: var(--pad-x);
    position: relative;
}

.cb-light::before,
.cb-light::after {
    content: "";
    position: absolute;
    left: 0;
    width: 100%;
    height: 24px;
    pointer-events: none;
    background: linear-gradient(to bottom, var(--carbon), var(--paper));
    filter: url(#watercolor-edge);
    top: -12px;
}
.cb-light::after {
    top: auto;
    bottom: -12px;
    background: linear-gradient(to bottom, var(--paper), var(--carbon));
}

.cb-light .stencil { color: var(--conduit); }
.cb-light .block-title { color: var(--carbon); }

.block-index {
    display: block;
    margin-bottom: 0.8rem;
    color: var(--kiln);
}

.block-title {
    font-family: var(--font-display);
    font-weight: 400;
    font-size: clamp(2.4rem, 5.5vw, 4rem);
    line-height: 0.9;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    margin-bottom: 1.2rem;
    color: var(--paper);
}

.cb-dark .block-title {
    background: linear-gradient(120deg, #faf5ee 0%, #d4922a 60%, #c2551a 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
}

.block-body {
    font-family: var(--font-body);
    font-weight: 300;
    font-size: clamp(1rem, 1.3vw, 1.2rem);
    line-height: 1.7;
    max-width: 44ch;
    margin-bottom: 1.2rem;
}

.cb-dark .block-body { color: rgba(250,245,238,0.82); }
.cb-light .block-body { color: rgba(28,25,23,0.85); }

.block-meta {
    display: block;
    color: var(--conduit);
    padding-top: 0.8rem;
    border-top: 1px dashed rgba(160,82,45,0.35);
    max-width: 36ch;
}

.cb-dark .block-meta { color: var(--gold); }

/* Diagram wrapper */
.cb-diagram {
    position: relative;
    padding: 1rem;
    background: rgba(160,82,45,0.05);
    border: 1px solid rgba(160,82,45,0.18);
    border-radius: 2px;
    min-height: 240px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 0.8rem;
}

.cb-light .cb-diagram {
    background: rgba(160,82,45,0.06);
    border-color: rgba(160,82,45,0.25);
}

.diagram {
    width: 100%;
    height: auto;
    max-height: 260px;
    display: block;
    flex: 1;
    filter: drop-shadow(0 0 0.3px rgba(160,82,45,0.6));
}

.diagram-label {
    font-size: 0.7rem !important;
    color: var(--conduit) !important;
    letter-spacing: 0.18em !important;
    display: block !important;
    text-align: left;
}

/* Sine diagram animation */
.sine-path {
    stroke-dasharray: 1200;
    stroke-dashoffset: 1200;
    animation: draw 3s ease-out forwards, sineFlow 12s linear 3s infinite;
}
.sine-path-2 { animation: draw 3s ease-out 0.4s forwards, sineFlow 14s linear 3.4s infinite reverse; }

@keyframes draw {
    to { stroke-dashoffset: 0; }
}
@keyframes sineFlow {
    0% { stroke-dashoffset: 0; }
    100% { stroke-dashoffset: -600; }
}

.sine-dots circle {
    animation: dotPulse 3s ease-in-out infinite;
    transform-origin: center;
    transform-box: fill-box;
}
.sine-dots circle:nth-child(1) { animation-delay: 0s; }
.sine-dots circle:nth-child(2) { animation-delay: 0.6s; }
.sine-dots circle:nth-child(3) { animation-delay: 1.2s; }
.sine-dots circle:nth-child(4) { animation-delay: 1.8s; }
.sine-dots circle:nth-child(5) { animation-delay: 2.4s; }

@keyframes dotPulse {
    0%, 100% { opacity: 0.4; r: 2.5; }
    50% { opacity: 1; r: 4; }
}

/* Rings diagram */
.ring { transform-origin: center; transform-box: fill-box; }
.ring.r1 { animation: ringSpin 18s linear infinite; }
.ring.r2 { animation: ringSpin 26s linear infinite reverse; }
.ring.r3 { animation: ringSpin 38s linear infinite; }
.ring.r4 { animation: ringSpin 52s linear infinite reverse; }

@keyframes ringSpin { to { transform: rotate(360deg); } }

.ring-nodes circle { animation: dotPulse 3.2s ease-in-out infinite; }
.ring-nodes circle:nth-child(2) { animation-delay: 0.7s; }
.ring-nodes circle:nth-child(3) { animation-delay: 1.4s; }
.ring-nodes circle:nth-child(4) { animation-delay: 2.1s; }
.ring-nodes circle:nth-child(5) { animation-delay: 0.4s; }
.ring-nodes circle:nth-child(6) { animation-delay: 1.1s; }

/* =============================================================
   LAYER 2 · Substrate · Canvas mesh
   ============================================================= */

.layer-2 {
    min-height: 100vh;
    background: var(--obsidian);
    color: var(--paper);
    position: relative;
    overflow: hidden;
    padding-top: clamp(6rem, 14vh, 10rem);
    padding-bottom: clamp(7rem, 14vh, 12rem);
}

.mesh-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
}

.substrate-content {
    position: relative;
    z-index: 2;
    max-width: 72ch;
}

.substrate-content .stencil { color: var(--gold); display: block; margin-bottom: 1rem; }

.substrate-title {
    color: var(--paper);
    text-shadow: 0 0 40px rgba(0,0,0,0.4);
    mix-blend-mode: normal;
    margin-bottom: 2rem;
}

.substrate-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: clamp(1.5rem, 3vw, 3rem);
    margin-top: clamp(3rem, 6vh, 5rem);
    max-width: 72ch;
}

.stat {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 1.2rem 0;
    border-top: 1px solid rgba(250,245,238,0.2);
    position: relative;
}

.stat::before {
    content: "";
    position: absolute;
    top: -1px;
    left: 0;
    width: 40%;
    height: 1px;
    background: var(--kiln);
}

.stat-label { color: rgba(212,146,42,0.85) !important; }

.stat-value {
    font-family: var(--font-display);
    font-weight: 400;
    font-size: clamp(2rem, 4.5vw, 3.4rem);
    color: var(--paper);
    letter-spacing: 0.04em;
    line-height: 0.95;
}

/* =============================================================
   LAYER 3 · The Core
   ============================================================= */

.layer-3 {
    min-height: 50vh;
    background: var(--core);
    position: relative;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding: clamp(3rem, 10vh, 7rem) var(--pad-x) clamp(3rem, 10vh, 7rem) calc(var(--conduit-left) + clamp(1.5rem, 4vw, 4rem));
    overflow: hidden;
}

.core-pulse {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--kiln);
    box-shadow:
        0 0 60px rgba(194,85,26,0.7),
        0 0 120px rgba(194,85,26,0.35);
    animation: corePulse 4s ease-in-out infinite;
    transform-origin: center;
    filter: url(#watercolor-edge-strong);
    position: relative;
    z-index: 2;
}

@keyframes corePulse {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 0 60px rgba(194,85,26,0.7), 0 0 120px rgba(194,85,26,0.35);
    }
    50% {
        transform: scale(40);
        box-shadow: 0 0 200px rgba(194,85,26,0.5), 0 0 400px rgba(212,146,42,0.3);
    }
}

.core-uptime {
    position: absolute;
    bottom: clamp(2rem, 4vh, 3rem);
    left: calc(var(--conduit-left) + clamp(1.5rem, 4vw, 4rem));
    color: var(--gold) !important;
    font-size: 0.75rem !important;
    z-index: 3;
    mix-blend-mode: difference;
}

/* =============================================================
   Responsive
   ============================================================= */

@media (max-width: 860px) {
    .conduit-block {
        grid-template-columns: 1fr;
        gap: 2rem;
    }
    .cb-diagram { order: 2; min-height: 200px; }
    .cb-text { order: 1; }
    .conduit-block:nth-of-type(2n) .cb-diagram { order: 2; }
    .conduit-block:nth-of-type(2n) .cb-text { order: 1; }
    .substrate-stats { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 540px) {
    :root { --conduit-left: 22px; }
    .stencil { gap: 0.8rem; }
    .substrate-stats { grid-template-columns: 1fr 1fr; }
    .infra-title svg { filter: none; }
}

/* Honor prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
