:root {
  --bg: #f5f4ee;
  --surface: #ffffff;
  --ink: #1b2420;
  --muted: #69736d;
  --line: #e2e1d8;
  --line-strong: #cfcdc1;
  --brand: #1d4a32;
  --brand-ink: #ffffff;
  --brand-soft: #e5efe8;
  --gold: #a87f12;
  --gold-soft: #f8f0d6;
  --danger: #b3261e;
  --danger-soft: #fbe9e7;
  --break-bg: #fdefe4;
  --break-ink: #a3480f;
  --break-line: #f2cdb2;
  --chart-line: #2f7a4f;
  --accent: #2f7a4f;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 30, 25, .05);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111513;
    --surface: #181e1b;
    --ink: #e6ebe8;
    --muted: #9aa49f;
    --line: #27302c;
    --line-strong: #36403b;
    --brand: #173b28;
    --brand-ink: #f1f5f2;
    --brand-soft: #1e3628;
    --gold: #e0b847;
    --gold-soft: #2e2915;
    --danger: #f08a80;
    --danger-soft: #3a1d1a;
    --break-bg: #33221a;
    --break-ink: #f2a874;
    --break-line: #4b3226;
    --chart-line: #4aa874;
    --accent: #6cc596;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

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

a { color: inherit; }
code { font-size: .9em; background: var(--brand-soft); padding: 1px 5px; border-radius: 4px; }

.wrap { max-width: 980px; margin: 0 auto; padding: 0 16px; }
main.wrap { padding-bottom: 64px; }

/* ---------- header ---------- */
.site-header { background: var(--brand); color: var(--brand-ink); }
.header-inner { display: flex; align-items: center; gap: 16px; min-height: 56px; }
.brand { display: flex; align-items: center; gap: 6px; font-weight: 700; font-size: 17px; text-decoration: none; letter-spacing: -.01em; white-space: nowrap; }
.brand-short { display: none; }
.top-nav { margin-left: auto; }
.header-tools { display: flex; align-items: center; gap: 8px; }
.season-switch select {
  background: rgba(255, 255, 255, .12);
  color: var(--brand-ink);
  border: 1px solid rgba(255, 255, 255, .28);
  border-radius: 999px;
  min-height: 34px;
  padding: 4px 12px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}
.season-switch select:hover { background: rgba(255, 255, 255, .2); }
.season-switch option { color: var(--ink); background: var(--surface); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.nav { display: flex; gap: 4px; }
.nav a, .admin-link { text-decoration: none; padding: 6px 12px; border-radius: 999px; opacity: .82; font-weight: 500; }
.nav a:hover, .admin-link:hover { opacity: 1; background: rgba(255, 255, 255, .1); }
.nav a[aria-current="page"], .admin-link[aria-current="page"] { opacity: 1; background: rgba(255, 255, 255, .18); }
.admin-link { display: inline-flex; align-items: center; gap: 6px; }
.admin-link svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* the bottom tab bar only appears on phones */
.tabbar { display: none; }

/* phone-only extras: a muted line under a name that carries the columns hidden on small screens */
.show-sm { display: none; }
.meta { font-size: 12.5px; font-weight: 500; color: var(--muted); line-height: 1.35; margin-top: 2px; }

/* ---------- headings ---------- */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin: 28px 0 16px; }
.eyebrow { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.eyebrow a { text-decoration: none; }
.eyebrow a:hover { text-decoration: underline; }
h1 { margin: 2px 0 0; font-size: 28px; line-height: 1.2; letter-spacing: -.02em; }
h2 { font-size: 18px; margin: 36px 0 12px; letter-spacing: -.01em; }
.page-head p.muted { margin: 4px 0 0; }

.muted { color: var(--muted); }
.dim { color: var(--line-strong); }
.strong { font-weight: 650; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.empty { padding: 32px; text-align: center; color: var(--muted); background: var(--surface); border: 1px dashed var(--line-strong); border-radius: var(--radius); }
.footnote { color: var(--muted); font-size: 13px; margin: 10px 2px 0; }
div.footnote { margin-top: 14px; }
div.footnote p { margin: 3px 0; }
.points-form .table-wrap { max-width: 420px; }

/* ---------- pickers ---------- */
.picker { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.picker label { font-size: 13px; color: var(--muted); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 10px 12px; text-align: left; vertical-align: middle; }
th { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); border-bottom: 1px solid var(--line); white-space: nowrap; vertical-align: bottom; line-height: 1.3; }
tbody tr + tr td { border-top: 1px solid var(--line); }
tbody tr:hover td { background: color-mix(in srgb, var(--brand-soft) 45%, var(--surface)); }
.num { text-align: right; }
.pos { width: 3.5em; color: var(--muted); font-weight: 600; }
td.week { font-weight: 650; white-space: nowrap; }
.player { text-decoration: none; font-weight: 600; }
.player:hover { text-decoration: underline; }

tr.leader td { background: var(--gold-soft); }
tr.leader td.pos { color: var(--gold); }
tr.leader:hover td { background: var(--gold-soft); }

.grid th, .grid td { padding: 8px 10px; }
.grid td:first-child { font-weight: 600; white-space: nowrap; }
.grid th:first-child, .grid td:first-child { position: sticky; left: 0; z-index: 1; background: var(--surface); box-shadow: 1px 0 0 var(--line); }
.scroll-x {
  background:
    linear-gradient(to left, var(--surface) 30%, transparent) right center / 40px 100% no-repeat local,
    radial-gradient(farthest-side at 100% 50%, rgba(0, 0, 0, .14), transparent) right center / 12px 100% no-repeat scroll,
    var(--surface);
}
.grid td.num:last-child, .grid th.num:last-child { border-left: 1px solid var(--line); }
.star { color: var(--gold); font-size: 10px; margin-left: 2px; vertical-align: super; }

.schedule .course { font-weight: 600; }
.schedule .note { color: var(--muted); font-size: 13px; margin-top: 2px; }
tr.break td { background: var(--break-bg); color: var(--break-ink); font-weight: 650; border-top-color: var(--break-line); }
tr.break td:first-child { box-shadow: inset 4px 0 0 var(--break-ink); }
tr.break:hover td { background: var(--break-bg); }
tr.break + tr td { border-top-color: var(--break-line); }
tr.next td { background: var(--brand-soft); }
tr.inactive td { color: var(--muted); }
tr.editing td { background: var(--gold-soft); }

/* ---------- badges ---------- */
.badge { display: inline-block; font-size: 11px; font-weight: 650; letter-spacing: .03em; padding: 1px 8px; border-radius: 999px; background: var(--line); color: var(--muted); vertical-align: 1px; white-space: nowrap; }
.badge-major { background: var(--gold-soft); color: var(--gold); border: 1px solid color-mix(in srgb, var(--gold) 35%, transparent); }
.badge-next { background: var(--brand); color: var(--brand-ink); }
.badge-done { background: var(--brand-soft); color: var(--ink); }
.badge-break { background: var(--break-ink); color: var(--surface); }

/* ---------- scores page ---------- */
.week-block { margin-top: 28px; scroll-margin-top: 16px; }
.week-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.week-head h2 { margin: 0; }
.week-head .sep { color: var(--muted); font-weight: 400; }
.week-block:target .table-wrap { outline: 2px solid var(--brand); outline-offset: 2px; }
.week-open .table-wrap { border-color: color-mix(in srgb, var(--brand) 35%, var(--line)); box-shadow: 0 0 0 3px var(--brand-soft); }
.course-line { margin: -4px 0 10px; font-size: 13px; }
td.not-played { color: var(--muted); font-style: italic; }
a.course { color: inherit; font-weight: 600; text-decoration: none; border-bottom: 1px solid var(--line-strong); }
a.course:hover { color: var(--brand); border-bottom-color: currentColor; }

/* ---------- player page ---------- */
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.stat-label { font-size: 12px; font-weight: 600; color: var(--muted); }
.stat-value { font-size: 26px; font-weight: 650; letter-spacing: -.01em; line-height: 1.25; }
.next-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 0 0 18px; }

.chart-grid { display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 760px) { .chart-grid { grid-template-columns: 1fr 1fr; } }
.chart-card { margin: 0; min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px 6px; box-shadow: var(--shadow); }
.chart-card h2 { margin: 0; font-size: 15px; }
.chart-card figcaption p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.chart { position: relative; min-height: 220px; border-radius: 6px; }
.chart:focus-visible { outline: 2px solid var(--brand); outline-offset: 4px; }
.chart svg { display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .season-rule { stroke: var(--line-strong); stroke-width: 1; }
.chart .axis-text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .series { fill: none; stroke: var(--chart-line); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { fill: var(--chart-line); stroke: var(--surface); stroke-width: 2; }
.chart .dot.active { r: 6; }
.chart .end-label { fill: var(--ink); font-size: 12px; font-weight: 650; }
.chart .crosshair { stroke: var(--line-strong); stroke-width: 1; }
.chart-tip { position: absolute; z-index: 2; pointer-events: none; display: grid; gap: 1px; padding: 6px 10px; background: var(--surface); border: 1px solid var(--line-strong); border-radius: 8px; box-shadow: 0 4px 14px rgba(0, 0, 0, .12); font-size: 12px; white-space: nowrap; }
.chart-tip strong { font-size: 15px; }
.chart-tip[hidden] { display: none; }

.season-label { margin: 18px 0 8px; font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
tr.season-row td { padding: 6px 12px; background: var(--bg); color: var(--muted); font-size: 12px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; }
tr.season-row:hover td { background: var(--bg); }
.player-rounds td.week { color: var(--muted); }
.est-round { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.est-round + .est-round { margin-top: 4px; }
.section-label { margin: 14px 0 8px; font-weight: 600; }
.player-rounds th, .player-rounds td { padding: 7px 8px; }
.player-rounds th:first-child, .player-rounds td:first-child { padding-left: 14px; }
a.one-line { display: inline-block; max-width: 230px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }

/* ---------- forms ---------- */
input, select, button { font: inherit; color: inherit; }
input:not([type="checkbox"]), select {
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  padding: 7px 10px;
  min-height: 36px;
  max-width: 100%;
}
input:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--brand) 55%, transparent); outline-offset: 1px; border-color: var(--brand); }
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--brand); }
.in-num { width: 5.5em; text-align: right; }
.in-short { width: 9em; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; color: var(--muted); }
.picker label { display: inline; font-weight: 500; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 20px; box-shadow: var(--shadow); }
.card h2 { margin: 0 0 12px; }
.form-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; }
.card .form-row + .form-row { margin-top: 12px; }
.form-row .grow { flex: 1 1 220px; }
.form-row .grow input, .form-row .grow select { width: 100%; }
.help-inline { flex-basis: 100%; margin: 0; color: var(--muted); font-size: 13px; }
.help { color: var(--muted); font-size: 13px; padding-left: 18px; margin: 14px 0 18px; }
.help li + li { margin-top: 4px; }
form.inline { display: inline; }
.assign-table select { width: 100%; max-width: 320px; }
.assign-table td:first-child { width: 40%; }

