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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  margin: 0 auto;
  padding: 16px;
  background: #f5f5f5;
  color: #222;
  max-width: 1100px;
  overflow-x: hidden;
}

/* ---- Header ---- */

header {
  text-align: center;
  margin-bottom: 24px;
  position: relative;
}

header h1 {
  font-size: 1.8rem;
}

#view-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  background: #e5e7eb;
  border-radius: 8px;
  padding: 4px;
  max-width: 300px;
  margin-left: auto;
  margin-right: auto;
}

.view-tab {
  flex: 1;
  padding: 8px 16px;
  font-size: 0.9rem;
  background: none;
  color: #6b7280;
  border-radius: 6px;
  font-weight: 500;
  text-decoration: none;
  text-align: center;
  transition: background 0.15s, color 0.15s;
}

.view-tab:hover {
  color: #374151;
}

.view-tab.active {
  background: #fff;
  color: #111;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

#menu-wrapper {
  position: absolute;
  top: 0;
  right: 0;
}

#menu-btn {
  background: none;
  font-size: 1.5rem;
  padding: 4px 10px;
  color: #555;
  letter-spacing: 2px;
}

#menu-btn:hover {
  color: #222;
}

#menu-dropdown {
  position: absolute;
  right: 0;
  top: 100%;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  padding: 8px 0;
  min-width: 180px;
  z-index: 10;
}

#menu-dropdown label,
#menu-dropdown button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 16px;
  font-size: 0.9rem;
  background: none;
  border: none;
  border-radius: 0;
  text-align: left;
  cursor: pointer;
  color: #333;
  font-weight: 400;
}

#menu-dropdown label:hover,
#menu-dropdown button:hover {
  background: #f3f4f6;
}

#menu-dropdown input[type="file"] {
  display: none;
}


/* ---- Common ---- */

h2 {
  margin-bottom: 12px;
  font-size: 1.3rem;
}

button {
  padding: 10px 20px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
}

.error {
  color: #dc2626;
  margin-top: 8px;
  font-size: 0.9rem;
}

.hidden {
  display: none;
}

.muted {
  color: #888;
  font-size: 0.9rem;
  font-style: italic;
}

#view-tabs.hidden {
  display: none;
}

/* ---- Setup ---- */

#setup-section {
  max-width: 600px;
  margin: 0 auto;
}

.setup-field {
  margin-bottom: 20px;
}

.setup-field label {
  display: block;
  font-weight: 600;
  margin-bottom: 4px;
}

.setup-field input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 0.95rem;
}

#setup-actions {
  margin-top: 8px;
}

#create-draw-btn {
  background: #2563eb;
  color: #fff;
  width: 100%;
}

#create-draw-btn:hover {
  background: #1d4ed8;
}

#court-inputs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

#court-inputs input {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 0.95rem;
}

/* ---- Entry view ---- */

#entry-view {
  max-width: 900px;
  margin: 0 auto;
}

#csv-section {
  margin-top: 24px;
}

#csv-upload-label {
  display: inline-block;
  padding: 8px 16px;
  background: #6b7280;
  color: #fff;
  border-radius: 4px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

#csv-upload-label:hover {
  background: #4b5563;
}

#csv-file {
  width: 0;
  height: 0;
  opacity: 0;
  position: absolute;
}

.round-card {
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 12px 16px;
  margin-bottom: 12px;
}

.round-done-btn {
  margin-top: 10px;
  width: 100%;
  padding: 8px;
  font-size: 0.9rem;
  background: #059669;
  color: #fff;
  border-radius: 4px;
}

.round-done-btn:hover {
  background: #047857;
}

.round-card h3 {
  font-size: 1.05rem;
  margin-bottom: 8px;
  color: #374151;
}

.match {
  padding: 8px 0;
  border-top: 1px solid #eee;
}

.match:first-of-type {
  border-top: none;
}

.match.scored {
  background: #f0fdf4;
  border-radius: 4px;
  padding-left: 10px;
  padding-right: 10px;
}

.match-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.match h4 {
  font-size: 0.85rem;
  color: #888;
  font-weight: 500;
}

.match-team {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.9rem;
  padding: 2px 0;
  color: #374151;
}

.match-team-score {
  font-size: 0.9rem;
  color: #6b7280;
  font-weight: 500;
  min-width: 24px;
  text-align: right;
}

.match-team-score.winner {
  color: #059669;
  font-weight: 700;
}

