/*
 * Race UI.
 *
 * The world this sits on top of is light, chunky and toy-like, so the interface
 * is built as crisp white cards rather than the dark translucent HUD most
 * racing games default to: it reads as the scoreboard clipped to a slot-car
 * set, which is what the game actually is.
 *
 * One typeface, one accent, hairline borders, hierarchy from weight and space.
 * The accent appears only on the primary action, the active state, and the
 * start lights.
 */

/* ─── Base ──────────────────────────────────────────────── */

.ui-root {
	position: fixed;
	inset: 0;
	z-index: 20;
	font-family: var(--font);
	color: var(--ink);
	font-variant-numeric: tabular-nums;
	pointer-events: none;
}

.ui-root > * {
	pointer-events: auto;
}

.ui-root [hidden] {
	display: none !important;
}

/* Full-screen scrim used by join, lobby and results. */
.screen {
	position: absolute;
	inset: 0;
	display: grid;
	place-items: center;
	padding: 24px;
	background: rgba(16, 20, 28, 0.34);
	backdrop-filter: blur(3px);
	-webkit-backdrop-filter: blur(3px);
	overflow-y: auto;
}

.card {
	width: min(560px, 100%);
	background: var(--surface);
	border: 1px solid var(--line);
	border-radius: var(--radius-card);
	box-shadow: var(--shadow-card);
	backdrop-filter: blur(16px);
	-webkit-backdrop-filter: blur(16px);
	padding: 32px;
}

.eyebrow {
	font-size: 11px;
	font-weight: 700;
	letter-spacing: 0.14em;
	text-transform: uppercase;
	color: var(--faint);
	margin: 0 0 10px;
}

h1 {
	font-size: 30px;
	font-weight: 800;
	letter-spacing: -0.02em;
	line-height: 1.1;
	margin: 0 0 6px;
}

h2 {
	font-size: 13px;
	font-weight: 700;
	letter-spacing: 0.1em;
	text-transform: uppercase;
	color: var(--faint);
	margin: 0 0 12px;
}

.lede {
	font-size: 15px;
	line-height: 1.5;
	color: var(--muted);
	margin: 0 0 24px;
}

/* ─── Controls ──────────────────────────────────────────── */

.field {
	display: block;
	margin-bottom: 20px;
}

.field > span {
	display: block;
	font-size: 12px;
	font-weight: 600;
	letter-spacing: 0.06em;
	text-transform: uppercase;
	color: var(--muted);
	margin-bottom: 8px;
}

input[type='text'] {
	width: 100%;
	height: 48px;
	padding: 0 14px;
	font: inherit;
	font-size: 16px; /* 16px keeps iOS from zooming the viewport on focus. */
	font-weight: 500;
	color: var(--ink);
	background: #fff;
	border: 1px solid var(--line);
	border-radius: 10px;
	box-sizing: border-box;
	transition: border-color 0.15s, box-shadow 0.15s;
}

input[type='text']:focus {
	outline: none;
	border-color: var(--ink);
	box-shadow: 0 0 0 3px rgba(23, 27, 34, 0.12);
}

.button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	min-height: 48px;
	padding: 0 22px;
	font: inherit;
	font-size: 15px;
	font-weight: 700;
	letter-spacing: 0.01em;
	color: var(--ink);
	background: #fff;
	border: 1px solid var(--line);
	border-radius: var(--radius-pill);
	cursor: pointer;
	transition: background 0.15s, border-color 0.15s, transform 0.08s;
}

