:root {
  --green: #1f4d2b;
  --green-soft: #e7efe8;
  --ink: #16181a;
  --muted: #5b6168;
  --line: #d5d9dd;
  --bg: #ffffff;
  --gold: #f2c14e;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 18px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
main, .top, .contacts { max-width: 560px; margin: 0 auto; padding: 0 16px; }

.top { padding-top: calc(12px + env(safe-area-inset-top)); display: flex; align-items: center; gap: 12px; justify-content: space-between; }
.top h1 { font-size: 24px; margin: 8px 0; color: var(--green); }
.top p { margin: 0; color: var(--muted); }
.top h1 { display: flex; align-items: center; gap: 10px; }
.top h1 img { width: 36px; height: 36px; border-radius: 8px; }
.season-btn { background: var(--green); color: #fff; border: 0; border-radius: 999px; padding: 8px 16px; font-size: 16px; font-weight: 700;
  white-space: nowrap; }

h2 { font-size: 20px; margin: 24px 0 8px; }
.hint { color: var(--muted); font-size: 16px; margin: 12px 0; }
.result { font-weight: 600; min-height: 1.4em; }

button { font: inherit; border-radius: 10px; cursor: pointer; }
.primary { background: var(--green); color: #fff; border: 0; padding: 12px 18px; font-weight: 600; }
.secondary { background: #fff; color: var(--green); border: 2px solid var(--green); padding: 10px 16px; font-weight: 600; margin: 4px 8px 4px 0; }
/* text buttons still get a full-size tap area */
.link { background: none; border: 0; color: var(--green); text-decoration: underline; padding: 4px; min-height: 44px; min-width: 44px; }
.wide { width: 100%; margin-top: 16px; padding: 16px; font-size: 20px; }
button:disabled { opacity: .5; }

input { font: inherit; padding: 10px 12px; border: 2px solid var(--line); border-radius: 10px; width: 100%; background: #fff; color: var(--ink); }
/* iPhone draws date boxes its own way and ignores their width unless its built-in look is turned off */
input[type="date"] { -webkit-appearance: none; appearance: none; display: block; min-width: 0; max-width: 100%; min-height: 48px; text-align: left; }
input[type="date"]::-webkit-date-and-time-value { text-align: left; }
input:focus { outline: none; border-color: var(--green); }
label { display: block; font-weight: 600; margin: 12px 0 6px; }
.inline { display: flex; gap: 8px; align-items: center; }
.inline input { flex: 1; min-width: 0; }
.inline .secondary { margin: 0; }
.row { margin: 12px 0; }

#notices { background: #fff6dc; border: 2px solid var(--gold); border-radius: 12px; padding: 4px 14px; margin: 12px 0; }
.index-row { display: flex; justify-content: space-between; align-items: center; margin: 8px 0; font-weight: 600; }

.choice { display: flex; gap: 8px; margin: 12px 0; }
.choice button { flex: 1; padding: 14px 8px; border: 2px solid var(--green); background: #fff; color: var(--green); font-weight: 700; font-size: 20px; }
.choice.small button { font-size: 16px; padding: 10px 4px; }
.choice button.on { background: var(--green); color: #fff; }
/* the tee buttons look like the tee markers: white, yellow, red; the chosen one gets a tick and a darker edge */
#tee-choice button { color: var(--ink); border: 2px solid #9aa3ab; }
#tee-choice button[data-tee="white"] { background: #fff; }
#tee-choice button[data-tee="yellow"] { background: #f4d23c; border-color: #c9a80f; }
#tee-choice button[data-tee="red"] { background: #c0504d; border-color: #8e3431; color: #fff; }
#tee-choice button.on { border-width: 3px; border-color: var(--ink); box-shadow: 0 0 0 2px #fff inset; font-weight: 800; }
#tee-choice button.on .tee-name::before { content: '✓ '; }
#tee-choice button { display: flex; flex-direction: column; align-items: center; line-height: 1.2; padding: 8px 4px; }
#tee-choice .tee-hc { font-size: 24px; font-weight: 800; }

.card { width: 100%; border-collapse: collapse; margin-top: 8px; }
.card th { text-align: left; font-size: 14px; color: var(--muted); font-weight: 600; padding: 6px 4px; border-bottom: 2px solid var(--line); }
.card td { padding: 6px 4px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.card td.hole { font-weight: 700; width: 3em; }
.card td.best { font-weight: 700; font-size: 20px; }
.card td.best.net { color: var(--muted); }
/* on the entry card every column is centred under its heading: hole, par, best gross, best net, today, totals */
#tab-card .card th, #tab-card .card td { text-align: center; }
.card td .star { color: #c9a80f; margin-left: 2px; }
.net-chance-note { background: #fff6dc; border-radius: 10px; padding: 8px 12px; font-size: 16px; font-weight: 600; margin: 8px 0; }
.card td input { width: 3.2em; text-align: center; font-size: 22px; font-weight: 700; padding: 8px 4px; }
.card.view .shots, .shots-key .shots { display: inline-flex; flex-direction: column; vertical-align: middle; margin-left: 3px;
  color: var(--green); font-weight: 800; font-size: 14px; line-height: .6; }
.shots-key .shots { width: 1em; align-items: center; margin: 0 6px 0 0; }
/* the player's card reads like a scorecard: every column centred under its heading, as on the Scores card */
.card.view th, .card.view td { text-align: center; }
.card.view td.si { color: var(--muted); font-size: 15px; }
.shots-key ul { list-style: none; padding-left: 0; margin: 4px 0; }
.shots-key p { margin: 8px 0 0; }
.late-box { background: #fff6dc; border: 2px solid var(--gold); border-radius: 12px; padding: 4px 12px 12px; margin: 12px 0; }
.late-box label { margin-top: 4px; }
textarea { font: inherit; width: 100%; padding: 10px 12px; border: 2px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink); resize: vertical; }
textarea:focus { outline: none; border-color: var(--green); }
.late-reason { background: #fff6dc; border-radius: 10px; padding: 8px 12px; }
.card td input.bad { border-color: #b3261e; background: #fdecea; color: #b3261e; }
.card tfoot td { font-weight: 700; font-size: 20px; border-bottom: 0; padding-top: 12px; }

/* the heading row and each player row share the same fixed columns, so each heading sits exactly over what it labels */
.board-wrap { margin-top: 12px; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
ol.board { list-style: none; margin: 0; padding: 0; }
.board-head, .board .row { display: flex; align-items: center; gap: 12px; width: 100%; margin: 0; padding: 0 20px 0 0; }
.board-head { min-height: 40px; background: var(--green); color: #fff; font-size: 13px; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; }
.board .row { min-height: 56px; border: 0; border-top: 1px solid var(--line); border-radius: 0; background: #fff; color: var(--ink);
  font-size: 18px; text-align: left; }
.board li:first-child .row { border-top: 0; }
/* the second and later names in a tie carry no position and a fainter line, so the group reads as one */
.board .row.tie { border-top-color: #eef0f2; }
.board .row.me { background: var(--green-soft); box-shadow: inset 4px 0 0 var(--green); font-weight: 700; }
.board-head .pos, .board .pos { width: 52px; flex: none; text-align: center; }
.board .pos { font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }
.board-head .name, .board .name { flex: 1; min-width: 0; }
.board-head .total, .board .total { width: 48px; flex: none; text-align: right; font-variant-numeric: tabular-nums; }
.board .total { font-size: 20px; font-weight: 700; }

.back { margin-top: 8px; font-size: 18px; }
.player-name { font-size: 24px; margin: 8px 0 0; }
.ko-status { font-weight: 600; color: var(--green); margin: 4px 0; }
.stats { display: flex; gap: 12px; margin: 12px 0; }
.stats div { flex: 1; background: var(--green-soft); border-radius: 12px; padding: 10px 12px; text-align: center; }
.stats b { font-size: 30px; display: block; line-height: 1.1; }
.stats span { display: block; font-weight: 600; }
.stats small { color: var(--muted); font-size: 15px; }
.facts { margin: 8px 0 12px; padding-left: 20px; }
.facts li { margin: 4px 0; }
.card.view td small { display: block; font-size: 13px; color: var(--muted); }
.card.view .score { display: inline-block; min-width: 1.9em; text-align: center; font-weight: 700; font-size: 20px; line-height: 1.8em; }
.card.view .score.birdie { border: 2px solid var(--green); border-radius: 50%; }
.card.view .score.eagle { border: 2px solid var(--green); border-radius: 50%; box-shadow: 0 0 0 3px #fff, 0 0 0 5px var(--green); }
.card.view .score.bogey { border: 2px solid var(--ink); border-radius: 2px; }
.card.view .score.double { border: 2px solid var(--ink); border-radius: 2px; box-shadow: 0 0 0 3px #fff, 0 0 0 5px var(--ink); }
.card.view td.when { font-size: 15px; color: var(--muted); white-space: nowrap; }
.card.view td.when.never { font-size: 20px; font-weight: 700; color: #b3261e; text-align: center; }

/* Knockout: one column per round, matches spread evenly down each column. */
.bracket { --gap: 10px; --box: 50px; display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); column-gap: var(--gap); margin-top: 8px; }
.ko-head { font-size: 13px; font-weight: 700; color: var(--muted); text-align: center; min-height: 34px; line-height: 1.2; }
.ko-head small { display: block; font-weight: 400; }
.ko-body { display: flex; flex-direction: column; height: calc(var(--rows) * (var(--box) + 12px)); }
.ko-pair { flex: 1; display: flex; flex-direction: column; justify-content: space-around; position: relative; }
.ko-match { position: relative; display: flex; flex-direction: column; justify-content: center; height: var(--box); width: 100%;
  padding: 2px 6px; border: 1px solid var(--line); border-radius: 8px; background: #fff; text-align: left; color: var(--ink); }
.ko-match.mine { border: 2px solid var(--green); }
.ko-line { display: flex; justify-content: space-between; gap: 2px; font-size: 14px; line-height: 1.5; white-space: nowrap; color: var(--ink); }
.ko-line .nm { overflow: hidden; text-overflow: ellipsis; }
.ko-line.won { font-weight: 700; color: var(--green); }
.ko-line.lost { color: var(--muted); }
.ko-line .sc { font-size: 12px; font-weight: 700; }
/* each round is drawn from the hat, so no lines join the rounds; a round not drawn yet has dashed, empty boxes */
.ko-col.undrawn .ko-match { border-style: dashed; background: #fafbfb; }
.ko-col.undrawn .ko-head small { color: #9a5b00; }
.full { display: none; }
@media (min-width: 640px) {
  main, .top, .contacts { max-width: 900px; }
  .bracket { --gap: 18px; }
  .short { display: none; }
  .full { display: inline; }
  .ko-head .full { display: block; }
}

.sheet-back { position: fixed; inset: 0; background: rgba(0, 0, 0, .35); display: flex; align-items: flex-end; justify-content: center; z-index: 10; }
.sheet { background: #fff; width: 100%; max-width: 560px; border-radius: 16px 16px 0 0; padding: 12px 16px calc(20px + env(safe-area-inset-bottom)); max-height: 85vh; overflow-y: auto; }
.sheet .v { display: block; color: var(--muted); font-size: 14px; margin-left: 2px; }
.sheet .status { margin: 10px 0 4px; font-weight: 600; }
.sheet .close { display: block; margin: 12px auto 0; }
.name-link { background: none; border: 0; padding: 2px 0; color: var(--ink); font-size: 20px; text-align: left; text-decoration: underline; text-decoration-color: var(--line); }
.name-link.won { font-weight: 700; color: var(--green); }
.tbd { color: var(--muted); font-style: italic; }
.enter .secondary { flex: 1; }
.enter .secondary.on { background: var(--green); color: #fff; }
.enter input { margin: 8px 0; }

select { font: inherit; font-size: 15px; padding: 8px; border: 2px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink); min-width: 0; flex: 1; }
.inline.draw { margin: 6px 0; }
.round-name { width: 6.5em; flex: none; font-size: 16px; }
/* play-by dates: room between the rows, and a Save button wide enough for "Saved" so the date box never changes size */
.inline.play-by { margin: 14px 0; }
.inline.play-by button { flex: none; width: 5.2em; text-align: center; padding-left: 0; padding-right: 0; }

/* small phones (iPhone SE and the like): a smaller header so nothing runs off the side, and the round name above its date */
@media (max-width: 359px) {
  .top { gap: 8px; }
  .top h1 { font-size: 20px; gap: 8px; }
  .top h1 img { width: 30px; height: 30px; }
  .season-btn { padding: 6px 12px; font-size: 15px; }
  .inline.play-by { flex-wrap: wrap; }
  .inline.play-by .round-name { width: 100%; }
}

.for-box { background: #fff6dc; border: 2px solid var(--gold); border-radius: 12px; padding: 4px 12px 10px; margin: 12px 0; }
.for-box label { margin-top: 8px; }
.for-box select { width: 100%; font-size: 18px; }
.for-box .hint { margin: 8px 0 0; }
.attached { color: var(--green); font-weight: 600; }
.secondary.on { background: var(--green); color: #fff; }
.danger { color: #b3261e; }
/* two actions side by side: Save changes and Cancel, Edit round and Delete round */
.pair { display: flex; gap: 10px; }
.pair .wide { flex: 1; min-width: 0; margin: 16px 0 0; }
.secondary.danger { border-color: #b3261e; }
.checked-list { margin: 16px 0; }
.primary.saved { background: #2e7d4f; }
.edit-note { background: #fff6dc; border: 2px solid var(--gold); border-radius: 12px; padding: 2px 12px; margin: 12px 0; font-weight: 600; }
#played:disabled { background: #f1f3f4; color: var(--muted); }
.round-line { display: grid; grid-template-columns: auto 1fr auto; column-gap: 10px; align-items: center; width: 100%; text-align: left;
  background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin: 8px 0; color: var(--ink); }
.round-line.pending { border: 2px solid var(--gold); }
.round-line.deleted, .round-line.rejected { opacity: .6; }
.round-line .who { font-weight: 700; font-size: 18px; }
.round-line .what { font-size: 16px; }
.round-line .why { grid-column: 1 / 3; font-size: 14px; color: var(--muted); }
.round-line .why:empty { display: none; }
.round-line .scores { grid-column: 1 / 3; font-size: 16px; font-variant-numeric: tabular-nums; }
.round-line.asked { border: 2px solid #b3261e; }
.card tr.net-chance td { background: #fff6dc; }
.round-line .go { grid-row: 1 / 3; grid-column: 3; font-size: 26px; color: var(--muted); }
.round-meta { font-size: 18px; font-weight: 600; margin: 4px 0; }
.grid-wrap { margin: 12px 0; }
table.grid { width: 100%; border-collapse: collapse; margin-bottom: 10px; table-layout: fixed; }
table.grid caption { text-align: left; font-weight: 700; font-size: 15px; padding: 4px 0; }
table.grid th, table.grid td { border: 1px solid var(--line); text-align: center; padding: 6px 0; font-size: 16px; }
table.grid tr > th:first-child { width: 5.2em; text-align: left; padding-left: 6px; font-size: 13px; }
table.grid .hole-row th { background: var(--green); color: #fff; }
table.grid td.muted { color: var(--muted); }
table.grid .this-round td { font-weight: 700; font-size: 18px; }
table.grid td.new-best { background: #d8f0dc; color: var(--green); }
img.card-photo { width: 100%; border-radius: 10px; border: 1px solid var(--line); margin: 8px 0; }
.decide { margin: 12px 0; }
.decide .match-tick { font-size: 18px; margin-bottom: 4px; }
.history-wrap { overflow-x: auto; margin: 8px -16px; padding: 0 16px; }
table.history { border-collapse: collapse; font-size: 16px; }
table.history th, table.history td { border: 1px solid var(--line); padding: 6px 8px; text-align: center; min-width: 2em; }
table.history .date { position: sticky; left: 0; background: #fff; text-align: left; white-space: nowrap; min-width: 3.4em; }
table.history .date small { display: block; font-size: 11px; color: #9a5b00; font-weight: 600; }
table.history thead tr:first-child th { background: var(--green); color: #fff; }
table.history thead tr:first-child th.date { background: var(--green); }
table.history tr.par th { font-weight: 400; color: var(--muted); }
table.history td.hc { color: var(--muted); }
table.history td.new-best { background: #d8f0dc; color: var(--green); font-weight: 700; }
table.history tr.faded td, table.history tr.faded th { opacity: .5; }
table.history tfoot th { font-weight: 700; }
.flags { color: #9a5b00; font-weight: 600; font-size: 14px; }
.match-tick { display: flex; align-items: center; gap: 8px; font-weight: 600; margin: 0; width: 100%; }
.match-tick input { width: 24px; height: 24px; flex: none; }
.sheet .ask { font-size: 20px; font-weight: 600; margin: 8px 0 12px; }
.sheet .wide { margin-top: 10px; }
table.gains { border-collapse: collapse; margin: 8px 0; min-width: 60%; }
table.gains caption { text-align: left; font-weight: 700; padding-bottom: 4px; }
table.gains th, table.gains td { padding: 6px 14px 6px 0; border-bottom: 1px solid var(--line); text-align: left; font-size: 18px; }
table.gains td { font-weight: 700; }
.checked-list summary { font-weight: 600; cursor: pointer; padding: 8px 0; }
.players td.yes { color: var(--green); white-space: nowrap; }
.players td.no { color: #b3261e; white-space: nowrap; }
.players { width: 100%; border-collapse: collapse; }
.players th, .players td { text-align: left; padding: 8px 4px; border-bottom: 1px solid var(--line); font-size: 16px; }
.link-box { background: var(--green-soft); border-radius: 12px; padding: 4px 12px 12px; margin: 8px 0; }
.link-box input { font-size: 14px; margin-bottom: 8px; }

.contacts { color: var(--muted); font-size: 15px; margin-top: 32px; }
.contacts p { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0; padding: 10px 0;
  border-top: 1px solid var(--line); }
.contact-btn { flex: none; color: var(--green); border: 2px solid var(--green); border-radius: 999px; padding: 8px 14px; font-weight: 700;
  text-decoration: none; white-space: nowrap; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; background: #fff; border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  background: none; border: 0; border-radius: 0; padding: 16px 2px; font-weight: 600; font-size: 15px; color: var(--muted); }
.tabs button.on { color: var(--green); box-shadow: inset 0 3px 0 var(--green); }

.signed-out { padding-top: 48px; }
.signed-out h1 { color: var(--green); }
.names { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.names .secondary { margin: 0; min-height: 52px; font-size: 18px; }
#pin, .pin-sheet input { font-size: 28px; letter-spacing: .4em; text-align: center; }
.account { display: flex; flex-wrap: wrap; gap: 4px 16px; align-items: center; }
