/**
 * Domino board styling, mesh build. The palette follows the desktop Tk GUI
 * so the two front ends read as the same game.
 *
 * The production felt is the same tested cell mesh without the development
 * overlay and controls.
 */

/* --- standing the board free of the theme ------------------------------
 *
 * A block theme wraps post content in a constrained layout with global side
 * padding, and prints the page title above it. On a page that is nothing but
 * the board, all of that is furniture around the interface.
 */

.phdomino-page .wp-block-post-title {
	display: none;
}

.phdomino-page main {
	margin-top: 0 !important;
}

.phdomino-page main > .wp-block-group {
	padding-top: 0 !important;
	padding-bottom: 0 !important;
}

/* The breakout below is measured against the viewport, so the page must not
 * be allowed to scroll sideways by the width of its own scrollbar. */
.phdomino-page {
	overflow-x: hidden;
}

/* Escape `is-layout-constrained` and the theme's global side padding. */
.phd.alignfull {
	width: 100vw;
	max-width: 100vw;
	margin-left: calc(50% - 50vw);
	margin-right: calc(50% - 50vw);
}

/* The debug panel is a sibling of the board, not a child, so the palette is
 * declared on the wrapper for both of them to inherit. */
.phdg-dev {
	--phd-bg: #1f2430;
	--phd-panel: #272d3b;
	--phd-text: #e6e9ef;
	--phd-muted: #9aa3b2;
	--phd-accent: #4da3ff;

	box-sizing: border-box;
	padding-bottom: 1rem;
	background: var(--phd-bg);
	color: var(--phd-text);
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
	font-size: 15px;
	line-height: 1.4;
}

.phdg-hud,
.phdg-hud * {
	box-sizing: border-box;
}

.phd {
	--phd-bg: #1f2430;
	--phd-panel: #272d3b;
	--phd-felt: #2f6f4f;
	--phd-text: #e6e9ef;
	--phd-muted: #9aa3b2;
	--phd-accent: #4da3ff;
	--phd-playable: #5fd28a;
	--phd-face: #f4f1e8;
	--phd-edge: #b9b2a0;
	--phd-back: #3a4152;
	--phd-pip: #20242e;
	--phd-pass: #e84a4a;

	--phd-short: clamp(30px, 3.1vw, 46px);
	--phd-long: calc(var(--phd-short) * 2);

	box-sizing: border-box;
	width: 100%;
	max-width: none;
	margin: 0;
	padding: 0.75rem clamp(0.75rem, 2vw, 2rem);
	position: relative;

	/* A frame that fits the screen it is on. The felt takes what the rows
	 * around it do not, so the page never reflows as tiles are played and
	 * the log is opened, and a short viewport no longer cuts the hand off
	 * the bottom of a box it cannot scroll. */
	height: auto;
	min-height: 0;
	display: flex;
	flex-direction: column;
	overflow: visible;
	background: var(--phd-bg);
	color: var(--phd-text);
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
	font-size: 15px;
	line-height: 1.4;
}

.phd *,
.phd *::before,
.phd *::after {
	box-sizing: inherit;
}

/* --- top bar ---------------------------------------------------------- */

.phd-topbar {
	display: flex;
	flex: 0 0 auto;
	align-items: center;
	gap: 1rem;
	flex-wrap: wrap;
	padding-bottom: 0.5rem;
}

.phd-seat {
	font-weight: 600;
	letter-spacing: 0.02em;
}

.phd-seat-note,
.phd-pips {
	color: var(--phd-muted);
	font-size: 0.85em;
}

/* Knowing your own pip count is a real advantage in a blocked game, so it is
 * off until the player asks for it. */
.phd-pips {
	display: none;
}

.phd-showpips .phd-pips {
	display: inline;
}

.phd-count {
	display: inline-block;
	min-width: 1.75em;
	padding: 0.1em 0.45em;
	border-radius: 999px;
	background: var(--phd-panel);
	color: var(--phd-accent);
	font-variant-numeric: tabular-nums;
	text-align: center;
}