.button:hover { background: #f4f5f7; }
.button:active { transform: scale(0.98); }

.button:focus-visible {
	outline: 3px solid rgba(23, 27, 34, 0.35);
	outline-offset: 2px;
}

.button--primary {
	color: var(--accent-ink);
	background: var(--accent);
	border-color: transparent;
}

.button--primary:hover { background: #c33420; }

.button--block { width: 100%; }

.button:disabled {
	opacity: 0.42;
	cursor: not-allowed;
	transform: none;
}

.button-row {
	display: flex;
	flex-wrap: wrap;
	gap: 10px;
}

/* Segmented control, used for lap count. */
.segmented {
	display: inline-flex;
	background: #fff;
	border: 1px solid var(--line);
	border-radius: var(--radius-pill);
	padding: 4px;
	gap: 2px;
}

.segmented button {
	min-width: 44px;
	height: 38px;
	padding: 0 12px;
	font: inherit;
	font-size: 14px;
	font-weight: 700;
	color: var(--muted);
	background: transparent;
	border: 0;
	border-radius: var(--radius-pill);
	cursor: pointer;
	transition: background 0.15s, color 0.15s;
}

.segmented button:hover { color: var(--ink); }

.segmented button[aria-pressed='true'] {
	color: var(--accent-ink);
	background: var(--accent);
}

.segmented button:focus-visible {
	outline: 3px solid rgba(23, 27, 34, 0.35);
	outline-offset: 1px;
}

/* A rule with a label sitting in the gap, separating primary from secondary. */
.divider {
	display: flex;
	align-items: center;
	gap: 12px;
	margin: 22px 0 18px;
	color: var(--faint);
	font-size: 11px;
	font-weight: 700;
	letter-spacing: 0.14em;
	text-transform: uppercase;
}

.divider::before,
.divider::after {
	content: '';
	flex: 1;
	height: 1px;
	background: var(--line);
}

.code-row {
	display: flex;
	gap: 10px;
}

.code-row input {
	flex: 1;
	min-width: 0;
	text-transform: uppercase;
	letter-spacing: 0.14em;
	font-weight: 700;
}

.code-row input::placeholder {
	text-transform: none;
	letter-spacing: 0;
	font-weight: 500;
}

/* ─── Join ──────────────────────────────────────────────── */

.room-code {
	display: inline-flex;
	align-items: baseline;
	gap: 10px;
	padding: 10px 16px;
	background: #fff;
	border: 1px solid var(--line);
	border-radius: 10px;
	margin-bottom: 24px;
}

.room-code .label {
	font-size: 11px;
	font-weight: 700;
	letter-spacing: 0.14em;
	text-transform: uppercase;
	color: var(--faint);
}

.room-code .value {
	font-size: 22px;
	font-weight: 800;
	letter-spacing: 0.16em;
	text-transform: uppercase;
}

/* ─── Lobby ─────────────────────────────────────────────── */

/* Horizontal because the list is long and the choice is casual: scanning a
   row beats a grid that pushes the start button off the card. */
.car-picker {
	display: flex;
	gap: 8px;
	overflow-x: auto;
	padding-bottom: 6px;
	margin-bottom: 22px;
	scrollbar-width: thin;
}

.car-chip {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	flex: none;
	min-height: 44px;
	padding: 0 14px;
	font: inherit;
	font-size: 13px;
	font-weight: 600;
	color: var(--ink);
	background: #fff;
	border: 1px solid var(--line);
	border-radius: var(--radius-pill);
	cursor: pointer;
	white-space: nowrap;
	transition: border-color 0.15s, background 0.15s;
}

.car-chip:hover { background: #f4f5f7; }

.car-chip:focus-visible {
	outline: 3px solid rgba(23, 27, 34, 0.35);
	outline-offset: 2px;
}

.car-chip .swatch {
	width: 10px;
	height: 10px;
	border-radius: 3px;
	flex: none;
	box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.14) inset;
}

.car-chip[aria-pressed='true'] {
	border-color: var(--ink);
	box-shadow: 0 0 0 1px var(--ink);
}

.lobby-head {
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: 20px;
	margin-bottom: 26px;
}

.roster {
	list-style: none;
	margin: 0 0 26px;
	padding: 0;
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
	gap: 8px;
}

.roster li {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 10px 12px;
	background: #fff;
	border: 1px solid var(--line);
	border-radius: 10px;
	font-size: 14px;
	font-weight: 600;
}

.roster .swatch {
	width: 10px;
	height: 10px;
	border-radius: 3px;
	flex: none;
	box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.12) inset;
}

.roster .who {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.roster .tag {
	margin-left: auto;
	font-size: 10px;
	font-weight: 700;
	letter-spacing: 0.1em;
	text-transform: uppercase;
	color: var(--faint);
}

.setting {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 16px;
	padding: 16px 0;
	border-top: 1px solid var(--line);
}

.setting .name {
	font-size: 14px;
	font-weight: 700;
}

.setting .detail {
	font-size: 13px;
	color: var(--muted);
	margin-top: 2px;
}

.lobby-actions {
	margin-top: 26px;
	padding-top: 24px;
	border-top: 1px solid var(--line);
}

.waiting {
	font-size: 14px;
	font-weight: 600;
	color: var(--muted);
	text-align: center;
	padding: 14px 0;
}

/* ─── Start lights ──────────────────────────────────────── */

/*
 * Five lights that fill left to right and then all go out at once, which is
 * how a real grid start reads. It replaces a generic "3, 2, 1" and is the one
 * piece of the interface that is purely about the subject.
 */
.lights {
	position: absolute;
	top: 12%;
	left: 50%;
	transform: translateX(-50%);
	display: flex;
	gap: 14px;
	padding: 18px 22px;
	background: rgba(16, 20, 28, 0.82);
	border-radius: 20px;
	box-shadow: 0 18px 50px rgba(16, 20, 28, 0.4);
}

.lights .bulb {
	width: 42px;
	height: 42px;
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.10);
	box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.5);
	transition: background 0.12s linear;
}

