/* layer2.quest -- Glitch Art Compression */

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

:root {
    --void: #0A0A0F;
    --raw-signal: #4ECDC4;
    --red-channel: #FF6B6B;
    --blue-channel: #45B7D1;
    --green-channel: #98D89E;
    --compressed-white: #E8E8F0;
    --proof-gold: #D4A843;
    --funnel-gray: #2A2A3A;
    --font-display: 'Azeret Mono', monospace;
    --font-body: 'Work Sans', sans-serif;
    --font-data: 'Fragment Mono', monospace;
}

html {
    scroll-behavior: smooth;
    scroll-snap-type: y mandatory;
}

body {
    background: var(--void);
    color: var(--compressed-white);
    font-family: var(--font-body);
    font-weight: 300;
    font-size: clamp(0.85rem, 1.2vw, 1.1rem);
    line-height: 1.75;
    overflow-x: hidden;
}

/* ---- Scanline Overlay ---- */
.scanline-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000;
    background: repeating-linear-gradient(
        to bottom,
        transparent 0px,
        transparent 1px,
        rgba(10, 10, 15, 0.15) 1px,
        rgba(10, 10, 15, 0.15) 2px
    );
}

/* ---- Progress Bar ---- */
.progress-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 2px;
    display: flex;
    z-index: 999;
}

.progress-segment {
    flex: 1;
    opacity: 0.2;
    transition: opacity 0.3s ease;
}

.progress-segment.active {
    opacity: 1;
}

/* ---- Stages ---- */
.stage {
    min-height: 100vh;
    scroll-snap-align: start;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

/* ---- Stage Labels ---- */
.stage-label-container {
    position: relative;
    z-index: 10;
    text-align: center;
}

.stage-label {
    font-family: var(--font-display);
    font-weight: 500;
    font-size: clamp(3rem, 8vw, 7rem);
    letter-spacing: 0.5em;
    text-transform: uppercase;
    color: var(--compressed-white);
    position: relative;
    text-shadow:
        -2px 0 var(--red-channel),
        2px 0 var(--blue-channel);
}

.stage-desc {
    font-family: var(--font-body);
    font-weight: 300;
    font-size: 1rem;
    color: var(--raw-signal);
    margin-top: 1rem;
    opacity: 0.7;
}

/* ---- Stage 1: RAW ---- */
.stage-raw {
    background: var(--void);
}

.rain-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

.stage-raw .stage-label-container {
    z-index: 5;
}

.stage-raw .stage-label {
    color: var(--raw-signal);
    text-shadow:
        -2px 0 rgba(255, 107, 107, 0.5),
        2px 0 rgba(69, 183, 209, 0.5);
}

/* ---- Stage 2: BATCH ---- */
.stage-batch {
    background: var(--void);
    padding: 4rem 2rem;
}

.batch-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2rem;
    max-width: 800px;
    width: 100%;
}

.frosted-panel {
    background: rgba(42, 42, 58, 0.4);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    border: 1px solid rgba(232, 232, 240, 0.1);
    padding: 1.5rem;
    max-width: 38ch;
    box-shadow:
        -2px 0 0 var(--red-channel),
        2px 0 0 var(--blue-channel);
}

.batch-blocks {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    min-height: 200px;
    position: relative;
}

.batch-block {
    width: 120px;
    height: 80px;
    border: 1px solid var(--compressed-white);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-data);
    font-size: clamp(0.5rem, 0.8vw, 0.7rem);
    letter-spacing: 0.05em;
    color: var(--raw-signal);
    overflow: hidden;
    transition: transform 0.8s cubic-bezier(0.23, 1, 0.32, 1),
                width 0.8s cubic-bezier(0.23, 1, 0.32, 1),
                height 0.8s cubic-bezier(0.23, 1, 0.32, 1),
                opacity 0.4s ease;
    box-shadow:
        -1px 0 0 rgba(255, 107, 107, 0.3),
        1px 0 0 rgba(69, 183, 209, 0.3);
    will-change: transform;
}

.batch-block:hover {
    box-shadow:
        -3px 0 0 var(--red-channel),
        3px 0 0 var(--blue-channel);
}

.batch-block .block-data {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 4px;
    font-size: 6px;
    line-height: 1.2;
    word-break: break-all;
    white-space: pre-wrap;
}

/* ---- Stage 3: COMPRESS ---- */
.stage-compress {
    background: var(--funnel-gray);
    padding: 4rem 2rem;
    min-height: 120vh;
}

