/* Lettrix — table de jeu de société : tapis de feutre vert, plateau encadré de
   noyer, cases en carton imprimé, tuiles en buis, actions en laiton.
   Deux éclairages : « jour » (clair) et « soirée » (sombre), même matière. */

:root {
  /* Tapis de jeu et interface */
  --papier: #24503d;          /* feutre : fond de page */
  --feutre-lumiere: #2e6149;  /* halo de la lampe au-dessus de la table */
  --surface: #2c5c47;         /* feutre relevé : champs, dialogues, encarts */
  --grille: #1d4332;          /* feutre en creux : survols, avatars */
  --trait: #3f6e58;           /* coutures, bordures */
  --encre: #f3ecda;           /* craie : texte */
  --encre-douce: #c9d1bd;     /* texte secondaire */
  --accent: #e6c57e;          /* laiton : actions, sélection, tour en cours */
  --accent-fonce: #f0d69e;    /* survol : le laiton s'éclaire */
  --accent-texte: #2a1b10;
  --accent-pale: #3b5f42;     /* reflet de laiton sur le feutre : ligne « moi » */
  /* Plateau et chevalet */
  --bois: #5b3a22;            /* noyer */
  --bois-clair: #744c2d;
  --bois-fonce: #3f2716;
  --case: #dccfae;            /* carton imprimé : case vide */
  --joint-plateau: #b5a47e;
  --repere: #1e5a43;          /* marque sur le carton et le buis : lettre posée, case visée */
  --tuile: #eddbb2;           /* buis */
  --tuile-relief: #c9ab76;    /* tranche de la tuile */
  --tuile-bord: #b89a64;
  --tuile-encre: #2a1b10;
  --tuile-encre-douce: #5e4a33;
  --tuile-joker: #8a3219;
  --tuile-choisie: #f8ebca;
  --mt: #a3412e;              /* mot compte triple */
  --mt-texte: #fbe6dd;
  --md: #dda28d;              /* mot compte double */
  --md-texte: #4e1e13;
  --lt: #2f5f86;              /* lettre compte triple */
  --lt-texte: #e4eff8;
  --ld: #a7c8da;              /* lettre compte double */
  --ld-texte: #18384e;
  --erreur: #fabfac;
  --monte: #a5ddb0;
  --descend: #fabfac;
  --ombre: 8, 22, 15;         /* teinte des ombres, en composantes rgb */
  --bulle-fond: #f3ecda;
  --bulle-texte: #1d2a22;
  --rayon-tuile: 12%;
  --police: "Alegreya Sans", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  --police-titre: "Rokkitt", Rockwell, "Roboto Slab", Georgia, serif;
  color-scheme: dark;
}

/* Soirée : suit le réglage de l'appareil, sauf choix « Clair » ou « Sombre »
   fait dans Réglages (attribut data-theme sur <html>). Même table, lampe tamisée. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --papier: #132a20;
    --feutre-lumiere: #1a3829;
    --surface: #1b372a;
    --grille: #0f241a;
    --trait: #2c4e3d;
    --encre: #e6deca;
    --encre-douce: #afb9a7;
    --accent: #d6b46e;
    --accent-fonce: #e3c78e;
    --accent-texte: #22160c;
    --accent-pale: #2c3e29;
    --bois: #4a2f1b;
    --bois-clair: #5f3e24;
    --bois-fonce: #311e10;
    --case: #c2b594;
    --joint-plateau: #9a8b69;
    --repere: #174a37;
    --tuile: #dac7a0;
    --tuile-relief: #b0955f;
    --tuile-bord: #a08353;
    --tuile-encre: #22160c;
    --tuile-encre-douce: #54412b;
    --tuile-joker: #7c2c15;
    --tuile-choisie: #e9d8b0;
    --mt: #8e3a2a;
    --mt-texte: #f6ddd3;
    --md: #c48e7b;
    --md-texte: #40170e;
    --lt: #2a5474;
    --lt-texte: #dce9f3;
    --ld: #93b3c5;
    --ld-texte: #13304a;
    --erreur: #efa08a;
    --monte: #96cfa1;
    --descend: #efa08a;
    --ombre: 0, 0, 0;
    --bulle-fond: #e6deca;
    --bulle-texte: #132a20;
  }
}
:root[data-theme="dark"] {
  --papier: #132a20;
  --feutre-lumiere: #1a3829;
  --surface: #1b372a;
  --grille: #0f241a;
  --trait: #2c4e3d;
  --encre: #e6deca;
  --encre-douce: #afb9a7;
  --accent: #d6b46e;
  --accent-fonce: #e3c78e;
  --accent-texte: #22160c;
  --accent-pale: #2c3e29;
  --bois: #4a2f1b;
  --bois-clair: #5f3e24;
  --bois-fonce: #311e10;
  --case: #c2b594;
  --joint-plateau: #9a8b69;
  --repere: #174a37;
  --tuile: #dac7a0;
  --tuile-relief: #b0955f;
  --tuile-bord: #a08353;
  --tuile-encre: #22160c;
  --tuile-encre-douce: #54412b;
  --tuile-joker: #7c2c15;
  --tuile-choisie: #e9d8b0;
  --mt: #8e3a2a;
  --mt-texte: #f6ddd3;
  --md: #c48e7b;
  --md-texte: #40170e;
  --lt: #2a5474;
  --lt-texte: #dce9f3;
  --ld: #93b3c5;
  --ld-texte: #13304a;
  --erreur: #efa08a;
  --monte: #96cfa1;
  --descend: #efa08a;
  --ombre: 0, 0, 0;
  --bulle-fond: #e6deca;
  --bulle-texte: #132a20;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  min-height: 100vh;
  /* la lampe éclaire le haut de la table, le feutre s'assombrit vers les bords */
  background: radial-gradient(120% 70% at 50% 0%, var(--feutre-lumiere), var(--papier) 75%) var(--papier);
  color: var(--encre);
  font-family: var(--police);
  font-size: 1.0625rem;
  font-feature-settings: "lnum" 1;   /* chiffres alignés : scores et tableaux */
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

