/* ============================================================
 * p_brand_grid + p_brand_card paragraphs.
 *
 * Split out of p_card_grid so the "circular brand logo + name +
 * description + optional CTA pill" pattern can evolve without
 * dragging the legacy stat/highlighted-challenge styling along.
 *
 * Two visual variants:
 *  - .p-brand-grid         → light section (F7F7F9 underneath via
 *                            host page bg), white-translucent cards
 *                            with backdrop blur. Figma 18602-39076.
 *  - .p-brand-grid--dark   → dark navy band with full-bleed gradient
 *                            + globe illustration, translucent
 *                            cards over it. Replaces the legacy
 *                            .p-card-grid--dark ecosystem variant.
 *
 * Neutralise Drupal field wrappers so .p-brand-grid__grid is the
 * effective grid container of the cards directly.
 * ============================================================ */

.p-brand-grid {
    position: relative;
    padding-block: 90px 180px;
}
/* Light variant — full-bleed F7F7F9 band behind the grid.
   Scrollbar-safe (same pattern as .p-card-grid--dark and .p-rich-text--dark). */
.p-brand-grid:not(.p-brand-grid--dark):not(.p-brand-grid--marquee)::before {
    content: '';
    display: block;
    position: absolute;
    inset-block-start: 0;
    inset-inline-start: 50%;
    transform: translateX(-50%);
    width: 100vw;
    height: 100%;
    background: var(--grayMoreLight);
    box-shadow: 0 0 0 100vmax var(--grayMoreLight);
    clip-path: inset(0 -100vmax);
    z-index: 0;
}
.p-brand-grid__inner {
    position: relative;
    z-index: 1;
}

/* H2 + intro */
.p-brand-grid__heading {
    font-family: var(--font); font-weight: var(--fw-bold);
    font-size: var(--H2);
    line-height: var(--lh-heading);
    letter-spacing: var(--ls-tight2);
    text-align: center;
    color: var(--black);
    margin: 0;
    max-width: 840px;
    margin-inline: auto;
}
.p-brand-grid__intro {
    font-family: var(--font); font-weight: var(--fw-medium);
    font-size: var(--BodyL);
    line-height: var(--lh-body);
    letter-spacing: var(--ls-snug);
    text-align: center;
    color: var(--black);
    max-width: 800px;
    margin-inline: auto;
    margin-block-start: 24px;
}
.p-brand-grid__intro p {
    margin: 0;
}

/* Grid container — Drupal wrappers neutralised so cards are direct grid items.
   Default 2-col (Figma platforms grid). Optional 3-col via the
   .p-brand-grid--cols-3 modifier (editor toggle, used for 5–6 card
   ecosystem grids). */
.p-brand-grid__grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    /* Rows size to content (cards still stretch to the tallest in their row)
       so a card is no taller than its content needs — matching Figma instead
       of padding every card out to a fixed 325px min. */
    grid-auto-rows: auto;
    gap: 24px;
    margin-block-start: 80px;
    max-width: var(--content-max);
    margin-inline: auto;
}
.p-brand-grid--cols-3 .p-brand-grid__grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}
.p-brand-grid__grid > .field,
.p-brand-grid__grid > .field > .field__items,
.p-brand-grid__grid > .field .field__item {
    display: contents;
}

/* ===== Card ===== */
.p-brand-card {
    --rmaa-card-bg: rgba(255, 255, 255, 0.88);
    --rmaa-card-radius: 12px;
    --rmaa-card-padding: 36px 28px 28px;
    --rmaa-card-text: var(--black);

    display: flex;
    flex-direction: column;
    gap: 24px;
    backdrop-filter: blur(4px);
}

/* Head row — circular logo + brand name side-by-side. */
.p-brand-card__head {
    display: flex;
    align-items: center;
    gap: 12px;
}
.p-brand-card__icon {
    flex: 0 0 42px;
    width: 42px;
    height: 42px;
}
.p-brand-card__icon img {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    object-fit: cover;
    box-shadow: 0 0 3px 0 rgba(136, 136, 136, 0.7);
}
.p-brand-card__icon .field,
.p-brand-card__icon .media,
.p-brand-card__icon .media__content,
.p-brand-card__icon .field__items,
.p-brand-card__icon .field__item {
    width: 42px;
    height: 42px;
    line-height: 0;
}
.p-brand-card__title {
    font-family: var(--font); font-weight: var(--fw-bold);
    font-size: var(--H5);
    line-height: var(--lh-heading);
    letter-spacing: var(--ls-snug);
    color: var(--black);
    margin: 0;
}

