@layer htmxo {
figure.captioned { margin: 0 0 1rem 0; }
/* The header takes what the toggle of a long text leaves of the row. */
figcaption.caption { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.25rem 0.5rem; margin-bottom: 0.5rem; }
figcaption.caption > .caption-header { flex: 1 1 16rem; min-width: 0; }
.caption-header { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 0.25rem 1rem; }
/* The title keeps 16rem beside the actions, else they wrap below it. An empty
   placeholder (the uncaptioned download header) takes no basis, so its button
   stays on the right. */
.caption-header > :first-child:not(:empty) { flex: 1 1 16rem; min-width: 0; }
.caption-actions { display: inline-flex; flex-wrap: wrap; gap: 0.25rem; }
}
/* Caption buttons — INTENTIONALLY UNLAYERED, at (0,2,0) so they beat Pico's
   unlayered button and [type=button] rules (0,0,1)/(0,1,0) in any order. */
.caption-actions > .caption-action { padding: 0.1rem 0.5rem; font-size: 0.85em; margin: 0; }
/* The toggle of a long text, drawn like those buttons: the one disclosure that
   is not the Pico bridge's full-width box, because it repeats on every figure
   and a row of its own would push the figure down. The `<details>` gives up its
   box, so its label and its content are items of the caption's row; closed
   content stays out of that row. INTENTIONALLY UNLAYERED, and stronger than
   Pico's and the bridge's `details` rules in any order. */
figcaption.caption > details.caption-long { display: contents; }
figcaption.caption > details.caption-long > summary {
    flex: 0 0 auto;
    margin: 0;
    padding: 0.1rem 0.5rem;
    border: var(--pico-border-width, 1px) solid var(--pico-secondary, currentColor);
    border-radius: var(--pico-border-radius, 0.25rem);
    background: transparent;
    color: var(--pico-secondary, inherit);
    font-size: 0.85em;
    font-weight: 400;
    line-height: var(--pico-line-height, 1.5);
}
figcaption.caption > details.caption-long > summary:is(:hover, :focus-visible) {
    border-color: var(--pico-secondary-hover, currentColor);
    background: transparent;
    color: var(--pico-secondary-hover, inherit);
}
figcaption.caption > details.caption-long > summary::before {
    width: 0.85rem;
    height: 0.85rem;
    margin-inline-end: 0.25rem;
    background-size: 0.85rem auto;
}
figcaption.caption > details.caption-long::details-content { position: absolute; padding: 0; }
figcaption.caption > details.caption-long[open]::details-content {
    position: static;
    flex: 1 0 100%;
    box-sizing: border-box;
    padding: 0.75rem 1rem;
    border: var(--pico-border-width, 1px) solid var(--pico-form-element-border-color, currentColor);
    border-radius: var(--pico-border-radius, 0.25rem);
}
figcaption.caption > details.caption-long > :last-child > :last-child { margin-bottom: 0; }
