/* Golf Stats - dark, dense, fast. */
:root {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #222221;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;
  --accent-ink: #9cc4f5;
  --birdie: #199e70;
  --eagle: #c98500;
  --danger: #e66767;
  --radius: 8px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--page); color: var(--ink); font: 14px/1.4 var(--font); }
body { min-height: 100vh; padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left); }
a { color: var(--accent-ink); }
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }

/* ---- gate ---- */
#gate { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.gate-card { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 28px; text-align: center; }
.gate-card h1 { margin: 0 0 4px; font-size: 22px; letter-spacing: 0.02em; }
.gate-card p { color: var(--ink-2); margin: 0 0 18px; }
.err { color: var(--danger); font-size: 13px; margin-top: 12px; }

/* ---- shell ---- */
header.top { position: sticky; top: 0; z-index: 5; background: rgba(13, 13, 13, 0.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }
.top-row { display: flex; align-items: center; gap: 12px; padding: 10px 16px; max-width: 1200px; margin: 0 auto; }
.brand { font-weight: 700; font-size: 16px; letter-spacing: 0.02em; white-space: nowrap; display: flex; align-items: center; gap: 8px; }
.brand i { width: 10px; height: 10px; border-radius: 50%; background: var(--birdie); display: inline-block; }
nav.tabs { display: flex; gap: 2px; margin-left: 8px; }
nav.tabs a { color: var(--ink-2); text-decoration: none; padding: 6px 12px; border-radius: 6px; white-space: nowrap; }
nav.tabs a.on { background: var(--surface-2); color: var(--ink); }
nav.tabs a:hover { color: var(--ink); }
.spacer { flex: 1; }
.who { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; }
main { max-width: 1200px; margin: 0 auto; padding: 16px; display: grid; gap: 14px; }
footer.stamp { color: var(--muted); font-size: 11px; text-align: center; padding: 18px 16px 28px; }

/* ---- buttons ---- */
.btn { background: var(--surface-2); border: 1px solid var(--border); color: var(--ink); border-radius: 6px; padding: 6px 12px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: rgba(255, 255, 255, 0.25); }
.btn.primary { background: var(--accent); border-color: transparent; color: #fff; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 4px 9px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.ghost:hover { color: var(--ink); background: var(--surface-2); }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.seg button { background: transparent; border: 0; padding: 4px 10px; color: var(--ink-2); cursor: pointer; font-size: 13px; }
.seg button.on { background: var(--surface-2); color: var(--ink); }

/* ---- cards / tiles ---- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; min-width: 0; }
.card > header { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.card > header h2 { margin: 0; font-size: 15px; font-weight: 600; }
.card > header .count { color: var(--muted); font-weight: 400; margin-left: 6px; }
.card > header .note { color: var(--muted); font-size: 12px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.tile .lbl { color: var(--muted); font-size: 12px; }
.tile .val { font-size: 26px; font-weight: 600; line-height: 1.15; margin-top: 2px; }
.tile.hero .val { font-size: 40px; }
.tile .sub { color: var(--ink-2); font-size: 12px; margin-top: 2px; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--ink-2); }
.lg { display: inline-flex; align-items: center; gap: 6px; }
.lg i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

/* ---- charts ---- */
.chart-root { position: relative; width: 100%; }
.chart-root svg { display: block; width: 100%; height: auto; }
.chart-root text { font-family: var(--font); }
.tip { position: absolute; pointer-events: none; background: #262624; border: 1px solid rgba(255, 255, 255, 0.14); border-radius: 6px; padding: 7px 10px; font-size: 12px; color: var(--ink-2); box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4); white-space: nowrap; z-index: 3; }
.tip b { color: var(--ink); font-weight: 600; }
.tip .row { display: flex; justify-content: space-between; gap: 14px; }
.tip .row i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 6px; }

/* ---- tables ---- */
.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--grid); white-space: nowrap; vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: 12px; position: sticky; top: 0; background: var(--surface); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.wrap { white-space: normal; min-width: 220px; max-width: 520px; color: var(--ink-2); }
td.dim { color: var(--muted); }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--surface-2); }
tr.total td { font-weight: 600; border-top: 1px solid var(--axis); color: var(--ink); }
.pivot td, .pivot th { text-align: right; font-variant-numeric: tabular-nums; }
.pivot td:first-child, .pivot th:first-child { text-align: left; }
.pivot tbody tr { cursor: default; }
.pivot tbody tr:hover { background: transparent; }
sup.m { color: var(--muted); font-size: 9px; margin-left: 2px; }
.tag { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 4px; background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--border); }
.tag.flag { color: var(--eagle); }

