/* ------------------------------------------------------------------------------------------------
   Standings on the broadcast pages: the qualifying broadcast with standings (broadcast-standings.html)
   and the full-standings broadcast (full-standings.html). Loaded after broadcast.css, whose tokens,
   theme switch and one-screen body it uses; this adds the scrolling standings list, the game cards and
   the two pages' layouts, each keyed off <html data-layout>.
   ------------------------------------------------------------------------------------------------ */

:root {
  /* The lines through a list. The cutline is the one a qualifying player reads for, so it is the
     loudest; a bye line is a step down; a cutline that only might move there is quieter still. */
  --cutline: #db2777;
  --byeline: #0369a1;
  --potential: #64748b;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --cutline: #f472b6;
    --byeline: #38bdf8;
    --potential: #94a3b8;
  }
}

:root[data-theme="dark"] {
  --cutline: #f472b6;
  --byeline: #38bdf8;
  --potential: #94a3b8;
}

/* ---- The list ---------------------------------------------------------------------------------- */

/* The window the list scrolls in. Nothing scrolls by hand (the page is a stream source, and the body
   hides overflow); broadcast-standings.js moves it. The soft edges let a row slide in and out rather
   than be cut through, and the fade is the moment the scroller jumps back to the top. */
.standings-viewport {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  transition: opacity 0.45s ease;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 0.35rem, #000 calc(100% - 0.6rem), transparent 100%);
  mask-image: linear-gradient(to bottom, transparent 0, #000 0.35rem, #000 calc(100% - 0.6rem), transparent 100%);
}

.standings-viewport.fading { opacity: 0; }

/* A little room above the first row and below the last, under the soft edges. */
.standings-list {
  padding: 0.3rem 0 0.6rem;
}

/* rank | name | points. The name gives way; the rank column holds three digits. */
.standings-row {
  display: grid;
  grid-template-columns: 2.1rem minmax(0, 1fr) auto;
  align-items: baseline;
  gap: 0 0.35rem;
  font-size: 1rem;
  line-height: 1.3;
  padding: 0.04rem 0.3rem;
  border-radius: 0.3rem;
}

.standings-row:nth-child(even of .standings-row) { background: var(--panel-bg); }

/* The player on the machine. */
.standings-row.mine {
  background: var(--mine-bg);
  box-shadow: inset 0.2rem 0 0 var(--on-game);
}

.standings-row .rank {
  color: var(--muted);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
  padding-right: 0.15rem;
}

.standings-row .name {
  white-space: nowrap;
  overflow: clip visible;
  text-overflow: ellipsis;
  min-width: 0;
}

.standings-row.mine .name { font-weight: 700; }

.standings-row .points {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* A line between two rows: its caption, then the rule running out to the edge. */
.standings-line {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0.1rem 0 0.12rem;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  line-height: 1.1;
  white-space: nowrap;
}

.standings-line::after {
  content: "";
  flex: 1;
  border-top: 0.14rem solid currentColor;
}

.standings-line-label {
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 0 1 auto;
  min-width: 0;
}

.standings-line.cutline { color: var(--cutline); }
.standings-line.bye { color: var(--byeline); }
.standings-line.bye::after { border-top-width: 0.09rem; }
.standings-line.potential { color: var(--potential); }
.standings-line.potential::after { border-top: 0.09rem dashed currentColor; }

/* A division's own heading, for a tournament whose divisions aren't one ranking. */
.standings-division {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0.5rem 0.3rem 0.15rem;
}

.standings-division:first-child { margin-top: 0; }

.standings-note {
  color: var(--muted);
  font-size: 0.95rem;
  padding: 0.2rem 0.3rem;
}

/* ---- The qualifying broadcast with standings ---------------------------------------------------- */

/* Sized for a panel about 1000x590, half of which is the machine: the type is set off that half, and
   still from the smaller of width and height, as broadcast.css does for the whole window. 1000x590
   lands near 17px. */
:root[data-layout="standings"] {
  font-size: clamp(11px, min(1.72vw, 3.05vh), 40px);
}

/* The machine on the left, the standings on the right, halves of the window. */
.split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  column-gap: 0.7rem;
  flex: 1;
  min-height: 0;
}

/* The machine's column stacks, as broadcast.html does in a tall window: the column is one. */
:root[data-layout="standings"] .stage {
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto auto auto minmax(0, 1fr);
  grid-template-areas: "head" "now" "next" "mine" "top";
  min-height: 0;
}

.standings-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--panel-bg);
  border-radius: 0.5rem;
  padding: 0.3rem 0.35rem 0;
  overflow: clip;
}

