.modal {
	display: none;
	position: fixed;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	background-color: rgba(0, 0, 0, 0.7);
	align-items: center;
	justify-content: center;
	z-index: 1000;
}

.modal.active {
	display: flex;
}

/* Searching overlay shows while still on the main menu (#main-menu-landing is
   z-index 2000), so it must sit above the menu rather than the board. The Versus
   "share link & wait" modal stays on the menu too, for the same reason. */
#queue-searching-modal,
#waiting-modal {
	z-index: 2500;
}

.modal-content {
	background: var(--menu-surface);
	color: var(--menu-text);
	padding: var(--space-5);
	border-radius: var(--menu-radius);
	width: 90%;
	max-width: 500px;
	box-shadow: var(--menu-shadow);
	text-align: center;
	position: relative;
}

.modal-content h2,
.modal-content h3,
.modal-content h4 {
	color: var(--menu-text);
}

.modal-content h2 {
	margin-bottom: 15px;
}

.modal-content p,
.modal-content label {
	color: var(--menu-text-dim);
}

.modal-content p {
	margin-bottom: 10px;
}

/* Generic inputs on the dark surface (login, deck editor, join-game, etc.). */
.modal-content input[type="text"],
.modal-content input[type="email"],
.modal-content input[type="password"],
.modal-content input[type="number"],
.modal-content select {
	background: var(--menu-input-bg);
	color: var(--menu-text);
	border: 1px solid var(--menu-border);
	border-radius: var(--radius-panel);
}

.modal-content input::placeholder {
	color: var(--menu-text-dim);
}

#login-modal .modal-body {
	text-align: center;
}

#login-modal form {
	display: flex;
	flex-direction: column;
	gap: 10px;
	margin: 20px 0;
}

#login-modal input {
	padding: 10px;
	background: var(--menu-input-bg);
	color: var(--menu-text);
	border: 1px solid var(--menu-border);
	border-radius: var(--radius-panel);
	font-size: 16px;
}

#login-modal button {
	padding: 10px;
	background-color: var(--button-bg);
	color: var(--button-text);
	border: none;
	border-radius: var(--radius-pill);
	cursor: pointer;
	font-size: 16px;
}

#login-modal button:hover {
	background-color: var(--button-hover);
}

#login-modal a {
	color: var(--highlight-color);
	text-decoration: none;
}

#login-modal a:hover {
	text-decoration: underline;
}

#login-modal {
	display: none !important;
	z-index: 3000 !important;
	/* When hidden */
}

#login-modal[style*="flex"] {
	display: flex !important;
	/* When shown */
}

#deck-editor-modal {
	display: none !important;
	z-index: 3000 !important;
}

#deck-editor-modal[style*="flex"] {
	display: flex !important;
}

#deck-editor-modal .modal-content {
	background: var(--menu-surface);
	color: var(--menu-text);
	padding: var(--space-5);
	border-radius: var(--menu-radius);
	width: 90%;
	max-width: 400px;
	min-height: 350px;
	/* Similar height to login modal */
	box-shadow: var(--menu-shadow);
	text-align: center;
	position: relative;
	display: flex;
	flex-direction: column;
	justify-content: center;
}

#deck-editor-modal .modal-body {
	display: flex;
	flex-direction: column;
	gap: var(--space-4);
	text-align: left;
}

#deck-editor-modal .deck-form {
	display: flex;
	flex-direction: column;
	gap: var(--space-4);
	margin: 0;
}

/* Reset the browser's default <fieldset> chrome so the two groups read as plain
   sections; we draw our own spacing. */
#deck-editor-modal fieldset {
	border: none;
	margin: 0;
	padding: 0;
}

/* Piece counts in a two-column grid; openers stacked. Both share .deck-row. */
#deck-editor-modal .deck-pieces {
	display: grid;
	grid-template-columns: repeat(2, 1fr);
	gap: var(--space-3) var(--space-4);
}

#deck-editor-modal .deck-openers {
	display: flex;
	flex-direction: column;
	gap: var(--space-3);
}

#deck-editor-modal .deck-row {
	display: flex;
	align-items: center;
	gap: var(--space-3);
}

#deck-editor-modal .deck-icon {
	font-size: 24px;
	line-height: 1;
	width: 1.4em;
	text-align: center;
	color: var(--menu-text);
}

/* Push the control to the right edge of each row for a clean aligned column. */
#deck-editor-modal .deck-row input[type="number"],
#deck-editor-modal .deck-row select {
	margin-left: auto;
}

#deck-editor-modal input[type="number"],
#deck-editor-modal select {
	padding: var(--space-2) var(--space-3);
	background: var(--menu-input-bg);
	color: var(--menu-text);
	border: 1px solid var(--menu-border);
	border-radius: var(--radius-panel);
	font-size: 16px;
}

#deck-editor-modal input[type="number"] {
	width: 64px;
}

#deck-editor-modal .deck-openers select {
	min-width: 96px;
}

#deck-editor-modal .deck-total {
	text-align: center;
	font-weight: bold;
	color: var(--menu-text-dim);
}

/* Highlight the total in red while the deck isn't exactly 105 cards. */
#deck-editor-modal .deck-total.invalid {
	color: #e25c5c;
}

#deck-editor-modal button {
	padding: var(--space-3);
	background-color: var(--button-bg);
	color: var(--button-text);
	border: none;
	border-radius: var(--radius-pill);
	cursor: pointer;
	font-size: 16px;
	font-weight: bold;
}

#deck-editor-modal button:hover {
	background-color: var(--button-hover);
}

