/**
 * CompKit Ticket Machine - front-end skin.
 *
 * An additive layer, loaded after frontend.css. It upgrades *structure only*:
 * layout, spacing, radii, focus states and touch targets.
 *
 * It deliberately sets no `color` and no `background` on anything the shop can
 * configure. Ticket numbers, ticket tabs, answer buttons, predefined quantity
 * buttons, prize statuses and the timer label are all painted by the inline
 * style block that Settings builds from the colour pickers. Overriding those
 * here would silently ignore a shop's own choices - and would fight any
 * dark-mode plugin on the theme side, which is exactly the failure mode the
 * game modules already have to defend against.
 *
 * Where a colour is genuinely needed it is derived from the theme, via
 * `currentColor` or a low-alpha black, so it works on light and dark alike.
 *
 * @package CompKit_Ticket_Machine
 * @since   1.1.0
 */

:root {
	--cktm-radius: 12px;
	--cktm-radius-sm: 8px;
	--cktm-radius-pill: 999px;
	--cktm-gap: 8px;

	/* Derived from the theme's own text colour, so it inherits light or dark. */
	--cktm-hairline: color-mix(in srgb, currentColor 14%, transparent);
	--cktm-hairline-soft: color-mix(in srgb, currentColor 8%, transparent);
	--cktm-focus: color-mix(in srgb, currentColor 45%, transparent);
}

/* color-mix is widely supported, but a fallback keeps older browsers sane. */
@supports not (color: color-mix(in srgb, red 50%, transparent)) {

	:root {
		--cktm-hairline: rgba(128, 128, 128, 0.32);
		--cktm-hairline-soft: rgba(128, 128, 128, 0.18);
		--cktm-focus: rgba(128, 128, 128, 0.6);
	}
}

/* -------------------------------------------------------------------------
 * Ticket number grid
 *
 * Upstream floated fixed 80x50 list items with negative margins to collapse
 * the borders. That produced ragged last rows, clipped long ticket numbers,
 * and 50px-tall touch targets sitting flush against each other on a phone.
 * Grid gives even columns at every width and lets a long number breathe.
 * ---------------------------------------------------------------------- */

.lty-lottery-ticket-panel .lty-ticket-number-wrapper ul {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
	gap: 1px;
	list-style: none;
}

.lty-lottery-ticket-panel .lty-ticket-number-wrapper ul li {
	display: flex;
	align-items: center;
	justify-content: center;
	float: none;
	width: auto;
	height: auto;
	min-height: 48px;
	margin: 0;
	padding: 10px 8px;
	border-radius: var(--cktm-radius-sm);
	font-size: 14px;
	line-height: 1.3;
	white-space: normal;
	overflow-wrap: anywhere;
	transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.12s ease;
}

.lty-lottery-ticket-panel .lty-ticket-number-wrapper ul li:hover {
	transform: translateY(-1px);
	box-shadow: 0 2px 8px rgba(0, 0, 0, 0.14);
}

.lty-lottery-ticket-panel .lty-ticket-number-wrapper ul li.lty-booked-ticket:hover,
.lty-lottery-ticket-panel .lty-ticket-number-wrapper ul li.lty-processing-ticket:hover {
	transform: none;
	box-shadow: none;
}

