:root {
    --void: #08090E;
    --channel-a: #C8CCD8;
    --channel-b: #00D4FF;
    --accent: #4A3AFF;
    --corruption: #FF8A2B;
    --code-bg: #0A0B10;
    --border: #2A2D3A;
    --module-num: #6E6A8A;
    --error: #FF4A6B;
    --channel-b-offset-x: 6px;
    --channel-b-offset-y: 6px;
    --channel-b-opacity: 0.15;
}

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 400;
    font-size: 15px;
    background-color: var(--void);
    color: var(--channel-a);
    line-height: 1.65;
    letter-spacing: 0.01em;
    position: relative;
    overflow-x: hidden;
}

/* ===== PROGRESS TRACK ===== */
.progress-track {
    position: fixed;
    top: 0;
    left: 0;
    width: 2px;
    height: 0%;
    background-color: var(--channel-b);
    z-index: 1000;
    transition: height 0.1s linear;
}

/* ===== CHANNEL B OVERLAY ===== */
.channel-b {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 900;
    mix-blend-mode: screen;
    opacity: var(--channel-b-opacity);
    transform: translate(var(--channel-b-offset-x), var(--channel-b-offset-y));
    will-change: transform, opacity;
}

/* ===== ORGANIC BLOBS ===== */
.blob {
    position: fixed;
    border-radius: 42% 58% 55% 45% / 48% 40% 60% 52%;
    background: radial-gradient(ellipse at center, var(--accent) 0%, transparent 70%);
    opacity: 0.05;
    pointer-events: none;
    z-index: 1;
    will-change: transform;
}

.blob-1 {
    width: 400px;
    height: 400px;
    top: -100px;
    right: -50px;
    animation: blob-orbit-1 45s ease-in-out infinite;
}

.blob-2 {
    width: 550px;
    height: 550px;
    top: 40%;
    left: -150px;
    border-radius: 55% 45% 48% 52% / 40% 58% 42% 60%;
    animation: blob-orbit-2 60s ease-in-out infinite;
}

.blob-3 {
    width: 350px;
    height: 350px;
    bottom: -50px;
    left: 50%;
    transform: translateX(-50%);
    border-radius: 48% 52% 45% 55% / 55% 45% 52% 48%;
    animation: blob-pulse 30s ease-in-out infinite;
}

@keyframes blob-orbit-1 {
    0%, 100% { transform: translate(0, 0); }
    25% { transform: translate(15px, -21px); }
    50% { transform: translate(30px, 0); }
    75% { transform: translate(15px, 21px); }
}

@keyframes blob-orbit-2 {
    0%, 100% { transform: translate(0, 0); }
    12.5% { transform: translate(10px, -14px); }
    25% { transform: translate(20px, 0); }
    37.5% { transform: translate(10px, 14px); }
    50% { transform: translate(0, 0); }
    62.5% { transform: translate(-10px, -14px); }
    75% { transform: translate(-20px, 0); }
    87.5% { transform: translate(-10px, 14px); }
}

@keyframes blob-pulse {
    0%, 100% { transform: translateX(-50%) scale(0.95); }
    50% { transform: translateX(-50%) scale(1.05); }
}

/* ===== DOCUMENT LAYOUT ===== */
.document {
    position: relative;
    z-index: 10;
    padding: 0;
}

/* ===== MODULE STRUCTURE ===== */
.module {
    position: relative;
    min-height: 90vh;
    padding: 80px 80px 80px 120px;
    opacity: 0;
    transform: translateY(20px);
    transition: none;
}

.module.is-visible {
    opacity: 1;
    transform: translateY(0);
    transition: opacity 0.6s ease, transform 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.module-inner {
    max-width: 900px;
    position: relative;
}

/* ===== MODULE HEADER ===== */
.module-header {
    margin-bottom: 48px;
    position: relative;
    animation: header-glitch 10s steps(1) infinite;
}

.module-number {
    display: block;
    font-family: 'Share Tech Mono', monospace;
    font-size: clamp(2.5rem, 6vw, 5rem);
    font-weight: 400;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--module-num);
    line-height: 1.1;
    margin-bottom: 16px;
    opacity: 0;
    transition: opacity 300ms ease;
}

.module.is-visible .module-number {
    opacity: 1;
}

.glitch-border {
    width: 100%;
    height: 1px;
    background: var(--border);
    margin-bottom: 24px;
    position: relative;
    animation: border-glitch 12s steps(1) infinite;
}

