:root {
  --bg: #0f1720;
  --panel: #17222e;
  --panel-alt: #1e2c3a;
  --border: #2c3d4f;
  --text: #e8eef4;
  --text-dim: #93a3b3;
  --accent: #2ecc71;
  --accent-dim: #1c8f52;
  --badge-bg: #e63946;
  --radius: 10px;
  --gap: 16px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 12px var(--gap);
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
}

.app-header h1 {
  margin: 0;
  font-size: 1.25rem;
}

.tabs {
  display: flex;
  gap: 8px;
}

.tab-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.15s ease;
}

.tab-btn:hover { color: var(--text); }

.tab-btn.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #06210f;
  font-weight: 600;
}

main {
  padding: var(--gap);
  max-width: 1400px;
  margin: 0 auto;
}

.tab-panel { display: none; }
.tab-panel.is-active { display: block; }

/* ---------- Groups ---------- */

.groups-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: var(--gap);
}

.group-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

.group-card h2 {
  margin: 0 0 10px;
  font-size: 1rem;
  color: var(--accent);
}

.standings {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
  margin-bottom: 12px;
}

.standings th, .standings td {
  padding: 4px 6px;
  text-align: center;
  border-bottom: 1px solid var(--border);
}

.standings th:first-child, .standings td.team-cell {
  text-align: left;
}

.standings td.team-cell {
  display: flex;
  align-items: center;
  gap: 6px;
}

.standings tbody tr:nth-child(-n+2) {
  background: rgba(46, 204, 113, 0.08);
}

.flag {
  width: 20px;
  height: 14px;
  object-fit: cover;
  border-radius: 2px;
  flex-shrink: 0;
  background: var(--panel-alt);
}

.flag-lg { width: 32px; height: 22px; }

.matches-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.matches-toggle {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.75rem;
  padding: 4px 0;
}

/* ---------- Match card ---------- */

.match-card {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.85rem;
}

.match-card.is-pending {
  opacity: 0.6;
}

.match-date {
  font-size: 0.68rem;
  color: var(--text-dim);
  margin-bottom: 6px;
}

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

.match-team {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.match-team.away {
  justify-content: flex-end;
  text-align: right;
}

.match-team .team-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.match-score {
  font-weight: 700;
  font-size: 1.05rem;
  padding: 0 10px;
  white-space: nowrap;
}

.match-extra {
  font-size: 0.68rem;
  color: var(--text-dim);
  text-align: center;
  margin-top: 2px;
}

.scorers-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 8px;
}

.scorers-col {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex: 1;
}

.scorers-col.away { justify-content: flex-end; }

.scorer-chip {
  position: relative;
  width: 34px;
  height: 34px;
  flex-shrink: 0;
}

.scorer-chip img,
.scorer-chip .avatar-fallback {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--border);
  display: block;
}

.avatar-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-weight: 700;
  color: #fff;
}

.goal-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--badge-bg);
  color: #fff;
  font-size: 0.6rem;
  font-weight: 700;
  min-width: 15px;
  height: 15px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--bg);
  padding: 0 2px;
}

.scorer-chip .scorer-name {
  position: absolute;
  bottom: -16px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.55rem;
  color: var(--text-dim);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.1s;
  background: var(--panel);
  padding: 1px 4px;
  border-radius: 4px;
  z-index: 5;
}

.scorer-chip:hover .scorer-name { opacity: 1; }

/* ---------- Bracket ---------- */

.bracket {
  display: flex;
  gap: 36px;
  overflow-x: auto;
  padding-bottom: 24px;
}

.bracket-round {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  min-width: 230px;
  flex-shrink: 0;
}

.bracket-round h3 {
  text-align: center;
  color: var(--accent);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0 0 12px;
}

.bracket-match-wrap {
  position: relative;
  padding: 6px 0;
  flex: 1;
  display: flex;
  align-items: center;
}

.bracket-round:not(:first-child) .bracket-match-wrap::before {
  content: "";
  position: absolute;
  left: -18px;
  top: 50%;
  width: 18px;
  height: 0;
  border-top: 2px solid var(--border);
}

.bracket-round:not(:last-child) .bracket-match-wrap::after {
  content: "";
  position: absolute;
  right: -18px;
  top: 50%;
  width: 18px;
  height: 0;
  border-top: 2px solid var(--border);
}

.bracket-match-wrap .match-card {
  width: 100%;
}

.bracket .match-card .scorers-row { display: none; }
.bracket .match-card.is-expanded .scorers-row { display: flex; }

.bracket .match-card {
  cursor: pointer;
}

.app-footer {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.72rem;
  padding: 20px;
}

@media (max-width: 640px) {
  .app-header { flex-direction: column; align-items: flex-start; gap: 10px; }
  .groups-grid { grid-template-columns: 1fr; }
}
