/*
 * The rules area.
 *
 * Laid out with the theme's own parts: lempar's cards, rows, chips, buttons and
 * callouts do most of the drawing, and this file adds only what a rule book
 * needs and they do not have. Colours and sizes are the theme's tokens, with the
 * browser's system colours behind them so the pages stay readable under another
 * theme: this plugin has no dependency on lempar or on the rest of the family.
 */

.wpfb-rules {
	--wpfb-rules-ink: var(--wp--preset--color--contrast, CanvasText);
	--wpfb-rules-muted: var(--wp--preset--color--muted, GrayText);
	--wpfb-rules-line: var(--wp--preset--color--line, GrayText);
	--wpfb-rules-accent: var(--wp--preset--color--accent, LinkText);
	--wpfb-rules-spirit: var(--wp--preset--color--spirit, LinkText);
	--wpfb-rules-alert: var(--wp--preset--color--alert, LinkText);
	--wpfb-rules-small: var(--wp--preset--font-size--small, 0.8125rem);
	--wpfb-rules-tap: var(--wp--custom--tap-target, 2.75rem);
	--wpfb-rules-gap-s: var(--wp--preset--spacing--20, 0.5rem);
	--wpfb-rules-gap-m: var(--wp--preset--spacing--30, 0.75rem);
	--wpfb-rules-gap: var(--wp--preset--spacing--40, 1rem);
	--wpfb-rules-gap-l: var(--wp--preset--spacing--60, 1.625rem);

	box-sizing: border-box;
	width: 100%;
	max-width: 48rem;
	margin-inline: auto;
	padding: 0 var(--wpfb-rules-gap) var(--wp--preset--spacing--70, 2.5rem);
	color: var(--wpfb-rules-ink);
	overflow-wrap: break-word;
}

/* lempar's parts set `display`, which would otherwise beat the attribute. */
.wpfb-rules [hidden] {
	display: none !important;
}

.wpfb-rules > * + * {
	margin-block-start: var(--wpfb-rules-gap);
}

/*
 * These clear their own margins, here or in the theme, and an equally weighted rule
 * would take the space above them too: the version line sat 0px under the chips.
 */
.wpfb-rules > * + .wpfb-rules-version,
.wpfb-rules > * + .wpfb-rules-tree,
.wpfb-rules > * + .lempar-stack,
.wpfb-rules > * + .wpfb-rules-definitions {
	margin-block-start: var(--wpfb-rules-gap);
}

.wpfb-rules h2,
.wpfb-rules h3,
.wpfb-rules h4 {
	margin: 0;
	line-height: 1.25;
}

.wpfb-rules h2 {
	font-size: var(--wp--preset--font-size--large, 1.1875rem);
}

.wpfb-rules h3 {
	font-size: var(--wp--preset--font-size--medium, 1rem);
}

.wpfb-rules h4 {
	color: var(--wpfb-rules-muted);
	font-size: var(--wpfb-rules-small);
}

/* Links in running text are told by their underline, so the ink keeps its contrast. */
.wpfb-rules-text a,
.wpfb-rules-credit a,
.wpfb-rules-version a,
.wpfb-rules-revision a,
.wpfb-rules-resources h3 a,
.wpfb-rules-change a,
.wpfb-rules .lempar-callout a,
.wpfb-rules-address a {
	color: inherit;
	text-decoration: underline;
	text-decoration-color: var(--wpfb-rules-accent);
	text-decoration-thickness: 2px;
	text-underline-offset: 0.15em;
}

/*
 * Padding on an inline box takes no room in the line, so a link inside a sentence
 * gets 44px to land on without moving a word. 1.1em is just under the height of the
 * text's own box, measured at 1.19em in the theme's body face, so the sum comes out
 * at the tap size or a little over at every text size.
 */
.wpfb-rules-xref,
.wpfb-rules-credit a,
.wpfb-rules-version a,
.wpfb-rules .lempar-callout a,
.wpfb-rules-source a {
	padding-block: calc((var(--wpfb-rules-tap) - 1.1em) / 2);
}

