:root {
  --bg: #f3f5f2;
  --card: #ffffff;
  --text: #15201a;
  --muted: #5f6b64;
  --line: #dde3de;
  --accent: #15803d;
  --accent-soft: #dcfce7;
  --header: #14532d;
  --bad: #b91c1c;
  --bad-soft: #fee2e2;
  --gold: #a16207;
  --gold-soft: #fef3c7;
  --radius: 16px;
  color-scheme: light;
}
/* Thème nuit : choisi avec le bouton ☀️/🌙 de l'en-tête (clair par défaut) */
:root[data-theme="dark"] {
  --bg: #0e1511;
  --card: #18221c;
  --text: #e8efe9;
  --muted: #9aa89f;
  --line: #2a3830;
  --accent: #4ade80;
  --accent-soft: #143822;
  --header: #0b2a18;
  --bad: #f87171;
  --bad-soft: #3b1717;
  --gold: #facc15;
  --gold-soft: #3a2f0b;
  color-scheme: dark;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
h1, h2, h3, p { margin: 0; }
small { font-size: .78rem; color: var(--muted); font-weight: 400; }

#app { max-width: 1100px; margin: 0 auto; padding-bottom: 96px; }
main { padding: 0 16px; }
.loading, .empty { text-align: center; color: var(--muted); padding: 48px 16px; }
.hint { font-size: .85rem; color: var(--muted); }
.center { text-align: center; margin-top: 12px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

/* En-tête */
.brand { font-size: 1.25rem; font-weight: 800; letter-spacing: -.01em; }
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--header); color: #fff;
  padding: 14px 16px; padding-top: max(14px, env(safe-area-inset-top));
}
.actions { display: flex; align-items: center; gap: 8px; min-width: 0; }
.theme {
  flex: none; border-radius: 999px; padding: 8px 12px; font-size: .88rem; font-weight: 600;
  background: rgba(255, 255, 255, .14); color: #fff; border: 0; white-space: nowrap;
}
.auth-theme { display: flex; justify-content: flex-end; padding: 14px 16px 0; }
.auth-theme .theme { background: var(--card); color: var(--text); border: 1px solid var(--line); }
.user {
  background: rgba(255, 255, 255, .14); color: #fff; border: 0; border-radius: 999px;
  padding: 8px 14px; min-width: 0; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* Les trois boutons */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; justify-content: center;
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  flex: 1; max-width: 213px; border: 0; background: none;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 10px 4px 12px; font-size: .85rem; font-weight: 600; color: var(--muted);
  border-top: 3px solid transparent;
}
.tabs .ico { font-size: 1.35rem; filter: grayscale(1); opacity: .7; }
.tabs [aria-current="true"] { color: var(--accent); border-top-color: var(--accent); }
.tabs [aria-current="true"] .ico { filter: none; opacity: 1; }

/* Choix de la semaine */
.weekbar { display: flex; gap: 8px; padding: 14px 16px; position: sticky; top: 0; z-index: 4; background: var(--bg); }
.weekbar button, .weekbar select {
  height: 46px; border: 1px solid var(--line); border-radius: 12px; background: var(--card);
}
.weekbar button { width: 46px; font-size: 1.5rem; line-height: 1; }
.weekbar button:disabled { opacity: .35; }
.weekbar select { flex: 1; min-width: 0; padding: 0 12px; font-weight: 700; text-align: center; text-align-last: center; }

.summary {
  padding: 10px 14px; border-radius: 12px; background: var(--card); border: 1px solid var(--line);
  font-size: .92rem; color: var(--muted);
}
.summary strong { color: var(--text); }
.summary.ok { background: var(--accent-soft); border-color: transparent; color: var(--text); }
.day { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 16px 4px 6px; }
.day::first-letter { text-transform: uppercase; }

/* Grille de matchs : 1 colonne sur mobile, 2 ou 3 sur grand écran */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 8px; align-items: start; }

