:root {
  --bg: #f4f5f2;
  --surface: #ffffff;
  --surface-2: #eef0ec;
  --ink: #0d1b2a;
  --ink-2: #47525e;
  --ink-3: #7b8590;
  --line: #dde1dc;
  --accent: #d7263d;
  --accent-ink: #ffffff;
  --win: #1f8a4c;
  --win-bg: #e3f3e8;
  --otw: #5aa575;
  --otl: #d08a2c;
  --loss: #c0392b;
  --loss-bg: #fbe7e4;
  --live: #e0262b;
  --hl: #fff4cc;
  --play: #0d1b2a;
  --play-ink: #ffffff;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(13, 27, 42, .06), 0 4px 16px rgba(13, 27, 42, .05);
  --display: 'Barlow Condensed', 'Arial Narrow', system-ui, sans-serif;
  --body: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b131c;
    --surface: #121d29;
    --surface-2: #192634;
    --ink: #eef2f5;
    --ink-2: #b4bec8;
    --ink-3: #7f8b97;
    --line: #243344;
    --accent: #ff4d5e;
    --win: #4cc27e;
    --win-bg: #143224;
    --otw: #77c495;
    --otl: #e3a24a;
    --loss: #ff6b5b;
    --loss-bg: #3a1a18;
    --hl: #2f2a14;
    --play: #eef2f5;
    --play-ink: #0b131c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 var(--body);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: inherit; }
img { display: block; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: #0d1b2a;
  color: #fff;
  border-bottom: 3px solid var(--accent);
}
.topbar-inner {
  max-width: 1080px; margin: 0 auto;
  padding: 10px 16px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.brand {
  font: 700 22px/1 var(--display);
  letter-spacing: .02em; text-transform: uppercase; text-decoration: none;
}
.brand span { color: var(--accent); }
.league-switch { display: flex; background: rgba(255,255,255,.08); border-radius: 999px; padding: 3px; }
.league-switch button {
  border: 0; background: transparent; color: #cfd6dd;
  font: 600 13px/1 var(--body); padding: 7px 14px; border-radius: 999px; cursor: pointer;
}
.league-switch button[aria-selected="true"] { background: #fff; color: #0d1b2a; }
.team-select-wrap { margin-left: auto; flex: 1 1 200px; max-width: 280px; }
#team-select {
  width: 100%;
  appearance: none;
  background: rgba(255,255,255,.08) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%23fff' stroke-width='2'/%3E%3C/svg%3E") no-repeat right 12px center;
  color: #fff; border: 1px solid rgba(255,255,255,.18); border-radius: 10px;
  font: 500 14px var(--body); padding: 9px 34px 9px 12px;
}
#team-select option { color: #0d1b2a; }

/* ---------- Layout ---------- */
main { flex: 1; width: 100%; max-width: 1080px; margin: 0 auto; padding: 20px 16px 40px; }
.loading, .error { padding: 60px 0; text-align: center; color: var(--ink-2); }
.error button { margin-top: 12px; }
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
h2.section {
  font: 700 20px/1.1 var(--display); text-transform: uppercase; letter-spacing: .03em;
  margin: 28px 0 10px;
}

/* ---------- Team picker ---------- */
.picker-intro { margin: 8px 0 18px; }
.picker-intro h1 { font: 700 34px/1 var(--display); text-transform: uppercase; margin: 0 0 6px; }
.picker-intro p { margin: 0; color: var(--ink-2); }
.team-grid {
  display: grid; gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.team-tile {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 18px 10px 14px; text-decoration: none; text-align: center;
  transition: transform .12s ease, border-color .12s ease;
}
.team-tile:hover { transform: translateY(-2px); border-color: var(--ink-3); }
.team-tile img { width: 56px; height: 56px; object-fit: contain; }
.team-tile .nm { font-weight: 600; font-size: 14px; }
.team-tile .rk { font-size: 12px; color: var(--ink-3); }

/* ---------- Omgång ---------- */
.round { overflow: hidden; }
.round-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 14px; }
.round-head > div { text-align: center; }
.round-head h2 { margin: 0; font: 700 20px/1 var(--display); text-transform: uppercase; letter-spacing: .03em; }
.round-head span { font-size: 12px; color: var(--ink-3); }
.round-head .btn { font-size: 18px; padding: 4px 12px; }
.round-head .btn:disabled { opacity: .35; cursor: default; }
.rgame {
  display: grid; align-items: center; gap: 10px;
  grid-template-columns: 90px 1fr 84px 1fr 84px;
  grid-template-areas: "date home mid away links";
  padding: 9px 14px; border-top: 1px solid var(--line);
}
.rdate { grid-area: date; font-size: 12px; color: var(--ink-2); }
.rgame .rt:first-of-type { grid-area: home; justify-content: flex-end; text-align: right; }
.rgame .rt:last-of-type { grid-area: away; }
.rgame .rt:first-of-type img { order: 2; }
.rt { display: flex; align-items: center; gap: 8px; text-decoration: none; min-width: 0; font-weight: 500; }
.rt span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rt:hover span { text-decoration: underline; }
.rt.won { font-weight: 700; }
.rt img { width: 26px; height: 26px; object-fit: contain; flex: none; }
.rmid { grid-area: mid; text-align: center; }
.rs { font: 700 20px/1 var(--display); display: inline-flex; align-items: center; gap: 4px; }
.rs.live { color: var(--live); }
.rs small { font: 600 10px var(--body); color: var(--ink-3); }
.rtime { font: 700 16px/1 var(--display); color: var(--ink-2); }
.rlinks { grid-area: links; display: flex; justify-content: flex-end; }
@media (max-width: 640px) {
  .rgame {
    grid-template-columns: 1fr auto 1fr;
    grid-template-areas: "date date date" "home mid away" "links links links";
    row-gap: 6px;
  }
  .rdate { text-align: center; }
  .rt { flex-direction: column; gap: 4px; text-align: center; font-size: 13px; }
  .rgame .rt:first-of-type { justify-content: center; text-align: center; }
  .rgame .rt:first-of-type img { order: 0; }
  .rt span { white-space: normal; }
  .rlinks { justify-content: center; }
}

/* ---------- Hero ---------- */
.hero { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 860px) { .hero { grid-template-columns: 1.15fr 1fr; } }
.team-head { padding: 20px; display: flex; gap: 18px; align-items: center; }
.team-head img { width: 84px; height: 84px; object-fit: contain; flex: none; }
.team-head h1 { font: 700 36px/1 var(--display); text-transform: uppercase; margin: 0 0 6px; }
.team-meta { color: var(--ink-2); font-size: 14px; }
.team-meta strong { color: var(--ink); }
.kpis { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 10px; font-size: 13px; color: var(--ink-2); }
.kpis b { font: 700 18px/1 var(--display); color: var(--ink); margin-right: 3px; }
.form { display: flex; gap: 4px; margin-top: 12px; align-items: center; }
.form .lbl { font-size: 12px; color: var(--ink-3); margin-right: 4px; }
.pill {
  display: inline-grid; place-items: center;
  min-width: 24px; height: 24px; padding: 0 5px; border-radius: 6px;
  font: 700 12px/1 var(--body); color: #fff;
}
.pill.W { background: var(--win); }
.pill.OTW { background: var(--otw); }
.pill.OTL { background: var(--otl); }
.pill.L { background: var(--loss); }

.next { padding: 18px 20px; display: flex; flex-direction: column; gap: 12px; }
.next .kicker { font: 700 13px/1 var(--display); letter-spacing: .08em; text-transform: uppercase; color: var(--accent); display: flex; align-items: center; gap: 8px; }
.matchup { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; }
.matchup .side { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; font-weight: 600; font-size: 14px; }
.matchup .side img { width: 48px; height: 48px; object-fit: contain; }
.matchup .mid { text-align: center; }
.matchup .time { font: 700 30px/1 var(--display); }
.matchup .date { font-size: 13px; color: var(--ink-2); margin-top: 4px; }
.matchup .score { font: 700 40px/1 var(--display); }
.next .venue { font-size: 13px; color: var(--ink-3); text-align: center; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border-radius: 999px; padding: 8px 14px;
  font: 600 13px/1 var(--body); text-decoration: none; white-space: nowrap;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer;
}
.btn:hover { border-color: var(--ink-3); }
.btn.play { background: var(--play); color: var(--play-ink); border-color: var(--play); }
.btn.play.live { background: var(--live); border-color: var(--live); color: #fff; }
.btn.sm { padding: 6px 10px; font-size: 12px; }
.btn svg { width: 12px; height: 12px; }

.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--live); animation: pulse 1.4s infinite; display: inline-block; }
@keyframes pulse { 50% { opacity: .3; } }
@media (prefers-reduced-motion: reduce) { .live-dot { animation: none; } .team-tile { transition: none; } }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; margin: 26px 0 14px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tabs button {
  border: 0; background: none; color: var(--ink-2); cursor: pointer;
  font: 700 16px/1 var(--display); text-transform: uppercase; letter-spacing: .04em;
  padding: 12px 12px 10px; border-bottom: 3px solid transparent; margin-bottom: -1px; white-space: nowrap;
}
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }

