/*
 * HPVFC Home Stats Block
 *
 * Three tiers, matching the house breakpoints used by dark_mode.css:
 *   >= 1025px                     two columns, 3fr / 7fr
 *   769px - 1024px                same ratio, tighter paddings and avatars
 *   <= 768px                      single stacked column, scrollable tab bar
 *   <= 600px                      compact rows
 *
 * Only the active panel is displayed; the JS toggles .is-active, and without JS
 * the server decides which panel is active (the select and the tabs are real
 * form control / links).
 */

.hpvfc-home-stats {
	/* One control height for both columns so the two headers - and therefore every row below them - line up.
	   Same value on both desktop tiers: a smaller step there made the header row shorter and the
	   diacritics of Vietnamese labels got clipped again. */
	--hpvfc-home-stats-control-height: 36px;
	/* How many rows the stacked (mobile) list shows before it starts scrolling. */
	--hpvfc-home-stats-mobile-rows: 5;
	/* iOS only: WebKit inflates text in a block whose text column crosses roughly 500px,
	   and it does so block by block, so on a phone the rows that are wide enough to need the
	   horizontal scroll render bigger than the rows next to them. The mobile min-width on
	   rows is what lets them cross that threshold. Pin the adjustment here (it is inherited,
	   so it covers the whole block) and nothing else on the page changes. */
	-webkit-text-size-adjust: 100%;
	text-size-adjust: 100%;

	display: grid;
	gap: var(--modern-space-4, 16px);
	/* Top kept small: the page already puts the theme's navigation margin and a template
	   <br /> above us, which together add about 40px on their own. */
	margin: var(--modern-space-2, 8px) 0 var(--modern-space-6, 24px);
	/* The block sits inside the theme's .wrapper; the theme now puts that wrapper on the
	   same grid as #content (see the #content > .wrapper rule in dark_mode.css), so no
	   negative margin is needed here. Measured at 1440/900/500: block, shoutbox, forum
	   tables, nav and footer all share the same edges. */
}

.hpvfc-home-stats *,
.hpvfc-home-stats *::before,
.hpvfc-home-stats *::after {
	box-sizing: border-box;
}

/* The homepage template leaves a bare <br /> between the navigation and this block, on top of
   the navigation's own bottom margin - two empty lines of gap. Scoped with :has() to the one
   that sits directly in front of us, so no other page loses a line break. Browsers without
   :has() simply keep the gap. */
br:has(+ .hpvfc-home-stats) {
	display: none;
}

