:root {
  --felt: #173f27;
  --felt-2: #1b4a2e;
  --felt-deep: #0e2a18;
  --card: #fbf8ef;
  --card-2: #f3eedf;
  --ink: #15301f;
  --muted: #6c7d70;
  --line: #e2dccb;
  --green: #2c8a4b;
  --green-soft: #dcefdf;
  --flag: #e2533b;
  --gold: #e7b52c;
  --gold-soft: #fbefc6;
  --radius: 20px;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.6) inset, 0 12px 30px -12px rgba(5, 20, 10, 0.55);
  --display: "Fraunces", Georgia, serif;
  --body: "DM Sans", system-ui, -apple-system, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--body);
  color: var(--ink);
  background-color: var(--felt);
  /* Mowed-lawn stripes with a soft vignette. */
  background-image:
    radial-gradient(ellipse at 50% -10%, rgba(120, 200, 120, 0.18), transparent 60%),
    repeating-linear-gradient(100deg, var(--felt) 0 70px, var(--felt-2) 70px 140px);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

main {
  max-width: 560px;
  margin: 0 auto;
  padding:
    max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
    max(32px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

h1, h2, h3 { font-family: var(--display); margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 1.15rem; }

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: 0.35; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 14px;
}
.card > h2 { margin-bottom: 12px; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

/* ---------- brand ---------- */
.brand { text-align: center; color: var(--card); padding: 28px 0 24px; }
.brand svg { width: 92px; height: 92px; filter: drop-shadow(0 10px 18px rgba(0, 0, 0, 0.35)); }
.brand h1 { font-size: 3rem; font-weight: 800; line-height: 1; margin-top: 6px; }
.brand h1 em { font-weight: 600; color: var(--gold); }
.brand p { margin: 10px 0 0; opacity: 0.8; }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px;
  border: 0; border-radius: 14px;
  background: var(--card-2); color: var(--ink);
  font-weight: 700; text-decoration: none;
  transition: transform 0.08s ease, background 0.15s ease;
}
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn.primary { background: var(--green); color: #fff; box-shadow: 0 6px 16px -6px rgba(20, 90, 45, 0.8); }
.btn.flag { background: var(--flag); color: #fff; }
.btn.ghost { background: transparent; border: 2px solid var(--line); }
.btn.big { width: 100%; min-height: 58px; font-size: 1.1rem; border-radius: 16px; }
.btn.block { width: 100%; }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: 0.9rem; border-radius: 10px; }

.field { display: block; margin-bottom: 16px; }
.field > span { display: block; font-size: 0.85rem; font-weight: 700; color: var(--muted); margin-bottom: 6px; }
.input {
  width: 100%; min-height: 50px; padding: 0 14px;
  border: 2px solid var(--line); border-radius: 14px;
  background: #fff; font-size: 1.05rem;
}
.input:focus { outline: none; border-color: var(--green); }

.row { display: flex; gap: 10px; align-items: center; }
.row > .grow { flex: 1; min-width: 0; }

.code-input {
  text-transform: uppercase; letter-spacing: 0.35em; text-align: center;
  font-family: var(--display); font-weight: 800; font-size: 1.4rem;
}
.code-input::placeholder { letter-spacing: 0.2em; color: #c9c3b1; }

.divider { display: flex; align-items: center; gap: 12px; margin: 18px 0 14px; color: var(--muted); font-size: 0.85rem; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; font-weight: 500; }
.switch input {
  appearance: none; width: 52px; height: 32px; border-radius: 99px; flex: none;
  background: var(--line); position: relative; transition: background 0.2s; cursor: pointer;
}
.switch input::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25); transition: transform 0.2s;
}
.switch input:checked { background: var(--green); }
.switch input:checked::after { transform: translateX(20px); }

/* ---------- lists ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list li + li { border-top: 1px solid var(--line); }
.list a, .list .item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 2px; color: inherit; text-decoration: none;
}
.list b { font-weight: 700; }
.pill {
  display: inline-block; padding: 3px 9px; border-radius: 99px;
  background: var(--green-soft); color: var(--green);
  font-weight: 700; font-size: 0.8rem; letter-spacing: 0.06em;
}

/* ---------- new game ---------- */
.courses { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.course-chip {
  display: inline-flex; align-items: center; gap: 2px;
  border: 2px solid var(--line); border-radius: 12px; background: #fff;
}
.course-chip button { border: 0; background: none; padding: 8px 4px 8px 12px; text-align: left; }
.course-chip button small { display: block; color: var(--muted); font-size: 0.75rem; }
.course-chip .x { padding: 8px 10px; color: var(--muted); font-size: 1.1rem; }
.course-chip.on { border-color: var(--green); background: var(--green-soft); }

.stepper { display: inline-flex; align-items: center; background: var(--card-2); border-radius: 14px; }
.stepper button { width: 44px; height: 44px; border: 0; background: none; font-size: 1.4rem; font-weight: 700; }
.stepper output { min-width: 2.5ch; text-align: center; font-family: var(--display); font-weight: 800; font-size: 1.25rem; }

.pars { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 8px; margin: 12px 0; }
.par-cell {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 58px; border: 2px solid var(--line); border-radius: 12px; background: #fff;
  transition: transform 0.08s ease;
}
.par-cell:active { transform: scale(0.94); }
.par-cell small { font-size: 0.7rem; color: var(--muted); }
.par-cell b { font-family: var(--display); font-size: 1.3rem; line-height: 1.1; }
.quick { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- game header ---------- */
.topbar { display: flex; align-items: center; gap: 10px; color: var(--card); margin-bottom: 14px; }
.topbar .title { flex: 1; min-width: 0; }
.topbar h1 { font-size: 1.35rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .sub { font-size: 0.8rem; opacity: 0.75; display: flex; align-items: center; gap: 6px; }
.icon-btn {
  display: grid; place-items: center; width: 44px; height: 44px; flex: none;
  border: 0; border-radius: 14px; background: rgba(255, 255, 255, 0.12); color: var(--card);
  text-decoration: none; font-size: 1.3rem;
}
.code-btn {
  border: 0; border-radius: 12px; padding: 8px 12px; flex: none;
  background: var(--card); color: var(--ink);
  font-family: var(--display); font-weight: 800; letter-spacing: 0.15em;
}
.live { width: 8px; height: 8px; border-radius: 50%; background: #9aa69c; display: inline-block; }
.live.on { background: #6fe08f; box-shadow: 0 0 0 3px rgba(111, 224, 143, 0.25); }

.tabs { display: grid; grid-template-columns: 1fr 1fr; background: rgba(0, 0, 0, 0.22); border-radius: 14px; padding: 4px; margin-bottom: 14px; }
.tabs button { border: 0; border-radius: 10px; min-height: 40px; background: none; color: var(--card); font-weight: 700; opacity: 0.75; }
.tabs button.on { background: var(--card); color: var(--ink); opacity: 1; }

/* ---------- hole view ---------- */
.hole-hero { display: grid; grid-template-columns: 56px 1fr 56px; align-items: center; text-align: center; padding: 18px 12px 14px; }
.hole-hero .nav { width: 52px; height: 52px; border-radius: 50%; border: 0; background: var(--card-2); font-size: 1.6rem; }
.hole-label { font-size: 0.75rem; font-weight: 700; letter-spacing: 0.2em; text-transform: uppercase; color: var(--muted); }
.hole-num { font-family: var(--display); font-weight: 800; font-size: 4.2rem; line-height: 0.95; }
.hole-of { font-size: 0.85rem; color: var(--muted); }
.par-row { grid-column: 1 / -1; display: flex; justify-content: center; margin-top: 12px; }
.par-tag {
  display: inline-flex; align-items: center; gap: 4px; padding: 4px; border-radius: 99px;
  background: var(--green-soft); color: var(--green); font-weight: 700;
}
.par-tag span { padding: 4px 10px; }
.par-tag button { width: 32px; height: 32px; border-radius: 50%; border: 0; background: #fff; color: var(--green); font-weight: 800; }

.strip { display: flex; gap: 6px; overflow-x: auto; padding: 4px 2px 14px; scrollbar-width: none; scroll-snap-type: x proximity; }
.strip::-webkit-scrollbar { display: none; }
.dot {
  flex: none; width: 38px; height: 38px; border-radius: 50%; scroll-snap-align: center;
  border: 2px solid rgba(255, 255, 255, 0.25); background: transparent; color: var(--card);
  font-weight: 700; font-size: 0.9rem;
}
.dot.done { background: rgba(255, 255, 255, 0.16); border-color: transparent; }
.dot.on { background: var(--card); color: var(--ink); border-color: var(--gold); }

.players { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.player { background: var(--card); border-radius: 18px; box-shadow: var(--shadow); padding: 14px; border-left: 6px solid var(--c); }
.p-head { display: flex; align-items: center; gap: 12px; }
.avatar {
  width: 40px; height: 40px; flex: none; border-radius: 50%; display: grid; place-items: center;
  background: var(--c); color: #fff; font-weight: 800; font-family: var(--display); font-size: 1.1rem;
}
.p-info { flex: 1; min-width: 0; }
.p-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.p-name em { font-style: normal; font-size: 0.7rem; font-weight: 700; color: var(--green); background: var(--green-soft); padding: 2px 6px; border-radius: 6px; margin-left: 6px; vertical-align: 2px; }
.p-meta { font-size: 0.82rem; color: var(--muted); }
.p-score {
  width: 50px; height: 50px; flex: none; display: grid; place-items: center;
  font-family: var(--display); font-weight: 800; font-size: 1.6rem;
  border-radius: 14px; background: var(--card-2); color: var(--muted);
}
.p-score.set { background: var(--ink); color: var(--card); }
.p-score.under { background: var(--flag); color: #fff; border-radius: 50%; }
.p-score.ace { background: var(--gold); color: var(--ink); border-radius: 50%; }
.chips { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-top: 12px; }
.chip {
  height: 46px; border: 0; border-radius: 12px; background: var(--card-2);
  font-family: var(--display); font-weight: 800; font-size: 1.15rem;
  transition: transform 0.08s ease, background 0.12s ease;
}
.chip:active { transform: scale(0.92); }
.chip.on { background: var(--green); color: #fff; }
.chip.more { color: var(--muted); }

.empty { text-align: center; padding: 28px 20px; }
.empty p { margin: 6px 0 16px; }
.next-wrap { margin-top: 14px; }

/* ---------- scorecard ---------- */
.board .rank-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; }
.board .rank-row + .rank-row { border-top: 1px solid var(--line); }
.rank { width: 30px; text-align: center; font-family: var(--display); font-weight: 800; color: var(--muted); }
.rank-row.first .rank { color: var(--gold); }
.to-par { font-family: var(--display); font-weight: 800; font-size: 1.4rem; min-width: 3ch; text-align: right; }
.to-par.under { color: var(--flag); }
.winner {
  text-align: center; background: linear-gradient(160deg, var(--gold-soft), var(--card));
  padding: 26px 20px;
}
.winner .trophy { font-size: 2.6rem; }
.winner h2 { font-size: 1.7rem; margin-top: 4px; }

.sc-wrap { overflow-x: auto; margin: 0 -20px; padding: 0 20px; }
.sc { border-collapse: separate; border-spacing: 0; font-variant-numeric: tabular-nums; min-width: 100%; }
.sc th, .sc td { padding: 0; text-align: center; height: 40px; min-width: 36px; font-size: 0.95rem; }
.sc thead th { font-size: 0.75rem; color: var(--muted); font-weight: 700; }
.sc tr.par td, .sc tr.par th { color: var(--muted); border-bottom: 2px solid var(--line); }
.sc th.name {
  position: sticky; left: -20px; z-index: 1; background: var(--card); text-align: left;
  padding: 0 10px 0 0; max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-weight: 700; box-shadow: 8px 0 8px -8px rgba(0, 0, 0, 0.18);
}
.sc tbody th.name { color: var(--ink); }
.sc tbody th.name::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--c); margin-right: 6px; }
.sc td.cell button {
  width: 32px; height: 32px; border: 0; background: none; border-radius: 8px; font-weight: 700;
}
.sc td.cell.cur { background: rgba(231, 181, 44, 0.16); }
.sc td.cell .under { background: var(--flag); color: #fff; border-radius: 50%; }
.sc td.cell .ace { background: var(--gold); border-radius: 50%; }
.sc td.cell .over { box-shadow: inset 0 0 0 1.5px var(--ink); }
.sc td.cell .over2 { box-shadow: inset 0 0 0 1.5px var(--ink), inset 0 0 0 3px var(--card), inset 0 0 0 4.5px var(--ink); }
.sc td.cell .none { color: #cdc6b3; }
.sc .tot { font-family: var(--display); font-weight: 800; padding: 0 6px 0 10px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 12px; font-size: 0.8rem; color: var(--muted); }
.legend i { display: inline-block; width: 12px; height: 12px; vertical-align: -1px; margin-right: 5px; border-radius: 50%; }

/* ---------- join banner ---------- */
.join-card { border: 2px dashed var(--green); background: var(--green-soft); }

/* ---------- sheet (dialog) ---------- */
#sheet {
  width: min(560px, 100vw); max-width: 100vw; max-height: 88dvh;
  margin: auto auto 0; padding: 0; border: 0;
  border-radius: 24px 24px 0 0; background: var(--card); color: var(--ink);
  box-shadow: 0 -20px 50px rgba(0, 0, 0, 0.35);
}
#sheet[open] { animation: rise 0.25s cubic-bezier(0.2, 0.9, 0.3, 1.1); }
#sheet::backdrop { background: rgba(6, 22, 12, 0.55); backdrop-filter: blur(2px); }
.sheet-body { padding: 10px 20px max(24px, env(safe-area-inset-bottom)); }
.grabber { width: 44px; height: 5px; border-radius: 99px; background: var(--line); margin: 10px auto 6px; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.sheet-section { padding: 16px 0; border-top: 1px solid var(--line); }
.sheet-section h3 { font-size: 1rem; margin-bottom: 10px; }
.p-edit { display: flex; gap: 8px; align-items: center; padding: 6px 0; }
.p-edit .input { min-height: 42px; font-size: 0.95rem; }
.p-edit .dot-c { width: 12px; height: 12px; border-radius: 50%; background: var(--c); flex: none; }
.stack { display: grid; gap: 10px; }

@keyframes rise { from { transform: translateY(40px); opacity: 0; } }

/* ---------- toast & confetti ---------- */
#toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); z-index: 50;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--card); padding: 12px 18px; border-radius: 14px;
  font-weight: 500; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  transition: opacity 0.2s, transform 0.2s; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

.confetti { position: fixed; top: -12px; width: 9px; height: 14px; z-index: 60; pointer-events: none; border-radius: 2px; animation: fall linear forwards; }
@keyframes fall { to { transform: translate(var(--dx), 105vh) rotate(var(--r)); } }

.loading { text-align: center; color: var(--card); padding: 80px 0; opacity: 0.8; }
.ball { width: 22px; height: 22px; border-radius: 50%; background: #fff; margin: 0 auto 14px; animation: roll 0.9s ease-in-out infinite alternate; box-shadow: inset -4px -4px 0 rgba(0, 0, 0, 0.08); }
@keyframes roll { from { transform: translateX(-30px); } to { transform: translateX(30px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

.btn.on-felt { background: rgba(255, 255, 255, 0.12); color: var(--card); }
.strip { position: relative; }
.sheet-head + .sheet-section { border-top: 0; }
