:root {
  --fond: #1a1238;
  --fond2: #2d1b5e;
  --surface: #2a2150;
  --surface2: #3a2f6b;
  --texte: #f4f0ff;
  --texte-doux: #b3a8d9;
  --verte: #2fbf71;
  --rouge: #5a2338;
  --accent: #ffc94d;
  --haut: #ff7a59;
  --bas: #5ab0ff;
  --tuile: min(9.5vw, 44px);
}

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

body {
  min-height: 100dvh;
  background: radial-gradient(120% 80% at 50% 0%, var(--fond2), var(--fond) 70%) fixed;
  color: var(--texte);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

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

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

#maj {
  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: 800; }
#maj button.selection { box-shadow: 0 0 0 2px var(--texte); }

/* En-tête */
@font-face {
  font-family: "Fredoka";
  src: url("fonts/fredoka-latin-600.woff2") format("woff2");
  font-weight: 600;
  font-display: swap;
}
header { display: flex; flex-direction: column; gap: 4px; }
h1 {
  text-align: center;
  font-family: "Fredoka", system-ui, sans-serif;
  font-size: 2.3rem;
  font-weight: 600;
  letter-spacing: .03em;
  background: linear-gradient(90deg, var(--accent), var(--haut));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.infos { display: flex; justify-content: space-between; align-items: baseline; }
#partie { font-size: .85rem; color: var(--texte-doux); }
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:not(:disabled) { background: var(--surface2); }
nav button:active:not(:disabled) { transform: scale(.9); }
nav button:disabled { opacity: .3; cursor: default; }
nav button.selection { background: var(--surface2); box-shadow: 0 0 0 2px var(--accent); }
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; }
.stat { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 4px 12px; padding: 10px 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 { grid-column: 1; font-size: 1.15rem; font-weight: 800; }
.stat-partie { grid-column: 1; font-size: .85rem; color: var(--texte-doux); }
.stat .bouton2 { grid-column: 2; grid-row: 1 / 4; padding: 8px 12px; font-size: .85rem; }
.bouton2:disabled { opacity: .35; cursor: default; }
#compteurs {
  position: relative;
  display: flex; gap: 12px;
  font-size: .85rem; color: var(--texte-doux);
}
#compteurs b { font-size: 1.3rem; color: var(--texte); font-variant-numeric: tabular-nums; }
.gain {
  position: absolute; right: 60px; top: -4px;
  font-weight: 900; color: var(--accent);
  animation: gain 900ms ease-out forwards;
}
@keyframes gain { from { transform: translateY(10px) scale(.6); opacity: 0; } 30% { opacity: 1; transform: translateY(0) scale(1.2); } to { transform: translateY(-22px); opacity: 0; } }

