:root {
  --bg: #f4f2fb;
  --card: #ffffff;
  --text: #1d1838;
  --muted: #736c94;
  --border: #e6e2f5;
  --soft: #efecfb;
  --primary: #5b3df5;
  --primary-2: #9b3df5;
  --grad: linear-gradient(120deg, #5b3df5 0%, #b23df5 55%, #ff6a5c 100%);
  --win: #fff4cf;
  --win-border: #f5b700;
  --danger: #e5484d;
  --ok: #18a058;
  --shadow: 0 6px 20px rgba(60, 40, 160, .08);
  /* couleurs des joueurs */
  --p0: #5b3df5; --p1: #ff6a5c; --p2: #12b886; --p3: #f59f00;
  --p4: #1c9cf0; --p5: #e64ab0; --p6: #7c5c3b; --p7: #2f9e44;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0d1a;
    --card: #1a1730;
    --text: #ece9ff;
    --muted: #a39cc8;
    --border: #2d2850;
    --soft: #241f42;
    --win: #3a3115;
    --shadow: 0 6px 20px rgba(0, 0, 0, .35);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); font-size: 16px;
  padding-bottom: calc(80px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}
.hidden { display: none !important; }

/* ---------- En-tête ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; justify-content: space-between; align-items: center;
  background: var(--grad); color: #fff;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  box-shadow: 0 4px 18px rgba(91, 61, 245, .3);
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 1.15rem; font-weight: 600; letter-spacing: .2px; }
.brand img { width: 32px; height: 32px; border-radius: 9px; box-shadow: 0 2px 6px rgba(0,0,0,.2); }
.brand b { font-weight: 800; }
.who { background: rgba(255,255,255,.2); padding: 4px 10px; border-radius: 999px; font-size: .85rem; font-weight: 600; }

.hero { text-align: center; padding: 22px 0 8px; }
.hero img { width: 96px; height: 96px; border-radius: 26px; box-shadow: var(--shadow); }
.hero h1 { margin: 12px 0 2px; font-size: 1.7rem; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero p { margin: 0; color: var(--muted); }

/* ---------- Mise en page ---------- */
.view { max-width: 720px; margin: 0 auto; padding: 12px; }
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 18px; padding: 14px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.title { font-size: 1.1rem; margin: 0 0 8px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row2 > label { margin-top: 0; }
.filters { padding: 10px; }
.actions { margin-top: 6px; }
.actions .btn { margin-top: 6px; }
label, .label { display: block; font-weight: 600; margin: 10px 0 4px; font-size: .92rem; }
label input, label select { margin-top: 4px; }
input, select {
  width: 100%; font: inherit; color: var(--text);
  background: var(--soft); border: 1.5px solid transparent;
  border-radius: 12px; padding: 10px 12px; min-height: 44px;
}
input:focus, select:focus { outline: none; border-color: var(--primary); background: var(--card); }
form > input { margin-top: 8px; }
.hint { color: var(--muted); font-size: .84rem; font-weight: 400; margin: 6px 0; }

/* ---------- Boutons ---------- */
.btn {
  display: block; width: 100%; margin-top: 12px;
  font: inherit; font-weight: 700; min-height: 46px;
  border-radius: 14px; border: 1.5px solid var(--border);
  background: var(--card); color: var(--text); cursor: pointer;
}
.btn.primary { background: var(--grad); color: #fff; border: none; box-shadow: 0 4px 14px rgba(91,61,245,.3); }
.btn.ghost { background: var(--soft); border-color: transparent; color: var(--primary); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.small { width: auto; min-height: 36px; padding: 0 14px; font-size: .88rem; border-radius: 10px; display: inline-block; }
.btn:active { transform: scale(.98); }

/* Contrôle segmenté */
.seg { display: flex; gap: 4px; background: var(--soft); padding: 4px; border-radius: 14px; }
.seg button {
  flex: 1; font: inherit; font-size: .88rem; font-weight: 600; padding: 9px 4px;
  border: none; border-radius: 10px; background: transparent; color: var(--muted); cursor: pointer;
}
.seg button.active { background: var(--card); color: var(--primary); box-shadow: 0 2px 8px rgba(60,40,160,.12); }
.sticky-seg { position: sticky; top: 64px; z-index: 10; margin-bottom: 12px; box-shadow: var(--shadow); background: var(--card); border: 1px solid var(--border); }
.sticky-seg button.active { background: var(--grad); color: #fff; }

/* ---------- Couleurs joueurs ---------- */
.pc0 { --pc: var(--p0); } .pc1 { --pc: var(--p1); } .pc2 { --pc: var(--p2); } .pc3 { --pc: var(--p3); }
.pc4 { --pc: var(--p4); } .pc5 { --pc: var(--p5); } .pc6 { --pc: var(--p6); } .pc7 { --pc: var(--p7); }
.avatar {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 30px; height: 30px; border-radius: 50%; background: var(--pc); color: #fff;
  font-weight: 800; font-size: .85rem;
}
.avatar.big { width: 52px; height: 52px; font-size: 1.3rem; }

/* Puces joueurs */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px 4px 4px;
  border-radius: 999px; border: 2px solid var(--border); background: var(--card);
  font: inherit; font-weight: 600; color: var(--muted); cursor: pointer;
}
.chip .avatar { width: 26px; height: 26px; font-size: .75rem; opacity: .45; }
.chip.on { border-color: var(--pc); color: var(--text); background: var(--soft); }
.chip.on .avatar { opacity: 1; }

/* ---------- Feuille de score ---------- */
.score-head { display: flex; justify-content: space-between; align-items: center; }
.score-head .btn { margin: 0; }
.table-wrap { overflow-x: auto; margin: 6px -14px 0; padding: 0 14px; }
table.sheet { border-collapse: separate; border-spacing: 4px; min-width: 100%; }
.sheet th, .sheet td { padding: 0; text-align: center; }
.sheet th.num, .sheet td.num { width: 26px; color: var(--muted); font-size: .8rem; position: sticky; left: 0; background: var(--card); z-index: 1; }
.sheet thead th.pl { min-width: 74px; }
.sheet .colhead {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 2px;
  border-radius: 12px; background: var(--soft); border-top: 4px solid var(--pc);
  font-size: .82rem; font-weight: 700; max-width: 110px; margin: 0 auto;
}
.sheet .colhead span.n { max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet input {
  min-height: 40px; padding: 6px 4px; text-align: center; border-radius: 10px;
  background: var(--soft); min-width: 64px; font-variant-numeric: tabular-nums;
}
.sheet tfoot td.tot {
  font-weight: 800; font-size: 1.1rem; padding: 8px 2px; border-radius: 12px;
  background: color-mix(in srgb, var(--pc) 14%, var(--card)); color: var(--text);
}
.sheet tfoot td.tot.win { background: var(--win); outline: 2px solid var(--win-border); }
.trophy {
  border: none; background: transparent; font-size: 1.25rem; cursor: pointer;
  filter: grayscale(1); opacity: .3; padding: 4px; min-height: 36px;
}
.trophy.on { filter: none; opacity: 1; }
.empty-sheet { text-align: center; color: var(--muted); padding: 18px 6px; }

/* ---------- Ludothèque ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.game-card {
  position: relative; overflow: hidden; border-radius: 18px; padding: 14px 12px 12px;
  background: var(--card); border: 1px solid var(--border); box-shadow: var(--shadow);
  text-align: left; font: inherit; color: var(--text); cursor: pointer;
}
.game-card::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 6px; background: var(--pc); }
.game-card .gname { font-weight: 800; font-size: 1rem; margin: 4px 0 6px; word-break: break-word; }
.game-card .gmeta { color: var(--muted); font-size: .8rem; }
.tag { display: inline-block; font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--soft); color: var(--primary); margin-bottom: 4px; }

/* ---------- Historique ---------- */
.match .mhead { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.match .mgame { font-weight: 800; }
.match .mdate { color: var(--muted); font-size: .82rem; white-space: nowrap; }
.match ol { list-style: none; padding: 0; margin: 10px 0 0; }
.match li { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 12px; }
.match li .pn { flex: 1; font-weight: 600; }
.match li .ps { font-weight: 800; font-variant-numeric: tabular-nums; }
.match li.win { background: var(--win); }
.match .mnotes { color: var(--muted); font-size: .85rem; margin-top: 8px; font-style: italic; }
.match details { margin-top: 8px; }
.match summary { color: var(--primary); font-weight: 600; font-size: .88rem; cursor: pointer; }
.mini { width: 100%; border-collapse: collapse; font-size: .85rem; margin-top: 6px; }
.mini th, .mini td { padding: 4px; text-align: center; border-bottom: 1px solid var(--border); }
.mini tfoot td { font-weight: 800; border-bottom: none; }
.link-del { background: none; border: none; color: var(--danger); font: inherit; font-size: .85rem; padding: 8px 0 0; cursor: pointer; }

/* ---------- Stats ---------- */
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 12px; }
.kpi { border-radius: 18px; padding: 14px; color: #fff; box-shadow: var(--shadow); }
.kpi .v { font-size: 1.7rem; font-weight: 800; line-height: 1.1; word-break: break-word; }
.kpi .v.sm { font-size: 1.15rem; }
.kpi .l { font-size: .82rem; opacity: .9; }
.k1 { background: linear-gradient(135deg, #5b3df5, #8f6bff); }
.k2 { background: linear-gradient(135deg, #ff6a5c, #ff9f5c); }
.k3 { background: linear-gradient(135deg, #12b886, #4fd1a5); }
.k4 { background: linear-gradient(135deg, #e64ab0, #b23df5); }

.podium { display: flex; align-items: flex-end; gap: 8px; margin-top: 4px; }
.podium .step { flex: 1; text-align: center; }
.podium .block { border-radius: 14px 14px 6px 6px; margin-top: 6px; padding: 8px 4px; color: #fff; font-weight: 800; }
.podium .s1 .block { background: linear-gradient(180deg, #f5b700, #f08c00); height: 92px; }
.podium .s2 .block { background: linear-gradient(180deg, #adb5bd, #868e96); height: 70px; }
.podium .s3 .block { background: linear-gradient(180deg, #e8916b, #c0663f); height: 54px; }
.podium .pn { font-weight: 700; font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 4px; }

table.stats { width: 100%; border-collapse: collapse; font-size: .92rem; }
.stats th, .stats td { padding: 8px 4px; text-align: center; border-bottom: 1px solid var(--border); }
.stats th:first-child, .stats td:first-child { text-align: left; }
.stats th { color: var(--muted); font-weight: 700; font-size: .75rem; text-transform: uppercase; letter-spacing: .3px; }
.stats tr:last-child td { border-bottom: none; }
.who-cell { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.who-cell .avatar { width: 24px; height: 24px; font-size: .7rem; }
.bar { height: 6px; background: var(--soft); border-radius: 3px; overflow: hidden; min-width: 40px; }
.bar > i { display: block; height: 100%; background: var(--pc, var(--primary)); border-radius: 3px; }
.v-win { color: var(--ok); font-weight: 800; }
.v-loss { color: var(--danger); font-weight: 700; }

.period-title { display: flex; justify-content: space-between; align-items: baseline; }
.period-title h3 { margin: 0; font-size: 1rem; text-transform: capitalize; }
.period-title span { color: var(--muted); font-size: .85rem; }

.form-dots { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 6px; }
.dot { width: 22px; height: 22px; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center; font-size: .7rem; font-weight: 800; color: #fff; }
.dot.w { background: var(--ok); }
.dot.l { background: var(--danger); opacity: .75; }
.player-head { display: flex; align-items: center; gap: 12px; }
.player-head h3 { margin: 0; font-size: 1.2rem; }
.player-head p { margin: 2px 0 0; color: var(--muted); font-size: .85rem; }

/* ---------- Gérer ---------- */
.list { list-style: none; padding: 0; margin: 0; }
.list li { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.list li:last-child { border-bottom: none; }
.list .pn { flex: 1; font-weight: 600; }
.badge { font-size: .72rem; font-weight: 700; border-radius: 999px; padding: 2px 9px; background: var(--soft); color: var(--muted); }
.badge.admin { background: var(--grad); color: #fff; }
.mini-btn { font: inherit; font-size: .78rem; font-weight: 700; border: 1px solid var(--border); background: var(--card); color: var(--primary); border-radius: 8px; padding: 5px 8px; cursor: pointer; }
.mini-btn.del { color: var(--danger); }
.inline { display: flex; gap: 8px; margin-top: 10px; }
.inline input { flex: 1; margin: 0; }
.inline .btn { width: auto; margin: 0; padding: 0 16px; white-space: nowrap; }

/* ---------- Fenêtre modale ---------- */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(20, 12, 50, .45); display: flex; align-items: flex-end; justify-content: center; }
.sheet-modal {
  width: 100%; max-width: 560px; background: var(--card); border-radius: 22px 22px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); box-shadow: 0 -8px 30px rgba(0,0,0,.2);
}

/* ---------- Barre de navigation ---------- */
.nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: flex; background: var(--card); border-top: 1px solid var(--border);
  padding: 4px 4px env(safe-area-inset-bottom); box-shadow: 0 -4px 18px rgba(60,40,160,.08);
}
.nav button {
  flex: 1; background: none; border: none; color: var(--muted); cursor: pointer;
  font: inherit; font-size: .68rem; font-weight: 600; padding: 6px 0 8px;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
}
.nav svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.nav svg .fill { fill: currentColor; stroke: none; }
.nav button.active { color: var(--primary); }
.nav button.active svg { background: var(--soft); border-radius: 10px; padding: 2px; width: 40px; height: 28px; }

.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.empty b { display: block; font-size: 2rem; margin-bottom: 6px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(92px + env(safe-area-inset-bottom)); z-index: 60;
  background: #231c45; color: #fff; padding: 11px 18px; border-radius: 14px; font-weight: 600;
  max-width: 90vw; box-shadow: 0 6px 20px rgba(0,0,0,.25);
}
.toast.error { background: var(--danger); }
.who:empty { display: none; }

/* Filtre de période (stats) */
#range-presets .chip { padding: 6px 12px; font-size: .9rem; }
#range-presets .chip.on { border-color: var(--primary); background: var(--primary); color: #fff; }
.range-card .row2 { margin-top: 4px; }
