/* =============================================
   rust.quest — styles.css
   A meditation on beautiful decay
   ============================================= */

/* ---- CSS Custom Properties ---- */
:root {
    --midnight-iron: #0A0A14;
    --verdigris-glow: #77FFD6;
    --patina-lavender: #E8D5F5;
    --oxide-rose: #FF77A8;
    --corroded-chrome: #1A3A4A;
    --tarnished-bronze: #8B6F47;
    --faded-lilac: #C4B8D9;
    --copper-verdigris: #3DFF8A;
    --pale-lilac: #E0D6F0;

    --bg-current: var(--midnight-iron);
    --noise-opacity: 0.04;
    --glitch-opacity: 0;
}

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

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

body {
    background-color: var(--midnight-iron);
    color: var(--faded-lilac);
    font-family: 'Work Sans', sans-serif;
    font-weight: 300;
    font-size: clamp(0.95rem, 1.2vw, 1.1rem);
    line-height: 1.75;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ---- Hidden SVG Filters ---- */
.svg-filters {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
}

/* ---- Typography ---- */
.heading-display {
    font-family: 'Libre Baskerville', serif;
    font-weight: 700;
    font-size: clamp(2.2rem, 4.5vw, 4.2rem);
    letter-spacing: 0.08em;
    color: var(--patina-lavender);
    text-shadow:
        0 0 40px rgba(119, 255, 214, 0.15),
        0 0 80px rgba(255, 119, 168, 0.08);
    margin-bottom: 1.5rem;
}

.heading-secondary {
    font-family: 'Libre Baskerville', serif;
    font-style: italic;
    font-weight: 400;
    font-size: clamp(1.1rem, 2vw, 1.5rem);
    letter-spacing: 0.04em;
    color: var(--verdigris-glow);
    margin-bottom: 1rem;
}

.pull-quote {
    font-family: 'Libre Baskerville', serif;
    font-style: italic;
    font-weight: 400;
    font-size: clamp(1.1rem, 2vw, 1.5rem);
    letter-spacing: 0.04em;
    color: var(--verdigris-glow);
    text-align: center;
    line-height: 1.8;
    text-shadow:
        0 0 40px rgba(119, 255, 214, 0.15),
        0 0 80px rgba(255, 119, 168, 0.08);
    padding: 2rem 0;
}

.body-text {
    font-family: 'Work Sans', sans-serif;
    font-weight: 300;
    font-size: clamp(0.95rem, 1.2vw, 1.1rem);
    line-height: 1.75;
    color: var(--faded-lilac);
    margin-bottom: 1.5rem;
}

.body-text:last-child {
    margin-bottom: 0;
}

.mono-accent {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 300;
    font-size: 0.8rem;
    color: var(--oxide-rose);
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

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

.stage-label {
    position: absolute;
    top: 2rem;
    left: 50%;
    transform: translateX(-50%);
    opacity: 0.5;
}

/* ---- Corrosion Column (central content spine) ---- */
.corrosion-column {
    width: 62%;
    max-width: 720px;
    padding: 4rem 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    z-index: 2;
}

/* ---- Stage Backgrounds ---- */

/* Pristine: near-black, clean */
.stage-pristine {
    background: var(--midnight-iron);
}

/* Tarnish: first hints of aurora */
.stage-tarnish {
    background:
        linear-gradient(
            180deg,
            var(--midnight-iron) 0%,
            rgba(26, 58, 74, 0.3) 50%,
            var(--midnight-iron) 100%
        );
}

.stage-tarnish::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
        repeating-linear-gradient(
            87deg,
            transparent,
            rgba(119, 255, 214, 0.03) 2px,
            transparent 4px
        ),
        repeating-linear-gradient(
            93deg,
            transparent,
            rgba(255, 119, 168, 0.02) 3px,
            transparent 6px
        );
    pointer-events: none;
}

/* Patina: full aurora expression */
.stage-patina {
    background:
        linear-gradient(
            160deg,
            var(--midnight-iron) 0%,
            var(--corroded-chrome) 30%,
            rgba(232, 213, 245, 0.08) 65%,
            var(--midnight-iron) 100%
        );
}

.stage-patina::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
        repeating-linear-gradient(
            87deg,
            transparent,
            rgba(119, 255, 214, 0.05) 2px,
            transparent 4px
        ),
        repeating-linear-gradient(
            93deg,
            transparent,
            rgba(255, 119, 168, 0.04) 3px,
            transparent 6px
        );
    pointer-events: none;
}