button { font: inherit; color: inherit; }
input, select, textarea { color: var(--encre); }
::placeholder { color: var(--encre-douce); opacity: 1; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Tuile ---------- */

.tuile {
  position: relative;
  display: inline-grid;
  place-items: center;
  aspect-ratio: 1;
  border-radius: var(--rayon-tuile);
  background: var(--tuile);
  color: var(--tuile-encre);
  font-family: var(--police-titre);
  font-weight: 700;
  line-height: 1;
  /* tuile de buis : bord fin et tranche plus foncée en bas */
  box-shadow: inset 0 -0.09em 0 var(--tuile-relief), inset 0 0 0 1px var(--tuile-bord);
  user-select: none;
  touch-action: none;
}

.tuile sub {
  position: absolute;
  right: 8%;
  bottom: 6%;
  font-family: var(--police);
  font-size: 0.38em;
  letter-spacing: -0.06em;   /* « 10 » (K, W, X, Y, Z) reste à l'écart de la lettre */
  font-weight: 600;
  line-height: 1;
  color: var(--tuile-encre-douce);
}

.tuile.joker { color: var(--tuile-joker); font-style: italic; }
/* Valeur à deux chiffres (K, W, X, Y, Z = 10) : la lettre se décale pour lui laisser la place */
.tuile.valeur-longue { padding-right: 0.22em; }
.tuile.joker-vierge::after { content: "?"; }

/* ---------- Pages (connexion, tableau de bord…) ---------- */

.page-etroite, .page-moyenne, .page-large {
  margin: 0 auto;
  padding: max(2rem, env(safe-area-inset-top)) 1rem 3rem;
}

.page-etroite { max-width: 28rem; }
.page-moyenne { max-width: 44rem; }
.page-large { max-width: 56rem; }

h1, h2 { font-family: var(--police-titre); font-weight: 700; letter-spacing: 0.005em; }
h1 { font-size: 2rem; line-height: 1.1; margin: 0 0 1rem; }
h2 { font-size: 1.3rem; line-height: 1.2; margin: 0; }

a { color: var(--accent); text-underline-offset: 3px; }

.titre-jeu {
  display: flex;
  gap: 0.5rem;
  margin: 1rem 0 2rem;
  font-size: clamp(1.6rem, 8.5vw, 2.6rem);
}

.tuile-titre { width: 1.3em; }

.note { color: var(--encre-douce); margin: 1.25rem 0; max-width: 60ch; }
.aide { color: var(--encre-douce); font-weight: 400; }

.formulaire { display: grid; gap: 1rem; }

.formulaire label {
  display: grid;
  gap: 0.35rem;
  font-weight: 600;
}

.formulaire input:not([type="radio"]):not([type="checkbox"]) {
  width: 100%;
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--trait);
  border-radius: 6px;
  background: var(--surface);
  font: inherit;
  font-weight: 400;
}

.formulaire input:focus-visible { outline: none; border-color: var(--accent); }

.formulaire fieldset { border: 0; margin: 0; padding: 0; }
.formulaire legend { font-weight: 700; margin-bottom: 0.5rem; }

.choix { display: flex; flex-wrap: wrap; gap: 0.5rem 1.25rem; }
.choix legend { flex-basis: 100%; }
.choix label { display: flex; align-items: center; gap: 0.4rem; font-weight: 500; min-height: 44px; }
.choix input { width: 1.2rem; height: 1.2rem; accent-color: var(--accent); }

.liste-invites {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr));
  gap: 0.25rem 1rem;
  max-height: 18rem;
  overflow-y: auto;
  margin-top: 0.6rem;
}

.formulaire .liste-invites label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 40px;
  font-weight: 500;
}

.liste-invites input { width: 1.15rem; height: 1.15rem; accent-color: var(--accent); }

.message-erreur { color: var(--erreur); min-height: 1.45em; margin: 0; }
.message-erreur:empty { min-height: 0; }

.retour { font-weight: 600; }
.retour::before { content: "‹ "; }

/* ---------- Tableau de bord ---------- */

.entete-page {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem 1rem;
  margin-bottom: 1.5rem;
}

.entete-page h1 { margin: 0; }
.compte { display: flex; gap: 1rem; align-items: baseline; flex-wrap: wrap; color: var(--encre-douce); }

/* ---------- Avatars ---------- */

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.6rem;
  height: 1.6rem;
  vertical-align: -0.35rem;
  border-radius: 6px;
  background: var(--grille);
  color: var(--encre-douce);
}

.avatar svg { width: 78%; height: 78%; fill: currentColor; }
.avatar svg .trou { fill: var(--grille); }  /* évidement du dessin, couleur du fond de l'avatar */
.avatar-petit { width: 1.25rem; height: 1.25rem; vertical-align: -0.25rem; border-radius: 5px; }
.avatar-vide { font-weight: 700; font-size: 0.85rem; color: var(--encre-douce); }
.avatar-nom { display: inline-flex; align-items: center; }

