/* Knockout-bracket rendering (assets/js/bracket.js) plus the multi-phase
   stack it's embedded in on competitions.html (assets/js/
   competition_phase_stack.js): a "current phase on top, resolved phases
   below" view for a competition with prelim rounds + groups + a knockout
   chain (e.g. Libertadores). Uses the same tokens as style.css
   (--surface-1/--border/--accent/--text-*) so it follows light/dark theme
   automatically -- no bracket-specific palette. */

:root {
  --bk-card-w: 236px;
  --bk-gap: 2.5rem;
}

@media (max-width: 640px) {
  :root {
    --bk-card-w: 190px;
    --bk-gap: 1.5rem;
  }
}

.bracket-intro {
  max-width: 720px;
  margin: 0 auto 1rem;
  text-align: center;
  color: var(--text-secondary);
}

/* Horizontal-scroll boundary: the bracket itself can be much wider than the
   viewport (4+ rounds x --bk-card-w), so it scrolls inside this box instead
   of the page body ever growing wider than the viewport. */
.bracket-scroll {
  overflow-x: auto;
  padding-bottom: 1rem;
}

.bracket-inner {
  display: inline-flex;
  flex-direction: column;
  gap: 0.75rem;
  min-width: 100%;
}

.bracket-header-row {
  display: flex;
  gap: var(--bk-gap);
}

.bracket-header-label {
  flex: 0 0 var(--bk-card-w);
  width: var(--bk-card-w);
  text-align: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
}

.bracket-rounds {
  position: relative;
  display: flex;
  align-items: stretch;
  gap: var(--bk-gap);
}

.bracket-lines {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
}

.bracket-line {
  fill: none;
  stroke: var(--baseline);
  stroke-width: 2;
}

.bracket-round {
  position: relative;
  z-index: 1;
  flex: 0 0 var(--bk-card-w);
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  gap: 1.25rem;
}

.bracket-match {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding: 0.55rem 0.7rem 0.6rem;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.bracket-status-badge {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.1rem;
}

.bracket-match.status-in_progress .bracket-status-badge {
  color: var(--accent-text, var(--accent));
}

.bracket-team {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.15rem 0.2rem;
  border-left: 3px solid transparent;
  border-radius: 4px;
}

.bracket-team.is-winner {
  border-left-color: var(--team-color, var(--accent));
  background: var(--page-plane);
}

/* A side that's a confirmed real team in a pair that hasn't been played
   yet (pair.status "scheduled"/"tbd") -- deliberately NOT the same
   treatment as .is-winner (bold + solid colored bar): that would read as
   "this team already won", which is false, it's merely IN this pair. A
   thin neutral (not team-colored) dashed bar plus the "Classificado" tag
   (see bracket.js's renderTeamRow) keeps it visually distinct from both a
   real winner and a plain/eliminated side. */
.bracket-team.is-confirmed {
  border-left-style: dashed;
  border-left-color: var(--gridline);
}

.bracket-confirmed-tag {
  flex: 0 0 auto;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  white-space: nowrap;
}

/* A projected occupant of a slot the real draw hasn't reached yet (see
   competition_phase_stack.js's normalizePair / bracket.js's SIDE_STATE):
   a real team row, but drawn muted + italic + a dashed amber bar so it
   never reads as an official pairing. The section-level
   .bracket-projection-note spells the caveat out in words. */
.bracket-team.is-projected {
  border-left-style: dashed;
  border-left-color: var(--zone-group-third);
}

.bracket-team.is-projected .bracket-team-name {
  font-style: italic;
  color: var(--text-muted);
}

.bracket-team.is-projected .bracket-crest {
  opacity: 0.75;
}

.bracket-projected-tag {
  flex: 0 0 auto;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--zone-group-third);
  white-space: nowrap;
}

.bracket-match.status-projected .bracket-status-badge {
  color: var(--zone-group-third);
}

.bracket-projection-note {
  max-width: 720px;
  margin: 0 0 1rem;
  padding: 0.55rem 0.75rem;
  border-left: 3px solid var(--zone-group-third);
  border-radius: 6px;
  background: var(--page-plane);
  font-size: 0.8rem;
  line-height: 1.4;
  color: var(--text-secondary);
}

.bracket-crest,
.bracket-crest-placeholder {
  width: 22px;
  height: 22px;
  object-fit: contain;
  flex-shrink: 0;
}

.bracket-crest-placeholder {
  border-radius: 50%;
  border: 1.5px dashed var(--gridline);
}

.bracket-team-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
}

/* renderTeamRow emits the full name and the 3-letter acronym side by side;
   only one shows. Full name by default, acronym on the narrow mobile card
   (see the max-width: 640px block below). */
.bracket-team-name-abbr {
  display: none;
}

