:root {
  --grass-a: #2c7a4b;
  --grass-b: #266e43;
  --rough: #123d2a;
  --flag: #d4262f;
  --flag-dark: #ad1d25;
  --sand: #efe4c4;
  --paper: #ffffff;
  --ink: #18241d;
  --muted: #64716a;
  --rule: #dbe4dc;
  --head: #256b43;
  --field: #f3f7f3;
  --on-grass: rgba(255, 255, 255, .86);
  --display: "Barlow Condensed", "Arial Narrow", system-ui, sans-serif;
  --body: "Barlow", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --grass-a: #17432b;
    --grass-b: #143c26;
    --rough: #0a2418;
    --paper: #142019;
    --ink: #e7eee9;
    --muted: #93a39a;
    --rule: #26362d;
    --head: #1e5a38;
    --field: #1a2a21;
    --sand: #3a3220;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { background: var(--grass-b); }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font: 400 16px/1.5 var(--body);
  -webkit-text-size-adjust: 100%;
  /* mown fairway stripes */
  background:
    linear-gradient(180deg, rgba(0,0,0,.18), transparent 320px),
    repeating-linear-gradient(104deg, var(--grass-a) 0 64px, var(--grass-b) 64px 128px);
  background-color: var(--grass-b);
}

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; }
:focus-visible { outline: 3px solid #ffd84d; outline-offset: 2px; }

/* ---------- masthead ---------- */

.masthead {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(32px + env(safe-area-inset-top)) 16px 24px;
  color: #fff;
}
.title-row { display: flex; align-items: flex-end; gap: 10px; }
.pin { width: 30px; height: 52px; flex: none; color: #fff; }
.pin .flag { fill: var(--flag); transform-origin: 9px 14px; }
.masthead h1 {
  margin: 0;
  font: 800 3.4rem/.88 var(--display);
  letter-spacing: -.01em;
  text-transform: uppercase;
  text-shadow: 0 2px 0 rgba(0,0,0,.15);
}
.tagline { margin: 8px 0 0; color: var(--on-grass); font-size: .95rem; max-width: 34ch; line-height: 1.4; }

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 0 16px calc(48px + env(safe-area-inset-bottom));
  display: grid;
  gap: 18px;
}

.on-grass { color: var(--on-grass); font-size: .88rem; margin: 10px 2px 0; }
.on-grass:empty { display: none; }
.center { text-align: center; }

/* ---------- format toggle (sits on the grass) ---------- */

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 4px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .24);
  box-shadow: inset 0 1px 3px rgba(0,0,0,.25);
}
.segmented button {
  border: 0;
  background: transparent;
  color: #fff;
  font: 700 1.15rem/1 var(--display);
  letter-spacing: .02em;
  padding: 12px 10px;
  border-radius: 999px;
  transition: background .15s, color .15s;
}
.segmented button[aria-checked="true"] {
  background: #fff;
  color: var(--head);
  box-shadow: 0 2px 6px rgba(0,0,0,.2);
}
@media (prefers-color-scheme: dark) {
  .segmented button[aria-checked="true"] { color: #1e5a38; }
}
.segmented button:disabled[aria-checked="false"] { opacity: .4; }

.allowance-row {
  margin-top: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 10px 10px 16px;
  border-radius: 12px;
  background: rgba(0,0,0,.2);
  color: #fff;
}
.allowance-row label { font-weight: 600; }
.suffix { display: flex; align-items: center; gap: 6px; }
.suffix span { font: 700 1.2rem var(--display); }
.suffix input {
  width: 4.5rem;
  border: 0;
  border-radius: 8px;
  padding: 8px 4px;
  text-align: center;
  font: 700 1.2rem var(--display);
  background: #fff;
  color: #18241d;
}

/* ---------- scorecard ---------- */

.scorecard {
  background: var(--paper);
  border-radius: 6px;
  box-shadow: 0 10px 30px rgba(0,0,0,.22), 0 1px 0 rgba(0,0,0,.08);
  overflow: hidden;
}
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 16px 16px 12px;
}
.card-head h2 { margin: 0; font: 700 1.6rem/1 var(--display); }
.count { color: var(--muted); font-weight: 500; }
.text-btn {
  border: 0; background: none; padding: 4px 0;
  color: var(--flag); font-weight: 600; font-size: .9rem;
}

.player-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 4.25rem 4.25rem 3.25rem;
  align-items: stretch;
}
.sc-head {
  background: var(--head);
  color: #fff;
  font: 600 .95rem/1 var(--display);
  letter-spacing: .03em;
}
.sc-head span { padding: 9px 12px; }
.sc-head span:nth-child(2), .sc-head span:nth-child(3) { text-align: center; padding-inline: 0; border-left: 1px solid rgba(255,255,255,.2); }

.player-list { list-style: none; margin: 0; padding: 0; }
.player-list li { border-bottom: 1px solid var(--rule); }
.player-list li > *:not(:first-child),
.add-row > *:not(:first-child) { border-left: 1px solid var(--rule); }
.player-list li:nth-child(even) { background: color-mix(in srgb, var(--field) 60%, transparent); }

