:root {
    --ux-font-min: 15px;
    --ux-font-max: 18px;
    --ux-leading: 1.55;
    --ux-radius: 18px;
    --ux-shadow: 0 10px 30px rgba(0, 0, 0, .10);
    --ux-shadow-soft: 0 8px 20px rgba(0, 0, 0, .08);
    --ux-border: 1px solid rgba(0, 0, 0, .08);
    --ux-border-dark: 1px solid rgba(255, 255, 255, .10);
    --ux-tap: 44px;
    --ux-safe-bottom: env(safe-area-inset-bottom, 0px);
    --ux-safe-top: env(safe-area-inset-top, 0px);
}

/* Fluid Typography */
html {
    font-size: clamp(var(--ux-font-min), 1.2vw + 0.6rem, var(--ux-font-max));
}

body {
    line-height: var(--ux-leading);
    -webkit-text-size-adjust: 100%;
    text-rendering: optimizeLegibility;
}

/* Safe Area Insets for iOS */
body {
    padding-bottom: var(--ux-safe-bottom);
}

/* Better tap targets for links and buttons */
a,
button,
.btn,
[role="button"] {
    min-height: var(--ux-tap);
    touch-action: manipulation;
}

button,
.btn {
    border-radius: var(--ux-radius);
}

/* Touch optimized cards */
.card,
.card-dark,
.why-card,
.feature-card,
.tutorial-card,
.grid-card {
    border-radius: var(--ux-radius);
    box-shadow: var(--ux-shadow-soft);
    border: var(--ux-border);
    transform: translateZ(0);
}

@media (hover: none) {

    .card:active,
    .card-dark:active,
    .why-card:active,
    .feature-card:active,
    .tutorial-card:active,
    .grid-card:active {
        transform: scale(.99);
        box-shadow: var(--ux-shadow);
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    body {
        background: #0b0d10;
        color: rgba(255, 255, 255, .92);
    }

    .card,
    .why-card,
    .feature-card,
    .tutorial-card,
    .grid-card {
        background: rgba(255, 255, 255, .04);
        border: var(--ux-border-dark);
    }

    .card-dark {
        background: rgba(255, 255, 255, .06);
        border: var(--ux-border-dark);
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
}

/* Menu stagger animation hooks */
.nav-open .nav-links a {
    opacity: 0;
    transform: translateY(6px);
    animation: ux-stagger .35s ease forwards;
}

.nav-open .nav-links a:nth-child(1) {
    animation-delay: .02s;
}

.nav-open .nav-links a:nth-child(2) {
    animation-delay: .05s;
}

.nav-open .nav-links a:nth-child(3) {
    animation-delay: .08s;
}

.nav-open .nav-links a:nth-child(4) {
    animation-delay: .11s;
}

.nav-open .nav-links a:nth-child(5) {
    animation-delay: .14s;
}

.nav-open .nav-links a:nth-child(6) {
    animation-delay: .17s;
}

.nav-open .nav-links a:nth-child(7) {
    animation-delay: .20s;
}

.nav-open .nav-links a:nth-child(8) {
    animation-delay: .23s;
}

.nav-open .nav-links a:nth-child(9) {
    animation-delay: .26s;
}

.nav-open .nav-links a:nth-child(10) {
    animation-delay: .29s;
}

@keyframes ux-stagger {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Scroll reveal base */
.ux-reveal {
    opacity: 0;
    transform: translateY(10px);
    transition: opacity .5s ease, transform .5s ease;
}

.ux-reveal.is-visible {
    opacity: 1;
    transform: translateY(0);
}

/* Scroll to top button */
#uxScrollTop {
    position: fixed;
    right: 16px;
    bottom: calc(16px + var(--ux-safe-bottom));
    width: 48px;
    height: 48px;
    border-radius: 999px;
    display: grid;
    place-items: center;
    z-index: 9999;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease, transform .2s ease;
    transform: translateY(8px);
    box-shadow: var(--ux-shadow);
}

#uxScrollTop.is-visible {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

/* Sticky Bottom CTA (mobile only) */
#uxBottomCTA {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(10px + var(--ux-safe-bottom));
    z-index: 9998;
    display: none;
    gap: 10px;
}

#uxBottomCTA a {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 48px;
    border-radius: 999px;
    text-decoration: none;
    font-weight: 700;
    box-shadow: var(--ux-shadow);
}

