:root {
	--page-bg: #101614;
	--panel-bg: rgba(25, 34, 31, 0.94);
	--panel-border: rgba(255, 255, 255, 0.08);
	--frame-dark: #291d15;
	--frame-mid: #5a3e29;
	--frame-light: #856344;
	--square-light: #e8e0cf;
	--square-dark: #71816b;
	--square-light-hover: #f2ead8;
	--square-dark-hover: #7f9078;
	--text-main: #f4efe5;
	--text-muted: #aab4ae;
	--accent: #d4ad62;
	--accent-light: #f0d38c;
	--danger: #d66868;
	--shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.46);
	--shadow-md: 0 10px 28px rgba(0, 0, 0, 0.3);
	--radius-lg: 16px;
	--radius-md: 10px;
	--font-ui: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
		"Segoe UI", sans-serif;
}

* {
	box-sizing: border-box;
}

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

body {
	color: var(--text-main);
	font-family: var(--font-ui);
	background:
		radial-gradient(circle at 50% 42%, rgba(99, 124, 111, 0.18), transparent 42%),
		linear-gradient(145deg, #18211e 0%, var(--page-bg) 58%, #0b100e 100%);
}

button,
input {
	font: inherit;
}

button:focus-visible,
input:focus-visible {
	outline: 3px solid rgba(240, 211, 140, 0.72);
	outline-offset: 2px;
}

.pnlApp {
	width: 100%;
	height: 100%;
	display: flex;
	flex-direction: row;
	align-items: center;
	justify-content: center;
	gap: clamp(12px, 2vw, 30px);
	padding: clamp(10px, 1.5vw, 24px);
	background:
		linear-gradient(rgba(255, 255, 255, 0.018) 1px, transparent 1px),
		linear-gradient(90deg, rgba(255, 255, 255, 0.018) 1px, transparent 1px);
	background-size: 32px 32px;
}

/* ===========================
   BOARD AND COORDINATES
   =========================== */

.board {
	position: relative;
	display: flex;
	flex: 0 1 auto;
	align-items: center;
	justify-content: center;
	aspect-ratio: 1 / 1;
	filter: drop-shadow(0 28px 30px rgba(0, 0, 0, 0.34));
}

.boardFrame {
	--coordSize: clamp(20px, 3.2vmin, 28px);
	position: relative;
	display: grid;
	grid-template-columns: var(--coordSize) minmax(0, 1fr) var(--coordSize);
	grid-template-rows: var(--coordSize) minmax(0, 1fr) var(--coordSize);
	width: 100%;
	height: 100%;
	overflow: hidden;
	border: 2px solid #1d140f;
	border-radius: 9px;
	background:
		linear-gradient(135deg, rgba(255, 255, 255, 0.09), transparent 36%),
		linear-gradient(120deg, var(--frame-light), var(--frame-mid) 46%, var(--frame-dark));
	box-shadow:
		inset 0 0 0 2px rgba(255, 255, 255, 0.08),
		inset 0 0 20px rgba(0, 0, 0, 0.34),
		var(--shadow-lg);
}

.boardFrame::after {
	content: "";
	position: absolute;
	inset: var(--coordSize);
	z-index: 2;
	border: 2px solid rgba(28, 19, 13, 0.72);
	box-shadow:
		inset 0 0 0 1px rgba(255, 255, 255, 0.12),
		0 0 0 1px rgba(255, 255, 255, 0.06);
	pointer-events: none;
}

.coordFiles {
	display: grid;
	grid-template-columns: repeat(8, 1fr);
	user-select: none;
}

.coordRanks {
	display: grid;
	grid-template-rows: repeat(8, 1fr);
	user-select: none;
}

.coordCell {
	display: flex;
	align-items: center;
	justify-content: center;
	color: #f5e8cc;
	font-family: Georgia, "Times New Roman", serif;
	font-size: clamp(11px, 1.65vmin, 15px);
	font-weight: 700;
	line-height: 1;
	text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
	background: transparent;
}

.rot180 {
	transform: rotate(180deg);
}

.coordTop {
	grid-column: 2;
	grid-row: 1;
}

.coordBottom {
	grid-column: 2;
	grid-row: 3;
}

.coordLeft {
	grid-column: 1;
	grid-row: 2;
}

.coordRight {
	grid-column: 3;
	grid-row: 2;
}

.corner {
	background: rgba(27, 18, 12, 0.16);
}

.tblBoard {
	grid-column: 2;
	grid-row: 2;
	width: 100%;
	height: 100%;
	border-spacing: 0;
	border-collapse: collapse;
	table-layout: fixed;
	align-self: stretch;
	justify-self: stretch;
}

.tblBoard tr {
	display: table-row;
}

.tblBoard td {
	position: relative;
	padding: 0;
	border: 0;
	aspect-ratio: 1 / 1;
	cursor: pointer;
	transition:
		background-color 130ms ease,
		filter 130ms ease;
	-webkit-tap-highlight-color: transparent;
}

.tblBoard td:hover {
	filter: brightness(1.055);
}

.squareContent {
	position: absolute;
	inset: 0;
	z-index: 1;
	display: flex;
	align-items: center;
	justify-content: center;
}

.pieceImg {
	width: 87%;
	height: 87%;
	object-fit: contain;
	user-select: none;
	pointer-events: none;
	filter: drop-shadow(0 5px 3px rgba(0, 0, 0, 0.24));
	transition:
		transform 150ms ease,
		filter 150ms ease;
}

.square:hover .pieceImg {
	transform: translateY(-1px);
	filter: drop-shadow(0 7px 4px rgba(0, 0, 0, 0.28));
}

/* Black pieces face the player sitting across the tablet, so they're flipped
   right-side up for that seat. translateY is negated on hover since it now
   runs in the rotated piece's own (flipped) coordinate space. */
.pieceImg.pieceBlack {
	transform: rotate(180deg);
}

.square:hover .pieceImg.pieceBlack {
	transform: rotate(180deg) translateY(1px);
}

.black {
	background-color: var(--square-dark);
}

.white {
	background-color: var(--square-light);
}

.black:hover {
	background-color: var(--square-dark-hover);
}

.white:hover {
	background-color: var(--square-light-hover);
}

/* Selection and legal-move indicators */

.square.selected {
	z-index: 1;
	box-shadow:
		inset 0 0 0 4px var(--accent-light),
		inset 0 0 18px rgba(240, 211, 140, 0.42);
}

.square.selected::before {
	content: "";
	position: absolute;
	inset: 8%;
	z-index: 3;
	border: 1px solid rgba(78, 54, 24, 0.55);
	border-radius: 4px;
	pointer-events: none;
}

.square.moveTarget:not(.captureTarget)::after {
	content: "";
	position: absolute;
	top: 50%;
	left: 50%;
	z-index: 4;
	width: 24%;
	height: 24%;
	border: 2px solid rgba(255, 255, 255, 0.55);
	border-radius: 50%;
	background: rgba(46, 75, 61, 0.66);
	box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
	transform: translate(-50%, -50%);
	pointer-events: none;
}

.square.captureTarget::after {
	content: "";
	position: absolute;
	inset: 7%;
	z-index: 4;
	border: clamp(3px, 0.55vmin, 5px) solid rgba(158, 52, 52, 0.78);
	border-radius: 50%;
	box-shadow:
		inset 0 0 0 2px rgba(255, 255, 255, 0.22),
		0 2px 8px rgba(0, 0, 0, 0.26);
	pointer-events: none;
}

.square.inCheck::before {
	content: "";
	position: absolute;
	inset: 0;
	background: radial-gradient(
		circle,
		rgba(255, 90, 90, 0.95) 0%,
		rgba(190, 40, 40, 0.7) 55%,
		rgba(190, 40, 40, 0) 100%
	);
	pointer-events: none;
}

/* ===========================
   PLAYER SIDE PANELS
   =========================== */

.columnLeft,
.columnRight {
	position: relative;
	z-index: 32;
	display: flex;
	flex: 1 1 180px;
	width: clamp(140px, 16vw, 240px);
	min-width: 130px;
	max-width: 260px;
	height: min(92vh, 780px);
	height: min(92svh, 780px);
	min-height: 0;
	overflow: visible;
	border: 1px solid var(--panel-border);
	border-radius: var(--radius-lg);
	background:
		linear-gradient(145deg, rgba(255, 255, 255, 0.045), transparent 35%),
		var(--panel-bg);
	box-shadow: var(--shadow-md);
}

.columnLeft {
	flex-direction: column-reverse;
	justify-content: flex-end;
}

.columnRight {
	flex-direction: column;
	transform: rotate(180deg);
}

.notes {
	flex: 1 1 auto;
	min-height: 0;
	margin: 10px;
	overflow-x: hidden;
	overflow-y: auto;
	border: 1px solid rgba(255, 255, 255, 0.065);
	border-radius: var(--radius-md);
	background: rgba(4, 8, 6, 0.22);
	scrollbar-color: rgba(212, 173, 98, 0.48) transparent;
	scrollbar-width: thin;
}

.notes::-webkit-scrollbar {
	width: 7px;
}

.notes::-webkit-scrollbar-thumb {
	border-radius: 10px;
	background: rgba(212, 173, 98, 0.48);
}

.moves {
	margin: 0;
	padding: 12px 14px;
}

.moveRow {
	min-height: 27px;
	padding: 4px 6px;
	border-bottom: 1px solid rgba(255, 255, 255, 0.055);
	color: #dbe2dd;
	font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
	font-size: clamp(13px, 1.35vw, 17px);
	line-height: 1.35;
	font-variant-numeric: tabular-nums;
}

.moveRow:last-child {
	border-bottom: 0;
	color: var(--accent-light);
}

.clock {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 10px;
	width: 100%;
	min-height: 62px;
	margin: 10px;
	padding: 10px 14px;
	border: 1px solid rgba(255, 255, 255, 0.12);
	border-radius: 12px;
	color: #f1f4f2;
	font-family: inherit;
	font-size: clamp(24px, 3vw, 42px);
	font-weight: 680;
	font-variant-numeric: tabular-nums;
	letter-spacing: 0.045em;
	line-height: 1;
	text-shadow: 0 2px 4px rgba(0, 0, 0, 0.36);
	background:
		linear-gradient(180deg, rgba(255, 255, 255, 0.055), transparent),
		#202a27;
	box-shadow:
		inset 0 1px 0 rgba(255, 255, 255, 0.08),
		0 5px 14px rgba(0, 0, 0, 0.22);
	-webkit-appearance: none;
	appearance: none;
	user-select: none;
	cursor: pointer;
	transition:
		border-color 160ms ease,
		background-color 160ms ease,
		box-shadow 160ms ease,
		transform 160ms ease;
}

/* The clock's own pause glyph — muted so it doesn't compete with the time,
   but always present as a hint that the whole clock is tappable. */
.clockPauseIcon {
	font-size: 0.4em;
	opacity: 0.55;
}

.clock:hover .clockPauseIcon {
	opacity: 0.85;
}

.clock.active .clockPauseIcon {
	opacity: 0.6;
}

.clock.active {
	border-color: rgba(240, 211, 140, 0.68);
	color: #231a0c;
	text-shadow: none;
	background:
		linear-gradient(180deg, rgba(255, 255, 255, 0.34), transparent 44%),
		linear-gradient(135deg, var(--accent-light), var(--accent));
	box-shadow:
		inset 0 1px 0 rgba(255, 255, 255, 0.46),
		0 0 0 3px rgba(212, 173, 98, 0.16),
		0 8px 22px rgba(0, 0, 0, 0.28);
	transform: translateY(-1px);
}

/* ===========================
   CONTROLS AND MENUS
   =========================== */

.menuAnchor {
	position: relative;
	display: flex;
	flex-direction: column;
	align-items: center;
	padding: 0 10px 2px;
}

/* The hamburger icon and the captured-pieces tray share one button — tapping
   anywhere across it (icon or pieces) opens the options menu. */
.menuBar {
	display: flex;
	align-items: center;
	width: 100%;
	min-height: 42px;
	padding: 8px 12px;
	gap: 8px;
	border: 1px solid rgba(255, 255, 255, 0.11);
	border-radius: 9px;
	color: #e8edea;
	font-family: inherit;
	background:
		linear-gradient(180deg, rgba(255, 255, 255, 0.05), transparent),
		#2a3531;
	box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
	-webkit-appearance: none;
	appearance: none;
	cursor: pointer;
	transition:
		background-color 140ms ease,
		border-color 140ms ease,
		transform 140ms ease;
}

.menuBar:hover {
	border-color: rgba(240, 211, 140, 0.46);
	background-color: #35433e;
	transform: translateY(-1px);
}

.menuBar:active {
	transform: translateY(0);
}

.hamburgerIcon {
	flex: 0 0 auto;
	font-size: 17px;
	line-height: 1;
}

.capturedPieces {
	display: flex;
	flex: 1 1 auto;
	flex-wrap: wrap;
	align-items: center;
	gap: 3px;
	min-height: 20px;
}

.capturedPieceImg {
	width: 20px;
	height: 20px;
	object-fit: contain;
	filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.4));
	pointer-events: none;
}