.bloc { margin-bottom: 2rem; }
.bloc > h2 { margin-bottom: 0.5rem; }

.bloc-entete {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.5rem;
}

.compteur { color: var(--encre-douce); font-weight: 500; font-variant-numeric: tabular-nums; }

.bloc-entete .bouton { text-decoration: none; display: inline-flex; align-items: center; }
.bouton[aria-disabled="true"] { opacity: 0.45; pointer-events: none; }

.liste-parties { list-style: none; margin: 0; padding: 0; }

.liste-parties > li {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.8rem 0;
  border-bottom: 1px solid var(--trait);
}

.liste-parties:empty::before {
  content: attr(data-vide);
  display: block;
  padding: 0.8rem 0;
  color: var(--encre-douce);
}

.ligne-partie { flex: 1; min-width: 0; color: inherit; text-decoration: none; }
.ligne-partie:hover .adversaires { text-decoration: underline; }

.adversaires { display: block; font-weight: 600; }
.etat-partie { display: block; color: var(--encre-douce); font-size: 0.95rem; }

/* La partie où c'est à moi de jouer porte une pastille jaune */
.liste-parties > li.a-moi { box-shadow: inset 3px 0 0 var(--accent); padding-left: 0.85rem; }
.liste-parties > li.a-moi .etat-partie { color: var(--encre); font-weight: 600; }
.liste-parties > li.urgent { box-shadow: inset 4px 0 0 var(--erreur); }
.liste-parties > li.urgent .etat-partie { color: var(--erreur); }

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

/* ---------- Boutons ---------- */

.bouton {
  min-height: 44px;
  padding: 0.55rem 0.95rem;
  border: 1px solid var(--trait);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
  font-weight: 500;
}

.bouton:hover:not(:disabled) { border-color: var(--encre-douce); }
.bouton:disabled { opacity: 0.45; cursor: not-allowed; }

/* Laiton : un seul bouton principal par écran */
.bouton-principal {
  background: linear-gradient(180deg, var(--accent-fonce), var(--accent));
  border-color: var(--accent);
  color: var(--accent-texte);
  font-weight: 700;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 2px 4px rgba(var(--ombre), 0.35);
}

.bouton-principal:hover:not(:disabled) { background: var(--accent-fonce); border-color: var(--accent-fonce); }

.bouton-lien {
  padding: 0.25rem 0;
  border: 0;
  background: none;
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  font-weight: 600;
}

.bouton-retirer {
  width: 44px;
  height: 44px;
  border: 0;
  background: none;
  color: var(--encre-douce);
  font-size: 1.4rem;
  cursor: pointer;
}

/* ---------- Mise en page de la partie ---------- */

.jeu {
  display: grid;
  gap: 0.75rem;
  max-width: 34rem;
  margin: 0 auto;
  padding: max(0.75rem, env(safe-area-inset-top)) 1rem max(1rem, env(safe-area-inset-bottom));
  grid-template-areas:
    "bandeau"
    "plateau"
    "joueur"
    "historique";
}

.bandeau { grid-area: bandeau; }
.zone-plateau { grid-area: plateau; }
.zone-joueur { grid-area: joueur; }
.zone-historique { grid-area: historique; }

@media (min-width: 900px) {
  .jeu {
    max-width: 72rem;
    gap: 1rem 2rem;
    padding-top: 1.5rem;
    grid-template-columns: minmax(0, 40rem) minmax(16rem, 1fr);
    grid-template-areas:
      "plateau bandeau"
      "plateau joueur"
      "plateau historique";
    grid-template-rows: auto auto 1fr;
    align-items: start;
  }
}

/* ---------- Bandeau des scores ---------- */

.bandeau .retour { flex-basis: 100%; }

.bandeau {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
}

.scores {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.score {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  padding: 0.2rem 0 0.15rem;
  border-bottom: 3px solid transparent;
  color: var(--encre-douce);
}

.score strong { color: var(--encre); font-size: 1.2rem; font-variant-numeric: tabular-nums; }

.score.courant { border-bottom-color: var(--accent); color: var(--encre); font-weight: 600; }

.sac { margin: 0; color: var(--encre-douce); font-variant-numeric: tabular-nums; }
.sac span:first-child { color: var(--encre); font-weight: 700; }

/* ---------- Plateau ---------- */

.plateau {
  display: grid;
  grid-template-columns: repeat(15, minmax(0, 1fr));
  grid-template-rows: repeat(15, minmax(0, 1fr));
  gap: 2px;
  width: 100%;
  aspect-ratio: 1;
  padding: 2px;
  border-radius: 2px;
  background: var(--joint-plateau);
  /* taille des lettres proportionnelle à la case (× 2 quand la grille est zoomée) */
  font-size: min(calc((100vw - 2rem) / 15 * 0.55 * var(--zoom, 1)), calc(1.45rem * var(--zoom, 1)));
  /* le double-toucher sert à zoomer la grille, pas la page */
  touch-action: manipulation;
}

/* Les lettres déjà jouées laissent faire défiler la grille zoomée */
.case > .tuile:not(.provisoire) { touch-action: manipulation; }

.zone-plateau { display: flex; flex-direction: column; }

/* Cadre en noyer : fil du bois, arête claire, ombre portée sur le feutre */
.cadre-plateau {
  padding: clamp(0.3rem, 1.6vw, 0.7rem);
  border-radius: 8px;
  background:
    repeating-linear-gradient(97deg, transparent 0 7px, rgba(0, 0, 0, 0.07) 7px 9px, transparent 9px 16px, rgba(255, 255, 255, 0.04) 16px 17px),
    linear-gradient(180deg, var(--bois-clair), var(--bois) 40%, var(--bois-fonce));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.14),
    inset 0 0 0 1px rgba(0, 0, 0, 0.35),
    0 10px 24px rgba(var(--ombre), 0.45);
}

