/* =========================================================
   Composants communs à toutes les aides de jeu
   (pensés d'abord pour le mobile en portrait).
   Les couleurs viennent de theme.css ; chaque outil ajoute ensuite
   ses propres styles dans son style.css.
   ========================================================= */

:root {
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

*, *::before, *::after { box-sizing: border-box; }
html { height: 100%; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 var(--font);
  -webkit-tap-highlight-color: transparent;
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(110% 70% at 50% -10%, var(--bg-glow) 0%, transparent 60%),
    radial-gradient(80% 50% at 100% 110%, var(--bg-glow-2), transparent 70%),
    var(--bg);
}
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: default; opacity: .4; }
[hidden] { display: none !important; }
svg { display: block; }
:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }

.screen {
  max-width: 560px;
  margin: 0 auto;
  padding-left: max(16px, var(--safe-l));
  padding-right: max(16px, var(--safe-r));
}

/* ---------- Boutons ---------- */
.btn { border: 0; border-radius: 14px; padding: 12px 18px; font-weight: 700; }
.btn-primary {
  background: linear-gradient(180deg, var(--primary-1), var(--primary-2));
  color: var(--on-primary);
  box-shadow: 0 8px 24px -10px var(--glow), inset 0 1px 0 rgba(255, 255, 255, .25);
}
.btn-primary:active { transform: translateY(1px); filter: brightness(.95); }
.btn-ghost {
  background: var(--panel-2);
  border: 1px solid var(--line-2);
  font-weight: 600;
  padding: 10px 14px;
}
.btn-danger {
  background: rgba(255, 92, 108, .14);
  border: 1px solid rgba(255, 92, 108, .5);
  color: #ffb6bf;
}
.btn-big { width: 100%; padding: 16px; font-size: 17px; border-radius: 16px; }

.icon-btn {
  flex: none;
  width: 42px; height: 42px; border-radius: 12px;
  border: 1px solid var(--line-2); background: var(--panel);
  display: grid; place-items: center;
}
.pill-btn {
  flex: none;
  display: inline-flex; align-items: center; gap: 6px;
  height: 42px; padding: 0 14px; border-radius: 12px;
  border: 1px solid var(--line-2); background: var(--panel);
  font-weight: 600; font-size: 14px;
}
.icon-btn svg, .pill-btn svg { width: 20px; height: 20px; }

/* Pastille numérotée à la couleur du joueur (variable --c) */
.num {
  flex: none; width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center;
  font-weight: 800; font-size: 15px;
  color: var(--ink); background: var(--c, var(--accent));
  box-shadow: 0 0 14px -2px var(--c, var(--accent));
}

/* Sélecteur segmenté : colonnes égales, quel que soit le nombre de boutons */
.seg {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px;
  background: var(--bg-2);
  padding: 4px;
  border-radius: 14px;
  border: 1px solid var(--line);
}
.seg button {
  min-width: 0;
  border: 0; background: transparent;
  padding: 11px 4px; border-radius: 10px;
  font-weight: 700; font-size: 17px; color: var(--muted);
  line-height: 1.2;
}
.seg button small { display: block; font-size: 11.5px; font-weight: 600; opacity: .8; }
.seg button[aria-pressed="true"] {
  background: linear-gradient(180deg, var(--primary-1), var(--primary-2));
  color: var(--on-primary);
  box-shadow: 0 4px 14px -4px var(--glow);
}

/* =========================================================
   ÉCRAN DE CONFIGURATION
   ========================================================= */
.setup { padding-top: calc(var(--safe-t) + 14px); padding-bottom: calc(var(--safe-b) + 104px); }

.home-link {
  display: inline-flex; align-items: center; gap: 4px;
  margin-bottom: 10px; padding: 4px 0;
  color: var(--muted); font-size: 14px; font-weight: 600;
  text-decoration: none;
}
.home-link:hover { color: var(--text); }

.setup-head { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.logo {
  width: 48px; height: 48px; flex: none;
  border-radius: 14px;
  display: grid; place-items: center;
  color: var(--logo-fg);
  background: radial-gradient(circle at 50% 40%, var(--logo-1), var(--logo-2) 70%);
  box-shadow: 0 6px 24px -6px var(--glow);
}
.logo svg { width: 28px; height: 28px; }
h1 { margin: 0; font-size: 24px; letter-spacing: .2px; }
.tagline { margin: 2px 0 0; color: var(--muted); font-size: 14px; }

.resume {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; margin-bottom: 14px;
  border-radius: var(--radius);
  border: 1px solid var(--resume-line);
  background: var(--resume-bg);
}
.resume-text { flex: 1; min-width: 0; }
.resume-text b { display: block; }
.resume-text small { color: var(--muted); }

.panel {
  background: linear-gradient(180deg, var(--panel), var(--panel-fade));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}
.panel h2 {
  margin: 0 0 12px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--muted);
  font-weight: 700;
}
.panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.panel-note { margin: 10px 2px 0; color: var(--muted); font-size: 13px; line-height: 1.45; }
.muted { color: var(--muted); font-size: 13px; }

