:root {
  --papier: #fffaf0;
  --carte: #ffffff;
  --encre: #2b2a33;
  --doux: #7a7486;
  --trait: #e6dfd0;
  --jaune: #ffc93c;
  --jaune-fond: #fff3c4;
  --vert: #2bb673;
  --vert-fond: #d9f5e6;
  --bleu: #4c8bf5;
  --bleu-fond: #e1ecff;
  --rouge: #ff6b5b;
  --rouge-fond: #ffe3df;
  --violet: #6c5ce7;
  --ombre: 0 2px 0 rgba(43, 42, 51, .08), 0 8px 24px rgba(43, 42, 51, .06);
  --rayon: 18px;
  --ui: "Fredoka", ui-rounded, "SF Pro Rounded", system-ui, sans-serif;
  --lecture: "Andika", "Georgia", serif;
  --haut: env(safe-area-inset-top, 0px);
  --bas: env(safe-area-inset-bottom, 0px);
}

[hidden] { display: none !important; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--papier);
  color: var(--encre);
  font-family: var(--ui);
  font-weight: 500;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
svg { display: block; }

.ecran { display: none; min-height: 100dvh; }
.ecran.actif { display: flex; flex-direction: column; }

/* ---------- Accueil ---------- */
#ecran-accueil {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(20px + var(--haut)) 20px calc(24px + var(--bas));
  gap: 22px;
}
.accueil-tete { display: flex; align-items: center; gap: 14px; }
.logo {
  width: 56px; height: 56px; flex: none;
  border-radius: 16px;
  background: var(--jaune);
  color: var(--encre);
  display: grid; place-items: center;
  box-shadow: var(--ombre);
}
.logo svg { width: 38px; height: 38px; }
h1 { font-size: 22px; font-weight: 600; margin: 0; line-height: 1.15; }
.sous-titre { margin: 2px 0 0; color: var(--doux); }
.accueil-tete .icone-btn { margin-left: auto; }

.icone-btn {
  width: 44px; height: 44px; border-radius: 14px;
  display: grid; place-items: center;
  color: var(--doux);
}
.icone-btn svg { width: 24px; height: 24px; }
.icone-btn:active { background: var(--trait); }

.consigne {
  margin: 0;
  font-size: 19px;
  line-height: 1.4;
  text-align: center;
  font-family: var(--lecture);
}

.modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.mode {
  background: var(--carte);
  border: 2.5px solid var(--trait);
  border-radius: var(--rayon);
  padding: 14px 6px 12px;
  font-size: 15px;
  line-height: 1.15;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  transition: transform .12s, border-color .15s, background .15s;
}
.mode:active { transform: scale(.97); }
.mode[aria-checked="true"] { border-color: var(--violet); background: #f1efff; color: var(--violet); }
.mode-picto { width: 40px; height: 32px; display: flex; flex-direction: column; justify-content: space-between; }
.mode-picto i { display: block; height: 7px; border-radius: 4px; background: currentColor; opacity: .85; }
.mode-picto.vertical { flex-direction: row; }
.mode-picto.vertical i { width: 8px; height: 100%; }
.mode-picto.des { position: relative; border: 3px solid currentColor; border-radius: 8px; width: 34px; height: 34px; }
.mode-picto.des b { position: absolute; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.mode-picto.des b:nth-child(1) { top: 4px; left: 4px; }
.mode-picto.des b:nth-child(2) { top: 11px; left: 11px; }
.mode-picto.des b:nth-child(3) { bottom: 4px; right: 4px; }

.gros-btn {
  background: var(--vert);
  color: #fff;
  font-size: 26px;
  font-weight: 600;
  padding: 20px;
  border-radius: 22px;
  box-shadow: 0 6px 0 #1f8f59;
  transition: transform .08s, box-shadow .08s;
}
.gros-btn:active { transform: translateY(5px); box-shadow: 0 1px 0 #1f8f59; }
.gros-btn:disabled { background: #b9c3bd; box-shadow: 0 6px 0 #9aa49e; }
.gros-btn.petit { font-size: 19px; padding: 14px; }
.etat-serveur { margin: -10px 0 0; text-align: center; color: var(--doux); font-size: 15px; min-height: 1em; }

.temps-bloc {
  background: var(--carte);
  border-radius: var(--rayon);
  padding: 16px;
  box-shadow: var(--ombre);
}
.temps-tete { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }
h2 { font-size: 18px; margin: 0; font-weight: 600; }
.record { color: var(--violet); font-size: 15px; }
.temps-grille { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.case-temps {
  aspect-ratio: 3 / 2;
  border: 2px solid var(--trait);
  border-radius: 10px;
  display: grid; place-items: center;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}
.case-temps.plein { border-color: #cfc7b6; }
.case-temps.meilleur { border-color: var(--violet); color: var(--violet); background: #f1efff; }

/* ---------- Lecture ---------- */
#ecran-lecture {
  height: 100dvh;
  min-height: 0;
  padding: var(--haut) 0 var(--bas);
}
.barre {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px 6px;
}
.chrono {
  font-size: 34px; font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: .5px;
}
.progression { min-width: 64px; text-align: right; color: var(--doux); font-size: 18px; font-variant-numeric: tabular-nums; padding-right: 6px; }
.progress { height: 6px; margin: 0 16px; background: var(--trait); border-radius: 3px; overflow: hidden; }
#barre-prog { height: 100%; width: 0; background: var(--vert); transition: width .3s; }

.grille-zone { flex: 1; min-height: 0; padding: 10px 12px; display: flex; justify-content: center; }
.grille {
  width: 100%;
  max-width: 620px;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(var(--cols, 5), 1fr);
  grid-template-rows: repeat(var(--lignes, 11), 1fr);
  border: 2.5px solid var(--encre);
  border-radius: 10px;
  overflow: hidden;
  background: var(--carte);
}
.cellule {
  display: flex; align-items: center; justify-content: center;
  border-right: 1.5px solid var(--encre);
  border-bottom: 1.5px solid var(--encre);
  font-family: var(--lecture);
  font-weight: 700;
  font-size: min(7.5vw, 4.4dvh, 44px);
  line-height: 1;
  position: relative;
  transition: background .2s, color .2s;
}
.cellule.fin-ligne { border-right: 0; }
.cellule.derniere-ligne { border-bottom: 0; }
.cellule.attente { color: #bdb6a8; }
.cellule.courante {
  background: var(--jaune-fond);
  color: var(--encre);
  z-index: 1;
  box-shadow: inset 0 0 0 4px var(--jaune);
  animation: respire 1.6s ease-in-out infinite;
}
.cellule.ok { background: var(--vert-fond); color: #1c7a4c; }
.cellule.ok::after, .cellule.aide::after {
  content: ""; position: absolute; right: 5px; top: 5px;
  width: 9px; height: 9px; border-radius: 50%;
}
.cellule.ok::after { background: var(--vert); }
.cellule.aide { background: var(--bleu-fond); color: #2f5fb3; }
.cellule.aide::after { background: var(--bleu); }
.cellule.pop { animation: pop .35s ease-out; }
.cellule.raté { animation: secoue .4s; background: var(--rouge-fond); box-shadow: inset 0 0 0 4px var(--rouge); }
.mode-hasard .cellule.attente { color: var(--encre); }

@keyframes respire { 50% { box-shadow: inset 0 0 0 6px var(--jaune); } }
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.12); } 100% { transform: scale(1); } }
@keyframes secoue { 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }

.pied {
  display: flex; align-items: center; gap: 12px;
  padding: 6px 16px 12px;
  min-height: 72px;
}
.micro { flex: 1; display: flex; align-items: center; gap: 10px; color: var(--doux); font-size: 17px; min-width: 0; }
.micro-icone {
  width: 48px; height: 48px; flex: none; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--trait); color: var(--doux);
  position: relative;
}
.micro-icone svg { width: 24px; height: 24px; position: relative; z-index: 1; }
.niveau {
  position: absolute; inset: 0; border-radius: 50%;
  background: var(--vert); opacity: .25;
  transform: scale(1);
  transition: transform .08s linear;
}
.micro.ecoute .micro-icone { color: var(--vert); background: var(--vert-fond); }
.micro.parle .micro-icone { color: #fff; background: var(--vert); }
.micro.reflechit .micro-icone { color: var(--violet); background: #f1efff; }
.micro.coupe .micro-icone { color: var(--rouge); background: var(--rouge-fond); }
#micro-texte { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; line-height: 1.2; font-size: 15px; }

.valider {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 18px;
  border-radius: 16px;
  background: var(--bleu-fond);
  color: var(--bleu);
  font-size: 18px; font-weight: 600;
  opacity: 0; pointer-events: none;
  transform: translateY(6px);
  transition: opacity .25s, transform .25s;
}
.valider svg { width: 24px; height: 24px; }
.valider.visible { opacity: 1; pointer-events: auto; transform: none; }
.valider.insiste { background: var(--bleu); color: #fff; box-shadow: 0 4px 0 #2f63c4; }
.valider:active { transform: translateY(3px); box-shadow: none; }

.decompte {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  background: rgba(255, 250, 240, .92);
  font-size: 160px; font-weight: 600; color: var(--violet);
  z-index: 10;
}
.decompte span { animation: pop .5s ease-out; }

/* ---------- Résultat ---------- */
#ecran-resultat { align-items: center; justify-content: center; position: relative; overflow: hidden; }
.resultat { text-align: center; padding: 24px; position: relative; z-index: 1; max-width: 420px; width: 100%; }
.etoiles { display: flex; justify-content: center; gap: 8px; margin-bottom: 8px; }
.etoiles svg { width: 64px; height: 64px; }
.etoiles svg.eteinte { opacity: .2; }
.etoiles svg:not(.eteinte) { animation: pop .5s ease-out backwards; }
.etoiles svg:nth-child(2) { animation-delay: .15s; }
.etoiles svg:nth-child(3) { animation-delay: .3s; }
.bravo { font-size: 34px; font-weight: 600; margin: 4px 0; }
.temps-final { font-size: 72px; font-weight: 600; margin: 0; font-variant-numeric: tabular-nums; color: var(--violet); }
.detail { color: var(--doux); font-size: 17px; margin: 6px 0 0; }
.nouveau-record {
  display: inline-block; margin: 16px 0 0;
  background: var(--jaune); padding: 8px 18px; border-radius: 999px;
  font-size: 20px; font-weight: 600;
  animation: pop .6s ease-out;
}
.actions { display: flex; flex-direction: column; gap: 12px; margin-top: 32px; }
.lien-btn { color: var(--doux); font-size: 18px; padding: 10px; }
.lien-btn.danger { color: var(--rouge); font-size: 16px; }
#confettis { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

/* ---------- Réglages ---------- */
dialog {
  border: 0; border-radius: 22px; padding: 0;
  width: min(440px, calc(100vw - 32px));
  background: var(--carte); color: var(--encre);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
}
dialog::backdrop { background: rgba(43, 42, 51, .35); }
dialog form { padding: 22px; display: flex; flex-direction: column; gap: 16px; }
.reglage { display: flex; gap: 12px; align-items: flex-start; font-size: 16px; line-height: 1.3; }
.reglage small { color: var(--doux); font-size: 14px; }
.reglage input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--violet); margin-top: 1px; flex: none; }
.reglage select { margin-left: auto; font: inherit; font-size: 15px; padding: 6px; border-radius: 10px; border: 2px solid var(--trait); background: var(--papier); color: var(--encre); }
.reglage:has(select) { align-items: center; }

@media (min-width: 700px) {
  .cellule { font-size: min(5vw, 4.6dvh, 48px); }
}

/* ---------- Version, nouveautés, journal ---------- */
.version-btn {
  align-self: center;
  margin-top: auto;
  color: var(--doux); font-size: 14px;
  padding: 8px 14px; border-radius: 999px;
  position: relative;
}
.version-btn:active { background: var(--trait); }
.pastille {
  position: absolute; top: 6px; right: 2px;
  width: 9px; height: 9px; border-radius: 50%; background: var(--rouge);
}
.nouveautes { max-height: 60dvh; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.nouveautes h3 { font-size: 16px; margin: 0 0 4px; font-weight: 600; }
.nouveautes h3 small { color: var(--doux); font-weight: 500; }
.nouveautes ul { margin: 0; padding-left: 18px; font-size: 15px; line-height: 1.35; color: var(--encre); }
.nouveautes li + li { margin-top: 4px; }
.nouveautes .actuelle h3 { color: var(--violet); }

.aide-journal { margin: -6px 0 0; color: var(--doux); font-size: 14px; line-height: 1.3; }
.table-journal { max-height: 50dvh; overflow-y: auto; border: 2px solid var(--trait); border-radius: 12px; }
.ligne-journal {
  display: grid; grid-template-columns: 64px 1fr; gap: 2px 10px;
  padding: 8px 12px; border-bottom: 1px solid var(--trait); font-size: 14px;
}
.ligne-journal:last-child { border-bottom: 0; }
.ligne-journal .syl { font-family: var(--lecture); font-weight: 700; font-size: 22px; grid-row: span 2; align-self: center; }
.ligne-journal .stats { font-variant-numeric: tabular-nums; }
.ligne-journal .stats b { font-weight: 600; }
.ligne-journal .stats .mauvais { color: var(--rouge); }
.ligne-journal .stats .bon { color: var(--vert); }
.ligne-journal .plutot { color: var(--doux); font-size: 13px; }
.journal-vide { padding: 18px; text-align: center; color: var(--doux); font-size: 15px; }
.journal-actions { display: flex; align-items: center; gap: 10px; }
.journal-actions .gros-btn { flex: 1; }
.gros-btn.bleu { background: var(--bleu); box-shadow: 0 5px 0 #2f63c4; }
.gros-btn.bleu:active { box-shadow: 0 1px 0 #2f63c4; }
.journal-btn { color: var(--violet); font-size: 16px; text-align: left; padding-left: 0; }
