:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface2: #1c2128;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #7d8590;
  --accent: #f0883e;
  --accent-hover: #d4793a;
  --success: #3fb950;
  --danger: #f85149;
  --warning: #d29922;
  --info: #58a6ff;
  --qualified-bg: rgba(63, 185, 80, 0.1);
  --qualified-border: rgba(63, 185, 80, 0.4);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 16px;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Layout */
.container { max-width: 900px; margin: 0 auto; padding: 1rem; }
.container-wide { max-width: 1400px; margin: 0 auto; padding: 1rem; }

/* Header */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.header-title { font-size: 1.1rem; font-weight: 700; color: var(--accent); }
.header-nav { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.header-nav a {
  color: var(--text-muted);
  font-size: 0.9rem;
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
  transition: background 0.15s, color 0.15s;
}
.header-nav a:hover, .header-nav a.active {
  background: var(--surface2);
  color: var(--text);
  text-decoration: none;
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem;
  margin-bottom: 1rem;
}
.card-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.8rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  border: 1px solid transparent;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary { background: var(--surface2); border-color: var(--border); color: var(--text); }
.btn-secondary:hover:not(:disabled) { background: var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { opacity: 0.85; }
.btn-success { background: var(--success); color: #fff; }
.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.8rem; }

/* Forms */
.form-group { margin-bottom: 0.85rem; }
.form-label { display: block; font-size: 0.85rem; color: var(--text-muted); margin-bottom: 0.3rem; }
.form-input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  color: var(--text);
  font-size: 0.95rem;
  transition: border-color 0.15s;
}
.form-input:focus { outline: none; border-color: var(--accent); }
.form-input::placeholder { color: var(--text-muted); }
.form-row { display: flex; gap: 0.75rem; }
.form-row .form-group { flex: 1; }

/* Tables */
.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table th {
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.table td { padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--border); }
.table tr:last-child td { border-bottom: none; }
.table tr.qualified { background: var(--qualified-bg); }
.table tr.qualified td:first-child { border-left: 3px solid var(--success); }

/* Badge */
.badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge-success { background: rgba(63,185,80,0.15); color: var(--success); }
.badge-warning { background: rgba(210,153,34,0.15); color: var(--warning); }
.badge-danger { background: rgba(248,81,73,0.15); color: var(--danger); }
.badge-info { background: rgba(88,166,255,0.15); color: var(--info); }
.badge-muted { background: var(--surface2); color: var(--text-muted); }

/* Status dots */
.status-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-right: 6px;
}
.status-dot.pending { background: var(--text-muted); }
.status-dot.done { background: var(--success); }

/* Tabs */
.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--border); margin-bottom: 1.5rem; }
.tab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  padding: 0.75rem 1rem;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: color 0.15s, border-color 0.15s;
  margin-bottom: -1px;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* Score input */
.score-form {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
}
.score-team { flex: 1; font-weight: 600; }
.score-team.right { text-align: right; }
.score-input {
  width: 65px;
  text-align: center;
  font-size: 1.3rem;
  font-weight: 700;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem;
  color: var(--text);
}
.score-input:focus { outline: none; border-color: var(--accent); }
.score-vs { color: var(--text-muted); font-weight: 700; }

/* Mobile score stepper */
.score-stepper {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.score-stepper-btn {
  width: 36px; height: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 1.3rem;
  font-weight: 700;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.12s, border-color 0.12s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}
.score-stepper-btn:active { background: var(--border); border-color: var(--accent); }
.score-stepper-input {
  width: 56px;
  text-align: center;
  font-size: 1.4rem;
  font-weight: 700;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.3rem 0.2rem;
  color: var(--text);
  -moz-appearance: textfield;
}
.score-stepper-input::-webkit-outer-spin-button,
.score-stepper-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.score-stepper-input:focus { outline: none; border-color: var(--accent); }

/* Mobile score form layout */
.mobile-score-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.mobile-score-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.85rem 1rem;
}
.mobile-score-team-name {
  flex: 1;
  font-weight: 700;
  font-size: 1rem;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mobile-score-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  margin-top: 0.25rem;
}

/* Match card */
.match-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.85rem 1rem;
  margin-bottom: 0.5rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.match-item:hover { border-color: var(--accent); background: var(--surface2); }
.match-item.done { opacity: 0.7; cursor: default; }
.match-item.done:hover { border-color: var(--border); background: var(--surface); }
.match-teams { flex: 1; display: flex; align-items: center; gap: 0.5rem; }
.match-team { font-weight: 600; }
.match-score { font-size: 1.1rem; font-weight: 700; color: var(--accent); min-width: 60px; text-align: center; }
.match-meta { font-size: 0.78rem; color: var(--text-muted); text-align: right; }

