:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --surface-2: #efebe4;
  --ink: #1d1b18;
  --muted: #6b655c;
  --line: #ddd6cb;
  --accent: #d2502d;
  --accent-ink: #ffffff;
  --good: #2f8f5b;
  --warn: #c98a12;
  --bad: #c0392b;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141311;
    --surface: #1e1c19;
    --surface-2: #2a2723;
    --ink: #f2eee8;
    --muted: #a39b8f;
    --line: #3a3631;
    --accent: #ff7a50;
    --accent-ink: #1a0f0a;
    --good: #5cc48a;
    --warn: #f0b440;
    --bad: #ff6b5a;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
a { color: inherit; }
.wrap { max-width: 760px; margin: 0 auto; padding: 16px; }
header.top {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 0 16px;
}
header.top a.back {
  text-decoration: none; font-size: 22px; width: 40px; height: 40px;
  display: grid; place-items: center; border-radius: 50%;
  background: var(--surface); box-shadow: var(--shadow);
}
header.top h1 { font-size: 24px; margin: 0; letter-spacing: -.01em; }
header.top .sub { color: var(--muted); font-size: 14px; }
.card {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px;
}
.card h2 { font-size: 17px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
button, .btn {
  font: inherit; border: 0; cursor: pointer; border-radius: 999px;
  padding: 12px 18px; background: var(--surface-2); color: var(--ink);
  min-height: 44px; text-decoration: none; display: inline-flex;
  align-items: center; justify-content: center; gap: 6px;
}
button.primary, .btn.primary { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.ghost { background: transparent; color: var(--muted); }
button.danger { color: var(--bad); }
button:disabled { opacity: .45; cursor: default; }
button:focus-visible, input:focus-visible, .chip:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.grow { flex: 1; }
input[type=text], input[type=number] {
  font: inherit; color: var(--ink); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
  min-height: 44px; width: 100%;
}
.players-list { display: grid; gap: 8px; margin-bottom: 12px; }
.players-list .row input { flex: 1; }

/* Tableau des scores */
.standings { display: grid; gap: 8px; }
.standing {
  display: grid; grid-template-columns: 28px 1fr auto; gap: 10px; align-items: center;
  padding: 10px 12px; border-radius: 12px; background: var(--surface-2);
}
.standing .rank { font-weight: 700; color: var(--muted); text-align: center; }
.standing .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.standing .total { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.standing .bar { grid-column: 2 / 4; height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.standing .bar span { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.standing.lead { outline: 2px solid var(--accent); }
.standing.lead .rank { color: var(--accent); }

.history { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 15px; }
.history-wrap { overflow-x: auto; }
.history th, .history td { padding: 8px 6px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
.history th:first-child, .history td:first-child { text-align: left; color: var(--muted); }
.history th { font-size: 13px; color: var(--muted); font-weight: 600; }
.history tfoot td { font-weight: 700; border-bottom: 0; }
.history td .tag { font-size: 11px; color: var(--warn); margin-left: 2px; }

.banner {
  border-radius: var(--radius); padding: 16px; margin-bottom: 16px;
  background: var(--accent); color: var(--accent-ink); font-weight: 600;
}
.banner.info { background: var(--surface-2); color: var(--ink); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; position: sticky; bottom: 0; padding: 12px 0; background: linear-gradient(transparent, var(--bg) 30%); }
.actions .primary { flex: 1; }

/* Saisie d'une manche */
dialog {
  border: 0; padding: 0; width: min(760px, 100vw); max-width: 100vw;
  max-height: 100dvh; margin: auto auto 0; border-radius: 20px 20px 0 0;
  background: var(--bg); color: var(--ink);
}
@media (min-width: 780px) { dialog { margin: auto; border-radius: 20px; max-height: 92dvh; } }
dialog::backdrop { background: rgba(0,0,0,.45); }
.dlg-head { position: sticky; top: 0; z-index: 1; background: var(--bg); padding: 16px 16px 8px; display: flex; align-items: center; gap: 8px; }
.dlg-head h2 { margin: 0; font-size: 19px; flex: 1; }
.dlg-body { padding: 0 16px 16px; }
.dlg-foot { position: sticky; bottom: 0; background: var(--bg); padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); display: flex; gap: 8px; border-top: 1px solid var(--line); }
.dlg-foot .primary { flex: 1; }
.entry { background: var(--surface); border-radius: var(--radius); padding: 12px; margin-bottom: 12px; box-shadow: var(--shadow); }
.entry-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.entry-head .name { font-weight: 700; flex: 1; }
.entry-head .score { font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; min-width: 3ch; text-align: right; }
.entry-head .score.zero { color: var(--bad); }
.chips { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-bottom: 8px; }
.chips.mods { grid-template-columns: repeat(6, 1fr); }
.chip {
  font: inherit; font-weight: 700; border-radius: 10px; min-height: 44px; padding: 0;
  background: var(--surface-2); color: var(--ink); border: 2px solid transparent;
  font-variant-numeric: tabular-nums;
}
.chip[aria-pressed=true] { background: var(--accent); color: var(--accent-ink); }
.chip.mod[aria-pressed=true] { background: var(--good); color: #fff; }
.toggle { display: flex; align-items: center; gap: 8px; min-height: 44px; cursor: pointer; }
.toggle input { width: 22px; height: 22px; accent-color: var(--accent); }
.note { font-size: 13px; color: var(--muted); }
.note.bonus { color: var(--good); font-weight: 600; }
.note.penalty { color: var(--warn); font-weight: 600; }
.radio-row { display: flex; align-items: center; gap: 8px; min-height: 44px; }
.radio-row input { width: 22px; height: 22px; accent-color: var(--accent); }

/* Accueil */
.games { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.game {
  display: block; text-decoration: none; background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px; position: relative; overflow: hidden;
}
.game .icon { font-size: 30px; font-weight: 800; width: 52px; height: 52px; border-radius: 14px; display: grid; place-items: center; margin-bottom: 12px; color: #fff; }
.game h2 { margin: 0 0 4px; font-size: 19px; }
.game p { margin: 0; color: var(--muted); font-size: 14px; }
.game .live { position: absolute; top: 14px; right: 14px; font-size: 12px; font-weight: 600; color: var(--good); }
.picker-result { font-size: 28px; font-weight: 800; text-align: center; padding: 12px; min-height: 64px; }
footer.foot { text-align: center; color: var(--muted); font-size: 13px; padding: 24px 0 8px; }
