/*
 * Reusable horizontal 3-slice UI skin.
 * One source PNG, no canvas, no generated data URLs and no JS layout pass.
 * LEFT/RIGHT keep their source proportions; only CENTER stretches horizontally.
 */
.ui-3slice {
    --press-distance: 2px;
    --press-scale: .985;
    --ui-source-width: 1;
    --ui-source-height: 1;
    --ui-left-slice: 0;
    --ui-right-slice: 0;
    --ui-center-slice: 1;
    --ui-left-width: calc(100% * 0); /* fallback only; overridden below using element height */
    position: relative;
    isolation: isolate;
    overflow: visible;
}

.ui-3slice__skin {
    position: absolute;
    inset: 0;
    z-index: 0;
    pointer-events: none;
}

.ui-3slice__part {
    position: absolute;
    top: 0;
    bottom: 0;
    display: block;
}

/* cap width = rendered height × source-cap-width / source-height */
.ui-3slice__part--left {
    left: 0;
    width: calc(var(--ui-left-slice) / var(--ui-source-height) * 100cqh);
    background-image: var(--ui-image);
    background-repeat: no-repeat;
    background-size: calc(var(--ui-source-width) / var(--ui-source-height) * 100cqh) 100%;
    background-position: left top;
}

.ui-3slice__part--right {
    right: 0;
    width: calc(var(--ui-right-slice) / var(--ui-source-height) * 100cqh);
    background-image: var(--ui-image);
    background-repeat: no-repeat;
    background-size: calc(var(--ui-source-width) / var(--ui-source-height) * 100cqh) 100%;
    background-position: right top;
}

/* Center is a clipping window. Its child contains the same full PNG, mapped so
   exactly the source middle strip fills this window. */
.ui-3slice__part--center {
    left: calc(var(--ui-left-slice) / var(--ui-source-height) * 100cqh);
    right: calc(var(--ui-right-slice) / var(--ui-source-height) * 100cqh);
    overflow: hidden;
}

.ui-3slice__center-image {
    position: absolute;
    top: 0;
    bottom: 0;
    left: calc(-1 * var(--ui-left-slice) / var(--ui-center-slice) * 100%);
    width: calc(var(--ui-source-width) / var(--ui-center-slice) * 100%);
    background-image: var(--ui-image);
    background-repeat: no-repeat;
    background-size: 100% 100%;
    background-position: left top;
}

.ui-3slice__content {
    position: relative;
    z-index: 1;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
}

/* Never transform the button itself: its screen position may already use transform. */
.ui-3slice__skin,
.ui-3slice__content {
    transition: transform 70ms ease-out, filter 70ms ease-out;
    transform-origin: 50% 55%;
}

/* Optional per-button shadow; follows the PNG alpha shape. */
.ui-3slice__skin {
    filter: var(--ui-shadow, none);
}

.ui-3slice.is-pressing .ui-3slice__skin {
    transform: translateY(var(--press-distance)) scale(var(--press-scale));
    filter: brightness(.93) var(--ui-shadow, none);
}

.ui-3slice.is-pressing .ui-3slice__content {
    transform: translateY(var(--press-distance)) scale(var(--press-scale));
}

/* Container-query units make cap widths depend on the button's actual height. */
.ui-3slice { container-type: size; }
