:root {
	--ink: #2b1d10;
	--wood-dark: rgba(48, 30, 14, 0.82);
	--edge: rgba(255, 236, 200, 0.22);
}

* { box-sizing: border-box; }

html, body {
	height: 100%;
	margin: 0;
}

body {
	display: flex;
	flex-direction: column;
	font: 16px/1.4 "Avenir Next", "Segoe UI", system-ui, sans-serif;
	color: #f6e7cf;
	background: #3a2716 url("../assets/graphics/background.png") repeat;
	background-size: 256px 256px;
	overflow: hidden;
	-webkit-user-select: none;
	user-select: none;
}

.toolbar {
	display: flex;
	align-items: center;
	gap: 12px 20px;
	padding: 10px 18px;
	background: var(--wood-dark);
	border-bottom: 1px solid var(--edge);
	box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
	z-index: 1;
}

.brand {
	flex: 0 0 auto;
}

.brand h1 {
	margin: 0;
	font-size: 22px;
	letter-spacing: 0.06em;
	text-shadow: 0 1px 0 rgba(0, 0, 0, 0.6);
}

/* ---- puzzle picker ---------------------------------------------------- */

.picker {
	position: relative;
}

/* Reads as the old italic subtitle until you notice the caret, so the toolbar
   gains a control without gaining visual weight. */
.picker-button {
	display: flex;
	align-items: center;
	gap: 6px;
	min-width: 0;
	margin: 0;
	padding: 1px 4px;
	font-size: 13px;
	font-style: italic;
	color: inherit;
	opacity: 0.75;
	background: none;
	border: 1px solid transparent;
	border-radius: 5px;
	box-shadow: none;
}

.picker-button:hover:not(:disabled),
.picker-button[aria-expanded="true"] {
	opacity: 1;
	filter: none;
	border-color: var(--edge);
	background: rgba(255, 236, 200, 0.08);
}

.picker-button:active:not(:disabled) { transform: none; }

.picker-button:disabled { opacity: 0.7; }
.picker-button:disabled .picker-caret { display: none; }

.picker-caret {
	width: 9px;
	height: 6px;
	flex: 0 0 auto;
	opacity: 0.8;
	transition: transform 150ms ease;
}

.picker-button[aria-expanded="true"] .picker-caret { transform: rotate(180deg); }

.picker-list {
	position: absolute;
	top: calc(100% + 8px);
	left: 0;
	z-index: 5;
	min-width: 220px;
	max-height: min(60vh, 420px);
	overflow-y: auto;
	margin: 0;
	padding: 6px;
	list-style: none;
	background: linear-gradient(rgba(78, 52, 25, 0.97), rgba(58, 38, 18, 0.97));
	border: 1px solid var(--edge);
	border-radius: 10px;
	box-shadow: 0 16px 34px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 230, 190, 0.18);
	outline: none;
}

.picker-list[hidden] { display: none; }

/* A little pointer up at the button, so the panel reads as attached to it. */
.picker-list::before {
	content: "";
	position: absolute;
	top: -5px;
	left: 18px;
	width: 8px;
	height: 8px;
	background: rgb(78, 52, 25);
	border-left: 1px solid var(--edge);
	border-top: 1px solid var(--edge);
	transform: rotate(45deg);
}

.picker-item {
	display: grid;
	grid-template-columns: 18px 1fr auto;
	align-items: center;
	gap: 10px;
	padding: 8px 10px;
	border-radius: 6px;
	font-size: 14px;
	white-space: nowrap;
	cursor: pointer;
}

.picker-item.active {
	background: linear-gradient(rgba(122, 85, 45, 0.9), rgba(92, 61, 31, 0.9));
	box-shadow: inset 0 1px 0 rgba(255, 230, 190, 0.22);
}

.picker-item[aria-selected="true"] .picker-name {
	font-weight: 600;
}

.picker-tick {
	display: flex;
	width: 18px;
	color: #9fd48a;
}

.picker-check {
	width: 15px;
	height: 15px;
	filter: drop-shadow(0 1px 0 rgba(0, 0, 0, 0.5));
}

