:root {
  /* Une couleur distincte par valeur de carte Numéro (0 à 12), inspirée de la palette du jeu */
  --num-0: #b0b0b0;
  --num-1: #e05353;
  --num-2: #e0762f;
  --num-3: #e0a62f;
  --num-4: #cdd12f;
  --num-5: #8fd12f;
  --num-6: #3fbf5c;
  --num-7: #2fb9a0;
  --num-8: #2f9fd1;
  --num-9: #3f6fe0;
  --num-10: #7a4fe0;
  --num-11: #b04fe0;
  --num-12: #e04fa8;

  --bonus-color: #f2a83c;
  --x2-color: #e8672f;
  --stop-color: #2f6fe0;
  --saute-color: #e0433f;
  --flip7-color: #f2c40c;

  --bg: #fbf3df;
  --panel-bg: #ffffff;
  --text: #26265c;
  --text-muted: #6a6a8f;
  --border: #26265c;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14142b;
    --panel-bg: #1f1f3f;
    --text: #f5f2e6;
    --text-muted: #a7a7cf;
    --border: #6a6a9f;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow-x: hidden;
}

#app {
  max-width: 720px;
  margin: 0 auto;
  padding: 12px 12px 100px;
}

#app-header {
  text-align: center;
  padding: 12px 0 4px;
}
#app-header h1 {
  margin: 0;
  font-size: 2.4rem;
  letter-spacing: 1px;
  color: var(--text);
}
#app-header .seven {
  color: var(--flip7-color);
  -webkit-text-stroke: 1px var(--border);
}
#app-header .subtitle {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.screen.hidden, .hidden {
  display: none !important;
}

h2 {
  font-size: 1.2rem;
  margin: 16px 0 8px;
}

.hint {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 0;
}

/* Boutons génériques, gros et tactiles */
.btn {
  font: inherit;
  font-weight: 700;
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  min-height: 48px;
  cursor: pointer;
  background: var(--panel-bg);
  color: var(--text);
  transition: transform 0.05s ease, filter 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-big { width: 100%; font-size: 1.1rem; padding: 16px; margin: 12px 0; }
.btn-primary { background: var(--stop-color); color: #fff; }
.btn-success { background: #2fbf6a; color: #fff; }
.btn-secondary { background: var(--panel-bg); color: var(--text); }

/* ---------- Écran configuration ---------- */
#form-add-player {
  display: flex;
  gap: 8px;
  margin: 12px 0;
}
#input-player-name {
  flex: 1;
  font-size: 1rem;
  padding: 12px;
  border-radius: 10px;
  border: 2px solid var(--border);
  background: var(--panel-bg);
  color: var(--text);
}

#setup-player-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
#setup-player-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--panel-bg);
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}
#setup-player-list .remove-player {
  background: var(--saute-color);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 6px 10px;
  font-weight: 700;
  cursor: pointer;
}

.error {
  color: var(--saute-color);
  font-weight: 700;
}

/* ---------- Archive des parties précédentes ---------- */
#archive-section { margin-top: 20px; }
.btn-danger-outline {
  background: transparent;
  color: var(--saute-color);
  border-color: var(--saute-color);
  width: 100%;
  margin-top: 8px;
}
#archive-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}
.archive-item {
  background: var(--panel-bg);
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}
.archive-item-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.archive-ranking {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  font-size: 0.9rem;
}
.archive-player.archive-winner {
  font-weight: 800;
  color: var(--flip7-color);
}
.archive-player.archive-winner::before {
  content: "🏆 ";
}

/* ---------- Barre supérieure partie en cours ---------- */
#game-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--panel-bg);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  margin-bottom: 8px;
  position: sticky;
  top: 0;
  z-index: 5;
}
#round-info .round-label {
  display: block;
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
}
#round-number { font-size: 1.4rem; font-weight: 800; }

#dealer-info { text-align: right; }
.dealer-badge {
  display: block;
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
}
#dealer-name { font-weight: 800; font-size: 1.1rem; }

.banner {
  background: var(--flip7-color);
  color: #26265c;
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 700;
  margin-bottom: 10px;
  text-align: center;
}

/* ---------- Tableau des scores ---------- */
#scoreboard-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
#scoreboard-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel-bg);
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
}
#scoreboard-list li.leader {
  background: linear-gradient(90deg, #f2c40c33, var(--panel-bg));
  border-color: var(--flip7-color);
  box-shadow: 0 0 0 2px var(--flip7-color) inset;
}
.sb-rank { font-weight: 800; width: 1.6em; color: var(--text-muted); }
.sb-name { flex: 1; font-weight: 700; }
.sb-total { font-weight: 800; font-size: 1.1rem; }
.sb-remaining { font-size: 0.75rem; color: var(--text-muted); white-space: nowrap; }
.sb-remaining.close { color: var(--saute-color); font-weight: 700; }

