/**
 * Handhelds.wtf Data — front-end + editor styles.
 *
 * Palette matches the site's existing hand-built app tables: the table itself
 * is the only surface, there is no panel behind it, and the CTA red is the same
 * one the download buttons use.
 *
 * Every colour is a custom property on `.hhwtf-data`, so one override retints
 * the block:
 *
 *   .hhwtf-data { --hhwtf-surface: #030712; --hhwtf-accent: #00d4aa; }
 */

/*
 * Force border-box inside the block.
 *
 * Themes that put content-box on buttons or inputs break anything sized with
 * `width: 100%` plus padding. The sort button ended up ~28px wider than its
 * header cell (100% of the cell, plus 14px padding on each side), anchored at
 * the cell's left edge and spilling out the right. That single fact produced
 * four symptoms at once: header labels drifting right inside an over-wide box,
 * hover targets not matching their columns, the last column's button pushing
 * scrollWidth past the table so a scrollbar appeared over blank space, and
 * clipped icons once the table was scrolled. The filter input's max-width hits
 * the same trap.
 */
.hhwtf-data,
.hhwtf-data *,
.hhwtf-data *::before,
.hhwtf-data *::after {
	box-sizing: border-box;
}

.hhwtf-data {
	--hhwtf-surface: #1b1e2e;
	--hhwtf-header: #23273b;
	--hhwtf-border: #2f3450;
	--hhwtf-text: #ffffff;
	--hhwtf-muted: #8b93b0;
	--hhwtf-tag-bg: #2f3450;
	--hhwtf-tag-text: #c7cbe0;
	--hhwtf-accent: #e8615f;
	--hhwtf-rating: #f5a623;
	--hhwtf-good: #4ade80;
	--hhwtf-bad: #ff4d4d;
	--hhwtf-radius: 12px;

	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
	/* No background and no padding — the table is the surface. */
	background: none;
	padding: 0;
	color: var(--hhwtf-text);
	margin: 16px 0;
}

/* --- header ------------------------------------------------------------ */

.hhwtf-data__head {
	display: flex;
	gap: 10px;
	align-items: center;
	flex-wrap: wrap;
	margin-bottom: 10px;
}

.hhwtf-data__title {
	margin: 0;
	font-size: 14px;
	font-weight: 700;
	color: var(--hhwtf-text);
	text-transform: uppercase;
	letter-spacing: .5px;
}

.hhwtf-data__count {
	font-size: 10px;
	font-weight: 600;
	color: var(--hhwtf-muted);
	text-transform: uppercase;
	letter-spacing: .6px;
}

/*
 * Capped width and a visible border so an unlabelled filter box reads as a
 * control rather than an empty bar above the table.
 */
.hhwtf-data__search {
	width: 100%;
	max-width: 220px;
	margin-left: auto;
	padding: 6px 10px;
	border: 1px solid var(--hhwtf-border);
	background: var(--hhwtf-surface);
	color: var(--hhwtf-text);
	border-radius: 8px;
	font-size: 13px;
	line-height: 1.4;
}

.hhwtf-data__search::placeholder { color: var(--hhwtf-muted); }
.hhwtf-data__search:focus { outline: none; border-color: var(--hhwtf-accent); }

/* --- table ------------------------------------------------------------- */

/*
 * `overflow-x: auto` does double duty: it clips the header row to the rounded
 * corners, and it only paints a scrollbar when the table genuinely overflows.
 * The old rule paired this with `min-width: max-content` on the table, which
 * forced the table wider than its container and produced a permanent scrollbar
 * even on a table that fit — that min-width is gone.
 */
.hhwtf-data__scroll {
	background: var(--hhwtf-surface);
	border: 1px solid var(--hhwtf-border);
	border-radius: var(--hhwtf-radius);
	overflow-x: auto;
	-webkit-overflow-scrolling: touch;
	scrollbar-width: thin;
	scrollbar-color: var(--hhwtf-border) transparent;
}

