:root {
  --bg: #f4f6f9; --card: #fff; --ink: #18202c; --muted: #5f6b7a; --line: #d8dee6;
  --accent: #1f6feb; --accent-ink: #fff; --red: #d1242f; --blue: #1f5fbf;
  --red-soft: #fde8ea; --blue-soft: #e5eefc; --ok: #1a7f37; --ok-soft: #dcf5e3;
  --warn: #9a6700; --warn-soft: #fff4d4; --btn: #e9edf2; --btn-on: #1f6feb;
  --tap: 56px; --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141b; --card: #18202b; --ink: #e6ebf1; --muted: #93a0b0; --line: #2b3646;
    --accent: #4c8dff; --red: #ff6b6b; --blue: #6ea8ff; --red-soft: #3a1d22; --blue-soft: #1a2a45;
    --ok: #4ac26b; --ok-soft: #173622; --warn: #e3b341; --warn-soft: #3a2f12; --btn: #253041; --btn-on: #4c8dff;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink);
  font: 17px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
body { padding-bottom: env(safe-area-inset-bottom); }
h1 { font-size: 1.7rem; margin: .4em 0; }
h2 { font-size: 1.15rem; margin: 0 0 .5em; letter-spacing: .02em; }
h3 { font-size: 1.05rem; margin: 1.2em 0 .5em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.grow { flex: 1; }
.mono { font-family: ui-monospace, Consolas, monospace; }
.page { max-width: 900px; margin: 0 auto; padding: 12px 16px 120px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row.center { justify-content: center; margin-top: 8px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 10px 0; }
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* buttons */
.btn { appearance: none; border: 0; border-radius: 10px; background: var(--btn); color: var(--ink);
  font: inherit; font-weight: 600; min-height: 44px; padding: 8px 14px; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; touch-action: manipulation;
  -webkit-tap-highlight-color: transparent; user-select: none; }
.btn:active { filter: brightness(.9); }
.btn:disabled { opacity: .5; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.danger { background: var(--red-soft); color: var(--red); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 40px; padding: 6px 12px; font-size: .95rem; }
.btn.big { min-height: var(--tap); font-size: 1.1rem; padding: 12px 18px; }
.btn.wide { width: 100%; }
.btn.on { background: var(--btn-on); color: #fff; }
.seg { display: inline-flex; gap: 4px; }
.seg.fill { display: flex; width: 100%; }
.seg.fill .btn { flex: 1; min-height: 48px; }

/* inputs */
input, select, textarea { font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; min-height: 44px; }
textarea { width: 100%; resize: vertical; }
.lbl { display: flex; flex-direction: column; gap: 4px; margin: 10px 0; font-weight: 600; }
.inline { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; }
.team-in { width: 6.5em; }
.num-in { width: 5em; }
.code-in { width: 9em; text-transform: uppercase; }
.search { width: 100%; margin: 6px 0 10px; }
.badge { font-size: .75rem; font-weight: 700; padding: 2px 8px; border-radius: 99px; }
.badge.warn { background: var(--warn-soft); color: var(--warn); }

/* home + setup */
.home-grid, .slot-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 18px 0; }
.home-btn { flex-direction: column; min-height: 140px; text-align: center; }
.home-btn b { font-size: 1.5rem; }
.home-btn small { font-weight: 400; color: var(--muted); }
.home-btn.wide-cell { grid-column: 1 / -1; min-height: 110px; }
.btn.switch { background: #fff; color: #1b2433; }
.slot { min-height: 90px; font-size: 1.3rem; }
.slot.red { background: var(--red-soft); color: var(--red); }
.slot.blue { background: var(--blue-soft); color: var(--blue); }
.slot.on { outline: 3px solid currentColor; }
@media (max-width: 420px) { .home-grid { grid-template-columns: 1fr; } }

/* headers */
.scout-head, .hub-head { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px; color: #fff; background: #1b2433; }
.scout-head.red { background: var(--red); }
.scout-head.blue { background: var(--blue); }
@media (prefers-color-scheme: dark) { .scout-head.red { background: #8c1d26; } .scout-head.blue { background: #1d3f7a; } }
.scout-head .title { flex: 1; text-align: center; min-width: 0; }
.big-title { font-size: 1.25rem; font-weight: 800; }
.hub-head .big-title { flex: 0; }
.hub-head .sub { flex: 1; }
.sub { font-size: .85rem; opacity: .9; }
.btn.nav { background: rgba(255,255,255,.18); color: #fff; min-width: 56px; min-height: 56px; font-size: 1.3rem; }
.hub-head .btn.ghost { color: #fff; }
.tools { margin: 4px 0 8px; }

/* form */
.field { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.field:first-of-type { border-top: 0; }
.field.col { flex-direction: column; align-items: stretch; }
.f-label { flex: 1; font-weight: 600; }
.f-label small, .toggle small { display: block; font-weight: 400; color: var(--muted); font-size: .8rem; }
.count { min-width: 2.2em; text-align: center; font-size: 1.6rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.btn.pm { width: 64px; height: 64px; font-size: 2rem; border-radius: 14px; }
.btn.pm.plus { background: var(--accent); color: #fff; }
.btn.toggle { width: 100%; min-height: 60px; flex-direction: column; justify-content: center; }
.btn.toggle.on small { color: rgba(255,255,255,.85); }
.field .seg.fill { flex: 1.4; }
.save-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 4; display: flex; gap: 12px; align-items: center;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); background: var(--card); border-top: 1px solid var(--line); }
.save-bar .est { font-weight: 700; white-space: nowrap; }
@media (max-width: 520px) {
  .scout-head .big-title { font-size: 1.05rem; }
  .field:not(.counter):not(.col) { flex-direction: column; align-items: stretch; }
  .btn.pm { width: 56px; height: 56px; }
}

/* QR + scanning */
.qr-box { display: flex; flex-direction: column; align-items: center; }
.qr-holder canvas { display: block; max-width: 100%; height: auto; image-rendering: pixelated; border-radius: 8px; }
.big-ok { font-size: 1.5rem; font-weight: 800; color: var(--ok); margin: 18px 0 6px; }
.qr-part { font-weight: 700; margin-top: 6px; min-height: 1.4em; }
.scan-view { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; }
.scan-video { display: block; width: 100%; height: 50vh; object-fit: contain; }
/* Matches the centre square the scanner reads at full resolution. */
.scan-aim { position: absolute; top: 4%; bottom: 4%; left: 50%; transform: translateX(-50%); aspect-ratio: 1;
  border: 3px solid rgba(255,255,255,.85); border-radius: 10px; box-shadow: 0 0 0 9999px rgba(0,0,0,.25); pointer-events: none; }
.scan-status { margin: 8px 0; font-weight: 600; }

/* lists + tables */
.list-row { display: flex; gap: 8px; align-items: center; padding: 10px; border-bottom: 1px solid var(--line); }
.log .new { background: var(--ok-soft); }
.log .updated { background: var(--warn-soft); }
.tabs { display: flex; overflow-x: auto; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 56px; z-index: 4; }
.tab { flex: 1; appearance: none; border: 0; background: none; color: var(--muted); font: inherit; font-weight: 700;
  padding: 14px 12px; border-bottom: 3px solid transparent; cursor: pointer; white-space: nowrap; }
.tab.on { color: var(--accent); border-bottom-color: var(--accent); }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { padding: 8px; border-bottom: 1px solid var(--line); text-align: center; }
.grid th.red { color: var(--red); } .grid th.blue { color: var(--blue); }
.grid td.have { background: var(--ok-soft); color: var(--ok); font-weight: 700; cursor: pointer; }
.grid td.miss { color: var(--muted); }
.grid td.warn { background: var(--warn-soft); color: var(--warn); }
.rank th.sort { cursor: pointer; white-space: nowrap; }
.rank th.on { color: var(--accent); }
.rank tbody tr { cursor: pointer; }
.rank td:nth-child(2) { text-align: left; }
.rank.small { font-size: .85rem; }
.tname { font-size: .75rem; color: var(--muted); max-width: 12em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kv th { text-align: left; font-weight: 400; color: var(--muted); }
.kv td { text-align: right; font-weight: 700; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 8px; margin-bottom: 10px; }
.stat { background: var(--bg); border-radius: 10px; padding: 8px; text-align: center; }
.stat-v { font-size: 1.3rem; font-weight: 800; }

/* modal + toast */
.modal { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.5); display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--card); width: 100%; max-width: 720px; max-height: 94vh; display: flex; flex-direction: column;
  border-radius: 16px 16px 0 0; padding-bottom: env(safe-area-inset-bottom); }
@media (min-width: 720px) { .modal { align-items: center; } .sheet { border-radius: 16px; } }
.sheet-head { display: flex; align-items: center; padding: 10px 10px 0 16px; }
.sheet-head h2 { flex: 1; margin: 0; }
.sheet-body { overflow-y: auto; padding: 8px 16px 16px; }
.sheet-actions { padding: 10px 16px 16px; display: flex; gap: 8px; }
#toast { position: fixed; left: 50%; bottom: 90px; transform: translate(-50%, 20px); opacity: 0; transition: .2s;
  background: #1b2433; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 30; max-width: 90vw; pointer-events: none; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.ok { background: var(--ok); }
#toast.err { background: var(--red); }
