/**
 * Site-wide birthday promo banner: a continuously scrolling "running row"
 * that stays pinned to the viewport top alongside the sticky header.
 *
 * Layout strategy:
 *   1. Banner is position: fixed at top:0 with a known height exposed as
 *      --s9-promo-banner-h on :root (gated via :has so the var is only set
 *      when the banner is actually in the DOM).
 *   2. #page-root gets padding-top equal to that height so initial content
 *      layout is not hidden behind the fixed banner.
 *   3. header.sticky's existing top:0 is overridden to top:var(banner-h)
 *      so the re-stickying header docks immediately below the banner
 *      instead of covering it.
 *
 * Z-index ladder (lowest to highest):
 *   - sticky header: no explicit z-index (default stacking)
 *   - banner:        9999  (above sticky header, below modal + menu-open)
 *   - modal:        99999  (firebase_login_modal)
 *   - menu-open header: 100000000001 (mobile menu UX takes over the screen)
 */

/* Variable lives on :root so header.sticky (a sibling of the banner in the
   DOM) can read it. :has() gates the var to pages where the banner exists.
   Also override --header-z (defined in main_v2.css as 2147483645) so the
   header sits BELOW the banner. Without this override the in-flow header
   visibly poked above the banner during the scroll range where it is
   meant to be hidden behind it. */
:root:has(.s9-promo-banner) {
    --s9-promo-banner-h: 44px;
    --header-z: 8000;
}

@media (max-width: 600px) {
    :root:has(.s9-promo-banner) {
        --s9-promo-banner-h: 40px;
    }
}

.s9-promo-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 9999;
    height: var(--s9-promo-banner-h, 44px);
    display: flex;
    align-items: center;
    background: #0F2447;
    color: #fff;
    font-family: 'Plus Jakarta Sans', -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
    overflow: hidden;
}

/* Push the page below the fixed banner so the initial layout is intact. */
body:has(.s9-promo-banner) #page-root {
    padding-top: var(--s9-promo-banner-h, 44px);
}

/* The sticky-on-scroll header already sets top:0 + position:fixed in
   main_v2.css. Override its top so it docks under the banner instead of
   overlapping it. Only applies when the banner is present.
   The companion JS patch (main_v2.js) zeroes the showPoint/hidePoint
   buffers when --s9-promo-banner-h is set, so the sticky kicks in the
   exact moment the in-flow header is hidden behind the banner (no gap).
   We keep a short slide-in/out so the header reads as motion instead of
   popping in: 180ms tracks the buffer-less threshold tightly without
   feeling like a separate animation. */
body:has(.s9-promo-banner) header.sticky {
    top: var(--s9-promo-banner-h, 44px);
    animation: stickyheader 0.18s ease-out;
}
body:has(.s9-promo-banner) header.nosticky {
    animation: stickyheaderhide 0.18s ease-in;
}

/* When the mobile menu is open, main_v2.css forces the header to top:0
   with a z-index higher than the banner's, so the menu takes over the
   screen and the banner gets covered. No override needed here; just
   document the intentional behavior. */

/* Viewport clips the over-wide scrolling track. */
.s9-promo-banner__viewport {
    flex: 1;
    height: 100%;
    overflow: hidden;
    display: flex;
    align-items: center;
}

/* The track holds 8 identical segments side by side. translateX(-50%)
   shifts it by exactly 4 segments; segment 5 == segment 1, so the loop
   is seamless. width:max-content keeps every segment on one line. */
.s9-promo-banner__track {
    display: flex;
    width: max-content;
    animation: s9-promo-scroll 36s linear infinite;
    will-change: transform;
}

@keyframes s9-promo-scroll {
    from { transform: translateX(0); }
    to   { transform: translateX(-50%); }
}

/* Pause while the visitor hovers so they can read it. */
.s9-promo-banner:hover .s9-promo-banner__track {
    animation-play-state: paused;
}

.s9-promo-banner__item {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    white-space: nowrap;
    padding: 0 0;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.01em;
}

.s9-promo-banner__emoji {
    font-size: 17px;
    line-height: 1;
}

.s9-promo-banner__sep {
    color: #1F86FF;
    font-size: 14px;
}

/* Soft fades at both ends so text eases in and out of the running row. */
.s9-promo-banner::before,
.s9-promo-banner::after {
    content: "";
    position: absolute;
    top: 0;
    width: 64px;
    height: 100%;
    pointer-events: none;
    z-index: 2;
}
.s9-promo-banner::before {
    left: 0;
    background: linear-gradient(90deg, #0F2447 0%, rgba(15, 36, 71, 0) 100%);
}
.s9-promo-banner::after {
    right: 0;
    background: linear-gradient(90deg, rgba(15, 36, 71, 0) 0%, #0F2447 100%);
}

@media (max-width: 600px) {
    .s9-promo-banner__item {
        font-size: 13px;
        gap: 8px;
    }
    /* Shorter track travel reads faster on narrow screens; speed it up. */
    .s9-promo-banner__track {
        animation-duration: 24s;
    }
    /* Smaller fade so more text is readable on a narrow viewport. */
    .s9-promo-banner::before,
    .s9-promo-banner::after {
        width: 36px;
    }
}

/* Respect reduced-motion: stop scrolling, center the first segment. */
@media (prefers-reduced-motion: reduce) {
    .s9-promo-banner__viewport {
        justify-content: center;
    }
    .s9-promo-banner__track {
        animation: none;
        width: auto;
    }
    .s9-promo-banner__item:not(:first-child) {
        display: none;
    }
}
