/* Le Mot Juste : style inspiré de Wordle. */

:root {
  --green:  #6aaa64;
  --yellow: #c9b458;
  --gray:   #787c7e;
  --tile-border:        #d3d6da;
  --tile-border-filled: #878a8c;
  --key-bg:   #d3d6da;
  --key-text: #1a1a1b;
  --text:     #1a1a1b;
  --muted:    #787c7e;
  --line:     #d3d6da;
  --bg:       #ffffff;

  --font: "Libre Franklin", "Helvetica Neue", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  /* Filet de sécurité mobile : jamais de scroll horizontal, même si un calcul déborde d'un pixel. */
  overflow-x: hidden;
}

.app {
  max-width: 500px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 0 12px;
}

/* En-tête */
/* .app fait au maximum 500px de large, sur mobile comme sur desktop (colonne
   centrée façon Wordle) : le header dispose donc toujours du même espace réduit,
   quel que soit l'appareil. D'où une mise en page sur deux lignes en permanence
   (titre au-dessus, boutons en dessous) plutôt qu'un point de rupture lié à la
   largeur de la fenêtre — sinon les boutons peuvent chevaucher le titre dès que
   plusieurs sont affichés en même temps (Admin, Changer, Stats, Règles). */
.header {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-areas: "title title" "left right";
  align-items: start;
  row-gap: 8px;
  column-gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}
