:root {
  --bg: #0c1018;
  --bg-raised: #151b27;
  --bg-row: #1b2331;
  --line: #28323f;
  --text: #e8edf4;
  --muted: #93a1b5;
  --accent: #00c46a;      /* through */
  --accent-soft: rgba(0, 196, 106, 0.14);
  --third: #f0b429;       /* best-third */
  --third-soft: rgba(240, 180, 41, 0.14);
  --out: #5a6678;
  --gold: #f5c542;
  --live: #ff4d4f;
  --radius: 12px;
  --maxw: 1320px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; font-size: 106.25%; } /* ~17px base */

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: var(--maxw); margin: 0 auto; padding-left: 18px; padding-right: 18px; }

a { color: var(--gold); }

/* Header */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
/* Full-width hero: the artwork as a cover background (crops its hard edges),
   with the controls in a frosted glass bar pinned to the bottom so they stay
   legible over the busy image. */
.site-header {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  min-height: clamp(300px, 32vw, 460px);
  background: #112038 url("benders-worldcup.webp") center 20% / cover no-repeat;
  border-bottom: 1px solid var(--line);
}
.site-header::before {
  content: "";
  position: absolute; inset: 0;
  background: linear-gradient(to bottom,
    rgba(8, 11, 18, 0.20) 0%,
    rgba(8, 11, 18, 0.00) 32%,
    rgba(8, 11, 18, 0.30) 100%);
}
.header-controls-bar {
  position: relative;
  width: 100%;
  background: rgba(9, 13, 22, 0.72);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(8px);
}
.header-controls-inner {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 12px 18px;
  padding-top: 12px; padding-bottom: 12px;
}
.statusbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; font-size: 0.84rem; text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6); }
.status-item { color: #d6deea; }
#status-updated { cursor: default; }
#status-updated::before { content: "\25CF"; color: var(--accent); margin-right: 6px; font-size: 0.7em; vertical-align: middle; }
#status-updated.stale::before { color: var(--third); } /* amber when data is over a day old */
.refresh-btn {
  background: rgba(10, 16, 26, 0.55); color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.18); border-radius: 8px; padding: 6px 12px;
  cursor: pointer; font-size: 0.84rem; transition: border-color .15s, background .15s;
  backdrop-filter: blur(4px);
}
.refresh-btn:hover { border-color: var(--accent); background: var(--accent-soft); }
.refresh-btn[disabled] { opacity: 0.5; cursor: progress; }

