/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:         #080d18;
  --surface:    #0f1625;
  --surface2:   #162035;
  --surface3:   #1d2a45;
  --border:     #243352;
  --accent:        #8B4DB8;
  --accent-strong: #6A318D;
  --accent-dim:    #400F9C;
  --gold:       #f5c518;
  --c-orange:   #FA4214;
  --c-blue:     #3169CA;
  --c-yellow:   #E2BD17;
  --c-pink:     #F721A2;
  --c-green:    #46925C;
  --text:       #dde4f0;
  --text-muted: #7a90b8;
  --text-dim:   #4a5a7a;
  --radius:     10px;
  --radius-sm:  6px;
  --shadow:     0 4px 20px rgba(0,0,0,0.4);
}

html { scroll-behavior: smooth; }
body {
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

/* ===== HEADER ===== */
header {
  background: linear-gradient(135deg, #2C1151 0%, #6A318D 50%, #2C1151 100%);
  border-bottom: 2px solid var(--accent);
  padding: 24px 20px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 20px;
  justify-content: space-between;
}
.logo { display: flex; align-items: center; gap: 14px; }
.logo-ball { font-size: 2.2rem; }
.logo h1 {
  font-family: 'Poppins', sans-serif;
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: #fff;
  line-height: 1;
}
.logo-year {
  font-size: 0.85rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: 2px;
  text-transform: uppercase;
}
.header-brand { text-align: right; }
.tagline { color: rgba(255,255,255,0.75); font-size: 0.9rem; }
.brand-tag {
  margin-top: 4px;
  font-family: 'Poppins', sans-serif;
  font-size: 0.78rem;
  font-weight: 700;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}
.usa-badge {
  background: var(--c-orange);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 1px;
  padding: 2px 6px;
  border-radius: 999px;
}

/* ===== MAIN ===== */
main { max-width: 1400px; margin: 0 auto; padding: 24px 20px 60px; }

/* ===== STEP INDICATOR ===== */
.steps {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  margin-bottom: 36px;
}
.step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  opacity: 0.4;
  transition: opacity 0.3s;
}
.step.active { opacity: 1; }
.step.done { opacity: 0.7; }
.step-num {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--surface3);
  border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.9rem;
  transition: all 0.3s;
}
.step.active .step-num {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  color: #fff;
}
.step.done .step-num {
  background: var(--accent-dim);
  border-color: var(--accent-dim);
  color: #fff;
}
.step-label { font-size: 0.75rem; color: var(--text-muted); font-weight: 600; white-space: nowrap; }
.step-line { flex: 1; min-width: 40px; max-width: 80px; height: 2px; background: var(--border); margin: 0 4px; margin-top: -12px; }

/* ===== SECTION ===== */
section { display: block; }
section.hidden { display: none; }

.section-header { text-align: center; margin-bottom: 28px; }
.section-header h2 { font-family: 'Poppins', sans-serif; font-size: 1.6rem; font-weight: 800; margin-bottom: 8px; }
.section-header p { color: var(--text-muted); font-size: 0.95rem; }
.section-footer {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
  margin-top: 28px;
  flex-wrap: wrap;
}
#groups-progress { color: var(--text-muted); font-size: 0.9rem; margin-right: auto; }

/* ===== BUTTONS ===== */
.btn-primary, .btn-secondary, .btn-ghost {
  padding: 11px 24px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
  white-space: nowrap;
}
.btn-primary {
  background: var(--accent-strong);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--accent); transform: translateY(-1px); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-secondary {
  background: transparent;
  color: var(--text-muted);
  border: 1.5px solid var(--border);
}
.btn-secondary:hover { border-color: var(--text-muted); color: var(--text); }
.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border: 1.5px solid var(--surface3);
  font-size: 0.8rem;
}
.btn-ghost:hover { color: var(--text-muted); border-color: var(--border); }

/* ===== GROUPS GRID ===== */
#groups-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.group-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-top: 3px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.2s;
}
.group-card.complete { border-color: var(--accent-dim); }

/* Nossa Rádio multi-color accent, cycling across the 12 group cards */
#groups-container .group-card:nth-child(5n+1) { border-top-color: var(--c-orange); }
#groups-container .group-card:nth-child(5n+2) { border-top-color: var(--c-blue); }
#groups-container .group-card:nth-child(5n+3) { border-top-color: var(--c-yellow); }
#groups-container .group-card:nth-child(5n+4) { border-top-color: var(--c-pink); }
#groups-container .group-card:nth-child(5n+5) { border-top-color: var(--c-green); }