.header__title {
  grid-area: title;
  margin: 0;
  text-align: center;
  font-weight: 800;
  font-size: 1.4rem;
  letter-spacing: .01em;
  white-space: nowrap;
}
.header__btn {
  font-family: inherit;
  font-size: .85rem;
  font-weight: 600;
  color: var(--text);
  background: none;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  white-space: nowrap;
}
.header__btn:hover { background: #f3f3f3; }
.header__btn--icon {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 999px;
  font-size: .85rem;
  font-weight: 800;
}
.header__side { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.header__side--left { grid-area: left; justify-self: start; justify-content: flex-start; }
.header__side--right { grid-area: right; justify-self: end; justify-content: flex-end; }
.header__btn--admin { border-color: var(--gray); }

/* Encore un peu plus compact sur les très petits écrans. */
@media (max-width: 360px) {
  .header__btn { font-size: .78rem; padding: 5px 8px; }
  .header__btn--icon { width: 30px; height: 30px; }
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

/* Écran nom */
.start {
  width: 100%;
  max-width: 420px;
  margin: auto;
  padding: 32px 8px;
  text-align: center;
}
/* Bandeau visuel de la page d'accueil */
.hero { margin: 0 0 22px; }
.hero__row {
  display: flex;
  gap: 6px;
  justify-content: center;
}
.hero__row--sm { margin-top: 18px; }
.hero__tile {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  font-size: 1.3rem;
  font-weight: 800;
  color: #fff;
  border-radius: 6px;
  animation: hero-pop .45s ease backwards;
}
.hero__tile--correct { background: var(--green); animation-delay: .05s; }
.hero__tile--present { background: var(--yellow); animation-delay: .15s; }
.hero__tile--absent  { background: var(--gray); animation-delay: .25s; }
.hero__row .hero__tile:nth-child(4) { animation-delay: .35s; background: var(--green); }
.hero__row .hero__tile:nth-child(5) { animation-delay: .45s; background: var(--yellow); }

.howto {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 0 0 28px;
}
.howto__step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px 6px;
  background: #f6f6f6;
  border-radius: 10px;
  /* Empêche le contenu texte de forcer la colonne à s'élargir au-delà de sa part
     de grille (piège classique de CSS Grid/Flexbox sur mobile). */
  min-width: 0;
}
.howto__icon { width: 26px; height: 26px; color: var(--text); }
.howto__step p {
  margin: 0;
  font-size: .78rem;
  line-height: 1.3;
  color: #333;
}

.start__form { display: flex; flex-direction: column; gap: 12px; }
.input {
  font-family: inherit;
  font-size: 1rem;
  padding: 14px 16px;
  border: 2px solid var(--tile-border);
  border-radius: 8px;
  text-align: center;
}
.input:focus { outline: none; border-color: var(--gray); }

.btn {
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  background: var(--text);
  border: none;
  border-radius: 8px;
  padding: 14px 22px;
  cursor: pointer;
}
.btn:hover { background: #000; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.start__known { margin-top: 28px; }
.start__known-label {
  display: block;
  font-size: .85rem;
  color: var(--muted);
  margin-bottom: 10px;
}
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip {
  font-family: inherit;
  font-size: .9rem;
  font-weight: 600;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  cursor: pointer;
}
.chip:hover { background: #f3f3f3; }

/* Écran de jeu */
.play {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
}
.caption {
  font-size: .95rem;
  color: var(--muted);
  margin: 16px 0 4px;
  min-height: 1.2em;
  text-align: center;
}

/* Plateau */
.board {
  --cols: 5;
  display: grid;
  gap: 5px;
  padding: 16px 0;
  margin: auto 0;
  width: 100%;
  max-width: 100%;
  /* Filet de sécurité : sur les très petits écrans avec une grille de 9-10 lettres,
     la rangée peut rester légèrement plus large que l'écran malgré le clamp() sur
     .tile ; on scrolle horizontalement plutôt que de casser la mise en page. */
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.row {
  display: grid;
  gap: 5px;
  grid-auto-flow: column;
  justify-content: center;
}
.row--invalid { animation: shake .5s; }

/* Taille de tuile fluide : dépend du nombre de colonnes (--cols, posé en JS sur
   .board) et de la largeur d'écran, pour qu'une grille de 10 lettres ne déborde
   jamais sur un téléphone. Le calcul reste borné à 58px sur grand écran. */
.tile {
  width: clamp(32px, calc((min(100vw, 500px) - 40px) / var(--cols) - 6px), 58px);
  height: clamp(32px, calc((min(100vw, 500px) - 40px) / var(--cols) - 6px), 58px);
  display: grid;
  place-items: center;
  font-size: clamp(.9rem, calc((min(100vw, 500px) - 40px) / var(--cols) * 0.4), 2rem);
  font-weight: 700;
  text-transform: uppercase;
  border: 2px solid var(--tile-border);
  color: var(--text);
  background: #fff;
  user-select: none;
}
.tile--filled { border-color: var(--tile-border-filled); animation: pop .1s; }
.tile--ghost { color: #c9c9c9; }

.tile--correct, .tile--present, .tile--absent {
  color: #fff;
  border: none;
}
.tile--correct { background: var(--green); }
.tile--present { background: var(--yellow); }
.tile--absent  { background: var(--gray); }
.tile--reveal { animation: flip .5s ease forwards; }

/* Résultat + actions */
.result {
  font-size: 1rem;
  font-weight: 600;
  text-align: center;
  margin: 4px 0 0;
}
.result b { letter-spacing: .04em; }
.actions { padding: 12px 0; min-height: 24px; }
.actions[hidden] { display: none; }

/* Sélecteur de taille de grille */
.size-select {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}
.size-select__label { font-size: .8rem; color: var(--muted); font-weight: 600; }
.size-select__options { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.size-select__opt {
  font-family: inherit;
  font-size: .85rem;
  font-weight: 700;
  min-width: 34px;
  padding: 6px 8px;
  border: 1.5px solid var(--line);
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
}
.size-select__opt:hover { background: #f3f3f3; }
.size-select__opt--active { background: var(--text); color: #fff; border-color: var(--text); }

/* Clavier */
.keyboard {
  width: 100%;
  max-width: 500px;
  padding: 8px 0 16px;
  margin-top: auto;
}
.keyboard[aria-hidden="true"] { opacity: .4; pointer-events: none; }
.krow {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin-bottom: 6px;
  touch-action: manipulation;
}
.key {
  font-family: inherit;
  font-size: .95rem;
  font-weight: 700;
  text-transform: uppercase;
  height: 56px;
  flex: 1;
  min-width: 0;
  border: none;
  border-radius: 4px;
  background: var(--key-bg);
  color: var(--key-text);
  cursor: pointer;
  display: grid;
  place-items: center;
}
.key:hover { filter: brightness(.96); }
.key--wide { flex: 1.5; font-size: .72rem; }
.key svg { width: 22px; height: 22px; }
.key--correct { background: var(--green); color: #fff; }
.key--present { background: var(--yellow); color: #fff; }
.key--absent  { background: var(--gray); color: #fff; }

/* Modale stats */
.modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; }
.modal__backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.5); }
.modal__card {
  position: relative;
  background: #fff;
  width: min(92vw, 460px);
  max-height: 86vh;
  overflow-y: auto;
  border-radius: 12px;
  padding: 28px 24px;
  box-shadow: 0 12px 40px rgba(0,0,0,.25);
  animation: rise .2s ease;
}
.modal__close {
  position: absolute;
  top: 12px; right: 14px;
  font-size: 1.7rem;
  line-height: 1;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
}
.modal__title {
  font-size: 1rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  margin: 0 0 12px;
}
.modal__title:nth-of-type(2) { margin-top: 28px; }
.empty { color: var(--muted); font-size: .9rem; margin: 0; }

.history { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.history__item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: #f6f6f6;
  border-radius: 8px;
}
.history__word { font-weight: 700; letter-spacing: .06em; }
.history__meta { font-size: .8rem; color: var(--muted); }
.tag {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 999px;
  color: #fff;
}
.tag--won { background: var(--green); }
.tag--lost { background: var(--gray); }
.tag--progress { background: var(--yellow); }

.leaderboard { list-style: none; margin: 0; padding: 0; }
.lb__row {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 10px 4px;
  border-bottom: 1px solid #eee;
}
.lb__row:last-child { border-bottom: none; }
.lb__row--me { font-weight: 700; }
.lb__rank { color: var(--muted); text-align: center; font-weight: 700; }
.lb__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb__score { font-size: .85rem; color: var(--muted); }

/* Règles */
.rules-list { margin: 0; padding-left: 1.2em; display: flex; flex-direction: column; gap: 8px; font-size: .92rem; line-height: 1.4; }

/* Lien discret (annuler une partie en cours) */
.link-btn {
  font-family: inherit;
  font-size: .82rem;
  font-weight: 600;
  color: var(--muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px 4px;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.link-btn:hover { color: var(--text); }

/* Écran de connexion admin */
.admin-login {
  max-width: 360px;
  margin: auto;
  padding: 32px 8px;
  width: 100%;
}
.admin-login__card {
  background: #fff;
  border: 2px solid var(--tile-border);
  border-radius: 12px;
  padding: 32px 26px;
  text-align: center;
  animation: admin-rise .3s ease;
}
.admin-login__badge {
  width: 44px; height: 44px;
  margin: 0 auto 16px;
  display: grid;
  place-items: center;
  background: var(--text);
  color: #fff;
  border-radius: 999px;
}
.admin-login__badge svg { width: 20px; height: 20px; }
.admin-login__title { margin: 0 0 4px; font-size: 1.2rem; font-weight: 800; }
.admin-login__subtitle { margin: 0 0 22px; font-size: .85rem; color: var(--muted); }
.admin-login__card form { display: flex; flex-direction: column; gap: 12px; }
.admin-login__error {
  margin: 0;
  font-size: .82rem;
  font-weight: 600;
  color: #c0392b;
  animation: shake .4s;
}
.admin-login__back {
  margin-top: 20px;
  font-family: inherit;
  font-size: .82rem;
  font-weight: 600;
  color: var(--muted);
  background: none;
  border: none;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.admin-login__back:hover { color: var(--text); }
@keyframes admin-rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Vue admin */
.admin { width: 100%; padding: 16px 0 32px; animation: admin-rise .3s ease; }
.admin__toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 20px;
}
.admin__toolbar .header__btn { flex-shrink: 0; }
.admin__title {
  margin: 0;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
  font-size: clamp(.85rem, 4vw, 1.05rem);
  font-weight: 800;
}
.admin__section-title {
  font-size: .78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  margin: 0 0 10px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--line);
}
.admin__cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 28px;
}
.admin__card {
  position: relative;
  overflow: hidden;
  min-width: 0;
  background: #f6f6f6;
  border-radius: 12px;
  padding: 16px 10px;
  text-align: center;
  animation: admin-card-in .4s ease backwards;
}
.admin__card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
}
.admin__card--gray::before   { background: var(--gray); }
.admin__card--dark::before   { background: var(--text); }
.admin__card--yellow::before { background: var(--yellow); }
.admin__card--green::before  { background: var(--green); }
.admin__card--gray   .admin__card-icon { color: var(--gray); }
.admin__card--dark   .admin__card-icon { color: var(--text); }
.admin__card--yellow .admin__card-icon { color: var(--yellow); }
.admin__card--green  .admin__card-icon { color: var(--green); }
.admin__card-icon { margin: 0 auto 6px; width: 22px; height: 22px; }
.admin__card-icon svg { width: 100%; height: 100%; }
.admin__card-value { font-size: 1.6rem; font-weight: 800; }
.admin__card-label { font-size: .75rem; color: var(--muted); margin-top: 2px; }
@keyframes admin-card-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.admin__table-wrap { overflow-x: auto; margin-bottom: 28px; }
.admin__table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.admin__table th, .admin__table td {
  padding: 9px 10px;
  text-align: left;
  border-bottom: 1px solid #eee;
  white-space: nowrap;
}
.admin__table th { color: var(--muted); font-weight: 700; text-transform: uppercase; font-size: .72rem; }
.admin__table td.empty { text-align: center; color: var(--muted); white-space: normal; }
.admin__table tbody tr { animation: admin-row-in .3s ease backwards; }
.admin__table tbody tr:hover { background: #fafafa; }
@keyframes admin-row-in {
  from { opacity: 0; transform: translateX(-6px); }
  to { opacity: 1; transform: translateX(0); }
}

/* Toast */
.toast {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  font-weight: 600;
  font-size: .92rem;
  padding: 12px 18px;
  border-radius: 6px;
  z-index: 200;
  max-width: 90vw;
  text-align: center;
  animation: rise .15s ease;
}

/* Animations */
@keyframes pop { from { transform: scale(.9); } to { transform: scale(1); } }
@keyframes hero-pop {
  from { transform: translateY(-10px) scale(.7); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}
@keyframes flip {
  0% { transform: rotateX(0); }
  50% { transform: rotateX(90deg); }
  100% { transform: rotateX(0); }
}
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-7px); }
  40%, 60% { transform: translateX(7px); }
}
@keyframes rise { from { opacity: 0; transform: translateY(8px) translateX(-50%); } to { opacity: 1; } }
.modal__card { animation-name: rise-center; }
@keyframes rise-center { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* Petits écrans */
@media (max-width: 420px) {
  .key { height: 50px; }
}

