*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --navy:        #1e2756;
  --navy-mid:    #2a3470;
  --navy-light:  #3d4f8a;
  --red:         #e53935;
  --eagle-gold:  #f5c518;
  --bogey-blue:  #1565c0;
  --double-dark: #1a1a2e;
  --page-bg:     #f0f2f8;
  --card-bg:     #ffffff;
  --border:      #dde1ef;
  --text:        #1a1a2e;
  --muted:       #6b7280;
  --par-bg:      #eef0f8;
  --rnd-bg:      #f7f8fd;
  --hh:          52px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--page-bg);
  color: var(--text);
  min-height: 100dvh;
}

/* ── App header ─────────────────────────────────────────── */
.app-header {
  background: var(--navy);
  color: #fff;
  height: var(--hh);
  padding: 0 16px;
  display: flex;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 400;
  box-shadow: 0 2px 12px rgba(0,0,0,.35);
}
.app-logo { display: flex; align-items: center; gap: 8px; }
.app-logo svg { width: 22px; height: 22px; flex-shrink: 0; }
.app-title { font-size: 16px; font-weight: 800; letter-spacing: .5px; text-transform: uppercase; }
.app-title em { color: var(--eagle-gold); font-style: normal; }

/* ── Message écran ──────────────────────────────────────── */
.screen-msg {
  text-align: center; padding: 60px 24px;
  font-size: 15px; color: var(--muted);
}

/* ── Main content ───────────────────────────────────────── */
#main-content { padding: 14px; max-width: 1440px; margin: 0 auto; }

/* ── Sticky controls (top-bar + legend-bar) ─────────────── */
.sticky-controls {
  position: sticky;
  top: var(--hh);
  left: 0;
  z-index: 300;
  background: var(--page-bg);
  margin: -14px -14px 0;
  padding: 14px 14px 0;
}

