/* ============================================
   meltdown.quest - Goblincore Fever Dream
   ============================================ */

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Literata', serif;
    background: linear-gradient(180deg, #2B1810 0%, #1A0E08 50%, #1C2E15 100%);
    color: #E8D5B7;
    overflow-x: hidden;
    min-height: 100vh;
    position: relative;
}

/* --- SVG Defs (hidden) --- */
.svg-defs {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
}

/* --- Grain Overlay --- */
#grain-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 1000;
    opacity: 0.06;
    mix-blend-mode: overlay;
    filter: url(#grain);
    background: transparent;
}

/* --- Particle Canvas --- */
#particle-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
}

/* --- Root Network Background --- */
.root-network {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
}

/* --- Breach Overlay (Intro Sequence) --- */
#breach-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

#breach-left,
#breach-right {
    position: absolute;
    top: 0;
    width: 52%;
    height: 100%;
    background: #2B1810;
    z-index: 2;
    transition: transform 0.8s ease-out;
}

#breach-left {
    left: 0;
}

#breach-right {
    right: 0;
}

#breach-left.split {
    transform: translateX(-105%);
}

#breach-right.split {
    transform: translateX(105%);
}

#breach-crack {
    position: absolute;
    width: 100%;
    height: 100%;
    z-index: 3;
    pointer-events: none;
}

#crack-path {
    stroke-dasharray: 2000;
    stroke-dashoffset: 2000;
    transition: stroke-dashoffset 1.2s ease-in-out;
}

#crack-path.animate {
    stroke-dashoffset: 0;
}

#breach-title {
    position: relative;
    z-index: 4;
    font-family: 'Syne', sans-serif;
    font-weight: 800;
    font-size: clamp(3rem, 10vw, 7rem);
    color: #C45D2A;
    letter-spacing: -0.03em;
    line-height: 0.95;
    text-transform: uppercase;
    opacity: 0;
    transition: opacity 0.3s ease;
}

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

#breach-title .letter {
    display: inline-block;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.2s ease, transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#breach-title .letter.show {
    opacity: 1;
    transform: translateY(0);
}

#scroll-indicator {
    position: absolute;
    bottom: 40px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 5;
    font-family: 'Caveat', cursive;
    font-size: 1.3rem;
    color: #E8D5B7;
    opacity: 0;
    transition: opacity 0.5s ease;
    text-align: center;
}

#scroll-indicator.visible {
    opacity: 1;
    animation: pulse-indicator 2s ease-in-out infinite;
}

.arrow-down {
    display: block;
    font-size: 1.8rem;
    margin-top: 4px;
}

@keyframes pulse-indicator {
    0%, 100% { opacity: 0.6; transform: translateX(-50%) translateY(0); }
    50% { opacity: 1; transform: translateX(-50%) translateY(8px); }
}

#breach-overlay.done {
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.6s ease;
}

/* --- Sidebar --- */
#sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: 280px;
    height: 100vh;
    background: linear-gradient(180deg, #2B1810 0%, #1A0E08 100%);
    z-index: 100;
    padding: 30px 20px;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    border-right: 2px solid #6B4226;
    transform: translateX(-100%);
    transition: transform 0.5s ease;
}

#sidebar.visible {
    transform: translateX(0);
}

/* Sidebar noise grain overlay */
#sidebar::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    filter: url(#grain);
    opacity: 0.12;
    pointer-events: none;
    z-index: 0;
}

.sidebar-header {
    margin-bottom: 30px;
    position: relative;
    z-index: 1;
}

.sidebar-title {
    font-size: 1.4rem;
    color: #C45D2A;
    text-transform: lowercase;
    letter-spacing: 0.05em;
}

#sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 12px;
    position: relative;
    z-index: 1;
}

