:root {
  --green: #1a6b2a;
  --dark: #0d3a18;
  --gold: #d4af37;
  --gold-light: #f0d060;
  --white: #fff;
  --light: #f4f7f4;
  --border: #dde5dd;
  --text: #1a2a1a;
  --muted: #6b7b6b;
  --red: #c0392b;
  --blue: #2980b9;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: linear-gradient(160deg, #0d3a18 0%, #1a6b2a 60%, #0d3a18 100%);
  min-height: 100vh;
  color: var(--text);
  font-size: 15px;
}

/* ---------- HEADER ---------- */
header {
  text-align: center;
  padding: 2rem 1rem 1.5rem;
  color: var(--white);
}
header .subtitle { color: var(--gold-light); font-size: 0.9rem; margin-top: 0.3rem; }
h1 {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--gold);
  text-shadow: 0 2px 8px rgba(0,0,0,0.4);
}
header nav {
  margin-top: 1rem;
  display: flex;
  justify-content: center;
  gap: 0.5rem;
}
header nav a {
  color: rgba(255,255,255,0.8);
  text-decoration: none;
  padding: 0.3rem 0.8rem;
  border-radius: 20px;
  border: 1px solid rgba(255,255,255,0.3);
  font-size: 0.85rem;
  transition: all 0.2s;
}
header nav a:hover, header nav a.active {
  background: var(--gold);
  color: var(--dark);
  border-color: var(--gold);
  font-weight: 600;
}

/* ---------- LAYOUT ---------- */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1rem 3rem;
}

/* ---------- CARDS ---------- */
.card {
  background: var(--white);
  border-radius: 12px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: 0 4px 24px rgba(0,0,0,0.18);
}
.card-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--dark);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 1rem;
  padding-bottom: 0.6rem;
  border-bottom: 2px solid var(--gold);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

/* ---------- TABLES ---------- */
table { width: 100%; border-collapse: collapse; }
th {
  background: var(--dark);
  color: var(--white);
  text-align: left;
  padding: 0.5rem 0.75rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
td {
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--light); }

