/*
 * Columns block styles
 *
 * Enqueued for core/columns via wp_enqueue_block_style().
 *
 * Everything is nested under `.wp-block-columns`. General Columns rules go
 * directly in that block; each style variation is its own self-contained
 * `&.is-style-*` block inside it, so the two never mix.
 *
 * @package Kindling
 * @since 1.0.0
 */
.wp-block-columns {
	/*
	 * Linked Tiles (styles/columns/linked-tiles.json)
	 *
	 * Edge-to-edge tiles, each column linked with the Kindling Blocks link setting
	 * (`href` on the column), which stretches an empty `.kindling-block-link`
	 * anchor over the column. Built for dark surfaces (Style 4 and Style 5), like
	 * the category bar under the page heroes.
	 *
	 *   divider  1px of teal (theme-14) at 30% on the right of every tile but
	 *            the last
	 *   hover    the tile darkens halfway to Navy 900 (#022447) and a 4px accent
	 *   focus    bar appears along its top edge: Sunset (theme-15) by default,
	 *            or the tile's own color from a `kindling-tile-accent-theme-NN`
	 *            class on the column (Advanced > Additional CSS class):
	 *              theme-15 Sunset, theme-16 Berry, theme-17 Meadow,
	 *              theme-14 Teal, theme-04 Gold
	 *   layout   one row down to 600px; on phones, two rows: the first three
	 *            tiles in thirds, the rest sharing the second row (3 + 2 for
	 *            the five Quick Links tiles)
	 *
	 * The bar is an inset shadow rather than a border so the tile content does not
	 * shift when it appears. Hover and focus share one state, so keyboard users
	 * get the same feedback.
	 */
	&.is-style-linked-tiles {
		--kindling-tile-divider: color-mix(
			in srgb,
			var(--wp--preset--color--theme-14) 30%,
			transparent
		);
		--kindling-tile-active: color-mix(
			in srgb,
			var(--wp--preset--color--theme-03),
			var(--wp--preset--color--theme-08)
		);

		gap: 0;

		> .wp-block-column {
			--kindling-tile-accent: var(--wp--preset--color--theme-15);

			transition:
				background-color 0.2s ease-out,
				box-shadow 0.2s ease-out;

			&:hover,
			&:focus-within {
				background-color: var(--kindling-tile-active);
				box-shadow: inset 0 4px 0 var(--kindling-tile-accent);
			}

			/* Per-tile accent bar colors. */
			&.kindling-tile-accent-theme-04 {
				--kindling-tile-accent: var(--wp--preset--color--theme-04);
			}

			&.kindling-tile-accent-theme-14 {
				--kindling-tile-accent: var(--wp--preset--color--theme-14);
			}

			&.kindling-tile-accent-theme-15 {
				--kindling-tile-accent: var(--wp--preset--color--theme-15);
			}

			&.kindling-tile-accent-theme-16 {
				--kindling-tile-accent: var(--wp--preset--color--theme-16);
			}

			&.kindling-tile-accent-theme-17 {
				--kindling-tile-accent: var(--wp--preset--color--theme-17);
			}

			/* Dividers between tiles (phones redraw them for two rows, below). */
			&:not(:last-child) {
				border-inline-end: 1px solid var(--kindling-tile-divider);
			}
		}

		/* The overlay link fills the tile, so keep its focus ring inside the tile. */
		.kindling-block-link:focus-visible {
			outline-offset: -2px;
		}

		/*
		 * One row, not a stack. Core stacks Columns at 781px and below with
		 * !important rules, so this style restates the row with !important at a
		 * higher specificity. Five tiles still fit side by side down to 600px.
		 */
		@media (max-width: 781px) {
			flex-wrap: nowrap !important;

			> .wp-block-column {
				flex: 1 1 0 !important;
				min-width: 0;
			}
		}

		/*
		 * Phones: two rows, as in the design. The first three tiles share the top
		 * row and the rest share the second (3 + 2 for five tiles). The tiles fill
		 * the full width of the band, so the dividers run edge to edge: between
		 * the tiles in each row and along the bottom of the top row.
		 *
		 * The width rule is scoped to a constrained parent so it outranks core's
		 * constrained-layout width and margins. `:nth-child(n)` lifts the divider
		 * rules to the specificity of the `:not(:last-child)` divider above, so
		 * they replace it rather than add to it.
		 */
		@media (max-width: 599px) {
			flex-wrap: wrap !important;

			.is-layout-constrained > & {
				max-width: none;
				margin-inline: 0 !important;
			}

			> .wp-block-column:nth-child(n) {
				/* Over a third, so later tiles wrap to the second row rather than squeeze into the first. */
				flex: 1 1 34% !important;
				border-inline-end: 0;

				&:nth-child(-n + 3) {
					flex-basis: calc(100% / 3) !important;
					max-width: calc(100% / 3);
					border-block-end: 1px solid var(--kindling-tile-divider);
				}

				&:nth-child(-n + 2),
				&:nth-child(n + 4):not(:last-child) {
					border-inline-end: 1px solid var(--kindling-tile-divider);
				}
			}
		}

		@media (prefers-reduced-motion: reduce) {
			> .wp-block-column {
				transition: none;
			}
		}
	}
}
