/**
 * Teletext viewer — strict row grid inside the black screen.
 */

.retrotext-viewport {
	--retrotext-page-rows: 24;
	--retrotext-status-rows: 1;
	--retrotext-header-rows: 3;
	--retrotext-body-rows: 18;
	--retrotext-footer-rows: 2;
	--retrotext-text-indent: 12px;
	--retrotext-footer-link-gap: 24px;
	--retrotext-row-height: calc(100cqh / var(--retrotext-page-rows));
	width: 100%;
	height: 100%;
	background: #000;
	box-sizing: border-box;
	overflow: hidden;
	display: flex;
	flex-direction: column;
	align-items: stretch;
	justify-content: flex-start;
	container-type: size;
	position: absolute;
	inset: 0;
}

.retrotext-grid {
	display: flex;
	flex-direction: column;
	flex: 1 1 auto;
	align-self: stretch;
	width: 100%;
	height: 100%;
	min-height: 0;
	min-width: 0;
	font-size: calc(var(--retrotext-row-height) * 0.72);
	line-height: var(--retrotext-row-height);
	letter-spacing: var(--retrotext-letter-spacing, 0.02em);
	word-spacing: var(--retrotext-word-spacing, normal);
	user-select: none;
	overflow: hidden;
}

.retrotext-grid__status,
.retrotext-grid__header,
.retrotext-grid__footer {
	flex: 0 0 auto;
	width: 100%;
	overflow: hidden;
}

.retrotext-grid__status {
	height: calc(var(--retrotext-row-height) * var(--retrotext-status-rows));
	background: #000;
	position: relative;
	z-index: 2;
	isolation: isolate;
}

.retrotext-grid__status--solid {
	border-bottom: 2px solid #000;
}

.retrotext-grid__status + .retrotext-grid__header {
	position: relative;
	z-index: 1;
}

.retrotext-grid__header {
	height: calc(var(--retrotext-row-height) * var(--retrotext-header-rows));
	position: relative;
	overflow: visible;
}

.retrotext-grid__header--overlap {
	overflow: visible;
	z-index: 1;
}

.retrotext-grid__body {
	flex: 0 0 auto;
	height: calc(var(--retrotext-row-height) * var(--retrotext-body-rows) - var(--retrotext-page-entry-footer-gap, 0px) - var(--retrotext-page-entry-top-gap, 0px));
	max-height: calc(var(--retrotext-row-height) * var(--retrotext-body-rows) - var(--retrotext-page-entry-footer-gap, 0px) - var(--retrotext-page-entry-top-gap, 0px));
	min-height: 0;
	box-sizing: border-box;
	padding-top: var(--retrotext-header-body-gap, 0);
	background: #000;
	overflow-x: hidden;
	overflow-y: auto;
	width: 100%;
	-webkit-overflow-scrolling: touch;
	scrollbar-width: thin;
	scrollbar-color: rgba(0, 255, 255, 0.5) #000;
}

.retrotext-grid__body::-webkit-scrollbar {
	width: 4px;
	height: 4px;
}

.retrotext-grid__body::-webkit-scrollbar-track {
	background: #000;
}

.retrotext-grid__body::-webkit-scrollbar-thumb {
	background: rgba(0, 255, 255, 0.5);
	border-radius: 0;
}

.retrotext-grid__scroll {
	flex: 1 1 auto;
	min-height: 0;
	width: 100%;
	overflow-x: hidden;
	overflow-y: auto;
	-webkit-overflow-scrolling: touch;
	scrollbar-width: thin;
	scrollbar-color: rgba(0, 255, 255, 0.5) #000;
}

.retrotext-grid__scroll::-webkit-scrollbar {
	width: 4px;
	height: 4px;
}

.retrotext-grid__scroll::-webkit-scrollbar-track {
	background: #000;
}

.retrotext-grid__scroll::-webkit-scrollbar-thumb {
	background: rgba(0, 255, 255, 0.5);
	border-radius: 0;
}

.retrotext-grid--header-scrolls .retrotext-grid__body {
	height: auto;
	max-height: none;
	overflow-y: visible;
	flex: 0 1 auto;
}

.retrotext-grid__body .retrotext-row--wrap,
.retrotext-row--wrap {
	height: auto;
	max-height: none;
	min-height: var(--retrotext-row-height);
	overflow: visible;
	white-space: pre-line;
	overflow-wrap: anywhere;
	word-break: break-word;
	text-overflow: clip;
	line-height: max(var(--retrotext-row-height), 1.15em);
}

.retrotext-row--wrap .retrotext-line {
	white-space: pre-line;
	overflow-wrap: anywhere;
	word-break: break-word;
	line-height: max(var(--retrotext-row-height), 1.15em);
}

