/*
 * Rockle game styles. Colors and fonts come from CSS variables that the
 * plugin sets from the settings screen (see Rockle_Shortcode::css_variables).
 */

.rockle {
	--rockle-correct: #007dba;
	--rockle-present: #005592;
	--rockle-absent: #767676;
	--rockle-tile-text: #fff;
	--rockle-absent-text: #fff;
	--rockle-text: #1a1a1b;
	--rockle-border: #949494;
	--rockle-key: #eeeeee;
	--rockle-key-text: #1a1a1b;
	--rockle-surface: #fff;
	--rockle-font: system-ui, sans-serif;
	--rockle-weight: 700;
	--rockle-gap: 5px;

	position: relative;
	box-sizing: border-box;
	max-width: 520px;
	margin: 0 auto;
	padding: 12px 8px 16px;
	background: var(--rockle-surface);
	color: var(--rockle-text);
	font-family: var(--rockle-font);
	font-weight: var(--rockle-weight);
	line-height: 1.3;
	text-align: center;
	-webkit-tap-highlight-color: transparent;
}

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

/* Font size is left to each button's own class, so keys can be smaller. */
.rockle button {
	font-family: inherit;
	font-weight: inherit;
	line-height: 1.2;
	letter-spacing: normal;
	margin: 0;
	box-shadow: none;
}

.rockle__preview {
	margin: 0 0 12px;
	padding: 10px 12px;
	border: 2px dashed var(--rockle-present);
	border-radius: 6px;
	font-size: 0.9rem;
	font-weight: 400;
	text-align: left;
}

.rockle__preview p,
.rockle__preview details {
	margin: 0 0 6px;
}

.rockle__preview summary {
	cursor: pointer;
}

.rockle__preview strong {
	margin-left: 6px;
	letter-spacing: 0.08em;
}

.rockle__message {
	margin: 40px 0;
	font-weight: 400;
}

.rockle__sr {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
}

/* Header */

.rockle__header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	padding-bottom: 8px;
	margin-bottom: 14px;
	border-bottom: 1px solid var(--rockle-border);
}

.rockle__icon {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 40px;
	height: 40px;
	padding: 6px;
	border: 0;
	border-radius: 50%;
	background: transparent;
	color: inherit;
	cursor: pointer;
}

.rockle__icon:hover {
	background: rgba(127, 127, 127, 0.12);
}

.rockle__icon svg {
	width: 26px;
	height: 26px;
}

.rockle button:focus-visible,
.rockle textarea:focus-visible,
.rockle input:focus-visible {
	outline: 3px solid var(--rockle-present);
	outline-offset: 2px;
}

/* Tiles */

.rockle__board {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: var(--rockle-gap);
	margin-bottom: 18px;
}

.rockle__row {
	display: grid;
	grid-template-columns: repeat(var(--len), 1fr);
	gap: var(--rockle-gap);
	width: min(100%, calc(var(--len) * 62px));
	container-type: inline-size;
}

.rockle__tile {
	display: flex;
	align-items: center;
	justify-content: center;
	aspect-ratio: 1;
	border: 2px solid var(--rockle-border);
	color: var(--rockle-text);
	font-size: clamp(0.75rem, calc(100cqi / var(--len) * 0.55), 2rem);
	font-weight: var(--rockle-weight);
	line-height: 1;
	text-transform: uppercase;
	user-select: none;
}

.rockle__tile[data-state="typed"] {
	border-color: var(--rockle-absent);
	animation: rockle-pop 0.1s ease-out;
}

.rockle__tile[data-state="missed"] {
	background: var(--rockle-absent);
	border-color: var(--rockle-absent);
	color: var(--rockle-absent-text);
}

.rockle__tile[data-state="hint"] {
	opacity: 0.35;
}

.rockle__tile[data-state="correct"],
.rockle__tile[data-state="present"],
.rockle__tile[data-state="absent"] {
	color: var(--rockle-tile-text);
}

.rockle__tile[data-state="correct"] {
	background: var(--rockle-correct);
	border-color: var(--rockle-correct);
}

.rockle__tile[data-state="present"] {
	background: var(--rockle-present);
	border-color: var(--rockle-present);
	/* A white inner border, so "wrong spot" doesn't rely on color alone. */
	box-shadow: inset 0 0 0 3px var(--rockle-tile-text);
}

.rockle__tile[data-state="absent"] {
	background: var(--rockle-absent);
	border-color: var(--rockle-absent);
	color: var(--rockle-absent-text);
}

/* The color shows from the midpoint of the flip, when the tile is edge-on. */
.rockle__tile.is-flip {
	animation: rockle-flip 0.5s ease-in both;
}

@keyframes rockle-flip {
	0% {
		transform: rotateX(0);
		background: transparent;
		border-color: var(--rockle-absent);
		color: var(--rockle-text);
	}
	49% {
		background: transparent;
		border-color: var(--rockle-absent);
		color: var(--rockle-text);
	}
	50% {
		transform: rotateX(-90deg);
	}
	100% {
		transform: rotateX(0);
	}
}

