/* ==========================================================================
 * Scores — jeux de société. Thème vert émeraude, look tableur, mobile-first.
 * Clair/sombre auto.
 * ====================================================================== */
:root {
  --accent: #12a06a;
  --accent-d: #0e855a;
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #eef1f0;
  --line: #d9dedb;
  --text: #16201b;
  --muted: #6b7772;
  --pos: #1f9d57;
  --neg: #d8443b;
  --total-bg: #e7f5ee;
  --shadow: 0 6px 24px rgba(0,0,0,.18);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1512;
    --surface: #16201b;
    --surface-2: #1d2a23;
    --line: #2a3a31;
    --text: #eaf1ed;
    --muted: #93a49b;
    --total-bg: #14352492;
    --shadow: 0 8px 30px rgba(0,0,0,.5);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior: none;
}
body.modal-open { overflow: hidden; }

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

/* ---- En-tête ---- */
.header {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 14px 10px;
  background: var(--accent);
  color: #fff;
}
.header h1 { font-size: 20px; margin: 0; font-weight: 700; letter-spacing: .2px; }
.ver { font-size: 11px; font-weight: 500; opacity: .55; }
.header-actions { display: flex; gap: 4px; }
.icon-btn {
  background: transparent; border: 0; color: #fff; padding: 8px;
  border-radius: 10px; cursor: pointer; display: grid; place-items: center;
}
.icon-btn:active { background: rgba(255,255,255,.18); }
.icon-btn.on { background: rgba(255,255,255,.24); }

/* ---- Zone tableur ---- */
.grid-wrap { flex: 1; min-height: 0; position: relative; }
/* Pas de -webkit-overflow-scrolling: touch : il casse la zone tactile des
   colonnes figées (sticky) sur iOS → le 1er joueur devenait intappable. */
.table-scroll { height: 100%; overflow: auto; }

/* ===== Tableur en flexbox : 1 ligne = 1 <div> flex indépendant ============= */
.sboard { display: flex; flex-direction: column; width: max-content; min-width: 100%; }
.srow { display: flex; min-height: 72px; }

/* Case de base : colonne joueur (flexible, ≥96px), centrée, quadrillage */
.scell {
  flex: 1 1 0; min-width: 96px;
  display: flex; align-items: center; justify-content: center;
  box-sizing: border-box; text-align: center;
  background: var(--surface);
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

/* Première colonne (labels manches / Total), largeur fixe, figée à gauche */
.scell.slabel {
  flex: 0 0 64px; min-width: 64px;
  position: sticky; left: 0; z-index: 2;
  background: var(--surface-2);
  color: var(--muted); font-size: 13px; font-weight: 600;
  justify-content: space-between; padding: 0 6px;
}
.scell.slabel .del { all: unset; color: var(--muted); font-size: 15px; padding: 10px 4px; cursor: pointer; }
.scell.slabel .del:active { color: var(--neg); }

/* Ligne d'en-tête (figée en haut) */
.srow-head { position: sticky; top: 0; z-index: 3; }
.srow-head .scell { background: var(--surface-2); min-height: 54px; font-size: 15px; font-weight: 700; }
.srow-head .slabel { z-index: 5; }
.scell.shead { cursor: pointer; flex-direction: column; overflow: hidden; padding: 6px 8px; }
.scell.shead .pname { max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.scell .rank { font-size: 11px; color: var(--muted); font-weight: 600; }

/* Cases de score */
.scell.sval { cursor: pointer; font-size: 20px; color: var(--text); font-variant-numeric: tabular-nums; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
.scell.sval:active { background: var(--surface-2); }
/* Les scores de manche restent neutres : seule la ligne Total est colorée. */
.scell.sval.pos { color: var(--text); }
.scell.sval.neg { color: var(--text); }
.scell.sval.blank { color: var(--muted); }
.scell.sval.editing { outline: 2px solid var(--accent); outline-offset: -2px; }

/* Ligne Total (figée en bas) */
.srow-total { position: sticky; bottom: 0; z-index: 3; }
.srow-total .scell { background: var(--total-bg); min-height: 60px; font-size: 19px; font-weight: 800; font-variant-numeric: tabular-nums; }
.srow-total .slabel { z-index: 5; color: var(--text); }
.scell.stotal.pos { color: var(--pos); }
.scell.stotal.neg { color: var(--neg); }
.scell.stotal.leader { box-shadow: inset 0 3px 0 var(--accent); }

/* ---- Barre du bas ---- */
.bottom-bar { padding: 10px 14px calc(10px + var(--safe-b)); background: var(--surface); border-top: 1px solid var(--line); }
.primary-btn {
  background: var(--accent); color: #fff; border: 0; border-radius: 12px;
  padding: 13px 18px; font-size: 16px; font-weight: 700; cursor: pointer; width: 100%;
}
.primary-btn:active { background: var(--accent-d); }
.ghost-btn { background: var(--surface-2); color: var(--text); border: 0; border-radius: 12px; padding: 12px 16px; font-size: 15px; font-weight: 600; cursor: pointer; }
.ghost-btn.full { width: 100%; }
.danger-btn { background: transparent; color: var(--neg); border: 0; border-radius: 12px; padding: 12px 14px; font-size: 15px; font-weight: 700; cursor: pointer; }

/* ---- État vide ---- */
.empty { position: absolute; inset: 0; display: grid; place-content: center; place-items: center; gap: 14px; text-align: center; padding: 30px; color: var(--muted); }
.empty .big { font-size: 54px; }
.empty p { margin: 0; font-size: 16px; max-width: 260px; }

/* ---- Bottom-sheets ---- */
.sheet-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; z-index: 50; }
.sheet {
  background: var(--surface); width: 100%; max-width: 520px;
  border-radius: 20px 20px 0 0; padding: 18px 18px calc(18px + var(--safe-b));
  box-shadow: var(--shadow); animation: up .18s ease;
}
@keyframes up { from { transform: translateY(20px); opacity: .6; } }
.sheet h2 { margin: 2px 0 14px; font-size: 18px; }
.input { width: 100%; padding: 14px; font-size: 17px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); color: var(--text); }
.sheet-actions { display: flex; align-items: center; gap: 8px; margin-top: 16px; }
.sheet-actions .spacer { flex: 1; }
.menu-item { display: block; width: 100%; text-align: left; background: var(--surface-2); border: 0; border-radius: 12px; padding: 14px; margin-bottom: 10px; font-size: 16px; font-weight: 600; color: var(--text); cursor: pointer; }
.menu-item small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; margin-top: 3px; }
.menu-item.danger { color: var(--neg); }

