:root {
  /* Couleurs du thème (remplacées par themes.js selon le thème choisi) */
  --brand-l: #1f7a4d;   /* couleur principale, mode clair */
  --brand-d: #3fb27a;   /* couleur principale, mode sombre */
  --accent: #d4e83a;
  --hero2: #145236;
  --bg: #f4f6f3;
  --surface: #ffffff;
  --surface-2: #eef2ec;
  --text: #17201a;
  --muted: #5d6b61;
  --border: #d9e0d6;
  --brand: var(--brand-l);
  --brand-ink: #ffffff;
  --warn: #b85c00;
  --warn-bg: #fff3e0;
  --danger: #b3261e;
  --info-bg: #e6f2ff;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 14px rgba(0,0,0,.05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-mode="light"]) {
    --bg: #0f1411; --surface: #18201b; --surface-2: #212b25; --text: #e8efe9; --muted: #9aaa9f;
    --border: #2d3a32; --brand: var(--brand-d); --brand-ink: #06140c; --warn: #ffb35c; --warn-bg: #3a2a14;
    --danger: #ff8a80; --info-bg: #15283a; --shadow: none; color-scheme: dark;
  }
}
:root[data-mode="dark"] {
  --bg: #0f1411; --surface: #18201b; --surface-2: #212b25; --text: #e8efe9; --muted: #9aaa9f;
  --border: #2d3a32; --brand: var(--brand-d); --brand-ink: #06140c; --warn: #ffb35c; --warn-bg: #3a2a14;
  --danger: #ff8a80; --info-bg: #15283a; --shadow: none; color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  -webkit-text-size-adjust: 100%;
}
a { color: var(--brand); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .6em; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }

/* ---- barre du haut ---- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; background: var(--brand); color: var(--brand-ink);
}
.topbar a { color: inherit; text-decoration: none; }
.logo { font-weight: 800; font-size: 1.15rem; display: flex; align-items: center; gap: 8px; }
.logo .ball { width: 22px; height: 22px; border-radius: 50%; background: var(--accent);
  background-image: radial-gradient(circle at 30% 30%, rgba(0,0,0,.25) 2px, transparent 3px),
    radial-gradient(circle at 70% 40%, rgba(0,0,0,.25) 2px, transparent 3px),
    radial-gradient(circle at 45% 72%, rgba(0,0,0,.25) 2px, transparent 3px); }
.topbar nav { margin-left: auto; display: flex; gap: 4px; align-items: center; }
.topbar nav a, .topbar nav button {
  padding: 8px 12px; border-radius: 8px; background: transparent; border: 0; color: inherit; font: inherit; cursor: pointer;
}
.topbar nav a:hover, .topbar nav button:hover, .topbar nav a.active { background: rgba(255,255,255,.16); }
.menu-btn { display: none; }

main { max-width: 1100px; margin: 0 auto; padding: 20px 16px 80px; }

/* ---- composants ---- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; }
.hidden { display: none !important; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 10px 16px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 34px; padding: 6px 10px; font-size: .9rem; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 4px; }
input, select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
.field { margin-bottom: 14px; }
.field .hint { font-size: .8rem; color: var(--muted); margin-top: 4px; font-weight: 400; }
.checkbox { display: flex; gap: 8px; align-items: center; font-weight: 500; }
.checkbox input { width: 20px; min-height: 20px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .78rem; font-weight: 700; background: var(--surface-2); color: var(--muted); }
.badge.active { background: var(--brand); color: var(--brand-ink); }
.badge.planned { background: var(--info-bg); color: var(--text); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.private { background: var(--surface-2); }

.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--border); margin-bottom: 16px; scrollbar-width: none; }
.tabs button { flex: none; padding: 10px 14px; border: 0; background: none; font: inherit; font-weight: 600; color: var(--muted); border-bottom: 3px solid transparent; cursor: pointer; }
.tabs button.on { color: var(--brand); border-color: var(--brand); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }

.hero { padding: 28px 20px; border-radius: var(--radius); background: linear-gradient(135deg, var(--brand-l), var(--hero2)); color: #fff; margin-bottom: 20px; }
.hero h1 { font-size: 1.9rem; }
.hero p { opacity: .9; max-width: 60ch; }

.code-input { font-size: 1.5rem; letter-spacing: .3em; text-transform: uppercase; text-align: center; font-weight: 700; }
.join-code { font-family: ui-monospace, monospace; font-size: 1.4rem; font-weight: 800; letter-spacing: .15em; }

/* ---- terrains ---- */
.courts { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.court { border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); overflow: hidden; }
.court header { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; background: var(--surface-2); font-weight: 700; }
.court .team { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 12px; }
.court .team + .team { border-top: 1px dashed var(--border); }
.court .names { font-weight: 600; }
.court .score { font-size: 1.6rem; font-weight: 800; font-variant-numeric: tabular-nums; min-width: 2ch; text-align: center; }
.court .team.win .names::after { content: " ✓"; color: var(--brand); }
.court.mine { outline: 3px solid var(--accent); }
.score-ctl { display: flex; align-items: center; gap: 6px; }
.score-ctl button { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 1.3rem; font-weight: 700; cursor: pointer; }
.score-ctl button:active { transform: scale(.94); }
.court footer { padding: 8px 12px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 6px; }

