:root {
  --bg: #eef2f8;
  --surface: #ffffff;
  --surface-2: #f5f7fb;
  --text: #111a2e;
  --muted: #55627a;
  --hairline: #dde3ee;
  --brand: #0b3d91;
  --brand-2: #1556c5;
  --brand-soft: #e3ecfb;
  --on-brand: #ffffff;
  --accent: #c8102e;
  --gold: #8a6100;
  --bronze: #8b4a1c;
  --ok: #157f3b;
  --warn-bg: #fff1c7;
  --warn-text: #563b00;
  --focus: #ffbf47;
  --radius: 16px;
  --tabbar-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --shadow: 0 1px 2px rgba(17, 26, 46, .06), 0 2px 8px rgba(17, 26, 46, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0f1a;
    --surface: #151d2c;
    --surface-2: #1c2638;
    --text: #edf2fa;
    --muted: #a3b0c5;
    --hairline: #29354b;
    --brand: #0f2f6e;
    --brand-2: #8fb4ff;
    --brand-soft: #1d2d4f;
    --accent: #ff8a9a;
    --gold: #f1c75b;
    --bronze: #e3a173;
    --ok: #5ee08d;
    --warn-bg: #46340a;
    --warn-text: #ffe7a3;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 1.0625rem;
  line-height: 1.45;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
a { color: var(--brand-2); }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 8px; }
.skip-link {
  position: absolute; left: 8px; top: -80px; z-index: 100;
  background: var(--focus); color: #000; padding: 10px 14px; border-radius: 10px; font-weight: 700;
}
.skip-link:focus { top: calc(8px + var(--safe-t)); }

/* ---------- App bar ---------- */
.appbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--brand); color: var(--on-brand);
  padding-top: var(--safe-t);
}
.appbar-row {
  max-width: 960px; margin: 0 auto; height: 52px; padding: 0 16px;
  display: flex; align-items: center; gap: 12px;
}
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; font-weight: 800; font-size: 1.1rem; letter-spacing: -.01em; }
.brand img { border-radius: 8px; }
.net-pill {
  margin-left: auto; display: inline-flex; align-items: center; gap: 6px;
  font-size: .8rem; font-weight: 700; padding: 4px 10px; border-radius: 999px;
  background: rgba(255,255,255,.16); white-space: nowrap;
}
.net-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: #4ade80; box-shadow: 0 0 0 3px rgba(74,222,128,.25); }
.net-pill[data-state="offline"] { background: var(--warn-bg); color: var(--warn-text); }
.net-pill[data-state="offline"] .dot { background: transparent; border: 2px solid currentColor; box-shadow: none; }
.net-banner {
  background: var(--warn-bg); color: var(--warn-text);
  font-size: .9rem; font-weight: 600; text-align: center; padding: 8px 16px;
}
.net-banner.back-online { background: #d7f5e2; color: #0d4a26; }

/* ---------- Tab bar (bottom on phones) ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabbar-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(16px); backdrop-filter: saturate(180%) blur(16px);
  border-top: 1px solid var(--hairline);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); text-decoration: none; font-size: .72rem; font-weight: 600;
  user-select: none; -webkit-user-select: none;
}
.tabbar svg {
  width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}
.tabbar a[aria-current="page"] { color: var(--brand-2); }
.tabbar a[aria-current="page"] svg { fill: color-mix(in srgb, currentColor 18%, transparent); stroke-width: 2.2; }
.tabbar a:active svg { transform: scale(.9); }

main {
  max-width: 960px; margin: 0 auto; outline: none;
  padding: 8px 16px calc(var(--tabbar-h) + var(--safe-b) + 24px);
}

/* Larger screens: tabs move into the top bar */
@media (min-width: 760px) {
  .tabbar {
    position: static; display: flex; height: auto; padding: 0; gap: 4px;
    background: none; border: 0; backdrop-filter: none; -webkit-backdrop-filter: none;
    margin-left: 12px;
  }
  .tabbar a { flex-direction: row; gap: 6px; color: rgba(255,255,255,.85); font-size: .95rem; padding: 8px 12px; border-radius: 999px; }
  .tabbar svg { width: 20px; height: 20px; }
  .tabbar a:hover { background: rgba(255,255,255,.12); }
  .tabbar a[aria-current="page"] { background: #fff; color: #0b3d91; }
  .appbar-row { height: 60px; }
  main { padding-bottom: 40px; }
}

/* ---------- Page header ---------- */
.page-title { font-size: 2rem; line-height: 1.15; letter-spacing: -.02em; margin: 16px 0 4px; font-weight: 800; }
.page-sub { color: var(--muted); margin: 0 0 12px; font-size: .95rem; }
h2.section { font-size: .8rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin: 24px 4px 8px; font-weight: 700; }

/* ---------- Segmented controls ---------- */
.controls { display: grid; gap: 10px; margin-bottom: 6px; position: sticky; top: calc(52px + var(--safe-t)); z-index: 5; background: var(--bg); padding: 8px 0; }
@media (min-width: 760px) { .controls { top: calc(60px + var(--safe-t)); } }
.segmented {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: var(--surface-2); border: 1px solid var(--hairline); border-radius: 12px; padding: 3px; gap: 3px;
}
.segmented button {
  border: 0; background: none; border-radius: 9px; min-height: 40px; padding: 6px 8px;
  font-weight: 600; font-size: .92rem; color: var(--muted); cursor: pointer; line-height: 1.15;
}
.segmented button small { display: block; font-weight: 500; font-size: .75rem; }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.15); }
@media (prefers-color-scheme: dark) { .segmented button[aria-pressed="true"] { background: #2d3b55; } }
.row-controls { display: flex; gap: 10px; align-items: center; }
.row-controls .segmented { flex: 1; }
.select-wrap { position: relative; }
.select-wrap select {
  appearance: none; -webkit-appearance: none; font: inherit; font-size: .92rem; font-weight: 600;
  min-height: 46px; padding: 8px 34px 8px 12px; border-radius: 12px; width: 100%;
  border: 1px solid var(--hairline); background: var(--surface-2); color: var(--text);
}
.select-wrap::after {
  content: ""; position: absolute; right: 13px; top: 50%; width: 8px; height: 8px; margin-top: -6px;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); pointer-events: none;
}

/* ---------- Cards & lists ---------- */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--hairline); }
.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border-radius: var(--radius); border: 1px solid var(--hairline); box-shadow: var(--shadow); overflow: hidden; }
.list > li + li { border-top: 1px solid var(--hairline); }

