:root {
  --bg: #f6f5f0;
  --card: #fff;
  --ink: #1c1f1a;
  --muted: #6b7064;
  --line: #e2e0d6;
  --green: #14532d;
  --a: #1d5fbf;
  --a-soft: #e3edfb;
  --b: #c2570c;
  --b-soft: #fcebdc;
  --halve: #8a8f82;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121411;
    --card: #1b1e1a;
    --ink: #e8e9e3;
    --muted: #9aa093;
    --line: #2e322c;
    --green: #2f8a52;
    --a: #6ea2f0;
    --a-soft: #1a2a42;
    --b: #f0995a;
    --b-soft: #3a2616;
    --halve: #8a8f82;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }

.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px;
  background: var(--green); color: #fff;
}
.brand { font-weight: 700; text-decoration: none; letter-spacing: .01em; white-space: nowrap; }
.brand .short { display: none; }
.top nav { display: flex; gap: 4px; }
.top nav a {
  text-decoration: none; padding: 6px 10px; border-radius: 6px; opacity: .8;
}
@media (max-width: 420px) {
  .top { gap: 6px; }
  .top nav { gap: 0; }
  .top nav a { padding: 6px 7px; font-size: 14px; }
}
.top nav a.on { background: rgba(255,255,255,.18); opacity: 1; }

main { max-width: 760px; margin: 0 auto; padding: 16px 16px calc(env(safe-area-inset-bottom, 0px) + 48px); }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 28px 0 8px; }
h2:first-child { margin-top: 4px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.pad { padding: 14px; }

/* Leaderboard */
.board { width: 100%; border-collapse: collapse; }
.board th, .board td { padding: 10px 8px; text-align: right; white-space: nowrap; }
.board th { font-size: 12px; color: var(--muted); font-weight: 500; }
.board td.team, .board th.team { text-align: left; white-space: normal; }
.board tr + tr td { border-top: 1px solid var(--line); }
.board .rank { width: 28px; color: var(--muted); text-align: left; }
.board .pts { font-size: 20px; font-weight: 700; }
.board tr.lead .pts { color: var(--green); }

.matches { display: grid; gap: 8px; }
.match-row {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px;
  padding: 12px 14px; text-decoration: none;
}
.match-row .side-b { text-align: right; }
.match-row .score { font-weight: 700; font-size: 18px; font-variant-numeric: tabular-nums; text-align: center; }
.match-row .score small { display: block; font-weight: 400; font-size: 12px; color: var(--muted); }
.round-label {
  display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap;
  font-size: 12px; color: var(--muted); margin: 16px 0 6px;
}
.round-ctl { display: inline-flex; align-items: center; gap: 8px; }
.badge { font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 999px; text-transform: uppercase; letter-spacing: .04em; }
.badge.pending { background: var(--line); color: var(--muted); }
.badge.open { background: #dc2626; color: #fff; }
.badge.closed { background: var(--ink); color: var(--bg); }
.live-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: #dc2626; vertical-align: middle; margin-left: 2px; }
.match-row.mine, .board tr.mine td.team strong { box-shadow: inset 3px 0 0 var(--green); }
.board tr.mine td.team strong { box-shadow: none; text-decoration: underline; text-decoration-color: var(--green); text-underline-offset: 3px; }
.signed-in { margin-top: 28px; text-align: center; }
.link { background: none; border: 0; padding: 0; color: inherit; text-decoration: underline; cursor: pointer; font: inherit; }
.note { margin: 12px 0 0; padding: 10px 14px; border-radius: var(--radius); background: var(--line); font-size: 14px; }
.dot-a { color: var(--a); } .dot-b { color: var(--b); }

/* Tabs */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.tabs a {
  text-decoration: none; padding: 7px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--card); font-size: 14px;
}
.tabs a.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }

/* Match header */
.vs { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: center; padding: 14px; }
.vs .name { font-weight: 600; }
.vs .name.b { text-align: right; }
.vs .big { font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; }
.vs .big .a { color: var(--a); } .vs .big .b { color: var(--b); }
.vs .sub { text-align: center; font-size: 12px; color: var(--muted); }

/* Scorecard */
.nine-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin: 22px 0 8px; flex-wrap: wrap; }
.nine-head h3 { margin: 0; font-size: 16px; }
.strokes-line { font-size: 13px; color: var(--muted); }
details.strokes { margin: 0 0 8px; }
details.strokes summary { cursor: pointer; font-size: 13px; color: var(--muted); }
.strokes-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; padding: 10px 0; }
.strokes-grid label { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 14px; }
.strokes-grid input { width: 64px; }

