:root {
	color-scheme: dark;

	/* The page's one palette and type scale (the game's own colours). New rules use these. */
	--ui-text: #e8dcc0;
	--ui-text-dim: #9a8f78;
	--ui-ink: #0e0e0a;          /* captions on the light game button faces */
	--ui-gold: #c89b3c;
	--ui-gold-hi: #f0d080;
	--ui-line: #6b5020;
	--ui-danger: #9a1e12;       /* captions of irreversible actions */
	--ui-danger-hi: #e0483a;
	--ui-ok: #6fd27a;
	--ui-teal: #7fcfb8;         /* the game's pressed/hovered button colour */
	--ui-body: rgba(0, 0, 0, 0.73); /* window and slot bodies of the game UI */
	--ui-font: "Segoe UI", system-ui, sans-serif;
	--ui-font-title: Georgia, "Times New Roman", serif;
	--ui-font-btn: bold 15px/1 Arial, sans-serif;
	--ui-fs-s: 11px;
	--ui-fs-m: 13px;
	--ui-fs-l: 15px;
	--ui-fs-xl: 18px;
	--ui-radius: 3px;

	--fg: var(--ui-text);
	--muted: var(--ui-text-dim);
	--accent: var(--ui-gold);
	--panel: rgba(12, 10, 8, 0.88);
	font-family: "Segoe UI", system-ui, sans-serif;

	/* Knight Online look: dark leather and stone, gold trim. */
	--ko-panel: radial-gradient(120% 80% at 50% 0%, rgba(70, 52, 30, 0.35), transparent 60%),
		linear-gradient(180deg, rgba(34, 27, 19, 0.95), rgba(14, 11, 8, 0.95));
	--ko-gold: var(--ui-gold);
	--ko-gold-hi: var(--ui-gold-hi);
	--ko-gold-lo: var(--ui-line);
	--ko-red: #b8321e;
	--ko-green: #6fd27a;
	--ko-serif: var(--ui-font-title);
	/* e_ItemAttrib: normal, magic, rare, craft, unique, upgrade. */
	--ko-attr-0: #e8e2d0;
	--ko-attr-1: #6f9bff;
	--ko-attr-2: #f0d050;
	--ko-attr-3: #5fc46a;
	--ko-attr-4: #e0a040;
	--ko-attr-5: #c070f0;
}

.ko-panel,
.hud-panel {
	border: 1px solid var(--ko-gold-lo);
	border-radius: 6px;
	background:
		radial-gradient(circle at 0 0, var(--ko-gold) 0 2px, transparent 3px),
		radial-gradient(circle at 100% 0, var(--ko-gold) 0 2px, transparent 3px),
		radial-gradient(circle at 0 100%, var(--ko-gold) 0 2px, transparent 3px),
		radial-gradient(circle at 100% 100%, var(--ko-gold) 0 2px, transparent 3px),
		var(--ko-panel);
	box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.6), inset 0 0 0 3px rgba(200, 155, 60, 0.28), 0 6px 18px rgba(0, 0, 0, 0.6);
}

.ko-title {
	margin: 0;
	padding: 2px 10px;
	border-bottom: 1px solid var(--ko-gold-lo);
	background: linear-gradient(90deg, transparent, rgba(200, 155, 60, 0.22), transparent);
	color: var(--ko-gold-hi);
	font: 600 15px/1.4 var(--ko-serif);
	letter-spacing: 0.08em;
	text-align: center;
	text-shadow: 0 1px 0 #000, 0 0 6px rgba(240, 208, 128, 0.35);
}

#touch-controls button {
	color: var(--fg);
	background: linear-gradient(#3a2c1a, #1c150d);
	border: 1px solid var(--ko-gold-lo);
	box-shadow: inset 0 1px 0 rgba(240, 208, 128, 0.22), 0 1px 2px #000;
}

#touch-controls button.primary:not(.game-btn) {
	color: #fff4d0;
	background: linear-gradient(#8a6a28, #4a3612);
	border-color: var(--ko-gold-hi);
}

#touch-controls button.danger:not(.game-btn),
#touch-controls button.warn:not(.game-btn) {
	color: #f8d8c8;
	background: linear-gradient(#7a2a1a, #3c120a);
	border-color: rgba(220, 90, 50, 0.85);
}

#touch-controls button:disabled {
	opacity: 0.45;
}

.ko-slot {
	position: relative;
	border: 1px solid #3a2e1c;
	border-radius: 4px;
	background: rgba(0, 0, 0, 0.45);
	box-shadow: inset 0 0 6px #000;
}

.ko-slot.attr-1 { border-color: var(--ko-attr-1); }
.ko-slot.attr-2 { border-color: var(--ko-attr-2); }
.ko-slot.attr-3 { border-color: var(--ko-attr-3); }
.ko-slot.attr-4 { border-color: var(--ko-attr-4); }
.ko-slot.attr-5 { border-color: var(--ko-attr-5); }

.ko-tabs {
	display: flex;
	gap: 4px;
	overflow-x: auto;
}

.ko-tabs > button {
	flex: none;
}

.ko-tabs > button.active {
	color: #fff4d0;
	border-color: var(--ko-gold-hi);
	background: linear-gradient(#6a4e1e, #33250e);
}

.ko-dot {
	position: absolute;
	top: -3px;
	right: -3px;
	width: 11px;
	height: 11px;
	border-radius: 50%;
	background: var(--ko-red);
	box-shadow: 0 0 0 2px #000;
	pointer-events: none;
}

.ko-dot[hidden] {
	display: none;
}

* {
	box-sizing: border-box;
}

html,
body {
	margin: 0;
	height: 100%;
	height: 100dvh;
	background: #000;
	color: var(--fg);
	overflow: hidden;
	overscroll-behavior: none;
	touch-action: none;
	-webkit-text-size-adjust: 100%;
}

#stage {
	position: fixed;
	inset: 0;
	display: grid;
	place-items: center;
}

#canvas {
	display: block;
	max-width: 100vw;
	max-height: 100vh;
	max-height: 100dvh;
	aspect-ratio: auto;
	outline: none;
	image-rendering: auto;
	/* Touch gestures belong to the game, not to page scrolling or zooming. */
	touch-action: none;
	-webkit-user-select: none;
	user-select: none;
}

#touch-controls {
	position: absolute;
	inset: 0;
	pointer-events: none;
	padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#move-pad {
	position: absolute;
	left: 0;
	bottom: 0;
	width: 42%;
	height: 62%;
	pointer-events: none;
}

#touch-controls.in-world #move-pad {
	pointer-events: auto;
}

#touch-controls:not(.in-world) #joystick {
	opacity: 0;
	pointer-events: none;
}

#joystick {
	position: absolute;
	left: calc(var(--sa-l) + 6px);
	bottom: calc(var(--sa-b) + 6px);
	width: min(22vmin, 148px);
	height: min(22vmin, 148px);
	border-radius: 50%;
	background: rgba(20, 16, 10, 0.35);
	border: 2px solid rgba(200, 155, 60, 0.45);
	pointer-events: auto;
	touch-action: none;
	opacity: 0.55;
}

#joystick.active {
	opacity: 1;
}

#joystick-knob {
	position: absolute;
	left: 50%;
	top: 50%;
	width: 40%;
	height: 40%;
	margin: -20% 0 0 -20%;
	border-radius: 50%;
	background: rgba(200, 155, 60, 0.55);
}

/* Phone HUD. Sizes are phone pixels times --k (stage height / 390, set by hud.js). Absolute
   children ignore the padding above, so they add the safe-area insets themselves. */
#touch-controls {
	--k: 1;
	--sa-t: env(safe-area-inset-top, 0px);
	--sa-r: env(safe-area-inset-right, 0px);
	--sa-b: env(safe-area-inset-bottom, 0px);
	--sa-l: env(safe-area-inset-left, 0px);
}

#touch-controls [hidden] {
	display: none !important;
}

#touch-controls button {
	padding: 0;
	font: 600 13px/1.1 "Segoe UI", system-ui, sans-serif;
	touch-action: none;
	-webkit-user-select: none;
	user-select: none;
	-webkit-touch-callout: none;
	-webkit-tap-highlight-color: transparent;
}

#hud-combat,
#hud-top,
#hud-chat {
	display: none;
}

#touch-controls.in-world #hud-combat,
#touch-controls.in-world #hud-top,
#touch-controls.in-world #hud-chat {
	display: flex;
}

/* Zero-size anchor at the attack button's centre; every control sits at (--x, --y) from it.
   40px puts the 72px attack button 4px from the screen corner. */
#hud-combat {
	position: absolute;
	right: calc(var(--sa-r) + 40px * var(--k));
	bottom: calc(var(--sa-b) + 40px * var(--k));
	width: 0;
	height: 0;
	transition: opacity 120ms;
}

#hud-combat > button {
	position: absolute;
	left: 0;
	top: 0;
	width: calc(46px * var(--k));
	height: calc(46px * var(--k));
	border: 2px solid rgba(200, 155, 60, 0.6);
	border-radius: 50%;
	background: radial-gradient(circle at 50% 35%, rgba(70, 52, 30, 0.72), rgba(16, 12, 8, 0.66));
	pointer-events: auto;
	transform: translate(-50%, -50%) translate(calc(var(--x, 0px) * var(--k)), calc(var(--y, 0px) * var(--k)));
}

#hud-combat > .atk {
	width: calc(72px * var(--k));
	height: calc(72px * var(--k));
	font-size: calc(26px * var(--k));
	font-family: var(--ko-serif);
	color: #fff0d8;
	text-shadow: 0 1px 2px #000;
	background: radial-gradient(circle at 50% 35%, rgba(176, 62, 40, 0.86), rgba(88, 20, 12, 0.8));
	border-color: rgba(240, 160, 90, 0.85);
}

#hud-combat > .small {
	width: calc(44px * var(--k));
	height: calc(44px * var(--k));
}

/* Inner arc (r 72): slots 1-3; outer arc (r 132): slots 4-8; quarter circle left/up of attack. */
.hud-slot[data-slot="0"] { --x: -72px; --y: 0px; }
.hud-slot[data-slot="1"] { --x: -51px; --y: -51px; }
.hud-slot[data-slot="2"] { --x: 0px; --y: -72px; }
.hud-slot[data-slot="3"] { --x: -132px; --y: 0px; }
.hud-slot[data-slot="4"] { --x: -122px; --y: -50px; }
.hud-slot[data-slot="5"] { --x: -93px; --y: -93px; }
.hud-slot[data-slot="6"] { --x: -50px; --y: -122px; }
.hud-slot[data-slot="7"] { --x: 0px; --y: -132px; }
#hud-page { --x: 0px; --y: -190px; width: calc(40px * var(--k)) !important; height: calc(40px * var(--k)) !important; font-size: 12px; }
#hud-target { --x: -190px; --y: 4px; }
#hud-loot { --x: -244px; --y: 4px; }

.hud-slot {
	overflow: hidden;
}

.hud-slot:empty::before {
	content: "+";
	color: rgba(200, 155, 60, 0.5);
	font-size: 20px;
}

.hud-slot img {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	border-radius: 50%;
	pointer-events: none;
}

.hud-slot .cd {
	position: absolute;
	inset: 0;
	border-radius: 50%;
	background: conic-gradient(rgba(0, 0, 0, 0.7) calc(var(--p, 0) * 1turn), transparent 0);
	pointer-events: none;
}

.hud-slot .count {
	position: absolute;
	right: 4px;
	bottom: 3px;
	font-size: 11px;
	text-shadow: 0 0 3px #000, 0 0 2px #000;
	pointer-events: none;
}

.hud-slot.unusable img {
	filter: grayscale(1) brightness(0.6);
}

#hud-combat > .hud-slot.pressed,
#hud-combat > .hud-key.pressed {
	border-color: var(--ko-gold-hi);
	filter: brightness(1.3);
}

#touch-controls.armed .hud-slot {
	border-color: var(--ko-gold-hi);
	box-shadow: 0 0 10px rgba(240, 208, 128, 0.8);
}

#hud-combat > .hud-slot.target {
	border-color: var(--ko-gold-hi);
	background: rgba(120, 90, 30, 0.85);
	box-shadow: 0 0 12px rgba(240, 208, 128, 0.9);
}

#hud-top {
	position: absolute;
	top: calc(var(--sa-t) + 4px);
	right: calc(var(--sa-r) + 4px);
	gap: 6px;
}

#hud-top button {
	height: 44px;
	min-width: 44px;
	border-radius: 10px;
	pointer-events: auto;
}

#hud-menu-btn,
#hud-skill-menu,
#hud-loot {
	position: relative;
}

#hud-loot.glow {
	color: #ffd27a;
	box-shadow: 0 0 12px rgba(240, 208, 128, 0.95);
}

#hud-loot-count {
	position: absolute;
	top: -4px;
	right: -4px;
	min-width: 16px;
	height: 16px;
	padding: 0 3px;
	border-radius: 8px;
	background: #c9a227;
	color: #1a1206;
	font: 700 11px/16px var(--ko-serif);
	text-align: center;
}

#hud-menu-btn {
	font-size: 20px !important;
}

#hud-close {
	padding: 0 14px !important;
}

#hud-chat {
	position: absolute;
	z-index: 3; /* above the quest tracker (2), which can sit over the chat button */
	left: calc(var(--sa-l) + 4px);
	top: calc(var(--sa-t) + 84px * var(--k));
	align-items: center;
	gap: 8px;
}

#hud-chat-btn {
	position: relative;
	width: 44px;
	height: 44px;
	border-radius: 50%;
	font-size: 18px !important;
	pointer-events: auto;
}

#hud-chat-badge {
	position: absolute;
	top: -4px;
	right: -4px;
	min-width: 18px;
	height: 18px;
	padding: 0 4px;
	border-radius: 9px;
	background: #b8321e;
	color: #fff;
	font-size: 11px;
	line-height: 18px;
}

#hud-chat-preview {
	max-width: calc(300px * var(--k));
	padding: 4px 8px;
	border-radius: 6px;
	background: rgba(0, 0, 0, 0.45);
	font-size: 12px;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	pointer-events: none;
}

#hud-chat-preview:empty,
#touch-controls.chat-open #hud-chat-preview {
	display: none;
}

/* Below the target bar. */
#hud-toast {
	position: absolute;
	top: calc(var(--sa-t) + 54px * var(--k));
	left: 50%;
	max-width: 60%;
	padding: 6px 12px;
	transform: translateX(-50%);
	border: 1px solid var(--ko-gold-lo);
	border-radius: 6px;
	background: var(--ko-panel);
	box-shadow: inset 0 0 0 2px rgba(200, 155, 60, 0.22), 0 4px 12px rgba(0, 0, 0, 0.6);
	font-size: 13px;
	text-align: center;
	pointer-events: none;
	z-index: 3;
}

/* Under the toast: "+1.234 EXP · +56 Noah". */
#hud-gain {
	position: absolute;
	top: calc(var(--sa-t) + 92px * var(--k));
	left: 50%;
	padding: 2px 10px;
	transform: translateX(-50%);
	border-radius: 10px;
	background: rgba(0, 0, 0, 0.45);
	color: var(--ko-gold-hi);
	font-size: 12px;
	white-space: nowrap;
	pointer-events: none;
	z-index: 3;
}

#hud-tip {
	max-width: calc(260px * var(--k));
	padding: 4px 8px;
	border: 1px solid var(--ko-gold-lo);
	border-radius: 6px;
	background: var(--ko-panel);
	font-size: 12px;
	pointer-events: none;
}

#touch-controls.chat-open #hud-tip {
	display: none;
}

/* The game's own state and target bars are off screen on touch (GameProcMain InitUI). */
#hud-bars,
#hud-targetbar {
	position: absolute;
	display: none;
	pointer-events: none;
	font-size: calc(12px * var(--k));
	text-shadow: 0 0 3px #000, 0 0 2px #000;
}

#touch-controls.in-world #hud-bars {
	display: grid;
}

#touch-controls.in-world #hud-targetbar {
	display: flex;
}

#hud-bars {
	top: calc(var(--sa-t) + 4px);
	left: calc(var(--sa-l) + 4px);
	width: calc(220px * var(--k));
	grid-template-columns: auto 1fr;
	column-gap: calc(6px * var(--k));
	row-gap: calc(3px * var(--k));
}

#hud-level {
	grid-row: 1 / 4;
	align-self: start;
	min-width: calc(34px * var(--k));
	height: calc(34px * var(--k));
	border: 2px solid rgba(200, 155, 60, 0.7);
	border-radius: 50%;
	background: rgba(20, 16, 10, 0.75);
	font-weight: 700;
	line-height: calc(30px * var(--k));
	text-align: center;
}

.hud-bar {
	position: relative;
	height: calc(16px * var(--k));
	overflow: hidden;
	border: 1px solid rgba(0, 0, 0, 0.8);
	border-radius: 4px;
	background: rgba(0, 0, 0, 0.55);
}

.hud-bar > i {
	position: absolute;
	inset: 0;
	transform-origin: 0 50%;
	transform: scaleX(var(--p, 0));
	transition: transform 80ms linear;
}

.hud-bar > span {
	position: relative;
	display: block;
	font-size: calc(11px * var(--k));
	font-weight: 600;
	line-height: calc(14px * var(--k));
	text-align: center;
	font-variant-numeric: tabular-nums;
}

.hud-bar.hp > i { background: linear-gradient(#e0483a, #8e1d14); }
.hud-bar.mp > i { background: linear-gradient(#4a86e8, #1c3f8e); }
.hud-bar.exp { height: calc(6px * var(--k)); border-radius: 3px; }
.hud-bar.exp > i { background: linear-gradient(#f0d080, #a07a28); }
#hud-bars .hud-bar.mp { height: calc(13px * var(--k)); }
#hud-bars .hud-bar.mp > span { line-height: calc(11px * var(--k)); font-size: calc(10px * var(--k)); }

/* Party list under the player's bars: name, level, thin HP and MP lines; a tap targets. */
#hud-party {
	position: absolute;
	top: calc(var(--sa-t) + 52px * var(--k));
	left: calc(var(--sa-l) + 4px);
	width: calc(150px * var(--k));
	display: none;
	flex-direction: column;
	gap: calc(4px * var(--k));
	pointer-events: auto;
	font-size: calc(11px * var(--k));
	text-shadow: 0 0 3px #000, 0 0 2px #000;
}

#touch-controls.in-world #hud-party:not([hidden]) {
	display: flex;
}

#hud-party-list {
	display: flex;
	flex-direction: column;
	gap: calc(3px * var(--k));
	margin: 0;
	padding: 0;
	list-style: none;
}

#hud-party-list > li {
	display: grid;
	gap: calc(2px * var(--k));
	padding: calc(3px * var(--k)) calc(5px * var(--k));
	border: 1px solid transparent;
	border-radius: 6px;
	background: rgba(12, 10, 8, 0.55);
}

#hud-party-list > li[hidden] { display: none; }
#hud-party-list > li.selected { border-color: rgba(200, 155, 60, 0.85); }
#hud-party-list > li.dead { opacity: 0.5; }

#hud-party-list .who {
	display: flex;
	align-items: baseline;
	gap: calc(5px * var(--k));
	min-width: 0;
}

#hud-party-marks {
	position: fixed;
	inset: 0;
	z-index: 5;
	pointer-events: none;
}

#hud-party-marks > svg {
	position: fixed;
	filter: drop-shadow(0 0 1px #000);
}

#hud-party-marks > svg[data-cls="warrior"] { fill: #e8a060; }
#hud-party-marks > svg[data-cls="rogue"] { fill: #8fd17a; }
#hud-party-marks > svg[data-cls="mage"] { fill: #ff8a5c; }
#hud-party-marks > svg[data-cls="priest"] { fill: #f2e48a; }

#hud-party-list .cls {
	flex: none;
	width: calc(12px * var(--k));
	height: calc(12px * var(--k));
	align-self: center;
	fill: rgba(255, 255, 255, 0.7);
}

#hud-party-list li[data-cls="warrior"] .cls { fill: #e8a060; }
#hud-party-list li[data-cls="rogue"] .cls { fill: #8fd17a; }
#hud-party-list li[data-cls="mage"] .cls { fill: #ff8a5c; }
#hud-party-list li[data-cls="priest"] .cls { fill: #f2e48a; }

#hud-party-list .who b {
	overflow: hidden;
	font-weight: 600;
	white-space: nowrap;
	text-overflow: ellipsis;
}

#hud-party-list li.leader .who b::before {
	content: "\2605 ";
	color: #e8c060;
}

#hud-party-list .who small {
	margin-left: auto;
	color: rgba(255, 255, 255, 0.6);
	font-variant-numeric: tabular-nums;
}

#hud-party-list .hud-bar {
	height: calc(4px * var(--k));
	border: 0;
	border-radius: 2px;
}

