body:has(.chess-window) {
	display: flex;
	flex-direction: column;
	align-items: center;
}

.content.chess-window {
	order: -1;
	width: min(754px, calc(100% - 16px));
	max-width: none;
	height: auto;
	max-height: none;
	margin: 12px 0 16px;
	color: #161616;
}

body:has(.chess-window) .wrapper { margin-top: 0; }
.chess-window .post_title { background: #00007f; }
.chess-window .post_title img { image-rendering: pixelated; }

.chess-window .tools {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 5px;
	padding: 7px 8px;
}

.chess-window .tool-outfit {
	display: inline-flex;
	align-items: center;
	gap: 5px;
	margin-left: auto;
	font-size: 13px;
}

.chess-window .tool-outfit select {
	padding: 4px 6px;
	border: 2px solid;
	border-color: #777 #fff #fff #777;
	background: #fff;
	color: #161616;
	font: inherit;
}

.chess-window .control {
	padding: 5px 10px;
	border: 0;
	background: #c0c0c0;
	font: inherit;
	box-shadow: inset 1px 1px #fff, inset -1px -1px #333, inset -2px -2px #808080;
}

.chess-window .control:active:not(:disabled) {
	box-shadow: inset 1px 1px #333, inset 2px 2px #808080, inset -1px -1px #fff;
	padding: 6px 9px 4px 11px;
}

.chess-window .control:disabled {
	color: #777;
	text-shadow: 1px 1px #fff;
}

.chess-window .chess-stage {
	display: grid;
	grid-template-columns: minmax(0, 1fr) 218px;
	gap: 12px;
	padding: 0 8px 8px;
	align-items: start;
}

.chess-window .inset {
	border: 2px solid;
	border-color: #777 #fff #fff #777;
}

.chess-window .boardframe {
	display: grid;
	grid-template-columns: 16px minmax(0, 1fr);
	grid-template-rows: auto 16px;
	gap: 2px 3px;
	padding: 6px 8px 4px 4px;
	background: #2f3b2e;
	box-shadow: inset 1px 1px #556651, inset -1px -1px #171e16;
}

.chess-window .board-ranks {
	display: grid;
	grid-template-rows: repeat(8, 1fr);
	align-items: center;
	justify-items: center;
	font: bold 11px/1 "Tahoma", "MS Sans Serif", sans-serif;
	color: #ece3c2;
	text-shadow: 1px 1px #141a13;
	user-select: none;
}

.chess-window .board-files {
	grid-column: 2;
	display: grid;
	grid-template-columns: repeat(8, 1fr);
	align-items: center;
	justify-items: center;
	font: bold 11px/1 "Tahoma", "MS Sans Serif", sans-serif;
	color: #ece3c2;
	text-shadow: 1px 1px #141a13;
	user-select: none;
}

.chess-window .board-well {
	border: 2px solid;
	border-color: #161d15 #94a48d #94a48d #161d15;
	background: #1b221a;
}

.chess-window .board {
	display: grid;
	grid-template: repeat(8, 1fr) / repeat(8, 1fr);
	aspect-ratio: 1;
	container-type: inline-size;
	touch-action: none;
	user-select: none;
	-webkit-user-select: none;
}

.chess-window .square {
	position: relative;
	display: grid;
	place-items: center;
	border: 0;
	border-radius: 0;
	padding: 0;
	min-width: 0;
	min-height: 0;
}

.chess-window .square.movable { cursor: grab; }
.chess-window.is-dragging,
.chess-window.is-dragging .square { cursor: grabbing; }

.chess-window .light {
	background: #ece3c2;
	box-shadow: inset 1px 1px rgba(255, 255, 255, 0.55), inset -1px -1px rgba(130, 120, 88, 0.22);
}

.chess-window .dark {
	background: #6c8661;
	box-shadow: inset 1px 1px rgba(255, 255, 255, 0.16), inset -1px -1px rgba(20, 32, 18, 0.25);
}

.chess-window .light.last {
	background: #dfce78;
	box-shadow: inset 0 0 0 2px #7a6620, inset 3px 3px rgba(255, 252, 224, 0.45);
}

.chess-window .dark.last {
	background: #a4ad54;
	box-shadow: inset 0 0 0 2px #51581b, inset 3px 3px rgba(244, 248, 198, 0.28);
}

.chess-window .piece {
	display: block;
	width: 88%;
	height: 88%;
	object-fit: contain;
	pointer-events: none;
	filter: drop-shadow(1px 2px 0 rgba(0, 0, 0, 0.24));
}

.chess-window .square.dragging-source .piece { opacity: 0.2; }

.chess-drag-ghost {
	position: fixed;
	left: 0;
	top: 0;
	pointer-events: none;
	z-index: 1000;
	will-change: transform;
	filter: drop-shadow(2px 5px 2px rgba(0, 0, 0, 0.35));
}

.chess-window .square:focus-visible {
	outline: 2px solid #000080;
	outline-offset: -3px;
	z-index: 1;
}

.chess-window .selected {
	background: #e2c85c;
	box-shadow: inset 0 0 0 2px #000080, inset 0 0 0 3px #fff7c2;
}

.chess-window .checked {
	background: #c95a50;
	box-shadow: inset 0 0 0 2px #6b120e, inset 0 0 0 3px #ffd6d0;
}

.chess-window .legal::after {
	content: "";
	position: absolute;
	pointer-events: none;
}

.chess-window .legal:not(.occupied)::after {
	width: 24%;
	aspect-ratio: 1;
	border-radius: 50%;
	background: rgba(20, 32, 18, 0.46);
	box-shadow: inset 1px 1px rgba(255, 255, 255, 0.45), inset -1px -1px rgba(0, 0, 0, 0.4);
}

.chess-window .legal.occupied::after {
	inset: 3px;
	border: 3px solid rgba(18, 28, 16, 0.65);
	box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.55);
	background: transparent;
}

