/*
 * q4u_bento — standalone frontend stylesheet.
 *
 * Bento Grid + Bento Tile. No dependency on q4u_base SCSS: the extension can be
 * deployed to any TYPO3 v13 + Bootstrap 5 site without touching the theme layer.
 *
 * Wired via Configuration/Sets/Q4uBento/setup.typoscript (page.includeCSS).
 *
 * Class namespace is .q4u-bento*. The shorter .bento / .bento__cell belong to
 * q4u_base's TopicIslands content element and both stylesheets load on the same page.
 *
 * Theme integration — every hook below is a custom property a theme may override:
 *   --q4u-bento-row            grid row unit (the floor of a one-row tile)
 *   --q4u-bento-gap            gutter between tiles
 *   --q4u-bento-font-display   headline font family
 *   --q4u-bento-on-primary     text colour on a solid primary tile
 *   --q4u-bento-on-secondary   ...on secondary
 *   --q4u-bento-on-tertiary    ...on tertiary
 *   --q4u-bento-scrim          gradient over a cover image
 */

/* ── Section wrapper ───────────────────────────────────────────────────── */

.q4u-bento-section {
    margin-block: clamp(1.5rem, 4vw, 3rem);
}

.q4u-bento-section__header {
    margin-bottom: clamp(1rem, 2vw, 1.75rem);
}

.q4u-bento-section__headline {
    font-family: var(--q4u-bento-font-display, inherit);
    font-size: clamp(2rem, 4vw, 3.25rem);
    font-weight: 600;
    line-height: 1.05;
    letter-spacing: -0.025em;
    margin: 0;
}

.q4u-bento-section__lead {
    font-size: 1.125rem;
    color: var(--bs-secondary-color);
    max-width: 60ch;
    margin-top: 1rem;
}

.q4u-bento-section__lead > :last-child {
    margin-bottom: 0;
}

/* ── The grid ──────────────────────────────────────────────────────────────
   grid-auto-rows uses minmax(unit, auto): a row is one unit tall unless its
   content needs more, then it grows. Nothing is ever clipped. Known and accepted
   consequence — one overfull tile stretches its whole row band, and a hero or big
   tile spanning into that band grows with it.

   grid-auto-flow is row, never dense. Dense packing would pull later tiles forward
   to fill holes, which is exactly what the spacer tiles exist to prevent. */

.q4u-bento {
    --q4u-bento-row: clamp(140px, 14vw, 200px);
    --q4u-bento-gap: clamp(0.5rem, 1.2vw, 1rem);

    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    grid-auto-rows: minmax(var(--q4u-bento-row), auto);
    grid-auto-flow: row;
    gap: var(--q4u-bento-gap);
}

/* Positioned grids are opt-in; old grids retain their original markup and layout. */
@media (min-width: 992px) {
    .q4u-bento--columns-12 { grid-template-columns: repeat(12, minmax(0, 1fr)); }
    .q4u-bento--positioned > .q4u-bento__position {
        grid-column: var(--bento-column) / span var(--bento-width);
        grid-row: var(--bento-row) / span var(--bento-height);
    }
}

.q4u-bento__position { min-width: 0; }
.q4u-bento__position > .q4u-bento__tile { box-sizing: border-box; height: 100%; }

@media (max-width: 991.98px) {
    .q4u-bento.q4u-bento--columns-12 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
    .q4u-bento--positioned > .q4u-bento__position {
        grid-column: span var(--bento-tablet-width);
        grid-row: span var(--bento-height);
    }
}

@media (max-width: 767.98px) {
    .q4u-bento.q4u-bento--columns-12 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .q4u-bento--positioned > .q4u-bento__position { grid-column: span var(--bento-mobile-width); }
}

