/* Chess league pages (chess.js): major events from Lichess broadcasts. */

.sp-chess { display: grid; gap: 24px; }
.sp-chess > * { min-width: 0; }

/* Section headings: the condensed face in capitals, like the box score's. */
.chess-hd {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 2px 12px;
  margin: 0 2px 8px;
}
.chess-hd h2 {
  margin: 0;
  font: 600 17px/1.2 var(--display);
  letter-spacing: .05em;
  text-transform: uppercase;
}
.chess-note { font-size: 13px; color: var(--muted); }

/* ─── Tables ───────────────────────────────────────────── */

.chess-t { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: 14px; }
.chess-t thead th {
  padding: 10px 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chess-t td {
  padding: 9px 8px;
  border-top: 1px solid var(--line);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: baseline;
}
/* Numbers are never cut. Their cells show in full, in tabular figures (each no wider than 1ch,
   bold too), in columns as wide as their widest value: a --bd, --rtg… count of characters set on
   the table from its data (chess.js), with the column's padding, never narrower than its old fixed
   width. On a narrow screen the names beside them give way. */
.chess-t td.chess-bd, .chess-t td.chess-num, .chess-t td.chess-rk, .chess-t td.chess-res, .chess-t td.chess-ks, .chess-t td.chess-x {
  overflow: visible;
  text-overflow: clip;
  font-variant-numeric: tabular-nums;
}
.chess-t th:first-child, .chess-t td:first-child { padding-left: 14px; }
.chess-t th:last-child, .chess-t td:last-child { padding-right: 14px; }
.chess-t .chess-num { text-align: right; }
.chess-t a { text-decoration: none; font-weight: 600; }
.chess-t a:hover { text-decoration: underline; text-underline-offset: 3px; }
.chess-t a:focus-visible { outline: 2px solid var(--ink); outline-offset: 1px; border-radius: 2px; }

.chess-title { font-size: 11px; font-weight: 700; color: var(--muted); }
.chess-short, .chess-sub { display: none; }
.chess-pending { color: var(--faint); }

/* Long lists show their first rows until expanded. */
.chess-extra { display: none; }
.chess-all .chess-extra { display: table-row; }
.chess-more-btn {
  display: block;
  width: 100%;
  padding: 10px;
  border: 0;
  background: var(--surface-2);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.chess-more-btn:hover { background: var(--line); }
.chess-more-btn:focus-visible { outline: 2px solid var(--ink); outline-offset: -2px; }

/* ─── Season: events ───────────────────────────────────── */

.chess-events .chess-dates { width: 132px; }
.chess-events .chess-place { width: 28%; }
.chess-events col.chess-c-rds { width: max(calc(var(--rds, 5) * 1ch + 22px), 80px); }
.chess-events td.chess-dates, .chess-events td.chess-place { color: var(--muted); }
.chess-events td.chess-dates { white-space: normal; } /* a long range wraps rather than losing its days */
.chess-events td.chess-ev { white-space: normal; }
.chess-evn { font-size: 15px; }
.chess-secs { display: flex; flex-wrap: wrap; gap: 2px 14px; margin-top: 3px; font-size: 13px; }
.chess-t a.chess-sec { font-weight: 500; color: var(--muted); text-decoration: underline; text-decoration-color: var(--line-strong); text-underline-offset: 3px; }
.chess-t a.chess-sec:hover { color: var(--ink); text-decoration-color: currentColor; }
td.chess-rds { font-weight: 600; }

/* The current season: its events beside the FIDE ranking, as tennis's season page has its
   tournaments beside the ATP ranking; one above the other on narrower screens. */
.chess-season {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 24px 16px;
  align-items: start;
}
.chess-season > * { min-width: 0; }
.chess-rank .chess-note { line-height: 1; } /* the month doesn't push the card below the events' */
.chess-rank-t { font-variant-numeric: tabular-nums; }
.chess-rank-t .chess-rk { text-align: right; }
.chess-rank-t col.chess-c-rk { width: max(calc(var(--rk, 3) * 1ch + 22px), 50px); }
.chess-rank-t col.chess-c-rtg { width: max(calc(var(--rtg, 4) * 1ch + 22px), 76px); }
.chess-rank-t td { padding-top: 7px; padding-bottom: 7px; }
.chess-rank-t td.chess-rtg { color: var(--ink); }
.chess-rank-t .chess-nf { visibility: hidden; } /* no flag (FIDE's own): the name stays in line */

/* ─── Event page ───────────────────────────────────────── */

.chess-nav { margin: 0 2px -8px; font-size: 14px; }
.chess-nav a { color: var(--muted); text-decoration: none; font-weight: 600; }
.chess-nav a:hover { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }
.chess-nav a:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; border-radius: 2px; }

.chess-head { margin: 0 2px; display: grid; gap: 10px; }

.chess-tabs, .chess-rpick { display: flex; flex-wrap: wrap; gap: 6px; }
.chess-tabs > *, .chess-rpick > * {
  display: inline-block;
  padding: 5px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
}
.chess-rpick { margin-bottom: 10px; }
.chess-rpick > * { min-width: 36px; padding: 4px 8px; text-align: center; }
.chess-tabs > span, .chess-rpick > span { background: transparent; color: var(--faint); border-color: var(--line); }
.chess-tabs a:hover, .chess-rpick a:hover { background: var(--surface-2); }
.chess-tabs a[aria-current], .chess-rpick a[aria-current] { background: var(--ink); border-color: var(--ink); color: var(--surface); }
.chess-tabs a:focus-visible, .chess-rpick a:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

.chess-facts { margin: 0; display: flex; flex-wrap: wrap; gap: 6px 22px; font-size: 14px; }
.chess-facts > div { display: flex; align-items: baseline; gap: 7px; min-width: 0; }
.chess-facts dt { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); white-space: nowrap; }
.chess-facts dd { margin: 0; }
.chess-facts a { font-weight: 600; }

