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

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

body {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 400;
    font-size: clamp(0.95rem, 1.5vw, 1.15rem);
    line-height: 1.7;
    letter-spacing: 0.01em;
    color: #2d1c10;
    background: #3a2e45;
    overflow-x: hidden;
    image-rendering: pixelated;
    -webkit-font-smoothing: auto;
}

/* === Scanline Overlay === */
#scanlines {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
    background: repeating-linear-gradient(
        to bottom,
        transparent,
        transparent 2px,
        rgba(45, 28, 16, 0.04) 2px,
        rgba(45, 28, 16, 0.04) 4px
    );
    animation: scanlineDrift 4s linear infinite;
}

@keyframes scanlineDrift {
    0% { transform: translateY(0); }
    100% { transform: translateY(4px); }
}

/* === HUD Frame === */
#hud-frame {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    pointer-events: none;
    border: 48px solid transparent;
    border-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='96' height='96'%3E%3Crect width='96' height='96' fill='%232d1c10'/%3E%3Crect x='4' y='4' width='88' height='88' fill='none' stroke='%23e8925a' stroke-width='2'/%3E%3Crect x='8' y='8' width='80' height='80' fill='transparent'/%3E%3C/svg%3E") 48 fill;
    opacity: 0;
    transition: opacity 0.8s ease-out;
}

#hud-frame.visible {
    opacity: 1;
}

#hud-top-left {
    position: absolute;
    top: -40px;
    left: -40px;
    font-family: 'Silkscreen', cursive;
    font-size: clamp(1rem, 2vw, 1.4rem);
    color: #f5c957;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    image-rendering: pixelated;
    pointer-events: auto;
}

#hud-top-right {
    position: absolute;
    top: -36px;
    right: -40px;
    font-family: 'Silkscreen', cursive;
    font-size: clamp(0.6rem, 1vw, 0.8rem);
    color: #e8925a;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

#hud-bottom {
    position: absolute;
    bottom: -40px;
    left: -40px;
    right: -40px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 8px;
}

#hud-section-name {
    font-family: 'Silkscreen', cursive;
    font-size: clamp(0.6rem, 1vw, 0.75rem);
    color: #f2a65a;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

#hud-progress {
    display: flex;
    gap: 4px;
}

.progress-square {
    display: block;
    width: 8px;
    height: 8px;
    background: rgba(242, 166, 90, 0.25);
    border: 1px solid #e8925a;
    image-rendering: pixelated;
}

.progress-square.filled {
    background: #f2a65a;
}

/* === Scenes (common) === */
.scene {
    position: relative;
    width: 100%;
    overflow: hidden;
}

.scene-content {
    position: relative;
    z-index: 10;
}

/* === Scene 1: Canopy === */
#scene-canopy {
    height: 100vh;
    background: #3a2e45;
    display: flex;
    align-items: center;
    justify-content: center;
}

.canopy-trees {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 70%;
    opacity: 0;
    transform: translateY(40px);
    transition: opacity 0.8s ease-out, transform 0.8s ease-out;
}

.canopy-trees.visible {
    opacity: 1;
    transform: translateY(0);
}

.pixel-tree {
    position: absolute;
    image-rendering: pixelated;
    -webkit-image-rendering: -webkit-optimize-contrast;
}

.tree-1 {
    bottom: 0;
    left: 5%;
    width: 120px;
    height: auto;
}

.tree-2 {
    bottom: 0;
    left: 25%;
    width: 90px;
    height: auto;
}

.tree-3 {
    bottom: 0;
    right: 15%;
    width: 150px;
    height: auto;
}

.tree-4 {
    bottom: 0;
    right: 35%;
    width: 100px;
    height: auto;
}

.canopy-content {
    text-align: center;
    z-index: 20;
}

#site-title {
    font-family: 'Silkscreen', cursive;
    font-size: clamp(2rem, 6vw, 5rem);
    color: #f5c957;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    image-rendering: pixelated;
    -moz-osx-font-smoothing: unset;
    opacity: 0;
    transition: opacity 0.6s ease-out;
}

#site-title.visible {
    opacity: 1;
}

#site-tagline {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 400;
    font-size: clamp(1rem, 2vw, 1.4rem);
    color: #f2a65a;
    margin-top: 0.5em;
    opacity: 0;
    transition: opacity 0.6s ease-out;
}

#site-tagline.visible {
    opacity: 1;
}

/* === Scene 2: Understory === */
#scene-understory {
    min-height: 100vh;
    background: linear-gradient(to bottom, #3a2e45 0%, #4a3e35 30%, #5a4e3a 100%);
    padding: 80px 48px 80px;
}

.understory-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.understory-tree-1 {
    bottom: 10%;
    left: 8%;
    width: 60px;
    opacity: 0.4;
}

.understory-tree-2 {
    bottom: 5%;
    right: 10%;
    width: 50px;
    opacity: 0.3;
}

.understory-content {
    display: flex;
    flex-wrap: wrap;
    gap: 24px;
    justify-content: center;
    align-items: flex-start;
    max-width: 1100px;
    margin: 0 auto;
    padding-top: 40px;
}

