/* FGC Scoreboard Controller — product UI, mobile-first */

:root {
	--bg: oklch(14% 0.01 260);
	--surface: oklch(20% 0.015 260);
	--surface-raised: oklch(24% 0.015 260);
	--border: oklch(32% 0.015 260);
	--border-strong: oklch(40% 0.015 260);
	--text: oklch(94% 0.01 260);
	--text-muted: oklch(68% 0.02 260);
	--text-subtle: oklch(62% 0.02 260);
	--p1: oklch(62% 0.2 25);
	--p1-soft: var(--surface);
	--p2: oklch(58% 0.14 250);
	--p2-soft: var(--surface);
	--accent: oklch(78% 0.12 145);
	--accent-ink: oklch(18% 0.04 145);
	--danger: oklch(65% 0.2 25);
	--success: oklch(72% 0.16 145);
	--warning: oklch(82% 0.14 95);
	--warning-ink: oklch(22% 0.04 95);
	--radius-sm: 6px;
	--radius-md: 10px;
	--radius-lg: 14px;
	--touch-min: 48px;
	--space-1: 4px;
	--space-2: 8px;
	--space-3: 12px;
	--space-4: 16px;
	--space-5: 20px;
	--space-6: 24px;
	--font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
	--font-mono: ui-monospace, "SF Mono", "Cascadia Code", monospace;
	--shadow-sm: 0 1px 2px oklch(0% 0 0 / 0.25);
	--shadow-md: 0 4px 16px oklch(0% 0 0 / 0.35);
	--z-sticky: 20;
	--z-modal: 100;
}

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

*,
*::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);
	font-size: 16px;
	line-height: 1.45;
	padding: var(--space-4);
	padding-left: max(var(--space-4), env(safe-area-inset-left));
	padding-right: max(var(--space-4), env(safe-area-inset-right));
	max-width: 720px;
	margin-inline: auto;
}

body.has-sticky-actions {
	padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px));
}

.skip-link {
	position: absolute;
	left: -9999px;
	top: auto;
	width: 1px;
	height: 1px;
	overflow: hidden;
	z-index: calc(var(--z-modal) + 1);
	background: var(--accent);
	color: var(--accent-ink);
	font-weight: 600;
	padding: var(--space-3) var(--space-4);
	border-radius: var(--radius-sm);
	text-decoration: none;
}

.skip-link:focus {
	position: fixed;
	left: var(--space-4);
	top: var(--space-4);
	width: auto;
	height: auto;
	overflow: visible;
}

.visually-hidden {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

/* --- Header --- */

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

.app-title {
	margin: 0;
	font-size: 1.125rem;
	font-weight: 650;
	letter-spacing: -0.02em;
	text-wrap: balance;
}

.header-actions {
	display: flex;
	align-items: center;
	gap: var(--space-2);
	flex-shrink: 0;
}

#lock-btn {
	appearance: none;
	background: var(--surface);
	color: var(--text-muted);
	border: 1px solid var(--border);
	border-radius: var(--radius-sm);
	font: inherit;
	font-size: 0.8125rem;
	font-weight: 600;
	padding: 0 var(--space-3);
	min-height: var(--touch-min);
	cursor: pointer;
	touch-action: manipulation;
}

#lock-btn[hidden] {
	display: none !important;
}

#lock-btn:focus-visible {
	outline: 2px solid var(--text);
	outline-offset: 2px;
}

/* --- Banners --- */

.banner {
	border-radius: var(--radius-md);
	padding: var(--space-3) var(--space-4);
	margin-bottom: var(--space-4);
	font-size: 0.875rem;
	line-height: 1.4;
	display: none;
}

.banner.is-visible {
	display: block;
}

#no-bin-warning {
	background: color-mix(in oklch, var(--warning) 18%, var(--surface));
	color: var(--text);
	border: 1px solid color-mix(in oklch, var(--warning) 40%, var(--border));
}

#no-bin-warning a {
	color: var(--warning);
	font-weight: 600;
}

