/* Babyfoot Score — thème sombre, mobile-first. */

:root {
  --bg: #0e1512;
  --surface: #17211c;
  --surface-2: #1e2b24;
  --border: #2b3a32;
  --text: #e8efe9;
  --muted: #93a69b;
  --accent: #4ade80;
  --accent-dim: #22c55e;
  --accent-contrast: #06281a;
  --danger: #f87171;
  --team1: #7dd3fc;
  --team2: #fca5a5;
  --gold: #fbbf24;
  --radius: 12px;
  --nav-h: 62px;
  --tap: 44px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  min-height: 100vh;
  min-height: 100dvh;
}

#app { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }

/* ---------- En-tête ---------- */

#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 10px; color: var(--accent); }
.brand h1 { font-size: 1.1rem; font-weight: 700; color: var(--text); letter-spacing: .02em; }

/* ---------- Navigation ---------- */

#nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 20;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}

#nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: var(--nav-h);
  color: var(--muted);
  text-decoration: none;
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .02em;
}

#nav a svg { width: 24px; height: 24px; }
#nav a.active { color: var(--accent); }
#nav a:active { background: var(--surface-2); }

/* ---------- Contenu ---------- */

.view {
  flex: 1;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 16px calc(var(--nav-h) + env(safe-area-inset-bottom) + 24px);
}

body.logged-out .view { padding-bottom: 24px; }

h2 { font-size: 1.25rem; margin-bottom: 12px; }
h3 { font-size: 1rem; margin: 16px 0 8px; }

.muted { color: var(--muted); font-size: .85rem; }
.empty { padding: 16px 0; text-align: center; }
.hint { margin-top: 8px; }

.error {
  background: rgba(248, 113, 113, .12);
  border: 1px solid var(--danger);
  color: var(--danger);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin: 10px 0;
  font-size: .9rem;
}

/* ---------- Champs et boutons ---------- */

.input, select.input {
  width: 100%;
  min-height: var(--tap);
  padding: 8px 12px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
}

.input:focus { outline: 2px solid var(--accent-dim); outline-offset: 1px; }

button { font: inherit; cursor: pointer; }

.btn-primary {
  min-height: var(--tap);
  padding: 10px 18px;
  background: var(--accent-dim);
  color: var(--accent-contrast);
  border: none;
  border-radius: var(--radius);
  font-weight: 700;
}
.btn-primary:disabled { opacity: .4; cursor: not-allowed; }
.btn-big { width: 100%; font-size: 1.05rem; margin-top: 12px; }

.btn-ghost {
  min-height: var(--tap);
  padding: 8px 12px;
  background: transparent;
  color: var(--accent);
  border: none;
  border-radius: var(--radius);
  font-weight: 600;
}

.btn-sm {
  min-height: var(--tap);
  padding: 6px 14px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.btn-danger { color: var(--danger); border-color: var(--danger); }

.field { margin: 14px 0; }
.field > label { display: block; font-size: .8rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 6px; }

/* ---------- Login ---------- */

.login-wrap { display: flex; justify-content: center; padding-top: 12vh; }
.login-form { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 12px; }
.login-form p { margin-bottom: 4px; }

/* ---------- Nouvelle partie ---------- */

.teams-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }

.team-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.team-panel h3 { margin: 0 0 2px; font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; }
.team-1 h3 { color: var(--team1); }
.team-2 h3 { color: var(--team2); }

.slot {
  min-height: var(--tap);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  font-size: .95rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0 8px;
}
.slot.filled { border-style: solid; background: var(--surface-2); color: var(--text); font-weight: 600; }

.chips-head { display: flex; align-items: center; justify-content: space-between; margin-top: 4px; }
.chips-head label { font-size: .8rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }

.newplayer-form { display: flex; gap: 8px; align-items: center; margin: 8px 0; flex-wrap: wrap; }
.newplayer-form .input { flex: 1; min-width: 150px; width: auto; }
.newplayer-form .error { flex-basis: 100%; margin: 0; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 4px; }

