:root {
  --bg: #f5f7f5;
  --surface: #ffffff;
  --surface-2: #eef2ee;
  --border: #d0dbd0;
  --text: #1a2b1a;
  --muted: #5a7a5a;
  --accent: #1f7a3a;
  --accent-dark: #155c2a;
  --danger: #dc2626;
  --warn: #d97706;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
}

body {
  padding-bottom: env(safe-area-inset-bottom);
}

#topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  padding-top: calc(14px + env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

#brand {
  font-weight: 700;
  font-size: 18px;
  text-decoration: none;
  color: var(--text);
}

#admin-link {
  position: fixed;
  bottom: 24px;
  right: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--bg);
  color: var(--bg);
  font-size: 22px;
  font-weight: 700;
  text-decoration: none;
  line-height: 1;
  z-index: 10;
}

#app {
  padding: 16px;
  max-width: 640px;
  margin: 0 auto;
}

h1 { font-size: 24px; margin: 8px 0 16px; }
h2 { font-size: 18px; margin: 24px 0 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }
h3 { font-size: 16px; margin: 16px 0 8px; }

.section { margin-bottom: 24px; }

.player-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.player-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
  font-weight: 600;
  font-size: 14px;
  min-height: 110px;
  box-shadow: var(--shadow);
}

.player-card:active { background: var(--surface-2); }

.player-avatar {
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  flex-shrink: 0;
}

select, input[type="text"], input[type="number"], input[type="password"], input[type="date"] {
  width: 100%;
  padding: 14px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  -webkit-appearance: none;
  appearance: none;
}

select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path fill='%235a7a5a' d='M6 8L0 0h12z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

button, .btn {
  display: inline-block;
  width: 100%;
  padding: 14px 16px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
}

button:active, .btn:active { background: var(--accent-dark); }

button.secondary, .btn.secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

button.danger { background: var(--danger); }

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}

.stat .label {
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.stat .value {
  font-size: 28px;
  font-weight: 700;
  color: var(--accent);
}

.stat .value.dim { color: var(--muted); }

.stat.compact {
  padding: 6px 12px;
}
.stat.compact .label {
  margin-bottom: 2px;
}

.course-list-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  text-decoration: none;
  color: var(--text);
}

.course-list-row .name { font-weight: 500; }
.course-list-row .arrow { color: var(--muted); }

table.player-stats {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

table.player-stats th, table.player-stats td {
  padding: 12px 10px;
  text-align: center;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

table.player-stats th {
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.5px;
}

table.player-stats td:first-child, table.player-stats th:first-child {
  text-align: left;
  font-weight: 600;
}

table.player-stats tr:last-child td { border-bottom: none; }

.score-pill {
  display: inline-block;
  padding: 4px 10px;
  margin: 3px;
  background: var(--surface-2);
  border-radius: 999px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.score-pill.best { background: var(--accent); color: white; font-weight: 700; }

.scores-wrap { line-height: 1.8; }

.back-link {
  display: inline-block;
  color: var(--muted);
  text-decoration: none;
  font-size: 16px;
  margin-bottom: 8px;
}

.muted { color: var(--muted); }
.empty { color: var(--muted); font-style: italic; padding: 20px 0; text-align: center; }

.form-row { margin-bottom: 14px; }
.form-row label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.5px; }

.player-pick-row {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
}

.player-pick-row label {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  text-transform: none;
  letter-spacing: 0;
}

.player-pick-row input[type="checkbox"] {
  width: 22px;
  height: 22px;
  accent-color: var(--accent);
}

.player-pick-row input[type="number"] {
  padding: 10px;
  font-size: 18px;
  text-align: center;
}

.player-pick-row input[type="number"]:disabled { opacity: 0.4; }

.btn-row { display: flex; gap: 8px; margin-top: 12px; }
.btn-row > * { flex: 1; }

/* Collapsible sections */
.collapsible-header {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  margin: 24px 0 12px;
}

.collapsible-header h2 {
  margin: 0;
  flex: 1;
}

.collapsible-arrow {
  font-size: 12px;
  color: var(--muted);
  transition: transform 0.2s ease;
  flex-shrink: 0;
  width: 20px;
}

.collapsible-arrow.open {
  transform: rotate(90deg);
}

.collapsible-body {
  overflow: hidden;
}

.collapsible-body.collapsed {
  display: none;
}

/* Home page section headers */
.home-section-header {
  margin: 16px 0 14px;
  justify-content: center;
  gap: 0;
}

.home-section-title {
  font-size: 22px !important;
  font-weight: 700 !important;
  color: var(--text) !important;
  text-decoration: underline;
  text-underline-offset: 5px;
  text-decoration-thickness: 2px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  margin: 0 !important;
}

/* Course buttons */
.course-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.course-btn {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-weight: 500;
  font-size: 16px;
  cursor: pointer;
  text-align: left;
  box-shadow: var(--shadow);
  font-family: inherit;
}

.course-btn:active {
  background: var(--surface-2);
}

.course-btn-active {
  background: var(--surface-2);
  border-color: var(--accent);
  border-width: 2px;
  font-weight: 700;
}

.course-btn-img {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
  overflow: hidden;
}

.course-btn-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.course-btn-name {
  flex: 1;
}

/* Clickable table rows */
table.player-stats tbody tr {
  cursor: pointer;
}

table.player-stats tbody tr:hover td {
  background: var(--surface-2);
}

/* Head-to-Head */
.vs-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 24px;
}

.vs-row {
  display: flex;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 12px;
  gap: 8px;
  box-shadow: var(--shadow);
}

.vs-player {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  gap: 4px;
}

.vs-player .pname {
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
  text-align: center;
}

.vs-player .pwins {
  font-size: 26px;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
}

.vs-player .pwins-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.vs-player .pwins.loss {
  color: var(--danger);
}

.vs-player .pwins-label.loss {
  color: var(--danger);
}

img.player-avatar {
  display: block;
  object-fit: cover;
}

.player-mgmt-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.player-mgmt-row input[type="text"] {
  flex: 1;
  padding: 10px 12px;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  font-size: 16px;
  flex-shrink: 0;
}

.vs-filter-row {
  margin-bottom: 12px;
}

.vs-player-link {
  cursor: pointer;
}

.vs-player-link:hover .pname {
  text-decoration: underline;
}

.course-section-label {
  font-size: 14px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  text-align: center;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 8px 0;
  margin: 0 0 10px 0;
}

.course-section-label + .course-list {
  margin-bottom: 0;
}

.course-section + .course-section {
  margin-top: 40px;
}

.course-section {
  margin-bottom: 8px;
}

.local-toggle-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--muted);
  flex-shrink: 0;
  cursor: pointer;
  white-space: nowrap;
}

.vs-sep {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  font-size: 16px;
  color: var(--muted);
  font-weight: 700;
  flex-shrink: 0;
  padding: 0 4px;
}

.vs-ties {
  font-size: 11px;
  font-weight: 600;
  color: #5a5a5a;
  text-align: center;
  white-space: nowrap;
}

.vs-ties-num {
  font-size: 13px;
  font-weight: 700;
  color: #4a4a4a;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: white;
  padding: 12px 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 100;
  animation: toast-in 0.2s ease-out;
}

.toast.error { background: var(--danger); }

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 20px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}
