:root {
  --fond: #fff; --panneau: #f6f6f9; --survol: #ebebf1; --ligne: #e2e2e9;
  --texte: #17171c; --discret: #656671; --accent: #5b48e0; --sur-accent: #fff; --danger: #c62828;
  --legendaire: #9a6200; --excellent: #7e22ce; --tresfun: #15803d; --sympa: #1d4ed8; --bof: #5f606a;
  --galere: var(--danger);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fond: #0f1014; --panneau: #17181e; --survol: #22242c; --ligne: #2f313b;
    --texte: #f3f3f6; --discret: #a3a4af; --accent: #9a8cff; --sur-accent: #14121f; --danger: #ff7b7b;
    --legendaire: #ffc857; --excellent: #c792ff; --tresfun: #5fd98a; --sympa: #77a7ff; --bof: #a9aab4;
  }
}
* { box-sizing: border-box; margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--fond); color: var(--texte);
  overscroll-behavior-y: none; -webkit-tap-highlight-color: transparent;
}
main {
  max-width: 600px; margin: 0 auto; min-height: 100dvh;
  padding: calc(18px + env(safe-area-inset-top)) calc(18px + env(safe-area-inset-right))
           calc(92px + env(safe-area-inset-bottom)) calc(18px + env(safe-area-inset-left));
  display: flex; flex-direction: column; gap: 16px;
}
h1 { font-size: 26px; line-height: 1.2; overflow-wrap: anywhere; }
h2 { font-size: 18px; margin-top: 8px; }
p { overflow-wrap: anywhere; }
.discret { color: var(--discret); font-size: 14px; }
.erreur { color: var(--danger); font-size: 14px; }
.pile { display: flex; flex-direction: column; gap: 12px; }
.rangee { display: flex; align-items: center; gap: 8px; }
.rangee.large { flex-wrap: wrap; }
.pousse { flex: 1; min-width: 0; overflow-wrap: anywhere; }

button, input { font: inherit; color: inherit; }
button {
  min-height: 44px; padding: 10px 16px; border: 0; border-radius: 12px;
  background: none; font-weight: 600; cursor: pointer; touch-action: manipulation;
}
button:active { background: var(--survol); }
button.principal { background: var(--accent); color: var(--sur-accent); }
button.secondaire { background: var(--panneau); }
button.danger { color: var(--danger); }
button:disabled { opacity: .45; cursor: default; }
button.petit { padding: 8px 10px; font-size: 14px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* 16 px minimum : en dessous, l'iPhone zoome sur le champ. */
input:not([type=range]):not([type=checkbox]) {
  width: 100%; min-height: 48px; padding: 10px 14px; font-size: 17px;
  border: 1px solid var(--ligne); border-radius: 12px; background: var(--panneau);
}
input::placeholder { color: var(--discret); opacity: 1; }
input[type=range] { width: 100%; height: 44px; margin: 0; accent-color: var(--couleur, var(--accent)); touch-action: pan-y; }

.entete { display: flex; align-items: center; gap: 14px; }
.score {
  flex: none; width: 112px; padding: 12px 6px; border-radius: 18px; text-align: center;
  color: var(--palier); font-weight: 700; font-size: 14px;
  background: color-mix(in srgb, var(--palier) 12%, var(--fond));
}
.score strong { display: block; font-size: 42px; line-height: 1.05; font-variant-numeric: tabular-nums; }
.collant { position: sticky; top: 0; z-index: 1; background: var(--fond);
  padding: calc(10px + env(safe-area-inset-top)) 0 10px; margin-top: calc(-10px - env(safe-area-inset-top)); }
.legendaire { --palier: var(--legendaire); } .excellent { --palier: var(--excellent); }
.tresfun { --palier: var(--tresfun); } .sympa { --palier: var(--sympa); }
.bof { --palier: var(--bof); } .galere { --palier: var(--galere); }

.critere { display: grid; grid-template-columns: 1fr auto; column-gap: 12px; align-items: center; }
.critere.negatif, .echelle.negatif { --couleur: var(--danger); }
.critere .nom { font-weight: 650; display: flex; align-items: center; gap: 6px; }
.critere .nom small { color: var(--discret); font-weight: 400; }
.critere output, .echelle output { font-size: 24px; font-weight: 700; min-width: 34px; text-align: right;
  color: var(--couleur, var(--accent)); font-variant-numeric: tabular-nums; }
.critere .discret, .critere input { grid-column: 1 / -1; }
button.aide { min-height: 44px; width: 44px; padding: 0; display: grid; place-items: center; margin: -8px 0; }
button.aide span { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center;
  background: var(--survol); color: var(--discret); font-size: 14px; }

.liste { display: flex; flex-direction: column; gap: 2px; margin: 0 -10px; padding: 0; list-style: none; }
.ligne { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px; border-radius: 12px; text-align: left; }
.ligne.moi { background: var(--panneau); }
.ligne .rang { width: 30px; flex: none; color: var(--discret); font-weight: 700; }
.ligne .rang.premier { color: var(--accent); }
.ligne .titre { flex: 1; min-width: 0; font-weight: 600; }
.ligne .titre span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ligne .titre small { color: var(--discret); font-weight: 400; }
.ligne .points { color: var(--palier); font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.moyenne { font-size: 48px; font-weight: 700; line-height: 1.1; color: var(--palier); }
.carte { background: var(--panneau); border-radius: 16px; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.vide { text-align: center; padding: 48px 16px; display: flex; flex-direction: column; gap: 8px; align-items: center; }

.reglage { display: flex; align-items: center; gap: 12px; min-height: 44px; font-weight: 600; }
.reglage input { appearance: none; -webkit-appearance: none; flex: none; width: 50px; height: 30px; margin: 0; border-radius: 15px;
  background: var(--discret); position: relative; transition: background .15s; }
.reglage input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px;
  border-radius: 50%; background: #fff; transition: transform .15s; }
.reglage input:checked { background: var(--accent); }
.reglage input:checked::after { transform: translateX(20px); }
.reglage input:disabled { opacity: .45; }

nav {
  position: fixed; inset: auto 0 0; z-index: 2; display: flex; justify-content: center;
  padding: 6px calc(8px + env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) calc(8px + env(safe-area-inset-left));
  background: var(--panneau); border-top: 1px solid var(--ligne);
}
nav button { flex: 1; max-width: 190px; min-height: 52px; padding: 6px 4px; color: var(--discret); font-size: 15px; }
nav button[aria-current=page] { color: var(--accent); background: var(--survol); }

dialog {
  width: 100%; max-width: 600px; max-height: 88dvh; margin: auto auto 0; border: 0;
  border-radius: 22px 22px 0 0; background: var(--fond); color: var(--texte); overflow-y: auto;
  padding: 20px calc(18px + env(safe-area-inset-right)) calc(18px + env(safe-area-inset-bottom)) calc(18px + env(safe-area-inset-left));
}
dialog::backdrop { background: rgb(0 0 0 / .5); }
.niveau { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px; }
.niveau b { width: 42px; flex: none; color: var(--discret); }
.niveau.actif { background: var(--survol); }
.niveau.actif b { color: var(--couleur, var(--accent)); }
.niveau strong { display: block; font-weight: 600; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
