/* Palette and type taken from PGA TOUR's stats pages: white ground, near-black
   navy text, TOUR navy for interaction, and green reserved for a number that is
   good news. The top bar stays near-black in both themes, as it is there. */
:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f2f2f2;
  --border: #e2e8f0;
  --rule: #1a202c;              /* the heavy line under a table header */
  --text: #1a202c;
  --text-dim: #757575;
  --accent: #003a70;            /* TOUR navy */
  --accent-soft: #eaf0f7;
  --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5l5-5' fill='none' stroke='%23003a70' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  --good: #468254;
  --bad: #b23b2e;
  --warn: #b7791f;
  --bar: #0f1519;               /* top navigation */
  --bar-text: #ffffff;
  --bar-dim: #c7c7c7;
  --radius: 4px;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}
[data-theme="dark"] {
  --bg: #0f1519;
  --surface: #171e24;
  --surface-2: #1f2830;
  --border: #2b3640;
  --rule: #7c8b99;
  --text: #edf1f5;
  --text-dim: #94a3af;
  --accent: #5b9bd9;
  --accent-soft: #16283a;
  --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5l5-5' fill='none' stroke='%235b9bd9' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  --good: #6fbf83;
  --bad: #e0705f;
  --warn: #d9a441;
  --bar: #080c0f;
  --bar-text: #ffffff;
  --bar-dim: #9aa7b2;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

/* ---------------------------------------------------------------- layout -- */
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 18px; background: var(--bar);
  border-bottom: 0;
  position: sticky; top: 0; z-index: 20;
  padding-top: max(10px, env(safe-area-inset-top));
}
.brand { font-weight: 700; letter-spacing: -.2px; color: var(--bar-text);
          font-size: 19px; }
.spacer { flex: 1; }
#nav { display: flex; gap: 2px; flex-wrap: wrap; }
#nav button {
  background: none; border: 0; color: var(--bar-dim); font: inherit;
  padding: 8px 12px; border-radius: 0; cursor: pointer; white-space: nowrap;
  font-size: 14px; border-bottom: 3px solid transparent;
}
#nav button:hover { color: var(--bar-text); }
/* The active tab is marked with a rule beneath it, as on the TOUR nav. */
#nav button.active { color: var(--bar-text); font-weight: 600;
                     border-bottom-color: var(--bar-text); }
.icon-btn {
  background: none; border: 1px solid rgba(255,255,255,.35); color: var(--bar-text);
  width: 32px; height: 32px; border-radius: 8px; cursor: pointer; font-size: 15px;
}
main { padding: 22px 18px 80px; max-width: 1180px; margin: 0 auto; }
.loading { color: var(--text-dim); padding: 40px; text-align: center; }

h1 { font-size: 38px; line-height: 1.1; font-weight: 600; letter-spacing: -.8px;
     margin: 4px 0 6px; }
h2 { font-size: 19px; font-weight: 600; letter-spacing: -.2px; margin: 26px 0 10px; }
h3 { font-size: 14px; margin: 18px 0 8px; text-transform: uppercase;
     letter-spacing: .06em; color: var(--text-dim); }
p.sub { color: var(--text-dim); margin: 0 0 18px; }
a { color: var(--accent); }

/* ----------------------------------------------------------------- cards -- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 20px; margin-bottom: 16px;
}
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.grid { display: grid; gap: 14px; }
.cols-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.cols-3 { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }

.tiles { display: grid; gap: 10px;
         grid-template-columns: repeat(auto-fit, minmax(132px, 1fr)); }
.tile {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px; min-width: 110px;
}
.tile .k { font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
           color: var(--text-dim); }
.tile .v { font-size: 28px; font-weight: 600; letter-spacing: -.5px; font-variant-numeric: tabular-nums;
           margin-top: 2px; }
.tile .d { font-size: 12px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.tile .v.good { color: var(--good); } .tile .v.bad { color: var(--bad); }

/* ---------------------------------------------------------------- tables -- */
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: right; padding: 11px 10px; border-bottom: 1px solid var(--border); }
th:first-child, td:first-child { text-align: left; }
/* Tiny bold uppercase headers over a heavy rule — the TOUR table signature. */
th { font-size: 11px; text-transform: uppercase; letter-spacing: .055em;
     color: var(--text-dim); font-weight: 700; padding: 6px 10px;
     border-bottom: 2px solid var(--rule); }
