:root {
  --bg: #0f1720;
  --panel: #16212e;
  --line: #24313f;
  --text: #e6edf3;
  --muted: #93a1b0;
  --accent: #3fb950;
  --accent-2: #58a6ff;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
}

header {
  padding: 1.5rem 2rem 0.5rem;
}

header h1 { margin: 0; }

.muted { color: var(--muted); }

main { padding: 1rem 2rem 3rem; }

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  margin-bottom: 1rem;
}

.controls form { display: flex; gap: 0.5rem; flex-wrap: wrap; }

input, select, button {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  font-size: 0.95rem;
}

button {
  cursor: pointer;
  border-color: var(--accent);
}
button:hover { background: var(--accent); color: #04160a; }

.rounds { width: 100%; }

/* ---- Scorecard modal ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 2rem;
}
.modal-overlay[hidden] { display: none; }
.modal-dialog {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  padding: 1.25rem 1.5rem;
  /* Wide enough for a full 18-hole card (22 columns) to fit without scroll. */
  max-width: min(1200px, 96vw);
  max-height: 90vh;
  overflow: auto;
}
.modal-close {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  padding: 0.2rem 0.5rem;
  font-size: 1rem;
  line-height: 1;
  border-color: var(--line);
}
.modal-close:hover { background: #b03636; color: #fff; border-color: #b03636; }

table {
  width: 100%;
  /* separate (not collapse) + no overflow clipping so position: sticky works
     on the header cells; collapsed borders and overflow:hidden both break it. */
  border-collapse: separate;
  border-spacing: 0;
  background: var(--panel);
  border-radius: 8px;
}

th, td {
  padding: 0.5rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--line);
  font-size: 0.9rem;
}

th { color: var(--muted); font-weight: 600; }

tbody tr.round-row { cursor: pointer; }
tbody tr.round-row:hover { background: #1d2a38; }
tr.selected { background: #23384a !important; }

.detail, .stat-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1rem 1.25rem;
}

/* ---- Scorecard (pivot: holes as columns, stats as rows) ---- */
/* overflow-x kept as a safety net on very narrow screens, but the compact
   sizing below lets a full 18-hole card fit in the modal without scrolling. */
.scorecard-scroll { overflow-x: auto; margin-top: 0.5rem; }
.scorecard {
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.8rem;
  width: 100%;
  table-layout: fixed;
}
.scorecard th, .scorecard td {
  text-align: center;
  padding: 0.28rem 0.15rem;
  white-space: nowrap;
  border-bottom: 1px solid var(--line);
}
.scorecard th { color: var(--muted); font-weight: 600; }
/* Sticky row-label column so stat names stay visible when scrolling wide. */
.scorecard .rowlabel {
  position: sticky;
  left: 0;
  background: var(--panel);
  text-align: left;
  color: var(--muted);
  z-index: 2;
  font-weight: 600;
  width: 6.5rem;
  padding-left: 0.25rem;
  padding-right: 0.5rem;
}
.scorecard .agg { font-weight: 700; color: var(--text); background: #131e2a; }
.scorecard tr.scoring td { padding: 0.22rem 0.1rem; }

/* Colored score chips (score vs par). Tuned to sit against the blue theme. */
.score {
  display: inline-block;
  min-width: 1.5em;
  padding: 0.12rem 0.2rem;
  border-radius: 5px;
  font-weight: 700;
  color: #04121f;
}
.sc-eagle  { background: #e3b341; }  /* eagle or better - yellow */
.sc-birdie { background: #e5534b; color: #fff; }  /* birdie - red */
.sc-par    { background: #4c8fd6; color: #fff; }  /* par - blue */
.sc-bogey  { background: #3fb950; }  /* bogey - green */
.sc-double { background: #8b98a5; }  /* double bogey or worse - gray */

/* Fairway / GIR icons */
.ic { font-size: 1rem; line-height: 1; }
.ic-hit { color: var(--accent); }         /* filled = hit (green) */
.ic-miss { color: #e5534b; }              /* missed fairway (red) */
.ic-miss-ring { color: var(--muted); }    /* missed green (muted ring) */

/* Legend */
.scorecard-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 0.75rem;
  font-size: 0.8rem;
  color: var(--muted);
}
.legend-key { display: inline-flex; align-items: center; gap: 0.35rem; }
.legend-key .swatch { width: 0.9rem; height: 0.9rem; border-radius: 3px; display: inline-block; }

.empty { color: var(--muted); text-align: center; font-style: italic; }

.hardest-result { margin: 0.5rem 0 1rem; }
.stat-card .big { font-size: 1.6rem; color: var(--accent-2); margin: 0.25rem 0; }

/* ---- Sticky header area (title + hardest-hole form on one row) ---- */
.sticky-top {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  flex-wrap: wrap;
  padding: 0.75rem 2rem;
}
.topbar .title h1 { margin: 0; }
.topbar .title p { margin: 0.15rem 0 0; }
.topbar .hardest { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.topbar .tools { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
.toggle-group { display: flex; gap: 0.5rem; }

/* Birdie/Eagle toggle buttons: outline by default, filled when active. */
.toggle {
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
}
.toggle:hover { border-color: var(--accent-2); background: #1d2a38; color: var(--text); }
.toggle.active, .toggle.active:hover {
  background: var(--accent-2);
  border-color: var(--accent-2);
  color: #04121f;
  font-weight: 600;
}

/* ---- Sticky table column headings ----
   They stick BELOW the sticky-top block. --thead-top is set from JS to the
   measured height of that block so the headers never slide underneath it. */
/* Scoped to the rounds table so it does NOT affect the scorecard modal. */
.rounds thead th {
  position: sticky;
  top: var(--thead-top, 0px);
  background: #111c27;
  z-index: 20;
}

/* ---- Sortable headers ---- */
th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { color: var(--text); }
th .arrow { font-size: 0.75rem; color: var(--accent-2); margin-left: 0.15rem; }
th.sort-asc .arrow::after { content: "▲"; }
th.sort-desc .arrow::after { content: "▼"; }

/* ---- Course filter dropdown (Excel-style) ---- */
th .filter-toggle {
  padding: 0 0.3rem;
  margin-left: 0.25rem;
  font-size: 0.7rem;
  line-height: 1.2;
  border-radius: 4px;
}
th.filtered .filter-toggle { background: var(--accent-2); color: #04160a; border-color: var(--accent-2); }

.course-filter {
  position: absolute;
  margin-top: 0.35rem;
  left: 0.5rem;
  width: 320px;
  max-width: 90vw;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  padding: 0.6rem;
  z-index: 40;
  font-weight: 400;
  color: var(--text);
}
.course-filter[hidden] { display: none; }
.course-filter-head { display: flex; gap: 0.5rem; margin-bottom: 0.5rem; }
.course-search { flex: 1; }
.course-filter-actions { display: flex; gap: 0.35rem; }
.course-filter-actions button, .course-filter-footer button { padding: 0.35rem 0.6rem; font-size: 0.85rem; }
.course-options { max-height: 320px; overflow-y: auto; display: flex; flex-direction: column; gap: 0.1rem; }
.course-option {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.25rem 0.35rem; border-radius: 4px; cursor: pointer; font-size: 0.85rem;
}
.course-option:hover { background: #1d2a38; }
.course-option input { width: auto; }
.course-option.hidden { display: none; }
.course-filter-footer { margin-top: 0.5rem; text-align: right; }
