:root {
  --cote-de: 74px;
  --feutre: #0d3b2e;
  --feutre-clair: #175843;
  --or: #d9b45b;
  --creme: #f3ecdc;
  --rouge: #c0392b;
  --noir: #1d1d1d;
  --ombre: 0 6px 16px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--creme);
  background:
    radial-gradient(ellipse at 50% 42%, var(--feutre-clair) 0%, var(--feutre) 62%, #07231b 100%);
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* ------------------------------------------------------------ En-tête */

.barre {
  display: flex;
  align-items: center;
  gap: 1.2rem;
  padding: 0.6rem 1.2rem;
  background: rgba(0, 0, 0, 0.28);
  border-bottom: 1px solid rgba(217, 180, 91, 0.25);
  flex-wrap: wrap;
}

.barre h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.5rem;
  letter-spacing: 0.06em;
  color: var(--or);
}

.scores {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  font-variant-numeric: tabular-nums;
}

.score { display: flex; flex-direction: column; line-height: 1.1; }
.score-nom { font-size: 0.7rem; opacity: 0.75; }
.score-valeur { font-size: 1.25rem; font-weight: 600; }
.score[data-joueur="0"] .score-valeur { color: var(--or); }
.score-sep { opacity: 0.4; }

.infos {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  margin-left: auto;
  font-size: 0.85rem;
  opacity: 0.9;
  flex-wrap: wrap;
}

.pastille {
  padding: 0.15rem 0.7rem;
  border-radius: 999px;
  border: 1px solid rgba(217, 180, 91, 0.45);
  white-space: nowrap;
}
.pastille.actif {
  background: var(--or);
  border-color: var(--or);
  color: #1a2b22;
  font-weight: 600;
}

.lien {
  background: none;
  border: 1px solid rgba(217, 180, 91, 0.5);
  color: var(--or);
  border-radius: 999px;
  padding: 0.25rem 0.8rem;
  cursor: pointer;
  font: inherit;
  font-size: 0.85rem;
}
.lien:hover { background: rgba(217, 180, 91, 0.15); }

/* -------------------------------------------------------------- Table */

.table {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(300px, 420px) minmax(280px, 1fr);
  gap: 1.5rem;
  align-items: start;
  justify-content: center;
  padding: 1.2rem 1.2rem 2rem;
}

/* ---------------------------------------------------- Feuille de marque */

.feuille {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
  font-variant-numeric: tabular-nums;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(217, 180, 91, 0.25);
  border-radius: 12px;
  overflow: hidden;
}

.feuille th, .feuille td {
  padding: 0.3rem 0.7rem;
  border-bottom: 1px solid rgba(243, 236, 220, 0.12);
  text-align: right;
  height: 2.1rem;
}
.feuille thead th {
  text-align: right;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  opacity: 0.75;
  background: rgba(0, 0, 0, 0.25);
}
.feuille thead th:first-child { text-align: left; }
.feuille th[scope="row"] {
  text-align: left;
  font-weight: 400;
  opacity: 0.85;
  cursor: help;
}
.feuille td { width: 5.5rem; }

.feuille .prise { font-weight: 600; }
.feuille .prise.nulle { opacity: 0.4; font-weight: 400; }
.feuille .attente { opacity: 0.25; }

/* Une case que l'on vient de remplir s'allume un instant. */
.feuille .fraiche { animation: inscrite 1.1s ease-out; }
@keyframes inscrite {
  0% { background: rgba(217, 180, 91, 0.55); }
  100% { background: transparent; }
}

.feuille .ligne-total th { opacity: 1; font-weight: 600; cursor: default; }
.feuille .ligne-prime { background: rgba(255, 255, 255, 0.04); }
.feuille .ligne-prime td { font-size: 0.85rem; opacity: 0.85; }
.feuille .ligne-forte { background: rgba(0, 0, 0, 0.3); }
.feuille .ligne-forte th, .feuille .ligne-forte td {
  color: var(--or);
  font-weight: 700;
  font-size: 1.02rem;
  border-bottom: none;
}

/* Cases encore libres : l'aperçu du score qu'on y inscrirait. */
.inscrire {
  font: inherit;
  font-variant-numeric: tabular-nums;
  width: 100%;
  padding: 0.1rem 0.35rem;
  border-radius: 7px;
  border: 1px dashed rgba(217, 180, 91, 0.55);
  background: rgba(217, 180, 91, 0.09);
  color: var(--or);
  cursor: pointer;
  text-align: right;
}
.inscrire:hover, .inscrire:focus-visible {
  background: var(--or);
  border-style: solid;
  color: #1a2b22;
  font-weight: 700;
  outline: none;
}
.inscrire.nulle { color: rgba(243, 236, 220, 0.45); border-color: rgba(243, 236, 220, 0.2); }
.inscrire.nulle:hover, .inscrire.nulle:focus-visible {
  background: rgba(192, 57, 43, 0.75);
  border-color: var(--rouge);
  color: var(--creme);
}

/* --------------------------------------------------------------- Piste */

.piste {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.1rem;
  padding-top: 1.5rem;
}

