/* ============================================================
   bada.quest - Corrupted Field Journal / Geological Strata
   ============================================================ */

:root {
    --crust-bg: #F2E4D1;
    --mantle-bg: #D4C4A8;
    --core-bg: #5C4033;
    --basalt-bg: #2A1F17;
    --text-dark: #3D2E1F;
    --text-light: #F5EDE0;
    --accent-green: #7A9E7E;
    --accent-sienna: #C75B39;
    --accent-clay: #B5654A;
    --fault-duration: 200ms;
    --parallax-slow: 0.35;
    --parallax-fast: 1.15;
}

/* ---- Reset & Base ---- */

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

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

body {
    font-family: 'Source Serif 4', Georgia, serif;
    font-weight: 400;
    font-size: clamp(1rem, 1.8vw, 1.2rem);
    line-height: 1.85;
    letter-spacing: 0.005em;
    color: var(--text-dark);
    background-color: var(--crust-bg);
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.svg-filters {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
}

/* ---- Typography ---- */

.site-title {
    font-family: 'Nunito Sans', 'Segoe UI', sans-serif;
    font-weight: 700;
    font-size: clamp(2.5rem, 6vw, 5.5rem);
    letter-spacing: -0.01em;
    line-height: 1.2;
    color: var(--text-dark);
    position: relative;
}

.section-heading {
    font-family: 'Nunito Sans', 'Segoe UI', sans-serif;
    font-weight: 700;
    font-size: clamp(1.6rem, 3vw, 2.8rem);
    letter-spacing: -0.01em;
    line-height: 1.2;
    color: inherit;
    margin-bottom: 0.5em;
    position: relative;
    cursor: default;
}

#core .section-heading,
#bedrock .section-heading {
    font-size: clamp(2.2rem, 5vw, 4rem);
}

.caveat-text {
    font-family: 'Caveat', cursive;
    font-weight: 400;
    font-size: clamp(0.9rem, 1.5vw, 1.1rem);
    opacity: 0.7;
}

.subtitle {
    margin-top: 0.75em;
    margin-bottom: 2em;
}

.annotation {
    margin-bottom: 2em;
    display: block;
}

.light-annotation {
    color: var(--text-light);
}

.body-text {
    max-width: 60ch;
    margin-bottom: 1.5em;
}

.light-text {
    color: var(--text-light);
}

/* ---- Glitch Heading Hover ---- */

.glitch-heading {
    position: relative;
    display: inline-block;
}

.glitch-heading::before,
.glitch-heading::after {
    content: attr(data-text);
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    pointer-events: none;
}

.glitch-heading::before {
    color: var(--accent-sienna);
    z-index: -1;
}

.glitch-heading::after {
    color: var(--accent-green);
    z-index: -1;
}

.glitch-heading.tremor::before {
    opacity: 0.6;
    transform: translate(-1px, -2px);
    animation: glitch-red 150ms ease-out forwards;
}

.glitch-heading.tremor::after {
    opacity: 0.6;
    transform: translate(1px, 2px);
    animation: glitch-green 150ms ease-out forwards;
}

@keyframes glitch-red {
    0% { transform: translate(-1px, -2px); opacity: 0.6; }
    100% { transform: translate(0, 0); opacity: 0; }
}

@keyframes glitch-green {
    0% { transform: translate(1px, 2px); opacity: 0.6; }
    100% { transform: translate(0, 0); opacity: 0; }
}

/* ---- Margin Notes ---- */

.margin-note {
    position: absolute;
    font-family: 'Caveat', cursive;
    font-size: clamp(0.8rem, 1.2vw, 1rem);
    color: var(--accent-sienna);
    opacity: 0.4;
    pointer-events: none;
    white-space: nowrap;
    transform: rotate(-2deg);
}

.light-note {
    color: var(--text-light);
    opacity: 0.35;
}

/* ---- Strata Sections ---- */

.stratum {
    position: relative;
    width: 100%;
    overflow: hidden;
}

#crust {
    min-height: 100vh;
    background-color: var(--crust-bg);
    color: var(--text-dark);
    display: flex;
    align-items: flex-start;
    padding-top: 12vh;
}