/* Standings and crosstables size to their content and scroll sideways when wider than the page. */
.chess-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.chess-std, .chess-match, .chess-res { table-layout: auto; }
.chess-std td, .chess-match td, .chess-res td { overflow: visible; }
/* A list-built event's result (no games): place, player, a match's points. */
.chess-res .chess-pl { width: 99%; }
.chess-res .chess-num { width: 1%; }
.chess-rk { width: 40px; }
td.chess-rk { color: var(--muted); font-weight: 600; }
td.chess-pl { font-weight: 600; }
.chess-std .chess-pl, .chess-match .chess-pl { width: 99%; }
.chess-std .chess-num, .chess-match .chess-num { width: 1%; }
td.chess-pts { font-weight: 700; }
td.chess-fed, td.chess-rtg, td.chess-pld, td.chess-perf, td.chess-diff, td.chess-elo { color: var(--muted); }
.chess-t .chess-x { width: 1%; min-width: 30px; padding-left: 5px; padding-right: 5px; text-align: center; font-size: 13px; }
.chess-cross td.chess-pl, .chess-cross th.chess-pl, .chess-match td.chess-pl, .chess-match th.chess-pl {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--surface);
}
td.chess-self { background: var(--line); }
/* Each result opens its game in Rounds. A double round robin's two results in one cell are kept
   apart so 1 and ½ never read as 1½. */
.chess-xg {
  display: inline-block;
  min-width: 1.4em;
  margin: -3px 0;
  padding: 3px;
  border: 0;
  border-radius: 4px;
  background: none;
  font: inherit;
  line-height: inherit;
  color: inherit;
  cursor: pointer;
}
.chess-xg + .chess-xg { margin-left: 3px; }
.chess-xg:hover { background: var(--line); }
.chess-xg:focus-visible { outline: 2px solid var(--ink); outline-offset: 1px; }

.chess-ko .chess-ka { text-align: right; }
.chess-ko .chess-ks { text-align: center; font-weight: 700; }
.chess-ko col.chess-c-ks { width: max(calc(var(--ks, 3) * 1ch + 16px), 84px); }

/* Teams: dense rows flowing down up to three columns (data-cols, fewer on narrower screens),
   one header per column, a 1 px rule between columns. */