#hud-party-leave {
	align-self: flex-start;
	padding: calc(2px * var(--k)) calc(8px * var(--k));
	border: 1px solid rgba(255, 255, 255, 0.2);
	border-radius: 999px;
	background: rgba(12, 10, 8, 0.55);
	color: rgba(255, 255, 255, 0.75);
	font: inherit;
	font-size: calc(10px * var(--k));
}

#hud-targetbar {
	top: calc(var(--sa-t) + 4px);
	left: 50%;
	width: calc(240px * var(--k));
	transform: translateX(-50%);
	flex-direction: column;
	align-items: stretch;
	gap: 2px;
}

#hud-target-name {
	overflow: hidden;
	font-weight: 600;
	text-align: center;
	white-space: nowrap;
	text-overflow: ellipsis;
}

#hud-targetbar.enemy #hud-target-name { color: #ff7a6a; }
#hud-targetbar.friend #hud-target-name { color: #8ab4ff; }

/* Centre, under the target bar: away from the joystick (left) and the attack cluster (right). */
#hud-lootpanel {
	top: calc(var(--sa-t) + 52px * var(--k));
	left: 50%;
	width: min(calc(420px * var(--k)), calc(100% - 360px * var(--k)));
	min-width: 280px;
	max-height: calc(100% - var(--sa-t) - var(--sa-b) - 64px * var(--k));
	transform: translateX(-50%);
	display: flex;
	flex-direction: column;
	gap: 8px;
}

#hud-lootpanel header {
	display: flex;
	justify-content: space-between;
	padding-bottom: 4px;
	border-bottom: 1px solid var(--ko-gold-lo);
	color: var(--ko-gold-hi);
	font: 600 15px/1.3 var(--ko-serif);
	letter-spacing: 0.06em;
	text-shadow: 0 1px 0 #000;
}

#hud-loot-status {
	color: var(--muted);
	font-weight: 400;
	font-size: 12px;
}

#hud-loot-grid {
	display: grid;
	grid-template-columns: repeat(3, 1fr);
	gap: 6px;
	flex: 1 1 auto;
	min-height: 0;
	overflow-y: auto;
	touch-action: pan-y;
}

#hud-loot-grid button {
	position: relative;
	display: flex;
	align-items: center;
	gap: 6px;
	min-height: calc(58px * var(--k));
	padding: 4px 6px !important;
	border-color: #3a2e1c;
	border-radius: 4px;
	background: rgba(0, 0, 0, 0.45);
	box-shadow: inset 0 0 6px #000;
	text-align: left;
	font-size: 11px !important;
}

#hud-loot-grid img,
#hud-loot-grid .noicon {
	flex: none;
	width: calc(44px * var(--k));
	height: calc(44px * var(--k));
	border-radius: 6px;
	background: rgba(0, 0, 0, 0.4);
}

#hud-loot-grid .name {
	display: -webkit-box;
	overflow: hidden;
	-webkit-line-clamp: 3;
	-webkit-box-orient: vertical;
	word-break: break-word;
}

#hud-loot-grid .count {
	position: absolute;
	left: calc(6px * var(--k));
	bottom: 3px;
	min-width: calc(44px * var(--k));
	text-align: right;
	font-size: 11px;
	text-shadow: 0 0 3px #000, 0 0 2px #000;
}

#hud-loot-grid button.attr-1 { border-color: var(--ko-attr-1); }
#hud-loot-grid button.attr-2 { border-color: var(--ko-attr-2); }
#hud-loot-grid button.attr-3 { border-color: var(--ko-attr-3); }
#hud-loot-grid button.attr-4 { border-color: var(--ko-attr-4); }
#hud-loot-grid button.attr-5 { border-color: var(--ko-attr-5); }
#hud-loot-grid button.attr-1 .name { color: var(--ko-attr-1); }
#hud-loot-grid button.attr-2 .name { color: var(--ko-attr-2); }
#hud-loot-grid button.attr-3 .name { color: var(--ko-attr-3); }
#hud-loot-grid button.attr-4 .name { color: var(--ko-attr-4); }
#hud-loot-grid button.attr-5 .name { color: var(--ko-attr-5); }
#hud-loot-grid button.gold .name { color: var(--ko-gold-hi); }

#hud-loot-grid button.better {
	box-shadow: inset 0 0 0 2px #8fd18f;
}

#hud-loot-grid button.bad {
	box-shadow: inset 0 0 0 2px #c44;
}

#hud-loot-grid button.sent {
	opacity: 0.55;
}

#hud-loot-grid button.sent::after {
	content: "…";
	position: absolute;
	right: 6px;
	top: 2px;
	font-size: 14px;
}

#hud-loot-grid p {
	grid-column: 1 / -1;
	margin: 8px 0;
	color: var(--muted);
	font-size: 13px;
	text-align: center;
}

#hud-lootpanel footer {
	display: flex;
	justify-content: flex-end;
	gap: 8px;
}

.hud-panel {
	position: absolute;
	padding: 10px;
	pointer-events: auto;
	z-index: 2;
}

.hud-panel button {
	min-height: 44px;
	padding: 0 12px !important;
	border-radius: 4px;
	font-size: 14px !important;
}

#hud-menu {
	top: calc(var(--sa-t) + 54px);
	right: calc(var(--sa-r) + 4px);
	display: grid;
	grid-template-columns: repeat(2, minmax(118px, auto));
	gap: 6px;
}

#hud-confirm {
	top: 40%;
	left: 50%;
	min-width: 260px;
	transform: translate(-50%, -50%);
	text-align: center;
}

#hud-confirm p {
	margin: 4px 0 12px;
	font-size: 15px;
}

#hud-confirm div {
	display: flex;
	justify-content: center;
	gap: 12px;
}

#hud-exit {
	top: 50%;
	left: 50%;
	width: min(280px, calc(100% - 48px));
	transform: translate(-50%, -50%);
	display: flex;
	flex-direction: column;
	gap: 8px;
	text-align: center;
	z-index: 5;
}

#hud-exit p {
	margin: 0;
	font-size: 15px;
}

#hud-exit button {
	width: 100%;
}

/* Left of the slot arcs, so a picked skill can be dropped on a slot while the list stays open. */
#hud-picker {
	top: calc(var(--sa-t) + 4px);
	bottom: calc(var(--sa-b) + 4px);
	left: var(--sa-l);
	width: min(520px, calc(100% - 320px * var(--k) - var(--sa-l) - var(--sa-r)));
	border-top-left-radius: 0;
	border-bottom-left-radius: 0;
	display: flex;
	flex-direction: column;
	gap: 6px;
}

#hud-picker header {
	display: flex;
	gap: 6px;
}

#hud-picker-tabs {
	display: flex;
	flex: 1;
	gap: 6px;
	overflow-x: auto;
}

#hud-picker-tabs button {
	flex: none;
}

#hud-picker-tabs button.active,
#hud-stats nav button.active {
	color: #fff4d0;
	border-color: var(--ko-gold-hi);
	background: linear-gradient(#6a4e1e, #33250e);
}

#hud-level,
#hud-bars .hud-bar.hp {
	position: relative;
	pointer-events: auto;
}

#hud-stats {
	top: calc(var(--sa-t) + 4px);
	bottom: calc(var(--sa-b) + 4px);
	left: var(--sa-l);
	width: min(440px, calc(100% - 320px * var(--k) - var(--sa-l) - var(--sa-r)));
	border-top-left-radius: 0;
	border-bottom-left-radius: 0;
	display: flex;
	flex-direction: column;
	gap: 6px;
	overflow-y: auto;
}

#hud-stats > * {
	flex: none;
}

#hud-stats header,
#hud-stats footer {
	display: flex;
	align-items: center;
	gap: 6px;
}

#hud-stats header .ko-title {
	flex: 1;
	font-size: 15px;
}

#hud-stats footer {
	justify-content: flex-end;
}

#hud-stats-points {
	color: var(--ko-gold-hi);
	font-weight: 700;
}

.stat-row {
	display: grid;
	grid-template-columns: 1fr auto 44px 34px 44px;
	align-items: center;
	gap: 6px;
}

.stat-row b {
	display: block;
	color: var(--ko-gold-hi);
}

.stat-row small {
	display: block;
	font-size: 10px;
	line-height: 1.2;
	opacity: 0.75;
}

.stat-row .val {
	font-variant-numeric: tabular-nums;
	text-align: right;
}

.stat-row .val em {
	color: #8fd18f;
	font-size: 12px;
	font-style: normal;
}

.stat-row .pend {
	color: var(--ko-gold-hi);
	font-weight: 700;
	text-align: center;
}

.stat-row.sending .pend::after {
	content: "…";
}

#hud-stats nav {
	display: flex;
	gap: 6px;
	overflow-x: auto;
}

#hud-stats nav button {
	flex: none;
}

#hud-stats-status,
#hud-stats-derived {
	margin: 0;
	font-size: 12px;
}

#hud-stats-status {
	color: #ffd27a;
}

#hud-stats-status:empty {
	display: none;
}

#hud-stats-derived {
	opacity: 0.85;
}

#hud-stat-chip {
	position: absolute;
	top: calc(var(--sa-t) + 118px * var(--k));
	left: 50%;
	transform: translateX(-50%);
	pointer-events: auto;
	z-index: 3;
}

#hud-picker-hint {
	margin: 0;
	color: var(--muted);
	font-size: 12px;
}

#hud-picker-grid,
#hud-skill-grid {
	display: grid;
	flex: 1;
	min-height: 0;
	grid-template-columns: repeat(auto-fill, minmax(66px, 1fr));
	grid-auto-rows: 78px;
	gap: 6px;
	overflow-y: auto;
	touch-action: pan-y;
}

#hud-picker-grid button,
#hud-skill-grid button {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 2px;
	min-height: 0;
	padding: 2px !important;
	font-size: 10px !important;
	touch-action: pan-y;
}

#hud-picker-grid button.selected,
#hud-skill-grid button.selected {
	border-color: #f0d080;
	background: rgba(120, 90, 30, 0.85);
}

#hud-picker-grid img,
#hud-picker-grid .noicon,
#hud-skill-grid img,
#hud-skill-grid .noicon {
	width: 40px;
	height: 40px;
	border-radius: 6px;
}

#hud-skill-grid button.locked {
	opacity: 0.45;
}

#hud-skills {
	top: calc(var(--sa-t) + 4px);
	bottom: calc(var(--sa-b) + 4px);
	left: var(--sa-l);
	width: min(440px, calc(100% - 320px * var(--k) - var(--sa-l) - var(--sa-r)));
	border-top-left-radius: 0;
	border-bottom-left-radius: 0;
	display: flex;
	flex-direction: column;
	gap: 6px;
}

#hud-skills > * {
	flex: none;
}

#hud-skill-grid {
	flex: 1;
	min-height: 0;
	grid-auto-rows: 68px;
}

#hud-skill-grid img,
#hud-skill-grid .noicon {
	width: 32px;
	height: 32px;
}

#hud-skill-grid button span {
	max-width: 100%;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

#hud-skills header,
#hud-skills footer {
	display: flex;
	align-items: center;
	gap: 6px;
}

#hud-skills header .ko-title {
	flex: 1;
	font-size: 15px;
}

#hud-skill-points {
	color: var(--ko-gold-hi);
	font-size: 12px;
	font-weight: 700;
}

#hud-skill-hint {
	flex: 1;
	overflow: hidden;
	font-size: 12px;
	white-space: nowrap;
	text-overflow: ellipsis;
}

#hud-skill-tabs {
	overflow-x: auto;
}

#hud-inv {
	top: calc(var(--sa-t) + 4px);
	bottom: var(--sa-b);
	right: var(--sa-r);
	z-index: 4;
	width: min(540px, calc(100% - 260px * var(--k) - var(--sa-l) - var(--sa-r)));
	border-top-right-radius: 0;
	border-bottom-right-radius: 0;
	display: flex;
	flex-direction: column;
	gap: 6px;
}

#hud-inv > * {
	flex: none;
}

#hud-inv header,
#hud-inv footer {
	display: flex;
	align-items: center;
	gap: 6px;
}

#hud-inv header .ko-title {
	flex: 1;
	font-size: 15px;
}

#hud-inv-gold,
#hud-inv-weight {
	color: var(--ko-gold-hi);
	font-size: 12px;
	font-weight: 700;
}

#hud-inv-body {
	display: flex;
	flex: 1;
	gap: 8px;
	min-height: 0;
}

#hud-inv-equip,
#hud-inv-bag {
	display: grid;
	gap: 4px;
	align-content: start;
}

#hud-inv-equip {
	flex: none;
	width: 148px;
	grid-template-columns: repeat(3, 44px);
	border-right: 1px solid rgba(200, 155, 60, 0.45);
	padding-right: 6px;
}

#hud-inv-equip::before {
	content: attr(data-label);
	grid-column: 1 / -1;
	font-size: 10px;
	line-height: 14px;
	letter-spacing: 0.06em;
	color: var(--ko-gold-hi);
}

#touch-controls:has(#hud-inv:not([hidden])) #hud-combat,
#touch-controls:has(#hud-exit:not([hidden])) #hud-combat,
#touch-controls:has(#hud-confirm:not([hidden])) #hud-combat {
	visibility: hidden;
}

#hud-inv-bag {
	grid-template-columns: repeat(7, 44px);
	overflow-y: auto;
	touch-action: pan-y;
}

#hud-inv-equip button,
#hud-inv-bag button,
#hud-inv-equip .gap {
	position: relative;
	width: 44px;
	height: 44px;
	min-height: 44px;
	padding: 0 !important;
}

#hud-inv-equip img,
#hud-inv-bag img {
	width: 36px;
	height: 36px;
	border-radius: 4px;
}

#hud-inv-bag button.better i,
#hud-inv-equip button.better i {
	position: absolute;
	left: 0;
	right: 0;
	bottom: 0;
	font-size: 8px;
	font-style: normal;
	color: #b6f0b6;
	background: rgba(0, 0, 0, 0.55);
}

#hud-inv-bag button.bad,
#hud-inv-equip button.bad {
	box-shadow: inset 0 0 0 2px #c44;
}

#hud-inv-detail-text {
	flex: 1;
	overflow: hidden;
	font-size: 12px;
	white-space: nowrap;
	text-overflow: ellipsis;
}

/* Player stall (pazar): the own stall panel and the stall being browsed share the bag panel's place. */
#hud-merchant,
#hud-merchant-browse,
#hud-clan {
	top: calc(var(--sa-t) + 4px);
	bottom: var(--sa-b);
	right: var(--sa-r);
	z-index: 4;
	width: min(420px, calc(100% - 260px * var(--k) - var(--sa-l) - var(--sa-r)));
	border-top-right-radius: 0;
	border-bottom-right-radius: 0;
	display: flex;
	flex-direction: column;
	gap: 6px;
}

#hud-merchant[hidden],
#hud-merchant-browse[hidden],
#hud-clan[hidden] {
	display: none;
}

#hud-merchant header,
#hud-merchant-browse header,
#hud-clan header {
	display: flex;
	flex: none;
	align-items: center;
	gap: 6px;
}

#hud-merchant header .ko-title,
#hud-merchant-browse-title,
#hud-clan header .ko-title {
	flex: 1;
	overflow: hidden;
	font-size: 15px;
	white-space: nowrap;
	text-overflow: ellipsis;
}

#hud-merchant-browse-title {
	color: var(--ko-gold-hi);
	font-weight: 700;
}

#hud-merchant-body,
#hud-merchant-browse-grid,
#hud-clan-body {
	display: flex;
	flex: 1;
	flex-direction: column;
	gap: 6px;
	min-height: 0;
	overflow-y: auto;
	touch-action: pan-y;
}

#hud-merchant-status,
#hud-clan-status {
	flex: none;
	min-height: 14px;
	margin: 0;
	color: var(--ko-gold-hi);
	font-size: 12px;
}

#hud-merchant p,
#hud-merchant-browse p,
#hud-clan p {
	margin: 0;
	font-size: 12px;
}

#touch-controls:has(#hud-merchant:not([hidden])) #hud-combat,
#touch-controls:has(#hud-merchant-browse:not([hidden])) #hud-combat,
#touch-controls:has(#hud-clan:not([hidden])) #hud-combat {
	visibility: hidden;
}

.merchant-tabs,
.merchant-foot {
	display: flex;
	flex: none;
	gap: 6px;
}

.merchant-tabs button,
.merchant-foot button {
	flex: 1;
}

#hud-merchant .merchant-tabs button.active,
#hud-merchant .merchant-toggle.active {
	outline: 2px solid var(--ko-gold-hi);
	outline-offset: -2px;
}

.merchant-wide {
	width: 100%;
}

.merchant-head {
	color: var(--ko-gold-hi);
	font-weight: 700;
}

.merchant-slotlist,
.merchant-add {
	display: flex;
	flex: none;
	flex-direction: column;
	gap: 4px;
}

.merchant-row {
	display: flex;
	flex: none;
	align-items: center;
	gap: 6px;
	padding: 3px;
	border: 1px solid rgba(200, 155, 60, 0.45);
	border-radius: 4px;
}

/* Item icons sit in the game's slot frame and fill it (45 px icons in a 46 px cell). */
.merchant-icon {
	flex: none;
	box-sizing: border-box;
	width: 46px;
	height: 46px;
	padding: 1px;
	border: 1px solid var(--ui-line);
	border-radius: var(--ui-radius);
	background: var(--ui-body);
	object-fit: contain;
	image-rendering: auto;
}

.merchant-info {
	display: flex;
	flex: 1;
	flex-direction: column;
	min-width: 0;
}

.merchant-name,
.merchant-price,
.merchant-own {
	overflow: hidden;
	font-size: 12px;
	white-space: nowrap;
	text-overflow: ellipsis;
}

.merchant-price {
	color: var(--ko-gold-hi);
}

.merchant-own {
	flex: none;
	max-width: 80px;
	color: #e08a8a;
	font-size: 10px;
}

.merchant-baggrid {
	display: grid;
	grid-template-columns: repeat(auto-fill, 48px);
	gap: 4px;
}

#touch-controls .merchant-baggrid button,
.merchant-baggrid button {
	position: relative;
	display: grid;
	place-items: center;
	box-sizing: border-box;
	width: 48px;
	height: 48px;
	min-width: 0;
	min-height: 48px;
	padding: 0 !important;
	border: 1px solid var(--ui-line);
	border-radius: var(--ui-radius);
	background: var(--ui-body);
	box-shadow: none;
}

.merchant-baggrid img {
	width: 46px;
	height: 46px;
	object-fit: contain;
}

#hud-merchant .merchant-baggrid button.selected {
	outline: 2px solid var(--ko-gold-hi);
	outline-offset: -2px;
}

.merchant-baggrid i {
	position: absolute;
	right: 2px;
	bottom: 0;
	font-size: 9px;
	font-style: normal;
	text-shadow: 0 0 2px #000, 0 0 2px #000;
}

.merchant-field {
	display: flex;
	align-items: center;
	gap: 8px;
	font-size: 12px;
}

.merchant-field span {
	flex: 1;
}

.merchant-num,
.merchant-title {
	box-sizing: border-box;
	height: 40px;
	padding: 0 8px;
	border: 1px solid rgba(200, 155, 60, 0.6);
	border-radius: 4px;
	color: #f2e6c8;
	background: rgba(0, 0, 0, 0.55);
	/* 16px keeps iOS Safari from zooming the page when the field takes focus. */
	font-size: 16px;
	pointer-events: auto;
	-webkit-user-select: text;
	user-select: text;
}

.merchant-num {
	flex: none;
	width: 112px;
	text-align: right;
}

.merchant-row .merchant-num {
	width: 64px;
}

.merchant-title {
	flex: 2;
	min-width: 0;
}

/* Price box: the number with separators, then quick steps and the NPC price as chips. */
.merchant-pricebox {
	display: flex;
	flex-direction: column;
	gap: 4px;
	min-width: 0;
}

.merchant-chips {
	display: flex;
	flex-wrap: wrap;
	gap: 4px;
}

#touch-controls .merchant-chips .game-btn.merchant-chip,
.merchant-chips .game-btn.merchant-chip {
	min-height: 28px;
	padding: 0 4px !important;
	border-width: 4px;
	font-size: 12px !important;
}

.merchant-hits {
	display: flex;
	flex-direction: column;
	gap: 2px;
	max-height: 180px;
	overflow-y: auto;
}

#touch-controls .merchant-hit,
.merchant-hit {
	display: flex;
	align-items: center;
	gap: 6px;
	padding: 2px 6px;
	border: 1px solid transparent;
	border-radius: 4px;
	background: rgba(0, 0, 0, 0.35);
	color: #f2e6c8;
	text-align: left;
}

.merchant-hit.selected { border-color: var(--ko-gold-hi); }
.merchant-hit .merchant-icon { width: 28px; height: 28px; }

.merchant-edit {
	margin: -2px 0 4px;
}

