:root {
	--page-bg: #101112;
	--shell-bg: #181a1d;
	--panel-bg: #1e2125;
	--panel-bg-strong: #24272c;
	--field-bg: #15171a;
	--border-subtle: #30343b;
	--border-strong: #464b54;
	--text-main: #e8e3da;
	--text-muted: #a7adb7;
	--accent: #69d2b0;
	--accent-strong: #8ee6c8;
	--accent-contrast: #07130f;
	--warning: #d9a441;
	--danger: #d86f66;
	--focus-ring: rgba(105, 210, 176, 0.28);
	--shadow-lg: 0 18px 50px rgba(0, 0, 0, 0.36);
	--radius: 8px;
	color-scheme: dark;
}

*,
*::before,
*::after {
	box-sizing: border-box;
}

html,
body,
#app {
	margin: 0;
	min-height: 100%;
	width: 100%;
}

html,
body {
	height: 100%;
	overflow: hidden;
	background: var(--page-bg);
	color: var(--text-main);
	font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}

body {
	min-width: 320px;
}

button,
input,
select,
textarea {
	font: inherit;
}

.app-root {
	display: grid;
	align-items: stretch;
	justify-items: center;
	width: 100%;
	height: 100vh;
	height: 100dvh;
	min-height: 0;
	padding: clamp(0.5rem, 1.8vw, 1.5rem);
	overflow: hidden;
	background:
		linear-gradient(180deg, rgba(255, 255, 255, 0.035), rgba(255, 255, 255, 0)),
		var(--page-bg);
}

.app-grid {
	display: grid;
	grid-template-rows: minmax(0, 1fr) auto auto auto auto;
	width: min(100%, var(--client-app-width, 1500px));
	height: 100%;
	min-height: 0;
	overflow: hidden;
	border: 1px solid var(--border-subtle);
	border-radius: var(--radius);
	background: var(--shell-bg);
	box-shadow: var(--shadow-lg);
}

.play-surface {
	display: grid;
	grid-template-columns: minmax(0, 1fr) clamp(12rem, 16vw, 15rem);
	height: 100%;
	min-height: 0;
	overflow: hidden;
	border-bottom: 1px solid var(--border-subtle);
}

.message-container {
	min-height: 0;
	overflow-y: auto;
	padding: clamp(0.85rem, 1.45vw, 1.35rem);
	padding-left: calc(clamp(0.85rem, 1.45vw, 1.35rem) + var(--client-message-left-offset, 0px));
	background: #151719;
	color: var(--text-main);
	font-family: var(--client-font-family, Consolas, "Cascadia Mono", "Courier New", monospace);
	font-size: var(--client-font-size, clamp(0.78rem, 0.72rem + 0.18vw, 0.95rem));
	line-height: var(--client-message-line-height, 1.48);
	white-space: pre-wrap;
	overflow-wrap: anywhere;
	scrollbar-color: var(--border-strong) transparent;
	scrollbar-width: thin;
}

.message-container > div + div {
	margin-top: var(--client-message-spacing, 6px);
}

.message-container > div {
	max-width: var(--client-message-wrap-width, none);
	content-visibility: auto;
	contain-intrinsic-size: auto 1.5em;
}

.message-container::-webkit-scrollbar,
.hotkey-strip::-webkit-scrollbar,
.input-field::-webkit-scrollbar {
	width: 0.6rem;
	height: 0.6rem;
}

.message-container::-webkit-scrollbar-track,
.hotkey-strip::-webkit-scrollbar-track,
.input-field::-webkit-scrollbar-track {
	background: transparent;
}

.message-container::-webkit-scrollbar-thumb,
.hotkey-strip::-webkit-scrollbar-thumb,
.input-field::-webkit-scrollbar-thumb {
	background: var(--border-strong);
	border: 2px solid transparent;
	border-radius: 999px;
	background-clip: padding-box;
}

.message-container::-webkit-scrollbar-thumb:hover,
.hotkey-strip::-webkit-scrollbar-thumb:hover,
.input-field::-webkit-scrollbar-thumb:hover {
	background-color: #5b626d;
}

.hotkey-panel {
	display: flex;
	flex-direction: column;
	gap: 0.7rem;
	min-width: 0;
	padding: 0.75rem;
	overflow-x: hidden;
	overflow-y: auto;
	background: #1a1d20;
	border-left: 1px solid var(--border-subtle);
}