@keyframes rockle-pop {
	50% {
		transform: scale(1.1);
	}
}

.is-shake {
	animation: rockle-shake 0.5s;
}

@keyframes rockle-shake {
	10%, 90% { transform: translateX(-1px); }
	20%, 80% { transform: translateX(2px); }
	30%, 50%, 70% { transform: translateX(-4px); }
	40%, 60% { transform: translateX(4px); }
}

/* Letter mode */

.rockle__word {
	display: grid;
	grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
	gap: 4px;
	width: min(100%, calc(var(--cols) * 52px));
	container-type: inline-size;
}

.rockle__word .rockle__tile {
	font-size: clamp(0.5rem, calc(100cqi / var(--cols) * 0.55), 1.75rem);
}

/* Long words stay on one line, so the tiles get smaller and closer together. */
.rockle__word--long {
	gap: 2px;
}

.rockle__word--long .rockle__tile {
	border-width: 1px;
}

/* Hyphens are part of the word and shown from the start. */
.rockle__tile[data-state="fixed"] {
	border-color: transparent;
	background: transparent;
	color: var(--rockle-text);
}

.rockle__word--solve {
	margin-top: 12px;
}

.rockle__misses {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: center;
	gap: 6px 12px;
	margin-top: 12px;
	font-size: 0.95rem;
}

.rockle__pips {
	display: inline-flex;
	gap: 4px;
}

.rockle__pip {
	width: 12px;
	height: 12px;
	border: 2px solid var(--rockle-absent);
	border-radius: 50%;
}

.rockle__pip.is-used {
	background: var(--rockle-absent);
}

.rockle__wrong,
.rockle__prompt,
.rockle__muted {
	margin: 4px 0 0;
	font-size: 0.9rem;
	font-weight: 400;
	opacity: 0.8;
}

.rockle__wrong {
	/* Room for two lines, so a long list of misses doesn't push the board down. */
	min-height: calc(2 * 1.3em);
	letter-spacing: 0.05em;
	word-break: break-word;
}

.rockle__controls {
	margin-bottom: 14px;
}

.rockle__controls:empty {
	display: none;
}

/* Buttons */

.rockle__button {
	min-width: 120px;
	padding: 10px 22px;
	border: 2px solid var(--rockle-correct);
	border-radius: 999px;
	background: var(--rockle-correct);
	color: var(--rockle-tile-text);
	font-size: 1rem;
	cursor: pointer;
}

.rockle__button--ghost {
	background: transparent;
	color: var(--rockle-text);
	border-color: var(--rockle-absent);
}

/* Keyboard */

.rockle__keyboard {
	display: flex;
	flex-direction: column;
	gap: 8px;
	user-select: none;
}

.rockle__keys {
	display: flex;
	justify-content: center;
	gap: 6px;
}

.rockle__key {
	flex: 1;
	max-width: 44px;
	height: 56px;
	padding: 0;
	border: 0;
	border-radius: 4px;
	background: var(--rockle-key);
	color: var(--rockle-key-text);
	font-size: 1.1rem;
	text-transform: uppercase;
	cursor: pointer;
	touch-action: manipulation;
}

.rockle__key--wide {
	flex: 1.5;
	max-width: 66px;
	font-size: 0.75rem;
}

.rockle__key svg {
	width: 22px;
	height: 22px;
	vertical-align: middle;
}

.rockle__key[data-state] {
	color: var(--rockle-tile-text);
}

.rockle__key[data-state="correct"] {
	background: var(--rockle-correct);
}

.rockle__key[data-state="present"] {
	background: var(--rockle-present);
	box-shadow: inset 0 0 0 3px var(--rockle-tile-text);
}

.rockle__key[data-state="absent"] {
	background: var(--rockle-absent);
	color: var(--rockle-absent-text);
}

.rockle__key:disabled {
	cursor: default;
	opacity: 0.85;
}

/* Toasts */

.rockle__toasts {
	position: absolute;
	z-index: 20;
	top: 8px;
	left: 50%;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 6px;
	transform: translateX(-50%);
	pointer-events: none;
}

.rockle__toast {
	padding: 12px 16px;
	border-radius: 6px;
	background: var(--rockle-text);
	color: var(--rockle-surface);
	font-size: 0.95rem;
	white-space: nowrap;
	transition: opacity 0.3s;
}

.rockle__toast.is-leaving {
	opacity: 0;
}

/* Dialogs */

.rockle__overlay {
	position: fixed;
	z-index: 100000;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 16px;
	background: rgba(0, 0, 0, 0.5);
}

.rockle__dialog {
	position: relative;
	width: 100%;
	max-width: 440px;
	max-height: calc(100vh - 32px);
	overflow-y: auto;
	padding: 24px 20px 20px;
	border-radius: 8px;
	background: var(--rockle-surface);
	color: var(--rockle-text);
	text-align: center;
	box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
}

.rockle__dialog p {
	margin: 0 0 12px;
	font-weight: 400;
	text-align: left;
}