.player-grid input {
  width: 100%;
  min-width: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  padding: 13px 12px;
  font: 500 1rem var(--body);
}
.player-grid input[type="number"] {
  text-align: center;
  padding-inline: 2px;
  font: 700 1.25rem/1 var(--display);
  -moz-appearance: textfield;
}
input::-webkit-outer-spin-button, input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.player-grid input:focus { outline: none; box-shadow: inset 0 0 0 2px var(--head); background: var(--field); }
.player-grid input::placeholder { color: var(--muted); opacity: .7; font-weight: 500; }
.player-grid input[aria-invalid="true"] { box-shadow: inset 0 0 0 2px var(--flag); background: color-mix(in srgb, var(--flag) 8%, transparent); }

.remove {
  border: 0; background: none; color: var(--muted);
  display: grid; place-items: center;
}
.remove { min-height: 48px; }
.remove svg { width: 18px; height: 18px; }
button svg { pointer-events: none; }
.remove:hover:not(:disabled) { color: var(--flag); }
.remove:disabled { visibility: hidden; }

.empty { margin: 0; padding: 18px 16px; color: var(--muted); font-size: .92rem; border-bottom: 1px solid var(--rule); }

.add-row { background: var(--field); border-bottom: 1px solid var(--rule); }
.add-row input#add-player { font-weight: 600; }
.add-btn {
  border: 0;
  background: var(--head);
  color: #fff;
  display: grid; place-items: center;
}
.add-btn svg { width: 20px; height: 20px; }
.add-btn:hover { filter: brightness(1.1); }
.add-row.locked { display: none; }

.footnote { margin: 0; padding: 10px 16px 14px; color: var(--muted); font-size: .8rem; }

/* ---------- draw ---------- */

.draw-btn {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  border: 0;
  border-radius: 999px;
  padding: 18px;
  background: var(--flag);
  color: #fff;
  font: 800 1.45rem/1 var(--display);
  letter-spacing: .02em;
  text-transform: uppercase;
  box-shadow: 0 4px 0 var(--flag-dark), 0 12px 24px rgba(0,0,0,.25);
  transition: transform .08s, box-shadow .08s;
}
.draw-btn svg { width: 22px; height: 22px; }
.draw-btn:not(:disabled):active { transform: translateY(3px); box-shadow: 0 1px 0 var(--flag-dark), 0 6px 14px rgba(0,0,0,.25); }
.draw-btn:disabled { background: rgba(0,0,0,.22); color: rgba(255,255,255,.6); box-shadow: none; }

/* ---------- leaderboard ---------- */

.board {
  background: var(--rough);
  border-radius: 10px;
  padding: 14px 10px 12px;
  box-shadow: 0 14px 34px rgba(0,0,0,.35), inset 0 0 0 2px rgba(255,255,255,.06);
  color: #fff;
  scroll-margin-top: 16px;
}
.board-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 0 6px 12px;
}
.board-head h2 { margin: 0; font: 800 1.9rem/1 var(--display); text-transform: uppercase; letter-spacing: .01em; }
.board-format { margin: 4px 0 0; color: rgba(255,255,255,.7); font-size: .85rem; }
.actions { display: flex; gap: 8px; }

.chip-btn {
  border: 0;
  border-radius: 999px;
  padding: 8px 14px;
  background: #fff;
  color: #123d2a;
  font-weight: 600;
  font-size: .88rem;
}
.chip-btn.ghost { background: transparent; color: rgba(255,255,255,.8); box-shadow: inset 0 0 0 1.5px rgba(255,255,255,.35); }

.results { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.result {
  display: grid;
  grid-template-columns: 3.4rem minmax(0, 1fr) auto;
  align-items: stretch;
  background: #fbfbf7;
  color: #18241d;
  border-radius: 3px;
  overflow: hidden;
  min-height: 58px;
}
.pos {
  display: grid; place-items: center;
  background: #e9eee8;
  color: #123d2a;
  font: 800 1.25rem/1 var(--display);
}
.pos-1 .pos { background: #ffd84d; color: #3d2f00; }
.body { display: grid; align-content: center; padding: 8px 12px; min-width: 0; }
.body strong {
  font: 700 1.3rem/1.05 var(--display);
  text-transform: uppercase;
  letter-spacing: .01em;
  overflow-wrap: anywhere;
}
.detail { color: #64716a; font-size: .8rem; line-height: 1.3; margin-top: 3px; overflow-wrap: anywhere; }
.total {
  display: grid;
  align-content: center;
  justify-items: end;
  padding: 0 14px 0 6px;
  color: var(--flag);
  font: 800 2rem/1 var(--display);
  font-variant-numeric: tabular-nums;
}
.total small { font: 600 .75rem/1.2 var(--body); color: #64716a; }

.board-note { margin: 10px 6px 0; color: rgba(255,255,255,.7); font-size: .8rem; }
.board-note:empty { display: none; }
.warn {
  margin: 0 0 10px;
  padding: 10px 12px;
  border-radius: 6px;
  background: var(--sand);
  color: var(--ink);
  font-size: .85rem;
}

/* one moment of motion: the board fills in when pairs are drawn */
.board.reveal .result {
  animation: slat-in .45s cubic-bezier(.2, .8, .2, 1) both;
  animation-delay: calc(var(--i, 0) * 90ms);
}
@keyframes slat-in {
  from { opacity: 0; transform: translateX(-14px) rotateX(55deg); }
  to { opacity: 1; transform: none; }
}

/* ---------- shared banner ---------- */

.banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(0,0,0,.24);
  color: #fff;
}
.banner p { margin: 0; font-weight: 600; }

@media (max-width: 380px) {
  .masthead h1 { font-size: 2.8rem; }
  .player-grid { grid-template-columns: minmax(0, 1fr) 3.6rem 3.6rem 3rem; }
}

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