* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, Arial, sans-serif; background: #f4f4f4; color: #111; }
h1 { text-align: center; margin-bottom: 8px; }
button { border: 0; border-radius: 8px; padding: 10px 14px; cursor: pointer; background: #32832b; color: white; font-weight: 700; }
button.secondary { background: #666; }
button.danger { background: #b71c1c; }
button.big { font-size: 24px; padding: 18px 30px; margin: 14px 0; }
table { width: 100%; border-collapse: collapse; margin-top: 12px; background: white; }
th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
th { background: #eee; cursor: pointer; }
tr.invalid { opacity: .55; text-decoration: line-through; }
input, select { padding: 10px; border: 1px solid #bbb; border-radius: 8px; font-size: 16px; }
#loginBtn { white-space: nowrap; }
.app { max-width: 1200px; margin: 0 auto; padding: 16px; }
.topbar, .tabs, .formgrid, .number-control { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.topbar { justify-content: space-between; margin-bottom: 12px; }
.card { background: white; border-radius: 10px; padding: 16px; margin-top: 12px; box-shadow: 0 2px 10px rgba(0,0,0,.08); }
.hidden { display: none !important; }
.menu { width: calc((100% - 30px)/4); }
.tabs button.active { background: #155b12; }
.number-control input { width: 120px; text-align: center; font-size: 24px; }
.number-control button { font-size: 24px; width: 56px; }
.grid-buttons { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; margin: 14px 0; }
.grid-buttons button { aspect-ratio: 1/1; font-size: 32px;  font-weight: bold; }
.grid-buttons button small { font-size: 16px; }
.msg { color: #b71c1c; }
.race-item { display: flex; justify-content: space-between; gap: 8px; align-items: center; padding: 8px; border-bottom: 1px solid #ddd; }
.race-item small { color: #555; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.split-buttons { display: flex; flex-wrap: wrap; gap: 10px; margin: 12px 0; }
.split-select-btn { width: calc((100% - 40px) / 5); background: #1976d2; }
.split-select-btn.active { background: #0d47a1; }
.grid-message { grid-column: 1 / -1; text-align: center; font-weight: bold; padding: 0 0 10px 0; }
.login-row { display: flex; align-items: end; gap: 1rem; flex-wrap: nowrap; }
.login-row .form-row { display: flex; flex-direction: column; }
.start-row { display: flex; gap: 12px; align-items: center; margin-bottom: 15px; }
.start-row #startName { flex: 1; min-width: 180px; }
.start-row #startBtn { white-space: nowrap; }
.report-title-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.section-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.right { text-align: right; }
.center { text-align: center; }
.report-block { margin-top: 18px; padding-top: 14px; border-top: 1px solid #ddd; }
.report-block h3 { margin-top: 0; }
.bib-not-started { background: #bdbdbd; color: #333; cursor: not-allowed; }
.bib-active { background: #2e7d32; color: white; }
.bib-done { background: #81c784; cursor: not-allowed; }
.category-row td { background: #eeeeee; font-weight: bold; padding-top: 12px; padding-bottom: 12px; }
.login-toggle-row { display: flex; justify-content: flex-end; margin: 10px 0; }
#startlistEditor { display: grid; grid-template-columns: 1fr auto auto; gap: 12px; align-items: start; margin-top: 18px; padding-top: 18px; border-top: 1px solid #ddd; }
#startlistName { grid-column: 1 / 2; width: 100%; }
#startlistContent { grid-column: 1 / -1; width: 100%; min-height: 420px; font-family: monospace; font-size: 16px; line-height: 1.35; }
#saveStartlistBtn, #cancelStartlistBtn { width: fit-content; }
#startlistMsg { margin: 0; align-self: center; }
.ready-panel { margin: 12px 0 18px 0; padding: 12px; border: 1px solid #ddd; border-radius: 10px; background: #f7f7f7; }
.ready-title { font-weight: bold; margin-bottom: 8px; }
.ready-bar { display: flex; gap: 6px; margin-bottom: 10px; }
.ready-segment { flex: 1; padding: 6px 8px; text-align: center; border-radius: 8px; background: #9e9e9e; color: white; font-weight: bold; }
.ready-segment.ready { background: #1b5e20; }
.ready-segment.all-ready { box-shadow: 0 0 10px rgba(27, 94, 32, .8); }
.ready-button { margin-top: 8px; }
.ready-row { display: flex; gap: 10px; align-items: center; }
.ready-row .ready-bar { flex: 1; margin-bottom: 0; }
.ready-row .ready-button { margin-top: 0; white-space: nowrap; }


@media (max-width: 1200px) {
	main{ width: 100%; }
	#loginBtn { width: 100%; }
	.login-row { flex-wrap: wrap; }
}

@media (max-width: 700px) {
	#loginBtn { width: 100%; max-width: 300px; }
	#loginBox h2 { text-align: center; }
	.topbar, .race-item { display: block; }
	.actions { margin-top: 8px; }
	.login-row { flex-direction: column; align-items: center; }
	.login-row .form-row { width: 100%; max-width: 300px; }
	.start-row { flex-wrap: wrap; }
	.start-row .number-control { width: 100%; justify-content: center; }
	.start-row #startName { flex: 1; }
	.report-title-row { flex-direction: column; align-items: stretch; }
	.section-header { flex-direction: column; align-items: stretch; }
	.formgrid { display: flex; flex-wrap: wrap; gap: 10px; }
	#raceName { width: 100%; }
	#splitCountWrap { display: flex; align-items: center; gap: 8px;  margin-top: 4px;}
	#splitCountWrap { flex: 1; flex-basis: 100%; }
	#splitCount { width: 60px; }
	#createRaceBtn { flex: 0 0 auto; }
}
