/* v56.77 shared player identity: the name is edited once from the select screen and reused by chat and rooms. */
.player-identity {
	display: inline-flex;
	align-items: center;
	min-height: 44px;
	max-width: 100%;
	margin: 2px 0 0;
	padding: 3px 10px;
	border: 1px solid #6d9a94;
	border-radius: 10px;
	background: #0c2733ee;
	color: #f6f0d6;
	font: 800 12px/1.25 system-ui;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	touch-action: manipulation;
}
.player-identity[aria-expanded='true'] { border-color: #ffe397; color: #ffe397; }
.player-identity-editor {
	display: flex;
	align-items: center;
	gap: 6px;
	max-width: 100%;
	margin-top: 3px;
}
.player-identity-editor.hidden { display: none; }
.player-identity-editor input {
	box-sizing: border-box;
	width: min(180px, 48vw);
	min-height: 38px;
	padding: 5px 9px;
	border: 1px solid #6d9a94;
	border-radius: 8px;
	background: #06151d;
	color: #f6f0d6;
	font: 600 16px system-ui;
}
.player-identity-editor button {
	box-sizing: border-box;
	width: auto;
	height: 38px;
	min-height: 38px;
	margin: 0;
	padding: 5px 10px;
	font-size: 12px;
	line-height: 1.2;
	white-space: nowrap;
}
.player-identity-editor input:focus { border-color: #ffe397; outline: none; }

/* v56.49 聊天室 (lobbychat.js): a pill at the end of the select screen's 累計 … 場 row (v56.52: as tall as its text, nothing moves), and a sheet at the bottom of the screen with everybody's
   lines and a box to type in. The box is 16 px (no zoom on an iPhone); every control is at least 44 px. On a phone the sheet is the whole screen,
   fitted by lobbychat.js to the part the keyboard leaves, with the box at the bottom and the newest line just over it. */
#gchat-open {
	position: relative;
	display: inline-flex;
	align-items: center;
	gap: 2px;
	min-height: 32px;
	margin: 4px 0 0;
	padding: 4px 12px;
	border: 1px solid #6d9a94;
	border-radius: 999px;
	background: #0c2733ee;
	color: #f6f0d6;
	font: 800 13px system-ui;
	white-space: nowrap;
	pointer-events: auto;
}
#gchat-open.hidden {
	display: none;
}
/* On the 累計 … 場 row (v56.52): exactly as tall as the row's text (its font and line height, the outline an inset shadow, no padding above or
   below), so the row and everything under it stay where they were before the pill came; the touch area (::after) takes no room. It gives up
   width before the count does, and the row never grows past the screen. */