.phd-topbar-controls {
	display: flex;
	align-items: center;
	justify-content: flex-end;
	gap: 1rem;
	flex-wrap: wrap;
	margin-left: auto;
}

.phd-ends {
	display: flex;
	align-items: center;
	gap: 0.35rem;
}

.phd-ends-label {
	color: var(--phd-muted);
	font-size: 0.75em;
	text-transform: uppercase;
	letter-spacing: 0.08em;
}

.phd-end {
	display: inline-block;
	min-width: 1.6em;
	padding: 0.1em 0.35em;
	border-radius: 6px;
	background: var(--phd-panel);
	color: var(--phd-text);
	font-weight: 700;
	font-variant-numeric: tabular-nums;
	text-align: center;
}

.phd-actions {
	display: flex;
	align-items: center;
	gap: 0.6rem;
}

.phd-language {
	max-width: 7.5rem;
	padding: 0.32em 1.7em 0.32em 0.55em;
	border: 1px solid #3c4457;
	border-radius: 7px;
	background-color: var(--phd-panel);
	color: var(--phd-text);
	font: inherit;
	font-size: 0.85em;
	cursor: pointer;
}

.phd-language:focus {
	outline: 2px solid var(--phd-accent);
	outline-offset: 1px;
}

.phd-toggle {
	display: inline-flex;
	align-items: center;
	gap: 0.35rem;
	color: var(--phd-muted);
	font-size: 0.85em;
	cursor: pointer;
	user-select: none;
}

.phd-btn {
	padding: 0.4em 0.9em;
	border: 1px solid #3c4457;
	border-radius: 8px;
	background: var(--phd-panel);
	color: var(--phd-text);
	font: inherit;
	font-size: 0.9em;
	cursor: pointer;
	transition: background 0.15s, border-color 0.15s;
}

.phd-btn:hover:not(:disabled) {
	border-color: var(--phd-accent);
}

.phd-btn:disabled {
	opacity: 0.4;
	cursor: default;
}

.phd-btn-primary {
	background: var(--phd-accent);
	border-color: var(--phd-accent);
	color: #10151f;
	font-weight: 600;
}

/* --- tiles ------------------------------------------------------------ */

.phd-tile {
	display: inline-flex;
	flex: 0 0 auto;
	background: var(--phd-face);
	border: 1px solid var(--phd-edge);
	border-radius: 6px;
	box-shadow: 0 2px 4px rgba(0, 0, 0, 0.35);
	overflow: hidden;
}

.phd-h {
	flex-direction: row;
	width: var(--phd-long);
	height: var(--phd-short);
}

.phd-v {
	flex-direction: column;
	width: var(--phd-short);
	height: var(--phd-long);
}

.phd-half {
	display: grid;
	flex: 1 1 50%;
	grid-template-columns: repeat(3, 1fr);
	grid-template-rows: repeat(3, 1fr);
	gap: 1px;
	padding: calc(var(--phd-short) * 0.11);
}

.phd-cell {
	display: block;
	border-radius: 50%;
}

.phd-pip {
	background: var(--phd-pip);
}

.phd-divider {
	flex: 0 0 1px;
	background: var(--phd-edge);
}

.phd-back {
	background: var(--phd-back);
	border-color: #4a5468;
}

.phd-small {
	--phd-short: 26px;
	--phd-long: 52px;
}

/* --- the table -------------------------------------------------------- */

/* The felt is the mesh, not a panel behind it. Trimming the field to whole
 * tiles leaves the mesh smaller than the space measured for it, and green
 * showing round the edges made the board look mis-centred rather than
 * exactly sized. So this element only positions; the green is painted on
 * .phdg-mesh, which is the mesh, to the cell. */
.phd-table {
	position: relative;
	flex: 0 0 480px;
	width: min(1840px, 100%);
	height: 480px;
	min-height: 480px;
	margin-inline: auto;
	display: flex;
	flex-direction: column;
	justify-content: center;
	padding: 0;
	background: none;
}

