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

:root {
    --pressed-linen: #FAF3E8;
    --forest-floor: #1F1710;
    --dark-umber: #3D2E1F;
    --faded-parchment: #D4C4A8;
    --sunset-coral: #D4623A;
    --twilight-violet: #4A2B5C;
    --amber-vein: #C4956A;
    --dust-mote: #8B7355;
    --cursor-x: 50%;
    --cursor-y: 50%;
    --cursor-x-ratio: 0.5;
}

html {
    scroll-behavior: smooth;
}

body {
    background: var(--pressed-linen);
    color: var(--dark-umber);
    font-family: 'Source Serif 4', Georgia, serif;
    font-size: clamp(1rem, 1.2vw, 1.2rem);
    line-height: 1.72;
    overflow-x: hidden;
}

/* === FILM GRAIN === */
#grain {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 9999;
    mix-blend-mode: multiply;
}

#grain svg {
    width: 100%;
    height: 100%;
}

/* === CURSOR FOLLOWER === */
#cursor-follower {
    position: fixed;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--sunset-coral);
    pointer-events: none;
    z-index: 9998;
    transition: transform 60ms ease-out, background-color 300ms ease;
    transform: translate(-50%, -50%);
    mix-blend-mode: multiply;
    opacity: 0.7;
}

#leaf-trails {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 9997;
}

.leaf-fragment {
    position: absolute;
    pointer-events: none;
    opacity: 0;
    animation: leafFall 1.2s ease-out forwards;
}

@keyframes leafFall {
    0% { opacity: 0.5; transform: translateY(0) rotate(var(--leaf-rotation)); }
    100% { opacity: 0; transform: translateY(20px) rotate(calc(var(--leaf-rotation) + 30deg)); }
}

/* === HERO: THE THRESHOLD === */
#hero {
    height: 100vh;
    display: grid;
    grid-template-columns: 1fr 1fr;
    position: relative;
    overflow: hidden;
}

.hero-panel {
    position: relative;
    overflow: hidden;
}

.hero-panel__image {
    position: absolute;
    inset: 0;
    background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="1200" height="800"><defs><linearGradient id="sky" x1="0" y1="0" x2="0" y2="1"><stop offset="0%" stop-color="%23999"/><stop offset="60%" stop-color="%23777"/><stop offset="100%" stop-color="%23555"/></linearGradient></defs><rect fill="url(%23sky)" width="1200" height="800"/><path d="M0,500 Q200,350 400,420 T800,380 T1200,450 L1200,800 L0,800Z" fill="%23444"/><path d="M0,550 Q300,450 600,500 T1200,480 L1200,800 L0,800Z" fill="%23333"/><circle cx="900" cy="200" r="60" fill="%23bbb" opacity="0.5"/></svg>') center/cover no-repeat;
    filter: grayscale(100%) contrast(1.1);
}

.hero-panel--warm .hero-panel__overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(160deg, #D4623A 0%, #C4956A 60%, #FAF3E8 100%);
    mix-blend-mode: multiply;
    opacity: 0.7;
    transition: filter 500ms ease;
}

.hero-panel--cool .hero-panel__overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(200deg, #4A2B5C 0%, #3D2E1F 60%, #1F1710 100%);
    mix-blend-mode: multiply;
    opacity: 0.7;
    transition: filter 500ms ease;
}

.hero-panel--warm {
    transition: filter 500ms ease;
    filter: hue-rotate(calc((var(--cursor-x-ratio) - 0.5) * 30deg));
}

.hero-panel--cool {
    transition: filter 500ms ease;
    filter: hue-rotate(calc((0.5 - var(--cursor-x-ratio)) * 30deg));
}

#hero-divider {
    position: absolute;
    left: 50%;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--pressed-linen);
    z-index: 10;
    animation: pulse 3s ease-in-out infinite;
    transform: translateX(-50%);
}

@keyframes pulse {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 1.0; }
}

#hero-title {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 20;
    font-family: 'Libre Baskerville', serif;
    font-weight: 700;
    font-size: clamp(2.5rem, 7vw, 6rem);
    letter-spacing: 0.02em;
    line-height: 1.05;
    text-shadow: 1px 1px 0 rgba(31, 23, 16, 0.3);
    white-space: nowrap;
}

.title-warm {
    color: var(--sunset-coral);
}

.title-cool {
    color: var(--faded-parchment);
}