.bench { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 4px 10px; border-radius: 999px; background: var(--surface-2); font-size: .9rem; }
.chip.forced { background: var(--warn-bg); color: var(--warn); }
.chip.me { outline: 2px solid var(--accent); font-weight: 700; }

.status-card { text-align: center; padding: 24px 16px; }
.status-card .big { font-size: 2rem; font-weight: 800; margin: 6px 0; }
.status-card.playing { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.status-card.bench { background: var(--info-bg); }
.status-card.rest { background: var(--warn-bg); color: var(--warn); }

.player-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); }
.player-row:last-child { border-bottom: 0; }
.player-row.absent .pname { text-decoration: line-through; color: var(--muted); }

.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 10px; z-index: 100; box-shadow: var(--shadow); max-width: calc(100% - 32px); }
.toast.err { background: var(--danger); color: #fff; }

dialog { border: 0; border-radius: var(--radius); padding: 0; width: min(520px, calc(100% - 32px)); background: var(--surface); color: var(--text); }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog .dlg-body { padding: 20px; }

.empty { padding: 30px 16px; text-align: center; color: var(--muted); }
.live-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #e53935; margin-right: 6px; animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

/* ---- mobile ---- */
@media (max-width: 760px) {
  .grid.cols-2, .grid.cols-3 { grid-template-columns: 1fr; }
  h1 { font-size: 1.35rem; }
  .hero h1 { font-size: 1.5rem; }
  .menu-btn { display: inline-flex; margin-left: auto; background: transparent; border: 0; color: inherit; font-size: 1.5rem; cursor: pointer; padding: 4px 8px; }
  .topbar { flex-wrap: wrap; }
  .topbar nav { display: none; width: 100%; flex-direction: column; align-items: stretch; margin: 0; padding-top: 6px; }
  .topbar nav.open { display: flex; }
  .topbar nav a, .topbar nav button { text-align: left; padding: 12px; }
  .courts { grid-template-columns: 1fr; }
  main { padding-top: 16px; }
  .hide-mobile { display: none; }
}

/* ===================== v2 : mobile, pointage, chrono, légal ===================== */
body { padding-bottom: env(safe-area-inset-bottom); }
.site-footer { max-width: 1100px; margin: 0 auto; padding: 24px 16px 100px; color: var(--muted); font-size: .85rem; display: flex; flex-wrap: wrap; gap: 6px 16px; justify-content: center; border-top: 1px solid var(--border); }
.site-footer a, .site-footer button { color: var(--muted); background: none; border: 0; font: inherit; cursor: pointer; padding: 0; text-decoration: underline; }

/* barre d'onglets en bas (mobile, connecté) */
.bottom-nav { display: none; }
@media (max-width: 760px) {
  .bottom-nav.on { display: grid; grid-template-columns: repeat(3, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    background: var(--surface); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); }
  .bottom-nav a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px 10px; color: var(--muted); text-decoration: none; font-size: .75rem; font-weight: 600; }
  .bottom-nav a .ico { font-size: 1.35rem; line-height: 1; }
  .bottom-nav a.active { color: var(--brand); }
  main { padding-bottom: 90px; }
}

