/* Prevent FOUC: Hide core layout containers by default until fully loaded */
body:not(.loaded) header,
body:not(.loaded) main,
body:not(.loaded) footer,
body:not(.loaded) .mobile-bottom-nav {
    display: none !important;
}

/* Prevent FOUC on modals */
.modal, .tracking-modal {
    display: none !important;
}
.modal.active, .tracking-modal.active {
    display: flex !important;
}

/* Mobile Preloader Overlay */
.app-preloader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #ffffff;
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.4s ease, visibility 0.4s ease;
}
.preloader-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 24px;
    background: #ffffff;
    padding: 40px 0;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    position: relative;
    z-index: 2;
}
.preloader-logo {
    height: 2.8rem;
    width: auto;
    object-fit: contain;
    opacity: 0.95;
    display: block;
}
.logo-wrapper {
    position: relative;
    overflow: hidden;
    display: inline-block;
    border-radius: 12px;
    padding: 6px 12px;
    animation: logo-float 2.5s ease-in-out infinite;
    filter: drop-shadow(0 8px 16px rgba(99, 102, 241, 0.12));
    will-change: transform;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}
.logo-wrapper::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        90deg,
        rgba(255, 255, 255, 0) 0%,
        rgba(255, 255, 255, 0.6) 50%,
        rgba(255, 255, 255, 0) 100%
    );
    transform: translateX(-150%) skewX(-20deg);
    animation: logo-shine 3s infinite ease-in-out;
    will-change: transform;
}
.drive-track-wrapper {
    position: relative;
    width: 100%;
    max-width: 100vw;
    height: 100px;
    overflow: hidden;
    margin: 0 auto 15px auto;
    z-index: 2;
}
.road-stitch-line {
    display: none !important;
}
.motorcycle-node {
    position: absolute;
    bottom: 5px;
    width: 110px;
    height: 85px;
    transform-origin: bottom center;
    will-change: left, transform;
    animation: l2r-linear 2.8s linear infinite;
}
.bike-bounce {
    animation: accel-vibe 0.08s linear infinite;
}
.front-wheel {
    transform-origin: 85px 70px;
    animation: moto-wheel-spin 0.35s linear infinite;
}
.back-wheel {
    transform-origin: 25px 70px;
    animation: moto-wheel-spin 0.35s linear infinite;
}
.ribbon-tape {
    position: absolute;
    right: 104px;
    top: 40px;
    width: 200px;
    height: 16px;
    background: repeating-linear-gradient(90deg, #d9232d, #d9232d 8px, #ffc107 8px, #ffc107 16px, #1b5ea8 16px, #1b5ea8 24px, #ffffff 24px, #ffffff 32px);
    opacity: 0.85;
    transform-origin: right center;
    transform: skewX(-15deg);
    animation: ribbon-wave-motion 0.15s linear infinite alternate;
    border-radius: 2px;
}

@keyframes l2r-linear {
    0% { left: -120px; }
    100% { left: 100%; }
}
@keyframes ribbon-wave-motion {
    0% { transform: skewX(-15deg) scaleY(0.9); }
    100% { transform: skewX(-15deg) scaleY(1.1) translateY(-2px); }
}
@keyframes accel-vibe {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-1.5px); }
}
@keyframes moto-wheel-spin {
    to { transform: rotate(360deg); }
}

/* Fullscreen Preloader Background Animations */
.fs-bg-wrapper {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
    overflow: hidden;
}
.sewing-grid-svg {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    opacity: 0.15;
}
.bg-stitch-line {
    stroke-dasharray: 15;
    stroke-dashoffset: 600;
    animation: draw-bg-stitch 30s linear infinite;
}
@keyframes draw-bg-stitch {
    to { stroke-dashoffset: 0; }
}
.floating-tool-svg {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
}
.bg-float-node {
    position: absolute;
    bottom: -80px;
    opacity: 0;
    z-index: 1;
}

/* 4 Unique organic drift pathways to prevent straight lines */
@keyframes drift-straight-left {
    0% { transform: translate(0, 0) rotate(0deg); opacity: 0; }
    10% { opacity: 0.48; }
    90% { opacity: 0.48; }
    100% { transform: translate(-60px, -115vh) rotate(270deg); opacity: 0; }
}

@keyframes drift-slanted {
    0% { transform: translate(0, 0) rotate(0deg); opacity: 0; }
    10% { opacity: 0.48; }
    90% { opacity: 0.48; }
    100% { transform: translate(80px, -115vh) rotate(360deg); opacity: 0; }
}

@keyframes drift-wavy {
    0% { transform: translate(0, 0) rotate(0deg); opacity: 0; }
    10% { opacity: 0.48; }
    33% { transform: translate(45px, -38vh) rotate(120deg); }
    66% { transform: translate(-35px, -76vh) rotate(240deg); }
    90% { opacity: 0.48; }
    100% { transform: translate(25px, -115vh) rotate(360deg); opacity: 0; }
}

@keyframes drift-spiral {
    0% { transform: translate(0, 0) rotate(0deg); opacity: 0; }
    10% { opacity: 0.48; }
    50% { transform: translate(-60px, -57vh) rotate(-180deg); }
    90% { opacity: 0.48; }
    100% { transform: translate(60px, -115vh) rotate(-360deg); opacity: 0; }
}
.svg-defs-hidden {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
}
@keyframes logo-float {
    0%, 100% {
        transform: translate3d(0, 0, 0) scale(1);
    }
    50% {
        transform: translate3d(0, -6px, 0) scale(1.02);
    }
}
@keyframes logo-shine {
    0% {
        transform: translateX(-150%) skewX(-20deg);
    }
    50%, 100% {
        transform: translateX(150%) skewX(-20deg);
    }
}

.preloader-tagline {
    font-family: 'DM Sans', sans-serif;
    font-size: 0.8rem;
    font-weight: 700;
    color: #6366f1;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    animation: text-pulse 1.8s infinite ease-in-out;
}
@keyframes text-pulse {
    0%, 100% {
        opacity: 0.5;
        letter-spacing: 0.08em;
    }
    50% {
        opacity: 1;
        letter-spacing: 0.12em;
    }
}

/* WebView Performance & Touch Tuning */
:root {
    --safe-area-inset-top: 0px;
    --safe-area-inset-bottom: 0px;
}

html.is-webview {
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
    overscroll-behavior-y: contain;
}

html.is-webview body {
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
    user-select: none;
}

html.is-webview input,
html.is-webview textarea {
    -webkit-user-select: text;
    user-select: text;
}

html.is-webview a,
html.is-webview button,
html.is-webview .mobile-bottom-nav-item,
html.is-webview .item-card {
    touch-action: manipulation;
}

/* Hardware acceleration on layout containers & animations */
.app-preloader, .modal, .tracking-modal, .mobile-bottom-nav {
    will-change: transform, opacity;
    transform: translate3d(0, 0, 0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}
