:root {
  --fond: #1a1238;
  --fond2: #2d1b5e;
  --surface: #2a2150;
  --surface2: #3a2f6b;
  --texte: #f4f0ff;
  --texte-doux: #b3a8d9;
  --verte: #2fbf71;
  --rouge: #b8324f;
  --accent: #ffc94d;
  --haut: #ff7a59;
}

@font-face {
  font-family: "Fredoka";
  src: url("fonts/fredoka-latin.woff2") format("woff2");
  font-weight: 300 700;
  font-display: swap;
}

* { box-sizing: border-box; margin: 0; }

/* Le jeu tient toujours dans l'écran : 100dvh est mal recalculé par Android. */
body {
  position: fixed; inset: 0; overflow: hidden;
  background: radial-gradient(120% 80% at 50% 0%, var(--fond2), var(--fond) 70%) fixed;
  color: var(--texte);
  font-family: "Fredoka", system-ui, sans-serif;
  font-synthesis: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

button { font: inherit; color: inherit; border: 0; cursor: pointer; }
button:disabled { cursor: default; }

main {
  max-width: 500px; height: 100%; margin: 0 auto;
  padding: calc(12px + env(safe-area-inset-top)) 16px calc(12px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 10px;
}

/* En surimpression de l'en-tête : dans le flux, il ferait déborder l'écran. */
#maj {
  position: fixed; z-index: 1;
  left: 16px; right: 16px; top: calc(12px + env(safe-area-inset-top));
  max-width: 468px; margin: 0 auto;
  box-shadow: 0 8px 24px #0008;
  display: flex; justify-content: center; align-items: center; gap: 10px;
  padding: 8px 12px; border-radius: 12px;
  background: var(--surface); font-size: .9rem;
  animation: entre 400ms cubic-bezier(.2, 1.4, .4, 1);
}
#maj[hidden] { display: none; }
#maj button { padding: 6px 12px; border-radius: 10px; background: var(--accent); color: var(--fond); font-weight: 700; }
#maj button.selection { box-shadow: 0 0 0 2px var(--texte); }
@keyframes entre { from { transform: translateY(24px) scale(.8); opacity: 0; } }

/* En-tête */
header { display: flex; flex-direction: column; gap: 2px; }
h1 {
  text-align: center; font-size: 2rem; font-weight: 600; letter-spacing: .06em;
  background: linear-gradient(90deg, var(--accent), var(--haut));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
nav { display: flex; justify-content: space-between; }
nav button {
  width: 42px; height: 42px; display: grid; place-items: center;
  border-radius: 12px; background: transparent;
  transition: background 150ms, transform 100ms;
}
nav button:hover { background: var(--surface2); }
nav button.selection { background: var(--surface2); box-shadow: 0 0 0 2px var(--accent); }
nav button:active { transform: scale(.9); }
nav svg { width: 24px; height: 24px; fill: none; stroke: var(--texte); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
nav svg .plein { fill: var(--texte); stroke: none; }
#b-sons .barre, #b-sons.coupe .ondes { display: none; }
#b-sons.coupe .barre { display: inline; }

/* Accueil / jeu : une seule des deux sections à la fois */
body.accueil #jeu, body:not(.accueil) #accueil { display: none; }
#accueil { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; padding: 4px; }
.bloc { display: flex; flex-direction: column; gap: 10px; padding: 16px; border-radius: 18px; background: var(--surface); }
.bloc h2 { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: .8rem; font-weight: 600; color: var(--texte-doux); text-transform: uppercase; letter-spacing: .06em; }
.bloc h2 span { text-transform: none; letter-spacing: 0; }
.bloc-etat { font-weight: 600; text-align: left; }
/* Seule la liste des dernières parties défile : le haut de l'accueil reste à l'écran. */
.bloc:last-child { flex-shrink: 1; min-height: 0; }
.passees { display: flex; flex-direction: column; gap: 10px; min-height: 3rem; overflow-y: auto; scrollbar-width: none; }
.passees::-webkit-scrollbar { display: none; }
.passee { display: grid; grid-template-columns: 1fr auto; column-gap: 10px; row-gap: 2px; align-items: center; padding: 8px 0 0; border-top: 1px solid var(--surface2); background: none; text-align: left; }
.passee-ouvrir { grid-column: 2; grid-row: 1 / span 2; font-size: 1.6rem; line-height: 1; color: var(--texte-doux); }
.passee-nom { font-size: .85rem; color: var(--texte-doux); }
.passee-score { font-weight: 600; }

/* Partie */
#jeu { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 8px; }
#partie { text-align: center; font-size: .9rem; color: var(--texte-doux); }
.badge { margin-left: 6px; padding: 1px 6px; border-radius: 8px; background: var(--accent); color: var(--fond); font-size: .7rem; font-weight: 700; }
#infos { display: flex; justify-content: space-between; font-size: .9rem; color: var(--texte-doux); font-variant-numeric: tabular-nums; }
#zone { flex: 1 1 0; min-height: 0; display: grid; place-items: center; }
#grille { display: grid; gap: 2px; }

.case {
  position: relative; display: grid; place-items: center;
  border-radius: calc(var(--t) * .14);
  background: var(--surface); box-shadow: inset 0 0 0 1px var(--surface2);
  color: var(--texte); font-weight: 600;
}
.case b { font-weight: 600; font-size: calc(var(--t) * .6); line-height: 1; }
/* Chiffre discret en coin, comme en v3 ; il disparaît une fois la lettre trouvée. */
.case i { position: absolute; top: calc(var(--t) * .07); right: calc(var(--t) * .1); font-style: normal; font-size: max(9px, calc(var(--t) * .3)); font-weight: 500; color: var(--texte-doux); line-height: 1; }
.case.rev i { display: none; }
.case.sel { background: var(--accent); color: var(--fond); }
.case.sel i { color: var(--fond); }
.case.pop { animation: pop 220ms ease-out; }
@keyframes pop { 50% { transform: scale(1.25); } }

/* Clavier */
#clavier { display: flex; flex-direction: column; gap: 6px; }
.rangee { display: flex; gap: 5px; justify-content: center; }
.touche {
  /* Largeur d'une rangée de 10, même pour celle du bas qui n'en a que 6. */
  flex: 0 1 calc((100% - 45px) / 10); max-width: 44px; height: 46px; border-radius: 8px;
  background: var(--surface2); font-weight: 600; font-size: 1.05rem;
  transition: transform 80ms;
}
.touche:active:not(:disabled) { transform: scale(.92); }
.touche.verte { background: var(--verte); color: white; }
.touche.rouge { background: var(--rouge); color: #ffffffa0; }

/* Fenêtre modale */
#modal {
  position: fixed; inset: 0; z-index: 2; display: grid; place-items: center; padding: 16px;
  background: #0d0820cc; backdrop-filter: blur(6px);
  animation: fondu 300ms;
}
#modal[hidden] { display: none; }
#modal .selection { outline: 3px solid var(--accent); outline-offset: 3px; }
@keyframes fondu { from { opacity: 0; } }
.modal-carte {
  position: relative; width: 100%; max-width: 380px;
  max-height: calc(100dvh - 32px); overflow-y: auto; scrollbar-width: none;
  padding: 28px 22px; border-radius: 22px; background: var(--surface); text-align: center;
  display: flex; flex-direction: column; gap: 10px;
  animation: entre 500ms cubic-bezier(.2, 1.4, .4, 1);
}
.modal-carte::-webkit-scrollbar { display: none; }
.modal-carte h2 { font-size: 1.6rem; font-weight: 600; }
.fermer { position: absolute; top: 10px; right: 10px; width: 36px; height: 36px; border-radius: 10px; background: none; font-size: 1.1rem; color: var(--texte-doux); }
.doux { color: var(--texte-doux); font-size: .9rem; }
.rang { font-size: 2.4rem; letter-spacing: .05em; color: var(--accent); }
.bilan { font-size: 1.1rem; font-weight: 600; }
.suite { font-size: 1.1rem; letter-spacing: .1em; word-break: break-all; }
.mots { font-size: .9rem; color: var(--texte-doux); letter-spacing: .06em; }
.bouton {
  padding: 14px; border-radius: 14px; background: var(--haut); font-weight: 700;
  box-shadow: 0 5px 0 color-mix(in srgb, var(--haut) 50%, black);
  transition: transform 100ms, box-shadow 100ms;
}
.bouton:active { transform: translateY(4px); box-shadow: 0 1px 0 color-mix(in srgb, var(--haut) 50%, black); }
.bouton2 {
  padding: 12px; border-radius: 14px; background: none; border: 2px solid var(--surface2);
  font-weight: 600; color: var(--texte-doux);
  transition: background 150ms, color 150ms;
}
.bouton2:hover { background: var(--surface2); color: var(--texte); }
.choix { display: flex; gap: 8px; }
.choix .bouton2 { flex: 1; display: flex; flex-direction: column; gap: 2px; padding: 10px 6px; }
.choix small { font-size: .75rem; font-weight: 400; }
.choix .choisi { background: var(--accent); border-color: var(--accent); color: var(--fond); }
.avertissement { color: var(--accent); font-size: .85rem; font-weight: 600; }
.erreur { color: #ff8a8a; font-size: .85rem; }
.erreur:empty { display: none; }
.separe { margin-top: 8px; padding-top: 14px; border-top: 1px solid var(--surface2); color: var(--texte-doux); font-size: .85rem; }
.liste { display: flex; flex-direction: column; gap: 4px; text-align: left; font-size: .8rem; color: var(--texte-doux); text-transform: uppercase; letter-spacing: .06em; }
.liste select, .ouvrir input {
  font: inherit; font-size: 1rem; font-weight: 600; text-transform: none; letter-spacing: 0;
  padding: 10px 12px; border: 2px solid var(--surface2); border-radius: 12px;
  background: var(--fond); color: var(--texte); color-scheme: dark; user-select: text;
}
.liste select { padding-right: 36px; appearance: none; cursor: pointer; background: var(--fond) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%23b3a8d9' stroke-width='2'/%3E%3C/svg%3E") no-repeat right 14px center; }
.ouvrir { display: flex; gap: 8px; }
.ouvrir input { flex: 1; min-width: 0; font-size: .85rem; }

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

/* Statistiques */
.stat { display: grid; grid-template-columns: 1fr auto; align-items: baseline; gap: 4px 12px; padding: 8px 0; border-top: 1px solid var(--surface2); text-align: left; }
.stat-titre { font-size: .8rem; color: var(--texte-doux); text-transform: uppercase; letter-spacing: .06em; }
.stat-valeur { font-size: 1.15rem; font-weight: 700; text-align: right; }
button.stat { width: 100%; background: none; }
.stat-detail { display: block; font-size: .8rem; font-weight: 400; color: var(--texte-doux); }
.histo { grid-column: 1 / -1; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 2px 10px; font-size: .8rem; }
.histo .piste { height: 10px; }
.histo .barre { display: block; height: 100%; border-radius: 5px; background: var(--accent); }
.effectif { min-width: 1.5em; text-align: right; font-variant-numeric: tabular-nums; }

/* Réglages, partage, aide */
.reglage { display: flex; gap: 8px; }
.reglage .bouton2 { flex: 1; }
.reglage .choisi { background: var(--accent); border-color: var(--accent); color: var(--fond); }
.partage-qr { align-self: center; width: 200px; max-width: 100%; border-radius: 12px; }
.lien { font-weight: 600; user-select: text; }
.modal-carte a { color: var(--accent); }
.aide-titre { margin-top: 4px; text-align: left; font-size: 1.05rem; font-weight: 700; color: var(--accent); }
.aide-texte { text-align: left; font-size: .92rem; line-height: 1.4; color: var(--texte-doux); }
.aide-texte b { color: var(--texte); }
#etoiles { margin-left: auto; }

/* Aide en écrans superposés : la fenêtre garde la hauteur du plus long, sans défilement ni saut. */
.aide-pile { display: grid; touch-action: pan-y; }
.aide-ecran { grid-area: 1 / 1; visibility: hidden; display: flex; flex-direction: column; gap: 10px; }
.aide-ecran.vu { visibility: visible; animation: aide-entre 250ms ease-out; }
@keyframes aide-entre { from { opacity: 0; transform: translateX(12px); } }
.aide-cases { --t: 38px; display: flex; gap: 3px; justify-content: center; margin: 4px 0; }
.aide-cases .case { width: var(--t); height: var(--t); }
.aide-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.aide-fleche { width: 40px; height: 40px; border-radius: 12px; background: var(--surface2); font-size: 1.5rem; font-weight: 700; line-height: 1; }
.aide-fleche:disabled { opacity: .3; cursor: default; }
.aide-points { display: flex; gap: 6px; }
.aide-point { width: 10px; height: 10px; padding: 0; border-radius: 50%; background: var(--surface2); transition: background 150ms, transform 150ms; }
.aide-point.on { background: var(--accent); transform: scale(1.3); }
