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

:root {
  --bg:        #0d1117;
  --surface:   #161b22;
  --border:    #30363d;
  --accent:    #f85149;
  --gold:      #e3b341;
  --text:      #c9d1d9;
  --muted:     #8b949e;
  --winner-bg: #1c3a1c;
  --loser-bg:  #2d1a1a;
  --winner-fg: #56d364;
  --loser-fg:  #6e3030;
  --input-bg:  #21262d;
  --radius:    4px;
  --font:      'Inter', 'Segoe UI', system-ui, sans-serif;
}

html { font-size: 13px; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  min-height: 100vh;
  padding: 0;
}

/* ─── Header ────────────────────────────────────────────────────────────────── */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}

.header h1 {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--gold);
  white-space: nowrap;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-left: auto;
}

/* ─── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--input-bg);
  color: var(--text);
  cursor: pointer;
  font-size: 0.85rem;
  font-family: inherit;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: #2d333b; border-color: #58a6ff; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary {
  background: #21262d;
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}
.btn-primary:hover:not(:disabled) {
  background: var(--accent);
  color: #fff;
}

.btn-secondary {
  background: #21262d;
  border-color: #58a6ff;
  color: #58a6ff;
  font-weight: 600;
}
.btn-secondary:hover:not(:disabled) {
  background: #58a6ff;
  color: #0d1117;
}

.btn-simulate {
  font-size: 1rem;
  padding: 8px 20px;
}

/* ─── Toggle ────────────────────────────────────────────────────────────────── */
.toggle-label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--muted);
  user-select: none;
}
.toggle-label input[type=checkbox] { accent-color: var(--accent); width: 14px; height: 14px; }
.toggle-label:hover { color: var(--text); }

/* ─── Bracket Wrapper ───────────────────────────────────────────────────────── */
.bracket-wrapper {
  overflow-x: auto;
  padding: 16px 12px 24px;
}

.bracket-container {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  grid-template-rows: auto auto;
  gap: 0;
  min-width: 1100px;
}

/* Left half: East (top) + Midwest (bottom) */
.bracket-left {
  grid-column: 1;
  grid-row: 1 / 3;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Center: Final Four + Championship */
.bracket-center {
  grid-column: 2;
  grid-row: 1 / 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0 8px;
  min-width: 220px;
}

/* Right half: West (top) + South (bottom) */
.bracket-right {
  grid-column: 3;
  grid-row: 1 / 3;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ─── Region Block ──────────────────────────────────────────────────────────── */
.region-block {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  overflow: hidden;
}

.region-title {
  background: #1c2128;
  padding: 6px 12px;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--gold);
  border-bottom: 1px solid var(--border);
}

/* Rounds inside a region go left-to-right (right side regions: right-to-left via CSS) */
.region-rounds {
  display: flex;
  flex-direction: row;
}

.bracket-right .region-rounds {
  flex-direction: row-reverse;
}

/* ─── Round Column ──────────────────────────────────────────────────────────── */
.round-col {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  min-width: 128px;
}
.bracket-right .round-col { border-right: none; border-left: 1px solid var(--border); }
.round-col:last-child { border-right: none; }
.bracket-right .round-col:last-child { border-left: none; }

.round-header {
  background: #1a1f27;
  padding: 4px 8px;
  font-size: 0.72rem;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  text-align: center;
  white-space: nowrap;
}

.round-games {
  display: flex;
  flex-direction: column;
  flex: 1;
  justify-content: space-around;
  padding: 4px 0;
}

/* ─── Game ──────────────────────────────────────────────────────────────────── */
.game {
  display: flex;
  flex-direction: column;
  margin: 3px 0;
  padding: 0 4px;
}

.game-divider {
  height: 1px;
  background: var(--border);
  margin: 0 4px;
}

/* ─── Team Slot ─────────────────────────────────────────────────────────────── */
.team-slot {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 4px;
  min-height: 22px;
  border-radius: 3px;
  transition: background 0.2s;
}
.team-slot.winner { background: var(--winner-bg); }
.team-slot.loser  { background: var(--loser-bg); }

.seed-badge {
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--muted);
  min-width: 16px;
  text-align: right;
  flex-shrink: 0;
}
.team-slot.winner .seed-badge { color: var(--winner-fg); }
.team-slot.loser  .seed-badge { color: var(--loser-fg); }