.group-header {
  background: var(--surface2);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.group-name { font-weight: 800; font-size: 0.85rem; letter-spacing: 0.5px; color: var(--text-muted); text-transform: uppercase; }
.group-status {
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  text-align: right;
  transition: color 0.3s;
}
.group-card.complete .group-status { color: var(--accent); }

.group-teams { padding: 8px; list-style: none; }

.team-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: var(--radius-sm);
  margin-bottom: 4px;
  cursor: pointer;
  user-select: none;
  background: var(--surface2);
  border: 1.5px solid transparent;
  transition: all 0.15s;
  position: relative;
}
.team-row:last-child { margin-bottom: 0; }
.team-row:hover { border-color: var(--border); background: var(--surface3); }
.team-row.ranked { background: var(--surface3); border-color: var(--border); }
.team-row.auto-fourth { cursor: default; opacity: 0.55; }
.team-row.auto-fourth:hover { border-color: transparent; background: var(--surface2); }

.team-pos {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-weight: 800;
  flex-shrink: 0;
  background: var(--surface3);
  color: var(--text-dim);
  border: 1.5px dashed var(--border);
}
.team-pos.pos-1 { background: var(--accent-strong); color: #fff; border-style: solid; border-color: var(--accent-strong); }
.team-pos.pos-2 { background: var(--accent-dim); color: #fff; border-style: solid; border-color: var(--accent-dim); }
.team-pos.pos-3 { background: var(--c-yellow); color: #2b1f00; border-style: solid; border-color: var(--c-yellow); }
.team-pos.pos-4 { background: var(--surface3); color: var(--text-dim); border-style: solid; border-color: var(--border); }

.team-flag { font-size: 1.3rem; line-height: 1; flex-shrink: 0; }
.team-name { font-size: 0.85rem; font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ===== THIRDS SECTION ===== */
.thirds-counter-wrap { text-align: center; margin-bottom: 24px; }
.thirds-counter {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  background: var(--surface2);
  border: 2px solid var(--border);
  border-radius: 999px;
  padding: 10px 24px;
}
.thirds-counter span:first-child { font-size: 2rem; font-weight: 800; color: var(--accent); }
.thirds-counter-label { font-size: 0.9rem; color: var(--text-muted); }

#thirds-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
}

.third-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: all 0.2s;
  position: relative;
}
.third-card:hover { border-color: var(--text-muted); background: var(--surface2); }
.third-card.selected {
  background: rgba(139,77,184,0.14);
  border-color: var(--accent);
}
.third-card.disabled-card {
  opacity: 0.4;
  cursor: not-allowed;
}
.third-flag { font-size: 1.6rem; }
.third-info { flex: 1; min-width: 0; }
.third-group { font-size: 0.65rem; font-weight: 700; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; }
.third-name { font-size: 0.9rem; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.third-check {
  width: 20px; height: 20px;
  border-radius: 50%;
  border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.65rem;
  color: transparent;
  transition: all 0.2s;
  flex-shrink: 0;
}
.third-card.selected .third-check {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  color: #fff;
}

/* ===== BRACKET ===== */
#bracket-outer { overflow-x: auto; padding-bottom: 16px; }
#bracket-scroll { min-width: 1260px; }

.bracket-legend {
  display: flex;
  gap: 20px;
  justify-content: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.legend-item { display: flex; align-items: center; gap: 6px; font-size: 0.8rem; color: var(--text-muted); }
.dot { width: 10px; height: 10px; border-radius: 50%; }
.dot-win   { background: var(--accent); }
.dot-elim  { background: var(--text-dim); }
.dot-pending { background: var(--surface3); border: 1.5px solid var(--border); }

#bracket-container {
  display: flex;
  align-items: stretch;
  gap: 0;
}

.bracket-col {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

/* Fixed widths per round */
.col-r32  { flex: 0 0 148px; }
.col-r16  { flex: 0 0 148px; }
.col-qf   { flex: 0 0 148px; }
.col-sf   { flex: 0 0 148px; }
.col-final{ flex: 0 0 160px; }

.round-col-header {
  text-align: center;
  padding: 6px 4px 10px;
  font-size: 0.62rem;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
  white-space: nowrap;
  flex-shrink: 0;
}

/* Each slot distributes column height equally */
.match-slot {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3px 4px;
  position: relative;
}

/* ---- Bracket connector lines ---- */
/* Left-side columns (R32, R16, QF): lines from slot center going right */
/* Even-indexed slots (1st, 3rd… of each pair) connect downward */
/* Odd-indexed slots (2nd, 4th…) connect upward                       */
/* Note: round-col-header is child 1, so first match-slot is child 2 (even) */

.col-r32.col-left .match-slot::after,
.col-r16.col-left .match-slot::after,
.col-qf.col-left  .match-slot::after {
  content: '';
  position: absolute;
  right: 0;
  width: 6px;
  border-right: 1px solid var(--border);
}
/* even child = first of pair → line goes DOWN from center to bottom */
.col-r32.col-left .match-slot:nth-child(even)::after,
.col-r16.col-left .match-slot:nth-child(even)::after,
.col-qf.col-left  .match-slot:nth-child(even)::after {
  top: 50%; height: 50%;
  border-bottom: 1px solid var(--border);
}
/* odd child = second of pair → line goes UP from center to top */
.col-r32.col-left .match-slot:nth-child(odd)::after,
.col-r16.col-left .match-slot:nth-child(odd)::after,
.col-qf.col-left  .match-slot:nth-child(odd)::after {
  bottom: 50%; height: 50%;
  border-top: 1px solid var(--border);
}

/* Right-side columns (R32, R16, QF): mirror, lines go LEFT */
.col-r32.col-right .match-slot::after,
.col-r16.col-right .match-slot::after,
.col-qf.col-right  .match-slot::after {
  content: '';
  position: absolute;
  left: 0;
  width: 6px;
  border-left: 1px solid var(--border);
}
.col-r32.col-right .match-slot:nth-child(even)::after,
.col-r16.col-right .match-slot:nth-child(even)::after,
.col-qf.col-right  .match-slot:nth-child(even)::after {
  top: 50%; height: 50%;
  border-bottom: 1px solid var(--border);
}
.col-r32.col-right .match-slot:nth-child(odd)::after,
.col-r16.col-right .match-slot:nth-child(odd)::after,
.col-qf.col-right  .match-slot:nth-child(odd)::after {
  bottom: 50%; height: 50%;
  border-top: 1px solid var(--border);
}

/* Match card */
.match-card {
  background: var(--surface2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  width: 100%;
  max-width: 148px;
}

.col-final .match-card { max-width: 160px; border-color: var(--gold); }

.match-team {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 8px;
  cursor: pointer;
  transition: background 0.15s;
  border-bottom: 1px solid var(--surface);
}
.match-team:last-child { border-bottom: none; }
.match-team:hover:not(.no-team) { background: var(--surface3); }
.match-team.winner { background: rgba(139,77,184,0.18); }
.match-team.winner .match-team-name { color: var(--accent); font-weight: 700; }
.match-team.eliminated { opacity: 0.38; }
.match-team.no-team { cursor: default; }

.match-flag { font-size: 1rem; flex-shrink: 0; width: 22px; text-align: center; }
.match-team-name {
  font-size: 0.7rem; font-weight: 600; flex: 1;
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.match-team-name.tbd { color: var(--text-dim); font-style: italic; }

/* ===== CHAMPION BANNER ===== */
#champion-banner {
  margin-bottom: 24px;
  display: flex;
  justify-content: center;
}
#champion-banner.hidden { display: none; }

.champion-inner {
  display: inline-flex;
  align-items: center;
  gap: 20px;
  background: linear-gradient(135deg, #1a1a00, #3a3000);
  border: 2px solid var(--gold);
  border-radius: var(--radius);
  padding: 24px 40px;
  animation: glow 2s ease-in-out infinite alternate;
}
@keyframes glow {
  from { box-shadow: 0 0 20px rgba(245,197,24,0.3); }
  to   { box-shadow: 0 0 40px rgba(245,197,24,0.6); }
}
.champion-trophy { font-size: 3rem; }
.champion-label { display: block; font-size: 0.8rem; color: var(--gold); font-weight: 700; text-transform: uppercase; letter-spacing: 2px; }
.champion-team { display: block; font-family: 'Poppins', sans-serif; font-size: 2rem; font-weight: 900; color: #fff; }

/* ===== FOOTER ===== */
footer {
  text-align: center;
  padding: 24px;
  color: var(--text-dim);
  font-size: 0.8rem;
  border-top: 1px solid var(--surface2);
}
footer a { color: var(--accent); text-decoration: none; }

/* ===== UTILITIES ===== */
.hidden { display: none !important; }

/* ===== RESPONSIVE ===== */
@media (max-width: 600px) {
  .header-inner { flex-direction: column; gap: 8px; text-align: center; }
  .logo h1 { font-size: 1.4rem; }
  #groups-container { grid-template-columns: 1fr 1fr; }
  #thirds-container { grid-template-columns: 1fr 1fr; }
  .section-footer { justify-content: center; }
  #groups-progress { width: 100%; text-align: center; margin-right: 0; }
}
@media (max-width: 400px) {
  #groups-container { grid-template-columns: 1fr; }
  #thirds-container { grid-template-columns: 1fr; }
}
