:root {
  --bg: #f4f6f4;
  --surface: #ffffff;
  --surface-2: #f0f3f0;
  --text: #14201a;
  --muted: #5d6c63;
  --line: #dde3dd;
  --accent: #0b5d2e;
  --accent-text: #ffffff;
  --danger: #b3261e;
  --warn: #a25a00;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 4px 14px rgba(0, 0, 0, .05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10140f;
    --surface: #191f19;
    --surface-2: #222a22;
    --text: #e8efe8;
    --muted: #9aab9f;
    --line: #2e382e;
    --accent: #4caf6d;
    --accent-text: #06210f;
    --danger: #f2a09a;
    --warn: #e0a458;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 14px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }

/* The UA's `[hidden] { display: none }` is a bare attribute selector, so any
   class here that sets `display` outranks it and the element stays visible.
   Every view in this app is toggled with the hidden attribute, so this has to
   win outright. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.1rem; }
code { background: var(--surface-2); padding: .1em .35em; border-radius: 4px; font-size: .9em; }

/* ---- Top bar ---- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: .85rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: .55rem; font-weight: 650; }
.brand-mark { font-size: 1.25rem; }
.session { display: flex; align-items: center; gap: .75rem; }
.who { color: var(--muted); font-size: .9rem; }

/* ---- Layout ---- */

.center {
  min-height: 70vh;
  display: grid;
  place-items: center;
  padding: 2rem 1.25rem;
}

#app { padding: 1.25rem; max-width: 1180px; margin: 0 auto; }

.split {
  display: grid;
  grid-template-columns: minmax(230px, 300px) 1fr;
  gap: 1rem;
  align-items: start;
}

@media (max-width: 780px) {
  .split { grid-template-columns: 1fr; }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.1rem;
}

.panel + .panel, .panel.grow > * + * { margin-top: 1rem; }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
}

.narrow { width: min(420px, 92vw); }
.muted { color: var(--muted); }
.right { text-align: right; }

/* ---- Tabs ---- */

.tabs { display: flex; gap: .35rem; margin-bottom: 1rem; flex-wrap: wrap; }

.tab {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: .5rem .9rem;
  border-radius: 999px;
  font: inherit;
  font-weight: 550;
  cursor: pointer;
}

.tab:hover { background: var(--surface-2); color: var(--text); }
.tab[aria-selected="true"] { background: var(--accent); color: var(--accent-text); }

/* ---- Buttons ---- */

.btn {
  font: inherit;
  font-weight: 550;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  padding: .5rem .9rem;
  cursor: pointer;
}