/* Groups grid */
.groups-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

/* Bracket */
.bracket { display: flex; gap: 0; overflow-x: auto; padding-bottom: 1rem; }
.bracket-round { display: flex; flex-direction: column; justify-content: space-around; min-width: 200px; }
.bracket-round-title {
  text-align: center;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  padding: 0.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.5rem;
}
.bracket-match {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin: 0.4rem 0.5rem;
  overflow: hidden;
}
.bracket-team {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
}
.bracket-team:first-child { border-bottom: 1px solid var(--border); }
.bracket-team.winner { color: var(--success); font-weight: 700; }
.bracket-team.loser { color: var(--text-muted); }
.bracket-team-score { font-weight: 700; }
.bracket-tbd { color: var(--text-muted); font-style: italic; }

/* Alerts */
.alert {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
.alert-danger { background: rgba(248,81,73,0.1); border: 1px solid rgba(248,81,73,0.3); color: var(--danger); }
.alert-success { background: rgba(63,185,80,0.1); border: 1px solid rgba(63,185,80,0.3); color: var(--success); }
.alert-warning { background: rgba(210,153,34,0.1); border: 1px solid rgba(210,153,34,0.3); color: var(--warning); }
.alert-info { background: rgba(88,166,255,0.1); border: 1px solid rgba(88,166,255,0.3); color: var(--info); }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  padding: 1rem;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  width: 100%; max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-title { font-size: 1.1rem; font-weight: 700; margin-bottom: 1.25rem; }
.modal-actions { display: flex; gap: 0.75rem; justify-content: flex-end; margin-top: 1.25rem; }

/* Loading */
.loading { color: var(--text-muted); text-align: center; padding: 2rem; }

/* Responsive */
@media (max-width: 600px) {
  .header { flex-wrap: wrap; }
  .groups-grid { grid-template-columns: 1fr; }
  .score-form { flex-wrap: wrap; }
  .form-row { flex-direction: column; gap: 0; }
  .bracket-round { min-width: 160px; }
  .bracket-team { font-size: 0.8rem; padding: 0.4rem 0.5rem; }

  /* Match cards bigger for touch */
  .match-item {
    padding: 1rem;
    border-radius: 10px;
    margin-bottom: 0.65rem;
  }
  .match-team { font-size: 1rem; }
  .match-score { font-size: 1.2rem; }
  .match-meta { font-size: 0.8rem; }

  /* Stepper buttons bigger on mobile */
  .score-stepper-btn { width: 44px; height: 44px; font-size: 1.5rem; border-radius: 10px; }
  .score-stepper-input { width: 60px; font-size: 1.5rem; padding: 0.4rem 0.2rem; }

  /* Card form padding */
  .card { padding: 1rem; }
  .mobile-score-row { padding: 1rem; }
  .mobile-score-team-name { font-size: 1rem; }
}

/* Searchable player dropdown */
.player-search { position: relative; }
.player-search-dropdown {
  position: absolute;
  top: 100%;
  left: 0; right: 0;
  background: var(--surface2);
  border: 1px solid var(--accent);
  border-top: none;
  border-radius: 0 0 6px 6px;
  max-height: 200px;
  overflow-y: auto;
  z-index: 200;
}
.player-search-option {
  padding: 0.45rem 0.75rem;
  cursor: pointer;
  font-size: 0.9rem;
}
.player-search-option:hover,
.player-search-option.active { background: var(--border); }
.player-search-option .ps-id { color: var(--text-muted); font-size: .78rem; margin-right: .3rem; }

/* Bigscreen specific */
.bigscreen-body {
  font-size: 18px;
  background: #080d14;
  overflow: hidden;
}
.bigscreen-header {
  background: #0d1117;
  border-bottom: 2px solid var(--accent);
  padding: 1rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.bigscreen-title { font-size: 1.8rem; font-weight: 800; color: var(--accent); }
.bigscreen-tournament-name { font-size: 1.1rem; color: var(--text-muted); }
.bigscreen-tabs { display: flex; gap: 0.5rem; }
.bigscreen-tab {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem 1rem;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
}
.bigscreen-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.bigscreen-groups {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
  padding: 1.5rem 2rem;
}
.bigscreen-group { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.bigscreen-group-title {
  background: var(--surface2);
  padding: 0.75rem 1rem;
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.bigscreen .table th { font-size: 0.8rem; }
.bigscreen .table td { font-size: 0.95rem; }
.bigscreen-bracket-wrap {
  padding: 0;
  height: calc(100vh - 80px);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* ── Tournament bracket: outside → center ── */
.bs-bracket {
  display: grid;
  grid-template-columns: 1fr auto auto auto 1fr;
  grid-template-rows: auto auto auto;
  align-items: center;
  gap: 0 0;
  width: 100%;
  height: 100%;
  padding: 1.5rem 2rem;
  box-sizing: border-box;
}

/* Column labels */
.bs-col-qf-left  { grid-column: 1; }
.bs-col-sf-left  { grid-column: 2; }
.bs-col-center   { grid-column: 3; }
.bs-col-sf-right { grid-column: 4; }
.bs-col-qf-right { grid-column: 5; }

.bs-round-label {
  text-align: center;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  padding: 0.4rem 0.5rem 0.8rem;
  white-space: nowrap;
}

/* Match card */
.bs-match {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  min-width: 170px;
  max-width: 220px;
  width: 100%;
}
.bs-team {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.55rem 0.85rem;
  font-size: 0.95rem;
  font-weight: 600;
  gap: 0.5rem;
  min-height: 2.4rem;
}
.bs-team:first-child { border-bottom: 1px solid var(--border); }
.bs-team.winner { color: var(--success); }
.bs-team.loser  { color: var(--text-muted); }
.bs-team-score  { font-weight: 800; font-size: 1rem; flex-shrink: 0; }
.bs-team-name   { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bs-tbd         { color: var(--text-muted); font-style: italic; font-weight: 400; }

/* Finale card — bigger */
.bs-match.finale {
  min-width: 200px;
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 0 24px rgba(240,136,62,0.18);
}
.bs-match.finale .bs-team { font-size: 1.1rem; padding: 0.75rem 1rem; }

/* Platz3 card — slightly muted */
.bs-match.platz3 { border-color: var(--text-muted); opacity: 0.85; min-width: 170px; }

/* Left QF column — matches stacked */
.bs-qf-left {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0;
  width: 100%;
}
/* Right QF column */
.bs-qf-right {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0;
  width: 100%;
}

/* SF columns */
.bs-sf-left, .bs-sf-right {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* Center column */
.bs-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
}

/* Connector wrappers */
.bs-qf-pair {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  position: relative;
  flex: 1;
  width: 100%;
  padding: 0.5rem 0;
}
.bs-qf-pair-right {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  position: relative;
  flex: 1;
  width: 100%;
  padding: 0.5rem 0;
}

/* Connector lines via pseudo-elements */
.bs-connector-left {
  display: flex;
  align-items: stretch;
  width: 100%;
}
.bs-connector-right {
  display: flex;
  align-items: stretch;
  width: 100%;
}

.bs-matches-left {
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
  align-items: flex-end;
  flex: 1;
}
.bs-matches-right {
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
  align-items: flex-start;
  flex: 1;
}

/* The bracket lines SVG overlay */
.bs-lines {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
  overflow: visible;
}

/* Wrapper that includes match + line */
.bs-with-line-left {
  display: flex;
  align-items: center;
  width: 100%;
  justify-content: flex-end;
}
.bs-with-line-right {
  display: flex;
  align-items: center;
  width: 100%;
  justify-content: flex-start;
}
.bs-line-h {
  height: 2px;
  background: var(--border);
  flex-shrink: 0;
}
.bs-line-v-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
}
.bs-line-v {
  width: 2px;
  background: var(--border);
  flex: 1;
}
.bs-line-mid-dot {
  width: 2px;
  height: 2px;
  background: var(--accent);
}

/* Full bracket layout using a grid approach */
.bs-bracket-root {
  display: flex;
  align-items: stretch;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: 1.5rem 2rem;
  box-sizing: border-box;
  gap: 0;
}

.bs-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.bs-col-header {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  padding-bottom: 0.75rem;
  text-align: center;
  white-space: nowrap;
}
.bs-col-matches {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  align-items: center;
  flex: 1;
  width: 100%;
  gap: 1rem;
  position: relative;
}

/* Connector between two adjacent columns */
.bs-connectors {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  align-items: stretch;
  flex: 0 0 32px;
  position: relative;
}
.bs-conn-line {
  flex: 1;
  border-right: 2px solid var(--border);
  position: relative;
}
.bs-conn-line::after {
  content: '';
  position: absolute;
  right: 0;
  top: 50%;
  width: 32px;
  height: 2px;
  background: var(--border);
}
.bs-conn-line-right {
  flex: 1;
  border-left: 2px solid var(--border);
  position: relative;
}
.bs-conn-line-right::after {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  width: 32px;
  height: 2px;
  background: var(--border);
}
