/* Prediction-pool leaderboard — self-contained, no dependencies */

:root {
  --bg: #ffffff;
  --fg: #1f2328;
  --muted: #6b7280;
  --line: #e5e7eb;
  --line-strong: #d1d5db;
  --row-alt: #f8f9fb;
  --row-hover: #eef4ff;
  --leader-col: #f3f6fb;
  --accent: #2563eb;
  --earned: #15803d;         /* points-earned number (green) */
  --miss: #b0b4ba;           /* missed prediction (faded) */
  --exact-bg: #fff6d6;       /* exact score (bonus) */
  --exact-bd: #f0c419;
  --gold: #d4af37;
  --silver: #9aa3ad;
  --bronze: #c07d3e;
  --header-h1: 64px;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

#container {
  height: 100vh;
  height: 100dvh;   /* dynamic viewport height: accounts for mobile browser UI */
  display: flex;
  flex-direction: column;
}

.lb-header {
  flex: 0 0 auto;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  position: relative;            /* anchor for the info popover */
}
.lb-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  flex-wrap: wrap;
}
.lb-toolbar h1 {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
  letter-spacing: .2px;
}

/* info button + popover (holds stats + legend) */
.lb-info {
  margin-left: auto;
  width: 28px; height: 28px;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: Georgia, "Times New Roman", serif;
  font-style: italic;
  font-weight: 700;
  font-size: 15px;
  line-height: 1;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background: var(--bg);
  color: var(--accent);
  cursor: pointer;
  transition: background .12s, border-color .12s;
}
.lb-info:hover, .lb-info.active { border-color: var(--accent); background: #eef4ff; }
.lb-infopanel {
  display: none;
  position: absolute;
  right: 14px; top: 46px;
  z-index: 40;
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.14);
  padding: 12px 14px;
  max-width: 280px;
}
.lb-infopanel.open { display: block; }
.lb-infopanel .info-stats { font-weight: 600; font-size: 13px; }
.lb-infopanel .info-updated { font-size: 12px; color: var(--muted); margin-top: 4px; }
.lb-infopanel .info-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: var(--muted);
  margin: 12px 0 8px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}
.lb-infopanel .lb-legend { flex-direction: column; align-items: flex-start; gap: 9px; padding: 0; }

/* view tabs */
.lb-tabs {
  display: inline-flex;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  overflow: hidden;
}
.lb-tab {
  font: inherit;
  font-size: 13px;
  padding: 5px 12px;
  border: 0;
  border-right: 1px solid var(--line);
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, color .12s;
}
.lb-tab:last-child { border-right: 0; }
.lb-tab:hover { background: var(--row-hover); }
.lb-tab.active { background: var(--accent); color: #fff; font-weight: 600; }
.lb-tab .cnt {
  font-size: 11px;
  opacity: .7;
  margin-left: 3px;
  font-variant-numeric: tabular-nums;
}
.lb-tab.active .cnt { opacity: .9; }

.lb-round {
  font: inherit;
  font-size: 13px;
  padding: 5px 8px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
  max-width: 200px;
}

.lb-empty {
  position: sticky;
  left: 0;
  padding: 28px 16px;
  color: var(--muted);
  font-size: 14px;
}
.lb-filter {
  font: inherit;
  font-size: 13px;
  padding: 5px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, border-color .12s;
}
.lb-filter:hover { border-color: var(--exact-bd); }
.lb-filter.active {
  background: var(--exact-bg);
  border-color: var(--exact-bd);
  font-weight: 600;
}
.lb-legend {
  display: flex;
  gap: 14px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
  flex-wrap: wrap;
  padding: 0 14px 9px;
}
.lb-legend .chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.lb-legend .swatch {
  width: 13px; height: 13px;
  border-radius: 3px;
  border: 1px solid var(--line-strong);
  display: inline-block;
}
.lb-legend .sample {
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  padding: 1px 5px;
  border-radius: 4px;
}
.sample.s-earned { color: var(--earned); font-weight: 700; }
.sample.s-miss { color: var(--miss); }
.swatch.s-exact { background: var(--exact-bg); border: 1px solid var(--exact-bd); }

/* Scroll region */
.lb-scroll {
  flex: 1 1 auto;
  overflow: auto;
  position: relative;
  -webkit-overflow-scrolling: touch;
  scroll-snap-type: x proximity;   /* gently snap one match per swipe */
  scroll-padding-left: 0;          /* overridden at runtime = frozen width */
}
/* one snap point per match column (defined on the first body row's cells) */
tbody tr:first-child td.match-col { scroll-snap-align: start; }

table.lb {
  border-collapse: separate;
  border-spacing: 0;
  width: max-content;
  min-width: 100%;
}

/* ---- Cells ---- */
table.lb th, table.lb td {
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  padding: 6px 8px;
  text-align: center;
  white-space: nowrap;
  background: var(--bg);
}

/* Match column group separator */
table.lb .match-col { border-right: 2px solid var(--line-strong); }

/* ---- Header (top sticky) ---- */
table.lb thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--bg);
}
table.lb thead tr.row-match th {
  top: 0;
  vertical-align: bottom;
  padding-top: 8px;
}
table.lb thead tr.row-sub th {
  top: var(--header-h1);
  z-index: 3;
  font-weight: 500;
  color: var(--muted);
  font-size: 11.5px;
  padding: 3px 8px;
}

