/* Word Trainer — uses the theme's colours (Prompt Gallery Dark palette), with fallbacks. */

.wt {
	--wt-card: var(--wp--preset--color--base-2, #1b1b21);
	--wt-line: var(--wp--preset--color--base-3, #2c2c34);
	--wt-text: var(--wp--preset--color--contrast, #f5f5f7);
	--wt-muted: var(--wp--preset--color--contrast-2, #9b9ba8);
	--wt-accent: var(--wp--preset--color--accent, #2563eb);
	--wt-accent-2: var(--wp--preset--color--accent-2, #60a5fa);
	--wt-btn-radius: var(--wp--custom--elements--button--border--radius, 0.75rem);
	--wt-radius: 14px;

	/* Tile colours: blue = right spot, amber = wrong spot, grey = not in word. */
	--wt-hit: var(--wt-accent);
	--wt-near: #d97706;
	--wt-miss: #3a3a44;
	--wt-key: #2e2e37;
	--wt-key-hover: #3a3a45;

	box-sizing: border-box;
	max-width: 780px;
	margin-inline: auto;
	color: var(--wt-text);
	-webkit-tap-highlight-color: transparent;
}

.wt *,
.wt *::before,
.wt *::after {
	box-sizing: border-box;
}

.wt [hidden] {
	display: none !important;
}

.wt h3 {
	margin: 0 0 0.75rem;
	font-size: 1.25rem;
	letter-spacing: -0.01em;
}

.wt-loading,
.wt-note,
.wt-empty {
	color: var(--wt-muted);
	font-size: 0.9rem;
}

.wt-note a {
	font-weight: 600;
}

/* ---------- Game area ---------- */

.wt-play {
	max-width: 500px;
	margin: 0 auto;
	display: flex;
	flex-direction: column;
	gap: 14px;
}

.wt-top {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
}

.wt-tabs {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
}

.wt-pill {
	appearance: none;
	padding: 0.5em 1.1em;
	border: 1px solid var(--wt-line);
	border-radius: 999px;
	background: transparent;
	color: inherit;
	font: inherit;
	font-size: 0.9rem;
	font-weight: 600;
	line-height: 1.2;
	cursor: pointer;
	transition: border-color 0.15s, background-color 0.15s;
}

.wt-pill:hover {
	border-color: var(--wt-accent);
}

.wt-pill.is-active {
	background: var(--wt-accent);
	border-color: var(--wt-accent);
	color: #fff;
}

.wt-tabs--sm .wt-pill {
	font-size: 0.8rem;
	padding: 0.4em 0.9em;
}

.wt-icon-btn {
	appearance: none;
	flex: none;
	width: 38px;
	height: 38px;
	border: 1px solid var(--wt-line);
	border-radius: 50%;
	background: transparent;
	color: inherit;
	font: inherit;
	font-weight: 700;
	cursor: pointer;
}

.wt-icon-btn:hover,
.wt-icon-btn.is-active {
	border-color: var(--wt-accent);
	color: var(--wt-accent-2);
}

.wt-card {
	background: var(--wt-card);
	border: 1px solid var(--wt-line);
	border-radius: var(--wt-radius);
	padding: 18px 20px;
}

.wt-help p,
.wt-help ul {
	margin: 0 0 0.6em;
	font-size: 0.92rem;
}

.wt-help p:last-child {
	margin-bottom: 0;
}

.wt-legend {
	list-style: none;
	padding: 0;
	display: grid;
	gap: 6px;
}

.wt-legend li {
	display: flex;
	align-items: center;
	gap: 10px;
}

.wt-bar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
	min-height: 32px;
}

.wt-label {
	display: inline-flex;
	align-items: center;
	gap: 8px;
}

.wt-chip {
	display: inline-block;
	margin-left: 6px;
	padding: 0.15em 0.6em;
	border: 1px solid var(--wt-line);
	border-radius: 999px;
	color: var(--wt-muted);
	font-size: 0.75rem;
	font-weight: 600;
	vertical-align: middle;
}

.wt-label .wt-chip {
	margin-left: 0;
}

.wt-chip--live {
	border-color: var(--wt-accent);
	color: var(--wt-accent-2);
}

.wt-clock {
	padding: 0.25em 0.75em;
	border: 1px solid var(--wt-line);
	border-radius: 999px;
	font-family: var(--wp--preset--font-family--mono, ui-monospace, monospace);
	font-size: 0.95rem;
	font-variant-numeric: tabular-nums;
	color: var(--wt-muted);
}

.wt-clock.is-running {
	border-color: var(--wt-accent);
	color: var(--wt-text);
}

/* ---------- Grid ---------- */

.wt-stage {
	position: relative;
	display: flex;
	justify-content: center;
}

.wt-grid {
	width: min(100%, 330px);
	display: grid;
	gap: 6px;
}

/* On short phone screens, shrink the grid so the keyboard still fits. */
@supports (height: 1svh) {
	.wt-grid {
		width: min(100%, clamp(220px, calc((100svh - 330px) * 0.83), 330px));
	}
}

.wt-row {
	display: grid;
	grid-template-columns: repeat(5, 1fr);
	gap: 6px;
}

.wt-tile {
	display: grid;
	place-items: center;
	aspect-ratio: 1;
	border: 2px solid var(--wt-line);
	border-radius: 8px;
	background: transparent;
	color: var(--wt-text);
	font-size: clamp(1.35rem, 6.5vw, 1.9rem);
	font-weight: 700;
	line-height: 1;
	text-transform: uppercase;
	user-select: none;
}

.wt-tile.is-filled {
	border-color: var(--wt-muted);
}

.wt-tile.is-hit,
.wt-key.is-hit {
	background: var(--wt-hit);
	border-color: var(--wt-hit);
	color: #fff;
}

.wt-tile.is-near,
.wt-key.is-near {
	background: var(--wt-near);
	border-color: var(--wt-near);
	color: #fff;
}

.wt-tile.is-miss {
	background: var(--wt-miss);
	border-color: var(--wt-miss);
	color: #fff;
}

.wt-tile--mini {
	display: inline-grid;
	width: 30px;
	height: 30px;
	aspect-ratio: auto;
	font-size: 0.95rem;
	border-radius: 6px;
	flex: none;
}

.wt-tile.is-pop {
	animation: wt-pop 0.12s ease-out;
}

.wt-tile.is-flip {
	animation: wt-flip 0.26s ease-in-out both;
}

.wt-row.is-shake {
	animation: wt-shake 0.4s ease-in-out;
}

.wt-row.is-win .wt-tile {
	animation: wt-bounce 0.5s ease-out both;
}

.wt-row.is-win .wt-tile:nth-child(2) { animation-delay: 0.08s; }
.wt-row.is-win .wt-tile:nth-child(3) { animation-delay: 0.16s; }
.wt-row.is-win .wt-tile:nth-child(4) { animation-delay: 0.24s; }
.wt-row.is-win .wt-tile:nth-child(5) { animation-delay: 0.32s; }

@keyframes wt-pop {
	50% { transform: scale(1.08); }
}

@keyframes wt-flip {
	0% { transform: rotateX(0); }
	50% { transform: rotateX(90deg); }
	100% { transform: rotateX(0); }
}

@keyframes wt-shake {
	20%, 60% { transform: translateX(-6px); }
	40%, 80% { transform: translateX(6px); }
}

@keyframes wt-bounce {
	40% { transform: translateY(-12px); }
	70% { transform: translateY(2px); }
}

@media (prefers-reduced-motion: reduce) {
	.wt *,
	.wt *::before,
	.wt *::after {
		animation: none !important;
		transition: none !important;
	}
}

.wt-toast {
	position: absolute;
	top: 8px;
	left: 50%;
	z-index: 2;
	transform: translate(-50%, -6px);
	padding: 0.55em 1em;
	border-radius: 10px;
	background: var(--wt-text);
	color: var(--wp--preset--color--base, #121216);
	font-size: 0.9rem;
	font-weight: 600;
	white-space: nowrap;
	pointer-events: none;
	opacity: 0;
	transition: opacity 0.15s, transform 0.15s;
}

.wt-toast.is-on {
	opacity: 1;
	transform: translate(-50%, 0);
}

/* ---------- Keyboard ---------- */

.wt-keys {
	display: flex;
	flex-direction: column;
	gap: 7px;
	user-select: none;
}

.wt-keyrow {
	display: flex;
	gap: 5px;
	justify-content: center;
}

.wt-keyrow--mid {
	padding-inline: 5%;
}

.wt-key {
	appearance: none;
	flex: 1 1 0;
	min-width: 0;
	height: 54px;
	padding: 0;
	border: 0;
	border-radius: 8px;
	background: var(--wt-key);
	color: var(--wt-text);
	font: inherit;
	font-size: 1.05rem;
	font-weight: 700;
	text-transform: uppercase;
	cursor: pointer;
	touch-action: manipulation;
	transition: background-color 0.15s, filter 0.15s;
}

.wt-key:hover {
	background: var(--wt-key-hover);
}

.wt-key:active {
	filter: brightness(1.25);
}

.wt-key.is-hit:hover,
.wt-key.is-near:hover {
	filter: brightness(1.1);
}

.wt-key.is-miss {
	background: transparent;
	box-shadow: inset 0 0 0 1px var(--wt-line);
	color: var(--wt-muted);
	opacity: 0.55;
}

.wt-key--wide {
	flex: 1.55 1 0;
	font-size: 0.75rem;
	text-transform: none;
}

.wt-key[data-key="back"] {
	font-size: 1.2rem;
}

/* ---------- Buttons ---------- */

.wt-btn {
	appearance: none;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	padding: 0.75em 1.4em;
	border: 1px solid var(--wt-accent);
	border-radius: var(--wt-btn-radius);
	background: var(--wt-accent);
	color: #fff;
	font: inherit;
	font-size: 0.9rem;
	font-weight: 600;
	line-height: 1.2;
	cursor: pointer;
	transition: background-color 0.15s;
}

.wt-btn:hover,
.wt-btn:focus-visible {
	background: #1d4ed8;
	border-color: #1d4ed8;
	color: #fff;
}

/* ---------- Result + definition ---------- */

.wt-result {
	text-align: center;
}

.wt-result p {
	margin: 0 0 0.75em;
}

.wt-result__title {
	margin-bottom: 0.25rem !important;
}

.wt-result__meta {
	color: var(--wt-muted);
	font-variant-numeric: tabular-nums;
}

.wt-word {
	margin: 0.5rem 0 1rem;
	padding: 16px;
	border-radius: 12px;
	background: rgba(255, 255, 255, 0.03);
	border: 1px solid var(--wt-line);
}

.wt-word__letters {
	font-size: 1.9rem;
	font-weight: 800;
	letter-spacing: 0.22em;
	margin-right: -0.22em;
	color: var(--wt-accent-2);
	line-height: 1.2;
}

.wt-word__pos {
	display: inline-block;
	margin: 4px 0 8px;
	color: var(--wt-muted);
	font-size: 0.85rem;
	font-style: italic;
}

.wt-word__def {
	font-size: 1rem;
	line-height: 1.5;
	margin-bottom: 0.5em !important;
}

.wt-word__ex {
	color: var(--wt-muted);
	font-size: 0.9rem;
	font-style: italic;
	margin-bottom: 0 !important;
}

.wt-actions {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 6px;
}

/* ---------- Dashboard ---------- */

.wt-dash {
	display: grid;
	gap: 18px;
	margin-top: 36px;
}

.wt-controls {
	display: flex;
	flex-wrap: wrap;
	justify-content: space-between;
	gap: 10px;
	margin-bottom: 12px;
}

.wt-board__body {
	transition: opacity 0.15s;
}

.wt-board__body.is-loading {
	opacity: 0.5;
}

.wt-table {
	width: 100%;
	border-collapse: collapse;
	font-size: 0.92rem;
	margin: 0;
}

.wt-table th,
.wt-table td {
	padding: 0.6em 0.5em;
	border: 0;
	border-bottom: 1px solid var(--wt-line);
	text-align: left;
}

.wt-table th {
	color: var(--wt-muted);
	font-size: 0.75rem;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.06em;
}

.wt-table tr:last-child td {
	border-bottom: 0;
}

.wt-table .wt-num {
	text-align: right;
	font-variant-numeric: tabular-nums;
	white-space: nowrap;
}

.wt-rank {
	width: 2.5em;
	color: var(--wt-muted);
	font-weight: 700;
	font-variant-numeric: tabular-nums;
}

.wt-rank--1 { color: #fbbf24; }
.wt-rank--2 { color: #cbd5e1; }
.wt-rank--3 { color: #d97706; }

.wt-name {
	font-weight: 600;
	overflow-wrap: anywhere;
}

.wt-table tr.is-me td {
	background: rgba(37, 99, 235, 0.14);
}

.wt-table tr.is-gap td {
	border-top: 2px dashed var(--wt-line);
}

.wt-sub {
	margin: 1.1rem 0 0.6rem;
	color: var(--wt-muted);
	font-size: 0.75rem;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.08em;
}

.wt-stats h3 + .wt-sub {
	margin-top: 0;
}

.wt-stat-grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(105px, 1fr));
	gap: 10px;
}

.wt-stat {
	display: flex;
	flex-direction: column;
	gap: 2px;
	padding: 12px;
	border: 1px solid var(--wt-line);
	border-radius: 10px;
}

.wt-stat__value {
	font-size: 1.35rem;
	font-weight: 700;
	font-variant-numeric: tabular-nums;
	line-height: 1.2;
}

.wt-stat__label {
	color: var(--wt-muted);
	font-size: 0.78rem;
	line-height: 1.3;
}

.wt-dist {
	display: grid;
	gap: 5px;
}

.wt-dist__row {
	display: flex;
	align-items: center;
	gap: 10px;
}

.wt-dist__n {
	width: 1em;
	color: var(--wt-muted);
	font-weight: 600;
	font-variant-numeric: tabular-nums;
	text-align: center;
}

.wt-dist__track {
	flex: 1;
}

.wt-dist__bar {
	min-width: 2em;
	padding: 0.15em 0.6em;
	border-radius: 6px;
	background: var(--wt-miss);
	font-size: 0.85rem;
	font-weight: 700;
	font-variant-numeric: tabular-nums;
	text-align: right;
}

.wt-dist__bar.is-today {
	background: var(--wt-accent);
	color: #fff;
}

/* ---------- Small screens ---------- */

@media (max-width: 480px) {
	.wt-play {
		gap: 12px;
	}

	.wt-card {
		padding: 16px;
	}

	.wt-keys {
		gap: 6px;
	}

	.wt-keyrow {
		gap: 4px;
	}

	.wt-key {
		height: 50px;
		font-size: 0.95rem;
		border-radius: 6px;
	}

	.wt-key--wide {
		font-size: 0.68rem;
	}

	.wt-table th:nth-child(4),
	.wt-table td:nth-child(4) {
		padding-left: 0.25em;
	}
}

@media (min-width: 720px) {
	.wt-dash {
		grid-template-columns: 1fr 1fr;
		align-items: start;
	}

	.wt-dash > :only-child {
		grid-column: 1 / -1;
	}
}