#mantle {
    min-height: 100vh;
    background-color: var(--mantle-bg);
    color: var(--text-dark);
    display: flex;
    align-items: flex-start;
    padding-top: 10vh;
}

#core {
    min-height: 80vh;
    background-color: var(--core-bg);
    color: var(--text-light);
    display: flex;
    align-items: flex-start;
    padding-top: 10vh;
}

#bedrock {
    min-height: 100vh;
    background-color: var(--basalt-bg);
    color: var(--text-light);
    display: flex;
    align-items: center;
    justify-content: flex-start;
}

/* ---- Stratum Content ---- */

.stratum-content {
    position: relative;
    z-index: 2;
    padding-left: 12vw;
    padding-right: 5vw;
    width: 60%;
    min-width: 300px;
}

#bedrock .stratum-content {
    padding-top: 0;
}

/* ---- Illustrations ---- */

.crust-illustration {
    position: absolute;
    right: 5vw;
    top: 15vh;
    width: 40%;
    max-width: 500px;
    z-index: 1;
}

.mantle-illustration {
    position: absolute;
    right: 3vw;
    top: 20%;
    width: 35%;
    max-width: 400px;
    z-index: 1;
    opacity: 0.7;
}

.core-illustration {
    position: absolute;
    right: 5vw;
    top: 15%;
    width: 30%;
    max-width: 350px;
    z-index: 1;
    opacity: 0.6;
}

.bedrock-illustration {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 50%;
    max-width: 600px;
    z-index: 1;
    opacity: 0.4;
}

.blob-illustration {
    width: 100%;
    height: auto;
}

/* Blob drift animation for crust */
.blob-drift {
    animation: blob-drift 8s ease-in-out infinite;
}

@keyframes blob-drift {
    0% { transform: translate(0, 0); }
    25% { transform: translate(3px, -2px); }
    50% { transform: translate(-2px, 4px); }
    75% { transform: translate(4px, 1px); }
    100% { transform: translate(0, 0); }
}

/* ---- Contour Lines ---- */

.contour-lines {
    position: absolute;
    z-index: 1;
    pointer-events: none;
}

.crust-contours {
    left: 45%;
    top: 30%;
    width: 20%;
    opacity: 0.8;
}

.mantle-contours {
    right: 2%;
    top: 60%;
    width: 15%;
    opacity: 0.7;
}

/* ---- Blob Dividers ---- */

.blob-divider {
    width: 70%;
    height: 25px;
    margin: 1.5em 0;
    opacity: 0.8;
}

.blob-divider svg {
    width: 100%;
    height: 100%;
}

/* ---- Fault Lines ---- */

.fault-line {
    position: relative;
    height: 15vh;
    overflow: hidden;
    z-index: 5;
}

.fault-line-intense {
    height: 18vh;
}

.fault-strip {
    width: 100%;
    height: 10px;
    position: relative;
    transform: translateX(0);
    transition: transform var(--fault-duration) ease-out;
    will-change: transform;
}

.fault-strip.wide {
    height: 18px;
}

/* Colors applied by position and context */
#fault-1 {
    background: linear-gradient(to bottom, var(--crust-bg), var(--mantle-bg));
}

#fault-1 .fault-strip:nth-child(odd) {
    background-color: var(--crust-bg);
}

#fault-1 .fault-strip:nth-child(even) {
    background-color: var(--mantle-bg);
}

#fault-2 {
    background: linear-gradient(to bottom, var(--mantle-bg), var(--core-bg));
}

#fault-2 .fault-strip:nth-child(odd) {
    background-color: var(--mantle-bg);
}

#fault-2 .fault-strip:nth-child(even) {
    background-color: var(--core-bg);
}

#fault-3 {
    background: linear-gradient(to bottom, var(--core-bg), var(--basalt-bg));
}

#fault-3 .fault-strip:nth-child(odd) {
    background-color: var(--core-bg);
}

#fault-3 .fault-strip:nth-child(even) {
    background-color: var(--basalt-bg);
}

/* Activated fault strips */
.fault-strip.active {
    transform: translateX(var(--strip-offset, 0));
}

