/* ==========================================================================
   harrysomewhere quiz — design tokens
   Committed dark theme: the game is a single immersive surface, so there is
   one palette rather than a half-considered light variant.
   ========================================================================== */

:root {
	color-scheme: dark;

	/* Surfaces */
	--bg: #0a0912;
	--bg-deep: #05040b;
	--surface: rgba(24, 21, 40, 0.72);
	--surface-solid: #181528;
	--surface-raised: rgba(255, 255, 255, 0.06);
	--surface-hover: rgba(255, 255, 255, 0.1);
	--border: rgba(255, 255, 255, 0.1);
	--border-strong: rgba(255, 255, 255, 0.2);

	/* Text — all pairs verified at 4.5:1 or better against --bg */
	--text: #f4f2fa;
	--text-muted: #a9a3c4;
	--text-faint: #7b7599;

	/* Semantic */
	--primary: #bb86fc;
	--primary-strong: #a46bf5;
	--primary-ink: #1a0b2e;
	--success: #46e0a0;
	--success-dim: rgba(70, 224, 160, 0.14);
	--success-ink: #04231a;
	--danger: #ff6b8a;
	--danger-dim: rgba(255, 107, 138, 0.14);
	--danger-ink: #2e060f;
	--warn: #ffc46b;

	/* Spacing — 4px rhythm */
	--sp-1: 4px;
	--sp-2: 8px;
	--sp-3: 12px;
	--sp-4: 16px;
	--sp-5: 20px;
	--sp-6: 24px;
	--sp-8: 32px;
	--sp-10: 40px;
	--sp-14: 56px;
	--sp-18: 72px;

	/* Radius */
	--r-sm: 10px;
	--r-md: 14px;
	--r-lg: 20px;
	--r-xl: 28px;
	--r-pill: 999px;

	/* Elevation */
	--shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
	--shadow-md: 0 8px 24px -8px rgba(0, 0, 0, 0.55);
	--shadow-lg: 0 24px 60px -20px rgba(0, 0, 0, 0.7);
	--glow-primary: 0 10px 40px -12px rgba(187, 134, 252, 0.55);

	/* Motion */
	--dur-fast: 150ms;
	--dur: 220ms;
	--dur-slow: 320ms;
	--ease-out: cubic-bezier(0.22, 0.8, 0.3, 1);
	--ease-in: cubic-bezier(0.5, 0, 0.75, 0);

	/* Layout */
	--content: 560px;
	--gutter: clamp(16px, 5vw, 32px);

	/* Type */
	--font-display: 'Outfit', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
	--font-body: 'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
}

/* ========================================================================== */

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

html {
	-webkit-text-size-adjust: 100%;
}

body {
	margin: 0;
	min-height: 100dvh;
	background: var(--bg);
	color: var(--text);
	font-family: var(--font-body);
	font-size: 16px;
	line-height: 1.55;
	font-synthesis-weight: none;
	-webkit-font-smoothing: antialiased;
	display: flex;
	flex-direction: column;
	overflow-x: hidden;
}

h1,
h2,
h3 {
	font-family: var(--font-display);
	font-weight: 700;
	line-height: 1.15;
	letter-spacing: -0.015em;
	margin: 0;
}

p {
	margin: 0;
}

img {
	max-width: 100%;
	display: block;
}

button {
	font: inherit;
	color: inherit;
}

:focus-visible {
	outline: 3px solid var(--primary);
	outline-offset: 3px;
	border-radius: var(--r-sm);
}

.sr-only {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
	border: 0;
}

.skip-link {
	position: absolute;
	top: var(--sp-2);
	left: var(--sp-2);
	z-index: 100;
	padding: var(--sp-3) var(--sp-4);
	background: var(--primary);
	color: var(--primary-ink);
	font-weight: 600;
	border-radius: var(--r-sm);
	text-decoration: none;
	transform: translateY(-200%);
	transition: transform var(--dur) var(--ease-out);
}

.skip-link:focus-visible {
	transform: translateY(0);
}

/* --- Aurora backdrop ------------------------------------------------------ */

