:root {
  /* Shared palette: quiet UI colors plus semantic result colors. */
  color-scheme: light;
  --ink: #17202a;
  --muted: #667085;
  --line: #d7dde5;
  --panel: #ffffff;
  --bg: #eef3f7;
  --accent: #0f766e;
  --soft: #e7f5f3;
  --win: #e7f5f3;
  --loss: #fde8e8;
  --draw: #fff4cc;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

header {
  background: #0b1f33;
  color: white;
  padding: 18px clamp(16px, 4vw, 40px);
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
}

h1 { margin: 0; font-size: clamp(22px, 3vw, 34px); letter-spacing: 0; }
h2, h3 { margin: 0 0 10px; letter-spacing: 0; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }

.subtitle { color: #c8d3df; margin-top: 4px; font-size: 14px; }
.countdown { color: #ffffff; margin-top: 8px; font-size: 15px; font-weight: 800; }
.header-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

button {
  border: 1px solid var(--line);
  background: white;
  color: var(--ink);
  border-radius: 6px;
  padding: 9px 12px;
  cursor: pointer;
  font-weight: 700;
}

button.primary { background: var(--accent); color: white; border-color: var(--accent); }

main { padding: 18px clamp(12px, 3vw, 32px) 40px; }

.tabs {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 16px;
  overflow-x: auto;
}

.tab {
  border: 0;
  background: transparent;
  border-radius: 0;
  padding: 12px 14px;
  color: var(--muted);
  white-space: nowrap;
}

.tab.active { color: var(--accent); border-bottom: 3px solid var(--accent); }
section[hidden] { display: none; }

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.status { color: var(--muted); font-size: 13px; }
.match-list { display: grid; gap: 10px; }

/* Game cards are a three-column layout on desktop and collapse naturally on mobile. */
.match {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  display: grid;
  grid-template-columns: minmax(210px, 1fr) minmax(260px, 2fr) minmax(116px, auto);
  gap: 12px;
  align-items: center;
  position: relative;
  scroll-margin-top: 18px;
}

.match-past { background: #e5e7eb; }
.match-live { border: 3px solid #11966e; background: #fbfffd; }
.live-badge {
  position: absolute;
  top: 8px;
  right: 38px;
  background: #11966e;
  color: white;
  border-radius: 5px;
  padding: 4px 7px;
  font-size: 12px;
  font-weight: 800;
}

.ball-mark {
  position: absolute;
  top: 8px;
  right: 10px;
  font-size: 17px;
}

.meta { color: var(--muted); font-size: 13px; line-height: 1.45; }
.teams { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; font-size: 17px; font-weight: 700; }
.team { display: inline-flex; align-items: center; gap: 7px; min-width: 0; }
.team.home { flex-direction: row-reverse; justify-content: flex-start; text-align: right; }
.fi {
  width: 1.45em;
  line-height: 1em;
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(23, 32, 42, 0.14);
  flex: 0 0 auto;
}
.emoji-flag {
  font-size: 20px;
  line-height: 1;
  flex: 0 0 auto;
}
.flag-small { width: 1.75em; }

.score { display: grid; gap: 4px; align-items: center; justify-content: center; min-width: 86px; }
.main-score, .penalty-score { display: flex; gap: 5px; align-items: center; justify-content: center; }
.penalty-score { font-size: 12px; color: var(--muted); }

.score input {
  width: 36px;
  height: 34px;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 5px;
  font-size: 16px;
  font-weight: 700;
  background: #fbfcfd;
}

.score input.score-win { background: var(--win); border-color: #87c7ad; }
.score input.score-loss { background: var(--loss); border-color: #e6a0a0; }
.score input.score-draw { background: var(--draw); border-color: #e0c15c; }
.watch-link {
  position: absolute;
  right: 10px;
  bottom: 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  text-decoration: none;
}

.groups { display: grid; grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); gap: 14px; }

.group-card, .bracket-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.bracket-wrap {
  overflow: auto;
  max-width: 100%;
  max-height: calc(100vh - 185px);
  min-width: 0;
}

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { border-bottom: 1px solid var(--line); padding: 7px 6px; text-align: center; }
th:first-child, td:first-child { text-align: left; }
.standings-team { display: inline-flex; gap: 7px; align-items: center; }
.matrix .standings-team { font-weight: 400; }
.qualified td { background: var(--soft); }
.third-qualified td { background: var(--draw); }

.matrix td:first-child, .matrix th:first-child { width: 32%; }
.matrix .diag { background: #f2f4f7; color: #98a2b3; }
.matrix .flag-only { font-size: 19px; text-align: center; }
.matrix .result-win { background: var(--win); }
.matrix .result-loss { background: var(--loss); }
.matrix .result-draw { background: var(--draw); }

/* The knockout bracket is intentionally a wide canvas inside a scrollable frame.
   Absolute positioning keeps each card aligned with the path of the winners. */
.bracket {
  overflow: visible;
  position: relative;
  min-height: 620px;
  padding-bottom: 6px;
  flex: 0 0 auto;
}

.bracket-title {
  position: absolute;
  width: 220px;
  font-weight: 800;
  color: var(--accent);
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 28px;
}

.title-emoji { font-size: 34px; line-height: 1; }

.bracket-lines {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: visible;
}

.bracket-lines path {
  /* Connector paths are generated in JS from the same card coordinates. */
  fill: none;
  stroke: #8b98a8;
  stroke-width: 2;
  stroke-linecap: square;
}

.bracket-match {
  position: absolute;
  transform: translateY(-50%);
  width: 220px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  min-height: 116px;
  padding: 8px;
}

.bracket-past { background: #d5d9df; }
.bracket-live { border: 3px solid #11966e; background: #fbfffd; }
.match-id { font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.bracket-date {
  color: var(--muted);
  font-size: 12px;
  margin-top: 7px;
  border-top: 1px solid #edf0f3;
  padding-top: 6px;
}
.slot { display: flex; justify-content: space-between; gap: 8px; border-top: 1px solid #edf0f3; padding-top: 4px; margin-top: 4px; }
.slot-team { display: inline-flex; align-items: center; gap: 6px; min-width: 0; }
.slot-score { display: inline-flex; align-items: center; gap: 5px; font-weight: 800; }
.winner-check { color: #11966e; font-weight: 900; }
.penalty-inline { color: #3f4650; font-size: 12px; font-weight: 700; }
.placeholder { color: var(--muted); }

.back-to-top {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 1000;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 0;
  background: var(--accent);
  color: white;
  box-shadow: 0 8px 22px rgba(15, 118, 110, 0.28);
  font-size: 26px;
  line-height: 1;
}

@media (max-width: 760px) {
  .match { grid-template-columns: 1fr; }
  .teams { grid-template-columns: 1fr; text-align: left; }
  .team.home { flex-direction: row; justify-content: flex-start; text-align: left; }
  .score { justify-content: flex-start; }
  .bracket { min-width: 1248px; }
}
