[data-theme] {
    --tex-url-tools: url(/static/img/uiskel/ui.png);
    --tex-url-tools-text: url(/static/img/uiskel/tools_text.png);
    --tex-url-border: url(/static/img/uiskel/border.png);
    --tex-url-border-active: url(/static/img/uiskel/border_active.png);
    --tex-url-ui: url(/static/img/uiskel/ui.png);
	--tex-isz-tools: 32px;
	--tex-isz-ui: 32px;
}

::before, ::after {
	--clr-pri: inherit;
	--clr-sec: inherit;
	--bg-clr: inherit;
	--tex-url-tools: inherit;
	--tex-url-tools-text: inherit;
	--tex-url-border: inherit;
	--tex-url-border-active: inherit;
	--tex-url-ui: inherit;
	--tex-isz-tools: inherit;
	--tex-isz-ui: inherit;
}

/* ux */

button.owop-ui:hover::after, a.owop-ui:hover::after {
	filter: brightness(1.1);
}

button.owop-ui:active::after, a.owop-ui:active::after {
	filter: brightness(0.8);
}

#game-data::before, #game-data::after { /* preload textures, used by loaded theme */
	position: absolute;
	width: 0;
	height: 0;
}

#game-data::after { /* preload textures */
	content: var(--tex-url-tools) var(--tex-url-tools-text)
		var(--tex-url-border) var(--tex-url-border-active) var(--tex-url-ui);
}

button {
	color: inherit;
	font: inherit;
	text-shadow: inherit;
}

.l-opt > input, .l-opt > input + label {
	vertical-align: middle;
}

.l-opt {
	margin: 3px 0;
}

h1 {
	font-size: 32px;
	margin: 0;
	font-weight: normal;
}

/* EUI */

#eui-container {
	user-select: none;
}

.eui-win {
	display: grid;
	grid-template-columns: 1fr auto;
	grid-template-rows: auto 1fr;
	row-gap: 5px;
}

.eui-win, .eui-wg, .eui-themed {
	border: 8px transparent solid;
	background-color: transparent;
	background-clip: padding-box;
	color: #FFF;
	border-image: var(--tex-url-border) 8 fill repeat;
}

.eui-win, .eui-wg {
	position: fixed;
	text-align: center;
}

.eui-win.moveable .eui-win-title {
	cursor: move;
}

.eui-win-title {
	padding: 5px;
	border-radius: 3px;
	background-color: #00000022;
}

.eui-win-close {
	appearance: none;
	border: unset;
	padding: 5px;
	border-radius: 3px;
	background-color: #00000022;
	margin-left: 5px;
	transition: background-color 100ms;
}

.eui-win:last-of-type .eui-win-title,
.eui-win:last-of-type .eui-win-close { /* topmost window, active */
	background-color: #00000044;
}

.eui-win .eui-win-close:hover {
	background-color: #CD5C5C;
}

.eui-win-close:active {
	filter: brightness(0.8);
}

.eui-win-close::before {
	content: 'X';
}

.eui-win-content {
	grid-column: 1 / -1;
	min-width: min-content;
}


/* UI TEXTURES */

button.owop-ui {
	padding: 4px;
}

.owop-ui::after, .tool::after {
	content: '';
	display: block;
	margin: auto;
	background-repeat: no-repeat;
	background-clip: content-box;
}

.owop-ui::after {
	width: var(--tex-isz-ui);
	height: var(--tex-isz-ui);
	background-image: var(--tex-url-ui);
}

.tool::after {
	width: var(--tex-isz-tools);
	height: var(--tex-isz-tools);
	background-image: var(--tex-url-tools);
	margin: -4px;
}

/* TABBED VIEW */

.tabs {
	display: grid;
	grid-template-rows: repeat(var(--num-tabs), auto) 1fr;
	grid-template-columns: auto 1fr;
}

.tab {
	display: contents;
}

.tab > label {
	text-align: center;
	grid-column: 1 / 2;
	padding: 5px;
	margin: 3px;
	border-radius: 3px;
	background-color: #00000044;
	cursor: pointer;
}

.tab > input[type=radio]:checked ~ label {
	background-color: #00000088;
	cursor: initial;
}

.tab > input[type=radio],
.tab > input[type=radio]:not(:checked) ~ label ~ .content {
	display: none;
}

.tab > .content {
	text-align: left;
	grid-column: 2 / 3;
	grid-row: 1 / -1;
	border-left: 1px solid #00000055;
	min-width: 200px;
	padding-left: 3px;
}


/* TOOL WINDOW */
.owop-tools {
	row-gap: unset;
}

.owop-tools .eui-win-content {
	width: min-content;
}

.eui-win.owop-tools .eui-win-title {
	padding: unset;
	background-color: unset;
	margin: auto;
	height: 16px;
	width: 36px;
	background-image: var(--tex-url-tools-text);
	background-repeat: no-repeat;
	background-position: center;
}

.owop-tools .tool {
	box-sizing: content-box;
	padding: 0;
	border: 8px transparent solid;
	background-color: transparent;
}

.owop-tools .tool.active {
	border: 8px transparent solid;
	border-image: var(--tex-url-border-active) 8 fill repeat;
}