/* Groupes de joueurs */
#groupsList { margin-bottom: 6px; }
.group-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.group-load {
  flex: 1; min-width: 0; text-align: left; cursor: pointer;
  background: var(--surface-2); color: var(--text); border: 0; border-radius: 12px; padding: 11px 14px;
}
.group-load strong { display: block; font-size: 16px; }
.group-load small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.group-del { background: transparent; border: 0; font-size: 18px; padding: 10px; cursor: pointer; border-radius: 10px; }
.group-del:active { background: var(--surface-2); }
.hint { color: var(--muted); font-size: 14px; margin: 4px 2px 12px; }

/* Écran d'accueil : préréglages de jeux */
.preset-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; width: 100%; max-width: 340px; margin-top: 4px; }
.preset-btn {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  background: var(--surface-2); color: var(--text); border: 0; border-radius: 14px;
  padding: 16px 10px; cursor: pointer; font-size: 15px; font-weight: 600;
}
.preset-btn:active { background: var(--line); }
.preset-btn .pi { font-size: 26px; line-height: 1; }
.preset-btn.custom { border: 1px dashed var(--line); background: transparent; }

/* Règles : titres de section, chips, sélecteur segmenté */
.section-title { margin: 14px 2px 8px; font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.section-title small { font-weight: 500; text-transform: none; letter-spacing: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { background: var(--surface-2); color: var(--text); border: 1px solid transparent; border-radius: 999px; padding: 8px 14px; font-size: 14px; font-weight: 600; cursor: pointer; }
.chip.on { border-color: var(--accent); color: var(--accent); background: rgba(18,160,106,.12); }
.chip.custom { display: inline-flex; align-items: center; }
.chip-x { margin-left: 8px; font-size: 17px; line-height: 1; opacity: .55; font-weight: 700; }
.chip-x:active { color: var(--neg); opacity: 1; }
.key:disabled { opacity: .3; }
.seg { display: flex; gap: 6px; background: var(--surface-2); border-radius: 12px; padding: 4px; }
.seg button { flex: 1; background: transparent; border: 0; border-radius: 9px; padding: 11px 8px; font-size: 14px; font-weight: 700; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--accent); color: #fff; }

/* Couleur des totaux selon la proximité de l'objectif (sens du jeu) */
.dir-high .stotal.prox1 { color: #7fc79b; }
.dir-high .stotal.prox2 { color: var(--pos); }
.dir-high .stotal.prox3 { color: var(--pos); background: rgba(31,157,87,.16); }
.dir-high .stotal.prox4 { color: #fff; background: var(--pos); }
.dir-low  .stotal.prox1 { color: #e6c778; }
.dir-low  .stotal.prox2 { color: #e69a4a; }
.dir-low  .stotal.prox3 { color: var(--neg); background: rgba(216,68,59,.16); }
.dir-low  .stotal.prox4 { color: #fff; background: var(--neg); }

/* ---- Clavier ---- */
.keypad { max-width: 420px; }
.keypad-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }
.keypad-who { font-size: 15px; color: var(--muted); font-weight: 600; }
.keypad-value { font-size: 32px; font-weight: 800; font-variant-numeric: tabular-nums; }
.keypad-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.key { background: var(--surface-2); border: 0; border-radius: 14px; height: 60px; font-size: 24px; font-weight: 700; color: var(--text); cursor: pointer; }
/* Pas de zoom au double-tap sur le clavier (saisie rapide) + pas de sélection de texte. */
.keypad, .keypad * { touch-action: manipulation; user-select: none; -webkit-user-select: none; }
.key:active { background: var(--line); }
.key-sign { color: var(--accent); }
.key-back { font-size: 20px; }
.keypad-foot { display: flex; gap: 10px; margin-top: 12px; }
.keypad-foot .ghost-btn { flex: 0 0 auto; }
.keypad-foot .primary-btn { flex: 1; }

[hidden] { display: none !important; }