#hud-merchant-target,
#hud-merchant-banner {
	position: absolute;
	left: 50%;
	transform: translateX(-50%);
	pointer-events: auto;
	z-index: 3;
}

#hud-merchant-target {
	bottom: calc(var(--sa-b) + 136px * var(--k));
	min-height: 44px;
	padding: 0 16px;
	color: var(--ko-gold-hi);
	font-size: 14px;
	font-weight: 700;
}

#hud-merchant-banner {
	top: calc(var(--sa-t) + 58px);
	display: flex;
	align-items: center;
	gap: 8px;
	max-width: min(420px, 80%);
	padding: 6px 8px;
	font-size: 12px;
}

#hud-merchant-banner[hidden] {
	display: none;
}

#hud-merchant-banner button {
	min-height: 36px;
	padding: 0 10px;
}

#hud-gear {
	position: absolute;
	left: 50%;
	bottom: calc(var(--sa-b) + 78px * var(--k));
	transform: translateX(-50%);
	display: flex;
	align-items: center;
	gap: 8px;
	max-width: min(420px, 70%);
	padding: 6px 8px;
	pointer-events: auto;
	z-index: 3;
}

#hud-gear img {
	width: 40px;
	height: 40px;
	border-radius: 6px;
}

#hud-gear button {
	min-width: 44px;
	min-height: 44px;
}

#hud-gear-text {
	display: flex;
	flex-direction: column;
	min-width: 0;
	font-size: 12px;
}

#hud-gear-text b {
	overflow: hidden;
	white-space: nowrap;
	text-overflow: ellipsis;
	color: var(--ko-gold-hi);
}

#hud-picker-grid span,
#hud-skill-grid span {
	max-width: 100%;
	overflow: hidden;
	white-space: nowrap;
	text-overflow: ellipsis;
}

#hud-picker-grid p,
#hud-skill-grid p {
	grid-column: 1 / -1;
	margin: 12px 0;
	color: var(--muted);
	font-size: 13px;
	text-align: center;
}

#hud-debug-keys {
	position: absolute;
	left: 50%;
	bottom: calc(var(--sa-b) + 2px);
	padding: 2px 8px;
	transform: translateX(-50%);
	border-radius: 4px;
	background: rgba(0, 0, 0, 0.7);
	color: #9fe0a0;
	font: 11px/1.3 ui-monospace, Consolas, monospace;
	white-space: nowrap;
	pointer-events: none;
	z-index: 5;
}

#hud-slot-actions {
	display: flex;
	justify-content: flex-end;
	gap: 8px;
}

/* A game message box is up: only chat stays live, taps reach the box on the canvas. */
#touch-controls.blocked #hud-combat,
#touch-controls.blocked #hud-top,
#touch-controls.blocked #move-pad {
	opacity: 0.35;
}

#touch-controls.blocked #hud-lootpanel {
	display: none;
}

/* The pad's wide area reaches under the message box buttons, so it lets touches through. The
   buttons stay hit-testable: a touch falling through them would walk the character. */
#touch-controls.blocked #move-pad,
#touch-controls.blocked #joystick {
	pointer-events: none;
}

/* A game window (bag, skills, shop) uses the right side: the attack cluster steps aside. */
#touch-controls.window-open #hud-combat {
	opacity: 0;
}

#touch-controls.window-open #hud-combat > button {
	pointer-events: none;
}

#stage.fit #canvas {
	width: 100vw;
	height: 100vh;
	height: 100dvh;
	object-fit: contain;
}

/* Phones: the bitmap matches the landscape screen, and the element covers it edge to edge.
   object-fit:fill absorbs a pixel of rounding instead of centering a 16:9 picture. */
body.touch-ui.landscape #canvas {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	max-width: none;
	max-height: none;
	object-fit: fill;
}

#install-hint {
	position: fixed;
	top: calc(6px + env(safe-area-inset-top));
	left: 50%;
	z-index: 30;
	display: flex;
	align-items: center;
	gap: 10px;
	max-width: calc(100vw - 24px);
	padding: 6px 6px 6px 12px;
	transform: translateX(-50%);
	border: 1px solid var(--accent);
	border-radius: 6px;
	background: rgba(12, 10, 8, 0.88);
	color: var(--fg);
	font-size: 13px;
	white-space: nowrap;
}

#install-hint[hidden] {
	display: none;
}

#install-hint button {
	min-width: 44px;
	min-height: 44px;
	padding: 0;
	border: 0;
	background: none;
	color: var(--accent);
	font-size: 16px;
}

#update-hint {
	position: fixed;
	top: calc(6px + env(safe-area-inset-top));
	left: 50%;
	z-index: 30;
	display: flex;
	align-items: center;
	gap: 8px;
	max-width: calc(100vw - 24px);
	padding: 4px 4px 4px 12px;
	transform: translateX(-50%);
	border: 1px solid var(--accent);
	border-radius: 6px;
	background: rgba(12, 10, 8, 0.9);
	color: var(--fg);
	font-size: 13px;
	white-space: nowrap;
}

#update-hint[hidden] {
	display: none;
}

#update-reload {
	min-height: 32px;
	padding: 0 12px;
	font-size: 13px;
}

#update-close {
	min-width: 36px;
	min-height: 36px;
	padding: 0;
	border: 0;
	background: none;
	color: var(--accent);
	font-size: 15px;
}

#rotate-hint {
	position: fixed;
	inset: 0;
	z-index: 40;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 16px;
	padding: 24px;
	background: #050403;
	color: var(--fg);
	text-align: center;
	touch-action: none;
}

#rotate-hint[hidden] {
	display: none;
}

#rotate-hint p {
	margin: 0;
	font-size: 22px;
	letter-spacing: 0.04em;
	color: var(--accent);
}

#rotate-hint span {
	max-width: 22em;
	color: var(--muted);
	font-size: 14px;
	line-height: 1.45;
}

#rotate-hint .phone {
	width: 42px;
	height: 72px;
	border: 3px solid var(--accent);
	border-radius: 8px;
	animation: rotate-phone 1.6s ease-in-out infinite;
}

@keyframes rotate-phone {
	0%, 30% { transform: rotate(0deg); }
	50%, 100% { transform: rotate(90deg); }
}

body.portrait #stage,
body.portrait #toolbar {
	visibility: hidden;
	pointer-events: none;
}

/* Upright phone: the landscape stage is turned 90° clockwise to fill the screen sideways. */
body.touch-ui.rotated #stage {
	inset: auto;
	top: 0;
	left: 0;
	width: var(--view-h, 100vh);
	height: var(--view-w, 100vw);
	transform-origin: 0 0;
	transform: translateX(var(--view-w, 100vw)) rotate(90deg);
}

body.touch-ui.rotated #touch-controls {
	--sa-t: env(safe-area-inset-right, 0px);
	--sa-r: env(safe-area-inset-bottom, 0px);
	--sa-b: env(safe-area-inset-left, 0px);
	--sa-l: env(safe-area-inset-top, 0px);
	padding: env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left) env(safe-area-inset-top);
}

/* Phones set themselves up (fit resolution, low memory, frame cap) and go fullscreen on the first
   touch; the desktop toolbar only covers the game there. */
body.touch-ui #toolbar {
	display: none;
}

#dialog {
	position: absolute;
	min-width: min(420px, 90vw);
	padding: 28px 32px;
	background: var(--panel);
	border: 1px solid #3a3020;
	border-radius: 6px;
	box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
	text-align: center;
}

/* Loading screens (page boot, map load): the brand logo, a status line and the gold bar, in the
   game's message box frame. Logo: web/shell/brand/logo.svg (swap the file, bump ?v=). */
#loader,
#zone-loading {
	position: absolute;
	border: 3px solid transparent;
	border-image: url("/ui/frame.png?v=1") 3 stretch;
	background: var(--ko-panel);
	background-clip: padding-box;
	box-shadow: 0 12px 40px rgba(0, 0, 0, 0.7);
	color: var(--ui-text);
	text-align: center;
	font-variant-numeric: tabular-nums;
}

#loader {
	width: min(440px, 90vw);
	padding: 22px 30px 16px;
}

.brand-logo {
	display: block;
	margin: 0 auto;
	line-height: 0;
}

.brand-logo img,
img.brand-logo {
	display: block;
	max-width: 100%;
	height: auto;
	margin: 0 auto;
}

#loader .brand-logo {
	width: min(300px, 70vw);
	margin-bottom: 12px;
}

#loader-status {
	margin: 0;
	font: var(--ui-fs-l) var(--ui-font);
	color: var(--ui-gold-hi);
}

#loader-detail {
	min-height: 1.2em;
	margin: 0;
	font-size: var(--ui-fs-s);
	color: var(--ui-text-dim);
}

.bar {
	height: 8px;
	margin: 12px 0 10px;
	background: #120d07;
	border: 1px solid var(--ui-line);
	box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.8);
	overflow: hidden;
}

#loader-bar,
#zone-loading-bar {
	width: 0;
	height: 100%;
	background: linear-gradient(180deg, var(--ui-gold-hi), var(--ui-gold) 55%, #8a6a28);
}

#loader.error #loader-bar {
	background: var(--ui-danger-hi);
}

#loader.error #loader-status {
	color: var(--ui-danger-hi);
}

#dialog button,
#settings-form button {
	margin-top: 10px;
	padding: 6px 18px;
	color: var(--fg);
	background: #2a2216;
	border: 1px solid #5a4a2a;
	border-radius: 3px;
	cursor: pointer;
}

#dialog button:hover,
#settings-form button:hover {
	background: #3a2e1a;
}

#netstat {
	position: absolute;
	top: 8px;
	left: 8px;
	padding: 6px 10px;
	font: 12px/1.45 ui-monospace, Consolas, monospace;
	white-space: pre;
	background: rgba(0, 0, 0, 0.65);
	border-radius: 4px;
	pointer-events: none;
}

#zone-loading {
	bottom: 14%;
	width: min(360px, 82vw);
	padding: 12px 20px 4px;
	font-size: var(--ui-fs-m);
	pointer-events: none;
}

#zone-loading .brand-logo {
	width: 150px;
	margin-bottom: 8px;
}

#gfx-lost {
	position: absolute;
	bottom: 18%;
	min-width: min(320px, 80vw);
	padding: 10px 18px 4px;
	font-size: 13px;
	text-align: center;
	background: var(--panel);
	border: 1px solid #3a3020;
	border-radius: 4px;
	pointer-events: none;
	font-variant-numeric: tabular-nums;
}

#gfx-lost {
	bottom: auto;
	padding-bottom: 10px;
}

#settings-form select {
	padding: 4px 6px;
	color: var(--fg);
	background: #120f0a;
	border: 1px solid #3a3020;
	border-radius: 3px;
}

#toolbar[hidden] {
	display: none;
}

#toolbar {
	position: fixed;
	right: 8px;
	bottom: 8px;
	display: flex;
	gap: 6px;
	align-items: flex-end;
	opacity: 0.25;
	transition: opacity 150ms;
	z-index: 5;
}

#toolbar:hover,
#toolbar:focus-within {
	opacity: 1;
}

#toolbar > button,
#settings > summary {
	padding: 4px 9px;
	font-size: 13px;
	color: var(--fg);
	background: var(--panel);
	border: 1px solid #3a3020;
	border-radius: 3px;
	cursor: pointer;
	list-style: none;
}

#settings[open] > summary {
	border-color: var(--accent);
}

#settings-form {
	position: absolute;
	right: 0;
	bottom: 34px;
	display: grid;
	gap: 8px;
	width: 300px;
	padding: 14px;
	background: var(--panel);
	border: 1px solid #3a3020;
	border-radius: 4px;
	font-size: 12px;
}

#settings-form label {
	display: grid;
	gap: 3px;
	color: var(--muted);
}

#settings-form input {
	padding: 5px 7px;
	color: var(--fg);
	background: #120f0a;
	border: 1px solid #3a3020;
	border-radius: 3px;
}

/* Registration (register.js): a button on the login screen and a form over the game. */
#register-open {
	position: fixed;
	right: calc(env(safe-area-inset-right) + 10px);
	bottom: calc(env(safe-area-inset-bottom) + 52px);
	z-index: 6;
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 9px 18px 9px 12px;
	border-radius: 4px;
	font: 600 15px/1.2 var(--ko-serif);
	letter-spacing: 0.08em;
	text-shadow: 0 1px 0 #000;
	cursor: pointer;
	animation: ko-glow 2.8s ease-in-out infinite;
	transition: transform 120ms, filter 120ms;
}

#register-open:hover {
	filter: brightness(1.15);
	transform: translateY(-1px);
}

#register-open:active {
	transform: translateY(1px);
}

@keyframes ko-glow {
	0%, 100% { box-shadow: inset 0 1px 0 rgba(255, 240, 200, 0.35), 0 2px 6px #000, 0 0 0 rgba(240, 208, 128, 0); }
	50% { box-shadow: inset 0 1px 0 rgba(255, 240, 200, 0.35), 0 2px 6px #000, 0 0 16px rgba(240, 208, 128, 0.45); }
}

.crest-mini {
	width: 18px;
	height: 21px;
	flex: none;
}

.crest-mini path {
	fill: rgba(20, 14, 6, 0.55);
	stroke: var(--ko-gold-hi);
	stroke-width: 1.6;
	stroke-linejoin: round;
}

.crest-mini .crest-sword {
	fill: none;
	stroke-linecap: round;
}

#register-open[hidden],
#register[hidden],
#register-fields[hidden],
#register-success[hidden],
#register-form .field-caps[hidden] {
	display: none;
}

#register {
	position: fixed;
	inset: 0;
	z-index: 30;
	display: grid;
	place-items: center;
	padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
	background: radial-gradient(ellipse at center, rgba(20, 12, 4, 0.55), rgba(0, 0, 0, 0.82) 70%);
	-webkit-backdrop-filter: blur(2px);
	backdrop-filter: blur(2px);
	animation: register-fade 160ms ease-out;
}

@keyframes register-fade {
	from { opacity: 0; }
}

@keyframes register-pop {
	from { opacity: 0; transform: translateY(10px) scale(0.97); }
}

#register-form {
	position: relative;
	width: min(440px, calc(100vw - 16px));
	max-height: calc(100dvh - 16px);
	padding: 0 18px 16px;
	overflow-y: auto;
	overscroll-behavior: contain;
	touch-action: pan-y;
	-webkit-overflow-scrolling: touch;
	animation: register-pop 200ms ease-out;
	/* A second gold line inside the frame, like the game's own windows. */
	outline: 1px solid rgba(200, 155, 60, 0.18);
	outline-offset: -6px;
}

.register-head {
	position: relative;
	display: grid;
	justify-items: center;
	gap: 2px;
	margin: 0 -18px 12px;
	padding: 14px 44px 12px;
	border-bottom: 1px solid var(--ko-gold-lo);
	background:
		linear-gradient(90deg, transparent, rgba(200, 155, 60, 0.18), transparent),
		linear-gradient(180deg, rgba(60, 44, 24, 0.6), transparent);
}

.register-head::after {
	/* Gold rule with a diamond in the middle under the header. */
	content: "";
	position: absolute;
	left: 50%;
	bottom: -5px;
	width: 9px;
	height: 9px;
	background: linear-gradient(135deg, var(--ko-gold-hi), var(--ko-gold-lo));
	border: 1px solid #000;
	transform: translateX(-50%) rotate(45deg);
}

.register-crest {
	width: 44px;
	height: 44px;
	margin-bottom: 2px;
	filter: drop-shadow(0 2px 3px #000) drop-shadow(0 0 8px rgba(240, 208, 128, 0.25));
}

.crest-shield {
	fill: #3a2810;
	stroke: var(--ko-gold-hi);
	stroke-width: 2;
}

.crest-inner {
	fill: #1a120a;
	stroke: var(--ko-gold-lo);
	stroke-width: 1.2;
}

.register-crest .crest-sword {
	fill: none;
	stroke: #e8dcc0;
	stroke-width: 2.2;
	stroke-linecap: round;
}

.register-crest .crest-guard {
	fill: none;
	stroke: var(--ko-gold-hi);
	stroke-width: 2.6;
	stroke-linecap: round;
}

.register-crest .crest-pommel {
	fill: var(--ko-gold);
}

.register-title {
	margin: 0;
	color: var(--ko-gold-hi);
	font: 600 19px/1.25 var(--ko-serif);
	letter-spacing: 0.1em;
	text-align: center;
	text-shadow: 0 1px 0 #000, 0 0 10px rgba(240, 208, 128, 0.35);
}

.register-sub {
	margin: 0;
	color: var(--muted);
	font: italic 13px/1.3 var(--ko-serif);
	text-align: center;
}

.register-x {
	position: absolute;
	top: 10px;
	right: 10px;
	width: 30px;
	height: 30px;
	padding: 0;
	border: 1px solid var(--ko-gold-lo);
	border-radius: 50%;
	background: radial-gradient(circle at 50% 35%, #3a2c1a, #120d07);
	cursor: pointer;
}

.register-x::before,
.register-x::after {
	content: "";
	position: absolute;
	left: 50%;
	top: 50%;
	width: 13px;
	height: 2px;
	border-radius: 1px;
	background: var(--ko-gold);
	transform: translate(-50%, -50%) rotate(45deg);
}

.register-x::after {
	transform: translate(-50%, -50%) rotate(-45deg);
}

.register-x:hover {
	border-color: var(--ko-gold-hi);
}

#register-fields {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 10px 12px;
}

#register-fields .field.wide,
#register-status,
.register-actions {
	grid-column: 1 / -1;
}

.field {
	display: grid;
	align-content: start;
	gap: 4px;
	min-width: 0;
}

.field-name {
	color: #c8b48a;
	font: 600 12px/1.2 var(--ko-serif);
	letter-spacing: 0.06em;
	text-transform: uppercase;
}

.field-box {
	position: relative;
	display: block;
}

#register-form input {
	width: 100%;
	height: 40px;
	padding: 0 34px 0 10px;
	color: var(--fg);
	background: linear-gradient(180deg, #0c0906, #18120b);
	border: 1px solid #3f3220;
	border-radius: 3px;
	box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.8);
	/* iOS zooms into inputs smaller than 16px. */
	font-size: 16px;
	-webkit-user-select: text;
	user-select: text;
	touch-action: manipulation;
	transition: border-color 120ms, box-shadow 120ms;
}

#register-form .field-box:has(.field-eye) input {
	padding-right: 64px;
}

#register-form input.pin {
	font-family: ui-monospace, Consolas, monospace;
	letter-spacing: 0.45em;
}

#register-form input:focus {
	outline: none;
	border-color: var(--ko-gold);
	box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.8), 0 0 0 2px rgba(200, 155, 60, 0.22), 0 0 10px rgba(240, 208, 128, 0.15);
}

.field[data-state="ok"] input {
	border-color: rgba(111, 210, 122, 0.55);
}

.field[data-state="bad"] input,
#register-form input.invalid {
	border-color: var(--ko-red);
	box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.8), 0 0 0 2px rgba(184, 50, 30, 0.25);
}

.field-mark {
	position: absolute;
	right: 10px;
	top: 50%;
	width: 16px;
	height: 16px;
	margin-top: -8px;
	border-radius: 50%;
	pointer-events: none;
	opacity: 0;
	transform: scale(0.6);
	transition: opacity 150ms, transform 150ms;
}

.field[data-state="ok"] .field-mark {
	opacity: 1;
	transform: none;
	background: var(--ko-green);
	box-shadow: 0 0 6px rgba(111, 210, 122, 0.5);
}

.field[data-state="ok"] .field-mark::after {
	/* A tick drawn with two borders. */
	content: "";
	position: absolute;
	left: 5px;
	top: 2px;
	width: 4px;
	height: 8px;
	border: solid #0d1a0e;
	border-width: 0 2px 2px 0;
	transform: rotate(45deg);
}

.field[data-state="bad"] .field-mark {
	opacity: 1;
	transform: none;
	background: var(--ko-red);
}

.field[data-state="bad"] .field-mark::after {
	content: "!";
	position: absolute;
	inset: 0;
	color: #fff;
	font: 700 12px/16px var(--ko-serif);
	text-align: center;
}

.field-eye {
	position: absolute;
	right: 32px;
	top: 50%;
	width: 28px;
	height: 28px;
	margin-top: -14px;
	padding: 0;
	border: 0;
	background: none;
	cursor: pointer;
	opacity: 0.65;
}

.field-eye:hover,
.field-eye[aria-pressed="true"] {
	opacity: 1;
}

.field-eye::before {
	/* An eye: almond outline with a pupil. */
	content: "";
	position: absolute;
	left: 50%;
	top: 50%;
	width: 16px;
	height: 10px;
	border: 2px solid var(--ko-gold);
	border-radius: 75% 15%;
	transform: translate(-50%, -50%) rotate(45deg);
}

.field-eye::after {
	content: "";
	position: absolute;
	left: 50%;
	top: 50%;
	width: 5px;
	height: 5px;
	border-radius: 50%;
	background: var(--ko-gold);
	transform: translate(-50%, -50%);
}

