.counter-layout {
    container-type: inline-size;
}

.counter-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 1.5rem 3rem;
}

/* Shared rows let the tallest value/tagline determine spacing for the whole row. */
.counter-grid > .counter-item {
    display: grid;
    grid-template-rows: subgrid;
    grid-row: span 3;
    min-width: 0;
    margin-bottom: 1.5rem;
}

.counter-value {
    min-width: 0;
    text-align: left;
    overflow-wrap: anywhere;
}

.counter-value > span {
    display: inline;
}

.counter-grid .counter-tagline {
    margin: 0;
    min-width: 0;
    overflow-wrap: anywhere;
}

.counter-line {
    align-self: start;
}

/* Four items wrap as 2 + 2, never 3 + 1. Three items stay together or stack. */
@container (min-width: 48rem) {
    .counter-grid[data-count="2"],
    .counter-grid[data-count="4"] {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@container (min-width: 64rem) {
    .counter-grid[data-count="3"] {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@container (min-width: 80rem) {
    .counter-grid[data-count="4"] {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}
