/* the display font of the game, used for titles */
@font-face {
	font-family: yikes;
	src: url('fonts/yikes.ttf');
}

/* the handwriting font of the labels in the levels, reduced to the Latin characters and the arrows */
@font-face {
	font-family: mynerve;
	src: url('fonts/Mynerve-Regular.woff2');
}

/*
 * The key colors, fonts and sizes of the page.
 */
:root {
	--color-page: #005674;
	--color-screen: #00a49f;
	--color-chrome: #97cee9;
	--color-text: #fff;
	--color-accent: #fde900;
	--color-selected: #3f3;
	--color-danger: #f33;

	--font-text: 16px Arial, sans-serif;
	--font-title: 24px yikes, sans-serif;
}

/* the sizes of all boxes include their padding and border */
*,
::before,
::after {
	box-sizing: border-box;
}

/* the background, the text color and the font of the page */
body {
	margin: 0;
	background: url('gfx/site/page.svg') center top var(--color-page);
	color: var(--color-text);
	font: var(--font-text);
}

/* titles use the display font in the accent color */
h1,
h2,
h3 {
	font: var(--font-title);
	color: var(--color-accent);
}

/* links keep the text color, so they stay readable on the dark page */
a {
	color: inherit;
}

/* the hidden attribute also hides an element that sets its own display */
[hidden] {
	display: none !important;
}

/*
 * The root element is a grid that is centered horizontally in the window. Its first two rows and columns are a block of
 * four cells, with a narrow top row and a narrow side column around a large main cell. The size of the block follows
 * the window up to a maximum width. The main cell is at most as high as the aspect ratio of the playfield allows. The
 * other parts go in rows below the block, each in the full width.
 */