/* Tuile de match (pronostics) */
.game { padding: 6px; }
.matchup { display: grid; grid-template-columns: 1fr 46px 1fr; align-items: stretch; gap: 4px; }
.mid { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; text-align: center; }
.when { font-size: .78rem; font-weight: 700; line-height: 1.2; }
.statbtn { border: 0; background: none; padding: 2px 6px; font-size: .9rem; border-radius: 8px; opacity: .55; }
.statbtn:hover, .game.open .statbtn { opacity: 1; background: var(--bg); }
.team {
  position: relative; min-width: 0; display: flex; align-items: center; gap: 7px;
  padding: 6px 7px; border: 2px solid var(--line); border-radius: 12px; background: none;
  transition: border-color .12s, background .12s, transform .08s;
}
.team.home { flex-direction: row-reverse; text-align: right; }
.team:not(:disabled):active { transform: scale(.97); }
.team:not(:disabled):hover { border-color: var(--accent); }
.team.picked { border-color: var(--accent); background: var(--accent-soft); }
.team:focus-visible, .btn:focus-visible, .tabs button:focus-visible, .statbtn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.logo {
  display: grid; place-items: center; flex: none;
  width: 34px; height: 34px; border-radius: 50%; background: #fff;
}
.logo { box-shadow: 0 0 0 1px var(--line); }
.top .brand { white-space: nowrap; }
.logo img { width: 82%; height: 82%; object-fit: contain; }
.tinfo { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.tname { font-weight: 800; font-size: .92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tname.long { font-size: .8rem; }
.trec { font-size: .75rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.team.picked::after {
  content: "✓"; position: absolute; top: -7px; right: -7px; width: 20px; height: 20px; border-radius: 50%;
  display: grid; place-items: center; background: var(--accent); color: var(--card); font-size: .72rem; font-weight: 800;
}
.team.home.picked::after { right: auto; left: -7px; }
.game.locked .team { opacity: .55; }
.game.locked .team.picked { opacity: 1; }

.stats { margin-top: 6px; }
.stats table { width: 100%; border-collapse: collapse; font-size: .85rem; table-layout: fixed; }
.stats td, .stats th { padding: 5px 4px; border-top: 1px solid var(--line); text-align: center; }
.stats thead th { border-top: 0; font-size: .9rem; }
.stats tbody th { font-weight: 400; color: var(--muted); font-size: .75rem; width: 44%; }
.stats td { font-weight: 700; font-variant-numeric: tabular-nums; }
.stats .hint { text-align: center; padding: 6px 4px 2px; font-size: .78rem; }

/* Résultats */
.result { padding: 8px 12px; }
.rhead { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: .78rem; color: var(--muted); margin-bottom: 2px; }
.live { color: var(--bad); font-weight: 700; }
.verdict { padding: 2px 8px; border-radius: 999px; font-weight: 700; white-space: nowrap; }
.verdict.good { background: var(--accent-soft); color: var(--accent); }
.verdict.bad { background: var(--bad-soft); color: var(--bad); }
.verdict.wait, .verdict.none { background: var(--bg); }
.rrow { display: flex; align-items: center; gap: 8px; padding: 3px 0; color: var(--muted); }
.rrow .logo { width: 28px; height: 28px; }
.rname { flex: 1; min-width: 0; font-size: .92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rrow.won { color: var(--text); }
.rrow.won .score { font-weight: 800; }
.score { font-size: 1.15rem; font-variant-numeric: tabular-nums; min-width: 2ch; text-align: right; }
.share { font-size: .75rem; font-variant-numeric: tabular-nums; }
.tag {
  display: inline-block; margin-left: 4px; padding: 0 6px; border-radius: 999px;
  border: 1px solid var(--accent); color: var(--accent); font-size: .68rem; font-weight: 700; white-space: nowrap;
}

/* Classement */
.seg { display: flex; padding: 4px; gap: 4px; background: var(--line); border-radius: 12px; margin-bottom: 14px; }
.seg button { flex: 1; border: 0; background: none; padding: 9px; border-radius: 9px; font-weight: 700; color: var(--muted); }
.seg [aria-selected="true"] { background: var(--card); color: var(--text); }
.banner {
  display: flex; align-items: center; gap: 14px; padding: 14px 16px; margin-bottom: 14px;
  border-radius: var(--radius); background: var(--gold-soft);
}
.banner .cup { font-size: 2.2rem; }
.banner small { display: block; color: var(--gold); font-weight: 700; }
.banner strong { font-size: 1.25rem; overflow-wrap: anywhere; }
.board { list-style: none; margin: 0; padding: 0; overflow: hidden; }
.board li { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--line); }
.board li:first-child { border-top: 0; }
.board .me { background: var(--accent-soft); }
.rank { width: 32px; text-align: center; font-weight: 800; font-size: 1.1rem; color: var(--muted); }
.pname { flex: 1; min-width: 0; font-weight: 700; overflow-wrap: anywhere; }
.pname small { display: block; }
.pts { font-size: 1.4rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.pts small { margin-left: 3px; }

/* Formulaires */
.auth { padding: 12vh 20px 40px; max-width: 420px; margin: 0 auto; }
.auth .brand { font-size: 2rem; text-align: center; }
.tagline { text-align: center; color: var(--muted); margin: 8px 0 24px; }
.form { display: flex; flex-direction: column; gap: 14px; }
.auth .form { padding: 20px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: .9rem; font-weight: 600; }
input {
  height: 48px; padding: 0 14px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--bg); font-size: 1rem;
}
input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.btn {
  min-height: 48px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); font-weight: 700;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--card); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: .82rem; }
.btn.danger { color: var(--bad); }
.form-error { color: var(--bad); font-size: .9rem; font-weight: 600; }

/* Compte */
dialog {
  width: min(480px, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
  border: 0; border-radius: var(--radius); padding: 20px; background: var(--card); color: var(--text);
}
dialog[open] { display: flex; flex-direction: column; gap: 20px; }
dialog::backdrop { background: rgba(0, 0, 0, .5); }
dialog h3 { font-size: 1rem; }
.dlg-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.dlg-head h2 { font-size: 1.2rem; overflow-wrap: anywhere; }
.close { border: 0; background: none; font-size: 1.2rem; padding: 8px; }
#admin { display: flex; flex-direction: column; gap: 10px; border-top: 1px solid var(--line); padding-top: 16px; }
.users { list-style: none; margin: 0; padding: 0; }
.users li { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 8px 0; border-top: 1px solid var(--line); }
.users li span { flex: 1; min-width: 120px; font-weight: 600; overflow-wrap: anywhere; }
.reset-result { padding: 10px 12px; border-radius: 10px; background: var(--gold-soft); font-size: .9rem; }
code { font-size: 1.05rem; font-weight: 700; user-select: all; }

#toast {
  position: fixed; left: 50%; bottom: 96px; transform: translate(-50%, 20px); z-index: 20;
  max-width: calc(100vw - 32px); padding: 10px 18px; border-radius: 999px;
  background: var(--text); color: var(--bg); font-size: .9rem; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: var(--bad); color: #fff; }

/* Classement et barre de semaine restent étroits sur grand écran */
.narrow, .weekbar { max-width: 640px; margin-left: auto; margin-right: auto; }

.summary .undo { display: block; margin-top: 2px; }

/* Question anti-spoiler */
.gate { padding: 28px 20px; margin-top: 12px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.gate-ico { font-size: 2.6rem; }
.gate h2 { font-size: 1.25rem; }
.gate p { color: var(--muted); }
.gate p strong { color: var(--bad); letter-spacing: .04em; }
.gate-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 8px; }

/* Points hors app (administration) */
.users .bonus { flex-basis: 100%; flex-direction: row; align-items: center; justify-content: space-between; gap: 8px; font-size: .8rem; font-weight: 400; color: var(--muted); }
.users .bonus span { display: flex; gap: 6px; flex: none; min-width: 0; }
.users .bonus input { width: 80px; height: 36px; padding: 0 8px; }
