:root {
  --bg: #f6faf1;
  --surface: #ffffff;
  --surface-2: #eef7e4;
  --border: #dfe9d6;
  --text: #1d2b18;
  --muted: #5f6f58;
  --brand: #b7e01e;       /* pickleball optic green */
  --brand-dark: #7ba30f;  /* readable green for text/links */
  --brand-text: #4f7300; /* brand green for text and links (5:1 on every light surface) */
  --brand-ink: #1d2b18;   /* dark text sitting on brand green */
  --shadow: 0 1px 2px rgba(29, 43, 24, 0.06), 0 4px 16px rgba(29, 43, 24, 0.06);
  --radius: 14px;
  --radius-sm: 9px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10150c;
    --surface: #171f11;
    --surface-2: #202b17;
    --border: #2c3a22;
    --text: #e9f2df;
    --muted: #93a687;
    --brand: #b7e01e;
    --brand-dark: #cdf23a;
    --brand-text: #cdf23a;
    --brand-ink: #10150c;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.45), 0 4px 20px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

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

a { color: var(--brand-text); }

header {
  padding: 18px 32px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  position: sticky;
  top: 0;
  z-index: 10;
}
header::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: -3px;
  height: 3px;
  background: linear-gradient(90deg, var(--brand), var(--brand-dark), var(--brand));
}
header .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 1.15rem;
  text-decoration: none;
  color: var(--text);
}
header .brand .dot {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #e2f97a, var(--brand) 55%, var(--brand-dark));
  border: 2px solid var(--brand-ink);
  box-shadow: inset -3px -3px 0 rgba(0,0,0,0.08);
  flex: none;
}
header nav {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
header nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
}
header nav a:hover { background: var(--surface-2); color: var(--text); }
header nav a.active { background: var(--brand); color: var(--brand-ink); }

main { padding: 28px 24px 60px; max-width: 1100px; margin: 0 auto; }

@media (prefers-reduced-motion: no-preference) {
  main { animation: page-fade-in 0.28s ease; }
  @keyframes page-fade-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
  }
}

/* ---------- buttons & inputs ---------- */
button, .btn {
  cursor: pointer;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  font-weight: 700;
  font-size: 0.92rem;
  background: var(--brand);
  color: var(--brand-ink);
  transition: transform 0.06s ease, box-shadow 0.15s ease;
}
button:hover, .btn:hover { box-shadow: 0 2px 10px rgba(120, 170, 20, 0.35); }
button:active, .btn:active { transform: translateY(1px); }
.btn-ghost {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--text);
}
.btn-danger { background: #e5533d; color: #fff; }

input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand-dark);
  box-shadow: 0 0 0 3px rgba(183, 224, 30, 0.35);
}
label { display: block; font-size: 0.85rem; color: var(--muted); font-weight: 600; margin-top: 12px; }

/* ---------- landing / search hero ---------- */
.hero {
  position: relative;
  text-align: center;
  padding: 60px 16px 32px;
  overflow: hidden;
}
.hero::before {
  content: '';
  position: absolute;
  top: -160px;
  left: 50%;
  transform: translateX(-50%);
  width: 680px;
  height: 680px;
  background: radial-gradient(circle, rgba(183, 224, 30, 0.28) 0%, rgba(183, 224, 30, 0) 62%);
  pointer-events: none;
  z-index: 0;
}
.hero > * { position: relative; z-index: 1; }
.eyebrow {
  display: inline-block;
  background: var(--surface-2);
  color: var(--brand-text);
  border: 1px solid var(--border);
  padding: 5px 14px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-bottom: 16px;
}
.hero h1 {
  font-size: 2.5rem;
  margin: 0 0 10px;
  letter-spacing: -0.02em;
}
.hero h1 .accent { color: var(--brand-text); }
.hero p { color: var(--muted); max-width: 560px; margin: 0 auto 28px; line-height: 1.5; }

.search-form {
  display: flex;
  gap: 8px;
  max-width: 560px;
  margin: 0 auto;
}
.search-form input {
  flex: 1;
  font-size: 1.05rem;
  padding: 14px 18px;
  border-radius: 999px;
  border: 2px solid var(--border);
}
.search-form input:focus { box-shadow: 0 0 0 4px rgba(183, 224, 30, 0.35); }
.search-form button {
  border-radius: 999px;
  padding: 0 26px;
  font-size: 1rem;
}