.field-eye[aria-pressed="true"]::after {
	width: 20px;
	height: 2px;
	border-radius: 1px;
	background: var(--ko-gold-hi);
	transform: translate(-50%, -50%) rotate(-35deg);
}

.field-hint,
.field-caps {
	color: #7d7462;
	font-size: 11px;
	line-height: 1.3;
}

.field-caps {
	color: #e8b860;
}

.field[data-state="bad"] .field-hint {
	color: #e89a88;
}

.field[data-state="ok"] .field-hint {
	color: #8fbf8f;
}

#register-form .register-trap {
	position: absolute;
	left: -10000px;
	width: 1px;
	height: 1px;
	overflow: hidden;
}

#register-status {
	min-height: 1.3em;
	margin: 0;
	padding: 0 2px;
	color: #f0a090;
	font-size: 13px;
	text-align: center;
}

#register-status:not(:empty) {
	padding: 7px 10px;
	border: 1px solid rgba(184, 50, 30, 0.5);
	border-radius: 3px;
	background: rgba(90, 20, 10, 0.35);
}

#register-status.ok:not(:empty) {
	color: #e8dcc0;
	border-color: var(--ko-gold-lo);
	background: rgba(60, 44, 20, 0.35);
}

.register-actions {
	display: flex;
	gap: 10px;
	justify-content: flex-end;
	padding-top: 4px;
}

.register-actions button,
#register-to-login {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	min-width: 110px;
	height: 40px;
	padding: 0 18px;
	border-radius: 4px;
	font: 600 14px/1 var(--ko-serif);
	letter-spacing: 0.05em;
	cursor: pointer;
	transition: filter 120ms, transform 120ms;
}

.register-actions button:hover:not(:disabled),
#register-to-login:hover {
	filter: brightness(1.15);
}

.register-actions button:active:not(:disabled),
#register-to-login:active {
	transform: translateY(1px);
}

#register-submit {
	flex: 1 1 auto;
	max-width: 220px;
}

.spinner {
	display: none;
	width: 15px;
	height: 15px;
	border: 2px solid rgba(255, 240, 200, 0.3);
	border-top-color: #fff4d0;
	border-radius: 50%;
	animation: register-spin 700ms linear infinite;
}

#register-form.busy .spinner {
	display: inline-block;
}

#register-form.busy #register-submit {
	opacity: 0.85;
}

@keyframes register-spin {
	to { transform: rotate(360deg); }
}

#register-success {
	display: grid;
	justify-items: center;
	gap: 8px;
	padding: 6px 4px 4px;
	text-align: center;
	animation: register-pop 220ms ease-out;
}

#register-success h3 {
	margin: 0;
	color: var(--ko-gold-hi);
	font: 600 18px/1.3 var(--ko-serif);
	letter-spacing: 0.08em;
	text-shadow: 0 1px 0 #000, 0 0 10px rgba(240, 208, 128, 0.35);
}

#register-success p {
	margin: 0 0 6px;
	color: var(--fg);
	font-size: 14px;
	line-height: 1.45;
}

.register-seal {
	width: 64px;
	height: 64px;
	filter: drop-shadow(0 0 10px rgba(240, 208, 128, 0.35));
}

.seal-ring {
	fill: none;
	stroke: var(--ko-gold);
	stroke-width: 2;
	stroke-dasharray: 4 3;
}

.seal-core {
	fill: #2a1e0c;
	stroke: var(--ko-gold-hi);
	stroke-width: 2;
}

.seal-check {
	fill: none;
	stroke: var(--ko-green);
	stroke-width: 4;
	stroke-linecap: round;
	stroke-linejoin: round;
	stroke-dasharray: 40;
	stroke-dashoffset: 40;
	animation: seal-draw 420ms 120ms ease-out forwards;
}

@keyframes seal-draw {
	to { stroke-dashoffset: 0; }
}

@media (prefers-reduced-motion: reduce) {
	#register-open,
	#register,
	#register-form,
	#register-success,
	.seal-check {
		animation: none;
	}

	.seal-check {
		stroke-dashoffset: 0;
	}
}

/* Narrow screens: one column. */
@media (max-width: 420px) {
	#register-fields {
		grid-template-columns: 1fr;
	}
}

/* Landscape phones: a short header and no hints so the form fits above the keyboard. */
@media (max-height: 520px) and (min-width: 560px) {
	#register-form {
		width: min(640px, calc(100vw - 16px));
		padding-bottom: 12px;
	}

	.register-head {
		grid-template-columns: auto auto;
		justify-content: center;
		align-items: center;
		column-gap: 10px;
		margin-bottom: 10px;
		padding: 8px 44px;
	}

	.register-crest {
		width: 28px;
		height: 28px;
		margin: 0;
	}

	.register-sub,
	.field-hint {
		display: none;
	}

	.register-x {
		top: 6px;
	}

	#register-fields {
		gap: 8px 12px;
	}

	/* Email and username share the first row: three full rows, no gap next to the last field. */
	#register-fields .field.wide {
		grid-column: auto;
	}

	#register-form input {
		height: 36px;
	}

	#register-status {
		min-height: 0;
	}
}

/* Phones: the page's own login form beside the game's small login row; compact, so the
   game stays in view. */
#quick-login {
	position: fixed;
	z-index: 20;
	left: calc(env(safe-area-inset-left, 0px) + 10px);
	top: 50%;
	width: min(220px, 34vw);
	max-height: calc(100dvh - 12px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
	display: grid;
	gap: 6px;
	padding: 6px 10px 9px;
	overflow-y: auto;
	overscroll-behavior: contain;
	transform: translateY(-50%);
	outline: 1px solid rgba(200, 155, 60, 0.18);
	outline-offset: -5px;
	animation: register-fade 160ms ease-out;
}

#quick-login[hidden] {
	display: none;
}

.quick-login-title {
	margin: 0;
	text-align: center;
	font: 600 13px var(--ko-serif);
	color: var(--ko-gold-hi);
	letter-spacing: 0.04em;
}

#quick-login input:not([type="checkbox"]) {
	width: 100%;
	height: 32px;
	padding: 0 8px;
	color: var(--fg);
	background: linear-gradient(180deg, #0c0906, #18120b);
	border: 1px solid #3f3220;
	border-radius: 3px;
	box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.8);
	/* iOS zooms into inputs smaller than 16px. */
	font-size: 16px;
	-webkit-user-select: text;
	user-select: text;
	touch-action: manipulation;
}

#quick-login input::placeholder {
	color: var(--muted);
	font-size: 14px;
}

#quick-login .field-box:has(.field-eye) input {
	padding-right: 34px;
}

#quick-login .field-eye {
	right: 3px;
}

#quick-login input:focus {
	outline: none;
	border-color: var(--ko-gold);
	box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.8), 0 0 0 2px rgba(200, 155, 60, 0.22);
}


.quick-login-remember {
	display: flex;
	align-items: center;
	gap: 5px;
	min-height: 30px;
	font-size: 12px;
	color: var(--fg);
	white-space: nowrap;
}

#quick-login .game-btn {
	width: 100%;
}

#quick-login-status {
	margin: 0;
	font-size: 11px;
	color: var(--ko-gold-hi);
}

#quick-login-status:empty {
	display: none;
}



/* ==== Shared look: the game's own UI pieces ==================================================
   web/shell/ui/*.png are cut out of the client's UIFs with tools/uie/scripts/web-ui-assets.txt.
   The stylesheet is served from a release folder, the images from the site: absolute URLs, and
   ?v=N raised whenever a picture changes (the CDN keeps old ones). */

/* Text buttons: the login panel's button face, gold; turquoise under the pointer and pressed,
   as in the game. Irreversible actions keep the face and get a red caption. */
.game-btn,
#touch-controls .game-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 6px;
	box-sizing: border-box;
	min-width: 0;
	min-height: 40px;
	margin: 0;
	padding: 0 8px !important;
	border: 6px solid transparent;
	border-radius: 0;
	border-image: url("/ui/btn-normal.png?v=2") 6 fill stretch;
	background: none;
	box-shadow: none;
	color: var(--ui-ink);
	font: var(--ui-font-btn);
	font-size: var(--ui-fs-l) !important;
	text-shadow: 0 1px 0 rgba(255, 255, 255, 0.55);
	white-space: nowrap;
	cursor: pointer;
	touch-action: manipulation;
	-webkit-tap-highlight-color: transparent;
}

@media (hover: hover) {
	.game-btn:hover,
	#touch-controls .game-btn:hover {
		border-image-source: url("/ui/btn-on.png?v=2");
	}
}

.game-btn:active,
#touch-controls .game-btn:active,
.game-btn.active,
#touch-controls .game-btn.active {
	border-image-source: url("/ui/btn-down.png?v=2");
	padding-top: 2px !important;
}

.game-btn.danger,
#touch-controls .game-btn.danger {
	color: var(--ui-danger);
}

/* Standard: the gold face of a game button always carries dark ink, whatever its state (primary,
   warn, active, a panel's own colour); light or gold text on it could not be read. */
.game-btn:not(.danger),
#touch-controls .game-btn:not(.danger),
#touch-controls .hud-panel .game-btn:not(.danger) {
	color: var(--ui-ink) !important;
}

.game-btn:disabled,
#touch-controls .game-btn:disabled {
	filter: grayscale(1);
	opacity: 0.5;
	cursor: default;
}

.game-btn .crest-mini {
	width: 14px;
	height: 16px;
}

/* The round gold close button of the game's info windows. */
.ui-close,
#touch-controls .ui-close {
	flex: none;
	width: 36px;
	height: 36px;
	min-width: 0;
	min-height: 0 !important;
	padding: 0 !important;
	border: 0;
	border-radius: 50%;
	background: url("/ui/close.png?v=1") center / 26px 26px no-repeat;
	box-shadow: none;
	color: transparent;
	font-size: 0 !important;
	cursor: pointer;
	-webkit-tap-highlight-color: transparent;
}

.ui-close:active,
#touch-controls .ui-close:active {
	background-image: url("/ui/close-down.png?v=1");
}

/* Windows: the game's message box frame (3 px gold bevel) around the page's leather body. */
.ko-panel,
.hud-panel {
	border: 3px solid transparent;
	border-radius: 0;
	border-image: url("/ui/frame.png?v=1") 3 stretch;
	background: var(--ko-panel);
	background-clip: padding-box;
	box-shadow: 0 6px 18px rgba(0, 0, 0, 0.6);
}

/* Item cells: the bag's gold-lined slot. Item grades keep their coloured edge. */
.ko-slot:not([class*="attr-"]) {
	border: 2px solid transparent;
	border-radius: 0;
	border-image: url("/ui/slot.png?v=1") 2 fill stretch;
	background: none;
	box-shadow: none;
}

/* Check boxes: the game's own (chat filter) box. */
.ui-check {
	appearance: none;
	-webkit-appearance: none;
	flex: none;
	width: 20px;
	height: 21px;
	margin: 0;
	border: 0;
	background: url("/ui/check.png?v=1") center / contain no-repeat;
	image-rendering: pixelated;
	cursor: pointer;
}

.ui-check:checked {
	background-image: url("/ui/check-on.png?v=1");
}

/* ==== UI kit (ui-kit.js): rows, check boxes, sliders, selects, sections, headers, footers ====
   Every page panel is built from these; sizes and colours come from the --ui-* tokens. */
.ui-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	margin-bottom: 8px;
}

.ui-section {
	display: flex;
	flex-direction: column;
	gap: 2px;
	margin: 0 0 10px;
}

.ui-section-title {
	margin: 0 0 4px;
	padding-bottom: 3px;
	border-bottom: 1px solid var(--ui-line);
	color: var(--ui-gold-hi);
	font: 600 var(--ui-fs-m) var(--ui-font-title);
	letter-spacing: 0.04em;
	text-transform: uppercase;
}

.ui-row {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	min-height: 36px;
	padding: 4px 6px;
	border-radius: var(--ui-radius);
	color: var(--ui-text);
	font: var(--ui-fs-m) var(--ui-font);
}

.ui-row-toggle { cursor: pointer; }
.ui-disabled { opacity: 0.45; pointer-events: none; }
.ui-row:hover { background: rgba(200, 155, 60, 0.08); }

.ui-row-text {
	display: flex;
	flex-direction: column;
	min-width: 0;
}

.ui-row-hint {
	color: var(--ui-text-dim);
	font-size: var(--ui-fs-s);
}

.ui-select {
	min-width: 150px;
	padding: 5px 8px;
	border: 1px solid var(--ui-line);
	border-radius: var(--ui-radius);
	background: var(--ui-body);
	color: var(--ui-text);
	font: var(--ui-fs-m) var(--ui-font);
}

.ui-select:focus { outline: 1px solid var(--ui-gold); }

.ui-slider {
	display: flex;
	align-items: center;
	gap: 8px;
	width: min(220px, 50vw);
}

.ui-slider output {
	min-width: 3.2em;
	color: var(--ui-gold-hi);
	font: 600 var(--ui-fs-m) var(--ui-font);
	font-variant-numeric: tabular-nums;
	text-align: right;
}

.ui-slider input[type="range"] {
	flex: 1;
	height: 6px;
	margin: 0;
	appearance: none;
	-webkit-appearance: none;
	border: 1px solid var(--ui-line);
	border-radius: 3px;
	background: linear-gradient(90deg, var(--ui-gold) var(--fill, 0%), rgba(0, 0, 0, 0.6) var(--fill, 0%));
	cursor: pointer;
}

.ui-slider input[type="range"]::-webkit-slider-thumb {
	width: 16px;
	height: 16px;
	appearance: none;
	-webkit-appearance: none;
	border: 2px solid var(--ui-gold-hi);
	border-radius: 50%;
	background: #2a2015;
	box-shadow: 0 1px 3px #000;
}

.ui-slider input[type="range"]::-moz-range-thumb {
	width: 14px;
	height: 14px;
	border: 2px solid var(--ui-gold-hi);
	border-radius: 50%;
	background: #2a2015;
}

.ui-footer {
	display: flex;
	flex-wrap: wrap;
	justify-content: flex-end;
	gap: 6px;
	margin-top: 6px;
}

.ui-wide { width: 100%; }

#hud-settings {
	/* Solid enough that the game under it does not read through. */
	background: radial-gradient(120% 80% at 50% 0%, rgba(70, 52, 30, 0.35), transparent 60%),
		linear-gradient(180deg, rgb(34, 27, 19), rgb(14, 11, 8));
	top: 50%;
	left: 50%;
	z-index: 6;
	width: min(440px, calc(100% - 24px));
	max-height: calc(100% - 24px);
	overflow-y: auto;
	transform: translate(-50%, -50%);
	animation: ui-pop 160ms ease-out;
}

#hud-settings[hidden] { display: none; }

/* Pop-ups over the game (leave, confirm): a title, a line of text, full-width game buttons. */
#hud-exit,
#hud-confirm {
	padding: 14px 16px 16px;
	animation: ui-pop 160ms ease-out;
}

#hud-exit p,
#hud-confirm p {
	margin: 0 0 6px;
	padding-bottom: 8px;
	border-bottom: 1px solid var(--ui-line);
	color: var(--ui-gold-hi);
	font: 600 var(--ui-fs-xl)/1.3 var(--ui-font-title);
	letter-spacing: 0.04em;
	text-align: center;
	text-shadow: 0 1px 0 #000, 0 0 6px rgba(240, 208, 128, 0.3);
}

#hud-exit {
	gap: 10px;
}

#hud-confirm div {
	gap: 10px;
}

#hud-confirm div .game-btn {
	flex: 1 1 0;
}

@keyframes ui-pop {
	from { opacity: 0; transform: translate(-50%, -50%) scale(0.96); }
}

@media (prefers-reduced-motion: reduce) {
	#hud-exit,
	#hud-confirm,
	#quick-login,
	#register-form {
		animation: none;
	}
}

/* Notes at the top of the screen (new version, install hint) share one look. */
#update-hint,
#install-hint {
	border: 3px solid transparent;
	border-radius: 0;
	border-image: url("/ui/frame.png?v=1") 3 stretch;
	background: var(--ko-panel);
	background-clip: padding-box;
	color: var(--ui-text);
	font-size: var(--ui-fs-m);
}

#update-reload {
	min-height: 34px;
	font-size: var(--ui-fs-m) !important;
}

/* The menu is a column of game buttons: compact rows, and it scrolls on very short screens. */
#hud-menu {
	gap: 4px;
	max-height: calc(100% - var(--sa-t) - var(--sa-b) - 60px);
	overflow-y: auto;
	overscroll-behavior: contain;
	touch-action: pan-y;
}

#touch-controls #hud-menu .game-btn {
	min-height: 36px;
	font-size: var(--ui-fs-m) !important;
}

/* Buttons of the HUD windows are thumb targets: 44 px like the rest of the phone HUD. */
#touch-controls .hud-panel .game-btn {
	min-height: 44px;
}

/* ---- Combat rings: the skill slots, attack and the small keys in the game's gold and leather ---- */
#hud-combat > button {
	border: 0;
	background:
		radial-gradient(circle at 50% 30%, rgba(255, 230, 170, 0.12), transparent 60%),
		radial-gradient(circle, rgba(34, 26, 16, 0.82) 0 62%, rgba(12, 9, 6, 0.86));
	box-shadow:
		inset 0 0 0 1px var(--ui-ink),
		inset 0 0 0 calc(3px * var(--k)) var(--ui-gold),
		inset 0 0 0 calc(4px * var(--k)) var(--ui-line),
		inset 0 calc(2px * var(--k)) calc(8px * var(--k)) rgba(0, 0, 0, 0.7),
		0 calc(2px * var(--k)) calc(6px * var(--k)) rgba(0, 0, 0, 0.55);
	color: var(--ui-gold-hi);
	font-family: var(--ui-font-title);
	text-shadow: 0 1px 2px #000;
	transition: transform 80ms, filter 80ms;
}

#hud-combat > .atk {
	background:
		radial-gradient(circle at 50% 28%, rgba(255, 200, 150, 0.35), transparent 55%),
		radial-gradient(circle, #8c2a18 0 55%, #4a120a);
	box-shadow:
		inset 0 0 0 1px var(--ui-ink),
		inset 0 0 0 calc(4px * var(--k)) var(--ui-gold),
		inset 0 0 0 calc(5px * var(--k)) var(--ui-line),
		inset 0 0 calc(14px * var(--k)) rgba(255, 140, 80, 0.35),
		0 calc(3px * var(--k)) calc(10px * var(--k)) rgba(0, 0, 0, 0.6);
	color: #fff0d8;
}

.hud-slot:empty {
	background: radial-gradient(circle, rgba(20, 15, 10, 0.55) 0 60%, rgba(10, 8, 5, 0.6));
	box-shadow:
		inset 0 0 0 calc(2px * var(--k)) rgba(200, 155, 60, 0.35),
		0 calc(2px * var(--k)) calc(6px * var(--k)) rgba(0, 0, 0, 0.4);
	outline: 1px dashed rgba(200, 155, 60, 0.35);
	outline-offset: calc(-7px * var(--k));
	border-radius: 50%;
}

.hud-slot:empty::before {
	color: rgba(240, 208, 128, 0.55);
	font: 300 calc(22px * var(--k)) / 1 var(--ui-font);
}

/* The icon sits inside the gold ring. */
.hud-slot img,
.hud-slot .cd {
	inset: calc(4px * var(--k));
	width: auto;
	height: auto;
}

.hud-slot img {
	width: calc(100% - 8px * var(--k));
	height: calc(100% - 8px * var(--k));
	box-shadow: inset 0 0 6px #000;
}

/* Cooldown: dark sweep, a gold edge that fills back up, the seconds in the middle. */
.hud-slot .cd {
	display: grid;
	place-items: center;
	background: conic-gradient(rgba(0, 0, 0, 0.72) calc(var(--p, 0) * 1turn), transparent 0);
	color: #fff4d8;
	font: 700 calc(17px * var(--k)) / 1 var(--ui-font);
	text-shadow: 0 0 3px #000, 0 0 2px #000;
}