/* The theme's highlight ink reads 4.43:1 on its own tint; the page's ink does not fall short. */
.wpfb-rules .is-style-pill.is-tone-highlight {
	color: var(--wpfb-rules-ink);
}

/* The head. */

.wpfb-rules-title {
	margin: 0;
	font-size: var(--wp--preset--font-size--x-large, 1.75rem);
	line-height: 1.15;
}

.wpfb-rules-lede {
	margin: 0.25rem 0 0;
	color: var(--wpfb-rules-muted);
}

.wpfb-rules-crumbs ol {
	display: flex;
	flex-wrap: wrap;
	margin: 0;
	padding: 0;
	font-size: var(--wpfb-rules-small);
	list-style: none;
}

.wpfb-rules-crumbs li + li::before {
	padding-inline: 0.25rem;
	color: var(--wpfb-rules-muted);
	content: "/";
}

.wpfb-rules-crumbs li {
	display: flex;
	align-items: center;
}

.wpfb-rules-crumbs a {
	display: inline-flex;
	align-items: center;
	min-height: var(--wpfb-rules-tap);
	min-width: var(--wpfb-rules-tap);
	color: inherit;
	font-weight: 700;
}

.wpfb-rules-search {
	display: flex;
	gap: var(--wpfb-rules-gap-s);
	align-items: stretch;
}

.wpfb-rules-search input[type="search"] {
	flex: 1 1 auto;
	width: auto;
	min-width: 0;
	min-height: var(--wpfb-rules-tap);
	margin: 0;
}

.wpfb-rules-search .lempar-button {
	flex: 0 0 auto;
}

.wpfb-rules-nav ul {
	flex-wrap: wrap;
	overflow: visible;
	margin: 0;
	padding: 0;
	list-style: none;
}

.wpfb-rules-version {
	margin: 0;
	color: var(--wpfb-rules-muted);
	font-size: var(--wpfb-rules-small);
	line-height: 1.45;
}

.wpfb-rules .lempar-callout p {
	margin: 0;
}

/* The list of sections. */

ol.wpfb-rules-sections,
.wpfb-rules ul.lempar-stack,
.wpfb-rules ol.lempar-stack {
	margin-inline: 0;
	padding: 0;
	list-style: none;
}

.wpfb-rules-sections__number {
	flex: 0 0 auto;
	min-width: 1.75rem;
	font-size: var(--wp--preset--font-size--large, 1.1875rem);
	font-weight: 800;
	font-variant-numeric: tabular-nums;
	text-align: center;
}

/* Rules. */

.wpfb-rules-text {
	line-height: 1.55;
}

.wpfb-rules-text p {
	margin: 0 0 var(--wpfb-rules-gap-s);
}

.wpfb-rules-text p:last-child {
	margin-block-end: 0;
}

.wpfb-rules-text ul {
	margin: 0 0 var(--wpfb-rules-gap-s);
	padding-inline-start: 1.25rem;
}

.wpfb-rules-tree {
	margin: 0;
	padding: 0;
	list-style: none;
}

.wpfb-rules-tree .wpfb-rules-tree {
	margin-block-start: var(--wpfb-rules-gap-s);
	padding-inline-start: var(--wpfb-rules-gap-m);
	border-inline-start: 2px solid var(--wpfb-rules-line);
}

.wpfb-rules-rule {
	margin-block-end: var(--wpfb-rules-gap-m);
	scroll-margin-block-start: 6rem;
}

.wpfb-rules-rule:last-child {
	margin-block-end: 0;
}

.wpfb-rules-rule__line {
	display: flow-root;
}

/*
 * The number runs into the text, so a deep rule like 18.1.1.5.1 costs no column
 * of its own on a narrow phone. Padding with matching negative margins makes the
 * target 44px without moving a line of the text: worked from the line height, since
 * a fixed 0.625rem came to 42px at the theme's. The pixel off the bottom is for
 * rounding: a float ending 1/64px below its line pushes the next line aside, and at
 * some widths every rule's second line was indented. The first values are for a
 * browser without the `lh` unit.
 */