.picker-name {
	overflow: hidden;
	text-overflow: ellipsis;
}

.picker-size {
	font-size: 12px;
	font-variant-numeric: tabular-nums;
	opacity: 0.6;
}

.visually-hidden {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
}

.status {
	margin: 0 auto 0 0;
	font-size: 14px;
	opacity: 0.85;
	min-height: 1.4em;
	/* Yields space to the buttons on a narrow screen rather than pushing them
	   out of reach. */
	flex: 0 1 auto;
	min-width: 0;
	overflow: hidden;
	white-space: nowrap;
	text-overflow: ellipsis;
}

/* On a phone in portrait the buttons scroll sideways instead of wrapping onto
   a second row and stealing height from the board. */
.buttons {
	display: flex;
	align-items: center;
	gap: 8px;
	flex: 0 1 auto;
	min-width: 0;
	overflow-x: auto;
	overscroll-behavior-x: contain;
	-webkit-overflow-scrolling: touch;
	scrollbar-width: none;
	/* The row is short; a scrollbar under it would only cramp the buttons. */
	padding-bottom: 1px;
}

.buttons::-webkit-scrollbar { display: none; }

/* Fade whichever edge has buttons hidden beyond it, so the row visibly
   continues rather than ending flush against the screen edge. */
.buttons.fade-right {
	-webkit-mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
	mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
}

.buttons.fade-left {
	-webkit-mask-image: linear-gradient(to right, transparent, #000 28px);
	mask-image: linear-gradient(to right, transparent, #000 28px);
}

.buttons.fade-left.fade-right {
	-webkit-mask-image: linear-gradient(to right, transparent, #000 28px, #000 calc(100% - 28px), transparent);
	mask-image: linear-gradient(to right, transparent, #000 28px, #000 calc(100% - 28px), transparent);
}

.buttons > * {
	flex: 0 0 auto;
}

.divider {
	width: 1px;
	height: 24px;
	background: var(--edge);
}

button {
	font: inherit;
	font-size: 14px;
	color: #f6e7cf;
	min-width: 44px;
	padding: 7px 14px;
	border: 1px solid var(--edge);
	border-radius: 7px;
	background: linear-gradient(#7a552d, #5c3d1f);
	box-shadow: inset 0 1px 0 rgba(255, 230, 190, 0.25), 0 2px 4px rgba(0, 0, 0, 0.4);
	cursor: pointer;
}

button:hover:not(:disabled) { filter: brightness(1.12); }
button:active:not(:disabled) { transform: translateY(1px); filter: brightness(0.94); }
button:disabled { opacity: 0.4; cursor: default; }

main {
	flex: 1;
	min-height: 0;
}

#board {
	display: block;
	width: 100%;
	height: 100%;
	touch-action: none;
	cursor: grab;
}

#board:active { cursor: grabbing; }

/* Over the board, under the win card, and never in the way of a click. */
.confetti {
	position: fixed;
	inset: 0;
	z-index: 3;
	width: 100%;
	height: 100%;
	pointer-events: none;
}

.dialog {
	position: fixed;
	inset: 0;
	z-index: 10;
	display: grid;
	place-items: center;
	background: rgba(20, 12, 5, 0.55);
	opacity: 0;
	transition: opacity 200ms ease;
}

/* display:grid would otherwise beat the UA [hidden] rule, leaving an invisible
   overlay on top of the board that eats every click. */
.dialog[hidden] { display: none; }

.dialog.visible { opacity: 1; }

.dialog-card {
	max-width: min(90vw, 420px);
	padding: 26px 34px 22px;
	text-align: center;
	border: 1px solid var(--edge);
	border-radius: 14px;
	background: var(--wood-dark);
	box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
}

.dialog-card h2 {
	margin: 0 0 8px;
	font-size: 26px;
	letter-spacing: 0.04em;
}

.dialog-card p {
	margin: 0 0 20px;
	opacity: 0.8;
}

.dialog-actions {
	display: flex;
	justify-content: center;
	gap: 10px;
}

.dialog-actions button { min-width: 96px; }

button.ghost {
	background: rgba(255, 236, 200, 0.06);
	box-shadow: none;
}