/* The tournament's name, as big as the machine's beside it, with "Qualifying standings" after it. */
.standings-head {
  display: flex;
  flex-direction: column;
  padding: 0 0.3rem 0.1rem;
  min-width: 0;
}

.standings-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
  text-transform: none;
  letter-spacing: 0;
  line-height: 1.15;
  margin: 0;
  white-space: nowrap;
  overflow: clip visible;
  text-overflow: ellipsis;
}

.standings-sub {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ---- The full-standings broadcast -------------------------------------------------------------- */

/* For a stream between games. The rows are what the type is set for: six columns across, each a name
   beside a number, so the width sets it — 1920 wide lands near 19px. The height only steps in for a
   very short window: the columns scroll, so a short, wide source (a band about 1870x680 under a
   stream's logos) shows fewer, readable rows rather than shrinking every row to fit more. Tying the
   type to 1.75vh did the latter, and such a band fell to the 11px floor with wide gaps between each
   name and its number. */
:root[data-layout="full"] {
  font-size: clamp(11px, min(1vw, 3.3vh), 44px);
}

/* Fewer tournaments, bigger type: each gets a wider share of the window, and the page is more often a
   panel in a stream layout than the whole screen — one tournament in a corner about 770x385 lands near
   20px rather than the 11px floor the three-across size gives it. The width term is the three-across
   one scaled to the group's share; the height term lets a short panel's rows grow, since the columns
   scroll and a row read off a stream matters more than how many fit. Three or more (the six-column
   screen) keep the size above. full-standings.js stamps data-groups. */
:root[data-layout="full"][data-groups="1"] {
  font-size: clamp(12px, min(2.7vw, 5.4vh), 44px);
}

:root[data-layout="full"][data-groups="2"] {
  font-size: clamp(12px, min(1.45vw, 3.2vh), 44px);
}

:root[data-layout="full"] body {
  padding: 0.7rem 0.8rem 0.5rem;
}

/* One group per tournament, side by side, equal widths. */
.full {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  column-gap: 0.9rem;
  flex: 1;
  min-height: 0;
}

/* A tournament: its name across the top, then its game cards and its standings, each a column that
   scrolls by itself. */
.group {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.08fr);
  grid-template-rows: auto auto minmax(0, 1fr);
  grid-template-areas:
    "title title"
    "games-head standings-head"
    "games standings";
  column-gap: 0.45rem;
  min-width: 0;
  min-height: 0;
  background: var(--panel-bg);
  border-radius: 0.6rem;
  padding: 0.45rem 0.45rem 0;
}

.group-title {
  grid-area: title;
  font-size: 1.45rem;
  font-weight: 800;
  color: var(--text);
  text-transform: none;
  letter-spacing: 0;
  line-height: 1.15;
  margin: 0 0.2rem 0.2rem;
  text-align: center;
  white-space: nowrap;
  overflow: clip visible;
  text-overflow: ellipsis;
  min-width: 0;
  padding-bottom: 0.3rem;
  border-bottom: 0.14rem solid var(--group-accent, var(--border));
}

