:root {
  --bg: #1a1a2e;
  --surface: #16213e;
  --surface2: #0f3460;
  --accent: #e94560;
  --accent2: #f5a623;
  --text: #eaeaea;
  --text-muted: #888;
  --gold: #ffd700;
  --silver: #c0c0c0;
  --bronze: #cd7f32;
  --radius: 8px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

header {
  background: var(--surface2);
  padding: 1rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 3px solid var(--accent);
  flex-wrap: wrap;
  gap: 1rem;
}

header h1 { font-size: 1.6rem; color: var(--accent2); }

nav { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.nav-btn {
  background: transparent;
  border: 2px solid var(--accent);
  color: var(--text);
  padding: 0.4rem 1rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 0.2s;
}
.nav-btn:hover, .nav-btn.active {
  background: var(--accent);
  color: #fff;
}

main { padding: 2rem; max-width: 1100px; margin: 0 auto; }

.view { display: none; }
.view.active { display: block; }

/* Controls */
.controls {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.controls label { font-weight: 600; color: var(--accent2); }

select, input[type="text"], input[type="date"], input[type="number"], input[type="password"] {
  background: var(--surface);
  border: 1px solid var(--surface2);
  color: var(--text);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  font-size: 0.95rem;
  min-width: 200px;
}

select:focus, input:focus {
  outline: none;
  border-color: var(--accent);
}

/* Cup sections */
.cup-section { margin-bottom: 2rem; }

.cup-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent2);
  padding: 0.5rem 0;
  border-bottom: 2px solid var(--surface2);
  margin-bottom: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Course cards */
.course-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 0.75rem;
}

.course-name {
  font-weight: 600;
  font-size: 1rem;
  margin-bottom: 0.5rem;
  color: var(--text);
}

.records-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.records-table th {
  text-align: left;
  color: var(--text-muted);
  font-weight: 600;
  padding: 0.25rem 0.5rem;
  font-size: 0.8rem;
  text-transform: uppercase;
}

.records-table td {
  padding: 0.35rem 0.5rem;
  border-top: 1px solid var(--surface2);
}

.rank-1 .rank-badge { color: var(--gold); font-weight: 700; }
.rank-2 .rank-badge { color: var(--silver); font-weight: 700; }
.rank-3 .rank-badge { color: var(--bronze); font-weight: 700; }

.no-records { color: var(--text-muted); font-style: italic; font-size: 0.9rem; }

/* Forms */
h2 { margin-bottom: 1.5rem; color: var(--accent2); }

.form-group {
  margin-bottom: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  max-width: 400px;
}

.form-group label { font-size: 0.9rem; font-weight: 600; }
.hint { color: var(--text-muted); font-weight: 400; font-size: 0.8rem; }

.btn-primary, .btn-danger {
  padding: 0.5rem 1.5rem;
  border: none;
  border-radius: var(--radius);
  font-size: 0.95rem;
  cursor: pointer;
  font-weight: 600;
  margin-top: 0.5rem;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #c73652; }
.btn-danger { background: #7f1d1d; color: #fff; }
.btn-danger:hover { background: #991b1b; }

.msg {
  margin-top: 0.75rem;
  font-size: 0.9rem;
  min-height: 1.2em;
}
.msg.success { color: #4ade80; }
.msg.error { color: var(--accent); }

/* Admin */
.admin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.5rem;
}

.admin-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem;
}

.admin-card h3 { margin-bottom: 1rem; color: var(--accent2); }

.admin-card input {
  width: 100%;
  margin-bottom: 0.75rem;
  display: block;
}

/* Seasons */
.seasons-intro {
  color: var(--text-muted);
  margin-bottom: 2rem;
  max-width: 700px;
  line-height: 1.7;
}

.rules-sections {
  display: flex;
  flex-direction: column;
  gap: 2.5rem;
  max-width: 800px;
}

.rules-section h3 {
  color: var(--accent2);
  font-size: 1.05rem;
  padding-bottom: 0.6rem;
  margin-bottom: 1rem;
  border-bottom: 2px solid var(--surface2);
}

.rules-section p {
  font-size: 0.9rem;
  line-height: 1.8;
  color: var(--text);
  margin-bottom: 1rem;
}

.rules-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
}

.rules-table th {
  text-align: left;
  color: var(--text-muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  padding: 0.6rem 1rem;
  background: var(--surface2);
}

.rules-table td {
  padding: 0.65rem 1rem;
  border-top: 1px solid var(--surface2);
}

.rules-label {
  color: var(--text-muted);
  font-weight: 600;
  width: 140px;
  white-space: nowrap;
}

/* Standings */
.standings-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
  max-width: 700px;
  margin-bottom: 0.5rem;
}

.standings-table th {
  text-align: left;
  color: var(--text-muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  padding: 0.4rem 0.75rem;
  border-bottom: 2px solid var(--surface2);
}

.standings-table td {
  padding: 0.6rem 0.75rem;
  border-top: 1px solid var(--surface2);
}

.col-rank { width: 48px; text-align: center; }
.col-pts  { width: 80px; text-align: right; }
.col-power { width: 80px; text-align: right; }
.col-games { width: 70px; text-align: right; }

.standing-row.rank-1 .standing-player { color: var(--gold); font-weight: 700; }
.standing-row.rank-2 .standing-player { color: var(--silver); font-weight: 700; }
.standing-row.rank-3 .standing-player { color: var(--bronze); font-weight: 700; }

.tourney-pts-note {
  font-size: 0.72rem;
  font-weight: 400;
  color: var(--accent2);
  opacity: 0.8;
}

.standings-unqualified-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-style: italic;
  margin: 1.25rem 0 0.5rem;
}

.standings-unqualified td {
  opacity: 0.6;
}

/* Admin game list */
.admin-card-wide {
  grid-column: 1 / -1;
}

.admin-game-controls {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1rem;
  align-items: center;
}

.admin-game-controls select { min-width: 160px; }

.games-list-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
}

.games-list-table th {
  text-align: left;
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid var(--surface2);
}

.games-list-table td {
  padding: 0.4rem 0.5rem;
  border-top: 1px solid var(--surface2);
  vertical-align: top;
}

.games-list-table .game-id {
  color: var(--accent2);
  font-weight: 700;
  width: 40px;
}

/* Position rows (Submit Game) */
.position-rows {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: 400px;
}

.position-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.position-label {
  font-weight: 700;
  min-width: 75px;
  color: var(--accent2);
  font-size: 0.95rem;
}

.position-row select {
  flex: 1;
  min-width: 0;
}

/* Secondary button */
.btn-secondary {
  padding: 0.5rem 1.5rem;
  border: 2px solid var(--surface2);
  border-radius: var(--radius);
  font-size: 0.95rem;
  cursor: pointer;
  font-weight: 600;
  margin-top: 0.5rem;
  background: transparent;
  color: var(--text-muted);
}
.btn-secondary:hover { border-color: var(--text-muted); color: var(--text); }

/* Back button */
.btn-back {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0;
  margin-bottom: 1.25rem;
  display: inline-block;
}
.btn-back:hover { text-decoration: underline; }

/* Tournaments */
.tournaments-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.tournament-list { display: flex; flex-direction: column; gap: 0.75rem; max-width: 600px; }

.tournament-card {
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}
.tournament-card:hover { border-color: var(--accent); }
.tournament-card-left { display: flex; flex-direction: column; gap: 0.25rem; }
.tournament-card-name { font-weight: 700; }
.tournament-card-meta { font-size: 0.82rem; color: var(--text-muted); }

.status-badge {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  white-space: nowrap;
}
.status-active    { background: #1a3a1a; color: #4ade80; }
.status-completed { background: #1a2a3a; color: #60a5fa; }

/* Bracket view */
.bracket-tournament-title {
  margin-bottom: 0.25rem;
}
.bracket-tournament-meta {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
  display: flex;
  gap: 1rem;
  align-items: center;
  flex-wrap: wrap;
}

.tournament-results {
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
  max-width: 360px;
}

.tournament-results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.tournament-results-table th {
  text-align: left;
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  padding: 0.25rem 0.5rem;
  border-bottom: 1px solid var(--surface2);
}

.tournament-results-table td {
  padding: 0.45rem 0.5rem;
  border-top: 1px solid var(--surface2);
}

.bracket-key-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
.bracket-key-row label { font-size: 0.85rem; font-weight: 600; color: var(--text-muted); }
.bracket-key-row input { min-width: 0; width: 200px; font-size: 0.85rem; padding: 0.35rem 0.6rem; }

.bracket-seeds {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 1.5rem;
}
.seed-chip {
  background: var(--surface2);
  border-radius: 4px;
  padding: 0.2rem 0.6rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.seed-chip strong { color: var(--text); }

.matchup-preview-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}
.matchup-preview-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.6rem;
  background: var(--surface2);
  border-radius: 4px;
  margin-bottom: 0.35rem;
  font-size: 0.9rem;
}
.matchup-preview-row.matchup-bye {
  opacity: 0.55;
}
.matchup-vs {
  color: var(--text-muted);
  font-size: 0.75rem;
  flex-shrink: 0;
}

.bracket-layout {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 1.5rem;
  overflow-x: auto;
  padding-bottom: 0.5rem;
}

.bracket-col-title {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--accent2);
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--surface2);
}