ui-root {
	/* the top row is at least as high as the narrator text with four lines of text */
	--grid-row-top-min: 149px;
	--grid-gap: 1rem;
	--grid-width: min(100vw - 2rem, 1400px);
	--editor-buttons-height: clamp(2rem, var(--grid-width) * 0.032, 3rem);
	--grid-row-bottom: 0px;
	--grid-height: min(100dvh - 2rem - var(--grid-row-bottom), var(--grid-col-main) * 3 / 4 / 0.85 + var(--grid-gap));
	--grid-col-side: calc((var(--grid-width) - var(--grid-gap)) * 0.15);
	--grid-col-main: calc(var(--grid-width) - var(--grid-gap) - var(--grid-col-side));
	--grid-row-top: max((var(--grid-height) - var(--grid-gap)) * 0.15, var(--grid-row-top-min));
	--grid-row-main: calc(var(--grid-height) - var(--grid-gap) - var(--grid-row-top));
	display: grid;
	grid-template:
		'corner top' var(--grid-row-top)
		'side main' var(--grid-row-main)
		/ var(--grid-col-side) var(--grid-col-main);
	gap: var(--grid-gap);
	justify-content: center;
	padding-top: 1rem;

	/* on a window that is taller than wide, the main cell takes the full width and the side cell goes below it */
	@media (orientation: portrait) {
		--grid-height: min(100dvh - 2rem - var(--grid-row-bottom), var(--grid-width) * 3 / 4 / 0.7 + 2 * var(--grid-gap));
		--grid-row-side: calc((var(--grid-height) - 2 * var(--grid-gap)) * 0.15);
		--grid-row-top: max((var(--grid-height) - 2 * var(--grid-gap)) * 0.15, var(--grid-row-top-min));
		--grid-row-main: calc(var(--grid-height) - 2 * var(--grid-gap) - var(--grid-row-top) - var(--grid-row-side));
		grid-template:
			'corner top' var(--grid-row-top)
			'main main' var(--grid-row-main)
			'side side' var(--grid-row-side)
			/ var(--grid-col-side) var(--grid-col-main);
	}

	/* the block leaves room for the row of the editor buttons while they show */
	&:has(> ui-editor-buttons:not([hidden])) {
		--grid-row-bottom: calc(var(--editor-buttons-height) + var(--grid-gap));
	}

	> * {
		grid-column: 1 / -1;
	}

	/* the robot head and the narrator text share the first row and have its height */
	> .top {
		grid-row: corner;
		grid-column: corner-start / top-end;
		display: flex;
		gap: var(--grid-gap);

		> ui-robot-head {
			aspect-ratio: 108 / 92;
		}

		> ui-narrator-text {
			flex: 1;
			--narrator-height: var(--grid-row-top);
		}

		/*
		 * The logo shows in the left corner while the robot head and the narrator text are hidden. It is larger than
		 * the corner and reaches into the empty top row and side column.
		 */
		> .logo {
			width: calc(var(--grid-col-side) * 2.1);
			align-self: start;
			position: relative;
			z-index: 1;
		}

		/* the tagline stands left of the character, in the chalk style of the logo */
		> .tagline {
			margin: 0 0 0 auto;
			align-self: center;
			font-family: mynerve;
			font-size: calc(var(--grid-row-top) * 0.2);
			line-height: 1.1;
			text-align: right;
			color: #e6f6fd;
			text-wrap: balance;

			/* a line break comes only between the sentences */
			> span {
				white-space: nowrap;
			}
		}

		/* the character stands at the right end of the row */
		> .mascot {
			height: 100%;
		}

		&:has(> ui-robot-head:not([hidden]), > ui-narrator-text:not([hidden])) > :is(.logo, .tagline, .mascot) {
			display: none;
		}
	}

	/* the HUD, the VCR panel and the editor palette fill the side cell */
	> ui-hud {
		grid-area: side;
		aspect-ratio: auto;
	}

	> :is(ui-vcr-panel, ui-editor-palette) {
		grid-area: side;
	}

	/*
	 * The dome on the chain shelf decorates the empty side cell. It fills the width of the cell, or its height when the
	 * cell is too low. Its pipe goes up to a cap at the top of the page, and right to behind the left edge of the CRT.
	 */
	> .side-deco {
		--deco-unit: min(var(--grid-col-side) / 246.5, var(--grid-row-main) / 572);
		--pipe-bands:
			#527080 12.5%, #456472 12.5% 22.5%, #3d5b6b 22.5% 30%, #38515d 30% 38%, #36434f 38% 62%, #38515d 62% 70%,
			#3d5b6b 70% 77.5%, #456472 77.5% 87.5%, #527080 87.5%;
		grid-area: side;
		position: relative;
		z-index: -1;
		width: calc(var(--deco-unit) * 246.5);
		height: calc(var(--deco-unit) * 572);
		background: url('gfx/site/dome-shelf.svg') center / 100% 100% no-repeat;

		&::before,
		&::after {
			content: '';
			position: absolute;
		}

		&::before {
			left: calc(var(--deco-unit) * -2.5);
			bottom: 100%;
			width: calc(var(--deco-unit) * 44.5);
			height: calc(1rem + var(--grid-row-top) + var(--grid-gap));
			background:
				linear-gradient(to right, #3c6b7c, #213645, #3c6b7c) top / 100% calc(var(--deco-unit) * 17) no-repeat,
				linear-gradient(to right, var(--pipe-bands)) center / calc(var(--deco-unit) * 39.5) 100% no-repeat;
		}

		&::after {
			left: 100%;
			top: calc(var(--deco-unit) * 399.5);
			width: calc(var(--grid-col-side) + var(--grid-gap) + 3rem - var(--deco-unit) * 246.5);
			height: calc(var(--deco-unit) * 60);
			background: linear-gradient(to bottom, var(--pipe-bands));
		}

		@media (orientation: portrait) {
			display: none;
		}
	}

	&:has(> ui-hud:not([hidden]), > ui-vcr-panel:not([hidden]), > ui-editor-palette:not([hidden])) > .side-deco {
		display: none;
	}

	/*
	 * The CRT shows the stage and the parts that show in its place. Its content has the aspect ratio of the
	 * playfield, so the stage fills the glass.
	 */
	> ui-crt {
		--crt-aspect: 4 / 3;
		grid-area: main;

		/* the parts in the CRT lie on top of each other in one cell */
		> * {
			grid-area: 1 / 1;
			min-width: 0;
			min-height: 0;
		}
	}
}

/* the footer has the width of the app, with the links on the left and the credits on the right */
footer {
	display: flex;
	flex-wrap: wrap;
	justify-content: space-between;
	gap: 1rem;
	width: min(100vw - 2rem, 1400px);
	margin: 1rem auto;

	> :last-child {
		text-align: right;
	}
}

/*
 * The about page has the logo at the top and a text column below it. The header has the width of the app. The text
 * column is narrower, so that its lines stay readable.
 */
body.about {
	> header {
		width: min(100vw - 2rem, 1400px);
		margin: 1rem auto 0;

		.logo {
			display: block;
			width: min(100%, 26rem);
		}
	}

	> main {
		width: min(100vw - 2rem, 50rem);
		margin: 0 auto;
		font-size: 1.25rem;
		line-height: 1.6;
	}

	/* the captions of the original and the revived version stand below the halves of the video */
	.compare {
		margin: 1.5rem 0;

		> video {
			display: block;
			width: 100%;
		}

		> figcaption {
			display: flex;

			> span {
				flex: 1;
				text-align: center;
			}
		}
	}
}