.hud-slot.cooling::after {
	content: "";
	position: absolute;
	inset: 0;
	border-radius: 50%;
	background: conic-gradient(transparent calc(var(--p, 0) * 1turn), var(--ui-gold-hi) 0);
	-webkit-mask: radial-gradient(circle, transparent calc(50% - 3px * var(--k)), #000 calc(50% - 2px * var(--k)));
	mask: radial-gradient(circle, transparent calc(50% - 3px * var(--k)), #000 calc(50% - 2px * var(--k)));
	pointer-events: none;
}


.hud-slot.ready {
	animation: slot-ready 360ms ease-out;
}

@keyframes slot-ready {
	0% { filter: brightness(1.8); box-shadow: 0 0 calc(16px * var(--k)) var(--ui-gold-hi); }
	100% { filter: none; }
}

.hud-slot .count {
	right: calc(2px * var(--k));
	bottom: calc(2px * var(--k));
	min-width: 14px;
	padding: 0 4px;
	border-radius: 7px;
	background: rgba(14, 10, 6, 0.85);
	box-shadow: 0 0 0 1px var(--ui-line);
	color: var(--ui-text);
	font: 700 10px / 14px var(--ui-font);
	text-align: center;
}

.hud-slot .count:empty {
	display: none;
}

.hud-slot.unusable {
	box-shadow:
		inset 0 0 0 1px var(--ui-ink),
		inset 0 0 0 calc(3px * var(--k)) var(--ui-danger),
		0 calc(2px * var(--k)) calc(6px * var(--k)) rgba(0, 0, 0, 0.55);
}

#hud-combat > button.pressed,
#hud-combat > button:active {
	transform: translate(-50%, -50%) translate(calc(var(--x, 0px) * var(--k)), calc(var(--y, 0px) * var(--k))) scale(0.92);
	filter: brightness(1.3);
}

#hud-combat > .hud-slot.target,
#touch-controls.armed .hud-slot {
	box-shadow:
		inset 0 0 0 calc(3px * var(--k)) var(--ui-gold-hi),
		0 0 calc(12px * var(--k)) rgba(240, 208, 128, 0.9);
}

#touch-controls.armed .hud-slot {
	animation: slot-armed 1.1s ease-in-out infinite;
}

@keyframes slot-armed {
	50% { box-shadow: inset 0 0 0 calc(3px * var(--k)) var(--ui-gold-hi), 0 0 calc(4px * var(--k)) rgba(240, 208, 128, 0.4); }
}

#hud-page {
	display: grid;
	place-content: center;
	line-height: 1;
	font-weight: 700;
}

#hud-page::after {
	content: "/" attr(data-of);
	color: var(--ui-text-dim);
	font-size: 9px;
}

@media (prefers-reduced-motion: reduce) {
	.hud-slot.ready,
	#touch-controls.armed .hud-slot {
		animation: none;
	}
}

/* ---- Chat panel: the page's own chat window; only it moves when the keyboard opens ---- */
#hud-chatpanel {
	position: fixed;
	left: calc(var(--sa-l) + 56px);
	top: calc(var(--sa-t) + 48px);
	width: min(460px, 52vw);
	height: min(280px, calc(100dvh - 200px * var(--k)));
	min-height: 150px;
	display: flex;
	flex-direction: column;
	gap: 6px;
	padding: 6px 8px 8px;
	z-index: 6;
	animation: ui-pop 140ms ease-out;
}

#hud-chatpanel[hidden] {
	display: none;
}

#hud-chatpanel header {
	display: flex;
	align-items: center;
	gap: 6px;
}

#hud-chat-modes {
	flex: 1;
	min-width: 0;
}

#touch-controls #hud-chat-modes > button {
	min-height: 30px;
	padding: 0 10px !important;
	font-size: var(--ui-fs-s) !important;
}

#hud-chat-modes > button[data-mode="private"].active { color: #80ffff; }
#hud-chat-modes > button[data-mode="party"].active { color: #40d0d0; }
#hud-chat-modes > button[data-mode="clan"].active { color: #60ff60; }
#hud-chat-modes > button[data-mode="ally"].active { color: #a0ff60; }
#hud-chat-modes > button[data-mode="shout"].active { color: #ff9040; }

#hud-chat-log {
	flex: 1;
	min-height: 0;
	margin: 0;
	padding: 4px 6px;
	list-style: none;
	overflow-y: auto;
	overscroll-behavior: contain;
	background: rgba(0, 0, 0, 0.35);
	box-shadow: inset 0 0 0 1px var(--ui-line);
	color: var(--ui-text);
	font: var(--ui-fs-m) / 1.35 var(--ui-font);
	-webkit-user-select: text;
	user-select: text;
}

#hud-chat-log li {
	overflow-wrap: anywhere;
}

#hud-chat-log b {
	color: var(--ui-gold-hi);
	font-weight: 700;
	cursor: pointer;
}

#hud-chat-form {
	display: flex;
	gap: 6px;
}

#hud-chat-form input {
	min-width: 0;
	height: 38px;
	padding: 0 10px;
	border: 1px solid var(--ui-line);
	border-radius: var(--ui-radius);
	background: rgba(8, 6, 4, 0.85);
	color: var(--ui-text);
	font: 16px var(--ui-font);
	-webkit-user-select: text;
	user-select: text;
}

#hud-chat-form input:focus {
	outline: none;
	border-color: var(--ui-gold);
	box-shadow: 0 0 0 1px var(--ui-gold);
}

#hud-chat-to {
	width: 96px;
	color: #80ffff !important;
}

#hud-chat-input {
	flex: 1;
}

#touch-controls #hud-chat-form .game-btn {
	min-height: 38px;
	padding: 0 14px !important;
}

#hud-chat-preview {
	pointer-events: auto;
}

#touch-controls #hud-chat-modes > button.active {
	border: 6px solid transparent;
	border-image: url("/ui/btn-on.png?v=2") 6 fill stretch;
	background: none;
	color: var(--ui-ink);
	text-shadow: none;
	font-weight: 700;
}

/* Readable on a phone: a wider window, larger lines; while typing it fills the space over the keyboard. */
#hud-chatpanel {
	width: min(620px, calc(100vw - var(--sa-l) - var(--sa-r) - 140px));
	height: min(340px, calc(100dvh - 120px * var(--k)));
}

#hud-chatpanel.typing {
	left: calc(var(--sa-l) + 8px);
	width: calc(100vw - var(--sa-l) - var(--sa-r) - 16px);
	min-height: 0;
	animation: none;
}

#hud-chat-log {
	font-size: 15px;
	line-height: 1.4;
}

#hud-chat-log li + li {
	margin-top: 2px;
}

#hud-chatpanel.typing #hud-chat-modes > button {
	min-height: 26px;
}

#hud-chat-form input {
	height: 42px;
	font-size: 17px;
}

#touch-controls #hud-chat-form .game-btn {
	min-height: 42px;
	min-width: 92px;
	font-size: 15px !important;
}

/* Lost connection: a game window over everything, also over the "quit" loader. */
/* Lost connection: the game dims and blurs behind one clear card; nothing else of the HUD shows. */
#reconnect-backdrop {
	position: fixed;
	inset: 0;
	z-index: 999;
	background: radial-gradient(80% 70% at 50% 45%, rgba(13, 15, 19, 0.55), rgba(5, 6, 9, 0.9));
	-webkit-backdrop-filter: blur(10px) saturate(0.6);
	backdrop-filter: blur(10px) saturate(0.6);
	animation: reconnect-fade 240ms ease-out;
}

#reconnect-backdrop[hidden] {
	display: none;
}

body.ko-offline #touch-controls,
body.ko-offline .hud-panel,
body.ko-offline #update-hint,
body.ko-offline #hud-toast {
	visibility: hidden !important;
}

#reconnect {
	position: fixed;
	top: 50%;
	left: 50%;
	z-index: 1000;
	display: grid;
	justify-items: center;
	gap: 10px;
	width: min(360px, calc(100vw - 32px));
	padding: 28px 24px 22px;
	border: 3px solid transparent;
	border-image: url("/ui/frame.png?v=1") 3 stretch;
	background: var(--ko-panel);
	background-clip: padding-box;
	box-shadow: 0 6px 18px rgba(0, 0, 0, 0.6);
	color: var(--ui-text);
	font-family: var(--ui-font);
	text-align: center;
	transform: translate(-50%, -50%);
	animation: ui-pop 200ms ease-out;
}

#reconnect[hidden] {
	display: none;
}

.reconnect-icon {
	display: grid;
	place-items: center;
	width: 60px;
	height: 60px;
	margin-bottom: 4px;
	border: 2px solid transparent;
	border-image: url("/ui/slot.png?v=1") 2 fill stretch;
	color: var(--ui-danger-hi);
}

.reconnect-icon svg {
	width: 28px;
	height: 28px;
	fill: none;
	stroke: currentColor;
	stroke-width: 1.8;
	stroke-linecap: round;
	stroke-linejoin: round;
}

#reconnect.going .reconnect-icon {
	color: var(--ko-gold-hi);
	animation: reconnect-pulse 1.1s ease-in-out infinite;
}

#reconnect h2 {
	margin: 0;
	color: var(--ko-gold-hi);
	font: 600 17px/1.25 var(--ko-serif);
	letter-spacing: 0.06em;
	text-shadow: 0 1px 0 #000;
}

#reconnect p {
	margin: 0;
	color: var(--ui-text-dim);
	font-size: 13px;
	line-height: 1.5;
}

#reconnect-status:empty {
	display: none;
}

#reconnect-status {
	color: var(--ko-gold-hi);
}

#reconnect .game-btn {
	width: 100%;
	min-height: 44px;
	margin-top: 8px;
}

@keyframes reconnect-fade { from { opacity: 0; } }
@keyframes reconnect-pulse { 50% { filter: brightness(1.4); } }

/* Keyboard up: little room is left, so the panel drops its tabs and frame padding; the mode is a chip
   beside the field and every other pixel goes to the newest messages. */
#hud-chat-mode {
	display: none;
}

#hud-chatpanel.typing {
	gap: 4px;
	padding: 4px 6px;
}

#hud-chatpanel.typing header {
	display: none;
}

#hud-chatpanel.typing #hud-chat-log {
	padding: 2px 6px;
	font-size: 14px;
	line-height: 1.3;
}

#touch-controls #hud-chatpanel.typing #hud-chat-mode {
	display: block;
	flex: none;
	min-width: 64px;
	height: 40px;
	padding: 0 8px !important;
	border: 1px solid var(--ui-line);
	border-radius: var(--ui-radius);
	background: rgba(8, 6, 4, 0.85);
	color: var(--ui-gold-hi);
	font: 700 13px var(--ui-font) !important;
}

#hud-chatpanel[data-mode="private"] #hud-chat-mode { color: #80ffff; }
#hud-chatpanel[data-mode="party"] #hud-chat-mode { color: #40d0d0; }
#hud-chatpanel[data-mode="clan"] #hud-chat-mode { color: #60ff60; }
#hud-chatpanel[data-mode="ally"] #hud-chat-mode { color: #a0ff60; }
#hud-chatpanel[data-mode="shout"] #hud-chat-mode { color: #ff9040; }

#hud-chatpanel.typing #hud-chat-form input,
#touch-controls #hud-chatpanel.typing #hud-chat-form .game-btn {
	height: 40px;
	min-height: 40px;
}

#hud-chatpanel.typing #hud-chat-to {
	width: 84px;
}

/* The browser draws in software: a note at the top with the fix. */
#gpu-hint {
	position: fixed;
	top: calc(6px + env(safe-area-inset-top));
	left: 50%;
	z-index: 31;
	width: min(560px, calc(100vw - 24px));
	display: grid;
	grid-template-columns: 1fr auto;
	gap: 2px 10px;
	padding: 8px 8px 8px 12px;
	transform: translateX(-50%);
	border: 3px solid transparent;
	border-image: url("/ui/frame.png?v=1") 3 stretch;
	background: var(--ko-panel);
	background-clip: padding-box;
	color: var(--ui-text);
	font: var(--ui-fs-m) / 1.35 var(--ui-font);
}

#gpu-hint[hidden] {
	display: none;
}

#gpu-hint > span:first-child {
	color: var(--ui-gold-hi);
	font-weight: 700;
}

#gpu-hint-how {
	grid-column: 1;
	color: var(--ui-text-dim);
}

#gpu-hint .ui-close {
	grid-column: 2;
	grid-row: 1 / span 2;
	align-self: start;
}

/* Clan panel: one row per member, the online ones brighter. */
.clan-list {
	display: flex;
	flex-direction: column;
	gap: 4px;
}

.clan-row {
	display: flex;
	align-items: center;
	gap: 6px;
	opacity: 0.6;
	font-size: 13px;
}

.clan-row.on {
	opacity: 1;
}

.clan-row span {
	flex: 1;
	overflow: hidden;
	white-space: nowrap;
	text-overflow: ellipsis;
}

/* Clan panel: the clan war (in progress, record, declare / surrender for the chief). */
.clan-war {
	display: flex;
	flex-direction: column;
	gap: 4px;
	padding: 6px 0;
	border-top: 1px solid var(--ui-line);
	border-bottom: 1px solid var(--ui-line);
	font-size: var(--ui-fs-m);
}

.clan-war p {
	margin: 0;
}

.clan-war-now {
	color: var(--ui-danger-hi);
	font-weight: bold;
}

#hud-clan-body > * {
	flex: none;
}

/* Clan panel: the alliance (confederacy) section under the members. */
.clan-sub {
	margin: 6px 0 0;
	font-size: 14px;
	color: var(--ui-gold-hi);
	border-top: 1px solid var(--ui-line);
	padding-top: 6px;
}

/* Desktop (body.desktop-hud): only the stall and clan panels of the page show; the game draws the
   rest itself. A visible child of a hidden parent shows, and only it takes the mouse. */
body.desktop-hud #touch-controls {
	visibility: hidden;
}

body.desktop-hud #hud-merchant,
body.desktop-hud #hud-merchant-browse,
body.desktop-hud #hud-clan,
body.desktop-hud #hud-settings,
body.desktop-hud #hud-confirm,
body.desktop-hud #hud-toast,
body.desktop-hud #hud-merchant-target,
body.desktop-hud #hud-merchant-banner {
	visibility: visible;
}

body.desktop-hud #hud-merchant,
body.desktop-hud #hud-merchant-browse,
body.desktop-hud #hud-clan {
	/* A window in the middle of the screen, like the game's own, not a strip down the right edge. */
	top: 50%;
	left: 50%;
	right: auto;
	bottom: auto;
	transform: translate(-50%, -50%);
	width: min(460px, calc(100% - 24px));
	height: auto;
	max-height: min(620px, calc(100% - 48px));
	border-radius: 6px;
}

/* ---- Player menu (hud.js): beside a right-clicked player; the game's frame, gold name, plain rows
   that light turquoise under the pointer like the game's buttons. */
#hud-pmenu {
	position: fixed;
	z-index: 8;
	display: flex;
	flex-direction: column;
	min-width: 168px;
	padding: 0 0 4px;
	color: var(--ui-text);
	font-family: var(--ui-font);
	pointer-events: auto;
	user-select: none;
	-webkit-font-smoothing: antialiased;
}

#hud-pmenu[hidden] { display: none; }
body.desktop-hud #hud-pmenu { visibility: visible; }

.pmenu-head {
	display: grid;
	grid-template-columns: auto 1fr;
	column-gap: 7px;
	align-items: center;
	margin-bottom: 3px;
	padding: 5px 10px 4px;
	border-bottom: 1px solid var(--ko-gold-lo);
	background: linear-gradient(90deg, transparent, rgba(200, 155, 60, 0.22), transparent);
}

.pmenu-nation {
	grid-row: span 2;
	width: 24px;
	height: 24px;
	object-fit: contain;
	filter: drop-shadow(0 1px 1px #000);
}

.pmenu-head b {
	overflow: hidden;
	color: var(--ko-gold-hi);
	font: 600 14px/1.25 var(--ko-serif);
	letter-spacing: 0.04em;
	text-overflow: ellipsis;
	text-shadow: 0 1px 0 #000;
	white-space: nowrap;
}

.pmenu-head small { color: var(--ui-text-dim); font-size: var(--ui-fs-s); }

#hud-pmenu .pmenu-item,
#touch-controls #hud-pmenu .pmenu-item {
	display: flex;
	align-items: center;
	gap: 9px;
	min-height: 30px;
	margin: 0 4px;
	padding: 0 8px;
	border: 1px solid transparent;
	border-radius: 0;
	background: none;
	box-shadow: none;
	color: var(--ui-text);
	font: 600 var(--ui-fs-m)/1 var(--ui-font);
	text-align: left;
	text-shadow: 0 1px 0 #000;
	cursor: pointer;
}

.pmenu-item svg {
	width: 15px;
	height: 15px;
	flex: none;
	fill: none;
	stroke: var(--ko-gold);
	stroke-width: 2;
	stroke-linecap: round;
	stroke-linejoin: round;
}

@media (hover: hover) {
	#hud-pmenu .pmenu-item:not(:disabled):hover {
		border-color: rgba(127, 207, 184, 0.45);
		background: linear-gradient(90deg, rgba(127, 207, 184, 0.18), rgba(127, 207, 184, 0.04));
		color: var(--ui-teal);
	}

	#hud-pmenu .pmenu-item:not(:disabled):hover svg { stroke: var(--ui-teal); }
}

#hud-pmenu .pmenu-item:active { color: var(--ui-teal); }
#hud-pmenu .pmenu-item:disabled { color: var(--ui-text-dim); cursor: default; }
#hud-pmenu .pmenu-item:disabled svg { stroke: var(--ui-text-dim); }
#hud-pmenu .pmenu-item.danger svg { stroke: var(--ui-danger-hi); }
#hud-pmenu .pmenu-item.armed { border-color: rgba(224, 72, 58, 0.5); background: rgba(154, 30, 18, 0.25); color: #ffb0a4; }

.pmenu-item em {
	margin-left: auto;
	padding-left: 10px;
	color: var(--ui-text-dim);
	font-size: 10px;
	font-style: normal;
	font-weight: 400;
}

/* ---- Testers' menu (cheat.js): a game window opened with the console key. The message box frame
   and leather (.hud-panel), a gold title strip that drags it, tabs on the left like the game's
   list buttons, slots for items. No animation. */
#hud-cheat {
	position: fixed;
	top: 50%;
	left: 50%;
	z-index: 7;
	display: flex;
	flex-direction: column;
	width: min(760px, calc(100% - 16px));
	height: min(540px, calc(100% - 16px));
	padding: 0;
	overflow: hidden;
	color: var(--ui-text);
	font-family: var(--ui-font);
	font-size: var(--ui-fs-m);
	pointer-events: auto;
	transform: translate(-50%, -50%);
	-webkit-font-smoothing: antialiased;
}

#hud-cheat.placed { transform: none; }
#hud-cheat[hidden] { display: none; }
body.desktop-hud #hud-cheat { visibility: visible; }
#hud-cheat button { min-height: 0; }
#hud-cheat button:not(.game-btn):not(.ui-close) { box-shadow: none; text-shadow: none; }

.cheat-title {
	display: flex;
	flex: none;
	align-items: center;
	gap: 8px;
	padding: 3px 4px 3px 12px;
	border-bottom: 1px solid var(--ko-gold-lo);
	background: linear-gradient(90deg, rgba(0, 0, 0, 0.35), rgba(200, 155, 60, 0.2), rgba(0, 0, 0, 0.35));
	cursor: move;
	user-select: none;
	touch-action: none;
}

.cheat-title-text {
	flex: 1;
	color: var(--ko-gold-hi);
	font: 600 15px/1.3 var(--ko-serif);
	letter-spacing: 0.08em;
	text-shadow: 0 1px 0 #000, 0 0 6px rgba(240, 208, 128, 0.35);
}

#hud-cheat .ui-close { width: 30px; height: 30px; cursor: pointer; }
/* Online tab: one row per player, crest, name and what they are, PM and go. */
#hud-cheat .cheat-online { display: flex; flex-direction: column; gap: 4px; }
#hud-cheat .cheat-player { display: flex; align-items: center; gap: 8px; padding: 4px 6px; border: 1px solid rgba(0, 0, 0, .45); background: rgba(0, 0, 0, .25); }
#hud-cheat .cheat-player.me { border-color: var(--ko-gold-lo); }
#hud-cheat .cheat-nation { width: 22px; height: 22px; flex: none; image-rendering: auto; }
#hud-cheat .cheat-player-who { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#hud-cheat .cheat-player-name { color: var(--ko-gold-hi); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#hud-cheat .cheat-player .game-btn { min-width: 64px; }

.cheat-body {
	display: grid;
	flex: 1;
	grid-template-columns: 132px 1fr;
	min-height: 0;
}

.cheat-nav {
	display: flex;
	flex-direction: column;
	gap: 3px;
	padding: 8px 6px;
	border-right: 1px solid var(--ko-gold-lo);
	background: rgba(0, 0, 0, 0.3);
}

#hud-cheat .cheat-tab {
	padding: 8px 10px;
	border: 1px solid #3a2e1c;
	border-radius: 0;
	background: linear-gradient(#2c2216, #17110a);
	color: var(--ui-text-dim);
	font: 600 var(--ui-fs-m)/1.2 var(--ui-font);
	text-align: left;
	cursor: pointer;
}

@media (hover: hover) {
	#hud-cheat .cheat-tab:hover { border-color: var(--ko-gold-lo); color: var(--ui-text); }
	#hud-cheat .cheat-item:hover { border-color: var(--ko-gold-hi); }
	#hud-cheat .cheat-chip:hover { color: var(--ui-text); }
}

