:root {
    --mc-bg: #f1f5f9;
    --mc-surface: #ffffff;
    --mc-border: #e2e8f0;
    --mc-text: #0f172a;
    --mc-muted: #64748b;
    --mc-primary: #dc2626;
    --mc-primary-dark: #b91c1c;
    --mc-ring: rgba(220, 38, 38, 0.2);
    --mc-shadow-sm: 0 8px 20px rgba(2, 8, 23, 0.06);
    --mc-shadow-md: 0 18px 36px rgba(2, 8, 23, 0.12);
    --mc-mesh-1: rgba(220, 38, 38, 0.055);
    --mc-mesh-2: rgba(14, 165, 233, 0.04);
    --mc-mesh-3: rgba(249, 115, 22, 0.045);
}

.mc-card {
    background: linear-gradient(165deg, #ffffff 0%, #fafbfc 55%, #f8fafc 100%);
    border: 1px solid rgba(226, 232, 240, 0.85);
    border-radius: 18px;
    box-shadow:
        0 1px 0 rgba(255, 255, 255, 0.8) inset,
        0 4px 24px -6px rgba(15, 23, 42, 0.07);
}

.mc-card-hover {
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1),
        box-shadow 0.28s ease,
        border-color 0.28s ease;
}

.mc-card-hover:hover {
    transform: translateY(-3px);
    box-shadow:
        0 1px 0 rgba(255, 255, 255, 0.9) inset,
        0 20px 40px -12px rgba(15, 23, 42, 0.12);
    border-color: rgba(252, 165, 165, 0.65);
}

/* Shared vehicle listing cards (optional hook) */
.mc-vehicle-card-shell {
    border-radius: 1rem;
    border: 1px solid rgba(226, 232, 240, 0.9);
    background: #fff;
    box-shadow: 0 4px 24px -4px rgba(15, 23, 42, 0.07);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
        box-shadow 0.3s ease,
        border-color 0.3s ease;
}

.mc-vehicle-card-shell:hover {
    transform: translateY(-4px);
    box-shadow: 0 24px 48px -16px rgba(15, 23, 42, 0.14);
    border-color: rgba(254, 202, 202, 0.9);
}

/* Listing card — spec pills (shared across home strips, grid, similar cars) */
.mc-vc-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    max-width: 100%;
    border-radius: 9999px;
    padding: 0.2rem 0.55rem;
    font-size: 0.75rem;
    line-height: 1.25rem;
    font-weight: 500;
    color: rgb(71 85 105);
    background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
    border: 1px solid rgba(226, 232, 240, 0.95);
    box-shadow:
        0 1px 0 rgba(255, 255, 255, 0.9) inset,
        0 1px 2px rgba(15, 23, 42, 0.04);
}

.mc-vc-pill ion-icon {
    flex-shrink: 0;
}

/* Fixed-height meta row: scroll instead of clipping extra tags */
.mc-vehicle-card-chips {
    align-content: flex-start;
    scrollbar-width: thin;
    scrollbar-color: rgba(148, 163, 184, 0.5) transparent;
}

.mc-vehicle-card-chips::-webkit-scrollbar {
    width: 5px;
}

.mc-vehicle-card-chips::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.45);
    border-radius: 9999px;
}

.mc-glass {
    background: linear-gradient(135deg, rgba(255,255,255,0.82), rgba(255,255,255,0.72));
    backdrop-filter: blur(14px) saturate(140%);
    -webkit-backdrop-filter: blur(14px) saturate(140%);
    border: 1px solid rgba(255, 255, 255, 0.6);
}

.mc-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    border-radius: 9999px;
    font-weight: 600;
    transition: all .2s ease;
    text-decoration: none;
    box-sizing: border-box;
}

.mc-btn-primary {
    background: linear-gradient(135deg, var(--mc-primary) 0%, var(--mc-primary-dark) 100%);
    color: #fff;
    box-shadow: 0 12px 24px rgba(220, 38, 38, 0.25);
}

