:root {
  --bg: #0d0b1a;
  --bg-panel: #17142b;
  --bg-panel-2: #1f1b38;
  --border: #2c2750;
  --text: #ece9ff;
  --muted: #9a93c7;
  --accent: #b23de8;
  --accent-2: #e8503d;
  --gold: #e8d23d;
  --silver: #c7ccd6;
  --bronze: #d08a45;
  --good: #3de89a;
  --danger: #e8503d;
  --radius: 16px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  -webkit-text-size-adjust: 100%;
}

html,
body {
  margin: 0;
  padding: 0;
  overscroll-behavior-y: none;
}

body {
  background: radial-gradient(1200px 600px at 50% -10%, #241a45 0%, var(--bg) 60%);
  background-attachment: fixed;
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  min-height: 100dvh;
}

button,
input {
  font-family: inherit;
  touch-action: manipulation;
}

button {
  user-select: none;
  -webkit-user-select: none;
}

#app {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 14px calc(48px + env(safe-area-inset-bottom));
  padding-left: max(14px, env(safe-area-inset-left));
  padding-right: max(14px, env(safe-area-inset-right));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 2px calc(12px);
  padding-top: max(12px, env(safe-area-inset-top));
  background: linear-gradient(180deg, var(--bg) 74%, transparent);
  backdrop-filter: blur(6px);
}

