:root {
  --bg: #0a0e17;
  --panel: #121826;
  --panel-2: #1a2234;
  --line: #2a3346;
  --text: #e7ecf3;
  --muted: #8a93a6;
  --win: #2ee6a6;
  font-synthesis: none;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background:
    radial-gradient(1200px 500px at 80% -10%, #16203a 0%, transparent 60%),
    radial-gradient(900px 500px at 0% 0%, #1a1430 0%, transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  min-height: 100vh;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
  background: rgba(10, 14, 23, 0.82);
  backdrop-filter: blur(10px);
}
.title-wrap h1 {
  margin: 0; font-size: clamp(20px, 3.4vw, 34px); letter-spacing: -0.02em;
  background: linear-gradient(90deg, #fff, #9fb4ff 55%, #ff8a5c);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.subtitle { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

.status { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #555; }
.dot.live { background: var(--win); box-shadow: 0 0 0 0 rgba(46,230,166,.6); animation: pulse 1.8s infinite; }
.dot.idle { background: #5a93c8; }
.dot.stale { background: #e0b020; }
.dot.err { background: #e05050; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(46,230,166,.55); }
  70% { box-shadow: 0 0 0 10px rgba(46,230,166,0); }
  100% { box-shadow: 0 0 0 0 rgba(46,230,166,0); }
}

/* ---------- filter label ---------- */
.filter-label {
  margin: 14px 0 0; padding: 0 24px;
  font-size: 12px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase;
  color: var(--muted);
}

/* ---------- scoreboard ---------- */
.scoreboard {
  display: flex; flex-wrap: wrap; gap: 10px;
  padding: 16px 24px 4px;
}
.brand-card {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel); border: 1px solid var(--line);
  border-left: 4px solid var(--c, #888);
  border-radius: 12px; padding: 8px 14px 8px 12px; min-width: 132px;
  transition: transform .15s ease, box-shadow .15s ease, opacity .15s ease;
  /* doubles as a filter button */
  font: inherit; color: var(--text); text-align: left; cursor: pointer;
}
.brand-card:hover { transform: translateY(-1px); border-color: var(--c, #888); }
.brand-card.active {
  border-color: var(--c, #fff);
  box-shadow: 0 0 0 2px var(--c, #fff), 0 6px 18px -8px var(--c, #000);
  background: var(--panel-2);
}
/* when a brand is selected, fade the rest to spotlight the choice */
.scoreboard.has-active .brand-card:not(.active) { opacity: .45; }
.scoreboard.has-active .brand-card.dead { opacity: .28; }
.brand-card .bc-logo {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 24px; border-radius: 6px; flex: none;
}
.brand-card .bc-logo img { width: 22px; height: 15px; object-fit: contain; }
.brand-card .bc-logo-text { font-size: 10px; font-weight: 800; color: #0a0e17; letter-spacing: .02em; }
.brand-card.dead .bc-logo { filter: grayscale(.7); }
.brand-card .bc-name { font-weight: 700; font-size: 13px; }
.brand-card .bc-count { font-size: 20px; font-weight: 800; line-height: 1; }
.brand-card .bc-of { color: var(--muted); font-size: 11px; }
.brand-card.dead { opacity: .4; }
/* brand with no Round-of-32 team: blacked out, not a usable filter */
.brand-card.absent {
  opacity: .32; filter: grayscale(1);
  cursor: default; pointer-events: none;
}
.brand-card.absent .bc-count { color: var(--muted) !important; }
.brand-card.absent .bc-of { text-transform: uppercase; font-size: 9px; letter-spacing: .08em; }

/* clear-filter text button at the end of the row */
.bc-clear {
  align-self: center; margin-left: 4px;
  background: none; border: none; color: var(--muted);
  font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
  padding: 6px 8px; border-radius: 8px; transition: color .14s ease, opacity .14s ease;
}
.bc-clear:hover { color: var(--text); text-decoration: underline; }
.scoreboard:not(.has-active) .bc-clear { opacity: .35; pointer-events: none; }

/* ---------- loading state ---------- */
.loader {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding: 70px 24px; color: var(--muted);
}
body:not(.is-loading) .loader { display: none; }
body.is-loading .filter-label,
body.is-loading .scoreboard { display: none; }
.spinner {
  width: 38px; height: 38px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: #9fb4ff;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loader p { margin: 0; font-size: 14px; font-weight: 600; letter-spacing: .02em; }

/* ---------- bracket ---------- */
/* Horizontally scrollable, but hide the native scrollbar so it doesn't read as a
   divider at the bottom of the tall <main>. Still swipeable / trackpad-scrollable. */
.bracket-scroll {
  overflow-x: auto; padding: 8px 24px 28px;
  scrollbar-width: none;        /* Firefox */
  -ms-overflow-style: none;     /* legacy Edge */
}
.bracket-scroll::-webkit-scrollbar { display: none; }  /* Chrome / Safari */
/* the bracket, the scroll hint, and the third-place section scroll sideways as one unit */
.scroll-track {
  display: flex; flex-direction: column; align-items: flex-start;
  width: max-content; min-width: 100%;
}
body.is-loading .scroll-hint,
body.is-loading .thirdplace { display: none; }
.bracket {
  display: flex; gap: 30px; align-items: stretch; min-width: max-content;
}
.round { display: flex; flex-direction: column; min-width: 230px; }
.round-title {
  font-size: 12px; text-transform: uppercase; letter-spacing: .12em;
  color: var(--muted); font-weight: 700; margin: 0; padding: 20px 0 16px; text-align: center;
}
.round-matches {
  display: flex; flex-direction: column; justify-content: space-around;
  flex: 1; gap: 14px;
}

.match {
  position: relative;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; overflow: hidden;
}
.match.live { border-color: var(--win); box-shadow: 0 0 0 1px rgba(46,230,166,.35); }
.match.justfinished { animation: flash 1.2s ease-out 4; }
@keyframes flash {
  0%,100% { box-shadow: 0 0 0 1px var(--line); }
  50% { box-shadow: 0 0 0 3px rgba(159,180,255,.8); }
}
.match-meta {
  display:flex; justify-content: space-between; align-items:center;
  font-size: 10px; color: var(--muted); padding: 4px 10px; border-bottom: 1px solid var(--line);
}
.match-meta .live-tag { color: var(--win); font-weight: 700; }

.team {
  position: relative;
  display: grid; grid-template-columns: 22px 1fr auto auto; align-items: center;
  gap: 9px; padding: 8px 10px;
  border-left: 4px solid var(--tc, transparent);
}
.team + .team { border-top: 1px solid var(--line); }
.team img.flag { width: 22px; height: 16px; object-fit: cover; border-radius: 2px; background:#222; }
.team .tname { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.team .tname.tbd { color: var(--muted); font-weight: 500; font-style: italic; }
.team .score { font-variant-numeric: tabular-nums; font-weight: 800; font-size: 15px; min-width: 16px; text-align: center; color: var(--muted); }
.team.winner { background: linear-gradient(90deg, rgba(46,230,166,.10), transparent 70%); }
.team.winner .score { color: var(--win); }
.team.winner .tname { color: #fff; }
.team.loser { opacity: .42; }
.team.loser img.flag { filter: grayscale(1); }

/* kit wordmark chip */
.kit {
  font-size: 10px; font-weight: 800; letter-spacing: .02em;
  padding: 2px 7px; border-radius: 6px; color: #0a0e17;
  background: var(--tc, #888); white-space: nowrap;
}
.kit.adidas, .kit.umbro { text-transform: lowercase; }

/* logo chip: white brand mark on the brand colour */
.kit-logo {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 18px; padding: 0; border-radius: 5px;
}
.kit-logo img { width: 18px; height: 12px; object-fit: contain; display: block; }
.team.loser .kit-logo { filter: grayscale(.7); opacity: .9; }

/* dimming when a brand filter is active */
.bracket.filtering .team:not(.brandmatch) { opacity: .16; }
.bracket.filtering .team.brandmatch { box-shadow: inset 0 0 0 9999px rgba(255,255,255,.03); }
.bracket.filtering .match { border-color: var(--line); }

/* connectors */
.round:not(:last-child) .match::before {
  content:''; position:absolute; right:-30px; top:50%; width:30px; height:1px; background: var(--line);
}

/* ---------- third place ---------- */
.thirdplace { padding: 0 24px 24px; }
.thirdplace .tp-wrap { max-width: 300px; }
.thirdplace h3 { font-size: 12px; text-transform: uppercase; letter-spacing:.12em; color: var(--muted); margin: 0 0 8px; }

/* ---------- footer ---------- */
.footer {
  display:flex; justify-content: space-between; flex-wrap: wrap; gap: 8px;
  padding: 14px 24px 30px; color: var(--muted); font-size: 12px; border-top: 1px solid var(--line);
}
.footer a { color: #9fb4ff; }

/* mobile-only scroll hint (hidden on larger screens) */
.scroll-hint { display: none; }

@media (max-width: 640px) {
  /* stretch (not flex-start) so the long subtitle wraps instead of widening the page */
  .topbar { flex-direction: column; align-items: stretch; gap: 8px; }
  .title-wrap { min-width: 0; }
  .title-wrap h1 { font-size: 26px; }
  /* let brand cards share the row width so the scoreboard never overflows */
  .brand-card { flex: 1 1 140px; min-width: 0; }
  .round { min-width: 210px; }

  /* larger, clearer column headers so the rounds read at a glance */
  .round-title {
    font-size: 20px; letter-spacing: .02em; margin: 0; padding: 20px 0 16px;
    color: var(--text);
  }

  .scroll-hint {
    display: flex; flex-wrap: wrap; align-items: center; justify-content: center;
    gap: 8px 12px; padding: 32px 20px; margin: 4px 0;
    font-size: 22px; font-weight: 800; color: var(--text); text-align: center;
  }
  .scroll-hint .scroll-arrow {
    width: 38px; height: 38px; flex: none; color: #9fb4ff;
    animation: nudge 1.2s ease-in-out infinite;
  }
  @keyframes nudge {
    0%, 100% { transform: translateX(0); }
    50% { transform: translateX(8px); }
  }
}

/* small phones: shrink the filter buttons so two fit per row, and drop brands
   that never reached the Round of 32 */
@media (max-width: 480px) {
  .scoreboard, .filter-label { padding-left: 16px; padding-right: 16px; }
  .scoreboard { gap: 10px; }
  .brand-card {
    flex: 0 1 calc(50% - 5px);   /* two per row; a lone card stays half-width */
    gap: 8px; padding: 7px 10px 7px 9px;
  }
  .brand-card .bc-logo { width: 28px; height: 20px; }
  .brand-card .bc-logo img { width: 18px; height: 12px; }
  .brand-card .bc-count { font-size: 16px; }
  .brand-card .bc-of { font-size: 10px; }
  .brand-card .bc-name { font-size: 11px; }
  .brand-card.absent { display: none; }   /* hide not-in-R32 brands entirely */
}
