/* =========================================================================
   layout.css — in-game screen: header, board, info bars, controls, modals.
   Conventions (see also base.css :root tokens):
     - Controls SIZE TO THEIR LABEL (width:auto) so text is never clipped.
     - Spacing comes from a parent's `gap`, never per-item margins.
     - Sizes/colors/radii/shadows come from --tokens, not magic numbers.
   ========================================================================= */

/* ── Header ─────────────────────────────────────────────────────────────── */
header {
	background-color: var(--highlight-color);
	color: white;
	padding: var(--space-3) var(--space-5);
	text-align: center;
}

/* ── Layout containers ──────────────────────────────────────────────────── */
.player-frame {
	margin-top: 0 !important;
	margin-bottom: 0 !important;
	flex: 0 0 auto;
	order: 4;
	width: 100%;
	position: relative;
	background: var(--menu-surface);
	display: flex;
	flex-direction: column;
	border-top: 1px solid var(--menu-border);
}

.player-controls-row {
	display: flex;
	flex-direction: row;
	align-items: center;
	justify-content: flex-start;
	gap: var(--space-3);
	padding: var(--space-2) var(--space-3) 0 var(--space-3);
	position: relative;
}

#board-container {
	display: flex;
	flex-direction: column;
	align-items: center;
	margin: 0 auto;
	padding: 0;
	width: 100%;
	max-width: 100%;
}

/* ── Controls: shared look for chips (deck/timer) and buttons ───────────────
   One base rule for the whole family. Each control widens to fit its label
   (no fixed width → no "…" clipping); spacing comes from the parent gap. */
.deck-info,
.timer,
.pass-button,
.redraw-button,
.multiplayer-button,
.spacer,
.menu-button {
	flex: 0 0 auto;
	width: auto;
	min-width: 0;
	height: var(--control-height);
	line-height: calc(var(--control-height) - 12px);
	padding: 6px var(--space-4);
	box-sizing: border-box;

	background: var(--button-bg);
	color: var(--button-text);
	border: none;
	border-radius: var(--radius-pill);
	box-shadow: var(--shadow-sm);

	font-size: 15px;
	font-weight: bold;
	text-align: center;
	white-space: nowrap;          /* one line; control grows instead of clipping */
	transition: background 0.2s, box-shadow 0.2s;
}

/* The clickable members get a pointer + the slight letter-spacing the design
   used, and a consistent hover. (Chips deck-info/timer are not buttons.) */
.pass-button,
.redraw-button,
.multiplayer-button,
.menu-button {
	position: static;
	cursor: pointer;
	letter-spacing: 1px;
}

.pass-button:hover,
.multiplayer-button:hover,
.menu-button:hover {
	background: var(--button-hover);
	box-shadow: var(--shadow-md);
}

/* ── Control variants ───────────────────────────────────────────────────── */

/* Deck chip: secondary info, so a smaller label. */
.deck-info {
	display: inline-block;
	font-size: 11.25px;
}

.deck-info .deck-count {
	color: inherit;
}

/* deck-info is wrapped in a bare <button> (.deck-button); strip the button
   chrome so only the inner chip shows. */
.deck-button {
	display: flex;
	align-items: center;
	justify-content: center;
	flex: 0 0 auto;
	width: auto;
	min-width: 0;
	height: var(--control-height);
	background: none;
	border: none;
	box-shadow: none;
	padding: 0;
	margin: 0;
	font: inherit;
	color: inherit;
	cursor: pointer;
}

/* Timer chip: a small floor so 3:00 ↔ 0:09 doesn't make it jump width. */
.timer {
	min-width: 64px;
}

.timer.active {
	background: var(--button-hover);
	box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
	border: 1px solid rgba(255, 255, 255, 0.4);
	transform: translateY(-1px);
	transition: all 0.2s ease;
}

.timer.low-time {
	background-color: #ff3b30;
	color: white;
	animation: timer-pulse 1s infinite;
}

@keyframes timer-pulse {
	0%   { opacity: 1; }
	50%  { opacity: 0.7; }
	100% { opacity: 1; }
}

/* Redraw chip: compact fixed-width counter sitting beside Pass; distinct
   accent so it reads as a limited resource, dimmed when out of uses. */
.redraw-button {
	width: 48px;
	min-width: 48px;
	max-width: 48px;
	padding: 6px var(--space-2);
	background: var(--redraw-bg);
	letter-spacing: 0;
}

