:root {
  --bg: #0b1020;
  --panel: #151b32;
  --panel-2: #1d2547;
  --text: #eef1fb;
  --muted: #9aa3c4;
  --accent: #3b82f6;
  --have: #22c55e;
  --double: #f59e0b;
  --danger: #ef4444;
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: env(safe-area-inset-bottom);
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
a { color: var(--accent); }

/* ---------------- AUTH ---------------- */
.auth {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border-radius: var(--radius);
  padding: 28px 22px;
  box-shadow: 0 20px 60px rgba(0,0,0,.4);
}
.auth-card h1 { margin: 0 0 6px; font-size: 24px; }
.auth-card form { display: grid; gap: 12px; margin-top: 18px; }
input, button { font-size: 16px; font-family: inherit; }
input {
  width: 100%;
  padding: 14px;
  border-radius: 12px;
  border: 1px solid #2a3358;
  background: var(--panel-2);
  color: var(--text);
}
input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.btn-primary {
  padding: 14px;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary:disabled { opacity: .6; }
.auth-toggle { text-align: center; margin-top: 16px; font-size: 14px; }
.auth-msg { text-align: center; min-height: 20px; margin: 10px 0 0; font-size: 14px; }
.auth-msg.error { color: var(--danger); }
.auth-msg.ok { color: var(--have); }

/* ---------------- TOP BAR ---------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  padding: 12px 14px 8px;
  padding-top: calc(12px + env(safe-area-inset-top));
  border-bottom: 1px solid #232a4a;
}
.topbar-row { display: flex; justify-content: space-between; align-items: center; }
.link-btn { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 14px; }

.stats { display: flex; gap: 10px; margin: 10px 0; }
.stat {
  flex: 1;
  background: var(--panel);
  border-radius: 10px;
  padding: 8px 4px;
  text-align: center;
}
.stat span { display: block; font-size: 20px; font-weight: 700; }
.stat small { color: var(--muted); font-size: 11px; }

.progress { height: 8px; background: var(--panel-2); border-radius: 99px; overflow: hidden; }
.progress-bar { height: 100%; width: 0%; background: linear-gradient(90deg, var(--have), var(--accent)); transition: width .3s; }

#search { margin-top: 12px; }

.filters { display: flex; gap: 8px; margin-top: 10px; overflow-x: auto; }
.chip-filter {
  white-space: nowrap;
  padding: 8px 14px;
  border-radius: 99px;
  border: 1px solid #2a3358;
  background: var(--panel);
  color: var(--muted);
  cursor: pointer;
}
.chip-filter.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.hint { font-size: 12px; color: var(--muted); margin: 8px 2px 0; }

.btn-share {
  width: 100%;
  margin-top: 10px;
  padding: 12px;
  border: none;
  border-radius: 12px;
  background: var(--double);
  color: #2a1800;
  font-weight: 700;
  cursor: pointer;
}
.btn-share:active { transform: scale(.98); }

.share-box {
  margin-top: 10px;
  padding: 10px;
  border: 1px solid #2a3358;
  border-radius: 12px;
  background: var(--panel);
}
.share-label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.share-url {
  display: block;
  font-size: 12px;
  color: var(--double);
  background: var(--panel-2);
  border-radius: 8px;
  padding: 8px 10px;
  word-break: break-all;
}

.io-row { display: flex; gap: 8px; margin-top: 8px; }
.btn-io {
  flex: 1;
  padding: 11px 8px;
  border: 1px solid #2a3358;
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}
.btn-io:active { transform: scale(.98); }

/* ---------------- TEAMS ---------------- */
.teams { padding: 12px 14px 60px; }
.team { margin-bottom: 12px; background: var(--panel); border-radius: var(--radius); overflow: hidden; }
.team-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  cursor: pointer;
  user-select: none;
}
.team-head .flag-letters {
  font-size: 12px; font-weight: 700; letter-spacing: .5px;
  background: var(--panel-2); padding: 4px 8px; border-radius: 6px; color: var(--muted);
}
.team-head .team-name { font-weight: 600; flex: 1; }
.team-head .team-count { font-size: 13px; color: var(--muted); }
.team-head .caret { color: var(--muted); transition: transform .2s; }
.team.open .caret { transform: rotate(90deg); }
.team-mini { height: 5px; background: var(--panel-2); }
.team-mini > div { height: 100%; background: var(--have); width: 0%; }

.cards-list { padding: 6px 10px 12px; display: grid; gap: 6px; }
.team:not(.open) .cards-list { display: none; }

.card-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel-2);
  border: 1px solid #2a3358;
  border-radius: 10px;
  padding: 8px 10px;
}
.card-row.is-have { border-color: var(--have); }
.card-row .rnum {
  font-weight: 700; font-size: 15px;
  min-width: 30px; text-align: center;
  color: var(--muted);
}
.card-row.is-have .rnum { color: var(--have); }
.card-row .rinfo { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.card-row .rcode { font-size: 11px; color: var(--muted); }
.card-row .rname { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* "J'ai" toggle */
.have-toggle {
  border: 1px solid #2a3358;
  background: var(--panel);
  color: var(--muted);
  border-radius: 9px;
  padding: 8px 12px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.card-row.is-have .have-toggle { background: var(--have); color: #04210f; border-color: var(--have); }

/* doubles stepper */
.stepper {
  display: flex; align-items: center;
  border: 1px solid #2a3358;
  border-radius: 9px;
  overflow: hidden;
}
.card-row.has-doubles .stepper { border-color: var(--double); }
.stepper button {
  width: 34px; height: 34px;
  border: none;
  background: var(--panel);
  color: var(--text);
  font-size: 20px; font-weight: 700;
  cursor: pointer;
}
.stepper button:active { background: var(--panel-2); }
.stepper .dval {
  min-width: 26px; text-align: center;
  font-weight: 700; font-size: 15px;
  color: var(--muted);
}
.card-row.has-doubles .stepper .dval { color: var(--double); }

.empty-note { text-align: center; color: var(--muted); padding: 40px 20px; }

/* ---------------- SYNC BADGE ---------------- */
.sync-badge {
  position: fixed;
  bottom: 14px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2);
  color: var(--text);
  padding: 8px 16px;
  border-radius: 99px;
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s;
}
.sync-badge.show { opacity: 1; }
.sync-badge.error { background: var(--danger); }