/* Hero */
.hero {
  margin-top: 14px; padding: 20px; border-radius: 20px; color: #fff;
  background: radial-gradient(120% 140% at 100% 0%, #2f6fe0 0%, #0b3d91 55%, #08285f 100%);
  position: relative; overflow: hidden;
}
.hero::after {
  content: ""; position: absolute; right: -40px; bottom: -60px; width: 200px; height: 200px; border-radius: 50%;
  border: 18px solid rgba(255,255,255,.07);
}
.hero h1 { margin: 0; font-size: 1.9rem; letter-spacing: -.02em; line-height: 1.1; }
.hero p { margin: 6px 0 0; opacity: .92; }
.hero .stat-row { display: flex; gap: 22px; margin-top: 18px; }
.hero .stat b { display: block; font-size: 1.5rem; line-height: 1; }
.hero .stat span { font-size: .8rem; opacity: .88; }

/* Quick tiles */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile {
  display: flex; flex-direction: column; gap: 4px; padding: 14px; min-height: 84px;
  text-decoration: none; color: var(--text); background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.tile b { font-size: 1rem; }
.tile span { color: var(--muted); font-size: .85rem; }
.tile:active { transform: scale(.98); }

/* Info rows */
.info-row { padding: 14px 16px; }
.info-row h3 { margin: 0 0 4px; font-size: 1rem; }
.info-row p, .info-row ul { margin: 0; color: var(--muted); font-size: .95rem; }
.info-row ul { padding-left: 1.1em; }
.info-row li { margin: 2px 0; }
.link-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; min-height: 52px; text-decoration: none; color: var(--text); }
.link-row .val { color: var(--brand-2); font-weight: 600; }

/* ---------- Game cards ---------- */
.games { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.game { padding: 12px 14px; }
.game-top { display: flex; align-items: center; gap: 8px; font-size: .82rem; color: var(--muted); margin-bottom: 8px; }
.game-top .time { font-weight: 800; color: var(--text); font-size: .95rem; }
.game-top .spacer { flex: 1; }
.team-line { display: flex; align-items: center; gap: 10px; min-height: 32px; }
.team-line .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.team-line .score { font-weight: 800; font-size: 1.25rem; font-variant-numeric: tabular-nums; min-width: 1.4em; text-align: right; }
.team-line.loser { color: var(--muted); }
.team-line.winner .name { font-weight: 700; }
.placeholder .name { color: var(--muted); font-style: italic; }
.game-foot { margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--hairline); font-size: .85rem; color: var(--muted); }
.game-foot a { color: inherit; }
.game.next { border-color: var(--brand-2); box-shadow: 0 0 0 1px var(--brand-2), var(--shadow); }
.crest {
  flex: none; width: 28px; height: 28px; border-radius: 8px; color: #fff;
  display: grid; place-items: center; font-size: .7rem; font-weight: 800; letter-spacing: .02em;
}
.crest.sm { width: 22px; height: 22px; border-radius: 6px; font-size: .6rem; }
.crest.tbd { background: var(--surface-2); color: var(--muted); border: 1px dashed var(--muted); }
.chip { display: inline-flex; align-items: center; font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; text-transform: uppercase; letter-spacing: .04em; }
.chip.final { background: var(--surface-2); color: var(--muted); border: 1px solid var(--hairline); }
.chip.upcoming { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); }
.chip.next { background: var(--brand-2); color: var(--surface); }
.chip.gold { background: color-mix(in srgb, var(--gold) 16%, transparent); color: var(--gold); }
.chip.bronze { background: color-mix(in srgb, var(--bronze) 16%, transparent); color: var(--bronze); }
.empty { text-align: center; color: var(--muted); padding: 32px 16px; }

