/* Reset & base */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --border: #2d3148;
  --accent: #4f8ef7;
  --accent-hover: #6ba3ff;
  --text: #e2e4f0;
  --muted: #737a99;
  --green: #3ecf8e;
  --red: #f56565;
  --yellow: #f6c90e;
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body { background: var(--bg); color: var(--text); font-family: var(--font); font-size: 15px; line-height: 1.5; }

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

/* Navbar */
.navbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
}
.brand { font-weight: 700; font-size: 18px; color: var(--text); }
.brand:hover { text-decoration: none; }
.nav-links { display: flex; align-items: center; gap: 16px; }
.nav-email { color: var(--muted); font-size: 13px; }
.btn-link { background: none; border: none; color: var(--accent); cursor: pointer; font-size: 15px; padding: 0; }
.btn-link:hover { color: var(--accent-hover); }

/* Layout */
.container { max-width: 1200px; margin: 0 auto; padding: 32px 24px; }
.page-header { margin-bottom: 24px; }
.page-header h1 { margin-bottom: 4px; }
.muted { color: var(--muted); font-size: 14px; }
.error { color: var(--red); font-size: 14px; margin-bottom: 8px; }
.action-row { display: flex; gap: 12px; margin-top: 24px; flex-wrap: wrap; align-items: center; }

/* Buttons */
.btn-primary, .btn-outline {
  display: inline-block; padding: 9px 18px; border-radius: var(--radius);
  font-size: 14px; font-weight: 500; cursor: pointer; border: none; transition: background 0.15s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); text-decoration: none; color: #fff; }
.btn-outline { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-outline:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }

/* Forms */
label { display: block; margin-bottom: 6px; font-size: 14px; color: var(--muted); }
input, select {
  display: block; width: 100%; padding: 9px 12px; margin-bottom: 16px;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); font-size: 15px;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }
button[type="submit"] { padding: 9px 18px; }

/* Cards */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px;
}
.center-card { max-width: 420px; margin: 60px auto; }
.center-card h1 { margin-bottom: 12px; }
.center-card p { margin-bottom: 16px; color: var(--muted); }

/* Pool list */
.pool-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; margin-bottom: 24px; }
.pool-list .card h2 { font-size: 18px; margin-bottom: 4px; }
.pool-actions { display: flex; gap: 8px; margin-top: 12px; }

/* Invite box */
.invite-box {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 16px; margin-bottom: 20px; font-size: 14px;
}

/* Member list */
.member-list { list-style: none; margin: 12px 0 24px; }
.member-list li { padding: 6px 0; border-bottom: 1px solid var(--border); }
.badge {
  font-size: 11px; padding: 2px 6px; border-radius: 99px; background: var(--accent);
  color: #fff; margin-left: 8px; font-weight: 600;
}

/* Leaderboard */
.leaderboard-table { width: 100%; border-collapse: collapse; margin-bottom: 8px; }
.leaderboard-table th, .leaderboard-table td {
  padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border);
}
.leaderboard-table th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.my-row { background: rgba(79, 142, 247, 0.08); }

/* ── Bracket layout ──────────────────────────────────────────── */
:root {
  --arm-w: 18px;    /* width of the ] bracket arm */
  --conn-w: 18px;   /* width of the incoming horizontal connector */
  --bracket-line: #c0c8d8;
  --bracket-gap: calc(var(--arm-w) + var(--conn-w));
  --card-bg: #ffffff;
  --card-border: #dde2ec;
  --row-h: 30px;
  /* Minimum slot height = tallest card (2 rows + score row + borders) + slot padding.
     All slots must share the same min-height so flex distributes pairs equally,
     which keeps bracket arms and connectors aligned across rounds. */
  --slot-min-h: calc(2 * var(--row-h) + 32px); /* 92px */
}

.bracket-outer {
  background: #f0f2f8;
  border-radius: 10px;
  padding: 24px 28px 28px;
  overflow-x: auto;
  margin-top: 8px;
}