.hpvfc-home-stats__column {
	min-width: 0;
	display: flex;
	flex-direction: column;
	background: var(--modern-surface, #111827);
	border: 1px solid var(--modern-border, #26334b);
	border-radius: var(--modern-radius-lg, 12px);
	padding: var(--modern-space-4, 16px);
	box-shadow: var(--modern-shadow-sm, none);
}

.hpvfc-home-stats__head {
	display: flex;
	flex-wrap: nowrap;
	align-items: center;
	justify-content: space-between;
	gap: var(--modern-space-2, 8px);
	min-height: calc(var(--hpvfc-home-stats-control-height) + var(--modern-space-3, 12px));
	padding-bottom: var(--modern-space-3, 12px);
}

.hpvfc-home-stats__title {
	margin: 0;
	flex: 1 1 auto;
	min-width: 0;
	font-size: 15px;
	/* Inter needs ~1.43em of line box (usWinAscent+usWinDescent over upem). Anything tighter
	   and WebKit clips stacked Vietnamese diacritics (ồ ườ ệ Ấ) inside overflow:hidden. */
	line-height: 1.5;
	font-weight: 600;
	color: var(--modern-text, #e7edf7);
	overflow: hidden;
	white-space: nowrap;
	/* Cut off means cut off: an ellipsis on a truncated title adds nothing here. */
	text-overflow: clip;
}

/* --- controls --- */

.hpvfc-home-stats__control {
	display: flex;
	flex: 0 1 auto;
	align-items: center;
	justify-content: flex-end;
	gap: 6px;
	margin: 0;
	min-width: 0;
}

.hpvfc-home-stats__visually-hidden {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect(0 0 0 0);
	clip-path: inset(50%);
	white-space: nowrap;
	border: 0;
}

/*
 * The switcher and the tab pills share one height so both column headers - and every
 * row under them - line up. The text label is visually hidden (it stays for screen
 * readers); the submit button only exists without JavaScript.
 */
.hpvfc-home-stats__control select,
.hpvfc-home-stats__submit,
.hpvfc-home-stats__tab,
.hpvfc-home-stats__collapse {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	height: var(--hpvfc-home-stats-control-height);
	/* Author min-height on purpose (and !important): Chrome enforces a ~38px UA
	   min-height on form controls through a higher-specificity UA rule, which would
	   otherwise make the select and the collapse button taller than the tab pills and
	   push every row under them out of alignment with the other column. */
	min-height: var(--hpvfc-home-stats-control-height) !important;
	box-sizing: border-box;
	padding: 0 10px;
	/* Same size as the theme body text (14px is the page body; controls sit one step
	   down); line-height stays generous so Vietnamese diacritics are never clipped. */
	font-size: 13px;
	line-height: 1.5;
	white-space: nowrap;
	color: var(--modern-text, #e7edf7);
	background: var(--modern-surface-raised, #172033);
	border: 1px solid var(--modern-border, #26334b);
	border-radius: var(--modern-radius-sm, 6px);
}

.hpvfc-home-stats__control select {
	/* Room for the longest option label plus the native dropdown arrow, and the form
	   grows so the select never has to ellipsise the selected value. */
	flex: 1 1 auto;
	min-width: 170px;
	max-width: 260px;
	cursor: pointer;
	/* Chrome styles <select> with :not(:-internal-list-box), which outranks a single
	   class selector, and its UA min-height would otherwise make this control taller
	   than the tab pills - and push the whole column out of alignment. */
	min-height: var(--hpvfc-home-stats-control-height) !important;
	/* Native select: keep the UA line-height. A fixed one renders Vietnamese diacritics
	   clipped in WebKit/Safari even when the box is tall enough. */
	line-height: normal;
}

.hpvfc-home-stats__submit {
	cursor: pointer;
}

/* Collapse toggle: mobile only (see the max-width: 768px block), and only when the
   script is running - without it the members list stays expanded. */
.hpvfc-home-stats__collapse {
	display: none;
	cursor: pointer;
}

/* Chevron drawn in CSS rather than a Font Awesome <i>: the theme re-declares
   body #content * { font-family: Inter !important }, which outranks .fas and turns the
   glyph into a missing character. A drawn chevron cannot be broken by that. */
.hpvfc-home-stats__collapse::after {
	content: "";
	width: 7px;
	height: 7px;
	border-right: 2px solid currentColor;
	border-bottom: 2px solid currentColor;
	transform: rotate(45deg);
	transition: transform 0.15s ease;
}

.hpvfc-home-stats__column--members.is-open .hpvfc-home-stats__collapse::after {
	transform: rotate(-135deg);
}

.hpvfc-home-stats__tabs {
	display: flex;
	flex-wrap: nowrap;
	gap: 6px;
	overflow-x: auto;
	max-width: 100%;
	scrollbar-width: none;
}

.hpvfc-home-stats__tabs::-webkit-scrollbar {
	display: none;
}

.hpvfc-home-stats__tab {
	flex: 0 0 auto;
	text-decoration: none;
	color: var(--modern-text-muted, #9aa8bd);
	background: transparent;
}

.hpvfc-home-stats__tab:hover {
	color: var(--modern-accent, #55c7f5);
	border-color: var(--modern-border-strong, #344563);
	text-decoration: none;
}

.hpvfc-home-stats__tab:focus-visible {
	outline: 2px solid var(--modern-accent, #55c7f5);
	outline-offset: 1px;
}

.hpvfc-home-stats__tab.is-active {
	color: var(--modern-accent, #55c7f5);
	background: var(--modern-surface-hover, #1d2940);
	border-color: var(--modern-border-strong, #344563);
}

/* --- panels --- */

.hpvfc-home-stats__list {
	list-style: none;
	margin: 0;
	padding: 0;
}

.hpvfc-home-stats__list:not(.is-active) {
	display: none;
}

.hpvfc-home-stats__item {
	display: flex;
	align-items: center;
	gap: 14px;
	min-height: 40px;
	padding: 6px 0;
	border-top: 1px solid var(--modern-border, #26334b);
}

.hpvfc-home-stats__list > .hpvfc-home-stats__item:first-child {
	border-top: 0;
}

.hpvfc-home-stats__rank {
	flex: 0 0 auto;
	width: 2.4em;
	text-align: right;
	font-size: 12px;
	font-variant-numeric: tabular-nums;
	color: var(--modern-text-muted, #9aa8bd);
}

.hpvfc-home-stats__avatar {
	flex: 0 0 auto;
	display: block;
	width: 32px;
	height: 32px;
	overflow: hidden;
	border-radius: var(--modern-radius-sm, 6px);
	background: var(--modern-surface-raised, #172033);
}

.hpvfc-home-stats__avatar img {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.hpvfc-home-stats__body {
	min-width: 0;
	display: flex;
	flex-direction: column;
	gap: 3px;
}

.hpvfc-home-stats__name {
	display: block;
	min-width: 0;
	overflow: hidden;
	text-overflow: clip;
	white-space: nowrap;
	/* Matches the theme body font-size (14px): block text must not read smaller than
	   the rest of the page. */
	font-size: 14px;
	line-height: 1.5;
	/* The theme forces its accent on every content link with !important, so that is where the
	   colour comes from either way; this is here so the intent matches. The weight matches the
	   theme's own thread lists (.stats_thread_item a). MyBB group name styles (house colours)
	   still show: they arrive as markup inside the link, and the theme rule only targets the
	   link itself. */
	font-weight: 650;
	color: var(--modern-accent, #55c7f5);
}

.hpvfc-home-stats__name:hover {
	color: var(--modern-accent, #55c7f5);
	text-decoration: none;
}

.hpvfc-home-stats__meta {
	min-width: 0;
	overflow: hidden;
	text-overflow: clip;
	white-space: nowrap;
	font-size: 12px;
	line-height: 1.5;
	color: var(--modern-text-muted, #9aa8bd);
}

.hpvfc-home-stats__meta a {
	color: inherit;
}

.hpvfc-home-stats__meta a:hover {
	color: var(--modern-accent, #55c7f5);
}

.hpvfc-home-stats__dot {
	padding: 0 2px;
}

.hpvfc-home-stats__empty {
	padding: 10px 0;
	font-size: 12px;
	color: var(--modern-text-muted, #9aa8bd);
}

/* --- 769px - 1024px --- */

@media (min-width: 769px) and (max-width: 1024px) {
	.hpvfc-home-stats {
		grid-template-columns: minmax(0, 3fr) minmax(0, 7fr);
	}

	.hpvfc-home-stats__column {
		padding: var(--modern-space-3, 12px);
	}

	.hpvfc-home-stats__control select {
		/* Fits inside the narrower column instead of overflowing it; the value text is
		   clipped (no ellipsis) when the label does not fit. */
		min-width: 0;
	}

	.hpvfc-home-stats__avatar {
		width: 26px;
		height: 26px;
	}

	.hpvfc-home-stats__item {
		min-height: 34px;
	}
}

/* --- >= 1025px: the requested 3 / 7 ratio --- */

@media (min-width: 1025px) {
	.hpvfc-home-stats {
		grid-template-columns: minmax(0, 3fr) minmax(0, 7fr);
		gap: var(--modern-space-6, 24px);
	}

	.hpvfc-home-stats__column {
		padding: var(--modern-space-5, 20px);
	}
}

/* --- <= 768px: stacked --- */

@media (max-width: 768px) {
	.hpvfc-home-stats {
		grid-template-columns: minmax(0, 1fr);
		/* The columns stack here, so the two headers no longer have to match height:
		   controls go back to a natural - and touch friendly - height, because forcing
		   them to the desktop height clipped the native select's own text. */
		--hpvfc-home-stats-control-height: 40px;
	}

	/* Mobile: only the thread tabs are shown; the member list (and with it its toggle button,
	   which lives inside that column) is hidden. The JS binding stays, it simply never fires. */
	.hpvfc-home-stats__title {
		display: none;
	}

	.hpvfc-home-stats__column--members {
		display: none;
	}

	.hpvfc-home-stats__control {
		flex: 1 1 auto;
		justify-content: flex-start;
	}

	.hpvfc-home-stats__control select {
		flex: 1 1 auto;
		max-width: none;
		height: auto;
		min-height: var(--hpvfc-home-stats-control-height) !important;
		padding-top: 8px;
		padding-bottom: 8px;
	}

	/* Mobile: the list shows --hpvfc-home-stats-mobile-rows rows and scrolls - vertically
	   through the rest of the list, and horizontally so a title that does not fit can be
	   revealed instead of being ellipsised away. Rows size to their content so nothing is
	   cut; separators on shorter rows therefore stop where the row does. The members
	   column (collapsed behind the toggle) gets the same treatment for consistency. */
	.hpvfc-home-stats__panels,
	.hpvfc-home-stats__list--threads {
		max-height: calc(var(--hpvfc-home-stats-mobile-rows) * 52px);
		overflow: auto;
		-webkit-overflow-scrolling: touch;
		scrollbar-width: thin;
		scrollbar-color: var(--modern-border, #26334b) transparent;
	}

	.hpvfc-home-stats__item {
		min-width: max-content;
	}
}

/* --- <= 600px: compact --- */

@media (max-width: 600px) {
	.hpvfc-home-stats {
		--hpvfc-home-stats-control-height: 40px;
	}

	.hpvfc-home-stats__item {
		min-height: 32px;
		gap: 12px;
	}

	.hpvfc-home-stats__avatar {
		display: none;
	}

	.hpvfc-home-stats__rank {
		width: 2.2em;
	}

	.hpvfc-home-stats__name {
		font-size: 13px;
	}
}

@media (prefers-reduced-motion: reduce) {
	.hpvfc-home-stats *,
	.hpvfc-home-stats *::before,
	.hpvfc-home-stats *::after {
		transition: none !important;
		animation: none !important;
	}
}
