/* BadFollow — mobile et iPad d'abord, thème clair.
 * Contraintes de terrain : on tape debout, d'une main, parfois au soleil.
 * Donc : cibles >= 44 px, contraste fort, champs >= 16 px (sinon Safari iOS
 * zoome au focus sans jamais dézoomer).
 * Les surcouches sont des NOIRS translucides (--fill) : sur fond clair, un
 * blanc translucide ne se voit pas. */

:root {
  color-scheme: light;
  --bg: #f1f5f2;
  --panel: #ffffff;
  --panel-2: #e8f1ec;
  --ink: #11241e;
  --muted: #4a5f56;
  --line: #d0ded6;
  --green: #0a7a52;
  --green-d: #075c3d;
  --on-accent: #ffffff;
  --red: #b32d23;
  --amber: #7a4b00;
  --blue: #1f6fb0;
  --fill: #0f261f0d;
  --fill-2: #0f261f1a;
  --radius: 14px;
}

* { box-sizing: border-box; }

/* `hidden` doit l'emporter sur les `display: flex/grid` des blocs ci-dessous,
 * sinon un bloc masqué (ex. la ligne Direction) reste visible. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

main {
  max-width: 1000px;
  margin: 0 auto;
  padding: 12px 12px 48px;
  padding-bottom: calc(48px + env(safe-area-inset-bottom));
}

a { color: var(--green); text-decoration: none; }
h1 { font-size: 1.4rem; margin: 0 0 6px; }
h2 { font-size: 1.1rem; margin: 18px 0 8px; }
h3 { font-size: 1rem; margin: 16px 0 6px; }
h4 { font-size: .95rem; margin: 12px 0 4px; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.good { color: var(--green); }
.bad { color: var(--red); }
.warn {
  background: #fdf2dd; color: var(--amber);
  border-radius: 10px; padding: 8px 12px; font-weight: 600; margin: 0 0 10px;
}
.vs { color: var(--muted); font-weight: 400; padding: 0 6px; }

/* ----------------------------------------------------------------- nav */

.nav {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 10px 12px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--green); position: sticky; top: 0; z-index: 20;
  border-bottom: 2px solid var(--green-d);
}
.brand { color: #fff; font-weight: 700; font-size: 1.05rem; }
.nav nav { display: flex; align-items: center; gap: 4px; }
.nav nav a {
  color: #ffffff; padding: 8px 10px; border-radius: 10px;
  display: inline-flex; align-items: center; min-height: 44px;
}
.nav nav a.on { background: var(--fill-2); color: #fff; }

/* --------------------------------------------------------------- cartes */

.card, .hero {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; margin: 12px 0;
}
.hero { text-align: center; }
.note { background: var(--fill); border-left: 3px solid var(--amber); padding: 8px 10px; border-radius: 8px; }

/* -------------------------------------------------------------- boutons */

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 10px 16px; gap: 6px;
  background: var(--green); color: var(--on-accent); border: none;
  border-radius: 12px; font-size: 1rem; font-weight: 600;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .35; }
.btn-sm { min-height: 36px; padding: 6px 10px; font-size: .9rem; }
.btn-big { width: 100%; min-height: 54px; font-size: 1.1rem; margin-top: 10px; }
.btn-ghost { background: var(--fill); color: var(--ink); border: 1px solid var(--line); }
.btn-danger { background: var(--fill); color: var(--red); border: 1px solid #edc3bf; }

/* ----------------------------------------------------------- scoreboard */

.board {
  display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px; margin: 12px 0;
  position: sticky; top: 56px; z-index: 10;
}
.board-side { text-align: center; padding: 6px; border-radius: 12px; }
.board-side.serving { background: var(--fill-2); box-shadow: inset 0 0 0 2px var(--green); }
.board-side.won { box-shadow: inset 0 0 0 2px var(--amber); }
.board-side .names { font-weight: 700; font-size: .95rem; min-height: 2.6em; }
.board-side .sets { color: var(--amber); letter-spacing: 2px; height: 1.2em; }
.board-side .score { font-size: 3.2rem; font-weight: 800; line-height: 1; margin: 2px 0 8px; }
.btn-point { width: 100%; }
.board-mid { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; min-width: 110px; }
.pill { background: var(--fill-2); border-radius: 999px; padding: 4px 10px; font-size: .85rem; white-space: nowrap; }
.flag { min-height: 1.4em; font-size: .85rem; text-align: center; }
.flag.on { color: var(--amber); font-weight: 700; }

/* -------------------------------------------------------------- picker */

.picker.off { opacity: .4; pointer-events: none; }
.picker-head { display: flex; flex-direction: column; gap: 6px; }
.chain { display: flex; flex-wrap: wrap; gap: 6px; min-height: 28px; }
.chain-item {
  background: var(--fill); border-radius: 999px; padding: 4px 10px;
  font-size: .82rem; border: 1px solid var(--line);
}
.chain-item.res-gagnant { border-color: var(--green); }
.chain-item.res-faute { border-color: var(--red); }

.pick-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 10px 0; }
.pick-label { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; width: 100%; }
.btn-pick { background: var(--fill); color: var(--ink); border: 1px solid var(--line); }
.btn-pick.on { background: var(--green); color: var(--on-accent); border-color: var(--green); }
.who-B.btn-pick.on { background: var(--blue); color: var(--on-accent); border-color: var(--blue); }

.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-top: 8px; }
.tab {
  flex: 0 0 auto; min-height: 44px; padding: 10px 16px; border-radius: 999px;
  background: var(--fill); color: var(--muted); border: 1px solid var(--line);
  font-size: .9rem; cursor: pointer;
}
.tab.on { background: var(--fill-2); color: var(--ink); border-color: var(--green); }