.card-wrap { overflow-x: auto; }
table.sc { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
table.sc th { font-size: 11px; font-weight: 600; color: var(--muted); padding: 8px 2px; text-align: center; vertical-align: bottom; }
table.sc th.pa { color: var(--a); } table.sc th.pb { color: var(--b); }
table.sc th .nm { display: block; max-width: 64px; margin: 0 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.sc td { padding: 4px 2px; text-align: center; border-top: 1px solid var(--line); }
table.sc td.hole { font-weight: 700; width: 34px; line-height: 1.1; }
table.sc td.hole a { text-decoration: none; }
table.sc td.hole .par { display: block; font-size: 10px; font-weight: 500; color: var(--muted); }
table.sc td.si { color: var(--muted); font-size: 12px; width: 28px; }
table.sc td.sep, table.sc th.sep { width: 6px; padding: 0; }
table.sc tfoot td { font-weight: 700; padding: 10px 2px; }

.cell { position: relative; display: inline-block; }
.cell input {
  width: 48px; height: 44px; text-align: center; font-size: 18px; font-weight: 600;
  border: 1px solid var(--line); border-radius: 8px; background: var(--bg);
  -moz-appearance: textfield;
}
.cell input:disabled { opacity: 1; background: transparent; border-color: transparent; color: var(--ink); -webkit-text-fill-color: var(--ink); }
.cell input.queued { border-style: dashed; border-color: var(--muted); }
.cell input:focus { outline: 2px solid var(--green); outline-offset: 0; background: var(--card); }
.cell input.best-a { background: var(--a-soft); border-color: var(--a); }
.cell input.best-b { background: var(--b-soft); border-color: var(--b); }
.cell .pop {
  position: absolute; top: 3px; right: 4px; font-size: 9px; line-height: 1; color: var(--ink); pointer-events: none;
  letter-spacing: -1px;
}
.res { display: inline-block; min-width: 30px; padding: 4px 6px; border-radius: 6px; font-size: 13px; font-weight: 700; }
.res.a { background: var(--a); color: #fff; }
.res.b { background: var(--b); color: #fff; }
.res.h { color: var(--halve); }

.legend { font-size: 12px; color: var(--muted); margin-top: 8px; }

/* Setup */
.form-grid { display: grid; gap: 10px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > label { flex: 1 1 160px; }
label.f { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
label.f.inline { display: flex; align-items: center; gap: 8px; color: var(--ink); font-size: 15px; }
input[type=text], input[type=number], select {
  padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); width: 100%;
}
input[type=checkbox] { width: 18px; height: 18px; }
.players { display: grid; gap: 8px; }
.players .p { display: grid; grid-template-columns: 1fr 64px 84px; gap: 8px; }
.teams { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.team-box { padding: 12px; }
.team-box h4 { margin: 0 0 8px; font-size: 14px; }
.team-box select + select { margin-top: 6px; }
.holes-tbl { width: 100%; border-collapse: collapse; }
.holes-tbl th { font-size: 12px; color: var(--muted); font-weight: 500; text-align: left; padding: 4px; }
.holes-tbl td { padding: 3px 4px; }
.holes-tbl td:first-child { font-weight: 700; width: 40px; }
.holes-tbl input { padding: 6px 8px; }
.si-grid { display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); gap: 4px; }
.si-grid label { display: grid; gap: 2px; text-align: center; font-size: 11px; color: var(--muted); }
.si-grid input { padding: 6px 2px; text-align: center; }
.sched { display: grid; gap: 8px; }
.sched .r { display: grid; grid-template-columns: 1.2fr 1fr 1fr; gap: 8px; align-items: end; }
.err { color: #b91c1c; font-size: 13px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--card); cursor: pointer; font-weight: 600; text-decoration: none;
}
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.danger { color: #b91c1c; }
.btn:disabled { opacity: .5; cursor: default; }
.savebar {
  position: sticky; bottom: 0; display: flex; gap: 8px; justify-content: flex-end; align-items: center;
  padding: 12px 0 calc(env(safe-area-inset-bottom, 0px) + 12px); background: var(--bg); border-top: 1px solid var(--line); margin-top: 24px;
}

#sync {
  position: sticky; top: calc(env(safe-area-inset-top, 0px) + 50px); z-index: 9;
  padding: 6px 16px; font-size: 13px; text-align: center; background: #fde68a; color: #422006;
}
#sync.busy { background: var(--line); color: var(--ink); }

.landing { max-width: 380px; margin: 8vh auto 0; }
.landing h1 { font-size: 34px; margin: 0 0 6px; letter-spacing: -.02em; }
.landing p { margin: 0 0 24px; }

#toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + 20px); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-size: 14px; z-index: 50;
}

/* Play mode */
.live-cta { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 14px; text-decoration: none; margin-bottom: 4px; }
.chips { display: flex; gap: 4px; overflow-x: auto; margin: -4px -16px 6px; padding: 4px 16px 6px; scrollbar-width: none; }
.chip {
  flex: 0 0 30px; height: 30px; display: grid; place-items: center; border-radius: 50%;
  font-size: 12px; font-weight: 700; text-decoration: none; border: 1px solid var(--line); background: var(--card);
}
.chip.a { background: var(--a); border-color: var(--a); color: #fff; }
.chip.b { background: var(--b); border-color: var(--b); color: #fff; }
.chip.h { background: var(--line); }
.chip.cur { outline: 2px solid var(--ink); outline-offset: 1px; }
.play-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 10px; margin-bottom: 10px; }
.ph-num { font-size: 30px; font-weight: 800; letter-spacing: -.02em; line-height: 1; }
.ph-meta { color: var(--muted); margin-top: 4px; }
.ph-right { text-align: right; }
.ph-match { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; margin-top: 4px; }
.ph-match small { font-size: 12px; font-weight: 500; color: var(--muted); margin-left: 4px; }
.badge.fmt { background: var(--green); color: #fff; }
.hole-photo { margin: 0; border-radius: var(--radius); overflow: hidden; background: var(--line); min-height: 120px; cursor: zoom-in; }
.hole-photo img { width: 100%; height: auto; display: block; }
.hole-photo.zoom {
  position: fixed; inset: 0; z-index: 100; border-radius: 0; background: rgba(0,0,0,.92);
  display: grid; place-items: center; cursor: zoom-out; padding: env(safe-area-inset-top, 0px) 0 env(safe-area-inset-bottom, 0px);
}
.hole-photo.zoom img { max-height: 100%; object-fit: contain; }
.tip { margin: 10px 0 6px; font-size: 14px; }
.tip a { color: var(--muted); }
.strokes-note { font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.sides { display: grid; gap: 10px; margin-top: 10px; }
.side { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px; border-left: 4px solid var(--a); }
.side-b { border-left-color: var(--b); }
.side-name { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 2px 0 4px; }
.pl-row { display: grid; grid-template-columns: 1fr 48px 56px 48px 40px; gap: 6px; align-items: center; padding: 6px 0; }
.pl-row + .pl-row { border-top: 1px solid var(--line); }
.pl-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pops { margin-left: 4px; color: var(--muted); letter-spacing: -1px; }
.pl-score { text-align: center; font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1; }
.pl-score small { display: block; font-size: 11px; font-weight: 500; color: var(--muted); margin-top: 2px; }
.pl-row.best .pl-score { color: var(--green); }
.step, .pk {
  height: 48px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg);
  font-size: 24px; font-weight: 600; cursor: pointer; touch-action: manipulation;
}
.pk { font-size: 14px; font-weight: 700; color: var(--muted); }
.pk.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.step:disabled, .pk:disabled { opacity: .35; }
.hole-result { margin-top: 10px; padding: 10px 14px; border-radius: var(--radius); font-weight: 700; text-align: center; color: #fff; }
.hole-result.a { background: var(--a); } .hole-result.b { background: var(--b); } .hole-result.h { background: var(--line); color: var(--ink); }
.play-nav { display: flex; justify-content: space-between; gap: 10px; margin-top: 14px; }
.play-nav .btn { flex: 1; }
.mini { margin-top: 16px; }
.mini summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.mini-row { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--line); }

.claim { margin-bottom: 12px; display: grid; gap: 8px; border-color: var(--green); }
.claim p { margin: 0; }
.claim-row { display: flex; gap: 8px; }
.claim-row input { flex: 1; min-width: 0; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); }
.claim .link { justify-self: start; color: var(--muted); }
label.f.inline.off { color: var(--muted); }
.claimed { display: flex; align-items: center; justify-content: space-between; gap: 4px; font-size: 13px; color: var(--green); font-weight: 600; padding: 0 4px; }
.claimed .link { color: var(--muted); font-weight: 400; }

/* Rules */
.rules p { margin: 0 0 10px; }
.rules p:last-child { margin-bottom: 0; }
.rules-tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.rules-tbl th { font-size: 12px; color: var(--muted); font-weight: 500; text-align: left; padding: 10px 12px 6px; }
.rules-tbl td { padding: 8px 12px; border-top: 1px solid var(--line); vertical-align: top; }
.sched-match + .sched-match { margin-top: 6px; padding-top: 6px; border-top: 1px dashed var(--line); }
.hcps { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; color: var(--muted); margin: 4px 0 6px; }
.hcps b { color: var(--ink); }
.rule-round { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin: 16px 0 6px; }
.rule-match { padding: 8px 0; border-top: 1px solid var(--line); font-size: 14px; }
.rule-nine { display: grid; grid-template-columns: 112px 1fr; gap: 8px; margin-top: 4px; }
.rule-nine .muted { font-size: 12px; padding-top: 1px; }
textarea { width: 100%; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); font: inherit; color: inherit; resize: vertical; }

/* Activity log */
.log { padding-top: 4px; }
.log-day { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin: 14px 0 4px; }
.log-row { display: grid; grid-template-columns: 64px 1fr; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 14px; }
.log-day + .log-row { border-top: 0; }
.log-time { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; padding-top: 2px; }
.log .muted { font-size: 12px; }
.changes { margin: 4px 0 0; padding-left: 18px; color: var(--muted); font-size: 13px; }
.tags { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.tag { font-size: 11px; padding: 2px 7px; border-radius: 999px; background: var(--line); color: var(--muted); }
.tag.warn { background: #fee2e2; color: #991b1b; }
.tag.note { background: var(--b-soft); color: var(--b); }

@media (max-width: 420px) {
  .brand .long { display: none; } .brand .short { display: inline; }
  .cell input { width: 42px; height: 42px; font-size: 17px; }
  table.sc td.si { display: none; } table.sc th.si { display: none; }
  .si-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}