.nav-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px 8px 12px;
    background: #E8D5B7;
    border: 2px solid #6B4226;
    clip-path: polygon(0 0, 92% 0, 100% 50%, 92% 100%, 0 100%);
    text-decoration: none;
    color: #5A6B3C;
    font-size: clamp(0.9rem, 2vw, 1.3rem);
    transform: rotate(var(--label-rot, 0deg));
    transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
    position: relative;
    cursor: pointer;
}

.nav-label:hover {
    background: #D4C4A0;
    color: #C45D2A;
    transform: rotate(calc(var(--label-rot, 0deg) + 2deg));
}

.nav-label:hover .label-text {
    color: #C45D2A;
}

.nav-label:active {
    transform: rotate(var(--label-rot, 0deg)) scale(0.95);
    background: #E8962A;
}

.label-text {
    transition: color 0.2s ease;
}

.label-mushroom {
    opacity: 0;
    transition: opacity 0.3s ease;
    flex-shrink: 0;
}

.nav-label:hover .label-mushroom {
    opacity: 1;
}

.sidebar-fern {
    margin-top: auto;
    align-self: center;
    position: relative;
    z-index: 1;
}

/* --- Hamburger (Mobile) --- */
#hamburger {
    display: none;
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 200;
    background: rgba(43, 24, 16, 0.9);
    border: 2px solid #6B4226;
    border-radius: 8px;
    padding: 10px;
    cursor: pointer;
    flex-direction: column;
    gap: 5px;
    width: 48px;
    height: 42px;
    justify-content: center;
    align-items: center;
}

.twig {
    display: block;
    width: 24px;
    height: 3px;
    background: #A0522D;
    border-radius: 40%;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.twig:nth-child(1) {
    transform: rotate(-2deg);
    width: 22px;
}

.twig:nth-child(2) {
    transform: rotate(1deg);
    width: 26px;
}

.twig:nth-child(3) {
    transform: rotate(-1deg);
    width: 20px;
}

#hamburger.open .twig:nth-child(1) {
    transform: rotate(45deg) translate(4px, 4px);
}

#hamburger.open .twig:nth-child(2) {
    opacity: 0;
}

#hamburger.open .twig:nth-child(3) {
    transform: rotate(-45deg) translate(6px, -6px);
}

/* Mobile overlay */
#mobile-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(26, 14, 8, 0.7);
    z-index: 90;
    opacity: 0;
    transition: opacity 0.3s ease;
}

#mobile-overlay.active {
    display: block;
    opacity: 1;
}

/* --- Main Content --- */
#main-content {
    margin-left: 280px;
    padding: 60px 40px 40px;
    position: relative;
    z-index: 1;
    min-height: 100vh;
    opacity: 0;
    transition: opacity 0.6s ease;
}

#main-content.visible {
    opacity: 1;
}

/* --- Content Sections --- */
.content-section {
    position: relative;
    margin-bottom: 20px;
}

/* --- Collage Grid --- */
.collage-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 10px;
    position: relative;
}

/* Overlapping effect via negative margins on grid items */
.collage-grid > *:nth-child(n+2) {
    margin-top: -30px;
}

/* --- Specimen Cards --- */
.specimen-card {
    background: #E8D5B7;
    color: #3D2B1F;
    padding: 30px 28px;
    position: relative;
    transform: rotate(var(--block-rot, 0deg));
    filter: drop-shadow(3px 4px 6px rgba(26, 14, 8, 0.4));
    z-index: 1;
}