.entry td { padding-top: 6px; padding-bottom: 6px; }
.entry input[type="date"] { min-width: 9.5em; }
.calc-ch, .calc-net { min-width: 3em; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 7px 16px; border-radius: 7px;
  border: 1px solid var(--brand); background: var(--brand); color: var(--brand-ink);
  font-weight: 600; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { filter: brightness(1.12); }
.btn-small { min-height: 30px; padding: 4px 12px; font-size: 13px; }
.btn-quiet { background: transparent; color: var(--ink); border-color: var(--line-strong); }
.btn-quiet:hover { background: var(--brand-soft); filter: none; }
.btn-danger { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn-danger:hover { background: var(--danger-soft); filter: none; }
.btn[disabled] { opacity: .4; cursor: not-allowed; }

/* ---------- admin ---------- */
.admin-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 20px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.subnav { display: flex; gap: 4px; flex-wrap: wrap; }
.subnav a { text-decoration: none; padding: 6px 12px; border-radius: 7px; color: var(--muted); font-weight: 600; }
.subnav a:hover { color: var(--ink); background: var(--surface); }
.subnav a[aria-current="page"] { color: var(--ink); background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); }
.signed-in { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.callout { margin: 16px 0 0; padding: 10px 14px; border-radius: var(--radius); background: var(--gold-soft); font-size: 14px; }
.login { max-width: 340px; margin: 64px auto; display: flex; flex-direction: column; gap: 14px; }
.login h1 { margin: 0; }

/* ---------- flash messages ---------- */
.flashes { margin-top: 20px; display: grid; gap: 6px; }
.flash { margin: 0; padding: 10px 14px; border-radius: var(--radius); font-weight: 500; }
.flash-ok { background: var(--brand-soft); }
.flash-error { background: var(--danger-soft); color: var(--danger); }

/* ---------- phones ---------- */
@media (max-width: 700px) {
  body { font-size: 15px; }
  .wrap { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
  main.wrap { padding-bottom: calc(88px + env(safe-area-inset-bottom)); }

  /* compact top bar: short name, season, admin gear */
  .header-inner { min-height: 52px; gap: 10px; }
  .brand { font-size: 17px; }
  .brand-full, .top-nav, .admin-label { display: none; }
  .brand-short { display: inline; }
  .header-tools { margin-left: auto; gap: 4px; }
  .admin-link { padding: 8px; }
  .admin-link svg { width: 20px; height: 20px; }

  /* bottom tab bar */
  .tabbar {
    display: grid; grid-template-columns: repeat(3, 1fr);
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    -webkit-backdrop-filter: saturate(1.6) blur(14px); backdrop-filter: saturate(1.6) blur(14px);
    border-top: 1px solid var(--line);
  }
  .tabbar a {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    min-height: 56px; padding: 6px 0 4px; font-size: 11px; font-weight: 600; letter-spacing: .01em;
    color: var(--muted); text-decoration: none; -webkit-tap-highlight-color: transparent;
  }
  .tabbar a[aria-current="page"] { color: var(--accent); }
  .tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

  /* swap wide columns for the muted line under each name */
  .hide-sm { display: none; }
  div.show-sm { display: block; }
  span.show-sm { display: inline; }
  th.show-sm, td.show-sm { display: table-cell; }

  /* headings and pickers */
  .page-head { margin: 18px 0 12px; gap: 10px; }
  .page-head > div:first-child { width: 100%; }
  h1 { font-size: 25px; }
  h2 { font-size: 17px; margin: 28px 0 10px; }
  .page-head .picker { width: 100%; }
  .page-head .picker select { flex: 1; }

  /* no zoom-on-focus on iPhones: inputs need 16px text */
  input:not([type="checkbox"]), select { font-size: 16px; min-height: 42px; }
  .btn { min-height: 42px; }
  .btn-small { min-height: 34px; }

  /* tables */
  th, td { padding: 10px 8px; }
  th:first-child, td:first-child { padding-left: 12px; }
  th:last-child, td:last-child { padding-right: 12px; }
  .pos { width: 2.6em; }
  .big { font-size: 17px; }
  .week-block { margin-top: 22px; }
  .week-head { gap: 6px 8px; }
  .week-head h2 { font-size: 17px; }
  .player-rounds th, .player-rounds td { padding: 10px 8px; }
  .player-rounds th:first-child, .player-rounds td:first-child { padding-left: 12px; }
  a.one-line { max-width: 170px; }

  /* player page */
  .stat-row { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat { padding: 10px 12px; }
  .stat-value { font-size: 22px; }
  .chart-card { padding: 12px 12px 4px; }

  /* admin */
  .subnav { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .subnav a { white-space: nowrap; }
  .card { padding: 14px; }
  .form-row > label:not(.grow) { flex: 1 1 40%; }
  .form-row input, .form-row select { width: 100%; }

  /* score entry: one card per player instead of a wide table */
  table.entry thead { display: none; }
  table.entry, table.entry tbody { display: block; }
  table.entry tr { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px 12px; padding: 14px 12px; border-top: 1px solid var(--line); }
  table.entry tr:first-child { border-top: 0; }
  table.entry tr:hover td { background: none; }
  table.entry td { display: block; padding: 0; border: 0; text-align: left; }
  table.entry td[data-label]::before { content: attr(data-label); display: block; margin-bottom: 4px; font-size: 12px; font-weight: 600; color: var(--muted); }
  /* row 1: name + live course handicap / net preview; row 2: gross, adj; row 3: HI, date */
  table.entry td.entry-name { grid-area: 1 / 1 / 2 / 3; align-self: center; font-size: 16px; }
  table.entry td.calc-ch { grid-area: 1 / 3; }
  table.entry td.calc-net { grid-area: 1 / 4; }
  table.entry td.entry-gross { grid-area: 2 / 1 / 3 / 3; }
  table.entry td.entry-adj { grid-area: 2 / 3 / 3 / 5; }
  table.entry td.entry-hi { grid-area: 3 / 1 / 4 / 3; }
  table.entry td.entry-date { grid-area: 3 / 3 / 4 / 5; }
  table.entry tr:not(:has(.calc-ch)) td.entry-name { grid-column: 1 / -1; }  /* establishment week: no preview */
  table.entry tr:not(:has(.entry-hi)) td.entry-date { grid-column: 1 / 3; }
  table.entry .in-num, table.entry input[type="date"] { width: 100%; min-width: 0; text-align: left; }
}
