/* ============================================================
   economic.day - Algorithmic Forestry
   Colors: #060D09, #0B2916, #1A4A3A, #3A5A40, #588157, #A3B18A, #DAD7CD, #C9A227, #B5651D
   Fonts: Commissioner (300,400,500,700), JetBrains Mono (400)
   ============================================================ */

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

html {
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: 'Commissioner', sans-serif;
    font-weight: 400;
    font-size: clamp(1.05rem, 1.8vw, 1.25rem);
    line-height: 1.72;
    letter-spacing: 0.01em;
    color: #DAD7CD;
    background-color: #060D09;
    overflow-x: hidden;
}

/* --- CSS Custom Properties --- */
:root {
    --ground: #060D09;
    --deep-canopy: #0B2916;
    --spore: #1A4A3A;
    --understory: #3A5A40;
    --moss: #588157;
    --pale-fern: #A3B18A;
    --fog-white: #DAD7CD;
    --golden-lichen: #C9A227;
    --fallen-leaf: #B5651D;
}

/* --- Typography --- */
h1, h2, h3 {
    font-family: 'Commissioner', sans-serif;
    font-weight: 700;
    line-height: 1.12;
    letter-spacing: -0.015em;
}

.data-annotation,
.organism-label,
.node-label,
.seed-annotation,
.scroll-hint-text {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 400;
    font-size: 0.85rem;
    letter-spacing: 0.02em;
}

/* --- Section Base --- */
.section {
    position: relative;
    width: 100%;
    contain: layout paint;
}

.section-dark {
    background-color: var(--deep-canopy);
    color: var(--fog-white);
}

.section-light {
    background-color: var(--fog-white);
    color: var(--deep-canopy);
}

.section-ground {
    background-color: var(--ground);
}

.section-inner {
    max-width: clamp(540px, 70vw, 880px);
    margin: 0 auto;
    padding: 10vh 1.5rem;
    position: relative;
}

/* --- Section Transitions --- */
.section-transition {
    background: linear-gradient(to bottom, var(--section-from), var(--section-to));
    height: 20vh;
    width: 100%;
}

/* ============================================================
   SECTION 1: THE CANOPY
   ============================================================ */
#canopy {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background-color: var(--deep-canopy);
}

#canopy-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0.3;
    will-change: transform;
}

.canopy-content {
    position: relative;
    z-index: 2;
    text-align: center;
    padding: 0 1.5rem;
}

.canopy-title {
    font-size: clamp(2.8rem, 6.5vw, 5.5rem);
    font-weight: 700;
    color: var(--fog-white);
    animation: titleReveal 2.5s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.canopy-subtitle {
    font-family: 'Commissioner', sans-serif;
    font-weight: 300;
    font-size: clamp(1rem, 2vw, 1.35rem);
    color: var(--pale-fern);
    max-width: 540px;
    margin: 1.5rem auto 0;
    animation: titleReveal 2.5s cubic-bezier(0.16, 1, 0.3, 1) 0.8s both;
}

@keyframes titleReveal {
    0% {
        opacity: 0;
        filter: blur(12px);
        letter-spacing: 0.15em;
    }
    100% {
        opacity: 1;
        filter: blur(0px);
        letter-spacing: -0.015em;
    }
}

/* Scroll hint */
.scroll-hint {
    position: absolute;
    bottom: 3vh;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    animation: hintPulse 3s ease-in-out infinite;
}

.scroll-hint-text {
    color: var(--pale-fern);
    opacity: 0.6;
    font-size: 0.75rem;
    text-transform: lowercase;
}

.scroll-hint-arrow {
    opacity: 0.5;
}

@keyframes hintPulse {
    0%, 100% { opacity: 0.5; transform: translateX(-50%) translateY(0); }
    50% { opacity: 0.9; transform: translateX(-50%) translateY(6px); }
}

/* ============================================================
   SECTION 2: THE UNDERSTORY
   ============================================================ */
#understory {
    min-height: 120vh;
    background-color: var(--fog-white);
    color: var(--deep-canopy);
}

.understory-inner {
    display: flex;
    flex-direction: column;
    gap: 15vh;
    padding: 15vh 1.5rem;
}

/* --- Flip Cards --- */
.flip-card {
    perspective: 1200px;
    width: 100%;
    min-height: 280px;
}

.flip-card-inner {
    position: relative;
    width: 100%;
    min-height: 280px;
    transition: transform 600ms cubic-bezier(0.4, 0, 0.2, 1);
    transform-style: preserve-3d;
}

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