.chess-t.chess-teams { --c: 3; font-size: 13px; font-variant-numeric: tabular-nums; }
.chess-teams[data-cols="2"] { --c: 2; }
.chess-teams[data-cols="1"] { --c: 1; }
.chess-th, .chess-tb { column-count: var(--c); column-gap: 1px; column-rule: 1px solid var(--line); }
.chess-teams .chess-tr {
  display: grid;
  /* Rank, team, rating, match points, game points: each number column as wide as its widest
     value (--rk… from chess.js), in the row's own ch, so the header row keeps the body's font size */
  grid-template-columns:
    max(calc(var(--rk, 3) * 1ch), 24px) minmax(0, 1fr) max(calc(var(--rtg, 4) * 1ch), 34px)
    max(calc(var(--mp, 2) * 1ch), 22px) max(calc(var(--gp, 4) * 1ch), 32px);
  column-gap: 8px;
  align-items: center;
  height: 23px;
  padding: 0 12px;
  break-inside: avoid;
  line-height: 22px;
  white-space: nowrap;
}
.chess-teams .chess-th .chess-tr { height: 26px; color: var(--muted); }
.chess-teams .chess-th .chess-tr > * { font-size: 10px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.chess-teams .chess-tb .chess-tr { border-top: 1px solid var(--line); }
.chess-teams .chess-extra { display: none; }
.chess-all .chess-teams .chess-extra { display: grid; }
.chess-teams .chess-rk { width: auto; }
.chess-teams .chess-tb .chess-rk, .chess-teams .chess-tb .chess-rtg { color: var(--muted); }
.chess-teams .chess-tb .chess-rk { font-weight: 600; }
.chess-teams .chess-tb .chess-pts { font-weight: 700; }
.chess-teams .chess-pl { min-width: 0; overflow: hidden; }
.chess-team {
  display: block;
  max-width: 100%;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  font-weight: 600;
  line-height: inherit;
  color: inherit;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}
.chess-team:hover { text-decoration: underline; text-underline-offset: 3px; }
.chess-team:focus-visible { outline: 2px solid var(--ink); outline-offset: -2px; border-radius: 2px; }
@media (max-width: 900px) {
  .chess-teams[data-cols="3"] { --c: 2; }
  .chess-teams[data-cols="3"] .chess-th .chess-tr:nth-child(3) { display: none; }
}
@media (max-width: 600px) {
  .chess-t.chess-teams { --c: 1; }
  .chess-teams .chess-th .chess-tr:nth-child(n + 2) { display: none; }
  .chess-teams .chess-tr { padding: 0 10px; }
}

/* Rounds: games under a row per round (or per team match). The board and rating columns are as
   wide as their widest numbers: an Olympiad's boards run past 100. */
.chess-games col.chess-c-bd { width: max(calc(var(--bd, 2) * 1ch + 22px), 44px); }
.chess-games col.chess-c-elo { width: max(calc(var(--elo, 4) * 1ch + 16px), 58px); }
.chess-games .chess-res { width: 66px; text-align: center; }
.chess-games .chess-exp { width: 42px; }
.chess-games td.chess-bd { color: var(--muted); }
.chess-games td.chess-w, .chess-games td.chess-b { font-weight: 600; }
.chess-games td.chess-res { font-weight: 700; }
.chess-open { color: var(--faint); }
.chess-g { cursor: pointer; scroll-margin-top: 8px; }
.chess-g:hover td, .chess-g.chess-on td { background: var(--surface-2); }

/* A long round or match line wraps between its names; the match score and the date stay whole. */
.chess-round th, .chess-match-row th {
  padding: 9px 14px;
  border-top: 1px solid var(--line);
  background: var(--surface-2);
  text-align: left;
  white-space: normal;
}
.chess-ms, .chess-rdate { white-space: nowrap; }
.chess-round th { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.chess-rdate { margin-left: 10px; font-weight: 600; letter-spacing: 0; text-transform: none; color: var(--faint); }
.chess-match-row th { font-size: 13px; font-weight: 600; }
.chess-ms { margin: 0 6px; font-weight: 700; font-variant-numeric: tabular-nums; }

td.chess-exp { padding: 0; text-align: center; vertical-align: middle; }
.chess-exp-btn {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.chess-exp-btn svg { transition: transform .15s ease; }
.chess-exp-btn[aria-expanded="true"] svg { transform: rotate(180deg); }
.chess-exp-btn:hover { background: var(--line); color: var(--ink); }
.chess-exp-btn:focus-visible { outline: 2px solid var(--ink); outline-offset: 1px; }

/* ─── Narrow screens ───────────────────────────────────── */

@media (max-width: 900px) {
  .chess-season { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 600px) {
  .chess-season { row-gap: 20px; }
  .chess-rank-t col.chess-c-rk { width: max(calc(var(--rk, 3) * 1ch + 14px), 42px); }
  .sp-chess { gap: 20px; }
  .chess-t { font-size: 13.5px; }
  .chess-t thead th { font-size: 10px; letter-spacing: .04em; }
  .chess-t th, .chess-t td { padding-left: 4px; padding-right: 4px; }
  .chess-t th:first-child, .chess-t td:first-child { padding-left: 10px; }
  .chess-t th:last-child, .chess-t td:last-child { padding-right: 10px; }
  .chess-long, .chess-title { display: none; }
  /* Columns left out on phones are collapsed to nothing: a display: none cell still gets a
     share of a fixed-layout table's width in Chromium. */
  .chess-events .chess-place, .chess-games .chess-elo, .chess-games col.chess-c-elo { width: 0; padding: 0; font-size: 0; }
  .chess-short { display: inline; }
  .chess-sub { display: block; margin-top: 2px; font-size: 12px; color: var(--muted); }
  .chess-events .chess-dates { width: 74px; }
  .chess-events td.chess-dates { white-space: normal; font-size: 12.5px; }
  .chess-events col.chess-c-rds { width: max(calc(var(--rds, 5) * 1ch + 14px), 52px); }
  .chess-std:not(.chess-cross) .chess-fed, .chess-std:not(.chess-cross) .chess-perf, .chess-std:not(.chess-cross) .chess-diff { display: none; }
  .chess-rk { width: 32px; }
  .chess-games col.chess-c-bd { width: max(calc(var(--bd, 2) * 1ch + 14px), 34px); }
  .chess-games .chess-res { width: 46px; }
  .chess-games .chess-exp { width: 32px; }
  .chess-ko col.chess-c-ks { width: max(calc(var(--ks, 3) * 1ch + 8px), 64px); }
  .chess-facts { font-size: 13px; gap: 4px 16px; }
}

/* ─── Federation flags (sports/flags.js) ──────────────── */

/* Before player and team names: tables, the game viewer's players, the preview's names. */
.chess-t .sp-flag, .cg-pname .sp-flag, .cpk-names .sp-flag {
  display: inline-block;
  width: auto;
  height: .8em;
  aspect-ratio: 4 / 3;
  margin-right: .4em;
  vertical-align: -.06em;
  outline: 1px solid var(--line);
}
/* The preview's names are 18 px: the flag stays the tables' 11 px. */
.cpk-names .sp-flag { height: .62em; margin-right: .3em; vertical-align: .02em; }
