/* Jogo "Quebra-Cabeça Católico" — porte do plugin catolico-quebra-cabeca,
   sem jQuery UI e sem canvas (peças fatiadas via CSS, não canvas).

   As peças são <button> (ver assets/js/quebra-cabeca.js): o reset de
   aparência é obrigatório aqui, senão o navegador desenha borda, fundo e
   fonte de button por cima do desenho da peça. */

#qc-container {
	max-width: 900px;
	margin: 0 auto;
	padding: 20px;
}

.qc-titulo-puzzle {
	font-family: var( --f-display, Georgia, serif );
	font-weight: 600;
	font-size: var( --fs-h3, 1.375rem );
	margin: 0 0 var( --esp-4, 16px );
}

#qc-toolbar {
	display: flex;
	flex-wrap: wrap;
	gap: 12px;
	justify-content: center;
	margin-bottom: 16px;
}

/* Alvo de toque de 44px, que o botão original não tinha. */
#qc-toolbar button {
	min-height: 44px;
	padding: 10px 20px;
	border: 1px solid transparent;
	border-radius: 8px;
	background: var( --acento-sobre );
	color: var( --texto-invertido );
	font-family: var( --f-ui, inherit );
	font-size: 1rem;
	font-weight: 600;
	cursor: pointer;
	touch-action: manipulation;
}

#qc-toolbar button:hover {
	filter: brightness( 1.08 );
}

#qc-toolbar button:focus-visible {
	outline: 2px solid var( --acento);
	outline-offset: 2px;
}

/* ---------- Progresso e instruções ---------- */

.qc-progresso {
	margin: 0 0 8px;
	text-align: center;
	font-family: var( --f-ui, inherit );
	font-size: var( --fs-legenda, 0.8125rem );
	color: var( --texto-2);
}

.qc-instrucoes {
	margin: 0 0 16px;
	text-align: center;
	font-family: var( --f-ui, inherit );
	font-size: var( --fs-legenda, 0.8125rem );
	color: var( --texto-2);
	max-width: 60ch;
	margin-inline: auto;
}

/* ---------- Tabuleiro ---------- */

#qc-area {
	display: flex;
	flex-direction: column;
	gap: 20px;
}

#qc-tabuleiro {
	--qc-colunas: 4;
	display: grid;
	grid-template-columns: repeat( var( --qc-colunas ), 1fr );
	gap: 2px;
	aspect-ratio: 1 / 1;
	background: var( --borda);
	border: 3px solid var( --borda-forte);
	border-radius: 8px;
	overflow: hidden;
	position: relative;
}

.qc-slot {
	background: rgba( 0, 0, 0, 0.04 );
	position: relative;
}

.qc-slot::after {
	content: "";
	position: absolute;
	inset: 0;
	border: 1px dashed rgba( 0, 0, 0, 0.15 );
}

/* Foco num slot (destino do percurso por teclado). */
.qc-slot:focus-visible {
	outline: 3px solid var( --acento);
	outline-offset: -3px;
}

/* ---------- Peças ---------- */

.qc-peca {
	/* Reset de <button>: sem isto o UA desenha borda/fundo/fonte próprios
	 * por cima do desenho da peça. */
	appearance: none;
	-webkit-appearance: none;
	display: block;
	width: 100%;
	height: 100%;
	margin: 0;
	padding: 0;
	border: 0;
	font: inherit;
	color: inherit;
	background-repeat: no-repeat;
	/* Ancora do ::after da marca de "encaixada". */
	position: relative;
	cursor: grab;
	touch-action: none;
	box-shadow: inset 0 0 0 1px rgba( 255, 255, 255, 0.6 );
}

.qc-peca--arrastando {
	cursor: grabbing;
	z-index: 100;
	box-shadow: 0 6px 16px rgba( 0, 0, 0, 0.3 );
	opacity: 0.9;
}

/* Encaixada: o verde sozinho não carrega a informação, então a peça
 * ganha também um contorno branco por dentro e um traço de canto. */
.qc-peca--correta {
	cursor: default;
	box-shadow: inset 0 0 0 3px var( --ui-sucesso);
}

.qc-peca--correta::after {
	content: "";
	position: absolute;
	inset: 0;
	background:
		linear-gradient( 135deg, transparent 48%, rgba( 255, 255, 255, 0.55 ) 48%, rgba( 255, 255, 255, 0.55 ) 52%, transparent 52% );
	pointer-events: none;
}

/* Pegada (teclado ou clique): feedback que não depende de cor — o
 * contorno é o estado, a cor só reforça. */
.qc-peca--segurada {
	outline: 3px dashed var( --acento);
	outline-offset: -3px;
}

.qc-peca:focus-visible {
	outline: 3px solid var( --acento);
	outline-offset: -2px;
	z-index: 10;
}

/* ---------- Bandeja ---------- */

#qc-bandeja {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	justify-content: center;
	padding: 15px;
	background: var( --superficie-2);
	border: 1px solid var( --borda);
	border-radius: 8px;
	min-height: 90px;
}

#qc-bandeja .qc-peca {
	width: 70px;
	height: 70px;
	border-radius: 4px;
}

/* ---------- Modais ---------- */

.qc-modal {
	/* Regra base flex; o estado fechado vem do [hidden] abaixo. */
	display: flex;
	position: fixed;
	inset: 0;
	background: rgba( 0, 0, 0, 0.6 );
	align-items: center;
	justify-content: center;
	z-index: 1000;
	padding: 20px;
	/* Rolagem dentro do modal não arrasta a página de trás. */
	overscroll-behavior: contain;
}

.qc-modal[hidden] {
	display: none;
}

/* Fundo e tinta por token, não #fff fixo: no tema escuro o conteúdo
 * herdava --texto (#EDE7DE) e ficava ilegível sobre branco. */
.qc-modal__conteudo {
	background: var( --superficie);
	color: var( --texto);
	border: 1px solid var( --borda-forte);
	border-radius: 12px;
	padding: 30px;
	max-width: 500px;
	width: 100%;
	text-align: center;
	position: relative;
	/* A coluna cresce com o texto: altura fixa cortaria em 200% de zoom. */
	max-height: calc( 100vh - 40px );
	overflow-y: auto;
	overscroll-behavior: contain;
}

.qc-modal__conteudo h2 {
	font-family: var( --f-display, Georgia, serif );
	color: var( --texto);
}

.qc-modal__conteudo img {
	max-width: 100%;
	border-radius: 8px;
}

.qc-modal__fechar {
	position: absolute;
	top: 0;
	right: 0;
	min-width: 44px;
	min-height: 44px;
	display: flex;
	align-items: center;
	justify-content: center;
	background: none;
	border: none;
	font-size: 24px;
	line-height: 1;
	cursor: pointer;
	color: var( --texto-2);
	border-radius: var( --raio-s, 4px );
}

.qc-modal__fechar:hover {
	background: var( --superficie-2);
	color: var( --texto);
}

.qc-modal__fechar:focus-visible {
	outline: 2px solid var( --acento);
	outline-offset: 2px;
}

@media ( max-width: 600px ) {
	#qc-bandeja .qc-peca {
		width: 56px;
		height: 56px;
	}
}

@media ( prefers-reduced-motion: reduce ) {
	/* O jogo não anima por conta própria, mas o filtro de brilho do
	 * hover é transição de cor — some com a preferência do sistema. */
	#qc-toolbar button {
		transition: none;
	}
}
