:root {
  color-scheme: dark;
  --bg: #10110f;
  --panel: #171915;
  --panel-strong: #20231d;
  --line: rgba(179, 177, 160, 0.27);
  --text: #f7f1df;
  --muted: #b9b09a;
  --green: #58b883;
  --gold: #e3b151;
  --shadow: rgba(0, 0, 0, 0.42);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 50% 48%, rgba(226, 171, 68, 0.2), transparent 13rem),
    radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.035), transparent 31rem),
    linear-gradient(120deg, rgba(31, 92, 64, 0.12), transparent 34%),
    var(--bg);
  color: var(--text);
}

button {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 370px;
  height: 100vh;
  overflow: hidden;
}

.bracket-stage {
  position: relative;
  min-width: 0;
  height: 100vh;
  overflow: hidden;
  padding: 28px clamp(18px, 4vw, 44px) 34px;
}

.bracket-stage::before {
  position: absolute;
  inset: 0;
  z-index: -1;
  content: "";
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.026) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.026) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(circle at center, black, transparent 82%);
}

.top-bar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin: 0 auto 18px;
  width: min(100%, 1180px);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--gold);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 4.35rem);
  line-height: 0.94;
}

.status-panel {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid rgba(247, 241, 223, 0.16);
  border-radius: 8px;
  background: rgba(23, 25, 21, 0.72);
  color: var(--muted);
  font-size: 0.88rem;
  white-space: nowrap;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--green);
  box-shadow: 0 0 14px var(--green);
}

.live-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.live-status::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--muted);
}

.live-status[data-state="live"] {
  color: var(--green);
}

.live-status[data-state="live"]::before {
  background: var(--green);
  box-shadow: 0 0 10px var(--green);
  animation: live-pulse 2.4s ease-in-out infinite;
}

.live-status[data-match="on"] {
  color: #ff9a9d;
}

.live-status[data-match="on"]::before {
  background: #ff5a5f;
  box-shadow: 0 0 10px #ff5a5f;
  animation: live-pulse 1.6s ease-in-out infinite;
}

.live-status[data-state="connecting"] {
  color: var(--gold);
}

.live-status[data-state="connecting"]::before {
  background: var(--gold);
}

@keyframes live-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.round-tag {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 7px;
  border-radius: 999px;
  background: rgba(227, 177, 81, 0.16);
  color: var(--gold);
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.bracket-wrap {
  position: relative;
  /* Fit the largest square that still leaves room for the top bar and the
     side panel. The numbers subtract: 180px (top bar + vertical padding),
     and the panel column (370px) + horizontal padding (~88px). */
  width: min(calc(100vh - 180px), calc(100vw - 470px), 1040px);
  aspect-ratio: 1;
  margin: 0 auto;
}

.bracket-lines,
.team-layer,
.round-labels {
  position: absolute;
  inset: 0;
}

.bracket-lines {
  overflow: visible;
}

.line-path {
  fill: none;
  stroke: var(--line);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
  transition: stroke 180ms ease, stroke-width 180ms ease, opacity 180ms ease;
}

.line-path.is-advanced {
  stroke: #ffffff;
  stroke-width: 4;
  filter: drop-shadow(0 0 4px rgba(255, 255, 255, 0.62));
}

.round-label {
  position: absolute;
  color: rgba(247, 241, 223, 0.58);
  font-size: 0.66rem;
  font-weight: 900;
  text-transform: uppercase;
  transform: translate(-50%, -50%);
  white-space: nowrap;
}

.team-node {
  position: absolute;
  z-index: 4;
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  padding: 0;
  border: 2px solid rgba(247, 241, 223, 0.72);
  border-radius: 50%;
  background: var(--team-color, #29332b);
  filter: drop-shadow(0 11px 14px var(--shadow));
  color: white;
  cursor: pointer;
  overflow: hidden;
  transform: translate(-50%, -50%);
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease,
    transform 160ms ease;
}

.team-node:hover,
.team-node:focus-visible {
  border-color: var(--gold);
  outline: none;
  transform: translate(-50%, -50%) scale(1.08);
}

.team-node.is-eliminated {
  filter: grayscale(0.85) brightness(0.55);
  border-color: rgba(247, 241, 223, 0.25);
}

.team-node.is-eliminated::after {
  position: absolute;
  inset: 50% 6%;
  height: 2px;
  background: rgba(247, 241, 223, 0.8);
  content: "";
  transform: rotate(-32deg) translateY(-1px);
  pointer-events: none;
}

.team-node.is-eliminated:hover,
.team-node.is-eliminated:focus-visible {
  filter: grayscale(0.6) brightness(0.75);
}

.team-node.is-advanced {
  border-color: #ffffff;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.28), 0 11px 14px var(--shadow);
}

.team-node.is-live {
  border-color: #ff5a5f;
  box-shadow: 0 0 0 3px rgba(255, 90, 95, 0.35), 0 11px 14px var(--shadow);
  animation: node-live-pulse 1.6s ease-in-out infinite;
}

@keyframes node-live-pulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(255, 90, 95, 0.35), 0 11px 14px var(--shadow); }
  50%      { box-shadow: 0 0 0 6px rgba(255, 90, 95, 0.08), 0 11px 14px var(--shadow); }
}