.match:not(.scored) {
  cursor: pointer;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  padding: 8px 10px;
  transition: background 0.15s;
}

.match:not(.scored):hover {
  background: #eff6ff;
  border-color: #93c5fd;
}

.section-header {
  margin-bottom: 10px;
  font-size: 1rem;
  color: #6b7280;
  font-weight: 600;
}

.section-header.completed-header {
  margin-top: 24px;
}

.match-team-name.winner {
  font-weight: 600;
  color: #059669;
}

.match-menu-wrapper {
  position: relative;
}

.match-menu-btn {
  background: none;
  color: #9ca3af;
  font-size: 1.1rem;
  padding: 0 6px;
  letter-spacing: 1px;
  font-weight: 700;
  line-height: 1;
}

.match-menu-btn:hover {
  color: #6b7280;
}

.match-menu-dropdown {
  position: absolute;
  right: 0;
  top: 100%;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  padding: 4px 0;
  z-index: 20;
  min-width: 100px;
}

.match-menu-item {
  display: block;
  width: 100%;
  padding: 6px 14px;
  font-size: 0.85rem;
  background: none;
  border: none;
  border-radius: 0;
  text-align: left;
  cursor: pointer;
  color: #333;
  font-weight: 400;
}

.match-menu-item:hover {
  background: #f3f4f6;
}

.match-menu-clear {
  color: #dc2626;
}

.matches-grid {
  display: grid;
  grid-template-columns: 1fr;
}

@media (min-width: 600px) {
  .matches-grid {
    grid-template-columns: 1fr 1fr;
    gap: 0 16px;
  }
  .matches-grid > .match {
    border-top: none;
  }
  .matches-grid > .match:not(.scored) {
    border-top: 1px solid #d1d5db;
  }
}

/* ---- Summary view ---- */

#summary-view {
  max-width: 1100px;
  margin: 0 auto;
}

.summary-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 32px;
  align-items: start;
}

@media (max-width: 1024px) {
  .summary-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 500px) {
}

/* Rankings table */
#rankings-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 1rem;
}

#rankings-table th,
#rankings-table td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid #ddd;
}

#rankings-table th {
  background: #e5e7eb;
  font-weight: 600;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

#rankings-table tbody tr:nth-child(even) {
  background: #f9fafb;
}

#rankings-table td:first-child,
#rankings-table th:first-child {
  text-align: center;
  width: 30px;
}

/* Results cards */
.result-round {
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 12px 16px;
  margin-bottom: 12px;
}

.result-round h3 {
  font-size: 1.05rem;
  margin-bottom: 8px;
  color: #374151;
}

.result-matches {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 16px;
}

.result-match {
  padding: 6px 0;
  max-width: 320px;
}

.result-match-header {
  font-size: 0.85rem;
  color: #888;
  font-weight: 500;
  margin-bottom: 2px;
}

.result-team {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.9rem;
  padding: 2px 0;
  color: #374151;
}

.result-team.winner .result-team-name {
  font-weight: 600;
  color: #059669;
}

.result-team-score {
  font-size: 0.9rem;
  color: #6b7280;
  font-weight: 500;
  min-width: 24px;
  text-align: right;
}

.result-team.winner .result-team-score {
  color: #059669;
  font-weight: 700;
}

.result-pending {
  color: #ccc;
}

@media (max-width: 500px) {
  .result-matches {
    grid-template-columns: 1fr;
  }
}

/* ---- Score dialog ---- */

#score-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

#score-overlay.hidden {
  display: none;
}

#score-dialog {
  background: #fff;
  border-radius: 10px;
  padding: 24px;
  width: 90%;
  max-width: 360px;
}

#score-dialog-instruction {
  margin-bottom: 4px;
  font-size: 1.1rem;
  text-align: center;
}

#score-dialog-subtitle {
  text-align: center;
  font-size: 0.9rem;
  color: #6b7280;
  margin-bottom: 16px;
}

.score-winner-btn {
  display: block;
  width: 100%;
  padding: 14px;
  margin-bottom: 8px;
  font-size: 1rem;
  font-weight: 500;
  background: #f3f4f6;
  color: #374151;
  border: 2px solid #d1d5db;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.score-winner-btn:hover {
  background: #eff6ff;
  border-color: #93c5fd;
  color: #2563eb;
}

#score-loser-prompt {
  text-align: center;
  font-size: 1.05rem;
  font-weight: 500;
  color: #374151;
  margin-bottom: 12px;
}

