/* Styles communs à toutes les pages du site.
   Mise en page : un écran de jeu plein cadre — barre d'icônes en haut,
   zone de jeu au centre, commandes en bas. Sobre, gros boutons, peu de mots. */
:root {
  /* Neutres légèrement bleutés, un accent vert (échiquiers de tournoi) */
  --fond: #F3F4F6;
  --surface: #FFFFFF;
  --surface-2: #E8EBF0;
  --ligne: #D8DCE3;
  --encre: #1A1E27;
  --encre-douce: #626979;
  --accent: #2E7D5B;
  --accent-doux: #DCEEE5;
  --sur-accent: #FFFFFF;
  --or: #D9A441;
  --alerte: #D2553F;
  --voile: rgba(22, 26, 34, .45);
  --ombre-carte: 0 18px 48px rgba(22, 26, 34, .18);

  /* Matières de la balance : laiton et noyer */
  --laiton-clair: #F7E2A6;
  --laiton: #D8AC50;
  --laiton-fonce: #9E772C;
  --laiton-trait: #6F521F;
  --grave: #4A3412;
  --bois-clair: #9C6B45;
  --bois: #74492D;
  --bois-fonce: #4F311E;
  --cadran: #FFFDF5;
  --ombre-sol: #1A1E27;

  /* Pièces */
  --piece-blanc: #FFFFFF;
  --piece-blanc-trait: #1A1E27;
  --piece-noir: #2B303B;
  --piece-noir-trait: #1A1E27;
  --piece-noir-detail: #FFFFFF;

  /* Typographie : Lexend, conçue pour faciliter la lecture */
  --police: "Lexend", "Segoe UI", system-ui, -apple-system, sans-serif;

  --rayon: 18px;
}

/* Mode sombre : des gris (pas du noir), contrastes vérifiés (texte ≥ 4,5:1 sur les fonds) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --fond: #2B2E35;
    --surface: #363A42;
    --surface-2: #41464F;
    --ligne: #545A65;
    --encre: #F2F4F7;
    --encre-douce: #BCC2CD;
    --accent: #62C99A;
    --accent-doux: #284638;
    --sur-accent: #0D1A13;
    --or: #E8BE68;
    --alerte: #F6957F;
    --voile: rgba(10, 12, 16, .55);
    --ombre-carte: 0 18px 48px rgba(0, 0, 0, .35);
    --laiton-clair: #EBD08C;
    --laiton: #C79A42;
    --laiton-fonce: #8A6526;
    --cadran: #3D414A;
    --ombre-sol: #0E1015;
    --piece-blanc: #F4F5F7;
    --piece-blanc-trait: #0E1015;
    --piece-noir: #262A31;
    --piece-noir-trait: #D2D7E0;
    --piece-noir-detail: #F4F5F7;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --fond: #2B2E35;
  --surface: #363A42;
  --surface-2: #41464F;
  --ligne: #545A65;
  --encre: #F2F4F7;
  --encre-douce: #BCC2CD;
  --accent: #62C99A;
  --accent-doux: #284638;
  --sur-accent: #0D1A13;
  --or: #E8BE68;
  --alerte: #F6957F;
  --voile: rgba(10, 12, 16, .55);
  --ombre-carte: 0 18px 48px rgba(0, 0, 0, .35);
  --laiton-clair: #EBD08C;
  --laiton: #C79A42;
  --laiton-fonce: #8A6526;
  --cadran: #3D414A;
  --ombre-sol: #0E1015;
  --piece-blanc: #F4F5F7;
  --piece-blanc-trait: #0E1015;
  --piece-noir: #262A31;
  --piece-noir-trait: #D2D7E0;
  --piece-noir-detail: #F4F5F7;
  color-scheme: dark;
}

html, body { height: 100%; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--fond);
  color: var(--encre);
  font-family: var(--police);
  font-size: 17px;
  -webkit-tap-highlight-color: transparent;
  transition: background-color .25s, color .25s;
}

.ecran {
  box-sizing: border-box;
  min-height: 100%;
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-block: 14px 20px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}

/* ---------- Barre du haut ---------- */
.barre { display: flex; align-items: center; gap: 8px; }
.barre .titre {
  margin: 0 auto 0 6px;
  font-weight: 600;
  font-size: clamp(19px, 3vw, 26px);
  letter-spacing: -0.01em;
  line-height: 1.1;
  text-wrap: balance;
  min-width: 0;
}