.team-node.is-selected {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(227, 177, 81, 0.32), 0 11px 14px var(--shadow);
}

.advance-node {
  position: absolute;
  z-index: 3;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 2px solid rgba(247, 241, 223, 0.72);
  border-radius: 50%;
  background: var(--team-color, #2a2a2a);
  filter: drop-shadow(0 6px 8px var(--shadow));
  color: white;
  cursor: pointer;
  overflow: hidden;
  transform: translate(-50%, -50%);
  transition: border-color 160ms ease, transform 160ms ease;
}

.advance-node:hover,
.advance-node:focus-visible {
  border-color: var(--gold);
  outline: none;
  transform: translate(-50%, -50%) scale(1.12);
}

.advance-node .flag {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  font-size: 1.7rem;
  line-height: 1;
  transform: scale(1.35);
}

.advance-node-r1 {
  width: 30px;
  height: 30px;
}

.advance-node-r2 {
  width: 28px;
  height: 28px;
  z-index: 4;
}

.advance-node-r3 {
  width: 30px;
  height: 30px;
  z-index: 5;
  border-color: var(--gold);
}

.advance-node-r1 .flag,
.advance-node-r2 .flag {
  font-size: 1.55rem;
}

.advance-node-r3 .flag {
  font-size: 1.65rem;
}

.flag {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  border: 0;
  border-radius: 50%;
  background: transparent;
  line-height: 1;
  transition: transform 160ms ease;
}

.flag-img {
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  font-size: 0;
  transform: scale(1.04);
}

.team-node .flag {
  font-size: 2.45rem;
}

.team-node:hover .flag,
.team-node:focus-visible .flag {
  transform: scale(1.18);
}

.team-panel {
  display: flex;
  height: 100vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  border-left: 1px solid rgba(247, 241, 223, 0.12);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.05), transparent 19rem),
    var(--panel);
}

.empty-state,
.team-card {
  width: 100%;
  padding: 28px;
}

.empty-state {
  align-self: center;
  color: var(--muted);
}

.empty-ball {
  display: block;
  margin-bottom: 16px;
  font-size: 2.5rem;
}

.empty-state h2,
.team-card h2 {
  margin: 0;
  color: var(--text);
  font-size: 1.75rem;
}

.empty-state p {
  max-width: 28rem;
  line-height: 1.55;
}

