/*
 * Chrome, layout and the tiles themselves.
 *
 * The board is drawn in the layout's own pixel space and scaled by one transform
 * on #board, so every size below is a fixed number: a tile is 60x80 whatever the
 * zoom. --tile-face matches the CREAM in js/tiles/faces.js, which is what makes
 * the ring inside a circle tile read as a hole.
 */

:root {
	--felt: #14332c;
	--felt-deep: #0d241f;
	--felt-raised: #1c453b;

	--ink: #eaf3ee;
	--ink-soft: #9db9ae;
	--ink-faint: #61796f;

	--gold: #e0b055;
	--gold-deep: #b98a34;
	--jade: #56b98c;
	--rose: #d97b6c;

	--tile-face: #f8f1de;
	--tile-top: #fffaef;
	--tile-side: #c9b791;
	--tile-line: #8f7c52;

	--radius-control: 12px;
	--radius-card: 18px;

	color-scheme: dark;
}

* {
	box-sizing: border-box;
}

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

body {
	background: var(--felt-deep);
	color: var(--ink);
	font-family: ui-rounded, "SF Pro Rounded", "Segoe UI Variable Display", system-ui,
		-apple-system, "Helvetica Neue", sans-serif;
	font-size: clamp(0.95rem, 3.3vw, 1.05rem);
	line-height: 1.35;
	overscroll-behavior: none;
	touch-action: pan-y;
	-webkit-text-size-adjust: 100%;
}

/*
 * The browser never zooms the app: scrolling is the only touch behaviour it is
 * allowed, so neither a pinch nor a double tap grows the menu or the chrome
 * around the board. Every element says so, not just body, because WebKit reads
 * touch-action from the element under the finger.
 *
 * The board allows nothing at all. A drag there pans it and a pinch zooms it,
 * both from the pointer events, and neither scrolls the page.
 */
#app,
#app * {
	touch-action: pan-y;
}

#app .board-viewport,
#app .board-viewport * {
	touch-action: none;
}

#app {
	position: relative;
	width: 100%;
	max-width: 56rem;
	height: 100%;
	margin-inline: auto;
	background:
		radial-gradient(120% 80% at 50% 0%, var(--felt-raised), transparent 70%),
		var(--felt);
}

.screen {
	position: absolute;
	inset: 0;
	display: flex;
	flex-direction: column;
	padding: max(0.75rem, env(safe-area-inset-top)) max(0.75rem, env(safe-area-inset-left))
		max(0.75rem, env(safe-area-inset-bottom)) max(0.75rem, env(safe-area-inset-right));
}

.screen[hidden] {
	display: none;
}

/* --- Controls ------------------------------------------------------------- */

button {
	min-height: 3rem;
	padding: 0.5rem 0.9rem;
	border: 1px solid #2f6355;
	border-radius: var(--radius-control);
	background: var(--felt-raised);
	color: var(--ink);
	font: inherit;
	font-weight: 600;
	cursor: pointer;
	-webkit-user-select: none;
	user-select: none;
	-webkit-tap-highlight-color: transparent;
	transition: background-color 90ms ease-out, border-color 90ms ease-out;
}

button.primary {
	min-height: 3.4rem;
	border-color: var(--gold-deep);
	background: linear-gradient(180deg, var(--gold), var(--gold-deep));
	color: #2a1c05;
	font-size: 1.05em;
}

button.quiet {
	min-height: 2.6rem;
	border-color: transparent;
	background: transparent;
	color: var(--ink-soft);
}

