:root {
  --bg:       #1d1f23;
  --bg-2:     #292a2e;
  --bg-3:     #34363a;
  --bg-4:     #3d3f44;
  --row:      #2a2c30;
  --row-alt:  #2f3135;
  --border:   #1a1b1f;
  --text:     #e6e6e6;
  --text-dim: #8b8d92;
  --accent:   #5aa9ff;
  --accent-2: #3b82f6;
  --good:     #4ade80;
  --bad:      #ef4444;
  --warn:     #f59e0b;
  --gold:     #facc15;
  --shadow:   0 2px 6px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
               Ubuntu, sans-serif;
  font-size: 13px;
  min-height: 100vh;
}

/* ─── Top bar ─── */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 22px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-wrap: wrap;
  gap: 12px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.2px;
}

.badge {
  background: var(--accent);
  color: #061224;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}
.badge.results { background: var(--gold); color: #2a1f00; }

.actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.stats {
  font-size: 12px;
  color: var(--text-dim);
  display: flex;
  gap: 16px;
  background: var(--bg-3);
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
}
.stats strong { color: var(--text); }

.btn {
  border: 1px solid var(--border);
  background: var(--bg-3);
  color: var(--text);
  padding: 7px 13px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 4px;
  cursor: pointer;
  transition: 120ms;
}
.btn:hover { background: var(--bg-4); }
.btn.primary {
  background: var(--accent-2);
  border-color: var(--accent-2);
  color: #fff;
}
.btn.primary:hover { background: var(--accent); border-color: var(--accent); }
.btn.primary:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.warn  { background: var(--warn); border-color: var(--warn); color: #2a1f00; }
.btn.ghost { background: transparent; }
.btn.ghost:hover { color: var(--bad); border-color: var(--bad); }

.hidden { display: none !important; }

/* ─── Banner "match en cours" ─── */
.current-banner {
  margin: 14px 22px 0;
  padding: 11px 16px;
  background: linear-gradient(90deg, rgba(90, 169, 255, 0.18), rgba(90, 169, 255, 0.04));
  border: 1px solid var(--accent);
  border-radius: 6px;
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 14px;
}
.cb-tag {
  background: var(--accent);
  color: #061224;
  padding: 4px 9px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}
.cb-text strong { color: var(--accent); font-weight: 700; }

/* ─── Bracket layout ─── */
:root {
  --row-h: 105px;      /* height of one grid row in LB section */
  --col-gap: 36px;     /* horizontal gap between columns (= connector width × 2) */
  --conn: rgba(255,255,255,0.22);
}

.bracket-root {
  padding: 18px 22px 40px;
}

/* UB section sits centered above the LB grid */
.ub-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 18px;
}
.section-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.4px;
  color: #d6d6d6;
  padding: 8px 14px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 3px;
  margin-bottom: 6px;
  width: clamp(260px, 28%, 360px);
  text-align: left;
}
.ub-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: clamp(260px, 28%, 360px);
}

/* LB section: 5-column grid with fixed row height for connector alignment */
.lb-headers {
  display: grid;
  grid-template-columns: repeat(5, minmax(190px, 1fr));
  column-gap: var(--col-gap);
  margin-bottom: 6px;
}
.lb-headers > span {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.4px;
  color: #d6d6d6;
  padding: 8px 14px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 3px;
}

.lb-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(190px, 1fr));
  grid-template-rows: repeat(7, var(--row-h));
  column-gap: var(--col-gap);
  position: relative;
}
.lb-grid > .match { align-self: center; position: relative; }

/* ─── Match block ─── */
.match {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 3px;
  overflow: hidden;
  box-shadow: var(--shadow);
  margin-bottom: 4px;
  position: relative;
}

.team {
  display: flex;
  align-items: center;
  padding: 7px 10px;
  gap: 10px;
  background: var(--row);
  border-bottom: 1px solid var(--border);
  min-height: 36px;
}
.team:nth-child(2) { background: var(--row-alt); }
.team:last-of-type { border-bottom: none; }

.team-logo {
  width: 22px;
  height: 22px;
  object-fit: contain;
  flex-shrink: 0;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.3));
}

.team-name {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #d6d6d6;
}

.team.placeholder .team-name {
  color: var(--text-dim);
  font-style: italic;
  font-weight: 400;
}

.team.winner {
  background: linear-gradient(90deg, rgba(74, 222, 128, 0.08), transparent 60%);
}
.team.winner .team-name { color: var(--good); font-weight: 700; }
.team.loser .team-name  { color: #5b5e64; }

/* Score input ─ minimal, like a counter cell */
.score {
  width: 38px;
  text-align: center;
  background: var(--bg-4);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px;
  border-radius: 3px;
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
}
.score::-webkit-outer-spin-button,
.score::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.score:focus { outline: none; border-color: var(--accent); background: var(--bg-2); }
.score.invalid {
  border-color: var(--bad);
  background: rgba(239, 68, 68, 0.12);
  color: var(--bad);
}
.score:disabled { opacity: 0.45; cursor: not-allowed; }

/* Meta + status: very subtle footer */
.match-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 3px 10px;
  background: var(--bg-3);
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 0.4px;
  border-top: 1px solid var(--border);
  min-height: 18px;
}
.match-label { font-weight: 600; text-transform: uppercase; display: flex; align-items: center; }
.prediction-tag { font-style: italic; }
.prediction-tag em { color: var(--gold); font-style: normal; font-weight: 600; }

