/* 
 * CSS Custom Properties (Variables)
 * Themes can override these by targeting .tournament-bracket-wrapper
 * Example in your theme:
 * .tournament-bracket-wrapper {
 *   --tb-primary-color: #your-color;
 *   --tb-border-color: #your-color;
 * }
 */
.tournament-bracket-wrapper {
  /* Colors */
  --tb-primary-color: #333;
  --tb-secondary-color: #555;
  --tb-muted-color: #666;
  --tb-border-color: #b19831;
  --tb-background: white;
  --tb-background-alt: #f9f9f9;
  --tb-background-hover: #f5f5f5;
  --tb-winner-bg: #b19831;
  --tb-error-bg: #fee;
  --tb-error-border: #fcc;
  --tb-error-text: #c00;
  --tb-accent-color: #0073aa;
  
  /* Spacing */
  --tb-spacing-sm: 10px;
  --tb-spacing-md: 20px;
  --tb-spacing-lg: 40px;
  --tb-spacing-xl: 60px;
  
  /* Borders */
  --tb-border-radius: 6px;
  --tb-border-width: 2px;
  
  /* Typography */
  --tb-font-family: Arial, sans-serif;
  --tb-font-size-base: 16px;
  --tb-font-size-sm: 0.9vw;
  
  /* Shadows */
  --tb-shadow-sm: 0 2px 4px rgba(0,0,0,0.1);
  --tb-shadow-md: 0 4px 8px rgba(0,0,0,0.15);
  
  /* Layout */
  --tb-match-width: 400px;
  --tb-round-gap: 40px;
  
  /* Connector Lines */
  --tb-connector-color: #b19831;
  --tb-connector-width: 2px;
  
  /* Application */
  margin-bottom: var(--tb-spacing-xl);
  padding-bottom: var(--tb-spacing-lg);
  border-bottom: 3px solid var(--tb-border-color);
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.tournament-bracket-wrapper:last-child {
  border-bottom: none;
  margin-bottom: 0;
}

.tournament-container {
  margin: 0 auto;
  padding: var(--tb-spacing-md);
  font-family: var(--tb-font-family);
  box-sizing: border-box;
}

.tournament-header {
  text-align: center;
  margin-bottom: calc(var(--tb-spacing-md) + 10px);
  width: 100%;
}

.tournament-header h1 {
  margin: var(--tb-spacing-sm) 0;
  color: var(--tb-primary-color);
}

.bracket-wrapper {
  overflow-x: auto;
  overflow-y: visible;
  padding: var(--tb-spacing-md) 0;
  -webkit-overflow-scrolling: touch;
  width: 100%;
  min-width: 100%;
}

.bracket-rounds {
  display: flex;
  gap: var(--tb-round-gap);
  min-width: 100%;
  width: max-content;
  padding: var(--tb-spacing-sm);
  position: relative;
}

.bracket-round {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  min-width: var(--tb-match-width);
  flex-shrink: 0;
  position: relative;
}

/* Round 1 gets even spacing */
.bracket-round[data-round="1"] {
  justify-content: space-evenly;
}

/* Visual connectors between rounds */
.bracket-round:not(:last-child)::after {
  content: '';
  position: absolute;
  right: calc(var(--tb-round-gap) * -1);
  top: 0;
  bottom: 0;
  width: var(--tb-round-gap);
  pointer-events: none;
}

.round-title {
  text-align: center;
  font-weight: bold;
  margin-bottom: 15px;
  color: var(--tb-secondary-color);
  font-size: var(--tb-font-size-base);
  text-transform: uppercase;
  white-space: nowrap;
}

.match {
  border: var(--tb-border-width) solid var(--tb-border-color);
  border-radius: var(--tb-border-radius);
  margin: var(--tb-spacing-sm) 0;
  background: var(--tb-background);
  background-color: none;
  box-shadow: none;
  position: relative;
  min-width: calc(var(--tb-match-width) - 20px);
  width: var(--tb-match-width);
  transition: transform 0.2s, box-shadow 0.2s;
  z-index: 10;
}

.match:focus-within {
  outline: 2px solid var(--tb-accent-color);
  outline-offset: 2px;
}

.match.bye {
  opacity: 1;
}

.match-player {
  padding: 12px 15px;
  border-bottom: 1px solid var(--tb-border-color);
  display: flex;
  min-height: 50px;
  gap: 8px;
  align-items: center;
  transition: background-color 0.2s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: var(--tb-font-size-base);
}

.match-player:first-of-type {
  border-radius: calc(var(--tb-border-radius) - var(--tb-border-width)) calc(var(--tb-border-radius) - var(--tb-border-width)) 0 0;
}

.match-player:last-of-type {
  border-bottom: none;
}

.match-player.winner {
  background-color: var(--tb-winner-bg);
  font-weight: bold;
  color: white;
}

.player-prefix {
  color: inherit;
  font-size: inherit;
  font-weight: inherit;
  flex-shrink: 0;
}

.player-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.match-result {
  padding: 8px 15px;
  background: none;
  text-align: center;
  font-size: 80%;
  color: inherit;
  border-top: 1px solid var(--tb-border-color);
  white-space: nowrap;
}

/* Connector Lines Between Rounds — rendered as SVG paths (see tournament-bracket.js) */
.connector-svg {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  overflow: visible;
}

/* Legacy div-based connector styles (kept for reference, no longer generated) */
.connector-line-set {
  position: absolute;
  pointer-events: none;
  z-index: 1;
}

.connector-line {
  position: absolute;
  background-color: var(--tb-connector-color);
  pointer-events: none;
}

.connector-horizontal {
  height: var(--tb-connector-width);
  transform: translateY(-50%);
}

.connector-vertical {
  width: var(--tb-connector-width);
}

.tournament-footer {
  margin-top: calc(var(--tb-spacing-md) + 10px);
  padding-top: var(--tb-spacing-md);
  border-top: 2px solid var(--tb-border-color);
  width: 100%;
}

.footer-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: var(--tb-font-size-sm);
  color: var(--tb-muted-color);
  flex-wrap: wrap;
  gap: var(--tb-spacing-sm);
}

