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

:root {
  --bg:          #0d1117;
  --surface:     #161b22;
  --surface2:    #21262d;
  --border:      #30363d;
  --text:        #e6edf3;
  --text-muted:  #8b949e;
  --pick:        #1f6feb;
  --pick-bg:     rgba(31, 111, 235, 0.12);
  --live:        #3fb950;
  --live-glow:   rgba(63, 185, 80, 0.35);
  --correct:     #3fb950;
  --wrong:       #f85149;
  --wrong-bg:    rgba(248, 81, 73, 0.1);
  --gold:        #d29922;
  --header-h:    56px;
  --bar-h:       52px;
}

html { font-size: 13px; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
.site-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 100;
}

.site-header h1 { font-size: 1.1rem; font-weight: 700; }
.owner { color: var(--text-muted); font-size: 0.85rem; margin-left: 8px; }

.back-btn {
  display: inline-flex;
  align-items: center;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  padding: 3px 8px 3px 4px;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
  white-space: nowrap;
  margin-bottom: 2px;
}
.back-btn:hover { color: var(--text); background: var(--surface2); }

.header-left { display: flex; flex-direction: column; gap: 1px; }

.header-right { display: flex; align-items: center; gap: 16px; }

.score-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 64px;
}
.score-label { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.score-value { font-size: 1.3rem; font-weight: 700; color: var(--gold); }

.update-status {
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: nowrap;
}
.update-status.live-dot::before {
  content: "●";
  color: var(--live);
  margin-right: 4px;
  animation: blink 1.2s ease-in-out infinite;
}

/* ── Scroll wrapper ──────────────────────────────────────────────────────── */
.bracket-scroll-wrapper {
  margin-top: var(--header-h);
  margin-bottom: var(--bar-h);
  overflow-x: auto;
  overflow-y: auto;
  padding: 16px 8px;
  min-height: calc(100vh - var(--header-h) - var(--bar-h));
}

/* ── Bracket container (3 columns: left | center | right) ────────────────── */
.bracket-container {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  grid-template-rows: auto auto;
  gap: 0;
  min-width: 1100px;
  width: max-content;
  margin: 0 auto;
}

/* ── Left / Right bracket halves ─────────────────────────────────────────── */
.bracket-half {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ── Region block ────────────────────────────────────────────────────────── */
.region {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.region-label {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  padding: 4px 8px;
  margin-bottom: 4px;
}

/* ── Round columns ────────────────────────────────────────────────────────── */
.rounds {
  display: flex;
  align-items: stretch;
}

/* Right-side regions reverse direction so rounds progress toward center */
.bracket-half.right .rounds {
  flex-direction: row-reverse;
}

.round-col {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  width: 130px;
  min-width: 130px;
  flex-shrink: 0;
  position: relative;
}

/* ── Game slot ────────────────────────────────────────────────────────────── */
.game-slot {
  display: flex;
  flex-direction: column;
  margin: 2px 4px;
  position: relative;
}

/* Connector lines via pseudo-elements */
.bracket-half.left .game-slot::after {
  content: "";
  position: absolute;
  right: -4px;
  top: 50%;
  width: 4px;
  height: 1px;
  background: var(--border);
}

.bracket-half.right .game-slot::after {
  content: "";
  position: absolute;
  left: -4px;
  top: 50%;
  width: 4px;
  height: 1px;
  background: var(--border);
}

/* ── Team row ─────────────────────────────────────────────────────────────── */
.team-row {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 3px 5px;
  border-radius: 3px;
  background: var(--surface);
  border: 1px solid var(--border);
  min-height: 24px;
  cursor: default;
  transition: background 0.15s;
  position: relative;
}

.team-row + .team-row { margin-top: 1px; }

.seed {
  font-size: 0.65rem;
  color: var(--text-muted);
  width: 14px;
  text-align: right;
  flex-shrink: 0;
}

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

.team-score {
  font-size: 0.8rem;
  font-weight: 700;
  width: 28px;
  text-align: right;
  flex-shrink: 0;
  color: var(--text-muted);
}

/* ── Pick highlight ──────────────────────────────────────────────────────── */
.team-row.is-pick {
  border-left: 3px solid var(--pick);
  background: var(--pick-bg);
}
.team-row.is-pick .team-name { color: #79c0ff; font-weight: 600; }

/* ── Live game ────────────────────────────────────────────────────────────── */
.game-slot.live .team-row {
  border-color: var(--live);
  box-shadow: 0 0 6px var(--live-glow);
}
.game-slot.live .team-row.is-pick {
  border-left-color: var(--live);
}
.game-slot.live .team-score { color: var(--live); }

.live-badge {
  position: absolute;
  top: -9px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--live);
  color: #000;
  font-size: 0.6rem;
  font-weight: 800;
  padding: 1px 5px;
  border-radius: 3px;
  letter-spacing: 0.08em;
  animation: blink 1.2s ease-in-out infinite;
  white-space: nowrap;
}

/* ── Final (completed) ───────────────────────────────────────────────────── */
.team-row.is-winner { font-weight: 700; }
.team-row.is-winner .team-score { color: var(--text); }

.team-row.is-loser {
  opacity: 0.45;
}
.team-row.is-loser .team-name { text-decoration: line-through; }

/* ── Wrong pick (pick was the loser) ─────────────────────────────────────── */
.team-row.is-pick.is-loser {
  border-left-color: var(--wrong);
  background: var(--wrong-bg);
  opacity: 0.65;
}
.team-row.is-pick.is-loser .team-name { color: var(--wrong); }

/* ── Upset advance (team that wasn't the user's pick advances) ───────────── */
.team-row.is-upset-advance {
  border-left: 3px solid var(--wrong);
  background: var(--wrong-bg);
}
.team-row.is-upset-advance .team-name {
  color: #ff7b72;
  font-weight: 600;
}
.team-row.is-upset-advance .seed { color: #ff7b72; }

/* ── Center column: Final Four + Championship ────────────────────────────── */
.center-bracket {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0 8px;
  gap: 12px;
  min-width: 180px;
}

.center-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--gold);
  text-align: center;
  margin-bottom: 4px;
}

.final-four-games {
  display: flex;
  flex-direction: column;
  gap: 24px;
  width: 100%;
}

.ff-game, .championship-game {
  display: flex;
  flex-direction: column;
  gap: 1px;
  position: relative;
}

.championship-game {
  border: 1px solid var(--gold);
  border-radius: 5px;
  padding: 4px;
  background: rgba(210, 153, 34, 0.06);
}

.championship-game .team-row {
  background: transparent;
  border-color: transparent;
}

/* ── Round headers (above each round column) ─────────────────────────────── */
.round-header {
  font-size: 0.62rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  text-align: center;
  padding: 2px 0 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

/* ── Rounds header row ───────────────────────────────────────────────────── */
.rounds-header {
  display: flex;
}
.bracket-half.right .rounds-header { flex-direction: row-reverse; }

.rounds-header .rh-col {
  width: 130px;
  min-width: 130px;
  text-align: center;
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  padding: 2px 4px 6px;
  border-bottom: 1px solid var(--border);
  margin: 0 4px;
}

/* ── Now Playing Bar ──────────────────────────────────────────────────────── */
.now-playing-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--bar-h);
  background: var(--surface);
  border-top: 1px solid var(--live);
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 12px;
  z-index: 100;
  overflow: hidden;
}

.np-label {
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--live);
  letter-spacing: 0.08em;
  white-space: nowrap;
  flex-shrink: 0;
}

.np-games {
  display: flex;
  gap: 16px;
  overflow-x: auto;
  flex: 1;
}

.np-game {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  font-size: 0.78rem;
  padding: 4px 8px;
  background: var(--surface2);
  border-radius: 4px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.np-score {
  font-weight: 700;
  color: var(--live);
}

.np-clock {
  color: var(--text-muted);
  font-size: 0.7rem;
}

/* ── Animations ───────────────────────────────────────────────────────────── */
@keyframes blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

/* ── Scrollbar ────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
