/* A team's roster (chess-teams.js): a popover beside its row on hover, a panel in its row on a click */

/* ─── The roster: board, player, rating, score; in the panel, each round's results under a player */
.ctm-roster {
  font-size: 13px;
  line-height: 20px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.ctm-row {
  display: grid;
  /* Board, player, rating, score: each number column as wide as its widest value (--bd, --rtg,
     --sc from chess-teams.js), in the row's own ch, so the header row keeps the body's font size */
  grid-template-columns:
    max(calc(var(--bd, 1) * 1ch), 16px) minmax(0, 1fr)
    max(calc(var(--rtg, 4) * 1ch), 36px) max(calc(var(--sc, 4) * 1ch), 46px);
  column-gap: 8px;
  align-items: baseline;
  padding: 2px 0;
}
.ctm-row + .ctm-row { border-top: 1px solid var(--line); }
.ctm-head { padding-top: 0; color: var(--muted); }
.ctm-head > span:not(.ctm-mk) { font-size: 10px; font-weight: 700; text-transform: uppercase; }
.ctm-bd { color: var(--muted); font-weight: 600; text-align: right; }
.ctm-pl { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.ctm-pl > span:last-child, .ctm-pl > a { font-weight: 600; }
.ctm-pl a { color: inherit; text-decoration: none; }
.ctm-pl a:hover { text-decoration: underline; text-underline-offset: 3px; }
.ctm-pl a:focus-visible { outline: 2px solid var(--ink); outline-offset: 1px; border-radius: 2px; }
.ctm-num { text-align: right; }
.ctm-rtg { color: var(--muted); }
.ctm-sc { font-weight: 700; }
.ctm-lbl { font-size: 10px; font-weight: 700; text-transform: uppercase; color: var(--muted); }
.ctm-roster .sp-flag {
  display: inline-block;
  width: auto;
  height: .8em;
  aspect-ratio: 4 / 3;
  margin-right: .4em;
  vertical-align: -.06em;
  outline: 1px solid var(--line);
}

/* Each round's result: a small square per round, under the player's name */
.ctm-mk {
  grid-column: 2 / -1;
  display: grid;
  grid-template-columns: repeat(var(--n), 15px);
  gap: 2px;
  margin: 1px 0 2px;
}
.ctm-m, .ctm-rds > span {
  width: 15px;
  height: 15px;
  font: 700 9px/15px var(--body);
  text-align: center;
}
.ctm-m { border-radius: 2px; color: #fff; }
.ctm-w { background: var(--win); }
.ctm-l { background: var(--loss); }
.ctm-d { background: var(--faint); }
.ctm-o { border: 1px solid var(--line-strong); color: var(--muted); line-height: 13px; }
.ctm-x { color: var(--faint); }
.ctm-u { background: var(--surface-2); outline: 1px solid var(--line); outline-offset: -1px; }
.ctm-rds { margin: 0; }
.ctm-rds > span { height: 12px; line-height: 12px; color: var(--faint); font-weight: 600; }

/* ─── Team facts: rank, match points, game points, average rating ─── */
.ctm-facts { display: flex; flex-wrap: wrap; gap: 2px 14px; margin: 0 0 8px; font-size: 12px; line-height: 18px; }
.ctm-facts div { display: flex; gap: 5px; align-items: baseline; }
.ctm-facts dt { color: var(--muted); font-size: 10px; font-weight: 700; text-transform: uppercase; }
.ctm-facts dd { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ─── The popover, fixed beside the team's row ───────────────────── */
.ctm-pop {
  position: fixed;
  z-index: 60;
  top: 0;
  left: 0;
  width: 360px;
  padding: 10px 12px 8px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}
.ctm-pop[hidden] { display: none; }
.ctm-name { margin: 0 0 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 600 18px/1.2 var(--display); }
.ctm-name .sp-flag {
  display: inline-block;
  width: auto;
  height: .62em;
  aspect-ratio: 4 / 3;
  margin-right: .3em;
  vertical-align: .02em;
  outline: 1px solid var(--line);
}

/* ─── The panel, in the team's row under its cells; it slides open like the game viewer ─── */
.chess-teams .chess-tr.ctm-has { height: auto; }
/* While a panel is open, each column keeps its rows */
.chess-teams .chess-tb > .ctm-break { break-before: column; }
.ctm-panel {
  grid-column: 1 / -1;
  display: grid;
  grid-template-rows: 0fr;
  white-space: normal;
  line-height: normal;
  cursor: auto;
  transition: grid-template-rows 260ms cubic-bezier(.25, 1, .5, 1);
}
.ctm-panel.ctm-open { grid-template-rows: 1fr; }
.ctm-in { min-height: 0; overflow: hidden; }
.ctm-body {
  margin: 2px 0 8px;
  padding: 8px 10px 6px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 4px;
}
.chess-team[aria-expanded="true"] { text-decoration: underline; text-underline-offset: 3px; }
tr.ctm-tr > td { padding: 0 14px; border-top: 0; }

@media (prefers-reduced-motion: reduce) {
  .ctm-panel { transition: none; }
}
@media (max-width: 600px) {
  .ctm-body { padding: 8px 8px 6px; }
}
