:root {
  --brun: #2b1a0e;
  --jaune: #ffd23f;
  --orange: #ff8c2b;
  --rouge: #e63946;
  --vert: #4fa83a;
  --creme: #fff8e7;
  --titre: "Luckiest Guy", "Arial Rounded MT Bold", "Arial Black", sans-serif;
  --texte: "Baloo 2", "Arial Rounded MT Bold", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--vert);
  font-family: var(--texte);
  color: var(--brun);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#jeu {
  position: fixed;
  inset: 0;
  /* taille posée en pixels par le script (= zone réellement visible) :
     100vh sur téléphone dépasse sous la barre d'adresse et décale les touches */
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}
body.en-jeu #jeu { cursor: none; }

/* ---------- boutons du coin ---------- */
#coin {
  position: fixed;
  right: max(12px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
  display: flex;
  gap: 8px;
  z-index: 20;
}
.rond {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 3px solid var(--brun);
  background: var(--creme);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--brun);
  transition: transform .08s, box-shadow .08s;
}
.rond:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--brun); }
.rond.off { opacity: .55; }
#btn-pause { display: none; }
body.en-jeu #btn-pause { display: block; }

/* ---------- écrans ---------- */
.ecran {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px;
  overflow-y: auto;
  background: radial-gradient(ellipse at 50% 40%, rgba(40, 70, 20, .35), rgba(20, 35, 10, .72));
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s;
}
.ecran.visible { opacity: 1; pointer-events: auto; }
.ecran::before, .ecran::after { content: ''; flex: 1 0 0; }

.carte {
  position: relative;
  width: min(560px, 100%);
  background: var(--creme);
  border: 4px solid var(--brun);
  border-radius: 28px;
  box-shadow: 0 10px 0 var(--brun), 0 24px 60px rgba(0, 0, 0, .35);
  padding: 18px 24px 18px;
  text-align: center;
  transform: translateY(14px) scale(.96);
  transition: transform .35s cubic-bezier(.2, 1.6, .4, 1);
  margin: 76px 0 16px;
  flex: 0 0 auto;
}
.ecran.visible .carte { transform: none; }
.carte.petite { width: min(380px, 100%); }

.tete-titre {
  width: 116px;
  height: 151px;
  margin: -86px auto -4px;
  filter: drop-shadow(0 6px 0 rgba(43, 26, 14, .25));
  animation: dodeline 1.6s ease-in-out infinite;
  transform-origin: 50% 90%;
  cursor: pointer;
}
.tete-titre canvas { width: 100%; height: 100%; display: block; }
.tete-titre.boing { animation: boing .5s ease-out; }
@keyframes dodeline {
  0%, 100% { transform: rotate(-6deg) translateY(0); }
  50% { transform: rotate(6deg) translateY(-6px); }
}
@keyframes boing {
  0% { transform: scale(1.15, .7); }
  40% { transform: scale(.9, 1.12); }
  70% { transform: scale(1.04, .96); }
  100% { transform: none; }
}

.titre {
  font-family: var(--titre);
  font-weight: 400;
  margin: 0;
  line-height: .9;
  font-size: clamp(42px, 10vw, 64px);
  color: var(--jaune);
  -webkit-text-stroke: 3px var(--brun);
  paint-order: stroke fill;
  text-shadow: 0 6px 0 var(--brun);
  letter-spacing: 1px;
  display: flex;
  justify-content: center;
  align-items: baseline;
  gap: .18em;
  flex-wrap: wrap;
  transform: rotate(-2.5deg);
}
.titre .petit { font-size: .55em; color: var(--orange); }

.titre-2 {
  font-family: var(--titre);
  font-weight: 400;
  margin: 4px 0 6px;
  font-size: clamp(30px, 7vw, 44px);
  line-height: 1;
  color: var(--jaune);
  -webkit-text-stroke: 2px var(--brun);
  paint-order: stroke fill;
  text-shadow: 0 4px 0 var(--brun);
}

.accroche { margin: 10px 0 10px; font-size: 18px; font-weight: 600; }
.accroche b { color: var(--rouge); }

.champ {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  font-weight: 800;
  margin-bottom: 14px;
}
.champ input {
  font: 800 18px var(--texte);
  color: var(--brun);
  width: 190px;
  padding: 6px 14px;
  border-radius: 14px;
  border: 3px solid var(--brun);
  background: #fff;
  outline: none;
  text-align: center;
  -webkit-user-select: text;
  user-select: text;
}
.champ input:focus { box-shadow: 0 0 0 4px rgba(255, 210, 63, .7); }
.champ input.erreur { border-color: var(--rouge); box-shadow: 0 0 0 4px rgba(230, 57, 70, .35); animation: secoue .4s; }
@keyframes secoue {
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}
.pseudo-erreur { margin: -6px 0 12px; color: var(--rouge); font-weight: 800; font-size: 14px; }

