/* Chess Club Tracker — Kingdom Heights Royals branding (khroyals.com)
   Brand: royal blue #00239C · bright blue #0031DC · red #FC1723 · navy ink #0B1928 · Montserrat.
   Chart series colors stay on the validated dataviz palette (set in app.js), independent of UI chrome. */
@font-face {
  font-family: 'Montserrat';
  font-style: normal;
  font-weight: 100 900; /* variable font */
  font-display: swap;
  src: url('fonts/montserrat.woff2') format('woff2');
}
:root {
  color-scheme: light;
  --bg: #fafaf9;
  --surface: #ffffff;
  --ink: #0b1928;
  --ink-2: #46536a;
  --muted: #8791a3;
  --grid: #e3e5ea;
  --baseline: #c2c8d2;
  --border: rgba(11, 25, 40, 0.10);
  --blue: #00239c;        /* KH royal blue — primary action color */
  --blue-bright: #0031dc; /* KH bright blue — focus/links */
  --blue-dark: #001a75;
  --red: #fc1723;         /* KH red — reserved for small accents */
  --green: #008300;
  --good: #0ca30c;
  --good-text: #006300;
  --warn: #eda100;
  --critical: #d03b3b;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Montserrat', system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
}

/* ---------- header / nav ---------- */
header {
  background: var(--surface);
  border-bottom: 3px solid var(--blue);
  padding: 0 20px;
  display: flex; align-items: center; gap: 22px;
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 8px 0; white-space: nowrap; }
.brand img { height: 44px; display: block; }
.brand .brand-title {
  font-size: 15px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--blue); border-left: 2px solid var(--red); padding-left: 12px; line-height: 1.3;
}
.brand .brand-title small { display: block; font-size: 10px; font-weight: 600; color: var(--ink-2); letter-spacing: 0.14em; }
nav { display: flex; gap: 2px; flex-wrap: wrap; }
nav button {
  background: none; border: none; font: inherit; color: var(--ink-2);
  padding: 18px 12px 15px; cursor: pointer; border-bottom: 3px solid transparent;
  margin-bottom: -3px; font-weight: 600; font-size: 13px;
}
nav button:hover { color: var(--blue); }
nav button.on { color: var(--blue); border-bottom-color: var(--red); font-weight: 700; }

main { max-width: 1080px; margin: 0 auto; padding: 22px 20px 60px; }

/* ---------- cards & layout ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 20px; margin-bottom: 18px;
}
.card h2 { font-size: 16px; margin: 0 0 12px; }
.card h3 { font-size: 14px; margin: 18px 0 8px; color: var(--ink-2); }
.row { display: flex; gap: 18px; flex-wrap: wrap; }
.row > .card { flex: 1 1 320px; margin-bottom: 0; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.hint { color: var(--muted); font-size: 13px; }
.subtle { color: var(--ink-2); font-size: 13px; }

/* ---------- tables ---------- */
table { border-collapse: collapse; width: 100%; }
th {
  text-align: left; font-size: 12px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.04em;
  padding: 6px 10px; border-bottom: 1px solid var(--baseline);
}
td { padding: 8px 10px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: rgba(0, 49, 220, 0.05); }
.rank { color: var(--muted); font-variant-numeric: tabular-nums; width: 30px; }
.medal { font-size: 15px; }

/* ---------- forms ---------- */
input, select, textarea {
  font: inherit; color: var(--ink); background: #fff;
  border: 1px solid var(--baseline); border-radius: 7px; padding: 7px 10px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue-bright); outline-offset: -1px; border-color: var(--blue-bright); }