/* Chromatic aberration on intense fault */
.fault-line-intense .fault-strip.active:nth-child(3n) {
    box-shadow: -4px 0 0 rgba(199, 91, 57, 0.6), 4px 0 0 rgba(122, 158, 126, 0.6);
}

/* Fault hatching */
.fault-hatching {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: repeating-linear-gradient(
        45deg,
        transparent,
        transparent 3px,
        rgba(61, 46, 31, 0.06) 3px,
        rgba(61, 46, 31, 0.06) 4px
    );
    pointer-events: none;
    opacity: 0;
    transition: opacity 300ms ease;
}

.fault-line.activated .fault-hatching {
    opacity: 1;
}

/* Chromatic flash colors for fault strips */
.fault-strip.flash-green {
    background-color: var(--accent-green) !important;
    transition: background-color 100ms ease;
}

.fault-strip.flash-sienna {
    background-color: var(--accent-sienna) !important;
    transition: background-color 100ms ease;
}

/* ---- Vertical Navigation ---- */

#strata-nav {
    position: fixed;
    right: 2vw;
    top: 50%;
    transform: translateY(-50%);
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
}

.nav-line {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 1px;
    background-color: rgba(242, 228, 209, 0.3);
    z-index: -1;
}

.nav-marker {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 1px solid rgba(242, 228, 209, 0.4);
    background-color: transparent;
    transition: background-color 0.6s cubic-bezier(0.34, 1.56, 0.64, 1),
                border-color 0.6s cubic-bezier(0.34, 1.56, 0.64, 1),
                transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
    cursor: pointer;
}

.nav-marker.active {
    background-color: var(--accent-green);
    border-color: var(--accent-green);
    transform: scale(1.3);
}

/* Adapt nav line color for dark/light sections */
body.in-light-section .nav-line {
    background-color: rgba(61, 46, 31, 0.15);
}

body.in-light-section .nav-marker {
    border-color: rgba(61, 46, 31, 0.3);
}

body.in-light-section .nav-marker.active {
    border-color: var(--accent-green);
}

/* ---- Load Fault Overlay ---- */

.load-fault-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    pointer-events: none;
    opacity: 0;
}

.load-fault-overlay.active {
    animation: load-fault-in 400ms ease-out forwards;
}

@keyframes load-fault-in {
    0% {
        opacity: 1;
        background: repeating-linear-gradient(
            0deg,
            transparent 0px,
            transparent 8px,
            var(--crust-bg) 8px,
            var(--crust-bg) 10px
        );
        transform: translateX(0);
    }
    30% {
        opacity: 1;
        background: repeating-linear-gradient(
            0deg,
            transparent 0px,
            transparent 6px,
            var(--accent-sienna) 6px,
            var(--accent-sienna) 9px,
            transparent 9px,
            transparent 14px,
            var(--accent-green) 14px,
            var(--accent-green) 16px
        );
        transform: translateX(5px);
    }
    70% {
        opacity: 0.6;
        transform: translateX(-3px);
    }
    100% {
        opacity: 0;
        transform: translateX(0);
    }
}

/* ---- Parallax Elements ---- */

.parallax-element {
    will-change: transform;
    transition: transform 0.1s linear;
}

/* ---- Responsive ---- */

@media (max-width: 900px) {
    .stratum-content {
        width: 85%;
        padding-left: 8vw;
        padding-right: 5vw;
    }

    .crust-illustration {
        width: 50%;
        right: 2vw;
        opacity: 0.5;
    }

    .mantle-illustration,
    .core-illustration {
        width: 40%;
        opacity: 0.4;
    }

    .margin-note {
        display: none;
    }

    #strata-nav {
        right: 1vw;
    }
}

@media (max-width: 600px) {
    .stratum-content {
        width: 95%;
        padding-left: 5vw;
        padding-right: 5vw;
    }

    .crust-illustration,
    .mantle-illustration,
    .core-illustration {
        width: 60%;
        opacity: 0.25;
    }

    .bedrock-illustration {
        width: 80%;
        opacity: 0.3;
    }

    .contour-lines {
        display: none;
    }

    .nav-marker {
        width: 8px;
        height: 8px;
    }

    #strata-nav {
        gap: 18px;
    }

    .fault-line {
        height: 10vh;
    }
}
