/**
 * Domino board styling. The palette follows the desktop Tk GUI so the two
 * front ends read as the same game.
 */

/* --- 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);
}

.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 fixed frame: the felt takes 350px of it and the rest is shared out
	 * by the flex column below, so the page never reflows as tiles are
	 * played and the log is opened. */
	height: 650px;
	display: flex;
	flex-direction: column;
	overflow: hidden;
	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-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 -------------------------------------------------------- */

.phd-table {
	position: relative;
	flex: 0 0 350px;
	height: 350px;
	display: flex;
	flex-direction: column;
	justify-content: center;
	padding: 0.75rem;
	border-radius: 12px;
	background: var(--phd-felt);
	box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.35);
}

.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;
}

.phd-chain .phd-tile {
	position: absolute;
}

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

.phd-empty {
	margin: 0.25rem 0 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: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);
}

.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: default;
}

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

.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.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);
	}
}