@media (max-width: 920px) {
    #uxBottomCTA {
        display: flex;
    }
}

/* Navbar auto hide helper */
.navbar.ux-hide {
    transform: translateY(-110%);
    transition: transform .25s ease;
}

.navbar.ux-show {
    transform: translateY(0);
    transition: transform .25s ease;
}

/* UX Controls: ensure visible defaults even if site styles don't define them */
#uxScrollTop {
    background: rgba(0, 0, 0, .72);
    color: #fff;
    border: 0;
}

#uxBottomCTA a {
    background: rgba(0, 0, 0, .82);
    color: #fff;
}

@media (prefers-color-scheme: dark) {
    #uxScrollTop {
        background: rgba(255, 255, 255, .14);
        color: rgba(255, 255, 255, .95);
    }

    #uxBottomCTA a {
        background: rgba(255, 255, 255, .16);
        color: rgba(255, 255, 255, .95);
    }
}

/* ============================================
   MOBILE FOOTER FIXES
   ============================================ */
@media (max-width: 768px) {
    .footer {
        padding: 3rem 0 2rem !important;
    }
    
    .footer .container {
        padding-left: 1.5rem;
        padding-right: 1.5rem;
    }
    
    /* Footer Grid - compact layout */
    .footer-grid {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 2rem 1.5rem !important;
        padding: 0;
    }
    
    /* Logo section - side by side layout */
    .footer-grid > div:first-child {
        grid-column: 1 / -1;
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: center;
        gap: 1.5rem;
        margin-bottom: 2rem;
        padding: 0 0.5rem;
    }
    
    .footer-logo {
        font-size: 1.5rem !important;
        line-height: 1.2 !important;
        text-align: left !important;
        font-weight: 500;
        flex-shrink: 0;
    }
    
    .footer-logo span {
        color: var(--color-gold, #b91c1c);
    }
    
    .footer-grid > div:first-child p {
        max-width: 200px !important;
        margin: 0 !important;
        font-size: 0.8rem !important;
        line-height: 1.4 !important;
        opacity: 0.7;
        text-align: left !important;
    }
    
    /* Navigation columns */
    .footer-grid > div:not(:first-child) {
        text-align: center;
    }
    
    .footer-grid h4 {
        font-size: 0.75rem !important;
        letter-spacing: 0.12em !important;
        margin-bottom: 1rem !important;
        opacity: 0.9;
        text-transform: uppercase;
        font-weight: 600;
    }
    
    .footer-grid ul {
        margin: 0;
        padding: 0;
        list-style: none;
    }
    
    .footer-grid ul li {
        margin-bottom: 0.6rem !important;
    }
    
    .footer-grid ul li a {
        font-size: 0.9rem !important;
        opacity: 0.85;
        text-decoration: none;
        transition: opacity 0.2s;
    }
    
    .footer-grid ul li a:hover {
        opacity: 1;
    }
    
    /* Sources section */
    .footer .container > div[style*="margin-top: 3rem"] {
        margin-top: 2rem !important;
        padding-top: 1.5rem !important;
        text-align: center;
    }
    
    .footer .container > div[style*="margin-top: 3rem"] h4 {
        font-size: 0.7rem !important;
        margin-bottom: 1rem !important;
        letter-spacing: 0.1em;
    }
    
    .footer .container > div[style*="margin-top: 3rem"] div[style*="display: flex"] {
        justify-content: center !important;
        gap: 0.75rem 1rem !important;
        font-size: 0.75rem !important;
    }
    
    /* Footer bottom - compact */
    .footer-bottom {
        flex-direction: column;
        text-align: center;
        gap: 0.4rem !important;
        margin-top: 1.25rem !important;
        padding-top: 1rem !important;
        font-size: 0.75rem !important;
    }
}

/* Extra small screens */
@media (max-width: 480px) {
    .footer-grid {
        gap: 1.25rem 1.5rem !important;
    }
    
    .footer-grid > div:not(:first-child) {
        text-align: center;
    }
    
    .footer-grid h4 {
        text-align: center;
    }
}