/* ── Variables ─────────────────────────────────────────────────────── */
:root {
  --orange:   #E35205;
  --orange-l: #FF7A35;
  --navy:     #002D72;
  --navy-l:   #1A4A9E;
  --white:    #FFFFFF;
  --gray-50:  #F8F9FA;
  --gray-100: #E9ECEF;
  --gray-200: #DEE2E6;
  --gray-400: #868E96;
  --gray-700: #343A40;
  --green:    #2E7D32;
  --red:      #C62828;
  --yellow:   #F9A825;
  --radius:   8px;
  --shadow:   0 2px 8px rgba(0,0,0,0.12);
}

/* ── Reset ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--gray-50);
  color: var(--gray-700);
  min-height: 100vh;
}

/* ── Navigation ────────────────────────────────────────────────────── */
nav {
  background: var(--navy);
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
nav .logo {
  color: var(--white);
  font-weight: 800;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
}
nav .logo span { color: var(--orange); }
nav .nav-links {
  display: flex;
  gap: 0.25rem;
  align-items: center;
}
nav .nav-links a {
  color: rgba(255,255,255,0.8);
  text-decoration: none;
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  transition: all 0.15s;
}
nav .nav-links a:hover, nav .nav-links a.active {
  background: rgba(255,255,255,0.15);
  color: var(--white);
}
.nav-user {
  color: rgba(255,255,255,0.6);
  font-size: 0.85rem;
}

/* ── Page layout ───────────────────────────────────────────────────── */
.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}
.page-wide {
  margin: 0 auto;
  padding: 1.5rem;
}

/* ── Cards ─────────────────────────────────────────────────────────── */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  border: 1px solid var(--gray-100);
}