#hud-cheat .cheat-tab.on {
	border-color: var(--ko-gold-hi);
	background: linear-gradient(#6a4e1e, #33250e);
	color: #fff4d0;
}

.cheat-content {
	display: flex;
	flex-direction: column;
	gap: 10px;
	min-width: 0;
	padding: 10px 12px;
	overflow-y: auto;
	scrollbar-width: thin;
	scrollbar-color: var(--ko-gold-lo) transparent;
	touch-action: pan-y;
}

.cheat-status {
	flex: none;
	min-height: 20px;
	padding: 3px 12px;
	border-top: 1px solid var(--ko-gold-lo);
	background: rgba(0, 0, 0, 0.4);
	color: var(--ui-ok);
	font-size: var(--ui-fs-s);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.cheat-status.bad { color: var(--ui-danger-hi); }

.cheat-section {
	display: flex;
	flex-direction: column;
	gap: 8px;
	padding: 8px 10px 10px;
	border: 1px solid #3a2e1c;
	background: rgba(0, 0, 0, 0.35);
}

.cheat-section-title {
	margin: 0 0 2px;
	padding-bottom: 3px;
	border-bottom: 1px solid rgba(107, 80, 32, 0.6);
	color: var(--ko-gold-hi);
	font: 600 13px/1.3 var(--ko-serif);
	letter-spacing: 0.05em;
	text-shadow: 0 1px 0 #000;
}

.cheat-line { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.cheat-label { color: var(--ui-text-dim); }
.cheat-muted { margin: 0; color: var(--ui-text-dim); font-size: var(--ui-fs-s); }
.cheat-closed { margin: 40px auto; color: var(--ui-danger-hi); font-size: var(--ui-fs-l); text-align: center; }
#hud-cheat .game-btn { min-height: 30px; padding: 0 10px !important; font-size: var(--ui-fs-s) !important; }
#hud-cheat .game-btn.armed { border-image-source: url("/ui/btn-on.png?v=2"); }

.cheat-input,
.cheat-search,
.cheat-select {
	height: 28px;
	box-sizing: border-box;
	padding: 0 6px;
	border: 2px solid transparent;
	border-image: url("/ui/slot.png?v=1") 2 fill stretch;
	background: none;
	color: var(--ui-text);
	font: var(--ui-fs-m) var(--ui-font);
}

.cheat-select option { background: #17110a; }
.cheat-search { flex: 1; min-width: 160px; }

/* Character card */
.cheat-card {
	display: grid;
	grid-template-columns: auto 1fr;
	gap: 6px 12px;
	align-items: center;
	padding: 10px;
	border: 1px solid var(--ko-gold-lo);
	background: radial-gradient(70% 140% at 100% 50%, rgba(200, 155, 60, 0.14), transparent 70%), rgba(0, 0, 0, 0.4);
}

.cheat-crest { grid-row: span 2; width: 40px; height: 40px; object-fit: contain; filter: drop-shadow(0 1px 1px #000); }
.cheat-facts, .cheat-stats { display: flex; flex-wrap: wrap; gap: 6px 18px; }
.cheat-fact, .cheat-stats span { display: flex; flex-direction: column; }
.cheat-fact small, .cheat-stats small { color: var(--ui-text-dim); font-size: 10px; letter-spacing: 0.05em; text-transform: uppercase; }
.cheat-fact b { color: var(--ko-gold-hi); font-size: 15px; text-shadow: 0 1px 0 #000; }
.cheat-stats b { color: var(--ui-text); }

/* Items */
.cheat-chips { display: flex; flex-wrap: wrap; gap: 4px; }

#hud-cheat .cheat-chip {
	padding: 4px 9px;
	border: 1px solid #3a2e1c;
	border-radius: 0;
	background: linear-gradient(#2c2216, #17110a);
	color: var(--ui-text-dim);
	font: 600 var(--ui-fs-s)/1.2 var(--ui-font);
	cursor: pointer;
}

#hud-cheat .cheat-chip.on { border-color: var(--ko-gold-hi); background: linear-gradient(#6a4e1e, #33250e); color: #fff4d0; }
.cheat-fit { display: flex; align-items: center; gap: 5px; color: var(--ui-text-dim); cursor: pointer; }

.cheat-grid, .cheat-set {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
	gap: 6px;
}

#hud-cheat .cheat-item {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 3px;
	padding: 6px 4px 4px;
	border: 1px solid #3a2e1c;
	background: rgba(0, 0, 0, 0.45);
	box-shadow: inset 0 0 6px #000;
	color: var(--ko-attr-0);
	cursor: pointer;
}

#hud-cheat .cheat-item img.merchant-icon,
#hud-cheat .cheat-detail-icon img.merchant-icon {
	width: 40px;
	height: 40px;
	padding: 0;
	border: 0;
	border-radius: 0;
	object-fit: cover;
}

.cheat-item-name {
	width: 100%;
	overflow: hidden;
	font-size: 10px;
	line-height: 1.25;
	text-align: center;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.cheat-detail {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 8px;
	padding: 8px;
	border: 1px solid var(--ko-gold-lo);
	background: rgba(40, 30, 16, 0.55);
}

.cheat-detail[hidden] { display: none; }
.cheat-detail-icon { display: grid; place-items: center; width: 46px; height: 46px; }
.cheat-detail-name { color: var(--ko-attr-2); text-shadow: 0 1px 0 #000; }

/* Teleport */
.cheat-zones { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.cheat-points { display: flex; flex-direction: column; gap: 4px; }
.cheat-point { display: flex; gap: 4px; }
.cheat-point .game-btn { flex: 1; justify-content: flex-start; }

#hud-cheat .cheat-del {
	width: 30px;
	border: 1px solid #3a2e1c;
	background: rgba(0, 0, 0, 0.45);
	color: var(--ui-danger-hi);
	cursor: pointer;
}

/* Debug */
.cheat-pre {
	margin: 0;
	padding: 8px;
	border: 1px solid #3a2e1c;
	background: rgba(0, 0, 0, 0.5);
	color: var(--ui-text);
	font: 11px/1.4 Consolas, monospace;
	white-space: pre-wrap;
	user-select: text;
}

.cheat-log { display: flex; flex-direction: column; gap: 2px; font-size: var(--ui-fs-s); }
.cheat-log div { display: flex; gap: 8px; color: var(--ui-ok); }
.cheat-log div.bad { color: var(--ui-danger-hi); }
.cheat-log small { color: var(--ui-text-dim); }

/* Phones: full screen, tabs in a row on top. */
@media (max-width: 640px), (max-height: 480px) {
	#hud-cheat { width: calc(100% - 8px); height: calc(100% - 8px); }
	.cheat-body { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
	.cheat-nav { flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--ko-gold-lo); }
	#hud-cheat .cheat-tab { flex: none; }
}

/* ---- Power Up Store (pus.js) ----
   The game's own look: the message box frame round leather, gold-lined slots, the sprite buttons,
   serif gold titles. No rounded cards or glow; gold stays the trim, not the surface. */
#hud-store {
	top: 50%;
	left: 50%;
	z-index: 6;
	display: flex;
	flex-direction: column;
	width: min(860px, calc(100% - 16px));
	height: min(600px, calc(100% - 16px));
	padding: 0;
	overflow: hidden;
	color: var(--ui-text);
	font-family: var(--ui-font);
	transform: translate(-50%, -50%);
	animation: ui-pop 160ms ease-out;
}

#hud-store[hidden] { display: none; }

#hud-store button { min-height: 0; }
#hud-store button:not(.game-btn):not(.ui-close) { box-shadow: none; text-shadow: none; }

.pus-ico {
	width: 16px;
	height: 16px;
	flex: none;
	fill: none;
	stroke: currentColor;
	stroke-width: 1.8;
	stroke-linecap: round;
	stroke-linejoin: round;
}

/* Header: the window's title strip */
.pus-head {
	display: flex;
	flex: none;
	align-items: center;
	gap: 12px;
	padding: 6px 8px 6px 10px;
	border-bottom: 1px solid var(--ko-gold-lo);
	background: linear-gradient(90deg, rgba(0, 0, 0, 0.35), rgba(200, 155, 60, 0.16), rgba(0, 0, 0, 0.35));
}

.pus-brand { display: flex; align-items: center; gap: 10px; min-width: 0; }

.pus-mark {
	display: grid;
	place-items: center;
	width: 32px;
	height: 32px;
	flex: none;
	border: 2px solid transparent;
	border-image: url("/ui/slot.png?v=1") 2 fill stretch;
	color: var(--ko-gold-hi);
	font: 700 19px/1 var(--ko-serif);
	text-shadow: 0 1px 0 #000, 0 0 6px rgba(240, 208, 128, 0.35);
}

.pus-titles { display: flex; flex-direction: column; gap: 1px; min-width: 0; }

.pus-title {
	margin: 0;
	color: var(--ko-gold-hi);
	font: 600 16px/1.25 var(--ko-serif);
	letter-spacing: 0.08em;
	text-shadow: 0 1px 0 #000, 0 0 6px rgba(240, 208, 128, 0.35);
	white-space: nowrap;
}

.pus-subtitle { color: var(--ui-text-dim); font-size: var(--ui-fs-s); white-space: nowrap; }

.pus-account { display: flex; align-items: center; gap: 8px; margin-left: auto; }

.pus-balance {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 3px 12px 3px 6px;
	border: 2px solid transparent;
	border-image: url("/ui/slot.png?v=1") 2 fill stretch;
}

.pus-balance.pus-flash { animation: pus-flash 800ms ease-out; }

.pus-balance-text { display: flex; flex-direction: column; line-height: 1.1; }

.pus-balance-label {
	color: var(--ui-text-dim);
	font-size: 10px;
	letter-spacing: 0.06em;
	text-transform: uppercase;
}

.pus-balance-value {
	color: var(--ko-gold-hi);
	font: 700 16px/1.15 var(--ui-font);
	font-variant-numeric: tabular-nums;
	text-shadow: 0 1px 0 #000;
}

.pus-coin {
	display: inline-block;
	flex: none;
	width: 22px;
	height: 22px;
	border-radius: 50%;
	background: radial-gradient(circle at 35% 30%, #fff1b8 0 8%, var(--ui-gold-hi) 30%, var(--ui-gold) 62%, #5a4012 100%);
	box-shadow: inset 0 -2px 2px rgba(0, 0, 0, 0.35), 0 0 0 1px #2a1e0a;
}

.pus-coin.sm { width: 13px; height: 13px; }
.pus-coin.xl { width: 52px; height: 52px; margin: 4px auto 0; }

/* Buttons are the game's sprite buttons (.game-btn), only sized for the store. */
#hud-store .game-btn { min-height: 34px; padding: 0 12px !important; font-size: var(--ui-fs-m) !important; }
#hud-store .game-btn .pus-ico { width: 14px; height: 14px; stroke-width: 2.4; }
#hud-store .ui-close { width: 32px; height: 32px; }

/* Body: categories on the left, products on the right */
.pus-main {
	display: grid;
	flex: 1;
	grid-template-columns: 176px 1fr;
	min-height: 0;
}

.pus-nav {
	display: flex;
	flex-direction: column;
	gap: 3px;
	padding: 8px 6px;
	border-right: 1px solid var(--ko-gold-lo);
	background: rgba(0, 0, 0, 0.3);
	overflow-y: auto;
}

#hud-store .pus-nav-item {
	display: flex;
	align-items: center;
	gap: 8px;
	width: 100%;
	padding: 7px 9px;
	border: 1px solid #3a2e1c;
	border-radius: 0;
	background: linear-gradient(#2c2216, #17110a);
	color: var(--ui-text-dim);
	font: 600 var(--ui-fs-m)/1.2 var(--ui-font);
	text-align: left;
	cursor: pointer;
}

@media (hover: hover) {
	#hud-store .pus-nav-item:hover { border-color: var(--ko-gold-lo); color: var(--ui-text); }
}

#hud-store .pus-nav-item.on {
	border-color: var(--ko-gold-hi);
	background: linear-gradient(#6a4e1e, #33250e);
	color: #fff4d0;
}

.pus-nav-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.pus-nav-count {
	min-width: 18px;
	padding: 1px 5px;
	border: 1px solid #3a2e1c;
	background: rgba(0, 0, 0, 0.5);
	color: var(--ui-text-dim);
	font-size: 10px;
	text-align: center;
}

.pus-nav-count:empty { display: none; }

.pus-content {
	min-width: 0;
	padding: 10px 12px 14px;
	overflow-y: auto;
	touch-action: pan-y;
	scrollbar-width: thin;
	scrollbar-color: var(--ko-gold-lo) transparent;
}

.pus-section-head {
	display: flex;
	align-items: baseline;
	gap: 10px;
	margin: 2px 0 10px;
	padding-bottom: 4px;
	border-bottom: 1px solid var(--ko-gold-lo);
}

.pus-section-head h3 {
	margin: 0;
	color: var(--ko-gold-hi);
	font: 600 14px/1.3 var(--ko-serif);
	letter-spacing: 0.06em;
	text-shadow: 0 1px 0 #000;
}

.pus-section-count { color: var(--ui-text-dim); font-size: var(--ui-fs-s); }

/* Featured banner */
.pus-hero {
	position: relative;
	display: flex;
	align-items: center;
	gap: 16px;
	margin-bottom: 14px;
	padding: 14px 18px;
	border: 1px solid var(--ko-gold-lo);
	background:
		radial-gradient(70% 140% at 100% 50%, rgba(200, 155, 60, 0.16), transparent 70%),
		rgba(0, 0, 0, 0.4);
	box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.6), inset 0 0 0 2px rgba(200, 155, 60, 0.18);
}

.pus-hero-text { display: flex; flex: 1; flex-direction: column; gap: 4px; min-width: 0; }

.pus-hero-kicker {
	color: var(--ui-gold);
	font-size: 10px;
	font-weight: 700;
	letter-spacing: 0.1em;
	text-transform: uppercase;
}

.pus-hero-name {
	margin: 0;
	color: var(--ko-attr-2);
	font: 600 20px/1.2 var(--ko-serif);
	text-shadow: 0 1px 0 #000;
}

.pus-hero-count { color: var(--ui-text-dim); font-size: var(--ui-fs-m); }

.pus-hero-actions { display: flex; align-items: center; gap: 14px; margin-top: 8px; }

.pus-hero-price,
.pus-card-price {
	display: flex;
	align-items: center;
	gap: 5px;
	color: var(--ko-gold-hi);
	font-weight: 700;
	font-variant-numeric: tabular-nums;
	text-shadow: 0 1px 0 #000;
}

.pus-hero-price { font-size: 19px; }
.pus-hero-price small,
.pus-card-price small { color: var(--ui-text-dim); font-size: 10px; font-weight: 600; }

.pus-hero-art {
	display: grid;
	place-items: center;
	width: 84px;
	height: 84px;
	flex: none;
	border: 2px solid transparent;
	border-image: url("/ui/slot.png?v=1") 2 fill stretch;
}

/* Product cards: a slot with the item, its name and price */
.pus-grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
	gap: 8px;
}

.pus-card {
	position: relative;
	display: flex;
	flex-direction: column;
	gap: 6px;
	padding: 10px 8px 8px;
	border: 1px solid #3a2e1c;
	background: rgba(0, 0, 0, 0.45);
	box-shadow: inset 0 0 6px #000;
	cursor: pointer;
}

@media (hover: hover) {
	.pus-card:hover { border-color: var(--ko-gold-lo); background: rgba(40, 30, 16, 0.55); }
}

.pus-card-art {
	display: grid;
	place-items: center;
	align-self: center;
	width: 52px;
	height: 52px;
	border: 2px solid transparent;
	border-image: url("/ui/slot.png?v=1") 2 fill stretch;
}

.pus-card-info { display: flex; flex-direction: column; gap: 2px; min-height: 34px; text-align: center; }

.pus-card-name {
	margin: 0;
	overflow: hidden;
	color: var(--ko-attr-0);
	font: 600 var(--ui-fs-m)/1.3 var(--ui-font);
	text-overflow: ellipsis;
	white-space: nowrap;
}

.pus-card-count { color: var(--ui-text-dim); font-size: var(--ui-fs-s); }

.pus-card-foot {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 6px;
	padding-top: 6px;
	border-top: 1px solid rgba(107, 80, 32, 0.6);
}

.pus-card-price { font-size: 14px; }
.pus-card.short .pus-card-price { color: var(--ui-text-dim); }

#hud-store .game-btn.pus-buy { min-height: 30px; padding: 0 8px !important; font-size: var(--ui-fs-s) !important; }

.pus-badge {
	position: absolute;
	top: 4px;
	left: 4px;
	z-index: 1;
	padding: 1px 5px;
	border: 1px solid #000;
	background: linear-gradient(#c88a2a, #7a4e12);
	color: #fff4d0;
	font: 700 9px/1.4 var(--ui-font);
	letter-spacing: 0.06em;
	text-shadow: 0 1px 0 #000;
}

.pus-badge.new { background: linear-gradient(#3f8a48, #1e4a24); }
.pus-badge.sale { background: linear-gradient(var(--ko-red), #5a140a); }

/* Item icons from the game (hud.js crops them to their 45x45 art): fill the slot. */
#hud-store img.merchant-icon {
	width: 100%;
	height: 100%;
	padding: 0;
	border: 0;
	border-radius: 0;
	background: none;
	object-fit: cover;
	image-rendering: auto;
}

.pus-art-ico { width: 56%; height: 56%; color: var(--ko-gold-hi); }

/* Loading and empty states */
.pus-skeleton {
	height: 150px;
	cursor: default;
	animation: pus-skeleton 1.2s ease-in-out infinite;
}

.pus-empty {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 8px;
	padding: 50px 20px;
	color: var(--ui-text-dim);
	text-align: center;
}

.pus-empty p { margin: 0; font-size: var(--ui-fs-m); }
.pus-empty-ico { width: 36px; height: 36px; stroke-width: 1.4; opacity: 0.6; }
.pus-muted { margin: 0; color: var(--ui-text-dim); font-size: var(--ui-fs-m); line-height: 1.5; }

/* History */
.pus-history {
	border: 1px solid #3a2e1c;
	background: rgba(0, 0, 0, 0.45);
}

.pus-history-row {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
	padding: 6px 10px;
	border-bottom: 1px solid rgba(107, 80, 32, 0.45);
}

.pus-history-row:last-child { border-bottom: 0; }
.pus-history-what { display: flex; align-items: center; gap: 10px; min-width: 0; }

.pus-history-art {
	display: grid;
	place-items: center;
	width: 34px;
	height: 34px;
	flex: none;
	border: 2px solid transparent;
	border-image: url("/ui/slot.png?v=1") 2 fill stretch;
}

.pus-history-name { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.pus-history-name strong { overflow: hidden; color: var(--ko-attr-0); font-size: var(--ui-fs-m); text-overflow: ellipsis; white-space: nowrap; }
.pus-history-name span { color: var(--ui-text-dim); font-size: var(--ui-fs-s); }
.pus-history-price { display: flex; align-items: center; gap: 10px; flex: none; color: var(--ko-gold-hi); font-size: var(--ui-fs-m); }
.pus-history-qty { color: var(--ui-text-dim); }

/* Purchase sheet: a message box over the store */
.pus-overlay {
	position: absolute;
	inset: 0;
	z-index: 2;
	display: grid;
	place-items: center;
	padding: 16px;
	background: rgba(0, 0, 0, 0.6);
}

.pus-overlay[hidden] { display: none; }

.pus-sheet {
	position: relative;
	display: flex;
	flex-direction: column;
	gap: 12px;
	width: min(360px, 100%);
	padding: 14px;
	border: 3px solid transparent;
	border-image: url("/ui/frame.png?v=1") 3 stretch;
	background: var(--ko-panel);
	background-clip: padding-box;
	box-shadow: 0 6px 18px rgba(0, 0, 0, 0.6);
	animation: ui-pop 140ms ease-out;
}

.pus-sheet-top { display: flex; align-items: center; gap: 12px; }

.pus-sheet-art {
	display: grid;
	place-items: center;
	width: 52px;
	height: 52px;
	flex: none;
	border: 2px solid transparent;
	border-image: url("/ui/slot.png?v=1") 2 fill stretch;
}

.pus-sheet-titles { display: flex; flex: 1; flex-direction: column; gap: 2px; min-width: 0; }

.pus-sheet-titles h3 {
	margin: 0;
	overflow: hidden;
	color: var(--ko-attr-0);
	font: 600 15px/1.25 var(--ko-serif);
	text-overflow: ellipsis;
	white-space: nowrap;
}

.pus-sheet-kicker {
	color: var(--ui-gold);
	font-size: 10px;
	font-weight: 700;
	letter-spacing: 0.1em;
	text-transform: uppercase;
}

.pus-sheet-unit { color: var(--ui-text-dim); font-size: var(--ui-fs-s); }
#hud-store .pus-sheet-top .ui-close { align-self: flex-start; }

.pus-sheet-row {
	display: flex;
	align-items: center;
	gap: 8px;
	color: var(--ui-text-dim);
	font-size: var(--ui-fs-m);
}

.pus-sheet-row > span { flex: 1; }

.pus-stepper {
	display: flex;
	align-items: center;
	border: 2px solid transparent;
	border-image: url("/ui/slot.png?v=1") 2 fill stretch;
}

#hud-store .pus-step {
	width: 32px;
	height: 30px;
	padding: 0;
	border: 0;
	background: transparent;
	color: var(--ko-gold-hi);
	font: 700 16px/1 var(--ui-font);
	cursor: pointer;
}

#hud-store .pus-step:active { color: var(--ui-teal); }

#hud-store .pus-step.pus-step-max {
	width: auto;
	padding: 0 10px;
	border: 1px solid var(--ko-gold-lo);
	background: linear-gradient(#2c2216, #17110a);
	font-size: 10px;
	letter-spacing: 0.06em;
}

.pus-qty {
	min-width: 36px;
	color: var(--ui-text);
	font: 700 14px/1 var(--ui-font);
	font-variant-numeric: tabular-nums;
	text-align: center;
}

.pus-summary {
	display: flex;
	flex-direction: column;
	gap: 6px;
	padding: 10px;
	border: 1px solid #3a2e1c;
	background: rgba(0, 0, 0, 0.45);
}

.pus-summary-line { display: flex; justify-content: space-between; gap: 12px; color: var(--ui-text-dim); font-size: var(--ui-fs-m); }
.pus-summary-line strong { color: var(--ko-gold-hi); font-variant-numeric: tabular-nums; }
.pus-summary-line:last-child { padding-top: 6px; border-top: 1px solid rgba(107, 80, 32, 0.6); }
.pus-summary-line strong.pus-bad { color: var(--ui-danger-hi); }

.pus-sheet-actions { display: flex; gap: 8px; }
#hud-store .pus-sheet-actions .game-btn { flex: 1; min-height: 38px; }
#hud-store .pus-sheet-actions .pus-confirm { flex: 2; }
#hud-store .pus-busy { animation: pus-busy 0.9s ease-in-out infinite; }

.pus-deposit-sheet { align-items: center; text-align: center; }
.pus-deposit-sheet h3 { margin: 0; color: var(--ko-gold-hi); font: 600 16px/1.2 var(--ko-serif); letter-spacing: 0.06em; }
#hud-store .pus-deposit-sheet > .ui-close { position: absolute; top: 6px; right: 6px; }
#hud-store .pus-deposit-sheet .game-btn { width: 100%; }

.pus-burst {
	position: absolute;
	top: 50%;
	left: 50%;
	z-index: 3;
	pointer-events: none;
}

.pus-burst .pus-coin {
	position: absolute;
	animation: pus-burst 900ms cubic-bezier(0.2, 0.7, 0.3, 1) forwards;
}

body.desktop-hud #hud-store { visibility: visible; }

/* Phones: categories become a row of tabs above the products. */
@media (max-width: 640px), (max-height: 480px) {
	#hud-store { width: calc(100% - 8px); height: calc(100% - 8px); }
	.pus-head { gap: 8px; padding: 5px 6px 5px 8px; }
	.pus-subtitle { display: none; }
	.pus-main { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
	.pus-nav { flex-direction: row; gap: 4px; padding: 6px; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--ko-gold-lo); }
	#hud-store .pus-nav-item { width: auto; flex: none; padding: 6px 10px; }
	.pus-content { padding: 8px; }
	.pus-hero { padding: 10px 12px; }
	.pus-hero-art { width: 64px; height: 64px; }
	.pus-hero-name { font-size: 17px; }
	.pus-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 6px; }
}

@keyframes pus-flash { 30% { box-shadow: 0 0 8px rgba(240, 208, 128, 0.6); } }
@keyframes pus-skeleton { 50% { opacity: 0.5; } }
@keyframes pus-busy { 50% { filter: brightness(0.85); } }
@keyframes pus-burst {
	0% { opacity: 1; transform: translate(0, 0) scale(0.6); }
	70% { opacity: 1; }
	100% { opacity: 0; transform: translate(var(--dx), calc(var(--dy) + 50px)) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
	#hud-store,
	#hud-store *,
	.pus-burst .pus-coin {
		animation: none !important;
		transition: none !important;
	}
}

/* ---- Quest book (quest.js): the testers' menu frame, a list of quest rows ---- */
#hud-quests {
	position: fixed;
	top: 50%;
	left: 50%;
	z-index: 7;
	display: flex;
	flex-direction: column;
	width: min(620px, calc(100% - 16px));
	height: min(560px, calc(100% - 16px));
	padding: 0;
	overflow: hidden;
	color: var(--ui-text);
	font-family: var(--ui-font);
	font-size: var(--ui-fs-m);
	pointer-events: auto;
	transform: translate(-50%, -50%);
	-webkit-font-smoothing: antialiased;
}

#hud-quests.placed { transform: none; }
#hud-quests[hidden] { display: none; }
body.desktop-hud #hud-quests { visibility: visible; }
#hud-quests button { min-height: 0; }
#hud-quests button:not(.game-btn):not(.ui-close) { box-shadow: none; text-shadow: none; }

.quest-title {
	display: flex;
	flex: none;
	align-items: center;
	gap: 8px;
	padding: 3px 4px 3px 12px;
	border-bottom: 1px solid var(--ko-gold-lo);
	background: linear-gradient(90deg, rgba(0, 0, 0, 0.35), rgba(200, 155, 60, 0.2), rgba(0, 0, 0, 0.35));
	cursor: move;
	user-select: none;
	touch-action: none;
}

.quest-title-text {
	flex: 1;
	color: var(--ko-gold-hi);
	font: 600 15px/1.3 var(--ko-serif);
	letter-spacing: 0.08em;
	text-shadow: 0 1px 0 #000, 0 0 6px rgba(240, 208, 128, 0.35);
}

#hud-quests .ui-close { width: 30px; height: 30px; cursor: pointer; }

.quest-nav {
	display: flex;
	flex: none;
	gap: 3px;
	padding: 6px 8px;
	border-bottom: 1px solid var(--ko-gold-lo);
	background: rgba(0, 0, 0, 0.3);
}

#hud-quests .quest-tab {
	flex: 1 1 0;
	padding: 7px 10px;
	border: 1px solid #3a2e1c;
	border-radius: 0;
	background: linear-gradient(#2c2216, #17110a);
	color: var(--ui-text-dim);
	font: 600 var(--ui-fs-m)/1.2 var(--ui-font);
	cursor: pointer;
}

#hud-quests .quest-tab.on {
	border-color: var(--ko-gold-hi);
	background: linear-gradient(#6a4e1e, #33250e);
	color: #fff4d0;
}

.quest-list {
	display: flex;
	flex: 1;
	flex-direction: column;
	gap: 6px;
	min-height: 0;
	padding: 8px 10px;
	overflow-y: auto;
	scrollbar-width: thin;
	scrollbar-color: var(--ko-gold-lo) transparent;
	touch-action: pan-y;
}

.quest-empty { margin: 30px auto; color: var(--ui-text-dim); text-align: center; }

.quest-row {
	display: flex;
	flex: none;
	flex-direction: column;
	gap: 4px;
	padding: 6px 8px 8px;
	border: 1px solid #3a2e1c;
	background: rgba(0, 0, 0, 0.35);
	cursor: pointer;
}

.quest-row.dim { opacity: 0.5; }

@media (hover: hover) {
	#hud-quests .quest-tab:hover { border-color: var(--ko-gold-lo); color: var(--ui-text); }
	.quest-row:hover { border-color: var(--ko-gold-lo); }
}

.quest-head { display: flex; align-items: center; gap: 8px; }
.quest-name { flex: 1; min-width: 0; color: var(--ko-gold-hi); font: 600 14px/1.3 var(--ko-serif); text-shadow: 0 1px 0 #000; }
.quest-lv { color: var(--ui-text-dim); font-size: var(--ui-fs-s); white-space: nowrap; }
.quest-badge { padding: 0 5px; border: 1px solid var(--ko-gold-lo); color: var(--ko-gold-hi); font-size: var(--ui-fs-s); white-space: nowrap; }
.quest-badge.taken { border-color: #4f8a3a; color: #9fdc7a; }
.quest-done { flex: none; width: 20px; height: 21px; background: url("/ui/check-on.png?v=1") center / contain no-repeat; }
#hud-quests .quest-track-btn { min-height: 28px; padding: 0 10px !important; font-size: var(--ui-fs-s) !important; }
#hud-quests .quest-track-btn.armed { border-image-source: url("/ui/btn-on.png?v=2"); }
.quest-npc { color: var(--ui-text-dim); font-size: var(--ui-fs-s); }
.quest-need-wrap { display: flex; flex-direction: column; gap: 2px; }
.quest-need { display: flex; align-items: center; gap: 6px; }
.quest-need img.merchant-icon { width: 28px; height: 28px; }
.quest-need-name { flex: 1; min-width: 0; }
.quest-count { font-variant-numeric: tabular-nums; white-space: nowrap; }
.quest-need.ok .quest-count { color: var(--ui-ok); }
.quest-src { display: flex; flex-wrap: wrap; gap: 2px 10px; padding-left: 34px; color: var(--ui-text-dim); font-size: var(--ui-fs-s); }
.quest-mob.fit { color: var(--ui-text); }
.quest-mob.easy { color: #8a8478; }
.quest-mob.hard { color: var(--ui-danger-hi); }
.quest-reward { color: #e8d6a0; font-size: var(--ui-fs-s); }
.quest-gold { color: var(--ko-gold-hi); font-size: var(--ui-fs-s); }
.quest-gold.short { color: var(--ui-danger-hi); }
.quest-details { display: flex; flex-direction: column; gap: 2px; margin-top: 4px; padding-top: 5px; border-top: 1px solid rgba(107, 80, 32, 0.6); font-size: var(--ui-fs-s); }
.quest-desc { margin: 0 0 4px; color: var(--ui-text); }
.quest-sub { margin-top: 3px; color: var(--ko-gold-hi); }
.quest-drop { padding-left: 10px; color: var(--ui-text-dim); }

@media (max-width: 640px), (max-height: 480px) {
	#hud-quests { width: calc(100% - 8px); height: calc(100% - 8px); }
	/* Thumb-sized: tabs, close and the track button at least 32 px; rows a bit tighter. */
	#hud-quests .quest-tab { min-height: 32px; }
	#hud-quests .ui-close { width: 32px; height: 32px; }
	#hud-quests .quest-track-btn { min-height: 34px; min-width: 76px; }
}

/* ---- Quest tracker (quest.js): a small box like the party list; right-middle on the desktop,
   under the party list on phones. ---- */
#hud-quest-track {
	position: absolute;
	top: 40%;
	right: 8px;
	z-index: 2;
	display: none;
	flex-direction: column;
	width: 210px;
	color: var(--ui-text);
	font-family: var(--ui-font);
	font-size: 12px;
	pointer-events: auto;
	text-shadow: 0 0 3px #000, 0 0 2px #000;
	-webkit-font-smoothing: antialiased;
}

#touch-controls.in-world #hud-quest-track:not([hidden]),
body.desktop-hud #hud-quest-track:not([hidden]) { display: flex; }
body.desktop-hud #hud-quest-track { visibility: visible; }
#hud-quest-track.placed { right: auto; }
#hud-quest-track.dead { opacity: 0.55; }
#hud-quest-track button { min-height: 0; box-shadow: none; }

.qt-head {
	display: flex;
	align-items: center;
	gap: 2px;
	padding: 1px 2px 1px 6px;
	border: 1px solid rgba(200, 155, 60, 0.55);
	background: rgba(12, 10, 8, 0.7);
	cursor: move;
	user-select: none;
	touch-action: none;
}

.qt-title { flex: 1; color: var(--ko-gold-hi); font: 600 12px/1.6 var(--ko-serif); letter-spacing: 0.05em; }

#hud-quest-track .qt-btn {
	width: 22px;
	height: 20px;
	padding: 0;
	border: 0;
	background: none;
	color: var(--ko-gold-hi);
	font: 600 14px/1 var(--ui-font);
	cursor: pointer;
}

.qt-body { display: flex; flex-direction: column; gap: 3px; margin-top: 3px; }
#hud-quest-track.min .qt-body { display: none; }

.qt-quest,
.qt-suggest {
	display: flex;
	flex-direction: column;
	gap: 2px;
	padding: 3px 6px;
	background: rgba(12, 10, 8, 0.55);
}

.qt-suggest { color: var(--ui-text-dim); cursor: pointer; }
.qt-name { color: #f0e0b0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qt-needs { display: flex; flex-wrap: wrap; gap: 2px 8px; }
.qt-need { display: inline-flex; align-items: center; gap: 3px; font-variant-numeric: tabular-nums; }
.qt-need img.merchant-icon { width: 20px; height: 20px; padding: 0; }
.qt-need.ok { color: var(--ko-gold-hi); }
.qt-need.ok::after { content: ""; width: 14px; height: 15px; background: url("/ui/check-on.png?v=1") center / contain no-repeat; }

.qt-go { display: flex; align-items: center; gap: 5px; min-height: 22px; cursor: pointer; }
.qt-who { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qt-go.npc .qt-who { color: var(--ko-gold-hi); }
.qt-who.easy { color: #8a8478; }
.qt-who.hard { color: var(--ui-danger-hi); }
.qt-dist,
.qt-far { color: var(--ui-text-dim); font-variant-numeric: tabular-nums; white-space: nowrap; }
.qt-here { color: var(--ui-ok); }
.qt-act { display: flex; align-items: center; gap: 6px; margin-top: 3px; cursor: pointer; font-size: var(--ui-fs-s); }
.qt-act-btn { padding: 0 6px; border: 1px solid #8a3a2a; color: #ffb090; background: rgba(60, 14, 8, .55); white-space: nowrap; }
.qt-act.npc .qt-act-btn { border-color: var(--ko-gold-lo); color: var(--ko-gold-hi); background: rgba(40, 30, 8, .55); }
.qt-act-who { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (hover: hover) { .qt-act:hover .qt-act-btn { filter: brightness(1.25); } }

.qt-arrow {
	flex: none;
	width: 14px;
	height: 16px;
	background: var(--ko-gold-hi);
	clip-path: polygon(50% 0, 100% 100%, 50% 72%, 0 100%);
}

@media (hover: hover) {
	.qt-go:hover .qt-who,
	.qt-suggest:hover { text-decoration: underline; }
}

/* Phones: the party list's width and scale, at its left edge (quest.js moves it under the list). */
@media (max-width: 640px), (max-height: 480px) {
	body:not(.desktop-hud) #hud-quest-track:not(.placed) {
		top: calc(var(--sa-t) + 52px * var(--k));
		right: auto;
		left: calc(var(--sa-l) + 4px);
	}
	body:not(.desktop-hud) #hud-quest-track {
		width: calc(160px * var(--k));
		font-size: calc(11px * var(--k));
	}
	/* The fold and hide buttons and the lines that do something: a thumb's height. */
	body:not(.desktop-hud) #hud-quest-track .qt-btn { min-width: 30px; min-height: 26px; }
	body:not(.desktop-hud) #hud-quest-track .qt-go,
	body:not(.desktop-hud) #hud-quest-track .qt-act,
	body:not(.desktop-hud) #hud-quest-track .qt-suggest { min-height: 26px; display: flex; align-items: center; }
	body:not(.desktop-hud) #hud-quest-track .qt-act-btn { padding: 3px 8px; }
}

/* The game's own cursor over every page element too: panels, forms, menus (hud.js picks the
   nation's pair). The canvas keeps the one the game sets on it (attack, repair, ...). */
html, body, body *:not(canvas), body *:not(canvas)::before, body *:not(canvas)::after {
	cursor: var(--ko-cursor, url("/cursors/Cursor_Normal.cur"), default) !important;
}
/* Pressed: the game's click cursor, as in the world. */
html:active, body:active, body *:not(canvas):active, body *:not(canvas):active::before, body *:not(canvas):active::after {
	cursor: var(--ko-cursor-click, url("/cursors/Cursor_Click.cur"), default) !important;
}

/* ---- NPC windows on phones (npc.js): shop, warehouse, menus, warp, anvil, reset, class ----
   Full screen, big rows and slots for a thumb, no animation. Touch only (no desktop opt-in). */
#hud-npc {
	position: fixed;
	top: calc(var(--sa-t) + 4px);
	right: calc(var(--sa-r) + 4px);
	bottom: calc(var(--sa-b) + 4px);
	left: calc(var(--sa-l) + 4px);
	z-index: 6;
	display: flex;
	flex-direction: column;
	padding: 0;
	overflow: hidden;
	color: var(--ui-text);
	font-family: var(--ui-font);
	font-size: var(--ui-fs-l);
	pointer-events: auto;
	-webkit-font-smoothing: antialiased;
}
#hud-npc[hidden] { display: none; }
#hud-npc *, #hud-npc *::before, #hud-npc *::after { animation: none !important; transition: none !important; }
#touch-controls:has(#hud-npc:not([hidden])) #hud-toast { z-index: 9; }

#hud-npc .npc-head {
	display: flex;
	flex: none;
	align-items: center;
	gap: 8px;
	min-height: 44px;
	padding: 2px 4px 2px 8px;
	border-bottom: 1px solid var(--ko-gold-lo);
}
#hud-npc .npc-title {
	flex: 1;
	min-width: 0;
	overflow: hidden;
	border: 0;
	background: none;
	font-size: var(--ui-fs-xl);
	text-align: left;
	text-overflow: ellipsis;
	white-space: nowrap;
}
#hud-npc .npc-head-info { display: flex; flex-direction: column; align-items: flex-end; gap: 1px; }
#hud-npc .npc-gold { color: var(--ui-gold-hi); font-weight: 700; font-size: var(--ui-fs-l); white-space: nowrap; }
#hud-npc .npc-busy { color: var(--ui-teal); font-size: var(--ui-fs-s); }
#hud-npc .npc-busy[hidden] { display: none; }
#hud-npc .ui-close { width: 44px; height: 44px; background-size: 30px 30px; }

#hud-npc .npc-tabbar { flex: none; padding: 6px 8px 0; }
#hud-npc .npc-tabbar[hidden], #hud-npc .npc-foot[hidden] { display: none; }
#hud-npc .npc-tabs { gap: 6px; }
#hud-npc .npc-tabs > button {
	flex: 1;
	min-width: 72px;
	min-height: 44px;
	border: 1px solid var(--ko-gold-lo);
	background: var(--ui-body);
	color: var(--ui-text);
	font-weight: 700;
	font-size: var(--ui-fs-l) !important;
}
#hud-npc .npc-tabs > button.active { color: #fff4d0; border-color: var(--ko-gold-hi); background: linear-gradient(#6a4e1e, #33250e); }
#hud-npc .npc-pages { margin-bottom: 8px; }
#hud-npc .npc-pages > button { flex: none; min-width: 48px; }

#hud-npc .npc-body {
	flex: 1;
	min-height: 0;
	padding: 8px;
	overflow-y: auto;
	overscroll-behavior: contain;
	-webkit-overflow-scrolling: touch;
}
#hud-npc .npc-foot { display: flex; flex: none; gap: 8px; padding: 6px 8px 8px; border-top: 1px solid var(--ko-gold-lo); }
#hud-npc .npc-foot > * { flex: 1; }

#hud-npc .game-btn, #hud-npc .npc-act { min-height: 48px; font-size: var(--ui-fs-l) !important; }
#hud-npc .ui-wide { width: 100%; }

/* Rows: menus, quest lines, warp list, class options. */
#hud-npc .npc-list { display: flex; flex-direction: column; gap: 6px; }
#hud-npc .npc-row {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
	width: 100%;
	min-height: 52px;
	padding: 6px 12px !important;
	border: 1px solid var(--ko-gold-lo);
	border-radius: var(--ui-radius);
	background: var(--ui-body);
	color: var(--ui-text);
	font-size: var(--ui-fs-l) !important;
	text-align: left;
}
#hud-npc .npc-row:active { border-color: var(--ui-teal); color: var(--ui-teal); }
#hud-npc .npc-row:disabled { opacity: 0.5; }
#hud-npc .npc-row-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
#hud-npc .npc-row-label { font-weight: 600; overflow-wrap: anywhere; }
#hud-npc .npc-row-sub { color: var(--ui-text-dim); font-size: var(--ui-fs-m); }
#hud-npc .npc-row-side { flex: none; color: var(--ui-gold-hi); font-weight: 700; }

#hud-npc .npc-text { margin: 0 0 10px; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }
#hud-npc .npc-hint { margin: 0 0 8px; color: var(--ui-text-dim); font-size: var(--ui-fs-m); }
#hud-npc .npc-empty { margin: 24px 0; color: var(--ui-text-dim); text-align: center; }
#hud-npc .npc-weight { margin: 8px 0 0; color: var(--ui-text-dim); font-size: var(--ui-fs-m); text-align: right; }

/* Item slots with the game's icons, the price under each. */
#hud-npc .npc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(68px, 1fr)); gap: 6px; }
#hud-npc .npc-slot {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 2px;
	min-height: 0;
	padding: 2px !important;
	border: 0;
	background: none;
	box-shadow: none;
	color: var(--ui-text);
}
#hud-npc .npc-icon { display: block; position: relative; box-sizing: border-box; width: 56px; height: 56px; }
#hud-npc .npc-icon img { display: block; width: 100%; height: 100%; }
#hud-npc .npc-count, #hud-npc .npc-plus {
	position: absolute;
	padding: 0 2px;
	background: rgba(0, 0, 0, 0.7);
	color: #fff;
	font: 700 11px/1.2 var(--ui-font);
}
#hud-npc .npc-count { right: 1px; bottom: 1px; }
#hud-npc .npc-plus { left: 1px; top: 1px; color: var(--ui-gold-hi); }
#hud-npc .npc-price { color: var(--ui-gold-hi); font-size: var(--ui-fs-m); font-weight: 700; white-space: nowrap; }
#hud-npc .npc-slot.short .npc-price { color: var(--ui-danger-hi); }
#hud-npc .npc-slot.short .npc-icon { opacity: 0.55; }
#hud-npc .npc-slot.rare .npc-icon { outline: 1px solid var(--ko-attr-2); }
#hud-npc .npc-slot.on .npc-icon { outline: 3px solid var(--ui-teal); outline-offset: -1px; }
#hud-npc .npc-slot:active .npc-icon { outline: 2px solid var(--ui-teal); }

/* Repair list, warehouse Noah, anvil, reset. */
#hud-npc .npc-repair { display: flex; align-items: center; gap: 10px; padding: 4px 0; border-bottom: 1px solid rgba(107, 80, 32, 0.5); }
#hud-npc .npc-repair .npc-icon { width: 44px; height: 44px; flex: none; }
#hud-npc .npc-repair-text { display: flex; flex: 1; flex-direction: column; min-width: 0; }
#hud-npc .npc-repair-all { margin-top: 10px; }
#hud-npc .npc-goldbox, #hud-npc .npc-reset { display: flex; flex-direction: column; gap: 8px; max-width: 480px; margin: 0 auto; }
#hud-npc .npc-gold-input {
	box-sizing: border-box;
	width: 100%;
	min-height: 48px;
	padding: 0 12px;
	border: 1px solid var(--ko-gold-lo);
	background: rgba(0, 0, 0, 0.6);
	color: var(--ui-text);
	font: 700 18px var(--ui-font);
	user-select: text;
	-webkit-user-select: text;
}
#hud-npc .npc-gold-quick, #hud-npc .npc-gold-actions { display: flex; gap: 8px; }
#hud-npc .npc-gold-quick > *, #hud-npc .npc-gold-actions > * { flex: 1; }
#hud-npc .npc-up-item { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
#hud-npc .npc-up-item .npc-row-label { flex: 1; }

#hud-npc .npc-line { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; }
#hud-npc .npc-line > span { color: var(--ui-text-dim); }
#hud-npc .npc-total strong { color: var(--ui-gold-hi); font-size: var(--ui-fs-xl); }
#hud-npc .npc-bad strong, #hud-npc .npc-why { color: var(--ui-danger-hi); }
#hud-npc .npc-why, #hud-npc .npc-ask { margin: 4px 0; font-weight: 600; }
#hud-npc .npc-why[hidden], #hud-npc .npc-ask[hidden] { display: none; }
#hud-npc .npc-ask { color: var(--ui-gold-hi); }

/* Bottom sheet: quantity and confirmations; a tap on the dimmed panel behind closes it. */
#hud-npc .npc-overlay {
	position: absolute;
	inset: 0;
	z-index: 2;
	display: flex;
	align-items: flex-end;
	justify-content: center;
	background: rgba(0, 0, 0, 0.55);
}
#hud-npc .npc-overlay[hidden] { display: none; }
#hud-npc .npc-sheet {
	box-sizing: border-box;
	width: min(560px, 100%);
	max-height: 100%;
	padding: 10px 12px 12px;
	overflow-y: auto;
	border-top: 2px solid var(--ko-gold);
	background: #17120c;
}
#hud-npc .npc-sheet-top { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
#hud-npc .npc-sheet-icon { width: 52px; height: 52px; flex: none; }
#hud-npc .npc-sheet-titles { display: flex; flex: 1; flex-direction: column; min-width: 0; }
#hud-npc .npc-sheet-title { margin: 0; color: var(--ui-gold-hi); font: 600 var(--ui-fs-xl)/1.25 var(--ui-font-title); overflow-wrap: anywhere; }
#hud-npc .npc-sheet-sub { color: var(--ui-text-dim); font-size: var(--ui-fs-m); }
#hud-npc .npc-sheet-text { margin: 6px 0 10px; line-height: 1.45; white-space: pre-wrap; }
#hud-npc .npc-sheet-actions { display: flex; gap: 8px; margin-top: 8px; }
#hud-npc .npc-sheet-actions > * { flex: 1; }
#hud-npc .npc-qty-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 4px 0 6px; }
#hud-npc .npc-qty-label { color: var(--ui-text-dim); }
#hud-npc .npc-stepper { display: flex; align-items: center; gap: 4px; }
#hud-npc .npc-step {
	min-width: 48px;
	min-height: 48px;
	padding: 0 8px !important;
	border: 1px solid var(--ko-gold-lo);
	background: var(--ui-body);
	color: var(--ui-text);
	font-weight: 700;
	font-size: var(--ui-fs-xl) !important;
}
#hud-npc .npc-step.ten, #hud-npc .npc-step.max { font-size: var(--ui-fs-m) !important; }
#hud-npc .npc-step:active { border-color: var(--ui-teal); color: var(--ui-teal); }
#hud-npc .npc-qty { min-width: 56px; color: var(--ui-gold-hi); font: 700 22px/1 var(--ui-font); text-align: center; }