.hotkey-panel-title {
	color: var(--text-muted);
	font-size: 0.75rem;
	font-weight: 750;
	letter-spacing: 0.08em;
	text-transform: uppercase;
}

.hotkey-pad {
	display: grid;
	grid-template-columns: repeat(4, minmax(0, 1fr));
	grid-template-rows: repeat(5, 2.65rem);
	gap: 0.42rem;
	flex: 0 0 auto;
	min-height: 0;
	align-content: start;
}

.quick-alias-panel {
	display: flex;
	flex-direction: column;
	gap: 0.42rem;
	padding-top: 0.7rem;
	border-top: 1px solid var(--border-subtle);
}

.quick-alias-grid {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: 0.42rem;
}

.hotkey-strip {
	display: none;
	gap: 0.45rem;
	min-height: 3.05rem;
	padding: 0.5rem clamp(0.65rem, 1.15vw, 0.95rem);
	overflow-x: auto;
	background: #1a1d20;
	border-bottom: 1px solid var(--border-subtle);
	scrollbar-color: var(--border-strong) transparent;
	scrollbar-width: thin;
}

.hotkey-button {
	display: grid;
	grid-template-columns: minmax(0, 1fr) auto;
	align-items: center;
	gap: 0.35rem;
	min-width: 0;
	min-height: 2.15rem;
	padding: 0.36rem 0.46rem;
	border: 1px solid var(--border-subtle);
	border-radius: 7px;
	color: var(--text-main);
	background: #262b31;
	cursor: pointer;
	font-weight: 700;
	letter-spacing: 0;
	transition:
		background-color 150ms ease,
		border-color 150ms ease,
		box-shadow 150ms ease,
		transform 120ms ease;
}

.quick-alias-button {
	display: flex;
	align-items: center;
	justify-content: center;
	min-width: 0;
	min-height: 2.15rem;
	padding: 0.38rem 0.48rem;
	border: 1px solid var(--border-subtle);
	border-radius: 7px;
	color: var(--text-main);
	background: #242a30;
	cursor: pointer;
	font-size: 0.86rem;
	font-weight: 700;
	letter-spacing: 0;
	text-align: center;
	transition:
		background-color 150ms ease,
		border-color 150ms ease,
		box-shadow 150ms ease,
		transform 120ms ease;
}

.quick-alias-login {
	min-height: 2.35rem;
	background: #2e3a3d;
	border-color: #415257;
	color: #d9f5eb;
}

.hotkey-pad .hotkey-button {
	grid-template-columns: 1fr;
	grid-template-rows: minmax(0, 1fr) auto;
	justify-items: center;
	min-height: 0;
	padding: 0.28rem;
	text-align: center;
}

.hotkey-button:hover {
	background: #30363d;
	border-color: #56606a;
}

.quick-alias-button:hover {
	background: #30363d;
	border-color: #56606a;
}

.hotkey-button:focus-visible,
.quick-alias-button:focus-visible {
	outline: none;
	box-shadow: 0 0 0 3px var(--focus-ring);
}

.hotkey-button:active,
.quick-alias-button:active {
	transform: translateY(1px);
}

.hotkey-button:disabled,
.quick-alias-button:disabled {
	cursor: default;
	opacity: 0.58;
	transform: none;
}

.hotkey-button.is-empty,
.quick-alias-button.is-empty {
	background: #202429;
	color: var(--text-muted);
}

.hotkey-button-label {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	text-align: center;
	max-width: 100%;
	line-height: 1.1;
}

.quick-alias-label {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	max-width: 100%;
	line-height: 1.1;
}

.hotkey-button-key {
	min-width: 1.35rem;
	padding: 0.12rem 0.28rem;
	border: 1px solid #4a515b;
	border-radius: 5px;
	color: #d9f5eb;
	background: #151719;
	font-family: Consolas, "Cascadia Mono", "Courier New", monospace;
	font-size: 0.72rem;
	font-weight: 700;
	text-align: center;
	white-space: nowrap;
}

.hotkey-button-northwest {
	grid-column: 1;
	grid-row: 2;
}

.hotkey-button-north {
	grid-column: 2;
	grid-row: 2;
}

.hotkey-button-northeast {
	grid-column: 3;
	grid-row: 2;
}

.hotkey-button-west {
	grid-column: 1;
	grid-row: 3;
}

.hotkey-button-numpad5 {
	grid-column: 2;
	grid-row: 3;
}