/* Description — pushes CTA to the card bottom via flex-grow. */
.p-brand-card__description {
    font-family: var(--font); font-weight: var(--fw-medium);
    font-size: var(--BodyS);
    line-height: var(--lh-body);
    color: var(--black);
    flex: 1 1 auto;
}
.p-brand-card__description p {
    margin: 0;
}

/* CTA pill — right-aligned at card bottom, black bg, arrow icon inline. */
.p-brand-card--has-link {
    /* description grows; cta sits at bottom-right via align-self */
}
.p-brand-card__cta {
    align-self: flex-start;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: 42px;
    padding-inline: 24px;
    border-radius: 999px;
    background: var(--black, #0b0b0b);
    color: var(--white);
    text-decoration: none;
    font-family: var(--font);
    font-weight: var(--fw-medium);
    font-size: var(--BodyM);
    line-height: 1;
    letter-spacing: var(--ls-tight);
    transition: background-color .2s ease;
}
.p-brand-card__cta:hover,
.p-brand-card__cta:focus {
    background: var(--blue);
    color: var(--white);
    text-decoration: none;
}
.p-brand-card__cta-arrow {
    display: inline-flex;
    width: 24px;
    height: 24px;
    align-items: center;
    justify-content: center;
}

/* ============================================================
 * Dark variant — ecosystem (Telegram, Twitch-live).
 * Full-bleed dark navy band + globe illustration behind the grid.
 * Cards become glass-light translucent over the illustration.
 * ============================================================ */

.p-brand-grid--dark {
    --bg_image: url("../../img/ru-map-earth.dark.png");
    --bg_size: contain;
    --bg_position: center;

    padding-block: 180px;
}
.p-brand-grid--dark::before {
    content: '';
    display: block;
    position: absolute;
    inset-block-start: 0;
    inset-inline-start: 50%;
    transform: translateX(-50%);
    width: 100vw;
    height: 100%;
    background: var(--dark-band-bg);
    /* Scrollbar-safe fill — same pattern as .p-card-grid--dark and
       .p-rich-text--dark. */
    box-shadow: 0 0 0 100vmax var(--dark);
    clip-path: inset(0 -100vmax);
    z-index: 0;
}
.p-brand-grid--dark .p-brand-grid__heading,
.p-brand-grid--dark .p-brand-grid__intro {
    color: var(--white);
}
.p-brand-grid--dark .p-brand-grid__heading {
    max-width: 681px;
}

.p-brand-grid--dark .p-brand-grid__grid {
    position: relative;
    padding-block: 85px;
}
.p-brand-grid--dark .p-brand-grid__grid::before {
    content: '';
    display: block;
    position: absolute;
    inset-block-start: 0;
    width: 100%;
    height: 100%;
    background-image: var(--bg_image);
    background-repeat: no-repeat;
    background-size: var(--bg_size);
    background-position: var(--bg_position);
    z-index: -1;
}

/* Glass-light cards over the globe. */
.p-brand-grid--dark .p-brand-card {
    --rmaa-card-bg: rgba(255, 255, 255, 0.88);
    backdrop-filter: blur(4px);
    position: relative;
}

/* First card in dark grid — accent purple (parity with legacy
   ecosystem first-card highlight on Telegram/Twitch-live). */
.p-brand-grid--dark .p-brand-grid__grid > .field > .field__items > .field__item:first-child .p-brand-card,
.p-brand-grid--dark .p-brand-grid__grid > .field > .field__item:first-child .p-brand-card,
.p-brand-grid--dark .p-brand-grid__grid .field__item:first-child .p-brand-card {
    --rmaa-card-bg: rgba(81, 55, 241, .88);
    color: var(--white);
}
.p-brand-grid--dark .p-brand-grid__grid > .field > .field__items > .field__item:first-child .p-brand-card .p-brand-card__title,
.p-brand-grid--dark .p-brand-grid__grid > .field > .field__item:first-child .p-brand-card .p-brand-card__title,
.p-brand-grid--dark .p-brand-grid__grid .field__item:first-child .p-brand-card .p-brand-card__title,
.p-brand-grid--dark .p-brand-grid__grid > .field > .field__items > .field__item:first-child .p-brand-card .p-brand-card__description,
.p-brand-grid--dark .p-brand-grid__grid > .field > .field__item:first-child .p-brand-card .p-brand-card__description,
.p-brand-grid--dark .p-brand-grid__grid .field__item:first-child .p-brand-card .p-brand-card__description {
    color: var(--white);
}

/* ============================================================
 * Marquee variant — field_marquee toggle.
 * Dark full-bleed band + infinite horizontal ticker of pill cards
 * (flag/logo left, title + stat right). Replaces the legacy
 * views.view.yandex_s_reach_across_the_cis_markets "Reach Across
 * the CIS Markets" block. Two identical runs (template) each
 * translate by their own width + gap for a seamless loop.
 * ============================================================ */

.p-brand-grid--marquee {
    padding-block: 60px 0;
    color: var(--white);
}
.p-brand-grid--marquee::before {
    content: '';
    display: block;
    position: absolute;
    inset-block-start: 0;
    inset-inline-start: 50%;
    transform: translateX(-50%);
    width: 100vw;
    height: 100%;
    background: var(--dark-band-bg);
    z-index: 0;
}
/* font-size pinned to the responsive tokens (legacy parity) — the 0,2,0
   specificity outranks the base 991/767/600 px shrinks below. */
.p-brand-grid--marquee .p-brand-grid__heading {
    color: var(--white);
    font-size: var(--H2);
    max-width: 661px;
    margin-block-end: 20px;
}
.p-brand-grid--marquee .p-brand-grid__intro {
    color: var(--white);
    font-size: var(--BodyL);
    max-width: 789px;
    margin-block-start: 0;
}

/* Ticker — full-bleed row of two duplicated card runs. */
.p-brand-grid__marquee {
    position: relative;
    z-index: 1;
    display: flex;
    gap: 12px;
    width: 100vw;
    margin-inline: calc(50% - 50vw);
    padding-block: 120px 180px;
    overflow: hidden;
}
.p-brand-grid__marquee-run {
    display: flex;
    flex-wrap: nowrap;
    gap: 12px;
    flex-shrink: 0;
    animation: brandMarquee 20s linear infinite;
}
.p-brand-grid__marquee-run > .field,
.p-brand-grid__marquee-run > .field > .field__items,
.p-brand-grid__marquee-run > .field .field__item {
    display: contents;
}

/* Pill card — glass pill over the dark band; icon spans both text rows
   via display:contents on the head wrapper. */
.p-brand-grid--marquee .p-brand-card {
    --rmaa-card-bg: rgba(255, 255, 255, 0.08);
    --rmaa-card-radius: 92px;
    --rmaa-card-padding: 20px;

    position: relative;
    display: grid;
    grid-template-columns: 64px auto;
    grid-template-rows: auto auto;
    align-content: center;
    column-gap: 16px;
    min-width: 312px;
    height: 104px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    backdrop-filter: none;
}
.p-brand-grid--marquee .p-brand-card__head {
    display: contents;
}
.p-brand-grid--marquee .p-brand-card__icon {
    grid-row: 1 / span 2;
    align-self: center;
    width: 64px;
    height: 64px;
    flex: none;
}
.p-brand-grid--marquee .p-brand-card__icon img {
    width: 64px;
    height: 64px;
    box-shadow: none;
}
.p-brand-grid--marquee .p-brand-card__icon .field,
.p-brand-grid--marquee .p-brand-card__icon .media,
.p-brand-grid--marquee .p-brand-card__icon .media__content,
.p-brand-grid--marquee .p-brand-card__icon .field__items,
.p-brand-grid--marquee .p-brand-card__icon .field__item {
    width: 64px;
    height: 64px;
}
.p-brand-grid--marquee .p-brand-card__title {
    grid-column: 2;
    font-size: var(--H3);
    letter-spacing: var(--ls-tight);
    color: var(--white);
    white-space: nowrap;
}
.p-brand-grid--marquee .p-brand-card__description {
    grid-column: 2;
    flex: none;
    font-size: var(--BodyM);
    letter-spacing: var(--ls-loose);
    color: rgba(157, 158, 163, 1);
    white-space: nowrap;
}

/* Linked pill (e.g. Kazakhstan → CIS page) — the CTA becomes an invisible
   stretched link covering the whole pill instead of a bottom button. */
.p-brand-grid--marquee .p-brand-card__cta {
    position: absolute;
    inset: 0;
    height: auto;
    padding: 0;
    border-radius: inherit;
    background: transparent;
}
.p-brand-grid--marquee .p-brand-card__cta:hover,
.p-brand-grid--marquee .p-brand-card__cta:focus {
    background: rgba(255, 255, 255, 0.06);
}
.p-brand-grid--marquee .p-brand-card__cta-label,
.p-brand-grid--marquee .p-brand-card__cta-arrow {
    display: none;
}


/* ============================================================
 * Responsive.
 * Same breakpoint scale as card-grid.css (1194 / 991 / 767 / 600).
 * ============================================================ */

@media (max-width: 1194px) {
    .p-brand-grid {
        padding-block: 90px 140px;
    }
    .p-brand-grid__grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 991px) {
    .p-brand-grid {
        padding-block: 80px 120px;
    }
    .p-brand-grid__heading {
        font-size: 36px;
    }
    .p-brand-grid__intro {
        font-size: 18px;
        margin-block-start: 20px;
    }
    .p-brand-grid__grid {
        margin-block-start: 48px;
        grid-auto-rows: auto;
    }
    /* 3-col collapses to 2-col one step earlier than fewer-card grids. */
    .p-brand-grid--cols-3 .p-brand-grid__grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .p-brand-card__title {
        font-size: 20px;
    }
}

@media (max-width: 767px) {
    .p-brand-grid {
        padding-block: 60px 80px;
    }
    .p-brand-grid__heading {
        font-size: 30px;
    }
    .p-brand-grid__intro {
        font-size: 16px;
        margin-block-start: 16px;
    }
    /* Both selectors listed so the single-column rule outranks the 991px
       `.p-brand-grid--cols-3 .p-brand-grid__grid` 2-col rule (0,2,0), which
       still matches at ≤767 and would otherwise keep cols-3 grids at 2
       columns — too narrow, so card content overflows the viewport. */
    .p-brand-grid__grid,
    .p-brand-grid--cols-3 .p-brand-grid__grid {
        grid-template-columns: 1fr;
        grid-auto-rows: auto;
        gap: 16px;
        margin-block-start: 32px;
    }
    .p-brand-card {
        --rmaa-card-padding: 28px 20px 20px;
        gap: 20px;
    }
    .p-brand-card__cta {
        align-self: flex-start;
    }
    .p-brand-grid--dark {
        --bg_position: center top;
        --bg_size: 160%;
    }
    .p-brand-grid--dark .p-brand-grid__grid {
        padding-block: 0;
    }
}

@media (max-width: 600px) {
    .p-brand-grid__heading {
        font-size: 26px;
    }
    .p-brand-card {
        --rmaa-card-padding: 24px 16px 18px;
    }
    .p-brand-card__title {
        font-size: 18px;
    }
}

/* ===== Marquee responsive (after the shared breakpoints so the
   variant rules win the equal-specificity cascade). Mirrors the
   legacy cis-markets mobile rules (responsive-main.css 767/600). ===== */

@media (max-width: 767px) {
    .p-brand-grid--marquee {
        padding-block: 100px 0;
    }
    .p-brand-grid--marquee .p-brand-grid__heading {
        margin-block-end: 24px;
        padding-inline: 16px;
    }
    .p-brand-grid--marquee .p-brand-grid__intro {
        padding-inline: 16px;
    }
    .p-brand-grid__marquee {
        padding-block: 80px 100px;
    }
    .p-brand-grid--marquee .p-brand-card {
        --rmaa-card-padding: 20px;
    }
}

@media (max-width: 600px) {
    .p-brand-grid--marquee::before {
        background: url("../../img/bg-fr4nw3.jpg") no-repeat bottom right;
        background-size: cover;
    }
}