.bracket-team.is-winner .bracket-team-name {
  color: var(--text-primary);
  font-weight: 700;
}

.bracket-team.is-placeholder .bracket-team-name {
  color: var(--text-muted);
  font-style: italic;
}

.bracket-team-score {
  flex: 0 0 auto;
  min-width: 1.2rem;
  text-align: right;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--text-secondary);
}

.bracket-team.is-winner .bracket-team-score {
  color: var(--accent-text, var(--accent-strong));
}

.bracket-meta {
  margin-top: 0.15rem;
  padding-top: 0.3rem;
  border-top: 1px solid var(--gridline);
  font-size: 0.7rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.bracket-probs {
  margin-top: 0.2rem;
}

.bracket-probs-bar {
  display: flex;
  height: 5px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--gridline);
}

.bracket-probs-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 0.2rem;
  font-size: 0.65rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.bracket-legend {
  max-width: 720px;
  margin: 1.5rem auto 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.4rem 1.2rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.bracket-legend-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.bracket-legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
  background: var(--accent);
}

.bracket-legend-swatch.is-confirmed {
  background: transparent;
  border: 1.5px dashed var(--text-muted);
}

.bracket-legend-swatch.is-placeholder {
  background: transparent;
  border: 1.5px dashed var(--gridline);
}

@media (max-width: 640px) {
  .bracket-match {
    padding: 0.45rem 0.55rem 0.5rem;
  }

  .bracket-crest,
  .bracket-crest-placeholder {
    width: 18px;
    height: 18px;
  }

  .bracket-team-name {
    font-size: 0.75rem;
  }

  /* --bk-card-w drops to 190px here -- too narrow for a full club name
     beside the crest and score, so show the acronym instead. */
  .bracket-team-name-full {
    display: none;
  }

  .bracket-team-name-abbr {
    display: inline;
  }

  .bracket-team-score {
    font-size: 0.8rem;
  }

  .bracket-status-badge,
  .bracket-meta {
    font-size: 0.6rem;
  }
}

/* ── Phase stack (assets/js/competition_phase_stack.js): one <section> per
   phase shown, most-advanced phase first (see that module for how "most
   advanced" is decided), each labeled and visually demoted the further back
   (i.e. the more resolved/historical) it is. */
.phase-stack {
  display: flex;
  flex-direction: column;
  gap: 1.75rem;
}

.phase-stack-section {
  padding-top: 0.25rem;
}

.phase-stack-section:not(:first-child) {
  padding-top: 1.5rem;
  border-top: 1px solid var(--gridline);
}

.phase-stack-heading {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  margin: 0 0 0.9rem;
}

.phase-stack-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1rem;
  color: var(--text-primary);
}

.phase-stack-section:not(:first-child) .phase-stack-title {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.phase-stack-status {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.phase-stack-section:first-child .phase-stack-status {
  color: var(--accent-text, var(--accent));
}

/* ── Group tables (round_robin phase w/ `groups`, e.g. Libertadores' 8
   groups of 4) -- one compact table per group, reusing style.css's
   .team-cell/.rank-number/.crest/.team-name conventions so a group row
   looks like a smaller version of the main standings table. CSS grid rows
   (.group-table-row), not a <table> -- see competition_phase_stack.js's
   renderGroupRow for why a <table>'s column-width model didn't reliably
   leave room for a long team name to ellipsis instead of wrapping/clipping. */
.groups-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}

@media (max-width: 640px) {
  .groups-grid {
    grid-template-columns: 1fr;
  }
}

.group-table-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-1);
  overflow: hidden;
  /* Size container: the acronym-vs-name switch below keys off THIS card's
     width, not the viewport (.groups-grid is 2-up until 640px, so a card
     can be ~300px wide at a 900px viewport). */
  container-type: inline-size;
}

/* The team column stays frozen while the 10 numeric columns (P/J/V/GP/GC/SG
   + 1º/2º/3º) scroll under it -- they don't all fit next to the team name
   on a narrow card. Rows are sized to their content and overflow this box;
   .team-cell is sticky. */
.group-table-scroll {
  overflow-x: auto;
}

.group-table-label {
  padding: 0.5rem 0.7rem;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--gridline);
}