/* ---------- Boutons ---------- */
.bouton-icone {
  flex: none;
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  padding: 0;
  border: 1px solid var(--ligne);
  border-radius: 14px;
  background: var(--surface);
  color: var(--encre);
  cursor: pointer;
  text-decoration: none;
  transition: background .15s, color .15s, transform .1s;
}
.bouton-icone svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.bouton-langue { font-size: 14px; font-weight: 700; letter-spacing: .04em; text-decoration: none; }
.bouton-icone:hover { background: var(--surface-2); }
.bouton-icone:active { transform: scale(.94); }
.bouton-icone[aria-expanded="true"] { background: var(--surface-2); }

/* bouton thème : la lune en mode clair, le soleil en mode sombre */
.bouton-theme .icone-soleil { display: none; }
.bouton-theme[data-theme="dark"] .icone-soleil { display: inline; }
.bouton-theme[data-theme="dark"] .icone-lune { display: none; }

.bouton-principal, .bouton-secondaire {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 50px;
  padding: 0 22px;
  border-radius: 14px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: transform .1s, background .15s;
}
.bouton-principal { border: none; background: var(--accent); color: var(--sur-accent); }
.bouton-secondaire { border: 1px solid var(--ligne); background: var(--surface); color: var(--encre); }
.bouton-secondaire:hover { background: var(--surface-2); }
.bouton-principal:active, .bouton-secondaire:active { transform: scale(.97); }

/* ---------- Panneau de réglages ---------- */
.reglages { position: relative; flex: none; }
.panneau {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 20;
  width: 260px;
  max-width: calc(100vw - 32px);
  padding: 6px;
  border: 1px solid var(--ligne);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--ombre-carte);
}
.ligne-reglage {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 10px;
  border: none;
  border-radius: 10px;
  background: none;
  color: var(--encre);
  font: inherit;
  font-size: 15px;
  text-align: left;
  cursor: pointer;
}
.ligne-reglage:hover { background: var(--surface-2); }
.ligne-reglage > svg { flex: none; width: 22px; height: 22px; fill: none; stroke: var(--encre-douce); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ligne-reglage > span:first-of-type { flex: 1; }

/* interrupteur */
.interrupteur {
  position: relative;
  flex: none;
  width: 42px;
  height: 24px;
  border-radius: 12px;
  background: var(--ligne);
  transition: background .2s;
}
.interrupteur::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
  transition: transform .2s;
}
[aria-checked="true"] > .interrupteur { background: var(--accent); }
[aria-checked="true"] > .interrupteur::after { transform: translateX(18px); }