.aurora {
	position: fixed;
	inset: -20%;
	z-index: -1;
	pointer-events: none;
	background:
		radial-gradient(42vmax 42vmax at 18% 12%, rgba(139, 92, 246, 0.3), transparent 62%),
		radial-gradient(38vmax 38vmax at 82% 8%, rgba(56, 189, 248, 0.2), transparent 60%),
		radial-gradient(46vmax 46vmax at 62% 88%, rgba(236, 72, 153, 0.16), transparent 62%),
		radial-gradient(50vmax 50vmax at 8% 82%, rgba(45, 212, 191, 0.14), transparent 64%);
	filter: blur(28px) saturate(115%);
	animation: drift 28s ease-in-out infinite alternate;
}

@keyframes drift {
	from {
		transform: translate3d(-2%, -1%, 0) scale(1);
	}
	to {
		transform: translate3d(2%, 2%, 0) scale(1.08);
	}
}

/* --- Shell ---------------------------------------------------------------- */

.topbar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: var(--sp-3);
	padding: calc(var(--sp-4) + env(safe-area-inset-top)) var(--gutter) var(--sp-4);
	max-width: calc(var(--content) + var(--gutter) * 2);
	width: 100%;
	margin-inline: auto;
}

.brand {
	display: inline-flex;
	align-items: center;
	gap: var(--sp-2);
	color: var(--text);
	text-decoration: none;
	font-family: var(--font-display);
	font-weight: 600;
	font-size: 15px;
	letter-spacing: -0.01em;
	padding: var(--sp-2);
	margin: calc(var(--sp-2) * -1);
	border-radius: var(--r-sm);
}

.brand img {
	width: 28px;
	height: 28px;
	border-radius: var(--r-pill);
	background: var(--surface-raised);
}

main {
	flex: 1;
	width: 100%;
	max-width: calc(var(--content) + var(--gutter) * 2);
	margin-inline: auto;
	padding: 0 var(--gutter) var(--sp-10);
}

.site-footer {
	padding: var(--sp-6) var(--gutter) calc(var(--sp-6) + env(safe-area-inset-bottom));
	text-align: center;
	color: var(--text-faint);
	font-size: 13px;
}

.site-footer a {
	color: var(--text-muted);
	text-decoration: none;
	border-bottom: 1px solid var(--border-strong);
	padding-bottom: 1px;
}

.site-footer a:hover {
	color: var(--text);
}

/* --- View switching ------------------------------------------------------- */

.view {
	display: flex;
	flex-direction: column;
	gap: var(--sp-5);
	animation: view-in var(--dur-slow) var(--ease-out) both;
}

[hidden] {
	display: none !important;
}

@keyframes view-in {
	from {
		opacity: 0;
		transform: translate3d(0, 12px, 0);
	}
	to {
		opacity: 1;
		transform: none;
	}
}

/* --- Cards ---------------------------------------------------------------- */

.card {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--r-xl);
	padding: var(--sp-6);
	box-shadow: var(--shadow-lg);
	backdrop-filter: blur(20px) saturate(140%);
	-webkit-backdrop-filter: blur(20px) saturate(140%);
}

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

.btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: var(--sp-2);
	min-height: 52px;
	padding: var(--sp-3) var(--sp-6);
	border: 1px solid transparent;
	border-radius: var(--r-pill);
	font-family: var(--font-display);
	font-weight: 600;
	font-size: 16px;
	cursor: pointer;
	text-decoration: none;
	touch-action: manipulation;
	transition:
		background-color var(--dur-fast) var(--ease-out),
		border-color var(--dur-fast) var(--ease-out),
		box-shadow var(--dur-fast) var(--ease-out),
		transform var(--dur-fast) var(--ease-out);
}

.btn:active:not(:disabled) {
	transform: scale(0.97);
}

.btn:disabled {
	opacity: 0.45;
	cursor: not-allowed;
}

.btn--primary {
	background: var(--primary);
	color: var(--primary-ink);
	box-shadow: var(--glow-primary);
}

.btn--primary:hover:not(:disabled) {
	background: var(--primary-strong);
}

.btn--ghost {
	background: var(--surface-raised);
	color: var(--text);
	border-color: var(--border);
}

.btn--ghost:hover:not(:disabled) {
	background: var(--surface-hover);
	border-color: var(--border-strong);
}

.btn--lg {
	min-height: 60px;
	font-size: 18px;
	padding-inline: var(--sp-8);
}

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

.btn svg {
	width: 20px;
	height: 20px;
	flex: none;
}

/* Compact variant for toolbar actions; still clears the 44px touch minimum. */
.btn--sm {
	min-height: 44px;
	padding: var(--sp-2) var(--sp-4);
	font-size: 14px;
}

.board__back {
	margin-top: var(--sp-6);
}