/* ---------- Standings ---------- */
.standings { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.standings caption { text-align: left; font-weight: 800; font-size: 1.05rem; padding: 14px 14px 2px; }
.standings th, .standings td { padding: 12px 6px; text-align: center; border-bottom: 1px solid var(--hairline); }
.standings thead th { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; padding-top: 10px; padding-bottom: 8px; font-weight: 700; }
.standings tbody tr:last-child > * { border-bottom: 0; }
.standings .team-col { text-align: left; padding-left: 14px; }
.standings tbody th { font-weight: 600; }
.standings .team-cell { display: flex; align-items: center; gap: 10px; }
.standings .rank { width: 1em; color: var(--muted); font-weight: 700; flex: none; }
.standings .pts { font-weight: 800; padding-right: 14px; }
.standings .cutline > * { border-bottom: 2px solid var(--brand-2); }
.standings .wide { display: none; }
@media (min-width: 560px) { .standings .wide { display: table-cell; } }
abbr[title] { text-decoration: none; }
.legend { color: var(--muted); font-size: .85rem; margin: 10px 4px; }
.legend .bar { display: inline-block; width: 18px; height: 3px; background: var(--brand-2); vertical-align: middle; margin-right: 6px; border-radius: 2px; }

/* ---------- Leaders ---------- */
.leader { display: flex; align-items: center; gap: 12px; padding: 12px 14px; }
.leader .rank { width: 1.6em; text-align: center; font-weight: 800; color: var(--muted); flex: none; }
.leader.top .rank { color: var(--gold); }
.leader .who { flex: 1; min-width: 0; }
.leader .who b { display: block; }
.leader .who > span { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.leader .big { text-align: right; flex: none; }
.leader .big b { display: block; font-size: 1.3rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.leader .big span { font-size: .75rem; color: var(--muted); white-space: nowrap; }

/* ---------- Arenas ---------- */
.arena { overflow: hidden; margin-bottom: 14px; }
.arena-head { padding: 16px; background: var(--brand-soft); }
.arena-head h2 { margin: 0; font-size: 1.2rem; }
.arena-head p { margin: 4px 0 0; color: var(--muted); font-size: .92rem; }
.arena .info-row + .info-row { border-top: 1px solid var(--hairline); }
.amenities { display: flex; flex-wrap: wrap; gap: 6px; list-style: none; padding: 0 !important; margin-top: 6px !important; }
.amenities li { background: var(--surface-2); border: 1px solid var(--hairline); border-radius: 999px; padding: 3px 10px; font-size: .85rem; color: var(--text); }

.foot-note { color: var(--muted); font-size: .82rem; text-align: center; margin: 24px 8px 0; }
.loading { color: var(--muted); padding: 24px 0; }

@media (prefers-reduced-motion: no-preference) {
  .view-enter { animation: enter .18s ease-out; }
  @keyframes enter { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
  .segmented button, .tabbar a, .tile { transition: background-color .15s, color .15s, transform .1s; }
}
@media (min-width: 760px) {
  .tiles { grid-template-columns: repeat(4, 1fr); }
  .games { grid-template-columns: 1fr 1fr; }
  .arenas-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
  .arenas-grid .arena { margin: 0; }
}

.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;
}