textarea { width: 100%; min-height: 170px; resize: vertical; font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
label { font-size: 13px; color: var(--ink-2); display: block; margin-bottom: 3px; }
.field { display: flex; flex-direction: column; }
form.inline { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
input.mini { width: 74px; text-align: right; font-variant-numeric: tabular-nums; }
input[type="date"] { width: 150px; }

/* ---------- buttons ---------- */
button.btn {
  font: inherit; cursor: pointer; border-radius: 7px; padding: 7px 14px;
  border: 1px solid var(--baseline); background: #fff; color: var(--ink);
}
button.btn:hover { border-color: var(--ink-2); }
button.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; font-weight: 600; }
button.btn.primary:hover { background: var(--blue-dark); border-color: var(--blue-dark); }
button.btn.danger { color: var(--critical); }
button.btn.danger:hover { border-color: var(--critical); }
button.btn.small { padding: 4px 10px; font-size: 13px; }
button.btn.ghost { border-color: transparent; background: none; color: var(--ink-2); }
button.btn.ghost:hover { color: var(--critical); }
button.btn:disabled { opacity: 0.45; cursor: default; }

/* result picker */
.res { display: inline-flex; gap: 4px; }
.res button {
  font: inherit; font-size: 13px; cursor: pointer; padding: 4px 9px;
  border: 1px solid var(--baseline); background: #fff; border-radius: 6px;
  font-variant-numeric: tabular-nums;
}
.res button:hover { border-color: var(--blue); }
.res button.on { background: var(--blue); border-color: var(--blue); color: #fff; font-weight: 600; }

/* ---------- badges & chips ---------- */
.badge {
  display: inline-block; font-size: 12px; font-weight: 600; border-radius: 20px;
  padding: 2px 10px; vertical-align: middle;
}
.badge.blue { background: rgba(0,35,156,0.10); color: var(--blue); }
.badge.green { background: rgba(12,163,12,0.12); color: var(--good-text); }
.badge.gray { background: rgba(11,11,11,0.07); color: var(--ink-2); }
.badge.red { background: rgba(208,59,59,0.10); color: var(--critical); }
.badge.gold { background: rgba(237,161,0,0.15); color: #8a5d00; }

/* ---------- goals ---------- */
.goal {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 10px; background: #fff;
}
.goal .spread { margin-bottom: 6px; }
.goal .who { font-weight: 600; }
.progress { height: 8px; background: var(--grid); border-radius: 4px; overflow: hidden; margin: 8px 0 4px; }
.progress > div { height: 100%; background: var(--blue); border-radius: 4px; }
.progress.done > div { background: var(--good); }
.callout {
  border: 1px solid rgba(12,163,12,0.4); background: rgba(12,163,12,0.06);
  border-radius: var(--radius); padding: 12px 16px; margin-bottom: 18px;
}
.callout b { color: var(--good-text); }

/* ---------- stats & charts ---------- */
.stats { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 18px; min-width: 130px;
  border-top: 3px solid var(--blue);
}
.stat .v { font-size: 26px; font-weight: 650; line-height: 1.2; }
.stat .k { font-size: 12px; color: var(--muted); }
.stat .delta { font-size: 12px; font-variant-numeric: tabular-nums; }
.stat.wk { border-top-color: var(--red); }
.stat.wk .v { font-size: 22px; }
.stat.wk .v .delta { font-size: 22px; }
.delta.up { color: var(--good-text); }
.delta.down { color: var(--critical); }
.delta.dn { color: var(--muted); } /* quiet, kid-friendly "went down" */
.pieces { font-size: 15px; letter-spacing: 2px; color: var(--blue); }

/* ---------- keychains ---------- */
.keychip {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid var(--border); border-radius: 20px; padding: 3px 6px 3px 11px;
  margin: 3px 6px 3px 0; font-size: 13px; font-weight: 600; background: #fff;
}
.keychip .piece { font-size: 17px; color: var(--blue); }
.keychip.given { background: rgba(12,163,12,0.07); border-color: rgba(12,163,12,0.35); color: var(--good-text); }
.keychip.pending { background: rgba(237,161,0,0.10); border-color: rgba(237,161,0,0.5); color: #8a5d00; }
.keychip .btn.small { padding: 2px 8px; font-size: 12px; }

/* ---------- sortable dashboard headers ---------- */
th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { color: var(--blue); }

/* ---------- wall leaderboard & pairing sheets ---------- */
.board { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 24px; }
.board-head { display: flex; align-items: center; gap: 16px; border-bottom: 3px solid var(--blue); padding-bottom: 12px; margin-bottom: 14px; }
.board-head img { height: 54px; }
.board-title { font-size: 19px; font-weight: 700; color: var(--blue); letter-spacing: 0.03em; text-transform: uppercase; }
.board-table td { font-size: 15px; padding: 10px; }
.board-table .medal { font-size: 18px; }
.write-line { display: inline-block; width: 90px; border-bottom: 1.5px solid var(--ink); height: 1.1em; }
.tickbox { display: inline-block; width: 15px; height: 15px; border: 1.5px solid var(--ink); border-radius: 3px; vertical-align: middle; }
@page { size: portrait; margin: 12mm; }
@media print {
  .board { border: none; padding: 0; }
  /* these views carry their own branded header */
  body.view-print-board .print-header, body.view-print-pairings .print-header,
  body.view-print-prizes .print-header { display: none !important; }
  /* compact so a full club fits on one portrait page */
  .board-head { padding-bottom: 8px; margin-bottom: 10px; }
  .board-head img { height: 42px; }
  .board-title { font-size: 15px; }
  .board-table th { font-size: 10px; padding: 4px 8px; }
  .board-table td { font-size: 12px; padding: 4px 8px; }
  .board-table .medal { font-size: 13px; }
  .board h3 { margin: 12px 0 6px; }
  .board tr { break-inside: avoid; }
  .tickbox { width: 12px; height: 12px; }
}

/* ---------- club day matchups ---------- */
tr.match-done td { opacity: 0.55; }
tr.match-new td { background: rgba(237, 161, 0, 0.13); }
tr.match-new td:first-child { box-shadow: inset 3px 0 0 var(--warn); }

/* ---------- parent progress slips ---------- */
.slips { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 14px; }
.slip {
  background: #fff; border: 2px solid var(--blue); border-radius: 8px;
  padding: 14px 18px; break-inside: avoid;
}
.slip-head { display: flex; gap: 10px; align-items: center; border-bottom: 2px solid var(--red); padding-bottom: 6px; margin-bottom: 8px; }
.slip-head img { height: 30px; }
.slip-school { font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--blue); }
.slip-date { font-size: 10px; color: var(--muted); }
.slip-name { font-size: 18px; font-weight: 700; margin-bottom: 6px; }
.slip-row { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; padding: 3px 0; border-bottom: 1px solid var(--grid); }
.slip-foot { font-size: 11px; color: var(--muted); margin-top: 8px; }
@media print {
  body.view-slips .print-header { display: none !important; }
  .slips { grid-template-columns: 1fr 1fr; gap: 8mm; }
}

/* ---------- tier certificate ---------- */
.certificate { background: #fff; border: 4px solid var(--blue); padding: 10px; max-width: 760px; margin: 0 auto; }
.cert-inner { border: 2px solid var(--red); padding: 44px 40px; text-align: center; }
.cert-logo { height: 64px; }
.cert-school { font-size: 12px; font-weight: 600; letter-spacing: 0.16em; text-transform: uppercase; color: var(--ink-2); margin-top: 10px; }
.cert-title { font-size: 34px; font-weight: 700; color: var(--blue); margin: 18px 0 4px; letter-spacing: 0.04em; }
.cert-piece { font-size: 56px; color: var(--red); line-height: 1.1; }
.cert-name { font-size: 30px; font-weight: 700; margin: 10px 0 2px; border-bottom: 2px solid var(--baseline); display: inline-block; padding: 0 34px 6px; }
.cert-body { font-size: 16px; color: var(--ink-2); line-height: 1.7; }
.cert-foot { display: flex; justify-content: space-between; margin-top: 46px; padding: 0 30px; }
.cert-line { border-top: 1.5px solid var(--ink); padding-top: 6px; min-width: 170px; font-size: 14px; }
.cert-line small { display: block; color: var(--muted); font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; }
@media print {
  body.view-certificate .print-header { display: none !important; } /* the certificate is its own artwork */
  body.view-certificate main { max-width: none; padding: 0; }
}

.chart-wrap { position: relative; }
.chart-wrap svg { display: block; width: 100%; height: auto; }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--ink-2); margin-bottom: 4px; }
.legend .dot, .dl .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; }
.tooltip {
  position: absolute; pointer-events: none; background: var(--ink); color: #fff;
  font-size: 12px; border-radius: 6px; padding: 6px 9px; white-space: nowrap;
  transform: translate(-50%, -110%); display: none; z-index: 5;
  font-variant-numeric: tabular-nums;
}
.tooltip .t-date { color: #c3c2b7; }
.spark { vertical-align: middle; }

/* ---------- misc ---------- */
.empty { color: var(--muted); padding: 18px 4px; text-align: center; }
#toast {
  position: fixed; bottom: 22px; right: 22px; z-index: 100;
  background: var(--ink); color: #fff; border-radius: 8px; padding: 10px 16px;
  font-size: 14px; display: none; max-width: 380px;
}
#toast.err { background: var(--critical); }
.back { margin-bottom: 14px; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 6px; margin: 10px 0; }
.checks label { display: flex; align-items: center; gap: 7px; font-size: 14px; color: var(--ink); margin: 0; cursor: pointer; }
.round-block { margin-bottom: 16px; }
.round-block h3 { margin-top: 0; }
ol.steps { margin: 6px 0 14px; padding-left: 22px; color: var(--ink-2); }
ol.steps li { margin-bottom: 4px; }
/* ---------- print (club wall / pairing sheets) ---------- */
.print-header { display: none; }
/* ---------- mobile ---------- */
@media (max-width: 740px) {
  header { padding: 0 10px; gap: 8px; }
  .brand { padding: 6px 0; }
  .brand img { height: 34px; }
  .brand .brand-title { display: none; }        /* logo carries the brand on phones */
  nav { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  nav::-webkit-scrollbar { display: none; }
  nav button { padding: 14px 10px 11px; white-space: nowrap; margin-bottom: 0; }
  main { padding: 14px 10px 60px; }
  .card, .board { padding: 14px 12px; overflow-x: auto; }  /* wide tables scroll inside the card */
  .row > .card { flex-basis: 100%; }

  .stats { gap: 8px; }
  .stat { min-width: 30%; flex: 1 1 30%; padding: 9px 10px; }
  .stat .v { font-size: 19px; }
  .stat.wk .v, .stat.wk .v .delta { font-size: 19px; }
  .stat .k { font-size: 11px; }

  /* touch targets + stop iOS zoom-on-focus (needs >=16px inputs) */
  input, select, textarea { font-size: 16px; }
  button.btn { padding: 10px 16px; }
  button.btn.small { padding: 7px 12px; font-size: 14px; }
  .res button { padding: 9px 13px; font-size: 16px; }
  .keychip .btn.small { padding: 7px 11px; }
  nav button, th.sortable { -webkit-tap-highlight-color: rgba(0, 35, 156, 0.15); }

  form.inline { gap: 10px; }
  form.inline .field { flex: 1 1 46%; }
  form.inline input:not(.mini), form.inline select { width: 100%; min-width: 0; }
  input[type="date"] { width: auto; }

  td, th { padding-left: 6px; padding-right: 6px; }
  /* leaderboard: drop the sparkline + last-online columns on small screens */
  table.lb th:nth-child(4), table.lb td:nth-child(4),
  table.lb th:nth-child(8), table.lb td:nth-child(8) { display: none; }
  table.lb td { white-space: nowrap; }
  .pieces { letter-spacing: 0; font-size: 13px; }
  .spread { row-gap: 8px; }
  .checks { grid-template-columns: 1fr 1fr; gap: 2px; }
  .checks label { padding: 8px 4px; }
  .checks input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--blue); }
  /* round/matchup tables: never crush the result buttons — scroll the card instead */
  .round-block td, .round-block th { white-space: nowrap; }
  .res { flex-wrap: nowrap; }
  .res button { white-space: nowrap; }
  .round-block .hint, .card table .hint + .hint { display: none; } /* "(white)" labels — white is always listed first */
  .round-block td:first-child { padding-right: 2px; }
}

@media print {
  header, .no-print { display: none !important; }
  body { background: #fff; }
  .card { border: none; padding: 0; }
  .print-header {
    display: flex; align-items: center; gap: 16px;
    border-bottom: 3px solid var(--blue); padding-bottom: 10px; margin-bottom: 18px;
  }
  .print-header img { height: 52px; }
  .print-header .brand-title {
    font-size: 16px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
    color: var(--blue); border-left: 2px solid var(--red); padding-left: 14px;
  }
  .print-header .brand-title small { display: block; font-size: 11px; font-weight: 600; color: var(--ink-2); letter-spacing: 0.14em; }
}