.error-slot {
	margin-top: var(--sp-5);
}

/* --- Start view ----------------------------------------------------------- */

.hero {
	text-align: center;
	padding: var(--sp-8) var(--sp-5) var(--sp-8);
}

.hero__eyebrow {
	font-size: 13px;
	font-weight: 600;
	letter-spacing: 0.1em;
	text-transform: uppercase;
	color: var(--primary);
	margin-bottom: var(--sp-3);
}

.hero__title {
	font-size: clamp(34px, 9vw, 52px);
	margin-bottom: var(--sp-3);
}

.hero__title em {
	font-style: normal;
	color: var(--primary);
}

.hero__lede {
	color: var(--text-muted);
	font-size: 17px;
	max-width: 34ch;
	margin: 0 auto var(--sp-8);
	text-wrap: balance;
}

.hero__rules {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: var(--sp-2);
	margin-top: var(--sp-6);
}

.rule-chip {
	display: inline-flex;
	align-items: center;
	gap: var(--sp-2);
	padding: var(--sp-2) var(--sp-4);
	background: var(--surface-raised);
	border: 1px solid var(--border);
	border-radius: var(--r-pill);
	font-size: 13px;
	color: var(--text-muted);
}

.rule-chip svg {
	width: 15px;
	height: 15px;
	color: var(--primary);
	flex: none;
}

/* --- HUD ------------------------------------------------------------------ */

.hud {
	display: flex;
	align-items: flex-end;
	justify-content: space-between;
	gap: var(--sp-4);
}

.hud__label {
	display: block;
	font-size: 12px;
	font-weight: 600;
	letter-spacing: 0.12em;
	text-transform: uppercase;
	color: var(--text-faint);
}

.hud__score {
	display: block;
	font-family: var(--font-display);
	font-size: 44px;
	font-weight: 700;
	line-height: 1;
	font-variant-numeric: tabular-nums;
	color: var(--text);
}

.hud__score.is-bumped {
	animation: bump var(--dur-slow) var(--ease-out);
	color: var(--success);
}

@keyframes bump {
	0% {
		transform: scale(1);
	}
	40% {
		transform: scale(1.22);
	}
	100% {
		transform: scale(1);
	}
}

.hud__meta {
	display: flex;
	align-items: center;
	gap: var(--sp-2);
	flex-wrap: wrap;
	justify-content: flex-end;
}

.chip {
	padding: var(--sp-1) var(--sp-3);
	background: var(--surface-raised);
	border: 1px solid var(--border);
	border-radius: var(--r-pill);
	font-size: 12px;
	font-weight: 500;
	letter-spacing: 0.04em;
	text-transform: capitalize;
	color: var(--text-muted);
}

.pips {
	display: inline-flex;
	gap: 4px;
	align-items: center;
}

.pips span {
	width: 7px;
	height: 7px;
	border-radius: var(--r-pill);
	background: var(--border-strong);
}

.pips span.is-on {
	background: var(--primary);
}

/* --- Timer ---------------------------------------------------------------- */

.timer__count {
	font-family: var(--font-display);
	font-size: 20px;
	font-weight: 700;
	font-variant-numeric: tabular-nums;
	line-height: 1;
	color: var(--text-muted);
	min-width: 2ch;
	text-align: right;
	transition: color var(--dur-fast) var(--ease-out);
}

.timer__count.is-low {
	color: var(--danger);
}

.timer {
	height: 6px;
	border-radius: var(--r-pill);
	background: var(--surface-raised);
	border: 1px solid var(--border);
	overflow: hidden;
	margin-top: calc(var(--sp-5) * -1 + var(--sp-2));
}

.timer__fill {
	display: block;
	height: 100%;
	background: var(--primary);
	transform-origin: left center;
	/* Driven per frame from app.js; scaleX keeps it off the layout path. */
	transform: scaleX(1);
}

.timer.is-low .timer__fill {
	background: var(--danger);
}

.timer.is-spent {
	opacity: 0.4;
}

/* --- Question ------------------------------------------------------------- */

.question__meta {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: var(--sp-3);
	margin-bottom: var(--sp-4);
}

.question__figure {
	margin: 0 0 var(--sp-5);
	border-radius: var(--r-lg);
	overflow: hidden;
	border: 1px solid var(--border);
	background: var(--surface-raised);
	/* Reserved box keeps the layout from jumping while the image loads. */
	aspect-ratio: 16 / 10;
}