/* Sous la grille, à droite : ne cache aucune case */
.bouton-zoom {
  align-self: flex-end;
  margin-top: 0.35rem;
  min-height: 2rem;
  padding: 0.2rem 0.75rem;
  border: 1px solid var(--trait);
  border-radius: 999px;
  background: var(--surface);
  color: var(--accent);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

/* Smartphone et tablette : grille zoomable, chevalet fixé en bas de l'écran */
@media (max-width: 899.98px) {
  .cadre-plateau.zoom {
    aspect-ratio: 1;
    overflow: auto;
    overscroll-behavior: contain;
  }
  .cadre-plateau.zoom .plateau { --zoom: 2; width: 200%; }

  .zone-joueur {
    position: sticky;
    bottom: 0;
    z-index: 10;
    margin: 0 -1rem;
    padding: 0.5rem 1rem max(0.6rem, env(safe-area-inset-bottom));
    background: var(--papier);
    box-shadow: 0 -4px 10px rgba(var(--ombre), 0.08);
  }
  .zone-joueur .statut-tour { margin: 0 0 0.25rem; font-size: 0.9rem; }
  .zone-joueur .apercu { min-height: 0; margin-bottom: 0.4rem; }
  .zone-joueur .apercu:empty { display: none; }
  .zone-joueur .chevalet { margin-bottom: 0.5rem; }
}

@media (min-width: 900px) {
  .plateau { font-size: 1.45rem; }
  .bouton-zoom { display: none; }
}

.case {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  padding: 0;
  border: 0;
  border-radius: 2px;
  background: var(--case);
  cursor: pointer;
}

.case .libelle {
  font-family: var(--police);
  font-size: 0.42em;
  font-weight: 700;
  letter-spacing: 0.02em;
  pointer-events: none;
}

.case.MT { background: var(--mt); color: var(--mt-texte); }
.case.MD { background: var(--md); color: var(--md-texte); }
.case.LT { background: var(--lt); color: var(--lt-texte); }
.case.LD { background: var(--ld); color: var(--ld-texte); }
.case.depart .libelle { font-size: 0.7em; color: var(--tuile-encre-douce); }

/* Une lettre est sélectionnée : seule la case survolée (ou atteinte au clavier) est marquée */
.case.cible:hover,
.case.cible:focus-visible { box-shadow: inset 0 0 0 2px var(--repere); outline: none; }

.case > .tuile {
  width: 100%;
  height: 100%;
  aspect-ratio: auto;
  font-size: 1em;
  border-radius: 3px;
}

.case > .tuile.provisoire {
  background: var(--tuile-choisie);
  box-shadow: inset 0 0 0 2px var(--repere);
  cursor: grab;
}

.case > .tuile.dernier-coup { box-shadow: inset 0 0 0 2px var(--tuile-encre-douce); }

/* Coup choisi dans l'historique */
.case > .tuile.coup-vu { background: var(--accent); color: var(--accent-texte); box-shadow: none; }
.case > .tuile.coup-vu sub { color: var(--accent-texte); }

/* ---------- Chevalet ---------- */

.apercu {
  min-height: 1.45em;
  margin: 0 0 0.6rem;
  font-weight: 600;
}

.apercu.invalide { color: var(--erreur); font-weight: 500; }
.apercu.valide strong { font-size: 1.15rem; }

.chevalet {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 0.35rem;
  min-height: 2.5rem;
  padding: 0.45rem 0.5rem 0.7rem;
  margin-bottom: 0.75rem;
  border-radius: 6px 6px 4px 4px;
  /* chevalet de noyer : la lèvre du bas retient les tuiles */
  background:
    linear-gradient(0deg, var(--bois-fonce) 0 0.3rem, transparent 0.3rem),
    repeating-linear-gradient(92deg, transparent 0 9px, rgba(0, 0, 0, 0.07) 9px 11px, transparent 11px 19px),
    linear-gradient(180deg, var(--bois-clair), var(--bois));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12), 0 6px 14px rgba(var(--ombre), 0.35);
  font-size: clamp(1.2rem, 6vw, 1.8rem);
}

.chevalet .tuile {
  width: 100%;
  border: 0;
  padding: 0;
  cursor: grab;
  transition: transform 120ms ease-out;
}

.chevalet .tuile.choisie {
  transform: translateY(-14%);
  background: var(--tuile-choisie);
  box-shadow: inset 0 0 0 2px var(--repere), 0 4px 6px rgba(var(--ombre), 0.35);
}
.chevalet .tuile.a-echanger { background: var(--grille); color: var(--encre-douce); box-shadow: inset 0 0 0 1px var(--trait); text-decoration: line-through; }

/* Repère d'insertion quand on range une lettre dans le chevalet */
.chevalet .tuile.insertion-avant { box-shadow: inset 3px 0 0 var(--repere), inset 0 0 0 1px var(--tuile-bord); }
.chevalet .tuile.insertion-apres { box-shadow: inset -3px 0 0 var(--repere), inset 0 0 0 1px var(--tuile-bord); }

