/* ==========================================================================
   Car Preloader (public website only)
   Markup : resources/views/components/car-preloader.blade.php
   Logic  : web/assets/js/car-preloader.js
   All selectors are prefixed "cpl" to avoid clashing with existing styles.
   Everything scales from --cpl-w (car width) so wheel speed and road speed
   stay in sync on every screen size.
   ========================================================================== */

.cpl {
    --cpl-w: clamp(230px, 54vw, 400px);           /* car width */
    --cpl-road-h: calc(var(--cpl-w) * .17);
    --cpl-period: calc(var(--cpl-w) * .375);      /* one road dash cycle */
    --cpl-speed: .7s;                             /* road cycle time; wheel turns in .76s -> no slipping */
    --cpl-city-tile: calc(var(--cpl-w) * 2.4);
    --cpl-post-tile: calc(var(--cpl-w) * 1.3);

    position: fixed;
    inset: 0;
    z-index: 2147483000;                          /* above modals, SweetAlert2, sidebars */
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: radial-gradient(120% 90% at 50% 38%, var(--cpl-bg1) 0%, var(--cpl-bg2) 100%);
    color: var(--cpl-ink);
    font-family: "Manrope", "Albert Sans", "Open Sans", system-ui, sans-serif;
    opacity: 1;
    visibility: visible;
    cursor: progress;
    -webkit-user-select: none;
    user-select: none;
    /* Pure-CSS safety net: if the script never runs, the overlay still goes away. */
    animation: cpl-failsafe .35s ease 12s forwards;
}

.cpl--web {
    --cpl-bg1: #ffffff;
    --cpl-bg2: #e6edf8;
    --cpl-ink: #111a3a;
    --cpl-muted: #6b7490;
    --cpl-primary: #243f88;
    --cpl-accent: #dd1e3c;
    --cpl-track: #d6ddec;
    --cpl-road: #1b2447;
    --cpl-road-edge: #2c3a6e;
    --cpl-lane: #ffffff;
    --cpl-city-op: .1;
    --cpl-post-op: .32;
    --cpl-body-1: #4a74dd;
    --cpl-body-2: #1a2f6c;
    --cpl-glass-1: #eaf2ff;
    --cpl-glass-2: #7d9fe0;
    --cpl-tire: #0d1226;
    --cpl-disc: #5a6286;
    --cpl-rim: #e6ecf8;
    --cpl-arch: #070b1c;
    --cpl-orb-1: rgba(36, 63, 136, .16);
    --cpl-orb-2: rgba(221, 30, 60, .11);
    --cpl-sweep: rgba(36, 63, 136, .07);
    --cpl-logo-shadow: rgba(17, 26, 58, .16);
}

/* ---- lifecycle states ---------------------------------------------------- */
.cpl--leaving { animation: cpl-fade-in .22s ease both; }        /* shown again on navigation */
.cpl--done {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    animation: none;
    transition: opacity .5s ease .08s, visibility 0s linear .6s;
}
.cpl--gone { display: none !important; }

html.cpl-lock, html.cpl-lock body { overflow: hidden !important; }

