/* ===========================
   Knockout Bracket Styles
   =========================== */

/* Variables */
:root {
  --bracket-bg: #f8fafc;
  --bracket-border: #e2e8f0;
  --bracket-connector: #cbd5e1;
  --match-pending: #f1f5f9;
  --match-ready: #dbeafe;
  --match-played: #ffffff;
  --winner-gold: #fbbf24;
  --winner-bg: #fef3c7;
  --winner-border: #f59e0b;
}

/* Container */
.knockout-bracket-container {
  padding: 1rem;
  min-height: 600px;
  max-height: calc(100vh - 250px);
  overflow-x: auto;
  overflow-y: auto;
  scroll-behavior: smooth;
  display: flex;
  flex-direction: column;
}

/* Section Title */
.bracket-section-title {
  font-size: 18px;
  font-weight: 700;
  color: #1e293b;
  margin-bottom: 1.5rem;
  padding-bottom: 0.75rem;
  border-bottom: 2px solid var(--bracket-border);
  flex-shrink: 0;
}

/* Horizontal Grid */
.bracket-horizontal {
  display: flex;
  gap: 40px;
  min-width: max-content;
  min-height: 600px;
  align-items: stretch;
}

.bracket-section {
  display: flex;
  flex-direction: column;
  flex: 1;
}

/* Row-based Vertical Layout */
.bracket-rounds-vertical {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  width: 100%;
}

.bracket-round-row {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.round-header {
  display: flex;
  justify-content: center;
  padding: 1em 2em;
  background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  border: 2px solid #cbd5e1;
}

.round-title {
  font-size: 18px;
  font-weight: 700;
  color: #1e293b;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.round-title::before {
  content: '?';
  color: #3b82f6;
  font-size: 12px;
}

.round-title::after {
  content: '?';
  color: #3b82f6;
  font-size: 12px;
}

.round-matches-horizontal {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: nowrap;
  padding: 0.75rem 0;
  overflow-x: auto;
}

.match-wrapper-horizontal {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
  width: 220px;
  max-width: 220px;
  min-width: 220px;
}

/* Vertical connector (arrow pointing down) */
.bracket-connector-vertical {
  width: 2px;
  height: 40px;
  background: var(--bracket-connector);
  position: relative;
  margin: 0 auto;
}

.bracket-connector-vertical::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 8px solid var(--bracket-connector);
}

/* Winner connector styling */
.match-wrapper-horizontal:has(.team-winner) .bracket-connector-vertical {
  background: var(--winner-gold);
  width: 3px;
}

.match-wrapper-horizontal:has(.team-winner) .bracket-connector-vertical::after {
  border-top-color: var(--winner-gold);
}

/* Old horizontal layout (keep for backward compatibility) */
.bracket-rounds {
  display: flex;
  gap: 40px;
  flex: 1;
  align-items: stretch;
}

.bracket-round {
  display: flex;
  flex-direction: column;
  min-width: 220px;
  padding: 1rem 0;
  flex: 1;
}

.round-matches {
  display: flex;
  flex-direction: column;
  flex: 1;
  position: relative;
  justify-content: space-around;
  padding: 1rem 0;
}

/* First round - tight spacing */
.bracket-round:first-child .round-matches {
  gap: 1rem;
}

/* Second round - medium spacing */
.bracket-round:nth-child(2) .round-matches {
  gap: 2.5rem;
}

/* Third round - large spacing */
.bracket-round:nth-child(3) .round-matches {
  gap: 5rem;
}

/* Fourth round (final) - centered */
.bracket-round:nth-child(4) .round-matches {
  justify-content: center;
}

/* Match Wrapper with Connector (old horizontal layout) */
.match-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.bracket-connector {
  position: absolute;
  left: 100%;
  top: 50%;
  width: 60px;
  height: 2px;
  background: var(--bracket-connector);
  transform: translateY(-50%);
  z-index: 1;
}

.bracket-connector::after {
  content: '';
  position: absolute;
  right: 0;
  top: 50%;
  width: 0;
  height: 0;
  border-left: 8px solid var(--bracket-connector);
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  transform: translateY(-50%);
  transition: border-left-color 0.3s ease;
}

/* Winner connector styling */
.match-wrapper:has(.team-winner) .bracket-connector {
  background: var(--winner-gold);
  height: 3px;
}

.match-wrapper:has(.team-winner) .bracket-connector::after {
  border-left-color: var(--winner-gold);
}

/* Match Card */
.bracket-match {
  background: white;
  border: 2px solid var(--bracket-border);
  border-radius: 6px;
  padding: 0.4rem;
  width: 100%;
  max-width: 100%;
  min-width: 180px;
  flex-shrink: 0;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  animation: matchFadeIn 0.4s ease-out backwards;
}

@keyframes matchFadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Stagger animation for multiple matches */
.match-wrapper:nth-child(1) .bracket-match { animation-delay: 0.05s; }
.match-wrapper:nth-child(2) .bracket-match { animation-delay: 0.1s; }
.match-wrapper:nth-child(3) .bracket-match { animation-delay: 0.15s; }
.match-wrapper:nth-child(4) .bracket-match { animation-delay: 0.2s; }
.match-wrapper:nth-child(5) .bracket-match { animation-delay: 0.25s; }
.match-wrapper:nth-child(6) .bracket-match { animation-delay: 0.3s; }
.match-wrapper:nth-child(7) .bracket-match { animation-delay: 0.35s; }
.match-wrapper:nth-child(8) .bracket-match { animation-delay: 0.4s; }

