/* Score Keeper. The header and its actions at the top, a card for each
   player below, each with a big score and a +1 and −1 a thumb reaches. An
   app, so every control is at least 44px (R-G26b), and the page scrolls when
   there are more players than fit (R-A8). */

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

/* any class that sets display would otherwise beat the UA's [hidden] */
[hidden] { display: none !important; }

:root {
  --bg: #14181f;
  --bg2: #1c222c;
  --line: #2c3442;
  --ink: #eceff4;
  --dim: #9ba7b9;
  --accent: #3fbf6a;
  --radius: 16px;
  --pad: 12px;
}

/* R-C40: the light look; "auto" follows the device */
:root[data-theme="light"] {
  --bg: #f4f6fa; --bg2: #ffffff; --line: #d6dde8;
  --ink: #17202c; --dim: #5b6779;
  --accent: #1b7f3b;
}

html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px; line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}

#app {
  min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column;
  padding: 0 var(--pad) env(safe-area-inset-bottom);
  max-width: 1100px; margin: 0 auto;
}

/* ---------- header ---------- */
#hdr {
  display: flex; align-items: center; gap: 8px;
  padding: max(8px, env(safe-area-inset-top)) 0 8px;
  border-bottom: 1px solid var(--line);
}
#hdr h1 { font-size: 19px; font-weight: 800; letter-spacing: -0.01em; white-space: nowrap; }
#hdrSpace, .grow { flex: 1; }

