:root {
  --green-900: #0f3d2e;
  --green-700: #1b6b47;
  --green-500: #2e9e6b;
  --green-100: #e6f4ec;
  --sand: #f4efe4;
  --ink: #16241d;
  --muted: #5d6b63;
  --line: #d8e2db;
  --gold: #c9a227;
  --bg: #f7f9f7;
  --card: #ffffff;
  --shadow: 0 1px 3px rgba(15, 61, 46, 0.12), 0 6px 18px rgba(15, 61, 46, 0.06);
  --radius: 14px;
  --tap: 44px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

main {
  flex: 1 0 auto;
  width: 100%;
  max-width: 880px;
  margin: 0 auto;
  padding: 1rem 1rem 2.5rem;
}

/* ---------- Header ---------- */
.site-header {
  background: linear-gradient(135deg, var(--green-900), var(--green-700));
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
}
.header-inner {
  max-width: 880px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  position: relative;
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: #fff;
  text-decoration: none;
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: 0.2px;
}
.brand-mark { font-size: 1.4rem; }
.site-nav { margin-left: auto; display: flex; gap: 0.25rem; }
.site-nav a {
  color: #d7ece1;
  text-decoration: none;
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
  font-size: 0.92rem;
  font-weight: 500;
  min-height: var(--tap);
  display: inline-flex;
  align-items: center;
}
.site-nav a:hover { background: rgba(255, 255, 255, 0.12); color: #fff; }
.site-nav a.active { background: rgba(255, 255, 255, 0.18); color: #fff; }

.nav-toggle {
  display: none;
  margin-left: auto;
  width: var(--tap);
  height: var(--tap);
  background: transparent;
  border: 0;
  cursor: pointer;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  padding: 10px;
}
.nav-toggle span {
  display: block;
  height: 2px;
  background: #fff;
  border-radius: 2px;
  transition: transform 0.2s, opacity 0.2s;
}

/* ---------- Footer ---------- */
.site-footer {
  flex-shrink: 0;
  background: var(--green-900);
  color: #cfe3d8;
  font-size: 0.8rem;
}
.footer-inner {
  max-width: 880px;
  margin: 0 auto;
  padding: 1rem;
  text-align: center;
}
.footer-inner p { margin: 0.3rem 0; }
.footer-meta { display: flex; flex-wrap: wrap; gap: 0.5rem 0.9rem; justify-content: center; }
.legend b { color: var(--gold); }
.legend-note { opacity: 0.7; }

/* ---------- Headings & cards ---------- */
.page-title {
  font-size: 1.45rem;
  margin: 0.4rem 0 0.2rem;
  color: var(--green-900);
}
.page-sub { margin: 0 0 1rem; color: var(--muted); font-size: 0.95rem; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
  margin-bottom: 1rem;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: flex-end;
  margin-bottom: 1rem;
}
.field { display: flex; flex-direction: column; gap: 0.25rem; flex: 1 1 180px; }
.field label { font-size: 0.78rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; }

select, input[type="text"], input[type="number"] {
  width: 100%;
  min-height: var(--tap);
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 1rem;
  background: #fff;
  color: var(--ink);
}
select:focus, input:focus { outline: 2px solid var(--green-500); outline-offset: 1px; }

.btn {
  min-height: var(--tap);
  border: 0;
  border-radius: 10px;
  padding: 0.55rem 1rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--green-700);
  color: #fff;
}
.btn:hover { background: var(--green-900); }
.btn.secondary { background: var(--green-100); color: var(--green-900); }
.btn.secondary:hover { background: #d6ecdf; }
.btn.danger { background: #c0392b; }
.btn.small { min-height: 36px; padding: 0.35rem 0.7rem; font-size: 0.85rem; }

/* ---------- Leaderboard ---------- */
.lb {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.lb-row {
  display: grid;
  grid-template-columns: 2.2rem 1fr auto auto;
  gap: 0.6rem;
  align-items: center;
  background: var(--card);
  border-radius: 12px;
  padding: 0.7rem 0.85rem;
  box-shadow: var(--shadow);
  border-left: 4px solid transparent;
}
.lb-row .rank { font-weight: 800; font-size: 1.05rem; color: var(--muted); text-align: center; }
.lb-row.rank-1 { border-left-color: var(--gold); }
.lb-row.rank-1 .rank { color: var(--gold); }
.lb-row.rank-2 { border-left-color: #9aa6a0; }
.lb-row.rank-3 { border-left-color: #b08d57; }
.lb-name { font-weight: 700; }
.lb-sub { font-size: 0.78rem; color: var(--muted); }
.lb-pts { text-align: right; }
.lb-pts .big { font-size: 1.35rem; font-weight: 800; color: var(--green-700); line-height: 1; }
.lb-pts .lbl { font-size: 0.68rem; color: var(--muted); text-transform: uppercase; }
.lb-gross { text-align: right; min-width: 3.2rem; }
.lb-gross .big { font-size: 1.05rem; font-weight: 700; }
.lb-gross .lbl { font-size: 0.68rem; color: var(--muted); text-transform: uppercase; }

/* ---------- Scorecard grid ---------- */
.score-grid { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.score-grid th, .score-grid td {
  border-bottom: 1px solid var(--line);
  padding: 0.45rem 0.4rem;
  text-align: center;
}
.score-grid th { color: var(--muted); font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.3px; }
.score-grid td.hole { font-weight: 700; text-align: left; }
.score-grid input.stroke {
  width: 3rem;
  min-height: 40px;
  text-align: center;
  padding: 0.3rem;
  font-size: 1rem;
}
.score-grid .recv { color: var(--gold); font-weight: 700; }
.pts-cell { font-weight: 700; }
.pts-4 { color: #1b9e4b; }
.pts-3 { color: #2e9e6b; }
.pts-2 { color: var(--ink); }
.pts-1 { color: #c08a00; }
.pts-0 { color: #c0392b; }
.totals-row td { font-weight: 800; background: var(--green-100); border-top: 2px solid var(--green-500); }

/* ---------- Players & courses ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list li {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.6rem 0.4rem; border-bottom: 1px solid var(--line);
}
.list li:last-child { border-bottom: 0; }
.list .grow { flex: 1; }
.list .hcp-badge {
  background: var(--green-100); color: var(--green-900);
  font-weight: 700; font-size: 0.82rem;
  padding: 0.2rem 0.55rem; border-radius: 999px;
}
.count-pill { font-size: 0.8rem; color: var(--muted); }

.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }
.toast {
  position: fixed; left: 50%; bottom: 1.2rem; transform: translateX(-50%) translateY(140%);
  background: var(--green-900); color: #fff; padding: 0.7rem 1.1rem; border-radius: 999px;
  box-shadow: var(--shadow); font-size: 0.9rem; transition: transform 0.25s ease; z-index: 100;
}
.toast.show { transform: translateX(-50%) translateY(0); }

.row-actions { display: flex; gap: 0.4rem; }

/* ---------- Mobile ---------- */
@media (max-width: 600px) {
  .nav-toggle { display: flex; }
  .site-nav {
    position: absolute;
    top: 100%; left: 0; right: 0;
    flex-direction: column;
    background: var(--green-900);
    padding: 0.4rem;
    gap: 0.2rem;
    display: none;
  }
  .site-nav.open { display: flex; }
  .site-nav a { width: 100%; }
  .lb-row { grid-template-columns: 2rem 1fr auto auto; gap: 0.4rem; padding: 0.6rem; }
  .score-grid th, .score-grid td { padding: 0.4rem 0.2rem; font-size: 0.85rem; }
  .score-grid input.stroke { width: 2.6rem; }
}

/* ---------- Auth control in header ---------- */
.auth-slot { display: inline-flex; align-items: center; gap: 0.5rem; margin-left: 0.5rem; }
.auth-user { color: #d7ece1; font-size: 0.88rem; font-weight: 600; }
.site-nav a.btn.small { background: var(--gold); color: var(--green-900); }
.site-nav a.btn.small:hover { background: #d9b53a; }

/* ---------- Login ---------- */
.login-card { max-width: 360px; }
.login-card .field { margin-bottom: 0.8rem; }
.login-error {
  background: #fdecea; color: #a3271b; border: 1px solid #f3c6c0;
  padding: 0.5rem 0.7rem; border-radius: 8px; font-size: 0.9rem; margin-bottom: 0.8rem;
}

/* ---------- Leaderboard pending state ---------- */
.lb-pending { color: var(--muted); align-self: center; }
.lb-row.rank-0 { border-left-color: var(--line); }
.lb-row.rank-0 .rank { color: var(--line); }

/* ---------- Photo grid ---------- */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.6rem;
}
.photo-cell {
  padding: 0;
  border: 0;
  background: var(--line);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  aspect-ratio: 1 / 1;
  box-shadow: var(--shadow);
}
.photo-cell img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.25s ease;
}
.photo-cell:hover img { transform: scale(1.05); }
.photo-cell:focus-visible { outline: 3px solid var(--green-500); outline-offset: 2px; }

@media (max-width: 700px) {
  .photo-grid { grid-template-columns: repeat(3, 1fr); gap: 0.4rem; }
}
@media (max-width: 460px) {
  .photo-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- Lightbox ---------- */
body.lb-open { overflow: hidden; }
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(8, 24, 18, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
.lightbox[hidden] { display: none; }
.lb-figure {
  margin: 0;
  max-width: 92vw;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
}
.lb-image {
  max-width: 92vw;
  max-height: 80vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
}
.lb-caption { color: #e6f4ec; font-size: 0.95rem; text-align: center; }
.lb-close, .lb-nav {
  position: absolute;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border: 0;
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lb-close {
  top: 1rem; right: 1rem;
  width: 44px; height: 44px;
  font-size: 1.6rem; line-height: 1;
}
.lb-nav {
  top: 50%; transform: translateY(-50%);
  width: 52px; height: 52px;
  font-size: 2rem; line-height: 1;
}
.lb-prev { left: 0.8rem; }
.lb-next { right: 0.8rem; }
.lb-close:hover, .lb-nav:hover { background: rgba(255, 255, 255, 0.25); }

@media (max-width: 600px) {
  .lb-nav { width: 42px; height: 42px; font-size: 1.6rem; }
  .lb-prev { left: 0.3rem; }
  .lb-next { right: 0.3rem; }
}