.tuile.fantome {
  position: fixed;
  z-index: 50;
  width: 2.6rem;
  font-size: 1.6rem;
  pointer-events: none;
  transform: translate(-50%, -60%) scale(1.1);
  box-shadow: 0 6px 14px rgba(var(--ombre), 0.25);
}

.tuile.en-deplacement { opacity: 0.3; }

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.actions .bouton-principal { margin-left: auto; min-width: 7rem; }

.consigne { flex-basis: 100%; margin: 0; color: var(--encre-douce); }

/* ---------- Vérifier un mot ---------- */

.verifier-mot { margin: 0.25rem 0 0.5rem; }
.verifier-mot label { display: block; margin-bottom: 0.3rem; font-weight: 600; }
.ligne-verifier { display: flex; gap: 0.5rem; }
.ligne-verifier input {
  flex: 1;
  min-width: 0;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--trait);
  border-radius: 6px;
  background: var(--surface);
  font: inherit;
  text-transform: uppercase;
}
.ligne-verifier input:focus-visible { outline: none; border-color: var(--accent); }
.resultat-verifier { min-height: 1.3em; margin: 0.35rem 0 0; font-weight: 600; }
.resultat-verifier:empty { min-height: 0; }
.resultat-verifier.invalide { color: var(--erreur); }

/* ---------- Lettres restantes ---------- */

.restantes {
  margin-bottom: 0.75rem;
  border-bottom: 1px solid var(--trait);
}

.restantes summary {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.2rem 0.4rem;
  min-height: 44px;
  padding: 0.6rem 0;
  font-weight: 600;
  cursor: pointer;
}

.restantes summary strong { font-variant-numeric: tabular-nums; }
.restantes-resume { flex-basis: 100%; color: var(--encre-douce); font-size: 0.9rem; font-weight: 400; }
.note-restantes { margin: 0 0 0.5rem; color: var(--encre-douce); font-size: 0.9rem; }

.grille-restantes {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(3.1rem, 1fr));
  gap: 0.4rem;
  margin: 0 0 0.9rem;
  padding: 0;
  list-style: none;
}

.restante {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.restante .tuile { width: 1.75rem; font-size: 1rem; flex: none; }
.restante .nombre { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 0.95rem; }
.restante.epuisee { opacity: 0.4; }
.restante.epuisee .nombre { text-decoration: line-through; }

/* ---------- Historique ---------- */

.zone-historique h2 { margin: 0.5rem 0 0.5rem; font-size: 1rem; }

.historique {
  margin: 0;
  padding: 0;
  list-style: none;
  color: var(--encre-douce);
  font-size: 0.95rem;
}

.historique li {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.35rem 0.4rem;
  border-bottom: 1px solid var(--trait);
}

.historique li strong { color: var(--encre); }
.historique .points { font-variant-numeric: tabular-nums; color: var(--encre); font-weight: 600; }
/* Coup posé : toute la ligne se touche pour le revoir sur la grille */
.historique li.revoir { padding: 0; }
.ligne-coup {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  width: 100%;
  min-height: 44px;
  padding: 0.35rem 0.4rem;
  border: 0;
  border-radius: 4px;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  align-items: center;
  cursor: pointer;
}
.ligne-coup:hover { background: var(--grille); }
.ligne-coup[aria-pressed="true"] { background: var(--accent-pale); box-shadow: inset 3px 0 0 var(--accent); }

.historique:empty::before { content: "Aucun coup pour l'instant."; }

/* ---------- Statut du tour, bulle d'information ---------- */

.statut-tour { margin: 0 0 0.35rem; font-weight: 600; }
.statut-tour.attente { color: var(--encre-douce); font-weight: 500; }
.statut-tour.urgent { color: var(--erreur); }

.echeance-partie { flex-basis: 100%; margin: 0; color: var(--encre-douce); font-size: 0.95rem; }
.echeance-partie:empty { display: none; }

.score.forfait strong { text-decoration: line-through; }
.score.forfait { opacity: 0.65; }

.bulle {
  position: fixed;
  left: 50%;
  bottom: max(1rem, env(safe-area-inset-bottom));
  z-index: 60;
  max-width: calc(100vw - 2rem);
  padding: 0.75rem 1.1rem;
  border-radius: 6px;
  background: var(--bulle-fond);
  color: var(--bulle-texte);
  font-weight: 500;
  transform: translateX(-50%);
  box-shadow: 0 4px 12px rgba(var(--ombre), 0.2);
}

/* ---------- Dialogues ---------- */

.dialogue {
  width: min(26rem, calc(100vw - 2rem));
  padding: 1.25rem;
  border: 1px solid var(--trait);
  border-radius: 8px;
  background: var(--surface);
  color: var(--encre);
  box-shadow: 0 18px 40px rgba(var(--ombre), 0.5);
}

.dialogue::backdrop { background: rgba(var(--ombre), 0.45); }
.dialogue h2 { margin: 0 0 1rem; font-size: 1.25rem; }

.lettres-joker {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.35rem;
  margin-bottom: 1rem;
  font-size: 1.3rem;
}

.lettres-joker .tuile { width: 100%; border: 0; cursor: pointer; }

.fin-scores { margin: 0 0 1.25rem; padding-left: 1.4rem; font-size: 1.1rem; }
.fin-scores li { padding: 0.2rem 0; }

/* ---------- Réglages ---------- */

.dialogue-large { width: min(32rem, calc(100vw - 2rem)); }

.reglages { border: 0; margin: 0 0 1rem; padding: 0; }
.reglages legend { font-weight: 700; padding: 0; margin-bottom: 0.5rem; }
.reglages .note { margin: 0.25rem 0 0.75rem; }
.reglages label { display: grid; gap: 0.35rem; font-weight: 600; }
.reglages input[type="email"] {
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--trait);
  border-radius: 8px;
  font: inherit;
  font-weight: 400;
}