@keyframes border-glitch {
    0%, 100% { background: var(--border); }
    8% { background: repeating-linear-gradient(90deg, var(--border) 0px, var(--border) 10px, transparent 10px, transparent 14px); }
    8.5% { background: var(--border); }
    45% { background: repeating-linear-gradient(90deg, var(--border) 0px, var(--border) 6px, transparent 6px, transparent 8px, var(--border) 8px, var(--border) 20px); }
    45.8% { background: var(--border); }
    72% { background: repeating-linear-gradient(90deg, transparent 0px, transparent 3px, var(--border) 3px, var(--border) 5px); }
    72.5% { background: var(--border); }
}

@keyframes header-glitch {
    0%, 100% { text-shadow: none; transform: translateX(0); }
    87% { text-shadow: none; transform: translateX(0); }
    87.1% { text-shadow: -2px 0 var(--channel-b), 2px 0 var(--corruption); transform: translateX(2px); }
    87.2% { text-shadow: none; transform: translateX(0); }
}

.module-title {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 24px;
    font-weight: 500;
    color: var(--channel-a);
    letter-spacing: 0.04em;
    position: relative;
    overflow: hidden;
}

/* Typewriter cursor for titles during animation */
.module-title.typing::after {
    content: '|';
    color: var(--channel-b);
    animation: cursor-blink 0.6s steps(1) infinite;
    margin-left: 2px;
}

@keyframes cursor-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* Baseline shimmer for individual characters */
.module-title .char {
    display: inline-block;
    animation: baseline-shimmer 3s ease-in-out infinite;
    opacity: 0;
    transition: opacity 0.05s ease;
}

.module-title .char.revealed {
    opacity: 1;
}

@keyframes baseline-shimmer {
    0%, 100% { transform: translateY(0); }
    25% { transform: translateY(-0.5px); }
    75% { transform: translateY(0.5px); }
}