/* Noms des joueurs */
.names { display: grid; gap: 8px; margin-top: 12px; }
.name-field { display: flex; align-items: center; gap: 10px; }
.text-input {
  flex: 1; min-width: 0; width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: 12px;
  padding: 11px 12px;
  color: var(--text);
  font: inherit; font-size: 16px; /* 16px : évite le zoom auto sur iOS */
}
.text-input::placeholder { color: var(--faint); }
.text-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }

/* Interrupteurs */
.switch-row {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
  cursor: pointer;
}
.panel h2 + .switch-row { border-top: 0; padding-top: 0; }
.sw-text { flex: 1; min-width: 0; }
.sw-text b { display: block; font-weight: 650; }
.sw-text small { display: block; color: var(--muted); font-size: 13px; line-height: 1.35; margin-top: 2px; }
.switch {
  appearance: none; -webkit-appearance: none;
  flex: none; position: relative; margin: 0;
  width: 50px; height: 30px; border-radius: 999px;
  background: var(--panel-3);
  border: 1px solid var(--line-2);
  cursor: pointer;
  transition: background .2s;
}
.switch::after {
  content: "";
  position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--switch-knob);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .4);
  transition: transform .2s, background .2s;
}
.switch:checked { background: linear-gradient(180deg, var(--primary-1), var(--primary-2)); border-color: transparent; }
.switch:checked::after { transform: translateX(20px); background: #fff; }

.footnote { color: var(--faint); font-size: 12.5px; text-align: center; margin: 6px 8px 0; line-height: 1.5; }

.setup-foot {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  padding: 14px max(16px, var(--safe-r)) calc(12px + var(--safe-b)) max(16px, var(--safe-l));
  background: linear-gradient(180deg, transparent, var(--bar-bg) 35%);
}
.setup-foot .btn { display: block; max-width: 528px; margin: 0 auto; }

/* =========================================================
   LISTES (classements, piles de cartes…)
   ========================================================= */
.list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.row {
  --c: var(--accent);
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px 10px 10px;
  border-radius: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 4px solid var(--c);
}
.row .lbl { flex: 1; min-width: 0; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .lbl small { display: block; color: var(--muted); font-weight: 500; font-size: 12px; overflow: hidden; text-overflow: ellipsis; }
.row .rank { flex: none; width: 34px; text-align: center; font-weight: 800; font-size: 14px; color: var(--muted); }
.row.first .rank { color: var(--gold); }
.row-total { flex: none; font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.empty-note { color: var(--muted); text-align: center; padding: 16px 8px; margin: 0; }

/* =========================================================
   FEUILLES (modales) ET TOAST
   ========================================================= */
#sheet-root { position: fixed; inset: 0; z-index: 50; }
.sheet-backdrop {
  position: absolute; inset: 0;
  display: flex; align-items: flex-end; justify-content: center;
  background: var(--backdrop);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  animation: fade .2s ease;
}
.sheet {
  width: 100%; max-width: 560px; max-height: 88vh; max-height: 88dvh;
  overflow: auto;
  padding: 10px 16px calc(16px + var(--safe-b));
  background: var(--bg-2);
  border: 1px solid var(--line-2); border-bottom: 0;
  border-radius: 22px 22px 0 0;
  animation: up .26s cubic-bezier(.2, .8, .2, 1);
  user-select: none; -webkit-user-select: none;
}
.sheet:focus { outline: none; }
#sheet-root.static .sheet-backdrop, #sheet-root.static .sheet { animation: none; } /* mise à jour sans ré-animation */
.grabber { width: 40px; height: 4px; border-radius: 2px; background: var(--line-2); margin: 0 auto 12px; }
.sheet h3 { margin: 0 0 4px; font-size: 18px; }
.sheet-sub { margin: 0 0 12px; color: var(--muted); font-size: 14px; line-height: 1.5; }
.sheet-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.sheet-actions .btn { width: 100%; padding: 14px; }
@media (min-width: 600px) {
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: 22px; border-bottom: 1px solid var(--line-2); }
}

.toast {
  position: fixed; left: 50%; z-index: 60;
  top: calc(var(--safe-t) + 62px);
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--toast-bg);
  border: 1px solid var(--line-2);
  box-shadow: 0 10px 30px -10px #000;
  font-size: 14px; font-weight: 600; text-align: center;
  opacity: 0; pointer-events: none;
  transform: translate(-50%, -12px);
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }

@media (hover: hover) {
  .icon-btn:hover, .pill-btn:hover:not(:disabled), .btn-ghost:hover { background: var(--panel-2); }
}

@media (prefers-reduced-motion: reduce) {
  .sheet, .sheet-backdrop { animation: none; }
}