tbody tr:hover { background: var(--surface-2); }
td.good { color: var(--good); } td.bad { color: var(--bad); }
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ---------------------------------------------------------------- inputs -- */
label { display: block; font-size: 11px; text-transform: uppercase;
        letter-spacing: .05em; color: var(--text-dim); margin-bottom: 3px; }
input, select, textarea, button.btn {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 11px;
  width: 100%; min-height: 38px;
}
/* Filter controls read as pills there, so the round ones stay round. */
select, .rail-search { border-radius: 999px; padding-left: 14px; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent); outline-offset: -1px;
}

/* A bare <select> looked like static text: same fill as the card and an arrow
   too faint to notice. Give it its own fill and an accent chevron. */
select {
  appearance: none; -webkit-appearance: none;
  background-color: var(--surface-2);
  background-image: var(--chevron);
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
  cursor: pointer;
  border-color: var(--border);
}
select:hover { border-color: var(--accent); }
.field { margin-bottom: 12px; }
.row { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
button.btn {
  cursor: pointer; background: var(--surface-2); font-weight: 600; width: auto;
  padding: 8px 16px;
}
button.btn:hover { border-color: var(--accent); color: var(--accent); }
button.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.btn.primary:hover { filter: brightness(1.08); color: #fff; }
button.btn.danger:hover { border-color: var(--bad); color: var(--bad); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Segmented choice buttons — big touch targets, works on phone later. */
.seg { display: flex; flex-wrap: wrap; gap: 5px; }
.seg button {
  font: inherit; cursor: pointer; padding: 7px 12px; min-height: 38px;
  border: 1px solid var(--border); background: var(--surface);
  border-radius: 8px; color: var(--text-dim); flex: 1 1 auto;
}
.seg button.on { background: var(--accent); border-color: var(--accent);
                 color: #fff; font-weight: 600; }
.seg.small button { padding: 5px 9px; min-height: 32px; font-size: 13px; }

/* -------------------------------------------------------------- entry ui -- */
.hole-nav { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 14px; }
.hole-nav button {
  width: 38px; height: 38px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-dim); cursor: pointer; font: inherit;
  font-variant-numeric: tabular-nums;
}
.hole-nav button.done { border-color: var(--accent); color: var(--accent); }
.hole-nav button.on { background: var(--accent); color: #fff; border-color: var(--accent);
                      font-weight: 700; }
.hole-head { display: flex; align-items: baseline; gap: 14px; margin-bottom: 12px; }
.hole-head .num { font-size: 30px; font-weight: 700; }
.hole-head .meta { color: var(--text-dim); }
details.layer { border-top: 1px solid var(--border); padding-top: 10px; margin-top: 12px; }
details.layer > summary {
  cursor: pointer; font-size: 14px; letter-spacing: .01em;
  color: var(--text); font-weight: 650; list-style: none;
  margin-bottom: 10px; padding: 8px 10px; border-radius: 8px;
  background: var(--surface-2); border: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
}
details.layer > summary:hover { border-color: var(--accent); }
details.layer > summary::-webkit-details-marker { display: none; }
details.layer > summary::before {
  content: "›"; color: var(--accent); font-weight: 800; font-size: 16px;
  line-height: 1; transform: rotate(90deg); transition: transform .12s ease;
}
details.layer[open] > summary::before { transform: rotate(-90deg); }
.layer-title { flex: 1; }
/* Says whether a collapsed section holds anything, so nothing is missed. */
.layer-flag {
  font-size: 10px; text-transform: uppercase; letter-spacing: .06em;
  font-weight: 700; padding: 2px 7px; border-radius: 999px;
  color: var(--text-dim); background: var(--bg); border: 1px solid var(--border);
}
details.layer.filled > summary > .layer-flag {
  color: var(--accent); border-color: var(--accent); background: var(--accent-soft);
}

.grid-entry { font-size: 13px; }
.grid-entry input, .grid-entry select { padding: 4px 5px; min-height: 30px; font-size: 13px; }
.grid-entry td, .grid-entry th { padding: 3px 4px; }
.grid-entry td:first-child { white-space: nowrap; color: var(--text-dim); font-size: 12px; }

/* -------------------------------------------------------------- charts --- */
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .grid-circle { fill: none; stroke: var(--border); stroke-width: 1; }
.chart .zero { stroke: var(--text-dim); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .axis { fill: var(--text-dim); font-size: 11px; font-family: var(--sans); }
.chart .axis.dim { opacity: .7; font-size: 10px; }
.chart .label { fill: var(--text); font-size: 12.5px; font-family: var(--sans); }
.chart .value { fill: var(--text); font-size: 11.5px; font-family: var(--mono); }
.chart .line-main { fill: none; stroke: var(--accent); stroke-width: 2.2;
                    stroke-linejoin: round; }
.chart .line-avg { fill: none; stroke: var(--text-dim); stroke-width: 1.6;
                   stroke-dasharray: 5 4; }
.chart .dot { fill: var(--accent); }
.chart .bar-main { fill: var(--accent); }
.chart .bar-good { fill: var(--good); }
.chart .bar-bad { fill: var(--bad); }
.chart .blob { fill: var(--accent); opacity: .8; }
.chart .blob-label { fill: #fff; font-size: 11px; font-family: var(--mono); }
.chart .target { fill: none; stroke: var(--text-dim); stroke-width: 1.5; }

/* --------------------------------------------------------------- misc ---- */
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px;
        font-size: 11px; background: var(--surface-2); color: var(--text-dim); }
.pill.good { background: var(--accent-soft); color: var(--accent); }
.leak { border-left: 3px solid var(--bad); padding-left: 12px; margin-bottom: 16px; }
.leak.ok { border-left-color: var(--good); }
.leak .h { font-weight: 650; }
.leak .c { font-family: var(--mono); color: var(--bad); }
.leak ul { margin: 6px 0 0; padding-left: 18px; color: var(--text-dim); font-size: 13.5px; }
.cov { display: flex; align-items: center; gap: 8px; margin: 3px 0; font-size: 12px; }
.cov .bar { flex: 1; height: 6px; background: var(--surface-2); border-radius: 3px;
            overflow: hidden; max-width: 160px; }
.cov .bar i { display: block; height: 100%; background: var(--accent); }
.empty { color: var(--text-dim); padding: 30px; text-align: center;
         border: 1px dashed var(--border); border-radius: var(--radius); }
.note { font-size: 12.5px; color: var(--text-dim); }
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--accent); color: #fff; padding: 10px 20px; border-radius: 8px;
  z-index: 60; font-weight: 600; box-shadow: 0 6px 20px rgba(0,0,0,.2);
}
.mono { font-family: var(--mono); }

@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; padding: 8px 12px; }
  #nav { order: 3; width: 100%; overflow-x: auto; }
  main { padding: 16px 12px 90px; }
  .tile .v { font-size: 20px; }
}

