:root {
  --bg: #f6f5f1;
  --card: #fff;
  --fg: #151515;
  --ink-2: #4a4945;
  --muted: #6b6a66;
  --dim: #8a8882;
  --faint: #a29f97;
  --line: #e6e4de;
  --line-2: #efede8;
  --chip: #ebe9e3;
  --hover: #f3f1ec;
  /* Zones */
  --ro16: #1fa463;
  --po-seeded: #2b7bf3;
  --po-unseeded: #f2a50c;
  --out: #dcd9d1;
  --stage: #7a5af5;
  /* Results */
  --win: #1fa463;
  --draw: #b9b5ab;
  --loss: #ef4f3c;
  --pos: #1a8f55;
  --neg: #d6402e;
  /* Favourite team (FAVORITE in app.js) */
  --fav: #e0101e;
  --fav-bg: #fdf0f0;
  --sans: Geist, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  padding: 36px 24px 64px;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.4 var(--sans);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}
header, .tabs, main { max-width: 1080px; margin-inline: auto; }
a { color: var(--fg); }
a:hover { color: var(--fav); }

/* Header */
header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-end;
  gap: 20px;
}
h1 { margin: 0; font: 600 40px/1 var(--sans); letter-spacing: -.035em; }

.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px; }
.md-progress { display: flex; flex-direction: column; gap: 6px; }
.md-bar { display: flex; gap: 3px; }
.md-bar span { width: 22px; height: 6px; border-radius: 3px; background: var(--out); }
.md-bar span.done { background: var(--fg); }
.md-bar span.next { box-shadow: inset 0 0 0 1.5px var(--fav); }
.md-text { font: 500 11px/1 var(--mono); color: var(--muted); }
.stale { color: var(--neg); font-size: 12px; font-weight: 600; }

button { font: inherit; cursor: pointer; }

/* Tabs */
.tabs {
  display: flex;
  gap: 2px;
  width: max-content;
  max-width: 100%;
  margin: 28px 0 20px;
  margin-left: max(0px, calc((100% - 1080px) / 2));
  padding: 3px;
  overflow-x: auto;
  border-radius: 999px;
  background: var(--chip);
}
.tabs a {
  display: flex;
  align-items: center;
  height: 32px;
  padding: 0 16px;
  border-radius: 999px;
  color: var(--muted);
  font: 500 13px var(--sans);
  text-decoration: none;
  white-space: nowrap;
}
.tabs a:hover { color: var(--fg); }
.tabs a.active { background: var(--card); color: var(--fg); box-shadow: 0 1px 2px rgba(0, 0, 0, .08); }

