@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap");

:root {
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --bg: #f3f4f6; --surface: #ffffff; --surface-2: #f9fafb;
  --fg: #111827; --fg-2: #374151; --muted: #6b7280;
  --line: #e5e7eb; --line-2: #cbd5e1;
  --accent: #4f46e5; --accent-fg: #ffffff; --accent-soft: #eef2ff;
  --win: #15803d; --win-soft: #dcfce7; --warn: #b45309; --warn-soft: #fef3c7; --danger: #dc2626;
  --gs: #a16207; --gs-soft: #fef3c7; --masters: #6d28d9; --masters-soft: #ede9fe;
  --s500: #0369a1; --s500-soft: #e0f2fe; --s250: #0f766e; --s250-soft: #ccfbf1; --custom: #4b5563; --custom-soft: #e5e7eb;
  --radius: 10px; --radius-sm: 6px; --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --slot-h: 78px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1117; --surface: #171a22; --surface-2: #1d2130;
    --fg: #e5e7eb; --fg-2: #cbd5e1; --muted: #8b93a3;
    --line: #262b38; --line-2: #3b4252;
    --accent: #818cf8; --accent-fg: #0f1117; --accent-soft: #1e1b4b;
    --win: #4ade80; --win-soft: #14532d; --warn: #fbbf24; --warn-soft: #422006; --danger: #f87171;
    --gs: #fbbf24; --gs-soft: #3b2a06; --masters: #c4b5fd; --masters-soft: #2e1065;
    --s500: #7dd3fc; --s500-soft: #0c2a3d; --s250: #5eead4; --s250-soft: #0a2e2a; --custom: #cbd5e1; --custom-soft: #2a303c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}
:root[data-theme="dark"] {
  --bg: #0f1117; --surface: #171a22; --surface-2: #1d2130;
  --fg: #e5e7eb; --fg-2: #cbd5e1; --muted: #8b93a3;
  --line: #262b38; --line-2: #3b4252;
  --accent: #818cf8; --accent-fg: #0f1117; --accent-soft: #1e1b4b;
  --win: #4ade80; --win-soft: #14532d; --warn: #fbbf24; --warn-soft: #422006; --danger: #f87171;
  --gs: #fbbf24; --gs-soft: #3b2a06; --masters: #c4b5fd; --masters-soft: #2e1065;
  --s500: #7dd3fc; --s500-soft: #0c2a3d; --s250: #5eead4; --s250-soft: #0a2e2a; --custom: #cbd5e1; --custom-soft: #2a303c;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 400 15px/1.5 var(--font); background: var(--bg); color: var(--fg); font-feature-settings: "tnum" 1, "cv11" 1; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; letter-spacing: -0.01em; }
h2 { font-size: 24px; font-weight: 700; margin-bottom: 14px; }
h3 { font-size: 16px; font-weight: 600; margin: 22px 0 10px; }
h4 { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); } .warn { color: var(--warn); } .small-text { font-size: 13px; }

header.site { position: sticky; top: 0; z-index: 10; background: var(--surface); border-bottom: 1px solid var(--line); }
header.site .inner { max-width: 1200px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center; gap: 20px; height: 56px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--fg); font-weight: 700; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand .mark { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: var(--accent-fg); display: grid; place-items: center; font-size: 11px; font-weight: 800; letter-spacing: .02em; }
.brand .sub { color: var(--muted); font-weight: 500; }
nav.main { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
nav.main::-webkit-scrollbar { display: none; }
nav.main a { color: var(--fg-2); padding: 6px 10px; border-radius: var(--radius-sm); font-weight: 500; white-space: nowrap; }
nav.main a:hover, nav.main a.active { background: var(--accent-soft); color: var(--accent); text-decoration: none; }
.who { margin-left: auto; display: flex; gap: 10px; align-items: center; font-size: 13px; white-space: nowrap; }
.tag { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }

main { max-width: 1200px; margin: 0 auto; padding: 24px 16px 48px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h2 { margin-bottom: 4px; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 20px; }
.cols > * { min-width: 0; }
.tab-panel { min-width: 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 20px; }
.card h3:first-child { margin-top: 0; }
section.block { margin-bottom: 28px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.section-head h3 { margin: 0; font-size: 18px; }

.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; margin-bottom: 20px; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; background: var(--surface-2); position: sticky; top: 0; }
tbody tr:last-child td, tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; }
tr.inactive { opacity: .55; }
.empty { color: var(--muted); padding: 18px 12px; text-align: center; }

input, select, textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--line-2); border-radius: var(--radius-sm); background: var(--surface); color: var(--fg); font: inherit; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
label { display: block; font-size: 13px; font-weight: 500; color: var(--fg-2); margin-bottom: 8px; }
label > input, label > select, label > textarea { margin-top: 4px; }
label.inline { display: inline-flex; align-items: center; gap: 6px; margin: 0; }
label.inline input { width: auto; }
.grid { display: grid; gap: 12px; max-width: 560px; }
button, .btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; min-height: 36px; border: 1px solid var(--line-2); border-radius: var(--radius-sm); background: var(--surface); color: var(--fg); font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; }
button:hover, .btn:hover { background: var(--surface-2); text-decoration: none; }
button.primary, .btn.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
button.primary:hover, .btn.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--danger); }
button.small, .btn.small { padding: 4px 10px; min-height: 30px; font-size: 13px; }
form.inline { display: inline-block; margin: 0 6px 6px 0; }
.actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }

.status { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line-2); color: var(--fg-2); text-transform: capitalize; white-space: nowrap; }
.status.running { border-color: transparent; background: var(--accent-soft); color: var(--accent); }
.status.finished { border-color: transparent; background: var(--win-soft); color: var(--win); }
.status.draft { border-color: transparent; background: var(--warn-soft); color: var(--warn); }
.tier { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 5px; white-space: nowrap; letter-spacing: .02em; }
.tier.grand_slam { background: var(--gs-soft); color: var(--gs); }
.tier.masters { background: var(--masters-soft); color: var(--masters); }
.tier.series_500 { background: var(--s500-soft); color: var(--s500); }
.tier.series_250 { background: var(--s250-soft); color: var(--s250); }
.tier.custom { background: var(--custom-soft); color: var(--custom); }
.clan { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500; color: var(--muted); white-space: nowrap; max-width: 160px; vertical-align: middle; }
.clan span { overflow: hidden; text-overflow: ellipsis; }
a.clan:hover { text-decoration: none; color: var(--fg); }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin: 18px 0 18px; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { border: none; border-bottom: 2px solid transparent; border-radius: 0; background: none; color: var(--muted); padding: 8px 14px; margin-bottom: -1px; min-height: 0; white-space: nowrap; flex-shrink: 0; }
.tab:hover { background: none; color: var(--fg); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.hidden { display: none !important; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin-bottom: 20px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; text-align: center; box-shadow: var(--shadow); }
.tile b { display: block; font-size: 24px; font-weight: 700; letter-spacing: -0.02em; } .tile span { color: var(--muted); font-size: 12px; }

.events { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.event { display: block; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); color: var(--fg); }
.event:hover { text-decoration: none; border-color: var(--accent); }
.event .top { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.event .name { font-weight: 600; font-size: 16px; margin-bottom: 2px; }
.event .line { color: var(--muted); font-size: 13px; }
.event .progress { margin-top: 10px; font-size: 13px; display: flex; justify-content: space-between; }
.bar { height: 6px; border-radius: 999px; background: var(--line); overflow: hidden; margin-top: 6px; }
.bar i { display: block; height: 100%; background: var(--accent); }
.race td.bar-cell { width: 34%; } .race .bar { margin: 0; }
.rank { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; font-size: 12px; font-weight: 700; background: var(--surface-2); color: var(--fg-2); }
.rank.r1 { background: var(--gs-soft); color: var(--gs); } .rank.r2 { background: var(--custom-soft); color: var(--custom); } .rank.r3 { background: var(--warn-soft); color: var(--warn); }
.result-row .who { margin: 0; font-size: 14px; }

.picker { columns: 3 190px; margin: 10px 0; }
.picker label { break-inside: avoid; font-size: 14px; font-weight: 400; margin-bottom: 4px; display: flex; align-items: center; gap: 6px; }
.picker input { width: auto; }

.bracket { display: flex; overflow-x: auto; padding: 4px 0 20px; --gap: 32px; scroll-snap-type: x proximity; }
.round { display: flex; flex-direction: column; flex: 0 0 240px; padding-right: var(--gap); scroll-snap-align: start; }
.round:last-child { padding-right: 0; }
.round h4 { margin: 0 0 10px; }
.pairs { display: flex; flex-direction: column; flex: 1; min-height: calc(var(--slots) * var(--slot-h)); }
.pair { display: flex; flex-direction: column; justify-content: space-around; flex: 1; position: relative; }
.pair.single { justify-content: center; }
.round:not(:last-child) .pair::after { content: ""; position: absolute; right: calc(var(--gap) / -2); top: 25%; bottom: 25%; border-right: 2px solid var(--line-2); border-radius: 2px; }
.round:not(:last-child) .pair::before { content: ""; position: absolute; right: calc(-1 * var(--gap)); width: calc(var(--gap) / 2); top: 50%; border-top: 2px solid var(--line-2); }
.round:not(:last-child) .pair.single::after { display: none; }
.round:not(:last-child) .pair.single::before { right: calc(-1 * var(--gap)); width: var(--gap); }
.match { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); box-shadow: var(--shadow); font-size: 14px; overflow: hidden; }
.round:not(:last-child) .match::after { content: ""; position: absolute; left: 100%; top: 50%; width: calc(var(--gap) / 2); border-top: 2px solid var(--line-2); }
.match.preview { border-style: dashed; box-shadow: none; }
.match.needs_admin, .match.error { border-color: var(--warn); }
.side { display: flex; align-items: center; gap: 8px; padding: 7px 10px 7px 8px; border-left: 3px solid transparent; min-height: 34px; }
.side + .side { border-top: 1px solid var(--line); }
.side .seed { flex: 0 0 18px; font-size: 11px; color: var(--muted); text-align: right; }
.side .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.side .name a { color: inherit; }
.side.empty .name { color: var(--muted); font-weight: 400; font-style: italic; }
.side.won { border-left-color: var(--win); background: var(--win-soft); }
.side.won .name { font-weight: 700; }
.side.lost { color: var(--muted); } .side.lost .name { font-weight: 400; }
.side .clan { font-size: 11px; max-width: 90px; }
.match .meta { font-size: 12px; color: var(--muted); padding: 5px 10px; border-top: 1px solid var(--line); background: var(--surface-2); display: flex; gap: 6px; flex-wrap: wrap; }
.match .admin { padding: 6px 8px; border-top: 1px solid var(--line); display: flex; gap: 6px; flex-wrap: wrap; }
.match .admin select { width: auto; padding: 4px 6px; font-size: 13px; }
.legend { font-size: 13px; color: var(--muted); margin-bottom: 10px; }

@media (max-width: 720px) {
  header.site .inner { gap: 12px; height: auto; flex-wrap: wrap; padding: 8px 12px; }
  .brand .sub { display: none; }
  nav.main { order: 3; flex-basis: 100%; margin: 0 -12px; padding: 0 12px 6px; }
  .who { margin-left: auto; }
  main { padding: 16px 12px 40px; }
  h2 { font-size: 21px; }
  th, td { padding: 9px 10px; }
  .cols { grid-template-columns: 1fr; }
  .picker { columns: 2 140px; }
  .round { flex-basis: 210px; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .race td.bar-cell { display: none; }
  button, .btn { min-height: 40px; }
  .tab { min-height: 40px; }
}
.charts .card { margin-bottom: 0; }
.charts { margin-bottom: 20px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 460px), 1fr)); }
.chart { width: 100%; height: auto; display: block; margin-top: 8px; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .tick { font-size: 13px; fill: var(--muted); }
.chart .mark { fill: var(--accent); }
.chart .mark:hover { filter: brightness(1.15); }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; }
.chart .dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart .dot.ghost { fill: transparent; stroke: none; }
.chart .dot:hover { r: 6; }
details.card summary { cursor: pointer; font-weight: 500; }
details.card table { font-size: 13px; margin-top: 8px; }
.boards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.board { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px; display: flex; flex-direction: column; }
.board-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.board-head h4 { color: var(--fg); font-size: 14px; text-transform: none; letter-spacing: 0; }
.info { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; background: var(--surface-2); border: 1px solid var(--line-2); color: var(--muted); font-size: 11px; font-weight: 700; cursor: help; }
.board-search { margin-bottom: 8px; padding: 6px 10px; font-size: 13px; }
.board table { font-size: 13px; }
.board th, .board td { padding: 6px 8px; }
.board th { position: static; }
.board-foot { display: flex; justify-content: space-between; align-items: center; margin-top: auto; padding-top: 8px; }
.board-foot button:disabled { opacity: .4; cursor: default; }
.clan img { width: 18px; height: 18px; object-fit: contain; border-radius: 3px; flex: none; }
.clan.icon-only { max-width: none; gap: 0; }
.side .clan img { width: 20px; height: 20px; }
.clan-head { display: flex; align-items: center; gap: 12px; }
.clan-head img { width: 40px; height: 40px; object-fit: contain; border-radius: 8px; }
.theme-toggle { width: 34px; height: 34px; padding: 0; justify-content: center; border-radius: 50%; }
.theme-toggle svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.theme-toggle .sun { display: none; }
:root[data-theme="dark"] .theme-toggle .sun { display: block; }
:root[data-theme="dark"] .theme-toggle .moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .sun { display: block; }
  :root:not([data-theme="light"]) .theme-toggle .moon { display: none; }
}
.brand .mark-img { width: 30px; height: 30px; border-radius: 8px; object-fit: contain; }
.tier.single_elimination { background: var(--s500-soft); color: var(--s500); }
.tier.round_robin { background: var(--s250-soft); color: var(--s250); }
.rr-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.rr-round { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; box-shadow: var(--shadow); }
.rr-round h4 { margin-bottom: 8px; }
.rr-round .match { margin-bottom: 8px; }
.rr-round .match:last-child { margin-bottom: 0; }
.organizer { font-size: 11px; font-weight: 600; padding: 1px 6px; border-radius: 999px; background: var(--gs-soft); color: var(--gs); }
.flash { border-color: var(--accent); }
.event .clan-head { display: inline-flex; align-items: center; gap: 8px; }
.event .clan-head img { width: 28px; height: 28px; border-radius: 6px; object-fit: contain; }