/* Each tournament's accent, from the queue board's palette, so the three read apart at a glance. */
.group:nth-child(4n + 1) { --group-accent: #e69f00; }
.group:nth-child(4n + 2) { --group-accent: #0072b2; }
.group:nth-child(4n + 3) { --group-accent: #009e73; }
.group:nth-child(4n + 4) { --group-accent: #cc79a7; }

.column-head {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 0 0.3rem 0.05rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.games-head { grid-area: games-head; }
.standings-head-full { grid-area: standings-head; }

.group .games-col { grid-area: games; }
.group .standings-col { grid-area: standings; }

/* The game cards: one per machine, its name over its top scores. */
.game-cards {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0.3rem 0 0.6rem;
}

.game-card {
  border: 1px solid var(--border);
  border-radius: 0.45rem;
  padding: 0.25rem 0.35rem 0.3rem;
  background: var(--bg);
}

.game-card h3 {
  font-size: 0.95rem;
  font-weight: 700;
  margin: 0 0 0.1rem;
  white-space: nowrap;
  overflow: clip visible;
  text-overflow: ellipsis;
}

/* name | score — the name gives way, the score never does. */
.game-score {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0 0.4rem;
  align-items: baseline;
  font-size: 0.92rem;
  line-height: 1.3;
}

.game-score .name {
  white-space: nowrap;
  overflow: clip visible;
  text-overflow: ellipsis;
  min-width: 0;
}

.game-score .score {
  color: var(--on-game);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.game-card .none {
  color: var(--muted);
  font-size: 0.85rem;
}

/* The page's status: when it last heard, small, and like broadcast.html's only while the pointer moves
   unless ?chrome=1. */
.full-status {
  position: fixed;
  right: 0.6rem;
  bottom: 0.25rem;
  margin: 0;
  font-size: 0.7rem;
  color: var(--muted);
}

.full-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.status-pill {
  font-size: 0.7rem;
  padding: 0.1rem 0.6rem;
  color: var(--muted);
}

.status-pill:hover,
.status-pill:focus-visible { color: var(--text); border-color: var(--text); }

:root[data-chrome="0"] .full-status {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}

:root[data-chrome="0"][data-pointer="active"] .full-status,
:root[data-chrome="0"] .full-status:focus-within { opacity: 1; pointer-events: auto; }

/* ---- The Tournaments dialog (full-standings.html) ----------------------------------------------
   Which tournaments the page shows and in what order, and the link that holds the choice. A modal
   <dialog>: it sits in the top layer, outside the page's grid, so it restates the ground and ink. */

.tournaments-dialog {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 0.6rem;
  padding: 1rem 1.2rem;
  width: min(36rem, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  max-height: calc(100dvh - 2rem);
}

.tournaments-dialog::backdrop { background: rgba(0, 0, 0, 0.55); }

.tournaments-dialog h2 {
  margin: 0 0 0.35rem;
  font-size: 1.15rem;
  color: var(--text);
  text-transform: none;
  letter-spacing: normal;
}

.tournaments-hint {
  margin: 0 0 0.75rem;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.35;
}

.tournaments-list {
  list-style: none;
  margin: 0 0 0.9rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.tournaments-row {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 0.45rem;
  padding: 0.3rem 0.4rem 0.3rem 0.6rem;
}

.tournaments-row label {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  cursor: pointer;
}

.tournaments-row input { align-self: center; }

.tournaments-name {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.tournaments-key {
  color: var(--muted);
  font-size: 0.8rem;
}

.tournaments-move {
  padding: 0.15rem 0.55rem;
}

.pill:disabled {
  opacity: 0.35;
  cursor: default;
}

.tournaments-link-label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.2rem;
}

.tournaments-link {
  box-sizing: border-box;
  width: 100%;
  font: inherit;
  font-size: 0.85rem;
  color: inherit;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 0.35rem;
  padding: 0.35rem 0.5rem;
}

.tournaments-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.4rem;
  margin-top: 0.75rem;
}

.pill-primary {
  border-color: var(--on-game);
  color: var(--on-game);
  font-weight: 600;
}
