:root {
	color-scheme: dark;
	font-family: "Segoe UI", sans-serif;
	background: #101216;
	color: #e8e4d9;
}

html, body {
	margin: 0;
	height: 100%;
	overflow: hidden;
}

#hud {
	position: fixed;
	z-index: 2;
	top: 0;
	left: 0;
	right: 0;
	display: flex;
	gap: 1.25rem;
	align-items: center;
	padding: 0.5rem 0.75rem;
	background: rgba(12, 14, 18, 0.82);
}

#overlay {
	position: fixed;
	inset: 0;
	z-index: 3;
	display: grid;
	place-items: center;
	background: #101216;
}

#overlay[hidden], #hud[hidden] {
	display: none !important;
}

.panel {
	width: min(420px, 92vw);
	background: #1a1e26;
	border: 1px solid #2c3340;
	padding: 1.25rem;
}

label, .character-row {
	display: flex;
	gap: 0.5rem;
	align-items: center;
	margin: 0.5rem 0;
}

input, select, button {
	font: inherit;
	background: #101216;
	color: inherit;
	border: 1px solid #3a4250;
	padding: 0.3rem 0.5rem;
}

button {
	cursor: pointer;
}

.error { color: #f0a0a0; min-height: 1.2em; }
.hint { color: #9aa3b2; font-size: 0.9rem; }
a { color: #d4c48a; }

#nametag {
	position: fixed;
	z-index: 4;
	pointer-events: none;
	transform: translate(-50%, -100%);
	background: rgba(12, 14, 18, 0.88);
	border: 1px solid #3a4250;
	padding: 0.1rem 0.45rem;
	font-size: 0.85rem;
}

#context-menu {
	position: fixed;
	z-index: 20;
	min-width: 140px;
	background: #161a22;
	border: 1px solid #3a4250;
	padding: 0.25rem;
	display: flex;
	flex-direction: column;
	gap: 0.15rem;
}

#context-menu[hidden] {
	display: none !important;
}

#context-menu button {
	display: block;
	width: 100%;
	text-align: left;
	background: transparent;
	border: 0;
	color: #e8ecf4;
	padding: 0.35rem 0.55rem;
	cursor: pointer;
}

#context-menu button:hover {
	background: #2a3140;
}

#inspect-backdrop {
	position: fixed;
	inset: 0;
	z-index: 6;
	background: rgba(0, 0, 0, 0.45);
}

#inspect-modal {
	position: fixed;
	z-index: 7;
	left: 50%;
	top: 40%;
	transform: translate(-50%, -50%);
	width: min(360px, 92vw);
	background: #161a22;
	border: 1px solid #3a4250;
	padding: 0.85rem 1rem 1rem;
}

#inspect-modal header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.75rem;
}

#inspect-action {
	display: flex;
	flex-wrap: wrap;
	gap: 0.4rem;
	margin-top: 0.5rem;
}

#death-backdrop {
	position: fixed;
	inset: 0;
	z-index: 20;
	background: rgba(0, 0, 0, 0.72);
}

#death-modal {
	position: fixed;
	z-index: 21;
	left: 50%;
	top: 42%;
	transform: translate(-50%, -50%);
	width: min(380px, 92vw);
	background: #161a22;
	border: 1px solid #713b3b;
	padding: 1rem 1.15rem 1.15rem;
	text-align: center;
}

#death-respawn {
	min-width: 9rem;
}

#friends-panel {
	position: fixed;
	z-index: 5;
	top: 48px;
	right: 0.75rem;
	width: min(280px, 92vw);
	max-height: calc(100vh - 64px);
	overflow: auto;
	background: #1a1e26;
	border: 1px solid #2c3340;
	padding: 0.75rem;
}

#skills-panel {
	position: fixed;
	z-index: 5;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	width: min(520px, 94vw);
	max-height: calc(100vh - 80px);
	overflow: auto;
	background: #1a1e26;
	border: 1px solid #2c3340;
	padding: 0.75rem;
	box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

.skills-grid {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 0.55rem 0.75rem;
	margin: 0.5rem 0;
}

.skill-row {
	display: flex;
	gap: 0.55rem;
	align-items: stretch;
	min-width: 0;
}

.skill-icon {
	flex: 0 0 36px;
	width: 36px;
	height: 36px;
	border-radius: 6px;
	background: #101216;
	border: 1px solid #3a4250;
}

.skill-body {
	flex: 1;
	display: flex;
	flex-direction: column;
	justify-content: center;
	gap: 0.25rem;
	min-width: 0;
}