#score-number-buttons {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.score-number-btn {
  padding: 14px 0;
  font-size: 1.2rem;
  font-weight: 600;
  background: #f3f4f6;
  color: #374151;
  border: 2px solid #d1d5db;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.score-number-btn:hover {
  background: #eff6ff;
  border-color: #93c5fd;
  color: #2563eb;
}

.score-step-cancel {
  margin-top: 12px;
  width: 100%;
}

#score-confirm-actions .score-step-cancel {
  margin-top: 0;
  width: auto;
}

.score-cancel {
  background: #6b7280;
  color: #fff;
  flex: 1;
}

.score-cancel:hover {
  background: #4b5563;
}

.score-confirm {
  background: #059669;
}

/* ---- Series controls ---- */

#series-select-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

#series-select {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 0.95rem;
}

#new-series-btn {
  background: #6b7280;
  color: #fff;
  font-size: 0.85rem;
  padding: 8px 12px;
  white-space: nowrap;
}

#new-series-btn:hover {
  background: #4b5563;
}

/* ---- Dialog overlay ---- */

.dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.dialog-overlay.hidden {
  display: none;
}

.dialog {
  background: #fff;
  border-radius: 10px;
  padding: 24px;
  width: 90%;
  max-width: 360px;
}

.dialog h3 {
  text-align: center;
  margin-bottom: 16px;
  font-size: 1.1rem;
}

.dialog input[type="text"] {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 0.95rem;
  margin-bottom: 16px;
}

.dialog-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.dialog-cancel-btn {
  background: #6b7280;
  color: #fff;
  font-size: 0.85rem;
  padding: 8px 16px;
}

.dialog-cancel-btn:hover {
  background: #4b5563;
}

.dialog-confirm-btn {
  background: #2563eb;
  color: #fff;
  font-size: 0.85rem;
  padding: 8px 16px;
}

.dialog-confirm-btn:hover {
  background: #1d4ed8;
}

/* ---- Players section ---- */

#current-players-list {
  margin-bottom: 8px;
}

.current-player-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 4px;
  margin-bottom: 4px;
}

.current-player-name {
  flex: 1;
  font-size: 0.95rem;
}

.remove-player-btn {
  background: none;
  color: #9ca3af;
  font-size: 1.2rem;
  padding: 4px 8px;
  line-height: 1;
  font-weight: 400;
}

.remove-player-btn:hover {
  color: #dc2626;
}

#new-player-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

#new-player-input {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 0.95rem;
}

#new-player-add-btn {
  background: #2563eb;
  color: #fff;
  font-size: 0.85rem;
  padding: 8px 14px;
}

#new-player-add-btn:hover {
  background: #1d4ed8;
}

/* ---- Previous players ---- */

#previous-players {
  margin-bottom: 16px;
}

#previous-players-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  padding: 8px 0;
  user-select: none;
}

#previous-players-toggle h3 {
  font-size: 1rem;
  color: #6b7280;
  font-weight: 600;
  margin: 0;
}

#previous-players-count {
  font-weight: 400;
  color: #9ca3af;
  font-size: 0.9rem;
}

.toggle-arrow {
  font-size: 0.7rem;
  color: #9ca3af;
  transition: transform 0.2s;
}

.toggle-arrow.open {
  transform: rotate(180deg);
}

#player-filter {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 0.9rem;
  margin-bottom: 8px;
}

#previous-players-list {
  max-height: 300px;
  overflow-y: auto;
  border: 1px solid #ddd;
  border-radius: 4px;
}

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

.previous-players-table th {
  text-align: left;
  padding: 6px 10px;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #6b7280;
  font-weight: 600;
  background: #f3f4f6;
  border-bottom: 1px solid #ddd;
}

.previous-players-table th:last-child {
  width: 40px;
}

.previous-players-table td {
  padding: 6px 10px;
  border-bottom: 1px solid #eee;
}

.previous-players-table tr:last-child td {
  border-bottom: none;
}

.previous-players-table td:nth-child(2),
.previous-players-table th:nth-child(2) {
  text-align: center;
}

.previous-players-table td:nth-child(3) {
  color: #9ca3af;
  font-size: 0.8rem;
}

.picker-add-btn {
  background: #2563eb;
  color: #fff;
  font-size: 0.85rem;
  padding: 4px 12px;
  border-radius: 4px;
}

.picker-add-btn:hover {
  background: #1d4ed8;
}

#current-players-empty {
  margin-bottom: 12px;
}

