/* =========================================================
   Turnierbaum
   ---------------------------------------------------------
   Konkurrenz-Umschalter, Gruppenphase und KO-Baum. Tablet und
   Desktop zeigen den ganzen Baum, das Smartphone Runde für Runde.
   Bausteine ui-* kommen aus components.css, Farben aus tokens.css.
   ========================================================= */

body {
  margin: 0;
  background: var(--background-primary, #f5f7fa);
  color: var(--text-primary, #003366);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

.baum-main p,
.baum-main h2,
.baum-main h3 {
  margin: 0;
}

.baum-empty {
  color: var(--text-secondary, #52606d);
  font-size: 14px;
}

.baum-toolbar .ui-seg {
  max-width: 100%;
}

.baum-head {
  display: grid;
  gap: 2px;
  padding: 14px 16px;
}

.baum-head .ui-section-title {
  margin: 0;
}

.baum-main .baum-head h2 {
  font-size: 19px;
}

.baum-main .baum-section-title {
  margin: 6px 0 0;
}

.baum-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  color: var(--text-secondary, #52606d);
  font-size: 13px;
}

/* Gruppenphase */

.baum-groups {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr));
  gap: 16px;
}

.baum-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.baum-table th {
  padding: 6px 4px;
  border-bottom: 1px solid var(--border-subtle, #e6eaef);
  color: var(--text-secondary, #52606d);
  font-size: 12px;
  font-weight: 700;
  text-align: right;
}

.baum-table td {
  padding: 8px 4px;
  border-bottom: 1px solid var(--border-subtle, #e6eaef);
  text-align: right;
  white-space: nowrap;
}

.baum-table th:nth-child(2),
.baum-table td:nth-child(2) {
  width: 100%;
  text-align: left;
  white-space: normal;
}

.baum-table th:first-child,
.baum-table td:first-child {
  color: var(--text-secondary, #52606d);
  text-align: left;
}

.baum-table tr.is-qualified td:first-child {
  color: var(--status-success, #0a7a2f);
  font-weight: 800;
}

.baum-table abbr {
  text-decoration: none;
}

.baum-group-matches {
  border-top: 1px solid var(--border-subtle, #e6eaef);
}

.baum-group-match {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  font-size: 14px;
}

.baum-group-players {
  flex: 1;
  min-width: 0;
}

.baum-group-players .is-winner {
  font-weight: 700;
}

.baum-group-score {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* KO-Baum */

.bracket-scroll {
  overflow-x: auto;
  overscroll-behavior-x: contain;
  padding: 0 16px 16px;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
}

.bracket-scroll:focus-visible {
  outline: 3px solid var(--focus-ring, #084e8e);
  outline-offset: -3px;
}

.bracket-tree {
  display: flex;
  min-width: max-content;
}

.bracket-round {
  display: flex;
  flex-direction: column;
  width: 236px;
  scroll-snap-align: start;
}

.baum-main .bracket-round-title {
  padding: 10px 0 8px;
  color: var(--text-secondary, #52606d);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.bracket-round-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  justify-content: space-around;
}

.bracket-pair {
  position: relative;
  display: flex;
  flex: 1;
  flex-direction: column;
  justify-content: space-around;
  padding-right: 28px;
}

/* Klammer zwischen den beiden Zubringern eines Spiels */
.bracket-pair::after {
  position: absolute;
  top: 25%;
  right: 14px;
  bottom: 25%;
  width: 14px;
  border: 2px solid var(--border-default, #d7d7d7);
  border-left: 0;
  border-radius: 0 8px 8px 0;
  content: "";
}

.bracket-pair.is-single::after {
  top: 50%;
  bottom: auto;
  border-width: 2px 0 0;
  border-radius: 0;
}

.bracket-round:last-child .bracket-pair::after {
  display: none;
}

.bracket-slot {
  position: relative;
  padding: 8px 0;
}

/* Verbindung von der Klammer zum Spiel der nächsten Runde */
.bracket-round + .bracket-round .bracket-slot::before {
  position: absolute;
  top: 50%;
  left: -14px;
  width: 14px;
  border-top: 2px solid var(--border-default, #d7d7d7);
  content: "";
}

.bracket-match {
  overflow: hidden;
  border: 1px solid var(--border-subtle, #e6eaef);
  border-radius: 12px;
  background: var(--surface-primary, #ffffff);
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.05);
}

.bracket-match.is-open {
  border-style: dashed;
}

.bracket-player {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 0 10px;
  font-size: 14px;
}

.bracket-player + .bracket-player {
  border-top: 1px solid var(--border-subtle, #e6eaef);
}

.bracket-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bracket-player.is-winner {
  box-shadow: inset 3px 0 0 var(--status-success, #0a7a2f);
  font-weight: 700;
}

.bracket-player.is-winner .bracket-name::after {
  color: var(--status-success, #0a7a2f);
  content: " ✓";
}

.bracket-player.is-placeholder .bracket-name {
  color: var(--text-secondary, #52606d);
  font-style: italic;
}

.bracket-score {
  display: flex;
  gap: 6px;
  color: var(--text-secondary, #52606d);
  font-variant-numeric: tabular-nums;
}

.bracket-score strong {
  color: var(--text-primary, #003366);
}

.bracket-seed {
  color: var(--text-secondary, #52606d);
  font-size: 11px;
  font-weight: 700;
}

.bracket-walkover {
  color: var(--text-secondary, #52606d);
  font-size: 11px;
  font-weight: 700;
}

/* Runde für Runde (Smartphone) */

.bracket-rounds {
  display: none;
}

.bracket-round-switch {
  width: 100%;
  margin-bottom: 10px;
}

.bracket-round-switch button {
  flex: 1;
  justify-content: center;
  padding: 0 8px;
}

.bracket-round-list {
  display: grid;
  gap: 10px;
}

.bracket-round-list[hidden] {
  display: none;
}

@media (max-width: 699px), (max-height: 599px) {
  .bracket-scroll {
    display: none;
  }

  .bracket-rounds {
    display: block;
    padding: 0 16px 16px;
  }

  .baum-toolbar {
    display: grid;
    grid-template-columns: 1fr auto;
  }

  .baum-toolbar .ui-seg {
    grid-column: 1 / -1;
    width: 100%;
  }

  .baum-toolbar .ui-seg a {
    flex: 1;
    justify-content: center;
  }

  .baum-toolbar .ui-spacer {
    display: none;
  }

  .baum-col-optional {
    display: none;
  }
}

@media print {
  .baum-toolbar {
    display: none !important;
  }

  .bracket-scroll {
    overflow: visible;
  }
}
