:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #0f1419;
  --text-2: #5b6470;
  --line: #e4e7eb;
  --accent: #1463ff;
  --accent-soft: #e6eeff;
  --live: #0a8f55;
  --live-soft: #e3f6ec;
  --danger: #c62828;
  --danger-soft: #fdecec;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --radius: 14px;
  --header-blur: rgba(246, 247, 249, .82);
  /* level colours */
  --lv-1000: #b7791f; --lv-750: #7c3aed; --lv-500: #1463ff; --lv-300: #0e9f9a; --lv-100: #3b8f3b;
  --lv-finals: #111827; --lv-grade1: #c62828; --lv-intl: #475569; --lv-future: #8a94a3; --lv-other: #64748b;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0f12;
    --surface: #161a1f;
    --surface-2: #1d2228;
    --text: #eef1f5;
    --text-2: #9aa4b2;
    --line: #262c33;
    --accent: #5b8cff;
    --accent-soft: #1b2740;
    --live: #3ccf8e;
    --live-soft: #13291f;
    --danger: #ff6b6b;
    --danger-soft: #331a1c;
    --shadow: none;
    --header-blur: rgba(13, 15, 18, .82);
    --lv-1000: #e3b341; --lv-750: #a78bfa; --lv-500: #5b8cff; --lv-300: #2dd4bf; --lv-100: #6cc46c;
    --lv-finals: #e5e7eb; --lv-grade1: #ff6b6b; --lv-intl: #94a3b8; --lv-future: #6b7280; --lv-other: #94a3b8;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}
button, input { font: inherit; color: inherit; }
.muted { color: var(--text-2); }
.small { font-size: 12.5px; }