.chip {
  min-height: var(--tap);
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: .95rem;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.chip-side1 { border-color: var(--team1); background: rgba(125, 211, 252, .12); }
.chip-side2 { border-color: var(--team2); background: rgba(252, 165, 165, .12); }
.chip-tag { font-size: .7rem; font-weight: 700; padding: 1px 6px; border-radius: 999px; background: var(--surface-2); }
.chip-side1 .chip-tag { color: var(--team1); }
.chip-side2 .chip-tag { color: var(--team2); }

.winner-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.btn-winner {
  min-height: 58px;
  border-radius: var(--radius);
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1.05rem;
  font-weight: 700;
}
.btn-winner.win-1.active { border-color: var(--team1); color: var(--team1); background: rgba(125, 211, 252, .12); }
.btn-winner.win-2.active { border-color: var(--team2); color: var(--team2); background: rgba(252, 165, 165, .12); }
.btn-winner.active::after { content: " ✓"; }

.accordion {
  margin: 16px 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.accordion summary {
  min-height: var(--tap);
  display: flex;
  align-items: center;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 600;
  color: var(--muted);
  list-style: none;
}
.accordion summary::before { content: "▸ "; margin-right: 6px; transition: transform .15s; }
.accordion[open] summary::before { content: "▾ "; }
.accordion summary::-webkit-details-marker { display: none; }
.accordion-body { padding: 0 14px 14px; }

.score-row { display: flex; align-items: center; gap: 10px; }
.input-score { width: 90px; text-align: center; font-size: 1.2rem; }
.score-sep { color: var(--muted); font-size: 1.2rem; }

.pos-list { display: flex; flex-direction: column; gap: 8px; }
.pos-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.pos-name { flex: 1; min-width: 80px; font-weight: 600; }
.btn-pos { min-width: 96px; }
.btn-pos.on { border-color: var(--accent-dim); color: var(--accent); }
.held-label { display: inline-flex; align-items: center; gap: 6px; font-size: .85rem; color: var(--muted); min-height: var(--tap); }
.held-label input { width: 20px; height: 20px; accent-color: var(--accent-dim); }

/* ---------- Historique ---------- */

.filters { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.pair-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.total-count { display: block; margin-bottom: 8px; }

.match-list { display: flex; flex-direction: column; gap: 10px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.tappable { cursor: pointer; }

.match-meta { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; }
.match-date { color: var(--muted); font-size: .8rem; }
.badge-win { font-size: .75rem; color: var(--gold); font-weight: 600; }

.match-line {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  font-size: .98rem;
}
.match-line .side { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.match-line .side:last-child { text-align: right; }
.match-line .winner { font-weight: 700; color: var(--accent); }
.match-line .score { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }

.match-pos { margin-top: 6px; font-size: .78rem; color: var(--muted); }

.match-actions { display: flex; gap: 10px; margin-top: 10px; }
.match-actions .btn-sm { flex: 1; }

.btn-more { width: 100%; margin-top: 12px; border: 1px dashed var(--border); }

/* ---------- Tableaux stats ---------- */

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
}
.stats-table th, .stats-table td {
  padding: 10px 8px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.stats-table th { color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; }
.stats-table td.num, .stats-table th:not(:first-child):not(:nth-child(2)) { text-align: right; }
.stats-table td:first-child { color: var(--muted); }
.stats-table .strong { font-weight: 700; color: var(--gold); }
.good { color: var(--accent); }
.bad { color: var(--danger); }

.detail-row td { background: var(--surface-2); }
.posdetail { display: flex; gap: 24px; flex-wrap: wrap; padding: 4px 0; }
.posblock { display: flex; flex-direction: column; gap: 2px; font-size: .85rem; }
.posblock strong { color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; }

/* ---------- Face-à-face ---------- */

.h2h-wrap { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.h2h-card { text-align: center; }
.h2h-card .match-line { font-size: 1.05rem; }

/* ---------- Toast ---------- */

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
  transform: translateX(-50%) translateY(8px);
  background: var(--accent-dim);
  color: var(--accent-contrast);
  font-weight: 700;
  padding: 10px 18px;
  border-radius: 999px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, .45);
  opacity: 0;
  transition: opacity .2s, transform .2s;
  z-index: 40;
  max-width: 90vw;
  text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- ≥ 768px : navigation en haut ---------- */

@media (min-width: 768px) {
  #nav {
    position: static;
    order: -1;
    border-top: none;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0;
    justify-content: center;
    gap: 8px;
  }
  #topbar { order: -2; }
  #nav a {
    flex: 0 0 auto;
    flex-direction: row;
    gap: 8px;
    min-height: 52px;
    padding: 0 18px;
    font-size: .9rem;
    border-bottom: 2px solid transparent;
  }
  #nav a svg { width: 20px; height: 20px; }
  #nav a.active { border-bottom-color: var(--accent); }
  .view { padding-bottom: 40px; }
  #toast { bottom: 32px; }
}