.pill {
  min-width: 44px; min-height: 44px;
  border-radius: 999px; border: 2px solid var(--line);
  background: var(--bg2); color: inherit; font: inherit; font-size: 18px;
  cursor: pointer;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 8px 14px;
  border-radius: 12px; border: 2px solid var(--line);
  background: var(--bg2); color: inherit; font: inherit; font-weight: 600;
  cursor: pointer; text-align: center; touch-action: manipulation;
}
.btn.primary { border-color: var(--accent); }
.btn.danger { border-color: #c0392b; }
.btn:disabled { opacity: 0.45; cursor: default; }
.pill:focus-visible, .btn:focus-visible, .step:focus-visible, .score:focus-visible, .name:focus-visible,
input:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* undo, share and new game keep one line at 320 px */
.actions { display: flex; align-items: center; gap: 8px; padding: 8px 0 2px; }
.actions .btn { padding: 8px 10px; white-space: nowrap; }
/* under 360 px Share keeps its icon only, so the three stay on one line */
@media (max-width: 359px) { #btnShare span { display: none; } }
/* the game and its target, and the round button for card games and golf */
.gameRow { display: flex; gap: 8px; padding: 2px 0 6px; }
.gameBtn { flex: 1; min-width: 0; justify-content: flex-start; }
.gameBtn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gameRow .primary { flex: 0 0 auto; white-space: nowrap; }
.overLine { margin: 0 0 6px; padding: 8px 10px; border: 2px solid var(--accent); border-radius: 10px; font-weight: 700; }
.lastLine { min-height: 22px; font-size: 14px; color: var(--dim); padding: 0 2px 6px; }
.saveNote { margin: 0 0 8px; padding: 8px 10px; border: 2px solid #c0392b; border-radius: 10px; font-size: 14px; }

/* ---------- the players ---------- */
.players {
  display: grid; gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}
.card {
  border: 2px solid var(--line); border-left-width: 8px; border-radius: var(--radius);
  background: var(--bg2); padding: 8px 10px 10px;
  display: flex; flex-direction: column; gap: 6px;
}
.card.lead { border-color: var(--accent); }
/* a colour down the left edge tells cards apart at a glance; the name is what says who it is */
.card.c0 { border-left-color: #2a8f4e; }
.card.c1 { border-left-color: #2b6cc4; }
.card.c2 { border-left-color: #c2410c; }
.card.c3 { border-left-color: #8e44ad; }
.card.c4 { border-left-color: #b8860b; }
.card.c5 { border-left-color: #0f8b8d; }
.cardTop { display: flex; align-items: center; gap: 6px; min-width: 0; }
.name {
  flex: 1; min-width: 0; min-height: 44px; text-align: left;
  border: 0; background: transparent; color: inherit; font: inherit;
  font-size: 19px; font-weight: 700; cursor: pointer;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.crown { font-size: 24px; flex: 0 0 auto; }
.cardRow { display: flex; align-items: stretch; gap: 8px; }
.step {
  flex: 0 0 auto; min-width: 72px; min-height: 72px;
  border-radius: 14px; border: 2px solid var(--line);
  background: var(--bg); color: inherit; font: inherit; font-size: 26px; font-weight: 700;
  cursor: pointer; touch-action: manipulation;
}
.score {
  flex: 1; min-width: 0; min-height: 72px; padding: 0 4px;
  border-radius: 14px; border: 2px dashed var(--line);
  background: transparent; color: inherit; font: inherit;
  font-size: 46px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums;
  cursor: pointer; touch-action: manipulation;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
/* the rest of the game's one-tap amounts, under the score */
.tapRow { display: flex; gap: 8px; }
.tap {
  flex: 1 1 0; min-height: 52px;
  border-radius: 14px; border: 2px solid var(--line);
  background: var(--bg); color: inherit; font: inherit; font-size: 22px; font-weight: 700;
  cursor: pointer; touch-action: manipulation;
}
.tap:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
/* SR2: on a short phone (320 x 568) two cards with four one-tap amounts fit without scrolling */
@media (max-height: 700px) {
  .players { gap: 6px; }
  .card { gap: 4px; padding: 4px 10px 6px; }
  .step, .score { min-height: 52px; }
  .tap { min-height: 44px; }
  .gameRow { padding: 0 0 4px; }
  .overLine { padding: 2px 8px; margin-bottom: 4px; }
  .lastLine { padding-bottom: 2px; }
}
.addRow { padding: 10px 0; }
.addRow .btn { width: 100%; }

#footer { margin-top: auto; padding: 2px 0 4px; font-size: 12px; color: var(--dim); }

/* ---------- sheets (R-A7: an app's panel may cover the window) ---------- */
.sheet {
  /* --keys: how much of the window an on-screen keyboard covers (app.js) */
  position: fixed; inset: 0 0 var(--keys, 0px) 0; z-index: 40;
  display: flex; align-items: flex-end; justify-content: center;
  background: rgba(0, 0, 0, 0.45);
}
.sheetCard {
  width: 100%; min-width: 0; max-width: 520px; max-height: 92%; overflow-y: auto;
  background: var(--bg2); border-radius: 18px 18px 0 0;
  padding: 16px var(--pad) max(16px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 10px;
}
.sheetCard h2 { font-size: 18px; }
.sheetCard h3 { font-size: 15px; margin-top: 4px; }
.types { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.types .btn { justify-content: flex-start; text-align: left; font-size: 15px; }
.types .btn[aria-pressed="true"] { border-color: var(--accent); }
.taps { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.taps input { min-height: 48px; width: 100%; min-width: 0; padding: 6px; text-align: center;
  border-radius: 10px; border: 2px solid var(--line); background: var(--bg); color: var(--ink); font: inherit; font-size: 20px; font-weight: 700; }
.roundRow { display: flex; align-items: center; gap: 8px; }
.rname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.sign { flex: 0 0 auto; width: 44px; min-height: 48px; border-radius: 10px; border: 2px solid var(--line);
  background: var(--bg2); color: inherit; font: inherit; font-size: 22px; font-weight: 700; cursor: pointer; }
.roundRow input { flex: 0 0 104px; width: 104px; min-width: 0; min-height: 48px; padding: 6px 10px; text-align: center;
  border-radius: 10px; border: 2px solid var(--line); background: var(--bg); color: var(--ink); font: inherit; font-size: 22px; font-weight: 700; }
#roundRows { display: flex; flex-direction: column; gap: 6px; }
.sheetCard p { font-size: 15px; }
.hint { color: var(--dim); font-size: 13px; }
.now { color: var(--dim); }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row .btn { flex: 1 1 0; }
.quick .btn { min-width: 60px; font-size: 18px; }
.chk { display: flex; align-items: center; gap: 8px; min-height: 44px; }
.chk input { width: 22px; height: 22px; }

.lfield { display: grid; grid-template-columns: 64px 1fr; align-items: center; gap: 4px 10px; }
.lfield span { color: var(--dim); font-size: 14px; }
.lfield input, #pointsIn {
  min-height: 52px; padding: 8px 12px; width: 100%;
  border-radius: 10px; border: 2px solid var(--line);
  background: var(--bg); color: var(--ink); font: inherit; font-size: 22px;
}
#pointsIn { font-size: 30px; font-weight: 700; text-align: center; }

.log { list-style: none; display: flex; flex-direction: column; gap: 2px; max-height: 40vh; max-height: 40dvh; overflow-y: auto; }
.log li { font-size: 15px; padding: 4px 2px; border-bottom: 1px solid var(--line); }
.log li.empty { color: var(--dim); border: 0; }
#pastList { display: flex; flex-direction: column; gap: 8px; }
.pastGame { border: 2px solid var(--line); border-radius: 12px; padding: 8px 10px; }
.pastWhen { color: var(--dim); font-size: 13px; }
.pastRow { font-size: 15px; }

/* ---------- toast ---------- */
.toastHost {
  /* at the top: the panels and the keyboard are at the bottom */
  position: fixed; left: 50%; top: calc(10px + env(safe-area-inset-top)); z-index: 60;
  transform: translateX(-50%); max-width: 90%;
  padding: 10px 14px; border-radius: 12px;
  background: var(--ink); color: var(--bg); font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.toastHost.on { opacity: 1; }
@media (prefers-reduced-motion: reduce) { .toastHost { transition: none; } }