#played-line {
	max-width: 100%;
}
#played-line #gchat-open,
#played-line #gchat-open[aria-expanded='true'] {
	/* A plain inline box, not a flex one, so a label too long for the row (觀戰 may be on it too) ends in … and not at the screen's edge. */
	display: inline-block;
	flex: 0 1 auto;
	white-space: nowrap;
	min-width: 0;
	min-height: 0;
	margin: 0 0 0 4px;
	padding: 0 8px;
	overflow: hidden;
	border: 0;
	box-shadow: inset 0 0 0 1px #6d9a94;
	font: inherit;
	/* Less than the row's own line (a 💬 has taller glyph boxes than the text beside it and would grow the row by 2 px otherwise). */
	line-height: 1.25;
	text-overflow: ellipsis;
}
#played-line #gchat-open[aria-expanded='true'] {
	box-shadow: inset 0 0 0 1px #ffe397;
}
/* A 44 px touch target around the 32 px pill. */
#gchat-open::after {
	content: '';
	position: absolute;
	inset: -6px -2px;
}
#gchat-open .c {
	color: #9bffe3;
	font-weight: 700;
}
#gchat-open[aria-expanded='true'] {
	border: 2px solid #ffe397;
	background: #29494b;
}
#gchat-open .n {
	position: absolute;
	top: -6px;
	right: -6px;
	display: none;
	min-width: 18px;
	height: 18px;
	padding: 0 4px;
	box-sizing: border-box;
	border-radius: 999px;
	background: #ffcf4d;
	color: #07171f;
	font: 900 11px/18px system-ui;
}
#gchat-open.new .n {
	display: block;
}
#gchat {
	position: fixed;
	z-index: 30;
	left: 50%;
	bottom: max(12px, env(safe-area-inset-bottom));
	display: flex;
	flex-direction: column;
	gap: 6px;
	box-sizing: border-box;
	width: min(calc(100% - 24px), 480px);
	height: min(460px, calc(100dvh - 96px));
	padding: 8px 10px 10px;
	transform: translateX(-50%);
	border: 1px solid #6d9a94;
	border-radius: 16px;
	background: #081d26f7;
	box-shadow: 0 10px 30px #000a;
	touch-action: pan-y;
	text-align: left;
}
#gchat.hidden {
	display: none;
}
#gchat .gchat-head {
	display: flex;
	align-items: center;
	gap: 8px;
}
#gchat .gchat-head strong {
	flex: 1;
	color: #ffe397;
	font-size: 15px;
}
#gchat .gchat-close {
	min-width: 44px;
	min-height: 44px;
	border: 1px solid #6d9a94;
	border-radius: 10px;
	background: #12333c;
	color: #e1efe4;
	font: 700 15px system-ui;
}
#gchat-log {
	display: flex;
	flex-direction: column;
	flex: 1 1 auto;
	min-height: 0;
	margin: 0;
	padding: 4px 8px;
	overflow-y: auto;
	overscroll-behavior: contain;
	list-style: none;
	border-radius: 10px;
	background: #06151d99;
	font-size: 14px;
	line-height: 1.45;
	overflow-wrap: anywhere;
	user-select: text;
	-webkit-user-select: text;
}
#gchat-log li {
	padding: 3px 0;
	color: #f6f0d6;
}
#gchat-log li b {
	margin-right: 6px;
	color: #9bffe3;
	white-space: nowrap;
}
#gchat-log li.me b {
	color: #ffcf4d;
}
#gchat-log li time {
	margin-left: 6px;
	white-space: nowrap;
	color: #6f8f8e;
	font-size: 11px;
}
#gchat-log .gchat-quiet {
	padding-top: 16px;
	color: #86a7a6;
	font-size: 13px;
	text-align: center;
}
#gchat .gchat-say {
	display: flex;
	flex: none;
	gap: 6px;
}
#gchat .gchat-say input {
	flex: 1;
	min-width: 0;
	min-height: 44px;
	padding: 6px 12px;
	box-sizing: border-box;
	border: 1px solid #6d9a94;
	border-radius: 12px;
	background: #06151d;
	color: #f6f0d6;
	font: 600 16px system-ui;
	user-select: text;
	-webkit-user-select: text;
}
#gchat .gchat-say input:focus {
	border-color: #ffe397;
	outline: none;
}
#gchat .gchat-say button {
	flex: none;
	min-width: 60px;
	min-height: 44px;
	border: 1px solid #ffcf4d;
	border-radius: 12px;
	background: #ffcf4d;
	color: #07171f;
	font: 900 15px system-ui;
}
#gchat .gchat-note {
	flex: none;
	margin: 0;
	color: #ffcf4d;
	font-size: 13px;
	text-align: center;
}
#gchat .gchat-note.hidden,
#gchat .gchat-human:empty {
	display: none;
}
#gchat .gchat-human {
	display: flex;
	flex: none;
	justify-content: center;
}
/* The newest line by the box: the list is pushed to the bottom of its space until it fills it. */
#gchat-log li:first-child {
	margin-top: auto;
}
#gchat-log li b small {
	margin-left: 2px;
	color: #5f8584;
	font-size: 10px;
	font-weight: 700;
}
#gchat-log li {
	position: relative;
	padding-right: 36px;
}
#gchat-log .gchat-flag {
	position: absolute;
	top: 50%;
	right: 0;
	min-width: 32px;
	min-height: 32px;
	padding: 0 4px;
	transform: translateY(-50%);
	border: 0;
	background: none;
	color: #6f8f8e;
	font-size: 13px;
}
#gchat-log .gchat-flag:disabled {
	color: #4e6766;
	font-size: 11px;
}
#gchat .gchat-me {
	appearance: none;
	min-width: 0;
	width: 100%;
	margin: 0;
	padding: 8px 4px;
	border: 0;
	background: transparent;
	max-width: 100%;
	overflow: hidden;
	color: #9bb8b5;
	font: 700 12px system-ui;
	text-align: right;
	white-space: nowrap;
	text-overflow: ellipsis;
}
#gchat .gchat-me-wrap {
	position: relative;
	flex: 1 1 0;
	min-width: 0;
	width: 0;
}
#gchat .gchat-me:hover,
#gchat .gchat-me[aria-expanded='true'] {
	color: #ffe397;
}
#gchat .gchat-me-editor {
	position: absolute;
	top: calc(100% + 4px);
	right: 0;
	z-index: 2;
	display: grid;
	grid-template-columns: minmax(120px, 1fr) auto auto;
	align-items: center;
	gap: 5px;
	min-width: min(330px, calc(100vw - 40px));
	padding: 6px;
	border: 1px solid #6d9a94;
	border-radius: 10px;
	background: #081d26f7;
	box-shadow: 0 8px 20px #000a;
}
#gchat .gchat-me-editor.hidden { display: none; }
#gchat .gchat-me-editor input {
	box-sizing: border-box;
	width: 100%;
	min-width: 0;
	height: 38px;
	min-height: 38px;
	max-height: 38px;
	min-height: 38px;
	padding: 5px 9px;
	border: 1px solid #6d9a94;
	border-radius: 8px;
	background: #06151d;
	color: #f6f0d6;
	font: 600 16px system-ui;
}
#gchat .gchat-me-editor button {
	box-sizing: border-box;
	appearance: none;
	margin: 0 !important;
	width: 52px;
	min-width: 52px;
	height: 38px !important;
	min-height: 38px !important;
	max-height: 38px;
	padding: 5px 9px;
	font-size: 13px;
	line-height: 1.2;
	border: 1px solid #6d9a94 !important;
	border-radius: 8px !important;
	background: #12333c !important;
	color: #e1efe4 !important;
	box-shadow: none !important;
	filter: none !important;
	transform: none !important;
	white-space: nowrap;
}
#gchat .gchat-me-editor .primary {
	border-color: #6d9a94 !important;
	background: #8ef4cb !important;
	color: #06151d !important;
	font-weight: 800;
}
/* While it is open the page behind does not scroll, so iOS has only the sheet to move. */
body.gchat-open {
	overflow: hidden;
	overscroll-behavior: none;
}
/* A phone (or a short landscape one): the whole screen, inside the safe area; lobbychat.js sets top and height to the visual viewport. */
@media (max-width: 600px), (max-height: 500px) {
	#gchat {
		top: 0;
		bottom: auto;
		left: 0;
		width: 100%;
		height: 100dvh;
		padding: max(8px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom))
			max(10px, env(safe-area-inset-left));
		transform: none;
		border: 0;
		border-radius: 0;
		box-shadow: none;
	}
}
/* v56.58 (lobbychat.js place()): on a phone the 聊天室 plate takes 單人's place beside 線上對戰, drawn as 單人's jade plate (select.css): the word
   alone on one line (the owner: no subtitle), and the unread count inside the plate's edge (the mask clips anything outside it); the 累計 row's pill goes. */