/* --- Player cards --- */

.players-grid {
	display: grid;
	grid-template-columns: 1fr;
	gap: var(--space-3);
	margin-bottom: var(--space-4);
}

@media (min-width: 720px) {
	.players-grid {
		grid-template-columns: 1fr 1fr;
		gap: var(--space-4);
	}
}

.player-card {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius-lg);
	overflow: hidden;
	min-width: 0;
}

.player-card.p1 {
	background: var(--p1-soft);
}

.player-card.p2 {
	background: var(--p2-soft);
}

.player-card fieldset {
	border: none;
	margin: 0;
	padding: 0;
	min-width: 0;
	width: 100%;
	display: flex;
	flex-direction: column;
}

.player-header {
	display: flex;
	align-items: center;
	gap: var(--space-2);
	padding: var(--space-3) var(--space-4);
	border-bottom: 1px solid color-mix(in oklch, var(--border) 70%, transparent);
}

.player-card.p1 .player-header {
	background: color-mix(in oklch, var(--p1) 22%, transparent);
}

.player-card.p2 .player-header {
	background: color-mix(in oklch, var(--p2) 22%, transparent);
}

.player-dot {
	width: 10px;
	height: 10px;
	border-radius: 50%;
	flex-shrink: 0;
}

.player-card.p1 .player-dot {
	background: var(--p1);
}

.player-card.p2 .player-dot {
	background: var(--p2);
}

.panel-title {
	font-size: 0.8125rem;
	font-weight: 650;
	margin: 0;
	padding: 0;
	color: var(--text);
}

.player-body {
	padding: var(--space-4);
	display: flex;
	flex-direction: column;
	gap: var(--space-3);
	min-width: 0;
}

/* --- Fields --- */

.field-row {
	display: flex;
	flex-direction: column;
	gap: var(--space-3);
}

@media (min-width: 400px) {
	.field-row {
		flex-direction: row;
	}
}

.field {
	flex: 1;
	display: flex;
	flex-direction: column;
	min-width: 0;
	gap: var(--space-1);
}

.field label {
	font-size: 0.75rem;
	font-weight: 600;
	color: var(--text-muted);
}

.field input,
.field select {
	appearance: none;
	background: var(--bg);
	border: 1px solid var(--border);
	border-radius: var(--radius-sm);
	color: var(--text);
	font: inherit;
	font-size: 1rem;
	padding: 0 var(--space-3);
	width: 100%;
	min-height: var(--touch-min);
}

.field input::placeholder {
	color: var(--text-subtle);
}

.field input:focus-visible,
.field select:focus-visible {
	outline: 2px solid var(--text);
	outline-offset: 1px;
	border-color: var(--border-strong);
}

@media (min-width: 400px) {
	.field-team {
		flex: 0 0 96px;
		max-width: 120px;
	}
}

.field-hint {
	font-size: 0.8125rem;
	color: var(--text-subtle);
	margin: var(--space-1) 0 0;
}

.game-mode-toggle {
	appearance: none;
	background: none;
	border: none;
	color: var(--p2);
	font: inherit;
	font-size: 0.8125rem;
	font-weight: 600;
	padding: var(--space-2) 0 0;
	margin: 0;
	cursor: pointer;
	text-align: left;
	min-height: auto;
	text-decoration: underline;
	text-underline-offset: 2px;
	touch-action: manipulation;
}

.game-mode-toggle:focus-visible {
	outline: 2px solid var(--p2);
	outline-offset: 2px;
	border-radius: 2px;
}

.game-field [hidden] {
	display: none !important;
}

/* --- Score stepper --- */

.score-stepper {
	display: flex;
	flex-direction: row;
	align-items: stretch;
	width: 100%;
	min-width: 0;
	border: 1px solid var(--border);
	border-radius: var(--radius-md);
	overflow: hidden;
	background: var(--bg);
}

