/* MCMS2 tiles widgets [tiles] / [tile] (SPEC §7). Loaded only on pages with tiles, before the theme's stylesheet.
   Themes change the look with these variables (on .mcms-tiles or higher):
   --mcms-tiles-accent  colour of the bar, link text and tiles without a picture (default: the theme's --accent)
   --mcms-tiles-radius  corner radius        --mcms-tiles-gap   space between tiles
   --mcms-tiles-bg      card background      --mcms-tiles-line  card border
   --mcms-tiles-min     narrowest tile when the number of columns is automatic
   --mcms-tiles-w       (set by the widget) own tile width — "Own size (pixels)" */

.mcms-tiles {
    --mcms-tiles-a: var(--mcms-tiles-accent, var(--accent, #2f6f5e));
    --mcms-tiles-r: var(--mcms-tiles-radius, var(--radius, 8px));
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, var(--mcms-tiles-min, 230px)), 1fr));
    gap: var(--mcms-tiles-gap, 1.4em);
    margin: 1.6em 0;
    padding: 0;
}
.mcms-tiles-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.mcms-tiles-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.mcms-tiles-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 860px) { .mcms-tiles-cols-4 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 680px) { .mcms-tiles-cols-3, .mcms-tiles-cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 440px) { .mcms-tiles[class*="mcms-tiles-cols-"] { grid-template-columns: minmax(0, 1fr); } }
/* own size in pixels: every tile keeps that width (smaller only on a narrower screen), the picture keeps its shape */
.mcms-tiles-fixed { grid-template-columns: repeat(auto-fill, min(100%, var(--mcms-tiles-w))); --mcms-tiles-width: var(--mcms-tiles-w); }

/* centred / right-aligned ([tiles align=…] or a centred / right paragraph in the editor): the tiles keep their width
   and an incomplete row is centred (or pushed right), instead of stretching or leaving empty columns.
   Tile width: the column width for 2–4 columns; for "as many as fit" --mcms-tiles-width (default 1.25 × the minimum). */
.mcms-tiles-align-center, .mcms-tiles-align-right {
    --mcms-tiles-n: 0;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
}
.mcms-tiles-align-right { justify-content: flex-end; }
.mcms-tiles-align-center > .mcms-tile, .mcms-tiles-align-right > .mcms-tile {
    flex: 0 1 auto;
    width: min(100%, var(--mcms-tiles-width, calc(var(--mcms-tiles-min, 230px) * 1.25)));
}
.mcms-tiles-align-center.mcms-tiles-cols-2, .mcms-tiles-align-right.mcms-tiles-cols-2 { --mcms-tiles-n: 2; }
.mcms-tiles-align-center.mcms-tiles-cols-3, .mcms-tiles-align-right.mcms-tiles-cols-3 { --mcms-tiles-n: 3; }
.mcms-tiles-align-center.mcms-tiles-cols-4, .mcms-tiles-align-right.mcms-tiles-cols-4 { --mcms-tiles-n: 4; }
@media (max-width: 860px) { .mcms-tiles-align-center.mcms-tiles-cols-4, .mcms-tiles-align-right.mcms-tiles-cols-4 { --mcms-tiles-n: 3; } }
@media (max-width: 680px) { .mcms-tiles-align-center[class*="mcms-tiles-cols-"], .mcms-tiles-align-right[class*="mcms-tiles-cols-"] { --mcms-tiles-n: 2; } }
@media (max-width: 440px) { .mcms-tiles-align-center[class*="mcms-tiles-cols-"], .mcms-tiles-align-right[class*="mcms-tiles-cols-"] { --mcms-tiles-n: 1; } }
.mcms-tiles-align-center[class*="mcms-tiles-cols-"] > .mcms-tile, .mcms-tiles-align-right[class*="mcms-tiles-cols-"] > .mcms-tile {
    width: calc((100% - (var(--mcms-tiles-n) - 1) * var(--mcms-tiles-gap, 1.4em)) / var(--mcms-tiles-n));
}

/* ---- a tile: the whole tile is the link (the title link is stretched over it) ---- */
.mcms-tile {
    position: relative;
    display: flex;
    flex-direction: column;
    min-width: 0;
    margin: 0;
    border-radius: var(--mcms-tiles-r);
    overflow: hidden;
    background: var(--mcms-tiles-bg, rgba(127, 127, 127, .07));
    box-shadow: inset 0 0 0 1px var(--mcms-tiles-line, rgba(127, 127, 127, .2)), 0 1px 2px rgba(0, 0, 0, .06);
    transition: transform .35s cubic-bezier(.2, .7, .2, 1), box-shadow .35s ease;
    isolation: isolate;
}
.mcms-tile:hover, .mcms-tile:focus-within {
    transform: translateY(-5px);
    box-shadow: inset 0 0 0 1px transparent, 0 14px 34px -10px rgba(0, 0, 0, .35), 0 4px 10px -4px rgba(0, 0, 0, .18);
}
.mcms-tile-title a::after { content: ""; position: absolute; inset: 0; z-index: 3; border-radius: inherit; }
.mcms-tile-title a:focus-visible { outline: none; }
.mcms-tile:focus-within .mcms-tile-title a::after { outline: 3px solid var(--mcms-tiles-a); outline-offset: 2px; }
.mcms-tile.is-hidden { opacity: .45; }

