/**
 * RPS ATC Loader — Add to Cart button feedback ("Print Racer").
 *
 * On click the button enters .rps-atc-racing: a grounded cart with spinning
 * wheels races in over a scrolling dashed road (speed lines + a printed
 * business card in the basket), decelerates and lingers mid-button so it reads,
 * then accelerates out and loops — until the AJAX add resolves. On success the
 * button flips to .rps-atc-success: green wash + a springing "✓ Added!". The
 * button's own label is hidden (color:transparent) during both states; the
 * background turns green only on success. A CSS spinner (.rps-atc-loading)
 * covers the rare case the scene markup can't be injected.
 *
 * Geometry is center-anchored (top:50% + margin) so it tracks the cart on
 * buttons of any height. Honors prefers-reduced-motion: no travel/spin — the
 * cart parks centered and success still confirms.
 */

/* ---- button states ---- */
.single_add_to_cart_button.rps-atc-racing,
.single_add_to_cart_button.rps-atc-success {
    position: relative;
    overflow: hidden;
    isolation: isolate;
}
.single_add_to_cart_button.rps-atc-racing {
    pointer-events: none;
    color: transparent !important; /* hide label; keep brand background */
    cursor: wait !important;
}
.single_add_to_cart_button.rps-atc-success {
    pointer-events: none;
    color: transparent !important;
    background: var(--rps-atc-ok, #13b981) !important;
    border-color: var(--rps-atc-ok, #13b981) !important;
    transition: background 0.2s ease;
}

/* ---- scene container (injected by JS) ---- */
.rps-atc-scene {
    position: absolute;
    inset: 0;
    z-index: 2;
    display: none;
    pointer-events: none;
}
.single_add_to_cart_button.rps-atc-racing .rps-atc-scene {
    display: block;
}

/* grounded scrolling road, just below the wheels */
.rps-atc-groad {
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    margin-top: 12px;
    height: 2px;
    background-image: linear-gradient(to right, rgba(255, 255, 255, 0.85) 0 11px, transparent 11px 20px);
    background-size: 20px 2px;
    background-repeat: repeat-x;
    opacity: 0.9;
    animation: rps-atc-road 0.42s linear infinite;
}

/* the moving rig (cart + wheels + lines + shadow) */
.rps-atc-rig {
    position: absolute;
    top: 0;
    bottom: 0;
    left: -46px;
    width: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    will-change: left, transform;
    animation: rps-atc-drive 2.05s linear infinite;
}
.rps-atc-gcart {
    position: relative;
    width: 34px;
    height: 30px;
    color: #fff;
    transform-origin: 50% 90%;
    animation: rps-atc-lean 2.05s ease-in-out infinite;
}
.rps-atc-body {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    filter: drop-shadow(0 2px 2px rgba(0, 40, 70, 0.28));
}
.rps-atc-wheel {
    position: absolute;
    bottom: 1px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    border: 1.7px solid #fff;
    background: rgba(255, 255, 255, 0.12);
    box-shadow: 0 1px 2px rgba(0, 40, 70, 0.3);
}
.rps-atc-wheel::after {
    content: "";
    position: absolute;
    inset: 1px;
    border-top: 1.5px solid #fff;
    transform-origin: center;
}
.rps-atc-wheel--a { left: 6px; }
.rps-atc-wheel--b { right: 5px; }
.single_add_to_cart_button.rps-atc-racing .rps-atc-wheel::after {
    animation: rps-atc-spin 0.3s linear infinite;
}
.rps-atc-gshadow {
    position: absolute;
    top: 50%;
    margin-top: 10px;
    left: 50%;
    width: 26px;
    height: 5px;
    border-radius: 50%;
    background: radial-gradient(ellipse at center, rgba(0, 40, 70, 0.35), transparent 70%);
    transform: translateX(-50%);
    animation: rps-atc-shadow 0.4s ease-in-out infinite;
}

/* speed lines trailing the cart */
.rps-atc-lines {
    position: absolute;
    right: 30px;
    top: 50%;
    width: 22px;
    height: 14px;
    transform: translateY(-50%);
    animation: rps-atc-lines-fade 2.05s linear infinite;
}
.rps-atc-lines i {
    position: absolute;
    right: 0;
    height: 1.6px;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 2px;
    animation: rps-atc-streak 0.5s linear infinite;
}
.rps-atc-lines i:nth-child(1) { top: 2px; width: 16px; animation-delay: 0s; }
.rps-atc-lines i:nth-child(2) { top: 7px; width: 22px; animation-delay: 0.12s; }
.rps-atc-lines i:nth-child(3) { top: 12px; width: 13px; animation-delay: 0.06s; }

/* printed business card riding in the basket (on-brand for the test product) */
.rps-atc-pcard {
    position: absolute;
    left: 9px;
    top: 3px;
    width: 15px;
    height: 10px;
    border-radius: 1.5px;
    background: #fff;
    box-shadow: 0 1px 2px rgba(0, 40, 70, 0.35);
    overflow: hidden;
    animation: rps-atc-card-bob 0.5s ease-in-out infinite;
}
.rps-atc-pcard::before {
    content: "";
    position: absolute;
    left: 2px;
    top: 2px;
    width: 5px;
    height: 5px;
    border-radius: 1px;
    background: linear-gradient(135deg, var(--rps-atc-brand, #00b9ff), #7bd0ff);
}
.rps-atc-pcard::after {
    content: "";
    position: absolute;
    left: 8px;
    top: 2.5px;
    width: 5px;
    height: 1.4px;
    border-radius: 1px;
    background: #9aa7b4;
    box-shadow: 0 2.5px 0 #c3ccd5, 0 5px 0 #c3ccd5;
}

/* ---- success payoff ---- */
.rps-atc-payoff {
    position: absolute;
    inset: 0;
    z-index: 5;
    display: none;
    align-items: center;
    justify-content: center;
    gap: 9px;
    color: #fff;
    pointer-events: none;
    /* Paint the green here (not on the button) so it covers any theme button
       background without a specificity war. inherit keeps the button's radius. */
    background: var(--rps-atc-ok, #13b981);
    border-radius: inherit;
}
.single_add_to_cart_button.rps-atc-success .rps-atc-payoff {
    display: flex;
    animation: rps-atc-pop 0.42s cubic-bezier(0.34, 1.56, 0.5, 1) both;
}
.rps-atc-ok-mark {
    width: 22px;
    height: 22px;
    flex: none;
}
.rps-atc-ok-mark circle {
    opacity: 0;
    animation: rps-atc-ring 0.42s ease-out 0.02s both;
}
.rps-atc-ok-mark path {
    stroke: #fff;
    stroke-width: 2.6;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-dasharray: 26;
    stroke-dashoffset: 26;
    animation: rps-atc-tick 0.42s cubic-bezier(0.65, 0, 0.35, 1) 0.12s forwards;
}
.rps-atc-ok-text {
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0.6px;
    animation: rps-atc-ok-text 0.4s cubic-bezier(0.2, 0.7, 0.2, 1) 0.16s both;
}

/* ---- keyframes ---- */
@keyframes rps-atc-road { to { background-position: -20px 0; } }
@keyframes rps-atc-spin { to { transform: rotate(360deg); } }
@keyframes rps-atc-shadow {
    0%, 100% { width: 26px; opacity: 0.6; }
    50% { width: 21px; opacity: 0.4; }
}
@keyframes rps-atc-lean {
    0%, 100% { transform: rotate(0) translateY(0); }
    25% { transform: rotate(-3deg) translateY(-1px); }
    60% { transform: rotate(1.5deg); }
}
@keyframes rps-atc-card-bob {
    0%, 100% { transform: translateY(0) rotate(-2deg); }
    50% { transform: translateY(-1.5px) rotate(1deg); }
}
@keyframes rps-atc-streak {
    0% { opacity: 0; transform: translateX(6px) scaleX(0.6); }
    40% { opacity: 0.9; }
    100% { opacity: 0; transform: translateX(-10px) scaleX(1.2); }
}
@keyframes rps-atc-lines-fade {
    0%, 38% { opacity: 1; }
    52%, 100% { opacity: 0; }
}
/* slow-at-the-finish drive: burst in, decelerate, linger readable mid-button,
   then accelerate out and loop */
@keyframes rps-atc-drive {
    0% { left: -46px; animation-timing-function: cubic-bezier(0.1, 0.62, 0.28, 1); }
    42% { left: 58%; animation-timing-function: cubic-bezier(0.5, 0, 0.5, 1); }
    54% { left: 64%; animation-timing-function: linear; }
    80% { left: 72%; animation-timing-function: cubic-bezier(0.55, 0, 0.9, 0.35); }
    100% { left: calc(100% + 46px); }
}
@keyframes rps-atc-pop {
    from { transform: scale(0.82); }
    to { transform: scale(1); }
}
@keyframes rps-atc-ring {
    from { opacity: 0; transform: scale(0.4); transform-origin: center; }
    to { opacity: 0.35; transform: scale(1); }
}
@keyframes rps-atc-tick { to { stroke-dashoffset: 0; } }
@keyframes rps-atc-ok-text {
    from { opacity: 0; transform: translateY(7px); }
    to { opacity: 1; transform: none; }
}

/* ---- spinner fallback (scene injection failed) ---- */
.single_add_to_cart_button.rps-atc-loading {
    pointer-events: none;
    opacity: 0.85;
    cursor: wait !important;
}
.rps-atc-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: rps-atc-spin 0.7s linear infinite;
    vertical-align: middle;
    margin-right: 8px;
}
.rps-atc-loading-text { vertical-align: middle; }

/* ---- inline add-to-cart error (AJAX validation failures) ---- */
.rps-atc-error {
    margin: 0 0 14px;
}
.rps-atc-error:empty {
    display: none;
}

/* ---- reduced motion ---- */
@media (prefers-reduced-motion: reduce) {
    .single_add_to_cart_button.rps-atc-racing .rps-atc-rig {
        left: 50%;
        transform: translateX(-50%);
        animation: none;
    }
    .single_add_to_cart_button.rps-atc-racing .rps-atc-gcart,
    .single_add_to_cart_button.rps-atc-racing .rps-atc-wheel::after,
    .single_add_to_cart_button.rps-atc-racing .rps-atc-gshadow,
    .single_add_to_cart_button.rps-atc-racing .rps-atc-pcard {
        animation: none;
    }
    .single_add_to_cart_button.rps-atc-racing .rps-atc-groad {
        animation: none;
        opacity: 0.4;
    }
    .single_add_to_cart_button.rps-atc-racing .rps-atc-lines {
        display: none;
    }
    .single_add_to_cart_button.rps-atc-success .rps-atc-payoff,
    .rps-atc-ok-mark circle,
    .rps-atc-ok-mark path,
    .rps-atc-ok-text {
        animation: none;
    }
    .rps-atc-ok-mark path { stroke-dashoffset: 0; }
    .rps-atc-ok-mark circle { opacity: 0.35; }
}