#deck-editor-modal button:disabled {
	background-color: var(--button-disabled-bg);
	cursor: not-allowed;
}

#deck-save-message {
	text-align: center;
	min-height: 1.2em;
}

/* Bare-button modals (multiplayer / waiting) carried unclassed <button>s that
   fell back to the browser default look. Give them the same pill style. */
#multiplayer-modal button,
#waiting-modal button {
	padding: 10px var(--space-4);
	background-color: var(--button-bg);
	color: var(--button-text);
	border: none;
	border-radius: var(--radius-pill);
	cursor: pointer;
	font-size: 16px;
	font-weight: bold;
	transition: background 0.2s;
}

#multiplayer-modal button:hover,
#waiting-modal button:hover {
	background-color: var(--button-hover);
}

/* Cancel reads as secondary: outlined instead of solid blue. */
#multiplayer-modal .cancel-button,
#waiting-modal .cancel-button {
	background-color: transparent;
	color: var(--menu-text-dim);
	border: 1px solid var(--menu-border);
}

#multiplayer-modal .cancel-button:hover,
#waiting-modal .cancel-button:hover {
	background-color: var(--menu-surface-2);
	color: var(--menu-text);
}

.separator {
	color: var(--menu-text-dim);
	margin: var(--space-3) 0;
}

.join-game-form {
	display: flex;
	flex-direction: column;
	gap: var(--space-2);
	margin: var(--space-3) 0;
}

.copy-link-container {
	display: flex;
	gap: var(--space-2);
	margin: var(--space-3) 0;
}

/* Post-game toast — non-blocking result card pinned bottom-centre. Unlike .modal
   it has no full-screen backdrop, so the board + move history stay clickable after
   the game ends. JS toggles inline display:flex/none; CSS owns the rest. */
#game-over-toast {
	position: fixed;
	left: 50%;
	bottom: var(--space-4);
	transform: translateX(-50%);
	z-index: 1500;
	flex-direction: column;
	align-items: center;
	gap: var(--space-2);
	padding: var(--space-3) var(--space-4);
	background: var(--menu-surface);
	color: var(--menu-text);
	border-radius: var(--menu-radius);
	box-shadow: var(--menu-shadow);
	text-align: center;
	max-width: 90vw;
	animation: game-over-toast-in 0.28s ease-out;
}

#game-over-toast #game-over-message {
	margin: 0;
	font-weight: 600;
	color: var(--menu-text);
	padding: 0 var(--space-3);
}

#game-over-toast #game-over-rating {
	margin: 0;
	font-weight: 600;
	color: var(--accent, var(--menu-text));
	padding: 0 var(--space-3);
}

#game-over-toast .button-row {
	display: flex;
	gap: var(--space-2);
}

#game-over-dismiss {
	position: absolute;
	top: 2px;
	right: 6px;
	background: none;
	border: none;
	color: var(--menu-text-dim);
	font-size: 1.3rem;
	line-height: 1;
	cursor: pointer;
	padding: 2px 6px;
}

#game-over-dismiss:hover {
	color: var(--menu-text);
}

@keyframes game-over-toast-in {
	from { opacity: 0; transform: translate(-50%, 16px); }
	to   { opacity: 1; transform: translate(-50%, 0); }
}

/* Rematch-pending — non-blocking card (mirrors #game-over-toast). The offer is
   sent after the game ends, so don't dim/lock the screen: let the offerer keep
   scrubbing the finished board + move history while waiting for the opponent.
   Transparent full-screen wrapper passes clicks through; only the card catches. */
#rematch-pending-modal {
	inset: auto 0 0 0;
	width: auto;
	height: auto;
	background-color: transparent;
	pointer-events: none;
	align-items: flex-end;
	padding-bottom: var(--space-4);
	z-index: 1500;
}

#rematch-pending-modal .modal-content {
	pointer-events: auto;
	width: auto;
	animation: game-over-toast-in 0.28s ease-out;
}

/* Disabled profile actions (features not shipped yet) read as greyed + inert
   instead of firing a "coming soon" popup. */
.profile-btn:disabled {
	opacity: 0.45;
	cursor: not-allowed;
}

/* Inline profile hint (e.g. "Log in to view your match history") — replaces a
   blocking alert. */
.profile-message {
	margin-top: var(--space-3);
	min-height: 1em;
	text-align: center;
	color: var(--menu-text-dim);
	font-size: 0.9rem;
}

/* AI difficulty picker in the in-game Game Options menu (vs-AI games only).
   A labelled segmented control; switching tiers takes effect on the bot's next
   move, mid-game. */
.ai-difficulty {
	display: flex;
	flex-direction: column;
	gap: var(--space-2);
	margin-bottom: var(--space-2);
}

.ai-difficulty .ai-difficulty-label {
	color: var(--menu-text-dim);
	font-size: 0.9rem;
}

.ai-difficulty .ai-difficulty-segments {
	display: flex;
	border-radius: var(--radius-panel, 8px);
	overflow: hidden;
}

.ai-difficulty .ai-diff-btn {
	flex: 1 1 0;
	border: 1px solid var(--menu-border);
	border-right-width: 0;
	background: var(--menu-input-bg);
	color: var(--menu-text);
	padding: 0.45em 0.5em;
	font-size: 0.95rem;
	cursor: pointer;
	transition: background 0.15s, color 0.15s;
}

.ai-difficulty .ai-diff-btn:last-child {
	border-right-width: 1px;
}

.ai-difficulty .ai-diff-btn.is-selected {
	background: var(--menu-text);
	color: var(--menu-surface);
}

/* Contains AI-generated edits. */