/* picture */
.mcms-tile-pic {
    position: relative;
    aspect-ratio: var(--mcms-tiles-ratio, 4 / 3);
    overflow: hidden;
    background: rgba(127, 127, 127, .14);
}
.mcms-tile-pic img {
    display: block;
    width: 100%;
    height: 100%;
    max-width: none;
    object-fit: cover;
    border: 0;
    border-radius: 0;
    margin: 0;
    padding: 0;
    box-shadow: none;
    transition: transform .8s cubic-bezier(.2, .7, .2, 1), filter .5s ease;
}
.mcms-tile:hover .mcms-tile-pic img, .mcms-tile:focus-within .mcms-tile-pic img { transform: scale(1.07); }

/* no picture: a coloured tile with the first letter of the title */
.mcms-tile.no-pic .mcms-tile-pic {
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--mcms-tiles-a);
    background-image:
        radial-gradient(circle at 18% 12%, rgba(255, 255, 255, .28), transparent 55%),
        radial-gradient(circle at 85% 95%, rgba(0, 0, 0, .3), transparent 60%),
        repeating-linear-gradient(135deg, rgba(255, 255, 255, .05) 0 2px, transparent 2px 14px);
}
.mcms-tile-initial {
    font-size: 4.2em;
    line-height: 1;
    color: #fff;
    opacity: .9;
    text-shadow: 0 2px 12px rgba(0, 0, 0, .25);
    transition: transform .6s cubic-bezier(.2, .7, .2, 1);
}
.mcms-tile:hover .mcms-tile-initial { transform: scale(1.12) rotate(-4deg); }

/* text */
.mcms-tile-body { display: flex; flex-direction: column; flex: 1; gap: .45em; padding: 1em 1.15em 1.15em; }
.mcms-tile-title { margin: 0; font-size: 1.12em; line-height: 1.3; }
.mcms-tile-title a, .mcms-tile-title span { color: inherit; text-decoration: none; }
.mcms-tile-text {
    margin: 0;
    font-size: .92em;
    line-height: 1.55;
    opacity: .78;
    white-space: pre-line;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 4;
    overflow: hidden;
}
.mcms-tile-more {
    margin-top: auto;
    padding-top: .35em;
    display: inline-flex;
    align-items: center;
    gap: .55em;
    font-size: .85em;
    letter-spacing: .04em;
    color: var(--mcms-tiles-a);
}
.mcms-tile-more::after {   /* arrow drawn with CSS */
    content: "";
    width: .5em;
    height: .5em;
    border-top: 2px solid currentColor;
    border-right: 2px solid currentColor;
    transform: rotate(45deg);
    transition: transform .3s ease;
}
.mcms-tile:hover .mcms-tile-more::after { transform: translateX(.35em) rotate(45deg); }

/* card style: accent bar that grows under the picture (on the picture's bottom edge: the text block must not be
   positioned, or the stretched title link would cover only the text instead of the whole tile) */
.mcms-tiles-card .mcms-tile-pic::after {
    content: "";
    position: absolute;
    left: 0;
    bottom: 0;
    z-index: 1;
    height: 3px;
    width: 100%;
    background: var(--mcms-tiles-a);
    transform: scaleX(0);
    transform-origin: left;
    transition: transform .45s cubic-bezier(.2, .7, .2, 1);
}
.mcms-tiles-card .mcms-tile:hover .mcms-tile-pic::after,
.mcms-tiles-card .mcms-tile:focus-within .mcms-tile-pic::after { transform: scaleX(1); }