.btn:hover { filter: brightness(1.04); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.link { background: none; border: none; color: var(--accent); padding: .25rem .4rem; }
.btn.danger { color: var(--danger); }

.provider-buttons { display: grid; gap: .6rem; margin: 1.25rem 0 .5rem; }

.btn.provider {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .6rem;
  padding: .7rem 1rem;
  font-size: 1rem;
}

.btn.provider svg { width: 18px; height: 18px; flex: none; }
.btn.provider.apple { background: #000; color: #fff; border-color: #000; }
/* Google requires its mark on white; keep it white in dark mode too. */
.btn.provider.google { background: #fff; color: #1f1f1f; border-color: #d0d0d0; }

/* ---- Lists ---- */

.list { list-style: none; margin: 0; padding: 0; display: grid; gap: .3rem; }

.list button {
  width: 100%;
  text-align: left;
  font: inherit;
  cursor: pointer;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 9px;
  padding: .55rem .65rem;
  color: inherit;
  display: grid;
  gap: .15rem;
}

.list button:hover { background: var(--surface-2); }
.list button[aria-current="true"] { background: var(--surface-2); border-color: var(--accent); }
.list .title { font-weight: 600; }
.list .sub { font-size: .8rem; color: var(--muted); }

/* ---- Tables ---- */

.table-scroll { overflow-x: auto; margin-top: .75rem; }

.grid { width: 100%; border-collapse: collapse; font-size: .93rem; }
.grid th, .grid td { padding: .55rem .6rem; border-bottom: 1px solid var(--line); text-align: left; }
.grid th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
.grid tbody tr:last-child td { border-bottom: none; }
.grid .num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---- Standings ---- */

.group-card { border: 1px solid var(--line); border-radius: var(--radius); padding: .85rem 1rem; }
.group-card + .group-card { margin-top: .75rem; }

.group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  flex-wrap: wrap;
  margin-bottom: .5rem;
}

.badge {
  display: inline-block;
  font-size: .75rem;
  font-weight: 650;
  padding: .15rem .5rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  color: var(--accent);
}

.badge.grey { background: var(--surface-2); color: var(--muted); }
.badge.warn { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.rank { width: 1.75rem; font-weight: 700; color: var(--muted); }
.rank.top { color: var(--accent); }

.meta { display: flex; gap: .75rem; flex-wrap: wrap; color: var(--muted); font-size: .85rem; }

/* ---- Forms ---- */

label { display: grid; gap: .3rem; margin-bottom: .75rem; font-size: .9rem; color: var(--muted); }

input[type="text"], input[type="number"], input:not([type]) {
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .5rem .6rem;
  width: 100%;
}

input:focus-visible, .btn:focus-visible, .tab:focus-visible, .list button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1rem; margin: 0 0 1rem; }
legend { font-weight: 650; padding: 0 .35rem; }

.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: .6rem; }
.field-row label { margin-bottom: 0; }

/* ---- Tee sheet ---- */

/* `label` is a grid by default above, which would stack the caption over the
   control. These captions are visually hidden or sit inline, so opt out. */
label.inline { display: inline-flex; align-items: center; gap: .35rem; margin: 0; }
label.inline.check { cursor: pointer; }
label.inline input, label.inline select { width: auto; }

select {
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .35rem .5rem;
}

select:focus-visible, input[type="checkbox"]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.weekend-nav { display: flex; align-items: center; gap: .4rem; }
.weekend-nav input[type="date"] {
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .4rem .55rem;
  width: auto;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-wrap: wrap;
  margin: .85rem 0 0;
}

.toolbar .search { margin: 0; flex: 1 1 220px; }
.toolbar .search input { max-width: 340px; }

.day-summary { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: .85rem; }

.day-chip {
  display: grid;
  gap: .1rem;
  flex: 1 1 200px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: .6rem .75rem;
  font-size: .85rem;
}

.day-chip-day { font-weight: 650; font-size: .95rem; }
.day-chip-count { color: var(--accent); font-weight: 600; }

/* Not `.center` — that name is already the full-page layout wrapper above
   (`display: grid`), which turns a table cell into a grid box and breaks the
   row apart. */
.grid .mid, th.mid { text-align: center; }
.grid .sub { font-size: .8rem; }
.grid tr.missing td { opacity: .6; font-style: italic; }

input[type="checkbox"].tick { width: 1.05rem; height: 1.05rem; accent-color: var(--accent); }

.segmented { display: inline-flex; gap: .25rem; margin: .25rem 0 1rem; flex-wrap: wrap; }

.seg {
  font: inherit;
  font-weight: 550;
  cursor: pointer;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: .4rem .9rem;
}

.seg:hover { background: var(--surface-2); color: var(--text); }
.seg[aria-selected="true"] { background: var(--accent); color: var(--accent-text); border-color: transparent; }

.tee-controls {
  display: flex;
  align-items: flex-end;
  gap: .75rem;
  flex-wrap: wrap;
  padding: .85rem 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.tee-controls > label { margin: 0; width: 8.5rem; }
.tee-controls input { width: 100%; }
.tee-actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-left: auto; }

.balance { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin: 1rem 0 .25rem; font-size: .85rem; }

.tee-group .group-head { align-items: flex-start; }
.tee-group-tools { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.tee-foot { margin: .5rem 0 0; font-size: .82rem; }
.won-label { font-size: .78rem; color: var(--muted); }

/* ---- Roster import / sync ---- */

.sync-status { font-size: .85rem; margin: .35rem 0 0; }
.sync-status.failed { color: var(--danger); }
/* A run that succeeded but only partly — warned, not alarmed. */
.sync-status.degraded { color: var(--warn); }

.import-card { width: min(640px, 94vw); max-height: 88vh; overflow-y: auto; }
.import-card textarea {
  font: inherit;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .85rem;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .5rem .6rem;
  width: 100%;
  resize: vertical;
}
.import-card input[type="file"] { font-size: .85rem; }

.import-summary { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; margin: .5rem 0; font-size: .85rem; }
.import-errors { margin: .25rem 0 .5rem; padding-left: 1.1rem; color: var(--warn); font-size: .82rem; }
.import-preview { max-height: 220px; overflow-y: auto; }

/* ---- Scorecard ---- */

.scorecard-scroll { margin-top: .75rem; }

.scorecard {
  border-collapse: collapse;
  font-size: .82rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.scorecard th, .scorecard td {
  border: 1px solid var(--line);
  padding: 0;
  text-align: center;
  min-width: 2.1rem;
}

.scorecard thead th {
  background: var(--surface-2);
  font-size: .72rem;
  font-weight: 650;
  color: var(--muted);
  padding: .3rem .1rem;
}

/* The name column stays put while the holes scroll under it — an 18-hole card
   is wider than a phone, and a row of numbers with no name is useless. */
.scorecard .who {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--surface);
  text-align: left;
  padding: .3rem .5rem;
  min-width: 8.5rem;
  font-weight: 550;
}

.scorecard thead .who { background: var(--surface-2); }
.scorecard .meta-row td { color: var(--muted); font-size: .75rem; padding: .2rem .1rem; }
.scorecard .tot { background: var(--surface-2); font-weight: 650; padding: .3rem .35rem; }
.scorecard .empty-cell { color: var(--line); }

.scorecard td button {
  font: inherit;
  font-variant-numeric: tabular-nums;
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  width: 100%;
  padding: .3rem .1rem;
  display: block;
  position: relative;
}

.scorecard td button:hover { background: var(--surface-2); }

/* Scores marked the way a card marks them: ring for under par, square for
   over. Drawn on the number itself so the grid stays aligned. */
.scorecard .gross {
  display: inline-grid;
  place-items: center;
  min-width: 1.45rem;
  min-height: 1.45rem;
  line-height: 1;
}

.scorecard .birdie .gross { border-radius: 50%; border: 1.5px solid var(--accent); }
.scorecard .eagle .gross { border-radius: 50%; border: 3px double var(--accent); }
.scorecard .bogey .gross { border: 1.5px solid var(--muted); }
.scorecard .double .gross { border: 3px double var(--danger); color: var(--danger); }

.scorecard .dots {
  position: absolute;
  top: .1rem;
  right: .18rem;
  font-size: .5rem;
  line-height: 1;
  color: var(--accent);
}

.scorecard-key { font-size: .78rem; margin: .4rem 0 0; }

.hole-matchup {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-wrap: wrap;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: .5rem .7rem;
  margin-bottom: .75rem;
  font-size: .9rem;
}

/* Balls that count for the team. Shading rather than another ring, so it
   layers under the birdie/bogey marks instead of fighting them. */
.scorecard td.counts { background: color-mix(in srgb, var(--accent) 15%, transparent); }
.scorecard td.ties { background: color-mix(in srgb, var(--accent) 6%, transparent); }
.scorecard td.ties button { outline: 1px dashed color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: -3px; }
.scorecard td.counts button:hover, .scorecard td.ties button:hover {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
}

.grid tr.counted td { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.grid tr.tied td { background: color-mix(in srgb, var(--accent) 4%, transparent); }

.key-counted {
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  padding: 0 .25rem;
  border-radius: 3px;
}
.key-tied {
  outline: 1px dashed color-mix(in srgb, var(--accent) 55%, transparent);
  outline-offset: -1px;
  padding: 0 .25rem;
}

/* ---- Outing / group setup ---- */

/* 18 holes across on a wide dialog, wrapping down on a phone. Each cell is a
   hole number with par above stroke index. */
.hole-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(52px, 1fr));
  gap: .3rem;
}

.hole-cell {
  display: grid;
  gap: .15rem;
  justify-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .3rem .2rem;
}

.hole-num { font-size: .7rem; font-weight: 650; color: var(--muted); }
.hole-cell input {
  width: 100%;
  padding: .25rem .1rem;
  text-align: center;
  font-size: .85rem;
}

.group-picker { max-height: 240px; overflow-y: auto; }

.pick-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: .55rem;
  margin: 0;
  padding: .4rem .3rem;
  border-bottom: 1px solid var(--line);
  font-size: .9rem;
  color: var(--text);
  cursor: pointer;
}