.phd-board {
	display: flex;
	flex: 1 1 auto;
	align-items: center;
	gap: 0.75rem;
	min-height: 0;
}

/* Tiles are placed at computed coordinates by ringLayout(), so this is a
 * surface rather than a row. Nothing scrolls: the tile size shrinks until the
 * whole chain fits the table. */
.phd-chain {
	position: relative;
	flex: 1 1 auto;
	align-self: stretch;
	min-width: 0;
	overflow: hidden;
}

.phdg-mesh .phd-tile {
	position: absolute;
}

.phd-on-board {
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

.phd-empty {
	position: absolute;
	left: 0;
	right: 0;
	bottom: 0.25rem;
	z-index: 1;
	margin: 0;
	text-align: center;
	color: rgba(255, 255, 255, 0.65);
	font-size: 0.85em;
	font-style: italic;
}

/* --- the ends of the chain, which are the drop targets ------------------ */

.phd-endtile {
	transition: box-shadow 0.12s, transform 0.12s;
}

/* An end that will accept the tile being dragged. */
.phd-endtile.phd-open,
.phd-openslot.phd-open {
	box-shadow: 0 0 0 3px var(--phd-playable), 0 2px 6px rgba(0, 0, 0, 0.45);
	cursor: pointer;
}

/* The end actually aimed at. */
.phd-endtile.phd-over,
.phd-openslot.phd-over {
	box-shadow: 0 0 0 4px var(--phd-playable), 0 0 18px rgba(95, 210, 138, 0.75);
	transform: translateY(-4px) scale(1.06);
}

/* Before the first tile is laid there is no end to aim at, so the opening
 * play is given a slot of its own. */
.phd-openslot {
	position: absolute;
	left: 50%;
	top: 50%;
	transform: translate(-50%, -50%);
	display: inline-flex;
	flex: 0 0 auto;
	align-items: center;
	justify-content: center;
	width: calc(var(--phd-long) + 0.5rem);
	height: var(--phd-long);
	border: 2px dashed rgba(255, 255, 255, 0.35);
	border-radius: 8px;
	color: rgba(255, 255, 255, 0.7);
	font-size: 0.75em;
	text-transform: uppercase;
	letter-spacing: 0.08em;
	transition: box-shadow 0.12s, transform 0.12s;
}

/* --- hands ------------------------------------------------------------ */

.phd-opphand {
	display: flex;
	flex: 0 0 auto;
	gap: 3px;
	align-items: center;
	justify-content: center;
	padding-bottom: 0.5rem;
	--phd-short: 22px;
	--phd-long: 44px;
}

.phd-hand-wrap {
	display: flex;
	flex: 1 1 auto;
	flex-direction: column;
	justify-content: center;
	min-height: 0;
	padding-top: 0.5rem;

	/* Slightly under the board tiles, so a full hand always clears the frame. */
	--phd-short: clamp(28px, 2.6vw, 40px);
	--phd-long: calc(var(--phd-short) * 2);
}

.phd-hand-meta {
	display: flex;
	align-items: baseline;
	gap: 0.5rem;
	padding-bottom: 0.4rem;
}

.phd-hand-row {
	position: relative;
	display: flex;
	align-items: flex-end;
}

.phd-hand {
	display: flex;
	flex: 1 1 auto;
	gap: 6px;
	align-items: flex-end;
	justify-content: center;
	flex-wrap: wrap;
	min-height: 0;
}

/* Pass sits at the end of the hand but remains outside its centring flow. */
.phd-passtile {
	position: absolute;
	right: 0;
	bottom: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	width: var(--phd-long);
	height: var(--phd-long);
	padding: 0;
	border: 2px dashed var(--phd-pass);
	border-radius: 6px;
	background: transparent;
	color: var(--phd-pass);
	font: inherit;
	font-size: 0.7em;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	cursor: default;
	transition: border-color 0.15s, color 0.15s, transform 0.12s;
}

.phd-passtile[hidden] {
	display: none;
}

.phd-passtile:disabled {
	opacity: 0.35;
}

.phd-passtile:not(:disabled) {
	border-style: solid;
	cursor: pointer;
}

.phd-passtile:not(:disabled):hover {
	transform: translateY(-6px);
	background: rgba(232, 74, 74, 0.15);
	box-shadow: 0 0 0 2px rgba(232, 74, 74, 0.35);
}

.phd-slot {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 2px;
}

.phd-hint {
	font-size: 0.7em;
	font-variant-numeric: tabular-nums;
	font-weight: 700;
	min-height: 1.2em;
}

.phd-in-hand {
	transition: transform 0.12s, box-shadow 0.12s;
}

/* A playable tile is always draggable; whether it is *shown* as playable is
 * the player's choice, so only the cursor is unconditional. */
.phd-playable {
	cursor: grab;
}

.phd-playable:hover {
	transform: translateY(-6px);
	box-shadow: 0 6px 10px rgba(0, 0, 0, 0.45);
}

/* Illegal tiles remain interactive so the attempted move can be submitted,
 * recorded, and resolved by the engine. Red distinguishes the consequence
 * without making the legal-play highlight ambiguous. */
.phd-illegal {
	cursor: grab;
}

.phd-illegal:hover {
	transform: translateY(-6px);
	box-shadow: 0 0 0 2px rgba(232, 74, 74, 0.65), 0 6px 10px rgba(0, 0, 0, 0.45);
}

.phd-highlight .phd-playable {
	border-color: var(--phd-playable);
	box-shadow: 0 0 0 2px rgba(95, 210, 138, 0.4), 0 2px 4px rgba(0, 0, 0, 0.35);
}

.phd-highlight .phd-dead {
	opacity: 0.5;
}

.phd-selected {
	transform: translateY(-8px);
	box-shadow: 0 0 0 2px var(--phd-accent), 0 6px 10px rgba(0, 0, 0, 0.45);
}

.phd-dead {
	cursor: grab;
}

.phd-opening-turn .phd-dead,
.phd-must-pass .phd-dead {
	opacity: 0.35;
	filter: grayscale(1);
}

.phd-busy .phd-hand {
	pointer-events: none;
	opacity: 0.7;
}

.phd-dragging {
	cursor: grabbing;
	user-select: none;
}

.phd-ghost {
	position: fixed;
	z-index: 9999;
	pointer-events: none;
	opacity: 0.92;
	filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.5));

	/* The tile is always built flat and rotated upright for the hand look, so
	 * turning it to match the end it is heading for is a transition rather
	 * than a swap. Centring is part of the transform for the same reason. */
	transform-origin: 50% 50%;
	transform: translate(-50%, -50%) rotate(90deg);
	transition: transform 0.14s ease-out;
}