/* ---- ambient background -------------------------------------------------- */
.cpl-bg { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.cpl-orb {
    position: absolute;
    width: 60vmax; height: 60vmax;
    border-radius: 50%;
    will-change: transform;
}
.cpl-orb--1 { left: -22vmax; top: -26vmax; background: radial-gradient(closest-side, var(--cpl-orb-1), transparent); animation: cpl-drift 9s ease-in-out infinite alternate; }
.cpl-orb--2 { right: -24vmax; bottom: -28vmax; background: radial-gradient(closest-side, var(--cpl-orb-2), transparent); animation: cpl-drift 11s ease-in-out infinite alternate-reverse; }
.cpl-sweep {
    position: absolute;
    top: -10%; bottom: -10%;
    width: 18vw;
    left: -30vw;
    background: linear-gradient(90deg, transparent, var(--cpl-sweep), transparent);
    transform: skewX(-18deg);
    animation: cpl-sweep 5.5s linear infinite;
    will-change: transform;
}
.cpl-sweep--2 { width: 9vw; animation-duration: 7.5s; animation-delay: 2.2s; }

/* ---- layout -------------------------------------------------------------- */
.cpl-inner {
    position: relative;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0 16px;
    box-sizing: border-box;
}

/* ---- logo ---------------------------------------------------------------- */
.cpl-logo {
    position: relative;
    height: clamp(46px, 9vh, 70px);               /* fixed box => no layout shift while the image loads */
    margin: 0 0 clamp(6px, 1.6vh, 16px);
    animation: cpl-logo-in .9s cubic-bezier(.16, .8, .25, 1) .05s both;
}
.cpl-logo img {
    display: block;
    height: 100%;
    width: auto;                                  /* original aspect ratio */
    max-width: min(72vw, 300px);
    object-fit: contain;
    filter: drop-shadow(0 6px 14px var(--cpl-logo-shadow));
}
.cpl-logo::after {                                /* light sweep that only touches the logo's own pixels */
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(105deg, transparent 35%, rgba(255, 255, 255, .95) 50%, transparent 65%) no-repeat;
    background-size: 250% 100%;
    background-position: 160% 0;
    -webkit-mask: var(--cpl-logo-url) center / contain no-repeat;
    mask: var(--cpl-logo-url) center / contain no-repeat;
    animation: cpl-logo-shine 2.8s ease-in-out 1.1s infinite;
    mix-blend-mode: soft-light;
    pointer-events: none;
}

/* ---- scene: skyline + lamp posts + road + car --------------------------- */
.cpl-scene {
    position: relative;
    width: 100%;
    height: calc(var(--cpl-w) * .57);
    overflow: hidden;
    -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 12%, #000 88%, transparent 100%);
    mask-image: linear-gradient(90deg, transparent 0, #000 12%, #000 88%, transparent 100%);
    animation: cpl-fade-in .6s ease .1s both;
}

.cpl-layer {
    position: absolute;
    left: 0;
    bottom: var(--cpl-road-h);
    background-repeat: repeat-x;
    background-position: 0 100%;
    will-change: transform;
}
.cpl-city {
    width: calc(100% + var(--cpl-city-tile));
    height: calc(var(--cpl-w) * .2);
    opacity: var(--cpl-city-op);
    background-size: var(--cpl-city-tile) 100%;
    animation: cpl-city 22s linear infinite;
}
.cpl-posts {                                      /* nearer than the skyline => moves faster */
    width: calc(100% + var(--cpl-post-tile));
    height: calc(var(--cpl-w) * .27);
    opacity: var(--cpl-post-op);
    background-size: var(--cpl-post-tile) 100%;
    animation: cpl-posts 3.1s linear infinite;
}
.cpl--web .cpl-city { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 528 60' preserveAspectRatio='none'%3E%3Cpath fill='%23243f88' d='M0 60V30h30V20h26v14h18V8h34v26h22v14h30V28h24V14h40v24h26V22h32v20h28V10h38v30h24V26h30v16h36V18h34v22h26V30V60z'/%3E%3C/svg%3E"); }
.cpl--web .cpl-posts { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 130 60' preserveAspectRatio='none'%3E%3Cpath d='M30 60V12Q30 6 38 6H46' fill='none' stroke='%23243f88' stroke-width='1.6' stroke-linecap='round'/%3E%3Ccircle cx='47' cy='7.5' r='2.4' fill='%23dd1e3c'/%3E%3Cpath d='M42 9L52 9L58 46L36 46Z' fill='%23dd1e3c' opacity='.12'/%3E%3C/svg%3E"); }

.cpl-road {
    position: absolute;
    left: 0; right: 0; bottom: 0;
    height: var(--cpl-road-h);
    background: linear-gradient(180deg, var(--cpl-road-edge) 0, var(--cpl-road) 16%, var(--cpl-road) 100%);
    overflow: hidden;
}
.cpl-road::before {                               /* kerb line on the far edge */
    content: "";
    position: absolute;
    left: 0; right: 0; top: 0;
    height: 2px;
    background: var(--cpl-accent);
    opacity: .9;
    box-shadow: 0 0 10px var(--cpl-accent);
}
.cpl-road::after {                                /* asphalt sheen under the car */
    content: "";
    position: absolute;
    left: 50%; top: 18%;
    width: 70%; height: 40%;
    transform: translateX(-50%);
    background: radial-gradient(closest-side, rgba(255, 255, 255, .09), transparent);
}
.cpl-lane {
    position: absolute;
    left: 0;
    bottom: calc(var(--cpl-road-h) * .13);
    width: calc(100% + var(--cpl-period));
    height: max(3px, calc(var(--cpl-road-h) * .07));
    background: repeating-linear-gradient(90deg,
        var(--cpl-lane) 0, var(--cpl-lane) calc(var(--cpl-period) * .47),
        transparent calc(var(--cpl-period) * .47), transparent var(--cpl-period));
    border-radius: 2px;
    opacity: .92;
    animation: cpl-lane var(--cpl-speed) linear infinite;
    will-change: transform;
}
.cpl-lane--far {                                  /* fainter second line = depth */
    bottom: auto;
    top: calc(var(--cpl-road-h) * .26);
    height: 2px;
    opacity: .26;
    animation-duration: calc(var(--cpl-speed) * 1.3);
}

/* ---- the car ------------------------------------------------------------- */
.cpl-car {
    position: absolute;
    left: calc(50% - var(--cpl-w) / 2);
    bottom: calc(var(--cpl-w) * .01);
    width: var(--cpl-w);
    height: calc(var(--cpl-w) * .4);
    animation: cpl-enter 1.1s cubic-bezier(.16, .8, .25, 1) both;
    will-change: transform;
}
.cpl-cruise {                                     /* static wrapper (kept for markup compatibility) */
    width: 100%; height: 100%;
    /* no side-to-side drift: the car stays centred, the road/scenery scroll past it */
}
.cpl-svg { display: block; width: 100%; height: 100%; overflow: visible; }

.cpl-body { animation: cpl-bob .62s ease-in-out infinite; transform-box: fill-box; transform-origin: 50% 100%; }
.cpl-susp { animation: cpl-hop .62s ease-in-out infinite; }
.cpl-susp--b { animation-delay: -.18s; }
.cpl-wheel { animation: cpl-spin .76s linear infinite; transform-box: fill-box; transform-origin: 50% 50%; }
.cpl-beam { animation: cpl-beam 1.8s ease-in-out infinite; }
.cpl-streak { animation: cpl-streak 1s linear infinite; opacity: 0; }
.cpl-streak--2 { animation-delay: .25s; animation-duration: 1.15s; }
.cpl-streak--3 { animation-delay: .5s;  animation-duration: .9s; }
.cpl-streak--4 { animation-delay: .75s; animation-duration: 1.05s; }
.cpl-dust { animation: cpl-dust 1.1s ease-out infinite; opacity: 0; transform-box: fill-box; transform-origin: 50% 50%; }
.cpl-dust--2 { animation-delay: .37s; }
.cpl-dust--3 { animation-delay: .74s; }
.cpl-shadow { animation: cpl-shadow .62s ease-in-out infinite; transform-box: fill-box; transform-origin: 50% 50%; }
.cpl-tail { animation: cpl-tail 1.4s ease-in-out infinite; }

/* the car drives off to the right as the page is revealed */
.cpl--done .cpl-car { animation: cpl-exit .6s cubic-bezier(.55, 0, .9, .5) both; }
.cpl--done .cpl-cruise { animation: none; }

/* ---- progress + message -------------------------------------------------- */
.cpl-status {
    width: min(78vw, 300px);
    margin-top: clamp(14px, 3vh, 26px);
    animation: cpl-rise .6s ease .35s both;
}
.cpl-track {
    position: relative;
    height: 5px;
    border-radius: 5px;
    background: var(--cpl-track);
    overflow: hidden;
}
.cpl-fill {
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--cpl-primary), var(--cpl-accent));
    transform: scaleX(.04);
    transform-origin: 0 50%;
    transition: transform .3s ease-out;
}
.cpl-fill::after {                                /* soft sheen sweeping along the bar */
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .6), transparent);
    transform: translateX(-100%);
    animation: cpl-sheen 1.3s ease-in-out infinite;
}
.cpl-meta {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-top: 12px;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: .02em;
    color: var(--cpl-ink);
}
.cpl-msg { opacity: .92; }
.cpl-dots span { animation: cpl-dot 1.2s infinite both; }
.cpl-dots span:nth-child(2) { animation-delay: .2s; }
.cpl-dots span:nth-child(3) { animation-delay: .4s; }
.cpl-pct { font-variant-numeric: tabular-nums; color: var(--cpl-muted); font-weight: 700; }