.lignes-prefs { display: grid; gap: 0.35rem; }
.ligne-pref {
  display: grid;
  grid-template-columns: 1fr 3.5rem 3.5rem;
  align-items: center;
  gap: 0.5rem;
}
.ligne-pref.entete {
  color: var(--encre-douce);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.ligne-pref input { justify-self: center; width: 1.15rem; height: 1.15rem; }

.choix-avatar {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(8.5rem, 1fr));
  gap: 0.4rem;
}

.choix-avatar-item {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--trait);
  border-radius: 9px;
  background: var(--surface);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.choix-avatar-item.choisi { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.choix-avatar-item span:last-child { font-size: 0.9rem; }

/* ---------- Statistiques et classement ---------- */

.stats { display: grid; gap: 0.3rem; margin: 0 0 1.25rem; }
.stats div {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.3rem 0;
  border-bottom: 1px solid var(--trait);
}
.stats dt { color: var(--encre-douce); }
.stats dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }

.classement { list-style: none; margin: 0; padding: 0; }
.classement:empty::before { content: attr(data-vide); color: var(--encre-douce); }
.classement li {
  display: grid;
  grid-template-columns: 2rem 1fr auto;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--trait);
}
.classement .rang { font-weight: 700; color: var(--encre-douce); font-variant-numeric: tabular-nums; }
.classement .qui { display: flex; align-items: center; gap: 0.5rem; font-weight: 600; }
.classement .bilan { color: var(--encre-douce); font-size: 0.95rem; text-align: right; }

/* ---------- Administration ---------- */

.formulaire-ligne {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.formulaire-ligne label { display: grid; gap: 0.25rem; font-weight: 600; }

.formulaire-ligne input {
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--trait);
  border-radius: 8px;
  font: inherit;
  font-weight: 400;
}

.tableau-defilant { overflow-x: auto; }

.tableau-admin { width: 100%; min-width: 34rem; border-collapse: collapse; font-size: 0.95rem; }

.tableau-admin th {
  padding: 0.4rem 0.5rem;
  text-align: left;
  color: var(--encre-douce);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 2px solid var(--trait);
}

.tableau-admin td { padding: 0.45rem 0.5rem; border-bottom: 1px solid var(--trait); vertical-align: middle; }

.compte-nom { display: flex; align-items: center; flex-wrap: wrap; gap: 0.45rem; font-weight: 600; }
.compte-email { color: var(--encre-douce); font-size: 0.9rem; font-weight: 400; }
.etat-bloque { color: var(--erreur); font-weight: 600; }

.actions-compte { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.bouton-petit { padding: 0.3rem 0.55rem; font-size: 0.9rem; }

.filtre-statut { display: flex; align-items: center; gap: 0.4rem; color: var(--encre-douce); }

.filtre-statut select {
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--trait);
  border-radius: 8px;
  background: var(--surface);
  font: inherit;
}

.formulaire-reglages {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: 0.75rem;
  align-items: end;
  margin-bottom: 0.5rem;
}

.formulaire-reglages label { display: grid; gap: 0.25rem; font-weight: 600; }

.formulaire-reglages input[type="number"] {
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--trait);
  border-radius: 8px;
  font: inherit;
  font-weight: 400;
}

.formulaire-reglages .case { display: flex; align-items: center; gap: 0.4rem; }
.formulaire-reglages button { justify-self: start; }

.code-activation {
  margin: 0.5rem 0 1.25rem;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 1.6rem;
  letter-spacing: 0.15em;
  text-align: center;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ---------- Tournoi ---------- */

.visuellement-cache {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.formulaire textarea {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--trait);
  border-radius: 6px;
  background: var(--surface);
  font: 0.95rem/1.4 ui-monospace, Consolas, monospace;
  font-weight: 400;
  resize: vertical;
}

.formulaire textarea:focus-visible { outline: none; border-color: var(--accent); }

.onglets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0 0 1rem;
  border-bottom: 2px solid var(--trait);
}

.onglet {
  min-height: 44px;
  padding: 0.5rem 0.9rem;
  border: 0;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  background: none;
  color: var(--encre-douce);
  font-weight: 600;
  cursor: pointer;
}

.onglet[aria-selected="true"] { color: var(--encre); border-bottom-color: var(--encre); }

