/*
 * The ranking. Geometry and paint for templates/keepnet.php, nothing else.
 *
 * Colour and type are read from the theme's --bb- tokens, each with its own value beside it as a
 * fallback, so the ranking is complete on a page where the theme has not been loaded.
 *
 * Every rule is written in logical properties. A row is one band: rank, brand, terms, figures and
 * the button, with the expander summary folded under the brand. The band is a grid and the grid
 * changes shape three times, because a layout that is correct at two widths is not correct:
 *
 *   1181 and up   five tracks, one band, the summary under the brand
 *   900 to 1180   four tracks, the terms drop under the brand and the figures
 *   621 to 899    three tracks, brand, figures and terms stacked beside the button
 *   620 and down  one column, the button as wide as the row
 */

.bbr,
.bbr__after {
	--bbr-ground: var(--bb-ground, #0b2c36);
	--bbr-row: var(--bb-row, #12323c);
	--bbr-lift: var(--bb-lift, #173b47);
	--bbr-deep: var(--bb-deep, #071f27);
	--bbr-ink: var(--bb-ink, #d6eef0);
	--bbr-muted: var(--bb-muted, #a9c9cf);
	--bbr-rule: var(--bb-rule, #48666e);
	--bbr-accent: var(--bb-accent, #ff8370);
	--bbr-label: var(--bb-button-ink, #14110f);
	--bbr-text: var(--bb-font-text, 'Barlow', system-ui, 'Segoe UI', Arial, sans-serif);
	--bbr-display: var(--bb-font-display, 'Zilla Slab', Georgia, 'Times New Roman', serif);

	display: block;
	margin-block: 0;
	color: var(--bbr-ink);
	font-family: var(--bbr-text);
	font-size: 17px;
	line-height: 1.45;
}

.bbr *,
.bbr *::before,
.bbr *::after,
.bbr__after *,
.bbr__after *::before,
.bbr__after *::after {
	box-sizing: border-box;
}

.bbr-noway {
	display: none;
}

/* ---- Heading and the one disclosure ---------------------------------------------------------- */

.bbr__head {
	margin: 0 0 8px;
	padding: 0;
	color: var(--bbr-ink);
	font-family: var(--bbr-display);
	font-size: 22px;
	font-weight: 500;
	line-height: 1.25;
	letter-spacing: 0;
}

.bbr__paid {
	margin: 0 0 14px;
	padding: 0;
	color: var(--bbr-muted);
	font-size: 14.2px;
	line-height: 1.45;
}

/* ---- The rows -------------------------------------------------------------------------------- */

.bbr__rows {
	display: flex;
	flex-direction: column;
	gap: 6px;
	margin: 0;
	padding: 0;
	list-style: none;
}

.bbr__row {
	margin: 0;
	padding: 8px 14px;
	list-style: none;
	background-color: var(--bbr-row);
	border: 1px solid var(--bbr-rule);
	border-radius: 2px;
	transition: background-color 150ms ease, border-color 150ms ease, box-shadow 150ms ease, transform 150ms ease;
}

.bbr__row--lead {
	border-color: var(--bbr-accent);
	box-shadow: 0 0 0 4px rgba(255, 131, 112, 0.2);
}

@media (hover: hover) {
	.bbr__row:hover {
		background-color: var(--bbr-lift);
		transform: translateY(-2px);
		box-shadow: 0 6px 0 -2px rgba(4, 18, 23, 0.55);
	}

	.bbr__row--lead:hover {
		box-shadow: 0 0 0 4px rgba(255, 131, 112, 0.2), 0 6px 0 -2px rgba(4, 18, 23, 0.55);
	}
}

.bbr__band {
	display: grid;
	grid-template-columns: 32px minmax(0, 1fr) 240px;
	grid-template-areas:
		"rank brand act"
		"rank terms act"
		"rank more act";
	grid-template-rows: auto auto auto;
	column-gap: 18px;
	row-gap: 4px;
	align-items: center;
	align-content: center;
	min-block-size: 96px;
}

.bbr__rank {
	grid-area: rank;
	align-self: center;
	color: var(--bbr-muted);
	font-family: var(--bbr-display);
	font-size: 20px;
	font-weight: 700;
	line-height: 1;
	font-variant-numeric: tabular-nums lining-nums;
}

/* ---- Brand: the operator's mark, its name, the offer in one line ------------------------------ */

.bbr__brand {
	grid-area: brand;
	display: grid;
	grid-template-columns: 156px minmax(0, 1fr);
	align-items: center;
	gap: 14px;
	min-inline-size: 0;
}

/*
 * The tile is a fixed frame the operator's own mark is fitted into, and never redrawn, recoloured
 * or cropped. Its inner box is 144 by 40, which is the size crl_brand() fits most marks to. A mark
 * that would be under 60 by 20 at that size is given a wider declared box instead, and one wider
 * than the frame — Tweedbet's wordmark is 330 by 27 — is scaled down by the frame while keeping
 * its own ratio, because `height: auto` and `width: auto` with both maxima set is a containment
 * rule rather than a stretch. The 60 by 20 reserved box under the image is what keeps a very wide
 * wordmark from collapsing to a twelve-pixel sliver.
 */
.bbr__tile {
	display: flex;
	align-items: center;
	justify-content: center;
	inline-size: 156px;
	block-size: 56px;
	padding: 6px;
	background-color: var(--bbr-deep);
	border: 1px solid var(--bbr-rule);
	border-radius: 3px;
}

.bbr__tile img {
	display: block;
	inline-size: auto;
	block-size: auto;
	min-inline-size: 60px;
	min-block-size: 20px;
	max-inline-size: 144px;
	max-block-size: 44px;
	object-fit: contain;
	object-position: center;
}

.bbr__who {
	flex: 1 1 auto;
	min-inline-size: 0;
}

.bbr__name {
	margin: 0;
	padding: 0;
	color: var(--bbr-ink);
	font-family: var(--bbr-text);
	font-size: 17px;
	font-weight: 700;
	line-height: 1.2;
	letter-spacing: 0;
	overflow-wrap: break-word;
}

.bbr__row--lead .bbr__name {
	color: var(--bbr-accent);
}

.bbr__offer {
	margin: 2px 0 0;
	padding: 0;
	color: var(--bbr-muted);
	font-size: 13px;
	line-height: 1.3;
}

/* ---- Terms: label and value pairs ------------------------------------------------------------ */

.bbr__terms {
	grid-area: terms;
	display: flex;
	flex-wrap: wrap;
	align-items: baseline;
	align-content: center;
	gap: 2px 18px;
	margin: 0;
	padding: 0;
	min-inline-size: 0;
	font-size: 13.5px;
	line-height: 1.35;
}

.bbr__terms > div {
	display: flex;
	gap: 6px;
	margin: 0;
	padding: 0;
	min-inline-size: 0;
}

.bbr__terms dt {
	margin: 0;
	padding: 0;
	color: var(--bbr-muted);
	font-weight: 400;
}

.bbr__terms dd {
	margin: 0;
	padding: 0;
	color: var(--bbr-ink);
	font-weight: 600;
	min-inline-size: 0;
}

/* ---- Figures: the two numbers a reader came for ---------------------------------------------- */

.bbr__figs {
	display: flex;
	align-items: flex-end;
	gap: 16px;
	margin-block-start: 4px;
	min-inline-size: 0;
}

.bbr__fig {
	flex: 1 1 0;
	display: flex;
	flex-direction: column;
	gap: 2px;
	min-inline-size: 0;
}

.bbr__figk {
	display: block;
	color: var(--bbr-muted);
	font-size: 11.5px;
	font-weight: 600;
	letter-spacing: 0.06em;
	line-height: 1.2;
	text-transform: uppercase;
}

.bbr__figv {
	display: block;
	color: var(--bbr-ink);
	font-family: var(--bbr-display);
	font-size: 30px;
	font-weight: 700;
	line-height: 1.1;
	letter-spacing: 0;
	font-variant-numeric: tabular-nums lining-nums;
	white-space: nowrap;
}

/* ---- Action: the button, and the age line directly under it ---------------------------------- */

.bbr__act {
	grid-area: act;
	display: flex;
	flex-direction: column;
	align-items: stretch;
	justify-content: center;
	gap: 7px;
	min-inline-size: 0;
}

.bbr__go {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 10px;
	inline-size: 100%;
	min-block-size: 44px;
	padding: 10px 16px;
	background-color: var(--bbr-accent);
	border: 3px solid var(--bbr-ink);
	border-radius: 14px;
	box-shadow: 4px 4px 0 0 var(--bbr-deep);
	color: var(--bbr-label);
	font-family: var(--bbr-text);
	font-size: 17px;
	font-weight: 700;
	line-height: 1;
	text-decoration: none;
	cursor: pointer;
	transition: transform 140ms ease, box-shadow 140ms ease, background-color 140ms ease, border-color 140ms ease;
}

.bbr__go-a {
	flex: 0 0 auto;
	display: block;
	transition: transform 140ms ease;
}

.bbr__go:hover {
	background-color: #ff9a8b;
	transform: translate(2px, 2px);
	box-shadow: 2px 2px 0 0 var(--bbr-deep);
	color: var(--bbr-label);
}

.bbr__go:hover .bbr__go-a {
	transform: translateX(3px);
}

.bbr__go:focus-visible {
	outline: 3px solid var(--bbr-ink);
	outline-offset: 3px;
	background-color: #ffb0a4;
	color: var(--bbr-label);
}

.bbr__go:active {
	background-color: #ff6b55;
	transform: translate(4px, 4px);
	box-shadow: 0 0 0 0 var(--bbr-deep);
	color: var(--bbr-label);
}

.bbr__go--none {
	background-color: transparent;
	border-style: dashed;
	box-shadow: none;
	color: var(--bbr-ink);
}

.bbr__small {
	margin: 0;
	padding: 0;
	background: none;
	border: 0;
	color: var(--bbr-muted);
	font-size: 12.5px;
	line-height: 1.25;
	text-align: center;
}

/* ---- Expander: licence, terms and the working ------------------------------------------------ */

/*
 * The expander sits in the same row as the brand, in the column the terms occupy, and its summary
 * is a single line of small underlined text. Folded away it adds no height at all: the row is the
 * band, the band is the row. Opened, it takes the full width beneath and pushes its row taller,
 * which is the one case where a row may exceed its budget.
 */
.bbr__more {
	grid-area: more;
	align-self: end;
	margin: 0;
	padding: 0;
	min-inline-size: 0;
}

/* Opened, the panel takes the full width of the band and pushes the row taller. */
.bbr__more[open] {
	grid-column: 1 / -1;
	grid-row: 3;
	align-self: stretch;
	padding-block-start: 8px;
}

.bbr__more > summary {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	margin: 0;
	padding: 0;
	color: var(--bbr-ink);
	font-size: 12.5px;
	font-weight: 600;
	line-height: 18px;
	white-space: nowrap;
	text-decoration: underline;
	text-decoration-thickness: 1px;
	text-underline-offset: 3px;
	cursor: pointer;
	list-style: none;
}

.bbr__more > summary,
.bbr__rules > summary {
	display: flex;
	align-items: center;
	gap: 8px;
	margin: 0;
	padding: 0;
	color: var(--bbr-ink);
	font-size: 13px;
	font-weight: 600;
	line-height: 24px;
	text-decoration: underline;
	text-decoration-thickness: 1px;
	text-underline-offset: 3px;
	cursor: pointer;
	list-style: none;
}

.bbr__more > summary {
	line-height: 22px;
}

.bbr__more > summary::-webkit-details-marker,
.bbr__rules > summary::-webkit-details-marker {
	display: none;
}

.bbr__more > summary::after,
.bbr__rules > summary::after {
	content: "";
	flex: 0 0 auto;
	inline-size: 7px;
	block-size: 7px;
	border-inline-end: 2px solid currentColor;
	border-block-end: 2px solid currentColor;
	transform: translateY(-2px) rotate(45deg);
	transition: transform 150ms ease;
}

.bbr__more[open] > summary::after,
.bbr__rules[open] > summary::after {
	transform: translateY(1px) rotate(225deg);
}

.bbr__more > summary:focus-visible,
.bbr__rules > summary:focus-visible {
	outline: 3px solid var(--bbr-ink);
	outline-offset: 3px;
}

.bbr__panel {
	padding-block: 12px 4px;
	color: var(--bbr-ink);
	font-size: 14.5px;
	line-height: 1.5;
}

.bbr__licence-line {
	margin: 0 0 10px;
	color: var(--bbr-ink);
	font-weight: 600;
}

.bbr__sets {
	display: grid;
	grid-template-columns: repeat(3, minmax(0, 1fr));
	gap: 14px 28px;
}

.bbr__group {
	margin: 0 0 4px;
	padding: 0 0 4px;
	border-block-end: 1px solid var(--bbr-rule);
	color: var(--bbr-muted);
	font-family: var(--bbr-text);
	font-size: 12px;
	font-weight: 600;
	letter-spacing: 0.06em;
	line-height: 1.3;
	text-transform: uppercase;
}

.bbr__lines {
	margin: 0;
	padding: 0;
}

.bbr__lines > div {
	margin: 0;
	padding: 5px 0;
	border-block-end: 1px dotted var(--bbr-rule);
}

.bbr__lines dt {
	margin: 0;
	color: var(--bbr-muted);
	font-size: 13px;
	font-weight: 400;
}

.bbr__lines dd {
	margin: 0;
	color: var(--bbr-ink);
}

.bbr__v {
	font-weight: 600;
}

.bbr__d {
	display: block;
	color: var(--bbr-muted);
	font-size: 13px;
	line-height: 1.4;
}

.bbr__work {
	margin: 12px 0 0;
	color: var(--bbr-ink);
}

/* ---- Beyond the block: any offer after the fifth goes into a plain table --------------------- */

.bbr__rest {
	margin-block-start: 22px;
}

.bbr__rest-head {
	margin: 0 0 8px;
	padding: 0;
	color: var(--bbr-ink);
	font-family: var(--bbr-display);
	font-size: 20px;
	font-weight: 500;
	line-height: 1.25;
}

.bbr__rest-wrap {
	overflow-x: auto;
}

.bbr__rest-tab {
	inline-size: 100%;
	border-collapse: collapse;
	font-size: 15px;
	line-height: 1.4;
}

.bbr__rest-tab th,
.bbr__rest-tab td {
	padding: 10px 12px;
	border-block-end: 1px solid var(--bbr-rule);
	text-align: start;
	vertical-align: top;
	background: none;
}

.bbr__rest-tab thead th {
	border-block-end: 2px solid var(--bbr-rule);
	background-color: var(--bb-tint, #1f3f49);
	font-size: 13px;
	font-weight: 700;
	letter-spacing: 0.06em;
	text-transform: uppercase;
}

.bbr__plain {
	color: var(--bbr-ink);
	font-weight: 600;
	text-decoration: underline;
	text-decoration-thickness: 2px;
	text-underline-offset: 3px;
}

.bbr__plain:focus-visible {
	outline: 3px solid var(--bbr-ink);
	outline-offset: 3px;
}

/* ---- What a licence would add, and the dated line ------------------------------------------- */

.bbr__rules {
	margin-block-start: 18px;
	padding: 8px 16px;
	border: 1px solid var(--bbr-rule);
	border-radius: 2px;
}

.bbr__rules > summary {
	font-size: 14.5px;
}

.bbr__rules .bbr__panel {
	padding-block: 10px 4px;
	columns: 2 340px;
	column-gap: 36px;
}

.bbr__rules .bbr__panel p {
	margin: 0 0 12px;
	break-inside: avoid;
}

.bbr__dated {
	margin: 18px 0 0;
	padding: 0;
	color: var(--bbr-muted);
	font-size: 14px;
	line-height: 1.45;
}

.bbr__editor {
	margin: 0 0 12px;
	padding: 12px 16px;
	border: 1px dashed var(--bbr-rule);
	color: var(--bbr-ink);
	font-size: 15px;
}

/* ---- 900 to 1180: two tracks, the terms under the brand --------------------------------------- */

@media (max-width: 1180px) {
	.bbr__band {
		grid-template-columns: 30px minmax(0, 1fr) 240px;
		grid-template-areas:
			"rank brand act"
			"rank terms act"
			"rank more act";
		row-gap: 4px;
	}

	.bbr__figs {
		max-inline-size: 400px;
	}

	.bbr__more[open] {
		grid-column: 1 / -1;
		grid-row: 4;
	}
}

/* ---- 621 to 899: two tracks, narrower button -------------------------------------------------- */

@media (max-width: 899px) {
	.bbr__band {
		grid-template-columns: 26px minmax(0, 1fr) 232px;
		grid-template-areas:
			"rank brand act"
			"rank terms act"
			"rank more act";
	}

	.bbr__sets {
		grid-template-columns: repeat(2, minmax(0, 1fr));
	}

	/* The two figures take the width they need and wrap when the column is narrow, so a wide sum never runs into the next figure. */
	.bbr__figs {
		flex-wrap: wrap;
		gap: 4px 16px;
	}

	.bbr__fig {
		flex: 0 1 auto;
	}

	.bbr__figv {
		font-size: 26px;
	}
}

/* Between 621 and 700 the brand column is under 160 pixels wide, so the figures are set a little smaller. */
@media (min-width: 621px) and (max-width: 700px) {
	.bbr__figv {
		font-size: 22px;
	}
}

/* ---- 620 and down: one column, the button as wide as the row --------------------------------- */

@media (max-width: 620px) {
	.bbr__row {
		padding: 12px;
	}

	.bbr__band {
		grid-template-columns: 22px minmax(0, 1fr);
		grid-template-areas:
			"rank brand"
			"terms terms"
			"more more"
			"act act";
		row-gap: 8px;
	}

	.bbr__rank {
		align-self: start;
		padding-block-start: 6px;
	}

	.bbr__brand {
		grid-template-columns: 108px minmax(0, 1fr);
		gap: 10px;
		align-items: center;
	}

	.bbr__tile {
		inline-size: 108px;
		block-size: 44px;
		padding: 4px;
	}

	.bbr__tile img {
		max-inline-size: 100px;
		max-block-size: 34px;
	}

	.bbr__name {
		font-size: 16px;
		line-height: 1.2;
	}

	.bbr__offer {
		font-size: 12px;
	}

	.bbr__figs {
		max-inline-size: none;
		gap: 4px 12px;
		margin-block-start: 2px;
	}

	.bbr__figv {
		font-size: 24px;
	}

	.bbr__terms {
		gap: 0 14px;
		font-size: 12.5px;
	}

	.bbr__more[open] {
		grid-column: 1 / -1;
		grid-row: 5;
	}

	.bbr__more > summary {
		min-block-size: 24px;
		line-height: 24px;
	}

	.bbr__sets {
		grid-template-columns: minmax(0, 1fr);
	}

	.bbr__rules {
		padding-inline: 16px;
	}
}

/* ---- Quiet for those who ask for it ---------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
	.bbr__row,
	.bbr__go,
	.bbr__go-a,
	.bbr__more > summary::after,
	.bbr__rules > summary::after {
		transition-property: background-color, border-color, box-shadow;
	}

	.bbr__row:hover,
	.bbr__go:hover,
	.bbr__go:active,
	.bbr__go:hover .bbr__go-a {
		transform: none;
	}
}

/* ---- a closed expander keeps its text out of the layout, so it is never measured under the button ---- */

.bbr__more:not([open]) > .bbr__panel {
	display: none;
}

/* ---- on the five track band an opened panel starts at the brand column, so it never runs over the rank numeral ---- */

@media (min-width: 1181px) {
	.bbr__more[open] {
		grid-column: 2 / -1;
	}
}

/* ---- on a phone the long Tweedbet mark is moved above the name and given a wider frame ---- */

@media (max-width: 620px) {
	.bbr__brand:has(.bbr__tile img[src*="tweedbet"]) {
		grid-template-columns: minmax(0, 1fr);
		row-gap: 6px;
	}

	.bbr__brand:has(.bbr__tile img[src*="tweedbet"]) .bbr__tile {
		inline-size: 164px;
		max-inline-size: 100%;
		block-size: 44px;
	}

	.bbr__brand:has(.bbr__tile img[src*="tweedbet"]) .bbr__tile img {
		max-inline-size: 152px;
	}
}