.pick-row:last-child { border-bottom: none; }
.pick-row:hover { background: var(--surface-2); }
.pick-row input { width: auto; }
.pick-name { font-weight: 550; }

.pairs { margin: .3rem 0 .75rem; padding-left: 1.1rem; font-size: .9rem; }

/* ---- Messages ---- */

.banner, .notice {
  border-radius: 9px;
  padding: .6rem .75rem;
  font-size: .9rem;
  margin: 0 0 1rem;
}

.banner.error, .notice.error { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.notice { background: var(--surface-2); color: var(--muted); }
.notice.ok { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }

.empty { color: var(--muted); font-size: .9rem; padding: .75rem 0; }

.search { margin: .85rem 0 0; }
.search input { max-width: 340px; }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  clip-path: inset(50%);
  overflow: hidden;
  white-space: nowrap;
}

/* ---- Dialog ---- */

dialog {
  border: none;
  background: transparent;
  padding: 0;
  color: var(--text);
}

dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog menu { display: flex; justify-content: flex-end; gap: .5rem; margin: 1rem 0 0; padding: 0; }
/* Sits with the fields above it rather than at the foot of the card, so a
   Search button reads as part of the search rather than as a second Save. */
dialog menu.inline { justify-content: flex-start; margin: .5rem 0 0; }