.hhwtf-data__scroll::-webkit-scrollbar { height: 8px; }
.hhwtf-data__scroll::-webkit-scrollbar-track { background: transparent; }
.hhwtf-data__scroll::-webkit-scrollbar-thumb {
	background: var(--hhwtf-border);
	border-radius: 4px;
}

/*
 * Theme resets.
 *
 * Themes (SmartMag among them) style bare `table` elements in post content:
 * a vertical margin, zebra striping, their own borders and cell padding. Our
 * table lives inside a bordered wrapper, so an inherited `table { margin }`
 * paints as blank bands above the header and below the last row — measured at
 * ~30px each on retrohandhelds.gg.
 *
 * These selectors are deliberately one class more specific than the theme's
 * bare-element rules, which is enough to win without reaching for !important.
 */
.hhwtf-data .hhwtf-data__table {
	margin: 0;
	border: 0;
	border-spacing: 0;
	line-height: 1.45;
}

.hhwtf-data .hhwtf-data__table > thead,
.hhwtf-data .hhwtf-data__table > tbody,
.hhwtf-data .hhwtf-data__table > tfoot { margin: 0; border: 0; }

.hhwtf-data .hhwtf-data__table caption { display: none; }

/* Kill inherited zebra striping; the hover rule further down is more specific. */
.hhwtf-data .hhwtf-data__table > tbody > tr,
.hhwtf-data .hhwtf-data__table > tbody > tr:nth-child(even),
.hhwtf-data .hhwtf-data__table > tbody > tr:nth-child(odd) {
	background: none;
}

/* The wrapper shouldn't pick up content margins either. */
.hhwtf-data .hhwtf-data__scroll { margin: 0; }

.hhwtf-data__table {
	width: 100%;
	border-collapse: collapse;
	font-size: 13px;
	background: var(--hhwtf-surface);
}

.hhwtf-data__th {
	background: var(--hhwtf-header);
	padding: 0;
	/* Every column heading is centred, including the label column. */
	text-align: center;
	border-bottom: 1px solid var(--hhwtf-border);
	border-right: 1px solid var(--hhwtf-border);
	white-space: nowrap;
}

.hhwtf-data__th:last-child { border-right: none; }

.hhwtf-data__sort {
	display: flex;
	align-items: center;
	justify-content: center;
	/*
	 * No `gap`: the arrow span sits in every header but stays empty until that
	 * column drives the sort, and a gap beside a zero-width child still shifts
	 * the label 2px off centre — the residue left over after the 1.4.1
	 * box-sizing fix. The spacing lives on the arrow now, so it only exists
	 * when the arrow does.
	 */
	/* box-sizing is reset above; max-width stops any stray sizing from spilling. */
	box-sizing: border-box;
	width: 100%;
	max-width: 100%;
	padding: 11px 14px;
	border: none;
	background: transparent;
	color: var(--hhwtf-muted);
	font: inherit;
	font-size: 10.5px;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: .7px;
	cursor: pointer;
}

.hhwtf-data__sort:hover { color: var(--hhwtf-text); }
.hhwtf-data__sort:focus-visible { outline: 2px solid var(--hhwtf-accent); outline-offset: -2px; }

/* Arrow only appears on the column currently driving the sort. */
.hhwtf-data__sort-arrow::after { content: ""; }
.hhwtf-data__th[data-dir] .hhwtf-data__sort { color: var(--hhwtf-text); }
.hhwtf-data__th[data-dir="asc"] .hhwtf-data__sort-arrow::after { content: "▲"; font-size: 8px; }
.hhwtf-data__th[data-dir="desc"] .hhwtf-data__sort-arrow::after { content: "▼"; font-size: 8px; }
.hhwtf-data__th[data-dir] .hhwtf-data__sort-arrow { margin-left: 4px; }

.hhwtf-data__table tbody tr { transition: background .1s; }
/*
 * Specificity here must match the :nth-child striping resets above (0,3,2) so
 * hover isn't lost on even rows; source order then decides in our favour.
 */
.hhwtf-data .hhwtf-data__table > tbody > tr:hover { background: rgba(255, 255, 255, .025); }
.hhwtf-data__table tbody tr[hidden] { display: none; }