.wpfb-rules-rule__number {
	box-sizing: border-box;
	float: inline-start;
	min-width: var(--wpfb-rules-tap);
	min-height: var(--wpfb-rules-tap);
	margin: -0.625rem 0.125rem -0.625rem -0.5rem;
	margin-block: calc((1lh - var(--wpfb-rules-tap)) / 2) calc((1lh - var(--wpfb-rules-tap)) / 2 - 1px);
	padding: 0.625rem 0.5rem;
	padding-block: calc((var(--wpfb-rules-tap) - 1lh) / 2);
	font-weight: 800;
	font-variant-numeric: tabular-nums;
}

.wpfb-rules a.wpfb-rules-rule__number {
	color: inherit;
	text-decoration: underline;
	text-decoration-color: var(--wpfb-rules-accent);
	text-decoration-thickness: 2px;
	text-underline-offset: 0.15em;
}

.wpfb-rules-rule__after {
	margin-block-start: var(--wpfb-rules-gap-s);
}

.wpfb-rules-missing {
	color: var(--wpfb-rules-muted);
	font-style: italic;
}

.wpfb-rules-above {
	display: flow-root;
	padding-block-end: var(--wpfb-rules-gap-s);
	border-block-end: 1px solid var(--wpfb-rules-line);
	color: var(--wpfb-rules-muted);
	font-size: 0.9375rem;
}

.wpfb-rules-tree--one > .wpfb-rules-rule > .wpfb-rules-rule__line {
	font-size: var(--wp--preset--font-size--large, 1.1875rem);
	line-height: 1.5;
}

.wpfb-rules-share {
	display: flex;
	flex-wrap: wrap;
	gap: var(--wpfb-rules-gap-s);
	align-items: center;
}

.wpfb-rules-address {
	flex: 1 1 100%;
	margin: 0;
	font-size: var(--wpfb-rules-small);
	overflow-wrap: anywhere;
}

.wpfb-rules-address a {
	display: inline-flex;
	align-items: center;
	min-height: var(--wpfb-rules-tap);
}

.wpfb-rules-history .is-style-pill {
	margin-inline-end: 0.25rem;
}

.wpfb-rules-english__rule {
	display: block;
}

.wpfb-rules-english__rule + .wpfb-rules-english__rule {
	margin-block-start: var(--wpfb-rules-gap-s);
}

.wpfb-rules-english__number {
	margin-block-end: 0.125rem !important;
	font-size: var(--wpfb-rules-small);
	font-weight: 800;
}

.wpfb-rules-pager {
	display: flex;
	flex-wrap: wrap;
	gap: var(--wpfb-rules-gap-s);
	justify-content: space-between;
}

/* The field. */

.wpfb-rules-figure {
	margin-inline: 0;
}

.wpfb-rules-field {
	display: block;
	width: 100%;
	max-width: 22rem;
	height: auto;
	margin-inline: auto;
	font-family: inherit;
}

.wpfb-rules-field text {
	fill: var(--wpfb-rules-ink);
}

.wpfb-rules-field .wpfb-rules-field__small {
	fill: var(--wpfb-rules-muted);
	font-size: 13px;
}

.wpfb-rules-field__zone {
	font-size: 15px;
	font-weight: 700;
}

.wpfb-rules-field__main {
	font-size: 16px;
	font-weight: 800;
}

.wpfb-rules-field__end {
	fill: color-mix(in srgb, var(--wpfb-rules-spirit) 16%, transparent);
}

.wpfb-rules-field__edge {
	fill: none;
	stroke: var(--wpfb-rules-ink);
	stroke-width: 2;
}

.wpfb-rules-field__goal,
.wpfb-rules-field__mark {
	stroke: var(--wpfb-rules-ink);
	stroke-width: 2;
}

