:root {
  --bg: #0b1220;
  --bg-elev: #131c2e;
  --bg-elev-2: #1b2740;
  --line: #25324d;
  --text: #e8edf6;
  --muted: #93a2c0;
  --accent: #4f8cff;
  --accent-2: #22d3a6;
  --men: #4f8cff;
  --women: #ff5c93;
  --bronze: #d08a4e;
  --live: #ff4d6d;
  --gold: #f5c451;
  --win: #22d3a6;
  --radius: 14px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: linear-gradient(180deg, #0e1830, #0b1220);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.header-inner {
  max-width: 980px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1; }
.brand-logo {
  width: 46px; height: 46px;
  display: grid; place-items: center;
  background: #fff;
  border-radius: 12px;
  flex: none;
}
.brand-logo img { width: 100%; height: 100%; object-fit: contain; padding: 4px; box-sizing: border-box; }
.brand-text { min-width: 0; }
.brand-text h1 { font-size: 17px; margin: 0; letter-spacing: 0.2px; }
.event-name { margin: 2px 0 0; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.event-sub { margin: 1px 0 0; font-size: 11px; color: var(--muted); opacity: 0.8; }

.header-actions { display: flex; align-items: center; gap: 8px; flex: none; }
.updated { font-size: 11px; color: var(--muted); min-width: 0; }
.live-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--live);
  box-shadow: 0 0 0 0 rgba(255, 77, 109, 0.6);
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(255, 77, 109, 0.5); }
  70% { box-shadow: 0 0 0 8px rgba(255, 77, 109, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 77, 109, 0); }
}
.icon-btn {
  background: var(--bg-elev-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  width: 38px; height: 38px;
  font-size: 18px;
  cursor: pointer;
  transition: transform 0.2s, background 0.2s;
}
.icon-btn:active { transform: scale(0.92); }
.icon-btn.spin { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.install-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

/* Category pills */
.category-bar {
  position: sticky;
  top: 0;
  z-index: 15;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.category-pills {
  max-width: 980px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 16px;
}
.cat-row {
  display: flex;
  align-items: center;
  min-width: 0;
}
.cat-row-pills {
  flex: 1;
  min-width: 0;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
}
.cat-row-pills::-webkit-scrollbar { display: none; }
.pill {
  flex: none;
  background: var(--bg-elev);
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.15s;
}
.pill:hover { filter: brightness(1.2); }

/* Gender colour-coding (pink = women, blue = men) */
.pill--women { color: var(--women); border-color: rgba(255, 92, 147, 0.4); }
.pill--men { color: var(--men); border-color: rgba(79, 140, 255, 0.4); }
.pill--other { color: var(--text); }
.pill.is-active { color: #fff; }
.pill--women.is-active { background: var(--women); border-color: var(--women); }
.pill--men.is-active { background: var(--men); border-color: var(--men); }
.pill--other.is-active { background: var(--accent); border-color: var(--accent); }

/* Content */
.content { max-width: 980px; margin: 0 auto; padding: 16px; }

.view-tabs {
  display: flex;
  gap: 6px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 5px;
  margin-bottom: 16px;
}
.view-tab {
  flex: 1;
  background: transparent;
  color: var(--muted);
  border: none;
  border-radius: 9px;
  padding: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.view-tab.is-active { background: var(--bg-elev-2); color: var(--text); }

.banner {
  background: rgba(245, 196, 81, 0.12);
  border: 1px solid rgba(245, 196, 81, 0.4);
  color: var(--gold);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 13px;
  margin-bottom: 16px;
}

/* Standings */
.section-title {
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin: 0 0 10px;
}
.table-wrap {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}
table.standings {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
table.standings th, table.standings td {
  padding: 11px 8px;
  text-align: center;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
table.standings th {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  font-weight: 600;
}
table.standings td.team, table.standings th.team {
  text-align: left;
  white-space: normal;
  width: 100%;
}
table.standings tr:last-child td { border-bottom: none; }
.pos {
  display: inline-grid;
  place-items: center;
  width: 22px; height: 22px;
  border-radius: 7px;
  background: var(--bg-elev-2);
  font-size: 12px;
  font-weight: 700;
}
tr.qualified .pos { background: var(--accent); color: #fff; }
.team-name { font-weight: 600; }
.flag { margin-right: 7px; }
.pts-col { font-weight: 800; color: var(--accent-2); }
.dim { color: var(--muted); }

/* Matches */
.match-filter {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  overflow-x: auto;
  scrollbar-width: none;
}
.match-filter::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.chip.is-active { background: var(--bg-elev-2); color: var(--text); border-color: var(--accent); }

.day-group { margin-bottom: 22px; }
.day-head {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 0 2px 10px;
  position: sticky;
  top: 56px;
}
.match {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}
.match.live { border-color: var(--live); box-shadow: 0 0 0 1px var(--live), var(--shadow); }
.match-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 10px;
  gap: 8px;
}
.match-meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.tag {
  background: var(--bg-elev-2);
  border-radius: 6px;
  padding: 2px 7px;
  font-size: 10px;
  font-weight: 600;
}
.status {
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.status.notstarted { background: var(--bg-elev-2); color: var(--muted); }
.status.starting { background: rgba(245, 196, 81, 0.18); color: var(--gold); }
.status.inprogress { background: rgba(255, 77, 109, 0.18); color: var(--live); }
.status.finished { background: rgba(34, 211, 166, 0.16); color: var(--accent-2); }

.match-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 5px 0;
}
.match-row .side { display: flex; align-items: center; gap: 8px; font-size: 15px; min-width: 0; }
.match-row .side .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.match-row.winner .name { color: var(--win); }
.match-row.winner::after { content: "▸"; }
.set-scores { display: flex; gap: 7px; align-items: center; }
.set-scores .s {
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  color: var(--muted);
  min-width: 16px;
  text-align: center;
}
.set-scores .s.won { color: var(--text); font-weight: 700; }
.big-sets {
  font-size: 22px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  min-width: 26px;
  text-align: right;
}
.big-sets.win { color: var(--win); }
.match-divider { height: 1px; background: var(--line); margin: 4px 0; }
.setline { margin-top: 8px; border-top: 1px dashed var(--line); padding-top: 8px; }

.loading { text-align: center; color: var(--muted); padding: 40px 0; font-size: 14px; }
.empty { text-align: center; color: var(--muted); padding: 30px 0; font-size: 14px; }

.app-footer {
  max-width: 980px;
  margin: 0 auto;
  padding: 8px 16px 28px;
  color: var(--muted);
  font-size: 11px;
  text-align: center;
  opacity: 0.7;
}

/* Head-to-head cross table */
.cross-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.cross-bar .section-title { margin: 0; }
.cross-toggle { display: flex; gap: 6px; }
.cross-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-elev);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}
.cross-wrap::-webkit-scrollbar { height: 8px; }
.cross-wrap::-webkit-scrollbar-thumb { background: var(--bg-elev-2); border-radius: 8px; }
table.cross {
  border-collapse: collapse;
  font-size: 13px;
  width: max-content;
  min-width: 100%;
  font-variant-numeric: tabular-nums;
}
table.cross th, table.cross td {
  padding: 9px 11px;
  text-align: center;
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  white-space: nowrap;
}
table.cross tr:last-child td, table.cross tr:last-child th { border-bottom: none; }
table.cross thead th {
  font-size: 10px;
  color: var(--muted);
  font-weight: 700;
  line-height: 1.4;
}
table.cross thead th .flag { margin: 0; font-size: 14px; }
table.cross .corner, table.cross .rowhead {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--bg-elev);
}
table.cross thead .corner { z-index: 3; }
table.cross .rowhead {
  text-align: left;
  font-weight: 600;
  font-size: 13px;
  border-right: 2px solid var(--line);
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
}
table.cross td.self { background: var(--bg-elev-2); }
table.cross td.win { color: var(--win); font-weight: 700; }
table.cross td.loss { color: var(--text); }
table.cross td.np { color: var(--muted); opacity: 0.45; }
table.cross td.live { color: var(--gold); font-weight: 700; }
.cell-dot {
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--gold);
  margin-left: 5px;
  vertical-align: middle;
  animation: blink 1.2s infinite;
}
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.2; } }

/* Knockout bracket */
.section-title.sub { margin-top: 18px; }
.bracket {
  display: flex;
  gap: 26px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding: 4px 2px 14px;
  margin-bottom: 8px;
}
.bracket::-webkit-scrollbar { height: 8px; }
.bracket::-webkit-scrollbar-thumb { background: var(--bg-elev-2); border-radius: 8px; }
.bround {
  display: flex;
  flex-direction: column;
  flex: 1 0 152px;
  min-width: 152px;
}
.bround-cards {
  flex: 1;
  display: flex;
  flex-direction: column;
}
.bslot {
  flex: 1;
  display: flex;
  align-items: center;
  position: relative;
}
.bround-cards--final { justify-content: center; }
.bround-cards--final > .bmatch { margin: 0; }
.bronze-spacer, .gold-spacer { visibility: hidden; pointer-events: none; }

/* Bracket connector lines */
.bround:not(:last-child) .bslot::after {            /* horizontal line out of each match */
  content: "";
  position: absolute;
  left: 100%;
  top: 50%;
  width: 13px;
  height: 2px;
  background: var(--line);
}
.bround:not(:last-child) .bslot::before {           /* vertical line merging each pair */
  content: "";
  position: absolute;
  left: 100%;
  margin-left: 13px;
  width: 2px;
  height: 50%;
  background: var(--line);
}
.bround:not(:last-child) .bslot:nth-child(odd)::before { top: 50%; }
.bround:not(:last-child) .bslot:nth-child(even)::before { bottom: 50%; }
.bround:not(:first-child) .bslot .bmatch::before,
.bround:not(:first-child) .bround-cards--final .gold-block > .bmatch::before { /* line into the next match */
  content: "";
  position: absolute;
  right: 100%;
  top: 50%;
  width: 13px;
  height: 2px;
  background: var(--line);
}
.bround-title {
  flex: none;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  font-weight: 700;
  text-align: center;
  margin-bottom: 8px;
}
.bround-title.bronze-title { margin: 4px 0 8px; color: var(--bronze); }
.bround-title.gold-title { margin: 4px 0 8px; color: var(--gold); }
.bmatch {
  position: relative;
  width: 100%;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 9px;
  margin: 6px 0;
  min-height: 48px;
  box-sizing: border-box;
  font-size: 12px;
  box-shadow: var(--shadow);
}
.bmatch.empty { opacity: 0.4; text-align: center; padding: 14px 9px; }
.bmatch.live { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold); }
.bteam {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 0;
}
.bteam + .bteam { border-top: 1px dashed var(--line); }
.bteam .bn { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.bteam.win .bn { color: var(--win); font-weight: 700; }
.bsc { flex: none; display: inline-flex; align-items: baseline; gap: 5px; }
.bteam .bs { font-weight: 800; font-variant-numeric: tabular-nums; }
.bteam .bp { font-size: 10px; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 14px; text-align: right; }

/* Cards (cautions) */
.card-team {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-team-head {
  font-weight: 700;
  font-size: 13px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
}
.card-player {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}
.card-player:last-child { border-bottom: none; }
.cp-name { font-size: 14px; min-width: 0; }
.cp-games { font-size: 11px; margin-top: 2px; }
.cp-badges { display: flex; gap: 6px; flex: none; }
.badge {
  font-size: 11px;
  font-weight: 800;
  padding: 3px 8px;
  border-radius: 6px;
  letter-spacing: 0.3px;
}
.badge.y { background: var(--gold); color: #3a2e0a; }
.badge.r { background: #e23b3b; color: #fff; }
.badge.yr { background: linear-gradient(100deg, var(--gold) 0 48%, #e23b3b 52% 100%); color: #fff; }

/* Update available toast */
.update-toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-elev-2);
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 8px 8px 8px 18px;
  box-shadow: var(--shadow);
  font-size: 13px;
  font-weight: 600;
  max-width: calc(100vw - 24px);
  animation: toast-in 0.3s ease;
}
.update-toast[hidden] { display: none; }
.update-text { white-space: nowrap; }
.update-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 9px 18px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  flex: none;
}
.update-btn:active { transform: scale(0.95); }
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 14px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

@media (min-width: 620px) {
  .brand-text h1 { font-size: 19px; }
  .event-name { font-size: 13px; }
}
