/* ==========================================================================
   GLOBAL DESIGN SYSTEM & COMMON STYLES
   ========================================================================== */

:root {
    /* Color Palette - Default Light Cream Theme */
    --ink: #0b1014;
    --night: #11191f;
    --panel: #172229;
    --paper: #f7f4ee;
    --paper-2: #ece7dc;
    --line: rgba(247, 244, 238, 0.16);
    --line-dark: rgba(11, 16, 20, 0.13);
    --text: #f7f4ee;
    --muted: #aab5b7;
    --muted-dark: #536066;
    
    /* Accents */
    --teal: #28c6a8;
    --blue: #4c7dff;
    --amber: #f4b84a;
    --rose: #df6d82;
    --green: #63c46f;
    
    /* Borders & Shadow */
    --radius: 8px;
    --shadow: 0 28px 90px rgba(11, 16, 20, 0.22);
}

/* Dark Mode Color Variable Overrides */
html[data-theme="dark"] {
    --paper: #0b1014;
    --paper-2: #11191f;
    --ink: #f7f4ee;
    --line-dark: rgba(247, 244, 238, 0.18);
    --muted-dark: #a5b0b3;
    --shadow: 0 28px 90px rgba(0, 0, 0, 0.62);
    --night: #060a0d;
    --panel: #152129;
}

* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

/* ==========================================================================
   CROSS-PAGE TRANSITIONS
   Modern browsers honour @view-transition for native cross-document
   animations. The JS fallback handles every other engine via a fade-slide
   class swap.
   ========================================================================== */
@view-transition {
    navigation: auto;
}

::view-transition-old(root) {
    animation: pt-fade-out 320ms cubic-bezier(0.4, 0, 0.2, 1) both;
}

