:root {
  --bg: #f3f6f1;
  --surface: #ffffff;
  --surface-2: #eef3ec;
  --text: #15241b;
  --muted: #5f7067;
  --line: #dbe4dc;
  --brand: #1b6b3f;
  --brand-2: #23884f;
  --brand-ink: #ffffff;
  --brand-soft: #e1f1e6;
  --accent: #e8553d;
  --gold: #e9b10e;
  --danger: #c0392b;
  --shadow: 0 1px 2px rgba(16, 40, 24, .06), 0 4px 16px rgba(16, 40, 24, .06);
  --radius: 16px;
  --tabbar-h: 64px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1511;
    --surface: #17211b;
    --surface-2: #1f2b24;
    --text: #e8f0ea;
    --muted: #93a69a;
    --line: #2a3a30;
    --brand: #2f9a5d;
    --brand-2: #38b26c;
    --brand-soft: #1b3426;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

body.sheet-open { overflow: hidden; }

button, input { font: inherit; color: inherit; }

button {
  cursor: pointer;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

button:disabled { cursor: default; opacity: .35; }

input[type="text"] {
  width: 100%;
  min-width: 0;
  padding: 12px 14px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  font-size: 16px; /* prevents iOS zoom on focus */
  outline: none;
}

input[type="text"]:focus { border-color: var(--brand-2); }

h1, h2 { margin: 0; line-height: 1.2; }

.icon { display: inline-flex; width: 1.25em; height: 1.25em; flex: none; }
.icon svg { width: 100%; height: 100%; }

.boot {
  display: grid;
  place-items: center;
  min-height: 100vh;
  font-size: 48px;
  animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse { 50% { opacity: .4; } }

/* ------------------------------------------------------------- buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 10px 18px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  font-weight: 600;
}

.btn:active:not(:disabled) { transform: scale(.98); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--brand-2); }
.btn.small { min-height: 38px; padding: 6px 12px; font-size: 15px; }
.btn.big { min-height: 56px; font-size: 18px; }
.btn.block { display: flex; width: 100%; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: none;
  border: 0;
  border-radius: 12px;
  background: transparent;
  font-size: 20px;
}

.icon-btn:active:not(:disabled) { background: var(--surface-2); }
.icon-btn.round { border-radius: 50%; background: var(--surface); box-shadow: var(--shadow); width: 52px; height: 52px; font-size: 24px; }
.icon-btn.danger { color: var(--danger); }

.linkish {
  padding: 0;
  border: 0;
  background: none;
  color: var(--brand-2);
  font-weight: 600;
  text-decoration: underline;
}

.tag {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand-2);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .02em;
  text-transform: uppercase;
  vertical-align: 2px;
}

.badge {
  display: inline-block;
  margin-right: 6px;
  padding: 0 6px;
  border-radius: 6px;
  background: var(--gold);
  color: #2b2100;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.hint { margin: 8px 0 0; color: var(--muted); font-size: 14px; }
.hint .icon { vertical-align: -3px; width: 1em; height: 1em; }
.center { text-align: center; }

.row-buttons { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.row-buttons .btn { flex: 1; }

/* --------------------------------------------------------------- stepper */

.stepper { display: flex; align-items: center; gap: 6px; }

.step {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--surface-2);
  font-size: 20px;
}

.step:active:not(:disabled) { background: var(--brand-soft); }

.stepper-value {
  min-width: 52px;
  font-size: 26px;
  font-weight: 800;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.stepper.wide { justify-content: center; gap: 24px; }

/* ------------------------------------------------------------------ home */

.home-hero {
  padding: calc(var(--safe-top) + 36px) 20px 28px;
  background: linear-gradient(160deg, var(--brand-2), var(--brand));
  color: #fff;
  text-align: center;
}

.home-hero .logo { width: 72px; height: 72px; border-radius: 18px; box-shadow: 0 6px 20px rgba(0, 0, 0, .2); }
.home-hero h1 { margin-top: 12px; font-size: 30px; letter-spacing: -.01em; }
.home-hero p { margin: 6px 0 0; opacity: .9; }

.home {
  display: grid;
  gap: 16px;
  max-width: 560px;
  margin: -14px auto 0;
  padding: 0 16px calc(var(--safe-bottom) + 32px);
}

.card {
  padding: 20px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.card h2 { margin-bottom: 14px; font-size: 20px; }
.card .btn.primary { margin-top: 8px; }

.field { display: block; margin-bottom: 18px; }
.field > span:first-child {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.holes-picker { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

.presets { display: flex; gap: 6px; }
.presets button {
  min-width: 42px;
  height: 38px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  font-weight: 600;
}
.presets button.on { border-color: var(--brand); background: var(--brand-soft); color: var(--brand-2); }

.player-inputs { display: grid; gap: 8px; margin-bottom: 6px; }
.player-input { position: relative; display: flex; align-items: center; gap: 4px; }
.player-input .tag { position: absolute; right: 12px; margin: 0; pointer-events: none; }

.recent { margin: 0; padding: 0; list-style: none; }
.recent li { display: flex; align-items: center; border-top: 1px solid var(--line); }
.recent li:first-child { border-top: 0; }
.recent a { flex: 1; min-width: 0; padding: 12px 0; color: inherit; text-decoration: none; }
.recent-name { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-meta { display: block; color: var(--muted); font-size: 14px; }

.tip { margin: 0; color: var(--muted); font-size: 14px; text-align: center; }
.tip .icon { vertical-align: -3px; width: 1.1em; height: 1.1em; }

/* ------------------------------------------------------------ game page */

.game-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: calc(var(--safe-top) + 6px) 6px 6px;
  background: var(--brand);
  color: #fff;
}

.game-header .icon-btn:active { background: rgba(255, 255, 255, .15); }
.game-header .title { flex: 1; min-width: 0; padding: 0 4px; }
.game-header h1 { font-size: 18px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.game-header .sub { font-size: 13px; opacity: .85; }
.game-header .conn { display: none; }
.game-header.offline .conn { display: inline; color: #ffd27a; }

.game-main {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px calc(var(--tabbar-h) + var(--safe-bottom) + 24px);
}

.tabbar {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 10;
  display: flex;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}

.tab {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.tab .icon { font-size: 22px; }
.tab.on { color: var(--brand-2); }

.empty, .empty-page { padding: 40px 8px; text-align: center; }
.empty-page { max-width: 420px; margin: 0 auto; padding-top: calc(var(--safe-top) + 80px); }
.empty p, .empty-page p { color: var(--muted); }
.big-emoji { font-size: 52px; line-height: 1.2; }

/* holes */

.hole-nav { display: flex; align-items: center; justify-content: space-between; padding: 4px 8px 12px; }
.hole-title { text-align: center; }
.hole-label, .hole-of { color: var(--muted); font-size: 13px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.hole-num { font-size: 56px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }

.chips {
  display: flex;
  gap: 6px;
  margin: 0 -16px 16px;
  padding: 4px 16px 8px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: none;
  width: 38px;
  height: 38px;
  border: 1.5px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.chip.started { border-color: var(--brand-2); color: var(--text); }
.chip.done { border-color: var(--brand-soft); background: var(--brand-soft); color: var(--brand-2); }
.chip.current { border-color: var(--brand); background: var(--brand); color: #fff; }

.rows { display: grid; gap: 10px; margin-bottom: 16px; }

.prow {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 12px 12px 16px;
  border: 2px solid transparent;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.prow.me { border-color: var(--brand-2); }

.pinfo { flex: 1; min-width: 0; }
.pname { display: flex; align-items: center; font-size: 17px; font-weight: 700; }
.pname > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.psub { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }

.prow .step { width: 46px; height: 46px; }

.score {
  width: 58px;
  height: 58px;
  border: 0;
  border-radius: 14px;
  background: var(--brand-soft);
  color: var(--brand-2);
  font-size: 30px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.score.blank { background: var(--surface-2); color: var(--muted); font-weight: 400; }

.holes > .btn { margin-top: 4px; }

/* leaderboard */

.winner {
  margin-bottom: 16px;
  padding: 20px;
  border-radius: var(--radius);
  background: linear-gradient(160deg, #f8d24b, var(--gold));
  color: #2b2100;
  text-align: center;
  box-shadow: var(--shadow);
}
.winner-name { font-size: 26px; font-weight: 800; }
.winner-sub { font-weight: 600; opacity: .8; }

.board { display: grid; gap: 8px; margin: 0 0 16px; padding: 0; list-style: none; }

.board li {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  border: 2px solid transparent;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.board li.me { border-color: var(--brand-2); }

.rank {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  flex: none;
  border-radius: 50%;
  background: var(--surface-2);
  font-weight: 800;
  font-size: 15px;
}
.board li.leader .rank { background: var(--gold); color: #2b2100; }

.bname { flex: 1; min-width: 0; font-size: 17px; font-weight: 700; }
.bname > span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bsub { color: var(--muted); font-size: 13px; font-weight: 500; }
.btotal { font-size: 28px; font-weight: 800; font-variant-numeric: tabular-nums; }

/* scorecard */

.game-main.tab-card { padding-left: 0; padding-right: 0; }

.card-wrap {
  max-height: calc(100vh - 150px - var(--safe-top) - var(--safe-bottom));
  margin: 0 16px;
  overflow: auto;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  -webkit-overflow-scrolling: touch;
}

.scorecard { min-width: 100%; border-collapse: separate; border-spacing: 0; font-variant-numeric: tabular-nums; }

.scorecard th, .scorecard td { padding: 0; border-bottom: 1px solid var(--line); text-align: center; }

.scorecard thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  max-width: 96px;
  padding: 10px 8px;
  overflow: hidden;
  background: var(--surface);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.scorecard th:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  width: 56px;
  min-width: 56px;
  background: var(--surface);
  color: var(--muted);
  font-size: 14px;
}
.scorecard thead th.corner { z-index: 3; }
.scorecard thead th.me { color: var(--brand-2); }

.scorecard tbody tr.current th:first-child, .scorecard tbody tr.current td { background: var(--brand-soft); }

.scorecard tfoot th, .scorecard tfoot td {
  position: sticky;
  bottom: 0;
  padding: 12px 8px;
  border-top: 2px solid var(--line);
  border-bottom: 0;
  background: var(--surface-2);
  font-size: 18px;
  font-weight: 800;
}
.scorecard tfoot th:first-child { z-index: 2; background: var(--surface-2); color: var(--text); font-size: 13px; text-transform: uppercase; }

.cell, .hole-link {
  width: 100%;
  min-width: 56px;
  height: 46px;
  border: 0;
  background: none;
  font-size: 18px;
  font-weight: 600;
}
.hole-link { min-width: 0; color: var(--muted); font-size: 15px; font-weight: 700; }
.cell.low { color: var(--brand-2); font-weight: 800; }
.cell:active { background: var(--surface-2); }

/* ---------------------------------------------------------------- sheets */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0);
  transition: background .2s;
}
.overlay.show { background: rgba(0, 0, 0, .45); }

.sheet {
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  padding: 18px 18px calc(var(--safe-bottom) + 18px);
  overflow-y: auto;
  border-radius: 22px 22px 0 0;
  background: var(--surface);
  transform: translateY(100%);
  transition: transform .22s ease-out;
  overscroll-behavior: contain;
}
.overlay.show .sheet { transform: none; }

.sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.sheet-title { font-size: 20px; font-weight: 800; }
.sheet-sub { color: var(--muted); font-size: 14px; }
.sheet-label {
  margin: 20px 0 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.keys { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 14px; }
.key {
  height: 62px;
  border: 0;
  border-radius: 14px;
  background: var(--surface-2);
  font-size: 26px;
  font-weight: 800;
}
.key:active, .key.on { background: var(--brand); color: #fff; }

.inline-form { display: flex; gap: 8px; }
.inline-form .btn { flex: none; }

.who-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.who-btn {
  min-height: 52px;
  padding: 8px 12px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.who-btn.on { border-color: var(--brand); background: var(--brand-soft); color: var(--brand-2); }
.who .btn.ghost { margin-top: 12px; }

.pl-list { margin: 0 0 10px; padding: 0; list-style: none; }
.pl-list li { display: flex; align-items: center; border-bottom: 1px solid var(--line); }
.pl-name { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.you-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

/* ----------------------------------------------------------------- toast */

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px);
  z-index: 100;
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 12px;
  background: #15241b;
  color: #fff;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 10px);
  transition: opacity .2s, transform .2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
