::deep :host {
    --roll-duration: 1s;
    --roll-easing: ease;
}

.bfrn {
    /* User-customizable CSS variables */
    /* font-family: var(--bfrn-font-family, inherit); */
    /* font-size: var(--bfrn-font-size, inherit); */
    line-height: var(--bfrn-line-height, normal);
    /* font-weight: var(--bfrn-font-weight, inherit); */
    color: var(--bfrn-color, inherit);
    
    /* Layout - not customizable */
    display: inline-flex;
    contain: layout style paint;
}

.bfrn__digit {
    width: 1ch;
    overflow: hidden;
    display: inline-flex;
    position: relative;
}

/* Static decimal-point separator — not a rolling digit */
.bfrn__dot {
    display: inline-flex;
    align-items: flex-end;
    justify-content: center;
    width: 0.4ch;
    line-height: inherit;
    user-select: none;
}

/* Static thousand-separator comma — not a rolling digit */
.bfrn__comma {
    display: inline-flex;
    align-items: flex-end;
    justify-content: center;
    width: 0.4ch;
    line-height: inherit;
    user-select: none;
}

/* Static symbol rendered before the digits (Money: $, Rate: x) */
.bfrn__prefix {
    display: inline-flex;
    align-items: flex-end;
    line-height: inherit;
    user-select: none;
}

/* Static symbol rendered after the digits (Percentage: %) */
.bfrn__suffix {
    display: inline-flex;
    align-items: flex-end;
    line-height: inherit;
    user-select: none;
}

.bfrn__value {
    color: transparent;
    position: relative;
}

/* Static digit (RollingNumbers Animated="false").

   In a rolling digit the visible glyph is a span inside the absolutely-positioned
   .bfrn__scale column and .bfrn__value only reserves the box, hence its transparent
   colour. A static digit has no column, so .bfrn__value IS the glyph and must be
   painted. Everything else — the 1ch width from .bfrn__digit, the box height and the
   baseline from .bfrn__value — is shared with the rolling variant, so the two render
   at identical metrics and can sit side by side in one .bfrn. */
.bfrn__digit--static .bfrn__value {
    color: inherit;
}

.bfrn__scale {
    user-select: none;
    position: absolute;
    left: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    transition: transform var(--roll-duration, 1s) var(--roll-easing, ease);
}

.bfrn__digit .bfrn__scale {
    transform: translateY(var(--digit-offset, 0%));
}

.bfrn__scale span:last-child {
    position: absolute;
    bottom: -10%;
    left: 0;
}

/* Top/bottom fade — active only while the digit is transitioning */
.bfrn__digit--scrolling {
    -webkit-mask-image: linear-gradient(
        to bottom,
        transparent 0%,
        black var(--bfrn-fade-size, 20%),
        black calc(100% - var(--bfrn-fade-size, 20%)),
        transparent 100%
    );
    mask-image: linear-gradient(
        to bottom,
        transparent 0%,
        black var(--bfrn-fade-size, 20%),
        black calc(100% - var(--bfrn-fade-size, 20%)),
        transparent 100%
    );
}

/* Support for prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
    .bfrn__scale {
        transition: none;
    }
}

/* High refresh rate optimization */
@media (prefers-reduced-motion: no-preference) {
    @supports (animation-timeline: scroll()) {
        .bfrn__scale {
            /* Ready for scroll-driven animations if needed */
        }
    }
}

/* Color scheme support */
@media (prefers-color-scheme: dark) {
    .bfrn {
        color-scheme: dark;
    }
}

/* Container queries support (when parent has container-type) */
@container (min-width: 0) {
    .bfrn__digit {
        /* Container-aware sizing if needed */
    }
}