.phd-ghost.phd-ghost-flat {
	transform: translate(-50%, -50%) rotate(0deg);
}

/* --- log -------------------------------------------------------------- */

.phd-log-wrap {
	position: relative;
	flex: 0 0 auto;
	margin-top: 0.25rem;
	color: var(--phd-muted);
	font-size: 0.85em;
}

.phd-log-wrap summary {
	cursor: pointer;
}

.phd-log {
	position: absolute;
	right: 0;
	bottom: 100%;
	z-index: 6;
	width: min(30rem, 100%);
	max-height: 15rem;
	margin: 0 0 0.4rem;
	padding: 0.5rem 0.5rem 0.5rem 2rem;
	border: 1px solid #3c4457;
	border-radius: 8px;
	background: var(--phd-panel);
	box-shadow: 0 8px 20px rgba(0, 0, 0, 0.45);
	overflow-y: auto;
	font-variant-numeric: tabular-nums;
}

.phd-log li {
	margin: 0.15rem 0;
}

/* --- game over -------------------------------------------------------- */

.phd-overlay {
	position: absolute;
	inset: 0;
	z-index: 10;
	display: flex;
	align-items: center;
	justify-content: center;
	background: rgba(15, 18, 26, 0.82);
}

.phd-overlay[hidden] {
	display: none;
}

