/* A sale on the App Store, shown only while it runs (MementoSale.swift). */

/* Atop the fixed header; the pages' top padding adds its height (--banner-height, measured by the banner's script,
   with this as the guess until it runs). */
:root {
    --banner-height: 60px;
    --sale-banner-bg: #17171d;
}

@media (prefers-color-scheme: light) {
    :root {
        --sale-banner-bg: #f4f2fb;
    }
}

.sale-banner {
    position: relative;
    overflow: hidden;
    background: var(--sale-banner-bg);
    color: var(--color-text);
    border-bottom: 1px solid var(--color-border);
    text-align: center;
    padding: 10px var(--space-lg);
    font-size: 0.9375rem;
    line-height: 1.45;
}

/* The words sit on a soft patch of the banner's own colour, so the confetti drifts behind them without getting in
   the way of reading. */
.sale-banner p {
    position: relative;
    z-index: 1;
    padding: 0 10px;
    border-radius: 999px;
    background: radial-gradient(closest-side, var(--sale-banner-bg) 70%, transparent);
}

.sale-banner strong {
    font-weight: 700;
}

/* The discount in Memento's red (LightRed in the app, the site's accent). */
.sale-banner-words {
    font-weight: 700;
}

/* The dots between the sale, the discount and the end date, evenly spaced. */
.sale-dot {
    margin: 0 0.5em;
}

.sale-banner-off {
    font-size: 1.1em;
    font-weight: 900;
    letter-spacing: 0.02em;
    color: var(--color-accent);
}

/* The poppers either side of the words, in a row. */
.sale-banner p {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    column-gap: 14px;
    row-gap: 6px;
}

.sale-popper {
    display: inline-block;
    font-size: 1.75rem;
    line-height: 1;
    animation: sale-pop 2.4s ease-in-out infinite;
    transform-origin: 20% 80%;
}

/* Turned to face the other one. */
.sale-popper-trailing {
    transform-origin: 80% 80%;
    --flip: -1;
}

@keyframes sale-pop {
    0%, 70%, 100% { transform: scaleX(var(--flip, 1)) rotate(0deg); }
    78% { transform: scaleX(var(--flip, 1)) rotate(-14deg) scale(1.15); }
    88% { transform: scaleX(var(--flip, 1)) rotate(6deg); }
}

/* Confetti falling through the banner (pieces from MementoSaleTag.confetti). */
.sale-confetti {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.sale-confetti i {
    position: absolute;
    top: -10px;
    left: var(--x);
    width: var(--w);
    height: var(--h);
    background: var(--c);
    border-radius: 1px;
    transform: rotate(var(--r));
    animation: sale-fall var(--d) linear var(--t) infinite;
}

@keyframes sale-fall {
    from { transform: translate(0, 0) rotate(var(--r)); }
    50% { transform: translate(6px, calc(var(--fall, 70px) / 2)) rotate(calc(var(--r) + 180deg)); }
    to { transform: translate(-2px, var(--fall, 70px)) rotate(calc(var(--r) + 360deg)); }
}

/* Without motion: the confetti scattered still, the poppers at rest. */
@media (prefers-reduced-motion: reduce) {
    .sale-popper {
        animation: none;
        transform: scaleX(var(--flip, 1));
    }

    .sale-confetti i {
        animation: none;
        top: calc(10% + (var(--w) - 4px) * 18);
    }

    .sale-confetti-cta i {
        top: calc(5% + (var(--w) - 4px) * 60);
    }
}

/* Beside the hero's App Store badge. */
.sale-hero {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-sm);
    margin: 0 0 var(--space-md);
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-text);
}

.sale-hero-badge {
    padding: 4px 12px;
    border-radius: 999px;
    background: var(--color-accent);
    color: #fff;
    font-size: 0.875rem;
    font-weight: 800;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    white-space: nowrap;
}

/* Under the closing call to action's heading. */
/* The closing call to action, while the sale runs: a card of the banner's colour with confetti falling all the way
   down it, a "Black Friday sale" pill over the heading, the discount under it, and a bigger App Store badge. */
.cta:has(.sale-cta) {
    border-top: none;
    padding: var(--space-3xl) 0 var(--space-4xl);
}

.cta:has(.sale-cta) .container {
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    max-width: 880px;
    padding: var(--space-4xl) var(--space-xl);
    border: 1px solid var(--color-border);
    border-radius: 32px;
    background: var(--sale-banner-bg);
}

/* A soft wash of the card's colour behind the words, above the confetti, so it falls around them. */
.cta:has(.sale-cta) .container::after {
    content: "";
    position: absolute;
    inset: 18% 15%;
    background: radial-gradient(closest-side, var(--sale-banner-bg) 55%, transparent);
    pointer-events: none;
}

.cta:has(.sale-cta) .container > :not(.sale-confetti) {
    position: relative;
    z-index: 1;
}

.cta:has(.sale-cta) h2 {
    order: 1;
    max-width: 16em;
    margin-bottom: var(--space-md);
}

/* The icon heads the card, above the pill; the directory's badge closes it, under the App Store's. */
.cta:has(.sale-cta) .cta-icon {
    order: -1;
}

.cta:has(.sale-cta) .app-store-badge {
    order: 3;
}

.cta:has(.sale-cta) .directory-badge {
    order: 4;
}

.cta:has(.sale-cta) .app-store-badge img {
    height: 64px;
}

/* The card's confetti falls by `top`, which goes by the card's height, so it reaches the bottom however tall the
   card grows. */
@media (prefers-reduced-motion: no-preference) {
    .sale-confetti-cta i {
        animation-name: sale-fall-card;
        animation-duration: calc(var(--d) * 2.2);
    }
}

@keyframes sale-fall-card {
    from { top: -10px; transform: translateX(0) rotate(var(--r)); }
    50% { transform: translateX(6px) rotate(calc(var(--r) + 180deg)); }
    to { top: calc(100% + 10px); transform: translateX(-2px) rotate(calc(var(--r) + 360deg)); }
}

/* The second set of pieces starts half a fall later, so the card never runs empty. */
.sale-confetti-cta i:nth-child(n + 37) {
    animation-delay: calc(var(--t) * 2.2 - var(--d) * 1.1);
}

.sale-cta-eyebrow {
    order: 0;
    margin-bottom: var(--space-lg);
    padding: 6px 16px;
    border: 1px solid var(--color-border);
    border-radius: 999px;
    background: var(--color-bg);
    font-size: 0.9375rem;
    font-weight: 700;
}

.sale-cta {
    order: 2;
    margin-bottom: var(--space-xl);
    font-size: 1.25rem;
    color: var(--color-text-secondary);
}

.sale-cta strong {
    color: var(--color-accent);
    font-weight: 800;
}

@media (max-width: 768px) {
    .sale-banner-detail,
    .sale-popper-trailing {
        display: none;
    }

    .sale-hero {
        justify-content: center;
    }
}