.lty-lottery-ticket-panel .lty-ticket-number-wrapper ul li:focus-visible {
	outline: 2px solid var(--cktm-focus);
	outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {

	.lty-lottery-ticket-panel .lty-ticket-number-wrapper ul li {
		transition: none;
	}

	.lty-lottery-ticket-panel .lty-ticket-number-wrapper ul li:hover {
		transform: none;
	}
}

/* -------------------------------------------------------------------------
 * Ticket tabs
 * ---------------------------------------------------------------------- */

.lty-lottery-ticket-panel .lty-lottery-ticket-tab-wrapper {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	margin-bottom: 10px;
}

.lty-lottery-ticket-panel .lty-lottery-ticket-tab-wrapper .lty-lottery-ticket-tab {
	float: none;
	margin: 0;
	padding: 7px 14px;
	border-radius: var(--cktm-radius-pill);
	font-size: 13px;
	line-height: 1.5;
	cursor: pointer;
	transition: transform 0.12s ease;
}

.lty-lottery-ticket-panel .lty-lottery-ticket-tab-wrapper .lty-lottery-ticket-tab:active {
	transform: scale(0.97);
}

/* -------------------------------------------------------------------------
 * Progress bar
 *
 * Taller, fully rounded, with the fill animating its width rather than
 * replaying the upstream keyframe on every paint.
 * ---------------------------------------------------------------------- */

.lty-progress-bar {
	height: 10px;
	border-radius: 999px;
	/* Track colour is `lty_settings_single_product_progress_bar_bg_color`. */
}

.lty-progress-bar span {
	border-radius: 999px;
}

.lty-progress-bar span.lty-progress-fill {
	transition: width 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}

.lty-lottery-progress-bar .lty-progress-bar-percentage {
	border-radius: var(--cktm-radius-sm);
	font-weight: 700;
	letter-spacing: -0.01em;
}

.lty-progress-count {
	gap: 10px;
	align-items: baseline;
	font-size: 0.9em;
}

.lty-progress-count .lty-progress-bar-start,
.lty-progress-count .lty-progress-bar-notice,
.lty-progress-count .lty-progress-bar-end {
	width: auto;
	flex: 1 1 0;
}

.lty-lottery-progress-bar .lty-progress-remaining-count {
	margin-top: 8px;
	font-size: 0.9em;
	opacity: 0.85;
}

/* -------------------------------------------------------------------------
 * Countdown
 * ---------------------------------------------------------------------- */

.lty-shop-timer-wrapper .lty-shop-timer-container {
	display: flex;
	flex-wrap: wrap;
	gap: 4px;
	align-items: stretch;
}

.lty-shop-timer-wrapper .lty-shop-timer-container .lty-shop-timer-section {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	min-width: 62px;
	padding: 10px 12px;
	border: 1px solid var(--cktm-hairline);
	border-radius: var(--cktm-radius-sm);
	line-height: 1.2;
	font-variant-numeric: tabular-nums;
}

/* The upstream separator was a `:before` colon between float'd sections; the
   flex gap replaces it and it would otherwise sit inside the new border. */
.lty-shop-timer-section:before {
	content: none;
}

.lty-shop-timer-section .lty-shop-timer-content {
	font-size: 0.78em;
	letter-spacing: 0.06em;
	text-transform: uppercase;
	opacity: 0.72;
}

/* -------------------------------------------------------------------------
 * Predefined quantity buttons and question answers
 * ---------------------------------------------------------------------- */

ul.lty-predefined-buttons,
ul.lty-lottery-answers {
	display: flex;
	flex-wrap: wrap;
	gap: var(--cktm-gap);
	margin: 0 0 14px;
	padding: 0;
	list-style: none;
}

ul.lty-predefined-buttons li,
ul.lty-lottery-answers li {
	float: none;
	margin: 0;
	padding: 10px 16px;
	border-radius: var(--cktm-radius-sm);
	min-height: 44px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	line-height: 1.4;
	transition: transform 0.12s ease, box-shadow 0.12s ease;
}

ul.lty-predefined-buttons li:hover,
ul.lty-lottery-answers li:hover {
	transform: translateY(-1px);
	box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

ul.lty-predefined-buttons li:focus-visible,
ul.lty-lottery-answers li:focus-visible {
	outline: 2px solid var(--cktm-focus);
	outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {

	ul.lty-predefined-buttons li,
	ul.lty-lottery-answers li {
		transition: none;
	}

	ul.lty-predefined-buttons li:hover,
	ul.lty-lottery-answers li:hover {
		transform: none;
	}
}

/* -------------------------------------------------------------------------
 * My Account dashboard
 * ---------------------------------------------------------------------- */

.lty-dashboard-wrapper {
	display: grid;
	grid-template-columns: 1fr;
	gap: 20px;
}

@media screen and (min-width: 768px) {

	.lty-dashboard-wrapper {
		grid-template-columns: minmax(180px, 220px) 1fr;
		align-items: start;
	}
}

.lty-dashboard-navigation,
.lty-dashboard-contents {
	float: none;
	width: auto;
}

.lty-dashboard-navigation nav {
	display: flex;
	flex-direction: column;
	gap: 2px;
}

.lty-dashboard-navigation nav a {
	padding: 10px 14px;
	border-radius: var(--cktm-radius-sm);
	text-decoration: none;
	transition: background-color 0.15s ease;
}

/* Hover and current backgrounds are shop settings; only weight is ours. */
.lty-dashboard-navigation nav .lty-current {
	font-weight: 700;
}

.lty-dashboard-contents h3 {
	margin-bottom: 10px;
	font-size: 1.05em;
	letter-spacing: -0.01em;
}

.lty-dashboard-contents table {
	border-radius: var(--cktm-radius);
	overflow: hidden;
	border-collapse: collapse;
	width: 100%;
}

.lty-dashboard-contents table th,
.lty-dashboard-contents table td {
	padding: 12px 14px;
	border-bottom: 1px solid var(--cktm-hairline-soft);
	text-align: left;
	vertical-align: middle;
}

.lty-dashboard-contents table tr:last-child td {
	border-bottom: 0;
}

.lty-dashboard-contents .lty-no-product-notice {
	padding: 28px 20px;
	border: 1px dashed var(--cktm-hairline);
	border-radius: var(--cktm-radius);
	text-align: center;
	opacity: 0.8;
}

/* A wide table must scroll inside itself, never push the page sideways. */
.lty-dashboard-contents,
.lty-entry-list-content-wrapper {
	overflow-x: auto;
	-webkit-overflow-scrolling: touch;
}

/* -------------------------------------------------------------------------
 * Entry list
 * ---------------------------------------------------------------------- */

.lty-entry-list-header-wrapper {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
	margin-bottom: 14px;
}

.lty-entry-list-header-wrapper h2 {
	margin: 0;
	letter-spacing: -0.01em;
}

/* -------------------------------------------------------------------------
 * Instant-win prize groups
 * ---------------------------------------------------------------------- */

.lty-instant-winner-prize-group-item {
	border-radius: var(--cktm-radius);
	overflow: hidden;
}

.lty-instant-winner-prize-group-item-content {
	padding: 12px 14px;
}

.lty-instant-winners-table {
	border-radius: var(--cktm-radius);
	overflow: hidden;
}

/* -------------------------------------------------------------------------
 * View more / view less
 * ---------------------------------------------------------------------- */

.lty-ticket-number-wrapper .lty-toggle-view-button {
	float: none;
	display: inline-flex;
	align-items: center;
	gap: 6px;
	margin: 10px 0 0;
	padding: 8px 14px;
	border-radius: var(--cktm-radius-pill);
	border: 1px solid var(--cktm-hairline);
	cursor: pointer;
	background: none;
}

.lty-ticket-number-wrapper .lty-toggle-view-button:hover {
	background: var(--cktm-hairline-soft);
}

/* -------------------------------------------------------------------------
 * Popups
 *
 * A popup that cannot be scrolled on a phone is a dead end. `touch-action`
 * must stay `auto` on the scrolling element, and the height has to be capped
 * against the small-viewport unit so a tall list is always reachable.
 * ---------------------------------------------------------------------- */

.lty-customer-lottery-tickets,
.lty-lottery-ticket-popup-content {
	max-height: min(70vh, 70svh);
	overflow-y: auto;
	touch-action: auto;
	-webkit-overflow-scrolling: touch;
	overscroll-behavior: contain;
}

/* -------------------------------------------------------------------------
 * Narrow screens
 * ---------------------------------------------------------------------- */

@media screen and (max-width: 480px) {

	.lty-lottery-ticket-panel .lty-ticket-number-wrapper ul {
		grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
	}

	.lty-progress-count {
		flex-wrap: wrap;
		gap: 4px;
	}

	.lty-progress-count .lty-progress-bar-start,
	.lty-progress-count .lty-progress-bar-notice,
	.lty-progress-count .lty-progress-bar-end {
		flex: 1 1 100%;
		text-align: left;
	}

	.lty-shop-timer-wrapper .lty-shop-timer-container .lty-shop-timer-section {
		min-width: 54px;
		padding: 8px 10px;
	}
}