.tier-ladder {
  display: flex;
  gap: 8px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 32px;
}
.tier-rung { text-decoration: none; display: inline-flex; transition: transform 0.12s ease; }
.tier-rung:hover { transform: translateY(-2px); }
.tier-rung .tier-badge { padding: 9px 20px; font-size: 0.88rem; box-shadow: var(--shadow); }
.tier-arrow { color: var(--muted); font-size: 1rem; }

.stats-row {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-top: 34px;
  flex-wrap: wrap;
}
.stat-card {
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 34px;
  box-shadow: var(--shadow);
}
.stat-card .n { font-size: 1.8rem; font-weight: 800; color: var(--brand-text); }
.stat-card .l { font-size: 0.78rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; margin-top: 2px; }

.note {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  color: var(--muted);
  font-size: 0.88rem;
  margin-bottom: 22px;
  line-height: 1.5;
}
.note strong { color: var(--text); }

/* ---------- results toolbar ---------- */
.results-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}
.results-toolbar .summary { color: var(--muted); font-size: 0.9rem; }
.results-toolbar .controls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.results-toolbar select { width: auto; padding: 8px 12px; }
.results-toolbar .search-form { margin: 0; max-width: 340px; }
.tournament-search { margin: 16px 0 8px; max-width: 520px; }
.tournament-search input { padding: 11px 16px; font-size: 0.95rem; }
.tournament-search-summary { margin: 0 0 14px; }
.results-toolbar .search-form input { padding: 9px 14px; font-size: 0.9rem; }
.results-toolbar .search-form button { padding: 0 16px; }