.tableau-classement {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.tableau-classement th,
.tableau-classement td {
  padding: 0.45rem 0.4rem;
  border-bottom: 1px solid var(--trait);
  text-align: right;
}

.tableau-classement thead th {
  color: var(--encre-douce);
  font-size: 0.85rem;
  font-weight: 600;
  border-bottom-width: 2px;
}

.tableau-classement abbr { text-decoration: none; cursor: help; }
.tableau-classement th[scope="row"],
.tableau-classement thead th:nth-child(2),
.tableau-classement thead th#entete-issue { text-align: left; }
.tableau-classement .abandon { color: var(--encre-douce); font-weight: 400; font-size: 0.85rem; font-style: italic; }
.tableau-classement th[scope="row"] { font-weight: 600; }
.tableau-classement .place { color: var(--encre-douce); font-weight: 400; font-size: 0.85rem; }
.tableau-classement .rang { color: var(--encre-douce); }
.tableau-classement .points { font-weight: 700; }
.tableau-classement .suite { text-align: left; white-space: nowrap; font-size: 0.9rem; }
.tableau-classement .monte { color: var(--monte); }
.tableau-classement .descend { color: var(--descend); }
.tableau-classement tr.moi { background: var(--accent-pale); }
.tableau-classement tr.moi th[scope="row"],
.tableau-classement tr.moi .points { color: var(--encre); }

.liste-matchs { list-style: none; margin: 0; padding: 0; }

.liste-matchs:empty::before {
  content: attr(data-vide);
  color: var(--encre-douce);
}

.liste-matchs li {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--trait);
  font-variant-numeric: tabular-nums;
}

.liste-matchs li.moi { font-weight: 600; }
.match-etat { color: var(--encre-douce); font-weight: 400; white-space: nowrap; }

.etiquette-tournoi {
  display: inline-block;
  padding: 0 0.4rem;
  border: 1px solid var(--trait);
  border-radius: 4px;
  color: var(--encre-douce);
  font-size: 0.8rem;
  font-weight: 600;
  vertical-align: 0.1em;
}

.info-tournoi { margin: 0; flex-basis: 100%; color: var(--encre-douce); font-size: 0.95rem; }

/* Écran étroit : l'essentiel (rang, joueur, J, V, GA, points, suite) tient sans défilement */
@media (max-width: 30rem) {
  .tableau-classement { font-size: 0.9rem; }
  .tableau-classement .secondaire { display: none; }
  .tableau-classement th, .tableau-classement td { padding: 0.45rem 0.25rem; }
}

/* Phase 2 : sous-onglets, duels */
.onglets-etapes { border-bottom-width: 1px; }
.onglets-etapes .onglet { min-height: 40px; font-size: 0.95rem; }
.sous-titre { font-size: 1rem; margin: 1.25rem 0 0.25rem; }
.duel-libelle { color: var(--encre-douce); font-weight: 400; white-space: nowrap; }
.liste-matchs li { align-items: baseline; }
.liste-matchs li .duel-libelle + .match-joueurs { flex: 1; }

.note-formulaire { margin: 0; font-size: 0.9rem; }

.version-appli { margin: 2.5rem 0 0; color: var(--encre-douce); font-size: 0.8rem; text-align: center; }

/* ---------- Discussion d'une partie ---------- */

.discussion {
  margin-bottom: 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--trait);
}
.zone-historique .discussion h2 { margin-top: 0; }

.messages {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  max-height: 16rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  margin: 0 0 0.6rem;
  padding: 0;
  list-style: none;
}
.messages:empty::before { content: "Aucun message pour l'instant."; color: var(--encre-douce); font-size: 0.95rem; }

.message {
  align-self: flex-start;
  max-width: 88%;
  padding: 0.35rem 0.6rem;
  border: 1px solid var(--trait);
  border-radius: 8px;
  background: var(--surface);
}
.message.moi { align-self: flex-end; background: var(--accent-pale); border-color: transparent; }
.message.masque .message-texte { color: var(--encre-douce); font-style: italic; }

.message-entete {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  margin: 0;
  color: var(--encre-douce);
  font-size: 0.8rem;
}
.message-entete strong { color: var(--encre); }
.message-texte { margin: 0.1rem 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }

.lien-signaler {
  margin-left: auto;
  padding: 0.1rem 0.2rem;
  border: 0;
  background: none;
  color: var(--encre-douce);
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}
.lien-signaler:hover { color: var(--erreur); }
.message-signale { margin-left: auto; font-style: italic; }

.phrases {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.5rem;
}
.phrase {
  min-height: 36px;
  padding: 0.25rem 0.65rem;
  border: 1px solid var(--trait);
  border-radius: 999px;
  background: var(--surface);
  color: var(--encre);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}
.phrase:hover { border-color: var(--accent); color: var(--accent); }

.form-message { display: flex; gap: 0.5rem; align-items: flex-end; }
.form-message textarea {
  flex: 1;
  min-width: 0;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--trait);
  border-radius: 6px;
  background: var(--surface);
  color: var(--encre);
  font: inherit;
  resize: vertical;
}
.form-message textarea:focus-visible { outline: none; border-color: var(--accent); }
.discussion .message-erreur:empty { display: none; }
.note-messagerie { margin: 0; color: var(--encre-douce); font-size: 0.9rem; }

/* Tableau de bord : messages non lus */
.etiquette-messages {
  display: inline-block;
  padding: 0 0.45rem;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-texte);
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
}