.flip-card-front,
.flip-card-back {
    position: absolute;
    inset: 0;
    backface-visibility: hidden;
    border-radius: 12px;
    padding: 2.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.flip-card-front {
    background: rgba(58, 90, 64, 0.06);
    border: 1px solid var(--understory);
    backdrop-filter: blur(4px);
}

.flip-card-back {
    transform: rotateY(180deg);
    background: rgba(58, 90, 64, 0.08);
    border: 1px solid var(--understory);
    backdrop-filter: blur(4px);
    text-align: left;
}

.flip-card-back p {
    color: var(--deep-canopy);
    line-height: 1.72;
    font-size: clamp(1rem, 1.6vw, 1.15rem);
}

.flip-card-back .data-annotation {
    margin-top: 1.5rem;
    color: var(--golden-lichen);
    align-self: flex-end;
}

.card-shape {
    width: 140px;
    height: 140px;
    margin-bottom: 1.5rem;
}

.card-label {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
    letter-spacing: 0.08em;
    text-transform: lowercase;
    color: var(--understory);
    opacity: 0.8;
}

/* ============================================================
   SECTION 3: THE FLOOR
   ============================================================ */
#floor {
    min-height: 100vh;
    background-color: var(--ground);
    overflow: hidden;
}

.floor-inner {
    padding-top: 12vh;
    padding-bottom: 12vh;
}

.section-heading {
    font-size: clamp(2rem, 4vw, 3.5rem);
    color: var(--fog-white);
    margin-bottom: 1rem;
    text-align: center;
}

.section-subheading {
    font-family: 'Commissioner', sans-serif;
    font-weight: 300;
    font-size: clamp(0.95rem, 1.5vw, 1.15rem);
    color: var(--pale-fern);
    text-align: center;
    margin-bottom: 10vh;
}

/* Dot grid background */
.dot-grid {
    position: absolute;
    inset: 0;
    background-image: radial-gradient(circle, var(--pale-fern) 1px, transparent 1px);
    background-size: 40px 40px;
    opacity: 0.05;
    pointer-events: none;
}

/* Organisms */
.organism-cluster {
    position: relative;
    width: 100%;
    height: 55vh;
    min-height: 400px;
}

.organism {
    position: absolute;
    left: var(--x);
    top: var(--y);
    width: var(--size);
    height: var(--size);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.8s ease;
    animation: organismPulse 4s ease-in-out infinite;
    animation-delay: var(--delay);
}

.organism.visible {
    opacity: 1;
}

.organism-circle {
    border-radius: 50%;
    background: radial-gradient(circle at 40% 40%, rgba(88, 129, 87, 0.6), rgba(88, 129, 87, 0.3));
    border: 1px solid var(--pale-fern);
}

.organism-hexagon {
    clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
    background-color: rgba(58, 90, 64, 0.3);
}

.organism-label {
    color: var(--pale-fern);
    font-size: 0.7rem;
    opacity: 0.8;
    text-align: center;
    pointer-events: none;
}

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

/* Connection lines */
.connection-lines {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.connection-path {
    stroke-dasharray: 500;
    stroke-dashoffset: 500;
    transition: stroke-dashoffset 1.5s ease;
}

.connection-path.drawn {
    stroke-dashoffset: 0;
}

/* Organic blobs */
.organic-blob {
    position: absolute;
    width: 300px;
    height: 300px;
    pointer-events: none;
    z-index: 0;
}

.blob-1 {
    top: 10%;
    right: -5%;
    animation: blobDrift1 12s ease-in-out infinite;
}

.blob-2 {
    bottom: 5%;
    left: -8%;
    animation: blobDrift2 10s ease-in-out infinite;
}

@keyframes blobDrift1 {
    0%, 100% { transform: translate(0, 0) rotate(0deg); }
    25% { transform: translate(-20px, 15px) rotate(5deg); }
    50% { transform: translate(10px, -10px) rotate(-3deg); }
    75% { transform: translate(-10px, -20px) rotate(2deg); }
}

@keyframes blobDrift2 {
    0%, 100% { transform: translate(0, 0) rotate(0deg); }
    33% { transform: translate(15px, -20px) rotate(-4deg); }
    66% { transform: translate(-15px, 10px) rotate(3deg); }
}

/* ============================================================
   SECTION 4: THE ROOT NETWORK
   ============================================================ */
#root-network {
    min-height: 100vh;
    background-color: var(--deep-canopy);
    overflow: hidden;
}

.section-roots {
    position: relative;
}

