:root {
  --bg: #12141a;
  --panel: #1b1f28;
  --panel-2: #232936;
  --line: #313a4c;
  --text: #eef1f6;
  --muted: #9aa5b8;
  --accent: #4da3ff;
  --ok: #35c07f;
  --err: #ff6b6b;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.brand { font-weight: 700; color: var(--text); text-decoration: none; letter-spacing: .2px; }
.topbar nav { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; }
.topbar nav a { color: var(--muted); text-decoration: none; }
.topbar nav a:hover { color: var(--text); }

main { max-width: 640px; margin: 0 auto; padding: 24px 16px 64px; }
main.wide { max-width: 1200px; }

h1 { font-size: 1.6rem; margin: 0 0 8px; }
h2 { font-size: 1.15rem; margin: 32px 0 10px; }
.lead { color: var(--text); margin: 0 0 16px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.tiny { font-size: .75rem; }
.nowrap { white-space: nowrap; }
.mt { margin-top: 12px; }
a { color: var(--accent); }
section { margin-bottom: 32px; }

.flash { padding: 10px 12px; border-radius: var(--radius); margin: 0 0 16px; }
.flash.ok { background: rgba(53,192,127,.14); border: 1px solid rgba(53,192,127,.4); }
.flash.error { background: rgba(255,107,107,.14); border: 1px solid rgba(255,107,107,.4); }

/* ----- forms ----- */
.stack { display: flex; flex-direction: column; gap: 8px; }
.stack label { font-weight: 600; margin-top: 8px; }
.inline { display: inline-flex; gap: 6px; align-items: center; margin: 0 6px 6px 0; }

input, select, button {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  min-height: 44px;
}
input:focus, select:focus, button:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

button { cursor: pointer; }
button.primary { background: var(--accent); border-color: var(--accent); color: #07121f; font-weight: 700; }
button.big { padding: 18px; font-size: 1.15rem; margin-top: 12px; }
button.link {
  background: none; border: none; color: var(--accent);
  padding: 6px 4px; min-height: 36px; text-decoration: underline;
}
button.link.danger { color: var(--err); }

/* ----- table cards (phone score entry) ----- */
.cards { display: flex; flex-direction: column; gap: 12px; }
.card {
  display: block;
  padding: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
}
.card.done { border-left-color: var(--ok); }
.card-title { display: block; font-size: 1.2rem; font-weight: 700; }
.card-note { display: block; color: var(--muted); margin-top: 4px; }

/* ----- multi-round score entry ----- */
.entry-form { display: flex; flex-direction: column; }
.entry-label { font-weight: 600; margin-bottom: 6px; }
.entry-form > select { font-size: 1.05rem; }

table.entry-table {
  width: 100%;
  border-collapse: collapse;
  margin: 20px 0 22px;
}
.entry-table th, .entry-table td { border: 1px solid var(--line); }

.entry-table thead th {
  background: var(--panel-2);
  color: var(--muted);
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  text-align: left;
  padding: 8px 12px;
}

.entry-table tbody th {
  background: var(--panel);
  text-align: left;
  font-size: 1.1rem;
  font-weight: 700;
  padding: 10px 12px;
  /* round name and the saved tag sit on one baseline, wrapping if cramped */
  display: table-cell;
}
.entry-table tbody th label { cursor: pointer; }
.entry-table tbody th .tag { margin-left: 8px; white-space: nowrap; }
.assigned-hint { margin: 8px 0 0; }

.entry-table .score-col { width: 104px; text-align: center; }
.entry-table thead th.score-col { text-align: center; }
.entry-table td.score-col { padding: 6px; }
.entry-table td.score-col input {
  width: 100%;
  min-height: 46px;
  text-align: center;
  font-size: 1.2rem;
  font-variant-numeric: tabular-nums;
}
.entry-table tr.saved td.score-col { background: rgba(53,192,127,.10); }

.tag {
  font-size: .75rem;
  font-weight: 500;
  color: var(--ok);
  background: rgba(53,192,127,.16);
  padding: 2px 8px;
  border-radius: 999px;
}

/* visually hidden, still read by screen readers */
.vh {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ----- grids ----- */
.scroll { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; }
table.grid th, table.grid td {
  text-align: left; padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
table.grid thead th { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; }
table.grid input { padding: 8px; min-height: 40px; }
input.numfield { width: 72px; text-align: center; }
.break { word-break: break-all; }

.matrix td { text-align: center; }
.matrix .rowhead { white-space: nowrap; }
.matrix .cell-form { display: flex; gap: 4px; align-items: center; }
.matrix .cell-form input { width: 72px; text-align: center; }
.matrix .no-score { background: rgba(255,107,107,.07); }
.matrix tr.totals td, .matrix tr.totals th { border-top: 2px solid var(--line); font-size: 1.1rem; }

.pill { padding: 2px 8px; border-radius: 999px; font-size: .75rem; text-transform: uppercase; }
.pill-open { background: rgba(53,192,127,.18); color: var(--ok); }
.pill-closed { background: rgba(154,165,184,.18); color: var(--muted); }

/* ----- QR sheet ----- */
.qr-sheet { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 20px; }
.qr-card {
  width: 260px; padding: 16px; text-align: center;
  background: #fff; color: #000;
  border: 1px dashed #999; border-radius: 8px;
}
.qr-page-title {
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: #666;
  margin-bottom: 6px;
}
.qr-name { font-size: 1.3rem; font-weight: 800; margin-bottom: 8px; }
.qr-url { font-size: .7rem; color: #555; margin-top: 6px; word-break: break-all; }
.qr-hint { font-size: .85rem; margin-top: 4px; }

@media print {
  @page { margin: 1.5cm; }

  body { background: #fff; color: #000; }
  .topbar, .no-print { display: none !important; }
  main { max-width: none; padding: 0; }

  /* One table per page: a full-size code anyone can scan from across the table. */
  .qr-sheet { display: block; gap: 0; margin: 0; }
  .qr-card {
    width: 100%;
    padding: 0;
    border: none;
    text-align: center;
    break-inside: avoid;
  }
  .qr-card:not(:last-child) {
    break-after: page;
    page-break-after: always;
  }
  .qr-page-title {
    font-size: 30pt;
    font-weight: 800;
    letter-spacing: .02em;
    text-transform: none;
    color: #000;
    margin: 0 0 0.5cm;
  }
  .qr-name { font-size: 22pt; margin-bottom: 0.7cm; }
  .qr-card img { width: 11.5cm; height: 11.5cm; }
  .qr-hint { font-size: 14pt; margin-top: 0.5cm; }
  .qr-url { font-size: 9pt; color: #555; margin-top: 0.3cm; }
}

/* ----- big-screen leaderboard ----- */
.board { text-align: center; }
.board-title { font-size: clamp(2rem, 6vw, 4rem); margin: 8px 0 24px; }
.board-rows { list-style: none; margin: 0 auto; padding: 0; max-width: 900px; }
.board-rows li {
  display: flex; align-items: baseline; gap: 16px;
  padding: clamp(6px, 1.2vh, 14px) 18px;
  margin-bottom: 8px;
  background: var(--panel);
  border-radius: var(--radius);
  font-size: clamp(1.2rem, 3.4vw, 2.2rem);
}

/* Two columns on anything laptop-sized, so a full field fits without scrolling.
   Multi-column fills down the left and then down the right, which keeps the
   ranking readable in order. */
@media (min-width: 900px) {
  .board-rows.two-col { column-count: 2; column-gap: 22px; }
  .board-rows.two-col li {
    break-inside: avoid;
    font-size: clamp(1.1rem, 1.7vw, 1.75rem);
    padding: 10px 16px;
  }
}
.board-rows .rank { color: var(--muted); min-width: 2.2em; text-align: right; }
.board-rows .name { flex: 1; text-align: left; font-weight: 700; }
.board-rows .pts { font-variant-numeric: tabular-nums; font-weight: 800; }
.board-rows li.lead-1 { background: linear-gradient(90deg, rgba(77,163,255,.25), var(--panel)); }
.board-stamp { color: var(--muted); font-size: .85rem; margin-top: 14px; }
.board-actions { margin: 18px 0 0; }
.reveal-link {
  display: inline-block;
  padding: 10px 20px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--accent);
  text-decoration: none;
  font-size: 1rem;
}
.reveal-link:hover { background: var(--panel); }

/* ----- final results reveal ----- */
.reveal {
  min-height: 78vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  cursor: pointer;
  outline: none;
  user-select: none;
}
.reveal-stage { min-height: 46vh; display: flex; flex-direction: column; justify-content: center; }
.reveal-kicker { color: var(--muted); letter-spacing: .14em; text-transform: uppercase; font-size: .9rem; margin: 0 0 12px; }
.reveal-title { font-size: clamp(2.4rem, 7vw, 5rem); margin: 0 0 16px; }
.reveal-hint { color: var(--muted); font-size: clamp(1rem, 2vw, 1.4rem); margin: 0; }
.reveal-place {
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: .12em;
  font-weight: 700;
  font-size: clamp(1.1rem, 2.6vw, 2rem);
  margin: 0 0 10px;
}
.reveal-names { margin: 0; }
/* Tied tables share a card, so shrink them and space them apart. */
.reveal-names.multi .reveal-name { font-size: clamp(1.6rem, 4.5vw, 3.4rem); margin-bottom: 14px; }
.reveal-names.multi .reveal-name:last-child { margin-bottom: 0; }
.reveal-name {
  font-size: clamp(2.2rem, 8vw, 6rem);
  font-weight: 800;
  line-height: 1.05;
  margin: 0 0 6px;
}
.reveal-score {
  font-size: clamp(1.4rem, 3.4vw, 2.6rem);
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  margin: 14px 0 0;
}
.reveal-progress { color: var(--muted); font-size: .9rem; margin: 26px 0 0; min-height: 1.2em; }
.reveal-escape { margin: 10px 0 0; font-size: .85rem; }
.reveal-escape a { color: var(--muted); }
