/* Header, smooth scrolling and click feel.
   Linked from every page through the shared head partial.

   Why the gap happened: the top bar scrolled with the page while the navbar stayed fixed 37px down,
   so the first 50px of scrolling opened a strip above the navbar, then the navbar jumped to the top.
   Now the top bar and navbar are one fixed unit that moves together with transforms only. */

:root { --tb-h: 0px; --ease-out: cubic-bezier(.22, 1, .36, 1); }
@media (min-width: 768px) { :root { --tb-h: 37px; } } /* motion.js measures the real height */

/* ---------- Smooth scrolling (Lenis) ---------- */
html { scroll-padding-top: 76px; }
html.lenis, html.lenis body { height: auto; }
html.lenis { scroll-behavior: auto !important; }
.lenis:not(.lenis-autoToggle).lenis-stopped { overflow: clip; }
.lenis [data-lenis-prevent] { overscroll-behavior: contain; }
.lenis.lenis-smooth iframe { pointer-events: none; }

/* ---------- Header unit ---------- */
.content-layer { padding-top: var(--tb-h); } /* keeps the page exactly where it was when the top bar was in flow */

.top-bar {
    position: fixed; top: 0; left: 0; right: 0; z-index: 51;
    background: rgba(255, 255, 255, .78) !important; border-bottom: 0 !important;
    -webkit-backdrop-filter: blur(14px) saturate(1.4); backdrop-filter: blur(14px) saturate(1.4);
    transition: transform .55s var(--ease-out), opacity .35s ease; will-change: transform;
}
#navbar, #navbar.scrolled { top: var(--tb-h) !important; }
#navbar {
    background: linear-gradient(180deg, rgba(255, 255, 255, .78), rgba(244, 251, 245, .62)) !important;
    border-bottom: 0 !important; box-shadow: none;
    -webkit-backdrop-filter: blur(14px) saturate(1.4); backdrop-filter: blur(14px) saturate(1.4);
    transition: transform .55s var(--ease-out), background-color .35s ease, box-shadow .35s ease;
    will-change: transform;
}
/* At the top of the page the header has no hard lower edge: its tint fades out over 28px */
#navbar::after { content: ""; position: absolute; left: 0; right: 0; top: 100%; height: 28px; pointer-events: none;
    background: linear-gradient(180deg, rgba(244, 251, 245, .62), rgba(244, 251, 245, 0)); transition: opacity .35s ease; }
.nav-compact #navbar::after { opacity: 0; }
/* The logo rests on a soft mint glow (no box), so foliage behind the header never runs through it */
#navbar > .container > a:first-child { position: relative; }
#navbar > .container > a:first-child::before { content: ""; position: absolute; inset: -18px -34px; z-index: -1;
    pointer-events: none; background: radial-gradient(closest-side, rgba(246, 252, 247, .96) 55%, rgba(246, 252, 247, 0));
    transition: opacity .35s ease; }
.nav-compact #navbar > .container > a:first-child::before { opacity: 0; } /* the compact bar is opaque enough */
#navbar > .container { border-bottom: 0 !important; transition: padding .45s var(--ease-out); }
#navbar a > img { height: 64px !important; transition: height .45s var(--ease-out); }

/* Compact: top bar slides away, navbar follows it up by exactly its height (same curve, same time). */
.nav-compact .top-bar { transform: translateY(-100%); opacity: 0; pointer-events: none; }
.nav-compact #navbar {
    transform: translateY(calc(-1 * var(--tb-h)));
    background: rgba(250, 253, 250, .9) !important;
    box-shadow: 0 12px 32px -20px rgba(16, 60, 30, .45);
}
.nav-compact #navbar > .container { padding-top: 6px; padding-bottom: 6px; }
.nav-compact #navbar a > img { height: 50px !important; }

/* Nav links: a green underline that grows on hover and marks the section you are reading */
#navbar .container > ul > li > a { position: relative; transition: color .25s ease; }
#navbar .container > ul > li > a::after {
    content: ""; position: absolute; left: 0; right: 0; bottom: -6px; height: 2px; border-radius: 2px;
    background: #39B54A; transform: scaleX(0); transform-origin: left center;
    transition: transform .4s var(--ease-out);
}
#navbar .container > ul > li > a:hover::after,
#navbar .container > ul > li > a.is-active::after { transform: scaleX(1); }
#navbar .container > ul > li > a.is-active { color: #1d235c; }

/* ---------- Click feel ---------- */
a, button { -webkit-tap-highlight-color: transparent; }
.content-layer a[class*="rounded"], .content-layer button, #navbar a[href="#contact"] {
    transition: transform .25s var(--ease-out), box-shadow .25s ease, background-color .25s ease,
                color .2s ease, border-color .2s ease !important;
}
.content-layer a[class*="rounded"]:hover, #navbar a[href="#contact"]:hover { transform: translateY(-1px); }
.content-layer a[class*="rounded"]:active, .content-layer button:active,
#navbar a[href="#contact"]:active { transform: scale(.97); }
.glass-card.cursor-pointer:active { transform: translateY(-1px) scale(.99); }
:focus-visible { outline: 2px solid #39B54A; outline-offset: 3px; }

/* Reveal-on-scroll: same effect as before, softer easing */
.fade-in { transition: opacity .8s var(--ease-out), transform .8s var(--ease-out); }

@media (prefers-reduced-motion: reduce) {
    .top-bar, #navbar, #navbar > .container, #navbar a > img, .fade-in { transition: none !important; }
}