.score-stepper .score-btn {
	appearance: none;
	margin: 0;
	padding: 0;
	border: none;
	border-radius: 0;
	font-size: 1.5rem;
	font-weight: 700;
	line-height: 1;
	flex: 0 0 var(--touch-min);
	width: var(--touch-min);
	min-width: var(--touch-min);
	max-width: var(--touch-min);
	min-height: 56px;
	cursor: pointer;
	touch-action: manipulation;
	user-select: none;
	-webkit-tap-highlight-color: transparent;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: background 150ms ease-out, transform 80ms ease-out;
}

.p1 .score-btn {
	background: color-mix(in oklch, var(--p1) 85%, black);
	color: white;
}

.p2 .score-btn {
	background: color-mix(in oklch, var(--p2) 85%, black);
	color: white;
}

.score-stepper .score-btn:active {
	transform: scale(0.96);
}

.score-stepper .score-btn:focus-visible {
	outline: 2px solid var(--text);
	outline-offset: -2px;
	z-index: 1;
}

.score-display {
	margin: 0;
	padding: 0;
	border: none;
	border-left: 1px solid var(--border);
	border-right: 1px solid var(--border);
	border-radius: 0;
	background: var(--surface-raised);
	color: var(--text);
	font-size: clamp(1.5rem, 6vw, 2rem);
	font-weight: 700;
	font-variant-numeric: tabular-nums;
	font-family: var(--font-mono);
	text-align: center;
	flex: 1 1 0;
	width: 0;
	min-width: 0;
	min-height: 56px;
	box-sizing: border-box;
	-webkit-appearance: none;
	appearance: none;
	cursor: text;
	line-height: 56px;
}

.score-display:focus-visible {
	outline: 2px solid var(--text);
	outline-offset: -2px;
}

/* --- Match panel --- */

.match-panel {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius-lg);
	padding: var(--space-4);
	margin-bottom: var(--space-4);
}

.match-panel fieldset {
	border: none;
	margin: 0;
	padding: 0;
	min-width: 0;
}

.match-panel .panel-title {
	font-size: 0.75rem;
	font-weight: 650;
	color: var(--text-muted);
	text-transform: uppercase;
	letter-spacing: 0.04em;
	margin-bottom: var(--space-3);
}

.match-panel .field-row {
	margin-bottom: var(--space-3);
}

.match-panel .field-row:last-child {
	margin-bottom: 0;
}

/* --- Counters --- */

.counters-section {
	margin-bottom: var(--space-4);
	border: 1px solid var(--border);
	border-radius: var(--radius-lg);
	background: var(--surface);
	overflow: hidden;
}

.counters-section > summary {
	cursor: pointer;
	font-size: 0.875rem;
	font-weight: 600;
	color: var(--text-muted);
	padding: var(--space-4);
	list-style: none;
	user-select: none;
	touch-action: manipulation;
}

.counters-section > summary::-webkit-details-marker {
	display: none;
}

.counters-section > summary::before {
	content: "+ ";
	font-weight: 700;
	color: var(--text-subtle);
}

.counters-section[open] > summary::before {
	content: "− ";
}

.counters-section > summary:focus-visible {
	outline: 2px solid var(--text);
	outline-offset: -2px;
}

.counters-inner {
	padding: 0 var(--space-4) var(--space-4);
	border-top: 1px solid var(--border);
}

.counters-empty-hint {
	font-size: 0.8125rem;
	color: var(--text-subtle);
	margin: var(--space-3) 0 var(--space-4);
	line-height: 1.45;
}

.counters-empty-hint code {
	font-family: var(--font-mono);
	font-size: 0.75rem;
	background: var(--bg);
	padding: 2px 6px;
	border-radius: 4px;
}

.counters-list {
	display: flex;
	flex-direction: column;
	gap: var(--space-3);
	margin-bottom: var(--space-3);
}

.counter-row {
	display: flex;
	flex-direction: column;
	gap: var(--space-3);
	padding: var(--space-3);
	background: var(--bg);
	border: 1px solid var(--border);
	border-radius: var(--radius-md);
}

