/*
 * A Ren'Py game fills the width it is given.
 *
 * MyArcadePlugin writes width and height attributes scaled to its max_width
 * setting, which is 800 here. Those attributes are deliberately left in place
 * so the frame still works if this file never loads; these rules override them
 * when it does.
 *
 * The height is not set to a number. It comes from the game's own shape, passed
 * in as --im3d-rg-aspect on the element, so a game that is not 16:9 is not
 * letterboxed or cropped to fit one.
 */

.im3d-rg-frame {
	aspect-ratio: var(--im3d-rg-aspect, 16 / 9);
	border: 0;
	display: block;
	height: auto;
	margin: 0 auto;
	max-width: 100%;
	width: 100%;
}

/*
 * On the fullscreen view the height is the limit, not the width. Filling the
 * width of a 2560px screen with a 16:9 game asks for 1440 pixels of height on a
 * viewport that has around 1313, and the bottom of the game ends up below the
 * fold with nothing to scroll to it.
 *
 * So the height is pinned to the viewport and the width follows from the game's
 * own shape, which leaves a margin at the sides on a wide screen rather than
 * cutting the game off. The class is on the element because the theme's
 * fullscreen template puts nothing on the body to key off.
 */
.im3d-rg-frame.im3d-rg-frame--fullscreen {
	height: 100vh;
	max-height: 100vh;
	max-width: 100vw;
	width: auto;
}

/*
 * The theme puts a 25px bar of its own above the game on that view, inside a
 * <center>. A frame pinned to the full viewport height therefore adds up to
 * more than the screen, and the page scrolls by exactly that bar - which on a
 * view called "fullscreen" is the one thing it should not do.
 *
 * So the wrapper becomes a column the height of the screen and the frame takes
 * whatever is left. The game's shape stops mattering here: Ren'Py letterboxes
 * its own canvas inside whatever rectangle it is given, which is what any game
 * does in fullscreen, so handing it the remaining space is better than fitting
 * a 16:9 box inside it and leaving a margin as well as the bar.
 *
 * Scoped by :has() to a wrapper that actually holds one of these frames, so
 * nothing else that uses <center> is touched. A browser without :has() keeps
 * the rule above and the 25px scroll, which is the behaviour this replaces
 * rather than a new fault.
 */
center:has(> .im3d-rg-frame--fullscreen) {
	display: flex;
	flex-direction: column;
	height: 100vh;
	overflow: hidden;
}

center:has(> .im3d-rg-frame--fullscreen) > .im3d-rg-frame--fullscreen {
	aspect-ratio: auto;
	flex: 1 1 auto;
	height: auto;
	max-height: none;
	min-height: 0;
	width: 100%;
}