::view-transition-new(root) {
    animation: pt-fade-in 420ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes pt-fade-in {
    from { opacity: 0; transform: translateY(14px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes pt-fade-out {
    from { opacity: 1; transform: translateY(0); }
    to   { opacity: 0; transform: translateY(-10px); }
}

body {
    margin: 0;
    font-family: Manrope, Arial, sans-serif;
    color: var(--ink);
    background: var(--paper);
    line-height: 1.6;
    letter-spacing: 0;
    overflow-x: hidden;
    transition: background-color 0.4s ease, color 0.4s ease;
}

/* JS-driven fallback: opacity-only so position:fixed children (topbar,
   scroll-meter, cursor-light, noise) stay anchored to the viewport. */
body.page-enter   { opacity: 0; }
body.page-loaded  {
    opacity: 1;
    transition: opacity 0.45s cubic-bezier(0.16, 1, 0.3, 1),
                background-color 0.4s ease, color 0.4s ease;
}
body.page-leaving {
    opacity: 0;
    transition: opacity 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

@media (prefers-reduced-motion: reduce) {
    body.page-enter, body.page-loaded, body.page-leaving {
        opacity: 1 !important;
        transition: none !important;
    }
    ::view-transition-old(root),
    ::view-transition-new(root) {
        animation: none !important;
    }
}

a {
    color: inherit;
    text-decoration: none;
}

/* --- Scroll Meter Progress Bar --- */
.scroll-meter {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 80;
    height: 4px;
    width: 100%;
    transform-origin: left;
    transform: scaleX(0);
    background: linear-gradient(90deg, var(--teal), var(--blue), var(--amber));
}

/* --- Background Grain & Texture --- */
.noise {
    pointer-events: none;
    position: fixed;
    inset: 0;
    z-index: 70;
    opacity: 0.035;
    background-image:
        linear-gradient(90deg, #000 1px, transparent 1px),
        linear-gradient(#000 1px, transparent 1px);
    background-size: 7px 7px;
}

html[data-theme="dark"] .noise {
    background-image:
        linear-gradient(90deg, #fff 1px, transparent 1px),
        linear-gradient(#fff 1px, transparent 1px);
    opacity: 0.02;
}

/* --- Ambient Spotlight Follower --- */
.cursor-light {
    pointer-events: none;
    position: fixed;
    z-index: 1;
    width: 420px;
    height: 420px;
    transform: translate(-50%, -50%);
    background: radial-gradient(circle, rgba(40, 198, 168, 0.11), transparent 62%);
    opacity: 0;
    transition: opacity 0.25s ease;
}

html[data-theme="dark"] .cursor-light {
    background: radial-gradient(circle, rgba(40, 198, 168, 0.15), transparent 65%);
}

.wrap {
    width: min(1180px, calc(100% - 42px));
    margin: 0 auto;
}

/* ==========================================================================
   TOPBAR NAVIGATION
   ========================================================================== */

.topbar {
    position: -webkit-sticky;       /* legacy iOS Safari */
    position: fixed !important;     /* hard-pin against any later override */
    top: 18px;
    left: 50%;
    z-index: 60;
    width: min(1180px, calc(100% - 42px));
    transform: translateX(-50%);
    border: 1px solid rgba(247, 244, 238, 0.15);
    border-radius: 8px;
    background: rgba(17, 25, 31, 0.76);
    color: var(--text);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    box-shadow: 0 18px 50px rgba(11, 16, 20, 0.28);
    transition: border-color 0.4s ease, background-color 0.4s ease;
    will-change: transform;         /* hint mobile GPU compositor */
}

html[data-theme="dark"] .topbar {
    border-color: rgba(247, 244, 238, 0.08);
    background: rgba(6, 10, 13, 0.82);
}

.nav {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 68px;
    padding: 0 14px 0 18px;
    gap: 18px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 800;
}

.mark {
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    background: var(--text);
    color: #0b1014;
    transition: background-color 0.4s ease, color 0.4s ease;
}

.brand span:last-child {
    display: block;
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 4px;
    color: rgba(247, 244, 238, 0.76);
    font-size: 0.82rem;
    font-weight: 800;
}

.nav-links a {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 11px;
    border-radius: 8px;
    border: 1px solid transparent;
    line-height: 1;
    transition: color 0.22s ease, background-color 0.22s ease,
                border-color 0.22s ease, transform 0.18s ease,
                box-shadow 0.22s ease;
}

.nav-links a > i,
.nav-links a > svg {
    display: inline-block;     /* reserves box-size before lucide hydrates */
    width: 15px;
    height: 15px;
    flex-shrink: 0;
    opacity: 0.85;
    transition: opacity 0.22s ease, transform 0.22s ease;
}

/* Fallback when the icon library failed to hydrate.
   main.js sets html.lucide-ready after a successful render. If the class
   never lands (CDN blocked, Cloudflare Rocket Loader interferes, etc.),
   the text labels stay visible so the nav is never invisible. */
html:not(.lucide-ready) .nav-links a > span {
    max-width: none !important;
    opacity: 1 !important;
    margin-left: 6px !important;
}
html:not(.lucide-ready) .nav-links a > i[data-lucide] {
    display: none;
}

.nav-links a:hover > i,
.nav-links a:hover > svg,
.nav-links a.active > i,
.nav-links a.active > svg {
    opacity: 1;
}

.nav-links a:hover > i,
.nav-links a:hover > svg {
    transform: scale(1.08);
}

.nav-links a > span {
    display: inline-block;
    font-size: 0.8rem;
    letter-spacing: 0.01em;
}

.nav-links a:hover {
    color: var(--text);
    background: rgba(247, 244, 238, 0.10);
    transform: translateY(-1px);
}

.nav-links a:active {
    transform: translateY(0);
}

.nav-links a.active:not(.nav-link-accent) {
    color: var(--text);
    background: rgba(247, 244, 238, 0.10);
}

/* ---- Cross-page accent link (Projects) — consistent across both pages ---- */
.nav-links a.nav-link-accent {
    color: var(--teal);
    background: rgba(40, 198, 168, 0.10);
    border-color: rgba(40, 198, 168, 0.30);
    padding: 9px 16px;
    font-weight: 800;
    letter-spacing: 0.01em;
    box-shadow: 0 6px 18px rgba(40, 198, 168, 0.08);
}

.nav-links a.nav-link-accent:hover {
    color: #0b1014;
    background: var(--teal);
    border-color: var(--teal);
    transform: translateY(-1px);
    box-shadow: 0 10px 24px rgba(40, 198, 168, 0.32);
}

.nav-links a.nav-link-accent:active {
    transform: translateY(0);
    box-shadow: 0 4px 10px rgba(40, 198, 168, 0.22);
}

.nav-links a.nav-link-accent:focus-visible {
    outline: 2px solid var(--teal);
    outline-offset: 2px;
}

/* Filled-pill state when the user is already on the Projects page */
.nav-links a.nav-link-accent.active {
    color: #0b1014;
    background: var(--teal);
    border-color: var(--teal);
    box-shadow: 0 8px 22px rgba(40, 198, 168, 0.28);
}

.nav-links a.nav-link-accent.active:hover {
    transform: translateY(-1px);
    box-shadow: 0 12px 28px rgba(40, 198, 168, 0.36);
}

/* ==========================================================================
   MOBILE NAV — HAMBURGER TOGGLE + SLIDE-DOWN PANEL
   ========================================================================== */

.nav-toggle {
    display: none;   /* shown only at mobile widths via override below */
    width: 40px;
    height: 40px;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid rgba(247, 244, 238, 0.22);
    border-radius: var(--radius);
    color: var(--text);
    cursor: pointer;
    transition: background-color 0.22s ease, border-color 0.22s ease;
}

.nav-toggle:hover {
    background: rgba(247, 244, 238, 0.10);
}

.nav-toggle-bars {
    position: relative;
    display: inline-block;
    width: 20px;
    height: 14px;
}

.nav-toggle-bars span {
    position: absolute;
    left: 0;
    width: 100%;
    height: 2px;
    background: currentColor;
    border-radius: 2px;
    transition: transform 0.28s ease, opacity 0.2s ease, top 0.28s ease;
}

.nav-toggle-bars span:nth-child(1) { top: 0; }
.nav-toggle-bars span:nth-child(2) { top: 6px; }
.nav-toggle-bars span:nth-child(3) { top: 12px; }

.nav.open .nav-toggle-bars span:nth-child(1) {
    top: 6px;
    transform: rotate(45deg);
}
.nav.open .nav-toggle-bars span:nth-child(2) {
    opacity: 0;
}
.nav.open .nav-toggle-bars span:nth-child(3) {
    top: 6px;
    transform: rotate(-45deg);
}

/* ==========================================================================
   MOBILE NAV — ICON-ONLY INLINE STRIP (shared by index.html + Projects.html)
   On mobile we drop the text labels and the hamburger. The nav links stay
   inline in the topbar as a compact row of icon chips, identical on both
   pages.
   ========================================================================== */
@media (max-width: 1020px) {
    /* Hamburger no longer needed — icon strip lives in the topbar */
    .nav-toggle { display: none !important; }

    /* Contact CTA hidden on mobile to keep the topbar uncluttered;
       reachable via Credentials → Contact section / footer socials. */
    .btn.nav-cta { display: none !important; }

    .nav {
        gap: 8px;
        padding: 0 10px;
    }

    .nav-links {
        display: inline-flex;
        align-items: center;
        gap: 2px;
        padding: 0;
        background: transparent;
        border: none;
        box-shadow: none;
        opacity: 1;
        visibility: visible;
        position: static;
        transform: none;
    }

    /* Icons-only by default; the active section's label slides open inline */
    .nav-links a {
        padding: 8px 9px;
        border-radius: 8px;
        gap: 0;
        transition: padding 0.28s ease, background-color 0.22s ease,
                    border-color 0.22s ease, color 0.22s ease;
    }
    .nav-links a > span {
        display: inline-block;
        max-width: 0;
        opacity: 0;
        overflow: hidden;
        margin-left: 0;
        white-space: nowrap;
        font-size: 0.74rem;
        font-weight: 800;
        letter-spacing: 0.02em;
        transition: max-width 0.32s cubic-bezier(0.16, 1, 0.3, 1),
                    opacity 0.22s ease,
                    margin-left 0.28s cubic-bezier(0.16, 1, 0.3, 1);
    }

    /* Active state on mobile: icon-only, no label expansion. The teal
       background and brighter icon indicate which section is current. */
    .nav-links a.active {
        background: rgba(40, 198, 168, 0.14);
        border-color: rgba(40, 198, 168, 0.30);
        color: var(--text);
    }
    .nav-links a.active > span {
        max-width: 0;        /* keep labels hidden on mobile even when active */
        opacity: 0;
        margin-left: 0;
    }
    .nav-links a.active > i,
    .nav-links a.active > svg {
        color: var(--teal);
        opacity: 1;
        transform: scale(1.08);
    }
    .nav-links a > i,
    .nav-links a > svg {
        width: 18px;
        height: 18px;
        opacity: 1;
    }

    /* Slimmer accent chip so it still feels distinct without the label */
    .nav-links a.nav-link-accent {
        padding: 8px 10px;
        border: 1px solid rgba(40, 198, 168, 0.35);
        background: rgba(40, 198, 168, 0.10);
        box-shadow: none;
    }
    .nav-links a.nav-link-accent.active {
        background: var(--teal);
        border-color: var(--teal);
        color: #0b1014;
    }
    .nav-links a.nav-link-accent.active > i,
    .nav-links a.nav-link-accent.active > svg {
        color: #0b1014;
    }
}

/* Extra-narrow phones: tighter still so everything stays inside the bar */
@media (max-width: 480px) {
    .nav { gap: 6px; padding: 0 8px; }
    .nav-links { gap: 0; }
    .nav-links a { padding: 7px 7px; }
    .nav-links a > i,
    .nav-links a > svg { width: 17px; height: 17px; }
    .btn-theme { width: 36px; height: 36px; }
}

/* --- Theme Selector Toggle --- */
.btn-theme {
    background: transparent;
    border: 1px solid rgba(247, 244, 238, 0.22);
    color: var(--text);
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background-color 0.25s, transform 0.25s, border-color 0.25s;
}

.btn-theme:hover {
    background: rgba(247, 244, 238, 0.12);
    transform: translateY(-1px);
}

.btn-theme svg {
    width: 18px;
    height: 18px;
}

/* ==========================================================================
   BUTTON COMPONENT
   ========================================================================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    min-height: 44px;
    padding: 0 17px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: var(--text);
    color: #0b1014;
    font-weight: 850;
    box-shadow: 0 18px 44px rgba(11, 16, 20, 0.24);
    transition: transform 0.25s ease, box-shadow 0.25s ease, background-color 0.25s ease, color 0.25s ease;
}

html[data-theme="dark"] .btn {
    box-shadow: 0 18px 44px rgba(0, 0, 0, 0.4);
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 26px 70px rgba(11, 16, 20, 0.30);
}

.btn:active {
    transform: translateY(0);
    box-shadow: 0 8px 18px rgba(11, 16, 20, 0.28);
}

.btn:focus-visible {
    outline: 2px solid var(--teal);
    outline-offset: 3px;
}

.btn.ghost {
    color: var(--text);
    background: transparent;
    border-color: rgba(247, 244, 238, 0.25);
    box-shadow: none;
}

.btn.ghost:hover {
    background: rgba(247, 244, 238, 0.08);
    border-color: rgba(247, 244, 238, 0.45);
}

.btn.ghost:active {
    background: rgba(247, 244, 238, 0.14);
}

/* Accent variant — teal CTA matching the nav accent for visual continuity */
.btn.accent {
    background: var(--teal);
    color: #0b1014;
    border-color: var(--teal);
    box-shadow: 0 14px 32px rgba(40, 198, 168, 0.28);
}

.btn.accent:hover {
    background: #2fd6b6;
    border-color: #2fd6b6;
    box-shadow: 0 20px 44px rgba(40, 198, 168, 0.40);
}

.btn.accent:active {
    box-shadow: 0 6px 14px rgba(40, 198, 168, 0.30);
}

/* ==========================================================================
   ANIMATION REVEAL WRAPPERS & FOOTER
   ========================================================================== */

.reveal {
    opacity: 0;
    transform: translateY(36px);
    transition: opacity 0.82s ease, transform 0.82s ease;
    transition-delay: var(--delay, 0ms);
}

.reveal.in-view {
    opacity: 1;
    transform: translateY(0);
}

section {
    padding: 105px 0;
    position: relative;
}

.section-dark {
    color: var(--text);
    background: var(--night);
    transition: background-color 0.4s ease, color 0.4s ease;
}

footer {
    color: rgba(247, 244, 238, 0.68);
    background: var(--ink);
    border-top: 1px solid rgba(247, 244, 238, 0.10);
    padding: 28px 0;
    font-size: 0.88rem;
    transition: background-color 0.4s ease, border-color 0.4s ease;
}

html[data-theme="dark"] footer {
    background: var(--night);
    border-top: 1px solid rgba(247, 244, 238, 0.06);
}

.footer-row {
    display: flex;
    justify-content: space-between;
    gap: 18px;
}

.footer-row a:hover {
    color: var(--text);
}

/* ==========================================================================
   REDUCED MOTION PREFERENCES
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }

    .reveal {
        opacity: 1;
        transform: none;
    }
}