.match-status {
  padding: 3px 10px;
  font-size: 10px;
  text-align: center;
  background: var(--bg-3);
  color: var(--text-dim);
  border-top: 1px solid var(--border);
  letter-spacing: 0.3px;
  min-height: 0;
}
.match-status:empty { display: none; }
.match-status.ok      { color: var(--good); }
.match-status.bad     { color: var(--bad); }
.match-status.partial { color: var(--warn); }
.match-status.exact   { color: var(--gold); font-weight: 700; }

/* Play-order number on the left of the label */
.play-num {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 3px;
  padding: 1px 5px;
  margin-right: 6px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

/* ─── Grand Final accent ─── */
.match[data-id="GF"] { border-color: rgba(250, 204, 21, 0.35); }
.match[data-id="GF"] .match-meta {
  background: rgba(250, 204, 21, 0.08);
  color: var(--gold);
}

/* ─── Current match highlight (results mode) ─── */
.match.current {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 0 18px rgba(90, 169, 255, 0.18);
}
.match.current .match-meta {
  background: rgba(90, 169, 255, 0.15);
  color: var(--accent);
}
.match.current .play-num {
  background: var(--accent);
  color: #061224;
  border-color: var(--accent);
}
.match.done { opacity: 0.95; }

/* ─── Toast ─── */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-3);
  border: 1px solid var(--border);
  padding: 10px 16px;
  border-radius: 6px;
  font-size: 13px;
  box-shadow: var(--shadow);
  z-index: 100;
}
.toast.err { border-color: var(--bad); color: var(--bad); }
.toast.ok  { border-color: var(--good); color: var(--good); }

/* ─── Connector lines (bottom bracket) ─────────────────────────
   All connectors live in the column-gap area to the LEFT or RIGHT
   of a match, using ::before (incoming) and ::after (outgoing).
   The "}" shape is made of a vertical border-right plus a horizontal
   border-top/bottom on the same pseudo-element.
*/

/* Incoming horizontal stub (left side of receiver) */
.lb-grid .match[data-id="LBR2_1"]::before,
.lb-grid .match[data-id="LBR2_2"]::before,
.lb-grid .match[data-id="LBQF1"]::before,
.lb-grid .match[data-id="LBQF2"]::before,
.lb-grid .match[data-id="SF1"]::before,
.lb-grid .match[data-id="SF2"]::before,
.lb-grid .match[data-id="GF"]::before {
  content: '';
  position: absolute;
  top: 50%;
  right: 100%;
  width: calc(var(--col-gap) / 2);
  height: 0;
  border-top: 1px solid var(--conn);
}

/* Single horizontal outgoing stub (1-to-1 forwards) */
.lb-grid .match[data-id="LBR2_1"]::after,
.lb-grid .match[data-id="LBR2_2"]::after,
.lb-grid .match[data-id="LBQF1"]::after,
.lb-grid .match[data-id="LBQF2"]::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 100%;
  width: calc(var(--col-gap) / 2);
  height: 0;
  border-top: 1px solid var(--conn);
}

/* "}" connector — top half of pair: goes right then DOWN to midpoint */
.lb-grid .match[data-id="LBR1_1"]::after,
.lb-grid .match[data-id="LBR1_3"]::after,
.lb-grid .match[data-id="SF1"]::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 100%;
  width: calc(var(--col-gap) / 2);
  border-top: 1px solid var(--conn);
  border-right: 1px solid var(--conn);
}

/* "}" connector — bottom half of pair: goes right then UP to midpoint */
.lb-grid .match[data-id="LBR1_2"]::after,
.lb-grid .match[data-id="LBR1_4"]::after,
.lb-grid .match[data-id="SF2"]::after {
  content: '';
  position: absolute;
  bottom: 50%;
  left: 100%;
  width: calc(var(--col-gap) / 2);
  border-bottom: 1px solid var(--conn);
  border-right: 1px solid var(--conn);
}

/* Heights for the vertical segments:
   - LBR1 pair → LBR2 midpoint  : distance = 1 row (var(--row-h))
   - SF  pair → GF  midpoint    : distance = 2 rows
*/
.lb-grid .match[data-id="LBR1_1"]::after,
.lb-grid .match[data-id="LBR1_2"]::after,
.lb-grid .match[data-id="LBR1_3"]::after,
.lb-grid .match[data-id="LBR1_4"]::after {
  height: var(--row-h);
}
.lb-grid .match[data-id="SF1"]::after,
.lb-grid .match[data-id="SF2"]::after {
  height: calc(var(--row-h) * 2);
}

/* Slot fed by an UB QF loser (cross-down): mark with dashed accent so the user
   sees that this team came from above rather than from the left-flowing bracket. */
.team.from-loser { border-left: 2px dashed var(--warn); }
.team.from-loser .team-name { color: var(--warn); }

/* ─── Responsive fallback: stack everything ─── */
@media (max-width: 1100px) {
  .lb-grid {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: none;
  }
  .lb-grid > .match,
  .lb-headers { grid-row: auto !important; }
  .lb-grid .match::before,
  .lb-grid .match::after { display: none; }
  .lb-headers { display: none; }
}
@media (max-width: 640px) {
  .lb-grid { grid-template-columns: 1fr; }
  .ub-row, .ub-section .section-title { width: 100%; }
  .topbar  { flex-direction: column; align-items: stretch; }
}