.team-name {
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-family: inherit;
  font-size: 0.78rem;
  width: 100%;
  padding: 1px 2px;
  border-radius: 2px;
  cursor: default;
}
.team-name:read-only { cursor: default; }
.team-name:not(:read-only) {
  cursor: text;
  border-bottom: 1px solid transparent;
}
.team-name:not(:read-only):focus {
  border-bottom: 1px solid #58a6ff;
  background: #1c2128;
}
.team-slot.winner .team-name { color: var(--winner-fg); font-weight: 600; }
.team-slot.loser  .team-name { color: var(--loser-fg); text-decoration: line-through; }
.team-name::placeholder { color: var(--muted); font-style: italic; }

/* ─── Final Four / Championship ─────────────────────────────────────────────── */
.center-section {
  width: 100%;
}

.center-title {
  text-align: center;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--gold);
  padding: 6px 0 4px;
}

.center-game {
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  margin: 4px 0;
  overflow: hidden;
}

.champion-slot {
  text-align: center;
  padding: 10px 12px;
  border: 1px solid var(--gold);
  border-radius: 4px;
  margin-top: 8px;
  background: #1c1a0a;
  min-height: 46px;
}

.champion-label {
  font-size: 0.7rem;
  color: var(--gold);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.champion-name {
  font-size: 1rem;
  font-weight: 700;
  color: var(--gold);
  margin-top: 2px;
}

/* ─── Bottom Controls ───────────────────────────────────────────────────────── */
.bottom-bar {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.captcha-area {
  margin-right: auto;
}

.export-group {
  display: flex;
  gap: 8px;
}

.status-msg {
  font-size: 0.82rem;
  color: var(--muted);
  padding: 0 8px;
}
.status-msg.error { color: var(--accent); }
.status-msg.success { color: var(--winner-fg); }

/* ─── Pickable slots (later rounds, both teams present) ─────────────────────── */
.team-slot.pickable {
  cursor: pointer;
}
.team-slot.pickable:hover {
  background: rgba(255, 255, 255, 0.04);
}

/* R64 seed badge — click target for manual picks */
.seed-badge {
  cursor: pointer;
  border-radius: 2px;
  transition: background 0.1s;
}
.seed-badge:hover {
  background: rgba(255, 255, 255, 0.12);
}

/* ─── Manual picks — gold instead of green ──────────────────────────────────── */
.team-slot.winner.manual {
  background: #1c1a0a;
  animation: none;
}
.team-slot.winner.manual .team-name  { color: var(--gold); font-weight: 600; }
.team-slot.winner.manual .seed-badge { color: var(--gold); }

/* ─── Animate wins ──────────────────────────────────────────────────────────── */
@keyframes fadeWin {
  from { background: #2ea04360; }
  to   { background: var(--winner-bg); }
}
.team-slot.winner { animation: fadeWin 0.4s ease-out; }

/* ─── Attribution ───────────────────────────────────────────────────────────── */
.attribution-bar {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 8px 20px;
  font-size: 0.75rem;
  color: var(--muted);
  text-align: center;
}
.instructions-bar {
  padding: 6px 20px;
  font-size: 0.72rem;
  color: var(--muted);
  text-align: center;
  line-height: 1.8;
  border-top: 1px solid var(--border);
  background: var(--bg);
}
.instructions-bar strong { color: var(--text); font-weight: 600; }
.instructions-bar em { color: var(--text); font-style: normal; font-weight: 500; }

.attribution-bar a {
  color: #58a6ff;
  text-decoration: none;
}
.attribution-bar a:hover { text-decoration: underline; }

/* ─── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  html { font-size: 11px; }
  .round-col { min-width: 100px; }
}
