/* ============================================
   bability.pro - Corrupted Pastoral Transmission
   ============================================ */

/* -- Reset & Base -- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

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

body {
    background-color: #FAF5EE;
    color: #2D2A3E;
    font-family: 'DM Sans', sans-serif;
    font-weight: 400;
    font-size: 17px;
    line-height: 1.7;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* -- Scan-line Overlay (Layer 3 - nearest) -- */
#scanline-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    pointer-events: none;
    background: repeating-linear-gradient(
        to bottom,
        rgba(255, 214, 224, 0.08) 0px,
        rgba(255, 214, 224, 0.08) 1px,
        transparent 1px,
        transparent 4px
    );
}

/* -- Noise Grain Overlay -- */
#noise-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 999;
    pointer-events: none;
    opacity: 1;
}

#noise-overlay svg {
    width: 100%;
    height: 100%;
}

/* -- Fixed Navigation -- */
#fixed-nav {
    position: fixed;
    top: 24px;
    left: 28px;
    z-index: 1001;
}

.nav-domain {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 300;
    font-size: 11px;
    color: #6B6580;
    letter-spacing: 0.05em;
    text-transform: none;
}

.nav-dot {
    display: inline-block;
    color: #F2A7B0;
    animation: dot-flicker 6s infinite;
}

@keyframes dot-flicker {
    0%, 48% { color: #F2A7B0; }
    49% { color: #A8B8E8; transform: translateX(1px); }
    50% { color: #A8B8E8; }
    51% { color: #A8B8E8; transform: translateX(-1px); }
    52%, 100% { color: #F2A7B0; }
}

/* -- Transmission Segments -- */
.transmission-segment {
    position: relative;
    width: 100%;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    perspective: 1000px;
}

/* -- Scrim Layers -- */
.scrim-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.layer-bg {
    z-index: 1;
    opacity: 0.15;
    transform: translateZ(-100px) scale(1.1);
    transform-style: preserve-3d;
}

.layer-bg-dominant {
    opacity: 0.6;
}

.layer-content {
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
}

.layer-crystals {
    z-index: 5;
    pointer-events: none;
}

/* -- Pastoral Illustrations -- */
.pastoral-illustration {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* Meadow Sage for SVG pastoral fills */
.pastoral-illustration path[fill="#B5D8C2"] {
    fill: #B5D8C2;
}

/* Phosphor Pink for glitch noise tinting */
.glitch-artifact {
    background-color: #FFD6E0;
}

/* SVG path drawing animation */
.draw-path {
    opacity: 0;
}

.draw-path.primary-outline {
    stroke-dasharray: 2000;
    stroke-dashoffset: 2000;
}

.draw-path.hatching {
    stroke-dasharray: 500;
    stroke-dashoffset: 500;
}

.transmission-segment.in-view .draw-path.primary-outline {
    animation: draw-stroke 2.5s cubic-bezier(0.22, 1, 0.36, 1) forwards;
    opacity: 1;
}

.transmission-segment.in-view .draw-path.hatching {
    animation: draw-stroke 1.5s cubic-bezier(0.22, 1, 0.36, 1) 0.5s forwards;
    opacity: 1;
}

@keyframes draw-stroke {
    0% {
        stroke-dashoffset: 2000;
    }
    95% {
        stroke-dashoffset: 0;
    }
    96% {
        stroke-dashoffset: 0;
        transform: translateX(4px);
    }
    97% {
        transform: translateX(0);
    }
    100% {
        stroke-dashoffset: 0;
        transform: translateX(0);
    }
}

/* -- Segment Content -- */
.segment-content {
    position: relative;
    max-width: 1400px;
    width: 100%;
    padding: 60px 48px;
    opacity: 0;
    transform: scale(0.85);
    transition: opacity 800ms cubic-bezier(0.22, 1, 0.36, 1),
                transform 800ms cubic-bezier(0.22, 1, 0.36, 1);
}

.transmission-segment.in-view .segment-content {
    opacity: 1;
    transform: scale(1);
}

/* Background zoom-focus pull */
.transmission-segment.in-view .layer-bg {
    animation: bg-focus-pull 800ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

@keyframes bg-focus-pull {
    0% {
        transform: translateZ(-100px) scale(1.25);
    }
    100% {
        transform: translateZ(-100px) scale(1.1);
    }
}

/* -- Layout Positions -- */
.segment-left {
    padding-left: calc((100% / 12) * 1.5);
    max-width: calc((100% / 12) * 7);
}

.segment-right {
    margin-left: auto;
    padding-right: calc((100% / 12) * 1.5);
    max-width: calc((100% / 12) * 7);
    text-align: right;
}

.segment-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    max-width: 900px;
    margin: 0 auto;
}

/* -- Segment 1 Special Layout -- */
.segment-1-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    max-width: 100%;
}

.segment-1-content .display-heading {
    font-size: clamp(72px, 12vw, 160px);
    line-height: 1;
    margin-bottom: 24px;
}

/* -- Typography -- */
.display-heading {
    font-family: 'Playfair Display', serif;
    font-weight: 900;
    font-size: clamp(56px, 9vw, 140px);
    line-height: 0.95;
    letter-spacing: -0.04em;
    color: #2D2A3E;
    margin-bottom: 32px;
    position: relative;
}

/* Glitch chromatic aberration on headings */
.glitch-text {
    text-shadow: 3px 0 #F2A7B0, -3px 0 #A8B8E8;
}

.glitch-text.glitching {
    animation: glitch-shift 400ms ease-out;
}

@keyframes glitch-shift {
    0% {
        text-shadow: 3px 0 #F2A7B0, -3px 0 #A8B8E8;
    }
    20% {
        text-shadow: 10px 0 #F2A7B0, -10px 0 #A8B8E8;
        transform: translateX(-4px);
    }
    40% {
        text-shadow: -8px 2px #F2A7B0, 8px -2px #A8B8E8;
        transform: translateX(6px);
    }
    60% {
        text-shadow: 12px -1px #F2A7B0, -12px 1px #A8B8E8;
        transform: translateX(-2px);
    }
    80% {
        text-shadow: -4px 0 #F2A7B0, 4px 0 #A8B8E8;
        transform: translateX(1px);
    }
    100% {
        text-shadow: 3px 0 #F2A7B0, -3px 0 #A8B8E8;
        transform: translateX(0);
    }
}

/* Scan-line displacement on glitch */
.glitch-text::before,
.glitch-text::after {
    content: attr(data-text);
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    font-family: inherit;
    font-weight: inherit;
    font-size: inherit;
    line-height: inherit;
    letter-spacing: inherit;
    opacity: 0;
    pointer-events: none;
}

.glitch-text::before {
    color: #F2A7B0;
    clip-path: inset(30% 0 40% 0);
}

.glitch-text::after {
    color: #A8B8E8;
    clip-path: inset(60% 0 10% 0);
}

.glitch-text.glitching::before {
    opacity: 0.7;
    animation: slice-shift-1 400ms ease-out;
}

.glitch-text.glitching::after {
    opacity: 0.7;
    animation: slice-shift-2 400ms ease-out;
}

@keyframes slice-shift-1 {
    0% { transform: translateX(0); }
    25% { transform: translateX(8px); }
    50% { transform: translateX(-6px); }
    75% { transform: translateX(10px); }
    100% { transform: translateX(0); }
}

@keyframes slice-shift-2 {
    0% { transform: translateX(0); }
    25% { transform: translateX(-10px); }
    50% { transform: translateX(6px); }
    75% { transform: translateX(-8px); }
    100% { transform: translateX(0); }
}

.body-text {
    font-family: 'DM Sans', sans-serif;
    font-weight: 400;
    font-size: 17px;
    line-height: 1.7;
    color: #2D2A3E;
    max-width: 540px;
    margin-bottom: 24px;
}

.segment-right .body-text {
    margin-left: auto;
}

.transmission-meta {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 300;
    font-size: 12px;
    color: #6B6580;
    letter-spacing: 0.06em;
    display: block;
    margin-top: 8px;
}

/* -- Interlude Segments -- */
.interlude {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.interlude .transmission-meta {
    opacity: 0.6;
}

/* -- Crystal Clusters -- */
.crystal-cluster {
    position: absolute;
}

.crystal {
    display: block;
    transition: transform 300ms ease;
}

.crystal:hover {
    transform: translate(2px, -3px);
}

.cluster-1 {
    top: 15%;
    right: 8%;
    display: flex;
    flex-direction: column;
    gap: 8px;
    transform: rotate(-12deg);
}

.cluster-2 {
    bottom: 20%;
    left: 5%;
    display: flex;
    gap: 6px;
    transform: rotate(8deg);
}

.cluster-3 {
    top: 25%;
    left: 6%;
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    max-width: 120px;
    transform: rotate(-5deg);
}

.cluster-4 {
    bottom: 18%;
    right: 10%;
    display: flex;
    gap: 8px;
    transform: rotate(15deg);
}

/* -- Dark Segment (End Transmission) -- */
.segment-dark {
    background-color: #3E3566;
}

.segment-dark .display-heading {
    color: #FAF5EE;
    text-shadow: 3px 0 rgba(242, 167, 176, 0.5), -3px 0 rgba(168, 184, 232, 0.5);
}

.segment-dark .transmission-meta {
    color: #A8B8E8;
}

.final-meta {
    margin-top: 16px;
}

.final-domain {
    margin-top: 60px;
    opacity: 0.4;
}

.final-domain .nav-domain {
    font-size: 13px;
    color: #EDE4F3;
}

/* -- Zoom-Focus Glitch Artifact -- */
.glitch-artifact {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 20;
    opacity: 0;
}

.glitch-artifact.active {
    animation: artifact-flash 150ms ease-out;
}

@keyframes artifact-flash {
    0% {
        opacity: 1;
    }
    25% {
        opacity: 1;
        transform: translateX(8px);
    }
    50% {
        opacity: 1;
        transform: translateX(-6px);
    }
    75% {
        opacity: 0.5;
        transform: translateX(4px);
    }
    100% {
        opacity: 0;
        transform: translateX(0);
    }
}

/* -- Signal Correction Animation (for segment 1 initial load) -- */
@keyframes signal-correct {
    0% { transform: translateX(0); }
    10% { transform: translateX(-8px); }
    20% { transform: translateX(6px); }
    30% { transform: translateX(-5px); }
    40% { transform: translateX(7px); }
    50% { transform: translateX(-4px); }
    60% { transform: translateX(3px); }
    70% { transform: translateX(-2px); }
    80% { transform: translateX(1px); }
    100% { transform: translateX(0); }
}

.signal-correcting {
    animation: signal-correct 150ms ease-out;
}

/* -- Glitch Slice Displacement for Zoom-Focus -- */
.slice-displaced {
    position: relative;
}

.slice-displaced::before {
    content: '';
    position: absolute;
    top: 30%;
    left: 0;
    width: 100%;
    height: 15%;
    background: inherit;
    clip-path: inset(0);
    transform: translateX(8px);
    opacity: 0;
    pointer-events: none;
    z-index: 25;
}

.slice-displaced.active::before {
    opacity: 0.6;
    animation: slice-pop 150ms ease-out forwards;
}

@keyframes slice-pop {
    0% { transform: translateX(8px); opacity: 0.6; }
    50% { transform: translateX(-6px); opacity: 0.4; }
    100% { transform: translateX(0); opacity: 0; }
}

/* -- Mobile Adaptation -- */
@media (max-width: 768px) {
    .segment-content {
        padding: 40px 24px;
    }

    .segment-left,
    .segment-right {
        padding-left: 24px;
        padding-right: 24px;
        max-width: 100%;
        margin-left: 0;
        text-align: left;
    }

    .segment-right .body-text {
        margin-left: 0;
    }

    .display-heading {
        font-size: clamp(48px, 14vw, 96px);
    }

    .segment-1-content .display-heading {
        font-size: clamp(48px, 16vw, 96px);
    }

    .body-text {
        font-size: 16px;
        max-width: 100%;
    }

    .layer-bg {
        transform: none;
    }

    .transmission-segment.in-view .layer-bg {
        animation: none;
    }

    .crystal-cluster {
        display: none;
    }

    #fixed-nav {
        top: 16px;
        left: 16px;
    }

    .cluster-1,
    .cluster-2,
    .cluster-3,
    .cluster-4 {
        display: none;
    }
}

@media (max-width: 480px) {
    .display-heading {
        font-size: clamp(40px, 16vw, 72px);
    }

    .segment-1-content .display-heading {
        font-size: clamp(40px, 18vw, 80px);
    }

    .transmission-meta {
        font-size: 10px;
    }
}

/* -- Reduced motion preference -- */
@media (prefers-reduced-motion: reduce) {
    .draw-path.primary-outline,
    .draw-path.hatching {
        animation: none;
        opacity: 1;
        stroke-dashoffset: 0;
    }

    .segment-content {
        opacity: 1;
        transform: none;
        transition: none;
    }

    .glitch-text {
        text-shadow: none;
    }

    .nav-dot {
        animation: none;
    }
}
