:root {
  color-scheme: light;
  --bg: #f6f6f3;
  --surface: #ffffff;
  --text: #191919;
  --muted: #666666;
  --line: #e4e3de;
  --grid: #eeede9;
  --accent: #1f5fae;
  --pos: 37, 125, 224;     /* blue, winning */
  --neg: 236, 70, 71;      /* red, losing */
  --grey-line: #c9c8c2;
  --chip: #efeee9;
  --error: #b42318;
  --ok: #067647;
  --warn: #9a6700;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #111111;
    --surface: #191919;
    --text: #efefef;
    --muted: #9c9c9c;
    --line: #2e2e2c;
    --grid: #262624;
    --accent: #79b0f2;
    --pos: 51, 140, 237;
    --neg: 235, 98, 99;
    --grey-line: #4a4a46;
    --chip: #262624;
    --error: #f97066;
    --ok: #47cd89;
    --warn: #f2c14e;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

header.site { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
header .bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px 4px; max-width: 1100px; margin: 0 auto; }
.brand { font-weight: 700; color: var(--text); font-size: 17px; }
select, input, button { font: inherit; color: inherit; }
select { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }
nav.tabs { display: flex; gap: 2px; overflow-x: auto; padding: 0 8px; max-width: 1100px; margin: 0 auto; scrollbar-width: none; }
nav.tabs a { padding: 8px 10px 10px; color: var(--muted); white-space: nowrap; border-bottom: 2px solid transparent; }
nav.tabs a[aria-current=page] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

main { max-width: 1100px; margin: 0 auto; padding: 12px 14px 40px; }
h1 { font-size: 22px; margin: 6px 0 2px; }
h2 { font-size: 17px; margin: 26px 0 6px; }
.sub { color: var(--muted); margin: 0 0 12px; }
.note { color: var(--muted); font-size: 13px; margin: 4px 0 8px; }
.crumb { margin: 4px 0 0; font-size: 14px; }
.head-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
footer { color: var(--muted); font-size: 12px; text-align: center; padding: 20px; }

button.save-img, .btn {
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn:disabled { opacity: .5; cursor: default; }

.scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { padding: 6px 8px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--grid); }
th { font-size: 12px; color: var(--muted); font-weight: 600; position: sticky; top: 0; background: var(--surface); }
tbody tr:last-child td { border-bottom: 0; }
td:first-child, th:first-child { text-align: left; }
caption { text-align: left; padding: 8px; font-weight: 600; }
table.league td:nth-child(2), table.league th:nth-child(2) { text-align: left; position: sticky; left: 0; background: var(--surface); }
table.league td:nth-child(2) { font-weight: 600; }
table.league td.idx, table.league th.idx { color: var(--muted); width: 1%; }
table.league td:nth-last-child(2) { font-weight: 700; }
.form { letter-spacing: 1px; }
table.league td:last-child, table.league th:last-child { text-align: left; }
table.log td:nth-child(n+7), table.log th:nth-child(n+7) { text-align: left; white-space: normal; min-width: 160px; color: var(--muted); }
table.log td:first-child { white-space: nowrap; }
table.facts th { text-align: left; font-size: 14px; color: var(--muted); font-weight: 500; position: static; width: 45%; }
table.facts td { text-align: left; white-space: normal; }
table.ringers tr:last-child td { font-weight: 700; }
table.positions td:first-child, table.positions th:first-child { position: sticky; left: 0; background: var(--surface); }

details.rules { margin-top: 14px; color: var(--muted); font-size: 13px; }
details.rules summary { cursor: pointer; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; margin: 10px 0; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.tile span { display: block; font-size: 12px; color: var(--muted); }
.tile b { font-size: 18px; }

/* Results */
.night { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; margin: 10px 0; }
.night h2 { margin: 2px 0 6px; font-size: 14px; color: var(--muted); font-weight: 600; }
.game { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: center; padding: 6px 0; border-top: 1px solid var(--grid); }
.night h2 + .game { border-top: 0; }
.game .team { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.game .names { font-size: 14px; }
.game .right { text-align: right; }
.game .score { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.game .score span { color: var(--muted); padding: 0 4px; }
.game.bonus, .game.nogame { display: block; font-size: 13px; color: var(--muted); }

/* Bump chart */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 10px; }
.chip { border: 1px solid var(--line); background: var(--chip); border-radius: 999px; padding: 4px 10px; font-size: 13px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.chip::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--c, var(--grey-line)); }
.chip.reset::before { display: none; }
.chip[aria-pressed=true] { background: var(--surface); border-color: var(--c); font-weight: 600; }
.chart-wrap { padding: 4px; }
#bump { display: block; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
#bump .bg { fill: var(--surface); }
#bump .grid { stroke: var(--grid); stroke-width: 1; }
#bump .axis { fill: var(--muted); font-size: 11px; }
#bump .player .line { fill: none; stroke: var(--grey-line); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
#bump .player .hit { fill: none; stroke: transparent; stroke-width: 14; cursor: pointer; }
#bump .player circle { fill: var(--grey-line); stroke: var(--surface); stroke-width: 2; opacity: 0; }
#bump .player .label { fill: var(--muted); font-size: 11px; cursor: pointer; }
#bump .player.on .line { stroke: var(--c); stroke-width: 3; }
#bump .player.on circle { fill: var(--c); opacity: 1; }
#bump .player.on .label { fill: var(--text); font-weight: 700; }

/* Partnerships grid */
table.grid-table { width: auto; }
table.grid-table th.rot { height: 90px; vertical-align: bottom; padding: 4px 2px; }
table.grid-table th.rot span { writing-mode: vertical-rl; transform: rotate(180deg); font-weight: 600; }
table.grid-table th.rowh { text-align: left; position: sticky; left: 0; background: var(--surface); z-index: 1; font-size: 13px; }
table.grid-table td { padding: 3px 4px; text-align: center; min-width: 40px; line-height: 1.1; border: 1px solid var(--grid); }
table.grid-table td b { display: block; font-size: 13px; }
table.grid-table td i { display: block; font-style: normal; font-size: 10px; color: var(--muted); }
table.grid-table td.pos { background: rgba(var(--pos), var(--a)); }
table.grid-table td.neg { background: rgba(var(--neg), var(--a)); }
table.grid-table td.self { background: var(--grid); }

/* Enter results */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin: 10px 0; }
.field { display: flex; flex-direction: column; gap: 4px; margin: 8px 0; }
.field label, .lbl { font-size: 13px; color: var(--muted); }
.field input, .field select { padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.teams { display: grid; grid-template-columns: 1fr; gap: 10px; }
@media (min-width: 720px) { .teams { grid-template-columns: 1fr 1fr; } }
.slot { display: grid; grid-template-columns: 1fr auto; gap: 6px; align-items: center; margin: 6px 0; }
.slot select, .slot input[type=text] { width: 100%; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.slot .guest-name { grid-column: 1 / -1; }
label.row.note { flex-wrap: nowrap; align-items: flex-start; }
.slot .guest { font-size: 13px; color: var(--muted); display: flex; gap: 4px; align-items: center; white-space: nowrap; }
.score-in { width: 90px; font-size: 22px; font-weight: 700; text-align: center; }
.msg { padding: 8px 10px; border-radius: 8px; margin: 8px 0; font-size: 14px; }
.msg.error { color: var(--error); border: 1px solid var(--error); }
.msg.ok { color: var(--ok); border: 1px solid var(--ok); }
.msg.warn { color: var(--warn); border: 1px solid var(--warn); }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
pre.preview { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px; overflow-x: auto; font-size: 12px; }
ul.warnings { padding-left: 18px; font-size: 13px; }
.game-entry { margin: 14px 0; }
.game-head { justify-content: space-between; }
.game-head h2 { margin: 0; font-size: 16px; }
.game-head h2:empty { display: none; }
.form-pick { display: inline-flex; gap: 6px; align-items: center; margin: 0 0 8px; }
.form-pick select { padding: 2px 6px; }
table.games td:last-child { text-align: left; white-space: normal; min-width: 180px; }
table.alltime td:nth-child(2) { position: sticky; left: 0; background: var(--surface); }
table.games th, table.games td { text-align: left; }
th.sortable { cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent; }
th.sortable:hover { color: var(--text); }
th.sortable::after { content: "↕"; opacity: .3; margin-left: 3px; font-size: 10px; }
th[aria-sort=ascending]::after { content: "▲"; opacity: 1; }
th[aria-sort=descending]::after { content: "▼"; opacity: 1; }
th[aria-sort] { color: var(--text); }