.counter-label-field label {
	display: block;
	font-size: 0.75rem;
	font-weight: 600;
	color: var(--text-muted);
	margin-bottom: var(--space-1);
}

.counter-label-field input {
	width: 100%;
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius-sm);
	color: var(--text);
	font: inherit;
	font-size: 1rem;
	padding: 0 var(--space-3);
	min-height: 44px;
}

.counter-row-actions {
	display: flex;
	align-items: flex-end;
	justify-content: space-between;
	gap: var(--space-3);
	width: 100%;
}

.counter-stepper-wrap {
	flex: 1 1 auto;
	min-width: 0;
	display: flex;
	flex-direction: column;
	gap: var(--space-1);
}

.counter-stepper-wrap .stepper-label {
	font-size: 0.75rem;
	font-weight: 600;
	color: var(--text-muted);
}

.counter-stepper {
	display: flex;
	flex-direction: row;
	align-items: stretch;
	width: 100%;
	min-width: 0;
	border: 1px solid var(--border);
	border-radius: var(--radius-sm);
	overflow: hidden;
}

.counter-stepper .counter-btn {
	appearance: none;
	margin: 0;
	padding: 0;
	border: none;
	background: var(--surface-raised);
	color: var(--text);
	font-size: 1.25rem;
	font-weight: 700;
	flex: 0 0 44px;
	width: 44px;
	min-width: 44px;
	max-width: 44px;
	min-height: 44px;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	touch-action: manipulation;
}

.counter-stepper .counter-btn:focus-visible,
.counter-stepper .counter-value:focus-visible,
.counter-label-field input:focus-visible {
	outline: 2px solid var(--text);
	outline-offset: -2px;
}

.counter-stepper .counter-value {
	margin: 0;
	padding: 0;
	border: none;
	border-left: 1px solid var(--border);
	border-right: 1px solid var(--border);
	background: var(--bg);
	color: var(--text);
	font-size: 1.25rem;
	font-weight: 700;
	font-variant-numeric: tabular-nums;
	font-family: var(--font-mono);
	text-align: center;
	flex: 1 1 0;
	width: 0;
	min-width: 0;
	min-height: 44px;
	box-sizing: border-box;
	-webkit-appearance: none;
	appearance: none;
	cursor: text;
	line-height: 44px;
}

.counter-remove {
	appearance: none;
	flex: 0 0 auto;
	background: transparent;
	border: 1px solid var(--border);
	border-radius: var(--radius-sm);
	color: var(--text-muted);
	font: inherit;
	font-size: 0.8125rem;
	font-weight: 600;
	padding: 0 var(--space-3);
	min-height: 44px;
	cursor: pointer;
	touch-action: manipulation;
}

.btn-add-counter {
	appearance: none;
	width: 100%;
	background: var(--surface-raised);
	border: 1px dashed var(--border-strong);
	border-radius: var(--radius-md);
	color: var(--text-muted);
	font: inherit;
	font-size: 0.875rem;
	font-weight: 600;
	padding: var(--space-3);
	min-height: var(--touch-min);
	cursor: pointer;
	touch-action: manipulation;
}

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

/* --- Actions --- */

.actions-wrap {
	display: flex;
	flex-direction: column;
	gap: var(--space-3);
}

.button-row {
	display: flex;
	gap: var(--space-2);
}

.button-row button {
	appearance: none;
	flex: 1;
	border-radius: var(--radius-md);
	font: inherit;
	font-size: 0.9375rem;
	font-weight: 650;
	padding: 0 var(--space-4);
	cursor: pointer;
	min-height: var(--touch-min);
	touch-action: manipulation;
	user-select: none;
	-webkit-tap-highlight-color: transparent;
	transition: background 150ms ease-out, transform 80ms ease-out;
}

.button-row button:focus-visible {
	outline: 2px solid var(--text);
	outline-offset: 2px;
}

.button-row button:active {
	transform: scale(0.98);
}

.btn-save {
	background: var(--accent);
	color: var(--accent-ink);
	border: none;
}