/* ---------- Toggle de mode de saisie ---------- */
.players-input-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}
.players-input-heading h2 { margin: 0; }
.mode-toggle {
  display: flex;
  border: 2px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.mode-btn {
  font: inherit;
  font-weight: 700;
  font-size: 0.8rem;
  border: none;
  background: var(--panel-bg);
  color: var(--text-muted);
  padding: 8px 10px;
  cursor: pointer;
}
.mode-btn.active {
  background: var(--stop-color);
  color: #fff;
}

/* ---------- Cartes joueur — mode "Score direct" ---------- */
.player-direct-card {
  background: var(--panel-bg);
  border: 2px solid var(--border);
  border-radius: 14px;
  padding: 12px;
}
.player-direct-card.is-dealer { border-color: var(--flip7-color); border-width: 3px; }
.player-direct-name { margin: 0 0 8px; font-size: 1.1rem; }
.player-direct-row {
  display: flex;
  gap: 8px;
}
.direct-score-input {
  flex: 1;
  font: inherit;
  font-size: 1.3rem;
  font-weight: 800;
  text-align: center;
  padding: 10px;
  border-radius: 10px;
  border: 2px solid var(--border);
  background: var(--bg);
  color: var(--text);
  min-height: 44px;
}
.direct-zero-btn { flex-shrink: 0; }
.player-direct-preview {
  margin: 8px 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ---------- Cartes joueur (saisie de manche) ---------- */
#players-input-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.player-card {
  background: var(--panel-bg);
  border: 2px solid var(--border);
  border-radius: 14px;
  padding: 12px;
}
.player-card.is-dealer { border-color: var(--flip7-color); border-width: 3px; }
.player-card.status-stop { opacity: 0.85; }
.player-card.status-saute { opacity: 0.6; }
.player-card.status-flip7 { box-shadow: 0 0 0 3px var(--flip7-color); }

.player-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.player-card-name { margin: 0; flex: 1; font-size: 1.1rem; }
.player-card-live-score {
  font-weight: 800;
  font-size: 1.3rem;
}
.player-card-status-tag {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 8px;
  text-transform: uppercase;
}
.player-card-status-tag.tag-stop { background: var(--stop-color); color: #fff; }
.player-card-status-tag.tag-saute { background: var(--saute-color); color: #fff; }
.player-card-status-tag.tag-flip7 { background: var(--flip7-color); color: #26265c; }
.player-card-status-tag:empty { display: none; }

.section-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  margin: 6px 0 4px;
}

.number-grid, .bonus-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  gap: 6px;
}

.card-btn {
  border: 2px solid var(--border);
  border-radius: 10px;
  min-height: 44px;
  font-weight: 800;
  font-size: 1rem;
  color: #fff;
  cursor: pointer;
  text-shadow: 0 1px 2px rgba(0,0,0,0.35);
}
.card-btn:active { transform: scale(0.95); }
.card-btn.selected { outline: 3px solid var(--border); outline-offset: 2px; }
.card-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.bonus-btn.selected { outline: 3px solid var(--border); outline-offset: 2px; }

.status-buttons {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 10px;
}
.btn-status { font-size: 0.9rem; padding: 10px 6px; min-height: 44px; }
.btn-stop { background: var(--stop-color); color: #fff; }
.btn-saute { background: var(--saute-color); color: #fff; }
.btn-flip7 { background: var(--flip7-color); color: #26265c; }
.btn-flip7.suggested { box-shadow: 0 0 0 3px #26265c; animation: pulse 1s infinite; }
.btn-edit { grid-column: 1 / -1; background: var(--panel-bg); }

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.03); }
}

/* ---------- Historique ---------- */
#history { margin-top: 20px; }
#history-content {
  margin-top: 10px;
  overflow-x: auto;
}
#history-content table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.85rem;
}
#history-content th, #history-content td {
  border: 1px solid var(--border);
  padding: 6px 8px;
  text-align: center;
}
#history-content th { background: var(--panel-bg); }

/* ---------- Fin de partie ---------- */
#screen-end { text-align: center; }
#winner-banner {
  background: linear-gradient(135deg, var(--flip7-color), #f2a83c);
  color: #26265c;
  border: 3px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  font-size: 1.3rem;
  font-weight: 800;
  margin: 12px 0;
}
#final-ranking {
  list-style: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
#final-ranking li {
  display: flex;
  justify-content: space-between;
  background: var(--panel-bg);
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 700;
}

#btn-new-game {
  position: fixed;
  bottom: 12px;
  left: 12px;
  right: 12px;
  max-width: 696px;
  margin: 0 auto;
  z-index: 10;
}

@media (min-width: 600px) {
  .status-buttons { grid-template-columns: repeat(4, 1fr); }
}
