/* Aspect ratio calculator: the fields on one side, the shape drawn to scale on the other.
   ========================================================================== */

.pst-ar {
	display: grid;
	grid-template-columns: minmax(0, 1.12fr) minmax(0, 0.88fr);
	gap: clamp(20px, 3vw, 36px);
}

.pst-ar__form,
.pst-ar__panel {
	display: flex;
	flex-direction: column;
	gap: 24px;
	min-width: 0;
}

.pst-ar__panel[hidden] {
	display: none;
}

/* A tiny outline drawn in the proportions of the ratio it stands for. */
.pst-ar__glyph {
	flex: none;
	width: calc(16px * min(1, var(--w) / var(--h)));
	height: calc(16px * min(1, var(--h) / var(--w)));
	min-width: 5px;
	min-height: 5px;
	border: 1.5px solid currentColor;
	border-radius: 2px;
}

.pst-ar__row {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 12px;
}

.pst-ar__row .pst-select {
	flex: 1 1 200px;
}

.pst-ar__pair {
	display: grid;
	grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
	gap: 10px;
	align-items: end;
}

.pst-ar__pair--ratio {
	flex: 1 1 200px;
	max-width: 260px;
}

.pst-ar__between {
	display: flex;
	align-items: center;
	justify-content: center;
	height: 52px;
	color: var(--pst-muted);
	font-family: var(--pst-display);
	font-size: 22px;
	font-weight: 700;
}

.pst .pst-ar__exact {
	color: var(--pst-muted);
}

.pst-ar__common {
	display: flex;
	flex-direction: column;
	gap: 10px;
}

.pst-ar__common .pst-chip {
	min-height: 40px;
	padding: 0 12px;
	font-size: 14px;
}

/* The answer of "find a ratio", right under the two fields. */
.pst-ar__found {
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	gap: 6px;
	padding: 18px 20px;
	border-radius: 16px;
	background: var(--pst-paper);
}

.pst-ar__found-value {
	font-family: var(--pst-display);
	font-size: clamp(34px, 4vw, 46px);
	font-weight: 700;
	font-variant-numeric: tabular-nums;
	letter-spacing: -0.02em;
	line-height: 1.05;
}

.pst-ar__found-note {
	color: var(--pst-soft);
	font-size: 15px;
}

/* Result: the shape with its measurements, the numbers, and the copy button. */
.pst-ar__result {
	display: flex;
	flex-direction: column;
	gap: 20px;
	min-width: 0;
	padding: clamp(16px, 2vw, 24px);
	border: 1px solid var(--pst-line);
	border-radius: 16px;
	background: var(--pst-paper);
}

.pst-ar__stage {
	display: flex;
	flex: 1 0 auto;
	align-items: center;
	justify-content: center;
	/* Room for the tallest shape with its measurements, so the page keeps its height while the shape changes. */
	min-height: 248px;
}

/* Until the script has fitted the shape to a narrow screen, nothing may stick out of the stage. */
.pst:not([data-pst-ready]) .pst-ar__stage {
	overflow: hidden;
}

.pst-ar__figure {
	display: inline-grid;
	grid-template-columns: auto 64px;
	grid-template-rows: auto 30px;
	gap: 10px 12px;
}

.pst-ar__shape {
	display: flex;
	align-items: center;
	justify-content: center;
	border-radius: 6px;
	background-color: var(--pst-ink);
	background-image: repeating-linear-gradient(90deg, rgba(250, 247, 242, 0.05) 0, rgba(250, 247, 242, 0.05) 1px, transparent 1px, transparent 16px);
	color: var(--pst-paper);
	font-family: var(--pst-display);
	font-size: 20px;
	font-weight: 700;
	font-variant-numeric: tabular-nums;
	line-height: 1;
	white-space: nowrap;
	transition: width 0.18s, height 0.18s;
}

.pst-ar__shape.is-small {
	font-size: 0;
}

/* Dimension lines, as on a technical drawing. */
.pst-ar__dim {
	position: relative;
	color: var(--pst-ink);
	font-size: 13px;
	font-weight: 600;
	font-variant-numeric: tabular-nums;
	line-height: 1.2;
	white-space: nowrap;
}

.pst-ar__dim--h {
	padding-top: 16px;
	text-align: center;
}

.pst-ar__dim--h::before {
	position: absolute;
	top: 0;
	right: 0;
	left: 0;
	height: 11px;
	border-right: 2px solid var(--pst-ink);
	border-left: 2px solid var(--pst-ink);
	background: linear-gradient(var(--pst-ink), var(--pst-ink)) center / 100% 2px no-repeat;
	content: "";
}

.pst-ar__dim--v {
	display: flex;
	align-items: center;
	padding-left: 18px;
}

.pst-ar__dim--v::before {
	position: absolute;
	top: 0;
	bottom: 0;
	left: 0;
	width: 11px;
	border-top: 2px solid var(--pst-ink);
	border-bottom: 2px solid var(--pst-ink);
	background: linear-gradient(var(--pst-ink), var(--pst-ink)) center / 2px 100% no-repeat;
	content: "";
}

/* The small figures share a row in equal parts. A caption that is long in some language keeps its
   width, and when the row gets too full the last figure moves to the next line. */
.pst .pst-ar__facts {
	display: flex;
	flex-wrap: wrap;
	gap: 14px 16px;
	padding-top: 18px;
	border-top: 1px solid var(--pst-line);
}

.pst-ar__fact {
	display: flex;
	flex: 1 1 0;
	flex-direction: column;
	gap: 2px;
	min-width: max-content;
}

.pst-ar__fact--main {
	flex: 0 0 100%;
	min-width: 0;
}

.pst-ar__fact dt {
	color: var(--pst-muted);
	font-size: 13px;
	font-weight: 400;
}

.pst-ar__fact dd {
	font-size: 17px;
	font-weight: 600;
	font-variant-numeric: tabular-nums;
}

.pst-ar__fact--main dd {
	overflow-wrap: anywhere;
}

.pst-ar__fact--main dd {
	font-family: var(--pst-display);
	font-size: clamp(28px, 3.2vw, 38px);
	font-weight: 700;
	letter-spacing: -0.02em;
	line-height: 1.1;
}

@container pst (max-width: 840px) {
	.pst-ar {
		grid-template-columns: minmax(0, 1fr);
	}
}

@container pst (max-width: 450px) {
	.pst-ar__figure {
		grid-template-columns: auto 58px;
	}
}

/* Browsers from before 2023 cannot measure the place a tool sits in: there the screen decides. */
@supports not (container-type: inline-size) {
	@media (max-width: 900px) {
		.pst-ar {
			grid-template-columns: minmax(0, 1fr);
		}
	}
}

@media (prefers-reduced-motion: reduce) {
	.pst-ar__shape {
		transition: none;
	}
}
