:root {
  --bg: #0e0f13;
  --panel: #1a1d24;
  --panel-2: #21252e;
  --line: #2c313c;
  --text: #e9ecf1;
  --muted: #8b93a3;
  --accent: #36c98e;
  --accent-dim: #1f6f53;
  --danger: #e0524b;
  --gold: #f5c542;
  --silver: #c7cdd6;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: radial-gradient(1200px 600px at 50% -10%, #1a1f2b 0%, var(--bg) 60%);
  color: var(--text);
  min-height: 100vh;
}

/* ---- top bar ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: rgba(14, 15, 19, 0.85);
  backdrop-filter: blur(8px);
  z-index: 5;
}
.topbar h1 { margin: 0; font-size: 1.5rem; letter-spacing: 0.5px; }
.topbar-actions { display: flex; gap: 0.6rem; align-items: center; }

/* ---- board / brackets ---- */
/* The board is a single horizontally-scrolling canvas. Everything lives inside
   .board-inner, which sizes to its content so the connector SVG can overlay the
   whole bracket in one coordinate space (see connectors.js). */
.board { padding: 1.5rem; overflow-x: auto; }
.board-inner {
  position: relative;
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 3rem;
  width: max-content;
  min-width: 100%;
}

/* SVG overlay holding the feeder lines. Sits behind the heat cards so lines
   appear to emerge from the card edges; never intercepts clicks. */
.connectors {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
  z-index: 0;
}
.connectors path { fill: none; stroke-width: 2; stroke-linecap: round; }
.connectors .link { stroke: #4a566b; }
.connectors .live { stroke: var(--accent); opacity: 0.9; }

.bracket {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
}

.bracket-title {
  margin: 0 0 1rem;
  font-size: 1.1rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--muted);
  border-left: 3px solid var(--accent);
  padding-left: 0.6rem;
}

.columns {
  display: flex;
  gap: 2.5rem;
  align-items: stretch;
  padding-bottom: 0.5rem;
}

/* A round: a fixed label pinned to the top, then its heats centered as a group
   in the remaining height. align-items:stretch above makes every column the
   same height (the tallest round), so later rounds with fewer heats sit
   centered against the round that feeds them — a proper bracket shape. */
.column {
  display: flex;
  flex-direction: column;
  min-width: 210px;
}
.column-heats {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1rem;
}

.column-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--muted);
  text-align: center;
  margin-bottom: 0.85rem;
}

/* ---- heat card ---- */
.heat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.75rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}
.heat-ready { border-color: var(--accent-dim); }
.heat-played { border-color: var(--accent); }
.heat-pending { opacity: 0.7; }

.heat-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}
.heat-title { font-weight: 600; font-size: 0.95rem; }
.badge { color: var(--accent); font-weight: 700; }

.slots { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; }
.slot {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--panel-2);
  border-radius: 6px;
  padding: 0.35rem 0.5rem;
  font-size: 0.9rem;
}
.slot-tbd .slot-name { color: var(--muted); font-style: italic; }

.place {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.3rem;
  height: 1.3rem;
  border-radius: 50%;
  font-size: 0.75rem;
  font-weight: 700;
  background: var(--line);
  color: var(--text);
  flex: none;
}
.place-1 { background: var(--gold); color: #2a2200; }
.place-2 { background: var(--silver); color: #20242b; }

/* ---- buttons ---- */
.btn {
  font: inherit;
  font-size: 0.85rem;
  padding: 0.45rem 0.8rem;
  border: 0;
  border-radius: 7px;
  background: var(--accent);
  color: #04130d;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { filter: brightness(1.08); }
.btn-report { margin-top: 0.6rem; width: 100%; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }

/* ---- modals ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1.5rem;
  width: min(420px, 92vw);
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
#players-modal .modal { width: min(560px, 94vw); }
.modal h3 { margin: 0 0 0.4rem; }
.modal-hint { margin: 0 0 1rem; color: var(--muted); font-size: 0.85rem; }
.modal-actions { display: flex; gap: 0.6rem; justify-content: flex-end; margin-top: 1.2rem; align-items: center; }

/* ---- edit-players list ---- */
.player-edit {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  max-height: 60vh;
  overflow-y: auto;
}
.player-edit li { display: flex; align-items: center; gap: 0.5rem; }
.player-edit .seed-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  background: var(--line);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  flex: none;
}
.player-edit input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 0.85rem;
  padding: 0.35rem 0.5rem;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
}
.player-edit input:focus { outline: none; border-color: var(--accent); }
@media (max-width: 520px) { .player-edit { grid-template-columns: 1fr; } }

/* ---- reorder list ---- */
.reorder { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.reorder li {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.5rem 0.6rem;
  cursor: grab;
}
.reorder li.dragging { opacity: 0.5; border-color: var(--accent); }
.reorder .rank {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  background: var(--accent);
  color: #04130d;
  font-weight: 700;
  font-size: 0.8rem;
  flex: none;
}
.reorder .rname { flex: 1; }
.reorder .arrows { display: flex; flex-direction: column; gap: 2px; }
.reorder .arrows button {
  font: inherit;
  line-height: 1;
  background: var(--line);
  color: var(--text);
  border: 0;
  border-radius: 4px;
  width: 1.4rem;
  height: 0.9rem;
  cursor: pointer;
  padding: 0;
}
.reorder .arrows button:disabled { opacity: 0.3; cursor: default; }
.reorder .grip { color: var(--muted); cursor: grab; }

/* ---- global leaderboard (fixed bottom-right HUD) ---- */
.leaderboard {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  width: 250px;
  max-height: min(60vh, 520px);
  display: flex;
  flex-direction: column;
  background: rgba(26, 29, 36, 0.94);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
  z-index: 10;
  overflow: hidden;
}
.leaderboard-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--line);
}
.leaderboard-head h2 {
  margin: 0;
  font-size: 0.95rem;
  letter-spacing: 0.5px;
}
.leaderboard-toggle {
  font: inherit;
  font-size: 1.1rem;
  line-height: 1;
  width: 1.6rem;
  height: 1.6rem;
  border: 0;
  border-radius: 6px;
  background: var(--line);
  color: var(--text);
  cursor: pointer;
}
.leaderboard.collapsed .leader-list { display: none; }

.leader-list {
  list-style: none;
  margin: 0;
  padding: 0.4rem;
  overflow-y: auto;
}
.leader-row {
  display: grid;
  grid-template-columns: 1.6rem 1fr auto auto;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.5rem;
  border-radius: 7px;
  font-size: 0.88rem;
}
.leader-row:nth-child(odd) { background: rgba(255, 255, 255, 0.03); }
.leader-rank { color: var(--muted); font-weight: 700; text-align: center; }
.leader-row:nth-child(1) .leader-rank { color: var(--gold); }
.leader-row:nth-child(2) .leader-rank { color: var(--silver); }
.leader-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leader-meta { color: var(--muted); font-size: 0.72rem; }
.leader-pts {
  font-weight: 700;
  color: var(--accent);
  min-width: 1.6rem;
  text-align: right;
}
.leader-champion { background: rgba(245, 197, 66, 0.12); }
.leader-champion .leader-name { color: var(--gold); font-weight: 600; }

@media (max-width: 640px) {
  .leaderboard { width: 200px; right: 0.5rem; bottom: 0.5rem; }
}