.redraw-button:hover:not(:disabled) {
	background: var(--redraw-hover);
	box-shadow: var(--shadow-md);
}

.redraw-button:disabled {
	opacity: 0.45;
	cursor: not-allowed;
}

/* Danger variant (concede etc.). */
.danger {
	background-color: #d83c3c;
}

.danger:hover {
	background-color: #a32a2a;
}

/* Game-over: grey everything out, kill active/low-time emphasis. */
.game-over {
	background-color: #888 !important;
	color: #eee !important;
	box-shadow: none !important;
	opacity: 0.75;
	transition: all 0.3s ease;
	border: 1px solid #777 !important;
}

.timer.game-over.active {
	background-color: #888 !important;
	transform: none !important;
	border: 1px solid #777 !important;
}

.timer.game-over.low-time {
	animation: none;
	background-color: #888 !important;
}

/* ── Info bars (above/below board) ──────────────────────────────────────────
   Fixed gap + wrap safety net so the row can never overflow the board width,
   however many controls it holds. */
.opponent-info,
.player-info {
	display: flex;
	justify-content: center;
	align-items: center;
	flex-wrap: wrap;
	gap: var(--space-2);
	width: var(--board-size);
	max-width: 100%;
	margin: var(--space-1) 0;
	padding: 6px var(--space-3);
	color: var(--menu-text);
	background: var(--menu-surface);
	border: 1px solid var(--menu-border);
	border-radius: var(--radius-panel);
	box-shadow: var(--shadow-sm);
}

.opponent-info {
	background: var(--menu-surface-2);
}

#white-player { background-color: var(--white-panel-bg); }
#black-player { background-color: var(--black-panel-bg); }

/* Player name + rating label in the info bars. Empty (singleplayer) → no box. */
.player-name {
	font-weight: 600;
	font-size: 0.9rem;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	max-width: 14ch;
}
.player-name:empty { display: none; }

/* Mirror order when playing as black. */
.timer-bar.reversed { flex-direction: row-reverse; }

.opponent-info.reversed,
.player-info.reversed { flex-direction: row-reverse; }

/* ── Timer bar ──────────────────────────────────────────────────────────── */
.timer-bar {
	width: 100%;
	display: flex;
	justify-content: center;
	margin: 0;
	padding: 0;
	background: transparent;
}

/* ── Status frame ───────────────────────────────────────────────────────── */
#status-frame {
	width: var(--board-size);
	max-width: 100%;
	margin-bottom: var(--space-2);
	padding: 10px var(--space-3);
	background: var(--menu-surface);
	border: 1px solid var(--menu-border);
	border-radius: var(--radius-panel);
	box-shadow: var(--shadow-sm);
	text-align: center;
}

#status-message {
	font-weight: 600;
	font-size: 16px;
	color: var(--menu-text);
}

/* ── Chessboard ─────────────────────────────────────────────────────────── */
#chessboard {
	width: var(--board-size);
	height: var(--board-size);
	border: 2px solid #333;
	margin: 0 auto !important;
}

#chessboard.active-white { border: 4px solid #ffffff !important; }
#chessboard.active-black { border: 4px solid #000000 !important; }

.highlight-square {
	background: #ffe680 !important;
}

.check-highlight {
	background-color: rgba(255, 0, 0, 0.4) !important;
	box-shadow: inset 0 0 5px 3px rgba(255, 0, 0, 0.8) !important;
}

/* Centered "PASS" overlay flashed on the board. */
.pass-indicator {
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	padding: var(--space-3) var(--space-5);
	background-color: rgba(0, 0, 0, 0.7);
	color: white;
	font-size: 32px;
	font-weight: bold;
	text-transform: uppercase;
	border-radius: 8px;
	z-index: 1000;
	opacity: 0;
	visibility: hidden;
	transition: opacity 0.2s ease;
}

/* ── Move history ──────────────────────────────────────────────────────────
   Desktop: board + panel sit side by side in a centered row (board fixed at
   --board-size, panel a fixed column). Mobile overrides in mobile.css stack the
   panel into a collapsible strip below the board. */
.game-board-row {
	display: flex;
	flex-direction: row;
	align-items: flex-start;
	justify-content: center;
	gap: var(--space-4);
	width: 100%;
}