.retrotext-grid__footer {
	height: calc(var(--retrotext-row-height) * var(--retrotext-footer-rows) + var(--retrotext-page-entry-footer-gap, 0px) + var(--retrotext-page-entry-top-gap, 0px));
	padding-top: var(--retrotext-page-entry-top-gap, 0px);
	overflow: visible;
}

.retrotext-row {
	display: block;
	width: 100%;
	max-width: none;
	box-sizing: border-box;
	padding: 0 0.75em;
	height: var(--retrotext-row-height);
	max-height: var(--retrotext-row-height);
	min-height: var(--retrotext-row-height);
	overflow: hidden;
	white-space: nowrap;
	text-overflow: ellipsis;
	text-align: left;
}

.retrotext-grid__body .retrotext-row,
.retrotext-grid__header .retrotext-row {
	padding-left: var(--retrotext-text-indent);
}

.retrotext-grid__status .retrotext-row {
	padding-left: 0.75em;
	padding-right: 0.75em;
}

.retrotext-row--status {
	display: flex;
	align-items: center;
	justify-content: space-between;
	width: 100%;
	white-space: nowrap;
}

.retrotext-status__page,
.retrotext-status__date,
.retrotext-status__time {
	flex: 0 0 auto;
}

.retrotext-status--overlay {
	background: transparent !important;
}

.retrotext-row--split {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.75em;
}

.retrotext-grid__header .retrotext-row--align-center {
	text-align: center;
}

.retrotext-grid__header .retrotext-row--align-center .retrotext-line--title {
	display: block;
	width: 100%;
	text-align: center;
	padding-right: 6em;
	box-sizing: border-box;
}

.retrotext-row--span-all {
	overflow: visible;
	display: flex;
	align-items: stretch;
	justify-content: flex-start;
	position: relative;
	width: 100%;
	height: calc(var(--retrotext-row-height) * var(--retrotext-row-span, 1));
	max-height: calc(var(--retrotext-row-height) * var(--retrotext-row-span, 1));
	min-height: calc(var(--retrotext-row-height) * var(--retrotext-row-span, 1));
}

.retrotext-row--header-fill {
	overflow: visible;
}

.retrotext-row--header-fill .retrotext-line--fill {
	display: flex;
	align-items: center;
	flex: 1 1 auto;
	align-self: stretch;
	min-height: 100%;
	width: auto;
	max-width: calc(100% - 7em);
	line-height: 1;
	background: transparent !important;
	font-size: calc(var(--retrotext-row-height) * var(--retrotext-row-span, 1) * 0.75);
	white-space: nowrap;
}

.retrotext-row--header-fill.retrotext-row--align-center .retrotext-line--fill,
.retrotext-row--header-fill.retrotext-row--align-center .retrotext-line--title {
	display: flex;
	justify-content: center;
	width: 100%;
	max-width: 100%;
	padding-right: 6em;
	box-sizing: border-box;
	text-align: center;
}

.retrotext-grid__header .retrotext-row:not(.retrotext-row--span-all) {
	display: flex;
	align-items: center;
}

.retrotext-row--span-all.retrotext-row--align-center {
	align-items: flex-start;
	justify-content: center;
}

.retrotext-row--span-all .retrotext-line--title {
	padding-top: 0;
}

.retrotext-header-span {
	position: absolute;
	inset: 0;
	z-index: 1;
	overflow: visible;
	pointer-events: none;
	display: flex;
	align-items: stretch;
	padding: 0 0.75em;
	padding-left: var(--retrotext-text-indent);
	box-sizing: border-box;
}

.retrotext-header-span--fill .retrotext-line--fill {
	display: flex;
	align-items: center;
	flex: 1 1 auto;
	align-self: stretch;
	min-height: 100%;
	font-size: calc(var(--retrotext-row-height) * var(--retrotext-row-span, 1) * 0.75);
	line-height: 1;
	background: transparent !important;
}

.retrotext-header-span--fill .retrotext-line--graphic-fill {
	position: absolute;
	top: 0;
	right: 0.75em;
	bottom: 0;
	height: 100%;
	display: flex;
	align-items: center;
}

.retrotext-header-span--align-center {
	justify-content: center;
}

.retrotext-header-span--align-center .retrotext-line--title {
	width: 100%;
	text-align: center;
	padding-right: 6em;
	box-sizing: border-box;
}

.retrotext-grid__header .retrotext-row {
	position: relative;
	z-index: 2;
}

.retrotext-row--graphic-right,
.retrotext-row--overlap-graphic {
	position: relative;
	overflow: visible;
}

.retrotext-line--graphic {
	font-family: "Courier New", Courier, "Lucida Console", monospace;
	letter-spacing: 0.04em;
	flex: 0 0 auto;
	line-height: 1 !important;
}

.retrotext-line--graphic-right {
	position: absolute;
	top: 50%;
	right: 0.75em;
	transform: translateY(-50%);
	white-space: pre;
	z-index: 2;
	background: transparent !important;
}

