:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #22c55e;
  --accent-dim: #14532d;
  --border: #334155;
  --error: #f87171;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

header h1 { margin: 0; font-size: 1.25rem; }
.header-actions { display: flex; align-items: center; gap: 0.75rem; }

.back {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
}
.back:hover { color: var(--text); }

main { padding: 1.5rem; max-width: 1000px; margin: 0 auto; }

.status { min-height: 1.2em; color: var(--muted); }
.status.error { color: var(--error); }

/* Home menu */
.menu {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}
.menu-card {
  display: block;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem;
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.15s;
}
.menu-card:hover { border-color: var(--accent); }
.menu-card h2 { margin: 0 0 0.4rem; font-size: 1.05rem; }
.menu-card p { margin: 0; color: var(--muted); font-size: 0.9rem; }

/* Players table */
.players-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border-radius: 10px;
  overflow: hidden;
}
.players-table th, .players-table td {
  padding: 0.6rem 0.8rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.handicap-input {
  width: 5rem;
  padding: 0.3rem;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
}
button {
  background: var(--accent);
  color: #04250f;
  border: none;
  border-radius: 6px;
  padding: 0.45rem 0.9rem;
  font-weight: 600;
  cursor: pointer;
}
button:disabled { background: var(--border); color: var(--muted); cursor: not-allowed; }

/* Select list */
.select-list { list-style: none; padding: 0; margin: 0 0 1rem; }
.select-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.9rem;
  margin-bottom: 0.4rem;
}
.select-list label { display: flex; align-items: center; gap: 0.6rem; cursor: pointer; flex: 1; }
.hcap { color: var(--muted); font-size: 0.85rem; }

/* Bracket */
.bracket {
  display: flex;
  align-items: flex-start;
  gap: 2rem;
  overflow-x: auto;
  padding-bottom: 1rem;
}
.round {
  display: flex;
  flex-direction: column;
  min-width: 220px;
}
.round h3 {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
/* Height is set inline per-bracket (see draw.html) to
   maxMatchesInAnyRound * MATCH_UNIT_REM, so justify-content:space-around
   centers each round's matches exactly between the pair feeding into them,
   whatever the match count. Every .match card is a fixed height (2 equal
   slots + a footer row) so that math holds regardless of content. */
.round-matches {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
}
.match {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  user-select: none;
  touch-action: manipulation;
}
.slot {
  height: 2.5rem;
  padding: 0 0.75rem;
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.slot.tbd, .slot.bye { color: var(--muted); font-style: italic; }
.slot.winner { background: var(--accent-dim); color: var(--accent); font-weight: 600; }
.slot.withdrew { background: #4a3f0a; color: #facc15; font-style: italic; }
.match-footer {
  height: 1.6rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  color: var(--muted);
  text-align: center;
}
.match-footer.enterable { padding: 0; }
.match-footer.split-note { color: var(--accent); }
.match-footer.undo-hint {
  color: var(--muted);
  font-style: italic;
}
.match-footer.undo-armed {
  position: relative;
  color: var(--error);
  font-style: normal;
  overflow: hidden;
  user-select: none;
}
.match-footer.undo-armed::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--error);
  opacity: 0.3;
  width: 0%;
}
.match-footer.undo-armed.undo-filling::before {
  width: 100%;
  transition: width 5s linear;
}

.enter-result-btn {
  width: 100%;
  height: 100%;
  border: none;
  border-radius: 0;
  background: var(--accent);
  color: #04250f;
  font-weight: 600;
  font-size: 0.75rem;
  cursor: pointer;
}

/* Plain stacked fixture list (Round Robin group matches) — no tree
   alignment needed, so it's just spaced with a simple gap. */
.match-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-width: 320px;
  margin-top: 1rem;
}

/* Panels (setup forms, results boxes) */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}
.panel h2 { margin: 0 0 0.75rem; font-size: 1.05rem; }

.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.75rem;
  max-width: 320px;
}
.field input, .field select {
  padding: 0.5rem;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;
}
.hint { color: var(--muted); font-size: 0.8rem; margin: 0.25rem 0 0; }

.checkbox-field {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.75rem;
  max-width: 480px;
  cursor: pointer;
}
.checkbox-field input { margin-top: 0.15rem; flex-shrink: 0; }

.seed-input {
  width: 4.5rem;
  padding: 0.3rem;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-left: 0.6rem;
}

.field-row {
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
}
.field-row .field { margin-bottom: 0.75rem; }
.field-row button { flex-shrink: 0; }

/* Admin PIN gate */
.pin-gate {
  max-width: 320px;
  margin: 3rem auto;
}
.pin-gate input {
  font-size: 1.4rem;
  letter-spacing: 0.3em;
  text-align: center;
}
.admin-btn {
  background: var(--border);
  color: var(--text);
}
.admin-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-bottom: 1.25rem;
}

.inline-form { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; }
.inline-form input {
  padding: 0.5rem;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
}

button.secondary { background: var(--border); color: var(--text); }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 10;
}
.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.5rem;
  width: 100%;
  max-width: 360px;
}
.modal h3 { margin: 0 0 0.75rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.6rem; margin-top: 0.5rem; }

/* Round Robin standings + shootout */
.players-table tr.advancing { background: var(--accent-dim); }
.shootout-box {
  border: 1px solid var(--error);
  border-radius: 8px;
  padding: 1rem;
  margin-top: 1rem;
}
.shootout-box h3 { margin: 0 0 0.5rem; color: var(--error); }

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