.topbar h1 {
  font-size: 1.3rem;
  margin: 0;
  letter-spacing: 0.3px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sync {
  font-size: 1.5rem;
  line-height: 1;
  color: var(--muted);
  transition: color 0.3s;
}
.sync.ok {
  color: var(--good);
}
.sync.err {
  color: var(--danger);
}

.icon-btn {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  color: var(--text);
  width: 46px;
  height: 46px;
  border-radius: 12px;
  font-size: 1.2rem;
  cursor: pointer;
}
.icon-btn:active {
  transform: scale(0.94);
}

/* Bannière identité */
.me-banner {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  margin-bottom: 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: linear-gradient(135deg, #2a1f4d, #201a3c);
  color: var(--text);
  cursor: pointer;
  text-align: left;
}
.me-banner:active {
  transform: scale(0.99);
}
.me-label {
  color: var(--muted);
  font-size: 0.95rem;
}
.me-name {
  font-weight: 800;
  font-size: 1.15rem;
  flex: 1;
}
.me-change {
  font-size: 0.85rem;
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 4px 10px;
  border-radius: 999px;
}

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.accent-panel {
  border-color: rgba(178, 61, 232, 0.5);
  box-shadow: 0 0 0 1px rgba(178, 61, 232, 0.15), var(--shadow);
}

.section-title {
  margin: 0 0 12px;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
}
.target-name {
  color: var(--gold);
  font-weight: 800;
  text-transform: none;
  letter-spacing: 0;
}
.formats-title {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* Sélecteur de joueur */
.players {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: 10px;
}

.player-chip {
  position: relative;
  padding: 14px 10px;
  min-height: 60px;
  border-radius: 14px;
  border: 2px solid var(--border);
  background: var(--bg-panel-2);
  color: var(--text);
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
}
.player-chip .chip-total {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  margin-top: 4px;
}
.player-chip.active {
  border-color: var(--accent);
  background: linear-gradient(180deg, #2a1f4d, #201a3c);
  box-shadow: 0 0 0 3px rgba(178, 61, 232, 0.25);
}
.player-chip.is-me::after {
  content: "👤";
  position: absolute;
  top: 4px;
  right: 6px;
  font-size: 0.8rem;
}
.player-chip:active {
  transform: scale(0.96);
}

/* Boutons de format */
.formats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}

.format-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 16px;
  min-height: 68px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: linear-gradient(135deg, #241d47, #1b1636);
  color: var(--text);
  cursor: pointer;
  text-align: left;
}
.format-btn:active {
  transform: scale(0.97);
  filter: brightness(1.2);
}
.format-btn .fmt-label {
  font-weight: 700;
  font-size: 1.05rem;
}
.format-btn .fmt-points {
  font-size: 0.9rem;
  color: var(--gold);
  font-weight: 800;
}

.undo-btn {
  margin-top: 12px;
  width: 100%;
  padding: 14px;
  min-height: 48px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-size: 0.95rem;
  cursor: pointer;
}
.undo-btn:active {
  transform: scale(0.98);
}

/* Classement */
.leaderboard {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.lb-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border-radius: 14px;
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
}
.lb-row.rank-1 {
  border-color: var(--gold);
  background: linear-gradient(90deg, rgba(232, 210, 61, 0.14), var(--bg-panel-2));
}
.lb-row.rank-2 {
  border-color: var(--silver);
}
.lb-row.rank-3 {
  border-color: var(--bronze);
}
.lb-row.is-me {
  outline: 2px solid rgba(178, 61, 232, 0.55);
  outline-offset: -2px;
}
.lb-medal {
  font-size: 1.7rem;
  width: 36px;
  text-align: center;
}
.lb-name {
  flex: 1;
  font-weight: 700;
  font-size: 1.15rem;
}
.lb-pulls {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 500;
}
.lb-total {
  font-size: 1.7rem;
  font-weight: 800;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}

/* Journal */
.log {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 340px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.log-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border-radius: 10px;
  background: var(--bg-panel-2);
  font-size: 0.95rem;
}
.log-row .log-who {
  font-weight: 700;
}
.log-row .log-what {
  flex: 1;
  color: var(--muted);
}
.log-row .log-pts {
  color: var(--gold);
  font-weight: 700;
}
.log-row .log-undo {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 1.2rem;
  padding: 4px 8px;
}
.log-empty {
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
  padding: 12px;
}

/* Modales (bottom-sheet) */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(6, 4, 16, 0.78);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
  backdrop-filter: blur(2px);
}
.modal.hidden,
.hidden {
  display: none;
}
.modal-card {
  background: var(--bg-panel);
  width: 100%;
  max-width: 720px;
  max-height: 92vh;
  overflow-y: auto;
  border-radius: 22px 22px 0 0;
  border: 1px solid var(--border);
  padding: 20px 16px calc(28px + env(safe-area-inset-bottom));
}

/* Onboarding (centré) */
.modal .onboard-card {
  align-self: center;
  border-radius: 22px;
  margin: 0 12px;
  max-width: 460px;
}
.onboard-title {
  margin: 4px 0 8px;
  text-align: center;
  font-size: 1.6rem;
}
.onboard-label {
  display: block;
  margin: 18px 0 8px;
  font-weight: 700;
}
.onboard-input {
  width: 100%;
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  padding: 14px 16px;
  font-size: 1.1rem;
}
.onboard-hint {
  margin: 18px 0 10px;
  color: var(--muted);
  font-weight: 600;
}
.onboard-slots {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.onboard-slot {
  width: 100%;
  padding: 16px;
  min-height: 58px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--bg-panel-2);
  color: var(--text);
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.onboard-slot:active {
  transform: scale(0.98);
}
.onboard-slot .slot-tag {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
}

/* Édition (réglages) */
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  background: var(--bg-panel);
  padding-bottom: 8px;
}
.modal-head h2 {
  margin: 0;
}
.modal-body h3 {
  margin: 20px 0 10px;
  font-size: 1rem;
}
.edit-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.edit-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.edit-row input {
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  padding: 12px;
  font-size: 1rem;
  min-width: 0;
}
.edit-row .in-name {
  flex: 1;
}
.edit-row .in-points {
  width: 74px;
  text-align: center;
}
.edit-row .del-row {
  background: none;
  border: 1px solid var(--border);
  color: var(--danger);
  border-radius: 10px;
  width: 46px;
  height: 46px;
  cursor: pointer;
  flex: none;
}

.ghost-btn {
  margin-top: 10px;
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--muted);
  padding: 12px;
  border-radius: 10px;
  width: 100%;
  cursor: pointer;
}
.primary-btn {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: none;
  color: #fff;
  font-weight: 700;
  padding: 16px;
  border-radius: 12px;
  width: 100%;
  font-size: 1.05rem;
  cursor: pointer;
}
.danger-btn {
  background: transparent;
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: 14px;
  border-radius: 12px;
  width: 100%;
  cursor: pointer;
  font-weight: 600;
}
.secondary-btn {
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 14px;
  border-radius: 12px;
  width: 100%;
  cursor: pointer;
  font-weight: 700;
  font-size: 1rem;
}
.secondary-btn:active {
  transform: scale(0.98);
}
.modal-actions {
  margin-top: 16px;
}
hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 22px 0;
}
.muted {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.4;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 14px 20px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 60;
  font-weight: 700;
  font-size: 1.05rem;
  max-width: 90vw;
  text-align: center;
  animation: pop 0.15s ease;
}
@keyframes pop {
  from {
    transform: translateX(-50%) scale(0.9);
    opacity: 0;
  }
}

/* Flash quand un joueur marque */
@keyframes flash {
  0% {
    box-shadow: 0 0 0 0 rgba(232, 210, 61, 0.6);
  }
  100% {
    box-shadow: 0 0 0 16px rgba(232, 210, 61, 0);
  }
}
.flash {
  animation: flash 0.6s ease-out;
}