/* Scan lines */
.scan-lines {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
}

.scan-lines::before {
    content: '';
    position: absolute;
    top: -100%;
    left: 0;
    width: 100%;
    height: 200%;
    background: repeating-linear-gradient(
        to bottom,
        transparent,
        transparent 3px,
        rgba(163, 177, 138, 0.03) 3px,
        rgba(163, 177, 138, 0.03) 4px
    );
    animation: scanDrift 20s linear infinite;
}

@keyframes scanDrift {
    0% { transform: translateY(0); }
    100% { transform: translateY(50%); }
}

.root-inner {
    padding-top: 8vh;
    padding-bottom: 8vh;
}

/* Network Graph */
.network-graph {
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    display: block;
}

.network-edge {
    stroke-dasharray: 500;
    stroke-dashoffset: 500;
    transition: stroke-dashoffset 1.2s ease;
}

.network-edge.revealed {
    stroke-dashoffset: 0;
}

.network-node {
    opacity: 0;
    transition: opacity 0.4s ease;
}

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

.network-node circle {
    transition: fill 0.3s ease;
}

.node-label {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    fill: var(--pale-fern);
    text-anchor: middle;
    opacity: 0;
    transition: opacity 0.4s ease 0.4s;
}

.network-node.visible .node-label {
    opacity: 0.8;
}

/* Root text clearings */
.root-text-clearing {
    max-width: 620px;
    margin: 10vh auto;
    padding: 2.5rem;
    border-radius: 12px;
    background: rgba(11, 41, 22, 0.6);
    border: 1px solid rgba(26, 74, 58, 0.3);
}

.root-text-clearing p {
    color: var(--fog-white);
    font-weight: 400;
    line-height: 1.72;
}

.root-text-clearing-2 {
    margin-top: 15vh;
}

/* ============================================================
   SECTION 5: THE SEED
   ============================================================ */
#seed {
    min-height: 60vh;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: seedHueShift 30s ease-in-out infinite;
}

@keyframes seedHueShift {
    0% { background-color: #0B2916; }
    25% { background-color: #0D3320; }
    50% { background-color: #0F3D2A; }
    75% { background-color: #0D3320; }
    100% { background-color: #0B2916; }
}

.seed-inner {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 60vh;
    padding: 10vh 1.5rem;
}

.seed-statement {
    font-family: 'Commissioner', sans-serif;
    font-weight: 700;
    font-size: clamp(2.2rem, 5vw, 4.5rem);
    line-height: 1.2;
    letter-spacing: -0.015em;
    color: var(--fog-white);
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 1.5s ease, transform 1.5s ease;
}

.seed-statement.revealed {
    opacity: 1;
    transform: translateY(0);
}

.seed-annotation {
    margin-top: 4rem;
    color: var(--golden-lichen);
    opacity: 0;
    transition: opacity 1s ease 1s;
}

.seed-statement.revealed ~ .seed-annotation {
    opacity: 0.6;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
    .organism-cluster {
        height: 70vh;
    }

    .organic-blob {
        width: 200px;
        height: 200px;
    }

    .flip-card {
        min-height: 240px;
    }

    .flip-card-inner {
        min-height: 240px;
    }

    .flip-card-front,
    .flip-card-back {
        padding: 1.5rem;
    }

    .root-text-clearing {
        padding: 1.5rem;
        margin: 8vh auto;
    }
}

@media (max-width: 480px) {
    .canopy-title {
        font-size: clamp(2rem, 10vw, 3.5rem);
    }

    .seed-statement {
        font-size: clamp(1.6rem, 8vw, 2.8rem);
    }

    .organism-cluster {
        height: 80vh;
    }

    .organism {
        --size: calc(var(--size) * 0.7) !important;
    }
}

/* ============================================================
   REDUCED MOTION
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
    .canopy-title,
    .canopy-subtitle {
        animation: none;
        opacity: 1;
        filter: none;
        letter-spacing: -0.015em;
    }

    .flip-card-inner {
        transition: none;
    }

    .flip-card.flipped .flip-card-inner {
        transform: none;
    }

    .flip-card.flipped .flip-card-front {
        display: none;
    }

    .flip-card.flipped .flip-card-back {
        position: relative;
        transform: none;
    }

    .organism {
        animation: none;
    }

    .organic-blob {
        animation: none;
    }

    .scan-lines::before {
        animation: none;
    }

    #seed {
        animation: none;
    }

    .scroll-hint {
        animation: none;
    }

    #canopy-canvas {
        display: none;
    }
}