input::placeholder { color: var(--text-dim); opacity: .8; font-style: italic; }

/* ------------------------------------------------------------- My Bag --- */
.tabs { display: flex; gap: 0; flex-wrap: wrap; margin: 8px 0 18px;
         border-bottom: 1px solid var(--border); }
.tab {
  font: inherit; cursor: pointer; padding: 9px 2px; margin-right: 18px;
  border: 0; border-bottom: 3px solid transparent; background: none;
  color: var(--text-dim); font-weight: 600; font-size: 14px;
}
.tab:hover { color: var(--text); }
.tab.on { color: var(--text); border-bottom-color: var(--accent); }
.bag-head { display: flex; gap: 20px; align-items: flex-start;
            justify-content: space-between; flex-wrap: wrap; margin-bottom: 8px; }
.bag-head .field { margin-bottom: 0; min-width: 170px; }
/* The middle number is the one you read first, as on a yardage book. */
.carry-mid input { font-size: 17px; font-weight: 700; text-align: center;
                   border-color: var(--accent); }
.actions { display: flex; gap: 8px; margin-top: 14px; }
button.btn.primary { background: var(--accent); color: #fff;
                     border-color: var(--accent); font-weight: 600;
                     border-radius: 999px; padding-left: 18px; padding-right: 18px; }