/* Short landscape phones: the sheet takes the right side, the stepper and its button stay in reach. */
@media (max-height: 430px) and (orientation: landscape) {
	#hud-npc .npc-overlay { align-items: stretch; justify-content: flex-end; }
	#hud-npc .npc-sheet { width: min(440px, 62%); border-top: 0; border-left: 2px solid var(--ko-gold); }
	#hud-npc .npc-head { min-height: 40px; }
}

/* ---- Clan cape shop (cape.js): a game window in the middle; the whole screen on phones ---- */
#hud-cape {
	position: fixed;
	top: 50%;
	left: 50%;
	z-index: 7;
	display: flex;
	flex-direction: column;
	width: min(660px, calc(100% - 16px));
	max-height: calc(100% - 16px);
	padding: 8px 12px 12px;
	overflow: hidden;
	color: var(--ui-text);
	font-family: var(--ui-font);
	font-size: var(--ui-fs-m);
	pointer-events: auto;
	transform: translate(-50%, -50%);
	-webkit-font-smoothing: antialiased;
}
#hud-cape[hidden] { display: none; }
#touch-controls:has(#hud-cape:not([hidden])) #hud-toast { z-index: 9; }
body.desktop-hud #hud-cape { visibility: visible; }
#hud-cape *, #hud-cape *::before, #hud-cape *::after { animation: none !important; transition: none !important; }
#hud-cape button { min-height: 0; }
#hud-cape button:not(.game-btn):not(.ui-close) { box-shadow: none; text-shadow: none; }
#hud-cape .ui-header { margin-bottom: 4px; }
#hud-cape .ui-header .ko-title { flex: 1; }
#hud-cape .ui-close { width: 30px; height: 30px; flex: none; }
#hud-cape .game-btn { min-height: 34px; min-width: 96px; padding: 0 14px !important; font-size: var(--ui-fs-m) !important; }
#hud-cape .game-btn:disabled { opacity: 0.45; }