#hero-subtitle {
    position: absolute;
    bottom: 15%;
    left: 50%;
    transform: translateX(-50%);
    z-index: 20;
    font-family: 'Josefin Sans', sans-serif;
    font-weight: 300;
    font-size: clamp(0.7rem, 0.9vw, 0.85rem);
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--amber-vein);
    white-space: nowrap;
}

/* === BRANCHING GRID === */
#branching-grid {
    position: relative;
    max-width: 1440px;
    margin: 0 auto;
    padding: clamp(16px, 3vw, 48px);
}

.background-veins {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.grid-container {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    grid-auto-flow: dense;
    gap: 16px;
    grid-auto-rows: minmax(120px, auto);
}

.module {
    position: relative;
    overflow: hidden;
    border-radius: 8px;
    background: var(--pressed-linen);
    box-shadow: inset 0 2px 8px rgba(31, 23, 16, 0.15);
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 600ms cubic-bezier(0.25, 0.46, 0.45, 0.94),
                transform 600ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.module.visible {
    opacity: 1;
    transform: translateY(0) perspective(800px)
        rotateX(calc((var(--cursor-y) - 50%) * 0.03deg))
        rotateY(calc((var(--cursor-x) - 50%) * -0.03deg));
}

/* Module grid placements */
.module--a { grid-column: span 5; grid-row: span 4; }
.module--b { grid-column: span 4; grid-row: span 3; }
.module--c { grid-column: span 8; grid-row: span 2; }
.module--d { grid-column: span 3; grid-row: span 5; }
.module--e { grid-column: span 5; grid-row: span 3; }
.module--f { grid-column: span 4; grid-row: span 2; }
.module--g { grid-column: span 8; grid-row: span 3; }

.module__image-wrap {
    position: absolute;
    inset: 0;
}

.module__image {
    position: absolute;
    inset: 0;
    background-size: cover;
    background-position: center;
    filter: grayscale(100%) contrast(1.1);
}

.module__duotone {
    position: absolute;
    inset: 0;
    mix-blend-mode: multiply;
}

.module__duotone--warm {
    background: linear-gradient(#D4623A, #C4956A);
}

.module__duotone--cool {
    background: linear-gradient(#4A2B5C, #3D2E1F);
}

.module__duotone-alt {
    opacity: 0;
    transition: opacity 500ms ease;
}

.module:hover .module__duotone-alt {
    opacity: 0.3;
}

.module__content {
    position: relative;
    z-index: 5;
    padding: clamp(16px, 2vw, 32px);
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    height: 100%;
    background: linear-gradient(to top, rgba(31, 23, 16, 0.7) 0%, transparent 60%);
}

.module__tag {
    font-family: 'Josefin Sans', sans-serif;
    font-weight: 300;
    font-size: clamp(0.7rem, 0.9vw, 0.85rem);
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--amber-vein);
    margin-bottom: 8px;
}

.module__title {
    font-family: 'Libre Baskerville', serif;
    font-weight: 700;
    font-size: clamp(1.2rem, 2vw, 1.8rem);
    letter-spacing: 0.02em;
    line-height: 1.15;
    color: var(--pressed-linen);
    text-shadow: 1px 1px 0 rgba(31, 23, 16, 0.3);
    margin-bottom: 8px;
}

.module__text {
    font-family: 'Source Serif 4', Georgia, serif;
    font-size: clamp(0.85rem, 1vw, 1rem);
    line-height: 1.6;
    color: var(--faded-parchment);
    max-width: 62ch;
}

.module__hover-glow {
    position: absolute;
    inset: 0;
    z-index: 4;
    background: radial-gradient(ellipse at var(--cursor-x) var(--cursor-y), rgba(212,98,58,0.12), transparent 70%);
    pointer-events: none;
    opacity: 0;
    transition: opacity 300ms ease;
}

.module:hover .module__hover-glow {
    opacity: 1;
}

.module__vein {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 3;
    pointer-events: none;
}

.module__vein path {
    stroke-dasharray: 200;
    stroke-dashoffset: 200;
    transition: stroke-dashoffset 1.5s ease;
}

.module.visible .module__vein path {
    stroke-dashoffset: 0;
}

/* === CONFLUENCE === */
#confluence {
    padding: clamp(32px, 5vw, 80px) clamp(16px, 3vw, 48px);
    max-width: 1440px;
    margin: 0 auto;
    overflow: hidden;
}

.confluence__title {
    font-family: 'Libre Baskerville', serif;
    font-weight: 700;
    font-size: clamp(1.5rem, 3vw, 2.5rem);
    letter-spacing: 0.02em;
    line-height: 1.05;
    color: var(--dark-umber);
    text-shadow: 1px 1px 0 rgba(31, 23, 16, 0.1);
    text-align: center;
    margin-bottom: clamp(24px, 3vw, 48px);
}

.confluence__strip {
    display: flex;
    gap: 24px;
    width: max-content;
    will-change: transform;
}

.confluence__pair {
    display: flex;
    gap: 4px;
    position: relative;
    flex-shrink: 0;
}

.confluence__image {
    width: 280px;
    height: 200px;
    border-radius: 6px;
    position: relative;
    overflow: hidden;
}

.confluence__image--warm {
    background: linear-gradient(160deg, #D4623A 0%, #C4956A 60%, #8B7355 100%);
}

.confluence__image--cool {
    background: linear-gradient(200deg, #4A2B5C 0%, #3D2E1F 60%, #1F1710 100%);
}

.confluence__image::after {
    content: '';
    position: absolute;
    inset: 0;
    background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="280" height="200"><rect fill="%23888" width="280" height="200" opacity="0.3"/><path d="M0,150 Q70,100 140,130 T280,110" stroke="%23aaa" fill="none" stroke-width="2" opacity="0.3"/><circle cx="200" cy="60" r="30" fill="%23aaa" opacity="0.2"/></svg>') center/cover;
    filter: grayscale(100%) contrast(1.1);
    mix-blend-mode: overlay;
    opacity: 0.5;
}

.confluence__label {
    position: absolute;
    bottom: -24px;
    left: 50%;
    transform: translateX(-50%);
    font-family: 'Josefin Sans', sans-serif;
    font-weight: 300;
    font-size: clamp(0.65rem, 0.8vw, 0.75rem);
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--amber-vein);
    white-space: nowrap;
}

/* === ROOT SYSTEM (FOOTER) === */
#root-system {
    position: relative;
    background: var(--forest-floor);
    min-height: 500px;
    overflow: hidden;
    padding: clamp(60px, 8vw, 120px) clamp(16px, 3vw, 48px) clamp(32px, 4vw, 60px);
}

.root-veins {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.vein-path {
    stroke-dasharray: 600;
    stroke-dashoffset: 600;
    transition: stroke-dashoffset 2.5s ease;
}

#root-system.visible .vein-path {
    stroke-dashoffset: 0;
}

.footer-content {
    position: relative;
    z-index: 5;
    text-align: center;
    max-width: 800px;
    margin: 0 auto;
}

.footer-nav {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 32px;
    margin-bottom: 48px;
}

.footer-nav__link {
    font-family: 'Josefin Sans', sans-serif;
    font-weight: 300;
    font-size: clamp(0.7rem, 0.9vw, 0.85rem);
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--amber-vein);
    text-decoration: none;
    position: relative;
    transition: color 300ms ease;
}

.footer-nav__link::after {
    content: '';
    position: absolute;
    bottom: -4px;
    left: 0;
    width: 0;
    height: 1px;
    background: var(--sunset-coral);
    transition: width 300ms ease;
}

.footer-nav__link:hover {
    color: var(--sunset-coral);
}

.footer-nav__link:hover::after {
    width: 100%;
}

.footer-text {
    font-family: 'Source Serif 4', Georgia, serif;
    font-size: clamp(1rem, 1.5vw, 1.3rem);
    line-height: 1.72;
    color: var(--faded-parchment);
    margin-bottom: 24px;
    font-style: italic;
}

.footer-copyright {
    font-family: 'Josefin Sans', sans-serif;
    font-weight: 300;
    font-size: 0.75rem;
    letter-spacing: 0.12em;
    color: var(--dust-mote);
    opacity: 0.6;
}

/* === RESPONSIVE === */
@media (max-width: 900px) {
    #hero {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr 1fr;
    }

    #hero-divider {
        left: 0;
        right: 0;
        top: 50%;
        bottom: auto;
        width: 100%;
        height: 2px;
    }

    .grid-container {
        grid-template-columns: repeat(6, 1fr);
    }

    .module--a, .module--b, .module--c,
    .module--d, .module--e, .module--f,
    .module--g {
        grid-column: span 6;
        grid-row: span 2;
    }

    .confluence__image {
        width: 200px;
        height: 140px;
    }

    .footer-nav {
        flex-direction: column;
        align-items: center;
        gap: 20px;
    }
}

@media (max-width: 600px) {
    .grid-container {
        grid-template-columns: 1fr;
    }

    .module--a, .module--b, .module--c,
    .module--d, .module--e, .module--f,
    .module--g {
        grid-column: span 1;
        grid-row: span 1;
        min-height: 300px;
    }
}