.btn-swap {
	background: var(--surface-raised);
	color: var(--text);
	border: 1px solid var(--border);
}

.btn-reset,
.btn-clear {
	background: transparent;
	color: var(--text-muted);
	border: 1px solid var(--border);
	font-size: 0.875rem;
	font-weight: 600;
}

.actions-secondary {
	margin-bottom: var(--space-1);
}

@media (max-width: 719px) {
	.actions-primary {
		position: fixed;
		left: 0;
		right: 0;
		bottom: 0;
		z-index: var(--z-sticky);
		margin: 0;
		padding: var(--space-3) var(--space-4);
		padding-bottom: calc(var(--space-3) + env(safe-area-inset-bottom, 0px));
		padding-left: max(var(--space-4), env(safe-area-inset-left));
		padding-right: max(var(--space-4), env(safe-area-inset-right));
		background: var(--bg);
		border-top: 1px solid var(--border);
		box-shadow: var(--shadow-md);
	}

	.actions-primary .btn-save,
	.actions-primary .btn-swap {
		min-height: 52px;
	}
}

/* --- Status --- */

#status {
	text-align: center;
	font-size: 0.8125rem;
	font-weight: 600;
	padding: var(--space-2) var(--space-3);
	margin-top: var(--space-3);
	border-radius: var(--radius-sm);
	visibility: hidden;
	min-height: 2rem;
	display: flex;
	align-items: center;
	justify-content: center;
}

.status-ok {
	background: color-mix(in oklch, var(--success) 20%, var(--surface));
	color: var(--success);
}

.status-err {
	background: color-mix(in oklch, var(--danger) 18%, var(--surface));
	color: color-mix(in oklch, var(--danger) 80%, white);
}

.status-loading {
	background: color-mix(in oklch, var(--warning) 18%, var(--surface));
	color: var(--warning);
}

/* --- Auth gate --- */

#auth-gate {
	position: fixed;
	inset: 0;
	z-index: var(--z-modal);
	background: color-mix(in oklch, var(--bg) 94%, transparent);
	display: flex;
	align-items: center;
	justify-content: center;
	padding: var(--space-4);
	padding-left: max(var(--space-4), env(safe-area-inset-left));
	padding-right: max(var(--space-4), env(safe-area-inset-right));
}

#auth-gate[hidden] {
	display: none !important;
}

.auth-gate-panel {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius-lg);
	box-shadow: var(--shadow-md);
	padding: var(--space-6);
	width: 100%;
	max-width: 360px;
}

.auth-gate-panel h2 {
	text-align: center;
	font-size: 1.125rem;
	font-weight: 650;
	margin: 0 0 var(--space-4);
}

.auth-gate-panel label {
	display: block;
	font-size: 0.8125rem;
	font-weight: 600;
	color: var(--text-muted);
	margin-bottom: var(--space-2);
}

.auth-gate-panel input {
	width: 100%;
	background: var(--bg);
	border: 1px solid var(--border);
	border-radius: var(--radius-sm);
	color: var(--text);
	font: inherit;
	font-size: 1rem;
	padding: 0 var(--space-3);
	margin-bottom: var(--space-3);
	min-height: var(--touch-min);
}

.auth-gate-panel input:focus-visible {
	outline: 2px solid var(--text);
	outline-offset: 2px;
}

.auth-gate-panel button[type="submit"] {
	appearance: none;
	width: 100%;
	background: var(--accent);
	color: var(--accent-ink);
	border: none;
	border-radius: var(--radius-md);
	font: inherit;
	font-weight: 650;
	font-size: 1rem;
	padding: 0 var(--space-4);
	cursor: pointer;
	min-height: var(--touch-min);
}

.auth-gate-panel button:focus-visible {
	outline: 2px solid var(--text);
	outline-offset: 2px;
}

#auth-gate-error {
	color: var(--danger);
	font-size: 0.875rem;
	font-weight: 600;
	text-align: center;
	margin: var(--space-3) 0 0;
	min-height: 1.25em;
}