.hotkey-button-east {
	grid-column: 3;
	grid-row: 3;
}

.hotkey-button-southwest {
	grid-column: 1;
	grid-row: 4;
}

.hotkey-button-south {
	grid-column: 2;
	grid-row: 4;
}

.hotkey-button-southeast {
	grid-column: 3;
	grid-row: 4;
}

.hotkey-button-look {
	grid-column: 1 / span 2;
	grid-row: 5;
}

.hotkey-button-enter {
	grid-column: 2;
	grid-row: 1;
}

.hotkey-button-leave {
	grid-column: 3;
	grid-row: 1;
}

.hotkey-button-up {
	grid-column: 4;
	grid-row: 1;
}

.hotkey-button-down {
	grid-column: 4;
	grid-row: 2 / span 2;
}

.hotkey-button-score {
	grid-column: 3;
	grid-row: 5;
}

.hotkey-button-numpad-enter {
	grid-column: 4;
	grid-row: 4 / span 2;
}

.input-container {
	display: grid;
	gap: 0.55rem;
	padding: clamp(0.65rem, 1.15vw, 0.95rem);
	background: var(--panel-bg);
	border-bottom: 1px solid var(--border-subtle);
}

.input-toolbar {
	display: flex;
	align-items: center;
	gap: 0.65rem;
	min-width: 0;
}

.file-input-button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex: 0 0 auto;
	cursor: pointer;
}