/* ---------- Game list ---------- */
.games { overflow: hidden; }
.games-head { display: flex; align-items: baseline; justify-content: space-between; padding: 14px 16px 8px; }
.games-head h3 { margin: 0; font: 700 17px/1 var(--display); text-transform: uppercase; letter-spacing: .03em; }
.games-head span { font-size: 12px; color: var(--ink-3); }
.game {
  display: grid; align-items: center; gap: 10px;
  grid-template-columns: 74px 1fr auto;
  padding: 10px 16px; border-top: 1px solid var(--line);
}
.game .when { font-size: 12px; color: var(--ink-2); line-height: 1.3; }
.game .when b { display: block; color: var(--ink); font-size: 13px; }
.game .opp { display: flex; align-items: center; gap: 10px; min-width: 0; }
.game .opp img { width: 28px; height: 28px; object-fit: contain; flex: none; }
.game .opp .t { min-width: 0; }
.game .opp .n { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.game .opp .ha { font-size: 11px; color: var(--ink-3); text-transform: uppercase; letter-spacing: .05em; }
.game .right { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.res {
  font: 700 18px/1 var(--display); padding: 5px 8px; border-radius: 8px; min-width: 56px; text-align: center;
}
.res.W { background: var(--win-bg); color: var(--win); }
.res.L { background: var(--loss-bg); color: var(--loss); }
.res small { font: 600 10px var(--body); margin-left: 3px; }
.game .links { display: flex; gap: 6px; }
@media (max-width: 560px) {
  .game {
    grid-template-columns: 1fr auto;
    grid-template-areas: "when right" "opp right";
    row-gap: 4px; padding: 10px 14px;
  }
  .game .when { grid-area: when; display: flex; gap: 6px; font-size: 12px; }
  .game .when b { display: inline; font-size: 12px; font-weight: 600; }
  .game .opp { grid-area: opp; }
  .game .right { grid-area: right; flex-direction: column; align-items: flex-end; gap: 6px; }
  .team-head { padding: 16px; gap: 14px; }
  .team-head img { width: 64px; height: 64px; }
  .team-head h1 { font-size: 30px; }
}
.two-col { display: grid; gap: 14px; }
@media (min-width: 900px) { .two-col { grid-template-columns: 1fr 1fr; align-items: start; } }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 9px 10px; text-align: right; white-space: nowrap; }
th:first-child, td:first-child { padding-left: 16px; }
th:last-child, td:last-child { padding-right: 16px; }
th {
  font: 600 11px/1 var(--body); text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3);
  border-bottom: 1px solid var(--line); background: var(--surface);
}
th.sortable { cursor: pointer; user-select: none; }
th.sorted { color: var(--ink); }
th.sorted::after { content: ' ▼'; font-size: 8px; }
td { border-bottom: 1px solid var(--line); }
tr:last-child td { border-bottom: 0; }
td.l, th.l { text-align: left; }
td.team-cell { display: flex; align-items: center; gap: 8px; }
td.team-cell img { width: 22px; height: 22px; object-fit: contain; }
td.team-cell a { text-decoration: none; font-weight: 500; }
td.team-cell a:hover { text-decoration: underline; }
td.strong { font-weight: 700; }
tr.me td { background: var(--hl); }
tr.cut td { border-bottom: 2px solid var(--ink-3); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; padding: 10px 16px 14px; font-size: 12px; color: var(--ink-3); border-top: 1px solid var(--line); }
.num { color: var(--ink-3); font-size: 12px; margin-right: 4px; }
.tag { font-size: 10px; font-weight: 600; color: var(--ink-3); border: 1px solid var(--line); border-radius: 4px; padding: 1px 4px; margin-left: 6px; }
.empty { padding: 24px 16px; color: var(--ink-3); text-align: center; }

/* ---------- Leaders ---------- */
.leaders { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.leader { padding: 16px; }
.leader h4 { margin: 0 0 10px; font: 700 15px/1 var(--display); text-transform: uppercase; letter-spacing: .05em; color: var(--ink-2); }
.leader ol { list-style: none; margin: 0; padding: 0; }
.leader li { display: flex; justify-content: space-between; gap: 8px; padding: 6px 0; border-top: 1px solid var(--line); font-size: 14px; }
.leader li:first-child { border-top: 0; }
.leader li:first-child .v { font-size: 26px; }
.leader .v { font: 700 18px/1 var(--display); }
.leader .sub { color: var(--ink-3); font-size: 12px; }

.footer { text-align: center; font-size: 12px; color: var(--ink-3); padding: 18px 16px 28px; }
.footer p { margin: 0; }
