:root {
  color-scheme: dark;
  --bg: #0b0f0c;
  --surface: #151c17;
  --surface-2: #1d2620;
  --line: #27342b;
  --text: #f2f5f0;
  --muted: #98a69b;
  --accent: #6fd37a;
  --front: #ffd166;
  --back: #8fd3ff;
  --danger: #ff6b6b;
  --tap: 56px;
  --pad: 16px;
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body {
  font: 17px/1.3 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
  touch-action: manipulation;
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
}
button {
  font: inherit; color: inherit; background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius); min-height: var(--tap); min-width: var(--tap); padding: 0 18px;
  cursor: pointer;
}
button:active { background: var(--line); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
b { font-weight: 700; }
[hidden] { display: none !important; }

#app {
  height: 100dvh; display: flex; flex-direction: column;
  padding-top: env(safe-area-inset-top);
}
.view { flex: 1; display: flex; flex-direction: column; min-height: 0; padding: 0 var(--pad); }
#view-card, #view-course { overflow-y: auto; -webkit-overflow-scrolling: touch; }

/* ---- bottom tabs ---- */
.tabs {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
  padding: 8px var(--pad) calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); background: var(--bg);
}
.tabs button { border-radius: 12px; min-height: 50px; color: var(--muted); background: transparent; border-color: transparent; }
.tabs button.on { color: var(--text); background: var(--surface-2); border-color: var(--line); }

/* ---- hole view ---- */
.holebar { display: flex; align-items: center; gap: 10px; padding: 8px 0 4px; }
.holebar .nav { font-size: 34px; line-height: 1; padding: 0; width: var(--tap); }
.holeinfo { flex: 1; text-align: center; }
.holenum { font-size: 26px; font-weight: 700; letter-spacing: -0.01em; }
.holemeta { color: var(--muted); font-size: 15px; }

