:root {
  color-scheme: light dark;
  --bg: #f3f2ef;
  --surface: #fcfcfb;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #7b7a75;
  --line: #e2e0da;
  --accent: #2a78d6;
  --accent-text: #ffffff;
  --danger: #c9302f;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #6250d6;
  --series-8: #e34948;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111110;
    --surface: #1a1a19;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --text-3: #8f8e86;
    --line: #2e2e2b;
    --accent: #3987e5;
    --danger: #e66767;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

[hidden] { display: none !important; }

h1, h2 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.05rem; margin-bottom: 12px; }

.top,
main {
  max-width: 560px;
  margin: 0 auto;
  padding: 0 16px;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: calc(14px + env(safe-area-inset-top));
  padding-bottom: 12px;
}

main { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 12px;
}

.note {
  margin: 10px 0 0;
  color: var(--text-3);
  font-size: 0.82rem;
}
h2 + .note { margin: -8px 0 12px; }

.empty {
  text-align: center;
  color: var(--text-2);
  padding: 36px 16px;
}
.empty .btn { margin-top: 14px; }

/* buttons */

.btn {
  font: inherit;
  font-weight: 600;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}
.btn.danger {
  color: var(--danger);
  border-color: transparent;
  background: none;
  padding: 0 8px;
}
.btn:disabled { opacity: 0.5; cursor: default; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* standings */

.standings {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}
.standings th {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-3);
  text-align: left;
  padding: 0 0 8px;
}
.standings td {
  padding: 10px 0;
  border-top: 1px solid var(--line);
}
.standings .num {
  text-align: right;
  padding-left: 12px;
  white-space: nowrap;
}
.standings abbr { text-decoration: none; }
.standings td:first-child {
  font-weight: 600;
  word-break: break-word;
}

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 8px;
  flex: none;
}

/* charts */

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin-bottom: 8px;
  font-size: 0.85rem;
  color: var(--text-2);
}
.legend span { display: inline-flex; align-items: center; }

.chart {
  position: relative;
  touch-action: pan-y;
}
.chart svg {
  display: block;
  width: 100%;
  overflow: visible;
}
.chart text {
  font-size: 11px;
  fill: var(--text-3);
  font-variant-numeric: tabular-nums;
}
.chart text.end-label {
  fill: var(--text-2);
  font-size: 12px;
}
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .cursor { stroke: var(--text-3); stroke-width: 1; }
.chart .series {
  fill: none;
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.chart .marker { stroke: var(--surface); stroke-width: 2; }

.tooltip {
  position: absolute;
  top: 0;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.8rem;
  box-shadow: 0 4px 14px rgb(0 0 0 / 0.14);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.tooltip .when { color: var(--text-3); margin-bottom: 2px; }
.tooltip .line { display: flex; align-items: center; }
.tooltip .line b { margin-left: auto; padding-left: 14px; }

.bars {
  display: grid;
  grid-template-columns: minmax(0, max-content) 1fr;
  gap: 10px 12px;
  align-items: center;
  font-size: 0.9rem;
}
.bars .name {
  max-width: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-2);
}
.bars .track {
  display: flex;
  align-items: center;
  gap: 8px;
  font-variant-numeric: tabular-nums;
  border-left: 1px solid var(--line);
}
.bars .bar {
  height: 14px;
  min-width: 2px;
  border-radius: 0 4px 4px 0;
}

/* players */

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.chip {
  font: inherit;
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 14px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: none;
  color: var(--text);
  cursor: pointer;
}
.chip.add {
  color: var(--accent);
  font-weight: 600;
  border-style: dashed;
}

/* matches */

.matches {
  list-style: none;
  margin: 0;
  padding: 0;
}
.match {
  font: inherit;
  color: inherit;
  text-align: left;
  width: 100%;
  display: block;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 16px;
  margin-bottom: 8px;
  cursor: pointer;
}
.match .when {
  font-size: 0.8rem;
  color: var(--text-3);
}
.match .result {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 2px 0;
}
.match .result strong { word-break: break-word; }
.match .result .vs { color: var(--text-3); font-size: 0.85rem; }
.match .result { flex-wrap: wrap; }
.match .result .loser { color: var(--text-2); word-break: break-word; }
.match .detail {
  font-size: 0.85rem;
  color: var(--text-2);
}

/* rules */

.rules ol,
.rules ul {
  margin: 0;
  padding-left: 1.3em;
}
.rules li + li { margin-top: 10px; }

/* tabs */

.tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  font: inherit;
  font-size: 0.75rem;
  flex: 1;
  max-width: 187px;
  min-height: 58px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 0;
  background: none;
  color: var(--text-3);
  cursor: pointer;
}
.tabs button[aria-current="page"] {
  color: var(--accent);
  font-weight: 600;
}
.tabs svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* dialogs */

dialog {
  width: 100%;
  max-width: 560px;
  margin: auto auto 0;
  border: 0;
  border-radius: 18px 18px 0 0;
  padding: 20px 16px calc(16px + env(safe-area-inset-bottom));
  background: var(--surface);
  color: var(--text);
  max-height: 92dvh;
  overflow-y: auto;
}
dialog::backdrop { background: rgb(0 0 0 / 0.45); }

@media (min-width: 600px) {
  dialog {
    margin: auto;
    border-radius: 18px;
  }
}

form label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-2);
  margin-bottom: 14px;
  min-width: 0;
}
form input,
form select {
  display: block;
  width: 100%;
  min-height: 46px;
  margin-top: 4px;
  padding: 0 12px;
  font: inherit;
  font-size: 16px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.entry {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px 68px 68px;
  gap: 8px;
  align-items: center;
  padding: 6px 0;
  border-top: 1px solid var(--line);
}
.entry.head {
  border-top: 0;
  padding: 0 0 6px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-3);
}
.entry.head span:not(:first-child) { text-align: center; }
.entry label {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  min-height: 46px;
  font-size: 1rem;
  color: var(--text);
}
.entry label span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.entry input[type="checkbox"],
.entry input[type="radio"] {
  width: 22px;
  height: 22px;
  min-height: 0;
  margin: 0;
  padding: 0;
  flex: none;
  accent-color: var(--accent);
}
.entry input[type="radio"] { justify-self: center; }
.entry input[type="number"] {
  margin: 0;
  padding: 0 6px;
  text-align: center;
}
.entry input:disabled { opacity: 0.35; }
#match-entries { margin-bottom: 14px; border-bottom: 1px solid var(--line); }

fieldset {
  border: 0;
  padding: 0;
  margin: 0;
}
legend {
  padding: 0;
  font-weight: 600;
  margin-bottom: 8px;
}
.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.error {
  color: var(--danger);
  font-size: 0.9rem;
  margin: 0 0 12px;
}
.actions {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 4px;
}
.spacer { flex: 1; }