.loading-message {
  padding: var(--tb-spacing-lg);
  text-align: center;
  color: var(--tb-muted-color);
  font-style: italic;
  width: 100%;
}

.error-message {
  padding: var(--tb-spacing-md);
  background: var(--tb-error-bg);
  border: 1px solid var(--tb-error-border);
  color: var(--tb-error-text);
  border-radius: 4px;
  margin: var(--tb-spacing-md) 0;
  font-size: var(--tb-font-size-base);
  line-height: 1.6;
  width: 100%;
  box-sizing: border-box;
}

.error-message strong {
  display: block;
  margin-bottom: var(--tb-spacing-sm);
  font-size: 16px;
}

.error-message code {
  background: #fff;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 12px;
  word-break: break-all;
}

.error-message ul {
  margin: 10px 0;
  padding-left: 20px;
}

.tournament-bracket-wrapper * {
  box-sizing: border-box;
}

@media (max-width: 1500px) {
  .tournament-bracket-wrapper {
    --tb-match-width: 400px;
  }
  
  .tournament-container {
    padding: var(--tb-spacing-sm);
  }
  
  .match-player {
    padding: var(--tb-spacing-sm) 12px;
    font-size: var(--tb-font-size-base);
  }
  
  .footer-content {
    flex-direction: column;
    gap: var(--tb-spacing-sm);
    text-align: center;
  }
}

.bracket-wrapper::-webkit-scrollbar {
  height: 12px;
}

.bracket-wrapper::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: var(--tb-border-radius);
}

.bracket-wrapper::-webkit-scrollbar-thumb {
  background: #888;
  border-radius: var(--tb-border-radius);
}

/* Accessibility improvements */
.match[role="article"],
.match-player[role="listitem"] {
  outline: none;
}

.match-player:focus {
  outline: 2px solid var(--tb-accent-color);
  outline-offset: -2px;
}

/* Skip to content for screen readers */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border-width: 0;
}