/* Family Games — mobile-first PWA. Theme via [data-theme] on <html>. */
:root {
  --bg: #f4f5fb; --card: #ffffff; --ink: #1c1e2b; --muted: #6b6f85;
  --line: #e3e5ef; --accent: #4a5486; --accent-ink: #fff;
  --pos: #2e7d4f; --neg: #c0392b; --gold: #caa64a;
  --shadow: 0 2px 10px rgba(30,32,52,.08);
  --radius: 16px; --tap: 48px;
}
html[data-theme="twilight"]  { --bg:#1a1c2e; --card:#262a44; --ink:#eef0fb; --muted:#a2a7c8; --line:#343a5c; --accent:#7c86d6; --accent-ink:#12142a; }
html[data-theme="forest"]    { --bg:#12211a; --card:#1c3227; --ink:#eafaf0; --muted:#9fc4ae; --line:#28483a; --accent:#5fbf87; --accent-ink:#08160f; }
html[data-theme="sunset"]    { --bg:#2a1720; --card:#3d2130; --ink:#ffeef4; --muted:#d8a7ba; --line:#552e42; --accent:#f0805f; --accent-ink:#2a0f16; }
html[data-theme="midnight"]  { --bg:#0a0d1a; --card:#151a30; --ink:#e8ecff; --muted:#8892c0; --line:#232a4a; --accent:#5b8dff; --accent-ink:#050810; }
html[data-theme="bubblegum"] { --bg:#fdeef6; --card:#ffffff; --ink:#3a1030; --muted:#9c6a8c; --line:#f6d4e6; --accent:#e0559e; --accent-ink:#fff; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--ink); font-size: 16px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
  overscroll-behavior-y: contain;
}
#topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center;
  gap: 8px; padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
  background: var(--card); border-bottom: 1px solid var(--line); box-shadow: var(--shadow);
}
#topTitle { flex: 1; font-weight: 800; font-size: 1.1rem; text-align: center; }
.icon-btn {
  min-width: var(--tap); height: var(--tap); border: none; background: transparent;
  color: var(--ink); font-size: 1.5rem; border-radius: 12px; cursor: pointer;
}
.icon-btn:active { background: var(--line); }
main#app { padding: 14px; max-width: 640px; margin: 0 auto; }
.loading { text-align: center; color: var(--muted); padding: 40px; }
.hidden { display: none !important; }

h2.section { font-size: .82rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); margin: 22px 4px 10px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px; margin-bottom: 12px; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 18px; border-radius: 14px; border: none;
  background: var(--accent); color: var(--accent-ink); font-size: 1rem; font-weight: 700;
  cursor: pointer; width: 100%; }
.btn:active { filter: brightness(.92); }
.btn.ghost { background: transparent; color: var(--ink); border: 1.5px solid var(--line); }
.btn.sm { min-height: 40px; width: auto; padding: 0 14px; font-size: .9rem; }
.btn.danger { background: var(--neg); color: #fff; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }

/* game grid */
.game-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.game-tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px 12px; text-align: center; cursor: pointer; }
.game-tile:active { transform: scale(.97); }
.game-tile .emoji { font-size: 2.2rem; line-height: 1.2; }
.game-tile .gname { font-weight: 700; margin-top: 6px; font-size: .98rem; }
.game-tile .gmeta { color: var(--muted); font-size: .78rem; margin-top: 3px; }

/* list rows */
.list-row { display: flex; align-items: center; gap: 12px; padding: 12px 4px;
  border-bottom: 1px solid var(--line); }
.list-row:last-child { border-bottom: none; }
.dot { width: 14px; height: 14px; border-radius: 50%; flex: none; }
.grow { flex: 1; min-width: 0; }
.grow .sub { color: var(--muted); font-size: .82rem; }
.pill { font-size: .72rem; padding: 3px 9px; border-radius: 999px; background: var(--line); color: var(--muted); }
.pill.win { background: var(--gold); color: #2a2000; font-weight: 700; }

/* inputs */
input[type=text], input[type=number], input[type=email], input[type=tel], select {
  width: 100%; min-height: var(--tap); padding: 0 14px; font-size: 1rem;
  border: 1.5px solid var(--line); border-radius: 12px; background: var(--bg); color: var(--ink);
}
label.fld { display: block; margin: 12px 0 6px; font-weight: 600; font-size: .9rem; }
.hint { color: var(--muted); font-size: .82rem; margin-top: 4px; }

.grp-label { font-size:.8rem; font-weight:700; color:var(--muted); text-transform:uppercase;
  letter-spacing:.05em; margin:14px 4px 6px; }

/* player picker chips */
.chip { display: inline-flex; align-items: center; gap: 8px; padding: 9px 14px;
  border-radius: 999px; border: 2px solid var(--line); background: var(--card);
  font-weight: 600; cursor: pointer; margin: 0 8px 8px 0; }
.chip.sel { border-color: var(--accent); background: var(--accent); color: var(--accent-ink); }
.chip .dot { width: 12px; height: 12px; }

/* scoreboard */
.score-player { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 12px; margin-bottom: 12px; }
.score-head { display: flex; align-items: center; gap: 10px; }
.score-head .pname { font-weight: 800; font-size: 1.05rem; flex: 1; }
.score-head .rank { font-size: .78rem; color: var(--muted); }
.score-total { font-size: 2rem; font-weight: 900; font-variant-numeric: tabular-nums; }
.score-total.leader { color: var(--gold); }
.steppers { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-top: 10px; }
.step-btn { min-height: 44px; border-radius: 10px; border: 1.5px solid var(--line);
  background: var(--bg); color: var(--ink); font-weight: 700; font-size: .95rem; cursor: pointer; }
.step-btn.plus:active { background: var(--pos); color: #fff; }
.step-btn.minus { color: var(--neg); }
.step-btn.minus:active { background: var(--neg); color: #fff; }
.step-mode { display:flex; gap:6px; margin-top:8px; }
.step-mode button { flex:1; min-height:38px; border-radius:10px; border:1.5px solid var(--line);
  background:var(--bg); color:var(--muted); font-weight:700; cursor:pointer; }
.step-mode button.on { background:var(--accent); color:var(--accent-ink); border-color:var(--accent); }
/* slider score entry */
.slider-row { display:flex; align-items:center; gap:12px; margin-top:12px; }
.pslider { -webkit-appearance:none; appearance:none; flex:1; height:14px; border-radius:999px;
  background:var(--line); outline:none; }
.pslider::-webkit-slider-thumb { -webkit-appearance:none; appearance:none; width:34px; height:34px;
  border-radius:50%; background:var(--c,var(--accent)); border:3px solid var(--card);
  box-shadow:var(--shadow); cursor:pointer; }
.pslider::-moz-range-thumb { width:34px; height:34px; border-radius:50%; background:var(--c,var(--accent));
  border:3px solid var(--card); box-shadow:var(--shadow); cursor:pointer; }
.slider-val { min-width:58px; text-align:right; font-size:1.5rem; font-weight:900;
  font-variant-numeric:tabular-nums; }
.step-chips { display:flex; gap:8px; margin-top:10px; }
.step-chips .chip { flex:1; justify-content:center; margin:0; font-size:1.05rem; padding:12px 0; }
.round-strip { display:flex; gap:4px; flex-wrap:wrap; margin-top:8px; }
.round-strip .rv { font-size:.75rem; color:var(--muted); background:var(--bg);
  border:1px solid var(--line); border-radius:8px; padding:2px 7px; font-variant-numeric:tabular-nums; }

/* round scorer */
.grid-wrap { overflow-x:auto; -webkit-overflow-scrolling:touch; border-radius:14px; }
.score-grid { border-collapse:collapse; width:100%; background:var(--card); font-variant-numeric:tabular-nums; }
.score-grid th, .score-grid td { padding:8px 10px; text-align:center; border-bottom:1px solid var(--line); font-size:.95rem; }
.score-grid thead th { position:sticky; top:0; background:var(--card); }
.score-grid .dot { display:inline-block; width:14px; height:14px; }
.score-grid td:first-child, .score-grid th:first-child { color:var(--muted); font-size:.8rem; }
.score-grid tr.rrow { cursor:pointer; }
.score-grid tr.rrow:active { background:var(--line); }
.score-grid .totrow td { font-weight:900; border-top:2px solid var(--line); border-bottom:none; }
.score-grid .tot.lead { color:var(--gold); }

.round-row { padding:12px 0; border-bottom:1px solid var(--line); }
.round-row:last-of-type { border-bottom:none; }
.rr-head { display:flex; align-items:center; gap:8px; margin-bottom:8px; }
.rr-head .dot { width:14px; height:14px; }
.rr-name { flex:1; font-weight:700; }
.rr-val { font-size:1.4rem; font-weight:900; font-variant-numeric:tabular-nums; min-width:46px; text-align:right; }
.rr-fields { display:flex; gap:8px; flex-wrap:wrap; align-items:flex-end; }
.rr-fields label { display:flex; flex-direction:column; font-size:.72rem; color:var(--muted); gap:3px; flex:1; min-width:64px; }
.rr-fields input[type=number] { min-height:44px; }
.rr-fields.ranks { gap:6px; }
.tog { min-height:44px; padding:0 12px; border-radius:10px; border:1.5px solid var(--line);
  background:var(--bg); color:var(--ink); font-weight:700; font-size:.9rem; cursor:pointer; flex:1; min-width:64px; }
.tog.on { background:var(--accent); color:var(--accent-ink); border-color:var(--accent); }
.tog.moon.on { background:#5b4b8a; color:#fff; border-color:#5b4b8a; }
.tog.bust.on { background:var(--neg); color:#fff; border-color:var(--neg); }
.ranks .tog { flex:1; padding:0 6px; }
.cntr-wrap { display:flex; flex-direction:column; align-items:center; gap:3px; flex:1; min-width:64px; }
.cntr-lbl { font-size:.72rem; color:var(--muted); }
.cntr { width:100%; min-height:52px; border-radius:12px; border:1.5px solid var(--line);
  background:var(--bg); color:var(--ink); font-size:1.5rem; font-weight:900; cursor:pointer;
  font-variant-numeric:tabular-nums; touch-action:none; user-select:none; -webkit-user-select:none;
  -webkit-touch-callout:none; }
.cntr:active { background:var(--accent); color:var(--accent-ink); border-color:var(--accent); }
.bonus-btns { display:flex; gap:6px; flex-wrap:wrap; margin-top:8px; }
.bonus-btns .tog { flex:0 1 auto; min-width:0; padding:0 10px; min-height:38px; font-size:.8rem; }

/* ring-of-dots board */
.ring { position:relative; width:100%; max-width:360px; aspect-ratio:1/1; margin:18px auto;
  border-radius:50%; background:var(--card); border:1px solid var(--line);
  box-shadow:var(--shadow) inset; touch-action:none; user-select:none; -webkit-user-select:none; }
.ring-center { position:absolute; left:50%; top:50%; transform:translate(-50%,-50%);
  text-align:center; pointer-events:none; width:44%; }
.rc-name { display:block; font-weight:800; font-size:1.05rem; }
.rc-val { display:block; font-weight:900; font-size:1.6rem; font-variant-numeric:tabular-nums; }
.rdot { position:absolute; transform:translate(-50%,-50%); width:clamp(56px,20vw,76px); height:clamp(56px,20vw,76px);
  border-radius:50%; display:flex; flex-direction:column; align-items:center; justify-content:center;
  color:#fff; box-shadow:var(--shadow); cursor:pointer; touch-action:none; }
.rdot-name { font-size:.62rem; font-weight:700; max-width:90%; overflow:hidden; text-overflow:ellipsis;
  white-space:nowrap; text-shadow:0 1px 2px rgba(0,0,0,.4); }
.rdot-score { font-size:1.15rem; font-weight:900; font-variant-numeric:tabular-nums; text-shadow:0 1px 2px rgba(0,0,0,.4); }
.rdot.active { outline:4px solid var(--ink); z-index:3; transform:translate(-50%,-50%) scale(1.12); }
.rdot.lead { box-shadow:0 0 0 3px var(--gold), var(--shadow); }

/* toast + sheet */
.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 12px 20px;
  border-radius: 999px; font-weight: 600; z-index: 60; box-shadow: var(--shadow); max-width: 90%; }
.sheet { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50; display: flex;
  align-items: flex-end; justify-content: center; }
#sheetInner { background: var(--card); width: 100%; max-width: 640px; border-radius: 22px 22px 0 0;
  padding: 20px 18px calc(24px + env(safe-area-inset-bottom)); max-height: 88vh; overflow-y: auto; }
.sheet-title { font-weight: 800; font-size: 1.15rem; margin-bottom: 6px; }
.center { text-align: center; }
.big-num { font-size: 2.6rem; font-weight: 900; }
a.link { color: var(--accent); text-decoration: none; font-weight: 600; }
.empty { color: var(--muted); text-align: center; padding: 24px; }