.group-table-row {
  display: grid;
  /* DEFAULT (narrow card): fixed 6.75rem team column showing rank + crest +
     the 3-letter acronym, plus 6 stat + N prob fixed columns -- prob-cell
     at 2.85rem so a 1-decimal percentage ("100.0%"), minus its
     padding-inline, never clips its neighbour. The row is
     `width: max-content` so those columns keep full width and spill past
     the card, scrolled via .group-table-scroll, with the acronym column
     frozen. `--group-prob-cols` (set once per competition on .groups-grid,
     inherited down -- see renderGroupTables) varies the LAST `repeat()`
     count: Libertadores shows 1º/2º/3º (3), Sudamericana only 1º/2º (2); a
     grid with fewer items than declared columns just leaves the extras
     blank, so a competition that doesn't set the variable still works
     (falls back to 3). The @container rule below switches back to the full
     name once the card is wide enough to hold it. */
  grid-template-columns: 6.75rem repeat(6, 1.85rem) repeat(var(--group-prob-cols, 3), 2.85rem);
  align-items: center;
  /* No column-gap: a transparent gap right of the frozen team column lets
     the scrolling numeric columns show through it (the Série A/B <td>s
     don't have this problem -- adjacent, no gap). Tracks touch instead and
     each carries its own padding-inline, so a scrolled column slides fully
     under the frozen cell's opaque background. */
  column-gap: 0;
  padding: 0.4rem 0.4rem;
  border-bottom: 1px solid var(--gridline);
  width: max-content;
  min-width: 100%;
}

.group-table-row > * {
  padding-inline: 0.15rem;
}

/* Default (narrow) shows the acronym; the @container rule below swaps to
   the full name. The abbr display: inline is needed to override the global
   `.team-name-abbr { display: none }` in style.css. */
.group-table-row .team-name-full {
  display: none;
}

.group-table-row .team-name-abbr {
  display: inline;
}

/* Compact frozen column: tighten the rank gutter so rank + crest + the
   3-letter acronym all fit the 6.75rem track without clipping. */
.group-table-row .rank-number {
  min-width: 1.15rem;
}

/* Freeze the team column; the numeric columns scroll under its opaque
   background. align-self: stretch + flex so the background covers the full
   row height, and a same-colour hard shadow seals the trailing sub-pixel
   seam (invisible). */
.group-table-row > .team-cell,
.group-table-header-row > span:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--surface-1);
  align-self: stretch;
  display: flex;
  align-items: center;
  box-shadow: 4px 0 0 var(--surface-1);
}

/* Roomy card (~30rem+): the full club name fits beside every numeric
   column, so show it and let the team track flex; no horizontal scroll. */
@container (min-width: 30rem) {
  .group-table-row {
    grid-template-columns: minmax(9rem, 1fr) repeat(6, 1.85rem) repeat(
        var(--group-prob-cols, 3),
        2.85rem
      );
    width: auto;
    min-width: 0;
  }

  .group-table-row .team-name-full {
    display: inline;
  }

  .group-table-row .team-name-abbr {
    display: none;
  }

  /* Long names must ellipsis inside the flexible team track now. */
  .group-table-row .team-name {
    flex-shrink: 1;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .group-table-row .rank-number {
    min-width: 1.5rem;
  }
}

.group-table-row:last-child {
  border-bottom: none;
}

.group-table-header-row {
  padding-top: 0.35rem;
  padding-bottom: 0.35rem;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-muted);
  text-align: center;
}

.group-table-header-row span:first-child {
  text-align: left;
}

.group-table-row .stat-cell {
  text-align: center;
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
}

.group-table-row .team-cell {
  min-width: 0;
  gap: 0.4rem;
  overflow: hidden;
}

/* Compact mode shows the 3-letter acronym -- it always fits, so don't let
   it shrink or ellipsis (the @container rule below re-enables clipping for
   the full name). */
.group-table-row .team-name {
  min-width: 0;
  flex-shrink: 0;
  white-space: nowrap;
  font-size: 0.8rem;
}

.group-table-row .crest {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

/* Real (not simulated) group-stage position, not the combined
   `standings.zone` (which used to drive this and, for Libertadores, lumps
   1st/2nd into one shared "knockout" color regardless of each rank's own
   real outcome) -- which rank gets which color (or none) is decided
   per-competition by `groupRankHighlight` (see PHASE_STACK_CONFIG's own
   comment on why Libertadores shares blue across 1st+2nd while Sudamericana
   splits blue/amber between them: each rank's own real next step differs
   between the two competitions). */
.group-table-row.rank-blue .team-cell {
  border-left-color: var(--zone-libertadores-grupos);
}

.group-table-row.rank-amber .team-cell {
  border-left-color: var(--zone-group-third);
}

/* ── Title probabilities (assets/js/competition_phase_stack.js's own
   renderTitleProbabilities -- always the page's first section). One row per
   team, ranked by prob_champion descending, with a column per how-far-they-
   get spot (see TITLE_PROB_COLUMNS) -- same rank-number/crest/team-name/
   stat-cell/prob-cell conventions the group tables already use. */
.title-probs-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-1);
  overflow-x: auto;
}