/* ── Top bar (mode | filter | stats on same line) ────────── */
.top-bar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.stats-bar   { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.stats-counts { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.chip {
  background: var(--card-bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 12px; font-size: 12px; color: var(--muted); white-space: nowrap;
}
.chip strong { font-size: 15px; color: var(--navy); display: block; }

/* ── Mode toggle bar ────────────────────────────────────── */
.mode-bar {
  display: flex;
  gap: 3px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  width: fit-content;
}
.mode-btn {
  border: none; border-radius: 7px;
  padding: 7px 16px; font-size: 12px; font-weight: 600;
  cursor: pointer; color: var(--muted); background: transparent;
  transition: all .15s; white-space: nowrap; line-height: 1;
}
.mode-btn:hover { background: var(--par-bg); color: var(--navy); }
.mode-btn.active { background: var(--navy); color: #fff; font-weight: 700; }

/* ── Legend ─────────────────────────────────────────────── */
.legend-bar {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: center; justify-content: center;
  margin-bottom: 10px; font-size: 11px; color: var(--muted);
}
.leg { display: flex; align-items: center; gap: 4px; }

/* ── Table wrapper ──────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--card-bg);
  border-radius: 12px;
  box-shadow: 0 1px 4px rgba(0,0,0,.08), 0 0 0 1px rgba(0,0,0,.04);
}

/* ── Scorecard table ────────────────────────────────────── */
/* border-collapse:separate required for position:sticky inside overflow-x:auto */
.sc {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  min-width: 860px;
  font-size: 12.5px;
}

/* ── Thead ──────────────────────────────────────────────── */
.sc thead th {
  background: var(--navy);
  color: rgba(255,255,255,.82);
  font-weight: 700;
  font-size: 11px;
  text-align: center;
  padding: 7px 3px;
  white-space: nowrap;
  border-right: 1px solid rgba(255,255,255,.1);
  border-bottom: 2px solid var(--navy-mid);
}
/* Corner: sticky left only (sticky+top broken inside overflow-x:auto) */
.sc thead .th-name {
  text-align: left;
  padding-left: 12px;
  min-width: 190px;
  position: sticky;
  left: 0;
  z-index: 10;
  background: var(--navy);
  border-right: 2px solid rgba(255,255,255,.2) !important;
}
.sc thead .th-sep {
  background: var(--navy-mid);
  border-left: 2px solid rgba(255,255,255,.25);
  border-right: 2px solid rgba(255,255,255,.25);
}
.sc thead .th-r { background: var(--navy-mid); border-left: 1px solid rgba(255,255,255,.1); }

/* ── Body cells ─────────────────────────────────────────── */
.sc tbody td {
  text-align: center;
  padding: 5px 2px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.sc tbody td.td-name {
  text-align: left;
  padding: 6px 8px 6px 12px;
  position: sticky;
  left: 0;
  z-index: 5;
  border-right: 2px solid var(--border) !important;
  min-width: 190px;
  max-width: 220px;
}
.td-sep { border-left: 2px solid var(--navy-mid) !important; border-right: 2px solid var(--navy-mid) !important; }
.td-tot { font-weight: 700; font-size: 13px; min-width: 40px; }
.td-r   { border-left: 1px solid var(--border); }

/* ── Ringer / main rows ─────────────────────────────────── */
.ringer-r { cursor: pointer; }
.ringer-r td        { background: var(--card-bg); padding: 7px 2px; border-top: 3px solid var(--border); }
.ringer-r td.td-name { background: var(--card-bg); border-top: 3px solid var(--border); overflow: hidden; }
.ringer-r:hover td         { background: #f4f6ff; }
.ringer-r:hover td.td-name { background: #f4f6ff; }

.n-club    { font-size: 13px; font-weight: 800; color: var(--navy); display: flex; align-items: baseline; justify-content: space-between; gap: 4px; position: relative; z-index: 1; }
.n-terrain { font-size: 11px; color: var(--muted); margin-top: 2px; font-style: italic; position: relative; z-index: 1; }
.n-meta    { font-size: 10px; color: #9ca3af; margin-top: 2px; position: relative; z-index: 1; }
.n-arrow   { font-size: 10px; color: #9ca3af; transition: transform .2s; flex-shrink: 0; }
.ringer-r .n-meta      { display: none; }
.ringer-r.open .n-meta { display: block; }
.n-gauge { position: absolute; top: 0; left: 0; width: 100%; height: 100%; display: flex; z-index: 0; pointer-events: none; }
.n-gs { height: 100%; }
.n-gs-eagle  { background: rgba(245,197,24,.22); }
.n-gs-birdie { background: rgba(229,57,53,.15); }
.n-gs-par    { background: rgba(0,0,0,.03); }
.n-gs-bogey  { background: rgba(21,101,192,.12); }
.n-gs-double { background: rgba(26,26,46,.14); }
.n-gs-triple { background: rgba(107,114,128,.10); }
.n-gs-lbl         { font-weight: 800; font-size: 9px; }
.n-gs-eagle-lbl   { color: #a07800; }
.n-gs-birdie-lbl  { color: var(--red); }
.n-gs-par-lbl     { color: var(--muted); }
.n-gs-bogey-lbl   { color: var(--bogey-blue); }
.n-gs-double-lbl  { color: #374151; }
.n-gs-triple-lbl  { color: #6b7280; }
.ringer-r.open .n-arrow { transform: rotate(180deg); }

/* Diff pill */
.dp { display: inline-block; padding: 2px 7px; border-radius: 5px; font-size: 12px; font-weight: 800; line-height: 1.5; }
.dp-under { background: var(--red);  color: #fff; }
.dp-over  { background: #374151;     color: #fff; }
.dp-even  { background: #9ca3af;     color: #fff; }

.td-tours { font-weight: 700; color: var(--navy-mid); font-size: 13px; }

/* ── Filter bar ─────────────────────────────────────────── */
.filter-bar {
  display: flex; align-items: center; justify-content: center;
  gap: 6px; flex-wrap: wrap; font-size: 12px; color: var(--muted);
}
.filter-bar label { font-weight: 600; color: var(--navy); }
.filter-bar select {
  border: 1px solid var(--border); border-radius: 6px;
  padding: 5px 6px; font-size: 12px; color: var(--text);
  background: var(--card-bg); cursor: pointer; outline: none;
  max-width: 140px;
}
.filter-bar .select-club { max-width: 200px; }
.filter-bar select:focus { border-color: var(--navy-light); }
.filter-sep { color: #9ca3af; font-size: 14px; }

/* ── Sortable headers ───────────────────────────────────── */
.th-sort { cursor: pointer; user-select: none; white-space: nowrap; }
.th-sort:hover { background: var(--navy-light) !important; }
.th-sort.sorted { background: var(--navy-mid) !important; color: #fff; }

/* ── Par rows ───────────────────────────────────────────── */
.par-r { display: none; }
.par-r.vis { display: table-row; }
.par-r td         { background: var(--par-bg); color: var(--muted); font-size: 11.5px; padding: 3px 2px; }
.par-r td.td-name { background: var(--par-bg); font-size: 11px; font-weight: 700; color: var(--muted); }
.par-r .td-tot    { color: var(--text); font-weight: 700; }

/* ── Round rows ─────────────────────────────────────────── */
.rnd-r { display: none; }
.rnd-r.vis { display: table-row; }
.rnd-r td         { background: var(--rnd-bg); color: var(--muted); font-size: 11px; padding: 4px 2px; }
.rnd-r td.td-name { background: var(--rnd-bg); font-size: 10.5px; padding-left: 20px !important; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rnd-r .td-tot    { font-size: 12px; }

/* ── Score badges ───────────────────────────────────────── */
.sb {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; font-size: 12.5px; font-weight: 700; line-height: 1;
}
.sb-eagle  { background: var(--eagle-gold); border-radius: 50%;  color: #1a1a1a; }
.sb-birdie { background: var(--red);         border-radius: 50%;  color: #fff; }
.sb-par    { color: var(--text); }
.sb-bogey  { background: var(--bogey-blue);  border-radius: 3px;  color: #fff; }
.sb-double { background: var(--double-dark); border-radius: 3px;  color: #fff; }
.sb-triple { background: #6b7280;            border-radius: 3px;  color: #fff; }
.sb-none   { color: #d1d5db; }
/* Wider badge for decimals (average mode) */
.sb-avg    { width: auto; min-width: 26px; padding: 0 5px; font-size: 11.5px; }
.rnd-r .sb { width: 22px; height: 22px; font-size: 11px; }

@media (max-width: 700px) {
  .top-bar {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  .filter-bar   { justify-content: center; }
  .mode-bar     { justify-self: center; }
  .stats-bar    { flex-direction: column; align-items: center; gap: 4px; }
  .chip-player  { width: 100%; text-align: center; }
  .stats-counts { flex-wrap: wrap; }
}

@media (max-width: 480px) {
  .app-title { font-size: 13px; }
  #main-content { padding: 10px; }
  .mode-btn { padding: 6px 10px; font-size: 11px; }
  .filter-bar select { font-size: 11px; max-width: 120px; }
  .n-club    { font-size: 11px; }
  .n-terrain { font-size: 10px; }
  .n-meta    { font-size: 9px; }
  .sc thead .th-name { min-width: 150px; }
  .sc tbody td.td-name { min-width: 150px; max-width: 170px; }
}