.phd-overlay-card {
	max-width: 32rem;
	padding: 1.5rem;
	border: 1px solid #3c4457;
	border-radius: 12px;
	background: var(--phd-panel);
	text-align: center;
}

.phd-overlay-card h3 {
	margin: 0 0 0.5rem;
	color: var(--phd-text);
	font-size: 1.4em;
}

.phd-overlay-card p {
	margin: 0 0 1rem;
	color: var(--phd-muted);
	font-size: 0.9em;
}

.phd-reveal {
	display: flex;
	flex-wrap: wrap;
	gap: 4px;
	justify-content: center;
	padding-bottom: 1.25rem;
}

.phd-overlay-actions {
	display: flex;
	gap: 0.5rem;
	justify-content: center;
}

.phd-error {
	padding: 0.75rem;
	border-left: 3px solid #d63638;
	background: #fcf0f1;
	color: #8a1f21;
}

/* --- narrow screens -------------------------------------------------- */

@media (max-width: 700px) {
	.phd {
		padding-inline: 0;
	}

	.phd-table {
		flex-basis: 528px;
		width: min(432px, 100%);
		height: 528px;
		min-height: 528px;
	}

	.phd-topbar,
	.phd-opphand,
	.phd-hand-wrap,
	.phd-log-wrap {
		margin-inline: 0.75rem;
	}

	.phd-topbar {
		gap: 0.5rem 1rem;
	}

	.phd-opponent,
	.phd-topbar-controls {
		width: 100%;
	}

	.phd-opphand {
		gap: 2px;
		--phd-short: clamp(17px, 4.5vw, 22px);
		--phd-long: calc(var(--phd-short) * 2);
	}

	.phd-hand-wrap {
		flex: 0 0 auto;
		justify-content: flex-start;
		padding-top: 0.75rem;
		--phd-short: clamp(28px, 6.4vw, 34px);
		--phd-long: calc(var(--phd-short) * 2);
	}

	.phd-hand-row {
		padding-right: calc(var(--phd-long) + 0.5rem);
	}

	.phd-passtile {
		top: 50%;
		bottom: auto;
		transform: translateY(-50%);
	}

	.phd-passtile:not(:disabled):hover {
		transform: translateY(calc(-50% - 6px));
	}

	.phd-hand {
		flex: 0 0 auto;
		gap: 4px;
		align-items: end;
		justify-content: center;
		flex-wrap: wrap;
		margin-inline: auto;
	}

	.phd-hand .phd-slot {
		width: var(--phd-short);
	}
}

/* --- the production cell mesh -----------------------------------------
 *
 * Everything below draws what the router reasons about, so that a bad
 * placement can be looked at rather than guessed at. A tile's cell
 * coordinates are multiplied by the cell size and used as pixel offsets
 * inside .phdg-mesh, so the drawing and the layout cannot drift apart.
 */

.phdg-mesh {
	position: absolute;
	left: 50%;
	top: 50%;
	transform: translate(-50%, -50%);
	border-radius: 12px;
	background: var(--phd-felt);
	box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.35);

	/* Replaced by the script once the table has been measured. */
	--phdg-cell: 12px;
	--phdg-black: 12px;
	--phdg-grey: 12px;
}

.phdg-band,
.phdg-lines {
	position: absolute;
	inset: 0;
	display: none;
	pointer-events: none;
}

.phdg-show-mesh .phdg-band,
.phdg-show-mesh .phdg-lines {
	display: block;
}

/* Standing the mesh on white rather than felt: the bands are the point of
 * this view, and they have to be told apart at a glance. */
.phdg-show-mesh .phdg-mesh {
	border-radius: 0;
	background: #fff;
	box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4);
}

/* The frame no tile may enter. */
.phdg-black {
	border: var(--phdg-black) solid rgba(0, 0, 0, 0.88);
}

/* The one-cell ring that exists because a double overhangs its run by
 * exactly one cell. Nothing but that overhang is ever allowed in here. */
.phdg-grey {
	inset: var(--phdg-black);
	border: var(--phdg-grey) solid rgba(140, 146, 158, 0.9);
}