.lights .bulb.on {
	background: var(--accent);
	box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.25);
}

.lights-caption {
	position: absolute;
	top: calc(12% + 96px);
	left: 50%;
	transform: translateX(-50%);
	font-size: 13px;
	font-weight: 700;
	letter-spacing: 0.16em;
	text-transform: uppercase;
	color: #fff;
	text-shadow: 0 2px 8px rgba(16, 20, 28, 0.7);
}

@media (prefers-reduced-motion: reduce) {
	.lights .bulb { transition: none; }
}

/* ─── HUD ───────────────────────────────────────────────── */

.hud {
	position: absolute;
	inset: 0;
}

.hud-primary {
	position: absolute;
	top: 16px;
	left: 16px;
	display: flex;
	align-items: stretch;
	gap: 1px;
	background: var(--line);
	border: 1px solid var(--line);
	border-radius: 14px;
	overflow: hidden;
	box-shadow: var(--shadow-card);
}

.hud-cell {
	background: var(--surface);
	backdrop-filter: blur(16px);
	-webkit-backdrop-filter: blur(16px);
	padding: 10px 16px 12px;
	min-width: 74px;
}

.hud-cell .k {
	display: block;
	font-size: 10px;
	font-weight: 700;
	letter-spacing: 0.14em;
	text-transform: uppercase;
	color: var(--faint);
	margin-bottom: 2px;
}

.hud-cell .v {
	display: block;
	font-size: 26px;
	font-weight: 800;
	letter-spacing: -0.02em;
	line-height: 1.05;
}

.hud-cell .v small {
	font-size: 15px;
	font-weight: 700;
	color: var(--faint);
	letter-spacing: 0;
}

.hud-standings {
	position: absolute;
	top: 16px;
	right: 16px;
	width: 216px;
	background: var(--surface);
	backdrop-filter: blur(16px);
	-webkit-backdrop-filter: blur(16px);
	border: 1px solid var(--line);
	border-radius: 14px;
	box-shadow: var(--shadow-card);
	overflow: hidden;
}

.hud-standings ol {
	list-style: none;
	margin: 0;
	padding: 6px;
}