/* Erosion: glitch-heavy, unstable */
.stage-erosion {
    background:
        linear-gradient(
            170deg,
            var(--midnight-iron) 0%,
            var(--corroded-chrome) 25%,
            rgba(255, 119, 168, 0.06) 65%,
            var(--midnight-iron) 100%
        );
}

.stage-erosion::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
        repeating-linear-gradient(
            87deg,
            transparent,
            rgba(119, 255, 214, 0.06) 2px,
            transparent 4px
        ),
        repeating-linear-gradient(
            93deg,
            transparent,
            rgba(255, 119, 168, 0.05) 3px,
            transparent 6px
        );
    opacity: 0.8;
    pointer-events: none;
}

/* Reclamation: harmonious, luminous */
.stage-reclamation {
    background:
        linear-gradient(
            180deg,
            var(--midnight-iron) 0%,
            var(--corroded-chrome) 30%,
            rgba(119, 255, 214, 0.06) 60%,
            var(--midnight-iron) 100%
        );
}

/* ---- Content Panels ---- */
.content-panel {
    background: rgba(26, 58, 74, 0.08);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    padding: 2.5rem 3rem;
    margin-bottom: 2.5rem;
    width: 100%;
    position: relative;
    overflow: hidden;
}

/* Corroded edge clip-paths — each panel gets a unique eroded edge */
.panel-tarnish-1 {
    clip-path: polygon(2% 0%, 98% 1%, 100% 3%, 99% 97%, 97% 100%, 3% 99%, 0% 96%, 1% 2%);
}

.panel-tarnish-2 {
    clip-path: polygon(1% 2%, 97% 0%, 100% 4%, 98% 98%, 96% 100%, 2% 97%, 0% 95%, 3% 1%);
}

.panel-tarnish-3 {
    clip-path: polygon(3% 0%, 99% 2%, 100% 5%, 97% 99%, 95% 100%, 1% 98%, 0% 93%, 2% 3%);
}

.panel-patina-1 {
    clip-path: polygon(0% 3%, 96% 0%, 100% 2%, 99% 95%, 98% 100%, 4% 98%, 1% 100%, 0% 4%);
}

.panel-patina-2 {
    clip-path: polygon(2% 1%, 100% 0%, 99% 4%, 97% 97%, 100% 100%, 3% 99%, 0% 96%, 1% 5%);
}

.panel-patina-3 {
    clip-path: polygon(1% 0%, 98% 3%, 100% 1%, 99% 98%, 96% 100%, 0% 97%, 2% 100%, 0% 2%);
}

.panel-patina-4 {
    clip-path: polygon(3% 2%, 97% 0%, 100% 3%, 98% 96%, 100% 100%, 2% 99%, 0% 97%, 1% 4%);
}

.panel-erosion-1 {
    clip-path: polygon(4% 0%, 95% 3%, 100% 1%, 97% 94%, 93% 100%, 5% 97%, 0% 100%, 2% 6%);
}

.panel-erosion-2 {
    clip-path: polygon(3% 4%, 96% 0%, 100% 5%, 94% 96%, 100% 100%, 6% 95%, 0% 100%, 1% 3%);
}

.panel-erosion-3 {
    clip-path: polygon(5% 0%, 94% 4%, 100% 2%, 96% 93%, 92% 100%, 4% 96%, 0% 98%, 3% 5%);
}

.panel-reclamation-1 {
    clip-path: polygon(1% 1%, 99% 0%, 100% 2%, 99% 99%, 98% 100%, 1% 99%, 0% 98%, 0% 2%);
}

.panel-reclamation-2 {
    clip-path: polygon(0% 2%, 98% 0%, 100% 1%, 100% 98%, 99% 100%, 2% 100%, 0% 99%, 1% 1%);
}

