/*
 * CONTENT BLOCK HERO (cb_hero)
 * Page headline (h1) with subline on a background of the palette or an image, as wide as main (page max width, like
 * the hero image of the hero section), the content with the page padding. Optional stamp: circle with text (and link)
 * at the bottom right.
 *
 * Like the hero section of records (see HeroSection.css), two clamps cut a right triangle from the background,
 * right angle top left and bottom right, height --cb-hero--clamp. Clamp and stamp scale fluidly with the element
 * width from 375px (40px clamp, 120px stamp) to 1280px (80px clamp, 188px stamp, see _redesign).
 *
 * Without image (design B3): content on yellow, or on light blue (.cb-hero--light-blue). Mobile first: the stamp below the content, aligned right and reaching
 * into the bottom clamp. From 48rem element width on it is placed at the bottom right, next to the content. Sub pages
 * (design 261118): lower, the content vertically centered, the stamp like on the start page.
 *
 * With image (.cb-hero--image, design 261105): a light grey band of fixed height (--cb-hero--band), cut by the clamps.
 * The image keeps its own aspect ratio (free crop variant "hero", see ImageFormat::HERO), it is as high as the band
 * and centered. Images wider than the band are cut by object-fit around the focus area of the crop, images nearly as
 * wide as the band fill it (.image--fill, see ImageFormat::HERO_FILL_RATIO) and are cut at the top and bottom. Content
 * (headline, subline) below the band, the stamp at the bottom right of the band.
 *
 * The stamp (B5) has the variants outline bold (border 4px), outline regular (border 2px) and filled with a surface
 * (.surface--light-blue, .surface--yellow, see variables.css).
 *
 * The hero of record detail views and pages with image (.record-hero, see Partials/Layout/RecordHero) uses these
 * styles, so it has the same proportions: yellow with the title, or the band with the image without content (title
 * below the hero, the h1 of the page).
 *
 * Accessibility
 * - Text colors per background with a contrast of at least 4.5:1 (see variables.css), no text on images
 * - The stamp has a border, so it stays visible on the page background and in forced colors mode
 * - A stamp without link is hidden from screen readers (aria-hidden, see the templates), with link it is a regular link
 */

/* Record hero: container of the hero like the content element of cb_hero (see BaseContentElement.css) */
.record-hero {
    container: content-element / inline-size;
}

.cb-hero {
    /* Same clamp as the hero section with breadcrumbs above the hero (see HeroSection.css) */
    --cb-hero--clamp     : clamp(2.5rem, 1.464rem + 4.42cqi, 5rem);
    --cb-hero--stamp     : clamp(7.5rem, 5.739rem + 7.514cqi, 11.75rem);
    --cb-hero--gap       : var(--layout--gap--large);
    /* 420px, grows with the content */
    --cb-hero--min-height: 26.25rem;
    --cb-hero--background: var(--color--yellow);
    --cb-hero--color     : var(--color--dark-grey);

    position: relative;
    isolation: isolate;
    max-width: var(--page-max);
    margin-inline: auto;
    /* Distance to the following content, which would start right at the bottom clamp otherwise */
    margin-bottom: var(--layout--gap--large);
    color: var(--cb-hero--color);
}

/* Background color without image (field background_color), dark grey text on it (contrast 17.24:1) */
.cb-hero--light-blue {
    --cb-hero--background: var(--color--light-blue);
}

/* Contrast mode: white on black like all surfaces (see variables.css), also the headline below the band of the image */
:root[data-contrast-mode="active"] .cb-hero {
    --cb-hero--background: #000000;
    --cb-hero--color     : #FFFFFF;
}

/*
 * Sub pages (and records) without image (design 261118): lower than on the start page (373px instead of 420px min
 * height), the content vertically centered on the visible left edge: the top clamp cuts it, so it runs from the clamp
 * height down to the bottom and its middle lies half a clamp below the middle of the element. The top padding is one
 * clamp larger than the bottom one, which moves the middle of the content box there. Padding: the clamp plus a small
 * gap, so longer content (wrapped headline, subline) keeps clear of the clamps and grows the hero.
 */
body:not(.page-layout--frontpage) .cb-hero:not(.cb-hero--image) {
    --cb-hero--min-height: 23.3125rem;
}

body:not(.page-layout--frontpage) .cb-hero:not(.cb-hero--image) .cb-hero__inner {
    justify-content: center;
    padding-top: calc(2 * var(--cb-hero--clamp) + var(--layout--gap--small));
    padding-bottom: calc(var(--cb-hero--clamp) + var(--layout--gap--small));
}

/* Mobile with stamp: content at the top, the stamp below it at the bottom (in the flow, see below) */
body:not(.page-layout--frontpage) .cb-hero--has-stamp:not(.cb-hero--image) .cb-hero__inner {
    justify-content: space-between;
}


/* BACKGROUND: behind the content, cut by the clamps */

.cb-hero__background {
    position: absolute;
    inset: 0;
    z-index: -1;
    overflow: hidden;
    background-color: var(--cb-hero--background);
    clip-path: polygon(
        0 var(--cb-hero--clamp),
        100% 0,
        100% calc(100% - var(--cb-hero--clamp)),
        0 100%
    );
}