.actionsMenu {
	position: absolute;
	top: calc(100% + 7px);
	left: 10px;
	right: 10px;
	z-index: 31;
	display: flex;
	flex-direction: column;
	min-width: 150px;
	overflow: hidden;
	border: 1px solid rgba(255, 255, 255, 0.12);
	border-radius: 11px;
	background: #26312d;
	box-shadow: 0 16px 32px rgba(0, 0, 0, 0.42);
}

.menuItem {
	padding: 12px 14px;
	border: 0;
	border-bottom: 1px solid rgba(255, 255, 255, 0.07);
	color: #eef2ef;
	font-weight: 650;
	text-align: left;
	background: transparent;
	cursor: pointer;
	transition:
		color 120ms ease,
		background-color 120ms ease;
}

.menuItem:last-child {
	border-bottom: 0;
}

.menuItem:hover {
	color: var(--accent-light);
	background: rgba(255, 255, 255, 0.065);
}

.menuBackdrop {
	position: fixed;
	inset: 0;
	z-index: 30;
	background: transparent;
}

/* ===========================
   OVERLAYS AND DIALOGS
   =========================== */

.pauseOverlay,
.modalOverlay {
	position: fixed;
	inset: 0;
	z-index: 50;
	display: flex;
	align-items: center;
	justify-content: center;
	-webkit-backdrop-filter: blur(8px);
}