button.btn.danger { color: var(--bad); border-color: var(--border);
                    border-radius: 999px; padding-left: 16px; padding-right: 16px; }
button.btn.danger:hover { border-color: var(--bad); }

/* ----------------------------------------------- courses master/detail --- */
.split { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 16px;
         align-items: start; }
@media (max-width: 860px) { .split { grid-template-columns: 1fr; } }

.rail { position: sticky; top: 12px; background: var(--surface);
        border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; }
@media (max-width: 860px) { .rail { position: static; } }
.rail-search { width: 100%; margin-bottom: 8px; }
.rail-list { display: flex; flex-direction: column; gap: 2px;
             max-height: 60vh; overflow-y: auto; }
/* Stacked on a phone the list sits above the detail, so keep it short enough
   that the selected course is not buried under a full screen of names. */
@media (max-width: 860px) { .rail-list { max-height: 34vh; } }
.rail-item {
  font: inherit; text-align: left; cursor: pointer; width: 100%;
  background: none; border: 1px solid transparent; border-radius: 8px;
  padding: 8px 10px; color: var(--text); display: flex; flex-direction: column; gap: 2px;
}
.rail-item:hover { background: var(--surface-2); }
.rail-item.on { background: var(--accent-soft); border-color: var(--accent); }
.rail-name { font-weight: 650; font-size: 14px; }
.rail-meta { font-size: 12px; color: var(--text-dim);
             display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.pill.small { font-size: 11px; padding: 1px 6px; }

.detail { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.detail-head { display: flex; justify-content: space-between; gap: 16px;
               align-items: flex-start; flex-wrap: wrap; }
.detail-head h2 { margin: 0; }
.tiles { display: flex; flex-wrap: wrap; gap: 10px; }

/* ------------------------------------------------- scorecard score marks --- */
/* The ring goes around the number, as on a paper card. The double ring is a
   second shadow with a gap of page colour between, so it works at any size. */
.score {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 21px; height: 21px; padding: 0 2px;
  font-variant-numeric: tabular-nums; line-height: 1;
}
.score.birdie, .score.eagle { border: 1.5px solid currentColor; border-radius: 50%; }
.score.bogey, .score.double { border: 1.5px solid currentColor; border-radius: 1px; }
.score.eagle { box-shadow: 0 0 0 2px var(--surface), 0 0 0 3.5px currentColor; }
.score.double { box-shadow: 0 0 0 2px var(--surface), 0 0 0 3.5px currentColor; }
/* Room for the outer ring so it is not clipped by the cell. */
.grid-entry td { padding: 3px 4px; }
.grid-entry tr:has(.score) td { padding-top: 6px; padding-bottom: 6px; }

/* ------------------------------------------------ on-course entry sizing --- */
/* Entry happens standing on a tee box, often one-handed. Targets are sized for
   a thumb rather than a cursor, and the hole heading carries the running score
   so there is no need to leave the hole to see where you stand. */
.hole-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap;
             margin-bottom: 14px; }
.hole-head .thru { margin-left: auto; font-size: 13px; color: var(--text-dim);
                   font-variant-numeric: tabular-nums; }
.hole-card .seg button { min-height: 44px; padding: 0 14px; font-size: 15px; }
.hole-card .seg.small button { min-height: 40px; }
.hole-card input, .hole-card select { min-height: 44px; font-size: 15px; }
.hole-card .layer > summary { padding: 10px 2px; }

/* ------------------------------------------------------- yardage book --- */
/* Read at arm's length, mid-round, by a player or a caddie: tight rows, one
   number per cell, the carry number carrying the most weight. */
.elev { padding: 12px 14px; }
.elev-row { display: flex; gap: 14px; flex-wrap: wrap; align-items: flex-end; }
.elev-row .field { margin-bottom: 0; }
.elev-summary { display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
                margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border);
                font-size: 13px; }