/* === Glassmorphic Cards === */
.glass-card {
    background: rgba(245, 240, 232, 0.72);
    backdrop-filter: blur(12px) saturate(1.4);
    -webkit-backdrop-filter: blur(12px) saturate(1.4);
    border: 1px solid rgba(245, 201, 87, 0.3);
    border-radius: 8px;
    padding: 28px 24px;
    max-width: 340px;
    flex: 1 1 280px;
}

@supports not (backdrop-filter: blur(12px)) {
    .glass-card {
        background: rgba(245, 240, 232, 0.92);
    }
}

.glass-card .card-icon {
    width: 16px;
    height: 16px;
    margin-bottom: 12px;
    image-rendering: pixelated;
}

.glass-card .card-icon svg {
    width: 16px;
    height: 16px;
    image-rendering: pixelated;
}

.glass-card h2,
.glass-card h3 {
    font-family: 'Silkscreen', cursive;
    font-size: clamp(1rem, 2vw, 1.3rem);
    color: #f5c957;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    margin-bottom: 12px;
    image-rendering: pixelated;
}

.glass-card h3 {
    font-size: clamp(0.85rem, 1.5vw, 1.1rem);
}

.glass-card p {
    color: #2d1c10;
    margin-bottom: 12px;
}

.glass-card code {
    font-family: 'JetBrains Mono', monospace;
    font-size: clamp(0.8rem, 1.2vw, 1rem);
    line-height: 1.6;
    background: rgba(45, 28, 16, 0.6);
    color: #f2a65a;
    border: 1px solid #e8925a;
    padding: 4px 8px;
    border-radius: 4px;
    display: inline-block;
}

/* === Fade Reveal === */
.fade-reveal {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.6s ease-out, transform 0.6s ease-out;
}

.fade-reveal.revealed {
    opacity: 1;
    transform: translateY(0);
}

/* === Scene 3: Root Network === */
#scene-roots {
    min-height: 150vh;
    background: linear-gradient(to bottom, #5a4e3a 0%, #3d2e1a 15%, #2d1c10 100%);
    padding: 80px 48px;
}

.roots-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.soil-line {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 8px;
    background: repeating-linear-gradient(
        to right,
        #5a4e3a 0px,
        #5a4e3a 4px,
        #4a3e2a 4px,
        #4a3e2a 8px
    );
    image-rendering: pixelated;
}

.root-system {
    position: absolute;
    top: 60px;
    left: 50%;
    transform: translateX(-50%);
    width: 80%;
    height: 80%;
}

.root-line {
    position: absolute;
    background: #e8925a;
    image-rendering: pixelated;
}

.root-main {
    left: 50%;
    top: 0;
    width: 4px;
    height: 100%;
    transform: translateX(-50%);
    opacity: 0.3;
}

.root-branch-1 {
    left: 50%;
    top: 20%;
    width: 30%;
    height: 4px;
    opacity: 0.25;
}

.root-branch-2 {
    right: 50%;
    top: 35%;
    width: 25%;
    height: 4px;
    opacity: 0.2;
}

.root-branch-3 {
    left: 50%;
    top: 50%;
    width: 20%;
    height: 4px;
    opacity: 0.2;
}

.root-branch-4 {
    right: 50%;
    top: 65%;
    width: 35%;
    height: 4px;
    opacity: 0.15;
}

.root-branch-5 {
    left: 50%;
    top: 80%;
    width: 15%;
    height: 4px;
    opacity: 0.15;
}

.roots-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 40px;
    max-width: 700px;
    margin: 0 auto;
}

.root-card {
    width: 100%;
}

.root-card p {
    color: rgba(245, 240, 232, 0.85);
}

.root-child-1,
.root-child-2,
.root-child-3 {
    max-width: 320px;
    padding: 20px;
}

.root-child-1 { align-self: flex-end; }
.root-child-2 { align-self: flex-start; }
.root-child-3 { align-self: flex-end; }

/* Cards in dark sections */
#scene-roots .glass-card {
    background: rgba(245, 240, 232, 0.12);
    border-color: rgba(232, 146, 90, 0.3);
}

/* === Scene 4: Mycelium === */
#scene-mycelium {
    min-height: 100vh;
    background: #2d1c10;
    padding: 80px 48px;
}

.mycelium-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: hidden;
}

.glow-spot {
    position: absolute;
    border-radius: 50%;
    filter: blur(40px);
    opacity: 0.3;
}

