/* ============================================
   rust.quest - Bauhaus + Rust Programming
   Palette: Jewel Tones
   ============================================ */

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

html {
    scroll-behavior: smooth;
}

body {
    background: #064E3B;
    color: #F0F0E8;
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 400;
    font-size: clamp(15px, 1.3vw, 17px);
    line-height: 1.7;
    overflow-x: hidden;
}

/* --- Typography --- */
h2, h3 {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
}

h2 {
    font-size: clamp(24px, 3.5vw, 48px);
}

h3 {
    font-size: clamp(18px, 2vw, 28px);
}

.section-title {
    text-align: center;
    margin-bottom: 3rem;
    color: #F0F0E8;
    letter-spacing: 0.05em;
}

/* --- Glitch Effect --- */
.glitch {
    position: relative;
    display: inline-block;
}

.glitch::before,
.glitch::after {
    content: attr(data-text);
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    opacity: 0;
}

.glitch::before {
    color: #991B1B;
    z-index: -1;
}

.glitch::after {
    color: #1E40AF;
    z-index: -1;
}

.glitch.active::before {
    opacity: 0.8;
    animation: glitch-before 0.3s steps(4) forwards;
}

.glitch.active::after {
    opacity: 0.8;
    animation: glitch-after 0.3s steps(4) forwards;
}

@keyframes glitch-before {
    0% {
        clip-path: inset(10% 0 80% 0);
        transform: translate(2px, -1px);
    }
    25% {
        clip-path: inset(40% 0 30% 0);
        transform: translate(-2px, 2px);
    }
    50% {
        clip-path: inset(70% 0 10% 0);
        transform: translate(1px, -2px);
    }
    75% {
        clip-path: inset(20% 0 50% 0);
        transform: translate(-1px, 1px);
    }
    100% {
        clip-path: inset(0 0 0 0);
        transform: translate(0);
        opacity: 0;
    }
}

@keyframes glitch-after {
    0% {
        clip-path: inset(60% 0 10% 0);
        transform: translate(-2px, 1px);
    }
    25% {
        clip-path: inset(10% 0 60% 0);
        transform: translate(2px, -2px);
    }
    50% {
        clip-path: inset(30% 0 40% 0);
        transform: translate(-1px, 2px);
    }
    75% {
        clip-path: inset(80% 0 5% 0);
        transform: translate(1px, -1px);
    }
    100% {
        clip-path: inset(0 0 0 0);
        transform: translate(0);
        opacity: 0;
    }
}

/* ============================================
   Section 1: The Compiler (Hero)
   ============================================ */
.compiler-section {
    position: relative;
    width: 100%;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #064E3B;
    overflow: hidden;
}

/* Leaf corners */
.leaf-corner {
    position: absolute;
    width: 120px;
    height: 120px;
    opacity: 0;
    transition: opacity 0.8s ease;
}

.leaf-corner.visible {
    opacity: 1;
}

.leaf-top-left {
    top: 20px;
    left: 20px;
}

.leaf-top-right {
    top: 20px;
    right: 20px;
}

.leaf-bottom-left {
    bottom: 20px;
    left: 20px;
}

.leaf-bottom-right {
    bottom: 20px;
    right: 20px;
}

/* Bauhaus frame */
.bauhaus-frame {
    position: relative;
    width: clamp(280px, 50vw, 400px);
    height: clamp(280px, 50vw, 400px);
    display: flex;
    align-items: center;
    justify-content: center;
}

.bauhaus-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* Stroke animation setup */
.bauhaus-triangle {
    stroke-dasharray: 900;
    stroke-dashoffset: 900;
}

.bauhaus-square {
    stroke-dasharray: 800;
    stroke-dashoffset: 800;
}

.bauhaus-circle {
    stroke-dasharray: 630;
    stroke-dashoffset: 630;
}

.bauhaus-triangle.animate {
    animation: draw-shape 0.5s ease forwards;
}

.bauhaus-square.animate {
    animation: draw-shape 0.3s ease forwards 0.2s;
}

.bauhaus-circle.animate {
    animation: draw-shape 0.2s ease forwards 0.4s;
}

@keyframes draw-shape {
    to {
        stroke-dashoffset: 0;
    }
}

/* Wordmark */
.wordmark {
    position: relative;
    z-index: 2;
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
    font-size: clamp(28px, 5vw, 56px);
    color: #F0F0E8;
    letter-spacing: 0.04em;
    opacity: 0;
    transition: opacity 0.6s ease;
    text-align: center;
}

.wordmark.visible {
    opacity: 1;
}

.wordmark span {
    position: relative;
    z-index: 1;
}

