/* Boggle FR — feuille unique. Priorité : la grille occupe l'écran et le geste
   ne déclenche jamais un geste du navigateur. */

:root {
  --bg: #11131a;
  --surface: #1b1f2a;
  --surface-hi: #252b39;
  --line: #303748;
  --text: #eef1f7;
  --muted: #8e97ab;
  --accent: #5b8cff;
  --accent-soft: #2a3a63;
  --valid: #3ddc84;
  --invalid: #ff5f56;
  --vowel: #f5c451;
}

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

html,
body {
  /* dvh et non vh : la barre d'URL de Safari rendrait 100vh plus haut que
     l'écran visible et couperait le bas de la grille. */
  height: 100dvh;
  /* Coupe le pull-to-refresh de Chrome Android, qui se déclencherait au premier
     glissé vers le bas sur la grille. */
  overscroll-behavior: none;
  overflow: hidden;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  /* La loupe et la sélection de texte d'iOS s'invitent sinon pendant le drag. */
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom)
    env(safe-area-inset-left);
}

/* ─── Écrans ─────────────────────────────────────────────────────────────── */

.screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  height: 100%;
  padding: 20px;
  max-width: 560px;
  margin: 0 auto;
}

.screen[hidden] {
  display: none;
}

.screen--game {
  justify-content: flex-start;
  gap: 10px;
}

.screen--results {
  justify-content: flex-start;
  overflow-y: auto;
  align-items: stretch;
  text-align: left;
}

.logo {
  font-size: clamp(2.4rem, 12vw, 3.6rem);
  font-weight: 800;
  letter-spacing: 0.16em;
  margin-bottom: 8px;
}

h2 {
  font-size: 1.25rem;
  font-weight: 700;
}

h3 {
  font-size: 0.95rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 18px 0 8px;
}

h3 small {
  text-transform: none;
  letter-spacing: 0;
}

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

/* ─── Contrôles ──────────────────────────────────────────────────────────── */

.btn {
  width: 100%;
  max-width: 320px;
  padding: 15px 20px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  /* 44 px minimum : sous ce seuil la cible est trop petite au doigt. */
  min-height: 48px;
}

.btn:active {
  transform: scale(0.985);
}

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #08101f;
}

.btn--ghost {
  background: transparent;
}

.btn:disabled {
  opacity: 0.45;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  max-width: 320px;
  font-size: 0.85rem;
  color: var(--muted);
}

input {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font-size: 1.05rem;
  font-family: inherit;
  /* 16px minimum sur iOS, sinon Safari zoome à la mise au point du champ. */
}

.code-input {
  max-width: 260px;
  text-align: center;
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 0.35em;
  text-transform: uppercase;
}

.big-code {
  font-size: clamp(2.6rem, 16vw, 4rem);
  font-weight: 800;
  letter-spacing: 0.2em;
  color: var(--accent);
}