main { padding: 0; }
.error { color: var(--neg); }
.note { max-width: 640px; margin: 12px 2px 0; color: var(--dim); font-size: 12px; line-height: 1.55; text-wrap: pretty; }
#sim-status, #ko-status { margin: 0 2px 12px; font: 500 11px var(--mono); }
.section-title { margin: 28px 2px 12px; font: 600 18px var(--sans); letter-spacing: -.02em; }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 14px; background: var(--card); }
table { width: 100%; border-collapse: collapse; font-size: 13px; white-space: nowrap; }
th {
  padding: 12px 6px 10px;
  border-bottom: 1px solid var(--line);
  color: var(--dim);
  font: 500 10.5px var(--mono);
  letter-spacing: .04em;
  text-transform: uppercase;
  text-align: left;
  user-select: none;
}
th[data-sort] { cursor: pointer; }
th[data-sort]:hover { color: var(--fg); }
th.sorted { color: var(--fg); }
th.sorted::after { content: " ↓"; }
th.sorted.asc::after { content: " ↑"; }
th:first-child, td:first-child { padding-left: 14px; }
th:last-child, td:last-child { padding-right: 14px; }
th.num { text-align: right; }
th.z-ro16 { color: var(--ro16); }
th.z-ps { color: var(--po-seeded); }
th.z-pu { color: #c98500; }
#simulation th.num:nth-child(n+6), #ko-table th.num { text-align: center; }

td { height: 34px; padding: 0 6px; border-bottom: 1px solid var(--line-2); }
tbody tr:last-child td { border-bottom: 0; }
tr.zone-end td { border-bottom: 1.5px solid #d9d6ce; }
.num { text-align: right; }
.dim { color: var(--dim); }
.muted { color: var(--muted); }
td.team { width: 100%; font-weight: 500; }
td.pts { font-size: 14px; font-weight: 700; }
td.gd.pos { color: var(--pos); }
td.gd.neg { color: var(--neg); }
td.elo { color: var(--muted); font: 400 12px var(--mono); }

tr.team-row { cursor: pointer; }
tr.team-row:hover td { background: var(--hover); }
tr.fav td { background: var(--fav-bg); }
tr.fav td.team, tr.fav .team-link { color: var(--fav); font-weight: 700; }

.rank-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: var(--out);
  color: var(--muted);
  font: 600 11px var(--mono);
}
.ro16 .rank-chip { background: var(--ro16); color: #fff; }
.playoff_seeded .rank-chip { background: var(--po-seeded); color: #fff; }
.playoff_unseeded .rank-chip { background: var(--po-unseeded); color: var(--fg); }

.cc {
  display: inline-block;
  width: 30px;
  margin-right: 10px;
  color: var(--faint);
  font: 500 10px var(--mono);
}

.pills { display: flex; gap: 3px; }
.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 17px;
  height: 17px;
  border-radius: 5px;
  color: #fff;
  font: 600 10px var(--mono);
}
.pill.W { background: var(--win); }
.pill.D { background: var(--draw); }
.pill.L { background: var(--loss); }

.legend { display: flex; flex-wrap: wrap; gap: 8px 20px; margin: 16px 2px 0; padding: 0; list-style: none; color: var(--ink-2); font-size: 12px; }
.legend li { display: flex; align-items: center; gap: 7px; }
.swatch { width: 10px; height: 10px; border-radius: 3px; }
.swatch.ro16 { background: var(--ro16); }
.swatch.playoff_seeded { background: var(--po-seeded); }
.swatch.playoff_unseeded { background: var(--po-unseeded); }
.swatch.eliminated { background: var(--out); }

/* Clickable team names */
.team-link {
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: inherit;
  cursor: pointer;
}
.team-link:hover { text-decoration: underline; }
.team-link.fav { color: var(--fav); font-weight: 700; }

/* Kamper */
#matches { display: flex; flex-direction: column; gap: 28px; }
.md-head { display: flex; align-items: baseline; gap: 12px; margin: 0 2px 10px; }
.md-head h2 { margin: 0; font: 600 18px var(--sans); letter-spacing: -.02em; }
.md-date { color: var(--dim); font: 500 11px var(--mono); letter-spacing: .05em; text-transform: uppercase; }
.md-status { margin-left: auto; padding: 3px 8px; border-radius: 999px; color: var(--faint); font: 500 11px var(--mono); }
.md-status.done { background: var(--chip); color: var(--muted); }
.md-status.next { background: var(--fg); color: #fff; }

.match-list { margin: 0; padding: 0; list-style: none; overflow: hidden; border: 1px solid var(--line); border-radius: 14px; background: var(--card); }
.match-list li {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) 84px minmax(0, 1fr);
  align-items: center;
  column-gap: 10px;
  padding: 10px 14px;
  border-top: 1px solid var(--line-2);
}
.match-list li:first-child { border-top: 0; }
.match-list li.fav { background: var(--fav-bg); }
.match-list .time { color: var(--faint); font: 400 11px var(--mono); }
.match-list .side { display: flex; align-items: center; gap: 8px; min-width: 0; }
.match-list .side.home { justify-content: flex-end; text-align: right; }
.match-list .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.match-list li.home-won .home .name, .match-list li.away-won .away .name { font-weight: 700; }
.match-list .name.fav { color: var(--fav); font-weight: 700; }
.match-list .result { text-align: center; font: 700 15px var(--sans); }
.match-list .result.upcoming { color: #c9c6be; font: 400 13px var(--mono); }
.elo-badge { flex: none; color: var(--faint); font: 400 10px var(--mono); }

.prediction {
  grid-column: 2 / 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  margin-top: 7px;
  color: var(--dim);
  font: 400 10.5px var(--mono);
}
.pbar { display: flex; gap: 2px; width: min(240px, 100%); height: 4px; overflow: hidden; border-radius: 2px; }
.pbar .seg { border-radius: 2px; }
.pbar .seg.h { background: var(--win); }
.pbar .seg.u { background: #cfccc4; }
.pbar .seg.b { background: var(--po-seeded); }
.ptext { text-align: center; }

/* Heat cells (Prognose, Sluttspill) */
td.heat { padding: 2px; }
td.heat span, .stage-chip {
  background: color-mix(in oklch, var(--hc) calc(6% + var(--p) * 88%), #fff);
}
td.heat span {
  display: block;
  min-width: 52px;
  padding: 5px 0;
  border-radius: 6px;
  text-align: center;
  font: 500 11.5px var(--mono);
}
.hot { color: #fff; }
.h-ro16 { --hc: var(--ro16); }
.h-playoff_seeded { --hc: var(--po-seeded); }
.h-playoff_unseeded { --hc: var(--po-unseeded); color: var(--fg); }
.h-eliminated { --hc: #a8a49a; }
.h-stage { --hc: var(--stage); }
.h-winner { --hc: var(--po-unseeded); color: var(--fg); }
td.heat span.nil { background: transparent; color: #c9c6be; }

/* Rank sparkline */
td.dist { width: 1%; padding-left: 12px; }
.spark { display: flex; align-items: flex-end; gap: 1px; width: 144px; height: 22px; }
.spark .bar { flex: 1; min-width: 2px; border-radius: 1px; background: var(--out); }
.spark .bar.ro16 { background: var(--ro16); }
.spark .bar.playoff_seeded { background: var(--po-seeded); }
.spark .bar.playoff_unseeded { background: var(--po-unseeded); }

/* Sluttspill funnel */
.funnel-wrap { overflow-x: auto; margin-bottom: 8px; }
.funnel { display: grid; grid-template-columns: repeat(6, minmax(158px, 1fr)); gap: 8px; min-width: 980px; }
.funnel-col { --fc: var(--stage); padding: 14px 14px 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--card); }
.f-playoff { --fc: var(--po-seeded); }
.f-r16 { --fc: var(--ro16); }
.f-final { --fc: var(--fav); }
.f-winner { --fc: var(--po-unseeded); background: #fff7e6; border-color: #f6dca3; }
.f-title { font: 600 14px var(--sans); letter-spacing: -.01em; }
.f-sub { margin: 2px 0 12px; color: var(--dim); font: 400 10.5px var(--mono); }
.f-list { display: flex; flex-direction: column; gap: 7px; margin: 0; padding: 0; list-style: none; }
.f-row { display: flex; justify-content: space-between; gap: 6px; font-size: 12px; }
.f-row .team-link { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.f-p { color: var(--muted); font: 500 11px var(--mono); }
.f-bar { display: block; height: 3px; margin-top: 3px; border-radius: 2px; background: var(--chip); }
.f-bar span { display: block; height: 3px; border-radius: 2px; background: var(--fc); }

/* Team modal */
#team-modal {
  width: min(580px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  padding: 0;
  border: 0;
  border-radius: 18px;
  background: var(--card);
  color: var(--fg);
  box-shadow: 0 24px 60px -20px rgba(0, 0, 0, .35);
}
#team-modal::backdrop { background: rgba(21, 21, 21, .32); backdrop-filter: blur(3px); }
.modal-inner { position: relative; padding: 26px 26px 22px; }
.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: #f1efea;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
}
.modal-close:hover { background: var(--line); color: var(--fg); }
.modal-kicker { display: flex; align-items: center; gap: 10px; color: var(--dim); font: 500 11px var(--mono); letter-spacing: .04em; text-transform: uppercase; }
.modal-kicker .rank-chip { width: 26px; height: 26px; border-radius: 7px; font-size: 12px; }
#team-modal h2 { margin: 10px 40px 0 0; font: 600 30px/1.05 var(--sans); letter-spacing: -.03em; }
#team-modal h2.fav { color: var(--fav); }
#team-modal h3 { margin: 26px 0 10px; color: var(--dim); font: 500 10.5px var(--mono); letter-spacing: .08em; text-transform: uppercase; }
.modal-meta { margin: 8px 0 0; color: var(--muted); font-size: 12.5px; }
#team-modal .note { margin: 8px 0 0; }

.perf-summary { margin: 0 0 10px; color: var(--ink-2); font-size: 13px; line-height: 1.6; }
.perf-badge { display: inline-block; margin-right: 4px; padding: 2px 10px; border-radius: 999px; color: #fff; font-size: 12px; font-weight: 600; }
.perf-badge.over { background: var(--win); }
.perf-badge.on { background: var(--dim); }
.perf-badge.under { background: var(--loss); }
.perf-list { display: flex; flex-direction: column; margin: 0; padding: 0; list-style: none; font-size: 13px; }
.perf-list li {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) 44px 92px;
  gap: 8px;
  align-items: center;
  padding: 7px 0;
  border-top: 1px solid var(--line-2);
}
.perf-list .md { color: var(--faint); font: 400 11px var(--mono); }
.perf-score { text-align: right; font-weight: 700; }
.perf-delta { text-align: right; font: 500 11.5px var(--mono); }
.perf-delta.pos { color: var(--pos); }
.perf-delta.neg { color: var(--neg); }

.zone-boxes { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.zone-box { display: flex; flex-direction: column; padding: 10px 10px 9px; border-radius: 10px; background: #f1efea; color: var(--ink-2); }
.zone-box.ro16 { background: var(--ro16); color: #fff; }
.zone-box.playoff_seeded { background: var(--po-seeded); color: #fff; }
.zone-box.playoff_unseeded { background: var(--po-unseeded); color: var(--fg); }
.zb-p { font: 600 20px var(--sans); letter-spacing: -.02em; }
.zb-label { margin-top: 2px; font-size: 11.5px; font-weight: 500; }
.zb-sub { font: 400 10px var(--mono); opacity: .75; }

.spark-wrap { width: 100%; margin-top: 14px; }
.spark-wrap .spark { width: 100%; height: 48px; gap: 2px; }
.spark-wrap .spark .bar { border-radius: 2px; }
.spark-axis { position: relative; height: 14px; margin-top: 4px; color: var(--faint); font: 400 10px var(--mono); }
.spark-axis span { position: absolute; transform: translateX(-50%); }
.spark-axis span:nth-child(1) { left: 1.4%; }
.spark-axis span:nth-child(2) { left: 22.2%; }
.spark-axis span:nth-child(3) { left: 44.4%; }
.spark-axis span:nth-child(4) { left: 66.7%; }
.spark-axis span:nth-child(5) { left: 98.6%; }

.stage-chips { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 4px; }
.stage-chip { display: flex; flex-direction: column; align-items: center; padding: 8px 4px; border-radius: 8px; text-align: center; }
.stage-chip.nil { background: var(--bg); color: var(--faint); }
.stage-chip .zb-p { font: 600 14px var(--mono); letter-spacing: 0; }
.stage-chip .zb-label { font-size: 10.5px; font-weight: 400; }

.remaining { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 0; list-style: none; }
.remaining li { padding: 12px 14px; border-radius: 12px; background: var(--bg); }
.rm-head { color: var(--dim); font: 400 10.5px var(--mono); letter-spacing: .04em; text-transform: uppercase; }
.rm-md { color: var(--fg); font-weight: 500; }
.rm-vs { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px; margin: 4px 0 8px; color: var(--dim); font-size: 14px; }
.rm-vs .team-link { color: var(--fg); font-weight: 600; }
.rm-vs .team-link.fav { color: var(--fav); }
.rm-vs .elo-badge { margin-left: auto; }
.rm-odds { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font: 400 11px var(--mono); }
.rm-odds .pbar { width: 100%; height: 6px; border-radius: 3px; }
.rm-odds .seg { border-radius: 3px; }
.rm-odds .seg.b { background: var(--loss); }
.rm-score { margin-top: 4px; color: var(--muted); font-size: 12px; }

@media (max-width: 600px) {
  body { padding: 24px 12px 48px; }
  h1 { font-size: 32px; }
  th, td { padding-left: 4px; padding-right: 4px; }
  .cc { display: none; }
  .match-list li { grid-template-columns: 40px minmax(0, 1fr) 52px minmax(0, 1fr); column-gap: 6px; padding: 10px; font-size: 13px; }
  .elo-badge { display: none; }
  .zone-boxes { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stage-chips { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .modal-inner { padding: 22px 18px 18px; }
}