.wpfb-rules-field__dim {
	stroke: var(--wpfb-rules-muted);
	stroke-width: 1;
}

.wpfb-rules-figure figcaption {
	margin-block-start: var(--wpfb-rules-gap-s);
	color: var(--wpfb-rules-muted);
	font-size: var(--wpfb-rules-small);
	line-height: 1.45;
}

/* Definitions. */

.wpfb-rules-definitions {
	margin: 0;
}

.wpfb-rules-definition {
	padding-block: var(--wpfb-rules-gap-m);
	border-block-end: 1px solid var(--wpfb-rules-line);
	scroll-margin-block-start: 6rem;
}

.wpfb-rules-definition dt {
	font-weight: 800;
}

.wpfb-rules-definition dt a {
	display: inline-flex;
	align-items: center;
	min-width: var(--wpfb-rules-tap);
	min-height: var(--wpfb-rules-tap);
}

.wpfb-rules-definition dd {
	margin: 0;
}

.wpfb-rules-definition__en {
	color: var(--wpfb-rules-muted);
	font-size: var(--wpfb-rules-small);
	font-weight: 500;
}

/* One long page. */

.wpfb-rules-document > section {
	margin-block-start: var(--wpfb-rules-gap-l);
}

.wpfb-rules-document > section > h2 {
	margin-block-end: var(--wpfb-rules-gap-m);
}

.wpfb-rules-document > section > h2 a {
	display: inline-flex;
	align-items: center;
	min-height: var(--wpfb-rules-tap);
}

/* Versions. */

.wpfb-rules-revision {
	padding-block-start: var(--wpfb-rules-gap-s);
	border-block-start: 1px solid var(--wpfb-rules-line);
}

.wpfb-rules-revision p {
	margin: 0;
}

.wpfb-rules-revision a {
	display: inline-flex;
	align-items: center;
	min-height: var(--wpfb-rules-tap);
}

.wpfb-rules-revision__name {
	display: flex;
	flex-wrap: wrap;
	gap: var(--wpfb-rules-gap-s);
	align-items: center;
	font-weight: 700;
}

/* Changes. */

.wpfb-rules-pick {
	display: grid;
	gap: var(--wpfb-rules-gap-s);
}

.wpfb-rules-pick p {
	display: grid;
	gap: 0.25rem;
	margin: 0;
}

.wpfb-rules-pick label {
	font-size: var(--wpfb-rules-small);
	font-weight: 700;
}

.wpfb-rules-pick select {
	box-sizing: border-box;
	width: 100%;
	min-height: var(--wpfb-rules-tap);
}

.wpfb-rules-filter {
	flex-wrap: wrap;
	overflow: visible;
}

.wpfb-rules-tally {
	display: flex;
	flex-wrap: wrap;
	gap: 0.25rem var(--wpfb-rules-gap-m);
	margin: 0;
	padding: 0;
	color: var(--wpfb-rules-muted);
	font-size: var(--wpfb-rules-small);
	list-style: none;
}

/* The chips say the same once the script has shown them. */
.wpfb-rules-filter:not([hidden]) + .wpfb-rules-tally {
	display: none;
}

.wpfb-rules-change {
	scroll-margin-block-start: 6rem;
}

.wpfb-rules-change__head {
	display: flex;
	flex-wrap: wrap;
	gap: var(--wpfb-rules-gap-s);
	align-items: center;
	justify-content: space-between;
}

.wpfb-rules-change__head h3 {
	font-size: var(--wp--preset--font-size--large, 1.1875rem);
}

.wpfb-rules-change__head h3 a {
	display: inline-flex;
	align-items: center;
	min-width: var(--wpfb-rules-tap);
	min-height: var(--wpfb-rules-tap);
}

.wpfb-rules-change__from {
	color: var(--wpfb-rules-muted);
	font-size: var(--wpfb-rules-small);
	font-weight: 500;
}

