:root {
  --bg: #0d0f12; --panel: #16191f; --panel2: #1e2229; --line: #2a2f38;
  --text: #f2f4f7; --dim: #9aa3af;
  --yellow: #e6c619; --yellow-dark: #b89e0e;
  --red: #d5372f; --red-dark: #a52620;
  --green: #35b558; --blue: #3b82f6;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
.app { max-width: 480px; margin: 0 auto; padding: 12px; }
.wide { max-width: 1500px; }

.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 4px; border-bottom: 1px solid var(--line); margin-bottom: 12px;
  font-size: 14px; color: var(--dim); gap: 10px; flex-wrap: wrap;
}
.topbar .who { color: var(--text); font-weight: 600; }
.topbar .clock { font-variant-numeric: tabular-nums; }
.topbar button { width: auto; padding: 6px 14px; font-size: 13px; }
/* A group of buttons inside the bar needs its own gap — the bar's gap only
   separates the group from the clock, not the buttons within it. */
.topbar .btns { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

h1 { font-size: 26px; text-align: center; margin: 10px 0 2px; }
h2 { font-size: 18px; margin: 18px 0 8px; }
.sub { text-align: center; color: var(--dim); margin-bottom: 14px; }

label { display: block; font-size: 13px; color: var(--dim); margin: 10px 0 4px; }
input, select, textarea {
  width: 100%; padding: 12px; font-size: 18px; color: var(--text);
  background: var(--panel2); border: 1px solid var(--line); border-radius: 8px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue); }