/* ---- Course lookup ---- */

.pick-list { display: flex; flex-direction: column; gap: .35rem; margin: .85rem 0 0; }
.pick-list button {
  display: flex; justify-content: space-between; align-items: baseline; gap: .75rem;
  width: 100%; text-align: left;
  padding: .55rem .7rem;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface-2); color: var(--text);
  font: inherit; cursor: pointer;
}
.pick-list button:hover { border-color: var(--accent); }
.pick-list button[aria-current="true"] { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.pick-list .sub { color: var(--muted); font-size: .8rem; }

/* ---- Duplicate cleanup ---- */

.merge-set {
  border: 1px solid var(--line); border-radius: 8px;
  padding: .6rem .75rem; margin: .6rem 0 0;
  background: var(--surface-2);
}
.merge-set p { margin: .35rem 0 0; font-size: .85rem; }
.merge-head { display: flex; align-items: flex-start; gap: .5rem; cursor: pointer; }
.merge-head input { margin-top: .2rem; }
.merge-head .badge { margin-left: .4rem; }

#coursePreview h3 { margin: 1.25rem 0 0; font-size: 1rem; }
.tee-table { width: 100%; border-collapse: collapse; margin: .5rem 0 0; font-size: .85rem; }
.tee-table th, .tee-table td { text-align: left; padding: .3rem .5rem; border-bottom: 1px solid var(--line); }
.tee-table th { color: var(--muted); font-weight: 600; }
.tee-table td.right, .tee-table th.right { text-align: right; }