/* hide zoom tool if the user has a touch screen */
@media (pointer:coarse) {
	.owop-tools .tool[data-tool="Zoom"] {
		display: none;
	}
}

/* LOWER LEFT UI AND COLOR WIDGET */

.owop-llui {
	display: flex;
	align-items: flex-end;
	position: fixed;
	padding: 4px;
	left: 0;
	bottom: 0;
	max-width: 100%;
	box-sizing: border-box;
}

.owop-llui > div:first-child {
	flex-shrink: 0;
}

.owop-llui > div:nth-child(2) {
	width: 350px;
}

.owop-llui, .owop-llui > div {
	pointer-events: none;
}

.owop-llui > div > * {
	pointer-events: initial;
}

.owop-llui > div {
	display: flex;
	flex-direction: column-reverse;
	align-items: flex-start;
}

.owop-llui > div + div {
	margin-left: 3px;
}

.owop-llui > div > * + * {
	margin-bottom: 3px;
}

.owop-colors, .owop-palettes {
	position: initial;
}

.owop-colors {
	display: flex;
	flex-wrap: wrap;
	width: 96px;
	height: 96px;
	flex-shrink: 0;
	box-sizing: border-box;
}

.owop-colors > * {
	width: 50%;
	height: 50%;
	appearance: none;
	background-color: transparent;
	border: 0;
}

.owop-colors > button.owop-ui {
	padding: 0;
}

.owop-clr-picker {
	position: relative;
}

.owop-clr-picker, .color-picker__dialog {
	color-scheme: light only;
}

.owop-clr-picker::before, .owop-clr-picker::after {
	content: '';
	display: block;
	position: absolute;
	width: 100%;
	height: 100%;
	border: 1px solid #00000055;
	box-sizing: border-box;
}

.owop-clr-picker::before {
	background-image: linear-gradient(45deg, #ddd 25%, transparent 25%, transparent 75%, #ddd 75%, #ddd 100%), linear-gradient(45deg, #ddd 25%, #fff 25%, #fff 75%, #ddd 75%, #ddd 100%);
	background-position: 0 0, 0.25em 0.25em;
	background-size: 0.5em 0.5em;
}

.owop-clr-picker::after {
	background-color: inherit;
}

.owop-colors > .primary-clr {
	margin: 2px -2px -2px 2px;
	z-index: 1;
}

.owop-colors > .secondary-clr {
	margin: -2px 2px 2px -2px;
}

.owop-colors > .palette-btn {
	margin: 0 -2px 0 2px;
}

/* click shield for color picker */
.color-picker__dialog::before {
	content: '';
	display: block;
	position: fixed;
	top: 0;
	left: 0;
	width: 100vw;
	height: 100vh;
}

/* PALETTE WIDGET */

.owop-palettes {
	min-height: 96px;
	width: 100%;
	box-sizing: border-box;
}

.owop-palettes summary {
	text-align: left;
	background-color: #00000044;
	border-radius: 3px;
	padding: 3px;
}

.owop-palettes > details[open] > summary {
	background-color: #00000055;
}

.owop-palettes > details + details {
	margin-top: 3px;
}

.world-palettes summary::before {
	content: 'World palettes (' attr(data-count) ')';
}

.user-palettes summary::before {
	content: 'User palettes (' attr(data-count) ')';
}

.owop-palette {
	display: flex;
	justify-content: center;
	flex-wrap: wrap;
	align-items: stretch;
	padding: 3px;
	background-color: #000000AA;
	position: relative;
}

.owop-palette + .owop-palette, summary + .owop-palette {
	margin-top: 3px;
}

.owop-palette:hover::before {
	content: attr(data-name) ' (' attr(data-clr-count) ' colors)';
	display: block;
	position: absolute;
	right: 0;
	top: 0;
	transform: translateY(-100%);
	background-color: #000000AA;
	padding: 0 3px;
	pointer-events: none;
}

.owop-pal-clr {
	--w-perc: inherit;
	flex-grow: 1;
	appearance: none;
	border: none;
	min-height: 16px;
	min-width: var(--w-perc, 24px);
	min-width: max(var(--w-perc, 24px), 24px);
}

/* POSITION WIDGET */

.owop-pos {
	border-top: none;
	border-left: none;
	padding-left: 3px;
	padding-top: 3px;
}

.owop-pos::before {
	content: 'X: ' attr(data-cur-x) ', Y: ' attr(data-cur-y);
}

/* show camera position instead on touch devices */
@media (pointer:coarse) {
	.owop-pos::before {
		content: 'X: ' attr(data-cam-x) ', Y: ' attr(data-cam-y);
	}
}

/* CURSOR COUNT WIDGET */

.owop-cursor-count {
	border-top: none;
	border-right: none;
	padding-right: 3px;
	padding-top: 3px;
	right: 0;
}

.owop-cursor-count[data-num-cur-world="1"]::before {
	content: attr(data-num-cur-world) ' cursor online';
}

.owop-cursor-count::before {
	content: attr(data-num-cur-world) ' cursors online';
}

.owop-cursor-count[data-num-cur-global="1"]:active::before {
	content: attr(data-num-cur-global) ' cursor globally';
}

.owop-cursor-count:active::before {
	content: attr(data-num-cur-global) ' cursors globally';
}

/* HELP WINDOW */

.help-links {
	display: flex;
	border-bottom: 1px solid #00000055;
}

.help-links > a {
	margin: 10px;
}

.help-cont {
	padding: 5px;
	text-align: left;
}

.help-cont::before {
	content: 'There\'s no help for you, yet...';
}

/* SETTINGS WINDOW */

.owop-win-settings h1 {
	border-bottom: 1px solid #00000044;
	margin-bottom: 3px;
	margin-left: -1px;
}

.settings-themes {
	max-height: 400px;
	overflow: auto;
}

.item-theme {
	width: 100%;
	min-height: 48px;
	max-width: 350px;
	box-sizing: border-box;
	display: flex;
	position: relative;
}

.item-theme.active::after {
	content: 'Selected';
	position: absolute;
	bottom: 0;
	right: 0;
	background: #00000044;
	padding: 3px;
	border-radius: 3px;
}

.item-theme:not(.active) {
	cursor: pointer;
}

.item-theme + .item-theme {
	margin-top: 3px;
}

.item-theme-pv {
	width: calc(var(--tex-isz-tools) * 2);
	height: calc(var(--tex-isz-tools) * 2);
	position: relative;
	border: 8px transparent solid;
	border-image: var(--tex-url-border-active) 8 fill repeat;
	flex-shrink: 0;
}

.info-theme-name {
	border-bottom: 1px solid #FFFFFF44;
}

.item-theme-info {
	margin: 0 8px;
	flex-grow: 1;
}

.item-theme-pv::before, .item-theme-pv::after {
	content: '';
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 50%;
	background: var(--tex-url-tools);
}

.item-theme-pv::after {
	top: unset;
	bottom: 0;
	background-position: calc(var(--tex-isz-tools) * -2) 0;
}

/* CHAT */

#chat {
	transform: translateY(100%);
}

