:root {
  --bg: #0d100c;
  --bg-panel: #14180f;
  --line: #2a2f22;
  --olive: #7a8c4f;
  --olive-dim: #4b5533;
  --sand: #cfc9a8;
  --white: #eae6d6;
  --red: #b0402a;
  --gold: #c8a24a;
  --mono: 'Space Mono', monospace;
  --display: 'Teko', sans-serif;
  color-scheme: dark;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
/* Mode nuit par défaut (palette de la démo). Le bouton du header bascule data-theme ;
   sans JS, on suit le réglage du système. */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #eeece2; --bg-panel: #f7f5ec; --line: #d6d2bf;
    --sand: #4a4738; --white: #1c1c14;
    color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #eeece2; --bg-panel: #f7f5ec; --line: #d6d2bf;
  --sand: #4a4738; --white: #1c1c14;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0d100c; --bg-panel: #14180f; --line: #2a2f22;
  --sand: #cfc9a8; --white: #eae6d6;
  color-scheme: dark;
}
html { scroll-padding-top: env(safe-area-inset-top, 0px); }

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--white);
  font-family: var(--mono);
  background-image:
    radial-gradient(circle at 15% 0%, rgba(122,140,79,0.08), transparent 40%),
    repeating-linear-gradient(0deg, rgba(255,255,255,0.012) 0px, rgba(255,255,255,0.012) 1px, transparent 1px, transparent 3px);
}

.wrap { max-width: 760px; margin: 0 auto; padding: 28px 20px 60px; }