.skill-title {
	font-size: 0.85rem;
	line-height: 1.2;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.skill-xp-track {
	height: 8px;
	background: #101216;
	border: 1px solid #3a4250;
	border-radius: 4px;
	overflow: hidden;
}

.skill-xp-fill {
	height: 100%;
	background: linear-gradient(90deg, #6a7a40, #d4c48a);
	border-radius: 3px;
	transition: width 0.25s ease-out;
}

#bag-panel, #bank-panel {
	position: fixed;
	z-index: 5;
	top: 48px;
	left: 0.75rem;
	width: min(320px, 92vw);
	max-height: calc(100vh - 64px);
	overflow: auto;
	background: #1a1e26;
	border: 1px solid #2c3340;
	padding: 0.75rem;
}

#bank-panel {
	left: auto;
	right: 0.75rem;
	width: min(340px, 92vw);
}

#bank-panel header {
	display: flex;
	justify-content: space-between;
	align-items: center;
}

.bank-tabs {
	display: flex;
	gap: 0.25rem;
	margin: 0.4rem 0;
}

.bank-tab {
	flex: 1;
	font-size: 0.8rem;
	padding: 0.3rem 0.4rem;
}

.bank-tab.active {
	outline: 1px solid #d4c48a;
}

.item-grid {
	display: grid;
	grid-template-columns: repeat(8, 1fr);
	gap: 0.25rem;
	margin: 0.4rem 0;
}

.item-grid.equip {
	grid-template-columns: repeat(3, 1fr);
}

.item-slot {
	position: relative;
	min-height: 36px;
	padding: 0.15rem;
	image-rendering: pixelated;
}

.item-slot img {
	width: 100%;
	height: 32px;
	object-fit: contain;
	image-rendering: pixelated;
}

.item-slot.selected {
	outline: 2px solid #d4c48a;
}

.item-slot .qty {
	position: absolute;
	right: 2px;
	bottom: 1px;
	font-size: 0.7rem;
}

.bag-actions {
	display: flex;
	flex-wrap: wrap;
	gap: 0.35rem;
}

.modal-backdrop {
	position: fixed;
	inset: 0;
	z-index: 5;
	background: rgba(8, 10, 14, 0.55);
}

#send-panel,
#send-target-panel,
#letter-panel,
#transfer-panel,
#write-cheque-panel {
	position: fixed;
	z-index: 6;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	width: min(380px, 92vw);
	max-height: min(80vh, 640px);
	overflow: auto;
	background: #1a1e26;
	border: 1px solid #2c3340;
	padding: 0.85rem 1rem 1rem;
}

#craft-panel {
	position: fixed;
	z-index: 6;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	width: min(560px, 94vw);
	max-height: min(85vh, 720px);
	overflow: auto;
	background: #1a1e26;
	border: 1px solid #2c3340;
	padding: 0.85rem 1rem 1rem;
}

#craft-panel header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-bottom: 0.5rem;
}

.craft-layout {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 0.75rem;
	align-items: start;
}

@media (max-width: 520px) {
	.craft-layout {
		grid-template-columns: 1fr;
	}
}

.craft-recipe-grid {
	display: grid;
	grid-template-columns: repeat(3, 1fr);
	gap: 0.35rem;
}

.craft-recipe-cell {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 0.2rem;
	padding: 0.35rem 0.25rem;
	min-height: 72px;
	background: #12151c;
	border: 1px solid #2c3340;
	cursor: pointer;
}

.craft-recipe-cell.selected {
	outline: 2px solid #d4c48a;
}

.craft-recipe-cell img {
	width: 32px;
	height: 32px;
	object-fit: contain;
	image-rendering: pixelated;
}

.craft-recipe-name {
	font-size: 0.72rem;
	text-align: center;
	line-height: 1.15;
	word-break: break-word;
}

.craft-detail {
	min-height: 160px;
	padding: 0.35rem;
	background: #12151c;
	border: 1px solid #2c3340;
}

.craft-output {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 0.25rem;
	margin-bottom: 0.5rem;
}

.craft-output img {
	width: 48px;
	height: 48px;
	object-fit: contain;
	image-rendering: pixelated;
}

.craft-output h3 {
	margin: 0;
	font-size: 0.95rem;
	text-align: center;
}

.craft-inputs {
	list-style: none;
	margin: 0 0 0.5rem;
	padding: 0;
}

.craft-input-row {
	display: flex;
	align-items: center;
	gap: 0.4rem;
	margin-bottom: 0.35rem;
	font-size: 0.85rem;
}

.craft-input-row.short {
	color: #c07070;
}

.craft-input-row img {
	width: 24px;
	height: 24px;
	object-fit: contain;
	image-rendering: pixelated;
}

.craft-progress {
	height: 8px;
	margin: 0.4rem 0;
	background: #0e1014;
	border: 1px solid #2c3340;
	border-radius: 2px;
	overflow: hidden;
}

.craft-progress-fill {
	height: 100%;
	width: 0%;
	background: linear-gradient(90deg, #6a7a40, #d4c48a);
	transition: width 0.05s linear;
}

#craft-button {
	width: 100%;
	margin-top: 0.25rem;
}