.mc-btn-primary:hover {
    filter: brightness(1.05);
    transform: translateY(-1px);
}

.mc-btn-primary:active {
    transform: translateY(0);
}

.mc-btn-ghost {
    color: #334155;
    border: 1px solid var(--mc-border);
    background: #fff;
}

.mc-btn-ghost:hover {
    color: var(--mc-primary);
    border-color: #fecaca;
    background: #fff5f5;
}

.mc-input {
    border: 1px solid #cbd5e1;
    border-radius: 12px;
    background: linear-gradient(180deg, #ffffff 0%, #fbfdff 100%);
    transition: border-color .2s ease, box-shadow .2s ease;
}

.mc-input:focus {
    border-color: var(--mc-primary);
    box-shadow: 0 0 0 4px var(--mc-ring);
    outline: none;
}

.mc-select,
.mc-textarea {
    border: 1px solid #cbd5e1;
    border-radius: 12px;
    background: linear-gradient(180deg, #ffffff 0%, #fbfdff 100%);
    transition: border-color .2s ease, box-shadow .2s ease;
}

.mc-select:focus,
.mc-textarea:focus {
    border-color: var(--mc-primary);
    box-shadow: 0 0 0 4px var(--mc-ring);
    outline: none;
}

/* —— App shell: sleek page background (all public pages) —— */
body.mc-app {
    min-height: 100vh;
    color: var(--mc-text);
    /* Flat gradient only — background-attachment:fixed forces a full repaint on every scroll frame */
    background: linear-gradient(168deg, #f8fafc 0%, #f1f5f9 42%, #eef2f7 100%);
}

html {
    scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }
}

/* Scrollbars (Firefox + WebKit) */
body.mc-app,
body.mc-app * {
    scrollbar-width: thin;
    scrollbar-color: rgba(220, 38, 38, 0.35) rgba(241, 245, 249, 0.8);
}

body.mc-app::-webkit-scrollbar,
body.mc-app *::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

body.mc-app::-webkit-scrollbar-track,
body.mc-app *::-webkit-scrollbar-track {
    background: rgba(241, 245, 249, 0.6);
    border-radius: 8px;
}

body.mc-app::-webkit-scrollbar-thumb,
body.mc-app *::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, rgba(220, 38, 38, 0.45), rgba(185, 28, 28, 0.5));
    border-radius: 8px;
}

body.mc-app::-webkit-scrollbar-thumb:hover,
body.mc-app *::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, rgba(220, 38, 38, 0.65), rgba(185, 28, 28, 0.7));
}

/* Stronger than `body.mc-app *` above so horizontal strips can truly hide scrollbars */
body.mc-app .scrollbar-hide {
    -ms-overflow-style: none;
    scrollbar-width: none;
    scrollbar-color: transparent transparent;
}

body.mc-app .scrollbar-hide::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
}

/* Glass auth / settings panels */
.mc-panel {
    width: 100%;
    border-radius: 1.25rem;
    background: linear-gradient(165deg, rgba(255, 255, 255, 0.94) 0%, rgba(248, 250, 252, 0.98) 100%);
    backdrop-filter: blur(18px) saturate(160%);
    -webkit-backdrop-filter: blur(18px) saturate(160%);
    border: 1px solid rgba(255, 255, 255, 0.9);
    box-shadow:
        0 1px 0 rgba(255, 255, 255, 0.95) inset,
        0 28px 56px -20px rgba(15, 23, 42, 0.14),
        0 0 0 1px rgba(15, 23, 42, 0.04);
}

/* Section surfaces (homepage modules) */
.mc-surface {
    border-radius: 1.25rem;
    background: linear-gradient(165deg, rgba(255, 255, 255, 0.88) 0%, rgba(255, 255, 255, 0.72) 100%);
    border: 1px solid rgba(226, 232, 240, 0.95);
    box-shadow:
        0 1px 0 rgba(255, 255, 255, 0.85) inset,
        0 12px 32px -12px rgba(15, 23, 42, 0.08);
    backdrop-filter: blur(12px) saturate(140%);
    -webkit-backdrop-filter: blur(12px) saturate(140%);
}