.pauseOverlay {
	flex-direction: column;
	gap: 18px;
	color: var(--text-main);
	background: rgba(8, 12, 10, 0.82);
	cursor: pointer;
}

.pauseIconWrap {
	position: relative;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 132px;
	height: 132px;
	border: 1px solid rgba(240, 211, 140, 0.36);
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.045);
	box-shadow: 0 16px 36px rgba(0, 0, 0, 0.32);
}

.pauseClockGlyph {
	font-size: 78px;
	line-height: 1;
	filter: grayscale(1) brightness(2.2);
}

.pauseIconWrap::after {
	content: "";
	position: absolute;
	top: 50%;
	left: 12%;
	right: 12%;
	height: 8px;
	border-radius: 10px;
	background: var(--danger);
	box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
	transform: translateY(-50%) rotate(-45deg);
}

.pauseHint {
	padding: 0 20px;
	color: #f1eee7;
	font-size: clamp(15px, 2vw, 19px);
	font-weight: 650;
	letter-spacing: 0.02em;
	text-align: center;
}

.modalOverlay {
	padding: 18px;
	background: rgba(7, 11, 9, 0.7);
}

/* Lets a dialog be read right-side up by the player sitting at the rotated
   (black) side of the tablet, regardless of the overlay's own orientation. */