.team-card {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.team-hero {
  display: grid;
  grid-template-columns: 74px 1fr;
  gap: 16px;
  align-items: center;
}

.team-badge {
  display: grid;
  place-items: center;
  width: 74px;
  height: 74px;
  overflow: hidden;
  border-radius: 50%;
  background: var(--team-color, #27352a);
  box-shadow: 0 18px 28px var(--shadow);
}

.team-badge .flag {
  font-size: 4.4rem;
  line-height: 1;
}

.team-badge .flag.flag-img {
  font-size: 0;
  transform: scale(1.02);
}

.team-meta {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.92rem;
}

.status-badge {
  display: inline-block;
  margin-top: 10px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.status-badge.is-out {
  background: rgba(215, 75, 75, 0.18);
  color: #f0a4a4;
}

.status-badge.is-in {
  background: rgba(88, 184, 131, 0.18);
  color: var(--green);
}

.status-badge.is-active {
  background: rgba(227, 177, 81, 0.18);
  color: var(--gold);
}

.path-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.path-row {
  display: grid;
  grid-template-columns: 36px 42px 1fr;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid rgba(247, 241, 223, 0.1);
  border-radius: 8px;
  background: var(--panel-strong);
}

.path-chip {
  display: grid;
  place-items: center;
  width: 32px;
  height: 26px;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.04em;
}

.path-chip.is-win {
  background: rgba(88, 184, 131, 0.22);
  color: var(--green);
}

.path-chip.is-loss {
  background: rgba(215, 75, 75, 0.22);
  color: #f0a4a4;
}

.path-chip.is-draw {
  background: rgba(227, 177, 81, 0.22);
  color: var(--gold);
}

.path-chip.is-upcoming {
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
}

.path-chip.is-live {
  background: rgba(255, 90, 95, 0.22);
  color: #ff9a9d;
  animation: chip-live-pulse 1.6s ease-in-out infinite;
}

@keyframes chip-live-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.55; }
}

.path-row.is-live-row {
  border-color: rgba(255, 90, 95, 0.35);
  background: linear-gradient(180deg, rgba(255, 90, 95, 0.06), var(--panel-strong));
}

.path-round {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.path-score {
  grid-column: 3;
  color: var(--text);
  font-size: 0.95rem;
}

.path-score strong {
  margin-right: 8px;
  font-weight: 800;
}

.path-meta {
  grid-column: 2 / 4;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.4;
}

.path-watch {
  grid-column: 2 / 4;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(88, 184, 131, 0.14);
  color: var(--green);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  justify-self: start;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  padding: 7px 10px;
  border: 1px solid rgba(247, 241, 223, 0.14);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.section-title {
  margin: 0 0 10px;
  color: var(--gold);
  font-size: 0.76rem;
  font-weight: 900;
  text-transform: uppercase;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.stat {
  min-height: 78px;
  padding: 13px;
  border: 1px solid rgba(247, 241, 223, 0.1);
  border-radius: 8px;
  background: var(--panel-strong);
}

.stat strong {
  display: block;
  margin-bottom: 6px;
  font-size: 1.35rem;
}

.stat span,
.match-card span,
.note {
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.45;
}

.match-card {
  display: grid;
  gap: 10px;
  padding: 15px;
  border: 1px solid rgba(247, 241, 223, 0.12);
  border-radius: 8px;
  background: #11130f;
}

.match-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.opponent {
  color: var(--text);
  font-size: 1.1rem;
  font-weight: 800;
}

.group-table {
  width: 100%;
  border-collapse: collapse;
  color: var(--text);
  font-size: 0.86rem;
}

.group-table th {
  padding: 6px 4px;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-align: center;
  text-transform: uppercase;
  border-bottom: 1px solid rgba(247, 241, 223, 0.14);
}

.group-table th:nth-child(2) {
  text-align: left;
}

.group-table td {
  padding: 8px 4px;
  text-align: center;
  border-bottom: 1px solid rgba(247, 241, 223, 0.06);
}

.group-table tr:last-child td {
  border-bottom: 0;
}

.group-table td.pos {
  color: var(--muted);
  font-weight: 800;
  width: 22px;
}

.group-table td.team {
  padding-left: 6px;
  text-align: left;
  font-weight: 700;
}

.group-table td.pts {
  color: var(--gold);
  font-weight: 800;
}

.group-table tr.is-self {
  background: rgba(227, 177, 81, 0.08);
}

.group-table tr.is-self td.team {
  color: var(--gold);
}

.source-note {
  margin-top: auto;
  padding-top: 18px;
  border-top: 1px solid rgba(247, 241, 223, 0.1);
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.45;
}

@media (max-width: 1160px) {
  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
    overflow: visible;
  }

  .bracket-stage {
    height: auto;
    overflow: visible;
  }

  .bracket-wrap {
    width: min(calc(100vw - 40px), 720px);
  }

  .team-panel {
    height: auto;
    overflow: visible;
    overscroll-behavior: auto;
    border-top: 1px solid rgba(247, 241, 223, 0.12);
    border-left: 0;
  }
}

@media (max-width: 680px) {
  .bracket-stage {
    padding: 20px 14px 22px;
  }

  .top-bar {
    align-items: stretch;
    flex-direction: column;
  }

  .status-panel {
    justify-content: center;
    width: 100%;
    white-space: normal;
  }

  .bracket-wrap {
    min-width: 760px;
  }

  .empty-state,
  .team-card {
    padding: 22px 18px 28px;
  }
}