#chat,
#dev-chat {
	position: absolute;
	right: 0;
	bottom: 0;
	min-width: 20%;
	max-width: 450px;
	/* max-height: 40%; // causes problems on old browsers */
	display: flex;
	font-family: pixel-op, monospace;
	flex-direction: column;
	background-color: transparent;
	pointer-events: none;
	overflow: hidden;
	transition: background-color 0.2s, box-shadow 0.2s, transform 0.75s;
	animation-fill-mode: forwards;
}

#dev-chat {
	left: 0;
	right: initial;
}

#chat.active,
#dev-chat.active {
	background-color: rgba(0, 0, 0, 0.8);
	box-shadow: 0px 0px 5px #000;
	pointer-events: all;
	overflow-y: auto;
}

@keyframes fade {
	from {
		opacity: 1;
	}

	to {
		opacity: 0;
	}
}

#chat-messages>li {
	background-color: rgba(0, 0, 0, 0.8);
	animation-name: fade;
	animation-duration: 3s;
	animation-delay: 15s;
	animation-fill-mode: forwards;
	transition: background-color 0.2s;
	white-space: pre-wrap;
}

#chat-messages>li a:link {
	color: #82c9ff;
}

#chat-messages>li a:visited {
	color: #ab80f9;
}

#chat-messages>li a:hover {
	color: #76b0dc;
}

#chat-messages>li.playerMessage {
	color: #999;
}

#chat-messages>li.userMessage>.nick {
	color: #3ab2ff;
}

#chat-messages>li.modMessage {
	color: #86ff41;
}

#chat-messages>li.adminMessage,
#chat-messages>li.serverError,
#chat-messages>li.serverRaw {
	color: #ff4f4f;
}

#chat-messages>li.discord>.nick {
	color: #6cffe7;
}

#chat-messages>li.serverInfo {
	color: #ff41e4;
}

#chat-messages>li.whisper,
#chat-messages>li>.whisper {
	color: #ffb735;
}

#chat-messages .emote {
	max-width: 1.375em;
	max-height: 1.375em;
	vertical-align: bottom;
	image-rendering: auto;
}

#chat-messages.active>li {
	background-color: initial;
	animation-duration: 0s;
	animation-direction: reverse;
}

#chat-messages,
#dev-chat-messages {
	flex: 1;
	margin: 0;
	padding: 0;
	font-size: 16px;
	max-height: 40vh;
	word-wrap: break-word;
	overflow: inherit;
	vertical-align: bottom;
}

#chat-input {
	flex: 0 1 auto;
	height: 16px;
	color: #FFF;
	pointer-events: all;
	border: 1px solid #666;
	padding: 4px;
	background: rgba(0, 0, 0, 0.8);
	font-family: pixel-op, sans-serif;
	font-size: 16px;
	resize: none;
	overflow-y: scroll;
	display: none;
}

#chat-input:focus {
	outline: none;
}

#chat-input::-moz-placeholder {
	color: #BBB;
}

#chat-input::placeholder {
	color: #BBB;
}

#captchawdow {
	margin: -4px;
}