.glow-1 { width: 120px; height: 120px; background: #7ec87e; top: 15%; left: 10%; }
.glow-2 { width: 80px; height: 80px; background: #f2a65a; top: 40%; right: 15%; }
.glow-3 { width: 100px; height: 100px; background: #7ec87e; bottom: 20%; left: 30%; }
.glow-4 { width: 60px; height: 60px; background: #f2a65a; top: 60%; left: 60%; }
.glow-5 { width: 90px; height: 90px; background: #7ec87e; bottom: 10%; right: 25%; }

.pixel-mushroom {
    position: absolute;
    image-rendering: pixelated;
}

.pixel-mushroom svg {
    image-rendering: pixelated;
}

.mush-1 { bottom: 30%; left: 8%; width: 32px; height: 32px; }
.mush-2 { top: 20%; right: 12%; width: 24px; height: 24px; }
.mush-3 { bottom: 15%; right: 30%; width: 28px; height: 28px; }

.pixel-parasite {
    position: absolute;
    image-rendering: pixelated;
}

.pixel-parasite svg {
    image-rendering: pixelated;
}

.parasite-1 { top: 35%; left: 20%; width: 16px; height: 16px; filter: drop-shadow(0 0 4px #d94f3b); animation: parasitePulse 2s ease-in-out infinite; }
.parasite-2 { bottom: 40%; right: 18%; width: 12px; height: 12px; filter: drop-shadow(0 0 4px #d94f3b); animation: parasitePulse 2s ease-in-out infinite 1s; }

@keyframes parasitePulse {
    0%, 100% { opacity: 0.7; }
    50% { opacity: 1; }
}

.mycelium-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 32px;
    max-width: 600px;
    margin: 0 auto;
}

.dark-card {
    background: rgba(62, 46, 69, 0.72);
    border: 1px solid rgba(126, 200, 126, 0.3);
}

.dark-card p {
    color: rgba(245, 240, 232, 0.85);
}

.dark-card em {
    color: #f5c957;
    font-style: italic;
}

/* === Scene 5: Bedrock === */
#scene-bedrock {
    min-height: 100vh;
    background: #2d1c10;
    padding: 80px 48px 120px;
    position: relative;
}

.bedrock-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: hidden;
}

.rock-stratum {
    position: absolute;
    left: 0;
    width: 100%;
    height: 4px;
    image-rendering: pixelated;
}

.stratum-1 {
    top: 20%;
    background: repeating-linear-gradient(to right, #3d2e1a 0px, #3d2e1a 8px, #4a3a25 8px, #4a3a25 16px);
}

.stratum-2 {
    top: 45%;
    background: repeating-linear-gradient(to right, #4a3a25 0px, #4a3a25 12px, #5a4835 12px, #5a4835 24px);
}

.stratum-3 {
    top: 65%;
    background: repeating-linear-gradient(to right, #3d2e1a 0px, #3d2e1a 6px, #50402a 6px, #50402a 12px);
}

.stratum-4 {
    top: 85%;
    background: repeating-linear-gradient(to right, #4a3a25 0px, #4a3a25 10px, #3d2e1a 10px, #3d2e1a 20px);
}

.fossil {
    position: absolute;
    opacity: 0.3;
    image-rendering: pixelated;
}

.fossil svg {
    image-rendering: pixelated;
}

.fossil-1 { top: 25%; left: 10%; width: 48px; height: 48px; }
.fossil-2 { top: 50%; right: 8%; width: 40px; height: 40px; }
.fossil-3 { bottom: 20%; left: 25%; width: 36px; height: 36px; }

.bedrock-content {
    display: flex;
    flex-wrap: wrap;
    gap: 24px;
    justify-content: center;
    align-items: flex-start;
    max-width: 1100px;
    margin: 0 auto;
}

#scene-bedrock .glass-card {
    background: rgba(245, 240, 232, 0.12);
    border-color: rgba(242, 166, 90, 0.3);
}

#scene-bedrock .glass-card p {
    color: rgba(245, 240, 232, 0.85);
}

.bedrock-final {
    width: 100%;
    text-align: center;
    padding-top: 60px;
}

.final-heading {
    font-family: 'Silkscreen', cursive;
    font-size: clamp(1.5rem, 4vw, 3rem);
    color: #f5c957;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    text-shadow: 0 0 20px rgba(242, 166, 90, 0.5);
    margin-bottom: 8px;
}

.final-subheading {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 500;
    font-size: clamp(1rem, 2vw, 1.3rem);
    color: #f2a65a;
}

/* === Responsive === */
@media (max-width: 768px) {
    #hud-frame {
        border-width: 24px;
    }

    #hud-top-left {
        top: -20px;
        left: -20px;
        font-size: 0.8rem;
    }

    #hud-top-right {
        top: -18px;
        right: -20px;
        font-size: 0.55rem;
    }

    #hud-bottom {
        bottom: -20px;
        left: -20px;
        right: -20px;
    }

    .scene {
        padding-left: 16px;
        padding-right: 16px;
    }

    #scene-understory,
    #scene-roots,
    #scene-mycelium,
    #scene-bedrock {
        padding-left: 16px;
        padding-right: 16px;
    }

    .glass-card {
        max-width: 100%;
    }

    .root-child-1,
    .root-child-2,
    .root-child-3 {
        align-self: center;
        max-width: 100%;
    }

    .tree-1 { width: 80px; }
    .tree-2 { width: 60px; }
    .tree-3 { width: 100px; }
    .tree-4 { width: 70px; }
}
