:root {
	--bg: #08090b;
	--panel: #111417;
	--line: #34383a;
	--text: #f7f5ff;
	--muted: #d8d5c5;
	--gold: #ffd869;
	--gold-dark: #7b4d12;
	color-scheme: dark;
}

html, body {
	margin: 0;
	width: 100%;
	height: 100%;
	height: 100dvh;
	overflow: hidden;
	overscroll-behavior: none;
	background: var(--bg);
	color: var(--text);
	font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
	-webkit-user-select: none;
	user-select: none;
	-webkit-touch-callout: none;
	-webkit-tap-highlight-color: transparent;
}

#stage {
	position: fixed;
	top: env(safe-area-inset-top, 0px);
	right: env(safe-area-inset-right, 0px);
	bottom: env(safe-area-inset-bottom, 0px);
	left: env(safe-area-inset-left, 0px);
	display: grid;
	place-content: center;
	place-items: center;
	overflow: hidden;
}

/* Landscape: the game reaches the bottom edge under the home indicator, so the chatbox sits on the screen's edge
   instead of above an empty strip. */
@media (orientation: landscape) {
	#stage {
		bottom: 0;
	}

	/* Mobile gameframe (toplevel 601): the scene draws edge to edge, under the notch and the home indicator; the
	   client keeps the gameframe inside the safe area (WebLayout reads it from #safe-probe). */
	body.osm #stage {
		top: 0;
		left: 0;
		right: 0;
	}
}

/* Desktop: a strip above the stage keeps the toolbar clear of a canvas that fills the page (resizable). */
@media not all and (pointer: coarse) {
	#stage {
		top: calc(env(safe-area-inset-top, 0px) + 42px);
	}
}

/* The device safe area insets as paddings, which scripts can read (env() is CSS only). */
#safe-probe {
	position: fixed;
	top: 0;
	left: 0;
	width: 0;
	height: 0;
	padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px)
		env(safe-area-inset-left, 0px);
	visibility: hidden;
	pointer-events: none;
}

/* The HD (WebGL2) canvas shares #game's grid cell under it; #game stays the input surface. */
#game, #game_gl {
	grid-area: 1 / 1;
	display: block;
	image-rendering: pixelated;
}

#game {
	z-index: 1;
	outline: none;
	touch-action: none;
}

#game_gl {
	background: #000;
	pointer-events: none;
}

#game_gl[hidden] {
	display: none;
}

#keyboard {
	position: fixed;
	left: 0;
	bottom: 0;
	width: 1px;
	height: 1px;
	padding: 0;
	border: 0;
	opacity: 0;
	font-size: 16px;
	pointer-events: none;
}

#loading {
	position: fixed;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	background: radial-gradient(ellipse at center, #15191c 0%, var(--bg) 70%);
	z-index: 10;
	transition: opacity 0.4s ease;
}

#loading.done {
	opacity: 0;
	pointer-events: none;
}

#loading .panel {
	width: min(360px, calc(100vw - 48px));
	padding: 28px 24px 22px;
	text-align: center;
	background: var(--panel);
	border: 1px solid var(--line);
	border-radius: 10px;
	box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
}

#loading .logo {
	display: block;
	margin: 0 auto 8px;
}

#loading h1 {
	margin: 0 0 18px;
	color: var(--gold);
	font: 600 26px/1.2 Georgia, "Times New Roman", serif;
	letter-spacing: 0.12em;
	text-transform: uppercase;
}

#loading .bar {
	height: 10px;
	overflow: hidden;
	background: #0b0d0f;
	border: 1px solid var(--line);
	border-radius: 5px;
}

#loading .fill {
	width: 0;
	height: 100%;
	background: linear-gradient(90deg, var(--gold-dark), var(--gold));
	transition: width 0.15s linear;
}

#loading .fill.indeterminate {
	width: 30%;
	animation: slide 1.2s ease-in-out infinite;
}

@keyframes slide {
	from { transform: translateX(-100%); }
	to { transform: translateX(340%); }
}

#loading p {
	min-height: 1.4em;
	margin: 12px 0 0;
	color: var(--muted);
}

#loading p.hint {
	margin-top: 6px;
	font-size: 0.85em;
	opacity: 0.8;
}

#loading .actions {
	display: flex;
	flex-direction: column;
	gap: 10px;
	align-items: center;
	margin-top: 16px;
}

#loading button {
	padding: 8px 22px;
	color: var(--bg);
	background: var(--gold);
	border: 0;
	border-radius: 6px;
	font: inherit;
	font-weight: 600;
	cursor: pointer;
}

#loading a {
	color: var(--gold);
}

#toolbar {
	position: fixed;
	top: calc(env(safe-area-inset-top, 0px) + 6px);
	left: calc(env(safe-area-inset-left, 0px) + 6px);
	display: flex;
	gap: 6px;
	z-index: 5;
	opacity: 0.35;
	transition: opacity 0.2s;
}

#toolbar:hover, #toolbar:focus-within {
	opacity: 1;
}

/* The canvas reaches the top left corner: only a handle shows until the toolbar is hovered or tapped. */
#toolbar.tuck {
	top: 0;
	padding: calc(env(safe-area-inset-top, 0px) + 6px) 6px 10px;
	background: rgba(8, 9, 11, 0.85);
	border: 1px solid var(--line);
	border-top: 0;
	border-radius: 0 0 8px 8px;
	opacity: 1;
	transform: translateY(calc(-100% + 6px));
	transition: transform 0.2s ease;
}