.mc-surface-muted {
    border-radius: 1rem;
    background: linear-gradient(180deg, rgba(248, 250, 252, 0.95) 0%, rgba(241, 245, 249, 0.85) 100%);
    border: 1px solid rgba(226, 232, 240, 0.9);
}

/* Dropdowns / typeahead panels */
.mc-popover {
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.98) 0%, rgba(248, 250, 252, 0.96) 100%);
    border: 1px solid rgba(226, 232, 240, 0.95);
    border-radius: 0.875rem;
    box-shadow:
        0 24px 48px -12px rgba(15, 23, 42, 0.14),
        0 0 0 1px rgba(15, 23, 42, 0.03);
    backdrop-filter: blur(16px) saturate(150%);
    -webkit-backdrop-filter: blur(16px) saturate(150%);
}

/* Navbar strip — solid-ish bar without backdrop-filter (blur under fixed nav makes vertical scroll janky on many GPUs) */
.mc-navbar {
    background: rgba(255, 255, 255, 0.94);
    border-bottom-color: rgba(226, 232, 240, 0.85);
    box-shadow: 0 4px 24px -8px rgba(15, 23, 42, 0.07);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}

/* Footer */
.mc-footer {
    background: linear-gradient(180deg, rgba(248, 250, 252, 0.97) 0%, rgba(241, 245, 249, 0.99) 100%);
    border-top: 1px solid rgba(226, 232, 240, 0.9);
    box-shadow: 0 -12px 40px -16px rgba(15, 23, 42, 0.05);
}

.mc-footer a {
    transition: color 0.2s ease;
}

.mc-btn-secondary {
    background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
    color: #334155;
    border: 1px solid rgba(226, 232, 240, 0.95);
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.05);
}

.mc-btn-secondary:hover {
    border-color: #fecaca;
    color: var(--mc-primary);
    background: #fff;
}

.mc-badge {
    display: inline-flex;
    align-items: center;
    gap: .25rem;
    border-radius: 9999px;
    padding: .25rem .6rem;
    font-size: .75rem;
    font-weight: 700;
    letter-spacing: .01em;
}

.mc-badge-neutral {
    color: #334155;
    background: #f1f5f9;
}

.mc-badge-primary {
    color: #991b1b;
    background: #fee2e2;
}

/* Navbar: keep fixed bar light; avoid extra compositor hints — fixed positioning already promotes a layer */
.mc-navbar {
    will-change: auto;
}

/* Card hover lift: only transform — no box-shadow repaint during scroll */
.mc-vehicle-card-shell,
.mc-card-hover {
    will-change: auto; /* reset until hover */
}
.mc-vehicle-card-shell:hover,
.mc-card-hover:hover {
    will-change: transform;
}

/* Sleek shared polish */
* {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

::selection {
    background: rgba(220, 38, 38, 0.15);
}

/* Media loading states (cars/listings) */
.mc-img-wrap {
    position: relative;
    overflow: hidden;
    background: #e5e7eb;
}

/*
 * One thumbnail frame shape everywhere: home strips, listings grid, similar cars, default card.
 * We use aspect-ratio 16/10 because virtually all car photography (Unsplash, dealer galleries,
 * phone cameras in landscape) falls between 3:2 and 16:9. 16:10 sits in the middle, so
 * object-fit: cover crops a near-invisible amount while the frame is always 100% filled.
 */
.mc-vehicle-card-photo {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 10;
    flex-shrink: 0;
    background: #e5e7eb;
}

/* Fallback for very old browsers that don't support aspect-ratio */
@supports not (aspect-ratio: 1) {
    .mc-vehicle-card-photo {
        height: 12rem;
    }
}

/* Direct photo: always fill frame with centered cover (no empty space, no letterbox) */
.mc-vehicle-card-photo > img,
.mc-img-wrap img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center 45%; /* slight bias upward so car bodies sit centered, not wheels */
}

