/*
 * Fivany homepage — port of Opnar's block engine
 * (components/home/home.css: hero, cat-grid, rail-head, rail-grid).
 */

/*
 * Section rhythm copied from Opnar's `.opnar-home`: 0.25rem stacking to
 * 0.5rem at 768px, tied to the layout's own header gap so every page
 * surface breathes at one rhythm.
 *
 * 8px between sections only reads as enough because each block supplies
 * its own separation: `.fv-rail-head` carries a 14px margin under every
 * heading, so the actual gap between one grid and the next heading is
 * 8px, and between that heading and its grid 14px. Opnar's blocks are
 * flat for the same reason — no card chrome, no per-section margins.
 *
 * The page's bottom breathing room comes from `.site-main`, not here.
 */
/*
 * The first block sits at the same rhythm as every other one.
 *
 * `.site-content` carries a 16px top padding site-wide (chrome.css, for the
 * flush header). On this page that lands above the banner as a band three
 * times the gap separating every block below it, so the home page takes its
 * top spacing from `.site-main` alone and the space above the first block
 * equals the space between the rest. Scoped to `body.home` because this
 * stylesheet loads everywhere; the two classes also outrank the single-class
 * rule it is overriding.
 */
body.home .site-content {
	padding-top: 0;
}

.fv-home {
	display: flex;
	flex-direction: column;
	gap: 0.25rem;
}

@media (min-width: 768px) {
	.fv-home {
		gap: 0.5rem;
	}
}

.fv-home section {
	scroll-margin-top: 90px;
}

/* ── Rail head — shared section header ─────────────────────────── */

.fv-rail-head {
	display: flex;
	align-items: flex-end;
	gap: 14px;
	margin-bottom: 14px;
	flex-wrap: wrap;
}

.fv-rail-head h2 {
	margin: 0;
	font-size: 18px;
	font-weight: 800;
	letter-spacing: -0.02em;
	color: var(--fv-ink);
	display: flex;
	align-items: center;
	gap: 10px;
	line-height: 1.2;
}

.fv-rail-head h2 em {
	font-style: normal;
	color: var(--fv-accent);
}

.fv-rail-head .meta {
	font-family: var(--fv-mono);
	font-size: 11px;
	color: var(--fv-ink-3);
	letter-spacing: 0.04em;
	text-transform: uppercase;
}

.fv-rail-head > .more {
	margin-left: auto;
	display: inline-flex;
	align-items: center;
	gap: 5px;
	height: 30px;
	padding: 0 12px;
	border: 1px solid var(--fv-line);
	border-radius: var(--fv-radius-md);
	background: var(--fv-surface);
	color: var(--fv-ink-2);
	font-size: 12.5px;
	font-weight: 600;
	transition: border-color 0.15s ease, color 0.15s ease;
}

.fv-rail-head > .more:hover {
	border-color: var(--fv-accent);
	color: var(--fv-accent);
}

/* ── Category tiles ────────────────────────────────────────────── */

/*
 * Opnar's horizontal category rail, sized to a fixed number of tiles per
 * screen: 6 visible on desktop, 2 on mobile, everything past that reached
 * by scrolling. Tile width is derived from the track rather than fixed in
 * px, so the visible count holds at any viewport --
 *   width = (100% - gaps) / n,  with (n - 1) gaps between n tiles.
 * `--fv-cat-n` is the only thing each breakpoint changes.
 */
.fv-cat-grid {
	--fv-cat-gap: 10px;
	--fv-cat-n: 6;

	display: flex;
	gap: var(--fv-cat-gap);
	overflow-x: auto;
	scroll-snap-type: x proximity;
	-webkit-overflow-scrolling: touch;
	scrollbar-width: thin;
	scrollbar-color: var(--fv-line-2) transparent;
	padding-bottom: 4px;
}

@media (max-width: 1023px) {
	.fv-cat-grid { --fv-cat-n: 4; }
}

@media (max-width: 767px) {
	.fv-cat-grid { --fv-cat-n: 4; }
}

.fv-cat-grid::-webkit-scrollbar {
	height: 6px;
}

.fv-cat-grid::-webkit-scrollbar-track {
	background: transparent;
}

.fv-cat-grid::-webkit-scrollbar-thumb {
	background: var(--fv-line-2);
	border-radius: 999px;
}

