:root {
  --bg: #0e1116;
  --bg2: #151a21;
  --panel: #1a2029;
  --panel2: #222a35;
  --line: #2c3541;
  --text: #e6e9ee;
  --muted: #8a94a3;
  --accent: #f39c12;
  --accent2: #ff7a00;
  --accent-dim: rgba(243, 156, 18, .16);
  --green: #2ecc71;
  --green-dim: rgba(46, 204, 113, .18);
  --red: #e74c3c;
  --red-dim: rgba(231, 76, 60, .18);
  --grey-dim: rgba(138, 148, 163, .16);
  --radius: 8px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg) radial-gradient(1200px 500px at 50% -200px, #1f2630 0%, transparent 70%) no-repeat;
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--red); min-height: 1.2em; margin: 8px 0 0; }

/* top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; border-bottom: 1px solid var(--line); background: rgba(14,17,22,.85);
  position: sticky; top: 0; z-index: 10; backdrop-filter: blur(6px);
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo { color: var(--accent); font-size: 26px; line-height: 1; text-shadow: 0 0 12px rgba(243,156,18,.5); }
.logo.big { font-size: 44px; text-align: center; }
.title { font-weight: 800; letter-spacing: .12em; font-size: 15px; }
.subtitle { color: var(--muted); font-size: 12px; letter-spacing: .04em; }
.who { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.who b { color: var(--accent); }

/* tabs */
.tabs {
  display: flex; gap: 4px; overflow-x: auto; padding: 0 12px; border-bottom: 1px solid var(--line);
  background: var(--bg2); scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  background: none; border: 0; border-bottom: 2px solid transparent; padding: 12px 12px 10px;
  color: var(--muted); cursor: pointer; white-space: nowrap; font-weight: 600; text-transform: uppercase;
  letter-spacing: .06em; font-size: 13px;
}
.tabs button:hover { color: var(--text); }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }

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

h2 { font-size: 20px; margin: 0 0 4px; letter-spacing: .02em; }
h3 { font-size: 16px; margin: 18px 0 8px; color: var(--accent); text-transform: uppercase; letter-spacing: .08em; }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px;
  margin-bottom: 16px;
}
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