.wpfb-rules-change__part {
	display: grid;
	gap: 0.25rem;
	line-height: 1.55;
}

.wpfb-rules-change__part p {
	margin: 0;
}

.wpfb-rules-diff del,
.wpfb-rules-diff ins {
	border-radius: 0.1875rem;
	padding-inline: 0.125rem;
	color: inherit;
}

.wpfb-rules-diff del {
	background-color: color-mix(in srgb, var(--wpfb-rules-alert) 22%, transparent);
	text-decoration: line-through;
}

.wpfb-rules-diff ins {
	background-color: color-mix(in srgb, var(--wpfb-rules-spirit) 24%, transparent);
	text-decoration: underline;
}

/* Colour and a line are for the eye; a screen reader is told in words. */
.wpfb-rules-diff del::before,
.wpfb-rules-diff ins::before {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
	content: " [" attr(data-label) ": ";
}

.wpfb-rules-diff del::after,
.wpfb-rules-diff ins::after {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
	content: "] ";
}

/* Search. */

.wpfb-rules-results .lempar-row__meta {
	display: block;
}

/* 25% left the ink at 4.10:1 on it in the light scheme. */
.wpfb-rules-results mark {
	background-color: color-mix(in srgb, var(--wpfb-rules-accent) 15%, transparent);
	color: inherit;
}

/* Resources. */

.wpfb-rules-resources {
	display: grid;
	gap: var(--wpfb-rules-gap-m);
	margin-block-start: var(--wpfb-rules-gap-l);
}

.wpfb-rules-resources p {
	margin: 0;
}

.wpfb-rules-resources h3 a {
	display: inline-flex;
	align-items: center;
	min-height: var(--wpfb-rules-tap);
}

.wpfb-rules-source summary {
	display: flex;
	align-items: center;
	min-height: var(--wpfb-rules-tap);
	color: var(--wpfb-rules-muted);
	font-size: var(--wpfb-rules-small);
	font-weight: 700;
	list-style: none;
	cursor: pointer;
}

.wpfb-rules-source summary::-webkit-details-marker {
	display: none;
}

/*
 * `display: flex` takes the browser's triangle away, and 24 cards then ended in
 * the word "Sumber" with nothing to say it opens. Drawn as the theme draws the
 * chevron on an expanding row, so everything that opens here points the same way.
 */
.wpfb-rules-source summary::after {
	flex-shrink: 0;
	width: 0.4375rem;
	height: 0.4375rem;
	margin-inline-start: 0.5rem;
	border-right: 2px solid currentcolor;
	border-bottom: 2px solid currentcolor;
	content: "";
	transform: translateY(-0.125rem) rotate(45deg);
}

.wpfb-rules-source[open] summary::after {
	transform: translateY(0.125rem) rotate(-135deg);
}

.wpfb-rules-source dl {
	display: grid;
	gap: var(--wpfb-rules-gap-s);
	margin: 0;
	font-size: var(--wpfb-rules-small);
}

.wpfb-rules-source dt {
	color: var(--wpfb-rules-muted);
}

.wpfb-rules-source dd {
	margin: 0;
}

.wpfb-rules-hash {
	font-variant-numeric: tabular-nums;
	overflow-wrap: anywhere;
}

/* What every page ends with. */

.wpfb-rules-credit {
	margin-block-start: var(--wpfb-rules-gap-l);
	padding-block-start: var(--wpfb-rules-gap);
	border-block-start: 1px solid var(--wpfb-rules-line);
	color: var(--wpfb-rules-muted);
	font-size: var(--wpfb-rules-small);
	line-height: 1.5;
}

.wpfb-rules-credit p {
	margin: 0 0 var(--wpfb-rules-gap-s);
}

/* A rule book gets printed. */

@media print {

	.wpfb-rules-search,
	.wpfb-rules-nav,
	.wpfb-rules-share,
	.wpfb-rules-pager,
	.wpfb-rules-filter {
		display: none !important;
	}
}