/* ---------- header ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--header-blur);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  backdrop-filter: saturate(180%) blur(18px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.topbar-inner, .filters, main, .footer { max-width: 820px; margin: 0 auto; padding-left: 16px; padding-right: 16px; }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; padding-top: 12px; padding-bottom: 8px; }
.brand { display: flex; align-items: center; gap: 12px; }
.logo { width: 40px; height: 40px; border-radius: 10px; box-shadow: 0 2px 6px rgba(20, 99, 255, .3); flex: none; }
h1 { font-size: 19px; line-height: 1.2; margin: 0; letter-spacing: -.01em; }
#subtitle { margin: 1px 0 0; font-size: 13px; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface);
  display: grid; place-items: center; cursor: pointer;
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.filters { padding-bottom: 10px; display: grid; gap: 8px; }
.chip-row {
  display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch;
  margin: 0 -16px; padding: 0 16px;
}
.chip-row::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 6px 12px; font-size: 14px; font-weight: 500; cursor: pointer; display: inline-flex; gap: 6px; align-items: center;
  transition: background .15s, border-color .15s, color .15s;
}
.chip .n { font-size: 12px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.chip[aria-selected="true"] { background: var(--text); border-color: var(--text); color: var(--bg); }
.chip[aria-selected="true"] .n { color: inherit; opacity: .7; }
.chip:focus-visible, .icon-btn:focus-visible, .card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.search-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.search-row .search { min-width: 200px; }
@media (max-width: 600px) { .search-row .search { flex: 1 1 100%; } .toggle { margin-right: 6px; } }
.search {
  flex: 1; display: flex; align-items: center; gap: 8px; background: var(--surface-2); border-radius: 10px; padding: 0 10px;
}
.search svg { width: 17px; height: 17px; color: var(--text-2); flex: none; }
.search input { border: 0; background: transparent; outline: none; width: 100%; padding: 8px 0; font-size: 15px; }
.toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 13.5px; color: var(--text-2); cursor: pointer; white-space: nowrap; }
.toggle input { accent-color: var(--accent); width: 16px; height: 16px; }

/* ---------- summary ---------- */
.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 16px 0 6px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); min-width: 0; }
.stat .k { font-size: 12px; color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.stat .v { font-size: 22px; font-weight: 700; letter-spacing: -.02em; margin-top: 2px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat .s { font-size: 13px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 520px) {
  .summary { grid-template-columns: 1fr 1fr; }
  .stat.next { grid-column: 1 / -1; order: -1; }
}

/* ---------- list ---------- */
.month { margin-top: 18px; }
.month-head {
  position: sticky; top: var(--sticky-top, 150px); z-index: 2; display: flex; justify-content: space-between; align-items: baseline;
  padding: 8px 2px 6px; background: var(--bg);
}
.month-head h2 { font-size: 15px; margin: 0; letter-spacing: -.01em; }
.month-head span { font-size: 13px; color: var(--text-2); }
.cards { display: grid; gap: 8px; }
.card {
  display: grid; grid-template-columns: 58px 1fr auto; gap: 12px; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px;
  box-shadow: var(--shadow); cursor: pointer; text-align: left; width: 100%;
  transition: transform .08s ease, border-color .15s;
}
.card:hover { border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); }
.card:active { transform: scale(.99); }
.card.cancelled { opacity: .62; }
.card.cancelled .title { text-decoration: line-through; }
.date-tile {
  border-radius: 11px; background: var(--surface-2); text-align: center; padding: 7px 2px; line-height: 1.1;
}
.date-tile .d { font-size: 17px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.date-tile .m { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text-2); margin-top: 2px; }
.card.ongoing .date-tile { background: var(--live-soft); }
.card.ongoing .date-tile .m { color: var(--live); }
.body { min-width: 0; }
.title { font-weight: 600; font-size: 15.5px; letter-spacing: -.01em; line-height: 1.3; }
.flag { margin-right: 6px; }
.place { font-size: 13.5px; color: var(--text-2); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.deadline { font-size: 13px; font-weight: 600; margin-top: 3px; }
.deadline.open { color: var(--accent); }
.deadline.urgent { color: var(--danger); }
.deadline.closed { color: var(--text-2); font-weight: 500; }
.badge.age-U15, .badge.age-U13, .badge.age-U11, .badge.age-U23 { --c: var(--text-2); }
.badges { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 7px; }
.badge {
  font-size: 11.5px; font-weight: 600; border-radius: 6px; padding: 2px 7px; line-height: 1.5;
  background: color-mix(in srgb, var(--c, var(--lv-other)) 13%, transparent); color: var(--c, var(--lv-other));
}
.badge.age-U17 { --c: var(--accent); }
.badge.age-U19 { --c: #d97706; }
.badge.age-Senior { --c: var(--text-2); }
.badge.status-Cancelled { --c: var(--danger); }
.badge.status-Rescheduled, .badge.status-Venue { --c: #d97706; }
.when { text-align: right; font-size: 13px; color: var(--text-2); white-space: nowrap; font-variant-numeric: tabular-nums; }
.when.live { color: var(--live); font-weight: 600; }
.when .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--live); margin-right: 5px; animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { opacity: .35; } }

.empty { text-align: center; padding: 48px 16px; }
.empty-icon { font-size: 40px; }
.empty h2 { font-size: 18px; margin: 10px 0 6px; }
.empty p { max-width: 460px; margin: 0 auto; }

.skeleton { height: 82px; border-radius: var(--radius); background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 50%, var(--surface) 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite; border: 1px solid var(--line); }
@keyframes shimmer { to { background-position: -200% 0; } }

.footer { padding-top: 28px; padding-bottom: 32px; }
.footer p { margin: 4px 0; }

/* ---------- detail sheet ---------- */
.sheet {
  border: 0; padding: 0; width: min(560px, 100%); max-width: 100%; max-height: 88vh; margin: auto auto 0;
  border-radius: 20px 20px 0 0; background: var(--surface); color: var(--text);
  box-shadow: 0 -10px 40px rgba(0, 0, 0, .25);
}
@media (min-width: 700px) { .sheet { margin: auto; border-radius: 20px; } }
.sheet::backdrop { background: rgba(10, 12, 16, .45); }
.sheet[open] { animation: up .22s ease-out; }
@keyframes up { from { transform: translateY(24px); opacity: .6; } }
.sheet-body { padding: 10px 20px calc(20px + env(safe-area-inset-bottom)); }
.grabber { width: 38px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 14px; }
.sheet h2 { font-size: 21px; margin: 0 0 4px; letter-spacing: -.02em; }
.sheet .full { font-size: 13px; color: var(--text-2); margin: 0 0 12px; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; margin: 14px 0 18px; font-size: 14.5px; }
.facts dt { color: var(--text-2); }
.facts dd { margin: 0; }
.actions { display: grid; gap: 8px; }
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px; padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface-2); font-weight: 600; text-decoration: none; color: var(--text); cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn svg { width: 18px; height: 18px; }