.y-big { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }
.y-home { font-size: 11px; color: var(--text-dim); margin-left: 5px;
          font-variant-numeric: tabular-nums; }
.y-home::before { content: '('; }
.y-home::after { content: ')'; }

/* Compact reference tables: this page is read at arm's length mid-round. */
.card.tight { padding: 10px 12px; margin-bottom: 12px; }
.card.tight h3 { margin: 0; font-size: 14px; }
.card.tight table { font-size: 13px; width: auto; }
.card.tight td, .card.tight th { padding: 2px 16px 2px 0; text-align: right;
                                 white-space: nowrap; }
.card.tight td:first-child, .card.tight th:first-child { text-align: left;
                                                         padding-right: 22px; }
.card.tight input { min-height: 30px; padding: 2px 6px; font-size: 13px;
                    text-align: center; }
.card.tight .bag-head { align-items: center; margin-bottom: 6px; gap: 10px; }
.card.tight .bag-head .field { margin: 0; }
.card.tight .bag-head input { min-height: 28px; }
.club-cell { display: flex; align-items: baseline; gap: 6px; white-space: nowrap; }
.club-cell strong { min-width: 24px; }
.club-cell .note { font-size: 11px; }
.elev-row { display: flex; gap: 7px; align-items: center; flex-wrap: wrap; }
.elev-lab { font-size: 11px; color: var(--text-dim); text-transform: uppercase;
            letter-spacing: .04em; }
.elev-out { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.elev-out strong { font-size: 15px; font-variant-numeric: tabular-nums; }
button.btn.tiny { padding: 2px 8px; font-size: 11px; min-height: 0; }
.card.tight .carry-mid input { font-size: 15px; }

/* Carry table and wedge matrix sit side by side where there is room. The wedge
   matrix is only a few rows, so stacking wasted a screen. */
.bag-split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
             gap: 12px; align-items: start; }
@media (max-width: 900px) { .bag-split { grid-template-columns: 1fr; } }
/* The measuring date is secondary to the numbers; keep it out of the way. */
.card.tight .bag-head { justify-content: space-between; }
.card.tight .bag-head .field label { font-size: 10px; }
.card.tight .bag-head input[type="date"] { width: 120px; font-size: 11px;
                                           min-height: 24px; padding: 1px 4px; }

/* Gap between a club and the next one down — the number a fitter reads first. */
.gap { color: var(--text-dim); font-variant-numeric: tabular-nums; font-size: 12px; }

/* Approach map: the hole from above, shaded by scoring from each distance. */
.stack { display: flex; flex-direction: column; gap: 12px; }
.approach-map { margin-top: 4px; }
.approach-map .map-val { fill: var(--text); font-size: 13px; font-weight: 700;
                         font-family: var(--sans); font-variant-numeric: tabular-nums; }
.approach-map .map-clubs { fill: var(--accent); font-weight: 650; font-size: 10px; }

/* ------------------------------------------------------- workshop bar --- */
/* Shown only on the copy served from this machine. Amber, matching its icon,
   so the copy you are looking at is never in doubt. */
.ws-bar {
  position: sticky; top: 0; z-index: 60;
  display: flex; align-items: center; gap: 10px;
  padding: 6px 14px; font-size: 12px;
  background: #d9a441; color: #2a1d05;
  border-bottom: 1px solid rgba(0, 0, 0, .18);
}
.ws-dot { width: 8px; height: 8px; border-radius: 50%; background: #2a1d05; opacity: .55; }
.ws-status { opacity: .75; }
.ws-publish {
  margin-left: auto; font: inherit; font-weight: 650; cursor: pointer;
  padding: 4px 12px; border-radius: 6px;
  border: 1px solid rgba(0, 0, 0, .35); background: rgba(255, 255, 255, .75);
  color: #2a1d05;
}
.ws-publish:hover:not(:disabled) { background: #fff; }
.ws-publish:disabled { opacity: .6; cursor: default; }