.controls-row {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: flex-end;
}
.view-toggle { display: inline-flex; background: rgba(10, 16, 26, 0.6); border: 1px solid rgba(255, 255, 255, 0.18); border-radius: 10px; padding: 4px; backdrop-filter: blur(4px); }
.view-btn {
  background: transparent; border: 0; color: var(--muted); padding: 7px 16px;
  border-radius: 7px; cursor: pointer; font-size: 0.88rem; font-weight: 600;
}
.view-btn.is-active { background: var(--accent); color: #052b18; }
.filter { position: relative; flex: 1 1 220px; max-width: 340px; }
.filter input {
  width: 100%; background: rgba(10, 16, 26, 0.62); border: 1px solid rgba(255, 255, 255, 0.18);
  color: var(--text); border-radius: 10px; padding: 9px 32px 9px 14px; font-size: 0.9rem;
  backdrop-filter: blur(4px);
}
.filter input:focus { outline: none; border-color: var(--accent); }
.filter-clear {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  background: none; border: 0; color: var(--muted); font-size: 1.2rem; cursor: pointer; padding: 0 6px;
}

/* Panels */
main { padding-top: 18px; padding-bottom: 40px; }
.panel { margin-bottom: 34px; }
.panel-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 14px; }
.panel-head h2 { margin: 0; font-size: 1.25rem; }
.legend { margin: 0; font-size: 0.78rem; color: var(--muted); display: flex; gap: 14px; align-items: center; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; vertical-align: middle; }
.dot-q { background: var(--accent); }
.dot-t { background: var(--third); }
.note { color: var(--muted); font-size: 0.8rem; margin-top: 14px; }
.loading { color: var(--muted); padding: 40px 0; text-align: center; }
.error-box { background: #2a1416; border: 1px solid #5a2327; color: #ffd0d2; padding: 16px; border-radius: var(--radius); }

/* Groups */
.groups-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); gap: 18px; }
.group-card { background: var(--bg-raised); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.group-card h3 { margin: 0; padding: 13px 16px; font-size: 0.95rem; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); border-bottom: 1px solid var(--line); }
table.standings { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
table.standings th { color: var(--muted); font-weight: 600; font-size: 0.74rem; text-transform: uppercase; padding: 9px 5px; text-align: center; }
table.standings th.team-col { text-align: left; padding-left: 16px; }
table.standings td { padding: 10px 5px; text-align: center; border-top: 1px solid var(--line); }
table.standings td.team-col { text-align: left; padding-left: 16px; }
table.standings td.pts { font-weight: 700; }
.pos { color: var(--muted); width: 22px; }
.team-cell { display: flex; align-items: center; gap: 8px; }
.flag { font-size: 1.1rem; line-height: 1; }
.team-meta { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.team-name { font-weight: 600; }
.player-name { font-size: 0.74rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
tr.q   td.pos { box-shadow: inset 3px 0 0 var(--accent); }
tr.q3  td.pos { box-shadow: inset 3px 0 0 var(--third); }
tr.hl { background: rgba(245, 197, 66, 0.13); }

/* Knockout bracket slot (e.g. "Runner-up Group A") before teams are known */
.slot { color: var(--muted); font-style: italic; font-size: 0.92em; }

/* Schedule */
.sched-filters { font-size: 0.82rem; color: var(--muted); }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.day-group { margin-bottom: 22px; }
.day-head {
  position: sticky; top: 0; z-index: 2; background: var(--bg);
  padding: 8px 0; font-size: 0.9rem; font-weight: 700; color: var(--gold);
  border-bottom: 1px solid var(--line);
}
.match {
  display: grid; grid-template-columns: 92px 1fr auto 1fr 124px; align-items: center;
  gap: 10px; padding: 11px 12px; background: var(--bg-raised);
  border: 1px solid var(--line); border-radius: 10px; margin-top: 8px; font-size: 0.9rem;
}
.match .ko-time { display: flex; flex-direction: column; gap: 2px; color: var(--muted); font-size: 0.82rem; }
.match .ko-clock { font-variant-numeric: tabular-nums; white-space: nowrap; }
.match .ko-group { font-size: 0.74rem; opacity: 0.8; }
.match .side { display: flex; align-items: center; gap: 8px; min-width: 0; }
.match .side.left { justify-content: flex-end; text-align: right; }
.match .side .team-meta { min-width: 0; }
.match .side.left .team-meta { align-items: flex-end; }
.match .scoreline { font-weight: 800; font-size: 1rem; font-variant-numeric: tabular-nums; min-width: 52px; text-align: center; }
.match .scoreline.pending { color: var(--muted); font-weight: 600; }
.match .status { text-align: right; }
.badge { display: inline-block; white-space: nowrap; font-size: 0.66rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; padding: 3px 7px; border-radius: 999px; }
.badge.ft { background: #1e2a22; color: var(--accent); }
.badge.awaiting { background: #2a2516; color: var(--third); }
.badge.upcoming { background: #1d2430; color: var(--muted); }
.badge.ko { background: #251a2e; color: #c79bff; }
.match.dim { opacity: 0.34; }
.match.hl { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold); }
.match .pen-note { font-size: 0.7rem; color: var(--muted); display: block; }
.stage-head { margin: 26px 0 4px; font-size: 1rem; color: var(--gold); }

/* Knockout bracket */
.bracket-scroll { overflow-x: auto; padding-bottom: 6px; }
.bracket {
  --u: 58px;       /* vertical pitch of one Round-of-32 slot */
  --gut: 34px;     /* gap between rounds, also the connector width */
  --card-w: 190px;
  display: flex; gap: var(--gut); width: max-content; padding: 4px 2px 10px;
}
.b-col { display: flex; flex-direction: column; flex: 0 0 var(--card-w); }
.b-col-head {
  margin: 0 0 8px; font-size: 0.72rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--muted); text-align: center;
}
.b-slots { display: flex; flex-direction: column; }
.b-slot { position: relative; display: flex; align-items: center; justify-content: center; }
/* each round's slot is twice as tall as the previous, so matches line up between their feeders */
.b-col[data-ri="0"] .b-slot { height: calc(var(--u) * 1); }
.b-col[data-ri="1"] .b-slot { height: calc(var(--u) * 2); }
.b-col[data-ri="2"] .b-slot { height: calc(var(--u) * 4); }
.b-col[data-ri="3"] .b-slot { height: calc(var(--u) * 8); }
.b-col[data-ri="4"] .b-slot,
.b-col--third .b-slot { height: calc(var(--u) * 16); }

.bcard {
  position: relative; width: 100%;
  background: var(--bg-raised); border: 1px solid var(--line); border-radius: 8px; overflow: hidden;
}
.b-team { display: flex; align-items: center; gap: 6px; padding: 6px 9px; font-size: 0.8rem; line-height: 1.2; }
.b-team + .b-team { border-top: 1px solid var(--line); }
.b-flag { font-size: 1rem; flex: 0 0 auto; }
.b-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.b-team.slot .b-name { font-style: italic; font-weight: 500; color: var(--muted); font-size: 0.76rem; }
.b-drafter { color: var(--muted); font-size: 0.68rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.b-score { margin-left: auto; font-weight: 800; font-variant-numeric: tabular-nums; flex: 0 0 auto; }
.b-team.win .b-name, .b-team.win .b-score { color: var(--accent); }
.bcard.dim { opacity: 0.34; }
.bcard.hl { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold); }

/* Connectors: feeder cards get a stub out to mid-gutter; each later-round slot
   draws a vertical line spanning its two feeders, plus a stub into its own card. */
.b-col[data-ri="0"] .bcard::after,
.b-col[data-ri="1"] .bcard::after,
.b-col[data-ri="2"] .bcard::after,
.b-col[data-ri="3"] .bcard::after {
  content: ""; position: absolute; top: 50%; left: 100%;
  width: calc(var(--gut) / 2); height: 2px; background: var(--line);
}
.b-col[data-ri="1"] .b-slot { --pb: calc(var(--u) * 1); }
.b-col[data-ri="2"] .b-slot { --pb: calc(var(--u) * 2); }
.b-col[data-ri="3"] .b-slot { --pb: calc(var(--u) * 4); }
.b-col[data-ri="4"] .b-slot { --pb: calc(var(--u) * 8); }
.b-col[data-ri="1"] .b-slot::before,
.b-col[data-ri="2"] .b-slot::before,
.b-col[data-ri="3"] .b-slot::before,
.b-col[data-ri="4"] .b-slot::before {
  content: ""; position: absolute; left: calc(var(--gut) / -2);
  top: calc(50% - var(--pb) / 2); width: 2px; height: var(--pb); background: var(--line);
}
.b-col[data-ri="1"] .b-slot::after,
.b-col[data-ri="2"] .b-slot::after,
.b-col[data-ri="3"] .b-slot::after,
.b-col[data-ri="4"] .b-slot::after {
  content: ""; position: absolute; top: 50%; left: calc(var(--gut) / -2);
  width: calc(var(--gut) / 2); height: 2px; background: var(--line);
}
.b-col--third { margin-left: var(--gut); }

/* Footer */
.site-footer { border-top: 1px solid var(--line); padding-top: 18px; padding-bottom: 32px; color: var(--muted); font-size: 0.82rem; }
.site-footer p { margin: 0 0 6px; }
.footer-meta { color: #aeb9c9; }

@media (max-width: 720px) {
  .site-header { min-height: clamp(330px, 92vw, 420px); background-position: center 16%; }
  .header-controls-bar { justify-content: center; }
  .statusbar { justify-content: center; width: 100%; }
  .controls-row { justify-content: center; width: 100%; }
}

@media (max-width: 620px) {
  .match { grid-template-columns: 68px 1fr auto 1fr; row-gap: 4px; }
  .match .status { grid-column: 1 / -1; text-align: left; }
  .match .side .player-name { font-size: 0.68rem; }
  .player-name { max-width: 120px; }
}