/* ---------- Réglage sur plusieurs lignes (titre + choix) ---------- */
.ligne-reglage-bloc { display: flex; flex-direction: column; gap: 8px; padding: 10px 10px 8px; }
.ligne-titre { display: flex; align-items: center; gap: 12px; font-size: 15px; }
.ligne-titre svg { flex: none; width: 22px; height: 22px; fill: none; stroke: var(--encre-douce); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ligne-reglage small { display: block; margin-top: 1px; font-size: 12px; color: var(--encre-douce); }

/* choix segmenté (ex. 1 dé / 3 dés) */
.segments { display: flex; gap: 6px; }
.segments button, .segments a {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 7px 4px;
  border: 2px solid var(--ligne);
  border-radius: 10px;
  background: var(--fond);
  color: var(--encre);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.segments button small, .segments a small { font-size: 11px; font-weight: 500; color: var(--encre-douce); }
.segments button[aria-pressed="true"], .segments a[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-doux); }
/* les choix sans dessin (langue, thème) : le texte un peu plus grand */
#reg-langue small, #reg-theme small { padding: 3px 0; font-size: 13px; font-weight: 600; color: var(--encre); }

.note-reglages { margin: 4px 10px 2px; font-size: 12px; color: var(--encre-douce); }
.segments-plateau { gap: 4px; }
.segments-plateau button { padding: 6px 2px; }
.segments-plateau svg { border-radius: 4px; box-shadow: 0 0 0 1px var(--ligne); }

/* ---------- Fenêtre par-dessus le jeu ---------- */
.voile {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  overflow-y: auto;
  padding: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) max(16px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  background: var(--voile);
  backdrop-filter: blur(4px);
}

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

@media (max-width: 560px) {
  .barre { gap: 6px; }
  .bouton-icone { width: 42px; height: 42px; border-radius: 12px; }
  .bouton-icone svg { width: 21px; height: 21px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* la copie du bouton « Suivant », en bas de l'écran quand le vrai est hors de vue (js/commun.js) */
.suivant-flottant {
  position: fixed;
  z-index: 45;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 52px;
  padding: 12px 26px;
  border-radius: 16px;
  font: inherit;
  font-size: 17px;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 10px 28px rgba(0, 0, 0, .22);
  cursor: pointer;
  animation: suivant-arrive .3s cubic-bezier(.2, 1.3, .4, 1);
}
.suivant-flottant svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.suivant-flottant kbd, .suivant-flottant .touche { display: none; }
@keyframes suivant-arrive { from { opacity: 0; transform: translate(-50%, 20px); } }

/* ---------- L'aide des jeux : le bouton « ? » et son tutoriel en étapes (js/aide.js) ---------- */
.bouton-aide span { font-size: 21px; font-weight: 700; line-height: 1; }
.bouton-aide.a-voir { border-color: var(--accent); color: var(--accent); animation: aide-bat 1.6s ease-in-out 3; }
@keyframes aide-bat { 50% { transform: scale(1.12); box-shadow: 0 0 0 6px var(--accent-doux); } }
.carte-aide {
  box-sizing: border-box;
  width: min(440px, 100%);
  padding: 14px 18px 18px;
  border-radius: 24px;
  background: var(--surface);
  box-shadow: var(--ombre-carte);
  animation: aide-arrive .35s cubic-bezier(.2, 1.2, .4, 1) both;
}
@keyframes aide-arrive { from { opacity: 0; transform: translateY(24px) scale(.96); } }
.aide-tete { display: flex; align-items: center; justify-content: space-between; }
.aide-compteur { margin: 0; color: var(--encre-douce); font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
.aide-corps { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 2px 4px 6px; text-align: center; }
.aide-numero {
  display: grid; place-items: center; width: 52px; height: 52px; border-radius: 50%;
  background: var(--accent-doux); color: var(--accent); font-size: 26px; font-weight: 700;
}
.aide-corps h2 { margin: 4px 0 0; font-size: 23px; font-weight: 700; letter-spacing: -0.01em; text-wrap: balance; }
.aide-texte { margin: 0; min-height: 4.6em; color: var(--encre); font-size: 16.5px; line-height: 1.5; text-wrap: pretty; }
.aide-texte kbd { padding: 1px 6px; border: 1px solid var(--ligne); border-radius: 6px; background: var(--fond); font: inherit; font-size: 13px; font-weight: 600; }
.aide-nav { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 12px; }
.aide-nav button { min-height: 46px; padding: 0 18px; border-radius: 14px; font: inherit; font-weight: 600; cursor: pointer; }
.aide-nav button:disabled { visibility: hidden; }
.aide-points { display: flex; gap: 7px; margin: 0; padding: 0; list-style: none; }
.aide-points li { width: 9px; height: 9px; border-radius: 50%; background: var(--ligne); transition: transform .2s, background .2s; }
.aide-points li.vu { background: var(--accent); opacity: .5; }
.aide-points li.actuel { background: var(--accent); transform: scale(1.3); }
@media (max-width: 400px) {
  .carte-aide { padding: 12px 14px 14px; }
  .aide-nav button { padding: 0 12px; }
}

/* Signature en bas de chaque jeu, discrète */
.signature {
  margin-top: -6px;
  font-size: 12px;
  line-height: 1;
  color: var(--encre-douce);
  text-align: center;
}

/* ---------- Couleur de l'échiquier (réglage de la page d'accueil, valable pour tout le site) ---------- */
:root { --plateau-claire: #ECECD7; --plateau-foncee: #739A62; }
:root[data-plateau="bleu"] { --plateau-claire: #E3EAF1; --plateau-foncee: #7898B8; }
:root[data-plateau="rouge"] { --plateau-claire: #F4E1D9; --plateau-foncee: #CB726B; }
:root[data-plateau="bois"] { --plateau-claire: #F0D9B5; --plateau-foncee: #B58863; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --plateau-claire: #D6D6C0; --plateau-foncee: #628751; }
  :root:not([data-theme="light"])[data-plateau="bleu"] { --plateau-claire: #C9D3DD; --plateau-foncee: #5F7F9F; }
  :root:not([data-theme="light"])[data-plateau="rouge"] { --plateau-claire: #DCC7BF; --plateau-foncee: #A95B56; }
  :root:not([data-theme="light"])[data-plateau="bois"] { --plateau-claire: #D9C19C; --plateau-foncee: #96704D; }
}
:root[data-theme="dark"] { --plateau-claire: #D6D6C0; --plateau-foncee: #628751; }
:root[data-theme="dark"][data-plateau="bleu"] { --plateau-claire: #C9D3DD; --plateau-foncee: #5F7F9F; }
:root[data-theme="dark"][data-plateau="rouge"] { --plateau-claire: #DCC7BF; --plateau-foncee: #A95B56; }
:root[data-theme="dark"][data-plateau="bois"] { --plateau-claire: #D9C19C; --plateau-foncee: #96704D; }

/* téléphone peu haut : des espacements un peu plus serrés, pour que le jeu tienne sur l'écran */
@media (max-width: 560px) and (max-height: 760px) {
  .ecran { gap: 10px; padding-block: 10px 12px; }
  .signature { margin-top: -4px; font-size: 11px; }
}

/* ---------- Comptes (js/compte.js) ---------- */
/* le bouton du compte, en haut de l'accueil */
.bouton-compte {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 46px;
  max-width: 180px;
  padding: 0 14px 0 10px;
  border: 1px solid var(--ligne);
  border-radius: 14px;
  background: var(--surface);
  color: var(--encre);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  text-decoration: none;
}
.bouton-compte svg { flex: none; width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.bouton-compte span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bouton-compte.connecte { border-color: var(--accent); background: var(--accent-doux); color: var(--accent); }
.bouton-compte:hover { background: var(--surface-2); }
@media (max-width: 560px) {
  .bouton-compte { height: 42px; padding: 0 10px 0 8px; max-width: 130px; font-size: 14px; }
}
@media (max-width: 380px) {
  .bouton-compte:not(.connecte) span { display: none; }
  .bouton-compte { padding: 0 9px; }
}
/* un jeu pas encore ouvert pour l'élève : un cadenas sur la carte de l'accueil */
.carte-jeu.verrouillee { position: relative; opacity: .5; filter: grayscale(.6); }
.carte-jeu.verrouillee::after {
  content: "";
  position: absolute;
  top: 8px;
  right: 8px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--encre) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2.2' stroke-linecap='round'%3E%3Crect x='6' y='11' width='12' height='9' rx='2'/%3E%3Cpath d='M8.5 11V8.5a3.5 3.5 0 0 1 7 0V11'/%3E%3C/svg%3E") center / 16px no-repeat;
}
/* et dans le jeu : une fenêtre par-dessus */
html.jeu-verrouille body > main { filter: blur(6px); pointer-events: none; user-select: none; }
.verrou-jeu { z-index: 90; }
.carte-verrou { text-align: center; }
.carte-verrou h2 { margin: 6px 0 4px; font-size: 22px; }
.carte-verrou .cadenas { width: 52px; height: 52px; fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; }
.carte-verrou .res-actions a { text-decoration: none; }
.signature a { color: inherit; }
