:root {
  --bg: #0f172a;
  --bg-elev: #1e293b;
  --bg-elev2: #273449;
  --border: #334155;
  --text: #f1f5f9;
  --text-dim: #94a3b8;
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --accent: #facc15;
  --danger: #ef4444;
  --success: #22c55e;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- Header ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(10px + var(--safe-top)) 14px 10px;
  background: linear-gradient(180deg, var(--primary-dark), var(--primary));
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}
.app-header h1 {
  font-size: 1.2rem;
  margin: 0;
  font-weight: 700;
  letter-spacing: 0.3px;
  flex: 1;
  text-align: center;
}
.header-spacer { width: 36px; }
.icon-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  border-radius: 50%;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.back-btn { font-size: 1.9rem; padding-bottom: 3px; }
.refresh-btn { font-size: 1.35rem; }
.refresh-btn.spinning { animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

main {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 14px 8px;
}

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: var(--radius-sm);
  padding: 13px 18px;
  font-size: 1rem;
  font-weight: 600;
  color: #fff;
  background: var(--primary);
  cursor: pointer;
  transition: transform 0.06s ease, filter 0.15s ease;
  text-align: center;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: linear-gradient(135deg, var(--primary), var(--primary-dark)); }
.btn.accent { background: var(--accent); color: #1f2937; }
.btn.ghost { background: var(--bg-elev); color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: var(--danger); }
.btn.block { width: 100%; }
.btn.lg { padding: 16px; font-size: 1.05rem; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn .emoji { font-size: 1.25rem; }

/* ---------- Accueil ---------- */
.home-hero {
  text-align: center;
  margin: 8px 0 26px;
}
.home-hero .logo { font-size: 3rem; }
.home-hero p { color: var(--text-dim); margin: 6px 0 0; }
.home-actions { display: grid; gap: 14px; }
.home-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: left;
  color: var(--text);
  width: 100%;
}
.home-card:active { transform: scale(0.98); }
.home-card .hc-emoji {
  font-size: 1.8rem;
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-elev2);
  border-radius: 12px;
  flex-shrink: 0;
}
.home-card .hc-text strong { display: block; font-size: 1.05rem; }
.home-card .hc-text span { color: var(--text-dim); font-size: 0.85rem; }

/* ---------- Section / listes ---------- */
.section-title {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
  margin: 22px 0 10px;
}
.empty {
  text-align: center;
  color: var(--text-dim);
  padding: 40px 16px;
}
.empty .em-emoji { font-size: 2.5rem; display: block; margin-bottom: 10px; }

.list { display: grid; gap: 10px; }
.list-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.list-row .lr-main { flex: 1; min-width: 0; }
.list-row .lr-main strong { display: block; }
.list-row .lr-main small { color: var(--text-dim); }
.list-row.clickable { cursor: pointer; }
.list-row.clickable:active { transform: scale(0.99); }
.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

/* ---------- Formulaires ---------- */
.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 6px;
}
input[type="text"], input[type="number"], input[type="date"], input[type="search"] {
  width: 100%;
  padding: 13px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  font-size: 1rem;
}
input:focus { outline: 2px solid var(--primary); outline-offset: 0; }
.inline-form { display: flex; gap: 8px; }
.inline-form input { flex: 1; }

/* Sélection joueurs (checkbox cards) */
.select-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.select-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elev);
  cursor: pointer;
  user-select: none;
}
.select-chip.selected { border-color: var(--primary); background: rgba(99, 102, 241, 0.15); }
.select-chip .check {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem; flex-shrink: 0;
}
.select-chip.selected .check { background: var(--primary); border-color: var(--primary); }

