:root {
  color-scheme: light;
  --bg: #f5f4f0;
  --surface: #fcfcfb;
  --border: #e2e0d8;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7a7974;
  --win: #1b7a3d;
  --loss: #b3261e;
  --on-status: #fff;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110;
    --surface: #1a1a19;
    --border: #2e2e2c;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #8f8e88;
    --win: #5cc47e;
    --loss: #ef7a72;
    --on-status: #111110;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
header, main { max-width: 1100px; margin: 0 auto; padding: 0 16px; }
header { padding-top: 28px; padding-bottom: 8px; }
h1 { margin: 0; font-size: 28px; }
h2 { margin: 0 0 4px; font-size: 17px; }
.muted { color: var(--muted); margin: 4px 0 0; }
.small { font-size: 13px; margin-bottom: 12px; }

.panel, .card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 16px;
}
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.grid > .panel { margin-bottom: 0; }
section.grid { margin-bottom: 16px; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin: 16px 0; }
.card { margin: 0; border-top: 4px solid var(--c); }
.card h3 { margin: 0 0 8px; font-size: 17px; }
.stat { display: flex; justify-content: space-between; color: var(--text-2); }
.stat b { color: var(--text); font-variant-numeric: tabular-nums; }

.period { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.period button {
  font: inherit;
  font-size: 14px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
}
.period button:hover { color: var(--text); border-color: var(--text-2); }
.period button[aria-pressed="true"] { background: var(--text); border-color: var(--text); color: var(--surface); }

.chart-wrap { position: relative; height: 320px; }
.clan-elo { display: grid; grid-template-columns: minmax(200px, 1fr) 3fr; gap: 16px; align-items: center; }
.clan-elo .small-chart { height: 180px; }
.elo-now { font-size: 40px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
@media (max-width: 640px) { .clan-elo { grid-template-columns: 1fr; } }

table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 500; font-size: 13px; }
td.num, th.num { text-align: right; white-space: nowrap; }
.bar { display: inline-block; height: 6px; border-radius: 3px; background: var(--text-2); opacity: .5; vertical-align: middle; margin-right: 6px; }

h4 { margin: 0 0 6px; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); }
.dot.inline { display: inline-block; margin-right: 8px; }
.month-chart { height: 240px; }
table.spaced { margin-top: 16px; }

.match { border-bottom: 1px solid var(--border); padding: 10px 0; }
.match:last-child { border-bottom: 0; }
.match-head { display: flex; flex-wrap: wrap; gap: 4px 12px; color: var(--text-2); font-size: 13px; margin-bottom: 6px; }
.match-head b { color: var(--text); }
.teams { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.team { font-size: 14px; }
.team .result { font-weight: 600; font-size: 13px; }
.team.won .result { color: var(--win); }
.team.lost .result { color: var(--loss); }
.team .p { display: flex; justify-content: space-between; gap: 8px; }
.team .p.clan { font-weight: 600; }
.team .p span:last-child { color: var(--text-2); }
.up { color: var(--win); }
.down { color: var(--loss); }

@media (max-width: 560px) {
  .teams { grid-template-columns: 1fr; }
}

.last-match { border-left: 4px solid var(--border); }
.last-match.won { border-left-color: var(--win); }
.last-match.lost { border-left-color: var(--loss); }
.lm-head { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; margin-bottom: 8px; }
.lm-result { font-weight: 700; font-size: 20px; }
.lm-players { display: flex; flex-wrap: wrap; gap: 4px 20px; margin-bottom: 8px; }
.lm-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 4px 16px; }

.brand { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; margin-bottom: 4px; }
.logo { width: 340px; max-width: 100%; height: auto; flex: none; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.tile { display: block; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; color: inherit; text-decoration: none; }
a.tile:hover { border-color: var(--text-2); }
.tile .label { color: var(--muted); font-size: 13px; }
.tile .value { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.25; }
.tile .sub { color: var(--text-2); font-size: 13px; }

a.match { display: block; color: inherit; text-decoration: none; border-radius: 6px; }
a.match:hover { background: var(--bg); }
.lm-link { display: inline-block; margin-top: 6px; color: var(--text-2); font-size: 14px; }

dialog#match-dialog, dialog#player-dialog {
  width: min(760px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
}
dialog#match-dialog::backdrop, dialog#player-dialog::backdrop { background: rgb(0 0 0 / .45); }
.md-top { display: flex; justify-content: space-between; align-items: start; gap: 12px; }
.md-top h2 { font-size: 20px; }
.md-close { font: inherit; font-size: 14px; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; }
.md-teams { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin: 16px 0 8px; }
.md-team h3 { margin: 0 0 6px; font-size: 15px; display: flex; justify-content: space-between; }
.md-team.won h3 span:first-child { color: var(--win); }
.md-team.lost h3 span:first-child { color: var(--loss); }
.md-team td { font-size: 14px; }
.md-team tr.clan td:first-child { font-weight: 600; }
.md-team a { color: var(--text-2); }
@media (max-width: 560px) { .md-teams { grid-template-columns: 1fr; } }

.expected { display: inline-flex; gap: 4px; align-items: baseline; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--border); color: var(--text-2); font-size: 12px; white-space: nowrap; }
.expected b { color: var(--text); }
.expected.up { border-color: var(--win); color: var(--win); }
.expected.down { border-color: var(--loss); color: var(--loss); }
.match-head .expected { margin-left: auto; }
.md-expected { margin: 8px 0 0; color: var(--text-2); font-size: 14px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.logo text { font: 700 19px system-ui, -apple-system, "Segoe UI", sans-serif; fill: var(--text); }
.logo-player { cursor: pointer; }
.logo-player:hover text, .logo-player:focus-visible text { text-decoration: underline; }
.logo-player:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
.card[data-player-link] { cursor: pointer; }
.card[data-player-link]:hover { border-color: var(--text-2); }
.nick { color: var(--muted); font-weight: 400; font-size: 14px; }
.md-top a { color: var(--text-2); }

dialog#player-dialog { width: min(860px, calc(100vw - 32px)); border-top: 4px solid var(--c, var(--border)); }
.player-chart { height: 220px; margin: 12px 0; }
.pl-stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-top: 12px; }
#player-tables .grid { margin-top: 8px; }
#player-tables h4 { margin-top: 12px; }

.form-box { display: flex; align-items: center; gap: 12px; padding: 10px 16px 10px 12px; border: 1px solid var(--border); border-left-width: 4px; border-radius: 8px; background: var(--surface); }
.form-box h2 { margin: 0; font-size: 17px; }
.form-box.up { border-left-color: var(--win); }
.form-box.down { border-left-color: var(--loss); }
.form-arrow { width: 44px; height: 44px; flex: none; color: var(--text-2); }
.form-arrow svg { width: 100%; height: 100%; display: block; }
.form-box.up .form-arrow { color: var(--win); transform: rotate(-90deg); }
.form-box.down .form-arrow { color: var(--loss); transform: rotate(90deg); }
.form-sub { color: var(--text-2); font-size: 13px; }
.form-dots { display: flex; gap: 4px; margin-top: 6px; }
.form-dots a { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font: 700 11px system-ui, sans-serif; color: var(--on-status); text-decoration: none; }
.form-dots a.won { background: var(--win); }
.form-dots a.lost { background: var(--loss); }
.form-dots a:hover, .form-dots a:focus-visible { outline: 2px solid var(--text); outline-offset: 1px; }

.fetched { margin: 2px 0 0; font-weight: 600; }
.fetched .muted { font-weight: 400; margin: 0; }
.fetched-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--win); margin-right: 8px; vertical-align: 1px; }