/*
 * WITH IMAGE (design 261105): grid of the band (row 1) and the content (row 2). The inner wrapper is no box, so the
 * content is placed below the band and the stamp on the band. Band height 210px below, from 48rem element
 * width on 420px on the start page and 373px on sub pages (see heights of the image in the templates, keep them in
 * sync).
 */
.cb-hero--image {
    --cb-hero--band      : 13.125rem;
    --cb-hero--background: var(--color--light-grey);

    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: var(--cb-hero--band) auto;
}

/* With content (cb_hero) the distance to the main content is the one of the page title (see layout.css) */
.cb-hero--image:has(.cb-hero__content) {
    margin-bottom: var(--layout--gap--default);
}

/* The band is a container, its width is the reference of the clamps for the copyright (see below) */
.cb-hero--image .cb-hero__background {
    container: cb-hero-band / inline-size;
    position: relative;
    inset: auto;
    z-index: auto;
    grid-area: 1 / 1;
    display: flex;
    justify-content: center;
}

.cb-hero--image .cb-hero__inner {
    display: contents;
}

/*
 * Figure as high as the band and as wide as the image, at most as wide as the band. The image (.image--free, see
 * base.css) gets its width from its aspect ratio, wider images are cut around the focus area of the crop.
 */
.cb-hero__figure {
    position: relative;
    flex: 0 1 auto;
    min-width: 0;
    height: 100%;
    margin: 0;
}

.cb-hero__figure .cb-hero__image {
    width: auto;
    height: 100%;
}

/*
 * Images nearly as wide as the band (.image--fill, see ImageFormat::HERO_FILL_RATIO) fill it instead of leaving narrow
 * grey margins, cut at the top and bottom around the focus area of the crop (object-fit of .image--free).
 */
.cb-hero__figure:has(.image--fill) {
    flex: 1 1 100%;
}

.cb-hero__figure .cb-hero__image.image--fill {
    width: 100%;
}

/*
 * Copyright of the image (see base.css): at the bottom left of the image, always the same distance (padding) above the
 * bottom clamp. The clamp cuts the band from its bottom left corner up to the clamp height at the right, so the cut is
 * clamp × x / band width above the bottom at the position x in the band. The distance is measured at the right edge
 * of the button, where the cut under it is highest.
 * x = (band width - image width) / 2 + left + button size, image width = min(band width, band height × ratio of the
 * image, --image-ratio of the figure, see ImageRatioViewHelper). The band width is resolved on the figure (registered
 * length, 100cqi of the band container). Lengths can't be divided, the slope clamp / band width is tan(atan2()).
 */
@property --cb-hero--band-width {
    syntax: "<length>";
    inherits: true;
    initial-value: 0px;
}

.cb-hero__figure {
    --cb-hero--band-width: 100cqi;
}

.cb-hero__copyright {
    --copyright--left  : var(--padding--default);
    --cb-hero--copyright-x: calc(
        (var(--cb-hero--band-width) - min(var(--cb-hero--band-width), var(--cb-hero--band) * var(--image-ratio, 1))) / 2
        + var(--copyright--left) + var(--copyright--size)
    );
    --copyright--bottom: calc(
        var(--cb-hero--copyright-x) * tan(atan2(var(--cb-hero--clamp), var(--cb-hero--band-width)))
        + var(--padding--default)
    );
}

/* Image filling the band: it starts at the left edge of the band */
.cb-hero__figure:has(.image--fill) .cb-hero__copyright {
    --cb-hero--copyright-x: calc(var(--copyright--left) + var(--copyright--size));
}

/* Content below the band, with the distance of the page title to the hero (see Page layout) */
.cb-hero--image .cb-hero__content {
    grid-area: 2 / 1;
    max-width: calc(50rem + 2 * var(--page-pad));
    padding: var(--layout--gap--large) var(--page-pad) 0;
}

/*
 * Stamp at the bottom right of the band (on the bottom clamp), at all widths. A grid item in the cell of the band, as
 * absolute positioning would refer to the whole hero (the parent .cb-hero__inner is no box).
 */
.cb-hero--image .cb-hero__stamp {
    position: relative;
    right: auto;
    bottom: auto;
    grid-area: 1 / 1;
    align-self: end;
    justify-self: end;
    margin: 0 var(--page-pad) 0 0;
	transform: rotate(-7deg);
}


/* CONTENT: headline and subline, the padding keeps them out of the clamps */

/* Mobile the stamp is pushed to the bottom of the min height, into the bottom clamp */
.cb-hero__inner {
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: var(--cb-hero--gap);
    min-height: var(--cb-hero--min-height);
    max-width: var(--page-max);
    margin-inline: auto;
    padding: calc(var(--cb-hero--clamp) + var(--cb-hero--gap)) var(--page-pad);
}

.cb-hero__content {
    max-width: 50rem;
}

/* Lead size, but not bold (unlike .text--lead) */
.cb-hero__subline {
    margin-top: var(--layout--gap--small);
    font-weight: var(--font-weight--regular);
}


