/* ═══════════════════════════════════════════════════════════════
   Product banner: a looping motion card, shared by every product.
   Icon tile → headline word by word → back, over a halftone field,
   with the brand mark on top, a caption below and a progress line.
   Halloween adds a corner cobweb and a bat crossing at each change.
   Colours: .mb--{pumpkin|hex|slime|blood|frost|ice}, picked on the
   product page (python/product_banner.py). Markup: shared/_product_banner.html
   Everything moves with transform/opacity only.
   ═══════════════════════════════════════════════════════════════ */

.mb {
    --loop: 8s;
    --ease: cubic-bezier(.23, 1, .32, 1);
    --acc: #ff8a3d; --acc-rgb: 255, 138, 61; --hi: #ffc58f;
    --bg-a: #140b10; --bg-b: #1f0f0d;
    position: relative;
    display: block;
    width: 100%;
    height: 100%;
    overflow: hidden;
    container-type: inline-size;
    color: #f6f3ff;
    background:
        radial-gradient(55% 65% at 50% 46%, rgba(var(--acc-rgb), .13), transparent 72%),
        linear-gradient(180deg, var(--bg-a), var(--bg-b));
    user-select: none;
}
.mb--pink  { --acc: #e879ff; --acc-rgb: 232, 121, 255; --hi: #f6c8ff; --bg-a: #120a17; --bg-b: #200f2a; }
.mb--hex   { --acc: #b17cff; --acc-rgb: 177, 124, 255; --hi: #dcc4ff; --bg-a: #0f0a1a; --bg-b: #1a0f2e; }
.mb--slime { --acc: #8ee05a; --acc-rgb: 142, 224, 90;  --hi: #cdf7ae; --bg-a: #08110c; --bg-b: #0e1d14; }
.mb--blood { --acc: #ff4d5e; --acc-rgb: 255, 77, 94;   --hi: #ffa3ab; --bg-a: #14080b; --bg-b: #230b11; }
.mb--frost { --acc: #3fd3b4; --acc-rgb: 63, 211, 180;  --hi: #b9f2e4; --bg-a: #071211; --bg-b: #0c1f1c; }
.mb--ice   { --acc: #6cc4ff; --acc-rgb: 108, 196, 255; --hi: #c9e8ff; --bg-a: #070d16; --bg-b: #0d1829; }

/* Halftone: fine dots across the edges, bigger ones gathering in the corners */
.mb-dots,
.mb-dots::after {
    position: absolute;
    inset: 0;
    pointer-events: none;
    background-size: 2.6cqi 2.6cqi;
}
.mb-dots {
    background-image: radial-gradient(rgba(var(--acc-rgb), .42) .45cqi, transparent .6cqi);
    -webkit-mask-image: radial-gradient(70% 80% at 50% 50%, transparent 38%, #000 100%);
            mask-image: radial-gradient(70% 80% at 50% 50%, transparent 38%, #000 100%);
}
.mb-dots::after {
    content: "";
    background-image: radial-gradient(rgba(var(--acc-rgb), .5) .75cqi, transparent .9cqi);
    -webkit-mask-image: radial-gradient(85% 95% at 50% 50%, transparent 66%, #000 100%);
            mask-image: radial-gradient(85% 95% at 50% 50%, transparent 66%, #000 100%);
}

/* Snow: a 200%-tall layer whose tile is one banner tall, moved by one tile */
.mb-snow {
    position: absolute;
    left: 0;
    right: 0;
    top: -100%;
    height: 200%;
    background-size: 100% 50%;
    animation: mb-fall 22s linear infinite;
    pointer-events: none;
}
.mb-snow--far {
    opacity: .4;
    background-image:
        radial-gradient(circle at 8% 14%, #fff 0 1px, transparent 1.6px),
        radial-gradient(circle at 26% 62%, #fff 0 1px, transparent 1.6px),
        radial-gradient(circle at 41% 28%, #fff 0 1px, transparent 1.6px),
        radial-gradient(circle at 57% 81%, #fff 0 1px, transparent 1.6px),
        radial-gradient(circle at 73% 44%, #fff 0 1px, transparent 1.6px),
        radial-gradient(circle at 89% 9%, #fff 0 1px, transparent 1.6px),
        radial-gradient(circle at 17% 90%, #fff 0 1px, transparent 1.6px),
        radial-gradient(circle at 65% 6%, #fff 0 1px, transparent 1.6px);
}
.mb-snow--near {
    opacity: .65;
    animation-duration: 12s;
    background-image:
        radial-gradient(circle at 14% 36%, #fff 0 1.4px, transparent 2.2px),
        radial-gradient(circle at 48% 70%, #fff 0 1.4px, transparent 2.2px),
        radial-gradient(circle at 82% 22%, #fff 0 1.4px, transparent 2.2px),
        radial-gradient(circle at 34% 8%, #fff 0 1.4px, transparent 2.2px);
}

/* Brand mark */
.mb-mark {
    position: absolute;
    top: 6.5cqi;
    left: 50%;
    width: 6.4cqi;
    margin-left: -3.2cqi;
    fill: none;
    stroke: var(--acc);
    stroke-width: 2.4;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* ── Stage: the tile and the headline share one cell and take turns ── */
.mb-stage {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
}
.mb-tile,
.mb-head { grid-area: 1 / 1; }

.mb-tile {
    width: 25cqi;
    aspect-ratio: 1;
    display: grid;
    place-items: center;
    border-radius: 6.5cqi;
    background: linear-gradient(160deg, rgba(255, 255, 255, .08), rgba(255, 255, 255, .02));
    border: 1px solid rgba(255, 255, 255, .09);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .08), 0 2.5cqi 6cqi rgba(0, 0, 0, .38);
    opacity: 0;
    animation: mb-tile var(--loop) var(--ease) var(--off, 0s) infinite;
}
.mb-tile-in {
    display: block;
    width: 58%;
    animation: mb-icon var(--loop) var(--ease) var(--off, 0s) infinite;
}
.mb-icon { display: block; width: 100%; height: auto; }
.mb-icon .i-a { fill: var(--acc); }
.mb-icon .i-b { fill: var(--hi); }
.mb-icon .i-c { fill: #fff; opacity: .55; }
.mb-icon .i-d { fill: var(--bg-a); }
.mb-icon .i-w { fill: #f4f2ff; }
.mb-icon .i-s { fill: none; stroke: #fff; stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
.mb-icon .i-rib { fill: none; stroke: rgba(0, 0, 0, .22); stroke-width: 1.6; }
.mb-icon .i-stem { fill: #6f8f3c; }

.mb-head {
    max-width: 94%;
    font-family: 'Outfit', system-ui, sans-serif;
    font-stretch: 75%;
    font-weight: 800;
    font-size: 8.5cqi;
    line-height: .94;
    letter-spacing: .005em;
    text-transform: uppercase;
    text-align: center;
    text-wrap: balance;
}
.mb-w {
    display: inline-block;
    opacity: 0;
    animation: mb-word var(--loop) var(--ease) calc(var(--off, 0s) + var(--i, 0) * 70ms) infinite;
}
.mb .is-accent { color: var(--acc); }

.mb-cap {
    position: absolute;
    left: 6cqi;
    right: 6cqi;
    bottom: 7.5cqi;
    font-family: 'Onest', system-ui, sans-serif;
    font-size: clamp(.68rem, 3.6cqi, 1.15rem);
    font-weight: 600;
    letter-spacing: -.01em;
    text-align: center;
    color: rgba(246, 243, 255, .9);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Progress line with a light that sweeps once per loop */
.mb-progress {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: max(2px, .9cqi);
    overflow: hidden;
    background: rgba(var(--acc-rgb), .8);
}
.mb-progress span {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: 16%;
    background: linear-gradient(90deg, transparent, #fff, transparent);
    transform: translateX(-100%);
    animation: mb-sweep var(--loop) linear var(--off, 0s) infinite;
}

/* ── Halloween ── */
.mb-web {
    position: absolute;
    top: 0;
    left: 0;
    width: 24cqi;
    fill: none;
    stroke: rgba(240, 236, 255, .2);
    stroke-width: .7;
    pointer-events: none;
}
.mb-bat {
    position: absolute;
    top: 0;
    left: 0;
    width: 9cqi;
    fill: #050308;
    stroke: rgba(var(--acc-rgb), .75);   /* moonlight catching the wings */
    stroke-width: 1.1;
    stroke-linejoin: round;
    opacity: 0;
    animation: mb-bat var(--loop) linear var(--off, 0s) infinite;
}
.mb-bat path {
    transform-box: fill-box;
    transform-origin: center;
    animation: mb-flap .2s ease-in-out infinite alternate;
}

/* Off-screen cards do not need to spend compositor time. JS toggles this with
   IntersectionObserver and also pauses every banner while the tab is hidden. */
.mb.is-motion-paused,
.mb.is-motion-paused * { animation-play-state: paused !important; }

@media (max-width: 640px) {
    /* One snow layer and no flapping bat on small GPUs keeps the art direction
       while cutting simultaneous compositing work substantially. */
    .mb-snow--near, .mb-bat { display: none; }
}

/* ── Timeline (one loop): tile 0–45%, headline 44–97% ── */
@keyframes mb-tile {
    0%   { opacity: 0; transform: translateY(8%) scale(.86); }
    7%   { opacity: 1; transform: none; }
    38%  { opacity: 1; transform: none; }
    45%  { opacity: 0; transform: translateY(-6%) scale(1.06); }
    100% { opacity: 0; transform: translateY(8%) scale(.86); }
}
/* The icon turns in edge-on, settles, then makes one full turn before the headline */
@keyframes mb-icon {
    0%        { transform: perspective(40cqi) rotateY(-90deg) scale(.82); }
    10%       { transform: perspective(40cqi) rotateY(0deg) scale(1); }
    17%       { transform: perspective(40cqi) rotateY(0deg) scale(1); }
    31%, 100% { transform: perspective(40cqi) rotateY(360deg) scale(1); }
}
@keyframes mb-word {
    0%, 44%   { opacity: 0; transform: translateY(45%); }
    52%       { opacity: 1; transform: none; }
    91%       { opacity: 1; transform: none; }
    97%, 100% { opacity: 0; transform: translateY(-30%); }
}
@keyframes mb-sweep {
    to { transform: translateX(725%); }
}
@keyframes mb-bat {
    0%, 35%   { opacity: 0; transform: translate(-14cqi, 22cqi) scale(.8); }
    37%       { opacity: 1; }
    45%       { transform: translate(28cqi, 9cqi) scale(1); }
    53%       { transform: translate(66cqi, 13cqi) scale(.9); }
    60%       { opacity: 1; transform: translate(108cqi, 1cqi) scale(.75); }
    61%, 100% { opacity: 0; transform: translate(108cqi, 1cqi) scale(.75); }
}
@keyframes mb-flap { to { transform: scaleY(.45); } }
@keyframes mb-fall { to { transform: translate3d(0, 50%, 0); } }

/* Reduced motion: hold the headline, no loop */
@media (prefers-reduced-motion: reduce) {
    .mb-snow, .mb-progress span, .mb-tile-in, .mb-bat path { animation: none; }
    .mb-tile, .mb-bat { animation: none; opacity: 0; }
    .mb-w { animation: none; opacity: 1; }
}