.bracket {
  display: flex;
  gap: var(--bracket-gap);
  min-width: max-content;
  align-items: stretch;   /* all columns match the tallest (R32) column */
  justify-content: center; /* center columns when viewport is wider than bracket */
}

/* ── Round columns ── */
.bracket-col {
  display: flex;
  flex-direction: column;
  width: 200px;
  flex-shrink: 0;
}

.round-header {
  text-align: center;
  padding: 0 0 14px;
  border-bottom: 2px solid var(--bracket-line);
  margin-bottom: 0;
}
.round-name { font-size: 11px; font-weight: 700; color: #3a4260; text-transform: uppercase; letter-spacing: 0.06em; }
.round-pts  { font-size: 11px; color: var(--accent); margin-top: 2px; }

.round-body {
  display: flex;
  flex-direction: column;
  flex: 1;
}

/* ── Match pairing: groups two sibling matches + draws bracket arm ── */
.match-pair {
  display: flex;
  flex-direction: column;
  flex: 1;
  position: relative;
}

/* Horizontal arm from a solo pair (Final) into the next column (Winner) */
.bracket-col:not(:last-child) .match-pair.solo::after {
  content: '';
  position: absolute;
  left: 100%;
  top: 50%;
  transform: translateY(-1px);
  width: var(--arm-w);
  height: 2px;
  background: var(--bracket-line);
  box-sizing: border-box;
  z-index: 1;
}

/* The ] bracket arm drawn to the right of each pair (except the Final) */
.bracket-col:not(:last-child) .match-pair:not(.solo)::after {
  content: '';
  position: absolute;
  left: 100%;                  /* starts at right edge of column */
  top: calc(25% - 1px);        /* offset -1px so the 2px border's visual center lands on slot center */
  height: calc(50% + 2px);     /* +2px compensates the -1px on each end */
  width: var(--arm-w);
  border-top: 2px solid var(--bracket-line);
  border-right: 2px solid var(--bracket-line);
  border-bottom: 2px solid var(--bracket-line);
  box-sizing: border-box;
  z-index: 1;
}

/* ── Match slot: centers the card vertically, draws incoming connector ── */
.match-slot {
  flex: 1;
  min-height: var(--slot-min-h); /* equal min-height for all slots → equal pair heights → aligned bracket lines */
  display: flex;
  align-items: center;
  padding: 4px 0;
  position: relative;
}

/* Horizontal connector arriving from the left (rounds 2–5) */
.bracket-col:not(:first-child) .match-slot::before {
  content: '';
  position: absolute;
  left: calc(-1 * var(--conn-w));
  top: 50%;
  transform: translateY(-1px); /* center on the 2px line */
  width: var(--conn-w);
  height: 2px;
  background: var(--bracket-line);
  z-index: 1;
}

/* ── Match card ── */
.match-cell {
  width: 100%;
  border: 1px solid var(--card-border);
  border-radius: 6px;
  overflow: hidden;
  background: var(--card-bg);
  box-shadow: 0 1px 4px rgba(0,0,0,0.07);
}

/* ── Team rows ── */
.team-row {
  display: flex;
  align-items: center;
  gap: 7px;
  width: 100%;
  height: var(--row-h);
  padding: 0 8px;
  font-size: 12.5px;
  font-weight: 500;
  color: #1e2540;
  background: transparent;
  border: none;
  font-family: var(--font);
  border-bottom: 1px solid var(--card-border);
  cursor: default;
  text-align: left;
  box-sizing: border-box;
}
.team-row:last-child { border-bottom: none; }

button.team-row { cursor: pointer; transition: background 0.12s; }
button.team-row:hover { background: #eef1fb; }
button.team-row:active { background: #dde4f7; }

.team-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.flag { width: 20px; height: 15px; object-fit: cover; border-radius: 2px; flex-shrink: 0; }

.result-mark { margin-left: auto; font-size: 13px; font-weight: 700; flex-shrink: 0; }

/* State colours */
.row-picked  { background: #eef1fb; color: #2d5bd6; font-weight: 600; }
.row-correct { background: #edfaf4; color: #1a7a4a; font-weight: 600; }
.row-wrong   { background: #fdf0f0; color: #c0392b; }
.row-wrong .team-name, .wrong-name { text-decoration: line-through; }
.row-winner  { color: #2c6e49; font-weight: 600; }
.row-loser   { color: #9aa3bf; }
.row-tbd     { color: #9aa3bf; font-style: italic; cursor: default; }

/* Winner column — wider to fit inline correct-answer display */
.bracket-col.winner-col { width: 250px; }

/* Wrong pick: crossed-out user pick + correct answer on the same line */
.winner-wrong-row { background: #fdf0f0; }
.wrong-pick {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: #c0392b;
  flex-shrink: 0;
}
.correct-inline {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: #1a7a4a;
  font-weight: 600;
}

button.row-picked:hover { background: #dde4f7 !important; }

/* Score separator row */
.score-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 2px 8px;
  background: #f5f7fc;
  border-top: 1px solid var(--card-border);
  border-bottom: 1px solid var(--card-border);
  font-size: 11px;
}

.score-line {
  font-weight: 700;
  color: #2d3148;
  letter-spacing: 0.04em;
}

.score-badge {
  font-size: 9px;
  font-weight: 700;
  padding: 1px 4px;
  border-radius: 3px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.badge-live {
  background: #e53e3e;
  color: #fff;
  animation: live-pulse 1.5s ease-in-out infinite;
}

.badge-ft {
  background: #718096;
  color: #fff;
}

.match-live {
  border-color: #e53e3e;
  box-shadow: 0 0 0 1px #e53e3e33;
}

@keyframes live-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.55; }
}

/* HTMX spinner */
.htmx-spinner {
  display: none; position: fixed; bottom: 20px; right: 20px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 8px 14px; font-size: 13px; color: var(--muted);
}
.htmx-request .htmx-spinner { display: block; }

/* Simulation progress bar */
.sim-loading {
  padding: 48px 0 32px;
  max-width: 460px;
}

.sim-bar-track {
  width: 100%;
  height: 8px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}

.sim-bar {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 99px;
  animation: sim-fill 10s cubic-bezier(0.15, 0.05, 0.25, 0.95) forwards;
}

@keyframes sim-fill {
  0%   { width: 0%; }
  70%  { width: 85%; }
  100% { width: 92%; }
}

/* Simulation */
.prob-bar-wrap { display: flex; align-items: center; gap: 8px; }
.prob-bar {
  height: 8px; background: var(--accent); border-radius: 99px;
  min-width: 2px; transition: width 0.3s;
}
.prob-bar-wrap span { font-size: 13px; white-space: nowrap; }

.pivotal-list { display: flex; flex-direction: column; gap: 16px; margin-top: 12px; }
.pivotal-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px;
}
.pivotal-teams { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.vs { color: var(--muted); font-weight: 400; margin: 0 6px; }
.pivotal-score { margin-bottom: 12px; }
.pivotal-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.pivotal-table th, .pivotal-table td { padding: 6px 8px; border-bottom: 1px solid var(--border); }
.pivotal-table th { color: var(--muted); font-weight: 500; }

.tooltip-trigger {
  cursor: help;
  border-bottom: 1px dotted var(--muted);
  position: relative;
}
.tooltip-trigger::after {
  content: attr(data-tooltip);
  display: none;
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: #1e2133;
  color: #e8eaf6;
  font-size: 12px;
  line-height: 1.4;
  padding: 7px 10px;
  border-radius: 5px;
  width: 260px;
  white-space: normal;
  z-index: 100;
  pointer-events: none;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}
.tooltip-trigger:hover::after { display: block; }