.file-input-button input[type="file"] {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

.input-help,
.batch-progress {
	color: var(--text-muted);
	font-size: 0.82rem;
}

.batch-progress {
	display: inline-flex;
	align-items: center;
	white-space: nowrap;
}

.settings-panel {
	max-height: min(26rem, 45dvh);
	padding: clamp(0.65rem, 1.15vw, 0.95rem);
	overflow: auto;
	background: #1b1f23;
	border-bottom: 1px solid var(--border-subtle);
}

.settings-panel-header {
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: 1rem;
	margin-bottom: 0.75rem;
}

.settings-panel h2,
.settings-panel p {
	margin: 0;
}

.settings-panel h2 {
	font-size: 1rem;
	line-height: 1.2;
}

.settings-panel p {
	margin-top: 0.25rem;
	color: var(--text-muted);
	font-size: 0.86rem;
	line-height: 1.35;
}

.settings-actions {
	display: flex;
	flex-wrap: wrap;
	justify-content: flex-end;
	gap: 0.45rem;
}

.settings-error {
	margin-bottom: 0.7rem;
	padding: 0.55rem 0.7rem;
	border: 1px solid rgba(216, 111, 102, 0.5);
	border-radius: var(--radius);
	color: #ffd6d1;
	background: rgba(216, 111, 102, 0.12);
	font-size: 0.88rem;
	line-height: 1.4;
}

.settings-grid {
	display: grid;
	grid-template-columns: 3.25rem minmax(7rem, 1fr) minmax(8rem, 0.9fr) minmax(12rem, 2fr) auto;
	min-width: 760px;
	border: 1px solid var(--border-subtle);
	border-radius: var(--radius);
	overflow: hidden;
}

.settings-grid-row {
	display: contents;
}

.settings-grid-row > * {
	display: flex;
	align-items: center;
	min-width: 0;
	padding: 0.45rem;
	border-top: 1px solid var(--border-subtle);
	background: #20242a;
}

.settings-grid-header > * {
	border-top: 0;
	color: var(--text-muted);
	background: #171a1d;
	font-size: 0.78rem;
	font-weight: 700;
	text-transform: uppercase;
}

.toggle-cell {
	justify-content: center;
}

.toggle-cell input {
	width: 1.05rem;
	height: 1.05rem;
	accent-color: var(--accent);
}

.settings-input {
	width: 100%;
	min-height: 2.15rem;
	padding: 0.45rem 0.55rem;
	border: 1px solid var(--border-strong);
	border-radius: 6px;
	outline: none;
	color: var(--text-main);
	background: var(--field-bg);
	font-size: 0.9rem;
	line-height: 1.25;
}

.settings-input:focus {
	border-color: var(--accent);
	box-shadow: 0 0 0 3px var(--focus-ring);
}

.key-input {
	cursor: pointer;
	font-family: Consolas, "Cascadia Mono", "Courier New", monospace;
}

.settings-section + .settings-section {
	margin-top: 1rem;
}

.settings-section h3 {
	margin: 0 0 0.55rem;
	color: var(--text-muted);
	font-size: 0.8rem;
	font-weight: 750;
	letter-spacing: 0.07em;
	line-height: 1.2;
	text-transform: uppercase;
}

.client-settings-grid {
	display: grid;
	grid-template-columns: repeat(3, minmax(0, 1fr));
	gap: 0.55rem;
}

.client-settings-grid label:not(.settings-checkbox) {
	display: grid;
	gap: 0.28rem;
	color: var(--text-muted);
	font-size: 0.78rem;
	font-weight: 700;
	text-transform: uppercase;
}

.client-settings-grid small {
	color: var(--text-muted);
	font-size: 0.72rem;
	font-weight: 400;
	line-height: 1.25;
	text-transform: none;
}

.settings-checkbox {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	min-height: 2.15rem;
	color: var(--text-main);
	font-size: 0.86rem;
}

.settings-checkbox input {
	width: 1.05rem;
	height: 1.05rem;
	accent-color: var(--accent);
}

.login-settings-grid {
	display: grid;
	grid-template-columns: repeat(3, minmax(0, 1fr));
	gap: 0.55rem;
	min-width: 760px;
}

.login-settings-grid label {
	display: grid;
	gap: 0.28rem;
	color: var(--text-muted);
	font-size: 0.78rem;
	font-weight: 700;
	text-transform: uppercase;
}

.alias-settings-grid {
	display: grid;
	grid-template-columns: 3.25rem minmax(7rem, 0.8fr) minmax(16rem, 2.2fr);
	min-width: 760px;
	border: 1px solid var(--border-subtle);
	border-radius: var(--radius);
	overflow: hidden;
}

.alias-settings-grid-row {
	display: contents;
}

.alias-settings-grid-row > * {
	display: flex;
	align-items: center;
	min-width: 0;
	padding: 0.45rem;
	border-top: 1px solid var(--border-subtle);
	background: #20242a;
}

.input-field {
	display: block;
	width: 100%;
	height: clamp(4.25rem, 10dvh, 7rem);
	min-height: 4.25rem;
	max-height: 12rem;
	margin: 0;
	padding: 0.8rem 0.9rem;
	overflow: auto;
	resize: none;
	border: 1px solid var(--border-strong);
	border-radius: var(--radius);
	outline: none;
	background: var(--field-bg);
	color: #f2eee7;
	box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
	font-family: var(--client-font-family, Consolas, "Cascadia Mono", "Courier New", monospace);
	font-size: var(--client-font-size, clamp(0.9rem, 0.82rem + 0.18vw, 1rem));
	line-height: var(--client-message-line-height, 1.4);
	transition:
		border-color 150ms ease,
		box-shadow 150ms ease,
		background-color 150ms ease;
}

.input-field::placeholder {
	color: #7f858f;
	opacity: 1;
}

.input-field:focus {
	border-color: var(--accent);
	background: #171a1d;
	box-shadow:
		0 0 0 3px var(--focus-ring),
		inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.status-footer {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.75rem;
	padding: clamp(0.65rem, 1.1vw, 0.9rem);
	background: var(--panel-bg-strong);
}

.connection-status,
.button-container {
	display: flex;
	align-items: center;
	gap: 0.6rem;
}

.connection-status {
	min-height: 2.5rem;
	padding: 0.45rem 0.7rem;
	border: 1px solid var(--border-subtle);
	border-radius: var(--radius);
	color: var(--text-muted);
	background: rgba(0, 0, 0, 0.14);
	font-size: 0.9rem;
	font-weight: 600;
}

.connection-dot {
	width: 0.7rem;
	height: 0.7rem;
	flex: 0 0 auto;
	border-radius: 999px;
	background: var(--danger);
	box-shadow: 0 0 0 3px rgba(216, 111, 102, 0.14);
}

.connection-dot.is-connected {
	background: var(--accent);
	box-shadow: 0 0 0 3px rgba(105, 210, 176, 0.15);
}

.connection-dot.is-disconnected {
	background: var(--warning);
	box-shadow: 0 0 0 3px rgba(217, 164, 65, 0.14);
}

.button-container {
	justify-content: flex-end;
	flex-wrap: wrap;
}

.client-button {
	min-height: 2.5rem;
	padding: 0.6rem 1rem;
	border: 1px solid transparent;
	border-radius: var(--radius);
	cursor: pointer;
	color: var(--text-main);
	background: #333840;
	font-size: 0.95rem;
	font-weight: 650;
	letter-spacing: 0;
	transition:
		background-color 150ms ease,
		border-color 150ms ease,
		box-shadow 150ms ease,
		color 150ms ease,
		transform 120ms ease;
}

.client-button:hover {
	background: #3d434c;
	border-color: #59616c;
}

.client-button:focus-visible {
	outline: none;
	box-shadow: 0 0 0 3px var(--focus-ring);
}

.client-button:active {
	transform: translateY(1px);
}

.client-button:disabled {
	cursor: not-allowed;
	opacity: 0.55;
	transform: none;
}

.primary-button {
	background: var(--accent);
	color: var(--accent-contrast);
}

.primary-button:hover {
	background: var(--accent-strong);
	border-color: var(--accent-strong);
}

.secondary-button {
	background: #30343b;
	border-color: #434955;
}

.compact-button {
	min-height: 2.15rem;
	padding: 0.42rem 0.65rem;
	background: #2f343b;
	border-color: #444b55;
	font-size: 0.86rem;
}

.visually-hidden {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

a {
	color: #7ec8ff;
	text-decoration-color: rgba(126, 200, 255, 0.55);
	text-underline-offset: 0.16em;
	transition:
		color 150ms ease,
		text-decoration-color 150ms ease;
}

a:hover {
	color: #a9dcff;
	text-decoration-color: currentColor;
}

.mxp-send-link {
	cursor: pointer;
	font-weight: 650;
}

.mxp-image {
	display: block;
	max-width: 100%;
	max-height: min(20rem, 45dvh);
	margin: 0.35rem 0;
	border-radius: var(--radius);
}

.ansi-blink {
	animation: ansi-blink 1s steps(1, end) infinite;
}

@keyframes ansi-blink {
	50% {
		opacity: 0;
	}
}

@media (max-width: 900px) {
	.app-root {
		padding: 0.75rem;
	}

	.app-grid {
		width: 100%;
	}

	.play-surface {
		display: block;
	}

	.message-container {
		height: 100%;
		border-bottom: 1px solid var(--border-subtle);
	}

	.hotkey-panel {
		display: none;
	}

	.hotkey-strip {
		display: flex;
	}

	.hotkey-strip .hotkey-button {
		flex: 0 0 auto;
		min-width: 5.5rem;
	}
}

@media (max-width: 640px) {
	.app-root {
		padding: 0;
	}

	.app-grid {
		border-width: 0;
		border-radius: 0;
	}

	.message-container {
		padding: 0.75rem;
		line-height: 1.42;
	}

	.hotkey-strip {
		min-height: 2.85rem;
		padding: 0.42rem 0.5rem;
	}

	.hotkey-strip .hotkey-button {
		min-width: 4.85rem;
		min-height: 2rem;
		padding: 0.3rem 0.4rem;
		font-size: 0.86rem;
	}

	.hotkey-button-key {
		font-size: 0.68rem;
	}

	.input-container,
	.settings-panel,
	.status-footer {
		padding: 0.6rem;
	}

	.input-field {
		height: clamp(4.25rem, 12dvh, 6rem);
	}

	.status-footer,
	.connection-status,
	.button-container {
		align-items: stretch;
	}

	.status-footer {
		flex-direction: column;
	}

	.input-toolbar {
		align-items: stretch;
		flex-direction: column;
	}

	.settings-panel-header {
		flex-direction: column;
	}

	.client-settings-grid {
		grid-template-columns: repeat(2, minmax(0, 1fr));
	}

	.settings-actions {
		display: grid;
		grid-template-columns: repeat(3, minmax(0, 1fr));
		width: 100%;
	}

	.connection-status,
	.button-container,
	.client-button {
		width: 100%;
	}

	.button-container {
		display: grid;
		grid-template-columns: 1fr 1fr;
	}
}

@media (max-width: 420px) {
	.client-settings-grid {
		grid-template-columns: 1fr;
	}

	.button-container {
		grid-template-columns: 1fr;
	}
}

@media (prefers-reduced-motion: reduce) {
	*,
	*::before,
	*::after {
		scroll-behavior: auto !important;
		transition-duration: 0.01ms !important;
		animation-duration: 0.01ms !important;
		animation-iteration-count: 1 !important;
	}

	.ansi-blink {
		animation: none;
	}
}