.hhwtf-data__td {
	padding: 12px 14px;
	border-bottom: 1px solid var(--hhwtf-border);
	border-right: 1px solid var(--hhwtf-border);
	text-align: center;
	vertical-align: middle;
}

.hhwtf-data__td:last-child { border-right: none; }
.hhwtf-data__table tbody tr:last-child .hhwtf-data__td { border-bottom: none; }

.hhwtf-data__td--label {
	text-align: left;
	font-weight: 700;
	font-size: 15px;
	color: var(--hhwtf-text);
}

/* Image cells shrink to their thumbnail instead of padding out a wide column. */
.hhwtf-data__td--media,
.hhwtf-data__th--media { width: 1%; white-space: nowrap; }

.hhwtf-data__name { color: var(--hhwtf-text); text-decoration: none; }
.hhwtf-data__name:hover { color: var(--hhwtf-accent); }

/* --- value types ------------------------------------------------------- */

.hhwtf-data__empty-cell { color: var(--hhwtf-muted); opacity: .55; }

.hhwtf-data__pill {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 28px;
	padding: 2px 8px;
	border: 1px solid transparent;
	border-radius: 4px;
	font-size: 11px;
	font-weight: 700;
	line-height: 1.4;
}

.hhwtf-data__pill--yes { background: rgba(74, 222, 128, .12); color: var(--hhwtf-good); border-color: rgba(74, 222, 128, .35); }
.hhwtf-data__pill--no  { background: rgba(139, 147, 176, .10); color: var(--hhwtf-muted); border-color: rgba(139, 147, 176, .25); }

.hhwtf-data__price { color: var(--hhwtf-good); font-weight: 700; }
.hhwtf-data__rating { color: var(--hhwtf-rating); font-weight: 700; }

.hhwtf-data__tags { display: inline-flex; gap: 4px; flex-wrap: wrap; justify-content: center; }

.hhwtf-data__tag {
	background: var(--hhwtf-tag-bg);
	color: var(--hhwtf-tag-text);
	padding: 3px 8px;
	border-radius: 4px;
	font-size: 10px;
	font-weight: 600;
	letter-spacing: .3px;
	/*
	 * Not `nowrap`. Array fields hold short labels most of the time — a console,
	 * a platform, a connectivity slug — but nothing stops a feed value from being
	 * a sentence, and `key_features` routinely is. An unbreakable sentence sets a
	 * min-content width its container can't go below, which blows a card open or
	 * pushes a table column past the scroll wrapper. Wrapping only engages when
	 * there isn't room, so short tags still sit on one line.
	 */
	max-width: 100%;
	white-space: normal;
	overflow-wrap: anywhere;
}

.hhwtf-data__tag--more { color: var(--hhwtf-accent); }

/*
 * List rendering for array fields whose items are sentences rather than labels.
 * `inline-grid` so it still shrinks to its content and sits correctly inside a
 * centred table cell or a right-aligned card row, while the text itself stays
 * left aligned — ragged-right sentences are the readable ones.
 */
.hhwtf-data__list {
	display: inline-grid;
	gap: 3px;
	margin: 0;
	padding: 0;
	max-width: 100%;
	list-style: none;
	text-align: left;
	font-size: 11.5px;
	line-height: 1.45;
	color: var(--hhwtf-tag-text);
	overflow-wrap: anywhere;
}

.hhwtf-data__list li { position: relative; padding-left: 12px; }

.hhwtf-data__list li::before {
	content: "\203A";
	position: absolute;
	left: 2px;
	color: var(--hhwtf-muted);
}

.hhwtf-data__list-more { color: var(--hhwtf-accent); font-weight: 600; }

.hhwtf-data__longtext {
	display: inline-block;
	max-width: 340px;
	/*
	 * Without a floor the table happily squeezes a description into ~180px and
	 * it wraps to ten-plus lines, which is what drives the tall rows.
	 */
	min-width: 200px;
	text-align: left;
	color: var(--hhwtf-muted);
	font-size: 12px;
	line-height: 1.45;
	white-space: normal;
}