#toolbar.tuck::after {
	content: "";
	position: absolute;
	left: 50%;
	bottom: 2px;
	width: 24px;
	height: 2px;
	margin-left: -12px;
	border-radius: 1px;
	background: var(--gold);
	opacity: 0.7;
}

#toolbar.tuck.open, #toolbar.tuck:focus-within {
	transform: none;
}

@media (hover: hover) {
	#toolbar.tuck:hover {
		transform: none;
	}
}

@media (hover: none) {
	#toolbar.tuck:not(.open) button {
		pointer-events: none;
	}
}

#toolbar button {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 30px;
	height: 30px;
	padding: 0;
	color: var(--gold);
	background: rgba(8, 9, 11, 0.75);
	border: 1px solid var(--line);
	border-radius: 6px;
	cursor: pointer;
}

#toolbar button[hidden] {
	display: none;
}

#toolbar button svg {
	width: 18px;
	height: 18px;
	fill: currentColor;
}

#toolbar button img {
	max-width: 20px;
	max-height: 20px;
}

#toolbar button.active {
	border-color: var(--gold);
}

#btn-uiscale {
	width: auto !important;
	min-width: 30px;
	padding: 0 5px !important;
	font: 600 11px/1 sans-serif;
}

#btn-keyboard {
	display: none !important;
}

#rotate {
	display: none;
	position: fixed;
	left: 50%;
	bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
	transform: translateX(-50%);
	padding: 6px 12px;
	color: var(--text);
	background: rgba(8, 9, 11, 0.85);
	border: 1px solid var(--gold-dark);
	border-radius: 6px;
	z-index: 6;
	pointer-events: none;
	white-space: nowrap;
}

@media (pointer: coarse) {
	#btn-keyboard {
		display: flex !important;
	}

	#toolbar:not(.tuck) {
		opacity: 0.7;
	}

	#toolbar button {
		width: 38px;
		height: 38px;
	}
}

@media (pointer: coarse) and (orientation: portrait) {
	#rotate {
		display: block;
	}
}

/* Touch screens without room above the canvas: a column in the margin the safe areas leave beside it (iPhone
   landscape), placed by loader.js, instead of a handle tucked under the notch or status bar. */
#toolbar.side {
	bottom: calc(env(safe-area-inset-bottom, 0px) + 6px);
	flex-direction: column;
	opacity: 0.85;
}

/* Mobile gameframe (toplevel 601, body.osm from WebDisplayMode): chat and its buttons take the top left, so the
   toolbar is one button at the bottom left, below the left-edge components, and opens upward (a row along the bottom
   edge when the column would not fit), placed by loader.js. */
#toolbar #btn-toolbar {
	display: none;
}

body.osm #toolbar {
	top: auto;
	flex-direction: column-reverse;
	gap: 4px;
	padding: 0;
	background: none;
	border: 0;
	transform: none;
	opacity: 0.6;
}

body.osm #toolbar.row {
	flex-direction: row;
}

body.osm #toolbar.open {
	opacity: 1;
}

body.osm #toolbar #btn-toolbar {
	display: flex;
}

body.osm #toolbar:not(.open) button:not(#btn-toolbar) {
	display: none !important;
}

body.osm #toolbar button {
	width: 32px;
	height: 32px;
}

body.osm #toolbar.open #btn-toolbar {
	border-color: var(--gold);
}

/* Touch mini menu (WebMenu): the client's menu as large rows, like the OSRS mobile client's */
@font-face {
	font-family: "RuneScape Bold";
	src: url("fonts/runescape_bold.ttf") format("truetype");
	font-display: swap;
}

.tm-backdrop {
	position: fixed;
	inset: 0;
	z-index: 20;
	touch-action: none;
}

.tm-panel {
	position: fixed;
	display: flex;
	flex-direction: column;
	min-width: 100px;
	max-width: calc(100vw - 8px);
	/* Menu.method12287: 0x5d5447 (6116423) fill, 1 px black outline, black title band */
	background: #5d5447;
	border: 0;
	padding: 1px;
	box-sizing: border-box;
	font: 12px/1 "RuneScape Bold", system-ui, -apple-system, sans-serif;
	overflow: hidden;
}

.tm-title {
	flex: none;
	padding: 3px 6px 2px;
	color: #5d5447;
	background: #000;
	white-space: nowrap;
}

.tm-rows {
	flex: 1 1 auto;
	margin-top: 1px;
	border: 1px solid #000;
	overflow-y: auto;
	overscroll-behavior: contain;
	-webkit-overflow-scrolling: touch;
	touch-action: pan-y;
}

.tm-row {
	display: block;
	width: 100%;
	min-height: 21px;
	padding: 0 5px;
	color: #fff;
	border: 0;
	font: inherit;
	text-align: left;
	text-shadow: 1px 1px 0 #000;
	background: #5d5447;
	white-space: nowrap;
	cursor: pointer;
}

.tm-parent::after {
	content: ">";
	float: right;
	margin-left: 10px;
	color: #fff;
}

.tm-sub[hidden] {
	display: none;
}

.tm-sub .tm-row {
	padding-left: 14px;
}

.tm-rows > .tm-row:nth-of-type(even), .tm-sub .tm-row:nth-of-type(even) {
	background: #4f463b;
}

.tm-rows > .tm-parent.tm-open {
	background: #726451;
}

.tm-rows .tm-row:active, .tm-rows .tm-row:hover {
	color: #ff0;
	background: #726451;
}
