:root {
  --bg: #0b1020;
  --bg2: #121a33;
  --panel: #161f3c;
  --panel2: #1c2750;
  --line: #2a3766;
  --text: #e8ecf8;
  --muted: #8b97c0;
  --accent: #4ade80;
  --accent2: #38bdf8;
  --gold: #fbbf24;
  --win: #1f8a4c;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: radial-gradient(1200px 600px at 70% -10%, #1b2750 0%, var(--bg) 55%);
  color: var(--text);
  min-height: 100vh;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 16px;
  padding: 24px 28px 16px;
  border-bottom: 1px solid var(--line);
}
.title h1 { margin: 0; font-size: 26px; letter-spacing: -0.5px; }
.title .sub { margin: 6px 0 0; color: var(--muted); font-size: 13px; }
.title .sub a { color: var(--accent2); text-decoration: none; }

/* page tabs */
.tabs { display: flex; gap: 8px; margin-top: 12px; }
.tab {
  font-size: 13px; font-weight: 600; text-decoration: none; color: var(--muted);
  padding: 7px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel);
}
.tab:hover { color: var(--text); }
.tab.active { color: #04121f; background: var(--accent2); border-color: var(--accent2); }

.controls { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
#refresh {
  background: linear-gradient(180deg, var(--accent2), #1d8fd0);
  color: #04121f;
  border: none;
  font-weight: 700;
  font-size: 14px;
  padding: 10px 18px;
  border-radius: 10px;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(56, 189, 248, 0.3);
  transition: transform 0.08s ease, filter 0.15s ease;
}
#refresh:hover { filter: brightness(1.08); }
#refresh:active { transform: translateY(1px); }
#refresh:disabled { opacity: 0.6; cursor: progress; }
.btnrow { display: flex; gap: 8px; align-items: center; }
.btn-secondary {
  display: inline-flex; align-items: center;
  background: var(--panel2);
  color: var(--text);
  border: 1px solid var(--line);
  font-weight: 700;
  font-size: 14px;
  padding: 10px 16px;
  border-radius: 10px;
  cursor: pointer;
  text-decoration: none;
  transition: filter 0.15s ease, transform 0.08s ease;
}
.btn-secondary:hover { filter: brightness(1.15); }
.btn-secondary:active { transform: translateY(1px); }
.btn-secondary.busy { opacity: 0.6; cursor: progress; }
.meta { color: var(--muted); font-size: 12px; text-align: right; }

.banner {
  margin: 14px 28px 0;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  background: #3a2118;
  border: 1px solid #6b3b22;
  color: #ffcaa8;
}
.hidden { display: none; }

main { padding: 20px 28px 40px; }
/* centered, comfortable reading width for the standalone Title-race page */
.narrow-main { max-width: 560px; margin: 0 auto; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  min-width: 0; /* allow panels to shrink within the grid track */
}
.panel h2 { margin: 0 0 14px; font-size: 16px; display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.hint { color: var(--muted); font-size: 11px; font-weight: 400; }
.legend { margin-left: auto; color: var(--muted); font-size: 11px; display: flex; align-items: center; gap: 6px; }
.legend .lg { font-size: 9px; font-weight: 700; border-radius: 4px; padding: 1px 5px; margin-left: 6px; }
.legend .p1 { color: #04121f; background: var(--gold); }
.legend .p2 { color: #04121f; background: var(--accent2); }
.legend .p3 { color: #fff; background: #7c5cff; }
.legend .score-pred { color: var(--muted); background: rgba(255, 255, 255, 0.06); }
.legend .score-ft { color: #04121f; background: var(--accent); }

/* Leaderboard */
.leaders { list-style: none; margin: 0; padding: 0; }
.leaders li {
  display: grid;
  grid-template-columns: 22px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}
.leaders li:last-child { border-bottom: none; }
.rank { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; text-align: right; }
.team { display: flex; align-items: center; gap: 8px; min-width: 0; }
.flag { font-size: 18px; flex: none; }
.tname { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pct { font-weight: 700; font-variant-numeric: tabular-nums; color: var(--accent); font-size: 14px; }
.barwrap { grid-column: 2 / 4; height: 4px; background: var(--panel2); border-radius: 4px; overflow: hidden; }
.bar { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); }
.odds-sub { color: var(--muted); font-size: 11px; }

/* Bracket */
.bracket-scroll { overflow-x: auto; padding-bottom: 8px; }
.bracket { display: flex; gap: 28px; min-width: max-content; }
.round { display: flex; flex-direction: column; justify-content: space-around; min-width: 178px; }
.round-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); margin-bottom: 8px; text-align: center;
}
.match {
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin: 7px 0;
  overflow: hidden;
}
/* kick-off date/time + venue header on each match */
.matchwhen {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
  padding: 3px 8px;
  background: rgba(255, 255, 255, 0.035);
  border-bottom: 1px solid var(--line);
}
.mw-date {
  color: var(--accent2); font-size: 10px; font-weight: 700;
  letter-spacing: 0.02em; font-variant-numeric: tabular-nums; white-space: nowrap;
}
.mw-venue {
  color: var(--muted); font-size: 9px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.slot {
  display: grid;
  grid-template-columns: 24px 15px 1fr 16px 30px;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  font-size: 13px;
}
.slot + .slot { border-top: 1px solid var(--line); }
.slot.win { background: rgba(31, 138, 76, 0.22); }
.slot.win .sname { font-weight: 700; }
.slot.lose { opacity: 0.5; }

/* score per side */
.sgoal {
  font-weight: 800; text-align: center; font-variant-numeric: tabular-nums;
  font-size: 13px; color: var(--muted);
}
.match.final .sgoal { color: var(--text); }
.match.final .slot.win .sgoal { color: var(--accent); }

/* predicted vs final badge */
.scoretag {
  text-align: center; font-size: 8.5px; letter-spacing: 0.08em; text-transform: uppercase;
  padding: 1px 0; font-weight: 700;
}
.scoretag.pred { color: var(--muted); background: rgba(255, 255, 255, 0.03); }
.scoretag.ft { color: #04121f; background: var(--accent); }
.scoretag.manual { color: #04121f; background: var(--gold); }
.match.final { border-color: var(--accent); box-shadow: 0 0 0 1px rgba(74, 222, 128, 0.25); }

/* a manually edited tie + the tap-to-edit affordance */
.match.manual { border-color: var(--gold); box-shadow: 0 0 0 1px rgba(251, 191, 36, 0.25); }
.match.editable { cursor: pointer; transition: border-color 0.12s ease, transform 0.06s ease; }
.match.editable:hover { border-color: var(--accent2); }
.match.editable:active { transform: scale(0.997); }
.match.editable:focus-visible { outline: 2px solid var(--accent2); outline-offset: 2px; }

/* result editor modal */
.editor-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(4, 8, 20, 0.66);
  display: flex; align-items: center; justify-content: center;
  padding: 16px; backdrop-filter: blur(2px);
}
.editor {
  width: 100%; max-width: 420px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 18px 18px 16px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.ed-title { font-size: 15px; font-weight: 700; margin-bottom: 14px; }
.ed-sub { color: var(--muted); font-size: 11px; font-weight: 500; }
.ed-grid {
  display: grid; grid-template-columns: 1fr 46px 14px 46px 1fr;
  align-items: center; gap: 8px;
}
.ed-team { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; min-width: 0; }
.ed-team span:not(.sflag) { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ed-team.right { justify-content: flex-end; text-align: right; }
.ed-score {
  width: 46px; height: 40px; text-align: center;
  font-size: 18px; font-weight: 800; font-variant-numeric: tabular-nums;
  color: var(--text); background: var(--panel2);
  border: 1px solid var(--line); border-radius: 8px;
}
.ed-score:focus { outline: none; border-color: var(--accent2); }
.ed-dash { text-align: center; color: var(--muted); }

.ed-adv { display: none; margin-top: 14px; }
.ed-adv.show { display: block; }
.ed-adv-lbl { font-size: 12px; color: var(--muted); }
.ed-adv-btns { display: flex; gap: 8px; margin-top: 6px; }
.ed-adv-btn {
  flex: 1; padding: 8px 10px; font-size: 13px; font-weight: 600;
  color: var(--text); background: var(--panel2);
  border: 1px solid var(--line); border-radius: 8px; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ed-adv-btn.on { color: #04121f; background: var(--gold); border-color: var(--gold); }

.ed-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 18px; }
.ed-right { display: flex; gap: 8px; margin-left: auto; }
.btn-primary {
  background: linear-gradient(180deg, var(--accent2), #1d8fd0); color: #04121f;
  border: none; font-weight: 700; font-size: 14px; padding: 9px 18px;
  border-radius: 9px; cursor: pointer;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost {
  background: transparent; color: var(--muted);
  border: 1px solid var(--line); font-weight: 600; font-size: 13px;
  padding: 9px 14px; border-radius: 9px; cursor: pointer;
}
.btn-ghost:hover { color: var(--text); }
.seed {
  color: var(--muted); font-size: 9px; font-weight: 700; text-align: center;
  border-radius: 4px; padding: 1px 0; background: rgba(255,255,255,0.05);
}
.seed.p1 { color: #04121f; background: var(--gold); }       /* group winner */
.seed.p2 { color: #04121f; background: var(--accent2); }    /* runner-up */
.seed.p3 { color: #fff; background: #7c5cff; }              /* best third */
.sflag { font-size: 14px; }
.sname { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sprob { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.slot.win .sprob { color: var(--accent); }

.champion {
  align-self: center;
  margin-top: 10px;
  text-align: center;
  background: linear-gradient(180deg, #2a2410, #1a160a);
  border: 1px solid var(--gold);
  border-radius: 10px;
  padding: 12px 18px;
}
.champion .lbl { font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--gold); }
.champion .cname { font-size: 18px; font-weight: 800; margin-top: 4px; }
.champion .cflag { font-size: 22px; }

footer {
  display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 16px 28px 30px; color: var(--muted); font-size: 11px;
  border-top: 1px solid var(--line);
}

.spin { display: inline-block; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Fixtures page ===== */
.fixtures-main { padding: 20px 28px 40px; max-width: 980px; }
.fx-legend {
  display: flex; flex-wrap: wrap; gap: 18px; color: var(--muted); font-size: 12px;
  padding: 12px 16px; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); margin-bottom: 18px;
}
.fx-legend span { display: flex; align-items: center; gap: 7px; }

.kpill {
  font-size: 9px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.04em;
  padding: 2px 6px; border-radius: 5px; white-space: nowrap;
}
.kpill.expected { color: #04121f; background: var(--accent); }
.kpill.projected { color: #fff; background: #7c5cff; }
.kpill.tbd { color: var(--muted); background: rgba(255, 255, 255, 0.06); }

.fx-day { margin-bottom: 22px; }
.fx-date {
  margin: 0 0 10px; font-size: 13px; color: var(--text); font-weight: 700;
  position: sticky; top: 0; background: var(--bg); padding: 6px 0; z-index: 2;
  border-bottom: 1px solid var(--line);
}
.fx-list { display: flex; flex-direction: column; gap: 6px; }

.fx-row {
  display: grid;
  grid-template-columns: 52px 132px 1fr 64px 1fr 48px;
  align-items: center; gap: 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 14px;
}
.fx-row.projected { border-left: 3px solid #7c5cff; }
.fx-row.expected { border-left: 3px solid var(--accent); }
.fx-row.tbd { opacity: 0.72; }

.fx-time { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.fx-stage { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }
.fx-team { display: flex; align-items: center; gap: 8px; min-width: 0; }
.fx-team.home { justify-content: flex-end; text-align: right; }
.fx-team.away { justify-content: flex-start; }
.fx-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fx-flag { font-size: 18px; flex: none; }
.fx-pos {
  font-size: 9px; font-weight: 700; color: var(--muted);
  background: rgba(255, 255, 255, 0.06); border-radius: 4px; padding: 1px 4px;
}
.fx-tbd { color: var(--muted); font-size: 12.5px; font-style: italic; }
.fx-score {
  text-align: center; font-weight: 800; font-size: 17px; font-variant-numeric: tabular-nums;
}
.fx-score .dash { color: var(--muted); margin: 0 3px; font-weight: 400; }
.fx-vs { text-align: center; color: var(--muted); font-size: 12px; }
.empty { color: var(--muted); }

@media (max-width: 760px) {
  .fx-row { grid-template-columns: 44px 1fr 56px 1fr; }
  .fx-stage { display: none; }
  .fx-row .kpill { display: none; }
}

/* ===== Phone layout ===== */
@media (max-width: 700px) {
  header {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    padding: 16px 16px 12px;
  }
  .title h1 { font-size: 20px; }
  .title .sub { font-size: 12px; }

  /* controls become a full-width, left-aligned stack */
  .controls { align-items: stretch; width: 100%; }
  .btnrow { width: 100%; }
  .btnrow #refresh, .btnrow .btn-secondary {
    flex: 1; justify-content: center; text-align: center; padding: 11px 12px;
  }
  .meta { text-align: left; }

  main { padding: 14px 12px 32px; gap: 14px; }
  .panel { padding: 14px 14px; border-radius: 10px; }
  .panel h2 { font-size: 15px; }

  /* keep the bracket legend from crowding the heading on small screens */
  .bracketwrap .legend { width: 100%; margin-left: 0; }

  .banner { margin: 12px 16px 0; }
  footer { padding: 14px 16px 26px; }

  /* the bracket itself stays a horizontal scroller, now smooth on touch */
  .bracket-scroll { -webkit-overflow-scrolling: touch; scroll-snap-type: x proximity; }
  .bracket { gap: 18px; }
  .round { min-width: 165px; scroll-snap-align: start; }

  /* show full team names (wrap) instead of clipping them on narrow rows */
  .fx-row { column-gap: 6px; padding: 9px 10px; }
  .fx-name { white-space: normal; overflow: visible; line-height: 1.15; }
  .fx-score { font-size: 16px; }
}

@media (max-width: 380px) {
  .btnrow { flex-direction: column; }
  .round { min-width: 158px; }
}

/* ===== Print / PDF export ===== */
@media print {
  /* size to content so the renderer can fit it on one poster page */
  html, body { min-height: 0 !important; height: auto !important; }
  body {
    background: var(--bg) !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  /* drop interactive chrome that has no place on paper */
  .controls .btnrow, #refresh, #pdf, .tabs, .banner { display: none !important; }
  header { border-bottom: 1px solid var(--line); padding-bottom: 12px; }

  /* let the full bracket expand instead of living in a scroll box */
  .bracket-scroll { overflow: visible !important; padding: 0 !important; }
  .bracket { min-width: 0 !important; }
  .round { justify-content: flex-start !important; }
  main { padding: 16px 24px 8px !important; }

  /* keep individual cards intact across any page split */
  .match, .champion, .fx-row, .fx-day, .leaders li { break-inside: avoid; }
  .fx-date { position: static !important; }
  footer { border-top: 1px solid var(--line); }
}