/* Sélection du type de jeu (chips) */
.type-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.type-chip {
  padding: 10px 14px;
  border: 2px solid var(--border);
  border-radius: 22px;
  background: var(--bg-elev);
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}
.type-chip.selected { border-color: var(--primary); background: rgba(99, 102, 241, 0.18); color: #fff; }
.type-chip:active { transform: scale(0.97); }

/* Badge sens du score dans la liste des types */
.type-badge {
  width: 40px; height: 40px;
  border-radius: 10px;
  background: var(--bg-elev2);
  color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem; flex-shrink: 0; font-weight: 700;
}

/* Segmented control (sens du score) */
.seg { display: flex; gap: 8px; }
.seg-btn {
  flex: 1;
  padding: 12px 8px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elev2);
  color: var(--text-dim);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}
.seg-btn.active { border-color: var(--primary); background: rgba(99, 102, 241, 0.18); color: #fff; }

/* Valeurs rapides dans la saisie de mène */
.score-input-block { margin-bottom: 14px; }
.score-input-block .score-input-row { margin-bottom: 6px; }
.preset-row {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 2px 0 4px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.preset-row::-webkit-scrollbar { display: none; }
.preset-chip {
  flex: 0 0 auto;
  min-width: 44px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--bg-elev2);
  color: var(--text);
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
}
.preset-chip:active { background: var(--primary); border-color: var(--primary); color: #fff; }
.round-hint {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--text-dim);
  font-size: 0.82rem;
  margin-top: 8px;
}
.round-hint .link-btn { padding: 4px 8px; font-weight: 600; }

/* Ordre des joueurs */
.section-hint { text-transform: none; letter-spacing: 0; font-weight: 400; opacity: 0.8; }
.order-list { display: grid; gap: 8px; }
.order-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.order-pos {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.85rem; font-weight: 700; flex-shrink: 0;
}
.order-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.order-row .mini-btn { font-size: 0.9rem; }
.order-row .mini-btn:disabled { opacity: 0.3; }

/* Barre d'action fixée en bas */
.bottom-bar {
  position: sticky;
  bottom: 0;
  margin: 18px -14px calc(-24px - var(--safe-bottom));
  padding: 12px 14px calc(12px + var(--safe-bottom));
  background: linear-gradient(180deg, rgba(15, 23, 42, 0), var(--bg) 30%);
  display: flex;
  gap: 10px;
}
.bottom-bar .btn { flex: 1; }

/* ---------- Tableau de scores ---------- */
.game-meta { margin-bottom: 12px; }
.game-meta h2 { margin: 0 0 2px; font-size: 1.15rem; }
.game-meta small { color: var(--text-dim); }

.score-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-elev);
}
.score-table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
}
.score-table th, .score-table td {
  padding: 12px 10px;
  text-align: center;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.score-table thead th {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  background: var(--bg-elev2);
  font-weight: 600;
}
/* Colonne joueur (gauche, figée = toujours visible au défilement) */
.col-player {
  width: 118px;
  min-width: 118px;
  max-width: 118px;
  text-align: left !important;
  position: sticky;
  left: 0;
  background: var(--bg-elev);
  z-index: 2;
  box-shadow: 4px 0 6px -4px rgba(0, 0, 0, 0.5);
}
thead .col-player { background: var(--bg-elev2); }
.col-player .pname { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.col-player .dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.col-player strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Colonne total (figée juste après le joueur = score en cours toujours visible) */
.col-total {
  min-width: 58px;
  position: sticky;
  left: 118px;
  background: #232f49;
  z-index: 2;
}
thead .col-total { background: #2b3852; }
.col-total .val { font-weight: 800; font-size: 1.05rem; color: var(--accent); }
thead .col-total { color: var(--accent); }
/* Colonnes mènes */
.col-round { min-width: 52px; }
.col-round.latest { background: rgba(250, 204, 21, 0.10); }
.score-table tbody tr:last-child td { border-bottom: none; }
.score-cell.pos { color: var(--success); }
.score-cell.neg { color: var(--danger); }
.leader .pname strong { color: var(--accent); }
.round-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.round-count { color: var(--text-dim); font-size: 0.85rem; text-align: center; margin: 12px 0; }

/* ---------- Modale ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
  padding: 0;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  width: 100%;
  max-width: 480px;
  background: var(--bg-elev);
  border-radius: 18px 18px 0 0;
  padding: 20px 18px calc(20px + var(--safe-bottom));
  box-shadow: var(--shadow);
  max-height: 88vh;
  overflow-y: auto;
  animation: slideUp 0.22s ease;
}
@keyframes slideUp { from { transform: translateY(30px); opacity: 0.6; } to { transform: translateY(0); opacity: 1; } }
.modal h2 { margin: 0 0 16px; font-size: 1.15rem; }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.modal-actions .btn { flex: 1; }
.score-input-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.score-input-row .sir-name { flex: 1; display: flex; align-items: center; gap: 8px; font-weight: 600; }
.score-input-row input { width: 110px; text-align: center; font-size: 1.1rem; }
.score-input-row .dot { width: 12px; height: 12px; border-radius: 50%; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  transform: translateX(-50%) translateY(20px);
  background: #0b1220;
  color: #fff;
  padding: 12px 18px;
  border-radius: 30px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 60;
  font-size: 0.92rem;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.search-bar { margin-bottom: 14px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.chip {
  font-size: 0.78rem;
  padding: 4px 10px;
  background: var(--bg-elev2);
  border-radius: 20px;
  color: var(--text-dim);
}

.row-actions { display: flex; gap: 6px; }
.mini-btn {
  border: none;
  background: var(--bg-elev2);
  color: var(--text-dim);
  width: 34px; height: 34px;
  border-radius: 8px;
  font-size: 1rem;
  cursor: pointer;
}
.mini-btn.danger:active { background: var(--danger); color: #fff; }

.link-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 0.9rem;
  cursor: pointer;
  padding: 6px;
}

/* Pied de page : suit directement le contenu, centré */
.app-footer {
  text-align: center;
  padding: 14px 14px calc(20px + var(--safe-bottom));
}
.app-version {
  display: block;
  margin-top: 4px;
  color: var(--text-dim);
  opacity: 0.55;
  font-size: 0.72rem;
  letter-spacing: 0.5px;
}

/* Bandeau « Partie terminée » */
.ended-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  margin: 0 0 12px;
  background: rgba(250, 204, 21, 0.12);
  border: 1px solid rgba(250, 204, 21, 0.35);
  border-radius: var(--radius-sm);
  color: var(--accent);
  font-weight: 600;
  font-size: 0.92rem;
}
.ended-banner .link-btn { color: var(--accent); font-weight: 700; }
.ended-badge { margin-right: 4px; }

/* Podium */
.podium { display: grid; gap: 8px; }
.podium-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--bg-elev2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.podium-row.rank-1 {
  background: linear-gradient(135deg, rgba(250, 204, 21, 0.22), rgba(250, 204, 21, 0.08));
  border-color: rgba(250, 204, 21, 0.5);
}
.podium-row.rank-2 {
  background: linear-gradient(135deg, rgba(226, 232, 240, 0.14), rgba(226, 232, 240, 0.05));
  border-color: rgba(226, 232, 240, 0.35);
}
.podium-row.rank-3 {
  background: linear-gradient(135deg, rgba(217, 119, 6, 0.16), rgba(217, 119, 6, 0.05));
  border-color: rgba(217, 119, 6, 0.4);
}
.podium-medal {
  font-size: 1.5rem;
  width: 36px;
  text-align: center;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}
.podium-name {
  flex: 1;
  min-width: 0;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.podium-total {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  font-size: 1.1rem;
  color: var(--text);
}
.podium-row.rank-1 .podium-total { color: var(--accent); font-size: 1.25rem; }
.app-footer a {
  color: var(--text-dim);
  text-decoration: none;
  font-size: 0.82rem;
}
.app-footer a strong { color: var(--primary); font-weight: 600; }
.app-footer a:active { opacity: 0.6; }