#gchat-act {
	display: none;
}
#select.gchat-swap #team-start,
#select.gchat-swap #played-line #gchat-open {
	display: none;
}
#select.gchat-swap #gchat-act {
	position: relative;
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
	gap: 3px;
	width: 100%;
	min-width: 0;
	min-height: 44px;
	margin: 0;
	padding: 8px 13%;
	border: 0;
	border-radius: 0;
	background: url(ui/btn-jade.webp) center/100% 100% no-repeat;
	-webkit-mask: url(ui/btn-jade.webp) center/100% 100% no-repeat;
	mask: url(ui/btn-jade.webp) center/100% 100% no-repeat;
	color: #0c1f33;
	font-size: 18px;
	font-weight: 900;
	font-style: italic;
	letter-spacing: 0.12em;
	line-height: 1.3;
	text-shadow: 0 1px 0 #ffffff99;
}
#select.gchat-swap #gchat-act:active {
	transform: scale(0.97);
}
#gchat-act .n {
	position: absolute;
	top: 8px;
	right: 15%;
	display: none;
	min-width: 18px;
	height: 18px;
	padding: 0 4px;
	box-sizing: border-box;
	border-radius: 999px;
	background: #0c1f33;
	color: #ffcf4d;
	font: 900 11px/18px system-ui;
	letter-spacing: 0;
	text-shadow: none;
}
#gchat-act.new .n {
	display: block;
}
/* v56.58: on a wide screen a column docked on the right, the whole height, as a chat app's side panel; the select screen (and any sheet over it)
   narrows beside it instead of going under it. It goes when the select screen does (說明書, a match). Its pill on the 累計 row shows only while ✕ has folded it. */
:root {
	--gchat-w: clamp(320px, 25vw, 400px);
}
body.gchat-dock #app > .overlay {
	right: var(--gchat-w);
}
body.gchat-dock #played-line #gchat-open {
	display: none;
}
#gchat.dock {
	top: 0;
	right: 0;
	bottom: 0;
	left: auto;
	width: var(--gchat-w);
	height: auto;
	gap: 8px;
	padding: 18px 16px max(16px, env(safe-area-inset-bottom));
	transform: none;
	border: 0;
	border-left: 1px solid #e8c46a55;
	border-radius: 0;
	background: linear-gradient(180deg, #0a2430, #06151d);
	box-shadow: -10px 0 28px #0007;
	touch-action: auto;
}
#gchat.dock .gchat-head {
	padding-bottom: 10px;
	background: linear-gradient(90deg, transparent, #e8c46a66 20%, #e8c46a66 80%, transparent) bottom/100% 1px no-repeat;
}
#gchat.dock .gchat-head strong {
	font-size: 18px;
	letter-spacing: 0.08em;
}
#gchat.dock #gchat-log {
	padding: 6px 10px;
	font-size: 15px;
}

/* The identity editor shares the room width. Keep the input flexible and the actions readable on phones. */
@media (max-width: 899px) and (orientation: portrait) {
	#room-identity .player-identity-editor {
		display: grid;
		grid-template-columns: minmax(0, 1fr) auto auto;
		width: 100%;
		gap: 6px;
		margin-top: 0;
	}
	#room-identity .player-identity-editor input {
		width: 100%;
		min-width: 0;
	}
	#room-identity .player-identity-editor button {
		width: 52px;
		min-width: 52px;
		white-space: nowrap;
	}
}