/* ===== EXPLANATION BLOCK ===== */
.explanation-block {
    max-width: 720px;
    margin-bottom: 40px;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 400ms cubic-bezier(0.2, 0.8, 0.2, 1), transform 400ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.module.is-visible .explanation-block {
    opacity: 1;
    transform: translateY(0);
    transition-delay: 0.5s;
}

.explanation-block p {
    margin-bottom: 16px;
    font-size: 15px;
    line-height: 1.65;
}

.explanation-block p:last-child {
    margin-bottom: 0;
}

/* ===== CODE CONTAINER ===== */
.code-container {
    margin: 32px 0;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 400ms ease, transform 400ms ease;
}

.module.is-visible .code-container {
    opacity: 1;
    transform: translateY(0);
    transition-delay: 0.8s;
}

.code-block {
    background-color: var(--code-bg);
    border: 1px solid var(--border);
    padding: 24px;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 13px;
    line-height: 1.7;
    color: var(--channel-a);
    overflow-x: auto;
    border-radius: 2px;
    position: relative;
    white-space: pre;
}

.code-keyword {
    color: var(--accent);
}

.code-string {
    color: var(--channel-b);
}

.code-comment {
    color: var(--module-num);
}

/* ===== ISOMETRIC DIAGRAMS ===== */
.isometric-diagram {
    width: 200px;
    height: 200px;
    position: relative;
    margin: 48px 0;
    margin-left: auto;
    opacity: 0;
    transition: opacity 400ms ease;
    animation: iso-glitch-rotate 15s ease-in-out infinite;
}

.module.is-visible .isometric-diagram {
    opacity: 0.85;
    transition-delay: 1.1s;
}

/* Staggered piece-by-piece assembly for isometric diagrams */
.isometric-diagram > * {
    opacity: 0;
    transition: opacity 150ms ease;
}

.module.is-visible .isometric-diagram > * {
    opacity: 1;
}

.module.is-visible .isometric-diagram > *:nth-child(1) { transition-delay: 1.2s; }
.module.is-visible .isometric-diagram > *:nth-child(2) { transition-delay: 1.28s; }
.module.is-visible .isometric-diagram > *:nth-child(3) { transition-delay: 1.36s; }
.module.is-visible .isometric-diagram > *:nth-child(4) { transition-delay: 1.44s; }

/* Ship hull children stagger */
.ship-hull > .plank {
    opacity: 0;
    transition: opacity 150ms ease;
}

.module.is-visible .ship-hull > .plank:nth-child(1) { opacity: 0.6; transition-delay: 1.2s; }
.module.is-visible .ship-hull > .plank:nth-child(2) { opacity: 0.6; transition-delay: 1.28s; }
.module.is-visible .ship-hull > .plank:nth-child(3) { opacity: 0.6; transition-delay: 1.36s; }
.module.is-visible .ship-hull > .plank:nth-child(4) { opacity: 0.6; transition-delay: 1.44s; }
.module.is-visible .ship-hull > .plank:nth-child(5) { opacity: 0.6; transition-delay: 1.52s; }
.module.is-visible .ship-hull > .plank:nth-child(6) { opacity: 0.6; transition-delay: 1.6s; }
.module.is-visible .ship-hull > .plank:nth-child(7) { opacity: 0.6; transition-delay: 1.68s; }
.module.is-visible .ship-hull > .plank:nth-child(8) { opacity: 0.6; transition-delay: 1.76s; }

@keyframes iso-glitch-rotate {
    0%, 100% { transform: rotate(0deg); }
    93% { transform: rotate(0deg); }
    93.5% { transform: rotate(0.5deg); }
    94% { transform: rotate(-0.5deg); }
    94.5% { transform: rotate(0deg); }
}

/* Liar's Paradox - Nested Speech Bubbles */
.diagram-liar {
    display: flex;
    align-items: center;
    justify-content: center;
}

.iso-bubble {
    position: absolute;
    border: 2px solid;
    border-radius: 4px 4px 4px 0;
    transform: skewX(-10deg) skewY(5deg);
}

.iso-bubble-1 {
    width: 160px;
    height: 120px;
    border-color: var(--channel-b);
    top: 20px;
    left: 20px;
}

.iso-bubble-2 {
    width: 120px;
    height: 90px;
    border-color: var(--accent);
    background: rgba(74, 58, 255, 0.08);
    top: 40px;
    left: 40px;
}

.iso-bubble-3 {
    width: 80px;
    height: 60px;
    border-color: var(--channel-b);
    background: rgba(0, 212, 255, 0.08);
    top: 55px;
    left: 60px;
}

.iso-bubble-4 {
    width: 40px;
    height: 30px;
    border-color: var(--accent);
    top: 70px;
    left: 80px;
    animation: bubble-glitch 4s steps(1) infinite;
}

@keyframes bubble-glitch {
    0%, 100% { background: rgba(74, 58, 255, 0.15); }
    50% { background: transparent; }
}

/* Ship of Theseus - Plank Grid */
.diagram-ship {
    display: flex;
    align-items: center;
    justify-content: center;
}

.ship-hull {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(2, 1fr);
    gap: 3px;
    width: 180px;
    height: 100px;
    transform: skewX(-15deg) skewY(10deg);
}

.plank {
    border: 1px solid var(--border);
    border-radius: 1px;
    transition: background 0.3s ease;
}

.plank-original {
    background: var(--channel-b);
    opacity: 0.6;
}

.plank-transition {
    background: linear-gradient(135deg, var(--channel-b) 0%, var(--corruption) 100%);
    opacity: 0.6;
}

.plank-replaced {
    background: var(--corruption);
    opacity: 0.6;
}

/* Omnipotence Paradox - Spear & Shield */
.diagram-omnipotence {
    display: flex;
    align-items: center;
    justify-content: center;
}

.iso-spear {
    position: absolute;
    width: 8px;
    height: 160px;
    background: linear-gradient(180deg, var(--channel-b), var(--accent));
    transform: rotate(-30deg) skewY(10deg);
    top: 20px;
    left: 50px;
    border-radius: 2px 2px 0 0;
    z-index: 3;
    clip-path: polygon(50% 0%, 100% 10%, 100% 100%, 0% 100%, 0% 10%);
}

.iso-shield {
    position: absolute;
    width: 100px;
    height: 120px;
    border: 3px solid var(--corruption);
    background: rgba(255, 138, 43, 0.08);
    border-radius: 8px 8px 50% 50%;
    transform: skewX(-10deg) skewY(5deg);
    top: 35px;
    left: 70px;
    z-index: 2;
}

.iso-conflict {
    position: absolute;
    width: 30px;
    height: 30px;
    background: radial-gradient(circle, var(--error) 0%, transparent 70%);
    top: 70px;
    left: 85px;
    z-index: 4;
    animation: conflict-pulse 2s ease-in-out infinite;
}

@keyframes conflict-pulse {
    0%, 100% { opacity: 0.3; transform: scale(1); }
    50% { opacity: 0.8; transform: scale(1.3); }
}

/* Zeno's Dichotomy - Recursive Corridor */
.diagram-zeno {
    display: flex;
    align-items: center;
    justify-content: center;
    perspective: 400px;
}

.zeno-corridor {
    display: flex;
    align-items: center;
    transform: rotateY(-15deg) rotateX(10deg);
    transform-style: preserve-3d;
}

.zeno-tile {
    border: 1px solid var(--channel-b);
    background: rgba(0, 212, 255, 0.06);
    margin-right: 2px;
    width: calc(40px * var(--tile-scale));
    height: calc(80px * var(--tile-scale));
    flex-shrink: 0;
    transition: background 0.3s ease;
}

.zeno-tile:nth-child(even) {
    border-color: var(--accent);
    background: rgba(74, 58, 255, 0.06);
}

/* Bootstrap Paradox - Dual Clock */
.diagram-bootstrap {
    display: flex;
    align-items: center;
    justify-content: center;
}

.clock-face {
    width: 140px;
    height: 140px;
    border: 2px solid var(--border);
    border-radius: 50%;
    position: relative;
    transform: skewX(-5deg) skewY(5deg);
}

.clock-hand {
    position: absolute;
    bottom: 50%;
    left: 50%;
    transform-origin: bottom center;
    border-radius: 2px;
}

.clock-hand-forward {
    width: 3px;
    height: 50px;
    background: var(--channel-b);
    animation: clock-forward 8s linear infinite;
    margin-left: -1.5px;
}

.clock-hand-backward {
    width: 3px;
    height: 38px;
    background: var(--corruption);
    animation: clock-backward 8s linear infinite;
    margin-left: -1.5px;
}

.clock-center {
    position: absolute;
    width: 8px;
    height: 8px;
    background: var(--channel-a);
    border-radius: 50%;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

@keyframes clock-forward {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

@keyframes clock-backward {
    from { transform: rotate(0deg); }
    to { transform: rotate(-360deg); }
}

/* ===== RESOLUTION / TERMINAL BLOCK ===== */
.resolution-block {
    background: var(--code-bg);
    border: 1px solid var(--border);
    padding: 20px 24px;
    margin-top: 40px;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 12px;
    font-weight: 300;
    line-height: 1.8;
    color: var(--module-num);
    border-radius: 2px;
    opacity: 0;
    transition: opacity 300ms ease;
}

.module.is-visible .resolution-block {
    opacity: 1;
    transition-delay: 1.6s;
}

.terminal-line {
    padding: 2px 0;
}

.terminal-prompt {
    color: var(--channel-b);
}

.terminal-error {
    color: var(--error);
    border-left: 3px solid var(--error);
    padding-left: 12px;
    margin-left: -3px;
}

/* ===== GLITCH ARTIFACTS ===== */
.glitch-artifact {
    position: relative;
    width: 100%;
    height: 24px;
    overflow: hidden;
    margin: 8px 0;
}

.glitch-artifact::before {
    content: '';
    position: absolute;
    top: 4px;
    left: 0;
    width: 100%;
    height: 3px;
    background: var(--channel-b);
    opacity: 0;
    animation: artifact-flash-1 8s steps(1) infinite;
}

.glitch-artifact::after {
    content: '';
    position: absolute;
    top: 14px;
    left: 15%;
    width: 60%;
    height: 4px;
    background: var(--corruption);
    opacity: 0;
    animation: artifact-flash-2 11s steps(1) infinite;
}

@keyframes artifact-flash-1 {
    0%, 100% { opacity: 0; }
    12% { opacity: 0.7; clip-path: inset(0 20% 0 5%); }
    12.8% { opacity: 0; }
    56% { opacity: 0.5; clip-path: inset(0 10% 0 30%); }
    56.5% { opacity: 0; }
    83% { opacity: 0.6; clip-path: inset(0 40% 0 0%); }
    83.4% { opacity: 0; }
}

@keyframes artifact-flash-2 {
    0%, 100% { opacity: 0; }
    23% { opacity: 0.6; clip-path: inset(0 5% 0 25%); }
    23.6% { opacity: 0; }
    67% { opacity: 0.8; clip-path: inset(0 30% 0 10%); }
    67.4% { opacity: 0; }
}

.glitch-artifact-final {
    height: 48px;
    margin: 24px 0;
}

.glitch-artifact-final::before {
    height: 5px;
    top: 8px;
}

.glitch-artifact-final::after {
    height: 6px;
    top: 28px;
    width: 80%;
    left: 5%;
}

/* ===== COLOPHON ===== */
.colophon {
    padding: 80px 120px;
    border-top: 1px solid var(--border);
}

.colophon-inner {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.colophon-text {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 13px;
    font-weight: 400;
    color: var(--module-num);
    letter-spacing: 0.02em;
}

.colophon-meta {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 11px;
    font-weight: 300;
    color: var(--error);
    letter-spacing: 0.01em;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .module {
        padding: 60px 24px 60px 40px;
    }

    .colophon {
        padding: 60px 40px;
    }

    .module-number {
        font-size: clamp(1.8rem, 8vw, 3rem);
    }

    .isometric-diagram {
        width: 160px;
        height: 160px;
        margin-left: 0;
    }

    .blob-1 {
        width: 250px;
        height: 250px;
    }

    .blob-2 {
        width: 350px;
        height: 350px;
    }

    .blob-3 {
        width: 200px;
        height: 200px;
    }
}