/* ---- Ad-hoc section ---- */

#adhoc-section {
  margin-top: 24px;
}

#add-adhoc-btn {
  background: #6b7280;
  color: #fff;
  font-size: 0.85rem;
  padding: 8px 14px;
  margin-top: 8px;
}

#add-adhoc-btn:hover {
  background: #4b5563;
}

/* ---- Ad-hoc dialog ---- */

#adhoc-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

#adhoc-overlay.hidden {
  display: none;
}

#adhoc-dialog {
  background: #fff;
  border-radius: 10px;
  padding: 24px;
  width: 90%;
  max-width: 400px;
}

#adhoc-dialog h3 {
  text-align: center;
  margin-bottom: 16px;
}

.adhoc-team {
  margin-bottom: 12px;
}

.adhoc-team label {
  display: block;
  font-weight: 600;
  margin-bottom: 4px;
  font-size: 0.9rem;
}

.adhoc-team select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 0.95rem;
  margin-bottom: 4px;
}

.adhoc-scores {
  display: grid;
  grid-template-columns: auto 1fr auto 1fr;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}

.adhoc-scores label {
  font-weight: 600;
  font-size: 0.9rem;
}

.adhoc-scores input {
  padding: 8px 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 0.95rem;
}

#adhoc-dialog-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 16px;
}

#adhoc-submit-btn {
  background: #2563eb;
}

#adhoc-submit-btn:hover {
  background: #1d4ed8;
}

.score-confirm:hover {
  background: #047857;
}

.score-confirm:focus {
  outline: 3px solid #059669;
  outline-offset: 2px;
}

.score-plus-btn {
  font-size: 1.4rem;
}

#score-confirm-preview {
  margin-bottom: 16px;
}

.confirm-team {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  font-size: 1rem;
  color: #374151;
  border-bottom: 1px solid #eee;
}

.confirm-team:last-child {
  border-bottom: none;
}

.confirm-team.winner .confirm-team-name {
  font-weight: 600;
  color: #059669;
}

.confirm-team-score {
  font-size: 1.1rem;
  font-weight: 600;
  color: #6b7280;
  min-width: 28px;
  text-align: right;
}

.confirm-team.winner .confirm-team-score {
  color: #059669;
}

#score-confirm-actions {
  display: flex;
  gap: 10px;
}

/* ---- Game rules inputs ---- */

#game-rules-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.game-rule-field label {
  display: block;
  font-weight: 600;
  margin-bottom: 4px;
  font-size: 0.9rem;
}

.game-rule-field input[type="number"],
.game-rule-field select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 0.95rem;
}

.radio-group {
  display: flex;
  gap: 16px;
  padding: 8px 0;
}

.radio-option {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 400;
  font-size: 0.95rem;
  cursor: pointer;
}

.radio-option input[type="radio"] {
  width: auto;
  margin: 0;
}

#rules-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

/* ---- Admin ---- */

#login-section {
  max-width: 400px;
  margin: 0 auto;
}

#login-btn {
  background: #2563eb;
  color: #fff;
  width: 100%;
}

#login-btn:hover {
  background: #1d4ed8;
}

#logout-btn {
  background: #6b7280;
  color: #fff;
  font-size: 0.8rem;
  padding: 6px 14px;
}

#logout-btn:hover {
  background: #4b5563;
}

#breadcrumb {
  margin-bottom: 16px;
  font-size: 0.9rem;
  color: #6b7280;
}

#breadcrumb a {
  color: #2563eb;
  text-decoration: none;
}

#breadcrumb a:hover {
  text-decoration: underline;
}

.breadcrumb-sep {
  color: #9ca3af;
}

.admin-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.admin-section-header h2 {
  margin-bottom: 0;
}

#new-org-btn,
.admin-action-btn {
  background: #2563eb;
  color: #fff;
  font-size: 0.8rem;
  padding: 6px 14px;
  border-radius: 4px;
  font-weight: 600;
  text-decoration: none;
}

#new-org-btn:hover,
.admin-action-btn:hover {
  background: #1d4ed8;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.admin-table th,
.admin-table td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid #ddd;
}

.admin-table th {
  background: #e5e7eb;
  font-weight: 600;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.admin-table tbody tr {
  cursor: pointer;
}

.admin-table tbody tr:hover {
  background: #e0e7ff;
}

.admin-table a {
  color: #2563eb;
  text-decoration: none;
}

.admin-table a:hover {
  text-decoration: underline;
}