/* Compiler tagline */
.compiler-tagline {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 500;
    font-size: 14px;
    color: #CA8A04;
    margin-top: 2rem;
    letter-spacing: 0.1em;
    opacity: 0;
    transition: opacity 0.8s ease 1.5s;
}

.compiler-tagline.visible {
    opacity: 1;
}

/* ============================================
   Section 2: Concept Modules
   ============================================ */
.concepts-section {
    position: relative;
    padding: 6rem 2rem;
    background: #022C22;
}

.concepts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 2.5rem;
    max-width: 1100px;
    margin: 0 auto;
}

/* Card flip */
.card {
    perspective: 600px;
    position: relative;
    height: 340px;
    cursor: pointer;
}

.card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transition: transform 0.5s ease;
    transform-style: preserve-3d;
}

.card:hover .card-inner,
.card.flipped .card-inner {
    transform: rotateY(180deg);
}

.card-front,
.card-back {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    border: 1.5px solid rgba(240, 240, 232, 0.15);
    border-radius: 4px;
}

.card-front {
    background: #064E3B;
}

.card-front h3 {
    color: #F0F0E8;
    margin-top: 1rem;
    font-size: clamp(20px, 2.2vw, 28px);
}

.card-hint {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 500;
    font-size: 12px;
    color: #16A34A;
    margin-top: 1rem;
    opacity: 0.7;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.card-icon {
    width: 80px;
    height: 80px;
}

.card-back {
    background: #1E40AF;
    transform: rotateY(180deg);
}

.card-back h3 {
    color: #CA8A04;
    font-size: clamp(18px, 2vw, 24px);
    margin-bottom: 1rem;
}

.card-back p {
    color: #F0F0E8;
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 400;
    font-size: clamp(13px, 1.2vw, 15px);
    line-height: 1.7;
    text-align: center;
}

/* Leaf border on cards */
.leaf-border {
    position: absolute;
    top: -6px;
    left: -6px;
    right: -6px;
    bottom: -6px;
    border: 1px solid #16A34A;
    border-radius: 6px;
    opacity: 0.25;
    pointer-events: none;
}

/* ============================================
   Section 3: The Ecosystem
   ============================================ */
.ecosystem-section {
    position: relative;
    padding: 6rem 2rem;
    background: #064E3B;
}

.ecosystem-diagram {
    position: relative;
    max-width: 800px;
    margin: 0 auto 2rem auto;
}

.ecosystem-svg {
    width: 100%;
    height: auto;
}

/* Ecosystem node animations */
.eco-node {
    opacity: 0;
    transition: opacity 0.5s ease;
}

.eco-node.visible {
    opacity: 1;
}

.eco-line {
    opacity: 0;
    transition: opacity 0.6s ease;
}

.eco-line.visible {
    opacity: 0.5;
}

/* Eco leaf borders */
.eco-leaf-border {
    position: absolute;
    top: 0;
    height: 100%;
    width: 40px;
    pointer-events: none;
}

.eco-leaf-border-left {
    left: -50px;
}

.eco-leaf-border-right {
    right: -50px;
}

.eco-leaf-border svg {
    width: 100%;
    height: 100%;
}

.ecosystem-caption {
    text-align: center;
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 500;
    font-size: 14px;
    color: #CA8A04;
    letter-spacing: 0.04em;
    max-width: 600px;
    margin: 0 auto;
}

/* ============================================
   Section 4: Memory Safe Footer
   ============================================ */
.footer-section {
    position: relative;
    padding: 4rem 2rem;
    background: #022C22;
    overflow: hidden;
    text-align: center;
}

.footer-glitch-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 2px,
        rgba(153, 27, 27, 0.03) 2px,
        rgba(153, 27, 27, 0.03) 4px
    );
    pointer-events: none;
}

.footer-content {
    position: relative;
    z-index: 1;
}

.footer-text {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
    font-size: clamp(20px, 3vw, 40px);
    color: #F0F0E8;
    margin-bottom: 1rem;
}

.footer-text span {
    position: relative;
    z-index: 1;
}

.footer-domain {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 500;
    font-size: 14px;
    color: #16A34A;
    letter-spacing: 0.15em;
    text-transform: lowercase;
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 768px) {
    .concepts-grid {
        grid-template-columns: 1fr;
        max-width: 400px;
    }

    .leaf-corner {
        width: 80px;
        height: 80px;
    }

    .bauhaus-frame {
        width: 260px;
        height: 260px;
    }

    .eco-leaf-border {
        display: none;
    }

    .ecosystem-diagram {
        overflow-x: auto;
    }
}

@media (max-width: 480px) {
    .leaf-corner {
        width: 60px;
        height: 60px;
    }

    .compiler-tagline {
        font-size: 12px;
    }

    .card {
        height: 300px;
    }
}