/* Panel light-sweep effect */
.content-panel::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(232, 213, 245, 0.04) 40%,
        rgba(119, 255, 214, 0.06) 50%,
        rgba(232, 213, 245, 0.04) 60%,
        transparent 100%
    );
    pointer-events: none;
    transition: none;
}

.content-panel.panel-visible::after {
    animation: lightSweep 1.5s ease-out forwards;
}

@keyframes lightSweep {
    from { left: -100%; }
    to { left: 100%; }
}

/* ---- Pristine Stage Title ---- */
.title-pristine {
    font-family: 'Libre Baskerville', serif;
    font-weight: 700;
    font-size: clamp(3rem, 7vw, 6rem);
    letter-spacing: 0.08em;
    color: var(--patina-lavender);
    text-shadow:
        0 0 40px rgba(119, 255, 214, 0.15),
        0 0 80px rgba(255, 119, 168, 0.08);
    opacity: 0;
    animation: fadeInTitle 1.5s ease-out 0.3s forwards;
    text-align: center;
}

.subtitle-pristine {
    font-family: 'Work Sans', sans-serif;
    font-weight: 300;
    font-size: clamp(0.95rem, 1.5vw, 1.2rem);
    color: var(--faded-lilac);
    opacity: 0;
    animation: fadeInTitle 1.2s ease-out 1.5s forwards;
    margin-top: 1.5rem;
    letter-spacing: 0.04em;
    text-align: center;
}

@keyframes fadeInTitle {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Descent line from title */
.descent-line {
    width: 1px;
    height: 0;
    background: var(--verdigris-glow);
    margin-top: 3rem;
    animation: drawLine 2s ease-out 2.5s forwards;
    opacity: 0.6;
}

@keyframes drawLine {
    from {
        height: 0;
    }
    to {
        height: 120px;
    }
}

/* ---- Fade-in Elements ---- */
.fade-element {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.8s ease-out, transform 0.8s ease-out;
}

.fade-element.visible {
    opacity: 1;
    transform: translateY(0);
}

/* Staggered delays applied via JS */

/* ---- Aurora Gradient Blobs ---- */
.aurora-container {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    overflow: hidden;
}

.aurora-blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    mix-blend-mode: screen;
    opacity: 0;
    will-change: transform;
}

.aurora-blob-1 {
    width: 400px;
    height: 400px;
    background: radial-gradient(circle, rgba(119, 255, 214, 0.12) 0%, transparent 70%);
    top: 10%;
    left: -10%;
    animation: auroraFloat1 45s ease-in-out infinite;
}

.aurora-blob-2 {
    width: 500px;
    height: 500px;
    background: radial-gradient(circle, rgba(255, 119, 168, 0.1) 0%, transparent 70%);
    top: 30%;
    right: -15%;
    animation: auroraFloat2 55s ease-in-out infinite;
}

.aurora-blob-3 {
    width: 350px;
    height: 350px;
    background: radial-gradient(circle, rgba(232, 213, 245, 0.1) 0%, transparent 70%);
    bottom: 20%;
    left: 10%;
    animation: auroraFloat3 40s ease-in-out infinite;
}

.aurora-blob-4 {
    width: 450px;
    height: 450px;
    background: radial-gradient(circle, rgba(61, 255, 138, 0.08) 0%, transparent 70%);
    top: 60%;
    right: 5%;
    animation: auroraFloat4 50s ease-in-out infinite;
}

.aurora-blob-5 {
    width: 300px;
    height: 300px;
    background: radial-gradient(circle, rgba(139, 111, 71, 0.1) 0%, transparent 70%);
    top: 50%;
    left: 30%;
    animation: auroraFloat5 35s ease-in-out infinite;
}

@keyframes auroraFloat1 {
    0%, 100% { transform: translate(0, 0) scale(1); }
    25% { transform: translate(80px, 60px) scale(1.1); }
    50% { transform: translate(40px, 120px) scale(0.95); }
    75% { transform: translate(-40px, 80px) scale(1.05); }
}