.cpl-sr {
    position: absolute !important;
    width: 1px; height: 1px;
    margin: -1px; padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ---- keyframes ----------------------------------------------------------- */
@keyframes cpl-lane   { to { transform: translateX(calc(var(--cpl-period) * -1)); } }
@keyframes cpl-city   { to { transform: translateX(calc(var(--cpl-city-tile) * -1)); } }
@keyframes cpl-posts  { to { transform: translateX(calc(var(--cpl-post-tile) * -1)); } }
@keyframes cpl-spin   { to { transform: rotate(360deg); } }
@keyframes cpl-bob {
    0%, 100% { transform: translateY(0) rotate(0); }
    28%      { transform: translateY(-1.6px) rotate(-.22deg); }
    62%      { transform: translateY(.7px) rotate(.18deg); }
}
@keyframes cpl-hop {
    0%, 100% { transform: translateY(0); }
    30%      { transform: translateY(.9px); }
    65%      { transform: translateY(-.6px); }
}
@keyframes cpl-shadow {
    0%, 100% { transform: scaleX(1);   opacity: .6; }
    35%      { transform: scaleX(.96); opacity: .48; }
}
@keyframes cpl-enter {
    from { transform: translate3d(calc(-50vw - 100%), 0, 0); }
    to   { transform: translate3d(0, 0, 0); }
}
@keyframes cpl-exit {
    0%   { transform: translate3d(0, 0, 0); }
    18%  { transform: translate3d(-4%, 0, 0) rotate(-.6deg); }  /* tiny squat before launch */
    100% { transform: translate3d(calc(50vw + 110%), 0, 0); }
}
@keyframes cpl-beam   { 0%, 100% { opacity: .78; } 50% { opacity: 1; } }
@keyframes cpl-tail   { 0%, 100% { opacity: .6; } 50% { opacity: 1; } }
@keyframes cpl-streak {
    0%   { transform: translateX(0);     opacity: 0; }
    15%  { opacity: .6; }
    100% { transform: translateX(-90px); opacity: 0; }
}
@keyframes cpl-dust {
    0%   { transform: translate(0, 0) scale(.5);         opacity: 0; }
    20%  { opacity: .4; }
    100% { transform: translate(-46px, -9px) scale(2.2); opacity: 0; }
}
@keyframes cpl-drift  { to { transform: translate3d(6vmax, 5vmax, 0) scale(1.08); } }
@keyframes cpl-sweep  { to { transform: translateX(160vw) skewX(-18deg); } }
@keyframes cpl-logo-in {
    from { opacity: 0; transform: translateY(16px) scale(.94); }
    to   { opacity: 1; transform: none; }
}
@keyframes cpl-logo-shine { 0% { background-position: 160% 0; } 55%, 100% { background-position: -60% 0; } }
@keyframes cpl-sheen  { to { transform: translateX(100%); } }
@keyframes cpl-dot    { 0%, 80%, 100% { opacity: .2; } 40% { opacity: 1; } }
@keyframes cpl-rise   { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes cpl-fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes cpl-failsafe { to { opacity: 0; visibility: hidden; pointer-events: none; } }

/* ---- small screens ------------------------------------------------------- */
@media (max-width: 480px) {
    .cpl-meta { font-size: 12px; }
    .cpl-sweep--2 { display: none; }
}
@media (max-height: 460px) {
    .cpl-logo { height: 38px; }
    .cpl-status { margin-top: 10px; }
}

/* ---- reduced motion: keep a calm, static composition -------------------- */
@media (prefers-reduced-motion: reduce) {
    .cpl-car, .cpl-cruise, .cpl-body, .cpl-susp, .cpl-wheel, .cpl-lane, .cpl-city, .cpl-posts,
    .cpl-beam, .cpl-tail, .cpl-streak, .cpl-dust, .cpl-shadow, .cpl-orb, .cpl-sweep, .cpl-logo,
    .cpl-scene, .cpl-fill::after, .cpl-dots span, .cpl-status,
    .cpl--done .cpl-car { animation: none !important; }
    .cpl-streak, .cpl-dust, .cpl-sweep, .cpl-logo::after { display: none; }
    .cpl-dots span { opacity: 1; }
    .cpl-fill { transition: none; }
    .cpl--done { transition-duration: .2s, 0s; transition-delay: 0s, .2s; }
}