.match-card { line-height: 1.25; min-width: 88px; }
.match-card .teams { font-weight: 600; font-size: 12px; }
.match-card .score { font-size: 14px; font-weight: 700; margin: 1px 0; }
.match-card .score.pending { color: var(--muted); font-weight: 600; }
.match-card .meta { font-size: 10.5px; color: var(--muted); }
th.match-head { cursor: pointer; }
th.match-head:hover .match-card { color: var(--accent); }

/* ---- Match-detail modal (tap a match header) ---- */
.lb-modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.42);
  z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.lb-modal {
  position: relative;
  background: var(--bg);
  border-radius: 12px;
  box-shadow: 0 14px 44px rgba(0,0,0,.32);
  width: min(420px, 100%);
  max-height: 85vh; max-height: 85dvh;
  overflow: auto;
  padding: 18px 18px 10px;
}
.mm-close {
  position: absolute; top: 6px; right: 10px;
  border: 0; background: none;
  font-size: 24px; line-height: 1;
  color: var(--muted); cursor: pointer;
}
.mm-close:hover { color: var(--fg); }
.mm-head { text-align: center; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.mm-teams { font-weight: 600; font-size: 15px; }
.mm-score { font-size: 22px; font-weight: 800; margin: 4px 0; }
.mm-score.pending { color: var(--muted); }
.mm-meta { font-size: 12px; color: var(--muted); }
.mm-row {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 6px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.mm-row:last-child { border-bottom: 0; }
.mm-colhead { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .3px; }
.mm-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mm-pred { width: 56px; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.mm-pts  { width: 56px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.mm-row.scored .mm-pts { color: var(--earned); font-weight: 700; }
.mm-row.exact { background: var(--exact-bg); border-radius: 6px; }
.mm-row.exact .mm-pts { color: #8a6d00; font-weight: 700; }

/* ---- Sticky left columns ---- */
/* left offsets are assigned at runtime from real column widths (see table.js);
   values here are only a pre-layout fallback. */
.col-rank   { left: 0;     min-width: 40px; }
.col-player { left: 40px;  min-width: 168px; text-align: left; }
.col-pts    { left: 208px; min-width: 64px; padding-left: 10px; padding-right: 10px; }
.col-exact  { left: 272px; min-width: 56px; }

table.lb thead .col-rank,
table.lb thead .col-player,
table.lb thead .col-pts,
table.lb thead .col-exact {
  z-index: 5;            /* corner: above both axes */
}
table.lb tbody .col-rank,
table.lb tbody .col-player,
table.lb tbody .col-pts,
table.lb tbody .col-exact {
  position: sticky;
  z-index: 2;
  background: var(--bg);
}
.col-exact { border-right: 2px solid var(--line-strong); }
table.lb thead .col-rank, table.lb thead .col-player,
table.lb thead .col-pts, table.lb thead .col-exact { position: sticky; }

/* Sortable headers */
th.sortable { cursor: pointer; user-select: none; font-weight: 600; }
th.sortable:hover { color: var(--accent); }
th.sortable .arrow { font-size: 10px; opacity: .35; margin-left: 3px; }
th.sortable.sorted .arrow { opacity: 1; color: var(--accent); }

/* ---- Body rows ---- */
tbody tr:nth-child(even) td,
tbody tr:nth-child(even) th { background: var(--row-alt); }
tbody tr:hover td,
tbody tr:hover th { background: var(--row-hover); }

td.col-player, th.col-player { text-align: left; font-weight: 600; }
.player-name { display: inline-flex; align-items: center; gap: 5px; }
.queen { filter: saturate(1.1); }

td.col-pts { font-weight: 700; font-variant-numeric: tabular-nums; }
td.col-exact { color: var(--muted); font-variant-numeric: tabular-nums; }

.rank-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 22px; height: 22px; padding: 0 5px;
  border-radius: 11px; font-weight: 700; font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.rank-1 { background: var(--gold);   color: #4a3a00; }
.rank-2 { background: var(--silver); color: #20262c; }
.rank-3 { background: var(--bronze); color: #2e1a08; }

/* Prediction cells.
   Color encodes outcome, not an arbitrary gradient:
     - miss  : prediction made but earned 0 pts  -> faded
     - scored: earned points                      -> green "+pts" number
     - exact : exact scoreline (bonus)            -> amber highlight
     - empty : no prediction                      -> dash */
td.pred { font-variant-numeric: tabular-nums; min-width: 64px; }
td.pred .res { font-size: 13px; font-weight: 600; }
td.pred .pts { display: block; font-size: 10.5px; color: var(--muted); margin-top: 1px; }

td.pred.miss .res { color: var(--miss); font-weight: 500; }
td.pred.empty .res { color: var(--line-strong); }

td.pred.scored .pts { color: var(--earned); font-weight: 700; }

td.pred.exact {
  background: var(--exact-bg);
  box-shadow: inset 0 0 0 2px var(--exact-bd);
}
td.pred.exact .pts { color: #8a6d00; font-weight: 700; }
tbody tr:nth-child(even) td.pred.exact { background: #fff0c2; }

/* Loading + empty */
.lb-status {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 15px; background: var(--bg);
}
.spinner {
  width: 22px; height: 22px; margin-right: 10px;
  border: 3px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Mobile ---- */
@media (max-width: 640px) {
  body { font-size: 13px; }
  .lb-toolbar { gap: 8px; padding: 8px 10px 6px; }
  .lb-toolbar h1 { width: 100%; }
  .lb-toolbar .lb-meta { margin-left: auto; font-size: 11.5px; }
  .lb-legend { font-size: 11px; gap: 10px; padding: 0 10px 8px; }
  .lb-tab { padding: 5px 9px; }

  /* Frozen side panel: place (#) + full name + Очки.
     Name column has a fixed width and wraps onto multiple lines to fit. */
  .col-rank   { min-width: 30px; }
  .col-player {
    width: 104px; min-width: 104px; max-width: 104px;
    text-align: left;
    line-height: 1.15;
    padding: 5px 6px;
  }
  /* higher specificity than base `table.lb th { white-space: nowrap }` */
  table.lb th.col-player {
    white-space: normal;          /* allow wrapping */
    overflow-wrap: anywhere;       /* break long single words like "Strogalshchikov" */
  }
  .col-player .player-name { display: inline; font-size: 11.5px; }   /* flow as text so it can wrap */
  .col-player .queen { font-size: 11px; }

  /* Очки stay frozen, just smaller column + font. */
  .col-pts    { min-width: 38px; font-size: 12px; padding-left: 4px; padding-right: 4px;
                border-right: 2px solid var(--line-strong); }
  td.col-pts  { font-size: 12px; }

  /* Exact is the only column that unfreezes (scrolls) to save width. */
  .col-exact  { min-width: 38px; }
  table.lb tbody .col-exact { position: static !important; left: auto !important; }
  table.lb thead .col-exact { left: auto !important; z-index: 3 !important; }

  .match-card { min-width: 72px; }
  .match-card .teams { font-size: 11px; white-space: normal; }
  td.pred { min-width: 54px; }
}