.cape-clan { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 12px; margin-bottom: 8px; color: var(--ui-text-dim); }
.cape-clan:empty { display: none; }
.cape-clan-name { color: var(--ui-gold-hi); font: 600 var(--ui-fs-l)/1.3 var(--ui-font-title); }
.cape-body { display: flex; flex: 1; flex-direction: column; gap: 8px; min-height: 0; overflow-y: auto; }
.cape-main { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: flex-start; }
.cape-side { display: flex; flex: 1 1 100%; flex-direction: column; gap: 6px; min-width: 0; }
.cape-preview { display: flex; flex: none; flex-direction: column; align-items: center; gap: 6px; width: 140px; }
.cape-preview-art { position: relative; width: 136px; height: 136px; padding: 4px; }
.cape-preview-art canvas { display: block; width: 128px; height: 128px; image-rendering: auto; }
.cape-preview-name { color: var(--ui-text); text-align: center; }
.cape-mark {
	position: absolute;
	right: 4px;
	bottom: 4px;
	left: 4px;
	padding: 1px 0;
	background: rgba(0, 0, 0, 0.7);
	color: var(--ui-ok);
	font-size: var(--ui-fs-s);
	text-align: center;
}
.cape-choose { display: flex; flex: 1; flex-direction: column; gap: 4px; min-width: 0; }
.cape-label { color: var(--ui-gold); font: 600 var(--ui-fs-m)/1.3 var(--ui-font-title); letter-spacing: 0.04em; }
.cape-grid { display: grid; gap: 4px; margin-bottom: 4px; }
.cape-colors, .cape-patterns { grid-template-columns: repeat(auto-fill, 48px); }
.cape-paints { grid-template-columns: repeat(auto-fill, 32px); }
#hud-cape .cape-paint { position: relative; width: 32px; height: 32px; padding: 4px !important; border-width: 1px; }
#hud-cape .cape-paint.on { border-color: var(--ui-gold-hi); box-shadow: inset 0 0 0 1px var(--ui-gold-hi); }
.cape-paint-chip { display: block; width: 100%; height: 100%; border: 1px solid #000; }
.cape-paint-chip.none { background: linear-gradient(to top right, transparent 45%, var(--ui-danger-hi) 45% 55%, transparent 55%), #d8d0c0; }
.cape-paint-custom { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.cape-paint-label { color: var(--ui-text-dim); }
#hud-cape .cape-paint-pick { width: 36px; height: 30px; padding: 1px; border: 1px solid var(--ui-line); background: var(--ui-body); }
#hud-cape .cape-paint-hex, #hud-cape .cape-fund-input {
	box-sizing: border-box;
	min-width: 0;
	height: 30px;
	padding: 0 8px;
	border: 1px solid var(--ui-line);
	border-radius: 0;
	background: rgba(0, 0, 0, 0.6);
	color: var(--ui-text);
	font: 600 var(--ui-fs-m) var(--ui-font);
	user-select: text;
	-webkit-user-select: text;
}
#hud-cape .cape-paint-hex { width: 92px; text-transform: uppercase; }
.cape-tabs { display: flex; flex: none; gap: 4px; margin-bottom: 8px; }
.cape-tabs:empty { display: none; }
#hud-cape .cape-tab {
	flex: 1 1 0;
	padding: 7px 10px;
	border: 1px solid #3a2e1c;
	border-radius: 0;
	background: linear-gradient(#2c2216, #17110a);
	color: var(--ui-text-dim);
	font: 600 var(--ui-fs-m)/1.2 var(--ui-font);
}
#hud-cape .cape-tab.on { border-color: var(--ui-gold-hi); background: linear-gradient(#6a4e1e, #33250e); color: #fff4d0; }
.cape-clan-fund { color: var(--ui-gold); }
.cape-preview-own { display: flex; align-items: center; gap: 6px; color: var(--ui-text-dim); font-size: var(--ui-fs-s); }
.cape-preview-own canvas { width: 28px; height: 28px; flex: none; border: 1px solid var(--ui-line); }
.cape-hint { margin: 0; color: var(--ui-text-dim); font-size: var(--ui-fs-s); line-height: 1.4; }
.cape-fund { display: flex; flex-direction: column; gap: 4px; padding-top: 8px; border-top: 1px solid var(--ui-line); }
.cape-fund-give { display: flex; align-items: center; gap: 8px; }
#hud-cape .cape-fund-input { width: 140px; height: 34px; }
.cape-fund-gives { color: var(--ui-ok); }
.cape-fund-gives.bad { color: var(--ui-danger-hi); }
#hud-cape .cape-swatch { position: relative; width: 48px; height: 48px; padding: 3px !important; border-width: 1px; }
#hud-cape .cape-swatch.on { border-color: var(--ui-gold-hi); box-shadow: inset 0 0 0 1px var(--ui-gold-hi), inset 0 0 6px #000; }
.cape-swatch-art { display: block; width: 40px; height: 40px; }
.cape-dot { position: absolute; top: 2px; right: 2px; width: 7px; height: 7px; border: 1px solid #000; background: var(--ui-ok); }
.cape-facts { display: flex; flex-direction: column; gap: 2px; padding: 6px 8px; border: 1px solid var(--ui-line); background: var(--ui-body); }
.cape-fact { display: flex; justify-content: space-between; gap: 12px; }
.cape-fact > span { color: var(--ui-text-dim); }
.cape-fact > strong { color: var(--ui-gold-hi); font-weight: 600; }
.cape-fact > strong.bad { color: var(--ui-danger-hi); }
.cape-why { margin: 0; color: var(--ui-danger-hi); text-align: center; }
.cape-note { margin: 16px 8px; line-height: 1.45; text-align: center; }
.cape-footer { flex: none; justify-content: flex-end; margin-top: 8px; }

/* Phones: the whole screen; the game turns portrait phones to landscape, so this is mostly 844 x 390:
   preview, choices and facts side by side, thumb-sized swatches. */
@media (max-width: 640px), (max-height: 480px) {
	#hud-cape { top: calc(var(--sa-t) + 4px); right: calc(var(--sa-r) + 4px); bottom: calc(var(--sa-b) + 4px); left: calc(var(--sa-l) + 4px); width: auto; max-height: none; padding: 4px 10px 8px; transform: none; }
	#hud-cape .ui-close { width: 34px; height: 34px; }
	#hud-cape .game-btn { min-height: 40px; flex: 1; }
	.cape-clan { margin-bottom: 4px; }
	.cape-footer { margin-top: 6px; }
	.cape-main { flex-wrap: nowrap; justify-content: center; }
	.cape-preview { width: 112px; }
	.cape-preview-art { width: 108px; height: 108px; }
	.cape-preview-art canvas { width: 100px; height: 100px; }
	.cape-tabs { margin-bottom: 4px; }
	#hud-cape .cape-tab { min-height: 34px; }
	.cape-choose { flex: 1 1 0; min-width: 0; }
	.cape-colors, .cape-patterns { grid-template-columns: repeat(auto-fill, 44px); }
	#hud-cape .cape-swatch { width: 44px; height: 44px; }
	#hud-cape .cape-swatch .cape-swatch-art { width: 36px; height: 36px; }
	#hud-cape .cape-fund-input { flex: 1; height: 40px; }
	#hud-cape .cape-paint-hex { height: 34px; }
	.cape-side { flex: 1 1 0; min-width: 190px; max-width: 320px; }
	/* Preview fixed on the left; the choices and the facts + fund scroll each on their own. */
	.cape-body { overflow: hidden; }
	.cape-main { flex: 1; min-height: 0; align-items: stretch; }
	.cape-choose, .cape-side { max-height: 100%; overflow-y: auto; overscroll-behavior: contain; }
	.cape-fund { padding-top: 6px; }
}

/* ---- clan emblem (emblem.js): opened from the cape merchant's window ---- */
#hud-emblem {
	position: fixed;
	top: 50%;
	left: 50%;
	z-index: 7;
	display: flex;
	flex-direction: column;
	width: min(420px, calc(100% - 16px));
	max-height: calc(100% - 16px);
	padding: 8px 12px 12px;
	overflow: hidden;
	color: var(--ui-text);
	font-family: var(--ui-font);
	font-size: var(--ui-fs-m);
	pointer-events: auto;
	transform: translate(-50%, -50%);
	-webkit-font-smoothing: antialiased;
}
#hud-emblem[hidden] { display: none; }
#touch-controls:has(#hud-emblem:not([hidden])) #hud-toast { z-index: 9; }
body.desktop-hud #hud-emblem { visibility: visible; }
#hud-emblem *, #hud-emblem *::before, #hud-emblem *::after { animation: none !important; transition: none !important; }
#hud-emblem button { min-height: 0; }
#hud-emblem .ui-header { margin-bottom: 4px; }
#hud-emblem .ui-header .ko-title { flex: 1; }
#hud-emblem .ui-close { width: 30px; height: 30px; flex: none; }
#hud-emblem .game-btn { min-height: 34px; min-width: 96px; padding: 0 14px !important; font-size: var(--ui-fs-m) !important; }
#hud-emblem .game-btn:disabled { opacity: 0.45; }
.emblem-body { display: flex; flex-direction: column; gap: 8px; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.emblem-clan { color: var(--ui-gold-hi); font-family: var(--ko-serif); font-size: var(--ui-fs-l); }
.emblem-now { display: flex; align-items: center; gap: 10px; }
.emblem-pick { display: flex; align-items: center; gap: 12px; }
.emblem-side { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.emblem-slot { display: flex; align-items: center; justify-content: center; padding: 4px; flex: none; }
.emblem-big { width: 136px; height: 136px; }
.emblem-small { width: 40px; height: 40px; }
.emblem-canvas { display: block; image-rendering: pixelated; image-rendering: crisp-edges; }
.emblem-label { color: var(--ui-text-dim); }
.emblem-hint { margin: 0; color: var(--ui-text-dim); font-size: var(--ui-fs-s); line-height: 1.4; }
.emblem-facts { display: flex; flex-direction: column; gap: 2px; padding: 6px 8px; border: 1px solid var(--ui-line); background: var(--ui-body); }
.emblem-fact { display: flex; justify-content: space-between; gap: 12px; }
.emblem-fact > span { color: var(--ui-text-dim); }
.emblem-fact > strong { color: var(--ui-gold-hi); font-weight: 600; }
.emblem-fact > strong.bad { color: var(--ui-danger-hi); }
.emblem-why { margin: 0; color: var(--ui-danger-hi); }
.emblem-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

/* Kill feed (server KILL_FEED_CHAT): the killer and the victim in their nation's colour */
#hud-chat-log li.kill-feed {
	padding: 1px 4px;
	border-left: 2px solid #b8323a;
	background: linear-gradient(90deg, rgba(150, 30, 36, 0.3), transparent 85%);
	color: var(--ui-text);
}

#hud-chat-log li.kill-feed.mine {
	border-left-color: var(--ui-gold-hi);
	background: linear-gradient(90deg, rgba(200, 155, 60, 0.32), transparent 85%);
}

#hud-chat-log li.kill-feed.died {
	border-left-color: #ff4a3c;
	background: linear-gradient(90deg, rgba(190, 30, 24, 0.45), transparent 85%);
}

/* one of mine (party, clan, nation) died / killed */
#hud-chat-log li.kill-feed.lost {
	border-left-color: #ff9632;
	background: linear-gradient(90deg, rgba(200, 110, 30, 0.26), transparent 85%);
}

#hud-chat-log li.kill-feed.won {
	border-left-color: #82e178;
	background: linear-gradient(90deg, rgba(70, 150, 60, 0.24), transparent 85%);
}

#hud-chat-log li.kill-feed b { font-weight: 700; }
#hud-chat-log li.kill-feed b.karus { color: #ff6a58; }
#hud-chat-log li.kill-feed b.elmorad { color: #6eacff; }

/* the names by who they are to me (KILL_RELATIONS in hud.js) */
#hud-chat-log li.kill-feed b.rel-me { color: var(--ui-gold-hi); text-decoration: underline; text-underline-offset: 2px; }
#hud-chat-log li.kill-feed b.rel-party { color: #6ec8ff; }
#hud-chat-log li.kill-feed b.rel-clan { color: #8cf06e; }
#hud-chat-log li.kill-feed b.rel-ally { color: #b4dca0; }
#hud-chat-log li.kill-feed b.rel-enemy { color: #ff5a4a; }

.kill-feed-tag {
	margin-right: 5px;
	color: #ff8f73;
	font-size: 0.82em;
	font-weight: 700;
	letter-spacing: 0.04em;
}

.kill-feed-sep {
	margin: 0 4px;
	color: var(--ui-text-dim);
	font-style: italic;
}

.kill-feed-streak {
	margin-left: 6px;
	color: var(--ui-gold-hi);
	font-weight: 700;
}

.kill-feed-ended {
	margin-left: 6px;
	color: #c4c4c4;
	font-style: italic;
}