.yards { display: grid; grid-template-columns: 1fr 1.6fr 1fr; align-items: end; gap: 6px; padding: 4px 0 0; }
.yd { text-align: center; }
.yd .lbl { display: block; font-size: 13px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.yd .num { display: block; font-weight: 800; letter-spacing: -0.03em; line-height: 1; }
.yd.front .num, .yd.back .num { font-size: min(52px, 11vw); }
.yd.front .num { color: var(--front); }
.yd.back .num { color: var(--back); }
.yd.middle .num { font-size: min(104px, 21vw); }
.yards.far .yd.middle .num { font-size: min(64px, 13vw); }
.yd.middle .lbl { color: var(--accent); }

.gps { text-align: center; color: var(--muted); font-size: 15px; min-height: 22px; padding: 6px 0 2px; }
.gps.bad { color: var(--danger); }
.gps.ok b { color: var(--accent); }

.nearest { margin: 4px auto 0; background: var(--surface-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 999px; min-height: 40px; padding: 0 16px; font-size: 15px; }

#map { flex: 1; min-height: 120px; width: 100%; margin: 6px 0; border-radius: var(--radius); background: var(--surface); display: block; }

.shotrow { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: center; }
.shotrow .big { font-weight: 700; font-size: 18px; background: var(--accent); color: #07140a; border-color: transparent; min-height: 60px; }
.shotrow .big:active { filter: brightness(0.9); }
.lastshot { text-align: center; font-size: 14px; color: var(--muted); background: transparent; border-color: transparent; padding: 0 6px; min-height: 60px; line-height: 1.2; }
.lastshot b { display: block; font-size: 30px; color: var(--text); line-height: 1.1; }
.gps .club { color: var(--text); font-weight: 700; }
.haz { text-align: center; font-size: 14px; font-weight: 600; padding: 0 0 2px; display: flex; justify-content: center; gap: 14px; flex-wrap: wrap; }
.haz .b { color: var(--front); }
.haz .w { color: var(--back); }
.clubs { display: flex; gap: 8px; overflow-x: auto; padding: 8px 0 2px; scrollbar-width: none; }
.clubs::-webkit-scrollbar { display: none; }
.chip { flex: 0 0 auto; min-width: 56px; min-height: 48px; padding: 0 10px; border-radius: 12px; font-weight: 700; line-height: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; }
.chip small { font-size: 11px; color: var(--muted); font-weight: 600; }
.chip.on { background: var(--accent); color: #07140a; border-color: transparent; }
.chip.on small { color: #07140a; }
.chip.next { border-color: var(--accent); }
.chip.mull { color: var(--front); }
.chip:disabled { opacity: 0.4; }
.scoreline .pscore { cursor: pointer; }
.rounds { display: grid; gap: 8px; }
.round { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px;
  display: flex; justify-content: space-between; align-items: center; gap: 10px; cursor: pointer; }
.round .meta { color: var(--muted); font-size: 13px; }
.round .tot { font-size: 24px; font-weight: 800; text-align: right; }
.round .tot small { display: block; font-size: 12px; color: var(--muted); font-weight: 600; }
.sect { margin: 14px 0 8px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; font-weight: 600; }

.holescores { display: grid; gap: 6px; padding: 10px 0 6px; }
.scoreline { display: grid; grid-template-columns: 1fr var(--tap) 64px var(--tap); align-items: center; gap: 6px; }
.scoreline .pname { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scoreline .pscore { text-align: center; font-size: 30px; font-weight: 800; }
.scoreline .pscore small { display: block; font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: 0.06em; }
.scoreline button { font-size: 28px; padding: 0; min-height: 50px; }

/* ---- scorecard ---- */
.cardhead { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; padding: 14px 0 6px; }
.cardhead h1 { font-size: 22px; margin: 0; letter-spacing: -0.01em; }
.cardhead .sub { color: var(--muted); font-size: 14px; }
.match { color: var(--accent); font-weight: 700; font-size: 18px; padding: 2px 0 8px; min-height: 22px; }
#card { display: grid; gap: 10px; }
.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table.card { border-collapse: collapse; width: 100%; table-layout: fixed; }
table.card th, table.card td { padding: 0; text-align: center; height: 42px; border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); font-size: 16px; overflow: hidden; }
table.card tr > :last-child { border-right: 0; }
table.card tr:last-child > * { border-bottom: 0; }
table.card th { color: var(--muted); font-weight: 600; font-size: 12px; }
table.card .sum { background: var(--surface-2); font-weight: 700; }
table.card .sum small { display: block; font-size: 10px; color: var(--muted); font-weight: 600; line-height: 1; }
table.card .sumlbl { background: var(--surface-2); }
table.card td.name, table.card th.name { text-align: left; padding: 0 8px; width: 78px; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; font-size: 15px; }
table.card td.name { cursor: pointer; }
table.card td.cur { background: #1d2a21; }
table.card td.s { cursor: pointer; }
table.card td.s span { display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px; border: 2px solid transparent; }
table.card td.s.birdie span { border-color: var(--text); border-radius: 50%; }
table.card td.s.eagle span { border-color: var(--text); border-radius: 50%; box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--text); width: 22px; height: 22px; }
table.card td.s.bogey span { border-color: var(--text); border-radius: 3px; }
table.card td.s.dbl span { border-color: var(--text); border-radius: 3px; box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--text); width: 22px; height: 22px; }
table.card td.under { color: var(--accent); }
table.card td.over { color: var(--front); }
.cardctl { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 12px 0; }
.cardctl .danger { color: var(--danger); }
.hint { color: var(--muted); font-size: 14px; text-align: center; padding: 4px 0 10px; }

/* ---- course picker ---- */
.courses { display: grid; gap: 12px; padding: 14px 0; }
.coursecard { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; align-items: center; }
.coursecard h2 { margin: 0; font-size: 20px; letter-spacing: -0.01em; }
.coursecard .meta { color: var(--muted); font-size: 14px; grid-column: 1; }
.coursecard button { grid-row: 1 / span 2; grid-column: 2; background: var(--accent); color: #07140a; border-color: transparent; font-weight: 700; }
.coursecard.active button { background: var(--surface-2); color: var(--text); border-color: var(--line); }
.brand { padding: 22px 0 4px; }
.brand h1 { margin: 0; font-size: 34px; letter-spacing: -0.02em; }
.brand p { margin: 2px 0 0; color: var(--muted); }
.foot { margin-top: auto; color: var(--muted); font-size: 12px; text-align: center; padding: 10px 0; }
.foot a { color: var(--muted); }

@media (max-height: 740px) {
  .yd.middle .num { font-size: min(84px, 21vw); }
  .yd.front .num, .yd.back .num { font-size: min(42px, 11vw); }
}
@media (prefers-reduced-motion: no-preference) {
  .yd .num { transition: color 200ms; }
}