@keyframes auroraFloat2 {
    0%, 100% { transform: translate(0, 0) scale(1); }
    25% { transform: translate(-60px, 80px) scale(1.05); }
    50% { transform: translate(-100px, 40px) scale(1.1); }
    75% { transform: translate(-30px, -40px) scale(0.9); }
}

@keyframes auroraFloat3 {
    0%, 100% { transform: translate(0, 0) scale(1); }
    33% { transform: translate(60px, -40px) scale(1.08); }
    66% { transform: translate(100px, 30px) scale(0.95); }
}

@keyframes auroraFloat4 {
    0%, 100% { transform: translate(0, 0) scale(1); }
    30% { transform: translate(-80px, -60px) scale(1.1); }
    60% { transform: translate(-40px, 40px) scale(0.95); }
}

@keyframes auroraFloat5 {
    0%, 100% { transform: translate(0, 0) scale(1); }
    40% { transform: translate(50px, -30px) scale(1.05); }
    70% { transform: translate(-30px, 50px) scale(1.1); }
}

/* ---- Scroll Indicator ---- */
.scroll-indicator {
    position: fixed;
    right: 2rem;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 16px;
    z-index: 100;
}

.stage-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgba(119, 255, 214, 0.3);
    cursor: pointer;
    transition: background 0.3s ease, transform 0.3s ease, box-shadow 0.3s ease;
}

.stage-dot.active {
    background: var(--verdigris-glow);
    animation: dotPulse 2s ease-in-out infinite;
}

@keyframes dotPulse {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(255, 119, 168, 0.3);
    }
    50% {
        transform: scale(1.3);
        box-shadow: 0 0 0 4px rgba(255, 119, 168, 0.3);
    }
}

/* ---- Margin Motifs ---- */
.margin-motif {
    position: absolute;
    opacity: 0.18;
    z-index: 1;
    pointer-events: none;
    transition: opacity 0.8s ease;
}

.margin-motif svg {
    width: 100px;
    height: auto;
}

.margin-left {
    left: 5%;
    top: 50%;
    transform: translateY(-50%);
}

.margin-right {
    right: 5%;
    top: 50%;
    transform: translateY(-50%);
}

/* SVG motif stroke animations */
.motif-torii line,
.motif-torii path {
    stroke-dasharray: 200;
    stroke-dashoffset: 200;
    transition: stroke-dashoffset 2s ease-out;
}

.stage-tarnish .motif-column rect,
.stage-tarnish .motif-column path,
.stage-tarnish .motif-column line,
.stage-tarnish .motif-column ellipse {
    stroke-dasharray: 400;
    stroke-dashoffset: 400;
    transition: stroke-dashoffset 2.5s ease-out;
}

.motif-deco circle,
.motif-deco line,
.motif-deco rect {
    stroke-dasharray: 400;
    stroke-dashoffset: 400;
    transition: stroke-dashoffset 2s ease-out;
}

.motif-bridge line,
.motif-bridge path {
    stroke-dasharray: 300;
    stroke-dashoffset: 300;
    transition: stroke-dashoffset 2s ease-out;
}

/* When stage is in view, draw the motifs */
.stage.in-view .motif-torii line,
.stage.in-view .motif-torii path {
    stroke-dashoffset: 0;
}

.stage.in-view .motif-column rect,
.stage.in-view .motif-column path,
.stage.in-view .motif-column line,
.stage.in-view .motif-column ellipse {
    stroke-dashoffset: 0;
}

.stage.in-view .motif-deco circle,
.stage.in-view .motif-deco line,
.stage.in-view .motif-deco rect {
    stroke-dashoffset: 0;
}

.stage.in-view .motif-bridge line,
.stage.in-view .motif-bridge path {
    stroke-dashoffset: 0;
}

/* Erosion stage: motifs begin erasing */
.stage-erosion.in-view .motif-bridge line,
.stage-erosion.in-view .motif-bridge path {
    stroke-dashoffset: 300;
    transition: stroke-dashoffset 4s ease-in 1s;
}