.hud-standings li {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 7px 10px;
	border-radius: 8px;
	font-size: 13px;
	font-weight: 600;
}

.hud-standings li.is-you {
	background: rgba(217, 58, 34, 0.10);
}

.hud-standings .pos {
	width: 20px;
	font-size: 13px;
	font-weight: 800;
	color: var(--faint);
	flex: none;
}

.hud-standings li.is-you .pos { color: var(--accent); }

.hud-standings .who {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.hud-standings .lap {
	margin-left: auto;
	font-size: 12px;
	font-weight: 700;
	color: var(--faint);
	flex: none;
}

.hud-banner {
	position: absolute;
	bottom: 22px;
	left: 50%;
	transform: translateX(-50%);
	padding: 12px 22px;
	background: var(--surface);
	backdrop-filter: blur(16px);
	-webkit-backdrop-filter: blur(16px);
	border: 1px solid var(--line);
	border-radius: var(--radius-pill);
	box-shadow: var(--shadow-card);
	font-size: 14px;
	font-weight: 700;
	white-space: nowrap;
}

/* ─── Results ───────────────────────────────────────────── */

.podium {
	display: grid;
	grid-template-columns: repeat(3, 1fr);
	align-items: end;
	gap: 10px;
	margin-bottom: 26px;
}

.podium .step {
	background: #fff;
	border: 1px solid var(--line);
	border-radius: 12px;
	padding: 14px 10px;
	text-align: center;
	overflow: hidden;
}

.podium .step .rank {
	font-size: 11px;
	font-weight: 800;
	letter-spacing: 0.12em;
	color: var(--faint);
}

.podium .step .who {
	font-size: 15px;
	font-weight: 700;
	margin: 6px 0 2px;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.podium .step .time {
	font-size: 12px;
	font-weight: 600;
	color: var(--muted);
}

/* Height, not colour, carries the ranking. */
.podium .step--1 { padding-top: 34px; border-color: rgba(217, 58, 34, 0.4); }
.podium .step--1 .rank { color: var(--accent); }
.podium .step--2 { padding-top: 22px; }
.podium .step--3 { padding-top: 14px; }

.classification {
	list-style: none;
	margin: 0;
	padding: 0;
	border-top: 1px solid var(--line);
	max-height: 220px;
	overflow-y: auto;
}

.classification li {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 11px 2px;
	border-bottom: 1px solid var(--line);
	font-size: 14px;
	font-weight: 600;
}

.classification .pos {
	width: 24px;
	font-weight: 800;
	color: var(--faint);
	flex: none;
}

.classification li.is-you .pos { color: var(--accent); }

.classification .who {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.classification .time {
	margin-left: auto;
	color: var(--muted);
	flex: none;
}

/* ─── Toast ─────────────────────────────────────────────── */

.toast {
	position: absolute;
	top: 16px;
	left: 50%;
	transform: translateX(-50%);
	max-width: min(420px, calc(100vw - 32px));
	padding: 12px 18px;
	background: var(--ink);
	color: #fff;
	border-radius: var(--radius-pill);
	font-size: 14px;
	font-weight: 600;
	box-shadow: 0 12px 30px rgba(16, 20, 28, 0.34);
}

/* ─── Small screens ─────────────────────────────────────── */

@media (max-width: 640px) {

	.card { padding: 24px 20px; }

	h1 { font-size: 25px; }

	.lobby-head { flex-direction: column; gap: 14px; }

	.hud-standings {
		width: auto;
		left: 16px;
		right: 16px;
		top: auto;
		bottom: 92px;
	}

	.hud-standings ol { display: flex; overflow-x: auto; padding: 6px; }

	.hud-standings li { flex: none; }

	.lights .bulb { width: 30px; height: 30px; }

	.podium { grid-template-columns: 1fr; }

	.podium .step { padding-top: 14px !important; }

}