.mc-img-skeleton {
    position: absolute;
    inset: 0;
    background: linear-gradient(110deg, #eef2f7 8%, #f8fafc 18%, #eef2f7 33%);
    background-size: 220% 100%;
    animation: mc-shimmer 1.4s linear infinite;
    transition: opacity .25s ease;
    will-change: background-position;
}

/* Thumbnails stay visible while loading — do not use opacity:0 (breaks when .is-loaded is wrong). */
.mc-img-wrap img {
    transition: transform .5s ease;
    will-change: transform;
}

.mc-img-wrap.is-loaded .mc-img-skeleton {
    opacity: 0;
    pointer-events: none;
    animation: none; /* stop consuming GPU after image is loaded */
}

.mc-img-wrap.is-loaded img {
    will-change: transform; /* keep only transform for hover scale */
}

@keyframes mc-shimmer {
    to { background-position-x: -220%; }
}

/* Focus visibility for keyboard users */
:focus-visible {
    outline: 2px solid var(--mc-primary);
    outline-offset: 2px;
}

.mc-btn:focus-visible,
.mc-input:focus-visible,
.mc-select:focus-visible,
.mc-textarea:focus-visible {
    outline: 2px solid var(--mc-primary);
    outline-offset: 2px;
}

/*
 * ===========================================================================
 * MOBILE SCROLL PERFORMANCE
 * ===========================================================================
 * Two things wreck mobile scroll:
 *   1. backdrop-filter on large panels — the GPU must re-rasterize the
 *      blurred region every frame, pegging the compositor and producing the
 *      classic "freeze then catch up" behavior when the user scrolls up.
 *   2. Long-running linear-infinite animations (shimmer skeletons, brand
 *      marquee) — they keep paint threads busy even when offscreen.
 *
 * We disable/tone these down on touch/small viewports. Desktop is unaffected.
 */
@media (max-width: 1024px), (hover: none) and (pointer: coarse) {
    .mc-surface,
    .mc-panel,
    .mc-popover,
    .mc-glass {
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
    }

    /* Replace translucent panel fills with solid ones so removing blur still looks clean */
    .mc-surface {
        background: #ffffff;
    }
    .mc-panel {
        background: #ffffff;
    }
    .mc-popover {
        background: #ffffff;
    }
    .mc-glass {
        background: rgba(255, 255, 255, 0.96);
    }

    /* Let the browser skip paint/layout for offscreen home page sections. */
    .homepage-bg > * {
        content-visibility: auto;
        contain-intrinsic-size: 1px 800px;
    }

    /* Kill "infinite" linear paints when the user isn't looking at them. */
    .mc-img-wrap.is-loaded .mc-img-skeleton { animation: none; }

    /* Offscreen horizontal car strips don't need to paint their (often
     * dozen+) cards while the user is above them. content-visibility lets
     * the browser skip layout/paint for the strip until it's near the
     * viewport. Reserve vertical space so scrollbar position doesn't jump. */
    .mc-home-car-strip {
        content-visibility: auto;
        contain-intrinsic-size: 1px 420px;
    }

    /* Brand marquee: on mobile, pause whenever offscreen AND don't force a layer-per-frame. */
    .animate-scroll {
        animation-duration: 45s; /* slower = fewer composited frames per second */
    }
}

/* Respect reduced motion — stop all continuous animations */
@media (prefers-reduced-motion: reduce) {
    .mc-img-skeleton,
    .animate-scroll {
        animation: none !important;
    }
}

/*
 * scroll-behavior: smooth on <html> conflicts with momentum scrolling on iOS
 * Safari — tapping the top of the screen or scrolling up with a fling can
 * produce a noticeable stutter while the browser interpolates. Leave smooth
 * scroll to explicit scrollTo() calls (dots, anchors) instead of every scroll.
 */
@media (hover: none) and (pointer: coarse) {
    html { scroll-behavior: auto; }
}