.btn {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 8px 14px;
  cursor: pointer; font-weight: 600;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: linear-gradient(180deg, var(--accent), var(--accent2)); border-color: var(--accent); color: #17110a; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--red); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

input, select, textarea {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
label > input, label > select, label > textarea { margin-top: 4px; color: var(--text); }
label.inline { display: flex; align-items: center; gap: 8px; color: var(--text); }
label.inline input { width: auto; }

/* stage chips */
.stage-select { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.chip {
  border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 5px 12px;
  cursor: pointer; font-size: 13px; font-weight: 600;
}
.chip.active { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }
.chip .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 6px; background: var(--muted); }
.chip .dot.open { background: var(--green); }
.chip .dot.locked { background: var(--red); }

/* lock banner */
.lockbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; padding: 12px 14px; border-radius: var(--radius);
  background: var(--accent-dim); border: 1px solid rgba(243,156,18,.35); margin-bottom: 14px;
}
.lockbar.locked { background: var(--red-dim); border-color: rgba(231,76,60,.4); }
.countdown { font-variant-numeric: tabular-nums; font-weight: 800; font-size: 20px; color: var(--accent); letter-spacing: .04em; }
.lockbar.locked .countdown { color: var(--red); }

/* swiss picker */
.counters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; position: sticky; top: 62px; z-index: 5; padding: 6px 0; background: var(--bg); }
.counter { padding: 6px 12px; border-radius: 6px; background: var(--panel); border: 1px solid var(--line); font-weight: 700; font-size: 14px; }
.counter.full { border-color: var(--green); color: var(--green); }
.counter .lbl { color: var(--muted); font-weight: 600; margin-right: 6px; }
.teams { display: grid; grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); gap: 8px; }
.team-row {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius);
}
.team-row.picked { border-color: rgba(243,156,18,.55); }
.team-row .tname { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.team-row .rec { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.tog {
  border: 1px solid var(--line); background: var(--bg2); border-radius: 5px; padding: 5px 9px; cursor: pointer;
  font-weight: 700; font-size: 13px; min-width: 46px;
}
.tog:hover:not(:disabled) { border-color: var(--accent); }
.tog.on { background: var(--accent); border-color: var(--accent); color: #17110a; }
.tog:disabled { cursor: not-allowed; opacity: .35; }
.tog.on:disabled { opacity: 1; }
.tog.correct { background: var(--green); border-color: var(--green); color: #07150d; }
.tog.wrong { background: var(--red); border-color: var(--red); color: #fff; }
.savestate { font-size: 13px; color: var(--muted); }
.savestate.ok { color: var(--green); }
.savestate.err { color: var(--red); }

/* bracket */
.bracket { display: grid; grid-template-columns: repeat(3, minmax(170px, 1fr)); gap: 16px; overflow-x: auto; padding-bottom: 6px; }
.round { display: flex; flex-direction: column; justify-content: space-around; gap: 12px; }
.round-title { text-align: center; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .1em; margin-bottom: 4px; }
.match { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.match .mlabel { font-size: 11px; color: var(--muted); padding: 4px 10px; background: var(--bg2); border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; }
.slot {
  display: block; width: 100%; text-align: left; border: 0; background: none; padding: 9px 10px; cursor: pointer;
  border-bottom: 1px solid var(--line); font-weight: 600; min-height: 38px;
}
.slot:last-child { border-bottom: 0; }
.slot:hover:not(:disabled) { background: var(--panel2); }
.slot:disabled { cursor: default; }
.slot.empty { color: var(--muted); font-style: italic; font-weight: 400; }
.slot.on { background: var(--accent-dim); color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }
.slot.correct { background: var(--green-dim); color: var(--green); box-shadow: inset 3px 0 0 var(--green); }
.slot.wrong { background: var(--red-dim); color: var(--red); box-shadow: inset 3px 0 0 var(--red); }
.slot.won { background: var(--green-dim); color: var(--green); box-shadow: inset 3px 0 0 var(--green); }
.slot.lost { color: var(--muted); text-decoration: line-through; }

/* tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.me td { background: var(--accent-dim); }
.rank { font-weight: 800; color: var(--muted); width: 40px; }
.rank.r1 { color: #ffd34d; } .rank.r2 { color: #cfd6df; } .rank.r3 { color: #d08a4a; }
.total { font-weight: 800; color: var(--accent); font-size: 16px; }

/* pick chips (everyone's picks) */
.pchip { display: inline-block; padding: 2px 8px; border-radius: 4px; margin: 2px 3px 2px 0; font-size: 13px; font-weight: 600; white-space: nowrap; }
.pchip.correct { background: var(--green-dim); color: var(--green); }
.pchip.wrong { background: var(--red-dim); color: var(--red); text-decoration: line-through; }
.pchip.pending { background: var(--grey-dim); color: var(--text); }
.legend { display: flex; gap: 10px; flex-wrap: wrap; margin: 6px 0 12px; font-size: 13px; }
td.picks { white-space: normal; min-width: 200px; }

/* results */
.standings { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 6px; }
.stand { display: flex; justify-content: space-between; padding: 7px 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; }
.stand.adv { border-color: rgba(46,204,113,.5); }
.stand.out { opacity: .55; }
.stand .wl { font-variant-numeric: tabular-nums; font-weight: 700; }
.stand.adv .wl { color: var(--green); }
.stand.out .wl { color: var(--red); }
.mlist { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 4px; }
.mlist li { display: flex; align-items: center; gap: 8px; padding: 6px 10px; background: var(--panel); border-radius: 6px; font-size: 14px; }
.mlist .w { color: var(--green); font-weight: 700; }
.mlist .l { color: var(--muted); }
.mlist .n { color: var(--muted); width: 28px; font-size: 12px; flex: none; }
.mlist .w, .mlist .l { min-width: 0; }
.mlist .w .team, .mlist .l .team { max-width: 100%; }
.mlist .btn { flex: none; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
/* admin: tap-the-winner result entry */
.amatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(280px, 100%), 1fr)); gap: 8px; }
.amatch { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 6px; }
.alabel { font-size: 12px; font-weight: 800; color: var(--accent); margin: 10px 0 6px; }
.aslot { min-height: 52px; min-width: 0; border: 1px solid var(--line); border-radius: 7px; background: var(--panel2); padding: 6px 8px; font-weight: 600; cursor: pointer; display: flex; justify-content: center; align-items: center; }
.aslot .team { min-width: 0; text-align: left; }
.aslot .team .tn { white-space: normal; line-height: 1.15; }
@media (max-width: 420px) { .aslot .seed { display: none; } }
.aslot:hover, .aslot:active { border-color: var(--accent); background: var(--accent-dim); }
.amatch .vs { color: var(--muted); font-size: 12px; }
details.other { margin-top: 12px; }
details.other summary { cursor: pointer; color: var(--muted); font-size: 14px; padding: 6px 0; }
@media (max-width: 760px) {
  .grid2 { grid-template-columns: minmax(0, 1fr); }
  .grid3.stack-sm { grid-template-columns: 1fr; }
  .bracket { grid-template-columns: repeat(3, minmax(150px, 1fr)); }
  main { padding: 12px; }
  .teams { grid-template-columns: 1fr; }
  .subtitle, .hide-sm { display: none; }
  .title { font-size: 13px; }
}

/* overlay / login */
.overlay { position: fixed; inset: 0; background: rgba(5,7,10,.88); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.login-card { width: 100%; max-width: 380px; }
.login-card h1 { text-align: center; margin: 6px 0; font-size: 22px; }
.login-card .btn { width: 100%; margin-top: 6px; padding: 10px; }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%) translateY(80px); background: var(--panel2);
  border: 1px solid var(--line); padding: 10px 16px; border-radius: 8px; transition: transform .2s, opacity .2s; z-index: 60; max-width: 90vw;
  opacity: 0; pointer-events: none;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast.err { border-color: var(--red); color: var(--red); }

.empty-state { text-align: center; padding: 40px 16px; color: var(--muted); }
.badge { display: inline-block; font-size: 11px; padding: 2px 7px; border-radius: 4px; background: var(--panel2); color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 700; }
.badge.open { color: var(--green); background: var(--green-dim); }
.badge.locked { color: var(--red); background: var(--red-dim); }
details > summary { cursor: pointer; font-weight: 700; padding: 4px 0; }
.user-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 8px 0; border-bottom: 1px solid var(--line); }
.user-row .uname { flex: 1; min-width: 120px; font-weight: 600; }

/* team badges */
.team { display: inline-flex; align-items: center; gap: 7px; min-width: 0; vertical-align: middle; }
.team .tn { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.flag { font-size: 14px; line-height: 1; }
.seed { font-size: 11px; color: var(--muted); font-weight: 600; }
.tlogo {
  --s: 28px; position: relative; flex: none; width: var(--s); height: var(--s); border-radius: 6px;
  background: hsl(var(--h) 45% 26%); border: 1px solid hsl(var(--h) 45% 38%);
  display: inline-flex; align-items: center; justify-content: center; overflow: hidden;
}
.tlogo .mono { color: hsl(var(--h) 80% 86%); font-weight: 800; font-size: calc(var(--s) * .36); letter-spacing: -.02em; line-height: 1; }
.tlogo .mono.long { font-size: calc(var(--s) * .28); }
.tlogo img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: var(--panel2); padding: 2px; }
.tlogo.sm { --s: 22px; border-radius: 5px; }
.tlogo.xs { --s: 18px; border-radius: 4px; }
.pchip .tlogo { margin-right: 5px; vertical-align: -4px; }
.team-row .tname { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.opp { font-size: 11px; color: var(--muted); padding-left: 35px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stand { align-items: center; gap: 8px; }
.stand .team { flex: 1; }
.mlist .w .team, .mlist .l .team { gap: 5px; }
.slot .team { max-width: 100%; }
code { background: var(--bg2); padding: 1px 5px; border-radius: 4px; font-size: 12px; }

/* pick mode switch */
.modes { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; margin-bottom: 12px; }
.mode { background: var(--panel); border: 0; padding: 8px 14px; cursor: pointer; font-weight: 700; font-size: 13px; color: var(--muted); }
.mode + .mode { border-left: 1px solid var(--line); }
.mode.active { background: var(--accent-dim); color: var(--accent); }

/* swiss simulator */
.sim { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px 26px; align-items: start; position: relative; }
/* winner/loser arrows between columns (drawn by drawSimArrows) */
.sarrows { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; z-index: 1; }
.sarrows path[data-team] { fill: none; stroke-width: 1.5; opacity: .4; transition: opacity .12s; }
.sarrows path.win { stroke: var(--green); }
.sarrows path.lose { stroke: var(--red); }
.sarrows marker.win path { fill: var(--green); }
.sarrows marker.lose path { fill: var(--red); }
.sarrows.dim path[data-team] { opacity: .08; }
.sarrows.dim path.hl { opacity: 1; stroke-width: 2.25; }
.scol { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.shead { display: flex; align-items: center; justify-content: space-between; gap: 6px; min-height: 30px;
  font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; }
.stools { display: flex; gap: 4px; }
.stools .btn { padding: 2px 8px; font-size: 12px; text-transform: none; letter-spacing: 0; }
.spool { display: flex; flex-direction: column; gap: 6px; }
.splabel { font-size: 12px; font-weight: 800; color: var(--accent); letter-spacing: .04em; margin-top: 2px; }
.smatch { background: var(--panel); border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
/* Every slot (empty, waiting or picked) has the same height so the bracket doesn't jump while picking. */
.smatch .slot { padding: 0 8px; height: 35px; min-height: 0; font-size: 13px; display: flex; align-items: center; }
.smatch .slot .team { gap: 6px; }
.smatch .slot.lost { text-decoration: none; opacity: .45; }
.smatch.ghost .slot { justify-content: center; color: var(--line); font-style: normal; }
.smatch.has-waiting { border-style: dashed; }
.smatch.ghost .slot.waiting { justify-content: flex-start; color: var(--text); cursor: default; }
.sbox { border-radius: 8px; padding: 8px 10px 10px; }
.sbox.win { background: var(--green-dim); border: 1px solid rgba(46,204,113,.45); }
.sbox.lose { background: var(--red-dim); border: 1px solid rgba(231,76,60,.45); }
.sblabel { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; margin: 2px 0 6px; }
.sbox.win .sblabel { color: var(--green); }
.sbox.lose .sblabel { color: var(--red); }
.sbteams { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.sbteam { display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 11px; font-weight: 600; min-width: 0; }
.sbteam > span:last-child { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tlogo.q { --h: 220; background: rgba(255,255,255,.06); border-style: dashed; border-color: rgba(255,255,255,.18); color: var(--muted); font-weight: 800; }
.tlogo.md { --s: 30px; }
@media (max-width: 760px) {
  .sim { grid-template-columns: 1fr; }
  .spool { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
  .splabel { grid-column: 1 / -1; }
  .sbteams { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}
