/*
 * 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: 3; }
}

.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);
	padding: 0 0 8px;
	display: flex;
	flex-direction: column;
	align-items: stretch;
	gap: 6px;
	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;
}

/*
 * Landscape rather than square, with a hard cap on top. A square box tied
 * the tile's height to its width, so the 6-up desktop rail grew ~223px
 * tall per picture and the section dwarfed the rows under it. 4:3 shortens
 * every tile, and `max-height` stops the picture growing further once the
 * viewport is wide enough for that ratio to exceed the cap.
 */
.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: 4 / 3;
	max-height: 150px;
	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);
}

.fv-cat-tile .meta {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 2px;
	text-align: center;
	padding: 0 2px;
	min-width: 0;
}

.fv-cat-tile .nm {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	height: 26px;
	padding: 0 10px;
	background: var(--fv-surface);
	color: var(--fv-accent);
	border: 1.5px solid var(--fv-accent);
	border-radius: var(--fv-radius-md);
	font-size: 11px;
	font-weight: 700;
	line-height: 1;
	letter-spacing: -0.005em;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	max-width: 100%;
	transition: background 0.15s ease, color 0.15s ease;
}

.fv-cat-tile:hover .nm {
	background: var(--fv-accent);
	color: #fff;
}

.fv-cat-tile .ct {
	font-family: var(--fv-mono);
	font-size: 10.5px;
	color: var(--fv-ink-3);
	letter-spacing: 0.02em;
}

.fv-cat-tile .pin {
	position: absolute;
	top: 10px;
	right: 10px;
	z-index: 3;
	font-family: var(--fv-mono);
	font-size: 9px;
	font-weight: 700;
	color: #fff;
	background: var(--fv-accent);
	padding: 3px 7px;
	border-radius: var(--fv-radius-full);
	letter-spacing: 0.04em;
	box-shadow: 0 2px 4px rgba(255, 107, 0, 0.3);
}

/* ── 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;
	}
}