.modalBox.rotated {
	transform: rotate(180deg);
}

.modalBox {
	width: min(380px, 100%);
	max-height: calc(100svh - 36px);
	padding: 24px;
	overflow-y: auto;
	border: 1px solid rgba(255, 255, 255, 0.12);
	border-radius: 16px;
	color: var(--text-main);
	background:
		linear-gradient(145deg, rgba(255, 255, 255, 0.055), transparent 40%),
		#202b27;
	box-shadow:
		inset 0 1px 0 rgba(255, 255, 255, 0.08),
		0 24px 70px rgba(0, 0, 0, 0.52);
}

.modalBox h2 {
	margin: 0 0 10px;
	color: #fffaf0;
	font-family: Georgia, "Times New Roman", serif;
	font-size: 25px;
	font-weight: 600;
	letter-spacing: 0.01em;
}

.modalBox p {
	margin: 0;
	color: #c8d1cc;
	line-height: 1.55;
}

.modalBox .modalWarning {
	color: #f09a9a;
	font-weight: 650;
}

.timeOptions {
	display: flex;
	flex-direction: column;
	gap: 7px;
	margin: 18px 0;
}

.timeOption {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 8px 11px;
	border: 1px solid rgba(255, 255, 255, 0.075);
	border-radius: 9px;
	color: #e5eae7;
	background: rgba(0, 0, 0, 0.12);
	cursor: pointer;
	transition:
		border-color 130ms ease,
		background-color 130ms ease;
}

