/* ==================================================================
 * Backyard Ultra Timer – PHONE APP DESIGN (black & white, big buttons)
 * Easy things to change:
 *   --ink    black          --paper  white
 *   --btn-h  height of each runner button
 *   --btn-w  smallest width of each runner button
 * ================================================================== */
:root {
	--ink: #000;
	--paper: #fff;
	--grey: #8a8a8a;
	--line: #d9d9d9;
	--btn-h: 92px;
	--btn-w: 96px;
	--font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--font); }
body { -webkit-user-select: none; user-select: none; overscroll-behavior: none; }
[hidden] { display: none !important; }
button { font-family: inherit; cursor: pointer; touch-action: manipulation; }

/* ---------- Shared big controls ---------- */
.big-input {
	width: 100%; height: 72px; font-size: 34px; font-weight: 900; text-align: center;
	border: 3px solid var(--ink); border-radius: 10px; background: var(--paper); color: var(--ink);
	font-family: inherit; outline: none; -webkit-user-select: text; user-select: text;
}
.big-input::placeholder { color: #c4c4c4; letter-spacing: 0.1em; }
.big-input:focus { box-shadow: 0 0 0 4px rgba(0, 0, 0, 0.15); }
.big-btn {
	height: 72px; padding: 0 22px; font-size: 24px; font-weight: 900; letter-spacing: 0.04em;
	background: var(--ink); color: var(--paper); border: 3px solid var(--ink); border-radius: 10px;
}
.big-btn:active { transform: scale(0.97); }
.big-btn.ghost { background: var(--paper); color: var(--ink); }
.msg { min-height: 1.4em; font-weight: 700; }

/* ---------- PIN screen ---------- */
.pin-screen {
	min-height: 100vh; display: flex; flex-direction: column; justify-content: center;
	gap: 14px; padding: 24px; max-width: 420px; margin: 0 auto; text-align: center;
}
.pin-logo { width: 120px; height: 120px; object-fit: cover; border-radius: 12px; margin: 0 auto; }
.pin-screen h1 { margin: 0; font-size: 44px; font-weight: 900; text-transform: uppercase; letter-spacing: -0.02em; }
.pin-screen p { margin: 0; color: #555; }

/* ---------- Top bar ---------- */
.top { position: sticky; top: 0; z-index: 5; }
.bar {
	display: flex; align-items: center; gap: 12px;
	padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top));
	background: var(--ink); color: var(--paper);
}
.bar-logo { width: 46px; height: 46px; border-radius: 8px; object-fit: cover; }
.bar-clock { flex: 1; display: flex; flex-direction: column; line-height: 1; min-width: 0; }
.bar-label { font-size: 13px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.1em; opacity: 0.8; }
.bar-time { font-size: 30px; font-weight: 900; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.bar-count { display: flex; flex-direction: column; align-items: center; line-height: 1; }
.bar-count-n { font-size: 28px; font-weight: 900; }
.bar-count-l { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; opacity: 0.75; }
.bar-menu {
	width: 52px; height: 52px; font-size: 26px; border-radius: 10px;
	background: transparent; color: var(--paper); border: 2px solid var(--paper);
}

/* ---------- Sync strip (is everything saved on the website?) ---------- */
.sync {
	display: flex; align-items: center; gap: 8px; padding: 6px 14px;
	font-size: 13px; font-weight: 700; background: var(--paper); color: var(--ink);
	border-bottom: 1px solid var(--line);
}
.sync-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--ink); flex: none; }
.sync-wait { background: #ededed; }
.sync-wait .sync-dot { background: transparent; border: 2px solid var(--ink); animation: blink 1s infinite; }
.sync-bad { background: var(--ink); color: var(--paper); }
.sync-bad .sync-dot { background: var(--paper); }
@keyframes blink { 50% { opacity: 0.2; } }

/* ---------- Bib entry row ---------- */
.entry { display: flex; gap: 10px; padding: 12px; border-bottom: 1px solid var(--line); }
.entry .big-input { flex: 1; }
.entry .big-btn { width: 120px; }

/* ---------- Runner buttons ---------- */
.grid {
	display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--btn-w), 1fr));
	gap: 10px; padding: 12px; padding-bottom: 120px;
}
.runner {
	position: relative; height: var(--btn-h); padding: 6px 4px;
	display: flex; flex-direction: column; align-items: center; justify-content: center;
	background: var(--paper); color: var(--ink); border: 3px solid var(--ink); border-radius: 12px;
	transition: transform 0.08s;
}
.runner:active { transform: scale(0.94); }
.runner-bib { font-size: 36px; font-weight: 900; line-height: 1; font-variant-numeric: tabular-nums; }
.runner-name {
	max-width: 100%; margin-top: 4px; font-size: 15px; font-weight: 700;
	white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.runner-info { font-size: 12px; font-weight: 700; opacity: 0.85; margin-top: 2px; }

/* Already finished this lap: filled black with a tick */
.runner.done { background: var(--ink); color: var(--paper); }
.runner.done::after {
	content: "✓"; position: absolute; top: 4px; right: 8px; font-size: 16px; font-weight: 900;
}
/* Missed a lap (out on time): grey, still tappable to fix a missed tap */
.runner.out { border-color: #bdbdbd; color: #9a9a9a; }
/* DNF: grey dashed, moved to the end of the list */
.runner.dnf { border: 3px dashed #bdbdbd; color: #a8a8a8; background: #f6f6f6; }
.runner.dnf .runner-info, .runner.out .runner-info { font-weight: 900; letter-spacing: 0.1em; }

/* While holding a button: a bar fills along the bottom (hold = DNF) */
.runner { overflow: hidden; -webkit-touch-callout: none; }
.runner.pressing::before {
	content: ""; position: absolute; left: 0; bottom: 0; height: 6px; width: 0;
	background: #8a8a8a; animation: hold 0.8s linear forwards;
}
@keyframes hold { to { width: 100%; } }

/* Short flash right after a tap */
.runner.flash { animation: flash 0.5s ease-out; }
@keyframes flash { 0% { transform: scale(1.12); } 100% { transform: scale(1); } }

/* ---------- Toast (bottom message with UNDO) ---------- */
.toast {
	position: fixed; left: 12px; right: 12px; bottom: max(12px, env(safe-area-inset-bottom)); z-index: 45;
	display: flex; align-items: center; gap: 12px; padding: 14px 14px 14px 18px;
	background: var(--ink); color: var(--paper); border-radius: 14px;
	box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}
.toast-text { flex: 1; font-size: 18px; line-height: 1.25; }
.toast-text b { font-size: 22px; }
.toast-undo {
	height: 56px; padding: 0 18px; font-size: 18px; font-weight: 900;
	background: var(--paper); color: var(--ink); border: 0; border-radius: 10px;
}
.toast.error { background: var(--paper); color: var(--ink); border: 3px solid var(--ink); }

/* ---------- Overlays (question + menu) ----------
 * Stacking order (higher = on top): menu 30, question 40, toast 45, winner 60 */
#ask { z-index: 40; }
.overlay {
	position: fixed; inset: 0; z-index: 30; background: rgba(0, 0, 0, 0.55);
	display: flex; align-items: flex-end; justify-content: center;
}
.ask-box, .sheet {
	width: 100%; max-width: 560px; background: var(--paper); color: var(--ink);
	border-radius: 18px 18px 0 0; padding: 20px 16px max(20px, env(safe-area-inset-bottom));
}
.ask-box p { font-size: 22px; font-weight: 700; margin: 4px 0 18px; line-height: 1.3; }
.ask-btns { display: flex; gap: 10px; }
.ask-btns .big-btn { flex: 1; }

.sheet { max-height: 85vh; display: flex; flex-direction: column; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; font-size: 20px; margin-bottom: 8px; }
.sheet-close { width: 48px; height: 48px; font-size: 22px; background: none; border: 2px solid var(--ink); border-radius: 10px; }
.tap-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.tap-list li {
	display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line);
	font-variant-numeric: tabular-nums;
}
.tap-bib { font-size: 26px; font-weight: 900; width: 58px; }
.tap-main { flex: 1; min-width: 0; }
.tap-main div:first-child { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tap-main div:last-child { font-size: 13px; color: #555; }
.tap-undo { height: 44px; padding: 0 14px; font-weight: 800; background: var(--paper); border: 2px solid var(--ink); border-radius: 8px; }
.tap-empty { color: var(--grey); padding: 14px 0; }
.sheet-tools { flex: none; display: flex; gap: 10px; margin-top: 14px; }
.sheet-tools .big-btn { flex: 1; height: 56px; font-size: 16px; padding: 0 8px; }
.sheet-note { font-size: 12px; color: var(--grey); text-align: center; margin: 10px 0 0; }

/* ---------- Winner screen ---------- */
.overlay.winner { align-items: center; background: var(--ink); z-index: 60; }
.winner-box { color: var(--paper); text-align: center; padding: 24px; width: 100%; max-width: 480px; }
.winner-k { font-size: 22px; font-weight: 900; letter-spacing: 0.4em; text-transform: uppercase; }
.winner-bib { font-size: 120px; font-weight: 900; line-height: 1; margin: 16px 0 6px; }
.winner-name { font-size: 32px; font-weight: 800; }
.winner-stats { font-size: 20px; opacity: 0.8; margin: 8px 0 32px; }
.winner-box .big-btn { width: 100%; }

/* ---------- Install button + iPhone hint in the menu (step 6) ---------- */
.install-btn { flex: none; width: 100%; height: 60px; font-size: 18px; margin-top: 12px; }
.install-hint {
	margin: 12px 0 0; padding: 12px 14px; border: 2px dashed var(--ink); border-radius: 10px;
	font-size: 15px; line-height: 1.35; text-align: center;
}

/* ---------- Step 7: star = beat their predicted laps ---------- */
.runner-star { position: absolute; top: 3px; left: 8px; font-size: 15px; }

/* ---------- Check-in screen (0.8) ---------- */
.checkin-open { flex: none; width: 100%; height: 60px; font-size: 19px; margin-top: 12px; }
.ci-screen {
	position: fixed; inset: 0; z-index: 35; background: var(--paper);
	display: flex; flex-direction: column; overflow: hidden;
}
.ci-bar {
	display: flex; align-items: center; gap: 12px; padding: 12px 14px;
	padding-top: max(12px, env(safe-area-inset-top)); background: var(--ink); color: var(--paper);
}
.ci-title { flex: 1; font-size: 24px; font-weight: 900; text-transform: uppercase; letter-spacing: 0.02em; }
.ci-title span { display: block; font-size: 13px; font-weight: 700; opacity: 0.75; letter-spacing: 0.06em; }
.ci-close { width: 52px; height: 52px; font-size: 24px; border-radius: 10px; background: transparent; color: var(--paper); border: 2px solid var(--paper); }
.ci-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 12px; border-bottom: 1px solid var(--line); }
.ci-search {
	flex: 1 1 100%; min-width: 0; height: 54px; font-size: 20px; padding: 0 14px; font-family: inherit;
	border: 3px solid var(--ink); border-radius: 10px; -webkit-user-select: text; user-select: text;
}
.ci-hide { font-size: 15px; font-weight: 700; display: flex; align-items: center; gap: 6px; }
.ci-hide input { width: 22px; height: 22px; }
.ci-msg { margin: 10px 12px 0; padding: 12px 14px; border-radius: 10px; background: var(--ink); color: var(--paper); font-weight: 700; }
.ci-msg.err { background: var(--paper); color: var(--ink); border: 3px solid var(--ink); }
.ci-list { flex: 1; overflow-y: auto; padding: 4px 12px 40px; -webkit-overflow-scrolling: touch; }
.ci-row {
	display: grid; grid-template-columns: minmax(0, 1fr) 74px 108px; align-items: center; gap: 10px;
	padding: 10px 12px; margin: 10px 0; border: 3px solid var(--ink); border-radius: 12px;
}
.ci-row.in { background: var(--ink); color: var(--paper); }
.ci-name { min-width: 0; font-size: 16px; font-weight: 800; line-height: 1.2; overflow-wrap: anywhere; }
.ci-name small { display: block; font-size: 12px; font-weight: 500; opacity: 0.75; margin-top: 2px; }
.ci-bib {
	width: 74px; height: 56px; font-size: 26px; font-weight: 900; text-align: center; font-family: inherit;
	border: 3px solid var(--ink); border-radius: 10px; background: var(--paper); color: var(--ink);
	-webkit-user-select: text; user-select: text;
}
.ci-btn {
	height: 56px; font-size: 15px; font-weight: 900; border-radius: 10px;
	background: var(--ink); color: var(--paper); border: 3px solid var(--ink);
}
.ci-row.in .ci-btn { background: var(--paper); color: var(--ink); border-color: var(--paper); }
.ci-btn:disabled { opacity: 0.5; }
.ci-empty { padding: 20px 4px; color: var(--grey); }
@media (max-width: 360px) {
	.ci-row { grid-template-columns: minmax(0, 1fr) 74px; }
	.ci-btn { grid-column: 1 / -1; }
}

/* ---------- 1.0: empty timer screen + runners without a bib ---------- */
.grid-empty { grid-column: 1 / -1; text-align: center; padding: 40px 10px; }
.grid-empty p { font-size: 20px; font-weight: 700; margin: 0 0 16px; }
.grid-empty .big-btn { width: 100%; max-width: 360px; }
.ci-bib::placeholder { color: #c4c4c4; }
.ci-row.nobib .ci-bib { border-style: dashed; }