/* Rank highlights */
.rank-1 td { background: #fffbe6; }
.rank-2 td { background: #f9f9f9; }
.rank-3 td { background: #fff4e6; }
.rank-1:hover td { background: #fff5cc; }

.rank-num {
  font-weight: 800;
  font-size: 1.1rem;
  color: var(--dark);
  width: 36px;
}
.rank-1 .rank-num { color: #b8860b; }
.rank-2 .rank-num { color: #6b7b6b; }
.rank-3 .rank-num { color: #cd853f; }

.pts-cell {
  font-weight: 700;
  font-size: 1rem;
  color: var(--green);
  text-align: right;
}

.team-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0.15rem 0.5rem;
  background: var(--light);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 0.78rem;
  white-space: nowrap;
}
.chip.advanced { background: #e6f4ea; border-color: #a5d6a7; }
.chip.eliminated { opacity: 0.45; text-decoration: line-through; }

/* ---------- TABS ---------- */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-bottom: 1rem;
}
.tab-btn {
  padding: 0.35rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--light);
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
  transition: all 0.15s;
}
.tab-btn:hover { border-color: var(--green); color: var(--green); }
.tab-btn.active { background: var(--dark); color: var(--white); border-color: var(--dark); }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---------- GROUP TABLE ---------- */
.group-table th:not(:first-child),
.group-table td:not(:first-child) { text-align: center; }
.group-table .team-col { text-align: left; min-width: 120px; }
.advance-marker {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}
.advance-marker.top2 { background: var(--green); }
.advance-marker.third { background: #f39c12; }
.advance-marker.out { background: var(--border); }

/* ---------- MATCHES ---------- */
.matches-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0.5rem;
}
.match-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  background: var(--light);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.match-card.played { background: #f0f7f0; border-color: #b2d8b2; }
.match-team { flex: 1; font-size: 0.85rem; text-align: center; }
.match-score {
  font-weight: 700;
  font-size: 1rem;
  min-width: 40px;
  text-align: center;
  color: var(--dark);
}
.match-vs { color: var(--muted); font-size: 0.75rem; }

/* ---------- BRACKET ---------- */
.bracket-rounds {
  display: flex;
  gap: 1rem;
  overflow-x: auto;
  padding-bottom: 0.5rem;
}
.bracket-round {
  flex: 0 0 auto;
  min-width: 180px;
}
.bracket-round-title {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  text-align: center;
  margin-bottom: 0.5rem;
}
.bracket-match {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 0.5rem;
  background: var(--white);
}
.bracket-team {
  padding: 0.4rem 0.6rem;
  font-size: 0.82rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
}
.bracket-team:last-child { border-bottom: none; }
.bracket-team.winner { background: #e6f4ea; font-weight: 700; }
.bracket-team.tbd { color: var(--muted); font-style: italic; }
.bracket-score { font-weight: 700; color: var(--dark); }

/* ---------- FORMS (admin) ---------- */
.form-group { margin-bottom: 1rem; }
label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 0.35rem; color: var(--dark); }
input[type=text], input[type=number], input[type=password], select {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
  background: var(--white);
  color: var(--text);
  transition: border-color 0.15s;
}
input:focus, select:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px rgba(26,107,42,0.12); }

.btn {
  display: inline-block;
  padding: 0.6rem 1.2rem;
  border-radius: 8px;
  border: none;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-primary { background: var(--dark); color: var(--white); }
.btn-primary:hover { background: var(--green); }
.btn-gold { background: var(--gold); color: var(--dark); }
.btn-gold:hover { background: var(--gold-light); }
.btn-danger { background: var(--red); color: var(--white); }
.btn-danger:hover { opacity: 0.85; }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.82rem; }

.names-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.75rem;
}

.alert {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
.alert-success { background: #e6f4ea; border: 1px solid #a5d6a7; color: #1b5e20; }
.alert-error { background: #fdecea; border: 1px solid #f5c6cb; color: #7f1d1d; }
.alert-info { background: #e3f2fd; border: 1px solid #90caf9; color: #1565c0; }

.score-row {
  display: grid;
  grid-template-columns: 1fr 50px 1fr;
  gap: 0.5rem;
  align-items: center;
}
.score-row .vs-label { text-align: center; color: var(--muted); font-size: 0.85rem; }

.hidden { display: none !important; }

/* ---------- POINT LEGEND ---------- */
.point-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-size: 0.8rem;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.5rem;
  background: var(--light);
  border-radius: 4px;
  border: 1px solid var(--border);
}
.legend-pts { font-weight: 700; color: var(--green); }

/* ---------- TEAM MODAL ---------- */
.team-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  z-index: 1000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  animation: fadeIn 0.15s ease;
}
@media (min-width: 601px) {
  .team-modal-overlay { align-items: center; padding: 1rem; }
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.team-modal {
  background: var(--white);
  border-radius: 16px 16px 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 88vh;
  overflow-y: auto;
  padding: 1.5rem;
  animation: slideUp 0.2s ease;
  position: relative;
}
@media (min-width: 601px) {
  .team-modal { border-radius: 16px; max-height: 80vh; }
}
@keyframes slideUp { from { transform: translateY(40px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: var(--light);
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}
.modal-close:hover { background: var(--border); }

.modal-flag { font-size: 3.5rem; text-align: center; line-height: 1; margin-bottom: 0.5rem; }
.modal-team-name { font-size: 1.4rem; font-weight: 800; text-align: center; color: var(--dark); }
.modal-nickname { text-align: center; color: var(--muted); font-size: 0.88rem; margin-bottom: 0.3rem; }
.modal-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25rem 0.6rem;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 600;
}
.modal-badges { display: flex; justify-content: center; gap: 0.4rem; flex-wrap: wrap; margin: 0.5rem 0 1rem; }
.badge-result { background: #e6f4ea; color: #1b5e20; }
.badge-conf { background: var(--light); color: var(--dark); border: 1px solid var(--border); }

.modal-summary {
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--text);
  margin-bottom: 1.25rem;
  padding: 0.75rem;
  background: var(--light);
  border-radius: 8px;
  border-left: 3px solid var(--gold);
}

.modal-facts-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 0.6rem;
}

.fact-box {
  background: linear-gradient(135deg, #0d3a18 0%, #1a6b2a 100%);
  color: var(--white);
  border-radius: 12px;
  padding: 1rem 1.25rem;
  min-height: 100px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 0.75rem;
}
.fact-text {
  font-size: 0.9rem;
  line-height: 1.55;
  flex: 1;
}
.fact-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.25rem;
}
.fact-dots {
  display: flex;
  gap: 0.3rem;
}
.fact-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255,255,255,0.35);
  transition: background 0.2s;
}
.fact-dot.active { background: var(--gold); }
.fact-btn {
  background: rgba(255,255,255,0.15);
  border: none;
  color: white;
  border-radius: 50%;
  width: 28px;
  height: 28px;
  cursor: pointer;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.fact-btn:hover { background: rgba(255,255,255,0.3); }

/* Make team names clickable */
.team-link {
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  border-bottom: 1px dashed var(--border);
  transition: border-color 0.15s;
}
.team-link:hover { border-color: var(--green); }
.chip.clickable { cursor: pointer; transition: all 0.15s; }
.chip.clickable:hover { background: #d4f0dc; border-color: var(--green); transform: scale(1.04); }

/* ---------- LOADING ---------- */
.loading {
  text-align: center;
  padding: 3rem;
  color: rgba(255,255,255,0.7);
  font-size: 1.1rem;
}

/* ---------- SECTION TOGGLE ---------- */
.section-toggle {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
.section-btn {
  padding: 0.5rem 1rem;
  border: 2px solid rgba(255,255,255,0.3);
  border-radius: 20px;
  background: rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.9);
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 600;
  transition: all 0.15s;
}
.section-btn:hover, .section-btn.active {
  background: var(--gold);
  color: var(--dark);
  border-color: var(--gold);
}

/* ---------- RESPONSIVE ---------- */
@media (max-width: 600px) {
  h1 { font-size: 1.4rem; }
  .card { padding: 1rem; }
  .bracket-rounds { gap: 0.5rem; }
  .bracket-round { min-width: 150px; }
  .names-grid { grid-template-columns: 1fr 1fr; }

  /* Standings: hide Teams column header text, show chips inline under name */
  .standings-wrap td, .standings-wrap th { padding: 0.4rem 0.45rem; font-size: 0.82rem; }
  .standings-hide-mobile { display: none; }

  /* Group table: hide GF/GA/GD to fit on screen */
  .group-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .group-table td, .group-table th { padding: 0.35rem 0.4rem; font-size: 0.8rem; }
  .group-table .team-col { min-width: 110px; }
  .group-col-hide { display: none; }
}