.fv-cat-tile {
	position: relative;
	background: var(--fv-cream);
	border: 0;
	border-radius: var(--fv-radius-lg);
	/* The label lives on the picture now, so there is no second row to pad
	   for and the tile is exactly the square. */
	padding: 0;
	display: flex;
	flex-direction: column;
	align-items: stretch;
	gap: 0;
	flex: 0 0 calc((100% - (var(--fv-cat-n) - 1) * var(--fv-cat-gap)) / var(--fv-cat-n));
	min-width: 0;
	scroll-snap-align: start;
	overflow: hidden;
	box-shadow: var(--fv-shadow-sm);
	color: inherit;
	transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.fv-cat-tile:hover {
	transform: translateY(-2px);
	box-shadow: var(--fv-shadow-md);
	background: var(--fv-cream-hover);
	color: inherit;
}

/*
 * Square, matching the source.
 *
 * WooCommerce crops category thumbnails to 324x324 (`woocommerce_thumbnail`,
 * hard crop), so every image arriving here is already a square. This box used
 * to be 4:3 with a 150px cap, which meant `object-fit: cover` threw away the
 * top and bottom of each one — and once the cap engaged the frame was not
 * even 4:3 any more but 1.47, so on a wide screen roughly a third of the
 * picture was cut off.
 *
 * The earlier note here worried that a square box ties tile height to tile
 * width and lets the rail grow without limit. It cannot: the section sits on
 * the `--fv-maxw` rail, so at six across the tile stops at ~224px however
 * wide the screen gets. Measured 1.00 at every breakpoint from 360 to 1920.
 */
.fv-cat-tile .pic {
	position: relative;
	background: transparent;
	border-radius: var(--fv-radius-md);
	display: flex;
	align-items: center;
	justify-content: center;
	overflow: hidden;
	aspect-ratio: 1 / 1;
	width: 100%;
}

.fv-cat-tile .pic img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
}

.fv-cat-tile .pic .fv-i {
	color: var(--fv-ink-soft);
}


/*
 * The category name, set on the picture.
 *
 * It was a bordered orange chip sitting under the image: inside a tile that
 * is one link, a control-shaped element reads as a second, different thing
 * to press, and it left a band of cream below every photograph doing no
 * work. On the image it labels the picture, which is what it is for.
 *
 * The scrim is a gradient rather than a flat bar so the bottom of the
 * photograph is still legible through it.
 */
.fv-cat-tile .nm {
	position: absolute;
	left: 0;
	right: 0;
	bottom: 0;
	z-index: 2;
	padding: 26px 10px 11px;
	text-align: center;
	font-size: 12.5px;
	font-weight: 700;
	line-height: 1.25;
	letter-spacing: -0.005em;
	color: #fff;
	/*
	 * Sized for the worst case, which here is the common one: this shop
	 * photographs pale underwear on pale backdrops, so the label usually
	 * sits over something near-white rather than something dark.
	 *
	 * Measured against a pure white picture, white text on this scrim gives
	 * 7.7:1 — WCAG AAA. The earlier, lighter gradient gave 5.1:1, which
	 * passes AA but leaves nothing spare once a photograph is brighter at
	 * the bottom than in the middle, as product shots on white tend to be.
	 */
	background: linear-gradient(
		to top,
		rgba(15, 23, 42, 0.86),
		rgba(15, 23, 42, 0.58) 60%,
		rgba(15, 23, 42, 0)
	);
	text-shadow: 0 1px 2px rgba(15, 23, 42, 0.4);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	transition: color 0.15s ease;
}

/*
 * Phone labels, defined after the base rule on purpose.
 *
 * These live here rather than up with the `--fv-cat-n` breakpoints because
 * they share the base rule's specificity: written earlier in the file they
 * lost the tie on source order and silently did nothing — `white-space`
 * stayed `nowrap` and "Undershirts" still rendered as "Undersh…".
 *
 * Four tiles across a 390px screen is about 85px each, and most of these
 * names do not fit on one line at a readable size. So they wrap, clamped to
 * two lines so a long name can never push the scrim up over the picture,
 * and hyphenate so a single long word breaks instead of being cut.
 */
@media (max-width: 767px) {
	.fv-cat-tile .nm {
		white-space: normal;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		line-clamp: 2;
		-webkit-box-orient: vertical;
		font-size: 11px;
		line-height: 1.22;
		padding: 20px 6px 8px;
		hyphens: auto;
		overflow-wrap: break-word;
	}
}

/*
 * Nothing behind the label but the tile itself — a scrim here would be a
 * grey smear across cream, so the name simply sits in ink.
 */
.fv-cat-tile:not(.has-thumb) .nm {
	background: none;
	color: var(--fv-ink);
	text-shadow: none;
	padding-top: 10px;
}


/* Hover already lifts the whole tile; the label only warms to the accent
   so the two do not compete. */
.fv-cat-tile:hover .nm {
	color: var(--fv-accent);
}

.fv-cat-tile.has-thumb:hover .nm {
	color: #fff;
}


/* ── Split promo banners ───────────────────────────────────────── */

.fv-split {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: 16px;
}

/* ── Short-rail visibility ─────────────────────────────────────────
 * A rail is only worth its heading if it can fill a row, and a row is
 * only worth showing if it is complete. Both depend on how many columns
 * the product grid has, so the rules move on shop.css's own breakpoints:
 * 4-up above 1023px, 3-up from 768 to 1023, 2-up below.
 *
 *   count 1        hidden everywhere — one card under a full-width
 *                  heading reads as a broken section at any size
 *   count 2        hidden everywhere: it cannot fill a row except on
 *                  mobile, where a two-card section is still too thin
 *                  to earn its heading
 *   count 3        fills the row on tablet, so it is kept there; hidden
 *                  on desktop where the row is 4-up; trimmed to two on
 *                  mobile so the 2-up row is not left ragged
 *   count 4+       shown, with any trailing part row trimmed
 *
 * Counts are enumerated rather than compared: CSS has no numeric
 * comparison for attribute values.
 */