.des {
  display: flex;
  gap: 0.7rem;
  flex-wrap: wrap;
  justify-content: center;
}

.de {
  width: var(--cote-de);
  height: var(--cote-de);
  padding: 0;
  border-radius: 14px;
  border: 2px solid transparent;
  background: #fdfbf5;
  color: var(--noir);
  box-shadow: var(--ombre);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}
.de .face { width: 100%; height: 100%; display: block; }
.de:disabled { cursor: default; }
.de.vide {
  background: rgba(255, 255, 255, 0.07);
  border: 2px dashed rgba(243, 236, 220, 0.25);
  box-shadow: none;
}

/* Un dé gardé sort du tapis : liseré d'or et léger relèvement. */
.de.gardee {
  border-color: var(--or);
  box-shadow: 0 0 0 3px rgba(217, 180, 91, 0.3), var(--ombre);
  transform: translateY(-8px);
}
.de:not(:disabled):hover, .de:not(:disabled):focus-visible {
  transform: translateY(-4px);
  outline: none;
}
.de.gardee:not(:disabled):hover, .de.gardee:not(:disabled):focus-visible {
  transform: translateY(-11px);
}

.de.roule { animation: roule 0.42s ease-out; }
@keyframes roule {
  0% { transform: rotate(-32deg) scale(0.8); opacity: 0.4; }
  55% { transform: rotate(12deg) scale(1.06); opacity: 1; }
  100% { transform: rotate(0) scale(1); }
}

.consigne {
  margin: 0;
  min-height: 1.3rem;
  font-size: 0.9rem;
  opacity: 0.85;
  text-align: center;
  max-width: 24rem;
}

.piste-actions { display: flex; gap: 0.5rem; }

.bouton {
  font: inherit;
  padding: 0.45rem 1.1rem;
  border-radius: 999px;
  border: 1px solid rgba(243, 236, 220, 0.4);
  background: rgba(255, 255, 255, 0.06);
  color: var(--creme);
  cursor: pointer;
}
.bouton:hover { background: rgba(255, 255, 255, 0.16); }
.bouton:disabled { opacity: 0.4; cursor: default; }
.bouton.principal {
  background: var(--or);
  border-color: var(--or);
  color: #1a2b22;
  font-weight: 600;
}
.bouton.principal:hover:not(:disabled) { background: #e7c976; }
.bouton.principal:disabled { background: rgba(217, 180, 91, 0.35); border-color: transparent; }

/* ------------------------------------------------------------ Panneaux */

.panneau {
  position: fixed;
  left: 50%;
  bottom: 50%;
  transform: translate(-50%, 50%);
  background: rgba(8, 32, 25, 0.96);
  border: 1px solid var(--or);
  border-radius: 14px;
  padding: 1.2rem 1.4rem;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  text-align: center;
  z-index: 10;
  max-width: min(92vw, 460px);
}
.panneau-titre { margin: 0 0 0.9rem; font-size: 1.1rem; font-weight: 600; color: var(--or); }
.panneau-actions { display: flex; gap: 0.5rem; justify-content: center; margin-top: 1rem; }
.feuille-fin { background: none; border: none; }
.feuille-fin th[scope="row"] { cursor: default; }

/* ------------------------------------------------------------- Journal */

.journal {
  position: fixed;
  right: 0.8rem;
  bottom: 0.8rem;
  width: min(250px, 42vw);
  max-height: 9.5rem;
  overflow: hidden;
  font-size: 0.75rem;
  line-height: 1.45;
  opacity: 0.75;
  pointer-events: none;
  text-align: right;
}
.journal p { margin: 0; }

dialog {
  border: 1px solid var(--or);
  border-radius: 14px;
  background: #0b2c22;
  color: var(--creme);
  max-width: min(92vw, 540px);
  padding: 1.4rem;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog h2 { margin-top: 0; color: var(--or); font-family: Georgia, serif; }
dialog ul { padding-left: 1.1rem; line-height: 1.55; font-size: 0.9rem; }
dialog li { margin-bottom: 0.4rem; }

/* ---------------------------------------------------------- Responsive */

@media (prefers-reduced-motion: reduce) {
  .de.roule, .feuille .fraiche { animation: none; }
  .de, .de.gardee, .de:hover { transform: none; }
}

@media (max-width: 820px) {
  /* La feuille passe au-dessus de la piste : une seule colonne. */
  .table {
    grid-template-columns: minmax(0, 460px);
    justify-content: center;
    padding: 0.9rem 0.7rem 1.5rem;
    gap: 1rem;
  }
  .piste { order: -1; padding-top: 0.3rem; }
  .journal { display: none; }
}

@media (max-width: 480px) {
  :root { --cote-de: 56px; }
  .barre { gap: 0.6rem; padding: 0.5rem 0.7rem; }
  .barre h1 { font-size: 1.15rem; }
  .infos { width: 100%; margin-left: 0; order: 3; }
  .feuille { font-size: 0.85rem; }
  .feuille th, .feuille td { padding: 0.25rem 0.45rem; }
  .feuille td { width: 4.2rem; }
  .des { gap: 0.45rem; }
}