.players {
  list-style: none;
  padding: 0;
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.players li {
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.players li.host::after {
  content: ' 👑';
}

/* ─── Avatar ─────────────────────────────────────────────────────────────── */

.identity {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.avatar-button {
  flex: 0 0 auto;
  width: 56px;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  /* L'emoji doit rester centré quelle que soit sa largeur (🇫🇷 est plus large). */
  display: grid;
  place-items: center;
  padding: 0;
}

.avatar-button:active {
  transform: scale(0.96);
}

/* Avatar cliquable dans la liste du lobby : seule sa propre ligne l'est. */
.players li .avatar-edit {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  font-size: 1.3rem;
  cursor: pointer;
}

.players li .avatar-edit::after {
  content: ' ✏️';
  font-size: 0.7rem;
  opacity: 0.6;
}

/* Feuille de sélection, remontée du bas : le pouce y accède sans traverser
   l'écran. */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(8, 10, 15, 0.72);
}

.sheet[hidden] {
  display: none;
}

.sheet-panel {
  width: 100%;
  max-width: 480px;
  max-height: 85dvh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px 18px 0 0;
  animation: sheet-up 220ms cubic-bezier(0.2, 0.9, 0.2, 1);
}

@keyframes sheet-up {
  from {
    transform: translateY(12%);
    opacity: 0.6;
  }
  to {
    transform: none;
    opacity: 1;
  }
}

.sheet-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  /* Le fond évite que la palette défile visiblement sous l'en-tête. */
  background: var(--surface);
  padding-bottom: 6px;
}

.sheet-title {
  margin: 0;
  font-size: 0.9rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.sheet-close {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font-size: 1.1rem;
  cursor: pointer;
}

.sheet-error {
  min-height: 1.2rem;
  font-size: 0.85rem;
  color: var(--invalid);
}

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

.palette button {
  aspect-ratio: 1;
  min-height: 48px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: var(--bg);
  font-size: 1.7rem;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
}

.palette button:active {
  transform: scale(0.94);
}

.palette button[aria-pressed='true'] {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.avatar-input {
  text-align: center;
  font-size: 2rem;
}

.cast-tip {
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
}

.cast-tip b {
  color: var(--accent);
  font-weight: 600;
  /* Une adresse doit pouvoir être lue caractère par caractère pour être retapée. */
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  word-break: break-all;
}

.players em {
  color: var(--muted);
  font-style: normal;
}

/* ─── HUD et grille ──────────────────────────────────────────────────────── */

.hud {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  width: 100%;
  padding: 4px 6px;
}

.timer {
  font-size: 2rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.counter {
  color: var(--muted);
  font-size: 1rem;
}

.counter b {
  color: var(--text);
  font-size: 1.4rem;
}

.grid-wrap {
  position: relative;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Reçoit la grille construite en JS ; vidé et reconstruit à chaque partie. */
.grid-host {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--size), 1fr);
  /* Tout se dérive du côté d'une case, pour que 4×4, 5×5 et 6×6 restent
     lisibles sans trois jeux de valeurs en dur. */
  --side: min(94vw, 440px);
  --cell: calc(var(--side) / var(--size));
  gap: calc(var(--cell) * 0.08);
  width: var(--side);
  aspect-ratio: 1;
  /* LE point critique du client : sans touch-action none, le premier glissé
     scrolle la page au lieu de tracer un mot. */
  touch-action: none;
}

.cell {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: calc(var(--cell) * 0.16);
  font-size: calc(var(--cell) * 0.44);
  font-weight: 700;
  text-transform: uppercase;
  transition: background 90ms linear, transform 90ms linear;
}

.cell--vowel {
  color: var(--vowel);
}

/* 'QU' tient sur une case sans déborder. */
.cell--digraph {
  font-size: calc(var(--cell) * 0.3);
  letter-spacing: -0.02em;
}

.cell--active {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.cell--head {
  background: var(--accent);
  color: #08101f;
  transform: scale(1.04);
}

.trail {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: visible;
}

.trail polyline {
  stroke: var(--accent);
  /* Proportionnel à la case : un trait de 7 px écraserait une grille 6×6. */
  stroke-width: calc(var(--cell) * 0.08);
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.75;
}

.current-word {
  min-height: 2.2rem;
  margin-top: 10px;
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: 0.1em;
}

.current-word--valid {
  color: var(--valid);
}

.current-word--invalid {
  color: var(--invalid);
  text-decoration: line-through;
}

.is-disabled .board {
  opacity: 0.55;
}

.countdown {
  position: absolute;
  /* Calé sur les dimensions du plateau, pas sur tout le wrap, pour ne pas
     recouvrir aussi le mot en cours. */
  top: 0;
  left: 0;
  right: 0;
  width: min(94vw, 440px);
  margin: 0 auto;
  aspect-ratio: 1;
  z-index: 5;
  display: grid;
  place-items: center;
  font-size: 26vw;
  font-weight: 800;
  color: var(--accent);
  background: rgba(17, 19, 26, 0.82);
  border-radius: 18px;
}

.word-list {
  list-style: none;
  padding: 0 6px;
  width: 100%;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-content: flex-start;
}

.word-list li {
  padding: 5px 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.04em;
}

/* ─── Résultats ──────────────────────────────────────────────────────────── */

.ranking {
  list-style: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ranking li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.ranking li.me {
  border-color: var(--accent);
  background: var(--surface-hi);
}

.rank {
  width: 1.6rem;
  font-weight: 800;
  color: var(--muted);
}

.who-avatar {
  flex: 0 0 auto;
  font-size: 1.6rem;
  line-height: 1;
}

.who {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-weight: 600;
}

/* Mot le plus long du joueur, sous son pseudo. */
.who small {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.06em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Le plus long de toute la partie : c'est un titre, il se voit. */
.who small.record {
  color: var(--vowel);
}

.who small.record::after {
  content: ' 👑';
}

.pts {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.scored {
  list-style: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.scored li {
  display: flex;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--surface);
  border-radius: 10px;
  letter-spacing: 0.06em;
  font-weight: 600;
}

.scored--muted li {
  color: var(--muted);
  text-decoration: line-through;
}

.scored .empty {
  color: var(--muted);
  font-weight: 400;
  letter-spacing: 0;
  text-decoration: none;
}

.longest {
  margin-top: 14px;
  color: var(--muted);
}

.longest b {
  color: var(--vowel);
  letter-spacing: 0.08em;
}

.missed {
  list-style: none;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.missed li {
  padding: 5px 10px;
  border: 1px dashed var(--line);
  border-radius: 999px;
  font-size: 0.85rem;
  color: var(--muted);
  letter-spacing: 0.05em;
}

.screen--results .btn {
  max-width: none;
  margin-top: 10px;
}

/* ─── Retour sur la validité d'un mot ────────────────────────────────────── */

/* Une lueur sur tout le pourtour de l'écran : le joueur garde les yeux sur la
   grille et perçoit quand même le verdict. Un simple changement de couleur du
   mot, sous la grille, passait inaperçu pendant le jeu. */
.edge {
  position: fixed;
  inset: 0;
  z-index: 15;
  pointer-events: none;
  opacity: 0;
  box-shadow: inset 0 0 0 0 transparent;
}

.edge--on {
  animation: edge-pulse 620ms ease-out;
}

.edge--valid {
  --edge-color: var(--valid);
}

.edge--unknown {
  --edge-color: var(--invalid);
}

.edge--duplicate {
  --edge-color: var(--vowel);
}

@keyframes edge-pulse {
  0% {
    opacity: 0;
    box-shadow: inset 0 0 0 0 var(--edge-color);
  }
  22% {
    opacity: 1;
    box-shadow: inset 0 0 46px 12px var(--edge-color);
  }
  100% {
    opacity: 0;
    box-shadow: inset 0 0 46px 12px var(--edge-color);
  }
}

/* Respecte le réglage système : une pulsation plein écran est exactement le
   genre d'animation que « réduire les animations » vise. */
@media (prefers-reduced-motion: reduce) {
  .edge--on {
    animation-duration: 1ms;
  }
}

/* ─── Réglages du lobby ──────────────────────────────────────────────────── */

.options {
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.option {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.option-label {
  font-size: 0.8rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.option-label b {
  color: var(--text);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
}

.chips {
  display: flex;
  gap: 6px;
}

.chip {
  flex: 1;
  padding: 10px 0;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--muted);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.chip--active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--text);
}

/* Réglages en lecture seule pour les joueurs qui ne sont pas l'hôte. */
.options.is-readonly .chip,
.options.is-readonly input {
  opacity: 0.55;
  pointer-events: none;
}

input[type='range'] {
  width: 100%;
  padding: 0;
  height: 34px;
  background: transparent;
  border: none;
  accent-color: var(--accent);
}

/* ─── Grille des résultats ───────────────────────────────────────────────── */

.result-grid {
  display: flex;
  justify-content: center;
  margin: 6px 0 10px;
}

/* La grille de fin n'est pas jouable : aucun geste à y capter. */
.result-grid .board {
  --side: min(72vw, 300px);
  touch-action: auto;
}

/* Case appartenant au mot sélectionné. */
.cell--path {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--text);
}

/* Première lettre : donne le sens de lecture du mot. */
.cell--path-start {
  background: var(--accent);
  color: #08101f;
}

.word-pick {
  cursor: pointer;
}

.word-pick--selected {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--text);
  text-decoration: none;
}

/* ─── Revue des mots ─────────────────────────────────────────────────────── */

/* Échelle par longueur : la couleur chauffe et la taille grandit à mesure que le
   mot s'allonge. Les deux ensemble se lisent d'un coup d'œil, même de loin — et
   les tailles sont en `em` pour que la même échelle serve au téléphone et à la
   télévision, seule la base changeant. */
.tier-3 {
  --tier: var(--muted);
  --tier-size: 1em;
}
.tier-4 {
  --tier: var(--text);
  --tier-size: 1.15em;
}
.tier-5 {
  --tier: var(--accent);
  --tier-size: 1.3em;
}
.tier-6 {
  --tier: var(--valid);
  --tier-size: 1.5em;
}
.tier-7 {
  --tier: var(--vowel);
  --tier-size: 1.75em;
}
.tier-8 {
  --tier: #ff9d3c;
  --tier-size: 2em;
}

.review {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-height: 8.5rem;
  justify-content: center;
  transition: min-height 400ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* Une fois la revue finie, la zone se replie : la garder ouverte pour un simple
   libellé pousserait tout le détail hors de l'écran. */
.review--done {
  min-height: 1.6rem;
}

.review-phase {
  font-size: 0.8rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  min-height: 1rem;
}

.review-word {
  display: flex;
  align-items: baseline;
  gap: 0.4em;
  font-size: 1.9rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--tier);
}

.review-word b {
  font-size: var(--tier-size);
  line-height: 1;
  /* Chaque mot entre en scène : sans ça, une suite de mots au même endroit ne se
     distinguerait pas d'un simple changement de texte. */
  animation: word-in 260ms cubic-bezier(0.2, 1.5, 0.4, 1);
}

.review-word small {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0;
}

/* Décompte d'amorce : le chiffre bat pour attirer l'œil avant que les points ne
   commencent à tomber. */
.review-word--countdown {
  color: var(--accent);
  font-size: 3rem;
  animation: countdown-beat 900ms ease-out;
}

@keyframes countdown-beat {
  from {
    opacity: 0.3;
    transform: scale(0.7);
  }
  55% {
    opacity: 1;
    transform: scale(1.1);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* Les mots de 8 lettres et plus méritent d'être remarqués. */
.review-word.tier-8 b {
  text-shadow: 0 0 18px rgba(255, 157, 60, 0.45);
}

@keyframes word-in {
  from {
    opacity: 0;
    transform: translateY(0.25em) scale(0.85);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* Qui a trouvé le mot. Plusieurs avatars = mot commun. */
.review-finders {
  display: flex;
  gap: 0.3em;
  font-size: 1.4rem;
  min-height: 1.6rem;
}

.review-finders span {
  animation: word-in 260ms cubic-bezier(0.2, 1.5, 0.4, 1);
}

/* Mon propre avatar ressort : c'est mon score que je suis. */
.review-finders .me {
  filter: drop-shadow(0 0 6px var(--accent));
}

.review-skip {
  font-size: 0.8rem;
  color: var(--muted);
  text-decoration: underline;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
}

/* Score qui monte pendant la revue. */
.pts--up {
  animation: pts-bump 240ms ease-out;
}

@keyframes pts-bump {
  50% {
    transform: scale(1.22);
    color: var(--valid);
  }
}

/* Pendant la revue, le détail reste caché : on ne dévoile pas la fin avant. */
.results-detail[hidden] {
  display: none;
}

/* ─── Bandeaux ───────────────────────────────────────────────────────────── */

.banner,
.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
}

.banner {
  top: calc(env(safe-area-inset-top) + 8px);
  background: #4a3a12;
  color: #ffd479;
}

.toast {
  bottom: calc(env(safe-area-inset-bottom) + 18px);
  background: var(--surface-hi);
  border: 1px solid var(--line);
}

[hidden] {
  display: none !important;
}