/* ---- overlay style: text on the picture ---- */
.mcms-tiles-overlay .mcms-tile { background: #222; color: #fff; display: grid; }   /* picture and text in one cell */
.mcms-tiles-overlay .mcms-tile-pic { grid-area: 1 / 1; }
.mcms-tiles-overlay .mcms-tile-pic { aspect-ratio: var(--mcms-tiles-ratio, 4 / 3); }
.mcms-tiles-overlay .mcms-tile-pic::after {   /* shade for the text; darkens the whole picture while the text is shown */
    content: "";
    position: absolute;
    inset: 0;
    background-color: rgba(0, 0, 0, 0);
    background-image: linear-gradient(to top, rgba(0, 0, 0, .88) 0%, rgba(0, 0, 0, .5) 35%, rgba(0, 0, 0, 0) 68%);
    transition: background-color .45s ease;
}
.mcms-tiles-overlay .mcms-tile:hover .mcms-tile-pic::after,
.mcms-tiles-overlay .mcms-tile:focus-within .mcms-tile-pic::after { background-color: rgba(0, 0, 0, .5); }
.mcms-tiles-overlay .mcms-tile-body {   /* not positioned: the stretched title link must cover the whole tile */
    grid-area: 1 / 1;
    align-self: end;
    min-width: 0;
    z-index: 2;
    padding: 1.1em 1.2em 1.2em;
    gap: 0;
}
.mcms-tiles-overlay .mcms-tile-title { font-size: 1.2em; color: #fff; text-shadow: 0 1px 8px rgba(0, 0, 0, .45); }   /* white also where the theme colours headings */
.mcms-tiles-overlay .mcms-tile-title a, .mcms-tiles-overlay .mcms-tile-title a:hover, .mcms-tiles-overlay .mcms-tile-title a:focus { color: #fff; }   /* …and links on hover */
.mcms-tiles-overlay .mcms-tile-text { color: #fff; text-shadow: 0 1px 6px rgba(0, 0, 0, .5); -webkit-line-clamp: 3; }   /* 3 lines: the title stays on small tiles */
.mcms-tiles-overlay .mcms-tile-title::after {   /* short accent line under the title, grows on hover */
    content: "";
    display: block;
    width: 2.2em;
    height: 3px;
    margin-top: .5em;
    background: var(--mcms-tiles-a);
    transition: width .45s cubic-bezier(.2, .7, .2, 1);
}
.mcms-tiles-overlay .mcms-tile:hover .mcms-tile-title::after { width: 4.5em; }
.mcms-tiles-overlay .mcms-tile-text,
.mcms-tiles-overlay .mcms-tile-more {
    max-height: 0;
    opacity: 0;
    transform: translateY(.6em);
    transition: max-height .45s ease, opacity .35s ease, transform .45s ease, margin .45s ease, padding .45s ease;
}
.mcms-tiles-overlay .mcms-tile-more { color: #fff; padding-top: 0; }
.mcms-tiles-overlay .mcms-tile:hover .mcms-tile-text,
.mcms-tiles-overlay .mcms-tile:focus-within .mcms-tile-text { max-height: 7em; opacity: 1; transform: none; margin-top: .6em; }
.mcms-tiles-overlay .mcms-tile:hover .mcms-tile-more,
.mcms-tiles-overlay .mcms-tile:focus-within .mcms-tile-more { max-height: 2em; opacity: 1; transform: none; padding-top: .6em; }
.mcms-tiles-overlay .mcms-tile:hover .mcms-tile-pic img { filter: brightness(.82); }
.mcms-tiles-overlay .mcms-tile.no-pic .mcms-tile-initial { transform: translateY(-.45em); }
.mcms-tiles-overlay .mcms-tile.no-pic:hover .mcms-tile-initial { transform: translateY(-.45em) scale(1.12) rotate(-4deg); }
/* touch screens have no hover: the text is always shown */
@media (hover: none) {
    .mcms-tiles-overlay .mcms-tile-text { max-height: 7em; opacity: 1; transform: none; margin-top: .6em; }
    .mcms-tiles-overlay .mcms-tile-pic::after { background-color: rgba(0, 0, 0, .35); }
}

/* ---- appearing one after another while scrolling (tiles.js; only with JavaScript) ---- */
.mcms-tiles.is-anim .mcms-tile { opacity: 0; transform: translateY(18px); }
.mcms-tiles.is-anim .mcms-tile.is-in {
    opacity: 1;
    transform: none;
    transition: opacity .6s ease calc(var(--i, 0) * 80ms), transform .7s cubic-bezier(.2, .7, .2, 1) calc(var(--i, 0) * 80ms), box-shadow .35s ease;
}
.mcms-tiles.is-anim .mcms-tile.is-in.is-done { transition: transform .35s cubic-bezier(.2, .7, .2, 1), box-shadow .35s ease; }
.mcms-tiles.is-anim .mcms-tile.is-in.is-done:hover { transform: translateY(-5px); }
.mcms-tiles.is-anim .mcms-tile.is-hidden.is-in { opacity: .45; }

@media (prefers-reduced-motion: reduce) {
    .mcms-tile, .mcms-tile *, .mcms-tile *::before, .mcms-tile *::after { transition: none !important; }
    .mcms-tile:hover, .mcms-tile:hover .mcms-tile-pic img, .mcms-tile:hover .mcms-tile-initial { transform: none; }
}
@media print {
    .mcms-tile { break-inside: avoid; box-shadow: none; border: 1px solid #999; }
    .mcms-tiles.is-anim .mcms-tile { opacity: 1; transform: none; }
}