/* En-tête */
header { margin-bottom: 28px; }
.theme-btn {
  width: 28px; height: 28px; padding: 0; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  border-color: var(--line); color: var(--sand); font-size: 14px; line-height: 1;
}
.theme-btn:hover { border-color: var(--olive); background: none; color: var(--olive); }
.tag-row { display: flex; justify-content: space-between; align-items: center; }
.tag { font-size: 12px; letter-spacing: 0.15em; color: var(--olive); }
.sync { display: inline-flex; align-items: center; gap: 6px; font-size: 10px; letter-spacing: 0.1em; color: var(--sand); opacity: 0.8; }
.sync i { width: 7px; height: 7px; border-radius: 50%; background: var(--red); }
.sync[data-state="on"] i { background: var(--olive); box-shadow: 0 0 0 3px rgba(122,140,79,0.2); }
h1 {
  font-family: var(--display); font-weight: 700;
  font-size: clamp(48px, 12vw, 76px); line-height: 0.85;
  margin: 4px 0 6px; letter-spacing: 0.01em;
}
.subtitle { color: var(--sand); font-size: 13px; max-width: 46ch; line-height: 1.5; }
.rules { display: flex; gap: 18px; flex-wrap: wrap; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.rule { font-size: 12px; color: var(--sand); display: flex; align-items: baseline; gap: 6px; }
.rule b { color: var(--olive); font-size: 15px; font-family: var(--display); font-weight: 600; }

/* Onglets */
.tabs { display: flex; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tabs a {
  flex: 1; text-align: center; padding: 10px 4px 8px;
  font-family: var(--display); font-size: 22px; letter-spacing: 0.04em; line-height: 1;
  color: var(--sand); opacity: 0.6; text-decoration: none;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs a:hover { opacity: 1; }
.tabs a.active { color: var(--white); opacity: 1; border-bottom-color: var(--olive); }

/* Panneaux */
.panel { background: var(--bg-panel); border: 1px solid var(--line); padding: 18px; margin-bottom: 16px; }
.panel-title { font-size: 11px; letter-spacing: 0.1em; color: var(--olive); margin: 0 0 12px; font-weight: 400; }
.empty { color: var(--sand); font-size: 13px; opacity: 0.7; padding: 6px 0; line-height: 1.5; }

/* Cagnotte */
.pot-panel {
  display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap;
  background: var(--bg-panel); border: 1px solid var(--olive-dim);
  padding: 16px 18px; margin-bottom: 16px;
}
.pot-label { font-size: 11px; letter-spacing: 0.08em; color: var(--sand); opacity: 0.8; margin-bottom: 4px; }
.pot-value { font-family: var(--display); font-size: 44px; line-height: 0.85; color: var(--gold); }
.pot-deal { font-size: 11px; color: var(--sand); margin-top: 8px; line-height: 1.4; }
.pot-deal b { color: var(--red); font-weight: 400; }
.pot-deal em { color: var(--gold); font-style: normal; }
.pot-settings { display: flex; gap: 16px; }
.setting { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.setting.left { align-items: flex-start; }
.rate-input { display: flex; align-items: center; gap: 6px; }
.rate-input span { color: var(--sand); font-size: 13px; }
input[type="number"] {
  width: 64px; background: transparent; border: 1px solid var(--line);
  color: var(--white); padding: 6px 8px; font-family: var(--mono); font-size: 14px; text-align: right;
}

/* Formulaires et boutons */
.add-row { display: flex; gap: 8px; }
input[type="text"] {
  flex: 1; min-width: 0; background: transparent; border: 1px solid var(--line);
  color: var(--white); padding: 10px 12px; font-family: var(--mono); font-size: 14px;
}
input:focus { outline: none; border-color: var(--olive); }
button {
  font-family: var(--mono); font-size: 13px; cursor: pointer;
  border: 1px solid var(--olive-dim); background: transparent; color: var(--olive);
  padding: 10px 16px;
}
button:hover { background: var(--olive-dim); color: var(--white); }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.4; cursor: default; pointer-events: none; }
button.primary { background: var(--olive); border-color: var(--olive); color: #0d100c; font-weight: 700; }
button.primary:hover { background: var(--gold); border-color: var(--gold); }
button.ghost { border-color: var(--line); color: var(--sand); font-size: 12px; padding: 8px 12px; }
button.ghost:hover { border-color: var(--red); color: var(--red); background: none; }

/* Sélection de la squad */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.chip {
  padding: 7px 12px; font-size: 13px; border: 1px solid var(--line); color: var(--sand); background: transparent;
}
.chip:hover { background: transparent; color: var(--white); border-color: var(--olive-dim); }
.chip[aria-pressed="true"] { border-color: var(--olive); color: var(--white); background: rgba(122,140,79,0.14); }
.chip[aria-pressed="true"]::before { content: "✓ "; color: var(--olive); }
.new-game-foot { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }

/* Classement */
.player {
  display: grid;
  grid-template-columns: 28px 1fr auto auto auto auto;
  align-items: center; gap: 10px;
  padding: 12px 0; border-bottom: 1px solid var(--line);
}
.player:last-child { border-bottom: none; }
.rank { font-family: var(--display); font-size: 26px; color: var(--olive-dim); text-align: center; }
.player.is-first .rank { color: var(--gold); }
.player.is-last .rank { color: var(--red); }
.name-col { display: flex; flex-direction: column; min-width: 0; }
.name { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { font-size: 10px; letter-spacing: 0.08em; margin-top: 2px; }
.badge.first { color: var(--gold); }
.badge.last { color: var(--red); }
.stat-group { display: flex; align-items: center; gap: 4px; }
.stat-label { font-size: 10px; color: var(--sand); opacity: 0.7; letter-spacing: 0.06em; }
.stepper { display: flex; align-items: center; gap: 6px; }
.stepper button { width: 30px; height: 30px; padding: 0; line-height: 1; display: flex; align-items: center; justify-content: center; font-size: 15px; }
.stat-value { font-size: 16px; min-width: 22px; text-align: center; }
.total { font-family: var(--display); font-size: 28px; min-width: 44px; text-align: right; }
.is-first .total { color: var(--gold); }
.is-last .total { color: var(--red); }
.remove-btn { border: none; background: none; color: var(--sand); opacity: 0.4; font-size: 16px; padding: 4px 6px; }
.remove-btn:hover { opacity: 1; color: var(--red); background: none; }

.footer-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 18px; font-size: 12px; color: var(--sand); }
.footer-row .count { opacity: 0.7; }
.footer-row .actions { display: flex; gap: 8px; }

/* Historique */
.game-card { background: var(--bg-panel); border: 1px solid var(--line); margin-bottom: 10px; }
.game-card summary { list-style: none; cursor: pointer; padding: 14px 16px; display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: baseline; }
.game-card summary::-webkit-details-marker { display: none; }
.game-card[open] summary { border-bottom: 1px solid var(--line); }
.game-date { font-size: 11px; letter-spacing: 0.08em; color: var(--olive); }
.game-pot { font-family: var(--display); font-size: 30px; line-height: 0.8; color: var(--gold); grid-row: span 2; align-self: center; }
.game-deal { font-size: 13px; color: var(--sand); line-height: 1.5; }
.game-deal .w { color: var(--gold); }
.game-deal .l { color: var(--red); }
.game-body { padding: 4px 16px 14px; }
.standing { display: grid; grid-template-columns: 24px 1fr auto auto; gap: 10px; align-items: baseline; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.standing:last-of-type { border-bottom: none; }
.standing .r { font-family: var(--display); font-size: 20px; color: var(--olive-dim); text-align: center; }
.standing .kr { color: var(--sand); opacity: 0.7; font-size: 11px; }
.standing .t { font-family: var(--display); font-size: 22px; min-width: 32px; text-align: right; }
.game-meta { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 12px; font-size: 11px; color: var(--sand); opacity: 0.8; }

/* Joueurs */
.career { padding: 12px 0; border-bottom: 1px solid var(--line); }
.career:last-child { border-bottom: none; }
.career-top { display: flex; align-items: baseline; gap: 10px; }
.career-top .name { flex: 1; }
.balance { font-family: var(--display); font-size: 26px; line-height: 1; }
.balance.pos { color: var(--gold); }
.balance.neg { color: var(--red); }
.career-stats { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 11px; color: var(--sand); margin-top: 4px; }
.career-stats b { color: var(--white); font-weight: 400; }
.career-actions { display: flex; gap: 2px; }
.icon-btn { border: none; background: none; color: var(--sand); opacity: 0.5; padding: 4px 6px; font-size: 13px; }
.icon-btn:hover { opacity: 1; background: none; color: var(--white); }
.icon-btn.danger:hover { color: var(--red); }

/* Notification */
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--bg-panel); border: 1px solid var(--red); color: var(--white);
  padding: 10px 14px; font-size: 12px; max-width: calc(100vw - 32px);
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.ok { border-color: var(--olive); }

@media (max-width: 480px) {
  .player { grid-template-columns: 22px 1fr auto auto; row-gap: 8px; }
  .stat-group.kills { grid-column: 2; }
  .stat-group.revives { grid-column: 3 / 5; justify-content: flex-end; }
  .total { grid-column: 3; grid-row: 1; }
  .remove-btn { grid-column: 4; grid-row: 1; }
  .pot-panel { align-items: flex-start; }
}

/* Comptes */
[hidden] { display: none !important; }
.top-right { display: flex; align-items: center; gap: 12px; min-width: 0; }
.user-box { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--sand); min-width: 0; }
.user-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40vw; }
.link-btn { border: none; padding: 0; font-size: 11px; color: var(--olive); text-decoration: underline; text-underline-offset: 3px; background: none; }
.link-btn:hover { background: none; color: var(--white); }

.stack { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; }
input[type="email"], input[type="password"], select {
  width: 100%; min-width: 0; background: transparent; border: 1px solid var(--line);
  color: var(--white); padding: 10px 12px; font-family: var(--mono); font-size: 14px;
}
.add-row select { flex: 1; width: auto; }
select option { background: var(--bg-panel); color: var(--white); }
.stack button.primary { margin-top: 4px; }
.hint { font-size: 11px; color: var(--sand); opacity: 0.75; line-height: 1.5; margin: 12px 0 0; }
.error { font-size: 12px; color: var(--red); margin: 0 0 12px; }
.row-between { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }

.seg { display: flex; margin-bottom: 16px; border: 1px solid var(--line); }
.seg button { flex: 1; border: none; color: var(--sand); padding: 10px 8px; }
.seg button[aria-pressed="true"] { background: var(--olive-dim); color: var(--white); }

.invite-card { border-left: 2px solid var(--gold); padding: 4px 0 4px 12px; margin-bottom: 16px; font-size: 13px; line-height: 1.5; display: flex; flex-direction: column; gap: 4px; }
.invite-card b { color: var(--gold); font-weight: 400; }
.invite-row { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-top: 1px solid var(--line); margin-top: 12px; }
.invite-row + .invite-row { margin-top: 0; }
.invite-info { flex: 1; display: flex; flex-direction: column; gap: 2px; font-size: 13px; min-width: 0; }
.invite-row .ghost:hover { border-color: var(--olive); color: var(--white); }

.pill { font-size: 9px; letter-spacing: 0.08em; border: 1px solid var(--line); color: var(--sand); padding: 2px 5px; white-space: nowrap; }
.pill.me { border-color: var(--olive); color: var(--olive); }
.pill.ghosted { opacity: 0.6; }
.career-top .name { min-width: 0; }
select:focus { outline: none; border-color: var(--olive); }
@media (max-width: 480px) {
  #syncLabel { display: none; }
  .top-right { gap: 8px; }
}

/* Parties en parallèle */
.game-switch { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
a.chip { display: inline-flex; align-items: center; gap: 6px; text-decoration: none; font-size: 12px; max-width: 100%; }
a.chip[aria-current="page"] { border-color: var(--olive); color: var(--white); background: rgba(122,140,79,0.14); }
a.chip.new { border-style: dashed; color: var(--olive); }
a.chip.new[aria-current="page"] { border-style: solid; }
.chip-tag { font-size: 9px; letter-spacing: 0.08em; color: var(--olive); margin-left: 6px; }
.chip:disabled { opacity: 0.45; }
.chip:disabled .chip-tag { color: var(--sand); }
.watch { font-size: 12px; color: var(--sand); border-left: 2px solid var(--olive-dim); padding: 2px 0 2px 10px; margin: 0 0 16px; line-height: 1.5; }
.stepper button:disabled { opacity: 0.25; }
input:disabled { opacity: 0.5; }