/*
 * Line clamp. `-webkit-line-clamp` still requires the legacy flexbox display
 * value, which is why this is a separate block rather than a property on the
 * rule above — applying `-webkit-box` unconditionally would break the unclamped
 * case. The standard `line-clamp` is listed after it for forward compatibility.
 */
.hhwtf-data--clamp .hhwtf-data__longtext {
	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: var(--hhwtf-clamp, 2);
	line-clamp: var(--hhwtf-clamp, 2);
	overflow: hidden;
}

/* Same red as the site's existing download buttons. */
.hhwtf-data__link { color: var(--hhwtf-accent); text-decoration: none; font-weight: 700; }
.hhwtf-data__link:hover { text-decoration: underline; }

/*
 * Obtainium links render as a bordered pill so an "Add to Obtainium" column
 * reads as an action rather than a second Download link sitting next to the
 * first. `white-space: nowrap` keeps the label on one line — the href is ~2.7KB
 * but the visible text is short, so the column should stay narrow.
 */
.hhwtf-data__link--obtainium {
	display: inline-block;
	padding: 5px 12px;
	border: 1px solid var(--hhwtf-accent);
	border-radius: 6px;
	font-size: 11.5px;
	line-height: 1.4;
	white-space: nowrap;
}

.hhwtf-data__link--obtainium:hover {
	background: var(--hhwtf-accent);
	color: #fff;
	text-decoration: none;
}

/*
 * Merged icon + name cell.
 *
 * Two things make this read like a real app row rather than a thumbnail in a
 * box: `cover` lets square artwork reach the rounded edges instead of being
 * letterboxed, and there's no background plate behind it. The standalone image
 * column below keeps `contain` plus a plate, since a wide product shot should
 * not be cropped.
 */
.hhwtf-data__label-wrap {
	display: flex;
	align-items: center;
	gap: 12px;
	text-align: left;
}

.hhwtf-data__label-text { min-width: 0; }

.hhwtf-data__thumb {
	width: 44px;
	height: 44px;
	object-fit: contain;
	border-radius: 8px;
	background: var(--hhwtf-tag-bg);
	display: block;
}

/* Must follow the base rule: same specificity, so source order decides. */
.hhwtf-data__thumb--inline {
	width: 48px;
	height: 48px;
	object-fit: cover;
	border-radius: 10px;
	background: none;
	flex: 0 0 auto;
}

/* --- cards ------------------------------------------------------------- */

/*
 * Card grid.
 *
 * `auto-fill` + `1fr` was the problem: auto-fill keeps empty tracks, and 1fr
 * makes each one absorb the leftover space, so a single card stretched the full
 * width and two cards split it in half. `auto-fit` collapses the empty tracks
 * and the max-track cap stops the survivors from stretching, which leaves real
 * free space for justify-content to centre. One card sits centred at its natural
 * width; a full row still fills out normally.
 */
.hhwtf-data__cards {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(240px, 340px));
	justify-content: center;
	gap: 12px;
}

/*
 * `min-width: 0` down the whole card tree. Grid and flex children take an
 * automatic minimum size of min-content, so a single wide value — a long tag,
 * an unbroken URL — drags its ancestors wider than the card and spills text
 * past the rounded border. Every spec row shares the card's one column track,
 * so one offending row widens all of them: that's why a long description would
 * wrap somewhere out past the card edge rather than at it.
 */
.hhwtf-data__card {
	background: var(--hhwtf-surface);
	border: 1px solid var(--hhwtf-border);
	border-radius: var(--hhwtf-radius);
	padding: 12px 14px;
	min-width: 0;
}

.hhwtf-data__card[hidden] { display: none; }

.hhwtf-data__card-head {
	display: flex;
	align-items: center;
	gap: 10px;
	margin-bottom: 8px;
	min-width: 0;
}

.hhwtf-data__card-title {
	margin: 0;
	font-size: 15px;
	font-weight: 700;
	color: var(--hhwtf-text);
	min-width: 0;
	overflow-wrap: anywhere;
}