.question__figure img {
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.question__prompt {
	font-size: clamp(21px, 5.5vw, 27px);
	margin-bottom: var(--sp-5);
	text-wrap: balance;
}

.question__prompt:focus {
	outline: none;
}

.answers {
	list-style: none;
	margin: 0;
	padding: 0;
	display: flex;
	flex-direction: column;
	gap: var(--sp-3);
}

.answers li {
	animation: answer-in var(--dur) var(--ease-out) both;
}

@keyframes answer-in {
	from {
		opacity: 0;
		transform: translate3d(0, 8px, 0);
	}
	to {
		opacity: 1;
		transform: none;
	}
}

.answer {
	width: 100%;
	min-height: 60px;
	display: flex;
	align-items: center;
	gap: var(--sp-3);
	padding: var(--sp-3) var(--sp-4);
	text-align: left;
	background: var(--surface-raised);
	border: 1px solid var(--border);
	border-radius: var(--r-md);
	cursor: pointer;
	touch-action: manipulation;
	transition:
		background-color var(--dur-fast) var(--ease-out),
		border-color var(--dur-fast) var(--ease-out),
		transform var(--dur-fast) var(--ease-out);
}

.answer:hover:not(:disabled) {
	background: var(--surface-hover);
	border-color: var(--border-strong);
}

.answer:active:not(:disabled) {
	transform: scale(0.985);
}

.answer:disabled {
	cursor: default;
}

.answer__key {
	flex: none;
	width: 28px;
	height: 28px;
	display: grid;
	place-items: center;
	border-radius: var(--r-sm);
	background: rgba(255, 255, 255, 0.07);
	border: 1px solid var(--border);
	font-size: 13px;
	font-weight: 600;
	font-variant-numeric: tabular-nums;
	color: var(--text-muted);
}

.answer__label {
	flex: 1;
	font-size: 16px;
	font-weight: 500;
}

.answer__mark {
	flex: none;
	width: 22px;
	height: 22px;
	display: none;
}

.answer__mark svg {
	width: 100%;
	height: 100%;
}

/* Result states pair colour with an icon and an announced label, never colour alone. */
.answer.is-correct {
	background: var(--success-dim);
	border-color: var(--success);
}

.answer.is-correct .answer__mark {
	display: block;
	color: var(--success);
}

.answer.is-wrong {
	background: var(--danger-dim);
	border-color: var(--danger);
}

.answer.is-wrong .answer__mark {
	display: block;
	color: var(--danger);
}

.answer.is-muted {
	opacity: 0.45;
}

/* --- Reveal --------------------------------------------------------------- */

.reveal {
	margin-top: var(--sp-5);
	padding-top: var(--sp-5);
	border-top: 1px solid var(--border);
	display: flex;
	flex-direction: column;
	gap: var(--sp-3);
	animation: view-in var(--dur) var(--ease-out) both;
}

.reveal__verdict {
	display: flex;
	align-items: center;
	gap: var(--sp-2);
	font-family: var(--font-display);
	font-weight: 600;
	font-size: 17px;
}

.reveal__verdict svg {
	width: 22px;
	height: 22px;
	flex: none;
}

.reveal__verdict.is-correct {
	color: var(--success);
}

.reveal__verdict.is-wrong {
	color: var(--danger);
}

.reveal__explanation {
	color: var(--text-muted);
	font-size: 15px;
}

.reveal__explanation:empty {
	display: none;
}

/* --- Dialog --------------------------------------------------------------- */

.dialog {
	width: min(calc(100vw - var(--sp-8)), 420px);
	padding: var(--sp-6);
	border: 1px solid var(--border-strong);
	border-radius: var(--r-xl);
	background: var(--surface-solid);
	color: var(--text);
	box-shadow: var(--shadow-lg);
}

.dialog::backdrop {
	/* Strong enough to isolate the dialog from the aurora behind it. */
	background: rgba(5, 4, 11, 0.72);
	backdrop-filter: blur(4px);
}

.dialog__title {
	font-size: 22px;
	margin-bottom: var(--sp-3);
}

.dialog__body {
	color: var(--text-muted);
	font-size: 15px;
}

.dialog__body strong {
	color: var(--primary);
	font-weight: 600;
	font-variant-numeric: tabular-nums;
}

.dialog__actions {
	display: flex;
	flex-direction: column;
	gap: var(--sp-3);
	margin-top: var(--sp-6);
}

/* --- Leaderboard ---------------------------------------------------------- */

.board__title {
	display: flex;
	align-items: center;
	gap: var(--sp-2);
	font-size: 19px;
	margin-bottom: var(--sp-4);
}

.board__title svg {
	width: 20px;
	height: 20px;
	color: var(--primary);
}

.board__list {
	list-style: none;
	margin: 0;
	padding: 0;
	display: flex;
	flex-direction: column;
}

.board__row {
	display: grid;
	grid-template-columns: 32px 1fr auto;
	align-items: center;
	gap: var(--sp-3);
	padding: var(--sp-3) var(--sp-2);
	border-bottom: 1px solid var(--border);
	font-size: 15px;
}

.board__row:last-child {
	border-bottom: 0;
}

.board__rank {
	font-family: var(--font-display);
	font-weight: 600;
	font-variant-numeric: tabular-nums;
	color: var(--text-faint);
	text-align: right;
}

.board__row--podium .board__rank {
	color: var(--warn);
}

.board__name {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	color: var(--text);
}

.board__score {
	font-family: var(--font-display);
	font-weight: 700;
	font-variant-numeric: tabular-nums;
	color: var(--primary);
}

.board__row--you {
	background: rgba(187, 134, 252, 0.12);
	border-radius: var(--r-sm);
	box-shadow: inset 0 0 0 1px rgba(187, 134, 252, 0.4);
}

.board__empty {
	color: var(--text-muted);
	font-size: 15px;
	padding: var(--sp-3) 0;
}

/* --- Game over ------------------------------------------------------------ */

.gameover {
	text-align: center;
}

.gameover__eyebrow {
	font-size: 13px;
	font-weight: 600;
	letter-spacing: 0.12em;
	text-transform: uppercase;
	color: var(--text-faint);
}

.gameover__score {
	font-family: var(--font-display);
	font-size: clamp(64px, 20vw, 88px);
	font-weight: 700;
	line-height: 1;
	font-variant-numeric: tabular-nums;
	color: var(--primary);
	margin: var(--sp-2) 0 var(--sp-1);
}

.gameover__unit {
	display: block;
	font-family: var(--font-body);
	font-size: 15px;
	font-weight: 500;
	letter-spacing: 0.02em;
	color: var(--text-muted);
	margin-top: var(--sp-2);
}

.gameover__name {
	color: var(--text-muted);
	font-size: 15px;
	margin-top: var(--sp-4);
}

.gameover__name strong {
	color: var(--text);
	font-weight: 600;
}

.gameover__rank {
	margin-top: var(--sp-2);
	font-size: 15px;
	color: var(--warn);
}

.gameover__rank:empty {
	display: none;
}

.gameover__actions {
	display: flex;
	flex-direction: column;
	gap: var(--sp-3);
	margin-top: var(--sp-6);
}

.gameover__follow {
	margin-top: var(--sp-5);
	font-size: 14px;
	color: var(--text-muted);
}

.gameover__follow a {
	color: var(--primary);
	font-weight: 600;
	text-decoration: none;
}

.gameover__follow a:hover {
	text-decoration: underline;
}

/* --- Status / errors ------------------------------------------------------ */

.notice {
	display: flex;
	align-items: flex-start;
	gap: var(--sp-3);
	padding: var(--sp-4);
	border-radius: var(--r-md);
	background: var(--danger-dim);
	border: 1px solid var(--danger);
	color: var(--text);
	font-size: 15px;
}

.notice svg {
	width: 20px;
	height: 20px;
	flex: none;
	color: var(--danger);
	margin-top: 2px;
}

.spinner {
	width: 18px;
	height: 18px;
	border-radius: var(--r-pill);
	border: 2px solid rgba(0, 0, 0, 0.25);
	border-top-color: currentColor;
	animation: spin 700ms linear infinite;
}

@keyframes spin {
	to {
		transform: rotate(360deg);
	}
}

/* --- Wider screens -------------------------------------------------------- */

@media (min-width: 768px) {
	.gameover__actions {
		flex-direction: row;
		justify-content: center;
	}

	.gameover__actions .btn {
		flex: 1;
		max-width: 220px;
	}
}

/* --- Reduced motion ------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
	*,
	*::before,
	*::after {
		animation-duration: 0.01ms !important;
		animation-iteration-count: 1 !important;
		transition-duration: 0.01ms !important;
	}

	.aurora {
		animation: none;
	}
}