/* Apply torn clip paths cyclically */
.specimen-card[style*="torn1"] {
    clip-path: url(#torn1);
}

.specimen-card[style*="torn2"] {
    clip-path: url(#torn2);
}

.specimen-card[style*="torn3"] {
    clip-path: url(#torn3);
}

.specimen-card[style*="torn4"] {
    clip-path: url(#torn4);
}

.specimen-card[style*="torn5"] {
    clip-path: url(#torn5);
}

/* Rust streak overlay */
.specimen-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: repeating-linear-gradient(
        45deg,
        transparent 0%,
        transparent 90%,
        #A0522D 90%,
        #A0522D 91%,
        transparent 91%
    );
    opacity: 0.18;
    pointer-events: none;
    z-index: 1;
}

/* Z-index stacking for collage layering */
.collage-grid > *:nth-child(1) { z-index: 1; }
.collage-grid > *:nth-child(2) { z-index: 2; }
.collage-grid > *:nth-child(3) { z-index: 3; }
.collage-grid > *:nth-child(4) { z-index: 4; }
.collage-grid > *:nth-child(5) { z-index: 5; }
.collage-grid > *:nth-child(6) { z-index: 6; }

/* --- Rot Circles --- */
.rot-circle {
    width: 160px;
    height: 160px;
    border-radius: 50%;
    background: radial-gradient(ellipse at 30% 70%, #A0522D 0%, #2B1810 70%);
    box-shadow: inset 0 0 30px 10px #C45D2A;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    justify-self: center;
    position: relative;
    z-index: 2;
}

.rot-number {
    font-family: 'Syne', sans-serif;
    font-weight: 800;
    font-size: 2.8rem;
    color: #E8962A;
    line-height: 1;
}

.rot-label {
    font-family: 'Caveat', cursive;
    font-size: 1rem;
    color: #E8D5B7;
    margin-top: 4px;
}

/* --- Typography --- */
.syne {
    font-family: 'Syne', sans-serif;
}

.literata {
    font-family: 'Literata', serif;
    font-size: clamp(1rem, 1.8vw, 1.15rem);
    font-weight: 400;
    line-height: 1.65;
    letter-spacing: 0.01em;
}

.caveat {
    font-family: 'Caveat', cursive;
}

.section-heading {
    font-weight: 800;
    font-size: clamp(1.8rem, 5vw, 3.2rem);
    color: #1A0E08;
    letter-spacing: -0.03em;
    line-height: 0.95;
    margin-bottom: 20px;
    transition: font-weight 0.3s ease;
}

.section-heading:hover {
    font-weight: 400;
}

.specimen-title {
    font-weight: 700;
    font-size: clamp(1.2rem, 3vw, 1.8rem);
    color: #C45D2A;
    margin-bottom: 12px;
    transition: font-weight 0.3s ease;
}

.specimen-title:hover {
    font-weight: 400;
}

.specimen-card p {
    margin-bottom: 14px;
    position: relative;
    z-index: 2;
}

.specimen-card p em {
    font-style: italic;
    color: #6B5B4F;
}

/* --- Annotations (Caveat labels) --- */
.annotation {
    display: inline-block;
    font-size: clamp(0.9rem, 2vw, 1.3rem);
    color: #A0522D;
    transform: rotate(var(--label-rot, 0deg));
    margin-top: 8px;
    position: relative;
    z-index: 2;
}

/* --- Mushroom Clusters --- */
.mushroom-cluster {
    position: relative;
    z-index: 2;
    margin-top: 10px;
}

.mushroom-svg {
    width: 100%;
    max-width: 140px;
    height: auto;
    transform: scaleY(0);
    transform-origin: bottom center;
    transition: transform 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.mushroom-cluster.grown .mushroom-svg {
    transform: scaleY(1);
}

/* --- Fern Strips --- */
.fern-strip {
    width: 100%;
    height: 80px;
    background: linear-gradient(180deg, #1C2E15 0%, #2B1810 100%);
    margin: 20px 0;
    position: relative;
    overflow: hidden;
    border-top: 1px solid rgba(75, 92, 58, 0.2);
    border-bottom: 1px solid rgba(75, 92, 58, 0.2);
}

/* Fern strip inner color: #4A5C3A used in SVG, #B87333 for copper accents */
.fern-strip-svg g {
    fill: #4A5C3A;
}

.fern-strip-svg {
    width: 100%;
    height: 100%;
}

/* --- Cracked Earth Dividers --- */
.cracked-earth-divider {
    width: 100%;
    height: 60px;
    margin: 30px 0;
    position: relative;
}

.cracked-earth-svg {
    width: 100%;
    height: 100%;
}

/* --- Scroll Fern (appears at 50%) --- */
#scroll-fern {
    position: fixed;
    right: 0;
    top: 0;
    width: 300px;
    height: 100vh;
    pointer-events: none;
    z-index: 0;
    opacity: 0;
    transition: opacity 1s ease;
}

#scroll-fern.visible {
    opacity: 1;
}

/* --- Bounce Enter Animation --- */
.bounce-enter {
    opacity: 0;
    transform: translateY(40px) scale(0.95) rotate(var(--block-rot, 0deg));
    transition: opacity 0.6s cubic-bezier(0.34, 1.56, 0.64, 1),
                transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.bounce-enter.entered {
    opacity: 1;
    transform: translateY(0) scale(1) rotate(var(--block-rot, 0deg));
}

/* Rot circles get a more aggressive bounce */
.rot-circle.bounce-enter {
    transform: scale(0.3);
}

.rot-circle.bounce-enter.entered {
    transform: scale(1);
    transition-timing-function: cubic-bezier(0.25, 1.8, 0.5, 1);
    transition-duration: 0.5s;
}

/* --- Footer --- */
#site-footer {
    background: linear-gradient(180deg, #1C2E15 0%, #0D1A0A 100%);
    padding: 60px 40px;
    text-align: center;
    position: relative;
    z-index: 2;
    border-top: 2px solid #6B4226;
}

.footer-title {
    font-weight: 800;
    font-size: clamp(1.5rem, 4vw, 2.5rem);
    color: #C45D2A;
    letter-spacing: -0.03em;
    margin-bottom: 10px;
    text-transform: uppercase;
}

.footer-tagline {
    font-size: 1.3rem;
    color: #5A6B3C;
    margin-bottom: 20px;
}

.footer-ferns {
    display: flex;
    justify-content: center;
}

.footer-fern-svg {
    width: 200px;
    height: 60px;
}

/* --- Copper Wire Accents --- */
.copper-wire {
    stroke: #B87333;
    stroke-width: 1.5;
    fill: none;
}

.copper-wire-end {
    fill: #8B5E3C;
}

/* --- Ember Gradient Accents (uses #D4763C) --- */
.ember-accent {
    background: linear-gradient(135deg, #C45D2A 0%, #D4763C 40%, #E8962A 100%);
}

/* --- Links --- */
a {
    color: #C45D2A;
    text-decoration: none;
    transition: color 0.2s ease;
}

a:hover {
    color: #E8962A;
}

/* --- Scrollbar Styling --- */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: #1A0E08;
}

::-webkit-scrollbar-thumb {
    background: #6B4226;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #A0522D;
}

/* --- Mobile Responsive (below 768px) --- */
@media (max-width: 768px) {
    #sidebar {
        width: 280px;
        z-index: 150;
    }

    #hamburger {
        display: flex;
    }

    #main-content {
        margin-left: 0;
        padding: 80px 20px 30px;
    }

    .collage-grid {
        grid-template-columns: 1fr;
    }

    .rot-circle {
        width: 130px;
        height: 130px;
    }

    .rot-number {
        font-size: 2.2rem;
    }

    #breach-title {
        font-size: clamp(2rem, 8vw, 4rem);
    }

    .specimen-card {
        padding: 22px 20px;
    }
}

/* --- Tablet (769px - 1024px) --- */
@media (min-width: 769px) and (max-width: 1024px) {
    #sidebar {
        width: 220px;
    }

    #main-content {
        margin-left: 220px;
        padding: 50px 30px;
    }
}

/* --- Large screens --- */
@media (min-width: 1400px) {
    .collage-grid {
        grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    }
}