.retrotext-line--graphic-overlap {
	position: absolute;
	top: 0;
	right: 0.75em;
	bottom: 0;
	height: 100%;
	max-height: 100%;
	transform: none;
	display: flex;
	align-items: center;
	white-space: pre;
	line-height: 1 !important;
	z-index: 2;
	background: transparent !important;
	overflow: visible;
}

.retrotext-row--overlap-graphic {
	position: relative;
	overflow: visible;
}

.retrotext-row--align-right {
	text-align: right;
}

.retrotext-row--sep,
.retrotext-row--footer-sep {
	padding: 0;
	min-height: 0;
	height: 0;
	max-height: none;
	line-height: 0;
	border-bottom: 2px solid currentColor;
	margin: 0;
}

.retrotext-row--footer-sep {
	border-bottom-width: 1px;
	margin: 0 0.75em;
}

.retrotext-row--link {
	cursor: pointer;
	white-space: normal;
	word-break: break-word;
	overflow-wrap: anywhere;
}

.retrotext-row--link:hover,
.retrotext-row--link:focus {
	outline: 1px solid currentColor;
	outline-offset: -1px;
}

.retrotext-row--footer-fastext {
	display: grid;
	grid-template-columns: repeat(var(--retrotext-footer-link-count, 1), minmax(0, 1fr));
	/* Respect the configured spacing on wide screens, but shrink the gap on
	 * narrow TV screens so several links (e.g. 5+) still fit side by side. */
	column-gap: min(var(--retrotext-footer-link-gap, 24px), 2cqw);
	align-items: center;
	padding-left: 0.4em;
	padding-right: 0.4em;
	padding-bottom: calc(0.1em + var(--retrotext-footer-offset, 0px));
	white-space: normal;
	overflow: hidden;
}

/* Scale the fastext label size down as the number of links grows so they fit
 * the screen width without being clipped (4:3 TV screens are narrow). */
.retrotext-row--footer-fastext .retrotext-line--action,
.retrotext-row--footer-fastext .retrotext-line--url {
	font-size: var(
		--retrotext-footer-link-font-size,
		min(
			calc(var(--retrotext-row-height) * 0.72),
			calc(92cqw / (var(--retrotext-footer-link-count, 1) * 4.5))
		)
	);
	letter-spacing: 0;
}

/* Footer link capitalisation (lowercase by default, uppercase when enabled).
 * Specific + !important so it beats the embed's global text-transform reset. */
.retrotext-grid__footer .retrotext-row--footer-fastext .retrotext-line--action,
.retrotext-grid__footer .retrotext-row--footer-fastext .retrotext-line--url {
	text-transform: var(--retrotext-footer-link-transform, lowercase) !important;
}

.retrotext-row--footer-fastext.retrotext-row--align-left {
	justify-items: start;
}

.retrotext-row--footer-fastext.retrotext-row--align-center {
	justify-items: center;
}

.retrotext-row--footer-fastext.retrotext-row--align-right {
	justify-items: end;
}

.retrotext-row--footer-fastext .retrotext-line--action,
.retrotext-row--footer-fastext .retrotext-line--url {
	display: block;
	min-width: 0;
	max-width: 100%;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	cursor: pointer;
}

.retrotext-row--footer-fastext.retrotext-row--align-left .retrotext-line--action,
.retrotext-row--footer-fastext.retrotext-row--align-left .retrotext-line--url {
	text-align: left;
}

.retrotext-row--footer-fastext.retrotext-row--align-center .retrotext-line--action,
.retrotext-row--footer-fastext.retrotext-row--align-center .retrotext-line--url {
	text-align: center;
}

.retrotext-row--footer-fastext.retrotext-row--align-right .retrotext-line--action,
.retrotext-row--footer-fastext.retrotext-row--align-right .retrotext-line--url {
	text-align: right;
}

@media (max-width: 900px) {
	.retrotext-row--footer-fastext {
		column-gap: 0.5em;
	}
}

.retrotext-line--url {
	text-decoration: none;
}

.retrotext-line--url:hover,
.retrotext-line--url:focus {
	text-decoration: underline;
	outline: none;
}

.retrotext-row--image .retrotext-line {
	display: block;
	width: 100%;
	overflow: hidden;
	white-space: nowrap;
}

.retrotext-line {
	display: inline;
	max-width: none;
}

.retrotext-row--align-center {
	text-align: center;
}

.retrotext-row--align-right {
	text-align: right;
}

.retrotext-line--action {
	cursor: pointer;
}

.retrotext-line--action:hover,
.retrotext-line--action:focus {
	text-decoration: underline;
	outline: none;
}

.screen-reader-text {
	border: 0;
	clip: rect(1px, 1px, 1px, 1px);
	clip-path: inset(50%);
	height: 1px;
	margin: -1px;
	overflow: hidden;
	padding: 0;
	position: absolute;
	width: 1px;
	word-wrap: normal !important;
}