#craft-button:disabled {
	opacity: 0.45;
}

#send-target-panel {
	z-index: 7;
}

#send-panel header,
#send-target-panel header,
#letter-panel header,
#transfer-panel header,
#write-cheque-panel header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 0.5rem;
	margin-bottom: 0.5rem;
}

#send-panel[hidden],
#send-target-panel[hidden],
#letter-panel[hidden],
#transfer-panel[hidden],
#write-cheque-panel[hidden],
.modal-backdrop[hidden] {
	display: none !important;
}

.send-item {
	display: flex;
	align-items: center;
	gap: 0.75rem;
	margin: 0.5rem 0;
}

.send-item img {
	width: 48px;
	height: 48px;
	object-fit: contain;
	image-rendering: pixelated;
}

.send-row {
	display: flex;
	flex-direction: column;
	gap: 0.25rem;
	margin: 0.5rem 0;
	font-size: 0.9rem;
}

.send-target-row {
	display: flex;
	align-items: center;
	gap: 0.65rem;
	width: 100%;
	text-align: left;
	margin: 0.3rem 0;
}

.send-target-text {
	display: flex;
	flex-direction: column;
	gap: 0.1rem;
}

.send-search {
	display: flex;
	flex-wrap: wrap;
	gap: 0.35rem;
	margin-top: 0.75rem;
}

.send-search input {
	flex: 1 1 6rem;
}

.char-preview {
	position: relative;
	width: 36px;
	height: 48px;
	flex: 0 0 auto;
	image-rendering: pixelated;
	background: #101216;
	border: 1px solid #2c3340;
}

.char-preview img {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	object-fit: contain;
	image-rendering: pixelated;
}

#letter-body {
	display: block;
	width: 100%;
	box-sizing: border-box;
	margin: 0;
	padding: 0;
	border: none;
	outline: none;
	resize: none;
	overflow: hidden;
	background: transparent;
	color: inherit;
	font: inherit;
	line-height: 1.45;
	min-height: 8rem;
	field-sizing: content;
}

.letter-paper {
	background: #f4f0e4;
	color: #1c1814;
	padding: 1.25rem 1.35rem;
	margin: 0.35rem 0 0.75rem;
	max-height: min(55vh, 420px);
	overflow-y: auto;
	scrollbar-width: none;
	-ms-overflow-style: none;
	box-shadow: inset 0 0 0 1px rgba(40, 32, 24, 0.08);
}

.letter-paper::-webkit-scrollbar {
	display: none;
	width: 0;
	height: 0;
}

.letter-signature {
	margin: 1.35rem 0 0;
	padding: 0;
	border: none;
	background: transparent;
	white-space: pre-wrap;
	font: inherit;
	color: inherit;
	line-height: 1.45;
}

#friends-panel h2, #friends-panel h3 {
	margin: 0.4rem 0;
	font-size: 0.95rem;
}

.social-row {
	display: flex;
	flex-wrap: wrap;
	gap: 0.35rem;
	align-items: center;
	margin: 0.35rem 0;
}

#inspect-modal[hidden],
#inspect-backdrop[hidden],
#death-modal[hidden],
#death-backdrop[hidden],
#friends-panel[hidden],
#skills-panel[hidden],
#bag-panel[hidden],
#bank-panel[hidden],
#craft-panel[hidden],
#craft-backdrop[hidden],
#nametag[hidden],
#chat-bar[hidden] {
	display: none !important;
}

#chat-bar {
	position: fixed;
	z-index: 5;
	left: 50%;
	bottom: 1.25rem;
	transform: translateX(-50%);
	width: min(640px, calc(100vw - 2rem));
}

#chat-bar input {
	width: 100%;
	box-sizing: border-box;
	padding: 0.55rem 0.75rem;
	background: rgba(12, 14, 18, 0.92);
}

#damage-numbers {
	position: fixed;
	inset: 0;
	z-index: 4;
	pointer-events: none;
	overflow: hidden;
}

.damage-number {
	position: absolute;
	transform: translate(-50%, -100%);
	font-size: 0.85rem;
	font-weight: 700;
	color: #fff;
	text-shadow: 0 1px 2px rgba(0, 0, 0, 0.85);
	white-space: nowrap;
	pointer-events: none;
	user-select: none;
}

.chat-bubble {
	position: fixed;
	z-index: 4;
	pointer-events: none;
	transform: translate(-50%, -100%);
	max-width: min(280px, 70vw);
	background: rgba(16, 18, 24, 0.92);
	border: 1px solid #3a4250;
	border-radius: 8px;
	padding: 0.3rem 0.55rem;
	font-size: 0.9rem;
	line-height: 1.25;
	white-space: pre-wrap;
	word-break: break-word;
}

.chat-bubble[hidden] {
	display: none !important;
}