.rockle__dialog-title {
	margin: 0 0 16px;
	color: inherit;
	font: inherit;
	font-size: 1.1rem;
	text-transform: uppercase;
	letter-spacing: 0.05em;
}

.rockle__close {
	position: absolute;
	top: 8px;
	right: 8px;
}

.rockle__example {
	display: flex;
	align-items: center;
	gap: 12px;
	margin-bottom: 10px;
}

.rockle__example .rockle__tile {
	flex: 0 0 40px;
	font-size: 1.25rem;
}

.rockle__example p {
	margin: 0;
}

.rockle__dialog .rockle__answer {
	margin: 0 0 16px;
	font-size: 1.1rem;
	font-weight: var(--rockle-weight);
	text-align: center;
	letter-spacing: 0.04em;
}

.rockle__numbers {
	display: flex;
	justify-content: center;
	gap: 8px;
	margin-bottom: 18px;
}

.rockle__number {
	display: flex;
	flex: 1;
	flex-direction: column;
	max-width: 80px;
}

.rockle__number-value {
	font-size: 2rem;
	line-height: 1.1;
}

.rockle__number-label {
	font-size: 0.75rem;
	font-weight: 400;
}

.rockle__subhead {
	margin: 0 0 10px;
	color: inherit;
	font: inherit;
	font-size: 0.95rem;
	text-transform: uppercase;
	letter-spacing: 0.05em;
}

.rockle__dist {
	display: flex;
	flex-direction: column;
	gap: 4px;
	margin-bottom: 18px;
	padding: 0 8px;
}

.rockle__dist-row {
	display: flex;
	align-items: center;
	gap: 6px;
	font-size: 0.9rem;
}

.rockle__dist-label {
	width: 1em;
}

.rockle__dist-bar {
	padding: 2px 8px;
	background: var(--rockle-absent);
	color: var(--rockle-absent-text);
	text-align: right;
}

.rockle__dist-bar.is-current {
	background: var(--rockle-correct);
}

.rockle__footer {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-around;
	gap: 16px;
	padding-top: 16px;
	border-top: 1px solid var(--rockle-border);
}

.rockle__countdown {
	display: flex;
	flex-direction: column;
}

.rockle__clock {
	font-size: 1.6rem;
	font-variant-numeric: tabular-nums;
}

.rockle__timer {
	margin: -6px 0 10px;
	font-size: 0.9rem;
	font-variant-numeric: tabular-nums;
	opacity: 0.8;
}

.rockle__timer:empty {
	display: none;
}

/* Leaderboard */

.rockle__leaderboard {
	margin-bottom: 18px;
	padding-top: 16px;
	border-top: 1px solid var(--rockle-border);
}

.rockle__ranks {
	width: 100%;
	margin: 0 0 8px;
	border-collapse: collapse;
	font-size: 0.9rem;
}

.rockle__ranks th,
.rockle__ranks td {
	padding: 5px 6px;
	border: 0;
	border-bottom: 1px solid var(--rockle-border);
	text-align: left;
}

.rockle__ranks th {
	font-size: 0.75rem;
	font-weight: 400;
	text-transform: uppercase;
	letter-spacing: 0.04em;
}

.rockle__ranks td:nth-child(2) {
	word-break: break-word;
}

.rockle__ranks th:nth-child(n+3),
.rockle__ranks td:nth-child(n+3) {
	text-align: right;
	font-variant-numeric: tabular-nums;
}

.rockle__ranks tr.is-mine td {
	background: var(--rockle-correct);
	color: var(--rockle-tile-text);
}

.rockle__name-form {
	margin-top: 12px;
	text-align: left;
}

.rockle__name-form label {
	display: block;
	margin-bottom: 6px;
	font-size: 0.9rem;
}

.rockle__name-row {
	display: flex;
	gap: 8px;
}

.rockle__name-row input {
	flex: 1;
	min-width: 0;
	padding: 8px 10px;
	border: 2px solid var(--rockle-absent);
	border-radius: 6px;
	background: var(--rockle-surface);
	color: var(--rockle-text);
	font: inherit;
	font-weight: 400;
}

.rockle__name-row .rockle__button {
	min-width: 0;
}

.rockle__error {
	margin: 6px 0 0;
	color: #b32d2e;
	font-size: 0.85rem;
	font-weight: 400;
}

.rockle__error:empty {
	display: none;
}

.rockle__share-text {
	width: 100%;
	margin-top: 14px;
	padding: 8px;
	font-family: inherit;
	font-size: 0.9rem;
	resize: none;
}

@media (max-width: 400px) {
	.rockle {
		padding-left: 4px;
		padding-right: 4px;
	}

	.rockle__keys {
		gap: 4px;
	}

	.rockle__key {
		height: 52px;
	}
}

@media (prefers-reduced-motion: reduce) {
	.rockle *,
	.rockle *::before,
	.rockle *::after {
		animation-duration: 0.01ms !important;
		animation-delay: 0ms !important;
	}
}