/* chrono */
.timer { font-variant-numeric: tabular-nums; font-weight: 800; }
.timer.low { color: var(--warn); }
.timer.over { color: var(--danger); animation: pulse 1s infinite; }
.timer.break { color: var(--brand); font-size: 1.1rem !important; }
.timer-box { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.timer-box .timer { font-size: 2rem; }
.progress { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin-top: 8px; }
.progress > span { display: block; height: 100%; background: var(--brand); border-radius: 99px; }
.banner { padding: 12px 14px; border-radius: var(--radius); background: var(--warn-bg); color: var(--warn); margin-bottom: 16px; display: flex; gap: 10px; justify-content: space-between; align-items: center; flex-wrap: wrap; }

/* pavé de pointage joueur */
.scorepad { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.scorepad .side { border-radius: var(--radius); border: 2px solid var(--border); background: var(--surface); padding: 12px; text-align: center; display: flex; flex-direction: column; gap: 8px; }
.scorepad .side.mine { border-color: var(--brand); }
.scorepad .who { font-weight: 700; font-size: .95rem; min-height: 2.6em; display: flex; align-items: center; justify-content: center; }
.scorepad .pts { font-size: 3.6rem; font-weight: 900; line-height: 1; font-variant-numeric: tabular-nums; }
.scorepad .plus { min-height: 72px; font-size: 1.8rem; font-weight: 900; border-radius: 14px; border: 0; background: var(--brand); color: var(--brand-ink); cursor: pointer; touch-action: manipulation; }
.scorepad .plus:active { transform: scale(.97); filter: brightness(1.1); }
.scorepad .minus { min-height: 40px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font-size: 1rem; font-weight: 700; cursor: pointer; touch-action: manipulation; }
.scorepad .tag { font-size: .75rem; font-weight: 700; color: var(--brand); text-transform: uppercase; letter-spacing: .05em; }
.score-actions { display: flex; gap: 8px; margin-top: 10px; }
.score-actions .btn { flex: 1; }

/* bandeau de témoins */
.consent { position: fixed; left: 12px; right: 12px; bottom: 12px; z-index: 200; max-width: 720px; margin: 0 auto; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 8px 30px rgba(0,0,0,.25); padding: 16px; }
.consent p { margin: 0 0 12px; font-size: .92rem; }
.consent .row .btn { flex: 1 1 auto; }
.toggle-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.toggle-row:last-child { border-bottom: 0; }
.toggle-row input { width: 22px; min-height: 22px; flex: none; margin-top: 2px; }

/* pages légales */
.legal { max-width: 820px; margin: 0 auto; }
.legal h2 { margin-top: 1.6em; }
.legal td, .legal th { vertical-align: top; font-size: .92rem; }
.legal .todo { background: var(--warn-bg); color: var(--warn); padding: 0 4px; border-radius: 4px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.seg label { margin: 0; padding: 10px 14px; cursor: pointer; font-weight: 600; }
.seg input { display: none; }
.seg label:has(input:checked) { background: var(--brand); color: var(--brand-ink); }

/* sélecteur de thèmes */
.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.swatch { display: flex; flex-direction: column; gap: 6px; padding: 10px; border-radius: 12px; border: 2px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 600; font-size: .9rem; color: var(--text); }
.swatch.on { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand) inset; }
.swatch .sw { display: flex; height: 28px; border-radius: 8px; overflow: hidden; }
.swatch .sw span { flex: 1; }
.swatch input { display: none; }

/* guide */
.guide .toc { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.guide .toc h3 { margin: 0 0 6px; font-size: .95rem; color: var(--muted); }
.guide .toc a { display: block; padding: 7px 0; text-decoration: none; font-weight: 600; border-bottom: 1px solid var(--border); }
.guide-sec { scroll-margin-top: 70px; }
.guide-sec h3 { margin-top: 1.2em; }
.guide-sec ul, .guide-sec ol { padding-left: 20px; }
.guide-sec li { margin: 4px 0; }
.steps { counter-reset: st; list-style: none; padding-left: 0 !important; }
.steps li { counter-increment: st; position: relative; padding: 4px 0 6px 40px; min-height: 30px; }
.steps li::before { content: counter(st); position: absolute; left: 0; top: 2px; width: 28px; height: 28px; border-radius: 50%;
  background: var(--brand); color: var(--brand-ink); font-weight: 800; display: grid; place-items: center; font-size: .9rem; }
.tip { background: var(--surface-2); border-left: 4px solid var(--brand); border-radius: 8px; padding: 10px 12px; margin: 12px 0; font-size: .93rem; }
.tip.muted { border-left-color: var(--border); color: var(--muted); }
.ui { display: inline-block; padding: 0 7px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); font-weight: 700; font-size: .88em; white-space: nowrap; }
.legend { display: grid; gap: 6px; margin: 10px 0; }
.legend span { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 8px; vertical-align: middle; }
.dot-ok { background: var(--brand); } .dot-bench { background: #5aa9f0; } .dot-rest { background: var(--warn); }
.guide details { border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; margin: 8px 0; background: var(--surface); }
.guide details summary { cursor: pointer; font-weight: 700; }
.guide details p { margin: 8px 0 0; }
@media (max-width: 760px) { .guide .toc { grid-template-columns: 1fr; } .ui { white-space: normal; } }