.phdg-lines {
	background-image:
		repeating-linear-gradient(
			to right,
			rgba(0, 0, 0, 0.18) 0 1px, transparent 1px var(--phdg-cell)
		),
		repeating-linear-gradient(
			to bottom,
			rgba(0, 0, 0, 0.18) 0 1px, transparent 1px var(--phdg-cell)
		);
}

/* On the mesh a tile is a block of cells, so the grid lines do the
 * separating that a drop shadow does on felt. */
.phdg-show-mesh .phdg-mesh .phd-tile {
	border-radius: 0;
	box-shadow: none;
	border: 1px solid rgba(0, 0, 0, 0.75);
}

/* --- the engine's messages, which had nowhere to go before -------------- */

.phd-status {
	color: var(--phd-muted);
	font-size: 0.85em;
	margin-left: auto;
}

.phd-status.phd-status-error {
	color: #ff8a8a;
	font-weight: 600;
}

/* --- the read-out ------------------------------------------------------ */

/* Below the board, not floating over it: the point of this view is to look
 * at the board as it would ship, which a panel sitting on the felt defeats. */
.phdg-hud {
	margin: 0 clamp(0.75rem, 2vw, 2rem);
	border: 1px solid #3c4457;
	border-radius: 8px;
	background: var(--phd-panel);
	color: var(--phd-muted);
	font-size: 0.78em;
	font-variant-numeric: tabular-nums;
}

.phdg-hud summary {
	padding: 0.35rem 0.6rem;
	cursor: pointer;
	color: var(--phd-text);
	font-weight: 600;
}

.phdg-hud-body {
	display: flex;
	flex-wrap: wrap;
	align-items: flex-start;
	gap: 0 1.5rem;
	padding: 0 0.6rem 0.6rem;
}

.phdg-hud-column {
	flex: 1 1 15rem;
	min-width: 0;
}

.phdg-stat {
	display: flex;
	justify-content: space-between;
	gap: 0.5rem;
	padding: 0.1rem 0;
}

.phdg-stat-key {
	color: var(--phd-muted);
}

.phdg-stat-value {
	color: var(--phd-text);
}

.phdg-hud-controls {
	display: flex;
	align-items: center;
	flex-wrap: wrap;
	gap: 0.5rem;
}

.phdg-hud-result {
	margin-top: 0.4rem;
	line-height: 1.35;
}

.phdg-warn,
.phdg-warn .phdg-stat-value {
	color: #ff8a8a;
	font-weight: 600;
}

@media (max-width: 700px) {
	.phdg-hud {
		margin: 0 0.75rem;
	}

	.phdg-slider label {
		flex: 0 0 4.5em;
	}
}

.phdg-slider {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	padding: 0.15rem 0;
}

.phdg-slider label {
	flex: 0 0 5.5em;
}

.phdg-slider input[type="range"] {
	flex: 1 1 auto;
	min-width: 0;
	accent-color: var(--phd-accent);
}

.phdg-slider-value {
	flex: 0 0 auto;
	min-width: 6em;
	color: var(--phd-text);
	text-align: right;
}

.phdg-mini {
	flex: 0 0 auto;
	padding: 0.15em 0.45em;
	font-size: 0.9em;
}

/* With the felt height driven by hand the board is no longer a fixed frame:
 * it grows to whatever has been asked for, and the page scrolls if that is
 * taller than the window. Clipping it to the frame would letterbox the mesh
 * instead of enlarging it, which is the opposite of what the slider is for.
 *
 * This is deliberately keyed to the height override alone. The width one must
 * not unpin the frame: with the frame released and no explicit height written,
 * the board has nothing to take its height from and collapses to nothing. */
.phdg-sized-h .phd {
	height: auto;
	min-height: 0;
	overflow: visible;
}

.phdg-sized-h .phd-table {
	/* An explicit height, not a share of what is left over. */
	flex: 0 0 auto;
	min-height: 0;
}

.phdg-sized-w .phd-table {
	margin-inline: auto;
}