.timeOption:hover {
	border-color: rgba(240, 211, 140, 0.38);
	background: rgba(255, 255, 255, 0.045);
}

.timeOption input {
	width: 17px;
	height: 17px;
	margin: 0;
	accent-color: var(--accent);
}

.modalActions {
	display: flex;
	justify-content: flex-end;
	gap: 10px;
	margin-top: 20px;
}

.btnPrimary,
.btnSecondary {
	min-height: 42px;
	padding: 9px 16px;
	border-radius: 9px;
	font-weight: 700;
	cursor: pointer;
	transition:
		border-color 140ms ease,
		background-color 140ms ease,
		transform 140ms ease,
		box-shadow 140ms ease;
}

.btnPrimary {
	border: 1px solid rgba(255, 255, 255, 0.2);
	color: #241b0d;
	background: linear-gradient(135deg, var(--accent-light), var(--accent));
	box-shadow: 0 5px 14px rgba(0, 0, 0, 0.24);
}

.btnSecondary {
	border: 1px solid rgba(255, 255, 255, 0.12);
	color: #e5eae7;
	background: #303b37;
}

.btnPrimary:hover,
.btnSecondary:hover {
	transform: translateY(-1px);
}

.btnPrimary:hover {
	box-shadow: 0 7px 18px rgba(0, 0, 0, 0.3);
}

.btnSecondary:hover {
	border-color: rgba(240, 211, 140, 0.34);
	background: #3a4742;
}

.btnPrimary:active,
.btnSecondary:active {
	transform: translateY(0);
}

/* ===========================
   PORTRAIT LAYOUT
   =========================== */

