:root {
  --bg: #f4f6f8; --panel: #ffffff; --panel2: #f0f2f5; --line: #dde2e8;
  --text: #17202a; --muted: #66727f; --accent: #1f7a4d; --accent-soft: #e3f3ea;
  --gold: #b7861a; --danger: #c0392b; --focus: #2b6cb0;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1418; --panel: #182026; --panel2: #1f2930; --line: #2c3842;
    --text: #e6ecf0; --muted: #93a1ad; --accent: #4cc38a; --accent-soft: #173327;
    --gold: #e0b44c; --danger: #ef6b5c; --focus: #6aa8ea;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1418; --panel: #182026; --panel2: #1f2930; --line: #2c3842;
  --text: #e6ecf0; --muted: #93a1ad; --accent: #4cc38a; --accent-soft: #173327;
  --gold: #e0b44c; --danger: #ef6b5c; --focus: #6aa8ea;
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* topo */
.top {
  position: sticky; top: 0; z-index: 5; display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; flex: 1 1 220px; min-width: 0; }
.logo { font-size: 1.4rem; }
.tname {
  flex: 1; min-width: 0; font-size: 1.15rem; font-weight: 700; border: 1px solid transparent;
  background: transparent; border-radius: 6px; padding: 4px 6px;
}
.tname:hover, .tname:focus { border-color: var(--line); background: var(--panel2); }
.tabs { display: flex; gap: 4px; background: var(--panel2); padding: 3px; border-radius: 9px; }
.tabs button {
  border: 0; background: transparent; padding: 6px 14px; border-radius: 7px; cursor: pointer; color: var(--muted); font-weight: 600;
}
.tabs button[aria-selected="true"] { background: var(--panel); color: var(--text); box-shadow: 0 1px 2px #0002; }
.status { font-size: .82rem; color: var(--muted); min-width: 80px; text-align: right; }
.status.err { color: var(--danger); }

main { max-width: 1280px; margin: 0 auto; padding: 16px; }
.tab { display: none; }
.tab.active { display: block; }

/* botões */
.btn {
  border: 1px solid var(--line); background: var(--panel); padding: 7px 14px; border-radius: 8px; cursor: pointer; font-weight: 600;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.small { padding: 3px 9px; font-size: .85rem; }
.icon-btn {
  border: 0; background: transparent; cursor: pointer; color: var(--muted); padding: 2px 6px; border-radius: 6px; font-size: 1rem;
}
.icon-btn:hover { color: var(--danger); background: var(--panel2); }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.toolbar .hint { color: var(--muted); font-size: .9rem; }

/* grupos */
.groups { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 560px), 1fr)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; min-width: 0; }
.card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.gname {
  flex: 1; min-width: 0; font-weight: 700; font-size: 1.05rem; border: 1px solid transparent; background: transparent;
  border-radius: 6px; padding: 3px 6px;
}
.gname:hover, .gname:focus { border-color: var(--line); background: var(--panel2); }
.badge { font-size: .75rem; padding: 2px 8px; border-radius: 99px; background: var(--panel2); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--accent-soft); color: var(--accent); }

.teams { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 2px; background: var(--panel2); border: 1px solid var(--line);
  border-radius: 99px; padding: 2px 4px 2px 10px; font-size: .9rem;
}
.chip .icon-btn { font-size: .85rem; padding: 0 4px; }
.add-team { display: flex; gap: 6px; margin-bottom: 12px; }
.add-team input, .field input, .field select {
  flex: 1; min-width: 0; border: 1px solid var(--line); background: var(--panel2); border-radius: 8px; padding: 7px 10px;
}

h3.sub { margin: 14px 0 6px; font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }

.table-wrap { overflow-x: auto; }
table.std { width: 100%; border-collapse: collapse; font-size: .9rem; font-variant-numeric: tabular-nums; }
.std th, .std td { padding: 6px 6px; text-align: center; border-bottom: 1px solid var(--line); white-space: nowrap; }
.std th { color: var(--muted); font-weight: 600; font-size: .78rem; }
.std td.team, .std th.team { text-align: left; width: 100%; white-space: normal; }
.std td.pts { font-weight: 700; }
.std td.pos { color: var(--muted); width: 1%; }
.std tr.q td.pos { color: var(--accent); font-weight: 700; box-shadow: inset 3px 0 0 var(--accent); }
.legend { font-size: .8rem; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; background: var(--accent); border-radius: 2px; vertical-align: -1px; margin-right: 4px; }

.round { margin-top: 8px; }
.round-title { font-size: .78rem; color: var(--muted); font-weight: 600; margin: 8px 0 4px; }
.match {
  display: grid; grid-template-columns: 1fr auto auto auto 1fr; align-items: center; gap: 6px;
  padding: 4px 0; border-bottom: 1px dashed var(--line);
}
.match:last-child { border-bottom: 0; }
.match .h { text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.match .a { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.match .x { color: var(--muted); font-size: .85rem; }
.score {
  width: 42px; text-align: center; border: 1px solid var(--line); background: var(--panel2); border-radius: 6px;
  padding: 4px 0; font-weight: 700; font-variant-numeric: tabular-nums;
}
.score:disabled { opacity: .5; }
.win { font-weight: 700; }

.empty { color: var(--muted); font-style: italic; padding: 8px 0; }
.empty-state { text-align: center; padding: 50px 16px; color: var(--muted); }
.empty-state .big { font-size: 2.6rem; }

/* playoffs */
.notice {
  background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--gold);
  border-radius: 8px; padding: 10px 12px; margin-bottom: 14px; font-size: .92rem;
}
.bracket { display: flex; gap: 22px; overflow-x: auto; padding-bottom: 10px; align-items: stretch; }
.col { display: flex; flex-direction: column; min-width: 240px; flex: 1 0 240px; }
.col h3 { margin: 0 0 8px; font-size: .82rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); text-align: center; }
.col .slots { display: flex; flex-direction: column; justify-content: space-around; flex: 1; gap: 12px; }
.pm { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.pm .side { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 6px; padding: 6px 8px; }
.pm .side + .side { border-top: 1px solid var(--line); }
.pm .tn { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pm .tn small { color: var(--muted); margin-left: 4px; }
.pm .tbd { color: var(--muted); font-style: italic; }
.pm .side.won { background: var(--accent-soft); }
.pm .side.won .tn { font-weight: 700; }
.pm .pen { width: 34px; font-size: .8rem; }
.pm .pen-label { font-size: .7rem; color: var(--muted); text-align: right; padding: 0 8px 4px; }
.pm.bye { opacity: .7; }
.champion {
  text-align: center; background: var(--panel); border: 2px solid var(--gold); border-radius: 12px; padding: 16px; margin: 0 0 16px;
}
.champion .big { font-size: 2.2rem; }
.champion b { font-size: 1.3rem; }
.third { margin-top: 18px; max-width: 280px; }

/* config */
.config { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field label { font-size: .85rem; color: var(--muted); font-weight: 600; }
.check { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; cursor: pointer; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.card h2 { margin: 0 0 12px; font-size: 1rem; }
.card p { color: var(--muted); font-size: .9rem; margin: 0 0 10px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

@media (max-width: 600px) {
  .top { padding: 8px 12px; }
  main { padding: 12px; }
  .std .opt { display: none; }
  .status { min-width: 0; }
}