/* ---- birdie grid ---- */
.holes { display: grid; grid-template-columns: repeat(9, 1fr); gap: 6px; }
.hole { background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; min-height: 64px; padding: 6px 8px; cursor: pointer; position: relative; overflow: hidden; }
.hole:hover { border-color: rgba(255, 255, 255, 0.3); }
.hole .n { color: var(--muted); font-size: 12px; font-weight: 600; }
.hole.bird { background: rgba(25, 158, 112, 0.16); border-color: rgba(25, 158, 112, 0.55); }
.hole.bird .n { color: var(--ink); }
.hole .d { font-size: 12px; color: var(--ink-2); margin-top: 4px; }
.hole .t { font-size: 11px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hole.bird::after { content: ""; position: absolute; top: 6px; right: 6px; width: 7px; height: 7px; border-radius: 50%; background: var(--birdie); }
.hole.multi::after { display: none; }
.hole .x { position: absolute; top: 4px; right: 5px; font-size: 11px; font-weight: 700; color: var(--birdie); }
.pad { padding: 0 16px 14px; margin: 0; }
details.past { margin: 14px 0; }
details.past > summary { cursor: pointer; color: var(--ink-2); font-size: 14px; font-weight: 600; padding: 6px 0; list-style: none; }
details.past > summary::before { content: "▸ "; color: var(--muted); }
details.past[open] > summary::before { content: "▾ "; }
details.past > summary::-webkit-details-marker { display: none; }
details.past .card { margin-top: 10px; }
.choices { display: grid; gap: 6px; }
.choice { display: flex; gap: 10px; align-items: baseline; text-align: left; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; color: var(--ink); cursor: pointer; font: inherit; }
.choice:hover { border-color: rgba(255, 255, 255, 0.3); }
.choice .d { color: var(--ink-2); font-size: 13px; white-space: nowrap; }
.choice .t { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
@media (max-width: 640px) {
  .holes { grid-template-columns: repeat(6, 1fr); }
  .hole { min-height: 54px; padding: 5px 6px; }
  .hole .t { display: none; }
}

/* ---- dialog ---- */
dialog { background: var(--surface); color: var(--ink); border: 1px solid var(--border); border-radius: 12px; padding: 0; width: min(440px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog form { padding: 18px 20px 16px; display: grid; gap: 12px; }
dialog h3 { margin: 0; font-size: 16px; }
.field { display: grid; gap: 4px; }
.field label { color: var(--muted); font-size: 12px; }
.field input, .field select, .field textarea { background: var(--page); border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; width: 100%; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--accent); }
.field textarea { min-height: 70px; resize: vertical; }
.field .help { color: var(--muted); font-size: 11px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.actions { display: flex; gap: 8px; justify-content: flex-end; align-items: center; margin-top: 4px; }
.actions .btn.danger { margin-right: auto; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #262624; border: 1px solid var(--border); padding: 8px 14px; border-radius: 8px; font-size: 13px; z-index: 20; }
.toast.err { border-color: var(--danger); color: var(--danger); }

@media (max-width: 720px) {
  .top-row { flex-wrap: wrap; padding: 8px 12px; }
  nav.tabs { order: 3; width: 100%; margin-left: 0; overflow-x: auto; }
  .who { display: none; }
  main { padding: 10px; gap: 10px; }
  .card { padding: 12px; }
}