.gros-bouton {
  font-family: var(--titre);
  font-size: 30px;
  letter-spacing: 1px;
  color: #fff;
  background: linear-gradient(#ff5a5f, var(--rouge));
  border: 4px solid var(--brun);
  border-radius: 20px;
  padding: 12px 42px 8px;
  cursor: pointer;
  box-shadow: 0 7px 0 var(--brun);
  -webkit-text-stroke: 1.5px var(--brun);
  paint-order: stroke fill;
  transition: transform .08s, box-shadow .08s, filter .15s;
  animation: pulse 1.4s ease-in-out infinite;
}
.gros-bouton:hover { filter: brightness(1.08); }
.gros-bouton:active { transform: translateY(5px); box-shadow: 0 2px 0 var(--brun); }
@keyframes pulse { 50% { transform: scale(1.05); } }

.bouton-lien {
  display: block;
  margin: 14px auto 0;
  background: none;
  border: 0;
  font: 800 16px var(--texte);
  color: var(--brun);
  text-decoration: underline;
  cursor: pointer;
  opacity: .75;
}

.regles {
  list-style: none;
  padding: 0;
  margin: 14px 0 4px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.regles li {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  border: 2px solid rgba(43, 26, 14, .15);
  border-radius: 14px;
  padding: 3px 8px;
  text-align: left;
  font-size: 13px;
  line-height: 1.1;
  font-weight: 600;
}
.regles li b { display: block; font-size: 14px; font-weight: 800; }
.regles .ico { flex: 0 0 32px; height: 38px; display: grid; place-items: center; font-size: 26px; }
.regles .ico canvas { width: 30px; height: 39px; }
.regles li.pas-taper { background: #ffe3e3; border-color: rgba(230, 57, 70, .35); }
.regles li.bonus { background: #e7f5ff; border-color: rgba(77, 171, 247, .35); }

.aide { font-size: 13px; opacity: .7; margin: 10px 0 0; font-weight: 600; }
.record { font-family: var(--titre); font-size: 20px; margin: 10px 0 0; color: var(--orange); -webkit-text-stroke: 1px var(--brun); paint-order: stroke fill; }
.record:empty { display: none; }

/* ---------- fin ---------- */
.tete-titre.fin { animation: vertige 2.2s ease-in-out infinite; }
@keyframes vertige {
  0%, 100% { transform: rotate(-10deg); }
  50% { transform: rotate(10deg) translateY(4px); }
}
.rang-label { margin: 12px 0 0; font-weight: 800; text-transform: uppercase; letter-spacing: 2px; font-size: 12px; opacity: .6; }
.citation { margin: 2px 0 6px; font-style: italic; font-weight: 600; font-size: 16px; }
.gros-score { font-family: var(--titre); font-size: 54px; line-height: 1; color: var(--brun); }
.gros-score small { display: block; font-family: var(--texte); font-size: 14px; font-weight: 800; letter-spacing: 2px; text-transform: uppercase; opacity: .6; }
.nouveau-record {
  font-family: var(--titre);
  color: var(--rouge);
  font-size: 22px;
  margin: 6px 0 0;
  animation: pulse .8s ease-in-out infinite;
}
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 12px 0 4px;
}
.stats div { background: #fff; border-radius: 14px; border: 2px solid rgba(43, 26, 14, .15); padding: 5px 4px 4px; }
.stats b { display: block; font-family: var(--titre); font-weight: 400; font-size: 21px; }
.stats span { font-size: 12px; font-weight: 700; opacity: .7; line-height: 1.1; display: block; }
.honte { font-size: 14px; font-weight: 700; color: var(--rouge); margin: 6px 0 8px; min-height: 1em; }

@media (max-width: 480px) {
  .carte { padding: 18px 16px; border-radius: 22px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .gros-bouton { font-size: 26px; padding: 10px 32px 6px; }
  .tete-titre { width: 104px; height: 136px; margin-top: -78px; }
  .accroche { font-size: 16px; }
}

/* ---------- choix du jeu ---------- */
.modes { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; margin: 0 0 14px; }
.mode {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-align: center;
  font: inherit;
  color: var(--brun);
  background: #fff;
  border: 3px solid rgba(43, 26, 14, .25);
  border-radius: 18px;
  padding: 8px 10px;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(43, 26, 14, .25);
  transition: transform .1s, box-shadow .1s, border-color .15s, background .15s;
}
.mode:hover { background: #fffbeb; }
.mode:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(43, 26, 14, .25); }
.mode.choisi {
  border-color: var(--brun);
  background: #fff3bf;
  box-shadow: 0 4px 0 var(--brun), 0 0 0 4px rgba(255, 210, 63, .55);
}
.mode-ico { flex: 0 0 46px; height: 60px; display: grid; place-items: center; }
.mode-ico canvas { width: 46px; height: 60px; }
.mode-txt b { display: block; font-family: var(--titre); font-weight: 400; font-size: 17px; letter-spacing: .5px; line-height: 1.1; margin-bottom: 2px; }
.mode-txt span { display: block; font-size: 12px; font-weight: 600; line-height: 1.15; opacity: .8; }
.regles[hidden] { display: none; }

.onglets { display: flex; gap: 6px; justify-content: center; margin: 4px 0 2px; }
.onglet {
  font: 800 15px var(--texte);
  color: var(--brun);
  background: #fff;
  border: 3px solid rgba(43, 26, 14, .25);
  border-radius: 14px;
  padding: 5px 14px 3px;
  cursor: pointer;
}
.onglet.actif { border-color: var(--brun); background: var(--jaune); box-shadow: 0 3px 0 var(--brun); }

/* ---------- classement & boutons secondaires ---------- */
.rangee-boutons { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 12px; }
.bouton-2 {
  font: 800 15px var(--texte);
  color: var(--brun);
  background: #fff;
  border: 3px solid var(--brun);
  border-radius: 14px;
  padding: 6px 14px 4px;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--brun);
  transition: transform .08s, box-shadow .08s;
}
.bouton-2:hover { background: #fff3bf; }
.bouton-2:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--brun); }
.bouton-2.fort { background: var(--jaune); font-family: var(--titre); font-weight: 400; font-size: 18px; letter-spacing: 1px; }
body:not(.en-ligne) .si-en-ligne { display: none !important; }

.mini-classement { margin: 8px 0 12px; }
.ma-place { margin: 0 0 6px; font-weight: 800; font-size: 16px; }
.ma-place b { color: var(--rouge); }
.liste-scores {
  list-style: none;
  margin: 0;
  padding: 0;
  text-align: left;
  border: 2px solid rgba(43, 26, 14, .15);
  border-radius: 14px;
  background: #fff;
  overflow: hidden;
}
.liste-scores:empty { display: none; }
.liste-scores.grande { max-height: min(52vh, 460px); overflow-y: auto; }
.liste-scores li {
  display: grid;
  grid-template-columns: 2.4em 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 4px 12px;
  font-weight: 700;
  font-size: 15px;
  border-top: 1px solid rgba(43, 26, 14, .08);
}
.liste-scores li:first-child { border-top: 0; }
.liste-scores li:nth-child(odd) { background: #fffaf0; }
.liste-scores .rg { font-family: var(--titre); font-weight: 400; font-size: 16px; text-align: center; }
.liste-scores .ps { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.liste-scores .ps small { font-weight: 600; opacity: .55; font-size: 12px; margin-left: 6px; }
.liste-scores .sc { font-family: var(--titre); font-weight: 400; font-size: 18px; }
.liste-scores li.moi { background: #fff3bf; box-shadow: inset 4px 0 0 var(--orange); }
.liste-scores li.ecart { justify-content: center; display: block; text-align: center; opacity: .5; padding: 0; line-height: 1; }

#toast {
  position: fixed;
  left: 50%;
  bottom: 80px;
  transform: translate(-50%, 20px);
  background: var(--brun);
  color: #fff;
  font-weight: 800;
  padding: 10px 18px;
  border-radius: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 30;
  max-width: 90vw;
  text-align: center;
}
#toast.visible { opacity: 1; transform: translate(-50%, 0); }

@media (max-height: 760px) {
  .aide { display: none; }
  .carte { margin-top: 70px; }
}

@media (max-width: 520px) {
  .regles { grid-template-columns: repeat(2, 1fr); }
  .modes { grid-template-columns: 1fr 1fr; gap: 6px; }
  .mode { padding: 6px; }
  .mode-ico { height: 50px; }
  .mode-ico canvas { width: 38px; height: 50px; }
  .mode-txt b { font-size: 15px; }
  .mode-txt span { font-size: 11px; }
  .onglets { flex-wrap: wrap; }
  .onglet { font-size: 13px; padding: 4px 10px 2px; }
}

/* cartes sans tête qui dépasse (pause, classement) : pas besoin de marge en haut */
.carte.sans-tete { margin-top: 16px; }

/* ---------- téléphone ---------- */
@media (max-width: 699px) {
  .rond { width: 42px; height: 42px; font-size: 18px; }
  #coin { gap: 6px; }
  /* dans les menus, les boutons passent en haut à droite pour ne pas couvrir la carte */
  body:not(.en-jeu) #coin { top: max(10px, env(safe-area-inset-top)); bottom: auto; }
  .ecran { padding: 12px 10px; }
  .carte { margin-top: 64px; }
  .carte.sans-tete { margin-top: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .tete-titre, .gros-bouton, .nouveau-record { animation: none; }
}