.bracket-round { margin-bottom: 1.25rem; }

.round-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.4rem;
}

.match-card {
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  padding: 0.65rem 0.85rem;
  margin-bottom: 0.5rem;
  min-width: 160px;
  max-width: 220px;
}

.match-card.ready {
  border-color: var(--accent);
  cursor: pointer;
}
.match-card.ready:hover { background: #1e1e3a; }

.match-player {
  font-size: 0.88rem;
  padding: 0.15rem 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.match-player.winner { font-weight: 700; color: var(--accent2); }
.match-player.loser  { color: var(--text-muted); text-decoration: line-through; }
.match-player.tbd    { color: var(--text-muted); font-style: italic; }

.match-vs {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.4;
}

.match-ready-hint {
  font-size: 0.7rem;
  color: var(--accent);
  margin-top: 0.25rem;
}

.match-reset-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  margin-bottom: 0.25rem;
}

/* Inline result picker */
.result-picker { margin-top: 0.5rem; }
.result-picker p { font-size: 0.78rem; color: var(--text-muted); margin-bottom: 0.4rem; }
.result-picker-btns { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.result-btn {
  flex: 1;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--text);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.8rem;
  white-space: nowrap;
}
.result-btn:hover { background: var(--accent); color: #fff; }
.result-cancel {
  font-size: 0.72rem;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  margin-top: 0.3rem;
  display: block;
}
.result-cancel:hover { color: var(--text); }

/* Player link */
.player-link {
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-style: dotted;
}
.player-link:hover { opacity: 0.75; }

/* Player History Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  z-index: 1000;
  padding: 2rem 1rem;
  overflow-y: auto;
}

.modal-box {
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  width: 100%;
  max-width: 760px;
  padding: 1.75rem;
  position: relative;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  border-bottom: 2px solid var(--surface2);
  padding-bottom: 1rem;
}

.modal-header h2 { margin: 0; }

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.75rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 0.25rem;
}
.modal-close:hover { color: var(--text); }

.history-season { margin-bottom: 2rem; }

.history-season-title {
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent2);
  margin-bottom: 0.6rem;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.history-table th {
  text-align: left;
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  padding: 0.3rem 0.5rem;
  border-bottom: 1px solid var(--surface2);
}

.history-table td {
  padding: 0.45rem 0.5rem;
  border-top: 1px solid var(--surface2);
  vertical-align: middle;
}

.history-table tr.over-cap td { opacity: 0.4; }

.history-season-total {
  text-align: right;
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 0.4rem;
}

.history-no-games {
  color: var(--text-muted);
  font-style: italic;
  font-size: 0.9rem;
}

/* Mobile */
@media (max-width: 600px) {
  main { padding: 1rem; }

  header { padding: 1rem; }

  nav { width: 100%; }
  .nav-btn { flex: 1 1 calc(50% - 0.25rem); text-align: center; }

  select, input[type="text"], input[type="date"], input[type="number"], input[type="password"] {
    min-width: 0;
    width: 100%;
  }

  .controls { flex-direction: column; align-items: flex-start; }

  /* Hide Date and ID on record board, Date on all-time */
  .col-date, .col-id { display: none; }

  /* Player history modal */
  .modal-box { padding: 1rem; }
  .history-col-opp, .history-col-power, .history-col-mult { display: none; }
}