/* ── Buttons ───────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 1.1rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
  text-decoration: none;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary  { background: var(--orange); color: var(--white); }
.btn-primary:hover:not(:disabled)  { background: var(--orange-l); }
.btn-navy     { background: var(--navy);   color: var(--white); }
.btn-navy:hover:not(:disabled)     { background: var(--navy-l); }
.btn-outline  { background: transparent; border: 2px solid var(--gray-200); color: var(--gray-700); }
.btn-outline:hover:not(:disabled)  { border-color: var(--orange); color: var(--orange); }
.btn-green    { background: var(--green);  color: var(--white); }
.btn-danger   { background: var(--red);    color: var(--white); }
.btn-sm       { padding: 0.35rem 0.75rem; font-size: 0.8rem; }
.btn-lg       { padding: 0.75rem 1.75rem; font-size: 1rem; }

/* ── Forms ─────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-weight: 600; font-size: 0.85rem; margin-bottom: 0.35rem; color: var(--gray-700); }
input[type=text], input[type=password], input[type=number], select, textarea {
  width: 100%;
  padding: 0.6rem 0.85rem;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius);
  font-size: 0.95rem;
  transition: border-color 0.15s;
  background: var(--white);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--navy);
}
.form-hint { font-size: 0.8rem; color: var(--gray-400); margin-top: 0.3rem; }

/* ── Alerts ────────────────────────────────────────────────────────── */
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  margin-bottom: 1rem;
}
.alert-error   { background: #FFEBEE; color: #B71C1C; border-left: 4px solid var(--red); }
.alert-success { background: #E8F5E9; color: #1B5E20; border-left: 4px solid var(--green); }
.alert-info    { background: #E3F2FD; color: #0D47A1; border-left: 4px solid #1565C0; }
.alert-warn    { background: #FFF8E1; color: #E65100; border-left: 4px solid var(--yellow); }

/* ── Hero / Login page ─────────────────────────────────────────────── */
.hero {
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-l) 60%, var(--orange) 100%);
  color: var(--white);
  text-align: center;
  padding: 4rem 2rem;
}
.hero h1 { font-size: 2.5rem; font-weight: 900; margin-bottom: 0.5rem; color: #ffffff; }
.hero h1 span { color: var(--orange-l); }
.hero p  { font-size: 1.1rem; opacity: 0.85; margin-bottom: 2rem; }
.nickname-chip {
  background: #f1f3f5; border: 1.5px solid #dee2e6; border-radius: 20px;
  padding: 0.25rem 0.65rem; font-size: 0.8rem; cursor: pointer;
  transition: all 0.15s; color: #495057;
}
.nickname-chip:hover { border-color: var(--navy); color: var(--navy); background: #e8edf5; }
.nickname-chip.selected { background: var(--navy); color: #fff; border-color: var(--navy); }
.login-card {
  max-width: 420px;
  margin: 0 auto;
  background: var(--white);
  border-radius: 12px;
  padding: 2rem;
  box-shadow: 0 8px 32px rgba(0,0,0,0.25);
}
.login-card h2 { text-align: center; color: var(--navy); margin-bottom: 1.5rem; font-size: 1.3rem; }
.tab-toggle {
  display: flex;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius);
  margin-bottom: 1.5rem;
  overflow: hidden;
}
.tab-toggle button {
  flex: 1;
  padding: 0.5rem;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--gray-400);
  transition: all 0.15s;
}
.tab-toggle button.active {
  background: var(--navy);
  color: var(--white);
}

/* ── Leaderboard ───────────────────────────────────────────────────── */
.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.leaderboard-table th {
  background: var(--navy);
  color: var(--white);
  padding: 0.75rem 1rem;
  text-align: left;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.leaderboard-table td {
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--gray-100);
}
.leaderboard-table tr:hover td { background: var(--gray-50); }
.leaderboard-table .rank-1 td:first-child { color: #C8960C; font-weight: 800; font-size: 1.1rem; }
.leaderboard-table .rank-2 td:first-child { color: var(--gray-400); font-weight: 800; }
.leaderboard-table .rank-3 td:first-child { color: #804000; font-weight: 800; }
.rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  border-radius: 50%;
  font-weight: 800;
  font-size: 0.85rem;
}
.rank-1 .rank-badge { background: #FFF8DC; color: #B8860B; }
.rank-2 .rank-badge { background: #F5F5F5; color: #606060; }
.rank-3 .rank-badge { background: #FFF0E8; color: #804000; }
.me-row td { background: #FFF3E0 !important; }
.points-current { font-weight: 700; color: var(--navy); font-size: 1rem; }
.points-max { color: var(--gray-400); font-size: 0.85rem; }
.champ-pick {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: var(--navy);
  color: var(--white);
  padding: 0.2rem 0.6rem;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
}

/* ── Bracket ───────────────────────────────────────────────────────── */
.bracket-wrapper {
  overflow-x: auto;
  padding-bottom: 1rem;
}
.bracket {
  display: flex;
  align-items: center;
  gap: 0;
  min-width: 1400px;
  font-size: 0.78rem;
}

/* Each region block */
.region-block {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.region-label {
  font-weight: 800;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--white);
  background: var(--navy);
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
  margin-bottom: 0.5rem;
}

/* Round columns */
.round-col {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
}

/* Game matchup card */
.game {
  display: flex;
  flex-direction: column;
  margin: 2px 2px;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--gray-200);
  background: var(--white);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  width: 155px;
}
.game .team-slot {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 5px 7px;
  cursor: pointer;
  transition: background 0.12s;
  min-height: 28px;
  user-select: none;
  border-bottom: 1px solid var(--gray-100);
}
.game .team-slot:last-child { border-bottom: none; }
.game .team-slot:hover { background: #FFF3E0; }
.game .team-slot.selected {
  background: var(--navy);
  color: var(--white);
}
.game .team-slot.selected .seed-badge { background: var(--orange); color: var(--white); }
.game .team-slot.correct  { background: #E8F5E9 !important; }
.game .team-slot.incorrect { background: #FFEBEE !important; text-decoration: line-through; opacity: 0.7; }
.game .team-slot.actual-winner { background: #E8F5E9 !important; font-weight: 700; }
.game .team-slot.tbd { color: var(--gray-400); font-style: italic; cursor: default; }
.seed-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  border-radius: 3px;
  background: var(--gray-100);
  color: var(--gray-700);
  font-size: 0.7rem;
  font-weight: 700;
  flex-shrink: 0;
}
.team-name { flex: 1; font-size: 0.75rem; font-weight: 500; line-height: 1.2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Finals (center) */
.finals-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 0 0.5rem;
}
.finals-label {
  font-weight: 800;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--gray-400);
  text-align: center;
}
.champ-game .game {
  width: 170px;
  border: 2px solid var(--orange);
}
.champ-game .game .team-slot { min-height: 34px; }
.champ-game .team-name { font-size: 0.85rem; font-weight: 600; }

/* Reversed region (right side reads right-to-left visually) */
.reversed { flex-direction: row-reverse; }
.reversed .round-col { flex-direction: column-reverse; }

/* Region pair grouping */
.region-pair {
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* Score badge on game */
.game .score {
  font-size: 0.7rem;
  color: var(--gray-400);
  padding: 1px 4px;
  text-align: right;
}

/* ── Bracket save bar ──────────────────────────────────────────────── */
.save-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--navy);
  color: var(--white);
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  box-shadow: 0 -4px 16px rgba(0,0,0,0.3);
  z-index: 200;
}
.save-bar .progress {
  font-size: 0.9rem;
  color: rgba(255,255,255,0.7);
}
.save-bar .progress strong { color: var(--white); }
.locked-banner {
  background: var(--orange);
  color: var(--white);
  text-align: center;
  padding: 0.6rem;
  font-weight: 600;
  font-size: 0.9rem;
}

/* ── Rules ─────────────────────────────────────────────────────────── */
.rules-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; }
.prize-card {
  text-align: center;
  padding: 1.5rem;
  border-radius: var(--radius);
  border: 2px solid var(--gray-200);
}
.prize-card.gold   { border-color: #C8960C; background: #FFFDE7; }
.prize-card.silver { border-color: #9E9E9E; background: #F5F5F5; }
.prize-card.bronze { border-color: #8D6E63; background: #FBE9E7; }
.prize-card .place { font-size: 2rem; font-weight: 900; }
.prize-card .amount { font-size: 1.5rem; font-weight: 700; color: var(--navy); }
.scoring-table { width: 100%; border-collapse: collapse; }
.scoring-table th, .scoring-table td { padding: 0.6rem 1rem; border-bottom: 1px solid var(--gray-100); }
.scoring-table th { background: var(--gray-50); font-weight: 600; text-align: left; }
.scoring-table .formula { color: var(--orange); font-weight: 700; }

/* ── Admin ─────────────────────────────────────────────────────────── */
.admin-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 1.5rem; }
.stat-boxes { display: flex; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.stat-box {
  background: var(--navy);
  color: var(--white);
  border-radius: var(--radius);
  padding: 1rem 1.5rem;
  flex: 1;
  min-width: 120px;
  text-align: center;
}
.stat-box .num { font-size: 2rem; font-weight: 800; }
.stat-box .lbl { font-size: 0.75rem; opacity: 0.7; text-transform: uppercase; }
.code-list { font-family: monospace; font-size: 0.85rem; }
.code-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.4rem 0.5rem;
  border-radius: 4px;
}
.code-item:nth-child(odd) { background: var(--gray-50); }
.code-used { opacity: 0.5; text-decoration: line-through; }
.badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge-green  { background: #E8F5E9; color: var(--green); }
.badge-orange { background: #FFF3E0; color: var(--orange); }
.badge-red    { background: #FFEBEE; color: var(--red); }
.badge-gray   { background: var(--gray-100); color: var(--gray-400); }

/* ── Utility ───────────────────────────────────────────────────────── */
h1, h2, h3 { color: var(--navy); }
h1 { font-size: 1.8rem; margin-bottom: 1rem; }
h2 { font-size: 1.3rem; margin-bottom: 0.75rem; }
h3 { font-size: 1rem; margin-bottom: 0.5rem; }
p { line-height: 1.6; }
.text-center { text-align: center; }
.text-muted  { color: var(--gray-400); font-size: 0.85rem; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.flex { display: flex; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
.w-full { width: 100%; }
.spinner {
  display: inline-block;
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Responsive ────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .hero h1 { font-size: 1.8rem; }
  nav { padding: 0 1rem; }
  nav .logo { font-size: 1rem; }
  .page { padding: 1rem; }
  .admin-grid { grid-template-columns: 1fr; }
}