/* Fenêtre des 3 mots */
#fenetre { display: flex; flex-direction: column; gap: 6px; align-items: center; }
.mot { display: flex; gap: 3px; transition: opacity 300ms, transform 300ms; }
.mot .tuile {
  width: calc(var(--tuile) * .62); height: calc(var(--tuile) * .62);
  display: grid; place-items: center;
  border-radius: 6px;
  background: var(--surface2);
  font-weight: 800; font-size: .9rem; text-transform: uppercase;
}
.pos1 { opacity: .3; }
.pos2 { opacity: .6; }
.pos3 { opacity: .95; }
.mot.actif .tuile { background: var(--accent); color: var(--fond); box-shadow: 0 0 12px #ffc94d55; }
.mot.inactif { opacity: .15; transform: scale(.92); }
.mot.entre { animation: entre 450ms cubic-bezier(.2, 1.4, .4, 1); }
@keyframes entre { from { transform: translateY(24px) scale(.8); opacity: 0; } }

/* Zone centrale */
#zone { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 14px; }
.consigne { text-align: center; color: var(--texte-doux); font-size: .9rem; }

.carte {
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-areas: "cote aides valeur" "points aides valeur";
  align-items: center; column-gap: 14px; row-gap: 6px;
  padding: 14px 18px;
  border-radius: 18px;
  background: var(--surface);
  border: 2px solid var(--c);
  box-shadow: 0 6px 0 color-mix(in srgb, var(--c) 45%, black);
  text-align: left;
  animation: carte 400ms backwards cubic-bezier(.2, 1.3, .4, 1);
  transition: transform 120ms;
}
.carte:active { transform: translateY(4px); box-shadow: 0 2px 0 color-mix(in srgb, var(--c) 45%, black); }
.carte.haut { --c: var(--haut); }
.carte.bas { --c: var(--bas); animation-delay: 80ms; }
@keyframes carte { from { transform: translateY(16px) scale(.95); opacity: 0; } }
.cote { grid-area: cote; font-weight: 800; color: var(--c); text-transform: uppercase; font-size: .8rem; letter-spacing: .08em; }
.points { grid-area: points; display: flex; gap: 4px; }
.points i { width: 10px; height: 10px; border-radius: 3px; background: var(--surface2); }
.points i.on { background: var(--accent); }
.aides { grid-area: aides; font-size: .9rem; color: var(--texte-doux); }
.valeur { grid-area: valeur; font-size: 2rem; font-weight: 900; color: var(--c); }

.abandon {
  align-self: center;
  margin-top: 8px;
  padding: 14px 32px; border-radius: 16px;
  background: #e5484d; color: white;
  font-size: 1.05rem; font-weight: 800;
  box-shadow: 0 6px 0 #8f1d2c;
  transition: transform 100ms, box-shadow 100ms;
}
.abandon:hover { background: #f05a5f; }
.abandon:active { transform: translateY(4px); box-shadow: 0 2px 0 #8f1d2c; }
.abandon { position: relative; overflow: hidden; touch-action: none; -webkit-touch-callout: none; }
.abandon span { position: relative; }
/* jauge de maintien : se remplit en 3 s (DUREE_ABANDON dans app.js) */
.abandon::after {
  content: ""; position: absolute; inset: 0;
  background: #8f1d2c;
  transform: scaleX(0); transform-origin: left;
}
.abandon.maintien::after { transform: scaleX(1); transition: transform 3s linear; }

.definition { text-align: center; font-size: 1.15rem; font-weight: 600; line-height: 1.35; }

.cases { display: flex; justify-content: center; gap: 5px; }
.case {
  position: relative;
  width: var(--tuile); height: calc(var(--tuile) * 1.15);
  display: grid; place-items: center;
  border-radius: 9px;
  background: var(--surface);
  border: 2px solid var(--surface2);
  font-size: 1.5rem; font-weight: 900; text-transform: uppercase;
  transition: border-color 150ms, transform 150ms;
}
.case.marquee { border-color: var(--verte); background: color-mix(in srgb, var(--verte) 18%, var(--surface)); }
.case.verrou { color: var(--verte); cursor: default; }
.case.curseur { border-color: var(--accent); transform: translateY(-3px); box-shadow: 0 4px 12px #ffc94d44; }
.case .num { position: absolute; top: 2px; left: 4px; font-size: .6rem; font-weight: 700; color: var(--texte-doux); }
.case.pop { animation: pop 140ms ease-out; }
@keyframes pop { 50% { transform: scale(1.15); } }

.cases.secoue, .cases.faux { animation: secoue 400ms; }
.cases.faux .case { background: #7a2140; border-color: #c2375f; }
@keyframes secoue { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
.cases.juste .case {
  animation: retourne 450ms calc(var(--i) * 70ms) backwards ease-in-out;
  background: var(--verte); border-color: var(--verte); color: white;
}
@keyframes retourne { 0% { transform: rotateX(0); background: var(--surface); } 50% { transform: rotateX(90deg); background: var(--surface); } }

/* Clavier */
#clavier { display: flex; flex-direction: column; gap: 6px; }
.rangee { display: flex; gap: 5px; justify-content: center; }
.touche {
  position: relative;
  flex: 1; max-width: 44px; height: 54px;
  border-radius: 8px;
  background: var(--surface2);
  font-weight: 700; font-size: 1.05rem; text-transform: uppercase;
  transition: transform 80ms, background 200ms;
}
.touche:active { transform: scale(.92); }
.touche.large { max-width: 76px; flex: 1.6; font-size: .8rem; }
.touche.verte { background: var(--verte); color: white; }
.touche.rouge { background: var(--rouge); color: #ffffff40; cursor: default; }
.badge {
  position: absolute; top: -6px; right: -4px;
  padding: 1px 5px; border-radius: 8px;
  background: var(--accent); color: var(--fond);
  font-size: .65rem; font-weight: 900; text-transform: none;
}

/* Fenêtre modale (fin de partie, aide) */
#modal {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  padding: 16px;
  background: #0d0820cc;
  backdrop-filter: blur(6px);
  animation: fondu 300ms;
}
#modal[hidden] { display: none; }
@keyframes fondu { from { opacity: 0; } }
.modal-carte {
  width: 100%; max-width: 380px;
  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 h2 { font-size: 1.6rem; font-weight: 900; }
.reponse-label { color: var(--texte-doux); font-size: .85rem; }
.reponse { font-size: 2rem; font-weight: 900; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); }
.modal-carte .definition { font-size: .95rem; color: var(--texte-doux); font-weight: 400; }
.bilan { font-size: 1.3rem; font-weight: 800; margin: 8px 0; }
.bouton2 {
  padding: 12px; border-radius: 14px;
  background: none; border: 2px solid var(--surface2);
  font-weight: 700; color: var(--texte-doux);
  transition: background 150ms, color 150ms;
}
.bouton2:hover { background: var(--surface2); color: var(--texte); }
#modal .selection { outline: 3px solid var(--accent); outline-offset: 3px; }
.bouton {
  padding: 14px; border-radius: 14px;
  background: var(--haut); font-weight: 800;
  box-shadow: 0 5px 0 color-mix(in srgb, var(--haut) 50%, black);
}

.regles { padding-left: 1.2em; text-align: left; display: flex; flex-direction: column; gap: 8px; font-size: .92rem; line-height: 1.4; color: var(--texte-doux); }

.modal-carte { position: relative; }
.fermer { position: absolute; top: 10px; right: 10px; width: 36px; height: 36px; border-radius: 10px; background: none; font-size: 1.1rem; color: var(--texte-doux); }
.partage-qr { align-self: center; background: #fff; padding: 12px; border-radius: 12px; line-height: 0; }
.partage-qr canvas { max-width: 100%; height: auto; }
.partage-url { display: flex; gap: 8px; }
.partage-url input { flex: 1; min-width: 0; font: inherit; font-size: .85rem; padding: 8px 10px; border: 2px solid var(--surface2); border-radius: 10px; background: var(--fond); color: var(--texte); user-select: text; }
.partage-url .bouton { padding: 8px 16px; }

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