/* ---------- tier sections ---------- */
.tier-section { margin-bottom: 30px; }
.tier-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.tier-badge {
  font-weight: 800;
  padding: 5px 14px;
  border-radius: 999px;
  font-size: 0.82rem;
  color: #fff;
  letter-spacing: 0.01em;
}
.tier-Pro { background: #e8ab00; color: #2b2100; }
.tier-Advance { background: #c23a26; }
.tier-Intermediate { background: #18759e; }
.tier-Novice { background: #1f7a4d; }
.tier-Beginner { background: #667066; }
.tier-Pending { background: #cfd8cb; color: #455141; }
.tier-count { color: var(--muted); font-size: 0.85rem; }

.player-grid { display: grid; gap: 8px; }
.player-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 13px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-decoration: none;
  color: var(--text);
  box-shadow: var(--shadow);
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}
.player-card:hover {
  border-color: var(--brand-dark);
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(29, 43, 24, 0.14);
}
.player-name { font-weight: 700; }
.player-meta { color: var(--muted); font-size: 0.85rem; }
.empty { color: var(--muted); font-style: italic; padding: 10px 2px; }

.player-grid.collapsed {
  max-height: 480px;
  overflow: hidden;
  position: relative;
}
.player-grid.collapsed::after {
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 64px;
  background: linear-gradient(to bottom, transparent, var(--bg));
  pointer-events: none;
}
.show-more-btn { margin-top: 10px; }

/* ---------- tables ---------- */
table { width: 100%; border-collapse: collapse; margin-top: 12px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
th { color: var(--muted); font-weight: 700; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; }
tr:last-child td { border-bottom: none; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}
.card h3 { margin-top: 0; }

a.source { color: var(--brand-text); font-size: 0.82rem; font-weight: 600; text-decoration: none; }
a.source:hover { text-decoration: underline; }
.reason { color: var(--muted); font-size: 0.88rem; margin-top: -6px; }

.tournament-list { display: grid; gap: 10px; }
.tournament-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 18px;
  text-decoration: none;
  color: var(--text);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  box-shadow: var(--shadow);
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}
.tournament-card:hover {
  border-color: var(--brand-dark);
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(29, 43, 24, 0.14);
}
.tournament-card .title { font-weight: 700; }
.level-pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  background: var(--surface-2);
  color: var(--brand-text);
  border: 1px solid var(--border);
}
.level-pill.level-club { background: var(--surface-2); color: var(--muted); border-color: var(--border); }
.level-pill.level-regional { background: rgba(58, 160, 201, 0.14); color: #1f6586; border-color: rgba(58, 160, 201, 0.35); }
.level-pill.level-national { background: rgba(232, 171, 0, 0.16); color: #7d5a00; border-color: rgba(232, 171, 0, 0.4); }
.level-pill.level-international { background: rgba(155, 92, 224, 0.14); color: #7a3fc2; border-color: rgba(155, 92, 224, 0.35); }

.division-block { margin-bottom: 22px; }
.division-block h3 {
  margin: 0 0 10px;
  font-size: 1rem;
  display: flex;
  align-items: center;
  gap: 8px;
}
.division-count { color: var(--muted); font-weight: 500; font-size: 0.85rem; }

.back-link { display: inline-block; margin-bottom: 16px; color: var(--muted); text-decoration: none; font-size: 0.9rem; font-weight: 600; }
.back-link:hover { color: var(--brand-text); }

@media (max-width: 640px) {
  header { padding: 14px 16px; }
  main { padding: 20px 14px 48px; }
  .hero h1 { font-size: 1.5rem; }
  .results-toolbar { flex-direction: column; align-items: stretch; }
}

/* Site footer: privacy / contact links on every public page */
.site-footer {
  max-width: 960px;
  margin: 48px auto 0;
  padding: 20px 16px 32px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
  line-height: 1.8;
}
.site-footer a { color: var(--brand-text); text-decoration: none; }
.site-footer a:hover { text-decoration: underline; }
.card ul { margin: 8px 0 12px 20px; padding: 0; }
.card li { margin: 4px 0; }

/* DUPR ID box on player pages (we show the ID and point to DUPR; no ratings copied) */
.dupr-box {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin: 12px 0 18px;
}
.dupr-box .player-meta { margin: 0; flex: 1 1 260px; }
.dupr-label { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.dupr-id { display: flex; align-items: center; gap: 8px; }
.dupr-id code { font-size: 1.1rem; font-weight: 700; color: var(--text); letter-spacing: 0.04em; }
.dupr-copy { padding: 4px 10px; font-size: 0.8rem; }

/* Privacy & data governance */
.category-label { font-size: 0.85rem; color: var(--muted); margin: -4px 0 8px; }
.privacy-notice { margin-top: 28px; }
.table-scroll { overflow-x: auto; }
.error-note { border-color: #e5533d; background: #fdecea; color: #7a1d10; }
.prose .card p, .prose .card li { line-height: 1.6; }
.admin-nav { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 20px; }
.admin-nav a { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border); text-decoration: none; color: var(--muted); font-size: 0.85rem; font-weight: 600; }
.admin-nav a.active { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.admin-stats .stat-card { text-decoration: none; color: inherit; }
.status-pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); vertical-align: middle; }
.status-GREEN, .status-public, .status-completed { background: #e6f6d9; color: #2f6b12; border-color: #b9e39a; }
.status-YELLOW, .status-restricted, .status-in_review, .status-identity_verified, .status-new { background: #fff6d6; color: #7a5b00; border-color: #f0dc8c; }
.status-RED, .status-hidden, .status-rejected { background: #fdecea; color: #8a1f11; border-color: #f3b7ad; }
.action-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.inline-form { display: flex; flex-wrap: wrap; gap: 0 12px; align-items: flex-end; margin-bottom: 12px; }
.inline-form label { flex: 1 1 180px; }
.inline-form button { margin-top: 12px; }
label.check { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
label.check input { width: auto; margin: 0; }
.result-action { display: flex; flex-wrap: wrap; gap: 4px; }
.result-action select, .result-action input { width: auto; min-width: 120px; margin: 0; }
.pre { white-space: pre-wrap; }
.audit-details { font-family: ui-monospace, monospace; font-size: 0.75rem; word-break: break-word; max-width: 420px; }
.pager { display: flex; align-items: center; gap: 12px; }

/* ---------- phones ---------- */
@media (max-width: 640px) {
  /* Compact, non-sticky header: the menu is one swipeable row instead of two wrapped lines. */
  header { position: relative; padding: 12px 16px 10px; gap: 8px; }
  header .brand { font-size: 1.05rem; }
  header .brand .dot { width: 22px; height: 22px; }
  header nav { width: calc(100% + 12px); flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -6px; }
  header nav::-webkit-scrollbar { display: none; }
  header nav { gap: 2px; }
  header nav a { padding: 14px 7px; font-size: 0.78rem; white-space: nowrap; flex: none; }

  main { padding: 18px 16px 40px; }
  .hero { padding: 24px 0 16px; }
  .hero h1 { font-size: 1.7rem; }
  .hero p { font-size: 0.95rem; text-align: left; margin-bottom: 20px; }
  .eyebrow { font-size: 0.7rem; margin-bottom: 12px; }
  .search-form input { padding: 12px 16px; }
  .search-form button { padding: 0 18px; }
  .tier-ladder { gap: 8px; margin-top: 22px; }
  .tier-arrow { display: none; }
  .tier-rung .tier-badge { padding: 8px 16px; }
  .stats-row { margin-top: 22px; }

  /* 16px text stops iPhones zooming in when a field is tapped. */
  input, select, textarea, .search-form input { font-size: 16px; }

  .card { padding: 16px; }

  /* Player results: one small card per tournament instead of a wide table. */
  .results-table thead { display: none; }
  .results-table, .results-table tbody, .results-table tr, .results-table td { display: block; width: 100%; }
  .results-table tr { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; margin-bottom: 10px; }
  .results-table td { border: none; padding: 3px 0; display: flex; gap: 10px; }
  .results-table td::before { content: attr(data-label); flex: 0 0 82px; color: var(--muted); font-size: 0.76rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; padding-top: 2px; }
  .results-table td:first-child { font-size: 0.95rem; }
  th, td { padding: 8px 8px; }

  /* Admin: one swipeable menu row, 2x2 counters, and wide tables scroll inside themselves. */
  .admin-nav { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .admin-nav::-webkit-scrollbar { display: none; }
  .admin-nav a { white-space: nowrap; flex: none; }
  .admin-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .admin-stats .stat-card { padding: 12px 8px; }
  .admin-stats .stat-card .n { font-size: 1.4rem; }
  main:has(.admin-nav) table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  main:has(.admin-nav) td { min-width: 90px; }
  main:has(.admin-nav) td.audit-details { min-width: 320px; }
  .result-action { flex-direction: column; min-width: 170px; }
  .result-action select, .result-action input { width: 100%; }
  .action-grid button { flex: 1 1 100%; }
  .inline-form label { flex: 1 1 100%; }
}

/* Upload results */
.upload-example { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; font-size: 0.82rem; white-space: pre-wrap; overflow-x: auto; }
.upload-new { border-left: 3px solid var(--border); padding-left: 12px; margin: 8px 0; }
.upload-preview { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 8px; }
.preview-division { margin: 8px 0; }
.preview-division ul { margin: 4px 0 0 18px; padding: 0; font-size: 0.9rem; }
button[disabled] { opacity: 0.5; cursor: not-allowed; }
label.check { margin: 14px 0; line-height: 1.4; }

/* Share this tournament */
.share-card { margin: 18px 0; }
.share-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.share-row .btn, .share-row button { text-decoration: none; display: inline-block; }
.share-row [hidden], .share-note[hidden] { display: none; }
@media (max-width: 640px) { .share-row > * { flex: 1 1 calc(50% - 8px); text-align: center; } }

/* Region and calendar links */
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 16px; }
.chip {
  display: inline-block;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 600;
}
.chip:hover { border-color: var(--brand-dark); color: var(--brand-text); }
.home-browse { margin-top: 26px; }
.home-browse .chip-row { justify-content: center; }
@media (max-width: 640px) { .chip { padding: 8px 14px; } }
@media (max-width: 640px) {
  .stats-row-3 { gap: 8px; flex-wrap: nowrap; }
  .stats-row-3 .stat-card { flex: 1 1 0; min-width: 0; padding: 12px 6px; }
  .stats-row-3 .stat-card .n { font-size: 1.35rem; }
  .stats-row-3 .stat-card .l { font-size: 0.68rem; letter-spacing: 0.02em; }
}

/* Home page link to the Pickle Rally Rush mini game (/play/) */
.game-promo {
  display: flex; align-items: center; gap: 14px;
  max-width: 460px; margin: 30px auto 0; padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); text-decoration: none; color: var(--text); text-align: left;
}
.game-promo:hover { border-color: var(--brand-dark); transform: translateY(-1px); }
.game-promo img { width: 56px; height: 56px; border-radius: 14px; flex: none; }
.game-promo .gp-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.game-promo .gp-text strong { font-size: 1.02rem; }
.game-promo .gp-text small { color: var(--muted); font-size: 0.82rem; line-height: 1.3; }
.game-promo .gp-btn { flex: none; background: var(--brand); color: var(--brand-ink); font-weight: 800; padding: 9px 20px; border-radius: 999px; }

/* Accessibility: page title as h1 (same look the h2 had), skip link, hidden labels, visible keyboard focus */
main h1 { font-size: 1.5em; margin: 0.83em 0; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: 8px; top: -60px; z-index: 100; padding: 10px 16px; border-radius: 8px; background: var(--brand); color: var(--brand-ink); font-weight: 700; text-decoration: none; }
.skip-link:focus { top: 8px; }
a:focus-visible, button:focus-visible, summary:focus-visible, [tabindex]:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid var(--brand-text);
  outline-offset: 2px;
}

/* Court list pager */
.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 18px 0; }
.pager .btn { min-height: 44px; display: inline-flex; align-items: center; text-decoration: none; }

.list-heading { font-size: 1.1rem; margin: 22px 0 8px; }