/* Stagger animation for horizontal wrappers */
.match-wrapper-horizontal:nth-child(1) .bracket-match { animation-delay: 0.05s; }
.match-wrapper-horizontal:nth-child(2) .bracket-match { animation-delay: 0.1s; }
.match-wrapper-horizontal:nth-child(3) .bracket-match { animation-delay: 0.15s; }
.match-wrapper-horizontal:nth-child(4) .bracket-match { animation-delay: 0.2s; }
.match-wrapper-horizontal:nth-child(5) .bracket-match { animation-delay: 0.25s; }
.match-wrapper-horizontal:nth-child(6) .bracket-match { animation-delay: 0.3s; }
.match-wrapper-horizontal:nth-child(7) .bracket-match { animation-delay: 0.35s; }
.match-wrapper-horizontal:nth-child(8) .bracket-match { animation-delay: 0.4s; }

.bracket-match:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  border-color: #3b82f6;
}

.bracket-match.match-ready {
  border-color: #3b82f6;
  background: linear-gradient(135deg, var(--match-ready) 0%, white 100%);
}

.bracket-match.match-played {
  opacity: 0.9;
}

.bracket-match-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.25rem;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--bracket-border);
}

.bracket-match-header .badge {
  font-size: 8px;
  padding: 0.15rem 0.35rem;
}

.bracket-match-header .small {
  font-size: 8px;
}

.bracket-match-teams {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

/* Team */
.bracket-team {
  display: flex;
  align-items: center;
  padding: 0.3rem 0.4rem;
  border-radius: 4px;
  transition: background 0.2s;
  gap: 0.3rem;
  background: #f8fafc;
  min-height: 28px;
}

.bracket-team:hover {
  background: #f1f5f9;
}

.bracket-team.team-winner {
  background: var(--winner-bg);
  border: 2px solid var(--winner-gold);
}

.bracket-team.team-clickable {
  cursor: pointer;
}

.bracket-team.team-empty {
  opacity: 0.5;
}

.team-info {
  flex: 1;
  min-width: 0;
}

.team-name {
  font-size: 11px;
  font-weight: 600;
  color: #1e293b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.1;
}

.team-winner .team-name {
  color: #92400e;
}

.team-score {
  font-size: 16px;
  font-weight: 700;
  color: #64748b;
  margin-left: auto;
  line-height: 1;
}

.team-winner .team-score {
  color: var(--winner-gold);
}

.winner-icon {
  color: var(--winner-gold);
  font-size: 14px;
  animation: trophy-pulse 2s infinite;
}

@keyframes trophy-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

/* VS Divider */
.vs-divider {
  text-align: center;
  padding: 0.125rem 0;
  font-size: 10px;
  font-weight: 600;
  color: #94a3b8;
  line-height: 1;
}

/* Players */
.team-players {
  display: flex;
  gap: 2px;
  margin-top: 2px;
}

.player-avatar {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1px solid white;
  object-fit: cover;
}

/* Actions */
.bracket-match-actions {
  margin-top: 0.35rem;
  padding-top: 0.35rem;
  border-top: 1px solid var(--bracket-border);
}

.bracket-match-actions .btn-sm {
  font-size: 10px;
  padding: 0.3rem 0.5rem;
}

/* Grand Finals */
.grand-finals {
  margin-top: 3rem;
  padding: 2rem;
  background: linear-gradient(135deg, #fef3c7 0%, #fbbf24 100%);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(251, 191, 36, 0.4);
}

.grand-finals .bracket-section-title {
  color: #92400e;
  border-bottom: 3px solid #f59e0b;
  text-align: center;
}

.grand-finals-match {
  display: flex;
  justify-content: center;
  padding: 2rem 0;
}

.grand-finals-match .bracket-match {
  width: 350px;
  border: 4px solid #f59e0b;
  box-shadow: 0 12px 32px rgba(251, 191, 36, 0.5);
  transform: scale(1.05);
}

/* Vertical/List View */
.bracket-vertical {
  max-width: 100%;
}

.bracket-vertical .bracket-match {
  width: 100%;
  max-width: 350px;
}

/* Responsive */
@media (max-width: 1200px) {
  .bracket-horizontal {
    gap: 40px;
  }
  
  .bracket-rounds {
    gap: 40px;
  }
  
  .bracket-connector {
    width: 40px;
  }
  
  .round-matches-horizontal {
    gap: 1.5rem;
  }
}

@media (max-width: 768px) {
  .knockout-bracket-container {
    padding: 1rem;
  }
  
  .bracket-horizontal {
    flex-direction: column;
    gap: 2rem;
  }
  
  .bracket-rounds {
    flex-direction: column;
    gap: 1.5rem;
  }
  
  .bracket-connector {
    display: none;
  }
  
  .bracket-match {
    width: 100%;
    max-width: 100%;
    min-width: unset;
  }
  
  .match-wrapper-horizontal {
    width: 100%;
    max-width: 100%;
    min-width: unset;
  }
  
  .round-matches-horizontal {
    flex-wrap: wrap;
  }
  
  .round-header {
    padding: 0.75rem 1rem;
  }
  
  .round-title {
    font-size: 14px;
  }
}
