/*
 * Tabs over panels on the same page (the tab-panels Stimulus controller,
 * docs/adr/0080), not tabs between pages (tabs.css). One box: the tabs
 * across its top, edge to edge, joined to the open tab's white panel
 * under them by a black line. The tabs are black with white words, the
 * open one blue. Each tab's words, then
 * how many in a white circle if it counts something. Two by two on phones,
 * one row from 48rem.
 *
 *   <div class="tab-panels" data-controller="tab-panels">
 *     <div class="tab-panels__list" role="tablist" aria-labelledby="(its heading)" data-turbo-prefetch="false">
 *       <a class="tab-panels__tab" role="tab" id="(tab)" href="(this page, asking for its panel)"
 *          aria-controls="(panel)" aria-selected="true|false" data-tab-panels-target="tab"
 *          data-action="click->tab-panels#select keydown->tab-panels#move">
 *         <span class="tab-panels__label">Words</span>
 *         <span class="tab-panels__count">3</span>
 *       </a>
 *       ...
 *     </div>
 *     <div class="tab-panels__panel" role="tabpanel" id="(panel)" aria-labelledby="(tab)" tabindex="0">...</div>
 *     <div class="tab-panels__panel" ... hidden>...</div>
 *   </div>
 */
.tab-panels {
    border: 0.125rem solid var(--black);
    border-radius: 0.5rem;
    overflow: hidden;
    background-color: var(--white);
}

.tab-panels__list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    border-bottom: 0.125rem solid var(--black);
    background-color: var(--black);
}

/* An odd one out takes its whole row, rather than leaving an empty place beside it. */
.tab-panels__tab:last-child:nth-child(odd) {
    grid-column: 1 / -1;
}

@media (min-width: 48rem) {
    .tab-panels__list {
        grid-template-columns: none;
        grid-auto-columns: minmax(0, 1fr);
        grid-auto-flow: column;
    }

    .tab-panels__tab:last-child:nth-child(odd) {
        grid-column: auto;
    }
}

/* Bold whether open or not, so opening one never rewraps it and moves the rest. */
.tab-panels__tab {
    --focus: var(--tertiary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 2.75rem;
    padding: 0.375rem 0.625rem;
    background-color: var(--black);
    color: var(--white);
    font-weight: 700;
    text-decoration: none;
}

.tab-panels__tab:hover .tab-panels__label {
    text-decoration: underline;
}

.tab-panels__tab[aria-selected="true"] {
    background-color: var(--primary);
}

/* The focus ring inside the tab or panel, as the box clips anything outside it: yellow on the tabs' black and blue. */
.tab-panels__tab:focus-visible,
.tab-panels__panel:focus-visible {
    outline-offset: -0.375rem;
}

.tab-panels__label {
    line-height: 1.2;
}

/* How many: a white circle on any tab, open or not. */
.tab-panels__count {
    display: inline-grid;
    flex-shrink: 0;
    place-items: center;
    min-width: 1.625rem;
    height: 1.625rem;
    margin-left: auto;
    padding: 0 0.375rem;
    border: 0.0625rem solid var(--black);
    border-radius: 999px;
    background-color: var(--white);
    color: var(--black);
    font-size: 0.875rem;
    font-weight: 400;
    line-height: 1;
}

.tab-panels__panel {
    padding: 0.75rem;
}

@media (max-width: 47.99rem) {
    .tab-panels__tab {
        font-size: 0.9375rem;
    }
}