button {
  width: 100%; padding: 14px; font-size: 17px; font-weight: 700;
  border: none; border-radius: 10px; cursor: pointer;
  background: var(--panel2); color: var(--text);
}
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--green); color: #fff; }
button.small { width: auto; padding: 6px 12px; font-size: 13px; font-weight: 600; }
button.danger { background: var(--red); color: #fff; }

.bib-input {
  font-size: 34px; text-align: center; font-weight: 700; letter-spacing: 2px;
}
.athlete-name { text-align: center; font-size: 24px; font-weight: 700; margin: 12px 0; min-height: 32px; }
.athlete-name.found { color: var(--green); }
.athlete-name.notfound { color: var(--red); }
.athlete-name .warn { display:block; font-size: 14px; color: var(--yellow); font-weight: 600; }

.cardgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 14px 0; }
.cardbtn { min-height: 92px; font-size: 19px; line-height: 1.25; border: 3px solid transparent; }
.cardbtn.yellow { background: var(--yellow-dark); color: #3d3505; }
.cardbtn.red { background: var(--red-dark); color: #f8d7d5; }
.cardbtn.selected.yellow { background: var(--yellow); color: #000; border-color: #fff; }
.cardbtn.selected.red { background: var(--red); color: #fff; border-color: #fff; }

.okbtn { margin-top: 6px; background: #3a4149; }
.okbtn.ready { background: var(--green); color: #fff; }

.msg { text-align: center; padding: 10px; border-radius: 8px; margin: 10px 0; font-weight: 600; display: none; }
.msg.ok { display: block; background: #14351f; color: var(--green); }
.msg.err { display: block; background: #3a1512; color: #ff8a80; }
.msg.info { display: block; background: #14263a; color: #7fb4f7; }

.log { margin-top: 18px; font-size: 14px; }
.log .row {
  display: flex; justify-content: space-between; gap: 8px;
  padding: 8px 6px; border-bottom: 1px solid var(--line);
}
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.pill.yellow { background: var(--yellow); color: #000; }
.pill.red { background: var(--red); color: #fff; }
.pill.grey { background: var(--panel2); color: var(--dim); }
.pill.green { background: var(--green); color: #fff; }

table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { border: 1px solid var(--line); padding: 4px 6px; text-align: center; }
th { background: var(--panel); position: sticky; top: 0; }
td.name { text-align: left; white-space: nowrap; }
tr.dq td { background: #2d1210; }
td.rc { font-weight: 700; }
.sym { color: var(--dim); font-size: 11px; }

/* Recorder-only tick: physical-card cross-check on the recorder's grid.
   Double-click a card cell once its paper card is in hand; never rendered
   for any other role or screen. */
#grid td.checkable { cursor: pointer; position: relative; }
#grid td.checkable.checked::after {
  content: '\2713';
  position: absolute; top: 0; right: 2px;
  font-size: 11px; line-height: 1; font-weight: 800; color: var(--green);
}

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; align-items: center; }
.toolbar input, .toolbar select { width: auto; padding: 8px; font-size: 14px; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px; margin-bottom: 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.muted { color: var(--dim); font-size: 13px; }
a { color: var(--blue); }

.offline { background: var(--yellow); color: #000; text-align: center; padding: 6px; border-radius: 8px; font-weight: 700; margin-bottom: 8px; display: none; }

/* Public posting board */
.board { max-width: 1100px; margin: 0 auto; padding: 16px; }
.board h1 { font-size: 34px; }
.board .row {
  display: flex; align-items: center; gap: 18px;
  padding: 14px 18px; border-bottom: 2px solid var(--line); font-size: 30px;
}
.board .bib { font-size: 44px; font-weight: 800; width: 130px; font-variant-numeric: tabular-nums; }
.board .squares { display: flex; gap: 10px; }
.board .sq {
  width: 46px; height: 46px; background: var(--red); border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 800; font-size: 26px;
}
.board .dqtag { margin-left: auto; font-weight: 800; color: var(--red); font-size: 30px; }
.board .pztag { margin-left: auto; font-weight: 800; color: var(--yellow); font-size: 24px; }

.tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.tabs button { background: var(--panel2); }
.tabs button.active { background: var(--blue); color: #fff; }
.hide { display: none !important; }
.pin-reveal { font-size: 22px; font-weight: 800; letter-spacing: 3px; color: var(--yellow); }

/* ---- modal dialog (panel positions) ---- */
.modal-back {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .68);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 24px 12px; overflow: auto; z-index: 50;
}
.modal {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  width: 100%; max-width: 620px; padding: 18px;
}
.modal h2 { margin-top: 0; }
.modal .modal-sub { color: var(--dim); font-size: 13px; margin-bottom: 12px; }
.modal .prow {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 2px; border-bottom: 1px solid var(--line);
}
.modal .prow .rname { flex: 1; min-width: 0; }
.modal .prow .rname b { display: block; font-size: 15px; }
.modal .prow select { width: auto; min-width: 150px; padding: 8px 10px; font-size: 15px; }
.modal .prow.locked { opacity: .62; }
.modal .warn-list { margin: 12px 0 0; }
.modal .warn-list div { color: var(--yellow); font-size: 13px; margin-top: 4px; }
.modal .modal-actions {
  display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; align-items: center;
}
.modal .modal-actions button { width: auto; padding: 10px 16px; font-size: 15px; }
.modal .modal-actions .spacer { flex: 1; }

/* ---- monitor meet chooser ---- */
.meetrow {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 10px 4px; border-bottom: 1px solid var(--line);
}
.meetrow b { font-size: 16px; }

/* ---- logo upload ---- */
.logo-row { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; margin-top: 4px; }
.logo-row .logo-preview {
  max-width: 220px; max-height: 70px; background: #fff; padding: 6px;
  border: 1px solid var(--line); border-radius: 8px;
}
.logo-row .logo-actions { display: flex; flex-direction: column; gap: 6px; }
.logo-row .logo-actions .muted { font-size: 12.5px; max-width: 420px; }
.logo-row input[type=file] { font-size: 13px; }
.logo-row .logo-size { display: flex; align-items: center; gap: 6px; }
.logo-row .logo-size label { margin: 0; font-size: 12px; color: var(--dim); white-space: nowrap; min-width: 150px; }
.logo-row .logo-size input { padding: 5px 8px; font-size: 13px; }

/* ---- Roster import dialog ---- */
.modal.wide { max-width: 860px; }
.modal .ifiles {
  display: flex; flex-wrap: wrap; gap: 14px; margin-top: 10px;
  padding: 12px; border-radius: 10px; background: var(--panel2);
}
.modal .ifiles > span { display: flex; flex-direction: column; gap: 4px; }
.modal .ifiles label { margin: 0; font-size: 12px; color: var(--dim); }
.modal .ifiles input[type=file] { font-size: 13px; }
.modal .ilist { margin-top: 12px; max-height: 46vh; overflow: auto; }
.modal .imeet { padding: 8px 2px 10px; border-bottom: 1px solid var(--line); }
.modal .imeet b { display: block; }
.modal .imeet .muted { font-size: 13px; }
.modal .irow { align-items: flex-start; }
.modal .irow input[type=checkbox] { width: 18px; height: 18px; margin-top: 10px; flex: none; }
.modal .irow .rname { display: flex; flex-direction: column; gap: 3px; }
.modal .irow .iname { width: 100%; font-size: 15px; font-weight: 600; padding: 7px 9px; }
.modal .irow .muted { font-size: 12.5px; }
.modal .irow .iwho { opacity: .8; }
.modal .irow select.iact { min-width: 180px; margin-top: 4px; }
.modal .iwarn { color: var(--yellow); font-size: 12.5px; margin: 2px 0; }

/* ---- panel grid (races across, officials down) ---- */
.gridwrap { overflow: auto; }
table.pgrid { border-collapse: collapse; width: 100%; font-size: 14px; }
table.pgrid th, table.pgrid td {
  border: 1px solid var(--line); padding: 7px 9px; text-align: left; white-space: nowrap;
}
table.pgrid thead th { background: var(--panel2); font-size: 13px; color: var(--dim); }
table.pgrid tbody th { font-weight: 600; text-align: left; }
table.pgrid td.pos { text-align: center; font-weight: 700; }
table.pgrid td.none { color: var(--line); text-align: center; }
table.pgrid tr.clickable { cursor: pointer; }
table.pgrid tr.clickable:hover td, table.pgrid tr.clickable:hover th { background: var(--panel2); }

@media print {
  body { background: #fff; color: #000; }
  .topbar, .tabs, .msg, .toolbar, button, .no-print { display: none !important; }
  .panel, .app { background: #fff; border: 0; max-width: none; padding: 0; }
  h1, h2, p, .muted, label { color: #000; }
  table.pgrid { font-size: 11pt; }
  table.pgrid th, table.pgrid td { border: 1px solid #666; }
  table.pgrid thead th, table.pgrid tbody th { background: #eee; color: #000; }
  table.pgrid td.none { color: #bbb; }
  .print-only { display: block !important; }
}
.print-only { display: none; }

/* A form nested inside a panel — set apart so it reads as a separate task */
.subpanel {
  margin-top: 14px; padding: 14px; border: 1px solid var(--line);
  border-left: 3px solid var(--blue); border-radius: 10px; background: var(--panel2);
}

/* ---- About box ---- */
.modal.about { max-width: 460px; }
.modal.about .arows { margin-top: 10px; }
.modal.about .arow {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 20px; padding: 8px 2px; border-bottom: 1px solid var(--line); font-size: 15px;
}
.modal.about .arow .alabel { color: var(--dim); white-space: nowrap; }
.modal.about .arow .avalue { text-align: right; font-weight: 600; }

/* Race heading on a meet-wide posting board */
.board .boardrace {
  font-size: 26px; margin: 22px 0 6px; padding-bottom: 6px;
  border-bottom: 2px solid var(--line); color: var(--dim);
}
.board .boardrace:first-child { margin-top: 0; }