.pick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 6px; margin-top: 8px; }
.btn-shot { background: var(--fill); color: var(--ink); border: 1px solid var(--line); font-size: .9rem; font-weight: 500; text-align: center; }
.btn-shot.on { background: var(--green); color: var(--on-accent); border-color: var(--green); }

.results .btn-res { flex: 1 1 30%; min-height: 52px; font-size: 1rem; }
.res-gagnant { background: var(--green); color: var(--on-accent); }
.res-neutre { background: var(--fill-2); color: var(--ink); border: 1px solid var(--line); }
.res-faute { background: var(--red); color: var(--on-accent); }

.pick-foot { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.pick-foot .btn { flex: 1 1 auto; }

/* ------------------------------------------------------------- listes */

.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.row {
  display: flex; align-items: center; gap: 8px;
  background: var(--fill); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px;
}
.row .grow { flex: 1; min-width: 0; color: var(--ink); }
.row-top { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: .8rem; margin-bottom: 4px; }
.row-main { font-size: 1rem; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.row-sub { font-size: .85rem; color: var(--muted); }
.row-actions { display: flex; gap: 6px; }

.tag { background: var(--green); color: var(--on-accent); border-radius: 6px; padding: 2px 7px; font-size: .75rem; font-weight: 700; }
.tag-ghost { background: var(--fill-2); color: var(--muted); }
.tag-done { background: var(--amber); color: var(--on-accent); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { background: var(--fill); border: 1px solid var(--line); border-radius: 999px; padding: 8px 12px; color: var(--ink); }

.history h3 { color: var(--muted); }
.points { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.point { padding: 6px 10px; border-radius: 8px; background: var(--fill); border-left: 3px solid var(--line); }
.point.win-A { border-left-color: var(--green); }
.point.win-B { border-left-color: var(--blue); }

/* ------------------------------------------------------------ formulaires */

.form { display: grid; gap: 10px; margin-top: 10px; }
.form label, label.block { display: grid; gap: 4px; font-size: .9rem; color: var(--muted); }
input, select, textarea {
  font-size: 16px; /* iOS : en dessous, Safari zoome au focus */
  min-height: 44px; padding: 10px; width: 100%;
  background: #fff; color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px;
  -webkit-appearance: none; appearance: none;
}
textarea { min-height: 70px; }
fieldset { border: 1px solid var(--line); border-radius: 12px; padding: 10px; display: grid; gap: 8px; }
legend { color: var(--muted); font-size: .85rem; padding: 0 6px; }
.search { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.search input { flex: 1 1 200px; }
details summary { cursor: pointer; padding: 10px 0; color: var(--green); }

/* ---------------------------------------------------------- statistiques */

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.stats { width: 100%; border-collapse: collapse; font-size: .9rem; min-width: 460px; }
table.stats th, table.stats td { padding: 7px 8px; text-align: right; border-bottom: 1px solid var(--line); }
table.stats th:first-child, table.stats td:first-child { text-align: left; }
table.stats th { color: var(--muted); font-weight: 600; font-size: .8rem; }
tr.dir-row td { color: var(--muted); font-size: .85rem; background: var(--fill); }
.headline { margin: 10px 0; padding-left: 18px; }
.headline li { margin: 4px 0; }
.score-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; margin: 10px 0; }
.big-score { font-size: 1.6rem; font-weight: 800; }
.big-score span { margin-right: 12px; }
.status { background: var(--fill); border-radius: 10px; padding: 10px; margin: 10px 0; }

/* ----------------------------------------------------------- dialogues */

dialog {
  width: min(680px, 94vw); border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel); color: var(--ink); padding: 16px;
}
dialog::backdrop { background: #0f261f73; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 50;
  background: var(--green); color: var(--on-accent); padding: 12px 18px;
  border-radius: 12px; font-weight: 600; max-width: 90vw;
}
.toast.bad { background: var(--red); color: var(--on-accent); }

/* --------------------------------------------------------- grands écrans */

@media (min-width: 760px) {
  .board-side .score { font-size: 4.2rem; }
  .pick-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
}
@media (max-width: 420px) {
  .board { grid-template-columns: 1fr auto 1fr; padding: 8px; }
  .board-side .score { font-size: 2.6rem; }
  .board-mid { min-width: 86px; }
  .pill { font-size: .75rem; padding: 3px 7px; }
}

/* ---- Lecture des statistiques par l'IA (page stats) ---- */
.ai-box {
  margin: 14px 0 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
}
.ai-box .btn { margin: 0; }
.ai-cols {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px 18px;
  margin-top: 8px;
}
.ai-cols b { display: block; margin-bottom: 4px; color: var(--green-d); }
.ai-cols ul { margin: 0; padding-left: 18px; }
.ai-cols li { margin-bottom: 4px; }
.ai-consigne {
  margin: 10px 0 0;
  padding: 8px 10px;
  border-left: 3px solid var(--green);
  background: var(--fill);
  border-radius: 0 6px 6px 0;
  font-weight: 600;
}

/* ---- Graphiques (overlay) ---- */
.chart-dlg {
  width: min(96vw, 760px);
  max-height: 90vh;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  color: var(--ink);
  overflow: hidden;
}
.chart-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
  position: sticky;
  top: 0;
}
.chart-head > div { display: flex; align-items: center; gap: 10px; min-width: 0; }
.chart-set { font-size: 16px; min-height: 44px; }
/* Sur un téléphone, le titre cède la place au sélecteur de set. */
@media (max-width: 480px) { .chart-head > div > b { display: none; } }
.chart-host {
  padding: 12px;
  overflow: auto;
  max-height: calc(90vh - 66px);
}
.chart-section { margin-bottom: 18px; }
.chart-section h3 {
  margin: 0 0 6px;
  font-size: 1rem;
  color: var(--green-d);
}
.chart-box { background: var(--panel-2); border-radius: 10px; padding: 8px; }
.chart { display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .sep { stroke: var(--line); stroke-width: 1; stroke-dasharray: 4 4; }
.chart .tick { font-size: 15px; fill: var(--ink); }
.chart .axis { font-size: 14px; fill: var(--muted); }
.chart .in-bar { font-size: 15px; fill: var(--on-accent); font-weight: 600; }
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
  font-size: 0.9rem;
  color: var(--muted);
}
.chart-legend li { display: flex; align-items: center; gap: 6px; }
.chart-legend .dot {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  display: inline-block;
}