/* Administration : messages signalés */
.texte-signale { white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---------- Revanche ---------- */

.bouton-revanche { width: 100%; margin-top: 0.25rem; }
.actions-fin { display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: flex-end; }

/* Tableau de bord : dernier coup joué */
.dernier-coup-tableau {
  display: block;
  color: var(--encre-douce);
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- Apparence (Réglages) ---------- */

.choix-theme { display: flex; flex-wrap: wrap; gap: 0.35rem 1.25rem; }
.reglages .choix-theme label { display: inline-flex; align-items: center; gap: 0.4rem; font-weight: 400; }
.choix-theme input { width: 1.1rem; height: 1.1rem; accent-color: var(--accent); }

/* ---------- Palmarès du tournoi ---------- */

.liens-haut { display: flex; flex-wrap: wrap; gap: 0.5rem 1.25rem; }
.liens-haut a:not(.retour) { color: var(--accent); font-weight: 600; text-underline-offset: 3px; }

.tableau-honneur thead th:first-child { text-align: left; }
.tableau-honneur thead th:nth-child(2) { text-align: right; }
.tableau-honneur .editions,
.tableau-honneur thead th.editions { text-align: left; color: var(--encre-douce); font-size: 0.9rem; }
.tableau-honneur td.editions { font-weight: 400; }
.moi-nom { font-weight: 700; color: var(--encre); }

.edition { padding-top: 1.25rem; border-top: 1px solid var(--trait); }
.edition > h2 { margin: 0; }
.date-edition { margin: 0.2rem 0 0.75rem; }

.ligue-palmares { margin-bottom: 1rem; }
.ligue-palmares .sous-titre { margin: 0.75rem 0 0.4rem; }

.podiums {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
  gap: 0.75rem;
}
.podium {
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--trait);
  border-radius: 8px;
  background: var(--surface);
}
.podium-groupe { margin: 0 0 0.35rem; color: var(--encre-douce); font-size: 0.85rem; font-weight: 600; }
.podium ol { margin: 0; padding: 0; list-style: none; }
.podium li {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  padding: 0.25rem 0;
}
.podium .rang {
  min-width: 2.2rem;
  color: var(--encre-douce);
  font-size: 0.85rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.podium .rang-1 { color: var(--accent); }
.podium .points { margin-left: auto; color: var(--encre-douce); font-variant-numeric: tabular-nums; font-size: 0.9rem; }

.mouvements {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.25rem 0.9rem;
  margin: 0.5rem 0 0;
  font-size: 0.95rem;
}
.mouvements dt { color: var(--encre-douce); font-weight: 600; }
.mouvements dd { margin: 0; }
@media (max-width: 30rem) {
  .mouvements { grid-template-columns: 1fr; }
  .mouvements dd { margin-bottom: 0.4rem; }
}

/* ---------- Fiche d'un joueur ---------- */

.lien-joueur { color: inherit; text-decoration: none; }
.lien-joueur:hover, .lien-joueur:focus-visible { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }

.entete-fiche { display: flex; align-items: center; gap: 0.9rem; margin-bottom: 1.5rem; }
.entete-fiche .avatar { width: 3rem; height: 3rem; border-radius: 10px; }
.entete-fiche .avatar-vide { font-size: 1.4rem; }
.entete-fiche h1 { margin: 0; }
.entete-fiche .note { margin: 0.15rem 0 0; }

.bilan-face { margin: 0 0 0.5rem; font-weight: 600; }
.liste-matchs a.match-joueurs { color: inherit; text-underline-offset: 3px; }
.liste-matchs li.resultat-victoire { box-shadow: inset 3px 0 0 var(--monte); padding-left: 0.6rem; }
.liste-matchs li.resultat-defaite { box-shadow: inset 3px 0 0 var(--descend); padding-left: 0.6rem; }
.liste-matchs li.resultat-nul { box-shadow: inset 3px 0 0 var(--trait); padding-left: 0.6rem; }

/* Administration : export Excel du tournoi */
.exports { margin-top: 1.25rem; }
.exports .actions a { text-decoration: none; }

/* ---------- Accessibilité ---------- */

/* Case active de la grille au clavier : bien visible, même sur une case bonus */
.case:focus-visible { outline: 3px solid var(--tuile-encre); outline-offset: -1px; z-index: 1; }

.aide-clavier { margin-top: 1rem; color: var(--encre-douce); font-size: 0.9rem; }
.aide-clavier summary { min-height: 44px; display: flex; align-items: center; font-weight: 600; cursor: pointer; }
.aide-clavier ul { margin: 0; padding-left: 1.2rem; }
.aide-clavier li { margin: 0.2rem 0; }

/* ---------- Guide du joueur ---------- */

.guide .bloc { max-width: 65ch; scroll-margin-top: 1rem; }
.guide ul { padding-left: 1.2rem; }
.guide li { margin: 0.35rem 0; }
.sommaire { margin: 0 0 2rem; padding: 0.75rem 1rem; border: 1px solid var(--trait); border-radius: 8px; background: var(--surface); }
.sommaire ol { margin: 0; padding-left: 1.3rem; columns: 2 16rem; }
.sommaire li { margin: 0.2rem 0; }
.sommaire a { color: var(--accent); text-underline-offset: 3px; }
.legende-bonus { list-style: none; padding-left: 0 !important; }
.legende-bonus li { display: flex; align-items: center; gap: 0.6rem; }
.case-exemple {
  display: inline-grid; place-items: center; width: 2rem; height: 2rem; border-radius: 3px;
  font-size: 0.7rem; font-weight: 700;
}
.case-exemple.MT { background: var(--mt); color: var(--mt-texte); }
.case-exemple.MD { background: var(--md); color: var(--md-texte); }
.case-exemple.LT { background: var(--lt); color: var(--lt-texte); }
.case-exemple.LD { background: var(--ld); color: var(--ld-texte); }
.tableau-lettres { max-width: 20rem; }
.tableau-lettres th[scope="row"] { text-align: left; }
.tableau-lettres thead th:first-child { text-align: left; }
.tableau-lettres .lettre-guide { display: inline-flex; align-items: center; gap: 0.5rem; }
.tableau-lettres .tuile { width: 2rem; font-size: 1.15rem; }