.hhwtf-data__card-title a { color: inherit; text-decoration: none; }
.hhwtf-data__card-title a:hover { color: var(--hhwtf-accent); }

/* An implicit `auto` track can't size below its widest item's min-content, so
   it overflows rather than wrapping. `minmax(0, 1fr)` lets it shrink. */
.hhwtf-data__card-specs { margin: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 5px; }

.hhwtf-data__card-row {
	display: flex;
	gap: 10px;
	justify-content: space-between;
	align-items: baseline;
	font-size: 12px;
	min-width: 0;
}

.hhwtf-data__card-row dt {
	color: var(--hhwtf-muted);
	font-size: 10px;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: .5px;
	flex: 0 0 auto;
}

.hhwtf-data__card-row dd { margin: 0; min-width: 0; text-align: right; color: var(--hhwtf-text); overflow-wrap: anywhere; }
/*
 * `display: block` matters: an inline-block takes its baseline from its LAST
 * line, so `align-items: baseline` on the row dropped the label to the bottom
 * of a wrapped paragraph instead of leaving it beside the first line. Left
 * aligned too, unlike the short values around it — a right-aligned paragraph
 * gives every line a ragged left edge, which is hard to read at card width.
 */
.hhwtf-data__card-row dd .hhwtf-data__longtext { display: block; text-align: left; max-width: none; min-width: 0; }
.hhwtf-data__card-row dd .hhwtf-data__list { text-align: left; }
.hhwtf-data__card-row dd .hhwtf-data__tags { justify-content: flex-end; }

/* --- footer / states --------------------------------------------------- */

.hhwtf-data__empty {
	text-align: center;
	color: var(--hhwtf-muted);
	padding: 20px;
	font-size: 13px;
}

.hhwtf-data__credit {
	margin: 8px 0 0;
	font-size: 10px;
	color: var(--hhwtf-muted);
	text-align: right;
	text-transform: uppercase;
	letter-spacing: .5px;
}

.hhwtf-data__credit a { color: var(--hhwtf-accent); text-decoration: none; font-weight: 600; }

.hhwtf-data--error {
	padding: 12px 14px;
	background: rgba(255, 77, 77, .1);
	border: 1px solid rgba(255, 77, 77, .35);
	color: var(--hhwtf-bad);
	border-radius: 8px;
	font-size: 13px;
}

/* --- responsive: table collapses to stacked rows ----------------------- */

@media (max-width: 600px) {
	.hhwtf-data__search { margin-left: 0; max-width: none; }

	.hhwtf-data__table { font-size: 12px; }
	.hhwtf-data__table thead { display: none; }

	.hhwtf-data__table tbody tr {
		display: block;
		padding: 10px 0;
		border-bottom: 1px solid var(--hhwtf-border);
	}

	.hhwtf-data__table tbody tr:last-child { border-bottom: none; }

	.hhwtf-data__td {
		display: flex;
		justify-content: space-between;
		gap: 12px;
		align-items: baseline;
		text-align: right;
		padding: 4px 14px;
		border-bottom: none;
		border-right: none;
	}

	.hhwtf-data__td--media { width: auto; padding-bottom: 8px; }
	.hhwtf-data__td--media .hhwtf-data__thumb { margin-left: auto; }

	/* The label column becomes the row's heading. */
	.hhwtf-data__td--label { display: block; text-align: left; padding-bottom: 6px; }
	.hhwtf-data__label-wrap { gap: 10px; }
	.hhwtf-data__td--label::before { content: none; }

	.hhwtf-data__td:not(.hhwtf-data__td--label)::before {
		content: attr(data-label);
		color: var(--hhwtf-muted);
		font-size: 10px;
		font-weight: 600;
		text-transform: uppercase;
		letter-spacing: .5px;
		text-align: left;
		flex: 0 0 auto;
	}

	.hhwtf-data__tags { justify-content: flex-end; }
	.hhwtf-data__longtext { text-align: right; max-width: none; min-width: 0; }
}

@media (prefers-reduced-motion: reduce) {
	.hhwtf-data * { transition: none !important; }
}