.fv-home .fv-rail-section[data-fv-count="1"],
.fv-home .fv-rail-section[data-fv-count="2"] {
	display: none;
}

@media (min-width: 1024px) {
	.fv-home .fv-rail-section[data-fv-count="3"] {
		display: none;
	}
}

@media (max-width: 767px) {
	/* Trim the odd third card so the two-up row is not left ragged. */
	.fv-home .fv-rail-section[data-fv-count="3"] .products > li.product:nth-child(n + 3) {
		display: none;
	}
}

/*
 * Tablet trims the trailing part row.
 *
 * Every rail asks for a multiple of four (four per category), so the 4-up
 * and 2-up grids always come out even and only the 3-up one is left
 * ragged — four products show as a row of three and a lone orphan.
 *
 * A card in the first column that is also among the last two items is by
 * definition starting a row of one or two, so it and everything after it
 * are the part row: eight cards drop to six, five and four drop to three,
 * and a count that already divides by three matches nothing. This holds
 * for any count without enumerating them, which the `data-fv-count` rules
 * above cannot do.
 */
@media (min-width: 768px) and (max-width: 1023px) {
	.fv-home .fv-rail-section .products > li.product:nth-child(3n + 1):nth-last-child(-n + 2),
	.fv-home .fv-rail-section .products > li.product:nth-child(3n + 1):nth-last-child(-n + 2) ~ li.product {
		display: none;
	}
}

/* ══════════════════════════════════════════════════════════════
   HOME BANNERS
   ══════════════════════════════════════════════════════════════ */

/*
 * The hero and the promo pair are uploaded artwork. Each slot publishes its
 * own aspect ratio as a custom property from inc/customizer.php, so the space
 * is reserved before the image arrives — without that the whole page shifts
 * down as the banner loads, which is the worst offender for layout shift on
 * a slow connection.
 */
.fv-banner {
	display: block;
	position: relative;
	overflow: hidden;
	border-radius: var(--fv-radius-lg);
	background: var(--fv-muted);
	aspect-ratio: var(--fv-banner-ratio, 1600 / 620);
	box-shadow: var(--fv-shadow-sm);
	transition: transform 0.18s ease, box-shadow 0.18s ease;
}

a.fv-banner:hover {
	transform: translateY(-2px);
	box-shadow: var(--fv-shadow-md);
}

/* ── Slides ────────────────────────────────────────────────────── */

/*
 * A scroll-snap track, not a transform carousel. The browser handles the
 * swipe, the momentum and the snapping; the script only nudges it along on
 * a timer. With JavaScript off it is still a swipeable strip rather than a
 * stuck first frame.
 */
.fv-banner-track {
	display: flex;
	width: 100%;
	height: 100%;
	overflow-x: auto;
	scroll-snap-type: x mandatory;
	scrollbar-width: none;
	-ms-overflow-style: none;
}

.fv-banner-track::-webkit-scrollbar { display: none; }

.fv-banner-slide {
	flex: 0 0 100%;
	width: 100%;
	height: 100%;
	scroll-snap-align: center;
	display: block;
}

/* `cover` rather than `contain`: the ratio already matches the artwork, so
 * this only absorbs rounding, and a letterboxed banner with bars down the
 * sides looks like a mistake. */
.fv-banner .fv-banner-img {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
	margin: 0;
}

/* ── Position dots ─────────────────────────────────────────────── */

.fv-banner-dots {
	position: absolute;
	left: 0;
	right: 0;
	bottom: 10px;
	display: flex;
	justify-content: center;
	gap: 6px;
	pointer-events: none;
}

.fv-banner-dot {
	width: 7px;
	height: 7px;
	border-radius: var(--fv-radius-full);
	/* White with a shadow rather than a brand colour: the dots sit on top of
	 * artwork nobody has seen yet, and white reads on any of it. */
	background: rgba(255, 255, 255, 0.55);
	box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
	pointer-events: auto;
	cursor: pointer;
	transition: background-color 0.2s ease, width 0.2s ease;
}

.fv-banner-dot.is-on {
	background: #fff;
	width: 18px;
}

@media (prefers-reduced-motion: reduce) {
	.fv-banner-track { scroll-behavior: auto; }
	.fv-banner-dot { transition: none; }
	a.fv-banner:hover { transform: none; }
}

.fv-split {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: 16px;
}

/* One banner set, not two: it takes the full width rather than sitting in
 * half a row with a gap beside it. */
.fv-split.is-single {
	grid-template-columns: 1fr;
}

/*
 * The pair stays side by side on a phone. Stacking pushed the first product
 * rail a full screen further down, and a banner is read at a glance — it does
 * not need the width a paragraph would. Each banner keeps its own aspect at
 * every width, so one uploaded image fits a phone and a desktop uncropped.
 */
@media (max-width: 767px) {
	.fv-split {
		gap: 10px;
	}
}