@media (max-width: 991.98px) {
    .q4u-bento { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 767.98px) {
    .q4u-bento { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.q4u-bento__empty {
    grid-column: 1 / -1;
    padding: 1.5rem;
    color: var(--bs-secondary-color);
    font-style: italic;
    margin: 0;
}

/* ── Size presets ──────────────────────────────────────────────────────────
   The only place a tile's footprint is defined. Fluid emits the class and
   nothing else, so there is no mapping to keep in sync. */

.q4u-bento__tile--s      { grid-column: span 1; grid-row: span 1; }
.q4u-bento__tile--wide   { grid-column: span 2; grid-row: span 1; }
.q4u-bento__tile--third  { grid-column: span 3; grid-row: span 1; }
.q4u-bento__tile--tall   { grid-column: span 1; grid-row: span 2; }
.q4u-bento__tile--hero   { grid-column: span 2; grid-row: span 2; }
.q4u-bento__tile--big    { grid-column: span 3; grid-row: span 2; }
.q4u-bento__tile--banner { grid-column: span 6; grid-row: span 1; }

@media (max-width: 991.98px) {
    .q4u-bento__tile--banner { grid-column: span 3; }
}

@media (max-width: 767.98px) {
    .q4u-bento__tile--third,
    .q4u-bento__tile--banner { grid-column: span 2; }
    .q4u-bento__tile--big    { grid-column: span 2; }
}

/* ── Typography per preset ─────────────────────────────────────────────────
   Headline size follows the tile, not the editor. A one-column tile must not be
   allowed a 56px headline. */

.q4u-bento__tile--s {
    --q4u-bento-h: clamp(1.125rem, 1.6vw, 1.375rem);
    --q4u-bento-lead: 0.9375rem;
}
.q4u-bento__tile--tall {
    --q4u-bento-h: clamp(1.25rem, 1.8vw, 1.5rem);
    --q4u-bento-lead: 0.9375rem;
}
.q4u-bento__tile--wide {
    --q4u-bento-h: clamp(1.375rem, 2.2vw, 1.75rem);
    --q4u-bento-lead: 1rem;
    --q4u-bento-lead-max: 44ch;
}
.q4u-bento__tile--third {
    --q4u-bento-h: clamp(1.5rem, 2.6vw, 2rem);
    --q4u-bento-lead: 1rem;
    --q4u-bento-lead-max: 48ch;
}
.q4u-bento__tile--banner {
    --q4u-bento-h: clamp(1.75rem, 3vw, 2.5rem);
    --q4u-bento-lead: 1.0625rem;
    --q4u-bento-lead-max: 46ch;
}
.q4u-bento__tile--hero {
    --q4u-bento-h: clamp(2rem, 3.6vw, 3rem);
    --q4u-bento-lead: 1.125rem;
    --q4u-bento-lead-max: 48ch;
}
.q4u-bento__tile--big {
    --q4u-bento-h: clamp(2.25rem, 4.2vw, 3.5rem);
    --q4u-bento-lead: 1.125rem;
    --q4u-bento-lead-max: 46ch;
}

/* ── Tile shell ────────────────────────────────────────────────────────── */

.q4u-bento__tile {
    /* Separation between the metadata line and the content block below it.

       There is no standard pixel value for this — the published guidance is
       relational: the gap BETWEEN groups must be clearly larger than the gap WITHIN
       one, and what the eye reads is the ratio, not the absolute. Inside the content
       block (kicker → headline → lead) the gap is 8px, so this token is deliberately
       2.5x to 4x that. It was 12px, a ratio of 1.5, and the chips read as part of
       the heading rather than as a separate line.

       ONE value for every preset. An earlier version used 2rem on two-row presets
       and 1.25rem on one-row ones, to stop the smaller tiles pushing their grid band
       past its unit height. That bought 12px of band height and cost the thing the
       separation exists for: the distance from the tags to the kicker then differed
       between neighbouring tiles, which is visible at a glance and defeats the
       grouping it was meant to express. A repeated element has one spacing.

       The price is paid in band height instead: two bands sit at 231 and 212 against
       a 200px unit rather than 219 and 200. Elastic rows are built for that. */
    --q4u-bento-group-gap: 2rem;

    position: relative;
    display: flex;
    flex-direction: column;
    min-width: 0;
    padding: clamp(1rem, 2vw, 2rem);
    border: 0;
    border-radius: 1rem;
    overflow: hidden;
}

.q4u-bento__body {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    flex: 0 1 auto;
    min-width: 0;
}

/* No opacity on the eyebrow. It is already set apart by the mono face, the uppercase
   and the letter-spacing, and opacity was the one thing pushing a sample below AA:
   white at 0.75 over the brand red (secondary/solid) composites to 3.29:1 at 12px.
   There is no headroom to tune it either — that tile only reaches 4.83:1 at full
   opacity. The demo page happens to carry no eyebrow on a secondary/solid tile, so
   this would have shipped unseen; it was found by probing all twelve colour x shade
   combinations rather than the ones the fixture uses. */

.q4u-bento__headline {
    font-family: var(--q4u-bento-font-display, inherit);
    font-size: var(--q4u-bento-h, 1.375rem);
    font-weight: 600;
    line-height: 1.08;
    letter-spacing: -0.02em;
    margin: 0 0 0.5rem;
}

/* Reading measure. NOT the tile width: on a 6-column banner the full width is 146
   characters per line, nearly twice the 80 that WCAG 1.4.8 (AAA) allows, and long
   lines are hard to track back to the start of the next one.

   CAUTION, `ch` IS NOT A CHARACTER. It is the advance width of the "0" glyph, and in
   this font that is 11.02px against an average character of 7.30px measured over real
   German prose — a factor of 1.51. The values below therefore read about 50% smaller
   than what they produce: 46ch is roughly 69 characters, 48ch about 72, 44ch about 66.
   `60ch` was in use here and rendered 91 characters, over the AAA ceiling, which is
   exactly the mistake the unit's name invites. */
.q4u-bento__lead {
    font-size: var(--q4u-bento-lead, 1rem);
    max-width: var(--q4u-bento-lead-max, none);
    margin: 0;
}

.q4u-bento__lead > :last-child {
    margin-bottom: 0;
}

/* ── Eyebrow token ─────────────────────────────────────────────────────────
   0.75rem is this project's 12px minimum font size. That minimum is a project
   rule; WCAG sets no absolute minimum font size. */

.q4u-bento-eyebrow {
    font-family: ui-monospace, 'SF Mono', Menlo, monospace;
    font-size: 0.75rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    margin: 0 0 0.5rem;
}

/* ── Colours ───────────────────────────────────────────────────────────────
   Each tile variant declares ONE foreground token, --q4u-bento-fg, and a single
   rule near the bottom pushes it into Bootstrap's custom properties and into an
   explicit link rule.

   Setting `color` alone is not enough: Bootstrap renders headings as
   `color: var(--bs-heading-color, inherit)` and links as
   `color: rgba(var(--bs-link-color-rgb), var(--bs-link-opacity, 1))`, both of
   which beat inheritance. A white-on-navy tile otherwise renders a black headline
   and a brand-coloured link — measured 1.89:1 for the theme's link red on the
   brand red tile, which is the same defect q4u_base fixed for bg-* utilities in
   SHPro-279.

   The primary foreground follows the theme's --bs-on-primary when available,
   including its configured contrast threshold. Other variants use the computed
   background contrast on supporting browsers and the fallbacks below elsewhere. */

/* ── Backgrounds ──────────────────────────────────────────────────────────
   Each variant declares its colour ONCE as --q4u-bento-bg and paints from it, so
   the cover scrim can tint itself with the same value instead of restating it. */

.q4u-bento__tile--solid.q4u-bento__tile--primary {
    --q4u-bento-bg: var(--bs-primary, #0d6efd);
    background-color: var(--q4u-bento-bg);
}
.q4u-bento__tile--solid.q4u-bento__tile--secondary {
    --q4u-bento-bg: var(--bs-secondary, #6c757d);
    background-color: var(--q4u-bento-bg);
}
.q4u-bento__tile--solid.q4u-bento__tile--tertiary {
    --q4u-bento-bg: rgb(var(--bs-tertiary-rgb, 205, 197, 192));
    background-color: var(--q4u-bento-bg);
}

.q4u-bento__tile--subtle.q4u-bento__tile--primary {
    --q4u-bento-bg: var(--bs-primary-bg-subtle, #cfe2ff);
    background-color: var(--q4u-bento-bg);
}
.q4u-bento__tile--subtle.q4u-bento__tile--secondary {
    --q4u-bento-bg: var(--bs-secondary-bg-subtle, #e2e3e5);
    background-color: var(--q4u-bento-bg);
}
.q4u-bento__tile--subtle.q4u-bento__tile--tertiary {
    /* Bootstrap auto-generates .bg-{color}-subtle only for its 8 default theme
       colours, so tertiary's tint is computed here. Mixed against --bs-body-bg,
       NOT a literal white: Bootstrap's own *-subtle variables flip to deep tints
       in dark mode and a mix against white does not, which produced a near-white
       tile carrying white text (1.01:1). */
    --q4u-bento-bg: color-mix(in srgb, rgb(var(--bs-tertiary-rgb, 205, 197, 192)) 20%, var(--bs-body-bg, white));
    background-color: var(--bs-tertiary-bg-subtle, #f3f1ed);
    background-color: var(--q4u-bento-bg);
}

/* White and black are absolutes, not theme colours: they do not follow the colour
   mode and they have no solid/subtle variant. The template emits no shade class for
   them, which is what keeps them out of the dark-mode rule that paints subtle tiles
   white — that pairing would render white text on a white tile. */
.q4u-bento__tile--white {
    --q4u-bento-bg: #fff;
    --q4u-bento-fg: #000;
    background-color: var(--q4u-bento-bg);
}
.q4u-bento__tile--black {
    --q4u-bento-bg: #000;
    --q4u-bento-fg: #fff;
    background-color: var(--q4u-bento-bg);
}

/* ── Foreground, fallback values (no contrast-color() support) ──
   Light mode assumes primary and secondary are dark brand colours and tertiary a
   light neutral — the fallback rgb(205, 197, 192) is this project's own tertiary,
   where white measures about 1.6:1. */

.q4u-bento__tile--solid.q4u-bento__tile--primary   { --q4u-bento-fg: var(--q4u-bento-on-primary, var(--bs-on-primary, #fff)); }
.q4u-bento__tile--solid.q4u-bento__tile--secondary { --q4u-bento-fg: var(--q4u-bento-on-secondary, #fff); }
.q4u-bento__tile--solid.q4u-bento__tile--tertiary  { --q4u-bento-fg: var(--q4u-bento-on-tertiary, #000); }

/* Subtle tiles use pure black or white, matching the project's black/white-only
   convention. Bootstrap's own *-text-emphasis variables produce tinted darks
   (dark blue on primary-subtle, greyish tan on tertiary-subtle), which read muddy. */
.q4u-bento__tile--subtle { --q4u-bento-fg: #000; }

/* Dark mode inverts the premise for solid tiles. A Bootstrap theme lightens its
   brand colours for dark backgrounds — measured on this project's default theme,
   primary goes rgb(61,58,97) → rgb(147,143,188) and secondary
   rgb(217,45,32) → rgb(232,109,99) — so white falls to about 3:1 and fails. */
[data-bs-theme="dark"] .q4u-bento__tile--subtle { --q4u-bento-fg: #fff; }

[data-bs-theme="dark"] .q4u-bento__tile--solid.q4u-bento__tile--primary {
    --q4u-bento-fg: var(--q4u-bento-on-primary-dark, var(--bs-on-primary, #000));
}
[data-bs-theme="dark"] .q4u-bento__tile--solid.q4u-bento__tile--secondary {
    --q4u-bento-fg: var(--q4u-bento-on-secondary-dark, #000);
}
[data-bs-theme="dark"] .q4u-bento__tile--solid.q4u-bento__tile--tertiary {
    --q4u-bento-fg: var(--q4u-bento-on-tertiary-dark, #000);
}

/* ── Foreground, computed ──────────────────────────────────────────────────
   contrast-color() selects black or white from the background in force. For
   primary, the theme's precomputed choice takes precedence: it incorporates
   the threshold configured in q4u_base, which contrast-color() does not know.

   Baseline Newly Available only since April 2026 (Chrome/Edge 147, Firefox 146,
   Safari 26), so the @supports guard is doing real work, not ceremony.

   Each selector is repeated with the [data-bs-theme="dark"] prefix purely to
   outrank the dark-mode fallbacks above, which are one class more specific. */

@supports (color: contrast-color(red)) {
    .q4u-bento__tile--solid.q4u-bento__tile--primary {
        --q4u-bento-fg: var(--q4u-bento-on-primary, var(--bs-on-primary, contrast-color(var(--bs-primary, #0d6efd))));
    }
    [data-bs-theme="dark"] .q4u-bento__tile--solid.q4u-bento__tile--primary {
        --q4u-bento-fg: var(--q4u-bento-on-primary-dark, var(--bs-on-primary, contrast-color(var(--bs-primary, #0d6efd))));
    }
    .q4u-bento__tile--solid.q4u-bento__tile--secondary,
    [data-bs-theme="dark"] .q4u-bento__tile--solid.q4u-bento__tile--secondary {
        --q4u-bento-fg: contrast-color(var(--bs-secondary, #6c757d));
    }
    .q4u-bento__tile--solid.q4u-bento__tile--tertiary,
    [data-bs-theme="dark"] .q4u-bento__tile--solid.q4u-bento__tile--tertiary {
        --q4u-bento-fg: contrast-color(rgb(var(--bs-tertiary-rgb, 205, 197, 192)));
    }

    .q4u-bento__tile--subtle.q4u-bento__tile--primary,
    [data-bs-theme="dark"] .q4u-bento__tile--subtle.q4u-bento__tile--primary {
        --q4u-bento-fg: contrast-color(var(--bs-primary-bg-subtle, #cfe2ff));
    }
    .q4u-bento__tile--subtle.q4u-bento__tile--secondary,
    [data-bs-theme="dark"] .q4u-bento__tile--subtle.q4u-bento__tile--secondary {
        --q4u-bento-fg: contrast-color(var(--bs-secondary-bg-subtle, #e2e3e5));
    }
    .q4u-bento__tile--subtle.q4u-bento__tile--tertiary,
    [data-bs-theme="dark"] .q4u-bento__tile--subtle.q4u-bento__tile--tertiary {
        --q4u-bento-fg: contrast-color(color-mix(in srgb, rgb(var(--bs-tertiary-rgb, 205, 197, 192)) 20%, var(--bs-body-bg, white)));
    }
}

/* THE TILE COLOUR RULES, on a cover image as everywhere else: a white tile gets
   dark text, a black tile light text, a brand tile whatever contrasts with it. The
   colour an editor picked is never overruled.

   The one exception is a tile with NO colour. There is nothing to rule with, and a
   transparent tile over a photograph would otherwise fall back to the page's body
   colour — which is exactly how a dark photo once ended up carrying black text. It
   takes white, protected by the scrim.

   The cost, stated rather than hidden: inside the scrim's guaranteed band the
   backdrop is the dark scrim, not the tile, so a LIGHT tile colour now puts dark
   text on a dark backdrop. Tile colour and darkening have to be chosen together on
   a cover tile; the README carries the pairing. */
/* Two classes, and the dark variant three, so this outranks the per-variant rules
   in the @supports block above (.--solid.--primary is 0,2,0 and its dark sibling
   0,3,0). Written with one class it silently lost for every theme colour while
   still winning for white, black and none — measured as black text at 1.1:1 on a
   dark scrim, with white behaving perfectly two rows away. */
.q4u-bento__tile.q4u-bento__tile--media-cover,
[data-bs-theme="dark"] .q4u-bento__tile.q4u-bento__tile--media-cover {
    /* The backdrop a word actually sits on is the darkening layer composited over
       the tile colour, so that is what the text colour is computed against — not
       the tile colour alone and not the scrim alone.

       It settles both ends by itself. With no darkening the composite IS the tile
       colour, so the colour rules outright: a white tile gets black text. Turn the
       darkening up and the composite slides to black, and the text follows it to
       white, because by then the scrim is what the reader sees.

       Picking one end instead of the composite fails at the other, and both were
       measured: forcing white ignored the tile colour entirely, while taking the
       tile colour alone put black text on a black scrim — 1.0:1 on seven of nine
       variants, at every darkening level.

       --q4u-bento-bg is undefined on a tile with no colour; the #000 fallback then
       makes the composite black and the text white, which is the right default over
       a photograph. */
    --q4u-bento-cover-backdrop: color-mix(
        in srgb,
        #000 calc(var(--q4u-bento-scrim-opacity, 0.65) * 100%),
        var(--q4u-bento-bg, #000)
    );
    --q4u-bento-fg: contrast-color(var(--q4u-bento-cover-backdrop));
}

/* Without contrast-color() there is nothing to compute with, so the old behaviour
   stands: white over the image, which the scrim's own floor protects. */
@supports not (color: contrast-color(red)) {
    .q4u-bento__tile--media-cover {
        --q4u-bento-fg: #fff;
    }
}

/* ── Applying the token ────────────────────────────────────────────────────
   --none tiles declare no token, so they inherit the page's own colours and
   keep the theme's link colour, which is legible there by definition. */

.q4u-bento__tile--solid,
.q4u-bento__tile--subtle,
.q4u-bento__tile--white,
.q4u-bento__tile--black,
.q4u-bento__tile--media-cover {
    color: var(--q4u-bento-fg);
    --bs-body-color: var(--q4u-bento-fg);
    --bs-heading-color: var(--q4u-bento-fg);
    --bs-emphasis-color: var(--q4u-bento-fg);
    --bs-link-color: var(--q4u-bento-fg);
    --bs-link-hover-color: var(--q4u-bento-fg);
}

/* Links, including any the editor put inside the RTE lead.
   This rule, not the custom properties above, is what recolours them.

   Bootstrap paints links from --bs-link-color-RGB — a channel triple, not a
   colour — so setting --bs-link-color leaves an RTE link at the theme's own
   colour. Measured before this rule existed: the theme's link red on the brand
   red tile, 1.89:1. contrast-color() returns a colour and cannot produce that
   triple, so the triple is not an option here.

   Hence !important, which is not laziness. q4u_base's theme ships

     [data-bs-theme=dark] a:not(.btn):not(.btn-brand) … 16 further :not()

   at specificity (0,17,1). A selector able to outrank that by specificity alone
   would be unreadable, and it would still lose to the next :not() somebody adds.
   On a tile whose background this extension chose, the link colour is not
   negotiable — that is exactly what autocontrast means — so stating it as
   !important says what is meant. Without it the rule wins in light mode and
   silently loses in dark, which is how this was found.

   .btn is excluded so a button pasted into a tile keeps its own colours. */
.q4u-bento__tile--solid :any-link:not(.btn),
.q4u-bento__tile--subtle :any-link:not(.btn),
.q4u-bento__tile--white :any-link:not(.btn),
.q4u-bento__tile--black :any-link:not(.btn),
.q4u-bento__tile--media-cover :any-link:not(.btn) {
    color: var(--q4u-bento-fg) !important;
    text-decoration-color: color-mix(in srgb, var(--q4u-bento-fg) 55%, transparent);
}

/* A transparent tile has no background of its own, so its contrast is normally not
   its business: on the page it inherits the theme's body colour, which the theme
   already pairs with the page background.

   The exception — a coloured background on the GRID element — is handled in
   q4u-bento-standalone.css, which ext_localconf.php loads ONLY when q4u_base is
   absent. See that file for why it is not loaded unconditionally. */

/* No background: the tile keeps its grid footprint and padding so its text aligns
   with the neighbouring tiles, but inherits the page's own colours.

   It declares no foreground token and sets no `color`. A `color: inherit` here used
   to look harmless and was neither redundant-but-safe nor correct:

     - redundant, because a --none tile matches none of the three selectors above
       that set `color`, so it inherits regardless;
     - harmful, because --none and --media-cover can be the SAME tile. Both rules are
       one class, this one comes later, so `inherit` beat the cover rule's white and
       the tile rendered black body text on a dark photograph. The headline, CTA and
       chips stayed white because they read --bs-heading-color / --q4u-bento-fg
       directly, which made it look like a partial failure rather than a cascade
       order problem. */
.q4u-bento__tile--none {
    background-color: transparent;
    /* The `inherit` fallback is the whole safety of this: with no --q4u-bento-fg
       declared — the ordinary case, a tile on the page — these resolve exactly as
       they did before the rules above existed. */
    color: var(--q4u-bento-fg, inherit);
    --bs-body-color: var(--q4u-bento-fg, inherit);
    --bs-heading-color: var(--q4u-bento-fg, inherit);
    --bs-emphasis-color: var(--q4u-bento-fg, inherit);
}

/* ── Spacer ────────────────────────────────────────────────────────────────
   Deliberate whitespace placed by an editor. Occupies its cells and nothing
   else. The markup already carries aria-hidden and holds no focusable content. */

.q4u-bento__tile--spacer {
    background: none;
    border: 0;
    padding: 0;
    pointer-events: none;
}

/* ── Category chips ──────────────────────────────────────────────────────
   The tile's FIRST child, on a line of its own, with the kicker below it.

   First child is what makes the offset unconditional: nothing optional sits above
   the chips, so they start at the tile's own padding on every tile — no "unless
   there is a kicker", no "unless there is a CTA". Two earlier designs anchored them
   to the lead and then to the CTA, and both moved.

   NOWRAP is the other half, and the easy one to miss. A wrapping chip row is 23, 46
   or 81px tall depending on how many categories an editor picked, so a fixed offset
   on its own still leaves the headline below it at a different height per tile.
   Overflow clips instead.

   min-height is derived, not chosen: 12px x 1.35 line-height = 16.2, plus 2 x 2.4px
   padding, plus 2 x 1px border = 23px. The floor keeps the row — and therefore
   everything under it — the same height whether it holds one chip or six.

   The mask is self-gating: it fades the last 24px, which is invisible until content
   actually reaches that far. No JS, no container query, no "+N more" counter.

   Outlined and not filled: an outline leaves the label on the tile background, whose
   contrast against --q4u-bento-fg is already measured, so the chips inherit that
   guarantee instead of reopening six colour x shade combinations plus `cover`.
   currentColor as the fallback covers the --none tile, which declares no token.

   0.75rem is this project's 12px minimum font size. */

.q4u-bento__cats {
    position: relative;
    z-index: 1;
    display: flex;
    flex: 0 0 auto;
    flex-wrap: nowrap;
    align-items: center;
    gap: 0.375rem;
    min-height: 1.4375rem;
    list-style: none;
    margin: 0 0 var(--q4u-bento-group-gap);
    padding: 0;
    min-width: 0;
    overflow: hidden;
    mask-image: linear-gradient(to right, #000 calc(100% - 1.5rem), transparent);
}

/* flex: 0 0 auto matters. The default flex-shrink: 1 would squeeze the pills in a
   nowrap row and push their text out past the border. Overflow is handled by
   clipping the row, not by deforming the chips. */
.q4u-bento__cat {
    flex: 0 0 auto;
    max-width: 100%;
    font-size: 0.75rem;
    line-height: 1.35;
    padding: 0.15rem 0.55rem;
    border: 1px solid color-mix(in srgb, var(--q4u-bento-fg, currentColor) 40%, transparent);
    border-radius: 999px;
    color: var(--q4u-bento-fg, inherit);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Call to action ────────────────────────────────────────────────────── */

/* Last child of the tile, so margin-top: auto pins it to the bottom edge with
   nothing optional in between — the CTA is now as positionally stable as the meta
   row, for the same reason. */
.q4u-bento__cta-wrap {
    position: relative;
    z-index: 1;
    margin: auto 0 0;
    padding-top: 1rem;
}

.q4u-bento__cta {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    color: inherit;
    font-weight: 500;
    text-decoration: none;
    transition: gap 140ms cubic-bezier(0.16, 1, 0.3, 1);
}

.q4u-bento__cta::after {
    content: "→";
}

.q4u-bento__cta:hover {
    gap: 0.65rem;
    color: inherit;
}

.q4u-bento__cta:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 3px;
}

/* Whole-tile click target. One anchor in the DOM, no nested links, focus lands on
   the CTA. z-index clears both the body (1) and a cover image (0).
   A link inside the RTE lead would sit underneath this layer — that is what the
   "Ganze Kachel verlinken" toggle is for. */
.q4u-bento__cta--stretched::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 3;
}

/* ── Media ─────────────────────────────────────────────────────────────────
   --focal-pos is written on the figure by the focalPoint ViewHelper.
   <t3bc:picture> emits imgproxy URLs at the image's natural aspect ratio, so the
   crop happens in the browser via object-fit and would otherwise be centred. */

.q4u-bento__media {
    margin: 0;
    min-width: 0;
}

.q4u-bento__media img {
    display: block;
    max-width: 100%;
    height: auto;
    /* The host theme rounds every content image — measured 1.99995rem, about 32px —
       and that fought the tile's own 16px corner: the image curved in further than
       the tile did and left a wedge of tile background showing at each corner of a
       cover image. Rounding belongs to the box that clips, which is the figure for
       inline and fill, and the tile itself for cover.

       !important because the theme's rule is

         .page-main img:not(.card-img):not(.card-img-top) … ten :not() in total

       at roughly (0,11,2). That is the same specificity-bomb pattern as its link
       rule, and no sane selector here outranks it — a plain .q4u-bento__media img
       is (0,1,1) and loses silently, which is exactly how this shipped.

       The cleaner fix lives in q4u_base: add .q4u-bento__media img to that :not()
       chain, as the card contexts already are, and this !important can go. */
    border-radius: 0 !important;
}

/* `inline` and `fill` share ONE box. Both take the height the text leaves over, and
   neither changes the tile's footprint — the preset decides that, which is the point
   of the whole grid. They differ in one property, object-fit:

     inline  contain  the whole image, never cropped, letterboxed if it must be
     fill    cover    cropped to the editor's focal point, fills the box

   `inline` used to sit in the flow at its natural ratio, which grew the tile and with
   it the entire grid row — measured on the demo, a portrait photo took a one-row tile
   from 200px to 384px and stretched every tile beside it. It keeps its promise of
   showing the whole image; it no longer gets to resize the mosaic to do so.

   No min-height: a floor on this figure is a floor on the TILE. 120px of it pushed a
   one-row tile with a two-line lead to 280px, taking its grid row along. A tile whose
   text leaves little room gets a small image — that is the mode working, and an
   editor who wants a large one picks a two-row preset or `cover`. */
.q4u-bento__media--inline,
.q4u-bento__media--fill {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    margin-top: 1rem;
    overflow: hidden;
    border-radius: 0.75rem;
}

/* Cover: the image is the tile. Absolute, so DOM order never has to vary. */
.q4u-bento__media--cover {
    position: absolute;
    inset: 0;
    z-index: 0;
    margin: 0;
}

/* COLOUR AND DARKENING ARE TWO SEPARATE LAYERS, on purpose.

   The first attempt mixed the tile colour into the black scrim. That cannot work:
   mixing changes the scrim's LUMINANCE, which is the one thing holding the text up,
   so colour and legibility fought each other. Measured across all six variants in
   both modes, the worst-case ratio by colour share was 6.98 / 4.82 / 3.83 / 2.78 /
   2.50 / 2.50 / 2.83 for 0 / 15 / 25 / 40 / 60 / 80 / 100% — non-monotonic, worst in
   the middle, and 60-80% unreachable at ANY opacity. A themed image was not
   obtainable that way.

   mix-blend-mode: color takes the hue and saturation of this layer and keeps the
   BACKDROP's luminance. The photograph becomes pink and stays as light or dark as it
   was, so the darkening layer's arithmetic is untouched: it is the same pure-black
   scrim whose floor was derived against a white photo, and the two controls are now
   genuinely independent.

   isolation: isolate on the figure keeps the blend inside the media box — without it
   the colour layer blends with the tile's own background too. */

.q4u-bento__media--cover {
    isolation: isolate;
}

/* Layer 1 — the hue. Opacity is the editor's "colour" setting, and because the blend
   preserves luminance it carries no contrast cost at any value. */
.q4u-bento__media--cover::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 1;
    background: var(--q4u-bento-bg, transparent);
    mix-blend-mode: color;
    opacity: var(--q4u-bento-scrim-tint, 0.15);
    pointer-events: none;
}

/* Layer 2 — the darkening, pure black, dark at BOTH ends because a tile's chips,
   kicker and headline sit at the top and its CTA at the bottom. An earlier version
   ran `to top`, leaving 0.15 at the top where the headline starts 29px down.

   The floor is derived: against a pure white photograph white text needs 4.5:1, so
   the composited backdrop must stay at or below sRGB 119, and 255 * (1 - a) <= 119
   gives a >= 0.53. The lightest stop is 0.55.

   Ends capped at 0.95, not 1: at the strongest setting min(1, 0.90 + 0.17) made them
   fully opaque and the photograph vanished behind them, which is not a darker image
   but no image.

   contrast-color() cannot replace this. A photograph is not a colour, and nothing in
   CSS can tell how light the pixels behind a given word are. */
.q4u-bento__media--cover::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 2;

    /* Both stops come from ScrimViewHelper, which owns the two edge cases: the ends
       are capped at 95 so the photograph never disappears completely, and they stay
       at 0 when the darkening is 0, so "none" really means none. Deriving them here
       with calc(min(...)) got the second one wrong. */
    background: var(--q4u-bento-scrim, linear-gradient(
        to bottom,
        color-mix(in srgb, #000 calc(var(--q4u-bento-scrim-end, 0.82) * 100%), transparent) 0%,
        color-mix(in srgb, #000 calc(var(--q4u-bento-scrim-opacity, 0.65) * 100%), transparent) 50%,
        color-mix(in srgb, #000 calc(var(--q4u-bento-scrim-end, 0.82) * 100%), transparent) 100%
    ));
}


/* BOTH the <picture> and the <img> are taken out of flow.

   The <img> alone is not enough, and this is the trap: with the picture left in
   flow as `width: 100%; height: 100%`, Chrome sizes it from the image's intrinsic
   ratio against its own width — measured here, 356px wide × 2097/1400 = 533px tall,
   for an image whose only child was already absolute. That height then propagated
   figure → tile → grid row, and a single `fill` tile stretched its row from 200px
   to 693px. The mode promises to fill the tile; it must never resize it.

   Verified by elimination: hiding the <picture> returned the row to its natural
   height, hiding only the <img> did not. */
.q4u-bento__media--inline picture,
.q4u-bento__media--fill picture,
.q4u-bento__media--cover picture {
    display: block;
    position: absolute;
    inset: 0;
    /* Redundant against inset: 0 for the used height, but NOT redundant as a
       percentage basis: without an explicit height the <img>'s own height: 100%
       resolves to auto and the image falls back to its intrinsic ratio, covering
       only part of the tile. */
    width: 100%;
    height: 100%;
}

.q4u-bento__media--inline img,
.q4u-bento__media--fill img,
.q4u-bento__media--cover img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

/* Cropped: the focal point decides which part survives. */
.q4u-bento__media--fill img,
.q4u-bento__media--cover img {
    object-fit: cover;
    object-position: var(--focal-pos, 50% 50%);
}

/* Not cropped, so there is nothing for a focal point to choose and the image stays
   centred in its letterbox. */
.q4u-bento__media--inline img {
    object-fit: contain;
    object-position: 50% 50%;
}

/* ── Reveal animation ──────────────────────────────────────────────────────
   Driven by bento-reveal.js, which adds .q4u-bento--reveal to the grid and then
   .is-revealed per tile as it enters the viewport. Without JavaScript the class
   is never added and every tile is simply visible, so this is additive only.

   Replaces a load-time animation whose nth-child delays stopped at the eighth
   tile and which finished before a grid below the fold was ever scrolled to. */

@media (prefers-reduced-motion: no-preference) {
    /* The :not() must match the script's own selector exactly. bento-reveal.js
       never observes a spacer — there is nothing in one to reveal — so a spacer
       covered by this rule would keep opacity: 0 and the 16px offset forever. */
    .q4u-bento--reveal .q4u-bento__tile:not(.q4u-bento__tile--spacer) {
        opacity: 0;
        transform: translateY(16px);
        transition:
            opacity 520ms cubic-bezier(0.16, 1, 0.3, 1),
            transform 520ms cubic-bezier(0.16, 1, 0.3, 1);
        transition-delay: var(--q4u-bento-delay, 0ms);
    }

    .q4u-bento--reveal .q4u-bento__tile.is-revealed {
        opacity: 1;
        transform: none;
    }
}

/* ── Published utilities ───────────────────────────────────────────────────
   Kept because a host site may use them in its own markup, although nothing in
   this extension does any more. */

.font-display   { font-family: var(--q4u-bento-font-display, inherit); }
.tracking-tight { letter-spacing: -0.025em; }
.tracking-mono  { letter-spacing: 0.04em; }

.bg-tertiary-subtle {
    background-color: var(--bs-tertiary-bg-subtle, #f3f1ed) !important;
    background-color: color-mix(in srgb, rgb(var(--bs-tertiary-rgb, 205, 197, 192)) 20%, white) !important;
}
