:root {
  --bg: #f6f7f5;
  --card: #fff;
  --text: #1a1a1a;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #166534;
  --start: #1d4ed8;
  --finish: #166534;
  --warn: #b45309;
  --error: #b91c1c;
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
}


* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
body.public { padding-bottom: 0; }

#topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
  background: var(--card); border-bottom: 1px solid var(--line); font-size: 14px;
}
#race-name { font-weight: 600; }
.ok { color: var(--accent); }
.warn { color: var(--warn); }
.error { color: var(--error); }
.muted { color: var(--muted); }

#install-hint, #insecure-hint { margin: 8px 16px; padding: 10px 12px; border-radius: 8px; background: #fef3c7; color: #78350f; font-size: 14px; }
#insecure-hint { background: #fee2e2; color: #7f1d1d; }
#update-hint { display: block; width: calc(100% - 32px); margin: 8px 16px; border: 0; background: var(--accent); color: #fff; font-weight: 600; }
#update-hint[hidden] { display: none; }

main { max-width: 900px; margin: 0 auto; padding: 8px 16px 24px; }
h1 { font-size: 22px; margin: 8px 0 12px; }
h2 { font-size: 16px; margin: 16px 0 8px; color: var(--muted); }

#bottom {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
#tabs { display: flex; overflow-x: auto; }
#sync-status { min-height: 18px; padding: 0 16px 4px; font-size: 12px; text-align: center; }
#clock { font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; }
#tabs button {
  flex: 1 0 auto; min-height: 56px; padding: 0 8px;
  border: 0; border-radius: 0; background: none; color: var(--muted);
  font-size: 14px; white-space: nowrap;
}
#tabs button.active { color: var(--accent); font-weight: 700; box-shadow: inset 0 3px 0 var(--accent); }

button {
  font: inherit; min-height: 44px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--card); color: var(--text);
  touch-action: manipulation;
}
button.danger { color: var(--error); }
button.secondary { color: var(--muted); }
button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
button:disabled { opacity: .4; }
button.icon { min-width: 44px; padding: 0; }

input, select, textarea {
  font: inherit; font-size: 16px; min-height: 44px; min-width: 0; padding: 6px 10px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--text);
}
label { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; font-size: 13px; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 6px; margin: 0; font-size: 15px; color: var(--text); }
label.check input { width: 22px; height: 22px; min-height: 0; }

.card { margin-bottom: 12px; padding: 4px 12px 12px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.edit-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 6px; }
.edit-row .grow { flex: 1 1 140px; }
.rider-row { flex-wrap: nowrap; }
.rider-row .narrow { width: 60px; flex: none; }
.rider-row .grow { flex: 1 1 0; }
.rider-row select { flex: 0 1 auto; max-width: 110px; }
.rider-row button.icon { flex: none; }
.narrow { width: 72px; }
.unit { font-size: 13px; color: var(--muted); }
.edit-block { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); }
.checks { display: flex; flex-wrap: wrap; gap: 8px 16px; margin: 4px 0 8px; }
textarea { width: 100%; margin: 8px 0; }
details summary { min-height: 44px; display: flex; align-items: center; color: var(--accent); }
.paste-preview p.error { margin: 4px 0; font-size: 14px; }
.gen-row { display: grid; grid-template-columns: 1fr 72px 72px; gap: 6px; align-items: center; margin-bottom: 6px; }
.gen-row small { grid-column: 1 / -1; margin-top: -2px; }
.gen-head { font-size: 13px; color: var(--muted); }
.public-link a { word-break: break-all; }

.summary { margin: -4px 0 12px; font-size: 14px; }
.row {
  display: flex; align-items: center; gap: 10px; min-height: 64px;
  margin-bottom: 8px; padding: 8px 0 8px 12px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
}
.row .text { flex: 1; min-width: 0; }
.row .who strong { display: block; font-size: 17px; }
.row .who small, .row .info { font-size: 14px; color: var(--muted); }
.row .info [data-since] { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.row button.main {
  align-self: stretch; min-width: 120px; margin: -8px 0;
  border: 0; border-radius: 0 12px 12px 0;
  font-size: 18px; font-weight: 700; color: #fff;
}
.row button.start { background: var(--start); }
.row button.finish { background: var(--finish); }
.row.done, .row.out { padding-right: 12px; opacity: .6; }
.row.invalid { border-color: var(--error); }
.row.invalid .info { color: var(--error); }
.row.flash { animation: flash 1.2s ease-out; }
@keyframes flash { from { box-shadow: 0 0 0 4px #facc15; } to { box-shadow: 0 0 0 0 transparent; } }
.empty { color: var(--muted); }

dialog { width: min(520px, calc(100vw - 32px)); padding: 16px; border: 0; border-radius: 16px; background: var(--card); color: var(--text); }
dialog::backdrop { background: rgba(0, 0, 0, .4); }
.actions, .statuses { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.statuses button { flex: 1; }
.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(100px + env(safe-area-inset-bottom)); z-index: 100;
  padding: 12px 16px; border-radius: 10px; background: #111; color: #fff; text-align: center;
}

.toolbar { display: flex; gap: 8px; margin: 8px 0; }
.category { margin-bottom: 20px; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
th, td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { font-weight: 600; color: var(--muted); }
tr.pending td, tr.out td { color: var(--muted); }
tr.out td { font-style: italic; }
tr.invalid td { color: var(--error); }
.on-track { font-size: 14px; color: var(--muted); }

@media print {
  #topbar, #bottom, #install-hint, #insecure-hint, .toolbar, .no-print { display: none !important; }
  body { padding: 0; background: #fff; color: #000; }
  .category { overflow: visible; break-after: page; }
  .category:last-child { break-after: auto; }
}