.title-probs-row {
  display: grid;
  /* `--title-probs-stat-cols` (set once on .title-probs-card, inherited down
     -- see competition_phase_stack.js's renderTitleProbabilitiesSection)
     varies per competition: Libertadores has 6 stat columns, Sudamericana
     has 7 (see PHASE_STACK_CONFIG's own titleProbColumns). A hardcoded
     `repeat(6, ...)` here used to silently swallow Sudamericana's 7th
     column into a wrapped extra grid row (a plain CSS grid places overflow
     items into an implicit next row instead of erroring) -- reading the
     real count instead fixes that for any competition, present or future,
     without needing to hardcode a second magic number here. Team-name
     column narrowed from minmax(15rem, ...) -- wider than it needed to be,
     it left less room than a 7-column competition's stat columns actually
     need before the row's min-width forces horizontal scroll. */
  grid-template-columns: 2rem minmax(11rem, 1.2fr) repeat(
      var(--title-probs-stat-cols, 6),
      minmax(4.1rem, 1fr)
    );
  align-items: center;
  /* No column-gap: the gap used to be a transparent strip that the
     scrolling probability columns showed through, just right of the frozen
     team cell. Adjacent tracks now touch (like the Série A/B <td>s), so a
     scrolled column slides fully under the frozen cell's opaque
     background. Each track carries the old 0.5rem of spacing as its own
     padding-inline instead, so a stat cell's usable width is unchanged. */
  column-gap: 0;
  padding: 0.45rem 0.7rem;
  border-bottom: 1px solid var(--gridline);
  min-width: calc(13rem + var(--title-probs-stat-cols, 6) * 4.1rem);
}

.title-probs-row > * {
  padding-inline: 0.25rem;
}

.title-probs-row:last-child {
  border-bottom: none;
}

.title-probs-row .team-cell {
  min-width: 0;
  overflow: hidden;
  gap: 0.5rem;
}

/* Freeze rank + team while the probability columns scroll under them
   (mirrors the group tables). nth-child rather than a class so the same
   rule pins the header row's cells: the rank track is 2rem and there's no
   column-gap, so the team cell sticks at 2rem. */
.title-probs-row > :nth-child(1),
.title-probs-row > :nth-child(2) {
  position: sticky;
  z-index: 1;
  background: var(--surface-1);
  /* align-items: center leaves each cell only as tall as its content, so a
     scrolled column peeks above and below it -- stretch + flex-centre the
     content instead. The same-colour hard shadow seals the sub-pixel seam
     at the trailing edge (invisible, unlike the earlier grey one). */
  align-self: stretch;
  display: flex;
  align-items: center;
  box-shadow: 4px 0 0 var(--surface-1);
}

.title-probs-row > :nth-child(1) {
  left: 0;
  justify-content: flex-end;
}

.title-probs-row > :nth-child(2) {
  left: 2rem;
}

/* Base .stat-cell/.prob-cell (style.css) have no text-align of their own --
   inside an actual <table> they inherit centering from the global `tbody
   td` rule, but these are grid <span>s, not <td>s, so that rule never
   reaches them. Same fix .group-table-row already has. */
.title-probs-row .stat-cell {
  text-align: center;
}

.title-probs-header-row {
  padding-top: 0.35rem;
  padding-bottom: 0.35rem;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-muted);
  text-align: center;
}

.title-probs-header-row span:nth-child(2) {
  text-align: left;
}

/* "Mostrar todos os times" / "Mostrar menos" toggle below the title-probs
   table (competition_phase_stack.js's own renderTitleProbabilitiesSection).
   Same pill-button look as .table-toggle-button (style.css) -- this used to
   fall back to unstyled browser defaults since matches.css (which defined
   these same class names for a different, unrelated feature) is never
   loaded on the probabilidades page. */
.load-more-wrap {
  display: flex;
  justify-content: center;
  margin: 0.75rem 0 0;
}

.load-more-btn {
  font: inherit;
  font-weight: 600;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-secondary);
  cursor: pointer;
}

.load-more-btn:hover {
  color: var(--text-primary);
  border-color: var(--accent);
}

/* Narrow screen: collapse the frozen team column to just crest + the
   3-letter acronym (rank is its own column), same idea as the Série A/B
   and group tables. Placed after every base .title-probs-row rule above so
   its grid-template-columns / gap actually win -- a @media block adds no
   specificity, so source order decides. */
@media (max-width: 640px) {
  .title-probs-row {
    grid-template-columns: 2rem 4.5rem repeat(var(--title-probs-stat-cols, 6), minmax(4.1rem, 1fr));
    min-width: calc(6.5rem + var(--title-probs-stat-cols, 6) * 4.1rem);
  }

  .title-probs-row .team-cell {
    gap: 0.3rem;
  }

  .title-probs-row .crest {
    width: 18px;
    height: 18px;
  }

  .title-probs-row .team-name-full {
    display: none;
  }

  .title-probs-row .team-name-abbr {
    display: inline;
  }
}