@media (hover: hover) {
	button:hover:not(:disabled) {
		background: #24544799;
		border-color: #3d7c69;
	}

	button.primary:hover:not(:disabled) {
		background: linear-gradient(180deg, #eec269, var(--gold));
	}
}

button:active:not(:disabled) {
	transform: translateY(1px);
}

button:focus-visible {
	outline: 3px solid var(--gold);
	outline-offset: 2px;
}

button:disabled {
	color: var(--ink-faint);
	border-color: #24483f;
	background: #163a32;
	cursor: default;
}

/* --- Menu ---------------------------------------------------------------- */

.menu-scroll {
	display: flex;
	flex-direction: column;
	gap: 0.75rem;
	width: 100%;
	max-width: 26rem;
	margin-inline: auto;
	padding-block: 0.5rem 1.5rem;
	overflow-y: auto;
	text-align: center;
}

/* Items keep their size and the column scrolls; without this a short screen
   squeezes the crest, which has no intrinsic height, to nothing. */
.menu-scroll > * {
	flex: none;
}

.crest {
	width: 11rem;
	max-height: 22vh;
	margin-inline: auto;
}

.crest-tile rect {
	fill: var(--tile-face);
	stroke: var(--tile-side);
	stroke-width: 2;
}

.crest-ring {
	fill: none;
	stroke: #1f5f9e;
	stroke-width: 6;
}

.crest-core {
	fill: #bf3b2f;
}

.crest-mark {
	fill: none;
	stroke: #1c7a52;
	stroke-width: 5;
	stroke-linecap: round;
}

.menu h1 {
	margin: 0;
	font-size: clamp(2rem, 9vw, 2.6rem);
	font-weight: 700;
	letter-spacing: -0.01em;
}

.subtitle {
	margin: 0 0 0.5rem;
	color: var(--ink-soft);
	text-wrap: balance;
}

.layout-list {
	display: flex;
	flex-direction: column;
	gap: 0.4rem;
}

.layout {
	display: grid;
	grid-template-columns: 1fr auto;
	gap: 0 0.75rem;
	padding: 0.7rem 0.9rem;
	text-align: left;
}

.layout-name {
	font-size: 1.05em;
}

.layout-detail {
	grid-column: 1;
	color: var(--ink-soft);
	font-weight: 400;
	font-size: 0.85em;
}

.layout-mark {
	grid-row: 1 / span 2;
	grid-column: 2;
	align-self: center;
	color: var(--ink-faint);
	font-variant-numeric: tabular-nums;
}

.layout-mark.is-time {
	color: var(--gold);
}

.layout.is-locked {
	opacity: 0.72;
}

.menu-options {
	display: flex;
	flex-direction: column;
	gap: 0.25rem;
	align-items: center;
	margin-top: 0.5rem;
}

.toggle {
	display: flex;
	gap: 0.6rem;
	align-items: center;
	padding: 0.5rem 0.25rem;
	color: var(--ink-soft);
	font-size: 0.9em;
	text-align: left;
	cursor: pointer;
}

.toggle input {
	width: 1.35rem;
	height: 1.35rem;
	flex: none;
	accent-color: var(--gold);
}

.summary {
	color: var(--ink-faint);
	font-size: 0.9em;
}

.summary p {
	margin: 0.1rem 0;
}

/* --- Game screen --------------------------------------------------------- */

.header-row {
	display: flex;
	gap: 0.5rem;
	align-items: center;
	flex: none;
}

.board-name {
	flex: 1;
	font-weight: 600;
	text-align: center;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.counter {
	color: var(--ink-soft);
	font-size: 0.9em;
	font-variant-numeric: tabular-nums;
}

.board-viewport {
	position: relative;
	flex: 1;
	min-height: 0;
	margin-block: 0.5rem;
	border-radius: var(--radius-card);
	background:
		radial-gradient(90% 70% at 50% 40%, #1d4b40, transparent 70%),
		var(--felt-deep);
	overflow: hidden;
	-webkit-user-select: none;
	user-select: none;
	-webkit-touch-callout: none;
}

.board {
	position: absolute;
	top: 0;
	left: 0;
	transform-origin: 0 0;
	will-change: transform;
}

.status-row {
	display: flex;
	gap: 0.5rem;
	align-items: center;
}

.zoom-controls {
	display: flex;
	flex: none;
	gap: 0.3rem;
}

button.round {
	width: 2.3rem;
	min-height: 2.3rem;
	padding: 0;
	border-radius: 50%;
	font-size: 1.05rem;
	line-height: 1;
}

/* --- Tiles --------------------------------------------------------------- */

.tile {
	position: absolute;
	width: 60px;
	height: 80px;
	border-radius: 7px;
	background: linear-gradient(158deg, var(--tile-top) 0%, var(--tile-face) 55%, #ede2c4 100%);
	box-shadow:
		5px 6px 0 -1px var(--tile-side),
		7px 9px 12px rgb(0 0 0 / 38%),
		inset 0 0 0 1px rgb(255 255 255 / 55%);
	transition: opacity 170ms ease-out, transform 170ms ease-out;
}

.tile-face {
	display: block;
	width: 100%;
	height: 100%;
}

/* A tile that cannot be taken is greyed by an overlay rather than a filter,
   which would cost a paint layer per tile on a board of 144. */
.tile:not(.is-free)::after {
	content: "";
	position: absolute;
	inset: 0;
	border-radius: inherit;
	background: rgb(11 32 27 / 32%);
}

.tile.is-gone {
	opacity: 0;
	transform: scale(0.55);
	pointer-events: none;
}

.tile.is-selected {
	outline: 3px solid var(--gold);
	outline-offset: -3px;
}

.tile.is-mate {
	outline: 3px dashed var(--jade);
	outline-offset: -3px;
}

.tile.is-hint {
	outline: 3px solid var(--jade);
	outline-offset: -3px;
	animation: throb 620ms ease-in-out infinite alternate;
}

.tile.is-blocked {
	animation: shake 260ms ease-in-out;
}

@keyframes throb {
	from { filter: none; }
	to { filter: brightness(1.25); }
}

@keyframes shake {
	0%, 100% { translate: 0 0; }
	25% { translate: -4px 0; }
	75% { translate: 4px 0; }
}

/* --- Bottom bar ---------------------------------------------------------- */

.bottom-bar {
	display: flex;
	flex: none;
	flex-direction: column;
	gap: 0.4rem;
}

.status {
	flex: 1;
	min-height: 2.4em;
	margin: 0;
	color: var(--gold);
	font-size: 0.82em;
	text-align: center;
	text-wrap: pretty;
}

.toolbar {
	display: grid;
	grid-template-columns: repeat(3, 1fr);
	gap: 0.4rem;
}

#shuffle-button.is-urgent {
	border-color: var(--gold);
	color: var(--gold);
	animation: throb 700ms ease-in-out infinite alternate;
}

/* --- Overlays ------------------------------------------------------------ */

.overlay {
	position: absolute;
	inset: 0;
	z-index: 100000;
	display: grid;
	place-items: center;
	padding: 1.25rem;
	background: rgb(8 26 22 / 78%);
}

.overlay[hidden] {
	display: none;
}

.card {
	display: flex;
	flex-direction: column;
	gap: 1rem;
	width: 100%;
	max-width: 24rem;
	max-height: 100%;
	padding: 1.75rem;
	border: 1px solid #2f6355;
	border-radius: var(--radius-card);
	background: var(--felt-raised);
	text-align: center;
	overflow-y: auto;
}

.card h2 {
	margin: 0;
	font-size: clamp(1.6rem, 7vw, 2.1rem);
	font-weight: 700;
}

.card p {
	margin: 0;
}

#result-detail {
	color: var(--ink-soft);
	white-space: pre-wrap;
}

.rules {
	text-align: left;
}

.rules p {
	color: var(--ink-soft);
	font-size: 0.94em;
}

.rules strong {
	color: var(--ink);
}

@media (prefers-reduced-motion: reduce) {
	button,
	.tile {
		transition: none;
	}

	.tile.is-hint,
	#shuffle-button.is-urgent,
	.tile.is-blocked {
		animation: none;
	}
}
