:root {
  --bg: #0f1714;
  --surface: #17231e;
  --surface-2: #203029;
  --line: #2e443a;
  --text: #eef5f0;
  --muted: #9bb3a7;
  --accent: #ffb020;
  --accent-ink: #1a1200;
  --good: #4cd38a;
  --bad: #ff5d5d;
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0 0 .4em; line-height: 1.15; }
h3 { margin-top: 1.2em; font-size: 1rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.muted { color: var(--muted); margin: 0 0 .8em; }
.fine { color: var(--muted); font-size: .8rem; margin: 1em 0; }
.center { text-align: center; }

.screen {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: max(16px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}

/* ---------- home ---------- */
.brand { text-align: center; margin: 12px 0 20px; }
.brand h1 { font-size: 2.2rem; letter-spacing: -.02em; }
.logo { width: 72px; height: 72px; }
.tagline { color: var(--muted); margin: 0 auto; max-width: 30ch; }

.field { display: block; margin-bottom: 16px; }
.field span { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
input {
  width: 100%;
  font: inherit;
  font-size: 1.1rem;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.code-input { text-transform: uppercase; letter-spacing: .3em; font-weight: 700; text-align: center; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}
.row { display: flex; gap: 10px; }
.row > input { flex: 1; min-width: 0; }

.btn {
  display: block;
  width: 100%;
  font: inherit;
  font-weight: 650;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
}
.row .btn { width: auto; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.danger { background: transparent; color: var(--bad); border-color: color-mix(in srgb, var(--bad) 50%, transparent); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .45; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.link { background: none; border: 0; color: var(--muted); font: inherit; text-decoration: underline; padding: 8px; cursor: pointer; }
.actions { display: grid; gap: 10px; margin-top: 20px; }

/* ---------- shared bits ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.topbar h2 { margin: 0; }
.pill {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: .85rem;
  font-weight: 600;
}
.pill.live { background: var(--good); color: #002611; border-color: transparent; }
.pill.warn { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.timer { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--muted); }

.big-code {
  text-align: center;
  font-size: 4rem;
  font-weight: 800;
  letter-spacing: .15em;
  margin: 0 0 8px;
  font-variant-numeric: tabular-nums;
}
.qr { display: block; width: 200px; height: 200px; margin: 0 auto 12px; border-radius: 10px; background: #fff; }
.spot-count { text-align: center; font-size: 4.5rem; font-weight: 800; margin-top: 16px; }

.gps-line {
  margin: 14px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: .9rem;
}
.gps-line.bad { border-color: var(--bad); color: var(--bad); }

.players { list-style: none; margin: 0; padding: 0; }
.players li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}
.players li .who { display: flex; align-items: center; gap: 8px; min-width: 0; }
.players li .who b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.players li .meta { color: var(--muted); font-size: .85rem; text-align: right; white-space: nowrap; }
.players li.empty { color: var(--muted); justify-content: center; }
.players.compact li { padding: 6px 0; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.on { background: var(--good); }
.tag { font-size: .75rem; padding: 1px 6px; border-radius: 6px; background: var(--surface-2); color: var(--muted); }
.tag.ok { color: var(--good); }
.tag.hit { background: var(--good); color: #002611; }

/* ---------- toasts / overlays ---------- */
.toast {
  /* Below the viewfinder's heading readout so it never hides it. */
  position: fixed; left: 50%; top: calc(max(12px, env(safe-area-inset-top)) + 92px); transform: translateX(-50%);
  z-index: 50; max-width: calc(100% - 32px);
  background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; font-weight: 600;
  box-shadow: 0 6px 24px rgb(0 0 0 / .4);
}
.toast.error { background: var(--bad); color: #fff; }
.conn {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  background: var(--accent); color: var(--accent-ink);
  text-align: center; font-weight: 700; padding: 6px;
}
.modal { position: fixed; inset: 0; z-index: 30; background: rgb(0 0 0 / .7); display: grid; place-items: center; padding: 16px; }
.modal-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; width: 100%; max-width: 360px; }

.pocket {
  position: fixed; inset: 0; z-index: 60; background: #000; color: #555;
  display: flex; flex-direction: column; justify-content: space-between; align-items: center;
  padding: 40px 16px; user-select: none; touch-action: none;
}
.pocket-count { font-size: 2rem; font-weight: 700; text-align: center; }
.pocket-gps { text-align: center; margin-top: 8px; font-size: .9rem; }
.pocket-unlock { border: 1px solid #333; border-radius: 999px; padding: 14px 22px; transition: background .2s; }
.pocket-unlock.holding { background: #222; color: #aaa; }

/* ---------- seeker viewfinder ---------- */
.viewfinder-screen {
  position: fixed; inset: 0; max-width: none; padding: 0; overflow: hidden;
  background: #000;
}
.viewfinder-screen video {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; transform-origin: 50% 50%;
}
.vf-shade {
  position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(rgb(0 0 0 / .55), transparent 22%, transparent 62%, rgb(0 0 0 / .7));
}
.crosshair {
  position: absolute; left: 50%; top: 50%; width: 64px; height: 64px;
  transform: translate(-50%, -50%); pointer-events: none;
  border: 2px solid rgb(255 255 255 / .85); border-radius: 50%;
  box-shadow: 0 0 0 1px rgb(0 0 0 / .5);
}
.crosshair::before, .crosshair::after {
  content: ""; position: absolute; background: rgb(255 255 255 / .9); box-shadow: 0 0 0 1px rgb(0 0 0 / .4);
}
.crosshair::before { left: 50%; top: -22px; bottom: -22px; width: 2px; transform: translateX(-50%); }
.crosshair::after { top: 50%; left: -22px; right: -22px; height: 2px; transform: translateY(-50%); }
.crosshair span {
  position: absolute; left: 50%; top: 50%; width: 6px; height: 6px; border-radius: 50%;
  transform: translate(-50%, -50%); background: var(--accent);
}
.crosshair.steady { border-color: var(--good); }
.crosshair.steady span { background: var(--good); }

.hud-top {
  position: absolute; left: 0; right: 0; top: 0;
  padding: max(12px, env(safe-area-inset-top)) 16px 0;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 8px;
  text-shadow: 0 1px 3px #000;
}
.hud-top .pill { text-shadow: none; }
.hud-readout { text-align: center; font-variant-numeric: tabular-nums; line-height: 1.2; }
.hud-readout b { font-size: 1.6rem; }
.hud-readout small { color: #ddd; }

.zoom {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  display: flex; flex-direction: column; gap: 8px;
}
.zoom button {
  width: 44px; height: 44px; border-radius: 50%; border: 1px solid rgb(255 255 255 / .4);
  background: rgb(0 0 0 / .45); color: #fff; font-weight: 700; font-size: .9rem;
}
.zoom button.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; }

.hud-bottom {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 0 16px max(16px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  text-shadow: 0 1px 3px #000;
}
.seeker-msg { text-align: center; font-weight: 600; max-width: 34ch; }
.sensor-line { font-size: .8rem; color: #ddd; text-align: center; }
.spot-btn {
  width: min(320px, 100%); padding: 18px; border-radius: 999px; border: 0;
  background: var(--accent); color: var(--accent-ink);
  display: flex; flex-direction: column; align-items: center;
  box-shadow: 0 8px 28px rgb(0 0 0 / .5);
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
.spot-btn:disabled { background: #555; color: #bbb; box-shadow: none; }
.spot-label { font-size: 1.5rem; font-weight: 900; letter-spacing: .06em; }
.spot-sub { font-size: .75rem; font-weight: 600; opacity: .75; }
.hud-bottom .link { color: #ccc; }

.result-sheet {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 80%;
  overflow: auto; background: var(--surface); border-top: 1px solid var(--line);
  border-radius: 20px 20px 0 0;
  padding: 20px 16px max(20px, env(safe-area-inset-bottom));
}
.result-points { text-align: center; font-size: 3rem; font-weight: 800; color: var(--accent); }
.result-main { text-align: center; font-size: 1.2rem; font-weight: 700; margin-bottom: 4px; }
.result-detail { text-align: center; color: var(--muted); font-size: .9rem; }
.result-wait { text-align: center; margin: 14px 0 6px; font-weight: 600; }

/* ---------- results ---------- */
.target { display: block; width: min(320px, 100%); margin: 12px auto 0; }
.target .ring { fill: none; stroke: var(--line); }
.target .ring-label { fill: var(--muted); font-size: 9px; }
.target .axis { stroke: var(--line); stroke-dasharray: 3 3; }
.target .hider { fill: var(--accent); }
.target .shot { stroke: #000; stroke-width: 1; }
.target .shot-label { font-size: 10px; font-weight: 700; fill: #000; text-anchor: middle; dominant-baseline: central; }

.results { list-style: none; padding: 0; margin: 0; }
.results li {
  display: grid; grid-template-columns: 28px 1fr auto; gap: 4px 10px; align-items: center;
  padding: 12px 0; border-bottom: 1px solid var(--line);
}
.results .rank { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; color: #000; font-size: .8rem; }
.results .pts { font-weight: 800; font-size: 1.2rem; }
.results .sub { grid-column: 2 / 4; color: var(--muted); font-size: .85rem; }

/* ---------- leaderboard ---------- */
.table-wrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
.board { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: .9rem; }
.board th, .board td { padding: 8px 6px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
.board th:nth-child(2), .board td:nth-child(2) { text-align: left; white-space: normal; }
.board th { color: var(--muted); font-weight: 600; font-size: .8rem; }
.board tr.me td { color: var(--accent); font-weight: 700; }
.games { list-style: none; padding: 0; margin: 0; }
.games li { padding: 10px 0; border-bottom: 1px solid var(--line); }
.games .when { color: var(--muted); font-size: .8rem; }