.funnel-container {
    position: relative;
    width: 100%;
    max-width: 600px;
    height: 800px;
    margin: 2rem auto;
}

.funnel-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

.funnel-line {
    stroke-dasharray: 1200;
    stroke-dashoffset: 1200;
    animation: funnelDraw 4s ease forwards;
}

.funnel-glow {
    stroke-dasharray: 10 20;
    animation: funnelFlow 3s linear infinite;
}

@keyframes funnelDraw {
    to { stroke-dashoffset: 0; }
}

@keyframes funnelFlow {
    0% { stroke-dashoffset: 30; }
    100% { stroke-dashoffset: 0; }
}

.compress-blocks {
    position: absolute;
    top: 40px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    justify-content: center;
    width: 80%;
    z-index: 2;
}

.compress-block {
    width: 40px;
    height: 40px;
    border: 1px solid var(--compressed-white);
    opacity: 0.5;
    transition: transform 1s ease, opacity 1s ease;
}

.compress-block.shrinking {
    transform: scale(0.3) translateY(300px);
    opacity: 0;
}

.compressed-glyph {
    position: absolute;
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 3;
    animation: glyphPulse 4s ease-in-out infinite;
}

.glyph-svg {
    width: 48px;
    height: 48px;
    filter: drop-shadow(0 0 12px rgba(212, 168, 67, 0.4));
}

@keyframes glyphPulse {
    0%, 100% { transform: translateX(-50%) scale(1); }
    50% { transform: translateX(-50%) scale(1.02); }
}

/* ---- Stage 4: VERIFY ---- */
.stage-verify {
    background: var(--void);
    padding: 4rem 2rem;
}

.verify-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2rem;
    max-width: 800px;
    width: 100%;
}

.verify-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
    max-width: 360px;
}

.verify-shape {
    width: 100px;
    height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transform: scale(0.8);
    transition: opacity 0.5s ease, transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.verify-shape.visible {
    opacity: 1;
    transform: scale(1);
}

.verify-shape svg {
    width: 80px;
    height: 80px;
}

.check-path {
    stroke-dasharray: 100;
    stroke-dashoffset: 100;
    transition: stroke-dashoffset 0.6s ease;
}

.verify-shape.checked .check-path {
    stroke-dashoffset: 0;
}

.stage-verify .stage-label {
    color: var(--blue-channel);
}

/* ---- Stage 5: COMMIT ---- */
.stage-commit {
    background: var(--void);
}

.commit-center {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2rem;
}

.proof-glyph {
    opacity: 0;
    transition: opacity 2s ease;
}

.proof-glyph.visible {
    opacity: 1;
}

.proof-svg {
    width: 48px;
    height: 48px;
    filter: drop-shadow(0 0 16px rgba(212, 168, 67, 0.5));
    animation: proofPulse 4s ease-in-out infinite;
}

@keyframes proofPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.02); }
}

.hash-output {
    font-family: var(--font-data);
    font-size: clamp(0.5rem, 0.8vw, 0.7rem);
    letter-spacing: 0.05em;
    color: var(--proof-gold);
    min-height: 1.5em;
}

.commit-label {
    color: var(--proof-gold);
    text-shadow:
        -1px 0 rgba(255, 107, 107, 0.3),
        1px 0 rgba(69, 183, 209, 0.3);
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
    .stage-label {
        font-size: clamp(2rem, 6vw, 4rem);
        letter-spacing: 0.3em;
        text-shadow:
            -1px 0 var(--red-channel),
            1px 0 var(--blue-channel);
    }

    .batch-block {
        width: 80px;
        height: 60px;
    }

    .frosted-panel {
        box-shadow:
            -1px 0 0 var(--red-channel),
            1px 0 0 var(--blue-channel);
    }

    .verify-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .verify-shape {
        width: 80px;
        height: 80px;
    }
}

/* ---- Reduced Motion ---- */
@media (prefers-reduced-motion: reduce) {
    html {
        scroll-snap-type: none;
    }

    .stage-label {
        text-shadow: none;
    }

    .funnel-line {
        stroke-dashoffset: 0;
        animation: none;
    }

    .funnel-glow {
        animation: none;
    }

    .compressed-glyph {
        animation: none;
    }

    .proof-svg {
        animation: none;
    }

    .proof-glyph {
        opacity: 1;
        transition: none;
    }

    .verify-shape {
        opacity: 1;
        transform: scale(1);
        transition: none;
    }

    .check-path {
        stroke-dashoffset: 0;
        transition: none;
    }

    .batch-block {
        transition: none;
    }
}
