:root {
  --bg: #f4f5f2;
  --panel: #ffffff;
  --ink: #1c211d;
  --muted: #66706a;
  --line: #d9ddd6;
  --accent: #1f6f43;
  --accent-ink: #ffffff;
  --win: #e5f2ea;
  --loss: #8b938d;
  --bad: #b3261e;
  --gold: #b8860b;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121513;
    --panel: #1b1f1c;
    --ink: #e7ebe8;
    --muted: #9aa49e;
    --line: #2e3430;
    --accent: #3fa36b;
    --accent-ink: #0b130e;
    --win: #1f3a2a;
    --loss: #6e7771;
    --bad: #ff8a80;
    --gold: #e0b44c;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
button, input, textarea { font: inherit; color: inherit; }

.top { padding: 20px 16px 0; max-width: 1400px; margin: 0 auto; }
.top h1 { margin: 0; font-size: 28px; letter-spacing: -0.5px; }
.sub { margin: 4px 0 14px; color: var(--muted); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); }
.tab {
  background: none; border: 0; padding: 10px 14px; cursor: pointer; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab.active { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.tab:disabled { opacity: .4; cursor: default; }

main { max-width: 1400px; margin: 0 auto; padding: 16px; }
.hidden { display: none !important; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.spacer { flex: 1; }
button.primary, button.ghost {
  border-radius: 8px; padding: 8px 14px; cursor: pointer; border: 1px solid var(--line);
}
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.ghost { background: var(--panel); }
button:disabled { opacity: .45; cursor: default; }
button.small { padding: 4px 10px; font-size: 13px; }
.toggle { color: var(--muted); font-size: 14px; display: flex; gap: 6px; align-items: center; }

.msg { min-height: 1.4em; margin: 0 0 10px; color: var(--muted); }
.msg.bad { color: var(--bad); }

.paste { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 14px; }
.paste p { margin: 0 0 8px; color: var(--muted); }
.paste textarea { width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px; }
.paste .row { margin-top: 8px; text-align: right; }

.regions-setup { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.region-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.region-name {
  width: 100%; font-weight: 700; font-size: 17px; border: 0; border-bottom: 1px dashed var(--line);
  background: transparent; padding: 4px 2px; margin-bottom: 8px;
}
.seed-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.seed-list li { display: flex; align-items: center; gap: 8px; }
.seed { width: 24px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; }
.seed-list input {
  flex: 1; min-width: 0; padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg);
}

/* Bracket */
.region { margin-bottom: 28px; }
.region h2 { font-size: 19px; margin: 0 0 8px; }
.rounds { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 6px; }
.round { flex: 0 0 230px; display: flex; flex-direction: column; }
.round h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin: 0 0 8px; }
.stack { flex: 1; display: flex; flex-direction: column; justify-content: space-around; gap: 8px; }

.game { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.game.big { border-color: var(--accent); }
.team { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-bottom: 1px solid var(--line); }
.team.tbd .tname { color: var(--muted); font-style: italic; }
.team.win { background: var(--win); font-weight: 600; }
.team.loss .tname, .team.loss .tscore { color: var(--loss); }
.tseed { width: 18px; text-align: right; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.tname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tname .reg { color: var(--muted); font-weight: 400; font-size: 11px; }
.tscore { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 22px; text-align: right; }
.gfoot { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 5px 8px 5px 10px; font-size: 12px; color: var(--muted); }
.final { font-weight: 600; color: var(--ink); }

.champion {
  display: flex; align-items: center; gap: 14px; background: var(--panel); border: 2px solid var(--gold);
  border-radius: 14px; padding: 14px 18px; margin-bottom: 18px;
}
.trophy { font-size: 38px; }
.cname { font-size: 22px; font-weight: 800; }
.cdet { color: var(--muted); }

.foot { max-width: 1400px; margin: 0 auto; padding: 8px 16px 28px; color: var(--muted); font-size: 13px; }

/* Records & history */
.search { padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); min-width: 0; width: 220px; max-width: 100%; }
button.danger { color: var(--bad); }
.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
table.rec { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
table.rec th, table.rec td { padding: 8px 12px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.rec th:nth-child(-n+2), table.rec td:nth-child(-n+2) { text-align: left; }
table.rec th { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); cursor: pointer; user-select: none; position: sticky; top: 0; background: var(--panel); }
table.rec th.sorted { color: var(--ink); }
table.rec tr:last-child td { border-bottom: 0; }
table.rec td.titles { font-weight: 700; color: var(--gold); }
table.rec td.rank { color: var(--muted); width: 1%; }
.hist-item { display: flex; align-items: center; gap: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; cursor: pointer; }
.hist-item:hover { border-color: var(--accent); }
.hist-item .htrophy { font-size: 26px; }
.hist-item .hmain { flex: 1; min-width: 0; }
.hist-item .hname { font-weight: 700; font-size: 17px; }
.hist-item .hdet { color: var(--muted); font-size: 13px; }
.empty { color: var(--muted); padding: 24px 4px; }
.saved-note { color: var(--muted); font-size: 13px; margin-left: auto; }

/* Team picker */
.setup-layout { display: grid; grid-template-columns: 1fr 300px; gap: 14px; align-items: start; }
.setup-layout .regions-setup { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.picker {
  position: sticky; top: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px; display: flex; flex-direction: column; gap: 8px; max-height: calc(100vh - 24px);
}
.pick-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.pick-target { font-size: 12px; color: var(--accent); font-weight: 600; text-align: right; }
.picker .search { width: 100%; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { flex: 1; border: 0; background: var(--panel); padding: 6px; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.pick-list { overflow-y: auto; flex: 1; min-height: 200px; max-height: 60vh; border-top: 1px solid var(--line); padding-top: 4px; }
.pick-conf { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin: 10px 2px 4px; }
.pick-team {
  display: block; width: 100%; text-align: left; background: none; border: 0; padding: 5px 8px; border-radius: 6px; cursor: pointer;
}
.pick-team:hover:not(:disabled) { background: var(--win); }
.pick-team:disabled { color: var(--loss); text-decoration: line-through; cursor: default; }
.seed-list li.active input { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 30%, transparent); }
.seed-list li.carried .seed { color: var(--gold); font-weight: 700; }
.carry-tag { font-size: 10px; color: var(--gold); font-weight: 700; white-space: nowrap; }
.slot-clear { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 0 4px; font-size: 16px; line-height: 1; }
@media (max-width: 760px) {
  .setup-layout { grid-template-columns: 1fr; }
  .picker { position: static; max-height: none; order: -1; }
  .pick-list { max-height: 260px; }
}
.region-card { min-width: 0; }
.seed-list { grid-template-columns: minmax(0, 1fr); }
.seed-list li { min-width: 0; }
.seed-list input { width: 100%; }