.chess-window .square.drop-target.legal {
	box-shadow: inset 0 0 0 2px #000080, inset 0 0 0 4px #ffffff;
	z-index: 1;
}

.chess-window .sidebar { display: grid; gap: 8px; }
.chess-window .portrait {
	height: 234px;
	overflow: hidden;
	text-align: center;
	background: repeating-linear-gradient(0deg, #d8d4c3 0 1px, #e2decd 1px 4px);
}

.chess-window .portrait img {
	width: 100%;
	height: 116%;
	object-fit: contain;
	object-position: top;
	vertical-align: top;
}

.chess-window .name, .chess-window .history h2 {
	margin: 0;
	padding: 5px 7px;
	border-bottom: 1px solid #808080;
	background: #b1b1b1;
	font-size: 13px;
}

.chess-window .name { display: flex; justify-content: space-between; }
.chess-window .name span { font-weight: normal; }
.chess-window .speech {
	min-height: 48px;
	margin: 0;
	padding: 8px;
	background: #ffffdf;
	font-size: 13px;
	line-height: 1.35;
}

.chess-window .history { background: #fff; }
.chess-window .history-scroll { max-height: 155px; overflow-y: auto; }
.chess-window .history table {
	width: 100%;
	border-collapse: collapse;
	font: 12px "Courier New", monospace;
}

.chess-window .history th, .chess-window .history td { padding: 3px 7px; text-align: left; }
.chess-window .history thead { background: #efefef; }
.chess-window .history tbody tr:last-child { background: #000080; color: #fff; }

.chess-window .status {
	display: grid;
	grid-template-columns: 1fr auto auto;
	gap: 4px;
	padding: 0 4px 4px;
}

.chess-window .status span {
	padding: 4px 7px;
	border: 1px solid;
	border-color: #888 #eee #eee #888;
	font-size: 12px;
}

@media (max-width: 620px) {
	.chess-window .tool-outfit { margin-left: 0; }
	.chess-window .chess-stage { grid-template-columns: 1fr; }
	.chess-window .sidebar { grid-template-columns: 1fr 1fr; align-items: start; }
	.chess-window .portrait { height: 170px; }
}

.chess-window .piece[hidden] { display: none; }

.chess-window dialog {
	border: 2px solid;
	border-color: #fff #333 #333 #fff;
	background: #c0c0c0;
	color: #161616;
}

.chess-window dialog h2 { margin: 0 0 8px; font-size: 14px; }

.chess-window .portrait canvas {
	display: block;
	width: 100%;
	height: 100%;
}

.chess-window .portrait[data-renderer="canvas"] canvas {
	object-fit: contain;
	object-position: center bottom;
	transform-origin: center bottom;
	animation: chess-rin-sway 5s ease-in-out infinite alternate;
}

@keyframes chess-rin-sway {
	from { transform: rotate(-1deg) scale(1.015); }
	to { transform: rotate(1deg); }
}

@media (prefers-reduced-motion: reduce) {
	.chess-window .portrait[data-renderer="canvas"] canvas { animation: none; }
}

.chess-window #chess-line-rest { visibility: hidden; }
.chess-window .speech[data-mood="furious"] { background: #ffebda; font-weight: bold; }
.chess-window .speech:is([data-mood="shocked"], [data-mood="nervous"], [data-mood="cry"]) { background: #e8f4ff; }
.chess-window .control[aria-pressed="true"] {
	box-shadow: inset 1px 1px #555, inset -1px -1px #fff;
	background: #d5d5d5;
}

.chess-window .clocks { background: #fff; }
.chess-window .clock {
	display: flex;
	justify-content: space-between;
	gap: 8px;
	padding: 5px 7px;
}
.chess-window .clock + .clock { border-top: 1px solid #aaa; }
.chess-window .clock.active { background: #000080; color: #fff; }
.chess-window .clock-time { font: bold 14px "Courier New", monospace; }
.chess-window .setup-field {
	display: grid;
	grid-template-columns: 90px minmax(0, 1fr);
	align-items: center;
	gap: 8px;
	margin: 8px 0;
}
.chess-window .clocks[hidden],
.chess-window .setup-field[hidden] { display: none; }
.chess-window .setup-field select { width: 100%; font: inherit; }
.chess-window #chess-setup { width: min(340px, calc(100vw - 24px)); box-sizing: border-box; }
.chess-window #chess-time-help { margin: 6px 0 12px; font-size: 12px; }
.chess-window .setup-actions { display: flex; gap: 6px; justify-content: flex-end; }
.chess-window #chess-setup-title,
.chess-window #chess-about-title,
.chess-window #chess-promotion-title {
	padding: 4px 6px;
	background: #000080;
	color: #fff;
	font-weight: bold;
}

.chess-window #chess-promotion {
	width: min(320px, calc(100vw - 24px));
	box-sizing: border-box;
}

.chess-window .promo-choices {
	display: grid;
	grid-template-columns: repeat(4, minmax(0, 1fr));
	gap: 6px;
	margin-top: 10px;
}

.chess-window .promo-btn {
	display: grid;
	justify-items: center;
	gap: 4px;
	padding: 6px 4px;
	font-size: 12px;
}

.chess-window .promo-btn:active:not(:disabled) {
	padding: 7px 3px 5px 5px;
}

.chess-window .promo-piece {
	width: 36px;
	height: 36px;
	object-fit: contain;
	pointer-events: none;
}

.chess-window .chess-opening {
	margin: 0;
	padding: 5px 7px;
	border-bottom: 1px solid #aaa;
	background: #ffffdf;
	font-size: 12px;
	overflow-wrap: anywhere;
}

.chess-window .setup-book {
	display: flex;
	align-items: center;
	gap: 5px;
	margin-bottom: 12px;
}

.chess-window .chess-opening[hidden],
.chess-window .setup-book[hidden] { display: none; }

.chess-window .chess-info {
	width: min(380px, calc(100vw - 24px));
	box-sizing: border-box;
}

.chess-window .chess-info p { margin: 10px 0; line-height: 1.4; }
.chess-window .chess-info a { color: #000080; text-decoration: underline; }
