/* KICKSTW reskin: the home page's featured brands under the two rows, the mosaic
   (templates/home/brands.php), per site_prototype/assets/css/home-brands.css there. Photos in rows
   whose joins do not line up, each brand's name on its photo in the bottom left corner.
   home-brands.js moves the joins as the page scrolls and brings the tiles in once; without it the
   block is whole and still. Everything is under .kt-chrome. Phone first; 721px and 1025px are the
   site's two breakpoints. */

/* ---------- The mosaic ----------
   A hairline of page (4px) between the photos. A tile's width is its share of the row (--fp of --kp
   tiles on a phone, --fd of --kd from 721px), set on the tile by the server. --shift (-1 to 1) is
   set on the block by the script as the page scrolls and moves the joins: a row at 5:4:3 is 4:4:4
   coming in, 5:4:3 in the middle of the window, 6:4:2 going out. How far of that it goes (0.3 on a
   phone, 0.6 from 721px, all of it from 1025px) is written into each breakpoint's width, since a
   stylesheet here declares no custom property of its own. */
.kt-chrome .fbm { container-type: inline-size; display: flex; flex-wrap: wrap; gap: 4px; }
/* Each tile is a container of its own, so its name is sized by the tile. A tile is a link, and the
   theme gives every link a 0.2s transition on everything: its width would trail the scroll, and
   while it trails Firefox can make a row a hair too wide, so the row's last tile drops to the next
   row for a frame and the block flickers. The joins follow the scroll directly, as in the prototype. */
.kt-chrome .fbm-tile { container-type: inline-size; position: relative; flex: 0 0 calc((100% - (var(--kp) - 1) * 4px) * (var(--fp) + (var(--fp) - 1 / var(--kp)) * var(--shift, 0) * 0.3) - 0.02px); height: 56cqw; overflow: hidden; color: var(--white); text-decoration: none; transition: none; }
.kt-chrome .fbm-tile:hover { color: var(--white); }
.kt-chrome .fbm-tile:focus-visible { outline-offset: -4px; outline-color: var(--white); }
/* Before its photo arrives a tile already has its tone, so its name can be read: dark under white
   words, the photo colour under ink. A photo that fails to load leaves the tile like this. */
.kt-chrome .fbm-pic { position: absolute; inset: 0; background: var(--ink-2); }
/* The photo fills its tile whether it is a bare <img> or wrapped in a <picture> (an inline box with
   no height of its own), so it is placed over the tile rather than sized by its parent. One rule
   places every photo: the middle, a third of the way down, where a face usually is. */
.kt-chrome .fbm-pic img { position: absolute; inset: 0; display: block; width: 100%; height: 100%; object-fit: cover; object-position: 50% 30%; }
.kt-chrome .fbm-pic img.is-waiting { opacity: 0; }
/* One flat tone over each photo, never a gradient: a dark photo is pushed darker and carries white
   words, a light one is washed lighter and carries ink. */
.kt-chrome .fbm-veil { position: absolute; inset: 0; background: var(--ink); opacity: 0.26; }
/* Three classes, to win over the home page's heading reset; the colour is the tile's. */
.kt-chrome .fbm .fbm-name { position: absolute; left: 0; right: 0; bottom: 0; margin: 0; padding: clamp(8px, 6cqw, 24px); color: inherit; font: var(--type-tile); letter-spacing: -0.015em; text-transform: uppercase; text-wrap: initial; overflow-wrap: anywhere; }
.kt-chrome .fbm-name span { text-decoration: underline 2px transparent; text-underline-offset: 5px; }
.kt-chrome .fbm-tile[data-tone="light"] { color: var(--ink); }
.kt-chrome .fbm-tile[data-tone="light"]:focus-visible { outline-color: var(--ink); }
.kt-chrome .fbm-tile[data-tone="light"] .fbm-pic { background: var(--brand-bg); }
.kt-chrome .fbm-tile[data-tone="light"] .fbm-veil { background: var(--white); opacity: 0.14; }
@media (min-width: 721px) {
  /* Two rows and the block's title fit one window, so the joins are seen moving as a whole. */
  .kt-chrome .fbm-tile { flex: 0 0 calc((100% - (var(--kd) - 1) * 4px) * (var(--fd) + (var(--fd) - 1 / var(--kd)) * var(--shift, 0) * 0.6) - 0.02px); height: min(29cqw, 40svh); }
}
@media (min-width: 1025px) {
  .kt-chrome .fbm-tile { flex: 0 0 calc((100% - (var(--kd) - 1) * 4px) * (var(--fd) + (var(--fd) - 1 / var(--kd)) * var(--shift, 0) * 1) - 0.02px); }
}

/* Under the pointer the name is underlined, as a link is, and the photo comes a little closer.
   A photo that arrives late fades in. */
.kt-chrome .fbm-tile:hover .fbm-name span, .kt-chrome .fbm-tile:focus-visible .fbm-name span { text-decoration-color: currentColor; }
@media (prefers-reduced-motion: no-preference) {
  .kt-chrome .fbm:not([data-motion="still"]) .fbm-name span { transition: text-decoration-color 0.2s ease; }
  .kt-chrome .fbm:not([data-motion="still"]) .fbm-pic img { transition: scale 0.9s cubic-bezier(0.2, 0.7, 0.2, 1), opacity 0.4s ease; }
}
@media (hover: hover) and (prefers-reduced-motion: no-preference) {
  .kt-chrome .fbm:not([data-motion="still"]) .fbm-tile:hover .fbm-pic img { scale: 1.04; }
}

/* ---------- Coming in, once ----------
   The script sets data-enter only when it can also take it off again. Each tile is uncovered from
   below, 70ms after the one before, while its photo settles and its name follows. */
@media (prefers-reduced-motion: no-preference) {
  .kt-chrome .fbm[data-motion="glide"][data-enter="ready"] .fbm-tile { clip-path: inset(100% 0 0 0); }
  .kt-chrome .fbm[data-motion="glide"][data-enter="ready"] .fbm-pic img { scale: 1.14; transition: none; }
  .kt-chrome .fbm[data-motion="glide"][data-enter="ready"] .fbm-name { opacity: 0; translate: 0 12px; }
  /* inset(0), not none: a clip-path only moves between two shapes of the same kind. */
  .kt-chrome .fbm[data-motion="glide"][data-enter="in"] .fbm-tile { clip-path: inset(0); transition: clip-path 0.9s cubic-bezier(0.2, 0.7, 0.2, 1) calc(var(--i) * 70ms); }
  .kt-chrome .fbm[data-motion="glide"][data-enter="in"] .fbm-pic img { transition: scale 1.4s cubic-bezier(0.2, 0.7, 0.2, 1) calc(var(--i) * 70ms), opacity 0.4s ease; }
  .kt-chrome .fbm[data-motion="glide"][data-enter="in"] .fbm-name { transition: opacity 0.5s ease calc(var(--i) * 70ms + 400ms), translate 0.5s ease calc(var(--i) * 70ms + 400ms); }
}