/* Phantom column the same width as the panel, mirrored on the board's left, so
   the board centers in the viewport while the panel still sits to its right. */
.game-board-row::before {
	content: '';
	flex: 0 0 220px;
	align-self: stretch;
}

/* In the row the board sizes to its contents, not 100% (that's the mobile rule). */
.game-board-row > #board-container {
	width: auto;
	flex: 0 0 auto;
}

#move-history-panel {
	flex: 0 0 220px;
	max-height: var(--board-size);
	display: flex;
	flex-direction: column;
	color: var(--menu-text);
	background: var(--menu-surface);
	border: 1px solid var(--menu-border);
	border-radius: var(--radius-panel);
	box-shadow: var(--shadow-sm);
	overflow: hidden;
}

.move-history-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: var(--space-2) var(--space-3);
	font-weight: bold;
	background: var(--menu-surface-2);
	border-bottom: 1px solid var(--menu-border);
}

/* Collapse toggle is mobile-only (shown again in mobile.css). */
#move-history-toggle {
	display: none;
	border: none;
	background: none;
	font-size: 18px;
	cursor: pointer;
}

#move-history-list {
	flex: 1 1 auto;
	overflow-y: auto;
	padding: var(--space-2);
	font-size: 14px;
}

.move-row {
	display: flex;
	align-items: center;
	gap: var(--space-2);
	padding: 1px 0;
}

.move-no {
	flex: 0 0 26px;
	color: var(--menu-text-dim);
	font-variant-numeric: tabular-nums;
	text-align: right;
}

.ply {
	flex: 1 1 0;
	padding: 2px 6px;
	border-radius: 3px;
	cursor: pointer;
	white-space: nowrap;
}

.ply:hover { background: rgba(255, 255, 255, 0.08); }
.ply.current { background: var(--highlight-color); color: #fff; }
.ply.pass { font-style: italic; color: #b9a3e6; }
.ply.empty, .ply.empty:hover { cursor: default; background: none; }

#move-history-badge {
	margin: var(--space-2);
	padding: 6px var(--space-3);
	border: none;
	border-radius: var(--radius-pill);
	background: var(--redraw-bg);
	color: #fff;
	font-size: 13px;
	font-weight: bold;
	cursor: pointer;
}

.move-history-nav {
	display: flex;
	gap: var(--space-2);
	padding: var(--space-2);
	border-top: 1px solid var(--menu-border);
}

.move-history-nav button {
	flex: 1 1 0;
	height: var(--control-height);
	border: none;
	border-radius: var(--radius-panel);
	background: var(--button-bg);
	color: var(--button-text);
	font-size: 16px;
	cursor: pointer;
}

.move-history-nav button:disabled { opacity: 0.4; cursor: default; }
.move-history-nav button:not(:disabled):hover { background: var(--button-hover); }

/* Cards dim + ignore clicks while the player is scrubbing back through history. */
#player-area.browsing-history #player-cards {
	opacity: 0.45;
	pointer-events: none;
}

/* ── Modals (game options, concede, game over) ──────────────────────────── */
.small-modal {
	width: 300px;
	max-width: 90%;
}

.modal-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: var(--space-3) var(--space-4);
	background: transparent;
	color: var(--menu-text);
	border-bottom: 1px solid var(--menu-border);
}

.modal-header h3 {
	margin: 0;
	font-size: 18px;
}

.modal-body {
	display: flex;
	flex-direction: column;
	gap: var(--space-2);
	padding: var(--space-5);
}

.close-modal {
	color: white;
	font-size: 24px;
	cursor: pointer;
}

.close-modal:hover {
	color: #ccc;
}

.button-row {
	display: flex;
	gap: var(--space-3);
	margin-top: var(--space-3);
}

.button-row > * {
	flex: 1 1 0;          /* equal-width buttons that fill the row */
}

/* ── Mobile tweaks ──────────────────────────────────────────────────────── */
@media (max-width: 768px) {
	#status-frame {
		padding: 6px var(--space-3);
		margin-bottom: var(--space-1);
	}

	#status-message {
		font-size: 14px;
	}

	.timer-bar.reversed .white-timer { order: 2; }
	.timer-bar.reversed .black-timer { order: 1; }
	.timer-bar.reversed .spacer      { order: 0; }
}
/* Contains AI-generated edits. */