/* STAMP: circle with text in the headline font, rotated by 7deg, the text stays within 90% of the circle */

.cb-hero__stamp {
    display: grid;
    place-items: center;
    align-self: flex-end;
    flex-shrink: 0;
    width: var(--cb-hero--stamp);
    height: var(--cb-hero--stamp);
    margin-bottom: calc(-1 * var(--cb-hero--clamp));
    /* 5% of the circle, a percentage would refer to the width of the hero */
    padding: calc(var(--cb-hero--stamp) * .05);
    border: var(--border-width--strong) solid var(--color--dark-grey);
    border-radius: 50%;
    background-color: var(--color--white);
    color: var(--color--dark-grey);
    font-family: var(--font-family--headline);
    font-size: var(--font-size--badge--large);
    font-weight: var(--font-weight--bold);
    line-height: var(--line-height--badge--large);
    text-align: center;
    hyphens: auto;
    overflow-wrap: anywhere;
}

.cb-hero__stamp__text {
    display: block;
    /* Moved down by .1em: the font leaves space below the baseline, so the ink is centered in the circle */
    transform: translateY(.1em) rotate(-7deg);
}

/*
 * Long texts (more than 12 or 30 characters, see the templates): smaller font relative to the circle, at most the
 * default size. The default size follows the viewport, the circle the element width, so without it long texts (and the
 * arrow of a link) run out of small circles. Horizontal, several rotated lines in a small font look restless.
 */
.cb-hero__stamp--long {
    font-size: min(var(--font-size--badge--large), var(--cb-hero--stamp) * .13);
    line-height: 1;
}

.cb-hero__stamp--very-long {
    font-size: min(var(--font-size--badge--large), var(--cb-hero--stamp) * .1);
    line-height: 1;
}

:is(.cb-hero__stamp--long, .cb-hero__stamp--very-long) .cb-hero__stamp__text {
    transform: translateY(.1em);
}

.cb-hero__stamp--outline-regular {
    border-width: var(--border-width--default);
    font-weight: var(--font-weight--regular);
}

/* Filled with the surface (background and text color), the transparent border stays visible in forced colors mode */
.cb-hero__stamp--filled {
    border-color: transparent;
    background-color: var(--surface--background);
    color: var(--surface--text);
}

/* Stamp filled with the background color: dark outline, otherwise the stamp is invisible */
:is(.cb-hero--yellow .cb-hero__stamp--filled.surface--yellow, .cb-hero--light-blue .cb-hero__stamp--filled.surface--light-blue) {
    border-color: var(--color--dark-grey);
}

/* Arrow below the text of a linked stamp, decorative (not read by screen readers), drawn in the text color */
.cb-hero__stamp--link .cb-hero__stamp__text::after {
    content: "";
    display: block;
    width: 1.25em;
    height: 1.25em;
    margin: .25em auto 0;
    background-color: currentColor;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='black' stroke-width='1.5' stroke-linecap='butt' stroke-linejoin='miter'%3E%3Cpath d='M2 8h10M9 4l4 4-4 4'/%3E%3C/svg%3E") center / contain no-repeat;
}

.cb-hero__stamp--link {
    text-decoration: none;
}

.cb-hero__stamp--link:hover .cb-hero__stamp__text {
    text-decoration: underline;
    text-underline-offset: .15em;
}

/* Backgrounds are replaced in forced colors mode, keep the arrow in the link color */
@media (forced-colors: active) {
    .cb-hero__stamp--link .cb-hero__stamp__text::after {
        forced-color-adjust: none;
        background-color: LinkText;
    }
}


@container content-element (min-width: 48rem) {
    .cb-hero--image {
        --cb-hero--band: 26.25rem;
    }

    /* Sub pages (and records): 373px, the same height on all sub pages */
    body:not(.page-layout--frontpage) .cb-hero--image {
        --cb-hero--band: 23.3125rem;
    }

    /* Start page: the content is indented, it starts 143px from the left edge of the hero */
    .page-layout--frontpage :is(.cb-hero__inner, .cb-hero--image .cb-hero__content) {
        padding-left: 8.9375rem;
    }

    /*
     * Stamp at the bottom right of the content area, the content keeps its width free (yellow, content beside it), on
     * the start page and in the small banner of sub pages.
     */
    .cb-hero--has-stamp:not(.cb-hero--image) .cb-hero__inner {
        min-height: max(var(--cb-hero--min-height), var(--cb-hero--stamp) + var(--cb-hero--clamp) + var(--cb-hero--gap));
    }

    .cb-hero--has-stamp:not(.cb-hero--image) .cb-hero__content {
        max-width: min(50rem, 100% - var(--cb-hero--stamp) - var(--cb-hero--gap));
    }

    /* Sub pages: the stamp is out of the flow, the content vertically centered again */
    body:not(.page-layout--frontpage) .cb-hero--has-stamp:not(.cb-hero--image) .cb-hero__inner {
        justify-content: center;
    }

    /* Bottom of the stamp flush with the (invisible) bottom of the hero (design B3, B4) */
    .cb-hero__stamp {
        position: absolute;
        right: var(--page-pad);
        bottom: 0;
        margin: 0;
    }
}