/* ---- Noise Overlay ---- */
.noise-overlay {
    position: fixed;
    inset: 0;
    z-index: 50;
    pointer-events: none;
    opacity: var(--noise-opacity);
    background-image:
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 2px,
            rgba(119, 255, 214, 0.015) 2px,
            rgba(119, 255, 214, 0.015) 4px
        ),
        repeating-linear-gradient(
            90deg,
            transparent,
            transparent 2px,
            rgba(255, 119, 168, 0.01) 2px,
            rgba(255, 119, 168, 0.01) 4px
        );
    mix-blend-mode: overlay;
}

/* ---- Jitter Animation (Erosion Stage) ---- */
@keyframes jitter {
    0%, 100% { transform: translate(0, 0); opacity: 1; }
    10% { transform: translate(-1px, 1px); opacity: 0.92; }
    20% { transform: translate(2px, 0px); opacity: 1; }
    30% { transform: translate(0px, -1px); opacity: 0.88; }
    40% { transform: translate(1px, 2px); opacity: 0.95; }
    50% { transform: translate(-2px, 0px); opacity: 1; }
    60% { transform: translate(0px, 1px); opacity: 0.9; }
    70% { transform: translate(1px, -2px); opacity: 0.95; }
    80% { transform: translate(-1px, 0px); opacity: 1; }
    90% { transform: translate(2px, 1px); opacity: 0.87; }
}

.jitter-text {
    animation: none;
}

.stage-erosion.in-view .jitter-text {
    animation: jitter 0.3s steps(1) infinite;
}

/* ---- Tarnish Aurora Streaks ---- */
.stage-tarnish::after {
    content: '';
    position: absolute;
    inset: 0;
    background:
        linear-gradient(0deg,
            transparent 20%,
            rgba(119, 255, 214, 0.03) 35%,
            transparent 40%,
            transparent 55%,
            rgba(119, 255, 214, 0.04) 65%,
            transparent 75%
        );
    animation: tarnishPulse 8s ease-in-out infinite;
    pointer-events: none;
}

@keyframes tarnishPulse {
    0%, 100% { opacity: 0.4; transform: scaleY(1); }
    50% { opacity: 0.8; transform: scaleY(1.05); }
}

/* ---- Final Word (Reclamation) ---- */
.final-word {
    font-family: 'Libre Baskerville', serif;
    font-weight: 700;
    font-size: clamp(3rem, 7vw, 6rem);
    letter-spacing: 0.08em;
    text-align: center;
    margin-top: 4rem;
    color: var(--patina-lavender);
    text-shadow:
        0 0 40px rgba(119, 255, 214, 0.15),
        0 0 80px rgba(255, 119, 168, 0.08);
}

.final-quest {
    display: inline;
    transition: opacity 0.4s ease;
}

.final-rust {
    display: inline;
    transition: color 1s ease;
}

.final-quest.dissolving {
    opacity: 0;
}

.final-rust.transforming {
    animation: colorCycle 8s ease-in-out forwards;
}

@keyframes colorCycle {
    0% { color: var(--patina-lavender); }
    15% { color: var(--verdigris-glow); }
    30% { color: var(--oxide-rose); }
    45% { color: var(--copper-verdigris); }
    60% { color: var(--tarnished-bronze); }
    75% { color: var(--faded-lilac); }
    100% { color: var(--verdigris-glow); }
}

/* ---- Patina stage body text: lighter color ---- */
.stage-patina .body-text {
    color: var(--pale-lilac);
}

/* ---- Reclamation stage body text: lighter color ---- */
.stage-reclamation .body-text {
    color: var(--pale-lilac);
}

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

    .aurora-blob {
        opacity: 0.1 !important;
    }

    .noise-overlay {
        opacity: 0.02;
    }
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
    .corrosion-column {
        width: 85%;
        padding: 3rem 0;
    }

    .content-panel {
        padding: 1.8rem 1.5rem;
    }

    .scroll-indicator {
        right: 1rem;
    }

    .margin-motif {
        display: none;
    }
}

@media (max-width: 480px) {
    .corrosion-column {
        width: 92%;
    }

    .content-panel {
        padding: 1.5rem 1.2rem;
    }

    .scroll-indicator {
        right: 0.5rem;
    }
}