@media (orientation: portrait) {
	html,
	body {
		overflow: auto;
	}

	/* Grid instead of a stacked flex column: the top/bottom bars (white/black)
	   size to their own content, and the board's row (minmax(0, 1fr)) claims
	   whatever height is left over. That leftover is computed from the bars'
	   *actual* rendered height, not a fixed guess, so the board is always the
	   largest square that fits and never gets pushed off screen as the move
	   list grows. */
	.pnlApp {
		display: grid;
		grid-template-columns: 1fr;
		grid-template-rows: auto minmax(0, 1fr) auto;
		height: 100vh;
		height: 100svh;
		gap: 8px;
		padding: 8px;
		overflow-y: auto;
	}

	.columnLeft,
	.columnRight {
		width: 100%;
		max-width: none;
		min-width: 0;
		height: auto;
		border-radius: 13px;
	}

	.notes {
		max-height: 12svh;
		min-height: 40px;
	}

	.board {
		width: auto;
		height: 100%;
		max-width: 100%;
		max-height: 100%;
		min-height: 0;
		justify-self: center;
		align-self: center;
		aspect-ratio: 1 / 1;
	}

	.clock {
		min-height: 46px;
		font-size: clamp(20px, 6.5vw, 32px);
	}

	.moveRow {
		font-size: 13px;
	}
}

/* ===========================
   LANDSCAPE LAYOUT
   =========================== */

@media (orientation: landscape) {
	html,
	body {
		/* Safety net: svh sizing below should already fit, but if some
		   device/browser-chrome combination still ends up taller than the
		   visible area, scroll instead of silently clipping the clocks. */
		overflow: auto;
	}

	.pnlApp {
		flex-direction: row;
		align-items: center;
		justify-content: center;
		overflow-y: auto;
	}

	.board {
		/* svh (small viewport height) instead of vh: on phones/tablets the
		   browser's address bar can hide the bottom slice of a plain vh-sized
		   layout — svh always accounts for the chrome being visible, so the
		   board and clocks stay fully on screen. vh kept first as a fallback
		   for browsers that don't understand svh. */
		width: min(94vh, calc(100vw - 310px));
		width: min(94svh, calc(100vw - 310px));
		height: min(94vh, calc(100vw - 310px));
		height: min(94svh, calc(100vw - 310px));
		max-width: 760px;
		max-height: 760px;
	}
}

@media (orientation: landscape) and (max-height: 520px) {
	.pnlApp {
		gap: 8px;
		padding: 6px;
	}

	.board {
		width: min(97vh, calc(100vw - 270px));
		width: min(97svh, calc(100vw - 270px));
		height: min(97vh, calc(100vw - 270px));
		height: min(97svh, calc(100vw - 270px));
	}

	.columnLeft,
	.columnRight {
		width: 120px;
		min-width: 120px;
		height: 97vh;
		height: 97svh;
		border-radius: 10px;
	}

	.clock {
		min-height: 46px;
		margin: 6px;
		padding: 7px 8px;
		font-size: clamp(20px, 4.8vh, 28px);
		font-size: clamp(20px, 4.8svh, 28px);
	}

	.menuAnchor {
		padding: 0 6px;
	}

	.menuBar {
		min-height: 36px;
		padding: 6px 8px;
	}

	.capturedPieceImg {
		width: 16px;
		height: 16px;
	}

	.notes {
		margin: 6px;
	}
}

@media (max-width: 620px) and (orientation: landscape) {
	.columnLeft,
	.columnRight {
		width: 104px;
		min-width: 104px;
	}

	.board {
		width: min(97vh, calc(100vw - 228px));
		width: min(97svh, calc(100vw - 228px));
		height: min(97vh, calc(100vw - 228px));
		height: min(97svh, calc(100vw - 228px));
	}

	.moves {
		padding: 7px;
	}

	.moveRow {
		font-size: 11px;
	}
}

@media (prefers-reduced-motion: reduce) {
	*,
	*::before,
	*::after {
		scroll-behavior: auto !important;
		transition-duration: 0.01ms !important;
		animation-duration: 0.01ms !important;
		animation-iteration-count: 1 !important;
	}
}
